Index: /branches/2015/dev_CMCC_merge_2015/NEMOGCM/CONFIG/SHARED/namelist_ref
===================================================================
--- /branches/2015/dev_CMCC_merge_2015/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 6052)
+++ /branches/2015/dev_CMCC_merge_2015/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 6053)
@@ -47,5 +47,4 @@
    nn_stocklist = 0,0,0,0,0,0,0,0,0,0 ! List of timesteps when a restart file is to be written
    nn_write    =    5475   !  frequency of write in the output file   (modulo referenced to nn_it000)
-   ln_dimgnnn  = .false.   !  DIMG file format: 1 file for all processors (F) or by processor (T)
    ln_mskland  = .false.   !  mask land points in NetCDF outputs (costly: + ~15%)
    ln_cfmeta   = .false.   !  output additional data to netCDF files required for compliance with the CF metadata standard
Index: /branches/2015/dev_CMCC_merge_2015/NEMOGCM/CONFIG/SHARED/namelist_top_ref
===================================================================
--- /branches/2015/dev_CMCC_merge_2015/NEMOGCM/CONFIG/SHARED/namelist_top_ref	(revision 6052)
+++ /branches/2015/dev_CMCC_merge_2015/NEMOGCM/CONFIG/SHARED/namelist_top_ref	(revision 6053)
@@ -123,4 +123,18 @@
 &namtrc_bc
 !
-   cn_dir        =  './'      !  root directory for the location of the data files
+   cn_dir_sbc        =  './'      !  root directory for the location of SURFACE data files
+   cn_dir_cbc        =  './'      !  root directory for the location of COASTAL data files
+   cn_dir_obc        =  './'      !  root directory for the location of OPEN data files
 /
+!----------------------------------------------------------------------
+!namtrc_bdy       !   Setup of tracer boundary conditions
+!-----------------------------------------------------------------------
+$namtrc_bdy
+   cn_trc_dflt     =  'neumann'    !  OBC applied by default to all tracers
+   cn_trc          =  'none'       !  Boundary conditions appled to the active tracers (see namtrc)
+
+   nn_trcdmp_bdy   = 0     !  Use damping timescales defined in nambdy of namelist
+                           !  = 0 NO damping of tracers at open boudaries
+                           !  = 1 Only for tracers forced with external data
+                           !  = 2 Damping applied to all tracers
+/
Index: /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90
===================================================================
--- /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 6052)
+++ /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 6053)
@@ -70,4 +70,10 @@
       REAL(wp), POINTER, DIMENSION(:,:) ::   ht_i   !: Now ice  thickness climatology
       REAL(wp), POINTER, DIMENSION(:,:) ::   ht_s   !: now snow thickness
+#endif
+#if defined key_top
+      CHARACTER(LEN=20)                   :: cn_obc  !: type of boundary condition to apply
+      REAL(wp)                            :: rn_fac  !: multiplicative scaling factor
+      REAL(wp), POINTER, DIMENSION(:,:)   :: trc     !: now field of the tracer
+      LOGICAL                             :: dmp     !: obc damping term
 #endif
    END TYPE OBC_DATA
Index: /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcsms_my_trc.F90
===================================================================
--- /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcsms_my_trc.F90	(revision 6052)
+++ /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcsms_my_trc.F90	(revision 6053)
@@ -18,4 +18,5 @@
    USE trd_oce
    USE trdtrc
+   USE trcbc, only : trc_bc_read
 
    IMPLICIT NONE
@@ -56,5 +57,10 @@
       IF( l_trdtrc )  CALL wrk_alloc( jpi, jpj, jpk, ztrmyt )
 
-      IF( l_trdtrc ) THEN      ! Save the trends in the ixed layer
+      CALL trc_bc_read  ( kt )       ! tracers: surface and lateral Boundary Conditions
+
+      ! add here the call to BGC model
+
+      ! Save the trends in the mixed layer
+      IF( l_trdtrc ) THEN
           DO jn = jp_myt0, jp_myt1
             ztrmyt(:,:,:) = tra(:,:,:,jn)
Index: /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcwri_my_trc.F90
===================================================================
--- /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcwri_my_trc.F90	(revision 6052)
+++ /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcwri_my_trc.F90	(revision 6053)
@@ -20,4 +20,5 @@
    PUBLIC trc_wri_my_trc 
 
+#  include "top_substitute.h90"
 CONTAINS
 
@@ -36,5 +37,5 @@
       DO jn = jp_myt0, jp_myt1
          cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
-         CALL iom_put( cltra, trn(:,:,:,jn) )
+         IF( ln_trc_wri(jn) ) CALL iom_put( cltra, trn(:,:,:,jn) )
       END DO
       !
Index: /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90
===================================================================
--- /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 6052)
+++ /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 6053)
@@ -33,4 +33,6 @@
    USE trdtra
    USE tranxt
+   USE trcbdy          ! BDY open boundaries
+   USE bdy_par, only: lk_bdy
 # if defined key_agrif
    USE agrif_top_interp
@@ -98,9 +100,5 @@
       END DO
 
-
-#if defined key_bdy
-!!      CALL bdy_trc( kt )               ! BDY open boundaries
-#endif
-
+      IF( lk_bdy )  CALL trc_bdy( kt )               ! BDY open boundaries
 
       ! set time step size (Euler/Leapfrog)
Index: /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90
===================================================================
--- /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 6052)
+++ /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 6053)
@@ -25,4 +25,6 @@
    USE trcsbc          ! surface boundary condition          (trc_sbc routine)
    USE zpshde          ! partial step: hor. derivative       (zps_hde routine)
+   USE trcbdy          ! BDY open boundaries
+   USE bdy_par, only: lk_bdy
 
 #if defined key_agrif
@@ -64,4 +66,5 @@
          IF( ln_trcdmp )        CALL trc_dmp    ( kt )      ! internal damping trends
          IF( ln_trcdmp_clo )    CALL trc_dmp_clo( kt )      ! internal damping trends on closed seas only
+         IF( lk_bdy )           CALL trc_bdy_dmp( kt )      ! BDY damping trends
                                 CALL trc_adv    ( kt )      ! horizontal & vertical advection 
          !                                                         ! Partial top/bottom cell: GRADh( trb )  
Index: /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trc.F90
===================================================================
--- /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 6052)
+++ /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 6053)
@@ -91,4 +91,9 @@
        CHARACTER(len = 20)  :: clunit   !: unit
        LOGICAL              :: llinit   !: read in a file or not
+#if defined  key_my_trc
+       LOGICAL              :: llsbc   !: read in a file or not
+       LOGICAL              :: llcbc   !: read in a file or not
+       LOGICAL              :: llobc   !: read in a file or not
+#endif
        LOGICAL              :: llsave   !: save the tracer or not
    END TYPE PTRACER
@@ -181,4 +186,12 @@
 # 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
+   INTEGER,           PUBLIC, ALLOCATABLE,  SAVE,  DIMENSION(:)   ::  nn_trcdmp_bdy        !: =T Tracer damping
+   ! 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
+   !
 
    !!----------------------------------------------------------------------
@@ -203,5 +216,13 @@
          &      cvol(jpi,jpj,jpk)     , trai(jptra)                                   ,       &
          &      ctrcnm(jptra)         , ctrcln(jptra)         , ctrcun(jptra)         ,       & 
-         &      ln_trc_ini(jptra)     , ln_trc_wri(jptra)     , qsr_mean(jpi,jpj)     ,  STAT = trc_alloc  )  
+         &      ln_trc_ini(jptra)     , ln_trc_wri(jptra)     , qsr_mean(jpi,jpj)     ,       &
+#if defined key_my_trc
+         &      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) ,       &
+         &      trcdta_bdy(jptra,nb_bdy)                                              ,       &
+#endif
+         &      STAT = trc_alloc  )
 
       IF( trc_alloc /= 0 )   CALL ctl_warn('trc_alloc: failed to allocate arrays')
Index: /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcbc.F90
===================================================================
--- /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcbc.F90	(revision 6052)
+++ /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcbc.F90	(revision 6053)
@@ -4,10 +4,12 @@
    !! TOP :  module for passive tracer boundary conditions
    !!=====================================================================
-   !!----------------------------------------------------------------------
-#if  defined key_top 
+   !! History :  3.5 !  2014-04  (M. Vichi, T. Lovato)  Original
+   !!            3.6 !  2015-03  (T . Lovato) Revision and BDY support
+   !!----------------------------------------------------------------------
+#if defined key_top
    !!----------------------------------------------------------------------
    !!   'key_top'                                                TOP model 
    !!----------------------------------------------------------------------
-   !!   trc_dta    : read and time interpolated passive tracer data
+   !!   trc_bc       : read and time interpolated tracer Boundary Conditions
    !!----------------------------------------------------------------------
    USE par_trc       !  passive tracers parameters
@@ -17,4 +19,7 @@
    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
 
    IMPLICIT NONE
@@ -24,25 +29,23 @@
    PUBLIC   trc_bc_read    ! called in trcstp.F90 or within
 
-   INTEGER  , SAVE, PUBLIC                             :: nb_trcobc   ! number of tracers with open BC
-   INTEGER  , SAVE, PUBLIC                             :: nb_trcsbc   ! number of tracers with surface BC
-   INTEGER  , SAVE, PUBLIC                             :: nb_trccbc   ! number of tracers with coastal BC
+   INTEGER  , SAVE, PUBLIC                             :: nb_trcobc    ! number of tracers with open BC
+   INTEGER  , SAVE, PUBLIC                             :: nb_trcsbc    ! number of tracers with surface BC
+   INTEGER  , SAVE, PUBLIC                             :: nb_trccbc    ! number of tracers with coastal BC
    INTEGER  , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: n_trc_indobc ! index of tracer with OBC data
    INTEGER  , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: n_trc_indsbc ! index of tracer with SBC data
    INTEGER  , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: n_trc_indcbc ! index of tracer with CBC data
-   INTEGER  , SAVE, PUBLIC                             :: ntra_obc     ! MAX( 1, nb_trcxxx ) to avoid compilation error with bounds checking
-   INTEGER  , SAVE, PUBLIC                             :: ntra_sbc     ! MAX( 1, nb_trcxxx ) to avoid compilation error with bounds checking
-   INTEGER  , SAVE, PUBLIC                             :: ntra_cbc     ! MAX( 1, nb_trcxxx ) to avoid compilation error with bounds checking
-   REAL(wp) , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: rf_trofac   ! multiplicative factor for OBCtracer values
-   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: sf_trcobc   ! structure of data input OBC (file informations, fields read)
-   REAL(wp) , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: rf_trsfac   ! multiplicative factor for SBC tracer values
-   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: sf_trcsbc   ! structure of data input SBC (file informations, fields read)
-   REAL(wp) , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: rf_trcfac   ! multiplicative factor for CBC tracer values
-   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: sf_trccbc   ! structure of data input CBC (file informations, fields read)
+   REAL(wp) , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: rf_trsfac    ! multiplicative factor for SBC tracer values
+   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: sf_trcsbc    ! structure of data input SBC (file informations, fields read)
+   REAL(wp) , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: rf_trcfac    ! multiplicative factor for CBC tracer values
+   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: sf_trccbc    ! structure of data input CBC (file informations, fields read)
+   REAL(wp) , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: rf_trofac    ! multiplicative factor for OBCtracer values
+   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:), TARGET  :: sf_trcobc    ! structure of data input OBC (file informations, fields read)
+   TYPE(MAP_POINTER), ALLOCATABLE, DIMENSION(:) :: nbmap_ptr   ! array of pointers to nbmap
 
    !! * Substitutions
 #  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
+   !! NEMO/OPA 3.6 , NEMO Consortium (2015)
+   !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -60,10 +63,12 @@
       !
       INTEGER,INTENT(IN) :: ntrc                           ! number of tracers
-      INTEGER            :: jl, jn                         ! dummy loop indices
+      INTEGER            :: jl, jn , ib, ibd, ii, ij, ik   ! dummy loop indices
       INTEGER            :: ierr0, ierr1, ierr2, ierr3     ! temporary integers
-      INTEGER            ::  ios                           ! Local integer output status for namelist read
+      INTEGER            :: ios                            ! Local integer output status for namelist read
+      INTEGER            :: nblen, igrd                    ! support arrays for BDY
       CHARACTER(len=100) :: clndta, clntrc
       !
-      CHARACTER(len=100) :: cn_dir
+      CHARACTER(len=100) :: cn_dir_sbc, cn_dir_cbc, cn_dir_obc
+
       TYPE(FLD_N), ALLOCATABLE, DIMENSION(:) :: slf_i  ! local array of namelist informations on the fields to read
       TYPE(FLD_N), DIMENSION(jpmaxtrc) :: sn_trcobc    ! open
@@ -74,8 +79,16 @@
       REAL(wp)   , DIMENSION(jpmaxtrc) :: rn_trcfac    ! multiplicative factor for tracer values
       !!
-      NAMELIST/namtrc_bc/ cn_dir, sn_trcobc, rn_trofac, sn_trcsbc, rn_trsfac, sn_trccbc, rn_trcfac 
+      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')
       !
+      IF( lwp ) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) 'trc_bc_init : Tracers Boundary Conditions (BC)'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
       !  Initialisation and local array allocation
       ierr0 = 0  ;  ierr1 = 0  ;  ierr2 = 0  ;  ierr3 = 0  
@@ -107,31 +120,5 @@
       n_trc_indcbc(:) = 0
       !
-      DO jn = 1, ntrc
-         IF( ln_trc_obc(jn) ) THEN
-             nb_trcobc       = nb_trcobc + 1 
-             n_trc_indobc(jn) = nb_trcobc 
-         ENDIF
-         IF( ln_trc_sbc(jn) ) THEN
-             nb_trcsbc       = nb_trcsbc + 1
-             n_trc_indsbc(jn) = nb_trcsbc
-         ENDIF
-         IF( ln_trc_cbc(jn) ) THEN
-             nb_trccbc       = nb_trccbc + 1
-             n_trc_indcbc(jn) = nb_trccbc
-         ENDIF
-      ENDDO
-      ntra_obc = MAX( 1, nb_trcobc )   ! To avoid compilation error with bounds checking
-      IF( lwp ) WRITE(numout,*) ' '
-      IF( lwp ) WRITE(numout,*) ' Number of passive tracers to be initialized with open boundary data :', nb_trcobc
-      IF( lwp ) WRITE(numout,*) ' '
-      ntra_sbc = MAX( 1, nb_trcsbc )   ! To avoid compilation error with bounds checking
-      IF( lwp ) WRITE(numout,*) ' '
-      IF( lwp ) WRITE(numout,*) ' Number of passive tracers to be initialized with surface boundary data :', nb_trcsbc
-      IF( lwp ) WRITE(numout,*) ' '
-      ntra_cbc = MAX( 1, nb_trccbc )   ! To avoid compilation error with bounds checking
-      IF( lwp ) WRITE(numout,*) ' '
-      IF( lwp ) WRITE(numout,*) ' Number of passive tracers to be initialized with coastal boundary data :', nb_trccbc
-      IF( lwp ) WRITE(numout,*) ' '
-
+      ! Read Boundary Conditions Namelists
       REWIND( numnat_ref )              ! Namelist namtrc_bc in reference namelist : Passive tracer data structure
       READ  ( numnat_ref, namtrc_bc, IOSTAT = ios, ERR = 901)
@@ -143,54 +130,149 @@
       IF(lwm) WRITE ( numont, namtrc_bc )
 
-      ! print some information for each 
+#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.' )
+         ENDDO
+      ENDDO
+
+#else
+      ! Force all tracers OBC to false if bdy not used
+      ln_trc_obc = .false.
+#endif
+      ! compose BC data indexes
+      DO jn = 1, ntrc
+         IF( ln_trc_obc(jn) ) THEN
+             nb_trcobc       = nb_trcobc + 1  ; n_trc_indobc(jn) = nb_trcobc
+         ENDIF
+         IF( ln_trc_sbc(jn) ) THEN
+             nb_trcsbc       = nb_trcsbc + 1  ; n_trc_indsbc(jn) = nb_trcsbc
+         ENDIF
+         IF( ln_trc_cbc(jn) ) THEN
+             nb_trccbc       = nb_trccbc + 1  ; n_trc_indcbc(jn) = nb_trccbc
+         ENDIF
+      ENDDO
+
+      ! Print summmary of Boundary Conditions
       IF( lwp ) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,'(a,i3)') '   Total tracers to be initialized with SURFACE BCs data:', nb_trcsbc
+         IF ( nb_trcsbc > 0 ) THEN
+            WRITE(numout,*) '   #trc        NAME        Boundary     Mult.Fact. '
+            DO jn = 1, ntrc
+               IF ( ln_trc_sbc(jn) ) WRITE(numout,9001) jn, TRIM( sn_trcsbc(jn)%clvar ), 'SBC', rn_trsfac(jn)
+            ENDDO
+         ENDIF
+         WRITE(numout,'(2a)') '   SURFACE BC data repository : ', TRIM(cn_dir_sbc)
+
+         WRITE(numout,*) ' '
+         WRITE(numout,'(a,i3)') '   Total tracers to be initialized with COASTAL BCs data:', nb_trccbc
+         IF ( nb_trccbc > 0 ) THEN
+            WRITE(numout,*) '   #trc        NAME        Boundary     Mult.Fact. '
+            DO jn = 1, ntrc
+               IF ( ln_trc_cbc(jn) ) WRITE(numout, 9001) jn, TRIM( sn_trccbc(jn)%clvar ), 'CBC', rn_trcfac(jn)
+            ENDDO
+         ENDIF
+         WRITE(numout,'(2a)') '   COASTAL BC data repository : ', TRIM(cn_dir_cbc)
+
+         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
+            WRITE(numout,*) '   #trc        NAME        Boundary     Mult.Fact.   OBC Settings'
+            DO jn = 1, ntrc
+               IF ( ln_trc_obc(jn) )  WRITE(numout, 9001) jn, TRIM( sn_trcobc(jn)%clvar ), 'OBC', rn_trofac(jn), (trcdta_bdy(jn,ib)%cn_obc,ib=1,nb_bdy)
+               IF ( .NOT. ln_trc_obc(jn) )  WRITE(numout, 9002) jn, 'Set data to IC and use default condition', (trcdta_bdy(jn,ib)%cn_obc,ib=1,nb_bdy)
+            ENDDO
+            WRITE(numout,*) ' '
+            DO ib = 1, nb_bdy
+                IF (nn_trcdmp_bdy(ib) .EQ. 0) WRITE(numout,9003) '   Boundary ',ib,' -> NO damping of tracers'
+                IF (nn_trcdmp_bdy(ib) .EQ. 1) WRITE(numout,9003) '   Boundary ',ib,' -> damping ONLY for tracers with external data provided'
+                IF (nn_trcdmp_bdy(ib) .EQ. 2) WRITE(numout,9003) '   Boundary ',ib,' -> damping of ALL tracers'
+                IF (nn_trcdmp_bdy(ib) .GT. 0) THEN
+                   WRITE(numout,9003) '     USE damping parameters from nambdy for boundary ', ib,' : '
+                   WRITE(numout,'(a,f10.2,a)') '     - Inflow damping time scale  : ',rn_time_dmp(ib),' days'
+                   WRITE(numout,'(a,f10.2,a)') '     - Outflow damping time scale : ',rn_time_dmp_out(ib),' days'
+                ENDIF
+            ENDDO
+         ENDIF
+#endif
+         WRITE(numout,'(2a)') '   OPEN BC data repository : ', TRIM(cn_dir_obc)
+      ENDIF
+9001  FORMAT(2x,i5, 3x, a15, 3x, a5, 6x, e11.3, 4x, 10a13)
+9002  FORMAT(2x,i5, 3x, a41, 3x, 10a13)
+9003  FORMAT(a, i5, a)
+
+      !
+#if defined key_bdy
+      ! OPEN Lateral boundary conditions
+      IF( nb_trcobc > 0 ) THEN 
+         ALLOCATE ( sf_trcobc(nb_trcobc), rf_trofac(nb_trcobc), nbmap_ptr(nb_trcobc), STAT=ierr1 )
+         IF( ierr1 > 0 ) THEN
+            CALL ctl_stop( 'trc_bc_init: unable to allocate sf_trcobc structure' )   ;   RETURN
+         ENDIF
+
+         igrd = 1                       ! Everything is at T-points here
+
          DO jn = 1, ntrc
-            IF( ln_trc_obc(jn) )  THEN    
-               clndta = TRIM( sn_trcobc(jn)%clvar ) 
-               IF(lwp) WRITE(numout,*) 'Preparing to read OBC data file for passive tracer number :', jn, ' name : ', clndta, & 
-               &               ' multiplicative factor : ', rn_trofac(jn)
-            ENDIF
-            IF( ln_trc_sbc(jn) )  THEN    
-               clndta = TRIM( sn_trcsbc(jn)%clvar ) 
-               IF(lwp) WRITE(numout,*) 'Preparing to read SBC data file for passive tracer number :', jn, ' name : ', clndta, & 
-               &               ' multiplicative factor : ', rn_trsfac(jn)
-            ENDIF
-            IF( ln_trc_cbc(jn) )  THEN    
-               clndta = TRIM( sn_trccbc(jn)%clvar ) 
-               IF(lwp) WRITE(numout,*) 'Preparing to read CBC data file for passive tracer number :', jn, ' name : ', clndta, & 
-               &               ' multiplicative factor : ', rn_trcfac(jn)
-            ENDIF
-         END DO
-      ENDIF
-      !
-      ! The following code is written this way to reduce memory usage and repeated for each boundary data
-      ! MAV: note that this is just a placeholder and the dimensions must be changed according to 
-      !      what will be done with BDY. A new structure will probably need to be included
-      !
-      ! OPEN Lateral boundary conditions
-      IF( nb_trcobc > 0 ) THEN       !  allocate only if the number of tracer to initialise is greater than zero
-         ALLOCATE( sf_trcobc(nb_trcobc), rf_trofac(nb_trcobc), STAT=ierr1 )
-         IF( ierr1 > 0 ) THEN
-            CALL ctl_stop( 'trc_bc_init: unable to allocate  sf_trcobc structure' )   ;   RETURN
-         ENDIF
-         !
-         DO jn = 1, ntrc
-            IF( ln_trc_obc(jn) ) THEN      ! update passive tracers arrays with input data read from file
-               jl = n_trc_indobc(jn)
-               slf_i(jl)    = sn_trcobc(jn)
-               rf_trofac(jl) = rn_trofac(jn)
-                                            ALLOCATE( sf_trcobc(jl)%fnow(jpi,jpj,jpk)   , STAT=ierr2 )
-               IF( sn_trcobc(jn)%ln_tint )  ALLOCATE( sf_trcobc(jl)%fdta(jpi,jpj,jpk,2) , STAT=ierr3 )
-               IF( ierr2 + ierr3 > 0 ) THEN
-                 CALL ctl_stop( 'trc_bc_init : unable to allocate passive tracer OBC data arrays' )   ;   RETURN
+            DO ib = 1, nb_bdy
+
+               nblen = idx_bdy(ib)%nblen(igrd)
+
+               IF ( ln_trc_obc(jn) ) THEN
+               ! Initialise from external data
+                  jl = n_trc_indobc(jn)
+                  slf_i(jl)    = sn_trcobc(jn)
+                  rf_trofac(jl) = rn_trofac(jn)
+                                               ALLOCATE( sf_trcobc(jl)%fnow(nblen,1,jpk)   , STAT=ierr2 )
+                  IF( sn_trcobc(jn)%ln_tint )  ALLOCATE( sf_trcobc(jl)%fdta(nblen,1,jpk,2) , STAT=ierr3 )
+                  IF( ierr2 + ierr3 > 0 ) THEN
+                    CALL ctl_stop( 'trc_bc_init : unable to allocate passive tracer OBC data arrays' )   ;   RETURN
+                  ENDIF
+                  trcdta_bdy(jn,ib)%trc => sf_trcobc(jl)%fnow(:,1,:)
+                  trcdta_bdy(jn,ib)%rn_fac = rf_trofac(jl)
+                  ! create OBC mapping array
+                  nbmap_ptr(jl)%ptr => idx_bdy(ib)%nbmap(:,igrd)
+                  nbmap_ptr(jl)%ll_unstruc = ln_coords_file(igrd)
+               ELSE
+               ! Initialise obc arrays from initial conditions
+                  ALLOCATE ( trcdta_bdy(jn,ib)%trc(nblen,jpk) )
+                  DO ibd = 1, nblen
+                     DO ik = 1, jpkm1
+                        ii = idx_bdy(ib)%nbi(ibd,igrd)
+                        ij = idx_bdy(ib)%nbj(ibd,igrd)
+                        trcdta_bdy(jn,ib)%trc(ibd,ik) = trn(ii,ij,ik,jn) * tmask(ii,ij,ik)
+                     END DO
+                  END DO
+                  trcdta_bdy(jn,ib)%rn_fac = 1._wp
                ENDIF
-            ENDIF
-            !   
+            ENDDO
          ENDDO
-         !                         ! fill sf_trcdta with slf_i and control print
-         CALL fld_fill( sf_trcobc, slf_i, cn_dir, 'trc_bc_init', 'Passive tracer OBC data', 'namtrc_bc' )
-         !
-      ENDIF
-      !
+
+         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
@@ -214,5 +296,5 @@
          ENDDO
          !                         ! fill sf_trcsbc with slf_i and control print
-         CALL fld_fill( sf_trcsbc, slf_i, cn_dir, 'trc_bc_init', 'Passive tracer SBC data', 'namtrc_bc' )
+         CALL fld_fill( sf_trcsbc, slf_i, cn_dir_sbc, 'trc_bc_init', 'Passive tracer SBC data', 'namtrc_bc' )
          !
       ENDIF
@@ -239,5 +321,5 @@
          ENDDO
          !                         ! fill sf_trccbc with slf_i and control print
-         CALL fld_fill( sf_trccbc, slf_i, cn_dir, 'trc_bc_init', 'Passive tracer CBC data', 'namtrc_bc' )
+         CALL fld_fill( sf_trccbc, slf_i, cn_dir_cbc, 'trc_bc_init', 'Passive tracer CBC data', 'namtrc_bc' )
          !
       ENDIF
@@ -249,5 +331,5 @@
 
 
-   SUBROUTINE trc_bc_read(kt)
+   SUBROUTINE trc_bc_read(kt, jit)
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE trc_bc_init  ***
@@ -264,33 +346,57 @@
       !! * Arguments
       INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-
+      INTEGER, INTENT( in ), OPTIONAL ::   jit   ! subcycle time-step index (for timesplitting option)
       !!---------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('trc_bc_read')
 
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'trc_bc_read : Surface boundary conditions for passive tracers.'
-         IF(lwp) WRITE(numout,*) '~~~~~~~ '
-      ENDIF
-
-      ! OPEN boundary conditions: DOES NOT WORK. Waiting for stable BDY
-      IF( nb_trcobc > 0 ) THEN
-        if (lwp) write(numout,'(a,i5,a,i5)') '   reading OBC data for ', nb_trcobc ,' variables at step ', kt
-        CALL fld_read(kt,1,sf_trcobc)
-        ! vertical interpolation on s-grid and partial step to be added
-      ENDIF
-
-      ! SURFACE boundary conditions       
-      IF( nb_trcsbc > 0 ) THEN
-        if (lwp) write(numout,'(a,i5,a,i5)') '   reading SBC data for ', nb_trcsbc ,' variables at step ', kt
-        CALL fld_read(kt,1,sf_trcsbc)
-      ENDIF
-
-      ! COASTAL boundary conditions       
-      IF( nb_trccbc > 0 ) THEN
-        if (lwp) write(numout,'(a,i5,a,i5)') '   reading CBC data for ', nb_trccbc ,' variables at step ', kt
-        CALL fld_read(kt,1,sf_trccbc)
-      ENDIF   
+      IF( kt == nit000 .AND. lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trc_bc_read : Surface boundary conditions for passive tracers.'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+
+      IF ( PRESENT(jit) ) THEN 
+
+         ! OPEN boundary conditions (use time_offset=+1 as they are applied at the end of the step)
+         IF( nb_trcobc > 0 ) THEN
+           if (lwp) write(numout,'(a,i5,a,i10)') '   reading OBC data for ', nb_trcobc ,' variable(s) at step ', kt
+           CALL fld_read(kt=kt, kn_fsbc=1, sd=sf_trcobc, map=nbmap_ptr, kit=jit, kt_offset=+1)
+         ENDIF
+
+         ! SURFACE boundary conditions
+         IF( nb_trcsbc > 0 ) THEN
+           if (lwp) write(numout,'(a,i5,a,i10)') '   reading SBC data for ', nb_trcsbc ,' variable(s) at step ', kt
+           CALL fld_read(kt=kt, kn_fsbc=1, sd=sf_trcsbc, kit=jit)
+         ENDIF
+
+         ! COASTAL boundary conditions
+         IF( nb_trccbc > 0 ) THEN
+           if (lwp) write(numout,'(a,i5,a,i10)') '   reading CBC data for ', nb_trccbc ,' variable(s) at step ', kt
+           CALL fld_read(kt=kt, kn_fsbc=1, sd=sf_trccbc, kit=jit)
+         ENDIF
+
+      ELSE
+
+         ! OPEN boundary conditions (use time_offset=+1 as they are applied at the end of the step)
+         IF( nb_trcobc > 0 ) THEN
+           if (lwp) write(numout,'(a,i5,a,i10)') '   reading OBC data for ', nb_trcobc ,' variable(s) at step ', kt
+           CALL fld_read(kt=kt, kn_fsbc=1, sd=sf_trcobc, map=nbmap_ptr, kt_offset=+1)
+         ENDIF
+
+         ! SURFACE boundary conditions
+         IF( nb_trcsbc > 0 ) THEN
+           if (lwp) write(numout,'(a,i5,a,i10)') '   reading SBC data for ', nb_trcsbc ,' variable(s) at step ', kt
+           CALL fld_read(kt=kt, kn_fsbc=1, sd=sf_trcsbc)
+         ENDIF
+
+         ! COASTAL boundary conditions
+         IF( nb_trccbc > 0 ) THEN
+           if (lwp) write(numout,'(a,i5,a,i10)') '   reading CBC data for ', nb_trccbc ,' variable(s) at step ', kt
+           CALL fld_read(kt=kt, kn_fsbc=1, sd=sf_trccbc)
+         ENDIF
+
+      ENDIF
+
       !
       IF( nn_timing == 1 )  CALL timing_stop('trc_bc_read')
@@ -303,4 +409,10 @@
    !!----------------------------------------------------------------------
 CONTAINS
+
+   SUBROUTINE trc_bc_init( ntrc )        ! Empty routine
+      INTEGER,INTENT(IN) :: ntrc                           ! number of tracers
+      WRITE(*,*) 'trc_bc_init: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_bc_init
+
    SUBROUTINE trc_bc_read( kt )        ! Empty routine
       WRITE(*,*) 'trc_bc_read: You should not have seen this print! error?', kt
Index: /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcbdy.F90
===================================================================
--- /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcbdy.F90	(revision 6053)
+++ /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcbdy.F90	(revision 6053)
@@ -0,0 +1,293 @@
+MODULE trcbdy
+   !!======================================================================
+   !!                       ***  MODULE  bdytrc  ***
+   !! Ocean tracers:   Apply boundary conditions for tracers in TOP component
+   !!======================================================================
+   !! History :  1.0  !  2005-01  (J. Chanut, A. Sellar)  Original code
+   !!            3.0  !  2008-04  (NEMO team)  add in the reference version
+   !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
+   !!            3.5  !  2012     (S. Mocavero, I. Epicoco) Optimization of BDY communications
+   !!            3.6  !  2015     (T. Lovato) Adapt BDY for tracers in TOP component
+   !!----------------------------------------------------------------------
+#if defined key_bdy && 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
+   !!----------------------------------------------------------------------
+   USE timing                       ! Timing
+   USE oce_trc                      ! ocean dynamics and tracers variables
+   USE par_trc
+   USE trc                          ! ocean space and time domain variables 
+   USE bdylib                       ! for orlanski library routines
+   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
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_bdy      ! routine called in trcnxt.F90 
+   PUBLIC trc_bdy_dmp  ! routine called in trcstp.F90 
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.6 , NEMO Consortium (2015)
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trc_bdy( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  SUBROUTINE trc_bdy  ***
+      !!
+      !! ** Purpose : - Apply open boundary conditions for tracers in TOP component
+      !!                and scale the tracer data
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) :: kt     ! Main time step counter
+      !!
+      INTEGER               :: ib_bdy, jn ! Loop indeces
+      !!----------------------------------------------------------------------
+      !
+      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' )
+            END SELECT
+
+            ! Boundary points should be updated
+            CALL lbc_bdy_lnk( tra(:,:,:,jn), 'T', 1., ib_bdy )
+
+         ENDDO
+      ENDDO
+      !
+      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 )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE trc_bdy_dmp  ***
+      !!                    
+      !! ** Purpose : Apply damping for tracers at open boundaries.
+      !!             It currently applies the damping to all tracers!!!
+      !! 
+      !!----------------------------------------------------------------------
+      INTEGER,         INTENT(in) ::   kt
+      !! 
+      INTEGER  ::   jn             ! Tracer index
+      REAL(wp) ::   zwgt           ! boundary weight
+      REAL(wp) ::   zta, zsa, ztime
+      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
+      INTEGER  ::   ii, ij         ! 2D addresses
+      INTEGER  ::   ib_bdy         ! Loop index
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('trc_bdy_dmp')
+      !
+      DO jn = 1, jptra
+         DO ib_bdy=1, nb_bdy
+            IF ( trcdta_bdy(jn, ib_bdy)%dmp ) THEN
+               igrd = 1                       ! Everything is at T-points here
+               DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
+                  ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                  ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                  zwgt = idx_bdy(ib_bdy)%nbd(ib,igrd)
+                  DO ik = 1, jpkm1
+                     zta = zwgt * ( trcdta_bdy(jn, ib_bdy)%trc(ib,ik) - trb(ii,ij,ik,jn) ) * tmask(ii,ij,ik)
+                     tra(ii,ij,ik,jn) = tra(ii,ij,ik,jn) + zta
+                  END DO
+               END DO
+            ENDIF
+         ENDDO
+      ENDDO
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('trc_bdy_dmp')
+      !
+   END SUBROUTINE trc_bdy_dmp
+ 
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                   NO Unstruct Open Boundary Conditions
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_bdy(kt)      ! Empty routine
+      WRITE(*,*) 'trc_bdy: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_bdy
+
+   SUBROUTINE trc_bdy_dmp(kt)      ! Empty routine
+      WRITE(*,*) 'trc_bdy_dmp: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_bdy_dmp
+
+#endif
+
+   !!======================================================================
+END MODULE trcbdy
Index: /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcdta.F90
===================================================================
--- /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcdta.F90	(revision 6052)
+++ /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcdta.F90	(revision 6053)
@@ -9,6 +9,7 @@
    !!            3.4   !  2010-11  (C. Ethe, G. Madec)  use of fldread + dynamical allocation 
    !!            3.5   !  2013-08  (M. Vichi)  generalization for other BGC models
-   !!----------------------------------------------------------------------
-#if  defined key_top 
+   !!            3.6   !  2015-03  (T. Lovato) revision of code log info
+   !!----------------------------------------------------------------------
+#if defined key_top 
    !!----------------------------------------------------------------------
    !!   'key_top'                                                TOP model 
@@ -72,4 +73,10 @@
       IF( nn_timing == 1 )  CALL timing_start('trc_dta_init')
       !
+      IF( lwp ) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) '  trc_dta_init : Tracers Initial Conditions (IC)'
+         WRITE(numout,*) '  ~~~~~~~~~~~ '
+      ENDIF
+      !
       !  Initialisation
       ierr0 = 0  ;  ierr1 = 0  ;  ierr2 = 0  ;  ierr3 = 0  
@@ -77,5 +84,5 @@
       ALLOCATE( n_trc_index(ntrc), slf_i(ntrc), STAT=ierr0 )
       IF( ierr0 > 0 ) THEN
-         CALL ctl_stop( 'trc_nam: unable to allocate n_trc_index' )   ;   RETURN
+         CALL ctl_stop( 'trc_dta_init: unable to allocate n_trc_index' )   ;   RETURN
       ENDIF
       nb_trcdta      = 0
@@ -97,9 +104,9 @@
       REWIND( numnat_ref )              ! Namelist namtrc_dta in reference namelist : Passive tracer input data
       READ  ( numnat_ref, namtrc_dta, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_dta in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_dta_init in reference namelist', lwp )
 
       REWIND( numnat_cfg )              ! Namelist namtrc_dta in configuration namelist : Passive tracer input data
       READ  ( numnat_cfg, namtrc_dta, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_dta in configuration namelist', lwp )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_dta_init in configuration namelist', lwp )
       IF(lwm) WRITE ( numont, namtrc_dta )
 
@@ -109,12 +116,14 @@
                clndta = TRIM( sn_trcdta(jn)%clvar ) 
                clntrc = TRIM( ctrcnm   (jn)       ) 
+               if (jn > jptra) clntrc='Dummy' ! By pass weird formats in ocean.output if ntrc > jptra
                zfact  = rn_trfac(jn)
                IF( clndta /=  clntrc ) THEN 
-                  CALL ctl_warn( 'trc_dta_init: passive tracer data initialisation :  ',   &
-                  &              'the variable name in the data file : '//clndta//   & 
-                  &              '  must be the same than the name of the passive tracer : '//clntrc//' ')
+                  CALL ctl_warn( 'trc_dta_init: passive tracer data initialisation    ',   &
+                  &              'Input name of data file : '//TRIM(clndta)//   &
+                  &              ' differs from that of tracer : '//TRIM(clntrc)//' ')
                ENDIF
-               WRITE(numout,*) ' read an initial file for passive tracer number :', jn, ' name : ', clndta, & 
-               &               ' multiplicative factor : ', zfact
+               WRITE(numout,*) ' '
+               WRITE(numout,'(a, i3,3a,e11.3)') ' Read IC file for tracer number :', &
+               &            jn, ', name : ', TRIM(clndta), ', Multiplicative Scaling factor : ', zfact
             ENDIF
          END DO
@@ -124,5 +133,5 @@
          ALLOCATE( sf_trcdta(nb_trcdta), rf_trfac(nb_trcdta), STAT=ierr1 )
          IF( ierr1 > 0 ) THEN
-            CALL ctl_stop( 'trc_dta_ini: unable to allocate  sf_trcdta structure' )   ;   RETURN
+            CALL ctl_stop( 'trc_dta_init: unable to allocate  sf_trcdta structure' )   ;   RETURN
          ENDIF
          !
@@ -135,5 +144,5 @@
                IF( sn_trcdta(jn)%ln_tint )  ALLOCATE( sf_trcdta(jl)%fdta(jpi,jpj,jpk,2) , STAT=ierr3 )
                IF( ierr2 + ierr3 > 0 ) THEN
-                 CALL ctl_stop( 'trc_dta : unable to allocate passive tracer data arrays' )   ;   RETURN
+                 CALL ctl_stop( 'trc_dta_init : unable to allocate passive tracer data arrays' )   ;   RETURN
                ENDIF
             ENDIF
@@ -141,5 +150,5 @@
          ENDDO
          !                         ! fill sf_trcdta with slf_i and control print
-         CALL fld_fill( sf_trcdta, slf_i, cn_dir, 'trc_dta', 'Passive tracer data', 'namtrc' )
+         CALL fld_fill( sf_trcdta, slf_i, cn_dir, 'trc_dta_init', 'Passive tracer data', 'namtrc' )
          !
       ENDIF
@@ -223,9 +232,4 @@
                            sf_dta(1)%fnow(ji,jj,ik) = (1.-zl) * sf_dta(1)%fnow(ji,jj,ik) + zl * sf_dta(1)%fnow(ji,jj,ik-1)
                         ENDIF
-                        ik = mikt(ji,jj)
-                        IF( ik > 1 ) THEN
-                           zl = ( gdept_0(ji,jj,ik) - gdept_1d(ik) ) / ( gdept_1d(ik+1) - gdept_1d(ik) )
-                           sf_dta(1)%fnow(ji,jj,ik) = (1.-zl) * sf_dta(1)%fnow(ji,jj,ik) + zl * sf_dta(1)%fnow(ji,jj,ik+1)
-                        ENDIF
                      END DO
                   END DO
Index: /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcini.F90
===================================================================
--- /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 6052)
+++ /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 6053)
@@ -26,4 +26,5 @@
    USE sbc_oce
    USE trcice          ! tracers in sea ice
+   USE trcbc,   only : trc_bc_init ! generalized Boundary Conditions
  
    IMPLICIT NONE
@@ -208,5 +209,9 @@
       !!----------------------------------------------------------------------
       !
+      ! Initialisation of tracers Initial Conditions
       IF( ln_trcdta )      CALL trc_dta_init(jptra)
+
+      ! Initialisation of tracers Boundary Conditions
+      IF( lk_my_trc )     CALL trc_bc_init(jptra)
 
       IF( ln_rsttr ) THEN
Index: /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcnam.F90
===================================================================
--- /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 6052)
+++ /branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 6053)
@@ -173,5 +173,5 @@
       !!---------------------------------------------------------------------
       !
-      IF(lwp) WRITE(numout,*) 'trc_nam : read the passive tracer namelists'
+      IF(lwp) WRITE(numout,*) 'trc_nam_run : read the passive tracer namelists'
       IF(lwp) WRITE(numout,*) '~~~~~~~'
 
@@ -271,8 +271,8 @@
       TYPE(PTRACER), DIMENSION(jptra) :: sn_tracer  ! type of tracer for saving if not key_iomput
       !!
-      NAMELIST/namtrc/ sn_tracer, ln_trcdta,ln_trcdmp, ln_trcdmp_clo
+      NAMELIST/namtrc/ sn_tracer, ln_trcdta, ln_trcdmp, ln_trcdmp_clo
       !!---------------------------------------------------------------------
       IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'trc_nam : read the passive tracer namelists'
+      IF(lwp) WRITE(numout,*) 'trc_nam_trc : read the passive tracer namelists'
       IF(lwp) WRITE(numout,*) '~~~~~~~'
 
@@ -291,4 +291,9 @@
          ctrcun    (jn) = TRIM( sn_tracer(jn)%clunit  )
          ln_trc_ini(jn) =       sn_tracer(jn)%llinit
+#if defined key_my_trc
+         ln_trc_sbc(jn) =       sn_tracer(jn)%llsbc
+         ln_trc_cbc(jn) =       sn_tracer(jn)%llcbc
+         ln_trc_obc(jn) =       sn_tracer(jn)%llobc
+#endif
          ln_trc_wri(jn) =       sn_tracer(jn)%llsave
       END DO
@@ -317,8 +322,4 @@
       NAMELIST/namtrc_dia/ ln_diatrc, ln_diabio, nn_writedia, nn_writebio
       !!---------------------------------------------------------------------
-
-      IF(lwp) WRITE(numout,*) 
-      IF(lwp) WRITE(numout,*) 'trc_nam_dia : read the passive tracer diagnostics options'
-      IF(lwp) WRITE(numout,*) '~~~~~~~'
 
       IF(lwp) WRITE(numout,*)
