Index: branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/AA_make
===================================================================
--- branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/AA_make	(revision 2578)
+++ branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/AA_make	(revision 2578)
@@ -0,0 +1,13 @@
+# $Header$
+all: ioipsl opatam
+
+ioipsl:
+	(cd ../../modeles/IOIPSL/src; $(M_K) ;)
+
+
+opatam:
+	(cd ../../modeles/NEMOTAM/WORK;  $(M_K) ;)
+
+
+clean:
+	(cd ../../modeles/NEMOTAM/WORK;  $(M_K) clean ;)
Index: branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/AA_make.ldef
===================================================================
--- branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/AA_make.ldef	(revision 2578)
+++ branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/AA_make.ldef	(revision 2578)
@@ -0,0 +1,11 @@
+#---------------------------------------------------------------------
+#- Creation des elements relatifs a ORCA :
+#-      ORCA  (lib, executable : opa)
+#---------------------------------------------------------------------
+SHELL = /bin/sh
+#---------------------------------------------------------------------
+LIBDIR = ../../../../lib
+BINDIR = ../../../../bin
+MODDIR = $(LIBDIR)
+#---------------------------------------------------------------------
+#-
Index: branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/namelist
===================================================================
--- branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/namelist	(revision 2578)
+++ branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/namelist	(revision 2578)
@@ -0,0 +1,736 @@
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! NEMO/OPA  :  1 - run manager      (namrun)
+!! namelists    2 - Domain           (namzgr, namzgr_sco, namdom)
+!!              3 - Surface boundary (namsbc, namsbc_ana, namsbc_flx, namsbc_clio, namsbc_core
+!!                                    namsbc_cpl, namqsr, namsbc_rnf, namsbc_ssr, namsbc_alb)
+!!              4 - lateral boundary (namlbc, namcla, namobc, namagrif, nambdy, nambdy_tide)
+!!              5 - bottom  boundary (nambfr, nambbc, nambbl)
+!!              6 - Tracer           (nameos, namtra_adv, namtra_ldf, namtra_dmp)
+!!              7 - dynamics         (namdyn_adv, namdyn_vor, namdyn_hpg, namdyn_spg, namdyn_ldf)
+!!              8 - Verical physics  (namzdf, namzdf_ric, namzdf_tke, namzdf_kpp, namzdf_ddm, namzdf_tmx)
+!!              9 - diagnostics      (namtrd, namgap, namspr, namflo, namptr)
+!!              9 - miscellaneous    (namsol, nammpp, nammpp_dyndist, namctl)
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!  CAUTION: some scripts does not support CAPITALs for logical use .true./.false., not .TRUE./.FALSE.
+
+!!======================================================================
+!!                   ***  Run management namelists  ***
+!!======================================================================
+!!   namrun            parameters of the run
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&namrun        !   parameters of the run
+!-----------------------------------------------------------------------
+   nn_no       =       0   !  job number
+   cn_exp      =  "ORCA2"  !  experience name 
+   nn_it000    =       1   !  first time step
+   nn_itend    =    5475   !  last  time step (std 5475)
+   nn_date0    =  010101   !  initial calendar date yymmdd (used if nrstdt=1)
+   nn_leapy    =       0   !  Leap year calendar (1) or not (0)
+   nn_istate   =       0   !  output the initial state (1) or not (0)
+   nn_stock    =    5475   !  frequency of creation of a restart file (modulo referenced to 1)
+   nn_write    =    5475   !  frequency of write in the output file   (modulo referenced to nit000)
+   ln_dimgnnn  = .false.   !  DIMG file format: 1 file for all processors (F) or by processor (T)
+   ln_mskland  = .false.   !  mask land points in NetCDF outputs (costly: + ~15%)
+   ln_clobber  = .false.   !  clobber (overwrite) an existing file
+   nn_chunksz  =       0   !  chunksize (bytes) for NetCDF file (working only with iom_nf90 routines)
+   ln_rstart   = .false.   !  start from rest (F) or from a restart file (T)
+   nn_rstctl   =       0       !  restart control = 0 nit000 is not compared to the restart file value
+                               !                  = 1 use ndate0 in namelist (not the value in the restart file)
+                               !                  = 2 calendar parameters read in the restart file
+   cn_ocerst_in  = "restart"   !  suffix of ocean restart name (input)
+   cn_ocerst_out = "restart"   !  suffix of ocean restart name (output)
+/
+!!======================================================================
+!!                      ***  Domain namelists  ***
+!!======================================================================
+!!   namzgr       vertical coordinate
+!!   namzgr_sco   s-coordinate or hybrid z-s-coordinate
+!!   namdom       space and time domain (bathymetry, mesh, timestep)
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&namzgr        !   vertical coordinate
+!-----------------------------------------------------------------------
+   ln_zco      = .false.   !  z-coordinate - full    steps   (T/F)      ("key_zco" may also be defined)
+   ln_zps      = .true.    !  z-coordinate - partial steps   (T/F)
+   ln_sco      = .false.   !  s- or hybrid z-s-coordinate    (T/F)
+/
+!-----------------------------------------------------------------------
+&namzgr_sco    !   s-coordinate or hybrid z-s-coordinate
+!-----------------------------------------------------------------------
+   rn_sbot_min =  300.     !  minimum depth of s-bottom surface (>0) (m)
+   rn_sbot_max = 5250.     !  maximum depth of s-bottom surface (= ocean depth) (>0) (m)
+   rn_theta    =    6.0    !  surface control parameter (0<=theta<=20)
+   rn_thetb    =    0.75   !  bottom control parameter  (0<=thetb<= 1)
+   rn_rmax     =    0.15   !  maximum cut-off r-value allowed (0<r_max<1)
+   ln_s_sigma  = .false.   !  hybrid s-sigma coordinates
+   rn_bb       =    0.8    !  stretching with s-sigma
+   rn_hc       =  150.0    !  critical depth with s-sigma 
+/
+!-----------------------------------------------------------------------
+&namdom        !   space and time domain (bathymetry, mesh, timestep)
+!-----------------------------------------------------------------------
+   nn_bathy    =    1      !  compute (=0) or read(=1) the bathymetry file
+   nn_closea   =    0      !  closed seas and lakes are removed (=0) or kept (=1) from the ORCA domain
+   nn_msh      =    0      !  create (=1) a mesh file (coordinates, scale factors, masks) or not (=0)
+   rn_e3zps_min=   20.     !  the thickness of the partial step is set larger than the minimum
+   rn_e3zps_rat=    0.1    !  of e3zps_min and e3zps_rat * e3t   (N.B. 0<e3zps_rat<1)
+                           !
+   rn_rdt      = 5760.     !  time step for the dynamics (and tracer if nacc=0)   ==> 5760
+   nn_baro     =   64      !  number of barotropic time step (for the split explicit algorithm) ("key_dynspg_ts")
+   rn_atfp     =    0.1    !  asselin time filter parameter
+   nn_acc      =    0      !  acceleration of convergence : =1      used, rdt < rdttra(k)
+                                 !                          =0, not used, rdt = rdttra
+   rn_rdtmin   = 28800.          !  minimum time step on tracers (used if nacc=1)
+   rn_rdtmax   = 28800.          !  maximum time step on tracers (used if nacc=1)
+   rn_rdth     =  800.           !  depth variation of tracer time step  (used if nacc=1)
+/
+!!======================================================================
+!!            ***  Surface Boundary Condition namelists  ***
+!!======================================================================
+!!   namsbc        surface boundary condition
+!!   namsbc_ana    analytical         formulation
+!!   namsbc_flx    flux               formulation
+!!   namsbc_clio   CLIO bulk formulea formulation
+!!   namsbc_core   CORE bulk formulea formulation
+!!   namsbc_cpl    CouPLed            formulation                       ("key_coupled")
+!!   namtra_qsr    penetrative solar radiation
+!!   namsbc_rnf    river runoffs
+!!   namsbc_ssr    sea surface restoring term (for T and/or S)
+!!   namsbc_alb    albedo parameters
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&namsbc        !   Surface Boundary Condition (surface module)
+!-----------------------------------------------------------------------
+   nn_fsbc     = 5         !  frequency of surface boundary condition computation 
+                           !               (= the frequency of sea-ice model call)
+   ln_ana      = .false.   !  analytical formulation (T => fill namsbc_ana ) 
+   ln_flx      = .false.   !  flux formulation       (T => fill namsbc_flx )
+   ln_blk_clio = .true.    !  CLIO bulk formulation  (T => fill namsbc_clio) 
+   ln_blk_core = .false.   !  CORE bulk formulation  (T => fill namsbc_core) 
+   ln_cpl      = .false.   !  Coupled formulation    (T => fill namsbc_cpl )
+   nn_ice      = 0         !  =0 no ice boundary condition   ,
+                           !  =1 use observed ice-cover      ,
+                           !  =2 ice-model used                             ("key_lim3" or "key_lim2)
+   nn_ico_cpl  = 0         !  ice-ocean coupling : =0 each nn_fsbc 
+                           !                       =1 stresses recomputed each ocean time step ("key_lim3" only)
+                           !                       =2 combination of 0 and 1 cases             ("key_lim3" only)
+   ln_dm2dc    = .false.   !  daily mean to diurnal cycle short wave (qsr)
+   ln_rnf      = .true.    !  runoffs (T => fill namsbc_rnf)
+   ln_ssr      = .true.    !  Sea Surface Restoring on T and/or S (T => fill namsbc_ssr)
+   nn_fwb      = 3         !  FreshWater Budget: =0 unchecked 
+                           !                     =1 global mean of e-p-r set to zero at each time step 
+                           !                     =2 annual global mean of e-p-r set to zero
+                           !                     =3 global emp set to zero and spread out over erp area
+/
+!-----------------------------------------------------------------------
+&namsbc_ana    !   analytical surface boundary condition
+!-----------------------------------------------------------------------
+   nn_tau000   =   0       !  gently increase the stress over the first ntau_rst time-steps
+   rn_utau0    =   0.5     !  uniform value for the i-stress
+   rn_vtau0    =   0.e0    !  uniform value for the j-stress
+   rn_qns0     =   0.e0    !  uniform value for the total heat flux
+   rn_qsr0     =   0.e0    !  uniform value for the solar radiation
+   rn_emp0     =   0.e0    !  uniform value for the freswater budget (E-P)
+/
+!-----------------------------------------------------------------------
+&namsbc_flx    !   surface boundary condition : flux formulation
+!-----------------------------------------------------------------------
+!              !   file name  ! frequency (hours) !  variable  ! time interpol. !  clim   ! 'yearly'/ ! weights  ! rotation !
+!              !              !  (if <0  months)  !    name    !    (logical)   !  (T/F)  ! 'monthly' ! filename ! pairing  !
+   sn_utau     = 'utau'       ,        24         ,    'utau'  ,     .false.    , .false. , 'yearly'  , ''       , ''
+   sn_vtau     = 'vtau'       ,        24         ,    'vtau'  ,     .false.    , .false. , 'yearly'  , ''       , ''
+   sn_qtot     = 'qtot'       ,        24         ,    'qtot'  ,     .false.    , .false. , 'yearly'  , ''       , ''
+   sn_qsr      = 'qsr'        ,        24         ,    'qsr'   ,     .false.    , .false. , 'yearly'  , ''       , ''
+   sn_emp      = 'emp'        ,        24         ,    'emp'   ,     .false.    , .false. , 'yearly'  , ''       , ''
+!
+   cn_dir      = './'      !  root directory for the location of the flux files
+/      
+!-----------------------------------------------------------------------
+&namsbc_clio   !   namsbc_clio  CLIO bulk formulea
+!-----------------------------------------------------------------------
+!              !   file name  ! frequency (hours) !  variable  ! time interpol. !  clim   ! 'yearly'/ ! weights  ! rotation !
+!              !              !  (if <0  months)  !    name    !    (logical)   !  (T/F)  ! 'monthly' ! filename ! pairing  !
+   sn_utau     = 'taux_1m'    ,       -1          , 'sozotaux' ,    .true.      , .true.  , 'yearly'  , ''       , ''
+   sn_vtau     = 'tauy_1m'    ,       -1          , 'sometauy' ,    .true.      , .true.  , 'yearly'  , ''       , ''
+   sn_wndm     = 'flx'        ,       -1          , 'socliowi' ,    .true.      , .true.  , 'yearly'  , ''       , ''
+   sn_tair     = 'flx'        ,       -1          , 'socliot2' ,    .true.      , .true.  , 'yearly'  , ''       , ''
+   sn_humi     = 'flx'        ,       -1          , 'socliohu' ,    .true.      , .true.  , 'yearly'  , ''       , ''
+   sn_ccov     = 'flx'        ,       -1          , 'socliocl' ,    .false.     , .true.  , 'yearly'  , ''       , ''
+   sn_prec     = 'flx'        ,       -1          , 'socliopl' ,    .false.     , .true.  , 'yearly'  , ''       , ''
+!
+   cn_dir      = './'      !  root directory for the location of the bulk files are
+/
+!-----------------------------------------------------------------------
+&namsbc_core   !   namsbc_core  CORE bulk formulea
+!-----------------------------------------------------------------------
+!              !   file name  ! frequency (hours) ! variable   ! time interpol. !  clim   ! 'yearly'/ ! weights              ! rotation !
+!              !              !  (if <0  months)  !   name     !    (logical)   !  (T/F)  ! 'monthly' ! filename             ! pairing  !
+   sn_wndi     = 'u10_core'   ,       -1          , 'u10'      ,    .true.      , .true.  , 'yearly'  ,'bicubic_weights_orca2.nc' , 'U1'
+   sn_wndj     = 'v10_core'   ,       -1          , 'v10'      ,    .true.      , .true.  , 'yearly'  ,'bicubic_weights_orca2.nc' , 'V1'
+   sn_qsr      = 'qsw_core'   ,       -1          , 'swdn'     ,    .true.      , .true.  , 'yearly'  ,'bilinear_weights_orca2.nc', ''
+   sn_qlw      = 'qlw_core'   ,       -1          , 'lwdn'     ,    .true.      , .true.  , 'yearly'  ,'bilinear_weights_orca2.nc', ''
+   sn_tair     = 't2_core'    ,       -1          , 't2'       ,    .true.      , .true.  , 'yearly'  ,'bilinear_weights_orca2.nc', ''
+   sn_humi     = 'q2_core'    ,       -1          , 'q2'       ,    .true.      , .true.  , 'yearly'  ,'bilinear_weights_orca2.nc', ''
+   sn_prec     = 'precip_core',       -1          , 'precip'   ,    .true.      , .true.  , 'yearly'  ,'bilinear_weights_orca2.nc', ''
+   sn_snow     = 'snow_core'  ,       -1          , 'snow'     ,    .true.      , .true.  , 'yearly'  ,'bilinear_weights_orca2.nc', ''
+   sn_tdif     = 'taudif_core',       24          , 'taudif'   ,    .true.      , .true.  , 'yearly'  ,'bilinear_weights_orca2.nc', ''
+!
+   cn_dir      = './'      !  root directory for the location of the bulk files
+   ln_2m       = .true.    !  air temperature and humidity referenced at 2m (T) instead 10m (F)
+   ln_taudif   = .false.   !  HF tau contribution: use "mean of stress module - module of the mean stress" data ?
+   rn_pfac     = 1.        !  multiplicative factor for precipitation (total & snow)
+/
+!-----------------------------------------------------------------------
+&namsbc_cpl    !   coupled ocean/atmosphere model                        ("key_coupled")
+!-----------------------------------------------------------------------
+                                       ! send
+cn_snd_temperature= 'weighted oce and ice'  ! 'oce only' 'weighted oce and ice' 'mixed oce-ice'
+cn_snd_albedo     = 'weighted ice'          ! 'none' 'weighted ice' 'mixed oce-ice'
+cn_snd_thickness  = 'none'                  ! 'none' 'weighted ice and snow'
+cn_snd_crt_nature = 'none'                  ! 'none' 'oce only' 'weighted oce and ice' 'mixed oce-ice'
+cn_snd_crt_refere = 'spherical'             ! 'spherical' 'cartesian'
+cn_snd_crt_orient = 'eastward-northward'    ! 'eastward-northward' or 'local grid'
+cn_snd_crt_grid   = 'T'                     ! 'T'
+                                       ! receive
+cn_rcv_w10m       = 'none'                  ! 'none' 'coupled'
+cn_rcv_taumod     = 'coupled'               ! 'none' 'coupled'
+cn_rcv_tau_nature = 'oce only'              ! 'oce only' 'oce and ice' 'mixed oce-ice'
+cn_rcv_tau_refere = 'cartesian'             ! 'spherical' 'cartesian'
+cn_rcv_tau_orient = 'eastward-northward'    ! 'eastward-northward' or 'local grid'
+cn_rcv_tau_grid   = 'U,V'                   ! 'T' 'U,V' 'U,V,F' 'U,V,I' 'T,F' 'T,I' 'T,U,V'
+cn_rcv_dqnsdt     = 'coupled'               ! 'none' 'coupled'
+cn_rcv_qsr        = 'oce and ice'           ! 'conservative' 'oce and ice' 'mixed oce-ice'
+cn_rcv_qns        = 'oce and ice'           ! 'conservative' 'oce and ice' 'mixed oce-ice'
+cn_rcv_emp        = 'conservative'          ! 'conservative' 'oce and ice' 'mixed oce-ice'
+cn_rcv_rnf        = 'coupled'               ! 'coupled' 'climato' 'mixed'
+cn_rcv_cal        = 'coupled'               ! 'none' 'coupled'
+/
+!-----------------------------------------------------------------------
+&namsbc_cpl_co2   !   coupled ocean/biogeo/atmosphere model            ("key_cpl_carbon_cycle")
+!-----------------------------------------------------------------------
+cn_snd_co2        = 'coupled'         ! send    :  'none' 'coupled'
+cn_rcv_co2        = 'coupled'         ! receive : 'none' 'coupled'
+/
+!-----------------------------------------------------------------------
+&namtra_qsr    !   penetrative solar radiation
+!-----------------------------------------------------------------------
+!              !   file name  ! frequency (hours) ! variable   ! time interpol. !  clim   ! 'yearly'/ ! weights  ! rotation !
+!              !              !  (if <0  months)  !   name     !    (logical)   !  (T/F)  ! 'monthly' ! filename ! pairing  !
+   sn_chl      = 'chlorophyll',        -1         , 'CHLA'     ,    .true.      , .true.  , 'yearly'  , ''       , ''
+ 
+   cn_dir      = './'      !  root directory for the location of the runoff files
+   ln_traqsr   = .true.    !  Light penetration (T) or not (F)
+   ln_qsr_rgb  = .true.    !  RGB (Red-Green-Blue) light penetration
+   ln_qsr_2bd  = .false.   !  2 bands              light penetration
+   ln_qsr_bio  = .false.   !  bio-model light penetration
+   nn_chldta   =      0    !  RGB : Chl data (=1) or cst value (=0)
+   rn_abs      =   0.58    !  RGB & 2 bands: fraction of light (rn_si1)
+   rn_si0      =   0.35    !  RGB & 2 bands: shortess depth of extinction
+   rn_si1      =   23.0    !  2 bands: longest depth of extinction
+   rn_si2      =   62.0    !  3 bands: longest depth of extinction (for blue waveband & 0.01 mg/m2 Chl)
+/
+!-----------------------------------------------------------------------
+&namsbc_rnf    !   runoffs namelist surface boundary condition
+!-----------------------------------------------------------------------
+!              !   file name  ! frequency (hours) ! variable   ! time interpol. !  clim   ! 'yearly'/ ! weights  ! rotation !
+!              !              !  (if <0  months)  !   name     !    (logical)   !  (T/F)  ! 'monthly' ! filename ! pairing  !
+   sn_rnf      = 'runoff_1m_nomask' ,  -1         , 'sorunoff' ,    .true.      , .true.  , 'yearly'  , ''       , ''
+   sn_cnf      = 'runoff_1m_nomask' ,   0         , 'socoefr'  ,    .false.     , .true.  , 'yearly'  , ''       , ''
+ 
+   cn_dir       = './'      !  root directory for the location of the runoff files
+   ln_rnf_emp   =   .false. !  runoffs included into precipitation field (T) or into a file (F)
+   ln_rnf_mouth =   .false. !  specific treatment at rivers mouths
+   rn_hrnf      =  15.e0    !  depth over which enhanced vertical mixing is used
+   rn_avt_rnf   =   1.e-3   !  value of the additional vertical mixing coef. [m2/s]
+   rn_rfact     =   1.e0    !  multiplicative factor for runoff
+/
+!-----------------------------------------------------------------------
+&namsbc_ssr    !   surface boundary condition : sea surface restoring
+!-----------------------------------------------------------------------
+!              !   file name  ! frequency (hours) ! variable   ! time interpol. !  clim   ! 'yearly'/ ! weights  ! rotation !
+!              !              !  (if <0  months)  !   name     !    (logical)   !  (T/F)  ! 'monthly' ! filename ! pairing  !
+   sn_sst      = 'sst_data'   ,        24         ,  'sst'     ,     .false.    , .false. , 'yearly'  , ''       , ''
+   sn_sss      = 'sss_data'   ,        -1         ,  'sss'     ,     .true.     , .true.  , 'yearly'  , ''       , ''
+    
+   cn_dir      = './'      !  root directory for the location of the runoff files
+   nn_sstr     =     0     !  add a retroaction term in the surface heat       flux (=1) or not (=0)
+   nn_sssr     =     2     !  add a damping     term in the surface freshwater flux (=2) 
+                           !  or to SSS only (=1) or no damping term (=0)
+   rn_dqdt     =   -40.    !  magnitude of the retroaction on temperature   [W/m2/K]
+   rn_deds     =   -27.7   !  magnitude of the damping on salinity   [mm/day]
+   ln_sssr_bnd =   .true.  !  flag to bound erp term (associated with nn_sssr=2)
+   rn_sssr_bnd =   4.e0    !  ABS(Max/Min) value of the damping erp term [mm/day]
+/      
+!-----------------------------------------------------------------------
+&namsbc_alb    !   albedo parameters
+!-----------------------------------------------------------------------
+   rn_cloud    =    0.06   !  cloud correction to snow and ice albedo 
+   rn_albice   =    0.53   !  albedo of melting ice in the arctic and antarctic
+   rn_alphd    =    0.80   !  coefficients for linear interpolation used to
+   rn_alphc    =    0.65   !  compute albedo between two extremes values 
+   rn_alphdi   =    0.72   !  (Pyane, 1972)
+/
+
+!!======================================================================
+!!               ***  Lateral boundary condition  ***
+!!======================================================================
+!!   namlbc        lateral momentum boundary condition
+!!   namcla        cross land advection
+!!   namobc        open boundaries parameters                           ("key_obc")
+!!   namagrif      agrif nested grid ( read by child model only )       ("key_agrif") 
+!!   nambdy        Unstructured open boundaries                         ("key_bdy")
+!!   namtide       Tidal forcing at open boundaries                     ("key_bdy_tides")
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&namlbc        !   lateral momentum boundary condition
+!-----------------------------------------------------------------------
+   rn_shlat    =    2.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
+                           !  free slip  !   partial slip  !   no slip   ! strong slip
+/
+!-----------------------------------------------------------------------
+&namcla        !   cross land advection
+!-----------------------------------------------------------------------
+   nn_cla      =    0      !  advection between 2 ocean pts separates by land
+/
+!-----------------------------------------------------------------------
+&namobc        !   open boundaries parameters                           ("key_obc")
+!-----------------------------------------------------------------------
+    ln_obc_clim= .false.   !  climatological obc data files (T) or not (F)
+    ln_vol_cst = .true.    !  impose the total volume conservation (T) or not (F)
+    ln_obc_fla = .false.   !  Flather open boundary condition 
+    nn_obcdta  =    1      !  = 0 the obc data are equal to the initial state
+                           !  = 1 the obc data are read in 'obc.dta' files
+    cn_obcdta  = 'annual'  !  set to annual if obc datafile hold 1 year of data
+                           !  set to monthly if obc datafile hold 1 month of data
+    rn_dpein   =    1.     !  damping time scale for inflow at east  open boundary
+    rn_dpwin   =    1.     !     -           -         -       west    -      -
+    rn_dpnin   =    1.     !     -           -         -       north   -      -
+    rn_dpsin   =    1.     !     -           -         -       south   -      -
+    rn_dpeob   = 3000.     !  time relaxation (days) for the east  open boundary
+    rn_dpwob   =   15.     !     -           -         -     west    -      -
+    rn_dpnob   = 3000.     !     -           -         -     north   -      -
+    rn_dpsob   =   15.     !     -           -         -     south   -      -
+    rn_volemp  =  1.       !  = 0 the total volume change with the surface flux (E-P-R)
+                           !  = 1 the total volume remains constant
+/
+!-----------------------------------------------------------------------
+&namagrif      !  AGRIF zoom                                            ("key_agrif")
+!-----------------------------------------------------------------------
+    nn_cln_update = 3      !  baroclinic update frequency
+    ln_spc_dyn    = .true. !  use 0 as special value for dynamics
+    rn_sponge_tra = 2880.  !  coefficient for tracer   sponge layer [s]
+    rn_sponge_dyn = 2880.  !  coefficient for dynamics sponge layer [s]
+/
+!-----------------------------------------------------------------------
+&nambdy        !  unstructured open boundaries                          ("key_bdy")
+!-----------------------------------------------------------------------
+    filbdy_mask    =  ''                  !  name of mask file (if ln_bdy_mask=.TRUE.)
+    filbdy_data_T  = 'bdydata_grid_T.nc'  !  name of data file (T-points)
+    filbdy_data_U  = 'bdydata_grid_U.nc'  !  name of data file (U-points)
+    filbdy_data_V  = 'bdydata_grid_V.nc'  !  name of data file (V-points)
+    ln_bdy_clim    = .false.              !  contain 1 (T) or 12 (F) time dumps and be cyclic
+    ln_bdy_vol     = .true.               !  total volume correction (see volbdy parameter)
+    ln_bdy_mask    = .false.              !  boundary mask from filbdy_mask (T) or boundaries are on edges of domain (F)
+    ln_bdy_tides   = .true.               !  Apply tidal harmonic forcing with Flather condition
+    ln_bdy_dyn_fla = .true.               !  Apply Flather condition to velocities
+    ln_bdy_tra_frs = .false.              !  Apply FRS condition to temperature and salinity 
+    ln_bdy_dyn_frs = .false.              !  Apply FRS condition to velocities
+    nbdy_dta       =  1                   !  = 0, bdy data are equal to the initial state
+                                          !  = 1, bdy data are read in 'bdydata   .nc' files
+    nb_rimwidth    = 9                    !  width of the relaxation zone
+    volbdy         = 0                    !  = 0, the total water flux across open boundaries is zero
+                                          !  = 1, the total volume of the system is conserved
+/
+!-----------------------------------------------------------------------
+&nambdy_tide     ! tidal forcing at unstructured boundaries              
+!-----------------------------------------------------------------------
+    filtide      = 'bdytide_'           !  file name root of tidal forcing files
+    tide_cpt     = 'M2','S1'            !  names of tidal components used
+    tide_speed   = 28.984106, 15.000001 !  phase speeds of tidal components (deg/hour)
+    ln_tide_date = .false.              !  adjust tidal harmonics for start date of run
+/
+
+!!======================================================================
+!!                 ***  Bottom boundary condition  ***
+!!======================================================================
+!!   nambfr        bottom friction
+!!   nambbc        bottom temperature boundary condition                ("key_trabbc")
+!!   nambbl        bottom boundary layer scheme                         ("key_trabbl_dif","key_trabbl_adv")
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&nambfr        !   bottom friction
+!-----------------------------------------------------------------------
+   nn_bfr      =    1      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
+                           !                              = 2 : nonlinear friction
+   rn_bfri1    =    4.e-4  !  bottom drag coefficient (linear case)
+   rn_bfri2    =    1.e-3  !  bottom drag coefficient (non linear case)
+   rn_bfeb2    =    2.5e-3 !  bottom turbulent kinetic energy background  (m^2/s^2)
+   ln_bfr2d    =   .false. !  horizontal variation of the bottom friction coef (read a 2D mask file )
+   rn_bfrien   =    50.    !  local multiplying factor of bfr (ln_bfr2d = .true.)
+/
+!-----------------------------------------------------------------------
+&nambbc        !   bottom temperature boundary condition
+!-----------------------------------------------------------------------
+   nn_geoflx   =    2      !  geothermal heat flux: = 0 no flux 
+                           !     = 1 constant flux
+                           !     = 2 variable flux (read in geothermal_heating.nc in mW/m2) 
+   rn_geoflx_cst = 86.4e-3 !  Constant value of geothermal heat flux [W/m2]
+/
+!-----------------------------------------------------------------------
+&nambbl        !   bottom boundary layer scheme
+!-----------------------------------------------------------------------
+!                          !  diffusive bbl                             ("key_trabbl")
+!                          !  advective bbl                             ("key_trabbl_adv")
+   rn_ahtbbl   =  10000.   !  lateral mixing coefficient in the bbl  [m2/s]
+/
+!!======================================================================
+!!                        Tracer (T & S ) namelists
+!!======================================================================
+!!   nameos        equation of state
+!!   namtra_adv    advection scheme
+!!   namtra_ldf    lateral diffusion scheme
+!!   namtra_dmp    T & S newtonian damping                              ("key_tradmp")
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&nameos        !   ocean physical parameters
+!-----------------------------------------------------------------------
+   nn_eos      =    0      !  type of equation of state and Brunt-Vaisala frequency
+                           !     = 0, UNESCO (formulation of Jackett and McDougall (1994) and of McDougall (1987) )
+                           !     = 1, linear: rho(T)   = rau0 * ( 1.028 - ralpha * T )
+                           !     = 2, linear: rho(T,S) = rau0 * ( rbeta * S - ralpha * T )
+   rn_alpha    =    2.e-4  !  thermal expension coefficient (neos= 1 or 2)
+   rn_beta     =    0.001  !  saline  expension coefficient (neos= 2)
+/
+!-----------------------------------------------------------------------
+&namtra_adv    !   advection scheme for tracer 
+!-----------------------------------------------------------------------
+   ln_traadv_cen2   =  .false.  !  2nd order centered scheme   
+   ln_traadv_tvd    =  .true.   !  TVD scheme                
+   ln_traadv_muscl  =  .false.  !  MUSCL scheme             
+   ln_traadv_muscl2 =  .false.  !  MUSCL2 scheme + cen2 at boundaries  
+   ln_traadv_ubs    =  .false.  !  UBS scheme                 
+/
+!-----------------------------------------------------------------------
+&namtra_ldf    !   lateral diffusion scheme for tracer 
+!-----------------------------------------------------------------------
+                           !  Type of the operator : 
+   ln_traldf_lap    =  .true.   !     laplacian operator       
+   ln_traldf_bilap  =  .false.  !     bilaplacian operator     
+                           !  Direction of action  :
+   ln_traldf_level  =  .false.  !     iso-level                
+   ln_traldf_hor    =  .false.  !     horizontal (geopotential)         (require "key_ldfslp" when ln_sco=T)
+   ln_traldf_iso    =  .true.   !     iso-neutral                       (require "key_ldfslp")
+                           !  Coefficient
+   rn_aht_0         =  2000.    !     horizontal eddy diffusivity for tracers [m2/s]
+   rn_ahtb_0        =     0.    !     background eddy diffusivity for ldf_iso [m2/s]
+   rn_aeiv_0        =  2000.    !     eddy induced velocity coefficient [m2/s]    (require "key_traldf_eiv")
+/
+!-----------------------------------------------------------------------
+&namtra_dmp    !   tracer: T & S newtonian damping                      ('key_tradmp')
+!-----------------------------------------------------------------------
+   nn_hdmp     =   -1      !  horizontal shape =-1, damping in Med and Red Seas only
+                           !                   =XX, damping poleward of XX degrees (XX>0)
+                           !                      + F(distance-to-coast) + Red and Med Seas
+   nn_zdmp     =    1      !  vertical   shape =0    damping throughout the water column
+                           !                   =1 no damping in the mixing layer (kz  criteria)
+                           !                   =2 no damping in the mixed  layer (rho crieria)
+   rn_surf     =   50.     !  surface time scale of damping   [days]
+   rn_bot      =  360.     !  bottom  time scale of damping   [days]
+   rn_dep      =  800.     !  depth of transition between rn_surf and rn_bot [meters]
+   nn_file     =    1      !  create a damping.coeff NetCDF file (=1) or not (=0)
+/
+!!======================================================================
+!!                      ***  Dynamics namelists  ***
+!!======================================================================
+!!   namdyn_adv    formulation of the momentum advection
+!!   namdyn_vor    advection scheme
+!!   namdyn_hpg    hydrostatic pressure gradient
+!!   namdyn_spg    surface pressure gradient                            (CPP key only)
+!!   namdyn_ldf    lateral diffusion scheme
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection
+!-----------------------------------------------------------------------
+   ln_dynadv_vec = .true.  !  vector form (T) or flux form (F)  
+   ln_dynadv_cen2= .false. !  flux form - 2nd order centered scheme
+   ln_dynadv_ubs = .false. !  flux form - 3rd order UBS      scheme 
+/  
+!-----------------------------------------------------------------------
+&namdyn_vor    !   option of physics/algorithm (not control by CPP keys)
+!-----------------------------------------------------------------------
+   ln_dynvor_ene = .false. !  enstrophy conserving scheme  
+   ln_dynvor_ens = .false. !  energy conserving scheme    
+   ln_dynvor_mix = .false. !  mixed scheme               
+   ln_dynvor_een = .true.  !  energy & enstrophy scheme  
+/
+!-----------------------------------------------------------------------
+&namdyn_hpg    !   Hydrostatic pressure gradient option
+!-----------------------------------------------------------------------
+   ln_hpg_zco  = .false.   !  z-coordinate - full steps                   
+   ln_hpg_zps  = .true.    !  z-coordinate - partial steps (interpolation)
+   ln_hpg_sco  = .false.   !  s-coordinate (standard jacobian formulation)
+   ln_hpg_hel  = .false.   !  s-coordinate (helsinki modification)
+   ln_hpg_wdj  = .false.   !  s-coordinate (weighted density jacobian)
+   ln_hpg_djc  = .false.   !  s-coordinate (Density Jacobian with Cubic polynomial)
+   ln_hpg_rot  = .false.   !  s-coordinate (ROTated axes scheme)
+   rn_gamma    = 0.e0      !  weighting coefficient (wdj scheme)
+   ln_dynhpg_imp = .false. !  time stepping: semi-implicit time scheme  (T)
+                                 !           centered      time scheme  (F)
+   nn_dynhpg_rst =  0            ! =1 dynhpg restartable restart or not (=0)
+/
+!-----------------------------------------------------------------------
+!namdyn_spg    !   surface pressure gradient   (CPP key only)
+!-----------------------------------------------------------------------
+!                          !  explicit free surface                     ("key_dynspg_exp")
+!                          !  filtered free surface                     ("key_dynspg_flt")
+!                          !  split-explicit free surface               ("key_dynspg_ts")
+
+!-----------------------------------------------------------------------
+&namdyn_ldf    !   lateral diffusion on momentum
+!-----------------------------------------------------------------------
+                           !  Type of the operator : 
+   ln_dynldf_lap    =  .true.   !  laplacian operator         
+   ln_dynldf_bilap  =  .false.  !  bilaplacian operator    
+                           !  Direction of action  : 
+   ln_dynldf_level  =  .false.  !  iso-level               
+   ln_dynldf_hor    =  .true.   !  horizontal (geopotential)            (require "key_ldfslp" in s-coord.)
+   ln_dynldf_iso    =  .false.  !  iso-neutral                          (require "key_ldfslp")
+                           !  Coefficient
+   rn_ahm_0    = 40000.         !  horizontal eddy viscosity   [m2/s]
+   rn_ahmb_0   =     0.         !  background eddy viscosity for ldf_iso [m2/s]
+/
+!!======================================================================
+!!             Tracers & Dynamics vertical physics namelists
+!!======================================================================
+!!       namzdf        vertical physics
+!!       namzdf_ric    richardson number dependent vertical mixing      ("key_zdfric"      )
+!!       namzdf_tke    TKE dependent vertical mixing                    ("key_zdftke"      )
+!!       namzdf_kpp    KPP dependent vertical mixing                    ("key_zdfkpp"      )
+!!       namzdf_ddm    double diffusive mixing parameterization         ("key_zdfddm"      )
+!!       namzdf_tmx    tidal mixing parameterization                    ("key_zdftmx"      )
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics
+!-----------------------------------------------------------------------
+   rn_avm0     =   1.2e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
+   rn_avt0     =   1.2e-5  !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
+   nn_avb      =    0      !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0      !  horizontal shape for avtb (=1) or not (=0)
+   ln_zdfevd   = .true.    !  enhanced vertical diffusion (evd) (T) or not (F)
+   nn_evdm     =    0      !  evd apply on tracer (=0) or on tracer and momentum (=1)
+   rn_avevd    =  100.     !  evd mixing coefficient [m2/s]
+   ln_zdfnpc   = .false.   !  Non-Penetrative algorithm (T) or not (F)
+   nn_npc      =    1            !  frequency of application of npc
+   nn_npcp     =  365            !  npc control print frequency
+   ln_zdfexp   = .false.   !  time-stepping: split-explicit (T) or implicit (F) time stepping
+   nn_zdfexp   =    3            !  number of sub-timestep for ln_zdfexp=T
+/
+!-----------------------------------------------------------------------
+&namzdf_ric    !   richardson number dependent vertical diffusion       ("key_zdfric" )
+!-----------------------------------------------------------------------
+   rn_avmri    = 100.e-4   !  maximum value of the vertical viscosity
+   rn_alp      =   5.      !  coefficient of the parameterization
+   nn_ric      =   2       !  coefficient of the parameterization
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  ("key_zdftke")
+!-----------------------------------------------------------------------
+   rn_ediff    =   0.1     !  coef. for vertical eddy coef. (avt=rn_ediff*mxl*sqrt(e) )
+   rn_ediss    =   0.7     !  coef. of the Kolmogoroff dissipation
+   rn_ebb      =  60.      !  coef. of the surface input of tke
+   rn_emin     =   1.e-6   !  minimum value of tke [m2/s2]
+   rn_emin0    =   1.e-4   !  surface minimum value of tke [m2/s2]
+   rn_bshear   =   1.e-20  !  background shear (>0)
+   nn_mxl      =   2       !  mixing length: = 0 bounded by the distance to surface and bottom
+                           !                 = 1 bounded by the local vertical scale factor
+                           !                 = 2 first vertical derivative of mixing length bounded by 1
+                           !                 = 3 same criteria as case 2 but applied in a different way
+   nn_pdl      =   1       !  Prandtl number function of richarson number (=1, avt=pdl(Ri)*avm) or not (=0, avt=avm)
+   ln_mxl0     = .false.   !  mixing length scale surface value as function of wind stress (T) or not (F)
+   rn_lmin     =   0.001   !  interior buoyancy lenght scale minimum value
+   rn_lmin0    =   0.01    !  surface  buoyancy lenght scale minimum value
+   nn_etau     =   0       !  exponentially deceasing penetration of tke due to internal & intertial waves
+                           !        = 0 no penetration ( O(2 km) resolution)
+                           !        = 1 additional tke source (rn_efr * en)
+                           !        = 2 additional tke source (rn_efr * en) applied only at the base of the mixed layer
+                           !        = 3 additional tke source (HF contribution: mean of stress module - module of mean stress)
+   nn_htau     =   1       !  type of exponential decrease of tke penetration
+                           !        = 0  constant 10 m length scale
+                           !        = 1  0.5m at the equator to 30m at high latitudes
+                           !        = 2  30 meters constant depth penetration
+                           !  otion used only if nn_etau = 1 or 2: 
+   rn_efr      =   0.05    !     fraction of surface tke value which penetrates inside the ocean
+                           !  otion used only if nn_etau = 3:
+   rn_addhft   =  -1.e-3   !     add offset   applied to the "mean of stress module - module of mean stress" (always kept > 0)
+   rn_sclhft   =   1.      !     scale factor applied to the "mean of stress module - module of mean stress"
+   ln_lc       = .false.   !  Langmuir cell parameterisation
+   rn_lc       =   0.15    !  coef. associated to Langmuir cells
+/
+!------------------------------------------------------------------------
+&namzdf_kpp    !   K-Profile Parameterization dependent vertical mixing  ("key_zdfkpp", and optionnally:
+!------------------------------------------------------------------------ "key_kppcustom" or "key_kpplktb")
+   ln_kpprimix = .true.    !  shear instability mixing 
+   rn_difmiw   =  1.0e-04  !  constant internal wave viscosity [m2/s]
+   rn_difsiw   =  0.1e-04  !  constant internal wave diffusivity [m2/s]
+   rn_riinfty  =  0.8      !  local Richardson Number limit for shear instability
+   rn_difri    =  0.0050   !  maximum shear mixing at Rig = 0    [m2/s]
+   rn_bvsqcon  = -0.01e-07 !  Brunt-Vaisala squared for maximum convection [1/s2] 
+   rn_difcon   =  1.       !  maximum mixing in interior convection [m2/s] 
+   nn_avb      =  0        !  horizontal averaged (=1) or not (=0) on avt and amv
+   nn_ave      =  1        !  constant (=0) or profile (=1) background on avt
+/
+!-----------------------------------------------------------------------
+&namzdf_ddm    !   double diffusive mixing parameterization             ("key_zdfddm")
+!-----------------------------------------------------------------------
+   rn_avts     = 1.e-4     !  maximum avs (vertical mixing on salinity)
+   rn_hsbfr    = 1.6       !  heat/salt buoyancy flux ratio
+/
+!-----------------------------------------------------------------------
+&namzdf_tmx    !   tidal mixing parameterization                        ("key_zdftmx")
+!-----------------------------------------------------------------------
+   rn_htmx     = 500.      !  vertical decay scale for turbulence (meters)
+   rn_n2min    = 1.e-8     !  threshold of the Brunt-Vaisala frequency (s-1)
+   rn_tfe      = 0.333     !  tidal dissipation efficiency
+   rn_me       = 0.2       !  mixing efficiency 
+   ln_tmx_itf  = .FALSE.   !  ITF specific parameterisation
+   rn_tfe_itf  = 1.        !  ITF tidal dissipation efficiency
+/
+!!======================================================================
+!!                  ***  Miscelaneous namelists  ***
+!!======================================================================
+!!   nammpp            Massively Parallel Processing                    ("key_mpp_mpi)
+!!   nammpp_dyndist    Massively Parallel domain decomposition          ("key_agrif" && "key_mpp_dyndist")
+!!   namctl            Control prints & Benchmark
+!!   namsol            elliptic solver / island / free surface 
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&namsol        !   elliptic solver / island / free surface 
+!-----------------------------------------------------------------------
+   nn_solv     =      1    !  elliptic solver: =1 preconditioned conjugate gradient (pcg)
+                           !                   =2 successive-over-relaxation (sor)
+   nn_sol_arp  =      0    !  absolute/relative (0/1) precision convergence test
+   rn_eps      =  1.e-6    !  absolute precision of the solver
+   nn_nmin     =    300    !  minimum of iterations for the SOR solver
+   nn_nmax     =    800    !  maximum of iterations for the SOR solver
+   nn_nmod     =     10    !  frequency of test for the SOR solver
+   rn_resmax   =  1.e-10   !  absolute precision for the SOR solver
+   rn_sor      =  1.92     !  optimal coefficient for SOR solver (to be adjusted with the domain)
+/
+!-----------------------------------------------------------------------
+&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi)
+!-----------------------------------------------------------------------
+   cn_mpi_send =  'S'      !  mpi send/recieve type   ='S', 'B', or 'I' for standard send,
+                           !  buffer blocking send or immediate non-blocking sends, resp.
+   nn_buffer   =   0       !  size in bytes of exported buffer ('B' case), 0 no exportation
+/
+!-----------------------------------------------------------------------
+&nammpp_dyndist !   Massively Parallel Distribution for AGRIF zoom      ("key_agrif" && "key_mpp_dyndist")
+!-----------------------------------------------------------------------
+   jpni        =    1      !  jpni   number of processors following i
+   jpnj        =    1      !  jpnj   number of processors following j
+   jpnij       =    1      !  jpnij  number of local domains
+/
+!-----------------------------------------------------------------------
+&namctl        !   Control prints & Benchmark
+!-----------------------------------------------------------------------
+   ln_ctl      = .false.   !  trends control print (expensive!)
+   nn_print    =    0      !  level of print (0 no extra print)
+   nn_ictls    =    0      !  start i indice of control sum (use to compare mono versus
+   nn_ictle    =    0      !  end   i indice of control sum        multi processor runs
+   nn_jctls    =    0      !  start j indice of control               over a subdomain)
+   nn_jctle    =    0      !  end   j indice of control
+   nn_isplt    =    1      !  number of processors in i-direction
+   nn_jsplt    =    1      !  number of processors in j-direction
+   nn_bench    =    0      !  Bench mode (1/0): CAUTION use zero except for bench
+                           !     (no physical validity of the results)
+   nn_bit_cmp  =    0      !  bit comparison mode (1/0): CAUTION use zero except for test
+                           !     of comparison between single and multiple processor runs
+/
+
+!!======================================================================
+!!                       ***  Diagnostics namelists  ***
+!!======================================================================
+!!   namtrd       dynamics and/or tracer trends                         ("key_trddyn","key_trdtra","key_trdmld")
+!!   namgap       level mean model-data gap                             ("key_diagap")
+!!   namflo       float parameters                                      ("key_float")
+!!   namptr       Poleward Transport Diagnostics
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&namtrd        !   diagnostics on dynamics and/or tracer trends         ("key_trddyn" and/or "key_trdtra")
+!              !       or mixed-layer trends or barotropic vorticity    ('key_trdmld' or  "key_trdvor")
+!-----------------------------------------------------------------------
+   nn_trd      = 365       !  time step frequency dynamics and tracers trends
+   nn_ctls     =   0       !  control surface type in mixed-layer trends (0,1 or n<jpk)
+   rn_ucf      =   1.      !  unit conversion factor (=1 -> /seconds ; =86400. -> /day)
+   cn_trdrst_in      = "restart_mld"   ! suffix of ocean restart name (input)
+   cn_trdrst_out     = "restart_mld"   ! suffix of ocean restart name (output)
+   ln_trdmld_restart = .false.         !  restart for ML diagnostics
+   ln_trdmld_instant = .false.         !  flag to diagnose trends of instantantaneous or mean ML T/S
+/
+!-----------------------------------------------------------------------
+&namgap       !   level mean model-data gap                             ('key_diagap')
+!-----------------------------------------------------------------------
+   nn_gap     =  15        !  time-step frequency of model-data gap computation
+   nn_prg     =  10        !  time-step frequency of gap print in model output
+/
+!-----------------------------------------------------------------------
+&namflo       !   float parameters                                      ("key_float")
+!-----------------------------------------------------------------------
+    ln_rstflo = .false.    !  float restart (T) or not (F)
+    nn_writefl=      75    !  frequency of writing in float output file 
+    nn_stockfl=    5475    !  frequency of creation of the float restart file 
+    ln_argo   = .false.    !  Argo type floats (stay at the surface each 10 days)
+    ln_flork4 = .false.    !  trajectories computed with a 4th order Runge-Kutta (T)
+                           !  or computed with Blanke' scheme (F)
+/
+!-----------------------------------------------------------------------
+&namptr       !   Poleward Transport Diagnostic
+!-----------------------------------------------------------------------
+   ln_diaptr  = .true.     !  Poleward heat and salt transport (T) or not (F)
+   ln_diaznl  = .true.     !  Add zonal means and meridional stream functions
+   ln_subbas  = .true.     !  Atlantic/Pacific/Indian basins computation (T) or not 
+                           !  (orca configuration only, need input basins mask file named "subbasins.nc"
+   ln_ptrcomp = .true.     !  Add decomposition : overturning
+   nf_ptr     =  1         !  Frequency of ptr computation [time step]
+   nf_ptr_wri =  15        !  Frequency of ptr outputs
+/
+&namtrj
+   ln_trjwri = .true.
+   nn_ittrjfrq = 15
+   ln_trj_spl = .false.
+/
+&namtst
+     ln_tst_opatam  = .true. 
+     ln_tst_adj_cpd = .true.
+     ln_tst_adj_stp = .true.
+     ln_tst_tan_cpd = .false.
+     ln_tst_tan_stp = .false.
+     ln_tst_tlh     = .false.
+     ln_tst_stop    = .false.
+/
+&namtlh
+        cn_tlhrst_in= 'restart_tlh.nc'
+        cn_tlhinc_in= 'increment_tlh.nc'
+        nn_stage    = 0         
+        ln_tlht     = .true.    
+        ln_tlhs     = .true.    
+        ln_tlhuv    = .true.    
+        ln_tlhssh   = .true.    
+        ln_incdx    = .false.   
+        ln_hnorm    = .false.   
+        rn_hstdt    = 1.        
+        rn_hstds    = 0.1       
+        rn_hstduv   = 0.01
+        rn_hstdssh  = 0.01      
+/
Index: branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/scripts/BB_make
===================================================================
--- branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/scripts/BB_make	(revision 2578)
+++ branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/scripts/BB_make	(revision 2578)
@@ -0,0 +1,16120 @@
+# $Header$
+# some variables
+TMP = ../../../tmp
+
+#WARNING : NEMOTAM does NOT support fortran 95 signed zero behaviour when using intrinsec SIGN function
+#          This doesnt happen whith Fortran 90 compilers but
+#          Check your compilers option in consequence when using real F95 compilers
+
+#-Q- sx8mercure  # Compiler options NEMOTAM (CEA SX6-NEC) 
+#-Q- sx8mercure  F_O = -f2003 nocbind noopt_ieee -size_t64 -dw -Wf\"-A dbl4\" -sx6 -C vopt -Wf"-P nh" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- sx8mercure  F_O = -f2003 nocbind noopt_ieee -size_t64 -dw -Wf\"-A dbl4\" -sx6 -ftrace -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- sx8mercure  F_F = $(F_O) -f3
+#-Q- sx8mercure  L_X = $(L_O) -ftrace
+#-Q- sx8brodie  # Compiler options NEMOTAM (CEA SX6-NEC) 
+#-Q- sx8brodie  F_O =  -f2003 nocbind noopt_ieee -dw -Wf\"-A idbl4\" -sx8 -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- sx8brodie  F_F = $(F_O) -f3
+#-Q- sx8brodie  L_X = $(L_O)
+#-Q- sxdkrz  # Compiler options for NEMOTAM (DKRZ SX6-NEC) 
+#-Q- sxdkrz  F_O =  -f2003 nocbind noopt_ieee -ew -sx6 -ftrace -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf"-pvctl noassume loopcnt=10000" -L transform -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- sxdkrz  F_F = $(F_O) -f3
+#-Q- sxdkrz  L_X = $(L_O) -ftrace
+#-Q- eshpux  # Compiler options for NEMOTAM (Earth Simulator)
+#-Q- eshpux  # for super perfs!
+#-Q- eshpux  # F_O = -f2003 nocbind noopt_ieee $(FTRACE) -pi nest=5 line=10000 expin=Fmpplib.F -Wf,-A idbl4 -C hopt -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- eshpux  # regular options!
+#-Q- eshpux  F_O = -f2003 nocbind noopt_ieee $(FTRACE) -Wf,-A idbl4 -C vopt -P stack -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -Wf,-pvctl nomsg -Wf"-O nomsg" -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- eshpux  F_F = $(F_O) -f3
+#-Q- eshpux  L_X = $(L_O)
+#-Q- linux  # Compiler options for NEMOTAM (pgf version)
+#-Q- linux  F_O = -Mlist -O3 -byteswapio -r8  -I $(MODDIR) -I$(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- linux  F_F = $(F_O)-Mextend
+#-Q- linux  L_X = -r8 -O3
+#-Q- lxiv7  # Compiler options for NEMOTAM (ifc version)
+#-Q- lxiv7  F_O = -O3 -r8  -I $(MODDIR) -I$(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- lxiv7  F_F = $(F_O) -extend_source 
+#-Q- lxiv7  L_X = -r8 -O3
+#-Q- lxiv8  # Compiler options for NEMOTAM (ifort version)
+#-Q- lxiv8  F_O = -O3 -r8  -I $(MODDIR) -I$(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- lxiv8  F_F = $(F_O) -extend_source 
+#-Q- lxiv8  L_X = -r8 -O3
+#-Q- g95  # Compiler options for NEMOTAM (g95 version)
+#-Q- g95  F_O = -O3 -fno-second-underscore -r8 -funroll-all-loops -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- g95  F_F = $(F_O)-ffixed-form -ffixed-line-length-132
+#-Q- g95  L_X = -r8 -O3
+#-Q- gfortran  # Compiler options for NEMOTAM (gfortran version)
+#-Q- gfortran  F_O = -fno-second-underscore -fdefault-real-8 -funroll-all-loops -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- gfortran  F_F = $(F_O)-ffixed-form -ffixed-line-length-132
+#-Q- gfortran  L_X = -fdefault-real-8
+#-Q- aix    # Compiler options for NEMOTAM (aix version)
+#-Q- aix    F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- aix    F_F = -O3 -qsave -qrealsize=8 -qsuffix=f=f -qsuffix=cpp=F -qfixed=132 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- aix   L_O = $(F_P) -q64 -O3
+#-Q- aix   L_X = $(L_O)
+#-Q- babel  # Compiler options for NEMOTAM (blue gene version)
+#-Q- babel  F_O =  -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qsource -qextname=flush -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- babel  F_F = -O3 -qsave -qrealsize=8 -qsuffix=f=f -qsuffix=cpp=F -qfixed=132 -qsource -qextname=flush -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- babel  L_X = $(L_O)
+#-Q- osxxlf    # Compiler options for NEMOTAM (osxxlf version)
+#-Q- osxxlf    F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qsource -qextname -qstrict -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- osxxlf    F_F = -O3 -qsave -qrealsize=8 -qsuffix=f=f -qsuffix=cpp=F -qfixed=132 -qsource -qextname -qstrict -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC)
+#-Q- osxxlf    L_X = -qrealsize=8 -O3
+PREF=
+#-Q- sx8mercure	PREF=i.
+#-Q- sx8brodie	PREF=i.
+#-Q- sxdkrz	PREF=i.
+#-Q- eshpux	PREF=i.
+
+# add suffix to P_P
+P_P := $(P_P:%=$(prefix)%)
+
+# Some tests to define variables related to Agrif compilation
+# Please do not change 
+ifneq (,$(findstring key_agrif,$(P_P)))
+AGRIF=use
+else
+AGRIF=notuse
+AGRIF_LIB=
+endif
+ifneq (,$(findstring key_mpp_mpi,$(P_P)))
+AGRIF_MPI=-DAGRIF_MPI
+else
+AGRIF_MPI=
+endif
+
+KEY_LIST = \
+     key_agrif \
+     key_antarctic \
+     key_arctic \
+     key_bdy \
+     key_c1d \
+     key_coupled \
+     key_cpl_albedo \
+     key_cpl_discharge \
+     key_cpl_ocevel \
+     key_cpl_rootexchg \
+     key_diaeiv \
+     key_diagap \
+     key_diahdy \
+     key_diahth \
+     key_diainstant \
+     key_diaspr \
+     key_dimgout \
+     key_dtasal \
+     key_dtatem \
+     key_dynldf_c1d \
+     key_dynldf_c2d \
+     key_dynldf_c3d \
+     key_dynspg_exp \
+     key_dynspg_flt \
+     key_dynspg_rl \
+     key_dynspg_ts \
+     key_ecmwf_dynmem \
+     key_eel_r2 \
+     key_eel_r5 \
+     key_eel_r6 \
+     key_esopa \
+     key_feti \
+     key_floats \
+     key_flx_bulk_monthly \
+     key_flx_core \
+     key_flx_forced_daily \
+     key_gyre \
+     key_islands \
+     key_kppcustom \
+     key_kpplktb \
+     key_ldfslp \
+     key_lim2 \
+     key_lim3 \
+     key_mpp \
+     key_mpp_dyndist \
+     key_mpp_mpi \
+     key_mpp_shmem \
+     key_noslip_accurate \
+     key_oasis3 \
+     key_oasis4 \
+     key_obc \
+     key_orca_lev10 \
+     key_orca_r025 \
+     key_orca_r05 \
+     key_orca_r2 \
+     key_orca_r4 \
+     key_pisces \
+     key_pomme_r025 \
+     key_sbc_cpl \
+     key_sigma_vvl \
+     key_sp \
+     key_tam \
+     key_top \
+     key_trabbc \
+     key_trabbl_adv \
+     key_trabbl_dif \
+     key_tradmp \
+     key_traldf_ano \
+     key_traldf_c1d \
+     key_traldf_c2d \
+     key_traldf_c3d \
+     key_traldf_eiv \
+     key_trddyn \
+     key_trdmld \
+     key_trdtra \
+     key_trdvor \
+     key_vectopt_loop \
+     key_vectopt_memory \
+     key_vvl \
+     key_zco \
+     key_zdfcst \
+     key_zdfddm \
+     key_zdfkpp \
+     key_zdfric \
+     key_zdftke 
+# .o file list in the library
+LIB_OBJ = \
+		$(MODEL_LIB)(lib_cray.o)\
+		$(MODEL_LIB)(lib_isml.o)\
+		$(MODEL_LIB)(lib_print.o)\
+		$(MODEL_LIB)(agrif_opa_interp.o)\
+		$(MODEL_LIB)(agrif_opa_sponge.o)\
+		$(MODEL_LIB)(agrif_opa_update.o)\
+		$(MODEL_LIB)(albedo.o)\
+		$(MODEL_LIB)(bdy_oce.o)\
+		$(MODEL_LIB)(bdy_par.o)\
+		$(MODEL_LIB)(bdydta.o)\
+		$(MODEL_LIB)(bdydyn.o)\
+		$(MODEL_LIB)(bdyini.o)\
+		$(MODEL_LIB)(bdytides.o)\
+		$(MODEL_LIB)(bdytra.o)\
+		$(MODEL_LIB)(bdyvol.o)\
+		$(MODEL_LIB)(c1d.o)\
+		$(MODEL_LIB)(cla.o)\
+		$(MODEL_LIB)(cla_div.o)\
+		$(MODEL_LIB)(cla_div_tam.o)\
+		$(MODEL_LIB)(cla_dynspg.o)\
+		$(MODEL_LIB)(cla_dynspg_tam.o)\
+		$(MODEL_LIB)(cla_tam.o)\
+		$(MODEL_LIB)(closea.o)\
+		$(MODEL_LIB)(closea_tam.o)\
+		$(MODEL_LIB)(cpl_oasis3.o)\
+		$(MODEL_LIB)(cpl_oasis4.o)\
+		$(MODEL_LIB)(cpl_oce.o)\
+		$(MODEL_LIB)(ctlopn.o)\
+		$(MODEL_LIB)(daymod.o)\
+		$(MODEL_LIB)(daymod_tam.o)\
+		$(MODEL_LIB)(diadimg.o)\
+		$(MODEL_LIB)(diafwb.o)\
+		$(MODEL_LIB)(diagap.o)\
+		$(MODEL_LIB)(diahdy.o)\
+		$(MODEL_LIB)(diahth.o)\
+		$(MODEL_LIB)(dianam.o)\
+		$(MODEL_LIB)(diaptr.o)\
+		$(MODEL_LIB)(diaspr.o)\
+		$(MODEL_LIB)(diawri.o)\
+		$(MODEL_LIB)(diawri_c1d.o)\
+		$(MODEL_LIB)(divcur.o)\
+		$(MODEL_LIB)(divcur_tam.o)\
+		$(MODEL_LIB)(dom_oce.o)\
+		$(MODEL_LIB)(domain.o)\
+		$(MODEL_LIB)(domcfg.o)\
+		$(MODEL_LIB)(domhgr.o)\
+		$(MODEL_LIB)(dommsk.o)\
+		$(MODEL_LIB)(domstp.o)\
+		$(MODEL_LIB)(domvvl.o)\
+		$(MODEL_LIB)(domwri.o)\
+		$(MODEL_LIB)(domzgr.o)\
+		$(MODEL_LIB)(dotprodfld.o)\
+		$(MODEL_LIB)(dtasal.o)\
+		$(MODEL_LIB)(dtatem.o)\
+		$(MODEL_LIB)(dynadv.o)\
+		$(MODEL_LIB)(dynadv_cen2.o)\
+		$(MODEL_LIB)(dynadv_tam.o)\
+		$(MODEL_LIB)(dynadv_ubs.o)\
+		$(MODEL_LIB)(dyncor_c1d.o)\
+		$(MODEL_LIB)(dynhpg.o)\
+		$(MODEL_LIB)(dynhpg_tam.o)\
+		$(MODEL_LIB)(dynkeg.o)\
+		$(MODEL_LIB)(dynkeg_tam.o)\
+		$(MODEL_LIB)(dynldf.o)\
+		$(MODEL_LIB)(dynldf_bilap.o)\
+		$(MODEL_LIB)(dynldf_bilap_tam.o)\
+		$(MODEL_LIB)(dynldf_bilapg.o)\
+		$(MODEL_LIB)(dynldf_iso.o)\
+		$(MODEL_LIB)(dynldf_lap.o)\
+		$(MODEL_LIB)(dynldf_lap_tam.o)\
+		$(MODEL_LIB)(dynldf_tam.o)\
+		$(MODEL_LIB)(dynnxt.o)\
+		$(MODEL_LIB)(dynnxt_c1d.o)\
+		$(MODEL_LIB)(dynnxt_tam.o)\
+		$(MODEL_LIB)(dynspg.o)\
+		$(MODEL_LIB)(dynspg_exp.o)\
+		$(MODEL_LIB)(dynspg_flt.o)\
+		$(MODEL_LIB)(dynspg_flt_tam.o)\
+		$(MODEL_LIB)(dynspg_oce.o)\
+		$(MODEL_LIB)(dynspg_rl.o)\
+		$(MODEL_LIB)(dynspg_tam.o)\
+		$(MODEL_LIB)(dynspg_ts.o)\
+		$(MODEL_LIB)(dynvor.o)\
+		$(MODEL_LIB)(dynvor_tam.o)\
+		$(MODEL_LIB)(dynzad.o)\
+		$(MODEL_LIB)(dynzad_tam.o)\
+		$(MODEL_LIB)(dynzdf.o)\
+		$(MODEL_LIB)(dynzdf_exp.o)\
+		$(MODEL_LIB)(dynzdf_exp_tam.o)\
+		$(MODEL_LIB)(dynzdf_imp.o)\
+		$(MODEL_LIB)(dynzdf_imp_tam.o)\
+		$(MODEL_LIB)(dynzdf_tam.o)\
+		$(MODEL_LIB)(eosbn2.o)\
+		$(MODEL_LIB)(eosbn2_tam.o)\
+		$(MODEL_LIB)(fldread.o)\
+		$(MODEL_LIB)(flo4rk.o)\
+		$(MODEL_LIB)(flo_oce.o)\
+		$(MODEL_LIB)(floats.o)\
+		$(MODEL_LIB)(floblk.o)\
+		$(MODEL_LIB)(flodom.o)\
+		$(MODEL_LIB)(flowri.o)\
+		$(MODEL_LIB)(geo2ocean.o)\
+		$(MODEL_LIB)(gridrandom.o)\
+		$(MODEL_LIB)(gridsum.o)\
+		$(MODEL_LIB)(ice_oce.o)\
+		$(MODEL_LIB)(in_out_manager.o)\
+		$(MODEL_LIB)(iom.o)\
+		$(MODEL_LIB)(iom_def.o)\
+		$(MODEL_LIB)(iom_ioipsl.o)\
+		$(MODEL_LIB)(iom_nf90.o)\
+		$(MODEL_LIB)(iom_rstdimg.o)\
+		$(MODEL_LIB)(istate.o)\
+		$(MODEL_LIB)(istate_mod.o)\
+		$(MODEL_LIB)(istate_tam.o)\
+		$(MODEL_LIB)(lbclnk.o)\
+		$(MODEL_LIB)(lbclnk_tam.o)\
+		$(MODEL_LIB)(ldfdyn.o)\
+		$(MODEL_LIB)(ldfdyn_oce.o)\
+		$(MODEL_LIB)(ldfeiv.o)\
+		$(MODEL_LIB)(ldfslp.o)\
+		$(MODEL_LIB)(ldftra.o)\
+		$(MODEL_LIB)(ldftra_oce.o)\
+		$(MODEL_LIB)(lib_feti.o)\
+		$(MODEL_LIB)(lib_mpp.o)\
+		$(MODEL_LIB)(lib_mpp_tam.o)\
+		$(MODEL_LIB)(model_tam.o)\
+		$(MODEL_LIB)(mpp_tam.o)\
+		$(MODEL_LIB)(mppallgatherv.o)\
+		$(MODEL_LIB)(mppini.o)\
+		$(MODEL_LIB)(mppsum.o)\
+		$(MODEL_LIB)(mppsumtam.o)\
+		$(MODEL_LIB)(nemotam.o)\
+		$(MODEL_LIB)(oasis4_date.o)\
+		$(MODEL_LIB)(obc_oce.o)\
+		$(MODEL_LIB)(obc_par.o)\
+		$(MODEL_LIB)(obccli.o)\
+		$(MODEL_LIB)(obcdom.o)\
+		$(MODEL_LIB)(obcdta.o)\
+		$(MODEL_LIB)(obcdyn.o)\
+		$(MODEL_LIB)(obcdyn_bt.o)\
+		$(MODEL_LIB)(obcdyn_tam.o)\
+		$(MODEL_LIB)(obcfla.o)\
+		$(MODEL_LIB)(obcini.o)\
+		$(MODEL_LIB)(obcrad.o)\
+		$(MODEL_LIB)(obcrst.o)\
+		$(MODEL_LIB)(obcspg.o)\
+		$(MODEL_LIB)(obctra.o)\
+		$(MODEL_LIB)(obctra_tam.o)\
+		$(MODEL_LIB)(obcvol.o)\
+		$(MODEL_LIB)(oce.o)\
+		$(MODEL_LIB)(oce_tam.o)\
+		$(MODEL_LIB)(opa.o)\
+		$(MODEL_LIB)(opatam_tst_ini.o)\
+		$(MODEL_LIB)(par_kind.o)\
+		$(MODEL_LIB)(par_oce.o)\
+		$(MODEL_LIB)(par_tlm.o)\
+		$(MODEL_LIB)(paresp.o)\
+		$(MODEL_LIB)(phycst.o)\
+		$(MODEL_LIB)(prtctl.o)\
+		$(MODEL_LIB)(ran_num.o)\
+		$(MODEL_LIB)(restart.o)\
+		$(MODEL_LIB)(sbc_ice.o)\
+		$(MODEL_LIB)(sbc_oce.o)\
+		$(MODEL_LIB)(sbc_oce_tam.o)\
+		$(MODEL_LIB)(sbcana.o)\
+		$(MODEL_LIB)(sbcana_tam.o)\
+		$(MODEL_LIB)(sbcblk_clio.o)\
+		$(MODEL_LIB)(sbcblk_core.o)\
+		$(MODEL_LIB)(sbccpl.o)\
+		$(MODEL_LIB)(sbcflx.o)\
+		$(MODEL_LIB)(sbcflx_tam.o)\
+		$(MODEL_LIB)(sbcfwb.o)\
+		$(MODEL_LIB)(sbcfwb_tam.o)\
+		$(MODEL_LIB)(sbcice_if.o)\
+		$(MODEL_LIB)(sbcice_lim.o)\
+		$(MODEL_LIB)(sbcice_lim_2.o)\
+		$(MODEL_LIB)(sbcmod.o)\
+		$(MODEL_LIB)(sbcmod_tam.o)\
+		$(MODEL_LIB)(sbcrnf.o)\
+		$(MODEL_LIB)(sbcssm.o)\
+		$(MODEL_LIB)(sbcssm_tam.o)\
+		$(MODEL_LIB)(sbcssr.o)\
+		$(MODEL_LIB)(sbcssr_tam.o)\
+		$(MODEL_LIB)(sms.o)\
+		$(MODEL_LIB)(sol_oce.o)\
+		$(MODEL_LIB)(sol_oce_tam.o)\
+		$(MODEL_LIB)(solfet.o)\
+		$(MODEL_LIB)(solfet_tam.o)\
+		$(MODEL_LIB)(solisl.o)\
+		$(MODEL_LIB)(solmat.o)\
+		$(MODEL_LIB)(solpcg.o)\
+		$(MODEL_LIB)(solpcg_tam.o)\
+		$(MODEL_LIB)(solsor.o)\
+		$(MODEL_LIB)(solsor_tam.o)\
+		$(MODEL_LIB)(solver.o)\
+		$(MODEL_LIB)(step.o)\
+		$(MODEL_LIB)(step_c1d.o)\
+		$(MODEL_LIB)(step_tam.o)\
+		$(MODEL_LIB)(stpctl.o)\
+		$(MODEL_LIB)(stpctl_tam.o)\
+		$(MODEL_LIB)(tamctl.o)\
+		$(MODEL_LIB)(tamtrj.o)\
+		$(MODEL_LIB)(tamtst.o)\
+		$(MODEL_LIB)(traadv.o)\
+		$(MODEL_LIB)(traadv_cen2.o)\
+		$(MODEL_LIB)(traadv_cen2_tam.o)\
+		$(MODEL_LIB)(traadv_eiv.o)\
+		$(MODEL_LIB)(traadv_eiv_tam.o)\
+		$(MODEL_LIB)(traadv_muscl.o)\
+		$(MODEL_LIB)(traadv_muscl2.o)\
+		$(MODEL_LIB)(traadv_qck.o)\
+		$(MODEL_LIB)(traadv_tam.o)\
+		$(MODEL_LIB)(traadv_tvd.o)\
+		$(MODEL_LIB)(traadv_ubs.o)\
+		$(MODEL_LIB)(trabbc.o)\
+		$(MODEL_LIB)(trabbc_tam.o)\
+		$(MODEL_LIB)(trabbl.o)\
+		$(MODEL_LIB)(tradmp.o)\
+		$(MODEL_LIB)(tradmp_tam.o)\
+		$(MODEL_LIB)(traldf.o)\
+		$(MODEL_LIB)(traldf_bilap.o)\
+		$(MODEL_LIB)(traldf_bilapg.o)\
+		$(MODEL_LIB)(traldf_iso.o)\
+		$(MODEL_LIB)(traldf_iso_tam.o)\
+		$(MODEL_LIB)(traldf_lap.o)\
+		$(MODEL_LIB)(traldf_lap_tam.o)\
+		$(MODEL_LIB)(traldf_tam.o)\
+		$(MODEL_LIB)(tranpc.o)\
+		$(MODEL_LIB)(tranxt.o)\
+		$(MODEL_LIB)(tranxt_tam.o)\
+		$(MODEL_LIB)(traqsr.o)\
+		$(MODEL_LIB)(traqsr_tam.o)\
+		$(MODEL_LIB)(trasbc.o)\
+		$(MODEL_LIB)(trasbc_tam.o)\
+		$(MODEL_LIB)(trazdf.o)\
+		$(MODEL_LIB)(trazdf_exp.o)\
+		$(MODEL_LIB)(trazdf_exp_tam.o)\
+		$(MODEL_LIB)(trazdf_imp.o)\
+		$(MODEL_LIB)(trazdf_imp_tam.o)\
+		$(MODEL_LIB)(trazdf_tam.o)\
+		$(MODEL_LIB)(trc_oce.o)\
+		$(MODEL_LIB)(trc_oce_tam.o)\
+		$(MODEL_LIB)(trcini.o)\
+		$(MODEL_LIB)(trcstp.o)\
+		$(MODEL_LIB)(trdicp.o)\
+		$(MODEL_LIB)(trdicp_oce.o)\
+		$(MODEL_LIB)(trdmld.o)\
+		$(MODEL_LIB)(trdmld_oce.o)\
+		$(MODEL_LIB)(trdmld_rst.o)\
+		$(MODEL_LIB)(trdmod.o)\
+		$(MODEL_LIB)(trdmod_oce.o)\
+		$(MODEL_LIB)(trdvor.o)\
+		$(MODEL_LIB)(trdvor_oce.o)\
+		$(MODEL_LIB)(trj_tam.o)\
+		$(MODEL_LIB)(tstool_tam.o)\
+		$(MODEL_LIB)(wzvmod.o)\
+		$(MODEL_LIB)(wzvmod_tam.o)\
+		$(MODEL_LIB)(zdf_oce.o)\
+		$(MODEL_LIB)(zdfbfr.o)\
+		$(MODEL_LIB)(zdfddm.o)\
+		$(MODEL_LIB)(zdfevd.o)\
+		$(MODEL_LIB)(zdfini.o)\
+		$(MODEL_LIB)(zdfkpp.o)\
+		$(MODEL_LIB)(zdfkpp_tam.o)\
+		$(MODEL_LIB)(zdfmxl.o)\
+		$(MODEL_LIB)(zdfric.o)\
+		$(MODEL_LIB)(zdftke.o)\
+		$(MODEL_LIB)(zpshde.o)\
+		$(MODEL_LIB)(zpshde_tam.o)
+
+.SUFFIXES: .f90 .F90 .F
+
+# Target
+all: 		diroce $(EXEC_BIN)
+		@cp SRC_FILE_LIST.temp SRC_FILE_LIST
+		@echo OPATAM model is OK
+# Cleaning objects, libraries and executables
+clean:
+ifeq ($(AGRIF),use)
+		-@(cd OPAFILES; ./efface)
+endif
+		$(RM) model_tam.o $(MODDIR)/ocetam/*.mod $(MODEL_LIB) $(SXMODEL_LIB) $(EXEC_BIN)
+		@echo OPATAM model \(.o .mod libraries and executables are removed\)
+
+# Dependancies
+diroce:
+		@if [ ! -d ../../../lib/ocetam ] ; then mkdir ../../../lib/ocetam ; fi
+
+$(EXEC_BIN) :	libioipsl firstagrif mpiagrif key keyverif  src_file_list libagrif $(MODEL_LIB) $(IOIPSL_LIB) $(AGRIF_LIB) agrif2model.o model_tam.o
+ifeq ($(AGRIF),use)
+		$(F_L) $(L_X) -o $(EXEC_BIN) model_tam.o agrif2model.o $(SXMODEL_LIB) $(OASISMPI2_LIB) $(IOIPSL_LIB) $(AGRIF_LIB) $(NCDF_LIB) $(LIBMPI) $(LIBMP)
+else
+		$(F_L) $(L_X) -o $(EXEC_BIN) model_tam.o $(SXMODEL_LIB) $(OASISMPI2_LIB) $(IOIPSL_LIB) $(NCDF_LIB) $(LIBMPI) $(LIBMP)
+endif
+
+# Agrif library and conv
+libagrif :
+ifeq ($(AGRIF),use)
+	@( if [ ! -d OPAFILES ]; then mkdir OPAFILES; fi )
+	@( if [ ! -d OPAFILES/AGRIF_INC ]; then mkdir OPAFILES/AGRIF_INC ; fi )
+	@( if [ ! -d OPAFILES/AGRIF_MODELFILES ]; then mkdir OPAFILES/AGRIF_MODELFILES ; fi )
+	@(cd ../../AGRIF ; $(M_K) -f Makefile P_P="$(AGRIF_MPI)" )
+	@cp -rf ../../AGRIF/agrif_opa.in OPAFILES/. 
+	@cp -rf ../../AGRIF/conv OPAFILES/. 
+	@cp -rf ../../AGRIF/efface OPAFILES/. 
+endif
+
+# Agrif interface with NEMO
+agrif2model.o :
+ifeq ($(AGRIF),use)
+	@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC $*.F90 > OPAFILES/$*.F90 
+	@$(F_C) \
+#-Q- aix		-qsuffix=f=F90 \
+#-Q- babel		-qsuffix=f=F90 \
+#-Q- osxxlf		-qsuffix=f=F90 \
+	$(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+#-Q- babel		-qsource \
+	   OPAFILES/$*.F90 || { mv $(PREF).L $(TMP) ; false ; exit ; }
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux			@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+endif
+
+# IOIPSL library 
+libioipsl :
+	(cd ../../IOIPSL/src ; $(M_K) -f Makefile )
+
+# Main program
+model_tam.o :	model_tam.F90
+		@$(F_C) $(F_O) -c model_tam.F90
+
+# if the make script is stopped, one doesn't destroy library
+.PRECIOUS : $(MODEL_LIB)
+#-Q- sxdkrz .PRECIOUS : $(SXMODEL_LIB)
+#-Q- eshpux .PRECIOUS : $(SXMODEL_LIB)
+
+# library dependancies
+$(MODEL_LIB):	$(LIB_OBJ)
+		@echo
+		@echo The library is up-to-date
+		@echo
+
+# Default rules
+.DEFAULTS:
+
+# rules for the .f90 files
+.f90.a :           
+		@$(F_C) $(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+#-Q- babel		-qsource \
+		$*.f90 || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; }
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+		@$(A_C) $(MODEL_LIB) $*.o  > /dev/null
+		@$(RM) $*.[of]
+		@if [ -f $*.mod ] ; then mv $*.mod $(MODDIR)/ocetam ; fi
+#-Q- aix		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- babel		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- linux		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- osxxlf		@mv $(PREF)$*.lst $(PREF)$*.L
+		@if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi
+
+# rules for the .F90 files
+.F90.a :  
+ifeq ($(AGRIF),use) 
+		@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC $*.F90 > OPAFILES/$*.F90 
+		@(cd OPAFILES ; ./conv agrif_opa.in -rm \
+#-Q- linux		-SubloopScalar \
+#-Q- g95			-SubloopScalar \
+#-Q- f95			-SubloopScalar \
+#-Q- osf1			-SubloopScalar \
+		-comdirin ./ -comdirout AGRIF_MODELFILES/. -convfile $*.F90)
+		-@mv -f OPAFILES/AGRIF_MODELFILES/$*.F90 OPAFILES/$*.F90
+		@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC OPAFILES/$*.F90 > OPAFILES/AGRIF_MODELFILES/$*.F90
+		-@mv -f OPAFILES/AGRIF_MODELFILES/$*.F90 OPAFILES/$*.F90
+		@$(F_C) $(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+#-Q- babel		-qsource \
+		OPAFILES/$*.F90 || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; } 
+else
+		@$(F_C) $(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+#-Q- babel		-qsource \
+		$*.F90 || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; }
+endif
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+		@$(A_C) $(MODEL_LIB) $*.o  > /dev/null
+		@$(RM) $*.[of]
+		@if [ -f $*.mod ] ; then mv $*.mod $(MODDIR)/ocetam ; fi
+#-Q- aix		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- babel		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- linux		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- osxxlf		@mv $(PREF)$*.lst $(PREF)$*.L
+		@if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi
+
+# rules for the .F files
+.F.a :           
+ifeq ($(AGRIF),use) 
+		@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC $*.F > OPAFILES/$*.F 
+		@(cd OPAFILES ; ./conv agrif_opa.in -rm \
+#-Q- linux		-SubloopScalar \
+#-Q- g95			-SubloopScalar \
+#-Q- f95			-SubloopScalar \
+#-Q- osf1			-SubloopScalar \
+		-comdirin ./ -comdirout AGRIF_MODELFILES/. -convfile $*.F)
+		-@mv -f OPAFILES/AGRIF_MODELFILES/$*.F OPAFILES/$*.F
+		@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC OPAFILES/$*.F > OPAFILES/AGRIF_MODELFILES/$*.F
+		-@mv -f OPAFILES/AGRIF_MODELFILES/$*.F OPAFILES/$*.F
+		@$(F_C) $(P_P) $(F_F) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+#-Q- babel		-qsource \
+		OPAFILES/$*.F || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; } 
+else
+		@$(F_C) $(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+#-Q- babel		-qsource \
+		$*.F || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; }
+endif
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+		@$(A_C) $(MODEL_LIB) $*.o  > /dev/null
+		@$(RM) $*.[of]
+		@if [ -f $*.mod ] ; then mv $*.mod $(MODDIR)/ocetam ; fi
+#-Q- aix		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- babel		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- linux		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- osxxlf		@mv $(PREF)$*.lst $(PREF)$*.L
+		@if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi
+
+# rules for the library from the .f files 
+.f.a : 		
+		@$(F_C) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+#-Q- babel		-qsource \
+		$*.f|| { if [ -f $(PREF)$*.L ] ; then mv $*.L $(TMP) ; fi ; false ; exit ; }
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+		@$(A_C) $(MODEL_LIB) $*.o  > /dev/null
+		@$(RM) -f $*.o
+#-Q- aix		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- babel		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- linux	@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- osxxlf		@mv $(PREF)$*.lst $(PREF)$*.L
+		@if [ -f $(PREF)$*.L ] ; then mv $*.L $(TMP) ; fi
+
+$(MODEL_LIB)(agrif_opa_interp.o) :	\
+	agrif_opa_interp.F90
+$(MODEL_LIB)(agrif_opa_sponge.o) :	\
+	agrif_opa_sponge.F90
+$(MODEL_LIB)(agrif_opa_update.o) :	\
+	agrif_opa_update.F90
+$(MODEL_LIB)(albedo.o) :	\
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(phycst.o) \
+	in_out_manager.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	albedo.F90
+$(MODEL_LIB)(bdy_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	bdy_par.F90 \
+	par_oce.F90 \
+	KEY_CPP \
+	bdy_oce.F90
+$(MODEL_LIB)(bdy_par.o) :	\
+	KEY_CPP \
+	bdy_par.F90
+$(MODEL_LIB)(bdydta.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdytides.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	bdy_oce.F90 \
+	bdytides.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	oce.F90 \
+	phycst.F90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	bdydta.F90
+$(MODEL_LIB)(bdydyn.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdytides.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	bdy_oce.F90 \
+	bdytides.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	bdydyn.F90
+$(MODEL_LIB)(bdyini.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdytides.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	bdy_oce.F90 \
+	bdytides.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	KEY_CPP \
+	bdyini.F90
+$(MODEL_LIB)(bdytides.o) :	\
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	bdy_par.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	bdytides.F90
+$(MODEL_LIB)(bdytra.o) :	\
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	bdy_par.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	bdy_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	KEY_CPP \
+	bdytra.F90
+$(MODEL_LIB)(bdyvol.o) :	\
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	bdy_par.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	bdy_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	bdyvol.F90
+$(MODEL_LIB)(c1d.o) :	\
+	KEY_CPP \
+	c1d.F90
+$(MODEL_LIB)(cla.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	cla.F90
+$(MODEL_LIB)(cla_div.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	cla_div.F90
+$(MODEL_LIB)(cla_div_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_mpp_tam.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	ran_num.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	lib_mpp.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce_tam.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	cla_div_tam.F90
+$(MODEL_LIB)(cla_dynspg.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obccli.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	obcdyn.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	cla_dynspg.F90
+$(MODEL_LIB)(cla_dynspg_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	sbc_oce_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	cla_dynspg_tam.F90
+$(MODEL_LIB)(cla_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	ran_num.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	paresp.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	cla_tam.F90
+$(MODEL_LIB)(closea.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	sbc_oce.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	closea.F90
+$(MODEL_LIB)(closea_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_mpp_tam.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	ran_num.F90 \
+	sbc_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	closea.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	lib_mpp.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	paresp.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	closea_tam.F90
+$(MODEL_LIB)(cpl_oasis3.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_ice.F90 \
+	KEY_CPP \
+	cpl_oasis3.F90
+$(MODEL_LIB)(cpl_oasis4.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oasis4_date.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oasis4_date.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	cpl_oasis4.F90
+$(MODEL_LIB)(cpl_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	cpl_oce.F90
+$(MODEL_LIB)(ctlopn.o) :	\
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	in_out_manager.F90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	ctlopn.F90
+$(MODEL_LIB)(daymod.o) :	\
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	c1d.F90 \
+	cpl_oce.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	trdmld_oce.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	daymod.F90
+$(MODEL_LIB)(daymod_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(phycst.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	par_kind.F90 \
+	phycst.F90 \
+	daymod_tam.F90
+$(MODEL_LIB)(diadimg.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	diadimg.F90
+$(MODEL_LIB)(diafwb.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	diafwb.F90
+$(MODEL_LIB)(diagap.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	diagap.F90
+$(MODEL_LIB)(diahdy.o) :	\
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	diahdy.F90
+$(MODEL_LIB)(diahth.o) :	\
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	diahth.F90
+$(MODEL_LIB)(dianam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(phycst.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	dianam.F90
+$(MODEL_LIB)(diaptr.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	diaptr.F90
+$(MODEL_LIB)(diaspr.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	KEY_CPP \
+	diaspr.F90
+$(MODEL_LIB)(diawri.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	fldread.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbcrnf.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcssr.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	dom_oce.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_ice.F90 \
+	sbc_oce.F90 \
+	sbcssr.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(lib_mpp.o) \
+	lib_mpp.F90 \
+	diawri_dimg.h90 \
+	zdfddm_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	diawri.F90
+$(MODEL_LIB)(diawri_c1d.o) :	\
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcana.o) \
+	$(MODEL_LIB)(sbcblk_clio.o) \
+	$(MODEL_LIB)(sbcblk_core.o) \
+	$(MODEL_LIB)(sbccpl.o) \
+	$(MODEL_LIB)(sbcflx.o) \
+	$(MODEL_LIB)(sbcfwb.o) \
+	$(MODEL_LIB)(sbcice_if.o) \
+	$(MODEL_LIB)(sbcice_lim.o) \
+	$(MODEL_LIB)(sbcice_lim_2.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(sbcssm.o) \
+	$(MODEL_LIB)(sbcssr.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	closea.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	fldread.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_ice.F90 \
+	sbc_oce.F90 \
+	sbcana.F90 \
+	sbcblk_clio.F90 \
+	sbcblk_core.F90 \
+	sbccpl.F90 \
+	sbcflx.F90 \
+	sbcfwb.F90 \
+	sbcice_if.F90 \
+	sbcice_lim.F90 \
+	sbcice_lim_2.F90 \
+	sbcrnf.F90 \
+	sbcssm.F90 \
+	sbcssr.F90 \
+	sol_oce.F90 \
+	trazdf_exp.F90 \
+	trdmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcmod.o) \
+	$(MODEL_LIB)(sbcssr.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	daymod.F90 \
+	dianam.F90 \
+	diawri.F90 \
+	dom_oce.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_ice.F90 \
+	sbc_oce.F90 \
+	sbcmod.F90 \
+	sbcssr.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdftke.F90 \
+	zdfddm_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	diawri_c1d.F90
+$(MODEL_LIB)(divcur.o) :	\
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	bdy_par.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	bdy_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	divcur.F90
+$(MODEL_LIB)(divcur_tam.o) :	\
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	bdy_par.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_mpp_tam.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	ran_num.F90 \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	bdy_oce.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	divcur_tam.F90
+$(MODEL_LIB)(dom_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	dom_oce.F90
+$(MODEL_LIB)(domain.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	bdy_oce.F90 \
+	c1d.F90 \
+	closea.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	solisl.F90 \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domhgr.o) \
+	$(MODEL_LIB)(dommsk.o) \
+	$(MODEL_LIB)(domstp.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(domwri.o) \
+	$(MODEL_LIB)(domzgr.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	closea.F90 \
+	dom_oce.F90 \
+	domhgr.F90 \
+	dommsk.F90 \
+	domstp.F90 \
+	domvvl.F90 \
+	domwri.F90 \
+	domzgr.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	domain.F90
+$(MODEL_LIB)(domcfg.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solisl.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	phycst.F90 \
+	solisl.F90 \
+	domcfg.F90
+$(MODEL_LIB)(domhgr.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	domhgr.F90
+$(MODEL_LIB)(dommsk.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	solisl.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dommsk.F90
+$(MODEL_LIB)(domstp.o) :	\
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	domstp.F90
+$(MODEL_LIB)(domvvl.o) :	\
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	bdy_par.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	bdy_oce.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	domvvl.F90
+$(MODEL_LIB)(domwri.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	domwri.F90
+$(MODEL_LIB)(domzgr.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sbc_oce.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	c1d.F90 \
+	closea.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	solisl.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	domzgr.F90
+$(MODEL_LIB)(dotprodfld.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mpp_tam.o) \
+	$(MODEL_LIB)(mppsum.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	mpp_tam.F90 \
+	mppsum.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	dom_oce.F90 \
+	mppsumtam.F90 \
+	par_kind.F90 \
+	dotprodfld.F90
+$(MODEL_LIB)(dtasal.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	dtasal.F90
+$(MODEL_LIB)(dtatem.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	dtatem.F90
+$(MODEL_LIB)(dynadv.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynadv_cen2.o) \
+	$(MODEL_LIB)(dynadv_ubs.o) \
+	$(MODEL_LIB)(dynkeg.o) \
+	$(MODEL_LIB)(dynzad.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	dom_oce.F90 \
+	dynadv_cen2.F90 \
+	dynadv_ubs.F90 \
+	dynkeg.F90 \
+	dynzad.F90 \
+	in_out_manager.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynadv.F90
+$(MODEL_LIB)(dynadv_cen2.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	solver.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynadv_cen2.F90
+$(MODEL_LIB)(dynadv_tam.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(divcur_tam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv_cen2.o) \
+	$(MODEL_LIB)(dynadv_ubs.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynkeg.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynzad.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opa.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdyini.F90 \
+	c1d.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	divcur.F90 \
+	divcur_tam.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	domvvl.F90 \
+	dotprodfld.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dynadv_cen2.F90 \
+	dynadv_ubs.F90 \
+	dyncor_c1d.F90 \
+	dynkeg.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	dynzad.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	ldfdyn.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	mppini.F90 \
+	mppsumtam.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcini.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opa.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	solisl.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	tradmp.F90 \
+	trc_oce_tam.F90 \
+	trcini.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfini.F90 \
+	zdfmxl.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(divcur_tam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynkeg_tam.o) \
+	$(MODEL_LIB)(dynzad_tam.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(wzvmod_tam.o) \
+	divcur.F90 \
+	divcur_tam.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynadv.F90 \
+	dynkeg_tam.F90 \
+	dynzad_tam.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	istate_mod.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	wzvmod_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynadv_tam.F90
+$(MODEL_LIB)(dynadv_ubs.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	solver.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynadv_ubs.F90
+$(MODEL_LIB)(dyncor_c1d.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dyncor_c1d.F90
+$(MODEL_LIB)(dynhpg.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynhpg.F90
+$(MODEL_LIB)(dynhpg_tam.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(eosbn2_tam.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opa.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdyini.F90 \
+	c1d.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	domvvl.F90 \
+	dotprodfld.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dyncor_c1d.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	eosbn2.F90 \
+	eosbn2_tam.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate.F90 \
+	istate_mod.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	ldfdyn.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	mppini.F90 \
+	mppsumtam.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcini.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opa.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	solisl.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	tradmp.F90 \
+	trc_oce_tam.F90 \
+	trcini.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfini.F90 \
+	zdfmxl.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynhpg.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(eosbn2_tam.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	$(MODEL_LIB)(zpshde_tam.o) \
+	divcur.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynhpg.F90 \
+	eosbn2.F90 \
+	eosbn2_tam.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	istate_mod.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	phycst.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	zpshde.F90 \
+	zpshde_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynhpg_tam.F90
+$(MODEL_LIB)(dynkeg.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynkeg.F90
+$(MODEL_LIB)(dynkeg_tam.o) :	\
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynkeg_tam.F90
+$(MODEL_LIB)(dynldf.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynldf_bilap.o) \
+	$(MODEL_LIB)(dynldf_bilapg.o) \
+	$(MODEL_LIB)(dynldf_iso.o) \
+	$(MODEL_LIB)(dynldf_lap.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	dynldf_bilap.F90 \
+	dynldf_bilapg.F90 \
+	dynldf_iso.F90 \
+	dynldf_lap.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf.F90
+$(MODEL_LIB)(dynldf_bilap.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf_bilap.F90
+$(MODEL_LIB)(dynldf_bilap_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_mpp_tam.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	ldfdyn_oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf_bilap_tam.F90
+$(MODEL_LIB)(dynldf_bilapg.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	KEY_CPP \
+	dynldf_bilapg.F90
+$(MODEL_LIB)(dynldf_iso.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf_iso.F90
+$(MODEL_LIB)(dynldf_lap.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf_lap.F90
+$(MODEL_LIB)(dynldf_lap_tam.o) :	\
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf_lap_tam.F90
+$(MODEL_LIB)(dynldf_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynldf_bilap_tam.o) \
+	$(MODEL_LIB)(dynldf_lap_tam.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynldf_bilap_tam.F90 \
+	dynldf_lap_tam.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf_tam.F90
+$(MODEL_LIB)(dynnxt.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdytides.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdytides.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obccli.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(agrif_opa_update.o) \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdydta.o) \
+	$(MODEL_LIB)(bdydyn.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obcdyn_bt.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	agrif_opa_interp.F90 \
+	agrif_opa_update.F90 \
+	bdy_oce.F90 \
+	bdydta.F90 \
+	bdydyn.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	obc_oce.F90 \
+	obcdyn.F90 \
+	obcdyn_bt.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	domzgr_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	dynnxt.F90
+$(MODEL_LIB)(dynnxt_c1d.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	KEY_CPP \
+	dynnxt_c1d.F90
+$(MODEL_LIB)(dynnxt_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_mpp_tam.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	ran_num.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynspg_oce.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	dynnxt_tam.F90
+$(MODEL_LIB)(dynspg.o) :	\
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdydta.o) \
+	$(MODEL_LIB)(bdydyn.o) \
+	$(MODEL_LIB)(bdytides.o) \
+	$(MODEL_LIB)(bdyvol.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	agrif_opa_interp.F90 \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdydta.F90 \
+	bdydyn.F90 \
+	bdytides.F90 \
+	bdyvol.F90 \
+	cla_dynspg.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	dynvor.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcdta.F90 \
+	obcdyn.F90 \
+	obcfla.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	solver.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	dynspg_ts.F90 \
+	in_out_manager.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg.F90
+$(MODEL_LIB)(dynspg_exp.o) :	\
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	c1d.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obccli.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	trdmld_oce.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcdta.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_exp.F90
+$(MODEL_LIB)(dynspg_flt.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdytides.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_feti.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdytides.F90 \
+	c1d.F90 \
+	cpl_oce.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_feti.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obccli.F90 \
+	obcdyn.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	trdmld_oce.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdydyn.o) \
+	$(MODEL_LIB)(bdyvol.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	agrif_opa_interp.F90 \
+	bdy_oce.F90 \
+	bdydyn.F90 \
+	bdyvol.F90 \
+	cla_dynspg.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	obcdyn.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solmat.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	solver.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	dynspg_flt.F90
+$(MODEL_LIB)(dynspg_flt_tam.o) :	\
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdydyn.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(bdyvol.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(gridsum.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppallgatherv.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opa.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	agrif_opa_interp.F90 \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdydyn.F90 \
+	bdyini.F90 \
+	bdyvol.F90 \
+	c1d.F90 \
+	cla_dynspg.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	domvvl.F90 \
+	dotprodfld.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dyncor_c1d.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	gridsum.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	ldfdyn.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_mpp_tam.F90 \
+	lib_print.f90 \
+	mppallgatherv.F90 \
+	mppini.F90 \
+	mppsumtam.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obccli.F90 \
+	obcdyn.F90 \
+	obcini.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opa.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	solver.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	tradmp.F90 \
+	trc_oce_tam.F90 \
+	trcini.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfini.F90 \
+	zdfmxl.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(cla_dynspg_tam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mppsum.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcdyn_tam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(solfet_tam.o) \
+	$(MODEL_LIB)(solpcg_tam.o) \
+	$(MODEL_LIB)(solsor_tam.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	cla_dynspg_tam.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynspg_flt.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	istate_mod.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	lib_mpp.F90 \
+	mppsum.F90 \
+	obc_oce.F90 \
+	obcdyn_tam.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	paresp.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	solfet_tam.F90 \
+	solpcg_tam.F90 \
+	solsor_tam.F90 \
+	solver.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_flt_tam.F90
+$(MODEL_LIB)(dynspg_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	dynspg_oce.F90
+$(MODEL_LIB)(dynspg_rl.o) :	\
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	c1d.F90 \
+	cpl_oce.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	trdmld_oce.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	solver.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	obc_vectopt_loop_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_rl.F90
+$(MODEL_LIB)(dynspg_tam.o) :	\
+	$(MODEL_LIB)(cla_dynspg_tam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsum.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcdyn_tam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(solfet_tam.o) \
+	$(MODEL_LIB)(solpcg_tam.o) \
+	$(MODEL_LIB)(solsor_tam.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	cla_dynspg_tam.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynspg_flt.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	istate_mod.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	mppsum.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcdyn_tam.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	paresp.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	solfet_tam.F90 \
+	solpcg_tam.F90 \
+	solsor_tam.F90 \
+	solver.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_flt_tam.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	dynspg_flt_tam.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	obc_oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_tam.F90
+$(MODEL_LIB)(dynspg_ts.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdytides.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdytides.F90 \
+	c1d.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dynadv.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obccli.F90 \
+	obcdta.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdydta.o) \
+	$(MODEL_LIB)(bdydyn.o) \
+	$(MODEL_LIB)(bdytides.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdydta.F90 \
+	bdydyn.F90 \
+	bdytides.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	dynvor.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcdta.F90 \
+	obcfla.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_ts.F90
+$(MODEL_LIB)(dynvor.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynadv_cen2.o) \
+	$(MODEL_LIB)(dynadv_ubs.o) \
+	$(MODEL_LIB)(dynkeg.o) \
+	$(MODEL_LIB)(dynzad.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	dynadv_cen2.F90 \
+	dynadv_ubs.F90 \
+	dynkeg.F90 \
+	dynzad.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	dynadv.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynvor.F90
+$(MODEL_LIB)(dynvor_tam.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynadv_cen2.o) \
+	$(MODEL_LIB)(dynadv_ubs.o) \
+	$(MODEL_LIB)(dynkeg.o) \
+	$(MODEL_LIB)(dynzad.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	bdy_oce.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynadv_cen2.F90 \
+	dynadv_ubs.F90 \
+	dynkeg.F90 \
+	dynzad.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	ran_num.F90 \
+	tstool_tam.F90 \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(divcur_tam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	divcur.F90 \
+	divcur_tam.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynadv.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynvor_tam.F90
+$(MODEL_LIB)(dynzad.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzad.F90
+$(MODEL_LIB)(dynzad_tam.o) :	\
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzad_tam.F90
+$(MODEL_LIB)(dynzdf.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	trazdf_exp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(dynzdf_imp.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	dynzdf_imp.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfkpp.F90 \
+	zdftke.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	dynzdf.F90
+$(MODEL_LIB)(dynzdf_exp.o) :	\
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzdf_exp.F90
+$(MODEL_LIB)(dynzdf_exp_tam.o) :	\
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	in_out_manager.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzdf_exp_tam.F90
+$(MODEL_LIB)(dynzdf_imp.o) :	\
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzdf_imp.F90
+$(MODEL_LIB)(dynzdf_imp_tam.o) :	\
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzdf_imp_tam.F90
+$(MODEL_LIB)(dynzdf_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	trazdf_exp.F90 \
+	trdmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynzdf_exp_tam.o) \
+	$(MODEL_LIB)(dynzdf_imp_tam.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynzdf_exp_tam.F90 \
+	dynzdf_imp_tam.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	tstool_tam.F90 \
+	zdf_oce.F90 \
+	zdfkpp.F90 \
+	zdftke.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	dynzdf_tam.F90
+$(MODEL_LIB)(eosbn2.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfddm.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	eosbn2.F90
+$(MODEL_LIB)(eosbn2_tam.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opa.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdyini.F90 \
+	c1d.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	domvvl.F90 \
+	dotprodfld.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dyncor_c1d.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate.F90 \
+	lbclnk.F90 \
+	ldfdyn.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	mppini.F90 \
+	mppsumtam.F90 \
+	obc_par.F90 \
+	obcini.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opa.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	solisl.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	tradmp.F90 \
+	trc_oce_tam.F90 \
+	trcini.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfini.F90 \
+	zdfmxl.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	istate_mod.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	phycst.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	zdfddm.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	eosbn2_tam.F90
+$(MODEL_LIB)(fldread.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	oce.F90 \
+	phycst.F90 \
+	fldread.F90
+$(MODEL_LIB)(flo4rk.o) :	\
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	KEY_CPP \
+	flo4rk.F90
+$(MODEL_LIB)(flo_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	flo_oce.F90
+$(MODEL_LIB)(floats.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	$(MODEL_LIB)(flo4rk.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(floblk.o) \
+	$(MODEL_LIB)(flodom.o) \
+	$(MODEL_LIB)(flowri.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	flo4rk.F90 \
+	flo_oce.F90 \
+	floblk.F90 \
+	flodom.F90 \
+	flowri.F90 \
+	lib_mpp.F90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	floats.F90
+$(MODEL_LIB)(floblk.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	floblk.F90
+$(MODEL_LIB)(flodom.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	flodom.F90
+$(MODEL_LIB)(flowri.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	flowri.F90
+$(MODEL_LIB)(geo2ocean.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	phycst.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	geo2ocean.F90
+$(MODEL_LIB)(gridrandom.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	ran_num.F90 \
+	gridrandom.F90
+$(MODEL_LIB)(gridsum.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mpp_tam.o) \
+	$(MODEL_LIB)(mppsum.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	mpp_tam.F90 \
+	mppsum.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mpp_tam.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	dom_oce.F90 \
+	lib_mpp.F90 \
+	mpp_tam.F90 \
+	mppsumtam.F90 \
+	par_kind.F90 \
+	gridsum.F90
+$(MODEL_LIB)(ice_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	ice_oce.F90
+$(MODEL_LIB)(in_out_manager.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	in_out_manager.F90
+$(MODEL_LIB)(iom.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	KEY_CPP \
+	iom.F90
+$(MODEL_LIB)(iom_def.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	iom_def.F90
+$(MODEL_LIB)(iom_ioipsl.o) :	\
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	$(IOIPSL_LIB) \
+	iom_ioipsl.F90
+$(MODEL_LIB)(iom_nf90.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	lbclnk.F90 \
+	iom_nf90.F90
+$(MODEL_LIB)(iom_rstdimg.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	lbclnk.F90 \
+	iom_rstdimg.F90
+$(MODEL_LIB)(istate.o) :	\
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdydta.o) \
+	$(MODEL_LIB)(bdydyn.o) \
+	$(MODEL_LIB)(bdytides.o) \
+	$(MODEL_LIB)(bdyvol.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	agrif_opa_interp.F90 \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdydta.F90 \
+	bdydyn.F90 \
+	bdytides.F90 \
+	bdyvol.F90 \
+	c1d.F90 \
+	cla_dynspg.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	dynspg_ts.F90 \
+	dynvor.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcdta.F90 \
+	obcdyn.F90 \
+	obcfla.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solmat.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	solver.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	c1d.F90 \
+	daymod.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dynspg.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	solisl.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	istate.F90
+$(MODEL_LIB)(istate_mod.o) :	\
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdydta.o) \
+	$(MODEL_LIB)(bdydyn.o) \
+	$(MODEL_LIB)(bdytides.o) \
+	$(MODEL_LIB)(bdyvol.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	agrif_opa_interp.F90 \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdydta.F90 \
+	bdydyn.F90 \
+	bdytides.F90 \
+	bdyvol.F90 \
+	c1d.F90 \
+	cla_dynspg.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	dynvor.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcdta.F90 \
+	obcdyn.F90 \
+	obcfla.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solmat.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	solver.F90 \
+	trdmld_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	c1d.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	solisl.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	istate_mod.F90
+$(MODEL_LIB)(istate_tam.o) :	\
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(divcur_tam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(eosbn2_tam.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	c1d.F90 \
+	cpl_oce.F90 \
+	divcur.F90 \
+	divcur_tam.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dotprodfld.F90 \
+	eosbn2.F90 \
+	eosbn2_tam.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate_mod.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	restart.F90 \
+	sbc_oce_tam.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	trdmld_oce.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(eosbn2_tam.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod_tam.o) \
+	$(MODEL_LIB)(zpshde_tam.o) \
+	c1d.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	eosbn2_tam.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	paresp.F90 \
+	restart.F90 \
+	tstool_tam.F90 \
+	wzvmod_tam.F90 \
+	zpshde_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	istate_tam.F90
+$(MODEL_LIB)(lbclnk.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	KEY_CPP \
+	lbclnk.F90
+$(MODEL_LIB)(lbclnk_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp_tam.F90 \
+	oce.F90 \
+	KEY_CPP \
+	lbclnk_tam.F90
+$(MODEL_LIB)(ldfdyn.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	ldftra_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_antarctic.h90 \
+	ldfdyn_arctic.h90 \
+	ldfdyn_c1d.h90 \
+	ldfdyn_c2d.h90 \
+	ldfdyn_c3d.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	ldfdyn.F90
+$(MODEL_LIB)(ldfdyn_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	ldfdyn_oce.F90
+$(MODEL_LIB)(ldfeiv.o) :	\
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	closea.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	fldread.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	sbcrnf.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	ldfeiv.F90
+$(MODEL_LIB)(ldfslp.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	ldfslp.F90
+$(MODEL_LIB)(ldftra.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	ldftra_c1d.h90 \
+	ldftra_c2d.h90 \
+	ldftra_c3d.h90 \
+	vectopt_loop_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	ldftra.F90
+$(MODEL_LIB)(ldftra_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	ldftra_oce.F90
+$(MODEL_LIB)(lib_cray.o) :	\
+	lib_cray.f90
+$(MODEL_LIB)(lib_feti.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(lib_mpp.o) \
+	lib_mpp.F90 \
+	KEY_CPP \
+	lib_feti.F90
+$(MODEL_LIB)(lib_isml.o) :	\
+	lib_isml.f90
+$(MODEL_LIB)(lib_mpp.o) :	\
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	lib_mpp.F90
+$(MODEL_LIB)(lib_mpp_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	KEY_CPP \
+	lib_mpp_tam.F90
+$(MODEL_LIB)(lib_print.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	lib_print.f90
+$(MODEL_LIB)(model.o) :	\
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(step.o) \
+	$(MODEL_LIB)(step_c1d.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_par.F90 \
+	bdyini.F90 \
+	c1d.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dyncor_c1d.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	istate.F90 \
+	ldfdyn.F90 \
+	ldftra.F90 \
+	lib_mpp.F90 \
+	mppini.F90 \
+	obc_par.F90 \
+	obcini.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	step.F90 \
+	step_c1d.F90 \
+	tamtrj.F90 \
+	trcini.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfini.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(opa.o) \
+	opa.F90 \
+	model.f90
+$(MODEL_LIB)(model_tam.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(tamtst.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	in_out_manager.F90 \
+	ldfdyn.F90 \
+	ldftra.F90 \
+	lib_mpp.F90 \
+	mppini.F90 \
+	obc_par.F90 \
+	obcini.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	phycst.F90 \
+	sbc_oce_tam.F90 \
+	sol_oce_tam.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	tamtst.F90 \
+	trc_oce_tam.F90 \
+	zdfini.F90 \
+	$(MODEL_LIB)(nemotam.o) \
+	nemotam.F90 \
+	KEY_CPP \
+	model_tam.F90
+$(MODEL_LIB)(mpp_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	lib_mpp.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	KEY_CPP \
+	mpp_tam.F90
+$(MODEL_LIB)(mppallgatherv.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	par_kind.F90 \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_mpp.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	KEY_CPP \
+	mppallgatherv.F90
+$(MODEL_LIB)(mppini.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	sol_oce.F90 \
+	$(MODEL_LIB)(iom.o) \
+	iom.F90 \
+	domzgr_substitute.h90 \
+	mppini_2.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	mppini.F90
+$(MODEL_LIB)(mppsum.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mppallgatherv.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	mppallgatherv.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	KEY_CPP \
+	mppsum.F90
+$(MODEL_LIB)(mppsumtam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppallgatherv.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	mppallgatherv.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mpp_tam.o) \
+	$(MODEL_LIB)(mppsum.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	mpp_tam.F90 \
+	mppsum.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	KEY_CPP \
+	mppsumtam.F90
+$(MODEL_LIB)(nemotam.o) :	\
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cla_div_tam.o) \
+	$(MODEL_LIB)(cla_tam.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(divcur_tam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(domhgr.o) \
+	$(MODEL_LIB)(dommsk.o) \
+	$(MODEL_LIB)(domstp.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(domwri.o) \
+	$(MODEL_LIB)(domzgr.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv_tam.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynhpg_tam.o) \
+	$(MODEL_LIB)(dynkeg_tam.o) \
+	$(MODEL_LIB)(dynldf_tam.o) \
+	$(MODEL_LIB)(dynnxt_tam.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_tam.o) \
+	$(MODEL_LIB)(dynvor_tam.o) \
+	$(MODEL_LIB)(dynzdf_tam.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(eosbn2_tam.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(istate_tam.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcdom.o) \
+	$(MODEL_LIB)(obcdyn_tam.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(obcrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opa.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sbcmod_tam.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solsor_tam.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(step_tam.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(traadv_tam.o) \
+	$(MODEL_LIB)(trabbc.o) \
+	$(MODEL_LIB)(trabbc_tam.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(tradmp_tam.o) \
+	$(MODEL_LIB)(traldf_tam.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(tranxt_tam.o) \
+	$(MODEL_LIB)(traqsr_tam.o) \
+	$(MODEL_LIB)(trasbc_tam.o) \
+	$(MODEL_LIB)(trazdf_tam.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(wzvmod_tam.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	$(MODEL_LIB)(zpshde_tam.o) \
+	bdy_par.F90 \
+	bdyini.F90 \
+	c1d.F90 \
+	cla_div_tam.F90 \
+	cla_tam.F90 \
+	closea.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	divcur_tam.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	domhgr.F90 \
+	dommsk.F90 \
+	domstp.F90 \
+	domvvl.F90 \
+	domwri.F90 \
+	domzgr.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dynadv_tam.F90 \
+	dyncor_c1d.F90 \
+	dynhpg_tam.F90 \
+	dynkeg_tam.F90 \
+	dynldf_tam.F90 \
+	dynnxt_tam.F90 \
+	dynspg_oce.F90 \
+	dynspg_tam.F90 \
+	dynvor_tam.F90 \
+	dynzdf_tam.F90 \
+	eosbn2.F90 \
+	eosbn2_tam.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate.F90 \
+	istate_tam.F90 \
+	lbclnk.F90 \
+	ldfdyn.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	mppini.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcdom.F90 \
+	obcdyn_tam.F90 \
+	obcini.F90 \
+	obcrst.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opa.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	paresp.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sbcmod_tam.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	solisl.F90 \
+	solsor_tam.F90 \
+	solver.F90 \
+	step_tam.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	traadv_tam.F90 \
+	trabbc.F90 \
+	trabbc_tam.F90 \
+	tradmp.F90 \
+	tradmp_tam.F90 \
+	traldf_tam.F90 \
+	tranpc.F90 \
+	tranxt_tam.F90 \
+	traqsr_tam.F90 \
+	trasbc_tam.F90 \
+	trazdf_tam.F90 \
+	trc_oce_tam.F90 \
+	trcini.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trj_tam.F90 \
+	wzvmod_tam.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfini.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	zpshde.F90 \
+	zpshde_tam.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(tamtst.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	in_out_manager.F90 \
+	ldfdyn.F90 \
+	ldftra.F90 \
+	lib_mpp.F90 \
+	mppini.F90 \
+	obc_par.F90 \
+	obcini.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	phycst.F90 \
+	sbc_oce_tam.F90 \
+	sol_oce_tam.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	tamtst.F90 \
+	trc_oce_tam.F90 \
+	zdfini.F90 \
+	KEY_CPP \
+	nemotam.F90
+$(MODEL_LIB)(oasis4_date.o) :	\
+	KEY_CPP \
+	oasis4_date.F90
+$(MODEL_LIB)(obc_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	par_oce.F90 \
+	KEY_CPP \
+	obc_oce.F90
+$(MODEL_LIB)(obc_par.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	obc_par_EEL_R5.h90 \
+	obc_par_POMME_R025.h90 \
+	KEY_CPP \
+	obc_par.F90
+$(MODEL_LIB)(obccli.o) :	\
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	in_out_manager.F90 \
+	obc_par.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	obccli.F90
+$(MODEL_LIB)(obcdom.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	obc_par.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcdom.F90
+$(MODEL_LIB)(obcdta.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	obccli.F90 \
+	oce.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	obcdta.F90
+$(MODEL_LIB)(obcdyn.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	obccli.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcdyn.F90
+$(MODEL_LIB)(obcdyn_bt.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	obccli.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcdyn_bt.F90
+$(MODEL_LIB)(obcdyn_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_mpp_tam.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	ran_num.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynspg_oce.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	obccli.F90 \
+	oce_tam.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	tstool_tam.F90 \
+	KEY_CPP \
+	obcdyn_tam.F90
+$(MODEL_LIB)(obcfla.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obccli.F90 \
+	oce.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	obc_oce.F90 \
+	obcdta.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcfla.F90
+$(MODEL_LIB)(obcini.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcdom.o) \
+	$(MODEL_LIB)(obcrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	obcdom.F90 \
+	obcrst.F90 \
+	oce.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcini.F90
+$(MODEL_LIB)(obcrad.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcrad.F90
+$(MODEL_LIB)(obcrst.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcrst.F90
+$(MODEL_LIB)(obcspg.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcspg.F90
+$(MODEL_LIB)(obctra.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obctra.F90
+$(MODEL_LIB)(obctra_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_mpp_tam.F90 \
+	lib_print.f90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	oce_tam.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obctra_tam.F90
+$(MODEL_LIB)(obcvol.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	obc_par.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcvol.F90
+$(MODEL_LIB)(oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	oce.F90
+$(MODEL_LIB)(oce_tam.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	KEY_CPP \
+	oce_tam.F90
+$(MODEL_LIB)(opa.o) :	\
+	$(MODEL_LIB)(agrif_opa_sponge.o) \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdydta.o) \
+	$(MODEL_LIB)(bdytides.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cla.o) \
+	$(MODEL_LIB)(cla_div.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diafwb.o) \
+	$(MODEL_LIB)(diagap.o) \
+	$(MODEL_LIB)(diahdy.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domhgr.o) \
+	$(MODEL_LIB)(dommsk.o) \
+	$(MODEL_LIB)(domstp.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(domwri.o) \
+	$(MODEL_LIB)(domzgr.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynhpg.o) \
+	$(MODEL_LIB)(dynldf.o) \
+	$(MODEL_LIB)(dynnxt.o) \
+	$(MODEL_LIB)(dynspg.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(dynzdf.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(floats.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfeiv.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oasis4_date.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcdom.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcrad.o) \
+	$(MODEL_LIB)(obcrst.o) \
+	$(MODEL_LIB)(obcspg.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcmod.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(stpctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(traadv.o) \
+	$(MODEL_LIB)(trabbc.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(traldf.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(tranxt.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trasbc.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfbfr.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	agrif_opa_sponge.F90 \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdydta.F90 \
+	bdytides.F90 \
+	c1d.F90 \
+	cla.F90 \
+	cla_div.F90 \
+	closea.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diafwb.F90 \
+	diagap.F90 \
+	diahdy.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaptr.F90 \
+	diaspr.F90 \
+	diawri.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domhgr.F90 \
+	dommsk.F90 \
+	domstp.F90 \
+	domvvl.F90 \
+	domwri.F90 \
+	domzgr.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dynadv.F90 \
+	dynhpg.F90 \
+	dynldf.F90 \
+	dynnxt.F90 \
+	dynspg.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	dynvor.F90 \
+	dynzdf.F90 \
+	eosbn2.F90 \
+	flo_oce.F90 \
+	floats.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfeiv.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oasis4_date.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcdom.F90 \
+	obcdta.F90 \
+	obcrad.F90 \
+	obcrst.F90 \
+	obcspg.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_ice.F90 \
+	sbc_oce.F90 \
+	sbcmod.F90 \
+	sbcrnf.F90 \
+	sol_oce.F90 \
+	solisl.F90 \
+	stpctl.F90 \
+	tamtrj.F90 \
+	traadv.F90 \
+	trabbc.F90 \
+	trabbl.F90 \
+	tradmp.F90 \
+	traldf.F90 \
+	tranpc.F90 \
+	tranxt.F90 \
+	traqsr.F90 \
+	trasbc.F90 \
+	trazdf.F90 \
+	trcstp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmld_rst.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfbfr.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(step.o) \
+	$(MODEL_LIB)(step_c1d.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_par.F90 \
+	bdyini.F90 \
+	c1d.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dyncor_c1d.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	istate.F90 \
+	ldfdyn.F90 \
+	ldftra.F90 \
+	lib_mpp.F90 \
+	mppini.F90 \
+	obc_par.F90 \
+	obcini.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	step.F90 \
+	step_c1d.F90 \
+	tamtrj.F90 \
+	trcini.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfini.F90 \
+	zpshde.F90 \
+	KEY_CPP \
+	opa.F90
+$(MODEL_LIB)(opatam_tst_ini.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(bdytides.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(domhgr.o) \
+	$(MODEL_LIB)(dommsk.o) \
+	$(MODEL_LIB)(domstp.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(domwri.o) \
+	$(MODEL_LIB)(domzgr.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynspg.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(oasis4_date.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcdom.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(obcrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(step.o) \
+	$(MODEL_LIB)(step_c1d.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdyini.F90 \
+	bdytides.F90 \
+	c1d.F90 \
+	closea.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	diaptr.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	domhgr.F90 \
+	dommsk.F90 \
+	domstp.F90 \
+	domvvl.F90 \
+	domwri.F90 \
+	domzgr.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dyncor_c1d.F90 \
+	dynspg.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	eosbn2.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate.F90 \
+	lbclnk.F90 \
+	ldfdyn.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	mppini.F90 \
+	oasis4_date.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcdom.F90 \
+	obcini.F90 \
+	obcrst.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_ice.F90 \
+	sbc_oce.F90 \
+	sol_oce.F90 \
+	solisl.F90 \
+	solver.F90 \
+	step.F90 \
+	step_c1d.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	tradmp.F90 \
+	tranpc.F90 \
+	trcini.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfini.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opa.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_par.F90 \
+	bdyini.F90 \
+	c1d.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dyncor_c1d.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	istate.F90 \
+	ldfdyn.F90 \
+	ldftra.F90 \
+	lib_mpp.F90 \
+	mppini.F90 \
+	obc_par.F90 \
+	obcini.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opa.F90 \
+	par_tlm.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sol_oce_tam.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	trc_oce_tam.F90 \
+	trcini.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfini.F90 \
+	zpshde.F90 \
+	KEY_CPP \
+	opatam_tst_ini.F90
+$(MODEL_LIB)(par_kind.o) :	\
+	par_kind.F90
+$(MODEL_LIB)(par_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	par_EEL_R2.h90 \
+	par_EEL_R5.h90 \
+	par_EEL_R6.h90 \
+	par_GYRE.h90 \
+	par_ORCA_R025.h90 \
+	par_ORCA_R05.h90 \
+	par_ORCA_R2.h90 \
+	par_ORCA_R4.h90 \
+	par_POMME_R025.h90 \
+	KEY_CPP \
+	par_oce.F90
+$(MODEL_LIB)(par_tlm.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	par_tlm.F90
+$(MODEL_LIB)(paresp.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfddm.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	zdf_oce.F90 \
+	KEY_CPP \
+	paresp.F90
+$(MODEL_LIB)(phycst.o) :	\
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	in_out_manager.F90 \
+	par_oce.F90 \
+	KEY_CPP \
+	phycst.F90
+$(MODEL_LIB)(prtctl.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	prtctl.F90
+$(MODEL_LIB)(ran_num.o) :	\
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	par_kind.F90 \
+	ran_num.F90
+$(MODEL_LIB)(restart.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfddm.F90 \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	c1d.F90 \
+	cpl_oce.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	oce.F90 \
+	phycst.F90 \
+	trdmld_oce.F90 \
+	zpshde.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	restart.F90
+$(MODEL_LIB)(sbc_ice.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	sbc_ice.F90
+$(MODEL_LIB)(sbc_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	sbc_oce.F90
+$(MODEL_LIB)(sbc_oce_tam.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	KEY_CPP \
+	sbc_oce_tam.F90
+$(MODEL_LIB)(sbcana.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	sbcana.F90
+$(MODEL_LIB)(sbcana_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	ran_num.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sbc_oce_tam.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	sbcana_tam.F90
+$(MODEL_LIB)(sbcblk_clio.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	albedo.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	fldread.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	sbcblk_clio.F90
+$(MODEL_LIB)(sbcblk_core.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	fldread.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	sbcblk_core.F90
+$(MODEL_LIB)(sbccpl.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oasis4_date.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oasis4_date.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_ice.F90 \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	geo2ocean.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_ice.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	sbccpl.F90
+$(MODEL_LIB)(sbcflx.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	fldread.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	sbcflx.F90
+$(MODEL_LIB)(sbcflx_tam.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	sbc_oce_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	sbcflx_tam.F90
+$(MODEL_LIB)(sbcfwb.o) :	\
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	closea.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	fldread.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	sbcrnf.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	sbcfwb.F90
+$(MODEL_LIB)(sbcfwb_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	ran_num.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sbc_oce_tam.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	sbcfwb_tam.F90
+$(MODEL_LIB)(sbcice_if.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfddm.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	fldread.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	sbcice_if.F90
+$(MODEL_LIB)(sbcice_lim.o) :	\
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	albedo.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	fldread.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	zdfddm.F90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcblk_clio.o) \
+	$(MODEL_LIB)(sbcblk_core.o) \
+	albedo.F90 \
+	c1d.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_ice.F90 \
+	sbc_oce.F90 \
+	sbcblk_clio.F90 \
+	sbcblk_core.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	sbcice_lim.F90
+$(MODEL_LIB)(sbcice_lim_2.o) :	\
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	albedo.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	fldread.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	zdfddm.F90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcblk_clio.o) \
+	$(MODEL_LIB)(sbcblk_core.o) \
+	albedo.F90 \
+	c1d.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_ice.F90 \
+	sbc_oce.F90 \
+	sbcblk_clio.F90 \
+	sbcblk_core.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	sbcice_lim_2.F90
+$(MODEL_LIB)(sbcmod.o) :	\
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcblk_clio.o) \
+	$(MODEL_LIB)(sbcblk_core.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	albedo.F90 \
+	c1d.F90 \
+	closea.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	fldread.F90 \
+	geo2ocean.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_ice.F90 \
+	sbc_oce.F90 \
+	sbcblk_clio.F90 \
+	sbcblk_core.F90 \
+	sbcrnf.F90 \
+	trdmld_oce.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcana.o) \
+	$(MODEL_LIB)(sbcblk_clio.o) \
+	$(MODEL_LIB)(sbcblk_core.o) \
+	$(MODEL_LIB)(sbccpl.o) \
+	$(MODEL_LIB)(sbcflx.o) \
+	$(MODEL_LIB)(sbcfwb.o) \
+	$(MODEL_LIB)(sbcice_if.o) \
+	$(MODEL_LIB)(sbcice_lim.o) \
+	$(MODEL_LIB)(sbcice_lim_2.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(sbcssm.o) \
+	$(MODEL_LIB)(sbcssr.o) \
+	closea.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbcana.F90 \
+	sbcblk_clio.F90 \
+	sbcblk_core.F90 \
+	sbccpl.F90 \
+	sbcflx.F90 \
+	sbcfwb.F90 \
+	sbcice_if.F90 \
+	sbcice_lim.F90 \
+	sbcice_lim_2.F90 \
+	sbcrnf.F90 \
+	sbcssm.F90 \
+	sbcssr.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	sbcmod.F90
+$(MODEL_LIB)(sbcmod_tam.o) :	\
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	closea.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	fldread.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	paresp.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	tstool_tam.F90 \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(closea_tam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sbcana_tam.o) \
+	$(MODEL_LIB)(sbcflx_tam.o) \
+	$(MODEL_LIB)(sbcfwb_tam.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(sbcssm_tam.o) \
+	$(MODEL_LIB)(sbcssr_tam.o) \
+	closea.F90 \
+	closea_tam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	par_kind.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sbcana_tam.F90 \
+	sbcflx_tam.F90 \
+	sbcfwb_tam.F90 \
+	sbcrnf.F90 \
+	sbcssm_tam.F90 \
+	sbcssr_tam.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	sbcmod_tam.F90
+$(MODEL_LIB)(sbcrnf.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	closea.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	fldread.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	sbcrnf.F90
+$(MODEL_LIB)(sbcssm.o) :	\
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	c1d.F90 \
+	cpl_oce.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	trdmld_oce.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	sbcssm.F90
+$(MODEL_LIB)(sbcssm_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	ran_num.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	paresp.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	sbcssm_tam.F90
+$(MODEL_LIB)(sbcssr.o) :	\
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	closea.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	fldread.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	fldread.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	sbcrnf.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	sbcssr.F90
+$(MODEL_LIB)(sbcssr_tam.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	ran_num.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	fldread.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	sbcssr_tam.F90
+$(MODEL_LIB)(sms.o) :	\
+	sms.F90
+$(MODEL_LIB)(sol_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	sol_oce.F90
+$(MODEL_LIB)(sol_oce_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sol_oce.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	in_out_manager.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	solver.F90 \
+	tamctl.F90 \
+	sol_oce_tam.F90
+$(MODEL_LIB)(solfet.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	dom_oce.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	sol_oce.F90 \
+	KEY_CPP \
+	solfet.F90
+$(MODEL_LIB)(solfet_tam.o) :	\
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	in_out_manager.F90 \
+	par_kind.F90 \
+	solfet_tam.F90
+$(MODEL_LIB)(solisl.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	solisl.F90
+$(MODEL_LIB)(solmat.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_feti.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_feti.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sol_oce.F90 \
+	KEY_CPP \
+	solmat.F90
+$(MODEL_LIB)(solpcg.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	sol_oce.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	solpcg.F90
+$(MODEL_LIB)(solpcg_tam.o) :	\
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	in_out_manager.F90 \
+	par_kind.F90 \
+	solpcg_tam.F90
+$(MODEL_LIB)(solsor.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	solsor.F90
+$(MODEL_LIB)(solsor_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mpp_tam.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_mpp_tam.F90 \
+	lib_print.f90 \
+	mpp_tam.F90 \
+	mppsumtam.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	ran_num.F90 \
+	solver.F90 \
+	tamctl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(gridsum.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	gridsum.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	lib_mpp.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	tstool_tam.F90 \
+	solsor_tam.F90
+$(MODEL_LIB)(solver.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_feti.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_feti.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	sol_oce.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	zdf_oce.F90 \
+	KEY_CPP \
+	solver.F90
+$(MODEL_LIB)(step.o) :	\
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(agrif_opa_update.o) \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdydta.o) \
+	$(MODEL_LIB)(bdydyn.o) \
+	$(MODEL_LIB)(bdytides.o) \
+	$(MODEL_LIB)(bdytra.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynadv_cen2.o) \
+	$(MODEL_LIB)(dynadv_ubs.o) \
+	$(MODEL_LIB)(dynkeg.o) \
+	$(MODEL_LIB)(dynldf_bilap.o) \
+	$(MODEL_LIB)(dynldf_bilapg.o) \
+	$(MODEL_LIB)(dynldf_iso.o) \
+	$(MODEL_LIB)(dynldf_lap.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynzad.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(dynzdf_imp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(flo4rk.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(floblk.o) \
+	$(MODEL_LIB)(flodom.o) \
+	$(MODEL_LIB)(flowri.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obcdyn_bt.o) \
+	$(MODEL_LIB)(obctra.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcana.o) \
+	$(MODEL_LIB)(sbcblk_clio.o) \
+	$(MODEL_LIB)(sbcblk_core.o) \
+	$(MODEL_LIB)(sbccpl.o) \
+	$(MODEL_LIB)(sbcflx.o) \
+	$(MODEL_LIB)(sbcfwb.o) \
+	$(MODEL_LIB)(sbcice_if.o) \
+	$(MODEL_LIB)(sbcice_lim.o) \
+	$(MODEL_LIB)(sbcice_lim_2.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(sbcssm.o) \
+	$(MODEL_LIB)(sbcssr.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(traadv_cen2.o) \
+	$(MODEL_LIB)(traadv_eiv.o) \
+	$(MODEL_LIB)(traadv_muscl.o) \
+	$(MODEL_LIB)(traadv_muscl2.o) \
+	$(MODEL_LIB)(traadv_qck.o) \
+	$(MODEL_LIB)(traadv_tvd.o) \
+	$(MODEL_LIB)(traadv_ubs.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(traldf_bilap.o) \
+	$(MODEL_LIB)(traldf_bilapg.o) \
+	$(MODEL_LIB)(traldf_iso.o) \
+	$(MODEL_LIB)(traldf_lap.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	agrif_opa_interp.F90 \
+	agrif_opa_update.F90 \
+	bdy_oce.F90 \
+	bdydta.F90 \
+	bdydyn.F90 \
+	bdytides.F90 \
+	bdytra.F90 \
+	c1d.F90 \
+	closea.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	diawri.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dynadv.F90 \
+	dynadv_cen2.F90 \
+	dynadv_ubs.F90 \
+	dynkeg.F90 \
+	dynldf_bilap.F90 \
+	dynldf_bilapg.F90 \
+	dynldf_iso.F90 \
+	dynldf_lap.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	dynspg_ts.F90 \
+	dynzad.F90 \
+	dynzdf_exp.F90 \
+	dynzdf_imp.F90 \
+	eosbn2.F90 \
+	fldread.F90 \
+	flo4rk.F90 \
+	flo_oce.F90 \
+	floblk.F90 \
+	flodom.F90 \
+	flowri.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obccli.F90 \
+	obcdyn.F90 \
+	obcdyn_bt.F90 \
+	obctra.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_ice.F90 \
+	sbc_oce.F90 \
+	sbcana.F90 \
+	sbcblk_clio.F90 \
+	sbcblk_core.F90 \
+	sbccpl.F90 \
+	sbcflx.F90 \
+	sbcfwb.F90 \
+	sbcice_if.F90 \
+	sbcice_lim.F90 \
+	sbcice_lim_2.F90 \
+	sbcrnf.F90 \
+	sbcssm.F90 \
+	sbcssr.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	traadv_cen2.F90 \
+	traadv_eiv.F90 \
+	traadv_muscl.F90 \
+	traadv_muscl2.F90 \
+	traadv_qck.F90 \
+	traadv_tvd.F90 \
+	traadv_ubs.F90 \
+	trabbl.F90 \
+	tradmp.F90 \
+	traldf_bilap.F90 \
+	traldf_bilapg.F90 \
+	traldf_iso.F90 \
+	traldf_lap.F90 \
+	traqsr.F90 \
+	trazdf.F90 \
+	trazdf_exp.F90 \
+	trazdf_imp.F90 \
+	trc_oce.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdmld_rst.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdftke.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(agrif_opa_sponge.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdydta.o) \
+	$(MODEL_LIB)(cla.o) \
+	$(MODEL_LIB)(cla_div.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diafwb.o) \
+	$(MODEL_LIB)(diagap.o) \
+	$(MODEL_LIB)(diahdy.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynhpg.o) \
+	$(MODEL_LIB)(dynldf.o) \
+	$(MODEL_LIB)(dynnxt.o) \
+	$(MODEL_LIB)(dynspg.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(dynzdf.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(floats.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfeiv.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcrad.o) \
+	$(MODEL_LIB)(obcrst.o) \
+	$(MODEL_LIB)(obcspg.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbcmod.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(stpctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(traadv.o) \
+	$(MODEL_LIB)(trabbc.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(traldf.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(tranxt.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trasbc.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfbfr.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	agrif_opa_sponge.F90 \
+	bdy_par.F90 \
+	bdydta.F90 \
+	cla.F90 \
+	cla_div.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diafwb.F90 \
+	diagap.F90 \
+	diahdy.F90 \
+	diahth.F90 \
+	diaptr.F90 \
+	diaspr.F90 \
+	diawri.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dynadv.F90 \
+	dynhpg.F90 \
+	dynldf.F90 \
+	dynnxt.F90 \
+	dynspg.F90 \
+	dynspg_oce.F90 \
+	dynvor.F90 \
+	dynzdf.F90 \
+	eosbn2.F90 \
+	flo_oce.F90 \
+	floats.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfeiv.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	obc_par.F90 \
+	obcdta.F90 \
+	obcrad.F90 \
+	obcrst.F90 \
+	obcspg.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbcmod.F90 \
+	sbcrnf.F90 \
+	stpctl.F90 \
+	tamtrj.F90 \
+	traadv.F90 \
+	trabbc.F90 \
+	trabbl.F90 \
+	tradmp.F90 \
+	traldf.F90 \
+	tranpc.F90 \
+	tranxt.F90 \
+	traqsr.F90 \
+	trasbc.F90 \
+	trazdf.F90 \
+	trcstp.F90 \
+	trdicp.F90 \
+	trdmld.F90 \
+	trdmld_rst.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfbfr.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	zpshde.F90 \
+	domzgr_substitute.h90 \
+	zdfddm_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	step.F90
+$(MODEL_LIB)(step_c1d.o) :	\
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(agrif_opa_update.o) \
+	$(MODEL_LIB)(bdytra.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(dynzdf_imp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obctra.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcana.o) \
+	$(MODEL_LIB)(sbcblk_clio.o) \
+	$(MODEL_LIB)(sbcblk_core.o) \
+	$(MODEL_LIB)(sbccpl.o) \
+	$(MODEL_LIB)(sbcflx.o) \
+	$(MODEL_LIB)(sbcfwb.o) \
+	$(MODEL_LIB)(sbcice_if.o) \
+	$(MODEL_LIB)(sbcice_lim.o) \
+	$(MODEL_LIB)(sbcice_lim_2.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(sbcssm.o) \
+	$(MODEL_LIB)(sbcssr.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	agrif_opa_interp.F90 \
+	agrif_opa_update.F90 \
+	bdytra.F90 \
+	c1d.F90 \
+	closea.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	diawri.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	dynzdf_exp.F90 \
+	dynzdf_imp.F90 \
+	eosbn2.F90 \
+	fldread.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obctra.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_ice.F90 \
+	sbc_oce.F90 \
+	sbcana.F90 \
+	sbcblk_clio.F90 \
+	sbcblk_core.F90 \
+	sbccpl.F90 \
+	sbcflx.F90 \
+	sbcfwb.F90 \
+	sbcice_if.F90 \
+	sbcice_lim.F90 \
+	sbcice_lim_2.F90 \
+	sbcrnf.F90 \
+	sbcssm.F90 \
+	sbcssr.F90 \
+	sol_oce.F90 \
+	solisl.F90 \
+	traqsr.F90 \
+	trazdf_exp.F90 \
+	trazdf_imp.F90 \
+	trc_oce.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdftke.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynzdf.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbcmod.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(stpctl.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(tranxt.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trasbc.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfbfr.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	daymod.F90 \
+	diawri.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dynzdf.F90 \
+	eosbn2.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbcmod.F90 \
+	sbcrnf.F90 \
+	stpctl.F90 \
+	tranpc.F90 \
+	tranxt.F90 \
+	traqsr.F90 \
+	trasbc.F90 \
+	trazdf.F90 \
+	trcstp.F90 \
+	zdf_oce.F90 \
+	zdfbfr.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	domzgr_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	step_c1d.F90
+$(MODEL_LIB)(step_tam.o) :	\
+	$(MODEL_LIB)(agrif_opa_sponge.o) \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdydta.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cla.o) \
+	$(MODEL_LIB)(cla_div.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(closea_tam.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diafwb.o) \
+	$(MODEL_LIB)(diagap.o) \
+	$(MODEL_LIB)(diahdy.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(divcur_tam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynhpg.o) \
+	$(MODEL_LIB)(dynkeg_tam.o) \
+	$(MODEL_LIB)(dynldf.o) \
+	$(MODEL_LIB)(dynldf_bilap_tam.o) \
+	$(MODEL_LIB)(dynldf_lap_tam.o) \
+	$(MODEL_LIB)(dynnxt.o) \
+	$(MODEL_LIB)(dynspg.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_flt_tam.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(dynzad_tam.o) \
+	$(MODEL_LIB)(dynzdf.o) \
+	$(MODEL_LIB)(dynzdf_exp_tam.o) \
+	$(MODEL_LIB)(dynzdf_imp_tam.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(eosbn2_tam.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(floats.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfeiv.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(obcrad.o) \
+	$(MODEL_LIB)(obcrst.o) \
+	$(MODEL_LIB)(obcspg.o) \
+	$(MODEL_LIB)(obctra_tam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opa.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sbcana_tam.o) \
+	$(MODEL_LIB)(sbcflx_tam.o) \
+	$(MODEL_LIB)(sbcfwb_tam.o) \
+	$(MODEL_LIB)(sbcmod.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(sbcssm_tam.o) \
+	$(MODEL_LIB)(sbcssr_tam.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(stpctl.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(traadv.o) \
+	$(MODEL_LIB)(traadv_cen2_tam.o) \
+	$(MODEL_LIB)(traadv_eiv_tam.o) \
+	$(MODEL_LIB)(trabbc.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(traldf.o) \
+	$(MODEL_LIB)(traldf_iso_tam.o) \
+	$(MODEL_LIB)(traldf_lap_tam.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(tranxt.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trasbc.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trazdf_exp_tam.o) \
+	$(MODEL_LIB)(trazdf_imp_tam.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(wzvmod_tam.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfbfr.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	$(MODEL_LIB)(zpshde_tam.o) \
+	agrif_opa_sponge.F90 \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdydta.F90 \
+	bdyini.F90 \
+	c1d.F90 \
+	cla.F90 \
+	cla_div.F90 \
+	closea.F90 \
+	closea_tam.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diafwb.F90 \
+	diagap.F90 \
+	diahdy.F90 \
+	diahth.F90 \
+	diaptr.F90 \
+	diaspr.F90 \
+	diawri.F90 \
+	divcur.F90 \
+	divcur_tam.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	domvvl.F90 \
+	dotprodfld.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dynadv.F90 \
+	dyncor_c1d.F90 \
+	dynhpg.F90 \
+	dynkeg_tam.F90 \
+	dynldf.F90 \
+	dynldf_bilap_tam.F90 \
+	dynldf_lap_tam.F90 \
+	dynnxt.F90 \
+	dynspg.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_flt_tam.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	dynvor.F90 \
+	dynzad_tam.F90 \
+	dynzdf.F90 \
+	dynzdf_exp_tam.F90 \
+	dynzdf_imp_tam.F90 \
+	eosbn2.F90 \
+	eosbn2_tam.F90 \
+	fldread.F90 \
+	flo_oce.F90 \
+	floats.F90 \
+	gridrandom.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	istate.F90 \
+	istate_mod.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	ldfdyn.F90 \
+	ldfdyn_oce.F90 \
+	ldfeiv.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_mpp_tam.F90 \
+	lib_print.f90 \
+	mppini.F90 \
+	mppsumtam.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obccli.F90 \
+	obcdta.F90 \
+	obcini.F90 \
+	obcrad.F90 \
+	obcrst.F90 \
+	obcspg.F90 \
+	obctra_tam.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opa.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	paresp.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sbcana_tam.F90 \
+	sbcflx_tam.F90 \
+	sbcfwb_tam.F90 \
+	sbcmod.F90 \
+	sbcrnf.F90 \
+	sbcssm_tam.F90 \
+	sbcssr_tam.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	solisl.F90 \
+	solver.F90 \
+	stpctl.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	traadv.F90 \
+	traadv_cen2_tam.F90 \
+	traadv_eiv_tam.F90 \
+	trabbc.F90 \
+	trabbl.F90 \
+	tradmp.F90 \
+	traldf.F90 \
+	traldf_iso_tam.F90 \
+	traldf_lap_tam.F90 \
+	tranpc.F90 \
+	tranxt.F90 \
+	traqsr.F90 \
+	trasbc.F90 \
+	trazdf.F90 \
+	trazdf_exp_tam.F90 \
+	trazdf_imp_tam.F90 \
+	trc_oce.F90 \
+	trc_oce_tam.F90 \
+	trcini.F90 \
+	trcstp.F90 \
+	trdicp.F90 \
+	trdmld.F90 \
+	trdmld_rst.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	wzvmod_tam.F90 \
+	zdf_oce.F90 \
+	zdfbfr.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfini.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	zpshde.F90 \
+	zpshde_tam.F90 \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cla_div_tam.o) \
+	$(MODEL_LIB)(cla_tam.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(daymod_tam.o) \
+	$(MODEL_LIB)(divcur_tam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynadv_tam.o) \
+	$(MODEL_LIB)(dynhpg_tam.o) \
+	$(MODEL_LIB)(dynldf_tam.o) \
+	$(MODEL_LIB)(dynnxt_tam.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_tam.o) \
+	$(MODEL_LIB)(dynvor_tam.o) \
+	$(MODEL_LIB)(dynzdf_tam.o) \
+	$(MODEL_LIB)(eosbn2_tam.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(istate_tam.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sbcfwb_tam.o) \
+	$(MODEL_LIB)(sbcmod_tam.o) \
+	$(MODEL_LIB)(sbcssr_tam.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(step.o) \
+	$(MODEL_LIB)(step_c1d.o) \
+	$(MODEL_LIB)(stpctl_tam.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(traadv_tam.o) \
+	$(MODEL_LIB)(trabbc.o) \
+	$(MODEL_LIB)(trabbc_tam.o) \
+	$(MODEL_LIB)(tradmp_tam.o) \
+	$(MODEL_LIB)(traldf_tam.o) \
+	$(MODEL_LIB)(tranxt_tam.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(traqsr_tam.o) \
+	$(MODEL_LIB)(trasbc_tam.o) \
+	$(MODEL_LIB)(trazdf_tam.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(wzvmod_tam.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfkpp_tam.o) \
+	$(MODEL_LIB)(zpshde_tam.o) \
+	c1d.F90 \
+	cla_div_tam.F90 \
+	cla_tam.F90 \
+	daymod.F90 \
+	daymod_tam.F90 \
+	divcur_tam.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynadv_tam.F90 \
+	dynhpg_tam.F90 \
+	dynldf_tam.F90 \
+	dynnxt_tam.F90 \
+	dynspg_oce.F90 \
+	dynspg_tam.F90 \
+	dynvor_tam.F90 \
+	dynzdf_tam.F90 \
+	eosbn2_tam.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate_mod.F90 \
+	istate_tam.F90 \
+	lbclnk_tam.F90 \
+	lib_mpp.F90 \
+	obc_par.F90 \
+	obcdta.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	paresp.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sbcfwb_tam.F90 \
+	sbcmod_tam.F90 \
+	sbcssr_tam.F90 \
+	sol_oce_tam.F90 \
+	step.F90 \
+	step_c1d.F90 \
+	stpctl_tam.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	traadv_tam.F90 \
+	trabbc.F90 \
+	trabbc_tam.F90 \
+	tradmp_tam.F90 \
+	traldf_tam.F90 \
+	tranxt_tam.F90 \
+	traqsr.F90 \
+	traqsr_tam.F90 \
+	trasbc_tam.F90 \
+	trazdf_tam.F90 \
+	trc_oce_tam.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	wzvmod_tam.F90 \
+	zdfkpp.F90 \
+	zdfkpp_tam.F90 \
+	zpshde_tam.F90 \
+	domzgr_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	step_tam.F90
+$(MODEL_LIB)(stpctl.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_ice.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcssr.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	dom_oce.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_ice.F90 \
+	sbc_oce.F90 \
+	sbcssr.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	diawri.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	sol_oce.F90 \
+	solisl.F90 \
+	stpctl.F90
+$(MODEL_LIB)(stpctl_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sol_oce.F90 \
+	solfet.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sol_oce.F90 \
+	solisl.F90 \
+	stpctl_tam.F90
+$(MODEL_LIB)(tamctl.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	tamctl.F90
+$(MODEL_LIB)(tamtrj.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	daymod.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	sbc_oce.F90 \
+	sol_oce.F90 \
+	tradmp.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	KEY_CPP \
+	tamtrj.F90
+$(MODEL_LIB)(tamtst.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cla_div_tam.o) \
+	$(MODEL_LIB)(cla_tam.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(closea_tam.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(daymod_tam.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(divcur_tam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynadv_tam.o) \
+	$(MODEL_LIB)(dynhpg.o) \
+	$(MODEL_LIB)(dynhpg_tam.o) \
+	$(MODEL_LIB)(dynkeg_tam.o) \
+	$(MODEL_LIB)(dynldf_bilap_tam.o) \
+	$(MODEL_LIB)(dynldf_lap_tam.o) \
+	$(MODEL_LIB)(dynldf_tam.o) \
+	$(MODEL_LIB)(dynnxt_tam.o) \
+	$(MODEL_LIB)(dynspg_flt_tam.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_tam.o) \
+	$(MODEL_LIB)(dynvor_tam.o) \
+	$(MODEL_LIB)(dynzad_tam.o) \
+	$(MODEL_LIB)(dynzdf_exp_tam.o) \
+	$(MODEL_LIB)(dynzdf_imp_tam.o) \
+	$(MODEL_LIB)(dynzdf_tam.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(eosbn2_tam.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(gridsum.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(istate_tam.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obctra_tam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sbcana_tam.o) \
+	$(MODEL_LIB)(sbcflx_tam.o) \
+	$(MODEL_LIB)(sbcfwb_tam.o) \
+	$(MODEL_LIB)(sbcmod_tam.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(sbcssm_tam.o) \
+	$(MODEL_LIB)(sbcssr_tam.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(step.o) \
+	$(MODEL_LIB)(step_c1d.o) \
+	$(MODEL_LIB)(stpctl_tam.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(traadv_cen2_tam.o) \
+	$(MODEL_LIB)(traadv_eiv_tam.o) \
+	$(MODEL_LIB)(traadv_tam.o) \
+	$(MODEL_LIB)(trabbc.o) \
+	$(MODEL_LIB)(trabbc_tam.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(tradmp_tam.o) \
+	$(MODEL_LIB)(traldf_iso_tam.o) \
+	$(MODEL_LIB)(traldf_lap_tam.o) \
+	$(MODEL_LIB)(traldf_tam.o) \
+	$(MODEL_LIB)(tranxt_tam.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(traqsr_tam.o) \
+	$(MODEL_LIB)(trasbc.o) \
+	$(MODEL_LIB)(trasbc_tam.o) \
+	$(MODEL_LIB)(trazdf_exp_tam.o) \
+	$(MODEL_LIB)(trazdf_imp_tam.o) \
+	$(MODEL_LIB)(trazdf_tam.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(wzvmod_tam.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfkpp_tam.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	$(MODEL_LIB)(zpshde_tam.o) \
+	bdy_oce.F90 \
+	c1d.F90 \
+	cla_div_tam.F90 \
+	cla_tam.F90 \
+	closea.F90 \
+	closea_tam.F90 \
+	daymod.F90 \
+	daymod_tam.F90 \
+	divcur.F90 \
+	divcur_tam.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dotprodfld.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dynadv.F90 \
+	dynadv_tam.F90 \
+	dynhpg.F90 \
+	dynhpg_tam.F90 \
+	dynkeg_tam.F90 \
+	dynldf_bilap_tam.F90 \
+	dynldf_lap_tam.F90 \
+	dynldf_tam.F90 \
+	dynnxt_tam.F90 \
+	dynspg_flt_tam.F90 \
+	dynspg_oce.F90 \
+	dynspg_tam.F90 \
+	dynvor_tam.F90 \
+	dynzad_tam.F90 \
+	dynzdf_exp_tam.F90 \
+	dynzdf_imp_tam.F90 \
+	dynzdf_tam.F90 \
+	eosbn2.F90 \
+	eosbn2_tam.F90 \
+	gridrandom.F90 \
+	gridsum.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	istate_mod.F90 \
+	istate_tam.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obccli.F90 \
+	obcdta.F90 \
+	obctra_tam.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	paresp.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sbcana_tam.F90 \
+	sbcflx_tam.F90 \
+	sbcfwb_tam.F90 \
+	sbcmod_tam.F90 \
+	sbcrnf.F90 \
+	sbcssm_tam.F90 \
+	sbcssr_tam.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	step.F90 \
+	step_c1d.F90 \
+	stpctl_tam.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	traadv_cen2_tam.F90 \
+	traadv_eiv_tam.F90 \
+	traadv_tam.F90 \
+	trabbc.F90 \
+	trabbc_tam.F90 \
+	trabbl.F90 \
+	tradmp.F90 \
+	tradmp_tam.F90 \
+	traldf_iso_tam.F90 \
+	traldf_lap_tam.F90 \
+	traldf_tam.F90 \
+	tranxt_tam.F90 \
+	traqsr.F90 \
+	traqsr_tam.F90 \
+	trasbc.F90 \
+	trasbc_tam.F90 \
+	trazdf_exp_tam.F90 \
+	trazdf_imp_tam.F90 \
+	trazdf_tam.F90 \
+	trc_oce.F90 \
+	trc_oce_tam.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	wzvmod_tam.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfkpp.F90 \
+	zdfkpp_tam.F90 \
+	zdfmxl.F90 \
+	zdftke.F90 \
+	zpshde.F90 \
+	zpshde_tam.F90 \
+	$(MODEL_LIB)(cla_div_tam.o) \
+	$(MODEL_LIB)(cla_tam.o) \
+	$(MODEL_LIB)(divcur_tam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynadv_tam.o) \
+	$(MODEL_LIB)(dynhpg_tam.o) \
+	$(MODEL_LIB)(dynkeg_tam.o) \
+	$(MODEL_LIB)(dynldf_tam.o) \
+	$(MODEL_LIB)(dynnxt_tam.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_tam.o) \
+	$(MODEL_LIB)(dynvor_tam.o) \
+	$(MODEL_LIB)(dynzdf_tam.o) \
+	$(MODEL_LIB)(eosbn2_tam.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate_tam.o) \
+	$(MODEL_LIB)(obcdyn_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(sbcmod_tam.o) \
+	$(MODEL_LIB)(solsor_tam.o) \
+	$(MODEL_LIB)(step_tam.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(traadv_tam.o) \
+	$(MODEL_LIB)(trabbc.o) \
+	$(MODEL_LIB)(trabbc_tam.o) \
+	$(MODEL_LIB)(tradmp_tam.o) \
+	$(MODEL_LIB)(traldf_tam.o) \
+	$(MODEL_LIB)(tranxt_tam.o) \
+	$(MODEL_LIB)(traqsr_tam.o) \
+	$(MODEL_LIB)(trasbc_tam.o) \
+	$(MODEL_LIB)(trazdf_tam.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(wzvmod_tam.o) \
+	$(MODEL_LIB)(zpshde_tam.o) \
+	cla_div_tam.F90 \
+	cla_tam.F90 \
+	divcur_tam.F90 \
+	dom_oce.F90 \
+	dynadv_tam.F90 \
+	dynhpg_tam.F90 \
+	dynkeg_tam.F90 \
+	dynldf_tam.F90 \
+	dynnxt_tam.F90 \
+	dynspg_oce.F90 \
+	dynspg_tam.F90 \
+	dynvor_tam.F90 \
+	dynzdf_tam.F90 \
+	eosbn2_tam.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate_tam.F90 \
+	obcdyn_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	paresp.F90 \
+	sbcmod_tam.F90 \
+	solsor_tam.F90 \
+	step_tam.F90 \
+	tamctl.F90 \
+	traadv_tam.F90 \
+	trabbc.F90 \
+	trabbc_tam.F90 \
+	tradmp_tam.F90 \
+	traldf_tam.F90 \
+	tranxt_tam.F90 \
+	traqsr_tam.F90 \
+	trasbc_tam.F90 \
+	trazdf_tam.F90 \
+	trj_tam.F90 \
+	wzvmod_tam.F90 \
+	zpshde_tam.F90 \
+	KEY_CPP \
+	tamtst.F90
+$(MODEL_LIB)(traadv.o) :	\
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcmod.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	closea.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	sbcmod.F90 \
+	sbcrnf.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(traadv_cen2.o) \
+	$(MODEL_LIB)(traadv_eiv.o) \
+	$(MODEL_LIB)(traadv_muscl.o) \
+	$(MODEL_LIB)(traadv_muscl2.o) \
+	$(MODEL_LIB)(traadv_qck.o) \
+	$(MODEL_LIB)(traadv_tvd.o) \
+	$(MODEL_LIB)(traadv_ubs.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	traadv_cen2.F90 \
+	traadv_eiv.F90 \
+	traadv_muscl.F90 \
+	traadv_muscl2.F90 \
+	traadv_qck.F90 \
+	traadv_tvd.F90 \
+	traadv_ubs.F90 \
+	trabbl.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv.F90
+$(MODEL_LIB)(traadv_cen2.o) :	\
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(fldread.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcana.o) \
+	$(MODEL_LIB)(sbcblk_clio.o) \
+	$(MODEL_LIB)(sbcblk_core.o) \
+	$(MODEL_LIB)(sbccpl.o) \
+	$(MODEL_LIB)(sbcflx.o) \
+	$(MODEL_LIB)(sbcfwb.o) \
+	$(MODEL_LIB)(sbcice_if.o) \
+	$(MODEL_LIB)(sbcice_lim.o) \
+	$(MODEL_LIB)(sbcice_lim_2.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(sbcssm.o) \
+	$(MODEL_LIB)(sbcssr.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	closea.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	fldread.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbcana.F90 \
+	sbcblk_clio.F90 \
+	sbcblk_core.F90 \
+	sbccpl.F90 \
+	sbcflx.F90 \
+	sbcfwb.F90 \
+	sbcice_if.F90 \
+	sbcice_lim.F90 \
+	sbcice_lim_2.F90 \
+	sbcrnf.F90 \
+	sbcssm.F90 \
+	sbcssr.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbcmod.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	closea.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	sbcmod.F90 \
+	sbcrnf.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_cen2.F90
+$(MODEL_LIB)(traadv_cen2_tam.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opa.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sbcmod.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdyini.F90 \
+	c1d.F90 \
+	closea.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	domvvl.F90 \
+	dotprodfld.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dyncor_c1d.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate.F90 \
+	lbclnk.F90 \
+	ldfdyn.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	mppini.F90 \
+	mppsumtam.F90 \
+	obc_par.F90 \
+	obcini.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opa.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sbcmod.F90 \
+	sbcrnf.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	solisl.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	trabbl.F90 \
+	tradmp.F90 \
+	trc_oce_tam.F90 \
+	trcini.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfini.F90 \
+	zdfmxl.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(traadv_cen2.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynspg_oce.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	istate_mod.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	paresp.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	traadv_cen2.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_cen2_tam.F90
+$(MODEL_LIB)(traadv_eiv.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	ldfeiv_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_eiv.F90
+$(MODEL_LIB)(traadv_eiv_tam.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfeiv_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_eiv_tam.F90
+$(MODEL_LIB)(traadv_muscl.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_muscl.F90
+$(MODEL_LIB)(traadv_muscl2.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_muscl2.F90
+$(MODEL_LIB)(traadv_qck.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_qck.F90
+$(MODEL_LIB)(traadv_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(traadv_cen2.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	istate_mod.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	paresp.F90 \
+	prtctl.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	traadv_cen2.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(traadv_cen2_tam.o) \
+	$(MODEL_LIB)(traadv_eiv_tam.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	traadv_cen2_tam.F90 \
+	traadv_eiv_tam.F90 \
+	trabbl.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_tam.F90
+$(MODEL_LIB)(traadv_tvd.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_tvd.F90
+$(MODEL_LIB)(traadv_ubs.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_ubs.F90
+$(MODEL_LIB)(trabbc.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	trabbc.F90
+$(MODEL_LIB)(trabbc_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(trabbc.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	in_out_manager.F90 \
+	trabbc.F90 \
+	tstool_tam.F90 \
+	KEY_CPP \
+	trabbc_tam.F90
+$(MODEL_LIB)(trabbl.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(oce.o) \
+	eosbn2.F90 \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	trabbl_adv.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	trabbl.F90
+$(MODEL_LIB)(tradmp.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	tradmp.F90
+$(MODEL_LIB)(tradmp_tam.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	paresp.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	tradmp.F90 \
+	tstool_tam.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	tradmp_tam.F90
+$(MODEL_LIB)(traldf.o) :	\
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	diaptr.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trazdf_exp.F90 \
+	trazdf_imp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdftke.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(traldf_bilap.o) \
+	$(MODEL_LIB)(traldf_bilapg.o) \
+	$(MODEL_LIB)(traldf_iso.o) \
+	$(MODEL_LIB)(traldf_lap.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	traldf_bilap.F90 \
+	traldf_bilapg.F90 \
+	traldf_iso.F90 \
+	traldf_lap.F90 \
+	trazdf.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf.F90
+$(MODEL_LIB)(traldf_bilap.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	diaptr.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfeiv_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf_bilap.F90
+$(MODEL_LIB)(traldf_bilapg.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	diaptr.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfeiv_substitute.h90 \
+	ldftra_substitute.h90 \
+	KEY_CPP \
+	traldf_bilapg.F90
+$(MODEL_LIB)(traldf_iso.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	diaptr.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf_iso.F90
+$(MODEL_LIB)(traldf_iso_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	paresp.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf_iso_tam.F90
+$(MODEL_LIB)(traldf_lap.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	diaptr.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf_lap.F90
+$(MODEL_LIB)(traldf_lap_tam.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynzdf.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opa.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sbcmod.o) \
+	$(MODEL_LIB)(sbcrnf.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(stpctl.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(tranxt.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trasbc.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfbfr.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdyini.F90 \
+	c1d.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	diawri.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	domvvl.F90 \
+	dotprodfld.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dyncor_c1d.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	dynzdf.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	istate.F90 \
+	lbclnk.F90 \
+	ldfdyn.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	mppini.F90 \
+	mppsumtam.F90 \
+	obc_par.F90 \
+	obcini.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opa.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sbcmod.F90 \
+	sbcrnf.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	solisl.F90 \
+	stpctl.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	tradmp.F90 \
+	tranpc.F90 \
+	tranxt.F90 \
+	traqsr.F90 \
+	trasbc.F90 \
+	trazdf.F90 \
+	trc_oce_tam.F90 \
+	trcini.F90 \
+	trcstp.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfbfr.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfini.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(step_c1d.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(traldf_lap.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	c1d.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate_mod.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	paresp.F90 \
+	step_c1d.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	traldf_lap.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf_lap_tam.F90
+$(MODEL_LIB)(traldf_tam.o) :	\
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(step_c1d.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(traldf_lap.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	c1d.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate_mod.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	paresp.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	step_c1d.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	traldf_lap.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(traldf_iso_tam.o) \
+	$(MODEL_LIB)(traldf_lap_tam.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	traldf_iso_tam.F90 \
+	traldf_lap_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf_tam.F90
+$(MODEL_LIB)(tranpc.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	tranpc.F90
+$(MODEL_LIB)(tranxt.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	bdy_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(agrif_opa_update.o) \
+	$(MODEL_LIB)(bdytra.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(obctra.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	agrif_opa_interp.F90 \
+	agrif_opa_update.F90 \
+	bdytra.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	obctra.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	tranxt.F90
+$(MODEL_LIB)(tranxt_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	lib_mpp.F90 \
+	lib_mpp_tam.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	ran_num.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obctra_tam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	obc_oce.F90 \
+	obctra_tam.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	paresp.F90 \
+	tstool_tam.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	tranxt_tam.F90
+$(MODEL_LIB)(traqsr.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trc_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traqsr.F90
+$(MODEL_LIB)(traqsr_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	sbc_oce.F90 \
+	trc_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	traqsr.F90 \
+	trc_oce.F90 \
+	trc_oce_tam.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traqsr_tam.F90
+$(MODEL_LIB)(trasbc.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	traqsr.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	trasbc.F90
+$(MODEL_LIB)(trasbc_tam.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opa.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdyini.F90 \
+	c1d.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	domvvl.F90 \
+	dotprodfld.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dyncor_c1d.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate.F90 \
+	lbclnk.F90 \
+	ldfdyn.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	mppini.F90 \
+	mppsumtam.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcini.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opa.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	solisl.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	tradmp.F90 \
+	traqsr.F90 \
+	trc_oce.F90 \
+	trc_oce_tam.F90 \
+	trcini.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfini.F90 \
+	zdfmxl.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trasbc.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	divcur.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	istate_mod.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	paresp.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	traqsr.F90 \
+	trasbc.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	trasbc_tam.F90
+$(MODEL_LIB)(trazdf.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	bdy_oce.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	trazdf_exp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trazdf_exp.F90 \
+	trazdf_imp.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfkpp.F90 \
+	zdftke.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	trazdf.F90
+$(MODEL_LIB)(trazdf_exp.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	bdy_oce.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	domvvl.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	trazdf_exp.F90
+$(MODEL_LIB)(trazdf_exp_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	obc_oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	paresp.F90 \
+	tstool_tam.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	trazdf_exp_tam.F90
+$(MODEL_LIB)(trazdf_imp.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	bdy_oce.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	domvvl.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	trazdf_imp.F90
+$(MODEL_LIB)(trazdf_imp_tam.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opa.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdyini.F90 \
+	c1d.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	domvvl.F90 \
+	dotprodfld.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dyncor_c1d.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate.F90 \
+	lbclnk.F90 \
+	ldfdyn.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	mppini.F90 \
+	mppsumtam.F90 \
+	obc_par.F90 \
+	obcini.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opa.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	solisl.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	tradmp.F90 \
+	trc_oce_tam.F90 \
+	trcini.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfini.F90 \
+	zdfmxl.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	istate_mod.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	paresp.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	trazdf_imp.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	trazdf_imp_tam.F90
+$(MODEL_LIB)(trazdf_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(paresp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate_mod.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	paresp.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	trazdf_exp.F90 \
+	trazdf_imp.F90 \
+	trdmod.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trazdf_exp_tam.o) \
+	$(MODEL_LIB)(trazdf_imp_tam.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	trazdf_exp_tam.F90 \
+	trazdf_imp_tam.F90 \
+	zdf_oce.F90 \
+	zdfkpp.F90 \
+	zdftke.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	trazdf_tam.F90
+$(MODEL_LIB)(trc_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	trc_oce.F90
+$(MODEL_LIB)(trc_oce_tam.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	KEY_CPP \
+	trc_oce_tam.F90
+$(MODEL_LIB)(trcini.o) :	\
+	trcini.F90
+$(MODEL_LIB)(trcstp.o) :	\
+	trcstp.F90
+$(MODEL_LIB)(trdicp.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	oce.F90 \
+	phycst.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	trdicp.F90
+$(MODEL_LIB)(trdicp_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	trdicp_oce.F90
+$(MODEL_LIB)(trdmld.o) :	\
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	c1d.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	daymod.F90 \
+	diadimg.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	trdmld_rst.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	zdfddm_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	trdmld.F90
+$(MODEL_LIB)(trdmld_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	trdmld_oce.F90
+$(MODEL_LIB)(trdmld_rst.o) :	\
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	c1d.F90 \
+	cpl_oce.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdvor_oce.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	restart.F90 \
+	trdmod_oce.F90 \
+	KEY_CPP \
+	trdmld_rst.F90
+$(MODEL_LIB)(trdmod.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	daymod.F90 \
+	diadimg.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdmld_rst.F90 \
+	trdmod_oce.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdmld.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	trdmod.F90
+$(MODEL_LIB)(trdmod_oce.o) :	\
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdvor_oce.F90 \
+	KEY_CPP \
+	trdmod_oce.F90
+$(MODEL_LIB)(trdvor.o) :	\
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	trdvor.F90
+$(MODEL_LIB)(trdvor_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	trdvor_oce.F90
+$(MODEL_LIB)(trj_tam.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	bdy_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	sol_oce.F90 \
+	tradmp.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	divcur.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sbc_oce.F90 \
+	tamtrj.F90 \
+	tradmp.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	KEY_CPP \
+	trj_tam.F90
+$(MODEL_LIB)(tstool_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	ran_num.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	tstool_tam.F90
+$(MODEL_LIB)(wzvmod.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sbc_oce.F90 \
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	bdy_oce.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	wzvmod.F90
+$(MODEL_LIB)(wzvmod_tam.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	bdy_oce.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	dynspg_oce.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	lib_mpp.F90 \
+	lib_mpp_tam.F90 \
+	lib_print.f90 \
+	mppsumtam.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	ran_num.F90 \
+	sbc_oce.F90 \
+	tstool_tam.F90 \
+	$(MODEL_LIB)(divcur_tam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	divcur_tam.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dotprodfld.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce_tam.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce_tam.F90 \
+	tstool_tam.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	wzvmod_tam.F90
+$(MODEL_LIB)(zdf_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	zdf_oce.F90
+$(MODEL_LIB)(zdfbfr.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	zdfbfr.F90
+$(MODEL_LIB)(zdfddm.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zdfddm.F90
+$(MODEL_LIB)(zdfevd.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	zdf_oce.F90 \
+	zdfkpp.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	zdfevd.F90
+$(MODEL_LIB)(zdfini.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	trazdf_exp.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	par_oce.F90 \
+	tranpc.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfkpp.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	zdfini.F90
+$(MODEL_LIB)(zdfkpp.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdicp.F90 \
+	trdmld.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	zdfkpp.F90
+$(MODEL_LIB)(zdfkpp_tam.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zdfkpp_tam.F90
+$(MODEL_LIB)(zdfmxl.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	zdfmxl.F90
+$(MODEL_LIB)(zdfric.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	zdfric.F90
+$(MODEL_LIB)(zdftke.o) :	\
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	c1d.F90 \
+	cpl_oce.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sbc_oce.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	trazdf_exp.F90 \
+	zdf_oce.F90 \
+	zdfmxl.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zdftke.F90
+$(MODEL_LIB)(zpshde.o) :	\
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfddm.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zpshde.F90
+$(MODEL_LIB)(zpshde_tam.o) :	\
+	$(MODEL_LIB)(bdy_oce.o) \
+	$(MODEL_LIB)(bdy_par.o) \
+	$(MODEL_LIB)(bdyini.o) \
+	$(MODEL_LIB)(c1d.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor_c1d.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_mpp_tam.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(mppsumtam.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opa.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(ran_num.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sbc_oce.o) \
+	$(MODEL_LIB)(sbc_oce_tam.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(sol_oce_tam.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trc_oce_tam.o) \
+	$(MODEL_LIB)(trcini.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	bdy_oce.F90 \
+	bdy_par.F90 \
+	bdyini.F90 \
+	c1d.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	domvvl.F90 \
+	dotprodfld.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dyncor_c1d.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	eosbn2.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate.F90 \
+	istate_mod.F90 \
+	lbclnk.F90 \
+	ldfdyn.F90 \
+	ldfslp.F90 \
+	ldftra.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_mpp_tam.F90 \
+	lib_print.f90 \
+	mppini.F90 \
+	mppsumtam.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcini.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opa.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	ran_num.F90 \
+	restart.F90 \
+	sbc_oce.F90 \
+	sbc_oce_tam.F90 \
+	sol_oce.F90 \
+	sol_oce_tam.F90 \
+	solisl.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	tradmp.F90 \
+	trc_oce_tam.F90 \
+	trcini.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zdfddm.F90 \
+	zdfini.F90 \
+	zdfmxl.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dotprodfld.o) \
+	$(MODEL_LIB)(eosbn2_tam.o) \
+	$(MODEL_LIB)(gridrandom.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate_mod.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lbclnk_tam.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(oce_tam.o) \
+	$(MODEL_LIB)(opatam_tst_ini.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(par_tlm.o) \
+	$(MODEL_LIB)(tamctl.o) \
+	$(MODEL_LIB)(tamtrj.o) \
+	$(MODEL_LIB)(trj_tam.o) \
+	$(MODEL_LIB)(tstool_tam.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	divcur.F90 \
+	dom_oce.F90 \
+	dotprodfld.F90 \
+	eosbn2_tam.F90 \
+	gridrandom.F90 \
+	in_out_manager.F90 \
+	istate_mod.F90 \
+	lbclnk.F90 \
+	lbclnk_tam.F90 \
+	oce.F90 \
+	oce_tam.F90 \
+	opatam_tst_ini.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	par_tlm.F90 \
+	tamctl.F90 \
+	tamtrj.F90 \
+	trj_tam.F90 \
+	tstool_tam.F90 \
+	wzvmod.F90 \
+	zpshde.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zpshde_tam.F90
+# agrif previous use
+firstagrif:
+ifeq ($(AGRIF),use)
+	@if [ -z "`cat KEY_CPP | grep key_agrif`" ]; then $(RM) model_tam.o $(MODDIR)/ocetam/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi
+else
+	@if [ -n "`cat KEY_CPP | grep key_agrif`" ]; then $(RM) -r OPAFILES model_tam.o $(MODDIR)/ocetam/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi
+endif
+#- RB : this rule is a pretty miserable trick to be able to re-compile NEMP-AGRIF-mono after NEMO-AGRIF-mpp
+#- I guess the good correction should be in AGRIF/LIB/toamr.c for the conv, to remove useless allocation declarations in AGRIF_INC
+# recompile all in this case
+mpiagrif:
+ifeq ($(AGRIF),use)
+ifeq (,$(AGRIF_MPI))
+	@if [ -n "`cat KEY_CPP | grep key_mpp_mpi`" ]; then $(RM) -r OPAFILES model_tam.o $(MODDIR)/ocetam/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi
+endif
+endif
+# key changing control
+key: 
+	@echo CHANGE of CPP KEYS yes/no ?
+	-@if [ "`cat KEY_CPP`" != "$(P_P:$(prefix)%=%)" ] ; then \
+		echo CPP options changed ; echo "$(P_P:$(prefix)%=%)" > KEY_CPP ; fi 
+# check key values
+keyverif:
+	@echo CHECKING KEY
+	@echo KEY USED : 
+	@for v in ` echo $(P_P:$(prefix)%=%) ` ; \
+	do \
+	echo $$v ;\
+        w=`echo $$v | cut -c1-3` ; \
+        if [ $$w = `echo "key"` ] ; then \
+        r=n ; \
+        echo " $(KEY_LIST) " | (grep $$v >/dev/null 2>&1) || r=o ; \
+           if [ $$r != "n" ] ; then \
+              echo "UNKNOWN KEY" ;\
+              false ;  \
+              exit ;  \
+           fi \
+        fi \
+	done
+# Checking the number of routines
+src_file_list: 
+	@echo CHECKING THE NUMBER AND NAMES OF SOURCE FILES 
+	@$(RM) `ls | fgrep -v -f .patron` 
+	@check=`grep OPA_SRC .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use OPA_SRC files"                ; \
+	    ln -sf ../../NEMO/OPA_SRC/*.[Ffh]90          . ; \
+	    ln -sf ../../NEMO/OPA_SRC/*/*.[Ffh]90      . ; \
+	fi 
+	@check=`grep OPATAM_SRC .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use OPATAM_SRC files"                ; \
+	    ln -sf ../OPATAM_SRC/*.[Ffh]90          . ; \
+	    ln -sf ../OPATAM_SRC/*/*.[Ffh]90      . ; \
+	fi 
+	@check=`grep LIM_SRC_2 .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use LIM_SRC_2 files"                ; \
+	    ln -sf ../../NEMO/LIM_SRC_2/*.[Ffh]90          . ; \
+	fi 
+	@check=`grep C1D_SRC .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use C1D_SRC files"                ; \
+	    ln -sf ../../NEMO/C1D_SRC/*.[Ffh]90          . ; \
+	fi 
+	@\$(RM) tmplist
+	@ls -1 | fgrep -v -f .patron  >tmplist
+	@cmp tmplist SRC_FILE_LIST.temp || { echo some routines have been added or suppressed ; \
+	sdiff -s tmplist SRC_FILE_LIST.temp ; cp tmplist SRC_FILE_LIST.temp ; \
+	\$(RM) model_tam.o \$(MODEL_LIB) \$(SXMODEL_LIB) \$(EXEC_BIN) ; \
+	echo "Rebuilding the AA_make files" ; \
+	cd ..  ; ../UTIL/fait_AA_make_tam ; echo " " ; \
+	echo "THE ins_make COMMAND in modipsl/util MUST BE RERUN PLEASE DO SO BEFORE gmake" ; \
+	echo "========================================== " ; \
+	../../util/ins_make ; echo " " ;  false ; exit ; }
Index: branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/scripts/BB_make.ldef
===================================================================
--- branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/scripts/BB_make.ldef	(revision 2578)
+++ branches/TAM_V3_2_2/CONFIG/ORCA2_TAM/scripts/BB_make.ldef	(revision 2578)
@@ -0,0 +1,63 @@
+#----------------------------------------------------------------------
+#- NEMO SYSTEM : Ocean model + Sea Ice Model   (BB_make.ldef in scripts)
+#----------------------------------------------------------------------
+SHELL = /bin/sh
+#-
+#-Q- t3e     #--- Please use gmake instead of make
+#-Q- fjvpp   #--- Please use gmake instead of make
+
+#-
+#- Define the libraries ---
+LIBDIR = ../../../lib
+MODDIR = $(LIBDIR)
+MODEL_LIB = $(LIBDIR)/ocetam/libopa.a
+IOIPSL_LIB = $(LIBDIR)/libioipsl.a
+#-Q- sxdkrz IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+#-Q- eshpux IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+AGRIF_LIB = $(LIBDIR)/libagrif.a
+#-Q- sxdkrz AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+#-Q- eshpux AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+SXMODEL_LIB = $(MODEL_LIB)
+#-Q- sxdkrz SXMODEL_LIB = $(LIBDIR)/ocetam/libsxopa.a
+#-Q- eshpux SXMODEL_LIB = $(LIBDIR)/ocetam/libsxopa.a
+OASISMPI2_LIB = 
+LIBMPI  =
+LIBMP   =
+EXEC_BIN = ../../../bin/opatam
+
+#-
+#- Key options for OPA ocean model : ORCA_R2 - FORCED 
+#  Keys have to be written on one single line (does NOT accept "\")
+
+P_P=key_orca_r2 \
+key_trabbl_dif \
+key_dynspg_flt \
+key_ldfslp  \
+key_traldf_c2d \
+key_traldf_eiv \
+key_dynldf_c3d \
+key_tradmp \
+key_dtatem \
+key_dtasal \
+key_trabbc \
+key_zdftke \
+key_zdfddm \
+key_diahth \
+key_tam
+
+#-
+#- Prefix for preprocessing ---
+prefix = -D
+#-Q- sx8mercure prefix = -D
+#-Q- sx8brodie prefix = -D
+#-Q- eshpux prefix = -D
+#-Q- sxdkrz prefix = -D
+#-Q- linux  prefix = -D
+#-Q- lxiv7  prefix = -D
+#-Q- lxiv8  prefix = -D
+#-Q- g95    prefix = -D
+#-Q- gfortran  prefix = -D
+#-Q- aix    prefix = -WF,-D
+#-Q- babel  prefix = -WF,-D
+#-Q- osxxlf prefix = -WF,-D
+
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/DOM/daymod.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/DOM/daymod.F90	(revision 2577)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/DOM/daymod.F90	(revision 2578)
@@ -39,6 +39,8 @@
    PUBLIC   day        ! called by step.F90
    PUBLIC   day_init   ! called by istate.F90
-
-   INTEGER ::   nsecd, nsecd05, ndt, ndt05
+   PUBLIC   day_mth    ! called by daymod_tam.F90
+
+   INTEGER, PUBLIC ::   nsecd, ndt, ndt05
+   INTEGER ::   nsecd05
 
    !!----------------------------------------------------------------------
@@ -239,5 +241,6 @@
       ENDIF
 
-      IF( lrst_oce )   CALL day_rst( kt, 'WRITE' )
+      CALL rst_opn( kt )                                ! Open the restart file if needed and control lrst_oce
+      IF( lrst_oce )   CALL day_rst( kt, 'WRITE' )      ! write day restart information
       !
    END SUBROUTINE day
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/DYN/dynadv.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/DYN/dynadv.F90	(revision 2577)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/DYN/dynadv.F90	(revision 2578)
@@ -23,4 +23,5 @@
 
    PUBLIC dyn_adv     ! routine called by step module
+   PUBLIC dyn_adv_ctl ! routine called by dynadv_tam module
  
    LOGICAL, PUBLIC ::   ln_dynadv_vec  = .TRUE.    ! vector form flag
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/DYN/dynhpg.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 2577)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 2578)
@@ -51,7 +51,6 @@
    REAL(wp), PUBLIC ::   rn_gamma      = 0.e0      !: weighting coefficient
    LOGICAL , PUBLIC ::   ln_dynhpg_imp = .FALSE.   !: semi-implicite hpg flag
-   INTEGER , PUBLIC ::   nn_dynhpg_rst = 0         !: add dynhpg implicit variables in restart ot not
-
-   INTEGER  ::   nhpg  =  0   ! = 0 to 6, type of pressure gradient scheme used ! (deduced from ln_hpg_... flags)
+
+   INTEGER , PUBLIC ::   nhpg  =  0   ! = 0 to 6, type of pressure gradient scheme used ! (deduced from ln_hpg_... flags)
 
    !! * Substitutions
@@ -124,5 +123,5 @@
 !     NAMELIST/namdyn_hpg/ ln_hpg_zco   , ln_hpg_zps   , ln_hpg_sco, ln_hpg_hel,   &
 !        &                 ln_hpg_wdj   , ln_hpg_djc   , ln_hpg_rot, rn_gamma  ,   &
-!        &                 ln_dynhpg_imp, nn_dynhpg_rst
+!        &                 ln_dynhpg_imp
       !!----------------------------------------------------------------------
 
@@ -144,8 +143,5 @@
          WRITE(numout,*) '      weighting coeff. (wdj scheme)                     rn_gamma      = ', rn_gamma
          WRITE(numout,*) '      time stepping: centered (F) or semi-implicit (T)  ln_dynhpg_imp = ', ln_dynhpg_imp
-         WRITE(numout,*) '      add in restart dynhpg semi-implicit variable      nn_dynhpg_rst = ', nn_dynhpg_rst
       ENDIF
-
-      IF( .NOT. ln_dynhpg_imp )   nn_dynhpg_rst = 0      ! force no adding dynhpg implicit variables in restart
 
       IF( lk_vvl .AND. .NOT. ln_hpg_sco )   THEN
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/DYN/sshwzv.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/DYN/sshwzv.F90	(revision 2577)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/DYN/sshwzv.F90	(revision 2578)
@@ -27,4 +27,6 @@
    USE diaar5, ONLY :   lk_diaar5
    USE iom
+   USE agrif_opa_interp
+   USE agrif_opa_update
 
    IMPLICIT NONE
@@ -137,5 +139,5 @@
 
                          CALL div_cur( kt )            ! Horizontal divergence & Relative vorticity
-      IF( n_cla == 1 )   CALL div_cla( kt )            ! Cross Land Advection (Update Hor. divergence)
+         IF( n_cla == 1 )   CALL div_cla( kt )            ! Cross Land Advection (Update Hor. divergence)
 
       ! set time step size (Euler/Leapfrog)
@@ -145,45 +147,44 @@
       zraur = 1. / rau0
 
-      !                                           !------------------------------!
-      !                                           !   After Sea Surface Height   !
-      !                                           !------------------------------!
-      zhdiv(:,:) = 0.e0
-      DO jk = 1, jpkm1                                 ! Horizontal divergence of barotropic transports
-        zhdiv(:,:) = zhdiv(:,:) + fse3t(:,:,jk) * hdivn(:,:,jk)
-      END DO
-
-      !                                                ! Sea surface elevation time stepping
-      ssha(:,:) = (  sshb(:,:) - z2dt * ( zraur * emp(:,:) + zhdiv(:,:) )  ) * tmask(:,:,1)
-
+         !                                           !------------------------------!
+         !                                           !   After Sea Surface Height   !
+         !                                           !------------------------------!
+         zhdiv(:,:) = 0.e0
+         DO jk = 1, jpkm1                                 ! Horizontal divergence of barotropic transports
+            zhdiv(:,:) = zhdiv(:,:) + fse3t(:,:,jk) * hdivn(:,:,jk)
+         END DO
+
+         !                                                ! Sea surface elevation time stepping
+         ssha(:,:) = (  sshb(:,:) - z2dt * ( zraur * emp(:,:) + zhdiv(:,:) )  ) * tmask(:,:,1)
+
+# if defined key_agrif
+      CALL agrif_ssh(kt)
+# endif
 #if defined key_obc
-# if defined key_agrif
       IF ( Agrif_Root() ) THEN 
+            ssha(:,:) = ssha(:,:) * obctmsk(:,:)
+            CALL lbc_lnk( ssha, 'T', 1. )  ! absolutly compulsory !! (jmm)
+         ENDIF
 # endif
-         ssha(:,:) = ssha(:,:) * obctmsk(:,:)
-         CALL lbc_lnk( ssha, 'T', 1. )  ! absolutly compulsory !! (jmm)
-# if defined key_agrif
-      ENDIF
-# endif
-#endif
-
-      !                                                ! Sea Surface Height at u-,v- and f-points (vvl case only)
-      IF( lk_vvl ) THEN                                ! (required only in key_vvl case)
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1      ! NO Vector Opt.
-               sshu_a(ji,jj) = 0.5  * umask(ji,jj,1) / ( e1u(ji  ,jj) * e2u(ji  ,jj) )                   &
-                  &                                  * ( e1t(ji  ,jj) * e2t(ji  ,jj) * ssha(ji  ,jj)     &
-                  &                                    + e1t(ji+1,jj) * e2t(ji+1,jj) * ssha(ji+1,jj) )
-               sshv_a(ji,jj) = 0.5  * vmask(ji,jj,1) / ( e1v(ji,jj  ) * e2v(ji,jj  ) )                   &
-                  &                                  * ( e1t(ji,jj  ) * e2t(ji,jj  ) * ssha(ji,jj  )     &
-                  &                                    + e1t(ji,jj+1) * e2t(ji,jj+1) * ssha(ji,jj+1) )
-               sshf_a(ji,jj) = 0.25 * umask(ji,jj,1) * umask (ji,jj+1,1)                                 & 
-                  &                                  * ( ssha(ji  ,jj) + ssha(ji  ,jj+1)                 &
-                  &                                    + ssha(ji+1,jj) + ssha(ji+1,jj+1) )
-            END DO
-         END DO
-         CALL lbc_lnk( sshu_a, 'U', 1. )               ! Boundaries conditions
-         CALL lbc_lnk( sshv_a, 'V', 1. )
-         CALL lbc_lnk( sshf_a, 'F', 1. )
-      ENDIF
+
+         !                                                ! Sea Surface Height at u-,v- and f-points (vvl case only)
+         IF( lk_vvl ) THEN                                ! (required only in key_vvl case)
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1      ! NO Vector Opt.
+                  sshu_a(ji,jj) = 0.5  * umask(ji,jj,1) / ( e1u(ji  ,jj) * e2u(ji  ,jj) )                   &
+                       &                                  * ( e1t(ji  ,jj) * e2t(ji  ,jj) * ssha(ji  ,jj)     &
+                       &                                    + e1t(ji+1,jj) * e2t(ji+1,jj) * ssha(ji+1,jj) )
+                  sshv_a(ji,jj) = 0.5  * vmask(ji,jj,1) / ( e1v(ji,jj  ) * e2v(ji,jj  ) )                   &
+                       &                                  * ( e1t(ji,jj  ) * e2t(ji,jj  ) * ssha(ji,jj  )     &
+                       &                                    + e1t(ji,jj+1) * e2t(ji,jj+1) * ssha(ji,jj+1) )
+                  sshf_a(ji,jj) = 0.25 * umask(ji,jj,1) * umask (ji,jj+1,1)                                 & 
+                       &                                  * ( ssha(ji  ,jj) + ssha(ji  ,jj+1)                 &
+                       &                                    + ssha(ji+1,jj) + ssha(ji+1,jj+1) )
+               END DO
+            END DO
+            CALL lbc_lnk( sshu_a, 'U', 1. )               ! Boundaries conditions
+            CALL lbc_lnk( sshv_a, 'V', 1. )
+            CALL lbc_lnk( sshf_a, 'F', 1. )
+         ENDIF
 
       !                                           !------------------------------!
@@ -197,15 +198,15 @@
       END DO
       !
-      CALL iom_put( "woce", wn                    )   ! vertical velocity
-      CALL iom_put( "ssh" , sshn                  )   ! sea surface height
-      CALL iom_put( "ssh2", sshn(:,:) * sshn(:,:) )   ! square of sea surface height
-      IF( lk_diaar5 ) THEN
-         z2d(:,:) = rau0 * e1t(:,:) * e2t(:,:)
-         DO jk = 1, jpk
-            z3d(:,:,jk) = wn(:,:,jk) * z2d(:,:)
-         END DO
-         CALL iom_put( "w_masstr" , z3d                     )   !           vertical mass transport
-         CALL iom_put( "w_masstr2", z3d(:,:,:) * z3d(:,:,:) )   ! square of vertical mass transport
-      ENDIF
+         CALL iom_put( "woce", wn                    )   ! vertical velocity
+         CALL iom_put( "ssh" , sshn                  )   ! sea surface height
+         CALL iom_put( "ssh2", sshn(:,:) * sshn(:,:) )   ! square of sea surface height
+         IF( lk_diaar5 ) THEN
+            z2d(:,:) = rau0 * e1t(:,:) * e2t(:,:)
+            DO jk = 1, jpk
+               z3d(:,:,jk) = wn(:,:,jk) * z2d(:,:)
+            END DO
+            CALL iom_put( "w_masstr" , z3d                     )   !           vertical mass transport
+            CALL iom_put( "w_masstr2", z3d(:,:,:) * z3d(:,:,:) )   ! square of vertical mass transport
+         ENDIF
       !
    END SUBROUTINE ssh_wzv
@@ -279,4 +280,9 @@
       ENDIF
       !
+#if defined key_agrif
+      ! Update velocity at AGRIF zoom boundaries
+      IF (.NOT.Agrif_Root())    CALL Agrif_Update_Dyn( kt )
+#endif
+
       IF(ln_ctl)   CALL prt_ctl(tab2d_1=sshb    , clinfo1=' sshb  - : ', mask1=tmask, ovlap=1 )
       !
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/TAM/tamtrj.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/TAM/tamtrj.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/TAM/tamtrj.F90	(revision 2578)
@@ -0,0 +1,193 @@
+MODULE tamtrj
+   !!======================================================================
+   !!                       ***  MODULE tamtrj  ***
+   !! Tangent and adjoint  trajectory interface: Write to file 
+   !!                                    the model state trajectory
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !!   tam_trj_ini  : init: read the namelist
+   !!   tam_trj_wri  : Write out the model state trajectory 
+   !!----------------------------------------------------------------------
+   !! * Modules used   
+   USE oce                ! Dynamics and active tracers defined in memory
+   USE sbc_oce            ! Ocean surface boundary conditions
+   USE zdf_oce            ! Vertical mixing variables
+#if defined key_zdfddm 
+   USE zdfddm, ONLY : &   ! Double diffusion mixing parameterization
+      & avs               ! Salinity vertical diffusivity coeff. at w-point
+#endif
+   USE ldftra_oce         ! Lateral tracer mixing coefficient defined in memory
+#if   defined key_ldfslp
+   USE ldfslp, ONLY : &   ! Slopes of neutral surfaces
+      & uslp, wslpi,  &   ! i_slope at U- and W-points
+      & vslp, wslpj       ! j-slope at V- and W-points
+#endif
+   USE zdfbfr,    ONLY:&  ! bottom friction
+      & bfrua,         &
+      & bfrva
+   USE tradmp             ! Tracer damping
+   USE sol_oce, ONLY : &  ! Solver variables defined in memory
+      & gcx
+   USE trc_oce       , ONLY: & ! share SMS/Ocean variables
+      & etot3
+   USE in_out_manager, ONLY : &  ! I/O manager
+      & lwp,     &
+      & numout
+   USE dom_oce, ONLY : &
+      & ndastp
+   USE iom                 ! I/O module
+   USE zdfmxl, ONLY : &   ! mixed layer depth
+      & hmlp
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+   PUBLIC tam_trj_init, &  !: Write out the background state
+      &   tam_trj_wri      !: Write out the background state
+
+   LOGICAL, PUBLIC :: & 
+      & ln_trjwri = .FALSE.   !: No output of the state trajectory fields
+
+   LOGICAL :: &
+      & ln_trj_spl            !: save the trajectory at simple precision
+
+   CHARACTER (LEN=40), PUBLIC :: &
+      & cn_dirtrj                                  !: Filename for storing the 
+                                                   !: reference trajectory
+   INTEGER, PUBLIC :: &          
+      & nn_ittrjfrq         !: Frequency of trajectory output for 4D-VAR
+
+CONTAINS
+   SUBROUTINE tam_trj_init
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tam_trj_init ***
+      !!
+      !! ** Purpose : initialize the model state trajectory 
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 10-01 (A. Vidard) 
+      !!-----------------------------------------------------------------------
+
+      IMPLICIT NONE
+
+      !! * Modules used
+      NAMELIST/namtrj/ nn_ittrjfrq, ln_trjwri, cn_dirtrj, ln_trj_spl
+
+      cn_dirtrj   = 'tam_trajectory'
+      ln_trjwri   = .FALSE.
+      nn_ittrjfrq = 1
+      ln_trj_spl  = .TRUE.
+
+      REWIND ( numnam )
+      READ   ( numnam, namtrj )
+
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tam_trj_ini : Trajectory handling:'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '          Namelist namtam : set trajectory parameters'
+         WRITE(numout,*) '             Logical switch for writing out state trajectory         ', &
+            &            ' ln_trjwri   = ', ln_trjwri
+         WRITE(numout,*) '             Logical switch for writing it at simple precision       ', &
+            &            ' ln_trj_spl  = ', ln_trj_spl
+         WRITE(numout,*) '             Frequency of trajectory output                          ', &
+            &            ' nn_ittrjfrq = ', nn_ittrjfrq
+      END IF
+   END SUBROUTINE tam_trj_init
+   SUBROUTINE tam_trj_wri( kt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tam_trj_wri ***
+      !!
+      !! ** Purpose : Write to file the model state trajectory 
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 2007-04 (A. Weaver) 
+      !!        ! 2009-03 (F. Vigilant) Add hmlp (zdfmxl) for no tracer nmldp=2 
+      !!        ! 2009-06 (F. Vigilant) special case when kt=nit000-1
+      !!        ! 2009-07 (F. Vigilant) add computation of eiv at restart
+      !!        ! 2010-01 (A. Vidard) asm_trj_wri->tam_trj_wri
+      !!        ! 2010-04 (F. Vigilant) converison to 3.2
+      !!-----------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER, INTENT( IN ) :: &
+         & kt                    ! Current time-step
+
+      !! * Local declarations
+      INTEGER :: &
+         & inum                  ! File unit number
+      INTEGER :: &
+         & it
+      INTEGER :: &
+         & ntype
+      CHARACTER (LEN=50) :: &
+         & cl_dirtrj
+      REAL(wp) :: &
+         & zdate            ! Date
+
+      IF ( ln_trj_spl ) THEN ; ntype = jp_r4 
+                        ELSE ; ntype = jp_r8 ; ENDIF
+      !------------------------------------------------------------------------
+      ! Write a single file for each trajectory time step
+      !------------------------------------------------------------------------
+      IF ( ( MOD( kt - nit000 + 1, nn_ittrjfrq ) == 0 ) .OR. &
+         & ( kt == nitend ) ) THEN
+         
+         it = kt - nit000 + 1
+
+         ! Define the output file        
+         WRITE(cl_dirtrj, FMT='(A,A,I5.5)' ) TRIM( cn_dirtrj ), '_', it
+         cl_dirtrj = TRIM( cl_dirtrj )
+         CALL iom_open( cl_dirtrj, inum, ldwrt = .TRUE., kiolib = jprstlib)
+
+         ! Output trajectory fields
+         CALL iom_rstput( it, it, inum, 'emp'   , emp   , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'emps'  , emps  , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'un'    , un    , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'vn'    , vn    , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'tn'    , tn    , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'sn'    , sn    , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'avmu'  , avmu  , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'avmv'  , avmv  , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'avt'   , avt   , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'bfrua' , bfrua , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'bfrva' , bfrva , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'etot3' , etot3 , ktype = ntype )
+#if defined key_ldfslp
+         CALL iom_rstput( it, it, inum, 'uslp'  , uslp  , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'vslp'  , vslp  , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'wslpi' , wslpi , ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'wslpj' , wslpj , ktype = ntype )
+#endif
+#if defined key_zdfddm
+         CALL iom_rstput( it, it, inum, 'avs'   , avs , ktype = ntype )
+#endif
+#if defined key_tradmp
+         CALL iom_rstput( it, it, inum, 'hmlp'  , hmlp, ktype = ntype )
+#endif
+         CALL iom_rstput( it, it, inum, 'aeiu'  , aeiu, ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'aeiv'  , aeiv, ktype = ntype )
+         CALL iom_rstput( it, it, inum, 'aeiw'  , aeiw, ktype = ntype )
+
+         CALL iom_close( inum )
+         
+      ENDIF
+
+   END SUBROUTINE tam_trj_wri
+END MODULE tamtrj
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/TRA/eosbn2.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/TRA/eosbn2.F90	(revision 2577)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/TRA/eosbn2.F90	(revision 2578)
@@ -16,4 +16,5 @@
    !!             -   ! 2003-08  (G. Madec)  F90, free form
    !!            3.0  ! 2006-08  (G. Madec)  add tfreez function
+   !!                 ! 2009-03  (M. Balmaseda) compute refrence rho prof
    !!----------------------------------------------------------------------
 
@@ -24,7 +25,9 @@
    !!                    volumic mass
    !!   eos_insitu_2d  : Compute the in situ density for 2d fields
+   !!   eos_insitu_pot_1pt : Compute the in situ density for a single point
    !!   eos_bn2        : Compute the Brunt-Vaisala frequency
    !!   tfreez         : Compute the surface freezing temperature
    !!   eos_init       : set eos parameters (namelist)
+   !!   eos_rprof      : Compute the in situ density of a reference profile
    !!----------------------------------------------------------------------
    USE dom_oce         ! ocean space and time domain
@@ -56,4 +59,5 @@
 
    REAL(wp), PUBLIC ::   ralpbet           !: alpha / beta ratio
+   INTEGER, PUBLIC  ::   neos_init = 0     !: control flag for initialization
    
    !! * Substitutions
@@ -592,4 +596,6 @@
       !!----------------------------------------------------------------------
       !
+      neos_init = 1               ! indicate that the initialization has been done
+
       REWIND( numnam )            ! Read Namelist nameos : equation of state
       READ  ( numnam, nameos )
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/TRA/tradmp.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 2577)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 2578)
@@ -41,4 +41,5 @@
 
    PUBLIC   tra_dmp    ! routine called by step.F90
+   PUBLIC cofdis, dtacof, dtacof_zoom
 
 #if ! defined key_agrif
@@ -315,5 +316,5 @@
       resto(:,:,:) = 0.e0
 
-      !                           !-----------------------------------------!
+         !                        !-----------------------------------------!
       IF( nn_hdmp > 0 ) THEN      !  Damping poleward of 'nn_hdmp' degrees  !
          !                        !-----------------------------------------!
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/TRA/tranxt.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 2577)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 2578)
@@ -38,4 +38,5 @@
    USE agrif_opa_update
    USE agrif_opa_interp
+   USE obc_oce
 
    IMPLICIT NONE
@@ -44,5 +45,5 @@
    PUBLIC   tra_nxt    ! routine called by step.F90
 
-   REAL(wp), DIMENSION(jpk) ::   r2dt_t   ! vertical profile time step, =2*rdttra (leapfrog) or =rdttra (Euler)
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   r2dt_t   ! vertical profile time step, =2*rdttra (leapfrog) or =rdttra (Euler)
 
    !! * Substitutions
@@ -101,5 +102,5 @@
       !
 #if defined key_obc
-      CALL obc_tra( kt )               ! OBC open boundaries
+      IF( lk_obc )   CALL obc_tra( kt ) ! OBC open boundaries
 #endif
 #if defined key_bdy
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/TRA/traqsr.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 2577)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 2578)
@@ -32,5 +32,5 @@
 
    PUBLIC   tra_qsr        ! routine called by step.F90 (ln_traqsr=T)
-
+   PUBLIC   tra_qsr_init   ! routine called by traqsr_tam.F90 (ln_traqsr=T)
    !                                           !!* Namelist namtra_qsr: penetrative solar radiation
    LOGICAL , PUBLIC ::   ln_traqsr  = .TRUE.    !: light absorption (qsr) flag
@@ -45,7 +45,7 @@
    
    ! Module variables
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_chl   ! structure of input Chl (file informations, fields read)
-   INTEGER ::   nksr   ! levels below which the light cannot penetrate ( depth larger than 391 m)
-   REAL(wp), DIMENSION(3,61) ::   rkrgb   !: tabulated attenuation coefficients for RGB absorption
+   TYPE(FLD), PUBLIC, ALLOCATABLE, DIMENSION(:) ::   sf_chl   ! structure of input Chl (file informations, fields read)
+   INTEGER, PUBLIC :: nksr   ! levels below which the light cannot penetrate ( depth larger than 391 m)
+   REAL(wp), PUBLIC, DIMENSION(3,61) ::   rkrgb   !: tabulated attenuation coefficients for RGB absorption
 
    !! * Substitutions
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/ZDF/zdftke.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 2577)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 2578)
@@ -87,5 +87,5 @@
 
    REAL(wp), DIMENSION(jpi,jpj)     ::   htau      ! depth of tke penetration (nn_htau)
-   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   en        ! now turbulent kinetic energy   [m2/s2]
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::  en ! now turbulent kinetic energy   [m2/s2]
    REAL(wp), DIMENSION(jpi,jpj,jpk) ::   dissl     ! now mixing lenght of dissipation
 
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/ZDF/zdftke_old.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/ZDF/zdftke_old.F90	(revision 2577)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/ZDF/zdftke_old.F90	(revision 2578)
@@ -31,5 +31,5 @@
    !!   zdf_tke_old  : update momentum and tracer Kz from a tke scheme
    !!   zdf_tke_init : initialization, namelist read, and parameters control
-   !!   tke_rst      : read/write tke restart in ocean restart file
+   !!   tke_old_rst  : read/write tke restart in ocean restart file
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and active tracers 
@@ -49,4 +49,5 @@
 
    PUBLIC   zdf_tke_old   ! routine called in step module
+   PUBLIC   tke_old_rst       ! routine called in asm module
 
    LOGICAL , PUBLIC, PARAMETER              ::   lk_zdftke_old = .TRUE.  !: TKE vertical mixing flag
@@ -66,18 +67,14 @@
 
    !                                       !!! ** Namelist  namzdf_tke  **
-   LOGICAL  ::   ln_rstke = .FALSE.         ! =T restart with tke from a run without tke
    LOGICAL  ::   ln_mxl0  = .FALSE.         ! mixing length scale surface value as function of wind stress or not
    LOGICAL  ::   ln_lc    = .FALSE.         ! Langmuir cells (LC) as a source term of TKE or not
-   INTEGER  ::   nn_itke  = 50              ! number of restart iterative loops
    INTEGER  ::   nn_mxl   =  2              ! type of mixing length (=0/1/2/3)
    INTEGER  ::   nn_pdl   =  1              ! Prandtl number or not (ratio avt/avm) (=0/1)
-   INTEGER  ::   nn_ave   =  1              ! horizontal average or not on avt, avmu, avmv (=0/1)
    REAL(wp) ::   rn_ediff = 0.1_wp          ! coefficient for avt: avt=rn_ediff*mxl*sqrt(e)
    REAL(wp) ::   rn_ediss = 0.7_wp          ! coefficient of the Kolmogoroff dissipation 
    REAL(wp) ::   rn_ebb   = 3.75_wp         ! coefficient of the surface input of tke
-   REAL(wp) ::   rn_efave = 1._wp           ! coefficient for ave : ave=rn_efave*avm
    REAL(wp) ::   rn_emin  = 0.7071e-6_wp    ! minimum value of tke (m2/s2)
    REAL(wp) ::   rn_emin0 = 1.e-4_wp        ! surface minimum value of tke (m2/s2)
-   REAL(wp) ::   rn_cri   = 2._wp / 9._wp   ! critic Richardson number
+   REAL(wp) ::   rn_bshear= 1.e-20_wp       ! background shear (>0)    (Not used in old TKE)
    INTEGER  ::   nn_etau  = 0               ! type of depth penetration of surface tke (=0/1/2)
    INTEGER  ::   nn_htau  = 0               ! type of tke profile of penetration (=0/1)
@@ -85,5 +82,12 @@
    REAL(wp) ::   rn_lmin  = 0.1_wp          ! interior min value of mixing length
    REAL(wp) ::   rn_efr   = 1.0_wp          ! fraction of TKE surface value which penetrates in the ocean
+   REAL(wp) ::   rn_addhft= 0.0_wp          ! add offset   applied to HF tau    (Not used in old TKE)
+   REAL(wp) ::   rn_sclhft= 1.0_wp          ! scale factor applied to HF tau    (Not used in old TKE)
    REAL(wp) ::   rn_lc    = 0.15_wp         ! coef to compute vertical velocity of Langmuir cells
+
+  !                                       !! ** old namelist value: now hard coded **
+   INTEGER  ::   nn_ave   =  1              ! horizontal average or not on avt, avmu, avmv (=0/1)
+   REAL(wp) ::   rn_efave = 1._wp           ! coefficient for ave : ave=rn_efave*avm
+   REAL(wp) ::   rn_cri   = 2._wp / 9._wp   ! critic Richardson number
 
    !! * Substitutions
@@ -686,5 +690,5 @@
       CALL lbc_lnk( avt, 'W', 1. )                      ! Lateral boundary conditions on avt  (sign unchanged)
 
-      IF( lrst_oce )   CALL tke_rst( kt, 'WRITE' )      ! write en in restart file
+      IF( lrst_oce )   CALL tke_old_rst( kt, 'WRITE' )      ! write en in restart file
 
       IF(ln_ctl) THEN
@@ -721,8 +725,9 @@
 # endif
       !!
-      NAMELIST/namzdf_tke/ ln_rstke, rn_ediff, rn_ediss, rn_ebb  , rn_efave, rn_emin,   &
-         &                 rn_emin0, rn_cri  , nn_itke , nn_mxl  , nn_pdl  , nn_ave ,   &
-         &                 ln_mxl0 , rn_lmin , rn_lmin0, nn_etau,   &
-         &                 nn_htau , rn_efr  , ln_lc   , rn_lc 
+      NAMELIST/namzdf_tke/ rn_ediff, rn_ediss , rn_ebb   , rn_emin  ,   &
+         &                 rn_emin0, rn_bshear, nn_mxl   , ln_mxl0  ,   &
+         &                 rn_lmin , rn_lmin0 , nn_pdl   , nn_etau  ,   &
+         &                 nn_htau , rn_efr   , rn_addhft, rn_sclhft,   &
+         &                 ln_lc   , rn_lc 
       !!----------------------------------------------------------------------
 
@@ -747,12 +752,9 @@
          WRITE(numout,*) '~~~~~~~~~~~~'
          WRITE(numout,*) '          Namelist namzdf_tke : set tke mixing parameters'
-         WRITE(numout,*) '             restart with tke from no tke              ln_rstke = ', ln_rstke
          WRITE(numout,*) '             coef. to compute avt                      rn_ediff = ', rn_ediff
          WRITE(numout,*) '             Kolmogoroff dissipation coef.             rn_ediss = ', rn_ediss
          WRITE(numout,*) '             tke surface input coef.                   rn_ebb   = ', rn_ebb
-         WRITE(numout,*) '             tke diffusion coef.                       rn_efave = ', rn_efave
          WRITE(numout,*) '             minimum value of tke                      rn_emin  = ', rn_emin
          WRITE(numout,*) '             surface minimum value of tke              rn_emin0 = ', rn_emin0
-         WRITE(numout,*) '             number of restart iter loops              nn_itke  = ', nn_itke
          WRITE(numout,*) '             mixing length type                        nn_mxl   = ', nn_mxl
          WRITE(numout,*) '             prandl number flag                        nn_pdl   = ', nn_pdl
@@ -852,10 +854,10 @@
       ! read or initialize turbulent kinetic energy ( en )
       ! -------------------------------------------------
-      CALL tke_rst( nit000, 'READ' )
+      CALL tke_old_rst( nit000, 'READ' )
       !
    END SUBROUTINE zdf_tke_init
 
 
-   SUBROUTINE tke_rst( kt, cdrw )
+   SUBROUTINE tke_old_rst( kt, cdrw )
      !!---------------------------------------------------------------------
      !!                   ***  ROUTINE ts_rst  ***
@@ -875,13 +877,11 @@
      IF( TRIM(cdrw) == 'READ' ) THEN
         IF( ln_rstart ) THEN
-           IF( iom_varid( numror, 'en', ldstop = .FALSE. ) > 0 .AND. .NOT.(ln_rstke) ) THEN 
+           IF( iom_varid( numror, 'en', ldstop = .FALSE. ) > 0 ) THEN 
               CALL iom_get( numror, jpdom_autoglo, 'en', en )
            ELSE
-              IF( lwp .AND. iom_varid( numror, 'en', ldstop = .FALSE. ) > 0 )   &
-                 &                       WRITE(numout,*) ' ===>>>> : previous run without tke scheme'
-              IF( lwp .AND. ln_rstke )   WRITE(numout,*) ' ===>>>> : We do not use en from the restart file'
+              IF(lwp)  WRITE(numout,*) ' ===>>>> : previous run without tke scheme'
               IF( lwp                )   WRITE(numout,*) ' ===>>>> : en is set by iterative loop'
               en (:,:,:) = rn_emin * tmask(:,:,:)
-              DO jit = 2, nn_itke + 1
+              DO jit = 2, 51
                  CALL zdf_tke_old( jit )
               END DO
@@ -894,5 +894,5 @@
      ENDIF
      !
-   END SUBROUTINE tke_rst
+   END SUBROUTINE tke_old_rst
 
 #else
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/lib_mpp.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/lib_mpp.F90	(revision 2577)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/lib_mpp.F90	(revision 2578)
@@ -112,5 +112,7 @@
    INTEGER ::   mppsize        ! number of process
    INTEGER ::   mpprank        ! process number  [ 0 - size-1 ]
-   INTEGER ::   mpi_comm_opa   ! opa local communicator
+!$AGRIF_DO_NOT_TREAT
+   INTEGER, PUBLIC ::   mpi_comm_opa   ! opa local communicator
+!$AGRIF_END_DO_NOT_TREAT
 
    ! variables used in case of sea-ice
@@ -129,16 +131,16 @@
    
    ! North fold condition in mpp_mpi with jpni > 1
-   INTEGER ::   ngrp_world        ! group ID for the world processors
-   INTEGER ::   ngrp_opa          ! group ID for the opa processors
-   INTEGER ::   ngrp_north        ! group ID for the northern processors (to be fold)
-   INTEGER ::   ncomm_north       ! communicator made by the processors belonging to ngrp_north
-   INTEGER ::   ndim_rank_north   ! number of 'sea' processor in the northern line (can be /= jpni !)
-   INTEGER ::   njmppmax          ! value of njmpp for the processors of the northern line
-   INTEGER ::   north_root        ! number (in the comm_opa) of proc 0 in the northern comm
-   INTEGER, DIMENSION(:), ALLOCATABLE ::   nrank_north   ! dimension ndim_rank_north
+   INTEGER, PUBLIC ::   ngrp_world        ! group ID for the world processors
+   INTEGER, PUBLIC ::   ngrp_opa          ! group ID for the opa processors
+   INTEGER, PUBLIC ::   ngrp_north        ! group ID for the northern processors (to be fold)
+   INTEGER, PUBLIC ::   ncomm_north       ! communicator made by the processors belonging to ngrp_north
+   INTEGER, PUBLIC ::   ndim_rank_north   ! number of 'sea' processor in the northern line (can be /= jpni !)
+   INTEGER, PUBLIC ::   njmppmax          ! value of njmpp for the processors of the northern line
+   INTEGER, PUBLIC ::   north_root        ! number (in the comm_opa) of proc 0 in the northern comm
+   INTEGER, PUBLIC, DIMENSION(:), ALLOCATABLE ::   nrank_north   ! dimension ndim_rank_north
 
    ! Type of send : standard, buffered, immediate
    CHARACTER(len=1) ::   cn_mpi_send = 'S'    ! type od mpi send/recieve (S=standard, B=bsend, I=isend)
-   LOGICAL          ::   l_isend = .FALSE.   ! isend use indicator (T if cn_mpi_send='I')
+   LOGICAL, PUBLIC  ::   l_isend = .FALSE.   ! isend use indicator (T if cn_mpi_send='I')
    INTEGER          ::   nn_buffer = 0       ! size of the buffer in case of mpi_bsend 
       
@@ -191,67 +193,13 @@
       WRITE(ldtxt(6),*) '      size in bytes of exported buffer   nn_buffer   = ', nn_buffer
 
-#if defined key_agrif
-      IF( Agrif_Root() ) THEN
-#endif
-         !!bug RB : should be clean to use Agrif in coupled mode
-#if ! defined key_agrif
-         CALL mpi_initialized ( mpi_was_called, code )
-         IF( code /= MPI_SUCCESS ) THEN
-            WRITE(*, cform_err)
-            WRITE(*, *) 'lib_mpp: Error in routine mpi_initialized'
-            CALL mpi_abort( mpi_comm_world, code, ierr )
-         ENDIF
-
-         IF( PRESENT(localComm) .and. mpi_was_called ) THEN
-            mpi_comm_opa = localComm
-            SELECT CASE ( cn_mpi_send )
-            CASE ( 'S' )                ! Standard mpi send (blocking)
-               WRITE(ldtxt(7),*) '           Standard blocking mpi send (send)'
-            CASE ( 'B' )                ! Buffer mpi send (blocking)
-               WRITE(ldtxt(7),*) '           Buffer blocking mpi send (bsend)'
-               CALL mpi_init_opa( ierr ) 
-            CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-               WRITE(ldtxt(7),*) '           Immediate non-blocking send (isend)'
-               l_isend = .TRUE.
-            CASE DEFAULT
-               WRITE(ldtxt(7),cform_err)
-               WRITE(ldtxt(8),*) '           bad value for cn_mpi_send = ', cn_mpi_send
-               nstop = nstop + 1
-            END SELECT
-         ELSE IF ( PRESENT(localComm) .and. .not. mpi_was_called ) THEN
-            WRITE(ldtxt(7),*) ' lib_mpp: You cannot provide a local communicator '
-            WRITE(ldtxt(8),*) '          without calling MPI_Init before ! '
-            nstop = nstop + 1
-         ELSE
-#endif
-            SELECT CASE ( cn_mpi_send )
-            CASE ( 'S' )                ! Standard mpi send (blocking)
-               WRITE(ldtxt(7),*) '           Standard blocking mpi send (send)'
-               CALL mpi_init( ierr )
-            CASE ( 'B' )                ! Buffer mpi send (blocking)
-               WRITE(ldtxt(7),*) '           Buffer blocking mpi send (bsend)'
-               CALL mpi_init_opa( ierr )
-            CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-               WRITE(ldtxt(7),*) '           Immediate non-blocking send (isend)'
-               l_isend = .TRUE.
-               CALL mpi_init( ierr )
-            CASE DEFAULT
-               WRITE(ldtxt(7),cform_err)
-               WRITE(ldtxt(8),*) '           bad value for cn_mpi_send = ', cn_mpi_send
-               nstop = nstop + 1
-            END SELECT
-
-#if ! defined key_agrif
-            CALL mpi_comm_dup( mpi_comm_world, mpi_comm_opa, code)
-            IF( code /= MPI_SUCCESS ) THEN
-               WRITE(*, cform_err)
-               WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
-               CALL mpi_abort( mpi_comm_world, code, ierr )
-            ENDIF
-            !
-         ENDIF
-#endif
-#if defined key_agrif
-      ELSE
+      CALL mpi_initialized ( mpi_was_called, code )
+      IF( code /= MPI_SUCCESS ) THEN
+         WRITE(*, cform_err)
+         WRITE(*, *) 'lib_mpp: Error in routine mpi_initialized'
+         CALL mpi_abort( mpi_comm_world, code, ierr )
+      ENDIF
+
+      IF( PRESENT(localComm) .and. mpi_was_called ) THEN
+         !
          SELECT CASE ( cn_mpi_send )
          CASE ( 'S' )                ! Standard mpi send (blocking)
@@ -259,4 +207,5 @@
          CASE ( 'B' )                ! Buffer mpi send (blocking)
             WRITE(ldtxt(7),*) '           Buffer blocking mpi send (bsend)'
+            CALL mpi_init_opa( ierr ) 
          CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
             WRITE(ldtxt(7),*) '           Immediate non-blocking send (isend)'
@@ -267,8 +216,41 @@
             nstop = nstop + 1
          END SELECT
+      ELSE IF ( PRESENT(localComm) .and. .not. mpi_was_called ) THEN
+         WRITE(ldtxt(7),*) ' lib_mpp: You cannot provide a local communicator '
+         WRITE(ldtxt(8),*) '          without calling MPI_Init before ! '
+         nstop = nstop + 1
+      ELSE
+         SELECT CASE ( cn_mpi_send )
+         CASE ( 'S' )                ! Standard mpi send (blocking)
+            WRITE(ldtxt(7),*) '           Standard blocking mpi send (send)'
+            CALL mpi_init( ierr )
+         CASE ( 'B' )                ! Buffer mpi send (blocking)
+            WRITE(ldtxt(7),*) '           Buffer blocking mpi send (bsend)'
+            CALL mpi_init_opa( ierr )
+         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
+            WRITE(ldtxt(7),*) '           Immediate non-blocking send (isend)'
+            l_isend = .TRUE.
+            CALL mpi_init( ierr )
+         CASE DEFAULT
+            WRITE(ldtxt(7),cform_err)
+            WRITE(ldtxt(8),*) '           bad value for cn_mpi_send = ', cn_mpi_send
+            nstop = nstop + 1
+         END SELECT
+         !
       ENDIF
 
-      mpi_comm_opa = mpi_comm_world
-#endif
+      IF( PRESENT(localComm) ) THEN 
+         IF( Agrif_Root() ) THEN
+            mpi_comm_opa = localComm
+         ENDIF
+      ELSE
+         CALL mpi_comm_dup( mpi_comm_world, mpi_comm_opa, code)
+         IF( code /= MPI_SUCCESS ) THEN
+            WRITE(*, cform_err)
+            WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
+            CALL mpi_abort( mpi_comm_world, code, ierr )
+         ENDIF
+      ENDIF 
+
       CALL mpi_comm_rank( mpi_comm_opa, mpprank, ierr )
       CALL mpi_comm_size( mpi_comm_opa, mppsize, ierr )
@@ -926,5 +908,5 @@
          SELECT CASE ( jpni )
          CASE ( 1 )     ;   CALL lbc_nfd        ( pt2d(1:jpi,1:jpj+jpr2dj), cd_type, psgn, pr2dj=jpr2dj )
-         CASE DEFAULT   ;   CALL mpp_lbc_north_e( pt2d                    , cd_type, psgn               )
+        CASE DEFAULT   ;   CALL mpp_lbc_north_e( pt2d                    , cd_type, psgn               )
          END SELECT 
          !
@@ -2067,4 +2049,5 @@
       ijpj   = 4
       ijpjm1 = 3
+      ztab(:,:,:) = 0.e0
       !
       DO jj = nlcj - ijpj +1, nlcj          ! put in znorthloc the last 4 jlines of pt3d
@@ -2132,4 +2115,5 @@
       ijpj   = 4
       ijpjm1 = 3
+      ztab(:,:) = 0.e0
       !
       DO jj = nlcj-ijpj+1, nlcj             ! put in znorthloc the last 4 jlines of pt2d
@@ -2197,4 +2181,5 @@
       !
       ijpj=4
+      ztab(:,:) = 0.e0
 
       ij=0
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/mppallgatherv.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/mppallgatherv.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/mppallgatherv.F90	(revision 2578)
@@ -0,0 +1,184 @@
+#if defined key_mpp_mpi
+#if defined key_sp
+#define mpivar mpi_real
+#else
+#define mpivar mpi_double_precision
+#endif
+#endif
+MODULE mppallgatherv
+   !!======================================================================
+   !!                       ***  MODULE mppallgatherv  ***
+   !! NEMO: MPP allgatherv routines
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !! mpp_gatherv : Gather a real array on all processors
+   !!----------------------------------------------------------------------
+   !! * Modules used   
+   USE par_kind, ONLY : &   ! Precision variables
+      & wp
+   USE par_oce, ONLY : &    ! Ocean parameters
+      & jpnij
+#if defined key_mpp_mpi
+   USE lib_mpp, ONLY : &    ! MPP library
+      & mpi_comm_opa
+#endif
+   
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+
+   PUBLIC &
+      & mpp_allgatherv
+
+   INTERFACE mpp_allgatherv
+      MODULE PROCEDURE mpp_allgatherv_real, mpp_allgatherv_int
+   END INTERFACE
+CONTAINS
+
+   SUBROUTINE mpp_allgatherv_real( pvalsin, knoin, pvalsout, ksizeout, &
+      &                            knoout, kstartout )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE mpp_allgatherv_real ***
+      !!          
+      !! ** Purpose : Gather a real array on all processors
+      !!
+      !! ** Method  : MPI all gatherv
+      !!
+      !! ** Action  : This does only work for MPI. 
+      !!              It does not work for SHMEM.
+      !!
+      !! References : http://www.mpi-forum.org
+      !!
+      !! History :
+      !!        !  08-08  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & knoin,     &
+         & ksizeout
+      REAL(wp), DIMENSION(knoin), INTENT(IN) :: &
+         & pvalsin
+      REAL(wp), DIMENSION(ksizeout), INTENT(OUT) :: &
+         & pvalsout
+      INTEGER, DIMENSION(jpnij), INTENT(OUT) :: &
+         & kstartout, &
+         & knoout
+      
+      !! * Local declarations
+      INTEGER :: &
+         & ierr
+#if defined key_mpp_mpi
+#include <mpif.h>
+      INTEGER, DIMENSION(jpnij) :: &
+         & idispl
+      INTEGER :: &
+         & ji
+      !-----------------------------------------------------------------------
+      ! Call the MPI library to get number of data per processor
+      !-----------------------------------------------------------------------
+      CALL mpi_allgather( knoin,  1, mpi_integer, &
+         &                knoout, 1, mpi_integer, &
+         &                mpi_comm_opa, ierr )
+      !-----------------------------------------------------------------------
+      ! Compute starts of each processors contribution
+      !-----------------------------------------------------------------------
+      kstartout(1) = 0
+      DO ji = 2, jpnij
+         kstartout(ji) = kstartout(ji-1) + knoout(ji-1) 
+      ENDDO
+      !-----------------------------------------------------------------------
+      ! Call the MPI library to do the gathering of the data
+      !-----------------------------------------------------------------------
+      CALL mpi_allgatherv( pvalsin,  knoin,  mpivar,            &
+         &                 pvalsout, knoout, kstartout, mpivar, &
+         &                 mpi_comm_opa, ierr )
+#elif defined key_mpp_shmem
+error "Only MPI support for MPP in NEMOVAR"
+#else
+      !-----------------------------------------------------------------------
+      ! For no-MPP just return input values
+      !-----------------------------------------------------------------------
+      pvalsout(1:knoin) = pvalsin(1:knoin)
+      kstartout(1) = 0
+      knoout(1) = knoin
+      
+#endif
+      
+   END SUBROUTINE mpp_allgatherv_real
+
+   SUBROUTINE mpp_allgatherv_int( kvalsin, knoin, kvalsout, ksizeout, &
+      &                               knoout, kstartout )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE mpp_allgatherv ***
+      !!          
+      !! ** Purpose : Gather an integer array on all processors
+      !!
+      !! ** Method  : MPI all gatherv
+      !!
+      !! ** Action  : This does only work for MPI. 
+      !!              It does not work for SHMEM.
+      !!
+      !! References : http://www.mpi-forum.org
+      !!
+      !! History :
+      !!        !  06-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & knoin,     &
+         & ksizeout
+      INTEGER, DIMENSION(knoin), INTENT(IN) :: &
+         & kvalsin
+      INTEGER, DIMENSION(ksizeout), INTENT(OUT) :: &
+         & kvalsout
+      INTEGER, DIMENSION(jpnij), INTENT(OUT) :: &
+         & kstartout, &
+         & knoout
+      
+      !! * Local declarations
+      INTEGER :: &
+         & ierr
+#if defined key_mpp_mpi
+#include <mpif.h>
+      INTEGER, DIMENSION(jpnij) :: &
+         & idispl
+      INTEGER :: &
+         & ji
+      !-----------------------------------------------------------------------
+      ! Call the MPI library to get number of data per processor
+      !-----------------------------------------------------------------------
+      CALL mpi_allgather( knoin,  1, mpi_integer, &
+         &                knoout, 1, mpi_integer, &
+         &                mpi_comm_opa, ierr )
+      !-----------------------------------------------------------------------
+      ! Compute starts of each processors contribution
+      !-----------------------------------------------------------------------
+      kstartout(1) = 0
+      DO ji = 2, jpnij
+         kstartout(ji) = kstartout(ji-1) + knoout(ji-1)
+      ENDDO
+      !-----------------------------------------------------------------------
+      ! Call the MPI library to do the gathering of the data
+      !-----------------------------------------------------------------------
+      CALL mpi_allgatherv( kvalsin,  knoin,  mpi_integer,            &
+         &                 kvalsout, knoout, kstartout, mpi_integer, &
+         &                 mpi_comm_opa, ierr )
+#elif defined key_mpp_shmem
+error "Only MPI support for MPP in NEMOVAR"
+#else
+      !-----------------------------------------------------------------------
+      ! For no-MPP just return input values
+      !-----------------------------------------------------------------------
+      kvalsout(1:knoin) = kvalsin(1:knoin)
+      kstartout(1) = 0
+      knoout(1) = knoin
+      
+#endif
+      
+   END SUBROUTINE mpp_allgatherv_int
+
+END MODULE mppallgatherv
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/mppsum.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/mppsum.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/mppsum.F90	(revision 2578)
@@ -0,0 +1,401 @@
+MODULE mppsum
+   !!======================================================================
+   !!                       ***  MODULE mpp_sum  ***
+   !! NEMO: Summation of arrays across processors
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   mppsum : Order independent MPP reproducible sum
+   !!----------------------------------------------------------------------
+   !! * Modules used   
+   USE par_kind, ONLY : &   ! Precision variables
+      & wp
+   USE dom_oce, ONLY : &    ! Ocean space and time domain variables
+      & nproc
+   USE par_oce, ONLY : &    ! Ocean parameters
+      & jpnij
+   USE lib_mpp
+   USE mppallgatherv
+   USE in_out_manager
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+
+   PUBLIC &
+      & mpp_sum_indep, & ! Order independent MPP reproducible sum
+      & comp_sum,      & ! Perform compensated (i.e. accurate) summation.
+      & fround           ! Rounding of floating-point number
+
+CONTAINS
+
+   FUNCTION mpp_sum_indep( pval, kn )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE mpp_sum_indep ***
+      !!          
+      !! ** Purpose : Sum all elements in the pval array in
+      !!              an accurate order-independent way.
+      !!
+      !! ** Method  : The code iterates the compensated summation until the 
+      !!              result is guaranteed to be within 4*eps of the true sum.
+      !!              It then rounds the result to the nearest floating-point 
+      !!              number whose last three bits are zero, thereby 
+      !!              guaranteeing an order-independent result.
+      !!
+      !! ** Action  : This does only work for MPI. 
+      !!              It does not work for SHMEM.
+      !!
+      !! References : M. Fisher (ECMWF): IFS code + personal communication
+      !!              The algorithm is based on Ogita et al. (2005) 
+      !!              SIAM J. Sci. Computing, Vol.26, No.6, pp1955-1988. 
+      !!              This is based in turn on an algorithm
+      !!              by Knuth (1969, seminumerical algorithms).
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code heavily based on IFS.
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) mpp_sum_indep
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kn
+      REAL(wp), DIMENSION(kn), INTENT(IN) :: &
+         & pval
+      !! * Local declarations
+      REAL(wp), DIMENSION(3) ::&
+         & zbuffl
+      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
+         & zpsums, &
+         & zperrs, &
+         & zpcors, &
+         & zbuffg, &
+         & zp
+      REAL(wp) :: &
+         & zcorr,   &
+         & zerr,    &
+         & zolderr, &
+         & zbeta,   &
+         & zres
+      INTEGER, DIMENSION(:), allocatable :: &
+         & irecv, &
+         & istart
+      INTEGER :: &
+         & ing
+      INTEGER :: &
+         & jj
+
+
+      ! Get global number of elements
+      ing = kn
+#ifdef key_mpp
+      CALL mpp_sum( ing )
+#endif
+      ! Check that the the algorithm can work 
+      
+      IF ( ( REAL( 2 * ing ) * EPSILON( zres ) ) >= 1.0 ) THEN
+
+         CALL ctl_stop('mpp_sum_indep:', &
+            &          'kn is too large to guarantee error bounds')
+
+      ENDIF
+      
+      ALLOCATE( &
+         & zp(MAX(kn,1)),                & 
+         & zbuffg(jpnij*SIZE(zbuffl)), &
+         & zpsums(jpnij),              &
+         & zperrs(jpnij),              &
+         & zpcors(jpnij)               &
+         & )
+
+      zolderr = HUGE(zerr)
+
+      ! Copy the input array. This avoids some tricky indexing, at the
+      ! expense of some inefficency.
+
+      IF ( kn > 0 ) THEN
+
+         zp(:) = pval(:)
+
+      ELSE
+
+         zp(1) = 0.0_wp
+
+      ENDIF
+      
+      k_loop: DO
+
+         ! Transform local arrays
+         
+         IF ( kn > 0 ) THEN
+
+            CALL comp_sum ( zp, kn, zcorr, zerr )
+
+         ENDIF
+
+         ! Gather partial sums and error bounds to all processors
+
+         zbuffl(1) = zp(MAX(kn,1))
+         
+         IF ( kn > 0 ) THEN
+
+            zbuffl(2) = zerr
+            zbuffl(3) = zcorr
+
+         ELSE
+            
+            zbuffl(2) = 0.0_wp
+            zbuffl(3) = 0.0_wp
+
+         ENDIF
+         
+         IF ( jpnij > 1 ) THEN
+
+            ALLOCATE( &
+               & irecv(jpnij), &
+               & istart(jpnij) &
+               & )
+
+            CALL mpp_allgatherv( zbuffl, SIZE(zbuffl), &
+               & zbuffg, jpnij * SIZE(zbuffl), irecv, istart )
+
+            DEALLOCATE( &
+               & irecv, &
+               & istart &
+               & )
+            
+            DO jj = 1, jpnij
+
+               zpsums(jj) = zbuffg(1+(jj-1)*SIZE(zbuffl))
+               zperrs(jj) = zbuffg(2+(jj-1)*SIZE(zbuffl))
+               zpcors(jj) = zbuffg(3+(jj-1)*SIZE(zbuffl))
+
+            END DO
+
+         ELSE
+
+            zpsums(1) = zbuffl(1)
+            zperrs(1) = zbuffl(2)
+            zpcors(1) = zbuffl(3)
+
+         ENDIF
+
+         ! Transform partial sums
+
+         CALL comp_sum( zpsums, jpnij, zcorr, zerr )
+         zerr  = zerr  + SUM(zperrs)
+         zcorr = zcorr + SUM(zpcors)
+         
+         ! Calculate final result
+         
+         zres = zpsums(jpnij) + zcorr
+
+         ! Calculate error bound. This is corollary 4.7 from Ogita et al. 
+         ! (2005)
+         
+         zbeta = zerr *( REAL( 2*ing, wp ) * EPSILON(zres) ) &
+            &  /(1.0_wp - REAL( 2*ing, wp ) * EPSILON(zres) )
+
+         zerr = EPSILON(zres) * ABS(zres) &
+            & +(zbeta + ( 2.0_wp * EPSILON(zres) * EPSILON(zres) * ABS(zres) &
+            &            +3.0_wp * TINY(zres) ) )
+
+         ! Update the last element of the local array
+
+         zp(MAX(kn,1)) = zpsums(nproc+1)
+
+         ! Exit if the global error is small enough
+
+         IF ( zerr < 4.0_wp * SPACING(zres) ) EXIT k_loop
+         
+         ! Take appropriate action if ZRES cannot be sufficiently refined.
+         
+         IF (zerr >= zolderr) THEN
+
+            CALL ctl_stop('Failed to refine sum', &
+               &          'Warning: Possiblity of non-reproducible results')
+
+         ENDIF
+
+         zolderr = zerr
+         
+      ENDDO k_loop
+
+      ! At this stage, we have guaranteed that ZRES less than 4*EPS
+      ! away from the exact sum. There are only four floating point
+      ! numbers in this range. So, if we find the nearest number that
+      ! has its last three bits zero, then we have a reproducible result.
+
+      mpp_sum_indep = fround(zres)
+
+      DEALLOCATE( &
+         & zpcors, &
+         & zperrs, &
+         & zpsums, &
+         & zbuffg, &
+         & zp      &
+         & )
+
+   END FUNCTION mpp_sum_indep
+
+   SUBROUTINE comp_sum( pval, kn, pcorr, perr )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE comp_sum ***
+      !!          
+      !! ** Purpose : To perform compensated (i.e. accurate) summation.
+      !!
+      !! ** Method  : These routines transform the elements of the array P, 
+      !!              such that:
+      !!              1)  pval(kn)         contains sum(pval)
+      !!              2)  pval(1)...pval(kn-1) contain the rounding errors 
+      !!                  that were made in calculating sum(pval).
+      !!              3)  The exact sum of the elements of pval is unmodified.
+      !!              On return, pcorr contains the sum of the rounding errors,
+      !!              perr contains the sum of their absolute values.
+      !!              After calling this routine, an accurate sum of the 
+      !!              elements of pval can be calculated as res=pval(n)+pcorr.
+      !!
+      !! ** Action  : 
+      !!
+      !! References : M. Fisher (ECMWF) IFS code + personal communications
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code heavily based on IFS 
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kn         ! Number of elements in input array
+      REAL(wp), DIMENSION(kn), INTENT(INOUT) :: &
+         & pval       ! Input array to be sum on input
+                      ! pval(kn) = sum (pval) on output
+                      ! pval(1)...pval(kn-1) = rounding errors on output
+      REAL(wp) :: &
+         & pcorr, &   ! Sum of rounding errors
+         & perr       ! Sum of absolute rounding errors
+      !! * Local declarations
+      REAL(wp) :: &
+         & zx, &
+         & zz, &
+         & zpsum
+      integer :: &
+         & jj
+
+      pcorr = 0.0_wp
+      perr  = 0.0_wp
+      
+      zpsum = pval(1)
+      
+      DO jj = 2, kn
+
+         ! It is vital that these 4 lines are not optimized in any way that
+         ! changes the results.
+
+         zx         = pval(jj) + zpsum
+         zz         = zx - pval(jj)
+         pval(jj-1) = ( pval(jj) - ( zx - zz ) ) + ( zpsum - zz ) 
+         zpsum      = zx
+
+         ! Accumulate the correction and the error
+         
+         pcorr      = pcorr + pval(jj-1)
+         perr       = perr + ABS( pval(jj-1) )
+
+      END DO
+
+      pval(kn) = zpsum
+      
+   END SUBROUTINE comp_sum
+
+   FUNCTION fround(pres)
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE fround ***
+      !!          
+      !! ** Purpose : Rounding of floating-point number
+      !!
+      !! ** Method  : Returns the value of PRES rounded to the nearest 
+      !!              floating-point number that has its last three bits zero
+      !!              This works on big-endian and little-endian machines.
+      !!
+      !! ** Action  : 
+      !!
+      !! References : M. Fisher (ECMWF) IFS code + personal communication
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code heavily based on IFS.
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) fround
+      !! * Arguments
+      REAL(wp), INTENT(IN) :: &
+         & pres      ! Value to be rounded
+      !! * Local declarations
+      REAL(wp) :: &
+         & zz(2), &
+         & zup,   &
+         & zdown
+      INTEGER :: &
+         & ii(2),         & 
+         & iequiv(8),     &
+         & ints_per_real, &
+         & i_low_word
+      INTEGER :: &
+         & jj
+
+      ii(:) = 1
+      zz(:) = 1.0_wp
+
+      ! Warning: If wp = 64 bits (or 32 bits for key_sp) this will not work.
+
+#if defined key_sp
+      ints_per_real = 32 / BIT_SIZE(ii)
+#else
+      ints_per_real = 64 / BIT_SIZE(ii)
+#endif
+
+      ! Test whether big-endian or little-endian
+      
+      zup = -1.0_wp
+      iequiv(1:ints_per_real) = TRANSFER(zup,iequiv(1:ints_per_real))
+      
+      IF ( iequiv(1) == 0 ) THEN
+         i_low_word = 1                ! Little-endian
+      ELSE
+         i_low_word = ints_per_real    ! Big-endian
+      ENDIF
+
+      ! Find the nearest number with all 3 lowest-order bits zeroed
+      
+      iequiv(1:ints_per_real) = transfer(pres,iequiv(1:ints_per_real))
+      zup    = pres
+      zdown  = pres
+
+      IF (IBITS(iequiv(i_low_word),0,3)/=0) THEN
+
+         DO jj = 1, 4
+
+            zup = NEAREST( zup, 1.0_wp )
+            iequiv(1:ints_per_real) = TRANSFER( zup, iequiv(1:ints_per_real) )
+
+            IF ( IBITS( iequiv(i_low_word), 0, 3 ) == 0 ) EXIT
+
+            zdown = NEAREST( zdown, -1.0 )
+
+            iequiv(1:ints_per_real) = TRANSFER( zdown, iequiv(1:ints_per_real))
+
+            IF ( IBITS( iequiv(i_low_word),0,3) == 0 ) EXIT
+
+         END DO
+
+         IF ( IBITS( iequiv( i_low_word ), 0, 3) /= 0 ) THEN
+
+            CALL ctl_stop('Fround:','This is not possible')
+
+         ENDIF
+         
+      ENDIF
+      
+      fround = TRANSFER( iequiv(1:ints_per_real), pres )
+      
+   END FUNCTION fround
+
+END MODULE mppsum
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/opa.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/opa.F90	(revision 2577)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/opa.F90	(revision 2578)
@@ -54,4 +54,6 @@
    USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
    USE diaptr          ! poleward transports           (dia_ptr_init routine)
+   USE tamtrj          ! writing out state trajectory
+
    USE step            ! OPA time-stepping                  (stp     routine)
 #if defined key_oasis3
@@ -156,5 +158,7 @@
       CALL opa_closefile
 #if defined key_oasis3 || defined key_oasis4
-      CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
+      IF( Agrif_Root() ) THEN
+         CALL cpl_prism_finalize        ! end coupling and mpp communications with OASIS
+     ENDIF
 #else
       IF( lk_mpp )   CALL mppstop       ! end mpp communications
@@ -190,15 +194,16 @@
       !                             !--------------------------------------------!
 #if defined key_iomput
+      IF( Agrif_Root() ) THEN
 # if defined key_oasis3 || defined key_oasis4
-      CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
-      CALL init_ioclient()                    ! io_server will get its communicators (if needed) from oasis (we don't see it)
-# else
-      CALL init_ioclient( ilocal_comm )       ! nemo local communicator (used or not) given by the io_server
+         CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
 # endif
+         CALL  init_ioclient( ilocal_comm )      ! exchange io_server nemo local communicator with the io_server
+      ENDIF
       narea = mynode( cltxt, ilocal_comm )    ! Nodes selection
-
 #else
 # if defined key_oasis3 || defined key_oasis4
-      CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
+      IF( Agrif_Root() ) THEN
+         CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
+      ENDIF
       narea = mynode( cltxt, ilocal_comm )    ! Nodes selection (control print return in cltxt)
 # else
@@ -272,4 +277,6 @@
       CALL trd_mod_init                         ! Mixed-layer/Vorticity/Integral constraints trends
       !
+      CALL tam_trj_init
+      !
    END SUBROUTINE opa_init
 
@@ -287,5 +294,5 @@
       NAMELIST/namdyn_hpg/ ln_hpg_zco   , ln_hpg_zps   , ln_hpg_sco, ln_hpg_hel,   &
          &                 ln_hpg_wdj   , ln_hpg_djc   , ln_hpg_rot, rn_gamma  ,   &
-         &                 ln_dynhpg_imp, nn_dynhpg_rst
+         &                 ln_dynhpg_imp
       !!----------------------------------------------------------------------
 
Index: branches/TAM_V3_2_2/NEMO/OPA_SRC/step.F90
===================================================================
--- branches/TAM_V3_2_2/NEMO/OPA_SRC/step.F90	(revision 2577)
+++ branches/TAM_V3_2_2/NEMO/OPA_SRC/step.F90	(revision 2578)
@@ -19,4 +19,5 @@
    !!             -   !  2006-01  (L. Debreu, C. Mazauric)  Agrif implementation
    !!             -   !  2006-07  (S. Masson)  restart using iom
+   !!             -   !  2008-06  (A. Vidard) TAM interface
    !!            3.2  !  2009-02  (G. Madec, R. Benshila)  reintroduicing z*-coordinate
    !!             -   !  2009-06  (S. Masson, G. Madec)  TKE restart compatible with key_cpl
@@ -112,4 +113,5 @@
    USE flo_oce         ! floats variables
    USE floats          ! floats computation               (flo_stp routine)
+   USE tamtrj          ! writing out state trajectory    
 
    USE stpctl          ! time stepping control            (stp_ctl routine)
@@ -160,4 +162,5 @@
       !!              -8- Outputs and diagnostics
       !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zta_tmp, zsa_tmp
       INTEGER ::   jk       ! dummy loop indice
       INTEGER ::   indic    ! error indicator if < 0
@@ -168,4 +171,7 @@
 !      IF ( Agrif_Root() .and. lwp) Write(*,*) '---'
 !      IF (lwp) Write(*,*) 'Grid Number',Agrif_Fixed(),' time step ',kstp
+# if defined key_iomput
+      IF( Agrif_Nbstepint() == 0) CALL iom_swap
+# endif
 #endif   
       indic = 1                                       ! reset to no error condition
@@ -175,6 +181,4 @@
       CALL iom_setkt( kstp )                          ! say to iom that we are at time step kstp
       
-      CALL rst_opn( kstp )                            ! Open the restart file
-
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Update data, open boundaries, surface boundary condition (including sea-ice)
@@ -261,4 +265,8 @@
                              ta(:,:,:) = 0.e0               ! set tracer trends to zero
                              sa(:,:,:) = 0.e0
+
+      ! Saving non-linear trajectory at restart state
+      ! May not be exact for sbc and zdf parameters
+      IF( ( ln_trjwri ) .AND. ( kstp == nit000 ) ) CALL tam_trj_wri( kstp - 1 )
 
                              CALL tra_sbc    ( kstp )       ! surface boundary condition
@@ -292,5 +300,15 @@
          IF( ln_zdfnpc   )   CALL tra_npc    ( kstp )       ! update after fields by non-penetrative convection
                              CALL tra_nxt    ( kstp )       ! tracer fields at next time step
-      ENDIF 
+     ENDIF 
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! saving ta and sa (temporary fix, please do not remove)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF (ln_trjwri) THEN
+                               ALLOCATE ( zta_tmp(jpi,jpj,jpk), &
+            &                             zsa_tmp(jpi,jpj,jpk)  )
+                               zta_tmp(:,:,:) = ta(:,:,:)
+                               zsa_tmp(:,:,:) = sa(:,:,:)
+      END IF
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -335,5 +353,18 @@
          IF( lk_trdmld     )   CALL trd_mld( kstp )         ! trends: Mixed-layer 
          IF( lk_trdvor     )   CALL trd_vor( kstp )         ! trends: vorticity budget
-      ENDIF
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! restoring ta and sa (temporary fix, please do not remove)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+         IF (ln_trjwri) THEN
+            ta(:,:,:) = zta_tmp(:,:,:)
+            sa(:,:,:) = zsa_tmp(:,:,:)
+            DEALLOCATE ( zta_tmp, &
+               &         zsa_tmp  )
+         END IF
+
+  
+      ENDIF
+      
+      IF( ln_trjwri ) CALL tam_trj_wri( kstp )          ! Output trajectory fields
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DOM/closea_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DOM/closea_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DOM/closea_tam.F90	(revision 2578)
@@ -0,0 +1,507 @@
+MODULE closea_tam
+#if defined key_tam
+   !!======================================================================
+   !!                       ***  MODULE  closea_tam  ***
+   !! Closed Seas  : specific treatments associated with closed seas
+   !!                Tangent and adjoint module
+   !!======================================================================
+   !! History of the direct module:
+   !!             8.2  !  00-05  (O. Marti)  Original code
+   !!             8.5  !  02-06  (E. Durand, G. Madec)  F90
+   !!             9.0  !  06-07  (G. Madec)  add clo_rnf, clo_ups, clo_bat
+   !! History of the tangent module:
+   !!             9.0  !  08-11  (A. Vidard)   skeleton tam of sbc_clo
+   !!             9.0  !  09-08  (F. Vigilant) tangent and adjoint version
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   sbc_clo    : Special handling of closed seas
+   !!----------------------------------------------------------------------
+ 
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jp_cfg,              &
+      & cp_cfg,              &
+      & jpi,                 &
+      & jpj,                 &
+      & jpiglo
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE sbc_oce_tam   , ONLY: & ! surface thermohaline fluxes
+      & emp_tl, emps_tl,     &
+      & emp_ad, emps_ad
+   USE lbclnk_tam    , ONLY: & ! TAM lateral boundary conditions
+      & lbc_lnk_adj
+   USE lbclnk        , ONLY: & ! Lateral boundary conditions
+      & lbc_lnk
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & e1t,                 &
+      & e2t,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3t,                 &
+#endif
+      & tmask_i, tmask,      &
+      & mig, mjg,            &
+      & mi0, mj0,            &
+      & nldi, nlei,          &
+      & nldj, nlej
+   USE sbc_oce
+   USE closea        , ONLY: &
+      & jpncs,               &
+      & ncstt,               &
+      & ncsi1,               &
+      & ncsj1,               &
+      & ncsi2,               &
+      & ncsj2,               &
+      & ncsnr,               &
+      & ncsir,               &
+      & ncsjr
+   USE lib_mpp                 ! distribued memory computing library
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              & 
+      & nit000,              & 
+      & nitend
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE paresp        , ONLY: & ! Weights for an energy-type scalar product
+      & wesp_t,              &
+      & wesp_s
+   USE tstool_tam    , ONLY: &
+      & stdemp,              &
+      & prntst_adj
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC sbc_clo_tan      ! routine called by sbcmod_tam module
+   PUBLIC sbc_clo_adj      ! routine called by sbcmod_tam module
+   PUBLIC sbc_clo_adj_tst  ! routine called by tst module
+
+   REAL(wp), DIMENSION (jpncs+1)       ::   surf             ! closed sea surface
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Id: closea.F90 1146 2008-06-25 11:42:56Z rblod $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+
+   SUBROUTINE sbc_clo_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_clo_tan  ***
+      !!                    
+      !! ** Purpose :   Special handling of closed seas (Tangent version)
+      !!
+      !! ** Method  :   Water flux is forced to zero over closed sea
+      !!      Excess is shared between remaining ocean, or
+      !!      put as run-off in open ocean. 
+      !!
+      !! ** Action  :   emp, emps   updated surface freshwater fluxes at kt
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean model time step
+      !
+      INTEGER                     ::   ji, jj, jc, jn   ! dummy loop indices
+      REAL(wp)                    ::   zze2
+      REAL(wp), DIMENSION (jpncs) ::   zemptl
+      !!----------------------------------------------------------------------
+      !
+      !                                                   !------------------!
+      IF( kt == nit000 ) THEN                             !  Initialisation  !
+         !                                                !------------------!
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*)'sbc_clo_tan : closed seas '
+         IF(lwp) WRITE(numout,*)'~~~~~~~'
+
+         ! Total surface of ocean
+         surf(jpncs+1) = SUM( e1t(:,:) * e2t(:,:) * tmask_i(:,:) )
+
+         DO jc = 1, jpncs
+            surf(jc) =0.0_wp
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  surf(jc) = surf(jc) + e1t(ji,jj) * e2t(ji,jj) * tmask_i(ji,jj)      ! surface of closed seas
+               END DO 
+            END DO 
+         END DO 
+         IF( lk_mpp )   CALL mpp_sum ( surf, jpncs+1 )       ! mpp: sum over all the global domain
+
+         IF(lwp) WRITE(numout,*)'     Closed sea surfaces'
+         DO jc = 1, jpncs
+            IF(lwp)WRITE(numout,FMT='(1I3,4I4,5X,F16.2)') jc, ncsi1(jc), ncsi2(jc), ncsj1(jc), ncsj2(jc), surf(jc)
+         END DO
+
+         ! jpncs+1 : surface of sea, closed seas excluded
+         DO jc = 1, jpncs
+            surf(jpncs+1) = surf(jpncs+1) - surf(jc)
+         END DO           
+         !
+      ENDIF
+      !                                                   !--------------------!
+      !                                                   !  update emp, emps  !
+      zemptl = 0.0_wp                                     !--------------------!
+      DO jc = 1, jpncs
+         DO jj = ncsj1(jc), ncsj2(jc)
+            DO ji = ncsi1(jc), ncsi2(jc)
+               zemptl(jc) = zemptl(jc) + e1t(ji,jj) * e2t(ji,jj) * emp_tl(ji,jj) * tmask_i(ji,jj)
+            END DO  
+         END DO 
+      END DO
+      IF( lk_mpp )   CALL mpp_sum ( zemptl(:) , jpncs )       ! mpp: sum over all the global domain
+
+      IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN      ! Black Sea case for ORCA_R2 configuration
+         zze2    = ( zemptl(3) + zemptl(4) ) / 2.
+         zemptl(3) = zze2
+         zemptl(4) = zze2
+      ENDIF
+      DO jc = 1, jpncs
+         !
+         IF( ncstt(jc) == 0 ) THEN 
+            ! water/evap excess is shared by all open ocean
+            emp_tl (:,:) = emp_tl (:,:) + zemptl(jc) / surf(jpncs+1)
+            emps_tl(:,:) = emps_tl(:,:) + zemptl(jc) / surf(jpncs+1)
+         ELSEIF( ncstt(jc) == 1 ) THEN 
+            ! Excess water in open sea, at outflow location, excess evap shared
+            IF ( zemptl(jc) <= 0.e0 ) THEN 
+                DO jn = 1, ncsnr(jc)
+                  ji = mi0(ncsir(jc,jn))
+                  jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
+                  IF (      ji > 1 .AND. ji < jpi   &
+                      .AND. jj > 1 .AND. jj < jpj ) THEN 
+                      emp_tl (ji,jj) = emp_tl (ji,jj) + zemptl(jc) /   &
+                         (FLOAT(ncsnr(jc)) * e1t(ji,jj) * e2t(ji,jj))
+                      emps_tl(ji,jj) = emps_tl(ji,jj) + zemptl(jc) /   &
+                          (FLOAT(ncsnr(jc)) * e1t(ji,jj) * e2t(ji,jj))
+                  END IF 
+                END DO 
+            ELSE 
+                emp_tl (:,:) = emp_tl (:,:) + zemptl(jc) / surf(jpncs+1)
+                emps_tl(:,:) = emps_tl(:,:) + zemptl(jc) / surf(jpncs+1)
+            ENDIF
+         ELSEIF( ncstt(jc) == 2 ) THEN 
+            ! Excess e-p+r (either sign) goes to open ocean, at outflow location
+            IF(      ji > 1 .AND. ji < jpi    &
+               .AND. jj > 1 .AND. jj < jpj ) THEN 
+                DO jn = 1, ncsnr(jc)
+                  ji = mi0(ncsir(jc,jn))
+                  jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
+                  emp_tl (ji,jj) = emp_tl (ji,jj) + zemptl(jc)   &
+                      / (FLOAT(ncsnr(jc)) *  e1t(ji,jj) * e2t(ji,jj) )
+                  emps_tl(ji,jj) = emps_tl(ji,jj) + zemptl(jc)   &
+                      / (FLOAT(ncsnr(jc)) *  e1t(ji,jj) * e2t(ji,jj) )
+                END DO 
+            ENDIF 
+         ENDIF 
+         !
+         DO jj = ncsj1(jc), ncsj2(jc)
+            DO ji = ncsi1(jc), ncsi2(jc)
+               emp_tl (ji,jj) = emp_tl (ji,jj) - zemptl(jc) / surf(jc)
+               emps_tl(ji,jj) = emps_tl(ji,jj) - zemptl(jc) / surf(jc)
+            END DO  
+         END DO 
+         !
+      END DO 
+      !
+      CALL lbc_lnk( emp_tl , 'T', 1. )
+      CALL lbc_lnk( emps_tl, 'T', 1. )
+      !
+   END SUBROUTINE sbc_clo_tan
+   SUBROUTINE sbc_clo_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_clo_adj  ***
+      !!                    
+      !! ** Purpose :   Special handling of closed seas (Adjoint version)
+      !!
+      !! ** Method  :   Water flux is forced to zero over closed sea
+      !!      Excess is shared between remaining ocean, or
+      !!      put as run-off in open ocean. 
+      !!
+      !! ** Action  :   emp, emps   updated surface freshwater fluxes at kt
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean model time step
+      !
+      !
+      INTEGER                     ::   ji, jj, jc, jn   ! dummy loop indices
+      REAL(wp)                    ::   zze2
+      REAL(wp), DIMENSION (jpncs) ::   zempad
+      !!----------------------------------------------------------------------
+      !
+      !                                                   !------------------!
+      IF( kt == nitend ) THEN                             !  Initialisation  !
+         !                                                !------------------!
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*)'sbc_clo_adj : closed seas '
+         IF(lwp) WRITE(numout,*)'~~~~~~~'
+
+         ! Total surface of ocean
+         surf(jpncs+1) = SUM( e1t(:,:) * e2t(:,:) * tmask_i(:,:) )
+
+         DO jc = 1, jpncs
+            surf(jc) =0.0_wp
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  surf(jc) = surf(jc) + e1t(ji,jj) * e2t(ji,jj) * tmask_i(ji,jj)      ! surface of closed seas
+               END DO 
+            END DO 
+         END DO 
+         IF( lk_mpp )   CALL mpp_sum ( surf, jpncs+1 )       ! mpp: sum over all the global domain
+
+         IF(lwp) WRITE(numout,*)'     Closed sea surfaces'
+         DO jc = 1, jpncs
+            IF(lwp)WRITE(numout,FMT='(1I3,4I4,5X,F16.2)') jc, ncsi1(jc), ncsi2(jc), ncsj1(jc), ncsj2(jc), surf(jc)
+         END DO
+
+         ! jpncs+1 : surface of sea, closed seas excluded
+         DO jc = 1, jpncs
+            surf(jpncs+1) = surf(jpncs+1) - surf(jc)
+         END DO           
+         !
+      ENDIF
+
+      zempad = 0.0_wp
+      CALL lbc_lnk_adj( emp_ad , 'T', 1. )
+      CALL lbc_lnk_adj( emps_ad, 'T', 1. )
+      DO jc = jpncs, 1, -1
+         !
+         DO jj = ncsj1(jc), ncsj2(jc)
+            DO ji = ncsi1(jc), ncsi2(jc)
+               zempad(jc) = zempad(jc) - emps_ad(ji,jj) / surf(jc)
+               zempad(jc) = zempad(jc) - emp_ad(ji,jj)  / surf(jc)
+            END DO  
+         END DO 
+         !
+         IF( ncstt(jc) == 0 ) THEN 
+            ! water/evap excess is shared by all open ocean
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zempad(jc) = zempad(jc) + emps_ad(ji,jj) / surf(jpncs+1)
+                  zempad(jc) = zempad(jc) + emp_ad(ji,jj)  / surf(jpncs+1)
+               END DO
+            END DO
+         ELSEIF( ncstt(jc) == 1 ) THEN 
+            ! Excess water in open sea, at outflow location, excess evap shared
+            IF ( zempad(jc) <= 0.e0 ) THEN 
+                DO jn = 1, ncsnr(jc)
+                  ji = mi0(ncsir(jc,jn))
+                  jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
+                  IF (      ji > 1 .AND. ji < jpi   &
+                      .AND. jj > 1 .AND. jj < jpj ) THEN 
+                      zempad(jc) = zempad(jc) + emps_ad(ji,jj) /   &
+                          (FLOAT(ncsnr(jc)) * e1t(ji,jj) * e2t(ji,jj))
+                      zempad(jc) = zempad(jc) + emp_ad(ji,jj)  /   &
+                          (FLOAT(ncsnr(jc)) * e1t(ji,jj) * e2t(ji,jj))
+                  END IF 
+                END DO 
+            ELSE 
+                DO jj = 1, jpj
+                   DO ji = 1, jpi
+                      zempad(jc) = zempad(jc) + emps_ad(ji,jj) / surf(jpncs+1)
+                      zempad(jc) = zempad(jc) + emp_ad(ji,jj)  / surf(jpncs+1)
+                   END DO
+                END DO
+            ENDIF
+         ELSEIF( ncstt(jc) == 2 ) THEN 
+            ! Excess e-p+r (either sign) goes to open ocean, at outflow location
+            IF(      ji > 1 .AND. ji < jpi    &
+               .AND. jj > 1 .AND. jj < jpj ) THEN 
+                DO jn = 1, ncsnr(jc)
+                  ji = mi0(ncsir(jc,jn))
+                  jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
+                  zempad(jc) = zempad(jc) + emps_ad(ji,jj)  &
+                      / (FLOAT(ncsnr(jc)) *  e1t(ji,jj) * e2t(ji,jj) )
+                  zempad(jc) = zempad(jc) + emp_ad(ji,jj)   &
+                      / (FLOAT(ncsnr(jc)) *  e1t(ji,jj) * e2t(ji,jj) )
+                END DO 
+            ENDIF 
+         ENDIF  
+         !
+      END DO
+      !                                                   !--------------------!
+      !                                                   !  update emp, emps  !
+                                                          !--------------------!
+      IF( lk_mpp )   CALL mpp_sum ( zempad(:) , jpncs )       ! mpp: sum over all the global domain
+      DO jc = 1, jpncs
+         DO jj = ncsj1(jc), ncsj2(jc)
+            DO ji = ncsi1(jc), ncsi2(jc)
+               emp_ad(ji,jj) = emp_ad(ji,jj) + e1t(ji,jj) * e2t(ji,jj) * zempad(jc) * tmask_i(ji,jj)
+            END DO  
+         END DO 
+      END DO
+      zempad = 0.0_wp
+   END SUBROUTINE sbc_clo_adj
+   SUBROUTINE sbc_clo_adj_tst ( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE sbc_clo_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!                   
+      !! History :
+      !!        ! 09-08 (F. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & istp,  &
+         & jstp,  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk  
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2            ! scalar product involving the adjoint routine
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zemp_tlin ,     & ! Tangent input
+         & zemps_tlin ,    & ! Tangent input
+         & zemp_tlout,     & ! Tangent output
+         & zemps_tlout,    & ! Tangent output
+         & zemp_adin ,     & ! Adjoint input
+         & zemps_adin ,    & ! Adjoint input
+         & zemp_adout,     & ! Adjoint output
+         & zemps_adout,    & ! Adjoint output
+         & zr                ! 2D random field 
+      CHARACTER(LEN=14) :: cl_name
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zemp_tlin(  jpi,jpj),     &
+         & zemps_tlin( jpi,jpj),     &
+         & zemp_tlout( jpi,jpj),     &
+         & zemps_tlout(jpi,jpj),     &
+         & zemp_adin(  jpi,jpj),     &
+         & zemps_adin( jpi,jpj),     &
+         & zemp_adout( jpi,jpj),     &
+         & zemps_adout(jpi,jpj),     &
+         & zr(         jpi,jpj)      &
+         & )
+      !==================================================================
+      ! 1) dx = ( emp_tl, emps_tl, ssh_tl ) and 
+      !    dy = ( emp_tl, emps_tl )
+      !==================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+          zemp_tlin  (:,:) = 0.0_wp
+          zemps_tlin (:,:) = 0.0_wp
+          zemp_tlout (:,:) = 0.0_wp
+          zemps_tlout(:,:) = 0.0_wp
+          zemp_adin  (:,:) = 0.0_wp
+          zemps_adin (:,:) = 0.0_wp
+          zemp_adout (:,:) = 0.0_wp
+          zemps_adout(:,:) = 0.0_wp
+          zr(:,:)          = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdemp )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zemp_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 446251 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdemp )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zemps_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+
+      emps_tl(:,:) = zemps_tlin(:,:)
+      emp_tl (:,:) = zemp_tlin (:,:)
+
+      CALL sbc_clo_tan( nit000 )
+
+      zemps_tlout(:,:) = emps_tl(:,:)
+      zemp_tlout (:,:) = emp_tl (:,:)
+      !-----------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !-----------------------------------------------------------------
+
+      DO jj = 1, jpi
+         DO ji = 1, jpj
+            zemp_adin( ji,jj) = zemp_tlout( ji,jj) &
+               &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+               &               * tmask(ji,jj,1)
+            zemps_adin(ji,jj) = zemps_tlout(ji,jj) &
+               &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+               &               * tmask(ji,jj,1)
+         END DO
+      END DO
+      !-----------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !-----------------------------------------------------------------
+      zsp1 = DOT_PRODUCT( zemp_tlout,  zemp_adin  ) &
+         & + DOT_PRODUCT( zemps_tlout, zemps_adin )
+
+      !-----------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !-----------------------------------------------------------------
+
+      emp_ad (:,:) = zemp_adin (:,:)
+      emps_ad(:,:) = zemps_adin(:,:)
+
+      CALL sbc_clo_adj ( nitend )
+
+      zemps_adout(:,:) = emps_ad(:,:)
+      zemp_adout (:,:) = emp_ad (:,:)
+
+      zsp2 = DOT_PRODUCT( zemp_tlin,  zemp_adout  ) &
+         & + DOT_PRODUCT( zemps_tlin, zemps_adout ) 
+
+      ! 14 char:'12345678901234'
+      cl_name = 'sbc_clo_adj   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      DEALLOCATE(       &
+         & zemp_tlin,   &
+         & zemps_tlin,  &
+         & zemp_tlout,  &
+         & zemps_tlout, &
+         & zemp_adin,   &
+         & zemps_adin,  &
+         & zemp_adout,  &
+         & zemps_adout, &
+         & zr           &
+         & )
+   END SUBROUTINE sbc_clo_adj_tst
+   !!======================================================================
+#endif
+END MODULE closea_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DOM/daymod_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DOM/daymod_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DOM/daymod_tam.F90	(revision 2578)
@@ -0,0 +1,170 @@
+MODULE daymod_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  daymod_tam  ***
+   !! Ocean        :  calendar, tangent and adjoint model version 
+   !!=====================================================================
+   !! History :  OPA  ! 1994-09  (M. Pontaud M. Imbard)  Original code
+   !!                 ! 1997-03  (O. Marti)
+   !!                 ! 1997-05  (G. Madec) 
+   !!                 ! 1997-08  (M. Imbard)
+   !!   NEMO     1.0  ! 2003-09  (G. Madec)  F90 + nyear, nmonth, nday
+   !!                 ! 2004-01  (A.M. Treguier) new calculation based on adatrj
+   !!                 ! 2006-08  (G. Madec)  surface module major update
+   !! History :
+   !!            OPA  ! 1998-2004 (A. Weaver, N. Daget) daytam
+   !!            NEMO ! 2005-08  (A. Vidard) skeleton 
+   !!                 ! 2008-08  (A. Vidard) 04-01 version, based on daytam
+   !!                 ! 2009-02  (A. Vidard) 06-08 version
+   !!            3.2  ! 2010-03  (F. Vigilant) 
+   !!----------------------------------------------------------------------     
+   !!----------------------------------------------------------------------
+   !!   day_tam        : calendar
+   !!  
+   !!           -------------------------------
+   !!           ----------- WARNING -----------
+   !!
+   !!   we assume that the time step is a divisor of the number of second of in a day
+   !!             ---> MOD( rday, rdttra(1) ) == 0
+   !!
+   !!           ----------- WARNING -----------
+   !!           -------------------------------
+   !!  
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind,       ONLY: & ! Precision variables
+      & wp
+   USE phycst,         ONLY: &
+      & rday
+   USE dom_oce,        ONLY: & ! ocean space and time domain
+      & rdttra,              &
+      & nyear_len ,          &
+      & nmonth_len,          &
+      & nyear     ,          &  !: current year
+
+      & nmonth    ,          &  !: current month
+      & nday      ,          &  !: current day of the month
+      & nday_year ,          &  !: curent day counted from jan 1st of the current year
+      & ndastp    ,          &  !: time step date in year/month/day aammjj
+      & nsec_year ,          &  !: current time step counted in second since 00h jan 1st of the current year
+      & nsec_month,          &  !: current time step counted in second since 00h 1st day of the current month
+      & nsec_day  ,          &  !: current time step counted in second since 00h of the current day
+      & fjulday   ,          &  !: julian day
+      & adatrj                  !: number of elapsed days since the begining of the run
+   !                            !  it is the accumulated duration of previous runs
+   !                            !  that may have been run with different time steps.
+   USE in_out_manager, ONLY: & ! I/O manager
+      & lwp,                 &
+      & nleapy,              &
+      & numout
+   USE daymod,         ONLY: &
+      & ndt,               &
+      & ndt05,               &
+      & day       ,          &
+      & day_mth
+     
+      
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC day_tam        ! called by steptan.F90 and stepadj.F90
+
+CONTAINS
+
+   SUBROUTINE day_tam( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                      ***  ROUTINE day_tam  ***
+      !! 
+      !! ** Purpose :   Compute the date with a day iteration IF necessary.
+      !!    	    	forward for the tangent linear, backward for the adjoint
+      !!
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step indices
+      INTEGER, INTENT( in ) ::   kindic  ! forward (0) or backward (1)
+      !!----------------------------------------------------------------------
+
+
+
+
+      SELECT CASE ( kindic )
+      CASE ( 0 )
+         ! ----------------------------------------------
+         ! Forward running Calendar for the tangent model
+         ! ----------------------------------------------
+         CALL day( kt )
+      CASE ( 1 )
+         ! ----------------------------------------------
+         ! Backward running Calendar for the adjoint model
+         ! ----------------------------------------------
+         CALL day_adj( kt )
+      CASE default
+         IF (lwp) WRITE(numout,*) 'day_tam called with a wrong kindic: ',kindic
+         CALL abort
+      END SELECT
+   END SUBROUTINE day_tam
+   SUBROUTINE day_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                      ***  ROUTINE day_adj  ***
+      !! 
+      !! ** Purpose :   Compute the date with a day iteration backward
+      !!                if necessary.
+      !!
+      !! ** Method  : - ???
+      !!
+      !! ** Action  : - nyear     : current year
+      !!              - nmonth    : current month of the year nyear
+      !!              - nday      : current day of the month nmonth
+      !!              - nday_year : current day of the year nyear
+      !!              - ndastp    : = nyear*10000 + nmonth*100 + nday
+      !!              - adatrj    : date in days since the beginning of the run
+      !!              - nsec_year : current time of the year (in second since 00h, jan 1st)
+      !!----------------------------------------------------------------------      
+      INTEGER, INTENT(in) ::   kt        ! ocean time-step indices
+      !
+      CHARACTER (len=25) ::   charout
+      REAL(wp)           ::   zprec      ! fraction of day corresponding to 0.1 second
+      !!----------------------------------------------------------------------
+
+      !                                                 ! New time-step
+      nsec_year  = nsec_year  - ndt 
+      nsec_month = nsec_month - ndt                 
+      nsec_day   = nsec_day   - ndt                 
+      adatrj = adatrj + rdttra(1) / rday
+      fjulday = fjulday + rdttra(1) / rday
+      IF( ABS(fjulday - REAL(NINT(fjulday),wp)) < zprec )   fjulday = REAL(NINT(fjulday),wp)   ! avoid truncation error
+      IF( ABS(adatrj  - REAL(NINT(adatrj ),wp)) < zprec )   adatrj  = REAL(NINT(adatrj ),wp)   ! avoid truncation error
+      
+      IF( nsec_day < 0 ) THEN                        ! NEW day
+         !
+         nday      = nday - 1
+         nday_year = nday_year - 1
+         nsec_day  = rday - ndt05
+         !
+         IF( nday == 0 ) THEN      ! NEW month
+            nmonth = nmonth - 1
+            IF( nmonth == 0 ) THEN                     ! NEW year
+               nyear     = nyear - 1
+               nmonth    = 12
+               nday_year = nyear_len(0)
+               nsec_year = nday_year * rday - ndt05
+               IF( nleapy == 1 )   CALL day_mth
+            ENDIF
+            nday   = nmonth_len(nmonth)
+            nsec_month = nmonth_len(nmonth) * rday - ndt05
+         ENDIF
+         !
+         ndastp = nyear * 10000 + nmonth * 100 + nday   ! NEW date
+         !
+         IF(lwp) WRITE(numout,'(a,i8,a,i4.4,a,i2.2,a,i2.2,a,i3.3)') '======>> time-step =', kt,   &
+              &   '      New day, DATE Y/M/D = ', nyear, '/', nmonth, '/', nday, '      nday_year = ', nday_year
+         IF(lwp) WRITE(numout,'(a,i8,a,i7,a,i5)') '         nsec_year = ', nsec_year,   &
+              &   '   nsec_month = ', nsec_month, '   nsec_day = ', nsec_day
+      ENDIF
+      
+      !
+   END SUBROUTINE day_adj
+
+   !!======================================================================
+#endif
+END MODULE daymod_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/divcur_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/divcur_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/divcur_tam.F90	(revision 2578)
@@ -0,0 +1,1446 @@
+MODULE divcur_tam
+#if defined key_tam
+   !!==============================================================================
+   !!       ***  MODULE  divcur_tam : TANGENT/ADJOINT OF MODULE divcur  ***
+   !!
+   !! Ocean diagnostic variable : horizontal divergence and relative vorticity
+   !!
+   !!==============================================================================
+   !! History of the TAM module:
+   !!             7.0  !  95-01  (F. Van den Berghe) 
+   !!             8.0  !  96-04  (A. Weaver)
+   !!             8.1  !  98-02  (A. Weaver)
+   !!             8.2  !  00-08  (A. Weaver)
+   !!             9.0  !  08-06  (A. Vidard) Skeleton
+   !!             9.0  !  08-07  (A. Weaver) 
+   !!             9.0  !  08-11  (A. Vidard) Nemo v3 
+   !!             9.0  !  09-02  (A. Vidard) cleanup
+   !!----------------------------------------------------------------------
+   !!   div_cur_tan     : Compute the horizontal divergence and relative
+   !!                     vorticity fields (tangent routine)
+   !!   div_cur_adj     : Compute the horizontal divergence and relative
+   !!                     vorticity fields (adjoint routine)
+   !!   div_cur_adj_tst : Test of the adjoint routine
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind,       ONLY: & ! Precision variables
+      & wp
+   USE par_oce,        ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1,               &
+      & jpiglo, jpjglo
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              & 
+      & nit000,              &
+      & nitend
+   USE dom_oce,        ONLY: & ! Ocean space and time domain
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+      & e1t,                 &
+      & e2t,                 &
+      & e1f,                 &
+      & e2f,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3u,                 &
+      & e3v,                 &
+      & e3f,                 &
+      & e3t,                 &
+#endif
+      & tmask,               &
+      & fmask,               &
+#if defined key_noslip_accurate
+      & nicoa,               &
+      & njcoa,               &
+      & npcoa,               &
+#endif
+      & mig,                 &
+      & mjg,                 &
+      & nperio,              &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      & Agrif_Root,          &
+      & nbondi,              &
+      & nbondj,              &
+      & nlci,                &
+      & nlcj
+#if defined key_obc
+   USE obc_par,        ONLY: & ! Open boundary conditions
+      & lp_obc_east,         &
+      & lp_obc_west,         &
+      & lp_obc_north,        &
+      & lp_obc_south
+   USE obc_oce,        ONLY: & ! Open boundary conditions
+      & nie0p1,              &
+      & nie1p1,              &
+      & njn0p1,              &
+      & njn1p1,              &
+      & nje0,                &
+      & nje1,                &
+      & niw0,                &
+      & niw1,                &
+      & njw0,                &
+      & njw1,                &
+      & nin0,                &
+      & nin1,                &
+      & nis0,                &
+      & nis1,                &
+      & njs0,                &
+      & njs1
+#endif
+#if defined key_bdy
+   USE bdy_oce,        ONLY: & ! Unstructured open boundaries variables
+      & bdytmask
+#endif
+   USE lbclnk,         ONLY: & ! Lateral boundary conditions
+      & lbc_lnk
+
+   USE lbclnk_tam,     ONLY: & ! TAM lateral boundary conditions
+      & lbc_lnk_adj
+   USE oce_tam,        ONLY: & ! TAM ocean dynamics and tracers variables
+      & un_tl,               &
+      & un_ad,               &
+      & vn_tl,               &
+      & vn_ad,               &
+      & hdivb_tl,            &
+      & hdivb_ad,            &
+      & hdivn_tl,            &
+      & hdivn_ad,            &
+      & rotb_tl,             &
+      & rotb_ad,             &
+      & rotn_tl,             &
+      & rotn_ad
+   USE gridrandom,     ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam,     ONLY: &
+      & prntst_adj,          & !
+      & stdu,                & ! stdev for u-velocity
+      & stdv                   !           v-velocity
+ 
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC div_cur_tan,    &   ! routine called by steptan.F90
+      &   div_cur_adj,    &   ! routine called by stepadj.F90 
+      &   div_cur_adj_tst     ! adjoint test routine
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+#if defined key_noslip_accurate
+   !!----------------------------------------------------------------------
+   !!   'key_noslip_accurate'                     2nd order centered scheme
+   !!                                                4th order at the coast
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE div_cur_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE div_cur_tan  ***
+      !!
+      !! ** Purpose of direct routine :
+      !!      compute the horizontal divergence and the relative
+      !!      vorticity at before and now time-step
+      !!
+      !! ** Method of direct routine : 
+      !!      I.  divergence :
+      !!         - save the divergence computed at the previous time-step
+      !!      (note that the Asselin filter has not been applied on hdivb)
+      !!         - compute the now divergence given by :
+      !!         hdivn = 1/(e1t*e2t*e3t) ( di[e2u*e3u un] + dj[e1v*e3v vn] )
+      !!      Note: if lk_zco=T, e3u=e3v=e3t, they are simplified in the
+      !!      above expression
+      !!         - apply lateral boundary conditions on hdivn 
+      !!      II. vorticity :
+      !!         - save the curl computed at the previous time-step
+      !!            rotb = rotn
+      !!      (note that the Asselin time filter has not been applied to rotb)
+      !!         - compute the now curl in tensorial formalism:
+      !!            rotn = 1/(e1f*e2f) ( di[e2v vn] - dj[e1u un] )
+      !!         - apply lateral boundary conditions on rotn through a call
+      !!      of lbc_lnk routine.
+      !!         - Coastal boundary condition: 'key_noslip_accurate' defined,
+      !!      the no-slip boundary condition is computed using Schchepetkin
+      !!      and O'Brien (1996) scheme (i.e. 4th order at the coast).
+      !!      For example, along east coast, the one-sided finite difference
+      !!      approximation used for di[v] is:
+      !!         di[e2v vn] =  1/(e1f*e2f)
+      !!                    * ( (e2v vn)(i) + (e2v vn)(i-1) + (e2v vn)(i-2) )
+      !!
+      !! ** Action  : - update hdivb, hdivn, the before & now hor. divergence
+      !!              - update rotb , rotn , the before & now rel. vorticity
+      !!
+      !! History of the direct routine:
+      !!   8.2  !  00-03  (G. Madec)  no slip accurate
+      !!   9.0  !  03-08  (G. Madec)  merged of cur and div, free form, F90
+      !!        !  05-01  (J. Chanut, A. Sellar) unstructured open boundaries
+      !! History of the TAM routine:
+      !!   9.0  !  08-06  (A. Vidard) Skeleton
+      !!        !  08-07  (A. Weaver)
+      !!        !  08-11  (A. Vidard) Nemo v3
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) :: &
+         & kt     ! ocean time-step index
+      
+      !! * Local declarations
+      INTEGER :: &
+         & ji,  & ! dummy loop indices
+         & jj,  &
+         & jk     
+      INTEGER :: &
+         & ii,  & ! temporary integer
+         & ij,  &
+         & jl,  &   
+         & ijt, &
+         & iju       
+      REAL(KIND=wp), DIMENSION(   jpi  ,1:jpj+2) :: &
+         & zwu    ! Workspace
+      REAL(KIND=wp), DIMENSION(-1:jpi+2,  jpj  ) :: &
+         & zwv    ! Workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'div_cur_tan : horizontal velocity', & 
+            &                    ' divergence and relative vorticity'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   NOT optimal for auto-tasking case'
+      ENDIF
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         hdivb_tl(:,:,jk) = hdivn_tl(:,:,jk)    ! time swap of div arrays
+         rotb_tl (:,:,jk) = rotn_tl (:,:,jk)    ! time swap of rot arrays
+
+         !                                             ! --------
+         ! Horizontal divergence                       !   div
+         !                                             ! --------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+               hdivn_tl(ji,jj,jk) = (   e2u(ji  ,jj  ) * un_tl(ji  ,jj  ,jk) &
+                  &                   - e2u(ji-1,jj  ) * un_tl(ji-1,jj  ,jk) &
+                  &                   + e1v(ji  ,jj  ) * vn_tl(ji  ,jj  ,jk) &
+                  &                   - e1v(ji  ,jj-1) * vn_tl(ji  ,jj-1,jk) &
+                  &                 ) / ( e1t(ji,jj) * e2t(ji,jj) )
+#else
+               hdivn_tl(ji,jj,jk) =   &
+                  & (   e2u(ji  ,jj  ) * fse3u(ji  ,jj  ,jk) * un_tl(ji  ,jj  ,jk) &
+                  &   - e2u(ji-1,jj  ) * fse3u(ji-1,jj  ,jk) * un_tl(ji-1,jj  ,jk) &
+                  &   + e1v(ji  ,jj  ) * fse3v(ji  ,jj  ,jk) * vn_tl(ji  ,jj  ,jk) &
+                  &   - e1v(ji  ,jj-1) * fse3v(ji  ,jj-1,jk) * vn_tl(ji  ,jj-1,jk) &
+                  & ) / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+#endif
+            END DO
+         END DO
+
+#if defined key_obc
+         IF (Agrif_Root() ) THEN
+            ! open boundaries (div must be zero behind the open boundary)
+            !  mpp remark: The zeroing of hdivn can probably be extended 
+            !              to 1->jpi/jpj for the correct row/column
+            IF( lp_obc_east  ) hdivn_tl(nie0p1:nie1p1,nje0  :nje1  ,jk) = 0.0_wp  ! east
+            IF( lp_obc_west  ) hdivn_tl(niw0  :niw1  ,njw0  :njw1  ,jk) = 0.0_wp  ! west
+            IF( lp_obc_north ) hdivn_tl(nin0  :nin1  ,njn0p1:njn1p1,jk) = 0.0_wp  ! north
+            IF( lp_obc_south ) hdivn_tl(nis0  :nis1  ,njs0  :njs1  ,jk) = 0.0_wp  ! south
+         ENDIF
+#endif         
+#if defined key_bdy
+         ! unstructured open boundaries (div must be zero behind the open boundary)
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               hdivn_tl(ji,jj,jk)=hdivn_tl(ji,jj,jk)*bdytmask(ji,jj)
+            END DO
+         END DO
+#endif         
+         IF ( .NOT. Agrif_Root() ) then
+            IF ((nbondi ==  1).OR.(nbondi == 2)) hdivn_tl(nlci-1 , :     ,jk) = 0.e0      ! east
+            IF ((nbondi == -1).OR.(nbondi == 2)) hdivn_tl(2      , :     ,jk) = 0.e0      ! west
+            IF ((nbondj ==  1).OR.(nbondj == 2)) hdivn_tl(:      ,nlcj-1 ,jk) = 0.e0      ! north
+            IF ((nbondj == -1).OR.(nbondj == 2)) hdivn_tl(:      ,2      ,jk) = 0.e0      ! south
+         ENDIF
+
+         !                                             ! --------
+         ! relative vorticity                          !   rot 
+         !                                             ! --------
+         ! contravariant velocity (extended for lateral b.c.)
+         ! inside the model domain
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zwu(ji,jj) = e1u(ji,jj) * un_tl(ji,jj,jk)
+               zwv(ji,jj) = e2v(ji,jj) * vn_tl(ji,jj,jk)
+            END DO  
+         END DO  
+ 
+         ! East-West boundary conditions
+         IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
+            zwv(  0  ,:) = zwv(jpi-2,:)
+            zwv( -1  ,:) = zwv(jpi-3,:)
+            zwv(jpi+1,:) = zwv(  3  ,:)
+            zwv(jpi+2,:) = zwv(  4  ,:)
+         ELSE
+            zwv(  0  ,:) = 0.0_wp
+            zwv( -1  ,:) = 0.0_wp
+            zwv(jpi+1,:) = 0.0_wp
+            zwv(jpi+2,:) = 0.0_wp
+         ENDIF
+
+         ! North-South boundary conditions
+         IF( nperio == 3 .OR. nperio == 4 ) THEN
+            ! north fold ( Grid defined with a T-point pivot) ORCA 2 degre
+            zwu(jpi,jpj+1) = 0.0_wp
+            zwu(jpi,jpj+2) = 0.0_wp
+            DO ji = 1, jpi-1
+               iju = jpi - ji + 1
+               zwu(ji,jpj+1) = - zwu(iju,jpj-3)
+               zwu(ji,jpj+2) = - zwu(iju,jpj-4)
+            END DO
+         ELSEIF( nperio == 5 .OR. nperio == 6 ) THEN
+            ! north fold ( Grid defined with a F-point pivot) ORCA 0.5 degre
+            zwu(jpi,jpj+1) = 0.0_wp
+            zwu(jpi,jpj+2) = 0.0_wp
+            DO ji = 1, jpi-1
+               iju = jpi - ji
+               zwu(ji,jpj  ) = - zwu(iju,jpj-1)
+               zwu(ji,jpj+1) = - zwu(iju,jpj-2)
+               zwu(ji,jpj+2) = - zwu(iju,jpj-3)
+            END DO
+            DO ji = -1, jpi+2
+               ijt = jpi - ji + 1
+               zwv(ji,jpj) = - zwv(ijt,jpj-2)
+            END DO
+            DO ji = jpi/2+1, jpi+2
+               ijt = jpi - ji + 1
+               zwv(ji,jpjm1) = - zwv(ijt,jpjm1)
+            END DO
+         ELSE
+            ! closed
+            zwu(:,jpj+1) = 0.0_wp
+            zwu(:,jpj+2) = 0.0_wp
+         ENDIF
+
+         ! relative vorticity (vertical component of the velocity curl) 
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               rotn_tl(ji,jj,jk) = (  zwv(ji+1,jj  ) - zwv(ji,jj)      &
+                  &                 - zwu(ji  ,jj+1) + zwu(ji,jj)  )   &
+                  &         * fmask(ji,jj,jk) / ( e1f(ji,jj) * e2f(ji,jj) )
+            END DO
+         END DO
+
+         ! second order accurate scheme along straight coast
+         DO jl = 1, npcoa(1,jk)
+            ii = nicoa(jl,1,jk)
+            ij = njcoa(jl,1,jk)
+            rotn_tl(ii,ij,jk) =  1.0_wp / ( e1f(ii,ij) * e2f(ii,ij) )  &
+               & * ( + 4.0_wp * zwv(ii+1,ij) - zwv(ii+2,ij) + 0.2_wp * zwv(ii+3,ij) )
+         END DO
+         DO jl = 1, npcoa(2,jk)
+            ii = nicoa(jl,2,jk)
+            ij = njcoa(jl,2,jk)
+            rotn_tl(ii,ij,jk) =  1.0_wp / ( e1f(ii,ij) * e2f(ii,ij) )  &
+               & * ( - 4.0_wp * zwv(ii,ij)   + zwv(ii-1,ij) - 0.2_wp * zwv(ii-2,ij) )
+         END DO
+         DO jl = 1, npcoa(3,jk)
+            ii = nicoa(jl,3,jk)
+            ij = njcoa(jl,3,jk)
+            rotn_tl(ii,ij,jk) = -1.0_wp / ( e1f(ii,ij) * e2f(ii,ij) )  &
+               & * ( + 4.0_wp * zwu(ii,ij+1) - zwu(ii,ij+2) + 0.2_wp * zwu(ii,ij+3) )
+         END DO
+         DO jl = 1, npcoa(4,jk)
+            ii = nicoa(jl,4,jk)
+            ij = njcoa(jl,4,jk)
+            rotn_tl(ii,ij,jk) = -1.0_wp / ( e1f(ii,ij) * e2f(ii,ij) )  &
+               & * ( -4.0_wp * zwu(ii,ij)    + zwu(ii,ij-1) - 0.2_wp * zwu(ii,ij-2) )
+         END DO
+
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+      
+      ! 4. Lateral boundary conditions on hdivn and rotn
+      ! ---------------------------------=======---======
+      CALL lbc_lnk( hdivn_tl, 'T', 1.0_wp )   ! T-point, no sign change
+      CALL lbc_lnk( rotn_tl , 'F', 1.0_wp )   ! F-point, no sign change
+   
+   END SUBROUTINE div_cur_tan
+
+   SUBROUTINE div_cur_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE div_cur_adj  ***
+      !!
+      !! ** Purpose of direct routine :
+      !!      compute the horizontal divergence and the relative
+      !!      vorticity at before and now time-step
+      !!
+      !! ** Method of direct routine : 
+      !!      I.  divergence :
+      !!         - save the divergence computed at the previous time-step
+      !!      (note that the Asselin filter has not been applied on hdivb)
+      !!         - compute the now divergence given by :
+      !!         hdivn = 1/(e1t*e2t*e3t) ( di[e2u*e3u un] + dj[e1v*e3v vn] )
+      !!      Note: if lk_zco=T, e3u=e3v=e3t, they are simplified in the
+      !!      above expression
+      !!         - apply lateral boundary conditions on hdivn 
+      !!      II. vorticity :
+      !!         - save the curl computed at the previous time-step
+      !!            rotb = rotn
+      !!      (note that the Asselin time filter has not been applied to rotb)
+      !!         - compute the now curl in tensorial formalism:
+      !!            rotn = 1/(e1f*e2f) ( di[e2v vn] - dj[e1u un] )
+      !!         - apply lateral boundary conditions on rotn through a call
+      !!      of lbc_lnk routine.
+      !!         - Coastal boundary condition: 'key_noslip_accurate' defined,
+      !!      the no-slip boundary condition is computed using Schchepetkin
+      !!      and O'Brien (1996) scheme (i.e. 4th order at the coast).
+      !!      For example, along east coast, the one-sided finite difference
+      !!      approximation used for di[v] is:
+      !!         di[e2v vn] =  1/(e1f*e2f)
+      !!                    * ( (e2v vn)(i) + (e2v vn)(i-1) + (e2v vn)(i-2) )
+      !!
+      !! ** Action  : - update hdivb, hdivn, the before & now hor. divergence
+      !!              - update rotb , rotn , the before & now rel. vorticity
+      !!
+      !! History of the direct routine:
+      !!   8.2  !  00-03  (G. Madec)  no slip accurate
+      !!   9.0  !  03-08  (G. Madec)  merged of cur and div, free form, F90
+      !! History of the TAM routine:
+      !!   9.0  !  08-06  (A. Vidard) Skeleton
+      !!   9.0  !  08-07  (A. Weaver) 
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) :: &
+         & kt     ! ocean time-step index
+      
+      !! * Local declarations
+      INTEGER :: &
+         & ji,  & ! dummy loop indices
+         & jj,  &
+         & jk     
+      INTEGER :: &
+         & ii,  & ! temporary integer
+         & ij,  &
+         & jl,  &   
+         & ijt, &
+         & iju       
+      REAL(wp) :: &
+         & zdiv, &
+         & zdju
+      REAL(KIND=wp), DIMENSION(   jpi  ,1:jpj+2) :: &
+         & zwu    ! Workspace
+      REAL(KIND=wp), DIMENSION(-1:jpi+2,  jpj  ) :: &
+         & zwv    ! Workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'div_cur_adj : horizontal velocity', & 
+            &                    ' divergence and relative vorticity'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   NOT optimal for auto-tasking case'
+      ENDIF
+
+      ! 4. Lateral boundary conditions on hdivn and rotn
+      ! ---------------------------------=======---======
+      CALL lbc_lnk_adj( rotn_ad , 'F', 1.0_wp )   ! F-point, no sign change
+      CALL lbc_lnk_adj( hdivn_ad, 'T', 1.0_wp )   ! T-point, no sign change
+
+      !                                                ! ===============
+      DO jk = jpkm1, 1, -1                             ! Horizontal slab
+         !                                             ! ===============
+
+         ! local adjoint workspace initialization
+         zwu(:,:) = 0.0_wp
+         zwv(:,:) = 0.0_wp
+
+         !                                             ! --------
+         ! relative vorticity                          !   rot 
+         !                                             ! --------
+
+         DO jl = npcoa(4,jk), 1, -1
+            ii = nicoa(jl,4,jk)
+            ij = njcoa(jl,4,jk)
+            rotn_ad(ii,ij,jk) = -1.0_wp * rotn_ad(ii,ij,jk) &
+               &                / ( e1f(ii,ij) * e2f(ii,ij) )
+            zwu(ii,ij  ) = zwu(ii,ij  ) - 4.0_wp * rotn_ad(ii,ij,jk)
+            zwu(ii,ij-1) = zwu(ii,ij-1) +          rotn_ad(ii,ij,jk)
+            zwu(ii,ij-2) = zwu(ii,ij-2) - 0.2_wp * rotn_ad(ii,ij,jk)
+            rotn_ad(ii,ij,jk) = 0.0_wp
+         END DO
+         DO jl = npcoa(3,jk), 1, -1
+            ii = nicoa(jl,3,jk)
+            ij = njcoa(jl,3,jk)
+            rotn_ad(ii,ij,jk) = -1.0_wp * rotn_ad(ii,ij,jk) &
+               &                / ( e1f(ii,ij) * e2f(ii,ij) )
+            zwu(ii,ij+1) = zwu(ii,ij+1) + 4.0_wp * rotn_ad(ii,ij,jk)
+            zwu(ii,ij+2) = zwu(ii,ij+2) -          rotn_ad(ii,ij,jk)
+            zwu(ii,ij+3) = zwu(ii,ij+3) + 0.2_wp * rotn_ad(ii,ij,jk)
+            rotn_ad(ii,ij,jk) = 0.0_wp
+         END DO
+         DO jl = npcoa(2,jk), 1, -1
+            ii = nicoa(jl,2,jk)
+            ij = njcoa(jl,2,jk)
+            rotn_ad(ii,ij,jk) =  1.0_wp * rotn_ad(ii,ij,jk) &
+               &                / ( e1f(ii,ij) * e2f(ii,ij) )
+            zwv(ii  ,ij) = zwv(ii  ,ij) - 4.0_wp * rotn_ad(ii,ij,jk)
+            zwv(ii-1,ij) = zwv(ii-1,ij) +          rotn_ad(ii,ij,jk)
+            zwv(ii-2,ij) = zwv(ii-2,ij) - 0.2_wp * rotn_ad(ii,ij,jk)
+            rotn_ad(ii,ij,jk) = 0.0_wp
+         END DO
+         ! second order accurate scheme along straight coast
+         DO jl = npcoa(1,jk), 1, -1
+            ii = nicoa(jl,1,jk)
+            ij = njcoa(jl,1,jk)
+            rotn_ad(ii,ij,jk) =  1.0_wp * rotn_ad(ii,ij,jk) &
+               &                / ( e1f(ii,ij) * e2f(ii,ij) )
+            zwv(ii+1,ij) = zwv(ii+1,ij) + 4.0_wp * rotn_ad(ii,ij,jk)
+            zwv(ii+2,ij) = zwv(ii+2,ij) -          rotn_ad(ii,ij,jk)
+            zwv(ii+3,ij) = zwv(ii+3,ij) + 0.2_wp * rotn_ad(ii,ij,jk)
+            rotn_ad(ii,ij,jk) = 0.0_wp
+         END DO
+
+         ! relative vorticity (vertical component of the velocity curl) 
+         DO jj = jpjm1, 1, -1
+            DO ji = fs_jpim1, 1, -1   ! vector opt.
+               rotn_ad(ji,jj,jk) = rotn_ad(ji,jj,jk) * fmask(ji,jj,jk) &
+                  &                / ( e1f(ji,jj) * e2f(ji,jj) )
+               zwv(ji  ,jj  ) = zwv(ji  ,jj  ) - rotn_ad(ji,jj,jk)
+               zwu(ji  ,jj  ) = zwu(ji  ,jj  ) + rotn_ad(ji,jj,jk)
+               zwu(ji  ,jj+1) = zwu(ji  ,jj+1) - rotn_ad(ji,jj,jk)
+               zwv(ji+1,jj  ) = zwv(ji+1,jj  ) + rotn_ad(ji,jj,jk)
+               rotn_ad(ji,jj,jk) = 0.0
+            END DO
+         END DO
+
+         ! North-South boundary conditions
+         IF( nperio == 3 .OR. nperio == 4 ) THEN
+            ! north fold ( Grid defined with a T-point pivot) ORCA 2 degree
+            DO ji = jpi-1, 1, -1
+               iju = jpi - ji + 1
+               zwu(iju,jpj-4) = zwu(iju,jpj-4) - zwu(ji,jpj+2)
+               zwu(ji ,jpj+2) = 0.0_wp
+               zwu(iju,jpj-3) = zwu(iju,jpj-3) - zwu(ji,jpj+1)
+               zwu(ji ,jpj+1) = 0.0_wp
+            END DO
+            zwu(jpi,jpj+2) = 0.0_wp
+            zwu(jpi,jpj+1) = 0.0_wp
+         ELSEIF( nperio == 5 .OR. nperio == 6 ) THEN
+            ! north fold ( Grid defined with a F-point pivot) ORCA 0.5 degree
+            DO ji = jpi+2, jpi/2+1, -1
+               ijt = jpi - ji + 1
+               zwv(ijt,jpjm1) = zwv(ijt,jpjm1) - zwv(ji,jpjm1)
+               zwv(ji ,jpjm1) = 0.0_wp
+            END DO
+            DO ji = jpi+2, -1, -1
+               ijt = jpi - ji + 1
+               zwv(ijt,jpj-2) = zwv(ijt,jpj-2) - zwv(ji,jpj  )
+               zwv(ji ,jpj  ) = 0.0_wp
+            END DO
+            DO ji = jpi-1, 1, -1
+               iju = jpi - ji
+               zwu(iju,jpj-3) = zwu(iju,jpj-3) - zwu(ji,jpj+2)
+               zwu(ji ,jpj+2) = 0.0_wp
+               zwu(iju,jpj-2) = zwu(iju,jpj-2) - zwu(ji,jpj+1)
+               zwu(ji ,jpj+1) = 0.0_wp
+               zwu(iju,jpj-1) = zwu(iju,jpj-1) - zwu(ji,jpj  )
+               zwu(ji ,jpj  ) = 0.0_wp
+            END DO
+            zwu(jpi,jpj+2) = 0.0_wp
+            zwu(jpi,jpj+1) = 0.0_wp
+         ELSE
+            ! closed
+            zwu(:,jpj+2) = 0.0_wp
+            zwu(:,jpj+1) = 0.0_wp
+         ENDIF
+
+         ! East-West boundary conditions
+         IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
+            zwv(  4  ,:) = zwv(  4  ,:) + zwv(jpi+2,:)
+            zwv(jpi+2,:) = 0.0_wp
+            zwv(  3  ,:) = zwv(  3  ,:) + zwv(jpi+1,:)
+            zwv(jpi+1,:) = 0.0_wp
+            zwv(jpi-3,:) = zwv(jpi-3,:) + zwv( -1  ,:)
+            zwv( -1  ,:) = 0.0_wp
+            zwv(jpi-2,:) = zwv(jpi-2,:) + zwv(  0  ,:)
+            zwv(  0  ,:) = 0.0_wp
+         ELSE
+            zwv(jpi+2,:) = 0.0_wp
+            zwv(jpi+1,:) = 0.0_wp
+            zwv( -1  ,:) = 0.0_wp
+            zwv(  0  ,:) = 0.0_wp
+         ENDIF
+
+         ! contravariant velocity (extended for lateral b.c.)
+         ! inside the model domain
+         DO jj = jpj, 1, -1
+            DO ji = jpi, 1, -1
+               vn_ad(ji,jj,jk) = vn_ad(ji,jj,jk) + e2v(ji,jj) * zwv(ji,jj)
+               un_ad(ji,jj,jk) = un_ad(ji,jj,jk) + e1u(ji,jj) * zwu(ji,jj)
+            END DO  
+         END DO  
+
+         IF( .NOT. AGRIF_Root() ) THEN
+            IF ((nbondi ==  1).OR.(nbondi == 2)) hdivn_ad(nlci-1 , :     ,jk) = 0.0_wp      ! east
+            IF ((nbondi == -1).OR.(nbondi == 2)) hdivn_ad(2      , :     ,jk) = 0.0_wp      ! west
+            IF ((nbondj ==  1).OR.(nbondj == 2)) hdivn_ad(:      ,nlcj-1 ,jk) = 0.0_wp      ! north
+            IF ((nbondj == -1).OR.(nbondj == 2)) hdivn_ad(:      ,2      ,jk) = 0.0_wp      ! south
+         ENDIF
+#if defined key_bdy
+         ! unstructured open boundaries (div must be zero behind the open boundary)
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               hdivn_ad(ji,jj,jk)=hdivn_ad(ji,jj,jk)*bdytmask(ji,jj)
+            END DO
+         END DO
+#endif         
+#if defined key_obc
+         IF (Agrif_Root() ) THEN
+            ! open boundaries (div must be zero behind the open boundary)
+            !  mpp remark: The zeroing of hdivn can probably be extended 
+            !              to 1->jpi/jpj for the correct row/column
+            IF( lp_obc_east  ) hdivn_ad(nie0p1:nie1p1,nje0  :nje1  ,jk) = 0.0_wp  ! east
+            IF( lp_obc_west  ) hdivn_ad(niw0  :niw1  ,njw0  :njw1  ,jk) = 0.0_wp  ! west
+            IF( lp_obc_north ) hdivn_ad(nin0  :nin1  ,njn0p1:njn1p1,jk) = 0.0_wp  ! north
+            IF( lp_obc_south ) hdivn_ad(nis0  :nis1  ,njs0  :njs1  ,jk) = 0.0_wp  ! south
+         ENDIF
+#endif         
+
+         !                                             ! --------
+         ! Horizontal divergence                       !   div
+         !                                             ! --------
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+#if defined key_zco
+               hdivn_ad(ji,jj,jk) =  hdivn_ad(ji,jj,jk)  &
+                  &                  / ( e1t(ji,jj) * e2t(ji,jj) )
+               un_ad(ji  ,jj  ,jk) = un_ad(ji  ,jj  ,jk) &
+                  &                  + e2u(ji  ,jj  ) * hdivn_ad(ji,jj,jk)
+               un_ad(ji-1,jj  ,jk) = un_ad(ji-1,jj  ,jk) &
+                  &                  - e2u(ji-1,jj  ) * hdivn_ad(ji,jj,jk)
+               vn_ad(ji  ,jj  ,jk) = vn_ad(ji  ,jj  ,jk) &
+                  &                  + e1v(ji  ,jj  ) * hdivn_ad(ji,jj,jk)
+               vn_ad(ji  ,jj-1,jk) = vn_ad(ji  ,jj-1,jk) &
+                  &                  - e1v(ji  ,jj-1) * hdivn_ad(ji,jj,jk)
+               hdivn_ad(ji,jj,jk) = 0.0_wp
+#else
+               hdivn_ad(ji,jj,jk) =  hdivn_ad(ji,jj,jk)  &
+                  &                  / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+               un_ad(ji  ,jj  ,jk) = un_ad(ji  ,jj  ,jk) &
+                  &                  + e2u(ji  ,jj  ) * fse3u(ji  ,jj  ,jk) &
+                  &                                   * hdivn_ad(ji,jj,jk)
+               un_ad(ji-1,jj  ,jk) = un_ad(ji-1,jj  ,jk) &
+                  &                  - e2u(ji-1,jj  ) * fse3u(ji-1,jj  ,jk) &
+                  &                                   * hdivn_ad(ji,jj,jk)
+               vn_ad(ji  ,jj  ,jk) = vn_ad(ji  ,jj  ,jk) & 
+                  &                  + e1v(ji  ,jj  ) * fse3v(ji  ,jj  ,jk) &
+                  &                                   * hdivn_ad(ji,jj,jk)
+               vn_ad(ji  ,jj-1,jk) = vn_ad(ji  ,jj-1,jk) & 
+                  &                  - e1v(ji  ,jj-1) * fse3v(ji  ,jj-1,jk) &
+                  &                                   * hdivn_ad(ji,jj,jk)
+               hdivn_ad(ji,jj,jk) = 0.0_wp
+#endif
+            END DO  
+         END DO  
+
+         rotn_ad (:,:,jk) = rotn_ad (:,:,jk) + rotb_ad (:,:,jk)  ! time swap
+         rotb_ad (:,:,jk) = 0.0_wp
+         hdivn_ad(:,:,jk) = hdivn_ad(:,:,jk) + hdivb_ad(:,:,jk)  ! time swap
+         hdivb_ad(:,:,jk) = 0.0_wp
+
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+   END SUBROUTINE div_cur_adj
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                           2nd order centered schemes
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE div_cur_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE div_cur_tan  ***
+      !!                    
+      !! ** Purpose of direct routine :
+      !!      compute the horizontal divergence and the relative
+      !!      vorticity at before and now time-step
+      !!
+      !! ** Method of direct routine : 
+      !!              - Divergence:
+      !!      - save the divergence computed at the previous time-step
+      !!      (note that the Asselin filter has not been applied on hdivb)
+      !!      - compute the now divergence given by :
+      !!         hdivn = 1/(e1t*e2t*e3t) ( di[e2u*e3u un] + dj[e1v*e3v vn] )
+      !!      Note: if lk_zco=T, e3u=e3v=e3t, they are simplified in the 
+      !!      above expression
+      !!      - apply lateral boundary conditions on hdivn 
+      !!              - Relavtive Vorticity :
+      !!      - save the curl computed at the previous time-step (rotb = rotn)
+      !!      (note that the Asselin time filter has not been applied to rotb)
+      !!      - compute the now curl in tensorial formalism:
+      !!            rotn = 1/(e1f*e2f) ( di[e2v vn] - dj[e1u un] )
+      !!      - apply lateral boundary conditions on rotn through a call to
+      !!      routine lbc_lnk routine.
+      !!      Note: Coastal boundary condition: lateral friction set through
+      !!      the value of fmask along the coast (see dommsk.F90) and shlat
+      !!      (namelist parameter)
+      !!
+      !! ** Action  : - update hdivb, hdivn, the before & now hor. divergence
+      !!              - update rotb , rotn , the before & now rel. vorticity
+      !!
+      !! History of the direct routine:
+      !!   1.0  !  87-06  (P. Andrich, D. L Hostis)  Original code
+      !!   4.0  !  91-11  (G. Madec)
+      !!   6.0  !  93-03  (M. Guyon)  symetrical conditions
+      !!   7.0  !  96-01  (G. Madec)  s-coordinates
+      !!   8.0  !  97-06  (G. Madec)  lateral boundary cond., lbc
+      !!   8.1  !  97-08  (J.M. Molines)  Open boundaries
+      !!   9.0  !  02-09  (G. Madec, E. Durand)  Free form, F90
+      !!        !  05-01  (J. Chanut) Unstructured open boundaries
+      !! History of the TAM routine:
+      !!   9.0  !  08-06  (A. Vidard) Skeleton
+      !!        !  08-07  (A. Weaver) tangent of the 02-09 version
+      !!        !  08-11  (A. Vidard) tangent of the 05-01 version
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) :: &
+         & kt     ! ocean time-step index
+      
+      !! * Local declarations
+      INTEGER :: &
+         & ji,  & ! dummy loop indices
+         & jj,  &
+         & jk     
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'div_cur_tan : horizontal velocity divergence and'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   relative vorticity'
+      ENDIF
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         hdivb_tl(:,:,jk) = hdivn_tl(:,:,jk)    ! time swap of div arrays
+         rotb_tl (:,:,jk) = rotn_tl (:,:,jk)    ! time swap of rot arrays
+
+         !                                             ! --------
+         ! Horizontal divergence                       !   div 
+         !                                             ! --------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+               hdivn_tl(ji,jj,jk) = (   e2u(ji  ,jj  ) * un_tl(ji  ,jj  ,jk) &
+                  &                   - e2u(ji-1,jj  ) * un_tl(ji-1,jj  ,jk) &
+                  &                   + e1v(ji  ,jj  ) * vn_tl(ji  ,jj  ,jk) &
+                  &                   - e1v(ji  ,jj-1) * vn_tl(ji  ,jj-1,jk) &
+                  &                 ) / ( e1t(ji,jj) * e2t(ji,jj) )
+#else
+               hdivn_tl(ji,jj,jk) =   &
+                  & (   e2u(ji  ,jj  ) * fse3u(ji  ,jj  ,jk) * un_tl(ji  ,jj  ,jk) &
+                  &   - e2u(ji-1,jj  ) * fse3u(ji-1,jj  ,jk) * un_tl(ji-1,jj  ,jk) &
+                  &   + e1v(ji  ,jj  ) * fse3v(ji  ,jj  ,jk) * vn_tl(ji  ,jj  ,jk) &
+                  &   - e1v(ji  ,jj-1) * fse3v(ji  ,jj-1,jk) * vn_tl(ji  ,jj-1,jk) &
+                  & ) / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+#endif
+            END DO  
+         END DO
+
+#if defined key_obc
+         IF ( Agrif_Root() ) THEN
+            ! open boundaries (div must be zero behind the open boundary)
+            !  mpp remark: The zeroing of hdivn can probably be extended to 1->jpi/jpj for the correct row/column
+            IF( lp_obc_east  ) hdivn_tl(nie0p1:nie1p1,nje0  :nje1  ,jk) = 0.0_wp ! east
+            IF( lp_obc_west  ) hdivn_tl(niw0  :niw1  ,njw0  :njw1  ,jk) = 0.0_wp ! west
+            IF( lp_obc_north ) hdivn_tl(nin0  :nin1  ,njn0p1:njn1p1,jk) = 0.0_wp ! north
+            IF( lp_obc_south ) hdivn_tl(nis0  :nis1  ,njs0  :njs1  ,jk) = 0.0_wp ! south
+         ENDIF
+#endif         
+#if defined key_bdy
+         ! unstructured open boundaries (div must be zero behind the open boundary)
+         DO jj = 1, jpj
+           DO ji = 1, jpi
+             hdivn_tl(ji,jj,jk)=hdivn_tl(ji,jj,jk)*bdytmask(ji,jj)
+           END DO
+         END DO
+#endif        
+         IF ( .NOT. Agrif_Root() ) THEN
+            IF ((nbondi ==  1).OR.(nbondi == 2)) hdivn_tl(nlci-1 , :     ,jk) = 0.e0      ! east
+            IF ((nbondi == -1).OR.(nbondi == 2)) hdivn_tl(2      , :     ,jk) = 0.e0      ! west
+            IF ((nbondj ==  1).OR.(nbondj == 2)) hdivn_tl(:      ,nlcj-1 ,jk) = 0.e0      ! north
+            IF ((nbondj == -1).OR.(nbondj == 2)) hdivn_tl(:      ,2      ,jk) = 0.e0      ! south
+         ENDIF 
+         !                                             ! --------
+         ! relative vorticity                          !   rot 
+         !                                             ! --------
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               rotn_tl(ji,jj,jk) = (   e2v(ji+1,jj  ) * vn_tl(ji+1,jj  ,jk) &
+                  &                  - e2v(ji  ,jj  ) * vn_tl(ji  ,jj  ,jk) &
+                  &                  - e1u(ji  ,jj+1) * un_tl(ji  ,jj+1,jk) &
+                  &                  + e1u(ji  ,jj  ) * un_tl(ji  ,jj  ,jk) &
+                  &                ) * fmask(ji,jj,jk) / ( e1f(ji,jj) * e2f(ji,jj) )
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+      
+      ! 4. Lateral boundary conditions on hdivn and rotn
+      ! ---------------------------------=======---======
+      CALL lbc_lnk( hdivn_tl, 'T', 1.0_wp )     ! T-point, no sign change
+      CALL lbc_lnk( rotn_tl , 'F', 1.0_wp )     ! F-point, no sign change
+
+   END SUBROUTINE div_cur_tan
+
+   SUBROUTINE div_cur_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE div_cur_adj  ***
+      !!                    
+      !! ** Purpose of direct routine :
+      !!      compute the horizontal divergence and the relative
+      !!      vorticity at before and now time-step
+      !!
+      !! ** Method of direct routine : 
+      !!              - Divergence:
+      !!      - save the divergence computed at the previous time-step
+      !!      (note that the Asselin filter has not been applied on hdivb)
+      !!      - compute the now divergence given by :
+      !!         hdivn = 1/(e1t*e2t*e3t) ( di[e2u*e3u un] + dj[e1v*e3v vn] )
+      !!      Note: if lk_zco=T, e3u=e3v=e3t, they are simplified in the 
+      !!      above expression
+      !!      - apply lateral boundary conditions on hdivn 
+      !!              - Relavtive Vorticity :
+      !!      - save the curl computed at the previous time-step (rotb = rotn)
+      !!      (note that the Asselin time filter has not been applied to rotb)
+      !!      - compute the now curl in tensorial formalism:
+      !!            rotn = 1/(e1f*e2f) ( di[e2v vn] - dj[e1u un] )
+      !!      - apply lateral boundary conditions on rotn through a call to
+      !!      routine lbc_lnk routine.
+      !!      Note: Coastal boundary condition: lateral friction set through
+      !!      the value of fmask along the coast (see dommsk.F90) and shlat
+      !!      (namelist parameter)
+      !!
+      !! ** Action  : - update hdivb, hdivn, the before & now hor. divergence
+      !!              - update rotb , rotn , the before & now rel. vorticity
+      !!
+      !! History of the direct routine:
+      !!   1.0  !  87-06  (P. Andrich, D. L Hostis)  Original code
+      !!   4.0  !  91-11  (G. Madec)
+      !!   6.0  !  93-03  (M. Guyon)  symetrical conditions
+      !!   7.0  !  96-01  (G. Madec)  s-coordinates
+      !!   8.0  !  97-06  (G. Madec)  lateral boundary cond., lbc
+      !!   8.1  !  97-08  (J.M. Molines)  Open boundaries
+      !!   9.0  !  02-09  (G. Madec, E. Durand)  Free form, F90
+      !! History of the TAM routine:
+      !!   9.0  !  08-06  (A. Vidard) Skeleton
+      !!   9.0  !  08-07  (A. Weaver) 
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) :: &
+         & kt     ! ocean time-step index
+      
+      !! * Local declarations
+      INTEGER :: &
+         & ji,  & ! dummy loop indices
+         & jj,  &
+         & jk     
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'div_cur_adj : horizontal velocity divergence and'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   relative vorticity'
+      ENDIF
+      
+      ! 4. Lateral boundary conditions on hdivn and rotn
+      ! ---------------------------------=======---======
+      CALL lbc_lnk_adj( rotn_ad , 'F', 1.0_wp )     ! F-point, no sign change
+      CALL lbc_lnk_adj( hdivn_ad, 'T', 1.0_wp )     ! T-point, no sign change
+
+      !                                                ! ===============
+      DO jk = jpkm1, 1, -1                             ! Horizontal slab
+         !                                             ! ===============
+
+         !                                             ! --------
+         ! relative vorticity                          !   rot 
+         !                                             ! --------
+         DO jj = jpjm1, 1, -1
+            DO ji = fs_jpim1, 1, -1   ! vector opt.
+               rotn_ad(ji,jj,jk) =  rotn_ad(ji,jj,jk) * fmask(ji,jj,jk) &
+                  &                       / ( e1f(ji,jj) * e2f(ji,jj) )
+               un_ad(ji  ,jj  ,jk) = un_ad(ji  ,jj  ,jk) &
+                  &                  + e1u(ji  ,jj  ) * rotn_ad(ji,jj,jk)
+               un_ad(ji  ,jj+1,jk) = un_ad(ji  ,jj+1,jk) &
+                  &                  - e1u(ji  ,jj+1) * rotn_ad(ji,jj,jk)
+               vn_ad(ji  ,jj  ,jk) = vn_ad(ji  ,jj  ,jk) &
+                  &                  - e2v(ji  ,jj  ) * rotn_ad(ji,jj,jk)
+               vn_ad(ji+1,jj  ,jk) = vn_ad(ji+1,jj  ,jk) &
+                  &                  + e2v(ji+1,jj  ) * rotn_ad(ji,jj,jk)
+               rotn_ad(ji,jj,jk) = 0.0_wp
+            END DO
+         END DO
+
+         IF( .NOT. AGRIF_Root() ) THEN
+            IF ((nbondi ==  1).OR.(nbondi == 2)) hdivn_ad(nlci-1 , :     ,jk) = 0.0_wp      ! east
+            IF ((nbondi == -1).OR.(nbondi == 2)) hdivn_ad(2      , :     ,jk) = 0.0_wp      ! west
+            IF ((nbondj ==  1).OR.(nbondj == 2)) hdivn_ad(:      ,nlcj-1 ,jk) = 0.0_wp      ! north
+            IF ((nbondj == -1).OR.(nbondj == 2)) hdivn_ad(:      ,2      ,jk) = 0.0_wp      ! south
+         ENDIF
+#if defined key_bdy
+         ! unstructured open boundaries (div must be zero behind the open boundary)
+         DO jj = 1, jpj
+           DO ji = 1, jpi
+             hdivn_ad(ji,jj,jk)=hdivn_ad(ji,jj,jk)*bdytmask(ji,jj)
+           END DO
+         END DO
+#endif        
+#if defined key_obc
+         ! open boundaries (div must be zero behind the open boundary)
+         !  mpp remark: The zeroing of hdivn can probably be extended to 1->jpi/jpj for the correct row/column
+         IF ( Agrif_Root() ) THEN
+            IF( lp_obc_east  ) hdivn_ad(nie0p1:nie1p1,nje0  :nje1  ,jk) = 0.0_wp ! east
+            IF( lp_obc_west  ) hdivn_ad(niw0  :niw1  ,njw0  :njw1  ,jk) = 0.0_wp ! west
+            IF( lp_obc_north ) hdivn_ad(nin0  :nin1  ,njn0p1:njn1p1,jk) = 0.0_wp ! north
+            IF( lp_obc_south ) hdivn_ad(nis0  :nis1  ,njs0  :njs1  ,jk) = 0.0_wp ! south
+         ENDIF
+#endif         
+
+         !                                             ! --------
+         ! Horizontal divergence                       !   div 
+         !                                             ! --------
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+#if defined key_zco
+               hdivn_ad(ji,jj,jk) =  hdivn_ad(ji,jj,jk)  &
+                  &                  / ( e1t(ji,jj) * e2t(ji,jj) )
+               un_ad(ji  ,jj  ,jk) = un_ad(ji  ,jj  ,jk) &
+                  &                  + e2u(ji  ,jj  ) * hdivn_ad(ji,jj,jk)
+               un_ad(ji-1,jj  ,jk) = un_ad(ji-1,jj  ,jk) &
+                  &                  - e2u(ji-1,jj  ) * hdivn_ad(ji,jj,jk)
+               vn_ad(ji  ,jj  ,jk) = vn_ad(ji  ,jj  ,jk) &
+                  &                  + e1v(ji  ,jj  ) * hdivn_ad(ji,jj,jk)
+               vn_ad(ji  ,jj-1,jk) = vn_ad(ji  ,jj-1,jk) &
+                  &                  - e1v(ji  ,jj-1) * hdivn_ad(ji,jj,jk)
+               hdivn_ad(ji,jj,jk) = 0.0_wp
+#else
+               hdivn_ad(ji,jj,jk) =  hdivn_ad(ji,jj,jk)  &
+                  &                  / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+               un_ad(ji  ,jj  ,jk) = un_ad(ji  ,jj  ,jk) & 
+                  &                  + e2u(ji  ,jj  ) * fse3u(ji  ,jj  ,jk) &
+                  &                                   * hdivn_ad(ji,jj,jk)
+               un_ad(ji-1,jj  ,jk) = un_ad(ji-1,jj  ,jk) &
+                  &                  - e2u(ji-1,jj  ) * fse3u(ji-1,jj  ,jk) &
+                  &                                   * hdivn_ad(ji,jj,jk)
+               vn_ad(ji  ,jj  ,jk) = vn_ad(ji  ,jj  ,jk) &
+                  &                  + e1v(ji  ,jj  ) * fse3v(ji  ,jj  ,jk) &
+                  &                                   * hdivn_ad(ji,jj,jk)
+               vn_ad(ji  ,jj-1,jk) = vn_ad(ji  ,jj-1,jk) &
+                  &                  - e1v(ji  ,jj-1) * fse3v(ji  ,jj-1,jk) &
+                  &                                   * hdivn_ad(ji,jj,jk)
+               hdivn_ad(ji,jj,jk) = 0.0_wp
+#endif
+            END DO  
+         END DO  
+
+         rotn_ad (:,:,jk) = rotn_ad (:,:,jk) + rotb_ad (:,:,jk)  ! time swap
+         rotb_ad (:,:,jk) = 0.0_wp
+         hdivn_ad(:,:,jk) = hdivn_ad(:,:,jk) + hdivb_ad(:,:,jk)  ! time swap
+         hdivb_ad(:,:,jk) = 0.0_wp
+
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+   END SUBROUTINE div_cur_adj
+   
+#endif
+
+   SUBROUTINE div_cur_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!          ***  ROUTINE div_cur_adj_tst : TEST OF div_cur_adj  ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Separate tests are applied for the following dx and dy:
+      !!         
+      !!      1) dx = ( un_tl, vn_tl ) and
+      !!         dy = ( hdivn_tl )
+      !!      2) dx = ( un_tl, vn_tl ) and
+      !!         dy = ( rotntl )
+      !!
+      !! History :
+      !!        ! 08-07 (A. Weaver)
+      !!-----------------------------------------------------------------------
+
+      !! * Modules used
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      INTEGER :: &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zun_tlin,     & ! Tangent input: now u-velocity
+         & zvn_tlin,     & ! Tangent input: now v-velocity
+         & zhdivn_tlin,  & ! Tangent input: now horizontal divergence
+         & zrotn_tlin,   & ! Tangent input: now relative vorticity
+         & zhdivb_tlout, & ! Tangent output: before horizontal divergence
+         & zhdivn_tlout, & ! Tangent output: now horizontal divergence
+         & zrotb_tlout,  & ! Tangent output: before relative vorticity
+         & zrotn_tlout,  & ! Tangent output: now relative vorticity
+         & zhdivb_adin,  & ! Adjoint input: before horizontal divergence
+         & zhdivn_adin,  & ! Adjoint input: now horizontal divergence
+         & zrotb_adin,   & ! Adjoint input: before relative vorticity
+         & zrotn_adin,   & ! Adjoint input: now relative vorticity
+         & zun_adout,    & ! Adjoint output: now u-velocity
+         & zvn_adout,    & ! Adjoint output: now v-velocity
+         & zhdivn_adout, & ! Adjoint output: now horizontal divergence
+         & zrotn_adout,  & ! Adjoint output: now relative vorticity
+         & znu,          & ! 3D random field for u
+         & znv             ! 3D random field for v
+
+      REAL(KIND=wp) :: &
+                           ! random field standard deviation for:
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_1,       & !   scalar product components
+         & zsp1_2,       & 
+         & zsp1_3,       & !   
+         & zsp1_4,       & 
+         & zsp2,         & ! scalar product involving the adjoint routine
+         & zsp2_1,       & !   scalar product components
+         & zsp2_2,       & 
+         & zsp2_3,       & 
+         & zsp2_4
+
+      CHARACTER(LEN=14) :: cl_name
+
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zun_tlin(jpi,jpj,jpk),     &
+         & zvn_tlin(jpi,jpj,jpk),     &
+         & zhdivn_tlin(jpi,jpj,jpk),  &
+         & zrotn_tlin(jpi,jpj,jpk),   &
+         & zhdivb_tlout(jpi,jpj,jpk), &
+         & zhdivn_tlout(jpi,jpj,jpk), &
+         & zrotb_tlout(jpi,jpj,jpk),  &
+         & zrotn_tlout(jpi,jpj,jpk),  &
+         & zhdivb_adin(jpi,jpj,jpk),  &
+         & zhdivn_adin(jpi,jpj,jpk),  &
+         & zrotb_adin(jpi,jpj,jpk),   &
+         & zrotn_adin(jpi,jpj,jpk),   &
+         & zun_adout(jpi,jpj,jpk),    &
+         & zvn_adout(jpi,jpj,jpk),    &
+         & zhdivn_adout(jpi,jpj,jpk), &
+         & zrotn_adout(jpi,jpj,jpk),  &
+         & znu(jpi,jpj,jpk),          &
+         & znv(jpi,jpj,jpk)           &
+         & )
+      
+ 
+      !==================================================================
+      ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and 
+      !    dy = ( hdivb_tl, hdivn_tl )
+      !==================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+
+      zun_tlin    (:,:,:) = 0.0_wp
+      zvn_tlin    (:,:,:) = 0.0_wp
+      zhdivn_tlin (:,:,:) = 0.0_wp
+      zrotn_tlin  (:,:,:) = 0.0_wp
+      zhdivb_tlout(:,:,:) = 0.0_wp
+      zhdivn_tlout(:,:,:) = 0.0_wp
+      zrotb_tlout (:,:,:) = 0.0_wp
+      zrotn_tlout (:,:,:) = 0.0_wp
+      zhdivb_adin (:,:,:) = 0.0_wp
+      zhdivn_adin (:,:,:) = 0.0_wp
+      zrotb_adin  (:,:,:) = 0.0_wp
+      zrotn_adin  (:,:,:) = 0.0_wp
+      zrotn_adout (:,:,:) = 0.0_wp
+      zhdivn_adout(:,:,:) = 0.0_wp
+      zun_adout   (:,:,:) = 0.0_wp
+      zvn_adout   (:,:,:) = 0.0_wp
+
+      un_tl   (:,:,:) = 0.0_wp
+      vn_tl   (:,:,:) = 0.0_wp
+      hdivb_tl(:,:,:) = 0.0_wp
+      hdivn_tl(:,:,:) = 0.0_wp
+      rotb_tl (:,:,:) = 0.0_wp
+      rotn_tl (:,:,:) = 0.0_wp
+      hdivb_ad(:,:,:) = 0.0_wp
+      hdivn_ad(:,:,:) = 0.0_wp
+      rotb_ad (:,:,:) = 0.0_wp
+      rotn_ad (:,:,:) = 0.0_wp
+      un_ad   (:,:,:) = 0.0_wp
+      vn_ad   (:,:,:) = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znu, 'U', 0.0_wp, stdu )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 523432 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znv, 'V', 0.0_wp, stdv )
+
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zun_tlin(ji,jj,jk) = znu(ji,jj,jk) 
+               zvn_tlin(ji,jj,jk) = znv(ji,jj,jk) 
+            END DO
+         END DO
+      END DO 
+
+      un_tl(:,:,:) = zun_tlin(:,:,:)
+      vn_tl(:,:,:) = zvn_tlin(:,:,:)
+
+      CALL div_cur_tan( nit000 )  ! Generate noise for before hdiv/rot fields
+
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zhdivn_tlin(ji,jj,jk) = 0.5_wp * hdivn_tl(ji,jj,jk) 
+               zrotn_tlin (ji,jj,jk) = 0.5_wp * rotn_tl (ji,jj,jk) 
+            END DO
+         END DO
+      END DO 
+
+      un_tl   (:,:,:) = 0.0_wp
+      vn_tl   (:,:,:) = 0.0_wp
+      hdivb_tl(:,:,:) = 0.0_wp
+      hdivn_tl(:,:,:) = 0.0_wp
+      rotb_tl (:,:,:) = 0.0_wp
+      rotn_tl (:,:,:) = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Call the tangent routine: dy = L dx
+      !--------------------------------------------------------------------
+
+      un_tl   (:,:,:) = zun_tlin   (:,:,:)
+      vn_tl   (:,:,:) = zvn_tlin   (:,:,:)
+      hdivn_tl(:,:,:) = zhdivn_tlin(:,:,:)
+
+      CALL div_cur_tan( nit000 ) 
+
+      zhdivb_tlout(:,:,:) = hdivb_tl(:,:,:)
+      zhdivn_tlout(:,:,:) = hdivn_tl(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !-------------------------------------------------------------------- 
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zhdivb_adin(ji,jj,jk) = zhdivb_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk)
+              zhdivn_adin(ji,jj,jk) = zhdivn_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1_1 = DOT_PRODUCT( zhdivb_tlout, zhdivb_adin )
+      zsp1_2 = DOT_PRODUCT( zhdivn_tlout, zhdivn_adin )
+      zsp1   = zsp1_1 + zsp1_2
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      hdivb_ad(:,:,:) = zhdivb_adin(:,:,:)
+      hdivn_ad(:,:,:) = zhdivn_adin(:,:,:)
+      rotb_ad (:,:,:) = 0.0_wp
+      rotn_ad (:,:,:) = 0.0_wp
+
+      CALL div_cur_adj( nit000 )
+
+      zun_adout   (:,:,:) = un_ad   (:,:,:)
+      zvn_adout   (:,:,:) = vn_ad   (:,:,:)
+      zhdivn_adout(:,:,:) = hdivn_ad(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: dx^T L^T W dy
+      !--------------------------------------------------------------------
+
+      zsp2_1 = DOT_PRODUCT( zun_tlin,    zun_adout    )
+      zsp2_2 = DOT_PRODUCT( zvn_tlin,    zvn_adout    )
+      zsp2_3 = DOT_PRODUCT( zhdivn_tlin, zhdivn_adout )
+      zsp2   = zsp2_1 + zsp2_2 + zsp2_3
+
+      cl_name = 'div_cur_adj T1'
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      !=============================================================
+      ! 2) dx = ( un_tl, vn_tl, rotn_tl ) and 
+      !    dy = ( rotb_tl, rotn_tl )
+      !=============================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+
+      un_tl   (:,:,:) = 0.0_wp
+      vn_tl   (:,:,:) = 0.0_wp
+      hdivb_tl(:,:,:) = 0.0_wp
+      hdivn_tl(:,:,:) = 0.0_wp
+      rotb_tl (:,:,:) = 0.0_wp
+      rotn_tl (:,:,:) = 0.0_wp
+      hdivb_ad(:,:,:) = 0.0_wp
+      hdivn_ad(:,:,:) = 0.0_wp
+      rotb_ad (:,:,:) = 0.0_wp
+      rotn_ad (:,:,:) = 0.0_wp
+      un_ad   (:,:,:) = 0.0_wp
+      vn_ad   (:,:,:) = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Call the tangent routine: dy = L dx
+      !--------------------------------------------------------------------
+
+      un_tl  (:,:,:) = zun_tlin  (:,:,:)
+      vn_tl  (:,:,:) = zvn_tlin  (:,:,:)
+      rotn_tl(:,:,:) = zrotn_tlin(:,:,:)
+
+      CALL div_cur_tan( nit000 ) 
+
+      zrotb_tlout(:,:,:) = rotb_tl(:,:,:)
+      zrotn_tlout(:,:,:) = rotn_tl(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zrotb_adin(ji,jj,jk) = zrotb_tlout(ji,jj,jk) &
+                 &               * e1f(ji,jj) * e2f(ji,jj) * fse3f(ji,jj,jk)
+              zrotn_adin(ji,jj,jk) = zrotn_tlout(ji,jj,jk) &
+                 &               * e1f(ji,jj) * e2f(ji,jj) * fse3f(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1_1 = DOT_PRODUCT( zrotb_tlout, zrotb_adin )
+      zsp1_2 = DOT_PRODUCT( zrotn_tlout, zrotn_adin )
+      zsp1   = zsp1_1 + zsp1_2
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      rotb_ad (:,:,:) = zrotb_adin(:,:,:)
+      rotn_ad (:,:,:) = zrotn_adin(:,:,:)
+      hdivb_ad(:,:,:) = 0.0_wp
+      hdivn_ad(:,:,:) = 0.0_wp
+
+      CALL div_cur_adj( nit000 )
+
+      zun_adout  (:,:,:) = un_ad  (:,:,:)
+      zvn_adout  (:,:,:) = vn_ad  (:,:,:)
+      zrotn_adout(:,:,:) = rotn_ad(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: dx^T L^T W dy
+      !--------------------------------------------------------------------
+
+      zsp2_1 = DOT_PRODUCT( zun_tlin,   zun_adout   )
+      zsp2_2 = DOT_PRODUCT( zvn_tlin,   zvn_adout   )
+      zsp2_3 = DOT_PRODUCT( zrotn_tlin, zrotn_adout )
+      zsp2   = zsp2_1 + zsp2_2 + zsp2_3
+
+      cl_name = 'div_cur_adj T2'
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      !=============================================================
+      ! 3) dx = ( un_tl, vn_tl, rotn_tl, hdin_tl ) and 
+      !    dy = ( rotb_tl, rotn_tl, hdivn_tl, hdivb_tl )
+      !=============================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+
+      un_tl   (:,:,:) = 0.0_wp
+      vn_tl   (:,:,:) = 0.0_wp
+      hdivb_tl(:,:,:) = 0.0_wp
+      hdivn_tl(:,:,:) = 0.0_wp
+      rotb_tl (:,:,:) = 0.0_wp
+      rotn_tl (:,:,:) = 0.0_wp
+      hdivb_ad(:,:,:) = 0.0_wp
+      hdivn_ad(:,:,:) = 0.0_wp
+      rotb_ad (:,:,:) = 0.0_wp
+      rotn_ad (:,:,:) = 0.0_wp
+      un_ad   (:,:,:) = 0.0_wp
+      vn_ad   (:,:,:) = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Call the tangent routine: dy = L dx
+      !--------------------------------------------------------------------
+
+      un_tl  (:,:,:) = zun_tlin  (:,:,:)
+      vn_tl  (:,:,:) = zvn_tlin  (:,:,:)
+      rotn_tl(:,:,:) = zrotn_tlin(:,:,:)
+      hdivn_tl(:,:,:) = zhdivn_tlin(:,:,:)
+
+      CALL div_cur_tan( nit000 ) 
+
+      zhdivb_tlout(:,:,:) = hdivb_tl(:,:,:)
+      zhdivn_tlout(:,:,:) = hdivn_tl(:,:,:)
+      zrotb_tlout(:,:,:) = rotb_tl(:,:,:)
+      zrotn_tlout(:,:,:) = rotn_tl(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !-------------------------------------------------------------------- 
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zhdivb_adin(ji,jj,jk) = zhdivb_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk)
+              zhdivn_adin(ji,jj,jk) = zhdivn_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zrotb_adin(ji,jj,jk) = zrotb_tlout(ji,jj,jk) &
+                 &               * e1f(ji,jj) * e2f(ji,jj) * fse3f(ji,jj,jk)
+              zrotn_adin(ji,jj,jk) = zrotn_tlout(ji,jj,jk) &
+                 &               * e1f(ji,jj) * e2f(ji,jj) * fse3f(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1_1 = DOT_PRODUCT( zhdivb_tlout, zhdivb_adin )
+      zsp1_2 = DOT_PRODUCT( zhdivn_tlout, zhdivn_adin )
+      zsp1_3 = DOT_PRODUCT( zrotb_tlout, zrotb_adin )
+      zsp1_4 = DOT_PRODUCT( zrotn_tlout, zrotn_adin )
+      zsp1   = zsp1_1 + zsp1_2 + zsp1_3 + zsp1_4
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      hdivb_ad(:,:,:) = zhdivb_adin(:,:,:)
+      hdivn_ad(:,:,:) = zhdivn_adin(:,:,:)
+      rotb_ad (:,:,:) = zrotb_adin(:,:,:)
+      rotn_ad (:,:,:) = zrotn_adin(:,:,:)
+
+      CALL div_cur_adj( nit000 )
+
+      zun_adout  (:,:,:) = un_ad  (:,:,:)
+      zvn_adout  (:,:,:) = vn_ad  (:,:,:)
+      zrotn_adout(:,:,:) = rotn_ad(:,:,:)
+      zhdivn_adout(:,:,:) = hdivn_ad(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: dx^T L^T W dy
+      !--------------------------------------------------------------------
+
+      zsp2_1 = DOT_PRODUCT( zun_tlin,   zun_adout   )
+      zsp2_2 = DOT_PRODUCT( zvn_tlin,   zvn_adout   )
+      zsp2_3 = DOT_PRODUCT( zrotn_tlin, zrotn_adout )
+      zsp2_4 = DOT_PRODUCT( zhdivn_tlin, zhdivn_adout )
+      zsp2   = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4
+
+      cl_name = 'div_cur_adj T3'
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+
+      DEALLOCATE( &
+         & zun_tlin,     &
+         & zvn_tlin,     &
+         & zhdivn_tlin,  &
+         & zrotn_tlin,   &
+         & zhdivb_tlout, &
+         & zhdivn_tlout, &
+         & zrotb_tlout,  &
+         & zrotn_tlout,  &
+         & zhdivb_adin,  &
+         & zhdivn_adin,  &
+         & zrotb_adin,   &
+         & zrotn_adin,   &
+         & zun_adout,    &
+         & zvn_adout,    &
+         & zhdivn_adout, &
+         & zrotn_adout,  &
+         & znu,          &
+         & znv           &
+         & )
+
+   END SUBROUTINE div_cur_adj_tst
+#endif
+
+   !!======================================================================
+
+END MODULE divcur_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynadv_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynadv_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynadv_tam.F90	(revision 2578)
@@ -0,0 +1,969 @@
+MODULE dynadv_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                       ***  MODULE  dynadv_tam  ***
+   !! Ocean active tracers:  advection scheme control
+   !!                        Tangent and Adjoint module
+   !!==============================================================================
+   !! History of the direct module:  
+   !!           9.0  ! 2006-11  (G. Madec)  Original code
+   !! History of the TAM module:
+   !!           9.0  ! 2008-08  (A. Vidard) first version
+   !!   NEMO    3.2  ! 2010-04 (F. Vigilant) 3.2 version
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_adv      : compute the momentum advection trend 
+   !!   dyn_adv_ctl  : control the different options of advection scheme
+   !!----------------------------------------------------------------------
+   USE par_kind,       ONLY: & ! Precision variables
+      & wp
+   USE par_oce,        ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 &
+      & jpiglo   
+   USE oce,            ONLY: &
+      & un,                  &
+      & vn,                  &
+      & wn,                  &
+      & ua,                  &
+      & va
+   USE dom_oce,        ONLY: & ! ocean space and time domain
+      & umask,               &
+      & vmask,               &
+      & mig,                 &
+      & mjg,                 &
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+# if defined key_zco
+      & e3t_0,               &
+# else
+      & e3u,                 &
+      & e3v,                 &
+# endif
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE oce_tam,        ONLY: &
+      & un_tl,               &
+      & vn_tl,               &
+      & wn_tl,               &
+      & ua_tl,               &
+      & va_tl,               &
+      & un_ad,               &
+      & vn_ad,               &
+      & wn_ad,               &
+      & ua_ad,               &
+      & va_ad
+
+   USE in_out_manager, ONLY: & ! I/O manager
+      & ctl_stop,            &
+      & lwp,                 &
+      & lk_esopa,            & 
+      & numout,              & 
+      & numnam,              & 
+      & nit000,              & 
+      & nitend
+   USE gridrandom,     ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam,     ONLY: &
+      & prntst_adj,          & !
+      & prntst_tlm,          & !
+      & stdu,                & ! stdev for u-velocity
+      & stdv,                & !           v-velocity
+      & stdw                   !           w-velocity
+
+   USE dynadv,         ONLY: &
+      & dyn_adv_ctl,         &
+      & ln_dynadv_vec,       & ! vector form flag
+      & ln_dynadv_cen2,      & ! flux form - 2nd order centered scheme flag
+      & ln_dynadv_ubs          ! flux form - 3rd order UBS s
+
+!   USE dynadv_cen2_tam ! centred flux form advection      (dyn_adv_cen2 routine)
+!   USE dynadv_ubs_tam  ! UBS flux form advection          (dyn_adv_ubs  routine)
+   USE dynkeg_tam,     ONLY: & ! kinetic energy gradient          (dyn_keg      routine)
+      & dyn_keg_tan,         &
+      & dyn_keg_adj
+   USE dynzad_tam,     ONLY: & ! vertical advection               (dyn_zad    routine)  
+      & dyn_zad_tan,         &
+      & dyn_zad_adj
+   USE sshwzv_tam    , ONLY: &
+      & ssh_wzv_tan
+   USE sshwzv        , ONLY: &
+      & ssh_wzv
+   USE divcur        , ONLY: &
+      & div_cur
+   USE divcur_tam    , ONLY: &
+      & div_cur_tan
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC dyn_adv_tan     ! routine called by steptan module
+   PUBLIC dyn_adv_adj     ! routine called by stepadj module
+   PUBLIC dyn_adv_adj_tst ! routine called by the tst module
+#if defined key_tst_tlm
+   PUBLIC dyn_adv_tlm_tst ! routine called by tamtst.F90
+#endif
+ 
+   INTEGER    ::   nadv   ! choice of the formulation and scheme for the advection
+   LOGICAL    ::   lfirst=.TRUE.     
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE dyn_adv_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_adv_tan  ***
+      !!                
+      !! ** Purpose of the direct routine:
+      !!            compute the ocean momentum advection trend.
+      !!
+      !! ** Method  : - Update (ua,va) with the advection term following nadv
+      !!      NB: in flux form advection (ln_dynadv_cen2 or ln_dynadv_ubs=T) 
+      !!      a metric term is add to the coriolis term while in vector form 
+      !!      it is the relative vorticity which is added to coriolis term
+      !!      (see dynvor module).
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 )   CALL dyn_adv_ctl_tam! initialisation & control of options
+
+      SELECT CASE ( nadv )                     ! compute advection trend and add it to general trend
+      CASE ( 0 )     
+                      CALL dyn_keg_tan     ( kt )    ! vector form : horizontal gradient of kinetic energy
+                      CALL dyn_zad_tan     ( kt )    ! vector form : vertical advection
+      CASE ( 1 ) 
+         IF (lwp) WRITE(numout,*) 'dyn_adv_cen2_tan not available yet' 
+         CALL abort
+!                      CALL dyn_adv_cen2_tan( kt )    ! 2nd order centered scheme
+      CASE ( 2 )   
+         IF (lwp) WRITE(numout,*) 'dyn_adv_ubs_tan not available yet' 
+         CALL abort
+!                      CALL dyn_adv_ubs_tan ( kt )    ! 3rd order UBS      scheme
+      !
+      CASE (-1 )                                 ! esopa: test all possibility with control print
+                      CALL dyn_keg_tan     ( kt )
+                      CALL dyn_zad_tan     ( kt )
+!                      CALL dyn_adv_cen2_tan( kt )
+!                      CALL dyn_adv_ubs_tan ( kt )
+      END SELECT
+      !
+   END SUBROUTINE dyn_adv_tan
+
+   SUBROUTINE dyn_adv_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_adv_adj  ***
+      !!                
+      !! ** Purpose of the direct routine:
+      !!            compute the ocean momentum advection trend.
+      !!
+      !! ** Method  : - Update (ua,va) with the advection term following nadv
+      !!      NB: in flux form advection (ln_dynadv_cen2 or ln_dynadv_ubs=T) 
+      !!      a metric term is add to the coriolis term while in vector form 
+      !!      it is the relative vorticity which is added to coriolis term
+      !!      (see dynvor module).
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!----------------------------------------------------------------------
+      !
+      IF  ( kt == nitend ) CALL dyn_adv_ctl_tam
+
+      SELECT CASE ( nadv )                     ! compute advection trend and add it to general trend
+      CASE ( 0 )     
+                      CALL dyn_zad_adj     ( kt )    ! vector form : vertical advection
+                      CALL dyn_keg_adj     ( kt )    ! vector form : horizontal gradient of kinetic energy
+      CASE ( 1 ) 
+         IF (lwp) WRITE(numout,*) 'dyn_adv_cen2_adj not available yet' 
+         CALL abort
+!         CALL dyn_adv_cen2_adj( kt )    ! 2nd order centered scheme
+      CASE ( 2 )   
+         IF (lwp) WRITE(numout,*) 'dyn_adv_ubs_adj not available yet' 
+         CALL abort
+!                      CALL dyn_adv_ubs_adj ( kt )    ! 3rd order UBS      scheme
+      !
+      CASE (-1 )                                 ! esopa: test all possibility with control print
+!                      CALL dyn_adv_ubs_adj ( kt )
+!                      CALL dyn_adv_cen2_adj( kt )
+                      CALL dyn_zad_adj     ( kt )
+                      CALL dyn_keg_adj     ( kt )
+      END SELECT
+      !
+   END SUBROUTINE dyn_adv_adj
+
+   SUBROUTINE dyn_adv_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_adv_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk,    &
+         & jt
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zun_tlin,     & ! Tangent input:  now  u-velocity
+         & zvn_tlin,     & ! Tangent input:  now  v-velocity
+         & zwn_tlin,     & ! Tangent input:  now  w-velocity
+         & zua_tlin,     & ! Tangent input: after u-velocity
+         & zva_tlin,     & ! Tangent input: after u-velocity         
+         & zua_tlout,    & ! Tangent output:after u-velocity
+         & zva_tlout,    & ! Tangent output:after v-velocity
+         & zua_adin,     & ! adjoint input: after u-velocity
+         & zva_adin,     & ! adjoint input: after v-velocity
+         & zun_adout,    & ! adjoint output: now  u-velocity
+         & zvn_adout,    & ! adjoint output: now  v-velocity
+         & zwn_adout,    & ! adjoint output: now  u-velocity
+         & zua_adout,    & ! adjoint output:after v-velocity
+         & zva_adout,    & ! adjoint output:after u-velocity
+         & zuvw            ! 3D random field for u, v and w
+
+      REAL(KIND=wp) ::   &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_1,       & !   scalar product components
+         & zsp1_2,       & 
+         & zsp2,         & ! scalar product involving the adjoint routine
+         & zsp2_1,       & !   scalar product components
+         & zsp2_2,       & 
+         & zsp2_3,       & 
+         & zsp2_4,       & 
+         & zsp2_5
+
+      CHARACTER(LEN=14) :: cl_name
+
+
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zun_tlin(jpi,jpj,jpk),     &
+         & zvn_tlin(jpi,jpj,jpk),     &
+         & zwn_tlin(jpi,jpj,jpk),     &
+         & zua_tlin(jpi,jpj,jpk),     &
+         & zva_tlin(jpi,jpj,jpk),     &
+         & zua_tlout(jpi,jpj,jpk),    &
+         & zva_tlout(jpi,jpj,jpk),    &
+         & zua_adin(jpi,jpj,jpk),     &
+         & zva_adin(jpi,jpj,jpk),     &
+         & zun_adout(jpi,jpj,jpk),    &
+         & zvn_adout(jpi,jpj,jpk),    &
+         & zwn_adout(jpi,jpj,jpk),    &
+         & zua_adout(jpi,jpj,jpk),    &
+         & zva_adout(jpi,jpj,jpk),    &
+         & zuvw(jpi,jpj,jpk)           & 
+         & )
+
+
+      !===================================================================================
+      ! 1)  dx = ( un_tl, vn_tl, ua_tl, va_tl )        --> dynkeg
+      ! and dy = ( ua_tl, va_tl ) 
+      ! 2)  dx = ( un_tl, vn_tl, wn_tl, ua_tl, va_tl ) --> dynkeg
+      ! and dy = ( ua_tl, va_tl ) 
+      ! 3)  dx = ( un_tl, vn_tl, wn_tl, ua_tl, va_tl ) --> dynadv
+      ! and dy = ( ua_tl, va_tl )
+      !======================================================================
+
+      DO jt = 1, 3
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+          zun_tlin(:,:,:)  = 0.0_wp
+          zvn_tlin(:,:,:)  = 0.0_wp
+          zwn_tlin(:,:,:)  = 0.0_wp
+          zua_tlin(:,:,:)  = 0.0_wp
+          zva_tlin(:,:,:)  = 0.0_wp
+          zua_tlout(:,:,:) = 0.0_wp
+          zva_tlout(:,:,:) = 0.0_wp
+          zua_adin(:,:,:)  = 0.0_wp
+          zva_adin(:,:,:)  = 0.0_wp
+          zun_adout(:,:,:) = 0.0_wp
+          zvn_adout(:,:,:) = 0.0_wp
+          zwn_adout(:,:,:) = 0.0_wp
+          zua_adout(:,:,:) = 0.0_wp
+          zva_adout(:,:,:) = 0.0_wp
+          zuvw(:,:,:)      = 0.0_wp
+
+          un_tl(:,:,:) = 0.0_wp
+          vn_tl(:,:,:) = 0.0_wp
+          wn_tl(:,:,:) = 0.0_wp
+          ua_tl(:,:,:) = 0.0_wp
+          va_tl(:,:,:) = 0.0_wp
+          un_ad(:,:,:) = 0.0_wp
+          vn_ad(:,:,:) = 0.0_wp
+          wn_ad(:,:,:) = 0.0_wp
+          ua_ad(:,:,:) = 0.0_wp
+          va_ad(:,:,:) = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+          DO jj = 1, jpj
+             DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 596035 + &
+                  &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zuvw, 'U', 0.0_wp, stdu )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zun_tlin(ji,jj,jk) = zuvw(ji,jj,jk) 
+               END DO
+            END DO
+         END DO
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 523432 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zuvw, 'V', 0.0_wp, stdv )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zvn_tlin(ji,jj,jk) = zuvw(ji,jj,jk) 
+               END DO
+            END DO
+         END DO
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 456953 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zuvw, 'W', 0.0_wp, stdw )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zwn_tlin(ji,jj,jk) = zuvw(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 432545 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zuvw, 'U', 0.0_wp, stdu )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zua_tlin(ji,jj,jk) = zuvw(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 287503 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zuvw, 'V', 0.0_wp, stdv )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zva_tlin(ji,jj,jk) = zuvw(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         un_tl(:,:,:) = zun_tlin(:,:,:)
+         vn_tl(:,:,:) = zvn_tlin(:,:,:)
+
+         wn_tl(:,:,:) = zwn_tlin(:,:,:)
+         ua_tl(:,:,:) = zua_tlin(:,:,:)
+         va_tl(:,:,:) = zva_tlin(:,:,:)
+
+         SELECT CASE ( jt )
+         CASE ( 1 ) 
+            CALL dyn_adv_ctl_tam
+            CALL dyn_keg_tan( nit000 )
+         CASE ( 2 ) 
+            CALL dyn_adv_ctl_tam
+            CALL dyn_zad_tan( nit000 )
+         CASE ( 3 ) 
+            CALL dyn_adv_tan ( nit000 )
+         END SELECT
+
+         zua_tlout(:,:,:) = ua_tl(:,:,:)
+         zva_tlout(:,:,:) = va_tl(:,:,:)
+
+         !--------------------------------------------------------------------
+         ! Initialize the adjoint variables: dy^* = W dy
+         !--------------------------------------------------------------------
+
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zua_adin(ji,jj,jk) = zua_tlout(ji,jj,jk) &
+                       &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                       &               * umask(ji,jj,jk) 
+                  zva_adin(ji,jj,jk) = zva_tlout(ji,jj,jk) &
+                       &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+                       &               * vmask(ji,jj,jk) 
+               END DO
+            END DO
+         END DO
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !--------------------------------------------------------------------
+         
+         zsp1_1 = DOT_PRODUCT( zua_tlout, zua_adin )
+         zsp1_2 = DOT_PRODUCT( zva_tlout, zva_adin )
+         zsp1   = zsp1_1 + zsp1_2
+         
+         !--------------------------------------------------------------------
+         ! Call the adjoint routine: dx^* = L^T dy^*
+         !--------------------------------------------------------------------
+
+         ua_ad(:,:,:) = zua_adin(:,:,:)
+         va_ad(:,:,:) = zva_adin(:,:,:)
+
+         SELECT CASE ( jt )
+         CASE ( 1 ) 
+            CALL dyn_keg_adj( nitend )
+         CASE ( 2 )
+            CALL dyn_zad_adj( nitend )
+         CASE ( 3 ) 
+            CALL dyn_adv_adj ( nitend )
+         END SELECT
+
+         zun_adout(:,:,:) = un_ad(:,:,:)
+         zvn_adout(:,:,:) = vn_ad(:,:,:)
+         zwn_adout(:,:,:) = wn_ad(:,:,:)
+         zua_adout(:,:,:) = ua_ad(:,:,:)
+         zva_adout(:,:,:) = va_ad(:,:,:)
+         
+         zsp2_1 = DOT_PRODUCT( zun_tlin, zun_adout )
+         zsp2_2 = DOT_PRODUCT( zvn_tlin, zvn_adout )
+         IF (jt .EQ. 1) THEN
+            zsp2_3 = 0.0_wp
+         ELSE
+            zsp2_3 = DOT_PRODUCT( zwn_tlin, zwn_adout )
+         ENDIF
+         zsp2_4 = DOT_PRODUCT( zua_tlin, zua_adout )
+         zsp2_5 = DOT_PRODUCT( zva_tlin, zva_adout )
+         zsp2   = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4 + zsp2_5
+
+         ! Compare the scalar products
+
+         SELECT CASE ( jt )
+         CASE ( 1 ) 
+            cl_name = 'dyn_keg_adj   '
+         CASE ( 2 ) 
+            cl_name = 'dyn_zad_adj   '
+         CASE ( 3 ) 
+            cl_name = 'dyn_adv_adj   '
+         END SELECT
+
+         CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      ENDDO
+
+      DEALLOCATE( &
+         & zun_tlin,     &
+         & zvn_tlin,     &
+         & zwn_tlin,     &
+         & zua_tlin,     &
+         & zva_tlin,     &
+         & zua_tlout,    &
+         & zva_tlout,    &
+         & zua_adin,     &
+         & zva_adin,     &
+         & zun_adout,    &
+         & zvn_adout,    &
+         & zwn_adout,    &
+         & zua_adout,    &
+         & zva_adout,    &
+         & zuvw          & 
+         & )
+
+   END SUBROUTINE dyn_adv_adj_tst
+  !!======================================================================
+   SUBROUTINE dyn_adv_ctl_tam
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_adv_ctl  ***
+      !!                
+      !! ** Purpose :   Control the consistency between namelist options for 
+      !!              momentum advection formulation & scheme and set nadv
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio
+
+      NAMELIST/namdyn_adv/ ln_dynadv_vec, ln_dynadv_cen2 , ln_dynadv_ubs
+      !!----------------------------------------------------------------------
+      
+      IF (lfirst) THEN
+
+         REWIND ( numnam )               ! Read Namelist namdyn_adv : momentum advection scheme
+         READ   ( numnam, namdyn_adv )
+
+         IF(lwp) THEN                    ! Namelist print
+            WRITE(numout,*)
+            WRITE(numout,*) 'dyn_adv_ctl : choice/control of the momentum advection scheme'
+            WRITE(numout,*) '~~~~~~~~~~~'
+            WRITE(numout,*) '       Namelist namdyn_adv : chose a advection formulation & scheme for momentum'
+            WRITE(numout,*) '          Vector/flux form (T/F)             ln_dynadv_vec  = ', ln_dynadv_vec
+            WRITE(numout,*) '          2nd order centred advection scheme ln_dynadv_cen2 = ', ln_dynadv_cen2
+            WRITE(numout,*) '          3rd order UBS advection scheme     ln_dynadv_ubs  = ', ln_dynadv_ubs
+         ENDIF
+
+         ioptio = 0                      ! Parameter control
+         IF( ln_dynadv_vec  )   ioptio = ioptio + 1
+         IF( ln_dynadv_cen2 )   ioptio = ioptio + 1
+         IF( ln_dynadv_ubs  )   ioptio = ioptio + 1
+         IF( lk_esopa       )   ioptio =          1
+
+         IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE advection scheme in namelist namdyn_adv' )
+
+      !                               ! Set nadv
+         IF( ln_dynadv_vec  )   nadv =  0 
+         IF( ln_dynadv_cen2 )   nadv =  1
+         IF( ln_dynadv_ubs  )   nadv =  2
+         IF( lk_esopa       )   nadv = -1
+
+         IF(lwp) THEN                    ! Print the choice
+            WRITE(numout,*)
+            IF( nadv ==  0 )   WRITE(numout,*) '         vector form : keg + zad + vor is used'
+            IF( nadv ==  1 )   WRITE(numout,*) '         flux form   : 2nd order scheme is used'
+            IF( nadv ==  2 )   WRITE(numout,*) '         flux form   : UBS       scheme is used'
+            IF( nadv == -1 )   WRITE(numout,*) '         esopa test: use all advection formulation'
+         ENDIF
+         !
+         lfirst = .FALSE.
+      END IF
+   END SUBROUTINE dyn_adv_ctl_tam
+#if defined key_tst_tlm
+   SUBROUTINE dyn_adv_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_adv_tlm_tst ***
+      !!
+      !! ** Purpose : Test the adjoint 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 :
+      !!        ! 09-08 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE dynadv
+      USE tamtrj              ! writing out state trajectory
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE divcur             ! horizontal divergence and relative vorticity
+      USE sshwzv             !  vertical velocity
+      USE gridrandom, ONLY: &
+        & grid_rd_sd
+      USE trj_tam
+      USE oce           , ONLY: & ! ocean dynamics and tracers variables
+         & ua, va
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER :: &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zun_tlin,     & ! Tangent input:  now  u-velocity
+         & zvn_tlin,     & ! Tangent input:  now  v-velocity
+         & zwn_tlin,     & ! Tangent input:  now  w-velocity
+         & zua_tlin,     & ! Tangent input: after u-velocity
+         & zva_tlin,     & ! Tangent input: after u-velocity         
+         & zua_out,      & ! Tangent output:after u-velocity
+         & zva_out,      & ! Tangent output:after v-velocity
+         & zua_wop,      & ! Tangent output:after u-velocity
+         & zva_wop,      & ! Tangent output:after v-velocity
+         & z3r             ! 3D field
+
+      REAL(KIND=wp) ::   &
+         & zsp1,         & ! scalar product
+         & zsp1_1,       & ! scalar product 
+         & zsp1_2,       & 
+         & zsp2,         & ! scalar product
+         & zsp2_1,       & ! scalar product 
+         & zsp2_2,       & 
+         & zsp3,         & ! scalar product
+         & zsp3_1,       & ! scalar product 
+         & zsp3_2,       & 
+         & zsp2_3,       & 
+         & zsp2_4,       & 
+         & zzsp,         &
+         & zzsp_1,       &
+         & zzsp_2,       &
+         & gamma,            &
+         & zgsp1,            &
+         & zgsp2,            &
+         & zgsp3,            &
+         & zgsp4,            &
+         & zgsp5,            &
+         & zgsp6,            &
+         & zgsp7
+
+      CHARACTER(LEN=14)   :: cl_name
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
+      CHARACTER (LEN=90)  ::  FMT
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zscua, zscva,    &
+         & zscerrua,        &
+         & zscerrva
+      INTEGER, DIMENSION(100):: &
+         & iiposua, iiposva,    &
+         & ijposua, ijposva,    & 
+         & ikposua, ikposva
+      INTEGER::             &
+         & ii,              &
+         & isamp=40,        &
+         & jsamp=40,        &
+         & ksamp=10,        &
+         & numsctlm
+     REAL(KIND=wp), DIMENSION(jpi,jpj,jpk) :: &
+         & zerrua, zerrva  
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zun_tlin(jpi,jpj,jpk),     &
+         & zvn_tlin(jpi,jpj,jpk),     &
+         & zwn_tlin(jpi,jpj,jpk),     &
+         & zua_tlin(jpi,jpj,jpk),     &
+         & zva_tlin(jpi,jpj,jpk),     &
+         & zua_out(jpi,jpj,jpk),      &
+         & zva_out(jpi,jpj,jpk),      &
+         & zua_wop(jpi,jpj,jpk),      &
+         & zva_wop(jpi,jpj,jpk),      &
+         & z3r    (jpi,jpj,jpk)       &
+         & )
+
+      !--------------------------------------------------------------------
+      ! Reset variables
+      !--------------------------------------------------------------------
+      zun_tlin( :,:,:) = 0.0_wp
+      zvn_tlin( :,:,:) = 0.0_wp
+      zwn_tlin( :,:,:) = 0.0_wp
+      zua_tlin( :,:,:) = 0.0_wp
+      zva_tlin( :,:,:) = 0.0_wp
+      zua_out ( :,:,:) = 0.0_wp
+      zva_out ( :,:,:) = 0.0_wp
+      zua_wop ( :,:,:) = 0.0_wp
+      zva_wop ( :,:,:) = 0.0_wp
+
+      zscua(:)         = 0.0_wp
+      zscva(:)         = 0.0_wp
+      zscerrua(:)      = 0.0_wp
+      zscerrva(:)      = 0.0_wp
+      zerrua(:,:,:)    = 0.0_wp
+      zerrva(:,:,:)    = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Output filename Xn=F(X0)
+      !--------------------------------------------------------------------
+!!      CALL tlm_namrd
+      gamma = h_ratio
+      file_wop='trj_wop_dynadv'
+      file_xdx='trj_xdx_dynadv'
+      !--------------------------------------------------------------------
+      ! 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, z3r,  'U', 0.0_wp, stdu)
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zun_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      CALL grid_rd_sd( 523432, z3r,  'V', 0.0_wp, stdv)
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zvn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      CALL grid_rd_sd( 432545, z3r,  'U', 0.0_wp, stdu)
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zua_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      CALL grid_rd_sd( 287503, z3r,  'V', 0.0_wp, stdv) 
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zva_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      ENDIF    
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      IF ( tlm_bch /= 2 )      CALL istate_p  
+
+      ! *** initialize the reference trajectory
+      ! ------------
+      CALL  trj_rea( nit000-1, 1 )
+      CALL  trj_rea( nit000, 1 )
+      ua(:,:,:)       = un(:,:,:)
+      va(:,:,:)       = vn(:,:,:)
+
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         zun_tlin(:,:,:) = gamma * zun_tlin(:,:,:)
+         un(:,:,:)       = un(:,:,:) + zun_tlin(:,:,:)
+
+         zvn_tlin(:,:,:) = gamma * zvn_tlin(:,:,:)
+         vn(:,:,:)       = vn(:,:,:) + zvn_tlin(:,:,:)
+
+         zua_tlin(:,:,:) = gamma * zua_tlin(:,:,:)
+         ua(:,:,:)       = ua(:,:,:) + zua_tlin(:,:,:)
+
+         zva_tlin(:,:,:) = gamma * zva_tlin(:,:,:)
+         va(:,:,:)       = va(:,:,:) + zva_tlin(:,:,:)
+         !recompute wn from un and vn
+         CALL div_cur( nit000)
+         CALL ssh_wzv( nit000, 1)
+      ENDIF 
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------
+      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 ( tlm_bch == 2 ) THEN        
+         !--------------------------------------------------------------------
+         ! Initialize the tangent variables 
+         !--------------------------------------------------------------------
+         CALL  trj_rea( nit000-1, 1 ) 
+         CALL  trj_rea( nit000, 1 ) 
+         ua(:,:,:)       = un(:,:,:)
+         va(:,:,:)       = vn(:,:,:)
+         un_tl  (:,:,:) = zun_tlin  (:,:,:)
+         vn_tl  (:,:,:) = zvn_tlin  (:,:,:)
+         !recompute wn_tl from un_tl and vn_tl
+         CALL div_cur_tan( nit000 )
+         CALL ssh_wzv_tan( nit000 )
+         ua_tl  (:,:,:) = zua_tlin  (:,:,:)
+         va_tl  (:,:,:) = zva_tlin  (:,:,:)
+ 
+         CALL dyn_adv_tan(nit000)
+
+         !--------------------------------------------------------------------
+         ! 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  )
+
+         zsp2      = zsp2_1 + zsp2_2
+         !--------------------------------------------------------------------
+         !  Storing data
+         !--------------------------------------------------------------------
+         CALL trj_rd_spl(file_wop) 
+         zua_wop  (:,:,:) = ua  (:,:,:)
+         zva_wop  (:,:,:) = va  (:,:,:)
+         CALL trj_rd_spl(file_xdx) 
+         zua_out  (:,:,:) = ua  (:,:,:)
+         zva_out  (:,:,:) = va  (:,:,:)
+         !--------------------------------------------------------------------
+         ! 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 jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zua_out   (ji,jj,jk) = zua_out    (ji,jj,jk) - zua_wop  (ji,jj,jk)
+                  zua_wop   (ji,jj,jk) = zua_out    (ji,jj,jk) - ua_tl    (ji,jj,jk)
+                  IF (  ua_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrua(ji,jj,jk) = zua_out(ji,jj,jk)/ua_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposua(ii) = ji
+                      ijposua(ii) = jj
+                      ikposua(ii) = jk
+                      IF ( INT(umask(ji,jj,jk)) .NE. 0)  THEN
+                         zscua (ii) =  zua_wop(ji,jj,jk)
+                         zscerrua (ii) =  ( zerrua(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         ii=0
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zva_out   (ji,jj,jk) = zva_out    (ji,jj,jk) - zva_wop  (ji,jj,jk)
+                  zva_wop   (ji,jj,jk) = zva_out    (ji,jj,jk) - va_tl    (ji,jj,jk)
+                  IF (  va_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrva(ji,jj,jk) = zva_out(ji,jj,jk)/va_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposva(ii) = ji
+                      ijposva(ii) = jj
+                      ikposva(ii) = jk
+                      IF ( INT(vmask(ji,jj,jk)) .NE. 0)  THEN
+                         zscva (ii) =  zua_wop(ji,jj,jk)
+                         zscerrva (ii) =  ( zerrva(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+
+         zsp1_1    = DOT_PRODUCT( zua_out, zua_out )
+         zsp1_2    = DOT_PRODUCT( zva_out, zva_out  )
+         zsp1      = zsp1_1 + zsp1_2
+
+         zsp3_1    = DOT_PRODUCT( zua_wop, zua_wop )
+         zsp3_2    = DOT_PRODUCT( zva_wop, zva_wop  )
+         zsp3      = zsp3_1 + zsp3_2
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name  = 'dynadv_tam:En '
+         zzsp     = SQRT(zsp3)
+         zzsp_1   = SQRT(zsp3_1)
+         zzsp_2   = SQRT(zsp3_2)
+         zgsp5    = zzsp
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp     = SQRT(zsp2)
+         zzsp_1   = SQRT(zsp2_1)
+         zzsp_2   = SQRT(zsp2_2)
+         zgsp4    = zzsp
+         cl_name  = 'dynadv_tam:Ln2'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         zzsp     = SQRT(zsp1)
+         zzsp_1   = SQRT(zsp1_1)
+         zzsp_2   = SQRT(zsp1_2)
+         cl_name  = 'dynadv:Mhdx-Mx'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         zgsp3    = SQRT( zsp3/zsp2 )
+         zgsp7    = zgsp3/gamma
+         zgsp1    = zzsp
+         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) 'dynadv  ', 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 = 'dynadv  '
+         IF (lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zscua(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscua     ', &
+                    & cur_loop, h_ratio, ii, iiposua(ii), ijposua(ii), zscua(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscva(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscva     ', &
+                    & cur_loop, h_ratio, ii, iiposva(ii), ijposva(ii), zscva(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrua(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrua  ', &
+                 & cur_loop, h_ratio, ii, iiposua(ii), ijposua(ii), zscerrua(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrva(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrva  ', &
+                    & cur_loop, h_ratio, ii, iiposva(ii), ijposva(ii), zscerrva(ii)
+            ENDDO
+      ! write separator
+      WRITE(numtan_sc,"(A4)") '===='
+         ENDIF
+      ENDIF
+      DEALLOCATE(                           &
+         & zun_tlin, zvn_tlin, zwn_tlin,    & 
+         & zua_tlin, zva_tlin,              & 
+         & zua_out, zva_out,                & 
+         & zua_wop, zva_wop,                &
+         & z3r                              &
+         & )
+   END SUBROUTINE dyn_adv_tlm_tst
+#endif
+#endif
+END MODULE dynadv_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynbfr_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynbfr_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynbfr_tam.F90	(revision 2578)
@@ -0,0 +1,436 @@
+MODULE dynbfr_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                 ***  MODULE  dynbfr  ***
+   !! Ocean dynamics :  bottom friction component of the momentum mixing trend
+   !!==============================================================================
+   !! History of the drect module:
+   !!            9.0  !  2008-11  (A. C. Coward)  Original code
+   !! History of the TAM module:
+   !!  NEMO      3.2  ! 2010-04 (F. Vigilant) Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_bfr      : Update the momentum trend with the bottom friction contribution
+   !!----------------------------------------------------------------------
+   USE par_kind,  ONLY: & ! Precision variables
+      & wp
+   USE oce_tam       , ONLY: &
+      & ub_tl,         &
+      & vb_tl,         &
+      & ua_tl,         &
+      & va_tl,         &
+      & ub_ad,         &
+      & vb_ad,         &
+      & ua_ad,         &
+      & va_ad
+   USE par_oce,   ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 &
+      & jpk,                 &
+      & jpiglo,              &
+      & jpij,                &  
+      & jpim1,               &
+      & jpjm1
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+     & mbathy,         &
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+#if defined key_zco
+      & e3t_0,         &
+#else
+      & e3u,           &
+      & e3v,           &
+#endif
+      & rdt,                 &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      & umask,               &
+      & vmask
+   USE zdf_oce         ! ocean vertical physics variables
+   USE zdfbfr,    ONLY:&          ! bottom friction
+      & bfrua,         &
+      & bfrva  
+   USE in_out_manager, ONLY: & ! I/O manager
+      & numnam,              &
+      & numout,              &
+      & nit000,              &
+      & nitend,              &
+      & lwp
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          & !
+                               ! random field standard deviation for:
+      & stdu,                & !   u-velocity
+      & stdv                   !   v-velocity
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_bfr_tan     ! routine called by step_tam.F90
+   PUBLIC   dyn_bfr_adj     ! routine called by step_tam.F90
+   PUBLIC   dyn_bfr_adj_tst ! routine called by the tst.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "zdfddm_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+   
+   SUBROUTINE dyn_bfr_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_bfr_tan  ***
+      !!
+      !! ** Purpose of direct routine:
+      !!                compute the bottom friction ocean dynamics physics.
+      !!
+      !! ** Action  :   (ua,va)   momentum trend increased by bottom friction trend
+      !!---------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !! 
+      INTEGER  ::   ji, jj          ! dummy loop indexes
+      INTEGER  ::   ikbu  , ikbv    ! temporary integers
+      INTEGER  ::   ikbum1, ikbvm1  !    -          -
+      REAL(wp) ::   zinv, zbfru, zbfrv   ! temporary scalar
+      !!---------------------------------------------------------------------
+      !
+      zinv = -1. / ( 2.*rdt )
+
+# if defined key_vectopt_loop
+      DO jj = 1, 1
+         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+# endif
+            ikbu = MIN( mbathy(ji+1,jj), mbathy(ji,jj) )
+            ikbv = MIN( mbathy(ji,jj+1), mbathy(ji,jj) )
+            ikbum1 = MAX( ikbu-1, 1 )
+            ikbvm1 = MAX( ikbv-1, 1 )
+            !
+            ! Apply stability criteria on absolute value  : Min abs(bfr) => Max (bfr)
+            zbfru = MAX( bfrua(ji,jj), fse3u(ji,jj,ikbum1)*zinv )
+            zbfrv = MAX( bfrva(ji,jj), fse3v(ji,jj,ikbvm1)*zinv )
+            !
+            ua_tl(ji,jj,ikbum1) = ua_tl(ji,jj,ikbum1) + zbfru * ub_tl(ji,jj,ikbum1) / fse3u(ji,jj,ikbum1)
+            va_tl(ji,jj,ikbvm1) = va_tl(ji,jj,ikbvm1) + zbfrv * vb_tl(ji,jj,ikbvm1) / fse3v(ji,jj,ikbvm1)
+            !
+         END DO
+      END DO
+      !
+   END SUBROUTINE dyn_bfr_tan
+
+   SUBROUTINE dyn_bfr_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_bfr_adj  ***
+      !!
+      !! ** Purpose of direct routine:
+      !!                compute the bottom friction ocean dynamics physics.
+      !!
+      !! ** Action  :   (ua,va)   momentum trend increased by bottom friction trend
+      !!---------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !! 
+      INTEGER  ::   ji, jj          ! dummy loop indexes
+      INTEGER  ::   ikbu  , ikbv    ! temporary integers
+      INTEGER  ::   ikbum1, ikbvm1  !    -          -
+      REAL(wp) ::   zinv, zbfru, zbfrv   ! temporary scalar
+      !!---------------------------------------------------------------------
+      !
+      zinv = -1. / ( 2.*rdt )
+
+# if defined key_vectopt_loop
+      DO jj = 1, 1
+         DO ji = jpij-jpj-1, jpi+2, -1   ! vector opt. (forced unrolling)
+# else
+      DO jj = jpjm1, 2, -1
+         DO ji = jpim1, 2, -1
+# endif
+            ikbu = MIN( mbathy(ji+1,jj), mbathy(ji,jj) )
+            ikbv = MIN( mbathy(ji,jj+1), mbathy(ji,jj) )
+            ikbum1 = MAX( ikbu-1, 1 )
+            ikbvm1 = MAX( ikbv-1, 1 )
+            !
+            ! Apply stability criteria on absolute value  : Min abs(bfr) => Max (bfr)
+            zbfru = MAX( bfrua(ji,jj), fse3u(ji,jj,ikbum1)*zinv )
+            zbfrv = MAX( bfrva(ji,jj), fse3v(ji,jj,ikbvm1)*zinv )
+            !
+            ub_ad(ji,jj,ikbum1) = ub_ad(ji,jj,ikbum1) + zbfru * ua_ad(ji,jj,ikbum1) / fse3u(ji,jj,ikbum1)
+            vb_ad(ji,jj,ikbvm1) = vb_ad(ji,jj,ikbvm1) + zbfrv * va_ad(ji,jj,ikbvm1) / fse3v(ji,jj,ikbvm1)
+            !
+         END DO
+      END DO
+      !
+   END SUBROUTINE dyn_bfr_adj
+
+   SUBROUTINE dyn_bfr_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_bfr_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : 
+      !!                
+      !! History :
+      !!        ! 2010-04 (F. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt        ! Output unit
+
+      !! * Local declarations
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zua_tlin,    & ! Tangent input: ua_tl
+         & zva_tlin,    & ! Tangent input: va_tl
+         & zub_tlin,    & ! Tangent input: ub_tl
+         & zvb_tlin,    & ! Tangent input: vb_tl
+         & zua_tlout,   & ! Tangent output: ua_tl
+         & zva_tlout,   & ! Tangent output: va_tl
+         & zua_adin,    & ! Adjoint input: ua_ad
+         & zva_adin,    & ! Adjoint input: va_ad
+         & zua_adout,   & ! Adjoint output: ua_ad
+         & zva_adout,   & ! Adjoint output: va_ad
+         & zub_adout,   & ! Adjoint oputput: ub_ad
+         & zvb_adout,   & ! Adjoint output: vb_ad
+         & znu            ! 3D random field for u
+      REAL(wp) :: &
+         & zsp1,    &   ! scalar product involving the tangent routine
+         & zsp2         ! scalar product involving the adjoint routine
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d    ! 2D seed for the random number generator
+      INTEGER :: &
+         & ji, &
+         & jj, &
+         & jk
+      CHARACTER (LEN=14) :: &
+         & cl_name
+
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zua_tlin(jpi,jpj,jpk),  &
+         & zva_tlin(jpi,jpj,jpk),  &
+         & zub_tlin(jpi,jpj,jpk),  &
+         & zvb_tlin(jpi,jpj,jpk),  &
+         & zua_tlout(jpi,jpj,jpk), &
+         & zva_tlout(jpi,jpj,jpk), &
+         & zua_adin(jpi,jpj,jpk),  &
+         & zva_adin(jpi,jpj,jpk),  &
+         & zua_adout(jpi,jpj,jpk), &
+         & zva_adout(jpi,jpj,jpk), &
+         & zub_adout(jpi,jpj,jpk), &
+         & zvb_adout(jpi,jpj,jpk), &
+         & znu(jpi,jpj,jpk)        &
+         & )
+
+      !=========================================================================
+      !     dx = ( ub_tl, ua_tl, vb_tl, va_tl )
+      ! and dy = ( ua_tl, va_tl )
+      !=========================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+
+      zub_tlin (:,:,:) = 0.0_wp
+      zvb_tlin (:,:,:) = 0.0_wp
+      zua_tlin (:,:,:) = 0.0_wp
+      zva_tlin (:,:,:) = 0.0_wp
+      zua_tlout(:,:,:) = 0.0_wp
+      zva_tlout(:,:,:) = 0.0_wp
+      zua_adin (:,:,:) = 0.0_wp
+      zva_adin (:,:,:) = 0.0_wp
+      zub_adout(:,:,:) = 0.0_wp
+      zvb_adout(:,:,:) = 0.0_wp
+      zua_adout(:,:,:) = 0.0_wp
+      zva_adout(:,:,:) = 0.0_wp
+
+      ub_tl(:,:,:) = 0.0_wp
+      vb_tl(:,:,:) = 0.0_wp
+      ua_tl(:,:,:) = 0.0_wp
+      va_tl(:,:,:) = 0.0_wp
+      ub_ad(:,:,:) = 0.0_wp
+      vb_ad(:,:,:) = 0.0_wp
+      ua_ad(:,:,:) = 0.0_wp
+      va_ad(:,:,:) = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 456953 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znu, 'U', 0.0_wp, stdu )
+
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zua_tlin(ji,jj,jk) = znu(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 3434334 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znu, 'V', 0.0_wp, stdv )
+
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+              zva_tlin(ji,jj,jk) = znu(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 935678 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znu, 'U', 0.0_wp, stdu )
+
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+             zub_tlin(ji,jj,jk) = znu(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 1462578 + &
+              &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znu, 'V', 0.0_wp, stdv )
+
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+             zvb_tlin(ji,jj,jk) = znu(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Call the tangent routine: dy = L dx
+      !--------------------------------------------------------------------
+
+      ua_tl(:,:,:) = zua_tlin(:,:,:)
+      va_tl(:,:,:) = zva_tlin(:,:,:)
+      ub_tl(:,:,:) = zub_tlin(:,:,:)
+      vb_tl(:,:,:) = zvb_tlin(:,:,:)
+
+      CALL dyn_bfr_tan( nit000 )
+
+      zua_tlout(:,:,:) = ua_tl(:,:,:)
+      zva_tlout(:,:,:) = va_tl(:,:,:)
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zua_adin(ji,jj,jk) = zua_tlout(ji,jj,jk) &
+                 &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                 &               * umask(ji,jj,jk)
+              zva_adin(ji,jj,jk) = zva_tlout(ji,jj,jk) &
+                 &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+                 &               * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1 =   DOT_PRODUCT( zua_tlout  , zua_adin   ) + DOT_PRODUCT( zva_tlout  , zva_adin   ) 
+
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      ua_ad(:,:,:) = zua_adin(:,:,:)
+      va_ad(:,:,:) = zva_adin(:,:,:)
+
+      CALL dyn_bfr_adj( nit000 )
+
+      zua_adout(:,:,:) = ua_ad(:,:,:) 
+      zva_adout(:,:,:) = va_ad(:,:,:)
+      zub_adout(:,:,:) = ub_ad(:,:,:) 
+      zvb_adout(:,:,:) = vb_ad(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: dx^T L^T W dy
+      !--------------------------------------------------------------------
+
+      zsp2 =   DOT_PRODUCT( zua_tlin  , zua_adout   ) &
+            &   + DOT_PRODUCT( zva_tlin  , zva_adout   ) &
+            &   + DOT_PRODUCT( zub_tlin  , zub_adout   ) &
+            &   + DOT_PRODUCT( zvb_tlin  , zvb_adout   )
+
+      ! Compare the scalar products
+
+      ! 14 char:'12345678901234'
+      cl_name = 'dyn_bfr_adj   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      ! Deallocate memory
+
+      DEALLOCATE( &
+         & zua_tlin,  &
+         & zva_tlin,  &
+         & zub_tlin,  &
+         & zvb_tlin,  &
+         & zua_tlout, &
+         & zva_tlout, &
+         & zua_adin,  &
+         & zva_adin,  &
+         & zua_adout, &
+         & zva_adout, &
+         & zub_adout, &
+         & zvb_adout, &
+         & znu        &
+         & )
+
+   END SUBROUTINE dyn_bfr_adj_tst
+   !!==============================================================================
+#endif
+END MODULE dynbfr_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynhpg_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynhpg_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynhpg_tam.F90	(revision 2578)
@@ -0,0 +1,1446 @@
+MODULE dynhpg_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  dynhpg_tam  ***
+   !! Ocean dynamics:  hydrostatic pressure gradient trend
+   !!                  Tangent and Adjoint module
+   !!======================================================================
+   !! History of the direct module:
+   !!            1.0  !  87-09  (P. Andrich, M.-A. Foujols)  hpg_zco: Original code
+   !!            5.0  !  91-11  (G. Madec)
+   !!            7.0  !  96-01  (G. Madec)  hpg_sco: Original code for s-coordinates
+   !!            8.0  !  97-05  (G. Madec)  split dynber into dynkeg and dynhpg
+   !!            8.5  !  02-07  (G. Madec)  F90: Free form and module
+   !!            8.5  !  02-08  (A. Bozec)  hpg_zps: Original code
+   !!            9.0  !  05-10  (A. Beckmann, B.W. An)  various s-coordinate options
+   !!                           Original code for hpg_ctl, hpg_hel hpg_wdj, hpg_djc, hpg_rot 
+   !!            9.0  !  05-11  (G. Madec) style & small optimisation
+   !! History of the TAM module:
+   !!            9.0  !  08-06  (A. Vidard) Skeleton
+   !!                 !  08-11  (A. Vidard) Nemo v3
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_hpg      : update the momentum trend with the now horizontal
+   !!                  gradient of the hydrostatic pressure
+   !!       hpg_ctl  : initialisation and control of options
+   !!       hpg_zco  : z-coordinate scheme
+   !!       hpg_zps  : z-coordinate plus partial steps (interpolation)
+   !!       hpg_sco  : s-coordinate (standard jacobian formulation)
+   !!       hpg_hel  : s-coordinate (helsinki modification)
+   !!       hpg_wdj  : s-coordinate (weighted density jacobian)
+   !!       hpg_djc  : s-coordinate (Density Jacobian with Cubic polynomial)
+   !!       hpg_rot  : s-coordinate (ROTated axes scheme)
+   !!----------------------------------------------------------------------
+   USE par_kind,       ONLY: & ! Precision variables
+      & wp
+   USE par_oce,        ONLY: & ! Ocean space and time domain variables
+      & jpi,           jpj,           jpk,           &
+      & jpim1,         jpjm1,         jpkm1,         &
+      & jpiglo
+   USE oce_tam       , ONLY: & ! ocean dynamics and tracers
+      & ua_tl,         va_tl,         rhd_tl,        &
+      & ua_ad,         va_ad,         rhd_ad,        &
+      & gru_tl,        grv_tl,        gru_ad,        &
+      & grv_ad,        tn_tl,         sn_tl,         &
+      & gtu_tl,        gtv_tl,        gsu_tl,        &
+      & gsv_tl,        rhop_tl
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & lk_vvl,        e1u,           e2u,           &
+      & e1v,           e2v,                          &
+#if defined key_zco
+      & e3t_0,         e3w_0,                        &
+#else
+      & e3u,           e3v,           e3w,           &
+#endif
+      & mbathy,        umask,         vmask,         &
+      & mig,           mjg,           nldi,          &
+      & nldj,          nlei,          nlej
+   USE dynhpg        , ONLY: &
+      & ln_hpg_zco,    ln_hpg_zps,    ln_hpg_sco,    &
+      & ln_hpg_hel,    ln_hpg_wdj,    ln_hpg_djc,    &
+      & ln_hpg_rot,    rn_gamma,      ln_dynhpg_imp, &
+      & nhpg
+   USE phycst        , ONLY: & ! physical constants
+      & grav
+   USE in_out_manager, ONLY: & ! I/O manager
+      & ctl_stop,      lwp,           numout,        & 
+      & numnam,        nit000,        nitend
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,    prntst_tlm,    stdu,          & 
+      & stdv,          stdr,          stdt,          & !
+      & stds
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_hpg_tan    ! routine called by step_tam module
+   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
+!   LOGICAL  ::   ln_hpg_zco = .TRUE.    ! z-coordinate - full steps
+!   LOGICAL  ::   ln_hpg_zps = .FALSE.   ! z-coordinate - partial steps (interpolation)
+!   LOGICAL  ::   ln_hpg_sco = .FALSE.   ! s-coordinate (standard jacobian formulation)
+!   LOGICAL  ::   ln_hpg_hel = .FALSE.   ! s-coordinate (helsinki modification)
+!   LOGICAL  ::   ln_hpg_wdj = .FALSE.   ! s-coordinate (weighted density jacobian)
+!   LOGICAL  ::   ln_hpg_djc = .FALSE.   ! s-coordinate (Density Jacobian with Cubic polynomial)
+!   LOGICAL  ::   ln_hpg_rot = .FALSE.   ! s-coordinate (ROTated axes scheme)
+!   REAL(wp) ::   gamm       = 0.e0      ! weighting coefficient
+
+!   INTEGER  ::   nhpg  =  0             ! = 0 to 6, type of pressure gradient scheme used
+      !                                 ! (deduced from ln_hpg_... flags)
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE dyn_hpg_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_hpg_tan  ***
+      !!
+      !! ** Method of the direct routine:
+      !!              Call the hydrostatic pressure gradient routine 
+      !!              using the scheme defined in the namelist
+      !!   
+      !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
+      !!             - Save the trend (l_trddyn=T)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !!
+      !!----------------------------------------------------------------------
+      IF( kt == nit000 )   CALL hpg_ctl_tam       ! initialisation & control of options
+
+      SELECT CASE ( nhpg )      ! Hydrastatic pressure gradient computation
+      CASE (  0 )   ;   CALL hpg_zco_tan    ( kt )      ! z-coordinate
+      CASE (  1 )   ;   CALL hpg_zps_tan    ( kt )      ! z-coordinate plus partial steps (interpolation)
+      CASE (  2 )   ;   CALL hpg_sco_tan    ( kt )      ! s-coordinate (standard jacobian formulation)
+      CASE (  3 )   ;   CALL hpg_hel_tan    ( kt )      ! s-coordinate (helsinki modification)
+      CASE (  4 )   ;   CALL hpg_wdj_tan    ( kt )      ! s-coordinate (weighted density jacobian)
+      CASE (  5 )   ;   CALL hpg_djc_tan    ( kt )      ! s-coordinate (Density Jacobian with Cubic polynomial)
+      CASE (  6 )   ;   CALL hpg_rot_tan    ( kt )      ! s-coordinate (ROTated axes scheme)
+      END SELECT
+   END SUBROUTINE dyn_hpg_tan
+   SUBROUTINE dyn_hpg_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_hpg_adj  ***
+      !!
+      !! ** Method of the direct routine:
+      !!              call the hydrostatic pressure gradient routine 
+      !!              using the scheme defined in the namelist
+      !!   
+      !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
+      !!             - Save the trend (l_trddyn=T)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !!
+      !!----------------------------------------------------------------------
+      IF( kt == nitend )   CALL hpg_ctl_tam      ! initialisation & control of options
+      
+      SELECT CASE ( nhpg )      ! Hydrastatic pressure gradient computation
+      CASE (  0 )   ;   CALL hpg_zco_adj    ( kt )      ! z-coordinate
+      CASE (  1 )   ;   CALL hpg_zps_adj    ( kt )      ! z-coordinate plus partial steps (interpolation)
+      CASE (  2 )   ;   CALL hpg_sco_adj    ( kt )      ! s-coordinate (standard jacobian formulation)
+      CASE (  3 )   ;   CALL hpg_hel_adj    ( kt )      ! s-coordinate (helsinki modification)
+      CASE (  4 )   ;   CALL hpg_wdj_adj    ( kt )      ! s-coordinate (weighted density jacobian)
+      CASE (  5 )   ;   CALL hpg_djc_adj    ( kt )      ! s-coordinate (Density Jacobian with Cubic polynomial)
+      CASE (  6 )   ;   CALL hpg_rot_adj    ( kt )      ! s-coordinate (ROTated axes scheme)
+      END SELECT
+   END SUBROUTINE dyn_hpg_adj
+
+   SUBROUTINE hpg_ctl_tam
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE hpg_ctl_tam  ***
+      !!
+      !! ** Purpose :   initializations for the hydrostatic pressure gradient
+      !!              computation and consistency control
+      !!
+      !! ** Action  :   Read the namelist namdyn_hpg and check the consistency
+      !!      with the type of vertical coordinate used (zco, zps, sco)
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio = 0      ! temporary integer
+
+!      Namelist read in opa_flg
+!      NAMELIST/nam_dynhpg/ ln_hpg_zco, ln_hpg_zps, ln_hpg_sco, ln_hpg_hel,   &
+!         &                 ln_hpg_wdj, ln_hpg_djc, ln_hpg_rot, gamm
+      !!----------------------------------------------------------------------
+
+!      REWIND ( numnam )               ! Read Namelist nam_dynhpg : pressure gradient calculation options
+!      READ   ( numnam, nam_dynhpg )
+
+      IF(lwp) THEN                    ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'dyn_ctl_tam : hydrostatic pressure gradient'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namdyn_hpg : choice of hpg scheme'
+         WRITE(numout,*) '      z-coord. - full steps                             ln_hpg_zco    = ', ln_hpg_zco
+         WRITE(numout,*) '      z-coord. - partial steps (interpolation)          ln_hpg_zps    = ', ln_hpg_zps
+         WRITE(numout,*) '      s-coord. (standard jacobian formulation)          ln_hpg_sco    = ', ln_hpg_sco
+         WRITE(numout,*) '      s-coord. (helsinki modification)                  ln_hpg_hel    = ', ln_hpg_hel
+         WRITE(numout,*) '      s-coord. (weighted density jacobian)              ln_hpg_wdj    = ', ln_hpg_wdj
+         WRITE(numout,*) '      s-coord. (Density Jacobian: Cubic polynomial)     ln_hpg_djc    = ', ln_hpg_djc
+         WRITE(numout,*) '      s-coord. (ROTated axes scheme)                    ln_hpg_rot    = ', ln_hpg_rot
+         WRITE(numout,*) '      weighting coeff. (wdj scheme)                     rn_gamma      = ', rn_gamma
+         WRITE(numout,*) '      time stepping: centered (F) or semi-implicit (T)  ln_dynhpg_imp = ', ln_dynhpg_imp
+      ENDIF
+
+      IF( lk_vvl .AND. .NOT. ln_hpg_sco )   THEN
+         CALL ctl_stop( 'hpg_ctl_tam : variable volume key_vvl compatible only with the standard jacobian formulation hpg_sco')
+      ENDIF
+
+      !                               ! Set nhpg from ln_hpg_... flags
+      IF( ln_hpg_zco )   nhpg = 0
+      IF( ln_hpg_zps )   nhpg = 1
+      IF( ln_hpg_sco )   nhpg = 2
+      IF( ln_hpg_hel )   nhpg = 3
+      IF( ln_hpg_wdj )   nhpg = 4
+      IF( ln_hpg_djc )   nhpg = 5
+      IF( ln_hpg_rot )   nhpg = 6
+
+      !                               ! Consitency check
+      ioptio = 0 
+      IF( ln_hpg_zco )   ioptio = ioptio + 1
+      IF( ln_hpg_zps )   ioptio = ioptio + 1
+      IF( ln_hpg_sco )   ioptio = ioptio + 1
+      IF( ln_hpg_hel )   ioptio = ioptio + 1
+      IF( ln_hpg_wdj )   ioptio = ioptio + 1
+      IF( ln_hpg_djc )   ioptio = ioptio + 1
+      IF( ln_hpg_rot )   ioptio = ioptio + 1
+      IF ( ioptio /= 1 )   CALL ctl_stop( ' NO or several hydrostatic pressure gradient options used' )
+
+      !
+   END SUBROUTINE hpg_ctl_tam
+   SUBROUTINE hpg_zco_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_zco_tan  ***
+      !!
+      !! ** Method of the direct routine:
+      !!      z-coordinate case, levels are horizontal surfaces.
+      !!      The now hydrostatic pressure gradient at a given level, jk,
+      !!      is computed by taking the vertical integral of the in-situ
+      !!      density gradient along the model level from the suface to that
+      !!      level:    zhpi = grav .....
+      !!                zhpj = grav .....
+      !!      add it to the general momentum trend (ua,va).
+      !!            ua = ua - 1/e1u * zhpi
+      !!            va = va - 1/e2v * zhpj
+      !! 
+      !! ** Action : - Update (ua_tl,va_tl) with the now hydrastatic pressure trend
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk       ! dummy loop indices
+      REAL(wp) ::   zcoef0, zcoef1   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zhpitl, zhpjtl
+      !!----------------------------------------------------------------------
+      
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:hpg_zco_tan : hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~   z-coordinate case '
+      ENDIF
+      
+      ! Local constant initialization 
+      zcoef0 = - grav * 0.5_wp
+
+      ! Surface value
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zcoef1 = zcoef0 * fse3w(ji,jj,1)
+            ! hydrostatic pressure gradient
+            zhpitl(ji,jj,1) = zcoef1 * ( rhd_tl(ji+1,jj,1) - rhd_tl(ji,jj,1) ) / e1u(ji,jj)
+            zhpjtl(ji,jj,1) = zcoef1 * ( rhd_tl(ji,jj+1,1) - rhd_tl(ji,jj,1) ) / e2v(ji,jj)
+            ! add to the general momentum trend
+            ua_tl(ji,jj,1) = ua_tl(ji,jj,1) + zhpitl(ji,jj,1)
+            va_tl(ji,jj,1) = va_tl(ji,jj,1) + zhpjtl(ji,jj,1)
+         END DO
+      END DO
+      !
+      ! interior value (2=<jk=<jpkm1)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcoef1 = zcoef0 * fse3w(ji,jj,jk)
+               ! hydrostatic pressure gradient
+               zhpitl(ji,jj,jk) = zhpitl(ji,jj,jk-1)   &
+                  &           + zcoef1 * (  ( rhd_tl(ji+1,jj,jk)+rhd_tl(ji+1,jj,jk-1) )   &
+                  &                       - ( rhd_tl(ji  ,jj,jk)+rhd_tl(ji  ,jj,jk-1) )  ) / e1u(ji,jj)
+
+               zhpjtl(ji,jj,jk) = zhpjtl(ji,jj,jk-1)   &
+                  &           + zcoef1 * (  ( rhd_tl(ji,jj+1,jk)+rhd_tl(ji,jj+1,jk-1) )   &
+                  &                       - ( rhd_tl(ji,jj,  jk)+rhd_tl(ji,jj  ,jk-1) )  ) / e2v(ji,jj)
+               ! add to the general momentum trend
+               ua_tl(ji,jj,jk) = ua_tl(ji,jj,jk) + zhpitl(ji,jj,jk)
+               va_tl(ji,jj,jk) = va_tl(ji,jj,jk) + zhpjtl(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE hpg_zco_tan
+   SUBROUTINE hpg_zco_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_zco_tan  ***
+      !!
+      !! ** Method of the direct routine:
+      !!      z-coordinate case, levels are horizontal surfaces.
+      !!      The now hydrostatic pressure gradient at a given level, jk,
+      !!      is computed by taking the vertical integral of the in-situ
+      !!      density gradient along the model level from the suface to that
+      !!      level:    zhpi = grav .....
+      !!                zhpj = grav .....
+      !!      add it to the general momentum trend (ua,va).
+      !!            ua = ua - 1/e1u * zhpi
+      !!            va = va - 1/e2v * zhpj
+      !! 
+      !! ** Action : - Update (ua_tl,va_tl) with the now hydrastatic pressure trend
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk       ! dummy loop indices
+      REAL(wp) ::   zcoef0, zcoef1   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zhpiad, zhpjad
+      !!----------------------------------------------------------------------
+      
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:hpg_zco_adj : hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~   z-coordinate case '
+      ENDIF
+      ! adjoint variables initialization
+      zhpiad = 0.0_wp
+      zhpjad = 0.0_wp
+      ! Local constant initialization 
+      zcoef0 = - grav * 0.5
+
+      ! interior value (2=<jk=<jpkm1)
+      DO jk = jpkm1, 2, -1
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+               zcoef1 = zcoef0 * fse3w(ji,jj,jk)
+               ! add to the general momentum trend
+               zhpiad(ji,jj,jk) = zhpiad(ji,jj,jk) + ua_ad(ji,jj,jk)
+               zhpjad(ji,jj,jk) = zhpjad(ji,jj,jk) + va_ad(ji,jj,jk)
+               ! hydrostatic pressure gradient
+               rhd_ad(ji,jj+1,jk  ) = rhd_ad(ji,jj+1,jk  ) + zhpjad(ji,jj,jk) * zcoef1 / e2v(ji,jj)
+               rhd_ad(ji,jj+1,jk-1) = rhd_ad(ji,jj+1,jk-1) + zhpjad(ji,jj,jk) * zcoef1 / e2v(ji,jj)
+               rhd_ad(ji,jj  ,jk  ) = rhd_ad(ji,jj  ,jk  ) - zhpjad(ji,jj,jk) * zcoef1 / e2v(ji,jj)
+               rhd_ad(ji,jj  ,jk-1) = rhd_ad(ji,jj  ,jk-1) - zhpjad(ji,jj,jk) * zcoef1 / e2v(ji,jj)
+               zhpjad(ji,jj  ,jk-1) = zhpjad(ji,jj  ,jk-1) + zhpjad(ji,jj,jk) 
+               zhpjad(ji,jj  ,jk  ) = 0.0_wp
+
+               rhd_ad(ji+1,jj,jk  ) = rhd_ad(ji+1,jj,jk  ) + zhpiad(ji,jj,jk) * zcoef1 / e1u(ji,jj)
+               rhd_ad(ji+1,jj,jk-1) = rhd_ad(ji+1,jj,jk-1) + zhpiad(ji,jj,jk) * zcoef1 / e1u(ji,jj)
+               rhd_ad(ji  ,jj,jk  ) = rhd_ad(ji  ,jj,jk  ) - zhpiad(ji,jj,jk) * zcoef1 / e1u(ji,jj)
+               rhd_ad(ji  ,jj,jk-1) = rhd_ad(ji  ,jj,jk-1) - zhpiad(ji,jj,jk) * zcoef1 / e1u(ji,jj)
+               zhpiad(ji  ,jj,jk-1) = zhpiad(ji  ,jj,jk-1) + zhpiad(ji,jj,jk) 
+               zhpiad(ji  ,jj,jk  ) = 0.0_wp
+
+            END DO
+         END DO
+      END DO
+      ! Surface value
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zcoef1 = zcoef0 * fse3w(ji,jj,1)
+            ! add to the general momentum trend
+            zhpiad(ji,jj,1) = zhpiad(ji,jj,1) + ua_ad(ji,jj,1)
+            zhpjad(ji,jj,1) = zhpjad(ji,jj,1) + va_ad(ji,jj,1)
+            ! hydrostatic pressure gradient
+            rhd_ad(ji,jj+1,1) = rhd_ad(ji,jj+1,1) + zhpjad(ji,jj,1) * zcoef1 / e2v(ji,jj)
+            rhd_ad(ji,jj  ,1) = rhd_ad(ji,jj  ,1) - zhpjad(ji,jj,1) * zcoef1 / e2v(ji,jj)
+            zhpjad(ji,jj,1) = 0.0_wp
+
+            rhd_ad(ji+1,jj,1) = rhd_ad(ji+1,jj,1) + zhpiad(ji,jj,1) * zcoef1 / e1u(ji,jj)
+            rhd_ad(ji  ,jj,1) = rhd_ad(ji  ,jj,1) - zhpiad(ji,jj,1) * zcoef1 / e1u(ji,jj)
+            zhpiad(ji,jj,1) = 0.0_wp
+         END DO
+      END DO
+      !
+      !
+   END SUBROUTINE hpg_zco_adj
+   SUBROUTINE hpg_zps_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE hpg_zps  ***
+      !!                    
+      !! ** Method of the direct routine:
+      !!              z-coordinate plus partial steps case.  blahblah...
+      !! 
+      !! ** Action  : - Update (ua_tl,va_tl) with the now hydrastatic pressure trend
+      !!---------------------------------------------------------------------- 
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk                       ! dummy loop indices
+      INTEGER  ::   iku, ikv                         ! temporary integers
+      REAL(wp) ::   zcoef0, zcoef1, zcoef2, zcoef3   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zhpitl, zhpjtl
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:hpg_zps_tan : hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~   z-coordinate with partial steps - vector optimization'
+      ENDIF
+
+      ! Local constant initialization
+      zcoef0 = - grav * 0.5
+
+      !  Surface value
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zcoef1 = zcoef0 * fse3w(ji,jj,1)
+            ! hydrostatic pressure gradient
+            zhpitl(ji,jj,1) = zcoef1 * ( rhd_tl(ji+1,jj  ,1) - rhd_tl(ji,jj,1) ) / e1u(ji,jj)
+            zhpjtl(ji,jj,1) = zcoef1 * ( rhd_tl(ji  ,jj+1,1) - rhd_tl(ji,jj,1) ) / e2v(ji,jj)
+            ! add to the general momentum trend
+            ua_tl(ji,jj,1) = ua_tl(ji,jj,1) + zhpitl(ji,jj,1)
+            va_tl(ji,jj,1) = va_tl(ji,jj,1) + zhpjtl(ji,jj,1)
+         END DO
+      END DO
+
+      ! interior value (2=<jk=<jpkm1)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcoef1 = zcoef0 * fse3w(ji,jj,jk)
+               ! hydrostatic pressure gradient
+               zhpitl(ji,jj,jk) = zhpitl(ji,jj,jk-1)   &
+                  &           + zcoef1 * (  ( rhd_tl(ji+1,jj,jk) + rhd_tl(ji+1,jj,jk-1) )   &
+                  &                       - ( rhd_tl(ji  ,jj,jk) + rhd_tl(ji  ,jj,jk-1) )  ) / e1u(ji,jj)
+
+               zhpjtl(ji,jj,jk) = zhpjtl(ji,jj,jk-1)   &
+                  &           + zcoef1 * (  ( rhd_tl(ji,jj+1,jk) + rhd_tl(ji,jj+1,jk-1) )   &
+                  &                       - ( rhd_tl(ji,jj,  jk) + rhd_tl(ji,jj  ,jk-1) )  ) / e2v(ji,jj)
+               ! add to the general momentum trend
+               ua_tl(ji,jj,jk) = ua_tl(ji,jj,jk) + zhpitl(ji,jj,jk)
+               va_tl(ji,jj,jk) = va_tl(ji,jj,jk) + zhpjtl(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! partial steps correction at the last level  (new gradient with  intgrd.F)
+# if defined key_vectopt_loop
+         jj = 1
+         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+# endif
+            iku = MIN ( mbathy(ji,jj), mbathy(ji+1,jj) ) - 1
+            ikv = MIN ( mbathy(ji,jj), mbathy(ji,jj+1) ) - 1
+            zcoef2 = zcoef0 * MIN( fse3w(ji,jj,iku), fse3w(ji+1,jj  ,iku) )
+            zcoef3 = zcoef0 * MIN( fse3w(ji,jj,ikv), fse3w(ji  ,jj+1,ikv) )
+            ! on i-direction
+            IF ( iku > 2 ) THEN
+               ! subtract old value
+               ua_tl(ji,jj,iku) = ua_tl(ji,jj,iku) - zhpitl(ji,jj,iku)
+               ! compute the new one
+               zhpitl (ji,jj,iku) = zhpitl(ji,jj,iku-1)   &
+                  + zcoef2 * ( rhd_tl(ji+1,jj,iku-1) - rhd_tl(ji,jj,iku-1) + gru_tl(ji,jj) ) / e1u(ji,jj)
+               ! add the new one to the general momentum trend
+               ua_tl(ji,jj,iku) = ua_tl(ji,jj,iku) + zhpitl(ji,jj,iku)
+            ENDIF
+            ! on j-direction
+            IF ( ikv > 2 ) THEN
+               ! subtract old value
+               va_tl(ji,jj,ikv) = va_tl(ji,jj,ikv) - zhpjtl(ji,jj,ikv)
+               ! compute the new one
+               zhpjtl (ji,jj,ikv) = zhpjtl(ji,jj,ikv-1)   &
+                  + zcoef3 * ( rhd_tl(ji,jj+1,ikv-1) - rhd_tl(ji,jj,ikv-1) + grv_tl(ji,jj) ) / e2v(ji,jj)
+               ! add the new one to the general momentum trend
+               va_tl(ji,jj,ikv) = va_tl(ji,jj,ikv) + zhpjtl(ji,jj,ikv)
+            ENDIF
+# if ! defined key_vectopt_loop
+         END DO
+# endif
+      END DO
+      !
+   END SUBROUTINE hpg_zps_tan
+   SUBROUTINE hpg_zps_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE hpg_zps  ***
+      !!                    
+      !! ** Method of the direct routine:
+      !!              z-coordinate plus partial steps case.  blahblah...
+      !! 
+      !! ** Action  : - Update (ua_tl,va_tl) with the now hydrastatic pressure trend
+      !!---------------------------------------------------------------------- 
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk                       ! dummy loop indices
+      INTEGER  ::   iku, ikv                         ! temporary integers
+      REAL(wp) ::   zcoef0, zcoef1, zcoef2, zcoef3   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk):: zhpiad, zhpjad
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:hpg_zps_adj : hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~   z-coordinate with partial steps - vector optimization'
+      ENDIF
+      zhpiad(:,:,:) = 0.0_wp
+      zhpjad(:,:,:) = 0.0_wp
+      ! Local constant initialization
+      zcoef0 = - grav * 0.5
+
+      ! partial steps correction at the last level  (new gradient with  intgrd.F)
+# if defined key_vectopt_loop
+         jj = 1
+         DO ji = jpij-jpi-1, jpi+2, -1   ! vector opt. (forced unrolling)
+# else
+      DO jj = jpjm1, 2, -1
+         DO ji = jpim1, 2, -1
+# endif
+            iku = MIN ( mbathy(ji,jj), mbathy(ji+1,jj) ) - 1
+            ikv = MIN ( mbathy(ji,jj), mbathy(ji,jj+1) ) - 1
+            zcoef2 = zcoef0 * MIN( fse3w(ji,jj,iku), fse3w(ji+1,jj  ,iku) )
+            zcoef3 = zcoef0 * MIN( fse3w(ji,jj,ikv), fse3w(ji  ,jj+1,ikv) )
+            ! on i-direction
+            IF ( iku > 2 ) THEN
+               ! add the new one to the general momentum trend
+               zhpiad(ji,jj,iku) = zhpiad(ji,jj,iku) + ua_ad(ji,jj,iku)
+               ! compute the new one
+               rhd_ad(ji+1,jj,iku-1) = rhd_ad(ji+1,jj,iku-1) + zhpiad (ji,jj,iku) * zcoef2 / e1u(ji,jj)
+               rhd_ad(ji,jj,iku-1) = rhd_ad(ji,jj,iku-1) - zhpiad (ji,jj,iku) * zcoef2 / e1u(ji,jj)
+               gru_ad(ji,jj) = gru_ad(ji,jj) + zhpiad (ji,jj,iku) * zcoef2 / e1u(ji,jj)
+               zhpiad(ji,jj,iku-1) = zhpiad(ji,jj,iku-1) + zhpiad (ji,jj,iku)
+               zhpiad (ji,jj,iku) = 0.0_wp
+               ! subtract old value
+               zhpiad(ji,jj,iku) = zhpiad(ji,jj,iku) - ua_ad(ji,jj,iku)
+            ENDIF
+            ! on j-direction
+            IF ( ikv > 2 ) THEN
+               ! add the new one to the general momentum trend
+               zhpjad(ji,jj,ikv) = zhpjad(ji,jj,ikv) + va_ad(ji,jj,ikv)
+               ! compute the new one
+               rhd_ad(ji,jj+1,ikv-1) = rhd_ad(ji,jj+1,ikv-1) + zhpjad (ji,jj,ikv) * zcoef3 / e2v(ji,jj)
+               rhd_ad(ji,jj,ikv-1) = rhd_ad(ji,jj,ikv-1) -zhpjad (ji,jj,ikv) * zcoef3 / e2v(ji,jj)
+               grv_ad(ji,jj) = grv_ad(ji,jj) +zhpjad (ji,jj,ikv) * zcoef3 / e2v(ji,jj)
+               zhpjad(ji,jj,ikv-1) = zhpjad(ji,jj,ikv-1) + zhpjad(ji,jj,ikv)
+               zhpjad (ji,jj,ikv) = 0.0_wp
+               ! subtract old value
+               zhpjad(ji,jj,ikv) = zhpjad(ji,jj,ikv) - va_ad(ji,jj,ikv)
+            ENDIF
+# if ! defined key_vectopt_loop
+         END DO
+# endif
+      END DO
+      !
+
+
+      ! interior value (2=<jk=<jpkm1)
+      DO jk = jpkm1, 2, -1
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+               zcoef1 = zcoef0 * fse3w(ji,jj,jk)
+               ! add to the general momentum trend
+               zhpiad(ji,jj,jk) = zhpiad(ji,jj,jk) + ua_ad(ji,jj,jk)
+               zhpjad(ji,jj,jk) = zhpjad(ji,jj,jk) + va_ad(ji,jj,jk)
+               ! hydrostatic pressure gradient
+               rhd_ad(ji,jj+1,jk  ) = rhd_ad(ji,jj+1,jk  ) + zhpjad(ji,jj,jk) * zcoef1 / e2v(ji,jj)
+               rhd_ad(ji,jj+1,jk-1) = rhd_ad(ji,jj+1,jk-1) + zhpjad(ji,jj,jk) * zcoef1 / e2v(ji,jj)
+               rhd_ad(ji,jj  ,jk  ) = rhd_ad(ji,jj  ,jk  ) - zhpjad(ji,jj,jk) * zcoef1 / e2v(ji,jj)
+               rhd_ad(ji,jj  ,jk-1) = rhd_ad(ji,jj  ,jk-1) - zhpjad(ji,jj,jk) * zcoef1 / e2v(ji,jj)
+               zhpjad(ji,jj  ,jk-1) = zhpjad(ji,jj  ,jk-1) + zhpjad(ji,jj,jk)
+               zhpjad(ji,jj  ,jk  ) = 0.0_wp
+
+               rhd_ad(ji+1,jj,jk  ) = rhd_ad(ji+1,jj,jk  ) + zhpiad(ji,jj,jk) * zcoef1 / e1u(ji,jj)
+               rhd_ad(ji+1,jj,jk-1) = rhd_ad(ji+1,jj,jk-1) + zhpiad(ji,jj,jk) * zcoef1 / e1u(ji,jj)
+               rhd_ad(ji  ,jj,jk  ) = rhd_ad(ji  ,jj,jk  ) - zhpiad(ji,jj,jk) * zcoef1 / e1u(ji,jj)
+               rhd_ad(ji  ,jj,jk-1) = rhd_ad(ji  ,jj,jk-1) - zhpiad(ji,jj,jk) * zcoef1 / e1u(ji,jj)
+               zhpiad(ji  ,jj,jk-1) = zhpiad(ji  ,jj,jk-1) + zhpiad(ji,jj,jk)
+               zhpiad(ji  ,jj,jk  ) = 0.0_wp
+            END DO
+         END DO
+      END DO
+      !  Surface value
+      DO jj = jpjm1, 2, -1
+         DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+            zcoef1 = zcoef0 * fse3w(ji,jj,1)
+            ! add to the general momentum trend
+            zhpiad(ji,jj,1) = zhpiad(ji,jj,1) + ua_ad(ji,jj,1)
+            zhpjad(ji,jj,1) = zhpjad(ji,jj,1) + va_ad(ji,jj,1)
+            ! hydrostatic pressure gradient
+            rhd_ad(ji+1,jj  ,1) = rhd_ad(ji+1,jj  ,1) + zhpiad(ji,jj,1) * zcoef1 / e1u(ji,jj)
+            rhd_ad(ji  ,jj  ,1) = rhd_ad(ji  ,jj  ,1) - zhpiad(ji,jj,1) * zcoef1 / e1u(ji,jj)
+            rhd_ad(ji  ,jj+1,1) = rhd_ad(ji  ,jj+1,1) + zhpjad(ji,jj,1) * zcoef1 / e2v(ji,jj)
+            rhd_ad(ji  ,jj  ,1) = rhd_ad(ji  ,jj  ,1) - zhpjad(ji,jj,1) * zcoef1 / e2v(ji,jj)
+            zhpiad(ji  ,jj  ,1) = 0.0_wp
+            zhpjad(ji  ,jj  ,1) = 0.0_wp
+         END DO
+      END DO
+
+   END SUBROUTINE hpg_zps_adj
+   SUBROUTINE hpg_sco_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_sco_tan  ***
+      !!
+      !! ** Method of the direct routine:   s-coordinate case. Jacobian scheme.
+      !!      The now hydrostatic pressure gradient at a given level, jk,
+      !!      is computed by taking the vertical integral of the in-situ
+      !!      density gradient along the model level from the suface to that
+      !!      level. s-coordinates (ln_sco): a corrective term is added
+      !!      to the horizontal pressure gradient :
+      !!         zhpi = grav .....  + 1/e1u mi(rhd) di[ grav dep3w ]
+      !!         zhpj = grav .....  + 1/e2v mj(rhd) dj[ grav dep3w ]
+      !!      add it to the general momentum trend (ua,va).
+      !!         ua = ua - 1/e1u * zhpi
+      !!         va = va - 1/e2v * zhpj
+      !!
+      !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      CALL ctl_stop( 'hpg_sco_tan not available yet')
+   END SUBROUTINE hpg_sco_tan
+   SUBROUTINE hpg_sco_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_sco_adj  ***
+      !!
+      !! ** Method of the direct routine:   s-coordinate case. Jacobian scheme.
+      !!      The now hydrostatic pressure gradient at a given level, jk,
+      !!      is computed by taking the vertical integral of the in-situ
+      !!      density gradient along the model level from the suface to that
+      !!      level. s-coordinates (ln_sco): a corrective term is added
+      !!      to the horizontal pressure gradient :
+      !!         zhpi = grav .....  + 1/e1u mi(rhd) di[ grav dep3w ]
+      !!         zhpj = grav .....  + 1/e2v mj(rhd) dj[ grav dep3w ]
+      !!      add it to the general momentum trend (ua,va).
+      !!         ua = ua - 1/e1u * zhpi
+      !!         va = va - 1/e2v * zhpj
+      !!
+      !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      CALL ctl_stop( 'hpg_sco_adj not available yet')
+   END SUBROUTINE hpg_sco_adj
+   SUBROUTINE hpg_hel_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_hel_tan  ***
+      !!
+      !! ** Method of the direct routine:   s-coordinate case.
+      !!      The now hydrostatic pressure gradient at a given level
+      !!      jk is computed by taking the vertical integral of the in-situ 
+      !!      density gradient along the model level from the suface to that 
+      !!      level. s-coordinates (ln_sco): a corrective term is added
+      !!      to the horizontal pressure gradient :
+      !!         zhpi = grav .....  + 1/e1u mi(rhd) di[ grav dep3w ]
+      !!         zhpj = grav .....  + 1/e2v mj(rhd) dj[ grav dep3w ]
+      !!      add it to the general momentum trend (ua,va).
+      !!         ua = ua - 1/e1u * zhpi
+      !!         va = va - 1/e2v * zhpj
+      !!
+      !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
+      !!             - Save the trend (l_trddyn=T)
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      CALL ctl_stop( 'hpg_hel_tan not available yet')
+   END SUBROUTINE hpg_hel_tan
+   SUBROUTINE hpg_hel_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_hel_adj  ***
+      !!
+      !! ** Method of the direct routine:   s-coordinate case.
+      !!      The now hydrostatic pressure gradient at a given level
+      !!      jk is computed by taking the vertical integral of the in-situ 
+      !!      density gradient along the model level from the suface to that 
+      !!      level. s-coordinates (ln_sco): a corrective term is added
+      !!      to the horizontal pressure gradient :
+      !!         zhpi = grav .....  + 1/e1u mi(rhd) di[ grav dep3w ]
+      !!         zhpj = grav .....  + 1/e2v mj(rhd) dj[ grav dep3w ]
+      !!      add it to the general momentum trend (ua,va).
+      !!         ua = ua - 1/e1u * zhpi
+      !!         va = va - 1/e2v * zhpj
+      !!
+      !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
+      !!             - Save the trend (l_trddyn=T)
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      CALL ctl_stop( 'hpg_hel_adj not available yet')
+   END SUBROUTINE hpg_hel_adj
+   SUBROUTINE hpg_wdj_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_wdj_tan  ***
+      !!
+      !! ** Method of the direct roiutine:
+      !!      Weighted Density Jacobian (wdj) scheme (song 1998)
+      !!      The weighting coefficients from the namelist parameter gamm
+      !!      (alpha=0.5-gamm ; beta=1-alpha=0.5+gamm)
+      !!
+      !! Reference : Song, Mon. Wea. Rev., 126, 3213-3230, 1998.
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      CALL ctl_stop( 'hpg_wdj_tan not available yet')
+   END SUBROUTINE hpg_wdj_tan
+   SUBROUTINE hpg_wdj_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_wdj_adj  ***
+      !!
+      !! ** Method of the direct roiutine:
+      !!      Weighted Density Jacobian (wdj) scheme (song 1998)
+      !!      The weighting coefficients from the namelist parameter gamm
+      !!      (alpha=0.5-gamm ; beta=1-alpha=0.5+gamm)
+      !!
+      !! Reference : Song, Mon. Wea. Rev., 126, 3213-3230, 1998.
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      CALL ctl_stop( 'hpg_wdj_adj not available yet')
+   END SUBROUTINE hpg_wdj_adj
+   SUBROUTINE hpg_djc_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_djc_tan  ***
+      !!
+      !! ** Method  :   Density Jacobian with Cubic polynomial scheme
+      !! 
+      !! Reference: Shchepetkin and McWilliams, J. Geophys. Res., 108(C3), 3090, 2003
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      CALL ctl_stop( 'hpg_djc_tan not available yet')
+   END SUBROUTINE hpg_djc_tan
+   SUBROUTINE hpg_djc_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_djc_adj  ***
+      !!
+      !! ** Method  :   Density Jacobian with Cubic polynomial scheme
+      !! 
+      !! Reference: Shchepetkin and McWilliams, J. Geophys. Res., 108(C3), 3090, 2003
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      CALL ctl_stop( 'hpg_djc_adj not available yet')
+   END SUBROUTINE hpg_djc_adj
+   SUBROUTINE hpg_rot_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_rot_tan  ***
+      !!
+      !! ** Method  :   rotated axes scheme (Thiem and Berntsen 2005)
+      !!
+      !! Reference: Thiem & Berntsen, Ocean Modelling, In press, 2005.
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+            !!
+      CALL ctl_stop( 'hpg_rot_tan not available yet')
+   END SUBROUTINE hpg_rot_tan
+   SUBROUTINE hpg_rot_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_rot_adj  ***
+      !!
+      !! ** Method  :   rotated axes scheme (Thiem and Berntsen 2005)
+      !!
+      !! Reference: Thiem & Berntsen, Ocean Modelling, In press, 2005.
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+            !!
+      CALL ctl_stop( 'hpg_rot_adj not available yet')
+   END SUBROUTINE hpg_rot_adj
+
+   SUBROUTINE dyn_hpg_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dynhpg_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Separate tests are applied for the following dx and dy:
+      !!                
+      !!              1) dx = ( SSH ) and dy = ( SSH )
+      !!                   
+      !! History :
+      !!        ! 08-07 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zrhd_tlin,              &  ! in situ density anomalie
+         & zua_tlin,               &  ! after u- velocity
+         & zva_tlin,               &  ! after v- velocity
+         & zua_tlout,              &  ! after u- velocity
+         & zva_tlout                  ! after v- velocity
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zrhd_adout,             &  ! in situ density anomalie
+         & zua_adout,              &  ! after u- velocity
+         & zva_adout,              &  ! after v- velocity
+         & zua_adin,               &  ! after u- velocity
+         & zva_adin                   ! after v- velocity
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   &
+         & zgru_tlin,              &
+         & zgrv_tlin,              &
+         & zgru_adout,             &
+         & zgrv_adout
+         
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zrh,          & ! 3D random field for rhd
+         & zau,          & ! 3D random field for u
+         & zav             ! 3D random field for v
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   &
+         & zgru,         & ! 2D random field for gru 
+         & zgrv            ! 2D random field for grv
+      REAL(KIND=wp) ::   &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_1,       & !   scalar product components
+         & zsp1_2,       & 
+         & zsp2,         & ! scalar product involving the adjoint routine
+         & zsp2_1,       & !   scalar product components
+         & zsp2_2,       & 
+         & zsp2_3,       & 
+         & zsp2_4,       & 
+         & zsp2_5
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d           ! 2D seed for the random number generator
+      INTEGER :: &
+         & iseed, &
+         & ji, &
+         & jj, &
+         & jk
+      CHARACTER(LEN=14) :: cl_name
+
+      ! Allocate memory
+      ALLOCATE( & 
+         & zrhd_tlin(jpi,jpj,jpk),  &
+         & zua_tlin(jpi,jpj,jpk),   &
+         & zva_tlin(jpi,jpj,jpk),   &
+         & zgru_tlin(jpi,jpj),      & 
+         & zgrv_tlin(jpi,jpj),      & 
+         & zua_tlout(jpi,jpj,jpk),  &
+         & zva_tlout(jpi,jpj,jpk),  &
+         & zrhd_adout(jpi,jpj,jpk), &
+         & zua_adout(jpi,jpj,jpk),  &
+         & zva_adout(jpi,jpj,jpk),  &
+         & zgru_adout(jpi,jpj),     & 
+         & zgrv_adout(jpi,jpj),     & 
+         & zua_adin(jpi,jpj,jpk),   &
+         & zva_adin(jpi,jpj,jpk),   &
+         & zrh(jpi,jpj,jpk),        & 
+         & zau(jpi,jpj,jpk),        & 
+         & zav(jpi,jpj,jpk),        & 
+         & zgru(jpi,jpj),           &
+         & zgrv(jpi,jpj)            &
+         &     )
+ 
+
+      !==================================================================
+      ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and 
+      !    dy = ( hdivb_tl, hdivn_tl )
+      !==================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      zrhd_tlin(:,:,:)  = 0.0_wp  
+      zua_tlin(:,:,:)   = 0.0_wp   
+      zva_tlin(:,:,:)   = 0.0_wp   
+      zgru_tlin(:,:)    = 0.0_wp
+      zgrv_tlin(:,:)    = 0.0_wp
+      zua_tlout(:,:,:)  = 0.0_wp  
+      zva_tlout(:,:,:)  = 0.0_wp  
+      zgru_adout(:,:)   = 0.0_wp
+      zgrv_adout(:,:)   = 0.0_wp
+      zrhd_adout(:,:,:) = 0.0_wp 
+      zua_adout(:,:,:)  = 0.0_wp  
+      zva_adout(:,:,:)  = 0.0_wp  
+      zua_adin(:,:,:)   = 0.0_wp   
+      zva_adin(:,:,:)   = 0.0_wp   
+      zrh(:,:,:)        = 0.0_wp         
+      zau(:,:,:)        = 0.0_wp         
+      zav(:,:,:)        = 0.0_wp 
+      zgru(:,:)         = 0.0_wp
+      zgrv(:,:)         = 0.0_wp
+
+
+      gru_tl(:,:)   = 0.0_wp
+      grv_tl(:,:)   = 0.0_wp
+      gru_ad(:,:)   = 0.0_wp
+      grv_ad(:,:)   = 0.0_wp
+      ua_tl(:,:,:)  = 0.0_wp
+      va_tl(:,:,:)  = 0.0_wp
+      rhd_tl(:,:,:) = 0.0_wp
+      ua_ad(:,:,:)  = 0.0_wp
+      va_ad(:,:,:)  = 0.0_wp
+      rhd_ad(:,:,:) = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zau, 'U', 0.0_wp, stdu )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 523432 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zav, 'V', 0.0_wp, stdv )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 456953 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zrh, 'W', 0.0_wp, stdr )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 432545 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zgru, 'U', 0.0_wp, stdu )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 287503 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zgrv, 'V', 0.0_wp, stdv )
+
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zrhd_tlin(ji,jj,jk) = zrh(ji,jj,jk)
+               zua_tlin(ji,jj,jk)  = zau(ji,jj,jk)
+               zva_tlin(ji,jj,jk)  = zav(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zgru_tlin(ji,jj)   = zgru(ji,jj)
+            zgrv_tlin(ji,jj)   = zgrv(ji,jj)
+         END DO
+      END DO
+      ua_tl(:,:,:)  = zua_tlin(:,:,:)
+      va_tl(:,:,:)  = zva_tlin(:,:,:)
+      rhd_tl(:,:,:) = zrhd_tlin(:,:,:)
+      gru_tl(:,:)   = zgru_tlin(:,:)
+      grv_tl(:,:)   = zgrv_tlin(:,:) 
+
+      CALL dyn_hpg_tan ( nit000 )
+
+      zua_tlout(:,:,:) = ua_tl(:,:,:)
+      zva_tlout(:,:,:) = va_tl(:,:,:)
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zua_adin(ji,jj,jk) = zua_tlout(ji,jj,jk) &
+                 &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                 &               * umask(ji,jj,jk)
+              zva_adin(ji,jj,jk) = zva_tlout(ji,jj,jk) &
+                 &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+                 &               * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1_1 = DOT_PRODUCT( zua_tlout, zua_adin )
+      zsp1_2 = DOT_PRODUCT( zva_tlout, zva_adin )
+      zsp1   = zsp1_1 + zsp1_2
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      ua_ad(:,:,:) = zua_adin(:,:,:)
+      va_ad(:,:,:) = zva_adin(:,:,:)
+
+      CALL dyn_hpg_adj ( nit000 )
+
+      zgru_adout(:,:)   = gru_ad(:,:)
+      zgrv_adout(:,:)   = grv_ad(:,:)
+      zrhd_adout(:,:,:) = rhd_ad(:,:,:)
+      zua_adout(:,:,:)  = ua_ad(:,:,:)
+      zva_adout(:,:,:)  = va_ad(:,:,:)
+
+      zsp2_1 = DOT_PRODUCT( zgru_tlin, zgru_adout )
+      zsp2_2 = DOT_PRODUCT( zgrv_tlin, zgrv_adout )
+      zsp2_3 = DOT_PRODUCT( zrhd_tlin, zrhd_adout )
+      zsp2_4 = DOT_PRODUCT( zua_tlin, zua_adout )
+      zsp2_5 = DOT_PRODUCT( zva_tlin, zva_adout )
+      zsp2   = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4 + zsp2_5
+      ! Compare the scalar products
+
+      cl_name = 'dyn_hpg_adj   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      DEALLOCATE( &
+         & zrhd_tlin,  &
+         & zua_tlin,   &
+         & zva_tlin,   &
+         & zgru_tlin,  & 
+         & zgrv_tlin,  & 
+         & zua_tlout,  &
+         & zva_tlout,  &
+         & zrhd_adout, &
+         & zua_adout,  &
+         & zva_adout,  &
+         & zgru_adout, & 
+         & zgrv_adout, & 
+         & zua_adin,   &
+         & zva_adin,   &
+         & zrh,        & 
+         & zau,        & 
+         & zav,        & 
+         & zgru,       &
+         & zgrv        &
+         &              )
+   END SUBROUTINE dyn_hpg_adj_tst
+#if defined key_tst_tlm
+   SUBROUTINE dyn_hpg_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_hpg_tlm_tst ***
+      !!
+      !! ** Purpose : Test the adjoint 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 
+      !!                   
+      !! History :
+      !!        ! 09-08 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE dynhpg
+      USE zpshde
+      USE eosbn2,     ONLY: & ! horizontal & vertical advective trend
+        & eos
+      USE zpshde_tam
+      USE eosbn2_tam,     ONLY: & ! horizontal & vertical advective trend
+        & eos_tan
+      USE tamtrj              ! writing out state trajectory
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE divcur             ! horizontal divergence and relative vorticity
+      USE gridrandom, ONLY: &
+        & grid_rd_sd
+      USE trj_tam
+      USE oce       , ONLY: & ! ocean dynamics and tracers variables
+        & ua, va, rhd,      &
+        & gru, grv,         &
+        & un, vn,           &      
+        & tn, sn, gtu, gtv, &
+        & gsu, gsv, rhop
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      !! * Local declarations
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zrd_tlin,               &  ! in situ density anomalie
+         & zua_tlin,               &  ! after u- velocity
+         & zva_tlin,               &  ! after v- velocity
+         & ztn_tlin,               &  ! after u- velocity
+         & zsn_tlin,               &  ! after v- velocity
+         & zua_wop,                &  ! after u- velocity
+         & zva_wop,                &  ! after v- velocity
+         & zua_out,                &  ! after u- velocity
+         & zva_out                    ! after v- velocity
+
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   &
+         & zgru_tlin,              &
+         & zgrv_tlin
+
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zrh,          & ! 3D random field for rhd
+         & zau,          & ! 3D random field for u
+         & zav             ! 3D random field for v
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   &
+         & zgru,         & ! 2D random field for gru 
+         & zgrv            ! 2D random field for grv
+
+      REAL(KIND=wp) ::   &
+         & zsp1,         & ! scalar product 
+         & zsp1_1,       & ! scalar product
+         & zsp1_2,       & 
+         & zsp2,         & ! scalar product 
+         & zsp2_1,       & ! scalar product
+         & zsp2_2,       &
+         & zsp3,         & ! scalar product
+         & zsp3_1,       & 
+         & zsp3_2,       & 
+         & zzsp,         & ! scalar product
+         & zzsp_1,       & 
+         & zzsp_2,       &
+         & gamma,            &
+         & zgsp1,            &
+         & zgsp2,            &
+         & zgsp3,            &
+         & zgsp4,            &
+         & zgsp5,            &
+         & zgsp6,            &
+         & zgsp7 
+      INTEGER :: &
+         & ji, &
+         & jj, &
+         & jk
+      CHARACTER(LEN=14)   :: cl_name
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
+      CHARACTER (LEN=90)  ::  FMT
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zscua, zscva,    &
+         & zscerrua,        &
+         & zscerrva
+      INTEGER, DIMENSION(100):: &
+         & iiposua, iiposva,    &
+         & ijposua, ijposva,    & 
+         & ikposua, ikposva
+      INTEGER::             &
+         & ii,              &
+         & isamp=40,        &
+         & jsamp=40,        &
+         & ksamp=10,        &
+         & numsctlm
+     REAL(KIND=wp), DIMENSION(jpi,jpj,jpk) :: &
+         & zerrua, zerrva
+      ! Allocate memory
+      ALLOCATE( & 
+         & zrd_tlin(jpi,jpj,jpk),   &
+         & zua_tlin(jpi,jpj,jpk),   &
+         & zva_tlin(jpi,jpj,jpk),   &
+         & ztn_tlin(jpi,jpj,jpk),   &
+         & zsn_tlin(jpi,jpj,jpk),   &
+         & zgru_tlin(jpi,jpj),      & 
+         & zgrv_tlin(jpi,jpj),      & 
+         & zua_wop  (jpi,jpj,jpk),  &
+         & zva_wop  (jpi,jpj,jpk),  &
+         & zua_out  (jpi,jpj,jpk),  &
+         & zva_out  (jpi,jpj,jpk),  &
+         & zrh(      jpi,jpj,jpk),  & 
+         & zau(      jpi,jpj,jpk),  & 
+         & zav(      jpi,jpj,jpk),  & 
+         & zgru(     jpi,jpj),      &
+         & zgrv(     jpi,jpj)       &
+         &     )
+
+      !--------------------------------------------------------------------
+      ! Reset variables
+      !--------------------------------------------------------------------
+      zrd_tlin( :,:,:) = 0.0_wp
+      zgru_tlin(  :,:) = 0.0_wp
+      zgrv_tlin(  :,:) = 0.0_wp
+      zua_tlin( :,:,:) = 0.0_wp
+      zva_tlin( :,:,:) = 0.0_wp
+      ztn_tlin( :,:,:) = 0.0_wp
+      zsn_tlin( :,:,:) = 0.0_wp
+      zua_out ( :,:,:) = 0.0_wp
+      zva_out ( :,:,:) = 0.0_wp
+      zua_wop ( :,:,:) = 0.0_wp
+      zva_wop ( :,:,:) = 0.0_wp
+
+      zrh(:,:,:)        = 0.0_wp         
+      zau(:,:,:)        = 0.0_wp         
+      zav(:,:,:)        = 0.0_wp 
+      zgru(:,:)         = 0.0_wp
+      zgrv(:,:)         = 0.0_wp
+
+      zscua(:)         = 0.0_wp
+      zscva(:)         = 0.0_wp
+      zscerrua(:)      = 0.0_wp
+      zscerrva(:)      = 0.0_wp
+      zerrua(:,:,:)    = 0.0_wp
+      zerrva(:,:,:)    = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Output filename Xn=F(X0)
+      !--------------------------------------------------------------------
+!!      CALL tlm_namrd
+      gamma = h_ratio  
+      file_wop='trj_wop_dynhpg'
+      file_xdx='trj_xdx_dynhpg'
+       !--------------------------------------------------------------------
+      ! 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, zau,  'U', 0.0_wp, stdu)
+         CALL grid_rd_sd( 523432, zav,  'V', 0.0_wp, stdv)
+         CALL grid_rd_sd( 456953, zrh,  'W', 0.0_wp, stdr)
+         CALL grid_rd_sd( 432545, zgru, 'U', 0.0_wp, stdu)
+         CALL grid_rd_sd( 287503, zgrv, 'V', 0.0_wp, stdv) 
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zrd_tlin(ji,jj,jk) = zrh(ji,jj,jk)
+                  zua_tlin(ji,jj,jk)  = zau(ji,jj,jk)
+                  zva_tlin(ji,jj,jk)  = zav(ji,jj,jk)
+               END DO
+            END DO
+         END DO 
+
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zgru_tlin(ji,jj)   = zgru(ji,jj)
+               zgrv_tlin(ji,jj)   = zgrv(ji,jj)
+            END DO
+         END DO 
+      ENDIF
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      IF ( tlm_bch /= 2 )      CALL istate_p  
+
+      ! *** initialize the reference trajectory
+      ! ------------
+      CALL  trj_rea( nit000-1, 1 )
+      ua(:,:,:)       = un(:,:,:)
+      va(:,:,:)       = vn(:,:,:) 
+
+      !  Compute rhd, gru and grv
+      CALL eos(tn, sn, rhd, rhop)
+      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
+
+         zrd_tlin(:,:,:) = gamma * zrd_tlin(:,:,:)
+         rhd(:,:,:)       = rhd(:,:,:) + zrd_tlin(:,:,:)
+
+         zua_tlin(:,:,:) = gamma * zua_tlin(:,:,:)
+         ua(:,:,:)       = ua(:,:,:) + zua_tlin(:,:,:)
+
+         zva_tlin(:,:,:) = gamma * zva_tlin(:,:,:)
+         va(:,:,:)       = va(:,:,:) + zva_tlin(:,:,:)
+
+         zgru_tlin(:,:) = gamma * zgru_tlin(:,:)
+         gru(:,:)       = gru(:,:) + zgru_tlin(:,:)
+
+         zgrv_tlin(:,:) = gamma * zgrv_tlin(:,:)
+         grv(:,:)       = grv(:,:) + zgrv_tlin(:,:)
+      ENDIF 
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------
+      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 ( tlm_bch == 2 ) THEN
+         !--------------------------------------------------------------------
+         ! Initialize the tangent variables 
+         !--------------------------------------------------------------------
+         CALL  trj_rea( nit000-1, 1 ) 
+         ua(:,:,:)       = un(:,:,:)
+         va(:,:,:)       = vn(:,:,:)
+         gru_tl  (  :,:) = zgru_tlin (:,:  )
+         grv_tl  (  :,:) = zgrv_tlin (:,:  )
+         rhd_tl  (:,:,:) = zrd_tlin  (:,:,:)
+         ua_tl   (:,:,:) = zua_tlin  (:,:,:)
+         va_tl   (:,:,:) = zva_tlin  (:,:,:) 
+         CALL dyn_hpg_tan(nit000)
+         !--------------------------------------------------------------------
+         ! 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  )
+         zsp2      = zsp2_1 + zsp2_2
+         !--------------------------------------------------------------------
+         !  Storing data
+         !--------------------------------------------------------------------
+         CALL trj_rd_spl(file_wop) 
+         zua_wop  (:,:,:) = ua  (:,:,:)
+         zva_wop  (:,:,:) = va  (:,:,:)
+         CALL trj_rd_spl(file_xdx) 
+         zua_out  (:,:,:) = ua  (:,:,:)
+         zva_out  (:,:,:) = va  (:,:,:)
+         !--------------------------------------------------------------------
+         ! 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 jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zua_out   (ji,jj,jk) = zua_out    (ji,jj,jk) - zua_wop  (ji,jj,jk)
+                  zua_wop   (ji,jj,jk) = zua_out    (ji,jj,jk) - ua_tl    (ji,jj,jk)
+                  IF (  ua_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrua(ji,jj,jk) = zua_out(ji,jj,jk)/ua_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposua(ii) = ji
+                      ijposua(ii) = jj
+                      ikposua(ii) = jk
+                      IF ( INT(umask(ji,jj,jk)) .NE. 0)  THEN
+                         zscua (ii) =  zua_wop(ji,jj,jk)
+                         zscerrua (ii) =  ( zerrua(ji,jj,jk) - 1.0_wp ) /gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         ii=0
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zva_out   (ji,jj,jk) = zva_out    (ji,jj,jk) - zva_wop  (ji,jj,jk)
+                  zva_wop   (ji,jj,jk) = zva_out    (ji,jj,jk) - va_tl    (ji,jj,jk)
+                  IF (  va_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrva(ji,jj,jk) = zva_out(ji,jj,jk)/va_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposva(ii) = ji
+                      ijposva(ii) = jj
+                      ikposva(ii) = jk
+                      IF ( INT(vmask(ji,jj,jk)) .NE. 0)  THEN
+                         zscva (ii) =  zua_wop(ji,jj,jk)
+                         zscerrva (ii) =  ( zerrva(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         zsp1_1    = DOT_PRODUCT( zua_out, zua_out )
+         zsp1_2    = DOT_PRODUCT( zva_out, zva_out  )
+         zsp1      = zsp1_1 + zsp1_2
+
+         zsp3_1    = DOT_PRODUCT( zua_wop, zua_wop )
+         zsp3_2    = DOT_PRODUCT( zva_wop, zva_wop  )
+         zsp3      = zsp3_1 + zsp3_2
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name  = 'dynhpg_tam:En '
+         zzsp     = dsqrt(zsp3)
+         zzsp_1   = dsqrt(zsp3_1)
+         zzsp_2   = dsqrt(zsp3_2)
+
+         zgsp5 = zzsp
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp     = SQRT(zsp2)
+         zzsp_1   = SQRT(zsp2_1)
+         zzsp_2   = SQRT(zsp2_2)
+         zgsp4    = zzsp
+         cl_name  = 'dynhpg_tam:Ln2'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         zzsp     = SQRT(zsp1)
+         zzsp_1   = SQRT(zsp1_1)
+         zzsp_2   = SQRT(zsp1_2)
+         cl_name  = 'dynhpg:Mhdx-Mx'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         zgsp3    = SQRT( zsp3/zsp2 )
+         zgsp7    = zgsp3/gamma
+         zgsp1    = zzsp
+         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) 'dynhpg  ', 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 = 'dynhpg  '
+         IF (lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zscua(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscua     ', &
+                    & cur_loop, h_ratio, ii, iiposua(ii), ijposua(ii), zscua(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscva(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscva     ', &
+                    & cur_loop, h_ratio, ii, iiposva(ii), ijposva(ii), zscva(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrua(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrua  ', &
+                 & cur_loop, h_ratio, ii, iiposua(ii), ijposua(ii), zscerrua(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrva(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrva  ', &
+                    & cur_loop, h_ratio, ii, iiposva(ii), ijposva(ii), zscerrva(ii)
+            ENDDO
+
+           ! write separator
+           WRITE(numtan_sc,"(A4)") '===='
+         ENDIF
+
+      ENDIF
+      DEALLOCATE(                           &
+         & zrd_tlin, zgru_tlin, zgrv_tlin,  & 
+         & zua_tlin, zva_tlin,              & 
+         & ztn_tlin, zsn_tlin,              & 
+         & zua_out, zva_out,                & 
+         & zua_wop, zva_wop,                &
+         & zrh,                             & 
+         & zau,                             & 
+         & zav,                             & 
+         & zgru,                            &
+         & zgrv                             &
+         & )
+   END SUBROUTINE dyn_hpg_tlm_tst
+   !!======================================================================
+#endif
+#endif
+END MODULE dynhpg_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynkeg_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynkeg_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynkeg_tam.F90	(revision 2578)
@@ -0,0 +1,181 @@
+MODULE dynkeg_tam
+#ifdef key_tam
+   !!===========================================================================
+   !!                       ***  MODULE  dynkeg_tam  ***   
+   !! Ocean dynamics:  kinetic energy gradient trend
+   !!======================================================================
+   !! History of the direct module:
+   !!            1.0  !  87-09  (P. Andrich, m.-a. Foujols)  Original code
+   !!            7.0  !  97-05  (G. Madec)  Split dynber into dynkeg and dynhpg
+   !!            9.0  !  02-07  (G. Madec)  F90: Free form and module
+   !! History of the TAM module:
+   !!            9.0  !  08-08  (A. Vidard) first version
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   dyn_keg_tan  : update the momentum trend with the horizontal tke
+   !!   dyn_keg_adj  : update the momentum trend with the horizontal tke
+   !!----------------------------------------------------------------------
+   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           , ONLY: & ! ocean dynamics and tracers
+      & un,                  &
+      & vn
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & e1u,                 &
+      & e2v
+   USE in_out_manager, ONLY: & ! I/O manager
+      & numout,              &
+      & nit000,              &
+      & nitend,              &
+      & lwp
+   USE oce_tam       , ONLY: & ! tam ocean dynamics and tracers
+      & un_tl,               &
+      & vn_tl,               &
+      & ua_tl,               &
+      & va_tl,               &
+      & un_ad,               &
+      & vn_ad,               &
+      & ua_ad,               &
+      & va_ad
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_keg_tan ! routine called by step_tam module
+   PUBLIC   dyn_keg_adj ! routine called by step_tam module
+   
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE dyn_keg_tan( kt )         
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_keg_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Compute the now momentum trend due to the horizontal
+      !!      gradient of the horizontal kinetic energy and add it to the 
+      !!      general momentum trend.
+      !!
+      !! ** Method of the direct routine:
+      !!      Compute the now horizontal kinetic energy 
+      !!         zhke = 1/2 [ mi-1( un^2 ) + mj-1( vn^2 ) ]
+      !!      Take its horizontal gradient and add it to the general momentum
+      !!      trend (ua,va).
+      !!         ua = ua - 1/e1u di[ zhke ]
+      !!         va = va - 1/e2v dj[ zhke ]
+      !!
+      !! ** Action : - Update the (ua_tl, va_tl) with the hor. ke gradient trend
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zutl, zvtl   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhketl   ! temporary 3D workspace
+      !!----------------------------------------------------------------------
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_keg_tan : kinetic energy gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF      
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         DO jj = 2, jpj         ! Horizontal kinetic energy at T-point
+            DO ji = fs_2, jpi   ! vector opt.
+               zutl = 0.5_wp * ( un_tl(ji-1,jj  ,jk) * un(   ji-1,jj  ,jk)   &
+                  &            + un_tl(ji  ,jj  ,jk) * un(   ji  ,jj  ,jk)  ) 
+               zvtl = 0.5_wp * ( vn_tl(ji  ,jj-1,jk) * vn(   ji  ,jj-1,jk)   &
+                  &            + vn(   ji  ,jj  ,jk) * vn_tl(ji  ,jj  ,jk)  )
+               zhketl(ji,jj,jk) = zvtl + zutl
+            END DO  
+         END DO  
+         DO jj = 2, jpjm1       ! add the gradient of kinetic energy to the general momentum trends
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ua_tl(ji,jj,jk) = ua_tl(ji,jj,jk) - ( zhketl(ji+1,jj  ,jk) - zhketl(ji,jj,jk) ) / e1u(ji,jj)
+               va_tl(ji,jj,jk) = va_tl(ji,jj,jk) - ( zhketl(ji  ,jj+1,jk) - zhketl(ji,jj,jk) ) / e2v(ji,jj)
+            END DO 
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+   END SUBROUTINE dyn_keg_tan
+
+   SUBROUTINE dyn_keg_adj( kt )         
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_keg_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Compute the now momentum trend due to the horizontal
+      !!      gradient of the horizontal kinetic energy and add it to the 
+      !!      general momentum trend.
+      !!
+      !! ** Method of the direct routine:
+      !!      Compute the now horizontal kinetic energy 
+      !!         zhke = 1/2 [ mi-1( un^2 ) + mj-1( vn^2 ) ]
+      !!      Take its horizontal gradient and add it to the general momentum
+      !!      trend (ua,va).
+      !!         ua = ua - 1/e1u di[ zhke ]
+      !!         va = va - 1/e2v dj[ zhke ]
+      !!
+      !! ** Action : - Update the (ua_ad, va_ad) with the hor. ke gradient trend
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zuad, zvad   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhkead   ! temporary 3D workspace
+      !!----------------------------------------------------------------------
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_keg_adj : kinetic energy gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF  
+      zhkead(:,:,:) = 0.0_wp ; zuad = 0.0_wp ; zvad = 0.0_wp
+      !                                                ! ===============
+      DO jk = jpkm1, 1, -1                             ! Horizontal slab
+         !                                             ! ===============
+         DO jj =  jpjm1, 2, -1 ! add the gradient of kinetic energy to the general momentum trends
+            DO ji = fs_jpim1, fs_2, -1 ! vector opt.
+               zhkead(ji  ,jj+1,jk) = zhkead(ji  ,jj+1,jk)              &
+                  &                  - va_ad(ji  ,jj  ,jk) / e2v(ji,jj)
+               zhkead(ji  ,jj  ,jk) = zhkead(ji  ,jj  ,jk)              &
+                  &                  + va_ad(ji  ,jj  ,jk) / e2v(ji,jj)
+               zhkead(ji+1,jj  ,jk) = zhkead(ji+1,jj  ,jk) &
+                  &                  - ua_ad(ji  ,jj  ,jk) / e1u(ji,jj)
+               zhkead(ji  ,jj  ,jk) = zhkead(ji  ,jj  ,jk)              &
+                  &                  + ua_ad(ji  ,jj  ,jk) / e1u(ji,jj)
+            END DO 
+         END DO
+         DO jj = jpj, 2, -1         ! Horizontal kinetic energy at T-point
+            DO ji = jpi, fs_2, -1   ! vector opt.
+               zuad = zhkead(ji,jj,jk)
+               zvad = zhkead(ji,jj,jk)
+               zhkead(ji,jj,jk) = 0.0_wp
+
+               vn_ad(ji  ,jj-1,jk) = vn_ad(ji  ,jj-1,jk) + zvad * vn(ji  ,jj-1,jk) * 0.5_wp
+               vn_ad(ji  ,jj  ,jk) = vn_ad(ji  ,jj  ,jk) + zvad * vn(ji  ,jj  ,jk) * 0.5_wp
+               un_ad(ji-1,jj  ,jk) = un_ad(ji-1,jj  ,jk) + zuad * un(ji-1,jj  ,jk) * 0.5_wp
+               un_ad(ji  ,jj  ,jk) = un_ad(ji  ,jj  ,jk) + zuad * un(ji  ,jj  ,jk) * 0.5_wp
+            END DO  
+         END DO  
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+   END SUBROUTINE dyn_keg_adj
+   SUBROUTINE dyn_keg_adj_tst( kumadt )         
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      ! done in dynadv_tam
+   END SUBROUTINE dyn_keg_adj_tst
+#endif
+END MODULE dynkeg_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynldf_bilap_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynldf_bilap_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynldf_bilap_tam.F90	(revision 2578)
@@ -0,0 +1,510 @@
+MODULE dynldf_bilap_tam
+#ifdef key_tam
+   !!===========================================================================
+   !!                       ***  MODULE  dynldf_bilap_tam  ***
+   !! Ocean dynamics:  lateral viscosity trend
+   !!                  Tangent and Adjoint Module
+   !!===========================================================================
+
+   !!---------------------------------------------------------------------------
+   !!   dyn_ldf_bilap_tan : update the momentum trend with the lateral diffusion
+   !!                       using an iso-level bilaplacian operator (tangent)
+   !!   dyn_ldf_bilap_adj : update the momentum trend with the lateral diffusion
+   !!                       using an iso-level bilaplacian operator (adjoint)
+   !!---------------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE lbclnk        , ONLY: & ! Boundary/halo exchange
+      & lbc_lnk
+   USE lbclnk_tam    , ONLY: & ! Boundary/halo exchange (adjoint)
+      & lbc_lnk_adj
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 &
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1
+   USE oce_tam       , ONLY: &
+      & ua_tl,               &
+      & va_tl,               &
+      & ua_ad,               &
+      & va_ad,               &
+      & rotb_tl,             &
+      & hdivb_tl,            &
+      & rotb_ad,             &
+      & hdivb_ad
+   USE ldfdyn_oce    , ONLY: & ! ocean dynamics: lateral physics
+      & ahm3,                &
+      & ahm4,                &
+      & ahm0   
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & ln_sco,              &
+      & ln_zps,              &
+      & fmask,               &
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+      & e1t,                 &
+      & e2t,                 &
+      & e1f,                 &
+      & e2f,                 &
+#if defined key_zco
+      & e3t_0
+#else
+      & e3u,                 &
+      & e3v,                 &
+      & e3t,                 &
+      & e3f
+#endif
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              & 
+      & nit000,              & 
+      & nitend
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dyn_ldf_bilap_tan  ! called by dynldf_tam.F90
+   PUBLIC dyn_ldf_bilap_adj  ! called by dynldf_tam.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldfdyn_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_ldf_bilap_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dyn_ldf_bilap_tan  ***
+      !!
+      !! ** Purpose :   Compute the before trend of the lateral momentum
+      !!      diffusion and add it to the general trend of momentum equation.
+      !!
+      !! ** Method  :   The before horizontal momentum diffusion trend is a 
+      !!      bi-harmonic operator (bilaplacian type) which separates the
+      !!      divergent and rotational parts of the flow.
+      !!      Its horizontal components are computed as follow:
+      !!      laplacian:
+      !!          zlu = 1/e1u di[ hdivb ] - 1/(e2u*e3u) dj-1[ e3f rotb ]
+      !!          zlv = 1/e2v dj[ hdivb ] + 1/(e1v*e3v) di-1[ e3f rotb ]
+      !!      third derivative:
+      !!       * multiply by the eddy viscosity coef. at u-, v-point, resp.
+      !!          zlu = ahmu * zlu
+      !!          zlv = ahmv * zlv
+      !!       * curl and divergence of the laplacian
+      !!          zuf = 1/(e1f*e2f) ( di[e2v zlv] - dj[e1u zlu] )
+      !!          zut = 1/(e1t*e2t*e3t) ( di[e2u*e3u zlu] + dj[e1v*e3v zlv] )
+      !!      bilaplacian:
+      !!              diffu = 1/e1u di[ zut ] - 1/(e2u*e3u) dj-1[ e3f zuf ]
+      !!              diffv = 1/e2v dj[ zut ] + 1/(e1v*e3v) di-1[ e3f zuf ]
+      !!      If ln_sco=F and ln_zps=F, the vertical scale factors in the
+      !!      rotational part of the diffusion are simplified
+      !!      Add this before trend to the general trend (ua,va):
+      !!            (ua,va) = (ua,va) + (diffu,diffv)
+      !!      'key_trddyn' defined: the two components of the horizontal
+      !!                               diffusion trend are saved.
+      !!
+      !! ** Action : - Update (ua,va) with the before iso-level biharmonic
+      !!               mixing trend.
+      !!
+      !! History :
+      !!        !  90-09  (G. Madec)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  93-03  (M. Guyon)  symetrical conditions (M. Guyon)
+      !!        !  96-01  (G. Madec)  statement function for e3
+      !!        !  97-07  (G. Madec)  lbc calls
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-08  (C. Talandier) New trends organization
+      !! History of the tangent routine
+      !!   9.0  !  09-12 (F. Vigilant) tangent of 9.0
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt           ! ocean time-step index
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk                ! dummy loop indices
+      REAL(wp) ::   &
+         zuatl, zvatl, zbt, ze2u, ze2v        ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::       &
+         zcutl, zcvtl                         ! temporary workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zuftl, zuttl, zlutl, zlvtl           ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_ldf_bilap_tan: iso-level bilaplacien operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~ '
+      ENDIF
+
+      zuftl(:,:,:) = 0.0_wp
+      zuttl(:,:,:) = 0.0_wp
+      zlutl(:,:,:) = 0.0_wp
+      zlvtl(:,:,:) = 0.0_wp
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Laplacian
+         ! ---------
+
+         IF( ln_sco .OR. ln_zps ) THEN   ! s-coordinate or z-coordinate with partial steps
+            zuftl(:,:,jk) = rotb_tl(:,:,jk) * fse3f(:,:,jk)
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zlutl(ji,jj,jk) = - ( zuftl(ji,jj,jk) - zuftl(ji,jj-1,jk) ) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )   &
+                     &         + ( hdivb_tl(ji+1,jj,jk) - hdivb_tl(ji,jj,jk) ) / e1u(ji,jj)
+   
+                  zlvtl(ji,jj,jk) = + ( zuftl(ji,jj,jk) - zuftl(ji-1,jj,jk) ) / ( e1v(ji,jj) * fse3v(ji,jj,jk) )   &
+                     &         + ( hdivb_tl(ji,jj+1,jk) - hdivb_tl(ji,jj,jk) ) / e2v(ji,jj)
+               END DO
+            END DO
+         ELSE                            ! z-coordinate - full step
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zlutl(ji,jj,jk) = - ( rotb_tl (ji  ,jj,jk) - rotb_tl (ji,jj-1,jk) ) / e2u(ji,jj)   &
+                     &         + ( hdivb_tl(ji+1,jj,jk) - hdivb_tl(ji,jj  ,jk) ) / e1u(ji,jj)
+   
+                  zlvtl(ji,jj,jk) = + ( rotb_tl (ji,jj  ,jk) - rotb_tl (ji-1,jj,jk) ) / e1v(ji,jj)   &
+                     &         + ( hdivb_tl(ji,jj+1,jk) - hdivb_tl(ji  ,jj,jk) ) / e2v(ji,jj)
+               END DO  
+            END DO  
+         ENDIF
+      ENDDO
+
+      ! Boundary conditions on the laplacian  (zlu,zlv)
+      CALL lbc_lnk( zlutl, 'U', -1.0_wp )
+      CALL lbc_lnk( zlvtl, 'V', -1.0_wp )
+
+      DO jk = 1, jpkm1
+   
+         ! Third derivative
+         ! ----------------
+         
+         ! Multiply by the eddy viscosity coef. (at u- and v-points)
+         zlutl(:,:,jk) = zlutl(:,:,jk) * fsahmu(:,:,jk)
+         zlvtl(:,:,jk) = zlvtl(:,:,jk) * fsahmv(:,:,jk)
+         
+         ! Contravariant "laplacian"
+         zcutl(:,:) = e1u(:,:) * zlutl(:,:,jk)
+         zcvtl(:,:) = e2v(:,:) * zlvtl(:,:,jk)
+         
+         ! Laplacian curl ( * e3f if s-coordinates or z-coordinate with partial steps)
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zuftl(ji,jj,jk) = fmask(ji,jj,jk) * (  zcvtl(ji+1,jj  ) - zcvtl(ji,jj)      &
+                  &                            - zcutl(ji  ,jj+1) + zcutl(ji,jj)  )   &
+#if defined key_zco
+                  &                         / ( e1f(ji,jj)*e2f(ji,jj) )
+#else
+                  &       * fse3f(ji,jj,jk) / ( e1f(ji,jj)*e2f(ji,jj) )
+#endif
+            END DO  
+         END DO
+
+         ! Laplacian Horizontal fluxes
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+#if defined key_zco
+               zlutl(ji,jj,jk) = e2u(ji,jj) * zlutl(ji,jj,jk)
+               zlvtl(ji,jj,jk) = e1v(ji,jj) * zlvtl(ji,jj,jk)
+#else
+               zlutl(ji,jj,jk) = e2u(ji,jj) * fse3u(ji,jj,jk) * zlutl(ji,jj,jk)
+               zlvtl(ji,jj,jk) = e1v(ji,jj) * fse3v(ji,jj,jk) * zlvtl(ji,jj,jk)
+#endif
+            END DO
+         END DO
+
+         ! Laplacian divergence
+         DO jj = 2, jpj
+            DO ji = fs_2, jpi   ! vector opt.
+#if defined key_zco
+               zbt = e1t(ji,jj) * e2t(ji,jj)
+#else
+               zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+#endif
+               zuttl(ji,jj,jk) = (  zlutl(ji,jj,jk) - zlutl(ji-1,jj  ,jk)   &
+                  &             + zlvtl(ji,jj,jk) - zlvtl(ji  ,jj-1,jk) ) / zbt
+            END DO
+         END DO
+      END DO
+
+      ! boundary conditions on the laplacian curl and div (zuf,zut)
+!!bug gm no need to do this 2 following lbc...
+      CALL lbc_lnk( zuftl, 'F', 1.0_wp )
+      CALL lbc_lnk( zuttl, 'T', 1.0_wp )
+
+      DO jk = 1, jpkm1      
+   
+         ! Bilaplacian
+         ! -----------
+
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+               ze2u = e2u(ji,jj)
+               ze2v = e1v(ji,jj)
+#else
+               ze2u = e2u(ji,jj) * fse3u(ji,jj,jk)
+               ze2v = e1v(ji,jj) * fse3v(ji,jj,jk)
+#endif
+               ! horizontal biharmonic diffusive trends
+               zuatl = - ( zuftl(ji  ,jj,jk) - zuftl(ji,jj-1,jk) ) / ze2u   &
+                  &  + ( zuttl(ji+1,jj,jk) - zuttl(ji,jj  ,jk) ) / e1u(ji,jj)
+
+               zvatl = + ( zuftl(ji,jj  ,jk) - zuftl(ji-1,jj,jk) ) / ze2v   &
+                  &  + ( zuttl(ji,jj+1,jk) - zuttl(ji  ,jj,jk) ) / e2v(ji,jj)
+               ! add it to the general momentum trends
+               ua_tl(ji,jj,jk) = ua_tl(ji,jj,jk) + zuatl
+               va_tl(ji,jj,jk) = va_tl(ji,jj,jk) + zvatl
+            END DO
+         END DO
+
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+   END SUBROUTINE dyn_ldf_bilap_tan
+
+
+   SUBROUTINE dyn_ldf_bilap_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dyn_ldf_bilap_adj  ***
+      !!
+      !! ** Purpose :   Compute the before trend of the lateral momentum
+      !!      diffusion and add it to the general trend of momentum equation.
+      !!
+      !! ** Method  :   The before horizontal momentum diffusion trend is a 
+      !!      bi-harmonic operator (bilaplacian type) which separates the
+      !!      divergent and rotational parts of the flow.
+      !!      Its horizontal components are computed as follow:
+      !!      laplacian:
+      !!          zlu = 1/e1u di[ hdivb ] - 1/(e2u*e3u) dj-1[ e3f rotb ]
+      !!          zlv = 1/e2v dj[ hdivb ] + 1/(e1v*e3v) di-1[ e3f rotb ]
+      !!      third derivative:
+      !!       * multiply by the eddy viscosity coef. at u-, v-point, resp.
+      !!          zlu = ahmu * zlu
+      !!          zlv = ahmv * zlv
+      !!       * curl and divergence of the laplacian
+      !!          zuf = 1/(e1f*e2f) ( di[e2v zlv] - dj[e1u zlu] )
+      !!          zut = 1/(e1t*e2t*e3t) ( di[e2u*e3u zlu] + dj[e1v*e3v zlv] )
+      !!      bilaplacian:
+      !!              diffu = 1/e1u di[ zut ] - 1/(e2u*e3u) dj-1[ e3f zuf ]
+      !!              diffv = 1/e2v dj[ zut ] + 1/(e1v*e3v) di-1[ e3f zuf ]
+      !!      If ln_sco=F and ln_zps=F, the vertical scale factors in the
+      !!      rotational part of the diffusion are simplified
+      !!      Add this before trend to the general trend (ua,va):
+      !!            (ua,va) = (ua,va) + (diffu,diffv)
+      !!      'key_trddyn' defined: the two components of the horizontal
+      !!                               diffusion trend are saved.
+      !!
+      !! ** Action : - Update (ua,va) with the before iso-level biharmonic
+      !!               mixing trend.
+      !!
+      !! History :
+      !!        !  90-09  (G. Madec)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  93-03  (M. Guyon)  symetrical conditions (M. Guyon)
+      !!        !  96-01  (G. Madec)  statement function for e3
+      !!        !  97-07  (G. Madec)  lbc calls
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-08  (C. Talandier) New trends organization
+      !! History of the adjoint routine
+      !!   9.0  !  09-12 (F. Vigilant) adjoint of 9.0
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk            ! dummy loop indices
+      REAL(wp) ::   &
+         zuaad, zvaad, zbt, ze2u, ze2v        ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::       &
+         zcuad, zcvad                         ! temporary workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zufad, zutad, zluad, zlvad           ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_ldf_bilap_adj: bilaplacien operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~ '
+      ENDIF
+
+      zuaad = 0.0_wp
+      zvaad = 0.0_wp
+
+      zufad(:,:,:) = 0.0_wp
+      zutad(:,:,:) = 0.0_wp
+      zluad(:,:,:) = 0.0_wp
+      zlvad(:,:,:) = 0.0_wp
+
+      zcvad(:,:) = 0.0_wp
+      zcuad(:,:) = 0.0_wp
+
+      DO jk = 1, jpkm1      
+   
+         ! Bilaplacian
+         ! -----------
+
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+#if defined key_zco
+               ze2u = e2u(ji,jj)
+               ze2v = e1v(ji,jj)
+#else
+               ze2u = e2u(ji,jj) * fse3u(ji,jj,jk)
+               ze2v = e1v(ji,jj) * fse3v(ji,jj,jk)
+#endif
+               ! add it to the general momentum trends
+               zvaad = zvaad + va_ad(ji,jj,jk) 
+               zuaad = zuaad + ua_ad(ji,jj,jk)
+
+               ! horizontal biharmonic diffusive trends
+               zufad(ji  ,jj  ,jk) = zufad(ji  ,jj  ,jk) + zvaad / ze2v
+               zufad(ji-1,jj  ,jk) = zufad(ji-1,jj  ,jk) - zvaad / ze2v
+               zutad(ji  ,jj  ,jk) = zutad(ji  ,jj  ,jk) - zvaad / e2v(ji,jj)
+               zutad(ji  ,jj+1,jk) = zutad(ji  ,jj+1,jk) + zvaad / e2v(ji,jj)
+
+               zufad(ji  ,jj  ,jk) = zufad(ji  ,jj  ,jk) - zuaad / ze2u
+               zufad(ji  ,jj-1,jk) = zufad(ji  ,jj-1,jk) + zuaad / ze2u
+               zutad(ji  ,jj  ,jk) = zutad(ji  ,jj  ,jk) - zuaad / e1u(ji,jj)
+               zutad(ji+1,jj  ,jk) = zutad(ji+1,jj  ,jk) + zuaad / e1u(ji,jj)
+
+               zuaad = 0.0_wp
+               zvaad = 0.0_wp
+            END DO
+         END DO
+
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      ! boundary conditions on the laplacian curl and div (zuf,zut)
+!!bug gm no need to do this 2 following lbc...
+      CALL lbc_lnk_adj( zutad, 'T', 1.0_wp )
+      CALL lbc_lnk_adj( zufad, 'F', 1.0_wp )
+
+      DO jk = 1, jpkm1
+   
+         ! Third derivative
+         ! ----------------
+
+         ! Laplacian divergence
+         DO jj = jpj, 2, -1
+            DO ji = jpi, fs_2, -1   ! vector opt.
+#if defined key_zco
+               zbt = e1t(ji,jj) * e2t(ji,jj)
+#else
+               zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+#endif
+               zluad(ji  ,jj  ,jk) = zluad(ji  ,jj  ,jk) + zutad(ji,jj,jk) / zbt
+               zluad(ji-1,jj  ,jk) = zluad(ji-1,jj  ,jk) - zutad(ji,jj,jk) / zbt 
+               zlvad(ji  ,jj  ,jk) = zlvad(ji  ,jj  ,jk) + zutad(ji,jj,jk) / zbt
+               zlvad(ji  ,jj-1,jk) = zlvad(ji  ,jj-1,jk) - zutad(ji,jj,jk) / zbt     
+
+               zutad(ji,jj,jk) = 0.0_wp
+            END DO
+         END DO
+
+         ! Laplacian Horizontal fluxes
+         DO jj = jpjm1, 1, -1
+            DO ji = fs_jpim1, 1, -1   ! vector opt.
+#if defined key_zco
+               zluad(ji,jj,jk) = e2u(ji,jj) * zluad(ji,jj,jk)
+               zlvad(ji,jj,jk) = e1v(ji,jj) * zlvad(ji,jj,jk)
+#else
+               zluad(ji,jj,jk) = e2u(ji,jj) * fse3u(ji,jj,jk) * zluad(ji,jj,jk)
+               zlvad(ji,jj,jk) = e1v(ji,jj) * fse3v(ji,jj,jk) * zlvad(ji,jj,jk)
+#endif
+            END DO
+         END DO
+
+         ! Laplacian curl ( * e3f if s-coordinates or z-coordinate with partial steps)
+         DO jj = jpjm1, 1, -1
+            DO ji = fs_jpim1, 1, -1   ! vector opt.
+#if defined key_zco
+               zufad(ji,jj,jk) = fmask(ji,jj,jk) * zufad(ji,jj,jk) / ( e1f(ji,jj)*e2f(ji,jj) )
+#else
+               zufad(ji,jj,jk) = fmask(ji,jj,jk) * zufad(ji,jj,jk) * fse3f(ji,jj,jk) / ( e1f(ji,jj)*e2f(ji,jj) )
+#endif
+               zcvad(ji  ,jj  ) = zcvad(ji  ,jj  ) - zufad(ji,jj,jk)
+               zcvad(ji+1,jj  ) = zcvad(ji+1,jj  ) + zufad(ji,jj,jk)
+               zcuad(ji  ,jj  ) = zcuad(ji  ,jj  ) + zufad(ji,jj,jk)
+               zcuad(ji  ,jj+1) = zcuad(ji  ,jj+1) - zufad(ji,jj,jk)                 
+
+               zufad(ji,jj,jk) = 0.0_wp
+            END DO  
+         END DO
+
+         ! Contravariant "laplacian"
+         DO jj = 1, jpj
+            DO ji = 1, jpi  
+               zlvad(ji,jj,jk) = zlvad(ji,jj,jk) + e2v(ji,jj) * zcvad(ji,jj)
+               zluad(ji,jj,jk) = zluad(ji,jj,jk) + e1u(ji,jj) * zcuad(ji,jj)
+               zcvad(ji,jj) = 0.0_wp
+               zcuad(ji,jj) = 0.0_wp
+            END DO  
+         END DO
+         
+         ! Multiply by the eddy viscosity coef. (at u- and v-points) 
+         zluad(:,:,jk) = zluad(:,:,jk) * fsahmu(:,:,jk)
+         zlvad(:,:,jk) = zlvad(:,:,jk) * fsahmv(:,:,jk)
+
+      END DO
+
+      ! Boundary conditions on the laplacian  (zlu,zlv)
+      CALL lbc_lnk_adj( zlvad, 'V', -1.0_wp )
+      CALL lbc_lnk_adj( zluad, 'U', -1.0_wp )
+
+       !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Laplacian
+         ! ---------
+
+         IF( ln_sco .OR. ln_zps ) THEN   ! s-coordinate or z-coordinate with partial steps
+            DO jj = jpjm1, 2, -1
+               DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+                  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
+
+                  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)
+                  zluad(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
+               DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+                  rotb_ad (ji  ,jj  ,jk) = rotb_ad (ji  ,jj  ,jk) + zlvad(ji,jj,jk) / e1v(ji,jj)
+                  rotb_ad (ji-1,jj  ,jk) = rotb_ad (ji-1,jj  ,jk) - zlvad(ji,jj,jk) / e1v(ji,jj)
+                  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) / e2u(ji,jj)
+                  rotb_ad (ji  ,jj-1,jk) = rotb_ad (ji  ,jj-1,jk) + zluad(ji,jj,jk) / e2u(ji,jj)
+                  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
+               END DO  
+            END DO  
+         ENDIF
+      ENDDO
+
+   END SUBROUTINE dyn_ldf_bilap_adj
+
+   !!======================================================================
+#endif
+END MODULE dynldf_bilap_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynldf_lap_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynldf_lap_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynldf_lap_tam.F90	(revision 2578)
@@ -0,0 +1,268 @@
+MODULE dynldf_lap_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  dynldf_lap_tam  ***
+   !! Ocean dynamics:  lateral viscosity trend
+   !!                  Tangent and Adjoint Module
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dyn_ldf_lap_tan  : update the momentum trend with the lateral diffusion
+   !!                      using an iso-level harmonic operator (tangent)
+   !!   dyn_ldf_lap_adj  : update the momentum trend with the lateral diffusion
+   !!                      using an iso-level harmonic operator (adjoint)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1
+   USE oce_tam       , ONLY: &
+      & ua_tl,               &
+      & va_tl,               &
+      & ua_ad,               &
+      & va_ad,               &
+      & rotb_tl,             &
+      & hdivb_tl,            &
+      & rotb_ad,             &
+      & hdivb_ad
+   USE ldfdyn_oce    , ONLY: & ! ocean dynamics: lateral physics
+      & ahm2,                &
+      & ahm1,                &
+      & ahm0   
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+#if defined key_zco
+      & e3t_0
+#else
+      & e3u,                 &
+      & e3v,                 &
+      & e3f
+#endif
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              & 
+      & nit000,              & 
+      & nitend
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dyn_ldf_lap_tan  ! called by dynldf_tam.F90
+   PUBLIC dyn_ldf_lap_adj  ! called by dynldf_tam.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldfdyn_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_ldf_lap_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dyn_ldf_lap_tan  ***
+      !!                       
+      !! ** Purpose of the direct routine:
+      !!      Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method of the direct routine:
+      !!      The before horizontal momentum diffusion trend is an
+      !!      harmonic operator (laplacian type) which separates the divergent
+      !!      and rotational parts of the flow.
+      !!      Its horizontal components are computed as follow:
+      !!         difu = 1/e1u di[ahmt hdivb] - 1/(e2u*e3u) dj-1[e3f ahmf rotb]
+      !!         difv = 1/e2v dj[ahmt hdivb] + 1/(e1v*e3v) di-1[e3f ahmf rotb]
+      !!      If lk_zco=T, e3f=e3u=e3v, the vertical scale factor are simplified
+      !!      in the rotational part of the diffusion.
+      !!      Add this before trend to the general trend (ua,va):
+      !!            (ua,va) = (ua,va) + (diffu,diffv)
+      !!      'key_trddyn' activated: the two components of the horizontal
+      !!                                 diffusion trend are saved.
+      !!
+      !! ** Action : - Update (ua,va) with the before iso-level harmonic 
+      !!               mixing trend.
+      !!
+      !! History of the direct routine:
+      !!        !  90-09 (G. Madec) Original code
+      !!        !  91-11 (G. Madec)
+      !!        !  96-01 (G. Madec) statement function for e3 and ahm
+      !!   8.5  !  02-06 (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-08 (C. Talandier) New trends organization
+      !! History of the tangent routine
+      !!   9.0  !  08-08 (A. Vidard) tangent of 9.0
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk            ! dummy loop indices
+      REAL(wp) ::   &
+         zuatl, zvatl, ze2utl, ze1vtl             ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_ldf_tan: iso-level harmonic (laplacien) operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+# if defined key_zco
+               ! horizontal diffusive trends
+               ze2utl = rotb_tl (ji,jj,jk) * fsahmf(ji,jj,jk)
+               ze1vtl = hdivb_tl(ji,jj,jk) * fsahmt(ji,jj,jk)
+
+               zuatl = - ( ze2utl - rotb_tl (ji  ,jj-1,jk) * fsahmf(ji  ,jj-1,jk) ) / e2u(ji,jj)   &
+                  &    + ( hdivb_tl(ji+1,jj  ,jk) * fsahmt(ji+1,jj  ,jk) - ze1vtl ) / e1u(ji,jj)
+
+               zvatl = + ( ze2utl - rotb_tl (ji-1,jj  ,jk) * fsahmf(ji-1,jj  ,jk) ) / e1v(ji,jj)   &
+                  &    + ( hdivb_tl(ji  ,jj+1,jk) * fsahmt(ji  ,jj+1,jk) - ze1vtl ) / e2v(ji,jj)
+# else
+               ! horizontal diffusive trends
+               ze2utl = rotb_tl (ji,jj,jk) * fsahmf(ji,jj,jk) * fse3f(ji,jj,jk)
+               ze1vtl = hdivb_tl(ji,jj,jk) * fsahmt(ji,jj,jk)
+
+               zuatl = - ( ze2utl - rotb_tl(ji  ,jj-1,jk) * fsahmf(ji  ,jj-1,jk) * fse3f(ji  ,jj-1,jk) ) &
+                  &     / ( e2u(ji,jj) * fse3u(ji,jj,jk) )  &
+                  &    + ( hdivb_tl(ji+1,jj  ,jk) * fsahmt(ji+1,jj  ,jk) - ze1vtl ) / e1u(ji,jj)
+
+               zvatl = + ( ze2utl - rotb_tl(ji-1,jj  ,jk) * fsahmf(ji-1,jj  ,jk) * fse3f(ji-1,jj  ,jk) ) &
+                  &     / ( e1v(ji,jj) * fse3v(ji,jj,jk) )  &
+                  &    + ( hdivb_tl(ji  ,jj+1,jk) * fsahmt(ji  ,jj+1,jk) - ze1vtl ) / e2v(ji,jj)
+# endif
+               ! add it to the general momentum trends
+               ua_tl(ji,jj,jk) = ua_tl(ji,jj,jk) + zuatl
+               va_tl(ji,jj,jk) = va_tl(ji,jj,jk) + zvatl
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+   END SUBROUTINE dyn_ldf_lap_tan
+
+   SUBROUTINE dyn_ldf_lap_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dyn_ldf_lap_adj  ***
+      !!                       
+      !! ** Purpose of the direct routine:
+      !!      Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method of the direct routine:
+      !!      The before horizontal momentum diffusion trend is an
+      !!      harmonic operator (laplacian type) which separates the divergent
+      !!      and rotational parts of the flow.
+      !!      Its horizontal components are computed as follow:
+      !!         difu = 1/e1u di[ahmt hdivb] - 1/(e2u*e3u) dj-1[e3f ahmf rotb]
+      !!         difv = 1/e2v dj[ahmt hdivb] + 1/(e1v*e3v) di-1[e3f ahmf rotb]
+      !!      If lk_zco=T, e3f=e3u=e3v, the vertical scale factor are simplified
+      !!      in the rotational part of the diffusion.
+      !!      Add this before trend to the general trend (ua,va):
+      !!            (ua,va) = (ua,va) + (diffu,diffv)
+      !!      'key_trddyn' activated: the two components of the horizontal
+      !!                                 diffusion trend are saved.
+      !!
+      !! ** Action : - Update (ua,va) with the before iso-level harmonic 
+      !!               mixing trend.
+      !!
+      !! History of the direct routine:
+      !!        !  90-09 (G. Madec) Original code
+      !!        !  91-11 (G. Madec)
+      !!        !  96-01 (G. Madec) statement function for e3 and ahm
+      !!   8.5  !  02-06 (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-08 (C. Talandier) New trends organization
+      !! History of the adjoint routine
+      !!   9.0  !  08-08 (A. Vidard) adjoint of 9.0
+      !!    -   !  09-01 (A. Weaver) misc. bug fixes and reorganization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk            ! dummy loop indices
+      REAL(wp) ::   &
+           zuaad , zvaad , ze2uad, ze1vad, &        ! temporary scalars
+         & zuaad1, zvaad1, zuaad2, zvaad2           ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_ldf_adj: iso-level harmonic (laplacien) operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+
+      !                                                ! ===============
+      DO jk = jpkm1, 1, -1                                ! Horizontal slab
+         !                                             ! ===============
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+
+               ! add it to the general momentum trends
+               zuaad = ua_ad(ji,jj,jk) 
+               zvaad = va_ad(ji,jj,jk)
+# if defined key_zco
+               ! horizontal diffusive trends
+               zvaad1 = zvaad / e2v(ji,jj)
+               zvaad2 = zvaad / e1v(ji,jj)
+               zuaad1 = zuaad / e1u(ji,jj)
+               zuaad2 = zuaad / e2u(ji,jj)
+
+               ze1vad = - zvaad1 - zuaad1
+               ze2uad =   zvaad2 - zuaad2
+
+               rotb_ad (ji-1,jj  ,jk) = rotb_ad (ji-1,jj  ,jk) - zvaad2 * fsahmf(ji-1,jj  ,jk)
+               rotb_ad (ji  ,jj-1,jk) = rotb_ad (ji  ,jj-1,jk) + zuaad2 * fsahmf(ji  ,jj-1,jk)
+               rotb_ad (ji  ,jj  ,jk) = rotb_ad (ji  ,jj  ,jk) + ze2uad * fsahmf(ji  ,jj  ,jk)
+
+               hdivb_ad(ji  ,jj+1,jk) = hdivb_ad(ji  ,jj+1,jk) + zvaad1 * fsahmt(ji  ,jj+1,jk)
+               hdivb_ad(ji  ,jj  ,jk) = hdivb_ad(ji  ,jj  ,jk) + ze1vad * fsahmt(ji  ,jj  ,jk)
+               hdivb_ad(ji+1,jj  ,jk) = hdivb_ad(ji+1,jj  ,jk) + zuaad1 * fsahmt(ji+1,jj  ,jk)
+# else
+               ! horizontal diffusive trends
+               zvaad1 = zvaad /   e2v(ji,jj)
+               zvaad2 = zvaad / ( e1v(ji,jj) * fse3v(ji,jj,jk) ) 
+               zuaad1 = zuaad /   e1u(ji,jj)
+               zuaad2 = zuaad / ( e2u(ji,jj) * fse3u(ji,jj,jk) )
+
+               ze1vad = - zvaad1 - zuaad1
+               ze2uad =   zvaad2 - zuaad2
+
+               rotb_ad (ji-1,jj  ,jk) = rotb_ad (ji-1,jj  ,jk) &
+                  &                   - zvaad2 * fsahmf(ji-1,jj  ,jk) * fse3f(ji-1,jj  ,jk)
+               rotb_ad (ji  ,jj-1,jk) = rotb_ad (ji  ,jj-1,jk) &
+                  &                   + zuaad2 * fsahmf(ji  ,jj-1,jk) * fse3f(ji  ,jj-1,jk)
+               rotb_ad (ji  ,jj  ,jk) = rotb_ad (ji  ,jj  ,jk) &
+                  &                   + ze2uad * fsahmf(ji  ,jj  ,jk) * fse3f(ji  ,jj  ,jk)
+
+               hdivb_ad(ji  ,jj+1,jk) = hdivb_ad(ji  ,jj+1,jk) &
+                  &                   + zvaad1 * fsahmt(ji  ,jj+1,jk)
+               hdivb_ad(ji  ,jj  ,jk) = hdivb_ad(ji  ,jj  ,jk) &
+                  &                   + ze1vad * fsahmt(ji  ,jj  ,jk)
+               hdivb_ad(ji+1,jj  ,jk) = hdivb_ad(ji+1,jj  ,jk) &
+                  &                   + zuaad1 * fsahmt(ji+1,jj  ,jk)
+
+# endif
+
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+   END SUBROUTINE dyn_ldf_lap_adj
+
+   !!======================================================================
+#endif
+END MODULE dynldf_lap_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynldf_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynldf_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynldf_tam.F90	(revision 2578)
@@ -0,0 +1,519 @@
+MODULE dynldf_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  dynldf_tam  ***
+   !! Ocean physics:  lateral diffusivity trends 
+   !!                 Tangent and Adjoint module
+   !!=====================================================================
+   !! History of the direct module:
+   !!          9.0  !  05-11  (G. Madec)  Original code (new step architecture)
+   !! History of the TAM module
+   !!          9.0  !  08-06  (A. Vidard) Skeleton 
+   !!               !  08-08  (A. Vidard) TAM of 9.0
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_ldf     : update the dynamics trend with the lateral diffusion
+   !!   dyn_ldf_ctl : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 & 
+      & jpiglo
+   USE oce_tam       , ONLY: &
+      & ua_tl,               &
+      & va_tl,               &
+      & ua_ad,               &
+      & va_ad,               &
+      & rotb_tl,             &
+      & hdivb_tl,            &
+      & rotb_ad,             &
+      & hdivb_ad
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & ln_zco,              &
+      & ln_sco,              &
+      & ln_zps,              &
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3u,                 &
+      & e3v,                 &
+#endif
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      & umask,               &
+      & vmask
+   USE ldfdyn_oce    , ONLY: & ! ocean dynamics lateral physics
+      & ln_dynldf_lap,       &     
+      & ln_dynldf_bilap,     &
+      & ln_dynldf_level,     &
+      & ln_dynldf_hor,       &
+      & ln_dynldf_iso
+   USE ldfslp        , ONLY: & ! lateral mixing: slopes of mixing orientation
+      & lk_ldfslp
+!   USE dynldf_bilapg_tam    ! lateral mixing       (dyn_ldf_bilapg routine)
+   USE dynldf_bilap_tam, ONLY: &     ! lateral mixing       (dyn_ldf_bilap  routine)
+      & dyn_ldf_bilap_tan,     &
+      & dyn_ldf_bilap_adj
+!   USE dynldf_iso_tam       ! lateral mixing       (dyn_ldf_iso    routine)
+   USE dynldf_lap_tam, ONLY: & ! lateral mixing       (dyn_ldf_lap    routine)
+      & dyn_ldf_lap_tan,     &
+      & dyn_ldf_lap_adj
+   USE in_out_manager, ONLY: & ! I/O manager
+      & ctl_stop,            &
+      & nit000,              &
+      & nitend,              &
+      & numout,              &
+      & lwp
+!   USE lib_mpp        , ONLY: & ! distribued memory computing library
+!   USE lbclnk         , ONLY: & ! ocean lateral boundary conditions (or mpp link)
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          & !
+                               ! random field standard deviation for:
+      & stdu,                & !   u-velocity
+      & stdv,                & !   v-velocity
+      & stdr,                & !   rotb
+      & stdh                   !   hdivb
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_ldf_tan        ! called by step_tam module 
+   PUBLIC   dyn_ldf_adj        ! called by step_tam module 
+   PUBLIC   dyn_ldf_adj_tst    ! called by the tst  module 
+
+   INTEGER ::   nldf = 0   ! type of lateral diffusion used defined from ln_dynldf_... namlist logicals)
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_ldf_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_ldf_tan  ***
+      !! 
+      !! ** Purpose of the direct routine:
+      !!            compute the lateral ocean dynamics physics.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL dyn_ldf_ctl_tam      ! initialisation & control of options
+
+      SELECT CASE ( nldf )                       ! compute lateral mixing trend and add it to the general trend
+      !
+      CASE ( 0 )    
+         CALL dyn_ldf_lap_tan    ( kt )      ! iso-level laplacian
+      CASE ( 1 )    
+         CALL ctl_stop('dyn_ldf_iso_tan not available yet')
+!         CALL dyn_ldf_iso_tan    ( kt )      ! rotated laplacian (except dk[ dk[.] ] part)
+      CASE ( 2 )   
+         CALL dyn_ldf_bilap_tan  ( kt )      ! iso-level bilaplacian
+      CASE ( 3 )
+         CALL ctl_stop('dyn_ldf_bilapg_tan not available yet')
+!         CALL dyn_ldf_bilapg_tan ( kt )      ! s-coord. horizontal bilaplacian
+      !
+      END SELECT
+      !
+   END SUBROUTINE dyn_ldf_tan
+
+   SUBROUTINE dyn_ldf_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_ldf_adj  ***
+      !! 
+      !! ** Purpose of the direct routine:
+      !!            compute the lateral ocean dynamics physics.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      IF( kt == nitend )   CALL dyn_ldf_ctl_tam      ! initialisation & control of options
+
+      SELECT CASE ( nldf )                       ! compute lateral mixing trend and add it to the general trend
+      !
+      CASE ( 0 )    
+         CALL dyn_ldf_lap_adj    ( kt )      ! iso-level laplacian
+      CASE ( 1 ) 
+         CALL ctl_stop('dyn_ldf_iso_adj not available yet')
+!         CALL dyn_ldf_iso_adj    ( kt )      ! rotated laplacian (except dk[ dk[.] ] part)
+      CASE ( 2 )   
+         CALL dyn_ldf_bilap_adj  ( kt )      ! iso-level bilaplacian
+      CASE ( 3 )
+         CALL ctl_stop('dyn_ldf_bilapg_adj not available yet')
+!         CALL dyn_ldf_bilapg_adj ( kt )      ! s-coord. horizontal bilaplacian
+      !
+      END SELECT      !
+   END SUBROUTINE dyn_ldf_adj
+
+   SUBROUTINE dyn_ldf_ctl_tam
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_ldf_ctl_tam  ***
+      !! 
+      !! ** Purpose of the direct routine:
+      !!            initializations of the horizontal ocean dynamics physics
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio, ierr         ! temporary integers 
+      !!----------------------------------------------------------------------
+    
+      !                                   ! Namelist nam_dynldf: already read in ldfdyn module
+
+      IF(lwp) THEN                        ! Namelist print
+         WRITE(numout,*)
+         WRITE(numout,*) 'dyn_ldf_ctl_tam : Choice of the lateral diffusive operator on dynamics'
+         WRITE(numout,*) '~~~~~~~~~~~~~~'
+         WRITE(numout,*) '       Namelist nam_dynldf : set lateral mixing parameters (type, direction, coefficients)'
+         WRITE(numout,*) '          laplacian operator          ln_dynldf_lap   = ', ln_dynldf_lap
+         WRITE(numout,*) '          bilaplacian operator        ln_dynldf_bilap = ', ln_dynldf_bilap
+         WRITE(numout,*) '          iso-level                   ln_dynldf_level = ', ln_dynldf_level
+         WRITE(numout,*) '          horizontal (geopotential)   ln_dynldf_hor   = ', ln_dynldf_hor
+         WRITE(numout,*) '          iso-neutral                 ln_dynldf_iso   = ', ln_dynldf_iso
+      ENDIF
+
+      !                                   ! control the consistency
+      ioptio = 0
+      IF( ln_dynldf_lap   )   ioptio = ioptio + 1
+      IF( ln_dynldf_bilap )   ioptio = ioptio + 1
+      IF( ioptio /= 1 ) CALL ctl_stop( '          use ONE of the 2 lap/bilap operator type on dynamics' )
+      ioptio = 0
+      IF( ln_dynldf_level )   ioptio = ioptio + 1
+      IF( ln_dynldf_hor   )   ioptio = ioptio + 1
+      IF( ln_dynldf_iso   )   ioptio = ioptio + 1
+      IF( ioptio /= 1 ) CALL ctl_stop( '          use only ONE direction (level/hor/iso)' )
+
+      !                                   ! Set nldf, the type of lateral diffusion, from ln_dynldf_... logicals
+      ierr = 0
+      IF ( ln_dynldf_lap ) THEN      ! laplacian operator
+         IF ( ln_zco ) THEN                ! z-coordinate
+            IF ( ln_dynldf_level )   nldf = 0      ! iso-level  (no rotation)
+            IF ( ln_dynldf_hor   )   nldf = 0      ! horizontal (no rotation)
+            IF ( ln_dynldf_iso   )   nldf = 1      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_zps ) THEN             ! z-coordinate
+            IF ( ln_dynldf_level )   ierr = 1      ! iso-level not allowed
+            IF ( ln_dynldf_hor   )   nldf = 0      ! horizontal (no rotation)
+            IF ( ln_dynldf_iso   )   nldf = 1      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_sco ) THEN             ! z-coordinate
+            IF ( ln_dynldf_level )   nldf = 0      ! iso-level  (no rotation)
+            IF ( ln_dynldf_hor   )   nldf = 1      ! horizontal (   rotation)
+            IF ( ln_dynldf_iso   )   nldf = 1      ! isoneutral (   rotation)
+         ENDIF
+      ENDIF
+
+      IF( ln_dynldf_bilap ) THEN      ! bilaplacian operator
+         IF ( ln_zco ) THEN                ! z-coordinate
+            IF ( ln_dynldf_level )   nldf = 2      ! iso-level  (no rotation)
+            IF ( ln_dynldf_hor   )   nldf = 2      ! horizontal (no rotation)
+            IF ( ln_dynldf_iso   )   ierr = 2      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_zps ) THEN             ! z-coordinate
+            IF ( ln_dynldf_level )   ierr = 1      ! iso-level not allowed 
+            IF ( ln_dynldf_hor   )   nldf = 2      ! horizontal (no rotation)
+            IF ( ln_dynldf_iso   )   ierr = 2      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_sco ) THEN             ! z-coordinate
+            IF ( ln_dynldf_level )   nldf = 2      ! iso-level  (no rotation)
+            IF ( ln_dynldf_hor   )   nldf = 3      ! horizontal (   rotation)
+            IF ( ln_dynldf_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( nldf == 1 .OR. nldf == 3 ) THEN      ! rotation
+         IF( .NOT.lk_ldfslp )   CALL ctl_stop( 'the rotation of the diffusive tensor require key_ldfslp' )
+      ENDIF
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         IF( nldf ==  0 )   WRITE(numout,*) '              laplacian operator'
+         IF( nldf ==  1 )   WRITE(numout,*) '              Rotated laplacian operator'
+         IF( nldf ==  2 )   WRITE(numout,*) '              bilaplacian operator'
+         IF( nldf ==  3 )   WRITE(numout,*) '              Rotated bilaplacian'
+      ENDIF
+      !
+   END SUBROUTINE dyn_ldf_ctl_tam
+
+   SUBROUTINE dyn_ldf_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_ldf_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Separate tests are applied for the following dx and dy:
+      !!                
+      !!              1) dx = ( SSH ) and dy = ( SSH )
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      INTEGER :: &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk,    &
+         & jt     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zua_tlin,     & ! Tangent input: after u-velocity
+         & zva_tlin,     & ! Tangent input: after u-velocity         
+         & zua_tlout,    & ! Tangent output:after u-velocity
+         & zva_tlout,    & ! Tangent output:after v-velocity
+         & zua_adin,     & ! adjoint input: after u-velocity
+         & zva_adin,     & ! adjoint input: after v-velocity
+         & zua_adout,    & ! adjoint output:after v-velocity
+         & zva_adout,    & ! adjoint output:after u-velocity
+         & zrotb_tlin,   &
+         & zhdivb_tlin,  &
+         & zrotb_adout,  &
+         & zhdivb_adout, &
+         & zrotb,        & ! 3D random field for rotb
+         & zhdivb,       & ! 3D random field for hdivb
+         & zau,          & ! 3D random field for u
+         & zav             ! 3D random field for v
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_1,       & !   scalar product components
+         & zsp1_2,       & 
+         & zsp2,         & ! scalar product involving the adjoint routine
+         & zsp2_1,       & !   scalar product components
+         & zsp2_2,       & 
+         & zsp2_3,       & 
+         & zsp2_4
+      CHARACTER(LEN=14) :: cl_name
+
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zua_tlin(jpi,jpj,jpk),     &
+         & zva_tlin(jpi,jpj,jpk),     &
+         & zua_tlout(jpi,jpj,jpk),    &
+         & zva_tlout(jpi,jpj,jpk),    &
+         & zua_adin(jpi,jpj,jpk),     &
+         & zva_adin(jpi,jpj,jpk),     &
+         & zua_adout(jpi,jpj,jpk),    &
+         & zva_adout(jpi,jpj,jpk),    &
+         & zrotb_tlin(jpi,jpj,jpk),   &
+         & zhdivb_tlin(jpi,jpj,jpk),  &
+         & zrotb_adout(jpi,jpj,jpk),  &
+         & zhdivb_adout(jpi,jpj,jpk), &
+         & zrotb(jpi,jpj,jpk),        & 
+         & zhdivb(jpi,jpj,jpk),       & 
+         & zau(jpi,jpj,jpk),          & 
+         & zav(jpi,jpj,jpk)           & 
+         & )
+
+      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 ) 
+         !    and  dy = ( ua_tl, va_tl )
+         !==================================================================
+
+         !--------------------------------------------------------------------
+         ! Reset the tangent and adjoint variables
+         !--------------------------------------------------------------------
+         zua_tlin(:,:,:)     = 0.0_wp     
+         zva_tlin(:,:,:)     = 0.0_wp     
+         zrotb_tlin(:,:,:)   = 0.0_wp   
+         zhdivb_tlin(:,:,:)  = 0.0_wp  
+         zua_tlout(:,:,:)    = 0.0_wp     
+         zva_tlout(:,:,:)    = 0.0_wp     
+         zua_adin(:,:,:)     = 0.0_wp    
+         zva_adin(:,:,:)     = 0.0_wp    
+         zrotb_adout(:,:,:)  = 0.0_wp  
+         zhdivb_adout(:,:,:) = 0.0_wp 
+         zua_adout(:,:,:)    = 0.0_wp    
+         zva_adout(:,:,:)    = 0.0_wp    
+         zrotb(:,:,:)        = 0.0_wp         
+         zhdivb(:,:,:)       = 0.0_wp        
+         zau(:,:,:)          = 0.0_wp           
+         zav(:,:,:)          = 0.0_wp    
+
+         ua_tl(:,:,:)    = 0.0_wp     
+         va_tl(:,:,:)    = 0.0_wp     
+         ua_ad(:,:,:)    = 0.0_wp     
+         va_ad(:,:,:)    = 0.0_wp     
+         rotb_tl(:,:,:)  = 0.0_wp   
+         hdivb_tl(:,:,:) = 0.0_wp  
+         rotb_ad(:,:,:)  = 0.0_wp  
+         hdivb_ad(:,:,:) = 0.0_wp 
+
+         !--------------------------------------------------------------------
+         ! Initialize the tangent input with random noise: dx
+         !--------------------------------------------------------------------
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 596035 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zau, 'U', 0.0_wp, stdu )
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 523432 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zav, 'V', 0.0_wp, stdv )
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 456953 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zrotb, 'F', 0.0_wp, stdr )
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 432545 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zhdivb, 'T', 0.0_wp, stdh )
+
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zua_tlin   (ji,jj,jk) = zau   (ji,jj,jk)
+                  zva_tlin   (ji,jj,jk) = zav   (ji,jj,jk)
+                  zhdivb_tlin(ji,jj,jk) = zhdivb(ji,jj,jk)
+                  zrotb_tlin (ji,jj,jk) = zrotb (ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         hdivb_tl(:,:,:) = zhdivb_tlin(:,:,:)
+         rotb_tl (:,:,:) = zrotb_tlin (:,:,:)
+         ua_tl   (:,:,:) = zua_tlin   (:,:,:)
+         va_tl   (:,:,:) = zva_tlin   (:,:,:)
+
+         IF (nldf == 0 )  CALL dyn_ldf_lap_tan(   nit000 )
+         IF (nldf == 2 )  CALL dyn_ldf_bilap_tan( nit000 )
+
+         zua_tlout(:,:,:) = ua_tl(:,:,:)
+         zva_tlout(:,:,:) = va_tl(:,:,:)
+
+         !--------------------------------------------------------------------
+         ! Initialize the adjoint variables: dy^* = W dy
+         !--------------------------------------------------------------------
+
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zua_adin(ji,jj,jk) = zua_tlout(ji,jj,jk) &
+                       &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                       &               * umask(ji,jj,jk)
+                  zva_adin(ji,jj,jk) = zva_tlout(ji,jj,jk) &
+                       &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+                       &               * vmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !--------------------------------------------------------------------
+
+         zsp1_1 = DOT_PRODUCT( zua_tlout, zua_adin )
+         zsp1_2 = DOT_PRODUCT( zva_tlout, zva_adin )
+         zsp1   = zsp1_1 + zsp1_2
+
+         !--------------------------------------------------------------------
+         ! Call the adjoint routine: dx^* = L^T dy^*
+         !--------------------------------------------------------------------
+
+         ua_ad(:,:,:) = zua_adin(:,:,:)
+         va_ad(:,:,:) = zva_adin(:,:,:)
+
+         IF (nldf == 0 )  CALL dyn_ldf_lap_adj(   nit000 )
+         IF (nldf == 2 )  CALL dyn_ldf_bilap_adj( nit000 )
+
+         zua_adout   (:,:,:) = ua_ad   (:,:,:)
+         zva_adout   (:,:,:) = va_ad   (:,:,:)
+         zrotb_adout (:,:,:) = rotb_ad (:,:,:)
+         zhdivb_adout(:,:,:) = hdivb_ad(:,:,:)
+
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: dx^T dx^*
+         !--------------------------------------------------------------------
+     
+         zsp2_1 = DOT_PRODUCT( zua_tlin,    zua_adout    )
+         zsp2_2 = DOT_PRODUCT( zva_tlin,    zva_adout    )
+         zsp2_3 = DOT_PRODUCT( zrotb_tlin,  zrotb_adout  )
+         zsp2_4 = DOT_PRODUCT( zhdivb_tlin, zhdivb_adout )
+         zsp2   = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4
+
+      ! Compare the scalar products
+      ! 14 char:'12345678901234'
+         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( &
+         & zua_tlin,     &
+         & zva_tlin,     &
+         & zua_tlout,    &
+         & zva_tlout,    &
+         & zua_adin,     &
+         & zva_adin,     &
+         & zua_adout,    &
+         & zva_adout,    &
+         & zrotb_tlin,   &
+         & zhdivb_tlin,  &
+         & zrotb_adout,  &
+         & zhdivb_adout, &
+         & zrotb,        & 
+         & zhdivb,       & 
+         & zau,          & 
+         & zav           & 
+         & )
+   END SUBROUTINE dyn_ldf_adj_tst
+   !!======================================================================
+#endif
+END MODULE dynldf_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynnxt_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynnxt_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynnxt_tam.F90	(revision 2578)
@@ -0,0 +1,862 @@
+MODULE dynnxt_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  dynnxt_tam  ***
+   !! Ocean dynamics: time stepping
+   !!                 Tangent and Adjoint Module
+   !!======================================================================
+   !! History of the direct module:
+   !!            OPA  !  1987-02  (P. Andrich, D. L Hostis)  Original code
+   !!                 !  1990-10  (C. Levy, G. Madec)
+   !!            7.0  !  1993-03  (M. Guyon)  symetrical conditions
+   !!            8.0  !  1997-02  (G. Madec & M. Imbard)  opa, release 8.0
+   !!            8.2  !  1997-04  (A. Weaver)  Euler forward step
+   !!             -   !  1997-06  (G. Madec)  lateral boudary cond., lbc routine
+   !!    NEMO    1.0  !  2002-08  (G. Madec)  F90: Free form and module
+   !!             -   !  2002-10  (C. Talandier, A-M. Treguier) Open boundary cond.
+   !!            2.0  !  2005-11  (V. Garnier) Surface pressure gradient organization
+   !!            2.3  !  2007-07  (D. Storkey) Calls to BDY routines. 
+   !!            3.2  !  2009-06  (G. Madec, R.Benshila)  re-introduce the vvl option
+   !! History of the TAM routine:
+   !!            9.0  !  2008-06  (A. Vidard) Skeleton
+   !!                 !  2008-08  (A. Vidard) tangent of the 05-11 version
+   !!                 !  2008-08  (A. Vidard) tangent of the 07-07 version
+   !!            3.2  !  2010-04  (F. Vigilant) 3.2 conversion
+   !!-------------------------------------------------------------------------   
+   !!----------------------------------------------------------------------
+   !!   dyn_nxt_tan  : update the horizontal velocity from the momentum trend
+   !!   dyn_nxt_adj  : update the horizontal velocity from the momentum trend
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 & 
+      & jpkm1,               & 
+      & jpiglo
+   USE oce_tam       , ONLY: & ! ocean dynamics and tracers
+      & un_tl,               &
+      & vn_tl,               &
+      & ub_tl,               &
+      & vb_tl,               &
+      & ua_tl,               &
+      & va_tl,               &
+      & un_ad,               &
+      & vn_ad,               &
+      & ub_ad,               &
+      & vb_ad,               &
+      & ua_ad,               &
+      & va_ad
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & umask,               &
+      & vmask,               &
+      & lk_vvl,              &
+      & neuler,              &
+      & rdt,                 & 
+      & atfp,                & 
+      & atfp1,               & 
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3v,                 &
+      & e3u,                 &
+#endif
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej   
+   USE in_out_manager, ONLY: & ! I/O manager
+      & lwp,                 &
+      & nit000,              &
+      & nitend,              &
+      & numout,              &
+      & ctl_stop
+   USE dynspg_oce    , ONLY: & ! surface pressure gradient variables
+      & lk_dynspg_flt,       &
+      & lk_dynspg_ts,        &
+      & lk_dynspg_exp
+   USE dynadv,         ONLY: &
+      & ln_dynadv_vec          ! vector form flag
+   USE lbclnk        , ONLY: & ! lateral boundary condition (or mpp link)
+      & lbc_lnk
+   USE lbclnk_tam    , ONLY: & ! lateral boundary condition (or mpp link)
+      & lbc_lnk_adj
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          & !
+                               ! random field standard deviation for:
+      & stdu,                & !   u-velocity
+      & stdv                   !   v-velocity
+
+!VERIF
+!   USE bdy_oce         ! unstructured open boundary conditions
+!   USE bdydta          ! unstructured open boundary conditions
+!   USE bdydyn          ! unstructured open boundary conditions
+!!!!!
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dyn_nxt_tan            ! routine called by step.F90
+   PUBLIC dyn_nxt_adj            ! routine called by step.F90
+   PUBLIC dyn_nxt_adj_tst        ! routine called by step.F90
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_nxt_tan ( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_nxt_tan  ***
+      !!                   
+      !! ** Purpose :   Compute the after horizontal velocity. Apply the boundary 
+      !!             condition on the after velocity, achieved the time stepping 
+      !!             by applying the Asselin filter on now fields and swapping 
+      !!             the fields.
+      !!
+      !! ** Method  : * After velocity is compute using a leap-frog scheme:
+      !!                       (ua,va) = (ub,vb) + 2 rdt (ua,va)
+      !!             Note that with flux form advection and variable volume layer
+      !!             (lk_vvl=T), the leap-frog is applied on thickness weighted
+      !!             velocity.
+      !!             Note also that in filtered free surface (lk_dynspg_flt=T),
+      !!             the time stepping has already been done in dynspg module
+      !!
+      !!              * Apply lateral boundary conditions on after velocity 
+      !!             at the local domain boundaries through lbc_lnk call,
+      !!             at the radiative open boundaries (lk_obc=T),
+      !!             at the relaxed   open boundaries (lk_bdy=T), and
+      !!             at the AGRIF zoom     boundaries (lk_agrif=T)
+      !!
+      !!              * Apply the time filter applied and swap of the dynamics
+      !!             arrays to start the next time step:
+      !!                (ub,vb) = (un,vn) + atfp [ (ub,vb) + (ua,va) - 2 (un,vn) ]
+      !!                (un,vn) = (ua,va).
+      !!             Note that with flux form advection and variable volume layer
+      !!             (lk_vvl=T), the time filter is applied on thickness weighted
+      !!             velocity.
+      !!
+      !! ** Action :   ub,vb   filtered before horizontal velocity of next time-step
+      !!               un,vn   now horizontal velocity of next time-step
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      !! * Local declarations
+#if ! defined key_dynspg_flt
+      REAL(wp) ::   z2dt         ! temporary scalar
+#endif
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zue3atl , zue3ntl , zue3btl  ! temporary scalar
+      REAL(wp) ::   zve3atl , zve3ntl , zve3btl  !    -         -
+      REAL(wp) ::   ze3u_b  , ze3u_n  , ze3u_a   !    -         -
+      REAL(wp) ::   ze3v_b  , ze3v_n  , ze3v_a   !    -         - 
+      REAL(wp) ::   zuftl   , zvftl              !    -         - 
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_nxt_tan : time stepping'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+#if defined key_dynspg_flt
+      !
+      ! Next velocity :   Leap-frog time stepping already done in dynspg_flt.F routine
+      ! -------------
+
+      ! Update after velocity on domain lateral boundaries      (only local domain required)
+      ! --------------------------------------------------
+      CALL lbc_lnk( ua_tl, 'U', -1.0_wp )         ! local domain boundaries
+      CALL lbc_lnk( va_tl, 'V', -1.0_wp ) 
+      !
+#else
+      ! Next velocity :   Leap-frog time stepping
+      ! -------------
+      z2dt = 2. * rdt                                 ! Euler or leap-frog time step 
+      IF( neuler == 0 .AND. kt == nit000 )  z2dt = rdt
+      !
+      IF( ln_dynadv_vec .OR. .NOT. lk_vvl ) THEN      ! applied on velocity
+         DO jk = 1, jpkm1
+            ua_tl(:,:,jk) = ( ub_tl(:,:,jk) + z2dt * ua_tl(:,:,jk) ) * umask(:,:,jk)
+            va_tl(:,:,jk) = ( vb_tl(:,:,jk) + z2dt * va_tl(:,:,jk) ) * vmask(:,:,jk)
+         END DO
+      ELSE                                            ! applied on thickness weighted velocity
+         DO jk = 1, jpkm1
+            ua_tl(:,:,jk) = (          ub_tl(:,:,jk) * fse3u_b(:,:,jk)      &
+               &              + z2dt * ua_tl(:,:,jk) * fse3u_n(:,:,jk)  )   &
+               &            / fse3u_a(:,:,jk) * umask(:,:,jk)
+            va_tl(:,:,jk) = (          vb_tl(:,:,jk) * fse3v_b(:,:,jk)      &
+               &              + z2dt * va_tl(:,:,jk) * fse3v_n(:,:,jk)  )   &
+               &            / fse3v_a(:,:,jk) * vmask(:,:,jk)
+         END DO
+      ENDIF
+
+      ! Update after velocity on domain lateral boundaries
+      ! --------------------------------------------------      
+      CALL lbc_lnk( ua_tl, 'U', -1.0_wp )     !* local domain boundaries
+      CALL lbc_lnk( va_tl, 'V', -1.0_wp ) 
+      !
+# if defined key_obc
+      !                                !* OBC open boundaries
+      IF( lk_obc )   CALL obc_dyn_tan( kt )
+      !
+      IF ( lk_dynspg_exp .OR. lk_dynspg_ts ) THEN
+         CALL ctl_stop ( 'dyn_spg_exp OR dyn_spg_ts not available yet in TAM' )
+      ENDIF
+      !
+# elif defined key_bdy 
+      !                                !* BDY open boundaries
+         CALL ctl_stop ( 'dyn_spg_exp OR dyn_spg_ts not available yet in TAM' )
+# endif
+      !
+# if defined key_agrif
+!      CALL Agrif_dyn( kt )             !* AGRIF zoom boundaries
+      CALL ctl_stop( 'Agrif_dyn_tan: key_agrif is not available' )
+# endif
+#endif
+
+      ! Time filter and swap of dynamics arrays
+      ! ------------------------------------------
+      IF( neuler == 0 .AND. kt == nit000 ) THEN        !* Euler at first time-step: only swap
+         DO jk = 1, jpkm1
+            un_tl(:,:,jk) = ua_tl(:,:,jk)                          ! un <-- ua
+            vn_tl(:,:,jk) = va_tl(:,:,jk)
+         END DO
+      ELSE                                             !* Leap-Frog : Asselin filter and swap
+         IF( ln_dynadv_vec .OR. .NOT. lk_vvl ) THEN          ! applied on velocity
+            DO jk = 1, jpkm1                              
+               DO jj = 1, jpj
+                  DO ji = 1, jpi    
+                     zuftl = atfp * ( ub_tl(ji,jj,jk) + ua_tl(ji,jj,jk) ) + atfp1 * un_tl(ji,jj,jk)
+                     zvftl = atfp * ( vb_tl(ji,jj,jk) + va_tl(ji,jj,jk) ) + atfp1 * vn_tl(ji,jj,jk)
+                     !
+                     ub_tl(ji,jj,jk) = zuftl                      ! ub <-- filtered velocity
+                     vb_tl(ji,jj,jk) = zvftl
+                     un_tl(ji,jj,jk) = ua_tl(ji,jj,jk)             ! un <-- ua
+                     vn_tl(ji,jj,jk) = va_tl(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+         ELSE                                                ! applied on thickness weighted velocity
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     ze3u_a = fse3u_a(ji,jj,jk)
+                     ze3v_a = fse3v_a(ji,jj,jk)
+                     ze3u_n = fse3u_n(ji,jj,jk)
+                     ze3v_n = fse3v_n(ji,jj,jk)
+                     ze3u_b = fse3u_b(ji,jj,jk)
+                     ze3v_b = fse3v_b(ji,jj,jk)
+                     !
+                     zue3atl = ua_tl(ji,jj,jk) * ze3u_a
+                     zve3atl = va_tl(ji,jj,jk) * ze3v_a
+                     zue3ntl = un_tl(ji,jj,jk) * ze3u_n
+                     zve3ntl = vn_tl(ji,jj,jk) * ze3v_n
+                     zue3btl = ub_tl(ji,jj,jk) * ze3u_b
+                     zve3btl = vb_tl(ji,jj,jk) * ze3v_b
+                     !
+                     zuftl  = ( atfp  * ( zue3btl  + zue3atl  ) + atfp1 * zue3ntl  )   &
+                        & / ( atfp  * ( ze3u_b + ze3u_a ) + atfp1 * ze3u_n ) * umask(ji,jj,jk)
+                     zvftl  = ( atfp  * ( zve3btl  + zve3atl  ) + atfp1 * zve3ntl  )   &
+                        & / ( atfp  * ( ze3v_b + ze3v_a ) + atfp1 * ze3v_n ) * vmask(ji,jj,jk)
+                     !
+                     ub_tl(ji,jj,jk) = zuftl                      ! ub_tl <-- filtered velocity
+                     vb_tl(ji,jj,jk) = zvftl
+                     un_tl(ji,jj,jk) = ua_tl(ji,jj,jk)            ! un_tl <-- ua
+                     vn_tl(ji,jj,jk) = va_tl(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+         ENDIF
+      ENDIF
+
+      !
+   END SUBROUTINE dyn_nxt_tan
+
+   SUBROUTINE dyn_nxt_adj ( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_nxt_tan  ***
+      !!                   
+      !! ** Purpose :   Compute the after horizontal velocity. Apply the boundary 
+      !!             condition on the after velocity, achieved the time stepping 
+      !!             by applying the Asselin filter on now fields and swapping 
+      !!             the fields.
+      !!
+      !! ** Method  : * After velocity is compute using a leap-frog scheme:
+      !!                       (ua,va) = (ub,vb) + 2 rdt (ua,va)
+      !!             Note that with flux form advection and variable volume layer
+      !!             (lk_vvl=T), the leap-frog is applied on thickness weighted
+      !!             velocity.
+      !!             Note also that in filtered free surface (lk_dynspg_flt=T),
+      !!             the time stepping has already been done in dynspg module
+      !!
+      !!              * Apply lateral boundary conditions on after velocity 
+      !!             at the local domain boundaries through lbc_lnk call,
+      !!             at the radiative open boundaries (lk_obc=T),
+      !!             at the relaxed   open boundaries (lk_bdy=T), and
+      !!             at the AGRIF zoom     boundaries (lk_agrif=T)
+      !!
+      !!              * Apply the time filter applied and swap of the dynamics
+      !!             arrays to start the next time step:
+      !!                (ub,vb) = (un,vn) + atfp [ (ub,vb) + (ua,va) - 2 (un,vn) ]
+      !!                (un,vn) = (ua,va).
+      !!             Note that with flux form advection and variable volume layer
+      !!             (lk_vvl=T), the time filter is applied on thickness weighted
+      !!             velocity.
+      !!
+      !! ** Action :   ub,vb   filtered before horizontal velocity of next time-step
+      !!               un,vn   now horizontal velocity of next time-step
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+#if ! defined key_dynspg_flt
+      REAL(wp) ::   z2dt         ! temporary scalar
+#endif
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zue3aad , zue3nad , zue3bad  ! temporary scalar
+      REAL(wp) ::   zve3aad , zve3nad , zve3bad  !    -         -
+      REAL(wp) ::   ze3u_b  , ze3u_n  , ze3u_a   !    -         -
+      REAL(wp) ::   ze3v_b  , ze3v_n  , ze3v_a   !    -         - 
+      REAL(wp) ::   zufad   , zvfad              !    -         - 
+      !!----------------------------------------------------------------------
+      !
+      ! adjoint local variables initialization
+      zue3aad = 0.0_wp ;  zue3nad = 0.0_wp ; zue3bad = 0.0_wp
+      zve3aad = 0.0_wp ;  zve3nad = 0.0_wp ; zve3bad = 0.0_wp
+      zufad   = 0.0_wp ;  zvfad   = 0.0_wp
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_nxt_adj : time stepping'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+      !
+      ! Time filter and swap of dynamics arrays
+      ! ------------------------------------------
+      IF( neuler == 0 .AND. kt == nit000 ) THEN        !* Euler at first time-step: only swap
+         DO jk = 1, jpkm1
+            ua_ad(:,:,jk) = ua_ad(:,:,jk) + un_ad(:,:,jk)          ! un_ad <-- ua_ad
+            va_ad(:,:,jk) = va_ad(:,:,jk) + vn_ad(:,:,jk)
+            un_ad(:,:,jk) = 0.0_wp
+            vn_ad(:,:,jk) = 0.0_wp
+         END DO
+      ELSE                                             !* Leap-Frog : Asselin filter and swap
+         IF( ln_dynadv_vec .OR. .NOT. lk_vvl ) THEN          ! applied on velocity
+            DO jk = 1, jpkm1                              
+               DO jj = 1, jpj
+                  DO ji = 1, jpi  
+                     va_ad(ji,jj,jk) = va_ad(ji,jj,jk) + vn_ad(ji,jj,jk)
+                     ua_ad(ji,jj,jk) = ua_ad(ji,jj,jk) + un_ad(ji,jj,jk)
+                     un_ad(ji,jj,jk) = 0.0_wp
+                     vn_ad(ji,jj,jk) = 0.0_wp
+                     zvfad           = zvfad + vb_ad(ji,jj,jk)
+                     zufad           = zufad + ub_ad(ji,jj,jk)
+                     ub_ad(ji,jj,jk) = 0.0_wp
+                     vb_ad(ji,jj,jk) = 0.0_wp
+
+                     ub_ad(ji,jj,jk) = ub_ad(ji,jj,jk) + atfp  * zufad 
+                     ua_ad(ji,jj,jk) = ua_ad(ji,jj,jk) + atfp  * zufad 
+                     un_ad(ji,jj,jk) = un_ad(ji,jj,jk) + atfp1 * zufad
+                     vb_ad(ji,jj,jk) = vb_ad(ji,jj,jk) + atfp  * zvfad 
+                     va_ad(ji,jj,jk) = va_ad(ji,jj,jk) + atfp  * zvfad 
+                     vn_ad(ji,jj,jk) = vn_ad(ji,jj,jk) + atfp1 * zvfad
+                     zufad           = 0.0_wp
+                     zvfad           = 0.0_wp
+                  END DO
+               END DO
+            END DO
+         ELSE                                                ! applied on thickness weighted velocity
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     ze3u_a = fse3u_a(ji,jj,jk)
+                     ze3v_a = fse3v_a(ji,jj,jk)
+                     ze3u_n = fse3u_n(ji,jj,jk)
+                     ze3v_n = fse3v_n(ji,jj,jk)
+                     ze3u_b = fse3u_b(ji,jj,jk)
+                     ze3v_b = fse3v_b(ji,jj,jk)
+                     !
+                     va_ad(ji,jj,jk) = va_ad(ji,jj,jk) + vn_ad(ji,jj,jk)
+                     ua_ad(ji,jj,jk) = ua_ad(ji,jj,jk) + un_ad(ji,jj,jk)
+                     un_ad(ji,jj,jk) = 0.0_wp
+                     vn_ad(ji,jj,jk) = 0.0_wp
+                     zvfad           = zvfad + vb_ad(ji,jj,jk)
+                     zufad           = zufad + ub_ad(ji,jj,jk)
+                     ub_ad(ji,jj,jk) = 0.0_wp
+                     vb_ad(ji,jj,jk) = 0.0_wp
+                     !
+                     zufad   = zufad  / ( atfp  * ( ze3u_b + ze3u_a ) + atfp1 * ze3u_n ) * umask(ji,jj,jk)
+                     zue3bad = zue3bad + atfp  * zufad
+                     zue3aad = zue3aad + atfp  * zufad
+                     zue3nad = zue3nad + atfp1 * zufad
+                     zufad   = 0.0_wp
+                     zvfad   = zvfad  / ( atfp  * ( ze3v_b + ze3v_a ) + atfp1 * ze3v_n ) * vmask(ji,jj,jk)
+                     zve3bad = zve3bad + atfp  * zvfad
+                     zve3aad = zve3aad + atfp  * zvfad
+                     zve3nad = zve3nad + atfp1 * zvfad
+                     zvfad   = 0.0_wp
+                     !
+                     vb_ad(ji,jj,jk) = vb_ad(ji,jj,jk) + ze3v_b * zve3bad
+                     ub_ad(ji,jj,jk) = ub_ad(ji,jj,jk) + ze3u_b * zue3bad
+                     vn_ad(ji,jj,jk) = vn_ad(ji,jj,jk) + ze3v_n * zve3nad
+                     un_ad(ji,jj,jk) = un_ad(ji,jj,jk) + ze3u_n * zue3nad
+                     va_ad(ji,jj,jk) = va_ad(ji,jj,jk) + ze3v_a * zve3aad
+                     ua_ad(ji,jj,jk) = ua_ad(ji,jj,jk) + ze3u_a * zue3aad
+                     zve3bad         = 0.0_wp
+                     zue3bad         = 0.0_wp
+                     zve3nad         = 0.0_wp
+                     zue3nad         = 0.0_wp
+                     zve3aad         = 0.0_wp
+                     zue3aad         = 0.0_wp
+                  END DO
+               END DO
+            END DO
+         ENDIF
+      ENDIF
+
+#if defined key_dynspg_flt
+      !
+      ! Next velocity :   Leap-frog time stepping already done in dynspg_flt.F routine
+      ! -------------
+
+      ! Update after velocity on domain lateral boundaries      (only local domain required)
+      ! --------------------------------------------------
+      CALL lbc_lnk_adj( ua_ad, 'U', -1.0_wp )         ! local domain boundaries
+      CALL lbc_lnk_adj( va_ad, 'V', -1.0_wp ) 
+      !
+#else
+      !
+      ! Update after velocity on domain lateral boundaries
+      ! --------------------------------------------------   
+# if defined key_agrif
+!      CALL Agrif_dyn( kt )             !* AGRIF zoom boundaries
+      CALL ctl_stop( 'Agrif_dyn_adj: key_agrif is not available' )
+# endif
+      !
+# if defined key_obc
+      !                                !* OBC open boundaries
+      IF ( lk_dynspg_exp .OR. lk_dynspg_ts ) THEN
+         CALL ctl_stop ( 'dyn_spg_exp OR dyn_spg_ts not available yet in TAM' )
+      ENDIF
+      IF( lk_obc )   CALL obc_dyn_adj( kt )
+      !
+# elif defined key_bdy 
+      !                                !* BDY open boundaries
+         CALL ctl_stop ( 'dyn_spg_exp OR dyn_spg_ts not available yet in TAM' )
+# endif
+      !
+      ! Update after velocity on domain lateral boundaries
+      ! --------------------------------------------------      
+      CALL lbc_lnk_adj( va_ad, 'U', -1.0_wp )     !* local domain boundaries
+      CALL lbc_lnk_adj( ua_ad, 'V', -1.0_wp ) 
+
+      ! Next velocity :   Leap-frog time stepping
+      ! -------------
+      z2dt = 2. * rdt                                 ! Euler or leap-frog time step
+      IF( neuler == 0 .AND. kt == nit000 )  z2dt = rdt
+      !
+      IF( ln_dynadv_vec .OR. .NOT. lk_vvl ) THEN      ! applied on velocity
+         DO jk = 1, jpkm1
+            ua_ad(:,:,jk) = ua_ad(:,:,jk) * umask(:,:,jk)
+            va_ad(:,:,jk) = va_ad(:,:,jk) * vmask(:,:,jk)
+            ub_ad(:,:,jk) = ub_ad(:,:,jk) + ua_ad(:,:,jk)
+            vb_ad(:,:,jk) = vb_ad(:,:,jk) + va_ad(:,:,jk)
+            ua_ad(:,:,jk) = ua_ad(:,:,jk) * z2dt
+            va_ad(:,:,jk) = va_ad(:,:,jk) * z2dt
+         END DO
+      ELSE                                            ! applied on thickness weighted velocity
+         DO jk = 1, jpkm1
+            ua_ad(:,:,jk) = ua_ad(:,:,jk)  / fse3u_a(:,:,jk) * umask(:,:,jk)
+            va_ad(:,:,jk) = va_ad(:,:,jk)  / fse3v_a(:,:,jk) * vmask(:,:,jk)
+            ub_ad(:,:,jk) = ub_ad(:,:,jk) + ua_ad(:,:,jk)  * fse3u_b(:,:,jk)
+            vb_ad(:,:,jk) = vb_ad(:,:,jk) + va_ad(:,:,jk)  * fse3v_b(:,:,jk)
+            ua_ad(:,:,jk) = ua_ad(:,:,jk) * z2dt *fse3u_n(:,:,jk)
+            va_ad(:,:,jk) = va_ad(:,:,jk) * z2dt *fse3v_n(:,:,jk)
+         END DO
+      ENDIF
+#endif
+      !
+   END SUBROUTINE dyn_nxt_adj
+
+   SUBROUTINE dyn_nxt_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_nxt_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Separate tests are applied for the following dx and dy:
+      !!                
+      !!              1) dx = ( SSH ) and dy = ( SSH )
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      INTEGER :: &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zun_tlin,     & ! Tangent input:   now   u-velocity
+         & zvn_tlin,     & ! Tangent input:   now   v-velocity
+         & zua_tlin,     & ! Tangent input:  after  u-velocity
+         & zva_tlin,     & ! Tangent input:  after  u-velocity         
+         & zub_tlin,     & ! Tangent input:  before u-velocity
+         & zvb_tlin,     & ! Tangent input:  before u-velocity         
+         & zun_adin,     & ! Adjoint input:   now   u-velocity
+         & zvn_adin,     & ! Adjoint input:   now   v-velocity
+         & zua_adin,     & ! Adjoint input:  after  u-velocity
+         & zva_adin,     & ! Adjoint input:  after  u-velocity         
+         & zub_adin,     & ! Adjoint input:  before u-velocity
+         & zvb_adin,     & ! Adjoint input:  before u-velocity         
+         & zun_tlout,    & ! Tangent output:  now   u-velocity
+         & zvn_tlout,    & ! Tangent output:  now   v-velocity
+         & zua_tlout,    & ! Tangent output: after  u-velocity
+         & zva_tlout,    & ! Tangent output: after  u-velocity         
+         & zub_tlout,    & ! Tangent output: before u-velocity
+         & zvb_tlout,    & ! Tangent output: before u-velocity         
+         & zun_adout,    & ! Adjoint output:  now   u-velocity
+         & zvn_adout,    & ! Adjoint output:  now   v-velocity
+         & zua_adout,    & ! Adjoint output: after  u-velocity
+         & zva_adout,    & ! Adjoint output: after  u-velocity         
+         & zub_adout,    & ! Adjoint output: before u-velocity
+         & zvb_adout,    & ! Adjoint output: before u-velocity         
+         & znu,          & ! 3D random field for u
+         & znv,          & ! 3D random field for v
+         & zbu,          & ! 3D random field for u
+         & zbv,          & ! 3D random field for v
+         & zau,          & ! 3D random field for u
+         & zav             ! 3D random field for v
+         
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_1,       & !   scalar product components
+         & zsp1_2,       & 
+         & zsp1_3,       & 
+         & zsp1_4,       & 
+         & zsp1_5,       & 
+         & zsp1_6,       & 
+         & zsp2,         & ! scalar product involving the adjoint routine
+         & zsp2_1,       & !   scalar product components
+         & zsp2_2,       & 
+         & zsp2_3,       & 
+         & zsp2_4,       & 
+         & zsp2_5,       & 
+         & zsp2_6
+      CHARACTER(LEN=14) :: cl_name
+
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zun_tlin(jpi,jpj,jpk),     & 
+         & zvn_tlin(jpi,jpj,jpk),     & 
+         & zua_tlin(jpi,jpj,jpk),     & 
+         & zva_tlin(jpi,jpj,jpk),     & 
+         & zub_tlin(jpi,jpj,jpk),     & 
+         & zvb_tlin(jpi,jpj,jpk),     & 
+         & zun_adin(jpi,jpj,jpk),     & 
+         & zvn_adin(jpi,jpj,jpk),     & 
+         & zua_adin(jpi,jpj,jpk),     & 
+         & zva_adin(jpi,jpj,jpk),     & 
+         & zub_adin(jpi,jpj,jpk),     & 
+         & zvb_adin(jpi,jpj,jpk),     & 
+         & zun_tlout(jpi,jpj,jpk),    & 
+         & zvn_tlout(jpi,jpj,jpk),    & 
+         & zua_tlout(jpi,jpj,jpk),    & 
+         & zva_tlout(jpi,jpj,jpk),    & 
+         & zub_tlout(jpi,jpj,jpk),    & 
+         & zvb_tlout(jpi,jpj,jpk),    & 
+         & zun_adout(jpi,jpj,jpk),    & 
+         & zvn_adout(jpi,jpj,jpk),    & 
+         & zua_adout(jpi,jpj,jpk),    & 
+         & zva_adout(jpi,jpj,jpk),    & 
+         & zub_adout(jpi,jpj,jpk),    & 
+         & zvb_adout(jpi,jpj,jpk),    & 
+         & znu(jpi,jpj,jpk),          & 
+         & znv(jpi,jpj,jpk),          & 
+         & zbu(jpi,jpj,jpk),          & 
+         & zbv(jpi,jpj,jpk),          & 
+         & zau(jpi,jpj,jpk),          & 
+         & zav(jpi,jpj,jpk)           & 
+         & )
+
+
+      !==================================================================
+      ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and 
+      !    dy = ( hdivb_tl, hdivn_tl )
+      !==================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+
+          zun_tlin(:,:,:) = 0.0_wp      
+          zvn_tlin(:,:,:) = 0.0_wp      
+          zua_tlin(:,:,:) = 0.0_wp      
+          zva_tlin(:,:,:) = 0.0_wp      
+          zub_tlin(:,:,:) = 0.0_wp      
+          zvb_tlin(:,:,:) = 0.0_wp      
+          zun_adin(:,:,:) = 0.0_wp      
+          zvn_adin(:,:,:) = 0.0_wp      
+          zua_adin(:,:,:) = 0.0_wp      
+          zva_adin(:,:,:) = 0.0_wp      
+          zub_adin(:,:,:) = 0.0_wp      
+          zvb_adin(:,:,:) = 0.0_wp      
+          zun_tlout(:,:,:) = 0.0_wp     
+          zvn_tlout(:,:,:) = 0.0_wp     
+          zua_tlout(:,:,:) = 0.0_wp     
+          zva_tlout(:,:,:) = 0.0_wp     
+          zub_tlout(:,:,:) = 0.0_wp     
+          zvb_tlout(:,:,:) = 0.0_wp     
+          zun_adout(:,:,:) = 0.0_wp     
+          zvn_adout(:,:,:) = 0.0_wp     
+          zua_adout(:,:,:) = 0.0_wp     
+          zva_adout(:,:,:) = 0.0_wp     
+          zub_adout(:,:,:) = 0.0_wp     
+          zvb_adout(:,:,:) = 0.0_wp     
+          znu(:,:,:) = 0.0_wp           
+          znv(:,:,:) = 0.0_wp           
+          zbu(:,:,:) = 0.0_wp           
+          zbv(:,:,:) = 0.0_wp           
+          zau(:,:,:) = 0.0_wp           
+          zav(:,:,:) = 0.0_wp           
+
+          un_tl(:,:,:) = 0.0_wp      
+          vn_tl(:,:,:) = 0.0_wp      
+          ua_tl(:,:,:) = 0.0_wp      
+          va_tl(:,:,:) = 0.0_wp      
+          ub_tl(:,:,:) = 0.0_wp      
+          vb_tl(:,:,:) = 0.0_wp      
+          un_ad(:,:,:) = 0.0_wp      
+          vn_ad(:,:,:) = 0.0_wp      
+          ua_ad(:,:,:) = 0.0_wp      
+          va_ad(:,:,:) = 0.0_wp      
+          ub_ad(:,:,:) = 0.0_wp      
+          vb_ad(:,:,:) = 0.0_wp      
+
+
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znu, 'U', 0.0_wp, stdu )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 523432 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znv, 'V', 0.0_wp, stdv )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 456953 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zbu, 'U', 0.0_wp, stdu )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 267406 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zbv, 'V', 0.0_wp, stdv )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 432545 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zau, 'U', 0.0_wp, stdu )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 287503 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zav, 'V', 0.0_wp, stdv )
+
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zun_tlin(ji,jj,jk) = znu(ji,jj,jk) 
+               zvn_tlin(ji,jj,jk) = znv(ji,jj,jk) 
+               zub_tlin(ji,jj,jk) = zbu(ji,jj,jk)
+               zvb_tlin(ji,jj,jk) = zbv(ji,jj,jk)
+               zua_tlin(ji,jj,jk) = zau(ji,jj,jk)
+               zva_tlin(ji,jj,jk) = zav(ji,jj,jk)
+            END DO
+         END DO
+      END DO 
+
+      un_tl(:,:,:) = zun_tlin(:,:,:)
+      vn_tl(:,:,:) = zvn_tlin(:,:,:)
+      ub_tl(:,:,:) = zub_tlin(:,:,:)
+      vb_tl(:,:,:) = zvb_tlin(:,:,:)
+      ua_tl(:,:,:) = zua_tlin(:,:,:)
+      va_tl(:,:,:) = zva_tlin(:,:,:)
+
+      call dyn_nxt_tan ( nit000 )
+
+      zun_tlout(:,:,:) = un_tl(:,:,:)
+      zvn_tlout(:,:,:) = vn_tl(:,:,:)
+      zub_tlout(:,:,:) = ub_tl(:,:,:)
+      zvb_tlout(:,:,:) = vb_tl(:,:,:)
+      zua_tlout(:,:,:) = ua_tl(:,:,:)
+      zva_tlout(:,:,:) = va_tl(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zun_adin(ji,jj,jk) = zun_tlout(ji,jj,jk) &
+                 &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                 &               * umask(ji,jj,jk)
+              zvn_adin(ji,jj,jk) = zvn_tlout(ji,jj,jk) &
+                 &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+                 &               * vmask(ji,jj,jk)
+              zub_adin(ji,jj,jk) = zub_tlout(ji,jj,jk) &
+                 &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                 &               * umask(ji,jj,jk)
+              zvb_adin(ji,jj,jk) = zvb_tlout(ji,jj,jk) &
+                 &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+                 &               * vmask(ji,jj,jk)
+              zua_adin(ji,jj,jk) = zua_tlout(ji,jj,jk) &
+                 &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                 &               * umask(ji,jj,jk)
+              zva_adin(ji,jj,jk) = zva_tlout(ji,jj,jk) &
+                 &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+                 &               * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1_1 = DOT_PRODUCT( zun_tlout, zun_adin )
+      zsp1_2 = DOT_PRODUCT( zvn_tlout, zvn_adin )
+      zsp1_3 = DOT_PRODUCT( zub_tlout, zub_adin )
+      zsp1_4 = DOT_PRODUCT( zvb_tlout, zvb_adin )
+      zsp1_5 = DOT_PRODUCT( zua_tlout, zua_adin )
+      zsp1_6 = DOT_PRODUCT( zva_tlout, zva_adin )
+      zsp1   = zsp1_1 + zsp1_2 + zsp1_3 + zsp1_4 + zsp1_5 + zsp1_6 
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      un_ad(:,:,:) = zun_adin(:,:,:)
+      vn_ad(:,:,:) = zvn_adin(:,:,:)
+      ub_ad(:,:,:) = zub_adin(:,:,:)
+      vb_ad(:,:,:) = zvb_adin(:,:,:)
+      ua_ad(:,:,:) = zua_adin(:,:,:)
+      va_ad(:,:,:) = zva_adin(:,:,:)
+
+      CALL dyn_nxt_adj ( nit000 )
+
+      zun_adout(:,:,:) = un_ad(:,:,:)
+      zvn_adout(:,:,:) = vn_ad(:,:,:)
+      zub_adout(:,:,:) = ub_ad(:,:,:)
+      zvb_adout(:,:,:) = vb_ad(:,:,:)
+      zua_adout(:,:,:) = ua_ad(:,:,:)
+      zva_adout(:,:,:) = va_ad(:,:,:)
+
+      zsp2_1 = DOT_PRODUCT( zun_tlin, zun_adout )
+      zsp2_2 = DOT_PRODUCT( zvn_tlin, zvn_adout )
+      zsp2_3 = DOT_PRODUCT( zub_tlin, zub_adout )
+      zsp2_4 = DOT_PRODUCT( zvb_tlin, zvb_adout )
+      zsp2_5 = DOT_PRODUCT( zua_tlin, zua_adout )
+      zsp2_6 = DOT_PRODUCT( zva_tlin, zva_adout )
+      zsp2   = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4 + zsp2_5 + zsp2_6
+
+      ! Compare the scalar products
+      ! 14 char:'12345678901234'
+      cl_name = 'dyn_nxt_adj   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      DEALLOCATE( &
+         & zun_tlin,     & 
+         & zvn_tlin,     & 
+         & zua_tlin,     & 
+         & zva_tlin,     & 
+         & zub_tlin,     & 
+         & zvb_tlin,     & 
+         & zun_adin,     & 
+         & zvn_adin,     & 
+         & zua_adin,     & 
+         & zva_adin,     & 
+         & zub_adin,     & 
+         & zvb_adin,     & 
+         & zun_tlout,    & 
+         & zvn_tlout,    & 
+         & zua_tlout,    & 
+         & zva_tlout,    & 
+         & zub_tlout,    & 
+         & zvb_tlout,    & 
+         & zun_adout,    & 
+         & zvn_adout,    & 
+         & zua_adout,    & 
+         & zva_adout,    & 
+         & zub_adout,    & 
+         & zvb_adout,    & 
+         & znu,          & 
+         & znv,          & 
+         & zbu,          & 
+         & zbv,          & 
+         & zau,          & 
+         & zav           & 
+         & )
+
+
+   END SUBROUTINE dyn_nxt_adj_tst
+   !!======================================================================
+#endif
+END MODULE dynnxt_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynspg_exp_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynspg_exp_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynspg_exp_tam.F90	(revision 2578)
@@ -0,0 +1,411 @@
+MODULE dynspg_exp_tam
+   !!======================================================================
+   !!                   ***  MODULE  dynspg_exp_tam  TANGENT/ADJOINT OF MODULE dynspg_exp***
+   !! Ocean dynamics:  surface pressure gradient trend
+   !!======================================================================
+   !! History of the direct module:
+   !!            2.0  !  2005-11  (V. Garnier, G. Madec, L. Bessieres) Original code
+   !!            3.2  !  2009-06  (G. Madec, M. Leclair, R. Benshila) introduce sshwzv module
+   !! History of the tam module:
+   !!            3.2  !  2010-06  (A. Vidard) tam of the 2009-06 version
+   !!----------------------------------------------------------------------
+#if defined key_dynspg_exp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_dynspg_exp'                              explicit free surface
+   !!----------------------------------------------------------------------
+   !!   dyn_spg_exp  : update the momentum trend with the surface 
+   !!                      pressure gradient in the free surface constant  
+   !!                      volume case with vector optimization
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE phycst        , ONLY: & ! Physical constants
+      & grav
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 &
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1,               &
+      & jpiglo
+   USE oce_tam       , ONLY: & ! Tangent-linear and adjoint model variables
+      & ua_tl,               &
+      & va_tl,               &
+      & ua_ad,               &
+      & va_ad,               &
+      & spgu_tl,             &
+      & spgv_tl,             &
+      & spgu_ad,             &
+      & spgv_ad,             &
+      & sshn_tl,             &
+      & sshn_ad
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3u,                 &
+      & e3v,                 &
+#endif
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      & umask,               &
+      & vmask,               &
+      & lk_vvl
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE paresp        , ONLY: & ! Normalized energy weights
+      & wesp_emp,            &
+      & wesp_ssh         
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              & 
+      & nit000,              &
+      & nitend
+   USE tstool_tam    , ONLY: &
+      & stdu,                &
+      & stdv,                &
+      & stdssh,              &
+      & prntst_adj,          &
+      & prntst_tlm           
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_spg_exp_tan       ! routine called by step.F90
+   PUBLIC   dyn_spg_exp_adj       ! routine called by step.F90
+   PUBLIC   dyn_spg_exp_adj_tst   ! routine called by tamtst.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.2 , LOCEAN-IPSL (2009) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_spg_exp_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine dyn_spg_exp_tan  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to the surface pressure
+      !!              gradient in case of explicit free surface formulation and 
+      !!              add it to the general trend of momentum equation.
+      !!
+      !! ** Method  :   Explicit free surface formulation. Add to the general
+      !!              momentum trend the surface pressure gradient :
+      !!                      (ua,va) = (ua,va) + (spgu,spgv)
+      !!              where spgu = -1/rau0 d/dx(ps) = -g/e1u di( sshn )
+      !!                    spgv = -1/rau0 d/dy(ps) = -g/e2v dj( sshn )
+      !!
+      !! ** Action :   (ua,va)   trend of horizontal velocity increased by 
+      !!                         the surf. pressure gradient trend
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in )  ::   kt         ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk               ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_spg_exp_tan : surface pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   (explicit free surface)'
+         !
+         spgu_tl(:,:) = 0.e0   ;   spgv_tl(:,:) = 0.e0
+         !
+         IF( lk_vvl .AND. lwp ) WRITE(numout,*) '              lk_vvl=T : spg is included in dynhpg'
+      ENDIF
+
+
+!!gm bug ??  Rachid we have to discuss of the call below. I don't understand why it is here and not in ssh_wzv
+!*TODOTAM      IF( lk_obc )   CALL obc_dta_bt_tan( kt, 0 )      ! OBC: read or estimate ssh and vertically integrated velocities
+!!gm
+
+      IF( .NOT. lk_vvl ) THEN          !* fixed volume : add the surface pressure gradient trend
+         !
+         DO jj = 2, jpjm1                    ! now surface pressure gradient
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               spgu_tl(ji,jj) = - grav * ( sshn_tl(ji+1,jj) - sshn_tl(ji,jj) ) / e1u(ji,jj)
+               spgv_tl(ji,jj) = - grav * ( sshn_tl(ji,jj+1) - sshn_tl(ji,jj) ) / e2v(ji,jj)
+            END DO 
+         END DO 
+         DO jk = 1, jpkm1                    ! Add it to the general trend
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ua_tl(ji,jj,jk) = ua_tl(ji,jj,jk) + spgu_tl(ji,jj)
+                  va_tl(ji,jj,jk) = va_tl(ji,jj,jk) + spgv_tl(ji,jj)
+               END DO
+            END DO
+         END DO
+         !
+      ENDIF
+      !
+   END SUBROUTINE dyn_spg_exp_tan
+   SUBROUTINE dyn_spg_exp_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine dyn_spg_exp_adj  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to the surface pressure
+      !!              gradient in case of explicit free surface formulation and 
+      !!              add it to the general trend of momentum equation.
+      !!
+      !! ** Method  :   Explicit free surface formulation. Add to the general
+      !!              momentum trend the surface pressure gradient :
+      !!                      (ua,va) = (ua,va) + (spgu,spgv)
+      !!              where spgu = -1/rau0 d/dx(ps) = -g/e1u di( sshn )
+      !!                    spgv = -1/rau0 d/dy(ps) = -g/e2v dj( sshn )
+      !!
+      !! ** Action :   (ua,va)   trend of horizontal velocity increased by 
+      !!                         the surf. pressure gradient trend
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in )  ::   kt         ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk               ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_spg_exp_adj : surface pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   (explicit free surface)'
+      END IF
+
+      spgu_ad(:,:) = 0.e0   ;   spgv_ad(:,:) = 0.e0
+
+      IF( .NOT. lk_vvl ) THEN          !* fixed volume : add the surface pressure gradient trend
+         !
+         DO jk = 1, jpkm1                    ! Add it to the general trend
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  spgu_ad(ji,jj) = spgu_ad(ji,jj) + ua_ad(ji,jj,jk) 
+                  spgv_ad(ji,jj) = spgv_ad(ji,jj) + va_ad(ji,jj,jk) 
+               END DO
+            END DO
+         END DO
+         DO jj = jpjm1, 2, -1                    ! now surface pressure gradient
+            DO ji = fs_jpim1, fs_2, -1           ! vector opt.
+               
+               spgu_ad(ji,jj) = - grav * spgu_ad(ji,jj) / e1u(ji,jj)
+               spgv_ad(ji,jj) = - grav * spgv_ad(ji,jj) / e2v(ji,jj)
+               sshn_ad(ji+1,jj) = sshn_ad(ji+1,jj) + spgu_ad(ji,jj)
+               sshn_ad(ji,jj+1) = sshn_ad(ji,jj+1) + spgv_ad(ji,jj)
+               sshn_ad(ji,jj)   = sshn_ad(ji,jj) - spgu_ad(ji,jj) - spgv_ad(ji,jj) 
+            END DO 
+         END DO 
+         !
+      ENDIF
+      !
+!!gm bug ??  Rachid we have to discuss of the call below. I don't understand why it is here and not in ssh_wzv
+!*TODOTAM       IF( lk_obc )   CALL obc_dta_bt_adj( kt, 0 )      ! OBC: read or estimate ssh and vertically integrated velocities
+!!gm
+
+
+   END SUBROUTINE dyn_spg_exp_adj
+   SUBROUTINE dyn_spg_exp_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_spg_exp_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 2010-06 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2            ! scalar product involving the adjoint routine
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zua_tlin ,     & ! Tangent input
+         & zva_tlin ,     & ! Tangent input
+         & zua_tlout,     & ! Tangent output
+         & zva_tlout,     & ! Tangent output
+         & zua_adin ,     & ! Adjoint input
+         & zva_adin ,     & ! Adjoint input
+         & zua_adout,     & ! Adjoint output
+         & zva_adout,     & ! Adjoint output
+         & zr3d           ! 3D random field 
+     REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+        & zsshn_tlin,    &
+        & zsshn_adout,   &
+        & zr2d
+       CHARACTER(LEN=14) :: &
+         & cl_name
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zua_tlin(   jpi,jpj,jpk),     &
+         & zva_tlin(   jpi,jpj,jpk),     &
+         & zsshn_tlin( jpi,jpj    ),     &
+         & zua_tlout(  jpi,jpj,jpk),     &
+         & zva_tlout(  jpi,jpj,jpk),     &
+         & zua_adin(   jpi,jpj,jpk),     &
+         & zva_adin(   jpi,jpj,jpk),     &
+         & zua_adout(  jpi,jpj,jpk),     &
+         & zva_adout(  jpi,jpj,jpk),     &
+         & zsshn_adout(jpi,jpj    ),     &
+         & zr3d(       jpi,jpj,jpk),     &
+         & zr2d(       jpi,jpj    )      &
+         & )
+      !==================================================================
+      ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and 
+      !    dy = ( hdivb_tl, hdivn_tl )
+      !==================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      
+      ua_ad( :,:,:) = 0.0_wp
+      va_ad( :,:,:) = 0.0_wp
+      sshn_ad( :,:) = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr3d, 'U', 0.0_wp, stdu )
+      zua_tlin(:,:,:) = zr3d(:,:,:) 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 345867 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr3d, 'V', 0.0_wp, stdv )
+      zva_tlin(:,:,:) = zr3d(:,:,:) 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 152467 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr2d, 'T', 0.0_wp, stdssh )
+      zsshn_tlin(:,:) = zr2d(:,:) 
+
+
+      ua_tl = zua_tlin
+      va_tl = zva_tlin
+      sshn_tl = zsshn_tlin
+      CALL dyn_spg_exp_tan( nit000 )
+      zua_tlout = ua_tl
+      zva_tlout = va_tl
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zua_adin(ji,jj,jk) = zua_tlout(ji,jj,jk) &
+                 &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                 &               * umask(ji,jj,jk)
+              zva_adin(ji,jj,jk) = zva_tlout(ji,jj,jk) &
+                 &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+                 &               * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1 = DOT_PRODUCT( zua_tlout, zua_adin ) &
+         & + DOT_PRODUCT( zva_tlout, zva_adin )
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      ua_ad = zua_adin
+      va_ad = zva_adin
+
+      CALL dyn_spg_exp_adj( nit000 )
+
+      zua_adout   = ua_ad
+      zva_adout   = va_ad
+      zsshn_adout = sshn_ad
+
+      zsp2 = DOT_PRODUCT( zua_tlin  , zua_adout   ) &
+         & + DOT_PRODUCT( zva_tlin  , zva_adout   ) &
+         & + DOT_PRODUCT( zsshn_tlin, zsshn_adout )
+
+      ! 14 char:'12345678901234'
+      cl_name = 'dyn_spg_exp   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      DEALLOCATE(         &
+         & zua_tlin,      &
+         & zva_tlin,      &
+         & zsshn_tlin,    &
+         & zua_tlout,     &
+         & zva_tlout,     &
+         & zua_adin,      &
+         & zva_adin,      &
+         & zua_adout,     &
+         & zva_adout,     &
+         & zsshn_adout,   &
+         & zr3d,          &
+         & zr2d           &
+         & )
+
+   END SUBROUTINE dyn_spg_exp_adj_tst
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case :   Empty module   No standart explicit free surface 
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dyn_spg_exp_tan( kt )       ! Empty routine
+      WRITE(*,*) 'dyn_spg_exp: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_spg_exp_tan
+   SUBROUTINE dyn_spg_exp_adj( kt )       ! Empty routine
+      WRITE(*,*) 'dyn_spg_exp: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_spg_exp_adj
+   SUBROUTINE dyn_spg_exp_adj_tst( kt )       ! Empty routine
+      WRITE(*,*) 'dyn_spg_exp: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_spg_exp_adj_tst
+#endif
+
+   !!======================================================================
+END MODULE dynspg_exp_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynspg_flt_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynspg_flt_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynspg_flt_tam.F90	(revision 2578)
@@ -0,0 +1,1783 @@
+MODULE dynspg_flt_tam
+   !!----------------------------------------------------------------------
+   !!    This software is governed by the CeCILL licence (Version 2)
+   !!----------------------------------------------------------------------
+#if defined key_tam
+   !!======================================================================
+   !!  ***  MODULE  dynspg_flt_tam : TANGENT/ADJOINT OF MODULE dynspg_flt  ***
+   !!
+   !! Ocean dynamics:  surface pressure gradient trend
+   !!
+   !!======================================================================
+   !! History of the direct module:
+   !! History    OPA  !  1998-05  (G. Roullet)  free surface
+   !!                 !  1998-10  (G. Madec, M. Imbard)  release 8.2
+   !!   NEMO     O.1  !  2002-08  (G. Madec)  F90: Free form and module
+   !!             -   !  2002-11  (C. Talandier, A-M Treguier) Open boundaries
+   !!            1.0  !  2004-08  (C. Talandier) New trends organization
+   !!             -   !  2005-11  (V. Garnier) Surface pressure gradient organization
+   !!            2.0  !  2006-07  (S. Masson)  distributed restart using iom
+   !!             -   !  2006-08  (J.Chanut, A.Sellar) Calls to BDY routines. 
+   !!            3.2  !  2009-03  (G. Madec, M. Leclair, R. Benshila) introduce sshwzv module
+   !! History of the TAM module:
+   !!            9.0  ! 2008-08  (A. Vidard) skeleton
+   !!             -   ! 2008-08  (A. Weaver) original version
+   !!   NEMO     3.2  ! 2010-04  (F. Vigilant) converison to 3.2
+   !!----------------------------------------------------------------------
+# if defined key_dynspg_flt   ||   defined key_esopa  
+   !!----------------------------------------------------------------------
+   !!   'key_dynspg_flt'                              filtered free surface
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   dyn_spg_flt_tan  : update the momentum trend with the surface pressure
+   !!                      gradient in the filtered free surface case 
+   !!                      (tangent routine)
+   !!   dyn_spg_flt_adj  : update the momentum trend with the surface pressure
+   !!                      gradient in the filtered free surface case
+   !!                      (adjoint routine)
+   !!   dyn_spg_flt_adj_tst : Test of the adjoint routine
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE prtctl                  ! Print control
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1,               &
+      & jpr2di,              &
+      & jpr2dj,              &
+      & jpij,                &
+      & jpiglo,              &
+      & lk_vopt_loop
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              & 
+      & nit000,              &
+      & nitend,              &
+      & ctl_stop,            &
+      & ln_ctl,              &
+      & ctmp1
+   USE phycst        , ONLY: & ! Physical constants
+      & grav
+   USE lib_mpp       , ONLY: & ! distributed memory computing
+      & lk_mpp,              &
+      & mpp_sum
+   USE mppsum        , ONLY: & ! Summation of arrays across processors
+      & mpp_sum_indep
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+      & e1t,                 &
+      & e2t,                 &
+#  if defined key_zco
+      & e3t_0,               &
+#  else
+      & e3u,                 &
+      & e3v,                 &
+#  endif
+      & tmask,               &
+      & umask,               &
+      & vmask,               &
+      & bmask,               &
+      & rdt,                 &
+      & neuler,              &
+      & n_cla,               &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      & atfp,                &   
+      & atfp1,               &
+      & lk_vvl
+   USE solver        , ONLY: & ! Solvers
+      & sol_mat
+   USE sol_oce       , ONLY: & ! Solver variables in memory
+      & nn_solv,             &
+      & nn_nmod,             &
+      & ncut,                &
+      & niter,               &
+      & eps,                 &
+      & epsr,                &
+      & rnorme,              &
+      & res,                 &
+      & c_solver_pt,         &
+      & gcdprc
+   USE oce_tam       , ONLY: & ! Tangent-linear and adjoint model variables
+      & ub_tl,               &
+      & vb_tl,               &
+      & ua_tl,               &
+      & va_tl,               &
+      & ub_ad,               &
+      & vb_ad,               &
+      & ua_ad,               &
+      & va_ad,               &
+      & spgu_tl,             &
+      & spgv_tl,             &
+      & spgu_ad,             &
+      & spgv_ad,             &
+      & sshn_tl,             &
+      & sshn_ad
+   USE sbc_oce_tam   , ONLY: & ! Surface BCs for tangent and adjoint model
+      & emp_tl,              &
+      & emp_ad
+#  if defined key_obc
+#    if defined key_pomme_r025
+   USE obc_oce
+   USE obcdyn_tam
+#    else
+   Error, OBC not ready.
+#    endif
+#  endif
+   USE sol_oce       , ONLY: & ! Solver arrays
+      & gcdmat
+   USE sol_oce_tam   , ONLY: & ! Solver arrays for tangent and adjoint model 
+      & gcx_tl,              &
+      & gcxb_tl,             &
+      & gcb_tl,              &
+      & gcx_ad,              &
+      & gcxb_ad,             &
+      & gcb_ad
+   USE solsor_tam    , ONLY: & ! SOR solver for tangent and adjoint model 
+      & sol_sor_tan,         &
+      & sol_sor_adj
+   USE solpcg_tam    , ONLY: & ! PCG solver for tangent and adjoint model 
+      & sol_pcg_tan,         &
+      & sol_pcg_adj
+   USE lbclnk        , ONLY: & ! Lateral boundary conditions
+      & lbc_lnk,             &
+      & lbc_lnk_e
+   USE lbclnk_tam    , ONLY: & ! TAM lateral boundary conditions
+      & lbc_lnk_adj,         &
+      & lbc_lnk_e_adj
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE paresp        , ONLY: & ! Normalized energy weights
+      & wesp_emp,            &
+      & wesp_ssh         
+   USE dynadv,         ONLY: &
+      & ln_dynadv_vec          ! vector form flag     
+   USE cla_dynspg_tam, ONLY: & ! Cross land advection on surface pressure
+      & dyn_spg_cla_tan,     &
+      & dyn_spg_cla_adj
+   USE tstool_tam    , ONLY: &
+      & stdu,                &
+      & stdv,                &
+      & stdw,                &
+      & stdemp,              &
+      & stdssh,              &
+      & prntst_adj,          &
+      & prntst_tlm           
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   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
+#  if defined key_tst_tlm
+   PUBLIC dyn_spg_flt_tlm_tst
+#  endif
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE dyn_spg_flt_tan( kt, kindic )
+      !!---------------------------------------------------------------------
+      !!                  ***  routine dyn_spg_flt_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Compute the now trend due to the surface pressure 
+      !!      gradient in case of filtered free surface formulation  and add
+      !!      it to the general trend of momentum equation.
+      !!
+      !! ** Method of the direct routine:
+      !!      Filtered free surface formulation. The surface
+      !!      pressure gradient is given by:
+      !!         spgu = 1/rau0 d/dx(ps) =  1/e1u di( sshn + btda )
+      !!         spgv = 1/rau0 d/dy(ps) =  1/e2v dj( sshn + btda )
+      !!      where sshn is the free surface elevation and btda is the after
+      !!      time derivative of the free surface elevation
+      !!       -1- evaluate the surface presure trend (including the addi-
+      !!      tional force) in three steps:
+      !!        a- compute the right hand side of the elliptic equation:
+      !!            gcb = 1/(e1t e2t) [ di(e2u spgu) + dj(e1v spgv) ]
+      !!         where (spgu,spgv) are given by:
+      !!            spgu = vertical sum[ e3u (ub+ 2 rdt ua ) ]
+      !!                 - grav 2 rdt hu /e1u di[sshn + emp]
+      !!            spgv = vertical sum[ e3v (vb+ 2 rdt va) ]
+      !!                 - grav 2 rdt hv /e2v dj[sshn + emp]
+      !!         and define the first guess from previous computation :
+      !!            zbtd = btda
+      !!            btda = 2 zbtd - btdb
+      !!            btdb = zbtd
+      !!        b- compute the relative accuracy to be reached by the
+      !!         iterative solver
+      !!        c- apply the solver by a call to sol... routine
+      !!       -2- compute and add the free surface pressure gradient inclu-
+      !!      ding the additional force used to stabilize the equation.
+      !!
+      !! ** Action : - Update (ua,va) with the surf. pressure gradient trend
+      !!
+      !! References : Roullet and Madec 1999, JGR.
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( IN  ) :: &
+         &  kt         ! ocean time-step index
+      INTEGER, INTENT( OUT ) :: &
+         &  kindic     ! solver convergence flag (<0 if not converge)
+
+      !! * Local declarations
+      INTEGER  :: &
+         & ji,    &     ! dummy loop indices
+         & jj,    &
+         & jk                          
+      REAL(wp) ::  &
+         & z2dt,   & ! temporary scalars
+         & z2dtg,  & 
+         & zgcb,   &
+         & zbtd,   & 
+         & ztdgu,  &
+         & ztdgv              
+      !! Variable volume
+      REAL(wp), DIMENSION(jpi,jpj) ::  & ! 2D workspace
+         & zsshub, & 
+         & zsshua, &
+         & zsshvb, &
+         & zsshva, &
+         & zssha          
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  &  ! 3D workspace
+         & zfse3ub, &
+         & zfse3ua, &
+         & zfse3vb, &
+         & zfse3va 
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 ) THEN
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_spg_flt_tan : surface pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~   (free surface constant volume case)'
+       
+         ! set to zero free surface specific arrays
+         spgu_tl(:,:) = 0.0_wp                    ! surface pressure gradient (i-direction)
+         spgv_tl(:,:) = 0.0_wp                    ! surface pressure gradient (j-direction)
+
+      ENDIF
+
+      ! Local constant initialization
+      IF     ( neuler == 0 .AND. kt == nit000     ) THEN
+
+         z2dt = rdt             ! time step: Euler if restart from rest
+         CALL sol_mat(kt)       ! initialize matrix
+
+      ELSEIF ( neuler == 0 .AND. kt == nit000 + 1 ) THEN
+
+         z2dt = 2.0_wp * rdt    ! time step: leap-frog
+         CALL sol_mat(kt)       ! initialize matrix
+
+      ELSEIF ( neuler /= 0 .AND. kt == nit000     ) THEN
+
+         z2dt = 2.0_wp * rdt    ! time step: leap-frog
+         CALL sol_mat(kt)       ! initialize matrix
+
+      ELSE
+
+         z2dt = 2.0_wp * rdt    ! time step: leap-frog
+
+      ENDIF
+
+      z2dtg  = grav * z2dt
+
+      ! Evaluate the masked next velocity (effect of the additional force not included)
+
+      IF( lk_vvl ) THEN          ! variable volume  (surface pressure gradient already included in dyn_hpg)
+         !
+         IF( ln_dynadv_vec ) THEN      ! vector form : applied on velocity
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                     ua_tl(ji,jj,jk) = (  ub_tl(ji,jj,jk) + z2dt * ua_tl(ji,jj,jk)  ) * umask(ji,jj,jk)
+                     va_tl(ji,jj,jk) = (  vb_tl(ji,jj,jk) + z2dt * va_tl(ji,jj,jk)  ) * vmask(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+            !
+         ELSE                          ! flux form : applied on thickness weighted velocity
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                     ua_tl(ji,jj,jk) = (        ub_tl(ji,jj,jk) * fse3u_b(ji,jj,jk)      &
+                        &           + z2dt * ua_tl(ji,jj,jk) * fse3u_n(ji,jj,jk)  )   &
+                        &         / fse3u_a(ji,jj,jk) * umask(ji,jj,jk)
+                     va_tl(ji,jj,jk) = (        vb_tl(ji,jj,jk) * fse3v_b(ji,jj,jk)      &
+                        &           + z2dt * va_tl(ji,jj,jk) * fse3v_n(ji,jj,jk)  )   &
+                        &         / fse3v_a(ji,jj,jk) * vmask(ji,jj,jk)
+                 END DO
+               END DO
+            END DO
+            !
+         ENDIF
+         !
+      ELSE                       ! fixed volume  (add the surface pressure gradient + unweighted time stepping)
+         !
+         DO jj = 2, jpjm1              ! Surface pressure gradient (now)
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               spgu_tl(ji,jj) = - grav * ( sshn_tl(ji+1,jj) - sshn_tl(ji,jj) ) / e1u(ji,jj)
+               spgv_tl(ji,jj) = - grav * ( sshn_tl(ji,jj+1) - sshn_tl(ji,jj) ) / e2v(ji,jj)
+            END DO 
+         END DO 
+         DO jk = 1, jpkm1              ! unweighted time stepping 
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ua_tl(ji,jj,jk) = (  ub_tl(ji,jj,jk) + z2dt * ( ua_tl(ji,jj,jk) + spgu_tl(ji,jj) )  ) * umask(ji,jj,jk)
+                  va_tl(ji,jj,jk) = (  vb_tl(ji,jj,jk) + z2dt * ( va_tl(ji,jj,jk) + spgv_tl(ji,jj) )  ) * vmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !
+      ENDIF
+
+#  if defined key_obc
+      IF( lk_obc )   CALL obc_dyn_tan( kt )      ! Update velocities on each open boundary with the radiation algorithm
+!      IF( lk_obc )   CALL obc_vol_tan( kt )   ! Correction of the barotropic componant velocity to control the volume of the system
+#  endif
+#  if defined key_bdy
+      CALL ctl_stop( 'dyn_spg_flt_tan: key_bdy is not available' )
+#  endif
+#  if defined key_agrif
+      CALL ctl_stop( 'dyn_spg_flt_tan: key_agrif is not available' )
+#  endif
+#  if defined key_orca_r2
+      IF( n_cla == 1 )   CALL dyn_spg_cla_tan( kt )      ! Cross Land Advection (update (ua,va))
+#  endif
+
+      ! compute the next vertically averaged velocity (effect of the additional force not included)
+      ! ---------------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            spgu_tl(ji,jj) = 0.0_wp
+            spgv_tl(ji,jj) = 0.0_wp
+         END DO
+      END DO
+
+      ! vertical sum
+!CDIR NOLOOPCHG
+      IF( lk_vopt_loop ) THEN          ! vector opt., forced unroll
+         DO jk = 1, jpkm1
+            DO ji = 1, jpij
+               spgu_tl(ji,1) = spgu_tl(ji,1) + fse3u(ji,1,jk) * ua_tl(ji,1,jk)
+               spgv_tl(ji,1) = spgv_tl(ji,1) + fse3v(ji,1,jk) * va_tl(ji,1,jk)
+            END DO
+         END DO
+      ELSE                        ! No  vector opt.
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  spgu_tl(ji,jj) = spgu_tl(ji,jj) + fse3u(ji,jj,jk) * ua_tl(ji,jj,jk)
+                  spgv_tl(ji,jj) = spgv_tl(ji,jj) + fse3v(ji,jj,jk) * va_tl(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      ! transport: multiplied by the horizontal scale factor
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            spgu_tl(ji,jj) = spgu_tl(ji,jj) * e2u(ji,jj)
+            spgv_tl(ji,jj) = spgv_tl(ji,jj) * e1v(ji,jj)
+         END DO
+      END DO
+
+      CALL lbc_lnk( spgu_tl, 'U', -1.0_wp )       ! lateral boundary conditions 
+      CALL lbc_lnk( spgv_tl, 'V', -1.0_wp )
+
+      IF( lk_vvl ) CALL ctl_stop( 'dyn_spg_flt_tan: lk_vvl is not available' )
+
+      ! Right hand side of the elliptic equation and first guess
+      ! -----------------------------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ! Divergence of the after vertically averaged velocity
+            zgcb =  spgu_tl(ji,jj) - spgu_tl(ji-1,jj)   &
+               &  + spgv_tl(ji,jj) - spgv_tl(ji,jj-1)
+            gcb_tl(ji,jj) = gcdprc(ji,jj) * zgcb
+            ! First guess of the after barotropic transport divergence
+            zbtd = gcx_tl(ji,jj)
+            gcx_tl (ji,jj) = 2.0_wp * zbtd - gcxb_tl(ji,jj)
+            gcxb_tl(ji,jj) =          zbtd
+         END DO
+      END DO
+      ! apply the lateral boundary conditions
+      IF( nn_solv == 2 .AND. MAX( jpr2di, jpr2dj ) > 0 ) CALL lbc_lnk_e( gcb_tl, c_solver_pt, 1.0_wp )   
+#  if defined key_agrif
+      CALL ctl_stop( 'dyn_spg_flt_tan: key_agrif is not available' )
+#  endif
+
+      ! Relative precision (computation on one processor)
+      ! ------------------
+      rnorme = SUM( gcb_tl(1:jpi,1:jpj) * gcdmat(1:jpi,1:jpj) * gcb_tl(1:jpi,1:jpj) * bmask(:,:) )
+      IF( lk_mpp )   CALL mpp_sum( rnorme )   ! sum over the global domain
+
+      epsr = eps * eps * rnorme
+      ncut = 0
+      ! if rnorme is 0, the solution is 0, the solver is not called
+      IF( rnorme == 0.0_wp ) THEN
+         gcx_tl(:,:) = 0.0_wp
+         res   = 0.0_wp
+         niter = 0
+         ncut  = 999
+      ENDIF
+
+      ! Evaluate the next transport divergence
+      ! --------------------------------------
+      !    Iterarive solver for the elliptic equation (except IF sol.=0)
+      !    (output in gcx with boundary conditions applied)
+      kindic = 0
+      IF( ncut == 0 ) THEN
+         IF    ( nn_solv == 1 ) THEN  ;  CALL sol_pcg_tan( kt, kindic )   ! diagonal preconditioned conjuguate gradient
+         ELSEIF( nn_solv == 2 ) THEN  ;  CALL sol_sor_tan( kt, kindic )   ! successive-over-relaxation
+         ENDIF
+      ENDIF
+      
+      ! Transport divergence gradient multiplied by z2dt
+      ! --------------------------------------------====
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ! trend of Transport divergence gradient
+            ztdgu = z2dtg * ( gcx_tl(ji+1,jj  ) - gcx_tl(ji,jj) ) / e1u(ji,jj)
+            ztdgv = z2dtg * ( gcx_tl(ji  ,jj+1) - gcx_tl(ji,jj) ) / e2v(ji,jj)
+            ! multiplied by z2dt
+#  if defined key_obc
+            ! caution : grad D = 0 along open boundaries
+            IF( Agrif_Root() ) THEN
+               spgu_tl(ji,jj) = z2dt * ztdgu * obcumask(ji,jj)
+               spgv_tl(ji,jj) = z2dt * ztdgv * obcvmask(ji,jj)         
+            ELSE
+               spgu_tl(ji,jj) = z2dt * ztdgu
+               spgv_tl(ji,jj) = z2dt * ztdgv
+            ENDIF
+#  elif defined key_bdy
+            CALL ctl_stop( 'dyn_spg_flt_tan: key_bdy is not available' )
+#  else
+            spgu_tl(ji,jj) = z2dt * ztdgu
+            spgv_tl(ji,jj) = z2dt * ztdgv
+#  endif
+         END DO
+      END DO
+
+#  if defined key_agrif      
+      CALL ctl_stop( 'dyn_spg_flt_tan: key_agrif is not available' )
+#  endif
+
+      ! Add the trends multiplied by z2dt to the after velocity
+      ! -------------------------------------------------------
+      !     ( c a u t i o n : (ua_tl,va_tl) here are the after velocity not the
+      !                       trend, the leap-frog time stepping will not
+      !                       be done in dynnxt_tan.F90 routine)
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ua_tl(ji,jj,jk) = ( ua_tl(ji,jj,jk) + spgu_tl(ji,jj) ) * umask(ji,jj,jk)
+               va_tl(ji,jj,jk) = ( va_tl(ji,jj,jk) + spgv_tl(ji,jj) ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      !
+   END SUBROUTINE dyn_spg_flt_tan
+
+   SUBROUTINE dyn_spg_flt_adj( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine dyn_spg_flt_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Compute the now trend due to the surface pressure 
+      !!      gradient in case of filtered free surface formulation  and add
+      !!      it to the general trend of momentum equation.
+      !!
+      !! ** Method of the direct routine:
+      !!      Filtered free surface formulation. The surface
+      !!      pressure gradient is given by:
+      !!         spgu = 1/rau0 d/dx(ps) =  1/e1u di( sshn + btda )
+      !!         spgv = 1/rau0 d/dy(ps) =  1/e2v dj( sshn + btda )
+      !!      where sshn is the free surface elevation and btda is the after
+      !!      time derivative of the free surface elevation
+      !!       -1- evaluate the surface presure trend (including the addi-
+      !!      tional force) in three steps:
+      !!        a- compute the right hand side of the elliptic equation:
+      !!            gcb = 1/(e1t e2t) [ di(e2u spgu) + dj(e1v spgv) ]
+      !!         where (spgu,spgv) are given by:
+      !!            spgu = vertical sum[ e3u (ub+ 2 rdt ua ) ]
+      !!                 - grav 2 rdt hu /e1u di[sshn + emp]
+      !!            spgv = vertical sum[ e3v (vb+ 2 rdt va) ]
+      !!                 - grav 2 rdt hv /e2v dj[sshn + emp]
+      !!         and define the first guess from previous computation :
+      !!            zbtd = btda
+      !!            btda = 2 zbtd - btdb
+      !!            btdb = zbtd
+      !!        b- compute the relative accuracy to be reached by the
+      !!         iterative solver
+      !!        c- apply the solver by a call to sol... routine
+      !!       -2- compute and add the free surface pressure gradient inclu-
+      !!      ding the additional force used to stabilize the equation.
+      !!
+      !! ** Action : - Update (ua,va) with the surf. pressure gradient trend
+      !!
+      !! References : Roullet and Madec 1999, JGR.
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( IN  ) :: &
+         &  kt         ! ocean time-step index
+      INTEGER, INTENT( OUT ) :: &
+         &  kindic     ! solver convergence flag (<0 if not converge)
+
+      !! * Local declarations
+      INTEGER  :: &
+         & ji, &     ! dummy loop indices
+         & jj, &
+         & jk                          
+      REAL(wp) :: &
+         & z2dt,   & ! temporary scalars
+         & z2dtg,  &
+         & zgcb,   &
+         & zbtd,   & 
+         & ztdgu,  &
+         & ztdgv              
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_spg_flt_adj : surface pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~   (free surface constant volume case)'
+      ENDIF
+
+      ! Local constant initialization
+      IF     ( neuler == 0 .AND. kt == nit000     ) THEN
+
+         z2dt = rdt             ! time step: Euler if restart from rest
+         CALL sol_mat(kt)       ! initialize matrix
+
+      ELSEIF (   neuler == 0 .AND. kt == nit000 + 1 ) THEN
+
+         z2dt = 2.0_wp * rdt    ! time step: leap-frog
+         CALL sol_mat(kt)       ! reinitialize matrix
+
+      ELSEIF (                   kt == nitend     ) THEN
+
+         z2dt = 2.0_wp * rdt    ! time step: leap-frog
+         CALL sol_mat(kt)       ! reinitialize matrix
+
+      ELSEIF ( neuler /= 0 .AND. kt == nit000     ) THEN
+
+         z2dt = 2.0_wp * rdt    ! time step: leap-frog
+         CALL sol_mat(kt)       ! initialize matrix
+
+      ELSE
+
+         z2dt = 2.0_wp * rdt    ! time step: leap-frog
+
+      ENDIF
+
+      z2dtg  = grav * z2dt
+
+      ! Add the trends multiplied by z2dt to the after velocity
+      ! -----------------------------------------------------------
+      !     ( c a u t i o n : (ua_ad,va_ad) here are the after velocity not the
+      !                       trend, the leap-frog time stepping will not
+      !                       be done in dynnxt_adj.F90 routine)
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ua_ad(ji,jj,jk) = ua_ad(ji,jj,jk) * umask(ji,jj,jk)
+               va_ad(ji,jj,jk) = va_ad(ji,jj,jk) * vmask(ji,jj,jk)
+               spgu_ad(ji,jj)  = spgu_ad(ji,jj)  + ua_ad(ji,jj,jk)
+               spgv_ad(ji,jj)  = spgv_ad(ji,jj)  + va_ad(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+#  if defined key_agrif      
+      CALL ctl_stop( 'dyn_spg_flt_adj: key_agrif is not available' )
+#  endif
+
+      ! Transport divergence gradient multiplied by z2dt
+      ! --------------------------------------------====
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ! multiplied by z2dt
+#  if defined key_obc
+            ! caution : grad D = 0 along open boundaries
+            IF( Agrif_Root() ) THEN
+               ztdgu = z2dt * spgu_ad(ji,jj) * obcumask(ji,jj)
+               ztdgv = z2dt * spgv_ad(ji,jj) * obcvmask(ji,jj)     
+               spgu_ad(ji,jj) = 0.0_wp
+               spgv_ad(ji,jj) = 0.0_wp
+            ELSE
+               ztdgu = z2dt * spgu_ad(ji,jj)
+               ztdgv = z2dt * spgv_ad(ji,jj)     
+               spgu_ad(ji,jj) = 0.0_wp
+               spgv_ad(ji,jj) = 0.0_wp
+            ENDIF
+#  elif defined key_bdy
+            CALL ctl_stop( 'dyn_spg_flt_adj: key_bdy is not available' )
+#  else
+            ztdgu = z2dt * spgu_ad(ji,jj)
+            ztdgv = z2dt * spgv_ad(ji,jj)
+            spgu_ad(ji,jj) = 0.0_wp
+            spgv_ad(ji,jj) = 0.0_wp
+#  endif
+            ! trend of Transport divergence gradient
+            ztdgu = ztdgu * z2dtg / e1u(ji,jj)
+            ztdgv = ztdgv * z2dtg / e2v(ji,jj)
+            gcx_ad(ji  ,jj  ) = gcx_ad(ji  ,jj  ) - ztdgu - ztdgv
+            gcx_ad(ji  ,jj+1) = gcx_ad(ji  ,jj+1) + ztdgv
+            gcx_ad(ji+1,jj  ) = gcx_ad(ji+1,jj  ) + ztdgu
+         END DO
+      END DO
+
+      ! Evaluate the next transport divergence
+      ! --------------------------------------
+      !    Iterative solver for the elliptic equation (except IF sol.=0)
+      !    (output in gcx_ad with boundary conditions applied)
+
+      kindic = 0
+      ncut = 0    !  Force solver
+      IF( ncut == 0 ) THEN
+         IF    ( nn_solv == 1 ) THEN ;  CALL sol_pcg_adj( kt, kindic )   ! diagonal preconditioned conjuguate gradient
+         ELSEIF( nn_solv == 2 ) THEN ;  CALL sol_sor_adj( kt, kindic )   ! successive-over-relaxation
+         ENDIF
+      ENDIF
+#  if defined key_agrif
+      CALL ctl_stop( 'dyn_spg_flt_adj: key_agrif is not available' )
+#  endif
+
+      ! Right hand side of the elliptic equation and first guess
+      ! --------------------------------------------------------
+      ! apply the lateral boundary conditions
+      IF( nn_solv == 2 .AND. MAX( jpr2di, jpr2dj ) > 0 ) &
+         &    CALL lbc_lnk_e_adj( gcb_ad, c_solver_pt, 1.0_wp )   
+
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ! First guess of the after barotropic transport divergence
+            zbtd = gcxb_ad(ji,jj) + 2.0_wp * gcx_ad(ji,jj) 
+            gcxb_ad(ji,jj) = - gcx_ad(ji,jj)
+            gcx_ad (ji,jj) = zbtd
+            ! Divergence of the after vertically averaged velocity
+            zgcb = gcb_ad(ji,jj) * gcdprc(ji,jj)
+            gcb_ad(ji,jj) = 0.0_wp
+            spgu_ad(ji-1,jj  ) = spgu_ad(ji-1,jj  ) - zgcb
+            spgu_ad(ji  ,jj  ) = spgu_ad(ji  ,jj  ) + zgcb
+            spgv_ad(ji  ,jj-1) = spgv_ad(ji  ,jj-1) - zgcb
+            spgv_ad(ji  ,jj  ) = spgv_ad(ji  ,jj  ) + zgcb
+         END DO
+      END DO
+
+      IF( lk_vvl ) CALL ctl_stop( 'dyn_spg_flt_adj: lk_vvl is not available' )
+
+      ! Boundary conditions on (spgu_ad,spgv_ad)
+      CALL lbc_lnk_adj( spgu_ad, 'U', -1.0_wp )
+      CALL lbc_lnk_adj( spgv_ad, 'V', -1.0_wp )
+
+      ! transport: multiplied by the horizontal scale factor
+      DO jj = 2,jpjm1
+         DO ji = fs_2,fs_jpim1   ! vector opt.
+            spgu_ad(ji,jj) = spgu_ad(ji,jj) * e2u(ji,jj)
+            spgv_ad(ji,jj) = spgv_ad(ji,jj) * e1v(ji,jj)
+         END DO
+      END DO
+
+      ! compute the next vertically averaged velocity (effect of the additional force not included)
+      ! ---------------------------------------------
+
+      ! vertical sum
+!CDIR NOLOOPCHG
+      IF( lk_vopt_loop ) THEN     ! vector opt., forced unroll
+         DO jk = 1, jpkm1
+            DO ji = 1, jpij
+               ua_ad(ji,1,jk) = ua_ad(ji,1,jk) + fse3u(ji,1,jk) * spgu_ad(ji,1)
+               va_ad(ji,1,jk) = va_ad(ji,1,jk) + fse3v(ji,1,jk) * spgv_ad(ji,1)
+            END DO
+         END DO
+      ELSE                        ! No  vector opt.
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  ua_ad(ji,jj,jk) = ua_ad(ji,jj,jk) + fse3u(ji,jj,jk) * spgu_ad(ji,jj)
+                  va_ad(ji,jj,jk) = va_ad(ji,jj,jk) + fse3v(ji,jj,jk) * spgv_ad(ji,jj)
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1 ! vector opt.
+            spgu_ad(ji,jj) = 0.0_wp
+            spgv_ad(ji,jj) = 0.0_wp
+         END DO
+      END DO
+
+#  if defined key_orca_r2
+      IF( n_cla == 1 )   CALL dyn_spg_cla_adj( kt )      ! Cross Land Advection (update (ua,va))
+#  endif
+#  if defined key_agrif
+      CALL ctl_stop( 'dyn_spg_flt_adj: key_agrif is not available' )
+#  endif
+#  if defined key_bdy
+      CALL ctl_stop( 'dyn_spg_flt_adj: key_bdy is not available' )
+#  endif
+#  if defined key_obc
+      !      IF( lk_obc )   CALL obc_vol_adj( kt )   ! Correction of the barotropic componant velocity to control the volume of the system
+      IF( lk_obc )   CALL obc_dyn_adj( kt )      ! Update velocities on each open boundary with the radiation algorithm      
+#  endif
+
+      ! Evaluate the masked next velocity (effect of the additional force not included)
+      IF( lk_vvl ) THEN          ! variable volume  (surface pressure gradient already included in dyn_hpg) 
+         !
+         IF( ln_dynadv_vec ) THEN      ! vector form : applied on velocity
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                     ub_ad(ji,jj,jk) = ub_ad(ji,jj,jk) + z2dt * ua_ad(ji,jj,jk) * umask(ji,jj,jk)
+                     ua_ad(ji,jj,jk) = z2dt * ua_ad(ji,jj,jk) * umask(ji,jj,jk)
+                     vb_ad(ji,jj,jk) = vb_ad(ji,jj,jk) + z2dt * va_ad(ji,jj,jk) * vmask(ji,jj,jk)
+                     va_ad(ji,jj,jk) = z2dt * va_ad(ji,jj,jk) * vmask(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+            !
+         ELSE                          ! flux form : applied on thickness weighted velocity
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                     ua_ad(ji,jj,jk) = ua_ad(ji,jj,jk) / fse3u_a(ji,jj,jk) * umask(ji,jj,jk)
+                     ub_ad(ji,jj,jk) = ub_ad(ji,jj,jk) + ua_ad(ji,jj,jk) * fse3u_b(ji,jj,jk)
+                     ua_ad(ji,jj,jk) = ua_ad(ji,jj,jk) * z2dt * fse3u_n(ji,jj,jk)
+                     va_ad(ji,jj,jk) = va_ad(ji,jj,jk) / fse3v_a(ji,jj,jk) * vmask(ji,jj,jk)
+                     vb_ad(ji,jj,jk) = vb_ad(ji,jj,jk) + va_ad(ji,jj,jk) * fse3v_b(ji,jj,jk)
+                     va_ad(ji,jj,jk) = va_ad(ji,jj,jk) * z2dt * fse3v_n(ji,jj,jk)
+                 END DO
+               END DO
+            END DO
+            !
+         ENDIF
+         !
+      ELSE                       ! fixed volume  (add the surface pressure gradient + unweighted time stepping) 
+         !
+         DO jk = 1, jpkm1               ! unweighted time stepping 
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ua_ad(  ji,jj,jk) = ua_ad(ji,jj,jk) * umask(ji,jj,jk)
+                  ub_ad(  ji,jj,jk) = ub_ad(ji,jj,jk) + ua_ad(ji,jj,jk)
+                  spgu_ad(ji,jj   ) = spgu_ad(ji,jj)  + ua_ad(ji,jj,jk) * z2dt
+                  ua_ad(  ji,jj,jk) = ua_ad(ji,jj,jk) * z2dt
+                  va_ad(  ji,jj,jk) = va_ad(ji,jj,jk) * vmask(ji,jj,jk)
+                  vb_ad(  ji,jj,jk) = vb_ad(ji,jj,jk) + va_ad(ji,jj,jk)
+                  spgv_ad(ji,jj   ) = spgv_ad(ji,jj)  + va_ad(ji,jj,jk) * z2dt
+                  va_ad(  ji,jj,jk) = va_ad(ji,jj,jk) * z2dt
+               END DO
+            END DO
+         END DO
+         DO jj = 2, jpjm1              ! Surface pressure gradient (now)
+            DO ji = fs_2, fs_jpim1     ! vector opt.
+               spgu_ad(ji  ,jj  ) = spgu_ad(ji  ,jj  ) * grav / e1u(ji,jj)
+               spgv_ad(ji  ,jj  ) = spgv_ad(ji  ,jj  ) * grav / e2v(ji,jj)
+               sshn_ad(ji  ,jj  ) = sshn_ad(ji  ,jj  ) + spgv_ad(ji,jj)
+               sshn_ad(ji  ,jj+1) = sshn_ad(ji  ,jj+1) - spgv_ad(ji,jj)
+               sshn_ad(ji  ,jj  ) = sshn_ad(ji  ,jj  ) + spgu_ad(ji,jj)
+               sshn_ad(ji+1,jj  ) = sshn_ad(ji+1,jj  ) - spgu_ad(ji,jj)
+               spgu_ad(ji  ,jj  ) = 0.0_wp
+               spgv_ad(ji  ,jj  ) = 0.0_wp
+            END DO 
+         END DO 
+      ENDIF
+
+      IF( kt == nit000 ) THEN
+         ! set to zero free surface specific arrays
+         spgu_ad(:,:) = 0.0_wp                    ! surface pressure gradient (i-direction)
+         spgv_ad(:,:) = 0.0_wp                    ! surface pressure gradient (j-direction)
+      ENDIF
+
+   END SUBROUTINE dyn_spg_flt_adj
+
+   SUBROUTINE dyn_spg_flt_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_spg_flt_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : 
+      !!                
+      !! History :
+      !!        ! 09-01 (A. Weaver)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt        ! Output unit
+
+      !! * Local declarations
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zua_tlin,    & ! Tangent input: ua_tl
+         & zva_tlin,    & ! Tangent input: va_tl
+         & zub_tlin,    & ! Tangent input: ub_tl
+         & zvb_tlin,    & ! Tangent input: vb_tl
+         & zua_tlout,   & ! Tangent output: ua_tl
+         & zva_tlout,   & ! Tangent output: va_tl
+         & zub_tlout,   & ! Tangent output: ua_tl
+         & zvb_tlout,   & ! Tangent output: va_tl         
+         & zub_adin,    & ! Tangent output: ua_ad
+         & zvb_adin,    & ! Tangent output: va_ad         
+         & zua_adin,    & ! Adjoint input: ua_ad
+         & zva_adin,    & ! Adjoint input: va_ad
+         & zua_adout,   & ! Adjoint output: ua_ad
+         & zva_adout,   & ! Adjoint output: va_ad
+         & zub_adout,   & ! Adjoint oputput: ub_ad
+         & zvb_adout,   & ! Adjoint output: vb_ad
+         & znu            ! 3D random field for u
+
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zgcx_tlin, zgcxb_tlin, zgcb_tlin, zgcx_tlout, zgcxb_tlout, zgcb_tlout,  &
+         & zgcx_adin, zgcxb_adin, zgcb_adin, zgcx_adout, zgcxb_adout, zgcb_adout,  &
+         & zspgu_tlout, zspgv_tlout, zspgu_adin, zspgv_adin
+
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zsshn_tlin, & ! Tangent input: sshn_tl
+         & zsshn_adout,& ! Adjoint output: sshn_ad
+         & zemp_tlin,  & ! Tangent input: emp_tl
+         & zemp_adout, & ! Adjoint output: emp_ad
+         & znssh         ! 2D random field for SSH
+      REAL(wp) :: &
+         & zsp1,    &   ! scalar product involving the tangent routine
+         & zsp2         ! scalar product involving the adjoint routine
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d    ! 2D seed for the random number generator
+      INTEGER :: &
+         & indic, &
+         & istp
+      INTEGER :: &
+         & ji, &
+         & jj, &
+         & jk, &
+         & kmod, &
+         & jstp
+      CHARACTER (LEN=14) :: &
+         & cl_name
+      INTEGER ::             &
+         & jpert
+      INTEGER, PARAMETER :: jpertmax = 7
+
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zua_tlin(jpi,jpj,jpk),  &
+         & zva_tlin(jpi,jpj,jpk),  &
+         & zub_tlin(jpi,jpj,jpk),  &
+         & zvb_tlin(jpi,jpj,jpk),  &
+         & zua_tlout(jpi,jpj,jpk), &
+         & zva_tlout(jpi,jpj,jpk), &
+         & zua_adin(jpi,jpj,jpk),  &
+         & zva_adin(jpi,jpj,jpk),  &
+         & zua_adout(jpi,jpj,jpk), &
+         & zva_adout(jpi,jpj,jpk), &
+         & zub_adout(jpi,jpj,jpk), &
+         & zvb_adout(jpi,jpj,jpk), &
+         & znu(jpi,jpj,jpk)        &
+         & )
+      ALLOCATE( &
+         & zsshn_tlin(jpi,jpj), &
+         & zsshn_adout(jpi,jpj),&
+         & zemp_tlin(jpi,jpj),  &
+         & zemp_adout(jpi,jpj), &
+         & znssh(jpi,jpj)       &
+         & )
+
+#  if defined key_obc
+      ALLOCATE( zemp_tlout(jpi,jpj), zemp_adin  (jpi,jpj), &
+                zwn_tlout (jpi,jpj), zwn_adin   (jpi,jpj) )
+#  endif
+
+      ALLOCATE( zgcx_tlin (jpi,jpj), zgcx_tlout (jpi,jpj), zgcx_adin (jpi,jpj), zgcx_adout (jpi,jpj),  &
+                zgcxb_tlin(jpi,jpj), zgcxb_tlout(jpi,jpj), zgcxb_adin(jpi,jpj), zgcxb_adout(jpi,jpj),  &
+                zgcb_tlin (jpi,jpj), zgcb_tlout (jpi,jpj), zgcb_adin (jpi,jpj), zgcb_adout (jpi,jpj)   &
+               & )
+
+      ALLOCATE ( zub_tlout(jpi,jpj,jpk), zvb_tlout(jpi,jpj,jpk),  &
+                 zub_adin (jpi,jpj,jpk), zvb_adin (jpi,jpj,jpk)  )
+
+      ALLOCATE( zspgu_tlout (jpi,jpj), zspgv_tlout (jpi,jpj), zspgu_adin (jpi,jpj), zspgv_adin (jpi,jpj))
+
+      !=========================================================================
+      !     dx = ( sshb_tl, sshn_tl, ub_tl, ua_tl, vb_tl, va_tl, wn_tl, emp_tl )
+      ! and dy = ( sshb_tl, sshn_tl, ua_tl, va_tl )
+      !=========================================================================
+
+      ! Test for time steps nit000 and nit000 + 1 (the matrix changes)
+
+      DO jstp = nit000, nit000 + 1
+         DO jpert = 1, jpertmax
+            istp = jstp
+
+            !--------------------------------------------------------------------
+            ! Reset the tangent and adjoint variables
+            !--------------------------------------------------------------------
+
+            zub_tlin (:,:,:) = 0.0_wp
+            zvb_tlin (:,:,:) = 0.0_wp
+            zua_tlin (:,:,:) = 0.0_wp
+            zva_tlin (:,:,:) = 0.0_wp
+            zua_tlout(:,:,:) = 0.0_wp
+            zva_tlout(:,:,:) = 0.0_wp
+            zua_adin (:,:,:) = 0.0_wp
+            zva_adin (:,:,:) = 0.0_wp
+            zub_adout(:,:,:) = 0.0_wp
+            zvb_adout(:,:,:) = 0.0_wp
+            zua_adout(:,:,:) = 0.0_wp
+            zva_adout(:,:,:) = 0.0_wp
+
+            zsshn_tlin (:,:) = 0.0_wp
+            zemp_tlin  (:,:) = 0.0_wp
+            zsshn_adout(:,:) = 0.0_wp
+            zemp_adout (:,:) = 0.0_wp
+            zspgu_adin (:,:) = 0.0_wp
+            zspgv_adin (:,:) = 0.0_wp
+            zspgu_tlout(:,:) = 0.0_wp
+            zspgv_tlout(:,:) = 0.0_wp
+
+            zgcx_tlout (:,:) = 0.0_wp ; zgcx_adin (:,:) = 0.0_wp ; zgcx_adout (:,:) = 0.0_wp
+            zgcxb_tlout(:,:) = 0.0_wp ; zgcxb_adin(:,:) = 0.0_wp ; zgcxb_adout(:,:) = 0.0_wp
+            zgcb_tlout (:,:) = 0.0_wp ; zgcb_adin (:,:) = 0.0_wp ; zgcb_adout (:,:) = 0.0_wp
+
+            ub_tl(:,:,:) = 0.0_wp
+            vb_tl(:,:,:) = 0.0_wp
+            ua_tl(:,:,:) = 0.0_wp
+            va_tl(:,:,:) = 0.0_wp
+            sshn_tl(:,:) = 0.0_wp
+            emp_tl(:,:)  = 0.0_wp
+            gcb_tl(:,:)  = 0.0_wp
+            gcx_tl(:,:)  = 0.0_wp
+            gcxb_tl(:,:) = 0.0_wp
+            spgu_tl(:,:) = 0.0_wp
+            spgv_tl(:,:) = 0.0_wp
+            ub_ad(:,:,:) = 0.0_wp
+            vb_ad(:,:,:) = 0.0_wp
+            ua_ad(:,:,:) = 0.0_wp
+            va_ad(:,:,:) = 0.0_wp
+            sshn_ad(:,:) = 0.0_wp
+            emp_ad(:,:)  = 0.0_wp
+            gcb_ad(:,:)  = 0.0_wp
+            gcx_ad(:,:)  = 0.0_wp
+            gcxb_ad(:,:) = 0.0_wp
+            spgu_ad(:,:) = 0.0_wp
+            spgv_ad(:,:) = 0.0_wp
+            !--------------------------------------------------------------------
+            ! Initialize the tangent input with random noise: dx
+            !--------------------------------------------------------------------
+            IF ( (jpert == 1) .OR. (jpert == jpertmax) ) THEN
+
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     iseed_2d(ji,jj) = - ( 456953 + &
+                        &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+                  END DO
+               END DO
+               CALL grid_random( iseed_2d, znu, 'U', 0.0_wp, stdu )
+
+               DO jk = 1, jpk
+                  DO jj = nldj, nlej
+                     DO ji = nldi, nlei
+                        zua_tlin(ji,jj,jk) = znu(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+
+            ENDIF
+            IF ( (jpert == 2) .OR. (jpert == jpertmax) ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     iseed_2d(ji,jj) = - ( 3434334 + &
+                        &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+                  END DO
+               END DO
+               CALL grid_random( iseed_2d, znu, 'V', 0.0_wp, stdv )
+
+               DO jk = 1, jpk
+                  DO jj = nldj, nlej
+                     DO ji = nldi, nlei
+                        zva_tlin(ji,jj,jk) = znu(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+
+            ENDIF
+            IF ( (jpert == 3) .OR. (jpert == jpertmax) ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     iseed_2d(ji,jj) = - ( 935678 + &
+                        &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+                  END DO
+               END DO
+               CALL grid_random( iseed_2d, znu, 'U', 0.0_wp, stdu )
+
+               DO jk = 1, jpk
+                  DO jj = nldj, nlej
+                     DO ji = nldi, nlei
+                        zub_tlin(ji,jj,jk) = znu(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+
+            ENDIF
+            IF ( (jpert == 4) .OR. (jpert == jpertmax) ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     iseed_2d(ji,jj) = - ( 1462578 + &
+                        &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+                  END DO
+               END DO
+               CALL grid_random( iseed_2d, znu, 'V', 0.0_wp, stdv )
+
+               DO jk = 1, jpk
+                  DO jj = nldj, nlej
+                     DO ji = nldi, nlei
+                        zvb_tlin(ji,jj,jk) = znu(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+
+            ENDIF
+            IF ( (jpert == 5) .OR. (jpert == jpertmax) ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     iseed_2d(ji,jj) = - ( 25674910 + &
+                        &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+                  END DO
+               END DO
+               CALL grid_random( iseed_2d, znssh, 'T', 0.0_wp, stdemp )
+
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     zemp_tlin(ji,jj) = znssh(ji,jj)
+                  END DO
+               END DO
+
+            ENDIF
+            IF ( (jpert == 6) .OR. (jpert == jpertmax) ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     iseed_2d(ji,jj) = - ( 12672456 + &
+                        &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+                  END DO
+               END DO
+               CALL grid_random( iseed_2d, znssh, 'T', 0.0_wp, stdssh )
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     zsshn_tlin(ji,jj) = znssh(ji,jj)
+                  END DO
+               END DO
+            END IF
+#  if defined key_obc
+            zgcx_tlin  (:,:) = ( zua_tlin(:,:,1) + zub_tlin(:,:,1) ) / 10.
+            zgcxb_tlin (:,:) = ( zua_tlin(:,:,2) + zub_tlin(:,:,2) ) / 10.
+            zgcb_tlin  (:,:) = ( zua_tlin(:,:,3) + zub_tlin(:,:,3) ) / 10.
+#  endif
+            zgcx_tlin  (:,:) = ( zua_tlin(:,:,1) + zub_tlin(:,:,1) ) / 10.
+            zgcxb_tlin (:,:) = ( zua_tlin(:,:,2) + zub_tlin(:,:,2) ) / 10.
+            !--------------------------------------------------------------------
+            ! Call the tangent routine: dy = L dx
+            !--------------------------------------------------------------------
+
+            ua_tl(:,:,:) = zua_tlin(:,:,:)
+            va_tl(:,:,:) = zva_tlin(:,:,:)
+            ub_tl(:,:,:) = zub_tlin(:,:,:)
+            vb_tl(:,:,:) = zvb_tlin(:,:,:)
+            emp_tl (:,:) = zemp_tlin (:,:)
+            sshn_tl(:,:) = zsshn_tlin(:,:)
+
+#  if defined key_obc
+            gcb_tl (:,:) = zgcb_tlin (:,:)
+#  else
+            gcx_tl (:,:) = 0.e0              ;   gcxb_tl(:,:) = 0.e0
+            gcb_tl (:,:) = 0.e0
+            gcx_tl (:,:) = zgcx_tlin (:,:)   ;   gcxb_tl(:,:) = zgcxb_tlin(:,:)
+#  endif
+
+            CALL dyn_spg_flt_tan( istp, indic )
+
+            zua_tlout(:,:,:) = ua_tl(:,:,:)   ;   zva_tlout(:,:,:) = va_tl(:,:,:)
+#  if defined key_obc
+            zgcx_tlout (:,:) = gcx_tl (:,:)   ;   zgcxb_tlout(:,:) = gcxb_tl(:,:)
+#  endif
+            zspgu_tlout(:,:) = spgu_tl(:,:)   ;   zspgv_tlout(:,:) = spgv_tl(:,:)
+            zgcb_tlout (:,:) = gcb_tl (:,:)
+
+            !--------------------------------------------------------------------
+            ! Initialize the adjoint variables: dy^* = W dy
+            !--------------------------------------------------------------------
+
+            DO jk = 1, jpk
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     zua_adin(ji,jj,jk) = zua_tlout(ji,jj,jk) &
+                        &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                        &               * umask(ji,jj,jk)
+                     zva_adin(ji,jj,jk) = zva_tlout(ji,jj,jk) &
+                        &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+                        &               * vmask(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+#  if defined key_obc
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zgcx_adin (ji,jj) = zgcx_tlout (ji,jj) &
+                     &              * e1t(ji,jj) * e2t(ji,jj) * fse3u(ji,jj,1) * tmask(ji,jj,1)
+                  zgcxb_adin(ji,jj) = zgcxb_tlout(ji,jj) &
+                     &              * e1t(ji,jj) * e2t(ji,jj) * fse3u(ji,jj,1) * tmask(ji,jj,1)
+               END DO
+            END DO
+#  endif
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zgcb_adin (ji,jj) = zgcb_tlout (ji,jj) &
+                     &              * e1t(ji,jj) * e2t(ji,jj) * fse3u(ji,jj,1) * tmask(ji,jj,1)
+                  zspgu_adin (ji,jj) = zspgu_tlout (ji,jj) &
+                     &              * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,1) * umask(ji,jj,1)
+                  zspgv_adin(ji,jj) = zspgv_tlout(ji,jj) &
+                     &              * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,1) * vmask(ji,jj,1)
+               END DO
+            END DO
+
+            !--------------------------------------------------------------------
+            ! Compute the scalar product: ( L dx )^T W dy
+            !--------------------------------------------------------------------
+
+            zsp1 =   DOT_PRODUCT( zua_tlout  , zua_adin   ) &
+#  if defined key_obc
+               &   + DOT_PRODUCT( zgcx_tlout , zgcx_adin  ) &
+               &   + DOT_PRODUCT( zgcxb_tlout, zgcxb_adin ) &
+#  endif
+               &   + DOT_PRODUCT( zgcb_tlout , zgcb_adin  ) &
+               &   + DOT_PRODUCT( zspgu_tlout , zspgu_adin  ) &
+               &   + DOT_PRODUCT( zspgv_tlout , zspgv_adin  ) &
+               &   + DOT_PRODUCT( zva_tlout  , zva_adin   ) 
+
+
+            !--------------------------------------------------------------------
+            ! Call the adjoint routine: dx^* = L^T dy^*
+            !--------------------------------------------------------------------
+
+            ua_ad(:,:,:) = zua_adin(:,:,:)
+            va_ad(:,:,:) = zva_adin(:,:,:)
+
+#  if defined key_obc
+            gcx_ad (:,:)   = zgcx_adin (:,:)   ;   gcxb_ad(:,:)   = zgcxb_adin(:,:)
+#  else
+            gcx_ad (:,:)   = 0.0_wp            ;   gcxb_ad(:,:) = 0.0_wp
+            gcb_ad (:,:)   = zgcb_adin (:,:)
+            spgu_ad(:,:)   = zspgu_adin(:,:)
+            spgv_ad(:,:)   = zspgv_adin(:,:)
+            ub_ad  (:,:,:) = zub_adin  (:,:,:) ;  vb_ad  (:,:,:) = zvb_adin  (:,:,:)
+#  endif
+
+            CALL dyn_spg_flt_adj( istp, indic )
+
+            zua_adout(:,:,:) = ua_ad(:,:,:) 
+            zva_adout(:,:,:) = va_ad(:,:,:)
+            zub_adout(:,:,:) = ub_ad(:,:,:) 
+            zvb_adout(:,:,:) = vb_ad(:,:,:)  
+            zemp_adout (:,:) = emp_ad (:,:) 
+            zsshn_adout(:,:) = sshn_ad(:,:) 
+            zgcx_adout (:,:) = gcx_ad (:,:) 
+            zgcxb_adout(:,:) = gcxb_ad(:,:) 
+#  if defined key_obc
+            zgcb_adout (:,:) = gcb_ad (:,:) 
+#  endif
+
+            !--------------------------------------------------------------------
+            ! Compute the scalar product: dx^T L^T W dy
+            !--------------------------------------------------------------------
+
+            zsp2 =   DOT_PRODUCT( zua_tlin  , zua_adout   ) &
+               &   + DOT_PRODUCT( zva_tlin  , zva_adout   ) &
+               &   + DOT_PRODUCT( zub_tlin  , zub_adout   ) &
+               &   + DOT_PRODUCT( zvb_tlin  , zvb_adout   ) &
+               &   + DOT_PRODUCT( zgcx_tlin , zgcx_adout  ) &            
+               &   + DOT_PRODUCT( zgcxb_tlin, zgcxb_adout ) & 
+#  if defined key_obc           
+               &   + DOT_PRODUCT( zgcb_tlin , zgcb_adout  ) &            
+#  endif
+               &   + DOT_PRODUCT( zsshn_tlin, zsshn_adout ) &
+               &   + DOT_PRODUCT( zemp_tlin , zemp_adout  )
+
+            ! Compare the scalar products
+
+            !    14 char:'12345678901234'
+            IF ( istp == nit000 ) THEN
+               SELECT CASE (jpert)
+               CASE(1)
+                  cl_name = 'spg_flt  Ua T1'
+               CASE(2)
+                  cl_name = 'spg_flt  Va T1'
+               CASE(3)
+                  cl_name = 'spg_flt  Ub T1'
+               CASE(4)
+                  cl_name = 'spg_flt  Vb T1'
+               CASE(5)
+                  cl_name = 'spg_flt emp T1'
+               CASE(6)
+                  cl_name = 'spg_flt ssh T1'
+               CASE(jpertmax)
+                  cl_name = 'dyn_spg_flt T1'
+               END SELECT
+            ELSEIF ( istp == nit000 + 1 ) THEN
+               SELECT CASE (jpert)
+               CASE(1)
+                  cl_name = 'spg_flt  Ua T2'
+               CASE(2)
+                  cl_name = 'spg_flt  Va T2'
+               CASE(3)
+                  cl_name = 'spg_flt  Ub T2'
+               CASE(4)
+                  cl_name = 'spg_flt  Vb T2'
+               CASE(5)
+                  cl_name = 'spg_flt emp T2'
+               CASE(6)
+                  cl_name = 'spg_flt ssh T2'
+               CASE(jpertmax)
+                  cl_name = 'dyn_spg_flt T2'
+               END SELECT
+            END IF
+            CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+         END DO
+      END DO
+
+!nn_nmod = kmod  ! restore initial frequency of test for the SOR solver
+
+      ! Deallocate memory
+
+      DEALLOCATE( &
+         & zua_tlin,  &
+         & zva_tlin,  &
+         & zub_tlin,  &
+         & zvb_tlin,  &
+         & zua_tlout, &
+         & zva_tlout, &
+         & zua_adin,  &
+         & zva_adin,  &
+         & zua_adout, &
+         & zva_adout, &
+         & zub_adout, &
+         & zvb_adout, &
+         & znu        &
+         & )
+      DEALLOCATE( &
+         & zsshn_tlin, &
+         & zemp_tlin,  &
+         & zsshn_adout,&
+         & zemp_adout, &
+         & znssh       &
+         & )
+      DEALLOCATE( zgcx_tlin , zgcx_tlout , zgcx_adin , zgcx_adout,  &
+         & zgcxb_tlin, zgcxb_tlout, zgcxb_adin, zgcxb_adout,  &
+         & zgcb_tlin , zgcb_tlout , zgcb_adin , zgcb_adout    &
+         & )
+      DEALLOCATE ( zub_tlout, zvb_tlout, zub_adin , zvb_adin )
+#  if defined key_obc
+      DEALLOCATE( zemp_tlout, zemp_adin  ,                           &
+                  zwn_tlout , zwn_adin    )
+#  endif
+   END SUBROUTINE dyn_spg_flt_adj_tst
+
+#  if defined key_tst_tlm
+   SUBROUTINE dyn_spg_flt_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_spg_flt_tlm_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 :
+      !!        ! 09-08 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE dynspg_flt
+      USE tamtrj              ! writing out state trajectory
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE gridrandom, ONLY: &
+        & grid_rd_sd
+      USE trj_tam
+      USE oce       , ONLY: & ! ocean dynamics and tracers variables
+        & ua, va, ub, vb,   &
+        & sshn
+      USE sbc_oce   , ONLY: &
+        & emp
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt        ! Output unit
+
+      !! * Local declarations
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zua_tlin,    & ! Tangent input: ua_tl
+         & zva_tlin,    & ! Tangent input: va_tl
+         & zub_tlin,    & ! Tangent input: ub_tl
+         & zvb_tlin,    & ! 
+         & zua_out,     & !
+         & zva_out,     & ! 
+         & zua_wop,     & ! 
+         & zva_wop,     &
+         & z3r            ! 3D field
+
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zsshn_tlin, & ! Tangent input: sshn_tl
+         & zemp_tlin,  & ! Tangent input: emp_tl
+         & zsshn_out,  & ! 
+         & zsshn_wop,  &
+         & z2r           ! 2D field
+      REAL(wp) :: &
+         & zsp1, zsp1_1, zsp1_2, zsp1_3, zsp1_4,  &   ! 
+         & zsp2, zsp2_1, zsp2_2, zsp2_3, zsp2_4,  &   !
+         & zsp3, zsp3_1, zsp3_2, zsp3_3, zsp3_4,  &   !
+         & zzsp, zzsp_1, zzsp_2, zzsp_3, zzsp_4,  &
+         & gamma,                                 &
+         & zgsp1, zgsp2, zgsp3, zgsp4, zgsp5,     &
+         & zgsp6, zgsp7
+      INTEGER :: &
+         & indic, &
+         & istp
+      INTEGER :: &
+         & ji, &
+         & jj, &
+         & jk
+      CHARACTER(LEN=14)   :: cl_name
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
+      CHARACTER (LEN=90)  ::  FMT
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zscua, zscva,        &
+         & zscerrua, zscerrva,  &
+         & zscsshb, zscsshn,    &
+         & zscerrsshb, zscerrsshn
+      INTEGER, DIMENSION(100):: &
+         & iipossshb, iipossshn, iiposua, iiposva,   &
+         & ijpossshb, ijpossshn, ijposua, ijposva,   &
+         & ikposua, ikposva
+      INTEGER::             &
+         & ii,              &
+         & isamp=40,        &
+         & jsamp=40,        &
+         & ksamp=40,        &
+         & numsctlm
+     REAL(KIND=wp), DIMENSION(jpi,jpj,jpk) :: &
+         & zerrua, zerrva 
+     REAL(KIND=wp), DIMENSION(jpi,jpj) :: &
+         & zerrsshb, zerrsshn
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zua_tlin(jpi,jpj,jpk),  &
+         & zva_tlin(jpi,jpj,jpk),  &
+         & zub_tlin(jpi,jpj,jpk),  &
+         & zvb_tlin(jpi,jpj,jpk),  &
+         & zua_out( jpi,jpj,jpk),  &
+         & zva_out( jpi,jpj,jpk),  &
+         & zua_wop( jpi,jpj,jpk),  &
+         & zva_wop( jpi,jpj,jpk),  &
+         & z3r(jpi,jpj,jpk)        &
+         & )
+      ALLOCATE( &
+         & zsshn_tlin(jpi,jpj), &
+         & zemp_tlin(jpi,jpj),  &
+         & zsshn_out(jpi,jpj),  &
+         & zsshn_wop(jpi,jpj),  &
+         & z2r(jpi,jpj)         &
+         & )
+      !--------------------------------------------------------------------
+      ! Reset variables
+      !--------------------------------------------------------------------
+      zua_tlin( :,:,:) = 0.0_wp
+      zva_tlin( :,:,:) = 0.0_wp
+      zub_tlin( :,:,:) = 0.0_wp
+      zvb_tlin( :,:,:) = 0.0_wp
+      zsshn_tlin( :,:) = 0.0_wp
+      zemp_tlin(  :,:) = 0.0_wp
+      zua_out ( :,:,:) = 0.0_wp
+      zva_out ( :,:,:) = 0.0_wp
+      zsshn_out ( :,:) = 0.0_wp
+      zua_wop ( :,:,:) = 0.0_wp
+      zva_wop ( :,:,:) = 0.0_wp
+      zsshn_wop( :,:) = 0.0_wp
+
+      zscua(:)         = 0.0_wp
+      zscva(:)         = 0.0_wp
+      zscerrua(:)      = 0.0_wp
+      zscerrva(:)      = 0.0_wp
+      zerrua(:,:,:)    = 0.0_wp
+      zerrva(:,:,:)    = 0.0_wp
+      zscsshn(:)       = 0.0_wp
+      zscerrsshn(:)    = 0.0_wp
+      zerrsshn(:,:)    = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Output filename Xn=F(X0)
+      !--------------------------------------------------------------------
+!!!!      CALL tlm_namrd
+      gamma = h_ratio
+      file_wop='trj_wop_dynspg'
+      file_xdx='trj_xdx_dynspg'
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         CALL grid_rd_sd( 456953, z3r,  'U', 0.0_wp, stdu)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zua_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 3434334, z3r, 'V', 0.0_wp, stdv)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zva_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 935678, z3r,  'U', 0.0_wp, stdu)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zub_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 1462578, z3r, 'V', 0.0_wp, stdv) 
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zvb_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 25674910, z2r, 'T', 0.0_wp, stdemp)
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zemp_tlin(ji,jj) = z2r(ji,jj)
+            END DO
+         END DO
+         CALL grid_rd_sd( 12672456, z2r,'T', 0.0_wp, stdssh)
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zsshn_tlin(ji,jj) = z2r(ji,jj)
+            END DO
+         END DO
+      ENDIF    
+
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      CALL istate_p  
+      ! *** initialize the reference trajectory
+      ! ------------
+      CALL  trj_rea( nit000-1, 1 )
+      CALL  trj_rea( nit000, 1 )
+
+
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         zua_tlin(:,:,:) = gamma * zua_tlin(:,:,:)
+         ua(:,:,:)       = ua(:,:,:) + zua_tlin(:,:,:)
+
+         zva_tlin(:,:,:) = gamma * zva_tlin(:,:,:)
+         va(:,:,:)       = va(:,:,:) + zva_tlin(:,:,:)
+
+         zub_tlin(:,:,:) = gamma * zub_tlin(:,:,:)
+         ub(:,:,:)       = ub(:,:,:) + zub_tlin(:,:,:)
+
+         zvb_tlin(:,:,:) = gamma * zvb_tlin(:,:,:)
+         vb(:,:,:)       = vb(:,:,:) + zvb_tlin(:,:,:)
+
+         zemp_tlin(:,:) = gamma * zemp_tlin(:,:)
+         emp(:,:)       = emp(:,:) + zemp_tlin(:,:)
+
+         zsshn_tlin(:,:) = gamma * zsshn_tlin(:,:)
+         sshn(:,:)       = sshn(:,:) + zsshn_tlin(:,:)
+      ENDIF
+
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------
+      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 ( tlm_bch == 2 ) THEN
+         !--------------------------------------------------------------------
+         ! Initialize the tangent variables 
+         !--------------------------------------------------------------------
+         CALL  trj_rea( nit000-1, 1 ) 
+         CALL  trj_rea( nit000, 1 ) 
+         ua_tl  (:,:,:) = zua_tlin  (:,:,:)
+         va_tl  (:,:,:) = zva_tlin  (:,:,:)
+         ub_tl  (:,:,:) = zub_tlin  (:,:,:)
+         vb_tl  (:,:,:) = zvb_tlin  (:,:,:)
+         emp_tl (:,:  ) = zemp_tlin (:,:  )
+         sshn_tl(:,:  ) = zsshn_tlin(:,:  )
+
+         CALL dyn_spg_flt_tan(nit000, indic)
+         !--------------------------------------------------------------------
+         ! 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    )
+         zsp2_4    = DOT_PRODUCT( sshn_tl, sshn_tl  )
+         zsp2      = zsp2_1 + zsp2_2 + zsp2_4
+         !--------------------------------------------------------------------
+         !  Storing data
+         !--------------------------------------------------------------------
+         CALL trj_rd_spl(file_wop) 
+         zua_wop  (:,:,:) = ua  (:,:,:)
+         zva_wop  (:,:,:) = va  (:,:,:)
+         zsshn_wop(:,:) = sshn(:,:)
+         CALL trj_rd_spl(file_xdx) 
+         zua_out  (:,:,:) = ua   (:,:,:)
+         zva_out  (:,:,:) = va   (:,:,:)
+         zsshn_out(:,:  ) = sshn (:,:  )
+         !--------------------------------------------------------------------
+         ! 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 jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zua_out   (ji,jj,jk) = zua_out    (ji,jj,jk) - zua_wop  (ji,jj,jk)
+                  zua_wop   (ji,jj,jk) = zua_out    (ji,jj,jk) - ua_tl    (ji,jj,jk)
+                  IF (  ua_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrua(ji,jj,jk) = zua_out(ji,jj,jk)/ua_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposua(ii) = ji
+                      ijposua(ii) = jj
+                      ikposua(ii) = jk
+                      IF ( INT(umask(ji,jj,jk)) .NE. 0)  THEN
+                         zscua (ii) =  zua_wop(ji,jj,jk)
+                         zscerrua (ii) =  ( zerrua(ji,jj,jk) - 1.0_wp ) /gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         ii=0
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zva_out   (ji,jj,jk) = zva_out    (ji,jj,jk) - zva_wop  (ji,jj,jk)
+                  zva_wop   (ji,jj,jk) = zva_out    (ji,jj,jk) - va_tl    (ji,jj,jk)
+                  IF (  va_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrva(ji,jj,jk) = zva_out(ji,jj,jk)/va_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposva(ii) = ji
+                      ijposva(ii) = jj
+                      ikposva(ii) = jk
+                      IF ( INT(vmask(ji,jj,jk)) .NE. 0)  THEN
+                         zscva (ii) =  zua_wop(ji,jj,jk)
+                         zscerrva (ii) =  ( zerrva(ji,jj,jk) - 1.0_wp ) /gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         ii=0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zsshn_out   (ji,jj) = zsshn_out    (ji,jj) - zsshn_wop  (ji,jj)
+               zsshn_wop   (ji,jj) = zsshn_out    (ji,jj) - sshn_tl    (ji,jj)
+               IF (  sshn_tl(ji,jj) .NE. 0.0_wp ) &
+                  & zerrsshn(ji,jj) = zsshn_out(ji,jj)/sshn_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0)  ) THEN
+                   ii = ii+1
+                   iipossshn(ii) = ji
+                   ijpossshn(ii) = jj
+                   IF ( INT(tmask(ji,jj,1)) .NE. 0)  THEN
+                      zscsshn (ii) =  zsshn_wop(ji,jj)
+                      zscerrsshn (ii) =  ( zerrsshn(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_4    = DOT_PRODUCT( zsshn_out, zsshn_out  )
+         zsp1      = zsp1_1 + zsp1_2 + zsp1_4
+         zsp3_1    = DOT_PRODUCT( zua_wop,   zua_wop    )
+         zsp3_2    = DOT_PRODUCT( zva_wop,   zva_wop    )
+         zsp3_4    = DOT_PRODUCT( zsshn_wop, zsshn_wop  )
+         zsp3      = zsp3_1 + zsp3_2 + zsp3_4
+
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name  = 'dynspg_tam:En '
+         zzsp     = SQRT(zsp3)
+         zzsp_1   = SQRT(zsp3_1)
+         zzsp_2   = SQRT(zsp3_2)
+         zzsp_4   = SQRT(zsp3_4)
+         zgsp5    = zzsp
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp     = SQRT(zsp2)
+         zzsp_1   = SQRT(zsp2_1)
+         zzsp_2   = SQRT(zsp2_2)
+         zzsp_4   = SQRT(zsp2_4)
+         zgsp4    = zzsp
+         cl_name = 'dynspg_tam:Ln2'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         zzsp     = SQRT(zsp1)
+         zzsp_1   = SQRT(zsp1_1)
+         zzsp_2   = SQRT(zsp1_2)
+         zzsp_4   = SQRT(zsp1_4)
+         cl_name  = 'dynspg:Mhdx-Mx'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+
+         zgsp3    = SQRT( zsp3/zsp2 )
+         zgsp7    = zgsp3/gamma
+         zgsp1    = zzsp
+         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) 'dspgflt ', 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 = 'dspgflt '
+         IF(lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zscua(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscua     ', &
+                    & cur_loop, h_ratio, ii, iiposua(ii), ijposua(ii), zscua(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscva(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscva     ', &
+                    & cur_loop, h_ratio, ii, iiposva(ii), ijposva(ii), zscva(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscsshn(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscsshn   ', &
+                    & cur_loop, h_ratio, ii, iipossshn(ii), ijpossshn(ii), zscsshn(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrua(ii) .NE. 0.0_wp ) WRITE(numsctlm,FMT) cl_name, 'zscerrua  ', &
+                    & cur_loop, h_ratio, ii, iiposua(ii), ijposua(ii), zscerrua(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrva(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrva  ', &
+                    & cur_loop, h_ratio, ii, iiposva(ii), ijposva(ii), zscerrva(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrsshn(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrsshn  ', &
+                    & cur_loop, h_ratio, ii, iipossshn(ii), ijpossshn(ii), zscerrsshn(ii)
+            ENDDO
+            ! write separator
+            WRITE(numtan_sc,"(A4)") '===='
+         ENDIF
+      ENDIF
+
+      DEALLOCATE(                   &
+         & zemp_tlin, zsshn_tlin,   &
+         & zua_tlin, zva_tlin,      &
+         & zua_out, zva_out,        & 
+         & zua_wop, zva_wop,        &
+         & zsshn_out, zsshn_wop,    &
+         & z3r, z2r                 &
+         & )
+   END SUBROUTINE dyn_spg_flt_tlm_tst
+#  endif
+# else
+   !!----------------------------------------------------------------------
+   !!   Default case :   Empty module   No standart explicit free surface 
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dyn_spg_flt_tan( kt, kindic )       ! Empty routine
+      WRITE(*,*) 'dyn_spg_flt: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_spg_flt_tan
+   SUBROUTINE dyn_spg_flt_adj( kt, kindic )       ! Empty routine
+      WRITE(*,*) 'dyn_spg_flt: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_spg_flt_adj
+   SUBROUTINE dyn_spg_flt_adj_tst( kt )       ! Empty routine
+      WRITE(*,*) 'dyn_spg_flt: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_spg_flt_adj_tst
+   SUBROUTINE dyn_spg_flt_tlm_tst( kt )       ! Empty routine
+      WRITE(*,*) 'dyn_spg_flt: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_spg_flt_tlm_tst
+# endif
+#endif
+END MODULE dynspg_flt_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynspg_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynspg_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynspg_tam.F90	(revision 2578)
@@ -0,0 +1,308 @@
+MODULE dynspg_tam
+   !!----------------------------------------------------------------------
+   !!    This software is governed by the CeCILL licence (Version 2)
+   !!----------------------------------------------------------------------
+#if defined key_tam
+   !!======================================================================
+   !!                       ***  MODULE  dynspg_tam  ***
+   !! Ocean dynamics:  surface pressure gradient control
+   !!                  Tangent and Adjoint Module
+   !!======================================================================
+   !! History of the direct module:
+   !!            1.0  ! 2005-12  (C. Talandier, G. Madec, V. Garnier)  Original code
+   !!            3.2  ! 2009-07  (R. Benshila)  Suppression of rigid-lid option
+   !! History of the T&A module:
+   !!            9.0  ! 2008-06  (A. Vidard) Skeleton
+   !!                 ! 2008-11  (A. Vidard) nemo v3
+   !!                 ! 2009-03  (A. Weaver) dynspg_flt_tam
+   !!            3.2  ! 2010-04  (F. Vigilant) modification for 3.2
+   !!----------------------------------------------------------------------
+   !!   dyn_spg_tan     : update the dynamics trend with the surface pressure
+   !!                     gradient (tangent routine)
+   !!   dyn_spg_adj     : update the dynamics trend with the surface pressure
+   !!                     gradient (adjoint routine)
+   !!   dyn_spg_adj_tst : Test of the adjoint routine
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & lk_esopa
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & n_cla
+#if defined key_obc
+   USE obc_oce       , ONLY: & ! ocean open boundary conditions
+      & ln_vol_cst, &
+      & ln_obc_fla
+#endif
+   USE dynspg_oce    , ONLY: & ! surface pressure gradient variables
+      & lk_dynspg_flt,       &
+      & lk_dynspg_ts,        &
+      & lk_dynspg_exp
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              & 
+      & nit000,              &
+      & nitend,              &
+      & ctl_stop
+
+   USE dynspg_exp_tam ! surface pressure gradient     (dyn_spg_exp routine)
+!   USE dynspg_ts_tam  ! surface pressure gradient     (dyn_spg_ts  routine)
+   USE dynspg_flt_tam  ! surface pressure gradient     (dyn_spg_flt routine)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   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
+#if defined key_tst_tlm
+   PUBLIC dyn_spg_tlm_tst
+#endif 
+
+   !! * module variables
+   INTEGER ::   nspg = 0   ! type of surface pressure gradient scheme defined from lk_dynspg_... 
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE dyn_spg_tan( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_spg_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!              achieve the momentum time stepping by computing the
+      !!              last trend, the surface pressure gradient, and performing
+      !!              the Leap-Frog integration.
+      !!gm              In the current version only the filtered solution provide
+      !!gm            the after velocity, in the 2 other (ua,va) are still the trends
+      !!
+      !! ** Method  :   Three schemes:
+      !!              - explicit computation      : the spg is evaluated at now
+      !!              - filtered computation      : the Roulet & madec (2000) technique is used
+      !!              - split-explicit computation: a time splitting technique is used
+      !!
+      !! N.B. : When key_esopa is used all the scheme are tested, regardless 
+      !!        of the physical meaning of the results. 
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( IN  ) :: &
+         & kt      ! ocean time-step index
+      INTEGER, INTENT( OUT ) :: &
+         & kindic  ! solver flag
+      !!----------------------------------------------------------------------
+
+!!gm NOTA BENE : the dynspg_exp and dynspg_ts should be modified so that 
+!!gm             they return the after velocity, not the trends (as in trazdf_imp...)
+!!gm             In this case, change/simplify dynnxt
+
+      IF( kt == nit000 )   CALL dyn_spg_ctl_tam  ! initialisation & control of options
+
+      SELECT CASE ( nspg )                       ! compute surf. pressure gradient 
+                                                 ! trend and add it to the general trend
+      CASE (  0 )  
+         CALL dyn_spg_exp_tan( kt )              ! explicit
+      CASE (  1 )   
+         CALL ctl_stop ( 'dyn_spg_ts_tan not available yet' )
+!!!      CALL dyn_spg_ts_tan ( kt )              ! time-splitting
+      CASE (  2 )  
+         CALL dyn_spg_flt_tan( kt, kindic )      ! filtered
+      !
+      END SELECT
+      !                    
+   END SUBROUTINE dyn_spg_tan
+
+   SUBROUTINE dyn_spg_adj( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_spg_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!            compute the lateral ocean dynamics physics.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( IN  ) :: &
+         & kt      ! ocean time-step index
+      INTEGER, INTENT( OUT ) :: &
+         & kindic  ! solver flag
+      !!----------------------------------------------------------------------
+
+      kindic = 0
+!!gm NOTA BENE : the dynspg_exp and dynspg_ts should be modified so that 
+!!gm             they return the after velocity, not the trends (as in trazdf_imp...)
+!!gm             In this case, change/simplify dynnxt
+
+      IF( kt == nitend )   CALL dyn_spg_ctl_tam  ! initialisation & control of options
+
+      SELECT CASE ( nspg )                       ! compute surf. pressure gradient 
+                                                 ! trend and add it to the general trend
+      CASE (  0 )  
+         CALL dyn_spg_exp_adj( kt )              ! explicit
+      CASE (  1 )   
+         CALL ctl_stop ( 'dyn_spg_ts_adj not available yet' )
+!!!      CALL dyn_spg_ts_adj ( kt )              ! time-splitting
+      CASE (  2 )  
+         CALL dyn_spg_flt_adj( kt, kindic )      ! filtered
+      !
+      END SELECT
+      !
+   END SUBROUTINE dyn_spg_adj
+
+   SUBROUTINE dyn_spg_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_spg_flt_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Call the appropriate test routine depending on the
+      !!              choice of free surface.
+      !!                
+      !! History :
+      !!        ! 09-01 (A. Weaver)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt        ! Output unit
+
+      CALL dyn_spg_ctl_tam                        ! initialisation & control of options
+
+      SELECT CASE ( nspg )                      
+      CASE (  0 )  
+         CALL dyn_spg_exp_adj_tst( kumadt )      ! explicit
+      CASE (  1 )   
+         CALL ctl_stop ( 'dyn_spg_ts_adj_tst not available yet' )
+!!!      CALL dyn_spg_ts_adj_tst ( kumadt )      ! time-splitting
+      CASE (  2 )  
+         CALL dyn_spg_flt_adj_tst( kumadt )      ! filtered
+      !
+      END SELECT
+      !                    
+   END SUBROUTINE dyn_spg_adj_tst
+
+   SUBROUTINE dyn_spg_ctl_tam
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_spg_ctl_tam  ***
+      !!                
+      !! ** Purpose :  Control the consistency between cpp options for 
+      !!               surface pressure gradient schemes
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER :: &
+        & ioptio
+
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN             ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'dyn_spg_ctl_tam : choice of the surface pressure gradient scheme'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '     Explicit free surface                  lk_dynspg_exp = ', lk_dynspg_exp
+         WRITE(numout,*) '     Free surface with time splitting       lk_dynspg_ts  = ', lk_dynspg_ts
+         WRITE(numout,*) '     Filtered free surface cst volume       lk_dynspg_flt = ', lk_dynspg_flt
+      ENDIF
+
+      ! Control of surface pressure gradient scheme options
+      ! ---------------------------------------------------
+      ioptio = 0
+      IF(lk_dynspg_exp)   ioptio = ioptio + 1
+      IF(lk_dynspg_ts )   ioptio = ioptio + 1
+      IF(lk_dynspg_flt)   ioptio = ioptio + 1
+
+      IF( ( ioptio > 1 .AND. .NOT. lk_esopa ) .OR. ioptio == 0 )   &
+           &   CALL ctl_stop( ' Choose only one surface pressure gradient scheme with a key cpp' )
+
+      IF( lk_esopa     )   nspg = -1
+      IF( lk_dynspg_exp)   nspg =  0
+      IF( lk_dynspg_ts )   nspg =  1
+      IF( lk_dynspg_flt)   nspg =  2
+
+      IF( lk_esopa     )   nspg = -1
+
+     IF(lwp) THEN
+         WRITE(numout,*)
+         IF( nspg == -1 )   WRITE(numout,*) '     ESOPA test All scheme used'
+         IF( nspg ==  0 )   WRITE(numout,*) '     explicit free surface'
+         IF( nspg ==  1 )   WRITE(numout,*) '     free surface with time splitting scheme'
+         IF( nspg ==  2 )   WRITE(numout,*) '     filtered free surface'
+      ENDIF
+
+      ! Control of timestep choice
+      ! --------------------------
+      IF( lk_dynspg_ts .OR. lk_dynspg_exp) THEN
+         IF( n_cla == 1 )   &
+           &   CALL ctl_stop( ' Crossland advection not implemented for this free surface formulation ' )
+      ENDIF
+
+#if defined key_obc
+      ! Conservation of ocean volume (key_dynspg_flt)
+      ! ---------------------------------------------
+      IF( lk_dynspg_flt ) ln_vol_cst = .true.
+
+      ! Application of Flather's algorithm at open boundaries
+      ! -----------------------------------------------------
+      IF( lk_dynspg_flt ) ln_obc_fla = .false.
+      IF( lk_dynspg_exp ) ln_obc_fla = .true.
+      IF( lk_dynspg_ts  ) ln_obc_fla = .true.
+#endif
+
+   END SUBROUTINE dyn_spg_ctl_tam
+#if defined key_tst_tlm
+   SUBROUTINE dyn_spg_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_spg_tlm_tst ***
+      !!
+      !! ** Purpose : Test the tangent linear routine.
+      !!
+      !! ** Method  : Verify the relative error Er of the linear model  
+      !!           
+      !!              Er = 100  norm( En ) / norm( L(t0,tn) gamma dx0 )
+      !!                                              --> zero when gamma --> zero
+      !!
+      !!              where  En   = Nn( gamma dx0 ) - L(t0, tn ) gamma dx0
+      !!                     L  =   Linear routine
+      !!                     Nn   = Perturbation evolution ( M( x0 + gamma dx0 ) - M( x0 ) )
+      !!                     gamma dx0  = input perturbation (random field)
+      !!                   
+      !! History :
+      !!        ! 09-06 (F. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt        ! Output unit
+
+      CALL dyn_spg_ctl_tam                        ! initialisation & control of options
+
+      SELECT CASE ( nspg )                      
+      CASE (  0 )  
+         CALL ctl_stop ( 'dyn_spg_exp_adj_tst not available yet' )
+      CALL dyn_spg_exp_adj_tst( kumadt )      ! explicit
+      CASE (  1 )   
+         CALL ctl_stop ( 'dyn_spg_ts_adj_tst not available yet' )
+!!!      CALL dyn_spg_ts_adj_tst ( kumadt )      ! time-splitting
+      CASE (  2 )  
+         CALL dyn_spg_flt_tlm_tst( kumadt )      ! filtered
+      !
+      END SELECT
+      !                    
+   END SUBROUTINE dyn_spg_tlm_tst
+
+  !!======================================================================
+#endif
+#endif
+END MODULE dynspg_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynvor_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynvor_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynvor_tam.F90	(revision 2578)
@@ -0,0 +1,1365 @@
+MODULE dynvor_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  dynvor_tam  ***
+   !! Ocean dynamics: Update the momentum trend with the relative and
+   !!                 planetary vorticity trends
+   !!                 Tangent and Adjoint Module
+   !!======================================================================
+   !! History of the drect module:
+   !! History :  OPA  !  1989-12  (P. Andrich)  vor_ens: Original code
+   !!            5.0  !  1991-11  (G. Madec) vor_ene, vor_mix: Original code
+   !!            6.0  !  1996-01  (G. Madec)  s-coord, suppress work arrays
+   !!            8.5  !  2002-08  (G. Madec)  F90: Free form and module
+   !!   NEMO     1.0  !  2004-02  (G. Madec)  vor_een: Original code
+   !!             -   !  2003-08  (G. Madec)  add vor_ctl
+   !!             -   !  2005-11  (G. Madec)  add dyn_vor (new step architecture)
+   !!            2.0  !  2006-11  (G. Madec)  flux form advection: add metric term
+   !!            3.2  !  2009-04  (R. Benshila)  vvl: correction of een scheme
+   !! History of the TAM module:
+   !!            9.0  ! 2008-06  (A. Vidard) Skeleton
+   !!            9.0  ! 2009-01  (A. Vidard) TAM of the 06-11 version
+   !!            9.0  ! 2010-01  (F. Vigilant) Add een TAM option
+   !!  NEMO      3.2  ! 2010-04 (F. Vigilant) 3.2 version     
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_vor     : Update the momentum trend with the vorticity trend
+   !!       vor_ens : enstrophy conserving scheme       (ln_dynvor_ens=T)
+   !!       vor_ene : energy conserving scheme          (ln_dynvor_ene=T)
+   !!       vor_mix : mixed enstrophy/energy conserving (ln_dynvor_mix=T)
+   !!       vor_een : energy and enstrophy conserving   (ln_dynvor_een=T)
+   !!       vor_ctl : set and control of the different vorticity option
+   !!----------------------------------------------------------------------
+   USE par_kind,       ONLY: & ! Precision variables
+      & wp
+   USE par_oce,        ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 & 
+      & jpim1,               &
+      & jpjm1,               & 
+      & jpkm1,               & 
+      & jpiglo
+   USE oce           , ONLY: & ! ocean dynamics and tracers
+      & un,                  &
+      & vn,                  &
+      & rotn
+   USE oce_tam       , ONLY: &
+      & un_tl,         &
+      & vn_tl,         &
+      & ua_tl,         &
+      & va_tl,         &
+      & rotn_tl,       &
+      & un_ad,         &
+      & vn_ad,         &
+      & ua_ad,         &
+      & va_ad,         &
+      & rotn_ad
+   USE divcur        , ONLY: &
+      & div_cur
+   USE divcur_tam    , ONLY: &
+      & div_cur_tan
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & ln_sco,              &
+      & ff,                  &
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3t,                 &
+      & e3u,                 &
+      & e3v,                 &
+      & e3f,                 &
+#endif
+      & e1f,                 &
+      & e2f,                 &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      & lk_vvl,              &
+      & umask,               &
+      & vmask,               &
+      & tmask
+   USE dynadv        , ONLY: &
+      & ln_dynadv_vec ! vector form flag
+   USE lbclnk        , ONLY: & ! Lateral boundary conditions
+      & lbc_lnk
+   USE lbclnk_tam    , ONLY: & ! Lateral boundary conditions
+      & lbc_lnk_adj
+   USE in_out_manager, ONLY: & ! I/O manager
+      & ctl_stop,            &
+      & lk_esopa,            &
+      & numnam,              &
+      & numout,              &
+      & nit000,              &
+      & nitend,              &
+      & lwp
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          & !
+                               ! random field standard deviation for:
+      & stdu,                & !   u-velocity
+      & stdv                   !   v-velocity
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_vor_tan     ! routine called by step_tam.F90
+   PUBLIC   dyn_vor_adj     ! routine called by step_tam.F90
+   PUBLIC   dyn_vor_adj_tst ! routine called by the tst.F90
+
+
+   !!* Namelist nam_dynvor: vorticity term
+   LOGICAL, PUBLIC ::   ln_dynvor_ene = .FALSE.   !: energy conserving scheme
+   LOGICAL, PUBLIC ::   ln_dynvor_ens = .TRUE.    !: enstrophy conserving scheme
+   LOGICAL, PUBLIC ::   ln_dynvor_mix = .FALSE.   !: mixed scheme
+   LOGICAL, PUBLIC ::   ln_dynvor_een = .FALSE.   !: energy and enstrophy conserving scheme
+
+   INTEGER ::   nvor = 0   ! type of vorticity trend used
+   INTEGER ::   ncor = 1   ! coriolis
+   INTEGER ::   nrvm = 2   ! =2 relative vorticity ; =3 metric term
+   INTEGER ::   ntot = 4   ! =4 total vorticity (relative + planetary) ; =5 coriolis + metric term
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE dyn_vor_tan( kt )
+      !!----------------------------------------------------------------------
+      !!
+      !! ** Purpose of the direct routine:
+      !!               compute the lateral ocean tracer physics.
+      !!
+      !! ** 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')
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!----------------------------------------------------------------------
+      IF( kt == nit000 )   CALL vor_ctl_tam          ! initialisation & control of options
+
+      !                                          ! vorticity term 
+      SELECT CASE ( nvor )                       ! compute the vorticity trend and add it to the general trend
+      !
+      CASE ( -1 )                                      ! esopa: test all possibility with control print
+!         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 )
+         !
+      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
+         !
+      CASE ( 1 )                                       ! enstrophy conserving scheme
+         CALL vor_ens_tan( kt, ntot, ua_tl, va_tl )                ! total vorticity
+         !
+      CASE ( 2 )                                       ! mixed ene-ens scheme
+         CALL ctl_stop ('vor_mix_tan not available yet')
+!         CALL vor_mix_tan( kt )                               ! total vorticity (mix=ens-ene)
+         !
+      CASE ( 3 )                                       ! energy and enstrophy conserving scheme
+         CALL vor_een_tan( kt, ntot, ua_tl, va_tl )                ! total vorticity
+         !
+      END SELECT
+
+   END SUBROUTINE dyn_vor_tan
+   SUBROUTINE vor_ens_tan( kt, kvor, pua_tl, pva_tl )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE vor_ens_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Compute the now total vorticity trend and add it to
+      !!      the general trend of the momentum equation.
+      !!
+      !! ** Method of the direct routine:
+      !!      Trend evaluated using now fields (centered in time)
+      !!      and the Sadourny (1975) flux FORM formulation : conserves the
+      !!      potential enstrophy of a horizontally non-divergent flow. the
+      !!      trend of the vorticity term is given by:
+      !!       * s-coordinate (ln_sco=T), the e3. are inside the derivative:
+      !!          voru = 1/e1u  mj-1[ (rotn+f)/e3f ]  mj-1[ mi(e1v*e3v vn) ]
+      !!          vorv = 1/e2v  mi-1[ (rotn+f)/e3f ]  mi-1[ mj(e2u*e3u un) ]
+      !!       * z-coordinate (default key), e3t=e3u=e3v, the trend becomes:
+      !!          voru = 1/e1u  mj-1[ rotn+f ]  mj-1[ mi(e1v vn) ]
+      !!          vorv = 1/e2v  mi-1[ rotn+f ]  mi-1[ mj(e2u un) ]
+      !!      Add this trend to the general momentum trend (ua,va):
+      !!          (ua,va) = (ua,va) + ( voru , vorv )
+      !!
+      !! ** Action : - Update (ua,va) arrays 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) ::   zfact1, zuav, zvau   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz         ! temporary 3D workspace
+      REAL(wp) ::   zuavtl, zvautl   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwxtl, zwytl, zwztl   ! temporary 3D workspace
+      !!----------------------------------------------------------------------
+      
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_vor_ens_tan : vorticity term: enstrophy conserving scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
+      ENDIF
+
+      ! Local constant initialization
+      zfact1 = 0.5 * 0.25
+
+!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
+            DO jj = 1, jpj                      ! caution: don't use (:,:) for this loop 
+               DO ji = 1, jpi                   ! it causes optimization problems on NEC in auto-tasking
+                  zwz(ji,jj) = zwz(ji,jj) / fse3f(ji,jj,jk)
+                  zwx(ji,jj) = e2u(ji,jj) * fse3u(ji,jj,jk) * un(ji,jj,jk)
+                  zwy(ji,jj) = e1v(ji,jj) * fse3v(ji,jj,jk) * vn(ji,jj,jk)
+               END DO
+            END DO
+         ELSE
+            DO jj = 1, jpj                      ! caution: don't use (:,:) for this loop 
+               DO ji = 1, jpi                   ! it causes optimization problems on NEC in auto-tasking
+                  zwx(ji,jj) = e2u(ji,jj) * un(ji,jj,jk)
+                  zwy(ji,jj) = e1v(ji,jj) * vn(ji,jj,jk)
+               END DO
+            END DO
+         ENDIF
+
+         ! Compute and add the vorticity term trend
+         ! ----------------------------------------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zuav = zfact1 / e1u(ji,jj) * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1)   &
+                  &                         + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) )
+               zvau =-zfact1 / e2v(ji,jj) * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1)   &
+                  &                         + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) )
+            END DO  
+         END DO  
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+!CDIR PARALLEL DO PRIVATE( zwxtl, zwytl, zwztl )
+      ! ===================
+      ! Tangent counterpart
+      ! ===================
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Potential vorticity and horizontal fluxes
+         ! -----------------------------------------
+         SELECT CASE( kvor )      ! vorticity considered
+         CASE ( 1 )   ;   zwztl(:,:) =  0.0_wp      ! planetary vorticity (Coriolis)
+         CASE ( 2 ,4)   ;   zwztl(:,:) =   rotn_tl(:,:,jk)                ! relative  vorticity
+         CASE ( 3 ,5 )                                                ! 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
+         END SELECT
+
+         IF( ln_sco ) THEN
+            DO jj = 1, jpj                      ! caution: don't use (:,:) for this loop 
+               DO ji = 1, jpi                   ! it causes optimization problems on NEC in auto-tasking
+                  zwztl(ji,jj) = zwztl(ji,jj) / fse3f(ji,jj,jk)
+                  zwxtl(ji,jj) = e2u(ji,jj) * fse3u(ji,jj,jk) * un_tl(ji,jj,jk)
+                  zwytl(ji,jj) = e1v(ji,jj) * fse3v(ji,jj,jk) * vn_tl(ji,jj,jk)
+               END DO
+            END DO
+         ELSE
+            DO jj = 1, jpj                      ! caution: don't use (:,:) for this loop 
+               DO ji = 1, jpi                   ! it causes optimization problems on NEC in auto-tasking
+                  zwxtl(ji,jj) = e2u(ji,jj) * un_tl(ji,jj,jk)
+                  zwytl(ji,jj) = e1v(ji,jj) * vn_tl(ji,jj,jk)
+               END DO
+            END DO
+         ENDIF
+
+         ! Compute and add the vorticity term trend
+         ! ----------------------------------------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zuavtl = zfact1 / e1u(ji,jj) * ( zwytl(ji  ,jj-1) + zwytl(ji+1,jj-1)   &
+                  &                         + zwytl(ji  ,jj  ) + zwytl(ji+1,jj  ) )
+               zvautl =-zfact1 / e2v(ji,jj) * ( zwxtl(ji-1,jj  ) + zwxtl(ji-1,jj+1)   &
+                  &                         + zwxtl(ji  ,jj  ) + zwxtl(ji  ,jj+1) )
+               pua_tl(ji,jj,jk) = pua_tl(ji,jj,jk)                   &
+                  &     + zuavtl * ( zwz(  ji,jj-1) + zwz(  ji,jj) ) &
+                  &     + zuav   * ( zwztl(ji,jj-1) + zwztl(ji,jj) )
+               pva_tl(ji,jj,jk) = pva_tl(ji,jj,jk)                   &
+                  &     + zvautl * ( zwz(  ji-1,jj) + zwz(  ji,jj) ) &
+                  &     + zvau   * ( zwztl(ji-1,jj) + zwztl(ji,jj) )
+            END DO  
+         END DO  
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   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 (1980) flux form formulation : conserves 
+      !!      both the horizontal kinetic energy and the potential enstrophy
+      !!      when horizontal divergence is zero (see the NEMO documentation)
+      !!      Add this trend to the general momentum trend (ua,va).
+      !!
+      !! ** 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
+#if defined key_vvl
+      REAL(wp), DIMENSION(jpi,jpj,jpk)       ::   ze3f
+#else
+      REAL(wp), DIMENSION(jpi,jpj,jpk), SAVE ::   ze3f
+#endif
+      !!----------------------------------------------------------------------
+
+      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,*) '~~~~~~~~~~~'
+      ENDIF
+
+      IF( kt == nit000 .OR. lk_vvl ) THEN      ! reciprocal of e3 at F-point (masked averaging of e3t)
+         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
+
+      zfac12 = 1.0_wp / 12.0_wp      ! Local constant initialization
+
+      
+!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
+            CALL lbc_lnk( zwz, 'F', 1._wp )
+            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
+            CALL lbc_lnk( zwztl, 'F', 1._wp )
+         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
+            CALL lbc_lnk( zwz, 'F', 1._wp )
+            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
+            CALL lbc_lnk( zwztl, 'F', 1._wp )
+         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 )
+      !!----------------------------------------------------------------------
+      !!
+      !! ** Purpose of the direct routine:
+      !!               compute the lateral ocean tracer physics.
+      !!
+      !! ** 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')
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitend )   CALL vor_ctl_tam          ! initialisation & control of options
+
+      !                                          ! vorticity term 
+      SELECT CASE ( nvor )                       ! compute the vorticity trend and add it to the general trend
+      !
+      CASE ( -1 )                                      ! esopa: test all possibility with control print
+         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 )
+!         CALL vor_ene_adj( kt, ntot, ua_ad, va_ad )
+         !
+      CASE ( 0 )                                       ! energy conserving scheme
+         CALL ctl_stop ('vor_ene_adj not available yet')
+!         CALL vor_ene_adj( kt, ntot, ua_ad, va_ad )                ! total vorticity
+         !
+      CASE ( 1 )                                       ! enstrophy conserving scheme
+         CALL vor_ens_adj( kt, ntot, ua_ad, va_ad )                ! total vorticity
+         !
+      CASE ( 2 )                                       ! mixed ene-ens scheme
+         CALL ctl_stop ('vor_mix_adj not available yet')
+!         CALL vor_mix_adj( kt )                               ! total vorticity (mix=ens-ene)
+         !
+      CASE ( 3 )                                       ! energy and enstrophy conserving scheme
+         CALL vor_een_adj( kt, ntot, ua_ad, va_ad )                ! total vorticity
+         !
+      END SELECT
+   END SUBROUTINE dyn_vor_adj
+   SUBROUTINE vor_ens_adj( kt, kvor, pua_ad, pva_ad )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE vor_ens_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Compute the now total vorticity trend and add it to
+      !!      the general trend of the momentum equation.
+      !!
+      !! ** Method of the direct routine:
+      !!      Trend evaluated using now fields (centered in time)
+      !!      and the Sadourny (1975) flux FORM formulation : conserves the
+      !!      potential enstrophy of a horizontally non-divergent flow. the
+      !!      trend of the vorticity term is given by:
+      !!       * s-coordinate (ln_sco=T), the e3. are inside the derivative:
+      !!          voru = 1/e1u  mj-1[ (rotn+f)/e3f ]  mj-1[ mi(e1v*e3v vn) ]
+      !!          vorv = 1/e2v  mi-1[ (rotn+f)/e3f ]  mi-1[ mj(e2u*e3u un) ]
+      !!       * z-coordinate (default key), e3t=e3u=e3v, the trend becomes:
+      !!          voru = 1/e1u  mj-1[ rotn+f ]  mj-1[ mi(e1v vn) ]
+      !!          vorv = 1/e2v  mi-1[ rotn+f ]  mi-1[ mj(e2u un) ]
+      !!      Add this trend to the general momentum trend (ua,va):
+      !!          (ua,va) = (ua,va) + ( voru , vorv )
+      !!
+      !! ** Action : - Update (ua,va) arrays 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_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) ::   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
+      !!----------------------------------------------------------------------
+      
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_vor_ens_adj : vorticity term: enstrophy conserving scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
+      ENDIF
+
+      ! Local constant initialization
+      zfact1 = 0.5 * 0.25
+
+!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
+            DO jj = 1, jpj                      ! caution: don't use (:,:) for this loop 
+               DO ji = 1, jpi                   ! it causes optimization problems on NEC in auto-tasking
+                  zwz(ji,jj) = zwz(ji,jj) / fse3f(ji,jj,jk)
+                  zwx(ji,jj) = e2u(ji,jj) * fse3u(ji,jj,jk) * un(ji,jj,jk)
+                  zwy(ji,jj) = e1v(ji,jj) * fse3v(ji,jj,jk) * vn(ji,jj,jk)
+               END DO
+            END DO
+         ELSE
+            DO jj = 1, jpj                      ! caution: don't use (:,:) for this loop 
+               DO ji = 1, jpi                   ! it causes optimization problems on NEC in auto-tasking
+                  zwx(ji,jj) = e2u(ji,jj) * un(ji,jj,jk)
+                  zwy(ji,jj) = e1v(ji,jj) * vn(ji,jj,jk)
+               END DO
+            END DO
+         ENDIF
+
+         ! Compute and add the vorticity term trend
+         ! ----------------------------------------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zuav = zfact1 / e1u(ji,jj) * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1)   &
+                  &                         + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) )
+               zvau =-zfact1 / e2v(ji,jj) * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1)   &
+                  &                         + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) )
+            END DO  
+         END DO  
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+!CDIR PARALLEL DO PRIVATE( zwxad, zwyad, zwzad )
+      ! ===================
+      ! Adjoint counterpart
+      ! ===================
+      zuavad     = 0.0_wp
+      zvauad     = 0.0_wp
+      zwxad(:,:) = 0.0_wp
+      zwyad(:,:) = 0.0_wp
+      zwzad(:,:) = 0.0_wp
+      !                                                ! ===============
+      DO jk = jpkm1, 1, -1                             ! Horizontal slab
+         !                                             ! ===============
+         ! Compute and add the vorticity term trend
+         ! ----------------------------------------
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+               zvauad = zvauad + pva_ad(ji,jj,jk) * ( zwz(ji-1,jj) + zwz(ji,jj) )
+               zwzad(ji-1,jj) = zwzad(ji-1,jj) + pva_ad(ji,jj,jk) * zvau
+               zwzad(ji  ,jj) = zwzad(ji  ,jj) + pva_ad(ji,jj,jk) * zvau
+
+               zuavad = zuavad + pua_ad(ji,jj,jk) * ( zwz(ji,jj-1) + zwz(ji,jj) ) 
+               zwzad(ji,jj-1) = zwzad(ji,jj-1) + pua_ad(ji,jj,jk) * zuav
+               zwzad(ji,jj  ) = zwzad(ji,jj  ) + pua_ad(ji,jj,jk) * zuav
+               
+               zwxad(ji-1,jj  ) = zwxad(ji-1,jj  ) - zvauad * zfact1 / e2v(ji,jj)
+               zwxad(ji-1,jj+1) = zwxad(ji-1,jj+1) - zvauad * zfact1 / e2v(ji,jj)
+               zwxad(ji  ,jj  ) = zwxad(ji  ,jj  ) - zvauad * zfact1 / e2v(ji,jj)
+               zwxad(ji  ,jj+1) = zwxad(ji  ,jj+1) - zvauad * zfact1 / e2v(ji,jj)
+               zvauad = 0.0_wp
+
+               zwyad(ji  ,jj-1) = zwyad(ji  ,jj-1) + zuavad * zfact1 / e1u(ji,jj)
+               zwyad(ji+1,jj-1) = zwyad(ji+1,jj-1) + zuavad * zfact1 / e1u(ji,jj)
+               zwyad(ji  ,jj  ) = zwyad(ji  ,jj  ) + zuavad * zfact1 / e1u(ji,jj)
+               zwyad(ji+1,jj  ) = zwyad(ji+1,jj  ) + zuavad * zfact1 / e1u(ji,jj)
+               zuavad = 0.0_wp
+            END DO  
+         END DO 
+         IF( ln_sco ) THEN
+            DO jj = jpj, 1, -1     ! caution: don't use (:,:) for this loop 
+               DO ji = jpi, 1, -1  ! it causes optimization problems on NEC in auto-tasking
+                  zwzad(ji,jj) = zwzad(ji,jj) / fse3f(ji,jj,jk)
+                  un_ad(ji,jj,jk) = un_ad(ji,jj,jk) + zwxad(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk)
+                  vn_ad(ji,jj,jk) = vn_ad(ji,jj,jk) + zwyad(ji,jj) * e1v(ji,jj) * fse3v(ji,jj,jk)
+                  zwxad(ji,jj) = 0.0_wp
+                  zwyad(ji,jj) = 0.0_wp
+               END DO
+            END DO
+         ELSE
+            DO jj = jpj, 1, -1    ! caution: don't use (:,:) for this loop 
+               DO ji = jpi, 1, -1 ! it causes optimization problems on NEC in auto-tasking
+                  un_ad(ji,jj,jk) = un_ad(ji,jj,jk) + e2u(ji,jj) * zwxad(ji,jj)
+                  vn_ad(ji,jj,jk) = vn_ad(ji,jj,jk) + e1v(ji,jj) * zwyad(ji,jj)
+                  zwxad(ji,jj) = 0.0_wp
+                  zwyad(ji,jj) = 0.0_wp
+               END DO
+            END DO
+         ENDIF
+         ! Potential vorticity and horizontal fluxes
+         ! -----------------------------------------
+         SELECT CASE( kvor )      ! vorticity considered
+         CASE ( 1 )                     ! planetary vorticity (Coriolis)
+            zwzad(:,:) =  0.0_wp
+         CASE ( 2 ,4)                   ! relative  vorticity
+            rotn_ad(:,:,jk) = rotn_ad(:,:,jk) + zwzad(:,:)
+            zwzad(:,:) = 0.0_wp
+         CASE ( 3 ,5 )                  ! metric term
+            DO jj = jpjm1, 1, -1
+               DO ji = fs_jpim1, 1, -1  ! vector opt.
+                  vn_ad(ji+1,jj,jk) = vn_ad(ji+1,jj,jk)                   &
+                     &  + zwzad(ji,jj) * ( e2v(ji+1,jj) - e2v(ji,jj) )    &
+                     &                 * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )
+                  vn_ad(ji  ,jj,jk) = vn_ad(ji  ,jj,jk)                   &
+                     &  + zwzad(ji,jj) * ( e2v(ji+1,jj) - e2v(ji,jj) )    &
+                     &                 * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )
+                  un_ad(ji,jj+1,jk) = un_ad(ji,jj+1,jk)                   &
+                     &  - zwzad(ji,jj) * ( e1u(ji,jj+1) - e1u(ji,jj) )    &
+                     &                 * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )
+                  un_ad(ji,jj  ,jk) = un_ad(ji,jj  ,jk)                   &
+                     &  - zwzad(ji,jj) * ( e1u(ji,jj+1) - e1u(ji,jj) )    &
+                     &                 * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )
+                  zwzad(ji,jj) = 0.0_wp
+               END DO
+            END DO
+         END SELECT
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   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,*) '~~~~~~~~~~~'
+      ENDIF
+
+      IF( kt == nitend .OR. lk_vvl ) THEN      ! reciprocal of e3 at F-point (masked averaging of e3t)
+         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
+            CALL lbc_lnk( zwz, 'F', 1._wp )
+         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
+            CALL lbc_lnk( zwz, 'F', 1._wp )
+         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 )
+            CALL lbc_lnk_adj( zwzad, 'F', 1._wp )                                                ! 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 ) 
+            CALL lbc_lnk_adj( zwzad, 'F', 1._wp )                                               ! 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
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE vor_ctl_tam  ***
+      !!
+      !! ** Purpose :   Control the consistency between cpp options for
+      !!      tracer advection schemes
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio          ! temporary integer
+      NAMELIST/namdyn_vor/ ln_dynvor_ens, ln_dynvor_ene, ln_dynvor_mix, ln_dynvor_een
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )               ! Read Namelist namdyn_vor : Vorticity scheme options
+      READ   ( numnam, namdyn_vor )
+
+      IF(lwp) THEN                    ! Namelist print
+         WRITE(numout,*)
+         WRITE(numout,*) 'dyn:vor_ctl_tam : vorticity term : read namelist and control the consistency'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '        Namelist namdyn_vor : 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
+         WRITE(numout,*) '           mixed enstrophy/energy conserving scheme   ln_dynvor_mix = ', ln_dynvor_mix
+         WRITE(numout,*) '           enstrophy and energy conserving scheme     ln_dynvor_een = ', ln_dynvor_een
+      ENDIF
+
+      ioptio = 0                     ! Control of vorticity scheme options
+      IF( ln_dynvor_ene )   ioptio = ioptio + 1
+      IF( ln_dynvor_ens )   ioptio = ioptio + 1
+      IF( ln_dynvor_mix )   ioptio = ioptio + 1
+      IF( ln_dynvor_een )   ioptio = ioptio + 1
+      IF( lk_esopa      )   ioptio =          1
+
+      IF( ioptio /= 1 ) CALL ctl_stop( ' use ONE and ONLY one vorticity scheme' )
+
+      !                              ! Set nvor (type of scheme for vorticity)
+      IF( ln_dynvor_ene )   nvor =  0
+      IF( ln_dynvor_ens )   nvor =  1
+      IF( ln_dynvor_mix )   nvor =  2
+      IF( ln_dynvor_een )   nvor =  3
+      IF( lk_esopa      )   nvor = -1
+      
+      !                              ! Set ncor, nrvm, ntot (type of vorticity)
+      IF(lwp) WRITE(numout,*)
+      ncor = 1
+      IF( ln_dynadv_vec ) THEN     
+         IF(lwp) WRITE(numout,*) '         Vector form advection : vorticity = Coriolis + relative vorticity'
+         nrvm = 2
+         ntot = 4
+      ELSE                        
+         IF(lwp) WRITE(numout,*) '         Flux form advection   : vorticity = Coriolis + metric term'
+         nrvm = 3
+         ntot = 5
+      ENDIF
+      
+      IF(lwp) THEN                   ! Print the choice
+         WRITE(numout,*)
+         IF( nvor ==  0 )   WRITE(numout,*) '         vorticity scheme : energy conserving scheme'
+         IF( nvor ==  1 )   WRITE(numout,*) '         vorticity scheme : enstrophy conserving scheme'
+         IF( nvor ==  2 )   WRITE(numout,*) '         vorticity scheme : mixed enstrophy/energy conserving scheme'
+         IF( nvor ==  3 )   WRITE(numout,*) '         vorticity scheme : energy and enstrophy conserving scheme'
+         IF( nvor == -1 )   WRITE(numout,*) '         esopa test: use all lateral physics options'
+      ENDIF
+      !
+   END SUBROUTINE vor_ctl_tam
+
+   SUBROUTINE dyn_vor_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_adv_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Separate tests are applied for the following dx and dy:
+      !!                
+      !!              1) dx = ( SSH ) and dy = ( SSH )
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      INTEGER :: &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk,    &
+         & jt     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zun_tlin,     & ! Tangent input:  now   u-velocity
+         & zvn_tlin,     & ! Tangent input:  now   v-velocity
+         & zrotn_tlin,   & ! Tangent input:  now   rot
+         & zun_adout,    & ! Adjoint output: now   u-velocity
+         & zvn_adout,    & ! Adjoint output: now   v-velocity
+         & zrotn_adout,  & ! Adjoint output: now   rot
+         & zua_adout,    & ! Tangent output: after u-velocity
+         & zva_adout,    & ! Tangent output: after v-velocity
+         & zua_tlin,     & ! Tangent output: after u-velocity
+         & zva_tlin,     & ! Tangent output: after v-velocity
+         & zua_tlout,    & ! Tangent output: after u-velocity
+         & zva_tlout,    & ! Tangent output: after v-velocity
+         & zua_adin,     & ! Tangent output: after u-velocity
+         & zva_adin,     & ! Tangent output: after v-velocity
+         & zau,          & ! 3D random field for rotn
+         & zav,          & ! 3D random field for rotn
+         & znu,          & ! 3D random field for u
+         & znv             ! 3D random field for v
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_1,       & !   scalar product components
+         & zsp1_2,       & 
+         & zsp2,         & ! scalar product involving the adjoint routine
+         & zsp2_1,       & !   scalar product components
+         & zsp2_2,       & 
+         & zsp2_3,       & 
+         & zsp2_4,       & 
+         & zsp2_5
+      CHARACTER(LEN=14) :: cl_name
+
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zun_tlin(jpi,jpj,jpk),     & 
+         & zvn_tlin(jpi,jpj,jpk),     & 
+         & zrotn_tlin(jpi,jpj,jpk),   & 
+         & zun_adout(jpi,jpj,jpk),    & 
+         & zvn_adout(jpi,jpj,jpk),    & 
+         & zrotn_adout(jpi,jpj,jpk),  & 
+         & zua_adout(jpi,jpj,jpk),    & 
+         & zva_adout(jpi,jpj,jpk),    & 
+         & zua_tlin(jpi,jpj,jpk),     & 
+         & zva_tlin(jpi,jpj,jpk),     & 
+         & zua_tlout(jpi,jpj,jpk),    & 
+         & zva_tlout(jpi,jpj,jpk),    & 
+         & zua_adin(jpi,jpj,jpk),     & 
+         & zva_adin(jpi,jpj,jpk),     & 
+         & zau(jpi,jpj,jpk),          & 
+         & zav(jpi,jpj,jpk),          & 
+         & znu(jpi,jpj,jpk),          & 
+         & znv(jpi,jpj,jpk)           &
+         & )
+
+      ! 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 )
+      
+         !==================================================================
+         ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and 
+         !    dy = ( hdivb_tl, hdivn_tl )
+         !==================================================================
+
+         !--------------------------------------------------------------------
+         ! Reset the tangent and adjoint variables
+         !--------------------------------------------------------------------
+     
+         zun_tlin(:,:,:) = 0.0_wp      
+         zvn_tlin(:,:,:) = 0.0_wp      
+         zrotn_tlin(:,:,:) = 0.0_wp    
+         zun_adout(:,:,:) = 0.0_wp     
+         zvn_adout(:,:,:) = 0.0_wp     
+         zrotn_adout(:,:,:) = 0.0_wp   
+         zua_tlout(:,:,:) = 0.0_wp     
+         zva_tlout(:,:,:) = 0.0_wp     
+         zua_adin(:,:,:) = 0.0_wp      
+         zva_adin(:,:,:) = 0.0_wp      
+         zua_adout(:,:,:) = 0.0_wp     
+         zva_adout(:,:,:) = 0.0_wp     
+         zua_tlin(:,:,:) = 0.0_wp      
+         zva_tlin(:,:,:) = 0.0_wp      
+         znu(:,:,:) = 0.0_wp           
+         znv(:,:,:) = 0.0_wp    
+         zau(:,:,:) = 0.0_wp           
+         zav(:,:,:) = 0.0_wp    
+
+
+         un_tl(:,:,:) = 0.0_wp
+         vn_tl(:,:,:) = 0.0_wp
+         ua_tl(:,:,:) = 0.0_wp
+         va_tl(:,:,:) = 0.0_wp
+         un_ad(:,:,:) = 0.0_wp
+         vn_ad(:,:,:) = 0.0_wp
+         ua_ad(:,:,:) = 0.0_wp
+         va_ad(:,:,:) = 0.0_wp
+         rotn_tl(:,:,:) = 0.0_wp
+         rotn_ad(:,:,:) = 0.0_wp
+          
+         !--------------------------------------------------------------------
+         ! Initialize the tangent input with random noise: dx
+         !--------------------------------------------------------------------
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 596035 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, znu, 'U', 0.0_wp, stdu )
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 523432 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, znv, 'V', 0.0_wp, stdv )
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 432545 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zau, 'U', 0.0_wp, stdu )
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 287503 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zav, 'V', 0.0_wp, stdv )
+
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zun_tlin(ji,jj,jk) = znu(ji,jj,jk) 
+                  zvn_tlin(ji,jj,jk) = znv(ji,jj,jk) 
+                  zua_tlin(ji,jj,jk) = zau(ji,jj,jk) 
+                  zva_tlin(ji,jj,jk) = zav(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         un_tl(:,:,:) = zun_tlin(:,:,:)
+         vn_tl(:,:,:) = zvn_tlin(:,:,:)
+         ua_tl(:,:,:) = zua_tlin(:,:,:)
+         va_tl(:,:,:) = zva_tlin(:,:,:)
+
+         ! initialize rotn_tl with noise
+         CALL div_cur_tan ( nit000 )
+
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zrotn_tlin(ji,jj,jk) = rotn_tl(ji,jj,jk) 
+               END DO
+            END DO
+         END DO
+         rotn_tl(:,:,:) = zrotn_tlin(:,:,:)
+
+
+         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(:,:,:)
+
+         !--------------------------------------------------------------------
+         ! Initialize the adjoint variables: dy^* = W dy
+         !--------------------------------------------------------------------
+
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zua_adin(ji,jj,jk) = zua_tlout(ji,jj,jk) &
+                       &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                       &               * umask(ji,jj,jk)
+                  zva_adin(ji,jj,jk) = zva_tlout(ji,jj,jk) &
+                       &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+                       &               * vmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !--------------------------------------------------------------------
+
+         zsp1_1 = DOT_PRODUCT( zua_tlout, zua_adin )
+         zsp1_2 = DOT_PRODUCT( zva_tlout, zva_adin )
+         zsp1   = zsp1_1 + zsp1_2
+
+         !--------------------------------------------------------------------
+         ! Call the adjoint routine: dx^* = L^T dy^*
+         !--------------------------------------------------------------------
+
+         ua_ad(:,:,:) = zua_adin(:,:,:)
+         va_ad(:,:,:) = zva_adin(:,:,:)
+
+
+         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(:,:,:)
+         zrotn_adout(:,:,:) = rotn_ad(:,:,:)
+         zua_adout(:,:,:)   = ua_ad(:,:,:)
+         zva_adout(:,:,:)   = va_ad(:,:,:)
+      
+         zsp2_1 = DOT_PRODUCT( zun_tlin, zun_adout )
+         zsp2_2 = DOT_PRODUCT( zvn_tlin, zvn_adout )
+         zsp2_3 = DOT_PRODUCT( zrotn_tlin, zrotn_adout )
+         zsp2_4 = DOT_PRODUCT( zua_tlin, zua_adout )
+         zsp2_5 = DOT_PRODUCT( zva_tlin, zva_adout )
+         zsp2   = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4 + zsp2_5
+
+         ! Compare the scalar products
+
+         ! 14 char:'12345678901234'
+         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( &
+         & zun_tlin,     &
+         & zvn_tlin,     &
+         & zrotn_tlin,   &
+         & zun_adout,    &
+         & zvn_adout,    &
+         & zrotn_adout,  &
+         & zua_adout,    &
+         & zva_adout,    &
+         & zua_tlin,     &
+         & zva_tlin,     &
+         & zua_tlout,    &
+         & zva_tlout,    &
+         & zua_adin,     &
+         & zva_adin,     &
+         & zau,          &
+         & zav,          &
+         & znu,          &
+         & znv           &
+         & )
+   END SUBROUTINE dyn_vor_adj_tst
+   !!=============================================================================
+#endif
+END MODULE dynvor_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynzad_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynzad_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynzad_tam.F90	(revision 2578)
@@ -0,0 +1,253 @@
+MODULE dynzad_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  dynzad_tam  ***
+   !! Ocean dynamics : vertical advection trend 
+   !!                        Tangent and Adjoint module
+   !!======================================================================
+   !! History of the direct module:
+   !!            6.0  !  91-01  (G. Madec) Original code
+   !!            7.0  !  91-11  (G. Madec)
+   !!            7.5  !  96-01  (G. Madec) statement function for e3
+   !!            8.5  !  02-07  (G. Madec) j-k-i case: Original code
+   !!            8.5  !  02-07  (G. Madec) Free form, F90
+   !! History of the tam module:
+   !!            9.0  !  08-08  (A. Vidard) first version
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_zad_tan   : tangent of the vertical advection momentum trend
+   !!   dyn_zad_adj   : adjoint of the vertical advection momentum trend
+   !!----------------------------------------------------------------------
+   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           , ONLY: & ! ocean dynamics and tracers
+      & un,                  &
+      & vn,                  &
+      & wn
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & e1t,                 &
+      & e2t,                 &
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+#if defined key_zco
+      & e3t_0
+#else
+      & e3u,                 &
+      & e3v
+#endif
+   USE in_out_manager, ONLY: & ! I/O manager
+      & lwp,                 &
+      & numout,              &
+      & nit000,              &
+      & nitend
+   USE oce_tam       , ONLY: & ! tam ocean dynamics and tracers
+      & un_tl,               &
+      & vn_tl,               &
+      & ua_tl,               &
+      & va_tl,               &
+      & un_ad,               &
+      & vn_ad,               &
+      & ua_ad,               &
+      & va_ad,               &
+      & wn_tl,               &
+      & wn_ad
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_zad_tan   ! routine called by step_tam.F90
+   PUBLIC   dyn_zad_adj   ! routine called by step_tam.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+   SUBROUTINE dyn_zad_tan ( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dynzad_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Compute the now vertical momentum advection trend and 
+      !!      add it to the general trend of momentum equation.
+      !!
+      !! ** Method of the direct routine:
+      !!      The now vertical advection of momentum is given by:
+      !!         w dz(u) = ua + 1/(e1u*e2u*e3u) mk+1[ mi(e1t*e2t*wn) dk(un) ]
+      !!         w dz(v) = va + 1/(e1v*e2v*e3v) mk+1[ mj(e1t*e2t*wn) dk(vn) ]
+      !!      Add this trend to the general trend (ua,va):
+      !!         (ua,va) = (ua,va) + w dz(u,v)
+      !!
+      !! ** Action  : - Update (ua_tl,va_tl) with the vert. momentum advection trends
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step inedx
+      !!
+      INTEGER  ::   ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   zuatl, zvatl        ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zww                ! 2D  workspace
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zwwtl              ! 2D  workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwuwtl, zwvwtl     ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) 'dyn_zad_tan : arakawa advection scheme'
+         IF(lwp)WRITE(numout,*) '~~~~~~~~~~~'
+         CALL flush(numout)
+      ENDIF
+
+
+      DO jk = 2, jpkm1              ! Vertical momentum advection at level w and u- and v- vertical
+         DO jj = 2, jpj                   ! vertical fluxes 
+            DO ji = fs_2, jpi             ! vector opt.
+               zww(  ji,jj) = 0.25 * e1t(ji,jj) * e2t(ji,jj) * wn(   ji,jj,jk)
+               zwwtl(ji,jj) = 0.25 * e1t(ji,jj) * e2t(ji,jj) * wn_tl(ji,jj,jk)
+            END DO
+         END DO
+         DO jj = 2, jpjm1                 ! vertical momentum advection at w-point
+            DO ji = fs_2, fs_jpim1        ! vector opt.
+               zwuwtl(ji,jj,jk) = ( zwwtl(ji+1,jj  ) + zwwtl(ji,jj) ) * ( un(   ji,jj,jk-1)-un(   ji,jj,jk) ) + &
+                  &               ( zww(  ji+1,jj  ) + zww(  ji,jj) ) * ( un_tl(ji,jj,jk-1)-un_tl(ji,jj,jk) )
+               zwvwtl(ji,jj,jk) = ( zwwtl(ji  ,jj+1) + zwwtl(ji,jj) ) * ( vn(   ji,jj,jk-1)-vn(   ji,jj,jk) ) + &
+                  &               ( zww(  ji  ,jj+1) + zww(  ji,jj) ) * ( vn_tl(ji,jj,jk-1)-vn_tl(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+      DO jj = 2, jpjm1              ! Surface and bottom values set to zero
+         DO ji = fs_2, fs_jpim1           ! vector opt.
+            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
+
+      DO jk = 1, jpkm1              ! Vertical momentum advection at u- and v-points
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1       ! vector opt.
+               !                         ! vertical momentum advective trends
+               zuatl = - ( zwuwtl(ji,jj,jk) + zwuwtl(ji,jj,jk+1) ) / ( e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) )
+               zvatl = - ( zwvwtl(ji,jj,jk) + zwvwtl(ji,jj,jk+1) ) / ( e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) )
+               !                         ! add the trends to the general momentum trends
+               ua_tl(ji,jj,jk) = ua_tl(ji,jj,jk) + zuatl
+               va_tl(ji,jj,jk) = va_tl(ji,jj,jk) + zvatl
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE dyn_zad_tan
+
+   SUBROUTINE dyn_zad_adj ( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dynzad_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Compute the now vertical momentum advection trend and 
+      !!      add it to the general trend of momentum equation.
+      !!
+      !! ** Method of the direct routine:
+      !!      The now vertical advection of momentum is given by:
+      !!         w dz(u) = ua + 1/(e1u*e2u*e3u) mk+1[ mi(e1t*e2t*wn) dk(un) ]
+      !!         w dz(v) = va + 1/(e1v*e2v*e3v) mk+1[ mj(e1t*e2t*wn) dk(vn) ]
+      !!      Add this trend to the general trend (ua,va):
+      !!         (ua,va) = (ua,va) + w dz(u,v)
+      !!
+      !! ** Action  : - Update (ua_tl,va_tl) with the vert. momentum advection trends
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step inedx
+      !!
+      INTEGER  ::   ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   zuaad, zvaad        ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zww                ! 2D  workspace
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zwwad              ! 2D  workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwuwad, zwvwad     ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitend ) THEN
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) 'dyn_zad_adj : arakawa advection scheme'
+         IF(lwp)WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+      zuaad         = 0.0_wp ; zvaad         = 0.0_wp
+      zwuwad(:,:,:) = 0.0_wp ; zwvwad(:,:,:) = 0.0_wp ; zwwad(:,:)    = 0.0_wp
+
+
+      DO jk = jpkm1, 1, -1             ! Vertical momentum advection at u- and v-points
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1 ! vector opt.
+               !                       ! add the trends to the general momentum trends
+               zuaad = zuaad + ua_ad(ji,jj,jk)
+               zvaad = zvaad + va_ad(ji,jj,jk)
+               !                       ! vertical momentum advective trends
+               zwuwad(ji,jj,jk  ) = zwuwad(ji,jj,jk  ) - zuaad / ( e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) )
+               zwuwad(ji,jj,jk+1) = zwuwad(ji,jj,jk+1) - zuaad / ( e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) )
+               zuaad = 0.0_wp
+
+               zwvwad(ji,jj,jk  ) = zwvwad(ji,jj,jk  ) - zvaad / ( e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) )
+               zwvwad(ji,jj,jk+1) = zwvwad(ji,jj,jk+1) - zvaad / ( e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) )
+               zvaad = 0.0_wp
+            END DO
+         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 
+            DO ji = fs_2, jpi             ! vector opt.
+               zww(ji,jj) = 0.25 * e1t(ji,jj) * e2t(ji,jj) * wn(ji,jj,jk)
+            END DO
+         END DO
+         DO jj = jpjm1, 2, -1          ! vertical momentum advection at w-point
+            DO ji = fs_jpim1, fs_2, -1 ! vector opt.
+               zwwad(ji,jj+1) = zwwad(ji,jj+1) + zwvwad(ji,jj,jk) * ( vn(ji,jj,jk-1)-vn(ji,jj,jk) )
+               zwwad(ji,jj  ) = zwwad(ji,jj  ) + zwvwad(ji,jj,jk) * ( vn(ji,jj,jk-1)-vn(ji,jj,jk) )
+               vn_ad(ji,jj,jk-1) = vn_ad(ji,jj,jk-1) + zwvwad(ji,jj,jk) * ( zww(ji,jj+1) + zww(ji,jj) )
+               vn_ad(ji,jj,jk  ) = vn_ad(ji,jj,jk  ) - zwvwad(ji,jj,jk) * ( zww(ji,jj+1) + zww(ji,jj) )
+               zwvwad(ji,jj,jk) = 0.0_wp
+
+               zwwad(ji+1,jj) = zwwad(ji+1,jj) + zwuwad(ji,jj,jk) * ( un(ji,jj,jk-1)-un(ji,jj,jk) )
+               zwwad(ji  ,jj) = zwwad(ji  ,jj) + zwuwad(ji,jj,jk) * ( un(ji,jj,jk-1)-un(ji,jj,jk) )
+               un_ad(ji,jj,jk-1) = un_ad(ji,jj,jk-1)  + zwuwad(ji,jj,jk) * ( zww(ji+1,jj) + zww(ji,jj) )
+               un_ad(ji,jj,jk  ) = un_ad(ji,jj,jk  )  - zwuwad(ji,jj,jk) * ( zww(ji+1,jj) + zww(ji,jj) )
+               zwuwad(ji,jj,jk) = 0.0_wp
+            END DO
+         END DO
+         DO jj = jpj, 2, -1                   ! vertical fluxes 
+            DO ji = jpi, fs_2, -1             ! vector opt.
+               wn_ad(ji,jj,jk) = wn_ad(ji,jj,jk) + zwwad(ji,jj) * 0.25 * e1t(ji,jj) * e2t(ji,jj)
+               zwwad(ji,jj) = 0.0_wp
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE dyn_zad_adj
+   SUBROUTINE dyn_zad_adj_tst( kumadt )         
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      ! done in dynadv_tam
+   END SUBROUTINE dyn_zad_adj_tst
+#endif
+END MODULE dynzad_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynzdf_exp_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynzdf_exp_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynzdf_exp_tam.F90	(revision 2578)
@@ -0,0 +1,111 @@
+MODULE dynzdf_exp_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                     ***  MODULE  dynzdf_exp_tam  ***
+   !! Ocean dynamics:  vertical component(s) of the momentum mixing trend
+   !!                 Tangent and Adjoint Module
+   !!==============================================================================
+   !! History of the direct module:
+   !!                !  90-10  (B. Blanke)  Original code
+   !!                !  97-05  (G. Madec)  vertical component of isopycnal
+   !!           8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !! History of the TAM module:
+   !!           9.0  !  08-0!  (A. Vidard) Skeleton
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_zdf_exp  : update the momentum trend with the vertical diffu-
+   !!                  sion using an explicit time-stepping scheme.
+   !!----------------------------------------------------------------------
+   !! * Modules used
+
+   USE in_out_manager  ! I/O manager
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dyn_zdf_exp_tan     ! called by dynzdf_tam.F90
+   PUBLIC dyn_zdf_exp_adj     ! called by dynzdf_tam.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_zdf_exp_tan( kt, p2dt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_zdf_exp_tan  ***
+      !!                   
+      !! ** Purpose of the direct routine:
+      !!      Compute the trend due to the vert. momentum diffusion
+      !!
+      !! ** Method of the direct routine:
+      !!      Explicit forward time stepping with a time splitting
+      !!      technique. The vertical diffusion of momentum is given by:
+      !!         diffu = dz( avmu dz(u) ) = 1/e3u dk+1( avmu/e3uw dk(ub) )
+      !!      Surface boundary conditions: wind stress input
+      !!      Bottom boundary conditions : bottom stress (cf zdfbfr.F90)
+      !!      Add this trend to the general trend ua :
+      !!         ua = ua + dz( avmu dz(u) )
+      !!
+      !! ** Action : - Update (ua,va) with the vertical diffusive trend
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER , INTENT( in ) ::   kt                           ! ocean time-step index
+      REAL(wp), INTENT( in ) ::   p2dt                         ! time-step 
+
+      !! * 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
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_zdf_exp_tan : vertical momentum diffusion explicit operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~ '
+      ENDIF
+
+      CALL ctl_stop ('dyn_zdf_exp_tan not available yet')
+   END SUBROUTINE dyn_zdf_exp_tan
+   SUBROUTINE dyn_zdf_exp_adj( kt, p2dt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_zdf_exp_adj  ***
+      !!                   
+      !! ** Purpose of the direct routine:
+      !!      Compute the trend due to the vert. momentum diffusion
+      !!
+      !! ** Method of the direct routine:
+      !!      Explicit forward time stepping with a time splitting
+      !!      technique. The vertical diffusion of momentum is given by:
+      !!         diffu = dz( avmu dz(u) ) = 1/e3u dk+1( avmu/e3uw dk(ub) )
+      !!      Surface boundary conditions: wind stress input
+      !!      Bottom boundary conditions : bottom stress (cf zdfbfr.F90)
+      !!      Add this trend to the general trend ua :
+      !!         ua = ua + dz( avmu dz(u) )
+      !!
+      !! ** Action : - Update (ua,va) with the vertical diffusive trend
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER , INTENT( in ) ::   kt                           ! ocean time-step index
+      REAL(wp), INTENT( in ) ::   p2dt                         ! time-step 
+
+      !! * 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
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_zdf_exp_adj : vertical momentum diffusion explicit operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~ '
+      ENDIF
+
+      CALL ctl_stop ('dyn_zdf_exp_adj not available yet')
+   END SUBROUTINE dyn_zdf_exp_adj
+#endif
+   !!==============================================================================
+END MODULE dynzdf_exp_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynzdf_imp_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynzdf_imp_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynzdf_imp_tam.F90	(revision 2578)
@@ -0,0 +1,540 @@
+MODULE dynzdf_imp_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                     ***  MODULE  dynzdf_imp_tam  ***
+   !! Ocean dynamics:  vertical component(s) of the momentum mixing trend
+   !!                 Tangent and Adjoint Module
+   !!==============================================================================
+   !! History of the direct module:
+   !!                !  90-10  (B. Blanke)  Original code
+   !!                !  97-05  (G. Madec)  vertical component of isopycnal
+   !!           8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !! History of the TAM module:
+   !!           9.0  !  09-01  (A. Vidard) TAM of the 02-08 version
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_zdf_imp  : update the momentum trend with the vertical diffu-
+   !!                  sion using an implicit time-stepping scheme.
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   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,               &
+      & ua_tl,               &
+      & vb_tl,               &
+      & va_tl,               &
+      & ub_ad,               &
+      & ua_ad,               &
+      & vb_ad,               &
+      & va_ad
+   USE zdf_oce       , ONLY: & ! ocean vertical physics
+      & avmu,                &
+      & avmv
+   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
+ 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dyn_zdf_imp_tan     ! called by dynzdf_tam.F90
+   PUBLIC dyn_zdf_imp_adj     ! called by dynzdf_tam.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_zdf_imp_tan( kt, p2dt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_zdf_imp_tan  ***
+      !!                   
+      !! ** Purpose of the direct routine:
+      !!      Compute the trend due to the vert. momentum diffusion
+      !!      and the surface forcing, and add it to the general trend of 
+      !!      the momentum equations.
+      !!
+      !! ** Method of the direct routine:
+      !!      The vertical momentum mixing trend is given by :
+      !!             dz( avmu dz(u) ) = 1/e3u dk+1( avmu/e3uw dk(ua) )
+      !!      backward time stepping
+      !!      Surface boundary conditions: wind stress input
+      !!      Bottom boundary conditions : bottom stress (cf zdfbfr.F)
+      !!      Add this trend to the general trend ua :
+      !!         ua = ua + dz( avmu dz(u) )E
+      !!
+      !! ** Action : - Update (ua,va) arrays with the after vertical diffusive
+      !!               mixing trend.
+      !!---------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      INTEGER , INTENT( in ) ::   kt                           ! ocean time-step index
+      REAL(wp), INTENT( in ) ::   p2dt                         ! time-step 
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk                          ! dummy loop indices
+      REAL(wp) ::   zrau0r, z2dtf, zcoef, zzws, zrhstl ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk):: zwi, zws, zwd ! temporary workspace arrays
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_zdf_imp_tan : vertical momentum diffusion explicit operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~ '
+      ENDIF
+      ! 0. Local constant initialization
+      ! --------------------------------
+      zrau0r = 1. / rau0      ! inverse of the reference density
+
+      ! 1. Vertical diffusion on u
+      ! ---------------------------
+      ! Matrix and second member construction
+      ! non zero value at the ocean bottom depending on the bottom friction
+      ! used but the bottom velocities have already been updated with the bottom
+      ! friction velocity in dyn_bfr using values from the previous timestep. There
+      ! is no need to include these in the implicit calculation.
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1 
+            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  ) * 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)
+               zwd(ji,jj,jk) = 1. - zwi(ji,jj,jk) - zzws
+            END DO
+         END DO
+      END DO
+
+      ! Surface boudary conditions
+      DO jj = 2, jpjm1 
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zwi(ji,jj,1) = 0.0_wp
+            zwd(ji,jj,1) = 1. - zws(ji,jj,1)
+         END DO
+      END DO
+
+      ! Matrix inversion starting from the first level
+      !-----------------------------------------------------------------------
+      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+      !
+      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+      !        (        ...               )( ...  ) ( ...  )
+      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+      !
+      !   m is decomposed in the product of an upper and a lower triangular matrix
+      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+      !   The solution (the after velocity) is in ua
+      !-----------------------------------------------------------------------
+
+      ! First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1   (increasing k)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zwd(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwd(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1
+      DO jj = 2, jpjm1   
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ua_tl(ji,jj,1) = ub_tl(ji,jj,1)  &
+                           + p2dt * ua_tl(ji,jj,1)
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zrhstl          = ub_tl(ji,jj,jk) + p2dt * ua_tl(ji,jj,jk)   ! zrhs=right hand side
+               ua_tl(ji,jj,jk) = zrhstl - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * ua_tl(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! thrid recurrence : SOLk = ( Lk - Uk * Ek+1 ) / Dk
+      DO jj = 2, jpjm1   
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ua_tl(ji,jj,jpkm1) = ua_tl(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
+         END DO
+      END DO
+      DO jk = jpk-2, 1, -1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ua_tl(ji,jj,jk) = ( ua_tl(ji,jj,jk) - zws(ji,jj,jk) * ua_tl(ji,jj,jk+1) ) / zwd(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Normalization to obtain the general momentum trend ua
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ua_tl(ji,jj,jk) = ( ua_tl(ji,jj,jk) - ub_tl(ji,jj,jk) ) / p2dt
+            END DO
+         END DO
+      END DO
+
+
+      ! 2. Vertical diffusion on v
+      ! ---------------------------
+      ! Matrix and second member construction
+      ! bottom boundary condition: both zwi and zws must be masked as avmv can take
+      ! non zero value at the ocean bottom depending on the bottom friction
+      ! used but the bottom velocities have already been updated with the bottom
+      ! friction velocity in dyn_bfr using values from the previous timestep. There
+      ! is no need to include these in the implicit calculation.
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcoef          = -p2dt / fse3v(ji,jj,jk)
+               zwi(ji,jj,jk) = zcoef * avmv(ji,jj,jk  ) / fse3vw(ji,jj,jk  ) * vmask(ji,jj,jk)
+               zzws          = zcoef * avmv(ji,jj,jk+1) / fse3vw(ji,jj,jk+1)
+               zws(ji,jj,jk) =  zzws * vmask(ji,jj,jk+1)
+               zwd(ji,jj,jk) = 1. - zwi(ji,jj,jk) - zzws
+            END DO
+         END DO
+      END DO
+
+      ! Surface boudary conditions
+      DO jj = 2, jpjm1   
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zwi(ji,jj,1) = 0._wp
+            zwd(ji,jj,1) = 1. - zws(ji,jj,1)
+         END DO
+      END DO
+
+      ! Matrix inversion
+      !-----------------------------------------------------------------------
+      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+      !
+      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+      !        (        ...               )( ...  ) ( ...  )
+      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+      !
+      !   m is decomposed in the product of an upper and lower triangular
+      !   matrix
+      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+      !   The solution (after velocity) is in 2d array va
+      !-----------------------------------------------------------------------
+
+      ! First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1   (increasing k)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zwd(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwd(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            va_tl(ji,jj,1) = vb_tl(ji,jj,1)  &
+                           + p2dt * va_tl(ji,jj,1)
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zrhstl          = vb_tl(ji,jj,jk) + p2dt * va_tl(ji,jj,jk)   ! zrhs=right hand side
+               va_tl(ji,jj,jk) = zrhstl - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * va_tl(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! thrid recurrence : SOLk = ( Lk - Uk * SOLk+1 ) / Dk
+      DO jj = 2, jpjm1   
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            va_tl(ji,jj,jpkm1) = va_tl(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
+         END DO
+      END DO
+      DO jk = jpk-2, 1, -1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               va_tl(ji,jj,jk) = ( va_tl(ji,jj,jk) - zws(ji,jj,jk) * va_tl(ji,jj,jk+1) ) / zwd(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Normalization to obtain the general momentum trend va
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               va_tl(ji,jj,jk) = ( va_tl(ji,jj,jk) - vb_tl(ji,jj,jk) ) / p2dt
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE dyn_zdf_imp_tan
+   SUBROUTINE dyn_zdf_imp_adj( kt, p2dt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_zdf_imp_adj  ***
+      !!                   
+      !! ** Purpose of the direct routine:
+      !!      Compute the trend due to the vert. momentum diffusion
+      !!      and the surface forcing, and add it to the general trend of 
+      !!      the momentum equations.
+      !!
+      !! ** Method of the direct routine:
+      !!      The vertical momentum mixing trend is given by :
+      !!             dz( avmu dz(u) ) = 1/e3u dk+1( avmu/e3uw dk(ua) )
+      !!      backward time stepping
+      !!      Surface boundary conditions: wind stress input
+      !!      Bottom boundary conditions : bottom stress (cf zdfbfr.F)
+      !!      Add this trend to the general trend ua :
+      !!         ua = ua + dz( avmu dz(u) )E
+      !!
+      !! ** Action : - Update (ua,va) arrays with the after vertical diffusive
+      !!               mixing trend.
+      !!---------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      INTEGER , INTENT( in ) ::   kt                           ! ocean time-step index
+      REAL(wp), INTENT( in ) ::   p2dt                         ! time-step 
+
+      !! * Local declarations
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk                          ! dummy loop indices
+      REAL(wp) ::   zrau0r, z2dtf, zcoef, zzws, zrhsad ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zwi, zws, zwd! temporary workspace arrays
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_zdf_imp_adj : vertical momentum diffusion explicit operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~ '
+      ENDIF
+      ! 0. Local constant initialization
+      ! --------------------------------
+      zrau0r = 1. / rau0      ! inverse of the reference density
+      zrhsad = 0.0_wp
+
+      ! 2. Vertical diffusion on v
+      ! ---------------------------
+      ! Matrix and second member construction
+      ! bottom boundary condition: both zwi and zws must be masked as avmv can take
+      ! non zero value at the ocean bottom depending on the bottom friction
+      ! used but the bottom velocities have already been updated with the bottom
+      ! friction velocity in dyn_bfr using values from the previous timestep. There
+      ! is no need to include these in the implicit calculation.
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcoef         = -p2dt / fse3v(ji,jj,jk)
+               zwi(ji,jj,jk) = zcoef * avmv(ji,jj,jk  ) / fse3vw(ji,jj,jk  ) * vmask(ji,jj,jk)
+               zzws          = zcoef * avmv(ji,jj,jk+1) / fse3vw(ji,jj,jk+1)
+               zws(ji,jj,jk) =  zzws * vmask(ji,jj,jk+1)
+               zwd(ji,jj,jk) = 1._wp - zwi(ji,jj,jk) - zzws
+            END DO
+         END DO
+      END DO
+
+      ! Surface boudary conditions
+      DO jj = 2, jpjm1   
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zwi(ji,jj,1) = 0._wp
+            zwd(ji,jj,1) = 1._wp - zws(ji,jj,1)
+         END DO
+      END DO
+
+      ! Matrix inversion
+      !-----------------------------------------------------------------------
+      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+      !
+      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+      !        (        ...               )( ...  ) ( ...  )
+      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+      !
+      !   m is decomposed in the product of an upper and lower triangular
+      !   matrix
+      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+      !   The solution (after velocity) is in 2d array va
+      !-----------------------------------------------------------------------
+
+      ! First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1   (increasing k)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zwd(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwd(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! Normalization to obtain the general momentum trend va
+      DO jk = jpkm1, 1, -1
+         DO jj = jpjm1, 2, -1   
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+               vb_ad(ji,jj,jk) = vb_ad(ji,jj,jk) - va_ad(ji,jj,jk) / p2dt
+               va_ad(ji,jj,jk) = va_ad(ji,jj,jk) / p2dt
+            END DO
+         END DO
+      END DO
+      ! thrid recurrence : SOLk = ( Lk - Uk * SOLk+1 ) / Dk
+      DO jk = 1, jpk-2
+         DO jj = jpjm1, 2, -1   
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+               va_ad(ji,jj,jk+1) = va_ad(ji,jj,jk+1) - zws(ji,jj,jk) * va_ad(ji,jj,jk) / zwd(ji,jj,jk)
+               va_ad(ji,jj,jk  ) = va_ad(ji,jj,jk  ) / zwd(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      DO jj = jpjm1, 2, -1   
+         DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+            va_ad(ji,jj,jpkm1) = va_ad(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
+         END DO
+      END DO
+      ! second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1
+      DO jk = jpkm1, 2, -1
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+               zrhsad            = zrhsad + va_ad(ji,jj,jk)
+               va_ad(ji,jj,jk-1) = va_ad(ji,jj,jk-1) - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * va_ad(ji,jj,jk)
+               va_ad(ji,jj,jk  ) = 0.0_wp
+               vb_ad(ji,jj,jk)   = vb_ad(ji,jj,jk) + zrhsad
+               va_ad(ji,jj,jk)   = va_ad(ji,jj,jk) + p2dt * zrhsad
+               zrhsad            = 0.0_wp
+            END DO
+         END DO
+      END DO
+      DO jj = jpjm1, 2, -1
+         DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+            vb_ad(ji,jj,1) = vb_ad(ji,jj,1) + va_ad(ji,jj,1)
+            va_ad(ji,jj,1) = va_ad(ji,jj,1) * p2dt 
+         END DO
+      END DO
+
+      ! 1. Vertical diffusion on u
+      ! ---------------------------
+      ! Matrix and second member construction
+      ! bottom boundary condition: both zwi and zws must be masked as avmu can take
+      ! non zero value at the ocean bottom depending on the bottom friction
+      ! used but the bottom velocities have already been updated with the bottom
+      ! friction velocity in dyn_bfr using values from the previous timestep. There
+      ! is no need to include these in the implicit calculation.
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1 
+            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  ) * 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)
+               zwd(ji,jj,jk) = 1._wp - zwi(ji,jj,jk) - zzws
+            END DO
+         END DO
+      END DO
+
+      ! Surface boudary conditions
+      DO jj = 2, jpjm1 
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zwi(ji,jj,1) = 0._wp
+            zwd(ji,jj,1) = 1._wp - zws(ji,jj,1)
+         END DO
+      END DO
+
+      ! Matrix inversion starting from the first level
+      !-----------------------------------------------------------------------
+      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+      !
+      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+      !        (        ...               )( ...  ) ( ...  )
+      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+      !
+      !   m is decomposed in the product of an upper and a lower triangular matrix
+      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+      !   The solution (the after velocity) is in ua
+      !-----------------------------------------------------------------------
+
+     ! First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1   (increasing k)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zwd(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwd(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+      ! Normalization to obtain the general momentum trend ua
+      DO jk = jpkm1, 1, -1
+         DO jj = jpjm1, 2, -1  
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+               ub_ad(ji,jj,jk) = ub_ad(ji,jj,jk) - ua_ad(ji,jj,jk) / p2dt
+               ua_ad(ji,jj,jk) = ua_ad(ji,jj,jk) / p2dt
+            END DO
+         END DO
+      END DO
+      ! thrid recurrence : SOLk = ( Lk - Uk * Ek+1 ) / Dk
+      DO jk = 1, jpk-2
+         DO jj = jpjm1, 2, -1   
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+               ua_ad(ji,jj,jk+1) = ua_ad(ji,jj,jk+1) - ua_ad(ji,jj,jk) * zws(ji,jj,jk) / zwd(ji,jj,jk)
+               ua_ad(ji,jj,jk)   = ua_ad(ji,jj,jk) / zwd(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      DO jj = jpjm1, 2, -1   
+         DO ji = fs_jpim1, fs_2, -1
+            ua_ad(ji,jj,jpkm1) = ua_ad(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
+         END DO
+      END DO
+      DO jk = jpkm1, 2, -1
+         DO jj = jpjm1, 2, -1   
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+               zrhsad            = zrhsad + ua_ad(ji,jj,jk)
+               ua_ad(ji,jj,jk-1) = ua_ad(ji,jj,jk-1) - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * ua_ad(ji,jj,jk)
+               ua_ad(ji,jj,jk)   = 0.0_wp
+               ub_ad(ji,jj,jk)   = ub_ad(ji,jj,jk) + zrhsad
+               ua_ad(ji,jj,jk)   = ua_ad(ji,jj,jk) + zrhsad * p2dt
+               zrhsad            = 0.0_wp
+            END DO
+         END DO
+      END DO
+      ! second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1
+      DO jj = 2, jpjm1   
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ub_ad(ji,jj,1) = ub_ad(ji,jj,1) + ua_ad(ji,jj,1)
+            ua_ad(ji,jj,1) = p2dt * ua_ad(ji,jj,1)
+         END DO
+      END DO
+
+ 
+
+   END SUBROUTINE dyn_zdf_imp_adj
+#endif
+   !!==============================================================================
+END MODULE dynzdf_imp_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynzdf_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynzdf_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/dynzdf_tam.F90	(revision 2578)
@@ -0,0 +1,442 @@
+MODULE dynzdf_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                 ***  MODULE  dynzdf_tam  ***
+   !! Ocean dynamics :  vertical component of the momentum mixing trend
+   !!                   Tangent and adjoint module
+   !!==============================================================================
+   !! History of the direct module:
+   !!         9.0  !  05-11  (G. Madec)  Original code
+   !! History of the T&A module:
+   !!         9.0  !  08-06  (A. Vidard) Skeleton
+   !!         9.0  !  08-08  (A. Vidard) tam of the 05-11 version
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_zdf      : Update the momentum trend with the vertical diffusion
+   !!       zdf_ctl  : initializations of the vertical diffusion scheme
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 & 
+      & jpiglo
+   USE oce_tam       , ONLY: & ! ocean dynamics and tracers tam variables
+      & ub_tl,               &
+      & vb_tl,               &
+      & ub_ad,               &
+      & vb_ad,               &
+      & ua_tl,               &
+      & va_tl,               &
+      & ua_ad,               &
+      & va_ad
+   USE dom_oce       , ONLY: & ! ocean space and time domain variables 
+      & rdt,                 &
+      & neuler,              &
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3u,                 &
+      & e3v,                 &
+#endif
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      & umask,               &
+      & vmask,               &
+      & ln_sco,              &
+      & lk_esopa
+   USE zdf_oce       , ONLY: & ! ocean vertical physics
+      & avmu,                &
+      & avmv,                &
+      & rn_avm0,                &
+      & ln_zdfexp
+   USE dynzdf_exp_tam, ONLY: & ! vertical diffusion: explicit (dyn_zdf_exp     routine)
+      & dyn_zdf_exp_tan,     &
+      & dyn_zdf_exp_adj
+   USE dynzdf_imp_tam, ONLY: & ! vertical diffusion: implicit (dyn_zdf_imp     routine)
+      & dyn_zdf_imp_tan,     &
+      & dyn_zdf_imp_adj
+   USE ldfdyn_oce    , ONLY: & ! ocean dynamics: lateral physics
+      & ln_dynldf_iso,       &
+      & ln_dynldf_hor
+   USE in_out_manager, ONLY: & ! I/O manager
+      & numout,              &
+      & nit000,              &
+      & nitend,              &
+      & lwp
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          & !
+                               ! random field standard deviation for:
+      & stdu,                & !   u-velocity
+      & stdv
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_zdf_tan    !  routine called by step_tam.F90
+   PUBLIC   dyn_zdf_adj    !  routine called by step_tam.F90
+   PUBLIC   dyn_zdf_adj_tst!  routine called by tst.F90
+
+   INTEGER  ::   nzdf = 0              ! type vertical diffusion algorithm used 
+      !                                ! defined from ln_zdf...  namlist logicals)
+
+   REAL(wp) ::   r2dt                  ! time-step, = 2 rdttra
+      !                                ! except at nit000 (=rdttra) if neuler=0
+   LOGICAL :: lfirst = .TRUE.
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "zdfddm_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+   
+   SUBROUTINE dyn_zdf_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_zdf_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!            compute the vertical ocean dynamics physics.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      !!
+      IF( kt == nit000 .AND. lfirst )   CALL zdf_ctl_tam          ! initialisation & control of options
+
+      !                                          ! set time step
+      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (restarting with Euler time stepping)
+      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdttra (leapfrog)
+      ENDIF
+      SELECT CASE ( nzdf )                       ! compute lateral mixing trend and add it to the general trend
+      !
+      CASE ( 0 )   ;   CALL dyn_zdf_exp_tan    ( kt, r2dt )      ! explicit scheme
+      CASE ( 1 )   ;   CALL dyn_zdf_imp_tan    ( kt, r2dt )      ! implicit scheme (k-j-i loop)
+      !
+      END SELECT
+   END SUBROUTINE dyn_zdf_tan
+
+   SUBROUTINE dyn_zdf_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_zdf_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!            compute the vertical ocean dynamics physics.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      !!
+      IF( kt == nitend .AND. lfirst )   CALL zdf_ctl_tam          ! initialisation & control of options
+
+      !                                          ! set time step
+      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (restarting with Euler time stepping)
+      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdttra (leapfrog)
+      ELSEIF( kt == nitend ) THEN ; r2dt = 2. * rdt
+      ENDIF
+      SELECT CASE ( nzdf )                       ! compute lateral mixing trend and add it to the general trend
+      !
+      CASE ( 0 )   ;   CALL dyn_zdf_exp_adj    ( kt, r2dt )      ! explicit scheme
+      CASE ( 1 )   ;   CALL dyn_zdf_imp_adj    ( kt, r2dt )      ! implicit scheme (k-j-i loop)
+      !
+      END SELECT
+
+   END SUBROUTINE dyn_zdf_adj
+   SUBROUTINE zdf_ctl_tam
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE zdf_ctl_tam  ***
+      !!
+      !! ** Purpose :   initializations of the vertical diffusion scheme
+      !!
+      !! ** Method  :   implicit (euler backward) scheme (default)
+      !!                explicit (time-splitting) scheme if ln_zdfexp=T
+      !!----------------------------------------------------------------------
+      USE zdftke_old, ONLY : lk_zdftke_old
+      USE zdftke, ONLY : lk_zdftke
+      USE zdfkpp, ONLY : lk_zdfkpp
+      !!----------------------------------------------------------------------
+
+      ! Choice from ln_zdfexp read in namelist in zdfini
+      IF( ln_zdfexp ) THEN   ;   nzdf = 0           ! use explicit scheme
+      ELSE                   ;   nzdf = 1           ! use implicit scheme
+      ENDIF
+
+      ! Force implicit schemes
+      IF( lk_zdftke_old .OR. lk_zdftke .OR. lk_zdfkpp )   nzdf = 1   ! TKE or KPP physics
+      IF( ln_dynldf_iso                               )   nzdf = 1   ! iso-neutral lateral physics
+      IF( ln_dynldf_hor .AND. ln_sco                  )   nzdf = 1   ! horizontal lateral physics in s-coordinate
+
+      IF( lk_esopa )    nzdf = -1                   ! Esopa key: All schemes used
+
+      IF(lwp) THEN                                  ! Print the choice
+         WRITE(numout,*)
+         WRITE(numout,*) 'dyn:zdf_ctl_tam : vertical dynamics physics scheme'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         IF( nzdf == -1 )   WRITE(numout,*) '              ESOPA test All scheme used'
+         IF( nzdf ==  0 )   WRITE(numout,*) '              Explicit time-splitting scheme'
+         IF( nzdf ==  1 )   WRITE(numout,*) '              Implicit (euler backward) scheme'
+      ENDIF
+      !
+      lfirst = .FALSE. 
+   END SUBROUTINE zdf_ctl_tam
+   SUBROUTINE dyn_zdf_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_zdf_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Separate tests are applied for the following dx and dy:
+      !!                
+      !!              1) dx = ( SSH ) and dy = ( SSH )
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt          ! Output unit
+      INTEGER :: &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      !! * Local declarations
+       REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zub_tlin,     & ! Tangent input: before u-velocity
+         & zvb_tlin,     & ! Tangent input: before v-velocity
+         & zua_tlin,     & ! Tangent input: after u-velocity
+         & zva_tlin,     & ! Tangent input: after v-velocity
+         & zua_tlout,    & ! Tangent output: after u-velocity
+         & zva_tlout,    & ! Tangent output: after v-velocity
+         & zua_adin,     & ! Adjoint input: after u-velocity
+         & zva_adin,     & ! Adjoint input: after v-velocity
+         & zub_adout,    & ! Adjoint output: before u-velocity
+         & zvb_adout,    & ! Adjoint output: before v-velocity
+         & zua_adout,    & ! Adjoint output: after u-velocity
+         & zva_adout,    & ! Adjoint output: after v-velocity
+         & zau,          & ! 3D random field for ua
+         & zav,          & ! 3D random field for va
+         & zbu,          & ! 3D random field for ub
+         & zbv             ! 3D random field for vb
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_1,       & !   scalar product components
+         & zsp1_2,       & 
+         & zsp2,         & ! scalar product involving the adjoint routine
+         & zsp2_1,       & !   scalar product components
+         & zsp2_2,       & 
+         & zsp2_3,       & 
+         & zsp2_4
+      CHARACTER(LEN=14) :: cl_name
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zua_tlin(jpi,jpj,jpk),     & 
+         & zva_tlin(jpi,jpj,jpk),     & 
+         & zub_tlin(jpi,jpj,jpk),     & 
+         & zvb_tlin(jpi,jpj,jpk),     & 
+         & zua_tlout(jpi,jpj,jpk),    & 
+         & zva_tlout(jpi,jpj,jpk),    & 
+         & zua_adin(jpi,jpj,jpk),     & 
+         & zva_adin(jpi,jpj,jpk),     & 
+         & zua_adout(jpi,jpj,jpk),    & 
+         & zva_adout(jpi,jpj,jpk),    & 
+         & zub_adout(jpi,jpj,jpk),    & 
+         & zvb_adout(jpi,jpj,jpk),    & 
+         & zau(jpi,jpj,jpk),          & 
+         & zav(jpi,jpj,jpk),          & 
+         & zbu(jpi,jpj,jpk),          & 
+         & zbv(jpi,jpj,jpk)           &
+         & )
+
+      ! Initialize the direct trajectory
+      avmu(:,:,:) = rn_avm0 * umask(:,:,:)
+      avmv(:,:,:) = rn_avm0 * vmask(:,:,:)
+
+      !==================================================================
+      ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and 
+      !    dy = ( hdivb_tl, hdivn_tl )
+      !==================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+     
+      zua_tlin(:,:,:)  = 0.0_wp      
+      zva_tlin(:,:,:)  = 0.0_wp      
+      zub_tlin(:,:,:)  = 0.0_wp      
+      zvb_tlin(:,:,:)  = 0.0_wp      
+      zua_tlout(:,:,:) = 0.0_wp     
+      zva_tlout(:,:,:) = 0.0_wp     
+      zua_adin(:,:,:)  = 0.0_wp      
+      zva_adin(:,:,:)  = 0.0_wp      
+      zua_adout(:,:,:) = 0.0_wp     
+      zva_adout(:,:,:) = 0.0_wp     
+      zub_adout(:,:,:) = 0.0_wp     
+      zvb_adout(:,:,:) = 0.0_wp     
+      zau(:,:,:)       = 0.0_wp           
+      zav(:,:,:)       = 0.0_wp           
+      zbu(:,:,:)       = 0.0_wp           
+      zbv(:,:,:)       = 0.0_wp           
+
+      ub_tl(:,:,:)     = 0.0_wp
+      vb_tl(:,:,:)     = 0.0_wp
+      ua_tl(:,:,:)     = 0.0_wp
+      va_tl(:,:,:)     = 0.0_wp
+      ub_ad(:,:,:)     = 0.0_wp
+      vb_ad(:,:,:)     = 0.0_wp
+      ua_ad(:,:,:)     = 0.0_wp
+      va_ad(:,:,:)     = 0.0_wp
+          
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zbu, 'U', 0.0_wp, stdu )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 523432 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zbv, 'V', 0.0_wp, stdv )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 432545 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zau, 'U', 0.0_wp, stdu )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 287503 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zav, 'V', 0.0_wp, stdv )
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zub_tlin(ji,jj,jk) = zbu(ji,jj,jk) 
+               zvb_tlin(ji,jj,jk) = zbv(ji,jj,jk) 
+               zua_tlin(ji,jj,jk) = zau(ji,jj,jk) 
+               zva_tlin(ji,jj,jk) = zav(ji,jj,jk) 
+            END DO
+         END DO
+      END DO 
+
+      ub_tl(:,:,:) = zub_tlin(:,:,:)
+      vb_tl(:,:,:) = zvb_tlin(:,:,:)
+      ua_tl(:,:,:) = zua_tlin(:,:,:)
+      va_tl(:,:,:) = zva_tlin(:,:,:)
+
+      CALL dyn_zdf_tan( nit000 )
+
+      zua_tlout(:,:,:) = ua_tl(:,:,:)
+      zva_tlout(:,:,:) = va_tl(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zua_adin(ji,jj,jk) = zua_tlout(ji,jj,jk) &
+                 &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                 &               * umask(ji,jj,jk)
+              zva_adin(ji,jj,jk) = zva_tlout(ji,jj,jk) &
+                 &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+                 &               * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1_1 = DOT_PRODUCT( zua_tlout, zua_adin )
+      zsp1_2 = DOT_PRODUCT( zva_tlout, zva_adin )
+      zsp1   = zsp1_1 + zsp1_2
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      ua_ad(:,:,:) = zua_adin(:,:,:)
+      va_ad(:,:,:) = zva_adin(:,:,:)
+
+      CALL dyn_zdf_adj ( nit000 )
+      zub_adout(:,:,:)   = ub_ad(:,:,:)
+      zvb_adout(:,:,:)   = vb_ad(:,:,:)
+      zua_adout(:,:,:)   = ua_ad(:,:,:)
+      zva_adout(:,:,:)   = va_ad(:,:,:)
+      
+      zsp2_1 = DOT_PRODUCT( zub_tlin, zub_adout )
+      zsp2_2 = DOT_PRODUCT( zvb_tlin, zvb_adout )
+      zsp2_3 = DOT_PRODUCT( zua_tlin, zua_adout )
+      zsp2_4 = DOT_PRODUCT( zva_tlin, zva_adout )
+      zsp2   = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4 
+
+      ! Compare the scalar products
+
+      ! 14 char:'12345678901234'
+      cl_name = 'dyn_zdf_adj   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      DEALLOCATE( &
+         & zua_tlin,     & 
+         & zva_tlin,     & 
+         & zub_tlin,     & 
+         & zvb_tlin,     & 
+         & zua_tlout,    & 
+         & zva_tlout,    & 
+         & zua_adin,     & 
+         & zva_adin,     & 
+         & zua_adout,    & 
+         & zva_adout,    & 
+         & zub_adout,    & 
+         & zvb_adout,    & 
+         & zau,          & 
+         & zav,          & 
+         & zbu,          & 
+         & zbv           &
+         & )
+
+  END SUBROUTINE dyn_zdf_adj_tst
+   !!==============================================================================
+#endif
+END MODULE dynzdf_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/sshwzv_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/sshwzv_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/DYN/sshwzv_tam.F90	(revision 2578)
@@ -0,0 +1,1090 @@
+MODULE sshwzv_tam  
+#if defined key_tam
+   !!==============================================================================
+   !!                       ***  MODULE  sshwzv  ***
+   !! Ocean dynamics : sea surface height and vertical velocity
+   !!==============================================================================
+   !! History of the direct module:
+   !!            3.1  !  2009-02  (G. Madec, M. Leclair)  Original code
+   !! History of the TAM module:
+   !!            3.2  !  2010-04  (F. Vigilant) Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   ssh_wzv        : after ssh & now vertical velocity
+   !!   ssh_nxt        : filter ans swap the ssh arrays
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1,               &
+      & jpiglo
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              & 
+      & nit000,              &
+      & nitend,              &
+      & ln_ctl
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & n_cla,               &
+      & e2u,                 &
+      & e1v,                 &
+      & e1t,                 &
+      & e1f,                 &
+      & e2t,                 &
+      & e2f,                 &
+# if defined key_vvl
+      & e3t_1,               &
+# else
+#  if defined key_zco
+      & e3t_0,               &
+#  else
+      & e3t,                 &
+#  endif
+# endif
+# if defined key_zco
+!      & e3u_0,               &  scale factor is identical to e3t_0
+!      & e3v_0,               &
+# else
+      & e3u,                 &
+      & e3v,                 &
+      & e3f,                 &
+# endif
+      & lk_vvl,              &
+      & rdt,                 &
+      & neuler,              &
+      & atfp,                &
+      & tmask,               &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE prtctl        , ONLY: & ! Print control
+      & prt_ctl
+   USE phycst        , ONLY: & ! Physical constants
+      & rau0
+# if defined key_obc
+   USE obc_par       , ONLY: & ! Open boundary conditions
+      & lp_obc_east,         &
+      & lp_obc_west,         &
+      & lp_obc_north,        &
+      & lp_obc_south
+   USE obc_oce       , ONLY: & ! Open boundary conditions
+      & nie0p1,              &
+      & nie1p1,              &
+      & njn0p1,              &
+      & njn1p1,              &
+      & nje0,                &
+      & nje1,                &
+      & niw0,                &
+      & niw1,                &
+      & njw0,                &
+      & njw1,                &
+      & nin0,                &
+      & nin1,                &
+      & nis0,                &
+      & nis1,                &
+      & njs0,                &
+      & njs1
+# endif
+   USE lbclnk        , ONLY: & ! Lateral boundary conditions
+      & lbc_lnk
+
+   USE lbclnk_tam    , ONLY: & ! TAM lateral boundary conditions
+      & lbc_lnk_adj
+   USE divcur_tam    , ONLY: & ! TAM horizontal divergence and relative
+      & div_cur_tan,         & ! vorticity
+      & div_cur_adj            ! vorticity
+   USE cla_div_tam   , ONLY: & 
+      & div_cla_tan,         & ! 
+      & div_cla_adj            ! 
+   USE oce_tam       , ONLY: & ! TAM ocean dynamics and tracers variables
+      & un_tl,               &
+      & un_ad,               &
+      & vn_tl,               &
+      & vn_ad,               &
+      & wn_tl,               &
+      & wn_ad,               &
+      & wn_tl,               &
+      & wn_ad,               &
+      & hdivn_tl,            &
+      & hdivn_ad,            &
+      & hdivb_tl,            &
+      & hdivb_ad,            &
+      & rotn_tl,             &
+      & rotn_ad,             &
+      & rotb_tl,             &
+      & rotb_ad,             &
+      & sshb_tl,             &
+      & sshb_ad,             &
+      & sshn_tl,             &
+      & sshn_ad,             &
+      & ssha_tl,             &
+      & ssha_ad
+   USE sbc_oce_tam   , ONLY: & ! surface variables
+      & emp_tl,              &
+      & emp_ad
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE paresp        , ONLY: & ! Normalized energy weights
+      & wesp_ssh 
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          &
+      & stdssh,              &
+      & stdu,                &
+      & stdv
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ssh_wzv_tan       ! called by step.F90
+   PUBLIC   ssh_nxt_tan       ! called by step.F90
+   PUBLIC   ssh_wzv_adj       ! called by step.F90
+   PUBLIC   ssh_nxt_adj       ! called by step.F90
+   PUBLIC   ssh_wzv_adj_tst   ! called by tamtst.F90
+   PUBLIC   ssh_nxt_adj_tst   ! called by tamtst.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE ssh_wzv_tan( kt , kdum ) 
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE ssh_wzv_tan  ***
+      !!                   
+      !! ** Purpose of direct routine : 
+      !!              compute the after ssh (ssha), the now vertical velocity
+      !!              and update the now vertical coordinate (lk_vvl=T).
+      !!
+      !! ** Method  : -
+      !!
+      !!              - Using the incompressibility hypothesis, the vertical 
+      !!      velocity is computed by integrating the horizontal divergence  
+      !!      from the bottom to the surface minus the scale factor evolution.
+      !!        The boundary conditions are w=0 at the bottom (no flux) and.
+      !!
+      !! ** action  :   ssha    : after sea surface height
+      !!                wn      : now vertical velocity
+      !! if lk_vvl=T:   sshu_a, sshv_a, sshf_a  : after sea surface height
+      !!                          at u-, v-, f-point s
+      !!                hu, hv, hur, hvr : ocean depth and its inverse at u-,v-points
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt   ! time step
+      !!
+      INTEGER  ::   jk              ! dummy loop indices
+      REAL(wp) ::   z2dt, zraur     ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zhdivtl     ! 2D workspace
+      INTEGER, OPTIONAL            ::   kdum        ! dummy argument to compute only vertical velocity
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'ssh_wzv_tan : after sea surface height and now vertical velocity '
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+         !
+         wn_tl(:,:,jpk) = 0.0_wp                   ! bottom boundary condition: w=0 (set once for all)
+         !
+         IF( lk_vvl ) THEN                    ! before and now Sea SSH at u-, v-, f-points (vvl case only)
+            IF (lwp) WRITE(numout,*) 'lk_vvl not available yet' 
+            CALL abort
+         ENDIF
+         !
+      ENDIF
+      !                                           !------------------------------!
+      IF( lk_vvl ) THEN                           !  Update Now Vertical coord.  !   (only in vvl case)
+                                                  !------------------------------!
+         IF (lwp) WRITE(numout,*) 'lk_vvl not available yet' 
+         CALL abort
+         !
+      ENDIF
+
+                         CALL div_cur_tan( kt )            ! Horizontal divergence & Relative vorticity
+
+      IF ( .NOT. PRESENT(kdum) ) THEN             ! jump
+         IF( n_cla == 1 )   CALL div_cla_tan( kt )            ! Cross Land Advection (Update Hor. divergence)
+      ENDIF
+
+      ! set time step size (Euler/Leapfrog)
+      z2dt = 2. * rdt 
+      IF( neuler == 0 .AND. kt == nit000 )   z2dt =rdt
+
+      zraur = 1. / rau0
+
+      IF ( .NOT. PRESENT(kdum) ) THEN             ! jump ssh computing
+         !                                        !------------------------------!
+         !                                        !   After Sea Surface Height   !
+         !                                        !------------------------------!
+         zhdivtl(:,:) = 0.0_wp
+         DO jk = 1, jpkm1                                 ! Horizontal divergence of barotropic transports
+            zhdivtl(:,:) = zhdivtl(:,:) + fse3t(:,:,jk) * hdivn_tl(:,:,jk)
+         END DO
+
+         !                                                ! Sea surface elevation time stepping
+         ssha_tl(:,:) = (  sshb_tl(:,:) - z2dt * ( zraur * emp_tl(:,:) + zhdivtl(:,:) )  ) * tmask(:,:,1)
+
+#if defined key_agrif
+!      CALL agrif_ssh_tan(kt)
+         IF (lwp) WRITE(numout,*) 'key_agrif not available yet' 
+         CALL abort
+#endif
+#if defined key_obc
+         IF ( Agrif_Root() ) THEN
+            ssha_tl(:,:) = ssha_tl(:,:) * obctmsk(:,:)
+            CALL lbc_lnk( ssha_tl, 'T', 1.0_wp )  ! absolutly compulsory !! (jmm)
+         ENDIF
+#endif
+
+         !                                                ! Sea Surface Height at u-,v- and f-points (vvl case only)
+         IF( lk_vvl ) THEN                                ! (required only in key_vvl case)
+            IF (lwp) WRITE(numout,*) 'lk_vvl not available yet' 
+            CALL abort
+         ENDIF
+
+      ENDIF
+      !                                           !------------------------------!
+      !                                           !     Now Vertical Velocity    !
+      !                                           !------------------------------!
+      !                                                ! integrate from the bottom the hor. divergence
+      DO jk = jpkm1, 1, -1
+         wn_tl(:,:,jk) = wn_tl(:,:,jk+1) - fse3t_n(:,:,jk) * hdivn_tl(:,:,jk)
+      END DO
+      !
+   END SUBROUTINE ssh_wzv_tan
+
+   SUBROUTINE ssh_nxt_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE ssh_nxt_tan  ***
+      !!
+      !! ** Purpose of the direct :
+      !!              achieve the sea surface  height time stepping by 
+      !!              applying Asselin time filter and swapping the arrays
+      !!              ssha  already computed in ssh_wzv  
+      !!
+      !! ** Method  : - apply Asselin time fiter to now ssh and swap :
+      !!             sshn = ssha + atfp * ( sshb -2 sshn + ssha )
+      !!             sshn = ssha
+      !!
+      !! ** action  : - sshb, sshn   : before & now sea surface height
+      !!                               ready for the next time step
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj               ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'ssh_nxt_tan : next sea surface height (Asselin time filter + swap)'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+
+      ! Time filter and swap of the ssh
+      ! -------------------------------
+
+      IF( lk_vvl ) THEN      ! Variable volume levels :   ssh at t-, u-, v, f-points
+         !                   ! ---------------------- !
+         IF (lwp) WRITE(numout,*) 'lk_vvl not available yet' 
+         CALL abort
+         !
+      ELSE                   ! fixed levels :   ssh at t-point only
+         !                   ! ------------ !
+         IF( neuler == 0 .AND. kt == nit000 ) THEN      ! Euler time-stepping at first time-step : no filter
+            sshn_tl(:,:) = ssha_tl(:,:)                            ! now <-- after  (before already = now)
+            !
+         ELSE                                           ! Leap-Frog time-stepping: Asselin filter + swap
+            DO jj = 1, jpj
+               DO ji = 1, jpi                                ! before <-- now filtered
+                  sshb_tl(ji,jj) = sshn_tl(ji,jj) + atfp * ( sshb_tl(ji,jj) - 2 * sshn_tl(ji,jj) + ssha_tl(ji,jj) )    
+                  sshn_tl(ji,jj) = ssha_tl(ji,jj)                  ! now <-- after
+               END DO
+            END DO
+         ENDIF
+      ENDIF
+      !
+#if defined key_agrif
+      ! Update velocity at AGRIF zoom boundaries
+      !IF (.NOT.Agrif_Root())    CALL Agrif_Update_Dyn_tan( kt )
+      IF (lwp) WRITE(numout,*) 'key_agrif not available yet' 
+      CALL abort
+#endif
+      !
+   END SUBROUTINE ssh_nxt_tan
+
+   SUBROUTINE ssh_wzv_adj( kt , kdum ) 
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE ssh_wzv_adj  ***
+      !!                   
+      !! ** Purpose of direct routine : 
+      !!              compute the after ssh (ssha), the now vertical velocity
+      !!              and update the now vertical coordinate (lk_vvl=T).
+      !!
+      !! ** Method  : -
+      !!
+      !!              - Using the incompressibility hypothesis, the vertical 
+      !!      velocity is computed by integrating the horizontal divergence  
+      !!      from the bottom to the surface minus the scale factor evolution.
+      !!        The boundary conditions are w=0 at the bottom (no flux) and.
+      !!
+      !! ** action  :   ssha    : after sea surface height
+      !!                wn      : now vertical velocity
+      !! if lk_vvl=T:   sshu_a, sshv_a, sshf_a  : after sea surface height
+      !!                          at u-, v-, f-point s
+      !!                hu, hv, hur, hvr : ocean depth and its inverse at u-,v-points
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt   ! time step
+      !!
+      INTEGER  ::   jk              ! dummy loop indices
+      REAL(wp) ::   z2dt, zraur     ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zhdivad     ! 2D workspace
+      INTEGER, OPTIONAL            ::   kdum        ! dummy argument to compute only vertical velocity
+      !!----------------------------------------------------------------------
+
+      ! adjoint variable initialization
+      zhdivad = 0.0_wp
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'ssh_wzv_adj : after sea surface height and now vertical velocity '
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+
+      !                                           !------------------------------!
+      !                                           !     Now Vertical Velocity    !
+      !                                           !------------------------------!
+      !                                                ! integrate from the bottom the hor. divergence
+      DO jk = 1, jpkm1
+         hdivn_ad(:,:,jk  ) = hdivn_ad(:,:,jk  ) - fse3t_n(:,:,jk) * wn_ad(:,:,jk)
+         wn_ad(   :,:,jk+1) = wn_ad(:,:,jk+1) +  wn_ad(:,:,jk)
+         wn_ad(   :,:,jk  ) = 0.0_wp
+      END DO
+      !
+      ! set time step size (Euler/Leapfrog)
+      z2dt = 2. * rdt 
+      IF( neuler == 0 .AND. kt == nit000 )   z2dt =rdt
+
+      zraur = 1. / rau0
+
+      IF ( .NOT. PRESENT(kdum) ) THEN             ! jump ssh computing
+         !                                        !------------------------------!
+         !                                        !   After Sea Surface Height   !
+         !                                        !------------------------------!
+         !                                                ! Sea Surface Height at u-,v- and f-points (vvl case only)
+         IF( lk_vvl ) THEN                                ! (required only in key_vvl case)
+            IF (lwp) WRITE(numout,*) 'lk_vvl not available yet' 
+            CALL abort
+         ENDIF
+
+#if defined key_obc
+         IF ( Agrif_Root() ) THEN
+            CALL lbc_lnk_ad( ssha_ad, 'T', 1.0_wp )  ! absolutly compulsory !! (jmm)
+            ssha_ad(:,:) = ssha_ad(:,:) * obctmsk(:,:)
+         ENDIF
+#endif
+#if defined key_agrif
+!      CALL agrif_ssh_adj(kt)
+         IF (lwp) WRITE(numout,*) 'key_agrif not available yet' 
+         CALL abort
+#endif         !                                                ! Sea surface elevation time stepping
+         sshb_ad(:,:) = sshb_ad(:,:) + ssha_ad(:,:)* tmask(:,:,1)
+         emp_ad( :,:) = emp_ad(:,:)  - z2dt * zraur * ssha_ad(:,:) * tmask(:,:,1)
+         zhdivad(:,:) = zhdivad(:,:) - z2dt * tmask(:,:,1) * ssha_ad(:,:)
+         ssha_ad(:,:) = 0.0_wp
+
+         DO jk = 1, jpkm1                                 ! Horizontal divergence of barotropic transports
+            hdivn_ad(:,:,jk) = hdivn_ad(:,:,jk) + fse3t(:,:,jk) * zhdivad(:,:)
+         END DO
+
+      ENDIF
+
+      IF ( .NOT. PRESENT(kdum) ) THEN             ! jump
+         IF( n_cla == 1 )   CALL div_cla_adj( kt )            ! Cross Land Advection (Update Hor. divergence)
+      ENDIF
+
+                         CALL div_cur_adj( kt )            ! Horizontal divergence & Relative vorticity
+      !
+      !                                           !------------------------------!
+      IF( lk_vvl ) THEN                           !  Update Now Vertical coord.  !   (only in vvl case)
+                                                  !------------------------------!
+         IF (lwp) WRITE(numout,*) 'lk_vvl not available yet' 
+         CALL abort
+         !
+      ENDIF
+      !
+      IF( kt == nit000 ) THEN
+         !
+         IF( lk_vvl ) THEN                    ! before and now Sea SSH at u-, v-, f-points (vvl case only)
+            IF (lwp) WRITE(numout,*) 'lk_vvl not available yet' 
+            CALL abort
+         ENDIF
+         !
+         wn_ad(:,:,jpk) = 0.0_wp                   ! bottom boundary condition: w=0 (set once for all)
+         !
+      ENDIF
+      !
+   END SUBROUTINE ssh_wzv_adj
+
+   SUBROUTINE ssh_nxt_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE ssh_nxt_adj  ***
+      !!
+      !! ** Purpose of the direct :
+      !!              achieve the sea surface  height time stepping by 
+      !!              applying Asselin time filter and swapping the arrays
+      !!              ssha  already computed in ssh_wzv  
+      !!
+      !! ** Method  : - apply Asselin time fiter to now ssh and swap :
+      !!             sshn = ssha + atfp * ( sshb -2 sshn + ssha )
+      !!             sshn = ssha
+      !!
+      !! ** action  : - sshb, sshn   : before & now sea surface height
+      !!                               ready for the next time step
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj               ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'ssh_nxt_adj : next sea surface height (Asselin time filter + swap)'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+
+      ! Time filter and swap of the ssh
+      ! -------------------------------
+#if defined key_agrif
+      ! Update velocity at AGRIF zoom boundaries
+      !IF (.NOT.Agrif_Root())    CALL Agrif_Update_Dyn_adj( kt )
+      IF (lwp) WRITE(numout,*) 'key_agrif not available yet' 
+      CALL abort
+#endif
+      IF( lk_vvl ) THEN      ! Variable volume levels :   ssh at t-, u-, v, f-points
+         !                   ! ---------------------- !
+         IF (lwp) WRITE(numout,*) 'lk_vvl not available yet' 
+         CALL abort
+         !
+      ELSE                   ! fixed levels :   ssh at t-point only
+         !                   ! ------------ !
+         IF( neuler == 0 .AND. kt == nit000 ) THEN      ! Euler time-stepping at first time-step : no filter
+            ssha_ad(:,:) = ssha_ad(:,:) + sshn_ad(:,:)
+            sshn_ad(:,:) = 0.0_wp
+            !
+         ELSE                                           ! Leap-Frog time-stepping: Asselin filter + swap
+            DO jj = 1, jpj
+               DO ji = 1, jpi                                ! before <-- now filtered
+                  ssha_ad(ji,jj) = ssha_ad(ji,jj) + sshn_ad(ji,jj)
+                  sshn_ad(ji,jj) = (1.0_wp - 2.0 * atfp) * sshb_ad(ji,jj)
+                  ssha_ad(ji,jj) = ssha_ad(ji,jj) + atfp * sshb_ad(ji,jj)
+                  sshb_ad(ji,jj) = atfp * sshb_ad(ji,jj)
+               END DO
+            END DO
+         ENDIF
+      ENDIF
+
+      !
+   END SUBROUTINE ssh_nxt_adj
+
+   SUBROUTINE ssh_wzv_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!          ***  ROUTINE ssh_wzv_adj_tst : TEST OF wzv_adj  ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Separate tests are applied for the following dx and dy:
+      !!         
+      !!            dx = ( un_tl, vn_tl, hdivn_tl, rotn_tl, emp_tl, sshb_tl ) and
+      !!            dy = ( hdivn_tl, hdivb_tl, rotn_tl, rotb_tl, wn_tl, ssha_tl )
+      !!
+      !! History :
+      !!        ! 2010-04 (F. Vigilant)
+      !!-----------------------------------------------------------------------
+
+      !! * Modules used
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zun_tlin,     & ! Tangent input: now u-velocity
+         & zvn_tlin,     & ! Tangent input: now v-velocity
+         & zhdivn_tlin,  & ! Tangent input: now horizontal divergence
+         & zrotn_tlin,   & ! Tangent input: now horizontal divergence
+         & zhdivn_tlout, & ! Tangent output: now horizontal divergence
+         & zrotn_tlout,  & ! Tangent output: now horizontal divergence
+         & zrotb_tlout,  & ! Tangent output: now horizontal divergence
+         & zhdivb_tlout, & ! Tangent output: now horizontal divergence
+         & zwn_tlout,    & ! Tangent output: now w-velocity
+         & zwn_adin,     & ! Adjoint input: now w-velocity
+         & zhdivn_adout, & ! Adjoint output: now horizontal divergence
+         & zrotn_adin,   & ! Adjoint input: now horizontal divergence
+         & zrotn_adout,  & ! Adjoint output: now horizontal divergence
+         & zrotb_adin,   & ! Adjoint input: now horizontal divergence
+         & zhdivn_adin,  & ! Adjoint input: now horizontal divergence
+         & zhdivb_adin,  & ! Adjoint output: now horizontal divergence
+         & zun_adout,    & ! Adjoint output: now horizontal divergence
+         & zvn_adout,    & ! Adjoint output: now horizontal divergence
+         & znu,          & ! 3D random field for u
+         & znv             ! 3D random field for v
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zsshb_tlin,   & ! Tangent input: before SSH
+         & zssha_tlout,  & ! Tangent input: before SSH
+         & zsshb_adout,  & ! Adjoint output: before SSH
+         & zssha_adin,   & ! Adjoint output: before SSH
+         & zemp_tlin,    & ! Tangent input: EmP
+         & zemp_adout,   & ! Adjoint output: EmP
+         & znssh,        & ! 2D random field for SSH
+         & znemp           ! 2D random field for EmP
+
+      INTEGER :: &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d           ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+                              ! random field standard deviation for:
+         & zstdssh,         & !   SSH
+         & zstdemp,         & !   EMP
+         & zsp1,            & ! scalar product involving the tangent routine
+         & zsp2,            & ! scalar product involving the adjoint routine
+         & zsp2_1,          & !   scalar product components
+         & zsp2_2,          & 
+         & zsp2_3,          & 
+         & zsp2_4,          & 
+         & zsp2_5,          & 
+         & zsp2_6,          & 
+         & z2dt,            & ! temporary scalars
+         & zraur
+      CHARACTER (LEN=14) :: &
+         & cl_name
+
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zhdivn_tlin(jpi,jpj,jpk),  &
+         & zhdivb_tlout(jpi,jpj,jpk), &
+         & zhdivn_tlout(jpi,jpj,jpk), &
+         & zrotn_tlin(jpi,jpj,jpk),   &
+         & zrotn_tlout(jpi,jpj,jpk),  &
+         & zrotb_tlout(jpi,jpj,jpk),  &
+         & zwn_tlout(jpi,jpj,jpk),    &
+         & zwn_adin(jpi,jpj,jpk),     &
+         & zhdivn_adout(jpi,jpj,jpk), &
+         & zhdivb_adin(jpi,jpj,jpk),  &
+         & zrotn_adin(jpi,jpj,jpk),   &
+         & zrotn_adout(jpi,jpj,jpk),  &
+         & zrotb_adin(jpi,jpj,jpk),   &
+         & zhdivn_adin(jpi,jpj,jpk),  &
+         & zun_tlin(jpi,jpj,jpk),     &
+         & zvn_tlin(jpi,jpj,jpk),     &
+         & zun_adout(jpi,jpj,jpk),    &
+         & zvn_adout(jpi,jpj,jpk),    &
+         & znu(jpi,jpj,jpk),          &
+         & znv(jpi,jpj,jpk)           &
+         & )
+      ALLOCATE( &
+         & zsshb_tlin(jpi,jpj),       &
+         & zsshb_adout(jpi,jpj),      &
+         & zssha_tlout(jpi,jpj),      &
+         & zssha_adin(jpi,jpj),       &
+         & zemp_tlin(jpi,jpj),        &
+         & zemp_adout(jpi,jpj),       &
+         & znssh(jpi,jpj),            &
+         & znemp(jpi,jpj)             &
+         & )
+      
+
+      ! Initialize constants
+
+      z2dt  = 2.0_wp * rdt       ! time step: leap-frog
+      zraur = 1.0_wp / rau0      ! inverse density of pure water (m3/kg)
+
+      zhdivn_tlin(:,:,:) = 0.0_wp
+      zrotn_tlin(:,:,:) = 0.0_wp
+      zemp_tlin(:,:) = 0.0_wp
+      zsshb_tlin(:,:) = 0.0_wp
+      zun_tlin (:,:,:) = 0.0_wp
+      zvn_tlin (:,:,:) = 0.0_wp
+
+      zhdivn_tlout(:,:,:) = 0.0_wp
+      zhdivb_tlout(:,:,:) = 0.0_wp
+      zrotn_tlout(:,:,:)  = 0.0_wp
+      zrotb_tlout(:,:,:)  = 0.0_wp
+      zwn_tlout(:,:,:) = 0.0_wp
+      zssha_tlout(:,:) = 0.0_wp
+
+      zhdivn_adin(:,:,:) = 0.0_wp
+      zhdivb_adin(:,:,:) = 0.0_wp
+      zrotn_adin(:,:,:)  = 0.0_wp
+      zrotb_adin(:,:,:)  = 0.0_wp
+      zwn_adin(:,:,:) = 0.0_wp
+      zssha_adin(:,:) = 0.0_wp
+
+      zhdivn_adout(:,:,:) = 0.0_wp
+      zrotn_adout(:,:,:) = 0.0_wp
+      zemp_adout(:,:) = 0.0_wp
+      zsshb_adout(:,:) = 0.0_wp
+      zun_adout (:,:,:) = 0.0_wp
+      zvn_adout (:,:,:) = 0.0_wp
+
+      un_tl   (:,:,:) = 0.0_wp
+      vn_tl   (:,:,:) = 0.0_wp
+      hdivn_tl(:,:,:) = 0.0_wp
+      hdivb_tl(:,:,:) = 0.0_wp
+      rotn_tl (:,:,:) = 0.0_wp
+      rotb_tl (:,:,:) = 0.0_wp
+      wn_tl(:,:,:) = 0.0_wp
+      ssha_tl(:,:) = 0.0_wp
+      sshb_tl(:,:) = 0.0_wp
+      emp_tl(:,:) = 0.0_wp
+
+      un_ad   (:,:,:) = 0.0_wp
+      vn_ad   (:,:,:) = 0.0_wp
+      hdivn_ad(:,:,:) = 0.0_wp
+      hdivb_ad(:,:,:) = 0.0_wp
+      rotn_ad (:,:,:) = 0.0_wp
+      rotb_ad (:,:,:) = 0.0_wp
+      wn_ad(:,:,:) = 0.0_wp
+      sshb_ad(:,:) = 0.0_wp
+      ssha_ad(:,:) = 0.0_wp
+      emp_ad(:,:) = 0.0_wp
+
+      !=============================================================
+      ! 1) dx = ( un_tl, vn_tl, emp_tl, sshb_tl ) and dy = ( wn_tl )
+      !                   - or -
+      ! 2) dx = ( hdivn_tl ) and dy = ( wn_tl )   
+      !=============================================================
+
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znu, 'U', 0.0_wp, stdu )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 523432 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znv, 'V', 0.0_wp, stdv )
+
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zun_tlin(ji,jj,jk) = znu(ji,jj,jk) 
+               zvn_tlin(ji,jj,jk) = znv(ji,jj,jk) 
+            END DO
+         END DO
+      END DO 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 785483 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znssh, 'T', 0.0_wp, stdssh )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 358606 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znemp, 'T', 0.0_wp, stdssh ) 
+
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zsshb_tlin(ji,jj) = znssh(ji,jj)
+            zemp_tlin (ji,jj) = znemp(ji,jj) / ( z2dt * zraur )
+         END DO
+      END DO
+
+      un_tl(:,:,:) = zun_tlin(:,:,:)
+      vn_tl(:,:,:) = zvn_tlin(:,:,:)
+      CALL div_cur_tan( nit000 )    ! Generate noise hdiv/rot fields
+
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zhdivn_tlin(ji,jj,jk) = 0.5_wp * hdivn_tl(ji,jj,jk) 
+               zrotn_tlin (ji,jj,jk) = 0.5_wp * rotn_tl (ji,jj,jk) 
+            END DO
+         END DO
+      END DO 
+
+      ! re-initialization to zero
+      un_tl   (:,:,:) = 0.0_wp
+      vn_tl   (:,:,:) = 0.0_wp
+      hdivb_tl(:,:,:) = 0.0_wp
+      hdivn_tl(:,:,:) = 0.0_wp
+      rotb_tl (:,:,:) = 0.0_wp
+      rotn_tl (:,:,:) = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Call the tangent routine: dy = L dx
+      !--------------------------------------------------------------------
+
+      hdivn_tl(:,:,:) = zhdivn_tlin(:,:,:)
+      rotn_tl(:,:,:) = zrotn_tlin(:,:,:)
+      sshb_tl(:,:) = zsshb_tlin(:,:)
+      emp_tl (:,:) = zemp_tlin (:,:)
+      un_tl(:,:,:) = zun_tlin(:,:,:)
+      vn_tl(:,:,:) = zvn_tlin(:,:,:)
+
+      CALL ssh_wzv_tan( nit000+1 ) 
+
+      zwn_tlout(:,:,:) = wn_tl(:,:,:)
+      zssha_tlout(:,: ) = ssha_tl(:,:)
+      zhdivb_tlout(:,:,:) = hdivb_tl(:,:,:)
+      zhdivn_tlout(:,:,:) = hdivn_tl(:,:,:)
+      zrotb_tlout(:,:,:) = rotb_tl(:,:,:)
+      zrotn_tlout(:,:,:) = rotn_tl(:,:,:)
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zwn_adin(ji,jj,jk) = zwn_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zssha_adin(ji,jj) = zssha_tlout(ji,jj) &
+               &                   * e1t(ji,jj) * e2t(ji,jj) * wesp_ssh &
+               &                   * tmask(ji,jj,1)
+         END DO
+      END DO
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zhdivb_adin(ji,jj,jk) = zhdivb_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk)
+              zhdivn_adin(ji,jj,jk) = zhdivn_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zrotb_adin(ji,jj,jk) = zrotb_tlout(ji,jj,jk) &
+                 &               * e1f(ji,jj) * e2f(ji,jj) * fse3f(ji,jj,jk)
+              zrotn_adin(ji,jj,jk) = zrotn_tlout(ji,jj,jk) &
+                 &               * e1f(ji,jj) * e2f(ji,jj) * fse3f(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+
+      zsp1 = DOT_PRODUCT( zwn_tlout, zwn_adin ) + DOT_PRODUCT( zssha_tlout, zssha_adin ) &
+           & +  DOT_PRODUCT( zhdivb_tlout, zhdivb_adin ) + DOT_PRODUCT( zhdivn_tlout, zhdivn_adin ) & 
+           & +  DOT_PRODUCT( zrotb_tlout, zrotb_adin ) + DOT_PRODUCT( zrotn_tlout, zrotn_adin )
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      wn_ad(:,:,:) = zwn_adin(:,:,:)
+      ssha_ad(:,:) = zssha_adin(:,:)
+      hdivb_ad(:,:,:) = zhdivb_adin(:,:,:)
+      hdivn_ad(:,:,:) = zhdivn_adin(:,:,:)
+      rotb_ad(:,:,:) = zrotb_adin(:,:,:)
+      rotn_ad(:,:,:) = zrotn_adin(:,:,:)
+
+      CALL ssh_wzv_adj( nit000+1 )
+
+      zrotn_adout(:,:,:) = rotn_ad(:,:,:)
+      zhdivn_adout(:,:,:) = hdivn_ad(:,:,:)
+      zsshb_adout(:,:) = sshb_ad(:,:)
+      zemp_adout (:,:) = emp_ad (:,:)
+      zun_adout(:,:,:) = un_ad(:,:,:)
+      zvn_adout(:,:,:) = vn_ad(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: dx^T L^T W dy
+      !--------------------------------------------------------------------
+
+      zsp2_1 = DOT_PRODUCT( zun_tlin,    zun_adout    )
+      zsp2_2 = DOT_PRODUCT( zvn_tlin,    zvn_adout    )
+      zsp2_3 = DOT_PRODUCT( zhdivn_tlin, zhdivn_adout )
+      zsp2_4 = DOT_PRODUCT( zemp_tlin,   zemp_adout   )
+      zsp2_5 = DOT_PRODUCT( zsshb_tlin,  zsshb_adout  )
+      zsp2_6 = DOT_PRODUCT( zrotn_tlin,  zrotn_adout  )
+
+      zsp2 = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4 + zsp2_5 + zsp2_6
+
+      ! Compare the scalar products
+      ! 14 char:'12345678901234'
+      cl_name = 'sshwzv_adj    '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+   END SUBROUTINE ssh_wzv_adj_tst
+
+   SUBROUTINE ssh_nxt_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!          ***  ROUTINE ssh_nxt_adj_tst : TEST OF nxt_adj  ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Separate tests are applied for the following dx and dy:
+      !!         
+      !!            dx = ( sshb_tl, sshn_tl, ssha_tl ) and
+      !!            dy = ( ssb_tl, sshn_tl )
+      !!
+      !! History :
+      !!        ! 2010-05 (F. Vigilant)
+      !!-----------------------------------------------------------------------
+
+      !! * Modules used
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zsshb_tlin,   & ! Tangent input: before SSH
+         & zsshn_tlin,   & ! Tangent input: before SSH
+         & zssha_tlin,   & ! Tangent input: before SSH
+         & zsshb_tlout,  & ! Tangent output: before SSH
+         & zsshn_tlout,  & ! Tangent output: before SSH
+         & zsshb_adin,   & ! Adjoint input: before SSH
+         & zsshn_adin,   & ! Adjoint input: before SSH
+         & zsshb_adout,  & ! Adjoint output: before SSH
+         & zsshn_adout,  & ! Adjoint output: before SSH
+         & zssha_adout,  & ! Adjoint output: before SSH
+         & znssh           ! 2D random field for EmP
+
+      INTEGER :: &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d           ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+                              ! random field standard deviation for:
+         & zstdssh,         & !   SSH
+         & zsp1,            & ! scalar product involving the tangent routine
+         & zsp2,            & ! scalar product involving the adjoint routine
+         & zsp1_1,          & !   scalar product components
+         & zsp1_2,          & 
+         & zsp2_1,          & !   scalar product components
+         & zsp2_2,          & 
+         & zsp2_3,          & 
+         & zsp2_4
+      CHARACTER (LEN=14) :: &
+         & cl_name
+
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zsshb_tlin(jpi,jpj),       &
+         & zsshn_tlin(jpi,jpj),       &
+         & zssha_tlin(jpi,jpj),       &
+         & zsshb_tlout(jpi,jpj),      &
+         & zsshn_tlout(jpi,jpj),      &
+         & zsshb_adin(jpi,jpj),       &
+         & zsshn_adin(jpi,jpj),       &
+         & zsshb_adout(jpi,jpj),      &
+         & zsshn_adout(jpi,jpj),      &
+         & zssha_adout(jpi,jpj),      &
+         & znssh(jpi,jpj)             &
+         & )
+      
+
+      ! Initialize constants
+
+      zsshb_tlin(:,:)  = 0.0_wp
+      zsshn_tlin(:,:)  = 0.0_wp
+      zssha_tlin(:,:)  = 0.0_wp
+
+      zsshb_tlout(:,:) = 0.0_wp
+      zsshn_tlout(:,:) = 0.0_wp
+
+      zsshb_adout(:,:) = 0.0_wp
+      zsshn_adout(:,:) = 0.0_wp
+      zssha_adout(:,:) = 0.0_wp
+
+      zsshb_adin(:,:)  = 0.0_wp
+      zsshn_adin(:,:)  = 0.0_wp
+
+      sshb_tl(:,:)     = 0.0_wp
+      sshn_tl(:,:)     = 0.0_wp
+      ssha_tl(:,:)     = 0.0_wp
+
+      sshb_ad(:,:)     = 0.0_wp
+      sshn_ad(:,:)     = 0.0_wp
+      ssha_ad(:,:)     = 0.0_wp
+
+      !=============================================================
+      ! dx = ( sshb_tl, sshn_tl, ssha_tl ) and dy = ( ssb_tl, sshn_tl )
+      !=============================================================
+
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 785483 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znssh, 'T', 0.0_wp, stdssh )
+
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zsshb_tlin(ji,jj) = znssh(ji,jj)
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 358606 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znssh, 'T', 0.0_wp, stdssh ) 
+
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zsshn_tlin(ji,jj) = znssh(ji,jj)
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, znssh, 'T', 0.0_wp, stdssh ) 
+
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zssha_tlin(ji,jj) = znssh(ji,jj)
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Call the tangent routine: dy = L dx
+      !--------------------------------------------------------------------
+
+      sshb_tl(:,:) = zsshb_tlin(:,:)
+      sshn_tl(:,:) = zsshn_tlin(:,:)
+      ssha_tl(:,:) = zssha_tlin(:,:)
+
+      CALL ssh_nxt_tan( nit000+1 ) 
+
+      zsshb_tlout(:,: ) = sshb_tl(:,:)
+      zsshn_tlout(:,: ) = sshn_tl(:,:)
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zsshb_adin(ji,jj) = zsshb_tlout(ji,jj) &
+               &                   * e1t(ji,jj) * e2t(ji,jj) * wesp_ssh &
+               &                   * tmask(ji,jj,1)
+            zsshn_adin(ji,jj) = zsshn_tlout(ji,jj) &
+               &                   * e1t(ji,jj) * e2t(ji,jj) * wesp_ssh &
+               &                   * tmask(ji,jj,1)
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+      zsp1_1 = DOT_PRODUCT( zsshb_tlout, zsshb_adin )
+      zsp1_2 = DOT_PRODUCT( zsshn_tlout, zsshn_adin )
+
+      zsp1 = zsp1_1 + zsp1_2
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      sshb_ad(:,:) = zsshb_adin(:,:)
+      sshn_ad(:,:) = zsshn_adin(:,:)
+
+      CALL ssh_nxt_adj( nit000+1 )
+
+      zsshb_adout(:,:) = sshb_ad(:,:)
+      zsshn_adout(:,:) = sshn_ad(:,:)
+      zssha_adout(:,:) = ssha_ad(:,:)
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: dx^T L^T W dy
+      !--------------------------------------------------------------------
+
+      zsp2_1 = DOT_PRODUCT( zsshb_tlin,  zsshb_adout  )
+      zsp2_2 = DOT_PRODUCT( zsshn_tlin,  zsshn_adout  )
+      zsp2_3 = DOT_PRODUCT( zssha_tlin,  zssha_adout  )
+
+      zsp2 = zsp2_1 + zsp2_2 + zsp2_3
+
+      ! Compare the scalar products
+      ! 14 char:'12345678901234'
+      cl_name = 'sshnxt_adj    '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+   END SUBROUTINE ssh_nxt_adj_tst
+
+   !!======================================================================
+#endif
+
+END MODULE sshwzv_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/OBC/obcdyn_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/OBC/obcdyn_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/OBC/obcdyn_tam.F90	(revision 2578)
@@ -0,0 +1,601 @@
+MODULE obcdyn_tam
+#if defined key_obc
+   !!=================================================================================
+   !!                       ***  MODULE  obcdyn  ***
+   !! Ocean dynamics:   Radiation of velocities on each open boundary
+   !!=================================================================================
+
+   !!---------------------------------------------------------------------------------
+   !!   obc_dyn_tan        : call the subroutine for each open boundary
+   !!   obc_dyn_east_tan   : 
+   !!   obc_dyn_west_tan   : 
+   !!   obc_dyn_north_tan  : 
+   !!   obc_dyn_south_tan  : 
+   !!   obc_dyn_adj        : call the subroutine for each open boundary
+   !!   obc_dyn_east_adj   : 
+   !!   obc_dyn_west_adj   : 
+   !!   obc_dyn_north_adj  : 
+   !!   obc_dyn_south_adj  : 
+   !!----------------------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------------------
+   !! * Modules used
+   USE oce_tam,        ONLY : ub_tl, vb_tl, ua_tl, va_tl, & ! ocean dynamics and tracers
+        &                     ub_ad, vb_ad, ua_ad, va_ad
+   USE obc_oce
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE lbclnk          ! ???
+   USE lbclnk_tam,     ONLY : lbc_lnk_adj ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp         ! ???
+   USE in_out_manager  ! I/O manager
+   USE prtctl
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC obc_dyn_tan ! routine called in dynspg_flt
+   PUBLIC obc_dyn_adj ! routine called in dynspg_flt
+   PUBLIC obc_dyn_adj_tst
+
+   !! * Module variables
+   INTEGER ::   ji, jj, jk     ! dummy loop indices
+   LOGICAL ::   ll_fbc
+
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obc_dyn_tan ( kt )
+      !!------------------------------------------------------------------------------
+      !!                      SUBROUTINE obc_dyn
+      !!                     ********************
+      !! ** Purpose :
+      !!      Compute  dynamics (u,v) at the open boundaries.
+      !!      if defined key_dynspg_flt: 
+      !!                 this routine is called by dynspg_flt and updates
+      !!                 ua, va which are the actual velocities (not trends)
+      !!
+      !!      The logical variable lp_obc_east, and/or lp_obc_west, and/or lp_obc_north, 
+      !!      and/or lp_obc_south allow the user to determine which boundary is an
+      !!      open one (must be done in the param_obc.h90 file).
+      !!
+      !! ** Reference : 
+      !!      Marchesiello P., 1995, these de l'universite J. Fourier, Grenoble, France.
+      !!
+      !! History :
+      !!        !  95-03 (J.-M. Molines) Original, SPEM
+      !!        !  97-07 (G. Madec, J.-M. Molines) addition
+      !!   8.5  !  02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/OBC/obcdyn.F90,v 1.5 2005/12/28 09:25:07 opalod Exp $ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+      !!----------------------------------------------------------------------
+
+      ! 0. Local constant initialization
+      ! --------------------------------
+
+#if defined key_pomme_r025
+      ! Warning : TAM is available only for fixed boundary conditions (FBC)
+      ll_fbc = .true.
+#else
+      Error, OBC not ready.
+#endif
+
+# if defined key_dynspg_rl 
+      Error, this option is obsolete (suppressed after nemo_v3_2)
+# endif
+
+      IF( lp_obc_east  )   CALL obc_dyn_east_tan
+      IF( lp_obc_west  )   CALL obc_dyn_west_tan
+      IF( lp_obc_north )   CALL obc_dyn_north_tan
+      IF( lp_obc_south )   CALL obc_dyn_south_tan
+
+      IF( lk_mpp ) THEN
+         CALL lbc_lnk( ub_tl, 'U', -1. )
+         CALL lbc_lnk( vb_tl, 'V', -1. )
+         CALL lbc_lnk( ua_tl, 'U', -1. )
+         CALL lbc_lnk( va_tl, 'V', -1. )
+      ENDIF
+
+   END SUBROUTINE obc_dyn_tan
+
+   SUBROUTINE obc_dyn_adj ( kt )
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn_adj  ***
+      !!              
+      !! ** Purpose :
+      !!
+      !!  History :
+      !!         ! 
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+      !! * Local declaration
+      !!------------------------------------------------------------------------------
+
+#if defined key_pomme_r025
+      ! Warning : TAM is available only for fixed boundary conditions (FBC)
+      ll_fbc = .true.
+#else
+      Error, OBC not ready.
+#endif
+
+      IF( lk_mpp ) THEN
+         CALL lbc_lnk_adj( va_ad, 'V', -1. )
+         CALL lbc_lnk_adj( ua_ad, 'U', -1. )
+         CALL lbc_lnk_adj( vb_ad, 'V', -1. )
+         CALL lbc_lnk_adj( ub_ad, 'U', -1. )
+      ENDIF
+
+      IF( lp_obc_south )   CALL obc_dyn_south_adj
+      IF( lp_obc_north )   CALL obc_dyn_north_adj
+      IF( lp_obc_west  )   CALL obc_dyn_west_adj
+      IF( lp_obc_east  )   CALL obc_dyn_east_adj
+
+   END SUBROUTINE obc_dyn_adj
+
+   SUBROUTINE obc_dyn_east_tan
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn_east  ***
+      !!              
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on east OBC velocities ua, va using the 
+      !!      phase velocities calculated in obc_rad_east subroutine in obcrad.F90 module
+      !!      If the logical lfbceast is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!    9.0  ! 05-11  (V. Garnier) Surface pressure gradient organization
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbceast is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      WRITE(numout,*) 'verif passage dans obc_dyn_east_tan'
+      IF ( ll_fbc .OR. lfbceast ) THEN
+
+         ! 1.1 U zonal velocity    
+         ! --------------------
+         DO ji = nie0, nie1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ua_tl(ji,jj,jk) = ua_tl(ji,jj,jk) * ( 1. - uemsk(jj,jk) )
+               END DO
+            END DO
+         END DO
+
+         ! 1.2 V meridional velocity
+         ! -------------------------
+         DO ji = nie0+1, nie1+1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  va_tl(ji,jj,jk) = va_tl(ji,jj,jk) * ( 1. - vemsk(jj,jk) ) 
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obcdyn_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_dyn_east_tan
+
+   SUBROUTINE obc_dyn_east_adj
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn_east_adj  ***
+      !!              
+      !! ** Purpose :
+      !!
+      !!  History :
+      !!         ! 
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      !! * Local declaration
+      !!------------------------------------------------------------------------------
+      WRITE(numout,*) 'verif passage dans obc_dyn_east_adj'
+
+      IF ( ll_fbc .OR. lfbceast ) THEN
+
+         ! 1.2 V meridional velocity
+         ! -------------------------
+         DO ji = nie0+1, nie1+1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  va_ad(ji,jj,jk) = va_ad(ji,jj,jk) * ( 1. - vemsk(jj,jk) ) 
+               END DO
+            END DO
+         END DO
+
+         ! 1.1 U zonal velocity    
+         ! --------------------
+         DO ji = nie0, nie1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ua_ad(ji,jj,jk) = ua_ad(ji,jj,jk) * ( 1. - uemsk(jj,jk) )
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obcdyn_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_dyn_east_adj
+
+   SUBROUTINE obc_dyn_west_tan
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn_west  ***
+      !!                  
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on west OBC velocities ua, va using the 
+      !!      phase velocities calculated in obc_rad_west subroutine in obcrad.F90 module
+      !!      If the logical lfbcwest is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!    9.0  ! 05-11  (V. Garnier) Surface pressure gradient organization
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcwest is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF ( ll_fbc .OR. lfbcwest ) THEN
+
+         ! 1.1 U zonal velocity
+         ! ---------------------
+         DO ji = niw0, niw1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ua_tl(ji,jj,jk) = ua_tl(ji,jj,jk) * ( 1. - uwmsk(jj,jk) ) 
+               END DO
+            END DO
+         END DO
+
+         ! 1.2 V meridional velocity
+         ! -------------------------
+         DO ji = niw0, niw1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  va_tl(ji,jj,jk) = va_tl(ji,jj,jk) * ( 1. - vwmsk(jj,jk) )
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obcdyn_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_dyn_west_tan
+
+   SUBROUTINE obc_dyn_west_adj
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn_west_adj  ***
+      !!              
+      !! ** Purpose :
+      !!
+      !!  History :
+      !!         ! 
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      !! * Local declaration
+      !!------------------------------------------------------------------------------
+      IF ( ll_fbc .OR. lfbcwest ) THEN
+
+         ! 1.2 V meridional velocity
+         ! -------------------------
+         DO ji = niw0, niw1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  va_ad(ji,jj,jk) = va_ad(ji,jj,jk) * ( 1. - vwmsk(jj,jk) )
+               END DO
+            END DO
+         END DO
+         ! 1.1 U zonal velocity
+         ! ---------------------
+         DO ji = niw0, niw1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ua_ad(ji,jj,jk) = ua_ad(ji,jj,jk) * ( 1. - uwmsk(jj,jk) ) 
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obcdyn_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_dyn_west_adj
+
+   SUBROUTINE obc_dyn_north_tan
+      !!------------------------------------------------------------------------------
+      !!                     SUBROUTINE obc_dyn_north
+      !!                    *************************
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on north OBC velocities ua, va using the 
+      !!      phase velocities calculated in obc_rad_north subroutine in obcrad.F90 module
+      !!      If the logical lfbcnorth is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!    9.0  ! 05-11  (V. Garnier) Surface pressure gradient organization
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcnorth is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! ---------------------------------------------------------
+ 
+        IF ( ll_fbc .OR. lfbcnorth ) THEN
+    
+         ! 1.1 U zonal velocity
+         ! --------------------
+         DO jj = njn0+1, njn1+1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ua_tl(ji,jj,jk) = ua_tl(ji,jj,jk) * ( 1. - unmsk(ji,jk) )
+               END DO
+            END DO
+         END DO
+
+         ! 1.2 V meridional velocity
+         ! -------------------------
+         DO jj = njn0, njn1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  va_tl(ji,jj,jk)= va_tl(ji,jj,jk) * ( 1. - vnmsk(ji,jk) )
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obcdyn_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_dyn_north_tan
+
+   SUBROUTINE obc_dyn_north_adj
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn_north_adj  ***
+      !!              
+      !! ** Purpose :
+      !!
+      !!  History :
+      !!         ! 
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      !! * Local declaration
+      !!------------------------------------------------------------------------------
+        IF ( ll_fbc .OR. lfbcnorth ) THEN
+    
+         ! 1.2 V meridional velocity
+         ! -------------------------
+         DO jj = njn0, njn1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  va_ad(ji,jj,jk)= va_ad(ji,jj,jk) * ( 1. - vnmsk(ji,jk) )
+               END DO
+            END DO
+         END DO
+
+         ! 1.1 U zonal velocity
+         ! --------------------
+         DO jj = njn0+1, njn1+1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ua_ad(ji,jj,jk) = ua_ad(ji,jj,jk) * ( 1. - unmsk(ji,jk) )
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obcdyn_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_dyn_north_adj
+
+   SUBROUTINE obc_dyn_south_tan
+      !!------------------------------------------------------------------------------
+      !!                     SUBROUTINE obc_dyn_south
+      !!                    *************************
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on south OBC velocities ua, va using the 
+      !!      phase velocities calculated in obc_rad_south subroutine in obcrad.F90 module
+      !!      If the logical lfbcsouth is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!    9.0  ! 05-11  (V. Garnier) Surface pressure gradient organization
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcsouth is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! ---------------------------------------------------------
+
+      IF ( ll_fbc .OR. lfbcsouth ) THEN
+      
+         ! 1.1 U zonal velocity
+         ! --------------------
+         DO jj = njs0, njs1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ua_tl(ji,jj,jk) = ua_tl(ji,jj,jk) * ( 1. - usmsk(ji,jk) )
+               END DO
+            END DO
+         END DO
+
+         ! 1.2 V meridional velocity
+         ! -------------------------
+         DO jj = njs0, njs1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  va_tl(ji,jj,jk) = va_tl(ji,jj,jk) * ( 1. - vsmsk(ji,jk) )
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obcdyn_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_dyn_south_tan
+
+   SUBROUTINE obc_dyn_south_adj
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn_south_adj  ***
+      !!              
+      !! ** Purpose :
+      !!
+      !!  History :
+      !!         ! 
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      !! * Local declaration
+      !!------------------------------------------------------------------------------
+      IF ( ll_fbc .OR. lfbcsouth ) THEN
+      
+         ! 1.2 V meridional velocity
+         ! -------------------------
+         DO jj = njs0, njs1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  va_ad(ji,jj,jk) = va_ad(ji,jj,jk) * ( 1. - vsmsk(ji,jk) )
+               END DO
+            END DO
+         END DO
+
+         ! 1.1 U zonal velocity
+         ! --------------------
+         DO jj = njs0, njs1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ua_ad(ji,jj,jk) = ua_ad(ji,jj,jk) * ( 1. - usmsk(ji,jk) )
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obcdyn_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_dyn_south_adj
+
+
+   SUBROUTINE obc_dyn_adj_tst( kumadt )
+
+     USE gridrandom, ONLY : grid_rd_sd
+     USE tstool_tam, ONLY : prntst_adj, stdu, stdv
+     USE dotprodfld, ONLY : dot_product  ! Computes dot product for 3D and 2D fields
+
+     INTEGER, INTENT(IN) ::  kumadt        ! Output unit
+     REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  &
+          zua_tlin,  zva_tlin,  zua_adin,  zva_adin, z3r
+     REAL(wp) ::  zspdx, zspdy
+     CHARACTER (LEN=14) ::  cl_name
+
+     ! ... Allocate memory
+     ALLOCATE(  zua_tlin (jpi,jpj,jpk), zva_tlin(jpi,jpj,jpk), &
+                zua_adin (jpi,jpj,jpk), zva_adin(jpi,jpj,jpk), &
+                z3r(jpi,jpj,jpk)  ) 
+     
+     ! ... Initialisations
+     zua_tlin(:,:,:) = 0.e0  ;   zua_adin(:,:,:) = 0.e0
+     zva_tlin(:,:,:) = 0.e0  ;   zva_adin(:,:,:) = 0.e0
+
+     ! ... Define random working arrays
+     CALL grid_rd_sd( 456953, z3r,  'U', 0.0_wp, stdu)
+     DO jk = 1, jpk ; DO jj = nldj, nlej ; DO ji = nldi, nlei
+        zua_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+     END DO ; END DO ; END DO
+     
+     CALL grid_rd_sd( 3434334, z3r, 'V', 0.0_wp, stdv)
+     DO jk = 1, jpk ; DO jj = nldj, nlej ; DO ji = nldi, nlei
+        zva_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+     END DO ; END DO ; END DO
+
+     ! ... Initialize the tangent variables
+     ua_tl(:,:,:) = zua_tlin(:,:,:)   ;   ub_tl(:,:,:) = 0.e0
+     va_tl(:,:,:) = zva_tlin(:,:,:)   ;   vb_tl(:,:,:) = 0.e0
+
+     ! ... Call the tangent routine
+     CALL obc_dyn_tan( nit000 )
+ 
+     ! ... Initialize the adjoint variables
+     zua_adin(:,:,:) = 1. * ua_tl(:,:,:)
+     zva_adin(:,:,:) = 1. * va_tl(:,:,:)
+
+     ! ... Calculate the scalar product for the output
+     zspdy = DOT_PRODUCT( ua_tl, zua_adin ) &
+           + DOT_PRODUCT( va_tl, zva_adin ) 
+
+     ! ... Call the adjoint routine
+     ua_ad(:,:,:) = zua_adin(:,:,:)   ;   ub_ad(:,:,:) = 0.e0
+     va_ad(:,:,:) = zva_adin(:,:,:)   ;   vb_ad(:,:,:) = 0.e0
+
+     CALL obc_dyn_adj( nit000 )
+
+     ! ... Calculate the scalar product for the input
+     zspdx = DOT_PRODUCT( zua_tlin, ua_ad ) &
+           + DOT_PRODUCT( zva_tlin, va_ad ) 
+
+     ! ... Diagnostic write
+     !    14 char:'12345678901234'
+     cl_name =    'obcdyn_tam    '
+     CALL prntst_adj( cl_name, kumadt, zspdx, zspdy )
+
+   END SUBROUTINE obc_dyn_adj_tst
+#else
+   !!=================================================================================
+   !!                       ***  MODULE  obcdyn  ***
+   !! Ocean dynamics:   Radiation of velocities on each open boundary
+   !!=================================================================================
+CONTAINS
+   SUBROUTINE obc_dyn_tan                              ! No open boundaries ==> empty routine
+   END SUBROUTINE obc_dyn_tan
+   SUBROUTINE obc_dyn_adj                              ! No open boundaries ==> empty routine
+   END SUBROUTINE obc_dyn_adj
+   SUBROUTINE obc_dyn_adj_tst
+   END SUBROUTINE obc_dyn_adj_tst
+#endif
+
+END MODULE obcdyn_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/OBC/obctra_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/OBC/obctra_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/OBC/obctra_tam.F90	(revision 2578)
@@ -0,0 +1,398 @@
+MODULE obctra_tam
+   !!=================================================================================
+   !!                       ***  MODULE  obctra  ***
+   !! Ocean tracers:   Radiation of tracers on each open boundary
+   !!=================================================================================
+#if defined key_obc
+   !!---------------------------------------------------------------------------------
+   !!   'key_obc'      :                                      Open Boundary Conditions
+   !!---------------------------------------------------------------------------------
+   !!   obc_tra_tan        : call the subroutine for each open boundary
+   !!   obc_tra_east_tan   : 
+   !!   obc_tra_west_tan   : 
+   !!   obc_tra_north_tan  : 
+   !!   obc_tra_south_tan  : 
+   !!   obc_tra_adj        : call the subroutine for each open boundary
+   !!   obc_tra_east_adj   : 
+   !!   obc_tra_west_adj   : 
+   !!   obc_tra_north_adj  : 
+   !!   obc_tra_south_adj  : 
+   !!----------------------------------------------------------------------------------
+   !! * Modules used
+   USE oce_tam,         ONLY : tb_tl, sb_tl, ta_tl, sa_tl, & ! ocean dynamics and tracers
+        &                      tb_ad, sb_ad, ta_ad, sa_ad
+   USE dom_oce         ! ocean space and time domain variables 
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE lib_mpp         ! ???
+   USE lbclnk          ! ???
+   USE lbclnk_tam,      ONLY : lbc_lnk_adj ! TAM lateral boundary conditions
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC obc_tra_tan     ! routine called in tranxt.F90 
+   PUBLIC obc_tra_adj     ! routine called in tranxt.F90 
+
+   !! * Module variables
+   LOGICAL  ::   ll_fbc
+
+   
+   !! * Substitutions
+#  include "obc_vectopt_loop_substitute.h90"
+   !!---------------------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/OBC/obctra.F90,v 1.4 2005/03/27 18:35:10 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obc_tra_tan( kt )
+      !!-------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE obc_tra  ***
+      !!                    
+      !! ** Purpose :   Compute tracer fields (t,s) along the open boundaries.
+      !!      This routine is called by the tranxt.F routine and updates ta,sa
+      !!      which are the actual temperature and salinity fields.
+      !!        The logical variable lp_obc_east, and/or lp_obc_west, and/or lp_obc_north,
+      !!      and/or lp_obc_south allow the user to determine which boundary is an
+      !!      open one (must be done in the param_obc.h90 file).
+      !!
+      !! Reference : 
+      !!   Marchesiello P., 1995, these de l'universite J. Fourier, Grenoble, France.
+      !!
+      !!  History :
+      !!        !  95-03 (J.-M. Molines) Original, SPEM
+      !!        !  97-07 (G. Madec, J.-M. Molines) addition
+      !!   8.5  !  02-10 (C. Talandier, A-M. Treguier) F90
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+      !!----------------------------------------------------------------------
+
+      ! 0. Local constant initialization
+
+#if defined key_pomme_r025
+      ! Warning : TAM is available only for fixed boundary conditions (FBC)
+      ll_fbc = .true.
+#else
+      Error, OBC not ready.
+#endif
+
+!    Remove the dependance on kt to avoid compilation warnings
+      IF( lp_obc_east  )   CALL obc_tra_east_tan     ! East open boundary
+      IF( lp_obc_west  )   CALL obc_tra_west_tan     ! West open boundary
+      IF( lp_obc_north )   CALL obc_tra_north_tan    ! North open boundary
+      IF( lp_obc_south )   CALL obc_tra_south_tan    ! South open boundary
+
+      IF( lk_mpp ) THEN
+         CALL lbc_lnk( ta_tl, 'T', 1. )
+         CALL lbc_lnk( sa_tl, 'T', 1. )
+      ENDIF
+
+   END SUBROUTINE obc_tra_tan
+
+   SUBROUTINE obc_tra_adj( kt )
+      !!                 ***  SUBROUTINE obc_tra  ***
+      INTEGER, INTENT( in ) ::   kt
+#if defined key_pomme_r025
+      ! Warning : TAM is available only for fixed boundary conditions (FBC)
+      ll_fbc = .true.
+#else
+      Error, OBC not ready.
+#endif
+
+      IF( lk_mpp ) THEN
+         CALL lbc_lnk_adj( sa_ad, 'T', 1. )
+         CALL lbc_lnk_adj( ta_ad, 'T', 1. )
+      ENDIF
+
+      IF( lp_obc_south )   CALL obc_tra_south_adj    ! South open boundary
+      IF( lp_obc_north )   CALL obc_tra_north_adj    ! North open boundary
+      IF( lp_obc_west  )   CALL obc_tra_west_adj     ! West open boundary
+      IF( lp_obc_east  )   CALL obc_tra_east_adj     ! East open boundary
+
+   END SUBROUTINE obc_tra_adj
+
+   SUBROUTINE obc_tra_east_tan
+      !!------------------------------------------------------------------------------
+      !!                ***  SUBROUTINE obc_tra_east  ***
+      !!                  
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on east OBC tracers ta, sa using the 
+      !!      phase velocities calculated in obc_rad_east subroutine in obcrad.F90 module
+      !!      If the logical lfbceast is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+      !!------------------------------------------------------------------------------
+      ! 1. First three time steps and more if lfbceast is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF ( ll_fbc .OR. lfbceast ) THEN
+
+        DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) * (1. - temsk(jj,jk))
+                  sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) * (1. - temsk(jj,jk))
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obctra_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_tra_east_tan
+
+   SUBROUTINE obc_tra_east_adj
+      !!                ***  SUBROUTINE obc_tra_east  ***
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+      IF ( ll_fbc .OR. lfbceast ) THEN
+
+        DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ta_ad(ji,jj,jk) = ta_ad(ji,jj,jk) * (1. - temsk(jj,jk))
+                  sa_ad(ji,jj,jk) = sa_ad(ji,jj,jk) * (1. - temsk(jj,jk))
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obctra_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_tra_east_adj
+
+   SUBROUTINE obc_tra_west_tan
+      !!------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE obc_tra_west  ***
+      !!           
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on west OBC tracers ta, sa using the 
+      !!      phase velocities calculated in obc_rad_west subroutine in obcrad.F90 module
+      !!      If the logical lfbcwest is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcwest is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF ( ll_fbc .OR. lfbcwest ) THEN
+
+         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) * (1. - twmsk(jj,jk))
+                  sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) * (1. - twmsk(jj,jk))
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obctra_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_tra_west_tan
+
+   SUBROUTINE obc_tra_west_adj
+      !!                 ***  SUBROUTINE obc_tra_west  ***
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+      IF ( ll_fbc .OR. lfbcwest ) THEN
+
+         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ta_ad(ji,jj,jk) = ta_ad(ji,jj,jk) * (1. - twmsk(jj,jk))
+                  sa_ad(ji,jj,jk) = sa_ad(ji,jj,jk) * (1. - twmsk(jj,jk))
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obctra_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_tra_west_adj
+
+   SUBROUTINE obc_tra_north_tan
+      !!------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE obc_tra_north  ***
+      !!
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on north OBC tracers ta, sa using the 
+      !!      phase velocities calculated in obc_rad_north subroutine in obcrad.F90 module
+      !!      If the logical lfbcnorth is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcnorth is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF ( ll_fbc .OR. lfbcnorth ) THEN
+
+         DO jj = fs_njn0+1, fs_njn1+1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ta_tl(ji,jj,jk)= ta_tl(ji,jj,jk) * (1.-tnmsk(ji,jk)) 
+                  sa_tl(ji,jj,jk)= sa_tl(ji,jj,jk) * (1.-tnmsk(ji,jk)) 
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obctra_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_tra_north_tan
+
+   SUBROUTINE obc_tra_north_adj
+      !!                 ***  SUBROUTINE obc_tra_north  ***
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+
+      IF ( ll_fbc .OR. lfbcnorth ) THEN
+
+         DO jj = fs_njn0+1, fs_njn1+1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ta_ad(ji,jj,jk)= ta_ad(ji,jj,jk) * (1.-tnmsk(ji,jk)) 
+                  sa_ad(ji,jj,jk)= sa_ad(ji,jj,jk) * (1.-tnmsk(ji,jk)) 
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obctra_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF
+
+   END SUBROUTINE obc_tra_north_adj
+
+   SUBROUTINE obc_tra_south_tan
+      !!------------------------------------------------------------------------------
+      !!                ***  SUBROUTINE obc_tra_south  ***
+      !!     
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on south OBC tracers ta, sa using the 
+      !!      phase velocities calculated in obc_rad_south subroutine in obcrad.F90 module
+      !!      If the logical lfbcsouth is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M Treguier) F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcsouth is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF ( ll_fbc .OR. lfbcsouth ) THEN
+
+         DO jj = fs_njs0, fs_njs1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ta_tl(ji,jj,jk)= ta_tl(ji,jj,jk) * (1.-tsmsk(ji,jk))
+                  sa_tl(ji,jj,jk)= sa_tl(ji,jj,jk) * (1.-tsmsk(ji,jk))
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obctra_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF   
+
+   END SUBROUTINE obc_tra_south_tan
+
+   SUBROUTINE obc_tra_south_adj
+      !!                ***  SUBROUTINE obc_tra_south  ***
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+
+      IF ( ll_fbc .OR. lfbcsouth ) THEN
+
+         DO jj = fs_njs0, fs_njs1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ta_ad(ji,jj,jk)= ta_ad(ji,jj,jk) * (1.-tsmsk(ji,jk))
+                  sa_ad(ji,jj,jk)= sa_ad(ji,jj,jk) * (1.-tsmsk(ji,jk))
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+         CALL ctl_stop( 'Error in obctra_tam : TAM is available only for fixed boundary conditions' )
+
+      END IF   
+
+   END SUBROUTINE obc_tra_south_adj
+
+#else
+   !!---------------------------------------------------------------------------------
+   !!   Default option                                                    Empty module
+   !!---------------------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE obc_tra_tan      ! Empty routine
+   END SUBROUTINE obc_tra_tan
+   SUBROUTINE obc_tra_adj
+   END SUBROUTINE obc_tra_adj
+
+#endif
+
+   !!=================================================================================
+END MODULE obctra_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbc_oce_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbc_oce_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbc_oce_tam.F90	(revision 2578)
@@ -0,0 +1,408 @@
+MODULE sbc_oce_tam
+   !!----------------------------------------------------------------------
+   !!    This software is governed by the CeCILL licence (Version 2)
+   !!----------------------------------------------------------------------
+#if defined key_tam
+   !!======================================================================
+   !!                       ***  MODULE  sbc_oce_tam  ***
+   !! Surface module :   variables defined in core memory 
+   !!                    Tangent and Adjoint Module
+   !!======================================================================
+   !! History of the direct module:
+   !!            3.0   !  2006-06  (G. Madec)  Original code
+   !!             -    !  2008-08  (G. Madec)  namsbc moved from sbcmod
+   !! History of the TAM module:
+   !!            3.0   !  2008-11  (A. Vidard)  Original code
+   !!            3.0   !  2009-03  (A. Weaver)  Allocate/initialization routine
+   !!            3.2   !  2010-04  (A. Vidard)  3.2 update
+   !!----------------------------------------------------------------------
+   USE par_kind, ONLY : &       ! Precision variables
+      & wp
+   USE par_oce, ONLY : &        ! Ocean space and time domain variables
+      & jpi,   &
+      & jpj
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+
+   PUBLIC &
+      & sbc_oce_tam_init,      & !: Initialize the TAM fields
+      & sbc_oce_tam_deallocate   !: Initialize the TAM fields
+
+   !!----------------------------------------------------------------------
+   !!              Ocean Surface Boundary Condition fields
+   !!----------------------------------------------------------------------
+   REAL(wp), PUBLIC, DIMENSION(:,:), ALLOCATABLE :: &
+      & utau_tl, & !: Tangent linear of sea surface i-stress (ocean referential)     [N/m2]
+      & vtau_tl, & !: Tangent linear of sea surface j-stress (ocean referential)     [N/m2]
+      & taum_tl, & !: Tangent linear of module of sea surface stress (at T-point)    [N/m2]
+      & wndm_tl, & !: Tangent linear of wind speed module at T-point (=|U10m-Uoce|)  [m/s
+      & qns_tl,  & !: Tangent linear of sea heat flux: non solar                     [W/m2]
+      & qsr_tl,  & !: Tangent linear of sea heat flux:     solar                     [W/m2]
+      & qns_tot_tl,  & !: Tangent linear of total sea heat flux: non solar                     [W/m2]
+      & qsr_tot_tl,  & !: Tangent linear of total sea heat flux:     solar                     [W/m2]
+      & emp_tl,  & !: Tangent linear of freshwater budget: volume flux               [Kg/m2/s]
+      & emps_tl, & !: Tangent linear of freshwater budget: concentration/dillution   [Kg/m2/s]
+      & fr_i_tl    !: Tangent linear of ice fraction  (between 0 to 1)               -
+#if defined key_cpl_carbon_cycle
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   atm_co2_tl   !: tangent of atmospheric pCO2                             [ppm]
+#endif
+
+   REAL(wp), PUBLIC, DIMENSION(:,:), ALLOCATABLE :: &
+      & utau_ad, & !: Adjoint of sea surface i-stress (ocean referential)     [N/m2]
+      & vtau_ad, & !: Adjoint of sea surface j-stress (ocean referential)     [N/m2]
+      & taum_ad, & !: Adjoint of module of sea surface stress (at T-point)    [N/m2]
+      & wndm_ad, & !: Adjoint of wind speed module at T-point (=|U10m-Uoce|)  [m/s]
+      & qns_ad,  & !: Adjoint of sea heat flux: non solar                     [W/m2
+      & qsr_ad,  & !: Adjoint of sea heat flux:     solar                     [W/m2]
+      & qns_tot_ad,  & !: Adjoint of total sea heat flux: non solar                     [W/m2
+      & qsr_tot_ad,  & !: Adjoint of total sea heat flux:     solar                     [W/m2]
+      & emp_ad,  & !: Adjoint of freshwater budget: volume flux               [Kg/m2/s]
+      & emps_ad, & !: Adjoint of freshwater budget: concentration/dillution   [Kg/m2/s]
+      & fr_i_ad    !: Adjoint of ice fraction  (between 0 to 1)               -
+#if defined key_cpl_carbon_cycle
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   atm_co2_ad   !: adjoint of atmospheric pCO2                             [ppm]
+#endif
+
+   !!----------------------------------------------------------------------
+   !!                     Sea Surface Mean fields
+   !!----------------------------------------------------------------------
+   REAL(wp), PUBLIC,  DIMENSION(:,:), ALLOCATABLE :: &
+      & ssu_m_tl, & !: mean (nn_fsbc time-step) surface sea i-current (U-point) [m/s]
+      & ssv_m_tl, & !: mean (nn_fsbc time-step) surface sea j-current (V-point) [m/s]
+      & sst_m_tl, & !: mean (nn_fsbc time-step) surface sea temperature     [Celsius]
+      & sss_m_tl, & !: mean (nn_fsbc time-step) surface sea salinity            [psu]
+      & ssh_m_tl    !: mean (nn_fsbc time-step) surface sea height                [m]
+                    
+   REAL(wp), PUBLIC,  DIMENSION(:,:), ALLOCATABLE :: &
+      & ssu_m_ad, & !: mean (nn_fsbc time-step) surface sea i-current (U-point) [m/s]
+      & ssv_m_ad, & !: mean (nn_fsbc time-step) surface sea j-current (V-point) [m/s]
+      & sst_m_ad, & !: mean (nn_fsbc time-step) surface sea temperature     [Celsius]
+      & sss_m_ad, & !: mean (nn_fsbc time-step) surface sea salinity            [psu]
+      & ssh_m_ad    !: mean (nn_fsbc time-step) surface sea height                [m]
+
+CONTAINS
+
+   SUBROUTINE sbc_oce_tam_init( kindic )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE sbc_oce_tam_init  ***
+      !!
+      !! ** Purpose : Allocate and initialize the tangent linear and 
+      !!              adjoint arrays
+      !!
+      !! ** Method  : kindic = 0  allocate/initialize both tl and ad variables
+      !!              kindic = 1  allocate/initialize only tl variables
+      !!              kindic = 2  allocate/initialize only ad variables
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 2009-03 (A. Weaver) Initial version (based on oce_tam_init)
+      !!        ! 2010-04 (A. Vidard) Nemo3.2 update 
+      !!-----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kindic        ! indicate which variables to allocate/initialize
+
+      !! * Local declarations
+      
+      ! Allocate tangent linear variable arrays
+      ! ---------------------------------------
+      
+      IF ( kindic == 0 .OR. kindic == 1 ) THEN
+
+         IF ( .NOT. ALLOCATED(utau_tl) ) THEN
+
+            ALLOCATE( utau_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(vtau_tl) ) THEN
+
+            ALLOCATE( vtau_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(taum_tl) ) THEN
+
+            ALLOCATE( taum_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(wndm_tl) ) THEN
+
+            ALLOCATE( wndm_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(qns_tl) ) THEN
+
+            ALLOCATE( qns_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(qsr_tl) ) THEN
+
+            ALLOCATE( qsr_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(qns_tot_tl) ) THEN
+
+            ALLOCATE( qns_tot_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(qsr_tot_tl) ) THEN
+
+            ALLOCATE( qsr_tot_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(emp_tl) ) THEN
+
+            ALLOCATE( emp_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(emps_tl) ) THEN
+
+            ALLOCATE( emps_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(fr_i_tl) ) THEN
+
+            ALLOCATE( fr_i_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(ssu_m_tl) ) THEN
+
+            ALLOCATE( ssu_m_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(ssv_m_tl) ) THEN
+
+            ALLOCATE( ssv_m_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(sst_m_tl) ) THEN
+
+            ALLOCATE( sst_m_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(sss_m_tl) ) THEN
+
+            ALLOCATE( sss_m_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(ssh_m_tl) ) THEN
+
+            ALLOCATE( ssh_m_tl(jpi,jpj) )
+            
+         ENDIF
+
+         ! Initialize tangent linear variable arrays to zero
+         ! -------------------------------------------------
+
+         utau_tl (:,:) = 0.0_wp
+         vtau_tl (:,:) = 0.0_wp
+         taum_tl (:,:) = 0.0_wp
+         wndm_tl (:,:) = 0.0_wp
+         qns_tl  (:,:) = 0.0_wp
+         qsr_tl  (:,:) = 0.0_wp
+         qns_tot_tl  (:,:) = 0.0_wp
+         qsr_tot_tl  (:,:) = 0.0_wp
+         emp_tl  (:,:) = 0.0_wp
+         emps_tl (:,:) = 0.0_wp
+         fr_i_tl (:,:) = 0.0_wp
+         ssu_m_tl(:,:) = 0.0_wp
+         ssv_m_tl(:,:) = 0.0_wp
+         sst_m_tl(:,:) = 0.0_wp
+         sss_m_tl(:,:) = 0.0_wp
+         ssh_m_tl(:,:) = 0.0_wp
+
+      ENDIF
+
+      IF ( kindic == 0 .OR. kindic == 2 ) THEN
+
+         ! Allocate adjoint variable arrays
+         ! --------------------------------
+      
+         IF ( .NOT. ALLOCATED(utau_ad) ) THEN
+
+            ALLOCATE( utau_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(vtau_ad) ) THEN
+
+            ALLOCATE( vtau_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(taum_ad) ) THEN
+
+            ALLOCATE( taum_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(wndm_ad) ) THEN
+
+            ALLOCATE( wndm_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(qns_ad) ) THEN
+
+            ALLOCATE( qns_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(qsr_ad) ) THEN
+
+            ALLOCATE( qsr_ad(jpi,jpj) )
+            
+         ENDIF
+          IF ( .NOT. ALLOCATED(qns_tot_ad) ) THEN
+
+            ALLOCATE( qns_tot_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(qsr_tot_ad) ) THEN
+
+            ALLOCATE( qsr_tot_ad(jpi,jpj) )
+            
+         ENDIF
+        IF ( .NOT. ALLOCATED(emp_ad) ) THEN
+
+            ALLOCATE( emp_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(emps_ad) ) THEN
+
+            ALLOCATE( emps_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(fr_i_ad) ) THEN
+
+            ALLOCATE( fr_i_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(ssu_m_ad) ) THEN
+
+            ALLOCATE( ssu_m_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(ssv_m_ad) ) THEN
+
+            ALLOCATE( ssv_m_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(sst_m_ad) ) THEN
+
+            ALLOCATE( sst_m_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(sss_m_ad) ) THEN
+
+            ALLOCATE( sss_m_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(ssh_m_ad) ) THEN
+
+            ALLOCATE( ssh_m_ad(jpi,jpj) )
+            
+         ENDIF
+
+         ! Initialize adjoint variable arrays to zero
+         ! ------------------------------------------
+
+         utau_ad (:,:) = 0.0_wp
+         vtau_ad (:,:) = 0.0_wp
+         taum_ad (:,:) = 0.0_wp
+         wndm_ad (:,:) = 0.0_wp
+         qns_ad  (:,:) = 0.0_wp
+         qsr_ad  (:,:) = 0.0_wp
+         qns_tot_ad  (:,:) = 0.0_wp
+         qsr_tot_ad  (:,:) = 0.0_wp
+         emp_ad  (:,:) = 0.0_wp
+         emps_ad (:,:) = 0.0_wp
+         fr_i_ad (:,:) = 0.0_wp
+         ssu_m_ad(:,:) = 0.0_wp
+         ssv_m_ad(:,:) = 0.0_wp
+         sst_m_ad(:,:) = 0.0_wp
+         sss_m_ad(:,:) = 0.0_wp
+         ssh_m_ad(:,:) = 0.0_wp
+
+      ENDIF
+
+   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(taum_tl) )    DEALLOCATE( taum_tl )
+         IF ( ALLOCATED(wndm_tl) )    DEALLOCATE( wndm_tl )
+         IF ( ALLOCATED(qns_tl) )     DEALLOCATE( qns_tl )
+         IF ( ALLOCATED(qsr_tl) )     DEALLOCATE( qsr_tl )
+         IF ( ALLOCATED(qns_tot_tl) ) DEALLOCATE( qns_tot_tl )
+         IF ( ALLOCATED(qsr_tot_tl) ) DEALLOCATE( qsr_tot_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 )
+         IF ( ALLOCATED(ssh_m_tl) )   DEALLOCATE( ssh_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(taum_ad) )    DEALLOCATE( taum_ad )
+         IF ( ALLOCATED(wndm_ad) )    DEALLOCATE( wndm_ad )
+         IF ( ALLOCATED(qns_ad) )     DEALLOCATE( qns_ad )
+         IF ( ALLOCATED(qsr_ad) )     DEALLOCATE( qsr_ad )
+         IF ( ALLOCATED(qns_tot_ad) ) DEALLOCATE( qns_tot_ad )
+         IF ( ALLOCATED(qsr_tot_ad) ) DEALLOCATE( qsr_tot_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 )
+         IF ( ALLOCATED(ssh_m_ad) )   DEALLOCATE( ssh_m_ad )
+         
+      ENDIF
+
+   END SUBROUTINE sbc_oce_tam_deallocate
+#endif
+
+END MODULE sbc_oce_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcana_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcana_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcana_tam.F90	(revision 2578)
@@ -0,0 +1,572 @@
+MODULE sbcana_tam
+#if defined key_tam
+   !!======================================================================
+   !!                       ***  MODULE  sbcana  ***
+   !! Ocean forcing:  analytical momentum, heat and freshwater forcings
+   !!=====================================================================
+   !! History of the direct module :  
+   !!            3.0   ! 2006-06  (G. Madec)  Original code
+   !!            3.2   ! 2009-07  (G. Madec)  Style only
+   !! History of the T&A module :
+   !!            3.0   ! 2009-10  (F. Vigilant) original verison
+   !!            3.2   ! 2020-04  (A. Vidard) nemo 3.2 update
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   sbc_ana  : set an analytical ocean forcing
+   !!   sbc_gyre : set the GYRE configuration analytical forcing
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! 
+      & wp
+   USE oce_tam       , ONLY: & ! ocean dynamics and tracers
+      & tb_tl,             &
+      & tb_ad
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 &
+      & jpk,                 &
+      & jpiglo
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & e1t,                 &
+      & e2t,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3t,                 &
+#endif
+      & tmask,               &
+      & tmask_i,             &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              &
+      & numnam,              &
+      & nbench,              &
+      & nbit_cmp,            & 
+      & nit000,              & 
+      & nitend
+   USE lib_mpp       , ONLY: & ! distributed memory computing
+      & lk_mpp,              &
+      & mpp_sum
+   USE sbc_oce_tam   , ONLY: & ! surface variables
+      & emp_tl,              &
+      & emps_tl,             &
+      & emp_ad,              &
+      & emps_ad,             &
+      & qsr_tl,              & ! thermohaline fluxes
+      & qsr_ad,              &
+      & qns_tl,              &
+      & qns_ad,              &
+      & utau_tl,             &
+      & utau_ad,             &
+      & vtau_tl,             &
+      & vtau_ad,             &
+      & taum_tl,             &
+      & taum_ad,             &
+      & wndm_tl,             &
+      & wndm_ad
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          &
+      & stdemp,              & !   evaporation minus precip
+      & stdt                 !   sea surface height
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   sbc_ana_tan        ! routine called sbcmod_tam
+   PUBLIC   sbc_ana_adj        ! routine called sbcmod_tam
+   PUBLIC   sbc_gyre_tan       ! routine called sbcmod_tam
+   PUBLIC   sbc_gyre_adj       ! routine called sbcmod_tam
+   PUBLIC   sbc_gyre_adj_tst   ! routine called by tst
+
+   !! * Namelist namsbc_ana
+   INTEGER  ::   nn_tau000 = 1      ! nb of time-step during which the surface stress
+      !                             ! increase from 0 to its nominal value 
+   REAL(wp) ::   rn_utau0  = 0.e0   ! constant wind stress value in i-direction
+   REAL(wp) ::   rn_vtau0  = 0.e0   ! constant wind stress value in j-direction
+   REAL(wp) ::   rn_qns0   = 0.e0   ! non solar heat flux
+   REAL(wp) ::   rn_qsr0   = 0.e0   !     solar heat flux
+   REAL(wp) ::   rn_emp0   = 0.e0   ! net freshwater flux
+ 
+   REAL(wp) ::   rhoa      = 1.22   ! Air density kg/m3
+   REAL(wp) ::   cdrag     = 1.5e-3 ! drag coefficient
+  
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE sbc_ana_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE sbc_ana_tan ***
+      !!              
+      !! ** Purpose :   provide at each time-step the ocean surface boundary
+      !!              condition, i.e. the momentum, heat and freshwater fluxes.
+      !!
+      !! ** Method  :   Constant and uniform surface forcing specified from
+      !!              namsbc_ana namelist parameters. All the fluxes are time
+      !!              independant except the stresses which increase from zero
+      !!              during the first nn_tau000 time-step 
+      !!                CAUTION : never mask the surface stress field !
+      !!
+      !! ** Action  : - set the ocean surface boundary condition, i.e.  
+      !!                   utau, vtau, taum, wndm, qns, qsr, emp, emps
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt       ! ocean time step
+      !!
+      NAMELIST/namsbc_ana/ nn_tau000, rn_utau0, rn_vtau0, rn_qns0, rn_qsr0, rn_emp0
+      !!---------------------------------------------------------------------
+      !
+      IF( kt == nit000 ) THEN
+         !
+         REWIND ( numnam )                   ! Read Namelist namsbc : surface fluxes
+         READ   ( numnam, namsbc_ana )
+         !
+         IF(lwp) WRITE(numout,*)' '
+         IF(lwp) WRITE(numout,*)' sbc_ana_tan : Constant surface fluxes read in namsbc_ana namelist'
+         IF(lwp) WRITE(numout,*)' ~~~~~~~ '
+         IF(lwp) WRITE(numout,*)'              spin up of the stress  nn_tau000 = ', nn_tau000, ' time-steps'
+         IF(lwp) WRITE(numout,*)'              constant i-stress      rn_utau0  = ', rn_utau0 , ' N/m2'
+         IF(lwp) WRITE(numout,*)'              constant j-stress      rn_vtau0  = ', rn_vtau0 , ' N/m2'
+         IF(lwp) WRITE(numout,*)'              non solar heat flux    rn_qns0   = ', rn_qns0  , ' W/m2'
+         IF(lwp) WRITE(numout,*)'              solar heat flux        rn_qsr0   = ', rn_qsr0  , ' W/m2'
+         IF(lwp) WRITE(numout,*)'              net heat flux          rn_emp0   = ', rn_emp0  , ' Kg/m2/s'
+         !
+         nn_tau000 = MAX( nn_tau000, 1 )   ! must be >= 1
+         qns_tl   (:,:) = 0.0_wp
+         qsr_tl   (:,:) = 0.0_wp
+         emp_tl   (:,:) = 0.0_wp
+         emps_tl  (:,:) = 0.0_wp
+         utau_tl  (:,:) = 0.0_wp
+         vtau_tl  (:,:) = 0.0_wp
+         taum_tl  (:,:) = 0.0_wp
+         wndm_tl  (:,:) = 0.0_wp
+         !
+      ENDIF
+      !
+   END SUBROUTINE sbc_ana_tan
+
+   SUBROUTINE sbc_ana_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE sbc_ana_adj ***
+      !!              
+      !! ** Purpose :   provide at each time-step the ocean surface boundary
+      !!              condition, i.e. the momentum, heat and freshwater fluxes.
+      !!
+      !! ** Method  :   Constant and uniform surface forcing specified from
+      !!              namsbc_ana namelist parameters. All the fluxes are time
+      !!              independant except the stresses which increase from zero
+      !!              during the first nn_tau000 time-step 
+      !!                CAUTION : never mask the surface stress field !
+      !!
+      !! ** Action  : - set the ocean surface boundary condition, i.e.  
+      !!                   utau, vtau, taum, wndm, qns, qsr, emp, emps
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt       ! ocean time step
+      !!
+      NAMELIST/namsbc_ana/ nn_tau000, rn_utau0, rn_vtau0, rn_qns0, rn_qsr0, rn_emp0
+      !!---------------------------------------------------------------------
+      !
+      IF( kt == nitend ) THEN
+         !
+         IF(lwp) WRITE(numout,*)' '
+         IF(lwp) WRITE(numout,*)' sbc_ana_adj : Constant surface fluxes read in namsbc_ana namelist'
+         IF(lwp) WRITE(numout,*)' ~~~~~~~ '
+
+         nn_tau000 = MAX( nn_tau000, 1 )   ! must be >= 1
+         qns_ad   (:,:) = 0.0_wp
+         qsr_ad   (:,:) = 0.0_wp
+         emp_ad   (:,:) = 0.0_wp
+         emps_ad  (:,:) = 0.0_wp
+         utau_ad  (:,:) = 0.0_wp
+         vtau_ad  (:,:) = 0.0_wp
+         taum_ad  (:,:) = 0.0_wp
+         wndm_ad  (:,:) = 0.0_wp
+         !
+      ENDIF
+      !
+   END SUBROUTINE sbc_ana_adj
+
+
+   SUBROUTINE sbc_gyre_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE sbc_gyre_tam ***
+      !!              
+      !! ** Purpose :   provide at each time-step the GYRE surface boundary
+      !!              condition, i.e. the momentum, heat and freshwater fluxes.
+      !!
+      !! ** Method  :   analytical seasonal cycle for GYRE configuration.
+      !!                CAUTION : never mask the surface stress field !
+      !!
+      !! ** Action  : - set the ocean surface boundary condition, i.e.   
+      !!                   utau, vtau, taum, wndm, qns, qsr, emp, emps
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt          ! ocean time step
+      !!
+      INTEGER  ::   ji, jj                 ! dummy loop indices
+      REAL(wp) ::   ztstar
+      REAL(wp) ::   ztrp
+      REAL(wp) ::   zsumemp_tl, zsurf
+      !!---------------------------------------------------------------------
+         
+      ! ---------------------------- !
+      !  heat and freshwater fluxes  !
+      ! ---------------------------- !
+      !same temperature, E-P as in HAZELEGER 2000
+
+      ztrp= - 40.e0        ! retroaction term on heat fluxes (W/m2/K)
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ! domain from 15 deg to 50 deg between 27 and 28  degC at 15N, -3
+            ! and 13 degC at 50N 53.5 + or - 11 = 1/4 period :
+            ! 64.5 in summer, 42.5 in winter
+            ! 23.5 deg : tropics
+            qsr_tl (ji,jj) =  0.0_wp
+            qns_tl (ji,jj) = ztrp *  tb_tl(ji,jj,1) 
+            emp_tl (ji,jj) =  0.0_wp
+         END DO
+      END DO
+      emps_tl(:,:) = emp_tl(:,:)
+
+      ! Compute the emp flux such as its integration on the whole domain at each time is zero
+      IF( nbench /= 1 .AND. nbit_cmp /= 1 ) THEN
+         zsumemp_tl = 0.e0   ;   zsurf = 0.e0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zsumemp_tl = zsumemp_tl + emp_tl(ji,jj) * tmask(ji,jj,1) * tmask_i(ji,jj)
+               zsurf   = zsurf   +              tmask(ji,jj,1) * tmask_i(ji,jj)
+            END DO
+         END DO
+
+         IF( lk_mpp )   CALL mpp_sum( zsumemp_tl  )       ! sum over the global domain
+         IF( lk_mpp )   CALL mpp_sum( zsurf    )       ! sum over the global domain
+
+         ! Default GYRE configuration
+         zsumemp_tl = zsumemp_tl / zsurf
+      ELSE
+         ! Benchmark GYRE configuration (to allow the bit to bit comparison between Mpp/Mono case)
+         zsumemp_tl = 0.e0   ;    zsurf = 0.e0
+      ENDIF
+
+      !salinity terms
+      emp_tl (:,:) = emp_tl(:,:) - zsumemp_tl * tmask(:,:,1)
+      emps_tl(:,:) = emp_tl(:,:)
+
+   END SUBROUTINE sbc_gyre_tan
+
+   SUBROUTINE sbc_gyre_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE sbc_gyre_adj ***
+      !!              
+      !! ** Purpose :   provide at each time-step the ocean surface boundary
+      !!      condition, i.e. the momentum, heat and freshwater fluxes.
+      !!
+      !! ** Method  :   analytical seasonal cycle for GYRE configuration.
+      !!      * C A U T I O N : never mask the surface stress field !
+      !!
+      !! ** Action  : - set the ocean surface boundary condition, i.e.   
+      !!                   utau, vtau, qns, qsr, emp, emps
+      !!
+      !! Reference : Hazeleger, W., and S. Drijfhout, JPO, 30, 677-695, 2000.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt          ! ocean time step
+
+      INTEGER  ::   ji, jj                 ! dummy loop indices
+      REAL(wp) ::   ztstar
+      REAL(wp) ::   ztrp
+      REAL(wp) ::   zsumemp_ad, zsurf
+      !!---------------------------------------------------------------------
+      
+      zsumemp_ad = 0.0_wp 
+      zsurf = 0.0_wp
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            emp_ad (ji,jj) = emp_ad(ji,jj) + emps_ad(ji,jj)
+            emps_ad(ji,jj) = 0.0_wp
+         END DO
+      END DO 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zsumemp_ad = zsumemp_ad - emp_ad (ji,jj) * tmask(ji,jj,1)
+         END DO
+      END DO
+
+      ! Compute the emp flux such as its integration on the whole domain at each time is zero
+      IF( nbench /= 1 .AND. nbit_cmp /= 1 ) THEN
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zsurf   = zsurf   +              tmask(ji,jj,1) * tmask_i(ji,jj)
+            END DO
+         END DO
+         ! Default GYRE configuration
+         zsumemp_ad = zsumemp_ad / zsurf
+
+         IF( lk_mpp )   CALL mpp_sum( zsurf    )       ! sum over the global domain
+         IF( lk_mpp )   CALL mpp_sum( zsumemp_ad  )       ! sum over the global domain
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               emp_ad(ji,jj) = emp_ad(ji,jj) + zsumemp_ad * tmask(ji,jj,1) * tmask_i(ji,jj)
+            END DO
+         END DO
+         zsumemp_ad = 0.0_wp   ;   zsurf = 0.0_wp
+      ELSE
+         ! Benchmark GYRE configuration (to allow the bit to bit comparison between Mpp/Mono case)
+         zsumemp_ad = 0.0_wp   ;    zsurf = 0.0_wp
+      ENDIF
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            emp_ad (ji,jj) = emp_ad(ji,jj) + emps_ad(ji,jj)
+            emps_ad(ji,jj) = 0.0_wp
+         END DO
+      END DO 
+
+      ! ---------------------------- !
+      !  heat and freshwater fluxes  !
+      ! ---------------------------- !
+      !same temperature, E-P as in HAZELEGER 2000
+
+      ztrp= - 40.e0        ! retroaction term on heat fluxes (W/m2/K)
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ! domain from 15 deg to 50 deg between 27 and 28  degC at 15N, -3
+            ! and 13 degC at 50N 53.5 + or - 11 = 1/4 period :
+            ! 64.5 in summer, 42.5 in winter
+            ! 23.5 deg : tropics
+            emp_ad (ji,jj)   =  0.0_wp
+            tb_ad  (ji,jj,1) = tb_ad(ji,jj,1) + ztrp * qns_ad (ji,jj)
+            qns_ad (ji,jj)   = 0.0_wp
+            qsr_ad (ji,jj)   =  0.0_wp
+         END DO
+      END DO
+
+   END SUBROUTINE sbc_gyre_adj
+
+   SUBROUTINE sbc_gyre_adj_tst ( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE example_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!                   
+      !! History :
+      !!        ! 09-10 (F. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & istp,  &
+         & jstp,  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk   
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2            ! scalar product involving the adjoint routine
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zemp_tlin ,     & ! Tangent input
+         & zemp_tlout,     & ! Tangent output
+         & zemps_tlout,    & ! Tangent output
+         & zqns_tlout,     & ! Tangent output
+         & zemp_adin ,     & ! Adjoint input
+         & zemps_adin,     & ! Adjoint input
+         & zqns_adin ,     & ! Adjoint input
+         & zemp_adout,     & ! Adjoint output 
+         & zr                ! 2D random field
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & ztb_tlin  ,     & ! Tangent input
+         & ztb_adout ,     & ! Adjoint output
+         & z3r               ! 3D random field 
+      CHARACTER(LEN=14) :: cl_name
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zemp_tlin(  jpi,jpj),     &
+         & ztb_tlin(jpi,jpj,jpk),    &
+         & zemp_tlout( jpi,jpj),     &
+         & zemps_tlout( jpi,jpj),    &
+         & zqns_tlout(  jpi,jpj),    &
+         & ztb_adout(jpi,jpj,jpk),   &
+         & zemp_adin(  jpi,jpj),     &
+         & zemps_adin( jpi,jpj),     &
+         & zqns_adin(  jpi,jpj),     &
+         & zemp_adout( jpi,jpj),     &
+         & zr(         jpi,jpj),     &
+         & z3r(     jpi,jpj,jpk)     &
+         & )
+      !==================================================================
+      ! 1) dx = ( emp_tl, emps_tl, ssh_tl ) and 
+      !    dy = ( emp_tl, emps_tl )
+      !==================================================================
+      ! Test for time steps nit000 and nit000 + 1 (the matrix changes)
+
+      DO jstp = nit000, nit000 + 1
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+          zemp_tlin  (:,:) = 0.0_wp
+          ztb_tlin (:,:,:) = 0.0_wp
+          zemp_tlout (:,:) = 0.0_wp
+          zemps_tlout(:,:) = 0.0_wp
+          zqns_tlout (:,:) = 0.0_wp
+          zemp_adin  (:,:) = 0.0_wp
+          zemps_adin (:,:) = 0.0_wp
+          zqns_adin  (:,:) = 0.0_wp
+          zemp_adout (:,:) = 0.0_wp
+          ztb_adout(:,:,:) = 0.0_wp
+          z3r(:,:,:)       = 0.0_wp
+          zr(:,:)          = 0.0_wp
+
+          qns_tl (:,:)     = 0.0_wp
+          qsr_tl (:,:)     = 0.0_wp
+          emps_tl(:,:)     = 0.0_wp
+          qsr_ad (:,:)     = 0.0_wp
+          tb_ad(:,:,:)     = 0.0_wp
+ 
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+          DO jj = 1, jpj
+             DO ji = 1, jpi
+                iseed_2d(ji,jj) = - ( 596035 + &
+                     &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+             END DO
+          END DO
+          CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdemp )
+          DO jj = nldj, nlej
+             DO ji = nldi, nlei
+                zemp_tlin(ji,jj) = zr(ji,jj) 
+             END DO
+          END DO
+          DO jj = 1, jpj
+             DO ji = 1, jpi
+                iseed_2d(ji,jj) = - ( 446251 + &
+                     &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+             END DO
+          END DO
+          CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdt )
+          DO jk = 1, jpk
+             DO jj = nldj, nlej
+                DO ji = nldi, nlei
+                   ztb_tlin(ji,jj,jk) = z3r(ji,jj,jk) 
+                END DO
+             END DO
+          END DO
+
+          tb_tl(:,:,:) = ztb_tlin(:,:,:)
+          emp_tl (:,:) = zemp_tlin (:,:)
+
+          CALL sbc_gyre_tan( istp )
+
+          zemps_tlout(:,:) = emps_tl(:,:)
+          zemp_tlout (:,:) = emp_tl (:,:)
+          zqns_tlout(:,:) = qns_tl(:,:)
+         
+         !-----------------------------------------------------------------
+         ! Initialize the adjoint variables: dy^* = W dy
+         !-----------------------------------------------------------------
+
+          DO jj = nldj, nlej
+             DO ji = nldi, nlei
+                zemp_adin( ji,jj) = zemp_tlout( ji,jj) &
+                     &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+                     &               * tmask(ji,jj,1)
+                zemps_adin(ji,jj) = zemps_tlout(ji,jj) &
+                     &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+                     &               * tmask(ji,jj,1)
+                zqns_adin(ji,jj) = zqns_tlout(ji,jj) &
+                     &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+                     &               * tmask(ji,jj,1)
+             END DO
+          END DO
+
+         !-----------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !-----------------------------------------------------------------
+
+          zsp1 = DOT_PRODUCT( zemp_tlout,  zemp_adin  )   &
+               & + DOT_PRODUCT( zemps_tlout, zemps_adin ) &
+               & + DOT_PRODUCT( zqns_tlout, zqns_adin )    
+
+         !-----------------------------------------------------------------
+         ! Call the adjoint routine: dx^* = L^T dy^*
+         !-----------------------------------------------------------------
+
+         emp_ad (:,:) = zemp_adin (:,:)
+         emps_ad(:,:) = zemps_adin(:,:)
+         qns_ad( :,:) = zqns_adin( :,:)
+
+         CALL sbc_gyre_adj ( istp )
+
+         ztb_adout(:,:,:) = tb_ad(:,:,:)
+         zemp_adout (:,:) = emp_ad (:,:)
+
+         zsp2 = DOT_PRODUCT( zemp_tlin,  zemp_adout  ) &
+            & + DOT_PRODUCT( ztb_tlin,  ztb_adout  ) 
+
+         ! 14 char:'12345678901234'
+         IF ( jstp == nit000 ) THEN
+             WRITE (cl_name,"(A14)") 'sbc_gyre_adj 1'
+         ELSEIF ( jstp == nit000 + 1 ) THEN
+             WRITE (cl_name,"(A14)") 'sbc_gyre_adj 2'
+         END IF
+!         WRITE (cl_name,"(A11,2x,i1)") 'sbc_fwb_adj',jn_fwb
+         CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      END DO
+
+      DEALLOCATE(       &
+         & zemp_tlin,   &
+         & ztb_tlin,    &
+         & zemp_tlout,  &
+         & zemps_tlout, &
+         & zqns_tlout,  &
+         & zemp_adin,   &
+         & zemps_adin,  &
+         & zqns_adin,   &
+         & zemp_adout,  &
+         & ztb_adout,   &
+         & z3r,         &
+         & zr           &
+         & )
+
+   END SUBROUTINE sbc_gyre_adj_tst
+#endif
+   !!======================================================================
+END MODULE sbcana_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcflx_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcflx_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcflx_tam.F90	(revision 2578)
@@ -0,0 +1,211 @@
+MODULE sbcflx_tam
+#if defined key_tam
+   !!======================================================================
+   !!                       ***  MODULE  sbcflx_tam  ***
+   !! Ocean forcing:  momentum, heat and freshwater flux formulation
+   !!                 Angent and Andjoint Module
+   !!=====================================================================
+   !! History of the direct module:  
+   !!      9.0   !  06-06  (G. Madec)  Original code
+   !! History of the T&A module:  
+   !!      9.0   !  08-11  (A. Vidard)  Original code
+   !!      9.0   !  10-04  (A. Vidard)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   namflx   : flux formulation namlist
+   !!   sbc_flx  : flux formulation as ocean surface boundary condition
+   !!              (forced mode, fluxes read in NetCDF files)
+   !!----------------------------------------------------------------------
+   !! question diverses
+   !!  *   ajouter un test sur la division entier de freqh et rdttra ???
+   !!  **  ajoute dans namelist: 1 year forcing files
+   !!                         or forcing file starts at the begining of the run
+   !!  *** we assume that the forcing file start and end with the previous
+   !!      year last record and the next year first record (useful for
+   !!      time interpolation, required even if no time interp???)
+   !!  *   ajouter un test sur la division de la frequence en pas de temps
+   !!  ==> daymod ajout de nsec_year = number of second since the begining of the year
+   !!      assumed to be 0 at 0h january the 1st (i.e. 24h december the 31)
+   !!
+   !!  *** regrouper dtatem et dtasal
+   !!----------------------------------------------------------------------
+   USE par_kind   , ONLY: & ! Precision variables
+      & wp
+   USE par_oce    , ONLY: & ! Ocean space and time domain variables
+      & jpi,              &
+      & jpj
+   USE sbc_oce_tam, ONLY: & ! Surface boundary condition: ocean fields
+      & utau_tl,          & ! sea surface i-stress (ocean referential) [N/m2]
+      & vtau_tl,          & ! sea surface j-stress (ocean referential) [N/m2]
+      & taum_tl,          &
+      & qns_tl ,          & ! sea heat flux: non solar                 [W/m2]
+      & qsr_tl ,          & ! sea heat flux:     solar                 [W/m2]
+      & emp_tl ,          & ! freshwater budget: volume flux           [Kg/m2/s]
+      & emps_tl,          & ! freshwater budget: concentr/dillution    [Kg/m2/s]
+      & wndm_tl,          & ! wind speed module at T-point(=|U10m-Uoce|)[m/s]
+      & utau_ad,          &
+      & vtau_ad,          &
+      & taum_ad,          &
+      & qns_ad ,          &
+      & qsr_ad ,          &
+      & emp_ad ,          &
+      & emps_ad,          &
+      & wndm_ad
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC sbc_flx_tan       ! routine called by sbcmod_tam.F90
+   PUBLIC sbc_flx_adj       ! routine called by sbcmod_tam.F90
+   PUBLIC sbc_flx_adj_tst   ! routine called by tst.F90
+
+   REAL(wp) ::   rhoa  = 1.22         ! Air density kg/m3
+   REAL(wp) ::   cdrag = 1.5e-3       ! drag coefficient
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Id: sbcflx.F90 1200 2008-09-24 13:05:20Z rblod $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE sbc_flx_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE sbc_flx_tan  ***
+      !!                   
+      !! ** Purpose of the direct routine:
+      !!                provide at each time step the surface ocean fluxes
+      !!                (momentum, heat, freshwater and runoff) 
+      !!
+      !! ** Method  : - READ each fluxes in NetCDF files:
+      !!                   i-component of the stress              utau  (N/m2)
+      !!                   j-component of the stress              vtau  (N/m2)
+      !!                   net downward heat flux                 qtot  (watt/m2)
+      !!                   net downward radiative flux            qsr   (watt/m2)
+      !!                   net upward freshwater (evapo - precip) emp   (kg/m2/s)
+      !!
+      !!      CAUTION :  - never mask the surface stress fields
+      !!                 - the stress is assumed to be in the mesh referential
+      !!                   i.e. the (i,j) referential
+      !!
+      !! ** Action  :   update at each time-step
+      !!              - utau, vtau  i- and j-component of the wind stress
+      !!              - taum        wind stress module at T-point
+      !!              - wndm        10m wind module at T-point
+      !!              - qns, qsr    non-slor and solar heat flux
+      !!              - emp, emps   evaporation minus precipitation
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time step
+      !!
+      INTEGER  ::   ji, jj          ! dummy indices
+     !!
+      !!---------------------------------------------------------------------
+      ! set the ocean fluxes from read fields
+!CDIR COLLAPSE
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            utau_tl(ji,jj) = 0.0_wp
+            vtau_tl(ji,jj) = 0.0_wp
+            qns_tl (ji,jj) = 0.0_wp
+            qsr_tl (ji,jj) = 0.0_wp 
+            emp_tl (ji,jj) = 0.0_wp
+         END DO
+      END DO
+
+      ! Initialization of emps (when no ice model)
+      emps_tl(:,:) = emp_tl (:,:) 
+
+      ! Estimation of wind speed as a function of wind stress ( |tau|=rhoa*Cd*|U|^2 )
+      ! WARNING !!! TANGENT NOT VALID if TAU is part of the state vector.
+      taum_tl(:,:) = 0.0_wp
+      wndm_tl(:,:) = 0.0_wp
+      !
+   END SUBROUTINE sbc_flx_tan
+   SUBROUTINE sbc_flx_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE sbc_flx_adj  ***
+      !!                   
+      !! ** Purpose of the direct routine:
+      !!                provide at each time step the surface ocean fluxes
+      !!                (momentum, heat, freshwater and runoff) 
+      !!
+      !! ** Method  : - READ each fluxes in NetCDF files:
+      !!                   i-component of the stress              utau  (N/m2)
+      !!                   j-component of the stress              vtau  (N/m2)
+      !!                   net downward heat flux                 qtot  (watt/m2)
+      !!                   net downward radiative flux            qsr   (watt/m2)
+      !!                   net upward freshwater (evapo - precip) emp   (kg/m2/s)
+      !!
+      !!      CAUTION :  - never mask the surface stress fields
+      !!                 - the stress is assumed to be in the mesh referential
+      !!                   i.e. the (i,j) referential
+      !!
+      !! ** Action  :   update at each time-step
+      !!              - utau, vtau  i- and j-component of the wind stress
+      !!              - taum        wind stress module at T-point
+      !!              - wndm        10m wind module at T-point
+      !!              - qns, qsr    non-slor and solar heat flux
+      !!              - emp, emps   evaporation minus precipitation
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time step
+      !!
+      INTEGER  ::   ji, jj   ! dummy indices
+      !!
+      !!---------------------------------------------------------------------
+      ! Estimation of wind speed as a function of wind stress ( |tau|=rhoa*Cd*|U|^2 )
+      ! WARNING !!! ADJGENT NOT VALID if TAU is par of the state vector.
+      taum_ad(:,:) = 0.0_wp
+      wndm_ad(:,:) = 0.0_wp
+      ! Initialization of emps (when no ice model)
+      emp_ad (:,:) =  emp_ad (:,:) + emps_ad(:,:)
+      emps_ad(:,:) = 0.0_wp
+       ! set the ocean fluxes from read fields
+!CDIR COLLAPSE
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            utau_ad(ji,jj) = 0.0_wp
+            vtau_ad(ji,jj) = 0.0_wp
+            qns_ad (ji,jj) = 0.0_wp
+            qsr_ad (ji,jj) = 0.0_wp 
+            emp_ad (ji,jj) = 0.0_wp
+         END DO
+      END DO
+     !
+   END SUBROUTINE sbc_flx_adj
+   SUBROUTINE sbc_flx_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE sbc_flx_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-11 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      ! adjoint is obvious, no need to test...
+   END SUBROUTINE sbc_flx_adj_tst
+#endif
+   !!======================================================================
+END MODULE sbcflx_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcfwb_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcfwb_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcfwb_tam.F90	(revision 2578)
@@ -0,0 +1,509 @@
+MODULE sbcfwb_tam
+#if defined key_tam
+   !!======================================================================
+   !!                       ***  MODULE  sbcfwb  ***
+   !! Ocean fluxes   : domain averaged freshwater budget
+   !!======================================================================
+   !! History of the direct module:
+   !!            8.2  !  01-02  (E. Durand)  Original code
+   !!            8.5  !  02-06  (G. Madec)  F90: Free form and module
+   !!            9.0  !  06-08  (G. Madec)  Surface module
+   !!            9.2  !  09-07  (C. Talandier) emp mean s spread over erp area 
+   !! History of the T&A module:
+   !!            9.0  !  06-08  (A. Vidard)  Surface module
+   !!            9.2  !  09-07  (A. Vidard)  NEMO3.2 update
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   sbc_fwb      : freshwater budget for global ocean configurations
+   !!                  in free surface and forced mode
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! 
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 &
+      & jpiglo
+   USE oce_tam       , ONLY: & ! ocean dynamics and tracers
+      & sshn_tl,             &
+      & sshn_ad
+   USE sbc_oce_tam   , ONLY: & ! surface variables
+      & emp_tl,              &
+      & emps_tl,             &
+      & emp_ad,              &
+      & emps_ad
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & rdttra,              &
+      & e1t,                 &
+      & e2t,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3t,                 &
+#endif
+      & tmask,               &
+      & tmask_i,             &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          &
+      & stdemp,              & !   evaporation minus precip
+      & stdssh                 !   sea surface height
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & ctl_stop,            &
+      & numout,              & 
+      & nit000,              & 
+      & nitend,              & 
+      & ctmp1  
+   USE lib_mpp                 ! distribued memory computing library
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   sbc_fwb_adj      ! routine called by sbcmod_tam
+   PUBLIC   sbc_fwb_tan      ! routine called by sbcmod_tam
+   PUBLIC   sbc_fwb_adj_tst  ! routine called by tst
+
+   REAL(wp), PUBLIC ::   a_fwb_tl           ! for before year.
+   REAL(wp), PUBLIC ::   a_fwb_ad           ! for before year.
+   REAL(wp) ::   area               ! global mean ocean surface (interior domain)
+
+   REAL(wp), DIMENSION(jpi,jpj) ::  &
+     & e1e2_i    ! area of the interior domain (e1t*e2t*tmask_i)
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Id: sbcfwb.F90 1168 2008-08-11 10:21:06Z rblod $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE sbc_fwb_tan( kt, kn_fwb, kn_fsbc )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_fwb_tan  ***
+      !!
+      !! ** Purpose :   Control the mean sea surface drift
+      !!
+      !! ** Method  :   several ways  depending on kn_fwb
+      !!                =0 no control 
+      !!                =1 global mean of emp set to zero at each nn_fsbc time step
+      !!                =2 annual global mean corrected from previous year
+      !!                =3 variable relaxation time to zero or to a time varying field
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+      INTEGER, INTENT( in ) ::   kn_fsbc  ! 
+      INTEGER, INTENT( in ) ::   kn_fwb   ! ocean time-step index
+      !!
+      INTEGER  ::   inum                  ! temporary logical unit
+      INTEGER  ::   ikty, iyear           ! 
+      CHARACTER (len=32) ::   clname 
+      REAL(wp) ::   z_emptl               ! temporary scalars
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 ) THEN
+         !
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'sbc_fwb_tan : FreshWater Budget correction.'
+            WRITE(numout,*) '~~~~~~~~~~~'
+         ENDIF
+         !
+         e1e2_i(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)
+         area = SUM( e1e2_i(:,:) )
+         IF( lk_mpp )   CALL  mpp_sum( area    )   ! sum over the global domain
+         !
+      ENDIF
+      
+
+      SELECT CASE ( kn_fwb )
+      !
+      CASE ( 1 )                               ! global mean emp set to zero
+         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN
+            z_emptl = SUM( e1e2_i(:,:) * emp_tl(:,:) ) / area
+            IF( lk_mpp )   CALL  mpp_sum( z_emptl    )   ! sum over the global domain
+            emp_tl (:,:) = emp_tl (:,:) - z_emptl
+            emps_tl(:,:) = emps_tl(:,:) - z_emptl
+         ENDIF
+         !
+      CASE ( 2 )                               ! emp budget adjusted from the previous year
+         ! initialisation
+         IF( kt == nit000 ) THEN
+            a_fwb_tl = 0.0_wp
+         ENDIF   
+         ! 
+         ikty = 365 * 86400 / rdttra(1)    !!bug  use of 365 days leap year or 360d year !!!!!!!
+         IF( MOD( kt, ikty ) == 0 ) THEN
+            a_fwb_tl   = SUM( e1e2_i(:,:) * sshn_tl(:,:) )
+            IF( lk_mpp )   CALL  mpp_sum( a_fwb_tl )   ! sum over the global domain
+            a_fwb_tl   = a_fwb_tl * 1.e+3 / ( area * 86400. * 365. )     ! convert in Kg/m3/s = mm/s
+!!gm        !                                                      !!bug 365d year 
+         ENDIF
+         ! 
+         ! correct the freshwater fluxes
+         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN
+            emp_tl (:,:) = emp_tl (:,:) + a_fwb_tl
+            emps_tl(:,:) = emps_tl(:,:) + a_fwb_tl
+         ENDIF
+         !
+      CASE ( 3 )
+         !
+         WRITE(ctmp1,*)'sbc_fwb_tan: nn_fwb=', kn_fwb, ' is not available for TAM yet , choose either 0/1/2'
+         CALL ctl_stop( ctmp1 )
+
+         !
+      CASE DEFAULT    ! you should never be there
+         WRITE(ctmp1,*)'sbc_fwb_tan: nn_fwb=', kn_fwb, ' is not permitted for the FreshWater Budget correction, choose either 0/1/2'
+         CALL ctl_stop( ctmp1 )
+         !
+      END SELECT
+      !
+   END SUBROUTINE sbc_fwb_tan
+
+
+   SUBROUTINE sbc_fwb_adj( kt, kn_fwb, kn_fsbc )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_fwb_adj  ***
+      !!
+      !! ** Purpose :   Control the mean sea surface drift
+      !!
+      !! ** Method  :   several ways  depending on kn_fwb
+      !!                =0 no control 
+      !!                =1 global mean of emp set to zero at each nn_fsbc time step
+      !!                =2 annual global mean corrected from previous year
+      !!                =3 variable relaxation time to zero or to a time varying field
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+      INTEGER, INTENT( in ) ::   kn_fsbc  ! 
+      INTEGER, INTENT( in ) ::   kn_fwb   ! ocean time-step index
+      !!
+      INTEGER  ::   inum                  ! temporary logical unit
+      INTEGER  ::   ikty, iyear           ! 
+      INTEGER  ::   ji, jj           ! 
+      CHARACTER (len=32) ::   clname 
+      REAL(wp) ::   z_empad               ! temporary scalars
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nitend ) THEN
+         !
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'sbc_fwb_adj : FreshWater Budget correction.'
+            WRITE(numout,*) '~~~~~~~~~~~'
+         ENDIF
+         !
+         e1e2_i(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)
+         area = SUM( e1e2_i(:,:) )
+         IF( lk_mpp )   CALL  mpp_sum( area    )   ! sum over the global domain
+         !
+         ! initialisation
+         a_fwb_ad = 0.0_wp
+      ENDIF
+         z_empad  = 0.0_wp      
+
+      SELECT CASE ( kn_fwb )
+      CASE ( 0 )
+         ! No Control
+      !
+      CASE ( 1 )                               ! global mean emp set to zero
+         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  z_empad = z_empad - emps_ad(ji,jj) - emp_ad(ji,jj)
+               END DO
+            END DO
+            IF( lk_mpp )   CALL  mpp_sum( z_empad    )   ! sum over the global domain
+            z_empad = z_empad / area
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  emp_ad(ji,jj) = emp_ad(ji,jj) +  e1e2_i(ji,jj) * z_empad
+               END DO
+            END DO
+         ENDIF
+         !
+      CASE ( 2 )                               ! emp budget adjusted from the previous year
+         ! 
+         ! initialisation
+         ikty = 365 * 86400 / rdttra(1)    !!bug  use of 365 days leap year or 360d year !!!!!!!
+         ! correct the freshwater fluxes
+         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  a_fwb_ad = a_fwb_ad + emps_ad(ji,jj) + emp_ad (ji,jj)
+               END DO
+            END DO
+         ENDIF
+         !
+         IF( MOD( kt, ikty ) == 0 ) THEN
+            a_fwb_ad   = a_fwb_ad * 1.e+3 / ( area * 86400. * 365. )     ! convert in Kg/m3/s = mm/s
+            IF( lk_mpp )   CALL  mpp_sum( a_fwb_ad )   ! sum over the global domain
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  sshn_ad(ji,jj) = sshn_ad(ji,jj) + e1e2_i(ji,jj) * a_fwb_ad
+               END DO
+            END DO
+            a_fwb_ad = 0.0_wp
+         ENDIF   
+         ! 
+      CASE ( 3 )
+         !
+         WRITE(ctmp1,*)'sbc_fwb_tan: nn_fwb=', kn_fwb, ' is not available for TAM yet , choose either 0/1/2'
+         CALL ctl_stop( ctmp1 )
+         !
+      CASE DEFAULT    ! you should never be there
+         WRITE(ctmp1,*)'sbc_fwb_adj: nn_fwb=', kn_fwb, ' is not permitted for the FreshWater Budget correction, choose either 0/1/2'
+         CALL ctl_stop( ctmp1 )
+         !
+      END SELECT
+      !
+   END SUBROUTINE sbc_fwb_adj
+
+   SUBROUTINE sbc_fwb_adj_tst ( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE example_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & istp,  &
+         & jstp,  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk,    &
+         & jn_fwb   
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2            ! scalar product involving the adjoint routine
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zemp_tlin ,     & ! Tangent input
+         & zemps_tlin ,    & ! Tangent input
+         & zssh_tlin ,     & ! Tangent input
+#if defined key_obc
+         & zssh_tlout, zssh_adin, &
+#endif
+         & zemp_tlout,     & ! Tangent output
+         & zemps_tlout,    & ! Tangent output
+         & zemp_adin ,     & ! Adjoint input
+         & zemps_adin ,    & ! Adjoint input
+         & zemp_adout,     & ! Adjoint output
+         & zemps_adout,    & ! Adjoint output
+         & zssh_adout,     & ! Adjoint output
+         & zr                ! 3D random field 
+      CHARACTER(LEN=14) :: cl_name
+      ! Allocate memory
+
+      ALLOCATE( &
+#if defined key_obc
+         & zssh_tlout( jpi,jpj),  zssh_adin ( jpi,jpj), &
+#endif
+         & zemp_tlin(  jpi,jpj),     &
+         & zemps_tlin( jpi,jpj),     &
+         & zssh_tlin(  jpi,jpj),     &
+         & zemp_tlout( jpi,jpj),     &
+         & zemps_tlout(jpi,jpj),     &
+         & zemp_adin(  jpi,jpj),     &
+         & zemps_adin( jpi,jpj),     &
+         & zemp_adout( jpi,jpj),     &
+         & zemps_adout(jpi,jpj),     &
+         & zssh_adout( jpi,jpj),     &
+         & zr(         jpi,jpj)      &
+         & )
+      !==================================================================
+      ! 1) dx = ( emp_tl, emps_tl, ssh_tl ) and 
+      !    dy = ( emp_tl, emps_tl )
+      !==================================================================
+      ! Test for time steps nit000 and nit000 + 1 (the matrix changes)
+
+      DO jstp = nit000, nit000 + 2
+         istp = jstp
+         IF ( jstp == nit000 +2 ) istp = nitend
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+          zemp_tlin  (:,:) = 0.0_wp
+          zemps_tlin (:,:) = 0.0_wp
+          zssh_tlin  (:,:) = 0.0_wp
+          zemp_tlout (:,:) = 0.0_wp
+          zemps_tlout(:,:) = 0.0_wp
+          zemp_adin  (:,:) = 0.0_wp
+          zemps_adin (:,:) = 0.0_wp
+          zemp_adout (:,:) = 0.0_wp
+          zemps_adout(:,:) = 0.0_wp
+          zssh_adout (:,:) = 0.0_wp
+          zr(:,:)          = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdemp )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zemp_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 446251 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdemp )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zemps_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO  
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 352678 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdssh )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zssh_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+
+      DO jn_fwb = 1, 2
+
+         a_fwb_tl         = 0.0_wp
+         a_fwb_ad         = 0.0_wp
+         sshn_ad    (:,:) = 0.0_wp
+
+         sshn_tl(:,:) = zssh_tlin (:,:)
+         emps_tl(:,:) = zemps_tlin(:,:)
+         emp_tl (:,:) = zemp_tlin (:,:)
+
+         CALL sbc_fwb_tan( istp, jn_fwb, 1 )
+
+         zemps_tlout(:,:) = emps_tl(:,:)
+         zemp_tlout (:,:) = emp_tl (:,:)
+#if defined key_obc
+         zssh_tlout (:,:) = sshn_tl (:,:)
+#endif
+         !-----------------------------------------------------------------
+         ! Initialize the adjoint variables: dy^* = W dy
+         !-----------------------------------------------------------------
+
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zemp_adin( ji,jj) = zemp_tlout( ji,jj) &
+                  &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+                  &               * tmask(ji,jj,1)
+               zemps_adin(ji,jj) = zemps_tlout(ji,jj) &
+                  &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+                  &               * tmask(ji,jj,1)
+#if defined key_obc
+               zssh_adin( ji,jj) = zssh_tlout( ji,jj) * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) * tmask(ji,jj,1)
+#endif
+            END DO
+         END DO
+
+         !-----------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !-----------------------------------------------------------------
+
+         zsp1 = DOT_PRODUCT( zemp_tlout,  zemp_adin  ) &
+            & + DOT_PRODUCT( zemps_tlout, zemps_adin )
+
+#if defined key_obc
+         zsp1 = zsp1 + DOT_PRODUCT( zssh_tlout, zssh_adin )
+#endif
+         !-----------------------------------------------------------------
+         ! Call the adjoint routine: dx^* = L^T dy^*
+         !-----------------------------------------------------------------
+
+         emp_ad (:,:) = zemp_adin (:,:)
+         emps_ad(:,:) = zemps_adin(:,:)
+#if defined key_obc
+         sshn_ad(:,:) = zssh_adin(:,:)
+#endif
+         CALL sbc_fwb_adj ( istp, jn_fwb, 1 )
+
+         zemps_adout(:,:) = emps_ad(:,:)
+         zemp_adout (:,:) = emp_ad (:,:)
+         zssh_adout (:,:) = sshn_ad(:,:)
+
+         zsp2 = DOT_PRODUCT( zemp_tlin,  zemp_adout  ) &
+            & + DOT_PRODUCT( zssh_tlin,  zssh_adout  ) &
+            & + DOT_PRODUCT( zemps_tlin, zemps_adout ) 
+
+         ! 14 char:'12345678901234'
+         IF ( istp == nit000 ) THEN
+             WRITE (cl_name,"(A10,1x,i1,1x,A1)") 'sbcfwb_adj',jn_fwb,'1'
+         ELSEIF ( istp == nit000 + 1 ) THEN
+             WRITE (cl_name,"(A10,1x,i1,1x,A1)") 'sbcfwb_adj',jn_fwb,'2'
+         ELSEIF ( istp == nitend ) THEN
+             WRITE (cl_name,"(A10,1x,i1,1x,A1)") 'sbcfwb_adj',jn_fwb,'3'
+         END IF
+!         WRITE (cl_name,"(A11,2x,i1)") 'sbc_fwb_adj',jn_fwb
+         CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      END DO
+
+      END DO
+
+      DEALLOCATE(       &
+         & zemp_tlin,   &
+         & zemps_tlin,  &
+         & zssh_tlin,   &
+         & zemp_tlout,  &
+         & zemps_tlout, &
+         & zemp_adin,   &
+         & zemps_adin,  &
+         & zemp_adout,  &
+         & zemps_adout, &
+         & zssh_adout,  &
+         & zr           &
+         & )
+
+   END SUBROUTINE sbc_fwb_adj_tst
+#endif
+   !!======================================================================
+END MODULE sbcfwb_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcmod_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcmod_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcmod_tam.F90	(revision 2578)
@@ -0,0 +1,286 @@
+MODULE sbcmod_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  sbcmod_tam  ***
+   !! Surface module :  provide to the ocean its surface boundary condition
+   !!                       Tangent&Adjoint module
+   !!======================================================================
+   !! History of the direct module :  
+   !!            3.0   !  07-2006  (G. Madec)  Original code
+   !!             -    !  08-2008  (S. Masson, E. .... ) coupled interface
+   !! History of the T&A module :
+   !!            3.0   !  11-2008  (A. Vidard) TAM of the 2006-07 version
+   !!            3.2   !  04-2010  (A. Vidard) Nemo3.2 update
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   sbc_init       : read namsbc namelist
+   !!   sbc            : surface ocean momentum, heat and freshwater boundary conditions
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE phycst        , ONLY: & !
+      & rday
+   USE lbclnk        , ONLY: &
+      & lbc_lnk
+   USE lbclnk_tam    , ONLY: &
+      & lbc_lnk_adj
+   !   USE ice_oce         ! sea-ice model : LIM
+   USE dom_oce       , ONLY: & ! ocean space domain variables
+      & rdt,          cp_cfg,       nclosea
+   USE sbc_oce       , ONLY: & ! Surface boundary condition: ocean fields
+      & nn_fsbc,      nn_ice,           &
+      & nn_fwb,       ln_ana,       ln_flx,           &
+      & ln_ssr,       ln_rnf,       ln_cpl,           &
+      & ln_dm2dc,     ln_blk_clio,  ln_blk_core
+   USE sbcmod        , ONLY: &
+      & sbc_init
+   USE sbc_oce_tam   , ONLY: & ! Surface boundary condition: ocean fields
+      & fr_i_tl,      emp_tl,       emp_ad
+   USE sbcssm_tam    , ONLY: & ! surface boundary condition: sea-surface mean variables
+      & sbc_ssm_tan,  sbc_ssm_adj,  sbc_ssm_adj_tst
+   USE sbcana_tam, ONLY:  & ! surface boundary condition: analytical formulation
+      & sbc_gyre_tan, sbc_gyre_adj, sbc_gyre_adj_tst
+!*B      & sbc_ana_tan,       &
+!*B      & sbc_ana_adj,       &
+!*B      & sbc_ana_adj_tst
+   USE sbcflx_tam    , ONLY: & ! surface boundary condition: flux formulation
+      & sbc_flx_tan,  sbc_flx_adj,  sbc_flx_adj_tst
+!   USE sbcblk_clio     ! surface boundary condition: bulk formulation : CLIO
+!   USE sbcblk_core     ! surface boundary condition: bulk formulation : CORE
+!   USE sbcice_if       ! surface boundary condition: ice-if sea-ice model
+!   USE sbcice_lim      ! surface boundary condition: LIM 3.0 sea-ice model
+!   USE sbcice_lim_2    ! surface boundary condition: LIM 2.0 sea-ice model
+!   USE sbccpl          ! surface boundary condition: coupled florulation
+   USE sbcssr_tam    , ONLY: & ! surface boundary condition: sea surface restoring
+      & sbc_ssr_tan,  sbc_ssr_adj,  sbc_ssr_adj_tst
+   USE closea_tam    , ONLY: & !specific treatments associated with closed seas
+      & sbc_clo_tan,  sbc_clo_adj,  sbc_clo_adj_tst
+!   USE sbcrnf_tam          ! surface boundary condition: runoffs
+   USE sbcrnf        , ONLY: & ! surface boundary condition: runoffs
+      & rnfmsk,       rnfmsk_z,     ln_rnf_mouth,     &
+      & nkrnf
+   USE sbcfwb_tam    , ONLY: & ! surface boundary condition: freshwater budget
+      & sbc_fwb_tan,  sbc_fwb_adj,  sbc_fwb_adj_tst
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,          ctl_warn,     numout,           &
+      & numnam,       nit000,       nitend,           &
+      & nstop
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   sbc_init_tam ! routine called by step_tam.F90
+   PUBLIC   sbc_tan      ! routine called by step_tam.F90
+   PUBLIC   sbc_adj      ! routine called by step_tam.F90
+   PUBLIC   sbc_adj_tst  ! routine called by tst.F90
+   
+   INTEGER          ::   nn_ico_cpl  = 0         !: ice-ocean coupling indicator
+   !                                             !  = 0   LIM-3 old case
+   !                                             !  = 1   stresses computed using now ocean velocity
+   !                                             !  = 2   combination of 0 and 1 cases
+
+   INTEGER ::   nsbc   ! type of surface boundary condition (deduced from namsbc informations)
+   INTEGER ::   nice   ! type of ice in the surface boundary condition (deduced from namsbc informations)
+   LOGICAL :: lfirst = .TRUE. ! initialisation flag
+      
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.0 , LOCEAN-IPSL (2008) 
+   !! $Id: sbcmod.F90 1172 2008-09-10 15:32:47Z ctlod $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE sbc_init_tam
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE sbc_init_tam ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!           Initialisation of the ocean surface boundary computation
+      !!
+      !! ** Method  :   Read the namsbc namelist and set derived parameters
+      !!
+      !! ** Action  : - read namsbc parameters
+      !!              - nsbc: type of sbc
+      !!----------------------------------------------------------------------
+      INTEGER ::   icpt      ! temporary integer
+      !!
+      NAMELIST/namsbc/ nn_fsbc, ln_ana, ln_flx, ln_blk_clio, ln_blk_core, ln_cpl,   &
+         &             ln_dm2dc, ln_rnf, ln_ssr, nn_fwb, nn_ico_cpl
+      !!----------------------------------------------------------------------
+
+      IF (lfirst) THEN
+
+         CALL sbc_init
+         IF( nn_ice == 0  )   fr_i_tl(:,:) = 0.e0       ! no ice in the domain, ice fraction is always zero
+         lfirst = .FALSE.
+      END IF
+      !
+   END SUBROUTINE sbc_init_tam
+
+
+   SUBROUTINE sbc_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE sbc_tan  ***
+      !!              
+      !! ** Purpose of the direct routine:
+      !!                provide at each time-step the ocean surface boundary
+      !!                condition (momentum, heat and freshwater fluxes)
+      !!
+      !! ** Method  :   blah blah  to be written ????????? 
+      !!                CAUTION : never mask the surface stress field (tke sbc)
+      !!
+      !! ** Action  : - set the ocean surface boundary condition, i.e.  
+      !!                utau, vtau, qns, qsr, emp, emps, qrp, erp
+      !!              - updte the ice fraction : fr_i
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt       ! ocean time step
+      !!---------------------------------------------------------------------
+
+      ! ocean to sbc mean sea surface variables (ss._m)
+      ! ---------------------------------------
+      CALL sbc_ssm_tan( kt )                         ! sea surface mean currents (at U- and V-points), 
+      !                                          ! temperature and salinity (at T-point) over nf_sbc time-step
+      !                                          ! (i.e. sst_m, sss_m, ssu_m, ssv_m)
+
+      ! sbc formulation
+      ! ---------------
+         
+      SELECT CASE( nsbc )                        ! Compute ocean surface boundary condition
+      !                                          ! (i.e. utau,vtau, qns, qsr, emp, emps)
+      CASE(  0 )   ;   CALL sbc_gyre_tan    ( kt )      ! analytical formulation : GYRE configuration
+         ! no! in default
+      !CASE(  1 )   ;   CALL sbc_ana_tan     ( kt )      ! analytical formulation : uniform sbc
+      CASE(  2 )   ;   CALL sbc_flx_tan     ( kt )      ! flux formulation
+      !CASE(  3 )   ;   CALL sbc_blk_clio_tan( kt )      ! bulk formulation : CLIO for the ocean
+      !CASE(  4 )   ;   CALL sbc_blk_core_tan( kt )      ! bulk formulation : CORE for the ocean
+      !CASE(  5 )   ;   CALL sbc_cpl_tan     ( kt )      ! coupled formulation
+      END SELECT
+
+      ! Misc. Options
+      ! -------------
+      ! not available
+!*B      SELECT CASE( nn_ice )                                     ! Update heat and freshwater fluxes over sea-ice areas
+!*B      CASE(  1 )   ;       CALL sbc_ice_if_tan   ( kt )                   ! Ice-cover climatology ("Ice-if" model)
+!*B         !                                                      
+!*B      CASE(  2 )   ;       CALL sbc_ice_lim_2_tan( kt, nsbc )             ! LIM 2.0 ice model
+!*B         !                                                     
+!*B      CASE(  3 )   ;       CALL sbc_ice_lim_tan  ( kt, nsbc, nn_ico_cpl)  ! LIM 3.0 ice model
+!*B      END SELECT                                              
+
+      ! add runoffs to fresh water fluxes... not needed in tangent
+ 
+      IF( ln_ssr       )   CALL sbc_ssr_tan( kt )                   ! add SST/SSS damping term
+
+      IF( nn_fwb  /= 0 )   CALL sbc_fwb_tan( kt, nn_fwb, nn_fsbc )  ! control the freshwater budget
+
+      IF( nclosea == 1 )   CALL sbc_clo_tan( kt )                   ! treatment of closed sea in the model domain 
+      !                                                         ! (update freshwater fluxes)
+      !
+!RBbug do not understand why see ticket 667
+      CALL lbc_lnk( emp_tl, 'T', 1. )  
+      !
+      !
+   END SUBROUTINE sbc_tan
+
+   !!======================================================================
+   SUBROUTINE sbc_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE sbc_adj  ***
+      !!              
+      !! ** Purpose of the direct routine:
+      !!                provide at each time-step the ocean surface boundary
+      !!                condition (momentum, heat and freshwater fluxes)
+      !!
+      !! ** Method  :   blah blah  to be written ????????? 
+      !!                CAUTION : never mask the surface stress field (tke sbc)
+      !!
+      !! ** Action  : - set the ocean surface boundary condition, i.e.  
+      !!                utau, vtau, qns, qsr, emp, emps, qrp, erp
+      !!              - updte the ice fraction : fr_i
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt       ! ocean time step
+      !!---------------------------------------------------------------------
+
+      ! Misc. Options
+      ! -------------
+!RBbug do not understand why see ticket 667
+      CALL lbc_lnk_adj( emp_ad, 'T', 1. )  
+      !
+      IF( nclosea == 1 )   CALL sbc_clo_adj( kt )                   ! treatment of closed sea in the model domain 
+      IF( nn_fwb  /= 0 )   CALL sbc_fwb_adj( kt, nn_fwb, nn_fsbc )  ! control the freshwater budget
+      IF( ln_ssr       )   CALL sbc_ssr_adj( kt )                   ! add SST/SSS damping term
+      SELECT CASE( nn_ice )                                     ! Update heat and freshwater fluxes over ice-covered areas
+!      CASE(  1 )   ;       CALL sbc_ice_if_adj ( kt )                     ! Ice-cover climatology ("Ice-if" model)
+         !                                                      
+!      CASE(  2 )   ;       CALL sbc_ice_lim_2_adj( kt, nsbc )             ! LIM 2.0 ice model
+         !                                                     
+!      CASE(  3 )   ;       CALL sbc_ice_lim_adj  ( kt, nsbc, nn_ico_cpl)  ! LIM 3.0 ice model
+      END SELECT                                              
+      ! sbc formulation
+      ! ---------------
+         
+      SELECT CASE( nsbc )                        ! Compute ocean surface boundary condition
+      !                                          ! (i.e. utau,vtau, qns, qsr, emp, emps)
+      CASE(  0 )   ;   CALL sbc_gyre_adj    ( kt )      ! analytical formulation : GYRE configuration
+!      CASE(  1 )   ;   CALL sbc_ana_adj     ( kt )      ! analytical formulation : uniform sbc
+      CASE(  2 )   ;   CALL sbc_flx_adj     ( kt )      ! flux formulation
+!      CASE(  3 )   ;   CALL sbc_blk_clio_adj( kt )      ! bulk formulation : CLIO for the ocean
+!      CASE(  4 )   ;   CALL sbc_blk_core_adj( kt )      ! bulk formulation : CORE for the ocean
+!      CASE(  5 )   ;   CALL sbc_cpl_adj     ( kt )      ! coupled formulation
+      END SELECT
+      ! ocean to sbc mean sea surface variables (ss._m)
+      ! ---------------------------------------
+      CALL sbc_ssm_adj( kt )                         ! sea surface mean currents (at U- and V-points), 
+      !                                          ! temperature and salinity (at T-point) over nf_sbc time-step
+      !                                          ! (i.e. sst_m, sss_m, ssu_m, ssv_m)
+
+
+   END SUBROUTINE sbc_adj
+   SUBROUTINE sbc_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE sbc_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      CALL sbc_init_tam         ! Read namsbc namelist : surface module      
+!
+      CALL sbc_fwb_adj_tst( kumadt )       ! control the freshwater budget
+      CALL sbc_ssr_adj_tst( kumadt )       ! add SST/SSS damping term
+!      CALL sbc_rnf_adj_tst( kumadt )       ! add runoffs to fresh water fluxes
+!      CALL sbc_ice_if_adj_tst( kumadt )    ! Ice-cover climatology ("Ice-if" model)
+!      CALL sbc_ice_lim_2_adj_tst( kumadt ) ! LIM 2.0 ice model
+!      CALL sbc_ice_lim_adj_tst( kumadt )   ! LIM 3.0 ice model
+      CALL sbc_gyre_adj_tst( kumadt )      ! analytical formulation : GYRE configuration
+!      CALL sbc_ana_adj_tst( kumadt )       ! analytical formulation : uniform sbc
+      CALL sbc_flx_adj_tst( kumadt )        ! flux formulation
+!      CALL sbc_blk_clio_adj_tst( kumadt )  ! bulk formulation : CLIO for the ocean
+!      CALL sbc_blk_core_adj_tst( kumadt )  ! bulk formulation : CORE for the ocean
+!      CALL sbc_cpl_adj_tst( kumadt )       ! coupled formulation
+      CALL sbc_ssm_adj_tst( kumadt )       ! sea surface mean currents (at U- and V-points), 
+      IF( nclosea == 1 ) CALL sbc_clo_adj_tst( kumadt )       ! closed seas,
+
+   END SUBROUTINE sbc_adj_tst
+   !!======================================================================
+#endif
+END MODULE sbcmod_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcssm_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcssm_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcssm_tam.F90	(revision 2578)
@@ -0,0 +1,720 @@
+MODULE sbcssm_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  sbcssm_tam  ***
+   !! Surface module :  provide time-mean ocean surface variables
+   !!                   Tangent and adjoint module
+   !!======================================================================
+   !! History of the direct module:
+   !!            9.0   !  06-07  (G. Madec)  Original code
+   !! History of the TAM module:
+   !!            9.0   !  08-11  (A. Vidard) Original code
+   !!            9.0   !  10-04  (A. Vidard) Nemo3.2 update
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   sbc_ssm_[tan adj]: calculate sea surface mean currents, temperature,  
+   !!                    and salinity over nn_fsbc time-step
+   !!----------------------------------------------------------------------
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 &
+      & jpiglo
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE oce_tam       , ONLY: & ! ocean dynamics and tracers
+      & ub_tl,               &
+      & vb_tl,               &
+      & tn_tl,               &
+      & sn_tl,               &
+      & sshn_tl,             &
+      & ub_ad,               &
+      & vb_ad,               &
+      & tn_ad,               &
+      & sn_ad,               &
+      & sshn_ad
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & e2u,                 &
+      & e1u,                 &
+      & e2v,                 &
+      & e1v,                 &
+      & e1t,                 &
+      & e2t,                 &
+# if defined key_vvl
+      & e3t_1,               &
+# else
+#  if defined key_zco
+      & e3t_0,               &
+#  else
+      & e3t,                 &
+#  endif
+# endif
+# if defined key_zco
+      & e3t_0,               &
+# else
+      & e3u,                 &
+      & e3v,                 &
+# endif
+      & tmask,               &
+      & umask,               &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE sbc_oce       , ONLY: & !
+      & nn_fsbc                ! Surface boundary condition: frequency of sbc computation (as well as sea-ice model)
+   USE sbc_oce_tam   , ONLY: & ! Surface boundary condition: ocean fields
+      & ssu_m_tl,            & ! mean (nn_fsbc time-step) surface sea i-current (U-point) [m/s]
+      & ssv_m_tl,            & ! mean (nn_fsbc time-step) surface sea j-current (U-point) [m/s]
+      & sst_m_tl,            & ! mean (nn_fsbc time-step) surface sea temperature     [Celsius]
+      & sss_m_tl,            & ! mean (nn_fsbc time-step) surface sea salinity            [psu]
+      & ssh_m_tl,            & ! mean (nn_fsbc time-step) surface sea height                [m]
+      & ssu_m_ad,            & ! mean (nn_fsbc time-step) surface sea i-current (U-point) [m/s]
+      & ssv_m_ad,            & ! mean (nn_fsbc time-step) surface sea j-current (U-point) [m/s]
+      & sst_m_ad,            & ! mean (nn_fsbc time-step) surface sea temperature     [Celsius]
+      & sss_m_ad,            & ! mean (nn_fsbc time-step) surface sea salinity            [psu]
+      & ssh_m_ad
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              & 
+      & nit000,              & 
+      & nitend,              & 
+      & ln_rstart
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE paresp        , ONLY: & ! Weights for an energy-type scalar product
+      & wesp_t,              &
+      & wesp_s
+   USE tstool_tam    , ONLY: &
+      & stdu,                &
+      & stdv,                &
+      & stdt,                &
+      & stds,                &
+      & stdssh,              &
+      & prntst_adj
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   sbc_ssm_tan     ! routine called by step_tam.F90
+   PUBLIC   sbc_ssm_adj     ! routine called by step_tam.F90
+   PUBLIC   sbc_ssm_adj_tst ! routine called by tst.F90
+   
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Id: sbcssm.F90 1196 2008-09-19 07:07:00Z ctlod $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE sbc_ssm_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE sbc_ssm_tan  ***
+      !!                     
+      !! ** Purpose of the direct routine:
+      !!                provide ocean surface variable to sea-surface boundary
+      !!                condition computation 
+      !!                
+      !! ** Method of the direct routine:
+      !!      compute mean surface velocity (2 components at U and 
+      !!      V-points) [m/s], temperature [Celcius] and salinity [psu] over
+      !!      the periode (kt - nn_fsbc) to kt
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt        ! ocean time step
+      !
+      REAL(wp) ::   zcoef       ! temporary scalar
+      REAL(wp) ::   zf_sbc      ! read sbc frequency 
+      !!---------------------------------------------------------------------
+      !                                                   ! ---------------------------------------- !
+      IF( nn_fsbc == 1 ) THEN                             !      Instantaneous surface fields        !
+         !                                                ! ---------------------------------------- !
+         IF( kt == nit000 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'sbc_ssm_tan: sea surface mean fields, nn_fsbc=1 : instantaneous values'
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+         ENDIF
+         !
+         ssu_m_tl(:,:) = ub_tl(:,:,1)
+         ssv_m_tl(:,:) = vb_tl(:,:,1)
+         sst_m_tl(:,:) = tn_tl(:,:,1)
+         sss_m_tl(:,:) = sn_tl(:,:,1)
+         ssh_m_tl(:,:) = sshn_tl(:,:)
+         !
+      ELSE
+         !                                                ! ---------------------------------------- !
+         IF( kt == nit000) THEN                           !       Initialisation: 1st time-step      !
+            !                                             ! ---------------------------------------- !
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'sbc_ssm_tan : sea surface mean fields'
+            !
+            IF( ln_rstart ) THEN 
+                  ssu_m_tl(:,:) = 0.0_wp
+                  ssv_m_tl(:,:) = 0.0_wp
+                  sst_m_tl(:,:) = 0.0_wp
+                  sss_m_tl(:,:) = 0.0_wp
+                  ssh_m_tl(:,:) = 0.0_wp
+             ELSE
+               IF(lwp) WRITE(numout,*) '~~~~~~~   mean fields initialised to instantaneous values'
+               zcoef = REAL( nn_fsbc - 1, wp )
+               ssu_m_tl(:,:) = zcoef * ub_tl(:,:,1)
+               ssv_m_tl(:,:) = zcoef * vb_tl(:,:,1)
+               sst_m_tl(:,:) = zcoef * tn_tl(:,:,1)
+               sss_m_tl(:,:) = zcoef * sn_tl(:,:,1)
+               ssh_m_tl(:,:) = zcoef * sshn_tl(:,:)
+            ENDIF
+            !                                             ! ---------------------------------------- !
+         ELSEIF( MOD( kt - 2 , nn_fsbc ) == 0 ) THEN      !   Initialisation: New mean computation   !
+            !                                             ! ---------------------------------------- !
+            ssu_m_tl(:,:) = 0.0_wp      ! reset to zero ocean mean sbc fields
+            ssv_m_tl(:,:) = 0.0_wp
+            sst_m_tl(:,:) = 0.0_wp
+            sss_m_tl(:,:) = 0.0_wp
+            ssh_m_tl(:,:) = 0.0_wp
+         ENDIF
+         !                                                ! ---------------------------------------- !
+         !                                                !        Cumulate at each time step        !
+         !                                                ! ---------------------------------------- !
+         ssu_m_tl(:,:) = ssu_m_tl(:,:) + ub_tl(:,:,1)
+         ssv_m_tl(:,:) = ssv_m_tl(:,:) + vb_tl(:,:,1)
+         sst_m_tl(:,:) = sst_m_tl(:,:) + tn_tl(:,:,1)
+         sss_m_tl(:,:) = sss_m_tl(:,:) + sn_tl(:,:,1)
+         ssh_m_tl(:,:) = ssh_m_tl(:,:) + sshn_tl(:,:)
+         !                                                ! ---------------------------------------- !
+         IF( MOD( kt - 1 , nn_fsbc ) == 0 ) THEN          !   Mean value at each nn_fsbc time-step   !
+            !                                             ! ---------------------------------------- !
+            zcoef = 1. / REAL( nn_fsbc, wp )
+            sst_m_tl(:,:) = sst_m_tl(:,:) * zcoef           ! mean SST             [Celcius]
+            sss_m_tl(:,:) = sss_m_tl(:,:) * zcoef           ! mean SSS             [psu]
+            ssu_m_tl(:,:) = ssu_m_tl(:,:) * zcoef           ! mean suface current  [m/s]
+            ssv_m_tl(:,:) = ssv_m_tl(:,:) * zcoef           !
+            ssh_m_tl(:,:) = ssh_m_tl(:,:) * zcoef           !
+            !
+         ENDIF
+         !
+      ENDIF
+      !
+   END SUBROUTINE sbc_ssm_tan
+
+   SUBROUTINE sbc_ssm_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE sbc_ssm_adj  ***
+      !!                     
+      !! ** Purpose of the direct routine:
+      !!                provide ocean surface variable to sea-surface boundary
+      !!                condition computation 
+      !!                
+      !! ** Method of the direct routine:
+      !!      compute mean surface velocity (2 components at U and 
+      !!      V-points) [m/s], temperature [Celcius] and salinity [psu] over
+      !!      the periode (kt - nn_fsbc) to kt
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt        ! ocean time step
+      !
+      REAL(wp) ::   zcoef       ! temporary scalar
+      REAL(wp) ::   zf_sbc      ! read sbc frequency 
+      !!---------------------------------------------------------------------
+      !                                                   ! ---------------------------------------- !
+      IF( nn_fsbc == 1 ) THEN                             !      Instantaneous surface fields        !
+         !                                                ! ---------------------------------------- !
+         IF( kt == nitend) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'sbc_ssm_adj: sea surface mean fields, nn_fsbc=1 : instantaneous values'
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+         ENDIF
+         !
+         ub_ad(:,:,1)  = ub_ad(:,:,1) + ssu_m_ad(:,:)
+         vb_ad(:,:,1)  = vb_ad(:,:,1) + ssv_m_ad(:,:)
+         tn_ad(:,:,1)  = tn_ad(:,:,1) + sst_m_ad(:,:)
+         sn_ad(:,:,1)  = sn_ad(:,:,1) + sss_m_ad(:,:)
+         sshn_ad(:,:)  = sshn_ad(:,:) + ssh_m_ad(:,:)
+         ssu_m_ad(:,:) = 0.0_wp
+         ssv_m_ad(:,:) = 0.0_wp
+         sst_m_ad(:,:) = 0.0_wp
+         sss_m_ad(:,:) = 0.0_wp
+         ssh_m_ad(:,:) = 0.0_wp
+         !
+      ELSE
+         !                                                ! ---------------------------------------- !
+         IF( MOD( kt - 1 , nn_fsbc ) == 0 ) THEN          !   Mean value at each nn_fsbc time-step   !
+            !                                             ! ---------------------------------------- !
+            zcoef = 1. / REAL( nn_fsbc, wp )
+            sst_m_ad(:,:) = sst_m_ad(:,:) * zcoef           ! mean SST             [Celcius]
+            sss_m_ad(:,:) = sss_m_ad(:,:) * zcoef           ! mean SSS             [psu]
+            ssu_m_ad(:,:) = ssu_m_ad(:,:) * zcoef           ! mean suface current  [m/s]
+            ssv_m_ad(:,:) = ssv_m_ad(:,:) * zcoef           !
+            ssh_m_ad(:,:) = ssh_m_ad(:,:) * zcoef           !
+            !
+         ENDIF
+         !                                                ! ---------------------------------------- !
+         !                                                !        Cumulate at each time step        !
+         !                                                ! ---------------------------------------- !
+         ub_ad(:,:,1) = ssu_m_ad(:,:) + ub_ad(:,:,1)
+         vb_ad(:,:,1) = ssv_m_ad(:,:) + vb_ad(:,:,1)
+         tn_ad(:,:,1) = sst_m_ad(:,:) + tn_ad(:,:,1)
+         sn_ad(:,:,1) = sss_m_ad(:,:) + sn_ad(:,:,1)
+         sshn_ad(:,:) = ssh_m_ad(:,:) + sshn_ad(:,:) 
+         !                                                ! ---------------------------------------- !
+         IF( kt == nitend) THEN                           !       Initialisation: 1st time-step      !
+            !                                             ! ---------------------------------------- !
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'sbc_ssm_adj : sea surface mean fields'
+            !
+         ENDIF
+         !                                                ! ---------------------------------------- !
+         IF( kt == nit000) THEN                           !       Initialisation: 1st time-step      !
+            !                                             ! ---------------------------------------- !
+
+            IF( ln_rstart ) THEN 
+                  ssu_m_ad(:,:) = 0.0_wp
+                  ssv_m_ad(:,:) = 0.0_wp
+                  sst_m_ad(:,:) = 0.0_wp
+                  sss_m_ad(:,:) = 0.0_wp
+                  ssh_m_ad(:,:) = 0.0_wp
+             ELSE
+               IF(lwp) WRITE(numout,*) '~~~~~~~   mean fields initialised to instantaneous values'
+               zcoef = REAL( nn_fsbc - 1, wp )
+               ub_ad(:,:,1)  = ub_ad(:,:,1) + zcoef * ssu_m_ad(:,:)
+               vb_ad(:,:,1)  = vb_ad(:,:,1) + zcoef * ssv_m_ad(:,:)
+               tn_ad(:,:,1)  = tn_ad(:,:,1) + zcoef * sst_m_ad(:,:)
+               sn_ad(:,:,1)  = sn_ad(:,:,1) + zcoef * sss_m_ad(:,:)
+               sshn_ad(:,:)  = sshn_ad(:,:) + zcoef * ssh_m_ad(:,:) 
+               ssu_m_ad(:,:) = 0.0_wp
+               ssv_m_ad(:,:) = 0.0_wp
+               sst_m_ad(:,:) = 0.0_wp
+               sss_m_ad(:,:) = 0.0_wp
+               ssh_m_ad(:,:) = 0.0_wp
+            ENDIF
+            !                                             ! ---------------------------------------- !
+         ELSEIF( MOD( kt - 2 , nn_fsbc ) == 0 ) THEN      !   Initialisation: New mean computation   !
+            !                                             ! ---------------------------------------- !
+            ssu_m_ad(:,:) = 0.0_wp      ! reset to zero ocean mean sbc fields
+            ssv_m_ad(:,:) = 0.0_wp
+            sst_m_ad(:,:) = 0.0_wp
+            sss_m_ad(:,:) = 0.0_wp
+            ssh_m_ad(:,:) = 0.0_wp
+         ENDIF
+
+         !
+      ENDIF
+      !
+   END SUBROUTINE sbc_ssm_adj
+
+   SUBROUTINE sbc_ssm_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE sbc_ssm_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action
+      !!              dx = ( un_tl, vn_tl, tn_tl, sn_tl )
+      !!              dy = ( ssu_m_tl, ssv_m_tl, sst_m_tl, sss_m_tl )
+      !!
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!        ! 09-01 (A. Weaver) cleaning
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2            ! scalar product involving the adjoint routine
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zub_tlin   ,     & ! Tangent input
+         & zvb_tlin   ,     & ! Tangent input
+         & ztn_tlin   ,     & ! Tangent input
+         & zsn_tlin   ,     & ! Tangent input
+         & zsshn_tlin ,     & ! Adjoint output
+         & zssum_tlin ,     & ! Tangent input
+         & zssvm_tlin ,     & ! Tangent input
+         & zsstm_tlin ,     & ! Tangent input
+         & zsssm_tlin ,     & ! Tangent input
+         & zsshm_tlin ,     & ! Tangent input
+         & zssum_tlout,     & ! Tangent output
+         & zssvm_tlout,     & ! Tangent output
+         & zsstm_tlout,     & ! Tangent output
+         & zsssm_tlout,     & ! Tangent output
+         & zsshm_tlout,     & ! Tangent output
+         & zub_adout  ,     & ! Adjoint input
+         & zvb_adout  ,     & ! Adjoint input
+         & ztn_adout  ,     & ! Adjoint input
+         & zsn_adout  ,     & ! Adjoint input
+         & zsshn_adout,     & ! Adjoint output
+         & zssum_adout,     & ! Adjoint input
+         & zssvm_adout,     & ! Adjoint input
+         & zsstm_adout,     & ! Adjoint input
+         & zsssm_adout,     & ! Adjoint input
+         & zsshm_adout,     & ! Adjoint input
+         & zssum_adin ,     & ! Adjoint output
+         & zssvm_adin ,     & ! Adjoint output
+         & zsstm_adin ,     & ! Adjoint output
+         & zsssm_adin ,     & ! Adjoint output
+         & zsshm_adin ,     & ! Adjoint output
+         & zr                 ! 2D random field 
+      CHARACTER(LEN=14) :: cl_name
+      ! Allocate memory
+
+      ALLOCATE(                      &
+         & zub_tlin   (jpi,jpj),     &
+         & zvb_tlin   (jpi,jpj),     &
+         & ztn_tlin   (jpi,jpj),     &
+         & zsn_tlin   (jpi,jpj),     &
+         & zsshn_tlin (jpi,jpj),     &
+         & zssum_tlin (jpi,jpj),     &
+         & zssvm_tlin (jpi,jpj),     &
+         & zsstm_tlin (jpi,jpj),     &
+         & zsssm_tlin (jpi,jpj),     &
+         & zsshm_tlin (jpi,jpj),     &
+         & zssum_tlout(jpi,jpj),     &
+         & zssvm_tlout(jpi,jpj),     &
+         & zsstm_tlout(jpi,jpj),     &
+         & zsssm_tlout(jpi,jpj),     &
+         & zsshm_tlout(jpi,jpj),     &
+         & zub_adout  (jpi,jpj),     &
+         & zvb_adout  (jpi,jpj),     &
+         & ztn_adout  (jpi,jpj),     &
+         & zsn_adout  (jpi,jpj),     &
+         & zsshn_adout(jpi,jpj),     &
+         & zssum_adout(jpi,jpj),     &
+         & zssvm_adout(jpi,jpj),     &
+         & zsstm_adout(jpi,jpj),     &
+         & zsssm_adout(jpi,jpj),     &
+         & zsshm_adout(jpi,jpj),     &
+         & zssum_adin (jpi,jpj),     &
+         & zssvm_adin (jpi,jpj),     &
+         & zsstm_adin (jpi,jpj),     &
+         & zsssm_adin (jpi,jpj),     &
+         & zsshm_adin (jpi,jpj),     &
+         & zr         (jpi,jpj)      &
+         & )
+      !==================================================================
+      ! 1) dx = ( un_tl, vn_tl, tn_tl, sn_tl ) and 
+      !    dy = ( ssu_m_tl, ssv_m_tl, sst_m_tl, sss_m_tl )
+      !==================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      zub_tlin   (:,:) = 0.0_wp     
+      zvb_tlin   (:,:) = 0.0_wp     
+      ztn_tlin   (:,:) = 0.0_wp     
+      zsn_tlin   (:,:) = 0.0_wp     
+      zssum_tlin (:,:) = 0.0_wp     
+      zssvm_tlin (:,:) = 0.0_wp     
+      zsstm_tlin (:,:) = 0.0_wp     
+      zsssm_tlin (:,:) = 0.0_wp     
+      zsshm_tlin (:,:) = 0.0_wp     
+      zssum_tlout(:,:) = 0.0_wp     
+      zssvm_tlout(:,:) = 0.0_wp     
+      zsstm_tlout(:,:) = 0.0_wp     
+      zsssm_tlout(:,:) = 0.0_wp     
+      zsshm_tlout(:,:) = 0.0_wp     
+      zub_adout  (:,:) = 0.0_wp     
+      zvb_adout  (:,:) = 0.0_wp     
+      ztn_adout  (:,:) = 0.0_wp     
+      zsn_adout  (:,:) = 0.0_wp     
+      zsshn_adout(:,:) = 0.0_wp     
+      zssum_adout(:,:) = 0.0_wp     
+      zssvm_adout(:,:) = 0.0_wp     
+      zsstm_adout(:,:) = 0.0_wp     
+      zsssm_adout(:,:) = 0.0_wp     
+      zsshm_adout(:,:) = 0.0_wp     
+      zssum_adin (:,:) = 0.0_wp     
+      zssvm_adin (:,:) = 0.0_wp     
+      zsstm_adin (:,:) = 0.0_wp     
+      zsssm_adin (:,:) = 0.0_wp     
+      zsshm_adin (:,:) = 0.0_wp     
+      zr         (:,:) = 0.0_wp      
+
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'U', 0.0_wp, stdu )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zub_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 234789 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'V', 0.0_wp, stdv ) 
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zvb_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 471426 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stds )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zsn_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO  
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 153859 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            ztn_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 237570 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdssh ) 
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zsshn_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 572840 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'U', 0.0_wp, stdu )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zssum_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 225179 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'V', 0.0_wp, stdv )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zssvm_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 264801 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt ) 
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zsstm_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 142859 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stds ) 
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zsssm_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 644869 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdssh ) 
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zsshm_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+
+      ub_tl (:,:,1) = zub_tlin  (:,:) 
+      vb_tl (:,:,1) = zvb_tlin  (:,:) 
+      tn_tl (:,:,1) = ztn_tlin  (:,:) 
+      sn_tl (:,:,1) = zsn_tlin  (:,:) 
+      sshn_tl (:,:) = zsshn_tlin(:,:) 
+      ssu_m_tl(:,:) = zssum_tlin(:,:) 
+      ssv_m_tl(:,:) = zssvm_tlin(:,:)  
+      sst_m_tl(:,:) = zsstm_tlin(:,:) 
+      sss_m_tl(:,:) = zsssm_tlin(:,:)
+      ssh_m_tl(:,:) = zsshm_tlin(:,:)
+      
+      CALL sbc_ssm_tan( nit000 + 1 )
+
+      zssum_tlout (:,:) = ssu_m_tl(:,:)
+      zssvm_tlout (:,:) = ssv_m_tl(:,:)
+      zsstm_tlout (:,:) = sst_m_tl(:,:)
+      zsssm_tlout (:,:) = sss_m_tl(:,:)
+      zsshm_tlout (:,:) = ssh_m_tl(:,:)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zssum_adin(ji,jj) = zssum_tlout(ji,jj) &
+               &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,1) &
+               &               * umask(ji,jj,1)
+            zssvm_adin(ji,jj) = zssvm_tlout(ji,jj) &
+               &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,1) &
+               &               * umask(ji,jj,1)
+            zsstm_adin(ji,jj) = zsstm_tlout(ji,jj) &
+               &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+               &               * tmask(ji,jj,1) * wesp_t(1)
+            zsssm_adin(ji,jj) = zsssm_tlout(ji,jj) &
+               &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+               &               * tmask(ji,jj,1) * wesp_s(1)
+            zsshm_adin(ji,jj) = zsshm_tlout(ji,jj) &
+               &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+               &               * tmask(ji,jj,1) * wesp_s(1)
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1 = DOT_PRODUCT( zssum_tlout, zssum_adin ) &
+         & + DOT_PRODUCT( zssvm_tlout, zssvm_adin ) &
+         & + DOT_PRODUCT( zsstm_tlout, zsstm_adin ) &
+         & + DOT_PRODUCT( zsssm_tlout, zsssm_adin ) &
+         & + DOT_PRODUCT( zsshm_tlout, zsshm_adin )
+ 
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      ssu_m_ad(:,:) = zssum_adin(:,:) 
+      ssv_m_ad(:,:) = zssvm_adin(:,:)  
+      sst_m_ad(:,:) = zsstm_adin(:,:) 
+      sss_m_ad(:,:) = zsssm_adin(:,:)
+      ssh_m_ad(:,:) = zsshm_adin(:,:)
+      ub_ad(:,:,1)  = 0.0_wp     
+      vb_ad(:,:,1)  = 0.0_wp     
+      tn_ad(:,:,1)  = 0.0_wp     
+      sn_ad(:,:,1)  = 0.0_wp     
+      sshn_ad(:,:)  = 0.0_wp     
+
+      CALL sbc_ssm_adj( nit000 + 1 )
+
+      zub_adout  (:,:) = ub_ad(:,:,1) 
+      zvb_adout  (:,:) = vb_ad(:,:,1) 
+      ztn_adout  (:,:) = tn_ad(:,:,1) 
+      zsn_adout  (:,:) = sn_ad(:,:,1) 
+      zsshn_adout(:,:) = sshn_ad(:,:)
+      zssum_adout(:,:) = ssu_m_ad(:,:) 
+      zssvm_adout(:,:) = ssv_m_ad(:,:)
+      zsstm_adout(:,:) = sst_m_ad(:,:)
+      zsssm_adout(:,:) = sss_m_ad(:,:)
+      zsshm_adout(:,:) = ssh_m_ad(:,:)
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: dx^T dx^*
+      !--------------------------------------------------------------------
+
+      zsp2 = DOT_PRODUCT( zub_tlin  , zub_adout   ) &
+         & + DOT_PRODUCT( zvb_tlin  , zvb_adout   ) &
+         & + DOT_PRODUCT( ztn_tlin  , ztn_adout   ) &
+         & + DOT_PRODUCT( zsn_tlin  , zsn_adout   ) &
+         & + DOT_PRODUCT( zsshn_tlin, zsshn_adout ) &
+         & + DOT_PRODUCT( zssum_tlin, zssum_adout ) &
+         & + DOT_PRODUCT( zssvm_tlin, zssvm_adout ) &
+         & + DOT_PRODUCT( zsstm_tlin, zsstm_adout ) &
+         & + DOT_PRODUCT( zsssm_tlin, zsssm_adout ) &
+         & + DOT_PRODUCT( zsshm_tlin, zsshm_adout )
+
+      ! 14 char:'12345678901234'
+      cl_name = 'sbc_ssm_adj   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      DEALLOCATE(           &
+         & zub_tlin   ,     & ! Tangent input
+         & zvb_tlin   ,     & ! Tangent input
+         & ztn_tlin   ,     & ! Tangent input
+         & zsn_tlin   ,     & ! Tangent input
+         & zssum_tlin ,     & ! Tangent input
+         & zssvm_tlin ,     & ! Tangent input
+         & zsstm_tlin ,     & ! Tangent input
+         & zsssm_tlin ,     & ! Tangent input
+         & zsshm_tlin ,     & ! Tangent input
+         & zssum_tlout,     & ! Tangent output
+         & zssvm_tlout,     & ! Tangent output
+         & zsstm_tlout,     & ! Tangent output
+         & zsssm_tlout,     & ! Tangent output
+         & zsshm_tlout,     & ! Tangent output
+         & zub_adout  ,     & ! Adjoint input
+         & zvb_adout  ,     & ! Adjoint input
+         & ztn_adout  ,     & ! Adjoint input
+         & zsn_adout  ,     & ! Adjoint input
+         & zssum_adout,     & ! Adjoint input
+         & zssvm_adout,     & ! Adjoint input
+         & zsstm_adout,     & ! Adjoint input
+         & zsssm_adout,     & ! Adjoint input
+         & zsshm_adout,     & ! Adjoint input
+         & zssum_adin ,     & ! Adjoint output
+         & zssvm_adin ,     & ! Adjoint output
+         & zsstm_adin ,     & ! Adjoint output
+         & zsssm_adin ,     & ! Adjoint output
+         & zsshm_adin ,     & ! Adjoint output
+         & zr               &
+         & )
+
+   END SUBROUTINE sbc_ssm_adj_tst
+#endif
+   !!======================================================================
+END MODULE sbcssm_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcssr_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcssr_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SBC/sbcssr_tam.F90	(revision 2578)
@@ -0,0 +1,414 @@
+MODULE sbcssr_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  sbcssr_tam  ***
+   !! Surface module :  add to heat and fresh water fluxes a restoring term
+   !!                   toward observed SST/SSS
+   !!                   Tangent and Adjoint Module
+   !!======================================================================
+   !! History of the direct routine:
+   !!            3.0  !  2006-06  (G. Madec)   Original code
+   !!            3.2  !  2009-04  (B. Lemaire) Introduce iom_put
+   !! History of the T&A routine:
+   !!            3.0  !  2008-11  (A. Vidard)  Original code (simplification: no linear salinity damping)
+   !!            3.2  !  2010-04  (A. Vidard)  Nemo3.2 update  
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   sbc_ssr        : add to sbc a restoring term toward SST/SSS climatology
+   !!----------------------------------------------------------------------
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 &
+      & jpiglo
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & e1t,                 &
+      & e2t,                 &
+# if defined key_vvl
+      & e3t_1,               &
+# else
+#  if defined key_zco
+      & e3t_0,               &
+#  else
+      & e3t,                 &
+#  endif
+# endif
+      & tmask,               &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej   
+   USE sbc_oce       , ONLY: & ! Surface boundary condition: ocean fields
+      & nn_fsbc
+   USE sbc_oce_tam   , ONLY: & ! Surface boundary condition: ocean fields
+      & sst_m_tl,            & ! mean (nn_fsbc time-step) surface sea temperature     [Celsius]
+      & sst_m_ad,            & ! mean (nn_fsbc time-step) surface sea temperature     [Celsius]
+      & qns_tl ,             & ! sea heat flux: non solar                 [W/m2]
+      & qns_ad              
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              & 
+      & numnam,              &
+      & nit000,              & 
+      & nitend 
+   USE gridrandom    , ONLY: &     ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & stdt,                &
+      & stdqns,              &
+      & prntst_adj
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   sbc_ssr_tan    ! routine called in sbcmod_tam
+   PUBLIC   sbc_ssr_adj    ! routine called in sbcmod_tam
+   PUBLIC   sbc_ssr_adj_tst! routine called in tst
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::  &
+     & erp_tl,    &    !: evaporation damping                          [kg/m2/s]
+     & qrp_tl,    &    !: heat flux damping                            [w/m2]
+     & erp_ad,    &    !: evaporation damping                          [kg/m2/s]
+     & qrp_ad          !: heat flux damping                            [w/m2]
+
+   !                                           !!* Namelist namsbc_ssr *
+   INTEGER, PUBLIC ::   nn_sstr     =   0       ! SST/SSS restoring indicator
+   INTEGER, PUBLIC ::   nn_sssr     =   0       ! SST/SSS restoring indicator
+   REAL(wp)        ::   rn_dqdt     = -40.e0    ! restoring factor on SST and SSS
+   REAL(wp)        ::   rn_deds     = -27.70    ! restoring factor on SST and SSS
+   LOGICAL         ::   ln_sssr_bnd = .false.   ! flag to bound erp term 
+   REAL(wp)        ::   rn_sssr_bnd =   0.e0    ! ABS(Max./Min.) value of erp term [mm/day]
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.2 , LOCEAN-IPSL (2009) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE sbc_ssr_tan( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE sbc_ssr_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!                Add to heat and/or freshwater fluxes a damping term
+      !!                toward observed SST and/or SSS.
+      !!
+      !! ** Method of the direct routine:
+      !!            : - Read namelist namsbc_ssr
+      !!              - Read observed SST and/or SSS
+      !!              - at each nscb time step
+      !!                   add a retroaction term on qns    (nn_sstr = 1)
+      !!                   add a damping term on emps       (nn_sssr = 1)
+      !!                   add a damping term on emp & emps (nn_sssr = 2)
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in   ) ::   kt   ! ocean time step
+      !!
+      INTEGER  ::   ji, jj   ! dummy loop indices
+      REAL(wp) ::   zqrptl   ! local scalar for heat flux damping
+      !!
+      !!----------------------------------------------------------------------
+      !                                               ! -------------------- !
+      IF( kt == nit000 ) THEN                         ! First call kt=nit000 !
+         !                                            ! -------------------- !
+         CALL sbc_ssr_ini_tam ( 0 )
+      ENDIF
+
+      IF( nn_sstr + nn_sssr /= 0 ) THEN
+ 
+         !                                         ! ========================= !
+         IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN      !    Add restoring term     !
+            !                                      ! ========================= !
+            !
+            IF( nn_sstr == 1 ) THEN                   !* Temperature restoring term
+!CDIR COLLAPSE
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zqrptl        = rn_dqdt * sst_m_tl(ji,jj)
+                     qns_tl(ji,jj) = qns_tl(ji,jj) + zqrptl
+                     qrp_tl(ji,jj) = zqrptl
+                  END DO
+               END DO
+            ENDIF
+            !
+            ! No linear Salinity damping term  (simplification)
+            !
+         ENDIF
+         !
+      ENDIF
+      !
+   END SUBROUTINE sbc_ssr_tan
+   SUBROUTINE sbc_ssr_adj( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE sbc_ssr_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!                Add to heat and/or freshwater fluxes a damping term
+      !!                toward observed SST and/or SSS.
+      !!
+      !! ** Method of the direct routine:
+      !!            : - Read namelist namsbc_ssr
+      !!              - Read observed SST and/or SSS
+      !!              - at each nscb time step
+      !!                   add a retroaction term on qns    (nn_sstr = 1)
+      !!                   add a damping term on emps       (nn_sssr = 1)
+      !!                   add a damping term on emp & emps (nn_sssr = 2)
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in   ) ::   kt   ! ocean time step
+      !!
+      INTEGER  ::   ji, jj   ! dummy loop indices
+      REAL(wp) ::   zqrpad   ! local scalar for heat flux damping
+      !!
+      !!----------------------------------------------------------------------
+      zqrpad = 0.0
+      !                                               ! -------------------- !
+      IF( kt == nitend ) THEN                         ! First call kt=nit000 !
+         !                                            ! -------------------- !
+         CALL sbc_ssr_ini_tam ( 1 )
+      ENDIF
+
+      IF( nn_sstr + nn_sssr /= 0 ) THEN
+ 
+         !                                         ! ========================= !
+         IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN      !    Add restoring term     !
+            !                                      ! ========================= !
+            !
+            IF( nn_sstr == 1 ) THEN                   ! Temperature restoring term
+!CDIR COLLAPSE
+               ! use zqrp scalar to optimize memory access (speedup the loop)
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zqrpad = qrp_ad(ji,jj)
+                     qrp_ad(ji,jj) = 0.0_wp
+
+                     zqrpad = zqrpad + qns_ad(ji,jj)
+                     sst_m_ad(ji,jj) = sst_m_ad(ji,jj) + rn_dqdt * zqrpad
+                  END DO
+               END DO
+            ENDIF
+            !
+            ! No linear Salinity damping term  (simplification)
+            !
+         ENDIF
+         !
+      ENDIF
+      !
+   END SUBROUTINE sbc_ssr_adj
+   SUBROUTINE sbc_ssr_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE sbc_ssr_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-11 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2            ! scalar product involving the adjoint routine
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zsst_m_tlin ,   & ! Tangent input
+         & zqns_tlin ,     & ! Tangent input
+         & zqns_tlout,     & ! Tangent output
+         & zqrp_tlout,     & ! Tangent output
+         & zqns_adin ,     & ! Adjoint input
+         & zqrp_adin ,     & ! Adjoint input
+         & zsst_m_adout,   & ! Adjoint output
+         & zqns_adout,     & ! Adjoint output
+         & zr                ! 3D random field 
+      CHARACTER(LEN=14) :: cl_name
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zqns_tlin(   jpi,jpj),   &
+         & zsst_m_tlin( jpi,jpj),   &
+         & zqns_tlout(  jpi,jpj),   &
+         & zqrp_tlout(  jpi,jpj),   &
+         & zqns_adin(   jpi,jpj),   &
+         & zqrp_adin(   jpi,jpj),   &
+         & zqns_adout(  jpi,jpj),   &
+         & zsst_m_adout(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
+      !--------------------------------------------------------------------
+          zqns_tlin(   :,:) = 0.0_wp
+          zsst_m_tlin( :,:) = 0.0_wp
+          zqns_tlout(  :,:) = 0.0_wp
+          zqrp_tlout(  :,:) = 0.0_wp
+          zqns_adin(   :,:) = 0.0_wp
+          zqrp_adin(   :,:) = 0.0_wp
+          zqns_adout(  :,:) = 0.0_wp
+          zsst_m_adout(:,:) = 0.0_wp
+          zr(          :,:) = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdqns )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zqns_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 371498 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zsst_m_tlin(ji,jj) = zr(ji,jj) 
+         END DO
+      END DO 
+
+      sst_m_tl(:,:) = zsst_m_tlin(:,:)
+      qns_tl(  :,:) = zqns_tlin(  :,:)
+
+      CALL sbc_ssr_tan (nit000)
+      zqns_tlout(:,:) = qns_tl(:,:)
+      zqrp_tlout(:,:) = qrp_tl(:,:)
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zqns_adin(ji,jj)   = zqns_tlout(ji,jj) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+                 &               * tmask(ji,jj,1)
+            END DO
+         END DO
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zqrp_adin(ji,jj)   = zqrp_tlout(ji,jj) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+                 &               * tmask(ji,jj,1)
+            END DO
+         END DO
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1 = DOT_PRODUCT( zqns_tlout, zqns_adin ) &
+         & + DOT_PRODUCT( zqrp_tlout, zqrp_adin ) 
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+      qns_ad(:,:) = zqns_adin(:,:)
+      qrp_ad(:,:) = zqrp_adin(:,:)
+      CALL sbc_ssr_adj (nit000)
+      zqns_adout(  :,:) = qns_ad(  :,:)
+      zsst_m_adout(:,:) = sst_m_ad(:,:)
+
+      zsp2 = DOT_PRODUCT( zqns_tlin,   zqns_adout   ) &
+         & + DOT_PRODUCT( zsst_m_tlin, zsst_m_adout )
+
+      ! 14 char:'12345678901234'
+      cl_name = 'sbc_ssr_adj   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      DEALLOCATE(        &
+         & zqns_tlin,    &
+         & zsst_m_tlin,  &
+         & zqns_tlout,   &
+         & zqrp_tlout,   &
+         & zqns_adin,    &
+         & zqrp_adin,    &
+         & zqns_adout,   &
+         & zsst_m_adout, &
+         & zr            &
+         & )
+
+
+
+   END SUBROUTINE sbc_ssr_adj_tst
+
+
+   SUBROUTINE sbc_ssr_ini_tam( kindic )
+      USE fldread
+      CHARACTER(len=100) ::  cn_dir          ! Root directory for location of ssr files
+      TYPE(FLD_N) ::   sn_sst, sn_sss        ! informations about the fields to be read
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(IN) :: kindic
+      NAMELIST/namsbc_ssr/ cn_dir, nn_sstr, nn_sssr, rn_dqdt, rn_deds, sn_sst, &
+         &                 sn_sss, ln_sssr_bnd, rn_sssr_bnd
+
+      REWIND ( numnam )         ! ... read in namlist namflx
+      READ( numnam, namsbc_ssr ) 
+
+      IF(lwp) THEN              ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'sbc_ssr_tam : SST and/or SSS damping term '
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '          SST restoring term (Yes=1)             nn_sstr = ', nn_sstr
+         WRITE(numout,*) '          SSS damping term (Yes=1, salt flux)    nn_sssr = ', nn_sssr
+         WRITE(numout,*) '                           (Yes=2, volume flux) '
+         WRITE(numout,*) '          dQ/dT (restoring magnitude on SST)     dqdt    = ', rn_dqdt, ' W/m2/K'
+         WRITE(numout,*) '          dE/dS (restoring magnitude on SST)     deds    = ', rn_deds, ' mm/day'
+      ENDIF
+      
+      !
+      ! Initialize qrp and erp if no restoring 
+      IF ( kindic == 0 ) THEN
+         qrp_tl(:,:) = 0.e0 
+         erp_tl(:,:) = 0.e0
+      ELSEIF ( kindic == 1 ) THEN 
+         qrp_ad(:,:) = 0.e0 
+         erp_ad(:,:) = 0.e0 
+      END IF
+   END SUBROUTINE sbc_ssr_ini_tam
+
+   !!======================================================================
+#endif
+END MODULE sbcssr_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SOL/sol_oce_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SOL/sol_oce_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SOL/sol_oce_tam.F90	(revision 2578)
@@ -0,0 +1,221 @@
+MODULE sol_oce_tam
+   !!----------------------------------------------------------------------
+   !!    This software is governed by the CeCILL licence (Version 2)
+   !!----------------------------------------------------------------------
+   !!======================================================================
+   !!                       ***  MODULE sol_oce_tam ***
+   !! NEMOVAR : variables controlling the solver for tangent and adjoint models
+   !!======================================================================
+   !! History of the direct module:
+   !!            9.0  !  02-11  (G. Madec)  F90: Free form and module
+   !! History of the TAM module:
+   !!            9.0  !  09-03  (A. Weaver) original version
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & nit000,              &
+      & nitend
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpr2di,              &
+      & jpr2dj
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!!! AW: This is the maximum number of iterations used in the balance operator
+!!      for a different elliptic equation than the one used in TAM.
+!!      Not a good idea to use the same parameter for both.
+!!
+   USE tamctl        , ONLY: & ! NEMOVAR variables for controlling the run
+      & nmax_fs
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   USE sol_oce       , ONLY: &
+      & nn_nmin
+#if defined key_dynspg_flt
+   USE solver        , ONLY: & ! Solver
+      & solver_init
+#endif
+   !! * Routine accessibility
+   
+   IMPLICIT NONE
+
+   !! * Accessibility
+   PUBLIC &
+      & sol_oce_tam_init,       & !: routine called by nemovar.F90
+      & sol_oce_tam_deallocate, &
+                    !
+      & gcx_tl,   & !: Tangent of now solution of the elliptic equation
+      & gcxb_tl,  & !: Tangent of before solution of the elliptic equation
+      & gcb_tl,   & !: Tangent of 2nd member of barotropic linear system
+      & gcr_tl,   & !: Tangent of residual =b-a.x
+      & 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
+      & nitsor
+   !! * Module variables
+   INTEGER, DIMENSION(:), ALLOCATABLE :: &
+      & nitsor      !: Number of SOR iterations
+
+   REAL(wp), DIMENSION(:,:), ALLOCATABLE :: &  
+      & gcx_tl,   & !: Tangent of now solution of the elliptic equation
+      & gcxb_tl,  & !: Tangent of before solution of the elliptic equation
+      & gcb_tl,   & !: Tangent of 2nd member of barotropic linear system
+      & gcr_tl,   & !: Tangent of residual =b-a.x
+      & 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
+
+CONTAINS
+
+   SUBROUTINE sol_oce_tam_init( kindic )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE sol_oce_tam_init  ***
+      !!
+      !! ** Purpose : 
+      !!
+      !! ** Method  : kindic = 0  allocate/initialize both tl and ad variables
+      !!                          and allocate/initialize solver
+      !!              kindic = 1  allocate/initialize only tl variables
+      !!              kindic = 2  allocate/initialize only ad variables
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 07-09 (K. Mogensen) Initial version
+      !!        ! 09-03 (A. Weaver) Allocate and intialization added
+      !!-----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & 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 ) )
+            nitsor(:) = nn_nmin
+
+         ENDIF
+
+
+      ENDIF
+      
+      IF ( kindic == 0 .OR. kindic == 1 ) THEN
+
+         IF (.NOT. ALLOCATED(gcx_tl) ) THEN
+         
+            ALLOCATE( gcx_tl (1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(gcxb_tl) ) THEN
+
+            ALLOCATE( gcxb_tl(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(gcb_tl) ) THEN
+
+            ALLOCATE( gcb_tl (1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(gcr_tl) ) THEN
+
+            ALLOCATE( gcr_tl (1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj) )
+
+         ENDIF
+
+         ! Initialize tangent linear variables arrays to zero
+         ! --------------------------------------------------
+
+         gcx_tl (:,:) = 0.0_wp
+         gcxb_tl(:,:) = 0.0_wp
+         gcb_tl (:,:) = 0.0_wp
+         gcr_tl (:,:) = 0.0_wp
+
+      ENDIF
+
+      IF ( kindic == 0 .OR. kindic == 2 ) THEN
+
+         IF (.NOT. ALLOCATED(gcx_ad) ) THEN
+         
+            ALLOCATE( gcx_ad (1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(gcxb_ad) ) THEN
+
+            ALLOCATE( gcxb_ad(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(gcb_ad) ) THEN
+ 
+            ALLOCATE( gcb_ad (1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj) )
+
+         ENDIF
+
+         ! Initialize adjoint variables arrays to zero
+         ! -------------------------------------------
+
+         gcx_ad (:,:) = 0.0_wp
+         gcxb_ad(:,:) = 0.0_wp
+         gcb_ad (:,:) = 0.0_wp
+
+      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_2_2/NEMOTAM/OPATAM_SRC/SOL/solfet_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SOL/solfet_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SOL/solfet_tam.F90	(revision 2578)
@@ -0,0 +1,79 @@
+MODULE solfet_tam
+   !!======================================================================
+   !!                       ***  MODULE solfet_tam ***
+   !! NEMOVAR : tangent and adjoint ....
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind
+   USE in_out_manager
+
+   !! * Routine accessibility
+   
+   IMPLICIT NONE
+
+   PUBLIC
+
+   !! * Module variables
+
+CONTAINS
+
+   SUBROUTINE sol_fet_tan( kt, kindic )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE sol_fet_tan  ***
+      !!
+      !! ** Purpose : 
+      !!
+      !! ** Method  : 
+      !!
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 07-09 (K. Mogensen) Initial version
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      INTEGER :: &
+         & kt,    &
+         & kindic
+      !! * Local declarations
+
+      CALL ctl_stop( 'sol_fet_tan  is not avaiable' )
+
+   END SUBROUTINE sol_fet_tan
+
+   SUBROUTINE sol_fet_adj( kt, kindic )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE sol_fet_adj  ***
+      !!
+      !! ** Purpose : 
+      !!
+      !! ** Method  : 
+      !!
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 07-09 (K. Mogensen) Initial version
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      INTEGER :: &
+         & kt,    &
+         & kindic
+      !! * Local declarations
+
+      CALL ctl_stop( 'sol_fet_adj  is not avaiable' )
+
+   END SUBROUTINE sol_fet_adj
+   
+END MODULE solfet_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SOL/solpcg_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SOL/solpcg_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SOL/solpcg_tam.F90	(revision 2578)
@@ -0,0 +1,251 @@
+MODULE solpcg_tam
+   !!======================================================================
+   !!                       ***  MODULE solpcgadj ***
+   !! NEMOVAR : tangent and adjoint .... (self adjoint)
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp        ! Variable kinds
+   USE par_oce       , ONLY: &
+      & jpi,                 &
+      & jpj,                 &
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpr2di,              &
+      & jpr2dj,              &
+      & jpiglo
+   USE in_out_manager
+   USE sol_oce       , ONLY: & ! solver variables
+      & gcdmat,              &
+      & rnorme,              &
+      & eps,                 &
+      & epsr,                &
+      & nn_nmax,             &
+      & nn_nmin,             &
+      & ncut,                &
+      & nn_nmod,             &
+      & radd,                &
+      & alph,                &
+      & beta,                &
+      & rr,                  &
+      & res,                 &
+      & rn_resmax,           &
+      & gcp,                 &
+      & gccd,                &
+      & gcdes,               &
+      & c_solver_pt,         &
+      & niter
+   USE lib_mpp       , ONLY: & ! distributed memory computing
+      & lk_mpp,              &
+      &  mpp_max
+   USE lbclnk       , ONLY: & ! ocean lateral boundary conditions (or mpp link)
+      & lbc_lnk
+   USE gridsum        , ONLY: & ! Global sums
+      & global_sum
+   USE lbclnk_tam              ! ocean lateral boundary conditions (or mpp link)
+   USE sol_oce_tam   , ONLY: & ! solver variables (assimilation)
+      & nitsor,              &
+      & gcx_tl,              & 
+      & gcb_tl,              & 
+      & gcr_tl,              & 
+      & gcx_ad,              & 
+      & gcb_ad            
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & mig,                 &
+      & mjg,                 &
+      & nimpp,               &
+      & njmpp,               &
+      & e2t,                 &
+      & e1t,                 &
+      & tmask,               &
+      & bmask,               &
+      & nlci,                &
+      & nlcj,                &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE gridrandom    , ONLY: &     ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: &     ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          &
+      & stdgc,               &
+      & prntst_tlm
+
+   !! * Routine accessibility
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC sol_pcg_adj          ! 
+   PUBLIC sol_pcg_tan          ! 
+   PUBLIC sol_pcg_adj_tst      ! 
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+
+
+CONTAINS
+
+   SUBROUTINE sol_pcg_tan( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE sol_pcg  ***
+      !!                    
+      !! ** Purpose :   Solve the ellipic equation for the transport
+      !!      divergence system  using a diagonal preconditionned
+      !!      conjugate gradient method.
+      !!
+      !! ** Method  :   Diagonal preconditionned conjugate gradient method.
+      !!      the algorithm is multitasked. (case of 5 points matrix)
+      !!      define              pa  = q^-1 * a
+      !!                        pgcb  = q^-1 * gcb
+      !!                 < . ; . >_q  = ( . )^t q ( . )
+      !!      where q is the preconditioning matrix = diagonal matrix of the
+      !!                                              diagonal elements of a
+      !!      Initialization  :
+      !!         x(o) = gcx
+      !!         r(o) = d(o) = pgcb - pa.x(o)
+      !!         rr(o)= < r(o) , r(o) >_q
+      !!      Iteration 1     :
+      !!         standard PCG algorithm
+      !!      Iteration n > 1 :
+      !!         s(n)   = pa.r(n)
+      !!         gam(n) = < r(n) , r(n) >_q
+      !!         del(n) = < r(n) , s(n) >_q
+      !!         bet(n) = gam(n) / gam(n-1)
+      !!         d(n)   = r(n) + bet(n) d(n-1)
+      !!         z(n)   = s(n) + bet(n) z(n-1) 
+      !!         sig(n) = del(n) - bet(n)*bet(n)*sig(n-1) 
+      !!         alp(n) = gam(n) / sig(n) 
+      !!         x(n+1) = x(n) + alp(n) d(n)
+      !!         r(n+1) = r(n) - alp(n) z(n)
+      !!      Convergence test :
+      !!         rr(n+1) / < gcb , gcb >_q   =< epsr
+      !!
+      !! ** Action : - niter  : solver number of iteration done
+      !!             - res    : solver residu reached
+      !!             - gcx()  : solution of the elliptic system
+      !!
+      !! References :
+      !!      Madec et al. 1988, Ocean Modelling, issue 78, 1-6.
+      !!      D Azevedo et al. 1993, Computer Science Technical Report, Tennessee U.
+      !!
+      !! History :
+      !!        !  90-10  (G. Madec)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  93-04  (M. Guyon)  loops and suppress pointers
+      !!        !  95-09  (M. Imbard, J. Escobar)  mpp exchange 
+      !!        !  96-05  (G. Madec)  merge sor and pcg formulations
+      !!        !  96-11  (A. Weaver)  correction to preconditioning
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form
+      !!        !  08-01  (R. Benshila) mpp optimization
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( inout ) ::   kindic   ! solver indicator, < 0 if the conver-
+      !                                      ! gence is not reached: the model is
+      !                                      ! stopped in step
+      !                                      ! set to zero before the call of solpcg
+      INTEGER                  ::   kt       ! current step time
+
+      CALL ctl_stop( 'sol_pcg_tan  is not avaiable' )
+
+   END SUBROUTINE sol_pcg_tan
+
+   SUBROUTINE sol_pcg_adj( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE sol_pcg  ***
+      !!                    
+      !! ** Purpose :   Solve the ellipic equation for the transport
+      !!      divergence system  using a diagonal preconditionned
+      !!      conjugate gradient method.
+      !!
+      !! ** Method  :   Diagonal preconditionned conjugate gradient method.
+      !!      the algorithm is multitasked. (case of 5 points matrix)
+      !!      define              pa  = q^-1 * a
+      !!                        pgcb  = q^-1 * gcb
+      !!                 < . ; . >_q  = ( . )^t q ( . )
+      !!      where q is the preconditioning matrix = diagonal matrix of the
+      !!                                              diagonal elements of a
+      !!      Initialization  :
+      !!         x(o) = gcx
+      !!         r(o) = d(o) = pgcb - pa.x(o)
+      !!         rr(o)= < r(o) , r(o) >_q
+      !!      Iteration 1     :
+      !!         standard PCG algorithm
+      !!      Iteration n > 1 :
+      !!         s(n)   = pa.r(n)
+      !!         gam(n) = < r(n) , r(n) >_q
+      !!         del(n) = < r(n) , s(n) >_q
+      !!         bet(n) = gam(n) / gam(n-1)
+      !!         d(n)   = r(n) + bet(n) d(n-1)
+      !!         z(n)   = s(n) + bet(n) z(n-1) 
+      !!         sig(n) = del(n) - bet(n)*bet(n)*sig(n-1) 
+      !!         alp(n) = gam(n) / sig(n) 
+      !!         x(n+1) = x(n) + alp(n) d(n)
+      !!         r(n+1) = r(n) - alp(n) z(n)
+      !!      Convergence test :
+      !!         rr(n+1) / < gcb , gcb >_q   =< epsr
+      !!
+      !! ** Action : - niter  : solver number of iteration done
+      !!             - res    : solver residu reached
+      !!             - gcx()  : solution of the elliptic system
+      !!
+      !! References :
+      !!      Madec et al. 1988, Ocean Modelling, issue 78, 1-6.
+      !!      D Azevedo et al. 1993, Computer Science Technical Report, Tennessee U.
+      !!
+      !! History :
+      !!        !  90-10  (G. Madec)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  93-04  (M. Guyon)  loops and suppress pointers
+      !!        !  95-09  (M. Imbard, J. Escobar)  mpp exchange 
+      !!        !  96-05  (G. Madec)  merge sor and pcg formulations
+      !!        !  96-11  (A. Weaver)  correction to preconditioning
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form
+      !!        !  08-01  (R. Benshila) mpp optimization
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( inout ) ::   kindic   ! solver indicator, < 0 if the conver-
+      !                                      ! gence is not reached: the model is
+      !                                      ! stopped in step
+      !                                      ! set to zero before the call of solpcg
+      INTEGER                  ::   kt       ! current step time
+
+      CALL ctl_stop( 'sol_adj_tan  is not avaiable' )
+
+   END SUBROUTINE sol_pcg_adj
+   SUBROUTINE sol_pcg_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE example_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+   END SUBROUTINE sol_pcg_adj_tst
+
+   
+END MODULE solpcg_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SOL/solsor_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SOL/solsor_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/SOL/solsor_tam.F90	(revision 2578)
@@ -0,0 +1,822 @@
+MODULE solsor_tam
+   !!======================================================================
+   !!                       ***  MODULE solsor_tam ***
+   !! NEMOVAR : Tangent linear ....
+   !!======================================================================
+   !! History :  OPA  ! 1990-10  (G. Madec)  Original code
+   !!            7.1  ! 1993-04  (G. Madec)  time filter
+   !!                 ! 1996-05  (G. Madec)  merge sor and pcg formulations
+   !!                 ! 1996-11  (A. Weaver)  correction to preconditioning
+   !!   NEMO     1.0  ! 2003-04  (C. Deltel, G. Madec)  Red-Black SOR in free form
+   !!            2.0  ! 2005-09  (R. Benshila, G. Madec)  MPI optimization
+   !! History of the  TAM:
+   !!                 !  1996-11 (A. Weaver)  correction to preconditioning
+   !!            8.2  !  2003-02 (C. Deltel) OPAVAR tangent-linear version
+   !!            9.0  !  2007-09 (K. Mogensen) tangent of the 03-04 version 
+   !!            9.0  !  2009-02 (A. Vidard)   tangent of the 05-09 version 
+   !!   NEMO     3.2  !  2010-04 (F. Vigilant) 3.2 version          
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   sol_sor_tan : Red-Black Successive Over-Relaxation solver TL
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp        ! Variable kinds
+   USE par_oce       , ONLY: &
+      & jpi,                 &
+      & jpj,                 &
+      & jpk,                 &
+      & jpr2di,              &
+      & jpr2dj,              &
+      & jpiglo
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & nit000, lwp
+   USE sol_oce       , ONLY: & ! solver variables
+      & gcdmat,              &
+      & rnorme,              &
+      & eps,                 &
+      & epsr,                &
+      & nn_nmax,                &
+      & nn_nmin,                &
+      & ncut,                &
+      & nn_nmod,                &
+      & res,                 &
+      & rn_resmax,              &
+      & gcp,                 &
+      & rn_sor,                 &
+      & nn_sol_arp,            &
+      & c_solver_pt,         &
+      & niter
+   USE lib_mpp       , ONLY: & ! distributed memory computing
+      & lk_mpp,              &
+      &  mpp_max
+   USE lbclnk       , ONLY: & ! ocean lateral boundary conditions (or mpp link)
+      & lbc_lnk_e
+   USE gridsum        , ONLY: & ! Global sums
+      & global_sum
+   USE lbclnk_tam              ! ocean lateral boundary conditions (or mpp link)
+   USE sol_oce_tam   , ONLY: & ! solver variables (assimilation)
+      & nitsor,              &
+      & gcx_tl,              & 
+      & gcb_tl,              & 
+      & gcr_tl,              & 
+      & gcx_ad,              & 
+      & gcb_ad            
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & mig,                 &
+      & mjg,                 &
+      & nimpp,               &
+      & njmpp,               &
+      & e2t,                 &
+      & e1t,                 &
+      & tmask,               &
+      & nlci,                &
+      & nlcj,                &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE gridrandom    , ONLY: &     ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: &     ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          &
+      & stdgc,               &
+      & prntst_tlm
+   
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC sol_sor_adj          ! 
+   PUBLIC sol_sor_tan          ! 
+   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
+
+   SUBROUTINE sol_sor_tan( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE sol_sor_tan : TL of sol_sor  ***
+      !!                 
+      !! ** Purpose :   Solve the ellipic equation for the transport 
+      !!      divergence system  using a red-black successive-over-
+      !!      relaxation method.
+      !!       This routine provides a MPI optimization to the existing solsor
+      !!     by reducing the number of call to lbc.
+      !! 
+      !! ** Method  :   Successive-over-relaxation method using the red-black 
+      !!      technique. The former technique used was not compatible with 
+      !!      the north-fold boundary condition used in orca configurations.
+      !!      Compared to the classical sol_sor, this routine provides a 
+      !!      mpp optimization by reducing the number of calls to lnc_lnk
+      !!      The solution is computed on a larger area and the boudary
+      !!      conditions only when the inside domain is reached.
+      !! 
+      !! References :   Madec et al. 1988, Ocean Modelling, issue 78, 1-6.
+      !!                Beare and Stevens 1997 Ann. Geophysicae 15, 1369-1377 
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in    ) ::   kt     ! Current timestep.
+      INTEGER, INTENT(inout) ::   kindic   ! solver indicator, < 0 if the convergence is not reached:
+      !                                    ! the model is stopped in step (set to zero before the call of solsor)
+      !!
+      INTEGER  ::   ji, jj, jn             ! dummy loop indices
+      INTEGER  ::   ishift, icount, istp
+      REAL(wp) ::   ztmp, zres, zres2
+      INTEGER  ::   ijmppodd, ijmppeven, ijpr2d
+      !!----------------------------------------------------------------------
+      
+      ijmppeven = MOD( nimpp+njmpp+jpr2di+jpr2dj   , 2 )
+      ijmppodd  = MOD( nimpp+njmpp+jpr2di+jpr2dj+1 , 2 )
+      ijpr2d = MAX( jpr2di, jpr2dj )
+      icount = 0
+      istp = kt - nit000 + 1
+      !                                                       ! ==============
+      DO jn = 1, nn_nmax                                         ! Iterative loop 
+         !                                                    ! ==============
+
+         IF( MOD(icount,ijpr2d+1) == 0 ) CALL lbc_lnk_e( gcx_tl, c_solver_pt, 1.0_wp )   ! lateral boundary conditions 
+
+         ! Residuals
+         ! ---------
+
+         ! Guess black update
+         DO jj = 2-jpr2dj, nlcj - 1 + jpr2dj
+            ishift = MOD( jj-ijmppodd-jpr2dj, 2 )
+            DO ji = 2-jpr2di+ishift, nlci - 1 + jpr2di, 2
+               ztmp =                  gcb_tl(ji  ,jj  )   &
+                  &   - gcp(ji,jj,1) * gcx_tl(ji  ,jj-1)   &
+                  &   - gcp(ji,jj,2) * gcx_tl(ji-1,jj  )   &
+                  &   - gcp(ji,jj,3) * gcx_tl(ji+1,jj  )   &
+                  &   - gcp(ji,jj,4) * gcx_tl(ji  ,jj+1)
+               ! Estimate of the residual
+               zres = ztmp - gcx_tl(ji,jj)
+               gcr_tl(ji,jj) = zres * gcdmat(ji,jj) * zres
+               ! Guess update
+               gcx_tl(ji,jj) = rn_sor * ztmp + ( 1.0_wp - rn_sor ) * gcx_tl(ji,jj)
+            END DO
+         END DO
+         icount = icount + 1 
+ 
+         IF( MOD(icount,ijpr2d+1) == 0 ) CALL lbc_lnk_e( gcx_tl, c_solver_pt, 1.0_wp )   ! lateral boundary conditions 
+
+         ! Guess red update
+        DO jj = 2-jpr2dj, nlcj-1+jpr2dj
+            ishift = MOD( jj-ijmppeven-jpr2dj, 2 )
+            DO ji = 2-jpr2di+ishift, nlci-1+jpr2di, 2
+               ztmp =                  gcb_tl(ji  ,jj  )   &
+                  &   - gcp(ji,jj,1) * gcx_tl(ji  ,jj-1)   &
+                  &   - gcp(ji,jj,2) * gcx_tl(ji-1,jj  )   &
+                  &   - gcp(ji,jj,3) * gcx_tl(ji+1,jj  )   &
+                  &   - gcp(ji,jj,4) * gcx_tl(ji  ,jj+1) 
+               ! Estimate of the residual
+               zres = ztmp - gcx_tl(ji,jj)
+               gcr_tl(ji,jj) = zres * gcdmat(ji,jj) * zres
+               ! Guess update
+               gcx_tl(ji,jj) = rn_sor * ztmp + ( 1.0_wp - rn_sor ) * gcx_tl(ji,jj)
+            END DO
+         END DO
+         icount = icount + 1
+      
+         ! test of convergence
+         IF ( jn > nn_nmin .AND. MOD( jn-nn_nmin, nn_nmod ) == 0 .OR. jn == nn_nmax ) THEN
+
+            SELECT CASE ( nn_sol_arp )
+            CASE ( 0 )
+               ! absolute precision (maximum value of the residual)
+               zres2 = MAXVAL( gcr_tl(2:nlci - 1,2:nlcj - 1) )
+               IF( lk_mpp )  CALL mpp_max( zres2 ) ! max over the global domain
+               ! test of convergence
+               IF( zres2 < rn_resmax .OR. jn == nn_nmax ) THEN
+                  res = SQRT( zres2 )
+                  niter = jn
+                  ncut = 999
+                  ! Store number of iterations for adjoint computation
+                  istp = kt - nit000 + 1
+                  nitsor(istp) = niter
+               ENDIF
+            CASE ( 1 )                 ! relative precision
+!               rnorme = SUM( gcr_tl(2:nlci - 1,2:nlcj - 1) )
+!               IF( lk_mpp ) CALL mpp_sum( rnorme ) ! sum over global domain
+               rnorme = global_sum(gcr_tl)
+               ! test of convergence
+               IF( rnorme < epsr .OR. jn == nn_nmax ) THEN
+                  res = SQRT( rnorme )
+                  niter = jn
+                  ncut = 999
+                  ! Store number of iterations for adjoint computation
+                  istp = kt - nit000 + 1
+                  nitsor(istp) = niter
+               ENDIF
+            END SELECT
+
+            !****
+            ! IF(lwp)WRITE(numsol,9300) jn, res, sqrt( epsr ) / eps
+!9300        FORMAT('          niter :',i6,' res :',e20.10,' b :',e20.10)
+            !****
+         
+         ENDIF
+         ! indicator of non-convergence or explosion
+         IF( jn == nn_nmax ) nitsor(istp) = jn
+         IF( jn == nn_nmax .OR. SQRT(epsr)/eps > 1.e+20 ) kindic = -2
+
+         IF( ncut == 999 ) GOTO 999
+         
+         !                                              ! =====================
+      END DO                                            ! END of iterative loop
+      !                                                 ! =====================
+
+999   CONTINUE
+    
+      !  Output in gcx_tl
+      !  ----------------
+
+      CALL lbc_lnk_e( gcx_tl, c_solver_pt, 1.0_wp )    ! Lateral BCs
+
+   END SUBROUTINE sol_sor_tan
+   SUBROUTINE sol_sor_adj( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE sol_sor_adj : adjoint of sol_sor  ***
+      !!                 
+      !! ** Purpose :   Solve the ellipic equation for the transport 
+      !!      divergence system  using a red-black successive-over-
+      !!      relaxation method.
+      !!       This routine provides a MPI optimization to the existing solsor
+      !!     by reducing the number of call to lbc.
+      !! 
+      !! ** Method  :   Successive-over-relaxation method using the red-black 
+      !!      technique. The former technique used was not compatible with 
+      !!      the north-fold boundary condition used in orca configurations.
+      !!      Compared to the classical sol_sor, this routine provides a 
+      !!      mpp optimization by reducing the number of calls to lnc_lnk
+      !!      The solution is computed on a larger area and the boudary
+      !!      conditions only when the inside domain is reached.
+      !! 
+      !! References :   Madec et al. 1988, Ocean Modelling, issue 78, 1-6.
+      !!                Beare and Stevens 1997 Ann. Geophysicae 15, 1369-1377
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in    ) ::   kt       ! Current timestep.
+      INTEGER, INTENT( inout ) ::   kindic   ! solver indicator, < 0 if the conver-
+      !                                      ! gence is not reached: the model is
+      !                                      ! stopped in step
+      !                                      ! set to zero before the call of solsor
+      INTEGER  ::   ji, jj, jn               ! dummy loop indices
+      INTEGER  ::   ishift, icount, istp, iter, ilower
+
+      INTEGER  ::   ijmppodd, ijmppeven, ijpr2d
+     !!----------------------------------------------------------------------
+      
+      ijmppeven = MOD(nimpp+njmpp+jpr2di+jpr2dj,2)
+      ijmppodd  = MOD(nimpp+njmpp+jpr2di+jpr2dj+1,2)
+      ijpr2d = MAX(jpr2di,jpr2dj)
+
+      ! Fixed number of iterations
+      istp = kt - nit000 + 1
+      iter = nitsor(istp)
+      icount = iter * 2
+
+      !  Output in gcx_ad
+      !  ----------------
+
+      CALL lbc_lnk_e_adj( gcx_ad, c_solver_pt, 1.0_wp )    ! Lateral BCs
+      !                                                    ! ==============
+      DO jn = iter, 1, -1                                  ! Iterative loop 
+         !                                                 ! ==============
+         ! Guess red update
+         DO jj =  nlcj-1+jpr2dj, 2-jpr2dj, -1
+            ishift = MOD( jj-ijmppeven-jpr2dj, 2 )
+            ilower = 2-jpr2dj+ishift + 2 * INT( ( ( nlci-1+jpr2dj )-( 2-jpr2dj+ishift ) ) / 2 )
+            DO ji = ilower, 2-jpr2dj+ishift, -2
+               gcb_ad(ji  ,jj  ) = gcb_ad(ji  ,jj  ) + rn_sor * gcx_ad(ji,jj)
+               
+               gcx_ad(ji  ,jj-1) = gcx_ad(ji  ,jj-1) - rn_sor * gcx_ad(ji,jj) &
+                  &                                           * gcp(ji,jj,1)
+               gcx_ad(ji-1,jj  ) = gcx_ad(ji-1,jj  ) - rn_sor * gcx_ad(ji,jj) &
+                  &                                           * gcp(ji,jj,2)
+               gcx_ad(ji+1,jj  ) = gcx_ad(ji+1,jj  ) - rn_sor * gcx_ad(ji,jj) &
+                  &                                           * gcp(ji,jj,3)
+               gcx_ad(ji  ,jj+1) = gcx_ad(ji  ,jj+1) - rn_sor * gcx_ad(ji,jj) &
+                  &                                           * gcp(ji,jj,4)
+               gcx_ad(ji  ,jj  ) = gcx_ad(ji  ,jj  ) * ( 1.0_wp - rn_sor )
+            END DO
+         END DO
+         icount = icount - 1 
+         
+         IF( MOD(icount,ijpr2d+1) == 0 ) CALL lbc_lnk_e_adj( gcx_ad, c_solver_pt, 1.0_wp )   ! Lateral BCs
+
+         ! Residus
+         ! -------
+
+         ! Guess black update
+         DO jj = nlcj - 1+jpr2dj, 2-jpr2dj, -1
+            ishift = MOD( jj-ijmppodd-jpr2dj, 2 )
+            ilower = 2-jpr2dj+ishift + 2 * INT( ( ( nlci-1+jpr2dj )-( 2-jpr2dj+ishift ) ) / 2 )
+            DO ji = ilower, 2-jpr2dj+ishift, -2
+               gcb_ad(ji  ,jj  ) = gcb_ad(ji  ,jj  ) + rn_sor * gcx_ad(ji,jj)
+               gcx_ad(ji  ,jj-1) = gcx_ad(ji  ,jj-1) - rn_sor * gcx_ad(ji,jj) &
+                  &                                           * gcp(ji,jj,1)
+               gcx_ad(ji-1,jj  ) = gcx_ad(ji-1,jj  ) - rn_sor * gcx_ad(ji,jj) &
+                  &                                           * gcp(ji,jj,2)
+               gcx_ad(ji+1,jj  ) = gcx_ad(ji+1,jj  ) - rn_sor * gcx_ad(ji,jj) &
+                  &                                           * gcp(ji,jj,3)
+               gcx_ad(ji  ,jj+1) = gcx_ad(ji  ,jj+1) - rn_sor * gcx_ad(ji,jj) &
+                  &                                           * gcp(ji,jj,4)
+               gcx_ad(ji  ,jj  ) = gcx_ad(ji  ,jj  ) * ( 1.0_wp - rn_sor )
+            END DO
+         END DO
+
+         icount = icount - 1 
+ 
+         IF( MOD(icount,ijpr2d+1) == 0 ) CALL lbc_lnk_e_adj( gcx_ad, c_solver_pt, 1.0_wp )   ! Lateral BCs
+         !                                              ! =====================
+      END DO                                            ! END of iterative loop
+      !                                                 ! =====================
+   END SUBROUTINE sol_sor_adj
+   SUBROUTINE sol_sor_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE example_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk,    &        
+         & kindic,&        ! flags fo solver convergence
+         & kmod,  &        ! frequency of test for the SOR solver
+         & kt              ! number of iteration
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2            ! scalar product involving the adjoint routine
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zgcb_tlin ,     & ! Tangent input
+         & zgcx_tlin ,     & ! Tangent input
+         & zgcx_tlout,     & ! Tangent output
+         & zgcx_adin ,     & ! Adjoint input
+         & zgcb_adout,     & ! Adjoint output
+         & zgcx_adout,     & ! Adjoint output
+         & zr             ! 3D random field 
+      CHARACTER(LEN=14) :: cl_name
+      ! Allocate memory
+
+
+      ALLOCATE( &
+         & zgcb_tlin( jpi,jpj),     &
+         & zgcx_tlin( jpi,jpj),     &
+         & zgcx_tlout(jpi,jpj),     &
+         & zgcx_adin( jpi,jpj),     &
+         & zgcx_adout(jpi,jpj),     &
+         & zgcb_adout(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
+      zgcx_tlout(:,:) = 0.0_wp
+      zgcx_adin( :,:) = 0.0_wp
+      zgcx_adout(:,:) = 0.0_wp
+      zgcb_adout(:,:) = 0.0_wp
+      zr(        :,:) = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      kt=nit000
+      kindic=0
+!      kmod = nn_nmod  ! store frequency of test for the SOR solver
+!      nn_nmod = 1     ! force frequency to one (remove adj_tst dependancy to nn_nmin)
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, 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
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 264792 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, 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
+
+      ncut = 1 ! reinitilize the solver convergence flag
+      gcr_tl(:,:) = 0.0_wp
+      gcb_tl(:,:) = zgcb_tlin(:,:)
+      gcx_tl(:,:) = zgcx_tlin(:,:)
+      CALL sol_sor_tan(kt, kindic) 
+      zgcx_tlout(:,:) = gcx_tl(:,:)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zgcx_adin(ji,jj) = zgcx_tlout(ji,jj)         &
+               &               * e1t(ji,jj) * e2t(ji,jj) &
+               &               * tmask(ji,jj,1)
+         END DO
+      END DO
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1 = DOT_PRODUCT( zgcx_tlout, zgcx_adin ) 
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      gcb_ad(:,:) = 0.0_wp
+      gcx_ad(:,:) = zgcx_adin(:,:)
+      CALL sol_sor_adj(kt, kindic) 
+      zgcx_adout(:,:) = gcx_ad(:,:)
+      zgcb_adout(:,:) = gcb_ad(:,:)
+     
+
+      zsp2 = DOT_PRODUCT( zgcx_tlin, zgcx_adout ) &
+         & + DOT_PRODUCT( zgcb_tlin, zgcb_adout )
+
+      ! 14 char:'12345678901234'
+      cl_name = 'sol_sor_adj   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+!      nn_nmod = kmod  ! restore initial frequency of test for the SOR solver
+
+      DEALLOCATE(      &
+         & zgcb_tlin,  &
+         & zgcx_tlin,  &
+         & zgcx_tlout, &
+         & zgcx_adin,  &
+         & zgcx_adout, &
+         & zgcb_adout, &
+         & zr          &
+         & )
+
+   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 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 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_2_2/NEMOTAM/OPATAM_SRC/TAM/trj_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TAM/trj_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TAM/trj_tam.F90	(revision 2578)
@@ -0,0 +1,924 @@
+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 zdfbfr,    ONLY:&  ! bottom friction
+      & bfrua,         &
+      & bfrva
+   USE trc_oce       , ONLY: & ! share SMS/Ocean variables
+      & etot3
+   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 sshwzv, ONLY : &  !  vertical velocity
+      & ssh_wzv
+  
+   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 :: &
+      & cn_tantrj                                  !: Filename for storing the 
+                                                   !: linear-tangent trajectory
+   INTEGER, PUBLIC :: &          
+      & nn_ittrjfrq_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,   &
+      & bfruar1,  &
+      & bfrvar1,  &   
+      & bfruar2,  &
+      & bfrvar2
+#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,    &
+      & etot3r1,  &
+      & unr2,     &
+      & vnr2,     &
+      & tnr2,     &
+      & snr2,     &
+      & avmur2,   &
+      & avmvr2,   &
+      & avtr2,    &
+      & uslpr2,   &
+      & vslpr2,   &
+      & wslpir2,  &
+      & wslpjr2,  &
+      & avsr2,    &
+      & etot3r2
+  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/ nn_ittrjfrq_tan, ln_trjwri_tan, cn_tantrj
+
+      ln_trjwri_tan = .FALSE.
+      nn_ittrjfrq_tan = 1
+      cn_tantrj = 'tl_trajectory'
+      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                          ', &
+            &            ' nn_ittrjfrq_tan = ', nn_ittrjfrq_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)
+      !!        ! 2010-04 (F. Vigilant) converison to 3.2
+      !!-----------------------------------------------------------------------
+      !! * 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_dirtrj
+      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, nn_ittrjfrq ) == 0 )  ) THEN       
+
+         it = kstp - nit000 + 1
+
+         IF ( inumtrj1 == -1 ) THEN
+
+            ! Define the input file 
+            WRITE(cl_dirtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( cn_dirtrj ), '_', it
+
+            !         WRITE(cl_dirtrj, FMT='(A,".nc")' ) TRIM( c_dirtrj )
+            cl_dirtrj = TRIM( cl_dirtrj )
+
+            IF(lwp) THEN
+
+               WRITE(numout,*)
+               WRITE(numout,*)'Reading non-linear fields from : ',TRIM(cl_dirtrj)
+               WRITE(numout,*)
+
+            ENDIF
+            CALL iom_open( cl_dirtrj, 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), &
+               & bfruar1(jpi,jpj),&
+               & bfrvar1(jpi,jpj),&
+               & bfruar2(jpi,jpj),&
+               & bfrvar2(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),    &
+               & etot3r1(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),    &
+               & etot3r2(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 ) / nn_ittrjfrq ) + 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  (:,:)
+            bfruar2  (:,:)  = bfruar1 (:,:)
+            bfrvar2  (:,:)  = bfrvar1 (:,:)
+
+            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
+            etot3r2 (:,:,:) = etot3r1 (:,:,:)
+#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_dirtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( cn_dirtrj ), '_', (it-nn_ittrjfrq)
+            cl_dirtrj = TRIM( cl_dirtrj )
+            IF(lwp) THEN
+               WRITE(numout,*)
+               WRITE(numout,*)'Reading non-linear fields from : ',TRIM(cl_dirtrj)
+               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) * nn_ittrjfrq
+
+            ! bug fixed to read several time the initial data
+            IF ( ( kstp - nit000 + 1 == 0 ) .AND. ( kdir == 1 ) ) THEN
+               ! Define the input file 
+               WRITE(cl_dirtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( cn_dirtrj ), '_', it
+
+               cl_dirtrj = TRIM( cl_dirtrj )
+
+               IF(lwp) THEN
+                  WRITE(numout,*)
+                  WRITE(numout,*)'Reading non-linear fields from : ',TRIM(cl_dirtrj)
+                  WRITE(numout,*)
+               ENDIF
+            END IF
+            IF ( inumtrj1 /= -1 )   CALL iom_open( cl_dirtrj, 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 )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'bfrua' , bfruar1 , inrc )
+            CALL iom_get( inumtrj1, jpdom_autoglo, 'bfrva' , bfrvar1 , 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, 'etot3' , etot3r1 , 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  (:,:)
+            bfruar1 (:,:)   = bfruar2 (:,:)
+            bfrvar1 (:,:)   = bfrvar2 (:,:)
+            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
+            etot3r1 (:,:,:) = etot3r2 (:,:,:)
+#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_dirtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( cn_dirtrj ), '_', (it)
+               ELSE      
+                  WRITE(cl_dirtrj, FMT='(A,A,I5.5,".nc")' ) TRIM( cn_dirtrj ), '_', (it+nn_ittrjfrq)
+               ENDIF
+               cl_dirtrj = TRIM( cl_dirtrj )
+
+               IF(lwp) THEN        
+                  WRITE(numout,*)
+                  WRITE(numout,*)'Reading non-linear fields from : ',TRIM(cl_dirtrj)
+                  WRITE(numout,*)        
+               ENDIF
+
+               CALL iom_open( cl_dirtrj, inumtrj2 ) 
+
+
+            inrcp = inrcm + 1
+            !            inrc  = inrcp
+            inrc = 1  ! temporary  fix
+
+            stpr2 = (inrcp - 1) * nn_ittrjfrq 
+            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 )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'bfrua' , bfruar2 , inrc )
+            CALL iom_get( inumtrj2, jpdom_autoglo, 'bfrva' , bfrvar2 , 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, 'etot3' , etot3r2 , 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, nn_ittrjfrq ) /= 0 )  ) THEN
+          IF(lwp) WRITE(numout,*) '   Warning ! nitend (=',nitend, ')', &
+               &                  ' and saving frequency (=',nn_ittrjfrq,') 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  (:,:)
+      bfrua(:,:)    = zwtr1 * bfruar1 (:,:)   + zwtr2 * bfruar2 (:,:)
+      bfrva(:,:)    = zwtr1 * bfrvar1 (:,:)   + zwtr2 * bfrvar2 (:,:)
+      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
+      etot3(:,:,:)  = zwtr1 * etot3r1 (:,:,:) + zwtr2 * etot3r2 (:,:,:)
+#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 ssh_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, nn_ittrjfrq_tan ) == 0 )  ) THEN       
+
+         it = kstp - nit000 + 1
+
+            ! Define the input file 
+            WRITE(cl_tantrj, FMT='(A,A,I5.5,".nc")' ) TRIM( cn_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, &
+               & bfruar1,&
+               & bfrvar1,&
+               & bfruar2,&
+               & bfrvar2 &
+               & )
+
+            DEALLOCATE(    &
+               & unr1,     &
+               & vnr1,     &
+               & tnr1,     &
+               & snr1,     &
+               & avmur1,   &
+               & avmvr1,   &
+               & avtr1,    &
+               & etot3r1,  &
+               & unr2,     &
+               & vnr2,     &
+               & tnr2,     &
+               & snr2,     &
+               & avmur2,   &
+               & avmvr2,   &
+               & avtr2,    &
+               & etot3r2   &
+               & )
+
+#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_2_2/NEMOTAM/OPATAM_SRC/TRA/eosbn2_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/eosbn2_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/eosbn2_tam.F90	(revision 2578)
@@ -0,0 +1,4593 @@
+MODULE eosbn2_tam
+   !!==============================================================================
+   !!                       ***  MODULE  eosbn2_tam  ***
+   !! Ocean diagnostic variable : equation of state - in situ and potential density
+   !!                                               - Brunt-Vaisala frequency
+   !!                             Tangent and Adjoint Module
+   !!===========================================================================   
+   !! History of the direct Module :
+   !!            OPA  ! 1989-03  (O. Marti)  Original code
+   !!            6.0  ! 1994-07  (G. Madec, M. Imbard)  add bn2
+   !!            6.0  ! 1994-08  (G. Madec)  Add Jackett & McDougall eos
+   !!            7.0  ! 1996-01  (G. Madec)  statement function for e3
+   !!            8.1  ! 1997-07  (G. Madec)  density instead of volumic mass
+   !!             -   ! 1999-02  (G. Madec, N. Grima) semi-implicit pressure gradient
+   !!            8.2  ! 2001-09  (M. Ben Jelloul)  bugfix on linear eos
+   !!   NEMO     1.0  ! 2002-10  (G. Madec)  add eos_init
+   !!             -   ! 2002-11  (G. Madec, A. Bozec)  partial step, eos_insitu_2d
+   !!             -   ! 2003-08  (G. Madec)  F90, free form
+   !!            3.0  ! 2006-08  (G. Madec)  add tfreez function
+   !!                 ! 2003-09  (M. Balmaseda) compute refrence rho prof
+   !! History of the TAM Module :
+   !!             8.2 ! 2005-03  (F. Van den Berghe, A. Weaver, N. Daget)
+   !!                                              - eostan.F
+   !!             9.0 ! 2007-07  (K. Mogensen) Initial version based on eostan.F
+   !!                 ! 2008-07 (A. Vidard) bug fix in computation of prd_tl if neos=1
+   !!                 ! 2008-11  (A. Vidard) TAM of the 06-08 version
+   !!  NEMO       3.2 ! 2010-04  (F. Vigilant) version 3.2
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !! Direct subroutines
+   !!   eos            : generic interface of the equation of state
+   !!   eos_insitu     : Compute the in situ density
+   !!   eos_insitu_pot : Compute the insitu and surface referenced potential
+   !!                    volumic mass
+   !!   eos_insitu_2d  : Compute the in situ density for 2d fields
+   !!   eos_insitu_pot_1pt : Compute the in situ density for a single point
+   !!   eos_bn2        : Compute the Brunt-Vaisala frequency
+   !!   tfreez         : Compute the surface freezing temperature (NOT IN TAM)
+   !!   eos_init       : set eos parameters (namelist)
+   !!   eos_rprof      : Compute the in situ density of a reference profile
+   !!----------------------------------------------------------------------
+   !! * Modules used
+#if defined key_zdfddm
+   USE oce_tam       , ONLY: &
+      & rrau_tl,             &
+      & rrau_ad
+#endif
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & tmask,               &
+      & e1t,                 &
+      & e2t,                 &
+#if defined key_zco
+      & e3t_0,               &
+      & e3w_0,               &
+      & gdept_0,             &
+      & gdepw_0,             &
+#else
+      & e3t,                 &
+      & e3w,                 &
+      & gdept,               &
+      & gdepw,               &
+#endif
+      & mig,                 &
+      & mjg,                 &
+      & nperio,              &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej   
+   USE par_kind      , ONLY: &
+      & wp
+   USE par_oce       , ONLY: &
+      & jpi,                 &
+      & jpj,                 &
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1,               &
+      & jpiglo
+   USE oce           , ONLY: &
+      & tn,                  &
+      & sn
+   USE phycst        , ONLY: & ! physical constants
+      & rau0,                &
+      & grav
+   USE in_out_manager, ONLY: & ! I/O manager
+      & lwp,                 &
+      & ctmp1,               &
+      & numout,              &
+      & ctl_stop
+#if defined key_zdfddm
+   USE zdfddm          ! vertical physics: double diffusion
+#endif
+   USE eosbn2        , ONLY: &
+      & eos_init,            &
+      & neos_init,           &
+      & nn_eos,              &
+      & rn_alpha,            &
+      & rn_beta,             &
+      & ralpbet
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          &
+      & prntst_tlm,          & !
+      & stds,                &
+      & stdt   
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Interface 
+    INTERFACE eos_tan
+       MODULE PROCEDURE eos_insitu_tan, eos_insitu_pot_tan, eos_pot_1pt_tan, eos_insitu_2d_tan
+    END INTERFACE 
+    INTERFACE eos_adj
+       MODULE PROCEDURE eos_insitu_adj, eos_insitu_pot_adj, eos_pot_1pt_adj, eos_insitu_2d_adj
+    END INTERFACE 
+   INTERFACE bn2_tan
+      MODULE PROCEDURE eos_bn2_tan
+   END INTERFACE 
+   INTERFACE bn2_adj
+      MODULE PROCEDURE eos_bn2_adj
+   END INTERFACE 
+
+   !! * Routine accessibility
+   PUBLIC eos_tan    ! called by step.F90, inidtr.F90, tranpc.F90 and intgrd.F90
+   PUBLIC bn2_tan    ! called by step.F90
+   PUBLIC eos_adj    ! called by step.F90, inidtr.F90, tranpc.F90 and intgrd.F90
+   PUBLIC bn2_adj    ! called by step.F90
+#if defined key_tam
+   PUBLIC eos_adj_tst
+   PUBLIC bn2_adj_tst
+#if defined key_tst_tlm
+   PUBLIC eos_tlm_tst
+   PUBLIC bn2_tlm_tst
+#endif
+#endif
+   
+   
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE eos_insitu_tan( ptem, psal, ptem_tl, psal_tl, prd_tl )
+      !!-----------------------------------------------------------------------
+      !!
+      !!        ***  ROUTINE eos_insitu_tan : TL OF ROUTINE   eos_insitu ***
+      !!
+      !! ** Purpose of direct routine   : Compute the in situ density 
+      !!       (ratio rho/rau0) from potential temperature and salinity 
+      !!       using an equation of state defined through the namelist 
+      !!       parameter nn_eos.
+      !!
+      !! ** Method of direct routine    : 3 cases:
+      !!      nn_eos = 0 : Jackett and McDougall (1994) equation of state.
+      !!         the in situ density is computed directly as a function of
+      !!         potential temperature relative to the surface (the opa t
+      !!         variable), salt and pressure (assuming no pressure variation
+      !!         along geopotential surfaces, i.e. the pressure p in decibars
+      !!         is approximated by the depth in meters.
+      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
+      !!         with pressure                      p        decibars
+      !!              potential temperature         t        deg celsius
+      !!              salinity                      s        psu
+      !!              reference volumic mass        rau0     kg/m**3
+      !!              in situ volumic mass          rho      kg/m**3
+      !!              in situ density anomalie      prd      no units
+      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
+      !!          t = 40 deg celcius, s=40 psu
+      !!      nn_eos = 1 : linear equation of state function of temperature only
+      !!              prd(t) = 0.0285 - rn_alpha * t
+      !!      nn_eos = 2 : linear equation of state function of temperature and
+      !!               salinity
+      !!              prd(t,s) = rn_beta * s - rn_alpha * tn - 1.
+      !!      Note that no boundary condition problem occurs in this routine
+      !!      as (ptem,psal) are defined over the whole domain.
+      !!
+      !! ** Comments on Adjoint Routine : 
+      !!      Care has been taken to avoid division by zero when computing 
+      !!      the inverse of the square root of salinity at masked salinity 
+      !!      points.
+      !!
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         & ptem,                 &  ! potential temperature
+         & psal,                 &  ! salinity
+         & ptem_tl,              &  ! TL of potential temperature
+         & psal_tl                  ! TL of salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   &
+         & prd_tl                   ! TL of potential density (surface referenced)
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   &             ! temporary scalars
+         zt, zs, zh, zsr, zr1, zr2, zr3, zr4, zrhop, ze, zbw,   &
+         zb, zd, zc, zaw, za, zb1, za1, zkw, zk0,               &
+         zttl, zstl, zhtl, zsrtl, zr1tl, zr2tl, zr3tl,          &
+         zr4tl, zrhoptl, zetl, zbwtl,                           &
+         zbtl, zdtl, zctl, zawtl, zatl, zb1tl, za1tl,           &
+         zkwtl, zk0tl, zpes, zrdc1, zrdc2, zeps,                &
+         zmask, zrau0r
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zws
+      !!----------------------------------------------------------------------
+
+      SELECT CASE ( nn_eos )
+
+      CASE ( 0 )               !== Jackett and McDougall (1994) formulation ==!
+         zrau0r = 1.e0 / rau0
+#ifdef key_sp
+         zeps = 1.e-7
+#else
+         zeps = 1.e-14
+#endif
+
+!CDIR NOVERRCHK
+         zws(:,:,:) = SQRT( ABS( psal(:,:,:) ) )
+         !
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  zh = fsdept(ji,jj,jk)        ! depth
+                  zsr= zws(ji,jj,jk)           ! square root salinity
+                  ! compute volumic mass pure water at atm pressure
+                  zr1= ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt   &
+                     -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
+                  ! seawater volumic mass atm pressure
+                  zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 ) *zt+7.6438e-5 ) *zt   &
+                     -4.0899e-3 ) *zt+0.824493
+                  zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
+                  zr4= 4.8314e-4
+
+                  ! potential volumic mass (reference to the surface)
+                  zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
+
+                  ! add the compression terms
+                  ze = ( -3.508914e-8*zt-1.248266e-8 ) *zt-2.595994e-6
+                  zbw= (  1.296821e-6*zt-5.782165e-9 ) *zt+1.045941e-4
+                  zb = zbw + ze * zs
+
+                  zd = -2.042967e-2
+                  zc =   (-7.267926e-5*zt+2.598241e-3 ) *zt+0.1571896
+                  zaw= ( ( 5.939910e-6*zt+2.512549e-3 ) *zt-0.1028859 ) *zt - 4.721788
+                  za = ( zd*zsr + zc ) *zs + zaw
+
+                  zb1=   (-0.1909078*zt+7.390729 ) *zt-55.87545
+                  za1= ( ( 2.326469e-3*zt+1.553190)*zt-65.00517 ) *zt+1044.077
+                  zkw= ( ( (-1.361629e-4*zt-1.852732e-2 ) *zt-30.41638 ) *zt + 2098.925 ) *zt+190925.6
+                  zk0= ( zb1*zsr + za1 )*zs + zkw
+
+                  ! Tangent linear part
+
+                  zttl = ptem_tl(ji,jj,jk)
+                  zstl = psal_tl(ji,jj,jk)
+
+                  zsrtl= ( 1.0 / MAX( 2.*zsr, zeps ) ) &
+                     &   * tmask(ji,jj,jk)                * zstl
+
+                  zr1tl= ( ( ( (  5.*6.536332e-9   * zt &
+                     &           -4.*1.120083e-6 ) * zt &
+                     &           +3.*1.001685e-4 ) * zt &
+                     &           -2.*9.095290e-3 ) * zt &
+                     &           +   6.793952e-2        ) * zttl
+
+                  zr2tl= ( ( (    4.*5.3875e-9   * zt &
+                     &           -3.*8.2467e-7 ) * zt &
+                     &           +2.*7.6438e-5 ) * zt &
+                     &           -   4.0899e-3        ) * zttl
+
+                  zr3tl= (       -2.*1.6546e-6   * zt &
+                     &           +   1.0227e-4        ) * zttl
+
+                  zrhoptl=                                  zr1tl &
+                     &     + zs                           * zr2tl &
+                     &     + zsr * zs                     * zr3tl &
+                     &     + zr3 * zs                     * zsrtl &
+                     &     + (  2. * zr4 * zs + zr2              &
+                     &        + zr3 * zsr           )     * zstl
+
+                  zetl = (       -2.*3.508914e-8   * zt &
+                     &           -   1.248266e-8        ) * zttl
+
+                  zbwtl= (        2.*1.296821e-6   * zt &
+                     &           -   5.782165e-9        ) * zttl
+
+                  zbtl =                                    zbwtl &
+                     &    + zs                            * zetl  &
+                  &       + ze                            * zstl
+
+                  zctl = (       -2.*7.267926e-5   * zt &
+                     &           +   2.598241e-3        ) * zttl
+
+                  zawtl= ( (      3.*5.939910e-6   * zt &
+                     &           +2.*2.512549e-3 ) * zt &
+                     &           -   0.1028859          ) * zttl
+
+                  zatl =                                    zawtl &
+                  &      + zd * zs                        * zsrtl & 
+                  &      + zs                             * zctl  &
+                  &      + ( zd * zsr + zc )              * zstl
+
+                  zb1tl= (       -2.*0.1909078     * zt &
+                     &           +   7.390729           ) * zttl
+
+                  za1tl= ( (      3.*2.326469e-3   * zt &
+                     &           +2.*1.553190    ) * zt &
+                     &           -   65.00517           ) * zttl
+
+                  zkwtl= ( ( (   -4.*1.361629e-4   * zt &
+                     &           -3.*1.852732e-2 ) * zt &
+                     &           -2.*30.41638    ) * zt &
+                     &           +   2098.925           ) * zttl
+
+                  zk0tl=                                    zkwtl &
+                     &  + zb1 * zs                        * zsrtl &
+                     &  + zs  * zsr                       * zb1tl &
+                     &  + zs                              * za1tl &
+                     &  + ( zb1 * zsr + za1 )             * zstl
+
+                  ! Masked in situ density anomaly
+
+                  zrdc1 = 1.0 / ( zk0 - zh * ( za - zh * zb ) )
+                  zrdc2 = 1.0 / ( 1.0 - zh * zrdc1 )
+
+                  prd_tl(ji,jj,jk) = tmask(ji,jj,jk) * zrdc2 * &
+                     &               (                              zrhoptl &
+                     &                 - zrdc2 * zh * zrdc1**2 * zrhop      &
+                     &                   * (                        zk0tl   &
+                     &                       - zh * (               zatl    &
+                     &                                - zh        * zbtl ) ) )&
+                     &               * zrau0r
+               END DO
+            END DO
+         END DO
+         !
+      CASE ( 1 )               !== Linear formulation function of temperature only ==!
+         DO jk = 1, jpkm1
+            prd_tl(:,:,jk) = ( - rn_alpha * ptem_tl(:,:,jk) ) * tmask(:,:,jk)
+         END DO
+         !
+      CASE ( 2 )               !== Linear formulation function of temperature and salinity ==!
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1
+            prd_tl(:,:,jk) = ( rn_beta  * psal_tl(:,:,jk) - rn_alpha * ptem_tl(:,:,jk ) ) * tmask(:,:,jk)
+         END DO
+         !
+      END SELECT
+
+   END SUBROUTINE eos_insitu_tan
+
+   SUBROUTINE eos_insitu_pot_tan( ptem, psal, ptem_tl, psal_tl, prd_tl, prhop_tl)
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE eos_insitu_pot_tan  ***
+      !!           
+      !! ** Purpose or the direct routine:
+      !!      Compute the in situ density (ratio rho/rau0) and the
+      !!      potential volumic mass (Kg/m3) from potential temperature and
+      !!      salinity fields using an equation of state defined through the 
+      !!     namelist parameter nn_eos.
+      !!
+      !! ** Method  :
+      !!      nn_eos = 0 : Jackett and McDougall (1994) equation of state.
+      !!         the in situ density is computed directly as a function of
+      !!         potential temperature relative to the surface (the opa t
+      !!         variable), salt and pressure (assuming no pressure variation
+      !!         along geopotential surfaces, i.e. the pressure p in decibars
+      !!         is approximated by the depth in meters.
+      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
+      !!              rhop(t,s)  = rho(t,s,0)
+      !!         with pressure                      p        decibars
+      !!              potential temperature         t        deg celsius
+      !!              salinity                      s        psu
+      !!              reference volumic mass        rau0     kg/m**3
+      !!              in situ volumic mass          rho      kg/m**3
+      !!              in situ density anomalie      prd      no units
+      !!
+      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
+      !!          t = 40 deg celcius, s=40 psu
+      !!
+      !!      nn_eos = 1 : linear equation of state function of temperature only
+      !!              prd(t) = ( rho(t) - rau0 ) / rau0 = 0.028 - rn_alpha * t
+      !!              rhop(t,s)  = rho(t,s)
+      !!
+      !!      nn_eos = 2 : linear equation of state function of temperature and
+      !!               salinity
+      !!              prd(t,s) = ( rho(t,s) - rau0 ) / rau0 
+      !!                       = rn_beta * s - rn_alpha * tn - 1.
+      !!              rhop(t,s)  = rho(t,s)
+      !!      Note that no boundary condition problem occurs in this routine
+      !!      as (tn,sn) or (ta,sa) are defined over the whole domain.
+      !!
+      !! ** Action  : - prd  , the in situ density (no units)
+      !!              - prhop, the potential volumic mass (Kg/m3)
+      !!
+      !! References :
+      !!      Jackett, D.R., and T.J. McDougall. J. Atmos. Ocean. Tech., 1994
+      !!      Brown, J. A. and K. A. Campana. Mon. Weather Rev., 1978
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem,   &  ! potential temperature
+         psal       ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem_tl,&  ! potential temperature
+         psal_tl    ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   &
+         prd_tl, &  ! potential density (surface referenced)
+         prhop_tl   ! potential density (surface referenced)
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   &             ! temporary scalars
+         zt, zs, zh, zsr, zr1, zr2, zr3, zr4, zrhop, ze, zbw,   &
+         zb, zd, zc, zaw, za, zb1, za1, zkw, zk0,               &
+         zttl, zstl, zhtl, zsrtl, zr1tl, zr2tl, zr3tl,          &
+         zr4tl, zrhoptl, zetl, zbwtl,                           &
+         zbtl, zdtl, zctl, zawtl, zatl, zb1tl, za1tl,           &
+         zkwtl, zk0tl, zpes, zrdc1, zrdc2, zeps,                &
+         zmask, zrau0r
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zws
+      !!----------------------------------------------------------------------
+
+      SELECT CASE ( nn_eos )
+
+      CASE ( 0 )               !== Jackett and McDougall (1994) formulation ==!
+         zrau0r = 1.e0 / rau0
+#ifdef key_sp
+         zeps = 1.e-7
+#else
+         zeps = 1.e-14
+#endif
+
+!CDIR NOVERRCHK
+         zws(:,:,:) = SQRT( ABS( psal(:,:,:) ) )
+         !
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  zh = fsdept(ji,jj,jk)        ! depth
+                  zsr = zws(ji,jj,jk)          ! square root salinity
+                  ! compute volumic mass pure water at atm pressure
+                  zr1 = ( ( ( ( 6.536332e-9   * zt - 1.120083e-6 ) * zt   &
+                     &        + 1.001685e-4 ) * zt - 9.095290e-3 ) * zt   &
+                     &        + 6.793952e-2 ) * zt + 999.842594
+                  ! seawater volumic mass atm pressure
+                  zr2 = ( ( ( 5.3875e-9   * zt - 8.2467e-7 ) * zt         &
+                     &      + 7.6438e-5 ) * zt - 4.0899e-3 ) * zt         &
+                     &      + 0.824493
+                  zr3 = ( -1.6546e-6 * zt + 1.0227e-4 ) * zt - 5.72466e-3
+                  zr4 = 4.8314e-4
+
+                  ! potential volumic mass (reference to the surface)
+                  zrhop= ( zr4 * zs + zr3 * zsr + zr2 ) * zs + zr1
+
+                  ! add the compression terms
+                  ze  = ( -3.508914e-8 * zt - 1.248266e-8 ) * zt - 2.595994e-6
+                  zbw = (  1.296821e-6 * zt - 5.782165e-9 ) * zt + 1.045941e-4
+                  zb  = zbw + ze * zs
+
+                  zd = -2.042967e-2
+                  zc =   (-7.267926e-5 * zt + 2.598241e-3 ) * zt + 0.1571896
+                  zaw= ( ( 5.939910e-6 * zt + 2.512549e-3 ) * zt - 0.1028859 ) * zt - 4.721788
+                  za = ( zd * zsr + zc ) * zs + zaw
+
+                  zb1 =   (-0.1909078   * zt + 7.390729 ) * zt - 55.87545
+                  za1 = ( ( 2.326469e-3 * zt + 1.553190 ) * zt - 65.00517  &
+                     &  ) * zt + 1044.077
+                  zkw = ( ( (-1.361629e-4 * zt - 1.852732e-2 ) * zt - 30.41638 &
+                     &    ) * zt + 2098.925 ) * zt + 190925.6
+                  zk0 = ( zb1 * zsr + za1 ) * zs + zkw
+
+
+                  zrdc1 = 1.0 / ( zk0 - zh * ( za - zh * zb ) )
+                  zrdc2 = 1.0 / ( 1.0 - zh * zrdc1 )
+
+                  ! Tangent linear part
+
+                  zttl = ptem_tl(ji,jj,jk)
+                  zstl = psal_tl(ji,jj,jk)
+
+                  zsrtl= ( 1.0 / MAX( 2.*zsr, zeps ) ) &
+                     &   * tmask(ji,jj,jk)                * zstl
+
+                  zr1tl= ( ( ( (  5.*6.536332e-9   * zt &
+                     &           -4.*1.120083e-6 ) * zt &
+                     &           +3.*1.001685e-4 ) * zt &
+                     &           -2.*9.095290e-3 ) * zt &
+                     &           +   6.793952e-2        ) * zttl
+
+                  zr2tl= ( ( (    4.*5.3875e-9   * zt &
+                     &           -3.*8.2467e-7 ) * zt &
+                     &           +2.*7.6438e-5 ) * zt &
+                     &           -   4.0899e-3        ) * zttl
+
+                  zr3tl= (       -2.*1.6546e-6   * zt &
+                     &           +   1.0227e-4        ) * zttl
+
+                  zrhoptl=                                  zr1tl &
+                     &     + zs                           * zr2tl &
+                     &     + zsr * zs                     * zr3tl &
+                     &     + zr3 * zs                     * zsrtl &
+                     &     + (  2. * zr4 * zs + zr2               &
+                     &        + zr3 * zsr           )     * zstl
+
+                  prhop_tl(ji,jj,jk) = zrhoptl * tmask(ji,jj,jk)
+
+                  zetl = (       -2.*3.508914e-8   * zt &
+                     &           -   1.248266e-8        ) * zttl
+
+                  zbwtl= (        2.*1.296821e-6   * zt &
+                     &           -   5.782165e-9        ) * zttl
+
+                  zbtl =                                    zbwtl &
+                     &    + zs                            * zetl  &
+                  &       + ze                            * zstl
+
+                  zctl = (       -2.*7.267926e-5   * zt &
+                     &           +   2.598241e-3        ) * zttl
+
+                  zawtl= ( (      3.*5.939910e-6   * zt &
+                     &           +2.*2.512549e-3 ) * zt &
+                     &           -   0.1028859          ) * zttl
+
+                  zatl =                                    zawtl &
+                  &      + zd * zs                        * zsrtl & 
+                  &      + zs                             * zctl  &
+                  &      + ( zd * zsr + zc )              * zstl
+
+                  zb1tl= (       -2.*0.1909078     * zt &
+                     &           +   7.390729           ) * zttl
+
+                  za1tl= ( (      3.*2.326469e-3   * zt &
+                     &           +2.*1.553190    ) * zt &
+                     &           -   65.00517           ) * zttl
+
+                  zkwtl= ( ( (   -4.*1.361629e-4   * zt &
+                     &           -3.*1.852732e-2 ) * zt &
+                     &           -2.*30.41638    ) * zt &
+                     &           +   2098.925           ) * zttl
+
+                  zk0tl=                                    zkwtl &
+                     &  + zb1 * zs                        * zsrtl &
+                     &  + zs  * zsr                       * zb1tl &
+                     &  + zs                              * za1tl &
+                     &  + ( zb1 * zsr + za1 )             * zstl
+
+                  ! Masked in situ density anomaly
+
+                  prd_tl(ji,jj,jk) = tmask(ji,jj,jk) * zrdc2 * &
+                     &               (                              zrhoptl &
+                     &                 - zrdc2 * zh * zrdc1**2 * zrhop      &
+                     &                   * (                        zk0tl   &
+                     &                       - zh * (               zatl    &
+                     &                                - zh        * zbtl ) ) )&
+                     &               * zrau0r
+               END DO
+            END DO
+         END DO
+         !
+      CASE ( 1 )                !==  Linear formulation = F( temperature )  ==!
+         DO jk = 1, jpkm1
+            prd_tl  (:,:,jk) = ( - rn_alpha * ptem_tl(:,:,jk) ) * tmask(:,:,jk)
+            prhop_tl(:,:,jk) = ( rau0 * prd_tl(:,:,jk)        ) * tmask(:,:,jk)
+         END DO
+         !
+      CASE ( 2 )                !==  Linear formulation = F( temperature , salinity )  ==!
+         DO jk = 1, jpkm1
+            prd_tl(:,:,jk)   = ( rn_beta  * psal_tl(:,:,jk) - rn_alpha * ptem_tl(:,:,jk) ) * tmask(:,:,jk)
+            prhop_tl(:,:,jk) = ( rau0 * prd_tl(:,:,jk) )       * tmask(:,:,jk)
+         END DO
+         !
+      END SELECT
+
+   END SUBROUTINE eos_insitu_pot_tan
+   SUBROUTINE eos_pot_1pt_tan( ptem, psal, ptem_tl, psal_tl, prhop_tl)
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE eos_pot_1pt_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Compute the
+      !!      potential volumic mass (Kg/m3) from potential temperature and
+      !!      salinity fields using an equation of state defined through the
+      !!     namelist parameter neos.
+      !!
+      !! ** Method  :
+      !!      nn_eos = 0 : Jackett and McDougall (1994) equation of state.
+      !!         the in situ density is computed directly as a function of
+      !!         potential temperature relative to the surface (the opa t
+      !!         variable), salt and pressure (assuming no pressure variation
+      !!         along geopotential surfaces, i.e. the pressure p in decibars
+      !!         is approximated by the depth in meters.
+      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
+      !!              rhop(t,s)  = rho(t,s,0)
+      !!         with pressure                      p        decibars
+      !!              potential temperature         t        deg celsius
+      !!              salinity                      s        psu
+      !!              reference volumic mass        rau0     kg/m**3
+      !!              in situ volumic mass          rho      kg/m**3
+      !!              in situ density anomalie      prd      no units
+      !!
+      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
+      !!          t = 40 deg celcius, s=40 psu
+      !!
+      !!      nn_eos = 1 : linear equation of state function of temperature only
+      !!              prd(t) = ( rho(t) - rau0 ) / rau0 = 0.028 - ralpha * t
+      !!              rhop(t,s)  = rho(t,s)
+      !!
+      !!      nn_eos = 2 : linear equation of state function of temperature and
+      !!               salinity
+      !!              prd(t,s) = ( rho(t,s) - rau0 ) / rau0
+      !!                       = rn_beta * s - rn_alpha * tn - 1.
+      !!              rhop(t,s)  = rho(t,s)
+      !!      Note that no boundary condition problem occurs in this routine
+      !!      as (tn,sn) or (ta,sa) are defined over the whole domain.
+      !!
+      !! ** Action  : - prd  , the in situ density (no units)
+      !!              - prhop, the potential volumic mass (Kg/m3)
+      !!
+      !! References :
+      !!      Jackett, D.R., and T.J. McDougall. J. Atmos. Ocean. Tech., 1994
+      !!      Brown, J. A. and K. A. Campana. Mon. Weather Rev., 1978
+      !!
+      !! History of the direct routine:
+      !!   4.0  !  89-03  (O. Marti)
+      !!        !  94-08  (G. Madec)
+      !!        !  96-01  (G. Madec) statement function for e3
+      !!        !  97-07  (G. Madec) introduction of neos, OPA8.1
+      !!        !  97-07  (G. Madec) density instead of volumic mass
+      !!        !  99-02  (G. Madec, N. Grima) semi-implicit pressure gradient
+      !!        !  01-09  (M. Ben Jelloul) bugfix
+      !!   9.0  !  03-08  (G. Madec)  F90, free form
+      !!        !  06-11  (G. Smith) single point case
+      !! History of the tangent routine:
+      !!   9.0  !  08-07  (A. Vidard) Initial version
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), INTENT( in ) ::   &
+         ptem,   &  ! potential temperature
+         psal       ! salinity
+     REAL(wp), INTENT( in ) ::   &
+         ptem_tl,   &  ! potential temperature
+         psal_tl       ! salinity
+      REAL(wp), INTENT( out ) ::   &
+         prhop_tl      ! potential density (surface referenced)
+
+      !! * Local declarations
+      INTEGER  ::  ji, jj, jk                ! dummy loop indices
+      REAL(wp) ::   &             ! temporary scalars
+         & zt, zs, zsr, zr1, zr2, zr3, zr4, zrhop,                &
+         & zttl, zstl, zsrtl, zr1tl, zr2tl, zr3tl, zr4tl, zrhoptl 
+      REAL(wp) :: zws, zwstl, zeps
+      !!----------------------------------------------------------------------
+
+#ifdef key_sp
+         zeps = 1.e-7
+#else
+         zeps = 1.e-14
+#endif
+
+      SELECT CASE ( nn_eos )
+
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+         zws = SQRT( ABS( psal ) )
+
+         zt = ptem
+         zs = psal
+         ! square root salinity
+         zsr= zws
+         ! compute volumic mass pure water at atm pressure
+         zr1= ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt   &
+            -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
+         ! seawater volumic mass atm pressure
+         zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 ) *zt+7.6438e-5 ) *zt   &
+            -4.0899e-3 ) *zt+0.824493
+         zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
+         zr4= 4.8314e-4
+
+         ! ==================
+         ! tangent linear part
+         ! ==================
+
+         zwstl = 1/MAX( 2*zws , zeps ) * psal_tl 
+         zttl = ptem_tl
+         zstl = psal_tl
+         ! square root salinity
+         zsrtl= zwstl
+         ! compute volumic mass pure water at atm pressure
+         zr1tl= ( ( ( (  5.*6.536332e-9   * zt &
+            &           -4.*1.120083e-6 ) * zt &
+            &           +3.*1.001685e-4 ) * zt &
+            &           -2.*9.095290e-3 ) * zt &
+            &           +   6.793952e-2        ) * zttl
+         ! seawater volumic mass atm pressure
+         zr2tl= ( ( (    4.*5.3875e-9   * zt &
+            &           -3.*8.2467e-7 ) * zt &
+            &           +2.*7.6438e-5 ) * zt &
+            &           -   4.0899e-3        ) * zttl
+
+         zr3tl= (       -2.*1.6546e-6   * zt &
+            &           +   1.0227e-4        ) * zttl
+
+         ! potential volumic mass (reference to the surface)
+         zrhoptl=                                  zr1tl &
+            &     + zs                           * zr2tl &
+            &     + zsr * zs                     * zr3tl &
+            &     + zr3 * zs                     * zsrtl &
+            &     + (  2. * zr4 * zs + zr2               &
+            &        + zr3 * zsr           )     * zstl
+
+         ! save potential volumic mass
+         prhop_tl = zrhoptl
+
+      CASE ( 1 )               ! Linear formulation function of temperature only
+
+         zttl = ptem_tl
+         !   ...  potential volumic mass
+         prhop_tl   = ( rau0 * ( - rn_alpha * zttl ) )
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+         zttl = ptem_tl
+         zstl = psal_tl
+         !   ...  potential volumic mass
+         prhop_tl   = rau0 * ( rn_beta  * zstl - rn_alpha * zttl ) 
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for nn_eos = ', nn_eos
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+         
+   END SUBROUTINE eos_pot_1pt_tan
+   SUBROUTINE eos_insitu_2d_tan( ptem, psal, pdep, ptem_tl, psal_tl, prd_tl )
+      !!-----------------------------------------------------------------------
+      !!
+      !!        ***  ROUTINE eos_insitu_2d_tan : TL OF ROUTINE eos_insitu_2d ***
+      !!
+      !! ** Purpose of direct routine   : Compute the in situ density 
+      !!       (ratio rho/rau0) from potential temperature and salinity 
+      !!       using an equation of state defined through the namelist 
+      !!       parameter nn_eos. * 2D field case
+      !!
+      !! ** Method of direct routine    : 3 cases:
+      !!      nn_eos = 0 : Jackett and McDougall (1994) equation of state.
+      !!         the in situ density is computed directly as a function of
+      !!         potential temperature relative to the surface (the opa t
+      !!         variable), salt and pressure (assuming no pressure variation
+      !!         along geopotential surfaces, i.e. the pressure p in decibars
+      !!         is approximated by the depth in meters.
+      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
+      !!         with pressure                      p        decibars
+      !!              potential temperature         t        deg celsius
+      !!              salinity                      s        psu
+      !!              reference volumic mass        rau0     kg/m**3
+      !!              in situ volumic mass          rho      kg/m**3
+      !!              in situ density anomalie      prd      no units
+      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
+      !!          t = 40 deg celcius, s=40 psu
+      !!      nn_eos = 1 : linear equation of state function of temperature only
+      !!              prd(t) = 0.0285 - ralpha * t
+      !!      nn_eos = 2 : linear equation of state function of temperature and
+      !!               salinity
+      !!              prd(t,s) = rn_beta * s - rn_alpha * tn - 1.
+      !!      Note that no boundary condition problem occurs in this routine
+      !!      as (ptem,psal) are defined over the whole domain.
+      !!
+      !! ** Comments on Adjoint Routine : 
+      !!      Care has been taken to avoid division by zero when computing 
+      !!      the inverse of the square root of salinity at masked salinity 
+      !!      points.
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!    8.2 ! 05-03 ((F. Van den Berghe, A. Weaver, N. Daget)  - eostan.F
+      !!    9.0 ! 07-07 (K. Mogensen) Initial version based on eostan.F
+      !!        ! 08-07 (A. Vidard) bug fix in computation of prd_tl if neos=1
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( in ) ::   &
+         & ptem,                 &  ! potential temperature
+         & psal,                 &  ! salinity
+         & pdep,                 &  ! depth
+         & ptem_tl,              &  ! TL of potential temperature
+         & psal_tl                  ! TL of salinity
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( out ) ::   &
+         & prd_tl                   ! TL of potential density (surface referenced)
+
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   &             ! temporary scalars
+         zt, zs, zh, zsr, zr1, zr2, zr3, zr4, zrhop, ze, zbw,   &
+         zb, zd, zc, zaw, za, zb1, za1, zkw, zk0,               &
+         zttl, zstl, zhtl, zsrtl, zr1tl, zr2tl, zr3tl,          &
+         zr4tl, zrhoptl, zetl, zbwtl,                           &
+         zbtl, zdtl, zctl, zawtl, zatl, zb1tl, za1tl,           &
+         zkwtl, zk0tl, zpes, zrdc1, zrdc2, zeps,                &
+         zmask
+      REAL(wp), DIMENSION(jpi,jpj) :: zws
+      !!----------------------------------------------------------------------
+
+      SELECT CASE ( nn_eos )
+
+      CASE ( 0 )               !== Jackett and McDougall (1994) formulation ==!
+
+#ifdef key_sp
+         zeps = 1.e-7
+#else
+         zeps = 1.e-14
+#endif
+
+!CDIR NOVERRCHK
+         DO jj = 1, jpjm1
+!CDIR NOVERRCHK
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zws(ji,jj) = SQRT( ABS( psal(ji,jj) ) )
+            END DO
+         END DO
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+
+               zmask = tmask(ji,jj,1)      ! land/sea bottom mask = surf. mask
+
+               zt = ptem (ji,jj)            ! interpolated T
+               zs = psal (ji,jj)            ! interpolated S
+               zsr= zws(ji,jj)            ! square root of interpolated S
+               zh = pdep(ji,jj)            ! depth at the partial step level
+                  ! compute volumic mass pure water at atm pressure
+                  zr1= ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt   &
+                     & -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
+                  ! seawater volumic mass atm pressure
+                  zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 ) *zt+7.6438e-5 ) *zt   &
+                     & -4.0899e-3 ) *zt+0.824493
+                  zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
+                  zr4= 4.8314e-4
+
+                  ! potential volumic mass (reference to the surface)
+                  zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
+
+                  ! add the compression terms
+                  ze = ( -3.508914e-8*zt-1.248266e-8 ) *zt-2.595994e-6
+                  zbw= (  1.296821e-6*zt-5.782165e-9 ) *zt+1.045941e-4
+                  zb = zbw + ze * zs
+
+                  zd = -2.042967e-2
+                  zc =   (-7.267926e-5*zt+2.598241e-3 ) *zt+0.1571896
+                  zaw= ( ( 5.939910e-6*zt+2.512549e-3 ) *zt-0.1028859 ) *zt - 4.721788
+                  za = ( zd*zsr + zc ) *zs + zaw
+
+                  zb1=   (-0.1909078*zt+7.390729 ) *zt-55.87545
+                  za1= ( ( 2.326469e-3*zt+1.553190)*zt-65.00517 ) *zt+1044.077
+                  zkw= ( ( (-1.361629e-4*zt-1.852732e-2 ) *zt-30.41638 ) *zt + 2098.925 ) *zt+190925.6
+                  zk0= ( zb1*zsr + za1 )*zs + zkw
+
+                  ! Tangent linear part
+
+                  zttl = ptem_tl(ji,jj)
+                  zstl = psal_tl(ji,jj)
+
+                  zsrtl= ( 1.0 / MAX( 2.*zsr, zeps ) ) &
+                     &   * tmask(ji,jj,1)                 * zstl
+
+                  zr1tl= ( ( ( (  5.*6.536332e-9   * zt &
+                     &           -4.*1.120083e-6 ) * zt &
+                     &           +3.*1.001685e-4 ) * zt &
+                     &           -2.*9.095290e-3 ) * zt &
+                     &           +   6.793952e-2        ) * zttl
+
+                  zr2tl= ( ( (    4.*5.3875e-9   * zt &
+                     &           -3.*8.2467e-7 ) * zt &
+                     &           +2.*7.6438e-5 ) * zt &
+                     &           -   4.0899e-3        ) * zttl
+
+                  zr3tl= (       -2.*1.6546e-6   * zt &
+                     &           +   1.0227e-4        ) * zttl
+
+                  zrhoptl=                                  zr1tl &
+                     &     + zs                           * zr2tl &
+                     &     + zsr * zs                     * zr3tl &
+                     &     + zr3 * zs                     * zsrtl &
+                     &     + (  2. * zr4 * zs + zr2              &
+                     &        + zr3 * zsr           )     * zstl
+
+                  zetl = (       -2.*3.508914e-8   * zt &
+                     &           -   1.248266e-8        ) * zttl
+
+                  zbwtl= (        2.*1.296821e-6   * zt &
+                     &           -   5.782165e-9        ) * zttl
+
+                  zbtl =                                    zbwtl &
+                     &    + zs                            * zetl  &
+                  &       + ze                            * zstl
+
+                  zctl = (       -2.*7.267926e-5   * zt &
+                     &           +   2.598241e-3        ) * zttl
+
+                  zawtl= ( (      3.*5.939910e-6   * zt &
+                     &           +2.*2.512549e-3 ) * zt &
+                     &           -   0.1028859          ) * zttl
+
+                  zatl =                                    zawtl &
+                  &      + zd * zs                        * zsrtl & 
+                  &      + zs                             * zctl  &
+                  &      + ( zd * zsr + zc )              * zstl
+
+                  zb1tl= (       -2.*0.1909078     * zt &
+                     &           +   7.390729           ) * zttl
+
+                  za1tl= ( (      3.*2.326469e-3   * zt &
+                     &           +2.*1.553190    ) * zt &
+                     &           -   65.00517           ) * zttl
+
+                  zkwtl= ( ( (   -4.*1.361629e-4   * zt &
+                     &           -3.*1.852732e-2 ) * zt &
+                     &           -2.*30.41638    ) * zt &
+                     &           +   2098.925           ) * zttl
+
+                  zk0tl=                                    zkwtl &
+                     &  + zb1 * zs                        * zsrtl &
+                     &  + zs  * zsr                       * zb1tl &
+                     &  + zs                              * za1tl &
+                     &  + ( zb1 * zsr + za1 )             * zstl
+
+                  ! Masked in situ density anomaly
+
+                  zrdc1 = 1.0 / ( zk0 - zh * ( za - zh * zb ) )
+                  zrdc2 = 1.0 / ( 1.0 - zh * zrdc1 )
+
+                  prd_tl(ji,jj) = tmask(ji,jj,1)  * zrdc2 *                &
+                     &            (                              zrhoptl   &
+                     &              - zrdc2 * zh * zrdc1**2 * zrhop        &
+                     &                * (                        zk0tl     &
+                     &                    - zh * (               zatl      &
+                     &                             - zh        * zbtl ) ) )&
+                     &               / rau0
+
+
+            END DO
+         END DO
+         !
+      CASE ( 1 )                !==  Linear formulation = F( temperature )  ==!
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               prd_tl(ji,jj) = ( - rn_alpha * ptem_tl(ji,jj) )     * tmask(ji,jj,1)
+            END DO
+         END DO
+         !
+      CASE ( 2 )                !==  Linear formulation = F( temperature , salinity )  ==!
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               prd_tl (ji,jj) = ( rn_beta * psal_tl(ji,jj) - rn_alpha * ptem_tl(ji,jj) ) * tmask(ji,jj,1) 
+            END DO
+         END DO
+         !
+      END SELECT
+
+
+   END SUBROUTINE eos_insitu_2d_tan
+
+   SUBROUTINE eos_insitu_adj(ptem, psal, ptem_ad, psal_ad, prd_ad)   
+      !!-----------------------------------------------------------------------
+      !!
+      !!        ***  ROUTINE eos_insitu_tan : Adjoint OF ROUTINE eos_insitu ***
+      !!
+      !! ** Purpose of direct routine   : Compute the in situ density 
+      !!       (ratio rho/rau0) from potential temperature and salinity 
+      !!       using an equation of state defined through the namelist 
+      !!       parameter nneos.
+      !!
+      !! ** Method of direct routine    : 3 cases:
+      !!      nn_eos = 0 : Jackett and McDougall (1994) equation of state.
+      !!         the in situ density is computed directly as a function of
+      !!         potential temperature relative to the surface (the opa t
+      !!         variable), salt and pressure (assuming no pressure variation
+      !!         along geopotential surfaces, i.e. the pressure p in decibars
+      !!         is approximated by the depth in meters.
+      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
+      !!         with pressure                      p        decibars
+      !!              potential temperature         t        deg celsius
+      !!              salinity                      s        psu
+      !!              reference volumic mass        rau0     kg/m**3
+      !!              in situ volumic mass          rho      kg/m**3
+      !!              in situ density anomalie      prd      no units
+      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
+      !!          t = 40 deg celcius, s=40 psu
+      !!      nn_eos = 1 : linear equation of state function of temperature only
+      !!              prd(t) = 0.0285 - rn_alpha * t
+      !!      nn_eos = 2 : linear equation of state function of temperature and
+      !!               salinity
+      !!              prd(t,s) = rn_beta * s - rn_alpha * tn - 1.
+      !!      Note that no boundary condition problem occurs in this routine
+      !!      as (ptem,psal) are defined over the whole domain.
+      !!
+      !! ** Comments on Adjoint Routine : 
+      !!      Care has been taken to avoid division by zero when computing 
+      !!      the inverse of the square root of salinity at masked salinity 
+      !!      points.
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!    8.2 ! 05-03 ((F. Van den Berghe, A. Weaver, N. Daget)  - eostan.F
+      !!    9.0 ! 08-08 (A. Vidard) 9.0 version
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem,                 &  ! potential temperature
+         psal                     ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         ptem_ad,              &  ! potential temperature
+         psal_ad                  ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         prd_ad                   ! potential density (surface referenced)
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   &             ! temporary scalars
+         zt, zs, zh, zsr, zr1, zr2, zr3, zr4, zrhop, ze, zbw,   &
+         zb, zd, zc, zaw, za, zb1, za1, zkw, zk0,               &
+         ztad, zsad, zhad, zsrad, zr1ad, zr2ad, zr3ad,          &
+         zr4ad, zrhopad, zead, zbwad,                           &
+         zbad, zdad, zcad, zawad, zaad, zb1ad, za1ad,           &
+         zkwad, zk0ad, zpes, zrdc1, zrdc2, zeps,                &
+         zmask, zrau0r
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zws
+      !!----------------------------------------------------------------------
+
+      ! initialization of adjoint variables
+      ztad    = 0.0_wp
+      zsad    = 0.0_wp
+      zhad    = 0.0_wp
+      zsrad   = 0.0_wp
+      zr1ad   = 0.0_wp
+      zr2ad   = 0.0_wp
+      zr3ad   = 0.0_wp
+      zr4ad   = 0.0_wp
+      zrhopad = 0.0_wp
+      zead    = 0.0_wp
+      zbwad   = 0.0_wp
+      zbad    = 0.0_wp
+      zdad    = 0.0_wp
+      zcad    = 0.0_wp
+      zawad   = 0.0_wp
+      zaad    = 0.0_wp
+      zb1ad   = 0.0_wp
+      za1ad   = 0.0_wp
+      zkwad   = 0.0_wp
+      zk0ad   = 0.0_wp
+
+      SELECT CASE ( nn_eos )
+
+      CASE ( 0 )               !== Jackett and McDougall (1994) formulation ==!
+         zrau0r = 1.e0 / rau0
+#ifdef key_sp
+         zeps = 1.e-7
+#else
+         zeps = 1.e-14
+#endif
+
+!CDIR NOVERRCHK
+         zws(:,:,:) = SQRT( ABS( psal(:,:,:) ) )
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  zh = fsdept(ji,jj,jk)        ! depth
+                  zsr= zws(ji,jj,jk)           ! square root salinity
+                  ! compute volumic mass pure water at atm pressure
+                  zr1= ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt   &
+                     -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
+                  ! seawater volumic mass atm pressure
+                  zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 ) *zt+7.6438e-5 ) *zt   &
+                     -4.0899e-3 ) *zt+0.824493
+                  zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
+                  zr4= 4.8314e-4
+
+                  ! potential volumic mass (reference to the surface)
+                  zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
+
+                  ! add the compression terms
+                  ze = ( -3.508914e-8*zt-1.248266e-8 ) *zt-2.595994e-6
+                  zbw= (  1.296821e-6*zt-5.782165e-9 ) *zt+1.045941e-4
+                  zb = zbw + ze * zs
+
+                  zd = -2.042967e-2
+                  zc =   (-7.267926e-5*zt+2.598241e-3 ) *zt+0.1571896
+                  zaw= ( ( 5.939910e-6*zt+2.512549e-3 ) *zt-0.1028859 ) *zt - 4.721788
+                  za = ( zd*zsr + zc ) *zs + zaw
+
+                  zb1=   (-0.1909078*zt+7.390729 ) *zt-55.87545
+                  za1= ( ( 2.326469e-3*zt+1.553190)*zt-65.00517 ) *zt+1044.077
+                  zkw= ( ( (-1.361629e-4*zt-1.852732e-2 ) *zt-30.41638 ) *zt + 2098.925 ) *zt+190925.6
+                  zk0= ( zb1*zsr + za1 )*zs + zkw
+
+                  zrdc1 = 1.0 / ( zk0 - zh * ( za - zh * zb ) )
+                  zrdc2 = 1.0 / ( 1.0 - zh * zrdc1 )
+                  ! ============
+                  ! Adjoint part
+                  ! ============
+
+                  ! Masked in situ density anomaly
+
+                  zrhopad = zrhopad + prd_ad(ji,jj,jk) * tmask(ji,jj,jk)    &
+                     &                                 * zrdc2 * zrau0r
+                  zk0ad   = zk0ad   - prd_ad(ji,jj,jk) * tmask(ji,jj,jk)    &
+                     &                                 * zrdc2 * zrdc2 * zh &
+                     &                                 * zrdc1**2 * zrhop   &
+                     &                                 * zrau0r
+                  zaad    = zaad    + prd_ad(ji,jj,jk) * tmask(ji,jj,jk)    &
+                     &                                 * zrdc2 * zrdc2 * zh &
+                     &                                 * zrdc1**2 * zrhop   &
+                     &                                 * zh * zrau0r
+                  zbad    = zbad    - prd_ad(ji,jj,jk) * tmask(ji,jj,jk)    &
+                     &                                 * zrdc2 * zrdc2 * zh &
+                     &                                 * zrdc1**2 * zrhop   &
+                     &                                 * zh * zh * zrau0r
+                  prd_ad(ji,jj,jk) = 0.0_wp
+
+                  zkwad = zkwad + zk0ad
+                  zsrad = zsrad + zk0ad * zb1 * zs  
+                  zb1ad = zb1ad + zk0ad * zs  * zsr
+                  za1ad = za1ad + zk0ad * zs  
+                  zsad  = zsad  + zk0ad * ( zb1 * zsr + za1 )
+                  zk0ad = 0.0_wp
+
+                  ztad  = ztad + zkwad * ( ( (-4.*1.361629e-4   * zt &
+                     &                        -3.*1.852732e-2 ) * zt &
+                     &                        -2.*30.41638    ) * zt &
+                     &                        +   2098.925           )
+                  zkwad = 0.0_wp
+
+                  ztad  = ztad + za1ad * ( ( 3.*2.326469e-3   * zt &
+                     &                      +2.*1.553190    ) * zt &
+                     &                      -   65.00517           )
+                  za1ad = 0.0_wp
+
+                  ztad  = ztad + zb1ad * (-2.*0.1909078     * zt &
+                     &                    +   7.390729           )
+                  zb1ad = 0.0_wp
+
+                  zawad = zawad + zaad
+                  zsrad = zsrad + zaad *   zd * zs
+                  zcad  = zcad  + zaad *   zs
+                  zsad  = zsad  + zaad * ( zd * zsr + zc )
+                  zaad  = 0.0_wp
+
+                  ztad  = ztad + zawad * ( ( 3.*5.939910e-6   * zt &
+                     &                      +2.*2.512549e-3 ) * zt &
+                     &                      -   0.1028859          ) 
+                  zawad = 0.0_wp
+
+                  ztad  = ztad + zcad * (-2.*7.267926e-5   * zt &
+                     &                   +   2.598241e-3        )
+                  zcad  = 0.0_wp
+
+                  zbwad = zbwad + zbad
+                  zead  = zead  + zbad * zs
+                  zsad  = zsad  + zbad * ze
+                  zbad  = 0.0_wp
+
+                  ztad  = ztad + zbwad *  ( 2.*1.296821e-6   * zt &
+                     &                     -   5.782165e-9        ) 
+                  zbwad = 0.0_wp
+
+                  ztad  = ztad + zead * (-2.*3.508914e-8   * zt &
+                     &                   -   1.248266e-8        )
+                  zead =  0.0_wp
+
+                  zr1ad   = zr1ad + zrhopad
+                  zr2ad   = zr2ad + zrhopad * zs
+                  zr3ad   = zr3ad + zrhopad * zsr * zs
+                  zsrad   = zsrad + zrhopad * zr3 * zs
+                  zsad    = zsad  + zrhopad * ( 2. * zr4 * zs + zr2  &
+                     &                        + zr3 * zsr           )
+                  zrhopad = 0.0_wp
+
+                  ztad  = ztad + zr3ad * (-2.*1.6546e-6   * zt &
+                     &                    +   1.0227e-4        )
+                  zr3ad = 0.0_wp
+
+                  ztad  = ztad + zr2ad * ( ( ( 4.*5.3875e-9   * zt &
+                     &                        -3.*8.2467e-7 ) * zt &
+                     &                        +2.*7.6438e-5 ) * zt &
+                     &                        -   4.0899e-3        )
+                  zr2ad = 0.0_wp
+
+                  ztad  = ztad + zr1ad * ( ( ( ( 5.*6.536332e-9   * zt &
+                     &                          -4.*1.120083e-6 ) * zt &
+                     &                          +3.*1.001685e-4 ) * zt &
+                     &                          -2.*9.095290e-3 ) * zt &
+                     &                          +   6.793952e-2        )
+                  zr1ad = 0.0_wp
+
+                  zsad  = zsad + zsrad * ( 1.0 / MAX( 2.*zsr, zeps ) ) &
+                     &                 * tmask(ji,jj,jk) 
+                  zsrad = 0.0_wp
+ 
+                  psal_ad(ji,jj,jk) = psal_ad(ji,jj,jk) + zsad
+                  ptem_ad(ji,jj,jk) = ptem_ad(ji,jj,jk) + ztad
+                  ztad = 0.0_wp
+                  zsad = 0.0_wp
+               END DO
+            END DO
+         END DO
+         !
+      CASE ( 1 )               !== Linear formulation function of temperature only ==!
+         DO jk = 1, jpkm1
+            ptem_ad(:,:,jk) = ptem_ad(:,:,jk) - rn_alpha * prd_ad(:,:,jk) * tmask(:,:,jk)
+            prd_ad(:,:,jk) = 0.0_wp
+         END DO
+         !
+      CASE ( 2 )               !== Linear formulation function of temperature and salinity ==!
+         DO jk = 1, jpkm1
+            ptem_ad(:,:,jk) = ptem_ad(:,:,jk) - rn_alpha * prd_ad(:,:,jk) * tmask(:,:,jk)
+            psal_ad(:,:,jk) = psal_ad(:,:,jk) + rn_beta * prd_ad( :,:,jk) * tmask(:,:,jk)
+            prd_ad( :,:,jk) = 0.0_wp
+         END DO
+         !
+      END SELECT
+   END SUBROUTINE eos_insitu_adj
+
+   SUBROUTINE eos_insitu_pot_adj ( ptem, psal, ptem_ad, psal_ad, prd_ad, prhop_ad )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE eos_insitu_pot_adj  ***
+      !!           
+      !! ** Purpose or the direct routine:
+      !!      Compute the in situ density (ratio rho/rau0) and the
+      !!      potential volumic mass (Kg/m3) from potential temperature and
+      !!      salinity fields using an equation of state defined through the 
+      !!     namelist parameter nn_eos.
+      !!
+      !! ** Method  :
+      !!      nn_eos = 0 : Jackett and McDougall (1994) equation of state.
+      !!         the in situ density is computed directly as a function of
+      !!         potential temperature relative to the surface (the opa t
+      !!         variable), salt and pressure (assuming no pressure variation
+      !!         along geopotential surfaces, i.e. the pressure p in decibars
+      !!         is approximated by the depth in meters.
+      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
+      !!              rhop(t,s)  = rho(t,s,0)
+      !!         with pressure                      p        decibars
+      !!              potential temperature         t        deg celsius
+      !!              salinity                      s        psu
+      !!              reference volumic mass        rau0     kg/m**3
+      !!              in situ volumic mass          rho      kg/m**3
+      !!              in situ density anomalie      prd      no units
+      !!
+      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
+      !!          t = 40 deg celcius, s=40 psu
+      !!
+      !!      neos = 1 : linear equation of state function of temperature only
+      !!              prd(t) = ( rho(t) - rau0 ) / rau0 = 0.028 - ralpha * t
+      !!              rhop(t,s)  = rho(t,s)
+      !!
+      !!      nn_eos = 2 : linear equation of state function of temperature and
+      !!               salinity
+      !!              prd(t,s) = ( rho(t,s) - rau0 ) / rau0 
+      !!                       = rn_beta * s - rn_alpha * tn - 1.
+      !!              rhop(t,s)  = rho(t,s)
+      !!      Note that no boundary condition problem occurs in this routine
+      !!      as (tn,sn) or (ta,sa) are defined over the whole domain.
+      !!
+      !! ** Action  : - prd  , the in situ density (no units)
+      !!              - prhop, the potential volumic mass (Kg/m3)
+      !!
+      !! References :
+      !!      Jackett, D.R., and T.J. McDougall. J. Atmos. Ocean. Tech., 1994
+      !!      Brown, J. A. and K. A. Campana. Mon. Weather Rev., 1978
+      !!
+      !! History of the adjoint routine:
+      !!   9.0  !  08-06  (A. Vidard) Initial version
+      !!----------------------------------------------------------------------
+      !! * Arguments
+
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::      &
+         ptem,                 &  ! potential temperature
+         psal                     ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         ptem_ad,              &  ! potential temperature
+         psal_ad                  ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         prd_ad,               &  ! potential density (surface referenced)
+         prhop_ad
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   &             ! temporary scalars
+         zt, zs, zh, zsr, zr1, zr2, zr3, zr4, zrhop, ze, zbw,   &
+         zb, zd, zc, zaw, za, zb1, za1, zkw, zk0,               &
+         ztad, zsad, zhad, zsrad, zr1ad, zr2ad, zr3ad,          &
+         zr4ad, zrhopad, zead, zbwad,                           &
+         zbad, zdad, zcad, zawad, zaad, zb1ad, za1ad,           &
+         zkwad, zk0ad, zpes, zrdc1, zrdc2, zeps,                &
+         zmask, zrau0r
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zws
+      !!----------------------------------------------------------------------
+
+      ! initialization of adjoint variables
+      ztad = 0.0_wp
+      zsad = 0.0_wp
+      zhad = 0.0_wp
+      zsrad = 0.0_wp
+      zr1ad = 0.0_wp
+      zr2ad = 0.0_wp
+      zr3ad = 0.0_wp
+      zr4ad = 0.0_wp
+      zrhopad = 0.0_wp
+      zead = 0.0_wp
+      zbwad = 0.0_wp
+      zbad = 0.0_wp
+      zdad = 0.0_wp
+      zcad = 0.0_wp
+      zawad = 0.0_wp
+      zaad = 0.0_wp
+      zb1ad  = 0.0_wp
+      za1ad = 0.0_wp
+      zkwad = 0.0_wp
+      zk0ad = 0.0_wp
+
+      SELECT CASE ( nn_eos )
+
+      CASE ( 0 )               !== Jackett and McDougall (1994) formulation ==!
+         zrau0r = 1.e0 / rau0
+#ifdef key_sp
+         zeps = 1.e-7
+#else
+         zeps = 1.e-14
+#endif
+
+!CDIR NOVERRCHK
+         zws(:,:,:) = SQRT( ABS( psal(:,:,:) ) )
+         !
+         DO jk =  jpkm1, 1, -1
+            DO jj = jpj, 1, -1 
+               DO ji = jpi, 1, -1
+                  ! direct recomputing
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  zh = fsdept(ji,jj,jk)        ! depth
+                  zsr = zws(ji,jj,jk)          ! square root salinity
+                  ! compute volumic mass pure water at atm pressure
+                  zr1 = ( ( ( ( 6.536332e-9   * zt - 1.120083e-6 ) * zt &
+                     &        + 1.001685e-4 ) * zt - 9.095290e-3 ) * zt &
+                     &        + 6.793952e-2 ) * zt + 999.842594
+                  ! seawater volumic mass atm pressure
+                  zr2 = ( ( ( 5.3875e-9   * zt - 8.2467e-7 ) * zt       &
+                     &      + 7.6438e-5 ) * zt - 4.0899e-3 ) * zt + 0.824493
+                  zr3 = ( -1.6546e-6 * zt + 1.0227e-4 ) * zt - 5.72466e-3
+                  zr4 = 4.8314e-4
+                  ! potential volumic mass (reference to the surface)
+                  zrhop = ( zr4 * zs + zr3*zsr + zr2 ) * zs + zr1
+                  ! add the compression terms
+                  ze  = ( -3.508914e-8 * zt - 1.248266e-8 ) * zt - 2.595994e-6
+                  zbw = (  1.296821e-6 * zt - 5.782165e-9 ) * zt + 1.045941e-4
+                  zb  = zbw + ze * zs
+
+                  zd = -2.042967e-2
+                  zc =   (-7.267926e-5 * zt + 2.598241e-3 ) * zt + 0.1571896
+                  zaw= ( ( 5.939910e-6 * zt + 2.512549e-3 ) * zt - 0.1028859 &
+                     &   ) * zt - 4.721788
+                  za = ( zd * zsr + zc ) * zs + zaw
+
+                  zb1=   (-0.1909078   * zt + 7.390729 ) * zt - 55.87545
+                  za1= ( ( 2.326469e-3 * zt + 1.553190 ) * zt - 65.00517 &
+                     &   ) * zt + 1044.077
+                  zkw= ( ( (-1.361629e-4 * zt - 1.852732e-2 ) * zt - 30.41638 &
+                     &    ) * zt + 2098.925 ) * zt + 190925.6
+                  zk0= ( zb1 * zsr + za1 ) * zs + zkw
+
+
+                  zrdc1 = 1.0 / ( zk0 - zh * ( za - zh * zb ) )
+                  zrdc2 = 1.0 / ( 1.0 - zh * zrdc1 )
+
+                  ! ============
+                  ! Adjoint part
+                  ! ============
+
+                  ! Masked in situ density anomaly
+
+                  zrhopad = zrhopad + prd_ad(ji,jj,jk) * tmask(ji,jj,jk)    &
+                     &                                 * zrdc2 * zrau0r
+                  zk0ad   = zk0ad   - prd_ad(ji,jj,jk) * tmask(ji,jj,jk)    &
+                     &                                 * zrdc2 * zrdc2 * zh &
+                     &                                 * zrdc1**2 * zrhop   &
+                     &                                 * zrau0r
+                  zaad    = zaad    + prd_ad(ji,jj,jk) * tmask(ji,jj,jk)    &
+                     &                                 * zrdc2 * zrdc2 * zh &
+                     &                                 * zrdc1**2 * zrhop   &
+                     &                                 * zh * zrau0r
+                  zbad    = zbad    - prd_ad(ji,jj,jk) * tmask(ji,jj,jk)    &
+                     &                                 * zrdc2 * zrdc2 * zh &
+                     &                                 * zrdc1**2 * zrhop   &
+                     &                                 * zh * zh * zrau0r
+                  prd_ad(ji,jj,jk) = 0.0_wp
+
+                  zkwad = zkwad + zk0ad
+                  zsrad = zsrad + zk0ad * zb1 * zs  
+                  zb1ad = zb1ad + zk0ad * zs  * zsr
+                  za1ad = za1ad + zk0ad * zs  
+                  zsad  = zsad  + zk0ad * ( zb1 * zsr + za1 )
+                  zk0ad = 0.0_wp
+
+                  ztad  = ztad + zkwad * ( ( (-4.*1.361629e-4   * zt &
+                     &                        -3.*1.852732e-2 ) * zt &
+                     &                        -2.*30.41638    ) * zt &
+                     &                        +   2098.925           )
+                  zkwad = 0.0_wp
+
+                  ztad  = ztad + za1ad * ( ( 3.*2.326469e-3   * zt &
+                     &                      +2.*1.553190    ) * zt &
+                     &                      -   65.00517           )
+                  za1ad = 0.0_wp
+
+                  ztad  = ztad + zb1ad * (-2.*0.1909078     * zt &
+                     &                    +   7.390729           )
+                  zb1ad = 0.0_wp
+
+                  zawad = zawad + zaad
+                  zsrad = zsrad + zaad *   zd * zs
+                  zcad  = zcad  + zaad *   zs
+                  zsad  = zsad  + zaad * ( zd * zsr + zc )
+                  zaad  = 0.0_wp
+
+                  ztad  = ztad + zawad * ( ( 3.*5.939910e-6   * zt &
+                     &                      +2.*2.512549e-3 ) * zt &
+                     &                      -   0.1028859          ) 
+                  zawad = 0.0_wp
+
+                  ztad  = ztad + zcad * (-2.*7.267926e-5   * zt &
+                     &                   +   2.598241e-3        )
+                  zcad  = 0.0_wp
+
+ 
+                  zsad  = zsad  + zbad * ze
+                  zead  = zead  + zbad * zs
+                  zbwad = zbwad + zbad
+                  zbad  = 0.0_wp
+                  
+                  ztad  = ztad + zbwad *  ( 2.*1.296821e-6   * zt &
+                     &                     -   5.782165e-9        ) 
+                  zbwad = 0.0_wp
+
+                  ztad  = ztad + zead * (-2.*3.508914e-8   * zt &
+                     &                   -   1.248266e-8        )
+                  zead =  0.0_wp
+
+                  zrhopad = zrhopad + prhop_ad(ji,jj,jk) * tmask(ji,jj,jk)
+                  prhop_ad(ji,jj,jk) = 0.0_wp
+
+                  zr1ad   = zr1ad + zrhopad
+                  zr2ad   = zr2ad + zrhopad * zs
+                  zr3ad   = zr3ad + zrhopad * zsr * zs
+                  zsrad   = zsrad + zrhopad * zr3 * zs
+                  zsad    = zsad  + zrhopad * ( 2. * zr4 * zs + zr2  &
+                     &                        + zr3 * zsr           )
+                  zrhopad = 0.0_wp
+
+                  ztad  = ztad + zr3ad * (-2.*1.6546e-6   * zt &
+                     &                    +   1.0227e-4        )
+                  zr3ad = 0.0_wp
+
+                  ztad  = ztad + zr2ad * ( ( ( 4.*5.3875e-9   * zt &
+                     &                        -3.*8.2467e-7 ) * zt &
+                     &                        +2.*7.6438e-5 ) * zt &
+                     &                        -   4.0899e-3        )
+                  zr2ad = 0.0_wp
+
+                  ztad  = ztad + zr1ad * ( ( ( ( 5.*6.536332e-9   * zt &
+                     &                          -4.*1.120083e-6 ) * zt &
+                     &                          +3.*1.001685e-4 ) * zt &
+                     &                          -2.*9.095290e-3 ) * zt &
+                     &                          +   6.793952e-2        )
+                  zr1ad = 0.0_wp
+
+                  zsad  = zsad + zsrad * ( 1.0 / MAX( 2.*zsr, zeps ) ) &
+                     &                 * tmask(ji,jj,jk) 
+                  zsrad = 0.0_wp
+ 
+                  psal_ad(ji,jj,jk) = psal_ad(ji,jj,jk) + zsad
+                  ptem_ad(ji,jj,jk) = ptem_ad(ji,jj,jk) + ztad
+                  ztad = 0.0_wp
+                  zsad = 0.0_wp
+               END DO
+            END DO
+         END DO
+         !
+      CASE ( 1 )               !==  Linear formulation = F( temperature )  ==!
+         DO jk = jpkm1, 1, -1
+            prd_ad(:,:,jk) = prd_ad(:,:,jk) + rau0 * prhop_ad(:,:,jk) * tmask(:,:,jk)
+            prhop_ad(:,:,jk) = 0.0_wp
+            ptem_ad(:,:,jk) = ptem_ad(:,:,jk) -  rn_alpha * prd_ad(:,:,jk) * tmask(:,:,jk)
+            prd_ad(:,:,jk) = 0.0_wp
+         END DO
+         !
+      CASE ( 2 )               !==  Linear formulation = F( temperature , salinity )  ==!
+         DO jk = 1, jpkm1
+            prd_ad(  :,:,jk) = prd_ad(:,:,jk) + rau0 * prhop_ad(:,:,jk) * tmask(:,:,jk)
+            prhop_ad(:,:,jk) = 0.0_wp
+            ptem_ad( :,:,jk) = ptem_ad(:,:,jk) - rn_alpha * prd_ad(:,:,jk) * tmask(:,:,jk)
+            psal_ad( :,:,jk) = psal_ad(:,:,jk) + rn_beta   * prd_ad(:,:,jk) * tmask(:,:,jk)
+            prd_ad(  :,:,jk) = 0.0_wp
+         END DO
+         !
+      END SELECT
+
+   END SUBROUTINE eos_insitu_pot_adj
+
+   SUBROUTINE eos_pot_1pt_adj( ptem, psal, ptem_ad, psal_ad, prhop_ad )
+      REAL(wp), INTENT( in ) ::      &
+         ptem,                 &  ! potential temperature
+         psal                     ! salinity
+      REAL(wp), INTENT( inout ) ::   &
+         ptem_ad,              &  ! potential temperature
+         psal_ad                  ! salinity
+      REAL(wp), INTENT( inout ) ::   &
+         prhop_ad                 ! potential density (surface referenced)
+
+      !! * Local declarations
+      INTEGER  ::  ji, jj, jk                ! dummy loop indices
+      REAL(wp) ::   &             ! temporary scalars
+         & zt, zs, zsr, zr1, zr2, zr3, zr4, zrhop,                &
+         & ztad, zsad, zsrad, zr1ad, zr2ad, zr3ad, zr4ad, zrhopad 
+      REAL(wp) :: zws, zwsad, zeps
+      !!----------------------------------------------------------------------
+
+#ifdef key_sp
+      zeps = 1.e-7
+#else
+      zeps = 1.e-14
+#endif
+      zwsad   = 0.0_wp
+      ztad    = 0.0_wp
+      zsad    = 0.0_wp
+      zsrad   = 0.0_wp
+      zr1ad   = 0.0_wp
+      zr2ad   = 0.0_wp
+      zr3ad   = 0.0_wp
+      zr4ad   = 0.0_wp
+      zrhopad = 0.0_wp
+      SELECT CASE ( nn_eos )
+
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+         zws = SQRT( ABS( psal ) )
+
+         zt = ptem
+         zs = psal
+         ! square root salinity
+         zsr= zws
+         ! compute volumic mass pure water at atm pressure
+         zr1= ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt   &
+            -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
+         ! seawater volumic mass atm pressure
+         zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 ) *zt+7.6438e-5 ) *zt   &
+            -4.0899e-3 ) *zt+0.824493
+         zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
+         zr4= 4.8314e-4
+
+         ! ============
+         ! Adjoint part
+         ! ============
+         ! save potential volumic mass
+         zrhopad  = zrhopad + prhop_ad
+         prhop_ad = 0.0_wp
+        ! potential volumic mass (reference to the surface)
+         zr1ad  = zr1ad + zrhopad
+         zr2ad  = zr2ad + zrhopad * zs
+         zr3ad  = zr3ad + zrhopad * zsr * zs   
+         zsrad  = zsrad + zrhopad * zr3 * zs 
+         zsad   = zsad  + zrhopad * ( 2. * zr4 * zs + zr2 &
+            &                       + zr3 * zsr            )
+         zrhopad= 0.0_wp
+
+         ! seawater volumic mass atm pressure
+         ztad  = ztad + zr3ad * ( -2.*1.6546e-6 * zt &
+            &                    +   1.0227e-4       )
+         zr3ad = 0.0_wp
+         ztad  = ztad + zr2ad * ( ( ( 4.*5.3875e-9   * zt &
+            &                        -3.*8.2467e-7 ) * zt &
+            &                        +2.*7.6438e-5 ) * zt &
+            &                        -   4.0899e-3        )
+         zr2ad = 0.0_wp
+        ! compute volumic mass pure water at atm pressure
+         ztad  = ztad + zr1ad * ( ( ( ( 5.*6.536332e-9   * zt &
+            &                          -4.*1.120083e-6 ) * zt &
+            &                          +3.*1.001685e-4 ) * zt &
+            &                          -2.*9.095290e-3 ) * zt &
+            &                          +   6.793952e-2        )
+         zr1ad = 0.0_wp
+         ! square root salinity
+         zwsad = zwsad + zsrad
+         zsrad = 0.0_wp
+
+         ptem_ad = ptem_ad + ztad
+         psal_ad = psal_ad + zsad
+         ztad    = 0.0_wp
+         zsad    = 0.0_wp
+
+         psal_ad = psal_ad + 1/MAX( 2*zws , zeps ) * zwsad 
+         zwsad   = 0.0_wp
+ 
+      CASE ( 1 )               ! Linear formulation function of temperature only
+
+         !   ...  potential volumic mass
+         ptem_ad  = ptem_ad - prhop_ad * rau0 * rn_alpha 
+         prhop_ad = 0.0_wp
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+          !   ...  potential volumic mass
+         ptem_ad  = ptem_ad - prhop_ad * rau0 * rn_alpha
+         psal_ad  = psal_ad + prhop_ad * rau0 * rn_beta
+         prhop_ad = 0.0_wp
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for nn_eos = ', nn_eos
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+     
+   END SUBROUTINE eos_pot_1pt_adj
+   SUBROUTINE eos_insitu_2d_adj( ptem, psal, pdep, ptem_ad, psal_ad, prd_ad )
+      !!-----------------------------------------------------------------------
+      !!
+      !!        ***  ROUTINE eos_insitu_2d_adj : adj OF ROUTINE eos_insitu_2d ***
+      !!
+      !! ** Purpose of direct routine   : Compute the in situ density 
+      !!       (ratio rho/rau0) from potential temperature and salinity 
+      !!       using an equation of state defined through the namelist 
+      !!       parameter nn_eos. * 2D field case
+      !!
+      !! ** Method of direct routine    : 3 cases:
+      !!      nn_eos = 0 : Jackett and McDougall (1994) equation of state.
+      !!         the in situ density is computed directly as a function of
+      !!         potential temperature relative to the surface (the opa t
+      !!         variable), salt and pressure (assuming no pressure variation
+      !!         along geopotential surfaces, i.e. the pressure p in decibars
+      !!         is approximated by the depth in meters.
+      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
+      !!         with pressure                      p        decibars
+      !!              potential temperature         t        deg celsius
+      !!              salinity                      s        psu
+      !!              reference volumic mass        rau0     kg/m**3
+      !!              in situ volumic mass          rho      kg/m**3
+      !!              in situ density anomalie      prd      no units
+      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
+      !!          t = 40 deg celcius, s=40 psu
+      !!      nn_eos = 1 : linear equation of state function of temperature only
+      !!              prd(t) = 0.0285 - rn_alpha * t
+      !!      nn_eos = 2 : linear equation of state function of temperature and
+      !!               salinity
+      !!              prd(t,s) = rn_beta * s - rn_alpha * tn - 1.
+      !!      Note that no boundary condition problem occurs in this routine
+      !!      as (ptem,psal) are defined over the whole domain.
+      !!
+      !! ** Comments on Adjoint Routine : 
+      !!      Care has been taken to avoid division by zero when computing 
+      !!      the inverse of the square root of salinity at masked salinity 
+      !!      points.
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!    8.2 ! 05-03 ((F. Van den Berghe, A. Weaver, N. Daget)  - eosadj.F
+      !!    9.0 ! 08-07 (A. Vidard) first version based on eosadj
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments   
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( in ) ::   &
+         & ptem,                 &  ! potential temperature
+         & psal,                 &  ! salinity
+         & pdep                     ! depth
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         & ptem_ad,              &  ! TL of potential temperature
+         & psal_ad                  ! TL of salinity
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         & prd_ad                   ! TL of potential density (surface referenced)
+      INTEGER ::  ji, jj          ! dummy loop indices
+      REAL(wp) ::   &             ! temporary scalars
+         zt, zs, zh, zsr, zr1, zr2, zr3, zr4, zrhop, ze, zbw,   &
+         zb, zd, zc, zaw, za, zb1, za1, zkw, zk0,               &
+         ztad, zsad, zhad, zsrad, zr1ad, zr2ad, zr3ad,          &
+         zr4ad, zrhopad, zead, zbwad,                           &
+         zbad, zdad, zcad, zawad, zaad, zb1ad, za1ad,           &
+         zkwad, zk0ad, zpes, zrdc1, zrdc2, zeps,                &
+         zmask
+      REAL(wp), DIMENSION(jpi,jpj) :: zws
+      !!----------------------------------------------------------------------
+
+      ! initialization of adjoint variables
+      ztad    = 0.0_wp
+      zsad    = 0.0_wp
+      zhad    = 0.0_wp
+      zsrad   = 0.0_wp
+      zr1ad   = 0.0_wp
+      zr2ad   = 0.0_wp
+      zr3ad   = 0.0_wp
+      zr4ad   = 0.0_wp
+      zrhopad = 0.0_wp
+      zead    = 0.0_wp
+      zbwad   = 0.0_wp
+      zbad    = 0.0_wp
+      zdad    = 0.0_wp
+      zcad    = 0.0_wp
+      zawad   = 0.0_wp
+      zaad    = 0.0_wp
+      zb1ad   = 0.0_wp
+      za1ad   = 0.0_wp
+      zkwad   = 0.0_wp
+      zk0ad   = 0.0_wp
+
+ 
+     SELECT CASE ( nn_eos )
+
+      CASE ( 0 )               !== Jackett and McDougall (1994) formulation ==!
+
+#ifdef key_sp
+         zeps = 1.e-7
+#else
+         zeps = 1.e-14
+#endif
+
+!CDIR NOVERRCHK
+         DO jj = 1, jpjm1
+!CDIR NOVERRCHK
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zws(ji,jj) = SQRT( ABS( psal(ji,jj) ) )
+            END DO
+         END DO
+         !
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zmask = tmask(ji,jj,1)      ! land/sea bottom mask = surf. mask
+               zt = ptem (ji,jj)           ! interpolated T
+               zs = psal (ji,jj)           ! interpolated S
+               zsr= zws(ji,jj)             ! square root of interpolated S
+               zh = pdep(ji,jj)            ! depth at the partial step level
+                  ! compute volumic mass pure water at atm pressure
+                  zr1= ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt   &
+                     &  -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
+                  ! seawater volumic mass atm pressure
+                  zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 ) *zt+7.6438e-5 ) *zt   &
+                     &  -4.0899e-3 ) *zt+0.824493
+                  zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
+                  zr4= 4.8314e-4
+
+                  ! potential volumic mass (reference to the surface)
+                  zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
+
+                  ! add the compression terms
+                  ze = ( -3.508914e-8*zt-1.248266e-8 ) *zt-2.595994e-6
+                  zbw= (  1.296821e-6*zt-5.782165e-9 ) *zt+1.045941e-4
+                  zb = zbw + ze * zs
+
+                  zd = -2.042967e-2
+                  zc =   (-7.267926e-5*zt+2.598241e-3 ) *zt+0.1571896
+                  zaw= ( ( 5.939910e-6*zt+2.512549e-3 ) *zt-0.1028859 ) *zt - 4.721788
+                  za = ( zd*zsr + zc ) *zs + zaw
+
+                  zb1=   (-0.1909078*zt+7.390729 ) *zt-55.87545
+                  za1= ( ( 2.326469e-3*zt+1.553190)*zt-65.00517 ) *zt+1044.077
+                  zkw= ( ( (-1.361629e-4*zt-1.852732e-2 ) *zt-30.41638 ) *zt + 2098.925 ) *zt+190925.6
+                  zk0= ( zb1*zsr + za1 )*zs + zkw
+
+                  zrdc1 = 1.0 / ( zk0 - zh * ( za - zh * zb ) )
+                  zrdc2 = 1.0 / ( 1.0 - zh * zrdc1 )
+                  ! ============
+                  ! Adjoint part
+                  ! ============
+
+                  ! Masked in situ density anomaly
+
+                  zrhopad = zrhopad + prd_ad(ji,jj) * tmask(ji,jj,1)     &
+                     &                              * zrdc2 / rau0
+                  zk0ad   = zk0ad   - prd_ad(ji,jj) * tmask(ji,jj,1)     &
+                     &                              * zrdc2 * zrdc2 * zh &
+                     &                              * zrdc1**2 * zrhop   &
+                     &                              / rau0
+                  zaad    = zaad    + prd_ad(ji,jj) * tmask(ji,jj,1)     &
+                     &                              * zrdc2 * zrdc2 * zh &
+                     &                              * zrdc1**2 * zrhop   &
+                     &                              * zh / rau0
+                  zbad    = zbad    - prd_ad(ji,jj) * tmask(ji,jj,1)     &
+                     &                              * zrdc2 * zrdc2 * zh &
+                     &                              * zrdc1**2 * zrhop   &
+                     &                              * zh * zh / rau0
+                  prd_ad(ji,jj) = 0.0_wp
+
+                  zkwad = zkwad + zk0ad
+                  zsrad = zsrad + zk0ad * zb1 * zs  
+                  zb1ad = zb1ad + zk0ad * zs  * zsr
+                  za1ad = za1ad + zk0ad * zs  
+                  zsad  = zsad  + zk0ad * ( zb1 * zsr + za1 )
+                  zk0ad = 0.0_wp
+
+                  ztad  = ztad + zkwad * ( ( (-4.*1.361629e-4   * zt &
+                     &                        -3.*1.852732e-2 ) * zt &
+                     &                        -2.*30.41638    ) * zt &
+                     &                        +   2098.925           )
+                  zkwad = 0.0_wp
+
+                  ztad  = ztad + za1ad * ( ( 3.*2.326469e-3   * zt &
+                     &                      +2.*1.553190    ) * zt &
+                     &                      -   65.00517           )
+                  za1ad = 0.0_wp
+
+                  ztad  = ztad + zb1ad * (-2.*0.1909078     * zt &
+                     &                    +   7.390729           )
+                  zb1ad = 0.0_wp
+
+                  zawad = zawad + zaad
+                  zsrad = zsrad + zaad *   zd * zs
+                  zcad  = zcad  + zaad *   zs
+                  zsad  = zsad  + zaad * ( zd * zsr + zc )
+                  zaad  = 0.0_wp
+
+                  ztad  = ztad + zawad * ( ( 3.*5.939910e-6   * zt &
+                     &                      +2.*2.512549e-3 ) * zt &
+                     &                      -   0.1028859          ) 
+                  zawad = 0.0_wp
+
+                  ztad  = ztad + zcad * (-2.*7.267926e-5   * zt &
+                     &                   +   2.598241e-3        )
+                  zcad  = 0.0_wp
+
+                  zbwad = zbwad + zbad
+                  zead  = zead  + zbad * zs
+                  zsad  = zsad  + zbad * ze
+                  zbad  = 0.0_wp
+
+                  ztad  = ztad + zbwad *  ( 2.*1.296821e-6   * zt &
+                     &                     -   5.782165e-9        ) 
+                  zbwad = 0.0_wp
+
+                  ztad  = ztad + zead * (-2.*3.508914e-8   * zt &
+                     &                   -   1.248266e-8        )
+                  zead =  0.0_wp
+
+                  zr1ad   = zr1ad + zrhopad
+                  zr2ad   = zr2ad + zrhopad * zs
+                  zr3ad   = zr3ad + zrhopad * zsr * zs
+                  zsrad   = zsrad + zrhopad * zr3 * zs
+                  zsad    = zsad  + zrhopad * ( 2. * zr4 * zs + zr2  &
+                     &                        + zr3 * zsr           )
+                  zrhopad = 0.0_wp
+
+                  ztad  = ztad + zr3ad * (-2.*1.6546e-6   * zt &
+                     &                    +   1.0227e-4        )
+                  zr3ad = 0.0_wp
+
+                  ztad  = ztad + zr2ad * ( ( ( 4.*5.3875e-9   * zt &
+                     &                        -3.*8.2467e-7 ) * zt &
+                     &                        +2.*7.6438e-5 ) * zt &
+                     &                        -   4.0899e-3        )
+                  zr2ad = 0.0_wp
+
+                  ztad  = ztad + zr1ad * ( ( ( ( 5.*6.536332e-9   * zt &
+                     &                          -4.*1.120083e-6 ) * zt &
+                     &                          +3.*1.001685e-4 ) * zt &
+                     &                          -2.*9.095290e-3 ) * zt &
+                     &                          +   6.793952e-2        )
+                  zr1ad = 0.0_wp
+
+                  zsad  = zsad + zsrad * ( 1.0 / MAX( 2.*zsr, zeps ) ) &
+                     &                 * tmask(ji,jj, 1) 
+                  zsrad = 0.0_wp
+ 
+                  psal_ad(ji,jj) = psal_ad(ji,jj) + zsad
+                  ptem_ad(ji,jj) = ptem_ad(ji,jj) + ztad
+                  ztad = 0.0_wp
+                  zsad = 0.0_wp
+            END DO
+         END DO
+         !
+      CASE ( 1 )                !==  Linear formulation = F( temperature )  ==!
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ptem_ad(ji,jj) = ptem_ad(ji,jj) - prd_ad(ji,jj) * rn_alpha * tmask(ji,jj,1)
+               prd_ad(ji,jj) = 0.0_wp
+            END DO
+         END DO
+         !
+      CASE ( 2 )               !==  Linear formulation = F( temperature , salinity )  ==!
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ptem_ad(ji,jj) = ptem_ad(ji,jj) - prd_ad(ji,jj) * rn_alpha * tmask(ji,jj,1) 
+               psal_ad(ji,jj) = psal_ad(ji,jj) + prd_ad(ji,jj) * rn_beta  * tmask(ji,jj,1)
+               prd_ad (ji,jj) = 0.0_wp
+            END DO
+         END DO
+         !
+      END SELECT
+   END SUBROUTINE eos_insitu_2d_adj
+
+   SUBROUTINE eos_bn2_tan ( ptem, psal, ptem_tl, psal_tl, pn2_tl )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE eos_bn2_tan  ***
+      !!
+      !! ** Purpose of the direct routine:   Compute the local 
+      !!      Brunt-Vaisala frequency at the time-step of the input arguments
+      !!      
+      !! ** Method of the direct routine:
+      !!       * nn_eos = 0  : UNESCO sea water properties
+      !!         The brunt-vaisala frequency is computed using the polynomial
+      !!      polynomial expression of McDougall (1987):
+      !!            N^2 = grav * beta * ( alpha/beta*dk[ t ] - dk[ s ] )/e3w
+      !!      If lk_zdfddm=T, the heat/salt buoyancy flux ratio Rrau is
+      !!      computed and used in zdfddm module :
+      !!              Rrau = alpha/beta * ( dk[ t ] / dk[ s ] )
+      !!       * nn_eos = 1  : linear equation of state (temperature only)
+      !!            N^2 = grav * rn_alpha * dk[ t ]/e3w
+      !!       * nn_eos = 2  : linear equation of state (temperature & salinity)
+      !!            N^2 = grav * (rn_alpha * dk[ t ] - rn_beta * dk[ s ] ) / e3w
+      !!      The use of potential density to compute N^2 introduces e r r o r
+      !!      in the sign of N^2 at great depths. We recommand the use of 
+      !!      nn_eos = 0, except for academical studies.
+      !!        Macro-tasked on horizontal slab (jk-loop)
+      !!      N.B. N^2 is set to zero at the first level (JK=1) in inidtr
+      !!      and is never used at this level.
+      !!
+      !! ** Action  : - pn2 : the brunt-vaisala frequency
+      !!
+      !! References :
+      !!      McDougall, T. J., J. Phys. Oceanogr., 17, 1950-1964, 1987.
+      !!
+      !! History:
+      !!        !  08-07  (A. Vidard) First version
+      !!----------------------------------------------------------------------
+      !! * Arguments
+
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem,                 &  ! potential temperature
+         psal                     ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem_tl,              &  ! potential temperature
+         psal_tl                  ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   &
+         pn2_tl                   ! Brunt-Vaisala frequency
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::             &
+         zgde3w, zt, zs, zh,  &  ! temporary scalars 
+         zalbet, zbeta           !    "         "
+      REAL(wp) ::             &
+         zttl, zstl,          &  ! temporary scalars 
+         zalbettl, zbetatl       !    "         "
+#if defined key_zdfddm
+      REAL(wp) ::   zds, zdstl   ! temporary scalars
+#endif
+
+      ! pn2_tl : interior points only (2=< jk =< jpkm1 )
+      ! -------------------------- 
+
+      SELECT CASE ( nn_eos )
+
+      CASE ( 0 )               !== Jackett and McDougall (1994) formulation ==!
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zgde3w = grav / fse3w(ji,jj,jk)
+                  zt = 0.5 * ( ptem(ji,jj,jk) + ptem(ji,jj,jk-1) )          ! potential temperature at w-point
+                  zs = 0.5 * ( psal(ji,jj,jk) + psal(ji,jj,jk-1) ) - 35.0   ! salinity anomaly (s-35) at w-point
+                  zh = fsdepw(ji,jj,jk)                                     ! depth in meters  at w-point
+
+                  zalbet = ( ( ( - 0.255019e-07 * zt + 0.298357e-05 ) * zt   &   ! ratio alpha/beta
+                     &                               - 0.203814e-03 ) * zt   &
+                     &                               + 0.170907e-01 ) * zt   &
+                     &   + 0.665157e-01                                      &
+                     &   +     ( - 0.678662e-05 * zs                         &
+                     &           - 0.846960e-04 * zt + 0.378110e-02 ) * zs   &
+                     &   +   ( ( - 0.302285e-13 * zh                         &
+                     &           - 0.251520e-11 * zs                         &
+                     &           + 0.512857e-12 * zt * zt           ) * zh   &
+                     &           - 0.164759e-06 * zs                         &
+                     &        +(   0.791325e-08 * zt - 0.933746e-06 ) * zt   &
+                     &                               + 0.380374e-04 ) * zh
+
+                  zbeta  = ( ( -0.415613e-09 * zt + 0.555579e-07 ) * zt      &   ! beta
+                     &                            - 0.301985e-05 ) * zt      &
+                     &   + 0.785567e-03                                      &
+                     &   + (     0.515032e-08 * zs                           &
+                     &         + 0.788212e-08 * zt - 0.356603e-06 ) * zs     &
+                     &   +(  (   0.121551e-17 * zh                           &
+                     &         - 0.602281e-15 * zs                           &
+                     &         - 0.175379e-14 * zt + 0.176621e-12 ) * zh     &
+                     &                             + 0.408195e-10   * zs     &
+                     &     + ( - 0.213127e-11 * zt + 0.192867e-09 ) * zt     &
+                     &                             - 0.121555e-07 ) * zh
+
+
+                  !! tangent part
+                  zttl = 0.5 * ( ptem_tl(ji,jj,jk) + ptem_tl(ji,jj,jk-1) )          ! potential temperature at w-point
+                  zstl = 0.5 * ( psal_tl(ji,jj,jk) + psal_tl(ji,jj,jk-1) )   ! salinity anomaly at w-point
+                  zalbettl = (    (   ( -4.*0.255019e-07   * zt                    &! ratio alpha/beta
+                     &              +3.*0.298357e-05 ) * zt                        &
+                     &              -2.*0.203814e-03 ) * zt                        &
+                     &      +           0.170907e-01                               &
+                     &      -           0.846960e-04   * zs                        &
+                     &      - (         0.933746e-06                               &
+                     &          - (  2.*0.791325e-08                               & 
+                     &              +2.*0.512857e-12   * zh ) * zt ) * zh ) * zttl &
+                     & + (  -        2.*0.678662e-05   * zs                        &
+                     &      -           0.846960e-04   * zt                        &
+                     &      +           0.378110e-02                               &
+                     &      + (     -   0.164759e-06                               &
+                     &              -   0.251520e-11   * zh ) * zh         ) * zstl
+
+                  zbetatl = (    (     -3.*0.415613e-09   * zt               &
+                     &              +2.*0.555579e-07 ) * zt                  &
+                     &      -           0.301985e-05                         &
+                     &      +           0.788212e-08   * zs                  &
+                     &      + (     -2.*0.213127e-11   * zt                  &
+                     &              -   0.175379e-14   * zh                  &
+                     &              +   0.192867e-09         ) * zh ) * zttl &
+                     & + (           2.*0.515032e-08   * zs                  &
+                     &      +           0.788212e-08   * zt                  &
+                     &      -           0.356603e-06                         &
+                     &      + (     -   0.602281e-15   * zh                  &
+                     &              +   0.408195e-10         ) * zh ) * zstl 
+
+                     pn2_tl(ji,jj,jk) = zgde3w * tmask(ji,jj,jk) * (                                   &
+                  &       zbeta   * (  zalbet                                        &
+                  &                  * ( ptem_tl(ji,jj,jk-1) - ptem_tl(ji,jj,jk) )   &
+                  &                 +  zalbettl                                      &
+                  &                 * ( ptem  (ji,jj,jk-1) - ptem  (ji,jj,jk) )      &
+                  &                 -  ( psal_tl(ji,jj,jk-1) - psal_tl(ji,jj,jk) ) ) &
+                  &     + zbetatl * (  zalbet                                        &
+                  &                  * ( ptem  (ji,jj,jk-1) - ptem  (ji,jj,jk) )     &
+                  &                 -  ( psal  (ji,jj,jk-1) - psal  (ji,jj,jk) ) ) )
+#if defined key_zdfddm
+                     zds = ( psal(ji,jj,jk-1) - psal(ji,jj,jk) )
+                     zdstl = ( psal_tl(ji,jj,jk-1) - psal_tl(ji,jj,jk) ) 
+                     IF ( ABS( zds) <= 1.e-20 ) THEN
+                        zds = 1.e-20
+                        rrau_tl(ji,jj,jk) = zalbettl * &
+                             &    ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) ) / zds       &
+                             &              + zalbet *   &
+                             &  ( ( ptem_tl(ji,jj,jk-1) - ptem_tl(ji,jj,jk) ) / zds )
+                     ELSE
+                     rrau_tl(ji,jj,jk) = zalbettl * &
+                        &    ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) ) / zds       &
+                        &              + zalbet *   &
+                        &  ( ( ptem_tl(ji,jj,jk-1) - ptem_tl(ji,jj,jk) ) / zds &
+                        &  - ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) ) * zdstl/ zds**2 )
+                  ENDIF
+#endif
+               END DO
+            END DO
+         END DO
+         !
+      CASE ( 1 )                !==  Linear formulation = F( temperature )  ==!
+         DO jk = 2, jpkm1
+            pn2_tl(:,:,jk) = rn_alpha * ( ptem_tl(:,:,jk-1) - ptem_tl(:,:,jk) ) * grav / fse3w(:,:,jk) * tmask(:,:,jk)
+         END DO
+         !
+      CASE ( 2 )               !==  Linear formulation = F( temperature , salinity )  ==!
+         DO jk = 2, jpkm1
+            pn2_tl(:,:,jk) = ( rn_alpha * ( ptem_tl(:,:,jk-1) - ptem_tl(:,:,jk) )    &
+                             & - rn_beta  * ( psal_tl(:,:,jk-1) - psal_tl(:,:,jk) )  ) &
+                             & * grav / fse3w(:,:,jk) * tmask(:,:,jk)
+         END DO
+#if defined key_zdfddm
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zds = ( psal(ji,jj,jk-1) - psal(ji,jj,jk) )
+                  zdstl = psal_tl(ji,jj,jk-1) - psal_tl(ji,jj,jk)
+                  IF ( ABS( zds) <= 1.e-20 ) THEN
+                     zds = 1.e-20
+                     rrau_tl(ji,jj,jk) = ralpbet * &
+                     & ( ( ptem_tl(ji,jj,jk-1) - ptem_tl(ji,jj,jk) ) / zds )
+                  ELSE
+                     rrau_tl(ji,jj,jk) = ralpbet * &
+                     & ( ( ptem_tl(ji,jj,jk-1) - ptem_tl(ji,jj,jk) ) / zds &
+                     & - ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) ) * zdstl / zds**2 )
+                  ENDIF
+                  rrau(ji,jj,jk) = ralpbet * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) ) / zds
+               END DO
+            END DO 
+         END DO                                                
+#endif
+      END SELECT
+
+   END SUBROUTINE eos_bn2_tan
+
+   SUBROUTINE eos_bn2_adj ( ptem, psal, ptem_ad, psal_ad, pn2_ad )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE eos_bn2_adj  ***
+      !!
+      !! ** Purpose of the direct routine:   Compute the local 
+      !!      Brunt-Vaisala frequency at the time-step of the input arguments
+      !!      
+      !! ** Method of the direct routine:
+      !!       * nn_eos = 0  : UNESCO sea water properties
+      !!         The brunt-vaisala frequency is computed using the polynomial
+      !!      polynomial expression of McDougall (1987):
+      !!            N^2 = grav * beta * ( alpha/beta*dk[ t ] - dk[ s ] )/e3w
+      !!      If lk_zdfddm=T, the heat/salt buoyancy flux ratio Rrau is
+      !!      computed and used in zdfddm module :
+      !!              Rrau = alpha/beta * ( dk[ t ] / dk[ s ] )
+      !!       * nn_eos = 1  : linear equation of state (temperature only)
+      !!            N^2 = grav * rn_alpha * dk[ t ]/e3w
+      !!       * nn_eos = 2  : linear equation of state (temperature & salinity)
+      !!            N^2 = grav * (rn_alpha * dk[ t ] - rn_beta * dk[ s ] ) / e3w
+      !!      The use of potential density to compute N^2 introduces e r r o r
+      !!      in the sign of N^2 at great depths. We recommand the use of 
+      !!      nn_eos = 0, except for academical studies.
+      !!        Macro-tasked on horizontal slab (jk-loop)
+      !!      N.B. N^2 is set to zero at the first level (JK=1) in inidtr
+      !!      and is never used at this level.
+      !!
+      !! ** Action  : - pn2 : the brunt-vaisala frequency
+      !!
+      !! References :
+      !!      McDougall, T. J., J. Phys. Oceanogr., 17, 1950-1964, 1987.
+      !!
+      !! History:
+      !!        !  08-07  (A. Vidard) First version
+      !!----------------------------------------------------------------------
+      !! * Arguments
+
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem,                 &  ! potential temperature
+         psal                     ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         ptem_ad,              &  ! adjoint potential temperature
+         psal_ad                  ! adjoint salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         pn2_ad                   ! adjoint Brunt-Vaisala frequency
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::             &
+         zgde3w, zt, zs, zh,  &  ! temporary scalars 
+         zalbet, zbeta           !    "         "
+      REAL(wp) ::             &
+         ztad, zsad,          &  ! temporary scalars 
+         zalbetad, zbetaad       !    "         "
+#if defined key_zdfddm
+      REAL(wp) ::   zds, zdsad          ! temporary scalars
+#endif
+
+      ! pn2_tl : interior points only (2=< jk =< jpkm1 )
+      ! -------------------------- 
+      zalbetad = 0.0_wp
+      zbetaad  = 0.0_wp
+      ztad     = 0.0_wp
+      zsad     = 0.0_wp
+#if defined key_zdfddm
+      zdsad    = 0.0_wp
+#endif
+
+      SELECT CASE ( nn_eos )
+
+      CASE ( 0 )               !== Jackett and McDougall (1994) formulation ==!
+         DO jk = jpkm1, 2, -1
+            DO jj = jpj, 1, -1
+               DO ji = jpi, 1, -1
+                  zgde3w = grav / fse3w(ji,jj,jk)
+                  zt = 0.5 * ( ptem(ji,jj,jk) + ptem(ji,jj,jk-1) )          ! potential temperature at w-point
+                  zs = 0.5 * ( psal(ji,jj,jk) + psal(ji,jj,jk-1) ) - 35.0   ! salinity anomaly (s-35) at w-point
+                  zh = fsdepw(ji,jj,jk)                                     ! depth in meters  at w-point
+
+                  zalbet = ( ( ( - 0.255019e-07 * zt + 0.298357e-05 ) * zt   &   ! ratio alpha/beta
+                     &                               - 0.203814e-03 ) * zt   &
+                     &                               + 0.170907e-01 ) * zt   &
+                     &   + 0.665157e-01                                      &
+                     &   +     ( - 0.678662e-05 * zs                         &
+                     &           - 0.846960e-04 * zt + 0.378110e-02 ) * zs   &
+                     &   +   ( ( - 0.302285e-13 * zh                         &
+                     &           - 0.251520e-11 * zs                         &
+                     &           + 0.512857e-12 * zt * zt           ) * zh   &
+                     &           - 0.164759e-06 * zs                         &
+                     &        +(   0.791325e-08 * zt - 0.933746e-06 ) * zt   &
+                     &                               + 0.380374e-04 ) * zh
+
+                  zbeta  = ( ( -0.415613e-09 * zt + 0.555579e-07 ) * zt      &   ! beta
+                     &                            - 0.301985e-05 ) * zt      &
+                     &   + 0.785567e-03                                      &
+                     &   + (     0.515032e-08 * zs                           &
+                     &         + 0.788212e-08 * zt - 0.356603e-06 ) * zs     &
+                     &   +(  (   0.121551e-17 * zh                           &
+                     &         - 0.602281e-15 * zs                           &
+                     &         - 0.175379e-14 * zt + 0.176621e-12 ) * zh     &
+                     &                             + 0.408195e-10   * zs     &
+                     &     + ( - 0.213127e-11 * zt + 0.192867e-09 ) * zt     &
+                     &                             - 0.121555e-07 ) * zh
+
+
+#if defined key_zdfddm
+                  
+                  zds = ( psal(ji,jj,jk-1) - psal(ji,jj,jk) )         
+                  IF ( ABS( zds) <= 1.e-20 ) THEN
+                     zds = 1.e-20    
+                     zdsad = 0.0_wp
+                  ELSE
+                     zdsad = rrau_ad(ji,jj,jk) * zalbet *( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) ) / zds**2
+                  ENDIF
+                  ptem_ad(ji,jj,jk-1) =  ptem_ad(ji,jj,jk-1) +  rrau_ad(ji,jj,jk) * zalbet / zds                  
+                  ptem_ad(ji,jj,jk  ) =  ptem_ad(ji,jj,jk  ) -  rrau_ad(ji,jj,jk) * zalbet / zds
+                  zalbetad = zalbetad + rrau_ad(ji,jj,jk) * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) ) / zds
+                  rrau_ad(ji,jj,jk) = 0._wp
+
+                  psal_ad(ji,jj,jk-1) = psal_ad(ji,jj,jk-1) + zdsad
+                  psal_ad(ji,jj,jk  ) = psal_ad(ji,jj,jk  ) - zdsad
+                  zdsad = 0._wp
+#endif
+                     ptem_ad(ji,jj,jk-1) = ptem_ad(ji,jj,jk-1) + zalbet*zbeta*zgde3w*tmask(ji,jj,jk)*pn2_ad(ji,jj,jk)
+                     ptem_ad(ji,jj,jk)   = ptem_ad(ji,jj,jk  ) - zalbet*zbeta*zgde3w*tmask(ji,jj,jk)*pn2_ad(ji,jj,jk)
+                     zalbetad = zalbetad + zbeta*zgde3w*tmask(ji,jj,jk)*( ptem  (ji,jj,jk-1) - ptem  (ji,jj,jk) ) *pn2_ad(ji,jj,jk) 
+                     psal_ad(ji,jj,jk-1) = psal_ad(ji,jj,jk-1) - zbeta*tmask(ji,jj,jk)*zgde3w*pn2_ad(ji,jj,jk) 
+                     psal_ad(ji,jj,jk  ) = psal_ad(ji,jj,jk  ) + zbeta*tmask(ji,jj,jk)*zgde3w*pn2_ad(ji,jj,jk) 
+                     zbetaad = zbetaad &
+                        & + zgde3w *tmask(ji,jj,jk)* (  zalbet * ( ptem  (ji,jj,jk-1) - ptem  (ji,jj,jk) )  &
+                        & -  ( psal  (ji,jj,jk-1) - psal  (ji,jj,jk) ) )*pn2_ad(ji,jj,jk) 
+
+                     pn2_ad(ji,jj,jk)  = 0.0_wp
+
+                     ztad = ztad + (    (     -3.*0.415613e-09   * zt           &
+                        &              +2.*0.555579e-07 ) * zt                  &
+                        &      -           0.301985e-05                         &
+                        &      +           0.788212e-08   * zs                  &
+                        &      + (     -2.*0.213127e-11   * zt                  &
+                        &              -   0.175379e-14   * zh                  &
+                        &              +   0.192867e-09         ) * zh ) *zbetaad
+
+                     zsad = zsad + (           2.*0.515032e-08   * zs           &
+                        &      +           0.788212e-08   * zt                  &
+                        &      -           0.356603e-06                         &
+                        &      + (     -   0.602281e-15   * zh                  &
+                        &              +   0.408195e-10         ) * zh ) * zbetaad
+
+                     zbetaad = 0.0_wp
+
+                     ztad = ztad + (    (   ( -4.*0.255019e-07   * zt           &! ratio alpha/beta
+                        &              +3.*0.298357e-05 ) * zt                  &
+                        &              -2.*0.203814e-03 ) * zt                  &
+                        &      +           0.170907e-01                         &
+                        &      -           0.846960e-04   * zs                  &
+                        &      - (         0.933746e-06                         &
+                        &          - (  2.*0.791325e-08                         & 
+                        &              +2.*0.512857e-12   * zh ) * zt ) * zh    &
+                        &                                                 ) *zalbetad
+
+                     zsad = zsad + (  -        2.*0.678662e-05   * zs           &
+                        &      -           0.846960e-04   * zt                  &
+                        &      +           0.378110e-02                         &
+                        &      + (     -   0.164759e-06                         &
+                        &              -   0.251520e-11   * zh ) * zh           &
+                        &                                                 ) *zalbetad
+
+                     zalbetad = 0.0_wp
+
+
+                     psal_ad(ji,jj,jk) = psal_ad(ji,jj,jk) + 0.5 * zsad
+                     psal_ad(ji,jj,jk-1) = psal_ad(ji,jj,jk-1) + 0.5 * zsad
+                     zsad = 0.0_wp
+
+                     ptem_ad(ji,jj,jk) = ptem_ad(ji,jj,jk) + 0.5 * ztad
+                     ptem_ad(ji,jj,jk-1) = ptem_ad(ji,jj,jk-1) + 0.5 * ztad
+                     ztad = 0.0_wp
+
+               END DO
+            END DO
+         END DO
+         !
+      CASE ( 1 )               !==  Linear formulation = F( temperature )  ==!
+         DO jk = jpkm1, 2, -1
+            ptem_ad(:,:,jk-1) = ptem_ad(:,:,jk-1)  + rn_alpha * pn2_ad(:,:,jk) &
+                                      & * grav / fse3w(:,:,jk) * tmask(:,:,jk)
+            ptem_ad(:,:,jk  ) = ptem_ad(:,:,jk  )  - rn_alpha * pn2_ad(:,:,jk) &
+                                      & * grav / fse3w(:,:,jk) * tmask(:,:,jk) 
+            pn2_ad(:,:,jk) = 0.0_wp
+         END DO
+         !
+      CASE ( 2 )               !==  Linear formulation = F( temperature , salinity )  ==!
+#if defined key_zdfddm
+         DO jk = jpkm1, 2, -1
+            DO jj = jpj, 1, -1
+               DO ji = jpi, 1, -1
+                  zds = ( psal(ji,jj,jk-1) - psal(ji,jj,jk) )
+                  IF ( ABS( zds) <= 1.e-20 ) THEN
+                     zds = 1.e-20    
+                     zdsad = 0.0_wp
+                  ELSE
+                     zdsad = zdsad - rrau_ad(ji,jj,jk) * ralpbet &
+                     & * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) ) / zds**2
+                  ENDIF
+                  rrau(ji,jj,jk) = ralpbet * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) ) / zds
+                  ptem_ad(ji,jj,jk-1) = ptem_ad(ji,jj,jk-1)   &
+                     & + rrau_ad(ji,jj,jk) * ralpbet / zds
+                  ptem_ad(ji,jj,jk  ) = ptem_ad(ji,jj,jk  )   &
+                     & - rrau_ad(ji,jj,jk) * ralpbet / zds
+                  rrau_ad(ji,jj,jk)  = 0._wp
+
+                  psal_ad(ji,jj,jk-1) = psal_ad(ji,jj,jk-1) + zdsad
+                  psal_ad(ji,jj,jk  ) = psal_ad(ji,jj,jk  ) - zdsad
+                  zdsad = 0._wp
+               END DO
+            END DO
+         END DO
+#endif          
+         DO jk = jpkm1, 2, -1
+            ptem_ad(:,:,jk-1) = ptem_ad(:,:,jk-1) + rn_alpha * pn2_ad(:,:,jk) &
+                       & * grav / fse3w(:,:,jk) * tmask(:,:,jk)
+            ptem_ad(:,:,jk  ) = ptem_ad(:,:,jk  ) - rn_alpha * pn2_ad(:,:,jk) &
+                       & * grav / fse3w(:,:,jk) * tmask(:,:,jk)
+            psal_ad(:,:,jk-1) = psal_ad(:,:,jk-1) - rn_beta  * pn2_ad(:,:,jk) &
+                       & * grav / fse3w(:,:,jk) * tmask(:,:,jk)
+            psal_ad(:,:,jk  ) = psal_ad(:,:,jk  ) + rn_beta  * pn2_ad(:,:,jk) &
+                       & * grav / fse3w(:,:,jk) * tmask(:,:,jk)
+            pn2_ad(:,:,jk) = 0.0_wp
+         END DO
+      END SELECT
+
+   END SUBROUTINE eos_bn2_adj
+
+#if defined key_tam
+   SUBROUTINE eos_insitu_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE eos_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-07 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         ztem,                   &  ! potential temperature
+         zsal                       ! salinity
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zt_adout,             &  ! potential temperature
+         & zs_adout                 ! salinity
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zrd_adin                 ! anomaly density
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zt_tlin,              &  ! potential temperature
+         & zs_tlin                  ! salinity
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & znt,                 &  ! potential temperature
+         & zns                     ! salinity
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zrd_tlout                  ! anomaly density 
+      REAL(KIND=wp) ::       &
+         & zsp1,             & ! scalar product involving the tangent routine
+         & zsp2,             & ! scalar product involving the adjoint routine
+         & zsp2_1,           & ! scalar product involving the adjoint routine
+         & zsp2_2              ! scalar product involving the adjoint routine
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d           ! 2D seed for the random number generator
+      INTEGER :: &
+         & ji, &
+         & jj, &
+         & jk, &
+	 & jn, &
+	 & jeos
+         
+      CHARACTER(LEN=14) :: cl_name
+
+      ALLOCATE( & 
+         & ztem(     jpi, jpj, jpk ),  &
+         & zsal(     jpi, jpj, jpk ),  &
+         & znt(      jpi, jpj, jpk ),  &
+         & zns(      jpi, jpj, jpk ),  &
+         & zt_adout( jpi, jpj, jpk ),  &  
+         & zs_adout( jpi, jpj, jpk ),  &
+         & zrd_adin( jpi, jpj, jpk ),  &
+         & zs_tlin(  jpi, jpj, jpk ),  &
+         & zt_tlin(  jpi, jpj, jpk ),  &
+         & zrd_tlout(jpi, jpj, jpk )    )
+      ! Initialize the reference state
+      ztem(:,:,:) = tn(:,:,:)
+      zsal(:,:,:) = sn(:,:,:)
+
+      ! store initial nn_eos
+      jeos = nn_eos
+      DO jn = 0, 2
+         nn_eos = jn
+         !=============================================================
+         ! 1) dx = ( T ) and dy = ( T )
+         !=============================================================
+
+         !--------------------------------------------------------------------
+         ! Reset the tangent and adjoint variables
+         !--------------------------------------------------------------------
+         zt_tlin(:,:,:)     = 0.0_wp
+         zs_tlin(:,:,:)     = 0.0_wp
+         zrd_tlout(:,:,:)   = 0.0_wp
+         zt_adout(:,:,:)    = 0.0_wp
+         zs_adout(:,:,:)    = 0.0_wp
+         zrd_adin(:,:,:)    = 0.0_wp
+
+         !--------------------------------------------------------------------
+         ! Initialize the tangent input with random noise: dx
+         !--------------------------------------------------------------------
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 456953 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, znt, 'T', 0.0_wp, stdt )
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 395703 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zns, 'T', 0.0_wp, stds )
+
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zt_tlin(ji,jj,jk) = znt(ji,jj,jk)
+                  zs_tlin(ji,jj,jk) = zns(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      
+         CALL eos_insitu_tan(ztem, zsal, zt_tlin, zs_tlin, zrd_tlout)
+ 
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zrd_adin(ji,jj,jk)   = zrd_tlout(ji,jj,jk) &
+                       &                 * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)&
+                       &                 * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !--------------------------------------------------------------------
+
+         zsp1 = DOT_PRODUCT( zrd_tlout, zrd_adin )
+
+         !--------------------------------------------------------------------
+         ! Call the adjoint routine: dx^* = L^T dy^*
+         !--------------------------------------------------------------------
+
+         CALL eos_insitu_adj(ztem, zsal, zt_adout, zs_adout, zrd_adin)
+
+         zsp2_1 = DOT_PRODUCT( zt_tlin, zt_adout )
+         zsp2_2 = DOT_PRODUCT( zs_tlin, zs_adout )
+         zsp2   = zsp2_1 + zsp2_2
+
+         ! Compare the scalar products
+
+         ! Compare the scalar products
+         ! 14 char:'12345678901234'
+         SELECT CASE( jn )
+         CASE (0) ; cl_name = 'eos_adj ins T1'
+         CASE (1) ; cl_name = 'eos_adj ins T2'
+         CASE (2) ; cl_name = 'eos_adj ins T3'
+         END SELECT
+         CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+      ENDDO
+      ! restore initial nn_eos
+      nn_eos = jeos
+
+      ! Deallocate memory
+
+      DEALLOCATE(      &
+         & ztem,       &
+         & zsal,       &
+         & zt_adout,   &    
+         & zs_adout,   &
+         & zrd_adin,   &
+         & zt_tlin,    &
+         & zs_tlin,    &
+         & zrd_tlout,  &
+         & znt,        &
+         & zns         &
+         & )
+            
+
+   END SUBROUTINE eos_insitu_adj_tst
+   SUBROUTINE eos_insitu_pot_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE eos_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Separate tests are applied for the following dx and dy:
+      !!                
+      !!              1) dx = ( SSH ) and dy = ( SSH )
+      !!                   
+      !! History :
+      !!        ! 08-07 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         ztem,                   &  ! potential temperature
+         zsal                       ! salinity
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zt_adout,             &  ! potential temperature
+         & zs_adout                 ! salinity
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zrd_adin                 ! anomaly density
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zrhop_adin               ! volume mass
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zt_tlin,              &  ! potential temperature
+         & zs_tlin                  ! salinity
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & znt,                 &  ! potential temperature
+         & zns                     ! salinity
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zrd_tlout                  ! anomaly density 
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zrhop_tlout                  ! volume mass
+      REAL(KIND=wp) ::       &
+         & zsp1,             & ! scalar product involving the tangent routine
+         & zsp2,             & ! scalar product involving the adjoint routine
+         & zsp2_1,           & ! scalar product involving the adjoint routine
+         & zsp2_2              ! scalar product involving the adjoint routine
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d           ! 2D seed for the random number generator
+      INTEGER :: &
+         & ji, &
+         & jj, &
+         & jk, &
+         & jn, &
+         & jeos
+      CHARACTER(LEN=14) :: cl_name
+
+       ! Allocate memory
+      ALLOCATE( & 
+         & ztem(     jpi, jpj, jpk ),  &
+         & zsal(     jpi, jpj, jpk ),  &
+         & zt_adout( jpi, jpj, jpk ),  &  
+         & zs_adout( jpi, jpj, jpk ),  &
+         & zrhop_adin( jpi, jpj, jpk ),  &
+         & zrd_adin( jpi, jpj, jpk ),  &
+         & zs_tlin(  jpi, jpj, jpk ),  &
+         & zt_tlin(  jpi, jpj, jpk ),  &
+         & zns(      jpi, jpj, jpk ),  &
+         & znt(      jpi, jpj, jpk ),  &
+         & zrd_tlout(jpi, jpj, jpk ),  &
+         & zrhop_tlout(jpi, jpj, jpk )    )
+
+      ! Initialize random field standard deviationsthe reference state
+      ztem = tn
+      zsal = sn
+
+      ! store initial nn_eos
+      jeos = nn_eos
+      DO jn = 0, 2
+         nn_eos = jn
+         !============================================= 
+         !  testing of eos_insitu_pot
+         !=============================================
+
+         !=============================================================
+         ! 1) dx = ( T ) and dy = ( T )
+         !=============================================================
+
+         !--------------------------------------------------------------------
+         ! Reset the tangent and adjoint variables
+         !--------------------------------------------------------------------
+         zt_tlin(:,:,:)     = 0.0_wp
+         zs_tlin(:,:,:)     = 0.0_wp
+         zrd_tlout(:,:,:)   = 0.0_wp
+         zrhop_tlout(:,:,:) = 0.0_wp
+         zt_adout(:,:,:)    = 0.0_wp
+         zs_adout(:,:,:)    = 0.0_wp
+         zrhop_adin(:,:,:)  = 0.0_wp
+         zrd_adin(:,:,:)    = 0.0_wp
+
+         !--------------------------------------------------------------------
+         ! Initialize the tangent input with random noise: dx
+         !--------------------------------------------------------------------
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 456953 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, znt, 'T', 0.0_wp, stdt )
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 456953 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zns, 'T', 0.0_wp, stds )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zt_tlin(ji,jj,jk) = znt(ji,jj,jk)
+                  zs_tlin(ji,jj,jk) = zns(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !--------------------------------------------------------------------
+         ! Call the tangent routine: dy = L dx
+         !--------------------------------------------------------------------
+
+         call eos_insitu_pot_tan ( ztem, zsal, zt_tlin, zs_tlin, zrd_tlout, zrhop_tlout ) 
+
+         !--------------------------------------------------------------------
+         ! Initialize the adjoint variables: dy^* = W dy
+         !--------------------------------------------------------------------
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zrd_adin(ji,jj,jk)   = zrd_tlout(ji,jj,jk) &
+                       &                 * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)&
+                       &                 * tmask(ji,jj,jk)
+                  zrhop_adin(ji,jj,jk) = zrhop_tlout(ji,jj,jk) &
+                       &                 * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)&
+                       &                 * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+             
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !--------------------------------------------------------------------
+
+         zsp1 =  DOT_PRODUCT( zrd_tlout  , zrd_adin   ) &
+              &  + DOT_PRODUCT( zrhop_tlout, zrhop_adin ) 
+         !--------------------------------------------------------------------
+         ! Call the adjoint routine: dx^* = L^T dy^*
+         !--------------------------------------------------------------------
+
+         CALL eos_insitu_pot_adj( ztem, zsal, zt_adout, zs_adout, zrd_adin, zrhop_adin ) 
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: dx^T L^T W dy
+         !--------------------------------------------------------------------
+       
+         zsp2_1 = DOT_PRODUCT( zt_tlin, zt_adout )
+         zsp2_2 = DOT_PRODUCT( zs_tlin, zs_adout )
+         zsp2 = zsp2_1 + zsp2_2  
+         ! Compare the scalar products
+         
+         ! 14 char:'12345678901234'
+         SELECT CASE( jn )
+         CASE (0) ; cl_name = 'eos_adj pot T1'
+         CASE (1) ; cl_name = 'eos_adj pot T2'
+         CASE (2) ; cl_name = 'eos_adj pot T3'
+         END SELECT
+         CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      ENDDO
+
+      ! restore initial nn_eos
+      nn_eos = jeos
+
+      ! Deallocate memory
+      DEALLOCATE(       &
+         & ztem,       &
+         & zsal,       &
+         & zt_adout,   &    
+         & zs_adout,   &
+         & zrd_adin,   &
+         & zrhop_adin, &
+         & zt_tlin,    &
+         & zs_tlin,    &
+         & zrd_tlout,  & 
+         & zrhop_tlout,&
+         & zns, znt    )
+            
+   END SUBROUTINE eos_insitu_pot_adj_tst
+   SUBROUTINE eos_insitu_2d_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE eos_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Separate tests are applied for the following dx and dy:
+      !!                
+      !!              1) dx = ( SSH ) and dy = ( SSH )
+      !!                   
+      !! History :
+      !!        ! 08-07 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   &
+         zdep                       ! depth
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   &
+         ztem,                   &  ! potential temperature
+         zsal                       ! salinity
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   &
+         & zt_adout,             &  ! potential temperature
+         & zs_adout                 ! salinity
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   &
+         & zrd_adin                 ! anomaly density
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   &
+         & zt_tlin,              &  ! potential temperature
+         & zs_tlin                  ! salinity
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   &
+         & znt,                 &  ! potential temperature
+         & zns                     ! salinity
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   &
+         & zrd_tlout                  ! anomaly density 
+      REAL(KIND=wp) ::       &
+         & zsp1,             & ! scalar product involving the tangent routine
+         & zsp2,             & ! scalar product involving the adjoint routine
+         & zsp2_1,           & ! scalar product involving the adjoint routine
+         & zsp2_2              ! scalar product involving the adjoint routine
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d           ! 2D seed for the random number generator
+      INTEGER :: &
+         & ji, &
+         & jj, &
+         & jn, &
+         & jeos
+      CHARACTER(LEN=14) :: cl_name
+
+      ! Allocate memory
+
+      ALLOCATE( & 
+         & zdep(     jpi, jpj ),  &
+         & ztem(     jpi, jpj ),  &
+         & zsal(     jpi, jpj ),  &
+         & znt(      jpi, jpj ),  &
+         & zns(      jpi, jpj ),  &
+         & zt_adout( jpi, jpj ),  &  
+         & zs_adout( jpi, jpj ),  &
+         & zrd_adin( jpi, jpj ),  &
+         & zs_tlin(  jpi, jpj ),  &
+         & zt_tlin(  jpi, jpj ),  &
+         & zrd_tlout(jpi, jpj )    )
+
+      ! Initialize the reference state
+      ztem(:,:) = tn(:,:,2)
+      zsal(:,:) = sn(:,:,2)
+      zdep(:,:) = fsdept(:,:,2)
+
+      ! store initial nn_eos
+      jeos = nn_eos
+      DO jn = 0, 2
+         nn_eos = jn
+         !=============================================================
+         ! 1) dx = ( T ) and dy = ( T )
+         !=============================================================
+
+         !--------------------------------------------------------------------
+         ! Reset the tangent and adjoint variables
+         !--------------------------------------------------------------------
+         zt_tlin(:,:)     = 0.0_wp
+         zs_tlin(:,:)     = 0.0_wp
+         zrd_tlout(:,:)   = 0.0_wp
+         zt_adout(:,:)    = 0.0_wp
+         zs_adout(:,:)    = 0.0_wp
+         zrd_adin(:,:)    = 0.0_wp
+
+         !--------------------------------------------------------------------
+         ! Initialize the tangent input with random noise: dx
+         !--------------------------------------------------------------------
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 456953 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, znt, 'T', 0.0_wp, stdt )
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 456953 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zns, 'T', 0.0_wp, stds )
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zt_tlin(ji,jj) = znt(ji,jj)
+               zs_tlin(ji,jj) = zns(ji,jj)
+            END DO
+         END DO
+      
+         CALL eos_insitu_2d_tan(ztem, zsal, zdep, zt_tlin, zs_tlin, zrd_tlout)
+ 
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zrd_adin(ji,jj)   = zrd_tlout(ji,jj) &
+                    &                 * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,2)&
+                    &                 * tmask(ji,jj,2)
+            END DO
+         END DO
+      
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !--------------------------------------------------------------------
+
+         zsp1 = DOT_PRODUCT( zrd_tlout, zrd_adin )
+
+         !--------------------------------------------------------------------
+         ! Call the adjoint routine: dx^* = L^T dy^*
+         !--------------------------------------------------------------------
+
+         CALL eos_insitu_2d_adj(ztem, zsal, zdep, zt_adout, zs_adout, zrd_adin)
+
+         zsp2_1 = DOT_PRODUCT( zt_tlin, zt_adout )
+         zsp2_2 = DOT_PRODUCT( zs_tlin, zs_adout )
+         zsp2   = zsp2_1 + zsp2_2
+
+         ! Compare the scalar products
+
+         ! 14 char:'12345678901234'
+         SELECT CASE( jn )
+         CASE (0) ; cl_name = 'eos_adj 2d  T1'
+         CASE (1) ; cl_name = 'eos_adj 2d  T2'
+         CASE (2) ; cl_name = 'eos_adj 2d  T3'
+         END SELECT
+         CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      ENDDO
+
+      ! restore initial nn_eos
+      nn_eos = jeos
+      
+      ! Deallocate memory
+
+      DEALLOCATE(      &
+         & zdep,       &
+         & ztem,       &
+         & zsal,       &
+         & zt_adout,   &    
+         & zs_adout,   &
+         & zrd_adin,   &
+         & zt_tlin,    &
+         & zs_tlin,    &
+         & zrd_tlout,  &
+         & zns, znt    )
+            
+
+   END SUBROUTINE eos_insitu_2d_adj_tst
+   SUBROUTINE eos_pot_1pt_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE eos_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Separate tests are applied for the following dx and dy:
+      !!                
+      !!              1) dx = ( SSH ) and dy = ( SSH )
+      !!                   
+      !! History :
+      !!        ! 08-07 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      !! * Local declarations
+      REAL(KIND=wp) ::  &
+         & ztem,        &
+         & zsal,        &
+         & zt_tlin,     &
+         & zs_tlin,     &
+         & zrhop_tlout, &
+         & zt_adout,     &
+         & zs_adout,     &
+         & zrhop_adin
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2            ! scalar product involving the adjoint routine
+      CHARACTER(LEN=14) :: cl_name
+
+      INTEGER :: &
+         & jn, &
+         & jeos
+
+      ! Initialize the reference state
+      ztem = 23.7
+      zsal = 30.1
+      ! store initial nn_eos
+      jeos = nn_eos
+      DO jn = 0, 2
+         nn_eos = jn
+         !==================================================================
+         ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and 
+         !    dy = ( hdivb_tl, hdivn_tl )
+         !==================================================================
+
+         !--------------------------------------------------------------------
+         ! Reset the tangent and adjoint variables
+         !--------------------------------------------------------------------
+
+         zt_tlin     = 1.12_wp
+         zs_tlin     = 0.123_wp
+         zrhop_tlout = 0.0_wp
+         zt_adout    = 0.0_wp
+         zs_adout    = 0.0_wp
+         zrhop_adin  = 0.0_wp
+      
+         CALL eos_pot_1pt_tan( ztem, zsal, zt_tlin, zs_tlin, zrhop_tlout )
+
+         !--------------------------------------------------------------------
+         ! Initialize the adjoint variables: dy^* = W dy
+         !--------------------------------------------------------------------
+      
+         zrhop_adin = zrhop_tlout * e1t(1,1) * e2t(1,1) * fse3t(1,1,1)
+
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !--------------------------------------------------------------------
+
+         zsp1 = zrhop_adin * zrhop_tlout
+
+         CALL eos_pot_1pt_adj( ztem, zsal, zt_adout, zs_adout, zrhop_adin )
+         
+         zsp2 = zt_tlin * zt_adout + zs_tlin * zs_adout
+
+         ! 14 char:'12345678901234'
+         SELECT CASE( jn )
+         CASE (0) ; cl_name = 'eos_adj 1pt T1'
+         CASE (1) ; cl_name = 'eos_adj 1pt T2'
+         CASE (2) ; cl_name = 'eos_adj 1pt T3'
+         END SELECT
+         CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+      ENDDO
+      ! restore initial nn_eos
+      nn_eos = jeos
+
+   END SUBROUTINE eos_pot_1pt_adj_tst
+   SUBROUTINE eos_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE eos_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! History :
+      !!        ! 08-07 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      CALL eos_insitu_adj_tst( kumadt )
+
+      CALL eos_insitu_pot_adj_tst( kumadt )
+
+      CALL eos_insitu_2d_adj_tst( kumadt )
+
+      CALL eos_pot_1pt_adj_tst( kumadt )
+
+   END SUBROUTINE eos_adj_tst
+   SUBROUTINE bn2_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE bn2_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Separate tests are applied for the following dx and dy:
+      !!                
+      !!              1) dx = ( SSH ) and dy = ( SSH )
+      !!                   
+      !! History :
+      !!        ! 08-07 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         ztem,                   &  ! potential temperature
+         zsal                       ! salinity
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zt_adout,             &  ! potential temperature
+         & zs_adout                 ! salinity
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zrd_adin,               &  ! potential density (surface referenced)
+         & zrd_adout                  ! potential density (surface referenced)
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zt_tlin,              &  ! potential temperature
+         & zs_tlin,              &  ! salinity
+         & zt_tlout,             &  ! potential temperature
+         & zs_tlout                 ! salinity
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zrd_tlout                  ! potential density (surface referenced)
+      REAL(KIND=wp) ::       &
+         & zsp1,             & ! scalar product involving the tangent routine
+         & zsp2,             & ! scalar product involving the adjoint routine
+         & zsp2_1,           & ! scalar product involving the adjoint routine
+         & zsp2_2              ! scalar product involving the adjoint routine
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & znt,                 &  ! potential temperature
+         & zns                     ! salinity
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d           ! 2D seed for the random number generator
+      INTEGER :: &
+         & iseed, &
+         & ji, &
+         & jj, &
+         & jk, &
+         & jn, &
+         & jeos
+      CHARACTER(LEN=14) :: cl_name
+
+      ! Allocate memory
+      ALLOCATE( & 
+         & ztem(     jpi, jpj, jpk ),  &
+         & zsal(     jpi, jpj, jpk ),  &
+         & zt_adout( jpi, jpj, jpk ),  &  
+         & zs_adout( jpi, jpj, jpk ),  &
+         & zrd_adin( jpi, jpj, jpk ),  &
+         & zrd_adout(jpi, jpj, jpk ),  &
+         & zs_tlin(  jpi, jpj, jpk ),  &
+         & zt_tlin(  jpi, jpj, jpk ),  &
+         & zns(      jpi, jpj, jpk ),  &
+         & znt(      jpi, jpj, jpk ),  &
+         & zt_tlout( jpi, jpj, jpk ),  &
+         & zs_tlout( jpi, jpj, jpk ),  &
+         & zrd_tlout(jpi, jpj, jpk )    )
+
+      ! Initialize random field standard deviationsthe reference state
+      ztem = tn
+      zsal = sn
+      ! store initial nn_eos
+      jeos = nn_eos
+      DO jn = 0, 2
+         nn_eos = jn
+         !=============================================================
+         ! 1) dx = ( T ) and dy = ( T )
+         !=============================================================
+
+         !--------------------------------------------------------------------
+         ! Reset the tangent and adjoint variables
+         !--------------------------------------------------------------------
+         zt_tlin(:,:,:) = 0.0_wp
+         zs_tlin(:,:,:) = 0.0_wp
+         zt_tlout(:,:,:) = 0.0_wp
+         zs_tlout(:,:,:) = 0.0_wp
+         zrd_tlout(:,:,:) = 0.0_wp
+         zt_adout(:,:,:) = 0.0_wp
+         zs_adout(:,:,:) = 0.0_wp
+         zrd_adin(:,:,:) = 0.0_wp
+         zrd_adout(:,:,:) = 0.0_wp
+
+         !--------------------------------------------------------------------
+         ! Initialize the tangent input with random noise: dx
+         !--------------------------------------------------------------------
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 456953 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, znt, 'T', 0.0_wp, stdt )
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 456953 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zns, 'T', 0.0_wp, stds )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zt_tlin(ji,jj,jk) = znt(ji,jj,jk)
+                  zs_tlin(ji,jj,jk) = zns(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !--------------------------------------------------------------------
+         ! Call the tangent routine: dy = L dx
+         !--------------------------------------------------------------------
+         zt_tlout(:,:,:) = zt_tlin
+         zs_tlout(:,:,:) = zs_tlin
+         
+         CALL eos_bn2_tan( ztem, zsal, zt_tlout, zs_tlout, zrd_tlout ) 
+         !--------------------------------------------------------------------
+         ! Initialize the adjoint variables: dy^* = W dy
+         !--------------------------------------------------------------------
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zrd_adin(ji,jj,jk) = zrd_tlout(ji,jj,jk) &
+                       &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                       &               * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+             
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !--------------------------------------------------------------------
+
+         zsp1 = DOT_PRODUCT( zrd_tlout, zrd_adin )
+
+         !--------------------------------------------------------------------
+         ! Call the adjoint routine: dx^* = L^T dy^*
+         !--------------------------------------------------------------------
+
+         zrd_adout(:,:,:) = zrd_adin(:,:,:)
+
+         CALL eos_bn2_adj( ztem, zsal, zt_adout, zs_adout, zrd_adout ) 
+
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: dx^T L^T W dy
+         !--------------------------------------------------------------------
+       
+         zsp2_1 = DOT_PRODUCT( zt_tlin, zt_adout )
+         zsp2_2 = DOT_PRODUCT( zs_tlin, zs_adout )
+         zsp2 = zsp2_1 + zsp2_2  
+
+         ! Compare the scalar products
+         
+         ! 14 char:'12345678901234'
+         SELECT CASE( jn )
+         CASE (0) ; cl_name = 'bn2_adj     T1'
+         CASE (1) ; cl_name = 'bn2_adj     T2'
+         CASE (2) ; cl_name = 'bn2_adj     T3'
+         END SELECT
+         CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+      ENDDO
+      ! restore initial nn_eos
+      nn_eos = jeos
+
+      ! Deallocate memory
+
+      DEALLOCATE(      &
+         & ztem,       &
+         & zsal,       &
+         & zt_adout,   &    
+         & zs_adout,   &
+         & zrd_adin,   &
+         & zrd_adout,  &
+         & zt_tlin,    &
+         & zs_tlin,    &
+         & zt_tlout,   &
+         & zs_tlout,   &
+         & zrd_tlout,  &
+         & zns, znt    )
+
+
+   END SUBROUTINE bn2_adj_tst
+#if defined key_tst_tlm
+   SUBROUTINE eos_insitu_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE eos_insitu_tlm_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 :
+      !!        ! 09-08 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE eosbn2,     ONLY: & ! horizontal & vertical advective trend
+        & eos
+      USE tamtrj              ! writing out state trajectory
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE gridrandom, ONLY: &
+        & grid_rd_sd
+      USE trj_tam
+      USE oce       , ONLY: & ! ocean dynamics and tracers variables
+        & tn, sn, rhd, rhop
+      USE in_out_manager, ONLY: & ! I/O manager 
+        & nitend,              & 
+        & nit000
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zrd_out,          &  ! 
+         & zt_tlin  ,        &  !
+         & zs_tlin  ,        &
+         & zrd_tl   ,        &    
+         & zrd_wop,          &
+         & z3r
+      REAL(KIND=wp) ::       &
+         & zsp1,             & 
+         & zsp2,             & 
+         & zsp3,             & 
+         & zzsp,             &
+         & gamma,            &
+         & zgsp1,            &
+         & zgsp2,            &
+         & zgsp3,            &
+         & zgsp4,            &
+         & zgsp5,            &
+         & zgsp6,            &
+         & zgsp7     
+      INTEGER :: &
+         & ji, &
+         & jj, &
+         & jk
+      CHARACTER(LEN=14)   :: cl_name
+      CHARACTER (LEN=128) :: file_out_sc, file_wop, file_out, file_xdx
+      CHARACTER (LEN=90)  :: FMT
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zscrd, zscerrrd
+      INTEGER, DIMENSION(100)::       &
+         & iiposrd, ijposrd, ikposrd
+      INTEGER::                         &
+         & ii, numsctlm,                &
+         & numtlm,                      &
+         & isamp=40,jsamp=40, ksamp=10
+     REAL(KIND=wp), DIMENSION(jpi,jpj,jpk) :: &
+         & zerrrd
+      ALLOCATE( & 
+         & zrd_out(   jpi, jpj, jpk ),  &
+         & zrd_tl(    jpi, jpj, jpk ),  &
+         & zs_tlin(   jpi, jpj, jpk ),  &
+         & zt_tlin(   jpi, jpj, jpk ),  &
+         & zrd_wop(   jpi, jpj, jpk ),  &
+         & z3r    (   jpi, jpj, jpk )    )
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      zt_tlin(  :,:,:)   = 0.0_wp
+      zs_tlin(  :,:,:)   = 0.0_wp
+      zrd_out(  :,:,:)   = 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)
+      !--------------------------------------------------------------------
+!      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
+      !--------------------------------------------------------------------
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         CALL grid_rd_sd( 596035, z3r, 'T', 0.0_wp, stdt)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zt_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 371836, z3r, 'S', 0.0_wp, stds)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zs_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      ENDIF 
+
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      IF ( tlm_bch /= 2 )  CALL istate_p  
+
+      ! *** initialize the reference trajectory
+      ! ------------
+      CALL  trj_rea( nit000-1, 1 )
+      CALL  trj_rea( nit000, 1 )
+
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         zt_tlin(:,:,:) = gamma * zt_tlin(:,:,:)
+         tn(:,:,:)       = tn(:,:,:) + zt_tlin(:,:,:)
+
+         zs_tlin(:,:,:) = gamma * zs_tlin(:,:,:)
+         sn(:,:,:)       = sn(:,:,:) + zs_tlin(:,:,:)
+      ENDIF 
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------      
+      IF ( tlm_bch /= 2 )  CALL eos(tn, sn, zrd_out)
+      rhd(:,:,:)= zrd_out(:,:,:)
+      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  
+         !--------------------------------------------------------------------
+         CALL  trj_rea( nit000-1, 1 ) 
+         CALL  trj_rea( nit000, 1 ) 
+         !-----------------------------------------------------------------------
+         !  Initialization of the dynamics and tracer fields for the tangent
+         !----------------------------------------------------------------------- 
+         CALL eos_insitu_tan(tn, sn, zt_tlin, zs_tlin, zrd_tl)
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L(t0,tn) gamma dx0 ) )
+         !--------------------------------------------------------------------
+         zsp2    = DOT_PRODUCT( zrd_tl, zrd_tl  )
+         !--------------------------------------------------------------------
+         !  Storing data
+         !--------------------------------------------------------------------
+         CALL trj_rd_spl(file_wop) 
+         zrd_wop  (:,:,:) = rhd  (:,:,:)
+         CALL trj_rd_spl(file_xdx) 
+         zrd_out  (:,:,:) = rhd  (:,:,:)
+         !--------------------------------------------------------------------
+         ! 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 jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zrd_out   (ji,jj,jk) = zrd_out    (ji,jj,jk) - zrd_wop  (ji,jj,jk)
+                  zrd_wop   (ji,jj,jk) = zrd_out    (ji,jj,jk) - zrd_tl    (ji,jj,jk)
+                  IF (  zrd_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrrd(ji,jj,jk) = zrd_out(ji,jj,jk)/zrd_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposrd(ii) = ji
+                      ijposrd(ii) = jj
+                      ikposrd(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+                         zscrd (ii) =  zrd_wop(ji,jj,jk)
+                         zscerrrd (ii) =  ( zerrrd(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+
+         zsp1    = DOT_PRODUCT( zrd_out, zrd_out  )
+         zsp3    = DOT_PRODUCT( zrd_wop, zrd_wop  )
+
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name = 'eos_insitu:En '
+         zzsp    = SQRT(zsp3)
+         zgsp5   = zzsp
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp    = SQRT(zsp2)
+         zgsp4   = zzsp
+         cl_name = 'eos_insitu:Ln2'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         zzsp    = SQRT(zsp1)
+         cl_name = 'eosins:Mhdx-Mx'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         zgsp3   = SQRT( zsp3/zsp2 )
+         zgsp7   = zgsp3/gamma
+         zgsp1   = zzsp
+         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) 'eosinsit', 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 =  'eosinsit'
+         IF(lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zscrd(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscrd   ', &
+                    & cur_loop, h_ratio, iiposrd(ii), ijposrd(ii), ikposrd(ii), zscrd(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrrd(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrrd', &
+                    & cur_loop, h_ratio, iiposrd(ii), ijposrd(ii),  ikposrd(ii), zscerrrd(ii)
+            ENDDO
+            ! write separator
+            WRITE(numtan_sc,"(A4)") '===='
+         ENDIF
+
+      ENDIF
+
+      DEALLOCATE(                       &
+         & zrd_out, zrd_tl, zrd_wop,    & 
+         & zt_tlin, zs_tlin, z3r        &    
+         & )
+   END SUBROUTINE eos_insitu_tlm_tst
+
+   SUBROUTINE eos_insitu_pot_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE eos_insitu_pot_tlm_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 :
+      !!        ! 09-08 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE eosbn2,     ONLY: & ! horizontal & vertical advective trend
+        & eos
+      USE tamtrj              ! writing out state trajectory
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE gridrandom, ONLY: &
+        & grid_rd_sd
+      USE trj_tam
+      USE oce       , ONLY: & ! ocean dynamics and tracers variables
+        & tn, sn, rhd, rhop
+      USE in_out_manager, ONLY: & ! I/O manager 
+        & nitend,              & 
+        & nit000
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & zrd_out,          &  ! 
+         & zrh_out,          &
+         & zt_tlin  ,        &  !
+         & zs_tlin  ,        &
+         & zrh_tl   ,        &
+         & zrd_tl   ,        &    
+         & zrd_wop  ,        &
+         & zrh_wop  ,        &
+         & z3r
+      REAL(KIND=wp) ::       &
+         & zsp1,             & 
+         & zsp2,             & 
+         & zsp3,             &
+         & zsp1_Rd, Zsp1_Rh, &
+         & zsp2_Rd, zsp2_Rh, &
+         & zsp3_Rd, zsp3_Rh, & 
+         & zzsp,             &
+         & gamma,            &
+         & zgsp1,            &
+         & zgsp2,            &
+         & zgsp3,            &
+         & zgsp4,            &
+         & zgsp5,            &
+         & zgsp6,            &
+         & zgsp7            
+      INTEGER :: &
+         & ji, &
+         & jj, &
+         & jk
+      CHARACTER(LEN=14)   :: cl_name
+      CHARACTER (LEN=128) :: file_out, file_wop,file_xdx
+      CHARACTER (LEN=90)  :: FMT
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zscrd, zscerrrd,           &
+         & zscrh, zscerrrh
+      INTEGER, DIMENSION(100)::       &
+         & iiposrd, ijposrd, ikposrd, &
+         & iiposrh, ijposrh, ikposrh
+      INTEGER::                         &
+         & ii, numsctlm,                &
+         & isamp=40,jsamp=40, ksamp=10
+     REAL(KIND=wp), DIMENSION(jpi,jpj,jpk) :: &
+         & zerrrd, zerrrh
+      ALLOCATE( & 
+         & zrd_out( jpi, jpj, jpk ),  &
+         & zrh_out( jpi, jpj, jpk ),  &
+         & zrd_tl(  jpi, jpj, jpk ),  &
+         & zrh_tl(  jpi, jpj, jpk ),  &  
+         & zs_tlin( jpi, jpj, jpk ),  &
+         & zt_tlin( jpi, jpj, jpk ),  &
+         & zrd_wop( jpi, jpj, jpk ),  &
+         & zrh_wop( jpi, jpj, jpk ),  &
+         & z3r    ( jpi, jpj, jpk )  )
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      zt_tlin(  :,:,:)   = 0.0_wp
+      zs_tlin(  :,:,:)   = 0.0_wp
+      zrd_out(  :,:,:)   = 0.0_wp
+      zrh_out(  :,:,:)   = 0.0_wp 
+      zrd_wop(  :,:,:)   = 0.0_wp
+      zrh_wop(  :,:,:)   = 0.0_wp
+      zscerrrd( :)       = 0.0_wp
+      zscerrrh( :)       = 0.0_wp
+      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)
+      !--------------------------------------------------------------------
+!!      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
+      !--------------------------------------------------------------------
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         CALL grid_rd_sd( 596035, z3r, 'T', 0.0_wp, stdt)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zt_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 371836, z3r, 'S', 0.0_wp, stds)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zs_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      ENDIF 
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      IF ( tlm_bch /= 2 )  CALL istate_p  
+
+      ! *** initialize the reference trajectory
+      ! ------------
+      CALL  trj_rea( nit000-1, 1 )
+      CALL  trj_rea( nit000, 1 )
+
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         zt_tlin(:,:,:) = gamma * zt_tlin(:,:,:)
+         tn(:,:,:)       = tn(:,:,:) + zt_tlin(:,:,:)
+
+         zs_tlin(:,:,:) = gamma * zs_tlin(:,:,:)
+         sn(:,:,:)       = sn(:,:,:) + zs_tlin(:,:,:)
+      ENDIF 
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------      
+      IF ( tlm_bch /= 2 )      CALL eos(tn, sn, zrd_out, zrh_out)
+      rhd (:,:,:) = zrd_out(:,:,:)
+      rhop(:,:,:) = zrh_out(:,:,:)
+      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  
+         !--------------------------------------------------------------------
+         CALL  trj_rea( nit000-1, 1 ) 
+         CALL  trj_rea( nit000, 1 ) 
+         !-----------------------------------------------------------------------
+         !  Initialization of the dynamics and tracer fields for the tangent
+         !----------------------------------------------------------------------- 
+         CALL eos_insitu_pot_tan(tn, sn, zt_tlin, zs_tlin, zrd_tl, zrh_tl)
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L(t0,tn) gamma dx0 ) )
+         !--------------------------------------------------------------------
+
+         zsp2_Rd  = DOT_PRODUCT( zrd_tl, zrd_tl  )
+         zsp2_Rh  = DOT_PRODUCT( zrh_tl, zrh_tl  )
+         zsp2     = zsp2_Rd + zsp2_Rh
+         !--------------------------------------------------------------------
+         !  Storing data
+         !--------------------------------------------------------------------
+         CALL trj_rd_spl(file_wop) 
+         zrd_wop  (:,:,:) = rhd  (:,:,:)
+         zrh_wop  (:,:,:) = rhop (:,:,:)
+         CALL trj_rd_spl(file_xdx) 
+         zrd_out  (:,:,:) = rhd  (:,:,:)
+         zrh_out  (:,:,:) = rhop (:,:,:)
+         !--------------------------------------------------------------------
+         ! 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 jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zrd_out   (ji,jj,jk) = zrd_out    (ji,jj,jk) - zrd_wop  (ji,jj,jk)
+                  zrd_wop   (ji,jj,jk) = zrd_out    (ji,jj,jk) - zrd_tl    (ji,jj,jk)
+                  IF (  zrd_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrrd(ji,jj,jk) = zrd_out(ji,jj,jk)/zrd_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposrd(ii) = ji
+                      ijposrd(ii) = jj
+                      ikposrd(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+                         zscrd (ii)    =  zrd_wop(ji,jj,jk)
+                         zscerrrd (ii) =  ( zerrrd( ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         ii=0
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zrh_out   (ji,jj,jk) = zrh_out    (ji,jj,jk) - zrh_wop  (ji,jj,jk)
+                  zrh_wop   (ji,jj,jk) = zrh_out    (ji,jj,jk) - zrh_tl    (ji,jj,jk)
+                  IF (  zrh_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrrh(ji,jj,jk) = zrh_out(ji,jj,jk)/zrh_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposrh(ii) = ji
+                      ijposrh(ii) = jj
+                      ikposrh(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+                         zscrh (ii)    =  zrh_wop(ji,jj,jk)
+                         zscerrrh (ii) =  ( zerrrh( ji,jj,jk) - 1.0_wp ) /gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         zsp1_Rd = DOT_PRODUCT( zrd_out, zrd_out  )
+         zsp1_Rh = DOT_PRODUCT( zrh_out, zrh_out  )
+         zsp1    = zsp1_Rd + zsp1_Rh
+
+         zsp3_Rd = DOT_PRODUCT( zrd_wop, zrd_wop  )
+         zsp3_Rh = DOT_PRODUCT( zrh_wop, zrh_wop  )
+         zsp3    = zsp3_Rd + zsp3_Rh
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name = 'eos_pot:En '
+         zzsp    = SQRT(zsp3)
+         zgsp5   = zzsp
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp    = SQRT(zsp2)
+         zgsp4   = zzsp
+         cl_name = 'eos_pot:Ln2'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         zzsp    = SQRT(zsp1)
+         cl_name = 'eospot:Mhdx-Mx'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         zgsp3   = SQRT( zsp3/zsp2 )
+         zgsp7   = zgsp3/gamma
+         zgsp1   = zzsp
+         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) 'eosinsp ', 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 = 'eosinsp '
+         IF(lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zscrd(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscrd   ', &
+                    & cur_loop, h_ratio, iiposrd(ii), ijposrd(ii), ikposrd(ii), zscrd(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscrh(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscrh   ', &
+                   & cur_loop, h_ratio, iiposrh(ii), ijposrh(ii), ikposrh(ii), zscrh(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrrd(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrrd', &
+                    & cur_loop, h_ratio, iiposrd(ii), ijposrd(ii), ikposrd(ii), zscerrrd(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrrh(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrrh', &
+                   & cur_loop, h_ratio, iiposrh(ii), ijposrh(ii), ikposrh(ii), zscerrrh(ii)
+            ENDDO
+            ! write separator
+            WRITE(numtan_sc,"(A4)") '===='
+         ENDIF
+      ENDIF
+
+      DEALLOCATE(                       &
+         & zrd_out, zrd_tl, zrd_wop,    & 
+         & zrh_out, zrh_tl, zrh_wop,    &
+         & zt_tlin, zs_tlin, z3r        &    
+         & )
+   END SUBROUTINE eos_insitu_pot_tlm_tst
+
+   SUBROUTINE eos_insitu_2d_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE eos_insitu_2d_tlm_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 :
+      !!        ! 09-08 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE eosbn2,     ONLY: & ! horizontal & vertical advective trend
+        & eos
+      USE tamtrj              ! writing out state trajectory
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE gridrandom, ONLY: &
+        & grid_rd_sd
+      USE trj_tam
+      USE oce       , ONLY: & ! ocean dynamics and tracers variables
+        & tn, sn, rhd, rhop
+      USE in_out_manager, ONLY: & ! I/O manager 
+        & nitend,              & 
+        & nit000
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   &
+         & zdep,             &  ! depth
+         & ztem,             &  ! potential temperature
+         & zsal                 ! salinity
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   &
+         & zrd_out,          &  ! 
+         & zt_tlin  ,        &  !
+         & zs_tlin  ,        &
+         & zrd_tl   ,        &    
+         & zrd_wop  ,        &
+         & z2r
+      REAL(KIND=wp) ::       &
+         & zsp1,             & 
+         & zsp2,             & 
+         & zsp3,             & 
+         & zzsp,             &
+         & gamma,            &
+         & zgsp1,            &
+         & zgsp2,            &
+         & zgsp3,            &
+         & zgsp4,            &
+         & zgsp5,            &
+         & zgsp6,            &
+         & zgsp7            
+      INTEGER :: &
+         & ji, &
+         & jj
+      CHARACTER(LEN=14)   :: cl_name
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
+      CHARACTER (LEN=90)  :: FMT
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zscrd, zscerrrd
+      INTEGER, DIMENSION(100)::       &
+         & iiposrd, ijposrd
+      INTEGER::                         &
+         & ii, numsctlm,                &
+         & isamp=40,jsamp=40
+     REAL(KIND=wp), DIMENSION(jpi,jpj) :: &
+         & zerrrd
+      ALLOCATE( & 
+         & ztem   ( jpi, jpj ),  &
+         & zsal   ( jpi, jpj ),  &
+         & zdep   ( jpi, jpj ),  &
+         & zrd_out( jpi, jpj ),  &
+         & zrd_tl(  jpi, jpj ),  &  
+         & zs_tlin( jpi, jpj ),  &
+         & zt_tlin( jpi, jpj ),  &
+         & zrd_wop( jpi, jpj ),  &
+         & z2r    ( jpi, jpj )   )
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      ztem   (  :,:)   = 0.0_wp
+      zsal   (  :,:)   = 0.0_wp
+      zt_tlin(  :,:)   = 0.0_wp
+      zs_tlin(  :,:)   = 0.0_wp
+      zrd_out(  :,:)   = 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)
+      !--------------------------------------------------------------------
+!!      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
+      !--------------------------------------------------------------------
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         CALL grid_rd_sd( 596035, z2r, 'T', 0.0_wp, stdt)
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zt_tlin(ji,jj) = z2r(ji,jj)
+            END DO
+         END DO
+         CALL grid_rd_sd( 371836, z2r, 'S', 0.0_wp, stds)
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zs_tlin(ji,jj) = z2r(ji,jj)
+            END DO
+         END DO
+      ENDIF 
+
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      IF ( tlm_bch /= 2 ) CALL istate_p  
+      ! *** initialize the reference trajectory
+      ! ------------
+      CALL  trj_rea( nit000-1, 1 )
+      CALL  trj_rea( nit000, 1 )
+      ! Initialize the reference state
+      ztem(:,:) = tn(:,:,2)
+      zsal(:,:) = sn(:,:,2)
+      zdep(:,:) = fsdept(:,:,2)
+
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         zt_tlin(:,:) = gamma * zt_tlin(:,:)
+         ztem(:,:)    = ztem(:,:) + zt_tlin(:,:)
+
+         zs_tlin(:,:) = gamma * zs_tlin(:,:)
+         zsal(:,:)    = zsal(:,:) + zs_tlin(:,:)
+      ENDIF 
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------    
+      IF ( tlm_bch /= 2 ) CALL eos(ztem, zsal, zdep, zrd_out)
+      rhd (:,:,2) = zrd_out(:,:)
+      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  
+         !--------------------------------------------------------------------
+         CALL  trj_rea( nit000-1, 1 ) 
+         CALL  trj_rea( nit000, 1 ) 
+         ztem(:,:) = tn(:,:,2)
+         zsal(:,:) = sn(:,:,2)
+         !-----------------------------------------------------------------------
+         !  Initialization of the dynamics and tracer fields for the tangent
+         !----------------------------------------------------------------------- 
+         CALL eos_insitu_2d_tan(ztem, zsal,  zdep, zt_tlin, zs_tlin, zrd_tl)
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L(t0,tn) gamma dx0 ) )
+         !--------------------------------------------------------------------
+         zsp2     = DOT_PRODUCT( zrd_tl, zrd_tl  )
+         !--------------------------------------------------------------------
+         !  Storing data
+         !--------------------------------------------------------------------
+         CALL trj_rd_spl(file_wop) 
+         zrd_wop  (:,:) = rhd  (:,:,2)
+         CALL trj_rd_spl(file_xdx) 
+         zrd_out  (:,:) = rhd  (:,:,2)
+         !--------------------------------------------------------------------
+         ! 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
+               zrd_out   (ji,jj) = zrd_out    (ji,jj) - zrd_wop  (ji,jj)
+               zrd_wop   (ji,jj) = zrd_out    (ji,jj) - zrd_tl    (ji,jj)
+               IF (  zrd_tl(ji,jj) .NE. 0.0_wp ) &
+                  & zerrrd(ji,jj) = zrd_out(ji,jj)/zrd_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0)  ) THEN
+                   ii = ii+1
+                   iiposrd(ii) = ji
+                   ijposrd(ii) = jj
+                   IF ( INT(tmask(ji,jj,2)) .NE. 0)  THEN
+                      zscrd (ii)    =  zrd_wop(ji,jj)
+                      zscerrrd (ii) =  ( zerrrd( ji,jj) - 1.0_wp ) / gamma
+                   ENDIF
+               ENDIF
+            END DO
+         END DO
+
+         zsp1    = DOT_PRODUCT( zrd_out, zrd_out  )
+
+         zsp3    = DOT_PRODUCT( zrd_wop, zrd_wop  )
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name = 'eos_2d:En '
+         zzsp    = SQRT(zsp3)
+         zgsp5   = zzsp
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp    = SQRT(zsp2)
+         zgsp4   = zzsp
+         cl_name = 'eos_2d:Ln2'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         zzsp    = SQRT(zsp1)
+         cl_name = 'eos_2d:Mhdx-Mx'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         zgsp3   = SQRT( zsp3/zsp2 )
+         zgsp7   = zgsp3/gamma
+         zgsp1   = zzsp
+         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) 'eosins2d', 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 = 'eosins2d'
+         IF(lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zscrd(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscrd   ', &
+                    & cur_loop, h_ratio, ii, iiposrd(ii), ijposrd(ii), zscrd(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrrd(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrrd', &
+                    & cur_loop, h_ratio, ii, iiposrd(ii), ijposrd(ii), zscerrrd(ii)
+            ENDDO
+            ! write separator
+            WRITE(numtan_sc,"(A4)") '===='
+         ENDIF
+
+      ENDIF
+
+      DEALLOCATE(                       &
+         & zrd_out, zrd_tl, zrd_wop,    & 
+         & ztem, zsal, zdep,            &
+         & zt_tlin, zs_tlin, z2r        &    
+         & )
+   END SUBROUTINE eos_insitu_2d_tlm_tst
+
+   SUBROUTINE eos_pot_1pt_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE eos_pot_1pt_tlm_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 :
+      !!        ! 09-08 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE eosbn2,     ONLY: & ! horizontal & vertical advective trend
+        & eos
+      USE tamtrj              ! writing out state trajectory
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE trj_tam
+      USE oce       , ONLY: & ! ocean dynamics and tracers variables
+        & tn, sn, rhd, rhop
+      USE in_out_manager, ONLY: & ! I/O manager 
+        & nitend,              & 
+        & nit000
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt                 ! Output unit
+      INTEGER::         &
+         & numsctlm      
+      !! * Local declarations
+      REAL(KIND=wp) ::  &
+         & ztem,        &
+         & zsal,        &
+         & zt_tlin,     &
+         & zs_tlin,     &
+         & zrh_out,     &
+         & zrh_tl,      &
+         & zrh_wop
+      REAL(KIND=wp) ::  &
+         & zsp1, zsp2,  & 
+         & zsp3, zzsp,  &
+         & gamma,            &
+         & zgsp1,            &
+         & zgsp2,            &
+         & zgsp3,            &
+         & zgsp4,            &
+         & zgsp5,            &
+         & zgsp6,            &
+         & zgsp7                   
+      CHARACTER(LEN=14) :: cl_name
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
+      CHARACTER (LEN=90)  :: FMT
+      ! Initialize the reference state
+      ztem = 23.7
+      zsal = 30.1
+
+      !--------------------------------------------------------------------
+      ! Reset the tangentvariables
+      !--------------------------------------------------------------------
+      zt_tlin   = 1.12_wp
+      zs_tlin   = 0.123_wp
+      zrh_out   = 0.0_wp
+      zrh_wop   = 0.0_wp
+      IF ( tlm_bch == 2 )    zrh_tl    = 0.0_wp  
+      !--------------------------------------------------------------------
+      ! Output filename Xn=F(X0)
+      !--------------------------------------------------------------------
+!!      CALL tlm_namrd
+      gamma = h_ratio
+      file_wop='trj_wop_eos_1pt'
+      file_xdx='trj_xdx_eos_1pt'
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      IF ( tlm_bch /= 2 ) CALL istate_p  
+
+      ! *** initialize the reference trajectory
+      ! ------------
+      CALL  trj_rea( nit000-1, 1 )
+      CALL  trj_rea( nit000, 1 )
+
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         zt_tlin = gamma * zt_tlin
+         ztem    = ztem + zt_tlin
+
+         zs_tlin = gamma * zs_tlin
+         zsal    = zsal + zs_tlin
+      ENDIF 
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------      
+      IF ( tlm_bch /= 2 ) CALL eos(ztem, zsal, zrh_out)
+      rhop (1,1,1) = zrh_out
+      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  
+         !--------------------------------------------------------------------
+         CALL  trj_rea( nit000-1, 1 ) 
+         CALL  trj_rea( nit000, 1 )
+         ztem = 23.7
+         zsal = 30.1   
+         !-----------------------------------------------------------------------
+         !  Initialization of the dynamics and tracer fields for the tangent
+         !----------------------------------------------------------------------- 
+         CALL eos_pot_1pt_tan(ztem, zsal, zt_tlin, zs_tlin, zrh_tl)
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L(t0,tn) gamma dx0 ) )
+         !--------------------------------------------------------------------
+         zsp2     = abs(zrh_tl)
+         !--------------------------------------------------------------------
+         !  Storing data
+         !--------------------------------------------------------------------
+         CALL trj_rd_spl(file_wop) 
+         zrh_wop   = rhop  (1,1,1)
+         CALL trj_rd_spl(file_xdx) 
+         zrh_out   = rhop  (1,1,1)
+         !--------------------------------------------------------------------
+         ! 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
+         zrh_out   = zrh_out  - zrh_wop  
+         zrh_wop   = zrh_out  - zrh_tl
+
+         zsp1    = abs(zrh_out)
+         zsp3    = abs(zrh_wop)
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name = 'eos_1pt:En '
+         zzsp    = zsp3
+         zgsp5   = zzsp
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp    = zsp2
+         zgsp4   = zzsp
+         cl_name = 'eos_1pt:Ln2'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         zzsp    = zsp1
+         cl_name = 'eos_1pt:Mhdx-Mx'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         zgsp3 = SQRT( zsp3/zsp2 )
+         zgsp7 = zgsp3/gamma
+         zgsp1 = zzsp
+         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) 'eos1pt  ', cur_loop, h_ratio, zgsp1, zgsp2, zgsp3, zgsp4, zgsp5, zgsp6, zgsp7
+      ENDIF
+
+   END SUBROUTINE eos_pot_1pt_tlm_tst
+
+   SUBROUTINE bn2_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE bn2_tlm_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 :
+      !!        ! 09-12 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE eosbn2,     ONLY: & ! horizontal & vertical advective trend
+        & bn2
+      USE tamtrj              ! writing out state trajectory
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE sshwzv             !  vertical velocity
+      USE gridrandom, ONLY: &
+        & grid_rd_sd
+      USE trj_tam
+      USE oce           , ONLY: & ! ocean dynamics and tracers variables
+        & tn, sn, rn2
+      USE oce_tam       , ONLY: &
+        & tn_tl,             &
+        & sn_tl,             &
+        & rn2_tl
+      USE in_out_manager, ONLY: & ! I/O manager               & 
+        & nit000
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2,         & ! scalar product involving the tangent routine
+         & zsp3,         & ! scalar product involving the tangent routine
+         & zzsp,         & ! scalar product involving the tangent routine
+         & gamma,            &
+         & zgsp1,            &
+         & zgsp2,            &
+         & zgsp3,            &
+         & zgsp4,            &
+         & zgsp5,            &
+         & zgsp6,            &
+         & zgsp7
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   &
+         & ztn_tlin,              &  ! potential temperature
+         & zsn_tlin,              &  ! salinity
+         & zrn2_out,              &  ! Brunt-Vaisala frequency [s-1] Direct output
+         & zrn2_wop,              &  ! Brunt-Vaisala frequency [s-1] Direct output w/o perturbation
+         & z3r                
+      CHARACTER(LEN=14)   :: cl_name
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
+      CHARACTER (LEN=90)  :: FMT
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zscrn2,          &
+         & zscerrrn2
+      INTEGER, DIMENSION(100)::                    &
+         & iiposrn2,ijposrn2, ikposrn2
+      INTEGER::             &
+         & ii,              &
+         & isamp=40,        &
+         & jsamp=40,        &
+         & ksamp=10,        &
+         & numsctlm
+     REAL(KIND=wp), DIMENSION(jpi,jpj,jpk) :: &
+         & zerrrn2
+
+      ! Allocate memory
+      ALLOCATE( & 
+         & zsn_tlin(  jpi, jpj, jpk ),  &
+         & ztn_tlin(  jpi, jpj, jpk ),  &
+         & zrn2_out(  jpi, jpj, jpk ),  &
+         & zrn2_wop(  jpi, jpj, jpk ),  &
+         & z3r(       jpi, jpj, jpk )    )
+
+
+      !--------------------------------------------------------------------
+      ! Output filename Xn=F(X0)
+      !--------------------------------------------------------------------
+!!      CALL tlm_namrd
+      gamma = h_ratio    
+      file_wop='trj_wop_bn2'
+      file_xdx='trj_xdx_bn2'  
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         CALL grid_rd_sd( 264940, z3r,  'T', 0.0_wp, stdt)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  ztn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 618304, z3r,  'T', 0.0_wp, stds) 
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      ENDIF  
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      IF ( tlm_bch /= 2 ) CALL istate_p  
+
+      ! *** initialize the reference trajectory
+      ! ------------
+      CALL  trj_rea( nit000-1, 1 )
+
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+
+         ztn_tlin(:,:,:) = gamma * ztn_tlin(:,:,:)
+         tn(:,:,:)       = tn(:,:,:) + ztn_tlin(:,:,:)
+
+         zsn_tlin(:,:,:) = gamma * zsn_tlin(:,:,:)
+         sn(:,:,:)       = sn(:,:,:) + zsn_tlin(:,:,:)
+
+      ENDIF 
+
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------
+      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 ( tlm_bch == 2 ) THEN
+         !--------------------------------------------------------------------
+         ! Initialize the tangent variables: dy^* = W dy  
+         !--------------------------------------------------------------------
+         CALL  trj_rea( nit000-1, 1 )  
+         tn_tl  (:,:,:) = ztn_tlin  (:,:,:)
+         sn_tl  (:,:,:) = zsn_tlin  (:,:,:)
+
+         !-----------------------------------------------------------------------
+         !  Initialization of the dynamics and tracer fields for the tangent
+         !----------------------------------------------------------------------- 
+         CALL bn2_tan(tn, sn, ztn_tlin, zsn_tlin, rn2_tl)
+
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L(t0,tn) gamma dx0 ) )
+         !--------------------------------------------------------------------
+         zsp2       = DOT_PRODUCT( rn2_tl, rn2_tl  )
+
+         !--------------------------------------------------------------------
+         !  Storing data
+         !--------------------------------------------------------------------
+         CALL trj_rd_spl(file_wop) 
+         zrn2_wop  (:,:,:) = rn2  (:,:,:)
+         CALL trj_rd_spl(file_xdx) 
+         zrn2_out  (:,:,:) = rn2  (:,:,:)
+         !--------------------------------------------------------------------
+         ! 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 jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zrn2_out   (ji,jj,jk) = zrn2_out    (ji,jj,jk) - zrn2_wop  (ji,jj,jk)
+                  zrn2_wop   (ji,jj,jk) = zrn2_out    (ji,jj,jk) - rn2_tl    (ji,jj,jk)
+                  IF (  rn2_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrrn2(ji,jj,jk) = zrn2_out(ji,jj,jk)/rn2_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposrn2(ii) = ji
+                      ijposrn2(ii) = jj
+                      ikposrn2(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+                         zscrn2 (ii) =  zrn2_wop(ji,jj,jk)
+                         zscerrrn2 (ii) =  ( zerrrn2(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+
+         zsp1      = DOT_PRODUCT( zrn2_out, zrn2_out  )
+
+         zsp3      = DOT_PRODUCT( zrn2_wop, zrn2_wop  )
+
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name = 'eosbn2_tam:En '
+         zzsp    = SQRT(zsp3)
+         zgsp5   = zzsp
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp    = SQRT(zsp2)
+         zgsp4   = zzsp
+         cl_name = 'eosbn2_tam:Ln2'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         zzsp    = SQRT(zsp1)
+         cl_name = 'traadv:Mhdx-Mx'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         zgsp3 = SQRT( zsp3/zsp2 )
+         zgsp7 = zgsp3/gamma
+         zgsp1 = zzsp
+         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) 'eosbn2  ', 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 = 'eosbn2  '
+         IF(lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zscrn2(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscrn2    ', &
+                    & cur_loop, h_ratio, ii, iiposrn2(ii), ijposrn2(ii), zscrn2(ii)
+            ENDDO
+            ! write separator
+            WRITE(numtan_sc,"(A4)") '===='
+         ENDIF
+
+      ENDIF
+
+      DEALLOCATE(                           &
+         & ztn_tlin, zsn_tlin,              &
+         & zrn2_out, zrn2_wop,              & 
+         & z3r                              &
+         & )
+
+   END SUBROUTINE bn2_tlm_tst
+
+   SUBROUTINE eos_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE eos_tlm_tst ***
+      !!
+      !! ** Purpose : Test the tangent routine.
+      !!
+      !! History :
+      !!        ! 09-08 (F. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      CALL eos_insitu_tlm_tst( kumadt )
+      CALL eos_insitu_pot_tlm_tst( kumadt )
+      CALL eos_insitu_2d_tlm_tst( kumadt )
+      CALL eos_pot_1pt_tlm_tst( kumadt )
+
+   END SUBROUTINE eos_tlm_tst
+#endif
+#endif
+   !!======================================================================
+END MODULE eosbn2_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traadv_cen2_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traadv_cen2_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traadv_cen2_tam.F90	(revision 2578)
@@ -0,0 +1,1288 @@
+MODULE traadv_cen2_tam
+#if defined key_tam
+   !!======================================================================
+   !!                     ***  MODULE  traadv_cen2_tam  ***
+   !! Ocean active tracers:  horizontal & vertical advective trend
+   !!                         Tangent and Adjoint module
+   !!======================================================================
+   !! History :  8.2  ! 2001-08  (G. Madec, E. Durand)  trahad+trazad=traadv 
+   !!            1.0  ! 2002-06  (G. Madec)  F90: Free form and module
+   !!            9.0  ! 2004-08  (C. Talandier) New trends organization
+   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
+   !!            2.0  ! 2006-04  (R. Benshila, G. Madec) Step reorganization
+   !!             -   ! 2006-07  (G. madec)  add ups_orca_set routine
+   !!            3.2  ! 2009-07  (G. Madec) add avmb, avtb in restart for cen2 advection
+   !! History of the T&A module
+   !!            9.0  ! 2008-12  (A. Vidard) original version
+   !!            3.2  ! 2010-04  (F. Vigilant) 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_adv_cen2 : update the tracer trend with the horizontal and
+   !!                  vertical advection trends using a seconder order
+   !!   ups_orca_set : allow mixed upstream/centered scheme in specific
+   !!                  area (set for orca 2 and 4 only)
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1,               &
+      & jpiglo,              &
+      & jp_cfg
+   USE oce           , ONLY: & ! ocean dynamics and active tracers
+      & un,                  &
+      & vn,                  &
+      & tb,                  &
+      & sb,                  &
+      & wn,                  &
+      & tn,                  &
+      & sn
+   USE oce_tam       , ONLY: & ! ocean dynamics and active tracers
+      & un_tl,               &
+      & vn_tl,               &
+      & tb_tl,               &
+      & sb_tl,               &
+      & wn_tl,               &
+      & tn_tl,               &
+      & sn_tl,               &
+      & ta_tl,               &
+      & sa_tl,               &
+      & tn_ad,               &
+      & sn_ad,               &
+      & ta_ad,               &
+      & sa_ad
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & tmask,               &
+      & e1t,                 &
+      & e2t,                 &
+      & e2u,                 &
+      & e1v,                 &
+# if defined key_vvl
+      & e3t_1,               &
+# else
+#  if defined key_zco
+      & e3t_0,               &
+#  else
+      & e3t,                 &
+#  endif
+# endif
+# if defined key_zco
+      & e3t_0,               &
+# else
+      & e3u,                 &
+      & e3v,                 &
+# endif
+      & lk_vvl,              &   
+      & tmask,               &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              & 
+      & nitend,              & 
+      & nit000,              &
+      & ln_rstart
+   USE zdf_oce       , ONLY: & ! ocean vertical physics
+      & avmb,                &
+      & avtb
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          &    !
+      & prntst_tlm,          &    !
+      & stdu,                &    ! stdev for u-velocity
+      & stdv,                &    ! stdev for v-velocity
+      & stdw,                &    ! stdev for w-velocity
+      & stdt,                &    ! stdev for temperature
+      & stds                      !           salinity
+   USE paresp        , ONLY: &
+      & wesp_t,              &
+      & wesp_s
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_adv_cen2_tan    ! routine called by traadv_tam.F90
+   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) ::  &
+     & btr2   ! inverse of T-point surface [1/(e1t*e2t)]
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.2 , LOCEAN-IPSL (2009)
+   !! $Id: traadv_cen2.F90 1201 2008-09-24 13:24:21Z rblod $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_adv_cen2_tan( kt, pun, pvn, pwn, pun_tl, pvn_tl, pwn_tl )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_cen2_tan  ***
+      !!                 
+      !! ** Purpose of the direct routine:
+      !!      Compute the now trend due to the advection of tracers
+      !!      and add it to the general trend of passive tracer equations.
+      !!
+      !! ** Method  :   The advection is evaluated by a second order centered
+      !!      scheme using now fields (leap-frog scheme). In specific areas
+      !!      (vicinity of major river mouths, some straits, or where tn is
+      !!      approaching the freezing point) it is mixed with an upstream
+      !!      scheme for stability reasons.
+      !!         Part 0 : compute the upstream / centered flag
+      !!                  (3D array, zind, defined at T-point (0<zind<1))
+      !!         Part I : horizontal advection
+      !!       * centered flux:
+      !!               zcenu = e2u*e3u  un  mi(tn)
+      !!               zcenv = e1v*e3v  vn  mj(tn)
+      !!       * upstream flux:
+      !!               zupsu = e2u*e3u  un  (tb(i) or tb(i-1) ) [un>0 or <0]
+      !!               zupsv = e1v*e3v  vn  (tb(j) or tb(j-1) ) [vn>0 or <0]
+      !!       * mixed upstream / centered horizontal advection scheme
+      !!               zcofi = max(zind(i+1), zind(i))
+      !!               zcofj = max(zind(j+1), zind(j))
+      !!               zwx = zcofi * zupsu + (1-zcofi) * zcenu
+      !!               zwy = zcofj * zupsv + (1-zcofj) * zcenv
+      !!       * horizontal advective trend (divergence of the fluxes)
+      !!               zta = 1/(e1t*e2t*e3t) { di-1[zwx] + dj-1[zwy] }
+      !!       * Add this trend now to the general trend of tracer (ta,sa):
+      !!              (ta,sa) = (ta,sa) + ( zta , zsa )
+      !!       * trend diagnostic ('key_trdtra' defined): the trend is
+      !!      saved for diagnostics. The trends saved is expressed as
+      !!      Uh.gradh(T), i.e.
+      !!                     save trend = zta + tn divn
+      !!         In addition, the advective trend in the two horizontal direc-
+      !!      tion is also re-computed as Uh gradh(T). Indeed hadt+tn divn is
+      !!      equal to (in s-coordinates, and similarly in z-coord.):
+      !!         zta+tn*divn=1/(e1t*e2t*e3t) { mi-1( e2u*e3u  un  di[tn] )
+      !!                                      +mj-1( e1v*e3v  vn  mj[tn] )  }
+      !!         NB:in z-coordinate - full step (ln_zco=T) e3u=e3v=e3t, so
+      !!      they vanish from the expression of the flux and divergence.
+      !!
+      !!         Part II : vertical advection
+      !!      For temperature (idem for salinity) the advective trend is com-
+      !!      puted as follows :
+      !!            zta = 1/e3t dk+1[ zwz ]
+      !!      where the vertical advective flux, zwz, is given by :
+      !!            zwz = zcofk * zupst + (1-zcofk) * zcent
+      !!      with
+      !!        zupsv = upstream flux = wn * (tb(k) or tb(k-1) ) [wn>0 or <0]
+      !!        zcenu = centered flux = wn * mk(tn)
+      !!         The surface boundary condition is :
+      !!      variable volume (lk_vvl = T) : zero advective flux
+      !!      lin. free-surf  (lk_vvl = F) : wn(:,:,1) * tn(:,:,1)
+      !!         Add this trend now to the general trend of tracer (ta,sa):
+      !!            (ta,sa) = (ta,sa) + ( zta , zsa )
+      !!         Trend diagnostic ('key_trdtra' defined): the trend is
+      !!      saved for diagnostics. The trends saved is expressed as :
+      !!             save trend =  w.gradz(T) = zta - tn divn.
+      !!
+      !! ** Action :  - update (ta,sa) with the now advective tracer trends
+      !!              - save trends in (ztrdt,ztrds) ('key_trdtra')
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER , INTENT(in)                         ::   kt    ! ocean time-step index
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pun_tl   ! ocean velocity u-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pvn_tl   ! ocean velocity v-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pwn_tl   ! ocean velocity w-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pun      ! ocean velocity u-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pvn      ! ocean velocity v-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pwn      ! ocean velocity w-component
+      !!
+      INTEGER  ::   ji, jj, jk                           ! dummy loop indices
+      REAL(wp) ::   zbtr, zhw, zhwtl,                 &  ! temporary scalars
+         &          ze3tr, zfui  , zfuitl  ,          &  !    "         "
+         &          zfvj  , zfvjtl                       !    "         "
+      REAL(wp) ::   zice                                 !    -         -
+      REAL(wp), DIMENSION(jpi,jpj)     ::   ztfreez      ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwwtl, zwztl ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwxtl, zwytl ! 3D workspace
+      !!----------------------------------------------------------------------
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_adv_cen2_tan : 2nd order centered advection scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~   Vector optimization case'
+         IF(lwp) WRITE(numout,*)
+         !
+         !   
+         btr2(:,:) = 1.0_wp / ( e1t(:,:) * e2t(:,:) )        ! inverse of T-point surface
+         IF ( jp_cfg == 2 .AND. .NOT. ln_rstart ) THEN    !   Increase the background in the surface layers
+            avmb(1) = 10.  * avmb(1)      ;      avtb(1) = 10.  * avtb(1)
+            avmb(2) = 10.  * avmb(2)      ;      avtb(2) = 10.  * avtb(2)
+            avmb(3) =  5.  * avmb(3)      ;      avtb(3) =  5.  * avtb(3)
+            avmb(4) =  2.5 * avmb(4)      ;      avtb(4) =  2.5 * avtb(4)
+         ENDIF
+      ENDIF
+
+      ! I. Horizontal advection
+      !    ====================
+      !
+      DO jk = 1, jpkm1
+         !                        ! Second order centered tracer flux at u- and v-points
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ! volume fluxes * 1/2
+               zfuitl = 0.5 * e2u(ji,jj) * fse3u(ji,jj,jk) * pun_tl(ji,jj,jk)
+               zfvjtl = 0.5 * e1v(ji,jj) * fse3v(ji,jj,jk) * pvn_tl(ji,jj,jk)
+               zfui = 0.5 * e2u(ji,jj) * fse3u(ji,jj,jk) * pun(ji,jj,jk)
+               zfvj = 0.5 * e1v(ji,jj) * fse3v(ji,jj,jk) * pvn(ji,jj,jk)
+               !
+               ! centered scheme
+               zwxtl(ji,jj,jk) = zfuitl * ( tn(ji,jj,jk) + tn(ji+1,jj,jk) ) &
+                  &            + zfui * ( tn_tl(ji,jj,jk) + tn_tl(ji+1,jj,jk) )
+               zwytl(ji,jj,jk) = zfvjtl * ( tn(ji,jj,jk) + tn(ji,jj+1,jk) ) &
+                  &            + zfvj * ( tn_tl(ji,jj,jk) + tn_tl(ji,jj+1,jk) )
+               zwwtl(ji,jj,jk) = zfuitl * ( sn(ji,jj,jk) + sn(ji+1,jj,jk) ) &
+                  &            + zfui * ( sn_tl(ji,jj,jk) + sn_tl(ji+1,jj,jk) )
+               zwztl(ji,jj,jk) = zfvjtl * ( sn(ji,jj,jk) + sn(ji,jj+1,jk) ) &
+                  &            + zfvj * ( sn_tl(ji,jj,jk) + sn_tl(ji,jj+1,jk) )
+            END DO
+         END DO
+         !                        ! Tracer flux divergence at t-point added to the general trend
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbtr = btr2(ji,jj) / fse3t(ji,jj,jk)
+               !
+               ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) - zbtr * ( zwxtl(ji,jj,jk) - zwxtl(ji-1,jj  ,jk) &
+                    &                                     + zwytl(ji,jj,jk) - zwytl(ji  ,jj-1,jk) )
+               sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) - zbtr * ( zwwtl(ji,jj,jk) - zwwtl(ji-1,jj  ,jk) &
+                    &                                     + zwztl(ji,jj,jk) - zwztl(ji  ,jj-1,jk) )
+            END DO
+         END DO
+      END DO
+
+      ! "zonal" mean advective heat and salt transport 
+      ! ----------------------------------------------
+
+!      IF( ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+!         IF( lk_zco ) THEN
+!            DO jk = 1, jpkm1
+!               DO jj = 2, jpjm1
+!                  DO ji = fs_2, fs_jpim1   ! vector opt.
+!                    zwytl(ji,jj,jk) = zwytl(ji,jj,jk) * fse3v(ji,jj,jk)
+!                    zwztl(ji,jj,jk) = zwztl(ji,jj,jk) * fse3v(ji,jj,jk)
+!                  END DO
+!               END DO
+!            END DO
+!         ENDIF
+!         pht_adv(:) = ptr_vj( zwy(:,:,:) )
+!         pst_adv(:) = ptr_vj( zwz(:,:,:) )
+!      ENDIF
+
+      ! II. Vertical advection
+      !     ==================
+      !
+      zwxtl(:,:,jpk) = 0.0_wp    ; zwytl(:,:,jpk) = 0.0_wp ! Bottom value : flux set to zero
+
+      IF( lk_vvl ) THEN                                    ! Surface value : zero in variable volume
+         zwxtl(:,:, 1 ) = 0.0_wp ; zwytl(:,:, 1 ) = 0.0_wp 
+      ELSE                                                 !               : linear free surface case
+         zwxtl(:,:, 1 ) = pwn_tl(:,:,1) * tn(:,:,1) + pwn(:,:,1) * tn_tl(:,:,1)
+         zwytl(:,:, 1 ) = pwn_tl(:,:,1) * sn(:,:,1) + pwn(:,:,1) * sn_tl(:,:,1)
+      ENDIF
+      !
+      DO jk = 2, jpk              ! Second order centered tracer flux at w-point
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! velocity * 1/2
+               zhwtl = 0.5 * pwn_tl(ji,jj,jk)
+               zhw   = 0.5 * pwn(   ji,jj,jk)
+               ! centered scheme
+               zwxtl(ji,jj,jk) = zhwtl * ( tn( ji,jj,jk) + tn(   ji,jj,jk-1) ) &
+                  &            + zhw * ( tn_tl(ji,jj,jk) + tn_tl(ji,jj,jk-1) )
+               zwytl(ji,jj,jk) = zhwtl * ( sn( ji,jj,jk) + sn(   ji,jj,jk-1) ) &
+                  &            + zhw * ( sn_tl(ji,jj,jk) + sn_tl(ji,jj,jk-1) )
+            END DO
+         END DO
+      END DO
+      !
+      DO jk = 1, jpkm1            ! divergence of Tracer flux added to the general trend
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ze3tr = 1.0_wp / fse3t(ji,jj,jk)
+               ! vertical advective trends
+               ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) - ze3tr * ( zwxtl(ji,jj,jk) - zwxtl(ji,jj,jk+1) )
+               sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) - ze3tr * ( zwytl(ji,jj,jk) - zwytl(ji,jj,jk+1) )
+            END DO
+         END DO
+      END DO
+
+
+      !
+   END SUBROUTINE tra_adv_cen2_tan
+   
+   SUBROUTINE tra_adv_cen2_adj( kt, pun, pvn, pwn, pun_ad, pvn_ad, pwn_ad )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_cen2_adj  ***
+      !!                 
+      !! ** Purpose of the direct routine:
+      !!      Compute the now trend due to the advection of tracers
+      !!      and add it to the general trend of passive tracer equations.
+      !!
+      !! ** Method  :   The advection is evaluated by a second order centered
+      !!      scheme using now fields (leap-frog scheme). In specific areas
+      !!      (vicinity of major river mouths, some straits, or where tn is
+      !!      approaching the freezing point) it is mixed with an upstream
+      !!      scheme for stability reasons.
+      !!         Part 0 : compute the upstream / centered flag
+      !!                  (3D array, zind, defined at T-point (0<zind<1))
+      !!         Part I : horizontal advection
+      !!       * centered flux:
+      !!               zcenu = e2u*e3u  un  mi(tn)
+      !!               zcenv = e1v*e3v  vn  mj(tn)
+      !!       * upstream flux:
+      !!               zupsu = e2u*e3u  un  (tb(i) or tb(i-1) ) [un>0 or <0]
+      !!               zupsv = e1v*e3v  vn  (tb(j) or tb(j-1) ) [vn>0 or <0]
+      !!       * mixed upstream / centered horizontal advection scheme
+      !!               zcofi = max(zind(i+1), zind(i))
+      !!               zcofj = max(zind(j+1), zind(j))
+      !!               zwx = zcofi * zupsu + (1-zcofi) * zcenu
+      !!               zwy = zcofj * zupsv + (1-zcofj) * zcenv
+      !!       * horizontal advective trend (divergence of the fluxes)
+      !!               zta = 1/(e1t*e2t*e3t) { di-1[zwx] + dj-1[zwy] }
+      !!       * Add this trend now to the general trend of tracer (ta,sa):
+      !!              (ta,sa) = (ta,sa) + ( zta , zsa )
+      !!       * trend diagnostic ('key_trdtra' defined): the trend is
+      !!      saved for diagnostics. The trends saved is expressed as
+      !!      Uh.gradh(T), i.e.
+      !!                     save trend = zta + tn divn
+      !!         In addition, the advective trend in the two horizontal direc-
+      !!      tion is also re-computed as Uh gradh(T). Indeed hadt+tn divn is
+      !!      equal to (in s-coordinates, and similarly in z-coord.):
+      !!         zta+tn*divn=1/(e1t*e2t*e3t) { mi-1( e2u*e3u  un  di[tn] )
+      !!                                      +mj-1( e1v*e3v  vn  mj[tn] )  }
+      !!         NB:in z-coordinate - full step (ln_zco=T) e3u=e3v=e3t, so
+      !!      they vanish from the expression of the flux and divergence.
+      !!
+      !!         Part II : vertical advection
+      !!      For temperature (idem for salinity) the advective trend is com-
+      !!      puted as follows :
+      !!            zta = 1/e3t dk+1[ zwz ]
+      !!      where the vertical advective flux, zwz, is given by :
+      !!            zwz = zcofk * zupst + (1-zcofk) * zcent
+      !!      with
+      !!        zupsv = upstream flux = wn * (tb(k) or tb(k-1) ) [wn>0 or <0]
+      !!        zcenu = centered flux = wn * mk(tn)
+      !!         The surface boundary condition is :
+      !!      rigid-lid (lk_dynspg_frd = T) : zero advective flux
+      !!      free-surf (lk_dynspg_fsc = T) : wn(:,:,1) * tn(:,:,1)
+      !!         Add this trend now to the general trend of tracer (ta,sa):
+      !!            (ta,sa) = (ta,sa) + ( zta , zsa )
+      !!         Trend diagnostic ('key_trdtra' defined): the trend is
+      !!      saved for diagnostics. The trends saved is expressed as :
+      !!             save trend =  w.gradz(T) = zta - tn divn.
+      !!
+      !! ** Action :  - update (ta,sa) with the now advective tracer trends
+      !!              - save trends in (ztrdt,ztrds) ('key_trdtra')
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER , INTENT(in)                         ::   kt    ! ocean time-step index
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pun_ad   ! ocean velocity u-component
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pvn_ad   ! ocean velocity v-component
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pwn_ad   ! ocean velocity w-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pun      ! ocean velocity u-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pvn      ! ocean velocity v-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pwn      ! ocean velocity w-component
+      !!
+      INTEGER  ::   ji, jj, jk                           ! dummy loop indices
+      REAL(wp) ::   zbtr, zhw, zhwad,                 &  ! temporary scalars
+         &          ze3tr, zfui  , zfuiad  ,          &  !    "         "
+         &          zfvj , zfvjad                        !    "         "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwwad, zwzad ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwxad, zwyad ! 3D workspace
+      !!----------------------------------------------------------------------
+      zhwad = 0.0_wp  ;  zfuiad = 0.0_wp  ;  zfvjad = 0.0_wp
+      zwxad(:,:,:) = 0.0_wp  ;  zwyad(:,:,:) = 0.0_wp  ;  zwwad(:,:,:) = 0.0_wp  ;  zwzad(:,:,:) = 0.0_wp
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_adv_cen2_adj : 2nd order centered advection scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~   Vector optimization case'
+         IF(lwp) WRITE(numout,*)
+         !
+         !   
+         btr2(:,:) = 1.0_wp / ( e1t(:,:) * e2t(:,:) )        ! inverse of T-point surface
+         IF ( jp_cfg == 2 .AND. .NOT. ln_rstart ) THEN    !   Increase the background in the surface layers
+            avmb(1) = 10.  * avmb(1)      ;      avtb(1) = 10.  * avtb(1)
+            avmb(2) = 10.  * avmb(2)      ;      avtb(2) = 10.  * avtb(2)
+            avmb(3) =  5.  * avmb(3)      ;      avtb(3) =  5.  * avtb(3)
+            avmb(4) =  2.5 * avmb(4)      ;      avtb(4) =  2.5 * avtb(4)
+         ENDIF
+      ENDIF
+      ! II. Vertical advection
+      !     ==================
+      !
+      DO jk = jpkm1, 1, -1            ! divergence of Tracer flux added to the general trend
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ze3tr = 1.0_wp / fse3t(ji,jj,jk)
+              ! vertical advective trends
+               zwxad(ji,jj,jk)   = zwxad(ji,jj,jk)   - ze3tr * ta_ad(ji,jj,jk)
+               zwxad(ji,jj,jk+1) = zwxad(ji,jj,jk+1) + ze3tr * ta_ad(ji,jj,jk)
+               zwyad(ji,jj,jk)   = zwyad(ji,jj,jk)   - ze3tr * sa_ad(ji,jj,jk)
+               zwyad(ji,jj,jk+1) = zwyad(ji,jj,jk+1) + ze3tr * sa_ad(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+      DO jk = jpk, 2, -1              ! Second order centered tracer flux at w-point
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! velocity * 1/2
+               zhw   = 0.5 * pwn(   ji,jj,jk)
+               ! centered scheme
+               zhwad             = zhwad + zwyad(ji,jj,jk) * ( sn( ji,jj,jk) + sn(   ji,jj,jk-1) )
+               sn_ad(ji,jj,jk)   = sn_ad(ji,jj,jk)   + zwyad(ji,jj,jk) * zhw
+               sn_ad(ji,jj,jk-1) = sn_ad(ji,jj,jk-1) + zwyad(ji,jj,jk) * zhw
+               zwyad(ji,jj,jk)   = 0.0_wp
+               zhwad             = zhwad + zwxad(ji,jj,jk) * ( tn( ji,jj,jk) + tn(   ji,jj,jk-1) )
+               tn_ad(ji,jj,jk)   = tn_ad(ji,jj,jk)   + zwxad(ji,jj,jk) * zhw
+               tn_ad(ji,jj,jk-1) = tn_ad(ji,jj,jk-1) + zwxad(ji,jj,jk) * zhw
+               zwxad(ji,jj,jk)   = 0.0_wp
+               ! velocity * 1/2
+               pwn_ad(ji,jj,jk) = pwn_ad(ji,jj,jk) + 0.5 * zhwad
+               zhwad = 0.0_wp
+           END DO
+         END DO
+      END DO
+      !
+      IF( lk_vvl ) THEN                                         ! Surface value : zero in variable volume
+         zwxad(:,:, 1 ) = 0.0_wp    ;    zwyad(:,:, 1 ) = 0.0_wp
+      ELSE                                                      !               : linear free surface case
+         pwn_ad(:,:,1) = pwn_ad(:,:,1) + zwyad(:,:, 1 ) * sn(:,:,1) 
+         sn_ad(:,:,1)  = sn_ad(:,:,1)  + zwyad(:,:, 1 ) * pwn(:,:,1)
+         pwn_ad(:,:,1) = pwn_ad(:,:,1) + zwxad(:,:, 1 ) * tn(:,:,1) 
+         tn_ad(:,:,1)  = tn_ad(:,:,1)  + zwxad(:,:, 1 ) * pwn(:,:,1)
+         zwxad(:,:, 1 ) = 0.0_wp
+         zwyad(:,:, 1 ) = 0.0_wp
+      ENDIF
+      !
+      zwxad(:,:,jpk) = 0.0_wp     ;    zwyad(:,:,jpk) = 0.0_wp  ! Bottom value  : flux set to zero
+      ! "zonal" mean advective heat and salt transport 
+      ! ----------------------------------------------
+
+!      IF( ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+!         IF( lk_zco ) THEN
+!            DO jk = 1, jpkm1
+!               DO jj = 2, jpjm1
+!                  DO ji = fs_2, fs_jpim1   ! vector opt.
+!                    zwyad(ji,jj,jk) = zwyad(ji,jj,jk) * fse3v(ji,jj,jk)
+!                    zwzad(ji,jj,jk) = zwzad(ji,jj,jk) * fse3v(ji,jj,jk)
+!                  END DO
+!               END DO
+!            END DO
+!         ENDIF
+!         pht_adv(:) = ptr_vj( zwy(:,:,:) )
+!         pst_adv(:) = ptr_vj( zwz(:,:,:) )
+!      ENDIF
+!
+      ! I. Horizontal advective fluxes
+      !    ====================
+      !
+      DO jk = 1, jpkm1
+         !                        ! Tracer flux divergence at t-point added to the general trend
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+               zbtr = btr2(ji,jj) / fse3t(ji,jj,jk)
+               ! horizontal advective trends
+               zwxad(ji  ,jj  ,jk) = zwxad(ji  ,jj  ,jk) - zbtr * ta_ad(ji,jj,jk)
+               zwxad(ji-1,jj  ,jk) = zwxad(ji-1,jj  ,jk) + zbtr * ta_ad(ji,jj,jk)
+               zwyad(ji  ,jj  ,jk) = zwyad(ji  ,jj  ,jk) - zbtr * ta_ad(ji,jj,jk)
+               zwyad(ji  ,jj-1,jk) = zwyad(ji  ,jj-1,jk) + zbtr * ta_ad(ji,jj,jk)
+               zwwad(ji  ,jj  ,jk) = zwwad(ji  ,jj  ,jk) - zbtr * sa_ad(ji,jj,jk)
+               zwwad(ji-1,jj  ,jk) = zwwad(ji-1,jj  ,jk) + zbtr * sa_ad(ji,jj,jk)
+               zwzad(ji  ,jj  ,jk) = zwzad(ji  ,jj  ,jk) - zbtr * sa_ad(ji,jj,jk)
+               zwzad(ji  ,jj-1,jk) = zwzad(ji  ,jj-1,jk) + zbtr * sa_ad(ji,jj,jk)
+            END DO
+         END DO
+         !                        ! Second order centered tracer flux at u- and v-points
+         DO jj = jpjm1, 1, -1
+            DO ji = fs_jpim1, 1, -1   ! vector opt.
+               ! volume fluxes * 1/2
+               zfui = 0.5 * e2u(ji,jj) * fse3u(ji,jj,jk) * pun(ji,jj,jk)
+               zfvj = 0.5 * e1v(ji,jj) * fse3v(ji,jj,jk) * pvn(ji,jj,jk)
+               ! centered scheme
+               zfvjad = zfvjad + zwzad(ji,jj,jk) * ( sn(ji,jj,jk) + sn(ji,jj+1,jk) )
+               sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) + zwzad(ji,jj,jk) * zfvj
+               sn_ad(ji,jj+1,jk) = sn_ad(ji,jj+1,jk) + zwzad(ji,jj,jk) * zfvj
+               zwzad(ji,jj,jk) = 0.0_wp
+               zfuiad = zfuiad + zwwad(ji,jj,jk) * ( sn(ji,jj,jk) + sn(ji+1,jj,jk) ) 
+               sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) + zwwad(ji,jj,jk) * zfui
+               sn_ad(ji+1,jj,jk) = sn_ad(ji+1,jj,jk) + zwwad(ji,jj,jk) * zfui
+               zwwad(ji,jj,jk) = 0.0_wp
+               zfvjad = zfvjad + zwyad(ji,jj,jk) * ( tn(ji,jj,jk) + tn(ji,jj+1,jk) )
+               tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) + zwyad(ji,jj,jk) * zfvj
+               tn_ad(ji,jj+1,jk) = tn_ad(ji,jj+1,jk) + zwyad(ji,jj,jk) * zfvj
+               zwyad(ji,jj,jk) = 0.0_wp
+               zfuiad = zfuiad + zwxad(ji,jj,jk) * ( tn(ji,jj,jk) + tn(ji+1,jj,jk) )
+               tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) + zwxad(ji,jj,jk) * zfui
+               tn_ad(ji+1,jj,jk) = tn_ad(ji+1,jj,jk) + zwxad(ji,jj,jk) * zfui
+               zwxad(ji,jj,jk) = 0.0_wp
+               ! volume fluxes * 1/2
+               pun_ad(ji,jj,jk) = pun_ad(ji,jj,jk) + 0.5 * e2u(ji,jj) * fse3u(ji,jj,jk) * zfuiad
+               pvn_ad(ji,jj,jk) = pvn_ad(ji,jj,jk) + 0.5 * e1v(ji,jj) * fse3v(ji,jj,jk) * zfvjad
+               zfuiad = 0.0_wp
+               zfvjad = 0.0_wp
+             END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE tra_adv_cen2_adj
+SUBROUTINE tra_adv_cen2_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tra_adv_cen2_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2            ! scalar product involving the adjoint routine
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zun_tlin ,     & ! Tangent input
+         & zvn_tlin ,     & ! Tangent input
+         & zwn_tlin ,     & ! Tangent input
+         & ztn_tlin ,     & ! Tangent input
+         & zsn_tlin ,     & ! Tangent input
+         & zta_tlin ,     & ! Tangent input
+         & zsa_tlin ,     & ! Tangent input
+         & zta_tlout,     & ! Tangent output
+         & zsa_tlout,     & ! Tangent output
+         & zta_adin ,     & ! Adjoint input
+         & zsa_adin ,     & ! Adjoint input
+         & zun_adout,     & ! Adjoint output
+         & zvn_adout,     & ! Adjoint output
+         & zwn_adout,     & ! Adjoint output
+         & ztn_adout,     & ! Adjoint output
+         & zsn_adout,     & ! Adjoint output
+         & zta_adout,     & ! Adjoint output
+         & zsa_adout,     & ! Adjoint output
+         & zr             ! 3D random field 
+      CHARACTER(LEN=14) ::&
+         & cl_name
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zun_tlin( jpi,jpj,jpk),     &
+         & zvn_tlin( jpi,jpj,jpk),     &
+         & zwn_tlin( jpi,jpj,jpk),     &
+         & ztn_tlin( jpi,jpj,jpk),     &
+         & zsn_tlin( jpi,jpj,jpk),     &
+         & zta_tlin( jpi,jpj,jpk),     &
+         & zsa_tlin( jpi,jpj,jpk),     &
+         & zta_tlout(jpi,jpj,jpk),     &
+         & zsa_tlout(jpi,jpj,jpk),     &
+         & zta_adin( jpi,jpj,jpk),     &
+         & zsa_adin( jpi,jpj,jpk),     &
+         & zun_adout(jpi,jpj,jpk),     &
+         & zvn_adout(jpi,jpj,jpk),     &
+         & zwn_adout(jpi,jpj,jpk),     &
+         & ztn_adout(jpi,jpj,jpk),     &
+         & zsn_adout(jpi,jpj,jpk),     &
+         & zta_adout(jpi,jpj,jpk),     &
+         & zsa_adout(jpi,jpj,jpk),     &
+         & zr(       jpi,jpj,jpk)      &
+         & )
+      !==================================================================
+      ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and 
+      !    dy = ( hdivb_tl, hdivn_tl )
+      !==================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      zun_tlin( :,:,:) = 0.0_wp
+      zvn_tlin( :,:,:) = 0.0_wp
+      zwn_tlin( :,:,:) = 0.0_wp
+      ztn_tlin( :,:,:) = 0.0_wp
+      zsn_tlin( :,:,:) = 0.0_wp
+      zta_tlin( :,:,:) = 0.0_wp
+      zsa_tlin( :,:,:) = 0.0_wp
+      zta_tlout(:,:,:) = 0.0_wp
+      zsa_tlout(:,:,:) = 0.0_wp
+      zta_adin( :,:,:) = 0.0_wp
+      zsa_adin( :,:,:) = 0.0_wp
+      zun_adout(:,:,:) = 0.0_wp
+      zvn_adout(:,:,:) = 0.0_wp
+      zwn_adout(:,:,:) = 0.0_wp
+      ztn_adout(:,:,:) = 0.0_wp
+      zsn_adout(:,:,:) = 0.0_wp
+      zta_adout(:,:,:) = 0.0_wp
+      zsa_adout(:,:,:) = 0.0_wp
+      zr(       :,:,:) = 0.0_wp
+
+      tn_ad(:,:,:) = 0.0_wp
+      sn_ad(:,:,:) = 0.0_wp 
+      
+       
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'U', 0.0_wp, stdu )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zun_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 371836 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'V', 0.0_wp, stdv ) 
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zvn_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 148379 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'W', 0.0_wp, stdw )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zwn_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 264940 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              ztn_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+            END DO
+         END DO
+      END DO 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 618304 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stds ) 
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsn_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 481903 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zta_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 263871 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stds ) 
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsa_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      tn_tl(:,:,:) = ztn_tlin(:,:,:)
+      sn_tl(:,:,:) = zsn_tlin(:,:,:)
+      ta_tl(:,:,:) = zta_tlin(:,:,:)
+      sa_tl(:,:,:) = zsa_tlin(:,:,:)
+
+      CALL tra_adv_cen2_tan(nit000, un, vn, wn, zun_tlin, zvn_tlin, zwn_tlin) 
+
+      zta_tlout(:,:,:) = ta_tl(:,:,:) 
+      zsa_tlout(:,:,:) = sa_tl(:,:,:) 
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zta_adin(ji,jj,jk) = zta_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_t(jk)
+              zsa_adin(ji,jj,jk) = zsa_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_s(jk)
+            END DO
+         END DO
+      END DO
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1 = DOT_PRODUCT( zta_tlout, zta_adin ) &
+         & + DOT_PRODUCT( zsa_tlout, zsa_adin )
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+      ta_ad(:,:,:) = zta_adin(:,:,:)
+      sa_ad(:,:,:) = zsa_adin(:,:,:)
+
+      CALL tra_adv_cen2_adj(nit000, un, vn, wn, zun_adout, zvn_adout, zwn_adout)
+
+      ztn_adout(:,:,:) = tn_ad(:,:,:)
+      zsn_adout(:,:,:) = sn_ad(:,:,:)
+      zta_adout(:,:,:) = ta_ad(:,:,:)
+      zsa_adout(:,:,:) = sa_ad(:,:,:)
+
+      zsp2 = DOT_PRODUCT( zun_tlin, zun_adout ) &
+         & + DOT_PRODUCT( zvn_tlin, zvn_adout ) &
+         & + DOT_PRODUCT( zwn_tlin, zwn_adout ) &
+         & + DOT_PRODUCT( ztn_tlin, ztn_adout ) &
+         & + DOT_PRODUCT( zsn_tlin, zsn_adout ) &
+         & + DOT_PRODUCT( zta_tlin, zta_adout ) &
+         & + DOT_PRODUCT( zsa_tlin, zsa_adout )
+
+      ! 14 char:'12345678901234'
+      cl_name = 'tra_adv_cen2  '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      DEALLOCATE(         &
+         & zun_tlin ,     & ! Tangent input
+         & zvn_tlin ,     & ! Tangent input
+         & zwn_tlin ,     & ! Tangent input
+         & ztn_tlin ,     & ! Tangent input
+         & zsn_tlin ,     & ! Tangent input
+         & zta_tlin ,     & ! Tangent input
+         & zsa_tlin ,     & ! Tangent input
+         & zta_tlout,     & ! Tangent output
+         & zsa_tlout,     & ! Tangent output
+         & zta_adin ,     & ! Adjoint input
+         & zsa_adin ,     & ! Adjoint input
+         & zun_adout,     & ! Adjoint output
+         & zvn_adout,     & ! Adjoint output
+         & zwn_adout,     & ! Adjoint output
+         & ztn_adout,     & ! Adjoint output
+         & zsn_adout,     & ! Adjoint output
+         & zta_adout,     & ! Adjoint output
+         & zsa_adout,     & ! Adjoint output
+         & zr             & ! 3D random field 
+         & )
+
+
+
+   END SUBROUTINE tra_adv_cen2_adj_tst
+#if defined key_tst_tlm
+SUBROUTINE tra_adv_cen2_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tra_adv_cen2_tlm_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 :
+      !!        ! 09-08 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE traadv_cen2         ! horizontal & vertical advective trend
+      USE tamtrj              ! writing out state trajectory
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE sshwzv             !  vertical velocity
+      USE gridrandom, ONLY: &
+        & grid_rd_sd
+      USE trj_tam
+      USE oce           , ONLY: & ! ocean dynamics and tracers variables
+        & tb, sb, tn, sn, ta,  &
+        & sa, gtu, gsu, gtv,   &
+        & gsv
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_Ta,      &
+         & zsp1_Sa,      &
+         & zsp2,         & ! scalar product involving the tangent routine
+         & zsp2_Ta,      &
+         & zsp2_Sa,      &
+         & zsp3,         & ! scalar product involving the tangent routine
+         & zsp3_Ta,      &
+         & zsp3_Sa,      &
+         & zzsp,         & ! scalar product involving the tangent routine
+         & zzsp_Ta,      &
+         & zzsp_Sa,      & 
+         & gamma,            &
+         & zgsp1,            &
+         & zgsp2,            &
+         & zgsp3,            &
+         & zgsp4,            &
+         & zgsp5,            &
+         & zgsp6,            &
+         & zgsp7 
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zun_tlin,      & ! Tangent input
+         & zvn_tlin,      & ! Tangent input
+         & zwn_tlin,      & ! Tangent input
+         & ztn_tlin,      & ! Tangent input
+         & zsn_tlin,      & ! Tangent input
+         & zta_tlin,      & ! Tangent input
+         & zsa_tlin,      & ! Tangent input
+         & zta_out ,      & ! Direct output
+         & zsa_out ,      & ! Direct output
+         & zta_wop ,      & ! Direct output w/o perturbation
+         & zsa_wop ,      & ! Direct output w/o perturbation
+         & z3r
+      CHARACTER(LEN=14)   :: cl_name
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
+      CHARACTER (LEN=90)  :: FMT
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zscta,zscsa,               &
+         & zscerrta, zscerrsa
+      INTEGER, DIMENSION(100)::           &
+         & iiposta, iipossa,              &
+         & ijposta, ijpossa,              & 
+         & ikposta, ikpossa
+      INTEGER::             &
+         & ii,              &
+         & isamp=40,        &
+         & jsamp=40,        &
+         & ksamp=10,        &
+         & numsctlm
+     REAL(KIND=wp), DIMENSION(jpi,jpj,jpk) :: &
+         & zerrta, zerrsa   
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zun_tlin( jpi,jpj,jpk),     &
+         & zvn_tlin( jpi,jpj,jpk),     &
+         & zwn_tlin( jpi,jpj,jpk),     &
+         & ztn_tlin( jpi,jpj,jpk),     &
+         & zsn_tlin( jpi,jpj,jpk),     &
+         & zta_tlin( jpi,jpj,jpk),     &
+         & zsa_tlin( jpi,jpj,jpk),     &
+         & zta_out ( jpi,jpj,jpk),     &
+         & zsa_out ( jpi,jpj,jpk),     &
+         & zta_wop ( jpi,jpj,jpk),     &
+         & zsa_wop ( jpi,jpj,jpk),     &
+         & z3r     ( jpi,jpj,jpk)      &
+         & )
+
+      !--------------------------------------------------------------------
+      ! Reset variables
+      !--------------------------------------------------------------------
+      zun_tlin( :,:,:) = 0.0_wp
+      zvn_tlin( :,:,:) = 0.0_wp
+      zwn_tlin( :,:,:) = 0.0_wp
+      ztn_tlin( :,:,:) = 0.0_wp
+      zsn_tlin( :,:,:) = 0.0_wp
+      zta_tlin( :,:,:) = 0.0_wp
+      zsa_tlin( :,:,:) = 0.0_wp
+      zta_out ( :,:,:) = 0.0_wp
+      zsa_out ( :,:,:) = 0.0_wp
+      zta_wop ( :,:,:) = 0.0_wp
+      zsa_wop ( :,:,:) = 0.0_wp
+
+      zscta(:)         = 0.0_wp
+      zscsa(:)         = 0.0_wp
+      zscerrta(:)      = 0.0_wp
+      zscerrsa(:)      = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Output filename Xn=F(X0)
+      !--------------------------------------------------------------------
+!!!!      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
+      !--------------------------------------------------------------------
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         CALL grid_rd_sd( 596035, z3r,  'U', 0.0_wp, stdu)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zun_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 371836, z3r,  'V', 0.0_wp, stdv)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zvn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 148379, z3r,  'W', 0.0_wp, stdw)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zwn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 264940, z3r,  'T', 0.0_wp, stdt)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  ztn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 618304, z3r,  'T', 0.0_wp, stds) 
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 481903, z3r,  'T', 0.0_wp, stdt)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zta_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 263871, z3r,  'T', 0.0_wp, stds) 
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsa_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      ENDIF       
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      IF ( tlm_bch /= 2 ) CALL istate_p  
+
+      ! *** initialize the reference trajectory
+      ! ------------
+      CALL  trj_rea( nit000-1, 1 )
+      CALL  trj_rea( nit000, 1 )
+
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         zun_tlin(:,:,:) = gamma * zun_tlin(:,:,:)
+         un(:,:,:)       = un(:,:,:) + zun_tlin(:,:,:)
+
+         zvn_tlin(:,:,:) = gamma * zvn_tlin(:,:,:)
+         vn(:,:,:)       = vn(:,:,:) + zvn_tlin(:,:,:)
+
+         zwn_tlin(:,:,:) = gamma * zwn_tlin(:,:,:)
+         wn(:,:,:)       = wn(:,:,:) + zwn_tlin(:,:,:)
+
+         ztn_tlin(:,:,:) = gamma * ztn_tlin(:,:,:)
+         tn(:,:,:)       = tn(:,:,:) + ztn_tlin(:,:,:)
+
+         zsn_tlin(:,:,:) = gamma * zsn_tlin(:,:,:)
+         sn(:,:,:)       = sn(:,:,:) + zsn_tlin(:,:,:)
+
+         zta_tlin(:,:,:) = gamma * zta_tlin(:,:,:)
+         ta(:,:,:)       = ta(:,:,:) + zta_tlin(:,:,:)
+
+         zsa_tlin(:,:,:) = gamma * zsa_tlin(:,:,:)
+         sa(:,:,:)       = sa(:,:,:) + zsa_tlin(:,:,:)
+      ENDIF 
+
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------
+      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 ( tlm_bch == 2 ) THEN       
+         !--------------------------------------------------------------------
+         ! Initialize the tangent variables: dy^* = W dy  
+         !--------------------------------------------------------------------
+         CALL  trj_rea( nit000-1, 1 ) 
+         CALL  trj_rea( nit000, 1 ) 
+         tn_tl  (:,:,:) = ztn_tlin  (:,:,:)
+         sn_tl  (:,:,:) = zsn_tlin  (:,:,:)
+         ta_tl  (:,:,:) = zta_tlin  (:,:,:)
+         sa_tl  (:,:,:) = zsa_tlin  (:,:,:)
+
+         !-----------------------------------------------------------------------
+         !  Initialization of the dynamics and tracer fields for the tangent
+         !----------------------------------------------------------------------- 
+         CALL tra_adv_cen2_tan(nit000, un, vn, wn, zun_tlin, zvn_tlin, zwn_tlin)
+
+         !--------------------------------------------------------------------
+         ! 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 
+         ! 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 jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zta_out   (ji,jj,jk) = zta_out    (ji,jj,jk) - zta_wop  (ji,jj,jk)
+                  zta_wop   (ji,jj,jk) = zta_out    (ji,jj,jk) - ta_tl    (ji,jj,jk)
+                  IF (  ta_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrta(ji,jj,jk) = zta_out(ji,jj,jk)/ta_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposta(ii) = ji
+                      ijposta(ii) = jj
+                      ikposta(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+                         zscta (ii) =  zta_wop(ji,jj,jk)
+                         zscerrta (ii) =  ( zerrta(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         ii=0
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zsa_out   (ji,jj,jk) = zsa_out    (ji,jj,jk) - zsa_wop  (ji,jj,jk)
+                  zsa_wop   (ji,jj,jk) = zsa_out    (ji,jj,jk) - sa_tl    (ji,jj,jk)
+                  IF (  sa_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrsa(ji,jj,jk) = zsa_out(ji,jj,jk)/sa_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iipossa(ii) = ji
+                      ijpossa(ii) = jj
+                      ikpossa(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+                         zscsa (ii) =  zsa_wop(ji,jj,jk)
+                         zscerrsa (ii) =  ( zerrsa(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+
+         zsp1_Ta    = DOT_PRODUCT( zta_out, zta_out  )
+         zsp1_Sa    = DOT_PRODUCT( zsa_out, zsa_out  )
+
+         zsp1      = zsp1_Ta + zsp1_Sa
+
+         zsp3_Ta    = DOT_PRODUCT( zta_wop, zta_wop  )
+         zsp3_Sa    = DOT_PRODUCT( zsa_wop, zsa_wop  )
+
+         zsp3      = zsp3_Ta + zsp3_Sa
+
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name = 'traadv_tam:En '
+         zzsp    = SQRT(zsp3)
+         zzsp_Ta = SQRT(zsp3_Ta)
+         zzsp_Sa = SQRT(zsp3_Sa)
+         zgsp5   = zzsp
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp     = SQRT(zsp2)
+         zzsp_Ta  = SQRT(zsp2_Ta)
+         zzsp_Sa  = SQRT(zsp2_Sa)
+         zgsp4    = zzsp
+         cl_name  = 'traadv_tam:Ln2'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         zzsp     = sqrt(zsp1)
+         zzsp_Ta  = sqrt(zsp1_Ta)
+         zzsp_Sa  = sqrt(zsp1_Sa)
+
+         cl_name = 'traadv:Mhdx-Mx'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         zgsp3    = SQRT( zsp3/zsp2 )
+         zgsp7    = zgsp3/gamma
+         zgsp1    = zzsp
+         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) 'tadvcen2', 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 = 'tadvcen2'
+         IF(lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zscta(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscta     ', &
+                    & cur_loop, h_ratio, ii, iiposta(ii), ijposta(ii), zscta(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscsa(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscsa     ', &
+                    & cur_loop, h_ratio, ii, iipossa(ii), ijpossa(ii), zscsa(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrta(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrta  ', &
+                    & cur_loop, h_ratio, ii, iiposta(ii), ijposta(ii), zscerrta(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrsa(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrsa  ', &
+                    & cur_loop, h_ratio, ii, iipossa(ii), ijpossa(ii), zscerrsa(ii)
+            ENDDO
+            ! write separator
+            WRITE(numtan_sc,"(A4)") '===='
+         ENDIF
+
+      ENDIF
+
+      DEALLOCATE(                           &
+         & zun_tlin, zvn_tlin,              &
+         & zwn_tlin, ztn_tlin,              &
+         & zsn_tlin,                        &
+         & zta_tlin, zsa_tlin,              & 
+         & zta_out, zsa_out,                & 
+         & zta_wop, zsa_wop,                &
+         & z3r                              &
+         & )
+
+  END SUBROUTINE  tra_adv_cen2_tlm_tst
+#endif
+#endif
+   !!======================================================================
+END MODULE traadv_cen2_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traadv_eiv_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traadv_eiv_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traadv_eiv_tam.F90	(revision 2578)
@@ -0,0 +1,122 @@
+MODULE traadv_eiv_tam
+#if defined key_tam
+   !!======================================================================
+   !!                    ***  MODULE  traadv_eiv_tam  ***
+   !! Ocean active tracers:  advection trend - eddy induced velocity
+   !!                        Tangent and Adjoint Module
+   !!======================================================================
+   !! History of the direct module:
+   !!         9.0  !  05-11  (G. Madec)  Original code, from traldf and zdf _iso
+   !! History of the T&A module:
+   !!         9.0  !  08-11  (A. Vidard) skeleton
+   !!----------------------------------------------------------------------
+# if defined key_traldf_eiv   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_traldf_eiv'                  rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   tra_ldf_iso : update the tracer trend with the horizontal component
+   !!                 of iso neutral laplacian operator or horizontal 
+   !!                 laplacian operator in s-coordinate
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi, jpj, jpk 
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp, numout              
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_adv_eiv_tan    ! routine called by traadv_tam.F90
+   PUBLIC   tra_adv_eiv_adj    ! routine called by traadv_tam.F90
+!!   PUBLIC   tra_adv_eiv_adj_tst! routine called by traadv_tam.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldftra_substitute.h90"
+#  include "ldfeiv_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Id: traadv_eiv.F90 1152 2008-06-26 14:11:13Z rblod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_adv_eiv_tan( kt, puntl, pvntl, pwntl )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_eiv_tan  ***
+      !! 
+      !! ** Purpose of the direct routine:
+      !!      Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method of the direct routine:
+      !!      The eddy induced advection is computed from the slope
+      !!      of iso-neutral surfaces computed in routine ldf_slp as follows:
+      !!         zu_eiv =  1/(e2u e3u)   dk[ aeiu e2u mi(wslpi) ]
+      !!         zv_eiv =  1/(e1v e3v)   dk[ aeiv e1v mj(wslpj)
+      !!         zw_eiv = -1/(e1t e2t) { di[ aeiu e2u mi(wslpi) ]
+      !!                               + dj[ aeiv e1v mj(wslpj) ] }
+      !!      add the eiv component to the model velocity:
+      !!         p.n = p.n + z._eiv
+      !!
+      !! ** Action  : - add to p.n the eiv component
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt    ! ocean time-step index
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   puntl   ! in : 3 ocean velocity components 
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pvntl   ! out: 3 ocean velocity components
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pwntl   !      increased by the eiv
+      !!
+      IF (lwp) WRITE(numout,*) 'key_diaeiv not available yet in NEMOTAM'
+!!!      CALL abort
+
+   END SUBROUTINE tra_adv_eiv_tan
+   SUBROUTINE tra_adv_eiv_adj( kt, punad, pvnad, pwnad )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_eiv_adj  ***
+      !! 
+      !! ** Purpose of the direct routine:
+      !!      Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method of the direct routine:
+      !!      The eddy induced advection is computed from the slope
+      !!      of iso-neutral surfaces computed in routine ldf_slp as follows:
+      !!         zu_eiv =  1/(e2u e3u)   dk[ aeiu e2u mi(wslpi) ]
+      !!         zv_eiv =  1/(e1v e3v)   dk[ aeiv e1v mj(wslpj)
+      !!         zw_eiv = -1/(e1t e2t) { di[ aeiu e2u mi(wslpi) ]
+      !!                               + dj[ aeiv e1v mj(wslpj) ] }
+      !!      add the eiv component to the model velocity:
+      !!         p.n = p.n + z._eiv
+      !!
+      !! ** Action  : - add to p.n the eiv component
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt    ! ocean time-step index
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   punad   ! in : 3 ocean velocity components 
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pvnad   ! out: 3 ocean velocity components
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pwnad   !      increased by the eiv
+      !!
+
+   END SUBROUTINE tra_adv_eiv_adj
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :             No rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE tra_adv_eiv_tan( kt, puntl, pvntl, pwntl ) ! Empty routine
+      REAL, DIMENSION(:,:,:) ::   puntl, pvntl, pwntl
+      WRITE(*,*) 'tra_adv_eiv_tam: You should not have seen this print! error?', kt, puntl(1,1,1), pvntl(1,1,1), pwntl(1,1,1)
+   END SUBROUTINE tra_adv_eiv_tan
+   SUBROUTINE tra_adv_eiv_adj( kt, punad, pvnad, pwnad ) ! Empty routine
+      REAL, DIMENSION(:,:,:) ::   punad, pvnad, pwnad
+      WRITE(*,*) 'tra_adv_eiv_tam: You should not have seen this print! error?', kt, punad(1,1,1), pvnad(1,1,1), pwnad(1,1,1)
+   END SUBROUTINE tra_adv_eiv_adj
+# endif
+#endif
+   !!==============================================================================
+END MODULE traadv_eiv_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traadv_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traadv_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traadv_tam.F90	(revision 2578)
@@ -0,0 +1,341 @@
+MODULE traadv_tam
+#if defined key_tam
+   !!==============================================================================
+   !!                       ***  MODULE  traadv_tam  ***
+   !! Ocean active tracers:  advection trend - 
+   !!                        Tangent and Adjoint Module
+   !!==============================================================================
+   !! History of the direct routine:
+   !!            9.0  !  05-11  (G. Madec)  Original code
+   !! History of the TAM:
+   !!                 !  08-06  (A. Vidard) Skeleton
+   !!                 !  09-03  (F. Vigilant) Add tra_adv_ctl_tam routine
+   !!                                         Allow call to tra_eiv_tam/adj
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_adv      : compute ocean tracer advection trend
+   !!   tra_adv_ctl  : control the different options of advection scheme
+   !!----------------------------------------------------------------------
+   USE par_kind         , ONLY: & ! Precision variables
+      & wp
+   USE par_oce          , ONLY: & ! Ocean space and time domain variables
+      & jpi,                    &
+      & jpj,                    & 
+      & jpk   
+   USE oce_tam          , ONLY: & ! ocean dynamics and active tracers
+      & un_tl,                  &
+      & vn_tl,                  &
+      & wn_tl,                  &
+      & un_ad,                  &
+      & vn_ad,                  &
+      & wn_ad
+   USE oce              , ONLY: & ! ocean dynamics and active tracers
+      & un,                     &
+      & vn,                     &
+      & wn
+   USE ldftra_oce       , ONLY: &
+      & lk_traldf_eiv
+   USE trabbl           , ONLY: &
+      & lk_trabbl_adv 
+   USE dom_oce         ! ocean space and time domain
+   USE traadv_cen2_tam, ONLY: & ! 2nd order centered scheme (tra_adv_cen2   routine)
+      & tra_adv_cen2_tan,     &
+      & tra_adv_cen2_adj,     &
+#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  ! I/O manager
+   USE prtctl          ! Print control
+ 
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_adv_tan     ! routine called by steptan module
+   PUBLIC   tra_adv_adj     ! routine called by stepadj module
+   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
+   LOGICAL, PUBLIC ::   ln_traadv_tvd    = .FALSE.      ! TVD scheme flag
+   LOGICAL, PUBLIC ::   ln_traadv_muscl  = .FALSE.      ! MUSCL scheme flag
+   LOGICAL, PUBLIC ::   ln_traadv_muscl2 = .FALSE.      ! MUSCL2 scheme flag
+   LOGICAL, PUBLIC ::   ln_traadv_ubs    = .FALSE.      ! UBS scheme flag
+   LOGICAL, PUBLIC ::   ln_traadv_qck    = .FALSE.      ! QUICKEST scheme flag
+
+   INTEGER ::   nadv   ! choice of the type of advection scheme
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE tra_adv_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_tan  ***
+      !!
+      !! ** Purpose of the direct routine:   
+      !!              compute the ocean tracer advection trend.
+      !!
+      !! ** Method  : - Update (ua,va) with the advection term following nadv
+      !!----------------------------------------------------------------------
+#if ( defined key_trabbl_adv || defined key_traldf_eiv )
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zuntl, zvntl, zwntl   ! effective velocity
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zun, zvn, zwn         ! effective velocity
+#else
+      USE oce_tam, ONLY :                       zuntl => un_tl       ! the effective velocity is the
+      USE oce_tam, ONLY :                       zvntl => vn_tl       ! Eulerian velocity
+      USE oce_tam, ONLY :                       zwntl => wn_tl       ! 
+      USE oce, ONLY :                       zun => un       ! the effective velocity is the
+      USE oce, ONLY :                       zvn => vn       ! Eulerian velocity
+      USE oce, ONLY :                       zwn => wn       ! 
+#endif
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!----------------------------------------------------------------------
+
+
+      IF( kt == nit000 )   CALL tra_adv_ctl_tam          ! initialisation & control of options
+
+#if defined key_trabbl_adv
+      zuntl(:,:,:) = un_tl(:,:,:) - u_bbl_tl(:,:,:)          ! add the bbl velocity
+      zvntl(:,:,:) = vn_tl(:,:,:) - v_bbl_tl(:,:,:)
+      zwntl(:,:,:) = wn_tl(:,:,:) + w_bbl_tl(:,:,:)
+      zun(:,:,:) = un(:,:,:) - u_bbl(:,:,:)          ! add the bbl velocity
+      zvn(:,:,:) = vn(:,:,:) - v_bbl(:,:,:)
+      zwn(:,:,:) = wn(:,:,:) + w_bbl(:,:,:)
+#endif
+      IF( lk_traldf_eiv ) THEN                       ! commpute and add the eiv velocity
+         IF( .NOT. lk_trabbl_adv ) THEN 
+            zuntl(:,:,:) = un_tl(:,:,:)
+            zvntl(:,:,:) = vn_tl(:,:,:)
+            zwntl(:,:,:) = wn_tl(:,:,:)
+            zun(:,:,:) = un(:,:,:)
+            zvn(:,:,:) = vn(:,:,:)
+            zwn(:,:,:) = wn(:,:,:)
+         ENDIF
+         CALL tra_adv_eiv_tan( kt, zuntl, zvntl, zwntl ) 
+      ENDIF
+      IF(lwp) WRITE(numout,*) ' tra_adv_tam: 2nd order scheme is forced in TAM'
+      nadv = 1 ! force tra_adv_cen2 for tangent
+      
+      SELECT CASE ( nadv )                           ! compute advection trend and add it to general trend
+      CASE ( 1 ) ; 
+         CALL tra_adv_cen2_tan ( kt, zun, zvn, zwn, zuntl, zvntl, zwntl )    ! 2nd order centered scheme
+      END SELECT
+      !
+   END SUBROUTINE tra_adv_tan
+
+   SUBROUTINE tra_adv_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_adj  ***
+      !!
+      !! ** Purpose of the direct routine:   
+      !!              compute the ocean tracer advection trend.
+      !!
+      !! ** Method  : - Update (ua,va) with the advection term following nadv
+      !!----------------------------------------------------------------------
+#if ( defined key_trabbl_adv || defined key_traldf_eiv )
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zunad, zvnad, zwnad   ! effective velocity
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zun, zvn, zwn   ! effective velocity
+#else
+      USE oce_tam, ONLY :                   zunad => un_ad       ! the effective velocity is the
+      USE oce_tam, ONLY :                   zvnad => vn_ad       ! Eulerian velocity
+      USE oce_tam, ONLY :                   zwnad => wn_ad       ! 
+      USE oce, ONLY :                       zun => un       ! the effective velocity is the
+      USE oce, ONLY :                       zvn => vn       ! Eulerian velocity
+      USE oce, ONLY :                       zwn => wn       ! 
+#endif
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitend )   CALL tra_adv_ctl_tam
+
+#if ( defined key_trabbl_adv || defined key_traldf_eiv )
+      zunad(:,:,:) = 0.0_wp 
+      zvnad(:,:,:) = 0.0_wp
+      zwnad(:,:,:) = 0.0_wp
+#endif
+#if defined key_trabbl_adv
+      zun(:,:,:) = un(:,:,:) - u_bbl(:,:,:)          ! add the bbl velocity
+      zvn(:,:,:) = vn(:,:,:) - v_bbl(:,:,:)
+      zwn(:,:,:) = wn(:,:,:) + w_bbl(:,:,:)
+#endif
+      IF( lk_traldf_eiv ) THEN                       ! commpute and add the eiv velocity
+         IF( .NOT. lk_trabbl_adv ) THEN 
+            zun(:,:,:) = un(:,:,:)
+            zvn(:,:,:) = vn(:,:,:)
+            zwn(:,:,:) = wn(:,:,:)
+         ENDIF
+      ENDIF
+
+     IF(lwp) WRITE(numout,*) ' tra_adv_tam: 2nd order scheme is forced in TAM'
+      nadv = 1 ! force tra_adv_cen2 for adjoint
+      
+      SELECT CASE ( nadv )                           ! compute advection trend and add it to general trend
+      CASE ( 1 ) ; CALL tra_adv_cen2_adj ( kt, zun, zvn, zwn, zunad, zvnad, zwnad )    ! 2nd order centered scheme
+      END SELECT
+      !
+      IF( lk_traldf_eiv ) THEN                       ! commpute and add the eiv velocity
+         CALL tra_adv_eiv_adj( kt, zunad, zvnad, zwnad ) 
+         IF( .NOT. lk_trabbl_adv ) THEN 
+            un_ad(:,:,:) = un_ad(:,:,:) + zunad(:,:,:)
+            zunad(:,:,:) = 0.0_wp
+            vn_ad(:,:,:) = vn_ad(:,:,:) + zvnad(:,:,:)
+            zvnad(:,:,:) = 0.0_wp
+            wn_ad(:,:,:) = wn_ad(:,:,:) + zwnad(:,:,:)
+            zwnad(:,:,:) = 0.0_wp
+         ENDIF
+      ENDIF
+# if defined key_trabbl_adv
+      un_ad(:,:,:)    = un_ad(:,:,:)    + zunad(:,:,:)
+      u_bbl_ad(:,:,:) = u_bbl_ad(:,:,:) - zunad(:,:,:)
+      zunad(:,:,:) = 0.0_wp
+      vn_ad(:,:,:)    = vn_ad(:,:,:)    + zvnad(:,:,:)
+      v_bbl_ad(:,:,:) = v_bbl_ad(:,:,:) - zvnad(:,:,:)
+      zvnad(:,:,:) = 0.0_wp
+      wn_ad(:,:,:)    = wn_ad(:,:,:)    + zwnad(:,:,:)
+      w_bbl_ad(:,:,:) = w_bbl_ad(:,:,:) + zwnad(:,:,:)
+      zwnad(:,:,:) = 0.0_wp
+# endif
+   END SUBROUTINE tra_adv_adj
+SUBROUTINE tra_adv_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE example_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      CALL tra_adv_cen2_adj_tst( kumadt )
+
+   END SUBROUTINE tra_adv_adj_tst
+
+   SUBROUTINE tra_adv_ctl_tam
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_ctl_tam  ***
+      !!                
+      !! ** Purpose :   Control the consistency between namelist options for 
+      !!              tracer advection schemes and set nadv
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio
+
+      NAMELIST/nam_traadv/ ln_traadv_cen2 , ln_traadv_tvd,    &
+         &                 ln_traadv_muscl, ln_traadv_muscl2, &
+         &                 ln_traadv_ubs  , ln_traadv_qck
+      !!----------------------------------------------------------------------
+
+!      REWIND ( numnam )               ! Read Namelist nam_traadv : tracer advection scheme
+!      READ   ( numnam, nam_traadv )
+
+      IF(lwp) THEN                    ! Namelist print
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_adv_ctl : choice/control of the tracer advection scheme'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '       Namelist nam_traadv : chose a advection scheme for tracers'
+         WRITE(numout,*) '          2nd order advection scheme     ln_traadv_cen2   = ', ln_traadv_cen2
+         WRITE(numout,*) '          TVD advection scheme           ln_traadv_tvd    = ', ln_traadv_tvd
+         WRITE(numout,*) '          MUSCL  advection scheme        ln_traadv_muscl  = ', ln_traadv_muscl
+         WRITE(numout,*) '          MUSCL2 advection scheme        ln_traadv_muscl2 = ', ln_traadv_muscl2
+         WRITE(numout,*) '          UBS    advection scheme        ln_traadv_ubs    = ', ln_traadv_ubs
+         WRITE(numout,*) '          QUICKEST advection scheme      ln_traadv_qck    = ', ln_traadv_qck
+    ENDIF
+
+      ioptio = 0                      ! Parameter control
+      IF( ln_traadv_cen2   )   ioptio = ioptio + 1
+      IF( ln_traadv_tvd    )   ioptio = ioptio + 1
+      IF( ln_traadv_muscl  )   ioptio = ioptio + 1
+      IF( ln_traadv_muscl2 )   ioptio = ioptio + 1
+      IF( ln_traadv_ubs    )   ioptio = ioptio + 1
+      IF( ln_traadv_qck    )   ioptio = ioptio + 1
+      IF( lk_esopa         )   ioptio =          1
+
+      IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE advection scheme in namelist nam_traadv' )
+
+      IF( n_cla == 1 .AND. .NOT. ln_traadv_cen2 )   &
+         &                CALL ctl_stop( 'cross-land advection only with 2nd order advection scheme' )
+
+      !                              ! Set nadv
+      IF( ln_traadv_cen2   )   nadv =  1
+      IF( ln_traadv_tvd    )   nadv =  2
+      IF( ln_traadv_muscl  )   nadv =  3
+      IF( ln_traadv_muscl2 )   nadv =  4
+      IF( ln_traadv_ubs    )   nadv =  5
+      IF( ln_traadv_qck    )   nadv =  6
+      IF( lk_esopa         )   nadv = -1
+
+      IF(lwp) THEN                   ! Print the choice
+         WRITE(numout,*)
+         IF( nadv ==  1 )   WRITE(numout,*) '         2nd order scheme is used'
+         IF( nadv ==  2 )   WRITE(numout,*) '         TVD       Not Available in NEMO TAM'
+         IF( nadv ==  3 )   WRITE(numout,*) '         MUSCL     Not Available in NEMO TAM'
+         IF( nadv ==  4 )   WRITE(numout,*) '         MUSCL2    Not Available in NEMO TAM'
+         IF( nadv ==  5 )   WRITE(numout,*) '         UBS       Not Available in NEMO TAM'
+         IF( nadv ==  6 )   WRITE(numout,*) '         QUICKEST  Not Available in NEMO TAM'
+         IF( nadv == -1 )   WRITE(numout,*) '         esopa test: Not Available in NEMO TAM'
+      ENDIF
+      !
+   END SUBROUTINE tra_adv_ctl_tam
+#if defined key_tst_tlm
+SUBROUTINE tra_adv_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tra_adv_tlm_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 
+      !!                   
+      !! History :
+      !!        ! 09-08 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      CALL tra_adv_cen2_tlm_tst( kumadt )
+
+   END SUBROUTINE tra_adv_tlm_tst
+#endif
+#endif
+
+
+  !!======================================================================
+END MODULE traadv_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trabbc_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trabbc_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trabbc_tam.F90	(revision 2578)
@@ -0,0 +1,132 @@
+MODULE trabbc_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                       ***  MODULE  trabbc_tam  ***
+   !! Ocean active tracers:  bottom boundary condition. 
+   !!                        Tangent and Adjoint Module
+   !!==============================================================================
+   !! History of the direct module:
+   !!            8.1  ! 99-10 (G. Madec)  original code
+   !!            8.5  ! 02-08 (G. Madec)  free form + modules
+   !!            8.5  ! 02-11 (A. Bozec)  tra_bbc_init: original code
+   !! History of the TAM:
+   !!                 ! 08-05 (A. Vidard) Skeleton
+   !!----------------------------------------------------------------------
+#if   defined key_trabbc 
+   !!----------------------------------------------------------------------
+   !!   'key_trabbc'                                  geothermal heat flux
+   !!----------------------------------------------------------------------
+   !!   tra_bbc      : update the tracer trend at ocean bottom 
+   !!   tra_bbc_init : initialization of geothermal heat flux trend
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE in_out_manager, ONLY: &  ! I/O manager
+      & lwp,                 &
+      & wp
+   USE trabbc        , ONLY: &  ! bottom boundary condition
+      & lk_trabbc
+   USE tstool_tam    , ONLY: &
+      & prntst_adj
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC tra_bbc_tan          ! routine called by step_tam.F90
+   PUBLIC tra_bbc_adj          ! routine called by step_tam.F90
+   PUBLIC tra_bbc_adj_tst      ! routine called by tst.F90 
+
+CONTAINS
+
+   SUBROUTINE tra_bbc_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_bbc_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Compute the bottom boundary contition on temperature 
+      !!      associated with geothermal heating and add it to the general
+      !!      trend of temperature equations.
+      !!
+      !! ** Method  :   The geothermal heat flux set to its constant value of 
+      !!       86.4 mW/m2 (Stein and Stein 1992, Huang 1999).
+      !!       The temperature trend associated to this heat flux through the
+      !!       ocean bottom can be computed once and is added to the temperature
+      !!       trend juste above the bottom at each time step:
+      !!            ta = ta + Qsf / (rau0 rcp e3T) for k= mbathy -1
+      !!       Where Qsf is the geothermal heat flux.
+      !!
+      !! ** Action  : - update the temperature trends (ta) with the trend of
+      !!                the ocean bottom boundary condition
+      !!
+      !! References : Stein, C. A., and S. Stein, 1992, Nature, 359, 123-129.
+      !!              Emile-Geay and Madec, 2009, Ocean Science.
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!----------------------------------------------------------------------
+      ! .... nothing to do
+      !
+   END SUBROUTINE tra_bbc_tan
+   SUBROUTINE tra_bbc_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_bbc_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Compute the bottom boundary contition on temperature 
+      !!      associated with geothermal heating and add it to the general
+      !!      trend of temperature equations.
+      !!
+      !! ** Method  :   The geothermal heat flux set to its constant value of 
+      !!       86.4 mW/m2 (Stein and Stein 1992, Huang 1999).
+      !!       The temperature trend associated to this heat flux through the
+      !!       ocean bottom can be computed once and is added to the temperature
+      !!       trend juste above the bottom at each time step:
+      !!            ta = ta + Qsf / (rau0 rcp e3T) for k= mbathy -1
+      !!       Where Qsf is the geothermal heat flux.
+      !!
+      !! ** Action  : - update the temperature trends (ta) with the trend of
+      !!                the ocean bottom boundary condition
+      !!
+      !! References : Stein, C. A., and S. Stein, 1992, Nature, 359, 123-129.
+      !!              Emile-Geay and Madec, 2009, Ocean Science.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!----------------------------------------------------------------------
+      ! .... nothing to do
+      !!
+   END SUBROUTINE tra_bbc_adj
+   SUBROUTINE tra_bbc_adj_tst( kumadt )           ! Dummy routine
+      INTEGER, INTENT( in ) ::   kumadt
+      REAL(KIND=wp) ::     &
+         & zsp1,           & ! scalar product involving the tangent routine
+         & zsp2              ! scalar product involving the adjoint routine
+      CHARACTER(LEN=14) :: &
+         & cl_name
+         
+      zsp1 = 0.0_wp
+      
+      zsp2 = 0.0_wp
+
+      ! 14 char:'12345678901234'
+      cl_name = 'tra_bbc_adj   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+      
+   END SUBROUTINE tra_bbc_adj_tst
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE tra_bbc_tan( kt )           ! Empty routine
+      WRITE(*,*) 'tra_bbc_tan: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_bbc_tan
+   SUBROUTINE tra_bbc_adj( kt )           ! Empty routine
+      WRITE(*,*) 'tra_bbc_adj: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_bbc_adj
+   SUBROUTINE tra_bbc_adj_tst( kt )           ! Empty routine
+      WRITE(*,*) 'tra_bbc_adj_tst: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_bbc_adj_tst
+#endif
+
+   !!======================================================================
+#endif
+END MODULE trabbc_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/tradmp_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/tradmp_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/tradmp_tam.F90	(revision 2578)
@@ -0,0 +1,771 @@
+MODULE tradmp_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  tradmp_tam  ***
+   !! Ocean physics: internal restoring trend on active tracers (T and S)
+   !!                Tangent and Adjoint Module
+   !!======================================================================
+   !! History of the direct module:
+   !!            OPA  ! 1991-03  (O. Marti, G. Madec)  Original code
+   !!                 ! 1992-06  (M. Imbard)  doctor norme
+   !!                 ! 1996-01  (G. Madec)  statement function for e3
+   !!                 ! 1997-05  (G. Madec)  macro-tasked on jk-slab
+   !!                 ! 1998-07  (M. Imbard, G. Madec) ORCA version
+   !!            7.0  ! 2001-02  (M. Imbard)  cofdis, Original code
+   !!            8.1  ! 2001-02  (G. Madec, E. Durand)  cleaning
+   !!  NEMO      1.0  ! 2002-08  (G. Madec, E. Durand)  free form + modules
+   !!                 ! 2003-08  (M. Balmaseda)  mods to allow eq. damping
+   !!            3.2  ! 2009-08  (G. Madec, C. Talandier)  DOCTOR norm for namelist parameter
+   !! History of the TAM:
+   !!                 ! 2008-09  (A. Vidard) tangent and adjoint module 
+   !!                                       of the 03-08 version
+   !!        NEMO 3.2 ! 2010-04 (F. Vigilant) 3.2 version   
+   !!----------------------------------------------------------------------
+#if   defined key_tradmp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   key_tradmp                                         internal damping
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   tra_dmp      : update the tracer trend with the internal damping
+   !!   tra_dmp_init : initialization, namlist read, parameters control
+   !!   dtacof_zoom  : restoring coefficient for zoom domain
+   !!   dtacof       : restoring coefficient for global domain
+   !!   cofdis       : compute the distance to the coastline
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1,               &
+      & jpiglo,              &
+      & jpjglo,              &
+      & jpizoom,             &
+      & jpjzoom
+   USE oce_tam       , ONLY: & ! ocean dynamics and tracers variables
+      & tb_tl,               &
+      & sb_tl,               &
+      & ta_tl,               &
+      & sa_tl,               &
+      & tb_ad,               &
+      & sb_ad,               &
+      & ta_ad,               &
+      & sa_ad      
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & lzoom,               & 
+      & lzoom_e,             &  
+      & lzoom_w,             &  
+      & lzoom_s,             &  
+      & lzoom_n,             &  
+      & lzoom_arct,          & 
+      & lzoom_anta,          &
+      & nperio,              &
+      & rdt,                 &
+      & mi0,                 &
+      & mj0,                 &
+      & mi1,                 &
+      & mj1,                 &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      & e1t,                 &
+      & e2t,                 &
+#if defined key_zco
+      & e3t_0,               &
+      & gdept_0,             &
+#else
+      & e3t,                 &
+      & gdept,               &
+#endif
+      & gdept_0,             &
+      & umask,               &
+      & vmask,               &
+      & tmask,               &
+      & fmask,               &
+      & gphiu,               &
+      & glamu,               &
+      & gphiv,               &
+      & glamv,               &
+      & gphit,               &
+      & glamt,               &
+      & gphif,               &
+      & glamf
+   USE zdf_oce, ONLY: &! ocean vertical physics
+      & avt
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & ctl_stop,            &
+      & lwp,                 &
+      & numout,              & 
+      & numnam,              & 
+      & ctmp1,               & 
+      & nit000,              &
+      & nitend
+   USE phycst        , ONLY: & ! Define parameters for the routines
+      & rday,                & 
+      & rpi,                 &
+      & ra,                  &
+      & rad
+   USE lib_mpp       , ONLY: & ! distributed memory computing
+      & lk_mpp
+   USE tradmp        , ONLY : &
+      & dtacof_zoom, dtacof,  &
+      & cofdis
+   USE prtctl        , ONLY: & ! Print control
+      & prt_ctl
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE dtatem        , ONLY: & ! temperature data
+      & lk_dtatem
+   USE dtasal        , ONLY: & ! salinity data
+      & lk_dtasal
+   USE zdfmxl        , ONLY: & ! mixed layer depth
+      & hmlp
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          & !
+      & stdt,                & ! stdev for temperature
+      & stds                   !           salinity
+   USE paresp        , ONLY: &
+      & wesp_t,              &
+      & wesp_s
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC tra_dmp_tan      ! routine called by step_tam.F90
+   PUBLIC tra_dmp_adj      ! routine called by step_tam.F90
+   PUBLIC tra_dmp_adj_tst  ! routine called by tst.F90
+#if ! defined key_agrif
+   LOGICAL, PUBLIC, PARAMETER ::   lk_tradmp = .TRUE.     !: internal damping flag
+#else
+   LOGICAL, PUBLIC            ::   lk_tradmp = .TRUE.     !: internal damping flag
+#endif
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) :: &
+     & strdmp_tl,   & !: damping salinity trend (psu/s)
+     & ttrdmp_tl,   & !: damping temperature trend (psu/s)
+     & ttrdmp_ad,   & !: damping temperature trend (psu/s)
+     & strdmp_ad,   & !: damping salinity trend (psu/s)
+     & resto          !: restoring coeff. on T and S (s-1)
+   
+   
+   LOGICAL :: lfirst = .TRUE.     !: flag for initialisation
+   !                             !!* Namelist namtra_dmp : T & S newtonian damping *
+   INTEGER  ::   nn_hdmp =   -1   ! = 0/-1/'latitude' for damping over T and S
+   INTEGER  ::   nn_zdmp =    0   ! = 0/1/2 flag for damping in the mixed layer
+   REAL(wp) ::   rn_surf =   50.  ! surface time scale for internal damping        [days]
+   REAL(wp) ::   rn_bot  =  360.  ! bottom time scale for internal damping         [days]
+   REAL(wp) ::   rn_dep  =  800.  ! depth of transition between rn_surf and rn_bot [meters]
+   INTEGER  ::   nn_file =    2   ! = 1 create a damping.coeff NetCDF file 
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+
+CONTAINS
+
+   SUBROUTINE tra_dmp_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tra_dmp_tan  ***
+      !!                  
+      !! ** Purpose of direct routine:
+      !!      Compute the tracer trend due to a newtonian damping
+      !!      of the tracer field towards given data field and add it to the
+      !!      general tracer trends.
+      !!
+      !! ** Method  :   Newtonian damping towards t_dta and s_dta computed 
+      !!      and add to the general tracer trends:
+      !!                     ta = ta + resto * (t_dta - tb)
+      !!                     sa = sa + resto * (s_dta - sb)
+      !!         The trend is computed either throughout the water column
+      !!      (nlmdmp=0) or in area of weak vertical mixing (nlmdmp=1) or
+      !!      below the well mixed layer (nlmdmp=2)
+      !!
+      !! ** Action  : - (ta,sa)   tracer trends updated with the damping trend 
+      !!
+      !! ASSUME key_zdfcst_tam
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk            ! dummy loop indices
+      REAL(wp) ::   ztest, ztatl, zsatl       ! temporary scalars
+      !!----------------------------------------------------------------------
+      IF( kt == nit000 )   CALL tra_dmp_init_tam  ! Initialization
+
+      ! 1. Newtonian damping trends on tracer fields
+      ! --------------------------------------------
+      !    compute the newtonian damping trends depending on nmldmp
+
+      SELECT CASE ( nn_zdmp )
+      !
+      CASE( 0 )                ! newtonian damping throughout the water column
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ztatl = - resto(ji,jj,jk) *  tb_tl(ji,jj,jk) 
+                  zsatl = - resto(ji,jj,jk) *  sb_tl(ji,jj,jk) 
+                  ! add the trends to the general tracer trends
+                  ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) + ztatl
+                  sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) + zsatl
+                  ! save the salinity trend (used in flx to close the salt budget)
+                  strdmp_tl(ji,jj,jk) = zsatl
+                  ttrdmp_tl(ji,jj,jk) = ztatl
+               END DO
+            END DO
+         END DO
+         !
+      CASE ( 1 )                ! no damping in the turbocline (avt > 5 cm2/s)
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ztest = avt(ji,jj,jk) - 5.e-4
+      !! ASSUME key_zdfcst_tam
+                  IF( ztest < 0. ) THEN
+                     ztatl = - resto(ji,jj,jk) * tb_tl(ji,jj,jk) 
+                     zsatl = - resto(ji,jj,jk) * sb_tl(ji,jj,jk)
+                  ELSE
+                     ztatl = 0.0_wp
+                     zsatl = 0.0_wp
+                  ENDIF
+                  ! add the trends to the general tracer trends
+                  ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) + ztatl
+                  sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) + zsatl
+                  ! save the salinity trend (used in flx to close the salt budget)
+                  strdmp_tl(ji,jj,jk) = zsatl
+                  ttrdmp_tl(ji,jj,jk) = ztatl
+               END DO
+            END DO
+         END DO
+         !
+      CASE ( 2 )                ! no damping in the mixed layer  
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  IF( fsdept(ji,jj,jk) >= hmlp (ji,jj) ) THEN
+                     ztatl = - resto(ji,jj,jk) * tb_tl(ji,jj,jk)
+                     zsatl = - resto(ji,jj,jk) * sb_tl(ji,jj,jk)
+                  ELSE
+                     ztatl = 0.e0
+                     zsatl = 0.e0
+                  ENDIF
+                  ! add the trends to the general tracer trends
+                  ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) + ztatl
+                  sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) + zsatl
+                  ! save the salinity trend (used in flx to close the salt budget)
+                  strdmp_tl(ji,jj,jk) = zsatl
+                  ttrdmp_tl(ji,jj,jk) = ztatl
+               END DO
+            END DO
+         END DO
+         !
+      END SELECT
+
+   END SUBROUTINE tra_dmp_tan
+   SUBROUTINE tra_dmp_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tra_dmp_adj  ***
+      !!                  
+      !! ** Purpose of direct routine:
+      !!      Compute the tracer trend due to a newtonian damping
+      !!      of the tracer field towards given data field and add it to the
+      !!      general tracer trends.
+      !!
+      !! ** Method  :   Newtonian damping towards t_dta and s_dta computed 
+      !!      and add to the general tracer trends:
+      !!                     ta = ta + resto * (t_dta - tb)
+      !!                     sa = sa + resto * (s_dta - sb)
+      !!         The trend is computed either throughout the water column
+      !!      (nlmdmp=0) or in area of weak vertical mixing (nlmdmp=1) or
+      !!      below the well mixed layer (nlmdmp=2)
+      !!
+      !! ** Action  : - (ta,sa)   tracer trends updated with the damping trend 
+      !!              - save the trends in (ttrd,strd) ('key_trdtra')
+      !! ASSUME key_zdfcst_tam
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk            ! dummy loop indices
+      REAL(wp) ::   ztest, ztaad, zsaad       ! temporary scalars
+      !!----------------------------------------------------------------------
+      IF( kt == nitend )   CALL tra_dmp_init_tam  ! Initialization
+
+      ! 1. Newtonian damping trends on tracer fields
+      ! --------------------------------------------
+      !    compute the newtonian damping trends depending on nmldmp
+      ztaad = 0.0_wp
+      zsaad = 0.0_wp
+
+      SELECT CASE ( nn_zdmp )
+      !
+      CASE( 0 )                ! newtonian damping throughout the water column
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! save the salinity trend (used in flx to close the salt budget)
+                  ztaad = ztaad + ttrdmp_ad(ji,jj,jk) 
+                  ttrdmp_ad(ji,jj,jk) = 0.0_wp
+                  zsaad = zsaad + strdmp_ad(ji,jj,jk) 
+                  strdmp_ad(ji,jj,jk) = 0.0_wp
+                  ! add the trends to the general tracer trends
+                  ztaad = ta_ad(ji,jj,jk) + ztaad
+                  zsaad = sa_ad(ji,jj,jk) + zsaad
+
+                  tb_ad(ji,jj,jk)  = tb_ad(ji,jj,jk) - ztaad * resto(ji,jj,jk)
+                  sb_ad(ji,jj,jk)  = sb_ad(ji,jj,jk) - zsaad * resto(ji,jj,jk)
+                  ztaad = 0.0_wp
+                  zsaad = 0.0_wp
+                END DO
+            END DO
+         END DO
+         !
+      CASE ( 1 )                ! no damping in the turbocline (avt > 5 cm2/s)
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! save the salinity trend (used in flx to close the salt budget)
+                  ztaad = ztaad + ttrdmp_ad(ji,jj,jk) 
+                  ttrdmp_ad(ji,jj,jk) = 0.0_wp
+                  zsaad = zsaad + strdmp_ad(ji,jj,jk) 
+                  strdmp_ad(ji,jj,jk) = 0.0_wp
+                  ! add the trends to the general tracer trends
+                  ztaad = ta_ad(ji,jj,jk) + ztaad
+                  zsaad = sa_ad(ji,jj,jk) + zsaad
+                  ztest = avt(ji,jj,jk) - 5.e-4
+      !! ASSUME key_zdfcst_tam
+                  IF( ztest < 0. ) THEN
+                     tb_ad(ji,jj,jk)  = tb_ad(ji,jj,jk) - ztaad * resto(ji,jj,jk)
+                     sb_ad(ji,jj,jk)  = sb_ad(ji,jj,jk) - zsaad * resto(ji,jj,jk)
+                     ztaad = 0.0_wp
+                     zsaad = 0.0_wp
+                  ELSE
+                     ztaad = 0.0_wp
+                     zsaad = 0.0_wp
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         !
+      CASE ( 2 )                ! no damping in the mixed layer 
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! save the salinity trend (used in flx to close the salt budget)
+                  ztaad = ztaad + ttrdmp_ad(ji,jj,jk) 
+                  ttrdmp_ad(ji,jj,jk) = 0.0_wp
+                  zsaad = zsaad + strdmp_ad(ji,jj,jk) 
+                  strdmp_ad(ji,jj,jk) = 0.0_wp
+                  ! add the trends to the general tracer trends
+                  ztaad = ta_ad(ji,jj,jk) + ztaad
+                  zsaad = sa_ad(ji,jj,jk) + zsaad
+                  IF( fsdept(ji,jj,jk) >= hmlp (ji,jj) ) THEN
+                     tb_ad(ji,jj,jk)  = tb_ad(ji,jj,jk) - ztaad * resto(ji,jj,jk)
+                     sb_ad(ji,jj,jk)  = sb_ad(ji,jj,jk) - zsaad * resto(ji,jj,jk)
+                     ztaad = 0.0_wp
+                     zsaad = 0.0_wp
+                  ELSE
+                     ztaad = 0.0_wp
+                     zsaad = 0.0_wp
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         !
+      END SELECT
+
+
+   END SUBROUTINE tra_dmp_adj
+   SUBROUTINE tra_dmp_init_tam
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_dmp_init_tam  ***
+      !! 
+      !! ** Purpose :   Initialization for the newtonian damping 
+      !!
+      !! ** Method  :   read the nammbf namelist and check the parameters
+      !!      called by tra_dmp at the first timestep (nit000)
+      !!----------------------------------------------------------------------
+
+      NAMELIST/namtra_dmp/ nn_hdmp, nn_file, nn_zdmp, rn_surf, rn_bot, rn_dep
+      !!----------------------------------------------------------------------
+
+      IF (lfirst) THEN
+
+         REWIND ( numnam )                  ! Read Namelist namtdp : temperature and salinity damping term
+         READ   ( numnam, namtra_dmp )
+         IF( lzoom )   nn_zdmp = 0           ! restoring to climatology at closed north or south boundaries
+         
+         IF(lwp) THEN                       ! Namelist print
+            WRITE(numout,*)
+            WRITE(numout,*) 'tra_dmp_tam : T and S newtonian damping'
+            WRITE(numout,*) '~~~~~~~~~~~'
+            WRITE(numout,*) '      Namelist namtra_dmp : set damping parameter'
+            WRITE(numout,*) '      T and S damping option         nn_hdmp = ', nn_hdmp
+            WRITE(numout,*) '      mixed layer damping option     nn_zdmp = ', nn_zdmp, '(zoom: forced to 0)'
+            WRITE(numout,*) '      surface time scale (days)      rn_surf = ', rn_surf
+            WRITE(numout,*) '      bottom time scale (days)       rn_bot  = ', rn_bot
+            WRITE(numout,*) '      depth of transition (meters)   rn_dep  = ', rn_dep
+            WRITE(numout,*) '      create a damping.coeff file    nn_file = ', nn_file
+         ENDIF
+         
+         !! ** modified to allow damping at the equator
+         
+         SELECT CASE ( nn_hdmp )
+         CASE (  -1  )   ;   IF(lwp) WRITE(numout,*) '   tracer damping in the Med & Red seas only'
+         CASE ( 0:90 )   ;   IF(lwp) WRITE(numout,*) '   tracer damping poleward of', nn_hdmp, ' degrees'
+         CASE DEFAULT
+            IF(lwp) WRITE(numout,*) '          tracer damping disabled', nn_hdmp
+            !         WRITE(ctmp1,*) '          bad flag value for ndmp = ', ndmp
+            !         CALL ctl_stop(ctmp1)
+         END SELECT
+         
+         SELECT CASE ( nn_zdmp )
+         CASE ( 0 )   ;   IF(lwp) WRITE(numout,*) '   tracer damping throughout the water column'
+         CASE ( 1 )   ;   IF(lwp) WRITE(numout,*) '   no tracer damping in the turbocline (avt > 5 cm2/s)'
+         CASE ( 2 )   ;   IF(lwp) WRITE(numout,*) '   no tracer damping in the mixed layer'
+         CASE DEFAULT
+            WRITE(ctmp1,*) '   bad flag value for nn_zdmp = ', nn_zdmp
+            CALL ctl_stop(ctmp1)
+         END SELECT
+         
+         IF( .NOT.lk_dtasal .OR. .NOT.lk_dtatem )   &
+            &   CALL ctl_stop( 'no temperature and/or salinity data define key_dtatem and key_dtasal' )
+         
+         !                          ! Damping coefficients initialization
+         IF( lzoom ) THEN   ;   CALL dtacof_zoom
+         ELSE               ;   CALL dtacof
+         ENDIF
+         !
+         lfirst = .FALSE.
+      END IF
+      ttrdmp_tl(:,:,:) = 0.0_wp       ! internal damping salinity trend (used in ocesbc)
+      ttrdmp_ad(:,:,:) = 0.0_wp       ! internal damping salinity trend (used in ocesbc)
+      strdmp_tl(:,:,:) = 0.0_wp       ! internal damping salinity trend (used in ocesbc)
+      strdmp_ad(:,:,:) = 0.0_wp       ! internal damping salinity trend (used in ocesbc)
+   END SUBROUTINE tra_dmp_init_tam
+
+   SUBROUTINE tra_dmp_adj_tst ( kumadt ) 
+      !!-----------------------------------------------------------------------
+      !!
+      !!          ***  ROUTINE tra_sbc_adj_tst : TEST OF tra_sbc_adj  ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+       !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      INTEGER ::  &
+         & istp,  &
+         & jstp,  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zsb_tlin,     &! Tangent input : before salinity
+         & ztb_tlin,     &! Tangent input : before temperature
+         & zsa_tlin,     &! Tangent input : after salinity
+         & zta_tlin,     &! Tangent input : after temperature
+         & zsa_tlout,    &! Tangent output: after salinity
+         & zta_tlout,    &! Tangent output: after temperature
+         & zstrdmp_tlout,&! Tangent output: salinity trend
+         & zttrdmp_tlout,&! Tangent output: temperature trend
+         & zsb_adout,    &! Adjoint output : before salinity
+         & ztb_adout,    &! Adjoint output : before temperature
+         & zsa_adout,    &! Adjoint output : after salinity
+         & zta_adout,    &! Adjoint output : after temperature
+         & zsa_adin,     &! Adjoint input : after salinity
+         & zta_adin,     &! Adjoint input : after temperature
+         & zstrdmp_adin, &! Adjoint input : salinity trend
+         & zttrdmp_adin, &! Tangent output: temperature trend
+         & z3r            ! 3D field
+         
+      REAL(KIND=wp) ::       &
+         & zsp1,             & ! scalar product involving the tangent routine
+         & zsp1_1,           & ! scalar product involving the tangent routine
+         & zsp1_2,           & ! scalar product involving the tangent routine
+         & zsp1_3,           & ! scalar product involving the tangent routine
+         & zsp1_4,           & ! scalar product involving the tangent routine
+         & zsp2,             & ! scalar product involving the adjoint routine
+         & zsp2_1,           & ! scalar product involving the adjoint routine
+         & zsp2_2,           & ! scalar product involving the adjoint routine
+         & zsp2_3,           & ! scalar product involving the adjoint routine
+         & zsp2_4              ! scalar product involving the adjoint routine
+      CHARACTER(LEN=14) ::   &
+         & cl_name
+
+      ALLOCATE( & 
+         & ztb_tlin(jpi,jpj,jpk),     &
+         & zsb_tlin(jpi,jpj,jpk),     &
+         & zsa_tlin(jpi,jpj,jpk),     &
+         & zta_tlin(jpi,jpj,jpk),     &
+         & zsa_tlout(jpi,jpj,jpk),    &
+         & zta_tlout(jpi,jpj,jpk),    &
+         & zstrdmp_tlout(jpi,jpj,jpk),&
+         & zttrdmp_tlout(jpi,jpj,jpk),&
+         & ztb_adout(jpi,jpj,jpk),    &
+         & zsb_adout(jpi,jpj,jpk),    &
+         & zsa_adout(jpi,jpj,jpk),    &
+         & zta_adout(jpi,jpj,jpk),    &
+         & zsa_adin(jpi,jpj,jpk),     &
+         & zta_adin(jpi,jpj,jpk),     &
+         & zttrdmp_adin(jpi,jpj,jpk), &
+         & zstrdmp_adin(jpi,jpj,jpk), &
+         & z3r         (jpi,jpj,jpk)  &
+         & )
+      ! Test for time steps nit000 and nit000 + 1 (the matrix changes)
+
+      DO jstp = nit000, nit000 + 2
+         istp = jstp
+         IF ( jstp == nit000 +2 ) istp = nitend
+
+      ! Initialize the reference state
+      avt(:,:,:) = 1.e-1
+      !=============================================================
+      ! 1) dx = ( T ) and dy = ( T )
+      !=============================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      zsb_tlin(:,:,:)      = 0.0_wp 
+      ztb_tlin(:,:,:)      = 0.0_wp 
+      zsa_tlin(:,:,:)      = 0.0_wp 
+      zta_tlin(:,:,:)      = 0.0_wp 
+      zsa_tlout(:,:,:)     = 0.0_wp 
+      zta_tlout(:,:,:)     = 0.0_wp 
+      zstrdmp_tlout(:,:,:) = 0.0_wp
+      zttrdmp_tlout(:,:,:) = 0.0_wp 
+      zsb_adout(:,:,:)     = 0.0_wp 
+      ztb_adout(:,:,:)     = 0.0_wp 
+      zsa_adout(:,:,:)     = 0.0_wp 
+      zta_adout(:,:,:)     = 0.0_wp 
+      zsa_adin(:,:,:)      = 0.0_wp 
+      zta_adin(:,:,:)      = 0.0_wp 
+      zstrdmp_adin(:,:,:)  = 0.0_wp 
+      zttrdmp_adin(:,:,:)  = 0.0_wp
+
+      sa_ad(:,:,:)      = 0.0_wp 
+      sb_ad(:,:,:)      = 0.0_wp 
+      ta_ad(:,:,:)      = 0.0_wp 
+      tb_ad(:,:,:)      = 0.0_wp 
+      strdmp_ad(:,:,:)  = 0.0_wp
+      ttrdmp_ad(:,:,:)  = 0.0_wp 
+      sa_tl(:,:,:)      = 0.0_wp 
+      sb_tl(:,:,:)      = 0.0_wp 
+      ta_tl(:,:,:)      = 0.0_wp 
+      tb_tl(:,:,:)      = 0.0_wp 
+      strdmp_tl(:,:,:)  = 0.0_wp
+      ttrdmp_tl(:,:,:)  = 0.0_wp 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 785483 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stds )
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zsb_tlin(ji,jj,jk) = z3r(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 358606 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               ztb_tlin(ji,jj,jk) = z3r(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stds )
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zsa_tlin(ji,jj,jk) = z3r(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 523432 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zta_tlin(ji,jj,jk) = z3r(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      sb_tl(:,:,:) = zsb_tlin(:,:,:) 
+      tb_tl(:,:,:) = ztb_tlin(:,:,:) 
+      sa_tl(:,:,:) = zsa_tlin(:,:,:) 
+      ta_tl(:,:,:) = zta_tlin(:,:,:)
+     
+      CALL tra_dmp_tan( istp )
+
+      zsa_tlout(:,:,:)     = sa_tl(:,:,:) 
+      zta_tlout(:,:,:)     = ta_tl(:,:,:)
+      zstrdmp_tlout(:,:,:) = strdmp_tl(:,:,:)
+      zttrdmp_tlout(:,:,:) = ttrdmp_tl(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsa_adin(ji,jj,jk)     = zsa_tlout(ji,jj,jk) &
+                 &                   * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &                   * tmask(ji,jj,jk) * wesp_s(jk)
+              zta_adin(ji,jj,jk)     = zta_tlout(ji,jj,jk) &
+                 &                   * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &                   * tmask(ji,jj,jk) * wesp_t(jk)
+              zstrdmp_adin(ji,jj,jk) = zstrdmp_tlout(ji,jj,jk) &
+                 &                   * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &                   * tmask(ji,jj,jk) * wesp_s(jk)
+              zttrdmp_adin(ji,jj,jk) = zttrdmp_tlout(ji,jj,jk) &                 
+                 &                   * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &                   * tmask(ji,jj,jk) * wesp_t(jk)
+            END DO
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1_1 = DOT_PRODUCT( zsa_tlout    , zsa_adin     )
+      zsp1_2 = DOT_PRODUCT( zta_tlout    , zta_adin     )
+      zsp1_3 = DOT_PRODUCT( zstrdmp_tlout, zstrdmp_adin )
+      zsp1_4 = DOT_PRODUCT( zttrdmp_tlout, zttrdmp_adin ) 
+      zsp1   = zsp1_1 + zsp1_2 + zsp1_3 + zsp1_4
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      sa_ad(:,:,:)     = zsa_adin(:,:,:)
+      ta_ad(:,:,:)     = zta_adin(:,:,:)
+      strdmp_ad(:,:,:) = zstrdmp_adin(:,:,:)
+      ttrdmp_ad(:,:,:) = zttrdmp_adin(:,:,:)
+
+      CALL tra_dmp_adj( istp )
+
+      zsb_adout(:,:,:) = sb_ad(:,:,:)
+      ztb_adout(:,:,:) = tb_ad(:,:,:)
+      zsa_adout(:,:,:) = sa_ad(:,:,:)
+      zta_adout(:,:,:) = ta_ad(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: dx^T L^T W dy
+      !--------------------------------------------------------------------
+
+      zsp2_1 = DOT_PRODUCT( zsb_tlin  , zsb_adout   )
+      zsp2_2 = DOT_PRODUCT( ztb_tlin  , ztb_adout   )
+      zsp2_3 = DOT_PRODUCT( zsa_tlin  , zsa_adout   )
+      zsp2_4 = DOT_PRODUCT( zta_tlin  , zta_adout   )
+
+      zsp2 = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4
+
+      ! Compare the scalar products
+
+      ! 14 char:'12345678901234'
+      IF ( istp == nit000 ) THEN
+         cl_name = 'tra_dmp_adj T1'
+      ELSEIF ( istp == nit000 +1 ) THEN
+         cl_name = 'tra_dmp_adj T2'
+      ELSEIF ( istp == nitend ) THEN
+         cl_name = 'tra_dmp_adj T3'
+      END IF
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      END DO
+
+      DEALLOCATE( & 
+         & zsb_tlin,     &
+         & ztb_tlin,     &
+         & zsa_tlin,     &
+         & zta_tlin,     &
+         & zsa_tlout,    &
+         & zta_tlout,    &
+         & zstrdmp_tlout,&
+         & zttrdmp_tlout,&
+         & zsb_adout,    &
+         & ztb_adout,    &
+         & zsa_adout,    &
+         & zta_adout,    &
+         & zsa_adin,     &
+         & zta_adin,     &
+         & zstrdmp_adin, &
+         & zttrdmp_adin, &
+         & z3r           &
+         & )
+
+   END SUBROUTINE tra_dmp_adj_tst
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default key                                     NO internal damping
+   !!----------------------------------------------------------------------
+   LOGICAL , PUBLIC, PARAMETER ::   lk_tradmp = .FALSE.    !: internal damping flag
+CONTAINS
+   SUBROUTINE tra_dmp_tan( kt )        ! Empty routine
+      WRITE(*,*) 'tra_dmp_tan: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_dmp_tan
+   SUBROUTINE tra_dmp_adj( kt )        ! Empty routine
+      WRITE(*,*) 'tra_dmp_adj: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_dmp_adj
+   SUBROUTINE tra_dmp_adj_tst( kt )        ! Empty routine
+      WRITE(*,*) 'tra_dmp_adj_tst: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_dmp_adj_tst
+#endif
+
+   !!======================================================================
+#endif
+END MODULE tradmp_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traldf_bilap_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traldf_bilap_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traldf_bilap_tam.F90	(revision 2578)
@@ -0,0 +1,883 @@
+MODULE traldf_bilap_tam
+#ifdef key_tam
+   !!===========================================================================
+   !!                       ***  MODULE  dynldf_bilap_tam  ***
+   !! Ocean dynamics:  lateral viscosity trend
+   !!                  tangent and Adjoint Module
+   !!===========================================================================
+
+   !!---------------------------------------------------------------------------
+   !!   dyn_ldf_bilap_tan : update the momentum trend with the lateral diffusion
+   !!                       using an iso-level bilaplacian operator (tangent)
+   !!   dyn_ldf_bilap_adj : update the momentum trend with the lateral diffusion
+   !!                       using an iso-level bilaplacian operator (adjoint)
+   !!---------------------------------------------------------------------------
+
+	!! * Modules used
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE lbclnk        , ONLY: & ! Boundary/halo exchange
+      & lbc_lnk
+   USE lbclnk_tam    , ONLY: & ! Boundary/halo exchange (adjoint)
+      & lbc_lnk_adj
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpiglo,              &
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1
+   USE oce_tam       , ONLY: & ! ocean dynamics and active tracers
+      & tb_tl,               &
+      & sb_tl,               &
+      & ta_tl,               &
+      & sa_tl,               &
+      & gtu_tl,              &
+      & gsu_tl,              &
+      & gtv_tl,              &
+      & gsv_tl,              &
+      & tb_ad,               &
+      & sb_ad,               &
+      & ta_ad,               &
+      & sa_ad,               &
+      & gtu_ad,              &
+      & gsu_ad,              &
+      & gtv_ad,              &
+      & gsv_ad
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & lk_zco,              &
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+      & e1t,                 &
+      & e2t,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3u,                 &
+      & e3v,                 &
+      & e3t,                 &
+#endif
+      & tmask,               &
+      & umask,               &
+      & vmask,               &
+      & mbathy,              &
+      & ln_zps,              &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      & lk_vvl
+   USE ldftra_oce    , ONLY: & ! ocean active tracers: lateral physics
+      & ahtv,                &
+      & ahtu,                &
+      & ahtw,                &
+      & ahtb0,               &
+      & aht0,                &
+      & ahtt
+!   USE trdmod          ! ocean active tracers trends 
+!   USE trdmod_oce      ! ocean variables trends
+   USE in_out_manager, ONLY: & ! I/O manager
+      & lwp,                 &
+      & numout,              &
+      & nitend,              &
+      & nit000,              &
+      & nstop
+!   USE diaptr          ! poleward transport diagnostics
+!   USE prtctl          ! Print control
+
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          & !
+      & prntst_tlm,          & !
+      & stdt,                & ! stdev for u-velocity
+      & stds                   !           v-velocity
+   USE paresp        , ONLY: & ! Weights for an energy-type scalar product
+      & wesp_t,              &
+      & wesp_s
+
+IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC tra_ldf_bilap_tan  ! called by dynldf_tam.F90
+   PUBLIC tra_ldf_bilap_adj  ! called by dynldf_tam.F90
+   PUBLIC tra_ldf_bilap_adj_tst  ! routine called by tradldf_tam.F90
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldftra_substitute.h90"
+#  include "ldfeiv_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+
+CONTAINS
+   SUBROUTINE tra_ldf_bilap_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_ldf_bilap  ***
+      !!
+      !! ** Purpose :   Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   4th order diffusive operator along model level surfaces 
+      !!      evaluated using before fields (forward time scheme). The hor.
+      !!      diffusive trends of temperature (idem for salinity) is given by:
+      !!      Laplacian of tb:
+      !!         zlt   = 1/(e1t*e2t*e3t) {  di-1[ e2u*e3u/e1u di(tb) ]
+      !!                                  + dj-1[ e1v*e3v/e2v dj(tb) ]  }
+      !!      Multiply by the eddy diffusivity coef. and insure lateral bc:
+      !!        zlt   = ahtt * zlt
+      !!        call to lbc_lnk
+      !!      Bilaplacian (laplacian of zlt):
+      !!         difft = 1/(e1t*e2t*e3t) {  di-1[ e2u*e3u/e1u di(zlt) ]
+      !!                                  + dj-1[ e1v*e3v/e2v dj(zlt) ]  }
+      !!      Note: if key_zco defined, e3t=e3u=e3v, they are simplified.
+      !!
+      !!      Add this trend to the general trend (ta,sa):
+      !!         (ta,sa) = (ta,sa) + ( difft , diffs )
+      !!
+      !! ** Action : - Update (ta,sa) arrays with the before iso-level
+      !!               biharmonic mixing trend.
+      !!
+      !! History :
+      !!        !  91-11  (G. Madec)  Original code
+      !!        !  93-03  (M. Guyon)  symetrical conditions
+      !!        !  95-11  (G. Madec)  suppress volumetric scale factors
+      !!        !  96-01  (G. Madec)  statement function for e3
+      !!        !  96-01  (M. Imbard)  mpp exchange
+      !!        !  97-07  (G. Madec)  optimization, and ahtt
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-08  (C. talandier) New trends organization
+      !!        !  05-11  (G. Madec)  zps or sco as default option
+      !!----------------------------------------------------------------------
+      !! History of the tangent routine
+      !!   9.0  !  10-05 (P.A. Bouttier) tangent of 9.0
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk             ! dummy loop indices
+      INTEGER ::   iku, ikv               ! temporary integers
+      REAL(wp) ::   ztatl, zsatl              ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   & 
+         zeeu, zeev, zbtr,              & ! 2D workspace
+         zlttl, zlstl
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   & 
+         zsutl, zsvtl, ztutl, ztvtl       ! 3D workspace 
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_ldf_bilap_tan : iso-level biharmonic operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~'
+      ENDIF
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         ! 0. Initialization of metric arrays (for z- or s-coordinates)
+         ! ----------------------------------
+
+         IF( lk_zco ) THEN      ! z-coordinate (1D arrays): no vertical scale factors
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zbtr(ji,jj) = 1. / ( e1t(ji,jj)*e2t(ji,jj) )
+                  zeeu(ji,jj) = e2u(ji,jj) / e1u(ji,jj) * umask(ji,jj,jk)
+                  zeev(ji,jj) = e1v(ji,jj) / e2v(ji,jj) * vmask(ji,jj,jk)
+               END DO
+            END DO
+         ELSE                   ! All coordinates (3D arrays): vertical scale factor are used
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zbtr(ji,jj) = 1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+                  zeeu(ji,jj) = e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj) * umask(ji,jj,jk)
+                  zeev(ji,jj) = e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj) * vmask(ji,jj,jk)
+               END DO
+            END DO
+         ENDIF
+
+         ! 1. Laplacian
+         ! ------------
+
+         ! First derivative (gradient)
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ztutl(ji,jj,jk) = zeeu(ji,jj) * ( tb_tl(ji+1,jj  ,jk) - tb_tl(ji,jj,jk) )
+               zsutl(ji,jj,jk) = zeeu(ji,jj) * ( sb_tl(ji+1,jj  ,jk) - sb_tl(ji,jj,jk) )
+               ztvtl(ji,jj,jk) = zeev(ji,jj) * ( tb_tl(ji  ,jj+1,jk) - tb_tl(ji,jj,jk) )
+               zsvtl(ji,jj,jk) = zeev(ji,jj) * ( sb_tl(ji  ,jj+1,jk) - sb_tl(ji,jj,jk) )
+            END DO
+         END DO
+         IF( ln_zps ) THEN      ! set gradient at partial step level
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  ! last level
+                  iku = MIN ( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1
+                  ikv = MIN ( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1
+                  IF( iku == jk ) THEN
+                     ztutl(ji,jj,jk) = zeeu(ji,jj) * gtu_tl(ji,jj)
+                     zsutl(ji,jj,jk) = zeeu(ji,jj) * gsu_tl(ji,jj)
+                  ENDIF
+                  IF( ikv == jk ) THEN
+                     ztvtl(ji,jj,jk) = zeev(ji,jj) * gtv_tl(ji,jj)
+                     zsvtl(ji,jj,jk) = zeev(ji,jj) * gsv_tl(ji,jj)
+                  ENDIF
+               END DO
+            END DO
+         ENDIF
+         
+         ! Second derivative (divergence)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zlttl(ji,jj) = zbtr(ji,jj) * (  ztutl(ji,jj,jk) - ztutl(ji-1,jj,jk) + ztvtl(ji,jj,jk) - ztvtl(ji,jj-1,jk)  )
+               zlstl(ji,jj) = zbtr(ji,jj) * (  zsutl(ji,jj,jk) - zsutl(ji-1,jj,jk) + zsvtl(ji,jj,jk) - zsvtl(ji,jj-1,jk)  )
+            END DO
+         END DO
+
+         ! Multiply by the eddy diffusivity coefficient
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zlttl(ji,jj) = fsahtt(ji,jj,jk) * zlttl(ji,jj)
+               zlstl(ji,jj) = fsahtt(ji,jj,jk) * zlstl(ji,jj)
+            END DO
+         END DO
+
+         ! Lateral boundary conditions on the laplacian (zlttl,zlstl)   (unchanged sgn)
+         CALL lbc_lnk( zlttl, 'T', 1.0_wp )   ;    CALL lbc_lnk( zlstl, 'T', 1.0_wp )
+
+         ! 2. Bilaplacian
+         ! --------------
+
+         ! third derivative (gradient)
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ztutl(ji,jj,jk) = zeeu(ji,jj) * ( zlttl(ji+1,jj  ) - zlttl(ji,jj) )
+               zsutl(ji,jj,jk) = zeeu(ji,jj) * ( zlstl(ji+1,jj  ) - zlstl(ji,jj) )
+               ztvtl(ji,jj,jk) = zeev(ji,jj) * ( zlttl(ji  ,jj+1) - zlttl(ji,jj) )
+               zsvtl(ji,jj,jk) = zeev(ji,jj) * ( zlstl(ji  ,jj+1) - zlstl(ji,jj) )
+            END DO
+         END DO
+
+         ! fourth derivative (divergence) and add to the general tracer trend
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! horizontal diffusive trends
+               ztatl = zbtr(ji,jj) * (  ztutl(ji,jj,jk) - ztutl(ji-1,jj,jk) + ztvtl(ji,jj,jk) - ztvtl(ji,jj-1,jk)  )
+               zsatl = zbtr(ji,jj) * (  zsutl(ji,jj,jk) - zsutl(ji-1,jj,jk) + zsvtl(ji,jj,jk) - zsvtl(ji,jj-1,jk)  )
+               ! add it to the general tracer trends
+               ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) + ztatl
+               sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) + zsatl
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           ! Horizontal slab
+      !                                                ! ===============
+
+
+   END SUBROUTINE tra_ldf_bilap_tan
+
+
+   SUBROUTINE tra_ldf_bilap_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_ldf_bilap  ***
+      !!
+      !! ** Purpose :   Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   4th order diffusive operator along model level surfaces 
+      !!      evaluated using before fields (forward time scheme). The hor.
+      !!      diffusive trends of temperature (idem for salinity) is given by:
+      !!      Laplacian of tb:
+      !!         zlt   = 1/(e1t*e2t*e3t) {  di-1[ e2u*e3u/e1u di(tb) ]
+      !!                                  + dj-1[ e1v*e3v/e2v dj(tb) ]  }
+      !!      Multiply by the eddy diffusivity coef. and insure lateral bc:
+      !!        zlt   = ahtt * zlt
+      !!        call to lbc_lnk
+      !!      Bilaplacian (laplacian of zlt):
+      !!         difft = 1/(e1t*e2t*e3t) {  di-1[ e2u*e3u/e1u di(zlt) ]
+      !!                                  + dj-1[ e1v*e3v/e2v dj(zlt) ]  }
+      !!      Note: if key_zco defined, e3t=e3u=e3v, they are simplified.
+      !!
+      !!      Add this trend to the general trend (ta,sa):
+      !!         (ta,sa) = (ta,sa) + ( difft , diffs )
+      !!
+      !! ** Action : - Update (ta,sa) arrays with the before iso-level
+      !!               biharmonic mixing trend.
+      !!
+      !! History :
+      !!        !  91-11  (G. Madec)  Original code
+      !!        !  93-03  (M. Guyon)  symetrical conditions
+      !!        !  95-11  (G. Madec)  suppress volumetric scale factors
+      !!        !  96-01  (G. Madec)  statement function for e3
+      !!        !  96-01  (M. Imbard)  mpp exchange
+      !!        !  97-07  (G. Madec)  optimization, and ahtt
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-08  (C. talandier) New trends organization
+      !!        !  05-11  (G. Madec)  zps or sco as default option
+      !!----------------------------------------------------------------------
+      !! History of the tangent routine
+      !!   9.0  !  10-05 (P.A. Bouttier) tangent of 9.0
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk             ! dummy loop indices
+      INTEGER ::   iku, ikv               ! temporary integers
+      REAL(wp) ::  ztaad, zsaad, ztmp     ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   & 
+         zeeu, zeev, zbtr,              & ! 2D workspace
+         zltad, zlsad
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   & 
+         zsuad, zsvad, ztuad, ztvad                         ! 3D workspace 
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_ldf_bilap_adj : iso-level biharmonic operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~'
+      ENDIF
+      ztaad = 0.e0_wp
+      zsaad = 0.e0_wp
+      zltad = 0.e0_wp
+      zlsad = 0.e0_wp
+      zsuad = 0.e0_wp
+      zsvad = 0.e0_wp
+      ztuad = 0.e0_wp
+      ztvad = 0.e0_wp
+      
+      ! "zonal" mean lateral diffusive heat and salt transport
+!      IF( ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+!         IF( lk_zco ) THEN      ! z-coordinate (1D arrays): multiply by the vertical scale factor
+!            DO jk = 1, jpkm1
+!               DO jj = 2, jpjm1
+!                  DO ji = fs_2, fs_jpim1   ! vector opt.
+!                     ztvad(ji,jj,jk) = ztvad(ji,jj,jk) * fse3v(ji,jj,jk)
+!                     zsvad(ji,jj,jk) = zsvad(ji,jj,jk) * fse3v(ji,jj,jk)
+!                  END DO
+!               END DO
+!            END DO
+!         ENDIF
+!         pht_ldf(:) = ptr_vj( ztvad(:,:,:) )
+!         pst_ldf(:) = ptr_vj( zsvad(:,:,:) )
+!      ENDIF
+
+      DO jk = 1, jpkm1
+            ! 0. Initialization of metric arrays (for z- or s-coordinates)
+            ! ----------------------------------
+
+            IF( lk_zco ) THEN      ! z-coordinate (1D arrays): no vertical scale factors
+               DO jj = jpjm1, 1, -1
+                  DO ji = fs_jpim1, 1 ,-1   ! vector opt.
+                     zbtr(ji,jj) = 1. / ( e1t(ji,jj)*e2t(ji,jj) )
+                     zeeu(ji,jj) = e2u(ji,jj) / e1u(ji,jj) * umask(ji,jj,jk)
+                     zeev(ji,jj) = e1v(ji,jj) / e2v(ji,jj) * vmask(ji,jj,jk)
+                  END DO
+               END DO
+            ELSE                   ! All coordinates (3D arrays): vertical scale factor are used
+               DO jj = jpjm1, 1, -1
+                  DO ji = fs_jpim1, 1 ,-1   ! vector opt.
+                     zbtr(ji,jj) = 1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+                     zeeu(ji,jj) = e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj) * umask(ji,jj,jk)
+                     zeev(ji,jj) = e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj) * vmask(ji,jj,jk)
+                  END DO
+               END DO
+            ENDIF
+            !   
+            ! 2. Bilaplacian
+            ! --------------
+            ! fourth derivative (divergence) and add to the general tracer trend
+            DO jj = jpjm1, 2, -1
+               DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+                  ! add it to the general tracer trends
+                  zsaad = sa_ad(ji,jj,jk) * zbtr(ji,jj)
+                  ztaad = ta_ad(ji,jj,jk) * zbtr(ji,jj)
+                  ! horizontal diffusive trends
+                  zsuad(ji  ,jj  ,jk) = zsuad(ji  ,jj  ,jk) + zsaad
+                  zsuad(ji-1,jj  ,jk) = zsuad(ji-1,jj  ,jk) - zsaad
+                  zsvad(ji  ,jj-1,jk) = zsvad(ji  ,jj-1,jk) - zsaad
+		  zsvad(ji  ,jj  ,jk) = zsvad(ji  ,jj  ,jk) + zsaad
+                  ztuad(ji  ,jj  ,jk) = ztuad(ji  ,jj  ,jk) + ztaad
+                  ztuad(ji-1,jj  ,jk) = ztuad(ji-1,jj  ,jk) - ztaad
+                  ztvad(ji  ,jj  ,jk) = ztvad(ji  ,jj  ,jk) + ztaad
+                  ztvad(ji  ,jj-1,jk) = ztvad(ji  ,jj-1,jk) - ztaad
+                  ztaad = 0.0_wp
+                  zsaad = 0.0_wp
+               END DO
+            END DO
+
+            ! third derivative (gradient)
+            DO jj = jpjm1, 1, -1
+               DO ji = fs_jpim1, 1 ,-1   ! vector opt.
+                  ztmp = zeev(ji,jj) * zsvad(ji,jj,jk)
+                  zlsad(ji  ,jj+1) = zlsad(ji  ,jj+1) + ztmp
+                  zlsad(ji  ,jj  ) = zlsad(ji  ,jj  ) - ztmp
+                  ztmp = zeev(ji,jj) * ztvad(ji,jj,jk)
+                  zltad(ji  ,jj+1) = zltad(ji  ,jj+1) + ztmp
+                  zltad(ji  ,jj  ) = zltad(ji  ,jj  ) - ztmp
+                  ztmp = zeeu(ji,jj) * zsuad(ji,jj,jk)
+                  zlsad(ji+1,jj  ) = zlsad(ji+1,jj  ) + ztmp
+                  zlsad(ji  ,jj  ) = zlsad(ji  ,jj  ) - ztmp
+                  ztmp = zeeu(ji,jj) * ztuad(ji,jj,jk)
+                  zltad(ji+1,jj  ) = zltad(ji+1,jj  ) + ztmp
+                  zltad(ji  ,jj  ) = zltad(ji  ,jj  ) - ztmp
+                  zsuad(ji  ,jj  ,jk) = 0.0_wp
+                  ztuad(ji  ,jj  ,jk) = 0.0_wp
+                  zsvad(ji  ,jj  ,jk) = 0.0_wp
+	          ztvad(ji  ,jj  ,jk) = 0.0_wp
+               END DO
+            END DO     
+            ! Lateral boundary conditions on the laplacian (zltad,zlsad)   (unchanged sgn)
+            CALL lbc_lnk_adj( zltad, 'T', 1.0_wp )   ;    CALL lbc_lnk_adj( zlsad, 'T', 1.0_wp )
+            ! Multiply by the eddy diffusivity coefficient
+            DO jj = jpjm1, 2, -1
+               DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+                  zltad(ji,jj) = fsahtt(ji,jj,jk) * zltad(ji,jj)
+                  zlsad(ji,jj) = fsahtt(ji,jj,jk) * zlsad(ji,jj)
+               END DO
+            END DO
+            ! Second derivative (divergence)
+            DO jj = jpjm1, 2, -1
+               DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+                  ztmp = zbtr(ji,jj) * zlsad(ji,jj)
+                  zsvad(ji  ,jj-1,jk) = zsvad(ji  ,jj-1,jk) - ztmp
+                  zsvad(ji  ,jj  ,jk) = zsvad(ji  ,jj  ,jk) + ztmp
+                  zsuad(ji-1,jj  ,jk) = zsuad(ji-1,jj  ,jk) - ztmp
+                  zsuad(ji  ,jj  ,jk) = zsuad(ji  ,jj  ,jk) + ztmp
+                  ztmp = zbtr(ji,jj) * zltad(ji,jj)
+                  ztvad(ji  ,jj-1,jk) = ztvad(ji  ,jj-1,jk) - ztmp
+                  ztvad(ji  ,jj  ,jk) = ztvad(ji  ,jj  ,jk) + ztmp
+                  ztuad(ji-1,jj  ,jk) = ztuad(ji-1,jj  ,jk) - ztmp
+                  ztuad(ji  ,jj  ,jk) = ztuad(ji  ,jj  ,jk) + ztmp
+                  zlsad(ji,jj) = 0.0_wp
+                  zltad(ji,jj) = 0.0_wp
+               END DO
+            END DO
+            IF( ln_zps ) THEN      ! set gradient at partial step level
+            DO jj = jpjm1, 1, -1
+               DO ji = fs_jpim1, 1 ,-1   ! vector opt.
+                     ! last level
+                     iku = MIN ( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1
+                     ikv = MIN ( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1
+                     IF( iku == jk ) THEN
+                        gsu_ad(ji,jj)   = gsu_ad(ji,jj) + zeeu(ji,jj) * zsuad(ji,jj,jk)
+                        gtu_ad(ji,jj)   = gtu_ad(ji,jj) + zeeu(ji,jj) * ztuad(ji,jj,jk)
+                        zsuad(ji,jj,jk) = 0.0_wp
+                        ztuad(ji,jj,jk) = 0.0_wp
+                     ENDIF
+                     IF( ikv == jk ) THEN
+                        gsv_ad(ji,jj)   = gsv_ad(ji,jj) + zeev(ji,jj) * zsvad(ji,jj,jk)
+                        gtv_ad(ji,jj)   = gtv_ad(ji,jj) + zeev(ji,jj) * ztvad(ji,jj,jk)
+                        ztvad(ji,jj,jk) = 0.0_wp
+                        zsvad(ji,jj,jk) = 0.0_wp
+                     ENDIF
+                  END DO
+               END DO
+            ENDIF
+            ! 1. Laplacian
+            ! ------------
+
+            ! First derivative (gradient)
+            DO jj = jpjm1, 1, -1
+               DO ji = fs_jpim1, 1 ,-1   ! vector opt.
+                  ztmp = zeev(ji,jj) * zsvad(ji,jj,jk)
+                  sb_ad(ji  ,jj  ,jk) = sb_ad(ji  ,jj  ,jk) - ztmp
+                  sb_ad(ji  ,jj+1,jk) = sb_ad(ji  ,jj+1,jk) + ztmp
+                  ztmp = zeev(ji,jj) * ztvad(ji,jj,jk)
+                  tb_ad(ji  ,jj  ,jk) = tb_ad(ji  ,jj  ,jk) - ztmp
+                  tb_ad(ji  ,jj+1,jk) = tb_ad(ji  ,jj+1,jk) + ztmp
+                  ztmp = zeeu(ji,jj) * zsuad(ji,jj,jk)
+                  sb_ad(ji  ,jj  ,jk) = sb_ad(ji  ,jj  ,jk) - ztmp
+                  sb_ad(ji+1,jj  ,jk) = sb_ad(ji+1,jj  ,jk) + ztmp
+                  ztmp = zeeu(ji,jj) * ztuad(ji,jj,jk)
+                  tb_ad(ji  ,jj  ,jk) = tb_ad(ji  ,jj  ,jk) - ztmp
+                  tb_ad(ji+1,jj  ,jk) = tb_ad(ji+1,jj  ,jk) + ztmp
+                  ztuad(ji,jj,jk) = 0.0_wp
+                  zsuad(ji,jj,jk) = 0.0_wp
+                  zsvad(ji,jj,jk) = 0.0_wp
+                  ztvad(ji,jj,jk) = 0.0_wp
+               END DO
+            END DO
+
+       END DO
+END SUBROUTINE tra_ldf_bilap_adj
+
+   SUBROUTINE tra_ldf_bilap_adj_tst ( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE example_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_T,       &
+         & zsp1_S,       &
+         & zsp2,         & ! scalar product involving the adjoint routine
+         & zsp2_1,       &
+         & zsp2_2,       &
+         & zsp2_3,       &
+         & zsp2_4,       &
+         & zsp2_5,       &
+         & zsp2_6,       &
+         & zsp2_7,       &
+         & zsp2_8,       &
+         & zsp2_T,       &
+         & zsp2_S
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & ztb_tlin ,      & ! Tangent input
+         & zsb_tlin ,      & ! Tangent input
+         & zta_tlin ,      & ! Tangent input
+         & zsa_tlin ,      & ! Tangent input
+         & zta_tlout,      & ! Tangent output
+         & zsa_tlout,      & ! Tangent output
+         & zta_adin,       & ! Adjoint input
+         & zsa_adin,       & ! Adjoint input
+         & ztb_adout ,     & ! Adjoint output
+         & zsb_adout ,     & ! Adjoint output
+         & zta_adout ,     & ! Adjoint output
+         & zsa_adout ,     & ! Adjoint output
+         & z3r               ! 3D random field 
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zgtu_tlin ,     & ! Tangent input
+         & zgsu_tlin ,     & ! Tangent input
+         & zgtv_tlin ,     & ! Tangent input
+         & zgsv_tlin ,     & ! Tangent input
+         & zgtu_adout ,    & ! Adjoint output
+         & zgsu_adout ,    & ! Adjoint output
+         & zgtv_adout ,    & ! Adjoint output
+         & zgsv_adout ,    & ! Adjoint output
+         & z2r               ! 2D random field 
+      CHARACTER(LEN=14) :: cl_name
+      ! Allocate memory
+
+      ALLOCATE( &
+         & ztb_tlin(jpi,jpj,jpk),      & 
+         & zsb_tlin(jpi,jpj,jpk),      & 
+         & zta_tlin(jpi,jpj,jpk),      & 
+         & zsa_tlin(jpi,jpj,jpk),      & 
+         & zgtu_tlin(jpi,jpj),         & 
+         & zgsu_tlin(jpi,jpj),         & 
+         & zgtv_tlin(jpi,jpj),         & 
+         & zgsv_tlin(jpi,jpj),         & 
+         & zta_tlout(jpi,jpj,jpk),     & 
+         & zsa_tlout(jpi,jpj,jpk),     & 
+         & zta_adin(jpi,jpj,jpk),      & 
+         & zsa_adin(jpi,jpj,jpk),      & 
+         & ztb_adout(jpi,jpj,jpk),     & 
+         & zsb_adout(jpi,jpj,jpk),     & 
+         & zta_adout(jpi,jpj,jpk),     & 
+         & zsa_adout(jpi,jpj,jpk),     & 
+         & zgtu_adout(jpi,jpj),        & 
+         & zgsu_adout(jpi,jpj),        & 
+         & zgtv_adout(jpi,jpj),        & 
+         & zgsv_adout(jpi,jpj),        & 
+         & z3r(jpi,jpj,jpk),           &
+         & z2r(jpi,jpj)                &
+         & )
+
+
+      !=======================================================================
+      ! 1) dx = ( tb_tl, ta_tl, sb_tl, sa_tl, gtu_tl, gtv_tl, gsu_tl, gsv_tl )
+      !    dy = ( ta_tl, sa_tl )
+      !=======================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+
+      ztb_tlin(:,:,:)  = 0.0_wp
+      zsb_tlin(:,:,:)  = 0.0_wp
+      zta_tlin(:,:,:)  = 0.0_wp
+      zsa_tlin(:,:,:)  = 0.0_wp
+      zgtu_tlin(:,:)   = 0.0_wp
+      zgsu_tlin(:,:)   = 0.0_wp
+      zgtv_tlin(:,:)   = 0.0_wp
+      zgsv_tlin(:,:)   = 0.0_wp
+      zta_tlout(:,:,:) = 0.0_wp
+      zsa_tlout(:,:,:) = 0.0_wp
+      zta_adin(:,:,:)  = 0.0_wp
+      zsa_adin(:,:,:)  = 0.0_wp
+      ztb_adout(:,:,:) = 0.0_wp
+      zsb_adout(:,:,:) = 0.0_wp
+      zta_adout(:,:,:) = 0.0_wp
+      zsa_adout(:,:,:) = 0.0_wp
+      zgtu_adout(:,:)  = 0.0_wp
+      zgsu_adout(:,:)  = 0.0_wp
+      zgtv_adout(:,:)  = 0.0_wp
+      zgsv_adout(:,:)  = 0.0_wp
+
+      tb_tl(:,:,:) = 0.0_wp
+      sb_tl(:,:,:) = 0.0_wp
+      ta_tl(:,:,:) = 0.0_wp
+      sa_tl(:,:,:) = 0.0_wp
+      gtu_tl(:,:)  = 0.0_wp
+      gsu_tl(:,:)  = 0.0_wp
+      gtv_tl(:,:)  = 0.0_wp
+      gsv_tl(:,:)  = 0.0_wp
+      tb_ad(:,:,:) = 0.0_wp
+      sb_ad(:,:,:) = 0.0_wp
+      ta_ad(:,:,:) = 0.0_wp
+      sa_ad(:,:,:) = 0.0_wp
+      gtu_ad(:,:)  = 0.0_wp
+      gsu_ad(:,:)  = 0.0_wp
+      gtv_ad(:,:)  = 0.0_wp
+      gsv_ad(:,:)  = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              ztb_tlin(ji,jj,jk) = z3r(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 727391 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stds )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsb_tlin(ji,jj,jk) = z3r(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 249741 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zta_tlin(ji,jj,jk) = z3r(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 182029 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stds )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsa_tlin(ji,jj,jk) = z3r(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z2r, 'U', 0.0_wp, stds )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zgtu_tlin(ji,jj) = z2r(ji,jj) 
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 727391 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z2r, 'U', 0.0_wp, stds )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zgsu_tlin(ji,jj) = z2r(ji,jj) 
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 249741 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z2r, 'V', 0.0_wp, stds )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zgtv_tlin(ji,jj) = z2r(ji,jj) 
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 182029 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z2r, 'V', 0.0_wp, stds )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zgsv_tlin(ji,jj) = z2r(ji,jj) 
+         END DO
+      END DO
+
+      tb_tl(:,:,:) = ztb_tlin(:,:,:) 
+      sb_tl(:,:,:) = zsb_tlin(:,:,:) 
+      ta_tl(:,:,:) = zta_tlin(:,:,:) 
+      sa_tl(:,:,:) = zsa_tlin(:,:,:) 
+      gtu_tl(:,:)  = zgtu_tlin(:,:)
+      gsu_tl(:,:)  = zgsu_tlin(:,:)
+      gtv_tl(:,:)  = zgtv_tlin(:,:)
+      gsv_tl(:,:)  = zgsv_tlin(:,:)
+
+      CALL tra_ldf_bilap_tan( nit000 ) 
+      
+      zta_tlout(:,:,:) = ta_tl(:,:,:)
+      zsa_tlout(:,:,:) = sa_tl(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsa_adin(ji,jj,jk) = zsa_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_s(jk)
+              zta_adin(ji,jj,jk) = zta_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_t(jk)
+            END DO
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !-------------------------------------------------------------------
+
+      zsp1_T = DOT_PRODUCT( zta_tlout, zta_adin )
+      zsp1_S = DOT_PRODUCT( zsa_tlout, zsa_adin )
+      zsp1 = zsp1_T + zsp1_S
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      ta_ad(:,:,:) = zta_adin(:,:,:)
+      sa_ad(:,:,:) = zsa_adin(:,:,:)
+
+      CALL tra_ldf_bilap_adj( nit000 ) 
+
+      ztb_adout(:,:,:) = tb_ad(:,:,:)
+      zsb_adout(:,:,:) = sb_ad(:,:,:)
+      zta_adout(:,:,:) = ta_ad(:,:,:)
+      zsa_adout(:,:,:) = sa_ad(:,:,:)
+      zgtu_adout(:,:)  = gtu_ad(:,:)
+      zgsu_adout(:,:)  = gsu_ad(:,:)
+      zgtv_adout(:,:)  = gtv_ad(:,:)
+      zgsv_adout(:,:)  = gsv_ad(:,:)
+          
+      zsp2_1 = DOT_PRODUCT( ztb_tlin , ztb_adout  )
+      zsp2_2 = DOT_PRODUCT( zta_tlin , zta_adout  )
+      zsp2_3 = DOT_PRODUCT( zgtu_tlin, zgtu_adout )
+      zsp2_4 = DOT_PRODUCT( zgtv_tlin, zgtv_adout )
+      zsp2_5 = DOT_PRODUCT( zsb_tlin , zsb_adout  )
+      zsp2_6 = DOT_PRODUCT( zsa_tlin , zsa_adout  )
+      zsp2_7 = DOT_PRODUCT( zgsu_tlin, zgsu_adout )
+      zsp2_8 = DOT_PRODUCT( zgsv_tlin, zgsv_adout ) 
+
+      zsp2_T = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4
+      zsp2_S = zsp2_5 + zsp2_6 + zsp2_7 + zsp2_8
+      zsp2   = zsp2_T + zsp2_S
+
+      cl_name = 'tra_ldf_bilap'
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      DEALLOCATE(         &
+         & ztb_tlin,      & ! Tangent input
+         & zsb_tlin,      & ! Tangent input
+         & zta_tlin,      & ! Tangent input
+         & zsa_tlin,      & ! Tangent input
+         & zgtu_tlin,     & ! Tangent input
+         & zgsu_tlin,     & ! Tangent input
+         & zgtv_tlin,     & ! Tangent input
+         & zgsv_tlin,     & ! Tangent input
+         & zta_tlout,     & ! Tangent output
+         & zsa_tlout,     & ! Tangent output
+         & zta_adin,      & ! Adjoint input
+         & zsa_adin,      & ! Adjoint input
+         & ztb_adout,     & ! Adjoint output
+         & zsb_adout,     & ! Adjoint output
+         & zta_adout,     & ! Adjoint output
+         & zsa_adout,     & ! Adjoint output
+         & zgtu_adout,    & ! Adjoint output
+         & zgsu_adout,    & ! Adjoint output
+         & zgtv_adout,    & ! Adjoint output
+         & zgsv_adout,    & ! Adjoint output
+         & z3r,           & ! 3D random field 
+         & z2r            &
+         & )
+      
+
+   END SUBROUTINE tra_ldf_bilap_adj_tst
+
+#endif
+END MODULE traldf_bilap_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traldf_iso_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traldf_iso_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traldf_iso_tam.F90	(revision 2578)
@@ -0,0 +1,1080 @@
+MODULE traldf_iso_tam
+#if defined key_tam
+   !!======================================================================
+   !!                   ***  MODULE  traldf_iso_tam  ***
+   !! Ocean active tracers:  horizontal component of the lateral tracer mixing trend
+   !!                        Tangent and adjoint module
+   !!======================================================================
+   !! History of the direct module:
+   !!                  !  94-08  (G. Madec, M. Imbard)
+   !!                  !  97-05  (G. Madec)  split into traldf and trazdf
+   !!             8.5  !  02-08  (G. Madec)  Free form, F90
+   !!             9.0  !  05-11  (G. Madec)  merge traldf and trazdf :-)
+   !! History of the T&A module:
+   !!             9.0  !  2008-12 (A. Vidard) original version
+   !!              -   !  2009-01 (A. Weaver) misc. bug fixes
+   !!      NEMO   3.2  !  2010-04 (F. Vigilant) 3.2 version
+   !!----------------------------------------------------------------------
+# if   defined key_ldfslp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_ldfslp'               slope of the lateral diffusive direction
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   tra_ldf_iso  : update the tracer trend with the horizontal 
+   !!                  component of a iso-neutral laplacian operator
+   !!                  and with the vertical part of
+   !!                  the isopycnal or geopotential s-coord. operator 
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpiglo,              &
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1
+   USE oce_tam       , ONLY: & ! ocean dynamics and active tracers
+      & tb_tl,               &
+      & sb_tl,               &
+      & ta_tl,               &
+      & sa_tl,               &
+      & gtu_tl,              &
+      & gsu_tl,              &
+      & gtv_tl,              &
+      & gsv_tl,              &
+      & tb_ad,               &
+      & sb_ad,               &
+      & ta_ad,               &
+      & sa_ad,               &
+      & gtu_ad,              &
+      & gsu_ad,              &
+      & gtv_ad,              &
+      & gsv_ad
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+      & e1t,                 &
+      & e2t,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3u,                 &
+      & e3v,                 &
+      & e3t,                 &
+#endif
+      & tmask,               &
+      & umask,               &
+      & vmask,               &
+      & mbathy,              &
+      & ln_zps,              &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE ldftra_oce    , ONLY: & ! ocean active tracers: lateral physics
+      & ahtv,                &
+      & ahtu,                &
+      & ahtw,                &
+      & ahtb0,               &
+      & aht0
+!   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager, ONLY: & ! I/O manager
+      & lwp,                 &
+      & numout,              &
+      & nitend,              &
+      & nit000
+   USE ldfslp        , ONLY: & ! iso-neutral slopes
+      & uslp,                &
+      & vslp,                &
+      & wslpi,               &
+      & wslpj
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          & !
+      & stdt,                & ! stdev for u-velocity
+      & stds                   !           v-velocity
+   USE paresp        , ONLY: & ! Weights for an energy-type scalar product
+      & wesp_t,              &
+      & wesp_s
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_ldf_iso_tan     ! routine called by tralfd_tam.F90
+   PUBLIC   tra_ldf_iso_adj     ! routine called by traldf_tam.F90
+   PUBLIC   tra_ldf_iso_adj_tst ! routine called by traldf_tam.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldftra_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_ldf_iso_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_ldf_iso_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend for a laplacian tensor (ezxcept the dz[ dz[.] ] term) and 
+      !!      add it to the general trend of tracer equation.
+      !!
+      !! ** Method of the direct routine:
+      !!      The horizontal component of the lateral diffusive trends 
+      !!      is provided by a 2nd order operator rotated along neural or geopo-
+      !!      tential surfaces to which an eddy induced advection can be added
+      !!      It is computed using before fields (forward in time) and isopyc-
+      !!      nal or geopotential slopes computed in routine ldfslp.
+      !!
+      !!      1st part :  masked horizontal derivative of T & S ( di[ t ] )
+      !!      ========    with partial cell update if ln_zps=T.
+      !!
+      !!      2nd part :  horizontal fluxes of the lateral mixing operator
+      !!      ========    
+      !!         zftu = (aht+ahtb0) e2u*e3u/e1u di[ tb ]
+      !!               - aht       e2u*uslp    dk[ mi(mk(tb)) ]
+      !!         zftv = (aht+ahtb0) e1v*e3v/e2v dj[ tb ]
+      !!               - aht       e2u*vslp    dk[ mj(mk(tb)) ]
+      !!      take the horizontal divergence of the fluxes:
+      !!         difft = 1/(e1t*e2t*e3t) {  di-1[ zftu ] +  dj-1[ zftv ]  }
+      !!      Add this trend to the general trend (ta,sa):
+      !!         ta = ta + difft
+      !!
+      !!      3rd part: vertical trends of the lateral mixing operator
+      !!      ========  (excluding the vertical flux proportional to dk[t] )
+      !!      vertical fluxes associated with the rotated lateral mixing:
+      !!         zftw =-aht {  e2t*wslpi di[ mi(mk(tb)) ]
+      !!                     + e1t*wslpj dj[ mj(mk(tb)) ]  }
+      !!      take the horizontal divergence of the fluxes:
+      !!         difft = 1/(e1t*e2t*e3t) dk[ zftw ]
+      !!      Add this trend to the general trend (ta,sa):
+      !!         ta = ta + difft
+      !!
+      !! ** Action :   Update (ta,sa) arrays with the before rotated diffusion
+      !!            trend (except the dk[ dk[.] ] term)
+      !!----------------------------------------------------------------------
+
+      INTEGER, INTENT( in ) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   iku, ikv     ! temporary integer
+      REAL(wp) ::   zmsku, zabe1, zcof1, zcoef3, ztatl   ! temporary scalars
+      REAL(wp) ::   zmskv, zabe2, zcof2, zcoef4, zsatl   !    "         "
+      REAL(wp) ::   zcoef0, zbtr                       !    "         "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zdkttl , zdk1ttl, zftutl, zftvtl   ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zdkstl , zdk1stl, zfsutl, zfsvtl   !  "     "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdittl, zdjttl, ztfwtl     ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdistl, zdjstl, zsfwtl     !  "      "
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_ldf_iso_tan : rotated laplacian diffusion operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
+      ENDIF
+
+      !!----------------------------------------------------------------------
+      !!   I - masked horizontal derivative of T & S
+      !!----------------------------------------------------------------------
+!!bug ajout.... why?   ( 1,jpj,:) and (jpi,1,:) should be sufficient....
+      zdittl (1,:,:) = 0.e0     ;     zdittl (jpi,:,:) = 0.e0
+      zdistl (1,:,:) = 0.e0     ;     zdistl (jpi,:,:) = 0.e0
+      zdjttl (1,:,:) = 0.e0     ;     zdjttl (jpi,:,:) = 0.e0
+      zdjstl (1,:,:) = 0.e0     ;     zdjstl (jpi,:,:) = 0.e0
+!!end
+
+      ! Horizontal temperature and salinity gradient 
+      DO jk = 1, jpkm1
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zdittl(ji,jj,jk) = ( tb_tl(ji+1,jj  ,jk) - tb_tl(ji,jj,jk) ) * umask(ji,jj,jk)
+               zdistl(ji,jj,jk) = ( sb_tl(ji+1,jj  ,jk) - sb_tl(ji,jj,jk) ) * umask(ji,jj,jk)
+               zdjttl(ji,jj,jk) = ( tb_tl(ji  ,jj+1,jk) - tb_tl(ji,jj,jk) ) * vmask(ji,jj,jk)
+               zdjstl(ji,jj,jk) = ( sb_tl(ji  ,jj+1,jk) - sb_tl(ji,jj,jk) ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      IF( ln_zps ) THEN      ! partial steps correction at the last level 
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ! last level
+               iku = MIN( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1
+               ikv = MIN( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1
+               zdittl(ji,jj,iku) = gtu_tl(ji,jj) 
+               zdistl(ji,jj,iku) = gsu_tl(ji,jj)               
+               zdjttl(ji,jj,ikv) = gtv_tl(ji,jj) 
+               zdjstl(ji,jj,ikv) = gsv_tl(ji,jj)               
+            END DO
+         END DO
+      ENDIF
+
+      !!----------------------------------------------------------------------
+      !!   II - horizontal trend of T & S (full)
+      !!----------------------------------------------------------------------
+      
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! 1. Vertical tracer gradient at level jk and jk+1
+         ! ------------------------------------------------
+         ! surface boundary condition: zdkt(jk=1)=zdkt(jk=2)
+
+         zdk1ttl(:,:) = ( tb_tl(:,:,jk) - tb_tl(:,:,jk+1) ) * tmask(:,:,jk+1)
+         zdk1stl(:,:) = ( sb_tl(:,:,jk) - sb_tl(:,:,jk+1) ) * tmask(:,:,jk+1)
+
+         IF( jk == 1 ) THEN
+            zdkttl(:,:) = zdk1ttl(:,:)
+            zdkstl(:,:) = zdk1stl(:,:)
+         ELSE
+            zdkttl(:,:) = ( tb_tl(:,:,jk-1) - tb_tl(:,:,jk) ) * tmask(:,:,jk)
+            zdkstl(:,:) = ( sb_tl(:,:,jk-1) - sb_tl(:,:,jk) ) * tmask(:,:,jk)
+         ENDIF
+
+         ! 2. Horizontal fluxes
+         ! --------------------
+
+         DO jj = 1 , jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+
+               zabe1 = ( fsahtu(ji,jj,jk) + ahtb0 ) * e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj)
+               zabe2 = ( fsahtv(ji,jj,jk) + ahtb0 ) * e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj)
+
+               zmsku = 1.0_wp / MAX(  tmask(ji+1,jj,jk  ) + tmask(ji,jj,jk+1)   &
+                  &                 + tmask(ji+1,jj,jk+1) + tmask(ji,jj,jk  ), 1.0_wp )
+
+               zmskv = 1.0_wp / MAX(  tmask(ji,jj+1,jk  ) + tmask(ji,jj,jk+1)   &
+                  &                 + tmask(ji,jj+1,jk+1) + tmask(ji,jj,jk  ), 1.0_wp )
+
+               ! *** NOTE ***  uslp() and vslp() are not linearized.
+
+               zcof1 = -fsahtu(ji,jj,jk) * e2u(ji,jj) * uslp(ji,jj,jk) * zmsku
+               zcof2 = -fsahtv(ji,jj,jk) * e1v(ji,jj) * vslp(ji,jj,jk) * zmskv
+
+               zftutl(ji,jj) = (  zabe1 * zdittl(ji,jj,jk)   &
+                  &              + zcof1 * (  zdkttl (ji+1,jj) + zdk1ttl(ji,jj)      &
+                  &                         + zdk1ttl(ji+1,jj) + zdkttl (ji,jj)  )  ) * umask(ji,jj,jk)
+               zftvtl(ji,jj) = (  zabe2 * zdjttl(ji,jj,jk)   &
+                  &              + zcof2 * (  zdkttl (ji,jj+1) + zdk1ttl(ji,jj)      &
+                  &                         + zdk1ttl(ji,jj+1) + zdkttl (ji,jj)  )  ) * vmask(ji,jj,jk)
+               zfsutl(ji,jj) = (  zabe1 * zdistl(ji,jj,jk)   &
+                  &              + zcof1 * (  zdkstl (ji+1,jj) + zdk1stl(ji,jj)      &
+                  &                         + zdk1stl(ji+1,jj) + zdkstl (ji,jj)  )  ) * umask(ji,jj,jk)
+               zfsvtl(ji,jj) = (  zabe2 * zdjstl(ji,jj,jk)   &
+                  &              + zcof2 * (  zdkstl (ji,jj+1) + zdk1stl(ji,jj)      &
+                  &                         + zdk1stl(ji,jj+1) + zdkstl (ji,jj)  )  ) * vmask(ji,jj,jk)
+
+            END DO
+         END DO
+
+
+         ! II.4 Second derivative (divergence) and add to the general trend
+         ! ----------------------------------------------------------------
+         DO jj = 2 , jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbtr= 1.0_wp / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+               ztatl = zbtr * (   zftutl(ji,jj) - zftutl(ji-1,jj  ) &
+                  &             + zftvtl(ji,jj) - zftvtl(ji  ,jj-1)  )
+               zsatl = zbtr * (   zfsutl(ji,jj) - zfsutl(ji-1,jj  ) &
+                  &             + zfsvtl(ji,jj) - zfsvtl(ji  ,jj-1)  )
+
+               ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) + ztatl
+               sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) + zsatl
+            END DO
+         END DO
+         !                                          ! ===============
+      END DO                                        !   End of slab  
+      !                                             ! ===============
+
+      !!----------------------------------------------------------------------
+      !!   III - vertical trend of T & S (extra diagonal terms only)
+      !!----------------------------------------------------------------------
+
+      ! Local constant initialization
+      ! -----------------------------
+      ztfwtl(1,:,:) = 0.0_wp     ;     ztfwtl(jpi,:,:) = 0.0_wp
+      zsfwtl(1,:,:) = 0.0_wp     ;     zsfwtl(jpi,:,:) = 0.0_wp
+
+
+      ! Vertical fluxes
+      ! ---------------
+
+      ! Surface and bottom vertical fluxes set to zero
+      ztfwtl(:,:, 1 ) = 0.0_wp   ;     ztfwtl(:,:,jpk) = 0.0_wp
+      zsfwtl(:,:, 1 ) = 0.0_wp   ;     zsfwtl(:,:,jpk) = 0.0_wp
+
+      ! interior (2=<jk=<jpk-1)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcoef0 = - fsahtw(ji,jj,jk) * tmask(ji,jj,jk)
+
+               zmsku = 1.0_wp / MAX(   umask(ji  ,jj,jk-1) + umask(ji-1,jj,jk)      &
+                  &                  + umask(ji-1,jj,jk-1) + umask(ji  ,jj,jk), 1.0_wp  )
+
+               zmskv = 1.0_wp / MAX(   vmask(ji,jj  ,jk-1) + vmask(ji,jj-1,jk)      &
+                  &                  + vmask(ji,jj-1,jk-1) + vmask(ji,jj  ,jk), 1.0_wp  )
+
+               ! *** NOTE ***  wslpi() and wslpj() are not linearized.
+
+               zcoef3 = zcoef0 * e2t(ji,jj) * zmsku * wslpi(ji,jj,jk)
+               zcoef4 = zcoef0 * e1t(ji,jj) * zmskv * wslpj(ji,jj,jk)
+
+               ztfwtl(ji,jj,jk) = zcoef3 * ( zdittl(ji  ,jj  ,jk-1) + zdittl(ji-1,jj  ,jk)      &
+                  &                        + zdittl(ji-1,jj  ,jk-1) + zdittl(ji  ,jj  ,jk)  )   &
+                  &             + zcoef4 * ( zdjttl(ji  ,jj  ,jk-1) + zdjttl(ji  ,jj-1,jk)      &
+                  &                        + zdjttl(ji  ,jj-1,jk-1) + zdjttl(ji  ,jj  ,jk)  )
+
+               zsfwtl(ji,jj,jk) = zcoef3 * ( zdistl(ji  ,jj  ,jk-1) + zdistl(ji-1,jj  ,jk)      &
+                  &                        + zdistl(ji-1,jj  ,jk-1) + zdistl(ji  ,jj  ,jk)  )   &
+                  &             + zcoef4 * ( zdjstl(ji  ,jj  ,jk-1) + zdjstl(ji  ,jj-1,jk)      &
+                  &                        + zdjstl(ji  ,jj-1,jk-1) + zdjstl(ji  ,jj  ,jk)  )
+            END DO
+         END DO
+      END DO
+
+
+      ! I.5 Divergence of vertical fluxes added to the general tracer trend
+      ! -------------------------------------------------------------------
+
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbtr =  1.0_wp / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+
+               ztatl = ( ztfwtl(ji,jj,jk) - ztfwtl(ji,jj,jk+1) ) * zbtr
+               zsatl = ( zsfwtl(ji,jj,jk) - zsfwtl(ji,jj,jk+1) ) * zbtr
+
+               ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) + ztatl
+               sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) + zsatl
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE tra_ldf_iso_tan
+
+   SUBROUTINE tra_ldf_iso_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_ldf_iso_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend for a laplacian tensor (ezxcept the dz[ dz[.] ] term) and 
+      !!      add it to the general trend of tracer equation.
+      !!
+      !! ** Method of the direct routine:
+      !!      The horizontal component of the lateral diffusive trends 
+      !!      is provided by a 2nd order operator rotated along neural or geopo-
+      !!      tential surfaces to which an eddy induced advection can be added
+      !!      It is computed using before fields (forward in time) and isopyc-
+      !!      nal or geopotential slopes computed in routine ldfslp.
+      !!
+      !!      1st part :  masked horizontal derivative of T & S ( di[ t ] )
+      !!      ========    with partial cell update if ln_zps=T.
+      !!
+      !!      2nd part :  horizontal fluxes of the lateral mixing operator
+      !!      ========    
+      !!         zftu = (aht+ahtb0) e2u*e3u/e1u di[ tb ]
+      !!               - aht       e2u*uslp    dk[ mi(mk(tb)) ]
+      !!         zftv = (aht+ahtb0) e1v*e3v/e2v dj[ tb ]
+      !!               - aht       e2u*vslp    dk[ mj(mk(tb)) ]
+      !!      take the horizontal divergence of the fluxes:
+      !!         difft = 1/(e1t*e2t*e3t) {  di-1[ zftu ] +  dj-1[ zftv ]  }
+      !!      Add this trend to the general trend (ta,sa):
+      !!         ta = ta + difft
+      !!
+      !!      3rd part: vertical trends of the lateral mixing operator
+      !!      ========  (excluding the vertical flux proportional to dk[t] )
+      !!      vertical fluxes associated with the rotated lateral mixing:
+      !!         zftw =-aht {  e2t*wslpi di[ mi(mk(tb)) ]
+      !!                     + e1t*wslpj dj[ mj(mk(tb)) ]  }
+      !!      take the horizontal divergence of the fluxes:
+      !!         difft = 1/(e1t*e2t*e3t) dk[ zftw ]
+      !!      Add this trend to the general trend (ta,sa):
+      !!         ta = ta + difft
+      !!
+      !! ** Action :   Update (ta,sa) arrays with the before rotated diffusion
+      !!            trend (except the dk[ dk[.] ] term)
+      !!----------------------------------------------------------------------
+
+      INTEGER, INTENT( in ) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   iku, ikv     ! temporary integer
+      REAL(wp) ::   zmsku, zabe1, zcof1, zcoef3, ztaad   ! temporary scalars
+      REAL(wp) ::   zmskv, zabe2, zcof2, zcoef4, zsaad   !    "         "
+      REAL(wp) ::   ztf3, ztf4, zsf3, zsf4               !
+      REAL(wp) ::   zcoef0, zbtr                       !    "         "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zdktad , zdk1tad, zftuad, zftvad   ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zdksad , zdk1sad, zfsuad, zfsvad   !  "     "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zditad, zdjtad, ztfwad     ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdisad, zdjsad, zsfwad     !  "      "
+      !!----------------------------------------------------------------------
+
+      zditad(:,:,:) = 0.0_wp ;  zdjtad(:,:,:) = 0.0_wp ;  ztfwad(:,:,:) = 0.0_wp
+      zdisad(:,:,:) = 0.0_wp ;  zdjsad(:,:,:) = 0.0_wp ;  zsfwad(:,:,:) = 0.0_wp
+
+      zdktad(:,:) = 0.0_wp ;  zdk1tad(:,:) = 0.0_wp   
+      zdksad(:,:) = 0.0_wp ;  zdk1sad(:,:) = 0.0_wp 
+
+      zftuad(:,:) = 0.0_wp ;  zftvad (:,:) = 0.0_wp 
+      zfsuad(:,:) = 0.0_wp ;  zfsvad (:,:) = 0.0_wp
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_ldf_iso_adj : rotated laplacian diffusion operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
+      ENDIF
+
+      !!----------------------------------------------------------------------
+      !!   III - vertical trend of T & S (extra diagonal terms only)
+      !!----------------------------------------------------------------------
+      ! I.5 Divergence of vertical fluxes added to the general tracer trend
+      ! -------------------------------------------------------------------
+
+      DO jk = jpkm1, 1, -1
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+               zbtr =  1.0_wp / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+               ztaad = ta_ad(ji,jj,jk) * zbtr
+               zsaad = sa_ad(ji,jj,jk) * zbtr
+
+               ztfwad(ji,jj,jk  ) = ztfwad(ji,jj,jk  ) + ztaad
+               ztfwad(ji,jj,jk+1) = ztfwad(ji,jj,jk+1) - ztaad
+               zsfwad(ji,jj,jk  ) = zsfwad(ji,jj,jk  ) + zsaad
+               zsfwad(ji,jj,jk+1) = zsfwad(ji,jj,jk+1) - zsaad
+            END DO
+         END DO
+      END DO
+      ! interior (2=<jk=<jpk-1)
+      DO jk = jpkm1, 2, -1
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+               zcoef0 = - fsahtw(ji,jj,jk) * tmask(ji,jj,jk)
+
+               zmsku = 1.0_wp / MAX(   umask(ji  ,jj,jk-1) + umask(ji-1,jj,jk)      &
+                  &                  + umask(ji-1,jj,jk-1) + umask(ji  ,jj,jk), 1.0_wp  )
+
+               zmskv = 1.0_wp / MAX(   vmask(ji,jj  ,jk-1) + vmask(ji,jj-1,jk)      &
+                  &                  + vmask(ji,jj-1,jk-1) + vmask(ji,jj  ,jk), 1.0_wp  )
+
+               ! *** NOTE ***  wslpi() and wslpj() are not linearized.
+
+               zcoef3 = zcoef0 * e2t(ji,jj) * zmsku * wslpi(ji,jj,jk)
+               zcoef4 = zcoef0 * e1t(ji,jj) * zmskv * wslpj(ji,jj,jk)
+
+               ztf3 = ztfwad(ji,jj,jk) * zcoef3
+               ztf4 = ztfwad(ji,jj,jk) * zcoef4
+               zsf3 = zsfwad(ji,jj,jk) * zcoef3
+               zsf4 = zsfwad(ji,jj,jk) * zcoef4
+
+               zditad(ji  ,jj  ,jk-1) = zditad(ji  ,jj  ,jk-1) + ztf3
+               zditad(ji-1,jj  ,jk  ) = zditad(ji-1,jj  ,jk  ) + ztf3
+               zditad(ji-1,jj  ,jk-1) = zditad(ji-1,jj  ,jk-1) + ztf3
+               zditad(ji  ,jj  ,jk  ) = zditad(ji  ,jj  ,jk  ) + ztf3
+
+               zdjtad(ji  ,jj  ,jk-1) = zdjtad(ji  ,jj  ,jk-1) + ztf4
+               zdjtad(ji  ,jj-1,jk  ) = zdjtad(ji  ,jj-1,jk  ) + ztf4
+               zdjtad(ji  ,jj-1,jk-1) = zdjtad(ji  ,jj-1,jk-1) + ztf4
+               zdjtad(ji  ,jj  ,jk  ) = zdjtad(ji  ,jj  ,jk  ) + ztf4
+
+               zdisad(ji  ,jj  ,jk-1) = zdisad(ji  ,jj  ,jk-1) + zsf3
+               zdisad(ji-1,jj  ,jk  ) = zdisad(ji-1,jj  ,jk  ) + zsf3
+               zdisad(ji-1,jj  ,jk-1) = zdisad(ji-1,jj  ,jk-1) + zsf3
+               zdisad(ji  ,jj  ,jk  ) = zdisad(ji  ,jj  ,jk  ) + zsf3
+
+               zdjsad(ji  ,jj  ,jk-1) = zdjsad(ji  ,jj  ,jk-1) + zsf4
+               zdjsad(ji  ,jj-1,jk  ) = zdjsad(ji  ,jj-1,jk  ) + zsf4
+               zdjsad(ji  ,jj-1,jk-1) = zdjsad(ji  ,jj-1,jk-1) + zsf4
+               zdjsad(ji  ,jj  ,jk  ) = zdjsad(ji  ,jj  ,jk  ) + zsf4
+
+               ztfwad(ji,jj,jk) = 0.0_wp
+               zsfwad(ji,jj,jk) = 0.0_wp
+            END DO
+         END DO
+      END DO
+ 
+      ! Local constant initialization
+      ! -----------------------------
+      ztfwad(1,:,:) = 0.0_wp     ;     ztfwad(jpi,:,:) = 0.0_wp
+      zsfwad(1,:,:) = 0.0_wp     ;     zsfwad(jpi,:,:) = 0.0_wp
+
+      ! Vertical fluxes
+      ! ---------------
+
+      ! Surface and bottom vertical fluxes set to zero
+      ztfwad(:,:, 1 ) = 0.0_wp   ;     ztfwad(:,:,jpk) = 0.0_wp
+      zsfwad(:,:, 1 ) = 0.0_wp   ;     zsfwad(:,:,jpk) = 0.0_wp
+
+      !!----------------------------------------------------------------------
+      !!   II - horizontal trend of T & S (full)
+      !!----------------------------------------------------------------------
+      
+      !                                                ! ===============
+      DO jk = jpkm1, 1, -1                             ! Horizontal slab
+         !                                             ! ===============
+         ! II.4 Second derivative (divergence) and add to the general trend
+         ! ----------------------------------------------------------------
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+
+               zbtr= 1.0_wp / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+               ztaad = ta_ad(ji,jj,jk) * zbtr
+               zsaad = sa_ad(ji,jj,jk) * zbtr
+
+               zftuad(ji  ,jj  ) = zftuad(ji  ,jj  ) + ztaad
+               zftuad(ji-1,jj  ) = zftuad(ji-1,jj  ) - ztaad
+               zftvad(ji  ,jj  ) = zftvad(ji  ,jj  ) + ztaad
+               zftvad(ji  ,jj-1) = zftvad(ji  ,jj-1) - ztaad
+
+               zfsuad(ji  ,jj  ) = zfsuad(ji  ,jj  ) + zsaad
+               zfsuad(ji-1,jj  ) = zfsuad(ji-1,jj  ) - zsaad
+               zfsvad(ji  ,jj  ) = zfsvad(ji  ,jj  ) + zsaad
+               zfsvad(ji  ,jj-1) = zfsvad(ji  ,jj-1) - zsaad
+
+            END DO
+         END DO
+
+         ! 2. Horizontal fluxes
+         ! --------------------
+         DO jj = jpjm1, 1, -1
+            DO ji = fs_jpim1, 1, -1   ! vector opt.
+               zabe1 = umask(ji,jj,jk) * ( fsahtu(ji,jj,jk) + ahtb0 ) &
+                  &                    * e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj)
+               zabe2 = vmask(ji,jj,jk) * ( fsahtv(ji,jj,jk) + ahtb0 ) &
+                  &                    * e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj)
+
+               zmsku = 1.0_wp / MAX(  tmask(ji+1,jj,jk  ) + tmask(ji,jj,jk+1)   &
+                  &                 + tmask(ji+1,jj,jk+1) + tmask(ji,jj,jk  ), 1.0_wp )
+
+               zmskv = 1.0_wp / MAX(  tmask(ji,jj+1,jk  ) + tmask(ji,jj,jk+1)   &
+                  &                 + tmask(ji,jj+1,jk+1) + tmask(ji,jj,jk  ), 1.0_wp )
+
+               ! *** NOTE ***  uslp() and vslp() are not linearized.
+
+               zcof1 = -fsahtu(ji,jj,jk) * e2u(ji,jj) * uslp(ji,jj,jk) * zmsku * umask(ji,jj,jk)
+               zcof2 = -fsahtv(ji,jj,jk) * e1v(ji,jj) * vslp(ji,jj,jk) * zmskv * vmask(ji,jj,jk)
+
+               zditad(ji,jj,jk) = zditad(ji,jj,jk) + zftuad(ji,jj) * zabe1
+
+               zdktad (ji+1,jj) = zdktad (ji+1,jj) + zftuad(ji,jj) * zcof1
+               zdktad (ji  ,jj) = zdktad (ji  ,jj) + zftuad(ji,jj) * zcof1
+               zdk1tad(ji  ,jj) = zdk1tad(ji  ,jj) + zftuad(ji,jj) * zcof1
+               zdk1tad(ji+1,jj) = zdk1tad(ji+1,jj) + zftuad(ji,jj) * zcof1
+               zftuad (ji  ,jj) = 0.0_wp
+               !
+               zdjtad(ji,jj,jk) = zdjtad(ji,jj,jk) + zftvad(ji,jj) * zabe2
+
+               zdktad (ji,jj+1) = zdktad (ji,jj+1) + zftvad(ji,jj) * zcof2
+               zdktad (ji,jj  ) = zdktad (ji,jj  ) + zftvad(ji,jj) * zcof2
+               zdk1tad(ji,jj  ) = zdk1tad(ji,jj  ) + zftvad(ji,jj) * zcof2
+               zdk1tad(ji,jj+1) = zdk1tad(ji,jj+1) + zftvad(ji,jj) * zcof2
+               zftvad (ji,jj  ) = 0.0_wp
+               !
+               zdisad(ji,jj,jk) = zdisad(ji,jj,jk) + zfsuad(ji,jj) * zabe1
+
+               zdksad (ji+1,jj) = zdksad (ji+1,jj) + zfsuad(ji,jj) * zcof1 
+               zdksad (ji  ,jj) = zdksad (ji  ,jj) + zfsuad(ji,jj) * zcof1 
+               zdk1sad(ji  ,jj) = zdk1sad(ji  ,jj) + zfsuad(ji,jj) * zcof1
+               zdk1sad(ji+1,jj) = zdk1sad(ji+1,jj) + zfsuad(ji,jj) * zcof1 
+               zfsuad (ji  ,jj) = 0.0_wp
+               !
+               zdjsad(ji,jj,jk) = zdjsad(ji,jj,jk) + zfsvad(ji,jj) * zabe2
+
+               zdksad (ji,jj+1) = zdksad (ji,jj+1) + zfsvad(ji,jj) * zcof2
+               zdksad (ji,jj  ) = zdksad (ji,jj  ) + zfsvad(ji,jj) * zcof2
+               zdk1sad(ji,jj  ) = zdk1sad(ji,jj  ) + zfsvad(ji,jj) * zcof2
+               zdk1sad(ji,jj+1) = zdk1sad(ji,jj+1) + zfsvad(ji,jj) * zcof2
+               zfsvad (ji,jj  ) = 0.0_wp
+
+            END DO
+         END DO
+
+         ! 1. Vertical tracer gradient at level jk and jk+1
+         ! ------------------------------------------------
+         ! surface boundary condition: zdkt(jk=1)=zdkt(jk=2)
+
+         IF( jk == 1 ) THEN
+
+            zdk1tad(:,:) = zdk1tad(:,:) + zdktad(:,:)
+            zdk1sad(:,:) = zdk1sad(:,:) + zdksad(:,:)
+
+            zdktad(:,:)  = 0.0_wp
+            zdksad(:,:)  = 0.0_wp
+
+         ELSE
+
+            tb_ad(:,:,jk-1) = tb_ad(:,:,jk-1) + zdktad(:,:) * tmask(:,:,jk)
+            tb_ad(:,:,jk  ) = tb_ad(:,:,jk  ) - zdktad(:,:) * tmask(:,:,jk)
+
+            sb_ad(:,:,jk-1) = sb_ad(:,:,jk-1) + zdksad(:,:) * tmask(:,:,jk)
+            sb_ad(:,:,jk  ) = sb_ad(:,:,jk  ) - zdksad(:,:) * tmask(:,:,jk)
+
+            zdktad(:,:) = 0.0_wp
+            zdksad(:,:) = 0.0_wp
+
+         ENDIF
+
+         tb_ad(:,:,jk  ) = tb_ad(:,:,jk  ) + zdk1tad(:,:) * tmask(:,:,jk+1)
+         tb_ad(:,:,jk+1) = tb_ad(:,:,jk+1) - zdk1tad(:,:) * tmask(:,:,jk+1)
+         
+         sb_ad(:,:,jk  ) = sb_ad(:,:,jk  ) + zdk1sad(:,:) * tmask(:,:,jk+1)
+         sb_ad(:,:,jk+1) = sb_ad(:,:,jk+1) - zdk1sad(:,:) * tmask(:,:,jk+1)
+         
+         zdk1tad(:,:) = 0.0_wp
+         zdk1sad(:,:) = 0.0_wp
+         !                                          ! ===============
+      END DO                                        !   End of slab  
+      !                                             ! ===============
+      !!----------------------------------------------------------------------
+      !!   I - masked horizontal derivative of T & S
+      !!----------------------------------------------------------------------
+      IF( ln_zps ) THEN      ! partial steps correction at the last level 
+         DO jj = jpjm1, 1, -1
+            DO ji = fs_jpim1, 1, -1   ! vector opt.
+
+               ! last level
+               iku = MIN( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1
+               ikv = MIN( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1
+
+               gtu_ad(ji,jj) = gtu_ad(ji,jj) + zditad(ji,jj,iku)
+               gtv_ad(ji,jj) = gtv_ad(ji,jj) + zdjtad(ji,jj,ikv)
+
+               gsu_ad(ji,jj) = gsu_ad(ji,jj) + zdisad(ji,jj,iku)
+               gsv_ad(ji,jj) = gsv_ad(ji,jj) + zdjsad(ji,jj,ikv)
+
+               zditad(ji,jj,iku) = 0.0_wp
+               zdjtad(ji,jj,ikv) = 0.0_wp
+
+               zdisad(ji,jj,iku) = 0.0_wp
+               zdjsad(ji,jj,ikv) = 0.0_wp
+ 
+           END DO
+         END DO
+      ENDIF
+
+      ! Horizontal temperature and salinity gradient 
+      DO jk = jpkm1, 1, -1
+         DO jj = jpjm1, 1, -1
+            DO ji = fs_jpim1, 1, -1   ! vector opt.
+
+               zditad(ji,jj,jk) = zditad(ji,jj,jk) * umask(ji,jj,jk)
+               zdjtad(ji,jj,jk) = zdjtad(ji,jj,jk) * vmask(ji,jj,jk)
+               zdisad(ji,jj,jk) = zdisad(ji,jj,jk) * umask(ji,jj,jk)
+               zdjsad(ji,jj,jk) = zdjsad(ji,jj,jk) * vmask(ji,jj,jk)
+
+               tb_ad(ji+1,jj  ,jk) = tb_ad(ji+1,jj  ,jk) + zditad(ji,jj,jk)
+               tb_ad(ji  ,jj  ,jk) = tb_ad(ji  ,jj  ,jk) - zditad(ji,jj,jk)
+               tb_ad(ji  ,jj+1,jk) = tb_ad(ji  ,jj+1,jk) + zdjtad(ji,jj,jk)
+               tb_ad(ji  ,jj  ,jk) = tb_ad(ji  ,jj  ,jk) - zdjtad(ji,jj,jk)
+
+               sb_ad(ji+1,jj  ,jk) = sb_ad(ji+1,jj  ,jk) + zdisad(ji,jj,jk)
+               sb_ad(ji  ,jj  ,jk) = sb_ad(ji  ,jj  ,jk) - zdisad(ji,jj,jk)
+               sb_ad(ji  ,jj+1,jk) = sb_ad(ji  ,jj+1,jk) + zdjsad(ji,jj,jk)
+               sb_ad(ji  ,jj  ,jk) = sb_ad(ji  ,jj  ,jk) - zdjsad(ji,jj,jk)
+
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE tra_ldf_iso_adj
+
+   SUBROUTINE tra_ldf_iso_adj_tst ( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE example_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_T,       &
+         & zsp1_S,       &
+         & zsp2,         & ! scalar product involving the adjoint routine
+         & zsp2_1,       &
+         & zsp2_2,       &
+         & zsp2_3,       &
+         & zsp2_4,       &
+         & zsp2_5,       &
+         & zsp2_6,       &
+         & zsp2_7,       &
+         & zsp2_8,       &
+         & zsp2_T,       &
+         & zsp2_S
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & ztb_tlin ,      & ! Tangent input
+         & zsb_tlin ,      & ! Tangent input
+         & zta_tlin ,      & ! Tangent input
+         & zsa_tlin ,      & ! Tangent input
+         & zta_tlout,      & ! Tangent output
+         & zsa_tlout,      & ! Tangent output
+         & zta_adin,       & ! Adjoint input
+         & zsa_adin,       & ! Adjoint input
+         & ztb_adout ,     & ! Adjoint output
+         & zsb_adout ,     & ! Adjoint output
+         & zta_adout ,     & ! Adjoint output
+         & zsa_adout ,     & ! Adjoint output
+         & z3r               ! 3D random field 
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zgtu_tlin ,     & ! Tangent input
+         & zgsu_tlin ,     & ! Tangent input
+         & zgtv_tlin ,     & ! Tangent input
+         & zgsv_tlin ,     & ! Tangent input
+         & zgtu_adout ,    & ! Adjoint output
+         & zgsu_adout ,    & ! Adjoint output
+         & zgtv_adout ,    & ! Adjoint output
+         & zgsv_adout ,    & ! Adjoint output
+         & z2r               ! 2D random field 
+      CHARACTER(LEN=14) :: cl_name
+      ! Allocate memory
+
+      ALLOCATE( &
+         & ztb_tlin(jpi,jpj,jpk),      & 
+         & zsb_tlin(jpi,jpj,jpk),      & 
+         & zta_tlin(jpi,jpj,jpk),      & 
+         & zsa_tlin(jpi,jpj,jpk),      & 
+         & zgtu_tlin(jpi,jpj),         & 
+         & zgsu_tlin(jpi,jpj),         & 
+         & zgtv_tlin(jpi,jpj),         & 
+         & zgsv_tlin(jpi,jpj),         & 
+         & zta_tlout(jpi,jpj,jpk),     & 
+         & zsa_tlout(jpi,jpj,jpk),     & 
+         & zta_adin(jpi,jpj,jpk),      & 
+         & zsa_adin(jpi,jpj,jpk),      & 
+         & ztb_adout(jpi,jpj,jpk),     & 
+         & zsb_adout(jpi,jpj,jpk),     & 
+         & zta_adout(jpi,jpj,jpk),     & 
+         & zsa_adout(jpi,jpj,jpk),     & 
+         & zgtu_adout(jpi,jpj),        & 
+         & zgsu_adout(jpi,jpj),        & 
+         & zgtv_adout(jpi,jpj),        & 
+         & zgsv_adout(jpi,jpj),        & 
+         & z3r(jpi,jpj,jpk),           &
+         & z2r(jpi,jpj)                &
+         & )
+
+      ! Initialize the reference state
+      uslp (:,:,:) = 2.0_wp
+      vslp (:,:,:) = 3.0_wp
+      wslpi(:,:,:) = 4.0_wp
+      wslpj(:,:,:) = 5.0_wp
+
+      !=======================================================================
+      ! 1) dx = ( tb_tl, ta_tl, sb_tl, sa_tl, gtu_tl, gtv_tl, gsu_tl, gsv_tl )
+      !    dy = ( ta_tl, sa_tl )
+      !=======================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+
+      ztb_tlin(:,:,:)  = 0.0_wp
+      zsb_tlin(:,:,:)  = 0.0_wp
+      zta_tlin(:,:,:)  = 0.0_wp
+      zsa_tlin(:,:,:)  = 0.0_wp
+      zgtu_tlin(:,:)   = 0.0_wp
+      zgsu_tlin(:,:)   = 0.0_wp
+      zgtv_tlin(:,:)   = 0.0_wp
+      zgsv_tlin(:,:)   = 0.0_wp
+      zta_tlout(:,:,:) = 0.0_wp
+      zsa_tlout(:,:,:) = 0.0_wp
+      zta_adin(:,:,:)  = 0.0_wp
+      zsa_adin(:,:,:)  = 0.0_wp
+      ztb_adout(:,:,:) = 0.0_wp
+      zsb_adout(:,:,:) = 0.0_wp
+      zta_adout(:,:,:) = 0.0_wp
+      zsa_adout(:,:,:) = 0.0_wp
+      zgtu_adout(:,:)  = 0.0_wp
+      zgsu_adout(:,:)  = 0.0_wp
+      zgtv_adout(:,:)  = 0.0_wp
+      zgsv_adout(:,:)  = 0.0_wp
+
+      tb_tl(:,:,:) = 0.0_wp
+      sb_tl(:,:,:) = 0.0_wp
+      ta_tl(:,:,:) = 0.0_wp
+      sa_tl(:,:,:) = 0.0_wp
+      gtu_tl(:,:)  = 0.0_wp
+      gsu_tl(:,:)  = 0.0_wp
+      gtv_tl(:,:)  = 0.0_wp
+      gsv_tl(:,:)  = 0.0_wp
+      tb_ad(:,:,:) = 0.0_wp
+      sb_ad(:,:,:) = 0.0_wp
+      ta_ad(:,:,:) = 0.0_wp
+      sa_ad(:,:,:) = 0.0_wp
+      gtu_ad(:,:)  = 0.0_wp
+      gsu_ad(:,:)  = 0.0_wp
+      gtv_ad(:,:)  = 0.0_wp
+      gsv_ad(:,:)  = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              ztb_tlin(ji,jj,jk) = z3r(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 727391 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stds ) 
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsb_tlin(ji,jj,jk) = z3r(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 249741 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zta_tlin(ji,jj,jk) = z3r(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 182029 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stds )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsa_tlin(ji,jj,jk) = z3r(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z2r, 'U', 0.0_wp, stds )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zgtu_tlin(ji,jj) = z2r(ji,jj) 
+         END DO
+      END DO 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 727391 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z2r, 'U', 0.0_wp, stds ) 
+      DO jj = nldj, nlej
+        DO ji = nldi, nlei
+           zgsu_tlin(ji,jj) = z2r(ji,jj) 
+        END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 249741 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z2r, 'V', 0.0_wp, stds )
+      DO jj = nldj, nlej
+        DO ji = nldi, nlei
+           zgtv_tlin(ji,jj) = z2r(ji,jj) 
+        END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 182029 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z2r, 'V', 0.0_wp, stds ) 
+      DO jj = nldj, nlej
+        DO ji = nldi, nlei
+           zgsv_tlin(ji,jj) = z2r(ji,jj) 
+        END DO
+      END DO
+
+      tb_tl(:,:,:) = ztb_tlin(:,:,:) 
+      sb_tl(:,:,:) = zsb_tlin(:,:,:) 
+      ta_tl(:,:,:) = zta_tlin(:,:,:) 
+      sa_tl(:,:,:) = zsa_tlin(:,:,:) 
+      gtu_tl(:,:)  = zgtu_tlin(:,:)
+      gsu_tl(:,:)  = zgsu_tlin(:,:)
+      gtv_tl(:,:)  = zgtv_tlin(:,:)
+      gsv_tl(:,:)  = zgsv_tlin(:,:)
+
+      CALL tra_ldf_iso_tan( nit000 ) 
+      
+      zta_tlout(:,:,:) = ta_tl(:,:,:)
+      zsa_tlout(:,:,:) = sa_tl(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsa_adin(ji,jj,jk) = zsa_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_s(jk)
+              zta_adin(ji,jj,jk) = zta_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_t(jk)
+            END DO
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1_T = DOT_PRODUCT( zta_tlout, zta_adin )
+      zsp1_S = DOT_PRODUCT( zsa_tlout, zsa_adin )
+      zsp1 = zsp1_T + zsp1_S
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      ta_ad(:,:,:) = zta_adin(:,:,:)
+      sa_ad(:,:,:) = zsa_adin(:,:,:)
+
+      CALL tra_ldf_iso_adj( nit000 ) 
+
+      ztb_adout(:,:,:) = tb_ad(:,:,:)
+      zsb_adout(:,:,:) = sb_ad(:,:,:)
+      zta_adout(:,:,:) = ta_ad(:,:,:)
+      zsa_adout(:,:,:) = sa_ad(:,:,:)
+      zgtu_adout(:,:)  = gtu_ad(:,:)
+      zgsu_adout(:,:)  = gsu_ad(:,:)
+      zgtv_adout(:,:)  = gtv_ad(:,:)
+      zgsv_adout(:,:)  = gsv_ad(:,:)
+          
+      zsp2_1 = DOT_PRODUCT( ztb_tlin , ztb_adout  )
+      zsp2_2 = DOT_PRODUCT( zta_tlin , zta_adout  )
+      zsp2_3 = DOT_PRODUCT( zgtu_tlin, zgtu_adout )
+      zsp2_4 = DOT_PRODUCT( zgtv_tlin, zgtv_adout )
+      zsp2_5 = DOT_PRODUCT( zsb_tlin , zsb_adout  )
+      zsp2_6 = DOT_PRODUCT( zsa_tlin , zsa_adout  )
+      zsp2_7 = DOT_PRODUCT( zgsu_tlin, zgsu_adout )
+      zsp2_8 = DOT_PRODUCT( zgsv_tlin, zgsv_adout ) 
+
+      zsp2_T = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4
+      zsp2_S = zsp2_5 + zsp2_6 + zsp2_7 + zsp2_8
+      zsp2   = zsp2_T + zsp2_S
+
+      cl_name = 'tra_ldf_iso_ad'
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      DEALLOCATE(         &
+         & ztb_tlin,      & ! Tangent input
+         & zsb_tlin,      & ! Tangent input
+         & zta_tlin,      & ! Tangent input
+         & zsa_tlin,      & ! Tangent input
+         & zgtu_tlin,     & ! Tangent input
+         & zgsu_tlin,     & ! Tangent input
+         & zgtv_tlin,     & ! Tangent input
+         & zgsv_tlin,     & ! Tangent input
+         & zta_tlout,     & ! Tangent output
+         & zsa_tlout,     & ! Tangent output
+         & zta_adin,      & ! Adjoint input
+         & zsa_adin,      & ! Adjoint input
+         & ztb_adout,     & ! Adjoint output
+         & zsb_adout,     & ! Adjoint output
+         & zta_adout,     & ! Adjoint output
+         & zsa_adout,     & ! Adjoint output
+         & zgtu_adout,    & ! Adjoint output
+         & zgsu_adout,    & ! Adjoint output
+         & zgtv_adout,    & ! Adjoint output
+         & zgsv_adout,    & ! Adjoint output
+         & z3r,           & ! 3D random field 
+         & z2r            &
+         & )
+      
+   END SUBROUTINE tra_ldf_iso_adj_tst
+# else
+   !!----------------------------------------------------------------------
+   !!   default option :   Dummy code   NO rotation of the diffusive tensor
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE tra_ldf_iso_tan( kt )               ! Empty routine
+      WRITE(*,*) 'tra_ldf_iso_tan: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_ldf_iso_tan
+   SUBROUTINE tra_ldf_iso_adj( kt )               ! Empty routine
+      WRITE(*,*) 'tra_ldf_iso_adj: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_ldf_iso_adj
+   SUBROUTINE tra_ldf_iso_adj_tst ( kumadt )
+      WRITE(*,*) 'tra_ldf_iso_adj_tst: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_ldf_iso_adj_tst
+# endif
+#endif
+
+   !!==============================================================================
+END MODULE traldf_iso_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traldf_lap_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traldf_lap_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traldf_lap_tam.F90	(revision 2578)
@@ -0,0 +1,1634 @@
+MODULE traldf_lap_tam
+#if defined key_tam
+   !!==============================================================================
+   !!                       ***  MODULE  traldf_lap  ***
+   !! Ocean active tracers:  horizontal component of the lateral tracer mixing trend
+   !!                        Tangent and adjoint module
+   !!==============================================================================
+   !! History :   9.0  !  ?????
+   !! History of the T&A module:
+   !!             9.0  !  09-03  (F. Vigilant) original version
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_ldf_lap  : update the tracer trend with the horizontal diffusion
+   !!                 using a iso-level harmonic (laplacien) operator.
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpiglo,              &
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1
+   USE oce_tam       , ONLY: & ! ocean dynamics and active tracers
+      & tb_tl,               &
+      & sb_tl,               &
+      & ta_tl,               &
+      & sa_tl,               &
+      & gtu_tl,              &
+      & gsu_tl,              &
+      & gtv_tl,              &
+      & gsv_tl,              &
+      & tb_ad,               &
+      & sb_ad,               &
+      & ta_ad,               &
+      & sa_ad,               &
+      & gtu_ad,              &
+      & gsu_ad,              &
+      & gtv_ad,              &
+      & gsv_ad
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+      & e1t,                 &
+      & e2t,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3u,                 &
+      & e3v,                 &
+      & e3t,                 &
+#endif
+      & tmask,               &
+      & umask,               &
+      & vmask,               &
+      & mbathy,              &
+      & ln_zps,              &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      &  lk_vvl
+   USE ldftra_oce    , ONLY: & ! ocean active tracers: lateral physics
+      & ahtv,                &
+      & ahtu,                &
+      & ahtw,                &
+      & ahtb0,               &
+      & aht0
+!   USE trdmod          ! ocean active tracers trends 
+!   USE trdmod_oce      ! ocean variables trends
+   USE in_out_manager, ONLY: & ! I/O manager
+      & lwp,                 &
+      & numout,              &
+      & nitend,              &
+      & nit000,              &
+      & nstop
+!   USE diaptr          ! poleward transport diagnostics
+!   USE prtctl          ! Print control
+
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          & !
+      & prntst_tlm,          & !
+      & stdt,                & ! stdev for u-velocity
+      & stds                   !           v-velocity
+   USE paresp        , ONLY: & ! Weights for an energy-type scalar product
+      & wesp_t,              &
+      & wesp_s
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC tra_ldf_lap_tan      ! routine called by tradldf_tam.F90
+   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
+#  include "domzgr_substitute.h90"
+#  include "ldftra_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Id: traldf_lap.F90 1152 2008-06-26 14:11:13Z rblod $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   
+CONTAINS
+
+   SUBROUTINE tra_ldf_lap_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_ldf_lap_tan  ***
+      !!                   
+      !! ** Purpose :   Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   Second order diffusive operator evaluated using before
+      !!      fields (forward time scheme). The horizontal diffusive trends of 
+      !!      temperature (idem for salinity) is given by:
+      !!          difft = 1/(e1t*e2t*e3t) {  di-1[ aht e2u*e3u/e1u di(tb) ]
+      !!                                   + dj-1[ aht e1v*e3v/e2v dj(tb) ] }
+      !!     Note: key_zco defined, the e3t=e3u=e3v, the trend becomes:  
+      !!          difft = 1/(e1t*e2t) {  di-1[ aht e2u/e1u di(tb) ]
+      !!                               + dj-1[ aht e1v/e2v dj(tb) ] }
+      !!      Add this trend to the general tracer trend (ta,sa):
+      !!          (ta,sa) = (ta,sa) + ( difft , diffs )
+      !!
+      !! ** Action  : - Update (ta,sa) arrays with the before iso-level 
+      !!                harmonic mixing trend.
+      !!
+      !! History :
+      !!   1.0  !  87-06  (P. Andrich, D. L Hostis)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  95-11  (G. Madec)  suppress volumetric scale factors
+      !!        !  96-01  (G. Madec)  statement function for e3
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-08  (C. Talandier) New trends organization
+      !!        !  05-11  (G. Madec)  add zps case
+      !! History of the tangent routine
+      !!   9.0  !  03-09 (F. Vigilant) tangent of 9.0
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+      
+      !! * Local save
+      REAL(wp), DIMENSION(jpi,jpj), SAVE ::   &
+      &   ze1ur, ze2vr, zbtr2              ! scale factor coefficients
+      
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk             ! dummy loop indices
+      INTEGER  ::   iku, ikv               ! temporary integers
+      REAL(wp) ::  zabe1, zabe2, zbtr      ! temporary scalars
+      REAL(wp) ::  ztatl, zsatl            ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  ztutl, ztvtl     ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  zsutl, zsvtl     ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_ldf_lap_tan : iso-level laplacian diffusion'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+         ze1ur(:,:) = e2u(:,:) / e1u(:,:)
+         ze2vr(:,:) = e1v(:,:) / e2v(:,:)
+         zbtr2(:,:) = 1. / ( e1t(:,:) * e2t(:,:) )
+      ENDIF
+      
+      !                                                  ! =============
+      DO jk = 1, jpkm1                                   ! Vertical slab
+         !                                               ! =============
+         ! 1. First derivative (gradient)
+         ! -------------------
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+#if defined key_zco
+               zabe1 = fsahtu(ji,jj,jk) * umask(ji,jj,jk) * ze1ur(ji,jj)
+               zabe2 = fsahtv(ji,jj,jk) * vmask(ji,jj,jk) * ze2vr(ji,jj)
+#else
+               zabe1 = fsahtu(ji,jj,jk) * umask(ji,jj,jk) * ze1ur(ji,jj) * fse3u(ji,jj,jk)
+               zabe2 = fsahtv(ji,jj,jk) * vmask(ji,jj,jk) * ze2vr(ji,jj) * fse3v(ji,jj,jk)
+#endif
+               ztutl(ji,jj,jk) = zabe1 * ( tb_tl(ji+1,jj  ,jk) - tb_tl(ji,jj,jk) )
+               zsutl(ji,jj,jk) = zabe1 * ( sb_tl(ji+1,jj  ,jk) - sb_tl(ji,jj,jk) )
+               ztvtl(ji,jj,jk) = zabe2 * ( tb_tl(ji  ,jj+1,jk) - tb_tl(ji,jj,jk) )
+               zsvtl(ji,jj,jk) = zabe2 * ( sb_tl(ji  ,jj+1,jk) - sb_tl(ji,jj,jk) )
+            END DO  
+         END DO  
+         IF( ln_zps ) THEN      ! set gradient at partial step level
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  ! last level
+                  iku = MIN ( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1
+                  ikv = MIN ( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1
+                  IF( iku == jk ) THEN
+                     zabe1 = fsahtu(ji,jj,iku) * umask(ji,jj,iku) * ze1ur(ji,jj) * fse3u(ji,jj,iku)
+                     ztutl(ji,jj,jk) = zabe1 * gtu_tl(ji,jj)
+                     zsutl(ji,jj,jk) = zabe1 * gsu_tl(ji,jj)
+                  ENDIF
+                  IF( ikv == jk ) THEN
+                     zabe2 = fsahtv(ji,jj,ikv) * vmask(ji,jj,ikv) * ze2vr(ji,jj) * fse3v(ji,jj,ikv)
+                     ztvtl(ji,jj,jk) = zabe2 * gtv_tl(ji,jj)
+                     zsvtl(ji,jj,jk) = zabe2 * gsv_tl(ji,jj)
+                  ENDIF
+               END DO
+            END DO
+         ENDIF
+         
+         
+         ! 2. Second derivative (divergence)
+         ! --------------------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+               zbtr = zbtr2(ji,jj)
+#else
+               zbtr = zbtr2(ji,jj) / fse3t(ji,jj,jk)
+#endif
+               ! horizontal diffusive trends
+               ztatl = zbtr * (  ztutl(ji,jj,jk) - ztutl(ji-1,jj  ,jk)   &
+                  &            + ztvtl(ji,jj,jk) - ztvtl(ji  ,jj-1,jk)  )
+               zsatl = zbtr * (  zsutl(ji,jj,jk) - zsutl(ji-1,jj  ,jk)   &
+                  &            + zsvtl(ji,jj,jk) - zsvtl(ji  ,jj-1,jk)  )
+               ! add it to the general tracer trends
+               ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) + ztatl
+               sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) + zsatl
+            END DO  
+         END DO  
+         !                                               ! =============
+      END DO                                             !  End of slab  
+      !                                                  ! =============
+
+      ! "zonal" mean lateral diffusive heat and salt transport 
+      ! Warning: no update of pht_ldf and /pst_ldf/ when /ln_diaptr/ is activated
+
+   END SUBROUTINE tra_ldf_lap_tan
+
+
+   SUBROUTINE tra_ldf_lap_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_ldf_lap_adj  ***
+      !!                   
+      !! ** Purpose :   Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   Second order diffusive operator evaluated using before
+      !!      fields (forward time scheme). The horizontal diffusive trends of 
+      !!      temperature (idem for salinity) is given by:
+      !!          difft = 1/(e1t*e2t*e3t) {  di-1[ aht e2u*e3u/e1u di(tb) ]
+      !!                                   + dj-1[ aht e1v*e3v/e2v dj(tb) ] }
+      !!     Note: key_zco defined, the e3t=e3u=e3v, the trend becomes:  
+      !!          difft = 1/(e1t*e2t) {  di-1[ aht e2u/e1u di(tb) ]
+      !!                               + dj-1[ aht e1v/e2v dj(tb) ] }
+      !!      Add this trend to the general tracer trend (ta,sa):
+      !!          (ta,sa) = (ta,sa) + ( difft , diffs )
+      !!
+      !! ** Action  : - Update (ta,sa) arrays with the before iso-level 
+      !!                harmonic mixing trend.
+      !!
+      !! History :
+      !!   1.0  !  87-06  (P. Andrich, D. L Hostis)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  95-11  (G. Madec)  suppress volumetric scale factors
+      !!        !  96-01  (G. Madec)  statement function for e3
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-08  (C. Talandier) New trends organization
+      !!        !  05-11  (G. Madec)  add zps case
+      !! History of the tangent routine
+      !!   9.0  !  03-09 (F. Vigilant) adjoint of 9.0
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+      
+      !! * Local save
+      REAL(wp), DIMENSION(jpi,jpj), SAVE ::   &
+      &   ze1ur, ze2vr, zbtr2              ! scale factor coefficients
+      
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk             ! dummy loop indices
+      INTEGER ::   iku, ikv               ! temporary integers
+      REAL(wp) ::  zabe1, zabe2, zbtr     ! temporary scalars
+      REAL(wp) ::  ztaad, zsaad           ! temporary scalars    
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ztuad, ztvad    ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zsuad, zsvad    ! 3D workspace
+      !!----------------------------------------------------------------------
+      ztvad(:,:,:) = 0.0_wp 
+      zsvad(:,:,:) = 0.0_wp
+      ztuad(:,:,:) = 0.0_wp
+      zsuad(:,:,:) = 0.0_wp
+      ztaad        = 0.0_wp
+      zsaad        = 0.0_wp
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_ldf_lap_adj : iso-level laplacian diffusion'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+         ze1ur(:,:) = e2u(:,:) / e1u(:,:)
+         ze2vr(:,:) = e1v(:,:) / e2v(:,:)
+         zbtr2(:,:) = 1. / ( e1t(:,:) * e2t(:,:) )
+      ENDIF      
+
+
+         
+      !                                                  ! =============
+      DO jk = 1, jpkm1                                   ! Vertical slab
+         !                                               ! =============
+
+         ! 2. Second derivative (divergence)
+         ! --------------------
+         DO jj = jpjm1, 2, -1
+            DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+#if defined key_zco
+               zbtr = zbtr2(ji,jj)
+#else
+               zbtr = zbtr2(ji,jj) / fse3t(ji,jj,jk)
+#endif
+               ! horizontal diffusive trends
+               ztaad             = zbtr * ta_ad(ji,jj,jk)
+               zsaad             = zbtr * sa_ad(ji,jj,jk)
+
+               ztuad(ji  ,jj  ,jk) = ztuad(ji  ,jj  ,jk) + ztaad
+               ztuad(ji-1,jj  ,jk) = ztuad(ji-1,jj  ,jk) - ztaad
+               ztvad(ji  ,jj  ,jk) = ztvad(ji  ,jj  ,jk) + ztaad
+               ztvad(ji  ,jj-1,jk) = ztvad(ji  ,jj-1,jk) - ztaad
+
+               zsuad(ji  ,jj  ,jk) = zsuad(ji  ,jj  ,jk) + zsaad
+               zsuad(ji-1,jj  ,jk) = zsuad(ji-1,jj  ,jk) - zsaad
+               zsvad(ji  ,jj  ,jk) = zsvad(ji  ,jj  ,jk) + zsaad
+               zsvad(ji  ,jj-1,jk) = zsvad(ji  ,jj-1,jk) - zsaad
+
+               !ztaad   = 0.0_wp
+               !zsaad   = 0.0_wp
+
+            END DO  
+         END DO  
+
+         ! 1. First derivative (gradient)
+         ! -------------------
+
+         IF( ln_zps ) THEN      ! set gradient at partial step level
+            DO jj = jpjm1, 1, -1
+               DO ji = fs_jpim1, 1, -1   ! vector opt.?
+                  ! last level
+                  iku = MIN ( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1
+                  ikv = MIN ( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1
+                  IF( iku == jk ) THEN
+                     zabe1 = fsahtu(ji,jj,iku) * umask(ji,jj,iku) * ze1ur(ji,jj) * fse3u(ji,jj,iku)
+
+                     gtu_ad(ji,jj) = zabe1 * ztuad(ji,jj,jk) + gtu_ad(ji,jj)
+                     gsu_ad(ji,jj) = zabe1 * zsuad(ji,jj,jk) + gsu_ad(ji,jj) 
+ 
+                     ztuad(ji,jj,jk)  = 0.0_wp
+                     zsuad(ji,jj,jk)  = 0.0_wp
+                  ENDIF
+                  IF( ikv == jk ) THEN
+                     zabe2 = fsahtv(ji,jj,ikv) * vmask(ji,jj,ikv) * ze2vr(ji,jj) * fse3v(ji,jj,ikv)
+
+                     gtv_ad(ji,jj) = zabe2 * ztvad(ji,jj,jk) + gtv_ad(ji,jj)
+                     gsv_ad(ji,jj) = zabe2 * zsvad(ji,jj,jk) + gsv_ad(ji,jj)
+
+                     ztvad(ji,jj,jk)  = 0.0_wp
+                     zsvad(ji,jj,jk)  = 0.0_wp
+                  ENDIF
+               END DO
+            END DO
+         ENDIF
+
+         DO jj = jpjm1, 1, -1
+            DO ji = fs_jpim1, 1, -1   ! vector opt. ?
+#if defined key_zco
+               zabe1 = fsahtu(ji,jj,jk) * umask(ji,jj,jk) * ze1ur(ji,jj)
+               zabe2 = fsahtv(ji,jj,jk) * vmask(ji,jj,jk) * ze2vr(ji,jj)
+#else
+               zabe1 = fsahtu(ji,jj,jk) * umask(ji,jj,jk) * ze1ur(ji,jj) * fse3u(ji,jj,jk)
+               zabe2 = fsahtv(ji,jj,jk) * vmask(ji,jj,jk) * ze2vr(ji,jj) * fse3v(ji,jj,jk)
+#endif
+               
+               tb_ad(ji  ,jj  ,jk) = tb_ad(ji  ,jj  ,jk) - (zabe1 * ztuad(ji,jj,jk) + zabe2 * ztvad(ji,jj,jk))
+               tb_ad(ji+1,jj  ,jk) = tb_ad(ji+1,jj  ,jk) +  zabe1 * ztuad(ji,jj,jk)
+               tb_ad(ji  ,jj+1,jk) = tb_ad(ji  ,jj+1,jk) +  zabe2 * ztvad(ji,jj,jk)
+
+               sb_ad(ji  ,jj  ,jk) = sb_ad(ji  ,jj  ,jk) - (zabe1 * zsuad(ji,jj,jk) + zabe2 * zsvad(ji,jj,jk))
+               sb_ad(ji+1,jj  ,jk) = sb_ad(ji+1,jj  ,jk) +  zabe1 * zsuad(ji,jj,jk)
+               sb_ad(ji  ,jj+1,jk) = sb_ad(ji  ,jj+1,jk) +  zabe2 * zsvad(ji,jj,jk)
+
+               ztuad(ji,jj,jk)   = 0.0_wp
+               zsuad(ji,jj,jk)   = 0.0_wp
+               ztvad(ji,jj,jk)   = 0.0_wp
+               zsvad(ji,jj,jk)   = 0.0_wp
+
+            END DO  
+         END DO  
+         
+          !                                               ! =============
+      END DO                                              !  End of slab  
+      !                                                   ! =============                    
+
+   END SUBROUTINE tra_ldf_lap_adj
+
+
+   SUBROUTINE tra_ldf_lap_adj_tst ( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE example_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_T,       &
+         & zsp1_S,       &
+         & zsp2,         & ! scalar product involving the adjoint routine
+         & zsp2_1,       &
+         & zsp2_2,       &
+         & zsp2_3,       &
+         & zsp2_4,       &
+         & zsp2_5,       &
+         & zsp2_6,       &
+         & zsp2_7,       &
+         & zsp2_8,       &
+         & zsp2_T,       &
+         & zsp2_S
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & ztb_tlin ,      & ! Tangent input
+         & zsb_tlin ,      & ! Tangent input
+         & zta_tlin ,      & ! Tangent input
+         & zsa_tlin ,      & ! Tangent input
+         & zta_tlout,      & ! Tangent output
+         & zsa_tlout,      & ! Tangent output
+         & zta_adin,       & ! Adjoint input
+         & zsa_adin,       & ! Adjoint input
+         & ztb_adout ,     & ! Adjoint output
+         & zsb_adout ,     & ! Adjoint output
+         & zta_adout ,     & ! Adjoint output
+         & zsa_adout ,     & ! Adjoint output
+         & z3r               ! 3D random field 
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zgtu_tlin ,     & ! Tangent input
+         & zgsu_tlin ,     & ! Tangent input
+         & zgtv_tlin ,     & ! Tangent input
+         & zgsv_tlin ,     & ! Tangent input
+         & zgtu_adout ,    & ! Adjoint output
+         & zgsu_adout ,    & ! Adjoint output
+         & zgtv_adout ,    & ! Adjoint output
+         & zgsv_adout ,    & ! Adjoint output
+         & z2r               ! 2D random field 
+      CHARACTER(LEN=14) :: cl_name
+      ! Allocate memory
+
+      ALLOCATE( &
+         & ztb_tlin(jpi,jpj,jpk),      & 
+         & zsb_tlin(jpi,jpj,jpk),      & 
+         & zta_tlin(jpi,jpj,jpk),      & 
+         & zsa_tlin(jpi,jpj,jpk),      & 
+         & zgtu_tlin(jpi,jpj),         & 
+         & zgsu_tlin(jpi,jpj),         & 
+         & zgtv_tlin(jpi,jpj),         & 
+         & zgsv_tlin(jpi,jpj),         & 
+         & zta_tlout(jpi,jpj,jpk),     & 
+         & zsa_tlout(jpi,jpj,jpk),     & 
+         & zta_adin(jpi,jpj,jpk),      & 
+         & zsa_adin(jpi,jpj,jpk),      & 
+         & ztb_adout(jpi,jpj,jpk),     & 
+         & zsb_adout(jpi,jpj,jpk),     & 
+         & zta_adout(jpi,jpj,jpk),     & 
+         & zsa_adout(jpi,jpj,jpk),     & 
+         & zgtu_adout(jpi,jpj),        & 
+         & zgsu_adout(jpi,jpj),        & 
+         & zgtv_adout(jpi,jpj),        & 
+         & zgsv_adout(jpi,jpj),        & 
+         & z3r(jpi,jpj,jpk),           &
+         & z2r(jpi,jpj)                &
+         & )
+
+
+      !=======================================================================
+      ! 1) dx = ( tb_tl, ta_tl, sb_tl, sa_tl, gtu_tl, gtv_tl, gsu_tl, gsv_tl )
+      !    dy = ( ta_tl, sa_tl )
+      !=======================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+
+      ztb_tlin(:,:,:)  = 0.0_wp
+      zsb_tlin(:,:,:)  = 0.0_wp
+      zta_tlin(:,:,:)  = 0.0_wp
+      zsa_tlin(:,:,:)  = 0.0_wp
+      zgtu_tlin(:,:)   = 0.0_wp
+      zgsu_tlin(:,:)   = 0.0_wp
+      zgtv_tlin(:,:)   = 0.0_wp
+      zgsv_tlin(:,:)   = 0.0_wp
+      zta_tlout(:,:,:) = 0.0_wp
+      zsa_tlout(:,:,:) = 0.0_wp
+      zta_adin(:,:,:)  = 0.0_wp
+      zsa_adin(:,:,:)  = 0.0_wp
+      ztb_adout(:,:,:) = 0.0_wp
+      zsb_adout(:,:,:) = 0.0_wp
+      zta_adout(:,:,:) = 0.0_wp
+      zsa_adout(:,:,:) = 0.0_wp
+      zgtu_adout(:,:)  = 0.0_wp
+      zgsu_adout(:,:)  = 0.0_wp
+      zgtv_adout(:,:)  = 0.0_wp
+      zgsv_adout(:,:)  = 0.0_wp
+
+      tb_tl(:,:,:) = 0.0_wp
+      sb_tl(:,:,:) = 0.0_wp
+      ta_tl(:,:,:) = 0.0_wp
+      sa_tl(:,:,:) = 0.0_wp
+      gtu_tl(:,:)  = 0.0_wp
+      gsu_tl(:,:)  = 0.0_wp
+      gtv_tl(:,:)  = 0.0_wp
+      gsv_tl(:,:)  = 0.0_wp
+      tb_ad(:,:,:) = 0.0_wp
+      sb_ad(:,:,:) = 0.0_wp
+      ta_ad(:,:,:) = 0.0_wp
+      sa_ad(:,:,:) = 0.0_wp
+      gtu_ad(:,:)  = 0.0_wp
+      gsu_ad(:,:)  = 0.0_wp
+      gtv_ad(:,:)  = 0.0_wp
+      gsv_ad(:,:)  = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdt )
+      ztb_tlin(:,:,:) = z3r(:,:,:) 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 727391 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stds )
+      zsb_tlin(:,:,:) = z3r(:,:,:) 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 249741 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdt )
+      zta_tlin(:,:,:) = z3r(:,:,:) 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 182029 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stds )
+      zsa_tlin(:,:,:) = z3r(:,:,:) 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z2r, 'U', 0.0_wp, stds )
+      zgtu_tlin(:,:) = z2r(:,:) 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 727391 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z2r, 'U', 0.0_wp, stds )
+      zgsu_tlin(:,:) = z2r(:,:) 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 249741 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z2r, 'V', 0.0_wp, stds )
+      zgtv_tlin(:,:) = z2r(:,:) 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 182029 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z2r, 'V', 0.0_wp, stds )
+      zgsv_tlin(:,:) = z2r(:,:) 
+
+      tb_tl(:,:,:) = ztb_tlin(:,:,:) 
+      sb_tl(:,:,:) = zsb_tlin(:,:,:) 
+      ta_tl(:,:,:) = zta_tlin(:,:,:) 
+      sa_tl(:,:,:) = zsa_tlin(:,:,:) 
+      gtu_tl(:,:)  = zgtu_tlin(:,:)
+      gsu_tl(:,:)  = zgsu_tlin(:,:)
+      gtv_tl(:,:)  = zgtv_tlin(:,:)
+      gsv_tl(:,:)  = zgsv_tlin(:,:)
+
+      CALL tra_ldf_lap_tan( nit000 ) 
+      
+      zta_tlout(:,:,:) = ta_tl(:,:,:)
+      zsa_tlout(:,:,:) = sa_tl(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsa_adin(ji,jj,jk) = zsa_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_s(jk)
+              zta_adin(ji,jj,jk) = zta_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_t(jk)
+            END DO
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !-------------------------------------------------------------------
+
+      zsp1_T = DOT_PRODUCT( zta_tlout, zta_adin )
+      zsp1_S = DOT_PRODUCT( zsa_tlout, zsa_adin )
+      zsp1 = zsp1_T + zsp1_S
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      ta_ad(:,:,:) = zta_adin(:,:,:)
+      sa_ad(:,:,:) = zsa_adin(:,:,:)
+
+      CALL tra_ldf_lap_adj( nit000 ) 
+
+      ztb_adout(:,:,:) = tb_ad(:,:,:)
+      zsb_adout(:,:,:) = sb_ad(:,:,:)
+      zta_adout(:,:,:) = ta_ad(:,:,:)
+      zsa_adout(:,:,:) = sa_ad(:,:,:)
+      zgtu_adout(:,:)  = gtu_ad(:,:)
+      zgsu_adout(:,:)  = gsu_ad(:,:)
+      zgtv_adout(:,:)  = gtv_ad(:,:)
+      zgsv_adout(:,:)  = gsv_ad(:,:)
+          
+      zsp2_1 = DOT_PRODUCT( ztb_tlin , ztb_adout  )
+      zsp2_2 = DOT_PRODUCT( zta_tlin , zta_adout  )
+      zsp2_3 = DOT_PRODUCT( zgtu_tlin, zgtu_adout )
+      zsp2_4 = DOT_PRODUCT( zgtv_tlin, zgtv_adout )
+      zsp2_5 = DOT_PRODUCT( zsb_tlin , zsb_adout  )
+      zsp2_6 = DOT_PRODUCT( zsa_tlin , zsa_adout  )
+      zsp2_7 = DOT_PRODUCT( zgsu_tlin, zgsu_adout )
+      zsp2_8 = DOT_PRODUCT( zgsv_tlin, zgsv_adout ) 
+
+      zsp2_T = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4
+      zsp2_S = zsp2_5 + zsp2_6 + zsp2_7 + zsp2_8
+      zsp2   = zsp2_T + zsp2_S
+
+      cl_name = 'tra_ldf_lap_ad'
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      DEALLOCATE(         &
+         & ztb_tlin,      & ! Tangent input
+         & zsb_tlin,      & ! Tangent input
+         & zta_tlin,      & ! Tangent input
+         & zsa_tlin,      & ! Tangent input
+         & zgtu_tlin,     & ! Tangent input
+         & zgsu_tlin,     & ! Tangent input
+         & zgtv_tlin,     & ! Tangent input
+         & zgsv_tlin,     & ! Tangent input
+         & zta_tlout,     & ! Tangent output
+         & zsa_tlout,     & ! Tangent output
+         & zta_adin,      & ! Adjoint input
+         & zsa_adin,      & ! Adjoint input
+         & ztb_adout,     & ! Adjoint output
+         & zsb_adout,     & ! Adjoint output
+         & zta_adout,     & ! Adjoint output
+         & zsa_adout,     & ! Adjoint output
+         & zgtu_adout,    & ! Adjoint output
+         & zgsu_adout,    & ! Adjoint output
+         & zgtv_adout,    & ! Adjoint output
+         & zgsv_adout,    & ! Adjoint output
+         & z3r,           & ! 3D random field 
+         & z2r            &
+         & )
+      
+
+   END SUBROUTINE tra_ldf_lap_adj_tst
+#if defined key_tst_tlm
+   SUBROUTINE tra_ldf_lap_tlm_tst ( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tra_ldf_lap_tlm_tst ***
+      !!
+      !! ** Purpose : Test the tangent routine.
+      !!
+      !! ** Method  : Verify the tangent with Taylor expansion 
+      !!           
+      !!                 M(x+h*dx) = M(x) + L(h*dx) + O(h^2)
+      !!
+      !!              where  L   = Linear 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 :
+      !!        ! 09-07 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE step_c1d            ! Time stepping loop for the 1D configuration
+!!      USE asminc              ! assimilation increments       (asm_inc_init routine)
+      USE tamtrj              ! writing out state trajectory  
+      USE lib_mpp,    ONLY: & ! distributed memory computing
+        & lk_mpp,           &
+        & mpp_max 
+      USE c1d,        ONLY: & ! 1D configuration
+        & lk_c1d
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE sshwzv             !  vertical velocity
+      USE gridrandom, ONLY: &
+        & grid_rd_sd
+      USE trj_tam
+      USE oce           , ONLY: & ! ocean dynamics and tracers variables
+        & tb, sb, tn, sn, ta,  &
+        & sa, gtu, gsu, gtv,   &
+        & gsv, gru, grv, rhd
+      USE traldf_lap          ! lateral mixing                   (tra_ldf routine)
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk,    &
+         & istp      
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_Tb,      &
+         & zsp1_Sb,      &
+         & zsp1_Ta,      &
+         & zsp1_Sa,      &
+         & zsp1_Gtu,     &
+         & zsp1_Gsu,     &
+         & zsp1_Gtv,     &
+         & zsp1_Gsv,     &
+         & zsp2,         & ! scalar product involving the tangent routine
+         & zsp2_Tb,      &
+         & zsp2_Sb,      &
+         & zsp2_Ta,      &
+         & zsp2_Sa,      &
+         & zsp2_Gtu,     &
+         & zsp2_Gsu,     &
+         & zsp2_Gtv,     &
+         & zsp2_Gsv,     &
+         & zsp3,         & ! scalar product involving the tangent routine
+         & zsp3_Tb,      &
+         & zsp3_Sb,      &
+         & zsp3_Ta,      &
+         & zsp3_Sa,      &
+         & zsp3_Gtu,     &
+         & zsp3_Gsu,     &
+         & zsp3_Gtv,     &
+         & zsp3_Gsv,     &
+         & zzsp,         & ! scalar product involving the tangent routine
+         & zzsp_Tb,      &
+         & zzsp_Sb,      &
+         & zzsp_Ta,      &
+         & zzsp_Sa,      &
+         & zzsp_Gtu,     &
+         & zzsp_Gsu,     &
+         & zzsp_Gtv,     &
+         & zzsp_Gsv,     &
+         & gamma,        &
+         & zgsp1,        &
+         & zgsp2,        &
+         & zgsp3,        &
+         & zgsp4,        &
+         & zgsp5,        &
+         & zgsp6,        &
+         & zgsp7
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & ztb_tlin ,      & ! Tangent input
+         & zsb_tlin ,      & ! Tangent input
+         & zta_tlin ,      & ! Tangent input
+         & zsa_tlin ,      & ! Tangent input
+         & ztb_out ,       & ! Direct output
+         & zsb_out ,       & ! Direct output
+         & zta_out ,       & ! Direct output
+         & zsa_out ,       & ! Direct output
+         & ztb_wop ,       & ! 
+         & zsb_wop ,       & ! 
+         & zta_wop ,       & ! 
+         & zsa_wop ,       & ! 
+         & z3r               ! 3D random field 
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zgtu_tlin ,     & ! Tangent input
+         & zgsu_tlin ,     & ! Tangent input
+         & zgtv_tlin ,     & ! Tangent input
+         & zgsv_tlin ,     & ! Tangent input
+         & zgtu_out ,      & ! Direct output
+         & zgsu_out ,      & ! Direct output
+         & zgtv_out ,      & ! Direct output
+         & zgsv_out ,      & ! Direct output
+         & zgtu_wop ,      & ! 
+         & zgsu_wop ,      & ! 
+         & zgtv_wop ,      & ! 
+         & zgsv_wop ,      & ! 
+         & z2r               ! 2D random field 
+      CHARACTER(LEN=14) ::   cl_name
+      CHARACTER (LEN=128) :: file_out_sc, file_wop, file_out, file_xdx
+      CHARACTER (LEN=90) :: &
+         & FMT
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zsctb, zscta,    &
+         & zscsb, zscsa,    &
+         & zscgtu, zscgsu,  &
+         & zscgtv, zscgsv,  &
+         & zscerrtb,        &
+         & zscerrta,        &
+         & zscerrsb,        &
+         & zscerrsa,        &
+         & zscerrgtu,       &
+         & zscerrgsu,       &
+         & zscerrgtv,       &
+         & zscerrgsv
+      INTEGER, DIMENSION(100)::                    &
+         & iipostb, iiposta, iipossb, iipossa,     &
+         & iiposgtu, iiposgsu, iiposgtv, iiposgsv, &
+         & ijpostb,  ijposta,  ijpossb,  ijpossa,  &
+         & ijposgtu, ijposgsu, ijposgtv, ijposgsv, & 
+         & ikpostb, ikposta, ikpossb, ikpossa
+      INTEGER::             &
+         & ii,              &
+         & isamp=40,        &
+         & jsamp=40,        &
+         & ksamp=10,        &
+         & numsctlm,        &
+         & numtlm
+     REAL(KIND=wp), DIMENSION(jpi,jpj,jpk) :: &
+         & zerrtb, zerrta,  & 
+         & zerrsb, zerrsa     
+
+      REAL(KIND=wp), DIMENSION(jpi,jpj)    :: &
+         & zerrgtu, zerrgsu, &  
+         & zerrgtv, zerrgsv  
+
+      ! Allocate memory
+      ALLOCATE( &
+         & ztb_tlin(jpi,jpj,jpk),      & 
+         & zsb_tlin(jpi,jpj,jpk),      & 
+         & zta_tlin(jpi,jpj,jpk),      & 
+         & zsa_tlin(jpi,jpj,jpk),      & 
+         & ztb_out(jpi,jpj,jpk),       & 
+         & zsb_out(jpi,jpj,jpk),       & 
+         & zta_out(jpi,jpj,jpk),       & 
+         & zsa_out(jpi,jpj,jpk),       &
+         & ztb_wop(jpi,jpj,jpk),       & 
+         & zsb_wop(jpi,jpj,jpk),       & 
+         & zta_wop(jpi,jpj,jpk),       & 
+         & zsa_wop(jpi,jpj,jpk),       &
+         & zgtu_tlin(jpi,jpj),         & 
+         & zgsu_tlin(jpi,jpj),         & 
+         & zgtv_tlin(jpi,jpj),         & 
+         & zgsv_tlin(jpi,jpj),         &  
+         & zgtu_out(jpi,jpj),         & 
+         & zgsu_out(jpi,jpj),         & 
+         & zgtv_out(jpi,jpj),         & 
+         & zgsv_out(jpi,jpj),         &
+         & zgtu_wop(jpi,jpj),         & 
+         & zgsu_wop(jpi,jpj),         & 
+         & zgtv_wop(jpi,jpj),         & 
+         & zgsv_wop(jpi,jpj),         &
+         & z3r(jpi,jpj,jpk),           &
+         & z2r(jpi,jpj)                &
+         & )
+
+      !--------------------------------------------------------------------
+      ! Reset variables
+      !--------------------------------------------------------------------
+
+      ztb_tlin(:,:,:)  = 0.0_wp
+      zsb_tlin(:,:,:)  = 0.0_wp
+      zta_tlin(:,:,:)  = 0.0_wp
+      zsa_tlin(:,:,:)  = 0.0_wp
+      ztb_out(:,:,:)   = 0.0_wp
+      zsb_out(:,:,:)   = 0.0_wp
+      zta_out(:,:,:)   = 0.0_wp
+      zsa_out(:,:,:)   = 0.0_wp
+      ztb_wop(:,:,:)   = 0.0_wp
+      zsb_wop(:,:,:)   = 0.0_wp
+      zta_wop(:,:,:)   = 0.0_wp
+      zsa_wop(:,:,:)   = 0.0_wp
+      zgtu_tlin(:,:)   = 0.0_wp
+      zgsu_tlin(:,:)   = 0.0_wp
+      zgtv_tlin(:,:)   = 0.0_wp
+      zgsv_tlin(:,:)   = 0.0_wp
+      zgtu_out(:,:)    = 0.0_wp
+      zgsu_out(:,:)    = 0.0_wp
+      zgtv_out(:,:)    = 0.0_wp
+      zgsv_out(:,:)    = 0.0_wp
+      zgtu_wop(:,:)    = 0.0_wp
+      zgsu_wop(:,:)    = 0.0_wp
+      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
+      ta_tl(:,:,:) = 0.0_wp
+      sa_tl(:,:,:) = 0.0_wp
+      gtu_tl(:,:)  = 0.0_wp
+      gsu_tl(:,:)  = 0.0_wp
+      gtv_tl(:,:)  = 0.0_wp
+      gsv_tl(:,:)  = 0.0_wp
+      ENDIF
+      zsctb(:)     = 0.0_wp
+      zscta(:)     = 0.0_wp
+      zscsb(:)     = 0.0_wp
+      zscsa(:)     = 0.0_wp
+      zscgtu(:)     = 0.0_wp
+      zscgsu(:)     = 0.0_wp
+      zscgtv(:)     = 0.0_wp
+      zscgsv(:)     = 0.0_wp
+      zscerrtb(:)     = 0.0_wp
+      zscerrta(:)     = 0.0_wp
+      zscerrsb(:)     = 0.0_wp
+      zscerrsa(:)     = 0.0_wp
+      zscerrgtu(:)     = 0.0_wp
+      zscerrgsu(:)     = 0.0_wp
+      zscerrgtv(:)     = 0.0_wp
+      zscerrgsv(:)     = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Output filename Xn=F(X0)
+      !--------------------------------------------------------------------
+!!!!      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
+      !--------------------------------------------------------------------
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         CALL grid_rd_sd( 596035, z3r,  'T', 0.0_wp, stdt)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  ztb_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 727391, z3r,  'S', 0.0_wp, stds)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsb_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 249741, z3r,  'T', 0.0_wp, stdt)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zta_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 182029, z3r,  'S', 0.0_wp, stds)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsa_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 596035, z2r, 'U', 0.0_wp, stds) 
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zgtu_tlin(ji,jj) = z2r(ji,jj)
+            END DO
+         END DO
+         CALL grid_rd_sd( 727391, z2r, 'U', 0.0_wp, stds)
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zgsu_tlin(ji,jj) = z2r(ji,jj)
+            END DO
+         END DO
+         CALL grid_rd_sd( 249741, z2r, 'V', 0.0_wp, stds)
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zgtv_tlin(ji,jj) = z2r(ji,jj)
+            END DO
+         END DO
+         CALL grid_rd_sd( 182029, z2r, 'V', 0.0_wp, stds)
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zgsv_tlin(ji,jj) = z2r(ji,jj)
+            END DO
+         END DO
+      ENDIF
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      IF ( tlm_bch /= 2 )      CALL istate_p  
+
+      ! *** initialize the reference trajectory
+      ! ------------
+      CALL  trj_rea( nit000-1, 1 )
+      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(:,:,:)
+         tb(:,:,:)       = tb(:,:,:) + ztb_tlin(:,:,:)
+
+         zsb_tlin(:,:,:) = gamma * zsb_tlin(:,:,:)
+         sb(:,:,:)       = sb(:,:,:) + zsb_tlin(:,:,:)
+
+         zta_tlin(:,:,:) = gamma * zta_tlin(:,:,:)
+         ta(:,:,:)       = ta(:,:,:) + zta_tlin(:,:,:)
+
+         zsa_tlin(:,:,:) = gamma * zsa_tlin(:,:,:)
+         sa(:,:,:)       = sa(:,:,:) + zsa_tlin(:,:,:)
+
+         zgtu_tlin(:,:) = gamma * zgtu_tlin(:,:)
+         gtu(:,:)       = gtu(:,:) + zgtu_tlin(:,:)
+
+         zgsu_tlin(:,:) = gamma * zgsu_tlin(:,:)
+         gsu(:,:)       = gsu(:,:) + zgsu_tlin(:,:)
+
+         zgtv_tlin(:,:) = gamma * zgtv_tlin(:,:)
+         gtv(:,:)       = gtv(:,:) + zgtv_tlin(:,:)
+
+         zgsv_tlin(:,:) = gamma * zgsv_tlin(:,:)
+         gsv(:,:)       = gsv(:,:) + zgsv_tlin(:,:)
+      ENDIF 
+      IF( .NOT. lk_vvl ) CALL ssh_wzv(nit000)
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------
+      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 ( tlm_bch == 2 ) THEN    
+         !--------------------------------------------------------------------
+         ! Initialize the tangent variables: dy^* = W dy  
+         !--------------------------------------------------------------------
+         CALL  trj_rea( nit000-1, 1 ) 
+         CALL  trj_rea( nit000, 1 ) 
+         tb_tl  (:,:,:) = ztb_tlin  (:,:,:)
+         sb_tl  (:,:,:) = zsb_tlin  (:,:,:)
+         ta_tl  (:,:,:) = zta_tlin  (:,:,:)
+         sa_tl  (:,:,:) = zsa_tlin  (:,:,:)
+         gtu_tl (  :,:) = zgtu_tlin (  :,:)
+         gsu_tl (  :,:) = zgsu_tlin (  :,:)
+         gtv_tl (  :,:) = zgtv_tlin (  :,:)
+         gsv_tl (  :,:) = zgsv_tlin (  :,:)
+
+         !-----------------------------------------------------------------------
+         !  Initialization of the dynamics and tracer fields for the tangent
+         !----------------------------------------------------------------------- 
+         CALL tra_ldf_lap_tan(nit000)
+
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L(t0,tn) gamma dx0 ) )
+         !--------------------------------------------------------------------
+
+         zsp2_Tb    = DOT_PRODUCT( tb_tl  , tb_tl    )
+         zsp2_Sb    = DOT_PRODUCT( sb_tl  , sb_tl    )
+         zsp2_Ta    = DOT_PRODUCT( ta_tl  , ta_tl    )
+         zsp2_Sa    = DOT_PRODUCT( sa_tl  , sa_tl    )
+         zsp2_Gtu  = DOT_PRODUCT( gtu_tl, gtu_tl  )
+         zsp2_Gsu  = DOT_PRODUCT( gsu_tl, gsu_tl  )
+         zsp2_Gtv  = DOT_PRODUCT( gtv_tl, gtv_tl  )
+         zsp2_Gsv  = DOT_PRODUCT( gsv_tl, gsv_tl  )
+
+         zsp2      = zsp2_Tb + zsp2_Sb + zsp2_Ta + zsp2_Sa + &
+                   & zsp2_Gtu + Zsp2_Gsu + zsp2_Gtv + zsp2_Gsv
+  
+         !--------------------------------------------------------------------
+         !  Storing data
+         !--------------------------------------------------------------------
+         CALL trj_rd_spl(file_wop) 
+         ztb_wop  (:,:,:) = tb  (:,:,:)
+         zsb_wop  (:,:,:) = sb  (:,:,:)
+         zta_wop  (:,:,:) = ta  (:,:,:)
+         zsa_wop  (:,:,:) = sa  (:,:,:)
+         zgtu_wop (:,:  ) = gtu (:,:  )
+         zgsu_wop (:,:  ) = gsu (:,:  )
+         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 
+         ! 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 jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztb_out   (ji,jj,jk) = ztb_out    (ji,jj,jk) - ztb_wop  (ji,jj,jk)
+                  ztb_wop   (ji,jj,jk) = ztb_out    (ji,jj,jk) - tb_tl    (ji,jj,jk)
+                  IF (  tb_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrtb(ji,jj,jk) = ztb_out(ji,jj,jk)/tb_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iipostb(ii) = ji
+                      ijpostb(ii) = jj
+                      ikpostb(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+!                         zsctb (ii) =  ztb_out(ji,jj,jk)
+                         zsctb (ii) =  ztb_wop(ji,jj,jk)
+                         zscerrtb (ii) =  ( zerrtb(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         ii=0
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zsb_out   (ji,jj,jk) = zsb_out    (ji,jj,jk) - zsb_wop  (ji,jj,jk)
+                  zsb_wop   (ji,jj,jk) = zsb_out    (ji,jj,jk) - sb_tl    (ji,jj,jk)
+                  IF (  sb_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrsb(ji,jj,jk) = zsb_out(ji,jj,jk)/sb_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iipossb(ii) = ji
+                      ijpossb(ii) = jj
+                      ikpossb(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+!                         zscsb (ii) =  zsb_out(ji,jj,jk)
+                         zscsb (ii) =  zsb_wop(ji,jj,jk)
+                         zscerrsb (ii) =  ( zerrsb(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         ii=0
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zta_out   (ji,jj,jk) = zta_out    (ji,jj,jk) - zta_wop  (ji,jj,jk)
+                  zta_wop   (ji,jj,jk) = zta_out    (ji,jj,jk) - ta_tl    (ji,jj,jk)
+                  IF (  ta_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrta(ji,jj,jk) = zta_out(ji,jj,jk)/ta_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposta(ii) = ji
+                      ijposta(ii) = jj
+                      ikposta(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+!                         zscta (ii) =  zta_out(ji,jj,jk)
+                         zscta (ii) =  zta_wop(ji,jj,jk)
+                         zscerrta (ii) =  ( zerrta(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         ii=0
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zsa_out   (ji,jj,jk) = zsa_out    (ji,jj,jk) - zsa_wop  (ji,jj,jk)
+                  zsa_wop   (ji,jj,jk) = zsa_out    (ji,jj,jk) - sa_tl    (ji,jj,jk)
+                  IF (  sa_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrsa(ji,jj,jk) = zsa_out(ji,jj,jk)/sa_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iipossa(ii) = ji
+                      ijpossa(ii) = jj
+                      ikpossa(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+!                         zscsa (ii) =  zsa_out(ji,jj,jk)
+                         zscsa (ii) =  zsa_wop(ji,jj,jk)
+                         zscerrsa (ii) =  ( zerrsa(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         ii=0
+         jk=1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zgtu_out   (ji,jj)= zgtu_out    (ji,jj) - zgtu_wop  (ji,jj)
+               zgtu_wop   (ji,jj) = zgtu_out    (ji,jj) - gtu_tl    (ji,jj)
+               IF (  gtu_tl(ji,jj) .NE. 0.0_wp ) &
+                  & zerrgtu(ji,jj) = zgtu_out(ji,jj)/gtu_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+               &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                   ii = ii+1
+                   iiposgtu(ii) = ji
+                   ijposgtu(ii) = jj
+                   IF ( INT(umask(ji,jj,jk)) .NE. 0)  THEN
+!                      zscgtu (ii) =  zgtu_out(ji,jj)
+                      zscgtu (ii) =  zgtu_wop(ji,jj)
+                      zscerrgtu (ii) =  ( zerrgtu(ji,jj) - 1.0_wp ) / gamma
+                   ENDIF
+               ENDIF
+            END DO
+         END DO
+         ii=0
+         jk=1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zgtv_out   (ji,jj) = zgtv_out    (ji,jj) - zgtv_wop  (ji,jj)
+               zgtv_wop   (ji,jj) = zgtv_out    (ji,jj) - gtv_tl    (ji,jj)
+               IF (  gtv_tl(ji,jj) .NE. 0.0_wp ) &
+                  & zerrgtv(ji,jj) = zgtv_out(ji,jj)/gtv_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+               &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                   ii = ii+1
+                   iiposgtv(ii) = ji
+                   ijposgtv(ii) = jj
+                   IF ( INT(vmask(ji,jj,jk)) .NE. 0)  THEN
+!                      zscgtv (ii) =  zgtv_out(ji,jj)
+                      zscgtv (ii) =  zgtv_wop(ji,jj)
+                      zscerrgtv (ii) = ( zerrgtv(ji,jj) - 1.0_wp ) /gamma
+                   ENDIF
+               ENDIF
+            END DO
+         END DO
+         ii=0
+         jk=1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zgsu_out   (ji,jj) = zgsu_out    (ji,jj) - zgsu_wop  (ji,jj)
+               zgsu_wop   (ji,jj) = zgsu_out    (ji,jj) - gsu_tl    (ji,jj)
+               IF (  gsu_tl(ji,jj) .NE. 0.0_wp ) &
+                  & zerrgsu(ji,jj) = zgsu_out(ji,jj)/gsu_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+               &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                   ii = ii+1
+                   iiposgsu(ii) = ji
+                   ijposgsu(ii) = jj
+                   IF ( INT(umask(ji,jj,jk)) .NE. 0)  THEN
+!                      zscgsu (ii) =  zgsu_out(ji,jj)
+                      zscgsu (ii) =  zgsu_wop(ji,jj)
+                      zscerrgsu (ii) =  ( zerrgsu(ji,jj) - 1.0_wp ) / gamma
+                   ENDIF
+               ENDIF
+            END DO
+         END DO
+         ii=0
+         jk=1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zgsv_out   (ji,jj) = zgsv_out    (ji,jj) - zgsv_wop  (ji,jj)
+               zgsv_wop   (ji,jj) = zgsv_out    (ji,jj) - gsv_tl    (ji,jj)
+               IF (  gsv_tl(ji,jj) .NE. 0.0_wp ) &
+                  & zerrgsv(ji,jj) = zgsv_out(ji,jj)/gsv_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+               &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                   ii = ii+1
+                   iiposgsv(ii) = ji
+                   ijposgsv(ii) = jj
+                   IF ( INT(vmask(ji,jj,jk)) .NE. 0)  THEN
+!                      zscgsv (ii) =  zgsv_out(ji,jj)
+                      zscgsv (ii) =  zgsv_wop(ji,jj)
+                      zscerrgsv (ii) =  ( zerrgsv(ji,jj) - 1.0_wp ) /gamma
+                   ENDIF
+               ENDIF
+            END DO
+         END DO
+
+         zsp1_Tb    = DOT_PRODUCT( ztb_out  , ztb_out    )
+         zsp1_Sb    = DOT_PRODUCT( zsb_out  , zsb_out    )
+         zsp1_Ta    = DOT_PRODUCT( zta_out  , zta_out    )
+         zsp1_Sa    = DOT_PRODUCT( zsa_out  , zsa_out    )
+         zsp1_Gtu   = DOT_PRODUCT( zgtu_out , zgtu_out   )
+         zsp1_Gsu   = DOT_PRODUCT( zgsu_out , zgsu_out   )
+         zsp1_Gtv   = DOT_PRODUCT( zgtv_out , zgtv_out   )
+         zsp1_Gsv   = DOT_PRODUCT( zgsv_out , zgsv_out   )
+
+         zsp1      = zsp1_Tb + zsp1_Sb + zsp1_Ta + zsp1_Sa + &
+                   & zsp1_Gtu + Zsp1_Gsu + zsp1_Gtv + zsp1_Gsv
+
+         zsp3_Tb    = DOT_PRODUCT( ztb_wop  , ztb_wop    )
+         zsp3_Sb    = DOT_PRODUCT( zsb_wop  , zsb_wop    )
+         zsp3_Ta    = DOT_PRODUCT( zta_wop  , zta_wop    )
+         zsp3_Sa    = DOT_PRODUCT( zsa_wop  , zsa_wop    )
+         zsp3_Gtu   = DOT_PRODUCT( zgtu_wop , zgtu_wop   )
+         zsp3_Gsu   = DOT_PRODUCT( zgsu_wop , zgsu_wop   )
+         zsp3_Gtv   = DOT_PRODUCT( zgtv_wop , zgtv_wop   )
+         zsp3_Gsv   = DOT_PRODUCT( zgsv_wop , zgsv_wop   )
+
+         zsp3      = zsp3_Tb + zsp3_Sb + zsp3_Ta + zsp3_Sa + &
+                   & zsp3_Gtu + Zsp3_Gsu + zsp3_Gtv + zsp3_Gsv
+
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name  = 'traldf_tam:En '
+         zzsp     = SQRT(zsp3)
+         zzsp_Tb  = SQRT(zsp3_Tb)
+         zzsp_Sb  = SQRT(zsp3_Sb)
+         zzsp_Ta  = SQRT(zsp3_Ta)
+         zzsp_Sa  = SQRT(zsp3_Sa)
+         zzsp_Gtu = SQRT(zsp3_Gtu)
+         zzsp_Gsu = SQRT(zsp3_Gsu)
+         zzsp_Gtv = SQRT(zsp3_Gtv)
+         zzsp_Gsv = SQRT(zsp3_Gsv)
+
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         !--------------------------------------------------------------------
+         ! Compute the relative error Er of the linear model
+         ! Er = norm(En) / norm(TL(gamma.dX0, t0,tn))
+         !--------------------------------------------------------------------
+         cl_name  = 'traldf:Er=En/L'
+         zzsp     = SQRT( zsp3/zsp2 )
+         zzsp_Tb  = SQRT( zsp3_Tb/zsp2_Tb)
+         zzsp_Sb  = SQRT( zsp3_Sb/zsp2_Sb)
+         zzsp_Ta  = SQRT(zsp3_Ta/zsp2_Ta)
+         zzsp_Sa  = SQRT(zsp3_Sa/zsp2_Sa)
+         zzsp_Gtu = SQRT(zsp3_Gtu/zsp2_Gtu)
+         zzsp_Gsu = SQRT(zsp3_Gsu/zsp2_Gsu)
+         zzsp_Gtv = SQRT(zsp3_Gtv/zsp2_Gtv)
+         zzsp_Gsv = SQRT(zsp3_Gsv/zsp2_Gsv)
+
+         zgsp3    = zzsp
+         zgsp7    = zzsp/gamma
+         zgsp4    = SQRT( zsp2 )
+         zgsp5    = SQRT( zsp3 )
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp     =  SQRT(zsp2)
+         zzsp_Tb  =  SQRT(zsp2_Tb)
+         zzsp_Sb  =  SQRT(zsp2_Sb)
+         zzsp_Ta  =  SQRT(zsp2_Ta)
+         zzsp_Sa  =  SQRT(zsp2_Sa)
+         zzsp_Gtu =  SQRT(zsp2_Gtu)
+         zzsp_Gsu =  SQRT(zsp2_Gsu)
+         zzsp_Gtv =  SQRT(zsp2_Gtv)
+         zzsp_Gsv =  SQRT(zsp2_Gsv)
+
+         cl_name = 'traldf:L_n2   '
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name  = 'traldf:Mhdx-Mx'
+         zzsp     =  SQRT(zsp1)
+         zzsp_Tb  =  SQRT(zsp1_Tb)
+         zzsp_Sb  =  SQRT(zsp1_Sa)
+         zzsp_Ta  =  SQRT(zsp1_Ta)
+         zzsp_Sa  =  SQRT(zsp1_Sa)
+         zzsp_Gtu =  SQRT(zsp1_Gtu)
+         zzsp_Gsu =  SQRT(zsp1_Gsu)
+         zzsp_Gtv =  SQRT(zsp1_Gtv)
+         zzsp_Gsv =  SQRT(zsp1_Gsv)
+
+         zgsp1    = zzsp
+         zgsp2    = zgsp1 / SQRT(zsp2)
+         zgsp6    = (zgsp2 - 1.0_wp)/gamma
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         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) 'tldf_lap', 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 = 'tldf_lap'
+         IF(lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zsctb(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zsctb     ', &
+                    & cur_loop, h_ratio, ii, iipostb(ii), ijpostb(ii), zsctb(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscsb(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscsb     ', &
+                    & cur_loop, h_ratio, ii, iipossb(ii), ijpossb(ii), zscsb(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscta(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscta     ', &
+                    & cur_loop, h_ratio, ii, iiposta(ii), ijposta(ii), zscta(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscsa(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscsa     ', &
+                    & cur_loop, h_ratio, ii, iipossa(ii), ijpossa(ii), zscsa(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrtb(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrtb     ', &
+                    & cur_loop, h_ratio, ii, iipostb(ii), ijpostb(ii), zscerrtb(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrsb(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrsb     ', &
+                    & cur_loop, h_ratio, ii, iipossb(ii), ijpossb(ii), zscerrsb(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrta(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrta     ', &
+                    & cur_loop, h_ratio, ii, iiposta(ii), ijposta(ii), zscerrta(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrsa(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrsa     ', &
+                    & cur_loop, h_ratio, ii, iipossa(ii), ijpossa(ii), zscerrsa(ii)
+            ENDDO
+            ! write separator
+            WRITE(numtan_sc,"(A4)") '===='
+         ENDIF
+
+      ENDIF
+
+      DEALLOCATE(         &
+         & ztb_tlin,      & ! Tangent input
+         & zsb_tlin,      & ! Tangent input
+         & zta_tlin,      & ! Tangent input
+         & zsa_tlin,      & ! Tangent input
+         & ztb_out,      & 
+         & zsb_out,      & 
+         & zta_out,      & 
+         & zsa_out,      & 
+         & ztb_wop,      & 
+         & zsb_wop,      & 
+         & zta_wop,      & 
+         & zsa_wop,      &
+         & zgtu_tlin,     & ! Tangent input
+         & zgsu_tlin,     & ! Tangent input
+         & zgtv_tlin,     & ! Tangent input
+         & zgsv_tlin,     & ! Tangent input
+         & zgtu_out,     & 
+         & zgsu_out,     & 
+         & zgtv_out,     &
+         & zgsv_out,     & 
+         & zgtu_wop,     & 
+         & zgsu_wop,     & 
+         & zgtv_wop,     &
+         & zgsv_wop,     &
+         & z3r,           & ! 3D random field 
+         & z2r            &
+         & )
+
+  END SUBROUTINE tra_ldf_lap_tlm_tst
+
+
+
+   SUBROUTINE asm_trj_wop_wri
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE asm_trj__wop_wri ***
+      !!
+      !! ** Purpose : Write to file the model state trajectory for use with
+      !!              4D-Var.
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!
+      !! History : 
+      !!        ! 09-07 (F. Vigilant) 
+      !!-----------------------------------------------------------------------
+      !! *Module udes
+      USE iom 
+      USE oce           , ONLY: & ! ocean dynamics and tracers variables
+      & tb, sb, ta, sa, gtu, gsu, gtv, gsv 
+      !! * Arguments
+      !! * Local declarations
+      INTEGER :: &
+         & inum                  ! File unit number
+      CHARACTER (LEN=50) :: &
+         & filename
+         ! Define the output file  
+         filename='trj_wop'       
+         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( 1, 1, inum, 'tb'   , tb  )
+         CALL iom_rstput( 1, 1, inum, 'sb'   , sb  )
+         CALL iom_rstput( 1, 1, inum, 'ta'   , ta  )
+         CALL iom_rstput( 1, 1, inum, 'sa'   , sa  )
+         CALL iom_rstput( 1, 1, inum, 'gtu'  , gtu )
+         CALL iom_rstput( 1, 1, inum, 'gsu'  , gsu )
+         CALL iom_rstput( 1, 1, inum, 'gtv'  , gtv )
+         CALL iom_rstput( 1, 1, inum, 'gsv'  , gsv )
+         CALL iom_close( inum )
+   END SUBROUTINE asm_trj_wop_wri
+
+   SUBROUTINE asm_trj_wop_rd
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE asm_trj__wop_rd ***
+      !!
+      !! ** Purpose : Read file the model state trajectory for use with
+      !!              4D-Var.
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!
+      !! History : 
+      !!        ! 09-07 (F. Vigilant) 
+      !!-----------------------------------------------------------------------
+      !! *Module udes
+      USE iom                 ! I/O module
+      USE oce           , ONLY: & ! ocean dynamics and tracers variables
+      & tb, sb, ta, sa, gtu, gsu, gtv, gsv 
+      !! * Arguments
+      !! * Local declarations
+      INTEGER :: &
+         & inum                  ! File unit number
+      CHARACTER (LEN=50) :: &
+         & filename
+      ! Define the output file  
+      filename='trj_wop'       
+      WRITE(filename, FMT='(A,A)' ) TRIM( filename ), '.nc'
+      filename = TRIM( filename )
+      CALL iom_open( filename, inum)
+
+      ! Output trajectory fields
+      CALL iom_get( inum, jpdom_data, 'tb'   , tb, 1  )
+      CALL iom_get( inum, jpdom_data, 'sb'   , sb, 1  )
+      CALL iom_get( inum, jpdom_data, 'ta'   , ta, 1  )
+      CALL iom_get( inum, jpdom_data, 'sa'   , sa, 1  )
+      CALL iom_get( inum, jpdom_data, 'gtu'  , gtu, 1 )
+      CALL iom_get( inum, jpdom_data, 'gsu'  , gsu, 1 )
+      CALL iom_get( inum, jpdom_data, 'gtv'  , gtv, 1 )
+      CALL iom_get( inum, jpdom_data, 'gsv'  , gsv, 1 )
+      CALL iom_close( inum )
+   END SUBROUTINE asm_trj_wop_rd
+#endif
+#endif
+   !!==============================================================================
+END MODULE traldf_lap_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traldf_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traldf_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traldf_tam.F90	(revision 2578)
@@ -0,0 +1,290 @@
+MODULE traldf_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  traldf_tam  ***
+   !! Ocean Active tracers : lateral diffusive trends 
+   !!                       Tangent and Adjoint Module
+   !!=====================================================================
+   !! History of the direct module:  
+   !!          9.0  ! 05-11 (G. Madec)  Original code
+   !! History of the TAM module:
+   !!          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
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_ldf     : update the tracer trend with the lateral diffusion
+   !!       ldf_ctl : initialization, namelist read, and parameters control
+   !!       ldf_ano : compute lateral diffusion for constant T-S profiles
+   !!----------------------------------------------------------------------
+   USE traldf_iso_tam, ONLY: & ! lateral mixing               (tra_ldf_iso routine)
+      & tra_ldf_iso_tan,     &
+      & tra_ldf_iso_adj,     &
+      & tra_ldf_iso_adj_tst
+   USE traldf_lap_tam, ONLY: & ! lateral mixing               (tra_ldf_lap_routine)
+      & tra_ldf_lap_tan,     &
+      & tra_ldf_lap_adj,     &
+#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
+   USE ldftra_oce    , ONLY: & 
+      & lk_traldf_eiv,       &
+      & ln_traldf_lap,       & 
+      & ln_traldf_bilap,     &
+      & ln_traldf_level,     &
+      & ln_traldf_hor,       & 
+      & ln_traldf_iso  
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & ln_sco,              &
+      & ln_zps,              &
+      & ln_zco
+   USE oce           , ONLY: &
+      &  l_traldf_rot
+   USE ldfslp        , ONLY: &
+      & lk_ldfslp
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_ldf_tan     ! called by step_tam.F90 
+   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
+
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE tra_ldf_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_ldf_tan  ***
+      !! 
+      !! ** Purpose of the direct routine:
+      !!            compute the lateral ocean tracer physics.
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL ldf_ctl_tam          ! initialisation & control of options
+
+      SELECT CASE ( nldf )                       ! compute lateral mixing trend and add it to the general trend
+      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
+
+   SUBROUTINE tra_ldf_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_ldf_adj  ***
+      !! 
+      !! ** Purpose of the direct routine:
+      !!            compute the lateral ocean tracer physics.
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
+      IF( kt == nitend )   CALL ldf_ctl_tam      ! initialisation & control of options
+
+      SELECT CASE ( nldf )                       ! compute lateral mixing trend and add it to the general trend
+      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
+      !
+   END SUBROUTINE tra_ldf_adj
+
+   SUBROUTINE tra_ldf_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE example_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      CALL ldf_ctl_tam
+
+      SELECT CASE ( nldf )                       ! compute lateral mixing trend and add it to the general trend
+       CASE ( 0 )   ;   CALL tra_ldf_lap_adj_tst( kumadt )
+       CASE ( 1 )   ;   CALL tra_ldf_iso_adj_tst( kumadt )
+      END SELECT
+
+   END SUBROUTINE tra_ldf_adj_tst
+
+   SUBROUTINE ldf_ctl_tam
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_ctl  ***
+      !! 
+      !! ** Purpose :   Choice of the operator for the lateral tracer diffusion
+      !!
+      !! ** Method  :   set nldf from the namtra_ldf logicals
+      !!      nldf == -1   ESOPA test: ALL operators are used
+      !!      nldf ==  0   laplacian operator
+      !!      nldf ==  1   Rotated laplacian operator
+      !!      nldf ==  2   bilaplacian operator
+      !!      nldf ==  3   Rotated bilaplacian
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio, ierr         ! temporary integers 
+!      
+!     NAMELIST/nam_traldf/ ln_traldf_lap  , ln_traldf_bilap,                &
+!        &                 ln_traldf_level, ln_traldf_hor, ln_traldf_iso,   &
+!        &                 aht0, ahtb0, aeiv0
+      !!----------------------------------------------------------------------
+
+      !  Define the lateral mixing oparator for tracers
+      ! ===============================================
+    
+      ! Namelist nam_traldf already read in ldftra module
+!     ! Read Namelist nam_traldf : Lateral physics on tracers
+!     REWIND( numnam )
+!     READ  ( numnam, namtra_ldf )
+
+      IF(lwp) THEN                    ! Namelist print
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra:ldf_ctl : lateral tracer diffusive operator'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '       Namelist namtra_ldf : set lateral mixing parameters (type, direction, coefficients)'
+         WRITE(numout,*) '          laplacian operator          ln_traldf_lap   = ', ln_traldf_lap
+         WRITE(numout,*) '          bilaplacian operator        ln_traldf_bilap = ', ln_traldf_bilap
+         WRITE(numout,*) '          iso-level                   ln_traldf_level = ', ln_traldf_level
+         WRITE(numout,*) '          horizontal (geopotential)   ln_traldf_hor   = ', ln_traldf_hor
+         WRITE(numout,*) '          iso-neutral                 ln_traldf_iso   = ', ln_traldf_iso
+      ENDIF
+
+      !                               ! control the input
+      ioptio = 0
+      IF( ln_traldf_lap   )   ioptio = ioptio + 1
+      IF( ln_traldf_bilap )   ioptio = ioptio + 1
+      IF( ioptio >  1 )   CALL ctl_stop( '          use ONE or NONE of the 2 lap/bilap operator type on tracer' )
+      IF( ioptio == 0 )   nldf = -2   ! No lateral diffusion
+      ioptio = 0
+      IF( ln_traldf_level )   ioptio = ioptio + 1
+      IF( ln_traldf_hor   )   ioptio = ioptio + 1
+      IF( ln_traldf_iso   )   ioptio = ioptio + 1
+      IF( ioptio /= 1 )   CALL ctl_stop( '          use only ONE direction (level/hor/iso)' )
+
+      ! defined the type of lateral diffusion from ln_traldf_... logicals
+      ! CAUTION : nldf = 1 is used in trazdf_imp, change it carefully
+      ierr = 0
+      IF( ln_traldf_lap ) THEN       ! laplacian operator
+         IF ( ln_zco ) THEN                ! z-coordinate
+            IF ( ln_traldf_level )   nldf = 0      ! iso-level  (no rotation)
+            IF ( ln_traldf_hor   )   nldf = 0      ! horizontal (no rotation)
+            IF ( ln_traldf_iso   )   nldf = 1      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_zps ) THEN             ! z-coordinate
+            IF ( ln_traldf_level )   ierr = 1      ! iso-level not allowed
+            IF ( ln_traldf_hor   )   nldf = 0      ! horizontal (no rotation)
+            IF ( ln_traldf_iso   )   nldf = 1      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_sco ) THEN             ! z-coordinate
+           CALL ctl_stop( '          You shouldn t have seen this error message, ln_sco option not impemented yet for tam' )
+         ENDIF
+      ENDIF
+
+      IF( ln_traldf_bilap ) THEN      ! bilaplacian operator
+         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',   &
+           &              ' the eddy induced velocity on tracers requires isopycnal laplacian diffusion' )
+      IF( nldf == 1 .OR. nldf == 3 ) THEN      ! rotation
+         IF( .NOT.lk_ldfslp )   CALL ctl_stop( '          the rotation of the diffusive tensor require key_ldfslp' )
+         l_traldf_rot = .TRUE.                 ! needed for trazdf_imp
+      ENDIF
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         IF( nldf == -2 )   WRITE(numout,*) '          NO lateral diffusion'
+         IF( nldf ==  0 )   WRITE(numout,*) '          laplacian operator'
+         IF( nldf ==  1 )   WRITE(numout,*) '          Rotated laplacian operator'
+      ENDIF
+
+   END SUBROUTINE ldf_ctl_tam
+
+#if defined key_tst_tlm
+   SUBROUTINE tra_ldf_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tra_ldf_tlm_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 
+      !!                   
+      !! History :
+      !!        ! 09-08 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      CALL ldf_ctl_tam
+
+      ! Force nldf to 0
+      nldf = 0
+
+      SELECT CASE ( nldf )                       ! compute lateral mixing trend and add it to the general trend
+       CASE ( 0 )   ;   CALL tra_ldf_lap_tlm_tst( kumadt )
+!       CASE ( 1 )   ;   CALL tra_ldf_iso_adj_tst( kumadt )
+      END SELECT
+
+   END SUBROUTINE tra_ldf_tlm_tst
+   !!======================================================================
+#endif
+#endif
+END MODULE traldf_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/tranxt_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/tranxt_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/tranxt_tam.F90	(revision 2578)
@@ -0,0 +1,947 @@
+MODULE tranxt_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  tranxt_tam  ***
+   !! Ocean active tracers:  time stepping on temperature and salinity
+   !!               Tangent and Adjoint module
+   !!======================================================================
+   !! History of the direct module:
+   !!            7.0  !  91-11  (G. Madec)  Original code
+   !!                 !  93-03  (M. Guyon)  symetrical conditions
+   !!                 !  96-02  (G. Madec & M. Imbard)  opa release 8.0
+   !!            8.0  !  96-04  (A. Weaver)  Euler forward step
+   !!            8.2  !  99-02  (G. Madec, N. Grima)  semi-implicit pressure grad.
+   !!  NEMO      1.0  !  2002-08  (G. Madec)  F90: Free form and module
+   !!             -   !  2002-11  (C. Talandier, A-M Treguier) Open boundaries
+   !!             -   !  2005-04  (C. Deltel) Add Asselin trend in the ML budget
+   !!            2.0  !  2006-02  (L. Debreu, C. Mazauric) Agrif implementation
+   !!            3.0  !  2008-06  (G. Madec)  time stepping always done in trazd
+   !!            3.1  !  2009-02  (G. Madec, R. Benshila)  re-introduce the vvl option
+   !! History of the TAM module:
+   !!            2.0  !  2008-09  (A. Vidard) tam of the 2006-02 version
+   !!            3.0  !  2008-11  (A. Vidard) tam of the 2008-06 version
+   !!             -   !  2009-01  (A. Weaver) corrections to test
+   !!            3.2  !  2010-04  (F. Vigilant)  version 3.2
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_nxt_tan    : time stepping on temperature and salinity (tangent)
+   !!   tra_nxt_adj    : time stepping on temperature and salinity (adjoint)
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 &
+      & jpkm1,               &
+      & jpiglo
+   USE dynhpg        , ONLY: &! hydrostatic pressure gradient
+      & ln_dynhpg_imp
+   USE oce_tam       , ONLY: &! ocean dynamics and tracers variables
+      & tn_tl,               &
+      & tb_tl,               &
+      & ta_tl,               &
+      & sn_tl,               &
+      & sb_tl,               &
+      & sa_tl,               &
+      & tn_ad,               &
+      & tb_ad,               &
+      & ta_ad,               &
+      & sn_ad,               &
+      & sb_ad,               &
+      & sa_ad
+   USE zdf_oce       , ONLY: &
+      & ln_zdfexp
+   USE dom_oce       , ONLY: & ! ocean space and time domain variables 
+      & neuler,              &
+      & rdttra,              &
+      & lk_vvl,              &
+      & atfp,                & 
+      & e1t,                 &
+      & e2t,                 &
+# if defined key_vvl
+      & e3t_1,               &
+# else
+#  if defined key_zco
+      & e3t_0,               &
+#  else
+      & e3t,                 &
+#  endif
+# endif
+      & tmask,               &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE tranxt, ONLY:         &
+      & r2dt_t
+   USE in_out_manager, ONLY: & ! I/O manager
+      & lwp,                 &
+      & numout,              &
+      & nitend,              &
+      & nit000
+   USE lbclnk        , ONLY: &
+      & lbc_lnk
+   USE lbclnk_tam    , ONLY: &
+      & lbc_lnk_adj
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE paresp        , ONLY: & ! Weights for an energy-type scalar product
+      & wesp_t,              &
+      & wesp_s
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          & !
+      & stdt,                & ! stdev for temperature
+      & stds                   !           salinity
+#if defined key_obc
+#  if defined key_pomme_r025
+   USE obc_oce
+   USE obctra_tam
+#  else
+   Error, OBC not ready.
+#  endif
+#endif
+   USE obc_oce
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC   tra_nxt_tan     ! routine called by step_tam.F90
+   PUBLIC   tra_nxt_adj     ! routine called by step_tam.F90
+   PUBLIC   tra_nxt_adj_tst ! routine called by tst.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE tra_nxt_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tranxt_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!             Apply the boundary condition on the after temperature  
+      !!             and salinity fields, achieved the time stepping by adding
+      !!             the Asselin filter on now fields and swapping the fields.
+      !! 
+      !! ** Method  :   At this stage of the computation, ta and sa are the 
+      !!             after temperature and salinity as the time stepping has
+      !!             been performed in trazdf_imp or trazdf_exp module.
+      !!
+      !!              - Apply lateral boundary conditions on (ta,sa) 
+      !!             at the local domain   boundaries through lbc_lnk call, 
+      !!             at the radiative open boundaries (lk_obc=T), 
+      !!             at the relaxed   open boundaries (lk_bdy=T), and
+      !!             at the AGRIF zoom     boundaries (lk_agrif=T)
+      !!
+      !!              - Update lateral boundary conditions on AGRIF children
+      !!             domains (lk_agrif=T)
+      !!
+      !! ** Action  : - (tb,sb) and (tn,sn) ready for the next time step
+      !!              - (ta,sa) time averaged (t,s)   (ln_dynhpg_imp = T)
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!----------------------------------------------------------------------
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_nxt_tan : achieve the time stepping by Asselin filter and array swap'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      ! Update after tracer on domain lateral boundaries
+      ! 
+      CALL lbc_lnk( ta_tl, 'T', 1.0_wp )      ! local domain boundaries  (T-point, unchanged sign)
+      CALL lbc_lnk( sa_tl, 'T', 1.0_wp )
+      !
+#if defined key_obc
+      IF( lk_obc )   CALL obc_tra_tan( kt )   ! OBC open boundaries
+#endif
+#if defined key_bdy
+      error "bdy not available in tangent yet"
+#endif
+#if defined key_agrif
+      IF(lwp) WRITE(numout,*) "key_vvl net available in tangent yet"
+#endif
+
+      ! set time step size (Euler/Leapfrog)
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;   r2dt_t(:) =     rdttra(:)      ! at nit000             (Euler)
+      ELSEIF( kt <= nit000 + 1 )           THEN   ;   r2dt_t(:) = 2.* rdttra(:)      ! at nit000 or nit000+1 (Leapfrog)
+      ENDIF
+
+      ! Leap-Frog + Asselin filter time stepping
+      IF( lk_vvl )   THEN   ;   CALL tra_nxt_vvl_tan( kt )      ! variable volume level (vvl)
+      ELSE                  ;   CALL tra_nxt_fix_tan( kt )      ! fixed    volume level
+      ENDIF
+
+#if defined key_agrif
+      ! Update tracer at AGRIF zoom boundaries
+      IF(lwp) WRITE(numout,*) "key_vvl net available in tangent yet"
+      CALL abort
+#endif    
+      !
+   END SUBROUTINE tra_nxt_tan
+
+   SUBROUTINE tra_nxt_fix_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tra_nxt_fix_tan  ***
+      !!
+      !! ** Purpose :   fixed volume: apply the Asselin time filter and 
+      !!                swap the tracer fields.
+      !! 
+      !! ** Method  : - Apply a Asselin time filter on now fields.
+      !!              - save in (ta,sa) an average over the three time levels 
+      !!             which will be used to compute rdn and thus the semi-implicit
+      !!             hydrostatic pressure gradient (ln_dynhpg_imp = T)
+      !!              - swap tracer fields to prepare the next time_step.
+      !!                This can be summurized for tempearture as:
+      !!             ztm = (ta+2tn+tb)/4       ln_dynhpg_imp = T
+      !!             ztm = 0                   otherwise
+      !!             tb  = tn + atfp*[ tb - 2 tn + ta ]
+      !!             tn  = ta 
+      !!             ta  = ztm       (NB: reset to 0 after eos_bn2 call)
+      !!
+      !! ** Action  : - (tb,sb) and (tn,sn) ready for the next time step
+      !!              - (ta,sa) time averaged (t,s)   (ln_dynhpg_imp = T)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk       ! dummy loop indices
+      REAL(wp) ::   ztmtl, ztftl     ! temporary scalars
+      REAL(wp) ::   zsmtl, zsftl     !    -         -
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_nxt_fix_tan : time stepping'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+      !
+      !                                              ! ----------------------- !
+      IF( ln_dynhpg_imp ) THEN                       ! semi-implicite hpg case !
+         !                                           ! ----------------------- !
+         !
+         IF( neuler == 0 .AND. kt == nit000 ) THEN        ! Euler time-stepping at first time-step
+            DO jk = 1, jpkm1                              ! (only swap)
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     tn_tl(ji,jj,jk) = ta_tl(ji,jj,jk)    ! tb_tl <-- tn_tl
+                     sn_tl(ji,jj,jk) = sa_tl(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+         ELSE                                             ! general case (Leapfrog + Asselin filter
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     ztmtl = 0.25 * ( ta_tl(ji,jj,jk) + 2.* tn_tl(ji,jj,jk) + tb_tl(ji,jj,jk) )  ! mean t
+                     zsmtl = 0.25 * ( sa_tl(ji,jj,jk) + 2.* sn_tl(ji,jj,jk) + sb_tl(ji,jj,jk) )
+                     ztftl = atfp * ( ta_tl(ji,jj,jk) - 2.* tn_tl(ji,jj,jk) + tb_tl(ji,jj,jk) )  ! Asselin filter on t 
+                     zsftl = atfp * ( sa_tl(ji,jj,jk) - 2.* sn_tl(ji,jj,jk) + sb_tl(ji,jj,jk) )
+                     tb_tl(ji,jj,jk) = tn_tl(ji,jj,jk) + ztftl                                   ! tb_tl <-- filtered tn_tl 
+                     sb_tl(ji,jj,jk) = sn_tl(ji,jj,jk) + zsftl
+                     tn_tl(ji,jj,jk) = ta_tl(ji,jj,jk)                                           ! tn_tl <-- ta_tl
+                     sn_tl(ji,jj,jk) = sa_tl(ji,jj,jk)
+                     ta_tl(ji,jj,jk) = ztmtl                                                     ! ta_tl <-- mean t
+                     sa_tl(ji,jj,jk) = zsmtl
+                  END DO
+               END DO
+            END DO
+         ENDIF
+         !                                           ! ----------------------- !
+      ELSE                                           !    explicit hpg case    !
+         !                                           ! ----------------------- !
+         !
+         IF( neuler == 0 .AND. kt == nit000 ) THEN        ! Euler time-stepping at first time-step
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     tn_tl(ji,jj,jk) = ta_tl(ji,jj,jk)    ! tn_tl <-- ta_tl
+                     sn_tl(ji,jj,jk) = sa_tl(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+         ELSE                                             ! general case (Leapfrog + Asselin filter
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     ztftl = atfp * ( ta_tl(ji,jj,jk) - 2.* tn_tl(ji,jj,jk) + tb_tl(ji,jj,jk) )   ! Asselin filter on t 
+                     zsftl = atfp * ( sa_tl(ji,jj,jk) - 2.* sn_tl(ji,jj,jk) + sb_tl(ji,jj,jk) )
+                     tb_tl(ji,jj,jk) = tn_tl(ji,jj,jk) + ztftl                                    ! tb_tl <-- filtered tn_tl 
+                     sb_tl(ji,jj,jk) = sn_tl(ji,jj,jk) + zsftl
+                     tn_tl(ji,jj,jk) = ta_tl(ji,jj,jk)                                            ! tn_tl <-- ta_tl
+                     sn_tl(ji,jj,jk) = sa_tl(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE tra_nxt_fix_tan
+
+   SUBROUTINE tra_nxt_vvl_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tra_nxt_vvl_tan  ***
+      !!
+      !! ** Purpose :   Time varying volume: apply the Asselin time filter  
+      !!                and swap the tracer fields.
+      !! 
+      !! ** Method  : - Apply a thickness weighted Asselin time filter on now fields.
+      !!              - save in (ta,sa) a thickness weighted average over the three 
+      !!             time levels which will be used to compute rdn and thus the semi-
+      !!             implicit hydrostatic pressure gradient (ln_dynhpg_imp = T)
+      !!              - swap tracer fields to prepare the next time_step.
+      !!                This can be summurized for tempearture as:
+      !!             ztm = (e3t_a*ta+2*e3t_n*tn+e3t_b*tb)   ln_dynhpg_imp = T
+      !!                  /(e3t_a   +2*e3t_n   +e3t_b   )    
+      !!             ztm = 0                                otherwise
+      !!             tb  = ( e3t_n*tn + atfp*[ e3t_b*tb - 2 e3t_n*tn + e3t_a*ta ] )
+      !!                  /( e3t_n    + atfp*[ e3t_b    - 2 e3t_n    + e3t_a    ] )
+      !!             tn  = ta 
+      !!             ta  = zt        (NB: reset to 0 after eos_bn2 call)
+      !!
+      !! ** Action  : - (tb,sb) and (tn,sn) ready for the next time step
+      !!              - (ta,sa) time averaged (t,s)   (ln_dynhpg_imp = T)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!     
+      INTEGER  ::   ji, jj, jk             ! dummy loop indices
+      REAL(wp) ::   ztm , ztc_f , ztf , ztca, ztcn, ztcb   ! temporary scalar
+      REAL(wp) ::   zsm , zsc_f , zsf , zsca, zscn, zscb   !    -         -
+      REAL(wp) ::   ze3mr, ze3fr                           !    -         -
+      REAL(wp) ::   ze3t_b, ze3t_n, ze3t_a, ze3t_f         !    -         -
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_nxt_vvl_tan : time stepping'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+      IF(lwp) WRITE(numout,*) "key_vvl net available in tangent yet"
+      CALL abort
+      !
+   END SUBROUTINE tra_nxt_vvl_tan
+
+   SUBROUTINE tra_nxt_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tranxt_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!             Apply the boundary condition on the after temperature  
+      !!             and salinity fields, achieved the time stepping by adding
+      !!             the Asselin filter on now fields and swapping the fields.
+      !! 
+      !! ** Method  :   At this stage of the computation, ta and sa are the 
+      !!             after temperature and salinity as the time stepping has
+      !!             been performed in trazdf_imp or trazdf_exp module.
+      !!
+      !!              - Apply lateral boundary conditions on (ta,sa) 
+      !!             at the local domain   boundaries through lbc_lnk call, 
+      !!             at the radiative open boundaries (lk_obc=T), 
+      !!             at the relaxed   open boundaries (lk_bdy=T), and
+      !!             at the AGRIF zoom     boundaries (lk_agrif=T)
+      !!
+      !!              - Update lateral boundary conditions on AGRIF children
+      !!             domains (lk_agrif=T)
+      !!
+      !! ** Action  : - (tb,sb) and (tn,sn) ready for the next time step
+      !!              - (ta,sa) time averaged (t,s)   (ln_dynhpg_imp = T)
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!----------------------------------------------------------------------
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_nxt_adj : achieve the time stepping by Asselin filter and array swap'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+#if defined key_agrif
+      ! Update tracer at AGRIF zoom boundaries
+      IF(lwp) WRITE(numout,*) "key_vvl net available in tangent yet"
+      CALL abort
+#endif 
+
+      ! set time step size (Euler/Leapfrog)
+      r2dt_t(:) =  2.* rdttra(:) ! initialization
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;   r2dt_t(:) =     rdttra(:)      ! at nit000             (Euler)
+      ELSEIF( kt <= nit000 + 1 )           THEN   ;   r2dt_t(:) = 2.* rdttra(:)      ! at nit000 or nit000+1 (Leapfrog)
+      ENDIF
+
+      ! Leap-Frog + Asselin filter time stepping
+      IF( lk_vvl )   THEN   ;   CALL tra_nxt_vvl_adj( kt )      ! variable volume level (vvl)
+      ELSE                  ;   CALL tra_nxt_fix_adj( kt )      ! fixed    volume level
+      ENDIF
+
+#if defined key_agrif
+      IF(lwp) WRITE(numout,*) "key_vvl net available in tangent yet"
+#endif
+#if defined key_bdy
+      error "bdy not available in tangent yet"
+#endif
+#if defined key_obc
+      IF( lk_obc )   CALL obc_tra_adj( kt ) ! OBC open boundaries
+#endif
+
+      ! Update after tracer on domain lateral boundaries
+      ! 
+      CALL lbc_lnk_adj( ta_ad, 'T', 1.0_wp )      ! local domain boundaries  (T-point, unchanged sign)
+      CALL lbc_lnk_adj( sa_ad, 'T', 1.0_wp )
+      !
+   END SUBROUTINE tra_nxt_adj
+
+   SUBROUTINE tra_nxt_fix_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tra_nxt_fix_adj  ***
+      !!
+      !! ** Purpose :   fixed volume: apply the Asselin time filter and 
+      !!                swap the tracer fields.
+      !! 
+      !! ** Method  : - Apply a Asselin time filter on now fields.
+      !!              - save in (ta,sa) an average over the three time levels 
+      !!             which will be used to compute rdn and thus the semi-implicit
+      !!             hydrostatic pressure gradient (ln_dynhpg_imp = T)
+      !!              - swap tracer fields to prepare the next time_step.
+      !!                This can be summurized for tempearture as:
+      !!             ztm = (ta+2tn+tb)/4       ln_dynhpg_imp = T
+      !!             ztm = 0                   otherwise
+      !!             tb  = tn + atfp*[ tb - 2 tn + ta ]
+      !!             tn  = ta 
+      !!             ta  = ztm       (NB: reset to 0 after eos_bn2 call)
+      !!
+      !! ** Action  : - (tb,sb) and (tn,sn) ready for the next time step
+      !!              - (ta,sa) time averaged (t,s)   (ln_dynhpg_imp = T)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk       ! dummy loop indices
+      REAL(wp) ::   ztmad, ztfad     ! temporary scalars
+      REAL(wp) ::   zsmad, zsfad     !    -         -
+      !!----------------------------------------------------------------------
+
+      ! local adjoint variables initialization
+      ztmad = 0.0_wp; ztfad = 0.0_wp; zsmad = 0.0_wp; zsfad = 0.0_wp
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_nxt_fix_adj : time stepping'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+      !
+      !                                              ! ----------------------- !
+      IF( ln_dynhpg_imp ) THEN                       ! semi-implicite hpg case !
+         !                                           ! ----------------------- !
+         !
+         IF( neuler == 0 .AND. kt == nit000 ) THEN        ! Euler time-stepping at first time-step
+            DO jk = 1, jpkm1                              ! (only swap)
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     ta_ad(ji,jj,jk) = ta_ad(ji,jj,jk) + tn_ad(ji,jj,jk)
+                     sa_ad(ji,jj,jk) = sa_ad(ji,jj,jk) + sn_ad(ji,jj,jk)
+                     tn_ad(ji,jj,jk) = 0.0_wp
+                     sn_ad(ji,jj,jk) = 0.0_wp
+                  END DO
+               END DO
+            END DO
+         ELSE                                             ! general case (Leapfrog + Asselin filter
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     ztmad = ta_ad(ji,jj,jk)
+                     zsmad = sa_ad(ji,jj,jk)
+                     ta_ad(ji,jj,jk) = tn_ad(ji,jj,jk)
+                     sa_ad(ji,jj,jk) = sn_ad(ji,jj,jk)
+                     ztfad = tb_ad(ji,jj,jk)
+                     zsfad = sb_ad(ji,jj,jk)
+                     tn_ad(ji,jj,jk) = tb_ad(ji,jj,jk)
+                     sn_ad(ji,jj,jk) = sb_ad(ji,jj,jk)
+                     ztfad = atfp * ztfad
+                     zsfad = atfp * zsfad
+                     tb_ad(ji,jj,jk) = ztfad
+                     sb_ad(ji,jj,jk) = zsfad
+                     ta_ad(ji,jj,jk) = ta_ad(ji,jj,jk) + ztfad
+                     sa_ad(ji,jj,jk) = sa_ad(ji,jj,jk) + zsfad                     
+                     tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) - 2. * ztfad
+                     sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) - 2. * zsfad 
+                     ztfad = 0.0_wp
+                     zsfad = 0.0_wp
+                     ztmad = 0.25 * ztmad
+                     zsmad = 0.25 * zsmad
+                     tb_ad(ji,jj,jk) = tb_ad(ji,jj,jk) + ztmad
+                     sb_ad(ji,jj,jk) = sb_ad(ji,jj,jk) + zsmad
+                     ta_ad(ji,jj,jk) = ta_ad(ji,jj,jk) + ztmad
+                     sa_ad(ji,jj,jk) = sa_ad(ji,jj,jk) + zsmad                     
+                     tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) + 2. * ztmad
+                     sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) + 2. * zsmad 
+                     ztmad = 0.0_wp
+                     zsmad = 0.0_wp
+                  END DO
+               END DO
+            END DO
+         ENDIF
+         !                                           ! ----------------------- !
+      ELSE                                           !    explicit hpg case    !
+         !                                           ! ----------------------- !
+         !
+         IF( neuler == 0 .AND. kt == nit000 ) THEN        ! Euler time-stepping at first time-step
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     ta_ad(ji,jj,jk) = ta_ad(ji,jj,jk) + tn_ad(ji,jj,jk)
+                     sa_ad(ji,jj,jk) = sa_ad(ji,jj,jk) + sn_ad(ji,jj,jk)
+                     tn_ad(ji,jj,jk) = 0.0_wp
+                     sn_ad(ji,jj,jk) = 0.0_wp
+                  END DO
+               END DO
+            END DO
+         ELSE                                             ! general case (Leapfrog + Asselin filter
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     ta_ad(ji,jj,jk) = ta_ad(ji,jj,jk) + tn_ad(ji,jj,jk)
+                     sa_ad(ji,jj,jk) = sa_ad(ji,jj,jk) + sn_ad(ji,jj,jk)
+                     ztfad = ztfad + tb_ad(ji,jj,jk)
+                     zsfad = zsfad + sb_ad(ji,jj,jk)
+                     tn_ad(ji,jj,jk) = tb_ad(ji,jj,jk)
+                     sn_ad(ji,jj,jk) = sb_ad(ji,jj,jk)
+
+                     ztfad = atfp * ztfad
+                     zsfad = atfp * zsfad
+                     tb_ad(ji,jj,jk) = ztfad
+                     sb_ad(ji,jj,jk) = zsfad
+                     ta_ad(ji,jj,jk) = ta_ad(ji,jj,jk) + ztfad
+                     sa_ad(ji,jj,jk) = sa_ad(ji,jj,jk) + zsfad                     
+                     tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) - 2. * ztfad
+                     sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) - 2. * zsfad 
+                     ztfad = 0.0_wp
+                     zsfad = 0.0_wp
+                  END DO
+               END DO
+            END DO
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE tra_nxt_fix_adj
+
+   SUBROUTINE tra_nxt_vvl_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tra_nxt_vvl_adj  ***
+      !!
+      !! ** Purpose :   Time varying volume: apply the Asselin time filter  
+      !!                and swap the tracer fields.
+      !! 
+      !! ** Method  : - Apply a thickness weighted Asselin time filter on now fields.
+      !!              - save in (ta,sa) a thickness weighted average over the three 
+      !!             time levels which will be used to compute rdn and thus the semi-
+      !!             implicit hydrostatic pressure gradient (ln_dynhpg_imp = T)
+      !!              - swap tracer fields to prepare the next time_step.
+      !!                This can be summurized for tempearture as:
+      !!             ztm = (e3t_a*ta+2*e3t_n*tn+e3t_b*tb)   ln_dynhpg_imp = T
+      !!                  /(e3t_a   +2*e3t_n   +e3t_b   )    
+      !!             ztm = 0                                otherwise
+      !!             tb  = ( e3t_n*tn + atfp*[ e3t_b*tb - 2 e3t_n*tn + e3t_a*ta ] )
+      !!                  /( e3t_n    + atfp*[ e3t_b    - 2 e3t_n    + e3t_a    ] )
+      !!             tn  = ta 
+      !!             ta  = zt        (NB: reset to 0 after eos_bn2 call)
+      !!
+      !! ** Action  : - (tb,sb) and (tn,sn) ready for the next time step
+      !!              - (ta,sa) time averaged (t,s)   (ln_dynhpg_imp = T)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!     
+      INTEGER  ::   ji, jj, jk             ! dummy loop indices
+      REAL(wp) ::   ztm , ztc_f , ztf , ztca, ztcn, ztcb   ! temporary scalar
+      REAL(wp) ::   zsm , zsc_f , zsf , zsca, zscn, zscb   !    -         -
+      REAL(wp) ::   ze3mr, ze3fr                           !    -         -
+      REAL(wp) ::   ze3t_b, ze3t_n, ze3t_a, ze3t_f         !    -         -
+      !!----------------------------------------------------------------------
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_nxt_vvl_adj : time stepping'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+      IF(lwp) WRITE(numout,*) "key_vvl net available in tangent yet"
+      CALL abort
+      !
+   END SUBROUTINE tra_nxt_vvl_adj
+
+   SUBROUTINE tra_nxt_adj_tst( kumadt ) 
+      !!-----------------------------------------------------------------------
+      !!
+      !!          ***  ROUTINE tra_nxt_adj_tst : TEST OF tra_nxt_adj  ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+       !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt            ! Output unit
+ 
+      INTEGER ::  &
+         & ji,    &          ! dummy loop indices
+         & jj,    &        
+         & jk,    &
+         & jn
+
+      LOGICAL ::  &          ! local variable for time scheme
+         & ll_dynhpg_imp 
+
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zsb_tlin,     &! Tangent input : before salinity
+         & ztb_tlin,     &! Tangent input : before temperature
+         & zsa_tlin,     &! Tangent input : after salinity
+         & zta_tlin,     &! Tangent input : after temperature
+         & zsn_tlin,     &! Tangent input : now salinity
+         & ztn_tlin,     &! Tangent input : now temperature
+         & zsb_tlout,    &! Tangent output: before salinity
+         & ztb_tlout,    &! Tangent output: before temperature
+         & zsa_tlout,    &! Tangent output: after salinity
+         & zta_tlout,    &! Tangent output: after temperature
+         & zsn_tlout,    &! Tangent output: now salinity
+         & ztn_tlout,    &! Tangent output: now temperature
+         & zsb_adin,     &! Adjoint input : before salinity
+         & ztb_adin,     &! Adjoint input : before temperature
+         & zsa_adin,     &! Adjoint input : after salinity
+         & zta_adin,     &! Adjoint input : after temperature
+         & zsn_adin,     &! Adjoint input : now salinity
+         & ztn_adin,     &! Adjoint input : now temperature
+         & zsb_adout,    &! Adjoint output: before salinity
+         & ztb_adout,    &! Adjoint output: before temperature
+         & zsa_adout,    &! Adjoint output: after salinity
+         & zta_adout,    &! Adjoint output: after temperature
+         & zsn_adout,    &! Adjoint output: now salinity
+         & ztn_adout,    &! Adjoint output: now temperature
+         & zr             ! 3D field
+         
+      REAL(KIND=wp) ::       &
+         & zsp1,             & ! scalar product involving the tangent routine
+         & zsp1_1,           & ! scalar product involving the tangent routine
+         & zsp1_2,           & ! scalar product involving the tangent routine
+         & zsp1_3,           & ! scalar product involving the tangent routine
+         & zsp1_4,           & ! scalar product involving the tangent routine
+         & zsp1_5,           & ! scalar product involving the tangent routine
+         & zsp1_6,           & ! scalar product involving the tangent routine
+         & zsp2,             & ! scalar product involving the adjoint routine
+         & zsp2_1,           & ! scalar product involving the adjoint routine
+         & zsp2_2,           & ! scalar product involving the adjoint routine
+         & zsp2_3,           & ! scalar product involving the adjoint routine
+         & zsp2_4,           & ! scalar product involving the adjoint routine
+         & zsp2_5,           & ! scalar product involving the adjoint routine
+         & zsp2_6              ! scalar product involving the adjoint routine
+      CHARACTER(LEN=14) ::   &
+         & cl_name
+
+      ALLOCATE( & 
+         & zsb_tlin(jpi,jpj,jpk),    &! Tangent input : before salinity
+         & ztb_tlin(jpi,jpj,jpk),    &! Tangent input : before temperature
+         & zsa_tlin(jpi,jpj,jpk),    &! Tangent input : after salinity
+         & zta_tlin(jpi,jpj,jpk),    &! Tangent input : after temperature
+         & zsn_tlin(jpi,jpj,jpk),    &! Tangent input : now salinity
+         & ztn_tlin(jpi,jpj,jpk),    &! Tangent input : now temperature
+         & zsb_tlout(jpi,jpj,jpk),   &! Tangent output: before salinity
+         & ztb_tlout(jpi,jpj,jpk),   &! Tangent output: before temperature
+         & zsa_tlout(jpi,jpj,jpk),   &! Tangent output: after salinity
+         & zta_tlout(jpi,jpj,jpk),   &! Tangent output: after temperature
+         & zsn_tlout(jpi,jpj,jpk),   &! Tangent output: now salinity
+         & ztn_tlout(jpi,jpj,jpk),   &! Tangent output: now temperature
+         & zsb_adin(jpi,jpj,jpk),    &! Adjoint input : before salinity
+         & ztb_adin(jpi,jpj,jpk),    &! Adjoint input : before temperature
+         & zsa_adin(jpi,jpj,jpk),    &! Adjoint input : after salinity
+         & zta_adin(jpi,jpj,jpk),    &! Adjoint input : after temperature
+         & zsn_adin(jpi,jpj,jpk),    &! Adjoint input : now salinity
+         & ztn_adin(jpi,jpj,jpk),    &! Adjoint input : now temperature
+         & zsb_adout(jpi,jpj,jpk),   &! Adjoint output: before salinity
+         & ztb_adout(jpi,jpj,jpk),   &! Adjoint output: before temperature
+         & zsa_adout(jpi,jpj,jpk),   &! Adjoint output: after salinity
+         & zta_adout(jpi,jpj,jpk),   &! Adjoint output: after temperature
+         & zsn_adout(jpi,jpj,jpk),   &! Adjoint output: now salinity
+         & ztn_adout(jpi,jpj,jpk),   &! Adjoint output: now temperature
+         & zr       (jpi,jpj,jpk)    &! 3D field
+         & )
+
+      ll_dynhpg_imp = ln_dynhpg_imp     ! store namelist define time scheme
+
+      DO jn = 1, 2
+
+         IF ( jn .EQ. 1) ln_dynhpg_imp = .TRUE.
+         IF ( jn .EQ. 2) ln_dynhpg_imp = .FALSE.
+
+         !==================================================================
+         ! 1) dx = ( tb_tl, tn_tl, ta_tl,       dy = ( tb_tl, tn_tl, ta_tl,
+         !           sb_tl, sn_tl, sa_tl  ) and        sb_tl, sn_tl, sa_tl )
+         !==================================================================
+
+         !--------------------------------------------------------------------
+         ! Reset the tangent and adjoint variables
+         !--------------------------------------------------------------------
+         sb_tl(:,:,:) = 0.0_wp
+         tb_tl(:,:,:) = 0.0_wp
+         sa_tl(:,:,:) = 0.0_wp
+         ta_tl(:,:,:) = 0.0_wp
+         sn_tl(:,:,:) = 0.0_wp
+         tn_tl(:,:,:) = 0.0_wp
+         sb_ad(:,:,:) = 0.0_wp
+         tb_ad(:,:,:) = 0.0_wp
+         sa_ad(:,:,:) = 0.0_wp
+         ta_ad(:,:,:) = 0.0_wp
+         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
+
+         r2dt_t(:) =  2.* rdttra(:) ! initialization
+         
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 785483 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stds )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsb_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+               END DO
+            END DO
+         END DO
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 358606 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  ztb_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+               END DO
+            END DO
+         END DO
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 596035 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stds )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsa_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+               END DO
+            END DO
+         END DO
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 523432 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zta_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+               END DO
+            END DO
+         END DO
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 263957 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stds )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsn_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+               END DO
+            END DO
+         END DO
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 459031 + &
+                    &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  ztn_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+               END DO
+            END DO
+         END DO
+
+         sb_tl(:,:,:) = zsb_tlin(:,:,:) 
+         tb_tl(:,:,:) = ztb_tlin(:,:,:) 
+         sa_tl(:,:,:) = zsa_tlin(:,:,:) 
+         ta_tl(:,:,:) = zta_tlin(:,:,:)
+         sn_tl(:,:,:) = zsn_tlin(:,:,:) 
+         tn_tl(:,:,:) = ztn_tlin(:,:,:)
+
+         CALL tra_nxt_tan( nit000 + 1 )
+
+         zsa_tlout(:,:,:) = sa_tl(:,:,:) 
+         zta_tlout(:,:,:) = ta_tl(:,:,:)
+         zsb_tlout(:,:,:) = sb_tl(:,:,:) 
+         ztb_tlout(:,:,:) = tb_tl(:,:,:)
+         zsn_tlout(:,:,:) = sn_tl(:,:,:) 
+         ztn_tlout(:,:,:) = tn_tl(:,:,:)
+
+         !--------------------------------------------------------------------
+         ! Initialize the adjoint variables: dy^* = W dy
+         !--------------------------------------------------------------------
+
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsa_adin(ji,jj,jk)     = zsa_tlout(ji,jj,jk) &
+                       &                   * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                       &                   * tmask(ji,jj,jk) * wesp_s(jk)
+                  zta_adin(ji,jj,jk)     = zta_tlout(ji,jj,jk) &
+                       &                   * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                       &                   * tmask(ji,jj,jk) * wesp_t(jk)
+                  zsb_adin(ji,jj,jk)     = zsb_tlout(ji,jj,jk) &
+                       &                   * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                       &                   * tmask(ji,jj,jk) * wesp_s(jk)
+                  ztb_adin(ji,jj,jk)     = ztb_tlout(ji,jj,jk) &
+                       &                   * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                       &                   * tmask(ji,jj,jk) * wesp_t(jk)
+                  zsn_adin(ji,jj,jk)     = zsn_tlout(ji,jj,jk) &
+                       &                   * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                       &                   * tmask(ji,jj,jk) * wesp_s(jk)
+                  ztn_adin(ji,jj,jk)     = ztn_tlout(ji,jj,jk) &
+                       &                   * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                       &                   * tmask(ji,jj,jk) * wesp_t(jk)
+               END DO
+            END DO
+         END DO
+
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !--------------------------------------------------------------------
+
+         zsp1_1 = DOT_PRODUCT( zsa_tlout    , zsa_adin     )
+         zsp1_2 = DOT_PRODUCT( zta_tlout    , zta_adin     )
+         zsp1_3 = DOT_PRODUCT( zsb_tlout    , zsb_adin     )
+         zsp1_4 = DOT_PRODUCT( ztb_tlout    , ztb_adin     )
+         zsp1_5 = DOT_PRODUCT( zsn_tlout    , zsn_adin     )
+         zsp1_6 = DOT_PRODUCT( ztn_tlout    , ztn_adin     )
+         zsp1   = zsp1_1 + zsp1_2 + zsp1_3 + zsp1_4 + zsp1_5 + zsp1_6
+
+         !--------------------------------------------------------------------
+         ! Call the adjoint routine: dx^* = L^T dy^*
+         !--------------------------------------------------------------------
+
+         sa_ad(:,:,:)     = zsa_adin(:,:,:)
+         ta_ad(:,:,:)     = zta_adin(:,:,:)
+         sb_ad(:,:,:)     = zsb_adin(:,:,:)
+         tb_ad(:,:,:)     = ztb_adin(:,:,:)
+         sn_ad(:,:,:)     = zsn_adin(:,:,:)
+         tn_ad(:,:,:)     = ztn_adin(:,:,:)
+
+         CALL tra_nxt_adj ( nit000 + 1 )
+
+         zsb_adout(:,:,:) = sb_ad(:,:,:)
+         ztb_adout(:,:,:) = tb_ad(:,:,:)
+         zsa_adout(:,:,:) = sa_ad(:,:,:)
+         zta_adout(:,:,:) = ta_ad(:,:,:)
+         zsn_adout(:,:,:) = sn_ad(:,:,:)
+         ztn_adout(:,:,:) = tn_ad(:,:,:)
+
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: dx^T L^T W dy
+         !--------------------------------------------------------------------
+
+         zsp2_1 = DOT_PRODUCT( zsb_tlin  , zsb_adout   )
+         zsp2_2 = DOT_PRODUCT( ztb_tlin  , ztb_adout   )
+         zsp2_3 = DOT_PRODUCT( zsa_tlin  , zsa_adout   )
+         zsp2_4 = DOT_PRODUCT( zta_tlin  , zta_adout   )
+         zsp2_5 = DOT_PRODUCT( zsn_tlin  , zsn_adout   )
+         zsp2_6 = DOT_PRODUCT( ztn_tlin  , ztn_adout   )
+
+         zsp2 = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4 + zsp2_5 + zsp2_6
+
+         ! Compare the scalar products
+
+         ! 14 char:'12345678901234'
+         IF ( jn .EQ. 1) cl_name = 'tra_nxt_adj T1'
+         IF ( jn .EQ. 2) cl_name = 'tra_nxt_adj T2'
+         CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      ENDDO
+
+      ln_dynhpg_imp = ll_dynhpg_imp   ! restore initial value of ln_dynhpg_imp
+
+      DEALLOCATE( & 
+         & zsb_tlin,     &
+         & ztb_tlin,     &
+         & zsa_tlin,     &
+         & zta_tlin,     &
+         & zsn_tlin,     &
+         & ztn_tlin,     &
+         & zsb_tlout,    &
+         & ztb_tlout,    &
+         & zsa_tlout,    &
+         & zta_tlout,    &
+         & zsn_tlout,    &
+         & ztn_tlout,    &
+         & zsb_adin,     &
+         & ztb_adin,     &
+         & zsa_adin,     &
+         & zta_adin,     &
+         & zsn_adin,     &
+         & ztn_adin,     &
+         & zsb_adout,    &
+         & ztb_adout,    &
+         & zsa_adout,    &
+         & zta_adout,    &
+         & zsn_adout,    &
+         & ztn_adout,    &
+         & zr            &
+         & )
+
+     END SUBROUTINE tra_nxt_adj_tst
+   !!======================================================================
+#endif
+END MODULE tranxt_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traqsr_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traqsr_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traqsr_tam.F90	(revision 2578)
@@ -0,0 +1,701 @@
+MODULE traqsr_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  traqsr_tam  ***
+   !! Ocean physics: solar radiation penetration in the top ocean levels
+   !!                Tangent and Adjoint Module
+   !!======================================================================
+   !! History :  OPA  !  1990-10  (B. Blanke)  Original code
+   !!            7.0  !  1991-11  (G. Madec)
+   !!                 !  1996-01  (G. Madec)  s-coordinates
+   !!   NEMO     1.0  !  2002-06  (G. Madec)  F90: Free form and module
+   !!             -   !  2005-11  (G. Madec) zco, zps, sco coordinate
+   !!            3.2  !  2009-04  (G. Madec & NEMO team) 
+   !! History of the TAM:
+   !!                 !  2008-05  (A. Vidard) Skeleton
+   !!            3.0  !  2008-09  (A. Vidard)   TAM of the 2005-11 version
+   !!            3.2  !  2010-03  (F. Vigilant) TAM of the 2009-11 version
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_qsr      : trend due to the solar radiation penetration
+   !!   tra_qsr_init : solar radiation penetration initialization
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: &
+      & jpi,                 &
+      & jpj,                 &
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1,               &
+      & jpiglo
+   USE oce_tam       , ONLY: & ! ocean dynamics and active tracers
+      & ta_tl,               &
+      & ta_ad
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & tmask,               &
+      & ln_zco,              &
+      & ln_sco,              &
+      & ln_zps,              &
+      & e1t,                 &
+      & e2t,                 &
+#if ! defined key_zco
+      & e3t,                 &
+#endif
+      & e3t_0,               &
+      & gdepw_0,             &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              & 
+      & nit000,              & 
+      & nitend  
+   USE fldread                 ! read input fields
+   USE sbc_oce       , ONLY: & ! thermohaline fluxes
+      & qsr
+   USE sbc_oce_tam   , ONLY: & ! thermohaline fluxes
+      & qsr_tl,              &
+      & qsr_ad
+   USE phycst        , ONLY: & ! physical constants
+      & ro0cpr
+   USE prtctl        , ONLY: & ! Print control
+      & prt_ctl
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE traqsr        , ONLY: & ! Solar radiation penetration
+      & ln_traqsr,           &
+      & ln_qsr_rgb,          &
+      & ln_qsr_2bd,          &
+      & ln_qsr_bio,          &
+      & tra_qsr_init,        &
+      & rn_abs,              &
+      & rn_si0,              &
+      & rn_si1,              &
+      & rn_si2,              &
+      & nn_chldta,           &
+      & sf_chl,              &
+      & nksr,                &
+      & rkrgb
+   USE trc_oce       , ONLY: & ! share SMS/Ocean variables
+      & etot3,               &
+      & lk_qsr_bio
+   USE trc_oce_tam   , ONLY: & ! share SMS/Ocean variables
+      & trc_oce_tam_init,    &
+      & etot3_tl,            &
+      & etot3_ad
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          &
+      & stdqsr,              &
+      & stdt
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_qsr_tan      ! routine called by step_tam.F90 (ln_traqsr=T)
+   PUBLIC   tra_qsr_adj      ! routine called by step_tam.F90 (ln_traqsr=T)
+   PUBLIC   tra_qsr_adj_tst  ! routine called by tst.F90 
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE tra_qsr_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_qsr_tan  ***
+      !!
+      !! ** Purpose :   Compute the temperature trend due to the solar radiation
+      !!      penetration and add it to the general temperature trend.
+      !!
+      !! ** Method  : The profile of the solar radiation within the ocean is defined
+      !!      through 2 wavebands (rn_si0,rn_si1) or 3 wavebands (RGB) and a ratio rn_abs
+      !!      Considering the 2 wavebands case:
+      !!         I(k) = Qsr*( rn_abs*EXP(z(k)/rn_si0) + (1.-rn_abs)*EXP(z(k)/rn_si1) )
+      !!         The temperature trend associated with the solar radiation penetration 
+      !!         is given by : zta = 1/e3t dk[ I ] / (rau0*Cp)
+      !!         At the bottom, boudary condition for the radiation is no flux :
+      !!      all heat which has not been absorbed in the above levels is put
+      !!      in the last ocean level.
+      !!         In z-coordinate case, the computation is only done down to the
+      !!      level where I(k) < 1.e-15 W/m2. In addition, the coefficients 
+      !!      used for the computation are calculated one for once as they
+      !!      depends on k only.
+      !!
+      !! ** Action  : - update ta with the penetrative solar radiation trend
+      !!
+      !! Reference  : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
+      !!              Lengaigne et al. 2007, Clim. Dyn., V28, 5, 503-516.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt        ! ocean time-step
+      !
+      !!
+      INTEGER  ::    ji, jj, jk          ! dummy loop indexes
+      INTEGER  ::   irgb                 ! temporary integers
+      REAL(wp) ::   zchl, zcoef, zsi0r   ! temporary scalars
+      REAL(wp) ::   zc0tl, zc1tl, zc2tl, zc3tl   !    -         -
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zekb, zekg, zekr                      ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze0tl, ze1tl , ze2tl, ze3tl, zeatl    ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_qsr_tan : penetration of the surface solar radiation'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+         CALL tra_qsr_init
+         CALL tra_qsr_init_tan
+         IF( .NOT.ln_traqsr )   RETURN
+      ENDIF
+      !                                           ! ============================================== !
+      IF( lk_qsr_bio .AND. ln_qsr_bio ) THEN      !  bio-model fluxes  : all vertical coordinates  !
+         !                                        ! ============================================== !
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) + ro0cpr * ( etot3_tl(ji,jj,jk) - etot3_tl(ji,jj,jk+1) ) / fse3t(ji,jj,jk) 
+               END DO
+            END DO
+         END DO
+         !                                        ! ============================================== !
+      ELSE                                        !  Ocean alone : 
+         !                                        ! ============================================== !
+         !
+         !                                                ! ------------------------- !
+         IF( ln_qsr_rgb) THEN                             !  R-G-B  light penetration !
+            !                                             ! ------------------------- !
+            ! Set chlorophyl concentration
+            IF( nn_chldta ==1 ) THEN                             !*  Variable Chlorophyll
+               !
+               CALL fld_read( kt, 1, sf_chl )                         ! Read Chl data and provides it at the current time step
+               !         
+!CDIR COLLAPSE
+!CDIR NOVERRCHK
+               DO jj = 1, jpj                                         ! Separation in R-G-B depending of the surface Chl
+!CDIR NOVERRCHK
+                  DO ji = 1, jpi
+                     zchl = MIN( 10.0_wp , MAX( 0.03_wp, sf_chl(1)%fnow(ji,jj) ) )
+                     irgb = NINT( 41 + 20.*LOG10(zchl) + 1.e-15 )
+                     zekb(ji,jj) = rkrgb(1,irgb)
+                     zekg(ji,jj) = rkrgb(2,irgb)
+                     zekr(ji,jj) = rkrgb(3,irgb)
+                  END DO
+               END DO
+               !
+               zsi0r = 1.0_wp / rn_si0
+               zcoef  = ( 1.0_wp - rn_abs ) / 3.0_wp                        ! equi-partition in R-G-B
+               ze0tl(:,:,1) = rn_abs  * qsr_tl(:,:)
+               ze1tl(:,:,1) = zcoef * qsr_tl(:,:)
+               ze2tl(:,:,1) = zcoef * qsr_tl(:,:)
+               ze3tl(:,:,1) = zcoef * qsr_tl(:,:)
+               zeatl(:,:,1) =         qsr_tl(:,:)
+               !
+               DO jk = 2, nksr+1
+!CDIR NOVERRCHK
+                  DO jj = 1, jpj
+!CDIR NOVERRCHK   
+                     DO ji = 1, jpi
+                        zc0tl = ze0tl(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zsi0r     )
+                        zc1tl = ze1tl(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekb(ji,jj) )
+                        zc2tl = ze2tl(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekg(ji,jj) )
+                        zc3tl = ze3tl(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekr(ji,jj) )
+                        ze0tl(ji,jj,jk) = zc0tl
+                        ze1tl(ji,jj,jk) = zc1tl
+                        ze2tl(ji,jj,jk) = zc2tl
+                        ze3tl(ji,jj,jk) = zc3tl
+                        zeatl(ji,jj,jk) = ( zc0tl + zc1tl + zc2tl + zc3tl ) * tmask(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+               !
+               DO jk = 1, nksr                                        ! compute and add qsr trend to ta
+                  ta_tl(:,:,jk) = ta_tl(:,:,jk) + ro0cpr * ( zeatl(:,:,jk) - zeatl(:,:,jk+1) ) / fse3t(:,:,jk)
+               END DO
+               zeatl(:,:,nksr+1:jpk) = 0.0_wp     ! below 400m set to zero
+               !
+            ELSE                                                 !*  Constant Chlorophyll
+               DO jk = 1, nksr
+                  ta_tl(:,:,jk) = ta_tl(:,:,jk) + etot3_tl(:,:,jk) * qsr(:,:) + etot3(:,:,jk) * qsr_tl(:,:)
+               END DO
+            ENDIF
+
+         ENDIF
+         !                                                ! ------------------------- !
+         IF( ln_qsr_2bd ) THEN                            !  2 band light penetration !
+            !                                             ! ------------------------- !
+            !
+            DO jk = 1, nksr
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                     ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) + etot3_tl(ji,jj,jk) * qsr(ji,jj) + etot3(ji,jj,jk) * qsr_tl(ji,jj)
+                  END DO
+               END DO
+            END DO
+            !
+         ENDIF
+         !
+      ENDIF
+      !
+   END SUBROUTINE tra_qsr_tan
+   SUBROUTINE tra_qsr_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_qsr_adj  ***
+      !!
+      !! ** Purpose :   Compute the temperature trend due to the solar radiation
+      !!      penetration and add it to the general temperature trend.
+      !!
+      !! ** Method  : The profile of the solar radiation within the ocean is defined
+      !!      through 2 wavebands (rn_si0,rn_si1) or 3 wavebands (RGB) and a ratio rn_abs
+      !!      Considering the 2 wavebands case:
+      !!         I(k) = Qsr*( rn_abs*EXP(z(k)/rn_si0) + (1.-rn_abs)*EXP(z(k)/rn_si1) )
+      !!         The temperature trend associated with the solar radiation penetration 
+      !!         is given by : zta = 1/e3t dk[ I ] / (rau0*Cp)
+      !!         At the bottom, boudary condition for the radiation is no flux :
+      !!      all heat which has not been absorbed in the above levels is put
+      !!      in the last ocean level.
+      !!         In z-coordinate case, the computation is only done down to the
+      !!      level where I(k) < 1.e-15 W/m2. In addition, the coefficients 
+      !!      used for the computation are calculated one for once as they
+      !!      depends on k only.
+      !!
+      !! ** Action  : - update ta with the penetrative solar radiation trend
+      !!
+      !! Reference  : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
+      !!              Lengaigne et al. 2007, Clim. Dyn., V28, 5, 503-516.
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step
+      !
+      !!
+      INTEGER  ::    ji, jj, jk       ! dummy loop indexes
+      INTEGER  ::   irgb                 ! temporary integers
+      REAL(wp) ::   zchl, zcoef, zsi0r   ! temporary scalars
+      REAL(wp) ::   zc0ad, zc1ad, zc2ad, zc3ad   !    -         -
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zekb, zekg, zekr                      ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze0ad, ze1ad , ze2ad, ze3ad, zeaad    ! 3D workspace
+      !!----------------------------------------------------------------------
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_qsr_adj : penetration of the surface solar radiation'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+         CALL tra_qsr_init
+         IF( .NOT.ln_traqsr )   RETURN
+      ENDIF
+      !                                           ! ============================================== !
+      IF( lk_qsr_bio .AND. ln_qsr_bio ) THEN      !  bio-model fluxes  : all vertical coordinates  !
+         !                                        ! ============================================== !
+         DO jk = jpkm1, 1, -1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  etot3_ad(ji,jj,jk)   = etot3_ad(ji,jj,jk  ) + ro0cpr * ta_ad(ji,jj,jk) / fse3t(ji,jj,jk)
+                  etot3_ad(ji,jj,jk+1) = etot3_ad(ji,jj,jk+1) - ro0cpr * ta_ad(ji,jj,jk) / fse3t(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !                                        ! ============================================== !
+      ELSE                                        !  Ocean alone : 
+         !                                        ! ============================================== !
+         !
+         !                                                ! ------------------------- !
+         IF( ln_qsr_2bd ) THEN                            !  2 band light penetration !
+            !                                             ! ------------------------- !
+            !
+            DO jk = 1, nksr
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                     etot3_ad(ji,jj,jk) = etot3_ad(ji,jj,jk) + ta_ad(ji,jj,jk) *  qsr(ji,jj)
+                     qsr_ad(ji,jj     ) = qsr_ad(ji,jj     ) + ta_ad(ji,jj,jk) * etot3(ji,jj,jk)    
+                  END DO
+               END DO
+            END DO
+            !
+         ENDIF
+         !
+         !                                                ! ------------------------- !
+         IF( ln_qsr_rgb) THEN                             !  R-G-B  light penetration !
+            !                                             ! ------------------------- !
+            ! Set chlorophyl concentration
+            IF( nn_chldta ==1 ) THEN                             !*  Variable Chlorophyll
+               zc0ad = 0.0_wp; zc1ad = 0.0_wp; zc2ad = 0.0_wp; zc3ad = 0.0_wp
+               ze0ad(:,:,:) = 0.0_wp; ze1ad(:,:,:) = 0.0_wp; ze2ad(:,:,:) = 0.0_wp; ze3ad(:,:,:) = 0.0_wp
+               zeaad(:,:,:) = 0.0_wp
+               !
+               CALL fld_read( kt, 1, sf_chl )                         ! Read Chl data and provides it at the current time step
+               !         
+!CDIR COLLAPSE
+!CDIR NOVERRCHK
+               DO jj = 1, jpj                                         ! Separation in R-G-B depending of the surface Chl
+!CDIR NOVERRCHK
+                  DO ji = 1, jpi
+                     zchl = MIN( 10.0_wp , MAX( 0.03_wp, sf_chl(1)%fnow(ji,jj) ) )
+                     irgb = NINT( 41 + 20.*LOG10(zchl) + 1.e-15 )
+                     zekb(ji,jj) = rkrgb(1,irgb)
+                     zekg(ji,jj) = rkrgb(2,irgb)
+                     zekr(ji,jj) = rkrgb(3,irgb)
+                  END DO
+               END DO
+               !
+               zsi0r = 1.0_wp / rn_si0
+               zcoef  = ( 1.0_wp - rn_abs ) / 3.0_wp
+
+               zeaad(:,:,nksr+1:jpk) = 0.0_wp     ! below 400m set to zero
+               !
+               DO jk = 1, nksr                                        ! compute and add qsr trend to ta
+                  zeaad(:,:,jk  ) =   ro0cpr * ta_ad(:,:,jk) / fse3t(:,:,jk)
+                  zeaad(:,:,jk+1) = - ro0cpr * ta_ad(:,:,jk) / fse3t(:,:,jk)                  
+               END DO
+               !
+               DO jk = nksr+1, 2, -1
+!CDIR NOVERRCHK
+                  DO jj = 1, jpj
+!CDIR NOVERRCHK   
+                     DO ji = 1, jpi
+                        zc0ad = zc0ad + zeaad(ji,jj,jk) * tmask(ji,jj,jk)
+                        zc1ad = zc1ad + zeaad(ji,jj,jk) * tmask(ji,jj,jk)
+                        zc2ad = zc2ad + zeaad(ji,jj,jk) * tmask(ji,jj,jk)
+                        zc3ad = zc3ad + zeaad(ji,jj,jk) * tmask(ji,jj,jk)
+                        zeaad(ji,jj,jk) = 0.0_wp
+                        zc0ad = zc0ad + ze0ad(ji,jj,jk)
+                        zc1ad = zc1ad + ze1ad(ji,jj,jk)
+                        zc2ad = zc2ad + ze2ad(ji,jj,jk)
+                        zc3ad = zc3ad + ze3ad(ji,jj,jk)
+                        ze0ad(ji,jj,jk) = 0.0_wp
+                        ze1ad(ji,jj,jk) = 0.0_wp
+                        ze2ad(ji,jj,jk) = 0.0_wp
+                        ze3ad(ji,jj,jk) = 0.0_wp
+                        ze0ad(ji,jj,jk-1) = ze0ad(ji,jj,jk-1) + zc0ad * EXP( - fse3t(ji,jj,jk-1) * zsi0r     )
+                        ze1ad(ji,jj,jk-1) = ze1ad(ji,jj,jk-1) + zc1ad * EXP( - fse3t(ji,jj,jk-1) * zekb(ji,jj) )
+                        ze2ad(ji,jj,jk-1) = ze2ad(ji,jj,jk-1) + zc2ad * EXP( - fse3t(ji,jj,jk-1) * zekg(ji,jj) )
+                        ze3ad(ji,jj,jk-1) = ze3ad(ji,jj,jk-1) + zc3ad * EXP( - fse3t(ji,jj,jk-1) * zekr(ji,jj) )
+                        zc0ad = 0.0_wp
+                        zc1ad = 0.0_wp
+                        zc2ad = 0.0_wp
+                        zc3ad = 0.0_wp
+                     END DO
+                  END DO
+               END DO
+               !
+               qsr_ad(:,:) = qsr_ad(:,:) + zeaad(:,:,1)
+               qsr_ad(:,:) = qsr_ad(:,:) + zcoef  * ze3ad(:,:,1)
+               qsr_ad(:,:) = qsr_ad(:,:) + zcoef  * ze2ad(:,:,1)               
+               qsr_ad(:,:) = qsr_ad(:,:) + zcoef  * ze1ad(:,:,1)               
+               qsr_ad(:,:) = qsr_ad(:,:) + rn_abs * ze0ad(:,:,1)
+               !
+            ELSE                                                 !*  Constant Chlorophyll
+               DO jk = 1, nksr
+                  etot3_ad(:,:,jk) = etot3_ad(:,:,jk) + ta_ad(:,:,jk) * qsr(:,:)
+                  qsr_ad(  :,:   ) = qsr_ad(  :,:   ) + ta_ad(:,:,jk) * etot3(:,:,jk)
+               END DO
+            ENDIF
+         ENDIF
+      ENDIF
+
+      IF( kt == nit000 ) THEN
+         CALL tra_qsr_init_adj
+      ENDIF
+
+   END SUBROUTINE tra_qsr_adj
+   SUBROUTINE tra_qsr_adj_tst ( kumadt ) 
+      !!-----------------------------------------------------------------------
+      !!
+      !!          ***  ROUTINE tra_sbc_adj_tst : TEST OF tra_sbc_adj  ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      INTEGER ::  &
+         & jstp,  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zta_tlin,     &! Tangent input : after temperature
+         & zta_tlout,    &! Tangent output: after temperature 
+         & zta_adout,    &! Adjoint output: after temperature 
+         & zta_adin,     &! Adjoint input : after temperature
+         & zetot3_tlin,  &! Tangent input 
+         & zetot3_adout, &! Adjoint output 
+         & zta,          & ! temporary after temperature
+         & zetot3          ! temporary 
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zqsr_tlin,    &! Tangent input : solar radiation (w/m2)
+         & zqsr_adout,   &! Adjoint output: solar radiation (w/m2)
+         & zqsr           ! temporary solar radiation (w/m2)
+      REAL(KIND=wp) ::       &
+         & zsp1,             & ! scalar product involving the tangent routine
+         & zsp2,             & ! scalar product involving the adjoint routine
+         & zsp2_1,           & ! scalar product involving the adjoint routine
+         & zsp2_2,           & ! scalar product involving the adjoint routine
+         & zsp2_3              ! scalar product involving the adjoint routine
+      CHARACTER(LEN=14) :: &
+         & cl_name
+
+      ALLOCATE( & 
+         & zta_tlin(jpi,jpj,jpk),     &
+         & zta_tlout(jpi,jpj,jpk),    &
+         & zta_adout(jpi,jpj,jpk),    &
+         & zta_adin(jpi,jpj,jpk),     &
+         & zta(jpi,jpj,jpk),          &
+         & zqsr_tlin(jpi,jpj),        &
+         & zqsr_adout(jpi,jpj),       &
+         & zetot3_tlin(jpi,jpj,jpk),  &
+         & zetot3_adout(jpi,jpj,jpk), &
+         & zqsr(jpi,jpj),             &
+         & zetot3(jpi,jpj,jpk)        &
+         & )
+      ! Initialize the reference state
+      qsr(:,:) = 1.0_wp ! ???
+      !Initialize etot3 to non-zero value until traj(nit000-1) is fixed
+      etot3(:,:,1) = 2.e-8   ; etot3(:,:,2) = 1.5e-9; etot3(:,:,3) = 8.5e-10
+      etot3(:,:,4) = 5.4e-10 ; etot3(:,:,5) = 3.5e-10; etot3(:,:,6:jpk) = 0.0_wp 
+      ! Initialize random field standard deviations
+      !=============================================================
+      ! 1) dx = ( T ) and dy = ( T )
+      !=============================================================
+
+      CALL trc_oce_tam_init( 0 )
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      zta_tlin(:,:,:)     = 0.0_wp     
+      zta_tlout(:,:,:)    = 0.0_wp    
+      zta_adout(:,:,:)    = 0.0_wp    
+      zta_adin(:,:,:)     = 0.0_wp     
+      zqsr_adout(:,:)     = 0.0_wp       
+      zqsr_tlin(:,:)      = 0.0_wp 
+      zetot3_tlin(:,:,:)  = 0.0_wp
+      zetot3_adout(:,:,:) = 0.0_wp 
+      ta_ad(:,:,:)        = 0.0_wp
+      qsr_ad(:,:)         = 0.0_wp
+      etot3_ad(:,:,:)     = 0.0_wp
+      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 358606 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zqsr, 'T', 0.0_wp, stdqsr )
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 232567 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zta, 'T', 0.0_wp, stdt )
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 148379 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zetot3, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zta_tlin(ji,jj,jk) = zta(ji,jj,jk)
+            END DO
+         END DO
+      END DO 
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zetot3_tlin(ji,jj,jk) = zetot3(ji,jj,jk)
+            END DO
+         END DO
+      END DO 
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zqsr_tlin(ji,jj)  = zqsr(ji,jj)
+         END DO
+      END DO
+      ! Test for time steps nit000 and nit000 + 1 (the matrix changes)
+      DO jstp = nit000, nit000 + 1
+         !--------------------------------------------------------------------
+         ! Call the tangent routine: dy = L dx
+         !--------------------------------------------------------------------
+         
+         ta_tl(:,:,:)    = zta_tlin(:,:,:)
+         etot3_tl(:,:,:) = zetot3_tlin(:,:,:)
+         qsr_tl(:,:)     = zqsr_tlin(:,:)
+      
+         CALL tra_qsr_tan( jstp )
+         
+         zta_tlout(:,:,:) = ta_tl(:,:,:)
+         
+         !--------------------------------------------------------------------
+         ! Initialize the adjoint variables: dy^* = W dy
+         !--------------------------------------------------------------------
+      
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zta_adin(ji,jj,jk) = zta_tlout(ji,jj,jk) &
+                     &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                     &               * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !--------------------------------------------------------------------
+
+         zsp1 = DOT_PRODUCT( zta_tlout, zta_adin )
+
+         !--------------------------------------------------------------------
+         ! Call the adjoint routine: dx^* = L^T dy^*
+         !--------------------------------------------------------------------
+
+         etot3_ad(:,:,:)  = 0.0_wp
+         qsr_ad(:,:)      = 0.0_wp       
+         ta_ad(:,:,:)     = zta_adin(:,:,:)
+         
+         CALL tra_qsr_adj( jstp )
+
+         zta_adout(:,:,:)    = ta_ad(:,:,:)
+         zetot3_adout(:,:,:) = etot3_ad(:,:,:)
+         zqsr_adout(:,:)     = qsr_ad(:,:)
+      
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: dx^T L^T W dy
+         !--------------------------------------------------------------------
+
+         zsp2_1 = DOT_PRODUCT( zta_tlin    , zta_adout   )
+         zsp2_2 = DOT_PRODUCT( zqsr_tlin   , zqsr_adout  )
+         zsp2_3 = DOT_PRODUCT( zetot3_tlin , zetot3_adout  )
+      
+         zsp2 = zsp2_1 + zsp2_2 + zsp2_3
+      
+         ! Compare the scalar products
+      
+         ! 14 char:   '12345678901234'
+         IF (jstp == nit000) THEN
+            cl_name = 'tra_qsr_adj  1'
+         ELSE
+            cl_name = 'tra_qsr_adj  2'
+         END IF
+         CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+      END DO
+      
+      DEALLOCATE( & 
+         & zta_tlin,     &
+         & zta_tlout,    &
+         & zta_adout,    &
+         & zta_adin,     &
+         & zta,          &
+         & zqsr_adout,   &
+         & zqsr_tlin,    &
+         & zqsr          &
+         & )
+
+      !
+   END SUBROUTINE tra_qsr_adj_tst
+   SUBROUTINE tra_qsr_init_tan
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_qsr_init_tan  ***
+      !!
+      !! ** Purpose :   Initialization for the penetrative solar radiation
+      !!
+      !! ** Method  :   The profile of solar radiation within the ocean is set
+      !!      from two length scale of penetration (rn_si0,rn_si1) and a ratio
+      !!      (rn_abs). These parameters are read in the namtra_qsr namelist. The
+      !!      default values correspond to clear water (type I in Jerlov' 
+      !!      (1968) classification.
+      !!         called by tra_qsr at the first timestep (nit000)
+      !!
+      !! ** Action  : - initialize rn_si0, rn_si1 and rn_abs
+      !!
+      !! Reference : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
+      !!----------------------------------------------------------------------
+
+      IF( ln_traqsr  ) THEN      !  Initialisation of Light Penetration  !  
+         !                       ! ===================================== !
+         !
+         !                                ! ---------------------------------- !
+         IF( ln_qsr_rgb ) THEN            !  Red-Green-Blue light penetration  !
+            !                             ! ---------------------------------- !
+            etot3_tl(:,:,:) = 0.0_wp               
+            !
+         ENDIF
+            !                             ! ---------------------------------- !
+         IF( ln_qsr_2bd ) THEN            !    2 bands    light penetration    !
+            !                             ! ---------------------------------- !
+            etot3_tl(:,:,:) = 0.0_wp               
+            !
+         ENDIF
+         !
+      ENDIF
+      !
+   END SUBROUTINE tra_qsr_init_tan
+   SUBROUTINE tra_qsr_init_adj
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_qsr_init_adj  ***
+      !!
+      !! ** Purpose :   Initialization for the penetrative solar radiation
+      !!
+      !! ** Method  :   The profile of solar radiation within the ocean is set
+      !!      from two length scale of penetration (rn_si0,rn_si1) and a ratio
+      !!      (rn_abs). These parameters are read in the namtra_qsr namelist. The
+      !!      default values correspond to clear water (type I in Jerlov' 
+      !!      (1968) classification.
+      !!         called by tra_qsr at the first timestep (nit000)
+      !!
+      !! ** Action  : - initialize rn_si0, rn_si1 and rn_abs
+      !!
+      !! Reference : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
+      !!----------------------------------------------------------------------
+
+      IF( ln_traqsr  ) THEN      !  Initialisation of Light Penetration  !  
+         !                       ! ===================================== !
+         !
+         !                                ! ---------------------------------- !
+         IF( ln_qsr_rgb ) THEN            !  Red-Green-Blue light penetration  !
+            !                             ! ---------------------------------- !
+            etot3_ad(:,:,:) = 0.0_wp               
+            !
+         ENDIF
+            !                             ! ---------------------------------- !
+         IF( ln_qsr_2bd ) THEN            !    2 bands    light penetration    !
+            !                             ! ---------------------------------- !
+            etot3_ad(:,:,:) = 0.0_wp               
+            !
+         ENDIF
+         !
+      ENDIF
+      !
+  END SUBROUTINE tra_qsr_init_adj
+
+   !!======================================================================
+#endif
+END MODULE traqsr_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trasbc_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trasbc_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trasbc_tam.F90	(revision 2578)
@@ -0,0 +1,994 @@
+MODULE trasbc_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                       ***  MODULE  trasbc_tam  ***
+   !! Ocean active tracers:  surface boundary condition
+   !!                        Tangent and Adjoint Module
+   !!==============================================================================
+   !! History of the direct module:
+   !!            8.2  !  98-10  (G. Madec, G. Roullet, M. Imbard)  Original code
+   !!            8.2  !  01-02  (D. Ludicone)  sea ice and free surface
+   !!            8.5  !  02-06  (G. Madec)  F90: Free form and module
+   !! History of the TAM:
+   !!                 !  2008-05  (A. Vidard) Skeleton
+   !!                 !  2008-11  (A. Vidard) tam of the 02-06 version
+   !!                 !  2010-04 (F. Vigilant) 3.2 version
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_sbc      : update the tracer trend at ocean surface
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 &
+      & jpk,                 & 
+      & jpim1,               &
+      & jpjm1,               &
+      & jpiglo
+   USE oce           , ONLY: & ! ocean dynamics and active tracers
+      & sn
+   USE oce_tam       , ONLY: & ! tangent and adjoint ocean dynamics and active tracers
+      & sn_tl,               &
+      & sa_tl,               &
+      & ta_tl,               &
+      & sn_ad,               &
+      & sa_ad,               &
+      & ta_ad
+   USE sbc_oce_tam   , ONLY: & ! surface thermohaline fluxes
+      & qns_tl,              &
+      & qsr_tl,              &
+      & emps_tl,             &
+      & qns_ad,              &
+      & qsr_ad,              &
+      & emps_ad
+   USE sbc_oce       , ONLY: & ! surface thermohaline fluxes
+      & emps
+   USE dom_oce       , ONLY: & ! ocean space domain variables
+      & rdt,                 &
+      & e1t,                 &
+      & e2t,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3t,                 &
+#endif
+      & tmask,               &
+      & lk_vvl,              &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE traqsr        , ONLY: & ! solar radiation penetration
+      & ln_traqsr
+   USE phycst        , ONLY: & ! physical constant
+      & rau0,                &
+      & ro0cpr
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & ctl_stop,            &
+      & lwp,                 &
+      & numout,              & 
+      & nit000,              &
+      & nitend
+   USE prtctl        , ONLY: & ! Print control
+      & prt_ctl
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE paresp        , ONLY: & ! Weights for an energy-type scalar product
+      & wesp_t,              &
+      & wesp_s
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          &
+      & prntst_tlm,          & !
+      & stdqns,              &
+      & stdt,                &
+      & stds,                &
+      & stdemp
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_sbc_tan     ! routine called by step_tam.F90
+   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
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+
+CONTAINS
+
+   SUBROUTINE tra_sbc_tan ( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_sbc_tan  ***
+      !!                   
+      !! ** Purpose of the direct routine:
+      !!      Compute the tracer surface boundary condition trend of
+      !!      (flux through the interface, concentration/dilution effect)
+      !!      and add it to the general trend of tracer equations.
+      !!
+      !! ** Method :
+      !!      Following Roullet and Madec (2000), the air-sea flux can be divided 
+      !!      into three effects: (1) Fext, external forcing; 
+      !!      (2) Fwi, concentration/dilution effect due to water exchanged 
+      !!         at the surface by evaporation, precipitations and runoff (E-P-R); 
+      !!      (3) Fwe, tracer carried with the water that is exchanged. 
+      !!
+      !!      Fext, flux through the air-sea interface for temperature and salt: 
+      !!            - temperature : heat flux q (w/m2). If penetrative solar
+      !!         radiation q is only the non solar part of the heat flux, the
+      !!         solar part is added in traqsr.F routine.
+      !!            ta = ta + q /(rau0 rcp e3t)  for k=1
+      !!            - salinity    : no salt flux
+      !!
+      !!      The formulation for Fwb and Fwi vary according to the free 
+      !!      surface formulation (linear or variable volume). 
+      !!      * Linear free surface
+      !!            The surface freshwater flux modifies the ocean volume
+      !!         and thus the concentration of a tracer and the temperature.
+      !!         First order of the effect of surface freshwater exchange 
+      !!         for salinity, it can be neglected on temperature (especially
+      !!         as the temperature of precipitations and runoffs is usually
+      !!         unknown).
+      !!            - temperature : we assume that the temperature of both
+      !!         precipitations and runoffs is equal to the SST, thus there
+      !!         is no additional flux since in this case, the concentration
+      !!         dilution effect is balanced by the net heat flux associated
+      !!         to the freshwater exchange (Fwe+Fwi=0):
+      !!            (Tp P - Te E) + SST (P-E) = 0 when Tp=Te=SST
+      !!            - salinity    : evaporation, precipitation and runoff
+      !!         water has a zero salinity (Fwe=0), thus only Fwi remains:
+      !!            sa = sa + emp * sn / e3t   for k=1
+      !!         where emp, the surface freshwater budget (evaporation minus
+      !!         precipitation minus runoff) given in kg/m2/s is divided
+      !!         by 1035 kg/m3 (density of ocean water) to obtain m/s.    
+      !!         Note: even though Fwe does not appear explicitly for 
+      !!         temperature in this routine, the heat carried by the water
+      !!         exchanged through the surface is part of the total heat flux
+      !!         forcing and must be taken into account in the global heat
+      !!         balance).
+      !!      * nonlinear free surface (variable volume, lk_vvl)
+      !!         contrary to the linear free surface case, Fwi is properly 
+      !!         taken into account by using the true layer thicknesses to       
+      !!         calculate tracer content and advection. There is no need to 
+      !!         deal with it in this routine.
+      !!           - temperature: Fwe=SST (P-E+R) is added to Fext.
+      !!           - salinity:  Fwe = 0, there is no surface flux of salt.
+      !!
+      !! ** Action  : - Update the 1st level of (ta,sa) with the trend associated
+      !!                with the tracer surface boundary condition 
+      !!              - save the trend it in ttrd ('key_trdtra')
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj                   ! dummy loop indices
+      REAL(wp) ::   ztatl, zsatl, zsrau, zse3t   ! temporary scalars
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_sbc_tan : TRAcer Surface Boundary Condition'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+
+      zsrau = 1.0_wp / rau0             ! initialization
+#if defined key_zco
+      zse3t = 1.0_wp / e3t_0(1)
+#endif
+
+      IF( .NOT.ln_traqsr )   qsr_tl(:,:) = 0.e0_wp   ! no solar radiation penetration
+
+      ! Concentration dillution effect on (t,s)
+      DO jj = 2, jpj
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+#if ! defined key_zco
+            zse3t = 1.0_wp / fse3t(ji,jj,1)
+#endif
+            IF( lk_vvl ) THEN
+               CALL ctl_stop( 'key_vvl  not available in NEMOTAM' )
+            ELSE
+               ! temperature : heat flux
+               ztatl = ro0cpr * zse3t * qns_tl(ji,jj)         
+
+               ! salinity :  concent./dilut. effect
+               zsatl = (   emps_tl(ji,jj) * sn   (ji,jj,1) &  
+                  &      + emps   (ji,jj) * sn_tl(ji,jj,1) ) * zsrau * zse3t     
+            ENDIF
+            ta_tl(ji,jj,1) = ta_tl(ji,jj,1) + ztatl    ! add the trend to the general tracer trend
+            sa_tl(ji,jj,1) = sa_tl(ji,jj,1) + zsatl
+         END DO
+      END DO
+
+   END SUBROUTINE tra_sbc_tan
+
+   SUBROUTINE tra_sbc_adj ( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_sbc_adj  ***
+      !!                   
+      !! ** Purpose of the direct routine:
+      !!      Compute the tracer surface boundary condition trend of
+      !!      (flux through the interface, concentration/dilution effect)
+      !!      and add it to the general trend of tracer equations.
+      !!
+      !! ** Method :
+      !!      Following Roullet and Madec (2000), the air-sea flux can be divided 
+      !!      into three effects: (1) Fext, external forcing; 
+      !!      (2) Fwi, concentration/dilution effect due to water exchanged 
+      !!         at the surface by evaporation, precipitations and runoff (E-P-R); 
+      !!      (3) Fwe, tracer carried with the water that is exchanged. 
+      !!
+      !!      Fext, flux through the air-sea interface for temperature and salt: 
+      !!            - temperature : heat flux q (w/m2). If penetrative solar
+      !!         radiation q is only the non solar part of the heat flux, the
+      !!         solar part is added in traqsr.F routine.
+      !!            ta = ta + q /(rau0 rcp e3t)  for k=1
+      !!            - salinity    : no salt flux
+      !!
+      !!      The formulation for Fwb and Fwi vary according to the free 
+      !!      surface formulation (linear or variable volume). 
+      !!      * Linear free surface
+      !!            The surface freshwater flux modifies the ocean volume
+      !!         and thus the concentration of a tracer and the temperature.
+      !!         First order of the effect of surface freshwater exchange 
+      !!         for salinity, it can be neglected on temperature (especially
+      !!         as the temperature of precipitations and runoffs is usually
+      !!         unknown).
+      !!            - temperature : we assume that the temperature of both
+      !!         precipitations and runoffs is equal to the SST, thus there
+      !!         is no additional flux since in this case, the concentration
+      !!         dilution effect is balanced by the net heat flux associated
+      !!         to the freshwater exchange (Fwe+Fwi=0):
+      !!            (Tp P - Te E) + SST (P-E) = 0 when Tp=Te=SST
+      !!            - salinity    : evaporation, precipitation and runoff
+      !!         water has a zero salinity (Fwe=0), thus only Fwi remains:
+      !!            sa = sa + emp * sn / e3t   for k=1
+      !!         where emp, the surface freshwater budget (evaporation minus
+      !!         precipitation minus runoff) given in kg/m2/s is divided
+      !!         by 1000 kg/m3 (density of plain water) to obtain m/s.    
+      !!         Note: even though Fwe does not appear explicitly for 
+      !!         temperature in this routine, the heat carried by the water
+      !!         exchanged through the surface is part of the total heat flux
+      !!         forcing and must be taken into account in the global heat
+      !!         balance).
+      !!      * nonlinear free surface (variable volume, lk_vvl)
+      !!         contrary to the linear free surface case, Fwi is properly 
+      !!         taken into account by using the true layer thicknesses to       
+      !!         calculate tracer content and advection. There is no need to 
+      !!         deal with it in this routine.
+      !!           - temperature: Fwe=SST (P-E+R) is added to Fext.
+      !!           - salinity:  Fwe = 0, there is no surface flux of salt.
+      !!
+      !! ** Action  : - Update the 1st level of (ta,sa) with the trend associated
+      !!                with the tracer surface boundary condition 
+      !!              - save the trend it in ttrd ('key_trdtra')
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj                   ! dummy loop indices
+      REAL(wp) ::   ztaad, zsaad, zsrau, zse3t   ! temporary scalars
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_sbc_adj : TRAcer Surface Boundary Condition'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+
+      zsrau = 1.0_wp / rau0             ! initialization
+#if defined key_zco
+      zse3t = 1.0_wp / e3t_0(1)
+#endif
+
+      ! Concentration dillution effect on (t,s)
+      DO jj = jpj, 2, -1
+         DO ji = fs_jpim1, fs_2, -1   ! vector opt.
+#if ! defined key_zco
+            zse3t = 1.0_wp / fse3t(ji,jj,1)
+#endif
+            ztaad = ta_ad(ji,jj,1)          ! add the trend to the general tracer trend
+            zsaad = sa_ad(ji,jj,1) 
+            IF( lk_vvl) THEN
+               CALL ctl_stop( 'key_vvl  not available in NEMOTAM' )
+            ELSE
+               ztaad = ztaad * ro0cpr * zse3t
+               zsaad = zsaad * zsrau  * zse3t
+               qns_ad(ji,jj)  = qns_ad(ji,jj)  + ztaad
+               emps_ad(ji,jj) = emps_ad(ji,jj) + zsaad * sn(ji,jj,1)
+               sn_ad(ji,jj,1) = sn_ad(ji,jj,1) + zsaad * emps(ji,jj)
+            ENDIF
+         END DO
+      END DO
+
+      IF( .NOT.ln_traqsr )   qsr_ad(:,:) = 0.e0_wp   ! no solar radiation penetration
+
+   END SUBROUTINE tra_sbc_adj
+
+   SUBROUTINE tra_sbc_adj_tst ( kumadt ) 
+      !!-----------------------------------------------------------------------
+      !!
+      !!          ***  ROUTINE tra_sbc_adj_tst : TEST OF tra_sbc_adj  ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE trj_tam
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      INTEGER :: &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zsn_tlin,     &! Tangent input : now salinity
+         & zsa_tlin,     &! Tangent input : after salinity
+         & zta_tlin,     &! Tangent input : after temperature
+         & zqns_tlin,    &! Tangent input : solar radiation (w/m2)
+         & zemps_tlin,   &! Tangent input : evaporation - precipitation (free surface)
+         & zsa_tlout,    &! Tangent output: after salinity 
+         & zta_tlout,    &! Tangent output: after temperature 
+         & zsa_adin,     &! Adjoint input : after salinity
+         & zta_adin,     &! Adjoint input : after temperature
+         & zsn_adout,    &! Adjoint output: now salinity
+         & zsa_adout,    &! Adjoint output: after salinity 
+         & zta_adout,    &! Adjoint output: after temperature 
+         & zqns_adout,   &! Adjoint output: solar radiation (w/m2)
+         & zemps_adout,  &! Adjoint output: evaporation - precipitation (free surface)
+         & zsn,          &! temporary now salinity
+         & zsa,          &! temporary after salinity
+         & zta,          &! temporary after temperature
+         & zqns,         &! temporary solar radiation (w/m2)
+         & zemps          ! temporary evaporation - precipitation (free surface)
+      REAL(KIND=wp) ::       &
+         & zsp1,             & ! scalar product involving the tangent routine
+         & zsp1_1,           & ! scalar product involving the tangent routine
+         & zsp1_2,           & ! scalar product involving the tangent routine
+         & zsp2,             & ! scalar product involving the adjoint routine
+         & zsp2_1,           & ! scalar product involving the adjoint routine
+         & zsp2_2,           & ! scalar product involving the adjoint routine
+         & zsp2_3,           & ! scalar product involving the adjoint routine
+         & zsp2_4,           & ! scalar product involving the adjoint routine
+         & zsp2_5,           & ! scalar product involving the adjoint routine
+         & z2dt,             & ! temporary scalars
+         & zraur
+      CHARACTER (LEN=14) :: &
+         & cl_name
+
+      ALLOCATE( & 
+         & zsn_tlin(jpi,jpj),     &
+         & zsa_tlin(jpi,jpj),     &
+         & zta_tlin(jpi,jpj),     &
+         & zsa_tlout(jpi,jpj),    &
+         & zta_tlout(jpi,jpj),    &
+         & zsn_adout(jpi,jpj),    &
+         & zsa_adout(jpi,jpj),    &
+         & zta_adout(jpi,jpj),    &
+         & zsa_adin(jpi,jpj),     &
+         & zta_adin(jpi,jpj),     &
+         & zsn(jpi,jpj),          &
+         & zsa(jpi,jpj),          &
+         & zta(jpi,jpj),          &
+         & zqns_adout(jpi,jpj),   &
+         & zqns_tlin(jpi,jpj),    &
+         & zemps_tlin(jpi,jpj),   &
+         & zemps_adout(jpi,jpj),  &
+         & zqns(jpi,jpj),         &
+         & zemps(jpi,jpj)         &
+         & )
+
+
+      ! Initialize constants
+      z2dt  = 2.0_wp * rdt       ! time step: leap-frog
+      zraur = 1.0_wp / rau0      ! inverse density of pure water (m3/kg)
+
+      ! Initialize the reference state
+
+      !===========================================================================
+      ! 1) dx = ( qns_tl, sn_tl, emps_tl, ta_tl, sa_tl ) and dy = ( ta_tl, sa_tl )
+      !===========================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+
+      sn_tl  (:,:,:) = 0.0_wp
+      sa_tl  (:,:,:) = 0.0_wp
+      ta_tl  (:,:,:) = 0.0_wp
+      emps_tl(:,:)   = 0.0_wp
+      qns_tl (:,:)   = 0.0_wp
+      sn_ad  (:,:,:) = 0.0_wp
+      sa_ad  (:,:,:) = 0.0_wp
+      ta_ad  (:,:,:) = 0.0_wp
+      emps_ad(:,:)   = 0.0_wp
+      qns_ad (:,:)   = 0.0_wp
+
+      zsn_tlin   (:,:) = 0.0_wp     
+      zsa_tlin   (:,:) = 0.0_wp     
+      zta_tlin   (:,:) = 0.0_wp     
+      zsa_tlout  (:,:) = 0.0_wp    
+      zta_tlout  (:,:) = 0.0_wp    
+      zsn_adout  (:,:) = 0.0_wp    
+      zsa_adout  (:,:) = 0.0_wp    
+      zta_adout  (:,:) = 0.0_wp    
+      zsa_adin   (:,:) = 0.0_wp     
+      zta_adin   (:,:) = 0.0_wp     
+      zqns_tlin  (:,:) = 0.0_wp        
+      zqns_adout (:,:) = 0.0_wp       
+      zemps_tlin (:,:) = 0.0_wp       
+      zemps_adout(:,:) = 0.0_wp      
+      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 785483 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zemps, 'T', 0.0_wp, stdemp )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 358606 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zqns, 'T', 0.0_wp, stdqns )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 523432 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zsn, 'T', 0.0_wp, stds )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 297563 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zsa, 'T', 0.0_wp, stds )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 232567 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zta, 'T', 0.0_wp, stdt )
+
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zsn_tlin  (ji,jj) = zsn  (ji,jj)
+            zsa_tlin  (ji,jj) = zsa  (ji,jj)
+            zta_tlin  (ji,jj) = zta  (ji,jj)
+            zemps_tlin(ji,jj) = zemps(ji,jj) / ( z2dt * zraur )
+            zqns_tlin (ji,jj) = zqns (ji,jj)
+         END DO
+      END DO 
+
+      !--------------------------------------------------------------------
+      ! Call the tangent routine: dy = L dx
+      !--------------------------------------------------------------------
+
+      sn_tl  (:,:,1) = zsn_tlin  (:,:)
+      sa_tl  (:,:,1) = zsa_tlin  (:,:)
+      ta_tl  (:,:,1) = zta_tlin  (:,:)
+      emps_tl(:,:)   = zemps_tlin(:,:)
+      qns_tl (:,:)   = zqns_tlin (:,:)
+
+      CALL tra_sbc_tan( nit000 )
+
+      zsa_tlout(:,:) = sa_tl(:,:,1) 
+      zta_tlout(:,:) = ta_tl(:,:,1)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zsa_adin(ji,jj) = zsa_tlout(ji,jj) &
+               &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+               &               * tmask(ji,jj,1) * wesp_s(1)
+            zta_adin(ji,jj) = zta_tlout(ji,jj) &
+               &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+               &               * tmask(ji,jj,1) * wesp_t(1)
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1_1 = DOT_PRODUCT( zsa_tlout, zsa_adin )
+      zsp1_2 = DOT_PRODUCT( zta_tlout, zta_adin )
+      zsp1   = zsp1_1 + zsp1_2
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      sa_ad(:,:,1) = zsa_adin(:,:)
+      ta_ad(:,:,1) = zta_adin(:,:)
+      sn_ad(:,:,1) = 0.0_wp
+      emps_ad(:,:) = 0.0_wp
+      qns_ad(:,:)  = 0.0_wp
+
+      CALL tra_sbc_adj( nitend )
+
+      zsn_adout  (:,:) = sn_ad(:,:,1)
+      zsa_adout  (:,:) = sa_ad(:,:,1)
+      zta_adout  (:,:) = ta_ad(:,:,1)
+      zqns_adout (:,:) = qns_ad(:,: )
+      zemps_adout(:,:) = emps_ad(:,:)     
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: dx^T L^T W dy
+      !--------------------------------------------------------------------
+
+      zsp2_1 = DOT_PRODUCT( zsn_tlin  , zsn_adout   )
+      zsp2_2 = DOT_PRODUCT( zsa_tlin  , zsa_adout   )
+      zsp2_3 = DOT_PRODUCT( zta_tlin  , zta_adout   )
+      zsp2_4 = DOT_PRODUCT( zqns_tlin , zqns_adout  )
+      zsp2_5 = DOT_PRODUCT( zemps_tlin, zemps_adout )
+
+      zsp2 = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4 + zsp2_5
+
+      ! Compare the scalar products
+
+      ! 14 char:'12345678901234'
+      cl_name = 'tra_sbc_adj   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+
+
+      DEALLOCATE( & 
+         & zsn_tlin,     &
+         & zsa_tlin,     &
+         & zta_tlin,     &
+         & zsa_tlout,    &
+         & zta_tlout,    &
+         & zsn_adout,    &
+         & zsa_adout,    &
+         & zta_adout,    &
+         & zsa_adin,     &
+         & zta_adin,     &
+         & zsn,          &
+         & zsa,          &
+         & zta,          &
+         & zqns_adout,   &
+         & zqns_tlin,    &
+         & zemps_tlin,   &
+         & zemps_adout,  &
+         & zqns,         &
+         & zemps         &
+         & )
+   END SUBROUTINE tra_sbc_adj_tst
+
+#if defined key_tst_tlm
+   SUBROUTINE tra_sbc_tlm_tst ( kumadt ) 
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_adv_tlm_tst ***
+      !!
+      !! ** Purpose : Test the adjoint 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 :
+      !!        ! 09-08 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE trasbc
+      USE tamtrj              ! writing out state trajectory
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE divcur             ! horizontal divergence and relative vorticity
+      USE sshwzv             !  vertical velocity
+      USE gridrandom, ONLY: &
+        & grid_rd_sd
+      USE trj_tam
+      USE oce           , ONLY: & ! ocean dynamics and tracers variables
+        & sn, ta, sa
+      USE sbc_oce       , ONLY: & ! ocean boundary condition
+        & qns, emps
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      INTEGER :: &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zsn_tlin,     &! Tangent input : now salinity
+         & zsa_tlin,     &! Tangent input : after salinity
+         & zta_tlin,     &! Tangent input : after temperature
+         & zsa_out,      &! Tangent output: after salinity 
+         & zta_out,      &! Tangent output: after temperature 
+         & zsa_wop,      &! 
+         & zta_wop,      &
+         & z3r            ! 3D field   
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zqns_tlin,    &! Tangent input : solar radiation (w/m2)
+         & zemps_tlin,   &! Tangent input : evaporation - precipitation (free surface)
+         & z2r     
+      REAL(KIND=wp) ::   &
+         & zsp1,         & ! scalar product 
+         & zsp1_1,       & ! scalar product
+         & zsp1_2,       & ! scalar product
+         & zsp2,         & ! scalar product
+         & zsp2_1,       & ! scalar product
+         & zsp2_2,       & ! scalar product 
+         & zsp3,         & ! scalar product
+         & zsp3_1,       & ! scalar product 
+         & zsp3_2,       & ! scalar product
+         & zzsp,         & ! scalar product
+         & zzsp_1,       & ! scalar product 
+         & zzsp_2,       & ! scalar product 
+         & zraur,        &
+         & gamma,        &
+         & zgsp1,        &
+         & zgsp2,        &
+         & zgsp3,        &
+         & zgsp4,        &
+         & zgsp5,        &
+         & zgsp6,        &
+         & zgsp7 
+      CHARACTER (LEN=14)  :: cl_name
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
+      CHARACTER (LEN=90)  ::  FMT
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zscta, zscsa, &
+         & zscerrta,     &
+         & zscerrsa
+      INTEGER, DIMENSION(100):: &
+         & iiposta, iipossa,    &
+         & ijposta, ijpossa,    & 
+         & ikposta, ikpossa
+      INTEGER::          &
+         & ii,           &
+         & isamp=40,     &
+         & jsamp=40,     &
+         & ksamp=10,     &
+         & numsctlm
+     REAL(KIND=wp), DIMENSION(jpi,jpj,jpk) :: &
+         & zerrta, zerrsa 
+
+      ALLOCATE( & 
+         & zsn_tlin ( jpi,jpj,jpk),     &
+         & zta_tlin ( jpi,jpj,jpk),     &
+         & zsa_tlin ( jpi,jpj,jpk),     &
+         & zta_out  ( jpi,jpj,jpk),     &
+         & zsa_out  ( jpi,jpj,jpk),     &
+         & zta_wop  ( jpi,jpj,jpk),     &
+         & zsa_wop  ( jpi,jpj,jpk),     &
+         & z3r      ( jpi,jpj,jpk),     &
+         & zqns_tlin( jpi,jpj    ),     &
+         & zemps_tlin(jpi,jpj    ),     &
+         & z2r       (jpi,jpj    )      &
+         & )
+
+      !--------------------------------------------------------------------
+      ! Reset variables
+      !--------------------------------------------------------------------
+      zsn_tlin  ( :,:,:) = 0.0_wp
+      zsa_tlin  ( :,:,:) = 0.0_wp
+      zta_tlin  ( :,:,:) = 0.0_wp
+      zqns_tlin ( :,:  ) = 0.0_wp
+      zemps_tlin( :,:  ) = 0.0_wp
+      zta_out   ( :,:,:) = 0.0_wp
+      zsa_out   ( :,:,:) = 0.0_wp
+      zta_wop   ( :,:,:) = 0.0_wp
+      zsa_wop   ( :,:,:) = 0.0_wp
+
+      zscta(:)         = 0.0_wp
+      zscsa(:)         = 0.0_wp
+      zscerrta(:)      = 0.0_wp
+      zscerrsa(:)      = 0.0_wp
+      zerrta(:,:,:)    = 0.0_wp
+      zerrsa(:,:,:)    = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Output filename Xn=F(X0)
+      !--------------------------------------------------------------------
+!!!!      CALL tlm_namrd
+      gamma = h_ratio
+      file_wop='trj_wop_trasbc'
+      file_xdx='trj_xdx_trasbc'
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         CALL grid_rd_sd( 523432, z3r,    'T', 0.0_wp, stds  )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 232567, z3r,    'T', 0.0_wp, stdt  )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zta_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 297563, z3r,    'T', 0.0_wp, stds  )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsa_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 358606, z2r,   'T', 0.0_wp, stdqns) 
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zqns_tlin(ji,jj) = z2r(ji,jj)
+            END DO
+         END DO
+         CALL grid_rd_sd( 785483, z2r,  'T', 0.0_wp, stdemp)
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zemps_tlin(ji,jj) = z2r(ji,jj)
+            END DO
+         END DO
+      ENDIF    
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      IF ( tlm_bch /= 2 )      CALL istate_p  
+
+      ! *** initialize the reference trajectory
+      ! ------------
+      CALL  trj_rea( nit000-1, 1 )
+      CALL  trj_rea( nit000, 1 )
+
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         zsn_tlin(:,:,:) = gamma * zsn_tlin(:,:,:)
+         sn(:,:,:)       = sn(:,:,:) + zsn_tlin(:,:,:)
+
+         zta_tlin(:,:,:) = gamma * zta_tlin(:,:,:)
+         ta(:,:,:)       = ta(:,:,:) + zta_tlin(:,:,:)
+
+         zsa_tlin(:,:,:) = gamma * zsa_tlin(:,:,:)
+         sa(:,:,:)       = sa(:,:,:) + zsa_tlin(:,:,:)
+
+         zqns_tlin(:,:) = gamma * zqns_tlin(:,:)
+         qns(:,:)         = qns(:,:) + zqns_tlin(:,:)
+
+         zemps_tlin(:,:) = gamma * zemps_tlin(:,:)
+         emps(:,:)       = emps(:,:) + zemps_tlin(:,:)
+      ENDIF 
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------
+      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 ( tlm_bch == 2 ) THEN         
+         !--------------------------------------------------------------------
+         ! Initialize the tangent variables: dy^* = W dy  
+         !--------------------------------------------------------------------
+         CALL  trj_rea( nit000-1, 1 ) 
+         CALL  trj_rea( nit000, 1 ) 
+         sn_tl   (:,:,:) = zsn_tlin  (:,:,:)
+         ta_tl   (:,:,:) = zta_tlin  (:,:,:)
+         sa_tl   (:,:,:) = zsa_tlin  (:,:,:)
+         qns_tl  (:,:  ) = zqns_tlin (:,:  )
+         emps_tl (:,:  ) = zemps_tlin(:,:  )
+         !-----------------------------------------------------------------------
+         !  Initialization of the dynamics and tracer fields for the tangent
+         !----------------------------------------------------------------------- 
+         CALL tra_sbc_tan(nit000)
+
+         !--------------------------------------------------------------------
+         ! 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  )
+
+         zsp2      = zsp2_1 + zsp2_2
+         !--------------------------------------------------------------------
+         !  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 
+         ! 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 jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zta_out   (ji,jj,jk) = zta_out    (ji,jj,jk) - zta_wop  (ji,jj,jk)
+                  zta_wop   (ji,jj,jk) = zta_out    (ji,jj,jk) - ta_tl    (ji,jj,jk)
+                  IF (  ta_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrta(ji,jj,jk) = zta_out(ji,jj,jk)/ta_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposta(ii) = ji
+                      ijposta(ii) = jj
+                      ikposta(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+                         zscta (ii) =  zta_wop(ji,jj,jk)
+                         zscerrta (ii) =  ( zerrta(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         ii=0
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zsa_out   (ji,jj,jk) = zsa_out    (ji,jj,jk) - zsa_wop  (ji,jj,jk)
+                  zsa_wop   (ji,jj,jk) = zsa_out    (ji,jj,jk) - sa_tl    (ji,jj,jk)
+                  IF (  sa_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrsa(ji,jj,jk) = zsa_out(ji,jj,jk)/sa_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iipossa(ii) = ji
+                      ijpossa(ii) = jj
+                      ikpossa(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+                         zscsa (ii) =  zsa_wop(ji,jj,jk)
+                         zscerrsa (ii) =  ( zerrsa(ji,jj,jk) - 1.0_wp ) /gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+
+         zsp1_1    = DOT_PRODUCT( zta_out, zta_out )
+         zsp1_2    = DOT_PRODUCT( zsa_out, zsa_out  )
+         zsp1      = zsp1_1 + zsp1_2
+
+         zsp3_1    = DOT_PRODUCT( zta_wop, zta_wop )
+         zsp3_2    = DOT_PRODUCT( zsa_wop, zsa_wop  )
+         zsp3      = zsp3_1 + zsp3_2
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name = 'trasbc_tam:En '
+         zzsp    = SQRT(zsp3)
+         zzsp_1  = SQRT(zsp3_1)
+         zzsp_2  = SQRT(zsp3_2)
+         zgsp5   = zzsp
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp    = SQRT(zsp2)
+         zzsp_1  = SQRT(zsp2_1)
+         zzsp_2  = SQRT(zsp2_2)
+         zgsp4   = zzsp
+         cl_name = 'trasbc_tam:Ln2'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         zzsp    = SQRT(zsp1)
+         zzsp_1  = SQRT(zsp1_1)
+         zzsp_2  = SQRT(zsp1_2)
+         cl_name = 'trasbc:Mhdx-Mx'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         zgsp3   = SQRT( zsp3/zsp2 )
+         zgsp7   = zgsp3/gamma
+         zgsp1   = zzsp
+         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) 'trasbc  ', 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 = 'trasbc  '
+         IF(lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zscta(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscta     ', &
+                    & cur_loop, h_ratio, ii, iiposta(ii), ijposta(ii), zscta(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscsa(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscsa     ', &
+                    & cur_loop, h_ratio, ii, iipossa(ii), ijpossa(ii), zscsa(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrta(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrta  ', &
+                    & cur_loop, h_ratio, ii, iiposta(ii), ijposta(ii), zscerrta(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrsa(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrsa  ', &
+                    & cur_loop, h_ratio, ii, iipossa(ii), ijpossa(ii), zscerrsa(ii)
+            ENDDO
+            ! write separator
+            WRITE(numtan_sc,"(A4)") '===='
+         ENDIF
+      ENDIF
+
+      DEALLOCATE(                           &
+         & zsn_tlin, zta_tlin, zsa_tlin,    & 
+         & zqns_tlin, zemps_tlin,           & 
+         & zta_out, zsa_out,                & 
+         & zta_wop, zsa_wop,                &
+         & z3r, z2r                         &
+         & )
+   END SUBROUTINE tra_sbc_tlm_tst
+!!======================================================================
+#endif
+#endif
+END MODULE trasbc_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trazdf_exp_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trazdf_exp_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trazdf_exp_tam.F90	(revision 2578)
@@ -0,0 +1,586 @@
+MODULE trazdf_exp_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                    ***  MODULE  trazdf_exp_tam  ***
+   !! Ocean active tracers:  vertical component of the tracer mixing trend using
+   !!                        a split-explicit time-stepping
+   !!                        Tangent and Adjoint module 
+   !!==============================================================================
+   !! History of the direct module :
+   !!   OPA           !  1990-10  (B. Blanke)  Original code
+   !!            7.0  !  1991-11  (G. Madec)
+   !!                 !  1992-06  (M. Imbard)  correction on tracer trend loops
+   !!                 !  1996-01  (G. Madec)  statement function for e3
+   !!                 !  1997-05  (G. Madec)  vertical component of isopycnal
+   !!                 !  1997-07  (G. Madec)  geopotential diffusion in s-coord
+   !!                 !  2000-08  (G. Madec)  double diffusive mixing
+   !!   NEMO     1.0  !  2002-08  (G. Madec)  F90: Free form and module
+   !!             -   !  2004-08  (C. Talandier) New trends organisation
+   !!             -   !  2005-11  (G. Madec)  New organisation
+   !!            3.0  !  2008-04  (G. Madec)  leap-frog time stepping done in trazdf
+   !! History of the T&A module :
+   !!                 !  2009-01  (A. Vidard) tam of the 2008-04 version
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_zdf_exp_tan  : compute the tracer the vertical diffusion trend using a
+   !!                  split-explicit time stepping and provide the after tracer (tangent)
+   !!   tra_zdf_exp_adj  : compute the tracer the vertical diffusion trend using a
+   !!                  split-explicit time stepping and provide the after tracer (adjoint)
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1,               &
+      & jpiglo
+   USE oce_tam       , ONLY: & ! ocean dynamics and active tracers
+      & tb_tl,               &
+      & sb_tl,               &
+      & ta_tl,               &
+      & sa_tl,               &
+      & tb_ad,               &
+      & sb_ad,               &
+      & ta_ad,               &
+      & sa_ad
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & e1t,                 &
+      & e2t,                 &
+# if defined key_vvl
+      & e3t_1,               &
+# else
+#  if defined key_zco
+      & e3t_0,               &
+      & e3w_0,               &
+#  else
+      & e3t,                 &
+      & e3w,                 &
+#  endif
+# endif
+      & tmask,               &
+      & lk_vvl,              &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      & rdttra
+   USE zdf_oce       , ONLY: & ! ocean vertical physics
+      & avt,                 &
+      & nn_zdfexp
+#if defined key_zdfddm
+   USE zdfddm        , ONLY: &
+      & avs
+#endif
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              & 
+      & nitend,              & 
+      & nit000
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE paresp        , ONLY: & ! Weights for an energy-type scalar product
+      & wesp_t,              &
+      & wesp_s
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          & !
+      & stdt,                & ! stdev for s-velocity
+      & stds                   !           t-velocity
+
+#if defined key_obc
+   USE obc_oce
+#endif
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_zdf_exp_tan       ! routine called by tra_zdf_tan.F90
+   PUBLIC   tra_zdf_exp_adj       ! routine called by tra_zdf_adj.F90
+   PUBLIC   tra_zdf_exp_adj_tst   ! routine called by tst.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "zdfddm_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA  3.0 , LOCEAN-IPSL (2008) 
+   !! $Id: trazdf_exp.F90 1146 2008-06-25 11:42:56Z rblod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_zdf_exp_tan( kt, p2dt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_zdf_exp_tan  ***
+      !!                   
+      !! ** Purpose of the direct routine:
+      !!      Compute the after tracer fields due to the vertical
+      !!      tracer mixing alone, and then due to the whole tracer trend.
+      !!
+      !! ** Method of the direct routine :
+      !!               - The after tracer fields due to the vertical diffusion
+      !!      of tracers alone is given by:
+      !!                zwx = tb + p2dt difft
+      !!      where difft = dz( avt dz(tb) ) = 1/e3t dk+1( avt/e3w dk(tb) )
+      !!           (if lk_zdfddm=T use avs on salinity instead of avt)
+      !!      difft is evaluated with an Euler split-explit scheme using a
+      !!      no flux boundary condition at both surface and bottomi boundaries.
+      !!      (N.B. bottom condition is applied through the masked field avt).
+      !!              - the after tracer fields due to the whole trend is 
+      !!      obtained in leap-frog environment by :
+      !!          ta = zwx + p2dt ta
+      !!              - in case of variable level thickness (lk_vvl=T) the 
+      !!     the leap-frog is applied on thickness weighted tracer. That is:
+      !!          ta = [ tb*e3tb + e3tn*( zwx - tb + p2dt ta ) ] / e3tn
+      !!
+      !! ** Action : - after tracer fields (ta,sa) 
+      !!---------------------------------------------------------------------
+      INTEGER , INTENT(in)                 ::   kt     ! ocean time-step index
+      REAL(wp), INTENT(in), DIMENSION(jpk) ::   p2dt   ! vertical profile of tracer time-step
+      !!
+      INTEGER  ::   ji, jj, jk, jl            ! dummy loop indices
+      REAL(wp) ::   zlavmr, zave3r, ze3tr     ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwxtl, zwytl, zwztl, zwwtl   ! 3D workspace
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_zdf_exp_tan : explicit vertical mixing'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
+      ENDIF
+
+      ! Initializations
+      ! ---------------
+      zlavmr = 1. / float( nn_zdfexp )                           ! Local constant
+      !
+      zwytl(:,:, 1 ) = 0.0_wp        ;   zwwtl(:,:, 1 ) = 0.0_wp        ! surface boundary conditions: no flux
+      zwytl(:,:,jpk) = 0.0_wp        ;   zwwtl(:,:,jpk) = 0.0_wp        ! bottom  boundary conditions: no flux
+      !
+      zwxtl(:,:,:)   = tb_tl(:,:,:)   ;   zwztl(:,:,:)   = sb_tl(:,:,:)   ! zwx and zwz arrays set to before tracer values
+
+      ! Split-explicit loop  (after tracer due to the vertical diffusion alone)
+      ! -------------------
+      !
+      DO jl = 1, nn_zdfexp
+         !                     ! first vertical derivative
+         DO jk = 2, jpk
+            DO jj = 2, jpjm1 
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zave3r = 1.e0 / fse3w_n(ji,jj,jk) 
+                  zwytl(ji,jj,jk) =   avt(ji,jj,jk) * ( zwxtl(ji,jj,jk-1) - zwxtl(ji,jj,jk) ) * zave3r
+                  zwwtl(ji,jj,jk) = fsavs(ji,jj,jk) * ( zwztl(ji,jj,jk-1) - zwztl(ji,jj,jk) ) * zave3r
+               END DO
+            END DO
+         END DO
+         !
+         DO jk = 1, jpkm1      ! second vertical derivative   ==> tracer at kt+l*2*rdt/n_zdfexp
+            DO jj = 2, jpjm1 
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ze3tr = zlavmr / fse3t_n(ji,jj,jk)
+                  zwxtl(ji,jj,jk) = zwxtl(ji,jj,jk) + p2dt(jk) * ( zwytl(ji,jj,jk) - zwytl(ji,jj,jk+1) ) * ze3tr
+                  zwztl(ji,jj,jk) = zwztl(ji,jj,jk) + p2dt(jk) * ( zwwtl(ji,jj,jk) - zwwtl(ji,jj,jk+1) ) * ze3tr
+               END DO
+            END DO
+         END DO
+         !
+      END DO
+
+      ! After tracer due to all trends
+      ! ------------------------------
+      IF( lk_vvl ) THEN          ! variable level thickness : leap-frog on tracer*e3t
+         IF(lwp) WRITE(numout,*) "key_vvl net available in tangent yet"
+         CALL abort
+      ELSE                       ! fixed level thickness : leap-frog on tracers
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1 
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ta_tl(ji,jj,jk) = ( zwxtl(ji,jj,jk) + p2dt(jk) * ta_tl(ji,jj,jk) ) *tmask(ji,jj,jk)
+                  sa_tl(ji,jj,jk) = ( zwztl(ji,jj,jk) + p2dt(jk) * sa_tl(ji,jj,jk) ) *tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      ENDIF
+      !
+   END SUBROUTINE tra_zdf_exp_tan
+
+   SUBROUTINE tra_zdf_exp_adj( kt, p2dt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_zdf_exp_adj  ***
+      !!                   
+      !! ** Purpose of the direct routine:
+      !!      Compute the after tracer fields due to the vertical
+      !!      tracer mixing alone, and then due to the whole tracer trend.
+      !!
+      !! ** Method of the direct routine :
+      !!               - The after tracer fields due to the vertical diffusion
+      !!      of tracers alone is given by:
+      !!                zwx = tb + p2dt difft
+      !!      where difft = dz( avt dz(tb) ) = 1/e3t dk+1( avt/e3w dk(tb) )
+      !!           (if lk_zdfddm=T use avs on salinity instead of avt)
+      !!      difft is evaluated with an Euler split-explit scheme using a
+      !!      no flux boundary condition at both surface and bottomi boundaries.
+      !!      (N.B. bottom condition is applied through the masked field avt).
+      !!              - the after tracer fields due to the whole trend is 
+      !!      obtained in leap-frog environment by :
+      !!          ta = zwx + p2dt ta
+      !!              - in case of variable level thickness (lk_vvl=T) the 
+      !!     the leap-frog is applied on thickness weighted tracer. That is:
+      !!          ta = [ tb*e3tb + e3tn*( zwx - tb + p2dt ta ) ] / e3tn
+      !!
+      !! ** Action : - after tracer fields (ta,sa) 
+      !!---------------------------------------------------------------------
+      INTEGER , INTENT(in)                 ::   kt     ! ocean time-step index
+      REAL(wp), INTENT(in), DIMENSION(jpk) ::   p2dt   ! vertical profile of tracer time-step
+      !!
+      INTEGER  ::   ji, jj, jk, jl            ! dummy loop indices
+      REAL(wp) ::   zlavmr, zave3r, ze3tr     ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwxad, zwyad, zwzad, zwwad   ! 3D workspace
+      !!---------------------------------------------------------------------
+
+      IF( kt == nitend ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_zdf_exp_adj : explicit vertical mixing'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
+      ENDIF
+
+      ! Initializations
+      ! ---------------
+      zlavmr = 1. / float( nn_zdfexp )                           ! Local constant
+      !
+      zwwad(:,:,:) = 0.0_wp       ;   zwxad(:,:,:) = 0.0_wp 
+      zwyad(:,:,:) = 0.0_wp       ;   zwzad(:,:,:) = 0.0_wp
+      ! After tracer due to all trends
+      ! ------------------------------
+      IF( lk_vvl ) THEN          ! variable level thickness : leap-frog on tracer*e3t
+         IF(lwp) WRITE(numout,*) "key_vvl net available in adjoint yet"
+         CALL abort
+      ELSE                       ! fixed level thickness : leap-frog on tracers
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1 
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zwxad(ji,jj,jk) = zwxad(ji,jj,jk) + ta_ad(ji,jj,jk) * tmask(ji,jj,jk)
+                  ta_ad(ji,jj,jk) = p2dt(jk) * ta_ad(ji,jj,jk) * tmask(ji,jj,jk)
+                  zwzad(ji,jj,jk) = zwzad(ji,jj,jk) + sa_ad(ji,jj,jk) * tmask(ji,jj,jk)
+                  sa_ad(ji,jj,jk) = p2dt(jk) * sa_ad(ji,jj,jk) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      ENDIF
+      !
+
+      ! Split-explicit loop  (after tracer due to the vertical diffusion alone)
+      ! -------------------
+      !
+      DO jl = 1, nn_zdfexp
+         DO jk =  jpkm1, 1, -1      ! second vertical derivative   ==> tracer at kt+l*2*rdt/n_zdfexp
+            DO jj = 2, jpjm1 
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ze3tr = zlavmr / fse3t_n(ji,jj,jk)
+                  zwyad(ji,jj,jk  ) = zwyad(ji,jj,jk  ) + p2dt(jk) * zwxad(ji,jj,jk) * ze3tr
+                  zwyad(ji,jj,jk+1) = zwyad(ji,jj,jk+1) - p2dt(jk) * zwxad(ji,jj,jk) * ze3tr
+                  zwwad(ji,jj,jk  ) = zwwad(ji,jj,jk  ) + p2dt(jk) * zwzad(ji,jj,jk) * ze3tr
+                  zwwad(ji,jj,jk+1) = zwwad(ji,jj,jk+1) - p2dt(jk) * zwzad(ji,jj,jk) * ze3tr
+               END DO
+            END DO
+         END DO
+         !                     ! first vertical derivative
+         DO jk = jpk, 2, -1
+            DO jj = 2, jpjm1 
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zave3r = 1.e0 / fse3w_n(ji,jj,jk) 
+                  zwxad(ji,jj,jk-1) = zwxad(ji,jj,jk-1) + avt(ji,jj,jk) * zwyad(ji,jj,jk) * zave3r
+                  zwxad(ji,jj,jk  ) = zwxad(ji,jj,jk  ) - avt(ji,jj,jk) * zwyad(ji,jj,jk) * zave3r
+                  zwyad(ji,jj,jk  ) = 0.0_wp
+                  zwzad(ji,jj,jk-1) = zwzad(ji,jj,jk-1) + fsavs(ji,jj,jk) * zwwad(ji,jj,jk) * zave3r
+                  zwzad(ji,jj,jk  ) = zwzad(ji,jj,jk  ) - fsavs(ji,jj,jk) * zwwad(ji,jj,jk) * zave3r
+                  zwwad(ji,jj,jk  ) = 0.0_wp
+               END DO
+            END DO
+         END DO
+         !
+         !
+      END DO
+
+      tb_ad(:,:,:) = tb_ad(:,:,:) + zwxad(:,:,:) 
+      sb_ad(:,:,:) = sb_ad(:,:,:) + zwzad(:,:,:)
+
+   END SUBROUTINE tra_zdf_exp_adj
+
+   SUBROUTINE tra_zdf_exp_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tra_zdf_exp_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) ::   &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2            ! scalar product involving the adjoint routine
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zta_tlin ,     & ! Tangent input
+         & ztb_tlin ,     & ! Tangent input
+#if defined key_obc
+         & ztb_tlout, zsb_tlout, ztb_adin, zsb_adin,  & 
+#endif
+         & zsa_tlin ,     & ! Tangent input
+         & zsb_tlin ,     & ! Tangent input
+         & zta_tlout,     & ! Tangent output
+         & zsa_tlout,     & ! Tangent output
+         & zta_adin ,     & ! Adjoint input
+         & zsa_adin ,     & ! Adjoint input
+         & zta_adout,     & ! Adjoint output
+         & ztb_adout,     & ! Adjoint output
+         & zsa_adout,     & ! Adjoint output
+         & zsb_adout,     & ! Adjoint output
+         & zr             ! 3D random field 
+      CHARACTER(LEN=14) :: cl_name
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zta_tlin( jpi,jpj,jpk),     &
+         & zsa_tlin( jpi,jpj,jpk),     &
+         & ztb_tlin( jpi,jpj,jpk),     &
+         & zsb_tlin( jpi,jpj,jpk),     &
+         & zta_tlout(jpi,jpj,jpk),     &
+         & zsa_tlout(jpi,jpj,jpk),     &
+         & zta_adin( jpi,jpj,jpk),     &
+         & zsa_adin( jpi,jpj,jpk),     &
+         & zta_adout(jpi,jpj,jpk),     &
+         & zsa_adout(jpi,jpj,jpk),     &
+         & ztb_adout(jpi,jpj,jpk),     &
+         & zsb_adout(jpi,jpj,jpk),     &
+         & zr(       jpi,jpj,jpk)      &
+         & )
+
+#if defined key_obc
+      ALLOCATE( ztb_tlout(jpi,jpj,jpk),  zsb_tlout(jpi,jpj,jpk),     &
+           &    ztb_adin (jpi,jpj,jpk),  zsb_adin (jpi,jpj,jpk) )
+#endif
+
+      !==================================================================
+      ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and 
+      !    dy = ( hdivb_tl, hdivn_tl )
+      !==================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+          zta_tlin( :,:,:) = 0.0_wp
+          ztb_tlin( :,:,:) = 0.0_wp
+          zsa_tlin( :,:,:) = 0.0_wp
+          zsb_tlin( :,:,:) = 0.0_wp
+          zta_tlout(:,:,:) = 0.0_wp
+          zsa_tlout(:,:,:) = 0.0_wp
+          zta_adin( :,:,:) = 0.0_wp
+          zsa_adin( :,:,:) = 0.0_wp
+          zta_adout(:,:,:) = 0.0_wp
+          zsa_adout(:,:,:) = 0.0_wp
+          ztb_adout(:,:,:) = 0.0_wp
+          zsb_adout(:,:,:) = 0.0_wp
+          zr(       :,:,:) = 0.0_wp
+
+          ta_tl(:,:,:)     = 0.0_wp
+          sa_tl(:,:,:)     = 0.0_wp
+          tb_tl(:,:,:)     = 0.0_wp
+          sb_tl(:,:,:)     = 0.0_wp
+          ta_ad(:,:,:)     = 0.0_wp
+          sa_ad(:,:,:)     = 0.0_wp
+          tb_ad(:,:,:)     = 0.0_wp
+          sb_ad(:,:,:)     = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zta_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+           END DO
+        END DO
+     END DO
+
+     DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 352791 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              ztb_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+           END DO
+        END DO
+     END DO
+
+     DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 142746 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stds )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsa_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+           END DO
+        END DO
+     END DO
+     DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 214934 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stds )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsb_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+           END DO
+        END DO
+     END DO
+      ta_tl(:,:,:) = zta_tlin(:,:,:)
+      sa_tl(:,:,:) = zsa_tlin(:,:,:)
+      tb_tl(:,:,:) = ztb_tlin(:,:,:)
+      sb_tl(:,:,:) = zsb_tlin(:,:,:)
+      CALL tra_zdf_exp_tan ( nit000, rdttra )
+      zta_tlout(:,:,:) = ta_tl(:,:,:)
+      zsa_tlout(:,:,:) = sa_tl(:,:,:)
+#if defined key_obc
+      ztb_tlout(:,:,:) = tb_tl(:,:,:)
+      zsb_tlout(:,:,:) = sb_tl(:,:,:)     
+#endif
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zta_adin(ji,jj,jk) = zta_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_t(jk)
+              zsa_adin(ji,jj,jk) = zsa_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_s(jk)
+#if defined key_obc
+              ztb_adin(ji,jj,jk) = ztb_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_t(jk)
+              zsb_adin(ji,jj,jk) = zsb_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_s(jk)
+            
+#endif
+            END DO
+         END DO
+      END DO
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1 = DOT_PRODUCT( zta_tlout, zta_adin ) &
+         & + DOT_PRODUCT( zsa_tlout, zsa_adin )
+
+#if defined key_obc
+      zsp1 = zsp1 + DOT_PRODUCT( ztb_tlout, ztb_adin ) &
+           &      + DOT_PRODUCT( zsb_tlout, zsb_adin )
+#endif
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      ta_ad(:,:,:) = zta_adin(:,:,:)
+      sa_ad(:,:,:) = zsa_adin(:,:,:)
+
+#if defined key_obc
+      tb_ad(:,:,:) = ztb_adin(:,:,:)
+      sb_ad(:,:,:) = zsb_adin(:,:,:)
+#endif
+      
+      CALL tra_zdf_exp_adj ( nit000, rdttra )
+      
+      zta_adout(:,:,:) = ta_ad(:,:,:)
+      zsa_adout(:,:,:) = sa_ad(:,:,:)
+      ztb_adout(:,:,:) = tb_ad(:,:,:)
+      zsb_adout(:,:,:) = sb_ad(:,:,:)
+
+      zsp2 = DOT_PRODUCT( zta_tlin, zta_adout ) &
+         & + DOT_PRODUCT( zsa_tlin, zsa_adout ) &
+         & + DOT_PRODUCT( ztb_tlin, ztb_adout ) &
+         & + DOT_PRODUCT( zsb_tlin, zsb_adout ) 
+
+      ! 14 char:'12345678901234'
+      cl_name = 'trazdf_exp_adj'
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      DEALLOCATE(   &
+         & zta_tlin,  &
+         & ztb_tlin,  &
+         & zsa_tlin,  &
+         & zsb_tlin,  &
+         & zta_tlout, &
+         & zsa_tlout, &
+         & zta_adin,  &
+         & zsa_adin,  &
+         & zta_adout, &
+         & ztb_adout, &
+         & zsa_adout, &
+         & zsb_adout, &
+         & zr       &
+         & )
+
+
+
+   END SUBROUTINE tra_zdf_exp_adj_tst
+
+   !!==============================================================================
+#endif
+END MODULE trazdf_exp_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trazdf_imp_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trazdf_imp_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trazdf_imp_tam.F90	(revision 2578)
@@ -0,0 +1,1392 @@
+MODULE trazdf_imp_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                 ***  MODULE  trazdf_imp_tam  ***
+   !! Ocean active tracers:  vertical component of the tracer mixing trend
+   !!                        Tangent and Adjoint Module
+   !!==============================================================================
+   !! History of the direct module:  
+   !!            OPA  !  1990-10  (B. Blanke)  Original code
+   !!            7.0  !  1991-11  (G. Madec)
+   !!                 !  1992-06  (M. Imbard) correction on tracer trend loops
+   !!                 !  1996-01  (G. Madec) statement function for e3
+   !!                 !  1997-05  (G. Madec) vertical component of isopycnal
+   !!                 !  1997-07  (G. Madec) geopotential diffusion in s-coord
+   !!                 !  2000-08  (G. Madec) double diffusive mixing
+   !!   NEMO     1.0  !  2002-08  (G. Madec) F90: Free form and module
+   !!            2.0  !  2006-11  (G. Madec) New step reorganisation
+   !!            3.2  !  2009-03  (G. Madec)  heat and salt content trends
+
+   !! History of the T&A module:
+   !!  NEMO      3.0  ! 2009-01 (A. Vidard) tam of the 06-11 version
+   !!            3.2  ! 2010-04 (F. Vigilant) 3.2 version
+   !!----------------------------------------------------------------------
+   !!   tra_zdf_imp_tan : Update the tracer trend with the diagonal vertical  
+   !!                 part of the mixing tensor (tangent).
+   !!   tra_zdf_imp_adj : Update the tracer trend with the diagonal vertical  
+   !!                 part of the mixing tensor (adjoint).
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 &
+      & jpim1,               &
+      & jpjm1,               &
+      & jpkm1,               &
+      & jpiglo
+   USE oce_tam       , ONLY: & ! ocean dynamics and active tracers
+      & tb_tl,               &
+      & sb_tl,               &
+      & ta_tl,               &
+      & sa_tl,               &
+      & tb_ad,               &
+      & sb_ad,               &
+      & ta_ad,               &
+      & sa_ad
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & e1t,                 &
+      & e2t,                 &
+# if defined key_vvl
+      & e3t_1,               &
+# else
+#  if defined key_zco
+      & e3t_0,               &
+      & e3w_0,               &
+#  else
+      & e3t,                 &
+      & e3w,                 &
+#  endif
+# endif
+      & tmask,               &
+      & lk_vvl,              &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      & rdttra
+   USE oce           , ONLY: & ! ocean dynamics and tracers variables
+      & l_traldf_rot
+   USE zdf_oce       , ONLY: & ! ocean vertical physics
+      & avt
+   USE ldftra_oce    , ONLY: & ! ocean active tracers: lateral physics
+      & ahtw,                &
+      & aht0
+   USE ldfslp        , ONLY: & ! lateral physics: slope of diffusion
+      & wslpi,               & !: i_slope at W-points
+      & wslpj                  !: j-slope at W-points
+#if defined key_zdfddm
+   USE zdfddm        , ONLY: &
+      & avs
+#endif
+   USE traldf_tam
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,          &
+      & numout,       & 
+      & nitend,       & 
+      & nit000
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          & !
+      & prntst_tlm,          & !
+      & stdt,                & ! stdev for u-velocity
+      & stds                   !           v-velocity
+   USE paresp        , ONLY: & ! Weights for an energy-type scalar product
+      & wesp_t,              &
+      & wesp_s
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC tra_zdf_imp_tan       !  routine called by tra_zdf_tan.F90
+   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
+#  include "domzgr_substitute.h90"
+#  include "ldftra_substitute.h90"
+#  include "zdfddm_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Id: trazdf_imp.F90 1156 2008-06-26 16:06:45Z rblod $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+   
+   SUBROUTINE tra_zdf_imp_tan( kt, p2dt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_zdf_imp_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!     Compute the trend due to the vertical tracer diffusion
+      !!     including the vertical component of lateral mixing (only for 2nd
+      !!     order operator, for fourth order it is already computed and add
+      !!     to the general trend in traldf.F) and add it to the general trend
+      !!     of the tracer equations.
+      !!
+      !! ** Method of the direct routine :
+      !!      The vertical component of the lateral diffusive trends
+      !!      is provided by a 2nd order operator rotated along neutral or geo-
+      !!      potential surfaces to which an eddy induced advection can be 
+      !!      added. It is computed using before fields (forward in time) and 
+      !!      isopycnal or geopotential slopes computed in routine ldfslp.
+      !!
+      !!      Second part: vertical trend associated with the vertical physics
+      !!      ===========  (including the vertical flux proportional to dk[t]
+      !!                  associated with the lateral mixing, through the
+      !!                  update of avt)
+      !!      The vertical diffusion of tracers (t & s) is given by:
+      !!             difft = dz( avt dz(t) ) = 1/e3t dk+1( avt/e3w dk(t) )
+      !!      It is computed using a backward time scheme (t=ta).
+      !!      Surface and bottom boundary conditions: no diffusive flux on
+      !!      both tracers (bottom, applied through the masked field avt).
+      !!      Add this trend to the general trend ta,sa :
+      !!         ta = ta + dz( avt dz(t) )
+      !!         (sa = sa + dz( avs dz(t) ) if lk_zdfddm=T )
+      !!
+      !!      Third part: recover avt resulting from the vertical physics
+      !!      ==========  alone, for further diagnostics (for example to
+      !!                  compute the turbocline depth in zdfmxl.F90).
+      !!         avt = zavt
+      !!         (avs = zavs if lk_zdfddm=T )
+      !!
+      !! ** Remarks on the tangent routine : - key_vvl is not available in tangent yet. 
+      !!    Once it will be this routine wil need to be rewritten
+      !!                                     - simplified version, slopes (wslp[ij])
+      !!     assumed to be constant (read from the trajectory). same for av[ts]
+      !!
+      !!---------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
+      REAL(wp), DIMENSION(jpk), INTENT( in ) ::   &
+         p2dt                                ! vertical profile of tracer time-step
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk               ! dummy loop indices
+      REAL(wp) ::   zavi, zrhstl, znvvl,   & ! temporary scalars
+         ze3tb, ze3tn, ze3ta                 ! variable vertical scale factors
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zwi, zwt, zavsi, zwd, zws           ! workspace arrays
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) 'tra_zdf_imp : implicit vertical mixing'
+         IF(lwp)WRITE(numout,*) '~~~~~~~~~~~ '
+         zavi = 0._wp      ! avoid warning at compilation phase when lk_ldfslp=F
+      ENDIF
+
+      ! I. Local initialization
+      ! -----------------------
+      zwd  (1,:, : ) = 0._wp     ;     zwd  (jpi,:,:) = 0._wp
+      zws  (1,:, : ) = 0._wp     ;     zws  (jpi,:,:) = 0._wp
+      zwi  (1,:, : ) = 0._wp     ;     zwi  (jpi,:,:) = 0._wp
+      zwt  (1,:, : ) = 0._wp     ;     zwt  (jpi,:,:) = 0._wp
+      zavsi(1,:, : ) = 0._wp     ;     zavsi(jpi,:,:) = 0._wp
+      zwt  (:,:,jpk) = 0._wp     ;     zwt  ( : ,:,1) = 0._wp
+      zavsi(:,:,jpk) = 0._wp     ;     zavsi( : ,:,1) = 0._wp
+
+      ! I.1 Variable volume : to take into account vertical variable vertical scale factors
+      ! -------------------
+      ! ... not available  in tangent yet
+      ! II. Vertical trend associated with the vertical physics
+      ! =======================================================
+      !     (including the vertical flux proportional to dk[t] associated
+      !      with the lateral mixing, through the avt update)
+      !     dk[ avt dk[ (t,s) ] ] diffusive trends
+
+      ! II.0 Matrix construction
+      ! ------------------------
+#if defined key_ldfslp
+      ! update and save of avt (and avs if double diffusive mixing)
+      IF( l_traldf_rot ) THEN
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zavi = fsahtw(ji,jj,jk)                       &   ! vertical mixing coef. due to lateral mixing
+                     & * (  wslpi(ji,jj,jk) * wslpi(ji,jj,jk)   &
+                     &    + wslpj(ji,jj,jk) * wslpj(ji,jj,jk)  )
+                  zwt(ji,jj,jk) = avt(ji,jj,jk) + zavi              ! zwt=avt+zavi (total vertical mixing coef. on temperature)
+# if defined key_zdfddm
+                  zavsi(ji,jj,jk) = fsavs(ji,jj,jk) + zavi          ! dd mixing: zavsi = total vertical mixing coef. on salinity
+# endif
+               END DO
+            END DO
+         END DO
+      ELSE                         ! no rotation but key_ldfslp defined
+         zwt  (:,:,:) = avt(:,:,:)
+# if defined key_zdfddm
+         zavsi(:,:,:) = avs(:,:,:)       ! avs /= avt (double diffusion mixing)
+# endif
+      ENDIF   
+#else
+      ! No isopycnal diffusion
+      zwt(:,:,:) = avt(:,:,:)
+# if defined key_zdfddm
+      zavsi(:,:,:) = avs(:,:,:)
+# endif
+
+#endif
+
+      ! Diagonal, inferior, superior  (including the bottom boundary condition via avt masked)
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ze3ta = 1._wp                                ! after scale factor at T-point
+               ze3tn = fse3t(ji,jj,jk)                      ! now   scale factor at T-point
+               zwi(ji,jj,jk) = - p2dt(jk) * zwt(ji,jj,jk  ) / ( ze3tn * fse3w(ji,jj,jk  ) )
+               zws(ji,jj,jk) = - p2dt(jk) * zwt(ji,jj,jk+1) / ( ze3tn * fse3w(ji,jj,jk+1) )
+               zwd(ji,jj,jk) = ze3ta - zwi(ji,jj,jk) - zws(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Surface boudary conditions
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ze3ta = 1._wp         ! after scale factor at T-point
+            zwi(ji,jj,1) = 0._wp
+            zwd(ji,jj,1) = ze3ta - zws(ji,jj,1)
+         END DO
+      END DO
+
+      ! II.1. Vertical diffusion on t
+      ! ---------------------------
+
+      !! Matrix inversion from the first level
+      !!----------------------------------------------------------------------
+      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+      !
+      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+      !        (        ...               )( ...  ) ( ...  )
+      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+      !
+      !   m is decomposed in the product of an upper and lower triangular matrix
+      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+      !   The second member is in 2d array zwy
+      !   The solution is in 2d array zwx
+      !   The 3d arry zwt is a work space array
+      !   zwy is used and then used as a work space array : its value is modified!
+
+      ! first recurrence:   Tk = Dk - Ik Sk-1 / Tk-1   (increasing k)
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            zwt(ji,jj,1) = zwd(ji,jj,1)
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zwt(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1)  /zwt(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! second recurrence:    Zk = Yk - Ik / Tk-1  Zk-1
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            ze3tb = 1._wp
+            ze3tn = 1._wp
+            ta_tl(ji,jj,1) = ze3tb * tb_tl(ji,jj,1) + p2dt(1) * ze3tn * ta_tl(ji,jj,1)
+         END DO
+      END DO
+       
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               ze3tb = 1._wp
+               ze3tn = 1._wp
+               zrhstl = ze3tb * tb_tl(ji,jj,jk) + p2dt(jk) * ze3tn * ta_tl(ji,jj,jk)   ! zrhs=right hand side 
+               ta_tl(ji,jj,jk) = zrhstl - zwi(ji,jj,jk) / zwt(ji,jj,jk-1) *ta_tl(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! third recurrence: Xk = (Zk - Sk Xk+1 ) / Tk
+      ! Save the masked temperature after in ta
+      ! (c a u t i o n:  temperature not its trend, Leap-frog scheme done it will not be done in tranxt)
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            ta_tl(ji,jj,jpkm1) = ta_tl(ji,jj,jpkm1) / zwt(ji,jj,jpkm1) * tmask(ji,jj,jpkm1)
+         END DO
+      END DO
+      DO jk = jpk-2, 1, -1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               ta_tl(ji,jj,jk) = ( ta_tl(ji,jj,jk) - zws(ji,jj,jk) * ta_tl(ji,jj,jk+1) ) / zwt(ji,jj,jk) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! II.2 Vertical diffusion on salinity
+      ! -----------------------------------
+
+#if defined key_zdfddm
+      ! Rebuild the Matrix as avt /= avs
+
+      ! Diagonal, inferior, superior  (including the bottom boundary condition via avs masked)
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ze3ta = 1._wp         ! after scale factor at T-point
+               ze3tn = fse3t(ji,jj,jk)        ! now   scale factor at T-point
+               zwi(ji,jj,jk) = - p2dt(jk) * zavsi(ji,jj,jk  ) / ( ze3tn * fse3w(ji,jj,jk  ) )
+               zws(ji,jj,jk) = - p2dt(jk) * zavsi(ji,jj,jk+1) / ( ze3tn * fse3w(ji,jj,jk+1) )
+               zwd(ji,jj,jk) = ze3ta - zwi(ji,jj,jk) - zws(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Surface boudary conditions
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ze3ta = 1._wp         ! after scale factor at T-point
+            zwi(ji,jj,1) = 0._wp
+            zwd(ji,jj,1) = ze3ta - zws(ji,jj,1)
+         END DO
+      END DO
+#endif
+
+
+      !! Matrix inversion from the first level
+      !!----------------------------------------------------------------------
+      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+      !
+      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+      !        (        ...               )( ...  ) ( ...  )
+      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+      !
+      !   m is decomposed in the product of an upper and lower triangular
+      !   matrix
+      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+      !   The second member is in 2d array zwy
+      !   The solution is in 2d array zwx
+      !   The 3d arry zwt is a work space array
+      !   zwy is used and then used as a work space array : its value is modified!
+
+      ! first recurrence:   Tk = Dk - Ik Sk-1 / Tk-1   (increasing k)
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            zwt(ji,jj,1) = zwd(ji,jj,1)
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zwt(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1)  /zwt(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! second recurrence:    Zk = Yk - Ik / Tk-1  Zk-1
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            ze3tb = 1.0_wp                   ! before scale factor at T-point
+            ze3tn = 1.0_wp                   ! now    scale factor at T-point
+            sa_tl(ji,jj,1) = ze3tb * sb_tl(ji,jj,1) + p2dt(1) * ze3tn * sa_tl(ji,jj,1)
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               ze3tb = 1.0_wp                  ! before scale factor at T-point
+               ze3tn = 1.0_wp                  ! now    scale factor at T-point
+               zrhstl = ze3tb * sb_tl(ji,jj,jk) + p2dt(jk) * ze3tn * sa_tl(ji,jj,jk)     ! zrhs=right hand side
+               sa_tl(ji,jj,jk) = zrhstl - zwi(ji,jj,jk) / zwt(ji,jj,jk-1) *sa_tl(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! third recurrence: Xk = (Zk - Sk Xk+1 ) / Tk
+      ! Save the masked temperature after in ta
+      ! (c a u t i o n:  temperature not its trend, Leap-frog scheme done it will not be done in tranxt)
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            sa_tl(ji,jj,jpkm1) = sa_tl(ji,jj,jpkm1) / zwt(ji,jj,jpkm1) * tmask(ji,jj,jpkm1)
+         END DO
+      END DO
+      DO jk = jpk-2, 1, -1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               sa_tl(ji,jj,jk) = ( sa_tl(ji,jj,jk) - zws(ji,jj,jk) * sa_tl(ji,jj,jk+1) ) / zwt(ji,jj,jk) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE tra_zdf_imp_tan
+   SUBROUTINE tra_zdf_imp_adj( kt, p2dt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_zdf_imp_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!     Compute the trend due to the vertical tracer diffusion
+      !!     including the vertical component of lateral mixing (only for 2nd
+      !!     order operator, for fourth order it is already computed and add
+      !!     to the general trend in traldf.F) and add it to the general trend
+      !!     of the tracer equations.
+      !!
+      !! ** Method of the direct routine :
+      !!      The vertical component of the lateral diffusive trends
+      !!      is provided by a 2nd order operator rotated along neutral or geo-
+      !!      potential surfaces to which an eddy induced advection can be 
+      !!      added. It is computed using before fields (forward in time) and 
+      !!      isopycnal or geopotential slopes computed in routine ldfslp.
+      !!
+      !!      Second part: vertical trend associated with the vertical physics
+      !!      ===========  (including the vertical flux proportional to dk[t]
+      !!                  associated with the lateral mixing, through the
+      !!                  update of avt)
+      !!      The vertical diffusion of tracers (t & s) is given by:
+      !!             difft = dz( avt dz(t) ) = 1/e3t dk+1( avt/e3w dk(t) )
+      !!      It is computed using a backward time scheme (t=ta).
+      !!      Surface and bottom boundary conditions: no diffusive flux on
+      !!      both tracers (bottom, applied through the masked field avt).
+      !!      Add this trend to the general trend ta,sa :
+      !!         ta = ta + dz( avt dz(t) )
+      !!         (sa = sa + dz( avs dz(t) ) if lk_zdfddm=T )
+      !!
+      !!      Third part: recover avt resulting from the vertical physics
+      !!      ==========  alone, for further diagnostics (for example to
+      !!                  compute the turbocline depth in zdfmxl.F90).
+      !!         avt = zavt
+      !!         (avs = zavs if lk_zdfddm=T )
+      !!
+      !! ** Remarks on the adjoint routine : - key_vvl is not available in adjoint yet. 
+      !!    Once it will be this routine wil need to be rewritten
+      !!                                     - simplified version, slopes (wslp[ij])
+      !!     assumed to be constant (read from the trajectory). same for av[ts]
+      !!
+      !!---------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
+      REAL(wp), DIMENSION(jpk), INTENT( in ) ::   &
+         p2dt                                ! vertical profile of tracer time-step
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk               ! dummy loop indices
+      REAL(wp) ::   zavi, zrhsad, znvvl,   & ! temporary scalars
+         ze3tb, ze3tn, ze3ta, zvsfvvl        ! variable vertical scale factors
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zwi, zwt, zavsi, zwd, zws           ! workspace arrays
+      !!---------------------------------------------------------------------
+
+      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
+
+      ! I. Local initialization
+      ! -----------------------
+      zrhsad         = 0.0_wp
+      zwd  (1,:, : ) = 0._wp     ;     zwd  (jpi,:,:) = 0._wp
+      zws  (1,:, : ) = 0._wp     ;     zws  (jpi,:,:) = 0._wp
+      zwi  (1,:, : ) = 0._wp     ;     zwi  (jpi,:,:) = 0._wp
+      zwt  (1,:, : ) = 0._wp     ;     zwt  (jpi,:,:) = 0._wp
+      zavsi(1,:, : ) = 0._wp     ;     zavsi(jpi,:,:) = 0._wp
+      zwt  (:,:,jpk) = 0._wp     ;     zwt  ( : ,:,1) = 0._wp
+      zavsi(:,:,jpk) = 0._wp     ;     zavsi( : ,:,1) = 0._wp
+
+      ! I.1 Variable volume : to take into account vertical variable vertical scale factors
+      ! -------------------
+      ! ... not available  in adjoint yet
+      ! II. Vertical trend associated with the vertical physics
+      ! =======================================================
+      !     (including the vertical flux proportional to dk[t] associated
+      !      with the lateral mixing, through the avt update)
+      !     dk[ avt dk[ (t,s) ] ] diffusive trends
+
+
+      ! II.0 Matrix construction
+      ! ------------------------
+
+#if defined key_ldfslp
+      ! update and save of avt (and avs if double diffusive mixing)
+      IF( l_traldf_rot ) THEN
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zavi = fsahtw(ji,jj,jk)                       &   ! vertical mixing coef. due to lateral mixing
+                     & * (  wslpi(ji,jj,jk) * wslpi(ji,jj,jk)   &
+                     &    + wslpj(ji,jj,jk) * wslpj(ji,jj,jk)  )
+                  zwt(ji,jj,jk) = avt(ji,jj,jk) + zavi              ! zwt=avt+zavi (total vertical mixing coef. on temperature)
+# if defined key_zdfddm
+                  zavsi(ji,jj,jk) = fsavs(ji,jj,jk) + zavi          ! dd mixing: zavsi = total vertical mixing coef. on salinity
+# endif
+               END DO
+            END DO
+         END DO
+      ELSE                         ! no rotation but key_ldfslp defined
+         zwt  (:,:,:) = avt(:,:,:)
+# if defined key_zdfddm
+         zavsi(:,:,:) = avs(:,:,:)       ! avs /= avt (double diffusion mixing)
+# endif
+      ENDIF   
+#else
+      ! No isopycnal diffusion
+      zwt(:,:,:) = avt(:,:,:)
+# if defined key_zdfddm
+      zavsi(:,:,:) = avs(:,:,:)
+# endif
+
+#endif
+
+      ! Diagonal, inferior, superior  (including the bottom boundary condition via avt masked)
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ze3ta = 1._wp                                ! after scale factor at T-point
+               ze3tn = fse3t(ji,jj,jk)                      ! now   scale factor at T-point
+               zwi(ji,jj,jk) = - p2dt(jk) * zwt(ji,jj,jk  ) / ( ze3tn * fse3w(ji,jj,jk  ) )
+               zws(ji,jj,jk) = - p2dt(jk) * zwt(ji,jj,jk+1) / ( ze3tn * fse3w(ji,jj,jk+1) )
+               zwd(ji,jj,jk) = ze3ta - zwi(ji,jj,jk) - zws(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Surface boudary conditions
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ze3ta = 1._wp         ! after scale factor at T-point
+            zwi(ji,jj,1) = 0._wp
+            zwd(ji,jj,1) = ze3ta - zws(ji,jj,1)
+         END DO
+      END DO
+
+
+      ! II.1. Vertical diffusion on t
+      ! ---------------------------
+
+      !! Matrix inversion from the first level
+      !!----------------------------------------------------------------------
+      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+      !
+      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+      !        (        ...               )( ...  ) ( ...  )
+      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+      !
+      !   m is decomposed in the product of an upper and lower triangular matrix
+      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+      !   The second member is in 2d array zwy
+      !   The solution is in 2d array zwx
+      !   The 3d arry zwt is a work space array
+      !   zwy is used and then used as a work space array : its value is modified!
+
+      ! first recurrence:   Tk = Dk - Ik Sk-1 / Tk-1   (increasing k)
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            zwt(ji,jj,1) = zwd(ji,jj,1)
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zwt(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1)  /zwt(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+      ! third recurrence: Xk = (Zk - Sk Xk+1 ) / Tk
+      ! Save the masked temperature after in ta
+      ! (c a u t i o n:  temperature not its trend, Leap-frog scheme done it will not be done in tranxt)
+      DO jk = 1, jpk-2
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               ta_ad(ji,jj,jk+1) = ta_ad(ji,jj,jk+1) - zws(ji,jj,jk) * ta_ad(ji,jj,jk) / zwt(ji,jj,jk) * tmask(ji,jj,jk)
+               ta_ad(ji,jj,jk)   = ta_ad(ji,jj,jk) / zwt(ji,jj,jk) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            ta_ad(ji,jj,jpkm1) = ta_ad(ji,jj,jpkm1) / zwt(ji,jj,jpkm1) * tmask(ji,jj,jpkm1)
+         END DO
+      END DO
+      ! second recurrence:    Zk = Yk - Ik / Tk-1  Zk-1
+      DO jk = jpkm1, 2, -1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               ze3tb = 1._wp
+               ze3tn = 1._wp
+               zrhsad = zrhsad + ta_ad(ji,jj,jk)
+               ta_ad(ji,jj,jk-1) = ta_ad(ji,jj,jk-1) - zwi(ji,jj,jk) / zwt(ji,jj,jk-1) * ta_ad(ji,jj,jk)
+               ta_ad(ji,jj,jk) = 0.0_wp
+               tb_ad(ji,jj,jk) = tb_ad(ji,jj,jk) + ze3tb * zrhsad
+               ta_ad(ji,jj,jk) = ta_ad(ji,jj,jk) + p2dt(jk) * ze3tn * zrhsad
+               zrhsad = 0.0_wp
+            END DO
+         END DO
+      END DO
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            ze3tb = 1._wp
+            ze3tn = 1._wp
+            tb_ad(ji,jj,1) = tb_ad(ji,jj,1) + ze3tb * ta_ad(ji,jj,1)
+            ta_ad(ji,jj,1) = ta_ad(ji,jj,1) * p2dt(1) * ze3tn 
+         END DO
+      END DO
+     ! II.2 Vertical diffusion on salinity
+      ! -----------------------------------
+
+#if defined key_zdfddm
+      ! Rebuild the Matrix as avt /= avs
+
+      ! Diagonal, inferior, superior  (including the bottom boundary condition via avs masked)
+      DO jk = jpkm1, 1, -1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ze3ta = 1._wp         ! after scale factor at T-point
+               ze3tn = fse3t(ji,jj,jk)         ! now   scale factor at T-point
+               zwi(ji,jj,jk) = - p2dt(jk) * zavsi(ji,jj,jk  ) / ( ze3tn * fse3w(ji,jj,jk  ) )
+               zws(ji,jj,jk) = - p2dt(jk) * zavsi(ji,jj,jk+1) / ( ze3tn * fse3w(ji,jj,jk+1) )
+               zwd(ji,jj,jk) = ze3ta - zwi(ji,jj,jk) - zws(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Surface boudary conditions
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ze3ta = 1._wp         ! after scale factor at T-point
+            zwi(ji,jj,1) = 0._wp
+            zwd(ji,jj,1) = ze3ta - zws(ji,jj,1)
+         END DO
+      END DO
+#endif
+
+
+      !! Matrix inversion from the first level
+      !!----------------------------------------------------------------------
+      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+      !
+      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+      !        (        ...               )( ...  ) ( ...  )
+      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+      !
+      !   m is decomposed in the product of an upper and lower triangular
+      !   matrix
+      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+      !   The second member is in 2d array zwy
+      !   The solution is in 2d array zwx
+      !   The 3d arry zwt is a work space array
+      !   zwy is used and then used as a work space array : its value is modified!
+
+      ! first recurrence:   Tk = Dk - Ik Sk-1 / Tk-1   (increasing k)
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            zwt(ji,jj,1) = zwd(ji,jj,1)
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zwt(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1)  /zwt(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+      ! third recurrence: Xk = (Zk - Sk Xk+1 ) / Tk
+      ! Save the masked temperature after in ta
+      ! (c a u t i o n:  temperature not its trend, Leap-frog scheme done it will not be done in tranxt)
+      DO jk = 1, jpk-2
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               sa_ad(ji,jj,jk+1) = sa_ad(ji,jj,jk+1) - zws(ji,jj,jk) * sa_ad(ji,jj,jk) / zwt(ji,jj,jk) * tmask(ji,jj,jk)
+               sa_ad(ji,jj,jk  ) = sa_ad(ji,jj,jk  ) / zwt(ji,jj,jk) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            sa_ad(ji,jj,jpkm1) = sa_ad(ji,jj,jpkm1) / zwt(ji,jj,jpkm1) * tmask(ji,jj,jpkm1)
+         END DO
+      END DO
+
+      ! second recurrence:    Zk = Yk - Ik / Tk-1  Zk-1
+     DO jk = jpkm1, 2, -1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               ze3tb = 1.0_wp                  ! before scale factor at T-point
+               ze3tn = 1.0_wp                  ! now    scale factor at T-point
+               zrhsad = zrhsad + sa_ad(ji,jj,jk)
+               sa_ad(ji,jj,jk-1) = sa_ad(ji,jj,jk-1) - zwi(ji,jj,jk) / zwt(ji,jj,jk-1) * sa_ad(ji,jj,jk)
+               sa_ad(ji,jj,jk) = 0.0_wp
+               sb_ad(ji,jj,jk) = sb_ad(ji,jj,jk) + ze3tb * zrhsad
+               sa_ad(ji,jj,jk) = sa_ad(ji,jj,jk) + p2dt(jk) * ze3tn * zrhsad
+               zrhsad = 0.0_wp
+            END DO
+         END DO
+      END DO
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            ze3tb = 1.0_wp                   ! before scale factor at T-point
+            ze3tn = 1.0_wp                   ! now    scale factor at T-point
+            sb_ad(ji,jj,1) = sb_ad(ji,jj,1) + ze3tb * sa_ad(ji,jj,1)
+            sa_ad(ji,jj,1) = p2dt(1) * ze3tn * sa_ad(ji,jj,1)
+         END DO
+      END DO
+   END SUBROUTINE tra_zdf_imp_adj
+SUBROUTINE tra_zdf_imp_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tra_zdf_imp_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & istp,  &
+         & jstp,  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) ::   &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2            ! scalar product involving the adjoint routine
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zta_tlin ,     & ! Tangent input
+         & ztb_tlin ,     & ! Tangent input
+         & zsa_tlin ,     & ! Tangent input
+         & zsb_tlin ,     & ! Tangent input
+         & zta_tlout,     & ! Tangent output
+         & zsa_tlout,     & ! Tangent output
+         & zta_adin ,     & ! Adjoint input
+         & zsa_adin ,     & ! Adjoint input
+         & zta_adout,     & ! Adjoint output
+         & ztb_adout,     & ! Adjoint output
+         & zsa_adout,     & ! Adjoint output
+         & zsb_adout,     & ! Adjoint output
+         & zr             ! 3D random field 
+      CHARACTER(LEN=14) :: cl_name
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zta_tlin( jpi,jpj,jpk),     &
+         & zsa_tlin( jpi,jpj,jpk),     &
+         & ztb_tlin( jpi,jpj,jpk),     &
+         & zsb_tlin( jpi,jpj,jpk),     &
+         & zta_tlout(jpi,jpj,jpk),     &
+         & zsa_tlout(jpi,jpj,jpk),     &
+         & zta_adin( jpi,jpj,jpk),     &
+         & zsa_adin( jpi,jpj,jpk),     &
+         & zta_adout(jpi,jpj,jpk),     &
+         & zsa_adout(jpi,jpj,jpk),     &
+         & ztb_adout(jpi,jpj,jpk),     &
+         & zsb_adout(jpi,jpj,jpk),     &
+         & zr(       jpi,jpj,jpk)      &
+         & )
+      !==================================================================
+      ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and 
+      !    dy = ( hdivb_tl, hdivn_tl )
+      !==================================================================
+
+      ! initialization (normally done in traldf)
+      l_traldf_rot = .TRUE. 
+
+      ! Test for time steps nit000 and nit000 + 1 (the matrix changes)
+
+      DO jstp = nit000, nit000 + 2
+         istp = jstp
+         IF ( jstp == nit000+2 ) istp = nitend
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+          zta_tlin( :,:,:) = 0.0_wp
+          ztb_tlin( :,:,:) = 0.0_wp
+          zsa_tlin( :,:,:) = 0.0_wp
+          zsb_tlin( :,:,:) = 0.0_wp
+          zta_tlout(:,:,:) = 0.0_wp
+          zsa_tlout(:,:,:) = 0.0_wp
+          zta_adin( :,:,:) = 0.0_wp
+          zsa_adin( :,:,:) = 0.0_wp
+          zta_adout(:,:,:) = 0.0_wp
+          zsa_adout(:,:,:) = 0.0_wp
+          ztb_adout(:,:,:) = 0.0_wp
+          zsb_adout(:,:,:) = 0.0_wp
+          zr(       :,:,:) = 0.0_wp
+          tb_ad(:,:,:)     = 0.0_wp
+          sb_ad(:,:,:)     = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zta_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+     DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 352791 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              ztb_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+     DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 142746 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stds )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsa_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+     DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 214934 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stds )
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsb_tlin(ji,jj,jk) = zr(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+
+      ta_tl(:,:,:) = zta_tlin(:,:,:)
+      sa_tl(:,:,:) = zsa_tlin(:,:,:)
+      tb_tl(:,:,:) = ztb_tlin(:,:,:)
+      sb_tl(:,:,:) = zsb_tlin(:,:,:)
+      CALL tra_zdf_imp_tan ( istp, rdttra )
+      zta_tlout(:,:,:) = ta_tl(:,:,:)
+      zsa_tlout(:,:,:) = sa_tl(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zta_adin(ji,jj,jk) = zta_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_t(jk)
+              zsa_adin(ji,jj,jk) = zsa_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk) * wesp_s(jk)
+            END DO
+         END DO
+      END DO
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1 = DOT_PRODUCT( zta_tlout, zta_adin ) &
+         & + DOT_PRODUCT( zsa_tlout, zsa_adin )
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      ta_ad(:,:,:) = zta_adin(:,:,:)
+      sa_ad(:,:,:) = zsa_adin(:,:,:)
+      
+      CALL tra_zdf_imp_adj ( istp, rdttra )
+      
+      zta_adout(:,:,:) = ta_ad(:,:,:)
+      zsa_adout(:,:,:) = sa_ad(:,:,:)
+      ztb_adout(:,:,:) = tb_ad(:,:,:)
+      zsb_adout(:,:,:) = sb_ad(:,:,:)
+      zsp2 = DOT_PRODUCT( zta_tlin, zta_adout ) &
+         & + DOT_PRODUCT( zsa_tlin, zsa_adout ) &
+         & + DOT_PRODUCT( ztb_tlin, ztb_adout ) &
+         & + DOT_PRODUCT( zsb_tlin, zsb_adout ) 
+
+      ! 14 char:'12345678901234'
+      IF ( istp == nit000 ) THEN
+         cl_name = 'trazdfimpadjT1'
+      ELSEIF ( istp == nit000 +1 ) THEN
+         cl_name = 'trazdfimpadjT2'
+      ELSEIF ( istp == nitend ) THEN
+         cl_name = 'trazdfimpadjT3'
+      END IF
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      END DO
+
+      DEALLOCATE(   &
+         & zta_tlin,  &
+         & ztb_tlin,  &
+         & zsa_tlin,  &
+         & zsb_tlin,  &
+         & zta_tlout, &
+         & zsa_tlout, &
+         & zta_adin,  &
+         & zsa_adin,  &
+         & zta_adout, &
+         & ztb_adout, &
+         & zsa_adout, &
+         & zsb_adout, &
+         & zr       &
+         & )
+
+
+
+   END SUBROUTINE tra_zdf_imp_adj_tst
+#if defined key_tst_tlm
+   SUBROUTINE tra_zdf_imp_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tra_adv_zdf_imp_tlm_tst ***
+      !!
+      !! ** Purpose : Test the adjoint 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 :
+      !!        ! 09-07 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE oce           , ONLY: & ! ocean dynamics and active tracers
+      & tb, sb, ta, sa
+      USE tamtrj              ! writing out state trajectory
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE sshwzv             !  vertical velocity
+      USE gridrandom, ONLY: &
+        & grid_rd_sd
+      USE trj_tam
+      USE oce           , ONLY: & ! ocean dynamics and tracers variables
+        & tb, sb, ta, sa
+      USE trazdf_imp          ! vertical component of the tracer mixing trend
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & istp,  &
+         & jstp,  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_Ta,      &
+         & zsp1_Sa,      &
+         & zsp2,         & ! scalar product involving the tangent routine
+         & zsp2_Ta,      &
+         & zsp2_Sa,      &
+         & zsp3,         & ! scalar product involving the tangent routine
+         & zsp3_Ta,      &
+         & zsp3_Sa,      &
+         & zzsp,         & ! scalar product involving the tangent routine
+         & zzsp_Ta,      &
+         & zzsp_Sa,      & 
+         & gamma,            &
+         & zgsp1,            &
+         & zgsp2,            &
+         & zgsp3,            &
+         & zgsp4,            &
+         & zgsp5,            &
+         & zgsp6,            &
+         & zgsp7  
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & ztb_tlin,      & ! Tangent input
+         & zsb_tlin,      & ! Tangent input
+         & zta_tlin,      & ! Tangent input
+         & zsa_tlin,      & ! Tangent input
+         & zta_out ,      & ! Direct output
+         & zsa_out ,      & ! Direct output
+         & zta_wop ,      & ! Direct output w/o perturbation
+         & zsa_wop ,      & ! Direct output w/o 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):: &
+         & zscta, zscsa,    &
+         & zscerrta,        &
+         & zscerrsa
+      INTEGER, DIMENSION(100):: &
+         & iipostb, iipossb,    &
+         & iiposta, iipossa,    &
+         & ijpostb, ijpossb,    &
+         & ijposta, ijpossa,    & 
+         & ikpostb, ikpossb,    &
+         & ikposta, ikpossa
+      INTEGER::             &
+         & ii,              &
+         & isamp=40,        &
+         & jsamp=40,        &
+         & ksamp=10,        &
+         & numsctlm
+     REAL(KIND=wp), DIMENSION(jpi,jpj,jpk) :: &
+         & zerrta, zerrsa   
+      ! Allocate memory
+      ALLOCATE( &
+         & ztb_tlin( jpi,jpj,jpk),     &
+         & zsb_tlin( jpi,jpj,jpk),     &
+         & zta_tlin( jpi,jpj,jpk),     &
+         & zsa_tlin( jpi,jpj,jpk),     &
+         & zta_out ( jpi,jpj,jpk),     &
+         & zsa_out ( jpi,jpj,jpk),     &
+         & zta_wop ( jpi,jpj,jpk),     &
+         & zsa_wop ( jpi,jpj,jpk),     &
+         & zr(       jpi,jpj,jpk)      &
+         & )
+      !--------------------------------------------------------------------
+      ! Reset variables
+      !--------------------------------------------------------------------
+      ztb_tlin( :,:,:) = 0.0_wp
+      zsb_tlin( :,:,:) = 0.0_wp
+      zta_tlin( :,:,:) = 0.0_wp
+      zsa_tlin( :,:,:) = 0.0_wp
+      zta_out ( :,:,:) = 0.0_wp
+      zsa_out ( :,:,:) = 0.0_wp
+      zta_wop ( :,:,:) = 0.0_wp
+      zsa_wop ( :,:,:) = 0.0_wp
+      zr(       :,:,:) = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Output filename Xn=F(X0)
+      !--------------------------------------------------------------------
+!!!!      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
+      !--------------------------------------------------------------------
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         CALL grid_rd_sd( 596035, zr,  'T', 0.0_wp, stdt)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  ztb_tlin(ji,jj,jk) = zr(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 352791, zr,  'T', 0.0_wp, stds) 
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsb_tlin(ji,jj,jk) = zr(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 142746, zr,  'T', 0.0_wp, stdt)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zta_tlin(ji,jj,jk) = zr(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 214934, zr,  'T', 0.0_wp, stds)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsa_tlin(ji,jj,jk) = zr(ji,jj,jk)
+               END DO
+            END DO
+         END DO 
+      ENDIF 
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      IF ( tlm_bch /= 2 )      CALL istate_p  
+
+      ! *** initialize the reference trajectory
+      ! ------------
+      CALL  trj_rea( nit000-1, 1 )
+      CALL  trj_rea( nit000, 1 )
+
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         ztb_tlin(:,:,:) = gamma * ztb_tlin(:,:,:)
+         tb(:,:,:)       = tb(:,:,:) + ztb_tlin(:,:,:)
+
+         zsb_tlin(:,:,:) = gamma * zsb_tlin(:,:,:)
+         sb(:,:,:)       = sb(:,:,:) + zsb_tlin(:,:,:)
+
+         zta_tlin(:,:,:) = gamma * zta_tlin(:,:,:)
+         ta(:,:,:)       = ta(:,:,:) + zta_tlin(:,:,:)
+
+         zsa_tlin(:,:,:) = gamma * zsa_tlin(:,:,:)
+         sa(:,:,:)       = sa(:,:,:) + zsa_tlin(:,:,:)
+      ENDIF 
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------
+      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 ( tlm_bch == 2 ) THEN
+         !--------------------------------------------------------------------
+         ! Initialize the tangent variables: dy^* = W dy  
+         !--------------------------------------------------------------------
+         CALL  trj_rea( nit000-1, 1 ) 
+         CALL  trj_rea( nit000, 1 ) 
+         tb_tl  (:,:,:) = ztb_tlin  (:,:,:)
+         sb_tl  (:,:,:) = zsb_tlin  (:,:,:)
+         ta_tl  (:,:,:) = zta_tlin  (:,:,:)
+         sa_tl  (:,:,:) = zsa_tlin  (:,:,:)
+
+         !-----------------------------------------------------------------------
+         !  Initialization of the dynamics and tracer fields for the tangent
+         !----------------------------------------------------------------------- 
+         CALL tra_zdf_imp_tan(nit000, rdttra)
+
+         !--------------------------------------------------------------------
+         ! 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 
+         ! 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 jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zta_out   (ji,jj,jk) = zta_out    (ji,jj,jk) - zta_wop  (ji,jj,jk)
+                  zta_wop   (ji,jj,jk) = zta_out    (ji,jj,jk) - ta_tl    (ji,jj,jk)
+                  IF (  ta_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrta(ji,jj,jk) = zta_out(ji,jj,jk)/ta_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iiposta(ii) = ji
+                      ijposta(ii) = jj
+                      ikposta(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+                         zscta (ii) =  zta_wop(ji,jj,jk)
+                         zscerrta (ii) =  ( zerrta(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         ii=0
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zsa_out   (ji,jj,jk) = zsa_out    (ji,jj,jk) - zsa_wop  (ji,jj,jk)
+                  zsa_wop   (ji,jj,jk) = zsa_out    (ji,jj,jk) - sa_tl    (ji,jj,jk)
+                  IF (  sa_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                     & zerrsa(ji,jj,jk) = zsa_out(ji,jj,jk)/sa_tl(ji,jj,jk)
+                  IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                  &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                  &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                      ii = ii+1
+                      iipossa(ii) = ji
+                      ijpossa(ii) = jj
+                      ikpossa(ii) = jk
+                      IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+                         zscsa (ii) =  zsa_wop(ji,jj,jk)
+                         zscerrsa (ii) =  ( zerrsa(ji,jj,jk) - 1.0_wp ) / gamma
+                      ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+
+         zsp1_Ta    = DOT_PRODUCT( zta_out, zta_out  )
+         zsp1_Sa    = DOT_PRODUCT( zsa_out, zsa_out  )
+
+         zsp1      = zsp1_Ta + zsp1_Sa
+
+         zsp3_Ta    = DOT_PRODUCT( zta_wop, zta_wop  )
+         zsp3_Sa    = DOT_PRODUCT( zsa_wop, zsa_wop  )
+
+         zsp3      = zsp3_Ta + zsp3_Sa
+ 
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name = 'trazdf_tam:En '
+         zzsp    = SQRT(zsp3)
+         zzsp_Ta = SQRT(zsp3_Ta)
+         zzsp_Sa = SQRT(zsp3_Sa)
+         zgsp5   = zzsp
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp      = SQRT(zsp2)
+         zzsp_Ta   = SQRT(zsp2_Ta)
+         zzsp_Sa   = SQRT(zsp2_Sa)
+         zgsp4     = zzsp
+         cl_name = 'trazdf_tam:Ln2'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         zzsp      = SQRT(zsp1)
+         zzsp_Ta   = SQRT(zsp1_Ta)
+         zzsp_Sa   = SQRT(zsp1_Sa)
+
+         cl_name = 'trazdf:Mhdx-Mx'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         zgsp3 = SQRT( zsp3/zsp2 )
+         zgsp7 = zgsp3/gamma
+         zgsp1 = zzsp
+         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) 'tzdfimp ', 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 = 'tzdfimp '
+         IF(lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zscta(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscta     ', &
+                    & cur_loop, h_ratio, ii, iiposta(ii), ijposta(ii), zscta(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscsa(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscsa     ', &
+                    & cur_loop, h_ratio, ii, iipossa(ii), ijpossa(ii), zscsa(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrta(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrta ', &
+                    & cur_loop, h_ratio, ii, iiposta(ii), ijposta(ii), zscerrta(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrsa(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrsa ', &
+                    & cur_loop, h_ratio, ii, iipossa(ii), ijpossa(ii), zscerrsa(ii)
+            ENDDO
+            ! write separator
+            WRITE(numtan_sc, "(A4)") '===='
+         ENDIF
+
+      ENDIF
+
+      DEALLOCATE(                  &
+         & ztb_tlin, zsb_tlin,     & 
+         & zta_tlin, zsa_tlin,     &  
+         & zta_out, zsa_out,       &  
+         & zta_wop, zsa_wop,       & 
+         & zr                      &
+         & )
+   END SUBROUTINE tra_zdf_imp_tlm_tst
+#endif
+#endif
+END MODULE trazdf_imp_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trazdf_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trazdf_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/trazdf_tam.F90	(revision 2578)
@@ -0,0 +1,277 @@
+MODULE trazdf_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                 ***  MODULE  trazdf_zdf  ***
+   !! Ocean active tracers:  vertical component of the tracer mixing trend
+   !!                 Tangent and Adjoint Module
+   !!==============================================================================
+   !! History of the direct module:  
+   !!            9.0  !  05-11  (G. Madec)  Original code
+   !! History of the TAM module:
+   !!            9.0  !  08-06  (A. Vidard) Skeleton
+   !!            9.0  !  09-01  (A. Vidard) TAM of the 05-11 version
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_zdf_tan  : Update the tracer trend with the vertical diffusion (tan)
+   !!   tra_zdf_adj  : Update the tracer trend with the vertical diffusion (adj)
+   !!       zdf_ctl  : ???
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpk,                 &
+      & lk_esopa
+   USE oce_tam       , ONLY: & ! ocean dynamics and active tracers
+      & ta_tl,               &
+      & sa_tl,               &
+      & ta_ad,               &
+      & sa_ad
+   USE dom_oce       , ONLY: & ! ocean space and time domain
+      & tmask,               &
+      & lk_vvl,              &
+      & neuler,              &
+      & rdttra,              &
+      & ln_sco
+   USE ldftra_oce    , ONLY: &
+      & ln_traldf_iso,       &
+      & ln_traldf_hor
+   USE zdf_oce      , ONLY : &
+      & ln_zdfexp
+   USE trazdf_exp_tam, ONLY: & ! vertical diffusion: explicit (tra_zdf_exp     routine)
+      & tra_zdf_exp_tan,     &
+      & tra_zdf_exp_adj,     &
+      & tra_zdf_exp_adj_tst
+   USE trazdf_imp_tam, ONLY: & ! vertical diffusion: implicit (tra_zdf_imp     routine)
+      & tra_zdf_imp_tan,     &
+      & tra_zdf_imp_adj,     &
+#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,                 &
+      & numout,              & 
+      & nitend,              & 
+      & nit000,              &
+      & ctl_stop
+   USE prtctl        , ONLY: &
+      & prt_ctl
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC  &
+      & tra_zdf_tan, &
+      & tra_zdf_adj         ! routines called by step_tam.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)
+
+   REAL(wp), DIMENSION(jpk) ::   r2dt  ! vertical profile time-step, = 2 rdttra
+      !                                ! except at nit000 (=rdttra) if neuler=0
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "zdfddm_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+   
+   SUBROUTINE tra_zdf_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_zdf_tan  ***
+      !!
+      !! ** Purpose of the direct routine:   
+      !!            compute the vertical ocean tracer physics.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL zdf_ctl_tam          ! initialisation & control of options
+
+      !                                          ! set time step
+      IF( neuler == 0 .AND. kt == nit000 ) THEN     ! at nit000
+         r2dt(:) =  rdttra(:)                          ! = rdtra (restarting with Euler time stepping)
+      ELSEIF( kt <= nit000 + 1) THEN                ! at nit000 or nit000+1
+         r2dt(:) = 2. * rdttra(:)                      ! = 2 rdttra (leapfrog)
+      ENDIF
+         
+      SELECT CASE ( nzdf )                       ! compute lateral mixing trend and add it to the general trend
+      CASE ( -1 )                                       ! esopa: test all possibility with control print
+         CALL tra_zdf_exp_tan    ( kt, r2dt )
+         CALL prt_ctl( tab3d_1=ta_tl, clinfo1=' zdf0 - Ta_tl: ', mask1=tmask,               &
+            &          tab3d_2=sa_tl, clinfo2=       ' Sa_tl: ', mask2=tmask, clinfo3='tra' )
+         CALL tra_zdf_imp_tan    ( kt, r2dt )
+         CALL prt_ctl( tab3d_1=ta_tl, clinfo1=' zdf1 - Ta_tl: ', mask1=tmask,               &
+            &          tab3d_2=sa_tl, clinfo2=       ' Sa_tl: ', mask2=tmask, clinfo3='tra' )
+
+      CASE ( 0 )                                       ! explicit scheme
+         CALL tra_zdf_exp_tan    ( kt, r2dt )
+
+      CASE ( 1 )                                       ! implicit scheme 
+         CALL tra_zdf_imp_tan    ( kt, r2dt )
+
+      END SELECT
+
+   END SUBROUTINE tra_zdf_tan
+   SUBROUTINE tra_zdf_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_zdf_adj  ***
+      !!
+      !! ** Purpose of the direct routine:   
+      !!            compute the vertical ocean tracer physics.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+      !!---------------------------------------------------------------------
+
+      IF( kt == nitend )   CALL zdf_ctl_tam          ! initialisation & control of options
+      !                                          ! set time step
+      IF( neuler == 0 .AND. kt == nit000 ) THEN     ! at nit000
+         r2dt(:) =  rdttra(:)                          ! = rdtra (restarting with Euler time stepping)
+      ELSEIF( kt <= nit000 + 1) THEN                ! at nit000 or nit000+1
+         r2dt(:) = 2. * rdttra(:)                      ! = 2 rdttra (leapfrog)
+      ELSEIF( kt == nitend) THEN
+         r2dt(:) = 2. * rdttra(:)
+      ENDIF
+         
+      SELECT CASE ( nzdf )                       ! compute lateral mixing trend and add it to the general trend
+      CASE ( -1 )                                       ! esopa: test all possibility with control print
+         CALL tra_zdf_exp_adj    ( kt, r2dt )
+         CALL prt_ctl( tab3d_1=ta_ad, clinfo1=' zdf0 - Ta_ad: ', mask1=tmask,               &
+            &          tab3d_2=sa_ad, clinfo2=       ' Sa_ad: ', mask2=tmask, clinfo3='tra' )
+         CALL tra_zdf_imp_adj    ( kt, r2dt )
+         CALL prt_ctl( tab3d_1=ta_ad, clinfo1=' zdf1 - Ta_ad: ', mask1=tmask,               &
+            &          tab3d_2=sa_ad, clinfo2=       ' Sa_ad: ', mask2=tmask, clinfo3='tra' )
+
+      CASE ( 0 )                                       ! explicit scheme
+         CALL tra_zdf_exp_adj    ( kt, r2dt )
+
+      CASE ( 1 )                                       ! implicit scheme 
+         CALL tra_zdf_imp_adj    ( kt, r2dt )
+
+      END SELECT
+
+   END SUBROUTINE tra_zdf_adj
+   SUBROUTINE tra_zdf_adj_tst( kumadt )
+      !! ** Purpose : Test the adjoint routines.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!       
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      ! init
+      CALL zdf_ctl_tam 
+      ! Test the explicit formulation            
+      CALL tra_zdf_exp_adj_tst    ( kumadt )
+      ! Test the implicit formulation            
+      CALL tra_zdf_imp_adj_tst    ( kumadt )
+   END SUBROUTINE tra_zdf_adj_tst
+   !!==============================================================================
+   SUBROUTINE zdf_ctl_tam
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE zdf_ctl_tam  ***
+      !!
+      !! ** Purpose :   Choose the vertical mixing scheme
+      !!
+      !! ** Method  :   Set nzdf from ln_zdfexp
+      !!      nzdf = 0   explicit (time-splitting) scheme (ln_zdfexp=T)
+      !!           = 1   implicit (euler backward) scheme (ln_zdfexp=F)
+      !!      NB: rotation of lateral mixing operator or TKE or KPP scheme,
+      !!      the implicit scheme is required.
+      !!----------------------------------------------------------------------
+      USE zdftke_old
+      USE zdftke
+      USE zdfkpp
+      !!----------------------------------------------------------------------
+
+      !  Define the vertical tracer physics scheme
+      ! ==========================================
+
+      ! Choice from ln_zdfexp already read in namelist in zdfini module
+      IF( ln_zdfexp ) THEN               ! use explicit scheme
+         nzdf = 0
+      ELSE                               ! use implicit scheme
+         nzdf = 1
+      ENDIF
+
+      ! Force implicit schemes
+      IF( lk_zdftke_old .OR. lk_zdftke .OR. lk_zdfkpp   )   nzdf = 1      ! TKE or KPP physics
+      IF( ln_traldf_iso                                 )   nzdf = 1      ! iso-neutral lateral physics
+      IF( ln_traldf_hor .AND. ln_sco                    )   nzdf = 1      ! horizontal lateral physics in s-coordinate
+
+      IF( ln_zdfexp .AND. nzdf == 1 )   THEN
+         CALL ctl_stop( 'tra_zdf_tam : If using the rotation of lateral mixing operator or TKE ', &
+            &           '            or KPP scheme, the implicit scheme is required, set ln_zdfexp = .false.' )
+      ENDIF
+
+      ! Test: esopa
+      IF( lk_esopa )    nzdf = -1                      ! All schemes used
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra:zdf_ctl_tam : vertical tracer physics scheme'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         IF( nzdf == -1 )   WRITE(numout,*) '              ESOPA test All scheme used'
+         IF( nzdf ==  0 )   WRITE(numout,*) '              Explicit time-splitting scheme'
+         IF( nzdf ==  1 )   WRITE(numout,*) '              Implicit (euler backward) scheme'
+      ENDIF
+
+   END SUBROUTINE zdf_ctl_tam
+#if defined key_tst_tlm
+   SUBROUTINE tra_zdf_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tra_zdf_tlm_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 
+      !!                   
+      !! History :
+      !!        ! 09-08 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      ! init
+      CALL zdf_ctl_tam 
+      ! Test the explicit formulation            
+      CALL tra_zdf_exp_adj_tst    ( kumadt )
+      ! Test the implicit formulation            
+      CALL tra_zdf_imp_tlm_tst    ( kumadt )
+   END SUBROUTINE tra_zdf_tlm_tst
+#endif
+#endif
+END MODULE trazdf_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/zpshde_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/zpshde_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/zpshde_tam.F90	(revision 2578)
@@ -0,0 +1,1472 @@
+MODULE zpshde_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                       ***  MODULE zpshde_tam   ***
+   !! z-coordinate - partial step : Horizontal Derivative
+   !!                               Tangent and Adjoint Module
+   !!==============================================================================
+   
+   !!----------------------------------------------------------------------
+   !!   zps_hde      :  Horizontal DErivative of T, S and rd at the last
+   !!                   ocean level (Z-coord. with Partial Steps)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 & 
+      & jpim1,               & 
+      & jpjm1,               & 
+      & jpiglo
+   USE oce           , ONLY: & ! ocean variables
+      & tn,                  &
+      & sn
+   USE dom_oce       , ONLY: & ! ocean space domain variables
+      & umask,               &
+      & vmask,               &
+      & e2u,                 &
+      & e1u,                 &
+      & e2v,                 &
+      & e1v,                 &
+# if defined key_zco
+      & gdept_0,             &
+      & e3t_0,               &
+      & e3w_0,               &
+# else
+      & gdept,               &
+      & e3u,                 &
+      & e3v,                 &
+      & e3w,                 &
+# endif
+      & mbathy,              &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE in_out_manager, ONLY: & ! I/O manager
+      & lwp,                 &
+      & numout,              & 
+      & nit000,              &
+      & nitend
+   USE eosbn2_tam    , ONLY: & ! ocean equation of state
+      & eos_tan,             &
+      & eos_adj
+   USE lbclnk        , ONLY: & ! lateral boundary conditions (or mpp link)
+      & lbc_lnk
+   USE lbclnk_tam    , ONLY: & ! lateral boundary conditions (or mpp link)
+      & lbc_lnk_adj
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          & !
+      & prntst_tlm,          & !
+      & stdt,                & ! stdev for temperature
+      & stds,                & !           salinity
+      & stdr                   !           
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC zps_hde_tan      ! routine called by step_tam.F90
+   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
+   INTEGER, DIMENSION(jpi,jpj) ::   &
+   &   mbatu, mbatv      ! bottom ocean level index at U- and V-points
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE zps_hde_tan ( kt, ptem, psal,              &
+      &                     ptem_tl, psal_tl, prd_tl ,   &
+                            pgtu_tl, pgsu_tl, pgru_tl,   &
+                            pgtv_tl, pgsv_tl, pgrv_tl     )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE zps_hde_tan  ***
+      !!                    
+      !! ** Purpose of the direct routine:
+      !!      Compute the horizontal derivative of T, S and rd
+      !!      at u- and v-points with a linear interpolation for z-coordinate
+      !!      with partial steps.
+      !!
+      !! ** Method of the direct routine:
+      !!      In z-coord with partial steps, scale factors on last 
+      !!      levels are different for each grid point, so that T, S and rd 
+      !!      points are not at the same depth as in z-coord. To have horizontal
+      !!      gradients again, we interpolate T and S at the good depth : 
+      !!      Linear interpolation of T, S   
+      !!         Computation of di(tb) and dj(tb) by vertical interpolation:
+      !!          di(t) = t~ - t(i,j,k) or t(i+1,j,k) - t~
+      !!          dj(t) = t~ - t(i,j,k) or t(i,j+1,k) - t~
+      !!         This formulation computes the two cases:
+      !!                 CASE 1                   CASE 2  
+      !!         k-1  ___ ___________   k-1   ___ ___________
+      !!                    Ti  T~                  T~  Ti+1
+      !!                  _____                        _____
+      !!         k        |   |Ti+1     k           Ti |   |
+      !!                  |   |____                ____|   |
+      !!              ___ |   |   |           ___  |   |   |
+      !!                  
+      !!      case 1->   e3w(i+1) >= e3w(i) ( and e3w(j+1) >= e3w(j) ) then
+      !!          t~ = t(i+1,j  ,k) + (e3w(i+1) - e3w(i)) * dk(Ti+1)/e3w(i+1)
+      !!        ( t~ = t(i  ,j+1,k) + (e3w(j+1) - e3w(j)) * dk(Tj+1)/e3w(j+1)  )
+      !!          or
+      !!      case 2->   e3w(i+1) <= e3w(i) ( and e3w(j+1) <= e3w(j) ) then
+      !!          t~ = t(i,j,k) + (e3w(i) - e3w(i+1)) * dk(Ti)/e3w(i )
+      !!        ( t~ = t(i,j,k) + (e3w(j) - e3w(j+1)) * dk(Tj)/e3w(j ) )
+      !!          Idem for di(s) and dj(s)          
+      !!
+      !!      For rho, we call eos_insitu_2d which will compute rd~(t~,s~) at 
+      !!      the good depth zh from interpolated T and S for the different
+      !!      formulation of the equation of state (eos).
+      !!      Gradient formulation for rho :
+      !!          di(rho) = rd~ - rd(i,j,k) or rd (i+1,j,k) - rd~
+      !!
+      !! ** Action  : - pgtu, pgsu, pgru: horizontal gradient of T, S
+      !!                and rd at U-points 
+      !!              - pgtv, pgsv, pgrv: horizontal gradient of T, S
+      !!                and rd at V-points 
+      !!
+      !! History of the direct routine:
+      !!   8.5  !  02-04  (A. Bozec)  Original code
+      !!   8.5  !  02-08  (G. Madec E. Durand)  Optimization and Free form
+      !! History of the TAM routine:
+      !!   9.0  !  08-06 (A. Vidard) Skeleton
+      !!        !  08-06 (A. Vidard) tangent of the 02-08 version
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem, psal                          ! 3D T, S and rd direct fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem_tl, psal_tl, prd_tl            ! 3D T, S and rd tangent fields
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( out ) ::   &
+         pgtu_tl, pgsu_tl, pgru_tl,       &  ! horizontal grad. of T, S and rd at u- 
+         pgtv_tl, pgsv_tl, pgrv_tl           ! and v-points of the partial step level
+
+
+      !! * Local declarations
+      INTEGER ::   ji, jj,       &  ! Dummy loop indices
+                   iku,ikv          ! partial step level at u- and v-points
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         ztmpi, ztmpj,           &
+         zti, ztj, zsi, zsj,     &  ! interpolated value of T, S 
+         zri, zrj,               &  ! and rd
+         ztitl, ztjtl,           &  ! interpolated value of Ttl
+         zsitl, zsjtl,           &  !, Stl 
+         zritl, zrjtl,           &  ! and rdtl
+         zhgi, zhgj                 ! depth of interpolation for eos2d
+      REAL(wp) ::   &
+         ze3wu, ze3wv,           &  ! temporary scalars
+         zmaxu1, zmaxu2,         &  !    "         "
+         zmaxv1, zmaxv2             !    "         "
+
+      ! Initialization (first time-step only): compute mbatu and mbatv
+      IF( kt == nit000 ) THEN
+         mbatu(:,:) = 0
+         mbatv(:,:) = 0
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               mbatu(ji,jj) = MAX( MIN( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1, 2 )
+               mbatv(ji,jj) = MAX( MIN( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1, 2 )
+            END DO
+         END DO
+         ztmpi(:,:) = FLOAT( mbatu(:,:) )
+         ztmpj(:,:) = FLOAT( mbatv(:,:) )
+         ! lateral boundary conditions: T-point, sign unchanged
+         CALL lbc_lnk( ztmpi , 'U', 1.0_wp )
+         CALL lbc_lnk( ztmpj , 'V', 1.0_wp )
+         mbatu(:,:) = MAX( INT( ztmpi(:,:) ), 2 )
+         mbatv(:,:) = MAX( INT( ztmpj(:,:) ), 2 )
+      ENDIF
+      
+
+      ! Interpolation of T and S at the last ocean level
+# if defined key_vectopt_loop
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
+# else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+# endif
+            ! last level
+            iku = mbatu(ji,jj)
+            ikv = mbatv(ji,jj)
+
+            ze3wu  = fse3w(ji+1,jj  ,iku) - fse3w(ji,jj,iku)
+            ze3wv  = fse3w(ji  ,jj+1,ikv) - fse3w(ji,jj,ikv)
+            zmaxu1 =  ze3wu / fse3w(ji+1,jj  ,iku)
+            zmaxu2 = -ze3wu / fse3w(ji  ,jj  ,iku)
+            zmaxv1 =  ze3wv / fse3w(ji  ,jj+1,ikv)
+            zmaxv2 = -ze3wv / fse3w(ji  ,jj  ,ikv)
+
+            ! i- direction
+
+            IF( ze3wu >= 0. ) THEN      ! case 1
+               ! interpolated values of T and S
+               zti(ji,jj) = ptem(ji+1,jj,iku)            &
+                  &       + zmaxu1 * ( ptem(ji+1,jj,iku-1) - ptem(ji+1,jj,iku) )
+               zsi(ji,jj) = psal(ji+1,jj,iku)            &
+                  &       + zmaxu1 * ( psal(ji+1,jj,iku-1) - psal(ji+1,jj,iku) )
+               ztitl(ji,jj) = ptem_tl(ji+1,jj,iku)       &
+                  &         + zmaxu1 * ( ptem_tl(ji+1,jj,iku-1) - ptem_tl(ji+1,jj,iku) )
+               zsitl(ji,jj) = psal_tl(ji+1,jj,iku)       &
+                  &         + zmaxu1 * ( psal_tl(ji+1,jj,iku-1) - psal_tl(ji+1,jj,iku) )
+               ! depth of the partial step level
+               zhgi(ji,jj) = fsdept(ji,jj,iku)
+               ! gradient of T and S
+               pgtu_tl(ji,jj) = umask(ji,jj,1) * ( ztitl(ji,jj) - ptem_tl(ji,jj,iku) )
+               pgsu_tl(ji,jj) = umask(ji,jj,1) * ( zsitl(ji,jj) - psal_tl(ji,jj,iku) )
+            ELSE                        ! case 2
+               ! interpolated values of T and S
+               zti(ji,jj) = ptem(ji,jj,iku)              &
+                  &       + zmaxu2 * ( ptem(ji,jj,iku-1) - ptem(ji,jj,iku) )
+               zsi(ji,jj) = psal(ji,jj,iku)              &
+                  &       + zmaxu2 * ( psal(ji,jj,iku-1) - psal(ji,jj,iku) )
+               ! interpolated values of T and S
+               ztitl(ji,jj) = ptem_tl(ji,jj,iku)         &
+                  &         + zmaxu2 * ( ptem_tl(ji,jj,iku-1) - ptem_tl(ji,jj,iku) )
+               zsitl(ji,jj) = psal_tl(ji,jj,iku)         &
+                  &         + zmaxu2 * ( psal_tl(ji,jj,iku-1) - psal_tl(ji,jj,iku) )
+               ! depth of the partial step level
+               zhgi(ji,jj) = fsdept(ji+1,jj,iku)
+               ! gradient of T and S 
+               pgtu_tl(ji,jj) = umask(ji,jj,1) * ( ptem_tl(ji+1,jj,iku) - ztitl (ji,jj) )
+               pgsu_tl(ji,jj) = umask(ji,jj,1) * ( psal_tl(ji+1,jj,iku) - zsitl (ji,jj) )
+            ENDIF
+
+            ! j- direction
+
+            IF( ze3wv >= 0. ) THEN      ! case 1
+               ! interpolated values of direct T and S
+               ztj(ji,jj) = ptem(ji,jj+1,ikv)            &
+                  &       + zmaxv1 * ( ptem(ji,jj+1,ikv-1) - ptem(ji,jj+1,ikv) )
+               zsj(ji,jj) = psal(ji,jj+1,ikv)            &
+                  &       + zmaxv1 * ( psal(ji,jj+1,ikv-1) - psal(ji,jj+1,ikv) )
+               ! interpolated values of tangent T and S
+               ztjtl(ji,jj) = ptem_tl(ji,jj+1,ikv)       &
+                  &         + zmaxv1 * ( ptem_tl(ji,jj+1,ikv-1) - ptem_tl(ji,jj+1,ikv) )
+               zsjtl(ji,jj) = psal_tl(ji,jj+1,ikv)       &
+                  &         + zmaxv1 * ( psal_tl(ji,jj+1,ikv-1) - psal_tl(ji,jj+1,ikv) )
+               ! depth of the partial step level
+               zhgj(ji,jj) = fsdept(ji,jj,ikv) 
+               ! gradient of T and S
+               pgtv_tl(ji,jj) = vmask(ji,jj,1) * ( ztjtl(ji,jj) - ptem_tl(ji,jj,ikv) )
+               pgsv_tl(ji,jj) = vmask(ji,jj,1) * ( zsjtl(ji,jj) - psal_tl(ji,jj,ikv) )
+
+            ELSE                        ! case 2
+               ! interpolated values of T and S
+               ztj(ji,jj) = ptem(ji,jj,ikv)       &
+                  &       + zmaxv2 * ( ptem(ji,jj,ikv-1) - ptem(ji,jj,ikv) )
+               zsj(ji,jj) = psal(ji,jj,ikv)       &
+                  &       + zmaxv2 * ( psal(ji,jj,ikv-1) - psal(ji,jj,ikv) ) 
+               ! interpolated values of T and S
+               ztjtl(ji,jj) = ptem_tl(ji,jj,ikv)  &
+                  &         + zmaxv2 * ( ptem_tl(ji,jj,ikv-1) - ptem_tl(ji,jj,ikv) )
+               zsjtl(ji,jj) = psal_tl(ji,jj,ikv)  &
+                  &         + zmaxv2 * ( psal_tl(ji,jj,ikv-1) - psal_tl(ji,jj,ikv) ) 
+               ! depth of the partial step level
+               zhgj(ji,jj) = fsdept(ji,jj+1,ikv) 
+               ! gradient of T and S
+               pgtv_tl(ji,jj) = vmask(ji,jj,1) * ( ptem_tl(ji,jj+1,ikv) - ztjtl(ji,jj) )
+               pgsv_tl(ji,jj) = vmask(ji,jj,1) * ( psal_tl(ji,jj+1,ikv) - zsjtl(ji,jj) )
+            ENDIF
+# if ! defined key_vectopt_loop
+         END DO
+# endif
+      END DO
+
+      ! Compute interpolated rd from zti, zsi, ztj, zsj for the 2 cases at the depth of the partial
+      ! step and store it in  zri, zrj for each  case
+      CALL eos_tan( zti, zsi, zhgi, ztitl, zsitl, zritl )
+      CALL eos_tan( ztj, zsj, zhgj, ztjtl, zsjtl, zrjtl )
+
+
+      ! Gradient of density at the last level 
+# if defined key_vectopt_loop 
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
+# else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+# endif
+            iku = mbatu(ji,jj)
+            ikv = mbatv(ji,jj)
+            ze3wu  = fse3w(ji+1,jj  ,iku) - fse3w(ji,jj,iku)
+            ze3wv  = fse3w(ji  ,jj+1,ikv) - fse3w(ji,jj,ikv)
+            IF( ze3wu >= 0. ) THEN    ! i-direction: case 1
+               pgru_tl(ji,jj) = umask(ji,jj,1) * ( zritl(ji,jj) - prd_tl(ji,jj,iku) )
+            ELSE                      ! i-direction: case 2
+               pgru_tl(ji,jj) = umask(ji,jj,1) * ( prd_tl(ji+1,jj,iku) - zritl(ji,jj) )
+            ENDIF
+            IF( ze3wv >= 0. ) THEN    ! j-direction: case 1
+               pgrv_tl(ji,jj) = vmask(ji,jj,1) * ( zrjtl(ji,jj) - prd_tl(ji,jj,ikv) )  
+            ELSE                      ! j-direction: case 2
+               pgrv_tl(ji,jj) = vmask(ji,jj,1) * ( prd_tl(ji,jj+1,ikv) - zrjtl(ji,jj) )
+            ENDIF
+# if ! defined key_vectopt_loop 
+         END DO
+# endif
+      END DO
+
+      ! Lateral boundary conditions on each gradient
+      CALL lbc_lnk( pgtu_tl , 'U', -1.0_wp )  ;  CALL lbc_lnk( pgtv_tl , 'V', -1.0_wp )
+      CALL lbc_lnk( pgsu_tl , 'U', -1.0_wp )  ;  CALL lbc_lnk( pgsv_tl , 'V', -1.0_wp )
+      CALL lbc_lnk( pgru_tl , 'U', -1.0_wp )  ;  CALL lbc_lnk( pgrv_tl , 'V', -1.0_wp )
+
+   END SUBROUTINE zps_hde_tan
+
+   SUBROUTINE zps_hde_adj ( kt, ptem, psal,              &
+      &                     ptem_ad, psal_ad, prd_ad ,   &
+                            pgtu_ad, pgsu_ad, pgru_ad,   &
+                            pgtv_ad, pgsv_ad, pgrv_ad     )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE zps_hde_adj  ***
+      !!                    
+      !! ** Purpose of the direct routine:
+      !!      Compute the horizontal derivative of T, S and rd
+      !!      at u- and v-points with a linear interpolation for z-coordinate
+      !!      with partial steps.
+      !!
+      !! ** Method of the direct routine:
+      !!      In z-coord with partial steps, scale factors on last 
+      !!      levels are different for each grid point, so that T, S and rd 
+      !!      points are not at the same depth as in z-coord. To have horizontal
+      !!      gradients again, we interpolate T and S at the good depth : 
+      !!      Linear interpolation of T, S   
+      !!         Computation of di(tb) and dj(tb) by vertical interpolation:
+      !!          di(t) = t~ - t(i,j,k) or t(i+1,j,k) - t~
+      !!          dj(t) = t~ - t(i,j,k) or t(i,j+1,k) - t~
+      !!         This formulation computes the two cases:
+      !!                 CASE 1                   CASE 2  
+      !!         k-1  ___ ___________   k-1   ___ ___________
+      !!                    Ti  T~                  T~  Ti+1
+      !!                  _____                        _____
+      !!         k        |   |Ti+1     k           Ti |   |
+      !!                  |   |____                ____|   |
+      !!              ___ |   |   |           ___  |   |   |
+      !!                  
+      !!      case 1->   e3w(i+1) >= e3w(i) ( and e3w(j+1) >= e3w(j) ) then
+      !!          t~ = t(i+1,j  ,k) + (e3w(i+1) - e3w(i)) * dk(Ti+1)/e3w(i+1)
+      !!        ( t~ = t(i  ,j+1,k) + (e3w(j+1) - e3w(j)) * dk(Tj+1)/e3w(j+1)  )
+      !!          or
+      !!      case 2->   e3w(i+1) <= e3w(i) ( and e3w(j+1) <= e3w(j) ) then
+      !!          t~ = t(i,j,k) + (e3w(i) - e3w(i+1)) * dk(Ti)/e3w(i )
+      !!        ( t~ = t(i,j,k) + (e3w(j) - e3w(j+1)) * dk(Tj)/e3w(j ) )
+      !!          Idem for di(s) and dj(s)          
+      !!
+      !!      For rho, we call eos_insitu_2d which will compute rd~(t~,s~) at 
+      !!      the good depth zh from interpolated T and S for the different
+      !!      formulation of the equation of state (eos).
+      !!      Gradient formulation for rho :
+      !!          di(rho) = rd~ - rd(i,j,k) or rd (i+1,j,k) - rd~
+      !!
+      !! ** Action  : - pgtu, pgsu, pgru: horizontal gradient of T, S
+      !!                and rd at U-points 
+      !!              - pgtv, pgsv, pgrv: horizontal gradient of T, S
+      !!                and rd at V-points 
+      !!
+      !! History of the direct routine:
+      !!   8.5  !  02-04  (A. Bozec)  Original code
+      !!   8.5  !  02-08  (G. Madec E. Durand)  Optimization and Free form
+      !! History of the TAM routine:
+      !!   9.0  !  08-06 (A. Vidard) Skeleton
+      !!        !  08-08 (A. Vidard) adjoint of the 02-08 version
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem, psal                          ! 3D T, S and rd direct fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         ptem_ad, psal_ad, prd_ad            ! 3D T, S and rd tangent fields
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         pgtu_ad, pgsu_ad, pgru_ad,       &  ! horizontal grad. of T, S and rd at u- 
+         pgtv_ad, pgsv_ad, pgrv_ad           ! and v-points of the partial step level
+
+
+      !! * Local declarations
+      INTEGER ::   ji, jj,       &  ! Dummy loop indices
+                   iku,ikv          ! partial step level at u- and v-points
+      REAL(wp), DIMENSION(jpi,jpj) ::    &
+         ztmpi, ztmpj,                   &
+         zti, ztj, zsi, zsj,             &  ! interpolated value of T, S 
+         zri, zrj,                       &  ! and rd
+         ztiad, ztjad, zsiad, zsjad,     &  ! interpolated value of Tad, Sad 
+         zriad, zrjad,                   &  ! and rdad
+         zhgi, zhgj                         ! depth of interpolation for eos2d
+      REAL(wp) ::   &
+         ze3wu, ze3wv,           &  ! temporary scalars
+         zmaxu1, zmaxu2,         &  !    "         "
+         zmaxv1, zmaxv2             !    "         "
+
+      ! Initialization (first time-step only): compute mbatu and mbatv
+      IF( kt == nitend ) THEN
+         mbatu(:,:) = 0
+         mbatv(:,:) = 0
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               mbatu(ji,jj) = MAX( MIN( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1, 2 )
+               mbatv(ji,jj) = MAX( MIN( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1, 2 )
+            END DO
+         END DO
+         ztmpi(:,:) = FLOAT( mbatu(:,:) )
+         ztmpj(:,:) = FLOAT( mbatv(:,:) )
+         ! lateral boundary conditions: T-point, sign unchanged
+         CALL lbc_lnk( ztmpi , 'U', 1.0_wp )
+         CALL lbc_lnk( ztmpj , 'V', 1.0_wp )
+         mbatu(:,:) = MAX( INT( ztmpi(:,:) ), 2 )
+         mbatv(:,:) = MAX( INT( ztmpj(:,:) ), 2 )
+      ENDIF
+      ! 1. Direct model recomputation
+      ! Interpolation of T and S at the last ocean level
+# if defined key_vectopt_loop  
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
+# else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+# endif
+            ! last level
+            iku = mbatu(ji,jj)
+            ikv = mbatv(ji,jj)
+
+            ze3wu  = fse3w(ji+1,jj  ,iku) - fse3w(ji,jj,iku)
+            ze3wv  = fse3w(ji  ,jj+1,ikv) - fse3w(ji,jj,ikv)
+            zmaxu1 =  ze3wu / fse3w(ji+1,jj  ,iku)
+            zmaxu2 = -ze3wu / fse3w(ji  ,jj  ,iku)
+            zmaxv1 =  ze3wv / fse3w(ji  ,jj+1,ikv)
+            zmaxv2 = -ze3wv / fse3w(ji  ,jj  ,ikv)
+
+            ! i- direction
+
+            IF( ze3wu >= 0. ) THEN      ! case 1
+               ! interpolated values of T and S
+               zti(ji,jj) = ptem(ji+1,jj,iku)       &
+                  &       + zmaxu1 * ( ptem(ji+1,jj,iku-1) - ptem(ji+1,jj,iku) )
+               zsi(ji,jj) = psal(ji+1,jj,iku)       &
+                  &       + zmaxu1 * ( psal(ji+1,jj,iku-1) - psal(ji+1,jj,iku) )
+               ! depth of the partial step level
+               zhgi(ji,jj) = fsdept(ji,jj,iku)
+            ELSE                        ! case 2
+               ! interpolated values of T and S
+               zti(ji,jj) = ptem(ji,jj,iku)         &
+                  &       + zmaxu2 * ( ptem(ji,jj,iku-1) - ptem(ji,jj,iku) )
+               zsi(ji,jj) = psal(ji,jj,iku) + zmaxu2 * ( psal(ji,jj,iku-1) - psal(ji,jj,iku) )
+               ! depth of the partial step level
+               zhgi(ji,jj) = fsdept(ji+1,jj,iku)
+            ENDIF
+
+            ! j- direction
+
+            IF( ze3wv >= 0. ) THEN      ! case 1
+               ! interpolated values of T and S
+               ztj(ji,jj) = ptem(ji,jj+1,ikv)       &
+                  &       + zmaxv1 * ( ptem(ji,jj+1,ikv-1) - ptem(ji,jj+1,ikv) )
+               zsj(ji,jj) = psal(ji,jj+1,ikv)       &
+                  &       + zmaxv1 * ( psal(ji,jj+1,ikv-1) - psal(ji,jj+1,ikv) )
+               ! depth of the partial step level
+               zhgj(ji,jj) = fsdept(ji,jj,ikv) 
+            ELSE                        ! case 2
+               ! interpolated values of T and S
+               ztj(ji,jj) = ptem(ji,jj,ikv)         &
+                  &       + zmaxv2 * ( ptem(ji,jj,ikv-1) - ptem(ji,jj,ikv) )
+               zsj(ji,jj) = psal(ji,jj,ikv)         &
+                  &       + zmaxv2 * ( psal(ji,jj,ikv-1) - psal(ji,jj,ikv) ) 
+               ! depth of the partial step level
+               zhgj(ji,jj) = fsdept(ji,jj+1,ikv) 
+            ENDIF
+# if ! defined key_vectopt_loop  
+         END DO
+# endif
+      END DO
+
+      !2. Adjoint model counterpart
+      ztiad = 0.0_wp ; ztjad = 0.0_wp ; zsiad = 0.0_wp
+      zsjad = 0.0_wp ; zriad = 0.0_wp ; zrjad = 0.0_wp
+
+      ! Lateral boundary conditions on each gradient
+      CALL lbc_lnk_adj( pgtu_ad , 'U', -1.0_wp )  ;  CALL lbc_lnk_adj( pgtv_ad , 'V', -1.0_wp )
+      CALL lbc_lnk_adj( pgsu_ad , 'U', -1.0_wp )  ;  CALL lbc_lnk_adj( pgsv_ad , 'V', -1.0_wp )
+      CALL lbc_lnk_adj( pgru_ad , 'U', -1.0_wp )  ;  CALL lbc_lnk_adj( pgrv_ad , 'V', -1.0_wp )
+
+      ! Gradient of density at the last level 
+# if defined key_vectopt_loop  
+         jj = 1
+         DO ji = jpij-jpi, -1    ! vector opt. (forced unrolled)
+# else
+      DO jj = jpjm1, 1, -1
+         DO ji = jpim1, 1, -1
+# endif
+            iku = mbatu(ji,jj)
+            ikv = mbatv(ji,jj)
+            ze3wu  = fse3w(ji+1,jj  ,iku) - fse3w(ji,jj,iku)
+            ze3wv  = fse3w(ji  ,jj+1,ikv) - fse3w(ji,jj,ikv)
+            IF( ze3wv >= 0. ) THEN    ! j-direction: case 1
+               zrjad(ji,jj)        = zrjad(ji,jj)                     &
+                  &                + pgrv_ad(ji,jj) * vmask(ji,jj,1)
+               prd_ad(ji,jj,ikv)   = prd_ad(ji,jj,ikv)                &
+                  &                - pgrv_ad(ji,jj) * vmask(ji,jj,1)
+               pgrv_ad(ji,jj)      = 0.0_wp
+            ELSE                      ! j-direction: case 2
+               prd_ad(ji,jj+1,ikv) = prd_ad(ji,jj+1,ikv)            &
+                  &                + pgrv_ad(ji,jj) * vmask(ji,jj,1)
+               zrjad(ji,jj)        = zrjad(ji,jj)                     &
+                  &                - pgrv_ad(ji,jj) * vmask(ji,jj,1)
+               pgrv_ad(ji,jj)      = 0.0_wp
+            ENDIF
+            IF( ze3wu >= 0. ) THEN    ! i-direction: case 1
+               zriad(ji,jj)        = zriad(ji,jj)                     &
+                  &                + pgru_ad(ji,jj) * umask(ji,jj,1)
+               prd_ad(ji,jj,iku)   = prd_ad(ji,jj,iku)                &
+                  &                - pgru_ad(ji,jj) * umask(ji,jj,1)
+               pgru_ad(ji,jj)      = 0.0_wp
+            ELSE                      ! i-direction: case 2
+               prd_ad(ji+1,jj,iku) = prd_ad(ji+1,jj,iku)            &
+                  &                + pgru_ad(ji,jj) * umask(ji,jj,1)
+               zriad(ji,jj)        = zriad(ji,jj)                   &
+                  &                - pgru_ad(ji,jj) * umask(ji,jj,1)
+               pgru_ad(ji,jj)      = 0.0_wp
+            ENDIF
+
+# if ! defined key_vectopt_loop   
+         END DO
+# endif
+      END DO
+
+
+      ! Compute interpolated rd from zti, zsi, ztj, zsj for the 2 cases at the depth of the partial
+      ! step and store it in  zri, zrj for each  case
+      CALL eos_adj( ztj, zsj, zhgj, ztjad, zsjad, zrjad )
+      CALL eos_adj( zti, zsi, zhgi, ztiad, zsiad, zriad )
+
+
+# if defined key_vectopt_loop  
+         jj = 1
+         DO ji = jpij-jpi, 1, -1   ! vector opt. (forced unrolled)
+# else
+      DO jj = jpjm1, 1, -1
+         DO ji = jpim1, 1, -1
+# endif
+            ! last level
+            iku = mbatu(ji,jj)
+            ikv = mbatv(ji,jj)
+
+            ze3wu  = fse3w(ji+1,jj  ,iku) - fse3w(ji,jj,iku)
+            ze3wv  = fse3w(ji  ,jj+1,ikv) - fse3w(ji,jj,ikv)
+            zmaxu1 =  ze3wu / fse3w(ji+1,jj  ,iku)
+            zmaxu2 = -ze3wu / fse3w(ji  ,jj  ,iku)
+            zmaxv1 =  ze3wv / fse3w(ji  ,jj+1,ikv)
+            zmaxv2 = -ze3wv / fse3w(ji  ,jj  ,ikv)
+
+            ! j- direction
+
+            IF( ze3wv >= 0. ) THEN      ! case 1
+               ! gradient of T and S
+               ztjad(ji,jj)           = ztjad(ji,jj)                &
+                  &                   + pgtv_ad(ji,jj) * vmask(ji,jj,1)
+               ptem_ad(ji,jj,ikv)     = ptem_ad(ji,jj,ikv)          &
+                  &                   - pgtv_ad(ji,jj) * vmask(ji,jj,1)
+               pgtv_ad(ji,jj)         = 0.0_wp
+
+               zsjad(ji,jj)           = zsjad(ji,jj)                &
+                  &                   + pgsv_ad(ji,jj) * vmask(ji,jj,1)
+               psal_ad(ji,jj,ikv)     = psal_ad(ji,jj,ikv)          &
+                  &                   - pgsv_ad(ji,jj) * vmask(ji,jj,1)
+               pgsv_ad(ji,jj)         = 0.0_wp
+               ! interpolated values of T and S
+               ptem_ad(ji,jj+1,ikv)   = ptem_ad(ji,jj+1,ikv)        &
+                  &                   + ztjad(ji,jj) * (1 - zmaxv1)
+               ptem_ad(ji,jj+1,ikv-1) = ptem_ad(ji,jj+1,ikv-1)      &
+                  &                   + ztjad(ji,jj)* zmaxv1
+               ztjad(ji,jj)           = 0.0_wp
+
+               psal_ad(ji,jj+1,ikv)   = psal_ad(ji,jj+1,ikv)        &
+                  &                   + zsjad(ji,jj) * (1 - zmaxv1)
+               psal_ad(ji,jj+1,ikv-1) = psal_ad(ji,jj+1,ikv-1)      &
+                  &                   + zsjad(ji,jj) * zmaxv1 
+               zsjad(ji,jj)           = 0.0_wp
+            ELSE                        ! case 2
+                ! gradient of T and S
+               ptem_ad(ji,jj+1,ikv)   = ptem_ad(ji,jj+1,ikv)        &
+                  &                   + pgtv_ad(ji,jj) * vmask(ji,jj,1) 
+               ztjad(ji,jj)           = ztjad(ji,jj)                &
+                  &                   - pgtv_ad(ji,jj) * vmask(ji,jj,1) 
+               pgtv_ad(ji,jj)         = 0.0_wp
+
+               psal_ad(ji,jj+1,ikv)   = psal_ad(ji,jj+1,ikv)        &
+                  &                   + pgsv_ad(ji,jj) * vmask(ji,jj,1) 
+               zsjad(ji,jj)           = zsjad(ji,jj)                &
+                  &                   - pgsv_ad(ji,jj) * vmask(ji,jj,1) 
+               pgsv_ad(ji,jj)         = 0.0_wp
+              ! interpolated values of T and S
+               ptem_ad(ji,jj,ikv)     = ptem_ad(ji,jj,ikv)          &
+                  &                   + ztjad(ji,jj) * (1 - zmaxv2)
+               ptem_ad(ji,jj,ikv-1)   = ptem_ad(ji,jj,ikv-1)        &
+                  &                   + ztjad(ji,jj) * zmaxv2
+               ztjad(ji,jj)           = 0.0_wp
+
+               psal_ad(ji,jj,ikv)     = psal_ad(ji,jj,ikv)          &
+                  &                   + zsjad(ji,jj) * (1 - zmaxv2) 
+               psal_ad(ji,jj,ikv-1)   = psal_ad(ji,jj,ikv-1)        &
+                  &                   + zsjad(ji,jj) * zmaxv2
+               zsjad(ji,jj)           = 0.0_wp
+            ENDIF
+
+            ! i- direction
+
+            IF( ze3wu >= 0. ) THEN      ! case 1
+               ! gradient of T and S
+               ztiad(ji,jj)       = ztiad(ji,jj)                    &
+                  &               + pgtu_ad(ji,jj) * umask(ji,jj,1)
+               ptem_ad(ji,jj,iku) = ptem_ad(ji,jj,iku)              &
+                  &               - pgtu_ad(ji,jj) * umask(ji,jj,1)
+               pgtu_ad(ji,jj)     = 0.0_wp
+
+               zsiad(ji,jj)       = zsiad(ji,jj)                    &
+                  &               + pgsu_ad(ji,jj) * umask(ji,jj,1)
+               psal_ad(ji,jj,iku) = psal_ad(ji,jj,iku)              &
+                  &               - pgsu_ad(ji,jj) * umask(ji,jj,1)
+               pgsu_ad(ji,jj)     = 0.0_wp
+               ! interpolated values of T and S
+               ptem_ad(ji+1,jj,iku)   = ptem_ad(ji+1,jj,iku)        &
+                  &                   + ztiad(ji,jj) * (1 - zmaxu1)
+               ptem_ad(ji+1,jj,iku-1) = ptem_ad(ji+1,jj,iku-1)      &
+                  &                   + ztiad(ji,jj) * zmaxu1 
+               ztiad(ji,jj)           = 0.0_wp
+
+               psal_ad(ji+1,jj,iku)   = psal_ad(ji+1,jj,iku)        &
+                  &                   + zsiad(ji,jj) * (1 - zmaxu1)
+               psal_ad(ji+1,jj,iku-1) = psal_ad(ji+1,jj,iku-1)      &
+                  &                   + zsiad(ji,jj) * zmaxu1
+               zsiad(ji,jj)           = 0.0_wp
+
+            ELSE                        ! case 2
+              ! gradient of T and S 
+               ptem_ad(ji+1,jj,iku)   = ptem_ad(ji+1,jj,iku)        &
+                  &                   + pgtu_ad(ji,jj) * umask(ji,jj,1)
+               ztiad (ji,jj)          = ztiad (ji,jj)               &
+                  &                   - pgtu_ad(ji,jj) * umask(ji,jj,1)
+               pgtu_ad(ji,jj)         = 0.0_wp
+
+               psal_ad(ji+1,jj,iku)   = psal_ad(ji+1,jj,iku)        &
+                  &                   + pgsu_ad(ji,jj) * umask(ji,jj,1)
+               zsiad (ji,jj)          = zsiad (ji,jj)               &
+                  &                   - pgsu_ad(ji,jj) * umask(ji,jj,1)
+               pgsu_ad(ji,jj)         = 0.0_wp
+              ! interpolated values of T and S
+               ptem_ad(ji,jj,iku)     = ptem_ad(ji,jj,iku)          &
+                  &                   + ztiad(ji,jj) * (1 - zmaxu2)
+               ptem_ad(ji,jj,iku-1)   = ptem_ad(ji,jj,iku-1)        &
+                  &                   + ztiad(ji,jj) * zmaxu2
+               ztiad(ji,jj)           = 0.0_wp
+
+               psal_ad(ji,jj,iku)     = psal_ad(ji,jj,iku)          &
+                  &                   + zsiad(ji,jj) * (1 - zmaxu2)
+               psal_ad(ji,jj,iku-1)   = psal_ad(ji,jj,iku-1)        &
+                  &                   + zsiad(ji,jj) * zmaxu2
+               zsiad(ji,jj)           = 0.0_wp
+            ENDIF
+
+# if ! defined key_vectopt_loop  
+         END DO
+# endif
+      END DO
+
+   END SUBROUTINE zps_hde_adj
+   SUBROUTINE zps_hde_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_adv_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      INTEGER :: &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk,    & 
+         & kt
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+ 
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & ztem,         & ! Direct field : temperature
+         & zsal,         & ! Direct field : salinity
+         & ztem_tlin,    & ! Tangent input: temperature
+         & zsal_tlin,    & ! Tangent input: salinity
+         & zrd_tlin,     & ! Tangent input:
+         & ztem_adout,   & ! Adjoint output: temperature
+         & zsal_adout,   & ! Adjoint output: salinity
+         & zrd_adout,    & ! Adjoint output: 
+         & zar,          & ! 3D random field for rd
+         & zat,          & ! 3D random field for t
+         & zas             ! 3D random field for s
+         
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zgtu_tlout,   & ! Tangent output: horizontal gradient
+         & zgtv_tlout,   & ! Tangent output: horizontal gradient
+         & zgsu_tlout,   & ! Tangent output: horizontal gradient
+         & zgsv_tlout,   & ! Tangent output: horizontal gradient
+         & zgru_tlout,   & ! Tangent output: horizontal gradient
+         & zgrv_tlout,   & ! Tangent output: horizontal gradient
+         & zgtu_adin,    & ! Adjoint input : horizontal gradient
+         & zgtv_adin,    & ! Adjoint input : horizontal gradient
+         & zgsu_adin,    & ! Adjoint input : horizontal gradient
+         & zgsv_adin,    & ! Adjoint input : horizontal gradient
+         & zgru_adin,    & ! Adjoint input : horizontal gradient
+         & zgrv_adin       ! Adjoint input : horizontal gradient
+
+      REAL(KIND=wp) :: &
+                           ! random field standard deviation for:
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_1,       & !   scalar product components
+         & zsp1_2,       & 
+         & zsp1_3,       & !   scalar product components
+         & zsp1_4,       & 
+         & zsp1_5,       & !   scalar product components
+         & zsp1_6,       & 
+         & zsp2,         & ! scalar product involving the adjoint routine
+         & zsp2_1,       & !   scalar product components
+         & zsp2_2,       & 
+         & zsp2_3
+      CHARACTER (LEN=14) :: &
+         & cl_name
+
+      kt = nit000
+      ! Allocate memory
+      ALLOCATE( &
+         & ztem(jpi,jpj,jpk),         & 
+         & zsal(jpi,jpj,jpk),         & 
+         & ztem_tlin(jpi,jpj,jpk),    & 
+         & zsal_tlin(jpi,jpj,jpk),    & 
+         & zrd_tlin(jpi,jpj,jpk),     & 
+         & ztem_adout(jpi,jpj,jpk),   & 
+         & zsal_adout(jpi,jpj,jpk),   & 
+         & zrd_adout(jpi,jpj,jpk),    & 
+         & zar(jpi,jpj,jpk),          & 
+         & zat(jpi,jpj,jpk),          & 
+         & zas(jpi,jpj,jpk),          &       
+         & zgtu_tlout(jpi,jpj),       & 
+         & zgtv_tlout(jpi,jpj),       & 
+         & zgsu_tlout(jpi,jpj),       & 
+         & zgsv_tlout(jpi,jpj),       & 
+         & zgru_tlout(jpi,jpj),       & 
+         & zgrv_tlout(jpi,jpj),       & 
+         & zgtu_adin(jpi,jpj),        & 
+         & zgtv_adin(jpi,jpj),        & 
+         & zgsu_adin(jpi,jpj),        & 
+         & zgsv_adin(jpi,jpj),        & 
+         & zgru_adin(jpi,jpj),        & 
+         & zgrv_adin(jpi,jpj)         &    
+         & ) 
+      ! Initialize random field standard deviationsthe reference state
+      ztem = tn
+      zsal = sn
+ 
+      !=============================================================
+      ! 1) dx = ( T ) and dy = ( T )
+      !=============================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      ztem_tlin(:,:,:)  = 0.0_wp     
+      zsal_tlin(:,:,:)  = 0.0_wp     
+      zrd_tlin(:,:,:)   = 0.0_wp     
+      ztem_adout(:,:,:) = 0.0_wp    
+      zsal_adout(:,:,:) = 0.0_wp    
+      zrd_adout(:,:,:)  = 0.0_wp    
+      zgtu_tlout(:,:)   = 0.0_wp    
+      zgtv_tlout(:,:)   = 0.0_wp    
+      zgsu_tlout(:,:)   = 0.0_wp    
+      zgsv_tlout(:,:)   = 0.0_wp    
+      zgru_tlout(:,:)   = 0.0_wp    
+      zgrv_tlout(:,:)   = 0.0_wp    
+      zgtu_adin(:,:)    = 0.0_wp     
+      zgtv_adin(:,:)    = 0.0_wp     
+      zgsu_adin(:,:)    = 0.0_wp     
+      zgsv_adin(:,:)    = 0.0_wp     
+      zgru_adin(:,:)    = 0.0_wp     
+      zgrv_adin(:,:)    = 0.0_wp         
+      
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 456953 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zat, 'T', 0.0_wp, stdt )
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 526791 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zas, 'T', 0.0_wp, stds )
+      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 395703 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zar, 'T', 0.0_wp, stdr )
+ 
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               ztem_tlin(ji,jj,jk) = zat(ji,jj,jk)
+               zsal_tlin(ji,jj,jk) = zas(ji,jj,jk)
+               zrd_tlin( ji,jj,jk) = zar(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      CALL zps_hde_tan ( kt, ztem      , zsal      ,               &
+         &                   ztem_tlin , zsal_tlin , zrd_tlin  ,   &
+         &                   zgtu_tlout, zgsu_tlout, zgru_tlout,   &
+         &                   zgtv_tlout, zgsv_tlout, zgrv_tlout     )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            jk = mbatu(ji,jj)
+            zgtu_adin(ji,jj) = zgtu_tlout(ji,jj) &
+               &             * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+               &             * umask(ji,jj,jk)
+            zgsu_adin(ji,jj) = zgsu_tlout(ji,jj) &
+               &             * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+               &             * umask(ji,jj,jk)
+            zgru_adin(ji,jj) = zgru_tlout(ji,jj) &
+               &             * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+               &             * umask(ji,jj,jk)
+            jk = mbatv(ji,jj)
+            zgtv_adin(ji,jj) = zgtv_tlout(ji,jj) &
+               &             * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+               &             * vmask(ji,jj,jk)
+            zgsv_adin(ji,jj) = zgsv_tlout(ji,jj) &
+               &             * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+               &             * vmask(ji,jj,jk)
+            zgrv_adin(ji,jj) = zgrv_tlout(ji,jj) &
+               &             * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+               &             * vmask(ji,jj,jk)
+         END DO
+      END DO
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1_1 = DOT_PRODUCT( zgtu_adin, zgtu_tlout )
+      zsp1_2 = DOT_PRODUCT( zgsu_adin, zgsu_tlout )
+      zsp1_3 = DOT_PRODUCT( zgru_adin, zgru_tlout )
+      zsp1_4 = DOT_PRODUCT( zgtv_adin, zgtv_tlout )
+      zsp1_5 = DOT_PRODUCT( zgsv_adin, zgsv_tlout )
+      zsp1_6 = DOT_PRODUCT( zgrv_adin, zgrv_tlout )
+      zsp1 = zsp1_1 + zsp1_2 + zsp1_3 + zsp1_4 + zsp1_5 + zsp1_6
+
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+      CALL zps_hde_adj ( kt, ztem      , zsal      ,               &
+         &                   ztem_adout, zsal_adout, zrd_adout ,   &
+         &                   zgtu_adin , zgsu_adin , zgru_adin ,   &
+         &                   zgtv_adin , zgsv_adin , zgrv_adin      )
+      zsp2_1 = DOT_PRODUCT( ztem_tlin, ztem_adout )
+      zsp2_2 = DOT_PRODUCT( zsal_tlin, zsal_adout )
+      zsp2_3 = DOT_PRODUCT( zrd_tlin , zrd_adout  )
+      zsp2   = zsp2_1 + zsp2_2 + zsp2_3
+
+      ! Compare the scalar products
+
+      cl_name = 'zps_hde_adj   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      ! Deallocate memory
+      DEALLOCATE( &
+         & ztem,         & 
+         & zsal,         & 
+         & ztem_tlin,    & 
+         & zsal_tlin,    & 
+         & zrd_tlin,     & 
+         & ztem_adout,   & 
+         & zsal_adout,   & 
+         & zrd_adout,    & 
+         & zar,          & 
+         & zat,          & 
+         & zas,          &       
+         & zgtu_tlout,   & 
+         & zgtv_tlout,   & 
+         & zgsu_tlout,   & 
+         & zgsv_tlout,   & 
+         & zgru_tlout,   & 
+         & zgrv_tlout,   & 
+         & zgtu_adin,    & 
+         & zgtv_adin,    & 
+         & zgsu_adin,    & 
+         & zgsv_adin,    & 
+         & zgru_adin,    & 
+         & zgrv_adin     &    
+         & ) 
+
+
+      
+   END SUBROUTINE zps_hde_adj_tst
+#if defined key_tst_tlm
+   SUBROUTINE zps_hde_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_adv_tlm_tst ***
+      !!
+      !! ** Purpose : Test the adjoint 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 :
+      !!        ! 09-08 (A. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE zpshde
+      USE oce_tam,        ONLY: &
+        & gtu_tl, gtv_tl,       &
+        & gsu_tl, gsv_tl,       &
+        & gru_tl, grv_tl,       &
+        & tn_tl, sn_tl, rhd_tl
+      USE tamtrj              ! writing out state trajectory
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE divcur             ! horizontal divergence and relative vorticity
+      USE sshwzv             !  vertical velocity
+      USE gridrandom, ONLY: &
+        & grid_rd_sd
+      USE trj_tam
+      USE oce           , ONLY: & ! ocean dynamics and tracers variables
+        & tn, sn, rhd,          &
+        & gtu, gtv, gsu, gsv,   &
+        & gru, grv
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER :: &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk   
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & ztem,         & ! Direct field : temperature
+         & zsal,         & ! Direct field : salinity
+         & ztn_tlin,     & ! Tangent input: temperature
+         & zsn_tlin,     & ! Tangent input: salinity
+         & zrd_tlin,     &
+         & z3r             ! 3D field   
+
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zgtu_out, zgtu_wop,    & ! Tangent output: horizontal gradient
+         & zgtv_out, zgtv_wop,    & ! Tangent output: horizontal gradient
+         & zgsu_out, zgsu_wop,    & ! Tangent output: horizontal gradient
+         & zgsv_out, zgsv_wop,    & ! Tangent output: horizontal gradient
+         & zgru_out, zgru_wop,    & ! Tangent output: horizontal gradient
+         & zgrv_out, zgrv_wop
+
+      REAL(KIND=wp) :: &
+         & zsp1,                 & ! scalar product involving the tangent routine
+         & zsp1_1, zsp1_2,       & 
+         & zsp1_3, zsp1_4,       & 
+         & zsp1_5, zsp1_6,       & 
+         & zsp2,                 & 
+         & zsp2_1, zsp2_2,       & 
+         & zsp2_3, zsp2_4,       & 
+         & zsp2_5, zsp2_6,       & 
+         & zsp3,                 &
+         & zsp3_1, zsp3_2,       & 
+         & zsp3_3, zsp3_4,       & 
+         & zsp3_5, zsp3_6,       & 
+         & zzsp,                 & 
+         & zzsp_1, zzsp_2,       & 
+         & zzsp_3, zzsp_4,       & 
+         & zzsp_5, zzsp_6,       &
+         & gamma,                &
+         & zgsp1, zgsp2,         &
+         & zgsp3, zgsp4,         &
+         & zgsp5, zgsp6,         &
+         & zgsp7
+      CHARACTER(LEN=14)   :: cl_name
+      CHARACTER (LEN=128) :: file_out, file_wop, file_xdx
+      CHARACTER (LEN=90)  ::  FMT
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zscgtu, zscgtv, zscgsu,    &
+         & zscgsv, zscgru, zscgrv,    &
+         & zscerrgtu, zscerrgtv,      &
+         & zscerrgsu, zscerrgsv,      &
+         & zscerrgru, zscerrgrv
+      INTEGER, DIMENSION(100):: &
+         & iiposgtu, iiposgtv, iiposgsu,   &
+         & iiposgsv, iiposgru, iiposgrv,   &
+         & ijposgtu, ijposgtv, ijposgsu,   &
+         & ijposgsv, ijposgru, ijposgrv  
+      INTEGER::             &
+         & ii,              &
+         & isamp=40,        &
+         & jsamp=40,        &
+         & numsctlm
+     REAL(KIND=wp), DIMENSION(jpi,jpj) :: &
+         & zerrgtu, zerrgtv, zerrgsu,     &
+         & zerrgsv, zerrgru, zerrgrv  
+      ! Allocate memory
+
+      ALLOCATE( &
+         & ztem(jpi,jpj,jpk),       & 
+         & zsal(jpi,jpj,jpk),       & 
+         & ztn_tlin(jpi,jpj,jpk),   & 
+         & zsn_tlin(jpi,jpj,jpk),   & 
+         & zrd_tlin(jpi,jpj,jpk),   &   
+         & z3r     (jpi,jpj,jpk),   &       
+         & zgtu_out(jpi,jpj),       & 
+         & zgtv_out(jpi,jpj),       & 
+         & zgsu_out(jpi,jpj),       & 
+         & zgsv_out(jpi,jpj),       & 
+         & zgru_out(jpi,jpj),       & 
+         & zgrv_out(jpi,jpj),       &
+         & zgtu_wop(jpi,jpj),       & 
+         & zgtv_wop(jpi,jpj),       & 
+         & zgsu_wop(jpi,jpj),       & 
+         & zgsv_wop(jpi,jpj),       & 
+         & zgru_wop(jpi,jpj),       & 
+         & zgrv_wop(jpi,jpj)        &
+         & ) 
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      ztn_tlin(:,:,:) = 0.0_wp     
+      zsn_tlin(:,:,:) = 0.0_wp     
+      zrd_tlin(:,:,:) = 0.0_wp         
+      zgtu_out(:,:)   = 0.0_wp    
+      zgtv_out(:,:)   = 0.0_wp    
+      zgsu_out(:,:)   = 0.0_wp    
+      zgsv_out(:,:)   = 0.0_wp    
+      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    
+      gsu_tl(:,:)     = 0.0_wp    
+      gsv_tl(:,:)     = 0.0_wp    
+      gru_tl(:,:)     = 0.0_wp    
+      grv_tl(:,:)     = 0.0_wp 
+      ENDIF
+      zscgtu(:)         = 0.0_wp
+      zscgtv(:)         = 0.0_wp
+      zscgsu(:)         = 0.0_wp
+      zscgsv(:)         = 0.0_wp
+      zscgru(:)         = 0.0_wp
+      zscgrv(:)         = 0.0_wp
+      zscerrgtu(:)      = 0.0_wp
+      zscerrgtv(:)      = 0.0_wp
+      zscerrgsu(:)      = 0.0_wp
+      zscerrgsv(:)      = 0.0_wp
+      zscerrgru(:)      = 0.0_wp
+      zscerrgrv(:)      = 0.0_wp
+      zerrgtu(:,:)      = 0.0_wp
+      zerrgtv(:,:)      = 0.0_wp
+      zerrgsu(:,:)      = 0.0_wp
+      zerrgsv(:,:)      = 0.0_wp
+      zerrgru(:,:)      = 0.0_wp
+      zerrgrv(:,:)      = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Output filename Xn=F(X0)
+      !--------------------------------------------------------------------
+!!!!      CALL tlm_namrd
+      gamma = h_ratio
+      file_wop='trj_wop_zps'
+      file_xdx='trj_xdx_zps'
+      !--------------------------------------------------------------------
+      ! 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, z3r,  'T', 0.0_wp, stdt)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  ztn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 523432, z3r,  'T', 0.0_wp, stds)
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL grid_rd_sd( 432545, z3r,  'T', 0.0_wp, stdr) 
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zrd_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      ENDIF 
+      !--------------------------------------------------------------------
+      ! Complete Init for Direct
+      !-------------------------------------------------------------------
+      IF ( tlm_bch /= 2 )  CALL istate_p  
+      ! *** initialize the reference trajectory
+      ! ------------
+      CALL  trj_rea( nit000-1, 1 )
+      CALL  trj_rea( nit000, 1 )
+
+      IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+         ztn_tlin(:,:,:) = gamma * ztn_tlin(:,:,:)
+         tn(:,:,:)       = tn(:,:,:) + ztn_tlin(:,:,:)
+
+         zsn_tlin(:,:,:) = gamma * zsn_tlin(:,:,:)
+         sn(:,:,:)       = sn(:,:,:) + zsn_tlin(:,:,:)
+
+         zrd_tlin(:,:,:) = gamma * zrd_tlin(:,:,:)
+         rhd(:,:,:)       = rhd(:,:,:) + zrd_tlin(:,:,:)
+      ENDIF     
+      !--------------------------------------------------------------------
+      !  Compute the direct model F(X0,t=n) = Xn
+      !--------------------------------------------------------------------
+      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 ( tlm_bch == 2 ) THEN
+         !--------------------------------------------------------------------
+         ! Initialize the tangent variables:
+         !--------------------------------------------------------------------
+         CALL  trj_rea( nit000-1, 1 ) 
+         CALL  trj_rea( nit000, 1 ) 
+         tn_tl  (:,:,:)  = ztn_tlin  (:,:,:)
+         sn_tl  (:,:,:)  = zsn_tlin  (:,:,:)
+         rhd_tl  (:,:,:) = zrd_tlin  (:,:,:)
+         CALL zps_hde_tan(nit000, tn  , sn       ,            &
+         &                   ztn_tlin , zsn_tlin , zrd_tlin,  &
+         &                   gtu_tl, gsu_tl, gru_tl,          &
+         &                   gtv_tl, gsv_tl, grv_tl           )
+
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L(t0,tn) gamma dx0 ) )
+         !--------------------------------------------------------------------
+
+         zsp2_1    = DOT_PRODUCT( gtu_tl, gtu_tl  )
+         zsp2_2    = DOT_PRODUCT( gtv_tl, gtv_tl  )
+         zsp2_3    = DOT_PRODUCT( gsu_tl, gsu_tl  )
+         zsp2_4    = DOT_PRODUCT( gsv_tl, gsv_tl  )
+         zsp2_5    = DOT_PRODUCT( gru_tl, gru_tl  )
+         zsp2_6    = DOT_PRODUCT( grv_tl, grv_tl  )
+
+         zsp2      = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4 + zsp2_5 + zsp2_6
+         !--------------------------------------------------------------------
+         !  Storing data
+         !--------------------------------------------------------------------
+
+         CALL trj_rd_spl(file_wop) 
+         zgtu_wop  (:,:) = gtu  (:,:)
+         zgtv_wop  (:,:) = gtv  (:,:)
+         zgsu_wop  (:,:) = gsu  (:,:)
+         zgsv_wop  (:,:) = gsv  (:,:)
+         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 
+         ! 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
+               zgtu_out   (ji,jj) = zgtu_out (ji,jj) - zgtu_wop  (ji,jj)
+               zgtu_wop   (ji,jj) = zgtu_out (ji,jj) - gtu_tl    (ji,jj)
+               IF (  gtu_tl(ji,jj) .NE. 0.0_wp ) &
+                  & zerrgtu(ji,jj) = zgtu_out(ji,jj)/gtu_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0) ) THEN
+                   ii = ii+1
+                   iiposgtu(ii) = ji
+                   ijposgtu(ii) = jj
+                   IF ( INT(umask(ji,jj,1)) .NE. 0)  THEN
+                      zscgtu (ii) =  zgtu_wop(ji,jj)
+                      zscerrgtu (ii) =  ( zerrgtu(ji,jj) - 1.0_wp ) /gamma
+                   ENDIF
+               ENDIF
+            END DO
+         END DO
+         ii=0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zgtv_out   (ji,jj) = zgtv_out (ji,jj) - zgtv_wop  (ji,jj)
+               zgtv_wop   (ji,jj) = zgtv_out (ji,jj) - gtv_tl    (ji,jj)
+               IF (  gtv_tl(ji,jj) .NE. 0.0_wp ) &
+                  & zerrgtv(ji,jj) = zgtv_out(ji,jj)/gtv_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0) ) THEN
+                   ii = ii+1
+                   iiposgtv(ii) = ji
+                   ijposgtv(ii) = jj
+                   IF ( INT(vmask(ji,jj,1)) .NE. 0)  THEN
+                      zscgtv (ii) =  zgtv_wop(ji,jj)
+                      zscerrgtv (ii) =  ( zerrgtv(ji,jj) - 1.0_wp ) / gamma
+                   ENDIF
+               ENDIF
+            END DO
+         END DO
+         ii=0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zgsu_out   (ji,jj) = zgsu_out (ji,jj) - zgsu_wop  (ji,jj)
+               zgsu_wop   (ji,jj) = zgsu_out (ji,jj) - gsu_tl    (ji,jj)
+               IF (  gsu_tl(ji,jj) .NE. 0.0_wp ) &
+                  & zerrgsu(ji,jj) = zgsu_out(ji,jj)/gsu_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0) ) THEN
+                   ii = ii+1
+                   iiposgsu(ii) = ji
+                   ijposgsu(ii) = jj
+                   IF ( INT(umask(ji,jj,1)) .NE. 0)  THEN
+                      zscgsu (ii) =  zgsu_wop(ji,jj)
+                      zscerrgsu (ii) =  ( zerrgsu(ji,jj) - 1.0_wp ) /gamma
+                   ENDIF
+               ENDIF
+            END DO
+         END DO
+         ii=0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zgsv_out   (ji,jj) = zgsv_out (ji,jj) - zgsv_wop  (ji,jj)
+               zgsv_wop   (ji,jj) = zgsv_out (ji,jj) - gsv_tl    (ji,jj)
+               IF (  gtv_tl(ji,jj) .NE. 0.0_wp ) &
+                  & zerrgsv(ji,jj) = zgsv_out(ji,jj)/gsv_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0) ) THEN
+                   ii = ii+1
+                   iiposgsv(ii) = ji
+                   ijposgsv(ii) = jj
+                   IF ( INT(vmask(ji,jj,1)) .NE. 0)  THEN
+                      zscgsv (ii) =  zgsv_wop(ji,jj)
+                      zscerrgsv (ii) =  ( zerrgsv(ji,jj) - 1.0_wp ) /gamma
+                   ENDIF
+               ENDIF
+            END DO
+         END DO
+         ii=0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zgru_out   (ji,jj) = zgru_out (ji,jj) - zgru_wop  (ji,jj)
+               zgru_wop   (ji,jj) = zgru_out (ji,jj) - gru_tl    (ji,jj)
+               IF (  gru_tl(ji,jj) .NE. 0.0_wp ) &
+                  & zerrgru(ji,jj) = zgru_out(ji,jj)/gru_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0) ) THEN
+                   ii = ii+1
+                   iiposgru(ii) = ji
+                   ijposgru(ii) = jj
+                   IF ( INT(umask(ji,jj,1)) .NE. 0)  THEN
+                      zscgru (ii) =  zgru_wop(ji,jj)
+                      zscerrgru (ii) =  ( zerrgru(ji,jj) - 1.0_wp ) /gamma
+                   ENDIF
+               ENDIF
+            END DO
+         END DO
+         ii=0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zgrv_out   (ji,jj) = zgrv_out (ji,jj) - zgrv_wop  (ji,jj)
+               zgrv_wop   (ji,jj) = zgrv_out (ji,jj) - grv_tl    (ji,jj)
+               IF (  grv_tl(ji,jj) .NE. 0.0_wp ) &
+                  & zerrgrv(ji,jj) = zgrv_out(ji,jj)/grv_tl(ji,jj)
+               IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+               &   (MOD(jj, jsamp) .EQ. 0) ) THEN
+                   ii = ii+1
+                   iiposgrv(ii) = ji
+                   ijposgrv(ii) = jj
+                   IF ( INT(vmask(ji,jj,1)) .NE. 0)  THEN
+                      zscgrv (ii) =  zgrv_wop(ji,jj)
+                      zscerrgrv (ii) =  ( zerrgrv(ji,jj) - 1.0_wp ) / gamma
+                   ENDIF
+               ENDIF
+            END DO
+         END DO
+         zsp1_1    = DOT_PRODUCT( zgtu_out, zgtu_out  )
+         zsp1_2    = DOT_PRODUCT( zgtv_out, zgtv_out  )
+         zsp1_3    = DOT_PRODUCT( zgsu_out, zgsu_out  )
+         zsp1_4    = DOT_PRODUCT( zgsv_out, zgsv_out  )
+         zsp1_5    = DOT_PRODUCT( zgru_out, zgru_out  )
+         zsp1_6    = DOT_PRODUCT( zgrv_out, zgrv_out  )
+         zsp1      = zsp1_1 + zsp1_2 + zsp1_3 + zsp1_4 + zsp1_5 + zsp1_6
+         zsp3_1    = DOT_PRODUCT( zgtu_wop, zgtu_wop  )
+         zsp3_2    = DOT_PRODUCT( zgtv_wop, zgtv_wop  )
+         zsp3_3    = DOT_PRODUCT( zgsu_wop, zgsu_wop  )
+         zsp3_4    = DOT_PRODUCT( zgsv_wop, zgsv_wop  )
+         zsp3_5    = DOT_PRODUCT( zgru_wop, zgru_wop  )
+         zsp3_6    = DOT_PRODUCT( zgrv_wop, zgrv_wop  )
+         zsp3      = zsp3_1 + zsp3_2 + zsp3_3 + zsp3_4 + zsp3_5 + zsp3_6
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name = 'zps_tam:En '
+         zzsp    = SQRT(zsp3)
+         zzsp_1  = SQRT(zsp3_1)
+         zzsp_2  = SQRT(zsp3_2)
+         zzsp_3  = SQRT(zsp3_3)
+         zzsp_4  = SQRT(zsp3_4)
+         zzsp_5  = SQRT(zsp3_5)
+         zzsp_6  = SQRT(zsp3_6)
+         zgsp5   = zzsp
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp    = SQRT(zsp2)
+         zzsp_1  = SQRT(zsp2_1)
+         zzsp_2  = SQRT(zsp2_2)
+         zzsp_3  = SQRT(zsp2_3)
+         zzsp_4  = SQRT(zsp2_4)
+         zzsp_5  = SQRT(zsp2_5)
+         zzsp_6  = SQRT(zsp2_6)
+         zgsp4   = zzsp
+         cl_name = 'zps_tam:Ln2'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         zzsp     = SQRT(zsp1)
+         zzsp_1   = SQRT(zsp1_1)
+         zzsp_2   = SQRT(zsp1_2)
+         zzsp_3   = SQRT(zsp1_3)
+         zzsp_4   = SQRT(zsp1_4)
+         zzsp_5   = SQRT(zsp1_5)
+         zzsp_6   = SQRT(zsp1_6)
+         cl_name  = 'zpshde:Mhdx-Mx'
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         zgsp3    = SQRT( zsp3/zsp2 )
+         zgsp7    = zgsp3/gamma
+         zgsp1    = zzsp
+         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) 'zpshde  ', 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 = 'zpshde  '
+         IF (lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zscgtu(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscgtu    ', &
+                    & cur_loop, h_ratio, ii, iiposgtu(ii), ijposgtu(ii), zscgtu(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscgtv(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscgtv    ', &
+                    & cur_loop, h_ratio, ii, iiposgtv(ii), ijposgtv(ii), zscgtv(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscgsu(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscgsu    ', &
+                    & cur_loop, h_ratio, ii, iiposgsu(ii), ijposgsu(ii), zscgsu(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscgsv(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscgsv    ', &
+                    & cur_loop, h_ratio, ii, iiposgsv(ii), ijposgsv(ii), zscgsv(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscgru(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscgru    ', &
+                    & cur_loop, h_ratio, ii, iiposgru(ii), ijposgru(ii), zscgru(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscgrv(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscgrv    ', &
+                    & cur_loop, h_ratio, ii, iiposgrv(ii), ijposgrv(ii), zscgrv(ii)
+            ENDDO
+            ! write separator
+            WRITE(numtan_sc,"(A4)") '===='
+         ENDIF
+      ENDIF
+      DEALLOCATE(              &
+         & ztem, zsal,         & 
+         & ztn_tlin, zsn_tlin, & 
+         & zrd_tlin, zgtu_out, & 
+         & zgtv_out, zgsu_out, & 
+         & zgsv_out, zgru_out, & 
+         & zgrv_out,           &
+         & z3r                 &
+         & ) 
+   END SUBROUTINE zps_hde_tlm_tst
+   !!======================================================================
+#endif
+#endif
+END MODULE zpshde_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/ZDF/zdfkpp_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/ZDF/zdfkpp_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/ZDF/zdfkpp_tam.F90	(revision 2578)
@@ -0,0 +1,333 @@
+MODULE zdfkpp_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                       ***  MODULE  zdfkpp_tam  ***
+   !! Ocean physics:  vertical mixing coefficient compute from the KPP 
+   !!                 turbulent closure parameterization
+   !!                 Tangent and Adjoint Module
+   !!=====================================================================
+   !! History of the direct module:
+   !!            8.1  ! 2000-03 (W.G. Large, J. Chanut) Original code
+   !!            8.1  ! 2002-06 (J.M. Molines) for real case CLIPPER  
+   !!            8.2  ! 2003-10 (Chanut J.) re-writting
+   !!            9.0  ! 2005-01 (C. Ethe) Free form, F90
+   !!                 ! 2008-07 (M. Balmaseda). Add parameteres to namelist
+   !! History of the TAM:
+   !!                 ! 2008-06 (A. Vidard) skeleton TAM of the 05-01 version
+   !!                 ! 2008-11 (A. Vidard) skeleton TAM of the 08-07 version
+   !!    NEMO         ! 2010-04 (F. Vigilant) converison to 3.2
+   !!----------------------------------------------------------------------
+#if defined key_zdfkpp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_zdfkpp'                                             KPP scheme
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   zdf_kpp      : update momentum and tracer Kz from a kpp scheme
+   !!   zdf_kpp_init : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and active tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE zdf_oce         ! ocean vertical physics
+   USE phycst          ! physical constants
+   USE eosbn2          ! equation of state
+   USE sbc_oce         ! thermohaline fluxes
+   USE zdfddm          ! double diffusion mixing
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   zdf_kpp_tan   ! routine called by steptan.F90
+   PUBLIC   tra_kpp_tan   ! routine called by steptan.F90
+   PUBLIC   zdf_kpp_adj   ! routine called by stepadj.F90
+   PUBLIC   tra_kpp_adj   ! routine called by stepadj.F90
+
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfkpp = .TRUE.    !: KPP vertical mixing flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   ghats   !: non-local scalar mixing term (gamma/<ws>o)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   & 
+      wt0                   ,  &  !: surface temperature flux for non local flux
+      ws0                   ,  &  !: surface salinity flux for non local flux
+      hkpp                        !: boundary layer depht
+
+   INTEGER ::                  & !!! ** kpp namelist (namkpp) **
+      nn_ave  =  1            ,  &  ! = 0/1 flag for horizontal average on avt, avmu, avmv
+
+   REAL(wp) ::                 & !!! ** Interior Mixing 
+      difmiw  = 1.2e-04_wp  ,  &  ! constant internal wave viscosity (m2/s)
+      difsiw  = 1.2e-05_wp  ,  &  ! constant internal wave diffusivity (m2/s)
+      Riinfty = 0.8_wp      ,  &  ! local Richardson Number limit for shear instability
+      difri   = 5.e-03_wp   ,  &  ! maximum shear mixing at Rig = 0    (m2/s)
+      bvsqcon = -1.e-09_wp  ,  &  ! Brunt-Vaisala squared (1/s**2) for maximum convection
+      difcon  = 1._wp             ! maximum mixing in interior convection (m2/s)
+#if defined key_zdfddm
+   REAL(wp) ::                 & !!! ** Double diffusion Mixing
+      difssf  = 1.e-03_wp   ,  &  ! maximum salt fingering mixing  (nmlst)
+      Rrho0   = 1.9_wp      ,  &  ! limit for salt  fingering mixing 
+      difsdc  = 1.5e-06_wp  ,  &  ! maximum diffusive convection mixing (nmlst)
+      rdifst  = 0.7_wp            ! ration salt/Temp diff if salt fingering 
+#endif
+   LOGICAL  ::                 &
+      ln_kpprimix  = .TRUE.       ! Shear instability mixing 
+
+   REAL(wp) ::                 & !!! ** General constants  **
+      epsln   = 1.0e-20_wp   , &  ! a small positive number    
+      pthird  = 1._wp/3._wp  , &  ! 1/3
+      pfourth = 1._wp/4._wp       ! 1/4
+
+   REAL(wp) ::                 & !!! ** Boundary Layer Turbulence Parameters  **
+      vonk     = 0.4_wp     ,  &  ! von Karman's constant
+      epsilon  = 0.1_wp     ,  &  ! nondimensional extent of the surface layer
+      rconc1   = 5.0_wp     ,  &  ! standard flux profile function parmaeters
+      rconc2   = 16.0_wp    ,  &  !         "        "
+      rconcm   = 8.38_wp    ,  &  ! momentum flux profile fit
+      rconam   = 1.26_wp    ,  &  !         "       "
+      rzetam   = -.20_wp    ,  &  !         "       "       
+      rconcs   = 98.96_wp   ,  &  !  scalar  flux profile fit
+      rconas   = -28.86_wp  ,  &  !         "       "
+      rzetas   = -1.0_wp          !         "       "  
+   REAL(wp) ::                 & !!! ** Boundary Layer Depth Diagnostic  **
+      Ricr     = 0.3_wp     ,  &  ! critical bulk Richardson Number
+      rcekman  = 0.7_wp     ,  &  ! coefficient for ekman depth  
+      rcmonob  = 1.0_wp     ,  &  ! coefficient for Monin-Obukhov depth 
+      rconcv   = 1.7_wp     ,  &  ! ratio of interior buoyancy frequency to buoyancy frequency at entrainment depth (namelist)
+      hbf      = 1.0_wp     ,  &  ! fraction of bound. layer depth to which absorbed solar 
+      !                           ! rad. and contributes to surf. buo. forcing
+      Vtc                         ! function of rconcv,rconcs,epsilon,vonk,Ricr
+   REAL(wp) ::                 & !!! ** Nonlocal Boundary Layer Mixing **
+      rcstar   = 5.0_wp     ,  &  ! coefficient for convective nonlocal transport
+      rcs      = 1.0e-3_wp  ,  &  ! conversion: mm/s ==> m/s   
+      rcg                         ! non-dimensional coefficient for nonlocal transport
+
+#if ! defined key_kppcustom
+   REAL(wp), DIMENSION(jpk,jpk) ::   & 
+      del                         ! array for reference mean values of vertical integration 
+#endif
+
+#if defined key_kpplktb
+   INTEGER, PARAMETER ::       & !!! ** Parameters for lookup table for turbulent velocity scales ** 
+      nilktb   = 892        ,  &  ! number of values for zehat in KPP lookup table
+      njlktb   = 482        ,  &  ! number of values for ustar in KPP lookup table
+      nilktbm1 = nilktb - 1 ,  &  !
+      njlktbm1 = njlktb - 1       !
+
+   REAL(wp), DIMENSION(nilktb,njlktb) ::  &
+      wmlktb                ,  &  ! lookup table for the turbulent vertical velocity scale for momentum
+      wslktb                       ! lookup table for the turbulent vertical velocity scale for tracers
+
+   REAL(wp) ::                 &
+      dehatmin = -4.e-7_wp  ,  &  ! minimum limit for zhat in lookup table (m3/s3) 
+      dehatmax = 0._wp      ,  &  ! maximum limit for zhat in lookup table (m3/s3)
+      ustmin   = 0._wp      ,  &  ! minimum limit for ustar in lookup table (m/s)
+      ustmax   = 0.04_wp    ,  &  ! maximum limit for ustar in lookup table (m/s)    
+      dezehat               ,  &  ! delta zhat in lookup table
+      deustar                     ! delta ustar in lookup table
+#endif
+   REAL(wp), DIMENSION(jpk) :: &  !!! attenuation coef  
+      ratt        
+   !! already defines in module traqsr, but only if the solar radiation penetration is considered
+   REAL(wp) ::                 & !!! * penetrative solar radiation coefficient *
+      rabs = 0.58_wp        ,  &  ! fraction associated with xsi1
+      xsi1 = 0.35_wp        ,  &  ! first depth of extinction 
+      xsi2 = 23.0_wp              ! second depth of extinction 
+      !                           ! (default values: water type Ib) 
+
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+      etmean                ,  &  ! coefficient used for horizontal smoothing
+      eumean                ,  &  ! at t-, u- and v-points
+      evmean  
+ 
+#if defined key_c1d
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &
+      rig                   ,  &  ! gradient Richardson number
+      rib                   ,  &  ! bulk Richardson number
+      buof                  ,  &  ! buoyancy forcing
+      mols                        ! moning-Obukhov length scale 
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &
+      ekdp                        ! Ekman depth
+#endif
+
+   INTEGER  ::  &                 !
+      jip = 62 , jjp = 111
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE zdf_kpp_tan ( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE zdf_kpp_tan  ***
+      !!
+      !! ** Purpose of thedirect routine:
+      !!      Compute the vertical eddy viscosity and diffusivity
+      !!      coefficients and non local mixing using K-profile parameterization
+      !!
+      !! ** Method :   The boundary layer depth hkpp is diagnosed at tracer points
+      !!      from profiles of buoyancy, and shear, and the surface forcing.
+      !!      Above hbl (sigma=-z/hbl <1) the mixing coefficients are computed from 
+      !!
+      !!                      Kx =  hkpp  Wx(sigma) G(sigma)  
+      !!
+      !!             and the non local term ghat = Cs / Ws(sigma) / hkpp
+      !!      Below hkpp  the coefficients are the sum of mixing due to internal waves
+      !!      shear instability and double diffusion.
+      !!
+      !!      -1- Compute the now interior vertical mixing coefficients at all depths. 
+      !!      -2- Diagnose the boundary layer depth. 
+      !!      -3- Compute the now boundary layer vertical mixing coefficients. 
+      !!      -4- Compute the now vertical eddy vicosity and diffusivity.
+      !!      -5- Smoothing
+      !!
+      !!        N.B. The computation is done from jk=2 to jpkm1 
+      !!             Surface value of avt avmu avmv are set once a time to zero
+      !!             in routine zdf_kpp_init.
+      !!
+      !! ** Action  :   update the non-local terms ghats
+      !!                update avt, avmu, avmv (before vertical eddy coef.)
+      !!
+      !! References : Large W.G., Mc Williams J.C. and Doney S.C.              
+      !!         Reviews of Geophysics, 32, 4, November 1994
+      !!         Comments in the code refer to this paper, particularly 
+      !!         the equation number. (LMD94, here after)
+      !!----------------------------------------------------------------------
+#if defined  key_zdfddm
+      USE oce     , zviscos => ua,      &  ! temp. array for viscosities use ua as workspace
+         &          zdiffut => ta,      &  ! temp. array for diffusivities use sa as workspace
+         &          zdiffus => sa          ! temp. array for diffusivities use sa as workspace
+#else
+      USE oce     , zviscos => ua,      &  ! temp. array for viscosities use ua as workspace
+         &          zdiffut => ta          ! temp. array for diffusivities use sa as workspace
+#endif
+      !!
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+      !!
+
+   END SUBROUTINE zdf_kpp_tan
+
+
+   SUBROUTINE tra_kpp_tan
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_kpp_tan  ***
+      !!
+      !! ** Purpose of the direct routine:   
+      !!      compute and add to the tracer trend the non-local
+      !!      tracer flux
+      !!
+      !! ** Method  :   ???
+      !!
+      !! history or the direct routine:
+      !!     9.0  ! 05-11 (G. Madec)  Original code
+      !! history:
+      !!          ! 08-06 (A. Vidard) 
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE oce, ONLY :    ztrdt => ua,       & ! use ua as 3D workspace
+                         ztrds => va          ! use va as 3D workspace
+      !!----------------------------------------------------------------------
+
+ 
+   END SUBROUTINE tra_kpp_tan
+   SUBROUTINE zdf_kpp_adj ( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE zdf_kpp_adj  ***
+      !!
+      !! ** Purpose of thedirect routine:
+      !!      Compute the vertical eddy viscosity and diffusivity
+      !!      coefficients and non local mixing using K-profile parameterization
+      !!
+      !! ** Method :   The boundary layer depth hkpp is diagnosed at tracer points
+      !!      from profiles of buoyancy, and shear, and the surface forcing.
+      !!      Above hbl (sigma=-z/hbl <1) the mixing coefficients are computed from 
+      !!
+      !!                      Kx =  hkpp  Wx(sigma) G(sigma)  
+      !!
+      !!             and the non local term ghat = Cs / Ws(sigma) / hkpp
+      !!      Below hkpp  the coefficients are the sum of mixing due to internal waves
+      !!      shear instability and double diffusion.
+      !!
+      !!      -1- Compute the now interior vertical mixing coefficients at all depths. 
+      !!      -2- Diagnose the boundary layer depth. 
+      !!      -3- Compute the now boundary layer vertical mixing coefficients. 
+      !!      -4- Compute the now vertical eddy vicosity and diffusivity.
+      !!      -5- Smoothing
+      !!
+      !!        N.B. The computation is done from jk=2 to jpkm1 
+      !!             Surface value of avt avmu avmv are set once a time to zero
+      !!             in routine zdf_kpp_init.
+      !!
+      !! ** Action  :   update the non-local terms ghats
+      !!                update avt, avmu, avmv (before vertical eddy coef.)
+      !!
+      !! References : Large W.G., Mc Williams J.C. and Doney S.C.              
+      !!         Reviews of Geophysics, 32, 4, November 1994
+      !!         Comments in the code refer to this paper, particularly 
+      !!         the equation number. (LMD94, here after)
+      !!----------------------------------------------------------------------
+#if defined  key_zdfddm
+      USE oce     , zviscos => ua,      &  ! temp. array for viscosities use ua as workspace
+         &          zdiffut => ta,      &  ! temp. array for diffusivities use sa as workspace
+         &          zdiffus => sa          ! temp. array for diffusivities use sa as workspace
+#else
+      USE oce     , zviscos => ua,      &  ! temp. array for viscosities use ua as workspace
+         &          zdiffut => ta          ! temp. array for diffusivities use sa as workspace
+#endif
+      !!
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+      !!
+
+   END SUBROUTINE zdf_kpp_adj
+
+
+   SUBROUTINE tra_kpp_adj
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_kpp_adj  ***
+      !!
+      !! ** Purpose :   compute and add to the tracer trend the non-local
+      !!      tracer flux
+      !!
+      !! ** Method  :   ???
+      !!
+      !! history :
+      !!     9.0  ! 05-11 (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE oce, ONLY :    ztrdt => ua,       & ! use ua as 3D workspace
+                         ztrds => va          ! use va as 3D workspace
+      !!----------------------------------------------------------------------
+
+ 
+   END SUBROUTINE tra_kpp_adj
+
+
+ 
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                                        NO KPP scheme
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfkpp = .FALSE.   !: KPP flag
+CONTAINS
+   SUBROUTINE zdf_kpp_tan( kt )          ! Empty routine
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+      WRITE(*,*) 'zdf_kpp_tan: You should not have seen this print! error?', kt
+   END SUBROUTINE zdf_kpp_tan
+   SUBROUTINE tra_kpp_tan( kt )          ! Empty routine
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+      WRITE(*,*) 'tra_kpp_tan: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_kpp_tan
+   SUBROUTINE zdf_kpp_adj( kt )          ! Empty routine
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+      WRITE(*,*) 'zdf_kpp_adj: You should not have seen this print! error?', kt
+   END SUBROUTINE zdf_kpp_adj
+   SUBROUTINE tra_kpp_adj( kt )          ! Empty routine
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+      WRITE(*,*) 'tra_kpp_adj: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_kpp_adj
+#endif
+
+   !!======================================================================
+#endif
+END MODULE zdfkpp_tam
+
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/cla_div_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/cla_div_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/cla_div_tam.F90	(revision 2578)
@@ -0,0 +1,957 @@
+MODULE cla_div_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                    ***  MODULE  cla_div_tam  ***
+   !! Ocean diagnostic variable : specific update of the horizontal divergence
+   !!                             CAUTION: Specific to ORCA_R2
+   !!                             Tangent and adjoint module
+   !!==============================================================================
+#  if defined key_orca_r2
+   !!----------------------------------------------------------------------
+   !!   'key_orca_r2'                                 global ocean model R2
+   !!----------------------------------------------------------------------
+   !!   div_cla      : 
+   !!   div_bab_el_mandeb
+   !!   div_gibraltar
+   !!   div_hormuz
+   !!   div_cla_init :
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind,       ONLY: & ! Precision variables
+      & wp
+   USE par_oce,        ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk,                 & 
+      & jpiglo
+   USE oce_tam,        ONLY: & ! ocean dynamics and tracers
+      & hdivn_tl,            &
+      & hdivn_ad
+   USE sbc_oce_tam,    ONLY: & ! surface variables
+      & emp_tl,              &
+      & emp_ad
+   USE dom_oce,        ONLY: & ! ocean space and time domain
+      & mi0,                 &
+      & mi1,                 &
+      & mj0,                 &
+      & mj1,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      & rdt,                 &
+      & tmask,               &
+      & mig,                 &
+      & mjg,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e1t,                 &
+      & e2t,                 &
+# if defined key_vvl
+      & e3t_1,               &
+# else
+#  if defined key_zco
+      & e3t_0,               &
+#  else
+      & e3t,                 &
+#  endif
+# endif
+# if defined key_zco
+      & e3t_0,               &
+# else
+      & e3u,                 &
+      & e3v
+# endif
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & nit000
+   USE phycst,         ONLY: & ! Physical constants
+      & rau0
+   USE lib_mpp,        ONLY: & ! distributed memory computing library
+      & lk_mpp,              &
+      & mpp_sum
+   USE lbclnk,         ONLY: & ! ocean lateral boundary conditions (or mpp link)
+      & lbc_lnk
+   USE lbclnk_tam,     ONLY: & ! ocean lateral boundary conditions (or mpp link)
+      & lbc_lnk_adj
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE gridrandom,     ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE tstool_tam,     ONLY: &
+      & prntst_adj,          & !
+      & stdemp,              & ! stdev for evaporation minus precip
+      & stdh                   !           hdiv
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Module variables
+   REAL(wp) :: zempmed_tl, zempred_tl       ! EMP of Mediterranean and Red Sea 
+   REAL(wp) :: zempmed_ad, zempred_ad       ! EMP of Mediterranean and Red Sea 
+   !! * Routine accessibility
+   PUBLIC div_cla_tan     ! routine called by step_tam.F90
+   PUBLIC div_cla_adj     ! routine called by step_tam.F90
+   PUBLIC div_cla_adj_tst ! routine called by tst.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE div_cla_tan ( kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE div_cla_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      update the horizontal divergence of the velocity field
+      !!      for at some straits ( Gibraltar, Bab el Mandeb and Hormuz ).
+      !!
+      !! ** Method  :   With imposed transport at each strait, we compute 
+      !!      corresponding velocities and update horizontal divergence.
+      !!        Apply lateral boundary conditions on hdivn through a call
+      !!      to routine lbc_lnk.
+      !!
+      !! ** Action  :   update hdivn array : the now horizontal divergence
+      !!
+      !! History of the direct routine:
+      !!   8.5  !  02-11 (A. Bozec)  Free form, F90
+      !! History of the TAM routine:
+      !!   9.0  !  08-06 (A. Vidard) Skeleton
+      !!   9.0  !  08-09 (A. Vidard) tangent of the 02-11 version
+      !!   9.0  !  09-02 (A. Vidard) cosmetic changes
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      !!----------------------------------------------------------------------
+      ! Correction of the Divergence at some straits
+            
+      CALL div_bab_el_mandeb_tan                    ! New divergence at Bab el Mandeb 
+
+      CALL div_gibraltar_tan                        ! New divergence at Gibraltar
+
+      CALL div_hormuz_tan                           ! Hormuz Strait ( persian Gulf)
+
+      ! Lateral boundary conditions on hdivn
+      CALL lbc_lnk( hdivn_tl, 'T', 1.0_wp )
+
+
+   END SUBROUTINE div_cla_tan
+
+   SUBROUTINE div_cla_adj ( kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE div_cla_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      update the horizontal divergence of the velocity field
+      !!      for at some straits ( Gibraltar, Bab el Mandeb and Hormuz ).
+      !!
+      !! ** Method  :   With imposed transport at each strait, we compute 
+      !!      corresponding velocities and update horizontal divergence.
+      !!        Apply lateral boundary conditions on hdivn through a call
+      !!      to routine lbc_lnk.
+      !!
+      !! ** Action  :   update hdivn array : the now horizontal divergence
+      !!
+      !! History of the direct routine:
+      !!   8.5  !  02-11 (A. Bozec)  Free form, F90
+      !! History of the TAM routine:
+      !!   9.0  !  08-06 (A. Vidard) Skeleton
+      !!   9.0  !  08-09 (A. Vidard) adjoint of the 02-11 version
+      !!   9.0  !  09-02 (A. Vidard) cosmetic changes
+     !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      !!----------------------------------------------------------------------
+      ! Correction of the Divergence at some straits
+
+      ! Lateral boundary conditions on hdivn
+      CALL lbc_lnk_adj( hdivn_ad, 'T', 1.0_wp )
+
+      CALL div_hormuz_adj                           ! Hormuz Strait ( persian Gulf)
+
+      CALL div_gibraltar_adj                        ! New divergence at Gibraltar
+
+      CALL div_bab_el_mandeb_adj                    ! New divergence at Bab el Mandeb 
+
+   END SUBROUTINE div_cla_adj
+
+   SUBROUTINE div_bab_el_mandeb_tan
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE div_bab_el_mandeb_tan  ***
+      !!       
+      !! ** Purpose of the direct routine:
+      !!     Update  the now horizontal divergence of the velocity 
+      !!     field in Bab el Mandeb ( Red Sea strait ).
+      !!
+      !! ** Method of the direct routine:
+      !!     Set the velocity field at each side of the strait :
+      !!                                          |
+      !!            |/ \|            N          |\ /|
+      !!            |_|_|______      |          |___|______
+      !!        88  |   |<-       W - - E    88 |   |<-
+      !!        87  |___|______      |       87 |___|->____
+      !!             160 161         S           160 161 
+      !!       horizontal view                horizontal view
+      !!          surface                        depth
+      !!      The now divergence is given by :
+      !!         hdivn = 1/(e1t*e2t) [ di(e2u  un) + dj(e1v  vn) ]
+      !!
+      !! ** History of the direct routine:
+      !!           !         (A. Bozec) Original code 
+      !!      8.5  !  02-11  (A. Bozec) F90: Free form and module
+      !! ** History of the tangent routine:
+      !!           !  08-09  (A. Vidard) Tangent linear of the 02-11 version
+      !!      9.0  !  09-02 (A. Vidard) cosmetic changes
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER  :: ji, jj, jk   ! dummy loop indices
+      REAL(wp) :: zsu, zvt, zwei   ! temporary scalar
+      REAL(wp), DIMENSION (jpk) ::  zu1_rs_tl, zu2_rs_tl, zu3_rs_tl
+      !!---------------------------------------------------------------------
+      
+      ! EMP on the Red Sea 
+      ! ------------------
+
+      zempred_tl = 0.e0
+      zwei = 0.e0
+      DO jj = mj0(87), mj1(96)
+         DO ji = mi0(148), mi1(160) 
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempred_tl = zempred_tl + emp_tl(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempred_tl )      ! sum with other processors value
+
+
+      ! convert in m3
+      zempred_tl = zempred_tl * 1.e-3         
+
+      ! Velocity profile at each point
+      ! ------------------------------
+
+      zu1_rs_tl(:) = 0.0_wp
+      zu2_rs_tl(:) = 0.0_wp
+      zu3_rs_tl(:) = 0.0_wp
+
+      ! velocity profile at 161,88 North point 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1,  8                                      
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu1_rs_tl(jk) = zu1_rs_tl(jk) - ( zempred_tl / 8. ) / ( e2u(ji, jj) * fse3u(ji, jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      ! velocity profile at 160,88 North  point
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1,  10                                     
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu3_rs_tl(jk) = zu3_rs_tl(jk) + ( zempred_tl / 10. ) / ( e1v(ji, jj) * fse3v(ji, jj,jk) )
+            END DO
+         END DO
+      END DO
+       
+      ! Divergence at each point of the straits
+      ! ---------------------------------------
+
+      ! compute the new divergence at 161,88 
+      DO jk = 1, 21
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji-1, jj) * fse3u(ji-1, jj,jk)
+               hdivn_tl(ji, jj  ,jk) = hdivn_tl(ji, jj  ,jk) - ( 1. / zvt ) * zsu * zu1_rs_tl(jk)
+            END DO
+         END DO
+      END DO
+
+      ! compute the new divergence at 161,87 
+      DO jk = 1, 21
+         DO jj = mj0(87), mj1(87) 
+            DO ji = mi0(161), mi1(161) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji-1, jj) * fse3u(ji-1, jj,jk)
+               hdivn_tl(ji, jj,jk) = hdivn_tl(ji, jj,jk) - ( 1. / zvt ) * zsu * zu2_rs_tl(jk)
+            END DO
+         END DO
+      END DO
+
+      ! compute the divergence at 160,89 
+      DO jk = 1, 18
+         DO jj = mj0(89), mj1(89) 
+            DO ji = mi0(160), mi1(160) 
+               zvt = e1t(ji, jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e1v(ji, jj-1) * fse3v(ji, jj-1,jk)
+               hdivn_tl(ji, jj,jk) = hdivn_tl(ji, jj,jk) - ( 1. / zvt ) * zsu * zu3_rs_tl(jk)
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE div_bab_el_mandeb_tan
+
+
+   SUBROUTINE div_bab_el_mandeb_adj
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE div_bab_el_mandeb_adj  ***
+      !!       
+      !! ** Purpose of the direct routine:
+      !!     Update  the now horizontal divergence of the velocity 
+      !!     field in Bab el Mandeb ( Red Sea strait ).
+      !!
+      !! ** Method of the direct routine:
+      !!     Set the velocity field at each side of the strait :
+      !!                                          |
+      !!            |/ \|            N          |\ /|
+      !!            |_|_|______      |          |___|______
+      !!        88  |   |<-       W - - E    88 |   |<-
+      !!        87  |___|______      |       87 |___|->____
+      !!             160 161         S           160 161 
+      !!       horizontal view                horizontal view
+      !!          surface                        depth
+      !!      The now divergence is given by :
+      !!         hdivn = 1/(e1t*e2t) [ di(e2u  un) + dj(e1v  vn) ]
+      !!
+      !! ** History of the direct routine:
+      !!           !         (A. Bozec) Original code 
+      !!      8.5  !  02-11  (A. Bozec) F90: Free form and module
+      !! ** History of the adjoint routine:
+      !!           !  08-09  (A. Vidard) Adjoint of the 02-11 version
+      !!      9.0  !  09-02 (A. Vidard) cosmetic changes
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER  :: ji, jj, jk   ! dummy loop indices
+      REAL(wp) :: zsu, zvt, zwei   ! temporary scalar
+      REAL(wp), DIMENSION (jpk) ::  zu1_rs_ad, zu2_rs_ad, zu3_rs_ad
+      !!---------------------------------------------------------------------
+      
+      zempred_ad = 0.e0
+      zu1_rs_ad(:) = 0.0_wp
+      zu2_rs_ad(:) = 0.0_wp
+      zu3_rs_ad(:) = 0.0_wp
+      zwei = 0.e0
+       
+      ! Divergence at each point of the straits
+      ! ---------------------------------------
+
+      ! compute the divergence at 160,89 
+      DO jk = 18, 1, -1
+         DO jj = mj0(89), mj1(89) 
+            DO ji = mi0(160), mi1(160) 
+               zvt = e1t(ji, jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e1v(ji, jj-1) * fse3v(ji, jj-1,jk)
+               zu3_rs_ad(jk) = zu3_rs_ad(jk) - hdivn_ad(ji, jj,jk) * ( 1. / zvt ) * zsu 
+            END DO
+         END DO
+      END DO
+
+      ! compute the new divergence at 161,87 
+      DO jk = 21, 1, -1
+         DO jj = mj0(87), mj1(87) 
+            DO ji = mi0(161), mi1(161) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji-1, jj) * fse3u(ji-1, jj,jk)
+               zu2_rs_ad(jk) = zu2_rs_ad(jk) - hdivn_ad(ji, jj,jk) * ( 1. / zvt ) * zsu
+            END DO
+         END DO
+      END DO
+
+      ! compute the new divergence at 161,88 
+      DO jk = 21, 1, -1
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji-1, jj) * fse3u(ji-1, jj,jk)
+               zu1_rs_ad(jk) = zu1_rs_ad(jk) - hdivn_ad(ji, jj  ,jk) * ( 1. / zvt ) * zsu
+            END DO
+         END DO
+      END DO
+
+      ! Velocity profile at each point
+      ! ------------------------------
+
+      ! velocity profile at 160,88 North  point
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 10, 1, -1                                     
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160)
+               zempred_ad = zempred_ad + ( zu3_rs_ad(jk) / 10. ) / ( e1v(ji, jj) * fse3v(ji, jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      ! velocity profile at 161,88 North point 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 8, 1, -1     
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zempred_ad = zempred_ad - ( zu1_rs_ad(jk) / 8. ) / ( e2u(ji, jj) * fse3u(ji, jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      zu1_rs_ad(:) = 0.0_wp
+      zu2_rs_ad(:) = 0.0_wp
+      zu3_rs_ad(:) = 0.0_wp
+
+      ! EMP on the Red Sea 
+      ! ------------------
+
+      ! convert in m3
+      zempred_ad = zempred_ad * 1.e-3         
+
+      IF( lk_mpp )   CALL mpp_sum( zempred_ad )      ! sum with other processors value
+
+      DO jj = mj1(96), mj0(87), -1
+         DO ji = mi1(160),  mi0(148), -1
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            emp_ad(ji,jj) = emp_ad(ji,jj) + zempred_ad * zwei
+         END DO
+      END DO
+      zempred_ad = 0.e0
+
+   END SUBROUTINE div_bab_el_mandeb_adj
+
+   SUBROUTINE div_gibraltar_tan
+      !! -------------------------------------------------------------------
+      !!                 ***  ROUTINE div_gibraltar_tan  ***
+      !!        
+      !! ** Purpose of the direct routine:
+      !!     update the now horizontal divergence of the velocity 
+      !!     field in Gibraltar.
+      !!
+      !! ** Method of the direct routine:
+      !!          ________________      N        ________________
+      !! 102           |    |->         |           <-|    |<-
+      !! 101      ___->|____|_____   W - - E     ___->|____|_____
+      !!           139   140  141       |         139   140  141
+      !!          horizontal view       S        horizontal view
+      !!            surface                          depth
+      !!      The now divergence is given by :
+      !!         hdivn = 1/(e1t*e2t) [ di(e2u  un) + dj(e1v  vn) ]
+      !!
+      !! ** History of the direct routine:
+      !!           !         (A. Bozec) Original code 
+      !!      8.5  !  02-10  (A. Bozec) F90: Free form and module
+      !! ** History of the tangent routine:
+      !!           !  08-09  (A. Vidard) Tangent linear of the 02-10 version
+      !!      9.0  !  09-02 (A. Vidard) cosmetic changes
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER  :: ji, jj, jk   ! dummy loop indices
+      REAL(wp) :: zsu, zvt
+      REAL(wp) :: zwei
+      REAL(wp), DIMENSION (jpk) ::  zu1_ms_tl, zu2_ms_tl, zu3_ms_tl
+      !!---------------------------------------------------------------------
+      
+      ! EMP on the Mediterranean Sea 
+      ! ----------------------------
+
+      zempmed_tl = 0.e0
+      zwei = 0.e0
+      DO jj = mj0(96), mj1(110)
+         DO ji = mi0(141),mi1(181)
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempmed_tl = zempmed_tl + emp_tl(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempmed_tl )      ! sum with other processors value
+
+      ! minus 2 points in Red Sea and 3 in Atlantic 
+      DO jj = mj0(96), mj1(96)
+         DO ji = mi0(148),mi1(148)
+            zempmed_tl = zempmed_tl -  emp_tl(ji  , jj) * tmask(ji  , jj,1) * e1t(ji  , jj) * e2t(ji  , jj)   &
+                              -  emp_tl(ji+1, jj) * tmask(ji+1, jj,1) * e1t(ji+1, jj) * e2t(ji+1, jj)   
+         END DO
+      END DO
+
+      ! convert in m3
+      zempmed_tl = zempmed_tl * 1.e-3
+
+      ! Velocity profile at each point
+      ! ------------------------------
+
+      zu1_ms_tl(:) = 0.0_wp
+      zu2_ms_tl(:) = 0.0_wp
+      zu3_ms_tl(:) = 0.0_wp
+
+      ! velocity profile at 139,101 South point 
+      ! we imposed zisw + EMP above the Mediterranean Sea 
+      DO jk = 1, 14                      
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu1_ms_tl(jk) =  zu1_ms_tl(jk) + ( zempmed_tl / 14. ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,jk) ) 
+            END DO
+         END DO
+      END DO
+      
+      ! velocity profile at 141,102  East point
+      ! flux in surface inflow of the Atlantic ocean + EMP   
+      DO  jk = 1, 14                     
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu3_ms_tl(jk) = zu3_ms_tl(jk) +  ( zempmed_tl / 14. ) / ( e2u(ji, jj) * fse3u(ji, jj,jk) ) 
+            END DO
+         END DO
+      END DO
+     
+      ! Divergence at each point of the straits
+      ! ---------------------------------------
+
+      ! compute the new divergence at 139,101 South point  
+      DO jk = 1, jpk
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji, jj) * fse3u(ji, jj,jk)
+               hdivn_tl(ji, jj,jk) = hdivn_tl(ji, jj,jk) + ( 1. / zvt ) * zsu * zu1_ms_tl(jk) 
+            END DO
+         END DO
+      END DO
+
+      ! compute the new divergence at 139,102 deep North point
+      DO jk = 1, jpk
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(139), mi1(139) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji, jj) * fse3u(ji, jj,jk)
+               hdivn_tl(ji, jj,jk) = hdivn_tl(ji, jj,jk) + ( 1. / zvt ) * zsu * zu2_ms_tl(jk) 
+            END DO
+         END DO
+      END DO
+
+      ! compute the divergence at 141,102 East point
+      DO jk = 1, jpk
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(141), mi1(141) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji-1, jj) * fse3u(ji-1, jj,jk)
+               hdivn_tl(ji, jj,jk) = hdivn_tl(ji, jj,jk) - ( 1. / zvt ) * zsu * zu3_ms_tl(jk)
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE div_gibraltar_tan
+
+   SUBROUTINE div_gibraltar_adj
+      !! -------------------------------------------------------------------
+      !!                 ***  ROUTINE div_gibraltar_adj  ***
+      !!        
+      !! ** Purpose of the direct routine:
+      !!     update the now horizontal divergence of the velocity 
+      !!     field in Gibraltar.
+      !!
+      !! ** Method of the direct routine:
+      !!          ________________      N        ________________
+      !! 102           |    |->         |           <-|    |<-
+      !! 101      ___->|____|_____   W - - E     ___->|____|_____
+      !!           139   140  141       |         139   140  141
+      !!          horizontal view       S        horizontal view
+      !!            surface                          depth
+      !!      The now divergence is given by :
+      !!         hdivn = 1/(e1t*e2t) [ di(e2u  un) + dj(e1v  vn) ]
+      !!
+      !! ** History of the direct routine:
+      !!           !         (A. Bozec) Original code 
+      !!      8.5  !  02-10  (A. Bozec) F90: Free form and module
+      !! ** History of the adjoint routine:
+      !!           !  08-09  (A. Vidard) Adjoint of the 02-10 version
+      !!      9.0  !  09-02 (A. Vidard) cosmetic changes
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER  :: ji, jj, jk   ! dummy loop indices
+      REAL(wp) :: zsu, zvt
+      REAL(wp) :: zwei
+      REAL(wp), DIMENSION (jpk) ::  zu1_ms_ad, zu2_ms_ad, zu3_ms_ad
+      !!---------------------------------------------------------------------
+      
+      zu1_ms_ad = 0.0_wp
+      zu2_ms_ad = 0.0_wp
+      zu3_ms_ad = 0.0_wp
+      zempmed_ad = 0.e0
+      zwei = 0.e0
+
+      ! Divergence at each point of the straits
+      ! ---------------------------------------
+
+      ! compute the divergence at 141,102 East point
+      DO jk = jpk, 1, -1
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(141), mi1(141) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji-1, jj) * fse3u(ji-1, jj,jk)
+               zu3_ms_ad(jk) = zu3_ms_ad(jk) - hdivn_ad(ji, jj,jk) * ( 1. / zvt ) * zsu
+            END DO
+         END DO
+      END DO
+
+      ! compute the new divergence at 139,102 deep North point
+      DO jk = jpk, 1, -1
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(139), mi1(139) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji, jj) * fse3u(ji, jj,jk)
+               zu2_ms_ad(jk) =  zu2_ms_ad(jk) + hdivn_ad(ji, jj,jk) * ( 1. / zvt ) * zsu 
+            END DO
+         END DO
+      END DO
+
+      ! compute the new divergence at 139,101 South point  
+      DO jk = jpk, 1, -1
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji, jj) * fse3u(ji, jj,jk)
+               zu1_ms_ad(jk) = zu1_ms_ad(jk) + hdivn_ad(ji, jj,jk) * ( 1. / zvt ) * zsu 
+            END DO
+         END DO
+      END DO
+
+      ! Velocity profile at each point
+      ! ------------------------------
+      
+      ! velocity profile at 141,102  East point
+      ! flux in surface inflow of the Aadantic ocean + EMP   
+      DO  jk = 14, 1, -1                     
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zempmed_ad = zempmed_ad + ( zu3_ms_ad(jk) / 14. ) / ( e2u(ji, jj) * fse3u(ji, jj,jk) ) 
+            END DO
+         END DO
+      END DO
+
+      ! velocity profile at 139,101 South point 
+      ! we imposed zisw + EMP above the Mediterranean Sea 
+      DO jk = 14, 1, -1                      
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zempmed_ad = zempmed_ad + ( zu1_ms_ad(jk) / 14. ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,jk) ) 
+            END DO
+         END DO
+      END DO
+      zu1_ms_ad(:) = 0.0_wp
+      zu2_ms_ad(:) = 0.0_wp
+      zu3_ms_ad(:) = 0.0_wp
+
+      ! EMP on the Mediterranean Sea 
+      ! ----------------------------
+
+      ! convert in m3
+      zempmed_ad = zempmed_ad * 1.e-3
+
+      ! minus 2 points in Red Sea and 3 in Aadantic 
+      DO jj = mj0(96), mj1(96)
+         DO ji = mi0(148),mi1(148)
+            emp_ad(ji  , jj) = emp_ad(ji  , jj) - zempmed_ad * tmask(ji  , jj,1) * e1t(ji  , jj) * e2t(ji  , jj)
+            emp_ad(ji+1, jj) = emp_ad(ji+1, jj) - zempmed_ad * tmask(ji+1, jj,1) * e1t(ji+1, jj) * e2t(ji+1, jj)   
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempmed_ad )      ! sum with other processors value
+
+      DO jj = mj1(110), mj0(96), -1
+         DO ji = mi1(181), mi0(141), -1
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            emp_ad(ji,jj) = emp_ad(ji,jj) + zempmed_ad * zwei
+         END DO
+      END DO
+      zempmed_ad = 0.e0
+
+   END SUBROUTINE div_gibraltar_adj
+
+
+
+   SUBROUTINE div_hormuz_tan
+      !! -------------------------------------------------------------------
+      !!                   ***  ROUTINE div_hormuz_tan  ***
+      !!              
+      !! ** Purpose of the direct routine:
+      !!     update the now horizontal divergence of the velocity 
+      !!     field in Hormuz ( Persic Gulf strait ) .
+      !!
+      !! ** Method  of the direct routine:
+      !!      The now divergence is given by :
+      !!         hdivn = 1/(e1t*e2t) [ di(e2u  un) + dj(e1v  vn) ]
+      !!
+      !! ** History of the direct routine  
+      !!           !         (A. Bozec) Original code 
+      !!      8.5  !  02-10  (A. Bozec) F90: Free form and module
+      !! ** History of the tangent routine:
+      !!           !  08-09  (A. Vidard) Tangent linear of the 02-10 version
+      !!      9.0  !  09-02 (A. Vidard) cosmetic changes
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      !... nothing
+
+   END SUBROUTINE div_hormuz_tan
+   SUBROUTINE div_hormuz_adj
+      !! -------------------------------------------------------------------
+      !!                   ***  ROUTINE div_hormuz_adj  ***
+      !!              
+      !! ** Purpose of the direct routine:
+      !!     update the now horizontal divergence of the velocity 
+      !!     field in Hormuz ( Persic Gulf strait ) .
+      !!
+      !! ** Method  of the direct routine:
+      !!      The now divergence is given by :
+      !!         hdivn = 1/(e1t*e2t) [ di(e2u  un) + dj(e1v  vn) ]
+      !!
+      !! ** History of the direct routine  
+      !!           !         (A. Bozec) Original code 
+      !!      8.5  !  02-10  (A. Bozec) F90: Free form and module
+      !! ** History of the Adjoint routine:
+      !!           !  08-09  (A. Vidard) Adjoint of the 02-10 version
+      !!   9.0     !  09-02 (A. Vidard) cosmetic changes
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      !... nothing
+
+   END SUBROUTINE div_hormuz_adj
+
+   SUBROUTINE div_cla_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_adv_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : Separate tests are applied for the following dx and dy:
+      !!                
+      !!              1) dx = ( SSH ) and dy = ( SSH )
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      INTEGER :: &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk,    &
+         & jt,   &        
+         & jii,  &        
+         & jis,  &        
+         & jji,  &        
+         & jjs     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zhdivn_tlin,   &
+         & zhdivn_tlout,  &
+         & zhdivn_adin,   &
+         & zhdivn_adout,  &
+         & zhdiv
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zemp_tlin,     &
+         & zemp_adout,    &
+         & zemp
+     REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2,         & ! scalar product involving the adjoint routine
+         & zsp2_1,       & !   scalar product components
+         & zsp2_2,       & 
+         & z2dt,         & ! temporary scalars
+         & zraur
+      CHARACTER(LEN=14) :: cl_name
+
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zhdivn_tlin(jpi,jpj,jpk),   &
+         & zhdivn_tlout(jpi,jpj,jpk),  &
+         & zhdivn_adin(jpi,jpj,jpk),   &
+         & zhdivn_adout(jpi,jpj,jpk),  &
+         & zhdiv(jpi,jpj,jpk),         &
+         & zemp_tlin(jpi,jpj),         &
+         & zemp_adout(jpi,jpj),        &
+         & zemp (jpi,jpj)              &
+         & )
+      ! Initialize constants
+
+      z2dt  = 2.0_wp * rdt       ! time step: leap-frog
+      zraur = 1.0_wp / rau0      ! inverse density of pure water (m3/kg)
+      !==================================================================
+      ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and 
+      !    dy = ( hdivb_tl, hdivn_tl )
+      !==================================================================
+
+      DO jt = 2, 1, -1
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      zhdivn_tlin(:,:,:)  = 0.0_wp   
+      zhdivn_tlout(:,:,:) = 0.0_wp
+      zhdivn_adin(:,:,:)  = 0.0_wp 
+      zhdivn_adout(:,:,:) = 0.0_wp
+      zemp_tlin(:,:)      = 0.0_wp
+      zemp_adout(:,:)     = 0.0_wp
+
+      emp_tl(:,:)      = 0.0_wp
+      emp_ad(:,:)      = 0.0_wp
+      hdivn_tl(:,:,:)  = 0.0_wp
+      hdivn_ad(:,:,:)  = 0.0_wp
+
+         SELECT CASE (jt)
+         CASE(1) ! Bab el Madeb
+            jji = mj0(86)
+            jjs = mj1(97)
+            jii = mi0(147)
+            jis = mi1(162)
+         CASE(2) ! Gibraltar
+            jji = mj0(95)
+            jjs = mj1(111)
+            jii = mi0(138)
+            jis = mi1(182)
+         END SELECT
+          
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zemp, 'T', 0.0_wp, stdemp )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 523432 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zhdiv, 'T', 0.0_wp, stdh )
+
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zhdivn_tlin(ji,jj,jk)  = zhdiv(ji,jj,jk)
+            END DO
+         END DO
+      END DO 
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zemp_tlin(ji,jj)      = zemp(ji,jj) / ( z2dt * zraur )
+         END DO
+      END DO 
+!      hdivn_tl(:,:,:)  = zhdivn_tlin(:,:,:)
+!      emp_tl(:,:)      = zemp_tlin(:,:) 
+
+         DO jk = 1, jpk
+            DO jj = jji, jjs
+               DO ji = jii, jis
+                  hdivn_tl(ji,jj,jk)  = zhdivn_tlin(ji,jj,jk)
+                  emp_tl(ji,jj)  = zemp_tlin(ji,jj)
+               END DO
+            END DO
+         END DO
+
+      CALL div_cla_tan( nit000 )
+
+      zhdivn_tlout(:,:,:) = hdivn_tl(:,:,:)
+
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zhdivn_adin(ji,jj,jk) = zhdivn_tlout(ji,jj,jk) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                 &               * tmask(ji,jj,jk)
+              
+            END DO
+         END DO
+      END DO
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1 = DOT_PRODUCT( zhdivn_tlout, zhdivn_adin )
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+      hdivn_ad(:,:,:) = zhdivn_adin(:,:,:)
+
+      CALL div_cla_adj( nit000 )
+
+         DO jk = 1, jpk
+            DO jj = jji, jjs    ! tlin should be 0 outside these boundaries but is not by construction
+               DO ji = jii, jis ! here it would insure that the dot product does not account for it
+                  zhdivn_adout(ji,jj,jk) = hdivn_ad(ji,jj,jk)
+                  zemp_adout(ji,jj) = emp_ad(ji,jj)
+               END DO
+            END DO
+         END DO
+
+!      zhdivn_adout(:,:,:) = hdivn_ad(:,:,:) 
+!      zemp_adout(:,:)     = emp_ad(:,:)
+
+      zsp2_1 = DOT_PRODUCT( zhdivn_tlin, zhdivn_adout )
+      zsp2_2 = DOT_PRODUCT( zemp_tlin,   zemp_adout   )
+      zsp2   = zsp2_1 + zsp2_2 
+
+      ! Compare the scalar products
+
+      ! 14 char:'12345678901234'
+         SELECT CASE (jt)
+         CASE(1) ! Bab el Madeb
+            cl_name = 'div_cla_adj BM'
+         CASE(2) ! Gibraltar
+            cl_name = 'div_cla_adj Gi'
+         END SELECT
+!      cl_name = 'div_cla_adj   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      END DO
+      DEALLOCATE( &
+         & zhdivn_tlin,   &
+         & zhdivn_tlout,  &
+         & zhdivn_adin,   &
+         & zhdivn_adout,  &
+         & zhdiv,         &
+         & zemp_tlin,     &
+         & zemp_adout,    &
+         & zemp           &
+         & )
+
+
+   END SUBROUTINE div_cla_adj_tst
+   !!======================================================================
+#  else
+   !!----------------------------------------------------------------------
+   !!   Default key                                            Dummy module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE div_cla_tan( kt )
+      WRITE(*,*) 'div_cla: You should have not see this print! error?', kt
+   END SUBROUTINE div_cla_tan
+   SUBROUTINE div_cla_adj( kt )
+      WRITE(*,*) 'div_cla_adj: You should have not see this print! error?', kt
+   END SUBROUTINE div_cla_adj
+   SUBROUTINE div_cla_adj_tst( kt )
+      WRITE(*,*) 'div_cla_adj_tst: You should have not see this print! error?', kt
+   END SUBROUTINE div_cla_adj_tst
+#  endif
+#endif
+END MODULE cla_div_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/cla_dynspg_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/cla_dynspg_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/cla_dynspg_tam.F90	(revision 2578)
@@ -0,0 +1,520 @@
+MODULE cla_dynspg_tam
+   !!----------------------------------------------------------------------
+   !!    This software is governed by the CeCILL licence (Version 2)
+   !!----------------------------------------------------------------------
+#if defined key_tam
+   !!======================================================================
+   !!  ***  MODULE  cla_dynspg_tam : TANGENT/ADJOINT OF MODULE cla_dynspg  ***
+   !!
+   !!  Update the momentum trend with the cross land advection from surface 
+   !!  pressure gradient in the free surface constant volume case with 
+   !!  vector optimization.
+   !!                  
+   !!======================================================================
+   !! History of the direct module:
+   !!        !         (A. Bozec)  Original code
+   !!   8.5  !  02-11  (A. Bozec)  F90: Free form and module
+   !! History of the TAM module:
+   !!   9.0  !  09-03  (A. Weaver) Original version
+   !!----------------------------------------------------------------------
+   !!   dyn_spg_cla_tan  : update the momentum trend with the surface pressure
+   !!                      gradient in the free surface constant volume case
+   !!                      with vector optimization (tangent routine)
+   !!   dyn_spg_cla_adj  : update the momentum trend with the surface pressure
+   !!                      gradient in the free surface constant volume case
+   !!                      with vector optimization (adjoint routine)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp,                 &
+      & numout,              &  
+      & nit000,              &
+      & nitend
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & mi0,                 &
+      & mi1,                 &
+      & mj0,                 &
+      & mj1,                 &
+      & e1t,                 &
+      & e2t,                 &
+      & e2u,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3t,                 &
+#endif
+      & tmask
+   USE oce_tam       , ONLY: & ! Tangent-linear and adjoint model variables
+      & ua_tl,               &
+      & va_tl,               &
+      & ua_ad,               &
+      & va_ad
+   USE sbc_oce_tam   , ONLY: & ! Surface BCs for tangent and adjoint model
+      & emp_tl,              &
+      & emp_ad
+   USE lib_mpp       , ONLY: & ! Massively parallel processing library
+      & mpp_sum,             &
+      & lk_mpp
+     
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dyn_spg_cla_tan,   & ! routine called by dyn_spg_tan
+      &   dyn_spg_cla_adj      ! routine called by dyn_spg_adj
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE dyn_spg_cla_tan( kt ) 
+      !!----------------------------------------------------------------------
+      !!              ***  routine dyn_spg_cla_tan  ***
+      !!
+      !! ** Purpose of direct routine :
+      !!
+      !! ** Method of direct routine : 
+      !!
+      !! ** Action :
+      !!
+      !! History
+      !!        !  09-03  (A. Weaver) Original version
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::  &
+         & kt              ! ocean time-step
+
+      !! * Local declarations
+      INTEGER  :: &
+         & ji, &           ! dummy loop indices
+         & jj, &
+         & jk                
+      INTEGER  :: &
+         & ii0, &          ! temporary integers
+         & ii1, &
+         & ij0, &
+         & ij1        
+      REAL(wp) ::  &    
+         & zempmed, &      ! EMP on Med Sea ans Red Sea
+         & zempred, &                
+         & zwei,    &                            !              
+         & zisw_rs, &      ! imposed transport Red sea
+         & zurw_rs, &
+         & zbrw_rs, &    
+         & zisw_ms, &      ! imposed transport Med Sea
+         & zurw_ms, &      
+         & zbrw_ms, &
+         & zmrw_ms
+      !!----------------------------------------------------------------------
+
+      ! Different velocities for straits ( Gibraltar, Bab el Mandeb...)
+         
+      ! Control print
+      ! -------------
+      IF( kt == nit000 ) THEN 
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'cla_dynspg_tan : cross land advection on surface '
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~   pressure '
+         IF(lwp) WRITE(numout,*) ' '
+      ENDIF
+
+      ! EMP on Mediterranean Sea and Red Sea 
+      ! ------------------------------------
+      ! compute the emp in Mediterranean Sea
+      zempmed = 0.0_wp
+      zwei = 0.0_wp
+      ij0 =  96   ;   ij1 = 110
+      ii0 = 141   ;   ii1 = 181
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempmed = zempmed + emp_tl(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempmed )      ! sum with other processors value
+
+      ! minus 2 points in Red Sea and 3 in Atlantic 
+      ij0 =  96   ;   ij1 =  96
+      ii0 = 148   ;   ii1 = 148
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            zempmed = zempmed - emp_tl(ji  ,jj) * tmask(ji  ,jj,1)             &
+               &                                * e1t(ji  ,jj) * e2t(ji  ,jj)  &
+               &              - emp_tl(ji+1,jj) * tmask(ji+1,jj,1)             &
+               &                                * e1t(ji+1,jj) * e2t(ji+1,jj)   
+         END DO
+      END DO
+      ! we convert in m3
+      zempmed = zempmed * 1.e-3_wp
+
+      ! compute the emp in Red Sea   
+      zempred = 0.0_wp
+      zwei = 0.0_wp
+      ij0 =  87   ;   ij1 =  96
+      ii0 = 148   ;   ii1 = 160
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempred = zempred + emp_tl(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempred )      ! sum with other processors value
+
+      ! we convert in m3
+      zempred = zempred * 1.e-3
+
+      ! New Transport at Bab el Mandeb and Gibraltar
+      ! --------------------------------------------
+
+      ! imposed transport at Bab el Mandeb
+      zisw_rs = 0.4e6_wp        ! inflow surface water
+      zurw_rs = 0.2e6_wp        ! upper recirculation water
+      zbrw_rs = 0.5e6_wp        ! bottom recirculation water
+
+      ! imposed transport at Gibraltar
+      zisw_ms = 0.8e6_wp        ! atlantic-mediterranean  water
+      zmrw_ms = 0.7e6_wp        ! middle recirculation water
+      zurw_ms = 2.5e6_wp        ! upper  recirculation water 
+      zbrw_ms = 3.5e6_wp        ! bottom recirculation water 
+
+      ! Different velocities for straits ( Gibraltar, Bab el Mandeb )
+      ! -------------------------------------------------------------
+
+      ! Bab el Mandeb
+      ! -------------
+      ! 160,88 north point Bab el Mandeb
+      ij0 =  88   ;   ij1 =  88
+      ii0 = 160   ;   ii1 = 160
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_tl(ji,jj  ,: ) = 0.0_wp  !  North East Bab el Mandeb 
+         END DO
+      END DO
+      !                              ! surface
+      DO jk = 1,  8                                      
+         DO jj = mj0(ij0), mj1(ij1)
+            DO ji = mi0(ii0), mi1(ii1)
+               ua_tl(ji, jj,jk) = - ( zempred / 8.0_wp ) &
+                  &               / ( e2u(ji, jj) * fse3t(ji, jj,jk) )     
+            END DO
+         END DO
+      END DO
+      !                              ! deeper
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_tl(ji, jj,21) = 0.0_wp
+         END DO
+      END DO
+
+      ! 160,87 south point Bab el Mandeb
+      ij0 =  87   ;   ij1 =  87
+      ii0 = 160   ;   ii1 = 160
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_tl(ji,jj  ,: ) = 0.0_wp  !  South East Bab el Mandeb 
+         END DO
+      END DO
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_tl(ji, jj,21) = 0.0_wp
+         END DO
+      END DO
+
+      ! Gibraltar
+      ! ---------
+
+      ! initialisation of velocity at concerned points 
+      ! 139, 101 south point in Gibraltar 
+      ij0 = 101   ;   ij1 = 101
+      ii0 = 139   ;   ii1 = 139
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_tl(ji,jj  ,: ) = 0.0_wp  !  South West Gibraltar
+            ua_tl(ji,jj+1,: ) = 0.0_wp  !  North West Gibraltar
+         END DO
+      END DO
+      !                            ! surface
+      DO jk = 1, 14                      
+         DO jj = mj0(ij0), mj1(ij1)
+            DO ji = mi0(ii0), mi1(ii1)
+               ua_tl(ji,jj,jk) = ( zempmed / 14.0_wp ) &
+                  &              / ( e2u(ji,jj) * fse3t(ji,jj,jk) ) 
+            END DO
+         END DO
+      END DO
+      !                            ! middle circulation
+      DO jk = 15, 20                      
+         DO jj = mj0(ij0), mj1(ij1)
+            DO ji = mi0(ii0), mi1(ii1)
+               ua_tl(ji,jj,jk) = 0.0_wp
+            END DO
+         END DO
+      END DO
+      !                            ! deeper 
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_tl(ji,jj,21) = 0.0_wp
+            ua_tl(ji,jj,22) = 0.0_wp
+         END DO
+      END DO
+
+      ! 139,102 north point in Gibraltar
+      ij0 = 102   ;   ij1 = 102
+      ii0 = 139   ;   ii1 = 139
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_tl(ji,jj  ,: ) = 0.0_wp !  North West Gibraltar
+         END DO
+      END DO
+      DO jk = 15, 20                      
+         DO jj = mj0(ij0), mj1(ij1)
+            DO ji = mi0(ii0), mi1(ii1)
+               ua_tl(ji,jj,jk) = 0.0_wp
+            END DO
+         END DO
+      END DO
+      !                            ! deeper
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_tl(ji,jj,22) = 0.0_wp
+         END DO
+      END DO
+
+   END SUBROUTINE dyn_spg_cla_tan
+
+   SUBROUTINE dyn_spg_cla_adj( kt ) 
+      !!----------------------------------------------------------------------
+      !!              ***  routine dyn_spg_cla_adj  ***
+      !!
+      !! ** Purpose of direct routine :
+      !!
+      !! ** Method of direct routine : 
+      !!
+      !! ** Action :
+      !!
+      !! History
+      !!        !  09-03  (A. Weaver) Original version
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::  &
+         & kt              ! ocean time-step
+
+      !! * Local declarations
+      INTEGER  :: &
+         & ji, &           ! dummy loop indices
+         & jj, &
+         & jk                
+      INTEGER  :: &
+         & ii0, &          ! temporary integers
+         & ii1, &
+         & ij0, &
+         & ij1        
+      REAL(wp) ::  &    
+         & zempmed, &      ! EMP on Med Sea ans Red Sea
+         & zempred, &                
+         & zwei,    &                            !              
+         & zisw_rs, &      ! imposed transport Red sea
+         & zurw_rs, &
+         & zbrw_rs, &    
+         & zisw_ms, &      ! imposed transport Med Sea
+         & zurw_ms, &      
+         & zbrw_ms, &
+         & zmrw_ms
+      !!----------------------------------------------------------------------
+
+      ! Different velocities for straits ( Gibraltar, Bab el Mandeb...)
+         
+      ! Control print
+      ! -------------
+      IF( kt == nitend ) THEN 
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'cla_dynspg_adj : cross land advection on surface '
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~   pressure '
+         IF(lwp) WRITE(numout,*) ' '
+      ENDIF
+
+      ! Local initialization
+      ! --------------------
+      zempmed = 0.0_wp
+      zempred = 0.0_wp
+
+      ! New Transport at Bab el Mandeb and Gibraltar
+      ! --------------------------------------------
+
+      ! imposed transport at Bab el Mandeb
+      zisw_rs = 0.4e6_wp        ! inflow surface water
+      zurw_rs = 0.2e6_wp        ! upper recirculation water
+      zbrw_rs = 0.5e6_wp        ! bottom recirculation water
+
+      ! imposed transport at Gibraltar
+      zisw_ms = 0.8e6_wp        ! atlantic-mediterranean  water
+      zmrw_ms = 0.7e6_wp        ! middle recirculation water
+      zurw_ms = 2.5e6_wp        ! upper  recirculation water 
+      zbrw_ms = 3.5e6_wp        ! bottom recirculation water 
+
+      ! Different velocities for straits ( Gibraltar, Bab el Mandeb )
+      ! -------------------------------------------------------------
+
+      ! Gibraltar
+      ! ---------
+
+      ! initialisation of velocity at concerned points
+
+      ! 139,102 north point in Gibraltar
+      ij0 = 102   ;   ij1 = 102
+      ii0 = 139   ;   ii1 = 139
+      !                            ! deeper
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_ad(ji,jj,22) = 0.0_wp
+         END DO
+      END DO
+
+      DO jk = 15, 20                      
+         DO jj = mj0(ij0), mj1(ij1)
+            DO ji = mi0(ii0), mi1(ii1)
+               ua_ad(ji,jj,jk) = 0.0_wp
+            END DO
+         END DO
+      END DO
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_ad(ji,jj  ,: ) = 0.0_wp !  North West Gibraltar
+         END DO
+      END DO
+
+      ! 139, 101 south point in Gibraltar 
+      ij0 = 101   ;   ij1 = 101
+      ii0 = 139   ;   ii1 = 139
+      !                            ! deeper 
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_ad(ji,jj,21) = 0.0_wp
+            ua_ad(ji,jj,22) = 0.0_wp
+         END DO
+      END DO
+      !                            ! middle circulation
+      DO jk = 15, 20                      
+         DO jj = mj0(ij0), mj1(ij1)
+            DO ji = mi0(ii0), mi1(ii1)
+               ua_ad(ji,jj,jk) = 0.0_wp
+            END DO
+         END DO
+      END DO
+      !                            ! surface
+      DO jk = 1, 14                      
+         DO jj = mj0(ij0), mj1(ij1)
+            DO ji = mi0(ii0), mi1(ii1)
+               zempmed = zempmed + ua_ad(ji,jj,jk) / 14.0_wp &
+                  &            / ( e2u(ji,jj) * fse3t(ji,jj,jk) ) 
+               ua_ad(ji,jj,jk) = 0.0_wp
+            END DO
+         END DO
+      END DO
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_ad(ji,jj+1,: ) = 0.0_wp  !  North West Gibraltar
+            ua_ad(ji,jj  ,: ) = 0.0_wp  !  South West Gibraltar
+         END DO
+      END DO
+
+      ! Bab el Mandeb
+      ! -------------
+
+      ! 160,87 south point Bab el Mandeb
+      ij0 =  87   ;   ij1 =  87
+      ii0 = 160   ;   ii1 = 160
+
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_ad(ji, jj,21) = 0.0_wp
+         END DO
+      END DO
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_ad(ji,jj  ,: ) = 0.0_wp  !  South East Bab el Mandeb 
+         END DO
+      END DO
+
+      ! 160,88 north point Bab el Mandeb
+      ij0 =  88   ;   ij1 =  88
+      ii0 = 160   ;   ii1 = 160
+      !                              ! deeper
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_ad(ji, jj,21) = 0.0_wp
+         END DO
+      END DO
+      !                              ! surface
+      DO jk = 1, 8                                      
+         DO jj = mj0(ij0), mj1(ij1)
+            DO ji = mi0(ii0), mi1(ii1)
+               zempred = zempred - ua_ad(ji,jj,jk) / 8.0_wp &
+                  &            / ( e2u(ji,jj) * fse3t(ji,jj,jk) ) 
+               ua_ad(ji,jj,jk) = 0.0_wp
+            END DO
+         END DO
+      END DO
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            ua_ad(ji,jj  ,: ) = 0.0_wp  !  North East Bab el Mandeb 
+         END DO
+      END DO
+
+      ! EMP on Mediterranean Sea and Red Sea 
+      ! ------------------------------------
+
+      ! we convert in m3
+      zempred = zempred * 1.e-3_wp
+
+!!!! AW: Adjoint of this????
+      IF( lk_mpp )   CALL mpp_sum( zempred )      ! sum with other processors value
+
+      ! compute the emp in Red Sea   
+      ij0 =  87   ;   ij1 =  96
+      ii0 = 148   ;   ii1 = 160
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            zwei = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            emp_ad(ji,jj) = emp_ad(ji,jj) + zempred * zwei
+         END DO
+      END DO
+
+      ! we convert in m3
+      zempmed = zempmed * 1.e-3_wp
+
+      ! minus 2 points in Red Sea and 3 in Atlantic 
+      ij0 =  96   ;   ij1 =  96
+      ii0 = 148   ;   ii1 = 148
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            emp_ad(ji  ,jj) = emp_ad(ji  ,jj)                        &
+               &            - zempmed * tmask(ji  ,jj,1)             &
+               &                      * e1t(ji  ,jj) * e2t(ji  ,jj)
+            emp_ad(ji+1,jj) = emp_ad(ji+1,jj)                        &
+               &            - zempmed * tmask(ji+1,jj,1)             &
+               &                      * e1t(ji+1,jj) * e2t(ji+1,jj)   
+         END DO
+      END DO
+
+      IF( lk_mpp )   CALL mpp_sum( zempmed )      ! sum with other processors value
+
+      ! compute the emp in Mediterranean Sea
+      ij0 =  96   ;   ij1 = 110
+      ii0 = 141   ;   ii1 = 181
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0), mi1(ii1)
+            zwei = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            emp_ad(ji,jj) = emp_ad(ji,jj) + zempmed * zwei
+         END DO
+      END DO
+
+   END SUBROUTINE dyn_spg_cla_adj
+   !!======================================================================
+
+#endif
+END MODULE cla_dynspg_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/cla_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/cla_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/cla_tam.F90	(revision 2578)
@@ -0,0 +1,2103 @@
+MODULE cla_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                         ***  MODULE  cla_tam  ***
+   !! Cross Land Advection : parameterize ocean exchanges through straits by a
+   !!                        specified advection across land. 
+   !!                        Tangent and Adjoint module
+   !!==============================================================================
+#  if defined key_orca_r2
+   !!----------------------------------------------------------------------
+   !!   'key_orca_r2'   :                             ORCA R2 configuration
+   !!----------------------------------------------------------------------
+   !!   tra_cla           : update the tracer trend with the horizontal 
+   !!                       and vertical advection trends at straits
+   !!   tra_bab_el_mandeb : 
+   !!   tra_gibraltar     :
+   !!   tra_hormuz        :
+   !!   tra_cla_init      :
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   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
+      & tn,                  &
+      & sn
+   USE sbc_oce_tam,    ONLY: & ! surface variables
+      & emp_tl,              &
+      & emp_ad
+   USE oce_tam,        ONLY: & ! ocean dynamics and tracers variables
+      & tn_tl,               &
+      & sn_tl,               &
+      & ta_tl,               &
+      & sa_tl,               &
+      & tn_ad,               &
+      & sn_ad,               &
+      & ta_ad,               &
+      & sa_ad
+   USE sbc_oce,        ONLY: & ! ocean surface boundary condition (fluxes)
+      & emp
+   USE phycst,         ONLY: & ! Physical constants
+      & rau0
+   USE dom_oce,        ONLY: & ! ocean space and time domain
+      & mi0,                 &
+      & mi1,                 &
+      & mj0,                 &
+      & mj1,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej,                &
+      & rdt,                 &
+      & tmask,               &
+      & mig,                 &
+      & mjg,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e1t,                 &
+      & e2t,                 &
+# if defined key_vvl
+      & e3t_1,               &
+# else
+#  if defined key_zco
+      & e3t_0,               &
+#  else
+      & e3t,                 &
+#  endif
+# endif
+# if ! defined key_zco
+      & e3u,                 &
+      & e3v
+# endif
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & nit000,              &
+      & nitend,              &
+      & numout,              &
+      & lwp
+   USE lib_mpp,        ONLY: & ! distributed memory computing library
+      & lk_mpp,              &
+      & mpp_sum
+   USE paresp,         ONLY: &
+      & wesp_t,              &
+      & wesp_s
+   USE gridrandom,     ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,    ONLY : & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE tstool_tam,     ONLY: &
+      & prntst_adj,          & !
+      & stdemp,              & ! stdev for evaporation minus precip
+      & stdt,                & !           temperature
+      & stds                   !           salinity
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC tra_cla_tan        ! routine called by step_tam.F90
+   PUBLIC tra_cla_adj        ! routine called by step_tam.F90
+   PUBLIC tra_cla_adj_tst    ! routine called by tst.F90
+
+   !! * Modules variables   
+   REAL(wp) :: zempmed, zempred
+   REAL(wp) :: zempmed_tl, zempred_tl
+   REAL(wp) :: zempmed_ad, zempred_ad
+
+   REAL(wp) :: zisw_rs, zurw_rs, zbrw_rs          ! Imposed transport Red Sea 
+   REAL(wp) :: zisw_ms, zmrw_ms, zurw_ms, zbrw_ms ! Imposed transport Med Sea 
+   REAL(wp), DIMENSION(jpk) ::      &
+      zu1_rs_i, zu2_rs_i, zu3_rs_i, &  ! Red Sea velocities
+      zu1_ms_i, zu2_ms_i, zu3_ms_i     ! Mediterranean Sea velocities
+   LOGICAL :: lfirst = .TRUE. ! initialisation flag
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE tra_cla_tan( kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE tra_cla_tan  ***
+      !!                   
+      !! ** Purpose of the direct reoutine:
+      !!      Update the now trend due to the advection of tracers
+      !!      and add it to the general trend of passive tracer equations
+      !!      at some straits ( Bab el Mandeb, Gibraltar, Hormuz ).
+      !!
+      !! ** Method  :   ...
+      !!         Add this trend now to the general trend of tracer (ta,sa):
+      !!            (ta,sa) = (ta,sa) + ( zta , zsa )
+      !!
+      !! ** Action  :   update (ta,sa) with the now advective tracer trends
+      !!
+      !! History of the direct method:
+      !!        !         (A. Bozec)  original code  
+      !!   8.5  !  02-11  (A. Bozec)  F90: Free form and module
+      !! History of the TAM:
+      !!        !  08-08  (A. Vidard) tangent of the 02-11 vesrsion
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+      !!----------------------------------------------------------------------
+ 
+      ! cross land advection for straits
+
+      ! Initialization
+      IF( kt == nit000 )   CALL tra_cla_init_tam
+
+
+      ! Bab el Mandeb strait horizontal advection
+
+      CALL tra_bab_el_mandeb_tan 
+
+      ! Gibraltar strait horizontal advection
+
+      CALL tra_gibraltar_tan
+
+      ! Hormuz Strait ( persian Gulf) horizontal advection
+
+      CALL tra_hormuz_tan 
+
+
+
+   END SUBROUTINE tra_cla_tan
+   SUBROUTINE tra_cla_adj( kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE tra_cla_adj  ***
+      !!                   
+      !! ** Purpose of the direct reoutine:
+      !!      Update the now trend due to the advection of tracers
+      !!      and add it to the general trend of passive tracer equations
+      !!      at some straits ( Bab el Mandeb, Gibraltar, Hormuz ).
+      !!
+      !! ** Method  :   ...
+      !!         Add this trend now to the general trend of tracer (ta,sa):
+      !!            (ta,sa) = (ta,sa) + ( zta , zsa )
+      !!
+      !! ** Action  :   update (ta,sa) with the now advective tracer trends
+      !!
+      !! History of the direct method:
+      !!        !         (A. Bozec)  original code  
+      !!   8.5  !  02-11  (A. Bozec)  F90: Free form and module
+      !! History:
+      !!        !  08-06  (A. Vidard) adjoint of the 02-11 vesrsion
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+      !!----------------------------------------------------------------------
+ 
+      ! cross land advection for straits
+
+      ! Initialization
+      IF( kt == nitend )   CALL tra_cla_init_tam
+
+
+      ! Hormuz Strait ( persian Gulf) horizontal advection
+      CALL tra_hormuz_adj 
+      ! Gibraltar strait horizontal advection
+
+      CALL tra_gibraltar_adj
+      ! Bab el Mandeb strait horizontal advection
+
+      CALL tra_bab_el_mandeb_adj 
+
+   END SUBROUTINE tra_cla_adj
+
+   SUBROUTINE tra_bab_el_mandeb_tan
+      !!---------------------------------------------------------------------
+      !!             ***  ROUTINE tra_bab_el_mandeb_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Update the horizontal advective trend of tracers
+      !!      correction in Bab el Mandeb strait and
+      !!      add it to the general trend of tracer equations.
+      !!
+      !! ** Method of the direct routine:
+      !!     We impose transport at Bab el Mandeb and knowing T and S in
+      !!     surface and depth at each side of the  strait, we deduce T and S
+      !!     of the deep outflow of the Red Sea in the Indian ocean . 
+      !!                                          |
+      !!            |/ \|            N          |\ /|
+      !!            |_|_|______      |          |___|______
+      !!        88  |   |<-       W - - E    88 |   |<-
+      !!        87  |___|______      |       87 |___|->____
+      !!             160 161         S           160 161 
+      !!       horizontal view                horizontal view
+      !!          surface                        depth
+      !!    
+      !!     The horizontal advection is evaluated by a second order cen-
+      !!     tered scheme using now fields (leap-frog scheme). In specific
+      !!     areas (vicinity of major river mouths, some straits, or tn
+      !!     approaching the freezing point) it is mixed with an upstream 
+      !!     scheme for stability reasons. 
+      !!
+      !!         C A U T I O N : the trend saved is the centered trend only.
+      !!      It doesn't take into account the upstream part of the scheme.
+      !!
+      !! ** history of the direct routine:
+      !!           !  02-11  (A. Bozec) Original code 
+      !!      8.5  !  02-11  (A. Bozec) F90: Free form and module
+      !! ** history of the tangent routine:
+      !!           !  08-08  (A. Vidard)
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk               ! dummy loop indices
+      REAL(wp) :: zsu, zvt
+      REAL(wp) :: zsumt, zsumt1, zsumt2, zsumt3, zsumt4
+      REAL(wp) :: zsums, zsums1, zsums2, zsums3, zsums4
+      REAL(wp) :: zsumttl, zsumt1tl, zsumt2tl, zsumt3tl, zsumt4tl
+      REAL(wp) :: zsumstl, zsums1tl, zsums2tl, zsums3tl, zsums4tl
+      REAL(wp) :: zt, zs
+      REAL(wp) :: zttl, zstl
+      REAL(wp) :: zwei
+      REAL(wp), DIMENSION (jpk) ::  zu1_rs, zu2_rs, zu3_rs
+      REAL(wp), DIMENSION (jpk) ::  zu1_rs_tl, zu2_rs_tl, zu3_rs_tl
+      !!---------------------------------------------------------------------
+
+      ! Initialization of vertical sum for T and S transport
+      ! ----------------------------------------------------
+
+      zsumt  = 0.e0       ! East  Bab el Mandeb surface north point (T)
+      zsums  = 0.e0       ! East  Bab el Mandeb surface north point (S)
+      zsumt1 = 0.e0       ! East  Bab el Mandeb depth   south point (T)
+      zsums1 = 0.e0       ! East  Bab el Mandeb depth   south point (S)
+      zsumt2 = 0.e0       ! West  Bab el Mandeb surface             (T)
+      zsums2 = 0.e0       ! West  Bab el Mandeb surface             (S)
+      zsumt3 = 0.e0       ! West  Bab el Mandeb depth               (T)
+      zsums3 = 0.e0       ! West  Bab el Mandeb depth               (S)
+      zsumt4 = 0.e0       ! East  Bab el Mandeb depth   north point (T) 
+      zsums4 = 0.e0       ! East  Bab el Mandeb depth   north point (S) 
+      zsumttl  = 0.e0       ! East  Bab el Mandeb surface north point (T)
+      zsumstl  = 0.e0       ! East  Bab el Mandeb surface north point (S)
+      zsumt1tl = 0.e0       ! East  Bab el Mandeb depth   south point (T)
+      zsums1tl = 0.e0       ! East  Bab el Mandeb depth   south point (S)
+      zsumt2tl = 0.e0       ! West  Bab el Mandeb surface             (T)
+      zsums2tl = 0.e0       ! West  Bab el Mandeb surface             (S)
+      zsumt3tl = 0.e0       ! West  Bab el Mandeb depth               (T)
+      zsums3tl = 0.e0       ! West  Bab el Mandeb depth               (S)
+      zsumt4tl = 0.e0       ! East  Bab el Mandeb depth   north point (T) 
+      zsums4tl = 0.e0       ! East  Bab el Mandeb depth   north point (S) 
+      
+      ! EMP of the Red Sea 
+      ! ------------------
+
+      zempred_tl = 0.e0
+      zempred = 0.e0
+      zwei = 0.e0
+      DO jj = mj0(87), mj1(96)
+         DO ji = mi0(148), mi1(160)
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempred    = zempred    + emp(ji,jj)    * zwei
+            zempred_tl = zempred_tl + emp_tl(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempred    )      ! sum with other processors value
+      IF( lk_mpp )   CALL mpp_sum( zempred_tl )      ! sum with other processors value
+
+      ! convert in m3
+      zempred_tl = zempred_tl * 1.e-3
+      zempred    = zempred    * 1.e-3
+
+      ! Velocity profile at each point
+      ! ------------------------------
+
+      zu1_rs(:) = zu1_rs_i(:)
+      zu2_rs(:) = zu2_rs_i(:)
+      zu3_rs(:) = zu3_rs_i(:)
+      zu1_rs_tl(:) = 0.0_wp
+      zu2_rs_tl(:) = 0.0_wp
+      zu3_rs_tl(:) = 0.0_wp
+
+      ! velocity profile at 161,88 East Bab el Mandeb North point 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1, 8                                      
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu1_rs(jk)    = zu1_rs(jk)    &
+                  &           - ( zempred / 8. ) / ( e2u(ji,jj) * fse3u(ji,jj,jk) ) 
+               zu1_rs_tl(jk) = zu1_rs_tl(jk) &
+                  &           - ( zempred_tl / 8. ) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )     
+            END DO
+         END DO
+      END DO
+
+      ! velocity profile at 161, 88 West Bab el Mandeb 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1,  10                                     
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu3_rs(jk)    = zu3_rs(jk)    &
+                  &          + ( zempred    / 10. ) / ( e1v(ji,jj) * fse3v(ji,jj,jk) )
+               zu3_rs_tl(jk) = zu3_rs_tl(jk) &
+                  &          + ( zempred_tl / 10. ) / ( e1v(ji,jj) * fse3v(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+      
+      ! Balance of temperature and salinity
+      ! -----------------------------------
+
+      ! east Bab el Mandeb surface vertical sum of transport* S,T
+      DO jk =  1, 19
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zsumt    = zsumt    &
+                  &     + tn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk)
+               zsums    = zsums    &
+                  &     + sn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk) 
+               zsumttl  = zsumttl  &
+                  &     + tn_tl(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk) &
+                  &     + tn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs_tl(jk)
+               zsumstl  = zsumstl  &
+                  &     + sn_tl(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk) &
+                  &     + sn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs_tl(jk) 
+            END DO
+         END DO
+      END DO
+
+      ! west Bab el Mandeb surface vertical sum of transport* S,T
+      DO jk =  1, 10
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zsumt2   = zsumt2     &
+                  &     + tn(ji,jj,jk) * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) * zu3_rs(jk)
+               zsums2   = zsums2     &
+                  &     + sn(ji,jj,jk) * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) * zu3_rs(jk)
+               zsumt2tl = zsumt2tl   &
+                  &     + tn_tl(ji,jj,jk) * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) * zu3_rs(jk) &
+                  &     + tn(ji,jj,jk) * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) * zu3_rs_tl(jk)
+               zsums2tl = zsums2tl   &
+                  &     + sn_tl(ji,jj,jk) * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) * zu3_rs(jk) &
+                  &     + sn(ji,jj,jk) * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) * zu3_rs_tl(jk)
+            END DO
+         END DO
+      END DO
+
+      ! west Bab el Mandeb deeper
+      DO jj = mj0(89), mj1(89) 
+         DO ji = mi0(160), mi1(160) 
+            zsumt3   = tn(ji,jj,16) * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * zu3_rs(16)
+            zsums3   = sn(ji,jj,16) * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * zu3_rs(16)
+            zsumt3tl = tn_tl(ji,jj,16) * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * zu3_rs(16) &
+               &     + tn(ji,jj,16) * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * zu3_rs_tl(16)
+            zsums3tl = sn_tl(ji,jj,16) * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * zu3_rs(16) &
+               &     + sn(ji,jj,16) * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * zu3_rs_tl(16)
+         END DO
+      END DO
+
+      ! east  Bab el Mandeb deeper  
+      DO jk =  20, 21
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zsumt4   = zsumt4   &
+                  &     + tn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk)
+               zsums4   = zsums4   &
+                  &     + sn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk)
+               zsumt4tl = zsumt4tl &
+                  &     + tn_tl(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk) &
+                  &     + tn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs_tl(jk)
+               zsums4tl = zsums4tl &
+                  &     + sn_tl(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk) &
+                  &     + sn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs_tl(jk)
+            END DO
+         END DO
+      END DO
+
+      ! Total transport  
+      zsumt1   = -( zsumt3 + zsumt2 + zsumt + zsumt4 )
+      zsums1   = -( zsums3 + zsums2 + zsums + zsums4 )
+      zsumt1tl = -( zsumt3tl + zsumt2tl + zsumttl + zsumt4tl )
+      zsums1tl = -( zsums3tl + zsums2tl + zsumstl + zsums4tl )
+
+      ! Temperature and Salinity at East Bab el Mandeb, Level 21
+      DO jj = mj0(88), mj1(88) 
+         DO ji = mi0(160), mi1(160) 
+            zt   = zsumt1 / ( zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) )
+            zs   = zsums1 / ( zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) )
+            zttl = zsumt1tl / ( zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) ) &
+               & - zsumt1 / ( 2 * zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) ) * zu2_rs_tl(21)
+            zstl = zsums1tl / ( zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) ) &
+               & - zsums1 / ( 2 * zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) ) * zu2_rs_tl(21)
+         END DO
+      END DO
+      
+      ! New Temperature and Salinity at East Bab el Mandeb
+      ! --------------------------------------------------
+
+      ! north point 	
+      DO jk = 1, jpk
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zvt             = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu             = e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+               ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) &
+                  &             + ( 1. / zvt ) * zsu * zu1_rs_tl(jk) * tn(ji,jj,jk) &
+                  &             + ( 1. / zvt ) * zsu * zu1_rs(jk) * tn_tl(ji,jj,jk)
+               sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) &
+                  &             + ( 1. / zvt ) * zsu * zu1_rs_tl(jk) * sn(ji,jj,jk) &
+                  &             + ( 1. / zvt ) * zsu * zu1_rs(jk) * sn_tl(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! south point
+      jk =  21
+      DO jj = mj0(87), mj1(87) 
+         DO ji = mi0(161), mi1(161) 
+            zvt             = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+            zsu             = e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+            ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) &
+               &            + ( 1. / zvt ) * zsu * zu2_rs_tl(jk) * zt &
+               &            + ( 1. / zvt ) * zsu * zu2_rs(jk) * zttl
+            sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) &
+               &            + ( 1. / zvt ) * zsu * zu2_rs_tl(jk) * zs &
+               &            + ( 1. / zvt ) * zsu * zu2_rs(jk) * zstl
+         END DO
+      END DO
+
+
+      ! New Temperature and Salinity at West Bab el Mandeb 
+      ! --------------------------------------------------
+
+      ! surface	
+      DO jk = 1, 10
+         DO jj = mj0(89), mj1(89) 
+            DO ji = mi0(160), mi1(160) 
+               zvt             = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu             = e1v(ji,jj-1) * fse3v(ji,jj-1,jk)
+               ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) &
+                  &            + ( 1. / zvt ) * zsu * zu3_rs_tl(jk) * tn(ji+1,jj-1,jk) &
+                  &            + ( 1. / zvt ) * zsu * zu3_rs(jk) * tn_tl(ji+1,jj-1,jk)
+               sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) &
+                  &            + ( 1. / zvt ) * zsu * zu3_rs_tl(jk) * sn(ji+1,jj-1,jk) &
+                  &            + ( 1. / zvt ) * zsu * zu3_rs(jk) * sn_tl(ji+1,jj-1,jk)
+            END DO
+         END DO
+      END DO
+      ! deeper
+      jk =  16
+      DO jj = mj0(89), mj1(89) 
+         DO ji = mi0(160), mi1(160) 
+            zvt             = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+            zsu             = e1v(ji,jj-1) * fse3v(ji,jj-1,jk)
+            ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) &
+               &            + ( 1. / zvt ) * zsu * zu3_rs_tl(jk) * tn(ji,jj,jk) &
+               &            + ( 1. / zvt ) * zsu * zu3_rs(jk) * tn_tl(ji,jj,jk)
+            sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk) &
+               &            + ( 1. / zvt ) * zsu * zu3_rs_tl(jk) * sn(ji,jj,jk) &
+               &            + ( 1. / zvt ) * zsu * zu3_rs(jk) * sn_tl(ji,jj,jk)
+         END DO
+      END DO
+
+   END SUBROUTINE tra_bab_el_mandeb_tan
+   SUBROUTINE tra_bab_el_mandeb_adj
+      !!---------------------------------------------------------------------
+      !!             ***  ROUTINE tra_bab_el_mandeb_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!      Update the horizontal advective trend of tracers
+      !!      correction in Bab el Mandeb strait and
+      !!      add it to the general trend of tracer equations.
+      !!
+      !! ** Method of the direct routine:
+      !!     We impose transport at Bab el Mandeb and knowing T and S in
+      !!     surface and depth at each side of the  strait, we deduce T and S
+      !!     of the deep outflow of the Red Sea in the Indian ocean . 
+      !!                                          |
+      !!            |/ \|            N          |\ /|
+      !!            |_|_|______      |          |___|______
+      !!        88  |   |<-       W - - E    88 |   |<-
+      !!        87  |___|______      |       87 |___|->____
+      !!             160 161         S           160 161 
+      !!       horizontal view                horizontal view
+      !!          surface                        depth
+      !!    
+      !!     The horizontal advection is evaluated by a second order cen-
+      !!     tered scheme using now fields (leap-frog scheme). In specific
+      !!     areas (vicinity of major river mouths, some straits, or tn
+      !!     approaching the freezing point) it is mixed with an upstream 
+      !!     scheme for stability reasons. 
+      !!
+      !!         C A U T I O N : the trend saved is the centered trend only.
+      !!      It doesn't take into account the upstream part of the scheme.
+      !!
+      !! ** history of the direct routine:
+      !!           !  02-11  (A. Bozec) Original code 
+      !!      8.5  !  02-11  (A. Bozec) F90: Free form and module
+      !! ** history of the adjoint routine:
+      !!           !  08-08  (A. Vidard)
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk               ! dummy loop indices
+      REAL(wp) :: zsu, zvt
+      REAL(wp) :: zsumt, zsumt1, zsumt2, zsumt3, zsumt4
+      REAL(wp) :: zsums, zsums1, zsums2, zsums3, zsums4
+      REAL(wp) :: zsumtad, zsumt1ad, zsumt2ad, zsumt3ad, zsumt4ad
+      REAL(wp) :: zsumsad, zsums1ad, zsums2ad, zsums3ad, zsums4ad
+      REAL(wp) :: zt, zs
+      REAL(wp) :: ztad, zsad
+      REAL(wp) :: zwei
+      REAL(wp), DIMENSION (jpk) ::  zu1_rs, zu2_rs, zu3_rs
+      REAL(wp), DIMENSION (jpk) ::  zu1_rs_ad, zu2_rs_ad, zu3_rs_ad
+      !!---------------------------------------------------------------------
+
+      ! Initialization of vertical sum for T and S transport
+      ! ----------------------------------------------------
+
+      zsumt    = 0.e0       ! East  Bab el Mandeb surface north point (T)
+      zsums    = 0.e0       ! East  Bab el Mandeb surface north point (S)
+      zsumt1   = 0.e0       ! East  Bab el Mandeb depth   south point (T)
+      zsums1   = 0.e0       ! East  Bab el Mandeb depth   south point (S)
+      zsumt2   = 0.e0       ! West  Bab el Mandeb surface             (T)
+      zsums2   = 0.e0       ! West  Bab el Mandeb surface             (S)
+      zsumt3   = 0.e0       ! West  Bab el Mandeb depth               (T)
+      zsums3   = 0.e0       ! West  Bab el Mandeb depth               (S)
+      zsumt4   = 0.e0       ! East  Bab el Mandeb depth   north point (T) 
+      zsums4   = 0.e0       ! East  Bab el Mandeb depth   north point (S) 
+      zsumtad  = 0.e0       ! East  Bab el Mandeb surface north point (T)
+      zsumsad  = 0.e0       ! East  Bab el Mandeb surface north point (S)
+      zsumt1ad = 0.e0       ! East  Bab el Mandeb depth   south point (T)
+      zsums1ad = 0.e0       ! East  Bab el Mandeb depth   south point (S)
+      zsumt2ad = 0.e0       ! West  Bab el Mandeb surface             (T)
+      zsums2ad = 0.e0       ! West  Bab el Mandeb surface             (S)
+      zsumt3ad = 0.e0       ! West  Bab el Mandeb depth               (T)
+      zsums3ad = 0.e0       ! West  Bab el Mandeb depth               (S)
+      zsumt4ad = 0.e0       ! East  Bab el Mandeb depth   north point (T) 
+      zsums4ad = 0.e0       ! East  Bab el Mandeb depth   north point (S) 
+      ztad     = 0.e0
+      zsad     = 0.e0
+      zu1_rs_ad (:) = 0.e0
+      zu2_rs_ad (:) = 0.e0
+      zu3_rs_ad (:) = 0.e0
+      zempred_ad = 0.e0
+      !===========================
+      ! Direct model recomputation
+      !===========================
+      ! EMP of the Red Sea 
+      ! ------------------
+
+      zempred = 0.e0
+      zwei    = 0.e0
+      DO jj = mj0(87), mj1(96)
+         DO ji = mi0(148), mi1(160)
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempred = zempred + emp(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempred )      ! sum with other processors value
+
+      ! convert in m3
+      zempred = zempred * 1.e-3
+
+      ! Velocity profile at each point
+      ! ------------------------------
+
+      zu1_rs(:) = zu1_rs_i(:)
+      zu2_rs(:) = zu2_rs_i(:)
+      zu3_rs(:) = zu3_rs_i(:)
+
+      ! velocity profile at 161,88 East Bab el Mandeb North point 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1, 8                                      
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu1_rs(jk) = zu1_rs(jk) - ( zempred / 8. ) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )     
+            END DO
+         END DO
+      END DO
+
+      ! velocity profile at 161, 88 West Bab el Mandeb 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1,  10                                     
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu3_rs(jk) = zu3_rs(jk) + ( zempred / 10. ) / ( e1v(ji,jj) * fse3v(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+      
+      ! Balance of temperature and salinity
+      ! -----------------------------------
+
+      ! east Bab el Mandeb surface vertical sum of transport* S,T
+      DO jk =  1, 19
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zsumt  = zsumt  + tn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk)  
+               zsums  = zsums  + sn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk) 
+            END DO
+         END DO
+      END DO
+
+      ! west Bab el Mandeb surface vertical sum of transport* S,T
+      DO jk =  1, 10
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zsumt2 = zsumt2 + tn(ji,jj,jk) * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) * zu3_rs(jk)
+               zsums2 = zsums2 + sn(ji,jj,jk) * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) * zu3_rs(jk)
+            END DO
+         END DO
+      END DO
+
+      ! west Bab el Mandeb deeper
+      DO jj = mj0(89), mj1(89) 
+         DO ji = mi0(160), mi1(160) 
+            zsumt3 = tn(ji,jj,16) * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * zu3_rs(16)
+            zsums3 = sn(ji,jj,16) * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * zu3_rs(16)
+         END DO
+      END DO
+
+      ! east  Bab el Mandeb deeper  
+      DO jk =  20, 21
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zsumt4 =  zsumt4 + tn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk)
+               zsums4 =  zsums4 + sn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk) 
+            END DO
+         END DO
+      END DO
+
+      ! Total transport  
+      zsumt1 = -( zsumt3 + zsumt2 + zsumt + zsumt4 )
+      zsums1 = -( zsums3 + zsums2 + zsums + zsums4 )
+
+      ! Temperature and Salinity at East Bab el Mandeb, Level 21
+      DO jj = mj0(88), mj1(88) 
+         DO ji = mi0(160), mi1(160) 
+            zt = zsumt1 / ( zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) )
+            zs = zsums1 / ( zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) )
+         END DO
+      END DO
+      
+      !=============
+      ! Adjoint part
+      !=============
+
+      ! New Temperature and Salinity at West Bab el Mandeb 
+      ! --------------------------------------------------
+
+      ! deeper
+      jk =  16
+      DO jj = mj1(89), mj0(89), -1
+         DO ji = mi1(160), mi0(160), -1
+            zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+            zsu = e1v(ji,jj-1) * fse3v(ji,jj-1,jk)
+            zu3_rs_ad(jk) = zu3_rs_ad(jk) + ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * tn(ji,jj,jk)
+            tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) + ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu3_rs(jk)
+            zu3_rs_ad(jk) = zu3_rs_ad(jk) + sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * sn(ji,jj,jk)
+            sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) + sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu3_rs(jk)
+         END DO
+      END DO
+      ! surface	
+      DO jk = 10, 1, -1
+         DO jj = mj1(89), mj0(89), -1
+            DO ji = mi1(160), mi0(160), -1
+               zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e1v(ji,jj-1) * fse3v(ji,jj-1,jk)
+               zu3_rs_ad(jk) = zu3_rs_ad(jk) + ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * tn(ji+1,jj-1,jk)
+               tn_ad(ji+1,jj-1,jk) = tn_ad(ji+1,jj-1,jk) + ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu3_rs(jk)
+               zu3_rs_ad(jk) = zu3_rs_ad(jk) + sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * sn(ji+1,jj-1,jk)
+               sn_ad(ji+1,jj-1,jk) = sn_ad(ji+1,jj-1,jk) + sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu3_rs(jk)
+            END DO
+         END DO
+      END DO
+      ! New Temperature and Salinity at East Bab el Mandeb
+      ! --------------------------------------------------
+
+      ! south point
+      jk =  21
+      DO jj = mj1(87), mj0(87), -1
+         DO ji = mi1(161), mi0(161), -1 
+            zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+            zsu = e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+            zu2_rs_ad(jk) = zu2_rs_ad(jk) + ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zt
+            ztad = ztad + ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu2_rs(jk)
+            zu2_rs_ad(jk) = zu2_rs_ad(jk) + sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zs
+            zsad = zsad + sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu2_rs(jk)
+         END DO
+      END DO
+
+      ! north point 	
+      DO jk = jpk, 1, -1
+         DO jj = mj1(88), mj0(88), -1
+            DO ji = mi1(161), mi0(161), -1
+               zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+               zu1_rs_ad(jk) = zu1_rs_ad(jk) + ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * tn(ji,jj,jk)
+               tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) + ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu1_rs(jk) 
+               zu1_rs_ad(jk) = zu1_rs_ad(jk) + sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * sn(ji,jj,jk)
+               sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) + sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu1_rs(jk) 
+            END DO
+         END DO
+      END DO
+
+      ! Balance of temperature and salinity
+      ! -----------------------------------
+
+      ! Temperature and Salinity at East Bab el Mandeb, Level 21
+      DO jj = mj1(88), mj0(88), -1
+         DO ji = mi1(160), mi0(160), -1
+            zsumt1ad = zsumt1ad + ztad / ( zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) )
+            zu2_rs_ad(21) = zu2_rs_ad(21) - ztad * zsumt1 / ( 2 * zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) )
+            ztad = 0.0_wp
+            zsums1ad = zsums1ad + zsad / ( zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) )
+            zu2_rs_ad(21) = zu2_rs_ad(21) - zsad * zsums1 / ( 2 * zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) )
+            zsad = 0.0_wp
+         END DO
+      END DO
+      ! Total transport  
+      zsumt3ad = zsumt3ad - zsumt1ad
+      zsumt2ad = zsumt2ad - zsumt1ad
+      zsumtad  = zsumtad  - zsumt1ad
+      zsumt4ad = zsumt4ad - zsumt1ad
+      zsumt1ad = 0.0_wp
+      zsums3ad = zsums3ad - zsums1ad
+      zsums2ad = zsums2ad - zsums1ad
+      zsumsad  = zsumsad  - zsums1ad
+      zsums4ad = zsums4ad - zsums1ad
+      zsums1ad = 0.0_wp
+
+      ! east  Bab el Mandeb deeper  
+      DO jk =  21, 20, -1
+         DO jj = mj1(88), mj0(88), -1
+            DO ji = mi1(161), mi0(161), -1
+               tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) + zsumt4ad * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk)
+               zu1_rs_ad(jk)   = zu1_rs_ad(jk)   + zsumt4ad * tn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+               sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) + zsums4ad * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk)
+               zu1_rs_ad(jk)   = zu1_rs_ad(jk)   + zsums4ad * sn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! west Bab el Mandeb deeper
+      DO jj = mj1(89), mj0(89), -1
+         DO ji = mi1(160), mi0(160), -1
+            tn_ad(ji,jj,16) = tn_ad(ji,jj,16) + zsumt3ad * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * zu3_rs(16)
+            zu3_rs_ad(16)   = zu3_rs_ad(16)   + zsumt3ad * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * tn(ji,jj,16)
+            sn_ad(ji,jj,16) = sn_ad(ji,jj,16) + zsums3ad * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * zu3_rs(16)
+            zu3_rs_ad(16)   = zu3_rs_ad(16)   + zsums3ad * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * sn(ji,jj,16)
+            zsumt3ad = 0.0_wp
+            zsums3ad = 0.0_wp
+         END DO
+      END DO
+
+      ! west Bab el Mandeb surface vertical sum of transport* S,T
+      DO jk =  10, 1, -1
+         DO jj = mj1(88), mj0(88), -1
+            DO ji = mi1(161), mi0(161), -1
+               tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) + zsumt2ad * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) * zu3_rs(jk)
+               zu3_rs_ad(jk)   = zu3_rs_ad(jk)   + zsumt2ad * tn(ji,jj,jk) * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) 
+               sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) + zsums2ad * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) * zu3_rs(jk)
+               zu3_rs_ad(jk)   = zu3_rs_ad(jk)   + zsums2ad * sn(ji,jj,jk) * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      ! east Bab el Mandeb surface vertical sum of transport* S,T
+      DO jk =  19, 1, -1
+         DO jj = mj1(88), mj0(88), -1
+            DO ji = mi1(161), mi0(161), -1
+               tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) + zsumtad * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk)
+               zu1_rs_ad(jk)   = zu1_rs_ad(jk)   + zsumtad * tn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) 
+               sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) + zsumsad * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk)
+               zu1_rs_ad(jk)   = zu1_rs_ad(jk)   + zsumsad * sn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) 
+            END DO
+         END DO
+      END DO
+
+      ! Velocity profile at each point
+      ! ------------------------------
+      ! velocity profile at 161, 88 West Bab el Mandeb 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 10, 1, -1                                     
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zempred_ad = zempred_ad + zu3_rs_ad(jk) / ( 10. * e1v(ji,jj) * fse3v(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      ! velocity profile at 161,88 East Bab el Mandeb North point 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 8, 1, -1                                      
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zempred_ad = zempred_ad - zu1_rs_ad(jk) / ( 8. * e2u(ji,jj) * fse3u(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      zu1_rs(:) = zu1_rs_i(:)
+      zu2_rs(:) = zu2_rs_i(:)
+      zu3_rs(:) = zu3_rs_i(:)
+      zu1_rs_ad(:) = 0.0_wp
+      zu2_rs_ad(:) = 0.0_wp
+      zu3_rs_ad(:) = 0.0_wp
+
+      ! EMP of the Red Sea 
+      ! ------------------
+
+      ! convert in m3
+      zempred_ad = zempred_ad * 1.e-3
+
+      IF( lk_mpp )   CALL mpp_sum( zempred_ad )      ! sum with other processors value
+      DO jj = mj0(87), mj1(96)
+         DO ji = mi0(148), mi1(160)
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            emp_ad(ji,jj) = emp_ad(ji,jj) + zempred_ad * zwei
+         END DO
+      END DO
+
+      zempred_ad = 0.e0
+      zwei = 0.e0
+ 
+   END SUBROUTINE tra_bab_el_mandeb_adj
+   SUBROUTINE tra_gibraltar_tan
+      !!---------------------------------------------------------------------
+      !!               ***  ROUTINE tra_gibraltar_tan  ***
+      !!
+      !! ** Purpose :
+      !!        Update the horizontal advective trend of tracers (t & s)
+      !!        correction in Gibraltar  and
+      !!        add it to the general trend of tracer equations.
+      !!
+      !! ** Method :
+      !!      We impose transport at Gibraltar and knowing T and S in
+      !!      surface and deeper at each side of the strait, we deduce T and S
+      !!      of the outflow of the Mediterranean Sea in the Atlantic ocean .
+      !!                                
+      !!          ________________      N        ________________
+      !! 102           |    |->         |           <-|    |<-
+      !! 101      ___->|____|_____   W - - E     ___->|____|_____
+      !!           139   140  141       |         139   140  141
+      !!          horizontal view       S        horizontal view
+      !!            surface                          depth
+      !!         C A U T I O N : the trend saved is the centered trend only.
+      !!      It doesn't take into account the upstream part of the scheme.
+      !!
+      !! ** history :
+      !!           !  02-06  (A. Bozec) Original code 
+      !!      8.5  !  02-11  (A. Bozec) F90: Free form and module
+      !! ** history of the tangent routine:
+      !!           !  08-08  (A. Vidard) tangent of the 02-11 version
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk               ! dummy loop indices
+      REAL(wp) :: zsu, zvt
+      REAL(wp) :: zsumt, zsumt1, zsumt2, zsumt3, zsumt4
+      REAL(wp) :: zsums, zsums1, zsums2, zsums3, zsums4
+      REAL(wp) :: zsumttl, zsumt1tl, zsumt2tl, zsumt3tl, zsumt4tl
+      REAL(wp) :: zsumstl, zsums1tl, zsums2tl, zsums3tl, zsums4tl
+      REAL(wp) :: zt, zs
+      REAL(wp) :: zttl, zstl
+      REAL(wp) :: zwei
+      REAL(wp), DIMENSION (jpk) ::  zu1_ms, zu2_ms, zu3_ms
+      REAL(wp), DIMENSION (jpk) ::  zu1_ms_tl, zu2_ms_tl, zu3_ms_tl
+      !!---------------------------------------------------------------------
+
+      ! Initialization of vertical sum for T and S transport
+      ! ----------------------------------------------------
+
+      zsumt  = 0.e0        ! West Gib. surface south point ( T )
+      zsums  = 0.e0        ! West Gib. surface south point ( S )
+      zsumt1 = 0.e0        ! East Gib. surface north point ( T )
+      zsums1 = 0.e0        ! East Gib. surface north point ( S )
+      zsumt2 = 0.e0        ! East Gib. depth   north point ( T )
+      zsums2 = 0.e0        ! East Gib. depth   north point ( S )
+      zsumt3 = 0.e0        ! West Gib. depth   south point ( T ) 
+      zsums3 = 0.e0        ! West Gib. depth   south point ( S ) 
+      zsumt4 = 0.e0        ! West Gib. depth   north point ( T ) 
+      zsums4 = 0.e0        ! West Gib. depth   north point ( S ) 
+      zsumttl  = 0.e0        ! West Gib. surface south point ( T )
+      zsumstl  = 0.e0        ! West Gib. surface south point ( S )
+      zsumt1tl = 0.e0        ! East Gib. surface north point ( T )
+      zsums1tl = 0.e0        ! East Gib. surface north point ( S )
+      zsumt2tl = 0.e0        ! East Gib. depth   north point ( T )
+      zsums2tl = 0.e0        ! East Gib. depth   north point ( S )
+      zsumt3tl = 0.e0        ! West Gib. depth   south point ( T ) 
+      zsums3tl = 0.e0        ! West Gib. depth   south point ( S ) 
+      zsumt4tl = 0.e0        ! West Gib. depth   north point ( T ) 
+      zsums4tl = 0.e0        ! West Gib. depth   north point ( S ) 
+       
+      ! EMP of Mediterranean Sea 
+      ! ------------------------
+      
+      zempmed_tl = 0.e0
+      zempmed    = 0.e0
+      zwei       = 0.e0
+      DO jj = mj0(96), mj1(110)
+         DO ji = mi0(141), mi1(181)
+            zwei       = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempmed    = zempmed    + emp   (ji,jj) * zwei
+            zempmed_tl = zempmed_tl + emp_tl(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempmed    )      ! sum with other processors value
+      IF( lk_mpp )   CALL mpp_sum( zempmed_tl )      ! sum with other processors value
+
+      ! minus 2 points in Red Sea and 3 in Atlantic ocean
+      DO jj = mj0(96),mj1(96)
+         DO ji = mi0(148),mi1(148)
+            zempmed_tl = zempmed_tl &
+               &       - emp_tl(ji  ,jj) * tmask(ji  ,jj,1) * e1t(ji  ,jj) * e2t(ji  ,jj) &
+               &       - emp_tl(ji+1,jj) * tmask(ji+1,jj,1) * e1t(ji+1,jj) * e2t(ji+1,jj)   
+            zempmed    = zempmed    &
+               &       - emp(ji  ,jj) * tmask(ji  ,jj,1) * e1t(ji  ,jj) * e2t(ji  ,jj)   &
+               &       - emp(ji+1,jj) * tmask(ji+1,jj,1) * e1t(ji+1,jj) * e2t(ji+1,jj)   
+         END DO
+      END DO
+
+      ! convert in m3
+      zempmed    = zempmed    * 1.e-3
+      zempmed_tl = zempmed_tl * 1.e-3
+
+      ! Velocity profile at each point
+      ! ------------------------------
+
+      zu1_ms(:) = zu1_ms_i(:)
+      zu2_ms(:) = zu2_ms_i(:)
+      zu3_ms(:) = zu3_ms_i(:)
+      zu1_ms_tl(:) = 0.0_wp
+      zu2_ms_tl(:) = 0.0_wp
+      zu3_ms_tl(:) = 0.0_wp
+
+      ! velocity profile at 139,101  South point + emp on surface 
+      DO jk = 1, 14                                      
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu1_ms(jk)    = zu1_ms(jk)    &
+                  &          + ( zempmed    / 14. ) / ( e2u(ji-1,jj-1) * fse3u(ji-1,jj-1,jk) )
+               zu1_ms_tl(jk) = zu1_ms_tl(jk) &
+                  &          + ( zempmed_tl / 14. ) / ( e2u(ji-1,jj-1) * fse3u(ji-1,jj-1,jk) )
+            END DO
+         END DO
+      END DO
+
+      ! profile at East Gibraltar    
+      ! velocity profile at 141,102  + emp on surface 
+      DO jk = 1,  14                                     
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu3_ms(jk)    = zu3_ms(jk)    &
+                  &          + ( zempmed    / 14. ) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )
+               zu3_ms_tl(jk) = zu3_ms_tl(jk) &
+                  &          + ( zempmed_tl / 14. ) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+      
+      ! Balance of temperature and salinity
+      ! -----------------------------------
+
+      ! west gibraltar surface vertical sum of transport* S,T
+      DO jk =  1, 14
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zsumt   = zsumt   + tn(ji,jj,jk) * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms(jk)
+               zsums   = zsums   + sn(ji,jj,jk) * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms(jk) 
+               zsumttl = zsumttl  &
+                  &    + tn_tl(ji,jj,jk) * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms(jk) &
+                  &    + tn(ji,jj,jk) * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms_tl(jk)
+               zsumstl = zsumstl  &
+                  &    + sn_tl(ji,jj,jk) * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms(jk) &
+                  &    + sn(ji,jj,jk) * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms_tl(jk) 
+            END DO
+         END DO
+      END DO
+
+      ! east Gibraltar surface  vertical sum of transport* S,T
+      DO jk =  1, 14
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zsumt1   = zsumt1   &
+                  &     + tn(ji,jj,jk) * e2u(ji+1,jj+1) * fse3u(ji+1,jj+1,jk) * zu3_ms(jk)
+               zsums1   = zsums1   &
+                  &     + sn(ji,jj,jk) * e2u(ji+1,jj+1) * fse3u(ji+1,jj+1,jk) * zu3_ms(jk)
+               zsumt1tl = zsumt1tl &
+                  &     + tn_tl(ji,jj,jk) * e2u(ji+1,jj+1) * fse3u(ji+1,jj+1,jk) * zu3_ms(jk) &
+                  &     + tn(ji,jj,jk) * e2u(ji+1,jj+1) * fse3u(ji+1,jj+1,jk) * zu3_ms_tl(jk)
+               zsums1tl = zsums1tl &
+                  &     + sn_tl(ji,jj,jk) * e2u(ji+1,jj+1) * fse3u(ji+1,jj+1,jk) * zu3_ms(jk) &
+                  &     + sn(ji,jj,jk) * e2u(ji+1,jj+1) * fse3u(ji+1,jj+1,jk) * zu3_ms_tl(jk)
+            END DO
+         END DO
+      END DO
+
+      ! east Gibraltar deeper  vertical sum of transport* S,T
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(141), mi1(141) 
+            zsumt2   = tn(   ji,jj,21) * e2u(ji-1,jj) * fse3u(ji-1,jj,21) * zu3_ms(   21)
+            zsums2   = sn(   ji,jj,21) * e2u(ji-1,jj) * fse3u(ji-1,jj,21) * zu3_ms(   21)
+            zsumt2tl = tn_tl(ji,jj,21) * e2u(ji-1,jj) * fse3u(ji-1,jj,21) * zu3_ms(   21) &
+               &     + tn(   ji,jj,21) * e2u(ji-1,jj) * fse3u(ji-1,jj,21) * zu3_ms_tl(21)
+            zsums2tl = sn_tl(ji,jj,21) * e2u(ji-1,jj) * fse3u(ji-1,jj,21) * zu3_ms(   21) &
+               &     + sn(   ji,jj,21) * e2u(ji-1,jj) * fse3u(ji-1,jj,21) * zu3_ms_tl(21)
+         END DO
+      END DO
+
+      ! west Gibraltar deeper vertical sum of transport* S,T
+      DO  jk =  21, 22 
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zsumt3   = zsumt3   &
+                  &     + tn(   ji,jj,jk) * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms(jk)
+               zsums3   = zsums3   &
+                  &     + sn(   ji,jj,jk) * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms(jk)
+               zsumt3tl = zsumt3tl &
+                  &     + tn_tl(ji,jj,jk) * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms(jk) &
+                  &     + tn(   ji,jj,jk) * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms_tl(jk)
+               zsums3tl = zsums3tl &
+                  &     + sn_tl(ji,jj,jk) * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms(jk) &
+                  &     + sn(   ji,jj,jk) * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms_tl(jk)
+            END DO
+         END DO
+      END DO
+
+      ! Total transport = 0.
+      zsumt4   = zsumt2   + zsumt1   - zsumt   - zsumt3
+      zsums4   = zsums2   + zsums1   - zsums   - zsums3
+      zsumt4tl = zsumt2tl + zsumt1tl - zsumttl - zsumt3tl
+      zsums4tl = zsums2tl + zsums1tl - zsumstl - zsums3tl
+
+      ! Temperature and Salinity at West gibraltar , Level 22
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(140), mi1(140) 
+            zt   = zsumt4   / ( zu2_ms(22) * e2u(ji-1,jj) * fse3u(ji-1,jj,22) )
+            zs   = zsums4   / ( zu2_ms(22) * e2u(ji-1,jj) * fse3u(ji-1,jj,22) )
+            zttl = zsumt4tl / ( zu2_ms(22) * e2u(ji-1,jj) * fse3u(ji-1,jj,22) ) &
+               & - zsumt4   / ( 2 * zu2_ms(22) * e2u(ji-1,jj) * fse3u(ji-1,jj,22) ) * zu2_ms_tl(22)
+            zstl = zsums4tl / ( zu2_ms(22) * e2u(ji-1,jj) * fse3u(ji-1,jj,22) ) &
+               & - zsums4   / ( 2 * zu2_ms(22) * e2u(ji-1,jj) * fse3u(ji-1,jj,22) ) * zu2_ms_tl(22)
+         END DO
+      END DO
+      
+      ! New Temperature and Salinity trend at West Gibraltar
+      ! ----------------------------------------------------
+
+      ! south point 	
+      DO jk = 1, 22
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e2u(ji,jj) * fse3u(ji,jj,jk)
+               ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk)                                   &
+                  &            - ( 1. / zvt ) * zsu * zu1_ms_tl(jk) * tn(ji,jj,jk) &
+                  &            - ( 1. / zvt ) * zsu * zu1_ms(jk) * tn_tl(ji,jj,jk)
+               sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk)                                   &
+                  &            - ( 1. / zvt ) * zsu * zu1_ms_tl(jk) * sn(ji,jj,jk) &
+                  &            - ( 1. / zvt ) * zsu * zu1_ms(jk) * sn_tl(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! north point 
+      DO jk = 15, 20
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(139), mi1(139) 
+               zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+               ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk)                                      &
+                  &            - ( 1. / zvt ) * zsu * zu2_ms_tl(jk) * tn(ji, jj-1,jk) &
+                  &            - ( 1. / zvt ) * zsu * zu2_ms(jk) * tn_tl(ji, jj-1,jk)
+               sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk)                                      &
+                  &            - ( 1. / zvt ) * zsu * zu2_ms_tl(jk) * sn(ji, jj-1,jk) &
+                  &            - ( 1. / zvt ) * zsu * zu2_ms(jk) * sn_tl(ji, jj-1,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Gibraltar outflow, north point deeper
+      jk =  22
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(139), mi1(139) 
+            zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+            zsu = e2u(ji, jj) * fse3u(ji, jj,jk)
+            ta_tl(ji, jj,jk) = ta_tl(ji, jj,jk)                        &
+               &             - ( 1. / zvt ) * zsu * zu2_ms_tl(jk) * zt &
+               &             - ( 1. / zvt ) * zsu * zu2_ms(jk) * zttl
+            sa_tl(ji, jj,jk) = sa_tl(ji, jj,jk)                        &
+               &             - ( 1. / zvt ) * zsu * zu2_ms_tl(jk) * zs &
+               &             - ( 1. / zvt ) * zsu * zu2_ms(jk) * zstl
+         END DO
+      END DO
+
+
+      ! New Temperature and Salinity at East Gibraltar 
+      ! ----------------------------------------------
+
+      ! surface	
+      DO jk = 1, 14
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(141), mi1(141) 
+               zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e2u(ji-1,jj) * fse3u(ji-2,jj,jk)
+               ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk)                                       &
+                  &            + ( 1. / zvt ) * zsu * zu3_ms_tl(jk) * tn(ji-2,jj-1,jk) &
+                  &            + ( 1. / zvt ) * zsu * zu3_ms(jk) * tn_tl(ji-2,jj-1,jk)
+               sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk)                                       &
+                  &            + ( 1. / zvt ) * zsu * zu3_ms_tl(jk) * sn(ji-2,jj-1,jk) &
+                  &            + ( 1. / zvt ) * zsu * zu3_ms(jk) * sn_tl(ji-2,jj-1,jk)
+            END DO
+         END DO
+      END DO
+      ! deeper
+      jk =  21
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(141), mi1(141) 
+            zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+            zsu = e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+            ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk)                                   &
+               &            + ( 1. / zvt ) * zsu * zu3_ms_tl(jk) * tn(ji,jj,jk) &
+               &            + ( 1. / zvt ) * zsu * zu3_ms(jk) * tn_tl(ji,jj,jk)
+            sa_tl(ji,jj,jk) = sa_tl(ji,jj,jk)                                   &
+               &            + ( 1. / zvt ) * zsu * zu3_ms_tl(jk) * sn(ji,jj,jk) &
+               &            + ( 1. / zvt ) * zsu * zu3_ms(jk) * sn_tl(ji,jj,jk)
+         END DO
+      END DO
+
+   END SUBROUTINE tra_gibraltar_tan
+   SUBROUTINE tra_gibraltar_adj
+      !!---------------------------------------------------------------------
+      !!               ***  ROUTINE tra_gibraltar_adj  ***
+      !!
+      !! ** Purpose :
+      !!        Update the horizontal advective trend of tracers (t & s)
+      !!        correction in Gibraltar  and
+      !!        add it to the general trend of tracer equations.
+      !!
+      !! ** Method :
+      !!      We impose transport at Gibraltar and knowing T and S in
+      !!      surface and deeper at each side of the strait, we deduce T and S
+      !!      of the outflow of the Mediterranean Sea in the Atlantic ocean .
+      !!                                
+      !!          ________________      N        ________________
+      !! 102           |    |->         |           <-|    |<-
+      !! 101      ___->|____|_____   W - - E     ___->|____|_____
+      !!           139   140  141       |         139   140  141
+      !!          horizontal view       S        horizontal view
+      !!            surface                          depth
+      !!         C A U T I O N : the trend saved is the centered trend only.
+      !!      It doesn't take into account the upstream part of the scheme.
+      !!
+      !! ** history :
+      !!           !  02-06  (A. Bozec) Original code 
+      !!      8.5  !  02-11  (A. Bozec) F90: Free form and module
+      !! ** history of the adjoint routine:
+      !!           !  08-08  (A. Vidard) tangent of the 02-11 version
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk               ! dummy loop indices
+      REAL(wp) :: zsu, zvt
+      REAL(wp) :: zsumt, zsumt1, zsumt2, zsumt3, zsumt4
+      REAL(wp) :: zsums, zsums1, zsums2, zsums3, zsums4
+      REAL(wp) :: zsumtad, zsumt1ad, zsumt2ad, zsumt3ad, zsumt4ad
+      REAL(wp) :: zsumsad, zsums1ad, zsums2ad, zsums3ad, zsums4ad
+      REAL(wp) :: zt, zs
+      REAL(wp) :: ztad, zsad
+      REAL(wp) :: zwei
+      REAL(wp), DIMENSION (jpk) ::  zu1_ms, zu2_ms, zu3_ms
+      REAL(wp), DIMENSION (jpk) ::  zu1_ms_ad, zu2_ms_ad, zu3_ms_ad
+      !!---------------------------------------------------------------------
+
+      ! Initialization of vertical sum for T and S transport
+      ! ----------------------------------------------------
+
+      zsumt  = 0.e0        ! West Gib. surface south point ( T )
+      zsums  = 0.e0        ! West Gib. surface south point ( S )
+      zsumt1 = 0.e0        ! East Gib. surface north point ( T )
+      zsums1 = 0.e0        ! East Gib. surface north point ( S )
+      zsumt2 = 0.e0        ! East Gib. depth   north point ( T )
+      zsums2 = 0.e0        ! East Gib. depth   north point ( S )
+      zsumt3 = 0.e0        ! West Gib. depth   south point ( T ) 
+      zsums3 = 0.e0        ! West Gib. depth   south point ( S ) 
+      zsumt4 = 0.e0        ! West Gib. depth   north point ( T ) 
+      zsums4 = 0.e0        ! West Gib. depth   north point ( S ) 
+      zsumtad  = 0.e0        ! West Gib. surface south point ( T )
+      zsumsad  = 0.e0        ! West Gib. surface south point ( S )
+      zsumt1ad = 0.e0        ! East Gib. surface north point ( T )
+      zsums1ad = 0.e0        ! East Gib. surface north point ( S )
+      zsumt2ad = 0.e0        ! East Gib. depth   north point ( T )
+      zsums2ad = 0.e0        ! East Gib. depth   north point ( S )
+      zsumt3ad = 0.e0        ! West Gib. depth   south point ( T ) 
+      zsums3ad = 0.e0        ! West Gib. depth   south point ( S ) 
+      zsumt4ad = 0.e0        ! West Gib. depth   north point ( T ) 
+      zsums4ad = 0.e0        ! West Gib. depth   north point ( S ) 
+      ztad     = 0.e0
+      zsad     = 0.e0
+      zu1_ms_ad(:) = 0.0_wp
+      zu2_ms_ad(:) = 0.0_wp
+      zu3_ms_ad(:) = 0.0_wp
+      zempmed_ad = 0.e0
+       
+      !=====================
+      ! Direct recomputation
+      !=====================
+
+      ! EMP of Mediterranean Sea 
+      ! ------------------------
+ 
+      zempmed = 0.e0
+      zwei = 0.e0
+      DO jj = mj0(96),mj1(110)
+         DO ji = mi0(141),mi1(181)
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempmed = zempmed + emp(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempmed )      ! sum with other processors value
+
+
+      ! minus 2 points in Red Sea and 3 in Atlantic ocean
+      DO jj = mj0(96),mj1(96)
+         DO ji = mi0(148),mi1(148)
+            zempmed = zempmed  -  emp(ji  ,jj) * tmask(ji  ,jj,1) * e1t(ji  ,jj) * e2t(ji  ,jj)   &
+                               -  emp(ji+1,jj) * tmask(ji+1,jj,1) * e1t(ji+1,jj) * e2t(ji+1,jj)   
+         END DO
+      END DO
+
+      ! convert in m3
+      zempmed = zempmed * 1.e-3
+
+      ! Velocity profile at each point
+      ! ------------------------------
+
+      zu1_ms(:) = zu1_ms_i(:)
+      zu2_ms(:) = zu2_ms_i(:)
+      zu3_ms(:) = zu3_ms_i(:)
+
+      ! velocity profile at 139,101  South point + emp on surface 
+      DO jk = 1, 14                      
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu1_ms(jk) = zu1_ms(jk) + ( zempmed / 14. ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,jk) ) 
+            END DO
+         END DO
+      END DO
+
+      ! profile at East Gibraltar    
+      ! velocity profile at 141,102  + emp on surface 
+      DO  jk = 1, 14                     
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu3_ms(jk) = zu3_ms(jk) +  ( zempmed / 14. ) / ( e2u(ji, jj) * fse3u(ji, jj,jk) ) 
+            END DO
+         END DO
+      END DO
+    
+      ! Balance of temperature and salinity
+      ! -----------------------------------
+
+      ! west gibraltar surface vertical sum of transport* S,T
+      DO  jk =  1, 14 
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zsumt  = zsumt + tn(ji, jj,jk) * e2u(ji, jj) * fse3u(ji, jj,jk) * zu1_ms(jk)  
+               zsums  = zsums + sn(ji, jj,jk) * e2u(ji, jj) * fse3u(ji, jj,jk) * zu1_ms(jk) 
+            END DO
+         END DO
+      END DO
+
+      ! east Gibraltar surface  vertical sum of transport* S,T
+      DO  jk =  1, 14 
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zsumt1 = zsumt1 + tn(ji, jj,jk) * e2u(ji+1, jj+1) * fse3u(ji+1, jj+1,jk) * zu3_ms(jk)
+               zsums1 = zsums1 + sn(ji, jj,jk) * e2u(ji+1, jj+1) * fse3u(ji+1, jj+1,jk) * zu3_ms(jk)
+            END DO
+         END DO
+      END DO
+
+      ! east Gibraltar deeper  vertical sum of transport* S,T
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(141), mi1(141) 
+            zsumt2 = tn(ji, jj,21) * e2u(ji-1, jj) * fse3u(ji-1, jj,21) * zu3_ms(21)
+            zsums2 = sn(ji, jj,21) * e2u(ji-1, jj) * fse3u(ji-1, jj,21) * zu3_ms(21)
+         END DO
+      END DO
+      
+      ! west Gibraltar deeper vertical sum of transport* S,T
+      DO  jk =  21, 22 
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zsumt3 = zsumt3 + tn(ji, jj,jk) * e2u(ji, jj) * fse3u(ji, jj,jk) * zu1_ms(jk)
+               zsums3 = zsums3 + sn(ji, jj,jk) * e2u(ji, jj) * fse3u(ji, jj,jk) * zu1_ms(jk)
+            END DO
+         END DO
+      END DO
+
+      ! Total transport = 0.
+      zsumt4 = zsumt2 + zsumt1 - zsumt - zsumt3
+      zsums4 = zsums2 + zsums1 - zsums - zsums3
+
+      ! Temperature and Salinity at West gibraltar , Level 22
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(140), mi1(140) 
+            zt = zsumt4 / ( zu2_ms(22) * e2u(ji-1, jj) * fse3u(ji-1, jj, 22) )
+            zs = zsums4 / ( zu2_ms(22) * e2u(ji-1, jj) * fse3u(ji-1, jj, 22) )
+         END DO
+      END DO
+
+      !=============
+      ! Adjoint part
+      !=============
+
+      ! New Temperature and Salinity at East Gibraltar 
+      ! ----------------------------------------------
+
+      ! deeper
+      jk =  21
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi1(141), mi0(141), -1
+            zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+            zsu = e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+            zu3_ms_ad(jk)   = zu3_ms_ad(jk)   + sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * sn(ji,jj,jk)
+            sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) + sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu3_ms(jk)
+            zu3_ms_ad(jk)   = zu3_ms_ad(jk)   + ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * tn(ji,jj,jk)
+            tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) + ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu3_ms(jk)
+         END DO
+      END DO
+
+      ! surface	
+      DO jk = 14, 1, -1
+         DO jj =  mj1(102), mj0(102), -1
+            DO ji = mi1(141), mi0(141), -1
+               zvt = e1t(ji,jj)   * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e2u(ji-1,jj) * fse3u(ji-2,jj,jk)
+               zu3_ms_ad(jk)       = zu3_ms_ad(jk)       + sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * sn(ji-2,jj-1,jk)
+               sn_ad(ji-2,jj-1,jk) = sn_ad(ji-2,jj-1,jk) + sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu3_ms(jk) 
+               zu3_ms_ad(jk)       = zu3_ms_ad(jk)       + ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * tn(ji-2,jj-1,jk)
+               tn_ad(ji-2,jj-1,jk) = tn_ad(ji-2,jj-1,jk) + ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu3_ms(jk) 
+            END DO
+         END DO
+      END DO
+      
+      ! New Temperature and Salinity trend at West Gibraltar
+      ! ----------------------------------------------------
+      ! Gibraltar outflow, north point deeper
+      jk =  22
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(139), mi1(139) 
+            zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+            zsu = e2u(ji, jj) * fse3u(ji, jj,jk)
+            zu2_ms_ad(jk) = zu2_ms_ad(jk) - sa_ad(ji, jj,jk) * ( 1. / zvt ) * zsu * zs
+            zsad          = zsad          - sa_ad(ji, jj,jk) * ( 1. / zvt ) * zsu * zu2_ms(jk)
+            zu2_ms_ad(jk) = zu2_ms_ad(jk) - ta_ad(ji, jj,jk) * ( 1. / zvt ) * zsu * zt
+            ztad          = ztad          - ta_ad(ji, jj,jk) * ( 1. / zvt ) * zsu * zu2_ms(jk)
+         END DO
+      END DO
+      ! north point 
+      DO jk = 20, 15, -1
+         DO jj = mj1(102), mj0(102), -1
+            DO ji = mi1(139), mi0(139), -1
+               zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+               zu2_ms_ad(jk)      = zu2_ms_ad(jk)      - sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * sn(ji, jj-1,jk)
+               sn_ad(ji, jj-1,jk) = sn_ad(ji, jj-1,jk) - sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu2_ms(jk)
+               zu2_ms_ad(jk)      = zu2_ms_ad(jk)      - ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * tn(ji, jj-1,jk)
+               tn_ad(ji, jj-1,jk) = tn_ad(ji, jj-1,jk) - ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu2_ms(jk)
+            END DO
+         END DO
+      END DO
+      ! south point 	
+      DO jk = 22, 1, -1
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e2u(ji,jj) * fse3u(ji,jj,jk)
+               zu1_ms_ad(jk)   = zu1_ms_ad(jk)   - sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * sn(ji,jj,jk)
+               sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) - sa_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu1_ms(jk)
+               zu1_ms_ad(jk)   = zu1_ms_ad(jk)   - ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * tn(ji,jj,jk)
+               tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) - ta_ad(ji,jj,jk) * ( 1. / zvt ) * zsu * zu1_ms(jk)
+            END DO
+         END DO
+      END DO
+
+      
+      ! Balance of temperature and salinity
+      ! -----------------------------------
+
+      ! Temperature and Salinity at West gibraltar , Level 22
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi1(140), mi0(140), -1
+            zsums4ad      = zsums4ad      &
+               &          + zsad  / ( zu2_ms(22) * e2u(ji-1,jj) * fse3u(ji-1,jj,22) )
+            zu2_ms_ad(22) = zu2_ms_ad(22) &
+               &          - zsad * zsums4 / ( 2 * zu2_ms(22) * e2u(ji-1,jj) * fse3u(ji-1,jj,22) )
+            zsumt4ad      = zsumt4ad      &
+               &          + ztad  / ( zu2_ms(22) * e2u(ji-1,jj) * fse3u(ji-1,jj,22) )
+            zu2_ms_ad(22) = zu2_ms_ad(22) &
+               &          - ztad * zsumt4 / ( 2 * zu2_ms(22) * e2u(ji-1,jj) * fse3u(ji-1,jj,22) )
+            ztad = 0.0_wp
+            zsad = 0.0_wp
+         END DO
+      END DO
+
+      ! Total transport = 0.
+      zsums2ad = zsums2ad + zsums4ad
+      zsums1ad = zsums1ad + zsums4ad
+      zsumsad  = zsumsad  - zsums4ad
+      zsums3ad = zsums3ad - zsums4ad
+      zsumt2ad = zsumt2ad + zsumt4ad
+      zsumt1ad = zsumt1ad + zsumt4ad
+      zsumtad  = zsumtad  - zsumt4ad
+      zsumt3ad = zsumt3ad - zsumt4ad
+      zsumt4ad = 0.0
+      zsums4ad = 0.0
+      
+      ! west Gibraltar deeper vertical sum of transport* S,T
+      DO  jk =  22, 21, -1 
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) + zsums3ad * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms(jk)
+               zu1_ms_ad(jk)   = zu1_ms_ad(jk)   + zsums3ad * e2u(ji,jj) * fse3u(ji,jj,jk) * sn(ji,jj,jk)
+               tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) + zsumt3ad * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms(jk)
+               zu1_ms_ad(jk)   = zu1_ms_ad(jk)   + zsumt3ad * e2u(ji,jj) * fse3u(ji,jj,jk) * tn(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! east Gibraltar deeper  vertical sum of transport* S,T
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi1(141), mi0(141), -1
+            sn_ad(ji,jj,21) = sn_ad(ji,jj,21) + zsums2ad * e2u(ji-1,jj) * fse3u(ji-1,jj,21) * zu3_ms(21) 
+            zu3_ms_ad(21)   =  zu3_ms_ad(21)  + zsums2ad * e2u(ji-1,jj) * fse3u(ji-1,jj,21) * sn(ji,jj,21)
+            tn_ad(ji,jj,21) = tn_ad(ji,jj,21) + zsumt2ad * e2u(ji-1,jj) * fse3u(ji-1,jj,21) * zu3_ms(21) 
+            zu3_ms_ad(21)   =  zu3_ms_ad(21)  + zsumt2ad * e2u(ji-1,jj) * fse3u(ji-1,jj,21) * tn(ji,jj,21)
+            zsumt2ad = 0.0_wp
+            zsums2ad = 0.0_wp
+         END DO
+      END DO
+
+      ! east Gibraltar surface  vertical sum of transport* S,T
+      DO jk =  14, 1, -1
+         DO jj = mj1(101), mj0(101), -1
+            DO ji = mi1(139), mi0(139), - 1
+               sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) + zsums1ad * e2u(ji+1,jj+1) * fse3u(ji+1,jj+1,jk) * zu3_ms(jk) 
+               zu3_ms_ad(jk)   = zu3_ms_ad(jk)   + zsums1ad * e2u(ji+1,jj+1) * fse3u(ji+1,jj+1,jk) * sn(ji,jj,jk)
+               tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) + zsumt1ad * e2u(ji+1,jj+1) * fse3u(ji+1,jj+1,jk) * zu3_ms(jk) 
+               zu3_ms_ad(jk)   = zu3_ms_ad(jk)   + zsumt1ad * e2u(ji+1,jj+1) * fse3u(ji+1,jj+1,jk) * tn(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! west gibraltar surface vertical sum of transport* S,T
+      DO jk =  14, 1, -1
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               sn_ad(ji,jj,jk) = sn_ad(ji,jj,jk) + zsumsad * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms(jk)
+               zu1_ms_ad(jk)   = zu1_ms_ad(jk)   + zsumsad * e2u(ji,jj) * fse3u(ji,jj,jk) * sn(ji,jj,jk)
+               tn_ad(ji,jj,jk) = tn_ad(ji,jj,jk) + zsumtad * e2u(ji,jj) * fse3u(ji,jj,jk) * zu1_ms(jk)
+               zu1_ms_ad(jk)   = zu1_ms_ad(jk)   + zsumtad * e2u(ji,jj) * fse3u(ji,jj,jk) * tn(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      ! Velocity profile at each point
+      ! ------------------------------
+      ! profile at East Gibraltar    
+      ! velocity profile at 141,102  + emp on surface 
+      DO jk = 14, 1, -1                                     
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zempmed_ad = zempmed_ad + zu3_ms_ad(jk) / ( 14. * e2u(ji,jj) * fse3u(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      ! velocity profile at 139,101  South point + emp on surface 
+      DO jk = 14, 1, -1                            
+         DO jj = mj1(102), mj0(102), -1
+            DO ji = mi1(140), mi0(140), -1
+               zempmed_ad = zempmed_ad + zu1_ms_ad(jk) / ( 14. * e2u(ji-1,jj-1) * fse3u(ji-1,jj-1,jk) )
+            END DO
+         END DO
+      END DO
+
+      zu1_ms_ad(:) = 0.0_wp
+      zu2_ms_ad(:) = 0.0_wp
+      zu3_ms_ad(:) = 0.0_wp
+
+      ! EMP of Mediterranean Sea 
+      ! ------------------------
+      
+      ! convert in m3
+      zempmed_ad = zempmed_ad * 1.e-3
+
+     ! minus 2 points in Red Sea and 3 in Atlantic ocean
+      DO jj = mj1(96), mj0(96), -1
+         DO ji = mi1(148), mi0(148), -1
+            emp_ad(ji  ,jj) = emp_ad(ji  ,jj) - zempmed_ad * tmask(ji  ,jj,1) * e1t(ji  ,jj) * e2t(ji  ,jj)
+            emp_ad(ji+1,jj) = emp_ad(ji+1,jj) - zempmed_ad * tmask(ji+1,jj,1) * e1t(ji+1,jj) * e2t(ji+1,jj)
+         END DO
+      END DO
+
+      IF( lk_mpp )   CALL mpp_sum( zempmed_ad )      ! sum with other processors value
+
+      DO jj = mj0(96), mj1(110)
+         DO ji = mi0(141), mi1(181)
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            emp_ad(ji,jj) = emp_ad(ji,jj) + zempmed_ad * zwei
+         END DO
+      END DO
+      zempmed_ad = 0.e0
+
+ 
+   END SUBROUTINE tra_gibraltar_adj
+   SUBROUTINE tra_hormuz_tan
+      !!---------------------------------------------------------------------
+      !!               ***  ROUTINE tra_hormuz_tan  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!        Update the horizontal advective trend of tracers
+      !!        correction in Hormuz.
+      !!
+      !! ** Method of the direct routine: We impose transport at Hormuz .
+      !!                                
+      !! ** history of the direct routine:
+      !!           !  02-11  (A. Bozec) Original code 
+      !!      8.5  !  02-11  (A. Bozec) F90: Free form and module
+      !! ** history of the tangent routine:
+      !!           !  08-08  (A. Vidard) tangent of the 02-11 version
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      !!---------------------------------------------------------------------
+      
+      !! ... nothing
+
+   END SUBROUTINE tra_hormuz_tan
+   SUBROUTINE tra_hormuz_adj
+      !!---------------------------------------------------------------------
+      !!               ***  ROUTINE tra_hormuz_adj  ***
+      !!
+      !! ** Purpose of the direct routine:
+      !!        Update the horizontal advective trend of tracers
+      !!        correction in Hormuz.
+      !!
+      !! ** Method of the direct routine: We impose transport at Hormuz .
+      !!                                
+      !! ** history of the direct routine:
+      !!           !  02-11  (A. Bozec) Original code 
+      !!      8.5  !  02-11  (A. Bozec) F90: Free form and module
+      !! ** history of the tangent routine:
+      !!           !  08-08  (A. Vidard) adjoint of the 02-11 version
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      !!---------------------------------------------------------------------
+      
+      !! ... nothing
+
+   END SUBROUTINE tra_hormuz_adj
+   SUBROUTINE tra_cla_init_tam
+      !!---------------------------------------------------------------------
+      !!               ***  ROUTINE tra_cla_init_tam  ***
+      !!
+      !! ** Purpose :   Initialization of variables
+      !!
+      !! ** history :
+      !!           !  02-11  (A. Bozec) Original code 
+      !!      8.5  !  02-11  (A. Bozec) F90: Free form and module
+      !! ** history of the tam version:
+      !!      9.0  !  08-08  (A. Vidard) Original code
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk              ! dummy loop indices
+      !!---------------------------------------------------------------------
+
+      ! Control print
+      ! -------------
+      IF (lfirst) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_cla_init_tam : cross land advection on tracer '
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
+
+         ! Initialization at Bab el Mandeb
+         ! -------------------------------
+
+         ! imposed transport
+         zisw_rs = 0.4e6        ! inflow surface water
+         zurw_rs = 0.2e6        ! upper recirculation water
+         !!Alex      zbrw_rs = 1.2e6        ! bottom  recirculation water
+         zbrw_rs = 0.5e6        ! bottom  recirculation water
+
+         ! initialization of the velocity at Bab el Mandeb
+         zu1_rs_i(:) = 0.e0      ! velocity profile at 161,88 South point
+         zu2_rs_i(:) = 0.e0      ! velocity profile at 161,87 North point
+         zu3_rs_i(:) = 0.e0      ! velocity profile at 160,88 East  point
+
+         ! velocity profile at 161,88 East Bab el Mandeb North point 
+         ! we imposed zisw_rs + EMP above the Red Sea 
+         DO jk = 1, 8                                      
+            DO jj = mj0(88), mj1(88) 
+               DO ji = mi0(160), mi1(160) 
+                  zu1_rs_i(jk) = -( zisw_rs / 8. ) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )     
+               END DO
+            END DO
+         END DO
+
+         ! recirculation water 
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu1_rs_i(20) = -(           zurw_rs ) / ( e2u(ji,jj) * fse3u(ji,jj,20) )
+               zu1_rs_i(21) = -( zbrw_rs - zurw_rs ) / ( e2u(ji,jj) * fse3u(ji,jj,21) )
+            END DO
+         END DO
+
+         ! velocity profile at 161,87 East Bab el Mandeb South point
+         DO jj = mj0(87), mj1(87) 
+            DO ji = mi0(160), mi1(160) 
+               zu2_rs_i(21) =  ( zbrw_rs + zisw_rs ) / ( e2u(ji,jj) * fse3u(ji,jj,21) )
+            END DO
+         END DO
+
+         ! velocity profile at 161, 88 West Bab el Mandeb 
+         ! we imposed zisw_rs + EMP above the Red Sea 
+         DO jk = 1,  10                                     
+            DO jj = mj0(88), mj1(88) 
+               DO ji = mi0(160), mi1(160) 
+                  zu3_rs_i(jk) =  ( zisw_rs / 10. ) / ( e1v(ji,jj) * fse3v(ji,jj,jk) )
+               END DO
+            END DO
+         END DO
+
+         ! deeper
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu3_rs_i(16)  = - zisw_rs /( e1v(ji,jj) * fse3v(ji,jj,16) )
+            END DO
+         END DO
+
+
+         ! Initialization at Gibraltar
+         ! ---------------------------
+
+         ! imposed transport
+         zisw_ms = 0.8e6         ! atlantic-mediterranean  water
+         zmrw_ms = 0.7e6         ! middle recirculation water
+         zurw_ms = 2.5e6         ! upper  recirculation water 
+         zbrw_ms = 3.5e6         ! bottom recirculation water 
+
+         ! initialization of the velocity
+         zu1_ms_i(:) = 0.e0       ! velocity profile at 139,101 South point
+         zu2_ms_i(:) = 0.e0       ! velocity profile at 139,102 North point
+         zu3_ms_i(:) = 0.e0       ! velocity profile at 141,102 East  point
+
+         ! velocity profile at 139,101  South point
+         DO jk = 1, 14                      
+            DO jj = mj0(102), mj1(102) 
+               DO ji = mi0(140), mi1(140) 
+                  zu1_ms_i(jk) = ( zisw_ms / 14. ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,jk)) 
+               END DO
+            END DO
+         END DO
+
+         ! middle recirculation ( uncounting in the balance )
+         DO jk = 15, 20                      
+            DO jj = mj0(102), mj1(102) 
+               DO ji = mi0(140), mi1(140) 
+                  zu1_ms_i(jk) = ( zmrw_ms / 6. ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,jk) ) 
+               END DO
+            END DO
+         END DO
+
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu1_ms_i(21) =  (           zurw_ms ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,21) )
+               zu1_ms_i(22) =  ( zbrw_ms - zurw_ms ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,22) )
+            END DO
+         END DO
+
+         ! velocity profile at 139,102  North point
+         ! middle recirculation ( uncounting in the balance )
+         DO jk = 15, 20                      
+            DO jj = mj0(102), mj1(102) 
+               DO ji = mi0(140), mi1(140) 
+                  zu2_ms_i(jk) = -( zmrw_ms / 6. ) / ( e2u(ji-1, jj) * fse3u(ji-1, jj,jk) ) 
+               END DO
+            END DO
+         END DO
+
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu2_ms_i(22) = -( zisw_ms + zbrw_ms ) / ( e2u(ji-1, jj) * fse3u(ji-1, jj,22) )
+            END DO
+         END DO
+
+         ! profile at East Gibraltar   
+         ! velocity profile at 141,102 
+         DO  jk = 1, 14                     
+            DO jj = mj0(102), mj1(102) 
+               DO ji = mi0(140), mi1(140) 
+                  zu3_ms_i(jk) =  ( zisw_ms / 14. ) / ( e2u(ji, jj) * fse3u(ji, jj,jk) ) 
+               END DO
+            END DO
+         END DO
+
+         ! deeper 
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu3_ms_i(21) = -zisw_ms / ( e2u(ji, jj) * fse3u(ji, jj,21) )
+            END DO
+         END DO
+         lfirst = .FALSE.
+      END IF
+
+
+   END SUBROUTINE tra_cla_init_tam
+   SUBROUTINE tra_cla_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE dyn_adv_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      INTEGER :: &        ! dummy loop indices
+         & ji,   &
+         & jj,   &        
+         & jk,   &        
+         & jt,   &        
+         & jii,  &        
+         & jis,  &        
+         & jji,  &        
+         & jjs
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &      
+         & ztn_tlin,               &  ! potential temperature
+         & zsn_tlin,               &  ! salinity
+         & zta_tlin,               &  ! potential temperature
+         & zsa_tlin,               &  ! salinity
+         & zta_tlout,              &  ! potential temperature
+         & zsa_tlout,              &  ! salinity
+         & ztn_adout,              &  ! potential temperature
+         & zsn_adout,              &  ! salinity
+         & zta_adout,              &  ! potential temperature
+         & zsa_adout,              &  ! salinity
+         & zta_adin,               &  ! potential temperature
+         & zsa_adin,               &  ! salinity
+         & z3r                        ! 3D random field 
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &     
+         & zemp_tlin,              &  ! evaporation minus precipitation
+         & zemp_adout,             &  ! evaporation minus precipitation
+         & z2r                        ! 2D random field 
+
+      REAL(KIND=wp) ::       &
+         & zsp1,             & ! scalar product involving the tangent routine
+         & zsp1_1,           & ! scalar product involving the tangent routine
+         & zsp1_2,           & ! scalar product involving the tangent routine
+         & zsp2,             & ! scalar product involving the adjoint routine
+         & zsp2_1,           & ! scalar product involving the adjoint routine
+         & zsp2_2,           & ! scalar product involving the adjoint routine
+         & zsp2_3,           & ! scalar product involving the adjoint routine
+         & zsp2_4,           & ! scalar product involving the adjoint routine
+         & zsp2_5,           & ! scalar product involving the adjoint routine
+         & z2dt,             & ! temporary scalars
+         & zraur
+      CHARACTER(LEN=14) :: cl_name
+
+      ALLOCATE( & 
+         & ztn_tlin(   jpi, jpj, jpk ),  &
+         & zsn_tlin(   jpi, jpj, jpk ),  &
+         & zta_tlin(   jpi, jpj, jpk ),  &
+         & zsa_tlin(   jpi, jpj, jpk ),  &
+         & zta_tlout(  jpi, jpj, jpk ),  &
+         & zsa_tlout(  jpi, jpj, jpk ),  &
+         & ztn_adout(  jpi, jpj, jpk ),  &
+         & zsn_adout(  jpi, jpj, jpk ),  &
+         & zta_adout(  jpi, jpj, jpk ),  &
+         & zsa_adout(  jpi, jpj, jpk ),  &
+         & zta_adin(   jpi, jpj, jpk ),  &  
+         & zsa_adin(   jpi, jpj, jpk ),  &  
+         & z3r(        jpi, jpj, jpk ),  &
+         & zemp_tlin(  jpi, jpj      ),  &
+         & zemp_adout( jpi, jpj      ),  &
+         & z2r(        jpi, jpj      )  &
+         &  )
+
+      ! Initialize constants
+
+      z2dt  = 2.0_wp * rdt       ! time step: leap-frog
+      zraur = 1.0_wp / rau0      ! inverse density of pure water (m3/kg)
+
+      !=============================================================
+      ! 1) dx = ( T ) and dy = ( T )
+      !=============================================================
+
+      DO jt = 2, 1, -1
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+         ztn_tlin(  :,:,:) = 0.0_wp  
+         zsn_tlin(  :,:,:) = 0.0_wp  
+         zta_tlin(  :,:,:) = 0.0_wp  
+         zsa_tlin(  :,:,:) = 0.0_wp  
+         zta_tlout( :,:,:) = 0.0_wp  
+         zsa_tlout( :,:,:) = 0.0_wp  
+         ztn_adout( :,:,:) = 0.0_wp  
+         zsn_adout( :,:,:) = 0.0_wp  
+         zta_adout( :,:,:) = 0.0_wp  
+         zsa_adout( :,:,:) = 0.0_wp  
+         zta_adin(  :,:,:) = 0.0_wp    
+         zsa_adin(  :,:,:) = 0.0_wp    
+         zemp_tlin( :,:  ) = 0.0_wp  
+         zemp_adout(:,:  ) = 0.0_wp   
+         
+         SELECT CASE (jt)
+         CASE(1) ! Bab el Madeb
+            jji = mj0(86)
+            jjs = mj1(97)
+            jii = mi0(147)
+            jis = mi1(162)
+         CASE(2) ! Gibraltar
+            jji = mj0(95)
+            jjs = mj1(111)
+            jii = mi0(138)
+            jis = mi1(182)
+         END SELECT
+         !--------------------------------------------------------------------
+         ! Initialize the tangent input with random noise: dx
+         !--------------------------------------------------------------------
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 456953 + &
+                  &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdt )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  ztn_tlin(ji,jj,jk) = z3r(ji,jj,jk)  
+               END DO
+            END DO
+         END DO 
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 395703 + &
+                  &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stds )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsn_tlin(ji,jj,jk) = z3r(ji,jj,jk)  
+               END DO
+            END DO
+         END DO
+         
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 536782 + &
+                  &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdt )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zta_tlin(ji,jj,jk) = z3r(ji,jj,jk)  
+               END DO
+            END DO
+         END DO
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 613925 + &
+                  &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stds )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsa_tlin(ji,jj,jk) = z3r(ji,jj,jk)  
+               END DO
+            END DO
+         END DO
+         
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               iseed_2d(ji,jj) = - ( 228401 + &
+                  &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+            END DO
+         END DO
+         CALL grid_random( iseed_2d, z2r, 'T', 0.0_wp, stdemp )
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zemp_tlin(ji,jj) = z2r(ji,jj)  
+            END DO
+         END DO
+
+         zemp_tlin(:,:) = zemp_tlin(:,:) / ( z2dt * zraur )
+
+         tn_ad(:,:,:) = 0.0_wp
+         sn_ad(:,:,:) = 0.0_wp
+         ta_ad(:,:,:) = 0.0_wp
+         sa_ad(:,:,:) = 0.0_wp
+         emp_ad(:,:)  = 0.0_wp
+         tn_tl(:,:,:) = 0.0_wp
+         sn_tl(:,:,:) = 0.0_wp
+         ta_tl(:,:,:) = 0.0_wp
+         sa_tl(:,:,:) = 0.0_wp
+         emp_tl(:,:)  = 0.0_wp
+
+
+         DO jk = 1, jpk
+            DO jj = jji, jjs
+               DO ji = jii, jis
+                  tn_tl(ji,jj,jk)  = ztn_tlin(ji,jj,jk)
+                  sn_tl(ji,jj,jk)  = zsn_tlin(ji,jj,jk)
+                  ta_tl(ji,jj,jk)  = zta_tlin(ji,jj,jk)
+                  sa_tl(ji,jj,jk)  = zsa_tlin(ji,jj,jk)
+                  emp_tl(ji,jj)    = zemp_tlin(ji,jj)
+               END DO
+            END DO
+         END DO
+         CALL tra_cla_tan ( nit000 ) 
+
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zta_tlout(ji,jj,jk)  = ta_tl(ji,jj,jk)
+                  zsa_tlout(ji,jj,jk)  = sa_tl(ji,jj,jk)
+                  zta_adin(ji,jj,jk)   = zta_tlout(ji,jj,jk) &
+                     &                 * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)&
+                     &                 * tmask(ji,jj,jk) * wesp_t(jk)
+                  zsa_adin(ji,jj,jk)   = zsa_tlout(ji,jj,jk) &
+                     &                 * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)&
+                     &                 * tmask(ji,jj,jk) * wesp_s(jk)
+               END DO
+            END DO
+         END DO
+
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !--------------------------------------------------------------------
+
+         zsp1_1 = DOT_PRODUCT( zta_tlout, zta_adin )
+         zsp1_2 = DOT_PRODUCT( zsa_tlout, zsa_adin )
+         zsp1 = zsp1_1 + zsp1_2
+
+         !--------------------------------------------------------------------
+         ! Call the adjoint routine: dx^* = L^T dy^*
+         !--------------------------------------------------------------------
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  sa_ad(ji,jj,jk) = zsa_adin(ji,jj,jk)
+                  ta_ad(ji,jj,jk) = zta_adin(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL tra_cla_adj ( nit000 ) 
+         DO jk = 1, jpk
+            DO jj = jji, jjs    ! tlin should be 0 outside these boundaries but is not by construction
+               DO ji = jii, jis ! here it would insure that the dot product does not account for it
+                  ztn_adout(ji,jj,jk) = tn_ad(ji,jj,jk)
+                  zsn_adout(ji,jj,jk) = sn_ad(ji,jj,jk)
+                  zta_adout(ji,jj,jk) = ta_ad(ji,jj,jk)
+                  zsa_adout(ji,jj,jk) = sa_ad(ji,jj,jk)
+                  zemp_adout(ji,jj)  = emp_ad(ji,jj)
+               END DO
+            END DO
+         END DO
+
+         zsp2_1 = DOT_PRODUCT( ztn_tlin , ztn_adout )
+         zsp2_2 = DOT_PRODUCT( zsn_tlin , zsn_adout )
+         zsp2_3 = DOT_PRODUCT( zta_tlin , zta_adout )
+         zsp2_4 = DOT_PRODUCT( zsa_tlin , zsa_adout )
+         zsp2_5 = DOT_PRODUCT( zemp_tlin, zemp_adout )
+         zsp2   = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4 + zsp2_5
+
+         ! Compare the scalar products
+
+         ! 14 char:'12345678901234'
+         SELECT CASE (jt)
+         CASE(1) ! Bab el Madeb
+            cl_name = 'tra_cla_adj BM'
+         CASE(2) ! Gibraltar
+            cl_name = 'tra_cla_adj Gi'
+         END SELECT
+         CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      END DO
+      ! Deallocate memory
+
+      DEALLOCATE(      &
+         & ztn_tlin  ,  &
+         & zsn_tlin  ,  &
+         & zta_tlin  ,  &
+         & zsa_tlin  ,  &
+         & zta_tlout ,  &
+         & zsa_tlout ,  &
+         & ztn_adout ,  &
+         & zsn_adout ,  &
+         & zta_adout ,  &
+         & zsa_adout ,  &
+         & zta_adin  ,  &  
+         & zsa_adin  ,  &  
+         & zemp_tlin ,  &
+         & zemp_adout   &
+         &  )
+
+   END SUBROUTINE tra_cla_adj_tst
+   !!======================================================================
+#  else
+   !!----------------------------------------------------------------------
+   !!   Default option                              NO cross land advection
+   !!----------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
+CONTAINS
+   SUBROUTINE tra_cla_tan( kt ) 
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step indice
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_cla_tan : No use of cross land advection'
+         WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+   END SUBROUTINE tra_cla_tan
+   SUBROUTINE tra_cla_adj( kt ) 
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step indice
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_cla_adj : No use of cross land advection'
+         WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+   END SUBROUTINE tra_cla_adj
+   SUBROUTINE tra_cla_adj_tst( kt ) 
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step indice
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_cla_adj_tst : No use of cross land advection'
+         WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+   END SUBROUTINE tra_cla_adj_tst
+#  endif
+#endif
+END MODULE cla_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/dotprodfld.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/dotprodfld.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/dotprodfld.F90	(revision 2578)
@@ -0,0 +1,101 @@
+MODULE dotprodfld
+   !!======================================================================
+   !!                       ***  MODULE dotprodfld ***
+   !! NEMOVAR dotprodfld : Computes dot prodoct for 3D and 2D fields
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!     dot_product     : Computes the dot_product for two 3D/2D fields   
+   !!----------------------------------------------------------------------   
+   !! * Modules used   
+   USE par_kind
+   USE dom_oce, ONLY :       &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk
+
+   USE mppsumtam
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+
+   PUBLIC &
+      & dot_product
+
+   !! * Interfaces
+
+   INTERFACE dot_product
+      MODULE PROCEDURE dot_product_3d
+      MODULE PROCEDURE dot_product_2d
+   END INTERFACE
+
+CONTAINS
+
+   FUNCTION dot_product_3d( pvec1, pvec2 )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE dot_product_3d  ***
+      !!          
+      !! ** Purpose : Computes the dot_product for two 3D fields
+      !!
+      !! ** Method  : Use the mppsum module
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-08  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) dot_product_3d
+      !! * Arguments
+      REAL(wp), INTENT(IN), DIMENSION(jpi,jpj,jpk) :: &
+         & pvec1, &     ! 3D fielss to compute dot_product of
+         & pvec2       
+      !! * Local declarations
+      
+      dot_product_3d = mpp_sum_inter( &
+         &                       PACK( pvec1(nldi:nlei,nldj:nlej,:),.TRUE.) * &
+         &                       PACK( pvec2(nldi:nlei,nldj:nlej,:),.TRUE.),  &
+         &                       (nlei-nldi+1) * (nlej-nldj+1) * jpk )
+         
+   END FUNCTION dot_product_3d
+
+   FUNCTION dot_product_2d( pvec1, pvec2 )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE dot_product_2d  ***
+      !!          
+      !! ** Purpose : Computes the dot_product for two 2D fields
+      !!
+      !! ** Method  : Use the mppsum module
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-08  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) dot_product_2d
+      !! * Arguments
+      REAL(wp), INTENT(IN), DIMENSION(jpi,jpj) :: &
+         & pvec1, &     ! 2D fields to compute dot_product of
+         & pvec2       
+      !! * Local declarations
+
+      dot_product_2d = mpp_sum_inter( &
+         &                       PACK( pvec1(nldi:nlei,nldj:nlej),.TRUE.) * &
+         &                       PACK( pvec2(nldi:nlei,nldj:nlej),.TRUE.),  &
+         &                       (nlei-nldi+1) * (nlej-nldj+1) )
+
+   END FUNCTION dot_product_2d
+
+END MODULE dotprodfld
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/gridrandom.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/gridrandom.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/gridrandom.F90	(revision 2578)
@@ -0,0 +1,533 @@
+MODULE gridrandom
+   !!======================================================================
+   !!                       *** MODULE gridrandom ***
+   !!
+   !! NEMOVAR: Construct gridded random noise fields
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !! grid_2d_ran     : Fill a 2D array with uncorrelated Gaussian noise
+   !!                   using a constant seed
+   !! grid_3d_ran     : Fill a 3D array with uncorrelated Gaussian noise
+   !!                   using a constant seed
+   !! grid_2d_ran_2d  : Fill a 2D array with uncorrelated Gaussian noise
+   !!                   using a 2D seed array (for MPP)
+   !! grid_3d_ran_2d  : Fill a 3D array with uncorrelated Gaussian noise
+   !!                   using a 2D seed array (for MPP)
+   !! grid_write_seed : Write out the 2D seed array for the random number 
+   !!                   generator
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind       ! Kind variables
+   USE dom_oce        ! Domain variables
+   USE in_out_manager ! I/O stuff
+   USE iom            ! I/O manager
+   USE ran_num        ! Random number routines
+   USE lbclnk         ! Boundary conditions and halos
+
+   IMPLICIT NONE
+
+   INTERFACE grid_random
+      MODULE PROCEDURE grid_2d_ran, grid_3d_ran, &
+         &             grid_2d_ran_2d, grid_3d_ran_2d
+   END INTERFACE
+
+   INTERFACE grid_rd_sd
+      MODULE PROCEDURE grid_2d_rd_sd_loc,  &
+         &             grid_3d_rd_sd_loc
+   END INTERFACE
+
+   !! * Routine accessibility
+   PRIVATE
+
+   PUBLIC &
+      & grid_random,      &
+      & grid_write_seed,  &
+      & grid_rd_sd
+
+CONTAINS
+
+   SUBROUTINE grid_2d_ran( kseed, pt2d, cd_type, pmean, pstd )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE grid_2d_ran ***
+      !!          
+      !! ** Purpose : Fill a 2D (surface) array with uncorrelated Gaussian 
+      !!              noise.
+      !!
+      !! ** Method  : The value of kseed is the seed for the random number
+      !!              generator. On the first call to "grid_2d_ran" it should 
+      !!              be set to a large negative number.
+      !!
+      !!              Apply the appropriate grid-point mask and lateral 
+      !!              boundary conditions before exiting.
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-11  (A. Weaver)  
+      !!----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(INOUT) :: &
+         & kseed       ! Seed for random number generator
+      REAL, INTENT(INOUT), DIMENSION(jpi,jpj) :: &
+         & pt2d        ! 2D field
+      REAL(wp), INTENT(IN) :: &
+         & pmean, &    ! Mean of noise
+         & pstd        ! Standard deviation of noise
+
+      !! * Local declarations
+      CHARACTER(LEN=1), INTENT(IN) ::   &
+         & cd_type     ! Nature of pt2d grid-point
+                       !   = T , U  or V  grid-point
+      INTEGER :: &
+         & ji, &
+         & jj
+
+      !--------------------------------------------------------------------
+      ! Fill in the 2D field with Gaussian noise
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            pt2d(ji,jj) = gaustb( kseed, pstd, pmean )
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Apply masks and lateral boundary conditions
+      !--------------------------------------------------------------------
+
+      IF ( cd_type == 'T' ) THEN
+ 
+         pt2d(:,:) = pt2d(:,:) * tmask(:,:,1)
+         CALL lbc_lnk( pt2d, 'T',  1.0 )
+
+      ELSEIF ( cd_type == 'U' ) THEN
+
+         pt2d(:,:) = pt2d(:,:) * umask(:,:,1)
+         CALL lbc_lnk( pt2d, 'U', -1.0 )
+
+      ELSEIF ( cd_type == 'V' ) THEN
+
+         pt2d(:,:) = pt2d(:,:) * vmask(:,:,1)
+         CALL lbc_lnk( pt2d, 'V', -1.0 )
+
+      ELSEIF ( cd_type == 'S' ) THEN
+         CALL lbc_lnk( pt2d, 'S', 1.0 )
+               
+      ENDIF
+            
+   END SUBROUTINE grid_2d_ran
+         
+   SUBROUTINE grid_3d_ran( kseed, pt3d, cd_type, pmean, pstd )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE grid_3d_ran ***
+      !!          
+      !! ** Purpose : Fill a 3D array with uncorrelated Gaussian noise.
+      !!
+      !! ** Method  : The value of kseed is the seed for the random number
+      !!              generator. On the first call to "grid_3d_ran" it should 
+      !!              be set to a large negative number.
+      !!
+      !!              Apply the appropriate grid-point mask and lateral 
+      !!              boundary conditions before exiting.
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-11  (A. Weaver)  
+      !!----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(INOUT) :: &
+         & kseed       ! Seed for random number generator
+      REAL, INTENT(INOUT), DIMENSION(jpi,jpj,jpk) :: &
+         & pt3d        ! 3D field
+      REAL(wp), INTENT(IN) :: &
+         & pmean, &    ! Mean of noise
+         & pstd        ! Standard deviation of noise
+ 
+      !! * Local declarations
+      CHARACTER(LEN=1), INTENT(IN) ::   &
+         & cd_type     ! Nature of pt3d grid-point
+                       !   = T , U  or V  grid-point
+      INTEGER  :: &
+         & ji, &
+         & jj, &
+         & jk
+
+      !--------------------------------------------------------------------
+      ! Fill in the 3D field with Gaussian noise
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               pt3d(ji,jj,jk) = gaustb( kseed, pstd, pmean )
+            END DO
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Apply masks and lateral boundary conditions
+      !--------------------------------------------------------------------
+
+      IF ( cd_type == 'T' ) THEN
+
+         pt3d(:,:,:) = pt3d(:,:,:) * tmask(:,:,:)
+         CALL lbc_lnk( pt3d, 'T',  1.0 )
+         
+      ELSEIF ( cd_type == 'U' ) THEN
+            
+         pt3d(:,:,:) = pt3d(:,:,:) * umask(:,:,:)
+         CALL lbc_lnk( pt3d, 'U', -1.0 )
+            
+      ELSEIF ( cd_type == 'V' ) THEN
+         
+         pt3d(:,:,:) = pt3d(:,:,:) * vmask(:,:,:)
+         CALL lbc_lnk( pt3d, 'V', -1.0 )
+
+      ELSEIF ( cd_type == 'S' ) THEN
+         CALL lbc_lnk( pt3d, 'S', 1.0 )
+
+      ENDIF
+
+   END SUBROUTINE grid_3d_ran
+      
+   SUBROUTINE grid_2d_ran_2d( kseed, pt2d, cd_type, pmean, pstd )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE grid_2d_ran_2d ***
+      !!          
+      !! ** Purpose : Fill a 2D (surface) array with uncorrelated Gaussian 
+      !!              noise.
+      !!
+      !! ** Method  : The value of kseed is the seed for the random number
+      !!              generator. On the first call to "grid_2d_ran_2d" it 
+      !!              should be set to a large negative number. 
+      !!             
+      !!              This version has a 2D seed array to allow reproducible 
+      !!              results for parallel execution.
+      !!
+      !!              The kseed array should be be initialized with a MPP 
+      !!              independent way. The mig, mjg values of each grid point
+      !!              can be used.
+      !!
+      !!              Apply the appropriate grid-point mask and lateral 
+      !!              boundary conditions before exiting.
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen) NEMOVAR version
+      !!        !  07-11  (A. Weaver) Treat one array only
+      !!----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(INOUT), DIMENSION(jpi,jpj) :: &
+         & kseed       ! Seed for random number generator
+      REAL, INTENT(INOUT), DIMENSION(jpi,jpj) :: &
+         & pt2d        ! 2D field
+      REAL(wp), INTENT(IN) :: &
+         & pmean, &    ! Mean of noise
+         & pstd        ! Standard deviation of noise
+
+      !! * Local declarations
+      CHARACTER(LEN=1), INTENT(IN) ::   &
+         & cd_type     ! Nature of pt2d grid-point
+                       !   = T , U  or V  grid-point
+      INTEGER :: &
+         & ji, &
+         & jj
+
+      !--------------------------------------------------------------------
+      ! Fill in the 2D field with Gaussian noise
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            pt2d(ji,jj) = gaustb_2d( ji, jj, kseed, pstd, pmean )
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Apply masks and lateral boundary conditions
+      !--------------------------------------------------------------------
+
+      IF ( cd_type == 'T' ) THEN
+ 
+         pt2d(:,:) = pt2d(:,:) * tmask(:,:,1)
+         CALL lbc_lnk( pt2d, 'T',  1.0 )
+
+      ELSEIF ( cd_type == 'U' ) THEN
+
+         pt2d(:,:) = pt2d(:,:) * umask(:,:,1)
+         CALL lbc_lnk( pt2d, 'U', -1.0 )
+
+      ELSEIF ( cd_type == 'V' ) THEN
+
+         pt2d(:,:) = pt2d(:,:) * vmask(:,:,1)
+         CALL lbc_lnk( pt2d, 'V', -1.0 )
+
+      ELSEIF ( cd_type == 'S' ) THEN
+         CALL lbc_lnk( pt2d, 'S', 1.0 )     
+          
+      ENDIF
+            
+   END SUBROUTINE grid_2d_ran_2d
+         
+   SUBROUTINE grid_3d_ran_2d( kseed, pt3d, cd_type, pmean, pstd )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE grid_3d_ran_2d ***
+      !!          
+      !! ** Purpose : Fill a 3D array with uncorrelated Gaussian noise.
+      !!
+      !! ** Method  : The value of kseed is the seed for the random number
+      !!              generator. On the first call to "grid_3d_ran_2d" it 
+      !!              should be set to a large negative number. 
+      !!              
+      !!              This version has a 2D seed array to allow reproducible 
+      !!              results for parallel execution.
+      !!             
+      !!              The kseed array should be be initialized with a MPP 
+      !!              independent way. The mig, mjg values of each grid point
+      !!              can be used.
+      !!
+      !!              Apply the appropriate grid-point mask and lateral 
+      !!              boundary conditions before exiting.
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen) NEMOVAR version
+      !!        !  07-11  (A. Weaver) Treat one array only
+      !!----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(INOUT), DIMENSION(jpi,jpj) :: &
+         & kseed       ! Seed for random number generator
+      REAL, INTENT(INOUT), DIMENSION(jpi,jpj,jpk) :: &
+         & pt3d        ! 3D field
+      REAL(wp), INTENT(IN) :: &
+         & pmean, &    ! Mean of noise
+         & pstd        ! Standard deviation of noise
+ 
+      !! * Local declarations
+      CHARACTER(LEN=1), INTENT(IN) ::   &
+         & cd_type     ! Nature of pt3d grid-point
+                       !   = T , U  or V  grid-point
+      INTEGER  :: &
+         & ji, &
+         & jj, &
+         & jk
+
+      !--------------------------------------------------------------------
+      ! Fill in the 3D field with Gaussian noise
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               pt3d(ji,jj,jk) = gaustb_2d( ji, jj, kseed, pstd, pmean )
+            END DO
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Apply masks and lateral boundary conditions
+      !--------------------------------------------------------------------
+
+      IF ( cd_type == 'T' ) THEN
+
+         pt3d(:,:,:) = pt3d(:,:,:) * tmask(:,:,:)
+         CALL lbc_lnk( pt3d, 'T',  1.0 )
+         
+      ELSEIF ( cd_type == 'U' ) THEN
+            
+         pt3d(:,:,:) = pt3d(:,:,:) * umask(:,:,:)
+         CALL lbc_lnk( pt3d, 'U', -1.0 )
+            
+      ELSEIF ( cd_type == 'V' ) THEN
+         
+         pt3d(:,:,:) = pt3d(:,:,:) * vmask(:,:,:)
+         CALL lbc_lnk( pt3d, 'V', -1.0 )
+
+      ELSEIF ( cd_type == 'S' ) THEN
+         CALL lbc_lnk( pt3d, 'S', 1.0 )    
+  
+      ENDIF
+
+   END SUBROUTINE grid_3d_ran_2d
+
+   SUBROUTINE grid_write_seed( cdfilename, kseed )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE grid_write_seed ***
+      !!          
+      !! ** Purpose : Write output 2d seed array
+      !!
+      !! ** Method  : IOM
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code based on iniwrk.F
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      CHARACTER(LEN=*), INTENT(IN) :: &
+         & cdfilename  ! File to be written
+      INTEGER, INTENT(IN), DIMENSION(jpi,jpj) :: &
+         & kseed       ! Seed array
+      !! * Local declarations
+      INTEGER :: &
+         & inum
+
+      ! Open the file
+
+      CALL iom_open( TRIM(cdfilename), inum, ldwrt = .TRUE., kiolib = jprstlib)
+
+      ! Write the seed
+   
+      CALL iom_rstput( 0, 0, inum, 'seed' , REAL(kseed) )
+     
+      ! Close the file
+
+      CALL iom_close( inum )
+      
+   END SUBROUTINE grid_write_seed
+
+   SUBROUTINE grid_2d_rd_sd_loc( kseed, pt2d, cd_type, pmean, pstd )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE grid_2d_rd_sd ***
+      !!          
+      !! ** Purpose : Fill a 2D (surface) array with uncorrelated Gaussian 
+      !!              noise.
+      !!
+      !! ** Method  : The value of kseed is an integer from which a seed is 
+      !!              generated for the random number
+      !!              and then call grid_random routine
+      !!
+      !!              Apply the appropriate grid-point mask and lateral 
+      !!              boundary conditions before exiting.
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  09-07  (F. Vigilant)  
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE par_oce       , ONLY: & ! Ocean space and time domain variables
+         & jpiglo
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kseed       ! Seed for random number generator
+      REAL, INTENT(INOUT), DIMENSION(jpi,jpj) :: &
+         & pt2d        ! 2D field
+      REAL(wp), INTENT(IN) :: &
+         & pmean, &    ! Mean of noise
+         & pstd        ! Standard deviation of noise
+
+      !! * Local declarations
+      CHARACTER(LEN=1), INTENT(IN) ::   &
+         & cd_type     ! Nature of pt2d grid-point
+                       !   = T , U  or V  grid-point
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d             ! 2D seed for the random number generator
+      INTEGER :: &
+         & ji, &
+         & jj
+
+      !--------------------------------------------------------------------
+      ! Generate the seed
+      !--------------------------------------------------------------------
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( kseed + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Generate the noise
+      !--------------------------------------------------------------------
+      CALL grid_random( iseed_2d, pt2d, cd_type, pmean, pstd )
+            
+   END SUBROUTINE grid_2d_rd_sd_loc
+
+   SUBROUTINE grid_3d_rd_sd_loc( kseed, pt3d, cd_type, pmean, pstd )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE grid_3d_rd_sd ***
+      !!          
+      !! ** Purpose : Fill a 3D array with uncorrelated Gaussian 
+      !!              noise.
+      !!
+      !! ** Method  : The value of kseed is an integer from which a seed is 
+      !!              generated for the random number
+      !!              and then call grid_random routine
+      !!
+      !!              Apply the appropriate grid-point mask and lateral 
+      !!              boundary conditions before exiting.
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  09-07  (F. Vigilant)  
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE par_oce       , ONLY: & ! Ocean space and time domain variables
+         & jpiglo
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kseed       ! Seed for random number generator
+      REAL, INTENT(INOUT), DIMENSION(jpi,jpj,jpk) :: &
+         & pt3d        ! 3D field
+      REAL(wp), INTENT(IN) :: &
+         & pmean, &    ! Mean of noise
+         & pstd        ! Standard deviation of noise
+
+      !! * Local declarations
+      CHARACTER(LEN=1), INTENT(IN) ::   &
+         & cd_type     ! Nature of pt2d grid-point
+                       !   = T , U  or V  grid-point
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d             ! 2D seed for the random number generator
+      INTEGER :: &
+         & ji, &
+         & jj
+
+      !--------------------------------------------------------------------
+      ! Generate the seed
+      !--------------------------------------------------------------------
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( kseed + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Generate the noise
+      !--------------------------------------------------------------------
+      CALL grid_random( iseed_2d, pt3d, cd_type, pmean, pstd )
+            
+   END SUBROUTINE grid_3d_rd_sd_loc
+
+
+END MODULE gridrandom
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/gridsum.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/gridsum.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/gridsum.F90	(revision 2578)
@@ -0,0 +1,403 @@
+MODULE gridsum
+   !!======================================================================
+   !!                       ***  MODULE gridsum  ***
+   !! NEMOVAR: Horizontal sum values
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !! max_value       : Find maximum value of interior points in a 2D/3D field
+   !! min_value       : Find minimum value of interior points in a 2D/3D field
+   !! global_sum      : Compute the global sum of a 2D/3D field
+   !! global_sum_weig : Compute the global weighted sum of a 2D/3D field
+   !! zonal_sum       : Compute the zonal sum of a 2D field
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind   ! Kind variables
+   USE dom_oce    ! Domain variables
+   USE lib_mpp    ! MPP stuff
+   USE mppsumtam  ! Reproducible sum
+   USE mpp_tam    ! MPP stuff
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+
+   PRIVATE
+
+   PUBLIC &
+      & max_value,       &
+      & min_value,       &
+      & global_sum,      &
+      & global_sum_weig, &
+      & zonal_sum
+   
+   !! * Interfaces
+
+   INTERFACE max_value
+      MODULE PROCEDURE max_value_2d
+      MODULE PROCEDURE max_value_3d
+   END INTERFACE
+
+   INTERFACE min_value
+      MODULE PROCEDURE min_value_2d
+      MODULE PROCEDURE min_value_3d
+   END INTERFACE
+
+   INTERFACE global_sum
+      MODULE PROCEDURE global_sum_2d
+      MODULE PROCEDURE global_sum_3d
+   END INTERFACE
+
+   INTERFACE global_sum_weig
+      MODULE PROCEDURE global_sum_weig_2d
+      MODULE PROCEDURE global_sum_weig_3d
+   END INTERFACE
+
+CONTAINS
+
+   FUNCTION max_value_2d( pfld )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE max_value_2d ***
+      !!          
+      !! ** Purpose : Find the global maximum of pfld
+      !!
+      !! ** Method  : Call the mpp_max routine, The result is 
+      !!              available on all processors
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) :: max_value_2d
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN) :: &
+         & pfld  ! Field to be averaged
+      !! * Local declarations
+      real(wp) :: &
+         & ztmp
+
+      ! Get max with mpp_max
+
+      ztmp = MAXVAL( pfld(nldi:nlei,nldj:nlej) )
+      IF( lk_mpp ) CALL mpp_max( ztmp )
+      max_value_2d = ztmp
+      
+   END FUNCTION max_value_2d
+
+   FUNCTION max_value_3d( pfld )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE max_value_3d ***
+      !!          
+      !! ** Purpose : Find the global maximum of pfld
+      !!
+      !! ** Method  : Call the mpp_max routine, The result is 
+      !!              available on all processors
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) :: max_value_3d
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(IN) :: &
+         & pfld  ! Field to be averaged
+      !! * Local declarations
+      real(wp) :: &
+         & ztmp
+
+      ! Get max with mpp_max
+
+      ztmp = MAXVAL( pfld(nldi:nlei,nldj:nlej,:) )
+      IF( lk_mpp ) CALL mpp_max( ztmp )
+      max_value_3d = ztmp
+      
+   END FUNCTION max_value_3d
+
+   FUNCTION min_value_2d( pfld )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE min_value_2d ***
+      !!          
+      !! ** Purpose : Find the global minimum of pfld
+      !!
+      !! ** Method  : Call the mpp_min routine, The result is 
+      !!              available on all processors
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) :: min_value_2d
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN) :: &
+         & pfld  ! Field to be averaged
+      !! * Local declarations
+      real(wp) :: &
+         & ztmp
+
+      ! Get min with mpp_min
+
+      ztmp = MINVAL( pfld(nldi:nlei,nldj:nlej) )
+      IF( lk_mpp ) CALL mpp_min(  ztmp )
+      min_value_2d = ztmp
+      
+   END FUNCTION min_value_2d
+
+   FUNCTION min_value_3d( pfld )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE min_value_3d ***
+      !!          
+      !! ** Purpose : Find the global minimum of pfld
+      !!
+      !! ** Method  : Call the mpp_min_real routine, The result is 
+      !!              available on all processors
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) :: min_value_3d
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(IN) :: &
+         & pfld  ! Field to be averaged
+      !! * Local declarations
+      real(wp) :: &
+         & ztmp
+
+      ! Get min with mpp_min
+
+      ztmp = MINVAL(pfld(nldi:nlei,nldj:nlej,:))
+      IF( lk_mpp ) CALL mpp_min( ztmp )
+      min_value_3d = ztmp
+      
+   END FUNCTION min_value_3d
+
+   FUNCTION global_sum_2d( pfld )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE global_sum_2d ***
+      !!          
+      !! ** Purpose : Compute the global sum of pfld
+      !!
+      !! ** Method  : Call the mppsum routine, The result is available
+      !!              on all processors
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) :: global_sum_2d
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN) :: &
+         & pfld  ! Field to be averaged
+      !! * Local declarations
+
+      ! Compute sum using the mppsum module
+
+      global_sum_2d = mpp_sum_inter( PACK( pfld(nldi:nlei,nldj:nlej), .TRUE. ), &
+         &                          ( nlei - nldi + 1 ) * ( nlej - nldj + 1 ) )
+      
+   END FUNCTION global_sum_2d
+   
+   FUNCTION global_sum_3d( pfld )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE global_sum_3d ***
+      !!          
+      !! ** Purpose : Compute the global sum of pfld
+      !!
+      !! ** Method  : Call the mppsum routine, The result is available
+      !!              on all processors
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) :: global_sum_3d
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(IN) :: &
+         & pfld  ! Field to be averaged
+      !! * Local declarations
+
+      ! Compute sum using the mppsum module
+
+      global_sum_3d = mpp_sum_inter( PACK( pfld(nldi:nlei,nldj:nlej,1:jpk), .TRUE. ), &
+         &                          ( nlei - nldi + 1 ) * ( nlej - nldj + 1 ) * jpk )
+      
+   END FUNCTION global_sum_3d
+
+   FUNCTION global_sum_weig_2d( pfld, pweig )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE global_sum_weig_2d ***
+      !!          
+      !! ** Purpose : Compute the global sum of pfld weighted by pweig
+      !!
+      !! ** Method  : Call the mppsum routine, The result is available
+      !!              on all processors
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) :: global_sum_weig_2d
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN) :: &
+         & pfld, & ! Field to be averaged
+         & pweig 
+      !! * Local declarations
+      REAL(wp), DIMENSION(jpi,jpj) :: &
+         & zwrk
+
+      ! Apply wieghts
+
+      zwrk(:,:) = pfld(:,:) * pweig(:,:)
+
+      ! Compute sum using the mppsum module
+
+      global_sum_weig_2d = mpp_sum_inter( PACK( zwrk(nldi:nlei,nldj:nlej), &
+         &                                      .TRUE. ),                  &
+         &                                ( nlei - nldi + 1 ) *            &
+         &                                ( nlej - nldj + 1 ) )
+      
+   END FUNCTION global_sum_weig_2d
+
+   FUNCTION global_sum_weig_3d( pfld, pweig )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE global_sum_weig_2d ***
+      !!          
+      !! ** Purpose : Compute the global sum of pfld weighted by pweig
+      !!
+      !! ** Method  : Call the mppsum routine, The result is available
+      !!              on all processors
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) :: global_sum_weig_3d
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(IN) :: &
+         & pfld, & ! Field to be averaged
+         & pweig 
+      !! * Local declarations
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: &
+         & zwrk
+
+      ! Apply wieghts
+
+      zwrk(:,:,:) = pfld(:,:,:) * pweig(:,:,:)
+
+      ! Compute sum using the mppsum module
+
+      global_sum_weig_3d = mpp_sum_inter( PACK( zwrk(nldi:nlei,nldj:nlej,1:jpk), &
+         &                                      .TRUE. ),                        &
+         &                                ( nlei - nldi + 1 ) *                  &
+         &                                ( nlej - nldj + 1 ) * jpk )
+      
+   END FUNCTION global_sum_weig_3d
+
+   SUBROUTINE zonal_sum( pfld, pweig, pout )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE zonal_sum ***
+      !!          
+      !! ** Purpose : Compute the zonal sum of pfld weighted by pweig
+      !!
+      !! ** Method  : Put local data unto a global grid and call the 
+      !!              mppsum routine for all latitudes. 
+      !!
+      !!              This should be done in a more optimum way !!!
+      !! 
+      !!              The result is available on all processors
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN) :: &
+         & pfld, & ! Field to be averaged
+         & pweig 
+      REAL(wp), DIMENSION(jpjglo), INTENT(OUT) :: &
+         & pout
+      !! * Local declarations
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zwrk
+      INTEGER :: &
+         & ji, &
+         & jj, &
+         & ii, &
+         & ij
+      
+
+
+      ! Allocate and fill global array with local input data
+
+      ALLOCATE( &
+         & zwrk(jpiglo,jpjglo) &
+         & )
+
+      zwrk(:,:) = 0.0
+      
+      DO jj = nldj, nlej
+
+         ij = mjg(jj)
+
+         DO ji = nldi, nlei
+
+            ii = mig(ji)
+
+            zwrk(ii,ij) = pfld(ji,jj) * pweig(ji,jj)
+
+         ENDDO
+
+      ENDDO
+
+      ! Sum individual latitudes
+
+      DO jj = 1, jpjglo
+
+         
+         pout(jj) = mpp_sum_inter( zwrk(:,jj), jpiglo )
+
+      ENDDO
+
+      ! Deallocate the work array
+
+      DEALLOCATE(zwrk)
+
+   END SUBROUTINE zonal_sum
+
+END MODULE gridsum
+
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/istate_mod.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/istate_mod.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/istate_mod.F90	(revision 2578)
@@ -0,0 +1,107 @@
+MODULE istate_mod
+   !!======================================================================
+   !!                     ***  MODULE  istate  ***
+   !! Ocean state   :  initial state setting
+   !!=====================================================================
+   !! History :   4.0  !  89-12  (P. Andrich)  Original code
+   !!             5.0  !  91-11  (G. Madec)  rewritting
+   !!             6.0  !  96-01  (G. Madec)  terrain following coordinates
+   !!             8.0  !  01-09  (M. Levy, M. Ben Jelloul)  istate_eel
+   !!             8.0  !  01-09  (M. Levy, M. Ben Jelloul)  istate_uvg
+   !!             9.0  !  03-08  (G. Madec)  F90: Free form, modules
+   !!             9.0  !  03-09  (G. Madec, C. Talandier)  add EEL R5
+   !!             9.0  !  04-05  (A. Koch-Larrouy)  istate_gyre 
+   !!             9.0  !  06-07  (S. Masson)  distributed restart using iom
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   istate_init   : initial state setting
+   !!   istate_tem    : analytical profile for initial Temperature
+   !!   istate_sal    : analytical profile for initial Salinity
+   !!   istate_eel    : initial state setting of EEL R5 configuration
+   !!   istate_gyre   : initial state setting of GYRE configuration
+   !!   istate_uvg    : initial velocity in geostropic balance
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and active tracers 
+   USE dom_oce         ! ocean space and time domain 
+   USE daymod          ! 
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE phycst          ! physical constants
+   USE dtatem          ! temperature data                 (dta_tem routine)
+   USE dtasal          ! salinity data                    (dta_sal routine)
+   USE restart         ! ocean restart                   (rst_read routine)
+   USE in_out_manager  ! I/O manager
+   USE iom
+   USE c1d             ! re-initialization of u-v mask for the 1D configuration
+   USE zpshde          ! partial step: hor. derivative (zps_hde routine)
+   USE eosbn2          ! equation of state            (eos bn2 routine)
+   USE domvvl          ! varying vertical mesh
+   USE dynspg_oce      ! pressure gradient schemes
+   USE dynspg_flt      ! pressure gradient schemes
+   USE dynspg_exp      ! pressure gradient schemes
+   USE dynspg_ts       ! pressure gradient schemes
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   istate_p   ! routine called by step_tam.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE istate_p
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE istate_init  ***
+      !! 
+      !! ** Purpose :   Initialization of the dynamics and tracer fields.
+      !!----------------------------------------------------------------------
+      USE eosbn2          ! eq. of state, Brunt Vaisala frequency (eos     routine)
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'istate_ini_tst : Initialization of the dynamics and tracers'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+
+      rhd  (:,:,:) = 0.e0
+      rhop (:,:,:) = 0.e0
+      rn2  (:,:,:) = 0.e0 
+
+      IF( ln_rstart ) THEN                    ! Restart from a file
+         !                                    ! -------------------
+         neuler = 1                              ! Set time-step indicator at nit000 (leap-frog)
+         CALL rst_read                           ! Read the restart file
+         CALL day_init                           ! model calendar (using both namelist and restart infos)
+      ELSE
+            CALL ctl_stop( ' You should not have seen this error message ' )
+      ENDIF
+
+      IF( lk_vvl .OR. lk_agrif ) THEN
+            CALL ctl_stop( ' You should not have seen this error message ' )
+      ENDIF
+
+      IF( lk_vvl ) THEN
+            CALL ctl_stop( ' You should not have seen this error message ' )
+      ENDIF
+!!! Temporary fix to save emp
+         IF( ln_rstart ) THEN
+            IF( lk_dynspg_flt )   CALL flt_rst( nit000, 'READ' )      ! read or initialize the following fields
+         END IF
+
+      !                                       ! Vertical velocity
+      !                                       ! -----------------
+
+!      IF( .NOT. lk_vvl )    CALL wzv( nit000 )                         ! from horizontal divergence
+      !
+   END SUBROUTINE istate_p
+
+
+   !!=====================================================================
+END MODULE istate_mod
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/istate_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/istate_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/istate_tam.F90	(revision 2578)
@@ -0,0 +1,805 @@
+MODULE istate_tam
+#ifdef key_tam
+   !!======================================================================
+   !!                     ***  MODULE  istate_tam  ***
+   !! Ocean state   :  initial state setting
+   !!                  Tangent and Adjoint Module
+   !!=====================================================================
+   !! History of the direct module:
+   !!             4.0  !  89-12  (P. Andrich)  Original code
+   !!             5.0  !  91-11  (G. Madec)  rewritting
+   !!             6.0  !  96-01  (G. Madec)  terrain following coordinates
+   !!             8.0  !  01-09  (M. Levy, M. Ben Jelloul)  istate_eel
+   !!             8.0  !  01-09  (M. Levy, M. Ben Jelloul)  istate_uvg
+   !!             9.0  !  03-08  (G. Madec)  F90: Free form, modules
+   !!             9.0  !  03-09  (G. Madec, C. Talandier)  add EEL R5
+   !!             9.0  !  04-05  (A. Koch-Larrouy)  istate_gyre 
+   !!             9.0  !  06-07  (S. Masson)  distributed restart using iom
+   !! History of the T&A module:
+   !!             9.0  !  09-04  (F. Vigilant) TAM of the 06-07 version
+   !!             9.0  !  10-05  (A. Vidard) TAM - NEMO 3.2
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   istate_init_tan : initial state setting for the tangent model
+   !!----------------------------------------------------------------------
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+  USE par_oce        , ONLY: & ! Ocean space and time domain variables
+      & jpi, jpj, jpk, jpiglo
+   USE oce_tam ! ocean dynamics and active tracers 
+   USE oce           , ONLY: & ! ocean dynamics and active tracers 
+      & tb, sb
+   USE dom_oce       , ONLY: & ! ocean space and time domain 
+      & neuler, ln_zps, mig, &
+      & mjg , nldi, nldj,    &
+      & nlei, nlej, lk_vvl,  &
+      & e1t, e2t, e1u, e2u,  &
+      & e1v, e2v,            &
+# if defined key_vvl
+      & e3t_1,               &
+# else
+#  if defined key_zco
+      & e3t_0, e3w_0,        &
+#  else
+      & e3u, e3v, e3t, e3w,  &
+#  endif
+# endif
+      & tmask, umask, vmask
+   USE daymod        , ONLY: &
+      & day_init
+   USE c1d           , ONLY: &
+      & lk_c1d
+   USE restart       , ONLY: & ! ocean restart
+      & numror             
+   USE in_out_manager, ONLY: & ! I/O manager
+      & numout, lwp, nit000
+   USE zpshde_tam    , ONLY: & ! partial step: hor. derivative (zps_hde routine)
+      & zps_hde_tan,         &
+      & zps_hde_adj
+   USE eosbn2_tam    , ONLY: &
+      & eos_tan, eos_adj
+   USE tstool_tam    , ONLY: &
+      & prntst_adj,          &
+      & stds  , stdt, stdr,  &
+      & stdssh, stdu, stdv
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld,     ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   USE paresp        , ONLY: & ! Normalized energy weights            
+      & wesp_ssh
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   istate_init_tan       ! routine called by step.F90
+   PUBLIC   istate_init_adj       ! routine called by step.F90
+   PUBLIC   istate_init_adj_tst   ! routine called by tst.F90
+    
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE istate_init_tan
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE istate_init Tangent ***
+      !! 
+      !! ** Purpose :   Initialization of the dynamics and tracer fields.
+      !!----------------------------------------------------------------------
+      USE eosbn2_tam          ! eq. of state, Brunt Vaisala frequency (eos     routine)
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'istate_ini_tan : Initialization of the dynamics and tracers'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+
+      rhd_tl  (:,:,:) = 0.0_wp
+      rhop_tl (:,:,:) = 0.0_wp
+      rn2_tl  (:,:,:) = 0.0_wp
+
+      !                                    ! Start from rest
+      !                                    ! ---------------
+      numror = 0                              ! define numror = 0 -> no restart file to read
+      neuler = 0                              ! Set time-step indicator at nit000 (euler forward)
+      CALL day_init                           ! model calendar (using both namelist and restart infos)
+      !                                       ! Initialization of ocean to zero
+
+      !     before fields       !       now fields          
+      ub_tl   (:,:,:) = un_tl   (:,:,:)    
+      vb_tl   (:,:,:) = vn_tl   (:,:,:)    
+      tb_tl   (:,:,:) = tn_tl   (:,:,:)
+      sb_tl   (:,:,:) = sn_tl   (:,:,:)
+      sshb_tl (  :,:) = sshn_tl (  :,:)
+      rotb_tl (:,:,:) = rotn_tl (:,:,:)  
+      hdivb_tl(:,:,:) = hdivn_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 )
+         
+   END SUBROUTINE istate_init_tan
+
+   SUBROUTINE istate_init_adj
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE istate_init  Adjoint Module ***
+      !! 
+      !! ** Purpose :   Initialization of the dynamics and tracer fields.
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE eosbn2_tam          ! eq. of state, Brunt Vaisala frequency (eos     routine)
+
+      !! * Local declarations
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'istate_ini_adj : Initialization of the dynamics and tracers'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+
+      neuler=0
+
+      IF( ln_zps .AND. .NOT. lk_c1d )   &
+            &             CALL zps_hde_adj( nit000, tb, sb, tb_ad, sb_ad, rhd_ad,  &  ! Partial steps: before Horizontal DErivative
+            &                                  gtu_ad, gsu_ad, gru_ad,             &  ! of t, s, rd at the bottom ocean level
+            &                                  gtv_ad, gsv_ad, grv_ad )
+         
+
+      CALL eos_adj( tb, sb, tb_ad, sb_ad, rhd_ad, rhop_ad )        ! before potential and in situ densities
+
+      !     before fields       !       now fields          
+      un_ad   (:,:,:) = un_ad(:,:,:) + ub_ad (:,:,:)
+      ub_ad   (:,:,:) = 0.0_wp
+
+      vn_ad   (:,:,:) = vn_ad(:,:,:) + vb_ad (:,:,:)
+      vb_ad   (:,:,:) = 0.0_wp
+
+      tn_ad   (:,:,:) = tn_ad(:,:,:) + tb_ad (:,:,:)
+      tb_ad   (:,:,:) = 0.0_wp
+
+      sn_ad   (:,:,:) = sn_ad(:,:,:) + sb_ad (:,:,:)
+      sb_ad   (:,:,:) = 0.0_wp
+
+      sshn_ad   (:,:  ) = sshn_ad(:,:  ) + sshb_ad (:,:  )
+      sshb_ad   (:,:  ) = 0.0_wp
+
+      rotn_ad (:,:,:) = rotn_ad(:,:,:) + rotb_ad (:,:,:)
+      rotb_ad (:,:,:) = 0.0_wp
+
+      hdivn_ad(:,:,:) = hdivn_ad(:,:,:) + hdivb_ad (:,:,:)
+      hdivb_ad(:,:,:) = 0.0_wp
+      !
+
+
+      rhd_ad  (:,:,:) = 0.0_wp
+      rhop_ad (:,:,:) = 0.0_wp
+      rn2_ad  (:,:,:) = 0.0_wp 
+
+      !
+   END SUBROUTINE istate_init_adj
+
+   SUBROUTINE istate_init_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE istate_init_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 2009-05 (F. Vigilant)
+      !!        ! 2010-05 (A. Vidard) Update for NEMO 3.2
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+
+      INTEGER ::         &
+         & ji,           &        ! dummy loop indices
+         & jj,           &        
+         & jk
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+
+      !! * Local declarations
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & ztn_tlin,     & ! Tangent input: temperature
+         & zsn_tlin,     & ! Tangent input: salinity
+         & zun_tlin,     & ! Tangent input: velocity
+         & zvn_tlin,     & ! Tangent input: velocity
+         & zrotn_tlin,   & ! Tangent input: rotational
+         & zdivn_tlin,   & ! Tangent input: divergence
+         & ztn_adout,    & ! Adjoint output: temperature
+         & zsn_adout,    & ! Adjoint output: salinity
+         & zun_adout,    & ! Adjoint output: velocity
+         & zvn_adout,    & ! Adjoint output: velocity
+         & zrotn_adout,  & ! adjoint output: rotational
+         & zdivn_adout,  & ! adjoint output: divergence
+         & ztb_tlout,    & ! Tangent output: temperature
+         & zsb_tlout,    & ! Tangent output: salinity
+         & zub_tlout,    & ! Tangent output: velocity
+         & zvb_tlout,    & ! Tangent output: velocity 
+         & zrhd_tlout,   & ! Tangent output: 
+         & zrhop_tlout,  & ! Tangent output:
+         & zrotb_tlout,  & ! Tangent output: 
+         & zdivb_tlout,  & ! Tangent output:
+         & zrn2_tlout,   & ! Tangent output:
+         & zrhd_adin,    & ! Adjoint input:
+         & zrhop_adin,   & ! Adjoint input:
+         & ztb_adin,     & ! Adjoint input: temperature
+         & zsb_adin,     & ! Adjoint input: salinity
+         & zub_adin,     & ! Adjoint input: velocity
+         & zvb_adin,     & ! Adjoint input: velocity
+         & zrotb_adin,   & ! Adjoint input:
+         & zdivb_adin,   & ! Adjoint input:
+         & zrn2_adin,    & ! Adjoint input:
+         & z3r             ! 3D random field
+
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zsshn_tlin,   & ! Tangent input : horizontal gradient
+         & zsshb_tlout,  & ! Tangent output: horizontal gradient
+         & zgtu_tlout,   & ! Tangent output: horizontal gradient
+         & zgtv_tlout,   & ! Tangent output: horizontal gradient
+         & zgsu_tlout,   & ! Tangent output: horizontal gradient
+         & zgsv_tlout,   & ! Tangent output: horizontal gradient
+         & zgru_tlout,   & ! Tangent output: horizontal gradient
+         & zgrv_tlout,   & ! Tangent output: horizontal gradient
+         & zgtu_adin,    & ! Adjoint input : horizontal gradient
+         & zgtv_adin,    & ! Adjoint input : horizontal gradient
+         & zgsu_adin,    & ! Adjoint input : horizontal gradient
+         & zgsv_adin,    & ! Adjoint input : horizontal gradient
+         & zgru_adin,    & ! Adjoint input : horizontal gradient
+         & zgrv_adin,    & ! Adjoint input : horizontal gradient
+         & zsshb_adin,   & ! Adjoint input : horizontal gradient 
+         & zsshn_adout,  & ! Adjoint output : horizontal gradient
+         & z2r             ! 2D random field
+
+      REAL(KIND=wp) ::   &
+                           ! random field standard deviation for:
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp1_1,       & !   scalar product components
+         & zsp1_2,       & 
+         & zsp1_3,       & !   scalar product components
+         & zsp1_4,       &  
+         & zsp1_5,       & !   scalar product components
+         & zsp1_6,       & 
+         & zsp1_7,       & !   scalar product components
+         & zsp1_8,       &
+         & zsp1_9,       &
+         & zsp1_10,      &
+         & zsp1_11,      &
+         & zsp1_12,      &
+         & zsp1_13,      &
+         & zsp1_14,      &
+         & zsp1_15,      &
+         & zsp1_16,      &
+         & zsp2,         & ! scalar product involving the adjoint routine
+         & zsp2_1,       & !   scalar product components
+         & zsp2_2,       & 
+         & zsp2_3,       &
+         & zsp2_4,       &
+         & zsp2_5,       &
+         & zsp2_6,       &
+         & zsp2_7
+
+      CHARACTER (LEN=14) :: &
+         & cl_name
+
+      ! Allocate memory
+      ALLOCATE( &
+         & ztn_tlin(jpi,jpj,jpk),     & 
+         & zsn_tlin(jpi,jpj,jpk),     & 
+         & zun_tlin(jpi,jpj,jpk),     & 
+         & zvn_tlin(jpi,jpj,jpk),     &
+         & zsshn_tlin(jpi,jpj),       &  
+         & zrotn_tlin(jpi,jpj,jpk),   &
+         & zdivn_tlin(jpi,jpj,jpk),   &
+         & ztn_adout(jpi,jpj,jpk),    & 
+         & zsn_adout(jpi,jpj,jpk),    &
+         & zun_adout(jpi,jpj,jpk),    & 
+         & zvn_adout(jpi,jpj,jpk),    &
+         & zrotn_adout(jpi,jpj,jpk),  &
+         & zdivn_adout(jpi,jpj,jpk),  &
+         & zsshn_adout(jpi, jpj),     & 
+         & z3r(jpi,jpj,jpk),          & 
+         & z2r(jpi,jpj),              &        
+         & zub_tlout(jpi,jpj,jpk),    & 
+         & zvb_tlout(jpi,jpj,jpk),    &
+         & zsb_tlout(jpi,jpj,jpk),    & 
+         & ztb_tlout(jpi,jpj,jpk),    &
+         & zrotb_tlout(jpi,jpj,jpk),  &
+         & zdivb_tlout(jpi,jpj,jpk),  &
+         & zrn2_tlout(jpi,jpj,jpk),   &
+         & zsshb_tlout(jpi,jpj),      &
+         & zgtu_tlout(jpi,jpj),       & 
+         & zgtv_tlout(jpi,jpj),       & 
+         & zgsu_tlout(jpi,jpj),       & 
+         & zgsv_tlout(jpi,jpj),       & 
+         & zgru_tlout(jpi,jpj),       & 
+         & zgrv_tlout(jpi,jpj),       &
+         & zrhd_tlout(jpi,jpj,jpk),   & 
+         & zrhop_tlout(jpi,jpj,jpk),  &
+         & zub_adin(jpi,jpj,jpk),     & 
+         & zvb_adin(jpi,jpj,jpk),     &
+         & zsb_adin(jpi,jpj,jpk),     & 
+         & ztb_adin(jpi,jpj,jpk),     &
+         & zrotb_adin(jpi,jpj,jpk),   &
+         & zdivb_adin(jpi,jpj,jpk),   &
+         & zrn2_adin(jpi,jpj,jpk),    &
+         & zsshb_adin(jpi,jpj),       &
+         & zgtu_adin(jpi,jpj),        & 
+         & zgtv_adin(jpi,jpj),        & 
+         & zgsu_adin(jpi,jpj),        & 
+         & zgsv_adin(jpi,jpj),        & 
+         & zgru_adin(jpi,jpj),        & 
+         & zgrv_adin(jpi,jpj),        &
+         & zrhd_adin(jpi,jpj,jpk),    &
+         & zrhop_adin(jpi,jpj,jpk)    &
+         & ) 
+
+
+      !=============================================================
+      ! 1) dx = ( T ) and dy = ( T )
+      !=============================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+      ztn_tlin    = 0.0_wp      
+      zsn_tlin    = 0.0_wp      
+      zun_tlin    = 0.0_wp      
+      zvn_tlin    = 0.0_wp     
+      zsshn_tlin  = 0.0_wp         
+      zrotn_tlin  = 0.0_wp   
+      zdivn_tlin  = 0.0_wp   
+      ztn_adout   = 0.0_wp     
+      zsn_adout   = 0.0_wp    
+      zun_adout   = 0.0_wp     
+      zvn_adout   = 0.0_wp    
+      zrotn_adout = 0.0_wp  
+      zdivn_adout = 0.0_wp  
+      zsshn_adout = 0.0_wp    
+      zub_tlout   = 0.0_wp     
+      zvb_tlout   = 0.0_wp    
+      zsb_tlout   = 0.0_wp     
+      ztb_tlout   = 0.0_wp    
+      zrotb_tlout = 0.0_wp  
+      zdivb_tlout = 0.0_wp  
+      zrn2_tlout  = 0.0_wp   
+      zsshb_tlout = 0.0_wp      
+      zgtu_tlout  = 0.0_wp        
+      zgtv_tlout  = 0.0_wp        
+      zgsu_tlout  = 0.0_wp        
+      zgsv_tlout  = 0.0_wp        
+      zgru_tlout  = 0.0_wp        
+      zgrv_tlout  = 0.0_wp       
+      zrhd_tlout  = 0.0_wp    
+      zrhop_tlout = 0.0_wp  
+      zub_adin    = 0.0_wp      
+      zvb_adin    = 0.0_wp     
+      zsb_adin    = 0.0_wp      
+      ztb_adin    = 0.0_wp     
+      zrotb_adin  = 0.0_wp   
+      zdivb_adin  = 0.0_wp   
+      zrn2_adin   = 0.0_wp    
+      zsshb_adin  = 0.0_wp       
+      zgtu_adin   = 0.0_wp         
+      zgtv_adin   = 0.0_wp         
+      zgsu_adin   = 0.0_wp         
+      zgsv_adin   = 0.0_wp         
+      zgru_adin   = 0.0_wp         
+      zgrv_adin   = 0.0_wp        
+      zrhd_adin   = 0.0_wp    
+      zrhop_adin  = 0.0_wp
+
+      tn_tl      (:,:,:) = 0.0_wp
+      sn_tl      (:,:,:) = 0.0_wp
+      un_tl      (:,:,:) = 0.0_wp
+      vn_tl      (:,:,:) = 0.0_wp
+      rotn_tl    (:,:,:) = 0.0_wp
+      hdivn_tl   (:,:,:) = 0.0_wp
+      sshn_tl    (:,:  ) = 0.0_wp
+      tb_tl      (:,:,:) = 0.0_wp
+      sb_tl      (:,:,:) = 0.0_wp
+      ub_tl      (:,:,:) = 0.0_wp
+      vb_tl      (:,:,:) = 0.0_wp
+      sshb_tl    (:,:  ) = 0.0_wp
+      rhd_tl     (:,:,:) = 0.0_wp
+      rhop_tl    (:,:,:) = 0.0_wp
+      gtu_tl     (:,:  ) = 0.0_wp
+      gsu_tl     (:,:  ) = 0.0_wp
+      gru_tl     (:,:  ) = 0.0_wp
+      gtv_tl     (:,:  ) = 0.0_wp
+      gsv_tl     (:,:  ) = 0.0_wp
+      grv_tl     (:,:  ) = 0.0_wp
+      tb_ad      (:,:,:) = 0.0_wp
+      sb_ad      (:,:,:) = 0.0_wp
+      ub_ad      (:,:,:) = 0.0_wp
+      vb_ad      (:,:,:) = 0.0_wp
+      sshb_ad    (:,:  ) = 0.0_wp
+      tn_ad      (:,:,:) = 0.0_wp
+      sn_ad      (:,:,:) = 0.0_wp
+      un_ad      (:,:,:) = 0.0_wp
+      vn_ad      (:,:,:) = 0.0_wp
+      sshn_ad    (:,:  ) = 0.0_wp
+      gtu_ad     (:,:  ) = 0.0_wp
+      gsu_ad     (:,:  ) = 0.0_wp
+      gtv_ad     (:,:  ) = 0.0_wp
+      gsv_ad     (:,:  ) = 0.0_wp
+
+      ! Warning, following variables used by istate
+      hdivn_tl           = 0.0_wp
+      hdivb_tl           = 0.0_wp
+      rotn_tl            = 0.0_wp
+      rotb_tl            = 0.0_wp
+      hdivn_ad           = 0.0_wp
+      hdivb_ad           = 0.0_wp
+      rotn_ad            = 0.0_wp
+      rotb_ad            = 0.0_wp
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 284035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdt )
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               ztn_tlin(ji,jj,jk) = z3r(ji,jj,jk)  
+            END DO
+         END DO
+      END DO 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - (  471426 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stds )
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zsn_tlin(ji,jj,jk) = z3r(ji,jj,jk)  
+            END DO
+         END DO
+      END DO 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 395703 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdr )
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zrotn_tlin(ji,jj,jk) = z3r(ji,jj,jk)  
+            END DO
+         END DO
+      END DO 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 327153 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdr )
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zdivn_tlin(ji,jj,jk) = z3r(ji,jj,jk)  
+            END DO
+         END DO
+      END DO 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 12672456 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z2r, 'T', 0.0_wp, stdssh )
+      DO jj = nldj, nlej
+         DO ji = nldi, nlei
+            zsshn_tlin(ji,jj) = z2r(ji,jj)  
+         END DO
+      END DO 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 456953 + &
+              &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'U', 0.0_wp, stdu )
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zun_tlin(ji,jj,jk) = z3r(ji,jj,jk)  
+            END DO
+         END DO
+      END DO
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 3434334 + &
+              &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, z3r, 'V', 0.0_wp, stdv )
+      DO jk = 1, jpk
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zvn_tlin(ji,jj,jk) = z3r(ji,jj,jk)  
+            END DO
+         END DO
+      END DO
+
+      tn_tl  (:,:,:) = ztn_tlin  (:,:,:)
+      sn_tl  (:,:,:) = zsn_tlin  (:,:,:)
+      rotn_tl(:,:,:) = zrotn_tlin(:,:,:)
+      hdivn_tl(:,:,:)= zdivn_tlin(:,:,:)
+      sshn_tl(:,:  ) = zsshn_tlin(:,:  )
+      un_tl  (:,:,:) = zun_tlin  (:,:,:)
+      vn_tl  (:,:,:) = zvn_tlin  (:,:,:)
+
+     !--------------------------------------------------------------------
+     ! Call the tangent routine: dy = L dx
+     !--------------------------------------------------------------------
+
+     CALL istate_init_tan
+
+     zrhd_tlout  (:,:,:) = rhd_tl  (:,:,:)
+     zrhop_tlout (:,:,:) = rhop_tl (:,:,:)
+     zgtu_tlout  (:,:  ) = gtu_tl  (:,:  )
+     zgtv_tlout  (:,:  ) = gtv_tl  (:,:  )
+     zgru_tlout  (:,:  ) = gru_tl  (:,:  )
+     zgrv_tlout  (:,:  ) = grv_tl  (:,:  )
+     zgsu_tlout  (:,:  ) = gsu_tl  (:,:  )
+     zgsv_tlout  (:,:  ) = gsv_tl  (:,:  )
+     zsshb_tlout (:,:  ) = sshb_tl (:,:  )
+     ztb_tlout   (:,:,:) = tb_tl   (:,:,:)
+     zsb_tlout   (:,:,:) = sb_tl   (:,:,:)
+     zub_tlout   (:,:,:) = ub_tl   (:,:,:)
+     zvb_tlout   (:,:,:) = vb_tl   (:,:,:)
+     zsshb_tlout (:,:  ) = sshb_tl (:,:  )
+
+     !--------------------------------------------------------------------
+     ! Initialize the adjoint variables: dy^* = W dy
+     !--------------------------------------------------------------------
+
+     DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zrhd_adin(ji,jj,jk)  = zrhd_tlout(ji,jj,jk) &
+                 &                 * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)&
+                 &                 * tmask(ji,jj,jk)
+              zrhop_adin(ji,jj,jk) = zrhop_tlout(ji,jj,jk) &
+                 &                 * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)&
+                 &                 * tmask(ji,jj,jk)
+              zrn2_adin(ji,jj,jk)  = zrn2_tlout(ji,jj,jk) &
+                 &                 * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)&
+                 &                 * tmask(ji,jj,jk)
+              zrotb_adin(ji,jj,jk) = zrotb_tlout(ji,jj,jk) &
+                 &                 * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)&
+                 &                 * tmask(ji,jj,jk)
+              zdivb_adin(ji,jj,jk) = zdivb_tlout(ji,jj,jk) &
+                 &                 * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)&
+                 &                 * tmask(ji,jj,jk)
+           END DO
+        END DO
+     END DO
+     DO jj = nldj, nlej
+        DO ji = nldi, nlei
+           zgtu_adin(ji,jj) = zgtu_tlout(ji,jj) &
+              &             * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,1) &
+              &             * umask(ji,jj,1)
+           zgsu_adin(ji,jj) = zgsu_tlout(ji,jj) &
+              &             * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,1) &
+              &             * umask(ji,jj,1)
+           zgru_adin(ji,jj) = zgru_tlout(ji,jj) &
+              &             * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,1) &
+              &             * umask(ji,jj,1)
+           zgtv_adin(ji,jj) = zgtv_tlout(ji,jj) &
+              &             * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,1) &
+              &             * vmask(ji,jj,1)
+           zgsv_adin(ji,jj) = zgsv_tlout(ji,jj) &
+              &             * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,1) &
+              &             * vmask(ji,jj,1)
+           zgrv_adin(ji,jj) = zgrv_tlout(ji,jj) &
+              &             * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,1) &
+              &             * vmask(ji,jj,1)
+        END DO
+     END DO
+     DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              ztb_adin(ji,jj,jk)   = ztb_tlout(ji,jj,jk) &
+                 &                 * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)&
+                 &                 * tmask(ji,jj,jk)
+           END DO
+        END DO
+     END DO
+     DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zsb_adin(ji,jj,jk)   = zsb_tlout(ji,jj,jk) &
+                 &                 * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)&
+                 &                 * tmask(ji,jj,jk)
+           END DO
+        END DO
+     END DO
+     DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zub_adin(ji,jj,jk)   = zub_tlout(ji,jj,jk) &
+                 &                 * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk)&
+                 &                 * umask(ji,jj,jk)
+           END DO
+        END DO
+     END DO
+     DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              zvb_adin(ji,jj,jk)   = zvb_tlout(ji,jj,jk) &
+                 &                 * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk)&
+                 &                 * vmask(ji,jj,jk)
+           END DO
+        END DO
+     END DO
+     DO jj = nldj, nlej
+        DO ji = nldi, nlei
+           zsshb_adin(ji,jj)    = zsshb_tlout(ji,jj) &
+              &                 * e1t(ji,jj) * e2t(ji,jj) * wesp_ssh &
+              &                 * tmask(ji,jj,1)
+        END DO
+     END DO
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1_1    = DOT_PRODUCT( zrhd_tlout   , zrhd_adin   )
+      zsp1_2    = DOT_PRODUCT( zrhop_tlout  , zrhop_adin  )
+      zsp1_3    = DOT_PRODUCT( zgtu_tlout   , zgtu_adin   )
+      zsp1_4    = DOT_PRODUCT( zgru_tlout   , zgru_adin   )
+      zsp1_5    = DOT_PRODUCT( zgsu_tlout   , zgsu_adin   )
+      zsp1_6    = DOT_PRODUCT( zgtv_tlout   , zgtv_adin   )
+      zsp1_7    = DOT_PRODUCT( zgrv_tlout   , zgrv_adin   )
+      zsp1_8    = DOT_PRODUCT( zgsv_tlout   , zgsv_adin   )
+      zsp1_9    = DOT_PRODUCT( zub_tlout    , zub_adin    )
+      zsp1_10   = DOT_PRODUCT( zvb_tlout    , zvb_adin    )
+      zsp1_11   = DOT_PRODUCT( ztb_tlout    , ztb_adin    )
+      zsp1_12   = DOT_PRODUCT( zsb_tlout    , zsb_adin    )
+      zsp1_13   = DOT_PRODUCT( zsshb_tlout  , zsshb_adin  )
+      zsp1_14   = DOT_PRODUCT( zrotb_tlout  , zrotb_adin  )
+      zsp1_15   = DOT_PRODUCT( zdivb_tlout  , zdivb_adin  )
+      zsp1_16   = DOT_PRODUCT( zrn2_tlout   , zrn2_adin   )
+
+      zsp1      = zsp1_1 + zsp1_2  + zsp1_3  + zsp1_4  + &
+                & zsp1_5 + zsp1_6  + zsp1_7  + zsp1_8  + &
+                & zsp1_9 + zsp1_10 + zsp1_11 + zsp1_12 + &
+                & zsp1_13+ zsp1_14 + zsp1_15 + zsp1_16
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      rhd_ad  (:,:,:) = zrhd_adin  (:,:,:)
+      rhop_ad (:,:,:) = zrhop_adin (:,:,:)
+      gtu_ad  (:,:  ) = zgtu_adin  (:,:  )
+      gtv_ad  (:,:  ) = zgtv_adin  (:,:  )
+      gru_ad  (:,:  ) = zgru_adin  (:,:  )
+      grv_ad  (:,:  ) = zgrv_adin  (:,:  )
+      gsu_ad  (:,:  ) = zgsu_adin  (:,:  )
+      gsv_ad  (:,:  ) = zgsv_adin  (:,:  )
+      ub_ad   (:,:,:) = zub_adin   (:,:,:)
+      vb_ad   (:,:,:) = zvb_adin   (:,:,:)
+      tb_ad   (:,:,:) = ztb_adin   (:,:,:)
+      sb_ad   (:,:,:) = zsb_adin   (:,:,:)
+      sshb_ad (:,:  ) = zsshb_adin (:,:  ) 
+      rotb_ad (:,:,:) = zrotb_adin (:,:,:)
+      hdivb_ad(:,:,:) = zdivb_adin (:,:,:)
+      rn2_ad  (:,:,:) = zrn2_adin  (:,:,:)
+     
+      CALL istate_init_adj
+
+      ztn_adout  (:,:,:) = tn_ad   (:,:,:)
+      zsn_adout  (:,:,:) = sn_ad   (:,:,:)
+      zrotn_adout(:,:,:) = rotn_ad (:,:,:)
+      zdivn_adout(:,:,:) = hdivn_ad(:,:,:)
+      zun_adout  (:,:,:) = un_ad   (:,:,:)
+      zvn_adout  (:,:,:) = vn_ad   (:,:,:)
+      zsshn_adout(:,:  ) = sshn_ad (:,:  )
+
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: dx^T L^T W dy
+      !--------------------------------------------------------------------
+       
+      zsp2_1    = DOT_PRODUCT( ztn_tlin  , ztn_adout    )
+      zsp2_2    = DOT_PRODUCT( zsn_tlin  , zsn_adout    )
+      zsp2_3    = DOT_PRODUCT( zrotn_tlin, zrotn_adout  )
+      zsp2_4    = DOT_PRODUCT( zdivn_tlin, zdivn_adout  )
+      zsp2_5    = DOT_PRODUCT( zun_tlin  , zun_adout    )
+      zsp2_6    = DOT_PRODUCT( zvn_tlin  , zvn_adout    )
+      zsp2_7    = DOT_PRODUCT( zsshn_tlin, zsshn_adout  )
+
+      zsp2      = zsp2_1 + zsp2_2 + zsp2_3 + zsp2_4 + zsp2_5 + zsp2_6 + zsp2_7
+
+      ! Compare the scalar products
+
+      ! 14 char:'12345678901234'
+      cl_name = 'istate_tst    '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      ! Deallocate memory
+      DEALLOCATE(        &
+         & ztn_tlin,     & 
+         & zsn_tlin,     & 
+         & ztn_adout,    & 
+         & zsn_adout,    &
+         & zrotn_tlin,   & 
+         & zdivn_tlin,   & 
+         & zrotn_adout,  &
+         & zdivn_adout,  &
+         & z3r,          & 
+         & z2r,          &
+         & zub_tlout,    & 
+         & zvb_tlout,    &
+         & zsb_tlout,    & 
+         & ztb_tlout,    &
+         & zsshb_tlout,  &        
+         & zgtu_tlout,   & 
+         & zgtv_tlout,   & 
+         & zgsu_tlout,   & 
+         & zgsv_tlout,   & 
+         & zgru_tlout,   & 
+         & zgrv_tlout,   &
+         & zrhd_tlout,   & 
+         & zrhop_tlout,  &
+         & zub_adin,     & 
+         & zvb_adin,     &
+         & zsb_adin,     & 
+         & ztb_adin,     &
+         & zsshb_adin,   &
+         & zgtu_adin,    & 
+         & zgtv_adin,    & 
+         & zgsu_adin,    & 
+         & zgsv_adin,    & 
+         & zgru_adin,    & 
+         & zgrv_adin,    &
+         & zrhd_adin,    &
+         & zrhop_adin,   &
+         & zrotb_adin,   &
+         & zdivb_adin,   &
+         & zrn2_adin,    &
+         & zrotb_tlout,  & 
+         & zdivb_tlout,  & 
+         & zrn2_tlout    & 
+         & )
+
+   END SUBROUTINE istate_init_adj_tst
+
+   !!=====================================================================
+#endif
+END MODULE istate_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/lbclnk_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/lbclnk_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/lbclnk_tam.F90	(revision 2578)
@@ -0,0 +1,285 @@
+MODULE lbclnk_tam
+   !!======================================================================
+   !!                       ***  MODULE  lbclnk_tam  ***
+   !! Ocean        : adjoint of lateral boundary conditions
+   !!=====================================================================
+#if   defined key_mpp_mpi   ||   defined key_mpp_shmem
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_mpi'     OR      MPI massively parallel processing library
+   !!   'key_mpp_shmem'         SHMEM massively parallel processing library
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   lbc_lnk_adj     : generic interface for mpp_lnk_3d_adj and 
+   !!                     mpp_lnkadj_2d routines defined in lib_mpp_tam
+   !!   lbc_lnk_adj_e   : generic interface for mpp_lnk_2d_e_adj
+   !!                     routine defined in lib_mpp_tam
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE lib_mpp_tam          ! distributed memory computing library
+
+   INTERFACE lbc_lnk_adj
+      MODULE PROCEDURE mpp_lnk_3d_gather_adj, mpp_lnk_3d_adj, mpp_lnk_2d_adj
+   END INTERFACE
+
+   INTERFACE lbc_lnk_e_adj
+      MODULE PROCEDURE mpp_lnk_2d_e_adj
+   END INTERFACE
+
+   PUBLIC lbc_lnk_adj       ! ocean lateral boundary conditions
+   PUBLIC lbc_lnk_e_adj     ! ocean lateral boundary conditions
+   !!----------------------------------------------------------------------
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                              shared memory computing
+   !!----------------------------------------------------------------------
+   !!   lbc_lnk_adj     : generic interface for lbc_lnkadj_3d and lbc_lnkadj_2d
+   !!   lbc_lnk_3d_adj  : set the lateral boundary condition on a 3D variable
+   !!                  on OPA ocean mesh
+   !!   lbc_lnk_2d_adj  : set the lateral boundary condition on a 2D variable
+   !!                  on OPA ocean mesh
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers   
+   USE dom_oce         ! ocean space and time domain 
+   USE in_out_manager  ! I/O manager
+   USE lbcnfd_tam      ! TAM of north fold
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTERFACE lbc_lnk_adj
+      MODULE PROCEDURE lbc_lnk_3d_gather_adj, lbc_lnk_3d_adj, lbc_lnk_2d_adj
+   END INTERFACE
+
+   INTERFACE lbc_lnk_e_adj
+      MODULE PROCEDURE lbc_lnk_2d_adj
+   END INTERFACE
+
+   PUBLIC lbc_lnk_adj       ! ocean/ice  lateral boundary conditions
+   PUBLIC lbc_lnk_e_adj     ! ocean/ice  lateral boundary conditions
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lbc_lnk_3d_gather_adj( pt3d1, cd_type1, pt3d2, cd_type2, psgn )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE lbc_lnkadj_3d_gather  ***
+      !!
+      !! ** Purpose : Adjoint of set lateral boundary conditions (non mpp case)
+      !!
+      !! ** Method  :
+      !!
+      !! History of TAM:
+      !!                  ! 2007-08  (K. Mogensen) Original code
+      !!         NEMO 3.2 ! 2010-04 (F. Vigilant)  External north fold treatment
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type1, cd_type2       ! nature of pt3d grid-points
+         !             !   = T ,  U , V , F or W  gridpoints
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         pt3d1, pt3d2          ! 3D array on which the boundary condition is applied
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   =-1 , the sign is changed if north fold boundary
+         !             !   = 1 , no sign change
+         !             !   = 0 , no sign change and > 0 required (use the inner
+         !             !         row/column if closed boundary)
+
+      CALL lbc_lnk_3d_adj( pt3d2, cd_type2, psgn)
+      CALL lbc_lnk_3d_adj( pt3d1, cd_type1, psgn)
+
+   END SUBROUTINE lbc_lnk_3d_gather_adj
+
+   SUBROUTINE lbc_lnk_3d_adj( pt3d, cd_type, psgn, cd_mpp )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE lbc_lnkadj_3d  ***
+      !!
+      !! ** Purpose : Adjoint of set lateral boundary conditions (non mpp case)
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!                  ! 2007-08  (K. Mogensen) Original code
+      !!         NEMO 3.2 ! 2010-04 (F. Vigilant)  External north fold treatment
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type       ! nature of pt3d grid-points
+         !             !   = T ,  U , V , F or W  gridpoints
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         pt3d          ! 3D array on which the boundary condition is applied
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   =-1 , the sign is changed if north fold boundary
+         !             !   = 1 , no sign change
+         !             !   = 0 , no sign change and > 0 required (use the inner
+         !             !         row/column if closed boundary)
+      CHARACTER(len=3), INTENT( in ), OPTIONAL ::    &
+         cd_mpp        ! fill the overlap area only (here do nothing)
+
+      IF (PRESENT(cd_mpp)) THEN
+         ! only fill the overlap area and extra allows 
+         ! this is in mpp case. In this module, just do nothing
+      ELSE
+
+         !                                     ! North-South boundaries
+         !                                     ! ======================
+         SELECT CASE ( nperio )
+
+         CASE ( 2 )                            !**  South symmetric  --  North closed
+
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'U' , 'W' )                   ! T-, U-, W-points
+               pt3d(:,jpj,:) = 0.0_wp
+               pt3d(:, 3 ,:) = pt3d(:,3,:) + pt3d(:,1,:)
+               pt3d(:, 1 ,:) = 0.0_wp
+            CASE ( 'V' , 'F' )                         ! V-, F-points
+               pt3d(:,jpj,:) = 0.0_wp
+               pt3d(:, 2 ,:) = pt3d(:,2,:) + psgn * pt3d(:,1,:)
+               pt3d(:, 1 ,:) = 0.0_wp
+            END SELECT
+
+         CASE ( 3 , 4 , 5, 6 )                 !**  North fold  T or F-point pivot  --  South closed
+            CALL lbc_nfd_adj( pt3d(:,:,:), cd_type, psgn  )  ! North fold
+            pt3d(jpi,jpj,:) = 0.0_wp
+            pt3d( 1 ,jpj,:) = 0.0_wp
+            !
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'U' , 'V' , 'W' , 'I' )             ! all points except F-point
+               pt3d(:, 1 ,:) = 0.0_wp
+            END SELECT
+
+         CASE DEFAULT                          !**  North closed  --  South closed
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d(:,jpj,:) = 0.0_wp
+               pt3d(:, 1 ,:) = 0.0_wp
+            CASE ( 'F' )                               ! F-point
+               pt3d(:,jpj,:) = 0.0_wp
+            END SELECT
+
+         END SELECT
+
+         !                                     !  East-West boundaries
+         !                                     ! ======================
+         SELECT CASE ( nperio )
+         !
+         CASE ( 1 , 4 , 6 )                       !**  cyclic east-west
+            pt3d(  2  ,:,:) = pt3d(  2  ,:,:) + pt3d(jpi,:,:)
+            pt3d(jpi,:,:) = 0.0_wp
+            pt3d(jpim1,:,:) = pt3d(jpim1,:,:) + pt3d( 1 ,:,:)
+            pt3d( 1 ,:,:) = 0.0_wp
+            !
+         CASE DEFAULT                             !**  East closed  --  West closed
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d( 1 ,:,:) = 0.0_wp
+               pt3d(jpi,:,:) = 0.0_wp
+            CASE ( 'F' )                               ! F-point
+               pt3d(jpi,:,:) = 0.0_wp
+            END SELECT
+            !
+         END SELECT
+
+      ENDIF
+
+   END SUBROUTINE lbc_lnk_3d_adj
+
+   SUBROUTINE lbc_lnk_2d_adj( pt2d, cd_type, psgn, cd_mpp )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE lbc_lnkadj_2d  ***
+      !!
+      !! ** Purpose : Adjoint of set lateral boundary conditions (non mpp case)
+      !!
+      !! ** Method  :
+      !!
+      !! History of TAM:
+      !!                  ! 2007-08  (K. Mogensen) Original code
+      !!         NEMO 3.2 ! 2010-04 (F. Vigilant)  External north fold treatment
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type       ! nature of pt2d grid-point
+         !             !   = T , U , V , F or W  gridpoints
+         !             !   = I sea-ice U-V gridpoint (= F ocean grid point with indice shift)
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   =-1 , the sign is modified following the type of b.c. used
+         !             !   = 1 , no sign change
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         pt2d          ! 2D array on which the boundary condition is applied
+      CHARACTER(len=3), INTENT( in ), OPTIONAL ::    &
+         cd_mpp        ! fill the overlap area only (here do nothing)
+      
+      IF (PRESENT(cd_mpp)) THEN
+         ! only fill the overlap area and extra allows 
+         ! this is in mpp case. In this module, just do nothing
+      ELSE
+
+         !                                     ! North-South boundaries
+         !                                     ! ======================
+         SELECT CASE ( nperio )
+         !
+         CASE ( 2 )                            ! *  south symmetric
+         SELECT CASE ( cd_type )
+         CASE ( 'T' , 'U' , 'W' )                   ! T-, U-, W-points
+            pt2d(:,jpj) = 0.0_wp
+            pt2d(:, 3 ) = pt2d(:,3) + pt2d(:,1)
+            pt2d(:, 1 ) = 0.0_wp
+         CASE ( 'V' , 'F' )                         ! V-, F-points
+            pt2d(:,jpj) = 0.e0
+            pt2d(:, 2 ) = pt2d(:,2) + psgn * pt2d(:,1)
+            pt2d(:, 1 ) = 0.e0
+         END SELECT
+         
+         CASE ( 3 , 4, 5, 6 )                   !**  North fold  T or F-point pivot  --  South closed 
+            CALL lbc_nfd_adj( pt2d(:,:), cd_type, psgn )
+            pt2d(jpi,jpj) = 0.0_wp
+            pt2d( 1 ,jpj) = 0.0_wp
+            pt2d( 1 , 1 ) = 0.0_wp        
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'U' , 'V' , 'W' ,  'I')             ! all points except F-point
+               pt2d(:, 1 ) = 0.0_wp
+            END SELECT
+         
+         CASE DEFAULT                          ! *  closed
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt2d(:,jpj) = 0.0_wp
+               pt2d(:, 1 ) = 0.0_wp
+            CASE ( 'F' )                               ! F-point
+               pt2d(:,jpj) = 0.0_wp
+            END SELECT
+            !
+         END SELECT
+
+         !                                     ! East-West boundaries
+         !                                     ! ====================
+         SELECT CASE ( nperio )
+         ! 
+         CASE ( 1 , 4 , 6 )                    ! * cyclic east-west
+            pt2d(  2  ,:) = pt2d(  2  ,:) + pt2d( jpi ,:)
+            pt2d( jpi ,:) = 0.0_wp
+            pt2d(jpim1,:) = pt2d(jpim1,:) + pt2d( 1 ,:)
+            pt2d(  1  ,:) = 0.0_wp 
+            !
+      CASE DEFAULT                             !** East closed  --  West closed
+         SELECT CASE ( cd_type )
+         CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+            pt2d(jpi,:) = 0.0_wp
+            pt2d( 1 ,:) = 0.0_wp
+         CASE ( 'F' )                               ! F-point
+            pt2d(jpi,:) = 0.0_wp
+         END SELECT
+         
+      END SELECT
+      
+      ENDIF
+      
+   END SUBROUTINE lbc_lnk_2d_adj
+
+#endif
+
+END MODULE lbclnk_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/lbcnfd_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/lbcnfd_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/lbcnfd_tam.F90	(revision 2578)
@@ -0,0 +1,946 @@
+MODULE lbcnfd_tam
+   !!======================================================================
+   !!                       ***  MODULE  lbcnfd  ***
+   !! Ocean        : north fold  boundary conditions
+   !!======================================================================
+   !!             9.0  !  2009-03  (R. Benshila) Initial version
+   !! History of TAM:
+   !!        NEMO 3.2  !  2010-04  (F. Vigilant) Original code 
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers   
+   USE dom_oce         ! ocean space and time domain 
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTERFACE lbc_nfd_adj
+      MODULE PROCEDURE lbc_nfd_3d_adj, lbc_nfd_2d_adj
+   END INTERFACE
+
+   PUBLIC lbc_nfd_adj       ! north fold conditions
+   PUBLIC lbc_nfd_adj_tst
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lbc_nfd_3d_adj( pt3d, cd_type, psgn )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine lbc_nfd_3d_adj  ***
+      !!
+      !! ** Purpose :   Adjoint of 3D lateral boundary condition : North fold
+      !!       treatment without processor exchanges. 
+      !!
+      !! ** Method  :   
+      !!
+      !! ** Action  :   pt3d with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1) , INTENT( in ) ::   &
+         cd_type       ! define the nature of ptab array grid-points
+      !             ! = T , U , V , F , W points
+      !             ! = S : T-point, north fold treatment ???
+      !             ! = G : F-point, north fold treatment ???
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+      !             !   = -1. , the sign is changed if north fold boundary
+      !             !   =  1. , the sign is kept  if north fold boundary
+      REAL(wp), DIMENSION(:,:,:), INTENT( inout ) ::   &
+         pt3d          ! 3D array on which the boundary condition is applied
+
+      !! * Local declarations
+      INTEGER  ::   ji, jk
+      INTEGER  ::   ijt, iju, ijpj, ijpjm1
+
+
+      SELECT CASE ( jpni )
+      CASE ( 1 )  ! only one proc along I
+         ijpj = nlcj
+      CASE DEFAULT 
+         ijpj   = 4
+      END SELECT
+      ijpjm1 = ijpj-1
+
+      DO jk = 1, jpk
+
+         SELECT CASE ( npolj )
+
+         CASE ( 3 , 4 )                        ! *  North fold  T-point pivot
+
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = jpiglo, jpiglo/2+1, -1
+                  ijt = jpiglo-ji+2
+                  pt3d(ijt,ijpjm1,jk) = pt3d(ijt,ijpjm1,jk) + psgn * pt3d(ji,ijpjm1,jk)
+                  pt3d(ji ,ijpjm1,jk) = 0.0_wp
+               END DO
+               DO ji = jpiglo, 2, -1
+                  ijt = jpiglo-ji+2
+                  pt3d(ijt,ijpj-2,jk) = pt3d(ijt,ijpj-2,jk) + psgn * pt3d(ji,ijpj,jk)
+                  pt3d(ji ,ijpj  ,jk) = 0.0_wp
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO ji = jpiglo-1, jpiglo/2, -1
+                  iju = jpiglo-ji+1
+                  pt3d(iju,ijpjm1,jk) = pt3d(iju,ijpjm1,jk) + psgn * pt3d(ji,ijpjm1,jk)
+                  pt3d(ji ,ijpjm1,jk) = 0.0_wp
+               END DO
+               DO ji = jpiglo-1, 1, -1
+                  iju = jpiglo-ji+1
+                  pt3d(iju,ijpj-2,jk) = pt3d(iju,ijpj-2,jk) + psgn * pt3d(ji,ijpj,jk)
+                  pt3d(ji ,ijpj  ,jk) = 0.0_wp
+               END DO
+            CASE ( 'V' )                               ! V-point
+               DO ji = jpiglo, 2, -1
+                  ijt = jpiglo-ji+2
+                  pt3d(ijt,ijpj-3,jk) = pt3d(ijt,ijpj-3,jk) + psgn * pt3d(ji,ijpj  ,jk)
+                  pt3d(ji,ijpj  ,jk) = 0.0_wp
+                  pt3d(ijt,ijpj-2,jk) = pt3d(ijt,ijpj-2,jk) + psgn * pt3d(ji,ijpj-1,jk)
+                  pt3d(ji,ijpj-1,jk) = 0.0_wp
+               END DO
+            CASE ( 'F' )                               ! F-point
+               DO ji = jpiglo-1, 1, -1
+                  iju = jpiglo-ji+1
+                  pt3d(iju,ijpj-3,jk) = pt3d(iju,ijpj-3,jk) + psgn * pt3d(ji,ijpj  ,jk)
+                  pt3d(ji ,ijpj  ,jk) = 0.0_wp
+                  pt3d(iju,ijpj-2,jk) = pt3d(iju,ijpj-2,jk) + psgn * pt3d(ji,ijpj-1,jk)
+                  pt3d(ji ,ijpj-1,jk) = 0.0_wp
+               END DO
+            END SELECT
+
+         CASE ( 5 , 6 )                        ! *  North fold  F-point pivot
+
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = jpiglo, 1, -1
+                  ijt = jpiglo-ji+1
+                  pt3d(ijt,ijpj-1,jk) = pt3d(ijt,ijpj-1,jk) + psgn * pt3d(ji,ijpj,jk)
+                  pt3d(ji ,ijpj  ,jk) = 0.0_wp
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO ji = jpiglo-1, 1, -1
+                  iju = jpiglo-ji
+                  pt3d(iju,ijpj-1,jk) = pt3d(iju,ijpj-1,jk) + psgn * pt3d(ji,ijpj,jk)
+                  pt3d(ji ,ijpj  ,jk) = 0.0_wp
+               END DO
+            CASE ( 'V' )                               ! V-point
+               DO ji = jpiglo, jpiglo/2+1, -1
+                  ijt = jpiglo-ji+1
+                  pt3d(ijt,ijpjm1,jk) = pt3d(ijt,ijpjm1,jk) + psgn * pt3d(ji,ijpjm1,jk)
+                  pt3d(ji ,ijpjm1,jk) = 0.0_wp
+               END DO
+               DO ji = jpiglo, 1, -1
+                  ijt = jpiglo-ji+1
+                  pt3d(ijt,ijpj-2,jk) = pt3d(ijt,ijpj-2,jk) + psgn * pt3d(ji,ijpj,jk)
+                  pt3d(ji ,ijpj  ,jk) = 0.0_wp
+               END DO
+            CASE ( 'F' )                               ! F-point
+               DO ji = jpiglo-1, jpiglo/2+1, -1
+                  iju = jpiglo-ji
+                  pt3d(iju,ijpjm1,jk) = pt3d(iju,ijpjm1,jk) + psgn * pt3d(ji,ijpjm1,jk)
+                  pt3d(ji ,ijpjm1,jk) = 0.0_wp
+               END DO
+               DO ji = jpiglo-1, 1, -1
+                  iju = jpiglo-ji
+                  pt3d(iju,ijpj-2,jk) = pt3d(iju,ijpj-2,jk) + psgn * pt3d(ji,ijpj  ,jk)
+                  pt3d(ji ,ijpj  ,jk) = 0.0_wp
+               END DO
+            END SELECT
+
+         CASE DEFAULT                           ! *  closed : the code probably never go through
+
+            SELECT CASE ( cd_type)
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d(:, 1  ,jk) = 0.0_wp
+               pt3d(:,ijpj,jk) = 0.0_wp
+            CASE ( 'F' )                               ! F-point
+               pt3d(:,ijpj,jk) = 0.0_wp
+            END SELECT
+
+         END SELECT     !  npolj
+
+      END DO
+
+   END SUBROUTINE lbc_nfd_3d_adj
+
+
+   SUBROUTINE lbc_nfd_2d_adj( pt2d, cd_type, psgn, pr2dj )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine lbc_nfd_2d  ***
+      !!
+      !! ** Purpose :   Adjoint of 2D lateral boundary condition : North fold
+      !!       treatment without processor exchanges. 
+      !!
+      !! ** Method  :   
+      !!
+      !! ** Action  :   pt2d with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1) , INTENT( in ) ::   &
+         cd_type       ! define the nature of ptab array grid-points
+      !             ! = T , U , V , F , W points
+      !             ! = S : T-point, north fold treatment ???
+      !             ! = G : F-point, north fold treatment ???
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+      !             !   = -1. , the sign is changed if north fold boundary
+      !             !   =  1. , the sign is kept  if north fold boundary
+      REAL(wp), DIMENSION(:,:), INTENT( inout ) ::   &
+         pt2d          ! 3D array on which the boundary condition is applied
+      INTEGER, OPTIONAL, INTENT(in) :: pr2dj
+
+      !! * Local declarations
+      INTEGER  ::   ji, jl, ipr2dj
+      INTEGER  ::   ijt, iju, ijpj, ijpjm1
+
+      SELECT CASE ( jpni )
+      CASE ( 1 )  ! only one proc along I
+         ijpj = nlcj
+      CASE DEFAULT 
+         ijpj = 4
+      END SELECT
+
+
+      IF( PRESENT(pr2dj) ) THEN
+         ipr2dj = pr2dj
+         IF (jpni .GT. 1) ijpj = ijpj + ipr2dj
+      ELSE
+         ipr2dj = 0 
+      ENDIF
+
+      ijpjm1 = ijpj-1
+
+
+      SELECT CASE ( npolj )
+
+      CASE ( 3, 4 )                       ! *  North fold  T-point pivot
+
+         SELECT CASE ( cd_type )
+
+         CASE ( 'T', 'S', 'W' )
+            DO ji = jpiglo, jpiglo/2+1, -1
+               ijt=jpiglo-ji+2
+               pt2d(ijt,ijpj-1) = pt2d(ijt,ijpj-1) + psgn * pt2d(ji,ijpj-1)
+               pt2d(ji ,ijpj-1) = 0.0_wp
+            END DO
+            DO jl = ipr2dj, 0, -1
+               DO ji = jpiglo, 2, -1
+                  ijt=jpiglo-ji+2
+                  pt2d(ijt,ijpj-2-jl) = pt2d(ijt,ijpj-2-jl) + psgn * pt2d(ji,ijpj+jl)
+                  pt2d(ji ,ijpj+jl  ) = 0.0_wp
+               END DO
+            END DO
+         CASE ( 'U' )                                     ! U-point
+            DO ji = jpiglo-1, jpiglo/2, -1
+               iju = jpiglo-ji+1
+               pt2d(iju,ijpjm1) = pt2d(iju,ijpjm1) + psgn * pt2d(ji,ijpjm1)
+               pt2d(ji,ijpjm1) = 0.0_wp
+            END DO
+            DO jl = ipr2dj, 0, -1
+               DO ji = jpiglo-1, 1, -1
+                  iju = jpiglo-ji+1
+                  pt2d(iju,ijpj-2-jl) = pt2d(iju,ijpj-2-jl) + psgn * pt2d(ji,ijpj+jl)
+                  pt2d(ji ,ijpj+jl  ) = 0.0_wp
+               END DO
+            END DO
+         CASE ( 'V' )                                     ! V-point
+            DO jl = ipr2dj, -1, -1
+               DO ji = jpiglo, 2, -1
+                  ijt = jpiglo-ji+2
+                  pt2d(ijt,ijpj-3-jl) = pt2d(ijt,ijpj-3-jl) + psgn * pt2d(ji,ijpj+jl)
+                  pt2d(ji ,ijpj+jl  ) = 0.0_wp
+               END DO
+            END DO
+         CASE ( 'F' , 'G' )                               ! F-point
+            DO jl = ipr2dj, -1, -1
+               DO ji = jpiglo-1, 1, -1
+                  iju = jpiglo-ji+1
+                  pt2d(iju,ijpj-3-jl) = pt2d(iju,ijpj-3-jl) + psgn * pt2d(ji,ijpj+jl)
+                  pt2d(ji,ijpj+jl) = 0.0_wp
+               END DO
+            END DO
+         CASE ( 'I' )                                     ! ice U-V point
+            DO jl = ipr2dj, 0, -1
+               DO ji = jpiglo, 3, -1
+                  iju = jpiglo - ji + 3
+                  pt2d(iju,ijpj-1-jl) = pt2d(iju,ijpj-1-jl) + psgn * pt2d(ji,ijpj+jl)
+                  pt2d(ji,ijpj+jl) = 0.0_wp
+               END DO
+               pt2d(3,ijpj-1+jl) = pt2d(3,ijpj-1+jl) + psgn * pt2d(2,ijpj+jl)
+               pt2d(2,ijpj+jl) = 0.0_wp
+            END DO
+         END SELECT
+
+      CASE ( 5, 6 )                        ! *  North fold  F-point pivot
+
+         SELECT CASE ( cd_type )
+         CASE ( 'T' , 'W' ,'S' )                          ! T-, W-point
+            DO jl = ipr2dj, 0, -1
+               DO ji = jpiglo, 1, -1
+                  ijt = jpiglo-ji+1
+                  pt2d(ijt,ijpj-1-jl) = pt2d(ijt,ijpj-1-jl) + psgn * pt2d(ji,ijpj+jl)
+                  pt2d(ji ,ijpj+jl  ) = 0.0_wp
+               END DO
+            END DO
+         CASE ( 'U' )                                     ! U-point
+            DO jl = ipr2dj, 0, -1
+               DO ji = jpiglo-1, 1, -1
+                  iju = jpiglo-ji
+                  pt2d(iju,ijpj-1-jl) = pt2d(iju,ijpj-1-jl) + psgn * pt2d(ji,ijpj+jl)
+                  pt2d(ji,ijpj+jl) = 0.0_wp
+               END DO
+            END DO
+         CASE ( 'V' )                                     ! V-point
+            DO ji = jpiglo, jpiglo/2+1, -1
+               ijt = jpiglo-ji+1
+               pt2d(ijt,ijpjm1) = pt2d(ijt,ijpjm1) + psgn * pt2d(ji,ijpjm1)
+               pt2d(ji ,ijpjm1) = 0.0_wp
+            END DO
+            DO jl = ipr2dj, 0, -1
+               DO ji = jpiglo, 1, -1
+                  ijt = jpiglo-ji+1
+                  pt2d(ijt,ijpj-2-jl) = pt2d(ijt,ijpj-2-jl) + psgn * pt2d(ji,ijpj+jl)
+                  pt2d(ji,ijpj+jl) = 0.0_wp
+               END DO
+            END DO
+         CASE ( 'F' , 'G' )                               ! F-point
+            DO ji = jpiglo-1, jpiglo/2+1, -1
+               iju = jpiglo-ji
+               pt2d(iju,ijpjm1) = pt2d(iju,ijpjm1) + psgn * pt2d(ji,ijpjm1)
+               pt2d(ji ,ijpjm1) = 0.0_wp
+            END DO
+            DO jl = ipr2dj, 0, -1
+               DO ji = jpiglo-1, 1, -1
+                  iju = jpiglo-ji
+                  pt2d(iju,ijpj-2-jl) = pt2d(iju,ijpj-2-jl) + psgn * pt2d(ji,ijpj+jl)
+                  pt2d(ji ,ijpj+jl  ) = 0.0_wp
+               END DO
+            END DO
+         CASE ( 'I' )                                  ! ice U-V point
+            DO jl = ipr2dj, 0, -1
+               DO ji = jpiglo-1, 2, -1
+                  ijt = jpiglo - ji + 2
+                  pt2d(ji ,ijpj-1-jl) = pt2d(ji ,ijpj-1-jl) + 0.5 * pt2d(ji,ijpj+jl)
+                  pt2d(ijt,ijpj-1-jl) = pt2d(ijt,ijpj-1-jl) + 0.5 * psgn * pt2d(ji,ijpj+jl)
+                  pt2d(ji ,ijpj+jl  ) = 0.0_wp
+               END DO
+            END DO
+            pt2d( 2 ,ijpj:ijpj+ipr2dj) = 0.0_wp
+         END SELECT
+
+      CASE DEFAULT                           ! *  closed : the code probably never go through
+
+         SELECT CASE ( cd_type)
+         CASE ( 'T' , 'U' , 'V' , 'W' )                 ! T-, U-, V-, W-points
+            pt2d(:, 1:1-ipr2dj     ) = 0.0_wp
+            pt2d(:,ijpj:ijpj+ipr2dj) = 0.0_wp
+         CASE ( 'F' )                                   ! F-point
+            pt2d(:,ijpj:ijpj+ipr2dj) = 0.0_wp
+         CASE ( 'I' )                                   ! ice U-V point
+            pt2d(:, 1:1-ipr2dj     ) = 0.0_wp
+            pt2d(:,ijpj:ijpj+ipr2dj) = 0.0_wp
+         END SELECT
+
+      END SELECT
+
+   END SUBROUTINE lbc_nfd_2d_adj
+
+   SUBROUTINE lbc_nfd_3d_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE lbc_nfd_3d_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : 
+      !!                
+      !! History :
+      !!        ! 2010-09 (F. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product      
+   USE lbcnfd,         ONLY: &
+      & lbc_nfd
+   USE tstool_tam    , ONLY: &
+      & stdu,                &
+      & stdv,                &
+      & stdt,                &
+      & prntst_adj  
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+      & e1t,                 &
+      & e2t,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3u,                 &
+      & e3v,                 &
+#endif
+      & tmask,               &
+      & umask,               &
+      & vmask,               &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE mppsumtam
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt        ! Output unit
+
+      !! * Local declarations
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zu_tlin,    & ! Tangent input: ua_tl
+         & zv_tlin,    & ! Tangent input: va_tl
+         & zt_tlin,    & ! Tangent input: ub_tl
+         & zu_tlout,   & ! Tangent output: ua_tl
+         & zv_tlout,   & ! Tangent output: va_tl
+         & zt_tlout,   & ! Tangent output: ua_tl         
+         & zu_adin,    & ! Tangent output: ua_ad
+         & zv_adin,    & ! Tangent output: va_ad         
+         & zt_adin,    & ! Adjoint input: ua_ad
+         & z_adin,    & ! Adjoint input: va_ad
+         & zu_adout,   & ! Adjoint output: ua_ad
+         & zv_adout,   & ! Adjoint output: va_ad
+         & zt_adout,   & ! Adjoint oputput: ub_ad
+         & znu            ! 3D random field for u
+
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zu_tl,    & ! Tangent input: ua_tl
+         & zv_tl,    & ! Tangent input: va_tl
+         & zt_tl,    & ! Tangent input: ub_tl      
+         & zu_ad,    & ! Tangent output: ua_ad
+         & zv_ad,    & ! Tangent output: va_ad         
+         & zt_ad
+      REAL(wp) :: &
+         & zsp1,    &   ! scalar product involving the tangent routine
+         & zsp2         ! scalar product involving the adjoint routine
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d    ! 2D seed for the random number generator
+      CHARACTER(len=1) :: &
+         & cd_type
+      INTEGER :: &
+         & indic, &
+         & istp
+      INTEGER :: &
+         & ji, &
+         & jj, &
+         & jk, &
+         & kmod, &
+         & jstp
+      CHARACTER (LEN=14) :: &
+         & cl_name
+      INTEGER ::             &
+         & zijpj, ziglo, zip, zdiff
+
+      ! Allocate memory
+
+      zijpj = 4
+
+      ALLOCATE( &
+         & zu_tlin(jpiglo,zijpj,jpk),  &
+         & zv_tlin(jpiglo,zijpj,jpk),  &
+         & zt_tlin(jpiglo,zijpj,jpk),  &
+         & zu_tlout(jpiglo,zijpj,jpk), &
+         & zv_tlout(jpiglo,zijpj,jpk), &
+         & zt_tlout(jpiglo,zijpj,jpk), &
+         & zu_adin(jpiglo,zijpj,jpk),  &
+         & zv_adin(jpiglo,zijpj,jpk),  &
+         & zt_adin(jpiglo,zijpj,jpk),  &
+         & zu_adout(jpiglo,zijpj,jpk), &
+         & zv_adout(jpiglo,zijpj,jpk), &
+         & zt_adout(jpiglo,zijpj,jpk), &
+         & znu(jpi,jpj,jpk)         &
+         & )
+
+      ALLOCATE( &
+         & zu_tl(jpiglo,zijpj,jpk),  &
+         & zv_tl(jpiglo,zijpj,jpk),  &
+         & zt_tl(jpiglo,zijpj,jpk),  &
+         & zu_ad(jpiglo,zijpj,jpk),  &
+         & zv_ad(jpiglo,zijpj,jpk),  &
+         & zt_ad(jpiglo,zijpj,jpk)   &
+         & )
+
+        zu_tlin (:,:,:) = 0.0_wp
+        zv_tlin (:,:,:) = 0.0_wp
+        zt_tlin (:,:,:) = 0.0_wp
+        zu_tlout(:,:,:) = 0.0_wp
+        zv_tlout(:,:,:) = 0.0_wp
+        zt_tlout(:,:,:) = 0.0_wp
+        zu_adin (:,:,:) = 0.0_wp
+        zv_adin (:,:,:) = 0.0_wp
+        zt_adin (:,:,:) = 0.0_wp
+        zu_adout(:,:,:) = 0.0_wp
+        zv_adout(:,:,:) = 0.0_wp
+        zt_adout(:,:,:) = 0.0_wp
+
+        zu_tl (:,:,:) = 0.0_wp
+        zv_tl (:,:,:) = 0.0_wp
+        zt_tl (:,:,:) = 0.0_wp
+        zu_ad (:,:,:) = 0.0_wp
+        zv_ad (:,:,:) = 0.0_wp
+        zt_ad (:,:,:) = 0.0_wp
+
+        ziglo = INT(jpiglo / (nlei - nldi) )
+        zdiff = nlei - nldi
+        !--------------------------------------------------------------------
+        ! Initialize the tangent input with random noise: dx
+        !--------------------------------------------------------------------
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              iseed_2d(ji,jj) = - ( 456953 + &
+                &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+           END DO
+        END DO
+        CALL grid_random( iseed_2d, znu, 'U', 0.0_wp, stdu )
+        DO jk = 1, jpk
+           DO jj = 1, 4
+              DO ji = nldi, nlei
+                 DO zip = 1, ziglo
+                    zu_tlin(ji+(zip-1)*zdiff,jj,jk) = znu(ji,jj,jk)
+                 ENDDO
+              END DO
+           END DO
+        END DO
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              iseed_2d(ji,jj) = - ( 3434334 + &
+                &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+           END DO
+        END DO
+        CALL grid_random( iseed_2d, znu, 'V', 0.0_wp, stdu )
+        DO jk = 1, jpk
+           DO jj = 1, 4
+              DO ji = nldi, nlei
+                 DO zip = 1, ziglo
+                    zv_tlin(ji+(zip-1)*zdiff,jj,jk) = znu(ji,jj,jk)
+                 ENDDO
+              END DO
+           END DO
+        END DO
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              iseed_2d(ji,jj) = - ( 935678 + &
+                &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+           END DO
+        END DO
+        CALL grid_random( iseed_2d, znu, 'T', 0.0_wp, stdt )
+        DO jk = 1, jpk
+           DO jj = 1, 4
+              DO ji = nldi, nlei
+                 DO zip = 1, ziglo
+                    zt_tlin(ji+(zip-1)*zdiff,jj,jk) = znu(ji,jj,jk)
+                 ENDDO
+              END DO
+           END DO
+        END DO
+
+        !--------------------------------------------------------------------
+        ! Call the tangent routine: dy = L dx
+        !--------------------------------------------------------------------
+        zu_tl(:,:,:) = zu_tlin(:,:,:)
+        zv_tl(:,:,:) = zv_tlin(:,:,:)
+        zt_tl(:,:,:) = zt_tlin(:,:,:)
+
+        CALL lbc_nfd( zu_tl, 'U',  -1.0_wp )
+        CALL lbc_nfd( zv_tl, 'V',  -1.0_wp )
+        CALL lbc_nfd( zt_tl, 'T',   1.0_wp )
+        zu_tlout(:,:,:) = zu_tl(:,:,:)
+        zv_tlout(:,:,:) = zv_tl(:,:,:)
+        zt_tlout(:,:,:) = zt_tl(:,:,:)
+
+        DO jk = 1, jpk
+           DO jj = 1,4
+              DO ji = nldi, nlei
+                 DO zip = 1, ziglo
+                    zu_adin(ji+(zip-1)*zdiff,jj,jk) = zu_tlout(ji+(zip-1)*ziglo,jj,jk) &
+                       &               * e1u(ji,jj) * e2u(ji,jj) &!* fse3u(ji,jj,jk) &
+                       &               * umask(ji,jj,jk)
+                    zv_adin(ji+(zip-1)*zdiff,jj,jk) = zv_tlout(ji+(zip-1)*ziglo,jj,jk) &
+                       &               * e1v(ji,jj) * e2v(ji,jj) &!* fse3v(ji,jj,jk) &
+                       &               * vmask(ji,jj,jk)
+                    zt_adin(ji+(zip-1)*zdiff,jj,jk) = zt_tlout(ji+(zip-1)*ziglo,jj,jk) &
+                       &               * e1t(ji,jj) * e2t(ji,jj) &!* fse3t(ji,jj,jk) &
+                       &               * tmask(ji,jj,jk)
+                 ENDDO
+              END DO
+           END DO
+        END DO
+
+        ! DOT_PRODUCT 
+        zsp1 = sum( &
+         &                       PACK(zu_tlout(:,:,:),.TRUE.) * &
+         &                       PACK( zu_adin(:,:,:),.TRUE.) )
+
+        zu_ad(:,:,:) = zu_adin(:,:,:)
+        zv_ad(:,:,:) = zv_adin(:,:,:)
+        zt_ad(:,:,:) = zt_adin(:,:,:)
+
+        CALL lbc_nfd_adj( zu_ad, 'U',  -1.0_wp )
+        CALL lbc_nfd_adj( zv_ad, 'V',  -1.0_wp )
+        CALL lbc_nfd_adj( zt_ad, 'T',   1.0_wp )
+
+        zu_adout(:,:,:) = zu_ad(:,:,:)
+        zv_adout(:,:,:) = zv_ad(:,:,:)
+        zt_adout(:,:,:) = zt_ad(:,:,:)
+
+        zsp2 = sum( &
+         &                       PACK(zu_tlin(:,:,:),.TRUE.) * &
+         &                       PACK( zu_adout(:,:,:),.TRUE.) )
+
+        cl_name = 'lbc_nfd  U  3d'
+        CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+        zsp1 = sum( &
+         &                       PACK(zv_tlout(:,:,:),.TRUE.) * &
+         &                       PACK( zv_adin(:,:,:),.TRUE.) )
+
+        zsp2 = sum( &
+         &                       PACK(zv_tlin(:,:,:),.TRUE.) * &
+         &                       PACK( zv_adout(:,:,:),.TRUE.) )
+        cl_name = 'lbc_nfd  V  3d'
+        CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+        zsp1 = sum( &
+         &                       PACK(zt_tlout(:,:,:),.TRUE.) * &
+         &                       PACK( zt_adin(:,:,:),.TRUE.) )
+
+        zsp2 = sum( &
+         &                       PACK(zt_tlin(:,:,:),.TRUE.) * &
+         &                       PACK( zt_adout(:,:,:),.TRUE.) )
+        cl_name = 'lbc_nfd  T  3d'
+        CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+   END SUBROUTINE lbc_nfd_3d_adj_tst
+
+   SUBROUTINE lbc_nfd_2d_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE lbc_nfd_2d_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : 
+      !!                
+      !! History :
+      !!        ! 2010-09 (F. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product      
+   USE lbcnfd,         ONLY: &
+      & lbc_nfd
+   USE tstool_tam    , ONLY: &
+      & stdu,                &
+      & stdv,                &
+      & stdt,                &
+      & prntst_adj  
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & e1u,                 &
+      & e2u,                 &
+      & e1v,                 &
+      & e2v,                 &
+      & e1t,                 &
+      & e2t,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3u,                 &
+      & e3v,                 &
+#endif
+      & tmask,               &
+      & umask,               &
+      & vmask,               &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE mppsumtam
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt        ! Output unit
+
+      !! * Local declarations
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zu_tlin,    & ! Tangent input: ua_tl
+         & zv_tlin,    & ! Tangent input: va_tl
+         & zt_tlin,    & ! Tangent input: ub_tl
+         & zu_tlout,   & ! Tangent output: ua_tl
+         & zv_tlout,   & ! Tangent output: va_tl
+         & zt_tlout,   & ! Tangent output: ua_tl         
+         & zu_adin,    & ! Tangent output: ua_ad
+         & zv_adin,    & ! Tangent output: va_ad         
+         & zt_adin,    & ! Adjoint input: ua_ad
+         & z_adin,    & ! Adjoint input: va_ad
+         & zu_adout,   & ! Adjoint output: ua_ad
+         & zv_adout,   & ! Adjoint output: va_ad
+         & zt_adout,   & ! Adjoint oputput: ub_ad
+         & znu            ! 3D random field for u
+
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zu_tl,    & ! Tangent input: ua_tl
+         & zv_tl,    & ! Tangent input: va_tl
+         & zt_tl,    & ! Tangent input: ub_tl      
+         & zu_ad,    & ! Tangent output: ua_ad
+         & zv_ad,    & ! Tangent output: va_ad         
+         & zt_ad
+      REAL(wp) :: &
+         & zsp1,    &   ! scalar product involving the tangent routine
+         & zsp2         ! scalar product involving the adjoint routine
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d    ! 2D seed for the random number generator
+      CHARACTER(len=1) :: &
+         & cd_type
+      INTEGER :: &
+         & indic, &
+         & istp
+      INTEGER :: &
+         & ji, &
+         & jj, &
+         & jk, &
+         & kmod, &
+         & jstp
+      CHARACTER (LEN=14) :: &
+         & cl_name
+      INTEGER ::             &
+         & zijpj, ziglo, zip, zdiff
+
+      ! Allocate memory
+
+      zijpj = 4
+
+      ALLOCATE( &
+         & zu_tlin(jpiglo,zijpj),  &
+         & zv_tlin(jpiglo,zijpj),  &
+         & zt_tlin(jpiglo,zijpj),  &
+         & zu_tlout(jpiglo,zijpj), &
+         & zv_tlout(jpiglo,zijpj), &
+         & zt_tlout(jpiglo,zijpj), &
+         & zu_adin(jpiglo,zijpj),  &
+         & zv_adin(jpiglo,zijpj),  &
+         & zt_adin(jpiglo,zijpj),  &
+         & zu_adout(jpiglo,zijpj), &
+         & zv_adout(jpiglo,zijpj), &
+         & zt_adout(jpiglo,zijpj), &
+         & znu(jpi,jpj)         &
+         & )
+
+      ALLOCATE( &
+         & zu_tl(jpiglo,zijpj),  &
+         & zv_tl(jpiglo,zijpj),  &
+         & zt_tl(jpiglo,zijpj),  &
+         & zu_ad(jpiglo,zijpj),  &
+         & zv_ad(jpiglo,zijpj),  &
+         & zt_ad(jpiglo,zijpj)   &
+         & )
+
+        zu_tlin (:,:) = 0.0_wp
+        zv_tlin (:,:) = 0.0_wp
+        zt_tlin (:,:) = 0.0_wp
+        zu_tlout(:,:) = 0.0_wp
+        zv_tlout(:,:) = 0.0_wp
+        zt_tlout(:,:) = 0.0_wp
+        zu_adin (:,:) = 0.0_wp
+        zv_adin (:,:) = 0.0_wp
+        zt_adin (:,:) = 0.0_wp
+        zu_adout(:,:) = 0.0_wp
+        zv_adout(:,:) = 0.0_wp
+        zt_adout(:,:) = 0.0_wp
+
+        zu_tl (:,:) = 0.0_wp
+        zv_tl (:,:) = 0.0_wp
+        zt_tl (:,:) = 0.0_wp
+        zu_ad (:,:) = 0.0_wp
+        zv_ad (:,:) = 0.0_wp
+        zt_ad (:,:) = 0.0_wp
+
+        ziglo = INT(jpiglo / (nlei - nldi) )
+        zdiff = nlei - nldi
+        !--------------------------------------------------------------------
+        ! Initialize the tangent input with random noise: dx
+        !--------------------------------------------------------------------
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              iseed_2d(ji,jj) = - ( 456953 + &
+                &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+           END DO
+        END DO
+        CALL grid_random( iseed_2d, znu, 'U', 0.0_wp, stdu )
+        DO jj = 1, 4
+           DO ji = nldi, nlei
+              DO zip = 1, ziglo
+                 zu_tlin(ji+(zip-1)*zdiff,jj) = znu(ji,jj)
+              END DO
+           END DO
+        END DO
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              iseed_2d(ji,jj) = - ( 3434334 + &
+                &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+           END DO
+        END DO
+        CALL grid_random( iseed_2d, znu, 'V', 0.0_wp, stdu )
+        DO jj = 1, 4
+           DO ji = nldi, nlei
+              DO zip = 1, ziglo
+                 zv_tlin(ji+(zip-1)*zdiff,jj) = znu(ji,jj)
+              END DO
+           END DO
+        END DO
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              iseed_2d(ji,jj) = - ( 935678 + &
+                &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+           END DO
+        END DO
+        CALL grid_random( iseed_2d, znu, 'T', 0.0_wp, stdt )
+        DO jj = 1, 4
+           DO ji = nldi, nlei
+              DO zip = 1, ziglo
+                 zt_tlin(ji+(zip-1)*zdiff,jj) = znu(ji,jj)
+              END DO
+           END DO
+        END DO
+
+        !--------------------------------------------------------------------
+        ! Call the tangent routine: dy = L dx
+        !--------------------------------------------------------------------
+        zu_tl(:,:) = zu_tlin(:,:)
+        zv_tl(:,:) = zv_tlin(:,:)
+        zt_tl(:,:) = zt_tlin(:,:)
+
+        CALL lbc_nfd( zu_tl, 'U',  -1.0_wp )
+        CALL lbc_nfd( zv_tl, 'V',  -1.0_wp )
+        CALL lbc_nfd( zt_tl, 'T',   1.0_wp )
+        zu_tlout(:,:) = zu_tl(:,:)
+        zv_tlout(:,:) = zv_tl(:,:)
+        zt_tlout(:,:) = zt_tl(:,:)
+
+        DO jj = 1,4
+           DO ji = nldi, nlei
+              DO zip = 1, ziglo
+              zu_adin(ji+(zip-1)*zdiff,jj) = zu_tlout(ji+(zip-1)*ziglo,jj) &
+                 &               * e1u(ji,jj) * e2u(ji,jj) &!* fse3u(ji,jj) &
+                 &               * umask(ji,jj,1)
+              zv_adin(ji+(zip-1)*zdiff,jj) = zv_tlout(ji+(zip-1)*ziglo,jj) &
+                 &               * e1v(ji,jj) * e2v(ji,jj) &!* fse3v(ji,jj) &
+                 &               * vmask(ji,jj,1)
+              zt_adin(ji+(zip-1)*zdiff,jj) = zt_tlout(ji+(zip-1)*ziglo,jj) &
+                 &               * e1t(ji,jj) * e2t(ji,jj) &!* fse3t(ji,jj) &
+                 &               * tmask(ji,jj,1)
+              END DO
+           END DO
+        END DO
+
+        zsp1 = sum( &
+         &                       PACK(zu_tlout(:,:),.TRUE.) * &
+         &                       PACK( zu_adin(:,:),.TRUE.) )
+        zu_ad(:,:) = zu_adin(:,:)
+        zv_ad(:,:) = zv_adin(:,:)
+        zt_ad(:,:) = zt_adin(:,:)
+
+        CALL lbc_nfd_adj( zu_ad, 'U',  -1.0_wp )
+        CALL lbc_nfd_adj( zv_ad, 'V',  -1.0_wp )
+        CALL lbc_nfd_adj( zt_ad, 'T',   1.0_wp )
+
+        zu_adout(:,:) = zu_ad(:,:)
+        zv_adout(:,:) = zv_ad(:,:)
+        zt_adout(:,:) = zt_ad(:,:)
+
+        zsp2 = sum( &
+         &                       PACK(zu_tlin(:,:),.TRUE.) * &
+         &                       PACK( zu_adout(:,:),.TRUE.) )
+        cl_name = 'lbc_nfd  U  2d'
+        CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+        zsp1 = sum( &
+         &                       PACK(zv_tlout(:,:),.TRUE.) * &
+         &                       PACK( zv_adin(:,:),.TRUE.) )
+
+        zsp2 = sum( &
+         &                       PACK(zv_tlin(:,:),.TRUE.) * &
+         &                       PACK( zv_adout(:,:),.TRUE.) )
+        cl_name = 'lbc_nfd  V  2d'
+        CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+        zsp1 = sum( &
+         &                       PACK(zt_tlout(:,:),.TRUE.) * &
+         &                       PACK( zt_adin(:,:),.TRUE.) )
+
+        zsp2 = sum( &
+         &                       PACK(zt_tlin(:,:),.TRUE.) * &
+         &                       PACK( zt_adout(:,:),.TRUE.) )
+        cl_name = 'lbc_nfd  T  2d'
+        CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+   END SUBROUTINE lbc_nfd_2d_adj_tst
+
+   SUBROUTINE lbc_nfd_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE lbc_nfd_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !! ** Action  : 
+      !!                
+      !! History :
+      !!        ! 2010-09 (F. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt        ! Output unit
+
+      CALL lbc_nfd_3d_adj_tst( kumadt )
+      CALL lbc_nfd_2d_adj_tst( kumadt )
+
+   END SUBROUTINE lbc_nfd_adj_tst
+   !!======================================================================
+END MODULE lbcnfd_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/lib_mpp_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/lib_mpp_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/lib_mpp_tam.F90	(revision 2578)
@@ -0,0 +1,1399 @@
+#if defined key_mpp_mpi
+#if defined key_sp
+#define mpivar mpi_real
+#else
+#define mpivar mpi_double_precision
+#endif
+#endif
+MODULE lib_mpp_tam
+   !!======================================================================
+   !!                       ***  MODULE  lib_mpp_tam  ***
+   !! Ocean numerics:  massively parallel processing library (TAM counterpart)
+   !!=====================================================================
+   !! History of the direct module:
+   !!            OPA  !  1994  (M. Guyon, J. Escobar, M. Imbard)  Original code
+   !!            7.0  !  1997  (A.M. Treguier)  SHMEM additions
+   !!            8.0  !  1998  (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI
+   !!                 !  1998  (J.M. Molines) Open boundary conditions
+   !!   NEMO     1.0  !  2003  (J.-M. Molines, G. Madec)  F90, free form
+   !!                 !  2003  (J.M. Molines) add mpp_ini_north(_3d,_2d)
+   !!             -   !  2004  (R. Bourdalle Badie)  isend option in mpi
+   !!                 !  2004  (J.M. Molines) minloc, maxloc
+   !!             -   !  2005  (G. Madec, S. Masson)  npolj=5,6 F-point & ice cases
+   !!             -   !  2005  (R. Redler) Replacement of MPI_COMM_WORLD except for MPI_Abort
+   !!             -   !  2005  (R. Benshila, G. Madec)  add extra halo case
+   !!             -   !  2008  (R. Benshila) add mpp_ini_ice
+   !!            3.2  !  2009  (R. Benshila) SHMEM suppression, north fold in lbc_nfd
+   !!            3.2  !  2009  (O. Marti)    add mpp_ini_znl 
+   !! History of the TAM:
+   !!            2.?  !  2007  (K. Mogensen) Original code (lib_mppadj)
+   !!            3.0  !  2009  (A. Vidard) nemo v3 update
+   !!            3.2  !  2010  (A. Vidard) 3.2 version, complete rewrite
+   !!----------------------------------------------------------------------
+#if   defined key_mpp_mpi  
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_mpi'             MPI massively parallel processing library
+   !!----------------------------------------------------------------------
+   !!   mpp_lnk     : interface (defined in lbclnk) for message passing of 2d or 3d arrays (mpp_lnk_2d, mpp_lnk_3d)
+   !!   mpp_lnk_3d_gather :  Message passing manadgement for two 3D arrays
+   !!   mpp_lnk_e   : interface (defined in lbclnk) for message passing of 2d array with extra halo (mpp_lnk_2d_e)
+   !!   mppobc      : variant of mpp_lnk for open boundary condition
+   !!   mpp_lbc_north : north fold processors gathering
+   !!   mpp_lbc_north_e : variant of mpp_lbc_north for extra outer halo
+   !!----------------------------------------------------------------------
+   !! History of the direct module:
+   !!        !  94 (M. Guyon, J. Escobar, M. Imbard)  Original code
+   !!        !  97  (A.M. Treguier)  SHMEM additions
+   !!        !  98  (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI
+   !!   9.0  !  03  (J.-M. Molines, G. Madec)  F90, free form
+   !!        !  04  (R. Bourdalle Badie)  isend option in mpi
+   !!        !  05  (G. Madec, S. Masson)  npolj=5,6 F-point & ice cases
+   !!        !  05  (R. Redler) Replacement of MPI_COMM_WORLD except for MPI_Abort
+   !!        !  09  (R. Benshila) SHMEM suppression, north fold in lbc_nfd
+   !! History of the TAM:
+   !!            2.?  !  2007  (K. Mogensen) Original code (lib_mppadj)
+   !!            3.0  !  2009  (A. Vidard) nemo v3 update
+   !!            3.2  !  2010  (A. Vidard) 3.2 version, complete rewrite
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Id$
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!---------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce                    ! ocean space and time domain 
+   USE in_out_manager             ! I/O manager
+   USE lib_mpp
+   USE lbcnfd_tam                 ! north fold treatment
+   USE mppsumtam, ONLY : &
+      & mpp_sum_nfd 
+
+   IMPLICIT NONE
+   PRIVATE
+   
+   PUBLIC   mpp_lbc_north_adj, mpp_lbc_north_e_adj
+   PUBLIC   mpp_lnk_3d_adj, mpp_lnk_3d_gather_adj, mpp_lnk_2d_adj, mpp_lnk_2d_e_adj
+   PUBLIC   mppobc_adj
+
+   !! * Interfaces
+   !! define generic interface for these routine as they are called sometimes
+   !! with scalar arguments instead of array arguments, which causes problems
+   !! for the compilation on AIX system as well as NEC and SGI. Ok on COMPACQ
+   INTERFACE mpp_lbc_north_adj
+      MODULE PROCEDURE mpp_lbc_north_3d_adj, mpp_lbc_north_2d_adj 
+   END INTERFACE
+   !! ========================= !!
+   !!  MPI  variable definition !!
+   !! ========================= !!
+!$AGRIF_DO_NOT_TREAT
+#  include <mpif.h>
+!$AGRIF_END_DO_NOT_TREAT
+   
+   ! message passing arrays
+   ! Note: the adjoint of t4ns is t4sn:
+   REAL(wp), DIMENSION(jpi,jprecj,jpk,2,2) ::   t4ns_ad, t4sn_ad   ! 2 x 3d for north-south & south-north
+   REAL(wp), DIMENSION(jpj,jpreci,jpk,2,2) ::   t4ew_ad, t4we_ad   ! 2 x 3d for east-west & west-east
+   REAL(wp), DIMENSION(jpi,jprecj,jpk,2,2) ::   t4p1_ad, t4p2_ad   ! 2 x 3d for north fold
+   REAL(wp), DIMENSION(jpi,jprecj,jpk,2)   ::   t3ns_ad, t3sn_ad   ! 3d for north-south & south-north
+   REAL(wp), DIMENSION(jpj,jpreci,jpk,2)   ::   t3ew_ad, t3we_ad   ! 3d for east-west & west-east
+   REAL(wp), DIMENSION(jpi,jprecj,jpk,2)   ::   t3p1_ad, t3p2_ad   ! 3d for north fold
+   REAL(wp), DIMENSION(jpi,jprecj,2)       ::   t2ns_ad, t2sn_ad   ! 2d for north-south & south-north
+   REAL(wp), DIMENSION(jpj,jpreci,2)       ::   t2ew_ad, t2we_ad   ! 2d for east-west & west-east
+   REAL(wp), DIMENSION(jpi,jprecj,2)       ::   t2p1_ad, t2p2_ad   ! 2d for north fold
+   REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,jprecj+jpr2dj,2) ::   &
+      &                                         tr2ns_ad, tr2sn_ad ! 2d for north-south & south-north + extra outer halo
+   REAL(wp), DIMENSION(1-jpr2dj:jpj+jpr2dj,jpreci+jpr2di,2) ::   &
+      &                                         tr2ew_ad, tr2we_ad ! 2d for east-west   & west-east   + extra outer halo
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.2 , LOCEAN-IPSL (2009) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+
+   SUBROUTINE mpp_lnk_3d_adj( ptab_ad, cd_type, psgn, cd_mpp, pval )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_3d  ***
+      !!
+      !! ** Purpose :   Message passing manadgement
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask 
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors 
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !! ** Action  :   ptab_ad with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab_ad  ! 3D array on which the boundary condition is applied
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
+      !                                                             ! = T , U , V , F , W points
+      REAL(wp)                        , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
+      !                                                             ! =  1. , the sign is kept
+      CHARACTER(len=3), OPTIONAL      , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only 
+      REAL(wp)        , OPTIONAL      , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
+      !!
+      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      REAL(wp) ::   zland
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !!----------------------------------------------------------------------
+      t3ns_ad = 0.0_wp ; t3sn_ad = 0.0_wp
+      t3we_ad = 0.0_wp ; t3ew_ad = 0.0_wp
+      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
+      ELSE                         ;   zland = 0.e0      ! zero by default
+      ENDIF
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd_adj      ( ptab_ad, cd_type, psgn )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_lbc_north_adj( ptab_ad, cd_type, psgn )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj-jprecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            t3ns_ad(:,jl,:,2)     = t3ns_ad(:,jl,:,2) + ptab_ad(:,ijhom+jl,:)
+            ptab_ad(:,ijhom+jl,:) = 0._wp
+         END DO
+      CASE ( 0 ) 
+         DO jl = 1, jprecj
+            t3ns_ad(:,jl,:,2)     = t3ns_ad(:,jl,:,2) + ptab_ad(:,ijhom+jl,:)
+            ptab_ad(:,ijhom+jl,:) = 0.0_wp
+            t3sn_ad(:,jl,:,2)     = t3sn_ad(:,jl,:,2) + ptab_ad(:,jl      ,:)
+            ptab_ad(:,jl      ,:) = 0.0_wp
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            t3sn_ad(:,jl,:,2) = t3sn_ad(:,jl,:,2) + ptab_ad(:,jl,:)
+            ptab_ad(:,jl,:)   = 0.0_wp
+         END DO
+      END SELECT
+! 
+      !                           ! Migrations
+      imigr = jprecj * jpi * jpk
+      SELECT CASE ( nbondj )     
+      CASE ( -1 )
+         CALL mppsend( 4, t3ns_ad(1,1,1,2), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, t3sn_ad(1,1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, t3sn_ad(1,1,1,2), imigr, noso, ml_req1 )
+         CALL mppsend( 4, t3ns_ad(1,1,1,2), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, t3sn_ad(1,1,1,1), imigr )
+         CALL mpprecv( 4, t3ns_ad(1,1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 ) 
+         CALL mppsend( 3, t3sn_ad(1,1,1,2), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, t3ns_ad(1,1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            ptab_ad(:,jprecj+jl,:) = ptab_ad(:,jprecj+jl,:) + t3ns_ad(:,jl,:,1)
+            t3ns_ad(:,jl,:,1)      = 0.0_wp
+            ptab_ad(:,ijhom +jl,:) = ptab_ad(:,ijhom +jl,:) + t3sn_ad(:,jl,:,1)
+            t3sn_ad(:,jl,:,1)      = 0.0_wp
+         END DO
+      ENDIF
+      !
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      iihom = nlci-jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            t3ew_ad(:,jl,:,2)     = t3ew_ad(:,jl,:,2) + ptab_ad(iihom+jl,:,:)
+            ptab_ad(iihom+jl,:,:) = 0.0_wp
+         END DO
+      CASE ( 0 ) 
+         DO jl = 1, jpreci
+            t3ew_ad(:,jl,:,2)     = t3ew_ad(:,jl,:,2) + ptab_ad(iihom+jl,:,:)
+            ptab_ad(iihom+jl,:,:) = 0.0_wp
+            t3we_ad(:,jl,:,2)     = t3we_ad(:,jl,:,2) + ptab_ad(jl      ,:,:)
+            ptab_ad(jl      ,:,:) = 0.0_wp
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            t3we_ad(:,jl,:,2)     = t3we_ad(:,jl,:,2) + ptab_ad(jl      ,:,:)
+            ptab_ad(jl      ,:,:) = 0.0_wp
+         END DO
+      END SELECT
+      !                           ! Write Dirichlet lateral conditions
+      !                           ! Migrations
+      imigr = jpreci * jpj * jpk
+      !
+      SELECT CASE ( nbondi ) 
+      CASE ( -1 )
+         CALL mppsend( 2, t3ew_ad(1,1,1,2), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, t3we_ad(1,1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, t3we_ad(1,1,1,2), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, t3ew_ad(1,1,1,2), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, t3we_ad(1,1,1,1), imigr )
+         CALL mpprecv( 2, t3ew_ad(1,1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, t3we_ad(1,1,1,2), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, t3ew_ad(1,1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      ! we play with the neigbours AND the row number because of the periodicity 
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            ptab_ad(iihom +jl,:,:) = ptab_ad(iihom +jl,:,:) + t3we_ad(:,jl,:,1)
+            t3we_ad(:,jl,:,1) = 0.0_wp
+            ptab_ad(jpreci+jl,:,:) = ptab_ad(jpreci+jl,:,:) + t3ew_ad(:,jl,:,1)
+            t3ew_ad(:,jl,:,1) = 0.0_wp
+         END DO
+      END SELECT  
+      !
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
+         !
+         ! WARNING ptab is defined only between nld and nle
+         DO jk = 1, jpk
+            DO ji = nlci+1, jpi                 ! added column(s) (full)
+               ptab_ad(nlei,      nlej   ,jk) = ptab_ad(nlei,nlej     ,jk) + SUM(ptab_ad(ji,nlej+1:jpj   ,jk))
+               ptab_ad(ji  ,nlej+1:jpj   ,jk) = 0.0_wp
+               ptab_ad(nlei,nldj         ,jk) = ptab_ad(nlei,nldj     ,jk) + SUM(ptab_ad(ji,1     :nldj-1,jk))
+               ptab_ad(ji  ,1     :nldj-1,jk) = 0.0_wp
+               ptab_ad(nlei,nldj  :nlej  ,jk) = ptab_ad(nlei,nldj:nlej,jk) + ptab_ad(ji,nldj  :nlej  ,jk)
+               ptab_ad(ji  ,nldj  :nlej  ,jk) = 0.0_wp
+            END DO
+            DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
+               ptab_ad(nlei         ,nlej,jk) = ptab_ad(nlei     ,nlej,jk) + SUM(ptab_ad(nlei+1:nlci  ,jj,jk))
+               ptab_ad(nlei+1:nlci  ,jj  ,jk) = 0.0_wp
+               ptab_ad(nldi         ,nlej,jk) = ptab_ad(nldi     ,nlej,jk) + SUM(ptab_ad(1     :nldi-1,jj,jk))
+               ptab_ad(1     :nldi-1,jj  ,jk) = 0.0_wp
+               ptab_ad(nldi  :nlei  ,nlej,jk) = ptab_ad(nldi:nlei,nlej,jk) + ptab_ad(nldi  :nlei  ,jj,jk)
+               ptab_ad(nldi  :nlei  ,jj  ,jk) = 0.0_wp
+            END DO
+         END DO
+         !
+      ELSE                              ! standard close or cyclic treatment 
+         !
+         !                                   ! North-South boundaries (always closed)
+                                      ptab_ad(:,nlcj-jprecj+1:jpj   ,:) = 0.0_wp       ! north
+         IF( .NOT. cd_type == 'F' )   ptab_ad(:,     1       :jprecj,:) = 0.0_wp       ! south except F-point
+         !                                   ! East-West boundaries
+         !                                        !* Cyclic east-west
+         IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+            ptab_ad( 2   ,:,:) = ptab_ad(  2  ,:,:) + ptab_ad(jpi,:,:) 
+            ptab_ad(jpi  ,:,:) = 0.0_wp
+            ptab_ad(jpim1,:,:) = ptab_ad(jpim1,:,:) + ptab_ad( 1 ,:,:)
+            ptab_ad( 1   ,:,:) = 0.0_wp
+         ELSE                                     !* closed
+            IF( .NOT. cd_type == 'F' )   ptab_ad(     1       :jpreci,:,:) = 0.0_wp    ! south except F-point
+                                         ptab_ad(nlci-jpreci+1:jpi   ,:,:) = 0.0_wp    ! north
+         ENDIF
+         !
+      ENDIF
+      !
+   END SUBROUTINE mpp_lnk_3d_adj
+
+
+   SUBROUTINE mpp_lnk_2d_adj( pt2d_ad, cd_type, psgn, cd_mpp, pval )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_2d  ***
+      !!                  
+      !! ** Purpose :   Message passing manadgement for 2d array
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask 
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors 
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d_ad  ! 2D array on which the boundary condition is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
+      !                                                         ! = T , U , V , F , W and I points
+      REAL(wp)                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
+      !                                                         ! =  1. , the sign is kept
+      CHARACTER(len=3), OPTIONAL  , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only 
+      REAL(wp)        , OPTIONAL  , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
+      !!
+      INTEGER  ::   ji, jj, jl   ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      REAL(wp) ::   zland
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !!----------------------------------------------------------------------
+      t2ns_ad = 0.0_wp ; t2sn_ad = 0.0_wp
+      t2we_ad = 0.0_wp ; t2ew_ad = 0.0_wp
+      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
+      ELSE                         ;   zland = 0.e0      ! zero by default
+      ENDIF
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd_adj      ( pt2d_ad, cd_type, psgn )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_lbc_north_adj( pt2d_ad, cd_type, psgn )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+      !
+      ! 3. North and south directions
+      ! -----------------------------
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj - jprecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            t2ns_ad(:,jl,2)     = t2ns_ad(:,jl,2) + pt2d_ad(:,ijhom+jl)
+            pt2d_ad(:,ijhom+jl) = t2ns_ad(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            t2ns_ad(:,jl,2)     = t2ns_ad(:,jl,2) + pt2d_ad(:,ijhom+jl)
+            pt2d_ad(:,ijhom+jl) = 0.0_wp
+            t2sn_ad(:,jl,2)     = t2sn_ad(:,jl,2) + pt2d_ad(:,jl      )
+            pt2d_ad(:,jl      ) = 0.0_wp
+         END DO
+      CASE ( 1 ) 
+         DO jl = 1, jprecj
+            t2sn_ad(:,jl,2) = t2sn_ad(:,jl,2) + pt2d_ad(:,jl      ) 
+            pt2d_ad(:,jl      ) = 0.0_wp
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, t2ns_ad(1,1,2), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, t2sn_ad(1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, t2sn_ad(1,1,2), imigr, noso, ml_req1 )
+         CALL mppsend( 4, t2ns_ad(1,1,2), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, t2sn_ad(1,1,1), imigr )
+         CALL mpprecv( 4, t2ns_ad(1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, t2sn_ad(1,1,2), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, t2ns_ad(1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            pt2d_ad(:,jprecj+jl) = pt2d_ad(:,jprecj+jl) + t2ns_ad(:,jl,1)
+            t2ns_ad(:,jl,1) = 0.0_wp
+            pt2d_ad(:,ijhom +jl) = pt2d_ad(:,ijhom +jl) + t2sn_ad(:,jl,1)
+            t2sn_ad(:,jl,1) = 0.0_wp
+         END DO
+      ENDIF
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci - jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            t2ew_ad(:,jl,2)     = t2ew_ad(:,jl,2) + pt2d_ad(iihom+jl,:)
+            pt2d_ad(iihom+jl,:) = 0.0_wp
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            t2ew_ad(:,jl,2)     = t2ew_ad(:,jl,2) + pt2d_ad(iihom+jl,:)
+            pt2d_ad(iihom+jl,:) = 0.0_wp
+            t2we_ad(:,jl,2)     = t2we_ad(:,jl,2) + pt2d_ad(jl      ,:)
+            pt2d_ad(jl      ,:) = 0.0_wp
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            t2we_ad(:,jl,2) = t2we_ad(:,jl,2) + pt2d_ad(jl,:)
+            pt2d_ad(jl,:)   = 0.0_wp
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, t2ew_ad(1,1,2), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, t2we_ad(1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, t2we_ad(1,1,2), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, t2ew_ad(1,1,2), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, t2we_ad(1,1,1), imigr )
+         CALL mpprecv( 2, t2ew_ad(1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, t2we_ad(1,1,2), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, t2ew_ad(1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      ! we play with the neigbours AND the row number because of the periodicity 
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            pt2d_ad(iihom +jl,:) = pt2d_ad(iihom +jl,:) + t2we_ad(:,jl,1)
+            t2we_ad(:,jl,1)      = 0.0_wp
+            pt2d_ad(jpreci+jl,:) = pt2d_ad(jpreci+jl,:) + t2ew_ad(:,jl,1)
+            t2ew_ad(:,jl,1)      = 0.0_wp
+         END DO
+      END SELECT
+      !
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      !
+      IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
+         !
+         ! WARNING pt2d is defined only between nld and nle
+         DO ji = nlci+1, jpi                 ! added column(s) (full)
+            pt2d_ad(nlei,       nlej  ) = pt2d_ad(nlei,     nlej) + SUM(pt2d_ad(ji,nlej+1:jpj   ))
+            pt2d_ad(ji  ,nlej+1:jpj   ) = 0.0_wp
+            pt2d_ad(nlei,nldj         ) = pt2d_ad(nlei,nldj     ) + SUM(pt2d_ad(ji,1     :nldj-1))
+            pt2d_ad(ji  ,1     :nldj-1) = 0.0_wp
+            pt2d_ad(nlei,nldj  :nlej  ) = pt2d_ad(nlei,nldj:nlej) + pt2d_ad(ji,nldj  :nlej  )
+            pt2d_ad(ji  ,nldj  :nlej  ) = 0.0_wp
+         END DO
+         DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
+            pt2d_ad(nlei         ,nlej) = pt2d_ad(     nlei,     nlej) + SUM(pt2d_ad(nlei+1:nlci  , jj))
+            pt2d_ad(nlei+1:nlci  ,jj  ) = 0.0_wp
+            pt2d_ad(nldi         ,nlej) = pt2d_ad(nldi     ,     nlej) + SUM(pt2d_ad(1     :nldi-1, jj))
+            pt2d_ad(1     :nldi-1,jj  ) = 0.0_wp
+            pt2d_ad(nldi  :nlei  ,nlej) = pt2d_ad(nldi:nlei,     nlej) + pt2d_ad(nldi  :nlei  , jj)
+            pt2d_ad(nldi  :nlei  , jj ) = 0.0_wp
+         END DO
+         !
+      ELSE                              ! standard close or cyclic treatment 
+         !
+         !                                   ! North-South boundaries (always closed)
+            IF( .NOT. cd_type == 'F' )   pt2d_ad(:,     1       :jprecj) = 0.0_wp !south except F-point
+                                         pt2d_ad(:,nlcj-jprecj+1:jpj   ) = 0.0_wp ! north
+         !                                   ! East-West boundaries
+         IF( nbondi == 2 .AND.   &                ! Cyclic east-west
+            &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+            pt2d_ad(  2  ,:) = pt2d_ad(  2  ,:) + pt2d_ad(jpi,:) ! east
+            pt2d_ad(jpi  ,:) = 0.0_wp
+            pt2d_ad(jpim1,:) = pt2d_ad(jpim1,:) + pt2d_ad( 1 ,:) ! west
+            pt2d_ad( 1   ,:) = 0.0_wp                                    
+         ELSE                                     ! closed
+            IF( .NOT. cd_type == 'F' )   pt2d_ad(     1       :jpreci,:) = 0.0_wp   ! south except F-point
+                                         pt2d_ad(nlci-jpreci+1:jpi   ,:) = 0.0_wp   ! north
+         ENDIF
+         !
+      ENDIF
+
+   END SUBROUTINE mpp_lnk_2d_adj
+
+
+   SUBROUTINE mpp_lnk_3d_gather_adj( ptab1_ad, cd_type1, ptab2_ad, cd_type2, psgn )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_3d_gather  ***
+      !!
+      !! ** Purpose :   Message passing manadgement for two 3D arrays
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask 
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors 
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !! ** Action  :   ptab1 and ptab2  with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab1_ad  ! first and second 3D array on which 
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab2_ad  ! the boundary condition is applied
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type1  ! nature of ptab1 and ptab2 arrays 
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type2  ! i.e. grid-points = T , U , V , F or W points
+      REAL(wp)                        , INTENT(in   ) ::   psgn      ! =-1 the sign change across the north fold boundary
+      !!                                                             ! =  1. , the sign is kept
+      INTEGER  ::   jl   ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !!----------------------------------------------------------------------
+      t4ns_ad = 0.0_wp ; t4sn_ad = 0.0_wp
+      t4we_ad = 0.0_wp ; t4ew_ad = 0.0_wp
+      ! 4. north fold treatment
+      ! -----------------------
+      IF( npolj /= 0 ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )                                           
+            CALL lbc_nfd_adj      ( ptab2_ad, cd_type2, psgn )
+            CALL lbc_nfd_adj      ( ptab1_ad, cd_type1, psgn )   ! only for northern procs.
+         CASE DEFAULT
+            CALL mpp_lbc_north_adj( ptab2_ad, cd_type2, psgn)
+            CALL mpp_lbc_north_adj( ptab1_ad, cd_type1, psgn )   ! for all northern procs.
+         END SELECT 
+         !
+      ENDIF
+      !
+      ! 3. North and south directions
+      ! -----------------------------
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj - jprecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            t4ns_ad(:,jl,:,2,2)    = t4ns_ad(:,jl,:,2,2) + ptab2_ad(:,ijhom+jl,:)
+            ptab2_ad(:,ijhom+jl,:) = 0.0_wp
+            t4ns_ad(:,jl,:,1,2)    = t4ns_ad(:,jl,:,1,2) + ptab1_ad(:,ijhom+jl,:) 
+            ptab1_ad(:,ijhom+jl,:) = 0.0_wp
+         END DO
+      CASE ( 0 ) 
+         DO jl = 1, jprecj
+            t4ns_ad(:,jl,:,2,2)    = t4ns_ad(:,jl,:,2,2) + ptab2_ad(:,ijhom+jl,:)
+            ptab2_ad(:,ijhom+jl,:) = 0.0_wp
+            t4sn_ad(:,jl,:,2,2)    = t4sn_ad(:,jl,:,2,2) + ptab2_ad(:,jl      ,:)
+            ptab2_ad(:,jl      ,:) = 0.0_wp
+            t4ns_ad(:,jl,:,1,2)    = t4ns_ad(:,jl,:,1,2) + ptab1_ad(:,ijhom+jl,:)
+            ptab1_ad(:,ijhom+jl,:) = 0.0_wp
+            t4sn_ad(:,jl,:,1,2)    = t4sn_ad(:,jl,:,1,2) + ptab1_ad(:,jl      ,:)
+            ptab1_ad(:,jl      ,:) = 0.0_wp
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            t4sn_ad(:,jl,:,2,2) = t4sn_ad(:,jl,:,2,2) + ptab2_ad(:,jl,:)
+            ptab2_ad(:,jl,:) = 0.0_wp
+            t4sn_ad(:,jl,:,1,2) = t4sn_ad(:,jl,:,1,2) + ptab1_ad(:,jl,:)
+            ptab1_ad(:,jl,:) = 0.0_wp
+         END DO
+      END SELECT
+      !                           ! Migrations
+      imigr = jprecj * jpi * jpk * 2
+      !
+      SELECT CASE ( nbondj )     
+      CASE ( -1 )
+         CALL mppsend( 4, t4ns_ad(1,1,1,1,2), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, t4sn_ad(1,1,1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, t4sn_ad(1,1,1,1,2), imigr, noso, ml_req1 )
+         CALL mppsend( 4, t4ns_ad(1,1,1,1,2), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, t4sn_ad(1,1,1,1,1), imigr )
+         CALL mpprecv( 4, t4ns_ad(1,1,1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 ) 
+         CALL mppsend( 3, t4sn_ad(1,1,1,1,2), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, t4ns_ad(1,1,1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj - nrecj
+         DO jl = 1, jprecj
+            ptab2_ad(:,jprecj+jl,:) = ptab2_ad(:,jprecj+jl,:) + t4ns_ad(:,jl,:,2,1) 
+            t4ns_ad(:,jl,:,2,1)     = 0.0_wp
+            ptab2_ad(:,ijhom +jl,:) = ptab2_ad(:,ijhom +jl,:) + t4sn_ad(:,jl,:,2,1)
+            t4sn_ad(:,jl,:,2,1)     = 0.0_wp
+            ptab1_ad(:,jprecj+jl,:) = ptab1_ad(:,jprecj+jl,:) + t4ns_ad(:,jl,:,1,1)
+            t4ns_ad(:,jl,:,1,1)     = 0.0_wp
+            ptab1_ad(:,ijhom +jl,:) = ptab1_ad(:,ijhom +jl,:) + t4sn_ad(:,jl,:,1,1)
+            t4sn_ad(:,jl,:,1,1)     = 0.0_wp
+         END DO
+      ENDIF
+      !
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci - jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            t4ew_ad(:,jl,:,2,2)    = t4ew_ad(:,jl,:,2,2) + ptab2_ad(iihom+jl,:,:)
+            ptab2_ad(iihom+jl,:,:) = 0.0_wp
+            t4ew_ad(:,jl,:,1,2)    = t4ew_ad(:,jl,:,1,2) + ptab1_ad(iihom+jl,:,:)
+            ptab1_ad(iihom+jl,:,:) = 0.0_wp
+         END DO
+      CASE ( 0 ) 
+         DO jl = 1, jpreci
+            t4ew_ad(:,jl,:,2,2)    = t4ew_ad(:,jl,:,2,2) + ptab2_ad(iihom+jl,:,:)
+            ptab2_ad(iihom+jl,:,:) = 0.0_wp
+            t4we_ad(:,jl,:,2,2)    = t4we_ad(:,jl,:,2,2) + ptab2_ad(jl      ,:,:)
+            ptab2_ad(jl      ,:,:) = 0.0_wp
+            t4ew_ad(:,jl,:,1,2)    = t4ew_ad(:,jl,:,1,2) + ptab1_ad(iihom+jl,:,:) 
+            ptab1_ad(iihom+jl,:,:) = 0.0_wp
+            t4we_ad(:,jl,:,1,2)    = t4we_ad(:,jl,:,1,2) + ptab1_ad(jl      ,:,:)
+            ptab1_ad(jl      ,:,:) = 0.0_wp
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            t4we_ad(:,jl,:,2,2) = t4we_ad(:,jl,:,2,2) + ptab2_ad(jl      ,:,:)
+            t4we_ad(:,jl,:,1,2) = t4we_ad(:,jl,:,1,2) + ptab1_ad(jl      ,:,:)
+            ptab1_ad(jl      ,:,:) = 0.0_wp
+            ptab2_ad(jl      ,:,:) = 0.0_wp
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj * jpk *2
+      !
+      SELECT CASE ( nbondi ) 
+      CASE ( -1 )
+         CALL mppsend( 2, t4ew_ad(1,1,1,1,2), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, t4we_ad(1,1,1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, t4we_ad(1,1,1,1,2), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, t4ew_ad(1,1,1,1,2), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, t4we_ad(1,1,1,1,1), imigr )
+         CALL mpprecv( 2, t4ew_ad(1,1,1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, t4we_ad(1,1,1,1,2), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, t4ew_ad(1,1,1,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      ! we play with the neigbours AND the row number because of the periodicity 
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            ptab2_ad(iihom +jl,:,:) = ptab2_ad(iihom +jl,:,:) + t4we_ad(:,jl,:,2,1)
+            t4we_ad(:,jl,:,2,1)     = 0.0_wp
+            ptab2_ad(jpreci+jl,:,:) = ptab2_ad(jpreci+jl,:,:) + t4ew_ad(:,jl,:,2,1)
+            t4ew_ad(:,jl,:,2,1)     = 0.0_wp
+            ptab1_ad(iihom +jl,:,:) = ptab1_ad(iihom +jl,:,:) + t4we_ad(:,jl,:,1,1)
+            t4we_ad(:,jl,:,1,1)     = 0.0_wp
+            ptab1_ad(jpreci+jl,:,:) = ptab1_ad(jpreci+jl,:,:) + t4ew_ad(:,jl,:,1,1)
+            t4ew_ad(:,jl,:,1,1)     = 0.0_wp
+         END DO
+      END SELECT
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      !                                      ! East-West boundaries
+      !                                           !* Cyclic east-west
+      !                                      ! North-South boundaries
+                                    ptab2_ad(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+                                    ptab1_ad(:,nlcj-jprecj+1:jpj   ,:) = 0.e0    ! north
+      IF( .NOT. cd_type2 == 'F' )   ptab2_ad(:,     1       :jprecj,:) = 0.e0
+      IF( .NOT. cd_type1 == 'F' )   ptab1_ad(:,     1       :jprecj,:) = 0.e0    ! south except at F-point
+      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+         ptab2_ad(  2  ,:,:) = ptab2_ad(  2  ,:,:) + ptab2_ad(jpi,:,:)
+         ptab2_ad(jpi,:,:)   = 0.0_wp
+         ptab2_ad(jpim1,:,:) = ptab2_ad(jpim1,:,:) + ptab2_ad( 1 ,:,:)
+         ptab2_ad( 1 ,:,:)   = 0.0_wp
+         ptab1_ad(  2  ,:,:) = ptab1_ad(  2  ,:,:) + ptab1_ad(jpi,:,:)
+         ptab1_ad(jpi,:,:)   = 0.0_wp
+         ptab1_ad(jpim1,:,:) = ptab1_ad(jpim1,:,:) + ptab1_ad( 1 ,:,:)
+         ptab1_ad( 1 ,:,:)   = 0.0_wp
+      ELSE                                        !* closed
+         IF( .NOT. cd_type1 == 'F' )   ptab1_ad(     1       :jpreci,:,:) = 0.e0    ! south except at F-point
+         IF( .NOT. cd_type2 == 'F' )   ptab2_ad(     1       :jpreci,:,:) = 0.e0
+                                       ptab1_ad(nlci-jpreci+1:jpi   ,:,:) = 0.e0    ! north
+                                       ptab2_ad(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+      ENDIF
+
+   END SUBROUTINE mpp_lnk_3d_gather_adj
+
+
+   SUBROUTINE mpp_lnk_2d_e_adj( pt2d_ad, cd_type, psgn )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_2d_e  ***
+      !!                  
+      !! ** Purpose :   Message passing manadgement for 2d array (with halo)
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask 
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    jpr2di : number of rows for extra outer halo
+      !!                    jpr2dj : number of columns for extra outer halo
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors 
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj), INTENT(inout) ::   pt2d_ad ! 2D array with extra halo
+      CHARACTER(len=1)                                            , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
+      !                                                                                         ! = T , U , V , F , W and I points
+      REAL(wp)                                                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the
+      !!                                                                                        ! north boundary, =  1. otherwise
+      INTEGER  ::   jl   ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ipreci, iprecj             ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !!----------------------------------------------------------------------
+
+      ipreci = jpreci + jpr2di      ! take into account outer extra 2D overlap area
+      iprecj = jprecj + jpr2dj
+      tr2ns_ad = 0.0_wp ; tr2sn_ad = 0.0_wp
+      tr2we_ad = 0.0_wp ; tr2ew_ad = 0.0_wp
+      ! 3. North and south directions
+      ! -----------------------------
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj - jprecj  
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, iprecj
+            tr2ns_ad(:,jl,2) = tr2ns_ad(:,jl,2) + pt2d_ad(:,ijhom+jl)
+            pt2d_ad(:,ijhom+jl) = 0.0_wp
+         END DO
+      CASE ( 0 )
+         DO jl = 1, iprecj
+            tr2ns_ad(:,jl,2)     = tr2ns_ad(:,jl,2) + pt2d_ad(:,ijhom+jl )
+            pt2d_ad(:,ijhom+jl ) = 0.0_wp
+            tr2sn_ad(:,jl,2)     = tr2sn_ad(:,jl,2) + pt2d_ad(:,jl-jpr2dj)
+            pt2d_ad(:,jl-jpr2dj) = 0.0_wp
+         END DO
+      CASE ( 1 ) 
+         DO jl = 1, iprecj
+            tr2sn_ad(:,jl,2) = tr2sn_ad(:,jl,2) + pt2d_ad(:,jl-jpr2dj)
+            pt2d_ad(:,jl-jpr2dj) = 0.0_wp
+         END DO
+      END SELECT
+      !                           ! Migrations
+      imigr = iprecj * ( jpi + 2*jpr2di )
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, tr2ns_ad(1-jpr2di,1,2), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, tr2sn_ad(1-jpr2di,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, tr2sn_ad(1-jpr2di,1,2), imigr, noso, ml_req1 )
+         CALL mppsend( 4, tr2ns_ad(1-jpr2di,1,2), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, tr2sn_ad(1-jpr2di,1,1), imigr )
+         CALL mpprecv( 4, tr2ns_ad(1-jpr2di,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, tr2sn_ad(1-jpr2di,1,2), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, tr2ns_ad(1-jpr2di,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj-jpr2dj
+         DO jl = 1, iprecj
+            pt2d_ad(:,jprecj+jl) = pt2d_ad(:,jprecj+jl) + tr2ns_ad(:,jl,1)
+            tr2ns_ad(:,jl,1) = 0.0_wp
+            pt2d_ad(:,ijhom +jl) = pt2d_ad(:,ijhom +jl) + tr2sn_ad(:,jl,1)
+            tr2sn_ad(:,jl,1) = 0.0_wp
+         END DO
+      ENDIF
+      !
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci - jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, ipreci
+            tr2ew_ad(:,jl,2)    = tr2ew_ad(:,jl,2) + pt2d_ad(iihom+jl,:)
+            pt2d_ad(iihom+jl,:) = 0.0_wp
+         END DO
+      CASE ( 0 )
+         DO jl = 1, ipreci
+            tr2ew_ad(:,jl,2)  = tr2ew_ad(:,jl,2) + pt2d_ad( iihom+jl,:)
+            pt2d_ad( iihom+jl,:) = 0.0_wp
+            tr2we_ad(:,jl,2)  = tr2we_ad(:,jl,2) + pt2d_ad(jl-jpr2di,:)
+            pt2d_ad(jl-jpr2di,:) = 0.0_wp
+         END DO
+      CASE ( 1 )
+         DO jl = 1, ipreci
+            tr2we_ad(:,jl,2)     = tr2we_ad(:,jl,2) + pt2d_ad(jl-jpr2di,:) 
+            pt2d_ad(jl-jpr2di,:) = 0.0_wp
+         END DO
+      END SELECT
+      !                           ! Migrations
+      imigr = ipreci * ( jpj + 2*jpr2dj)
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, tr2ew_ad(1-jpr2dj,1,2), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, tr2we_ad(1-jpr2dj,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, tr2we_ad(1-jpr2dj,1,2), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, tr2ew_ad(1-jpr2dj,1,2), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, tr2we_ad(1-jpr2dj,1,1), imigr )
+         CALL mpprecv( 2, tr2ew_ad(1-jpr2dj,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, tr2we_ad(1-jpr2dj,1,2), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, tr2ew_ad(1-jpr2dj,1,1), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      ! we play with the neigbours AND the row number because of the periodicity 
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci-jpr2di
+         DO jl = 1, ipreci
+            pt2d_ad(iihom +jl,:) = pt2d_ad(iihom +jl,:) + tr2we_ad(:,jl,1)
+            tr2we_ad(:,jl,1)     = 0.0_wp
+            pt2d_ad(jpreci+jl,:) = pt2d_ad(jpreci+jl,:) + tr2ew_ad(:,jl,1)
+            tr2ew_ad(:,jl,1)     = 0.0_wp
+         END DO
+      END SELECT
+      !
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      ! Order matters Here !!!!
+      !
+      ! north fold treatment
+      ! -----------------------
+      IF( npolj /= 0 ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd_adj        ( pt2d_ad(1:jpi,1:jpj+jpr2dj), cd_type, psgn, pr2dj=jpr2dj )
+         CASE DEFAULT   ;   CALL mpp_lbc_north_e_adj( pt2d_ad                    , cd_type, psgn               )
+         END SELECT 
+         !
+      ENDIF
+      !                                      ! East-West boundaries
+      !                                           !* Cyclic east-west
+      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+         pt2d_ad(     2      :2+jpr2di  ,:) = pt2d_ad(     2      :2+jpr2di  ,:) &
+            &                               + pt2d_ad(    jpi     :jpi+jpr2di,:)! west
+         pt2d_ad(   jpi      :jpi+jpr2di,:) = 0.0_wp
+         pt2d_ad(jpim1-jpr2di:  jpim1   ,:) = pt2d_ad(jpim1-jpr2di:  jpim1   ,:) &
+            &                               + pt2d_ad(1-jpr2di    :     1    ,:)! east
+         pt2d_ad(1-jpr2di    :     1    ,:) = 0.0_wp
+         !
+      ELSE                                        !* closed
+                                      pt2d_ad(nlci-jpreci+1:jpi+jpr2di,:) = 0.e0    ! north
+         IF( .NOT. cd_type == 'F' )   pt2d_ad(  1-jpr2di   :jpreci    ,:) = 0.e0    ! south except at F-point
+      ENDIF
+      !
+      !                                      !* North-South boundaries (always colsed)
+                                   pt2d_ad(:,nlcj-jprecj+1:jpj+jpr2dj) = 0.e0    ! north
+      IF( .NOT. cd_type == 'F' )   pt2d_ad(:,  1-jpr2dj   :  jprecj  ) = 0.e0    ! south except at F-point
+                                
+
+   END SUBROUTINE mpp_lnk_2d_e_adj
+
+
+
+   SUBROUTINE mppobc_adj( ptab_ad, kd1, kd2, kl, kk, ktype, kij )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppobc  ***
+      !! 
+      !! ** Purpose :   Message passing manadgement for open boundary
+      !!     conditions array
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!       between processors following neighboring subdomains.
+      !!       domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors 
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                     ::   kd1, kd2   ! starting and ending indices
+      INTEGER , INTENT(in   )                     ::   kl         ! index of open boundary
+      INTEGER , INTENT(in   )                     ::   kk         ! vertical dimension
+      INTEGER , INTENT(in   )                     ::   ktype      ! define north/south or east/west cdt
+      !                                                           !  = 1  north/south  ;  = 2  east/west
+      INTEGER , INTENT(in   )                     ::   kij        ! horizontal dimension
+      REAL(wp), INTENT(inout), DIMENSION(kij,kk)  ::   ptab_ad    ! variable array
+      !! 
+      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
+      INTEGER  ::   iipt0, iipt1, ilpt1   ! temporary integers
+      INTEGER  ::   ijpt0, ijpt1          !    -          -
+      INTEGER  ::   imigr, iihom, ijhom   !    -          -
+      INTEGER ::   ml_req1, ml_req2, ml_err    ! for key_mpi_isend
+      INTEGER ::   ml_stat(MPI_STATUS_SIZE)    ! for key_mpi_isend
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztabad ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      ! boundary condition initialization
+      ! ---------------------------------
+      ztabad(:,:) = 0.e0
+      !
+      IF( ktype==1 ) THEN                                  ! north/south boundaries
+         iipt0 = MAX( 1, MIN(kd1 - nimpp+1, nlci     ) )
+         iipt1 = MAX( 0, MIN(kd2 - nimpp+1, nlci - 1 ) )
+         ilpt1 = MAX( 1, MIN(kd2 - nimpp+1, nlci     ) )
+         ijpt0 = MAX( 1, MIN(kl  - njmpp+1, nlcj     ) )
+         ijpt1 = MAX( 0, MIN(kl  - njmpp+1, nlcj - 1 ) )
+      ELSEIF( ktype==2 ) THEN                              ! east/west boundaries
+         iipt0 = MAX( 1, MIN(kl  - nimpp+1, nlci     ) )
+         iipt1 = MAX( 0, MIN(kl  - nimpp+1, nlci - 1 ) )
+         ijpt0 = MAX( 1, MIN(kd1 - njmpp+1, nlcj     ) )
+         ijpt1 = MAX( 0, MIN(kd2 - njmpp+1, nlcj - 1 ) )
+         ilpt1 = MAX( 1, MIN(kd2 - njmpp+1, nlcj     ) )
+      ELSE
+         CALL ctl_stop( 'mppobc: bad ktype' )
+      ENDIF
+      
+      ! Communication level by level
+      ! ----------------------------
+!!gm Remark : this is very time consumming!!!
+      !                                         ! ------------------------ !
+      DO jk = 1, kk                             !   Loop over the levels   !
+         !                                      ! ------------------------ !
+         !
+         ! 2. North and south directions
+         ! -----------------------------
+         !
+         !                              ! Write Dirichlet lateral conditions
+         ijhom = nlcj - jprecj
+         IF( ktype==1 .AND. kd1 <= jpi+nimpp-1 .AND. nimpp <= kd2 ) THEN
+            DO jj = ijpt0, ijpt1            ! north/south boundaries
+               DO ji = iipt0,ilpt1
+                  ztabad(ji,jj)  = ztabad(ji,jj) + ptab_ad(ji,jk)
+                  ptab_ad(ji,jk) = 0.0_wp
+               END DO
+            END DO
+         ELSEIF( ktype==2 .AND. kd1 <= jpj+njmpp-1 .AND. njmpp <= kd2 ) THEN
+            DO jj = ijpt0, ilpt1            ! east/west boundaries
+               DO ji = iipt0,iipt1
+                  ztabad(ji,jj)  = ztabad(ji,jj) + ptab_ad(jj,jk)
+                  ptab_ad(jj,jk) = 0.0_wp
+               END DO
+            END DO
+         ENDIF
+         IF( nbondj == 0 .OR. nbondj == -1 ) THEN
+            DO jl = 1, jprecj
+               t2ns_ad(:,jl,2)    = t2ns_ad(:,jl,2) + ztabad(:,ijhom+jl)
+               ztabad(:,ijhom+jl) = 0.0_wp
+            END DO
+         ENDIF
+         IF( nbondj == 0 .OR. nbondj == 1 ) THEN
+            DO jl = 1, jprecj
+               t2sn_ad(:,jl,2) = t2sn_ad(:,jl,2) + ztabad(:,jl)
+               ztabad(:,jl)    = 0.0_wp
+            END DO
+         ENDIF
+         !
+         !                              ! Migrations
+         imigr = jprecj * jpi
+         !
+         IF( nbondj == -1 ) THEN
+            CALL mppsend( 4, t2ns_ad(1,1,2), imigr, nono, ml_req1 )
+            CALL mpprecv( 3, t2sn_ad(1,1,1), imigr )
+            IF(l_isend) CALL mpi_wait( ml_req1, ml_stat, ml_err )
+         ELSEIF( nbondj == 0 ) THEN
+            CALL mppsend( 3, t2sn_ad(1,1,2), imigr, noso, ml_req1 )
+            CALL mppsend( 4, t2ns_ad(1,1,2), imigr, nono, ml_req2 )
+            CALL mpprecv( 3, t2sn_ad(1,1,1), imigr )
+            CALL mpprecv( 4, t2ns_ad(1,1,1), imigr )
+            IF( l_isend )   CALL mpi_wait( ml_req1, ml_stat, ml_err )
+            IF( l_isend )   CALL mpi_wait( ml_req2, ml_stat, ml_err )
+         ELSEIF( nbondj == 1 ) THEN
+            CALL mppsend( 3, t2sn_ad(1,1,2), imigr, noso, ml_req1 )
+            CALL mpprecv( 4, t2ns_ad(1,1,1), imigr)
+            IF( l_isend )   CALL mpi_wait( ml_req1, ml_stat, ml_err )
+         ENDIF
+         IF( nbondj /= 2 ) THEN         ! Read Dirichlet lateral conditions
+            ijhom = nlcj-nrecj
+            DO jl = 1, jprecj
+               ztabad(:,jprecj+jl) = ztabad(:,jprecj+jl) + t2ns_ad(:,jl,1)
+               t2ns_ad(:,jl,1) = ztabad(:,jprecj+jl)
+               t2sn_ad(:,jl,1) = ztabad(:,ijhom +jl)
+            END DO
+         ENDIF
+         !
+         ! 1. East and west directions
+         ! ---------------------------
+         !
+         !                              ! Write Dirichlet lateral conditions
+         iihom = nlci-jpreci
+         !
+         IF( nbondi == -1 .OR. nbondi == 0 ) THEN
+            DO jl = 1, jpreci
+               t2ew_ad(:,jl,2) = t2ew_ad(:,jl,2) + ztabad(iihom+jl,:)
+               ztabad(iihom+jl,:) = 0.0_wp
+            END DO
+         ENDIF
+         IF( nbondi == 0 .OR. nbondi == 1 ) THEN
+            DO jl = 1, jpreci
+               t2we_ad(:,jl,2) = t2we_ad(:,jl,2) + ztabad(jl,:)
+               ztabad(jl,:) = 0.0_wp
+            END DO
+         ENDIF
+         !                              ! Migrations
+         imigr=jpreci*jpj
+         !
+         IF( nbondi == -1 ) THEN
+            CALL mppsend( 2, t2ew_ad(1,1,2), imigr, noea, ml_req1 )
+            CALL mpprecv( 1, t2we_ad(1,1,1), imigr )
+            IF(l_isend)   CALL mpi_wait( ml_req1, ml_stat, ml_err )
+         ELSEIF( nbondi == 0 ) THEN
+            CALL mppsend( 1, t2we_ad(1,1,2), imigr, nowe, ml_req1 )
+            CALL mppsend( 2, t2ew_ad(1,1,2), imigr, noea, ml_req2 )
+            CALL mpprecv( 1, t2we_ad(1,1,1), imigr )
+            CALL mpprecv( 2, t2ew_ad(1,1,1), imigr )
+            IF(l_isend)   CALL mpi_wait( ml_req1, ml_stat, ml_err )
+            IF(l_isend)   CALL mpi_wait( ml_req2, ml_stat, ml_err )
+         ELSEIF( nbondi == 1 ) THEN
+            CALL mppsend( 1, t2we_ad(1,1,2), imigr, nowe, ml_req1 )
+            CALL mpprecv( 2, t2ew_ad(1,1,1), imigr )
+            IF(l_isend) CALL mpi_wait( ml_req1, ml_stat, ml_err )
+         ENDIF
+         !
+         IF( nbondi /= 2 ) THEN         ! Read Dirichlet lateral conditions
+            iihom = nlci-nreci
+            DO jl = 1, jpreci
+               ztabad(iihom +jl,:)  = ztabad(iihom +jl,:) + t2we_ad(:,jl,1)
+               t2we_ad(:,jl,1)      = 0.0_wp
+               ztabad(jpreci+jl,:)  = ztabad(jpreci+jl,:) + t2ew_ad(:,jl,1)
+               t2ew_ad(:,jl,1)      = 0.0_wp
+            END DO
+         ENDIF
+         !
+         IF( ktype == 1 ) THEN                               ! north/south boundaries
+            DO jj = ijpt0, ijpt1
+               DO ji = iipt0, iipt1
+                  ptab_ad(ji,jk) = ptab_ad(ji,jk) + ztabad(ji,jj)
+                  ztabad(ji,jj)  = 0.0_wp
+               END DO
+            END DO
+         ELSEIF( ktype == 2 ) THEN                           ! east/west boundaries
+            DO jj = ijpt0, ijpt1
+               DO ji = iipt0, iipt1
+                  ptab_ad(jj,jk) = ptab_ad(jj,jk) + ztabad(ji,jj)
+                  ztabad(ji,jj) = 0.0_wp
+               END DO
+            END DO
+         ENDIF
+         !
+      END DO
+      !
+   END SUBROUTINE mppobc_adj
+   
+   SUBROUTINE mpp_lbc_north_3d_adj( pt3d_ad, cd_type, psgn )
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_3d  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition 
+      !!              in mpp configuration in case of jpn1 > 1
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather 
+      !!              the 4 northern lines of the global domain on 1 processor
+      !!              and apply lbc north-fold on this sub array. Then we
+      !!              scatter the north fold array back to the processors.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pt3d_ad   ! 3D array on which the b.c. is applied
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
+      !                                                              !   = T ,  U , V , F or W  gridpoints
+      REAL(wp)                        , INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
+      !!                                                             ! =  1. , the sign is kept
+      INTEGER ::   ji, jj, jr
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ijpj, ijpjm1, ij, iproc
+      REAL(wp), DIMENSION(jpiglo,4,jpk)      ::   ztabad
+      REAL(wp), DIMENSION(jpi   ,4,jpk)      ::   znorthlocad
+      REAL(wp), DIMENSION(jpi   ,4,jpk,jpni) ::   znorthgloioad
+      !!----------------------------------------------------------------------
+      !   
+      ijpj   = 4
+      ijpjm1 = 3
+      ztabad(:,:,:) = 0.0_wp  ;  znorthlocad (:,:,:)= 0.0_wp  ;  znorthgloioad(:,:,:,:) = 0.0_wp
+      !
+      DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt3d
+         ij = jj - nlcj + ijpj
+         DO ji= 1, nlci
+            ztabad(ji+nimpp-1,ij,:) = ztabad(ji+nimpp-1,ij,:) + pt3d_ad(ji,jj,:)
+            pt3d_ad(ji,jj,:) = 0.0_wp
+         END DO
+      END DO
+      !
+      CALL lbc_nfd_adj( ztabad, cd_type, psgn )   ! North fold boundary condition
+      !
+      !                                     ! recover the global north array
+      DO jr = 1, ndim_rank_north
+         iproc = nrank_north(jr) + 1
+         ildi  = nldit (iproc)
+         ilei  = nleit (iproc)
+         iilb  = nimppt(iproc)
+         DO jj = 1, 4
+            DO ji = ildi, ilei
+               znorthgloioad(ji,jj,:,jr) = znorthgloioad(ji,jj,:,jr) + ztabad(ji+iilb-1,jj,:)
+               ztabad(ji+iilb-1,jj,:)    = 0.0_wp
+            END DO
+         END DO
+      END DO
+      !                                     ! Build in procs of ncomm_north the znorthgloio
+      itaille = jpi * jpk * ijpj
+      ! specific treatment of adjoint of mpi_allgather
+      znorthgloioad = mpp_sum_nfd(znorthgloioad,jpi,4,jpk,jpni,ncomm_north) 
+      jr=  ndim_rank_north-jpnij+nproc+1
+      znorthlocad(:,:,:) = znorthgloioad(:,:,:,jr)
+
+      DO jj = nlcj - ijpj +1, nlcj          ! put in znorthloc the last 4 jlines of pt3d
+         ij = jj - nlcj + ijpj
+         pt3d_ad(:,jj,:) = pt3d_ad(:,jj,:) + znorthlocad(:,ij,:)
+         znorthlocad(:,ij,:) = 0.0_wp
+      END DO
+      !
+      !
+   END SUBROUTINE mpp_lbc_north_3d_adj
+
+
+   SUBROUTINE mpp_lbc_north_2d_adj( pt2d_ad, cd_type, psgn)
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_2d  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition 
+      !!              in mpp configuration in case of jpn1 > 1 (for 2d array )
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather 
+      !!              the 4 northern lines of the global domain on 1 processor
+      !!              and apply lbc north-fold on this sub array. Then we
+      !!              scatter the north fold array back to the processors.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d_ad   ! 3D array on which the b.c. is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
+      !                                                          !   = T ,  U , V , F or W  gridpoints
+      REAL(wp)                    , INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
+      !!                                                             ! =  1. , the sign is kept
+      INTEGER ::   ji, jj, jr
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ijpj, ijpjm1, ij, iproc
+      REAL(wp), DIMENSION(jpiglo,4)      ::   ztabad
+      REAL(wp), DIMENSION(jpi   ,4)      ::   znorthlocad
+      REAL(wp), DIMENSION(jpi   ,4,jpni) ::   znorthgloioad
+      !!----------------------------------------------------------------------
+      !
+      ijpj   = 4
+      ijpjm1 = 3
+      ztabad = 0.0_wp  ;  znorthlocad = 0.0_wp  ;  znorthgloioad = 0.0_wp
+      !
+      DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
+         ij = jj - nlcj + ijpj
+         DO ji = 1, nlci
+            ztabad(ji+nimpp-1,ij) = ztabad(ji+nimpp-1,ij) + pt2d_ad(ji,jj)
+            pt2d_ad(ji,jj)        = 0.0_wp
+         END DO
+      END DO
+      !
+      CALL lbc_nfd_adj( ztabad, cd_type, psgn )   ! North fold boundary condition
+      !
+      DO jr = 1, ndim_rank_north            ! recover the global north array
+         iproc = nrank_north(jr) + 1
+         ildi=nldit (iproc)
+         ilei=nleit (iproc)
+         iilb=nimppt(iproc)
+         DO jj = 1, 4
+            DO ji = ildi, ilei
+               znorthgloioad(ji,jj,jr) = znorthgloioad(ji,jj,jr) + ztabad(ji+iilb-1,jj)
+               ztabad(ji+iilb-1,jj) = 0.0_wp
+            END DO
+         END DO
+      END DO
+      !
+      !                                     ! Build in procs of ncomm_north the znorthgloio
+      itaille = jpi * ijpj
+      ! specific treatment of adjoint of mpi_allgather
+      znorthgloioad = mpp_sum_nfd(znorthgloioad,jpi,4,jpni,ncomm_north) 
+      jr=  ndim_rank_north-jpnij+nproc+1
+      znorthlocad(:,:) = znorthgloioad(:,:,jr)
+
+      DO jj = nlcj-ijpj+1, nlcj             ! put in znorthloc the last 4 jlines of pt2d
+         ij = jj - nlcj + ijpj
+         pt2d_ad(:,jj) = pt2d_ad(:,jj) + znorthlocad(:,ij)
+         znorthlocad(:,ij) = 0.0_wp
+      END DO
+      !
+   END SUBROUTINE mpp_lbc_north_2d_adj
+
+
+   SUBROUTINE mpp_lbc_north_e_adj( pt2d_ad, cd_type, psgn)
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_2d  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition 
+      !!              in mpp configuration in case of jpn1 > 1 and for 2d 
+      !!              array with outer extra halo
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather 
+      !!              the 4+2*jpr2dj northern lines of the global domain on 1 
+      !!              processor and apply lbc north-fold on this sub array. 
+      !!              Then we scatter the north fold array back to the processors.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj), INTENT(inout) ::   pt2d_ad  ! 2D array with extra halo
+      CHARACTER(len=1)                                            , INTENT(in   ) ::   cd_type  ! nature of pt3d grid-points
+      !                                                                                         !   = T ,  U , V , F or W -points
+      REAL(wp)                                                    , INTENT(in   ) ::   psgn     ! = -1. the sign change across the  
+      !!                                                                                        ! north fold, =  1. otherwise
+      INTEGER ::   ji, jj, jr
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ijpj, ij, iproc
+      REAL(wp), DIMENSION(jpiglo,4+2*jpr2dj)      ::   ztabad
+      REAL(wp), DIMENSION(jpi   ,4+2*jpr2dj)      ::   znorthlocad
+      REAL(wp), DIMENSION(jpi   ,4+2*jpr2dj,jpni) ::   znorthgloioad
+      !!----------------------------------------------------------------------
+      !
+      ijpj=4
+      ztabad = 0.0_wp  ;  znorthlocad = 0.0_wp  ;  znorthgloioad = 0.0_wp
+
+      ij = jpr2dj
+      !! Scatter back to pt2d
+      DO jj = nlcj - ijpj + 1 , nlcj +jpr2dj
+      ij  = ij +1 
+         DO ji= 1, nlci
+            ztabad(ji+nimpp-1,ij) = ztabad(ji+nimpp-1,ij) + pt2d_ad(ji,jj)
+            pt2d_ad(ji,jj)        = 0.0_wp
+         END DO
+      END DO
+      ! 2. North-Fold boundary conditions
+      ! ----------------------------------
+      CALL lbc_nfd_adj( ztabad(:,:), cd_type, psgn, jpr2dj)!, pr2dj = jpr2dj )
+      !
+      DO jr = 1, ndim_rank_north            ! recover the global north array
+         iproc = nrank_north(jr) + 1
+         ildi = nldit (iproc)
+         ilei = nleit (iproc)
+         iilb = nimppt(iproc)
+         DO jj = 1, ijpj+2*jpr2dj
+            DO ji = ildi, ilei
+               znorthgloioad(ji,jj,jr) = znorthgloioad(ji,jj,jr) + ztabad(ji+iilb-1,jj)
+               ztabad(ji+iilb-1,jj)    = 0.0_wp
+            END DO
+         END DO
+      END DO
+      !
+      itaille = jpi * ( ijpj + 2 * jpr2dj )
+      ! specific treatment of adjoint of mpi_allgather
+      znorthgloioad = mpp_sum_nfd(znorthgloioad,jpi,4,jpni,ncomm_north) 
+      jr=  ndim_rank_north-jpnij+nproc+1
+      znorthlocad(:,:) = znorthgloioad(:,:,jr)
+
+      ij=0
+      ! put in znorthloc the last 4 jlines of pt2d
+      DO jj = nlcj - ijpj + 1 - jpr2dj, nlcj +jpr2dj
+         ij = ij + 1
+         DO ji = 1, jpi
+            pt2d_ad(ji,jj)     = pt2d_ad(ji,jj) + znorthlocad(ji,ij)
+            znorthlocad(ji,ij) = 0.0_wp
+         END DO
+      END DO
+      !
+   END SUBROUTINE mpp_lbc_north_e_adj
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case:            Dummy module        share memory computing
+   !!----------------------------------------------------------------------
+   INTERFACE mppobc_adj
+      MODULE PROCEDURE mppobc_adj_1d, mppobc_adj_2d, mppobc_adj_3d, mppobc_adj_4d
+   END INTERFACE
+
+
+   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .FALSE.      !: mpp flag
+   INTEGER :: ncomm_ice
+
+CONTAINS
+
+   SUBROUTINE mppobc_adj_1d( parr, kd1, kd2, kl, kk, ktype, kij )
+      INTEGER  ::   kd1, kd2, kl , kk, ktype, kij
+      REAL, DIMENSION(:) ::   parr           ! variable array
+      WRITE(*,*) 'mppobc: You should not have seen this print! error?', parr(1), kd1, kd2, kl, kk, ktype, kij
+   END SUBROUTINE mppobc_adj_1d
+
+   SUBROUTINE mppobc_adj_2d( parr, kd1, kd2, kl, kk, ktype, kij )
+      INTEGER  ::   kd1, kd2, kl , kk, ktype, kij
+      REAL, DIMENSION(:,:) ::   parr           ! variable array
+      WRITE(*,*) 'mppobc: You should not have seen this print! error?', parr(1,1), kd1, kd2, kl, kk, ktype, kij
+   END SUBROUTINE mppobc_adj_2d
+
+   SUBROUTINE mppobc_adj_3d( parr, kd1, kd2, kl, kk, ktype, kij )
+      INTEGER  ::   kd1, kd2, kl , kk, ktype, kij
+      REAL, DIMENSION(:,:,:) ::   parr           ! variable array
+      WRITE(*,*) 'mppobc: You should not have seen this print! error?', parr(1,1,1), kd1, kd2, kl, kk, ktype, kij
+   END SUBROUTINE mppobc_adj_3d
+
+   SUBROUTINE mppobc_adj_4d( parr, kd1, kd2, kl, kk, ktype, kij )
+      INTEGER  ::   kd1, kd2, kl , kk, ktype, kij
+      REAL, DIMENSION(:,:,:,:) ::   parr           ! variable array
+      WRITE(*,*) 'mppobc: You should not have seen this print! error?', parr(1,1,1,1), kd1, kd2, kl, kk, ktype, kij
+   END SUBROUTINE mppobc_adj_4d
+
+
+#endif
+   !!----------------------------------------------------------------------
+END MODULE lib_mpp_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/model_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/model_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/model_tam.F90	(revision 2578)
@@ -0,0 +1,9 @@
+PROGRAM model_tam
+#if defined key_tam
+   USE opa_tam
+   IMPLICIT NONE
+   CALL opa_tam_model
+#else
+   WRITE(*,*)'Compile with -Dkey_tam'
+#endif
+END PROGRAM model_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/mpp_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/mpp_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/mpp_tam.F90	(revision 2578)
@@ -0,0 +1,281 @@
+#if defined key_mpp_mpi
+#if defined key_sp
+#define mpivar mpi_real
+#else
+#define mpivar mpi_double_precision
+#endif
+#endif
+MODULE mpp_tam
+   !!======================================================================
+   !!                       ***  MODULE mpp_tam  ***
+   !! NEMOTAM: Various MPP support routines
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !! mpp_sum_reals       : Sum an array of reals from all processors
+   !! mpp_global_or,      : Do an op operation
+   !! mpp_global_max_real : Som
+   !!----------------------------------------------------------------------
+   !! * Modules used   
+   USE par_kind, ONLY : &   ! Precision variables
+      & wp
+   USE par_oce, ONLY : &    ! Ocean parameters
+      & jpnij
+   USE dom_oce, ONLY : &    ! Ocean space and time domain variables
+      & nproc, &
+      & jpiglo, &
+      & jpjglo, &
+      & jpi, &
+      & jpj, &
+      & nldi, &
+      & nldj, &
+      & nlei, &
+      & nlej, &
+      & mig, &
+      & mjg
+#if defined key_mpp_mpi
+   USE lib_mpp, ONLY : &    ! MPP library
+      & mpi_comm_opa
+#endif
+   
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+
+   PUBLIC &
+      & mpp_sum_reals,      &
+      & mpp_global_or,      &
+      & mpp_global_max_real, &
+      & mpp_global_max_real2
+
+CONTAINS
+
+   SUBROUTINE mpp_sum_reals( pvalin, pvalout, kn )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE mpp_sum_integers ***
+      !!          
+      !! ** Purpose : Sum all elements of a real array
+      !!
+      !! ** Method  : MPI all reduce.
+      !!
+      !! ** Action  : This does only work for MPI. 
+      !!              It does not work for SHMEM.
+      !!
+      !! References : http://www.mpi-forum.org
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER :: &
+         & kn 
+      REAL(wp), DIMENSION(kn), INTENT(IN) :: &
+         & pvalin
+      REAL(wp), DIMENSION(kn), INTENT(OUT) :: &
+         & pvalout
+
+#if defined key_mpp_mpi
+      !! * Local declarations
+      INTEGER :: &
+         & ierr
+#     include <mpif.h>
+
+      !-----------------------------------------------------------------------
+      ! Call the MPI library to find the sum across processors
+      !-----------------------------------------------------------------------
+      CALL mpi_allreduce( pvalin, pvalout, kn, mpivar, mpi_sum, &
+         &                mpi_comm_opa, ierr )
+#elif defined key_mpp_shmem
+#error "Only MPI support for MPP in NEMOVAR"
+#else
+
+      !-----------------------------------------------------------------------
+      ! For no-MPP just return input values
+      !-----------------------------------------------------------------------
+      pvalout(:) = pvalin(:)
+#endif
+   END SUBROUTINE mpp_sum_reals
+
+   SUBROUTINE mpp_global_or( ldval )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE mpp_global_or ***
+      !!          
+      !! ** Purpose : Apply the "or" 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
+      LOGICAL, DIMENSION(jpiglo,jpjglo), INTENT(INOUT) :: &
+         & ldval
+      !! * Local declarations
+      INTEGER :: &
+         & ierr
+#if defined key_mpp_mpi
+#include <mpif.h>
+      LOGICAL, DIMENSION(:,:), ALLOCATABLE :: &
+         & llcp
+
+      ! Copy data for input to MPI
+
+      ALLOCATE( &
+         & llcp(jpiglo,jpjglo) &
+         & )
+      llcp(:,:) = ldval(:,:)
+
+      ! Call the MPI library to find the coast lines globally
+
+      CALL mpi_allreduce( llcp, ldval, jpiglo*jpjglo, mpi_logical, &
+         &                mpi_lor, mpi_comm_opa, ierr )
+
+      DEALLOCATE( &
+         & llcp &
+         & )
+
+#elif defined key_mpp_shmem
+#error "Only MPI support for MPP in NEMOVAR"
+#endif
+      
+   END SUBROUTINE mpp_global_or
+
+   SUBROUTINE mpp_global_max_real( zin, zout )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE mpp_global_max_real ***
+      !!          
+      !! ** 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(:,:) = 0.0
+      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_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_2_2/NEMOTAM/OPATAM_SRC/mppsumtam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/mppsumtam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/mppsumtam.F90	(revision 2578)
@@ -0,0 +1,491 @@
+MODULE mppsumtam
+   !!======================================================================
+   !!                       ***  MODULE mppsumtam  ***
+   !! NEMOTAM: Summation of arrays across processors
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   mpp_sum_inter  : Interface for depending on nmppsum
+   !!   mpp_sum_simple : Simple sum
+   !!   loc_sum_inter  : Interface for depending on nmppsum (local version)
+   !!   loc_sum_simple : Simple sum (local version)
+   !!   loc_sum_indep  : Order independent MPP reproducible sum
+   !!----------------------------------------------------------------------
+   !! * Modules used   
+   USE par_kind, ONLY : &   ! Precision variables
+      & wp
+   USE dom_oce, ONLY : &    ! Ocean space and time domain variables
+      & nproc
+   USE par_oce, ONLY : &    ! Ocean parameters
+      & jpnij
+#if defined key_mpp_mpi
+   USE lib_mpp, ONLY : &    ! MPP library
+      & mpi_comm_opa,  &
+      & mpp_sum
+#endif
+   USE lib_mpp
+   USE mpp_tam
+   USE mppsum
+   USE in_out_manager
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+
+   PUBLIC &
+      & mpp_sum_inter,  & ! Interface for depending on nmppsum
+      & mpp_sum_simple, & ! Simple sum
+      & loc_sum_inter,  & ! Interface for depending on nmppsum
+      & loc_sum_simple, & ! Simple sum
+      & loc_sum_indep,  & ! Order independent local reproducible sum
+      & nmppsum           ! Summation control
+
+   PUBLIC mpp_sum_nfd
+
+   INTERFACE mpp_sum_nfd
+      MODULE PROCEDURE mpp_sum_nfd_3d,mpp_sum_nfd_4d 
+   END INTERFACE
+
+   !! * Module variables
+   INTEGER :: nmppsum = 2 ! Choice of MPP sum for 
+                          ! (1 = simple)
+                          ! (2 = order independent)
+   
+CONTAINS
+
+   FUNCTION mpp_sum_inter( pval, kn )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE mpp_sum_inter ***
+      !!          
+      !! ** Purpose : Summation of arrays across processors
+      !!
+      !! ** Method  : Call either mpp_sum_simple or mpp_sum_indep depending on
+      !!              nmppsum
+      !!
+      !! ** Action  : This does only work for MPI. 
+      !!              It does not work for SHMEM.
+      !!
+      !! References : http://www.mpi-forum.org
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) mpp_sum_inter
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kn
+      REAL(wp), DIMENSION(kn), INTENT(IN) :: &
+         & pval
+      !! * Local declarations
+     
+      IF ( nmppsum == 1 ) THEN
+         
+         mpp_sum_inter = mpp_sum_simple( pval, kn )
+         
+      ELSEIF ( nmppsum == 2 ) THEN
+
+         mpp_sum_inter = mpp_sum_indep( pval, kn )
+
+      ELSE
+
+         CALL ctl_stop( ' mpp_sum: Invalid nmppsum ' )
+
+      ENDIF
+
+   END FUNCTION mpp_sum_inter
+
+   FUNCTION mpp_sum_simple( pval, kn )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE mpp_sum_simple ***
+      !!          
+      !! ** Purpose : Summation of arrays across processors
+      !!
+      !! ** Method  : This routine is the naive implementation using
+      !!              mpi_allreduce for the sum of local data 
+      !!
+      !! ** Action  : This does only work for MPI. 
+      !!              It does not work for SHMEM.
+      !!
+      !! References : http://www.mpi-forum.org
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) mpp_sum_simple
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kn
+      REAL(wp), DIMENSION(kn), INTENT(IN) :: &
+         & pval
+      !! * Local declarations
+      REAL(wp) :: &
+         & zres
+      INTEGER :: &
+         & ierr
+      INTEGER :: &
+         & ji
+
+      ! Compute local sum   
+      zres = SUM( pval(1:kn) )    
+      ! Global sum
+
+      CALL mpp_sum( zres )
+
+      mpp_sum_simple = zres
+
+   END FUNCTION mpp_sum_simple
+
+   FUNCTION loc_sum_inter( pval, kn )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE loc_sum_inter ***
+      !!          
+      !! ** Purpose : Summation of arrays across processors
+      !!
+      !! ** Method  : Call either loc_sum_simple or loc_sum_indep depending on
+      !!              nmppsum
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-09  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) loc_sum_inter
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kn
+      REAL(wp), DIMENSION(kn), INTENT(IN) :: &
+         & pval
+      !! * Local declarations
+      
+      IF ( nmppsum == 1 ) THEN
+         
+         loc_sum_inter = loc_sum_simple( pval, kn )
+         
+      ELSEIF ( nmppsum == 2 ) THEN
+
+         loc_sum_inter = loc_sum_indep( pval, kn )
+
+      ELSE
+
+         CALL ctl_stop( ' loc_sum: Invalid nmppsum = ' )
+
+      ENDIF
+
+   END FUNCTION loc_sum_inter
+
+   FUNCTION loc_sum_simple( pval, kn )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE loc_sum_simple ***
+      !!          
+      !! ** Purpose : Summation of arrays across processors
+      !!
+      !! ** Method  : This routine is the naive implementation for the sum 
+      !!              of local data 
+      !!
+      !! ** Action  : 
+      !!
+      !! References : 
+      !!
+      !! History :
+      !!        !  07-09  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) loc_sum_simple
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kn
+      REAL(wp), DIMENSION(kn), INTENT(IN) :: &
+         & pval
+      !! * Local declarations
+      REAL(wp) :: &
+         & zloc
+      INTEGER :: &
+         & ierr
+      INTEGER :: &
+         & ji
+
+      ! Compute local sum
+
+      zloc = SUM( pval(1:kn) )
+      
+      loc_sum_simple = zloc
+
+   END FUNCTION loc_sum_simple
+
+   FUNCTION loc_sum_indep( pval, kn )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE loc_sum_indep ***
+      !!          
+      !! ** Purpose : Sum all elements in the pval array in
+      !!              an accurate order-independent way.
+      !!
+      !! ** Method  : The code iterates the compensated summation until the 
+      !!              result is guaranteed to be within 4*eps of the true sum.
+      !!              It then rounds the result to the nearest floating-point 
+      !!              number whose last three bits are zero, thereby 
+      !!              guaranteeing an order-independent result.
+      !!
+      !!              This version is used for local arrays. It is identical
+      !!              to the MPP version for clarity.
+      !!
+      !! ** Action  : 
+      !!
+      !! References : M. Fisher (ECMWF): IFS code + personal communication
+      !!              The algorithm is based on Ogita et al. (2005) 
+      !!              SIAM J. Sci. Computing, Vol.26, No.6, pp1955-1988. 
+      !!              This is based in turn on an algorithm
+      !!              by Knuth (1969, seminumerical algorithms).
+      !!
+      !! History :
+      !!        !  07-09  (K. Mogensen)  Original code heavily based on IFS.
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) loc_sum_indep
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kn
+      REAL(wp), DIMENSION(kn), INTENT(IN) :: &
+         & pval
+      !! * Local declarations
+      REAL(wp), DIMENSION(3) ::&
+         & zbuffl
+      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
+         & zpsums, &
+         & zperrs, &
+         & zpcors, &
+         & zbuffg, &
+         & zp
+      REAL(wp) :: &
+         & zcorr,   &
+         & zerr,    &
+         & zolderr, &
+         & zbeta,   &
+         & zres
+      INTEGER :: &
+         & jj
+
+      ! Check that the the algorithm can work 
+      
+      IF ( ( REAL( 2 * kn ) * EPSILON( zres ) ) >= 1.0 ) THEN
+
+         CALL ctl_stop( 'kn is too large to guarantee error bounds' )
+
+      ENDIF
+      
+      ALLOCATE( &
+         & zp(MAX(kn,1)),                & 
+         & zbuffg(1*SIZE(zbuffl)), &
+         & zpsums(1),              &
+         & zperrs(1),              &
+         & zpcors(1)               &
+         & )
+
+      zolderr = HUGE(zerr)
+
+      ! Copy the input array. This avoids some tricky indexing, at the
+      ! expense of some inefficency.
+
+      IF ( kn > 0 ) THEN
+
+         zp(:) = pval(:)
+
+      ELSE
+
+         zp(1) = 0.0_wp
+
+      ENDIF
+
+      k_loop: DO
+
+         ! Transform local arrays
+         
+         IF ( kn > 0 ) THEN
+
+            CALL comp_sum ( zp, kn, zcorr, zerr )
+
+         ENDIF
+
+         ! Gather partial sums and error bounds to all processors
+
+         zbuffl(1) = zp(MAX(kn,1))
+         
+         IF ( kn > 0 ) THEN
+
+            zbuffl(2) = zerr
+            zbuffl(3) = zcorr
+
+         ELSE
+            
+            zbuffl(2) = 0.0_wp
+            zbuffl(3) = 0.0_wp
+
+         ENDIF
+
+         zpsums(1) = zbuffl(1)
+         zperrs(1) = zbuffl(2)
+         zpcors(1) = zbuffl(3)
+
+         ! Transform partial sums
+
+         CALL comp_sum( zpsums, 1, zcorr, zerr )
+         zerr  = zerr  + SUM(zperrs)
+         zcorr = zcorr + SUM(zpcors)
+         
+         ! Calculate final result
+         
+         zres = zpsums(1) + zcorr
+
+         ! Calculate error bound. This is corollary 4.7 from Ogita et al. 
+         ! (2005)
+         
+         zbeta = zerr *( REAL( 2*kn, wp ) * EPSILON(zres) ) &
+            &  /(1.0_wp - REAL( 2*kn, wp ) * EPSILON(zres) )
+
+         zerr = EPSILON(zres) * ABS(zres) &
+            & +(zbeta + ( 2.0_wp * EPSILON(zres) * EPSILON(zres) * ABS(zres) &
+            &            +3.0_wp * TINY(zres) ) )
+
+         ! Update the last element of the local array
+
+         zp(MAX(kn,1)) = zpsums(nproc+1)
+
+         ! Exit if the global error is small enough
+
+         IF ( zerr < 4.0_wp * SPACING(zres) ) EXIT k_loop
+         
+         ! Take appropriate action if ZRES cannot be sufficiently refined.
+         
+         IF (zerr >= zolderr) THEN
+
+            CALL ctl_stop( 'Failed to refine sum', &
+               &           'Warning: Possiblity of non-reproducible results' )
+
+         ENDIF
+
+         zolderr = zerr
+         
+      ENDDO k_loop
+
+      ! At this stage, we have guaranteed that ZRES less than 4*EPS
+      ! away from the exact sum. There are only four floating point
+      ! numbers in this range. So, if we find the nearest number that
+      ! has its last three bits zero, then we have a reproducible result.
+
+      loc_sum_indep = fround(zres)
+
+      DEALLOCATE( &
+         & zpcors, &
+         & zperrs, &
+         & zpsums, &
+         & zbuffg, &
+         & zp      &
+         & )
+
+   END FUNCTION loc_sum_indep
+
+#if defined key_mpp_mpi
+   FUNCTION mpp_sum_nfd_4d( pval, kn1, kn2, kn3, kn4, kcom )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE mpp_sum_nfd_4d ***
+      !!          
+      !! ** Purpose : Summation of arrays across processors (of kcom group)
+      !!
+      !! ** Method  : Pack 4d array to vector, sum vector and then unpack
+      !!
+      !! ** Action  : This does only work for MPI. 
+      !!              It does not work for SHMEM.
+      !!
+      !! History :
+      !!        !  10-11  (F. Vigilant)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp), DIMENSION(kn1, kn2, kn3, kn4) :: mpp_sum_nfd_4d
+      !! * Arguments
+      INTEGER, INTENT(IN) :: kn1, kn2, kn3, kn4
+      REAL(wp), DIMENSION(kn1, kn2, kn3, kn4), INTENT(IN) :: pval
+      INTEGER , INTENT( in ), OPTIONAL        :: kcom
+      !! * Local declarations
+      REAL(wp), DIMENSION(:), ALLOCATABLE     :: zvec
+      LOGICAL, DIMENSION(kn1, kn2, kn3, kn4)  :: zmask
+      REAL(wp), DIMENSION(kn1, kn2, kn3, kn4) :: zfd
+      INTEGER :: zdim
+      
+      zdim = kn1 * kn2 * kn3 * kn4
+      ALLOCATE( zvec(zdim) )
+      
+      zvec = PACK( pval(1:kn1,1:kn2,1:kn3,1:kn4),.TRUE.)
+
+      CALL mpp_sum( zvec, zdim, kcom )
+
+      zmask(:,:,:,:) = .TRUE.
+      mpp_sum_nfd_4d = UNPACK( zvec, zmask, zfd )
+      
+   END FUNCTION mpp_sum_nfd_4d
+
+   FUNCTION mpp_sum_nfd_3d( pval, kn1, kn2, kn3, kcom )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE mpp_sum_nfd_3d ***
+      !!          
+      !! ** Purpose : Summation of arrays across processors (of kcom group)
+      !!
+      !! ** Method  : Pack 3d array to vector, sum vector and then unpack
+      !!
+      !! ** Action  : This does only work for MPI. 
+      !!              It does not work for SHMEM.
+      !!
+      !! History :
+      !!        !  10-11  (F. Vigilant)  Original code
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp), DIMENSION(kn1, kn2, kn3) :: mpp_sum_nfd_3d
+      !! * Arguments
+      INTEGER, INTENT(IN) ::kn1, kn2, kn3
+      REAL(wp), DIMENSION(kn1, kn2, kn3), INTENT(IN) :: pval
+      INTEGER , INTENT( in ), OPTIONAL        :: kcom
+      !! * Local declarations
+      REAL(wp), DIMENSION(:), ALLOCATABLE     :: zvec
+      LOGICAL, DIMENSION(kn1, kn2, kn3)  :: zmask
+      REAL(wp), DIMENSION(kn1, kn2, kn3) :: zfd
+      INTEGER :: zdim
+      
+      zdim = kn1 * kn2 * kn3
+      ALLOCATE( zvec(zdim) )
+      
+      zvec = PACK( pval(1:kn1,1:kn2,1:kn3),.TRUE.)
+
+      CALL mpp_sum( zvec, zdim, kcom )
+
+      zmask(:,:,:) = .TRUE.
+      mpp_sum_nfd_3d = UNPACK( zvec, zmask, zfd )
+      
+   END FUNCTION mpp_sum_nfd_3d
+#else
+   FUNCTION mpp_sum_nfd_4d( pval, kn1, kn2, kn3, kn4, kcom )
+      !! * Function return
+      REAL(wp), DIMENSION(kn1, kn2, kn3, kn4) :: mpp_sum_nfd_4d
+      !! * Arguments
+      INTEGER, INTENT(IN) :: kn1, kn2, kn3, kn4
+      REAL(wp), DIMENSION(kn1, kn2, kn3, kn4), INTENT(IN) :: pval
+      INTEGER , INTENT( in ), OPTIONAL        :: kcom
+      mpp_sum_nfd_4d = 0.0_wp
+      WRITE(*,*) 'mpp_sum_nfd_4d: You should not have seen this print! error?'
+   END FUNCTION mpp_sum_nfd_4d
+   FUNCTION mpp_sum_nfd_3d( pval, kn1, kn2, kn3, kcom )
+      !! * Function return
+      REAL(wp), DIMENSION(kn1, kn2, kn3) :: mpp_sum_nfd_3d
+      !! * Arguments
+      INTEGER, INTENT(IN) :: kn1, kn2, kn3
+      REAL(wp), DIMENSION(kn1, kn2, kn3), INTENT(IN) :: pval
+      INTEGER , INTENT( in ), OPTIONAL        :: kcom
+      mpp_sum_nfd_3d = 0.0_wp
+      WRITE(*,*) 'mpp_sum_nfd_3d: You should not have seen this print! error?'
+   END FUNCTION mpp_sum_nfd_3d
+#endif
+
+END MODULE mppsumtam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/mt19937ar.f90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/mt19937ar.f90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/mt19937ar.f90	(revision 2578)
@@ -0,0 +1,232 @@
+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(ks,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 :: iy,jk
+      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_2_2/NEMOTAM/OPATAM_SRC/oce_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/oce_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/oce_tam.F90	(revision 2578)
@@ -0,0 +1,1010 @@
+MODULE oce_tam
+   !!----------------------------------------------------------------------
+   !!    This software is governed by the CeCILL licence (Version 2)
+   !!----------------------------------------------------------------------
+   !!======================================================================
+   !!                       ***  MODULE oce_tam ***
+   !! NEMOVAR Tangent linear and Adjoint Model variables :
+   !! 
+   !!    Allocate tangent linear and adjoint fields for the inner loop
+   !!
+   !!======================================================================
+   !! History of the direct module:
+   !!   8.5  !  02-11  (G. Madec)  F90: Free form and module
+   !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !! History of the TAM module:
+   !!   9.0  !  07-07 (K. Mogensen) Initial version
+   !!   9.0  !  08-03 (A. Vidard) Add variables
+   !!   9.0  !  09-03 (A. Weaver) Nemo v3 compatible, merge tl_init/ad_init
+   !!----------------------------------------------------------------------
+   !!   oce_tam_init : Allocate and initialize the TAM fields
+   !!----------------------------------------------------------------------
+   !! * Modules used   
+   USE par_kind, ONLY : &  ! Precision variables
+      & wp
+   USE par_oce, ONLY : &   ! Ocean space and time domain variables
+      & jpi, &
+      & jpj, &
+      & jpk
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+   PUBLIC &
+      & oce_tam_init,       & !: Initialize the TAM fields
+      & oce_tam_deallocate, &
+                    !:
+      & ub_tl,    & !: Tangent linear of before u-component velocity
+      & un_tl,    & !: Tangent linear of now u-component velocity
+      & ua_tl,    & !: Tangent linear of after u-component velocity
+      & vb_tl,    & !: Tangent linear of before v-component velocity
+      & vn_tl,    & !: Tangent linear of now v-component velocity
+      & va_tl,    & !: Tangent linear of after v-component velocity
+      & wn_tl,    & !: Tangent linear of now w-component velocity
+      & rotb_tl,  & !: Tangent linear of now relative vorticity
+      & rotn_tl,  & !: Tangent linear of now relative vorticity
+      & hdivb_tl, & !: Tangent linear of before horizontal divergence
+      & hdivn_tl, & !: Tangent linear of now horizontal divergence
+      & tb_tl,    & !: Tangent linear of before of temperature 
+      & tn_tl,    & !: Tangent linear of now temperature 
+      & ta_tl,    & !: Tangent linear of after temperature 
+      & sb_tl,    & !: Tangent linear of before salinity
+      & sn_tl,    & !: Tangent linear of now salinity
+      & sa_tl,    & !: Tangent linear of after salinity
+      & rhd_tl,   & !: Tangent linear of Now in situ density anomaly  
+      & rhop_tl,  & !: Tangent linear of potential volumic mass (kg/m3)
+      & rn2_tl,   & !: Tangent linear of Now Brunt-Vaisala frequency
+                    !:
+      & spgu_tl,  & !: Tangent linear of horizontal surface pressure gradient
+      & spgv_tl,  & !: 
+#if defined key_dynspg_rl
+      & bsfb_tl,  & !: Tangent linear of before barotropic streamfunction
+      & bsfn_tl,  & !: Tangent linear of now barotropic streamfunction
+      & bsfd_tl,  & !: Tangent linear of now trend of barotropic streamfunction
+#else
+      & sshb_tl,  & !: Tangent linear of before sea surface height
+      & sshn_tl,  & !: Tangent linear of now sea surface height
+      & ssha_tl,  & !: Tangent linear of after sea surface height
+      & sshu_tl,  & !: Tangent linear of sea surface height at u-point
+      & sshv_tl,  & !: Tangent linear of sea surface height at v-point
+      & sshbb_tl, & !: Tangent linear of before before sea surface height
+#endif
+      & gtu_tl,   & !: Tangent Linear of
+      & gsu_tl,   & !:
+      & gru_tl,   & !: t-, s- and rd horizontal gradient at u- and 
+      & gtv_tl,   & !:   v-points at bottom ocean level
+      & gsv_tl,   & !: 
+      & grv_tl,   & !:
+                    !:
+      & ub_ad,    & !: Adjoint of before u-component velocity
+      & un_ad,    & !: Adjoint of now u-component velocity
+      & ua_ad,    & !: Adjoint of after u-component velocity
+      & vb_ad,    & !: Adjoint of before v-component velocity
+      & vn_ad,    & !: Adjoint of now v-component velocity
+      & va_ad,    & !: Adjoint of after v-component velocity
+      & wn_ad,    & !: Adjoint of now w-component velocity
+      & rotb_ad,  & !: Adjoint of before relative vorticity
+      & rotn_ad,  & !: Adjoint of now relative vorticity
+      & hdivb_ad, & !: Adjoint of before horizontal divergence
+      & hdivn_ad, & !: Adjoint of now horizontal divergence
+      & tb_ad,    & !: Adjoint of before temperature 
+      & tn_ad,    & !: Adjoint of now temperature 
+      & ta_ad,    & !: Adjoint of after temperature 
+      & sb_ad,    & !: Adjoint of before salinity
+      & sn_ad,    & !: Adjoint of now salinity
+      & sa_ad,    & !: Adjoint of after salinity
+      & rhd_ad,   & !: Adjoint of now in situ density anomaly  
+      & rhop_ad,  & !: Adjoint of potential volumic mass (kg/m3)
+      & rn2_ad,   & !: Adjoint of now Brunt-Vaisala frequency
+      & spgu_ad,  & !: Adjoint linear of horizontal surface pressure gradient
+      & spgv_ad,  & !: 
+#if defined key_dynspg_rl
+      & bsfb_ad,  & !: Adjoint of before barotropic streamfunction
+      & bsfn_ad,  & !: Adjoint of now barotropic streamfunction
+      & bsfd_ad,  & !: Adjoint of now trend of barotropic streamfunction
+#else
+      & sshb_ad,  & !: Adjoint of before sea surface height
+      & sshn_ad,  & !: Adjoint of now sea surface height
+      & ssha_ad,  & !: Adjoint of after sea surface height
+      & sshu_ad,  & !: Adjoint of sea surface height at u-point
+      & sshv_ad,  & !: Adjoint of sea surface height at v-point
+      & sshbb_ad, & !: Adjoint of before before sea surface height
+#endif
+      & gtu_ad,   & !: Adjoint of
+      & gsu_ad,   & !:
+      & gru_ad,   & !: t-, s- and rd horizontal gradient at u- and 
+      & gtv_ad,   & !:   v-points at bottom ocean level
+      & gsv_ad,   & !: 
+      & 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.
+   PUBLIC &
+      & rrau_tl,  & !: Tangent Linear of heat/salt buoyancy flux ratio
+      & rrau_ad     !: Adjoint of heat/salt buoyancy flux ratio
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+#endif
+
+   !! * Module variables
+   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+      & ub_tl,    & !: Tangent linear of before u-component velocity
+      & un_tl,    & !: Tangent linear of now u-component velocity
+      & ua_tl,    & !: Tangent linear of after u-component velocity
+      & vb_tl,    & !: Tangent linear of before v-component velocity
+      & vn_tl,    & !: Tangent linear of now v-component velocity
+      & va_tl,    & !: Tangent linear of after v-component velocity
+      & wn_tl,    & !: Tangent linear of now w-component velocity
+      & rotb_tl,  & !: Tangent linear of before relative vorticity
+      & rotn_tl,  & !: Tangent linear of now relative vorticity
+      & hdivb_tl, & !: Tangent linear of before horizontal divergence
+      & hdivn_tl, & !: Tangent linear of now horizontal divergence
+      & tb_tl,    & !: Tangent linear of before temperature 
+      & tn_tl,    & !: Tangent linear of now temperature 
+      & ta_tl,    & !: Tangent linear of after temperature 
+      & sb_tl,    & !: Tangent linear of before salinity
+      & sn_tl,    & !: Tangent linear of now salinity
+      & sa_tl,    & !: Tangent linear of after salinity
+      & rhd_tl,   & !: Tangent linear of now in situ density anomaly  
+      & rhop_tl,  & !: Tangent linear of potential volumic mass (kg/m3)
+      & rn2_tl      !: Tangent linear of now Brunt-Vaisala frequency
+
+   REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+      & spgu_tl,  & !: Tangent of horizontal surface pressure gradient
+      & spgv_tl,  & !: 
+#if defined key_dynspg_rl
+      & bsfb_tl,  & !: Tangent linear of before barotropic streamfunction
+      & bsfn_tl,  & !: Tangent linear of now barotropic streamfunction
+      & bsfd_tl,  & !: Tangent linear of now trend of barotropic streamfunction
+#else  
+      & sshb_tl,  & !: Tangent linear of before sea surface height
+      & sshn_tl,  & !: Tangent linear of now sea surface height
+      & ssha_tl,  & !: Tangent linear of after sea surface height
+      & sshu_tl,  & !: Tangent linear of sea surface height at u-point
+      & sshv_tl,  & !: Tangent linear of sea surface height at v-point
+      & sshbb_tl, & !: Tangent linear of before before sea surface height
+#endif
+      & gtu_tl,   & !: Tangent Linear of
+      & gsu_tl,   & !:
+      & gru_tl,   & !: t-, s- and rd horizontal gradient at u- and 
+      & gtv_tl,   & !:   v-points at bottom ocean level
+      & gsv_tl,   & !: 
+      & grv_tl       
+
+   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+      & ub_ad,    & !: Adjoint of before u-component velocity
+      & un_ad,    & !: Adjoint of now u-component velocity
+      & ua_ad,    & !: Adjoint of after u-component velocity
+      & vb_ad,    & !: Adjoint of before v-component velocity
+      & vn_ad,    & !: Adjoint of now v-component velocity
+      & va_ad,    & !: Adjoint of after v-component velocity
+      & wn_ad,    & !: Adjoint of now w-component velocity
+      & rotb_ad,  & !: Adjoint of before relative vorticity
+      & rotn_ad,  & !: Adjoint of now relative vorticity
+      & hdivb_ad, & !: Adjoint of before horizontal divergence
+      & hdivn_ad, & !: Adjoint of now horizontal divergence
+      & tb_ad,    & !: Adjoint of before temperature 
+      & tn_ad,    & !: Adjoint of now temperature 
+      & ta_ad,    & !: Adjoint of after temperature 
+      & sb_ad,    & !: Adjoint of before salinity
+      & sn_ad,    & !: Adjoint of now salinity
+      & sa_ad,    & !: Adjoint of after salinity
+      & rhd_ad,   & !: Adjoint of now in situ density anomaly  
+      & rhop_ad,  & !: Adjoint of potential volumic mass (kg/m3)
+      & rn2_ad      !: Adjoint of now Brunt-Vaisala frequency
+
+#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.
+   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+      & rrau_tl,  & !: Tangent Linear of heat/salt buoyancy flux ratio
+      & rrau_ad     !: Adjoint of heat/salt buoyancy flux ratio
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+#endif
+
+   REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+      & spgu_ad,  & !: Adjoint of horizontal surface pressure gradient
+      & spgv_ad,  & !: 
+#if defined key_dynspg_rl
+      & bsfb_ad,  & !: Adjoint of before barotropic streamfunction
+      & bsfn_ad,  & !: Adjoint of now barotropic streamfunction
+      & bsfd_ad,  & !: Adjoint of now trend of barotropic streamfunction
+#else  
+      & sshb_ad,  & !: Adjoint of before sea surface height
+      & sshn_ad,  & !: Adjoint of now sea surface height
+      & ssha_ad,  & !: Adjoint of after sea surface height
+      & sshu_ad,  & !: Adjoint of sea surface height at u-point
+      & sshv_ad,  & !: Adjoint of sea surface height at v-point
+      & sshbb_ad, & !: Adjoint of before before sea surface height
+#endif
+      & gtu_ad,   & !: Adjoint of
+      & gsu_ad,   & !:
+      & gru_ad,   & !: t-, s- and rd horizontal gradient at u- and 
+      & gtv_ad,   & !:   v-points at bottom ocean level
+      & gsv_ad,   & !: 
+      & grv_ad
+
+CONTAINS
+
+   SUBROUTINE oce_tam_init( kindic )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE oce_tam_init  ***
+      !!
+      !! ** Purpose : Allocate and initialize the tangent linear and 
+      !!              adjoint arrays
+      !!
+      !! ** Method  : kindic = 0  allocate/initialize both tl and ad variables
+      !!              kindic = 1  allocate/initialize only tl variables
+      !!              kindic = 2  allocate/initialize only ad variables
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 07-07 (K. Mogensen) Initial version
+      !!        ! 08-07 (A. Vidard) Add missing variables
+      !!        ! 08-07 (A. Weaver) Add missing variables
+      !!        ! 09-03 (A. Weaver) Combine tl_init/ad_init into oce_tam_init,
+      !!                            make consistent with oce.F90 in NEMO
+      !!        ! 09-03 (A. Vidard) bug fixes on ssh*_ad alloc
+      !!-----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kindic        ! indicate which variables to allocate/initialize
+
+      !! * Local declarations
+      ! Allocate tangent linear variable arrays
+      ! ---------------------------------------
+      
+      IF ( kindic == 0 .OR. kindic == 1 ) THEN
+
+         IF ( .NOT. ALLOCATED(ub_tl) ) THEN
+
+            ALLOCATE( ub_tl(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(un_tl) ) THEN
+
+            ALLOCATE( un_tl(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(ua_tl) ) THEN
+
+            ALLOCATE( ua_tl(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(vb_tl) ) THEN
+
+            ALLOCATE( vb_tl(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(vn_tl) ) THEN
+
+            ALLOCATE( vn_tl(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(va_tl) ) THEN
+
+            ALLOCATE( va_tl(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(wn_tl) ) THEN
+
+            ALLOCATE( wn_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(rotb_tl) ) THEN
+
+            ALLOCATE( rotb_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(rotn_tl) ) THEN
+
+            ALLOCATE( rotn_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(hdivb_tl) ) THEN
+
+            ALLOCATE( hdivb_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(hdivn_tl) ) THEN
+
+            ALLOCATE( hdivn_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(tb_tl) ) THEN
+
+            ALLOCATE( tb_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(tn_tl) ) THEN
+
+            ALLOCATE( tn_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(ta_tl) ) THEN
+
+            ALLOCATE( ta_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(sb_tl) ) THEN
+
+            ALLOCATE( sb_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(sn_tl) ) THEN
+
+            ALLOCATE( sn_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(sa_tl) ) THEN
+
+            ALLOCATE( sa_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(rhd_tl) ) THEN
+
+            ALLOCATE( rhd_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(rhop_tl) ) THEN
+
+            ALLOCATE( rhop_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(rn2_tl) ) THEN
+
+            ALLOCATE( rn2_tl(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(spgu_tl) ) THEN
+
+            ALLOCATE( spgu_tl(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(spgv_tl) ) THEN
+
+            ALLOCATE( spgv_tl(jpi,jpj) )
+            
+         ENDIF
+#if defined key_dynspg_rl
+         IF ( .NOT. ALLOCATED(bsfb_tl) ) THEN
+
+            ALLOCATE( bsfb_tl(jpi,jpj) )
+         
+         ENDIF
+         IF ( .NOT. ALLOCATED(bsfn_tl) ) THEN
+
+            ALLOCATE( bsfn_tl(jpi,jpj) )
+         
+         ENDIF
+         IF ( .NOT. ALLOCATED(bsfd_tl) ) THEN
+
+            ALLOCATE( bsfd_tl(jpi,jpj) )
+         
+         ENDIF
+#else
+         IF (.NOT. ALLOCATED(sshb_tl) ) THEN
+         
+            ALLOCATE( sshb_tl(jpi,jpj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(sshn_tl) ) THEN
+         
+            ALLOCATE( sshn_tl(jpi,jpj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(ssha_tl) ) THEN
+         
+            ALLOCATE( ssha_tl(jpi,jpj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(sshu_tl) ) THEN
+         
+            ALLOCATE( sshu_tl(jpi,jpj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(sshv_tl) ) THEN
+         
+            ALLOCATE( sshv_tl(jpi,jpj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(sshbb_tl) ) THEN
+         
+            ALLOCATE( sshbb_tl(jpi,jpj) )
+
+         ENDIF
+#endif      
+         IF ( .NOT. ALLOCATED(gtu_tl) ) THEN
+
+            ALLOCATE( gtu_tl(jpi,jpj) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(gtv_tl) ) THEN
+
+            ALLOCATE( gtv_tl(jpi,jpj) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(gsu_tl) ) THEN
+
+            ALLOCATE( gsu_tl(jpi,jpj) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(gsv_tl) ) THEN
+
+            ALLOCATE( gsv_tl(jpi,jpj) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(gru_tl) ) THEN
+
+            ALLOCATE( gru_tl(jpi,jpj) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(grv_tl) ) THEN
+
+            ALLOCATE( grv_tl(jpi,jpj) )
+
+         ENDIF
+
+#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 ( .NOT. ALLOCATED(rrau_tl) ) THEN
+
+            ALLOCATE( rrau_tl(jpi,jpj,jpk) )
+            
+         ENDIF
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+#endif
+
+         ! Initialize tangent linear variable arrays to zero
+         ! -------------------------------------------------
+
+         ub_tl   (:,:,:) = 0.0_wp
+         un_tl   (:,:,:) = 0.0_wp
+         ua_tl   (:,:,:) = 0.0_wp
+         vb_tl   (:,:,:) = 0.0_wp
+         vn_tl   (:,:,:) = 0.0_wp
+         va_tl   (:,:,:) = 0.0_wp
+         wn_tl   (:,:,:) = 0.0_wp
+         rotb_tl (:,:,:) = 0.0_wp
+         rotn_tl (:,:,:) = 0.0_wp
+         hdivb_tl(:,:,:) = 0.0_wp
+         hdivn_tl(:,:,:) = 0.0_wp
+         tb_tl   (:,:,:) = 0.0_wp
+         tn_tl   (:,:,:) = 0.0_wp
+         ta_tl   (:,:,:) = 0.0_wp
+         sb_tl   (:,:,:) = 0.0_wp
+         sn_tl   (:,:,:) = 0.0_wp
+         sa_tl   (:,:,:) = 0.0_wp
+         rhd_tl  (:,:,:) = 0.0_wp
+         rhop_tl (:,:,:) = 0.0_wp
+         rn2_tl  (:,:,:) = 0.0_wp
+
+         spgu_tl(:,:)  = 0.0_wp
+         spgv_tl(:,:)  = 0.0_wp
+
+#if defined key_dynspg_rl
+         bsfb_tl(:,:)  = 0.0_wp
+         bsfn_tl(:,:)  = 0.0_wp
+         bsfd_tl(:,:)  = 0.0_wp
+#else
+         sshb_tl(:,:)  = 0.0_wp
+         sshn_tl(:,:)  = 0.0_wp
+         ssha_tl(:,:)  = 0.0_wp
+         sshu_tl(:,:)  = 0.0_wp
+         sshv_tl(:,:)  = 0.0_wp
+         sshbb_tl(:,:) = 0.0_wp
+#endif
+         gtu_tl (:,:)  = 0.0_wp
+         gsu_tl (:,:)  = 0.0_wp
+         gru_tl (:,:)  = 0.0_wp
+         gtv_tl (:,:)  = 0.0_wp
+         gsv_tl (:,:)  = 0.0_wp
+         grv_tl (:,:)  = 0.0_wp
+
+#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.
+         rrau_tl(:,:,:) = 0.0_wp
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+#endif
+
+      ENDIF
+
+      IF ( kindic == 0 .OR. kindic == 2 ) THEN
+
+         ! Allocate adjoint variable arrays
+         ! --------------------------------
+      
+         IF ( .NOT. ALLOCATED(ub_ad) ) THEN
+
+            ALLOCATE( ub_ad(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(un_ad) ) THEN
+
+            ALLOCATE( un_ad(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(ua_ad) ) THEN
+
+            ALLOCATE( ua_ad(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(vb_ad) ) THEN
+
+            ALLOCATE( vb_ad(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(vn_ad) ) THEN
+
+            ALLOCATE( vn_ad(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(va_ad) ) THEN
+
+            ALLOCATE( va_ad(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(wn_ad) ) THEN
+
+            ALLOCATE( wn_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(rotb_ad) ) THEN
+
+            ALLOCATE( rotb_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(rotn_ad) ) THEN
+
+            ALLOCATE( rotn_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(hdivb_ad) ) THEN
+
+            ALLOCATE( hdivb_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(hdivn_ad) ) THEN
+
+            ALLOCATE( hdivn_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(tb_ad) ) THEN
+
+            ALLOCATE( tb_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(tn_ad) ) THEN
+
+            ALLOCATE( tn_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(ta_ad) ) THEN
+
+            ALLOCATE( ta_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(sb_ad) ) THEN
+
+            ALLOCATE( sb_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(sn_ad) ) THEN
+
+            ALLOCATE( sn_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(sa_ad) ) THEN
+
+            ALLOCATE( sa_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(rhd_ad) ) THEN
+
+            ALLOCATE( rhd_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(rhop_ad) ) THEN
+
+            ALLOCATE( rhop_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(rn2_ad) ) THEN
+
+            ALLOCATE( rn2_ad(jpi,jpj,jpk) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(spgu_ad) ) THEN
+
+            ALLOCATE( spgu_ad(jpi,jpj) )
+            
+         ENDIF
+         IF ( .NOT. ALLOCATED(spgv_ad) ) THEN
+
+            ALLOCATE( spgv_ad(jpi,jpj) )
+            
+         ENDIF
+#if defined key_dynspg_rl
+         IF ( .NOT. ALLOCATED(bsfb_ad) ) THEN
+
+            ALLOCATE( bsfb_ad(jpi,jpj) )
+         
+         ENDIF
+         IF ( .NOT. ALLOCATED(bsfn_ad) ) THEN
+
+            ALLOCATE( bsfn_ad(jpi,jpj) )
+         
+         ENDIF
+         IF ( .NOT. ALLOCATED(bsfd_ad) ) THEN
+
+            ALLOCATE( bsfd_ad(jpi,jpj) )
+         
+         ENDIF
+#else
+         IF (.NOT. ALLOCATED(sshb_ad) ) THEN
+         
+            ALLOCATE( sshb_ad(jpi,jpj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(sshn_ad) ) THEN
+         
+            ALLOCATE( sshn_ad(jpi,jpj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(ssha_ad) ) THEN
+         
+            ALLOCATE( ssha_ad(jpi,jpj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(sshu_ad) ) THEN
+         
+            ALLOCATE( sshu_ad(jpi,jpj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(sshv_ad) ) THEN
+         
+            ALLOCATE( sshv_ad(jpi,jpj) )
+
+         ENDIF
+         IF (.NOT. ALLOCATED(sshbb_ad) ) THEN
+         
+            ALLOCATE( sshbb_ad(jpi,jpj) )
+
+         ENDIF
+#endif      
+         IF ( .NOT. ALLOCATED(gtu_ad) ) THEN
+
+            ALLOCATE( gtu_ad(jpi,jpj) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(gtv_ad) ) THEN
+
+            ALLOCATE( gtv_ad(jpi,jpj) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(gsu_ad) ) THEN
+
+            ALLOCATE( gsu_ad(jpi,jpj) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(gsv_ad) ) THEN
+
+            ALLOCATE( gsv_ad(jpi,jpj) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(gru_ad) ) THEN
+
+            ALLOCATE( gru_ad(jpi,jpj) )
+
+         ENDIF
+         IF ( .NOT. ALLOCATED(grv_ad) ) THEN
+
+            ALLOCATE( grv_ad(jpi,jpj) )
+
+         ENDIF
+
+#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 ( .NOT. ALLOCATED(rrau_ad) ) THEN
+
+            ALLOCATE( rrau_ad(jpi,jpj,jpk) )
+            
+         ENDIF
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+#endif
+
+         ! Initialize adjoint variable arrays to zero
+         ! ------------------------------------------
+
+         ub_ad   (:,:,:) = 0.0_wp
+         un_ad   (:,:,:) = 0.0_wp
+         ua_ad   (:,:,:) = 0.0_wp
+         vb_ad   (:,:,:) = 0.0_wp
+         vn_ad   (:,:,:) = 0.0_wp
+         va_ad   (:,:,:) = 0.0_wp
+         wn_ad   (:,:,:) = 0.0_wp
+         rotb_ad (:,:,:) = 0.0_wp
+         rotn_ad (:,:,:) = 0.0_wp
+         hdivb_ad(:,:,:) = 0.0_wp
+         hdivn_ad(:,:,:) = 0.0_wp
+         tb_ad   (:,:,:) = 0.0_wp
+         tn_ad   (:,:,:) = 0.0_wp
+         ta_ad   (:,:,:) = 0.0_wp
+         sb_ad   (:,:,:) = 0.0_wp
+         sn_ad   (:,:,:) = 0.0_wp
+         sa_ad   (:,:,:) = 0.0_wp
+         rhd_ad  (:,:,:) = 0.0_wp
+         rhop_ad (:,:,:) = 0.0_wp
+         rn2_ad  (:,:,:) = 0.0_wp
+
+         spgu_ad(:,:) = 0.0_wp
+         spgv_ad(:,:) = 0.0_wp
+#if defined key_dynspg_rl
+         bsfn_ad(:,:) = 0.0_wp
+         bsfb_ad(:,:) = 0.0_wp
+         bsfd_ad(:,:) = 0.0_wp
+#else
+         sshb_ad(:,:)  = 0.0_wp
+         sshn_ad(:,:)  = 0.0_wp
+         ssha_ad(:,:)  = 0.0_wp
+         sshu_ad(:,:)  = 0.0_wp
+         sshv_ad(:,:)  = 0.0_wp
+         sshbb_ad(:,:) = 0.0_wp
+#endif
+         gtu_ad (:,:) = 0.0_wp
+         gsu_ad (:,:) = 0.0_wp
+         gru_ad (:,:) = 0.0_wp
+         gtv_ad (:,:) = 0.0_wp
+         gsv_ad (:,:) = 0.0_wp
+         grv_ad (:,:) = 0.0_wp
+
+#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.
+         rrau_ad  (:,:,:) = 0.0_wp
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+#endif
+
+      ENDIF
+
+   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_2_2/NEMOTAM/OPATAM_SRC/opa_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/opa_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/opa_tam.F90	(revision 2578)
@@ -0,0 +1,434 @@
+MODULE opa_tam
+#if defined key_tam
+   !!==============================================================================
+   !!                       ***  MODULE opa_tam   ***
+   !! Ocean system   : TAM of the OPA ocean dynamics 
+   !!==============================================================================
+   !! History of the direct module:
+   !!            OPA  ! 1990-10  (C. Levy, G. Madec)  Original code
+   !!            7.0  ! 1991-11  (M. Imbard, C. Levy, G. Madec)
+   !!            7.1  ! 1993-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar, 
+   !!                             P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes )  release 7.1 
+   !!             -   ! 1992-06  (L.Terray)  coupling implementation
+   !!             -   ! 1993-11  (M.A. Filiberti) IGLOO sea-ice 
+   !!            8.0  ! 1996-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar, 
+   !!                             P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy)  release 8.0
+   !!            8.1  ! 1997-06  (M. Imbard, G. Madec)
+   !!            8.2  ! 1999-11  (M. Imbard, H. Goosse)  LIM sea-ice model 
+   !!                 ! 1999-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP 
+   !!                 ! 2000-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
+   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and modules
+   !!             -   ! 2004-06  (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
+   !!             -   ! 2004-08  (C. Talandier) New trends organization
+   !!             -   ! 2005-06  (C. Ethe) Add the 1D configuration possibility
+   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
+   !!             -   ! 2006-03  (L. Debreu, C. Mazauric)  Agrif implementation
+   !!             -   ! 2006-04  (G. Madec, R. Benshila)  Step reorganization
+   !!             -   ! 2007-07  (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
+   !!            3.2  ! 2009-08  (S. Masson)  open/write in the listing file in mpp
+   !! History of the TAM module:
+   !!            3.0  ! 2009-06  (F. Vigilant) first version (2 different executables)
+   !!            3.2  ! 2011-01  (A. Vidard) Rewriting it as one executable and update to 3.2.2
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   opa_model      : solve ocean dynamics, tracer and/or sea-ice
+   !!   opa_init       : initialization of the opa model
+   !!   opa_flg        : initialisation of algorithm flag 
+   !!   opa_closefile  : close remaining files
+   !!----------------------------------------------------------------------
+   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 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 sbcmod          ! surface boundary condition 
+   USE eosbn2          ! equation of state                 (eos_init routine)
+   USE dynhpg          ! hydrostatic pressure gradient
+   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)
+
+   USE tamtrj          ! writing out state trajectory
+   USE trj_tam         ! reading in state trajectory
+   USE tamtst          ! TAM testing options and init
+   USE step            ! OPA time-stepping                  (stp     routine)
+#if defined key_oasis3
+   USE cpl_oasis3      ! OASIS3 coupling
+#elif defined key_oasis4
+   USE cpl_oasis4      ! OASIS4 coupling (not working)
+#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
+   USE step_c1d        ! Time stepping loop for the 1D configuration
+#if defined key_top
+   USE trcini          ! passive tracer initialisation
+#endif
+   
+   USE iom
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing
+#if defined key_iomput
+   USE mod_ioclient
+#endif
+
+   USE opatlh           ! Tangent linear hypothesis testing
+   USE tamtst           ! Testing of the TAM operators
+   USE tamctl
+   USE oce_tam          ! OCE TAM field
+   USE sol_oce_tam      ! Initialize elliptic solver
+   USE trc_oce_tam      ! TRC TAM fields
+   USE sbc_oce_tam      ! SBC TAM fields
+   USE sbcmod_tam     
+   
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   opa_tam_model   ! called by model_tam.F90
+   PUBLIC   opa_tam_init    ! needed by AGRIF (? for tam ?)
+
+   CHARACTER (len=64) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.2 , LOCEAN-IPSL (2009) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE opa_tam_model
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa  ***
+      !!
+      !! ** Purpose :   opa solves the primitive equations on an orthogonal 
+      !!              curvilinear mesh on the sphere.
+      !!
+      !! ** Method  : - model general initialization
+      !!              - launch the time-stepping (stp routine)
+      !!              - finalize the run by closing files and communications
+      !!
+      !! References : Madec, Delecluse,Imbard, and Levy, 1997:  internal report, IPSL.
+      !!              Madec, 2008, internal report, IPSL.
+      !!----------------------------------------------------------------------
+      INTEGER ::   istp       ! time step index
+      !!----------------------------------------------------------------------
+
+#if defined key_agrif
+      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
+#endif
+
+      !                            !-----------------------!
+      CALL opa_tam_init            !==  Initialisations  ==!
+      !                            !-----------------------!
+      PRINT*,'init_done'
+      ! 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 )
+
+      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
+
+      !                            !-----------------------!
+      !                            !==   time stepping   ==!
+      !                            !-----------------------!
+      istp = nit000
+      IF ( ln_tst_opatam .AND. ln_tst_tlh .AND. .NOT. ln_incdx ) CALL opa_tlh_store
+
+      nstop = 0
+
+      IF( lk_c1d ) THEN                 !==  1D configuration  ==!
+         CALL ctl_stop( '       lk_c1d not available')         
+      ELSE                              !==  3D ocean with  ==!
+         DO WHILE ( istp <= nitend .AND. nstop == 0 )
+#if defined key_agrif
+            CALL ctl_stop( '       Agrif not available')
+#else
+            CALL stp( istp )                 ! standard time stepping
+#endif
+            istp = istp + 1
+            IF( lk_mpp )   CALL mpp_max( nstop )
+         END DO
+      ENDIF
+      IF ( ln_tst_opatam .AND. nstop == 0 ) THEN
+         IF ( ln_tst_tlh ) THEN
+            CALL opa_tlh
+         END IF
+         IF ( ln_tst_adj_cpd .OR. ln_tst_adj_stp .OR. ln_tst_tan_cpd .OR. ln_tst_tan_stp ) THEN
+            CALL tam_tst
+         END IF
+      END IF
+      !                            !------------------------!
+      !                            !==  finalize the run  ==!
+      !                            !------------------------!
+      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_tam_closefile
+#if defined key_oasis3 || defined key_oasis4
+      CALL ctl_stop( '       Key_oasis3 and key_oasis4 not available')
+#else
+      IF( lk_mpp )   CALL mppstop       ! end mpp communications
+#endif
+      !
+   END SUBROUTINE opa_tam_model
+
+
+   SUBROUTINE opa_tam_init
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_tam_init  ***
+      !!
+      !! ** Purpose :   initialization of the opa model
+      !!
+      !!----------------------------------------------------------------------
+#if defined key_oasis3 || defined key_oasis4 || defined key_iomput
+      INTEGER :: ilocal_comm
+#endif
+      CHARACTER(len=80),DIMENSION(10) ::   cltxt = ''
+      INTEGER                         ::   ji   ! local loop indices
+      !!
+      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
+         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle, nn_bench, nn_bit_cmp
+      !!----------------------------------------------------------------------
+      !
+      !                             ! open Namelist file
+      CALL ctl_opn( numnam, 'namelist', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
+      !
+      READ( numnam, namctl )        ! Namelist namctl : Control prints & Benchmark
+      !
+      !                             !--------------------------------------------!
+      !                             !  set communicator & select the local node  !
+      !                             !--------------------------------------------!
+#if defined key_iomput
+      IF( Agrif_Root() ) THEN
+# if defined key_oasis3 || defined key_oasis4
+         CALL ctl_stop( '       Key_oasis3 and key_oasis4 not available')
+# endif
+         CALL ctl_stop( '       Agrif not available')
+      ENDIF
+      narea = mynode( cltxt, ilocal_comm )    ! Nodes selection
+#else
+# if defined key_oasis3 || defined key_oasis4
+      CALL ctl_stop( '       Key_oasis3 and key_oasis4 not available')
+# else
+      nproc = mynode( cltxt )                 ! Nodes selection (control print return in cltxt)
+# endif
+#endif
+      narea = nproc + 1                       ! mynode return the rank of proc (0 --> jpnij -1 )
+
+      lwp = (narea == 1) .OR. ln_ctl          ! control of all listing output print
+
+      IF(lwp) THEN                            ! open listing units
+         !
+         CALL ctl_opn( numout, 'opatam.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
+         !
+         WRITE(numout,*)
+         WRITE(numout,*) '         CNRS - NERC - Met OFFICE - MERCATOR-ocean'
+         WRITE(numout,*) '                       NEMO team'
+         WRITE(numout,*) '            Ocean General Circulation Model'
+         WRITE(numout,*) '                  version 3.2  (2009) '
+         WRITE(numout,*)
+         WRITE(numout,*)
+         DO ji = 1, SIZE(cltxt) 
+            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
+         END DO
+         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
+         !
+      ENDIF
+      !                             !--------------------------------!
+      !                             !  Model general initialization  !
+      !                             !--------------------------------!
+
+      CALL opa_tam_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 eos_init                         ! Equation of state
+      CALL dom_cfg                          ! Domain configuration
+      CALL dom_init                         ! Domain
+      CALL tam_init
+!!gm c1d case can be moved in dom_init routine
+      IF( lk_c1d ) THEN                          ! 1D configuration 
+            CALL ctl_stop( '       c1d not available')
+      ENDIF
+!!gm c1d end
+
+      IF( ln_ctl )   CALL prt_ctl_init      ! Print control
+
+      IF( lk_obc )   CALL obc_init          ! Open boundaries 
+      IF( lk_bdy )   CALL ctl_stop( '    key_bdy not available')          ! Unstructured open boundaries
+
+      CALL istate_init                      ! ocean initial state (Dynamics and tracers)
+
+      !                                     ! Ocean physics
+      CALL sbc_init                             ! Read namsbc namelist : surface module (needed for iom_init)
+      CALL ldf_tra_init                         ! Lateral ocean tracer physics
+      CALL ldf_dyn_init                         ! Lateral ocean momentum physics
+      CALL zdf_init                             ! Vertical ocean physics
+
+#if defined key_top
+      CALL ctl_stop( '       top not available')
+#endif
+      !                                     ! diagnostics
+      CALL iom_init                             ! iom_put initialization
+      CALL dia_ptr_init                         ! Poleward TRansports initialization
+      CALL trd_mod_init                         ! Mixed-layer/Vorticity/Integral constraints trends
+      !
+      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
+      CALL sbc_oce_tam_init( 0 )            ! SBC TAM fields
+      CALL sbc_init_tam
+      CALL tam_trj_init
+      !
+   END SUBROUTINE opa_tam_init
+
+
+   SUBROUTINE opa_tam_flg
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa  ***
+      !!
+      !! ** Purpose :   Initialise logical flags that control the choice of
+      !!              some algorithm or control print
+      !!
+      !! ** Method  : - print namctl information
+      !!              - Read in namilist namflg logical flags
+      !!----------------------------------------------------------------------
+      NAMELIST/namdyn_hpg/ ln_hpg_zco   , ln_hpg_zps   , ln_hpg_sco, ln_hpg_hel,   &
+         &                 ln_hpg_wdj   , ln_hpg_djc   , ln_hpg_rot, rn_gamma  ,   &
+         &                 ln_dynhpg_imp
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN                 ! Parameter print
+         WRITE(numout,*)
+         WRITE(numout,*) 'opa_tam_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                  nn_print   = ', nn_print
+         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
+         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
+         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
+         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
+         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
+         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
+         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
+         WRITE(numout,*) '      bit comparison mode (0/1)       nn_bit_cmp = ', nn_bit_cmp
+      ENDIF
+
+      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
+      nictls    = nn_ictls
+      nictle    = nn_ictle
+      njctls    = nn_jctls
+      njctle    = nn_jctle
+      isplt     = nn_isplt
+      jsplt     = nn_jsplt
+      nbench    = nn_bench
+      nbit_cmp  = nn_bit_cmp
+
+      !                           ! Parameter control
+      !
+      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
+         IF( lk_mpp ) THEN
+            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real splitted domain
+         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
+            ijsplt = isplt * jsplt            ! total number of processors ijsplt
+         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
+         !
+         !                              ! indices used for the SUM control
+         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
+            lsp_area = .FALSE.                        
+         ELSE                                             ! print control 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
+      ENDIF
+
+      IF( nbench == 1 )   THEN            ! Benchmark 
+         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          ! Bit compare
+         CALL ctl_warn( ' Bit comparison enabled. Single and multiple processor results must bit compare', &
+              &         ' WARNING: RESULTS ARE NOT PHYSICAL.' )
+      ENDIF
+
+      REWIND( numnam )              ! Read Namelist namdyn_hpg : ln_dynhpg_imp must be read at the initialisation phase
+      READ  ( numnam, namdyn_hpg )
+      !
+   END SUBROUTINE opa_tam_flg
+
+
+   SUBROUTINE opa_tam_closefile
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_tam_closefile  ***
+      !!
+      !! ** Purpose :   Close the files
+      !!----------------------------------------------------------------------
+      USE dtatem        ! temperature data
+      USE dtasal        ! salinity data
+      !!----------------------------------------------------------------------
+      !
+      IF( lk_mpp )   CALL mppsync
+      !
+      CALL iom_close                                 ! close all input/output files managed by iom_*
+      !
+      IF( numstp     /= -1 )   CLOSE( numstp     )   ! time-step file
+      IF( numsol     /= -1 )   CLOSE( numsol     )   ! solver file
+      IF( numnam     /= -1 )   CLOSE( numnam     )   ! oce namelist
+      IF( numnam_ice /= -1 )   CLOSE( numnam_ice )   ! ice namelist
+      IF( numevo_ice /= -1 )   CLOSE( numevo_ice )   ! ice variables (temp. evolution)
+      IF( numout     /=  6 )   CLOSE( numout     )   ! standard model output file
+      numout = 6   ! redefine numout in case it is used after this point...
+      !
+   END SUBROUTINE opa_tam_closefile
+
+   !!======================================================================
+#endif
+END MODULE opa_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/opatlh.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/opatlh.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/opatlh.F90	(revision 2578)
@@ -0,0 +1,125 @@
+MODULE opatlh
+#if defined key_tam
+   !!==============================================================================
+   !!                       ***  MODULE opatlh   ***
+   !! Ocean system   : Testing of the tangent linear hypothesis 
+   !!==============================================================================
+   !! History:
+   !!   NEMO     3.0  ! 2011-01 (F. Vigilant) first version (2 different executables)
+   !!            3.2  ! 2011-01 (A. Vidard) reaorganization and update to 3.2.2
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   opa_tlh       : run the perturbed direct model and the tangent
+   !!----------------------------------------------------------------------
+   
+   USE oce           , ONLY : & ! Direct Ocean fields
+      & un,            vn,           tn,          sn,          sshn
+      
+   USE oce_tam       , ONLY : & ! Tangent Ocean fields
+      & un_tl,         vn_tl,        tn_tl,       sn_tl,       sshn_tl
+
+   USE tamctl        , ONLY : & ! TAM related namelist
+      & ln_incdx,      cn_tlhrst_in
+
+   USE step_tam      , ONLY : & ! Tangent and adjoint model integrations
+      & stp_tan
+
+   USE step          , ONLY : & ! direct model integration
+      & stp
+
+   USE istate        , ONLY : & ! initialization of the direct model 
+      & istate_init
+
+   USE in_out_manager, ONLY : & ! I/O manager
+      & ctl_stop,      nit000,       nitend,     nstop,     cn_ocerst_in
+
+   USE c1d           , ONLY : & ! 1D initialization
+      & lk_c1d
+
+   USE lib_mpp       , ONLY : & ! mpp library
+      & mpp_max
+
+   PRIVATE
+
+   PUBLIC opa_tlh
+   PUBLIC opa_tlh_store
+CONTAINS
+   SUBROUTINE opa_tlh
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_tlh  ***
+      !!
+      !! ** Purpose :   performe the second integration of the direct model 
+      !!                and the integration of the tangent model in order to
+      !!                validate (or not) the tangent linear hypothesis
+      !!
+      !!----------------------------------------------------------------------
+
+      INTEGER :: istp
+
+      IF ( ln_incdx ) THEN
+         ! read in the increment
+         CALL ctl_stop( '   tlh from increment not available')         
+         
+         ! create the new direct model initial state
+      ELSE
+         ! Read another restart
+         cn_ocerst_in = cn_tlhrst_in
+         CALL istate_init
+         ! compute the increment 
+         un_tl   = un_tl   - un
+         vn_tl   = vn_tl   - vn
+         tn_tl   = tn_tl   - tn
+         sn_tl   = sn_tl   - sn
+         sshn_tl = sshn_tl - sshn
+         
+      END IF
+
+      ! Integration of the direct model from the perturbed state
+      istp = nit000
+      IF( lk_c1d ) THEN                 !==  1D configuration  ==!
+         CALL ctl_stop( '       lk_c1d not available')         
+      ELSE                              !==  3D ocean with  ==!
+         DO WHILE ( istp <= nitend .AND. nstop == 0 )
+# if defined key_agrif
+            CALL ctl_stop( '       Agrif not available')
+# else
+            CALL stp( istp )                 ! standard time stepping
+# endif
+            istp = istp + 1
+            IF( lk_mpp )   CALL mpp_max( nstop )
+         END DO
+      ENDIF
+      ! Integration of the tangent model
+      istp = nit000
+      IF( lk_c1d ) THEN                 !==  1D configuration  ==!
+         CALL ctl_stop( '       lk_c1d not available')         
+      ELSE                              !==  3D ocean with  ==!
+         DO WHILE ( istp <= nitend .AND. nstop == 0 )
+# if defined key_agrif
+            CALL ctl_stop( '       Agrif not available')
+# else
+            CALL stp_tan( istp )                 ! standard time stepping
+# endif
+            istp = istp + 1
+            IF( lk_mpp )   CALL mpp_max( nstop )
+         END DO
+      ENDIF
+   END SUBROUTINE opa_tlh
+   SUBROUTINE opa_tlh_store
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_tlh_store  ***
+      !!
+      !! ** Purpose :   store the direct model initial state in the tangent 
+      !!                for the computation of the increment
+      !!
+      !!----------------------------------------------------------------------
+      
+      un_tl   = un
+      vn_tl   = vn
+      tn_tl   = tn
+      sn_tl   = sn
+      sshn_tl = sshn
+   END SUBROUTINE opa_tlh_store
+#endif
+END MODULE opatlh
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/paresp.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/paresp.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/paresp.F90	(revision 2578)
@@ -0,0 +1,262 @@
+MODULE paresp
+   !!======================================================================
+   !!                       ***  MODULE paresp ***
+   !! NEMOVAR : Weights for an energy-type scalar product
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!  par_esp : Compute and store weights for an energy-type scalar product
+   !!----------------------------------------------------------------------
+   !! * Modules used   
+   USE par_kind, ONLY : &  ! Precision variables
+      & wp
+   USE par_oce, ONLY : &   ! Ocean space and time domain variables
+      & jpk
+   USE eosbn2, ONLY : &    ! Equation of state
+      & rn_alpha, &
+      & rn_beta
+   USE phycst, ONLY : &    ! Physical constants
+      & grav, &
+      & rcp
+   USE zdf_oce, ONLY : &   ! Vertical mixing parameters
+      & rn_avt0, &
+      & rn_avm0
+   USE dom_oce, ONLY : &   ! Ocean space domain parameters
+      & gdept_0, &
+      & e3w_0
+   USE in_out_manager      ! I/O stuff
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+
+   PUBLIC &
+      & par_esp       !: Compute and store energy weights
+
+   !! * Share module variables
+   REAL(wp), DIMENSION(jpk), PUBLIC ::   &
+      & wesp_t,   &   !: Normalized energy weights for temperature
+      & wesp_s        !: Normalized energy weights for salinity
+   REAL(wp), PUBLIC ::   &
+      & wesp_u,   &   !: Normalized energy weights for velocity
+      & wesp_ssh, &   !: Normalized energy weights for SSH
+      & wesp_tau, &   !: Normalized energy weights for windstress
+      & wesp_q,   &   !: Normalized energy weights for heat flux
+      & wesp_emp      !: Normalized energy weights for EmP
+
+CONTAINS
+
+   SUBROUTINE par_esp
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE par_esp  ***
+      !!
+      !! ** Purpose : Compute and store weights for an energy-type scalar 
+      !!              product.
+      !!
+      !! ** Method  : 
+      !!      The weighting coefficients are computed from an analytical
+      !!      linear density profile which is similar to the one used in 
+      !!      default option in OPA direct.
+      !!
+      !!      The weighting coefficients for the forcing fields are estimated 
+      !!      from the surface boundary conditions.
+      !!
+      !!      The weighting coefficients for the velocity variables are 
+      !!      normalized to one.
+      !!
+      !!       wesp_t(k) = ( g / N(k) )^2 x alpha^2      
+      !!       wesp_s(k) = ( g / N(k) )^2 x beta^2      
+      !!       wesp_u    = 1
+      !!       wesp_ssh  = g
+      !!       wesp_tau  = ( ( e3w(1) / ( avu x rho0 ) )^2
+      !!       wesp_q    = ( ( g / N(1) x alpha
+      !!                  x e3w(1) / ( avT x rho0 x cp ) )^2
+      !!       wesp_emp  = ( ( g / N(1) x beta
+      !!                  x e3w(1) x S(1) / avT )^2
+      !!      
+      !!      where
+      !!
+      !!        N(k)   is the Brunt-Vaisala frequency (depth-dependent)
+      !!        alpha  is the thermal expansion coefficient
+      !!        beta   is the salinity expansion coefficient
+      !!        g      is gravity
+      !!        avu    is vertical eddy viscosity coefficent for dynamics
+      !!        avT    is vertical eddy diffusivity coefficent for tracers
+      !!        e3w(1) is the vertical scale factor at top w-point
+      !!        rho0   is a reference density
+      !!        S(1)   is a reference salinity at the surface
+      !!
+      !!      The complete scalar product < ; > for the state vector 
+      !!
+      !!       dx = ( du , dv , dT , dS , deta , dq , demp , dtaux , dtauy )
+      !!
+      !!      involves the volume/area elements:
+      !!
+      !!      < dx ; dx > = sum_i,j (  deta^2  * e1T * e2T           * wesp_ssh
+      !!                             + dq^2    * e1T * e2T * e3w(1)  * wesp_q
+      !!                             + demp^2  * e1T * e2T * e3w(1)  * wesp_emp
+      !!                             + dtaux^2 * e1u * e2u * e3uw(1) * wesp_tau
+      !!                             + dtauy^2 * e1v * e2v * e3vw(1) * wesp_tau
+      !!                    + sum_k (  du^2 * e1u * e2u * e3u * wesp_u
+      !!                             + dv^2 * e1v * e2v * e3v * wesp_u
+      !!                             + dT^2 * e1T * e2T * e3T * wesp_T
+      !!                             + dS^2 * e1T * e2T * e3T * wesp_S )    )
+      !!
+      !! ** Action  :
+      !!                   
+      !! History :
+      !!        ! 97-06 (A. Weaver, J. Vialard) OPAVAR version
+      !!        ! 07-11 (A. Weaver) NEMOVAR version based on OPAVAR paresp.F
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+
+      !! * Local declarations
+      REAL(KIND=wp) :: &
+         & zgrau0, &
+         & zk,     &
+         & zt0,    &
+         & zs0,    &
+         & zrau0
+      REAL(KIND=wp), DIMENSION(jpk) :: &
+         & ztan,   &
+         & zsan,   &
+         & zrhan,  &
+         & zbn2an
+      INTEGER :: &
+         & jk
+
+      !--------------------------------------------------------------------
+      ! Local constant initialization
+      !--------------------------------------------------------------------
+
+      zt0   = 19.0_wp    ! Reference temperature
+      zs0   = 35.0_wp    ! Reference salinity
+      zrau0 = 1025.0_wp  ! Reference density
+
+      zgrau0 = -1.0_wp * grav / zrau0
+
+      !--------------------------------------------------------------------
+      ! Initialize rho with an analytical profile
+      !--------------------------------------------------------------------
+
+      !  Define analytical temperature profile
+
+      DO jk = 1, jpk
+         ztan(jk) =  7.5_wp * ( 1.0_wp - TANH( ( gdept_0(jk) - 80.0_wp ) &
+            &                 / 30.0_wp ) ) &
+            &      + 10.0_wp * ( 5300.0_wp - gdept_0(jk) ) / 5300.0_wp
+         ztan(jk) = ABS( ztan(jk) )
+      END DO
+#if defined key_pomme_r025
+      ztan(44) = 0.20
+      ztan(45) = 0.15
+      ztan(46) = 0.10
+#endif
+
+      !  Define analytical salinity profile
+
+      DO jk = 1, jpk
+         zsan(jk) = 35.50_wp
+      END DO
+
+      !  Define analytical density profile
+
+      DO jk = 1, jpk
+         zrhan(jk) =  zrau0 * ( 1.0_wp - rn_alpha * ( ztan(jk) - zt0 ) &
+            &                          + rn_beta  * ( zsan(jk) - zs0 ) )
+      END DO
+
+      !--------------------------------------------------------------------
+      ! Calculate N^2 at T and S points
+      !--------------------------------------------------------------------
+
+      DO jk = 2, jpkm1
+         zbn2an(jk) = ( zgrau0 / 2.0_wp ) &
+            & * (   ( ( zrhan(jk-1) - zrhan(jk  ) ) / e3w_0(jk  ) ) &
+            &     + ( ( zrhan(jk  ) - zrhan(jk+1) ) / e3w_0(jk+1) ) )
+      END DO
+
+      zbn2an(1)   = zbn2an(2)
+      zbn2an(jpk) = zbn2an(jpkm1)
+
+      !--------------------------------------------------------------------
+      ! Calculate energy-type weights
+      !--------------------------------------------------------------------
+     
+      DO jk = 1, jpk
+         zk = ( grav * grav ) / zbn2an(jk)
+         wesp_t(jk) = zk * rn_alpha * rn_alpha
+         wesp_s(jk) = zk * rn_beta  * rn_beta
+      END DO
+
+      wesp_u   = 1.0_wp
+      wesp_ssh = grav
+      wesp_tau = ( e3w_0(1) / ( rn_avm0 * zrau0 ) )**2
+      wesp_q   = wesp_t(1) * ( e3w_0(1) / ( rn_avt0 * zrau0 * rcp ) )**2
+      wesp_emp = wesp_s(1) * ( e3w_0(1) * zsan(1) / rn_avt0  )**2
+
+      !--------------------------------------------------------------------
+      ! Print
+      !--------------------------------------------------------------------
+
+      IF (lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' par_esp: Analytical T, S, rho, N^2 profiles'
+         WRITE(numout,*) ' -------'
+         WRITE(numout,*) 
+         WRITE(numout,995) 
+         WRITE(numout,996)
+         DO jk = 1, jpk 
+            IF(lwp)WRITE(numout,1007) jk, ztan(jk), zsan(jk), &
+               &                      zrhan(jk), zbn2an(jk)   
+         END DO
+         WRITE(numout,*)
+         WRITE(numout,*) ' par_esp: Energy scalar product weights', &
+            &            ' for T and S'
+         WRITE(numout,*) ' -------'
+         WRITE(numout,*) 
+         WRITE(numout,998) 
+         WRITE(numout,999)
+         DO jk = 1, jpk 
+            WRITE(numout,1006) jk, wesp_t(jk), wesp_s(jk)
+         END DO
+         WRITE(numout,*)
+         WRITE(numout,*) ' par_esp: Energy scalar product weights', &
+            &            ' for u, SSH, tau, Q and EmP'
+         WRITE(numout,*) ' -------'
+         WRITE(numout,*)
+         WRITE(numout,*) '          wesp_u   = ', wesp_u
+         WRITE(numout,*) '          wesp_ssh = ', wesp_ssh
+         WRITE(numout,*) '          wesp_tau = ', wesp_tau
+         WRITE(numout,*) '          wesp_q   = ', wesp_q
+         WRITE(numout,*) '          wesp_emp = ', wesp_emp
+
+ 995     FORMAT('    level        T              S    ', &
+            &   '        rho             N^2 ')
+ 996     FORMAT('    -----     --------       --------', &
+            &   '     ----------     ----------')
+ 998     FORMAT('    level   wesp_T        wesp_S   ')
+ 999     FORMAT('    ----- ----------   ------------')
+ 1005    FORMAT(4X,I2,3X,E12.5,1X,E12.5)
+ 1006    FORMAT(4X,I2,3X,E12.5,1X,E12.5)
+ 1007    FORMAT(4X,I2,6X,F10.5,5X,F10.5,5X,F10.5,5X,E10.5)
+         CALL flush( numout )
+
+      ENDIF
+      
+      DO jk = 1, jpk 
+         IF ( zbn2an(jk) < 0.0_wp ) THEN
+            IF(lwp)WRITE(numout,990) zbn2an(jk), jk
+990         FORMAT(' paresp : Error unstable density profile;', &
+               &   ' zbn2an = ',E10.5,' at level ',I3)
+            CALL ctl_stop( 'paresp; unstable density profile' )
+         ENDIF
+      ENDDO
+
+   END SUBROUTINE par_esp
+
+END MODULE paresp
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/partlm.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/partlm.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/partlm.F90	(revision 2578)
@@ -0,0 +1,28 @@
+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
+
+END MODULE par_tlm
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/ran_num.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/ran_num.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/ran_num.F90	(revision 2578)
@@ -0,0 +1,275 @@
+MODULE ran_num
+   !!======================================================================
+   !!                       *** MODULE ran_num ***
+   !! NEMOVAR: Random number routines
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !! gaustb    : returns a gaussian randum number with mean and std.
+   !! gaustb_2d : returns a gaussian randum number with mean and std for a
+   !!             given horizontal grid point
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind       ! Kind variables
+   USE dom_oce        ! Domain variables
+   USE in_out_manager ! I/O stuff
+   USE mt19937ar, ONLY : &
+    & init_mtrand,       &
+    & mtrand_real1
+ 
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+
+   PRIVATE
+
+   PUBLIC &
+      & gaustb, &
+      & gaustb_2d
+
+CONTAINS
+
+   FUNCTION gaustb( kseed, pamp, pmean  )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE gaustb ***
+      !!          
+      !! ** Purpose : Returns a gaussian randum number with mean and std.
+      !!
+      !! ** Method  : Generate Gaussian random variables.
+      !!              The standard deviation and mean of the variables are 
+      !!              specified by the variables pamp and pmean.
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code based on gaustb.F
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) :: &
+         & gaustb
+      !! * Arguments
+      INTEGER, INTENT(INOUT) :: &
+         & kseed        ! Seed
+      REAL(wp), INTENT(IN) :: &
+         & pamp, &      ! Amplitude
+         & pmean        ! Mean value
+      !! * Local declarations
+      
+      gaustb = pamp * gausva( kseed ) + pmean
+
+   END FUNCTION gaustb
+
+
+   FUNCTION gausva( kdum )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE gausva ***
+      !!          
+      !! ** Purpose : Returns a normally distributed deviate with 0 mean 
+      !!              and unit variance using the unifva(kdum) as the 
+      !!              source of uniform deviates.
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code based on gaustb.F
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) :: &
+         & gausva
+      !! * Arguments
+      INTEGER, INTENT(INOUT) :: &
+         & kdum          ! Seed
+      !! * Local declarations
+      REAL(wp), SAVE :: &
+         & gset
+      INTEGER, SAVE :: &
+         & niset = 0
+      REAL(wp) :: &
+         & zfac, &
+         & zrsq, &
+         & zv1,  &
+         & zv2
+
+      ! Begin main
+
+      IF ( niset == 0 ) THEN
+
+         zv1   = 2.0_wp * psrandom( kdum ) - 1.0_wp
+         zv2   = 2.0_wp * psrandom( kdum ) - 1.0_wp
+         zrsq  = zv1**2 + zv2**2
+         
+         DO WHILE ( ( zrsq >= 1.0_wp ) .OR. ( zrsq == 0.0_wp ) ) 
+
+            zv1   = 2.0_wp * psrandom( kdum ) - 1.0_wp
+            zv2   = 2.0_wp * psrandom( kdum ) - 1.0_wp
+            zrsq  = zv1**2 + zv2**2
+
+         END DO
+
+         zfac   = SQRT( -2.0_wp * LOG( zrsq ) / zrsq )
+         gset   = zv1 * zfac
+         gausva = zv2 * zfac
+         niset  = 1
+
+      ELSE
+
+         gausva = gset
+         niset  = 0
+
+      ENDIF
+       
+   END FUNCTION gausva
+
+   FUNCTION gaustb_2d( ki, kj, kseed, pamp, pmean  )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE gaustb_2d ***
+      !!          
+      !! ** Purpose : Returns a Gaussian randum number with mean and std
+      !!              for a given horizontal grid point.
+      !!
+      !! ** Method  : Generate Gaussian random variables.
+      !!              The standard deviation and mean of the variables are 
+      !!              specified by the variables pamp and pmean.
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code based on gaustb.F
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) :: &
+         & gaustb_2d
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & ki, &        ! Indices in seed array
+         & kj
+      INTEGER, INTENT(INOUT), DIMENSION(jpi,jpj) :: &
+         & kseed        ! Seed
+      REAL(wp), INTENT(IN) :: &
+         & pamp, &      ! Amplitude
+         & pmean        ! Mean value
+      !! * Local declarations
+      
+      gaustb_2d = pamp * gausva_2d( ki, kj, kseed ) + pmean
+
+   END FUNCTION gaustb_2d
+
+   FUNCTION gausva_2d( ki, kj, kdum )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE gausva_2d ***
+      !!          
+      !! ** Purpose : Returns a normally distributed deviate with 0 mean 
+      !!              and unit variance.
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  07-07  (K. Mogensen)  Original code based on gaustb.F
+      !!----------------------------------------------------------------------
+      !! * Function return
+      REAL(wp) :: &
+         & gausva_2d
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & ki, &         ! Indices in seed array
+         & kj
+      INTEGER, INTENT(INOUT), DIMENSION(jpi,jpj) :: &
+         & kdum          ! Seed
+      !! * Local declarations
+      REAL(wp), SAVE, DIMENSION(jpi,jpj) :: &
+         & gset
+      INTEGER, SAVE, DIMENSION(jpi,jpj) :: &
+         & niset
+      LOGICAL, SAVE :: &
+         & llinit = .FALSE.
+      REAL(wp) :: &
+         & zfac, &
+         & zrsq, &
+         & zv1,  &
+         & zv2
+
+      ! Initialization
+
+      IF ( .NOT. llinit ) THEN
+
+         niset(:,:) = 0
+         llinit     = .TRUE.
+
+      ENDIF
+
+      ! Begin main
+
+      IF ( niset(ki,kj) == 0 ) THEN
+
+         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( kdum(ki,kj) ) - 1.0_wp
+            zv2   = 2.0_wp * psrandom( kdum(ki,kj) ) - 1.0_wp
+            zrsq  = zv1**2 + zv2**2
+
+         END DO
+
+         zfac   = SQRT( -2.0_wp * LOG( zrsq ) / zrsq )
+         gset(ki,kj) = zv1 * zfac
+         gausva_2d   = zv2 * zfac
+         niset(ki,kj) = 1
+
+      ELSE
+
+         gausva_2d = gset(ki,kj)
+         niset(ki,kj)  = 0
+
+      ENDIF
+       
+   END FUNCTION gausva_2d
+
+   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.
+      INTEGER :: &
+	& kdum1, &
+	& kdum2
+
+      ! Initialization
+      IF ( .NOT. llinit ) THEN
+	 kdum2 = 596035
+	 kdum1 = kdum + nproc * kdum2
+         CALL init_mtrand(kdum)
+         llinit     = .TRUE.
+      ENDIF
+
+      psrandom = mtrand_real1()
+
+   END FUNCTION psrandom
+
+
+END MODULE ran_num
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/step_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/step_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/step_tam.F90	(revision 2578)
@@ -0,0 +1,1955 @@
+MODULE step_tam
+#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, rn2
+   USE dynhpg        , ONLY: &
+      & ln_dynhpg_imp
+   USE zdfkpp        , ONLY: &
+      & lk_zdfkpp      ! KPP vertical mixing 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 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,        &
+      & oce_tam_deallocate,  &
+      & 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,    &
+#if defined key_obc
+      & sshb_ad,             &
+#endif
+      & 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,    &
+      & rotb_tl, hdivb_tl,   &
+      & rotn_tl, hdivn_tl,   &
+      & wn_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 dynbfr_tam      ! time-stepping                    (adjoint of dyn_nxt routine)
+   USE sshwzv_tam      ! vertical velocity and ssh        (ssh_wzv 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 zdfkpp_tam     ! KPP vertical mixing
+   USE zdf_oce, ONLY : & ! KPP vertical mixing
+      & lk_zdfcst, avt, avmv, avmu, &
+      & rn_avt0, rn_avm0, ln_zdfevd         
+   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)
+
+!!   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
+   USE iom ! for dumping an abort state 
+#if defined key_obc
+   USE obc_par, ONLY : lk_obc
+   USE obcdta          ! open boundary condition data     (obc_dta routine)
+#endif
+
+#if defined key_agrif
+#error 'agrif not yet implemented in nemotam'
+#endif
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC stp_tan,      &
+      &   stp_adj,      & ! called by simvar.F90
+#if defined key_tst_tlm
+      &   stp_tlm_tst,  &
+#endif
+      &   stp_adj_tst
+
+   !! * 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( 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
+      !! ---------------------------------------------------------------------
+
+#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
+
+      IF( kstp /= nit000 )   CALL day_tam( kstp, 0 )             ! Calendar (day was already called at nit000 in day_init)
+
+      CALL iom_setkt( kstp )                          ! say to iom that we are at time step kstp
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! 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) 
+
+!      IF( lk_obc     )   CALL obc_dta( kstp )  ! ???       ! update dynamic and tracer data at open boundaries
+      ! 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
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      !  Ocean dynamics : ssh, wn, hdiv, rot                                 !
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+                             CALL ssh_wzv_tan( kstp )         ! after ssh & vertical velocity
+
+      ! saving direct variables ua,va, ta, sa before entering in tracer
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Ocean physics update                (ua, va, ta, sa used as workspace)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+!                             CALL bn2_tan( tb, sb, tb_tl, sb_tl, rn2b_tl )          ! before Brunt-Vaisala frequency not needed in tangent
+                             CALL bn2_tan( tn, sn, tn_tl, sn_tl, rn2_tl )         ! now Brunt-Vaisala frequency
+
+      !-----------------------------------------------------------------------
+      !  VERTICAL PHYSICS
+      !-----------------------------------------------------------------------
+
+      !                                                     ! 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)... 
+      IF( lk_zdfcst )   THEN                                       ! Constant Kz (reset avt, avm[uv] to the background value)
+
+         avt (:,:,:) = rn_avt0 * tmask(:,:,:)
+         avmu(:,:,:) = rn_avm0 * umask(:,:,:)
+         avmv(:,:,:) = rn_avm0 * vmask(:,:,:)
+
+         IF( ln_zdfevd )   THEN 
+            CALL zdf_evd( kstp )                 ! enhanced vertical eddy diffusivity
+            CALL bn2( tb, sb, rn2 )              ! before Brunt-Vaisala frequency
+         END IF
+         IF( lk_zdfddm )   &
+            &              CALL zdf_ddm( kstp )                 ! double diffusive mixing
+
+                           CALL zdf_bfr( kstp )                 ! bottom friction
+
+                           CALL zdf_mxl( kstp )                 ! mixed layer depth
+      ENDIF
+      ! ! 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
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! diagnostics and outputs             (ua, va, ta, sa used as workspace)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !      not needed in tangent
+
+#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
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Active tracers                              (ua, va used as workspace)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                             ta_tl(:,:,:) = 0.0_wp            ! set tracer trends to zero
+                             sa_tl(:,:,:) = 0.0_wp
+
+      ! 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
+
+      IF( ln_dynhpg_imp  ) THEN                             ! semi-implicit hpg (time stepping then eos)
+      ! update the new (t,s) fields by non
+      ! penetrative convective adjustment ... not available 
+                             CALL tra_nxt_tan( kstp )                              ! tracer fields at next time step
+                             CALL eos_tan( ta, sa, ta_tl, sa_tl, &                 ! Time-filtered in situ density used in dynhpg module
+                                         & rhd_tl, rhop_tl         )              
+         IF( ln_zps    )     CALL zps_hde_tan( kstp, ta, sa, ta_tl, sa_tl,     & 
+            &                                  rhd_tl, gtu_tl, gsu_tl, gru_tl, &   ! Partial steps: time filtered hor. gradient
+            &                                  gtv_tl, gsv_tl, grv_tl )            ! of t, s, rd at the bottom ocean level
+      ELSE                                              ! centered hpg (default case)
+                             CALL eos_tan( tn, sn, tn_tl, sn_tl, &                 ! now (swap=before) in situ density for dynhpg module
+            &                              rhd_tl, rhop_tl )       
+         IF( ln_zps    )     CALL zps_hde_tan( kstp, tn, sn, tn_tl, sn_tl,     &   ! Partial steps: now horizontal gradient
+            &                                  rhd_tl, gtu_tl, gsu_tl, gru_tl, &   ! of t, s, rd at the bottom ocean level
+            &                                  gtv_tl, gsv_tl, grv_tl )        
+                             CALL tra_nxt_tan( kstp )                              ! tracer fields at next time step    
+      ENDIF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Dynamics                                    (ta, sa used as workspace)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                             ua_tl(:,:,:) = 0.0_wp               ! set dynamics trends to zero
+                             va_tl(:,:,:) = 0.0_wp
+
+      ! 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_bfr_tan( kstp )           ! bottom friction   
+
+                             CALL dyn_zdf_tan( kstp )           ! vertical diffusion
+                             indic=0
+                             CALL dyn_spg_tan( kstp, indic )    ! surface pressure gradient
+                             CALL dyn_nxt_tan( kstp )           ! lateral velocity at next time step
+                             CALL ssh_nxt_tan( kstp )         ! sea surface height 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 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
+
+#if defined key_agrif
+#error 'agrif not yet implemented in nemotam'
+   ! SUBROUTINE stp_adj( )
+#else
+   SUBROUTINE stp_adj( kstp )
+#endif
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE stp_adj  ***
+      !!                      
+      !! ** 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
+      !! ---------------------------------------------------------------------
+
+#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
+
+      ! ... Read basic state trajectory at end of previous step
+                             CALL trj_rea( ( kstp - 1 ), -1 )
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Dynamics                                    (ta, sa used as workspace)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! apply dynamics assimilation increment ... not needed in adjoint
+                             indic=0
+      !i bug lbc sur emp
+      ! vertical mesh at next time step ... not available
+
+                             CALL ssh_nxt_adj( kstp )         ! sea surface height at next time step
+                             CALL dyn_nxt_adj( kstp )           ! lateral velocity at next time step
+                             CALL dyn_spg_adj( kstp, indic )    ! surface pressure gradient
+                             CALL dyn_zdf_adj( kstp )           ! vertical diffusion
+                             CALL dyn_bfr_adj( kstp )           ! bottom friction   
+                             CALL dyn_hpg_adj( kstp )           ! horizontal gradient of Hydrostatic pressure
+#if defined key_agrif
+      ! momemtum sponge ... not available
+#endif
+                             CALL dyn_ldf_adj( kstp )           ! lateral mixing
+                             CALL dyn_vor_adj( kstp )           ! vorticity term including Coriolis
+                             CALL dyn_adv_adj( kstp )           ! advection (vector or flux form)
+
+                             ua_ad(:,:,:)  = 0.0_wp                ! set tracer trends to zero
+                             va_ad(:,:,:)  = 0.0_wp  
+                           
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Active tracers                              (ua, va used as workspace)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      IF( ln_dynhpg_imp  ) THEN                             ! semi-implicit hpg
+         IF( ln_zps    )     CALL zps_hde_adj( kstp, ta, sa, ta_ad, sa_ad,      &   ! Partial steps: time filtered hor. gradient
+            &                                  rhd_ad, gtu_ad, gsu_ad, gru_ad,  &   ! of t, s, rd at the bottom ocean level
+            &                                  gtv_ad, gsv_ad, grv_ad )
+                             CALL eos_adj( ta, sa, ta_ad, sa_ad, rhd_ad, rhop_ad )  ! Time-filtered in situ density used in dynhpg module
+                             CALL tra_nxt_adj( kstp )           ! tracer fields at next time step
+      ELSE                                                  ! centered hpg (default case)
+                             CALL tra_nxt_adj( kstp )           ! tracer fields at next time step
+         IF( ln_zps    )     CALL zps_hde_adj( kstp, tn, sn, tn_ad, sn_ad,      &   ! Partial steps: now horizontal gradient
+            &                                  rhd_ad, gtu_ad, gsu_ad, gru_ad,  &   ! of t, s, rd at the bottom ocean level
+            &                                  gtv_ad, gsv_ad, grv_ad )
+                             CALL eos_adj( tn, sn, tn_ad, sn_ad, rhd_ad, rhop_ad )  ! now (swap=before) in situ density for dynhpg module
+      ENDIF
+
+      ! update the new (t,s) fields by non
+      ! penetrative convective adjustment ... not available 
+
+                             CALL tra_zdf_adj( kstp )       ! vertical mixing
+#if defined key_agrif
+      ! tracers sponge ... not available
+#endif
+                             CALL tra_ldf_adj( kstp )       ! lateral mixing
+
+!      IF( lk_zdfkpp )        CALL tra_kpp_adj( kstp )       ! KPP non-local tracer fluxes
+      IF( n_cla == 1     )   CALL tra_cla_adj( kstp )       ! Cross Land Advection (Update Hor. advection)
+
+                             CALL tra_adv_adj( kstp )       ! horizontal & vertical advection
+      IF( lk_tradmp      )   CALL tra_dmp_adj( kstp )       ! internal damping trends
+      ! advective (and/or diffusive) bottom boundary layer scheme ... currently not available
+      ! diffusive bottom boundary layer scheme ... currently not available
+
+      IF( lk_trabbc      )   CALL tra_bbc_adj( kstp )       ! bottom heat flux
+
+      IF( ln_traqsr      )   CALL tra_qsr_adj( kstp )       ! penetrative solar radiation qsr
+
+                             CALL tra_sbc_adj( kstp )       ! surface boundary condition
+
+                             ta_ad(:,:,:) = 0.0_wp            ! set tracer trends to zero
+                             sa_ad(:,:,:) = 0.0_wp
+
+      ! apply tracer assimilation increment ... not needed in adjoint
+#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 adjoint for the time being
+
+#endif
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Ocean physics update                (ua, va, ta, sa used as workspace)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !-----------------------------------------------------------------------
+      !  LATERAL PHYSICS
+      !-----------------------------------------------------------------------
+#if defined key_traldf_c2d
+      ! eddy induced velocity coefficient... not needed in tangent with lk_zdfcst_adj
+#endif
+      ! before slope of the lateral mixing... not needed in adjoint with lk_zdfcst_adj
+      !-----------------------------------------------------------------------
+      !  VERTICAL PHYSICS
+      !-----------------------------------------------------------------------
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+      ! mixed layer depth... not needed in adjoint with lk_zdfcst_adj
+      ! bottom friction... not needed in adjoint with lk_zdfcst_adj
+      ! double diffusive mixing ... not needed in adjoint with lk_zdfcst_adj
+      ! enhanced vertical eddy diffusivity ... not needed in adjoint with lk_zdfcst_adj
+      ! ! increase diffusivity at rivers mouths... not needed in tangent 
+      ! lk_zdfcst_adj:  Constant Kz read from the reference trajectory
+      ! Constant Kz (reset avt, avm[uv] to the background value)... not available
+      ! KPP closure scheme for Kz ... not available
+      ! TKE closure scheme for Kz ... not available
+      ! Richardson number dependent Kz  ... not available
+      !                                                     ! Vertical eddy viscosity and diffusivity coefficients
+                             CALL bn2_adj( tn, sn, tn_ad, sn_ad, rn2_ad )         ! now Brunt-Vaisala frequency
+!                             CALL bn2_adj( tb, sb, tb_ad, sb_ad, rn2b_ad )              ! before Brunt-Vaisala frequency
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      !  Ocean dynamics : ssh, wn, hdiv, rot                                 !
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                             CALL ssh_wzv_adj( kstp )         ! after ssh & vertical velocity
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Update data, open boundaries and Forcings
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! Output the initial state and forcings ... not needed in adjoint
+!      IF( lk_bdy     )   CALL bdy_dta_adj( kstp )         ! update dynamic and tracer data at unstructured open boundary
+      ! compute phase velocities at open boundaries ... not needed for the time being, to investigate whenever we do obc.
+      ! update dynamic and tracer data at open boundaries ... not needed for the time being, to investigate whenever we do obc.
+
+                             CALL sbc_adj ( kstp ) ! Sea boundary condition (including sea-ice) 
+      ! update 3D salinity data ... not needed in tangent
+      ! update 3D temperature data ... not needed in adjoint
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! 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_adj( kstp, indic, 0 )
+      IF( indic < 0      )   CALL ctl_stop( 'step_adj: indic < 0' )
+
+      ! close input  ocean restart file ... not needed in adjoint
+      ! write output ocean restart file... not needed in adjoint
+      ! write open boundary restart file... not needed in adjoint
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! 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 adjoint
+         ! trends: dynamics ... not needed in adjoint
+         ! trends: active tracers... not needed in adjoint
+         ! trends: Mixed-layer ... not needed in adjoint
+         ! trends: vorticity budget... not needed in adjoint
+         ! Surface pressure diagnostics... not needed in adjoint
+         ! Thermocline depth (20 degres isotherm depth)... not needed in adjoint
+         ! basin averaged diagnostics... not needed in adjoint
+         ! dynamical heigh diagnostics... not needed in adjoint
+         ! Fresh water budget diagnostics... not needed in adjoint
+         ! obs-minus-model (assimilation) diagnostics NOTE: may be better off outside this module
+         ! Poleward TRansports diagnostics... not needed in adjoint
+
+
+         !                                                 ! Outputs
+         ! ocean model: outputs... not needed in adjoint
+
+      ENDIF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Coupled mode
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      ! coupled mode : field exchanges ... not available for the next 20 years
+      !
+   END SUBROUTINE stp_adj
+
+   SUBROUTINE stp_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE example_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 09-03 (F. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE sbcssr_tam, ONLY: &
+         & qrp_tl, qrp_ad,  &
+         & erp_tl, erp_ad
+      USE sbcfwb_tam, ONLY: &
+         & a_fwb_tl,        & ! for before year.
+         & a_fwb_ad  ! for before year.
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt               ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::             &
+         & ji,               &  ! dummy loop indices
+         & jj,               &        
+         & jk,               &
+         & istp
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d             ! 2D seed for the random number generator
+      REAL(KIND=wp) ::       &
+         & zsp1    ,         &  ! scalar product involving the tangent routine
+         & zsp1_U  ,         &
+         & zsp1_V  ,         & 
+         & zsp1_T  ,         & 
+         & zsp1_S  ,         & 
+         & zsp1_SSH,         &   
+         & zsp2    ,         &  ! scalar product involving the adjoint routine
+         & zsp2_U  ,         &
+         & zsp2_V  ,         & 
+         & zsp2_T  ,         & 
+         & zsp2_S  ,         & 
+         & zsp2_SSH     
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zun_tlin ,        & ! Tangent input
+         & zvn_tlin ,        & ! Tangent input
+         & ztn_tlin ,        & ! Tangent input
+         & zsn_tlin ,        & ! Tangent input
+         & zun_tlout,        & ! Tangent output
+         & zvn_tlout,        & ! Tangent output
+         & ztn_tlout,        & ! Tangent output
+         & zsn_tlout,        & ! Tangent outpu
+         & zun_adin ,        & ! Adjoint input
+         & zvn_adin ,        & ! Adjoint input
+         & ztn_adin ,        & ! Adjoint input
+         & zsn_adin ,        & ! Adjoint input
+#if defined key_obc
+         & zub_adin ,        & ! Adjoint input
+         & zvb_adin ,        & ! Adjoint input
+         & ztb_adin ,        & ! Adjoint input
+         & zsb_adin ,        & ! Adjoint input
+         & zub_tlout ,        & ! Adjoint input
+         & zvb_tlout ,        & ! Adjoint input
+         & ztb_tlout ,        & ! Adjoint input
+         & zsb_tlout ,        & ! Adjoint input
+#endif
+         & zun_adout,        & ! Adjoint output
+         & zvn_adout,        & ! Adjoint output
+         & ztn_adout,        & ! Adjoint output
+         & zsn_adout,        & ! Adjoint output
+         & z3r                 ! 3D random field  
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zsshn_tlin  ,     & ! Tangent input
+         & zsshn_tlout ,     & ! Tangent input
+         & zsshn_adin  ,     & ! Adjoint output
+         & zsshn_adout ,     & ! Adjoint output
+#if defined key_obc
+         & zsshb_tlout ,     & ! Tangent input
+         & zsshb_adin  ,     & ! Tangent input
+#endif
+         & z2r                 ! 2D random field 
+
+      CHARACTER(LEN=14) ::   &
+         & cl_name
+
+      INTEGER ::             &
+         & jpert
+      INTEGER, PARAMETER :: jpertmax = 6
+
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zun_tlin(   jpi,jpj,jpk), zvn_tlin(   jpi,jpj,jpk), ztn_tlin(  jpi,jpj,jpk), &
+         & zsn_tlin(   jpi,jpj,jpk), zsshn_tlin( jpi,jpj    ), zun_tlout( jpi,jpj,jpk), &
+         & zvn_tlout(  jpi,jpj,jpk), ztn_tlout(  jpi,jpj,jpk), zsn_tlout( jpi,jpj,jpk), &
+         & zsshn_tlout(jpi,jpj    ), zun_adin(   jpi,jpj,jpk), zvn_adin(  jpi,jpj,jpk), &
+         & ztn_adin(   jpi,jpj,jpk), zsn_adin(   jpi,jpj,jpk), zsshn_adin(jpi,jpj    ), &
+         & zun_adout(  jpi,jpj,jpk), zvn_adout(  jpi,jpj,jpk), ztn_adout( jpi,jpj,jpk), &
+         & zsn_adout(  jpi,jpj,jpk), zsshn_adout(jpi,jpj    ), z2r(       jpi,jpj    ), &
+         & z3r(        jpi,jpj,jpk)                                                     &
+         & )
+    
+#if defined key_obc
+      ALLOCATE( zub_adin   (jpi,jpj,jpk), zvb_adin  (jpi,jpj,jpk) ,        &
+           &    ztb_adin   (jpi,jpj,jpk), zsb_adin  (jpi,jpj,jpk) ,        &
+           &    zub_tlout  (jpi,jpj,jpk), zvb_tlout (jpi,jpj,jpk) ,        &
+           &    ztb_tlout  (jpi,jpj,jpk), zsb_tlout (jpi,jpj,jpk) ,        &
+           &    zsshb_tlout(jpi,jpj)    , zsshb_adin(jpi,jpj)       )
+#endif
+      !==================================================================
+      ! 1) dx = ( un_tl, vn_tl, tn_tl, sn_tl, sshn_tl ) and 
+      !    dy = ( ..... )
+      !==================================================================
+
+
+      DO jpert = 1, jpertmax
+
+         !--------------------------------------------------------------------
+         ! Reset the tangent and adjoint variables
+         !--------------------------------------------------------------------
+         zun_tlin   (:,:,:) = 0.0_wp
+         zvn_tlin   (:,:,:) = 0.0_wp
+         ztn_tlin   (:,:,:) = 0.0_wp
+         zsn_tlin   (:,:,:) = 0.0_wp
+         zsshn_tlin (  :,:) = 0.0_wp
+         zun_tlout  (:,:,:) = 0.0_wp
+         zvn_tlout  (:,:,:) = 0.0_wp
+         ztn_tlout  (:,:,:) = 0.0_wp
+         zsn_tlout  (:,:,:) = 0.0_wp
+         zsshn_tlout(  :,:) = 0.0_wp
+         zun_adin   (:,:,:) = 0.0_wp
+         zvn_adin   (:,:,:) = 0.0_wp
+         ztn_adin   (:,:,:) = 0.0_wp
+         zsn_adin   (:,:,:) = 0.0_wp
+         zsshn_adin (  :,:) = 0.0_wp
+         zun_adout  (:,:,:) = 0.0_wp
+         zvn_adout  (:,:,:) = 0.0_wp
+         ztn_adout  (:,:,:) = 0.0_wp
+         zsn_adout  (:,:,:) = 0.0_wp
+         zsshn_adout(  :,:) = 0.0_wp
+         z3r        (:,:,:) = 0.0_wp
+         z2r        (  :,:) = 0.0_wp
+
+         !--------------------------------------------------------------------
+         ! Initialize the tangent input with random noise: dx
+         !--------------------------------------------------------------------
+       
+         IF ( (jpert == 1) .OR. (jpert == jpertmax) ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  iseed_2d(ji,jj) = - ( 596035 + &
+                     &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+               END DO
+            END DO
+            CALL grid_random( iseed_2d, z3r, 'U', 0.0_wp, stdu )
+            DO jk = 1, jpk
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     zun_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+         ENDIF
+         IF ( (jpert == 2) .OR. (jpert == jpertmax) ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  iseed_2d(ji,jj) = - ( 371836 + &
+                     &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+               END DO
+            END DO
+            CALL grid_random( iseed_2d, z3r, 'V', 0.0_wp, stdv ) 
+            DO jk = 1, jpk
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     zvn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+         ENDIF
+         IF ( (jpert == 3) .OR. (jpert == jpertmax) ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  iseed_2d(ji,jj) = - ( 284035 + &
+                     &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+               END DO
+            END DO
+            CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stdt )
+            DO jk = 1, jpk
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     ztn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+                  END DO
+               END DO
+            END DO 
+         ENDIF
+         IF ( (jpert == 4) .OR. (jpert == jpertmax) ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  iseed_2d(ji,jj) = - (  471426 + &
+                     &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+               END DO
+            END DO
+            CALL grid_random( iseed_2d, z3r, 'T', 0.0_wp, stds ) 
+            DO jk = 1, jpk
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     zsn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+         ENDIF
+         IF ( (jpert == 5) .OR. (jpert == jpertmax) ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  iseed_2d(ji,jj) = - ( 712035 + &
+                     &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+               END DO
+            END DO
+            CALL grid_random( iseed_2d, z2r, 'T', 0.0_wp, stdssh )
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsshn_tlin(ji,jj) = z2r(ji,jj)
+               END DO
+            END DO
+         ENDIF
+
+         IF (jpert>0) THEN
+
+            CALL     oce_tam_init( 1 )    ! allocate/initialize tl variables
+            CALL sbc_oce_tam_init( 1 )    
+            CALL sol_oce_tam_init( 1 )   
+            CALL trc_oce_tam_init( 1 )
+
+            qrp_tl = 0.0_wp
+            erp_tl = 0.0_wp
+
+            emp_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
+   
+            istp = nit000 - 1 
+            CALL  trj_rea( istp, 1 ) 
+            !--------------------------------------------------------------------
+            ! Initialize the tangent variables: dy^* = W dy
+            !--------------------------------------------------------------------
+
+            un_tl  (:,:,:) = zun_tlin   (:,:,:)
+            vn_tl  (:,:,:) = zvn_tlin   (:,:,:)
+            tn_tl  (:,:,:) = ztn_tlin   (:,:,:)
+            sn_tl  (:,:,:) = zsn_tlin   (:,:,:)
+            sshn_tl(  :,:) = zsshn_tlin (  :,:)
+
+#if defined key_pomme_r025
+            IF ( (jpert == 5) .OR. (jpert == jpertmax) ) THEN
+               !DO ji = 1, jpi
+               !   DO jj = 1, jpj
+               !      sshn_tl(ji,jj) = cos( (2.*rpi)*(FLOAT(ji)-0.5)/FLOAT(jpi) + rpi/2. ) &
+               !                     * sin( (2.*rpi)*(FLOAT(jj)-0.5)/FLOAT(jpj) ) / 100.
+               !   END DO
+               !END DO
+            
+               DO ji = 1, jpi
+                  DO jj = 1, jpj
+                     zsshn_tlin(ji,jj) = exp( -((float(ji)-float(jpi)/2.)/(float(jpi)/5.))**2 &
+                          -((float(jj)-float(jpj)/2.)/(float(jpj)/5.))**2 ) / 100. &
+                          * tmask(ji,jj,1)
+                  END DO
+               END DO
+               sshn_tl(:,:) = zsshn_tlin(:,:) 
+            ENDIF
+#endif
+
+            CALL     oce_tam_deallocate( 2 )    ! deallocate adj variables
+            CALL sbc_oce_tam_deallocate( 2 )   
+            CALL sol_oce_tam_deallocate( 2 ) 
+
+            !-----------------------------------------------------------------------
+            !  Initialization of the dynamics and tracer fields for the tangent
+            !-----------------------------------------------------------------------
+
+            CALL istate_init_tan 
+         
+            DO istp = nit000, nitend, 1
+               CALL stp_tan( istp )
+            END DO
+
+
+            zun_tlout  ( :,:,:) = un_tl   (:,:,:)
+            zvn_tlout  ( :,:,:) = vn_tl   (:,:,:)
+            ztn_tlout  ( :,:,:) = tn_tl   (:,:,:)
+            zsn_tlout  ( :,:,:) = sn_tl   (:,:,:)
+            zsshn_tlout(   :,:) = sshn_tl (  :,:)
+
+#if defined key_obc
+            zub_tlout  (:,:,:) = ub_tl  (:,:,:)
+            zvb_tlout  (:,:,:) = vb_tl  (:,:,:)
+            ztb_tlout  (:,:,:) = tb_tl  (:,:,:)
+            zsb_tlout  (:,:,:) = sb_tl  (:,:,:)
+            zsshb_tlout(:,:)   = sshb_tl(:,:)
+#endif
+
+            !--------------------------------------------------------------------
+            ! Initialize the adjoint variables: dy^* = W dy
+            !--------------------------------------------------------------------
+         
+            DO jk = 1, jpk
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     zun_adin(ji,jj,jk) = zun_tlout(ji,jj,jk) &
+                          &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                          &               * umask(ji,jj,jk) * wesp_u
+#if defined key_obc
+                     zub_adin(ji,jj,jk) = zub_tlout(ji,jj,jk) &
+                          &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                          &               * umask(ji,jj,jk) * wesp_u
+#endif
+                  END DO
+               END DO
+            END DO
+            
+            DO jk = 1, jpk
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     zvn_adin(ji,jj,jk) = zvn_tlout(ji,jj,jk) &
+                          &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+                          &               * vmask(ji,jj,jk) * wesp_u
+#if defined key_obc
+                     zvb_adin(ji,jj,jk) = zvb_tlout(ji,jj,jk) &
+                          &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) &
+                          &               * vmask(ji,jj,jk) * wesp_u
+#endif
+                  END DO
+               END DO
+            END DO
+
+            DO jk = 1, jpk
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     ztn_adin(ji,jj,jk) = ztn_tlout(ji,jj,jk) &
+                          &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                          &               * tmask(ji,jj,jk) * wesp_t(jk)
+#if defined key_obc
+                     ztb_adin(ji,jj,jk) = ztb_tlout(ji,jj,jk) &
+                          &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                          &               * tmask(ji,jj,jk) * wesp_t(jk)
+#endif
+                  END DO
+               END DO
+            END DO
+         
+            DO jk = 1, jpk
+               DO jj = nldj, nlej
+                  DO ji = nldi, nlei
+                     zsn_adin(ji,jj,jk) = zsn_tlout(ji,jj,jk) &
+                          &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                          &               * tmask(ji,jj,jk) * wesp_s(jk)
+#if defined key_obc
+                     zsb_adin(ji,jj,jk) = zsb_tlout(ji,jj,jk) &
+                          &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
+                          &               * tmask(ji,jj,jk) * wesp_s(jk)
+#endif
+                  END DO
+               END DO
+            END DO
+         
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zsshn_adin(ji,jj) = zsshn_tlout(ji,jj) &
+                       &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+                       &               * tmask(ji,jj,1) * wesp_ssh
+#if defined key_obc
+                  zsshb_adin(ji,jj) = zsshb_tlout(ji,jj) &
+                       &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) &
+                       &               * tmask(ji,jj,1) * wesp_ssh
+#endif
+               END DO
+            END DO
+            
+            !--------------------------------------------------------------------
+            ! Compute the scalar product: ( L dx )^T W dy
+            !--------------------------------------------------------------------
+         
+
+            zsp1_U    = DOT_PRODUCT( zun_tlout  , zun_adin    )
+            zsp1_V    = DOT_PRODUCT( zvn_tlout  , zvn_adin    )
+            zsp1_T    = DOT_PRODUCT( ztn_tlout  , ztn_adin    )
+            zsp1_S    = DOT_PRODUCT( zsn_tlout  , zsn_adin    )
+            zsp1_SSH  = DOT_PRODUCT( zsshn_tlout, zsshn_adin  )
+            
+            zsp1      = zsp1_U + zsp1_V + zsp1_T + zsp1_S + zsp1_SSH
+ 
+#if defined key_obc
+            zsp1_U    = DOT_PRODUCT( zub_tlout  , zub_adin    )
+            zsp1_V    = DOT_PRODUCT( zvb_tlout  , zvb_adin    )
+            zsp1_T    = DOT_PRODUCT( ztb_tlout  , ztb_adin    )
+            zsp1_S    = DOT_PRODUCT( zsb_tlout  , zsb_adin    )
+            zsp1_SSH  = DOT_PRODUCT( zsshb_tlout, zsshb_adin  )
+         
+            zsp1      = zsp1 + ( zsp1_U + zsp1_V + zsp1_T + zsp1_S + zsp1_SSH )
+#endif
+            !--------------------------------------------------------------------
+            ! Call the adjoint routine: dx^* = L^T dy^*
+            !--------------------------------------------------------------------
+            CALL     oce_tam_init( 2 )    ! allocate/initialize adj variables
+            CALL sbc_oce_tam_init( 2 )    
+            CALL sol_oce_tam_init( 2 )   
+            CALL trc_oce_tam_init( 2 )
+
+            qrp_ad = 0.0_wp
+            erp_ad = 0.0_wp
+            emp_ad(:,:) = 0.0_wp
+#if defined key_tradmp
+            strdmp_ad = 0.0_wp
+            ttrdmp_ad = 0.0_wp
+#endif
+            a_fwb_ad = 0.0_wp
+         
+            un_ad  (:,:,:) = zun_adin   (:,:,:)
+            vn_ad  (:,:,:) = zvn_adin   (:,:,:)
+            tn_ad  (:,:,:) = ztn_adin   (:,:,:)
+            sn_ad  (:,:,:) = zsn_adin   (:,:,:)
+            sshn_ad(  :,:) = zsshn_adin (  :,:)   
+         
+#if defined key_obc
+            ub_ad  (:,:,:) = zub_adin   (:,:,:)
+            vb_ad  (:,:,:) = zvb_adin   (:,:,:)
+            tb_ad  (:,:,:) = ztb_adin   (:,:,:)
+            sb_ad  (:,:,:) = zsb_adin   (:,:,:)
+            sshb_ad(:,:)   = zsshb_adin (:,:)   
+#endif
+
+            CALL     oce_tam_deallocate( 1 )    !deallocate tl variables
+            CALL sbc_oce_tam_deallocate( 1 )  
+            CALL sol_oce_tam_deallocate( 1 ) 
+            CALL trc_oce_tam_deallocate( 1 )  
+
+            DO istp = nitend, nit000, -1
+               CALL stp_adj(istp)
+            END DO
+         
+            CALL istate_init_adj
+         
+            zun_adout  ( :,:,:) = un_ad   (:,:,:)
+            zvn_adout  ( :,:,:) = vn_ad   (:,:,:)
+            ztn_adout  ( :,:,:) = tn_ad   (:,:,:)
+            zsn_adout  ( :,:,:) = sn_ad   (:,:,:)
+            zsshn_adout(   :,:) = sshn_ad (  :,:)
+            
+            zsp2_U    = DOT_PRODUCT( zun_tlin  , zun_adout )
+            zsp2_V    = DOT_PRODUCT( zvn_tlin  , zvn_adout )
+            zsp2_T    = DOT_PRODUCT( ztn_tlin  , ztn_adout )
+            zsp2_S    = DOT_PRODUCT( zsn_tlin  , zsn_adout )
+            zsp2_SSH  = DOT_PRODUCT( zsshn_tlin, zsshn_adout )
+         
+            zsp2      = zsp2_U + zsp2_V + zsp2_T + zsp2_S + zsp2_SSH
+  
+            CALL     oce_tam_deallocate( 2 )    !deallocate adj variables
+            CALL sbc_oce_tam_deallocate( 2 )    
+            CALL sol_oce_tam_deallocate( 2 ) 
+            CALL trc_oce_tam_deallocate( 2 )
+       
+            ! 14 char:'12345678901234'
+            SELECT CASE (jpert)
+            CASE(1)
+               cl_name = 'step_adj     U'
+            CASE(2)
+               cl_name = 'step_adj     V'
+            CASE(3)
+               cl_name = 'step_adj     T'
+            CASE(4)
+               cl_name = 'step_adj     S'
+            CASE(5)
+               cl_name = 'step_adj   SSH'
+            CASE(jpertmax)
+               cl_name = 'step_adj      '
+            END SELECT
+            CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+         endif
+      END DO
+
+      DEALLOCATE(                                 &
+         & zun_tlin   , zvn_tlin   , ztn_tlin   , &
+         & zsn_tlin   , zsshn_tlin , zun_tlout  , &
+         & zvn_tlout  , ztn_tlout  , zsn_tlout  , &
+         & zsshn_tlout, zun_adin   , zvn_adin   , &
+         & ztn_adin   , zsn_adin   , zsshn_adin , &
+         & zun_adout  , zvn_adout  , ztn_adout  , &
+         & zsn_adout  , zsshn_adout, z2r        , &
+         & z3r                                    &
+         & )
+
+   END SUBROUTINE stp_adj_tst
+#if defined key_tst_tlm
+   SUBROUTINE stp_tlm_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE example_tl_tst ***
+      !!
+      !! ** Purpose : Test the tangent linear 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 :
+      !!        ! 09-06 (F. Vigilant)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      USE sbcssr_tam, ONLY: &
+         & qrp_tl,erp_tl
+      USE sbcfwb_tam, ONLY: &
+         & a_fwb_tl           ! for before year.
+      USE step_c1d            ! Time stepping loop for the 1D configuration
+      USE tamtrj              ! writing out state trajectory  
+      USE lib_mpp,    ONLY: & ! distributed memory computing
+        & lk_mpp,           &
+        & mpp_max 
+      USE c1d,        ONLY: & ! 1D configuration
+        & lk_c1d
+      USE par_tlm,    ONLY: &
+        & tlm_bch,          &
+        & cur_loop,         &
+        & h_ratio
+      USE istate_mod
+      USE sshwzv             !  vertical velocity
+      USE sbc_oce           , ONLY: & ! ocean dynamics and tracers variables
+        & emp,              &
+        & emps
+      USE tamctl,         ONLY: & ! Control parameters
+       & numtan, numtan_sc
+      USE step
+      !USE step_cpd
+      !USE step_tam_cpd
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt               ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::             &
+         & ji,               &  ! dummy loop indices
+         & jj,               &        
+         & jk,               &
+         & istp,             &
+         & pgamma,           &  ! control the number of pertubation loops
+         & igamma,           &
+         & nit_loop
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d             ! 2D seed for the random number generator
+      REAL(KIND=wp) ::       &
+         & zsp1, zsp2, zsp3, zzsp,                   &  ! scalar product
+         & zsp1_U, zsp1_V, zsp1_T, zsp1_S, zsp1_SSH, &   
+         & zsp2_U, zsp2_V, zsp2_T, zsp2_S, zsp2_SSH, &
+         & zsp3_U, zsp3_V, zsp3_T, zsp3_S, zsp3_SSH, &
+         & zzsp_U, zzsp_V, zzsp_T, zzsp_S, zzsp_SSH, &
+         & gamma,                                    &
+         & 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   ,        &
+         & sa_tmp   ,        &
+         & zun_tlin ,        & ! Pertubation input
+         & zvn_tlin ,        & ! Pertubation input
+         & ztn_tlin ,        & ! Pertubation input
+         & zsn_tlin ,        & ! Pertubation input
+         & zun_out  ,        & ! Direct output
+         & zvn_out  ,        & ! Direct output
+         & ztn_out  ,        & ! Direct output
+         & zsn_out  ,        & ! Direct output
+         & zun_wop  ,        & ! Direct without pertubation output
+         & zvn_wop  ,        & ! Direct without pertubation output
+         & ztn_wop  ,        & ! Direct without pertubation output
+         & zsn_wop  ,        & ! Direct without pertubation output
+         & z3r                  ! 3D random field  
+      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
+         & emp_tmp,              &
+         & emps_tmp,             &
+         & sshn_tmp ,             &
+         & zsshn_tlin  ,     & ! Pertubation input
+         & zsshn_out   ,     & ! Direct output
+         & zsshn_wop    ,     & ! Direct without pertubation output
+         & z2r                 ! 2D random field 
+ 
+      CHARACTER(LEN=14)   :: cl_name
+      CHARACTER (LEN=128) :: file_out, file_wop, file_wop2, file_xdx
+      CHARACTER (LEN=90)  :: FMT
+
+      REAL(KIND=wp), DIMENSION(100):: &
+         & zscu   , zscv   , zsct   , zscs   , zscssh, &
+         & zscerru, zscerrv, zscerrt, zscerrs, zscerrssh
+      INTEGER, DIMENSION(100)::       &
+         & iiposu, iiposv, iipost, iiposs, iiposssh, &
+         & ijposu, ijposv, ijpost, ijposs, ijposssh, &
+         & ikposu, ikposv, ikpost, ikposs
+      INTEGER::                &
+         & ii,                 &
+         & isamp=40,           &
+         & jsamp=40,           &
+         & ksamp=10,           &
+         & numsctlm
+     REAL(KIND=wp), DIMENSION(jpi,jpj,jpk) :: &
+         & zerru, zerrv, zerrt, zerrs            ! Pertubation input
+      REAL(KIND=wp), DIMENSION(jpi,jpj)    :: &
+         & zerrssh                               ! Pertubation input
+      INTEGER ::               &
+         & jdir, jdirmax=6                          ! Perturbation direction (U, V, T, S, SSH, all)
+
+      ! Allocate memory
+
+      ALLOCATE( &
+         & zun_tlin(   jpi,jpj,jpk),     &
+         & zvn_tlin(   jpi,jpj,jpk),     &
+         & ztn_tlin(   jpi,jpj,jpk),     &
+         & zsn_tlin(   jpi,jpj,jpk),     &
+         & zsshn_tlin( jpi,jpj    ),     &
+         & zun_out(    jpi,jpj,jpk),     &
+         & zvn_out(    jpi,jpj,jpk),     &
+         & ztn_out(    jpi,jpj,jpk),     &
+         & zsn_out(    jpi,jpj,jpk),     &
+         & zsshn_out(  jpi,jpj    ),     &
+         & zun_wop(    jpi,jpj,jpk),     &
+         & zvn_wop(    jpi,jpj,jpk),     &
+         & ztn_wop(    jpi,jpj,jpk),     &
+         & zsn_wop(    jpi,jpj,jpk),     &
+         & zsshn_wop(  jpi,jpj    ),     &
+         & z2r(        jpi,jpj    ),     &
+         & z3r(        jpi,jpj,jpk),     &
+         & emp_tmp(    jpi,jpj    ),     &
+         & emps_tmp(   jpi,jpj    ),     &
+         & ta_tmp(     jpi,jpj,jpk),     &
+         & sa_tmp(     jpi,jpj,jpk),     &
+         & sshn_tmp(    jpi,jpj   )      &  
+         & )
+
+      !--------------------------------------------------------------------
+      ! Reset the scalar
+      !--------------------------------------------------------------------
+      zscu   (:) = 0.0_wp
+      zscv   (:) = 0.0_wp
+      zsct   (:) = 0.0_wp
+      zscs   (:) = 0.0_wp
+      zscssh (:) = 0.0_wp
+
+      iiposu   (:) = 0
+      iiposv   (:) = 0
+      iipost   (:) = 0
+      iiposs   (:) = 0
+      iiposssh (:) = 0
+      ijposu   (:) = 0
+      ijposv   (:) = 0
+      ijpost   (:) = 0
+      ijposs   (:) = 0
+      ijposssh (:) = 0
+      ikposu   (:) = 0
+      ikposv   (:) = 0
+      ikpost   (:) = 0
+      ikposs   (:) = 0
+
+      zscerru   (:) = 0.0_wp
+      zscerrv   (:) = 0.0_wp
+      zscerrt   (:) = 0.0_wp
+      zscerrs   (:) = 0.0_wp
+      zscerrssh (:) = 0.0_wp
+
+      zerru   (:,:,:) = 0.0_wp
+      zerrv   (:,:,:) = 0.0_wp
+      zerrt   (:,:,:) = 0.0_wp
+      zerrs   (:,:,:) = 0.0_wp
+      zerrssh (:,:) = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent variables
+      !--------------------------------------------------------------------
+      zun_tlin   ( :,:,:) = 0.0_wp
+      zvn_tlin   ( :,:,:) = 0.0_wp
+      ztn_tlin   ( :,:,:) = 0.0_wp
+      zsn_tlin   ( :,:,:) = 0.0_wp
+      zsshn_tlin (   :,:) = 0.0_wp
+      z3r        ( :,:,:) = 0.0_wp
+      z2r        (   :,:) = 0.0_wp
+
+      !--------------------------------------------------------------------
+      ! Output filename Xn=F(X0)
+      !--------------------------------------------------------------------
+!!!!      CALL tlm_namrd
+      gamma = h_ratio
+      file_wop='trj_wop_step'
+      file_xdx='trj_xdx_step'
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+      jdir = jdirmax
+       IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+          IF (( jdir .EQ. 1 ) .OR. ( jdir .EQ. jdirmax ) ) THEN
+             CALL grid_rd_sd( 596035, z3r,  'U', 0.0_wp, stdu)
+             DO jk = 1, jpk
+                DO jj = nldj, nlej
+                   DO ji = nldi, nlei
+                      zun_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+                   END DO
+                END DO
+             END DO 
+
+          ENDIF
+          IF (( jdir .EQ. 2 ) .OR. ( jdir .EQ. jdirmax ) ) THEN
+             CALL grid_rd_sd( 371836, z3r,  'V', 0.0_wp, stdv)
+             DO jk = 1, jpk
+                DO jj = nldj, nlej
+                   DO ji = nldi, nlei
+                      zvn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+                   END DO
+                END DO
+             END DO
+
+          ENDIF
+          IF (( jdir .EQ. 3 ) .OR. ( jdir .EQ. jdirmax ) ) THEN
+          CALL grid_rd_sd( 284035, z3r,  'T', 0.0_wp, stdt)
+             DO jk = 1, jpk
+                DO jj = nldj, nlej
+                   DO ji = nldi, nlei
+                      ztn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+                   END DO
+                END DO
+             END DO
+
+          ENDIF
+          IF (( jdir .EQ. 4 ) .OR. ( jdir .EQ. jdirmax ) ) THEN
+             CALL grid_rd_sd( 471426, z3r,  'T', 0.0_wp, stds)
+             DO jk = 1, jpk
+                DO jj = nldj, nlej
+                   DO ji = nldi, nlei
+                      zsn_tlin(ji,jj,jk) = z3r(ji,jj,jk)
+                   END DO
+                END DO
+             END DO  
+
+          ENDIF
+          IF (( jdir .EQ. 5 ) .OR. ( jdir .EQ. jdirmax ) ) THEN
+             CALL grid_rd_sd( 712035, z2r,'T', 0.0_wp, stdssh)
+             DO jj = nldj, nlej
+                DO ji = nldi, nlei
+                   zsshn_tlin(ji,jj) = z2r(ji,jj)
+                END DO
+             END DO
+
+          ENDIF
+     ENDIF 
+     IF ( tlm_bch /= 2 )  CALL istate_p 
+
+         !--------------------------------------------------------------------
+         !  Open File to save scalar result
+         !--------------------------------------------------------------------
+
+      ! 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 ( 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
+           ENDIF
+        ENDIF
+
+        IF (( cur_loop .NE. 0) .OR. ( gamma .NE. 0.0_wp) )THEN
+           zun_tlin(:,:,:) = gamma * zun_tlin(:,:,:)
+           un(:,:,:)       = un(:,:,:) + zun_tlin(:,:,:)
+
+           zvn_tlin(:,:,:) = gamma * zvn_tlin(:,:,:)
+           vn(:,:,:)        = vn(:,:,:) + zvn_tlin(:,:,:)
+
+           ztn_tlin(:,:,:) = gamma * ztn_tlin(:,:,:)
+           tn(:,:,:)        = tn(:,:,:) + ztn_tlin(:,:,:)
+
+           zsn_tlin(:,:,:) = gamma * zsn_tlin(:,:,:)
+           sn(:,:,:)        = sn(:,:,:) + zsn_tlin(:,:,:)
+
+           zsshn_tlin(:,:)   = gamma * zsshn_tlin(:,:)
+           sshn (:,:)        = sshn (:,:) + zsshn_tlin(:,:)
+        ENDIF 
+ 
+        IF( .NOT. lk_vvl ) CALL ssh_wzv(nit000, 1) 
+
+        !--------------------------------------------------------------------
+        !  Compute the direct model F(X0,t=n) = Xn
+        !--------------------------------------------------------------------
+        IF ( tlm_bch /= 2 )  THEN
+        DO istp = nit000, nitend, 1
+           CALL stp( istp )
+        END DO
+        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 ( tlm_bch == 2 ) THEN        
+
+           !--------------------------------------------------------------------
+           ! Initialize the tangent variables: dy^* = W dy  
+           !--------------------------------------------------------------------
+           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
+
+           CALL  trj_rea( nit000-1, 1 ) 
+
+           un_tl  (:,:,:) = zun_tlin   (:,:,:)
+           vn_tl  (:,:,:) = zvn_tlin   (:,:,:)
+           tn_tl  (:,:,:) = ztn_tlin   (:,:,:)
+           sn_tl  (:,:,:) = zsn_tlin   (:,:,:)
+           sshn_tl(  :,:) = zsshn_tlin (  :,:)
+ 
+
+           !-----------------------------------------------------------------------
+           !  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
+       
+           !--------------------------------------------------------------------
+           ! Compute the scalar product: ( L(t0,tn) gamma dx0 ) )
+           !--------------------------------------------------------------------
+
+           zsp2_U    = DOT_PRODUCT( un_tl  , un_tl    )
+           zsp2_V    = DOT_PRODUCT( vn_tl  , vn_tl    )
+           zsp2_T    = DOT_PRODUCT( tn_tl  , tn_tl    )
+           zsp2_S    = DOT_PRODUCT( sn_tl  , sn_tl    )
+           zsp2_SSH  = DOT_PRODUCT( sshn_tl, sshn_tl  )
+
+           zsp2      = zsp2_U + zsp2_V + zsp2_T + zsp2_S + zsp2_SSH
+  
+           !--------------------------------------------------------------------
+           !  Storing data
+           !--------------------------------------------------------------------
+           CALL trj_rd_spl(file_wop)
+           zun_wop   (:,:,:) = un   (:,:,:)
+           zvn_wop   (:,:,:) = vn   (:,:,:)
+           ztn_wop   (:,:,:) = tn   (:,:,:)
+           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 
+           ! 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 jk = 1, jpk
+              DO jj = 1, jpj
+                 DO ji = 1, jpi
+                    zun_out   (ji,jj,jk) = zun_out    (ji,jj,jk) - zun_wop  (ji,jj,jk)
+                    zun_wop   (ji,jj,jk) = zun_out    (ji,jj,jk) - un_tl    (ji,jj,jk)
+                    IF (  un_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                       & zerru(ji,jj,jk) = zun_out(ji,jj,jk)/un_tl(ji,jj,jk)
+                       IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                       &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                       &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                          ii = ii+1
+                          iiposu(ii) = ji
+                          ijposu(ii) = jj
+                          ikposu(ii) = jk
+                          IF ( INT(umask(ji,jj,jk)) .NE. 0)  THEN
+                             zscu (ii) =  zun_out(ji,jj,jk)
+                             zscerru (ii) = ( zerru(ji,jj,jk) - 1.0_wp ) / gamma
+                          ENDIF
+                    ENDIF
+                 END DO
+              END DO
+           END DO
+           ii=0      
+           DO jk = 1, jpk
+              DO jj = 1, jpj
+                 DO ji = 1, jpi
+                    zvn_out   (ji,jj,jk) = zvn_out    (ji,jj,jk) - zvn_wop  (ji,jj,jk)
+                    zvn_wop   (ji,jj,jk) = zvn_out    (ji,jj,jk) - vn_tl    (ji,jj,jk)
+                    IF (  vn_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                    & zerrv(ji,jj,jk) = zvn_out(ji,jj,jk)/vn_tl(ji,jj,jk)
+                       IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                       &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                       &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                          ii = ii+1
+                          iiposv(ii) = ji
+                          ijposv(ii) = jj
+                          ikposv(ii) = jk
+                          IF ( INT(vmask(ji,jj,jk)) .NE. 0)  THEN
+                             zscv (ii) =  zvn_out    (ji,jj,jk)
+                             zscerrv (ii) =  ( zerrv(ji,jj,jk) - 1.0_wp ) / gamma
+                          ENDIF
+                       ENDIF
+                 END DO
+              END DO
+           END DO
+           ii=0
+           DO jk = 1, jpk
+              DO jj = 1, jpj
+                 DO ji = 1, jpi
+                    ztn_out   (ji,jj,jk) = ztn_out   (ji,jj,jk) - ztn_wop   (ji,jj,jk)
+                    ztn_wop   (ji,jj,jk) = ztn_out   (ji,jj,jk) - tn_tl     (ji,jj,jk)
+                    IF (  tn_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                    & zerrt(ji,jj,jk) = ztn_out(ji,jj,jk)/tn_tl(ji,jj,jk)
+                       IF( (MOD(ji, isamp) .EQ. 0) .AND. &
+                       &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                       &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                          ii = ii+1
+                          iipost(ii) = ji
+                          ijpost(ii) = jj
+                          ikpost(ii) = jk
+                          IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+                             zsct (ii) =  ztn_out    (ji,jj,jk)
+                             zscerrt (ii) =  ( zerrt(ji,jj,jk) - 1.0_wp ) / gamma
+                          ENDIF
+                       ENDIF
+                 END DO
+              END DO
+           END DO
+           ii=0
+           DO jk = 1, jpk
+              DO jj = 1, jpj
+                 DO ji = 1, jpi
+                    zsn_out   (ji,jj,jk) = zsn_out   (ji,jj,jk) - zsn_wop   (ji,jj,jk)
+                    zsn_wop   (ji,jj,jk) = zsn_out   (ji,jj,jk) - sn_tl     (ji,jj,jk)
+                    IF (  sn_tl(ji,jj,jk) .NE. 0.0_wp ) &
+                    & zerrs(ji,jj,jk) = zsn_out(ji,jj,jk)/sn_tl(ji,jj,jk)
+                       IF( (MOD(ji, isamp) .EQ. 0) .AND. & 
+                       &   (MOD(jj, jsamp) .EQ. 0) .AND. &
+                       &   (MOD(jk, ksamp) .EQ. 0)     ) THEN
+                          ii = ii+1
+                          iiposs(ii) = ji
+                          ijposs(ii) = jj
+                          ikposs(ii) = jk
+                          IF ( INT(tmask(ji,jj,jk)) .NE. 0)  THEN
+                             zscs (ii) =  zsn_out    (ji,jj,jk)
+                             zscerrs (ii) =  ( zerrs(ji,jj,jk) - 1.0_wp ) / gamma
+                          ENDIF
+                       ENDIF
+                 END DO
+              END DO
+           END DO
+           ii=0
+           jk=1
+           DO jj = 1, jpj
+              DO ji = 1, jpi
+                 zsshn_out (ji,jj   ) = zsshn_out (ji,jj   ) - zsshn_wop (ji,jj   )
+                 zsshn_wop (ji,jj   ) = zsshn_out (ji,jj   ) - sshn_tl   (ji,jj   )
+                 IF (  sshn_tl(ji,jj) .NE. 0.0_wp ) &
+                 & zerrssh(ji,jj) = zsshn_out(ji,jj)/sshn_tl(ji,jj)
+                    IF( (MOD(ji, isamp) .EQ. 0) .AND. & 
+                    &   (MOD(jj, jsamp) .EQ. 0) ) THEN
+                       ii = ii+1
+                       iiposssh(ii) = ji
+                       ijposssh(ii) = jj
+                       IF ( INT(tmask(ji,jj,jk)) .NE. 0 ) THEN
+                          zscssh (ii) =  zsshn_out    (ji,jj)
+                          zscerrssh (ii) =  ( zerrssh(ji,jj) - 1.0_wp ) / gamma
+                       ENDIF
+                    ENDIF
+              END DO
+           END DO
+
+           zsp1_U    = DOT_PRODUCT( zun_out  , zun_out    )
+           zsp1_V    = DOT_PRODUCT( zvn_out  , zvn_out    )
+           zsp1_T    = DOT_PRODUCT( ztn_out  , ztn_out    )
+           zsp1_S    = DOT_PRODUCT( zsn_out  , zsn_out    )
+           zsp1_SSH  = DOT_PRODUCT( zsshn_out, zsshn_out  )
+
+           zsp1      = zsp1_U + zsp1_V + zsp1_T + zsp1_S + zsp1_SSH
+
+           zsp3_U    = DOT_PRODUCT( zun_wop  , zun_wop    )
+           zsp3_V    = DOT_PRODUCT( zvn_wop  , zvn_wop    )
+           zsp3_T    = DOT_PRODUCT( ztn_wop  , ztn_wop    )
+           zsp3_S    = DOT_PRODUCT( zsn_wop  , zsn_wop    )
+           zsp3_SSH  = DOT_PRODUCT( zsshn_wop, zsshn_wop  )
+
+           zsp3      = zsp3_U + zsp3_V + zsp3_T + zsp3_S + zsp3_SSH
+
+         !--------------------------------------------------------------------
+         ! Print the linearization error En - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name = 'step_tam:En   '
+         zzsp     = SQRT(zsp3)
+         zzsp_U   = SQRT(zsp3_U)
+         zzsp_V   = SQRT(zsp3_V)
+         zzsp_T   = SQRT(zsp3_T)
+         zzsp_S   = SQRT(zsp3_S)
+         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 )
+
+         CALL prntst_tlm( 'U             ', kumadt, zzsp_U  , h_ratio )
+         CALL prntst_tlm( 'V             ', kumadt, zzsp_V  , h_ratio )
+         CALL prntst_tlm( 'T             ', kumadt, zzsp_T  , h_ratio )
+         CALL prntst_tlm( 'S             ', kumadt, zzsp_S  , h_ratio )
+         CALL prntst_tlm( 'SSH           ', kumadt, zzsp_SSH, h_ratio )
+
+         !--------------------------------------------------------------------
+         ! Compute TLM norm2
+         !--------------------------------------------------------------------
+         zzsp     =  SQRT(zsp2)
+         zzsp_U   =  SQRT(zsp2_U)
+         zzsp_V   =  SQRT(zsp2_V)
+         zzsp_T   =  SQRT(zsp2_T)
+         zzsp_S   =  SQRT(zsp2_S)
+         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 )
+
+         CALL prntst_tlm( 'U             ', kumadt, zzsp_U  , h_ratio )
+         CALL prntst_tlm( 'V             ', kumadt, zzsp_V  , h_ratio )
+         CALL prntst_tlm( 'T             ', kumadt, zzsp_T  , h_ratio )
+         CALL prntst_tlm( 'S             ', kumadt, zzsp_S  , h_ratio )
+         CALL prntst_tlm( 'SSH           ', kumadt, zzsp_SSH, h_ratio )
+
+         !--------------------------------------------------------------------
+         ! Print the linearization error Nn - norme 2
+         !--------------------------------------------------------------------
+         ! 14 char:'12345678901234'
+         cl_name = 'step_tam:Nn   '
+         zzsp     =  SQRT(zsp1)
+         zzsp_U   =  SQRT(zsp1_U)
+         zzsp_V   =  SQRT(zsp1_V)
+         zzsp_T   =  SQRT(zsp1_T)
+         zzsp_S   =  SQRT(zsp1_S)
+         zzsp_SSH =  SQRT(zsp1_SSH)
+!         zzsp      = zzsp_U + zzsp_V + zzsp_T + zzsp_S + zzsp_SSH
+         CALL prntst_tlm( cl_name, kumadt, zzsp, h_ratio )
+
+         CALL prntst_tlm( 'U             ', kumadt, zzsp_U  , h_ratio )
+         CALL prntst_tlm( 'V             ', kumadt, zzsp_V  , h_ratio )
+         CALL prntst_tlm( 'T             ', kumadt, zzsp_T  , h_ratio )
+         CALL prntst_tlm( 'S             ', kumadt, zzsp_S  , h_ratio )
+         CALL prntst_tlm( 'SSH           ', kumadt, zzsp_SSH, h_ratio )
+
+         zgsp3    = SQRT( zsp3/zsp2 )
+         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, zgsp1_T ,zgsp4_T, zgsp5_T,zgsp1_S,zgsp4_S,zgsp5_S!,
+         !--------------------------------------------------------------------
+         ! 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 = 'step '
+         IF (lwp) THEN
+            DO ii=1, 100, 1
+               IF ( zscu(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscu     ', &
+                    & cur_loop, h_ratio,  iiposu(ii), ijposu(ii), ikposu(ii), zscu(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscv(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscv     ', &
+                    & cur_loop, h_ratio,  iiposv(ii), ijposv(ii), ikposv(ii), zscv(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zsct(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zsct     ', &
+                    & cur_loop, h_ratio,  iipost(ii), ijpost(ii), ikpost(ii), zsct(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscs(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscs    ', &
+                    & cur_loop, h_ratio,  iiposs(ii), ijposs(ii), ikposs(ii), zscs(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscssh(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscssh  ', &
+                    & cur_loop, h_ratio,  iiposssh(ii), ijposssh(ii), ijposssh(ii), zscssh(ii)
+            ENDDO
+
+            DO ii=1, 100, 1
+               IF ( zscerru(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerru  ', &
+                    & cur_loop, h_ratio,  iiposu(ii), ijposu(ii), ikposu(ii), zscerru(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrv(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrv  ', &
+                    & cur_loop, h_ratio,  iiposv(ii), ijposv(ii), ikposv(ii), zscerrv(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrt(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrt  ', &
+                    & cur_loop, h_ratio,  iipost(ii), ijpost(ii), ikpost(ii), zscerrt(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrs(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerrs ', &
+                    & cur_loop, h_ratio,  iiposs(ii), ijposs(ii), ikposs(ii), zscerrs(ii)
+            ENDDO
+            DO ii=1, 100, 1
+               IF ( zscerrssh(ii) .NE. 0.0_wp ) WRITE(numtan_sc,FMT) cl_name, 'zscerssh', &
+                    & cur_loop, h_ratio,  iiposssh(ii), ijposssh(ii), ijposssh(ii), zscerrssh(ii)
+            ENDDO
+            ! write separator
+            WRITE(numtan_sc,"(A4)") '===='
+         ENDIF
+
+      ENDIF
+
+      DEALLOCATE(       &
+         & zun_tlin   , &
+         & zvn_tlin   , &
+         & ztn_tlin   , &
+         & zsn_tlin   , &
+         & zsshn_tlin , &
+         & zun_out    , &
+         & zvn_out    , &
+         & ztn_out    , &
+         & zsn_out    , &
+         & zsshn_out  , &
+         & zun_wop    , &
+         & zvn_wop    , &
+         & ztn_wop    , &
+         & zsn_wop    , &
+         & zsshn_wop  , &
+         & z2r        , &
+         & z3r          &
+         & )
+
+   END SUBROUTINE stp_tlm_tst
+
+      !!----------------------------------------------------------------------
+
+   SUBROUTINE asm_trj_wop_tasa_wri
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE asm_trj_wop_tasa_wri ***
+      !!
+      !! ** Purpose : Write to file the model state trajectory for use with
+      !!              4D-Var.
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!
+      !! History : 
+      !!        ! 09-07 (F. Vigilant) 
+      !!-----------------------------------------------------------------------
+      !! *Module udes
+      USE iom 
+      USE oce           , ONLY: & ! ocean dynamics and tracers variables
+      & tn, sn 
+      !! * Arguments
+      !! * Local declarations
+      INTEGER :: &
+         & inum                  ! File unit number
+      CHARACTER (LEN=50) :: &
+         & filename
+         ! Define the output file  
+         filename='trj_wop_tasa'       
+         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( 1, 1, inum, 'tn'   , tn  )
+         CALL iom_rstput( 1, 1, inum, 'sn'   , sn  )
+         CALL iom_close( inum )
+   END SUBROUTINE asm_trj_wop_tasa_wri
+
+   SUBROUTINE asm_trj_wop_tasa_rd
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE asm_trj_wop_tasa_rd ***
+      !!
+      !! ** Purpose : Read file the model state trajectory for use with
+      !!              4D-Var.
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!
+      !! History : 
+      !!        ! 09-07 (F. Vigilant) 
+      !!-----------------------------------------------------------------------
+      !! *Module udes
+      USE iom                 ! I/O module
+      USE oce           , ONLY: & ! ocean dynamics and tracers variables
+      & tn, sn 
+      !! * Arguments
+      !! * Local declarations
+      INTEGER :: &
+         & inum                  ! File unit number
+      CHARACTER (LEN=50) :: &
+         & filename
+         ! Define the output file  
+         filename='trj_wop_tasa'       
+         WRITE(filename, FMT='(A,A)' ) TRIM( filename ), '.nc'
+         filename = TRIM( filename )
+         CALL iom_open( filename, inum)
+
+         ! Output trajectory fields
+         CALL iom_get( inum, jpdom_data, 'tn'   , tn, 1  )
+         CALL iom_get( inum, jpdom_data, 'sn'   , sn, 1  )
+         CALL iom_close( inum )
+   END SUBROUTINE asm_trj_wop_tasa_rd
+
+
+   !!======================================================================
+#endif
+#endif
+END MODULE step_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/stpctl_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/stpctl_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/stpctl_tam.F90	(revision 2578)
@@ -0,0 +1,308 @@
+MODULE stpctl_tam
+#ifdef key_tam
+   !!==============================================================================
+   !!                       ***  MODULE  stpctl_tam  ***
+   !! Ocean run control :  gross check of the ocean time stepping
+   !!                      Tangent and adjoint module
+   !!==============================================================================
+   !! History of the direct module:
+   !!            OPA  ! 1991-03  (G. Madec) Original code
+   !!            6.0  ! 1992-06  (M. Imbard)
+   !!            8.0  ! 1997-06  (A.M. Treguier)
+   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
+   !!            2.0  ! 2009-07  (G. Madec)  Add statistic for time-spliting
+   !! History of the T&A module:
+   !!            3.0  ! 2009-??  (A. Vidard) orignal version
+   !!            3.2  ! 2010-04  (A. Vidard) nemo3.2 update 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   stp_ctl_tan      : Control the run
+   !!   stp_ctl_adj      : Control the run
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & ctl_opn,             &
+      & lwp,                 &
+      & numout,              & 
+      & numstp,              & 
+      & numsol,              &
+      & nwrite,              &
+      & cform_err,           &
+      & nit000
+   USE par_oce       , ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 & 
+      & jpk
+   USE oce_tam       , ONLY: & ! ocean dynamics and tracers variables
+      & un_tl,               &
+      & vn_tl,               &
+      & tn_tl,               &
+      & sn_tl,               &
+      & un_ad,               &
+      & vn_ad,               &
+      & tn_ad,               &
+      & sn_ad
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & umask,               &
+      & vmask,               &
+      & tmask,               &
+      & nimpp,               &
+      & njmpp,               &
+      & narea
+   USE sol_oce       , ONLY: & ! ocean space and time domain variables 
+      & eps,                 &
+      & epsr,                &
+      & niter,               &
+      & res
+   USE lib_mpp       , ONLY: & ! distributed memory computing
+      & lk_mpp,              &
+      & mpp_max,             &
+      & mpp_maxloc
+   USE dynspg_oce    , ONLY: & ! pressure gradient schemes 
+      & lk_dynspg_flt
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC stp_ctl_tan           ! routine called by steptan.F90
+   PUBLIC stp_ctl_adj           ! routine called by stepadj.F90
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE stp_ctl_tan( kt, kindic, ksign )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE stp_ctl_tan  ***
+      !!                     
+      !! ** Purpose of the direct routine:   Control the run
+      !!
+      !! ** Method  : - Save the time step in numstp
+      !!              - Print it each 50 time steps
+      !!              - Print solver statistics in numsol 
+      !!              - Stop the run IF problem for the solver ( indec < 0 )
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+      INTEGER, INTENT( in ) ::   ksign
+      INTEGER, INTENT( inout ) ::   kindic  ! indicator of solver convergence
+
+      !! * local declarations
+      INTEGER  ::   ji, jj, jk                 ! dummy loop indices
+      INTEGER  ::   ii, ij, ik                 ! temporary integers
+      REAL(wp) ::   zumax, zvmax, ztmax, zsmax ! temporary scalars
+      INTEGER, DIMENSION(3) ::   ilocu         ! 
+      INTEGER, DIMENSION(3) ::   ilocv         ! 
+      INTEGER, DIMENSION(3) ::   iloct         ! 
+      INTEGER, DIMENSION(3) ::   ilocs         !  
+      CHARACTER(len=80) :: clname
+      LOGICAL :: lfirst =.TRUE.
+      IF( kt == nit000 .AND. lwp .AND. lfirst ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'stp_ctl_tan : time-stepping control'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         ! open time.step file
+         clname = 'time_tan.step'
+         CALL ctl_opn( numstp, clname, 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
+         lfirst = .FALSE.
+      ENDIF
+
+      IF(lwp) WRITE(numstp, '(1x, i8)' ) kt        !* save the current time step in numstp
+      IF(lwp) REWIND(numstp)                       !  --------------------------
+
+      ! elliptic solver statistics (if required)
+      ! --------------------------
+      IF( lk_dynspg_flt ) THEN
+      ! Solver
+      IF(lwp) WRITE(numsol,9200) kt, niter, res, SQRT(epsr)/eps
+
+      ! Islands (if exist)
+!!!!AV TO DO      IF( lk_isl )   CALL isl_stp_ctl_tan( kt, kindic )
+
+
+      ! Output in numwso and numwvo IF kindic<0
+      ! ---------------------------------------
+      !    (i.e. problem for the solver)
+      IF( kindic < 0 ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*) ' stpctl_tan: the elliptic solver DO not converge or explode'
+            WRITE(numout,*) ' ========= '
+            WRITE(numout,9200) kt, niter, res, sqrt(epsr)/eps
+            WRITE(numout,*)
+           WRITE(numout,*) ' =========  *******************************'
+         ENDIF
+      ENDIF
+      ENDIF
+
+9200  FORMAT(' it :', i8, ' niter :', i4, ' res :',e30.18,' b :',e30.18)
+
+      ! Test maximum of tangent fields
+      ! ------------------------
+
+      ! 1. zonal velocity
+      ! -----------------
+
+      !! zumax = MAXVAL( ABS( un_tl(:,:,:) ) )   ! slower than the following loop on NEC SX5
+      zumax = 0.e0
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zumax = MAX(zumax,ABS(un_tl(ji,jj,jk)))
+          END DO 
+        END DO 
+      END DO        
+      IF( lk_mpp )   CALL mpp_max( zumax )       ! max over the global domain
+
+      IF( MOD( kt, nwrite ) == 1 .AND. lwp ) WRITE(numout,*) ' ==>> time-step= ',kt,' abs(U) max: ', zumax
+      IF( zumax > 50._wp) THEN
+         IF( lk_mpp ) THEN
+            CALL mpp_maxloc(ABS(un_tl),umask,zumax,ii,ij,ik)
+         ELSE
+            ilocu = MAXLOC( ABS( un_tl(:,:,:) ) )
+            ii = ilocu(1) + nimpp - 1
+            ij = ilocu(2) + njmpp - 1
+            ik = ilocu(3)
+         ENDIF
+         IF(lwp) THEN
+            WRITE(numout,cform_err)
+            WRITE(numout,*) ' stpctl_tan: the zonal velocity is larger than 50 m/s'
+            WRITE(numout,*) ' ========= '
+            WRITE(numout,9400) kt, zumax, ii, ij, ik
+            WRITE(numout,*)
+         ENDIF
+         kindic = -3
+
+      ENDIF
+9400  FORMAT (' kt=',i6,' max abs(U): ',1pg11.4,', i j k: ',3i5)
+      ! 2. meridional velocity
+      ! ----------------------
+      zvmax = 0.e0
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zvmax = MAX(zvmax,ABS(vn_tl(ji,jj,jk)))
+          END DO 
+        END DO 
+      END DO        
+      IF( lk_mpp )   CALL mpp_max( zvmax )   ! max over the global domain
+
+      IF( MOD( kt, nwrite ) == 1 .AND. lwp ) WRITE(numout,*) ' ==>> time-step= ',kt,' abs(V) max: ', zvmax
+      IF( zvmax > 50.) THEN
+         IF( lk_mpp ) THEN
+            CALL mpp_maxloc(ABS(vn_tl),vmask,zvmax,ii,ij,ik)
+         ELSE
+            ilocv = MAXLOC( ABS( vn_tl(:,:,:) ) )
+            ii = ilocv(1) + nimpp - 1
+            ij = ilocv(2) + njmpp - 1
+            ik = ilocv(3)
+         ENDIF
+         IF(lwp) THEN
+            WRITE(numout,cform_err)
+            WRITE(numout,*) ' stpctl_tan: the meridional  velocity is larger than 50 m/s'
+            WRITE(numout,*) ' ========= '
+            WRITE(numout,9410) kt, zvmax, ii, ij, ik
+            WRITE(numout,*)
+         ENDIF
+         kindic = -3
+      ENDIF
+9410  FORMAT (' kt=',i6,' max abs(V): ',1pg11.4,', i j k: ',3i5)
+      ! 3. Temperature
+      ! ----------------------
+      ztmax = 0.e0
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ztmax = MAX(ztmax,ABS(tn_tl(ji,jj,jk)))
+          END DO 
+        END DO 
+      END DO        
+      IF( lk_mpp )   CALL mpp_max( ztmax )   ! max over the global domain
+
+      IF( MOD( kt, nwrite ) == 1 .AND. lwp ) WRITE(numout,*) ' ==>> time-step= ',kt,' abs(T) max: ', zTmax
+      IF( ztmax > 80.) THEN
+         IF( lk_mpp ) THEN
+            CALL mpp_maxloc(ABS(tn_tl),tmask,ztmax,ii,ij,ik)
+         ELSE
+            iloct = MAXLOC( ABS( tn_tl(:,:,:) ) )
+            ii = iloct(1) + nimpp - 1
+            ij = iloct(2) + njmpp - 1
+            ik = iloct(3)
+         ENDIF
+         IF(lwp) THEN
+            WRITE(numout,cform_err)
+            WRITE(numout,*) ' stpctl_tan: the temperature is larger than 80 K'
+            WRITE(numout,*) ' ========= '
+            WRITE(numout,9420) kt, ztmax, ii, ij, ik
+            WRITE(numout,*)
+         ENDIF
+         kindic = -3
+      ENDIF
+9420  FORMAT (' kt=',i6,' max abs(T): ',1pg11.4,', i j k: ',3i5)
+
+      ! 3. Salinity
+      ! ----------------------
+      zsmax = 0.e0
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zsmax = MAX(zsmax,ABS(sn_tl(ji,jj,jk)))
+          END DO 
+        END DO 
+      END DO        
+      IF( lk_mpp )   CALL mpp_max( zsmax )   ! max over the global domain
+
+      IF( MOD( kt, nwrite ) == 1 .AND. lwp ) WRITE(numout,*) ' ==>> time-step= ',kt,' abs(S) max: ', zsmax
+      IF( zsmax > 100.) THEN
+         IF( lk_mpp ) THEN
+            CALL mpp_maxloc(ABS(sn_tl),tmask,zsmax,ii,ij,ik)
+         ELSE
+            ilocs = MAXLOC( ABS( sn_tl(:,:,:) ) )
+            ii = ilocs(1) + nimpp - 1
+            ij = ilocs(2) + njmpp - 1
+            ik = ilocs(3)
+         ENDIF
+         IF(lwp) THEN
+            WRITE(numout,cform_err)
+            WRITE(numout,*) ' stpctl_tan: the Salinity is larger than 100 o/oo'
+            WRITE(numout,*) ' ========== '
+            WRITE(numout,9430) kt, zsmax, ii, ij, ik
+            WRITE(numout,*)
+         ENDIF
+         kindic = -3
+      ENDIF
+9430  FORMAT (' kt=',i6,' max abs(S): ',1pg11.4,', i j k: ',3i5)
+
+   END SUBROUTINE stp_ctl_tan
+   SUBROUTINE stp_ctl_adj( kt, kindic, ksign )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE stp_ctl_adj  ***
+      !!                     
+      !! ** Purpose of the direct routine:   Control the run
+      !!
+      !! ** Method  : - Save the time step in numstp
+      !!              - Print it each 50 time steps
+      !!              - Print solver statistics in numsol 
+      !!              - Stop the run IF problem for the solver ( indec < 0 )
+      !!
+      !! History :
+      !!        !  91-03  ()
+      !!        !  91-11  (G. Madec)
+      !!        !  92-06  (M. Imbard)
+      !!        !  97-06  (A.M. Treguier)
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+      INTEGER, INTENT( in ) ::   ksign
+      INTEGER, INTENT( inout ) ::   kindic  ! indicator of solver convergence
+
+      !! * local declarations
+
+   END SUBROUTINE stp_ctl_adj
+
+   !!======================================================================
+#endif
+END MODULE stpctl_tam
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/tamctl.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/tamctl.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/tamctl.F90	(revision 2578)
@@ -0,0 +1,54 @@
+MODULE tamctl
+   !!======================================================================
+   !!                       ***  MODULE tamctl ***
+   !! NEMOTAMR : variables controlling the run.
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !! History :
+   !!        !  ...    ( ... )        Original code: varctl.F90
+   !!        !  09-06  (F. Vigilant)  Created to split NEMOVAR / NEMOTAM
+   !!---------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind
+
+   !! * Routine accessibility
+   
+   IMPLICIT NONE
+
+   PUBLIC
+
+   !! * Module variables
+
+
+   INTEGER :: & 
+      & nmax_fs         ! Maximum number of iterations for the SSH balance
+                        ! elliptic equation solver
+
+
+   !! namtst:  assimilation test parameters
+
+   LOGICAL :: &
+      & ln_tst_opatam,  & ! Switch for NEMOTAM adjoint tests
+      & ln_tst_adj_cpd, & ! Switch for NEMOTAM adjoint tests (components only)
+      & ln_tst_adj_stp, & ! Switch for STEP_TAM adjoint tests
+      & ln_tst_tan_cpd, & ! Switch for NEMOTAM tangent components accuracy tests 
+      & ln_tst_tan_stp, & ! Switch for NEMOTAM tangent accuracy tests
+      & ln_tst_stop       ! Switch for stopping after the tests
+
+   LOGICAL :: &
+      & ln_tst_tlh        ! Switch for tangent linear hypothesis testing
+   INTEGER   :: nn_stage
+   LOGICAL   :: ln_tlht, ln_tlhs, ln_tlhuv, ln_incdx, ln_hnorm, ln_tlhssh
+   CHARACTER :: cn_tlhinc_in, cn_tlhrst_in
+   REAL(wp)  :: rn_hstdt, rn_hstds, rn_hstduv, rn_hstdssh
+   !! Units for tangent test
+
+   INTEGER :: &
+      & numtan, &       ! Output for tangent diagnostics
+      & numtan_sc  	!Output for tangent diagnostics (scalar sampling)
+
+END MODULE tamctl
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/tamtst.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/tamtst.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/tamtst.F90	(revision 2578)
@@ -0,0 +1,384 @@
+MODULE tamtst
+#if defined key_tam
+   !!======================================================================
+   !!                       ***  MODULE tst ***
+   !! NEMOVAR : Testing routine
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !! * Modules used   
+   USE par_kind, ONLY : &  ! Precision variables
+      & wp
+   USE par_oce, ONLY : &   ! Ocean space and time domain variables
+      & jpi, jpj, jpk
+   USE dom_oce, ONLY : &   ! Processor area number
+      & narea, n_cla
+   USE trabbc        , ONLY: &! bottom boundary condition
+      & lk_trabbc
+   USE traqsr        , ONLY: &
+      &  ln_traqsr
+   USE in_out_manager      ! Input/output
+   USE iom                 ! netCDF output/input
+   USE paresp              ! Weights for energy-type scalar product
+   USE tamctl              ! TAM control
+   USE sbcmod_tam          ! Tangent/adjoint of surface BCs
+   USE eosbn2_tam          ! Tangent/adjoint of eq. of state, Brunt-Vaisala
+   USE trasbc_tam          ! Tangent/adjoint of surface BCs application
+   USE traqsr_tam          ! Tangent/adjoint of penetrative solar radiation
+   USE trabbc_tam          ! Tangent/adjoint of bottom heat flux
+   USE tradmp_tam          ! Tangent/adjoint of internal damping trends
+   USE traadv_tam          ! Tangent/adjoint of horizontal/vertical advection
+   USE cla_tam             ! Tangent/adjoint of cross land advection
+   USE cla_div_tam         ! Tangent/adjoint of cross land advection
+   USE traldf_tam          ! Tangent/adjoint of lateral mixing
+   USE trazdf_tam          ! Tangent/adjoint of vertical diffusion
+   USE tranxt_tam          ! Tangent/adjoint of tracers at next time step
+   USE zpshde_tam          ! Tangent/adjoint of horiz. derivs. for partial steps
+   USE divcur_tam          ! Tangent/adjoint of horiz. div. and rel. vorticity
+   USE dynadv_tam          ! Tangent/adjoint of horizontal/vertical advection
+   USE dynhpg_tam          ! Tangent/adjoint of horiz. pressure gradient
+   USE dynkeg_tam          ! Tangent/adjoint of kinetic energy gradient
+   USE dynldf_tam          ! Tangent/adjoint of lateral mixing
+   USE dynnxt_tam          ! Tangent/adjoint of dynamics at next time step
+   USE dynspg_tam          ! Tangent/adjoint of surface pressure gradient
+   USE dynvor_tam          ! Tangent/adjoint of relative and planetary vorticity
+   USE dynzdf_tam          ! Tangent/adjoint of vertical diffusion
+   USE dynbfr_tam          ! Tangent/adjoint of bottom friction 
+   USE sshwzv_tam          ! Tangent/adjoint of vertical velocity
+   USE step_tam            ! manager of the adjoint ocean time stepping
+   USE trj_tam             ! reference trajectory
+   USE istate_tam
+   USE solsor_tam
+   USE solpcg_tam
+#if defined key_obc
+   USE obcdyn_tam
+#endif
+#if defined key_mpp_mpi
+   USE lbcnfd_tam
+#endif
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+
+   PUBLIC &
+      & tam_tst,  &        !: Scalar product test of the adjoint routines
+      & tam_init, &        !: Reading of the namelist 
+      & numadt             !: File unit number for adjoint test output
+
+   !! * Module variables
+   INTEGER :: &
+      & numadt             !: File unit number for adjoint test output
+
+CONTAINS
+
+   SUBROUTINE tam_tst
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tam_tst  ***
+      !!
+      !! ** Purpose : Apply various tests (linearization, adjoint)
+      !!              on the NEMOTAM code.
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!                   
+      !! History : 
+      !!        ! 2007-11 (A. Weaver) original (adjoint tests)
+      !!        ! 2009-08 (F. Vigilant) Add tangent tests
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+
+      !! * Local declarations
+      CHARACTER (LEN=128) :: file_out
+
+      ! Open adjoint test output unit
+
+      IF (lwp) THEN
+
+         WRITE(file_out,FMT="('adjoint_test.output_',I4.4)") &
+            &   narea-1
+         CALL ctl_opn( numadt, file_out, 'UNKNOWN', 'FORMATTED',   &
+            &         'SEQUENTIAL', 1, numadt, .FALSE., 1 )
+
+         WRITE(numout,*) ' tstopt: Start testing adjoint operators ...'
+         WRITE(numout,*) ' ------'
+
+         WRITE(numout,*)
+         WRITE(numout,990) file_out
+990      FORMAT('          Output in file = ',A20)
+         WRITE(numout,*)
+
+         WRITE(numadt,*)
+         WRITE(numadt,997) 
+         WRITE(numadt,998) 
+         WRITE(numadt,999) 
+997      FORMAT('  Routine (L)',2X,' ( L * dx )^T W dy ',2X, &
+            &   '     dx^T L^T W dy    ',2X,'Rel.',2X,      &
+            &   'Mach.',2X,'Status')
+998      FORMAT('             ',2X,'                   ',2X, &
+            &   '                      ',2X,'Err.',2x,      &
+            &   'Eps. ',2X,'      ')
+999      FORMAT('  -----------',2X,'-------------------',2X, &
+            &   '----------------------',2X,'----',2X,      &
+            &   '-----',2X,'------')
+         CALL FLUSH(numout)
+         CALL FLUSH(numadt)
+
+      ENDIF
+
+      ! Initialize energy weights
+
+      CALL par_esp
+
+      ! -----------------------------------------------------
+      ! Test the adjoint of the components of M (NEMOTAM)
+      ! -----------------------------------------------------
+
+      IF ( ln_tst_opatam ) THEN
+         !
+         IF ( ln_tst_adj_cpd ) THEN
+            ! *** initialize the reference trajectory
+            ! ------------
+            CALL trj_rea( nit000 - 1, 1 )
+            ! *** Tracers
+            ! ----------- 
+            CALL tra_adv_adj_tst( numadt )    ! Horizontal and vertical advection
+            IF (lwp) WRITE(numadt,*)
+            IF ( ln_traqsr      )  THEN
+               CALL tra_qsr_adj_tst( numadt )    ! Penetrative solar radiation
+               IF (lwp) WRITE(numadt,*)
+            ENDIF
+            CALL tra_ldf_adj_tst( numadt )    ! Lateral mixing
+            IF (lwp) WRITE(numadt,*)
+            CALL eos_adj_tst( numadt )        ! In situ density
+            IF (lwp) WRITE(numadt,*)
+            IF ( lk_tradmp      )  THEN
+               CALL tra_dmp_adj_tst( numadt )    ! Internal damping trends
+               IF (lwp) WRITE(numadt,*)
+            ENDIF
+            IF ( lk_trabbc      )  THEN
+               CALL tra_bbc_adj_tst( numadt )    ! Bottom heat flux
+               IF (lwp) WRITE(numadt,*)
+            ENDIF
+            IF ( n_cla == 1     )  THEN
+               CALL tra_cla_adj_tst( numadt )    ! Cross land advection (update hor. advection)
+               IF (lwp) WRITE(numadt,*)
+            ENDIF
+            CALL tra_zdf_adj_tst( numadt )    ! Vertical mixing
+            IF (lwp) WRITE(numadt,*)
+            CALL tra_nxt_adj_tst( numadt )    ! Tracer fields at next time step
+            IF (lwp) WRITE(numadt,*)
+            CALL istate_init_adj_tst( numadt )
+            IF (lwp) WRITE(numadt,*)
+            CALL tra_sbc_adj_tst( numadt )    ! Surface boundary condition
+            IF (lwp) WRITE(numadt,*)
+            CALL bn2_adj_tst( numadt )        ! Brunt-Vaisala frequency
+            IF (lwp) WRITE(numadt,*)
+            CALL zps_hde_adj_tst( numadt )    ! Partial steps: horiz. grad. at bottom level
+            IF (lwp) WRITE(numadt,*)
+            ! *** Vertical physics
+            ! --------------------
+            CALL dyn_zdf_adj_tst( numadt )    ! Vertical diffusion
+            IF (lwp) WRITE(numadt,*)
+            CALL dyn_ldf_adj_tst( numadt )    ! Lateral mixing
+            IF (lwp) WRITE(numadt,*)
+            CALL dyn_adv_adj_tst( numadt )    ! Advection (vector or flux form)
+            IF (lwp) WRITE(numadt,*)
+            CALL dyn_hpg_adj_tst( numadt )    ! Horizontal pressure gradient
+            IF (lwp) WRITE(numadt,*)
+            CALL div_cur_adj_tst( numadt )    ! Horizontal divergence and relative vorticity
+            IF (lwp) WRITE(numadt,*)
+            CALL ssh_wzv_adj_tst( numadt )    ! Vertical velocity
+            IF (lwp) WRITE(numadt,*)
+            CALL ssh_nxt_adj_tst( numadt )    ! Sea surface  height time stepping
+            IF (lwp) WRITE(numadt,*)
+            IF ( n_cla == 1     )  THEN
+               CALL div_cla_adj_tst( numadt )    ! Cross land advection (update hor. divergence)
+               IF (lwp) WRITE(numadt,*)
+            ENDIF
+# if defined key_mpp_mpi            
+            CALL lbc_nfd_adj_tst( numadt )
+            IF (lwp) WRITE(numadt,*)
+# endif
+            CALL dyn_vor_adj_tst( numadt )    ! Vorticity term including Coriolis
+            IF (lwp) WRITE(numadt,*)
+            CALL dyn_spg_adj_tst( numadt )    ! Surface pressure gradient
+            IF (lwp) WRITE(numadt,*)
+            CALL dyn_nxt_adj_tst( numadt )    ! Lateral velocity at next time step
+            IF (lwp) WRITE(numadt,*)
+            CALL dyn_bfr_adj_tst( numadt )    ! Surface pressure gradient
+            IF (lwp) WRITE(numadt,*)
+# if defined key_dynspg_flt
+            ! *** Red-Black SOR solver
+            ! ------------
+            CALL sol_sor_adj_tst( numadt )
+            IF (lwp) WRITE(numadt,*)
+# endif
+            ! *** Surface boundary conditions
+            ! ------------
+            CALL sbc_adj_tst( numadt )        ! surface boundary conditions
+            CALL flush(numadt)
+            IF (lwp) THEN
+               WRITE(numout,*)
+               WRITE(numout,*) ' tstopt: Finished testing standalone operators'
+               WRITE(numout,*) ' ------'
+               WRITE(numout,*)
+            ENDIF
+         ENDIF
+         !
+         ! *** Time-loop operator
+         ! ----------------------
+         IF ( ln_tst_adj_stp ) THEN
+            CALL stp_adj_tst( numadt )        ! Time-stepping
+            IF (lwp) WRITE(numadt,*)
+            CALL flush(numadt)
+         ENDIF
+         ! *** Tangent accuracy
+         ! ----------------------
+#if defined key_tst_tlm
+         IF (ln_tst_tan_cpd) THEN
+            CALL sol_sor_tlm_tst( numadt )
+            IF (lwp) WRITE(numadt,*)
+
+            CALL dyn_hpg_tlm_tst( numadt )
+            IF (lwp) WRITE(numadt,*)
+
+            CALL dyn_spg_tlm_tst( numadt )
+            IF (lwp) WRITE(numadt,*)
+
+            CALL dyn_adv_tlm_tst( numadt )
+            IF (lwp) WRITE(numadt,*)
+
+            CALL eos_tlm_tst( numadt )
+            IF (lwp) WRITE(numadt,*)
+
+            CALL zps_hde_tlm_tst( numadt )
+            IF (lwp) WRITE(numadt,*)
+
+            CALL tra_sbc_tlm_tst( numadt )
+            IF (lwp) WRITE(numadt,*)
+
+            CALL bn2_tlm_tst( numadt )
+            IF (lwp) WRITE(numadt,*)
+
+            CALL tra_zdf_tlm_tst( numadt )
+            IF (lwp) WRITE(numadt,*)
+
+            CALL tra_adv_tlm_tst( numadt )     
+            IF (lwp) WRITE(numadt,*)
+
+            CALL tra_ldf_tlm_tst( numadt ) 
+            IF (lwp) WRITE(numadt,*)
+            CALL flush( numadt )
+         ENDIF
+         IF ( ln_tst_tan_stp ) THEN     
+            CALL stp_tlm_tst( numadt )
+            IF (lwp) WRITE(numadt,*)
+            CALL flush( numadt )
+         ENDIF
+#endif
+
+      ENDIF
+
+      ! Close output file
+
+      IF (lwp) CLOSE(numadt)
+
+      IF (lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' tamtst: Finished testing operators'
+         WRITE(numout,*) ' ------'
+         WRITE(numout,*)
+      ENDIF
+      CALL flush(numout)
+   END SUBROUTINE tam_tst
+   SUBROUTINE tam_init
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE tam_init  ***
+      !!                    
+      !! ** Purpose :   read tam related namelists and print the variables.
+      !!
+      !! ** input   : - namtst namelist
+      !!              - namtlh namelist
+      !!----------------------------------------------------------------------
+!!      NAMELIST/namtam/ 
+      NAMELIST/namtst/ ln_tst_opatam, ln_tst_adj_cpd, ln_tst_adj_stp, &
+         &             ln_tst_tan_cpd, ln_tst_tan_stp, ln_tst_tlh, ln_tst_stop 
+
+      NAMELIST/namtlh/ nn_stage, ln_tlht, ln_tlhs, ln_tlhuv, ln_tlhssh, cn_tlhinc_in, ln_incdx, ln_hnorm, rn_hstdt, rn_hstds, rn_hstduv, rn_hstdssh, cn_tlhrst_in
+
+
+      
+      ln_tst_opatam  = .TRUE. 
+      ln_tst_adj_cpd = .TRUE.
+      ln_tst_adj_stp = .TRUE.
+      ln_tst_tan_cpd = .FALSE.
+      ln_tst_tan_stp = .FALSE.
+      ln_tst_tlh     = .FALSE.
+      ln_tst_stop    = .FALSE.
+
+
+      REWIND( numnam )              ! Namelist namrun : parameters of the run
+      READ  ( numnam, namtst )
+      IF (lwp) THEN                 ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'tam_tst  : Tangent and Adjoint testing'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) '   Namelist nam_tst'
+         WRITE(numout,*) '      switch for tam testing             ln_tst_opatam  = ', ln_tst_opatam
+         WRITE(numout,*) '      switch for adjoint module testing  ln_tst_adj_cpd = ', ln_tst_adj_cpd 
+         WRITE(numout,*) '      switch for adjoint of step testing ln_tst_adj_stp = ', ln_tst_adj_stp 
+         WRITE(numout,*) '      switch for tangent module testing  ln_tst_tan_cpd = ', ln_tst_tan_cpd 
+         WRITE(numout,*) '      switch for tangent of step testing ln_tst_tan_stp = ', ln_tst_tan_stp 
+         WRITE(numout,*) '      switch for T.L. hypothesis testing ln_tst_tlh     = ', ln_tst_tlh
+         WRITE(numout,*) '      switch for stopping after the test ln_tst_stop   = ', ln_tst_stop
+      END IF
+
+      IF ( ln_tst_tlh ) THEN
+
+         cn_tlhrst_in= 'restart_tlh.nc'
+         cn_tlhinc_in= 'increment_tlh.nc'
+         nn_stage    = 0         
+         ln_tlht     = .TRUE.    
+         ln_tlhs     = .TRUE.    
+         ln_tlhuv    = .TRUE.    
+         ln_tlhssh   = .TRUE.    
+         ln_incdx    = .FALSE.   
+         ln_hnorm    = .FALSE.   
+         rn_hstdt    = 1.        
+         rn_hstds    = 0.1       
+         rn_hstduv   = 0.01
+         rn_hstdssh  = 0.01      
+         
+         REWIND( numnam )              ! Namelist namrun : parameters of the run
+         READ  ( numnam, namtlh )
+         !
+         IF (lwp) THEN                 ! control print
+            WRITE(numout,*)
+            WRITE(numout,*) 'tam_tlh  : Tangent linear hypothesis testing'
+            WRITE(numout,*) '~~~~~~~    initialization through namelist read'
+            WRITE(numout,*) '   Namelist nam_tlh'
+            WRITE(numout,*) '      current stage                      nn_stage    = ', nn_stage
+            WRITE(numout,*) '      switch for testing temperature     ln_tlht     = ', ln_tlht
+            WRITE(numout,*) '      switch for testing salinity        ln_tlhs     = ', ln_tlhs
+            WRITE(numout,*) '      switch for testing velocities      ln_tlhuv    = ', ln_tlhuv
+            WRITE(numout,*) '      switch for testing sea surf height ln_tlhssh   = ', ln_tlhssh
+            WRITE(numout,*) '      switch for reading an increment    ln_incdx    = ', ln_incdx
+            WRITE(numout,*) '      switch for a normed perturbation   ln_hnorm    = ', ln_hnorm
+            WRITE(numout,*) '      Upper bound of norm. for T         rn_hstdt    = ', rn_hstdt
+            WRITE(numout,*) '      Upper bound of norm. for S         rn_hstds    = ', rn_hstds
+            WRITE(numout,*) '      Upper bound of norm. for UV        rn_hstduv   = ', rn_hstduv
+            WRITE(numout,*) '      Upper bound of norm. for SSH       rn_hstdssh  = ', rn_hstdssh
+         END IF
+      END IF
+            
+   END SUBROUTINE tam_init
+#endif
+END MODULE tamtst
Index: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/trc_oce_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/trc_oce_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/trc_oce_tam.F90	(revision 2578)
@@ -0,0 +1,151 @@
+MODULE trc_oce_tam
+#if defined key_tam
+   !!======================================================================
+   !!                      ***  MODULE  trc_oce_tam  ***
+   !! Ocean passive tracer  :  share SMS/Ocean variables
+   !!                          Tangent and Adjoint Module
+   !!======================================================================
+   !! History of the direct module:
+   !!   9.0  !  04-03  (C. Ethe)  F90: Free form and module
+   !! History of the T&A module:
+   !!   9.0  !  08-11  (A. Vidard)  original version
+   !!----------------------------------------------------------------------
+# if defined key_top && defined key_pisces
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Id: trc_oce.F90 1152 2008-06-26 14:11:13Z rblod $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   USE sms_pisces_tam , ONLY :  &
+      etot3_tl    =>   etot3_tl & !!:  Biological fluxes for light
+      etot3_ad    =>   etot3_ad   !!:  Biological fluxes for light
+# else
+   !!----------------------------------------------------------------------
+   !! Default option                         No Biological fluxes for light          
+   !!----------------------------------------------------------------------
+   USE par_kind, ONLY : &       ! Precision variables
+      & wp
+   USE par_oce, ONLY: &
+      & jpi,          &
+      & jpj,          &
+      & jpk
+   !! * Module variables
+   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+      & etot3_tl, &
+      & etot3_ad
+# endif
+   PUBLIC &
+      & trc_oce_tam_init,       & !: Initialize the trend TAM fields
+      & trc_oce_tam_deallocate, & !: Deallocate the trend TAM fields
+      & etot3_tl, &
+      & etot3_ad
+
+CONTAINS
+
+   SUBROUTINE trc_oce_tam_init( kindic )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE trc_oce_tam_init  ***
+      !!
+      !! ** Purpose : Allocate and initialize the tangent linear and
+      !!              adjoint arrays
+      !!
+      !! ** Method  : kindic = 0  allocate/initialize both tl and ad variables
+      !!              kindic = 1  allocate/initialize only tl variables
+      !!              kindic = 2  allocate/initialize only ad variables
+      !!
+      !! ** Action  :
+      !!
+      !! References :
+      !!
+      !! History :
+      !!        ! 09-05 (F. Vigilant) Initial version
+      !!-----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kindic        ! indicate which variables to allocate/initialize
+
+      !! * Local declarations
+      ! Allocate tangent linear variable arrays
+      ! ---------------------------------------
+
+      IF ( kindic == 0 .OR. kindic == 1 ) THEN
+
+         IF ( .NOT. ALLOCATED(etot3_tl) ) THEN
+
+            ALLOCATE( etot3_tl(jpi,jpj,jpk) )
+
+         ENDIF
+
+         ! Initialize tangent linear variable arrays to zero
+         ! -------------------------------------------------
+
+         etot3_tl   (:,:,:) = 0.0_wp
+
+      END IF
+
+      IF ( kindic == 0 .OR. kindic == 2 ) THEN
+            
+         ! Allocate adjoint variable arrays
+         ! --------------------------------
+
+         IF ( .NOT. ALLOCATED(etot3_ad) ) THEN
+
+            ALLOCATE( etot3_ad(jpi,jpj,jpk) )
+
+         ENDIF
+
+         ! Initialize adjoint variable arrays to zero
+         ! ------------------------------------------
+
+         etot3_ad   (:,:,:) = 0.0_wp
+
+      END IF
+
+   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_2_2/NEMOTAM/OPATAM_SRC/tstool_tam.F90
===================================================================
--- branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/tstool_tam.F90	(revision 2578)
+++ branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/tstool_tam.F90	(revision 2578)
@@ -0,0 +1,251 @@
+MODULE tstool_tam
+   !!==========================================================================
+   !!     ***  MODULE  tstool_tam : TAM testing utilities  ***
+   !!==========================================================================
+   !! History of the NEMOTAM module:
+   !!             3.0  !  08-11  (A. Vidard) initial version
+   USE par_oce,        ONLY: & ! Ocean space and time domain variables
+      & jpi,                 &
+      & jpj,                 &
+      & jpk,                 &
+      & jpiglo,              &
+      & jpjglo
+   USE dom_oce       , ONLY: & ! Ocean space and time domain
+      & e1u,                 &
+      & e2u,                 &
+#if defined key_zco
+      & e3t_0,               &
+#else
+      & e3u,                 &
+#endif
+      & umask,               &
+      & mig,                 &
+      & mjg,                 &
+      & nldi,                &
+      & nldj,                &
+      & nlei,                &
+      & nlej
+   USE par_kind      , ONLY: & ! Precision variables
+      & wp
+   USE in_out_manager, ONLY: & ! I/O manager 
+      & lwp
+   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
+      & grid_random
+   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
+      & dot_product
+   IMPLICIT NONE
+   PRIVATE
+   REAL(KIND=wp), PUBLIC ::  & ! random field standard deviation for:
+      & stdu   =  0.1_wp,    & !   u-velocity
+      & stdv   =  0.1_wp,    & !   v-velocity
+      & stdw   = 0.01_wp,    & !   w-velocity
+#if defined key_obc
+      & stds   = 0.01_wp,    & !   salinity
+      & stdt   = 0.20_wp,    & !   temperature
+      & stdssh = 0.005_wp,   & !   sea surface height
+#else
+      & stds   =  0.1_wp,    & !   salinity
+      & stdt   =  1.0_wp,    & !   temperature
+      & stdssh = 0.01_wp,    & !   sea surface height
+#endif
+      & stdemp = 0.01_wp,    & !   evaporation minus precip 0.1_wp / SQRT( wesp_emp ) 
+      & stdqns =  1.0_wp,    & !   non solar heat flux
+      & stdqsr =  1.0_wp,    & !   solar heat flux
+      & stdgc  =  0.1_wp,    & !   gcx, gcb
+      & stdr   =  0.1_wp,    & !   rotb, rhd
+      & stdh   =  0.1_wp       !   hdivb
+
+   PUBLIC &
+      & prntst_adj,          &
+      & prntst_tlm
+
+#  include "domzgr_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE prntst_adj( cd_name, kumadt, psp1, psp2 )
+      CHARACTER(LEN=14), INTENT(in) :: cd_name
+      REAL(wp), INTENT(in) :: psp1, psp2
+      INTEGER, INTENT(in) :: kumadt
+      REAL(KIND=wp) :: &
+         & zspdif,       & ! scalar product difference
+         & ztol            ! accepted tolerance
+      CHARACTER (LEN=47) :: &
+         & FMT
+      CHARACTER (LEN=9)  :: &
+         & cl_stat         ! Accuracy status of adjoint routine (ok or warning)
+
+      ! Compare the scalar products
+
+      zspdif = ABS( psp1 - psp2 )
+      IF ( psp1 /= 0.0_wp ) zspdif = zspdif / ABS( psp1 )
+       
+      ztol = EPSILON( zspdif ) * 10.
+
+      IF ( zspdif < ztol ) THEN 
+         cl_stat = '   ok    '
+      ELSEIF ( zspdif < ztol*100._wp ) THEN 
+         cl_stat = ' warning '
+      ELSE
+         cl_stat = 'RED ALERT'
+      ENDIF  
+
+      IF (lwp) THEN
+         FMT = "(A14,1X,E20.15,2X,E20.15,2X,E6.1,1X,E6.1,1x,A9)"
+         WRITE(kumadt,FMT) cd_name, psp1, psp2, zspdif, ztol, cl_stat
+         CALL FLUSH( kumadt )
+      ENDIF
+   END SUBROUTINE prntst_adj
+
+   SUBROUTINE prntst_tlm( cd_name, kumadt, psp1, psp2 )
+      CHARACTER(LEN=14), INTENT(in) :: cd_name
+      REAL(wp), INTENT(in) :: psp1, psp2
+      INTEGER, INTENT(in) :: kumadt
+      REAL(KIND=wp) :: &
+         & zspratio       ! scalar product difference
+      CHARACTER (LEN=47) :: &
+         & FMT
+      CHARACTER (LEN=9)  :: &
+         & cl_stat         ! Accuracy status of adjoint routine (ok or warning)
+
+      ! Compare the scalar products
+
+      IF ( psp1 /= 0.0_wp ) zspratio = 100 * psp1 /  psp2  
+
+      IF (lwp) THEN
+         FMT = "(A14,1X,E20.13,2X,E20.15,2X,E6.1,1X)"
+         WRITE(kumadt,FMT) cd_name, psp1, psp2, zspratio
+         CALL FLUSH( kumadt )
+      ENDIF
+   END SUBROUTINE prntst_tlm
+
+   SUBROUTINE example_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE example_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product 
+      !!           
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx 
+      !!
+      !!                   
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+ 
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &        
+         & jk     
+      INTEGER, DIMENSION(jpi,jpj) :: &
+         & iseed_2d        ! 2D seed for the random number generator
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2            ! scalar product involving the adjoint routine
+      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & z_tlin ,     & ! Tangent input
+         & z_tlout,     & ! Tangent output
+         & z_adin ,     & ! Adjoint input
+         & z_adout,     & ! Adjoint output
+         & zr             ! 3D random field 
+      CHARACTER(LEN=14) :: &
+         & cl_name
+      ! Allocate memory
+
+      ALLOCATE( &
+         & z_tlin( jpi,jpj,jpk),     &
+         & z_tlout(jpi,jpj,jpk),     &
+         & z_adin( jpi,jpj,jpk),     &
+         & z_adout(jpi,jpj,jpk),     &
+         & zr(     jpi,jpj,jpk)      &
+         & )
+      !==================================================================
+      ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and 
+      !    dy = ( hdivb_tl, hdivn_tl )
+      !==================================================================
+
+      !--------------------------------------------------------------------
+      ! Reset the tangent and adjoint variables
+      !--------------------------------------------------------------------
+          z_tlin( :,:,:) = 0.0_wp
+          z_tlout(:,:,:) = 0.0_wp
+          z_adin( :,:,:) = 0.0_wp
+          z_adout(:,:,:) = 0.0_wp
+          zr(     :,:,:) = 0.0_wp
+      !--------------------------------------------------------------------
+      ! Initialize the tangent input with random noise: dx
+      !--------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iseed_2d(ji,jj) = - ( 596035 + &
+               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
+         END DO
+      END DO
+      CALL grid_random( iseed_2d, zr, 'U', 0.0_wp, stdr )
+      z_tlin(:,:,:) = zr(:,:,:) 
+
+      CALL example_tan 
+      !--------------------------------------------------------------------
+      ! Initialize the adjoint variables: dy^* = W dy
+      !--------------------------------------------------------------------
+
+      DO jk = 1, jpk
+        DO jj = nldj, nlej
+           DO ji = nldi, nlei
+              z_adin(ji,jj,jk) = z_tlout(ji,jj,jk) &
+                 &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) &
+                 &               * umask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !--------------------------------------------------------------------
+      ! Compute the scalar product: ( L dx )^T W dy
+      !--------------------------------------------------------------------
+
+      zsp1 = DOT_PRODUCT( z_tlout, z_adin )
+
+      !--------------------------------------------------------------------
+      ! Call the adjoint routine: dx^* = L^T dy^*
+      !--------------------------------------------------------------------
+
+      CALL example_adj 
+
+      zsp2 = DOT_PRODUCT( z_tlin, z_adout )
+
+      ! 14 char:'12345678901234'
+      cl_name = 'example_adj   '
+      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      DEALLOCATE(     &
+         & z_tlin,  &
+         & z_tlout, &
+         & z_adin,  &
+         & z_adout, &
+         & zr       &
+         & )
+
+
+
+   END SUBROUTINE example_adj_tst
+
+   SUBROUTINE example_tan
+   END SUBROUTINE example_tan
+   SUBROUTINE example_adj
+   END SUBROUTINE example_adj
+
+END MODULE tstool_tam
Index: branches/TAM_V3_2_2/UTIL/fait_AA_make_tam
===================================================================
--- branches/TAM_V3_2_2/UTIL/fait_AA_make_tam	(revision 2578)
+++ branches/TAM_V3_2_2/UTIL/fait_AA_make_tam	(revision 2578)
@@ -0,0 +1,590 @@
+#!/bin/ksh
+#set -vx
+############################################################
+#
+# Purpose :
+# This script aims to create create the AA_make file
+# in the WORK directory. 
+# AA_make contains :
+#    - compilation options speccific to NEMOTAM
+#    - compilation rules
+#    - dependancies
+# Running the modipsl/util/ins_make command is needed AFTER
+# fait_AA_make.
+#
+# Method :
+# We use temporary files to perform the following steps :
+#    1- search all CPP keys in the code
+#    2- write compilation rules 
+#    3- add compilation options add the beginning of AA_make 
+#    4- search and write dependancies
+#    5- add some specific rules (links creation in the WORK)
+#
+# Modification : - add F_F for .F file compiler option on aix
+#                - add KEY_CPP dependancy for source containing 
+#                              only #if defined CPP statement
+#
+############################################################
+#-
+echo "This script must be run while in the modipsl/modeles/NEMOTAM directory"
+cd WORK || exit
+pwd
+
+# Test version of echo
+stringtest=`echo "\c"`
+if [ "$stringtest" ]; then
+   echo 'aliasing echo with /bin/echo -e ...'
+   alias echo='echo -e'
+fi
+
+#-
+#- Search CPP keys ---
+liste_cle=$(egrep '^# *if[!( &]*def|^# *elif' *.[Fh] *.[Fh]90  2> /dev/null | grep key_ | sed 's/||/\
+/' | sed 's/\&\&/\
+/' | sed 's/^.*key_/key_/' | sed 's/ *[) ] *$//' | sort -u  )
+
+#-
+#- Write main compilation rules ---
+cat > tampon <<end
+
+.SUFFIXES: .f90 .F90 .F
+
+# Target
+all: 		diroce \$(EXEC_BIN)
+		@cp SRC_FILE_LIST.temp SRC_FILE_LIST
+		@echo OPATAM model is OK
+# Cleaning objects, libraries and executables
+clean:
+ifeq (\$(AGRIF),use)
+		-@(cd OPAFILES; ./efface)
+endif
+		\$(RM) model_tam.o \$(MODDIR)/ocetam/*.mod \$(MODEL_LIB) \$(SXMODEL_LIB) \$(EXEC_BIN)
+		@echo OPA model \(.o .mod libraries and executables are removed\)
+
+# Dependancies
+diroce:
+		@if [ ! -d ../../../lib/ocetam ] ; then mkdir ../../../lib/ocetam; fi
+
+\$(EXEC_BIN) :	libioipsl libioserver firstagrif mpiagrif key keyverif src_file_list libagrif \$(MODEL_LIB) \$(IOIPSL_LIB) \$(AGRIF_LIB) agrif2model.o model_tam.o 
+ifeq (\$(AGRIF),use)
+		\$(F_L) \$(L_X) -o \$(EXEC_BIN) model_tam.o agrif2model.o \$(SXMODEL_LIB) \$(USER_LIB) \$(IOIPSL_LIB) \$(AGRIF_LIB) \$(NCDF_LIB) \$(LIBMPI) \$(LIBMP)
+else
+		\$(F_L) \$(L_X) -o \$(EXEC_BIN) model_tam.o \$(SXMODEL_LIB) \$(USER_LIB) \$(IOIPSL_LIB) \$(NCDF_LIB) \$(LIBMPI) \$(LIBMP)
+endif
+
+# ioserver library
+libioserver :
+ifeq (\$(IOSERVER),use)
+ifeq (\$(FCM),use)
+	(cd ../../XMLF90; ./configure -arch \$(FCM_ARCH); fcm build; mkdir -p ../../lib/libxmlio_server  ; cd ../../lib/libxmlio_server ; ln -sf ../../modeles/XMLF90/lib/*.a .; ln -sf ../../modeles/XMLF90/inc/*.mod .)
+	(cd ../../XMLIO_SERVER; ./configure -arch \$(FCM_ARCH); fcm build ; cd ../../lib/libxmlio_server ; ln -sf ../../modeles/XMLIO_SERVER/lib/*.a . ; ln -sf ../../modeles/XMLIO_SERVER/inc/* . ; cd ../../bin ; ln -sf ../modeles/XMLIO_SERVER/bin/server.exe ioserver)
+else
+	(cd ../../XMLF90/external ; \$(M_K) -f Makefile )
+	(cd ../../XMLIO_SERVER/external ; \$(M_K) -f Makefile P_P="\$(IOSERVER_MPI)" )
+endif
+endif
+
+# Agrif library and conv
+libagrif :  \$(call keycompat,key_iomput,key_agrif)
+ifeq (\$(AGRIF),use)
+	@( if [ ! -d OPAFILES ]; then mkdir OPAFILES; fi )
+	@( if [ ! -d OPAFILES/AGRIF_INC ]; then mkdir OPAFILES/AGRIF_INC ; fi )
+	@( if [ ! -d OPAFILES/AGRIF_MODELFILES ]; then mkdir OPAFILES/AGRIF_MODELFILES ; fi )
+	@(cd ../../AGRIF ; \$(M_K) -f Makefile P_P="\$(AGRIF_MPI)" )
+	@cp -rf ../../AGRIF/agrif_opa.in OPAFILES/. 
+	@cp -rf ../../AGRIF/conv OPAFILES/. 
+	@cp -rf ../../AGRIF/efface OPAFILES/. 
+endif
+
+# Agrif interface with NEMO
+agrif2model.o :
+ifeq (\$(AGRIF),use)
+	@\$(P_C) \$(P_O) -IOPAFILES/AGRIF_INC \$*.F90 > OPAFILES/\$*.F90 
+	@\$(F_C) \\
+#-Q- aix		-qsuffix=f=F90 \\
+#-Q- aix6		-qsuffix=f=F90 \\
+#-Q- babel		-qsuffix=f=F90 \\
+#-Q- osxxlf		-qsuffix=f=F90 \\
+	\$(P_P) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sx8mercure		-R2 \\
+#-Q- sx9mercure		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix6		-qsource \\
+#-Q- aix		-qsource \\
+#-Q- babel		-qsource \\
+	   OPAFILES/\$*.F90 || { mv \$(PREF).L \$(TMP) ; false ; exit ; }
+#-Q- sxdkrz		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+#-Q- eshpux			@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+endif
+
+# IOIPSL library 
+libioipsl :
+	(cd ../../IOIPSL/src ; \$(M_K) -f Makefile )
+
+# Main program
+model_tam.o :	model_tam.f90
+		@\$(F_C) \$(F_O) -c model_tam.f90
+
+# if the make script is stopped, one doesn't destroy library
+.PRECIOUS : \$(MODEL_LIB)
+#-Q- sxdkrz .PRECIOUS : \$(SXMODEL_LIB)
+#-Q- eshpux .PRECIOUS : \$(SXMODEL_LIB)
+
+# library dependancies
+\$(MODEL_LIB):	\$(LIB_OBJ)
+		@echo
+		@echo The library is up-to-date
+		@echo
+
+# Default rules
+.DEFAULTS:
+
+# rules for the .f90 files
+.f90.a :           
+		@\$(F_C) \$(P_P) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sx8mercure		-R2 \\
+#-Q- sx9mercure		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+#-Q- aix6		-qsource \\
+#-Q- babel		-qsource \\
+		\$*.f90 || { if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi ; false ; exit ; }
+#-Q- sxdkrz		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+#-Q- eshpux		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+		@\$(A_C) \$(MODEL_LIB) \$*.o  > /dev/null
+		@\$(RM) \$*.[of]
+		@if [ -f \$*.mod ] ; then mv \$*.mod \$(MODDIR)/ocetam ; fi
+#-Q- aix		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- aix6		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- babel		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- linux		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- osxxlf		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+		@if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi
+
+# rules for the .F90 files
+.F90.a :  
+ifeq (\$(AGRIF),use) 
+		@\$(P_C) \$(P_O) -IOPAFILES/AGRIF_INC \$*.F90 > OPAFILES/\$*.F90 
+		@(cd OPAFILES ; ./conv agrif_opa.in -rm \\
+#-Q- linux		-SubloopScalar \\
+#-Q- g95			-SubloopScalar \\
+#-Q- f95			-SubloopScalar \\
+#-Q- osf1			-SubloopScalar \\
+		-comdirin ./ -comdirout AGRIF_MODELFILES/. -convfile \$*.F90)
+		-@mv -f OPAFILES/AGRIF_MODELFILES/\$*.F90 OPAFILES/\$*.F90
+		@\$(P_C) \$(P_O) -IOPAFILES/AGRIF_INC OPAFILES/\$*.F90 > OPAFILES/AGRIF_MODELFILES/\$*.F90
+		-@mv -f OPAFILES/AGRIF_MODELFILES/\$*.F90 OPAFILES/\$*.F90
+		@\$(F_C) \$(P_P) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sx8mercure		-R2 \\
+#-Q- sx9mercure		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+#-Q- aix6		-qsource \\
+#-Q- babel		-qsource \\
+		OPAFILES/\$*.F90 || { if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi ; false ; exit ; } 
+else
+		@\$(F_C) \$(P_P) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sx8mercure		-R2 \\
+#-Q- sx9mercure		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+#-Q- aix6		-qsource \\
+#-Q- babel		-qsource \\
+		\$*.F90 || { if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi ; false ; exit ; }
+endif
+#-Q- sxdkrz		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+#-Q- eshpux		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+		@\$(A_C) \$(MODEL_LIB) \$*.o  > /dev/null
+		@\$(RM) \$*.[of]
+		@if [ -f \$*.mod ] ; then mv \$*.mod \$(MODDIR)/ocetam ; fi
+#-Q- aix		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- aix6		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- babel		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- linux		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- osxxlf		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+		@if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi
+
+end
+#-
+#- Compilation options ---
+exec 1> AA_make
+MAIN="model_tam"
+echo '# $Header$'
+echo '# some variables'
+echo 'TMP = ../../../tmp'
+echo ''
+echo '#WARNING : NEMO does NOT support fortran 95 signed zero behaviour when using intrinsec SIGN function'
+echo '#          This doesnt happen whith Fortran 90 compilers but'
+echo '#          Check your compilers option in consequence when using real F95 compilers'
+echo ''
+echo '#-Q- platine # Compiler options NEMO (CCRT Itanium Bull) '
+echo '#-Q- platine F_O = -O3 -i4 -r8 -module $(MODDIR)/ocetam -I$(MODDIR) -I$(MODDIR)/ocetam -I$(NCDF_INC) $(USER_INC) '
+echo '#-Q- platine L_X = $(L_O) '
+echo '#-Q- sx8mercure  # Compiler options NEMO (CCRT SX8-NEC) '
+echo '#-Q- sx8mercure  F_O = -f2003 nocbind -size_t64 -dw -Wf\"-A dbl4\" -sx8 -C vopt -P stack -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf"-P nh" -Wf',-pvctl noassume loopcnt=10000 shape=10000000 -L transform' -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC) '
+echo '#-Q- sx8mercure  L_X = $(L_O)'
+echo '#-Q- sx9mercure  # Compiler options NEMO (CCRT SX9-NEC) '
+echo '#-Q- sx9mercure  F_O = -f2003 nocbind -size_t64 -dw -Wf\"-A dbl4\" -C vopt -P stack -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf"-P nh" -Wf',-pvctl noassume loopcnt=10000 shape=10000000 -L transform' -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC) '
+echo '#-Q- sx9mercure  L_X = $(L_O)'
+echo '#-Q- sx8brodie  # Compiler options NEMO (IDRIS SX8-NEC) '
+echo '#-Q- sx8brodie  F_O =  -f2003 nocbind -dw -Wf\"-A idbl4\" -sx8 -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC)'
+echo '#-Q- sx8brodie  L_X = $(L_O)'
+echo '#-Q- sxdkrz  # Compiler options for NEMO (DKRZ SX6-NEC) '
+echo '#-Q- sxdkrz  F_O =  -f2003 nocbind -ew -sx6 -ftrace -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf"-pvctl noassume loopcnt=10000" -L transform -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC)'
+echo '#-Q- sxdkrz  L_X = $(L_O) -ftrace'
+echo '#-Q- eshpux  # Compiler options for NEMO (Earth Simulator)'
+echo '#-Q- eshpux  # for super perfs!'
+echo '#-Q- eshpux  # F_O = -f2003 nocbind $(FTRACE) -pi nest=5 line=10000 expin=Fmpplib.F -Wf,-A idbl4 -C hopt -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC)'
+echo '#-Q- eshpux  # regular options!'
+echo '#-Q- eshpux  F_O = -f2003 nocbind $(FTRACE) -Wf,-A idbl4 -C vopt -P stack -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -Wf,-pvctl nomsg -Wf"-O nomsg" -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC)'
+echo '#-Q- eshpux  L_X = $(L_O)'
+echo '#-Q- linux  # Compiler options for NEMO (pgf version)'
+echo '#-Q- linux  F_O = -Mlist -O3 -byteswapio -r8  -I $(MODDIR) -I$(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC)'
+echo '#-Q- linux  L_X = -r8 -O3'
+echo '#-Q- lxiv7  # Compiler options for NEMO (ifc version)'
+echo '#-Q- lxiv7  F_O = -O3 -r8  -I $(MODDIR) -I$(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC)'
+echo '#-Q- lxiv7  L_X = -r8 -O3'
+echo '#-Q- lxiv8  # Compiler options for NEMO (ifort version)'
+echo '#-Q- lxiv8  F_O = -O3 -r8  -I $(MODDIR) -I$(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC)'
+echo '#-Q- lxiv8  L_X = -r8 -O3'
+echo '#-Q- g95  # Compiler options for NEMO (g95 version)'
+echo '#-Q- g95  F_O = -O3 -fno-second-underscore -r8 -funroll-all-loops -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC)'
+echo '#-Q- g95  L_X = -r8 -O3'
+echo '#-Q- gfortran  # Compiler options for NEMO (gfortran version)'
+echo '#-Q- gfortran  F_O = -fno-second-underscore -fdefault-real-8 -funroll-all-loops -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC)'
+echo '#-Q- gfortran  L_X = -fdefault-real-8'
+echo '#-Q- aix    # Compiler options for NEMO (aix version)'
+echo '#-Q- aix    F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC)' 
+echo '#-Q- aix   L_O = $(F_P) -q64 -O3'
+echo '#-Q- aix   L_X = $(L_O)'
+echo '#-Q- aix6    # Compiler options for NEMO (aix6 version)'
+echo '#-Q- aix6    F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC)' 
+echo '#-Q- aix6   L_O = $(F_P) -q64 -O3'
+echo '#-Q- aix6   L_X = $(L_O)'
+echo '#-Q- babel  # Compiler options for NEMO (blue gene version)'
+echo '#-Q- babel  F_O =  -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qsource -qextname=flush -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC)'
+echo '#-Q- babel  L_X = $(L_O)'
+echo '#-Q- osxxlf    # Compiler options for NEMO (osxxlf version)'
+echo '#-Q- osxxlf    F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qsource -qextname -qstrict -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/ocetam -I $(NCDF_INC) $(USER_INC)' 
+echo '#-Q- osxxlf    L_X = -qrealsize=8 -O3'
+
+echo 'PREF='
+echo '#-Q- sx8mercure	PREF=i.'
+echo '#-Q- sx9mercure	PREF=i.'
+echo '#-Q- sx8brodie	PREF=i.'
+echo '#-Q- sxdkrz	PREF=i.'
+echo '#-Q- eshpux	PREF=i.'
+echo ''
+echo '# add suffix to P_P'
+echo 'override P_P := $(P_P:%=$(prefix)%)'
+echo ''
+echo '# Some tests to define variables related to Agrif compilation'
+echo '# Please do not change '
+echo 'ifneq (,$(findstring key_agrif,$(P_P)))'
+echo 'AGRIF=use'
+echo 'else'
+echo 'AGRIF=notuse'
+echo 'AGRIF_LIB='
+echo 'endif'
+echo 'ifneq (,$(findstring key_mpp_mpi,$(P_P)))'
+echo 'AGRIF_MPI=-DAGRIF_MPI'
+echo 'else'
+echo 'AGRIF_MPI='
+echo 'endif'
+echo ''
+echo '# Some tests to define variables related to xmlioserver compilation'
+echo '# Please do not change '
+echo 'ifneq (,$(findstring key_iomput,$(P_P)))'
+echo 'IOSERVER=use'
+echo 'override USER_LIB += -L../../../lib/libxmlio_server -lioserver -lxmlio -lxmlf90'
+echo 'override USER_INC += -I../../../lib/libxmlio_server'
+echo 'ifneq (,$(findstring key_mpp_mpi,$(P_P)))'
+echo 'IOSERVER_MPI='
+echo 'else'
+echo 'IOSERVER_MPI=-DNO_MPI'
+echo 'endif'
+echo 'else'
+echo 'IOSERVER=notuse'
+echo 'endif'
+echo ''
+
+echo '# A variables related to xmlioserver compilationi (fcm or AA_make)'
+echo '# Please do not change '
+echo 'override FCM ?= notuse'
+echo ''
+
+echo '#check key compatibility'
+echo 'keycompat=$(if $(and $(findstring $1,$(P_P)),$(findstring $2,$(P_P))),$(error $1 and $2 NOT compatible))'
+
+echo ''
+# Write the cpp key list with one key by line
+echo 'KEY_LIST = \c'
+for i in ${liste_cle}
+do
+ echo "\\"
+ echo "     $i \c"
+done
+
+echo ''
+echo '# .o file list in the library'
+echo 'LIB_OBJ = \c'
+#
+# find all .f90 in the current directory
+# build object files list  LIB_OBJ
+# one dependancy by line
+
+for i in `ls *.f90  `
+do
+  bn=`basename $i .f90`
+  if [ "${bn}" != "${MAIN}" ] 
+  then 
+  if [ "${bn}" != "agrif2model" ] 
+  then 
+    echo "\\"
+    echo "		\$(MODEL_LIB)($bn.o)\c"
+  fi
+  fi
+done
+
+# find all .F90 in the current directory
+# build object files list  LIB_OBJ
+# one dependancy by line
+
+for i in `ls *.F90  `
+do
+  bn=`basename $i .F90`
+  if [ "${bn}" != "${MAIN}" ] 
+  then 
+  if [ "${bn}" != "agrif2model" ] 
+  then 
+    echo "\\"
+    echo "		\$(MODEL_LIB)($bn.o)\c"
+  fi
+  fi
+done
+
+echo ""
+
+cat tampon
+rm tampon
+#-
+#- Write all dependancies ---
+
+for fic in `ls *.f90 *.F90  *.F 2> /dev/null `
+do
+    if [ "${fic}" != "agrif2model.F90" ]
+    then
+    if [ "${fic}" != "${MAIN}.[Ff]" ]
+    then
+	i=0
+	j=0
+	dep=""
+	inc=""
+	inc2=""
+	inc3=""
+	luse0=""
+	luse1=""
+	luse2=""
+	luse3=""
+        key=""
+#- search include files (old ice model form, should it be suppressed ?)
+	for inc in `sed -n 's/^[  	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $fic | sort -u`
+	do
+	    dep="$dep\n$inc"
+	done
+
+#- take into account CPP dependancies  keys only (par_trc_trp example)
+	for key in `sed -n 's/^#[ 	eElL]*[iF][fF][ 	]*[dD][eE][fF][iI][nN][eE][dD][ 	]*//p' $fic | sort -u`
+	do
+	    j=1
+	done
+
+#- search include files on 3 levels
+	for inc in `sed -n 's/^#[ 	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $fic | sort -u`
+	do
+	    j=1
+	    dep="$dep\n$inc"
+		for inc2 in `sed -n 's/^#[ 	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $inc | sort -u`
+		do
+		    dep="$dep\n$inc2"
+		    #- search include  in include (third level !!!)
+		    for inc3 in `sed -n 's/^#[  	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $inc2 | sort -u`
+		    do
+			dep="$dep\n$inc3"
+		    done
+		done
+	done
+
+#- search USE in include files
+	for inc in `sed -n 's/^#[ 	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $fic | sort -u`
+	do
+		for fuse0 in `sed -n 's/^[ 	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $inc | sort -u`
+		do
+                    [ -f $fuse0.[hfF]90 ] || continue
+		    lfuse0=$fuse0.f90
+		    [ -f $fuse0.F90 ] && lfuse0=$fuse0.F90
+		    luse0="$luse0\n$lfuse0\n\$(MODEL_LIB)($fuse0.o)"
+		done
+
+#- search USE in  files included in included files and add to luse0
+
+		for inc2 in `sed -n 's/^#[ 	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $inc | sort -u`
+		do
+		    for fuse0 in `sed -n 's/^[ 	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $inc2 | sort -u`
+		    do
+                        [ -f $fuse0.[hfF]90 ] || continue
+		        lfuse0=$fuse0.f90
+		        [ -f $fuse0.F90 ] && lfuse0=$fuse0.F90
+		        luse0="$luse0\n$lfuse0\n\$(MODEL_LIB)($fuse0.o)"
+		    done
+  	        done
+	done
+
+#- search USE (and USE of USE and so on three levels)
+	for fuse1 in `sed -n 's/^[ 	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $fic | sort -u`
+	do
+            [ -f $fuse1.[hfF]90 ] || continue
+	    lfuse1=$fuse1.f90
+	    [ -f $fuse1.F90 ] && lfuse1=$fuse1.F90
+	    luse1="$luse1\n$lfuse1\n\$(MODEL_LIB)($fuse1.o)"
+		for fuse2 in `sed -n 's/^[ 	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $lfuse1 | sort -u`
+		do
+                    [ -f $fuse2.[hfF]90 ] || continue
+		    lfuse2=$fuse2.f90
+		    [ -f $fuse2.F90 ] && lfuse2=$fuse2.F90
+		    luse2="$luse2\n$lfuse2\n\$(MODEL_LIB)($fuse2.o)"
+		    # on cherche les USE  dans le fichier deja USE (3eme niveau! balaise!)
+		    for fuse3 in `sed -n 's/^#[  	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $lfuse2 | sort -u`
+		    do
+                        [ -f $fuse3.[hfF]90 ] || continue
+			luse3="$luse3\n$lfuse3\n\$(MODEL_LIB)($fuse3.o)"
+                    done
+		done
+	done
+#-
+#-  dep contains all dependancies 
+	echo "\$(MODEL_LIB)(`echo $fic|awk -F. '{print $1}'`.o) :	\c"
+	for depele in `echo $luse3 | sort -u` `echo $luse2 | sort -u` `echo $luse1 | sort -u` `echo $luse0 | sort -u` `echo $dep | sort -u`
+	do
+	    echo "\\"
+ 	    echo "	$depele \c"
+ 	    let i=i+1 # pour signaler le premier
+	done
+
+#-
+#- add dependancies with IOIPSL library (if source files contains IOIPSL)
+        grep -i 'use *ioipsl' ${fic} >/dev/null && ( echo "\\" ; echo "	\$(IOIPSL_LIB) \c")
+
+#-
+#- add dependancies with IOIPSL library (if source files contains Agrif_*)
+        grep -i 'use Agrif_*' ${fic} >/dev/null && ( echo "\\" ; echo "	\$(AGRIF_LIB) \c")
+
+#-
+#- add dependancies with KEY_CPP (if source file includes cpp  keys)
+	if [ ${j} != "0" ] 
+        then 
+	  echo "\\"
+	  echo "	KEY_CPP \c" 
+	fi
+#-
+#- end with the file itself
+	     echo "\\"
+       	     echo "	$fic"
+    fi
+    fi
+echo $fic done >/dev/tty
+done
+#-
+#- Write some special rules ---
+echo '# agrif previous use'
+echo "firstagrif:"
+echo "ifeq (\$(AGRIF),use)"
+echo '	@if [ -z "`cat KEY_CPP | grep key_agrif`" ]; then $(RM) model_tam.o $(MODDIR)/ocetam/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi'
+echo "else"
+echo '	@if [ -n "`cat KEY_CPP | grep key_agrif`" ]; then $(RM) -r OPAFILES model_tam.o $(MODDIR)/ocetam/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi'
+echo "endif"
+#-
+echo '#- RB : this rule is a pretty miserable trick to be able to re-compile NEMP-AGRIF-mono after NEMO-AGRIF-mpp'
+echo '#- I guess the good correction should be in AGRIF/LIB/toamr.c for the conv, to remove useless allocation declarations in AGRIF_INC'
+echo '# recompile all in this case' 
+echo "mpiagrif:"
+echo "ifeq (\$(AGRIF),use)"
+echo "ifeq (,\$(AGRIF_MPI))"
+echo '	@if [ -n "`cat KEY_CPP | grep key_mpp_mpi`" ]; then $(RM) -r OPAFILES model_tam.o $(MODDIR)/ocetam/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi'
+echo "endif"
+echo "endif"
+#-
+echo '# key changing control'
+echo "key: "
+echo "	@echo CHANGE of CPP KEYS yes/no ?"
+echo "	-@if [ \"\`cat KEY_CPP\`\" != \"\$(P_P:\$(prefix)%=%)\" ] ; then \\"
+echo "		echo CPP options changed ; echo \"\$(P_P:\$(prefix)%=%)\" > KEY_CPP ; fi "
+#-
+echo '# check key values'
+echo "keyverif:"
+echo '	@echo CHECKING KEY'
+echo '	@echo KEY USED : '
+echo '	@for v in ` echo $(P_P:$(prefix)%=%) ` ; \'
+echo '	do \'
+echo '	echo $$v ;\'
+echo '        w=`echo $$v | cut -c1-3` ; \'
+echo '        if [ $$w = `echo "key"` ] ; then \'
+echo '        r=n ; \'
+echo '        echo " $(KEY_LIST) " | (grep $$v >/dev/null 2>&1) || r=o ; \'
+echo '           if [ $$r != "n" ] ; then \'
+echo '              echo "UNKNOWN KEY" ;\'
+echo '              false ;  \'
+echo '              exit ;  \'
+echo '           fi \'
+echo '        fi \'
+echo '	done'
+echo '# Checking the number of routines'
+echo "src_file_list: "
+echo '	@echo CHECKING THE NUMBER AND NAMES OF SOURCE FILES '
+echo '	@$(RM) `ls | fgrep -v -f .patron` '
+echo '	@check=`grep OPA_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use OPA_SRC files"                ; \'
+echo '	    ln -sf ../../NEMO/OPA_SRC/*.[Ffh]90          . ; \'
+echo '	    ln -sf ../../NEMO/OPA_SRC/*/*.[Ffh]90      . ; \'
+echo '	fi '
+echo '	@check=`grep OPATAM_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use OPATAM_SRC files"                ; \'
+echo '	    ln -sf ../OPATAM_SRC/*.[Ffh]90          . ; \'
+echo '	    ln -sf ../OPATAM_SRC/*/*.[Ffh]90      . ; \'
+echo '	fi '
+echo '	@check=`grep LIM_SRC_2 .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use LIM_SRC_2 files"                ; \'
+echo '	    ln -sf ../../NEMO/LIM_SRC_2/*.[Ffh]90          . ; \'
+echo '	fi '
+echo '	@check=`grep C1D_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use C1D_SRC files"                ; \'
+echo '	    ln -sf ../../NEMO/C1D_SRC/*.[Ffh]90          . ; \'
+echo '	fi '
+echo '	@\$(RM) tmplist'
+echo '	@ls -1 | fgrep -v -f .patron  >tmplist'
+echo '	@cmp tmplist SRC_FILE_LIST.temp || { echo some routines have been added or suppressed ; \'
+echo '	sdiff -s tmplist SRC_FILE_LIST.temp ; cp tmplist SRC_FILE_LIST.temp ; \'
+echo '	\$(RM) model_tam.o \$(MODEL_LIB) \$(SXMODEL_LIB) \$(EXEC_BIN) ; \'
+echo '	echo "Rebuilding the AA_make files" ; \'
+echo '	cd ..  ; ../UTIL/fait_AA_make ; echo " " ; \'
+echo '	echo "THE ins_make COMMAND in modipsl/util MUST BE RERUN PLEASE DO SO BEFORE gmake" ; \'
+echo '	echo "========================================== " ; \'
+echo '	../../util/ins_make ; echo " " ;  false ; exit ; }'
+exec > /dev/null
+
Index: branches/TAM_V3_2_2/UTIL/fait_config_tam
===================================================================
--- branches/TAM_V3_2_2/UTIL/fait_config_tam	(revision 2578)
+++ branches/TAM_V3_2_2/UTIL/fait_config_tam	(revision 2578)
@@ -0,0 +1,143 @@
+#!/bin/ksh
+######################################################
+# Author : Rachid benshila for ESOPA
+# Contact : opatlod@lodyc.jussieu.fr
+#
+# This script aims to create the NEMOTAM/WORK directory 
+# with links to target directories for the sources
+# and to link in the WORK the BB_make and BB_make.ldef 
+# associated  to a chosen configuration
+#
+######################################################
+
+###################################
+#                                 #
+# Beginning of user modifications #
+#                                 #
+###################################
+#- Config name ---
+# To add a new configuration called NAME you have to change this script
+# 1. Add your configuration in LIST
+# 2. Add the directories needed for this config : set -A DIR_NAME DIR1 DIR2 ...
+# 3. Run fait_config NAME
+# If there is no directory config/NAME/scripts, and in this no BB_make.ldef, 
+# the config/ORCA2_TAM directory is copied under NAME
+#
+LIST="ORCA2_TAM"
+set -A DIR_ORCA2_TAM OPATAM_SRC OPA_SRC C1D_SRC
+###################################
+#                                 #
+#    End of user modifications    #
+#                                 #
+###################################
+
+
+#- Some tests ---
+d_n=$(dirname $0); b_n=$(basename $0);
+
+if   [ ${#} -gt 1 ]; then
+    echo 'Only one configuration can be specified in:' 1>&2;
+    echo $LIST 1>&2;
+    exit 3;
+elif [ ${#} -eq 1 ]; then
+     m_n="${1}"
+elif [ ${#} -eq 0 ]; then
+    echo 'You must specify one configuration in :' 1>&2;
+    echo $LIST 1>&2;
+    echo 'You can also complete fait_config to add a new one'
+    exit 3;
+fi
+
+#- Create the WORK --
+d_m=`find ${d_n}/.. -name NEMOTAM`  ;
+[ -d ${d_m}/WORK ] || mkdir ${d_m}/WORK;
+cd ${d_m}/WORK
+
+#- Clean links and librairies
+[ -f Makefile ] && gmake clean 
+[ -n "`\ls`" ] && \rm -rf * 
+
+#- Find the number of directories ---
+eval NDIR=\${#DIR_${m_n}[*]}
+
+#- Build a working array TAB containing the directories ---
+i=0
+while [ i -lt $NDIR ]
+do
+    eval  TAB[i]=\${DIR_${m_n}[i]}
+    let i=i+1
+done
+
+#- Creating the good links, at first on OPATAM_SRC ---
+if [ ${#TAB[*]} -ne 0 ] ; then
+    echo " Creating NEMOTAM/WORK = ${TAB[*]} for ${m_n}"
+
+    i=0
+    while [ i -lt $NDIR ]
+    do
+	[ ${#TAB[i]} -ne 0 ] && [ "${TAB[i]}" = "OPATAM_SRC" ] && ln -sf ../OPATAM_SRC/*.[Ffh]90 .
+	[ ${#TAB[i]} -ne 0 ] && [ "${TAB[i]}" = "OPATAM_SRC" ] && ln -sf ../OPATAM_SRC/*/*.[Ffh]90 . && break
+	let i=$i+1
+    done
+    i=0
+    while [ i -lt $NDIR ]
+    do
+        [ ${#TAB[i]} -ne 0 ] && [ "${TAB[i]}" = "OPA_SRC" ] && ln -sf ../../NEMO/OPA_SRC/*.[Ffh]90 .
+        [ ${#TAB[i]} -ne 0 ] && [ "${TAB[i]}" = "OPA_SRC" ] && ln -sf ../../NEMO/OPA_SRC/*/*.[Ffh]90 . && break
+        let i=$i+1
+    done
+    i=0
+    while [ i -lt $NDIR ]
+    do
+      if [ "${TAB[i]}" = "C1D_SRC" ]; then
+          ln -sf ../../NEMO/C1D_SRC/*.[Ffh]90 .
+      elif [ "${TAB[i]}" = "LIM_SRC_2" ]; then
+          ln -sf ../../NEMOLIM_SRC_2/*.[Ffh]90 . 
+      fi
+      let i=$i+1
+    done	 		
+
+    [ ! -d ../../../config/${m_n} ] && \cp -R ../../../config/ORCA2_TAM ../../../config/${m_n} 
+    ln -sf ../../../*/${m_n}/scripts/BB_make AA_make ; 
+    ln -sf ../../../*/${m_n}/scripts/BB_make.ldef AA_make.ldef ;
+
+else
+
+    echo "Configuration "${m_n}" not supported" 1>&2
+    echo 'Make your choice in :' 1>&2
+    echo $LIST 1>&2
+    echo 'You can also complete fait_config to add a new one'
+    exit 1
+
+fi 
+
+#- Building the standard list of source files ---
+cat >.patron <<"EOF" 
+CVS
+SRC_PARAM
+SRC_FILE_LIST
+tmplist
+AA_make
+KEY_CPP
+Makefile
+*?.o
+ i.?*
+*?.L
+.patron
+bloc.com
+para.com
+defcst.f
+fontbc.f
+icdyna.f
+thersf.f
+OPAFILES
+EOF
+ls -1 | fgrep -v -f .patron  >SRC_FILE_LIST ; cp SRC_FILE_LIST SRC_FILE_LIST.temp ;
+
+#- Writing KEY_CPP file ---
+sed -e /^P_P/\!d -e "s/P_P = //" AA_make.ldef > KEY_CPP;    
+
+#- Save new configuration an d directories names ---
+print ${m_n} ${TAB[*]} >.config 
+
+exit 0;
