Index: branches/2016/dev_CMCC_2016/DOC/Namelists/nam_tide
===================================================================
--- branches/2016/dev_CMCC_2016/DOC/Namelists/nam_tide	(revision 7298)
+++ branches/2016/dev_CMCC_2016/DOC/Namelists/nam_tide	(revision 7299)
@@ -1,8 +1,9 @@
 !-----------------------------------------------------------------------
-&nam_tide      !   tide parameters                                      ("key_tide")
+&nam_tide      !   tide parameters
 !-----------------------------------------------------------------------
-   ln_tide_pot = .true.    !  use tidal potential forcing
-   ln_tide_ramp= .false.   !
-   rdttideramp =    0.     !
-   clname(1)   = 'DUMMY'   !  name of constituent - all tidal components must be set in namelist_cfg
+   ln_tide       = .true.   !  Activate tide module
+   ln_tide_pot   = .true.   !  use tidal potential forcing
+   ln_tide_ramp  = .false.  !
+   rdttideramp   =    0.    !
+   clname(1)     = 'DUMMY'  !  name of constituent - all tidal components must be set in namelist_cfg
 /
Index: branches/2016/dev_CMCC_2016/DOC/Namelists/nambdy
===================================================================
--- branches/2016/dev_CMCC_2016/DOC/Namelists/nambdy	(revision 7298)
+++ branches/2016/dev_CMCC_2016/DOC/Namelists/nambdy	(revision 7299)
@@ -1,5 +1,6 @@
 !-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries                          ("key_bdy")
+&nambdy        !  unstructured open boundaries
 !-----------------------------------------------------------------------
+    ln_bdy         = .true.               !  Activate BDY module
     nb_bdy         = 0                    !  number of open boundary sets
     ln_coords_file = .true.               !  =T : read bdy coordinates from file
Index: branches/2016/dev_CMCC_2016/DOC/Namelists/nambdy_dta
===================================================================
--- branches/2016/dev_CMCC_2016/DOC/Namelists/nambdy_dta	(revision 7298)
+++ branches/2016/dev_CMCC_2016/DOC/Namelists/nambdy_dta	(revision 7299)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&nambdy_dta    !  open boundaries - external data                       ("key_bdy")
+&nambdy_dta    !  open boundaries - external data
 !-----------------------------------------------------------------------
 !              !  file name      ! frequency (hours) ! variable  ! time interp.!  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
Index: branches/2016/dev_CMCC_2016/DOC/TexFiles/Chapters/Chap_CFG.tex
===================================================================
--- branches/2016/dev_CMCC_2016/DOC/TexFiles/Chapters/Chap_CFG.tex	(revision 7298)
+++ branches/2016/dev_CMCC_2016/DOC/TexFiles/Chapters/Chap_CFG.tex	(revision 7299)
@@ -299,5 +299,5 @@
 In particular, the AMM uses $S$-coordinates in the vertical rather than
 $z$-coordinates and is forced with tidal lateral boundary conditions
-using a flather boundary condition from the BDY module (key\_bdy).
+using a flather boundary condition from the BDY module.
 The AMM configuration  uses the GLS (key\_zdfgls) turbulence scheme, the
 VVL non-linear free surface(key\_vvl) and time-splitting
@@ -306,5 +306,5 @@
 In addition to the tidal boundary condition the model may also take
 open boundary conditions from a North Atlantic model. Boundaries may be
-completely ommited by removing the BDY key (key\_bdy).
+completely omitted by setting \np{ln\_bdy} to false.
 Sample surface fluxes, river forcing and a sample initial restart file
 are included to test a realistic model run. The Baltic boundary is
Index: branches/2016/dev_CMCC_2016/DOC/TexFiles/Chapters/Chap_DYN.tex
===================================================================
--- branches/2016/dev_CMCC_2016/DOC/TexFiles/Chapters/Chap_DYN.tex	(revision 7298)
+++ branches/2016/dev_CMCC_2016/DOC/TexFiles/Chapters/Chap_DYN.tex	(revision 7299)
@@ -1209,5 +1209,5 @@
 into account when computing the surface pressure gradient.
 
-(2) When \np{ln\_tide\_pot}~=~true and \key{tide} is defined (see \S\ref{SBC_tide}), 
+(2) When \np{ln\_tide\_pot}~=~true and \np{ln\_tide}~=~true (see \S\ref{SBC_tide}), 
 the tidal potential is taken into account when computing the surface pressure gradient.
 
Index: branches/2016/dev_CMCC_2016/DOC/TexFiles/Chapters/Chap_LBC.tex
===================================================================
--- branches/2016/dev_CMCC_2016/DOC/TexFiles/Chapters/Chap_LBC.tex	(revision 7298)
+++ branches/2016/dev_CMCC_2016/DOC/TexFiles/Chapters/Chap_LBC.tex	(revision 7299)
@@ -350,5 +350,5 @@
 % Unstructured open boundaries BDY 
 % ====================================================================
-\section{Unstructured Open Boundary Conditions (\key{bdy}) (BDY)}
+\section{Unstructured Open Boundary Conditions (BDY)}
 \label{LBC_bdy}
 
@@ -368,5 +368,5 @@
 Options are defined through the \ngn{nambdy} \ngn{nambdy\_index} 
 \ngn{nambdy\_dta} \ngn{nambdy\_dta2} namelist variables.
-The BDY module is an alternative implementation of open boundary
+The BDY module is the core implementation of open boundary
 conditions for regional configurations. It implements the Flow
 Relaxation Scheme algorithm for temperature, salinity, velocities and
@@ -376,10 +376,9 @@
 an isobath or other irregular contour. 
 
-The BDY module was modelled on the OBC module and shares many features
-and a similar coding structure \citep{Chanut2005}.
-
-The BDY module is completely rewritten at NEMO 3.4 and there is a new
-set of namelists. Boundary data files used with earlier versions of
-NEMO may need to be re-ordered to work with this version. See the
+The BDY module was modelled on the OBC module (see NEMO 3.4) and shares many
+features and a similar coding structure \citep{Chanut2005}.
+
+Boundary data files used with earlier versions of NEMO may need
+to be re-ordered to work with this version. See the
 section on the Input Boundary Data Files for details.
 
@@ -388,4 +387,5 @@
 \label{BDY_namelist}
 
+The BDY module is activated by setting \np{ln\_bdy} to true.
 It is possible to define more than one boundary ``set'' and apply
 different boundary conditions to each set. The number of boundary
Index: branches/2016/dev_CMCC_2016/DOC/TexFiles/Chapters/Chap_SBC.tex
===================================================================
--- branches/2016/dev_CMCC_2016/DOC/TexFiles/Chapters/Chap_SBC.tex	(revision 7298)
+++ branches/2016/dev_CMCC_2016/DOC/TexFiles/Chapters/Chap_SBC.tex	(revision 7299)
@@ -776,5 +776,5 @@
 
 A module is available to compute the tidal potential and use it in the momentum equation.
-This option is activated when \key{tide} is defined.
+This option is activated when \np{ln\_tide} is set to true in \ngn{nam\_tide}.
 
 Some parameters are available in namelist \ngn{nam\_tide}:
Index: branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/AMM12/EXP00/namelist_cfg
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/AMM12/EXP00/namelist_cfg	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/AMM12/EXP00/namelist_cfg	(revision 7299)
@@ -189,6 +189,7 @@
 /
 !-----------------------------------------------------------------------
-&nam_tide      !   tide parameters (#ifdef key_tide)
-!-----------------------------------------------------------------------
+&nam_tide      !   tide parameters
+!-----------------------------------------------------------------------
+   ln_tide     = .true.
    clname(1)     =   'Q1'   !  name of constituent
    clname(2)     =   'O1'
@@ -208,5 +209,6 @@
 /
 !-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries                          ("key_bdy")
+&nambdy        !  unstructured open boundaries
+    ln_bdy         = .true.
     nb_bdy         =  1
     cn_dyn2d       = 'flather'
@@ -216,5 +218,5 @@
 /
 !-----------------------------------------------------------------------
-&nambdy_dta      !  open boundaries - external data           ("key_bdy")
+&nambdy_dta      !  open boundaries - external data
 !-----------------------------------------------------------------------
 !          !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
Index: branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/AMM12/cpp_AMM12.fcm
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/AMM12/cpp_AMM12.fcm	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/AMM12/cpp_AMM12.fcm	(revision 7299)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys  key_bdy key_tide key_zdfgls key_diainstant key_mpp_mpi key_iomput
+ bld::tool::fppkeys key_zdfgls key_diainstant key_mpp_mpi key_iomput
Index: branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/C1D_PAPA/EXP00/namelist_cfg
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/C1D_PAPA/EXP00/namelist_cfg	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/C1D_PAPA/EXP00/namelist_cfg	(revision 7299)
@@ -174,13 +174,13 @@
 /
 !-----------------------------------------------------------------------
-&nam_tide      !    tide parameters (#ifdef key_tide)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries                          ("key_bdy")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy_dta      !  open boundaries - external data           ("key_bdy")
+&nam_tide      !    tide parameters
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy        !  unstructured open boundaries                          
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy_dta      !  open boundaries - external data           
 !-----------------------------------------------------------------------
 /
Index: branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/GYRE/EXP00/namelist_cfg
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/GYRE/EXP00/namelist_cfg	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/GYRE/EXP00/namelist_cfg	(revision 7299)
@@ -154,13 +154,13 @@
 /
 !-----------------------------------------------------------------------
-&nam_tide      !    tide parameters (#ifdef key_tide)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries                          ("key_bdy")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy_dta      !  open boundaries - external data           ("key_bdy")
+&nam_tide      !    tide parameters
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy        !  unstructured open boundaries                          
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy_dta      !  open boundaries - external data           
 !-----------------------------------------------------------------------
 /
Index: branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg	(revision 7299)
@@ -159,13 +159,13 @@
 /
 !-----------------------------------------------------------------------
-&nam_tide      !    tide parameters (#ifdef key_tide)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries                          ("key_bdy")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy_dta      !  open boundaries - external data           ("key_bdy")
+&nam_tide      !    tide parameters
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy        !  unstructured open boundaries                          
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy_dta      !  open boundaries - external data           
 !-----------------------------------------------------------------------
 /
Index: branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/GYRE_XIOS/EXP00/namelist_cfg
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/GYRE_XIOS/EXP00/namelist_cfg	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/GYRE_XIOS/EXP00/namelist_cfg	(revision 7299)
@@ -152,13 +152,13 @@
 /
 !-----------------------------------------------------------------------
-&nam_tide      !    tide parameters (#ifdef key_tide)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries                          ("key_bdy")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy_dta      !  open boundaries - external data           ("key_bdy")
+&nam_tide      !    tide parameters
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy        !  unstructured open boundaries                          
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy_dta      !  open boundaries - external data           
 !-----------------------------------------------------------------------
 /
Index: branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/1_namelist_cfg
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/1_namelist_cfg	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/1_namelist_cfg	(revision 7299)
@@ -305,6 +305,6 @@
 !!   namlbc        lateral momentum boundary condition
 !!   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")
+!!   nambdy        Unstructured open boundaries
+!!   namtide       Tidal forcing at open boundaries
 !!======================================================================
 !
@@ -324,6 +324,7 @@
 /
 !-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries                          ("key_bdy")
-!-----------------------------------------------------------------------
+&nambdy        !  unstructured open boundaries
+!-----------------------------------------------------------------------
+    ln_bdy         = .false.              !  Use unstructured open boundaries
     nb_bdy = 1                            !  number of open boundary sets       
     ln_coords_file = .true.               !  =T : read bdy coordinates from file
@@ -351,5 +352,5 @@
 /
 !-----------------------------------------------------------------------
-&nambdy_dta      !  open boundaries - external data           ("key_bdy")
+&nambdy_dta      !  open boundaries - external data
 !-----------------------------------------------------------------------
 !              !   file name    ! frequency (hours) !  variable  ! time interpol. !  clim   ! 'yearly'/ ! weights  ! rotation !
Index: branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/namelist_cfg
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/namelist_cfg	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/ORCA2_LIM_CFC_C14b/EXP00/namelist_cfg	(revision 7299)
@@ -138,13 +138,13 @@
 /
 !-----------------------------------------------------------------------
-&nam_tide      !   tide parameters (#ifdef key_tide)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries                          ("key_bdy")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy_dta      !  open boundaries - external data           ("key_bdy")
+&nam_tide      !   tide parameters
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy        !  unstructured open boundaries                          
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy_dta      !  open boundaries - external data           
 !-----------------------------------------------------------------------
 /
Index: branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/SHARED/namelist_ref
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 7299)
@@ -589,7 +589,7 @@
 !!   namagrif      agrif nested grid ( read by child model only )       ("key_agrif")
 !!   nam_tide      Tidal forcing 
-!!   nambdy        Unstructured open boundaries                         ("key_bdy")
-!!   nambdy_dta    Unstructured open boundaries - external data         ("key_bdy")
-!!   nambdy_tide   tidal forcing at open boundaries                     ("key_bdy_tides")
+!!   nambdy        Unstructured open boundaries                         
+!!   nambdy_dta    Unstructured open boundaries - external data         
+!!   nambdy_tide   tidal forcing at open boundaries                     
 !!======================================================================
 !
@@ -611,6 +611,7 @@
 /
 !-----------------------------------------------------------------------
-&nam_tide      !   tide parameters                                      ("key_tide")
-!-----------------------------------------------------------------------
+&nam_tide      !   tide parameters
+!-----------------------------------------------------------------------
+   ln_tide     = .false.
    ln_tide_pot = .true.    !  use tidal potential forcing
    ln_tide_ramp= .false.   !
@@ -619,6 +620,7 @@
 /
 !-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries                          ("key_bdy")
-!-----------------------------------------------------------------------
+&nambdy        !  unstructured open boundaries                          
+!-----------------------------------------------------------------------
+    ln_bdy         = .false.              !  Use unstructured open boundaries
     nb_bdy         = 0                    !  number of open boundary sets
     ln_coords_file = .true.               !  =T : read bdy coordinates from file
@@ -653,5 +655,5 @@
 /
 !-----------------------------------------------------------------------
-&nambdy_dta    !  open boundaries - external data                       ("key_bdy")
+&nambdy_dta    !  open boundaries - external data                       
 !-----------------------------------------------------------------------
 !              !  file name      ! frequency (hours) ! variable  ! time interp.!  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/LIM_SRC_3/limcons.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/LIM_SRC_3/limcons.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/LIM_SRC_3/limcons.F90	(revision 7299)
@@ -286,5 +286,4 @@
       REAL(wp), PARAMETER             :: zconv = 1.e-9 ! convert W to GW and kg to Mt
 
-#if ! defined key_bdy
       ! heat flux
       zhfx  = glob_sum( ( hfx_in - hfx_out - diag_heat - diag_trp_ei - diag_trp_es - SUM( qevap_ice * a_i_b, dim=3 ) )  &
@@ -304,5 +303,4 @@
       IF( ABS( zsfx ) > zs_sill ) WRITE(numout,*) 'violation sfx    [psu*Mt/day]   (',cd_routine,')  = ',(zsfx)
       IF( ABS( zhfx ) > zh_sill ) WRITE(numout,*) 'violation hfx    [GW]           (',cd_routine,')  = ',(zhfx)
-#endif
 
    END SUBROUTINE lim_cons_final
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90	(revision 7299)
@@ -41,7 +41,6 @@
    USE agrif_lim2_interp
 #endif
-#if defined key_bdy
+   USE bdy_oce   , ONLY: ln_bdy
    USE bdyice_lim
-#endif
 
    IMPLICIT NONE
@@ -460,7 +459,5 @@
             CALL agrif_rhg_lim2( jter, nn_nevp, 'U' )
 #endif
-#if defined key_bdy
-         CALL bdy_ice_lim_dyn( 'U' )
-#endif         
+         IF( ln_bdy ) CALL bdy_ice_lim_dyn( 'U' )
 
             DO jj = k_j1+1, k_jpj-1
@@ -486,7 +483,5 @@
             CALL agrif_rhg_lim2( jter, nn_nevp, 'V' )
 #endif
-#if defined key_bdy
-         CALL bdy_ice_lim_dyn( 'V' )
-#endif         
+         IF( ln_bdy ) CALL bdy_ice_lim_dyn( 'V' )
 
          ELSE 
@@ -513,7 +508,5 @@
             CALL agrif_rhg_lim2( jter, nn_nevp, 'V' )
 #endif
-#if defined key_bdy
-         CALL bdy_ice_lim_dyn( 'V' )
-#endif         
+         IF( ln_bdy ) CALL bdy_ice_lim_dyn( 'V' )
 
             DO jj = k_j1+1, k_jpj-1
@@ -538,7 +531,5 @@
             CALL agrif_rhg_lim2( jter, nn_nevp, 'U' )
 #endif
-#if defined key_bdy
-         CALL bdy_ice_lim_dyn( 'U' )
-#endif         
+         IF( ln_bdy ) CALL bdy_ice_lim_dyn( 'U' )
 
          ENDIF
@@ -577,8 +568,7 @@
       CALL agrif_rhg_lim2( nn_nevp , nn_nevp, 'V' )
 #endif
-#if defined key_bdy
-      CALL bdy_ice_lim_dyn( 'U' )
-      CALL bdy_ice_lim_dyn( 'V' )
-#endif         
+      IF( ln_bdy ) THEN
+         CALL bdy_ice_lim_dyn( 'U' ) ; CALL bdy_ice_lim_dyn( 'V' )
+      ENDIF
 
       DO jj = k_j1+1, k_jpj-1 
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90	(revision 7299)
@@ -36,4 +36,5 @@
    USE limctl         ! 
    USE limcons        ! 
+   USE bdy_oce  , ONLY: ln_bdy
    !
    USE in_out_manager ! I/O manager
@@ -221,5 +222,5 @@
 
       ! conservation test
-      IF( ln_limdiahsb )   CALL lim_cons_final( 'limsbc' )
+      IF( ln_limdiahsb .AND. .NOT. ln_bdy)   CALL lim_cons_final( 'limsbc' )
 
       ! control prints
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/NST_SRC/agrif_user.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 7299)
@@ -61,5 +61,5 @@
    USE nemogcm
    USE tradmp
-   USE bdy_par
+   USE bdy_oce   , ONLY: ln_bdy
 
    IMPLICIT NONE
@@ -78,5 +78,5 @@
    ln_tradmp = .FALSE.
    ! no open boundary on fine grids
-   lk_bdy = .FALSE.
+   ln_bdy = .FALSE.
 
 
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 7299)
@@ -10,14 +10,12 @@
    !!            3.6  !  2014-01  (C. Rousset) add ice boundary conditions for lim3
    !!----------------------------------------------------------------------
-#if defined key_bdy 
-   !!----------------------------------------------------------------------
-   !!   'key_bdy'                      Unstructured Open Boundary Condition
-   !!----------------------------------------------------------------------
    USE par_oce         ! ocean parameters
-   USE bdy_par         ! Unstructured boundary parameters
    USE lib_mpp         ! distributed memory computing
 
    IMPLICIT NONE
    PUBLIC
+
+   INTEGER, PUBLIC, PARAMETER ::   jp_bdy  = 10       !: Maximum number of bdy sets
+   INTEGER, PUBLIC, PARAMETER ::   jpbgrd  = 3        !: Number of horizontal grid types used  (T, U, V)
 
    TYPE, PUBLIC ::   OBC_INDEX    !: Indices and weights which define the open boundary
@@ -82,4 +80,6 @@
    !! Namelist variables
    !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC            ::   ln_bdy                   !: Unstructured Ocean Boundary Condition
+
    CHARACTER(len=80), DIMENSION(jp_bdy) ::   cn_coords_file !: Name of bdy coordinates file
    CHARACTER(len=80)                    ::   cn_mask_file   !: Name of bdy mask file
@@ -166,11 +166,4 @@
    END FUNCTION bdy_oce_alloc
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module                NO Unstructured Open Boundary Condition
-   !!----------------------------------------------------------------------
-   LOGICAL ::   ln_tides = .false.  !: =T apply tidal harmonic forcing along open boundaries
-#endif
-
    !!======================================================================
 END MODULE bdy_oce
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_par.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_par.F90	(revision 7298)
+++ 	(revision )
@@ -1,43 +1,0 @@
-MODULE bdy_par
-   !!======================================================================
-   !!                      ***  MODULE bdy_par   ***
-   !! Unstructured Open Boundary Cond. :   define related parameters
-   !!======================================================================
-   !! History :  1.0  !  2005-01  (J. Chanut, A. Sellar)  Original code
-   !!            3.0  !  2008-04  (NEMO team)  add in the reference version
-   !!            3.3  !  2010-09  (D. Storkey and E. O'Dea) update for Shelf configurations
-   !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
-   !!----------------------------------------------------------------------
-#if defined   key_bdy
-   !!----------------------------------------------------------------------
-   !!   'key_bdy' :                    Unstructured Open Boundary Condition
-   !!----------------------------------------------------------------------
-
-   IMPLICIT NONE
-   PUBLIC
-
-# if ! defined key_agrif
-   LOGICAL, PUBLIC, PARAMETER ::   lk_bdy  = .TRUE.   !: Unstructured Ocean Boundary Condition flag
-# else
-   LOGICAL, PUBLIC            ::   lk_bdy  = .TRUE.   !: Unstructured Ocean Boundary Condition flag
-# endif
-   INTEGER, PUBLIC, PARAMETER ::   jp_bdy  = 10       !: Maximum number of bdy sets
-   INTEGER, PUBLIC, PARAMETER ::   jpbgrd  = 3	      !: Number of horizontal grid types used  (T, U, V)
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :            NO Unstructured open boundary condition
-   !!----------------------------------------------------------------------
-# if ! defined key_agrif
-   LOGICAL, PUBLIC, PARAMETER ::   lk_bdy  = .FALSE.   !: Unstructured Ocean Boundary Condition flag
-# else
-   LOGICAL, PUBLIC            ::   lk_bdy  = .FALSE.   !: Unstructured Ocean Boundary Condition flag
-# endif
-#endif
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!======================================================================
-END MODULE bdy_par
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 7299)
@@ -12,8 +12,4 @@
    !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
    !!            3.6  !  2012-01  (C. Rousset) add ice boundary conditions for lim3
-   !!----------------------------------------------------------------------
-#if defined key_bdy
-   !!----------------------------------------------------------------------
-   !!   'key_bdy'                     Open Boundary Conditions
    !!----------------------------------------------------------------------
    !!    bdy_dta        : read external data along open boundaries from file
@@ -36,4 +32,5 @@
 #endif
    USE sbcapr
+   USE sbctide         ! Tidal forcing or not
 
    IMPLICIT NONE
@@ -381,21 +378,21 @@
       END DO  ! ib_bdy
 
-#if defined key_tide
-      IF (ln_dynspg_ts) THEN      ! Fill temporary arrays with slow-varying bdy data                           
-         DO ib_bdy = 1, nb_bdy    ! Tidal component added in ts loop
-            IF ( nn_dyn2d_dta(ib_bdy) .ge. 2 ) THEN
-               nblen => idx_bdy(ib_bdy)%nblen
-               nblenrim => idx_bdy(ib_bdy)%nblenrim
-               IF( cn_dyn2d(ib_bdy) == 'frs' ) THEN; ilen1(:)=nblen(:) ; ELSE ; ilen1(:)=nblenrim(:) ; ENDIF 
-               IF ( dta_bdy(ib_bdy)%ll_ssh ) dta_bdy_s(ib_bdy)%ssh(1:ilen1(1)) = dta_bdy(ib_bdy)%ssh(1:ilen1(1))
-               IF ( dta_bdy(ib_bdy)%ll_u2d ) dta_bdy_s(ib_bdy)%u2d(1:ilen1(2)) = dta_bdy(ib_bdy)%u2d(1:ilen1(2))
-               IF ( dta_bdy(ib_bdy)%ll_v2d ) dta_bdy_s(ib_bdy)%v2d(1:ilen1(3)) = dta_bdy(ib_bdy)%v2d(1:ilen1(3))
-            ENDIF
-         END DO
-      ELSE ! Add tides if not split-explicit free surface else this is done in ts loop
-         !
-         CALL bdy_dta_tides( kt=kt, time_offset=time_offset )
+      IF ( ln_tide ) THEN
+         IF (ln_dynspg_ts) THEN      ! Fill temporary arrays with slow-varying bdy data                           
+            DO ib_bdy = 1, nb_bdy    ! Tidal component added in ts loop
+               IF ( nn_dyn2d_dta(ib_bdy) .ge. 2 ) THEN
+                  nblen => idx_bdy(ib_bdy)%nblen
+                  nblenrim => idx_bdy(ib_bdy)%nblenrim
+                  IF( cn_dyn2d(ib_bdy) == 'frs' ) THEN; ilen1(:)=nblen(:) ; ELSE ; ilen1(:)=nblenrim(:) ; ENDIF 
+                  IF ( dta_bdy(ib_bdy)%ll_ssh ) dta_bdy_s(ib_bdy)%ssh(1:ilen1(1)) = dta_bdy(ib_bdy)%ssh(1:ilen1(1))
+                  IF ( dta_bdy(ib_bdy)%ll_u2d ) dta_bdy_s(ib_bdy)%u2d(1:ilen1(2)) = dta_bdy(ib_bdy)%u2d(1:ilen1(2))
+                  IF ( dta_bdy(ib_bdy)%ll_v2d ) dta_bdy_s(ib_bdy)%v2d(1:ilen1(3)) = dta_bdy(ib_bdy)%v2d(1:ilen1(3))
+               ENDIF
+            END DO
+         ELSE ! Add tides if not split-explicit free surface else this is done in ts loop
+            !
+            CALL bdy_dta_tides( kt=kt, time_offset=time_offset )
+         ENDIF
       ENDIF
-#endif
 
       IF ( ln_apr_obc ) THEN
@@ -899,20 +896,4 @@
    END SUBROUTINE bdy_dta_init
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module                   NO Open Boundary Conditions
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE bdy_dta( kt, jit, time_offset ) ! Empty routine
-      INTEGER, INTENT( in )           ::   kt    
-      INTEGER, INTENT( in ), OPTIONAL ::   jit   
-      INTEGER, INTENT( in ), OPTIONAL ::   time_offset
-      WRITE(*,*) 'bdy_dta: You should not have seen this print! error?', kt
-   END SUBROUTINE bdy_dta
-   SUBROUTINE bdy_dta_init()                  ! Empty routine
-      WRITE(*,*) 'bdy_dta_init: You should not have seen this print! error?'
-   END SUBROUTINE bdy_dta_init
-#endif
-
    !!==============================================================================
 END MODULE bdydta
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90	(revision 7299)
@@ -11,8 +11,4 @@
    !!            3.3  !  2010-09  (D.Storkey) add ice boundary conditions
    !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
-   !!----------------------------------------------------------------------
-#if defined key_bdy 
-   !!----------------------------------------------------------------------
-   !!   'key_bdy' :                    Unstructured Open Boundary Condition
    !!----------------------------------------------------------------------
    !!   bdy_dyn        : split velocities into barotropic and baroclinic parts
@@ -137,14 +133,4 @@
    END SUBROUTINE bdy_dyn
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module                   NO Unstruct Open Boundary Conditions
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE bdy_dyn( kt )      ! Empty routine
-      WRITE(*,*) 'bdy_dyn: You should not have seen this print! error?', kt
-   END SUBROUTINE bdy_dyn
-#endif
-
    !!======================================================================
 END MODULE bdydyn
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn2d.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn2d.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn2d.F90	(revision 7299)
@@ -7,8 +7,4 @@
    !!            3.5  !  2012     (S. Mocavero, I. Epicoco) Optimization of BDY communications
    !!            3.5  !  2013-07  (J. Chanut) Compliant with time splitting changes
-   !!----------------------------------------------------------------------
-#if defined key_bdy 
-   !!----------------------------------------------------------------------
-   !!   'key_bdy' :                    Unstructured Open Boundary Condition
    !!----------------------------------------------------------------------
    !!   bdy_dyn2d          : Apply open boundary conditions to barotropic variables.
@@ -310,16 +306,4 @@
    END SUBROUTINE bdy_ssh
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module                   NO Unstruct Open Boundary Conditions
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE bdy_dyn2d( kt )      ! Empty routine
-      INTEGER, intent(in) :: kt
-      WRITE(*,*) 'bdy_dyn2d: You should not have seen this print! error?', kt
-   END SUBROUTINE bdy_dyn2d
-
-#endif
-
    !!======================================================================
 END MODULE bdydyn2d
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn3d.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn3d.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn3d.F90	(revision 7299)
@@ -6,8 +6,4 @@
    !! History :  3.4  !  2011     (D. Storkey) new module as part of BDY rewrite 
    !!            3.5  !  2012     (S. Mocavero, I. Epicoco) Optimization of BDY communications
-   !!----------------------------------------------------------------------
-#if defined key_bdy 
-   !!----------------------------------------------------------------------
-   !!   'key_bdy' :                    Unstructured Open Boundary Condition
    !!----------------------------------------------------------------------
    !!   bdy_dyn3d        : apply open boundary conditions to baroclinic velocities
@@ -296,17 +292,4 @@
    END SUBROUTINE bdy_dyn3d_dmp
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module                   NO Unstruct Open Boundary Conditions
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE bdy_dyn3d( kt )      ! Empty routine
-      WRITE(*,*) 'bdy_dyn3d: You should not have seen this print! error?', kt
-   END SUBROUTINE bdy_dyn3d
-   SUBROUTINE bdy_dyn3d_dmp( kt )      ! Empty routine
-      WRITE(*,*) 'bdy_dyn3d_dmp: You should not have seen this print! error?', kt
-   END SUBROUTINE bdy_dyn3d_dmp
-#endif
-
    !!======================================================================
 END MODULE bdydyn3d
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90	(revision 7299)
@@ -8,7 +8,6 @@
    !!              -   !  2012-01 (C. Rousset)  add lim3 and remove useless jk loop 
    !!----------------------------------------------------------------------
-#if defined   key_bdy   &&  ( defined key_lim2 || defined key_lim3 )
-   !!----------------------------------------------------------------------
-   !!   'key_bdy'            and                 Unstructured Open Boundary Conditions
+#if defined key_lim2 || defined key_lim3
+   !!----------------------------------------------------------------------
    !!   'key_lim2'                                                 LIM-2 sea ice model
    !!   'key_lim3'                                                 LIM-3 sea ice model
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 7299)
@@ -13,8 +13,5 @@
    !!            3.4  !  2012     (J. Chanut) straight open boundary case update
    !!            3.5  !  2012     (S. Mocavero, I. Epicoco) optimization of BDY communications
-   !!----------------------------------------------------------------------
-#if defined key_bdy
-   !!----------------------------------------------------------------------
-   !!   'key_bdy'                     Unstructured Open Boundary Conditions
+   !!            3.7  !  2016     (T. Lovato) Remove bdy macro, call here init for dta and tides
    !!----------------------------------------------------------------------
    !!   bdy_init      : Initialization of unstructured open boundaries
@@ -23,5 +20,7 @@
    USE dom_oce        ! ocean space and time domain
    USE bdy_oce        ! unstructured open boundary conditions
-   USE sbctide  , ONLY: lk_tide ! Tidal forcing or not
+   USE bdydta         ! open boundary cond. setting   (bdy_dta_init routine)
+   USE bdytides       ! open boundary cond. setting   (bdytide_init routine)
+   USE sbctide        ! Tidal forcing or not
    USE phycst   , ONLY: rday
    !
@@ -53,11 +52,75 @@
    !!----------------------------------------------------------------------
 CONTAINS
-   
+
    SUBROUTINE bdy_init
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE bdy_init  ***
+      !!
+      !! ** Purpose :   Initialization of the dynamics and tracer fields with
+      !!              unstructured open boundaries.
+      !!
+      !! ** Method  :   Read initialization arrays (mask, indices) to identify
+      !!              an unstructured open boundary
+      !!
+      !! ** Input   :  bdy_init.nc, input file for unstructured open boundaries
+      !!----------------------------------------------------------------------
+      NAMELIST/nambdy/ ln_bdy, nb_bdy, ln_coords_file, cn_coords_file,         &
+         &             ln_mask_file, cn_mask_file, cn_dyn2d, nn_dyn2d_dta,     &
+         &             cn_dyn3d, nn_dyn3d_dta, cn_tra, nn_tra_dta,             &
+         &             ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp, rn_time_dmp_out, &
+         &             cn_ice_lim, nn_ice_lim_dta,                             &
+         &             rn_ice_tem, rn_ice_sal, rn_ice_age,                     &
+         &             ln_vol, nn_volctl, nn_rimwidth
+         !
+      INTEGER  ::   ios                 ! Local integer output status for namelist read
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('bdy_init')
+
+      ! ------------------------
+      ! Read namelist parameters
+      ! ------------------------
+      REWIND( numnam_ref )              ! Namelist nambdy in reference namelist :Unstructured open boundaries
+      READ  ( numnam_ref, nambdy, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy in reference namelist', lwp )
+      !
+      REWIND( numnam_cfg )              ! Namelist nambdy in configuration namelist :Unstructured open boundaries
+      READ  ( numnam_cfg, nambdy, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, nambdy )
+
+      ! -----------------------------------------
+      ! unstructured open boundaries use control
+      ! -----------------------------------------
+      IF ( ln_bdy ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'bdy_init : initialization of open boundaries'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~'
+         !
+         ! Open boundaries definition (arrays and masks)
+         CALL bdy_segs
+         !
+         ! Open boundaries initialisation of external data arrays
+         CALL bdy_dta_init
+         !
+         ! Open boundaries initialisation of tidal harmonic forcing
+         IF( ln_tide ) CALL bdytide_init
+         !
+      ELSE
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'bdy_init : open boundaries not used (ln_bdy = F)'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~'
+         !
+      ENDIF
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_init')
+      !
+   END SUBROUTINE bdy_init
+   
+   SUBROUTINE bdy_segs
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE bdy_init  ***
       !!         
-      !! ** Purpose :   Initialization of the dynamics and tracer fields with 
-      !!              unstructured open boundaries.
+      !! ** Purpose :   Definition of unstructured open boundaries.
       !!
       !! ** Method  :   Read initialization arrays (mask, indices) to identify 
@@ -90,48 +153,20 @@
       REAL(wp), POINTER, DIMENSION(:,:)       ::   zfmask  ! temporary fmask array excluding coastal boundary condition (shlat)
       !!
-      CHARACTER(LEN=80),DIMENSION(jpbgrd)  ::   clfile     ! Namelist variables
       CHARACTER(LEN=1)                     ::   ctypebdy   !     -        - 
       INTEGER                              ::   nbdyind, nbdybeg, nbdyend
       !!
-      NAMELIST/nambdy/ nb_bdy, ln_coords_file, cn_coords_file,                 &
-         &             ln_mask_file, cn_mask_file, cn_dyn2d, nn_dyn2d_dta,     &
-         &             cn_dyn3d, nn_dyn3d_dta, cn_tra, nn_tra_dta,             &  
-         &             ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp, rn_time_dmp_out, &
-         &             cn_ice_lim, nn_ice_lim_dta,                           &
-         &             rn_ice_tem, rn_ice_sal, rn_ice_age,                 &
-         &             ln_vol, nn_volctl, nn_rimwidth
-         !
       NAMELIST/nambdy_index/ ctypebdy, nbdyind, nbdybeg, nbdyend
       INTEGER  ::   ios                 ! Local integer output status for namelist read
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('bdy_init')
-      !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'bdy_init : initialization of open boundaries'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~'
-      !
-      IF( jperio /= 0 )   CALL ctl_stop( 'Cyclic or symmetric,',   &
-         &                               ' and general open boundary condition are not compatible' )
-
+      IF( nn_timing == 1 )   CALL timing_start('bdy_segs')
+      !
       cgrid = (/'t','u','v'/)
-      
-      ! ------------------------
-      ! Read namelist parameters
-      ! ------------------------
-      REWIND( numnam_ref )              ! Namelist nambdy in reference namelist :Unstructured open boundaries  
-      READ  ( numnam_ref, nambdy, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy in reference namelist', lwp )
-      !
-      REWIND( numnam_cfg )              ! Namelist nambdy in configuration namelist :Unstructured open boundaries
-      READ  ( numnam_cfg, nambdy, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy in configuration namelist', lwp )
-      IF(lwm) WRITE ( numond, nambdy )
 
       ! -----------------------------------------
       ! Check and write out namelist parameters
       ! -----------------------------------------
-      !                                   ! control prints
-      IF(lwp) WRITE(numout,*) '   nambdy'
+      IF( jperio /= 0 )   CALL ctl_stop( 'bdy_segs: Cyclic or symmetric,',   &
+         &                               ' and general open boundary condition are not compatible' )
 
       IF( nb_bdy == 0 ) THEN 
@@ -189,6 +224,6 @@
               CASE DEFAULT   ;   CALL ctl_stop( 'nn_dyn2d_dta must be between 0 and 3' )
            END SELECT
-           IF (( nn_dyn2d_dta(ib_bdy) .ge. 2 ).AND.(.NOT.lk_tide)) THEN
-             CALL ctl_stop( 'You must activate key_tide to add tidal forcing at open boundaries' )
+           IF (( nn_dyn2d_dta(ib_bdy) .ge. 2 ).AND.(.NOT.ln_tide)) THEN
+             CALL ctl_stop( 'You must activate with ln_tide to add tidal forcing at open boundaries' )
            ENDIF
         ENDIF
@@ -839,5 +874,5 @@
                IF(lwp) THEN         ! Since all procs read global data only need to do this check on one proc...
                   IF( nbrdta(ib,igrd,ib_bdy) < nbrdta(ibm1,igrd,ib_bdy) ) THEN
-                     CALL ctl_stop('bdy_init : ERROR : boundary data in file must be defined ', &
+                     CALL ctl_stop('bdy_segs : ERROR : boundary data in file must be defined ', &
                           &        ' in order of distance from edge nbr A utility for re-ordering ', &
                           &        ' boundary coordinates and data files exists in the TOOLS/OBC directory')
@@ -1300,8 +1335,7 @@
       CALL wrk_dealloc(jpi,jpj,   zfmask ) 
       !
-      IF( nn_timing == 1 )   CALL timing_stop('bdy_init')
-      !
-   END SUBROUTINE bdy_init
-
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_segs')
+      !
+   END SUBROUTINE bdy_segs
 
    SUBROUTINE bdy_ctl_seg
@@ -1713,13 +1747,4 @@
    END SUBROUTINE bdy_ctl_corn
 
-#else
-   !!---------------------------------------------------------------------------------
-   !!   Dummy module                                   NO open boundaries
-   !!---------------------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE bdy_init      ! Dummy routine
-   END SUBROUTINE bdy_init
-#endif
-
    !!=================================================================================
 END MODULE bdyini
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdylib.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdylib.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdylib.F90	(revision 7299)
@@ -5,8 +5,6 @@
    !!======================================================================
    !! History :  3.6  !  2013     (D. Storkey) original code
+   !!            4.0  !  2014     (T. Lovato) Generalize OBC structure
    !!----------------------------------------------------------------------
-#if defined key_bdy 
-   !!----------------------------------------------------------------------
-   !!   'key_bdy' :                    Unstructured Open Boundary Condition
    !!----------------------------------------------------------------------
    !!   bdy_orlanski_2d
@@ -25,13 +23,150 @@
    PRIVATE
 
-   PUBLIC   bdy_orlanski_2d     ! routine called where?
-   PUBLIC   bdy_orlanski_3d     ! routine called where?
+   PUBLIC   bdy_frs, bdy_spe, bdy_nmn, bdy_orl
+   PUBLIC   bdy_orlanski_2d
+   PUBLIC   bdy_orlanski_3d
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2016)
    !! $Id$ 
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 CONTAINS
+
+   SUBROUTINE bdy_frs( idx, pta, dta )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_frs  ***
+      !!
+      !! ** Purpose : Apply the Flow Relaxation Scheme for tracers at open boundaries.
+      !!
+      !! Reference : Engedahl H., 1995, Tellus, 365-382.
+      !!----------------------------------------------------------------------
+      TYPE(OBC_INDEX),                     INTENT(in) ::   idx  ! OBC indices
+      REAL(wp), DIMENSION(:,:),            INTENT(in) ::   dta  ! OBC external data
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pta  ! tracer trend
+      !!
+      REAL(wp) ::   zwgt           ! boundary weight
+      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
+      INTEGER  ::   ii, ij         ! 2D addresses
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('bdy_frs')
+      ! 
+      igrd = 1                       ! Everything is at T-points here
+      DO ib = 1, idx%nblen(igrd)
+         DO ik = 1, jpkm1
+            ii = idx%nbi(ib,igrd) 
+            ij = idx%nbj(ib,igrd)
+            zwgt = idx%nbw(ib,igrd)
+            pta(ii,ij,ik) = ( pta(ii,ij,ik) + zwgt * (dta(ib,ik) - pta(ii,ij,ik) ) ) * tmask(ii,ij,ik)
+         END DO
+      END DO
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_frs')
+      !
+   END SUBROUTINE bdy_frs
+
+   SUBROUTINE bdy_spe( idx, pta, dta )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_spe  ***
+      !!
+      !! ** Purpose : Apply a specified value for tracers at open boundaries.
+      !!
+      !!----------------------------------------------------------------------
+      TYPE(OBC_INDEX),                     INTENT(in) ::   idx  ! OBC indices
+      REAL(wp), DIMENSION(:,:),            INTENT(in) ::   dta  ! OBC external data
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pta  ! tracer trend
+      !!
+      REAL(wp) ::   zwgt           ! boundary weight
+      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
+      INTEGER  ::   ii, ij         ! 2D addresses
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('bdy_spe')
+      !
+      igrd = 1                       ! Everything is at T-points here
+      DO ib = 1, idx%nblenrim(igrd)
+         ii = idx%nbi(ib,igrd)
+         ij = idx%nbj(ib,igrd)
+         DO ik = 1, jpkm1
+            pta(ii,ij,ik) = dta(ib,ik) * tmask(ii,ij,ik)
+         END DO
+      END DO
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_spe')
+      !
+   END SUBROUTINE bdy_spe
+
+   SUBROUTINE bdy_nmn( idx, pta )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_nmn  ***
+      !!
+      !! ** Purpose : Duplicate the value for tracers at open boundaries.
+      !!
+      !!----------------------------------------------------------------------
+      TYPE(OBC_INDEX),                     INTENT(in) ::   idx  ! OBC indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pta  ! tracer trend
+      !!
+      REAL(wp) ::   zwgt           ! boundary weight
+      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
+      INTEGER  ::   ii, ij, zcoef, zcoef1, zcoef2, ip, jp   ! 2D addresses
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('bdy_nmn')
+      !
+      igrd = 1                       ! Everything is at T-points here
+      DO ib = 1, idx%nblenrim(igrd)
+         ii = idx%nbi(ib,igrd)
+         ij = idx%nbj(ib,igrd)
+         DO ik = 1, jpkm1
+            ! search the sense of the gradient
+            zcoef1 = bdytmask(ii-1,ij  ) +  bdytmask(ii+1,ij  )
+            zcoef2 = bdytmask(ii  ,ij-1) +  bdytmask(ii  ,ij+1)
+            IF ( zcoef1+zcoef2 == 0) THEN
+               ! corner
+               zcoef = tmask(ii-1,ij,ik) + tmask(ii+1,ij,ik) +  tmask(ii,ij-1,ik) +  tmask(ii,ij+1,ik)
+               pta(ii,ij,ik) = pta(ii-1,ij  ,ik) * tmask(ii-1,ij  ,ik) + &
+                 &             pta(ii+1,ij  ,ik) * tmask(ii+1,ij  ,ik) + &
+                 &             pta(ii  ,ij-1,ik) * tmask(ii  ,ij-1,ik) + &
+                 &             pta(ii  ,ij+1,ik) * tmask(ii  ,ij+1,ik)
+               pta(ii,ij,ik) = ( pta(ii,ij,ik) / MAX( 1, zcoef) ) * tmask(ii,ij,ik)
+            ELSE
+               ip = bdytmask(ii+1,ij  ) - bdytmask(ii-1,ij  )
+               jp = bdytmask(ii  ,ij+1) - bdytmask(ii  ,ij-1)
+               pta(ii,ij,ik) = pta(ii+ip,ij+jp,ik) * tmask(ii+ip,ij+jp,ik)
+            ENDIF
+         END DO
+      END DO
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_nmn')
+      !
+   END SUBROUTINE bdy_nmn
+
+   SUBROUTINE bdy_orl( idx, ptb, pta, dta, ll_npo )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_orl  ***
+      !!
+      !! ** Purpose : Apply Orlanski radiation for tracers at open boundaries.
+      !!              This is a wrapper routine for bdy_orlanski_3d below
+      !!
+      !!----------------------------------------------------------------------
+      TYPE(OBC_INDEX),                     INTENT(in) ::   idx  ! OBC indices
+      REAL(wp), DIMENSION(:,:),            INTENT(in) ::   dta  ! OBC external data
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptb  ! before tracer field
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pta  ! tracer trend
+      LOGICAL,                             INTENT(in) ::   ll_npo  ! switch for NPO version
+      !!
+      INTEGER  ::   igrd                                    ! grid index
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('bdy_orl')
+      !
+      igrd = 1                       ! Everything is at T-points here
+      !
+      CALL bdy_orlanski_3d( idx, igrd, ptb(:,:,:), pta(:,:,:), dta, ll_npo )
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_orl')
+      !
+   END SUBROUTINE bdy_orl
 
    SUBROUTINE bdy_orlanski_2d( idx, igrd, phib, phia, phi_ext, ll_npo )
@@ -355,18 +490,4 @@
    END SUBROUTINE bdy_orlanski_3d
 
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module                   NO Unstruct Open Boundary Conditions
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE bdy_orlanski_2d( idx, igrd, phib, phia, phi_ext  )      ! Empty routine
-      WRITE(*,*) 'bdy_orlanski_2d: You should not have seen this print! error?', kt
-   END SUBROUTINE bdy_orlanski_2d
-   SUBROUTINE bdy_orlanski_3d( idx, igrd, phib, phia, phi_ext  )      ! Empty routine
-      WRITE(*,*) 'bdy_orlanski_3d: You should not have seen this print! error?', kt
-   END SUBROUTINE bdy_orlanski_3d
-#endif
-
    !!======================================================================
 END MODULE bdylib
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 7299)
@@ -11,8 +11,4 @@
    !!            3.5  !  2013-07  (J. Chanut) Compliant with time splitting changes
    !!----------------------------------------------------------------------
-#if defined key_bdy
-   !!----------------------------------------------------------------------
-   !!   'key_bdy'     Open Boundary Condition
-   !!----------------------------------------------------------------------
    !!   bdytide_init  : read of namelist and initialisation of tidal harmonics data
    !!   tide_update   : calculation of tidal forcing at each timestep
@@ -21,5 +17,4 @@
    USE dom_oce        ! ocean space and time domain
    USE phycst         ! physical constants
-   USE bdy_par        ! Unstructured boundary parameters
    USE bdy_oce        ! ocean open boundary conditions
    USE tideini        ! 
@@ -598,23 +593,4 @@
   END SUBROUTINE tide_init_velocities
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module         NO Unstruct Open Boundary Conditions for tides
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE bdytide_init             ! Empty routine
-      WRITE(*,*) 'bdytide_init: You should not have seen this print! error?'
-   END SUBROUTINE bdytide_init
-   SUBROUTINE bdytide_update( kt, jit )   ! Empty routine
-      WRITE(*,*) 'bdytide_update: You should not have seen this print! error?', kt, jit
-   END SUBROUTINE bdytide_update
-   SUBROUTINE bdy_dta_tides( kt, kit, time_offset )     ! Empty routine
-      INTEGER, INTENT( in )            ::   kt          ! Dummy argument empty routine      
-      INTEGER, INTENT( in ),OPTIONAL   ::   kit         ! Dummy argument empty routine
-      INTEGER, INTENT( in ),OPTIONAL   ::   time_offset ! Dummy argument empty routine
-      WRITE(*,*) 'bdy_dta_tides: You should not have seen this print! error?', kt, jit
-   END SUBROUTINE bdy_dta_tides
-#endif
-
    !!======================================================================
 END MODULE bdytides
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90	(revision 7299)
@@ -8,11 +8,7 @@
    !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
    !!            3.5  !  2012     (S. Mocavero, I. Epicoco) Optimization of BDY communications
+   !!            4.0  !  2016     (T. Lovato) Generalize OBC structure
    !!----------------------------------------------------------------------
-#if defined key_bdy
-   !!----------------------------------------------------------------------
-   !!   'key_bdy'                     Unstructured Open Boundary Conditions
-   !!----------------------------------------------------------------------
-   !!   bdy_tra            : Apply open boundary conditions to T and S
-   !!   bdy_tra_frs        : Apply Flow Relaxation Scheme
+   !!   bdy_tra       : Apply open boundary conditions & damping to T and S
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers variables
@@ -20,5 +16,4 @@
    USE bdy_oce        ! ocean open boundary conditions
    USE bdylib         ! for orlanski library routines
-   USE bdydta   , ONLY:   bf   ! 
    !
    USE in_out_manager ! I/O manager
@@ -29,9 +24,14 @@
    PRIVATE
 
+   ! Local structure to rearrange tracers data
+   TYPE, PUBLIC ::   ztrabdy
+      REAL(wp), POINTER, DIMENSION(:,:) ::  tra
+   END TYPE
+
    PUBLIC   bdy_tra      ! called in tranxt.F90 
    PUBLIC   bdy_tra_dmp  ! called in step.F90 
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0, NEMO Consortium (2016)
    !! $Id$ 
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -48,198 +48,45 @@
       INTEGER, INTENT(in) ::   kt   ! Main time step counter
       !
-      INTEGER ::   ib_bdy   ! Loop index
+      INTEGER                        :: ib_bdy, jn   ! Loop indeces
+      TYPE(ztrabdy), DIMENSION(jpts) :: zdta         ! Temporary data structure
       !!----------------------------------------------------------------------
 
       DO ib_bdy=1, nb_bdy
          !
-         SELECT CASE( cn_tra(ib_bdy) )
-         CASE('none'        )   ;   CYCLE
-         CASE('frs'         )   ;   CALL bdy_tra_frs     ( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
-         CASE('specified'   )   ;   CALL bdy_tra_spe     ( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
-         CASE('neumann'     )   ;   CALL bdy_tra_nmn     ( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
-         CASE('orlanski'    )   ;   CALL bdy_tra_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ll_npo=.false. )
-         CASE('orlanski_npo')   ;   CALL bdy_tra_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ll_npo=.true. )
-         CASE('runoff'      )   ;   CALL bdy_tra_rnf     ( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
-         CASE DEFAULT           ;   CALL ctl_stop( 'bdy_tra : unrecognised option for open boundaries for T and S' )
-         END SELECT
-         ! Boundary points should be updated
-         CALL lbc_bdy_lnk( tsa(:,:,:,jp_tem), 'T', 1., ib_bdy )
-         CALL lbc_bdy_lnk( tsa(:,:,:,jp_sal), 'T', 1., ib_bdy )
+         zdta(1)%tra => dta_bdy(ib_bdy)%tem
+         zdta(2)%tra => dta_bdy(ib_bdy)%sal
+         !
+         DO jn = 1, jpts
+            !
+            SELECT CASE( TRIM(cn_tra(ib_bdy)) )
+            CASE('none'        )   ;   CYCLE
+            CASE('frs'         )   ;   CALL bdy_frs ( idx_bdy(ib_bdy),                tsa(:,:,:,jn), zdta(jn)%tra )
+            CASE('specified'   )   ;   CALL bdy_spe ( idx_bdy(ib_bdy),                tsa(:,:,:,jn), zdta(jn)%tra )
+            CASE('neumann'     )   ;   CALL bdy_nmn ( idx_bdy(ib_bdy),                tsa(:,:,:,jn)               )
+            CASE('orlanski'    )   ;   CALL bdy_orl ( idx_bdy(ib_bdy), tsb(:,:,:,jn), tsa(:,:,:,jn), zdta(jn)%tra, ll_npo=.false. )
+            CASE('orlanski_npo')   ;   CALL bdy_orl ( idx_bdy(ib_bdy), tsb(:,:,:,jn), tsa(:,:,:,jn), zdta(jn)%tra, ll_npo=.true. )
+            CASE('runoff'      )   ;   CALL bdy_rnf ( idx_bdy(ib_bdy),                tsa(:,:,:,jn),               jn )
+            CASE DEFAULT           ;   CALL ctl_stop( 'bdy_tra : unrecognised option for open boundaries for T and S' )
+            END SELECT
+            ! Boundary points should be updated
+            CALL lbc_bdy_lnk( tsa(:,:,:,jn), 'T', 1., ib_bdy )
+            ! 
+         END DO
       END DO
       !
    END SUBROUTINE bdy_tra
 
-
-   SUBROUTINE bdy_tra_frs( idx, dta, kt )
+   SUBROUTINE bdy_rnf( idx, pta, jpa )
       !!----------------------------------------------------------------------
-      !!                 ***  SUBROUTINE bdy_tra_frs  ***
+      !!                 ***  SUBROUTINE bdy_rnf  ***
       !!                    
-      !! ** Purpose : Apply the Flow Relaxation Scheme for tracers at open boundaries.
-      !! 
-      !! Reference : Engedahl H., 1995, Tellus, 365-382.
-      !!----------------------------------------------------------------------
-      INTEGER,         INTENT(in) ::   kt    !
-      TYPE(OBC_INDEX), INTENT(in) ::   idx   ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta   ! OBC external data
-      !
-      REAL(wp) ::   zwgt           ! boundary weight
-      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
-      INTEGER  ::   ii, ij         ! 2D addresses
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('bdy_tra_frs')
-      !
-      igrd = 1                       ! Everything is at T-points here
-      DO ib = 1, idx%nblen(igrd)
-         DO ik = 1, jpkm1
-            ii = idx%nbi(ib,igrd)
-            ij = idx%nbj(ib,igrd)
-            zwgt = idx%nbw(ib,igrd)
-            tsa(ii,ij,ik,jp_tem) = ( tsa(ii,ij,ik,jp_tem) + zwgt * ( dta%tem(ib,ik) - tsa(ii,ij,ik,jp_tem) ) ) * tmask(ii,ij,ik)         
-            tsa(ii,ij,ik,jp_sal) = ( tsa(ii,ij,ik,jp_sal) + zwgt * ( dta%sal(ib,ik) - tsa(ii,ij,ik,jp_sal) ) ) * tmask(ii,ij,ik)
-         END DO
-      END DO 
-      !
-      IF( kt .eq. nit000 )   CLOSE( unit = 102 )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('bdy_tra_frs')
-      !
-   END SUBROUTINE bdy_tra_frs
-
-
-   SUBROUTINE bdy_tra_spe( idx, dta, kt )
-      !!----------------------------------------------------------------------
-      !!                 ***  SUBROUTINE bdy_tra_frs  ***
-      !!                    
-      !! ** Purpose : Apply a specified value for tracers at open boundaries.
+      !! ** Purpose : Specialized routine to apply TRA runoff values at OBs:
+      !!                  - duplicate the neighbour value for the temperature
+      !!                  - specified to 0.1 PSU for the salinity
       !! 
       !!----------------------------------------------------------------------
-      INTEGER,         INTENT(in) ::   kt    !
-      TYPE(OBC_INDEX), INTENT(in) ::   idx   ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta   ! OBC external data
-      !
-      REAL(wp) ::   zwgt           ! boundary weight
-      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
-      INTEGER  ::   ii, ij         ! 2D addresses
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 ) CALL timing_start('bdy_tra_spe')
-      !
-      igrd = 1                       ! Everything is at T-points here
-      DO ib = 1, idx%nblenrim(igrd)
-         ii = idx%nbi(ib,igrd)
-         ij = idx%nbj(ib,igrd)
-         DO ik = 1, jpkm1
-            tsa(ii,ij,ik,jp_tem) = dta%tem(ib,ik) * tmask(ii,ij,ik)
-            tsa(ii,ij,ik,jp_sal) = dta%sal(ib,ik) * tmask(ii,ij,ik)
-         END DO
-      END DO
-      !
-      IF( kt == nit000 )   CLOSE( unit = 102 )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('bdy_tra_spe')
-      !
-   END SUBROUTINE bdy_tra_spe
-
-
-   SUBROUTINE bdy_tra_nmn( idx, dta, kt )
-      !!----------------------------------------------------------------------
-      !!                 ***  SUBROUTINE bdy_tra_nmn  ***
-      !!                    
-      !! ** Purpose : Duplicate the value for tracers at open boundaries.
-      !! 
-      !!----------------------------------------------------------------------
-      INTEGER,         INTENT(in) ::   kt    ! 
-      TYPE(OBC_INDEX), INTENT(in) ::   idx   ! OBC indices
-      TYPE(OBC_DATA) , INTENT(in) ::   dta   ! OBC external data
-      !
-      REAL(wp) ::   zwgt           ! boundary weight
-      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
-      INTEGER  ::   ii, ij,zcoef, zcoef1,zcoef2, ip, jp   ! 2D addresses
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('bdy_tra_nmn')
-      !
-      igrd = 1                       ! Everything is at T-points here
-      DO ib = 1, idx%nblenrim(igrd)
-         ii = idx%nbi(ib,igrd)
-         ij = idx%nbj(ib,igrd)
-         DO ik = 1, jpkm1
-            ! search the sense of the gradient
-            zcoef1 = bdytmask(ii-1,ij  ) +  bdytmask(ii+1,ij  )
-            zcoef2 = bdytmask(ii  ,ij-1) +  bdytmask(ii  ,ij+1)
-            IF ( zcoef1+zcoef2 == 0) THEN
-               ! corner
-               zcoef = tmask(ii-1,ij,ik) + tmask(ii+1,ij,ik) +  tmask(ii,ij-1,ik) +  tmask(ii,ij+1,ik)
-               tsa(ii,ij,ik,jp_tem) = tsa(ii-1,ij  ,ik,jp_tem) * tmask(ii-1,ij  ,ik) + &
-                 &                    tsa(ii+1,ij  ,ik,jp_tem) * tmask(ii+1,ij  ,ik) + &
-                 &                    tsa(ii  ,ij-1,ik,jp_tem) * tmask(ii  ,ij-1,ik) + &
-                 &                    tsa(ii  ,ij+1,ik,jp_tem) * tmask(ii  ,ij+1,ik)
-               tsa(ii,ij,ik,jp_tem) = ( tsa(ii,ij,ik,jp_tem) / MAX( 1, zcoef) ) * tmask(ii,ij,ik)
-               tsa(ii,ij,ik,jp_sal) = tsa(ii-1,ij  ,ik,jp_sal) * tmask(ii-1,ij  ,ik) + &
-                 &                    tsa(ii+1,ij  ,ik,jp_sal) * tmask(ii+1,ij  ,ik) + &
-                 &                    tsa(ii  ,ij-1,ik,jp_sal) * tmask(ii  ,ij-1,ik) + &
-                 &                    tsa(ii  ,ij+1,ik,jp_sal) * tmask(ii  ,ij+1,ik)
-               tsa(ii,ij,ik,jp_sal) = ( tsa(ii,ij,ik,jp_sal) / MAX( 1, zcoef) ) * tmask(ii,ij,ik)
-            ELSE
-               ip = bdytmask(ii+1,ij  ) - bdytmask(ii-1,ij  )
-               jp = bdytmask(ii  ,ij+1) - bdytmask(ii  ,ij-1)
-               tsa(ii,ij,ik,jp_tem) = tsa(ii+ip,ij+jp,ik,jp_tem) * tmask(ii+ip,ij+jp,ik)
-               tsa(ii,ij,ik,jp_sal) = tsa(ii+ip,ij+jp,ik,jp_sal) * tmask(ii+ip,ij+jp,ik)
-            ENDIF
-         END DO
-      END DO
-      !
-      IF( kt == nit000 )   CLOSE( unit = 102 )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('bdy_tra_nmn')
-      !
-   END SUBROUTINE bdy_tra_nmn
- 
-
-   SUBROUTINE bdy_tra_orlanski( idx, dta, ll_npo )
-      !!----------------------------------------------------------------------
-      !!                 ***  SUBROUTINE bdy_tra_orlanski  ***
-      !!             
-      !!              - Apply Orlanski radiation to temperature and salinity. 
-      !!              - Wrapper routine for bdy_orlanski_3d
-      !! 
-      !!
-      !! References:  Marchesiello, McWilliams and Shchepetkin, Ocean Modelling vol. 3 (2001)    
-      !!----------------------------------------------------------------------
-      TYPE(OBC_INDEX), INTENT(in) ::   idx     ! OBC indices
-      TYPE(OBC_DATA) , INTENT(in) ::   dta     ! OBC external data
-      LOGICAL        , INTENT(in) ::   ll_npo  ! switch for NPO version
-      !
-      INTEGER  ::   igrd                                    ! grid index
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 ) CALL timing_start('bdy_tra_orlanski')
-      !
-      igrd = 1      ! Orlanski bc on temperature; 
-      !            
-      CALL bdy_orlanski_3d( idx, igrd, tsb(:,:,:,jp_tem), tsa(:,:,:,jp_tem), dta%tem, ll_npo )
-
-      igrd = 1      ! Orlanski bc on salinity;
-      !  
-      CALL bdy_orlanski_3d( idx, igrd, tsb(:,:,:,jp_sal), tsa(:,:,:,jp_sal), dta%sal, ll_npo )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('bdy_tra_orlanski')
-      !
-   END SUBROUTINE bdy_tra_orlanski
-
-
-   SUBROUTINE bdy_tra_rnf( idx, dta, kt )
-      !!----------------------------------------------------------------------
-      !!                 ***  SUBROUTINE bdy_tra_rnf  ***
-      !!                    
-      !! ** Purpose : Apply the runoff values for tracers at open boundaries:
-      !!                  - specified to 0.1 PSU for the salinity
-      !!                  - duplicate the value for the temperature
-      !! 
-      !!----------------------------------------------------------------------
-      INTEGER        , INTENT(in) ::   kt    ! 
-      TYPE(OBC_INDEX), INTENT(in) ::   idx   ! OBC indices
-      TYPE(OBC_DATA) , INTENT(in) ::   dta   ! OBC external data
+      TYPE(OBC_INDEX),                     INTENT(in) ::   idx  ! OBC indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pta  ! tracer trend
+      INTEGER,                             INTENT(in) ::   jpa  ! TRA index
       !
       REAL(wp) ::   zwgt           ! boundary weight
@@ -248,5 +95,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('bdy_tra_rnf')
+      IF( nn_timing == 1 )   CALL timing_start('bdy_rnf')
       !
       igrd = 1                       ! Everything is at T-points here
@@ -257,15 +104,12 @@
             ip = bdytmask(ii+1,ij  ) - bdytmask(ii-1,ij  )
             jp = bdytmask(ii  ,ij+1) - bdytmask(ii  ,ij-1)
-            tsa(ii,ij,ik,jp_tem) = tsa(ii+ip,ij+jp,ik,jp_tem) * tmask(ii,ij,ik)
-            tsa(ii,ij,ik,jp_sal) =                        0.1 * tmask(ii,ij,ik)
+            if (jpa == jp_tem) pta(ii,ij,ik) = pta(ii+ip,ij+jp,ik) * tmask(ii,ij,ik)
+            if (jpa == jp_sal) pta(ii,ij,ik) =                 0.1 * tmask(ii,ij,ik)
          END DO
       END DO
       !
-      IF( kt == nit000 )   CLOSE( unit = 102 )
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_rnf')
       !
-      IF( nn_timing == 1 )   CALL timing_stop('bdy_tra_rnf')
-      !
-   END SUBROUTINE bdy_tra_rnf
-
+   END SUBROUTINE bdy_rnf
 
    SUBROUTINE bdy_tra_dmp( kt )
@@ -308,18 +152,4 @@
    END SUBROUTINE bdy_tra_dmp
  
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module                   NO Unstruct Open Boundary Conditions
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE bdy_tra(kt)      ! Empty routine
-      WRITE(*,*) 'bdy_tra: You should not have seen this print! error?', kt
-   END SUBROUTINE bdy_tra
-
-   SUBROUTINE bdy_tra_dmp(kt)      ! Empty routine
-      WRITE(*,*) 'bdy_tra_dmp: You should not have seen this print! error?', kt
-   END SUBROUTINE bdy_tra_dmp
-#endif
-
    !!======================================================================
 END MODULE bdytra
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90	(revision 7299)
@@ -9,8 +9,4 @@
    !!            3.0  !  2008-04  (NEMO team)  add in the reference version
    !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
-   !!----------------------------------------------------------------------
-#if defined key_bdy
-   !!----------------------------------------------------------------------
-   !!   'key_bdy'                     unstructured open boundary conditions
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers 
@@ -175,14 +171,4 @@
    END SUBROUTINE bdy_vol
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module                   NO Unstruct Open Boundary Conditions
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE bdy_vol( kt )        ! Empty routine
-      WRITE(*,*) 'bdy_vol: You should not have seen this print! error?', kt
-   END SUBROUTINE bdy_vol
-#endif
-
    !!======================================================================
 END MODULE bdyvol
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90	(revision 7299)
@@ -6,8 +6,7 @@
    !! History :  3.1  !  2007  (O. Le Galloudec, J. Chanut)  Original code
    !!----------------------------------------------------------------------
-#if defined key_diaharm && defined key_tide
+#if defined key_diaharm
    !!----------------------------------------------------------------------
    !!   'key_diaharm'
-   !!   'key_tide'
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers variables
@@ -16,4 +15,5 @@
    USE daymod
    USE tide_mod
+   USE sbctide         ! Tidal forcing or not
    !
    USE in_out_manager  ! I/O units
@@ -82,4 +82,6 @@
          WRITE(numout,*) '~~~~~~~ '
       ENDIF
+      !
+      IF( .NOT. ln_tide )   CALL ctl_stop( 'dia_harm_init : ln_tide must be true for harmonic analysis')
       !
       CALL tide_init_Wave
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 7299)
@@ -23,6 +23,6 @@
    USE trabbc          ! bottom boundary condition 
    USE trabbc          ! bottom boundary condition
-   USE bdy_par         ! (for lk_bdy)
    USE restart         ! ocean restart
+   USE bdy_oce   , ONLY: ln_bdy
    !
    USE iom             ! I/O manager
@@ -395,5 +395,5 @@
       surf_tot  = glob_sum( surf(:,:) )                                       ! total ocean surface area
 
-      IF( lk_bdy ) CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' )         
+      IF( ln_bdy ) CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' )         
       !
       ! ---------------------------------- !
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 7299)
@@ -88,5 +88,5 @@
       !!      are defined with the proper value at lateral domain boundaries.
       !!
-      !!      In case of open boundaries (lk_bdy=T):
+      !!      In case of open boundaries (ln_bdy=T):
       !!        - tmask is set to 1 on the points to be computed bay the open
       !!          boundaries routines.
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 7299)
@@ -32,5 +32,5 @@
    USE dynspg_ts      ! surface pressure gradient: split-explicit scheme
    USE domvvl         ! variable volume
-   USE bdy_oce        ! ocean open boundary conditions
+   USE bdy_oce   , ONLY: ln_bdy
    USE bdydta         ! ocean open boundary conditions
    USE bdydyn         ! ocean open boundary conditions
@@ -77,5 +77,5 @@
       !!              * Apply lateral boundary conditions on after velocity 
       !!             at the local domain boundaries through lbc_lnk call,
-      !!             at the one-way open boundaries (lk_bdy=T),
+      !!             at the one-way open boundaries (ln_bdy=T),
       !!             at the AGRIF zoom   boundaries (lk_agrif=T)
       !!
@@ -147,12 +147,9 @@
       CALL lbc_lnk( va, 'V', -1. ) 
       !
-# if defined key_bdy
       !                                !* BDY open boundaries
-      IF( lk_bdy .AND. ln_dynspg_exp )   CALL bdy_dyn( kt )
-      IF( lk_bdy .AND. ln_dynspg_ts  )   CALL bdy_dyn( kt, dyn3d_only=.true. )
+      IF( ln_bdy .AND. ln_dynspg_exp )   CALL bdy_dyn( kt )
+      IF( ln_bdy .AND. ln_dynspg_ts  )   CALL bdy_dyn( kt, dyn3d_only=.true. )
 
 !!$   Do we need a call to bdy_vol here??
-      !
-# endif
       !
       IF( l_trddyn ) THEN             ! prepare the atf trend computation + some diagnostics
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 7299)
@@ -88,5 +88,5 @@
       !
       IF(      ln_apr_dyn                                                &   ! atmos. pressure
-         .OR.  ( .NOT.ln_dynspg_ts .AND. (ln_tide_pot .AND. lk_tide) )   &   ! tide potential (no time slitting)
+         .OR.  ( .NOT.ln_dynspg_ts .AND. (ln_tide_pot .AND. ln_tide) )   &   ! tide potential (no time slitting)
          .OR.  nn_ice_embd == 2  ) THEN                                      ! embedded sea-ice
          !
@@ -111,5 +111,5 @@
          !
          !                                    !==  tide potential forcing term  ==!
-         IF( .NOT.ln_dynspg_ts .AND. ( ln_tide_pot .AND. lk_tide )  ) THEN   ! N.B. added directly at sub-time-step in ts-case
+         IF( .NOT.ln_dynspg_ts .AND. ( ln_tide_pot .AND. ln_tide )  ) THEN   ! N.B. added directly at sub-time-step in ts-case
             !
             CALL upd_tide( kt )                      ! update tide potential
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 7299)
@@ -33,5 +33,5 @@
    USE dynvor          ! vorticity term
    USE wet_dry         ! wetting/drying flux limter
-   USE bdy_par         ! for lk_bdy
+   USE bdy_oce   , ONLY: ln_bdy
    USE bdytides        ! open boundary condition data
    USE bdydyn2d        ! open boundary conditions on barotropic variables
@@ -607,8 +607,6 @@
          !                                                !  ------------------
          ! Update only tidal forcing at open boundaries
-#if defined key_tide
-         IF( lk_bdy      .AND. lk_tide )   CALL bdy_dta_tides( kt, kit=jn, time_offset= noffset+1 )
-         IF( ln_tide_pot .AND. lk_tide )   CALL upd_tide     ( kt, kit=jn, time_offset= noffset   )
-#endif
+         IF( ln_bdy      .AND. ln_tide )   CALL bdy_dta_tides( kt, kit=jn, time_offset= noffset+1 )
+         IF( ln_tide_pot .AND. ln_tide )   CALL upd_tide     ( kt, kit=jn, time_offset= noffset   )
          !
          ! Set extrapolation coefficients for predictor step:
@@ -705,8 +703,7 @@
          CALL lbc_lnk( ssha_e, 'T',  1._wp )
 
-#if defined key_bdy
          ! Duplicate sea level across open boundaries (this is only cosmetic if linssh=T)
-         IF( lk_bdy )   CALL bdy_ssh( ssha_e )
-#endif
+         IF( ln_bdy )   CALL bdy_ssh( ssha_e )
+
 #if defined key_agrif
          IF( .NOT.Agrif_Root() )   CALL agrif_ssh_ts( jn )
@@ -861,5 +858,5 @@
          !
          ! Add tidal astronomical forcing if defined
-         IF ( lk_tide.AND.ln_tide_pot ) THEN
+         IF ( ln_tide.AND.ln_tide_pot ) THEN
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -967,8 +964,7 @@
          CALL lbc_lnk_multi( ua_e, 'U', -1._wp, va_e , 'V', -1._wp )
          !
-#if defined key_bdy  
          !                                                 ! open boundaries
-         IF( lk_bdy )   CALL bdy_dyn2d( jn, ua_e, va_e, un_e, vn_e, hur_e, hvr_e, ssha_e )
-#endif
+         IF( ln_bdy )   CALL bdy_dyn2d( jn, ua_e, va_e, un_e, vn_e, hur_e, hvr_e, ssha_e )
+
 #if defined key_agrif                                                           
          IF( .NOT.Agrif_Root() )  CALL agrif_dyn_ts( jn )  ! Agrif
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90	(revision 7299)
@@ -22,6 +22,5 @@
    USE divhor         ! horizontal divergence
    USE phycst         ! physical constants
-   USE bdy_oce        ! 
-   USE bdy_par        !
+   USE bdy_oce   , ONLY: ln_bdy, bdytmask
    USE bdydyn2d       ! bdy_ssh routine
 #if defined key_agrif
@@ -116,10 +115,8 @@
          CALL agrif_ssh( kt )
 # endif
-# if defined key_bdy
-         IF( lk_bdy ) THEN
+         IF( ln_bdy ) THEN
             CALL lbc_lnk( ssha, 'T', 1. )    ! Not sure that's necessary
             CALL bdy_ssh( ssha )             ! Duplicate sea level across open boundaries
          ENDIF
-# endif
       ENDIF
 
@@ -211,11 +208,9 @@
       ENDIF
 
-#if defined key_bdy
-      IF( lk_bdy ) THEN
+      IF( ln_bdy ) THEN
          DO jk = 1, jpkm1
             wn(:,:,jk) = wn(:,:,jk) * bdytmask(:,:)
          END DO
       ENDIF
-#endif
       !
       IF( nn_timing == 1 )  CALL timing_stop('wzv')
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 7299)
@@ -666,7 +666,6 @@
       !!                using a general mapping (for open boundaries)
       !!----------------------------------------------------------------------
-#if defined key_bdy
-      USE bdy_oce, ONLY:  dta_global, dta_global2         ! workspace to read in global data arrays
-#endif 
+      USE bdy_oce, ONLY: ln_bdy, dta_global, dta_global2         ! workspace to read in global data arrays
+
       INTEGER                   , INTENT(in ) ::   num     ! stream number
       CHARACTER(LEN=*)          , INTENT(in ) ::   clvar   ! variable name
@@ -692,12 +691,12 @@
       ilendta = iom_file(num)%dimsz(1,idvar)
 
-#if defined key_bdy
-      ipj = iom_file(num)%dimsz(2,idvar)
-      IF( map%ll_unstruc) THEN   ! unstructured open boundary data file
-         dta_read => dta_global
-      ELSE                       ! structured open boundary data file
-         dta_read => dta_global2
-      ENDIF
-#endif
+      IF ( ln_bdy ) THEN
+         ipj = iom_file(num)%dimsz(2,idvar)
+         IF( map%ll_unstruc) THEN   ! unstructured open boundary data file
+            dta_read => dta_global
+         ELSE                       ! structured open boundary data file
+            dta_read => dta_global2
+         ENDIF
+      ENDIF
 
       IF(lwp) WRITE(numout,*) 'Dim size for ',        TRIM(clvar),' is ', ilendta
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 7299)
@@ -62,7 +62,6 @@
    USE timing          ! Timing
 
-#if defined key_bdy 
-   USE bdyice_lim       ! unstructured open boundary data  (bdy_ice_lim routine)
-#endif
+   USE bdy_oce   , ONLY: ln_bdy
+   USE bdyice_lim      ! unstructured open boundary data  (bdy_ice_lim routine)
 
    IMPLICIT NONE
@@ -166,8 +165,6 @@
             IF( nn_monocat /= 2 ) CALL lim_itd_me ! Mechanical redistribution ! (ridging/rafting)
             !
-#if defined key_bdy
-            CALL bdy_ice_lim( kt )                ! bdy ice thermo 
-            IF( ln_icectl )       CALL lim_prt( kt, iiceprt, jiceprt, 1, ' - ice thermo bdy - ' )
-#endif
+            IF( ln_bdy )  CALL bdy_ice_lim( kt )                ! bdy ice thermo 
+            IF( ln_bdy .AND. ln_icectl )  CALL lim_prt( kt, iiceprt, jiceprt, 1, ' - ice thermo bdy - ' )
             !
             CALL lim_update1( kt )                ! Corrections
@@ -380,7 +377,6 @@
       r1_nlay_s = 1._wp / REAL( nlay_s, wp )
       !
-#if defined key_bdy
-      IF( lwp .AND. ln_limdiahsb )  CALL ctl_warn('online conservation check activated but it does not work with BDY')
-#endif
+      IF( lwp .AND. ln_bdy .AND. ln_limdiahsb )  &
+      &   CALL ctl_warn('online conservation check activated but it does not work with BDY')
       !
    END SUBROUTINE ice_run
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90	(revision 7299)
@@ -54,7 +54,6 @@
 # endif
 
-#if defined key_bdy 
+   USE bdy_oce   , ONLY: ln_bdy
    USE bdyice_lim       ! unstructured open boundary data  (bdy_ice_lim routine)
-#endif
 
    IMPLICIT NONE
@@ -230,7 +229,5 @@
                            CALL lim_trp_2      ( kt )      ! Ice transport   ( Advection/diffusion )
            IF( ln_limdmp ) CALL lim_dmp_2      ( kt )      ! Ice damping 
-#if defined key_bdy
-                           CALL bdy_ice_lim( kt ) ! bdy ice thermo
-#endif
+           IF( ln_bdy    ) CALL bdy_ice_lim( kt ) ! bdy ice thermo
          END IF
          !                                             ! Ice surface fluxes in coupled mode 
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 7299)
@@ -47,5 +47,5 @@
    USE traqsr         ! active tracers: light penetration
    USE sbcwave        ! Wave module
-   USE bdy_par        ! Require lk_bdy
+   USE bdy_oce   , ONLY: ln_bdy
    !
    USE prtctl         ! Print control                    (prt_ctl routine)
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90	(revision 7299)
@@ -22,7 +22,6 @@
    REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:) ::   pot_astro   !
 
-#if defined key_tide
    !!----------------------------------------------------------------------
-   !!   'key_tide' :                                        tidal potential
+   !!   tidal potential
    !!----------------------------------------------------------------------
    !!   sbc_tide            : 
@@ -30,5 +29,4 @@
    !!----------------------------------------------------------------------
 
-   LOGICAL, PUBLIC, PARAMETER ::   lk_tide  = .TRUE.
    REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   amp_pot, phi_pot
 
@@ -125,16 +123,4 @@
    END SUBROUTINE tide_init_potential
 
-#else
-  !!----------------------------------------------------------------------
-  !!   Default case :   Empty module
-  !!----------------------------------------------------------------------
-  LOGICAL, PUBLIC, PARAMETER ::   lk_tide = .FALSE.
-CONTAINS
-  SUBROUTINE sbc_tide( kt )      ! Empty routine
-    INTEGER         , INTENT(in) ::   kt         ! ocean time-step
-    WRITE(*,*) 'sbc_tide: You should not have seen this print! error?', kt
-  END SUBROUTINE sbc_tide
-#endif
-
   !!======================================================================
 END MODULE sbctide
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90	(revision 7299)
@@ -12,6 +12,6 @@
    !!----------------------------------------------------------------------
    USE oce            ! 
-   USE sbc_oce	       ! Surface boundary condition: ocean fields
-   USE bdy_oce        !
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE bdy_oce   , ONLY: ln_bdy, bdytmask
    USE domvvl         !
    !
@@ -19,5 +19,5 @@
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! distribued memory computing library
-   USE fldread	       ! read input fields
+   USE fldread        ! read input fields
    USE wrk_nemo       !
 
@@ -32,6 +32,6 @@
    INTEGER , PARAMETER ::   jp_wn  = 3   ! index of wave number                 (1/m)    at T-point
 
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:)  :: sf_cd	  ! structure of input fields (file informations, fields read) Drag Coefficient
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:)  :: sf_sd	  ! structure of input fields (file informations, fields read) Stokes Drift
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:)  :: sf_cd         ! structure of input fields (file informations, fields read) Drag Coefficient
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:)  :: sf_sd         ! structure of input fields (file informations, fields read) Stokes Drift
 
    REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION (:,:)   :: cdn_wave 
@@ -172,11 +172,11 @@
             wsd3d(:,:,jk) = wsd3d(:,:,jk+1) - ze3hdiv(:,:,jk)
          END DO
-#if defined key_bdy
-         IF( lk_bdy ) THEN
+         !
+         IF( ln_bdy ) THEN
             DO jk = 1, jpkm1
                wsd3d(:,:,jk) = wsd3d(:,:,jk) * bdytmask(:,:)
             END DO
          ENDIF
-#endif
+         !
          CALL wrk_dealloc( jpi,jpj,jpk,   zusd_t, zvsd_t, ze3hdiv )
          ! 
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/tideini.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/tideini.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/tideini.F90	(revision 7299)
@@ -25,4 +25,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:) ::   ftide        !:
 
+   LOGICAL , PUBLIC ::   ln_tide         !:
    LOGICAL , PUBLIC ::   ln_tide_pot     !:
    LOGICAL , PUBLIC ::   ln_tide_ramp    !:
@@ -48,14 +49,6 @@
       INTEGER  ::   ios                 ! Local integer output status for namelist read
       !
-      NAMELIST/nam_tide/ln_tide_pot, ln_tide_ramp, rdttideramp, clname
+      NAMELIST/nam_tide/ln_tide, ln_tide_pot, ln_tide_ramp, rdttideramp, clname
       !!----------------------------------------------------------------------
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'tide_init : Initialization of the tidal components'
-         WRITE(numout,*) '~~~~~~~~~ '
-      ENDIF
-      !
-      CALL tide_init_Wave
       !
       ! Read Namelist nam_tide
@@ -69,4 +62,25 @@
       IF(lwm) WRITE ( numond, nam_tide )
       !
+      IF (ln_tide) THEN
+         IF (lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'tide_init : Initialization of the tidal components'
+            WRITE(numout,*) '~~~~~~~~~ '
+            WRITE(numout,*) '   Namelist nam_tide'
+            WRITE(numout,*) '              Use tidal components : ln_tide      = ', ln_tide
+            WRITE(numout,*) '      Apply astronomical potential : ln_tide_pot  = ', ln_tide_pot
+            WRITE(numout,*) '                                     nb_harmo     = ', nb_harmo
+            WRITE(numout,*) '                                     ln_tide_ramp = ', ln_tide_ramp
+            WRITE(numout,*) '                                     rdttideramp  = ', rdttideramp
+         ENDIF
+      ELSE
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tide_init : tidal components not used (ln_tide = F)'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~ '
+         RETURN
+      ENDIF
+      !
+      CALL tide_init_Wave
+      !
       nb_harmo=0
       DO jk = 1, jpmax_harmo
@@ -79,11 +93,4 @@
       IF( nb_harmo == 0 )   CALL ctl_stop( 'tide_init : No tidal components set in nam_tide' )
       !
-      IF(lwp) THEN
-         WRITE(numout,*) '   Namelist nam_tide'
-         WRITE(numout,*) '      Apply astronomical potential : ln_tide_pot  =', ln_tide_pot
-         WRITE(numout,*) '                                     nb_harmo     = ', nb_harmo
-         WRITE(numout,*) '                                     ln_tide_ramp = ', ln_tide_ramp 
-         WRITE(numout,*) '                                     rdttideramp  = ', rdttideramp
-      ENDIF
       IF( ln_tide_ramp.AND.((nitend-nit000+1)*rdt/rday < rdttideramp) )   &
          &   CALL ctl_stop('rdttideramp must be lower than run duration')
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/updtide.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/updtide.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/SBC/updtide.F90	(revision 7299)
@@ -5,8 +5,4 @@
    !!======================================================================
    !! History :  9.0  !  07  (O. Le Galloudec)  Original code
-   !!----------------------------------------------------------------------
-#if defined key_tide
-   !!----------------------------------------------------------------------
-   !!   'key_tide' :                                        tidal potential
    !!----------------------------------------------------------------------
    !!   upd_tide       : update tidal potential
@@ -81,18 +77,4 @@
    END SUBROUTINE upd_tide
 
-#else
-  !!----------------------------------------------------------------------
-  !!   Dummy module :                                        NO TIDE
-  !!----------------------------------------------------------------------
-CONTAINS
-  SUBROUTINE upd_tide( kt, kit, time_offset )  ! Empty routine
-    INTEGER, INTENT(in)           ::   kt      !  integer  arg, dummy routine
-    INTEGER, INTENT(in), OPTIONAL ::   kit     !  optional arg, dummy routine
-    INTEGER, INTENT(in), OPTIONAL ::   time_offset !  optional arg, dummy routine
-    WRITE(*,*) 'upd_tide: You should not have seen this print! error?', kt
-  END SUBROUTINE upd_tide
-
-#endif
-
   !!======================================================================
 
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 7299)
@@ -37,5 +37,5 @@
    USE ldftra          ! lateral physics on tracers
    USE ldfslp
-   USE bdy_oce         ! BDY open boundary condition variables
+   USE bdy_oce   , ONLY: ln_bdy
    USE bdytra          ! open boundary condition (bdy_tra routine)
    !
@@ -79,5 +79,5 @@
       !!              - Apply lateral boundary conditions on (ta,sa) 
       !!             at the local domain   boundaries through lbc_lnk call, 
-      !!             at the one-way open boundaries (lk_bdy=T), 
+      !!             at the one-way open boundaries (ln_bdy=T), 
       !!             at the AGRIF zoom   boundaries (lk_agrif=T)
       !!
@@ -111,7 +111,5 @@
       CALL lbc_lnk( tsa(:,:,:,jp_sal), 'T', 1._wp )
       !
-#if defined key_bdy 
-      IF( lk_bdy )   CALL bdy_tra( kt )  ! BDY open boundaries
-#endif
+      IF( ln_bdy )   CALL bdy_tra( kt )  ! BDY open boundaries
  
       ! set time step size (Euler/Leapfrog)
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 7299)
@@ -205,5 +205,5 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1
-               IF( fsdept(ji,jj,jk) < ekm_dep(ji,jj) ) THEN
+               IF( gdept_n(ji,jj,jk) < ekm_dep(ji,jj) ) THEN
                   avmv(ji,jj,jk) = MAX( avmv(ji,jj,jk), rn_wvmix )
                   avmu(ji,jj,jk) = MAX( avmu(ji,jj,jk), rn_wvmix )
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 7299)
@@ -52,8 +52,6 @@
 #endif
    USE tideini        ! tidal components initialization   (tide_ini routine)
+   USE bdy_oce,   ONLY: ln_bdy
    USE bdyini         ! open boundary cond. setting       (bdy_init routine)
-   USE bdydta         ! open boundary cond. setting   (bdy_dta_init routine)
-   USE bdytides       ! open boundary cond. setting   (bdytide_init routine)
-   USE sbctide, ONLY  : lk_tide
    USE istate         ! initial state setting          (istate_init routine)
    USE ldfdyn         ! lateral viscosity setting      (ldfdyn_init routine)
@@ -433,12 +431,7 @@
       !                                      ! external forcing 
 !!gm to be added : creation and call of sbc_apr_init
-      IF( lk_tide       )   CALL    tide_init   ! tidal harmonics
+                            CALL    tide_init   ! tidal harmonics
                             CALL     sbc_init   ! surface boundary conditions (including sea-ice)
-!!gm ==>> bdy_init should call bdy_dta_init and bdytide_init  NOT in nemogcm !!!
-      IF( lk_bdy        )   CALL     bdy_init   ! Open boundaries initialisation
-      IF( lk_bdy        )   CALL bdy_dta_init   ! Open boundaries initialisation of external data arrays
-      IF( lk_bdy .AND. lk_tide )   &
-         &                  CALL bdytide_init   ! Open boundaries initialisation of tidal harmonic forcing
-         
+                            CALL     bdy_init   ! Open boundaries initialisation
       !                                      ! Ocean physics
       !                                         ! Vertical physics
@@ -659,7 +652,5 @@
       USE diadct    , ONLY: diadct_alloc 
 #endif 
-#if defined key_bdy
       USE bdy_oce   , ONLY: bdy_oce_alloc
-#endif
       !
       INTEGER :: ierr
@@ -676,7 +667,5 @@
       ierr = ierr + diadct_alloc    ()          ! 
 #endif 
-#if defined key_bdy
       ierr = ierr + bdy_oce_alloc   ()          ! bdy masks (incl. initialization)
-#endif
       !
       IF( lk_mpp    )   CALL mpp_sum( ierr )
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 7299)
@@ -104,7 +104,7 @@
       ! Update external forcing (tides, open boundaries, and surface boundary condition (including sea-ice)
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( lk_tide    )   CALL sbc_tide( kstp )                   ! update tide potential
+      IF( ln_tide    )   CALL sbc_tide( kstp )                   ! update tide potential
       IF( ln_apr_dyn )   CALL sbc_apr ( kstp )                   ! atmospheric pressure (NB: call before bdy_dta which needs ssh_ib) 
-      IF( lk_bdy     )   CALL bdy_dta ( kstp, time_offset=+1 )   ! update dynamic & tracer data at open boundaries
+      IF( ln_bdy     )   CALL bdy_dta ( kstp, time_offset=+1 )   ! update dynamic & tracer data at open boundaries
                          CALL sbc     ( kstp )                   ! Sea Boundary Condition (including sea-ice)
 
@@ -200,5 +200,5 @@
       IF(  lk_asminc .AND. ln_asmiau .AND. ln_dyninc )   &
                &         CALL dyn_asm_inc   ( kstp )  ! apply dynamics assimilation increment
-      IF( lk_bdy     )   CALL bdy_dyn3d_dmp ( kstp )  ! bdy damping trends
+      IF( ln_bdy     )   CALL bdy_dyn3d_dmp ( kstp )  ! bdy damping trends
 #if defined key_agrif
       IF(.NOT. Agrif_Root())  & 
@@ -259,5 +259,5 @@
       IF( lk_trabbl  )   CALL tra_bbl       ( kstp )  ! advective (and/or diffusive) bottom boundary layer scheme
       IF( ln_tradmp  )   CALL tra_dmp       ( kstp )  ! internal damping trends
-      IF( lk_bdy     )   CALL bdy_tra_dmp   ( kstp )  ! bdy damping trends
+      IF( ln_bdy     )   CALL bdy_tra_dmp   ( kstp )  ! bdy damping trends
 #if defined key_agrif
       IF(.NOT. Agrif_Root())  & 
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/step_oce.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 7299)
@@ -47,6 +47,5 @@
    USE stopts 
 
-   USE bdy_par          ! for lk_bdy
-   USE bdy_oce          ! for dmp logical
+   USE bdy_oce    , ONLY: ln_bdy
    USE bdydta           ! open boundary condition data     (bdy_dta routine)
    USE bdytra           ! bdy cond. for tracers            (bdy_tra routine)
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 7299)
@@ -59,9 +59,5 @@
    USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
    USE icbstp          ! handle bergs, calving, themodynamics and transport
-#if defined key_bdy
    USE bdyini          ! open boundary cond. setting       (bdy_init routine). clem: mandatory for LIM3
-   USE bdydta          ! open boundary cond. setting   (bdy_dta_init routine). clem: mandatory for LIM3
-#endif
-   USE bdy_par
 
    IMPLICIT NONE
@@ -363,6 +359,5 @@
       !           the environment of ocean BDY. Therefore bdy is called in both OPA and SAS modules. 
       !           This is not clean and should be changed in the future. 
-      IF( lk_bdy        )   CALL     bdy_init
-      IF( lk_bdy        )   CALL bdy_dta_init
+                            CALL     bdy_init
       ! ==>
       
@@ -514,10 +509,6 @@
       USE diawri    , ONLY: dia_wri_alloc
       USE dom_oce   , ONLY: dom_oce_alloc
-#if defined key_bdy   
-      USE bdy_oce   , ONLY: bdy_oce_alloc
+      USE bdy_oce   , ONLY: ln_bdy, bdy_oce_alloc
       USE oce         ! clem: mandatory for LIM3 because needed for bdy arrays
-#else
-      USE oce       , ONLY : sshn, sshb, snwice_mass, snwice_mass_b, snwice_fmass
-#endif
       !
       INTEGER :: ierr,ierr1,ierr2,ierr3,ierr4,ierr5,ierr6,ierr7,ierr8
@@ -527,25 +518,23 @@
       ierr =        dia_wri_alloc   ()
       ierr = ierr + dom_oce_alloc   ()          ! ocean domain
-#if defined key_bdy
       ierr = ierr + bdy_oce_alloc   ()          ! bdy masks (incl. initialization)
-      ierr = ierr + oce_alloc       ()          ! (tsn...)
-#endif
-
-#if ! defined key_bdy
-       ALLOCATE( snwice_mass(jpi,jpj)  , snwice_mass_b(jpi,jpj),             &
-         &      snwice_fmass(jpi,jpj)  , STAT= ierr1 )
-      !
-      ! lim code currently uses surface temperature and salinity in tsn array for initialisation
-      ! and ub, vb arrays in ice dynamics, so allocate enough of arrays to use
-      ! clem: should not be needed. To be checked out
-      jpm = MAX(jp_tem, jp_sal)
-      ALLOCATE( tsn(jpi,jpj,1,jpm)  , STAT=ierr2 )
-      ALLOCATE( ub(jpi,jpj,1)       , STAT=ierr3 )
-      ALLOCATE( vb(jpi,jpj,1)       , STAT=ierr4 )
-      ALLOCATE( tsb(jpi,jpj,1,jpm)  , STAT=ierr5 )
-      ALLOCATE( sshn(jpi,jpj)       , STAT=ierr6 )
-      ALLOCATE( un(jpi,jpj,1)       , STAT=ierr7 )
-      ALLOCATE( vn(jpi,jpj,1)       , STAT=ierr8 )
-      ierr = ierr + ierr1 + ierr2 + ierr3 + ierr4 + ierr5 + ierr6 + ierr7 + ierr8
+# if ! defined key_lim2 && ! defined key_lim3
+         ierr = ierr + oce_alloc       ()          ! (tsn...)
+# else
+         ALLOCATE( snwice_mass(jpi,jpj)  , snwice_mass_b(jpi,jpj),             &
+            &      snwice_fmass(jpi,jpj)  , STAT= ierr1 )
+         !
+         ! lim code currently uses surface temperature and salinity in tsn array for initialisation
+         ! and ub, vb arrays in ice dynamics, so allocate enough of arrays to use
+         ! clem: should not be needed. To be checked out
+         jpm = MAX(jp_tem, jp_sal)
+         ALLOCATE( tsn(jpi,jpj,1,jpm)  , STAT=ierr2 )
+         ALLOCATE( ub(jpi,jpj,1)       , STAT=ierr3 )
+         ALLOCATE( vb(jpi,jpj,1)       , STAT=ierr4 )
+         ALLOCATE( tsb(jpi,jpj,1,jpm)  , STAT=ierr5 )
+         ALLOCATE( sshn(jpi,jpj)       , STAT=ierr6 )
+         ALLOCATE( un(jpi,jpj,1)       , STAT=ierr7 )
+         ALLOCATE( vn(jpi,jpj,1)       , STAT=ierr8 )
+         ierr = ierr + ierr1 + ierr2 + ierr3 + ierr4 + ierr5 + ierr6 + ierr7 + ierr8
 #endif
       !
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/SAS_SRC/step.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/SAS_SRC/step.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/SAS_SRC/step.F90	(revision 7299)
@@ -23,8 +23,6 @@
    USE eosbn2           ! equation of state                (eos_bn2 routine)
    USE diawri           ! Standard run outputs             (dia_wri routine)
-   USE bdy_par          ! clem: mandatory for LIM3
-#if defined key_bdy
+   USE bdy_oce   , ONLY: ln_bdy
    USE bdydta           ! clem: mandatory for LIM3
-#endif
    USE stpctl           ! time stepping control            (stp_ctl routine)
    !
@@ -82,7 +80,5 @@
       !           From SAS: ocean bdy data are wrong  (but we do not care) and ice bdy data are OK.  
       !           This is not clean and should be changed in the future. 
-#if defined key_bdy
-      IF( lk_bdy     )       CALL bdy_dta ( kstp, time_offset=+1 )   ! update dynamic & tracer data at open boundaries
-#endif
+      IF( ln_bdy     )       CALL bdy_dta ( kstp, time_offset=+1 )   ! update dynamic & tracer data at open boundaries
       ! ==>
                              CALL sbc    ( kstp )         ! Sea Boundary Condition (including sea-ice)
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 7299)
@@ -33,6 +33,6 @@
    USE trdtra
    USE tranxt
+   USE bdy_oce   , ONLY: ln_bdy
    USE trcbdy          ! BDY open boundaries
-   USE bdy_par, only: lk_bdy
 # if defined key_agrif
    USE agrif_top_interp
@@ -99,5 +99,5 @@
       END DO
 
-      IF( lk_bdy )  CALL trc_bdy( kt )
+      IF( ln_bdy )  CALL trc_bdy( kt )
 
       !                                ! set time step size (Euler/Leapfrog)
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 7299)
@@ -25,6 +25,6 @@
    USE trcsbc          ! surface boundary condition          (trc_sbc routine)
    USE zpshde          ! partial step: hor. derivative       (zps_hde routine)
+   USE bdy_oce   , ONLY: ln_bdy
    USE trcbdy          ! BDY open boundaries
-   USE bdy_par, only: lk_bdy
 
 #if defined key_agrif
@@ -65,5 +65,5 @@
          IF( lk_trabbl )        CALL trc_bbl    ( kt )      ! advective (and/or diffusive) bottom boundary layer scheme
          IF( ln_trcdmp )        CALL trc_dmp    ( kt )      ! internal damping trends
-         IF( lk_bdy )           CALL trc_bdy_dmp( kt )      ! BDY damping trends
+         IF( ln_bdy )           CALL trc_bdy_dmp( kt )      ! BDY damping trends
                                 CALL trc_adv    ( kt )      ! horizontal & vertical advection 
          !                                                         ! Partial top/bottom cell: GRADh( trb )  
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/trc.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 7299)
@@ -14,7 +14,5 @@
    USE par_oce
    USE par_trc
-#if defined key_bdy
-   USE bdy_oce, only: nb_bdy, OBC_DATA
-#endif
+   USE bdy_oce, only: ln_bdy, nb_bdy, OBC_DATA
    
    IMPLICIT NONE
@@ -189,5 +187,4 @@
 # endif
    !
-#if defined key_bdy
    CHARACTER(len=20), PUBLIC, ALLOCATABLE,  SAVE,  DIMENSION(:)   ::  cn_trc_dflt          ! Default OBC condition for all tracers
    CHARACTER(len=20), PUBLIC, ALLOCATABLE,  SAVE,  DIMENSION(:)   ::  cn_trc               ! Choice of boundary condition for tracers
@@ -195,5 +192,4 @@
    ! External data structure of BDY for TOP. Available elements: cn_obc, ll_trc, trcnow, dmp
    TYPE(OBC_DATA),    PUBLIC, ALLOCATABLE, DIMENSION(:,:), TARGET ::  trcdta_bdy           !: bdy external data (local process)
-#endif
    !
 
@@ -210,6 +206,8 @@
       !!-------------------------------------------------------------------
       USE lib_mpp, ONLY: ctl_warn
+      INTEGER :: ierr(2)
       !!-------------------------------------------------------------------
       !
+      ierr(:) = 0
       ALLOCATE( trn(jpi,jpj,jpk,jptra), trb(jpi,jpj,jpk,jptra), tra(jpi,jpj,jpk,jptra),       &  
          &      trc_i(jpi,jpj,jptra)  , trc_o(jpi,jpj,jptra)                          ,       &
@@ -223,9 +221,13 @@
          &      ln_trc_sbc(jptra)     , ln_trc_cbc(jptra)     , ln_trc_obc(jptra)     ,       &
 #endif
-#if defined key_bdy
-         &      cn_trc_dflt(nb_bdy)   , cn_trc(nb_bdy)        , nn_trcdmp_bdy(nb_bdy) ,       &
+         &      STAT = ierr(1)  )
+
+      IF ( ln_bdy ) THEN
+         ALLOCATE( cn_trc_dflt(nb_bdy)   , cn_trc(nb_bdy)     , nn_trcdmp_bdy(nb_bdy) ,       &
          &      trcdta_bdy(jptra,nb_bdy)                                              ,       &
-#endif
-         &      STAT = trc_alloc  )
+         &      STAT = ierr(2)  )
+      ENDIF
+         !
+      trc_alloc = MAXVAL( ierr )
 
       IF( trc_alloc /= 0 )   CALL ctl_warn('trc_alloc: failed to allocate arrays')
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/trcbc.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/trcbc.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/trcbc.F90	(revision 7299)
@@ -19,7 +19,5 @@
    USE lib_mpp       !  MPP library
    USE fldread       !  read input fields
-#if defined key_bdy
-   USE bdy_oce, only: nb_bdy , idx_bdy, ln_coords_file, rn_time_dmp, rn_time_dmp_out
-#endif
+   USE bdy_oce,  ONLY: ln_bdy, nb_bdy , idx_bdy, ln_coords_file, rn_time_dmp, rn_time_dmp_out
 
    IMPLICIT NONE
@@ -78,7 +76,6 @@
       !!
       NAMELIST/namtrc_bc/ cn_dir_sbc, cn_dir_cbc, cn_dir_obc, sn_trcobc, rn_trofac, sn_trcsbc, rn_trsfac, sn_trccbc, rn_trcfac
-#if defined key_bdy
       NAMELIST/namtrc_bdy/ cn_trc_dflt, cn_trc, nn_trcdmp_bdy
-#endif
+
       !!----------------------------------------------------------------------
       IF( nn_timing == 1 )  CALL timing_start('trc_bc_init')
@@ -128,37 +125,38 @@
       IF(lwm) WRITE ( numont, namtrc_bc )
 
-#if defined key_bdy
-      REWIND( numnat_ref )              ! Namelist namtrc_bc in reference namelist : Passive tracer data structure
-      READ  ( numnat_ref, namtrc_bdy, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_bdy in reference namelist', lwp )
-
-      REWIND( numnat_cfg )              ! Namelist namtrc_bc in configuration namelist : Passive tracer data structure
-      READ  ( numnat_cfg, namtrc_bdy, IOSTAT = ios, ERR = 904 )
-904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_bdy in configuration namelist', lwp )
-      IF(lwm) WRITE ( numont, namtrc_bdy )
-      ! setup up preliminary informations for BDY structure
-      DO jn = 1, ntrc
-         DO ib = 1, nb_bdy
-            ! Set type of obc in BDY data structure (around here we may plug user override of obc type from nml)
-            IF ( ln_trc_obc(jn) ) THEN
-               trcdta_bdy(jn,ib)%cn_obc = TRIM( cn_trc(ib) )
-            ELSE
-               trcdta_bdy(jn,ib)%cn_obc = TRIM( cn_trc_dflt(ib) )
-            ENDIF
-            ! set damping use in BDY data structure
-            trcdta_bdy(jn,ib)%dmp = .false.
-            IF(nn_trcdmp_bdy(ib) .EQ. 1 .AND. ln_trc_obc(jn) ) trcdta_bdy(jn,ib)%dmp = .true.
-            IF(nn_trcdmp_bdy(ib) .EQ. 2 ) trcdta_bdy(jn,ib)%dmp = .true.
-            IF(trcdta_bdy(jn,ib)%cn_obc == 'frs' .AND. nn_trcdmp_bdy(ib) .NE. 0 )  &
-                & CALL ctl_stop( 'Use FRS OR relaxation' )
-            IF (nn_trcdmp_bdy(ib) .LT. 0 .OR. nn_trcdmp_bdy(ib) .GT. 2)            &
-                & CALL ctl_stop( 'Not a valid option for nn_trcdmp_bdy. Allowed: 0,1,2.' )
+      IF ( ln_bdy ) THEN
+         REWIND( numnat_ref )              ! Namelist namtrc_bdy in reference namelist : Passive tracer data structure
+         READ  ( numnat_ref, namtrc_bdy, IOSTAT = ios, ERR = 903)
+903      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_bdy in reference namelist', lwp )
+
+         REWIND( numnat_cfg )              ! Namelist namtrc_bdy in configuration namelist : Passive tracer data structure
+         READ  ( numnat_cfg, namtrc_bdy, IOSTAT = ios, ERR = 904 )
+904      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_bdy in configuration namelist', lwp )
+         IF(lwm) WRITE ( numont, namtrc_bdy )
+      
+         ! setup up preliminary informations for BDY structure
+         DO jn = 1, ntrc
+            DO ib = 1, nb_bdy
+               ! Set type of obc in BDY data structure (around here we may plug user override of obc type from nml)
+               IF ( ln_trc_obc(jn) ) THEN
+                  trcdta_bdy(jn,ib)%cn_obc = TRIM( cn_trc(ib) )
+               ELSE
+                  trcdta_bdy(jn,ib)%cn_obc = TRIM( cn_trc_dflt(ib) )
+               ENDIF
+               ! set damping use in BDY data structure
+               trcdta_bdy(jn,ib)%dmp = .false.
+               IF(nn_trcdmp_bdy(ib) .EQ. 1 .AND. ln_trc_obc(jn) ) trcdta_bdy(jn,ib)%dmp = .true.
+               IF(nn_trcdmp_bdy(ib) .EQ. 2 ) trcdta_bdy(jn,ib)%dmp = .true.
+               IF(trcdta_bdy(jn,ib)%cn_obc == 'frs' .AND. nn_trcdmp_bdy(ib) .NE. 0 )  &
+                   & CALL ctl_stop( 'Use FRS OR relaxation' )
+               IF (nn_trcdmp_bdy(ib) .LT. 0 .OR. nn_trcdmp_bdy(ib) .GT. 2)            &
+                   & CALL ctl_stop( 'Not a valid option for nn_trcdmp_bdy. Allowed: 0,1,2.' )
+            ENDDO
          ENDDO
-      ENDDO
-
-#else
-      ! Force all tracers OBC to false if bdy not used
-      ln_trc_obc = .false.
-#endif
+      ELSE
+         ! Force all tracers OBC to false if bdy not used
+         ln_trc_obc = .false.
+      ENDIF
+
       ! compose BC data indexes
       DO jn = 1, ntrc
@@ -198,6 +196,6 @@
          WRITE(numout,*) ' '
          WRITE(numout,'(a,i3)') '   Total tracers to be initialized with OPEN BCs data:', nb_trcobc
-#if defined key_bdy
-         IF ( nb_trcobc > 0 ) THEN
+
+         IF ( ln_bdy .AND. nb_trcobc > 0 ) THEN
             WRITE(numout,*) '   #trc        NAME        Boundary     Mult.Fact.   OBC Settings'
             DO jn = 1, ntrc
@@ -217,5 +215,5 @@
             ENDDO
          ENDIF
-#endif
+
          WRITE(numout,'(2a)') '   OPEN BC data repository : ', TRIM(cn_dir_obc)
       ENDIF
@@ -225,7 +223,6 @@
 
       !
-#if defined key_bdy
       ! OPEN Lateral boundary conditions
-      IF( nb_trcobc > 0 ) THEN 
+      IF( ln_bdy .AND. nb_trcobc > 0 ) THEN 
          ALLOCATE ( sf_trcobc(nb_trcobc), rf_trofac(nb_trcobc), nbmap_ptr(nb_trcobc), STAT=ierr1 )
          IF( ierr1 > 0 ) THEN
@@ -272,5 +269,5 @@
          CALL fld_fill( sf_trcobc, slf_i, cn_dir_obc, 'trc_bc_init', 'Passive tracer OBC data', 'namtrc_bc' )
       ENDIF
-#endif
+
       ! SURFACE Boundary conditions
       IF( nb_trcsbc > 0 ) THEN       !  allocate only if the number of tracer to initialise is greater than zero
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/trcbdy.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/trcbdy.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/trcbdy.F90	(revision 7299)
@@ -9,11 +9,9 @@
    !!            3.5  !  2012     (S. Mocavero, I. Epicoco) Optimization of BDY communications
    !!            3.6  !  2015     (T. Lovato) Adapt BDY for tracers in TOP component
+   !!            4.0  !  2016     (T. Lovato) Generalize OBC structure
    !!----------------------------------------------------------------------
-#if defined key_bdy && key_top
+#if defined key_top
    !!----------------------------------------------------------------------
-   !!   'key_bdy'                     Unstructured Open Boundary Conditions
-   !!----------------------------------------------------------------------
-   !!   trc_bdy            : Apply open boundary conditions to T and S
-   !!   trc_bdy_frs        : Apply Flow Relaxation Scheme
+   !!   trc_bdy       : Apply open boundary conditions & damping to tracers
    !!----------------------------------------------------------------------
    USE timing                       ! Timing
@@ -24,5 +22,5 @@
    USE lbclnk                       ! ocean lateral boundary conditions (or mpp link)
    USE in_out_manager               ! I/O manager
-   USE bdy_oce, only: idx_bdy, OBC_INDEX, BDYTMASK, lk_bdy       ! ocean open boundary conditions
+   USE bdy_oce, only: idx_bdy       ! ocean open boundary conditions
 
    IMPLICIT NONE
@@ -33,5 +31,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.6 , NEMO Consortium (2015)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2016)
    !! $Id$ 
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -43,194 +41,40 @@
       !!                  ***  SUBROUTINE trc_bdy  ***
       !!
-      !! ** Purpose : - Apply open boundary conditions for tracers in TOP component
-      !!                and scale the tracer data
+      !! ** Purpose : - Apply open boundary conditions for TOP tracers
       !!
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) :: kt     ! Main time step counter
       !!
-      INTEGER               :: ib_bdy, jn ! Loop indeces
+      INTEGER                           :: ib_bdy, jn ! Loop indeces
+      REAL(wp), POINTER, DIMENSION(:,:) ::  ztrc
+      REAL(wp), POINTER                 ::  zfac
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 ) CALL timing_start('trc_bdy')
       !
-      DO jn = 1, jptra
-         DO ib_bdy=1, nb_bdy
-
-            SELECT CASE( trcdta_bdy(jn,ib_bdy)%cn_obc )
-            CASE('none')
-               CYCLE
-            CASE('frs')
-               CALL bdy_trc_frs( jn, idx_bdy(ib_bdy), trcdta_bdy(jn,ib_bdy), kt )
-            CASE('specified')
-               CALL bdy_trc_spe( jn, idx_bdy(ib_bdy), trcdta_bdy(jn,ib_bdy), kt )
-            CASE('neumann')
-               CALL bdy_trc_nmn( jn, idx_bdy(ib_bdy), trcdta_bdy(jn,ib_bdy), kt )
-            CASE('orlanski')
-               CALL bdy_trc_orlanski( jn, idx_bdy(ib_bdy), trcdta_bdy(jn,ib_bdy), ll_npo=.false. )
-            CASE('orlanski_npo')
-               CALL bdy_trc_orlanski( jn, idx_bdy(ib_bdy), trcdta_bdy(jn,ib_bdy), ll_npo=.true. )
-            CASE DEFAULT
-               CALL ctl_stop( 'trc_bdy : unrecognised option for open boundaries for passive tracers' )
+      DO ib_bdy=1, nb_bdy
+         DO jn = 1, jptra
+            !
+            ztrc => trcdta_bdy(jn,ib_bdy)%trc 
+            zfac => trcdta_bdy(jn,ib_bdy)%rn_fac
+            !
+            SELECT CASE( TRIM(trcdta_bdy(jn,ib_bdy)%cn_obc) )
+            CASE('none'        )   ;   CYCLE
+            CASE('frs'         )   ;   CALL bdy_frs( idx_bdy(ib_bdy),                tra(:,:,:,jn), ztrc*zfac )
+            CASE('specified'   )   ;   CALL bdy_spe( idx_bdy(ib_bdy),                tra(:,:,:,jn), ztrc*zfac )
+            CASE('neumann'     )   ;   CALL bdy_nmn( idx_bdy(ib_bdy),                tra(:,:,:,jn) )
+            CASE('orlanski'    )   ;   CALL bdy_orl( idx_bdy(ib_bdy), trb(:,:,:,jn), tra(:,:,:,jn), ztrc*zfac, ll_npo=.false. )
+            CASE('orlanski_npo')   ;   CALL bdy_orl( idx_bdy(ib_bdy), trb(:,:,:,jn), tra(:,:,:,jn), ztrc*zfac, ll_npo=.true. )
+            CASE DEFAULT           ;   CALL ctl_stop( 'trc_bdy : unrecognised option for open boundaries for passive tracers' )
             END SELECT
-
             ! Boundary points should be updated
             CALL lbc_bdy_lnk( tra(:,:,:,jn), 'T', 1., ib_bdy )
-
-         ENDDO
-      ENDDO
+            !
+         END DO
+      END DO
       !
       IF( nn_timing == 1 ) CALL timing_stop('trc_bdy')
 
    END SUBROUTINE trc_bdy
-
-   SUBROUTINE bdy_trc_frs( jn, idx, dta, kt )
-      !!----------------------------------------------------------------------
-      !!                 ***  SUBROUTINE bdy_trc_frs  ***
-      !!                    
-      !! ** Purpose : Apply the Flow Relaxation Scheme for tracers at open boundaries.
-      !! 
-      !! Reference : Engedahl H., 1995, Tellus, 365-382.
-      !!----------------------------------------------------------------------
-      INTEGER,         INTENT(in) ::   kt
-      INTEGER,         INTENT(in) ::   jn   ! Tracer index
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
-      !! 
-      REAL(wp) ::   zwgt           ! boundary weight
-      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
-      INTEGER  ::   ii, ij         ! 2D addresses
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 ) CALL timing_start('bdy_trc_frs')
-      ! 
-      igrd = 1                       ! Everything is at T-points here
-      DO ib = 1, idx%nblen(igrd)
-         DO ik = 1, jpkm1
-            ii = idx%nbi(ib,igrd)
-            ij = idx%nbj(ib,igrd)
-            zwgt = idx%nbw(ib,igrd)
-            tra(ii,ij,ik,jn) = ( tra(ii,ij,ik,jn) + zwgt * ( ( dta%trc(ib,ik) * dta%rn_fac)  & 
-                        &  - tra(ii,ij,ik,jn) ) ) * tmask(ii,ij,ik)
-         END DO
-      END DO 
-      !
-      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_trc_frs')
-      !
-   END SUBROUTINE bdy_trc_frs
-  
-   SUBROUTINE bdy_trc_spe( jn, idx, dta, kt )
-      !!----------------------------------------------------------------------
-      !!                 ***  SUBROUTINE bdy_trc_frs  ***
-      !!                    
-      !! ** Purpose : Apply a specified value for tracers at open boundaries.
-      !! 
-      !!----------------------------------------------------------------------
-      INTEGER,         INTENT(in) ::   kt
-      INTEGER,         INTENT(in) ::   jn   ! Tracer index
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
-      !! 
-      REAL(wp) ::   zwgt           ! boundary weight
-      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
-      INTEGER  ::   ii, ij         ! 2D addresses
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 ) CALL timing_start('bdy_trc_spe')
-      !
-      igrd = 1                       ! Everything is at T-points here
-      DO ib = 1, idx%nblenrim(igrd)
-         ii = idx%nbi(ib,igrd)
-         ij = idx%nbj(ib,igrd)
-         DO ik = 1, jpkm1
-            tra(ii,ij,ik,jn) = dta%trc(ib,ik) * dta%rn_fac * tmask(ii,ij,ik)
-         END DO
-      END DO
-      !
-      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_trc_spe')
-      !
-   END SUBROUTINE bdy_trc_spe
-
-   SUBROUTINE bdy_trc_nmn( jn, idx, dta, kt )
-      !!----------------------------------------------------------------------
-      !!                 ***  SUBROUTINE bdy_trc_nmn  ***
-      !!                    
-      !! ** Purpose : Duplicate the value for tracers at open boundaries.
-      !! 
-      !!----------------------------------------------------------------------
-      INTEGER,         INTENT(in) ::   kt
-      INTEGER,         INTENT(in) ::   jn   ! Tracer index
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
-      !! 
-      REAL(wp) ::   zwgt           ! boundary weight
-      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
-      INTEGER  ::   ii, ij, zcoef, zcoef1, zcoef2, ip, jp   ! 2D addresses
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 ) CALL timing_start('bdy_trc_nmn')
-      !
-      igrd = 1                       ! Everything is at T-points here
-      DO ib = 1, idx%nblenrim(igrd)
-         ii = idx%nbi(ib,igrd)
-         ij = idx%nbj(ib,igrd)
-         DO ik = 1, jpkm1
-            ! search the sense of the gradient
-            zcoef1 = bdytmask(ii-1,ij  ) +  bdytmask(ii+1,ij  )
-            zcoef2 = bdytmask(ii  ,ij-1) +  bdytmask(ii  ,ij+1)
-            IF ( zcoef1+zcoef2 == 0) THEN
-               ! corner
-               zcoef = tmask(ii-1,ij,ik) + tmask(ii+1,ij,ik) +  tmask(ii,ij-1,ik) +  tmask(ii,ij+1,ik)
-               tra(ii,ij,ik,jn) = tra(ii-1,ij  ,ik,jn) * tmask(ii-1,ij  ,ik) + &
-                 &                tra(ii+1,ij  ,ik,jn) * tmask(ii+1,ij  ,ik) + &
-                 &                tra(ii  ,ij-1,ik,jn) * tmask(ii  ,ij-1,ik) + &
-                 &                tra(ii  ,ij+1,ik,jn) * tmask(ii  ,ij+1,ik)
-               tra(ii,ij,ik,jn) = ( tra(ii,ij,ik,jn) / MAX( 1, zcoef) ) * tmask(ii,ij,ik)
-            ELSE
-               ip = bdytmask(ii+1,ij  ) - bdytmask(ii-1,ij  )
-               jp = bdytmask(ii  ,ij+1) - bdytmask(ii  ,ij-1)
-               tra(ii,ij,ik,jn) = tra(ii+ip,ij+jp,ik,jn) * tmask(ii+ip,ij+jp,ik)
-            ENDIF
-         END DO
-      END DO
-      !
-      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_trc_nmn')
-      !
-   END SUBROUTINE bdy_trc_nmn
- 
-
-   SUBROUTINE bdy_trc_orlanski( jn, idx, dta, ll_npo )
-      !!----------------------------------------------------------------------
-      !!                 ***  SUBROUTINE bdy_trc_orlanski  ***
-      !!             
-      !!              - Apply Orlanski radiation to tracers of TOP component. 
-      !!              - Wrapper routine for bdy_orlanski_3d
-      !! 
-      !!
-      !! References:  Marchesiello, McWilliams and Shchepetkin, Ocean Modelling vol. 3 (2001)    
-      !!----------------------------------------------------------------------
-      INTEGER,                      INTENT(in) ::   jn      ! Tracer index
-      TYPE(OBC_INDEX),              INTENT(in) ::   idx     ! OBC indices
-      TYPE(OBC_DATA),               INTENT(in) ::   dta     ! OBC external data
-      LOGICAL,                      INTENT(in) ::   ll_npo  ! switch for NPO version
-
-      INTEGER  ::   igrd                                    ! grid index
-      !!----------------------------------------------------------------------
-
-      IF( nn_timing == 1 ) CALL timing_start('bdy_trc_orlanski')
-      !
-      igrd = 1      ! Orlanski bc on tracers; 
-      !            
-      CALL bdy_orlanski_3d( idx, igrd, trb(:,:,:,jn), tra(:,:,:,jn), (dta%trc * dta%rn_fac), ll_npo )
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_trc_orlanski')
-      !
-
-   END SUBROUTINE bdy_trc_orlanski
 
    SUBROUTINE trc_bdy_dmp( kt )
Index: branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/trcsub.F90
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/trcsub.F90	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/NEMO/TOP_SRC/trcsub.F90	(revision 7299)
@@ -20,6 +20,6 @@
    USE domvvl
    USE divhor          ! horizontal divergence            (div_hor routine)
-   USE sbcrnf, ONLY: h_rnf, nk_rnf   ! River runoff 
-   USE bdy_oce
+   USE sbcrnf    , ONLY: h_rnf, nk_rnf    ! River runoff
+   USE bdy_oce   , ONLY: ln_bdy, bdytmask ! BDY
 #if defined key_agrif
    USE agrif_opa_update
@@ -493,5 +493,6 @@
       z1_rau0 = 0.5 / rau0
       ssha(:,:) = (  sshb(:,:) - z2dt * ( z1_rau0 * ( emp_b(:,:) + emp(:,:) ) + zhdiv(:,:) )  ) * tmask(:,:,1)
-#if ! defined key_dynspg_ts
+
+      IF( .NOT.ln_dynspg_ts ) THEN
       ! These lines are not necessary with time splitting since
       ! boundary condition on sea level is set during ts loop
@@ -499,9 +500,9 @@
       CALL agrif_ssh( kt )
 #endif
-#if defined key_bdy
-      ssha(:,:) = ssha(:,:) * bdytmask(:,:)
-      CALL lbc_lnk( ssha, 'T', 1. ) 
-#endif
-#endif
+         IF( ln_bdy ) THEN
+            ssha(:,:) = ssha(:,:) * bdytmask(:,:)
+            CALL lbc_lnk( ssha, 'T', 1. ) 
+         ENDIF
+      ENDIF
       !
       !                                           !------------------------------!
@@ -514,7 +515,5 @@
             &                      - ( e3t_a(:,:,jk) - e3t_b(:,:,jk) )    &
             &                         * tmask(:,:,jk) * z1_2dt
-#if defined key_bdy
-         wn(:,:,jk) = wn(:,:,jk) * bdytmask(:,:)
-#endif
+         IF( ln_bdy ) wn(:,:,jk) = wn(:,:,jk) * bdytmask(:,:)
       END DO
       !
Index: branches/2016/dev_CMCC_2016/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena	(revision 7299)
@@ -4,5 +4,5 @@
 #BSUB -n NPROCS
 #BSUB -a poe
-#BSUB -J MPI_config
+#BSUB -J NEMO_SETTE
 #BSUB -o poe.stdout.%J
 #BSUB -e poe.stderr.%J
Index: branches/2016/dev_CMCC_2016/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena_xios
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena_xios	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena_xios	(revision 7299)
@@ -4,5 +4,5 @@
 #BSUB -n TOTAL_NPROCS
 #BSUB -a poe
-#BSUB -J MPI_config
+#BSUB -J NEMO_SETTE
 #BSUB -o poe.stdout.%J
 #BSUB -e poe.stderr.%J
Index: branches/2016/dev_CMCC_2016/NEMOGCM/SETTE/sette.sh
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/SETTE/sette.sh	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/SETTE/sette.sh	(revision 7299)
@@ -767,5 +767,5 @@
     export TEST_NAME="LONG"
     cd ${CONFIG_DIR}
-    . ./makenemo -m ${CMP_NAM} -n AMM12_LONG -r AMM12 -j 8 add_key "key_tide" del_key ${DEL_KEYS}
+    . ./makenemo -m ${CMP_NAM} -n AMM12_LONG -r AMM12 -j 8 del_key ${DEL_KEYS}
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -829,5 +829,5 @@
     export TEST_NAME="REPRO_8_4"
     cd ${CONFIG_DIR}
-    . ./makenemo -m ${CMP_NAM} -n AMM12_32 -r AMM12 -j 8 add_key "key_tide" del_key ${DEL_KEYS}
+    . ./makenemo -m ${CMP_NAM} -n AMM12_32 -r AMM12 -j 8 del_key ${DEL_KEYS}
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -949,5 +949,5 @@
     export TEST_NAME="REPRO_8_4"
     cd ${CONFIG_DIR}
-    . ./makenemo -m ${CMP_NAM} -n SAS_32 -r ORCA2_SAS_LIM -j 8 add_key del_key ${DEL_KEYS}
+    . ./makenemo -m ${CMP_NAM} -n SAS_32 -r ORCA2_SAS_LIM -j 8 del_key ${DEL_KEYS}
     cd ${SETTE_DIR}
     . ./param.cfg
Index: branches/2016/dev_CMCC_2016/NEMOGCM/TRUST/inputs/AMM12/namelist_cfg
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/TRUST/inputs/AMM12/namelist_cfg	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/TRUST/inputs/AMM12/namelist_cfg	(revision 7299)
@@ -209,6 +209,7 @@
 /
 !-----------------------------------------------------------------------
-&nam_tide      !   tide parameters (#ifdef key_tide)
-!-----------------------------------------------------------------------
+&nam_tide      !   tide parameters
+!-----------------------------------------------------------------------
+   ln_tide     = .true.
    clname(1)     =   'Q1'   !  name of constituent
    clname(2)     =   'O1'
@@ -228,5 +229,6 @@
 /
 !-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries                          ("key_bdy")
+&nambdy        !  unstructured open boundaries
+    ln_bdy         = .true.
     nb_bdy         =  1
     cn_dyn2d       = 'flather'
@@ -236,5 +238,5 @@
 /
 !-----------------------------------------------------------------------
-&nambdy_dta      !  open boundaries - external data           ("key_bdy")
+&nambdy_dta      !  open boundaries - external data
 !-----------------------------------------------------------------------
 !          !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
Index: branches/2016/dev_CMCC_2016/NEMOGCM/TRUST/inputs/GYRE/namelist_cfg
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/TRUST/inputs/GYRE/namelist_cfg	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/TRUST/inputs/GYRE/namelist_cfg	(revision 7299)
@@ -163,13 +163,13 @@
 /
 !-----------------------------------------------------------------------
-&nam_tide      !    tide parameters (#ifdef key_tide)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries                          ("key_bdy")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy_dta      !  open boundaries - external data           ("key_bdy")
+&nam_tide      !    tide parameters
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy        !  unstructured open boundaries
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy_dta      !  open boundaries - external data
 !-----------------------------------------------------------------------
 /
Index: branches/2016/dev_CMCC_2016/NEMOGCM/fcm-make/inc/keys-amm12.cfg
===================================================================
--- branches/2016/dev_CMCC_2016/NEMOGCM/fcm-make/inc/keys-amm12.cfg	(revision 7298)
+++ branches/2016/dev_CMCC_2016/NEMOGCM/fcm-make/inc/keys-amm12.cfg	(revision 7299)
@@ -1,2 +1,2 @@
 preprocess.prop{fpp.defs} = \
-  key_bdy key_tide key_dynspg_ts key_ldfslp key_zdfgls key_vvl key_diainstant key_mpp_mpi key_iomput
+  key_dynspg_ts key_ldfslp key_zdfgls key_vvl key_diainstant key_mpp_mpi key_iomput
