Index: /NEMO/trunk/cfgs/AGRIF_DEMO/EXPREF/1_namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/AGRIF_DEMO/EXPREF/1_namelist_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/AGRIF_DEMO/EXPREF/1_namelist_cfg	(revision 11536)
@@ -52,6 +52,6 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_tem = 'data_1m_potential_temperature_nomask',     -1      ,'votemper',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
-   sn_sal = 'data_1m_salinity_nomask'             ,     -1      ,'vosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_tem = 'data_1m_potential_temperature_nomask',     -1.     ,'votemper',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_sal = 'data_1m_salinity_nomask'             ,     -1.     ,'vosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
 /
 !!======================================================================
@@ -99,14 +99,14 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ !          weights filename            ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                                      ! pairing  !    filename   !
-   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6         , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Uwnd'   , ''
-   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6         , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Vwnd'   , ''
-   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_tair     = 't_10.15JUNE2009_fill'       ,    6         , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6         , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1         , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1         , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_slp      = 'slp.15JUNE2009_fill'        ,    6         , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_tdif     = 'taudif_core'                ,   24         , 'taudif'  ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6.        , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Uwnd'   , ''
+   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6.        , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Vwnd'   , ''
+   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_tair     = 't_10.15JUNE2009_fill'       ,    6.        , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6.        , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_slp      = 'slp.15JUNE2009_fill'        ,    6.        , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_tdif     = 'taudif_core'                ,   24.        , 'taudif'  ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -122,5 +122,5 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_chl      ='chlorophyll'            ,        -1         , 'CHLA'    ,   .true.    , .true. , 'yearly'  , ''               , ''       , ''
+   sn_chl      ='chlorophyll'            ,        -1.        , 'CHLA'    ,   .true.    , .true. , 'yearly'  , ''               , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -135,9 +135,9 @@
    !           !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
    !           !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_rnf      = 'runoff_core_monthly',    -1    , 'sorunoff',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
-   sn_cnf      = 'runoff_core_monthly',     0    , 'socoefr0',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
-   sn_s_rnf    = 'runoffs'            ,    24    , 'rosaline',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
-   sn_t_rnf    = 'runoffs'            ,    24    , 'rotemper',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
-   sn_dep_rnf  = 'runoffs'            ,     0    , 'rodepth' ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+   sn_rnf      = 'runoff_core_monthly',    -1.   , 'sorunoff',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_cnf      = 'runoff_core_monthly',     0.   , 'socoefr0',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+   sn_s_rnf    = 'runoffs'            ,    24.   , 'rosaline',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_t_rnf    = 'runoffs'            ,    24.   , 'rotemper',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_dep_rnf  = 'runoffs'            ,     0.   , 'rodepth' ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -363,7 +363,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/cfgs/AGRIF_DEMO/EXPREF/2_namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/AGRIF_DEMO/EXPREF/2_namelist_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/AGRIF_DEMO/EXPREF/2_namelist_cfg	(revision 11536)
@@ -50,6 +50,6 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_tem = 'data_1m_potential_temperature_nomask',     -1      ,'votemper',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
-   sn_sal = 'data_1m_salinity_nomask'             ,     -1      ,'vosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_tem = 'data_1m_potential_temperature_nomask',     -1.   ,'votemper',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_sal = 'data_1m_salinity_nomask'             ,     -1.   ,'vosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
 /
 !!======================================================================
@@ -95,14 +95,14 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ !          weights filename            ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                                      ! pairing  !    filename   !
-   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6         , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bicub.nc'     , 'Uwnd'   , ''
-   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6         , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bicub.nc'     , 'Vwnd'   , ''
-   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'     , ''       , ''
-   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'     , ''       , ''
-   sn_tair     = 't_10.15JUNE2009_fill'       ,    6         , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'     , ''       , ''
-   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6         , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'     , ''       , ''
-   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1         , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'     , ''       , ''
-   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1         , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'  , ''       , ''
-   sn_slp      = 'slp.15JUNE2009_fill'        ,    6         , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'  , ''       , ''
-   sn_tdif     = 'taudif_core'                ,   24         , 'taudif'  ,   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'  , ''       , ''
+   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6.        , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bicub.nc'     , 'Uwnd'   , ''
+   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6.        , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bicub.nc'     , 'Vwnd'   , ''
+   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'     , ''       , ''
+   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'     , ''       , ''
+   sn_tair     = 't_10.15JUNE2009_fill'       ,    6.        , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'     , ''       , ''
+   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6.        , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'     , ''       , ''
+   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'     , ''       , ''
+   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'  , ''       , ''
+   sn_slp      = 'slp.15JUNE2009_fill'        ,    6.        , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'  , ''       , ''
+   sn_tdif     = 'taudif_core'                ,   24.        , 'taudif'  ,   .false.   , .true. , 'yearly'  , 'weights_core2_nordic1_bilin.nc'  , ''       , ''
 
 /
@@ -119,5 +119,5 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ !          weights filename            ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                                      ! pairing  !    filename   !
-   sn_chl      ='chlorophyll'            ,        -1         , 'CHLA'    ,   .true.    , .true. , 'yearly'  , ''                                   , ''       , ''
+   sn_chl      ='chlorophyll'            ,        -1.        , 'CHLA'    ,   .true.    , .true. , 'yearly'  , ''                                   , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -312,7 +312,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/cfgs/AGRIF_DEMO/EXPREF/3_namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/AGRIF_DEMO/EXPREF/3_namelist_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/AGRIF_DEMO/EXPREF/3_namelist_cfg	(revision 11536)
@@ -50,6 +50,6 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_tem = 'data_1m_potential_temperature_nomask',     -1      ,'votemper',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
-   sn_sal = 'data_1m_salinity_nomask'             ,     -1      ,'vosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_tem = 'data_1m_potential_temperature_nomask',     -1.     ,'votemper',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_sal = 'data_1m_salinity_nomask'             ,     -1.     ,'vosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
 /
 !!======================================================================
@@ -95,14 +95,14 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ !          weights filename            ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                                      ! pairing  !    filename   !
-   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6         , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bicub.nc'     , 'Uwnd'   , ''
-   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6         , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bicub.nc'     , 'Vwnd'   , ''
-   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
-   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
-   sn_tair     = 't_10.15JUNE2009_fill'       ,    6         , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
-   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6         , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
-   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1         , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
-   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1         , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
-   sn_slp      = 'slp.15JUNE2009_fill'        ,    6         , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
-   sn_tdif     = 'taudif_core'                ,   24         , 'taudif'  ,   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
+   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6.        , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bicub.nc'     , 'Uwnd'   , ''
+   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6.        , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bicub.nc'     , 'Vwnd'   , ''
+   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
+   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
+   sn_tair     = 't_10.15JUNE2009_fill'       ,    6.        , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
+   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6.        , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
+   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
+   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
+   sn_slp      = 'slp.15JUNE2009_fill'        ,    6.        , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
+   sn_tdif     = 'taudif_core'                ,   24.        , 'taudif'  ,   .false.   , .true. , 'yearly'  , 'weights_core2_nordic2_bilin.nc'     , ''       , ''
 
 /
@@ -119,5 +119,5 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ !          weights filename            ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                                      ! pairing  !    filename   !
-   sn_chl      ='chlorophyll'            ,        -1         , 'CHLA'    ,   .true.    , .true. , 'yearly'  , ''                                   , ''       , ''
+   sn_chl      ='chlorophyll'            ,        -1.        , 'CHLA'    ,   .true.    , .true. , 'yearly'  , ''                                   , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -312,7 +312,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/cfgs/AGRIF_DEMO/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/AGRIF_DEMO/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/AGRIF_DEMO/EXPREF/namelist_cfg	(revision 11536)
@@ -52,6 +52,6 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_tem = 'data_1m_potential_temperature_nomask',     -1      ,'votemper',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
-   sn_sal = 'data_1m_salinity_nomask'             ,     -1      ,'vosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_tem = 'data_1m_potential_temperature_nomask',     -1.     ,'votemper',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_sal = 'data_1m_salinity_nomask'             ,     -1.     ,'vosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
 /
 !!======================================================================
@@ -99,14 +99,14 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ !          weights filename            ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                                      ! pairing  !    filename   !
-   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6         , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Uwnd'   , ''
-   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6         , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Vwnd'   , ''
-   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_tair     = 't_10.15JUNE2009_fill'       ,    6         , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6         , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1         , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1         , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_slp      = 'slp.15JUNE2009_fill'        ,    6         , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_tdif     = 'taudif_core'                ,   24         , 'taudif'  ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6.        , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Uwnd'   , ''
+   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6.        , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Vwnd'   , ''
+   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_tair     = 't_10.15JUNE2009_fill'       ,    6.        , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6.        , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_slp      = 'slp.15JUNE2009_fill'        ,    6.        , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_tdif     = 'taudif_core'                ,   24.        , 'taudif'  ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -122,5 +122,5 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_chl      ='chlorophyll'            ,        -1         , 'CHLA'    ,   .true.    , .true. , 'yearly'  , ''               , ''       , ''
+   sn_chl      ='chlorophyll'            ,        -1.        , 'CHLA'    ,   .true.    , .true. , 'yearly'  , ''               , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -135,9 +135,9 @@
    !           !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
    !           !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_rnf      = 'runoff_core_monthly',    -1    , 'sorunoff',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
-   sn_cnf      = 'runoff_core_monthly',     0    , 'socoefr0',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
-   sn_s_rnf    = 'runoffs'            ,    24    , 'rosaline',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
-   sn_t_rnf    = 'runoffs'            ,    24    , 'rotemper',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
-   sn_dep_rnf  = 'runoffs'            ,     0    , 'rodepth' ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+   sn_rnf      = 'runoff_core_monthly',    -1.   , 'sorunoff',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_cnf      = 'runoff_core_monthly',     0.   , 'socoefr0',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+   sn_s_rnf    = 'runoffs'            ,    24.   , 'rosaline',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_t_rnf    = 'runoffs'            ,    24.   , 'rotemper',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_dep_rnf  = 'runoffs'            ,     0.   , 'rodepth' ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -363,7 +363,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/cfgs/AMM12/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/trunk/cfgs/AMM12/EXPREF/context_nemo.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/AMM12/EXPREF/context_nemo.xml	(revision 11536)
@@ -6,4 +6,14 @@
 <context id="nemo">
 <!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
 <!-- Fields definition -->
     <field_definition src="./field_def_nemo-oce.xml"/>   <!--  NEMO ocean dynamics                     -->
@@ -18,13 +28,13 @@
     
     <axis_definition>
-      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
-      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
-      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
-      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
-      <axis id="nfloat" long_name="Float number"      unit="-"                 />
-      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
-      <axis id="ncatice" long_name="Ice category"       unit="1"               />
-      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
-      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
+      <axis id="deptht"  long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="nfloat"  long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"     unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"      unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"  unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"  unit="degC"              />
     </axis_definition>
  
Index: /NEMO/trunk/cfgs/AMM12/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/AMM12/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/AMM12/EXPREF/namelist_cfg	(revision 11536)
@@ -77,9 +77,9 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_utau     = 'amm12_utau'            ,          1        , 'utau'    ,  .false.    , .false., 'daily'   ,  ''              ,  ''      , ''
-   sn_vtau     = 'amm12_vtau'            ,          1        , 'vtau'    ,  .false.    , .false., 'daily'   ,  ''              ,  ''      , ''
-   sn_qtot     = 'amm12_flx'             ,          3        , 'sonsfldo',  .true.     , .false., 'daily'   ,  ''              ,  ''      , ''
-   sn_qsr      = 'amm12_flx'             ,          3        , 'soshfldo',  .true.     , .false., 'daily'   ,  ''              ,  ''      , ''
-   sn_emp      = 'amm12_flx'             ,          3        , 'sowafldo',  .true.     , .false., 'daily'   ,  ''              ,  ''      , ''
+   sn_utau     = 'amm12_utau'            ,          1.       , 'utau'    ,  .false.    , .false., 'daily'   ,  ''              ,  ''      , ''
+   sn_vtau     = 'amm12_vtau'            ,          1.       , 'vtau'    ,  .false.    , .false., 'daily'   ,  ''              ,  ''      , ''
+   sn_qtot     = 'amm12_flx'             ,          3.       , 'sonsfldo',  .true.     , .false., 'daily'   ,  ''              ,  ''      , ''
+   sn_qsr      = 'amm12_flx'             ,          3.       , 'soshfldo',  .true.     , .false., 'daily'   ,  ''              ,  ''      , ''
+   sn_emp      = 'amm12_flx'             ,          3.       , 'sowafldo',  .true.     , .false., 'daily'   ,  ''              ,  ''      , ''
 /
 !-----------------------------------------------------------------------
@@ -101,6 +101,6 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_sst      = 'amm12_sstref'          ,        24         ,  'sst'     ,   .true.   , .false., 'daily'   , ''               , ''       , ''
-   sn_sss      = 'sss_data'              ,        -1         ,  'sss'     ,   .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_sst      = 'amm12_sstref'          ,        24.        ,  'sst'     ,   .true.   , .false., 'daily'   , ''               , ''       , ''
+   sn_sss      = 'sss_data'              ,        -1.        ,  'sss'     ,   .true.   , .true. , 'yearly'  , ''               , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -116,9 +116,9 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_rnf      = 'amm12_rivers'          ,        24         , 'rorunoff',   .false.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_cnf      = 'runoff_1m_nomask'      ,         0         , 'socoefr0',   .false.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_s_rnf    = 'amm12_rivers'          ,        24         , 'rosaline',   .false.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_t_rnf    = 'amm12_rivers'          ,        24         , 'rotemper',   .false.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_dep_rnf  = 'amm12_rivers'          ,        24         , 'rodepth' ,   .false.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_rnf      = 'amm12_rivers'          ,        24.        , 'rorunoff',   .false.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_cnf      = 'runoff_1m_nomask'      ,         0.        , 'socoefr0',   .false.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_s_rnf    = 'amm12_rivers'          ,        24.        , 'rosaline',   .false.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_t_rnf    = 'amm12_rivers'          ,        24.        , 'rotemper',   .false.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_dep_rnf  = 'amm12_rivers'          ,        24.        , 'rodepth' ,   .false.   , .true. , 'yearly'  , ''               , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -133,5 +133,5 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_apr      = 'amm12_mslp'            ,          1        ,'p_msl'    ,   .false.   , .false., 'daily'  ,    ''            ,    ''    ,      ''
+   sn_apr      = 'amm12_mslp'            ,          1.       ,'p_msl'    ,   .false.   , .false., 'daily'  ,    ''            ,    ''    ,      ''
 /
 !!======================================================================
@@ -187,17 +187,20 @@
 &nambdy_dta    !  open boundaries - external data                       
 !-----------------------------------------------------------------------
-   ln_full_vel = .false.
-
+   ln_zinterp  = .false.      !  T if a vertical interpolation is required. Variables gdep[tuv] and e3[tuv] must exist in the file
+   !                          !  automatically defined to T if the number of vertical levels in bdy dta /= jpk
+   ln_full_vel = .false.      !  T if [uv]3d are "full" velocities and not only its baroclinic components
+   !                          !  in this case, baroclinic and barotropic velocities will be recomputed -> [uv]2d not needed
+   !
    cn_dir  =    './bdydta/'
    !___________!_________________________!___________________!___________!_____________!________!___________!__________________!__________!_______________!
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   bn_ssh      = 'amm12_bdyT_dyn2d'      ,         24        , 'sossheig',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
-   bn_u2d      = 'amm12_bdyU_dyn2d'      ,         24        , 'vobtcrtx',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
-   bn_v2d      = 'amm12_bdyV_dyn2d'      ,         24        , 'vobtcrty',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
-   bn_u3d      = 'amm12_bdyU_dyn3d'      ,         24        , 'vozocrtx',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
-   bn_v3d      = 'amm12_bdyV_dyn3d'      ,         24        , 'vomecrty',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
-   bn_tem      = 'amm12_bdyT_tra'        ,         24        , 'votemper',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
-   bn_sal      = 'amm12_bdyT_tra'        ,         24        , 'vosaline',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
+   bn_ssh      = 'amm12_bdyT_dyn2d'      ,         24.       , 'sossheig',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
+   bn_u2d      = 'amm12_bdyU_dyn2d'      ,         24.       , 'vobtcrtx',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
+   bn_v2d      = 'amm12_bdyV_dyn2d'      ,         24.       , 'vobtcrty',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
+   bn_u3d      = 'amm12_bdyU_dyn3d'      ,         24.       , 'vozocrtx',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
+   bn_v3d      = 'amm12_bdyV_dyn3d'      ,         24.       , 'vomecrty',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
+   bn_tem      = 'amm12_bdyT_tra'        ,         24.       , 'votemper',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
+   bn_sal      = 'amm12_bdyT_tra'        ,         24.       , 'vosaline',    .true.   , .false.,  'daily'  ,    ''            ,   ''     , ''
 /
 !-----------------------------------------------------------------------
@@ -347,7 +350,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/cfgs/C1D_PAPA/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/C1D_PAPA/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/C1D_PAPA/EXPREF/namelist_cfg	(revision 11536)
@@ -65,6 +65,6 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_tem      = 'init_PAPASTATION'       ,         24        ,'votemper',  .false.     , .true.,  'daily'  ,    ''            ,    ''    ,    ''
-   sn_sal      = 'init_PAPASTATION'       ,         24        ,'vosaline',  .false.     , .true.,  'daily'  ,    ''            ,    ''    ,    ''
+   sn_tem      = 'init_PAPASTATION'       ,         24.       ,'votemper',  .false.     , .true.,  'daily'  ,    ''            ,    ''    ,    ''
+   sn_sal      = 'init_PAPASTATION'       ,         24.       ,'vosaline',  .false.     , .true.,  'daily'  ,    ''            ,    ''    ,    ''
 /
 !-----------------------------------------------------------------------
@@ -99,6 +99,6 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_ucur     = 'ucurrent'              ,         -1        ,'u_current',   .false.   , .true. , 'monthly' ,  ''              ,  'Ume'   , ''
-   sn_vcur     = 'vcurrent'              ,         -1        ,'v_current',   .false.   , .true. , 'monthly' ,  ''              ,  'Vme'   , ''
+   sn_ucur     = 'ucurrent'              ,         -1.       ,'u_current',   .false.   , .true. , 'monthly' ,  ''              ,  'Ume'   , ''
+   sn_vcur     = 'vcurrent'              ,         -1.       ,'v_current',   .false.   , .true. , 'monthly' ,  ''              ,  'Vme'   , ''
 /
 
@@ -150,14 +150,14 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ !       weights filename               ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                                      ! pairing  !    filename   !
-   sn_wndi     = 'forcing_C1D_PAPA'   ,  3    , 'sowinu10',   .true.     , .false. , 'yearly'  , ''   ,''   , ''
-   sn_wndj     = 'forcing_C1D_PAPA'   ,  3    , 'sowinv10',   .true.     , .false. , 'yearly'  , ''   ,''   , ''
-   sn_qsr      = 'forcing_C1D_PAPA'   ,  3    , 'sosudosw',   .false.    , .false. , 'yearly'  , ''  , ''   , ''
-   sn_qlw      = 'forcing_C1D_PAPA'   ,  3    , 'sosudolw',   .false.    , .false. , 'yearly'  , ''  , ''   , ''
-   sn_tair     = 'forcing_C1D_PAPA'   ,  3    , 'sotemair',   .true.     , .false. , 'yearly'  , ''  , ''   , ''
-   sn_humi     = 'forcing_C1D_PAPA'   ,  3    , 'sohumspe',   .true.     , .false. , 'yearly'  , ''  , ''   , ''
-   sn_prec     = 'forcing_C1D_PAPA'   ,  3    , 'sowaprec',   .false.    , .false. , 'yearly'  , ''  , ''   , ''
-   sn_snow     = 'forcing_C1D_PAPA'   ,  3    , 'sososnow',   .false.    , .false. , 'yearly'  , ''  , ''   , ''
-   sn_slp      = 'forcing_C1D_PAPA'   ,  3    , 'somslpre',   .true.     , .false. , 'yearly'  , ''  , ''   , ''
-   sn_tdif     = 'forcing_C1D_PAPA'   , 24    , 'taudif'  ,   .false.    , .false. , 'yearly'  , ''  , ''   , ''
+   sn_wndi     = 'forcing_C1D_PAPA'   ,  3.   , 'sowinu10',   .true.     , .false. , 'yearly'  , ''   ,''   , ''
+   sn_wndj     = 'forcing_C1D_PAPA'   ,  3.   , 'sowinv10',   .true.     , .false. , 'yearly'  , ''   ,''   , ''
+   sn_qsr      = 'forcing_C1D_PAPA'   ,  3.   , 'sosudosw',   .false.    , .false. , 'yearly'  , ''  , ''   , ''
+   sn_qlw      = 'forcing_C1D_PAPA'   ,  3.   , 'sosudolw',   .false.    , .false. , 'yearly'  , ''  , ''   , ''
+   sn_tair     = 'forcing_C1D_PAPA'   ,  3.   , 'sotemair',   .true.     , .false. , 'yearly'  , ''  , ''   , ''
+   sn_humi     = 'forcing_C1D_PAPA'   ,  3.   , 'sohumspe',   .true.     , .false. , 'yearly'  , ''  , ''   , ''
+   sn_prec     = 'forcing_C1D_PAPA'   ,  3.   , 'sowaprec',   .false.    , .false. , 'yearly'  , ''  , ''   , ''
+   sn_snow     = 'forcing_C1D_PAPA'   ,  3.   , 'sososnow',   .false.    , .false. , 'yearly'  , ''  , ''   , ''
+   sn_slp      = 'forcing_C1D_PAPA'   ,  3.   , 'somslpre',   .true.     , .false. , 'yearly'  , ''  , ''   , ''
+   sn_tdif     = 'forcing_C1D_PAPA'   , 24.   , 'taudif'  ,   .false.    , .false. , 'yearly'  , ''  , ''   , ''
 
 /
@@ -185,5 +185,5 @@
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
 
-   sn_chl      ='chlorophyll_PAPASTATION',         -1        , 'CHLA'    ,   .true.     , .true. , 'yearly'  ,        ''       ,    ''    , ''
+   sn_chl      ='chlorophyll_PAPASTATION',         -1.       , 'CHLA'    ,   .true.     , .true. , 'yearly'  ,        ''       ,    ''    , ''
 /
 !-----------------------------------------------------------------------
@@ -420,7 +420,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
@@ -445,13 +445,13 @@
 /
 !-----------------------------------------------------------------------
-&namflo        !   float parameters                                     ("key_float")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nam_diaharm   !   Harmonic analysis of tidal constituents              ("key_diaharm")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namdct        ! transports through some sections                       ("key_diadct")
+&namflo        !   float parameters                                     (default: OFF)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nam_diaharm   !   Harmonic analysis of tidal constituents              (default: OFF)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nam_diadct    ! transports through some sections                       (default: OFF)
 !-----------------------------------------------------------------------
 /
Index: /NEMO/trunk/cfgs/C1D_PAPA/MY_SRC/usrdef_nam.F90
===================================================================
--- /NEMO/trunk/cfgs/C1D_PAPA/MY_SRC/usrdef_nam.F90	(revision 11535)
+++ /NEMO/trunk/cfgs/C1D_PAPA/MY_SRC/usrdef_nam.F90	(revision 11536)
@@ -39,5 +39,5 @@
 CONTAINS
 
-   SUBROUTINE usr_def_nam( ldtxt, ldnam, cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+   SUBROUTINE usr_def_nam( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -51,5 +51,4 @@
       !! ** input   : - namusr_def namelist found in namelist_cfg
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), DIMENSION(:), INTENT(out) ::   ldtxt, ldnam    ! stored print information
       CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
       INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
@@ -57,16 +56,14 @@
       INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
       !
-      INTEGER ::   ios, ii   ! Local integer
+      INTEGER ::   ios   ! Local integer
       !!
       NAMELIST/namusr_def/ rn_bathy
       !!----------------------------------------------------------------------
       !
-      ii = 1
-      !
       REWIND( numnam_cfg )          ! Namelist namusr_def (exist in namelist_cfg only)
       READ  ( numnam_cfg, namusr_def, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist', .TRUE. )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist' )
       !
-      WRITE( ldnam(:), namusr_def )
+      IF(lwm)   WRITE( numond, namusr_def )
       !
       cd_cfg = 'C1D'               ! name & resolution (not used)
@@ -77,25 +74,24 @@
       kpj = 3
       kpk = 75 
-      !
-      !                             ! control print
-      WRITE(ldtxt(ii),*) '   '                                                                            ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'     ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~~~~~~ '                                                                   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Namelist namusr_def : C1 case'                                               ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      type of vertical coordinate : '                                           ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         z-coordinate flag                     ln_zco = ', ln_zco               ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         z-partial-step coordinate flag        ln_zps = ', ln_zps               ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         s-coordinate flag                     ln_sco = ', ln_sco               ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      C1D domain = 3 x 3 x75 grid-points                '                       ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         resulting global domain size :        jpiglo = ', kpi                  ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpjglo = ', kpj                  ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpkglo = ', kpk                  ;   ii = ii + 1
-
-      !
       !                             ! Set the lateral boundary condition of the global domain
       kperio =  7                   ! C1D configuration : 3x3 basin with cyclic Est-West and Norht-South condition
       !
-      WRITE(ldtxt(ii),*) '   Lateral boundary condition of the global domain'                           ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      C1D : closed basin                 jperio = ', kperio                   ;   ii = ii + 1
+      !                             ! control print
+      IF(lwp) THEN
+         WRITE(numout,*) '   '
+         WRITE(numout,*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '   Namelist namusr_def : C1 case'
+         WRITE(numout,*) '      type of vertical coordinate : '
+         WRITE(numout,*) '         z-coordinate flag                     ln_zco = ', ln_zco
+         WRITE(numout,*) '         z-partial-step coordinate flag        ln_zps = ', ln_zps
+         WRITE(numout,*) '         s-coordinate flag                     ln_sco = ', ln_sco
+         WRITE(numout,*) '      C1D domain = 3 x 3 x75 grid-points                '
+         WRITE(numout,*) '         resulting global domain size :        jpiglo = ', kpi
+         WRITE(numout,*) '                                               jpjglo = ', kpj
+         WRITE(numout,*) '                                               jpkglo = ', kpk
+         WRITE(numout,*) '   Lateral boundary condition of the global domain'
+         WRITE(numout,*) '      C1D : closed basin                       jperio = ', kperio
+      ENDIF
       !
    END SUBROUTINE usr_def_nam
Index: /NEMO/trunk/cfgs/GYRE_BFM/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/trunk/cfgs/GYRE_BFM/EXPREF/context_nemo.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/GYRE_BFM/EXPREF/context_nemo.xml	(revision 11536)
@@ -6,4 +6,14 @@
 <context id="nemo">
 <!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
 <!-- Fields definition -->
     <field_definition src="./field_def_nemo-oce.xml"/>   <!--  NEMO ocean dynamics                     -->
@@ -19,13 +29,13 @@
     
     <axis_definition>
-      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
-      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
-      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
-      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
-      <axis id="nfloat" long_name="Float number"      unit="-"                 />
-      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
-      <axis id="ncatice" long_name="Ice category"       unit="1"               />
-      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
-      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
+      <axis id="deptht"  long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="nfloat"  long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"     unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"      unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"  unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"  unit="degC"              />
     </axis_definition>
  
Index: /NEMO/trunk/cfgs/GYRE_BFM/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/GYRE_BFM/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/GYRE_BFM/EXPREF/namelist_cfg	(revision 11536)
@@ -227,7 +227,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/cfgs/GYRE_PISCES/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/trunk/cfgs/GYRE_PISCES/EXPREF/context_nemo.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/GYRE_PISCES/EXPREF/context_nemo.xml	(revision 11536)
@@ -6,4 +6,14 @@
 <context id="nemo">
 <!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
 <!-- Fields definition -->
     <field_definition src="./field_def_nemo-oce.xml"/>   <!--  NEMO ocean dynamics                     -->
@@ -19,13 +29,13 @@
     
     <axis_definition>
-      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
-      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
-      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
-      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
-      <axis id="nfloat" long_name="Float number"      unit="-"                 />
-      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
-      <axis id="ncatice" long_name="Ice category"       unit="1"               />
-      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
-      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
+      <axis id="deptht"  long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="nfloat"  long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"     unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"      unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"  unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"  unit="degC"              />
     </axis_definition>
  
Index: /NEMO/trunk/cfgs/GYRE_PISCES/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/GYRE_PISCES/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/GYRE_PISCES/EXPREF/namelist_cfg	(revision 11536)
@@ -221,7 +221,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/context_nemo.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/context_nemo.xml	(revision 11536)
@@ -6,4 +6,14 @@
 <context id="nemo">
 <!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
 <!-- Fields definition -->
     <field_definition src="./field_def_nemo-oce.xml"/>    <!--  NEMO ocean dynamics     --> 
@@ -22,14 +32,14 @@
     
     <axis_definition>
-      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
-      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
-      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
-      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
-      <axis id="profsed" long_name="Vertical S levels" unit="cm" positive="down" />
-      <axis id="nfloat" long_name="Float number"      unit="-"                 />
-      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
-      <axis id="ncatice" long_name="Ice category"       unit="1"               />
-      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
-      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
+      <axis id="deptht"  long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="profsed" long_name="Vertical S levels" unit="cm" positive="down"/>
+      <axis id="nfloat"  long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"     unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"      unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"  unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"  unit="degC"              />
     </axis_definition>
  
Index: /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/file_def_nemo-ice.xml
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/file_def_nemo-ice.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/file_def_nemo-ice.xml	(revision 11536)
@@ -78,5 +78,5 @@
        <field field_ref="vfxice"           name="vfxice" />
        <field field_ref="vfxsnw"           name="vfxsnw" />
-       
+
        <!-- categories -->
        <field field_ref="icemask_cat"      name="simskcat"/>
@@ -93,25 +93,25 @@
      <file id="file22" name_suffix="_SBC_scalar" description="scalar variables" enabled=".true." >
        <!-- global contents -->
-       <field field_ref="ibgvol_tot"     grid_ref="grid_1point"   name="ibgvol_tot"   />
-       <field field_ref="sbgvol_tot"     grid_ref="grid_1point"   name="sbgvol_tot"   />
-       <field field_ref="ibgarea_tot"    grid_ref="grid_1point"   name="ibgarea_tot"  />
-       <field field_ref="ibgsalt_tot"    grid_ref="grid_1point"   name="ibgsalt_tot"  />
-       <field field_ref="ibgheat_tot"    grid_ref="grid_1point"   name="ibgheat_tot"  />
-       <field field_ref="sbgheat_tot"    grid_ref="grid_1point"   name="sbgheat_tot"  />
+       <field field_ref="ibgvol_tot"     name="ibgvol_tot"   />
+       <field field_ref="sbgvol_tot"     name="sbgvol_tot"   />
+       <field field_ref="ibgarea_tot"    name="ibgarea_tot"  />
+       <field field_ref="ibgsalt_tot"    name="ibgsalt_tot"  />
+       <field field_ref="ibgheat_tot"    name="ibgheat_tot"  />
+       <field field_ref="sbgheat_tot"    name="sbgheat_tot"  />
        
        <!-- global drifts (conservation checks) -->
-       <field field_ref="ibgvolume"      grid_ref="grid_1point"   name="ibgvolume"    />
-       <field field_ref="ibgsaltco"      grid_ref="grid_1point"   name="ibgsaltco"    />
-       <field field_ref="ibgheatco"      grid_ref="grid_1point"   name="ibgheatco"    />
-       <field field_ref="ibgheatfx"      grid_ref="grid_1point"   name="ibgheatfx"    />
+       <field field_ref="ibgvolume"      name="ibgvolume"    />
+       <field field_ref="ibgsaltco"      name="ibgsaltco"    />
+       <field field_ref="ibgheatco"      name="ibgheatco"    />
+       <field field_ref="ibgheatfx"      name="ibgheatfx"    />
        
        <!-- global forcings  -->
-       <field field_ref="ibgfrcvoltop"   grid_ref="grid_1point"   name="ibgfrcvoltop" />
-       <field field_ref="ibgfrcvolbot"   grid_ref="grid_1point"   name="ibgfrcvolbot" />
-       <field field_ref="ibgfrctemtop"   grid_ref="grid_1point"   name="ibgfrctemtop" />
-       <field field_ref="ibgfrctembot"   grid_ref="grid_1point"   name="ibgfrctembot" />
-       <field field_ref="ibgfrcsal"      grid_ref="grid_1point"   name="ibgfrcsal"    />
-       <field field_ref="ibgfrchfxtop"   grid_ref="grid_1point"   name="ibgfrchfxtop" />
-       <field field_ref="ibgfrchfxbot"   grid_ref="grid_1point"   name="ibgfrchfxbot" />
+       <field field_ref="ibgfrcvoltop"   name="ibgfrcvoltop" />
+       <field field_ref="ibgfrcvolbot"   name="ibgfrcvolbot" />
+       <field field_ref="ibgfrctemtop"   name="ibgfrctemtop" />
+       <field field_ref="ibgfrctembot"   name="ibgfrctembot" />
+       <field field_ref="ibgfrcsal"      name="ibgfrcsal"    />
+       <field field_ref="ibgfrchfxtop"   name="ibgfrchfxtop" />
+       <field field_ref="ibgfrchfxbot"   name="ibgfrchfxbot" />
      </file>
      
Index: /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/file_def_nemo-oce.xml
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/file_def_nemo-oce.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/file_def_nemo-oce.xml	(revision 11536)
@@ -37,5 +37,4 @@
 	  <field field_ref="wspd"         name="windsp"   />
 	  <field field_ref="precip"       name="precip"   />
-	  <field field_ref="berg_melt_qlat"  name="berg_melt_qlat" />
 	  <!-- ice and snow -->
 	  <field field_ref="snowpre" />
@@ -82,17 +81,17 @@
         <file id="file15" name_suffix="_scalar" description="scalar variables" >
           <!-- global drifts (conservation checks) -->
-          <field field_ref="bgtemper"     grid_ref="grid_1point"   name="bgtemper"    />
-          <field field_ref="bgsaline"     grid_ref="grid_1point"   name="bgsaline"    />
-          <field field_ref="bgheatco"     grid_ref="grid_1point"   name="bgheatco"    />
-          <field field_ref="bgheatfx"     grid_ref="grid_1point"   name="bgheatfx"    />
-          <field field_ref="bgsaltco"     grid_ref="grid_1point"   name="bgsaltco"    />
-          <field field_ref="bgvolssh"     grid_ref="grid_1point"   name="bgvolssh"    />
-          <field field_ref="bgvole3t"     grid_ref="grid_1point"   name="bgvole3t"    />
+          <field field_ref="bgtemper"     name="bgtemper"    />
+          <field field_ref="bgsaline"     name="bgsaline"    />
+          <field field_ref="bgheatco"     name="bgheatco"    />
+          <field field_ref="bgheatfx"     name="bgheatfx"    />
+          <field field_ref="bgsaltco"     name="bgsaltco"    />
+          <field field_ref="bgvolssh"     name="bgvolssh"    />
+          <field field_ref="bgvole3t"     name="bgvole3t"    />
 
           <!-- global surface forcings  -->
-          <field field_ref="bgfrcvol"     grid_ref="grid_1point"   name="bgfrcvol"    />
-          <field field_ref="bgfrctem"     grid_ref="grid_1point"   name="bgfrctem"    />
-          <field field_ref="bgfrchfx"     grid_ref="grid_1point"   name="bgfrchfx"    />
-          <field field_ref="bgfrcsal"     grid_ref="grid_1point"   name="bgfrcsal"    />
+          <field field_ref="bgfrcvol"     name="bgfrcvol"    />
+          <field field_ref="bgfrctem"     name="bgfrctem"    />
+          <field field_ref="bgfrchfx"     name="bgfrchfx"    />
+          <field field_ref="bgfrcsal"     name="bgfrcsal"    />
         </file>
 
Index: /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/file_def_nemo-pisces.xml
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/file_def_nemo-pisces.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/file_def_nemo-pisces.xml	(revision 11536)
@@ -14,15 +14,15 @@
 
         <file id="file31" name_suffix="_bioscalar" description="pisces sms variables" >
-          <field field_ref="tdenit"   name="tdenit"   grid_ref="grid_1point" unit="TgN/yr" operation="instant" > tdenit * 14. * 86400. * 365. / 1e12 </field>
-          <field field_ref="tnfix"    name="tnfix"    grid_ref="grid_1point" unit="TgN/yr" operation="instant" > tnfix * 14. * 86400. * 365. / 1e12 </field>
-          <field field_ref="tcflx"    name="tcflx"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" > tcflx * -1. * 12. * 86400. * 365. / 1e15 </field>
-          <field field_ref="tcflxcum" name="tcflxcum" grid_ref="grid_1point" unit="PgC"    operation="instant" > tcflxcum * -1. * 12. / 1e15 </field>
-          <field field_ref="tcexp"    name="tcexp"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" > tcexp * 12. * 86400. * 365. / 1e15 </field>
-          <field field_ref="tintpp"   name="tintpp"   grid_ref="grid_1point" unit="PgC/yr" operation="instant" > tintpp * 12. * 86400. * 365. / 1e15 </field>
-          <field field_ref="pno3tot"  name="pno3tot"  grid_ref="grid_1point" unit="umolN"  > pno3tot * 16. / 122. * 1e6 </field>
-          <field field_ref="ppo4tot"  name="ppo4tot"  grid_ref="grid_1point" unit="umolP"  > ppo4tot * 1. / 122. * 1e6 </field>
-          <field field_ref="psiltot"  name="psiltot"  grid_ref="grid_1point" unit="umolC"  > psiltot * 1e6  </field>
-          <field field_ref="palktot"  name="palktot"  grid_ref="grid_1point" unit="umolC"  > palktot * 1e6  </field>
-          <field field_ref="pfertot"  name="pfertot"  grid_ref="grid_1point" unit="nmolFe" > pfertot * 1e9  </field>
+          <field field_ref="tdenit"   name="tdenit"    unit="TgN/yr" operation="instant" > tdenit * 14. * 86400. * 365. / 1e12 </field>
+          <field field_ref="tnfix"    name="tnfix"     unit="TgN/yr" operation="instant" > tnfix * 14. * 86400. * 365. / 1e12 </field>
+          <field field_ref="tcflx"    name="tcflx"     unit="PgC/yr" operation="instant" > tcflx * -1. * 12. * 86400. * 365. / 1e15 </field>
+          <field field_ref="tcflxcum" name="tcflxcum"  unit="PgC"    operation="instant" > tcflxcum * -1. * 12. / 1e15 </field>
+          <field field_ref="tcexp"    name="tcexp"     unit="PgC/yr" operation="instant" > tcexp * 12. * 86400. * 365. / 1e15 </field>
+          <field field_ref="tintpp"   name="tintpp"    unit="PgC/yr" operation="instant" > tintpp * 12. * 86400. * 365. / 1e15 </field>
+          <field field_ref="pno3tot"  name="pno3tot"   unit="umolN"  > pno3tot * 16. / 122. * 1e6 </field>
+          <field field_ref="ppo4tot"  name="ppo4tot"   unit="umolP"  > ppo4tot * 1. / 122. * 1e6 </field>
+          <field field_ref="psiltot"  name="psiltot"   unit="umolC"  > psiltot * 1e6  </field>
+          <field field_ref="palktot"  name="palktot"   unit="umolC"  > palktot * 1e6  </field>
+          <field field_ref="pfertot"  name="pfertot"   unit="nmolFe" > pfertot * 1e9  </field>
         </file>
 
Index: /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg	(revision 11536)
@@ -50,6 +50,6 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_tem = 'data_1m_potential_temperature_nomask',     -1      ,'votemper',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
-   sn_sal = 'data_1m_salinity_nomask'             ,     -1      ,'vosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_tem = 'data_1m_potential_temperature_nomask',     -1.     ,'votemper',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_sal = 'data_1m_salinity_nomask'             ,     -1.     ,'vosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
 /
 !!======================================================================
@@ -109,14 +109,14 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ !          weights filename            ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                                      ! pairing  !    filename   !
-   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6         , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Uwnd'   , ''
-   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6         , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Vwnd'   , ''
-   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_tair     = 't_10.15JUNE2009_fill'       ,    6         , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6         , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1         , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1         , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_slp      = 'slp.15JUNE2009_fill'        ,    6         , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_tdif     = 'taudif_core'                ,   24         , 'taudif'  ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6.        , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Uwnd'   , ''
+   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6.        , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Vwnd'   , ''
+   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_tair     = 't_10.15JUNE2009_fill'       ,    6.        , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6.        , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_slp      = 'slp.15JUNE2009_fill'        ,    6.        , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_tdif     = 'taudif_core'                ,   24.        , 'taudif'  ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -132,5 +132,5 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_chl      ='chlorophyll'            ,        -1         , 'CHLA'    ,   .true.    , .true. , 'yearly'  , ''               , ''       , ''
+   sn_chl      ='chlorophyll'            ,        -1.        , 'CHLA'    ,   .true.    , .true. , 'yearly'  , ''               , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -154,9 +154,9 @@
    !           !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
    !           !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_rnf      = 'runoff_core_monthly',    -1    , 'sorunoff',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
-   sn_cnf      = 'runoff_core_monthly',     0    , 'socoefr0',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
-   sn_s_rnf    = 'runoffs'            ,    24    , 'rosaline',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
-   sn_t_rnf    = 'runoffs'            ,    24    , 'rotemper',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
-   sn_dep_rnf  = 'runoffs'            ,     0    , 'rodepth' ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+   sn_rnf      = 'runoff_core_monthly',    -1.   , 'sorunoff',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_cnf      = 'runoff_core_monthly',     0.   , 'socoefr0',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+   sn_s_rnf    = 'runoffs'            ,    24.   , 'rosaline',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_t_rnf    = 'runoffs'            ,    24.   , 'rotemper',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_dep_rnf  = 'runoffs'            ,     0.   , 'rodepth' ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -173,5 +173,5 @@
    !      ! file name ! frequency (hours) !   variable   ! time interp. !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
    !      !           !  (if <0  months)  !     name     !   (logical)  !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_icb =  'calving',       -1          , 'calving'    ,   .true.     , .true.  , 'yearly'  , ''       , ''       , ''
+   sn_icb =  'calving',       -1.         , 'calving'    ,   .true.     , .true.  , 'yearly'  , ''       , ''       , ''
 /
 !!======================================================================
@@ -391,7 +391,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_top_cfg
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_top_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_top_cfg	(revision 11536)
@@ -57,12 +57,12 @@
 !          !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
 !          !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_trcdta(1)  = 'data_DIC_nomask'        ,        -12        ,  'DIC'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(2)  = 'data_Alkalini_nomask'   ,        -12        ,  'Alkalini',    .false.   , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(3)  = 'data_O2_nomask'         ,        -1         ,  'O2'      ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(5)  = 'data_PO4_nomask'        ,        -1         ,  'PO4'     ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(7)  = 'data_Si_nomask'         ,        -1         ,  'Si'      ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(10) = 'data_DOC_nomask'        ,        -12        ,  'DOC'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(14) = 'data_Fer_nomask'        ,        -12        ,  'Fer'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(23) = 'data_NO3_nomask'        ,        -1         ,  'NO3'     ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(1)  = 'data_DIC_nomask'        ,        -12.       ,  'DIC'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(2)  = 'data_Alkalini_nomask'   ,        -12.       ,  'Alkalini',    .false.   , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(3)  = 'data_O2_nomask'         ,        -1.        ,  'O2'      ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(5)  = 'data_PO4_nomask'        ,        -1.        ,  'PO4'     ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(7)  = 'data_Si_nomask'         ,        -1.        ,  'Si'      ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(10) = 'data_DOC_nomask'        ,        -12.       ,  'DOC'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(14) = 'data_Fer_nomask'        ,        -12.       ,  'Fer'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(23) = 'data_NO3_nomask'        ,        -1.        ,  'NO3'     ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
    rn_trfac(1)   =   1.0e-06  !  multiplicative factor
    rn_trfac(2)   =   1.0e-06  !  -      -      -     -
Index: /NEMO/trunk/cfgs/ORCA2_OFF_PISCES/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_OFF_PISCES/EXPREF/context_nemo.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/ORCA2_OFF_PISCES/EXPREF/context_nemo.xml	(revision 11536)
@@ -6,4 +6,14 @@
 <context id="nemo">
 <!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
 <!-- Fields definition -->
     <field_definition src="./field_def_nemo-oce.xml"/>   <!--  Ocean biology                     -->
@@ -19,14 +29,14 @@
     
     <axis_definition>
-      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
-      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
-      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
-      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
-      <axis id="profsed" long_name="Vertical S levels" unit="cm" positive="down" />
-      <axis id="nfloat" long_name="Float number"      unit="-"                 />
-      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
-      <axis id="ncatice" long_name="Ice category"       unit="1"               />
-      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
-      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
+      <axis id="deptht"  long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="profsed" long_name="Vertical S levels" unit="cm" positive="down"/>
+      <axis id="nfloat"  long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"     unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"      unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"  unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"  unit="degC"              />
     </axis_definition>
  
Index: /NEMO/trunk/cfgs/ORCA2_OFF_PISCES/EXPREF/file_def_nemo.xml
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_OFF_PISCES/EXPREF/file_def_nemo.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/ORCA2_OFF_PISCES/EXPREF/file_def_nemo.xml	(revision 11536)
@@ -19,15 +19,15 @@
       <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."> <!-- 1d files -->
         <file id="file1" name_suffix="_bioscalar" description="pisces sms variables" >
-           <field field_ref="tdenit"   name="tdenit"   grid_ref="grid_1point" unit="TgN/yr" operation="instant" > tdenit * 14. * 86400. * 365. / 1e12 </field>
-           <field field_ref="tnfix"    name="tnfix"    grid_ref="grid_1point" unit="TgN/yr" operation="instant" > tnfix * 14. * 86400. * 365. / 1e12 </field>
-           <field field_ref="tcflx"    name="tcflx"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" > tcflx * -1. * 12. * 86400. * 365. / 1e15 </field>
-           <field field_ref="tcflxcum" name="tcflxcum" grid_ref="grid_1point" unit="PgC"    operation="instant" > tcflxcum * -1. * 12. / 1e15 </field>
-           <field field_ref="tcexp"    name="tcexp"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" > tcexp * 12. * 86400. * 365. / 1e15 </field>
-           <field field_ref="tintpp"   name="tintpp"   grid_ref="grid_1point" unit="PgC/yr" operation="instant" > tintpp * 12. * 86400. * 365. / 1e15 </field>
-           <field field_ref="pno3tot"  name="pno3tot"  grid_ref="grid_1point" unit="umolN"  > pno3tot * 16. / 122. * 1e6 </field>
-           <field field_ref="ppo4tot"  name="ppo4tot"  grid_ref="grid_1point" unit="umolP"  > ppo4tot * 1. / 122. * 1e6 </field>
-           <field field_ref="psiltot"  name="psiltot"  grid_ref="grid_1point" unit="umolC"  > psiltot * 1e6  </field>
-           <field field_ref="palktot"  name="palktot"  grid_ref="grid_1point" unit="umolC"  > palktot * 1e6  </field>
-           <field field_ref="pfertot"  name="pfertot"  grid_ref="grid_1point" unit="nmolFe" > pfertot * 1e9  </field>
+           <field field_ref="tdenit"   name="tdenit"    unit="TgN/yr" operation="instant" > tdenit * 14. * 86400. * 365. / 1e12 </field>
+           <field field_ref="tnfix"    name="tnfix"     unit="TgN/yr" operation="instant" > tnfix * 14. * 86400. * 365. / 1e12 </field>
+           <field field_ref="tcflx"    name="tcflx"     unit="PgC/yr" operation="instant" > tcflx * -1. * 12. * 86400. * 365. / 1e15 </field>
+           <field field_ref="tcflxcum" name="tcflxcum"  unit="PgC"    operation="instant" > tcflxcum * -1. * 12. / 1e15 </field>
+           <field field_ref="tcexp"    name="tcexp"     unit="PgC/yr" operation="instant" > tcexp * 12. * 86400. * 365. / 1e15 </field>
+           <field field_ref="tintpp"   name="tintpp"    unit="PgC/yr" operation="instant" > tintpp * 12. * 86400. * 365. / 1e15 </field>
+           <field field_ref="pno3tot"  name="pno3tot"   unit="umolN"  > pno3tot * 16. / 122. * 1e6 </field>
+           <field field_ref="ppo4tot"  name="ppo4tot"   unit="umolP"  > ppo4tot * 1. / 122. * 1e6 </field>
+           <field field_ref="psiltot"  name="psiltot"   unit="umolC"  > psiltot * 1e6  </field>
+           <field field_ref="palktot"  name="palktot"   unit="umolC"  > palktot * 1e6  </field>
+           <field field_ref="pfertot"  name="pfertot"   unit="nmolFe" > pfertot * 1e9  </field>
         </file>
       </file_group>
Index: /NEMO/trunk/cfgs/ORCA2_OFF_PISCES/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_OFF_PISCES/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/ORCA2_OFF_PISCES/EXPREF/namelist_cfg	(revision 11536)
@@ -318,18 +318,18 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_tem      = 'dyna_grid_T'           ,       120         , 'votemper'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_sal      = 'dyna_grid_T'           ,       120         , 'vosaline'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_mld      = 'dyna_grid_T'           ,       120         , 'somixhgt'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_emp      = 'dyna_grid_T'           ,       120         , 'sowaflup'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_fmf      = 'dyna_grid_T'           ,       120         , 'iowaflup'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_ice      = 'dyna_grid_T'           ,       120         , 'soicecov'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_qsr      = 'dyna_grid_T'           ,       120         , 'soshfldo'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_wnd      = 'dyna_grid_T'           ,       120         , 'sowindsp'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_uwd      = 'dyna_grid_U'           ,       120         , 'uocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_vwd      = 'dyna_grid_V'           ,       120         , 'vocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_wwd      = 'dyna_grid_W'           ,       120         , 'wocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_avt      = 'dyna_grid_W'           ,       120         , 'voddmavs'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_ubl      = 'dyna_grid_U'           ,       120         , 'sobblcox'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_vbl      = 'dyna_grid_V'           ,       120         , 'sobblcoy'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_tem      = 'dyna_grid_T'           ,       120.        , 'votemper'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_sal      = 'dyna_grid_T'           ,       120.        , 'vosaline'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_mld      = 'dyna_grid_T'           ,       120.        , 'somixhgt'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_emp      = 'dyna_grid_T'           ,       120.        , 'sowaflup'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_fmf      = 'dyna_grid_T'           ,       120.        , 'iowaflup'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_ice      = 'dyna_grid_T'           ,       120.        , 'soicecov'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_qsr      = 'dyna_grid_T'           ,       120.        , 'soshfldo'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_wnd      = 'dyna_grid_T'           ,       120.        , 'sowindsp'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_uwd      = 'dyna_grid_U'           ,       120.        , 'uocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_vwd      = 'dyna_grid_V'           ,       120.        , 'vocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_wwd      = 'dyna_grid_W'           ,       120.        , 'wocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_avt      = 'dyna_grid_W'           ,       120.        , 'voddmavs'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_ubl      = 'dyna_grid_U'           ,       120.        , 'sobblcox'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_vbl      = 'dyna_grid_V'           ,       120.        , 'sobblcoy'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
 /
 !!======================================================================
@@ -376,7 +376,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
@@ -401,13 +401,13 @@
 /
 !-----------------------------------------------------------------------
-&namflo        !   float parameters                                     ("key_float")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nam_diaharm   !   Harmonic analysis of tidal constituents              ("key_diaharm")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namdct        ! transports through some sections                       ("key_diadct")
+&namflo        !   float parameters                                     (default: OFF)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nam_diaharm   !   Harmonic analysis of tidal constituents              (default: OFF)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nam_diadct    !   transports through some sections                     (default: OFF)
 !-----------------------------------------------------------------------
 /
Index: /NEMO/trunk/cfgs/ORCA2_OFF_PISCES/EXPREF/namelist_top_cfg
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_OFF_PISCES/EXPREF/namelist_top_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/ORCA2_OFF_PISCES/EXPREF/namelist_top_cfg	(revision 11536)
@@ -56,12 +56,12 @@
 !          !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
 !          !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_trcdta(1)  = 'data_DIC_nomask'        ,        -12        ,  'DIC'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(2)  = 'data_Alkalini_nomask'   ,        -12        ,  'Alkalini',    .false.   , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(3)  = 'data_O2_nomask'         ,        -1         ,  'O2'      ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(5)  = 'data_PO4_nomask'        ,        -1         ,  'PO4'     ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(7)  = 'data_Si_nomask'         ,        -1         ,  'Si'      ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(10) = 'data_DOC_nomask'        ,        -12        ,  'DOC'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(14) = 'data_Fer_nomask'        ,        -12        ,  'Fer'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(23) = 'data_NO3_nomask'        ,        -1         ,  'NO3'     ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(1)  = 'data_DIC_nomask'        ,        -12.       ,  'DIC'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(2)  = 'data_Alkalini_nomask'   ,        -12.       ,  'Alkalini',    .false.   , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(3)  = 'data_O2_nomask'         ,        -1.        ,  'O2'      ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(5)  = 'data_PO4_nomask'        ,        -1.        ,  'PO4'     ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(7)  = 'data_Si_nomask'         ,        -1.        ,  'Si'      ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(10) = 'data_DOC_nomask'        ,        -12.       ,  'DOC'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(14) = 'data_Fer_nomask'        ,        -12.       ,  'Fer'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(23) = 'data_NO3_nomask'        ,        -1.        ,  'NO3'     ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
    rn_trfac(1)   =   1.0e-06  !  multiplicative factor
    rn_trfac(2)   =   1.0e-06  !  -      -      -     -
Index: /NEMO/trunk/cfgs/ORCA2_OFF_TRC/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_OFF_TRC/EXPREF/context_nemo.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/ORCA2_OFF_TRC/EXPREF/context_nemo.xml	(revision 11536)
@@ -6,4 +6,14 @@
 <context id="nemo">
 <!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
 <!-- Fields definition -->
     <field_definition src="./field_def_nemo-oce.xml"/>   <!--  Ocean biology                     -->
@@ -19,13 +29,13 @@
     
     <axis_definition>
-      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
-      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
-      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
-      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
-      <axis id="nfloat" long_name="Float number"      unit="-"                 />
-      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
-      <axis id="ncatice" long_name="Ice category"       unit="1"               />
-      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
-      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
+      <axis id="deptht"  long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="nfloat"  long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"     unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"      unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"  unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"  unit="degC"              />
     </axis_definition>
  
Index: /NEMO/trunk/cfgs/ORCA2_OFF_TRC/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_OFF_TRC/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/ORCA2_OFF_TRC/EXPREF/namelist_cfg	(revision 11536)
@@ -316,18 +316,18 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_tem      = 'dyna_grid_T'           ,       120         , 'votemper'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_sal      = 'dyna_grid_T'           ,       120         , 'vosaline'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_mld      = 'dyna_grid_T'           ,       120         , 'somixhgt'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_emp      = 'dyna_grid_T'           ,       120         , 'sowaflup'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_fmf      = 'dyna_grid_T'           ,       120         , 'iowaflup'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_ice      = 'dyna_grid_T'           ,       120         , 'soicecov'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_qsr      = 'dyna_grid_T'           ,       120         , 'soshfldo'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_wnd      = 'dyna_grid_T'           ,       120         , 'sowindsp'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_uwd      = 'dyna_grid_U'           ,       120         , 'uocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_vwd      = 'dyna_grid_V'           ,       120         , 'vocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_wwd      = 'dyna_grid_W'           ,       120         , 'wocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_avt      = 'dyna_grid_W'           ,       120         , 'voddmavs'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_ubl      = 'dyna_grid_U'           ,       120         , 'sobblcox'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_vbl      = 'dyna_grid_V'           ,       120         , 'sobblcoy'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_tem      = 'dyna_grid_T'           ,       120.        , 'votemper'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_sal      = 'dyna_grid_T'           ,       120.        , 'vosaline'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_mld      = 'dyna_grid_T'           ,       120.        , 'somixhgt'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_emp      = 'dyna_grid_T'           ,       120.        , 'sowaflup'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_fmf      = 'dyna_grid_T'           ,       120.        , 'iowaflup'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_ice      = 'dyna_grid_T'           ,       120.        , 'soicecov'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_qsr      = 'dyna_grid_T'           ,       120.        , 'soshfldo'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_wnd      = 'dyna_grid_T'           ,       120.        , 'sowindsp'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_uwd      = 'dyna_grid_U'           ,       120.        , 'uocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_vwd      = 'dyna_grid_V'           ,       120.        , 'vocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_wwd      = 'dyna_grid_W'           ,       120.        , 'wocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_avt      = 'dyna_grid_W'           ,       120.        , 'voddmavs'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_ubl      = 'dyna_grid_U'           ,       120.        , 'sobblcox'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_vbl      = 'dyna_grid_V'           ,       120.        , 'sobblcoy'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
 /
 !!======================================================================
@@ -374,5 +374,5 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
+!!   namflo       float parameters                                      (default: OFF)
 !!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
 !!   namdct       transports through some sections                      ("key_diadct")
@@ -399,5 +399,5 @@
 /
 !-----------------------------------------------------------------------
-&namflo        !   float parameters                                     ("key_float")
+&namflo        !   float parameters                                     (default: OFF)
 !-----------------------------------------------------------------------
 /
Index: /NEMO/trunk/cfgs/ORCA2_SAS_ICE/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_SAS_ICE/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/ORCA2_SAS_ICE/EXPREF/namelist_cfg	(revision 11536)
@@ -70,14 +70,14 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ !       weights filename               ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                                      ! pairing  !    filename   !
-   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6         , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Uwnd'   , ''
-   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6         , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Vwnd'   , ''
-   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_tair     = 't_10.15JUNE2009_fill'       ,    6         , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6         , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1         , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1         , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_slp      = 'slp.15JUNE2009_fill'        ,    6         , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_tdif     = 'taudif_core'                ,   24         , 'taudif'  ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6.        , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Uwnd'   , ''
+   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6.        , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Vwnd'   , ''
+   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_tair     = 't_10.15JUNE2009_fill'       ,    6.        , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6.        , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_slp      = 'slp.15JUNE2009_fill'        ,    6.        , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_tdif     = 'taudif_core'                ,   24.        , 'taudif'  ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -96,11 +96,11 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_usp      = 'sas_grid_U'            ,       120         , 'uos'     ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
-   sn_vsp      = 'sas_grid_V'            ,       120         , 'vos'     ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
-   sn_tem      = 'sas_grid_T'            ,       120         , 'sosstsst',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
-   sn_sal      = 'sas_grid_T'            ,       120         , 'sosaline',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
-   sn_ssh      = 'sas_grid_T'            ,       120         , 'sossheig',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
-   sn_e3t      = 'sas_grid_T'            ,       120         , 'e3t_m'   ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
-   sn_frq      = 'sas_grid_T'            ,       120         , 'frq_m'   ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_usp      = 'sas_grid_U'            ,       120.        , 'uos'     ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_vsp      = 'sas_grid_V'            ,       120.        , 'vos'     ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_tem      = 'sas_grid_T'            ,       120.        , 'sosstsst',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_sal      = 'sas_grid_T'            ,       120.        , 'sosaline',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_ssh      = 'sas_grid_T'            ,       120.        , 'sossheig',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_e3t      = 'sas_grid_T'            ,       120.        , 'e3t_m'   ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_frq      = 'sas_grid_T'            ,       120.        , 'frq_m'   ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
 /
 !!======================================================================
@@ -177,7 +177,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/cfgs/SHARED/domain_def_nemo.xml
===================================================================
--- /NEMO/trunk/cfgs/SHARED/domain_def_nemo.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/SHARED/domain_def_nemo.xml	(revision 11536)
@@ -10,7 +10,4 @@
      </domain>
 
-     <domain id="1point" domain_ref="grid_T" >
-       <zoom_domain ibegin="1" jbegin="1" ni="1" nj="1"/>
-     </domain>
      <!--   Eq section -->
      <domain id="EqT" domain_ref="grid_T" > <zoom_domain id="EqT"/> </domain>
Index: /NEMO/trunk/cfgs/SHARED/field_def_nemo-ice.xml
===================================================================
--- /NEMO/trunk/cfgs/SHARED/field_def_nemo-ice.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/SHARED/field_def_nemo-ice.xml	(revision 11536)
@@ -32,33 +32,33 @@
  
 	  <!-- general fields -->
-          <field id="icemass"      long_name="Sea-ice mass per area"                                   standard_name="sea_ice_amount"                            unit="kg/m2"/>
+          <field id="icemass"      long_name="Sea-ice mass per gridcell area"                          standard_name="sea_ice_amount"                            unit="kg/m2"/>
           <field id="snwmass"      long_name="Snow mass per area"                                      standard_name="liquid_water_content_of_surface_snow"      unit="kg/m2"/>
-          <field id="iceconc"      long_name="Sea-ice area fraction"                                   standard_name="sea_ice_area_fraction"                     unit=""    />
-          <field id="icevolu"      long_name="Sea-ice volume per area"                                 standard_name="sea_ice_thickness"                         unit="m"   />
-          <field id="icethic"      long_name="Sea-ice thickness per area"                              standard_name="sea_ice_thickness"                         unit="m"   />
-          <field id="snwthic"      long_name="Snow thickness per area"                                 standard_name="snow_thickness"                            unit="m"   />
-          <field id="icebrv"       long_name="brine volume"                                                                                                      unit="%"   />
-          <field id="iceage"       long_name="ice age"                                                                                                           unit="days"/>
-          <field id="icehnew"      long_name="frazil ice collection thickness"                                                                                   unit="m"   />
-          <field id="snwvolu"      long_name="snow volume"                                                                                                       unit="m"   />
-          <field id="icefrb"       long_name="Sea-ice freeboard"                                       standard_name="sea_ice_freeboard"                         unit="m"   />
-          <field id="icealb"       long_name="Sea-ice or snow albedo"                                  standard_name="sea_ice_albedo"                            unit=""    />
-          <field id="tau_icebfr"   long_name="ice friction on ocean bottom for landfast ice"                                                                     unit="N/2" />
+          <field id="iceconc"      long_name="Sea-ice area fraction"                                   standard_name="sea_ice_area_fraction"                     unit=""     />
+          <field id="icevolu"      long_name="Sea-ice volume per area"                                 standard_name="sea_ice_thickness"                         unit="m"    />
+          <field id="icethic"      long_name="Sea-ice thickness"                                       standard_name="sea_ice_thickness"                         unit="m"    />
+          <field id="snwthic"      long_name="Snow thickness"                                          standard_name="snow_thickness"                            unit="m"    />
+          <field id="icebrv"       long_name="brine volume"                                                                                                      unit="%"    />
+          <field id="iceage"       long_name="ice age"                                                                                                           unit="days" detect_missing_value="true"/>
+          <field id="icehnew"      long_name="frazil ice collection thickness"                                                                                   unit="m"    />
+          <field id="snwvolu"      long_name="snow volume"                                                                                                       unit="m"    />
+          <field id="icefrb"       long_name="Sea-ice freeboard"                                       standard_name="sea_ice_freeboard"                         unit="m"    />
+          <field id="icealb"       long_name="Sea-ice or snow albedo"                                  standard_name="sea_ice_albedo"                            unit=""    detect_missing_value="true" />
 	  
 	  <!-- melt ponds -->
-	  <field id="iceapnd"      long_name="melt pond fraction"                                      standard_name="sea_ice_meltpond_fraction"                 unit="%" /> 
+	  <field id="iceapnd"      long_name="melt pond concentration"                                 standard_name="sea_ice_meltpond_concentration"            unit=""  /> 
+          <field id="icehpnd"      long_name="melt pond depth"                                         standard_name="sea_ice_meltpond_depth"                    unit="m" /> 
           <field id="icevpnd"      long_name="melt pond volume"                                        standard_name="sea_ice_meltpond_volume"                   unit="m" /> 
 	  
 	  <!-- heat -->
-          <field id="icetemp"      long_name="Mean ice temperature"                                                                                              unit="degC" />
-          <field id="snwtemp"      long_name="Mean snow temperature"                                                                                             unit="degC" />
-          <field id="icettop"      long_name="temperature at the ice surface"                                                                                    unit="degC" />
-          <field id="icetbot"      long_name="temperature at the ice bottom"                                                                                     unit="degC" />
-          <field id="icetsni"      long_name="temperature at the snow-ice interface"                                                                             unit="degC" />
+          <field id="icetemp"      long_name="Mean ice temperature"                                                                                              unit="degC" detect_missing_value="true" />
+          <field id="snwtemp"      long_name="Mean snow temperature"                                                                                             unit="degC" detect_missing_value="true" />
+          <field id="icettop"      long_name="temperature at the ice surface"                                                                                    unit="degC" detect_missing_value="true" />
+          <field id="icetbot"      long_name="temperature at the ice bottom"                                                                                     unit="degC" detect_missing_value="true" />
+          <field id="icetsni"      long_name="temperature at the snow-ice interface"                                                                             unit="degC" detect_missing_value="true" />
           <field id="icehc"        long_name="ice heat content"                                                                                                  unit="J/m2" /> 
           <field id="snwhc"        long_name="snow heat content"                                                                                                 unit="J/m2" />
 	  
 	  <!-- salt -->
-          <field id="icesalt"      long_name="Sea ice salinity"                                                                                                  unit="g/kg"  />
+          <field id="icesalt"      long_name="Sea ice salinity"                                                                                                  unit="g/kg"  detect_missing_value="true" />
           <field id="icesalm"      long_name="Mass of salt in sea ice per area"                        standard_name="sea_ice_salt_mass"                         unit="kg/m2" />
 	  
@@ -71,4 +71,6 @@
           <field id="utau_oi"      long_name="X-component of ocean stress on sea ice"                  standard_name="sea_ice_base_upward_x_stress"              unit="N/m2" />
           <field id="vtau_oi"      long_name="Y-component of ocean stress on sea ice"                  standard_name="sea_ice_base_upward_y_stress"              unit="N/m2" />
+          <field id="utau_bi"      long_name="X-component of ocean bottom stress on sea ice -landfast" standard_name="ocean_bottom_upward_x_stress"              unit="N/m2" />
+          <field id="vtau_bi"      long_name="Y-component of ocean bottom stress on sea ice -landfast" standard_name="ocean_bottom_upward_y_stress"              unit="N/m2" />
           <field id="isig1"        long_name="1st principal stress component for EVP rhg"                                                                        unit=""     />
           <field id="isig2"        long_name="2nd principal stress component for EVP rhg"                                                                        unit=""     />
@@ -92,7 +94,7 @@
 	  
 	  <!-- trends -->
-          <field id="afxthd"       long_name="sea-ice area fraction change from thermodynamics"  standard_name="tendency_of_sea_ice_area_fraction_due_to_dynamics" unit="s-1" />
-          <field id="afxdyn"       long_name="sea-ice area fraction change from dynamics"        standard_name="tendency_of_sea_ice_area_fraction_due_to_dynamics" unit="s-1" />
-	  <field id="afxtot"       long_name="area tendency (total)"                                                                                               unit="s-1" />
+          <field id="afxthd"       long_name="sea-ice area fraction change from thermodynamics" standard_name="tendency_of_sea_ice_area_fraction_due_to_dynamics" unit="s-1" />
+          <field id="afxdyn"       long_name="sea-ice area fraction change from dynamics"       standard_name="tendency_of_sea_ice_area_fraction_due_to_dynamics" unit="s-1" />
+	  <field id="afxtot"       long_name="area tendency (total)"                                                                                              unit="s-1" />
 	  
 	  <!-- momentum (advection) -->
@@ -168,19 +170,4 @@
           <field id="e3t_m"    unit="m"    />
           <field id="frq_m"    unit="-"    />
-
-	  <!-- categories -->
-	  <field id="iceconc_cat"  long_name="Sea-ice concentration per category"                unit=""       grid_ref="grid_T_3D_ncatice" />
-          <field id="icethic_cat"  long_name="Sea-ice thickness per category"                    unit="m"      grid_ref="grid_T_3D_ncatice" />
-          <field id="snwthic_cat"  long_name="Snow thickness per category"                       unit="m"      grid_ref="grid_T_3D_ncatice" />
-          <field id="icesalt_cat"  long_name="Sea-Ice Bulk salinity per category"                unit="g/kg"   grid_ref="grid_T_3D_ncatice" />
-          <field id="icetemp_cat"  long_name="Ice temperature per category"                      unit="degC"   grid_ref="grid_T_3D_ncatice" />
-          <field id="snwtemp_cat"  long_name="Snow temperature per category"                     unit="degC"   grid_ref="grid_T_3D_ncatice" />
-          <field id="icettop_cat"  long_name="Ice/snow surface temperature per category"         unit="degC"   grid_ref="grid_T_3D_ncatice" />
-          <field id="iceapnd_cat"  long_name="Ice melt pond concentration per category"          unit="%"      grid_ref="grid_T_3D_ncatice" /> 
-          <field id="icehpnd_cat"  long_name="Ice melt pond thickness per category"              unit="m"      grid_ref="grid_T_3D_ncatice" /> 
-          <field id="iceafpnd_cat" long_name="Ice melt pond fraction per category"               unit="m"      grid_ref="grid_T_3D_ncatice" /> 
-          <field id="icemask_cat"  long_name="Fraction of time step with sea ice (per category)" unit=""       grid_ref="grid_T_3D_ncatice" />
-          <field id="iceage_cat"   long_name="Ice age per category"                              unit="days"   grid_ref="grid_T_3D_ncatice" />
-          <field id="icebrv_cat"   long_name="Brine volume per category"                         unit="%"      grid_ref="grid_T_3D_ncatice" />
 
 	  <!-- ================= -->
@@ -249,15 +236,42 @@
           <field id="xmtrptot"     long_name="X-component of sea-ice mass transport"                   standard_name="sea_ice_x_transport"                   unit="kg/s" > xmtrpice + xmtrpsnw </field>
           <field id="ymtrptot"     long_name="Y-component of sea-ice mass transport"                   standard_name="sea_ice_y_transport"                   unit="kg/s" > ymtrpice + ymtrpsnw </field>
-
-	  <!-- categories -->
-          <field id="iceconc_cat_cmip"     long_name="Sea-ice area fractions in thickness categories"  standard_name="sea_ice_area_fraction_over_categories" detect_missing_value="true" unit=""  grid_ref="grid_T_3D_ncatice" > iceconc_cat      * icemask_cat + $missval * (1.-icemask_cat) </field>
-          <field id="icethic_cat_cmip"     long_name="Sea-ice thickness in thickness categories"       standard_name="sea_ice_thickness_over_categories"     detect_missing_value="true" unit="m" grid_ref="grid_T_3D_ncatice" > icethic_cat      * icemask_cat + $missval * (1.-icemask_cat) </field>
-          <field id="snwthic_cat_cmip"     long_name="Snow thickness in thickness categories"          standard_name="snow_thickness_over_categories"        detect_missing_value="true" unit="m" grid_ref="grid_T_3D_ncatice" > snwthic_cat      * icemask_cat + $missval * (1.-icemask_cat) </field>
-          <field id="iceconc_cat_pct_cmip" long_name="Sea-ice area fractions in thickness categories"  standard_name="sea_ice_area_fraction_over_categories" detect_missing_value="true" unit="%" grid_ref="grid_T_3D_ncatice" > iceconc_cat*100. * icemask_cat + $missval * (1.-icemask_cat) </field>
 	 
 	</field_group> <!-- SBC_2D -->
 
+	<!-- categories -->
+        <field_group id="SBC_3D" grid_ref="grid_T_ncatice" >
+
+          <!-- standard ice fields -->  
+	  <field id="iceconc_cat"  long_name="Sea-ice concentration per category"                unit=""        />
+          <field id="icethic_cat"  long_name="Sea-ice thickness per category"                    unit="m"       detect_missing_value="true" />
+          <field id="snwthic_cat"  long_name="Snow thickness per category"                       unit="m"       detect_missing_value="true" />
+          <field id="icesalt_cat"  long_name="Sea-Ice Bulk salinity per category"                unit="g/kg"    detect_missing_value="true" />
+          <field id="icetemp_cat"  long_name="Ice temperature per category"                      unit="degC"    detect_missing_value="true" />
+          <field id="snwtemp_cat"  long_name="Snow temperature per category"                     unit="degC"    detect_missing_value="true" />
+          <field id="icettop_cat"  long_name="Ice/snow surface temperature per category"         unit="degC"    detect_missing_value="true" />
+          <field id="iceapnd_cat"  long_name="Ice melt pond concentration per category"          unit=""        /> 
+          <field id="icehpnd_cat"  long_name="Ice melt pond thickness per category"              unit="m"       detect_missing_value="true" /> 
+          <field id="iceafpnd_cat" long_name="Ice melt pond fraction per category"               unit=""        /> 
+          <field id="icemask_cat"  long_name="Fraction of time step with sea ice (per category)" unit=""        />
+          <field id="iceage_cat"   long_name="Ice age per category"                              unit="days"    detect_missing_value="true" />
+          <field id="icebrv_cat"   long_name="Brine volume per category"                         unit="%"       detect_missing_value="true" />
+
+          <!-- Add-ons for SIMIP -->
+          <field id="iceconc_cat_cmip"     long_name="Sea-ice area fractions in thickness categories"  standard_name="sea_ice_area_fraction_over_categories" detect_missing_value="true" unit=""   > iceconc_cat      * icemask_cat + $missval * (1.-icemask_cat) </field>
+          <field id="icethic_cat_cmip"     long_name="Sea-ice thickness in thickness categories"       standard_name="sea_ice_thickness_over_categories"     detect_missing_value="true" unit="m"  > icethic_cat      * icemask_cat + $missval * (1.-icemask_cat) </field>
+          <field id="snwthic_cat_cmip"     long_name="Snow thickness in thickness categories"          standard_name="snow_thickness_over_categories"        detect_missing_value="true" unit="m"  > snwthic_cat      * icemask_cat + $missval * (1.-icemask_cat) </field>
+          <field id="iceconc_cat_pct_cmip" long_name="Sea-ice area fractions in thickness categories"  standard_name="sea_ice_area_fraction_over_categories" detect_missing_value="true" unit="%"  > iceconc_cat*100. * icemask_cat + $missval * (1.-icemask_cat) </field>
+
+	</field_group> <!-- SBC_3D -->
+	
 	<!-- scalar variables -->
-	<field_group id="SBC_0D"  grid_ref="grid_1point" >
+	<field_group id="SBC_scalar"  grid_ref="grid_scalar" >
+          <field id="NH_iceextt"      long_name="Sea ice extent North"                   standard_name="sea_ice_extent_n"                   unit="1e6_km2"  />
+          <field id="SH_iceextt"      long_name="Sea ice extent South"                   standard_name="sea_ice_extent_s"                   unit="1e6_km2"  />
+          <field id="NH_icevolu"      long_name="Sea ice volume North"                   standard_name="sea_ice_volume_n"                   unit="1e3_km3"  />
+          <field id="SH_icevolu"      long_name="Sea ice volume South"                   standard_name="sea_ice_volume_s"                   unit="1e3_km3"  />
+          <field id="NH_icearea"      long_name="Sea ice area North"                     standard_name="sea_ice_area_n"                     unit="1e6_km2"  />
+          <field id="SH_icearea"      long_name="Sea ice area South"                     standard_name="sea_ice_area_s"                     unit="1e6_km2"  />
+
           <!-- available with ln_icediaout -->
           <field id="ibgfrcvoltop"    long_name="global mean ice/snow forcing at interface ice/snow-atm (volume equivalent ocean volume)"   unit="km3"      />
@@ -281,15 +295,11 @@
           <field id="sbgheat_tot"     long_name="global mean snow heat content"                                                             unit="1e20J"    />
 
-          <field id="NH_iceextt"      long_name="Sea ice extent North"                   standard_name="sea_ice_extent_n"                   unit="1e6_km2"  />
-          <field id="SH_iceextt"      long_name="Sea ice extent South"                   standard_name="sea_ice_extent_s"                   unit="1e6_km2"  />
-          <field id="NH_icevolu"      long_name="Sea ice volume North"                   standard_name="sea_ice_volume_n"                   unit="1e3_km3"  />
-          <field id="SH_icevolu"      long_name="Sea ice volume South"                   standard_name="sea_ice_volume_s"                   unit="1e3_km3"  />
-          <field id="NH_icearea"      long_name="Sea ice area North"                     standard_name="sea_ice_area_n"                     unit="1e6_km2"  />
-          <field id="SH_icearea"      long_name="Sea ice area South"                     standard_name="sea_ice_area_s"                     unit="1e6_km2"  />
-
+	  <!-- available later -->
+	  <!--
           <field id="strait_mifl"     long_name="Sea ice mass flux through straits"      standard_name="sea_ice_mass_transport_across_line" unit="kg/s"  grid_ref="grid_4strait" />
           <field id="strait_arfl"     long_name="Sea ice area flux through straits"      standard_name="sea_ice_area_transport_across_line" unit="m2/s"  grid_ref="grid_4strait" />  
           <field id="strait_msfl"     long_name="Sea ice snow flux through straits"      standard_name="snow_mass_transport_across_line"    unit="kg/s"  grid_ref="grid_4strait" />
-	</field_group> <!-- SBC_0D -->
+          -->
+	</field_group>
   
 	<!-- 
@@ -299,10 +309,132 @@
       
 	<field_group id="myvarICE"        grid_ref="grid_T_2D" >
-          <field field_ref="icethic"          name="sithic"  />
-          <field field_ref="icevolu"          name="sivolu"  />
-          <field field_ref="iceconc"          name="siconc"  />
+	  <!-- ice mask -->
+	  <field field_ref="icemask"          name="simsk"   />
+	  <field field_ref="icemask05"        name="simsk05" />
+	  <field field_ref="icemask15"        name="simsk15" />
+	  
+	  <!-- general -->
+	  <field field_ref="snwvolu"          name="snvolu" />
+	  <field field_ref="snwthic"          name="snthic" />
+	  <field field_ref="icethic"          name="sithic" />
+<!--
+	  <field field_ref="icethic"          name="sithic_max" operation="maximum" />
+	  <field field_ref="icethic"          name="sithic_min" operation="minimum" />
+-->
+	  <field field_ref="fasticepres"      name="fasticepres" />
+	  <field field_ref="icevolu"          name="sivolu" />
+	  <field field_ref="iceconc"          name="siconc" />
+	  <field field_ref="icesalt"          name="sisali" />
+	  <field field_ref="iceapnd"          name="siapnd" />
+	  <field field_ref="icehpnd"          name="sihpnd" />
+	  <field field_ref="icevpnd"          name="sivpnd" />
+          <field field_ref="iceage"           name="siage"  />
+	  <field field_ref="sst_m"            name="sst_m"  />
+	  <field field_ref="sss_m"            name="sss_m"  />
+	  
+	  <!-- heat -->
+	  <field field_ref="icetemp"          name="sitemp" />
+	  <field field_ref="snwtemp"          name="sntemp" />
+	  <field field_ref="icettop"          name="sittop" />
+	  <field field_ref="icetbot"          name="sitbot" />
+	  <field field_ref="icetsni"          name="sitsni" />
+	  
+	  <!-- momentum -->
+	  <field field_ref="uice"             name="sivelu"  />
+	  <field field_ref="vice"             name="sivelv"  />
+	  <field field_ref="icevel"           name="sivelo"  />
+	  <field field_ref="utau_ai"          name="utau_ai" />
+	  <field field_ref="vtau_ai"          name="vtau_ai" />
+	  <field field_ref="utau_oi"          name="utau_oi" />
+	  <field field_ref="vtau_oi"          name="vtau_oi" />
+	  
+	  <!-- rheology -->
+	  <field field_ref="icediv"           name="sidive"  />
+	  <field field_ref="iceshe"           name="sishea"  />
+	  <field field_ref="icestr"           name="sistre"  />
+	  <field field_ref="normstr"          name="normstr" />
+	  <field field_ref="sheastr"          name="sheastr" />
+	  <field field_ref="isig1"            name="isig1"   />
+	  <field field_ref="isig2"            name="isig2"   />
+	  <field field_ref="isig3"            name="isig3"   />
+	  
+	  <!-- heat fluxes -->
+	  <field field_ref="qt_oce_ai"        name="qt_oce_ai"  />
+	  <field field_ref="qt_atm_oi"        name="qt_atm_oi"  />
+	  <field field_ref="qtr_ice_top"      name="qtr_ice_top"/>
+	  <field field_ref="qtr_ice_bot"      name="qtr_ice_bot"/>
+	  <field field_ref="qt_ice"           name="qt_ice"     />
+	  <field field_ref="qsr_ice"          name="qsr_ice"    />
+	  <field field_ref="qns_ice"          name="qns_ice"    />
+	  <field field_ref="qemp_ice"         name="qemp_ice"   />
+	  <field field_ref="albedo"           name="albedo"     />
+          <field field_ref="icealb"           name="icealb"     />
+	  
+	  <field field_ref="hfxcndtop"        name="hfxcndtop"  />
+	  <field field_ref="hfxcndbot"        name="hfxcndbot"  />
+	  <field field_ref="hfxsensib"        name="hfxsensib"  />
+
+	  <field field_ref="icehc"         name="icehc"  />
+	  <field field_ref="snwhc"         name="snwhc"  />
+	  <field field_ref="hfxbog"        name="hfxbog"  />
+	  <field field_ref="hfxbom"        name="hfxbom"  />
+	  <field field_ref="hfxsum"        name="hfxsum"  />
+	  <field field_ref="hfxopw"        name="hfxopw"  />
+	  <field field_ref="hfxdif"        name="hfxdif"  />
+	  <field field_ref="hfxsnw"        name="hfxsnw"  />
+	  <field field_ref="hfxerr"        name="hfxerr"  />
+	  <field field_ref="hfxthd"        name="hfxthd"  />
+	  <field field_ref="hfxdyn"        name="hfxdyn"  />
+	  <field field_ref="hfxres"        name="hfxres"  />
+	  <field field_ref="hfxsub"        name="hfxsub"  />
+	  <field field_ref="hfxspr"        name="hfxspr"  />
+
+<!--
+	  <field field_ref="hfxdhc"        name="hfxbudget"  operation="average" freq_op="1d" > @qt_atm_oi - @qt_oce_ai -@hfxdhc </field>
+-->
+	  
+	  <!-- salt fluxes -->
+	  <field field_ref="sfxice"           name="sfxice" />
+	  
+	  <!-- mass fluxes -->
+	  <field field_ref="vfxice"           name="vfxice" />
+	  <field field_ref="vfxsnw"           name="vfxsnw" />
+
+	  <field field_ref="vfxbom"           name="vfxbom" />
+	  <field field_ref="vfxbog"           name="vfxbog" />
+	  <field field_ref="vfxsum"           name="vfxsum" />
+	  <field field_ref="vfxopw"           name="vfxopw" />
+	  <field field_ref="vfxlam"           name="vfxlam" />
+	  <field field_ref="vfxsni"           name="vfxsni" />
+	  <field field_ref="vfxdyn"           name="vfxdyn" />
+	  <field field_ref="vfxres"           name="vfxres" />
+	  <field field_ref="vfxpnd"           name="vfxpnd" />
+	  <field field_ref="vfxsub"           name="vfxsub" />
+	  <field field_ref="vfxsub_err"       name="vfxsub_err" />
+          <field field_ref="vfxthin"          name="vfxthin" />
+	
+	  <!-- diag error for negative ice volume after advection -->
+	  <field field_ref="iceneg_pres"      name="sineg_pres" />
+	  <field field_ref="iceneg_volu"      name="sineg_volu" />
+	  <field field_ref="iceneg_hfx"       name="sineg_hfx"  />
+        </field_group>
+
+
+        <field_group id="myvarICE_cat"        grid_ref="grid_T_ncatice" >
+
+	  <!-- categories -->
+	  <field field_ref="icemask_cat"      name="simskcat"/>
+	  <field field_ref="snwthic_cat"      name="snthicat"/>
+	  <field field_ref="iceconc_cat"      name="siconcat"/>
+	  <field field_ref="icethic_cat"      name="sithicat"/>
+	  <field field_ref="icesalt_cat"      name="sisalcat"/>
+	  <field field_ref="icetemp_cat"      name="sitemcat"/>
+	  <field field_ref="snwtemp_cat"      name="sntemcat"/>
+	  <field field_ref="icettop_cat"      name="sitopcat"/>
+
 	</field_group>    
 
-	<field_group id="ICE_globalbudget"  grid_ref="grid_1point" >
+	<field_group id="ICE_globalbudget"  grid_ref="grid_scalar" >
+	  <!-- global contents -->
     	  <field field_ref="ibgvol_tot"       name="ibgvol_tot"   />
 	  <field field_ref="sbgvol_tot"       name="sbgvol_tot"   />
@@ -312,9 +444,11 @@
     	  <field field_ref="sbgheat_tot"      name="sbgheat_tot"  />
 
-     	  <field field_ref="ibgvolume"        name="ibgvolume"    />
+	  <!-- global drifts (conservation checks) -->
+	  <field field_ref="ibgvolume"        name="ibgvolume"    />
     	  <field field_ref="ibgsaltco"        name="ibgsaltco"    />
     	  <field field_ref="ibgheatco"        name="ibgheatco"    />
           <field field_ref="ibgheatfx"        name="ibgheatfx"    />
 
+	  <!-- global forcings  -->
     	  <field field_ref="ibgfrcvoltop"     name="ibgfrcvoltop" />
     	  <field field_ref="ibgfrcvolbot"     name="ibgfrcvolbot" />
@@ -333,5 +467,5 @@
 
 	<!-- SIMIP monthly scalar variables -->
-	<field_group id="SImon_scalars"   grid_ref="grid_1point" >
+	<field_group id="SImon_scalars"   grid_ref="grid_scalar" >
           <!-- Integrated quantities -->
           <field field_ref="NH_iceextt"       name="siextentn"    />
Index: /NEMO/trunk/cfgs/SHARED/field_def_nemo-oce.xml
===================================================================
--- /NEMO/trunk/cfgs/SHARED/field_def_nemo-oce.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/SHARED/field_def_nemo-oce.xml	(revision 11536)
@@ -343,7 +343,4 @@
 	</field_group>
 	
-	<!-- scalar variables -->
-	<field_group id="SBC_0D"  grid_ref="grid_1point" >
-	</field_group>
 
       </field_group> <!-- SBC -->
@@ -500,5 +497,5 @@
       <field id="ahmf_3d"      long_name=" 3D      f-eddy viscosity coefficient"   unit="m2/s or m4/s"  grid_ref="grid_T_3D"/>
 
-      <field_group id="scalar"  grid_ref="grid_T_2D"  >
+      <field_group id="scalar"  grid_ref="grid_scalar"  >
       	<!-- Need to have a salinity reference climatological file : sali_ref_clim_monthly -->
         <field id="voltot"     long_name="global total volume"                          standard_name="sea_water_volume"                               unit="m3"   />
@@ -527,5 +524,5 @@
       </field_group>
       
-      <!-- variables available with key_float -->
+      <!-- variables available with ln_floats -->
 
       <field_group id="floatvar" grid_ref="grid_T_nfloat"  operation="instant" >
Index: /NEMO/trunk/cfgs/SHARED/field_def_nemo-pisces.xml
===================================================================
--- /NEMO/trunk/cfgs/SHARED/field_def_nemo-pisces.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/SHARED/field_def_nemo-pisces.xml	(revision 11536)
@@ -290,5 +290,5 @@
      </field_group>
 
-     <field_group id="tracer_scalar"  grid_ref="grid_T_2D"  >
+     <field_group id="tracer_scalar"  grid_ref="grid_scalar"  >
      <!-- PISCES scalar  -->
        <field id="pno3tot"         long_name="Global mean nitrate concentration"                  unit="mol/m3"   />
Index: /NEMO/trunk/cfgs/SHARED/grid_def_nemo.xml
===================================================================
--- /NEMO/trunk/cfgs/SHARED/grid_def_nemo.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/SHARED/grid_def_nemo.xml	(revision 11536)
@@ -7,5 +7,5 @@
        </grid>
         <!--  -->
-       <grid id="grid_T_3D_ncatice" >
+       <grid id="grid_T_ncatice" >
          <domain id="grid_T" />
          <axis id="ncatice" />
@@ -49,12 +49,12 @@
        </grid>
         <!--  -->
-       <grid id="grid_1point" >
-         <domain domain_ref="1point"/>
-       </grid>
-        <!--  -->
        <grid id="grid_T_nfloat" >
          <domain id="grid_T" />
          <axis id="nfloat" />
        </grid>
+      <!-- scalars -->
+      <grid id="grid_scalar" >
+        <scalar/>
+      </grid>
 
     </grid_definition>
Index: /NEMO/trunk/cfgs/SHARED/namelist_ice_ref
===================================================================
--- /NEMO/trunk/cfgs/SHARED/namelist_ice_ref	(revision 11535)
+++ /NEMO/trunk/cfgs/SHARED/namelist_ice_ref	(revision 11536)
@@ -56,5 +56,4 @@
    rn_ishlat        =   2.            !  lbc : free slip (0) ; partial slip (0-2) ; no slip (2) ; strong slip (>2)
    ln_landfast_L16  = .false.         !  landfast: parameterization from Lemieux 2016
-   ln_landfast_home = .false.         !  landfast: parameterization from "home made"
       rn_depfra     =   0.125         !        fraction of ocean depth that ice must reach to initiate landfast
                                       !          recommended range: [0.1 ; 0.25] - L16=0.125 - home=0.15
@@ -178,9 +177,10 @@
 &namthd_pnd     !   Melt ponds
 !------------------------------------------------------------------------------
-   ln_pnd_H12       = .false.         !  activate evolutive melt ponds (from Holland et al 2012)
-   ln_pnd_CST       = .false.         !  activate constant  melt ponds
-      rn_apnd       =   0.2           !     prescribed pond fraction, at Tsu=0 degC
-      rn_hpnd       =   0.05          !     prescribed pond depth,    at Tsu=0 degC
-   ln_pnd_alb       = .false.         !  melt ponds affect albedo or not
+   ln_pnd           = .false.         !  activate melt ponds or not
+     ln_pnd_H12     = .false.         !  activate evolutive melt ponds (from Holland et al 2012)
+     ln_pnd_CST     = .false.         !  activate constant  melt ponds
+       rn_apnd      =   0.2           !     prescribed pond fraction, at Tsu=0 degC
+       rn_hpnd      =   0.05          !     prescribed pond depth,    at Tsu=0 degC
+     ln_pnd_alb     = .false.         !  melt ponds affect albedo or not
 /
 !------------------------------------------------------------------------------
@@ -189,22 +189,34 @@
    ln_iceini        = .true.          !  activate ice initialization (T) or not (F)
    ln_iceini_file   = .false.         !  netcdf file provided for initialization (T) or not (F)
-   rn_thres_sst     =   2.0           !  max delta temp. above Tfreeze with initial ice = (sst - tfreeze)
-   rn_hts_ini_n     =   0.3           !  initial real snow thickness (m), North
+   rn_thres_sst     =   2.0           !  max temp. above Tfreeze with initial ice = (sst - tfreeze)
+   rn_hti_ini_n     =   3.0           !  initial ice thickness       (m), North
+   rn_hti_ini_s     =   1.0           !        "            "             South
+   rn_hts_ini_n     =   0.3           !  initial snow thickness      (m), North
    rn_hts_ini_s     =   0.3           !        "            "             South
-   rn_hti_ini_n     =   3.0           !  initial real ice thickness  (m), North
-   rn_hti_ini_s     =   1.0           !        "            "             South
    rn_ati_ini_n     =   0.9           !  initial ice concentration   (-), North
    rn_ati_ini_s     =   0.9           !        "            "             South
    rn_smi_ini_n     =   6.3           !  initial ice salinity     (g/kg), North
    rn_smi_ini_s     =   6.3           !        "            "             South
-   rn_tmi_ini_n     = 270.            !  initial ice/snw temperature (K), North
+   rn_tmi_ini_n     = 270.            !  initial ice temperature     (K), North
    rn_tmi_ini_s     = 270.            !        "            "             South
-
+   rn_tsu_ini_n     = 270.            !  initial surface temperature (K), North
+   rn_tsu_ini_s     = 270.            !        "            "             South
+   rn_tms_ini_n     = 270.            !  initial snw temperature     (K), North
+   rn_tms_ini_s     = 270.            !        "            "             South
+   rn_apd_ini_n     =   0.2           !  initial pond fraction       (-), North
+   rn_apd_ini_s     =   0.2           !        "            "             South
+   rn_hpd_ini_n     =   0.05          !  initial pond depth          (m), North
+   rn_hpd_ini_s     =   0.05          !        "            "             South
+   ! -- for ln_iceini_file = T
    sn_hti = 'Ice_initialization'    , -12 ,'hti'   ,  .false.  , .true., 'yearly'  , '' , '', ''
    sn_hts = 'Ice_initialization'    , -12 ,'hts'   ,  .false.  , .true., 'yearly'  , '' , '', ''
    sn_ati = 'Ice_initialization'    , -12 ,'ati'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_smi = 'Ice_initialization'    , -12 ,'smi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_tmi = 'Ice_initialization'    , -12 ,'tmi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
    sn_tsu = 'Ice_initialization'    , -12 ,'tsu'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_tmi = 'Ice_initialization'    , -12 ,'tmi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_smi = 'Ice_initialization'    , -12 ,'smi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_tms = 'NOT USED'              , -12 ,'tms'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   !      melt ponds (be careful, sn_apd is the pond concentration (not fraction), so it differs from rn_apd)
+   sn_apd = 'NOT USED'              , -12 ,'apd'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_hpd = 'NOT USED'              , -12 ,'hpd'   ,  .false.  , .true., 'yearly'  , '' , '', ''
    cn_dir='./'
 /
@@ -222,5 +234,8 @@
 &namdia         !   Diagnostics
 !------------------------------------------------------------------------------
-   ln_icediachk     = .false.         !  check online the heat, mass & salt budgets (T) or not (F)
+   ln_icediachk     = .false.         !  check online the heat, mass & salt budgets at each time step
+      !                               !     rate of ice spuriously gained/lost. For ex., rn_icechk=1. <=> 1mm/year, rn_icechk=0.1 <=> 1mm/10years                                   
+      rn_icechk_cel =  1.             !     check at any gridcell           => stops the code if violated (and writes a file)
+      rn_icechk_glo =  0.1            !     check over the entire ice cover => only prints warnings
    ln_icediahsb     = .false.         !  output the heat, mass & salt budgets (T) or not (F)
    ln_icectl        = .false.         !  ice points output for debug (T or F)
Index: /NEMO/trunk/cfgs/SHARED/namelist_pisces_ref
===================================================================
--- /NEMO/trunk/cfgs/SHARED/namelist_pisces_ref	(revision 11535)
+++ /NEMO/trunk/cfgs/SHARED/namelist_pisces_ref	(revision 11536)
@@ -34,6 +34,6 @@
 !              !  file name   ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
 !              !              !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_patm     = 'presatm'    ,     -1            , 'patm'    ,  .true.      , .true. , 'yearly'  , ''       , ''       , ''
-   sn_atmco2   = 'presatmco2' ,     -1            , 'xco2'    ,  .true.      , .true. , 'yearly'  , ''       , ''       , ''
+   sn_patm     = 'presatm'    ,     -1.           , 'patm'    ,  .true.      , .true. , 'yearly'  , ''       , ''       , ''
+   sn_atmco2   = 'presatmco2' ,     -1.           , 'xco2'    ,  .true.      , .true. , 'yearly'  , ''       , ''       , ''
    cn_dir      = './'     !  root directory for the location of the dynamical files
 !
@@ -141,5 +141,5 @@
 !              !  file name       ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
 !              !                  !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_par      = 'par.orca'       ,     24            , 'fr_par'  ,  .true.      , .true. , 'yearly'  , ''       , ''       , ''
+   sn_par      = 'par.orca'       ,     24.           , 'fr_par'  ,  .true.      , .true. , 'yearly'  , ''       , ''       , ''
    cn_dir      = './'      !  root directory for the location of the dynamical files
    ln_varpar   =  .true.   ! boolean for PAR variable
@@ -347,16 +347,16 @@
 !              !  file name        ! frequency (hours) ! variable      ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
 !              !                   !  (if <0  months)  !   name        !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_dust     = 'dust.orca'       ,     -1            , 'dust'        ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
-   sn_solub    = 'solubility.orca' ,    -12            , 'solubility1' ,  .false.     , .true. , 'yearly'  , ''       , ''    , ''
-   sn_riverdic = 'river.orca'      ,    120            , 'riverdic'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
-   sn_riverdoc = 'river.orca'      ,    120            , 'riverdoc'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
-   sn_riverdin = 'river.orca'      ,    120            , 'riverdin'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
-   sn_riverdon = 'river.orca'      ,    120            , 'riverdon'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
-   sn_riverdip = 'river.orca'      ,    120            , 'riverdip'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
-   sn_riverdop = 'river.orca'      ,    120            , 'riverdop'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
-   sn_riverdsi = 'river.orca'      ,    120            , 'riverdsi'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
-   sn_ndepo    = 'ndeposition.orca',    -12            , 'ndep'        ,  .false.     , .true. , 'yearly'  , ''       , ''    , ''
-   sn_ironsed  = 'bathy.orca'      ,    -12            , 'bathy'       ,  .false.     , .true. , 'yearly'  , ''       , ''    , ''
-   sn_hydrofe  = 'hydrofe.orca'    ,    -12            , 'epsdb'       ,  .false.     , .true. , 'yearly'  , ''       , ''    , ''
+   sn_dust     = 'dust.orca'       ,     -1.           , 'dust'        ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
+   sn_solub    = 'solubility.orca' ,    -12.           , 'solubility1' ,  .false.     , .true. , 'yearly'  , ''       , ''    , ''
+   sn_riverdic = 'river.orca'      ,    120.           , 'riverdic'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
+   sn_riverdoc = 'river.orca'      ,    120.           , 'riverdoc'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
+   sn_riverdin = 'river.orca'      ,    120.           , 'riverdin'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
+   sn_riverdon = 'river.orca'      ,    120.           , 'riverdon'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
+   sn_riverdip = 'river.orca'      ,    120.           , 'riverdip'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
+   sn_riverdop = 'river.orca'      ,    120.           , 'riverdop'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
+   sn_riverdsi = 'river.orca'      ,    120.           , 'riverdsi'    ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
+   sn_ndepo    = 'ndeposition.orca',    -12.           , 'ndep'        ,  .false.     , .true. , 'yearly'  , ''       , ''    , ''
+   sn_ironsed  = 'bathy.orca'      ,    -12.           , 'bathy'       ,  .false.     , .true. , 'yearly'  , ''       , ''    , ''
+   sn_hydrofe  = 'hydrofe.orca'    ,    -12.           , 'epsdb'       ,  .false.     , .true. , 'yearly'  , ''       , ''    , ''
 !
    cn_dir      = './'      !  root directory for the location of the dynamical files
Index: /NEMO/trunk/cfgs/SHARED/namelist_ref
===================================================================
--- /NEMO/trunk/cfgs/SHARED/namelist_ref	(revision 11535)
+++ /NEMO/trunk/cfgs/SHARED/namelist_ref	(revision 11536)
@@ -50,12 +50,16 @@
       cn_ocerst_indir = "."         !  directory from which to read input ocean restarts
       cn_ocerst_out   = "restart"   !  suffix of ocean restart name (output)
-      cn_ocerst_outdir = "."         !  directory in which to write output ocean restarts
+      cn_ocerst_outdir = "."        !  directory in which to write output ocean restarts
    ln_iscpl    = .false.   !  cavity evolution forcing or coupling to ice sheet model
    nn_istate   =       0   !  output the initial state (1) or not (0)
    ln_rst_list = .false.   !  output restarts at list of times using nn_stocklist (T) or at set frequency with nn_stock (F)
-   nn_stock    =    5840   !  frequency of creation of a restart file (modulo referenced to 1)
+   nn_stock    =       0   !  used only if ln_rst_list = F: output restart freqeuncy (modulo referenced to 1)
+      !                          !    =  0 force to write restart files only at the end of the run
+      !                          !    = -1 do not do any restart
    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    =    5840   !  frequency of write in the output file   (modulo referenced to nn_it000)
-   ln_mskland  = .false.   !  mask land points in NetCDF outputs (costly: + ~15%)
+   nn_write    =       0   !  used only if key_iomput is not defined: output frequency (modulo referenced to nn_it000)
+      !                          !    =  0 force to write output files only at the end of the run
+      !                          !    = -1 do not do any output file
+   ln_mskland  = .false.   !  mask land points in NetCDF outputs
    ln_cfmeta   = .false.   !  output additional data to netCDF files required for compliance with the CF metadata standard
    ln_clobber  = .true.    !  clobber (overwrite) an existing file
@@ -107,6 +111,6 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_tem = 'data_1m_potential_temperature_nomask',  -1      , 'votemper',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
-   sn_sal = 'data_1m_salinity_nomask'             ,  -1      , 'vosaline',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_tem = 'data_1m_potential_temperature_nomask',  -1.     , 'votemper',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_sal = 'data_1m_salinity_nomask'             ,  -1.     , 'vosaline',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
 /
 !-----------------------------------------------------------------------
@@ -163,6 +167,6 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_ucur     = 'ucurrent'              ,         -1        ,'u_current',   .false.   , .true. , 'monthly' ,  ''              ,  'Ume'   , ''
-   sn_vcur     = 'vcurrent'              ,         -1        ,'v_current',   .false.   , .true. , 'monthly' ,  ''              ,  'Vme'   , ''
+   sn_ucur     = 'ucurrent'              ,         -1.       ,'u_current',   .false.   , .true. , 'monthly' ,  ''              ,  'Ume'   , ''
+   sn_vcur     = 'vcurrent'              ,         -1.       ,'v_current',   .false.   , .true. , 'monthly' ,  ''              ,  'Vme'   , ''
 /
 
@@ -239,9 +243,9 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_utau     = 'utau'                  ,        24         , 'utau'    , .false.     , .false., 'yearly'  , ''               , ''       , ''
-   sn_vtau     = 'vtau'                  ,        24         , 'vtau'    , .false.     , .false., 'yearly'  , ''               , ''       , ''
-   sn_qtot     = 'qtot'                  ,        24         , 'qtot'    , .false.     , .false., 'yearly'  , ''               , ''       , ''
-   sn_qsr      = 'qsr'                   ,        24         , 'qsr'     , .false.     , .false., 'yearly'  , ''               , ''       , ''
-   sn_emp      = 'emp'                   ,        24         , 'emp'     , .false.     , .false., 'yearly'  , ''               , ''       , ''
+   sn_utau     = 'utau'                  ,        24.        , 'utau'    , .false.     , .false., 'yearly'  , ''               , ''       , ''
+   sn_vtau     = 'vtau'                  ,        24.        , 'vtau'    , .false.     , .false., 'yearly'  , ''               , ''       , ''
+   sn_qtot     = 'qtot'                  ,        24.        , 'qtot'    , .false.     , .false., 'yearly'  , ''               , ''       , ''
+   sn_qsr      = 'qsr'                   ,        24.        , 'qsr'     , .false.     , .false., 'yearly'  , ''               , ''       , ''
+   sn_emp      = 'emp'                   ,        24.        , 'emp'     , .false.     , .false., 'yearly'  , ''               , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -268,13 +272,13 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ !       weights filename               ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                                      ! pairing  !    filename   !
-   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6         , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Uwnd'   , ''
-   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6         , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Vwnd'   , ''
-   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24         , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_tair     = 't_10.15JUNE2009_fill'       ,    6         , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6         , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1         , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1         , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_slp      = 'slp.15JUNE2009_fill'        ,    6         , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_wndi     = 'u_10.15JUNE2009_fill'       ,    6.        , 'U_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Uwnd'   , ''
+   sn_wndj     = 'v_10.15JUNE2009_fill'       ,    6.        , 'V_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'  , 'Vwnd'   , ''
+   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'SWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,   24.        , 'LWDN_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_tair     = 't_10.15JUNE2009_fill'       ,    6.        , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_humi     = 'q_10.15JUNE2009_fill'       ,    6.        , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
+   sn_slp      = 'slp.15JUNE2009_fill'        ,    6.        , 'SLP'     ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
    sn_tdif     = 'taudif_core'                ,   24         , 'taudif'  ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
 /
@@ -343,11 +347,11 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_usp      = 'sas_grid_U'            ,       120         , 'uos'     ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
-   sn_vsp      = 'sas_grid_V'            ,       120         , 'vos'     ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
-   sn_tem      = 'sas_grid_T'            ,       120         , 'sosstsst',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
-   sn_sal      = 'sas_grid_T'            ,       120         , 'sosaline',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
-   sn_ssh      = 'sas_grid_T'            ,       120         , 'sossheig',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
-   sn_e3t      = 'sas_grid_T'            ,       120         , 'e3t_m'   ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
-   sn_frq      = 'sas_grid_T'            ,       120         , 'frq_m'   ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_usp      = 'sas_grid_U'            ,       120.        , 'uos'     ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_vsp      = 'sas_grid_V'            ,       120.        , 'vos'     ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_tem      = 'sas_grid_T'            ,       120.        , 'sosstsst',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_sal      = 'sas_grid_T'            ,       120.        , 'sosaline',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_ssh      = 'sas_grid_T'            ,       120.        , 'sossheig',   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_e3t      = 'sas_grid_T'            ,       120.        , 'e3t_m'   ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
+   sn_frq      = 'sas_grid_T'            ,       120.        , 'frq_m'   ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,    ''
 /
 !-----------------------------------------------------------------------
@@ -377,5 +381,5 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_chl      ='chlorophyll'            ,        -1         , 'CHLA'    ,   .true.    , .true. , 'yearly'  , ''               , ''       , ''
+   sn_chl      ='chlorophyll'            ,        -1.        , 'CHLA'    ,   .true.    , .true. , 'yearly'  , ''               , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -394,6 +398,6 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_sst      = 'sst_data'              ,        24         ,  'sst'    ,    .false.  , .false., 'yearly'  ,    ''            ,    ''    ,     ''
-   sn_sss      = 'sss_data'              ,        -1         ,  'sss'    ,    .true.   , .true. , 'yearly'  ,    ''            ,    ''    ,     ''
+   sn_sst      = 'sst_data'              ,        24.        ,  'sst'    ,    .false.  , .false., 'yearly'  ,    ''            ,    ''    ,     ''
+   sn_sss      = 'sss_data'              ,        -1.        ,  'sss'    ,    .true.   , .true. , 'yearly'  ,    ''            ,    ''    ,     ''
 /
 !-----------------------------------------------------------------------
@@ -416,9 +420,9 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_rnf      = 'runoff_core_monthly'   ,        -1         , 'sorunoff',   .true.    , .true. , 'yearly'  , ''               , ''       , ''
-   sn_cnf      = 'runoff_core_monthly'   ,         0         , 'socoefr0',   .false.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_s_rnf    = 'runoffs'               ,        24         , 'rosaline',   .true.    , .true. , 'yearly'  , ''               , ''       , ''
-   sn_t_rnf    = 'runoffs'               ,        24         , 'rotemper',   .true.    , .true. , 'yearly'  , ''               , ''       , ''
-   sn_dep_rnf  = 'runoffs'               ,         0         , 'rodepth' ,   .false.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_rnf      = 'runoff_core_monthly'   ,        -1.        , 'sorunoff',   .true.    , .true. , 'yearly'  , ''               , ''       , ''
+   sn_cnf      = 'runoff_core_monthly'   ,         0.        , 'socoefr0',   .false.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_s_rnf    = 'runoffs'               ,        24.        , 'rosaline',   .true.    , .true. , 'yearly'  , ''               , ''       , ''
+   sn_t_rnf    = 'runoffs'               ,        24.        , 'rotemper',   .true.    , .true. , 'yearly'  , ''               , ''       , ''
+   sn_dep_rnf  = 'runoffs'               ,         0.        , 'rodepth' ,   .false.   , .true. , 'yearly'  , ''               , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -433,5 +437,5 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_apr      = 'patm'                  ,         -1        ,'somslpre' ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,      ''
+   sn_apr      = 'patm'                  ,         -1.       ,'somslpre' ,   .true.    , .true. , 'yearly'  ,    ''            ,    ''    ,      ''
 /
 !-----------------------------------------------------------------------
@@ -460,12 +464,12 @@
    !           !             !  (if <0  months)  !   name    !  (logical)  !  (T/F)  ! 'monthly' ! filename ! pairing  ! filename      !
 !* nn_isf = 4 case
-   sn_fwfisf   = 'rnfisf'    ,         -12       ,'sowflisf' ,  .false.    , .true.  , 'yearly'  ,    ''    ,   ''     ,    ''
+   sn_fwfisf   = 'rnfisf'    ,         -12.      ,'sowflisf' ,  .false.    , .true.  , 'yearly'  ,    ''    ,   ''     ,    ''
 !* nn_isf = 3 case
-   sn_rnfisf   = 'rnfisf'    ,         -12       ,'sofwfisf' ,  .false.    , .true.  , 'yearly'  ,    ''    ,   ''     ,    ''
+   sn_rnfisf   = 'rnfisf'    ,         -12.      ,'sofwfisf' ,  .false.    , .true.  , 'yearly'  ,    ''    ,   ''     ,    ''
 !* nn_isf = 2 and 3 cases 
-   sn_depmax_isf ='rnfisf'    ,         -12       ,'sozisfmax',  .false.    , .true.  , 'yearly'  ,    ''    ,   ''     ,    ''
-   sn_depmin_isf ='rnfisf'    ,         -12       ,'sozisfmin',  .false.    , .true.  , 'yearly'  ,    ''    ,   ''     ,    ''
+   sn_depmax_isf ='rnfisf'   ,         -12.      ,'sozisfmax',  .false.    , .true.  , 'yearly'  ,    ''    ,   ''     ,    ''
+   sn_depmin_isf ='rnfisf'   ,         -12.      ,'sozisfmin',  .false.    , .true.  , 'yearly'  ,    ''    ,   ''     ,    ''
 !* nn_isf = 2 case
-   sn_Leff_isf = 'rnfisf'    ,         -12       ,'Leff'     ,  .false.    , .true.  , 'yearly'  ,    ''    ,   ''     ,    ''
+   sn_Leff_isf = 'rnfisf'    ,         -12.      ,'Leff'     ,  .false.    , .true.  , 'yearly'  ,    ''    ,   ''     ,    ''
 /
 !-----------------------------------------------------------------------
@@ -483,14 +487,14 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_cdg      =  'sdw_ecwaves_orca2'    ,        6          , 'drag_coeff' ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
-   sn_usd      =  'sdw_ecwaves_orca2'    ,        6          , 'u_sd2d'     ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
-   sn_vsd      =  'sdw_ecwaves_orca2'    ,        6          , 'v_sd2d'     ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
-   sn_hsw      =  'sdw_ecwaves_orca2'    ,        6          , 'hs'         ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
-   sn_wmp      =  'sdw_ecwaves_orca2'    ,        6          , 'wmp'        ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
-   sn_wfr      =  'sdw_ecwaves_orca2'    ,        6          , 'wfr'        ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
-   sn_wnum     =  'sdw_ecwaves_orca2'    ,        6          , 'wave_num'   ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
-   sn_tauwoc   =  'sdw_ecwaves_orca2'    ,        6          , 'wave_stress',  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
-   sn_tauwx    =  'sdw_ecwaves_orca2'    ,        6          , 'wave_stress',  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
-   sn_tauwy    =  'sdw_ecwaves_orca2'    ,        6          , 'wave_stress',  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_cdg      =  'sdw_ecwaves_orca2'    ,        6.         , 'drag_coeff' ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_usd      =  'sdw_ecwaves_orca2'    ,        6.         , 'u_sd2d'     ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_vsd      =  'sdw_ecwaves_orca2'    ,        6.         , 'v_sd2d'     ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_hsw      =  'sdw_ecwaves_orca2'    ,        6.         , 'hs'         ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_wmp      =  'sdw_ecwaves_orca2'    ,        6.         , 'wmp'        ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_wfr      =  'sdw_ecwaves_orca2'    ,        6.         , 'wfr'        ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_wnum     =  'sdw_ecwaves_orca2'    ,        6.         , 'wave_num'   ,  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_tauwoc   =  'sdw_ecwaves_orca2'    ,        6.         , 'wave_stress',  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_tauwx    =  'sdw_ecwaves_orca2'    ,        6.         , 'wave_stress',  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
+   sn_tauwy    =  'sdw_ecwaves_orca2'    ,        6.         , 'wave_stress',  .true.  , .true. , 'yearly'  ,  ''              , ''       , ''
 /
 !-----------------------------------------------------------------------
@@ -532,5 +536,5 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_icb     =  'calving'              ,         -1         ,'calvingmask',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_icb     =  'calving'              ,         -1.        ,'calvingmask',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
 /
 
@@ -598,37 +602,49 @@
    nn_ice_dta    =  0         !  = 0, bdy data are equal to the initial state
    !                          !  = 1, bdy data are read in 'bdydata   .nc' files
-   rn_ice_tem    = 270.       !  si3 only: arbitrary temperature of incoming sea ice
-   rn_ice_sal    = 10.        !  si3 only:      --   salinity           --
-   rn_ice_age    = 30.        !  si3 only:      --   age                --
    !
    ln_tra_dmp    =.false.     !  open boudaries conditions for tracers
    ln_dyn3d_dmp  =.false.     !  open boundary condition for baroclinic velocities
    rn_time_dmp   =  1.        !  Damping time scale in days
-   rn_time_dmp_out = 1.        !  Outflow damping time scale
+   rn_time_dmp_out = 1.       !  Outflow damping time scale
    nn_rimwidth   = 10         !  width of the relaxation zone
    ln_vol        = .false.    !  total volume correction (see nn_volctl parameter)
    nn_volctl     =  1         !  = 0, the total water flux across open boundaries is zero
-   nb_jpk_bdy    = -1         ! number of levels in the bdy data (set < 0 if consistent with planned run)
 /
 !-----------------------------------------------------------------------
 &nambdy_dta    !  open boundaries - external data                       (see nam_bdy)
 !-----------------------------------------------------------------------
-   ln_full_vel = .false.      !  ???
-
+   ln_zinterp  = .false.      !  T if a vertical interpolation is required. Variables gdep[tuv] and e3[tuv] must exist in the file
+   !                          !  automatically defined to T if the number of vertical levels in bdy dta /= jpk
+   ln_full_vel = .false.      !  T if [uv]3d are "full" velocities and not only its baroclinic components
+   !                          !  in this case, baroclinic and barotropic velocities will be recomputed -> [uv]2d not needed
+   !
    cn_dir      = 'bdydta/'    !  root directory for the BDY data location
    !___________!_________________________!___________________!___________!_____________!________!___________!__________________!__________!_______________!
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   bn_ssh      = 'amm12_bdyT_u2d'        ,         24        , 'sossheig',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
-   bn_u2d      = 'amm12_bdyU_u2d'        ,         24        , 'vobtcrtx',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
-   bn_v2d      = 'amm12_bdyV_u2d'        ,         24        , 'vobtcrty',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
-   bn_u3d      = 'amm12_bdyU_u3d'        ,         24        , 'vozocrtx',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
-   bn_v3d      = 'amm12_bdyV_u3d'        ,         24        , 'vomecrty',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
-   bn_tem      = 'amm12_bdyT_tra'        ,         24        , 'votemper',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
-   bn_sal      = 'amm12_bdyT_tra'        ,         24        , 'vosaline',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_ssh      = 'amm12_bdyT_u2d'        ,         24.       , 'sossheig',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_u2d      = 'amm12_bdyU_u2d'        ,         24.       , 'vobtcrtx',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_v2d      = 'amm12_bdyV_u2d'        ,         24.       , 'vobtcrty',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_u3d      = 'amm12_bdyU_u3d'        ,         24.       , 'vozocrtx',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_v3d      = 'amm12_bdyV_u3d'        ,         24.       , 'vomecrty',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_tem      = 'amm12_bdyT_tra'        ,         24.       , 'votemper',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_sal      = 'amm12_bdyT_tra'        ,         24.       , 'vosaline',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
 !* for si3
-!   bn_a_i     = 'amm12_bdyT_ice'        ,         24        , 'ileadfra',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
-!   bn_h_i     = 'amm12_bdyT_ice'        ,         24        , 'iicethic',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
-!   bn_h_s     = 'amm12_bdyT_ice'        ,         24        , 'isnowthi',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_a_i      = 'amm12_bdyT_ice'        ,         24.       , 'siconc'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_h_i      = 'amm12_bdyT_ice'        ,         24.       , 'sithic'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_h_s      = 'amm12_bdyT_ice'        ,         24.       , 'snthic'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_t_i      = 'NOT USED'              ,         24.       , 'sitemp'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_t_s      = 'NOT USED'              ,         24.       , 'sntemp'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_tsu      = 'NOT USED'              ,         24.       , 'sittop'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_s_i      = 'NOT USED'              ,         24.       , 'sisalt'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   ! melt ponds (be careful, bn_aip is the pond concentration (not fraction), so it differs from rn_iceapnd)
+   bn_aip      = 'NOT USED'              ,         24.       , 'siapnd'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_hip      = 'NOT USED'              ,         24.       , 'sihpnd'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   ! if bn_t_i etc are "not used", then define arbitrary temperatures and salinity and ponds
+   rn_ice_tem  = 270.         !  arbitrary temperature               of incoming sea ice
+   rn_ice_sal  = 10.          !       --   salinity                            --
+   rn_ice_age  = 30.          !       --   age                                 --
+   rn_ice_apnd = 0.2          !       --   pond fraction = a_ip/a_i            --
+   rn_ice_hpnd = 0.05         !       --   pond depth                          --
 /
 !-----------------------------------------------------------------------
@@ -944,18 +960,18 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_tem      = 'dyna_grid_T'           ,       120         , 'votemper'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_sal      = 'dyna_grid_T'           ,       120         , 'vosaline'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_mld      = 'dyna_grid_T'           ,       120         , 'somixhgt'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_emp      = 'dyna_grid_T'           ,       120         , 'sowaflup'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_fmf      = 'dyna_grid_T'           ,       120         , 'iowaflup'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_ice      = 'dyna_grid_T'           ,       120         , 'soicecov'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_qsr      = 'dyna_grid_T'           ,       120         , 'soshfldo'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_wnd      = 'dyna_grid_T'           ,       120         , 'sowindsp'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_uwd      = 'dyna_grid_U'           ,       120         , 'uocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_vwd      = 'dyna_grid_V'           ,       120         , 'vocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_wwd      = 'dyna_grid_W'           ,       120         , 'wocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_avt      = 'dyna_grid_W'           ,       120         , 'voddmavs'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_ubl      = 'dyna_grid_U'           ,       120         , 'sobblcox'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
-   sn_vbl      = 'dyna_grid_V'           ,       120         , 'sobblcoy'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_tem      = 'dyna_grid_T'           ,       120.        , 'votemper'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_sal      = 'dyna_grid_T'           ,       120.        , 'vosaline'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_mld      = 'dyna_grid_T'           ,       120.        , 'somixhgt'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_emp      = 'dyna_grid_T'           ,       120.        , 'sowaflup'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_fmf      = 'dyna_grid_T'           ,       120.        , 'iowaflup'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_ice      = 'dyna_grid_T'           ,       120.        , 'soicecov'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_qsr      = 'dyna_grid_T'           ,       120.        , 'soshfldo'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_wnd      = 'dyna_grid_T'           ,       120.        , 'sowindsp'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_uwd      = 'dyna_grid_U'           ,       120.        , 'uocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_vwd      = 'dyna_grid_V'           ,       120.        , 'vocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_wwd      = 'dyna_grid_W'           ,       120.        , 'wocetr_eff',  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_avt      = 'dyna_grid_W'           ,       120.        , 'voddmavs'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_ubl      = 'dyna_grid_U'           ,       120.        , 'sobblcox'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
+   sn_vbl      = 'dyna_grid_V'           ,       120.        , 'sobblcoy'  ,  .true.   , .true. , 'yearly'  , ''               , ''       , ''
 /
 
@@ -1102,7 +1118,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
@@ -1139,5 +1155,5 @@
 &namhsb        !  Heat and salt budgets                                 (default: OFF)
 !-----------------------------------------------------------------------
-   ln_diahsb   = .false.   !  check the heat and salt budgets (T) or not (F)
+   ln_diahsb   = .false.   !  output the heat and salt budgets (T) or not (F)
 /
 !-----------------------------------------------------------------------
@@ -1148,34 +1164,37 @@
 /
 !-----------------------------------------------------------------------
-&namflo        !   float parameters                                     ("key_float")
-!-----------------------------------------------------------------------
-   jpnfl       = 1         !  total number of floats during the run
-   jpnnewflo   = 0         !  number of floats for the restart
-   ln_rstflo   = .false.   !  float restart (T) or not (F)
-   nn_writefl  =      75   !  frequency of writing in float output file
-   nn_stockfl  =    5475   !  frequency of creation of the float restart file
-   ln_argo     = .false.   !  Argo type floats (stay at the surface each 10 days)
-   ln_flork4   = .false.   !  trajectories computed with a 4th order Runge-Kutta (T)
-   !                       !  or computed with Blanke' scheme (F)
-   ln_ariane   = .true.    !  Input with Ariane tool convention(T)
-   ln_flo_ascii = .true.    !  Output with Ariane tool netcdf convention(F) or ascii file (T)
-/
-!-----------------------------------------------------------------------
-&nam_diaharm   !   Harmonic analysis of tidal constituents              ("key_diaharm")
-!-----------------------------------------------------------------------
-    nit000_han = 1         ! First time step used for harmonic analysis
-    nitend_han = 75        ! Last time step used for harmonic analysis
-    nstep_han  = 15        ! Time step frequency for harmonic analysis
-    tname(1)   = 'M2'      ! Name of tidal constituents
-    tname(2)   = 'K1'
-/
-!-----------------------------------------------------------------------
-&namdct        ! transports through some sections                       ("key_diadct")
-!-----------------------------------------------------------------------
-    nn_dct     = 15        !  time step frequency for transports computing
-    nn_dctwri  = 15        !  time step frequency for transports writing
-    nn_secdebug = 112       !      0 : no section to debug
-    !                      !     -1 : debug all section
-    !                      !  0 < n : debug section number n
+&namflo        !   float parameters                                     (default: OFF)
+!-----------------------------------------------------------------------
+   ln_floats   = .false.      ! activate floats or not
+      jpnfl       = 1         !    total number of floats during the run
+      jpnnewflo   = 0         !    number of floats for the restart
+      ln_rstflo   = .false.   !    float restart (T) or not (F)
+      nn_writefl  =      75   !    frequency of writing in float output file
+      nn_stockfl  =    5475   !    frequency of creation of the float restart file
+      ln_argo     = .false.   !    Argo type floats (stay at the surface each 10 days)
+      ln_flork4   = .false.   !    trajectories computed with a 4th order Runge-Kutta (T)
+      !                       !    or computed with Blanke' scheme (F)
+      ln_ariane   = .true.    !    Input with Ariane tool convention(T)
+      ln_flo_ascii= .true.    !    Output with Ariane tool netcdf convention(F) or ascii file (T)
+/
+!-----------------------------------------------------------------------
+&nam_diaharm   !   Harmonic analysis of tidal constituents              (default: OFF)
+!-----------------------------------------------------------------------
+    ln_diaharm = .false.   ! Choose tidal harmonic output or not
+       nit000_han = 1      !    First time step used for harmonic analysis
+       nitend_han = 75     !    Last time step used for harmonic analysis
+       nstep_han  = 15     !    Time step frequency for harmonic analysis
+       tname(1)   = 'M2'   !    Name of tidal constituents
+       tname(2)   = 'K1'   !              ---
+/
+!-----------------------------------------------------------------------
+&nam_diadct    !   transports through some sections                     (default: OFF)
+!-----------------------------------------------------------------------
+    ln_diadct  = .false.   ! Calculate transport thru sections or not
+       nn_dct     = 15     !  time step frequency for transports computing
+       nn_dctwri  = 15     !  time step frequency for transports writing
+       nn_secdebug = 112   !      0 : no section to debug
+       !                   !     -1 : debug all section
+       !                   !  0 < n : debug section number n
 /
 !-----------------------------------------------------------------------
@@ -1295,10 +1314,9 @@
 &nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi")
 !-----------------------------------------------------------------------
-   cn_mpi_send =  'I'      !  mpi send/recieve type   ='S', 'B', or 'I' for standard send,
-   !                       !  buffer blocking send or immediate non-blocking sends, resp.
-   nn_buffer   =   0       !  size in bytes of exported buffer ('B' case), 0 no exportation
+   ln_listonly =  .false.  !  do nothing else than listing the best domain decompositions (with land domains suppression)
+   !                       !  if T: the largest number of cores tested is defined by max(mppsize, jpni*jpnj)
    ln_nnogather =  .true.  !  activate code to avoid mpi_allgather use at the northfold
-   jpni        =   0       !  jpni   number of processors following i (set automatically if < 1)
-   jpnj        =   0       !  jpnj   number of processors following j (set automatically if < 1)
+   jpni        =   0       !  number of processors following i (set automatically if < 1), see also ln_listonly = T
+   jpnj        =   0       !  number of processors following j (set automatically if < 1), see also ln_listonly = T
 /
 !-----------------------------------------------------------------------
Index: /NEMO/trunk/cfgs/SHARED/namelist_top_ref
===================================================================
--- /NEMO/trunk/cfgs/SHARED/namelist_top_ref	(revision 11535)
+++ /NEMO/trunk/cfgs/SHARED/namelist_top_ref	(revision 11536)
@@ -59,5 +59,5 @@
 !                !  file name        ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
 !                !                   !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_trcdta(1)  = 'data_TRC_nomask' ,        -12        ,  'TRC'    ,    .false.   , .true. , 'yearly'  , ''       , ''       , ''
+   sn_trcdta(1)  = 'data_TRC_nomask' ,        -12.       ,  'TRC'    ,    .false.   , .true. , 'yearly'  , ''       , ''       , ''
    !
    cn_dir        =  './'     !  root directory for the location of the data files
Index: /NEMO/trunk/cfgs/SPITZ12/EXPREF/file_def_nemo-ice.xml
===================================================================
--- /NEMO/trunk/cfgs/SPITZ12/EXPREF/file_def_nemo-ice.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/SPITZ12/EXPREF/file_def_nemo-ice.xml	(revision 11536)
@@ -93,25 +93,25 @@
      <file id="file22" name_suffix="_SBC_scalar" description="scalar variables" enabled=".true." >
        <!-- global contents -->
-       <field field_ref="ibgvol_tot"     grid_ref="grid_1point"   name="ibgvol_tot"   />
-       <field field_ref="sbgvol_tot"     grid_ref="grid_1point"   name="sbgvol_tot"   />
-       <field field_ref="ibgarea_tot"    grid_ref="grid_1point"   name="ibgarea_tot"  />
-       <field field_ref="ibgsalt_tot"    grid_ref="grid_1point"   name="ibgsalt_tot"  />
-       <field field_ref="ibgheat_tot"    grid_ref="grid_1point"   name="ibgheat_tot"  />
-       <field field_ref="sbgheat_tot"    grid_ref="grid_1point"   name="sbgheat_tot"  />
+       <field field_ref="ibgvol_tot"     name="ibgvol_tot"   />
+       <field field_ref="sbgvol_tot"     name="sbgvol_tot"   />
+       <field field_ref="ibgarea_tot"    name="ibgarea_tot"  />
+       <field field_ref="ibgsalt_tot"    name="ibgsalt_tot"  />
+       <field field_ref="ibgheat_tot"    name="ibgheat_tot"  />
+       <field field_ref="sbgheat_tot"    name="sbgheat_tot"  />
        
        <!-- global drifts (conservation checks) -->
-       <field field_ref="ibgvolume"      grid_ref="grid_1point"   name="ibgvolume"    />
-       <field field_ref="ibgsaltco"      grid_ref="grid_1point"   name="ibgsaltco"    />
-       <field field_ref="ibgheatco"      grid_ref="grid_1point"   name="ibgheatco"    />
-       <field field_ref="ibgheatfx"      grid_ref="grid_1point"   name="ibgheatfx"    />
+       <field field_ref="ibgvolume"      name="ibgvolume"    />
+       <field field_ref="ibgsaltco"      name="ibgsaltco"    />
+       <field field_ref="ibgheatco"      name="ibgheatco"    />
+       <field field_ref="ibgheatfx"      name="ibgheatfx"    />
        
        <!-- global forcings  -->
-       <field field_ref="ibgfrcvoltop"   grid_ref="grid_1point"   name="ibgfrcvoltop" />
-       <field field_ref="ibgfrcvolbot"   grid_ref="grid_1point"   name="ibgfrcvolbot" />
-       <field field_ref="ibgfrctemtop"   grid_ref="grid_1point"   name="ibgfrctemtop" />
-       <field field_ref="ibgfrctembot"   grid_ref="grid_1point"   name="ibgfrctembot" />
-       <field field_ref="ibgfrcsal"      grid_ref="grid_1point"   name="ibgfrcsal"    />
-       <field field_ref="ibgfrchfxtop"   grid_ref="grid_1point"   name="ibgfrchfxtop" />
-       <field field_ref="ibgfrchfxbot"   grid_ref="grid_1point"   name="ibgfrchfxbot" />
+       <field field_ref="ibgfrcvoltop"   name="ibgfrcvoltop" />
+       <field field_ref="ibgfrcvolbot"   name="ibgfrcvolbot" />
+       <field field_ref="ibgfrctemtop"   name="ibgfrctemtop" />
+       <field field_ref="ibgfrctembot"   name="ibgfrctembot" />
+       <field field_ref="ibgfrcsal"      name="ibgfrcsal"    />
+       <field field_ref="ibgfrchfxtop"   name="ibgfrchfxtop" />
+       <field field_ref="ibgfrchfxbot"   name="ibgfrchfxbot" />
      </file>
      
Index: /NEMO/trunk/cfgs/SPITZ12/EXPREF/file_def_nemo-oce.xml
===================================================================
--- /NEMO/trunk/cfgs/SPITZ12/EXPREF/file_def_nemo-oce.xml	(revision 11535)
+++ /NEMO/trunk/cfgs/SPITZ12/EXPREF/file_def_nemo-oce.xml	(revision 11536)
@@ -81,17 +81,17 @@
         <file id="file15" name_suffix="_scalar" description="scalar variables" >
           <!-- global drifts (conservation checks) -->
-          <field field_ref="bgtemper"     grid_ref="grid_1point"   name="bgtemper"    />
-          <field field_ref="bgsaline"     grid_ref="grid_1point"   name="bgsaline"    />
-          <field field_ref="bgheatco"     grid_ref="grid_1point"   name="bgheatco"    />
-          <field field_ref="bgheatfx"     grid_ref="grid_1point"   name="bgheatfx"    />
-          <field field_ref="bgsaltco"     grid_ref="grid_1point"   name="bgsaltco"    />
-          <field field_ref="bgvolssh"     grid_ref="grid_1point"   name="bgvolssh"    />
-          <field field_ref="bgvole3t"     grid_ref="grid_1point"   name="bgvole3t"    />
+          <field field_ref="bgtemper"     name="bgtemper"    />
+          <field field_ref="bgsaline"     name="bgsaline"    />
+          <field field_ref="bgheatco"     name="bgheatco"    />
+          <field field_ref="bgheatfx"     name="bgheatfx"    />
+          <field field_ref="bgsaltco"     name="bgsaltco"    />
+          <field field_ref="bgvolssh"     name="bgvolssh"    />
+          <field field_ref="bgvole3t"     name="bgvole3t"    />
 
           <!-- global surface forcings  -->
-          <field field_ref="bgfrcvol"     grid_ref="grid_1point"   name="bgfrcvol"    />
-          <field field_ref="bgfrctem"     grid_ref="grid_1point"   name="bgfrctem"    />
-          <field field_ref="bgfrchfx"     grid_ref="grid_1point"   name="bgfrchfx"    />
-          <field field_ref="bgfrcsal"     grid_ref="grid_1point"   name="bgfrcsal"    />
+          <field field_ref="bgfrcvol"     name="bgfrcvol"    />
+          <field field_ref="bgfrctem"     name="bgfrctem"    />
+          <field field_ref="bgfrchfx"     name="bgfrchfx"    />
+          <field field_ref="bgfrcsal"     name="bgfrcsal"    />
         </file>
 
Index: /NEMO/trunk/cfgs/SPITZ12/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/SPITZ12/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/SPITZ12/EXPREF/namelist_cfg	(revision 11536)
@@ -47,6 +47,6 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
-   sn_tem    = 'T_SPITZ12'   ,  24           ,'votemper',    .false.   , .false., 'daily'   , ''      , '' ,    ''
-   sn_sal    = 'S_SPITZ12'   ,  24           ,'vosaline',    .false.   , .false., 'daily'   , ''      , '' ,    ''
+   sn_tem    = 'T_SPITZ12'   ,  24.          ,'votemper',    .false.   , .false., 'daily'   , ''      , '' ,    ''
+   sn_sal    = 'S_SPITZ12'   ,  24.          ,'vosaline',    .false.   , .false., 'daily'   , ''      , '' ,    ''
 /
 !!======================================================================
@@ -98,14 +98,14 @@
    !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ !          weights filename            ! rotation ! land/sea mask !
    !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                                      ! pairing  !    filename   !
-   sn_wndi     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,   2 ,  'u10'     ,   .true.    , .false. , 'yearly'  , 'weights_bicub', 'Uwnd' , ''
-   sn_wndj     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,   2 ,  'v10'     ,   .true.    , .false. , 'yearly'  , 'weights_bicub', 'Vwnd' , ''
-   sn_qsr      = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,   2 ,  'ssrd'    ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
-   sn_qlw      = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,   2 ,  'strd'    ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
-   sn_tair     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,   2 ,  't10'     ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
-   sn_humi     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,   2 ,  'humi'    ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
-   sn_prec     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,   2 ,  'precip'  ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
-   sn_snow     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,   2 ,  'snow'    ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
-   sn_slp      = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,   2 ,  'slp'     ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
-   sn_tdif     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,   2 ,  'tdif'    ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
+   sn_wndi     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,  2. ,  'u10'     ,   .true.    , .false. , 'yearly'  , 'weights_bicub', 'Uwnd' , ''
+   sn_wndj     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,  2. ,  'v10'     ,   .true.    , .false. , 'yearly'  , 'weights_bicub', 'Vwnd' , ''
+   sn_qsr      = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,  2. ,  'ssrd'    ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
+   sn_qlw      = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,  2. ,  'strd'    ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
+   sn_tair     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,  2. ,  't10'     ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
+   sn_humi     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,  2. ,  'humi'    ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
+   sn_prec     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,  2. ,  'precip'  ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
+   sn_snow     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,  2. ,  'snow'    ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
+   sn_slp      = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,  2. ,  'slp'     ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
+   sn_tdif     = 'MARv3.6-9km-Svalbard-2hourly_spitz' ,  2. ,  'tdif'    ,   .true.    , .false. , 'yearly'  , 'weights_bilin', '' , ''
 /
 !-----------------------------------------------------------------------
@@ -171,30 +171,28 @@
    nn_ice_dta    =  1         !  = 0, bdy data are equal to the initial state
    !                          !  = 1, bdy data are read in 'bdydata   .nc' files
-   rn_ice_tem    = 267.       !  si3 only: arbitrary temperature of incoming sea ice
-   rn_ice_sal    =   6.       !  si3 only:      --   salinity           --
-   rn_ice_age    = 365.       !  si3 only:      --   age                --
-   !
    nn_rimwidth   = 1          !  width of the relaxation zone
    ln_vol        = .false.    !  total volume correction (see nn_volctl parameter)
-   nb_jpk_bdy    = -1         ! number of levels in the bdy data (set < 0 if consistent with planned run)
 /
 !-----------------------------------------------------------------------
 &nambdy_dta    !  open boundaries - external data                       (see nam_bdy)
 !-----------------------------------------------------------------------
-   ln_full_vel = .false.      !  ???
-
+   ln_zinterp  = .false.      !  T if a vertical interpolation is required. Variables gdep[tuv] and e3[tuv] must exist in the file
+   !                          !  automatically defined to T if the number of vertical levels in bdy dta /= jpk
+   ln_full_vel = .false.      !  T if [uv]3d are "full" velocities and not only its baroclinic components
+   !                          !  in this case, baroclinic and barotropic velocities will be recomputed -> [uv]2d not needed
+   !
    cn_dir  =  './'
 !              !  file name      ! frequency (hours) ! variable  ! time interp. !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
 !              !                 !  (if <0  months)  !   name    !  (logical)   !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
-   bn_ssh =   'bdyT_u2d_grid12' ,         72       , 'sossheig' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
-   bn_u2d =   'bdyU_u2d_grid12' ,         72       , 'vobtcrtx' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
-   bn_v2d =   'bdyV_u2d_grid12' ,         72       , 'vobtcrty' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
-   bn_u3d  =  'bdyU_u3d_grid12' ,         72       , 'vozocrtx' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
-   bn_v3d  =  'bdyV_u3d_grid12' ,         72       , 'vomecrty' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
-   bn_tem  =  'bdyT_tem_grid12' ,         72       , 'votemper' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
-   bn_sal  =  'bdyT_sal_grid12' ,         72       , 'vosaline' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
-   bn_a_i  =  'bdyT_ice_grid12' ,         72       , 'ileadfra' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
-   bn_h_i  =  'bdyT_ice_grid12' ,         72       , 'iicethic' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
-   bn_h_s  =  'bdyT_ice_grid12' ,         72       , 'isnowthi' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
+   bn_ssh =   'bdyT_u2d_grid12' ,         72.      , 'sossheig' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
+   bn_u2d =   'bdyU_u2d_grid12' ,         72.      , 'vobtcrtx' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
+   bn_v2d =   'bdyV_u2d_grid12' ,         72.      , 'vobtcrty' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
+   bn_u3d  =  'bdyU_u3d_grid12' ,         72.      , 'vozocrtx' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
+   bn_v3d  =  'bdyV_u3d_grid12' ,         72.      , 'vomecrty' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
+   bn_tem  =  'bdyT_tem_grid12' ,         72.      , 'votemper' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
+   bn_sal  =  'bdyT_sal_grid12' ,         72.      , 'vosaline' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
+   bn_a_i  =  'bdyT_ice_grid12' ,         72.      , 'ileadfra' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
+   bn_h_i  =  'bdyT_ice_grid12' ,         72.      , 'iicethic' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
+   bn_h_s  =  'bdyT_ice_grid12' ,         72.      , 'isnowthi' ,     .true.     , .false. ,  'yearly'  ,    ''    ,   ''   , ''
 /
 !-----------------------------------------------------------------------
@@ -350,7 +348,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/cfgs/SPITZ12/EXPREF/namelist_ice_cfg
===================================================================
--- /NEMO/trunk/cfgs/SPITZ12/EXPREF/namelist_ice_cfg	(revision 11535)
+++ /NEMO/trunk/cfgs/SPITZ12/EXPREF/namelist_ice_cfg	(revision 11536)
@@ -80,6 +80,7 @@
 &namthd_pnd     !   Melt ponds
 !------------------------------------------------------------------------------
-   ln_pnd_H12       = .true.          !  activate evolutive melt ponds (from Holland et al 2012)
-   ln_pnd_alb       = .true.          !  melt ponds affect albedo or not
+   ln_pnd           = .true.          !  activate melt ponds or not
+     ln_pnd_H12     = .true.          !  activate evolutive melt ponds (from Holland et al 2012)
+     ln_pnd_alb     = .true.          !  melt ponds affect albedo or not
 /
 
Index: /NEMO/trunk/doc/latex/NEMO/subfiles/chap_DIA.tex
===================================================================
--- /NEMO/trunk/doc/latex/NEMO/subfiles/chap_DIA.tex	(revision 11535)
+++ /NEMO/trunk/doc/latex/NEMO/subfiles/chap_DIA.tex	(revision 11536)
@@ -1668,7 +1668,7 @@
 \label{sec:DIA_diag_dct}
 
-%------------------------------------------namdct----------------------------------------------------
-
-\nlst{namdct}
+%------------------------------------------nam_diadct----------------------------------------------------
+
+\nlst{nam_diadct}
 %-------------------------------------------------------------------------------------------------------------
 
@@ -1689,5 +1689,5 @@
 - \texttt{salt\_transport}   for   salt transports (unit: $10^{9}Kg s^{-1}$) \\
 
-Namelist variables in \nam{dct} control how frequently the flows are summed and the time scales over which
+Namelist variables in \nam{\_diadct} control how frequently the flows are summed and the time scales over which
 they are averaged, as well as the level of output for debugging:
 \np{nn\_dct}   : frequency of instantaneous transports computing
Index: /NEMO/trunk/doc/latex/NEMO/subfiles/chap_LBC.tex
===================================================================
--- /NEMO/trunk/doc/latex/NEMO/subfiles/chap_LBC.tex	(revision 11535)
+++ /NEMO/trunk/doc/latex/NEMO/subfiles/chap_LBC.tex	(revision 11536)
@@ -20,5 +20,5 @@
 {Boundary condition at the coast (\protect\np{rn\_shlat})}
 \label{sec:LBC_coast}
-%--------------------------------------------nam_lbc-------------------------------------------------------
+%--------------------------------------------namlbc-------------------------------------------------------
 
 \nlst{namlbc}
@@ -113,5 +113,5 @@
 \begin{description}
 
-\item[free-slip boundary condition (\np{rn\_shlat}\forcode{ = 0}):] the tangential velocity at
+\item[free-slip boundary condition (\np{rn\_shlat}\forcode{=0}):] the tangential velocity at
   the coastline is equal to the offshore velocity,
   \ie\ the normal derivative of the tangential velocity is zero at the coast,
@@ -119,5 +119,5 @@
   (\autoref{fig:LBC_shlat}-a).
 
-\item[no-slip boundary condition (\np{rn\_shlat}\forcode{ = 2}):] the tangential velocity vanishes at the coastline.
+\item[no-slip boundary condition (\np{rn\_shlat}\forcode{=2}):] the tangential velocity vanishes at the coastline.
   Assuming that the tangential velocity decreases linearly from
   the closest ocean velocity grid point to the coastline,
@@ -251,20 +251,10 @@
 \label{sec:LBC_mpp}
 
-For massively parallel processing (mpp), a domain decomposition method is used.
-The basic idea of the method is to split the large computation domain of a numerical experiment into
-several smaller domains and solve the set of equations by addressing independent local problems.
-Each processor has its own local memory and computes the model equation over a subdomain of the whole model domain.
-The subdomain boundary conditions are specified through communications between processors which
-are organized by explicit statements (message passing method).
-
-A big advantage is that the method does not need many modifications of the initial \fortran code.
-From the modeller's point of view, each sub domain running on a processor is identical to the "mono-domain" code.
-In addition, the programmer manages the communications between subdomains,
-and the code is faster when the number of processors is increased.
-The porting of OPA code on an iPSC860 was achieved during Guyon's PhD [Guyon et al. 1994, 1995]
-in collaboration with CETIIS and ONERA.
-The implementation in the operational context and the studies of performance on
-a T3D and T3E Cray computers have been made in collaboration with IDRIS and CNRS.
-The present implementation is largely inspired by Guyon's work [Guyon 1995].
+%-----------------------------------------nammpp--------------------------------------------
+
+\nlst{nammpp}
+%-----------------------------------------------------------------------------------------------
+
+For massively parallel processing (mpp), a domain decomposition method is used. The basic idea of the method is to split the large computation domain of a numerical experiment into several smaller domains and solve the set of equations by addressing independent local problems. Each processor has its own local memory and computes the model equation over a subdomain of the whole model domain. The subdomain boundary conditions are specified through communications between processors which are organized by explicit statements (message passing method). The present implementation is largely inspired by Guyon's work [Guyon 1995].
 
 The parallelization strategy is defined by the physical characteristics of the ocean model.
@@ -272,7 +262,5 @@
 depend at the very most on one neighbouring point.
 The only non-local computations concern the vertical physics
-(implicit diffusion, turbulent closure scheme, ...) (delocalization over the whole water column),
-and the solving of the elliptic equation associated with the surface pressure gradient computation
-(delocalization over the whole horizontal domain).
+(implicit diffusion, turbulent closure scheme, ...).
 Therefore, a pencil strategy is used for the data sub-structuration:
 the 3D initial domain is laid out on local processor memories following a 2D horizontal topological splitting.
@@ -284,12 +272,11 @@
 each processor sends to its neighbouring processors the update values of the points corresponding to
 the interior overlapping area to its neighbouring sub-domain (\ie\ the innermost of the two overlapping rows).
-The communication is done through the Message Passing Interface (MPI).
+Communications are first done according to the east-west direction and next according to the north-south direction. There is no specific communications for the corners. The communication is done through the Message Passing Interface (MPI) and requires \key{mpp\_mpi}. Use also \key{mpi2} if MPI3 is not available on your computer.
 The data exchanges between processors are required at the very place where
 lateral domain boundary conditions are set in the mono-domain computation:
 the \rou{lbc\_lnk} routine (found in \mdl{lbclnk} module) which manages such conditions is interfaced with
-routines found in \mdl{lib\_mpp} module when running on an MPP computer (\ie\ when \key{mpp\_mpi} defined).
-It has to be pointed out that when using the MPP version of the model,
-the east-west cyclic boundary condition is done implicitly,
-whilst the south-symmetric boundary condition option is not available.
+routines found in \mdl{lib\_mpp} module.
+The output file \textit{communication\_report.txt} provides the list of which routines do how
+many communications during 1 time step of the model.\\
 
 %>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -305,24 +292,17 @@
 %>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 
-In the standard version of \NEMO, the splitting is regular and arithmetic.
-The i-axis is divided by \jp{jpni} and
-the j-axis by \jp{jpnj} for a number of processors \jp{jpnij} most often equal to $jpni \times jpnj$
-(parameters set in  \nam{mpp} namelist).
-Each processor is independent and without message passing or synchronous process,
-programs run alone and access just its own local memory.
-For this reason, the main model dimensions are now the local dimensions of the subdomain (pencil) that
-are named \jp{jpi}, \jp{jpj}, \jp{jpk}.
-These dimensions include the internal domain and the overlapping rows.
-The number of rows to exchange (known as the halo) is usually set to one (\jp{jpreci}=1, in \mdl{par\_oce}).
-The whole domain dimensions are named \jp{jpiglo}, \jp{jpjglo} and \jp{jpk}.
-The relationship between the whole domain and a sub-domain is:
-\[
-  jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci
-  jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj
-\]
-where \jp{jpni}, \jp{jpnj} are the number of processors following the i- and j-axis.
-
-One also defines variables nldi and nlei which correspond to the internal domain bounds,
-and the variables nimpp and njmpp which are the position of the (1,1) grid-point in the global domain.
+In \NEMO, the splitting is regular and arithmetic. The total number of subdomains corresponds to the number of MPI processes allocated to \NEMO\ when the model is launched (\ie\ mpirun -np x ./nemo will automatically give x subdomains). The i-axis is divided by \np{jpni} and the j-axis by \np{jpnj}. These parameters are defined in \nam{mpp} namelist. If \np{jpni} and \np{jpnj} are < 1, they will be automatically redefined in the code to give the best domain decomposition (see bellow).
+
+Each processor is independent and without message passing or synchronous process, programs run alone and access just its own local memory. For this reason, the main model dimensions are now the local dimensions of the subdomain (pencil) that are named \jp{jpi}, \jp{jpj}, \jp{jpk}.
+These dimensions include the internal domain and the overlapping rows. The number of rows to exchange (known as the halo) is usually set to one (nn\_hls=1, in \mdl{par\_oce}, and must be kept to one until further notice). The whole domain dimensions are named \jp{jpiglo}, \jp{jpjglo} and \jp{jpk}. The relationship between the whole domain and a sub-domain is:
+\[
+  jpi = ( jpiglo-2\times nn\_hls + (jpni-1) ) / jpni + 2\times nn\_hls
+\]
+\[
+  jpj = ( jpjglo-2\times nn\_hls + (jpnj-1) ) / jpnj + 2\times nn\_hls
+\]
+
+One also defines variables nldi and nlei which correspond to the internal domain bounds, and the variables nimpp and njmpp which are the position of the (1,1) grid-point in the global domain (\autoref{fig:mpp}). Note that since the version 4, there is no more extra-halo area as defined in \autoref{fig:mpp} so \jp{jpi} is now always equal to nlci and \jp{jpj} equal to nlcj.
+
 An element of $T_{l}$, a local array (subdomain) corresponds to an element of $T_{g}$,
 a global array (whole domain) by the relationship:
@@ -331,45 +311,20 @@
   T_{g} (i+nimpp-1,j+njmpp-1,k) = T_{l} (i,j,k),
 \]
-with  $1 \leq i \leq jpi$, $1  \leq j \leq jpj $ , and  $1  \leq k \leq jpk$.
-
-Processors are numbered from 0 to $jpnij-1$, the number is saved in the variable nproc.
-In the standard version, a processor has no more than
-four neighbouring processors named nono (for north), noea (east), noso (south) and nowe (west) and
-two variables, nbondi and nbondj, indicate the relative position of the processor:
-\begin{itemize}
-\item 		nbondi = -1 	an east neighbour, no west processor,
-\item 		nbondi =  0	an east neighbour, a west neighbour,
-\item 		nbondi =  1 	no east processor, a west neighbour,
-\item 		nbondi =  2 	no splitting following the i-axis.
-\end{itemize}
-During the simulation, processors exchange data with their neighbours.
-If there is effectively a neighbour, the processor receives variables from this processor on its overlapping row,
-and sends the data issued from internal domain corresponding to the overlapping row of the other processor.
-
-
-The \NEMO\ model computes equation terms with the help of mask arrays (0 on land points and 1 on sea points).
-It is easily readable and very efficient in the context of a computer with vectorial architecture.
-However, in the case of a scalar processor, computations over the land regions become more expensive in
-terms of CPU time.
-It is worse when we use a complex configuration with a realistic bathymetry like the global ocean where
-more than 50 \% of points are land points.
-For this reason, a pre-processing tool can be used to choose the mpp domain decomposition with a maximum number of
-only land points processors, which can then be eliminated (\autoref{fig:mppini2})
-(For example, the mpp\_optimiz tools, available from the DRAKKAR web site).
-This optimisation is dependent on the specific bathymetry employed.
-The user then chooses optimal parameters \jp{jpni}, \jp{jpnj} and \jp{jpnij} with $jpnij < jpni \times jpnj$,
-leading to the elimination of $jpni \times jpnj - jpnij$ land processors.
-When those parameters are specified in \nam{mpp} namelist,
-the algorithm in the \rou{inimpp2} routine sets each processor's parameters (nbound, nono, noea,...) so that
-the land-only processors are not taken into account.
-
-\gmcomment{Note that the inimpp2 routine is general so that the original inimpp
-routine should be suppressed from the code.}
-
-When land processors are eliminated,
-the value corresponding to these locations in the model output files is undefined.
-Note that this is a problem for the meshmask file which requires to be defined over the whole domain.
-Therefore, user should not eliminate land processors when creating a meshmask file
-(\ie\ when setting a non-zero value to \np{nn\_msh}).
+with $1 \leq i \leq jpi$, $1  \leq j \leq jpj $ , and  $1  \leq k \leq jpk$.
+
+The 1-d arrays $mig(1:\jp{jpi})$ and $mjg(1:\jp{jpj})$, defined in \rou{dom\_glo} routine (\mdl{domain} module), should be used to get global domain indices from local domain indices. The 1-d arrays, $mi0(1:\jp{jpiglo})$, $mi1(1:\jp{jpiglo})$ and $mj0(1:\jp{jpjglo})$, $mj1(1:\jp{jpjglo})$ have the reverse purpose and should be used to define loop indices expressed in global domain indices (see examples in \mdl{dtastd} module).\\
+
+The \NEMO\ model computes equation terms with the help of mask arrays (0 on land points and 1 on sea points). It is therefore possible that an MPI subdomain contains only land points. To save ressources, we try to supress from the computational domain as much land subdomains as possible. For example if $N_{mpi}$ processes are allocated to NEMO, the domain decomposition will be given by the following equation:
+\[
+  N_{mpi} = jpni \times jpnj - N_{land} + N_{useless}
+\]
+$N_{land}$ is the total number of land subdomains in the domain decomposition defined by \np{jpni} and \np{jpnj}. $N_{useless}$ is the number of land subdomains that are kept in the compuational domain in order to make sure that $N_{mpi}$ MPI processes are indeed allocated to a given subdomain. The values of $N_{mpi}$, \np{jpni}, \np{jpnj},  $N_{land}$ and $N_{useless}$ are printed in the output file \texttt{ocean.output}. $N_{useless}$ must, of course, be as small as possible to limit the waste of ressources. A warning is issued in  \texttt{ocean.output} if $N_{useless}$ is not zero. Note that non-zero value of $N_{useless}$ is uselly required when using AGRIF as, up to now, the parent grid and each of the child grids must use all the $N_{mpi}$ processes.
+
+If the domain decomposition is automatically defined (when \np{jpni} and \np{jpnj} are < 1), the decomposition chosen by the model will minimise the sub-domain size (defined as $max_{all domains}(jpi \times jpj)$) and maximize the number of eliminated land subdomains. This means that no other domain decomposition (a set of \np{jpni} and \np{jpnj} values) will use less processes than $(jpni  \times  jpnj - N_{land})$ and get a smaller subdomain size.
+In order to specify $N_{mpi}$ properly (minimize $N_{useless}$), you must run the model once with \np{ln\_list} activated. In this case, the model will start the initialisation phase, print the list of optimum decompositions ($N_{mpi}$, \np{jpni} and \np{jpnj}) in \texttt{ocean.output} and directly abort. The maximum value of $N_{mpi}$ tested in this list is given by $max(N_{MPI\_tasks}, \np{jpni} \times \np{jpnj})$. For example, run the model on 40 nodes with ln\_list activated and $\np{jpni} = 10000$ and $\np{jpnj} = 1$, will print the list of optimum domains decomposition from 1 to about 10000. 
+
+Processors are numbered from 0 to $N_{mpi} - 1$. Subdomains containning some ocean points are numbered first from 0 to $jpni * jpnj - N_{land} -1$. The remaining $N_{useless}$ land subdomains are numbered next, which means that, for a given (\np{jpni}, \np{jpnj}), the numbers attributed to he ocean subdomains do not vary with $N_{useless}$. 
+
+When land processors are eliminated, the value corresponding to these locations in the model output files is undefined. \np{ln\_mskland} must be activated in order avoid Not a Number values in output files. Note that it is better to not eliminate land processors when creating a meshmask file (\ie\ when setting a non-zero value to \np{nn\_msh}).
 
 %>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -406,7 +361,7 @@
 %-----------------------------------------------------------------------------------------------
 
-Options are defined through the \nam{bdy} \nam{bdy\_dta} namelist variables.
+Options are defined through the \nam{bdy} and \nam{bdy\_dta} namelist variables.
 The BDY module is the core implementation of open boundary conditions for regional configurations on
-temperature, salinity, barotropic and baroclinic velocities, as well as ice concentration, ice and snow thicknesses.
+ocean temperature, salinity, barotropic-baroclinic velocities, ice-snow concentration, thicknesses, temperatures, salinity and melt ponds concentration and thickness.
 
 The BDY module was modelled on the OBC module (see \NEMO\ 3.4) and shares many features and
@@ -421,21 +376,18 @@
 \label{subsec:BDY_namelist}
 
-The BDY module is activated by setting \np{ln\_bdy}\forcode{ = .true.} .
+The BDY module is activated by setting \np{ln\_bdy}\forcode{=.true.} .
 It is possible to define more than one boundary ``set'' and apply different boundary conditions to each set.
 The number of boundary sets is defined by \np{nb\_bdy}.
-Each boundary set may be defined as a set of straight line segments in a namelist
-(\np{ln\_coords\_file}\forcode{ = .false.}) or read in from a file (\np{ln\_coords\_file}\forcode{ = .true.}).
-If the set is defined in a namelist, then the namelists \nam{bdy\_index} must be included separately, one for each set.
-If the set is defined by a file, then a ``\ifile{coordinates.bdy}'' file must be provided.
+Each boundary set can be either defined as a series of straight line segments directly in the namelist
+(\np{ln\_coords\_file}\forcode{=.false.}, and a namelist block \nam{bdy\_index} must be included for each set) or read in from a file (\np{ln\_coords\_file}\forcode{=.true.}, and a ``\ifile{coordinates.bdy}'' file must be provided).
 The coordinates.bdy file is analagous to the usual \NEMO\ ``\ifile{coordinates}'' file.
 In the example above, there are two boundary sets, the first of which is defined via a file and
-the second is defined in a namelist.
+the second is defined in the namelist.
 For more details of the definition of the boundary geometry see section \autoref{subsec:BDY_geometry}.
 
 For each boundary set a boundary condition has to be chosen for the barotropic solution
 (``u2d'':sea-surface height and barotropic velocities), for the baroclinic velocities (``u3d''),
-for the active tracers \footnote{The BDY module does not deal with passive tracers at this version} (``tra''), and sea-ice (``ice'').
-For each set of variables there is a choice of algorithm and a choice for the data,
-eg. for the active tracers the algorithm is set by \np{cn\_tra} and the choice of data is set by \np{nn\_tra\_dta}.\\
+for the active tracers \footnote{The BDY module does not deal with passive tracers at this version} (``tra''), and for sea-ice (``ice'').
+For each set of variables one has to choose an algorithm and the boundary data (set resp. by \np{cn\_tra} and \np{nn\_tra\_dta} for tracers).\\
 
 The choice of algorithm is currently as follows:
@@ -452,11 +404,11 @@
 \end{description}
 
-The main choice for the boundary data is to use initial conditions as boundary data
-(\np{nn\_tra\_dta}\forcode{ = 0}) or to use external data from a file (\np{nn\_tra\_dta}\forcode{ = 1}).
+The boundary data is either set to initial conditions
+(\np{nn\_tra\_dta}\forcode{=0}) or forced with external data from a file (\np{nn\_tra\_dta}\forcode{=1}).
 In case the 3d velocity data contain the total velocity (ie, baroclinic and barotropic velocity),
-the bdy code can derived baroclinic and barotropic velocities by setting \np{ln\_full\_vel}\forcode{ = .true. }
+the bdy code can derived baroclinic and barotropic velocities by setting \np{ln\_full\_vel}\forcode{=.true.}
 For the barotropic solution there is also the option to use tidal harmonic forcing either by
-itself (\np{nn\_dyn2d\_dta}\forcode{ = 2}) or in addition to other external data (\np{nn\_dyn2d\_dta}\forcode{ = 3}).\\
-Sea-ice salinity, temperature and age data at the boundary are constant and defined repectively by \np{rn\_ice\_sal}, \np{rn\_ice\_tem} and \np{rn\_ice\_age}.
+itself (\np{nn\_dyn2d\_dta}\forcode{=2}) or in addition to other external data (\np{nn\_dyn2d\_dta}\forcode{=3}).\\
+If not set to initial conditions, sea-ice salinity, temperatures and melt ponds data at the boundary can either be read in a file or defined as constant (by \np{rn\_ice\_sal}, \np{rn\_ice\_tem}, \np{rn\_ice\_apnd}, \np{rn\_ice\_hpnd}). Ice age is constant and defined by \np{rn\_ice\_age}.
 
 If external boundary data is required then the \nam{bdy\_dta} namelist must be defined.
@@ -468,8 +420,9 @@
 For each required variable, the filename, the frequency of the files and
 the frequency of the data in the files are given.
-Also whether or not time-interpolation is required and whether the data is climatological (time-cyclic) data.\\
+Also whether or not time-interpolation is required and whether the data is climatological (time-cyclic) data.
+For sea-ice salinity, temperatures and melt ponds, reading the files are skipped and constant values are used if filenames are defined as {'NOT USED'}.\\
 
 There is currently an option to vertically interpolate the open boundary data onto the native grid at run-time.
-If \np{nn\_bdy\_jpk} $< -1$, it is assumed that the lateral boundary data are already on the native grid.
+If \np{nn\_bdy\_jpk}$<-1$, it is assumed that the lateral boundary data are already on the native grid.
 However, if \np{nn\_bdy\_jpk} is set to the number of vertical levels present in the boundary data,
 a bilinear interpolation onto the native grid will be triggered at runtime.
@@ -630,5 +583,5 @@
 \jp{jpinft} give the start and end $i$ indices for each segment with similar for the other boundaries.
 These segments define a list of $T$ grid points along the outermost row of the boundary ($nbr\,=\, 1$).
-The code deduces the $U$ and $V$ points and also the points for $nbr\,>\, 1$ if \np{nn\_rimwidth}\forcode{ > 1}.
+The code deduces the $U$ and $V$ points and also the points for $nbr\,>\, 1$ if \np{nn\_rimwidth}\forcode{>1}.
 
 The boundary geometry may also be defined from a ``\ifile{coordinates.bdy}'' file.
@@ -706,9 +659,9 @@
 There is an option to force the total volume in the regional model to be constant.
 This is controlled  by the \np{ln\_vol} parameter in the namelist.
-A value of \np{ln\_vol}\forcode{ = .false.} indicates that this option is not used.
+A value of \np{ln\_vol}\forcode{=.false.} indicates that this option is not used.
 Two options to control the volume are available (\np{nn\_volctl}).
-If \np{nn\_volctl}\forcode{ = 0} then a correction is applied to the normal barotropic velocities around the boundary at
+If \np{nn\_volctl}\forcode{=0} then a correction is applied to the normal barotropic velocities around the boundary at
 each timestep to ensure that the integrated volume flow through the boundary is zero.
-If \np{nn\_volctl}\forcode{ = 1} then the calculation of the volume change on
+If \np{nn\_volctl}\forcode{=1} then the calculation of the volume change on
 the timestep includes the change due to the freshwater flux across the surface and
 the correction velocity corrects for this as well.
Index: /NEMO/trunk/doc/namelists/nam_diadct
===================================================================
--- /NEMO/trunk/doc/namelists/nam_diadct	(revision 11536)
+++ /NEMO/trunk/doc/namelists/nam_diadct	(revision 11536)
@@ -0,0 +1,10 @@
+!-----------------------------------------------------------------------
+&nam_diadct     !   transports through some sections                    (default: OFF)
+!-----------------------------------------------------------------------
+    ln_diadct  = .false.   ! Calculate transport thru sections or not
+       nn_dct     = 15     !  time step frequency for transports computing
+       nn_dctwri  = 15     !  time step frequency for transports writing
+       nn_secdebug = 112   !      0 : no section to debug
+       !                   !     -1 : debug all section
+       !                   !  0 < n : debug section number n
+/
Index: /NEMO/trunk/doc/namelists/nam_diaharm
===================================================================
--- /NEMO/trunk/doc/namelists/nam_diaharm	(revision 11535)
+++ /NEMO/trunk/doc/namelists/nam_diaharm	(revision 11536)
@@ -1,9 +1,10 @@
 !-----------------------------------------------------------------------
-&nam_diaharm   !   Harmonic analysis of tidal constituents              ("key_diaharm")
+&nam_diaharm   !   Harmonic analysis of tidal constituents              (default: OFF)
 !-----------------------------------------------------------------------
-    nit000_han = 1         ! First time step used for harmonic analysis
-    nitend_han = 75        ! Last time step used for harmonic analysis
-    nstep_han  = 15        ! Time step frequency for harmonic analysis
-    tname(1)   = 'M2'      ! Name of tidal constituents
-    tname(2)   = 'K1'
+    ln_diaharm = .false.   ! Choose tidal harmonic output or not
+       nit000_han = 1      !    First time step used for harmonic analysis
+       nitend_han = 75     !    Last time step used for harmonic analysis
+       nstep_han  = 15     !    Time step frequency for harmonic analysis
+       tname(1)   = 'M2'   !    Name of tidal constituents
+       tname(2)   = 'K1'
 /
Index: /NEMO/trunk/doc/namelists/nambdy
===================================================================
--- /NEMO/trunk/doc/namelists/nambdy	(revision 11535)
+++ /NEMO/trunk/doc/namelists/nambdy	(revision 11536)
@@ -22,7 +22,4 @@
    nn_ice_dta    =  0         !  = 0, bdy data are equal to the initial state
    !                          !  = 1, bdy data are read in 'bdydata   .nc' files
-   rn_ice_tem    = 270.       !  si3 only: arbitrary temperature of incoming sea ice
-   rn_ice_sal    = 10.        !  si3 only:      --   salinity           --
-   rn_ice_age    = 30.        !  si3 only:      --   age                --
    !
    ln_tra_dmp    =.false.     !  open boudaries conditions for tracers
@@ -33,4 +30,3 @@
    ln_vol        = .false.    !  total volume correction (see nn_volctl parameter)
    nn_volctl     =  1         !  = 0, the total water flux across open boundaries is zero
-   nb_jpk_bdy    = -1         ! number of levels in the bdy data (set < 0 if consistent with planned run)
 /
Index: /NEMO/trunk/doc/namelists/nambdy_dta
===================================================================
--- /NEMO/trunk/doc/namelists/nambdy_dta	(revision 11535)
+++ /NEMO/trunk/doc/namelists/nambdy_dta	(revision 11536)
@@ -2,6 +2,9 @@
 &nambdy_dta    !  open boundaries - external data                       (see nam_bdy)
 !-----------------------------------------------------------------------
-   ln_full_vel = .false.      !  ???
-
+   ln_zinterp  = .false.      !  T if a vertical interpolation is required. Variables gdep[tuv] and e3[tuv] must exist in the file
+   !                          !  automatically defined to T if the number of vertical levels in bdy dta /= jpk
+   ln_full_vel = .false.      !  T if [uv]3d are "full" velocities and not only its baroclinic components
+   !                          !  in this case, baroclinic and barotropic velocities will be recomputed -> [uv]2d not needed
+   !
    cn_dir      = 'bdydta/'    !  root directory for the BDY data location
    !___________!_________________________!___________________!___________!_____________!________!___________!__________________!__________!_______________!
@@ -16,6 +19,19 @@
    bn_sal      = 'amm12_bdyT_tra'        ,         24        , 'vosaline',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
 !* for si3
-!   bn_a_i     = 'amm12_bdyT_ice'        ,         24        , 'ileadfra',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
-!   bn_h_i     = 'amm12_bdyT_ice'        ,         24        , 'iicethic',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
-!   bn_h_s     = 'amm12_bdyT_ice'        ,         24        , 'isnowthi',    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_a_i      = 'amm12_bdyT_ice'        ,         24.       , 'siconc'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_h_i      = 'amm12_bdyT_ice'        ,         24.       , 'sithic'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_h_s      = 'amm12_bdyT_ice'        ,         24.       , 'snthic'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_t_i      = 'NOT USED'              ,         24.       , 'sitemp'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_t_s      = 'NOT USED'              ,         24.       , 'sntemp'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_tsu      = 'NOT USED'              ,         24.       , 'sittop'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_s_i      = 'NOT USED'              ,         24.       , 'sisalt'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   ! melt ponds (be careful, bn_aip is the pond concentration (not fraction), so it differs from rn_iceapnd)
+   bn_aip      = 'NOT USED'              ,         24.       , 'siapnd'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   bn_hip      = 'NOT USED'              ,         24.       , 'sihpnd'  ,    .true.   , .false.,  'daily'  ,    ''            ,   ''     ,     ''
+   ! if bn_t_i etc are "not used", then define arbitrary temperatures and salinity and ponds
+   rn_ice_tem  = 270.         !  arbitrary temperature               of incoming sea ice
+   rn_ice_sal  = 10.          !       --   salinity                            --
+   rn_ice_age  = 30.          !       --   age                                 --
+   rn_ice_apnd = 0.2          !       --   pond fraction = a_ip/a_i            --
+   rn_ice_hpnd = 0.05         !       --   pond depth                          --
 /
Index: MO/trunk/doc/namelists/namdct
===================================================================
--- /NEMO/trunk/doc/namelists/namdct	(revision 11535)
+++ 	(revision )
@@ -1,9 +1,0 @@
-!-----------------------------------------------------------------------
-&namdct        ! transports through some sections                       ("key_diadct")
-!-----------------------------------------------------------------------
-    nn_dct     = 15        !  time step frequency for transports computing
-    nn_dctwri  = 15        !  time step frequency for transports writing
-    nn_secdebug = 112       !      0 : no section to debug
-    !                      !     -1 : debug all section
-    !                      !  0 < n : debug section number n
-/
Index: /NEMO/trunk/doc/namelists/namdia
===================================================================
--- /NEMO/trunk/doc/namelists/namdia	(revision 11535)
+++ /NEMO/trunk/doc/namelists/namdia	(revision 11536)
@@ -2,5 +2,8 @@
 &namdia         !   Diagnostics
 !------------------------------------------------------------------------------
-   ln_icediachk     = .false.         !  check online the heat, mass & salt budgets (T) or not (F)
+   ln_icediachk     = .false.         !  check online the heat, mass & salt budgets at each time step
+      !                               !     rate of ice spuriously gained/lost. For ex., rn_icechk=1. <=> 1mm/year, rn_icechk=0.1 <=> 1mm/10years
+      rn_icechk_cel =  1.             !     check at any gridcell           => stops the code if violated (and writes a file)
+      rn_icechk_glo =  0.1            !     check over the entire ice cover => only prints warnings
    ln_icediahsb     = .false.         !  output the heat, mass & salt budgets (T) or not (F)
    ln_icectl        = .false.         !  ice points output for debug (T or F)
Index: /NEMO/trunk/doc/namelists/namflo
===================================================================
--- /NEMO/trunk/doc/namelists/namflo	(revision 11535)
+++ /NEMO/trunk/doc/namelists/namflo	(revision 11536)
@@ -1,14 +1,15 @@
 !-----------------------------------------------------------------------
-&namflo        !   float parameters                                     ("key_float")
+&namflo        !   float parameters                                     (default: OFF)
 !-----------------------------------------------------------------------
-   jpnfl       = 1         !  total number of floats during the run
-   jpnnewflo   = 0         !  number of floats for the restart
-   ln_rstflo   = .false.   !  float restart (T) or not (F)
-   nn_writefl  =      75   !  frequency of writing in float output file
-   nn_stockfl  =    5475   !  frequency of creation of the float restart file
-   ln_argo     = .false.   !  Argo type floats (stay at the surface each 10 days)
-   ln_flork4   = .false.   !  trajectories computed with a 4th order Runge-Kutta (T)
-   !                       !  or computed with Blanke' scheme (F)
-   ln_ariane   = .true.    !  Input with Ariane tool convention(T)
-   ln_flo_ascii = .true.    !  Output with Ariane tool netcdf convention(F) or ascii file (T)
+   ln_floats   = .false.      ! activate floats or not
+      jpnfl       = 1         !    total number of floats during the run
+      jpnnewflo   = 0         !    number of floats for the restart
+      ln_rstflo   = .false.   !    float restart (T) or not (F)
+      nn_writefl  =      75   !    frequency of writing in float output file
+      nn_stockfl  =    5475   !    frequency of creation of the float restart file
+      ln_argo     = .false.   !    Argo type floats (stay at the surface each 10 days)
+      ln_flork4   = .false.   !    trajectories computed with a 4th order Runge-Kutta (T)
+      !                       !    or computed with Blanke' scheme (F)
+      ln_ariane   = .true.    !    Input with Ariane tool convention(T)
+      ln_flo_ascii= .true.    !    Output with Ariane tool netcdf convention(F) or ascii file (T)
 /
Index: /NEMO/trunk/doc/namelists/namhsb
===================================================================
--- /NEMO/trunk/doc/namelists/namhsb	(revision 11535)
+++ /NEMO/trunk/doc/namelists/namhsb	(revision 11536)
@@ -2,4 +2,4 @@
 &namhsb        !  Heat and salt budgets                                 (default: OFF)
 !-----------------------------------------------------------------------
-   ln_diahsb   = .false.   !  check the heat and salt budgets (T) or not (F)
+   ln_diahsb   = .false.   !  output the heat and salt budgets (T) or not (F)
 /
Index: /NEMO/trunk/doc/namelists/namini
===================================================================
--- /NEMO/trunk/doc/namelists/namini	(revision 11535)
+++ /NEMO/trunk/doc/namelists/namini	(revision 11536)
@@ -4,22 +4,34 @@
    ln_iceini        = .true.          !  activate ice initialization (T) or not (F)
    ln_iceini_file   = .false.         !  netcdf file provided for initialization (T) or not (F)
-   rn_thres_sst     =   2.0           !  max delta temp. above Tfreeze with initial ice = (sst - tfreeze)
-   rn_hts_ini_n     =   0.3           !  initial real snow thickness (m), North
+   rn_thres_sst     =   2.0           !  max temp. above Tfreeze with initial ice = (sst - tfreeze)
+   rn_hti_ini_n     =   3.0           !  initial ice thickness       (m), North
+   rn_hti_ini_s     =   1.0           !        "            "             South
+   rn_hts_ini_n     =   0.3           !  initial snow thickness      (m), North
    rn_hts_ini_s     =   0.3           !        "            "             South
-   rn_hti_ini_n     =   3.0           !  initial real ice thickness  (m), North
-   rn_hti_ini_s     =   1.0           !        "            "             South
    rn_ati_ini_n     =   0.9           !  initial ice concentration   (-), North
    rn_ati_ini_s     =   0.9           !        "            "             South
    rn_smi_ini_n     =   6.3           !  initial ice salinity     (g/kg), North
    rn_smi_ini_s     =   6.3           !        "            "             South
-   rn_tmi_ini_n     = 270.            !  initial ice/snw temperature (K), North
+   rn_tmi_ini_n     = 270.            !  initial ice temperature     (K), North
    rn_tmi_ini_s     = 270.            !        "            "             South
-
+   rn_tsu_ini_n     = 270.            !  initial surface temperature (K), North
+   rn_tsu_ini_s     = 270.            !        "            "             South
+   rn_tms_ini_n     = 270.            !  initial snw temperature     (K), North
+   rn_tms_ini_s     = 270.            !        "            "             South
+   rn_apd_ini_n     =   0.2           !  initial pond fraction       (-), North
+   rn_apd_ini_s     =   0.2           !        "            "             South
+   rn_hpd_ini_n     =   0.05          !  initial pond depth          (m), North
+   rn_hpd_ini_s     =   0.05          !        "            "             South
+   !        ! if ln_iceini_file=T
    sn_hti = 'Ice_initialization'    , -12 ,'hti'   ,  .false.  , .true., 'yearly'  , '' , '', ''
    sn_hts = 'Ice_initialization'    , -12 ,'hts'   ,  .false.  , .true., 'yearly'  , '' , '', ''
    sn_ati = 'Ice_initialization'    , -12 ,'ati'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_smi = 'Ice_initialization'    , -12 ,'smi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_tmi = 'Ice_initialization'    , -12 ,'tmi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
    sn_tsu = 'Ice_initialization'    , -12 ,'tsu'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_tmi = 'Ice_initialization'    , -12 ,'tmi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_smi = 'Ice_initialization'    , -12 ,'smi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_tms = 'NOT USED'              , -12 ,'tms'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   !      melt ponds (be careful, sn_apd is the pond concentration (not fraction), so it differs from rn_apd)
+   sn_apd = 'NOT USED'              , -12 ,'apd'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_hpd = 'NOT USED'              , -12 ,'hpd'   ,  .false.  , .true., 'yearly'  , '' , '', ''
    cn_dir='./'
 /
Index: /NEMO/trunk/doc/namelists/nammpp
===================================================================
--- /NEMO/trunk/doc/namelists/nammpp	(revision 11535)
+++ /NEMO/trunk/doc/namelists/nammpp	(revision 11536)
@@ -2,7 +2,4 @@
 &nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi")
 !-----------------------------------------------------------------------
-   cn_mpi_send =  'I'      !  mpi send/recieve type   ='S', 'B', or 'I' for standard send,
-   !                       !  buffer blocking send or immediate non-blocking sends, resp.
-   nn_buffer   =   0       !  size in bytes of exported buffer ('B' case), 0 no exportation
    ln_nnogather =  .true.  !  activate code to avoid mpi_allgather use at the northfold
    jpni        =   0       !  jpni   number of processors following i (set automatically if < 1)
Index: /NEMO/trunk/doc/namelists/namthd_pnd
===================================================================
--- /NEMO/trunk/doc/namelists/namthd_pnd	(revision 11535)
+++ /NEMO/trunk/doc/namelists/namthd_pnd	(revision 11536)
@@ -2,8 +2,9 @@
 &namthd_pnd     !   Melt ponds
 !------------------------------------------------------------------------------
-   ln_pnd_H12       = .false.         !  activate evolutive melt ponds (from Holland et al 2012)
-   ln_pnd_CST       = .false.         !  activate constant  melt ponds
-      rn_apnd       =   0.2           !     prescribed pond fraction, at Tsu=0 degC
-      rn_hpnd       =   0.05          !     prescribed pond depth,    at Tsu=0 degC
-   ln_pnd_alb       = .false.         !  melt ponds affect albedo or not
+   ln_pnd           = .false.         !  activate melt ponds or not
+     ln_pnd_H12     = .false.         !  activate evolutive melt ponds (from Holland et al 2012)
+     ln_pnd_CST     = .false.         !  activate constant  melt ponds
+       rn_apnd      =   0.2           !     prescribed pond fraction, at Tsu=0 degC
+       rn_hpnd      =   0.05          !     prescribed pond depth,    at Tsu=0 degC
+     ln_pnd_alb     = .false.         !  melt ponds affect albedo or not
 /
Index: /NEMO/trunk/src/ICE/ice.F90
===================================================================
--- /NEMO/trunk/src/ICE/ice.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/ice.F90	(revision 11536)
@@ -102,4 +102,5 @@
    !! vt_i        |      -      |    Total ice vol. per unit area | m     |
    !! vt_s        |      -      |    Total snow vol. per unit ar. | m     |
+   !! st_i        |      -      |    Total Sea ice salt content   | pss.m |
    !! sm_i        |      -      |    Mean sea ice salinity        | pss   |
    !! tm_i        |      -      |    Mean sea ice temperature     | K     |
@@ -109,4 +110,5 @@
    !! bv_i        |      -      |    relative brine volume        | ???   | 
    !! at_ip       |      -      |    Total ice pond concentration |       |
+   !! hm_ip       |      -      |    Mean ice pond depth          | m     |
    !! vt_ip       |      -      |    Total ice pond vol. per unit area| m |
    !!=====================================================================
@@ -135,5 +137,4 @@
    REAL(wp), PUBLIC ::   rn_ishlat        !: lateral boundary condition for sea-ice
    LOGICAL , PUBLIC ::   ln_landfast_L16  !: landfast ice parameterizationfrom lemieux2016 
-   LOGICAL , PUBLIC ::   ln_landfast_home !: landfast ice parameterizationfrom home made 
    REAL(wp), PUBLIC ::   rn_depfra        !:    fraction of ocean depth that ice must reach to initiate landfast ice
    REAL(wp), PUBLIC ::   rn_icebfr        !:    maximum bottom stress per unit area of contact (lemieux2016) or per unit volume (home) 
@@ -188,4 +189,5 @@
 
    !                                     !!** ice-ponds namelist (namthd_pnd)
+   LOGICAL , PUBLIC ::   ln_pnd           !: Melt ponds (T) or not (F)
    LOGICAL , PUBLIC ::   ln_pnd_H12       !: Melt ponds scheme from Holland et al 2012
    LOGICAL , PUBLIC ::   ln_pnd_CST       !: Melt ponds scheme with constant fraction and depth
@@ -196,4 +198,6 @@
    !                                     !!** ice-diagnostics namelist (namdia) **
    LOGICAL , PUBLIC ::   ln_icediachk     !: flag for ice diag (T) or not (F)
+   REAL(wp), PUBLIC ::   rn_icechk_cel    !: rate of ice spuriously gained/lost (at any gridcell)
+   REAL(wp), PUBLIC ::   rn_icechk_glo    !: rate of ice spuriously gained/lost (globally)
    LOGICAL , PUBLIC ::   ln_icediahsb     !: flag for ice diag (T) or not (F)
    LOGICAL , PUBLIC ::   ln_icectl        !: flag for sea-ice points output (T) or not (F)
@@ -213,7 +217,4 @@
    REAL(wp), PUBLIC, PARAMETER ::   epsi20 = 1.e-20_wp  !: small number 
 
-   !                                     !!** some other parameters for advection using the ULTIMATE-MACHO scheme
-   LOGICAL, PUBLIC, DIMENSION(2) :: l_split_advumx = .FALSE.    ! force one iteration at the first time-step
-
    !                                     !!** define arrays
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   u_oce,v_oce !: surface ocean velocity used in ice dynamics
@@ -251,6 +252,4 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_res     !: mass flux from residual component of wfx_ice             [kg.m-2.s-1]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_err_sub !: mass flux error after sublimation                        [kg.m-2.s-1]
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   afx_tot     !: ice concentration tendency (total)        [s-1]
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx_bog     !: salt flux due to ice bottom growth                   [pss.kg.m-2.s-1 => g.m-2.s-1]
@@ -309,4 +308,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   u_ice, v_ice !: components of the ice velocity                          (m/s)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   vt_i , vt_s  !: ice and snow total volume per unit area                 (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   st_i         !: Total ice salinity content                              (pss.m)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   at_i         !: ice total fractional area (ice concentration)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ato_i        !: =1-at_i ; total open water fractional area
@@ -334,4 +334,5 @@
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   at_ip      !: total melt pond fraction
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hm_ip      !: mean melt pond depth                     [m]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   vt_ip      !: total melt pond volume per unit area     [m]
 
@@ -355,7 +356,4 @@
    !! * Ice diagnostics
    !!----------------------------------------------------------------------
-   ! thd refers to changes induced by thermodynamics
-   ! trp   ''         ''     ''       advection (transport of ice)
-   !
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_trp_vi   !: transport of ice volume
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_trp_vs   !: transport of snw volume
@@ -369,4 +367,13 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_vsnw     !: snw volume variation   [m/s] 
 
+   !!----------------------------------------------------------------------
+   !! * Ice conservation
+   !!----------------------------------------------------------------------
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_v        !: conservation of ice volume
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_s        !: conservation of ice salt
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_t        !: conservation of ice heat
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_fv       !: conservation of ice volume
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_fs       !: conservation of ice salt
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_ft       !: conservation of ice heat
    !
    !!----------------------------------------------------------------------
@@ -393,5 +400,5 @@
       INTEGER :: ice_alloc
       !
-      INTEGER :: ierr(15), ii
+      INTEGER :: ierr(16), ii
       !!-----------------------------------------------------------------
       ierr(:) = 0
@@ -409,5 +416,5 @@
          &      wfx_bog    (jpi,jpj) , wfx_dyn   (jpi,jpj) , wfx_bom(jpi,jpj) , wfx_sum(jpi,jpj) ,           &
          &      wfx_res    (jpi,jpj) , wfx_sni   (jpi,jpj) , wfx_opw(jpi,jpj) , wfx_spr(jpi,jpj) ,           &
-         &      afx_tot    (jpi,jpj) , rn_amax_2d(jpi,jpj),                                                  &
+         &      rn_amax_2d (jpi,jpj) ,                                                                       &
          &      qsb_ice_bot(jpi,jpj) , qlead     (jpi,jpj) ,                                                 &
          &      sfx_res    (jpi,jpj) , sfx_bri   (jpi,jpj) , sfx_dyn(jpi,jpj) , sfx_sub(jpi,jpj) , sfx_lam(jpi,jpj) ,  &
@@ -429,7 +436,7 @@
       ii = ii + 1
       ALLOCATE( u_ice(jpi,jpj) , v_ice(jpi,jpj) ,                                   &
-         &      vt_i (jpi,jpj) , vt_s (jpi,jpj) , at_i(jpi,jpj) , ato_i(jpi,jpj) ,  &
-         &      et_i (jpi,jpj) , et_s (jpi,jpj) , tm_i(jpi,jpj) , tm_s (jpi,jpj) ,  &
-         &      sm_i (jpi,jpj) , tm_su(jpi,jpj) , hm_i(jpi,jpj) , hm_s (jpi,jpj) ,  &
+         &      vt_i (jpi,jpj) , vt_s (jpi,jpj) , st_i(jpi,jpj) , at_i(jpi,jpj) , ato_i(jpi,jpj) ,  &
+         &      et_i (jpi,jpj) , et_s (jpi,jpj) , tm_i(jpi,jpj) , tm_s(jpi,jpj) ,  &
+         &      sm_i (jpi,jpj) , tm_su(jpi,jpj) , hm_i(jpi,jpj) , hm_s(jpi,jpj) ,  &
          &      om_i (jpi,jpj) , bvm_i(jpi,jpj) , tau_icebfr(jpi,jpj)            , STAT=ierr(ii) )
 
@@ -444,5 +451,5 @@
 
       ii = ii + 1
-      ALLOCATE( at_ip(jpi,jpj) , vt_ip(jpi,jpj) , STAT = ierr(ii) )
+      ALLOCATE( at_ip(jpi,jpj) , hm_ip(jpi,jpj) , vt_ip(jpi,jpj) , STAT = ierr(ii) )
 
       ! * Old values of global variables
@@ -465,4 +472,9 @@
          &      diag_sice  (jpi,jpj) , diag_vice   (jpi,jpj) , diag_vsnw  (jpi,jpj), STAT=ierr(ii) )
 
+      ! * Ice conservation
+      ii = ii + 1
+      ALLOCATE( diag_v (jpi,jpj) , diag_s (jpi,jpj) , diag_t (jpi,jpj),   & 
+         &      diag_fv(jpi,jpj) , diag_fs(jpi,jpj) , diag_ft(jpi,jpj), STAT=ierr(ii) )
+      
       ! * SIMIP diagnostics
       ii = ii + 1
Index: /NEMO/trunk/src/ICE/icealb.F90
===================================================================
--- /NEMO/trunk/src/ICE/icealb.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icealb.F90	(revision 11536)
@@ -192,8 +192,8 @@
       REWIND( numnam_ice_ref )              ! Namelist namalb in reference namelist : Albedo parameters
       READ  ( numnam_ice_ref, namalb, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namalb in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namalb in reference namelist' )
       REWIND( numnam_ice_cfg )              ! Namelist namalb in configuration namelist : Albedo parameters
       READ  ( numnam_ice_cfg, namalb, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namalb in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namalb in configuration namelist' )
       IF(lwm) WRITE( numoni, namalb )
       !
Index: /NEMO/trunk/src/ICE/icecor.F90
===================================================================
--- /NEMO/trunk/src/ICE/icecor.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icecor.F90	(revision 11536)
@@ -17,5 +17,5 @@
    USE phycst         ! physical constants
    USE ice            ! sea-ice: variable
-   USE ice1D          ! sea-ice: thermodynamic sea-ice variables
+   USE ice1D          ! sea-ice: thermodynamic variables
    USE iceitd         ! sea-ice: rebining
    USE icevar         ! sea-ice: operations
@@ -60,4 +60,5 @@
       IF( ln_timing    )   CALL timing_start('icecor')                                                             ! timing
       IF( ln_icediachk )   CALL ice_cons_hsm(0, 'icecor', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+      IF( ln_icediachk )   CALL ice_cons2D  (0, 'icecor',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft) ! conservation
       !
       IF( kt == nit000 .AND. lwp .AND. kn == 2 ) THEN
@@ -78,5 +79,5 @@
       !                             !-----------------------------------------------------
       at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
-      DO jl  = 1, jpl
+      DO jl = 1, jpl
          WHERE( at_i(:,:) > rn_amax_2d(:,:) )   a_i(:,:,jl) = a_i(:,:,jl) * rn_amax_2d(:,:) / at_i(:,:)
       END DO
@@ -84,5 +85,5 @@
       !                             !-----------------------------------------------------
       IF ( nn_icesal == 2 ) THEN    !  salinity must stay in bounds [Simin,Simax]        !
-      !                             !-----------------------------------------------------
+         !                          !-----------------------------------------------------
          zzc = rhoi * r1_rdtice
          DO jl = 1, jpl
@@ -117,12 +118,7 @@
             END DO
          END DO
-         CALL lbc_lnk_multi( 'icecor', u_ice, 'U', -1., v_ice, 'V', -1. )            ! lateral boundary conditions
+         CALL lbc_lnk_multi( 'icecor', u_ice, 'U', -1., v_ice, 'V', -1. )
       ENDIF
 
-!!gm I guess the trends are only out on demand 
-!!   So please, only do this is it exite an iom_use of on a these variables
-!!   furthermore, only allocate the diag_ arrays in this case 
-!!   and do the iom_put here so that it is only a local allocation
-!!gm 
       !                             !-----------------------------------------------------
       SELECT CASE( kn )             !  Diagnostics                                       !
@@ -130,20 +126,16 @@
       CASE( 1 )                        !--- dyn trend diagnostics
          !
-!!gm   here I think the number of ice cat is too small to use a SUM instruction...
-         DO jj = 1, jpj
-            DO ji = 1, jpi            
-               !                 ! heat content variation (W.m-2)
-               diag_heat(ji,jj) = - (  SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) )    & 
-                  &                  + SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )  ) * r1_rdtice
-               !                 ! salt, volume
-               diag_sice(ji,jj) = SUM( sv_i(ji,jj,:) - sv_i_b(ji,jj,:) ) * rhoi * r1_rdtice
-               diag_vice(ji,jj) = SUM( v_i (ji,jj,:) - v_i_b (ji,jj,:) ) * rhoi * r1_rdtice
-               diag_vsnw(ji,jj) = SUM( v_s (ji,jj,:) - v_s_b (ji,jj,:) ) * rhos * r1_rdtice
-            END DO
-         END DO
+         IF( ln_icediachk .OR. iom_use('hfxdhc') ) THEN
+            diag_heat(:,:) = - SUM(SUM( e_i (:,:,1:nlay_i,:) - e_i_b (:,:,1:nlay_i,:), dim=4 ), dim=3 ) * r1_rdtice &      ! W.m-2
+               &             - SUM(SUM( e_s (:,:,1:nlay_s,:) - e_s_b (:,:,1:nlay_s,:), dim=4 ), dim=3 ) * r1_rdtice
+            diag_sice(:,:) =   SUM(     sv_i(:,:,:)          - sv_i_b(:,:,:)                  , dim=3 ) * r1_rdtice * rhoi
+            diag_vice(:,:) =   SUM(     v_i (:,:,:)          - v_i_b (:,:,:)                  , dim=3 ) * r1_rdtice * rhoi
+            diag_vsnw(:,:) =   SUM(     v_s (:,:,:)          - v_s_b (:,:,:)                  , dim=3 ) * r1_rdtice * rhos
+         ENDIF
          !                       ! concentration tendency (dynamics)
-         zafx   (:,:) = SUM( a_i(:,:,:) - a_i_b(:,:,:), dim=3 ) * r1_rdtice 
-         afx_tot(:,:) = zafx(:,:)
-         IF( iom_use('afxdyn') )   CALL iom_put( 'afxdyn' , zafx(:,:) )
+         IF( iom_use('afxdyn') .OR. iom_use('afxthd') .OR. iom_use('afxtot') ) THEN 
+            zafx(:,:) = SUM( a_i(:,:,:) - a_i_b(:,:,:), dim=3 ) * r1_rdtice 
+            CALL iom_put( 'afxdyn' , zafx )
+         ENDIF
          !
       CASE( 2 )                        !--- thermo trend diagnostics & ice aging
@@ -151,29 +143,32 @@
          oa_i(:,:,:) = oa_i(:,:,:) + a_i(:,:,:) * rdt_ice   ! ice natural aging incrementation
          !
-!!gm   here I think the number of ice cat is too small to use a SUM instruction...
-         DO jj = 1, jpj
-            DO ji = 1, jpi            
-               !                 ! heat content variation (W.m-2)
-               diag_heat(ji,jj) = diag_heat(ji,jj) - (  SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) )    & 
-                  &                                   + SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )  ) * r1_rdtice
-               !                 ! salt, volume
-               diag_sice(ji,jj) = diag_sice(ji,jj) + SUM( sv_i(ji,jj,:) - sv_i_b(ji,jj,:) ) * rhoi * r1_rdtice
-               diag_vice(ji,jj) = diag_vice(ji,jj) + SUM( v_i (ji,jj,:) - v_i_b (ji,jj,:) ) * rhoi * r1_rdtice
-               diag_vsnw(ji,jj) = diag_vsnw(ji,jj) + SUM( v_s (ji,jj,:) - v_s_b (ji,jj,:) ) * rhos * r1_rdtice
-            END DO
-         END DO
+         IF( ln_icediachk .OR. iom_use('hfxdhc') ) THEN
+            diag_heat(:,:) = diag_heat(:,:) &
+               &             - SUM(SUM( e_i (:,:,1:nlay_i,:) - e_i_b (:,:,1:nlay_i,:), dim=4 ), dim=3 ) * r1_rdtice &
+               &             - SUM(SUM( e_s (:,:,1:nlay_s,:) - e_s_b (:,:,1:nlay_s,:), dim=4 ), dim=3 ) * r1_rdtice
+            diag_sice(:,:) = diag_sice(:,:) &
+               &             + SUM(     sv_i(:,:,:)          - sv_i_b(:,:,:)                  , dim=3 ) * r1_rdtice * rhoi
+            diag_vice(:,:) = diag_vice(:,:) &
+               &             + SUM(     v_i (:,:,:)          - v_i_b (:,:,:)                  , dim=3 ) * r1_rdtice * rhoi
+            diag_vsnw(:,:) = diag_vsnw(:,:) &
+               &             + SUM(     v_s (:,:,:)          - v_s_b (:,:,:)                  , dim=3 ) * r1_rdtice * rhos
+            CALL iom_put ( 'hfxdhc' , diag_heat ) 
+         ENDIF
          !                       ! concentration tendency (total + thermo)
-         zafx   (:,:) = SUM( a_i(:,:,:) - a_i_b(:,:,:), dim=3 ) * r1_rdtice
-         afx_tot(:,:) = afx_tot(:,:) + zafx(:,:)
-         IF( iom_use('afxthd') )   CALL iom_put( 'afxthd' , zafx(:,:) )
-         IF( iom_use('afxtot') )   CALL iom_put( 'afxtot' , afx_tot(:,:) )
+         IF( iom_use('afxdyn') .OR. iom_use('afxthd') .OR. iom_use('afxtot') ) THEN 
+            zafx(:,:) = zafx(:,:) + SUM( a_i(:,:,:) - a_i_b(:,:,:), dim=3 ) * r1_rdtice
+            CALL iom_put( 'afxthd' , SUM( a_i(:,:,:) - a_i_b(:,:,:), dim=3 ) * r1_rdtice )
+            CALL iom_put( 'afxtot' , zafx )
+         ENDIF
          !
       END SELECT
       !
       ! controls
-      IF( ln_icediachk   )   CALL ice_cons_hsm(1, 'icecor', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
-      IF( ln_ctl         )   CALL ice_prt3D   ('icecor')                                                             ! prints
-      IF( ln_icectl .AND. kn == 2 )   CALL ice_prt( kt, iiceprt, jiceprt, 2, ' - Final state - ' )                   ! prints
-      IF( ln_timing      )   CALL timing_stop ('icecor')                                                             ! timing
+      IF( ln_ctl       )   CALL ice_prt3D   ('icecor')                                                             ! prints
+      IF( ln_icectl .AND. kn == 2 ) &
+         &                 CALL ice_prt     ( kt, iiceprt, jiceprt, 2, ' - Final state - ' )                       ! prints
+      IF( ln_icediachk )   CALL ice_cons_hsm(1, 'icecor', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+      IF( ln_icediachk )   CALL ice_cons2D  (1, 'icecor',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft) ! conservation
+      IF( ln_timing    )   CALL timing_stop ('icecor')                                                             ! timing
       !
    END SUBROUTINE ice_cor
Index: /NEMO/trunk/src/ICE/icectl.F90
===================================================================
--- /NEMO/trunk/src/ICE/icectl.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icectl.F90	(revision 11536)
@@ -12,6 +12,7 @@
    !!   'key_si3'                                       SI3 sea-ice model
    !!----------------------------------------------------------------------
-   !!    ice_cons_hsm     : conservation tests on heat, salt and mass
-   !!    ice_cons_final   : conservation tests on heat, salt and mass at end of time step
+   !!    ice_cons_hsm     : conservation tests on heat, salt and mass during a  time step (global) 
+   !!    ice_cons_final   : conservation tests on heat, salt and mass at end of time step (global)
+   !!    ice_cons2D       : conservation tests on heat, salt and mass at each gridcell
    !!    ice_ctl          : control prints in case of crash
    !!    ice_prt          : control prints at a given grid point
@@ -27,4 +28,5 @@
    !
    USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
    USE lib_mpp        ! MPP library
    USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
@@ -37,8 +39,15 @@
    PUBLIC   ice_cons_hsm
    PUBLIC   ice_cons_final
+   PUBLIC   ice_cons2D
    PUBLIC   ice_ctl
    PUBLIC   ice_prt
    PUBLIC   ice_prt3D
 
+   ! thresold values for conservation
+   !    these values are changed by the namelist parameter rn_icechk, so that threshold = zchk * rn_icechk
+   REAL(wp), PARAMETER ::   zchk_m   = 1.e-5   ! kg/m2/s <=> 1mm of ice per year  spuriously gained/lost
+   REAL(wp), PARAMETER ::   zchk_s   = 1.e-4   ! g/m2/s  <=> 1mm of ice per year  spuriously gained/lost (considering s=10g/kg)
+   REAL(wp), PARAMETER ::   zchk_t   = 3.      ! W/m2    <=> 1mm of ice per year  spuriously gained/lost (considering Lf=3e5J/kg)
+   
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
@@ -59,5 +68,5 @@
       !! ** Method  : This is an online diagnostics which can be activated with ln_icediachk=true
       !!              It prints in ocean.output if there is a violation of conservation at each time-step
-      !!              The thresholds (zv_sill, zs_sill, zt_sill) which determine violations are set to
+      !!              The thresholds (zchk_m, zchk_s, zchk_t) which determine violations are set to
       !!              a minimum of 1 mm of ice (over the ice area) that is lost/gained spuriously during 100 years.
       !!              For salt and heat thresholds, ice is considered to have a salinity of 10 
@@ -68,109 +77,86 @@
       REAL(wp)        , INTENT(inout) ::   pdiag_v, pdiag_s, pdiag_t, pdiag_fv, pdiag_fs, pdiag_ft
       !!
-      REAL(wp) ::   zv, zs, zt, zfs, zfv, zft
-      REAL(wp) ::   zvmin, zamin, zamax, zeimin, zesmin, zsmin
+      REAL(wp) ::   zdiag_mass, zdiag_salt, zdiag_heat, &
+         &          zdiag_vmin, zdiag_amin, zdiag_amax, zdiag_eimin, zdiag_esmin, zdiag_smin
       REAL(wp) ::   zvtrp, zetrp
-      REAL(wp) ::   zarea, zv_sill, zs_sill, zt_sill
-      REAL(wp), PARAMETER ::   zconv = 1.e-9 ! convert W to GW and kg to Mt
+      REAL(wp) ::   zarea
       !!-------------------------------------------------------------------
       !
       IF( icount == 0 ) THEN
-         !                          ! water flux
-         pdiag_fv = glob_sum( 'icectl',                                                                       &
-            &                 -( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) +                  &
-            &                    wfx_opw(:,:) + wfx_res(:,:) + wfx_dyn(:,:) + wfx_lam(:,:) + wfx_pnd(:,:)  +  &
-            &                    wfx_snw_sni(:,:) + wfx_snw_sum(:,:) + wfx_snw_dyn(:,:) + wfx_snw_sub(:,:) +  &
-            &                    wfx_ice_sub(:,:) + wfx_spr(:,:)  &
-            &                  ) * e1e2t(:,:) ) * zconv
+
+         pdiag_v = glob_sum( 'icectl',   SUM( v_i * rhoi + v_s * rhos, dim=3 ) * e1e2t )
+         pdiag_s = glob_sum( 'icectl',   SUM( sv_i * rhoi            , dim=3 ) * e1e2t )
+         pdiag_t = glob_sum( 'icectl', ( SUM( SUM( e_i, dim=4 ), dim=3 ) + SUM( SUM( e_s, dim=4 ), dim=3 ) ) * e1e2t )
+
+         ! mass flux
+         pdiag_fv = glob_sum( 'icectl',  &
+            &                         ( wfx_bog + wfx_bom + wfx_sum + wfx_sni + wfx_opw + wfx_res + wfx_dyn + wfx_lam + wfx_pnd + &
+            &                           wfx_snw_sni + wfx_snw_sum + wfx_snw_dyn + wfx_snw_sub + wfx_ice_sub + wfx_spr ) * e1e2t )
+         ! salt flux
+         pdiag_fs = glob_sum( 'icectl',  &
+            &                         ( sfx_bri + sfx_bog + sfx_bom + sfx_sum + sfx_sni + &
+            &                           sfx_opw + sfx_res + sfx_dyn + sfx_sub + sfx_lam ) * e1e2t )
+         ! heat flux
+         pdiag_ft = glob_sum( 'icectl',  &
+            &                         (   hfx_sum + hfx_bom + hfx_bog + hfx_dif + hfx_opw + hfx_snw  &
+            &                           - hfx_thd - hfx_dyn - hfx_res - hfx_sub - hfx_spr ) * e1e2t )
+
+      ELSEIF( icount == 1 ) THEN
+
+         ! -- mass diag -- !
+         zdiag_mass = ( glob_sum( 'icectl', SUM( v_i * rhoi + v_s * rhos, dim=3 ) * e1e2t ) - pdiag_v ) * r1_rdtice       &
+            &         + glob_sum( 'icectl', ( wfx_bog + wfx_bom + wfx_sum + wfx_sni + wfx_opw + wfx_res + wfx_dyn +       &
+            &                                 wfx_lam + wfx_pnd + wfx_snw_sni + wfx_snw_sum + wfx_snw_dyn + wfx_snw_sub + &
+            &                                 wfx_ice_sub + wfx_spr ) * e1e2t )                                           &
+            &         - pdiag_fv
          !
-         !                          ! salt flux
-         pdiag_fs = glob_sum( 'icectl',                                                                     &
-            &                  ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) +  &
-            &                    sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:) + sfx_lam(:,:)    &
-            &                  ) *  e1e2t(:,:) ) * zconv 
+         ! -- salt diag -- !
+         zdiag_salt = ( glob_sum( 'icectl', SUM( sv_i * rhoi , dim=3 ) * e1e2t ) - pdiag_s ) * r1_rdtice  &
+            &         + glob_sum( 'icectl', ( sfx_bri + sfx_bog + sfx_bom + sfx_sum + sfx_sni +           &
+            &                                 sfx_opw + sfx_res + sfx_dyn + sfx_sub + sfx_lam ) * e1e2t ) &
+            &         - pdiag_fs
          !
-         !                          ! heat flux
-         pdiag_ft = glob_sum( 'icectl',                                                                    &
-            &                  ( hfx_sum(:,:) + hfx_bom(:,:) + hfx_bog(:,:) + hfx_dif(:,:) + hfx_opw(:,:) + hfx_snw(:,:)  & 
-            &                  - hfx_thd(:,:) - hfx_dyn(:,:) - hfx_res(:,:) - hfx_sub(:,:) - hfx_spr(:,:)   &
-            &                  ) *  e1e2t(:,:) ) * zconv
-
-         pdiag_v = glob_sum( 'icectl', SUM( v_i * rhoi + v_s * rhos, dim=3 ) * e1e2t * zconv )
-
-         pdiag_s = glob_sum( 'icectl', SUM( sv_i * rhoi            , dim=3 ) * e1e2t * zconv )
-
-         pdiag_t = glob_sum( 'icectl', (  SUM( SUM( e_i(:,:,1:nlay_i,:), dim=4 ), dim=3 )     &
-            &                 + SUM( SUM( e_s(:,:,1:nlay_s,:), dim=4 ), dim=3 ) ) * e1e2t ) * zconv
-
-      ELSEIF( icount == 1 ) THEN
-
-         ! water flux
-         zfv = glob_sum( 'icectl',                                                                        &
-            &             -( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) +                  &
-            &                wfx_opw(:,:) + wfx_res(:,:) + wfx_dyn(:,:) + wfx_lam(:,:) + wfx_pnd(:,:)  +  &
-            &                wfx_snw_sni(:,:) + wfx_snw_sum(:,:) + wfx_snw_dyn(:,:) + wfx_snw_sub(:,:) +  &
-            &                wfx_ice_sub(:,:) + wfx_spr(:,:)  &
-            &              ) * e1e2t(:,:) ) * zconv - pdiag_fv
-
-         ! salt flux
-         zfs = glob_sum( 'icectl',                                                                       &
-            &              ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) +  &
-            &                sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:) + sfx_lam(:,:)    & 
-            &              ) * e1e2t(:,:) ) * zconv - pdiag_fs
-
-         ! heat flux
-         zft = glob_sum( 'icectl',                                                                      &
-            &              ( hfx_sum(:,:) + hfx_bom(:,:) + hfx_bog(:,:) + hfx_dif(:,:) + hfx_opw(:,:) + hfx_snw(:,:)  & 
-            &              - hfx_thd(:,:) - hfx_dyn(:,:) - hfx_res(:,:) - hfx_sub(:,:) - hfx_spr(:,:)   &
-            &              ) * e1e2t(:,:) ) * zconv - pdiag_ft
- 
-         ! outputs
-         zv = ( ( glob_sum( 'icectl', SUM( v_i * rhoi + v_s * rhos, dim=3 ) * e1e2t ) * zconv  &
-            &     - pdiag_v ) * r1_rdtice - zfv ) * rday
-
-         zs = ( ( glob_sum( 'icectl', SUM( sv_i * rhoi            , dim=3 ) * e1e2t ) * zconv  &
-            &     - pdiag_s ) * r1_rdtice + zfs ) * rday
-
-         zt = ( glob_sum( 'icectl',                                                                &
-            &             (  SUM( SUM( e_i(:,:,1:nlay_i,:), dim=4 ), dim=3 )                       &
-            &              + SUM( SUM( e_s(:,:,1:nlay_s,:), dim=4 ), dim=3 ) ) * e1e2t ) * zconv   &
-            &   - pdiag_t ) * r1_rdtice + zft
-
-         ! zvtrp and zetrp must be close to 0 if the advection scheme is conservative
-         zvtrp = glob_sum( 'icectl', ( diag_trp_vi * rhoi + diag_trp_vs * rhos ) * e1e2t  ) * zconv * rday 
-         zetrp = glob_sum( 'icectl', ( diag_trp_ei        + diag_trp_es        ) * e1e2t  ) * zconv
-
-         zamax  = glob_max( 'icectl', SUM( a_i, dim=3 ) )
-         zvmin  = glob_min( 'icectl', v_i )
-         zamin  = glob_min( 'icectl', a_i )
-         zsmin  = glob_min( 'icectl', sv_i )
-         zeimin = glob_min( 'icectl', SUM( e_i, dim=3 ) )
-         zesmin = glob_min( 'icectl', SUM( e_s, dim=3 ) )
-
-         ! set threshold values and calculate the ice area (+epsi10 to set a threshold > 0 when there is no ice) 
-         zarea   = glob_sum( 'icectl', SUM( a_i + epsi10, dim=3 ) * e1e2t ) * zconv ! in 1.e9 m2
-         zv_sill = zarea * 2.5e-5
-         zs_sill = zarea * 25.e-5
-         zt_sill = zarea * 10.e-5
-
-         IF(lwp) THEN
+         ! -- heat diag -- !
+         zdiag_heat = ( glob_sum( 'icectl', ( SUM(SUM(e_i, dim=4), dim=3) + SUM(SUM(e_s, dim=4), dim=3) ) * e1e2t ) - pdiag_t &
+            &         ) * r1_rdtice                                                                                           &
+            &         + glob_sum( 'icectl', (  hfx_sum + hfx_bom + hfx_bog + hfx_dif + hfx_opw + hfx_snw                      &
+            &                                - hfx_thd - hfx_dyn - hfx_res - hfx_sub - hfx_spr ) * e1e2t )                    &
+            &         - pdiag_ft
+
+         ! -- min/max diag -- !
+         zdiag_amax  = glob_max( 'icectl', SUM( a_i, dim=3 ) )
+         zdiag_vmin  = glob_min( 'icectl', v_i )
+         zdiag_amin  = glob_min( 'icectl', a_i )
+         zdiag_smin  = glob_min( 'icectl', sv_i )
+         zdiag_eimin = glob_min( 'icectl', SUM( e_i, dim=3 ) )
+         zdiag_esmin = glob_min( 'icectl', SUM( e_s, dim=3 ) )
+
+         ! -- advection scheme is conservative? -- !
+         zvtrp = glob_sum( 'icectl', ( diag_trp_vi * rhoi + diag_trp_vs * rhos ) * e1e2t ) ! must be close to 0
+         zetrp = glob_sum( 'icectl', ( diag_trp_ei        + diag_trp_es        ) * e1e2t ) ! must be close to 0
+
+         ! ice area (+epsi10 to set a threshold > 0 when there is no ice) 
+         zarea = glob_sum( 'icectl', SUM( a_i + epsi10, dim=3 ) * e1e2t )
+
+         IF( lwp ) THEN
             ! check conservation issues
-            IF ( ABS( zv ) > zv_sill )   WRITE(numout,*) 'violation volume [Mt/day]     (',cd_routine,') = ',zv
-            IF ( ABS( zs ) > zs_sill )   WRITE(numout,*) 'violation saline [psu*Mt/day] (',cd_routine,') = ',zs
-            IF ( ABS( zt ) > zt_sill )   WRITE(numout,*) 'violation enthalpy [GW]       (',cd_routine,') = ',zt
+            IF( ABS(zdiag_mass) > zchk_m * rn_icechk_glo * zarea ) &
+               &                   WRITE(numout,*)   cd_routine,' : violation mass cons. [kg] = ',zdiag_mass * rdt_ice
+            IF( ABS(zdiag_salt) > zchk_s * rn_icechk_glo * zarea ) &
+               &                   WRITE(numout,*)   cd_routine,' : violation salt cons. [g]  = ',zdiag_salt * rdt_ice
+            IF( ABS(zdiag_heat) > zchk_t * rn_icechk_glo * zarea ) &
+               &                   WRITE(numout,*)   cd_routine,' : violation heat cons. [J]  = ',zdiag_heat * rdt_ice
+            ! check negative values
+            IF( zdiag_vmin  < 0. ) WRITE(numout,*)   cd_routine,' : violation v_i < 0         = ',zdiag_vmin
+            IF( zdiag_amin  < 0. ) WRITE(numout,*)   cd_routine,' : violation a_i < 0         = ',zdiag_amin
+            IF( zdiag_smin  < 0. ) WRITE(numout,*)   cd_routine,' : violation s_i < 0         = ',zdiag_smin
+            IF( zdiag_eimin < 0. ) WRITE(numout,*)   cd_routine,' : violation e_i < 0         = ',zdiag_eimin
+            IF( zdiag_esmin < 0. ) WRITE(numout,*)   cd_routine,' : violation e_s < 0         = ',zdiag_esmin
             ! check maximum ice concentration
-            IF ( zamax > MAX( rn_amax_n,rn_amax_s)+epsi10 .AND. cd_routine /= 'icedyn_adv' .AND. cd_routine /= 'icedyn_rdgrft' )  &
-               &                         WRITE(numout,*) 'violation a_i>amax            (',cd_routine,') = ',zamax
-            ! check negative values
-            IF ( zvmin  < 0. )           WRITE(numout,*) 'violation v_i<0  [m]          (',cd_routine,') = ',zvmin
-            IF ( zamin  < 0. )           WRITE(numout,*) 'violation a_i<0               (',cd_routine,') = ',zamin
-            IF ( zsmin  < 0. )           WRITE(numout,*) 'violation s_i<0               (',cd_routine,') = ',zsmin
-            IF ( zeimin < 0. )           WRITE(numout,*) 'violation e_i<0               (',cd_routine,') = ',zeimin
-            IF ( zesmin < 0. )           WRITE(numout,*) 'violation e_s<0               (',cd_routine,') = ',zesmin
-!clem: the following check fails (I think...)
-!            IF ( ABS(zvtrp ) > zv_sill .AND. cd_routine == 'icedyn_adv' ) THEN
-!                                           WRITE(numout,*) 'violation vtrp [Mt/day]       (',cd_routine,') = ',zvtrp
-!                                           WRITE(numout,*) 'violation etrp [GW]           (',cd_routine,') = ',zetrp
-!            ENDIF
+            IF( zdiag_amax > MAX(rn_amax_n,rn_amax_s)+epsi10 .AND. cd_routine /= 'icedyn_adv' .AND. cd_routine /= 'icedyn_rdgrft' ) &
+               &                   WRITE(numout,*)   cd_routine,' : violation a_i > amax      = ',zdiag_amax
+            ! check if advection scheme is conservative
+            IF( ABS(zvtrp) > zchk_m * rn_icechk_glo * zarea .AND. cd_routine == 'icedyn_adv' ) &
+               &                   WRITE(numout,*)   cd_routine,' : violation adv scheme [kg] = ',zvtrp * rdt_ice
          ENDIF
          !
@@ -179,5 +165,4 @@
    END SUBROUTINE ice_cons_hsm
 
-
    SUBROUTINE ice_cons_final( cd_routine )
       !!-------------------------------------------------------------------
@@ -188,40 +173,175 @@
       !! ** Method  : This is an online diagnostics which can be activated with ln_icediachk=true
       !!              It prints in ocean.output if there is a violation of conservation at each time-step
-      !!              The thresholds (zv_sill, zs_sill, zt_sill) which determine the violation are set to
+      !!              The thresholds (zchk_m, zchk_s, zchk_t) which determine the violation are set to
       !!              a minimum of 1 mm of ice (over the ice area) that is lost/gained spuriously during 100 years.
       !!              For salt and heat thresholds, ice is considered to have a salinity of 10 
       !!              and a heat content of 3e5 J/kg (=latent heat of fusion) 
       !!-------------------------------------------------------------------
-      CHARACTER(len=*), INTENT(in)    :: cd_routine    ! name of the routine
-      REAL(wp)                        :: zqmass, zhfx, zsfx, zvfx
-      REAL(wp)                        :: zarea, zv_sill, zs_sill, zt_sill
-      REAL(wp), PARAMETER             :: zconv = 1.e-9 ! convert W to GW and kg to Mt
+      CHARACTER(len=*), INTENT(in) ::   cd_routine    ! name of the routine
+      REAL(wp) ::   zdiag_mass, zdiag_salt, zdiag_heat
+      REAL(wp) ::   zarea
       !!-------------------------------------------------------------------
 
       ! water flux
-      zvfx  = glob_sum( 'icectl', ( wfx_ice + wfx_snw + wfx_spr + wfx_sub + diag_vice + diag_vsnw ) * e1e2t ) * zconv * rday
-
-      ! salt flux
-      zsfx  = glob_sum( 'icectl', ( sfx + diag_sice ) * e1e2t ) * zconv * rday
-
-      ! heat flux
+      ! -- mass diag -- !
+      zdiag_mass = glob_sum( 'icectl', ( wfx_ice + wfx_snw + wfx_spr + wfx_sub + diag_vice + diag_vsnw ) * e1e2t )
+
+      ! -- salt diag -- !
+      zdiag_salt = glob_sum( 'icectl', ( sfx + diag_sice ) * e1e2t )
+
+      ! -- heat diag -- !
       ! clem: not the good formulation
-      !!zhfx  = glob_sum( 'icectl', ( qt_oce_ai - qt_atm_oi + diag_heat + hfx_thd + hfx_dyn + hfx_res + hfx_sub + hfx_spr  &
-      !!   &                        ) * e1e2t ) * zconv
-
-      ! set threshold values and calculate the ice area (+epsi10 to set a threshold > 0 when there is no ice) 
-      zarea   = glob_sum( 'icectl', SUM( a_i + epsi10, dim=3 ) * e1e2t ) * zconv ! in 1.e9 m2
-      zv_sill = zarea * 2.5e-5
-      zs_sill = zarea * 25.e-5
-      zt_sill = zarea * 10.e-5
-
-      IF(lwp) THEN
-         IF( ABS( zvfx ) > zv_sill )   WRITE(numout,*) 'violation vfx  [Mt/day]       (',cd_routine,') = ',zvfx
-         IF( ABS( zsfx ) > zs_sill )   WRITE(numout,*) 'violation sfx  [psu*Mt/day]   (',cd_routine,') = ',zsfx
-         !!IF( ABS( zhfx ) > zt_sill )   WRITE(numout,*) 'violation hfx  [GW]           (',cd_routine,') = ',zhfx
+      !!zdiag_heat  = glob_sum( 'icectl', ( qt_oce_ai - qt_atm_oi + diag_heat + hfx_thd + hfx_dyn + hfx_res + hfx_sub + hfx_spr  &
+      !!   &                              ) * e1e2t )
+
+      ! ice area (+epsi10 to set a threshold > 0 when there is no ice) 
+      zarea = glob_sum( 'icectl', SUM( a_i + epsi10, dim=3 ) * e1e2t )
+
+      IF( lwp ) THEN
+         IF( ABS(zdiag_mass) > zchk_m * rn_icechk_glo * zarea ) &
+            &                   WRITE(numout,*) cd_routine,' : violation mass cons. [kg] = ',zdiag_mass * rdt_ice
+         IF( ABS(zdiag_salt) > zchk_s * rn_icechk_glo * zarea ) &
+            &                   WRITE(numout,*) cd_routine,' : violation salt cons. [g]  = ',zdiag_salt * rdt_ice
+         !!IF( ABS(zdiag_heat) > zchk_t * rn_icechk_glo * zarea ) WRITE(numout,*) cd_routine,' : violation heat cons. [J]  = ',zdiag_heat * rdt_ice
       ENDIF
       !
    END SUBROUTINE ice_cons_final
 
+   SUBROUTINE ice_cons2D( icount, cd_routine, pdiag_v, pdiag_s, pdiag_t, pdiag_fv, pdiag_fs, pdiag_ft )
+      !!-------------------------------------------------------------------
+      !!                       ***  ROUTINE ice_cons2D ***
+      !!
+      !! ** Purpose : Test the conservation of heat, salt and mass for each ice routine
+      !!                     + test if ice concentration and volume are > 0
+      !!
+      !! ** Method  : This is an online diagnostics which can be activated with ln_icediachk=true
+      !!              It stops the code if there is a violation of conservation at any gridcell
+      !!-------------------------------------------------------------------
+      INTEGER         , INTENT(in) ::   icount        ! called at: =0 the begining of the routine, =1  the end
+      CHARACTER(len=*), INTENT(in) ::   cd_routine    ! name of the routine
+      REAL(wp)        , DIMENSION(jpi,jpj), INTENT(inout) ::   pdiag_v, pdiag_s, pdiag_t, pdiag_fv, pdiag_fs, pdiag_ft
+      !!
+      REAL(wp), DIMENSION(jpi,jpj) ::   zdiag_mass, zdiag_salt, zdiag_heat, &
+         &                              zdiag_amin, zdiag_vmin, zdiag_smin, zdiag_emin !!, zdiag_amax  
+      INTEGER ::   jl, jk
+      LOGICAL ::   ll_stop_m = .FALSE.
+      LOGICAL ::   ll_stop_s = .FALSE.
+      LOGICAL ::   ll_stop_t = .FALSE.
+      CHARACTER(len=120) ::   clnam   ! filename for the output
+      !!-------------------------------------------------------------------
+      !
+      IF( icount == 0 ) THEN
+
+         pdiag_v = SUM( v_i  * rhoi + v_s * rhos, dim=3 )
+         pdiag_s = SUM( sv_i * rhoi             , dim=3 )
+         pdiag_t = SUM( SUM( e_i, dim=4 ), dim=3 ) + SUM( SUM( e_s, dim=4 ), dim=3 )
+
+         ! mass flux
+         pdiag_fv = wfx_bog + wfx_bom + wfx_sum + wfx_sni + wfx_opw + wfx_res + wfx_dyn + wfx_lam + wfx_pnd  +  &
+            &       wfx_snw_sni + wfx_snw_sum + wfx_snw_dyn + wfx_snw_sub + wfx_ice_sub + wfx_spr
+         ! salt flux
+         pdiag_fs = sfx_bri + sfx_bog + sfx_bom + sfx_sum + sfx_sni + sfx_opw + sfx_res + sfx_dyn + sfx_sub + sfx_lam 
+         ! heat flux
+         pdiag_ft =   hfx_sum + hfx_bom + hfx_bog + hfx_dif + hfx_opw + hfx_snw  & 
+            &       - hfx_thd - hfx_dyn - hfx_res - hfx_sub - hfx_spr
+
+      ELSEIF( icount == 1 ) THEN
+
+         ! -- mass diag -- !
+         zdiag_mass =   ( SUM( v_i * rhoi + v_s * rhos, dim=3 ) - pdiag_v ) * r1_rdtice                             &
+            &         + ( wfx_bog + wfx_bom + wfx_sum + wfx_sni + wfx_opw + wfx_res + wfx_dyn + wfx_lam + wfx_pnd + &
+            &             wfx_snw_sni + wfx_snw_sum + wfx_snw_dyn + wfx_snw_sub + wfx_ice_sub + wfx_spr )           &
+            &         - pdiag_fv
+         IF( MAXVAL( ABS(zdiag_mass) ) > zchk_m * rn_icechk_cel )   ll_stop_m = .TRUE.
+         !
+         ! -- salt diag -- !
+         zdiag_salt =   ( SUM( sv_i * rhoi , dim=3 ) - pdiag_s ) * r1_rdtice                                                  &
+            &         + ( sfx_bri + sfx_bog + sfx_bom + sfx_sum + sfx_sni + sfx_opw + sfx_res + sfx_dyn + sfx_sub + sfx_lam ) &
+            &         - pdiag_fs
+         IF( MAXVAL( ABS(zdiag_salt) ) > zchk_s * rn_icechk_cel )   ll_stop_s = .TRUE.
+         !
+         ! -- heat diag -- !
+         zdiag_heat =   ( SUM( SUM( e_i, dim=4 ), dim=3 ) + SUM( SUM( e_s, dim=4 ), dim=3 ) - pdiag_t ) * r1_rdtice &
+            &         + (  hfx_sum + hfx_bom + hfx_bog + hfx_dif + hfx_opw + hfx_snw                                & 
+            &            - hfx_thd - hfx_dyn - hfx_res - hfx_sub - hfx_spr )                                        &
+            &         - pdiag_ft
+         IF( MAXVAL( ABS(zdiag_heat) ) > zchk_t * rn_icechk_cel )   ll_stop_t = .TRUE.
+         !
+         ! -- other diags -- !
+         ! a_i < 0
+         zdiag_amin(:,:) = 0._wp
+         DO jl = 1, jpl
+            WHERE( a_i(:,:,jl) < 0._wp )   zdiag_amin(:,:) = 1._wp
+         ENDDO
+         ! v_i < 0
+         zdiag_vmin(:,:) = 0._wp
+         DO jl = 1, jpl
+            WHERE( v_i(:,:,jl) < 0._wp )   zdiag_vmin(:,:) = 1._wp
+         ENDDO
+         ! s_i < 0
+         zdiag_smin(:,:) = 0._wp
+         DO jl = 1, jpl
+            WHERE( s_i(:,:,jl) < 0._wp )   zdiag_smin(:,:) = 1._wp
+         ENDDO
+         ! e_i < 0
+         zdiag_emin(:,:) = 0._wp
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               WHERE( e_i(:,:,jk,jl) < 0._wp )   zdiag_emin(:,:) = 1._wp
+            ENDDO
+         ENDDO
+         ! a_i > amax
+         !WHERE( SUM( a_i, dim=3 ) > ( MAX( rn_amax_n, rn_amax_s ) + epsi10 )   ;   zdiag_amax(:,:) = 1._wp
+         !ELSEWHERE                                                             ;   zdiag_amax(:,:) = 0._wp
+         !END WHERE
+
+         IF( ll_stop_m .OR. ll_stop_s .OR. ll_stop_t ) THEN
+            clnam = 'diag_ice_conservation_'//cd_routine
+            CALL ice_cons_wri( clnam, zdiag_mass, zdiag_salt, zdiag_heat, zdiag_amin, zdiag_vmin, zdiag_smin, zdiag_emin )
+         ENDIF
+
+         IF( ll_stop_m )   CALL ctl_stop( 'STOP', cd_routine//': ice mass conservation issue' )
+         IF( ll_stop_s )   CALL ctl_stop( 'STOP', cd_routine//': ice salt conservation issue' )
+         IF( ll_stop_t )   CALL ctl_stop( 'STOP', cd_routine//': ice heat conservation issue' )
+         
+      ENDIF
+
+   END SUBROUTINE ice_cons2D
+
+   SUBROUTINE ice_cons_wri( cdfile_name, pdiag_mass, pdiag_salt, pdiag_heat, pdiag_amin, pdiag_vmin, pdiag_smin, pdiag_emin )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE ice_cons_wri  ***
+      !!        
+      !! ** Purpose :   create a NetCDF file named cdfile_name which contains 
+      !!                the instantaneous fields when conservation issue occurs
+      !!
+      !! ** Method  :   NetCDF files using ioipsl
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*), INTENT( in ) ::   cdfile_name      ! name of the file created
+      REAL(wp), DIMENSION(:,:), INTENT( in ) ::   pdiag_mass, pdiag_salt, pdiag_heat, &
+         &                                        pdiag_amin, pdiag_vmin, pdiag_smin, pdiag_emin !!, pdiag_amax  
+      !!
+      INTEGER ::   inum
+      !!----------------------------------------------------------------------
+      ! 
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'ice_cons_wri : single instantaneous ice state'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~  named :', cdfile_name, '...nc'
+      IF(lwp) WRITE(numout,*)                
+
+      CALL iom_open( TRIM(cdfile_name), inum, ldwrt = .TRUE., kdlev = jpl )
+      
+      CALL iom_rstput( 0, 0, inum, 'cons_mass', pdiag_mass(:,:) , ktype = jp_r8 )    ! ice mass spurious lost/gain
+      CALL iom_rstput( 0, 0, inum, 'cons_salt', pdiag_salt(:,:) , ktype = jp_r8 )    ! ice salt spurious lost/gain
+      CALL iom_rstput( 0, 0, inum, 'cons_heat', pdiag_heat(:,:) , ktype = jp_r8 )    ! ice heat spurious lost/gain
+      ! other diags
+      CALL iom_rstput( 0, 0, inum, 'aneg_count', pdiag_amin(:,:) , ktype = jp_r8 )    ! 
+      CALL iom_rstput( 0, 0, inum, 'vneg_count', pdiag_vmin(:,:) , ktype = jp_r8 )    ! 
+      CALL iom_rstput( 0, 0, inum, 'sneg_count', pdiag_smin(:,:) , ktype = jp_r8 )    ! 
+      CALL iom_rstput( 0, 0, inum, 'eneg_count', pdiag_emin(:,:) , ktype = jp_r8 )    ! 
+      
+      CALL iom_close( inum )
+
+   END SUBROUTINE ice_cons_wri
    
    SUBROUTINE ice_ctl( kt )
@@ -246,14 +366,9 @@
       ialert_id = 2 ! reference number of this alert
       cl_alname(ialert_id) = ' Incompat vol and con         '    ! name of the alert
-
       DO jl = 1, jpl
          DO jj = 1, jpj
             DO ji = 1, jpi
                IF(  v_i(ji,jj,jl) /= 0._wp   .AND.   a_i(ji,jj,jl) == 0._wp   ) THEN
-                  !WRITE(numout,*) ' ALERTE 2 :   Incompatible volume and concentration '
-                  !WRITE(numout,*) ' at_i     ', at_i(ji,jj)
-                  !WRITE(numout,*) ' Point - category', ji, jj, jl
-                  !WRITE(numout,*) ' a_i *** a_i_b   ', a_i      (ji,jj,jl), a_i_b  (ji,jj,jl)
-                  !WRITE(numout,*) ' v_i *** v_i_b   ', v_i      (ji,jj,jl), v_i_b  (ji,jj,jl)
+                  WRITE(numout,*) ' ALERTE 2 :   Incompatible volume and concentration '
                   inb_alp(ialert_id) = inb_alp(ialert_id) + 1
                ENDIF
@@ -269,4 +384,5 @@
          DO ji = 1, jpi
             IF(   h_i(ji,jj,jl)  >  50._wp   ) THEN
+               WRITE(numout,*) ' ALERTE 3 :   Very thick ice'
                !CALL ice_prt( kt, ji, jj, 2, ' ALERTE 3 :   Very thick ice ' )
                inb_alp(ialert_id) = inb_alp(ialert_id) + 1
@@ -280,15 +396,21 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            IF(   MAX( ABS( u_ice(ji,jj) ), ABS( v_ice(ji,jj) ) ) > 1.5  .AND.  &
+            IF(   MAX( ABS( u_ice(ji,jj) ), ABS( v_ice(ji,jj) ) ) > 2.  .AND.  &
                &  at_i(ji,jj) > 0._wp   ) THEN
+               WRITE(numout,*) ' ALERTE 4 :   Very fast ice'
                !CALL ice_prt( kt, ji, jj, 1, ' ALERTE 4 :   Very fast ice ' )
-               !WRITE(numout,*) ' ice strength             : ', strength(ji,jj)
-               !WRITE(numout,*) ' oceanic stress utau      : ', utau(ji,jj) 
-               !WRITE(numout,*) ' oceanic stress vtau      : ', vtau(ji,jj)
-               !WRITE(numout,*) ' sea-ice stress utau_ice  : ', utau_ice(ji,jj) 
-               !WRITE(numout,*) ' sea-ice stress vtau_ice  : ', vtau_ice(ji,jj)
-               !WRITE(numout,*) ' sst                      : ', sst_m(ji,jj)
-               !WRITE(numout,*) ' sss                      : ', sss_m(ji,jj)
-               !WRITE(numout,*) 
+               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+            ENDIF
+         END DO
+      END DO
+
+      ! Alert on salt flux
+      ialert_id = 5 ! reference number of this alert
+      cl_alname(ialert_id) = ' High salt flux               ' ! name of the alert
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( ABS( sfx (ji,jj) ) > 1.0e-2 ) THEN  ! = 1 psu/day for 1m ocean depth
+               WRITE(numout,*) ' ALERTE 5 :   High salt flux'
+               !CALL ice_prt( kt, ji, jj, 3, ' ALERTE 5 :   High salt flux ' )
                inb_alp(ialert_id) = inb_alp(ialert_id) + 1
             ENDIF
@@ -302,14 +424,6 @@
          DO ji = 1, jpi
             IF(   tmask(ji,jj,1) <= 0._wp   .AND.   at_i(ji,jj) > 0._wp   ) THEN 
+               WRITE(numout,*) ' ALERTE 6 :   Ice on continents'
                !CALL ice_prt( kt, ji, jj, 1, ' ALERTE 6 :   Ice on continents ' )
-               !WRITE(numout,*) ' masks s, u, v        : ', tmask(ji,jj,1), umask(ji,jj,1), vmask(ji,jj,1) 
-               !WRITE(numout,*) ' sst                  : ', sst_m(ji,jj)
-               !WRITE(numout,*) ' sss                  : ', sss_m(ji,jj)
-               !WRITE(numout,*) ' at_i(ji,jj)          : ', at_i(ji,jj)
-               !WRITE(numout,*) ' v_ice(ji,jj)         : ', v_ice(ji,jj)
-               !WRITE(numout,*) ' v_ice(ji,jj-1)       : ', v_ice(ji,jj-1)
-               !WRITE(numout,*) ' u_ice(ji-1,jj)       : ', u_ice(ji-1,jj)
-               !WRITE(numout,*) ' u_ice(ji,jj)         : ', v_ice(ji,jj)
-               !
                inb_alp(ialert_id) = inb_alp(ialert_id) + 1
             ENDIF
@@ -325,8 +439,6 @@
             DO ji = 1, jpi
                IF( s_i(ji,jj,jl) < 0.1 .AND. a_i(ji,jj,jl) > 0._wp ) THEN
+                  WRITE(numout,*) ' ALERTE 7 :   Very fresh ice'
 !                 CALL ice_prt(kt,ji,jj,1, ' ALERTE 7 :   Very fresh ice ' )
-!                 WRITE(numout,*) ' sst                  : ', sst_m(ji,jj)
-!                 WRITE(numout,*) ' sss                  : ', sss_m(ji,jj)
-!                 WRITE(numout,*) 
                   inb_alp(ialert_id) = inb_alp(ialert_id) + 1
                ENDIF
@@ -335,4 +447,19 @@
       END DO
 !
+      ! Alert if qns very big
+      ialert_id = 8 ! reference number of this alert
+      cl_alname(ialert_id) = ' fnsolar very big             ' ! name of the alert
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( ABS( qns(ji,jj) ) > 1500._wp .AND. at_i(ji,jj) > 0._wp ) THEN
+               !
+               WRITE(numout,*) ' ALERTE 8 :   Very high non-solar heat flux'
+               !CALL ice_prt( kt, ji, jj, 2, '   ')
+               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+               !
+            ENDIF
+         END DO
+      END DO
+      !+++++
 
 !     ! Alert if too old ice
@@ -345,4 +472,5 @@
                       ( ABS( o_i(ji,jj,jl) ) < 0._wp) ) .AND. &
                              ( a_i(ji,jj,jl) > 0._wp ) ) THEN
+                  WRITE(numout,*) ' ALERTE 9 :   Wrong ice age'
                   !CALL ice_prt( kt, ji, jj, 1, ' ALERTE 9 :   Wrong ice age ')
                   inb_alp(ialert_id) = inb_alp(ialert_id) + 1
@@ -351,44 +479,5 @@
          END DO
       END DO
- 
-      ! Alert on salt flux
-      ialert_id = 5 ! reference number of this alert
-      cl_alname(ialert_id) = ' High salt flux               ' ! name of the alert
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( ABS( sfx (ji,jj) ) > 1.0e-2 ) THEN  ! = 1 psu/day for 1m ocean depth
-               !CALL ice_prt( kt, ji, jj, 3, ' ALERTE 5 :   High salt flux ' )
-               !DO jl = 1, jpl
-                  !WRITE(numout,*) ' Category no: ', jl
-                  !WRITE(numout,*) ' a_i        : ', a_i      (ji,jj,jl) , ' a_i_b      : ', a_i_b  (ji,jj,jl)   
-                  !WRITE(numout,*) ' v_i        : ', v_i      (ji,jj,jl) , ' v_i_b      : ', v_i_b  (ji,jj,jl)   
-                  !WRITE(numout,*) ' '
-               !END DO
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-            ENDIF
-         END DO
-      END DO
-
-      ! Alert if qns very big
-      ialert_id = 8 ! reference number of this alert
-      cl_alname(ialert_id) = ' fnsolar very big             ' ! name of the alert
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( ABS( qns(ji,jj) ) > 1500._wp .AND. at_i(ji,jj) > 0._wp ) THEN
-               !
-               !WRITE(numout,*) ' ALERTE 8 :   Very high non-solar heat flux'
-               !WRITE(numout,*) ' ji, jj    : ', ji, jj
-               !WRITE(numout,*) ' qns       : ', qns(ji,jj)
-               !WRITE(numout,*) ' sst       : ', sst_m(ji,jj)
-               !WRITE(numout,*) ' sss       : ', sss_m(ji,jj)
-               !
-               !CALL ice_prt( kt, ji, jj, 2, '   ')
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-               !
-            ENDIF
-         END DO
-      END DO
-      !+++++
- 
+  
       ! Alert if very warm ice
       ialert_id = 10 ! reference number of this alert
@@ -400,13 +489,8 @@
                DO ji = 1, jpi
                   ztmelts    =  -rTmlt * sz_i(ji,jj,jk,jl) + rt0
-                  IF( t_i(ji,jj,jk,jl) >= ztmelts  .AND.  v_i(ji,jj,jl) > 1.e-10   &
-                     &                             .AND.  a_i(ji,jj,jl) > 0._wp   ) THEN
-                     !WRITE(numout,*) ' ALERTE 10 :   Very warm ice'
-                     !WRITE(numout,*) ' ji, jj, jk, jl : ', ji, jj, jk, jl
-                     !WRITE(numout,*) ' t_i : ', t_i(ji,jj,jk,jl)
-                     !WRITE(numout,*) ' e_i : ', e_i(ji,jj,jk,jl)
-                     !WRITE(numout,*) ' sz_i: ', sz_i(ji,jj,jk,jl)
-                     !WRITE(numout,*) ' ztmelts : ', ztmelts
-                     inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+                  IF( t_i(ji,jj,jk,jl) > ztmelts  .AND.  v_i(ji,jj,jl) > 1.e-10   &
+                     &                            .AND.  a_i(ji,jj,jl) > 0._wp   ) THEN
+                     WRITE(numout,*) ' ALERTE 10 :   Very warm ice'
+                    inb_alp(ialert_id) = inb_alp(ialert_id) + 1
                   ENDIF
                END DO
@@ -435,5 +519,4 @@
    END SUBROUTINE ice_ctl
  
-   
    SUBROUTINE ice_prt( kt, ki, kj, kn, cd1 )
       !!-------------------------------------------------------------------
@@ -443,5 +526,5 @@
       !!                in ocean.ouput 
       !!                3 possibilities exist 
-      !!                n = 1/-1 -> simple ice state (plus Mechanical Check if -1)
+      !!                n = 1/-1 -> simple ice state
       !!                n = 2    -> exhaustive state
       !!                n = 3    -> ice/ocean salt fluxes
@@ -482,6 +565,6 @@
                WRITE(numout,*) ' - Cell values '
                WRITE(numout,*) '   ~~~~~~~~~~~ '
-               WRITE(numout,*) ' cell area     : ', e1e2t(ji,jj)
                WRITE(numout,*) ' at_i          : ', at_i(ji,jj)       
+               WRITE(numout,*) ' ato_i         : ', ato_i(ji,jj)       
                WRITE(numout,*) ' vt_i          : ', vt_i(ji,jj)       
                WRITE(numout,*) ' vt_s          : ', vt_s(ji,jj)       
@@ -503,13 +586,4 @@
                END DO
             ENDIF
-            IF( kn == -1 ) THEN
-               WRITE(numout,*) ' Mechanical Check ************** '
-               WRITE(numout,*) ' Check what means ice divergence '
-               WRITE(numout,*) ' Total ice concentration ', at_i (ji,jj)
-               WRITE(numout,*) ' Total lead fraction     ', ato_i(ji,jj)
-               WRITE(numout,*) ' Sum of both             ', ato_i(ji,jj) + at_i(ji,jj)
-               WRITE(numout,*) ' Sum of both minus 1     ', ato_i(ji,jj) + at_i(ji,jj) - 1.00
-            ENDIF
-            
 
             !--------------------
@@ -525,5 +599,4 @@
                WRITE(numout,*) ' - Cell values '
                WRITE(numout,*) '   ~~~~~~~~~~~ '
-               WRITE(numout,*) ' cell area     : ', e1e2t(ji,jj)
                WRITE(numout,*) ' at_i          : ', at_i(ji,jj)       
                WRITE(numout,*) ' vt_i          : ', vt_i(ji,jj)       
@@ -624,6 +697,6 @@
       !!
       !!-------------------------------------------------------------------
-      CHARACTER(len=*), INTENT(in)  :: cd_routine    ! name of the routine
-      INTEGER                       :: jk, jl        ! dummy loop indices
+      CHARACTER(len=*), INTENT(in) ::   cd_routine    ! name of the routine
+      INTEGER                      ::   jk, jl        ! dummy loop indices
       
       CALL prt_ctl_info(' ========== ')
@@ -684,5 +757,5 @@
       
    END SUBROUTINE ice_prt3D
-
+      
 #else
    !!----------------------------------------------------------------------
Index: /NEMO/trunk/src/ICE/icedia.F90
===================================================================
--- /NEMO/trunk/src/ICE/icedia.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icedia.F90	(revision 11536)
@@ -34,5 +34,6 @@
    PUBLIC   ice_dia_init   ! called in icestp.F90
 
-   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   vol_loc_ini, sal_loc_ini, tem_loc_ini ! initial volume, salt and heat contents
+   REAL(wp), SAVE ::   z1_e1e2  ! inverse of the ocean area
+   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   vol_loc_ini, sal_loc_ini, tem_loc_ini                    ! initial volume, salt and heat contents
    REAL(wp)                              ::   frc_sal, frc_voltop, frc_volbot, frc_temtop, frc_tembot  ! global forcing trends
    
@@ -80,19 +81,34 @@
       ENDIF
 
-!!gm glob_sum includes a " * tmask_i ", so remove  " * tmask(:,:,1) "
-
+      IF( kt == nit000 ) THEN
+         z1_e1e2 = 1._wp / glob_sum( 'icedia', e1e2t(:,:) )
+      ENDIF
+      
       ! ----------------------- !
-      ! 1 -  Contents !
+      ! 1 -  Contents           !
       ! ----------------------- !
-      zbg_ivol = glob_sum( 'icedia', vt_i(:,:) * e1e2t(:,:) ) * 1.e-9                  ! ice volume (km3)
-      zbg_svol = glob_sum( 'icedia', vt_s(:,:) * e1e2t(:,:) ) * 1.e-9                  ! snow volume (km3)
-      zbg_area = glob_sum( 'icedia', at_i(:,:) * e1e2t(:,:) ) * 1.e-6                  ! area (km2)
-      zbg_isal = glob_sum( 'icedia', SUM( sv_i(:,:,:), dim=3 ) * e1e2t(:,:) ) * 1.e-9  ! salt content (pss*km3)
-      zbg_item = glob_sum( 'icedia', et_i * e1e2t(:,:) ) * 1.e-20                      ! heat content (1.e20 J)
-      zbg_stem = glob_sum( 'icedia', et_s * e1e2t(:,:) ) * 1.e-20                      ! heat content (1.e20 J)
-      
+      IF(  iom_use('ibgvol_tot' ) .OR. iom_use('sbgvol_tot' ) .OR. iom_use('ibgarea_tot') .OR. &
+         & iom_use('ibgsalt_tot') .OR. iom_use('ibgheat_tot') .OR. iom_use('sbgheat_tot') ) THEN
+
+         zbg_ivol = glob_sum( 'icedia', vt_i(:,:) * e1e2t(:,:) ) * 1.e-9  ! ice volume (km3)
+         zbg_svol = glob_sum( 'icedia', vt_s(:,:) * e1e2t(:,:) ) * 1.e-9  ! snow volume (km3)
+         zbg_area = glob_sum( 'icedia', at_i(:,:) * e1e2t(:,:) ) * 1.e-6  ! area (km2)
+         zbg_isal = glob_sum( 'icedia', st_i(:,:) * e1e2t(:,:) ) * 1.e-9  ! salt content (pss*km3)
+         zbg_item = glob_sum( 'icedia', et_i(:,:) * e1e2t(:,:) ) * 1.e-20 ! heat content (1.e20 J)
+         zbg_stem = glob_sum( 'icedia', et_s(:,:) * e1e2t(:,:) ) * 1.e-20 ! heat content (1.e20 J)
+
+         CALL iom_put( 'ibgvol_tot'  , zbg_ivol ) 
+         CALL iom_put( 'sbgvol_tot'  , zbg_svol ) 
+         CALL iom_put( 'ibgarea_tot' , zbg_area ) 
+         CALL iom_put( 'ibgsalt_tot' , zbg_isal ) 
+         CALL iom_put( 'ibgheat_tot' , zbg_item ) 
+         CALL iom_put( 'sbgheat_tot' , zbg_stem ) 
+ 
+      ENDIF
+
       ! ---------------------------!
       ! 2 - Trends due to forcing  !
       ! ---------------------------!
+      ! they must be kept outside an IF(iom_use) because of the call to dia_rst below
       z_frc_volbot = r1_rau0 * glob_sum( 'icedia', -( wfx_ice(:,:) + wfx_snw(:,:) + wfx_err_sub(:,:) ) * e1e2t(:,:) ) * 1.e-9   ! freshwater flux ice/snow-ocean 
       z_frc_voltop = r1_rau0 * glob_sum( 'icedia', -( wfx_sub(:,:) + wfx_spr(:,:) )                    * e1e2t(:,:) ) * 1.e-9   ! freshwater flux ice/snow-atm
@@ -106,52 +122,36 @@
       frc_temtop  = frc_temtop  + z_frc_temtop  * rdt_ice ! 1.e20 J
       frc_tembot  = frc_tembot  + z_frc_tembot  * rdt_ice ! 1.e20 J
+
+      CALL iom_put( 'ibgfrcvoltop' , frc_voltop )   ! vol  forcing ice/snw-atm          (km3 equivalent ocean water) 
+      CALL iom_put( 'ibgfrcvolbot' , frc_volbot )   ! vol  forcing ice/snw-ocean        (km3 equivalent ocean water) 
+      CALL iom_put( 'ibgfrcsal'    , frc_sal    )   ! sal - forcing                     (psu*km3 equivalent ocean water)   
+      CALL iom_put( 'ibgfrctemtop' , frc_temtop )   ! heat on top of ice/snw/ocean      (1.e20 J)   
+      CALL iom_put( 'ibgfrctembot' , frc_tembot )   ! heat on top of ocean(below ice)   (1.e20 J)   
+
+      IF(  iom_use('ibgfrchfxtop') .OR. iom_use('ibgfrchfxbot') ) THEN
+         CALL iom_put( 'ibgfrchfxtop' , frc_temtop * z1_e1e2 * 1.e-20 * kt*rdt ) ! heat on top of ice/snw/ocean      (W/m2)
+         CALL iom_put( 'ibgfrchfxbot' , frc_tembot * z1_e1e2 * 1.e-20 * kt*rdt ) ! heat on top of ocean(below ice)   (W/m2) 
+      ENDIF
+      
+      ! ---------------------------------- !
+      ! 3 -  Content variations and drifts !
+      ! ---------------------------------- !
+      IF(  iom_use('ibgvolume') .OR. iom_use('ibgsaltco') .OR. iom_use('ibgheatco') .OR. iom_use('ibgheatfx') ) THEN
             
-      ! ----------------------- !
-      ! 3 -  Content variations !
-      ! ----------------------- !
-      zdiff_vol = r1_rau0 * glob_sum( 'icedia', ( rhoi*vt_i(:,:) + rhos*vt_s(:,:) - vol_loc_ini(:,:) ) * e1e2t(:,:) ) * 1.e-9   ! freshwater trend (km3) 
-      zdiff_sal = r1_rau0 * glob_sum( 'icedia', ( rhoi* SUM( sv_i(:,:,:), dim=3 ) - sal_loc_ini(:,:) ) * e1e2t(:,:) ) * 1.e-9   ! salt content trend (km3*pss)
-      zdiff_tem =           glob_sum( 'icedia', ( et_i(:,:) + et_s(:,:)           - tem_loc_ini(:,:) ) * e1e2t(:,:) ) * 1.e-20  ! heat content trend (1.e20 J)
-      !                               + SUM( qevap_ice * a_i_b, dim=3 )       !! clem: I think this term should not be there (but needs a check)
-
-      ! ----------------------- !
-      ! 4 -  Drifts             !
-      ! ----------------------- !
-      zdiff_vol = zdiff_vol - ( frc_voltop + frc_volbot )
-      zdiff_sal = zdiff_sal - frc_sal
-      zdiff_tem = zdiff_tem - ( frc_tembot - frc_temtop )
-
-      ! ----------------------- !
-      ! 5 - Diagnostics writing !
-      ! ----------------------- !
-!!gm I don't understand the division by the ocean surface (i.e. glob_sum( 'icedia', e1e2t(:,:) ) * 1.e-20 * kt*rdt )
-!!   and its multiplication bu kt ! is it really what we want ? what is this quantity ?
-!!   IF it is really what we want, compute it at kt=nit000, not 3 time by time-step !
-!!   kt*rdt  : you mean rdtice ?
-!!gm
-      !
-      IF( iom_use('ibgvolume')    )   CALL iom_put( 'ibgvolume' , zdiff_vol     )   ! ice/snow volume  drift            (km3 equivalent ocean water)         
-      IF( iom_use('ibgsaltco')    )   CALL iom_put( 'ibgsaltco' , zdiff_sal     )   ! ice salt content drift            (psu*km3 equivalent ocean water)
-      IF( iom_use('ibgheatco')    )   CALL iom_put( 'ibgheatco' , zdiff_tem     )   ! ice/snow heat content drift       (1.e20 J)
-      IF( iom_use('ibgheatfx')    )   CALL iom_put( 'ibgheatfx' ,               &   ! ice/snow heat flux drift          (W/m2)
-         &                                                     zdiff_tem /glob_sum( 'icedia', e1e2t(:,:) * 1.e-20 * kt*rdt ) )
-
-      IF( iom_use('ibgfrcvoltop') )   CALL iom_put( 'ibgfrcvoltop' , frc_voltop )   ! vol  forcing ice/snw-atm          (km3 equivalent ocean water) 
-      IF( iom_use('ibgfrcvolbot') )   CALL iom_put( 'ibgfrcvolbot' , frc_volbot )   ! vol  forcing ice/snw-ocean        (km3 equivalent ocean water) 
-      IF( iom_use('ibgfrcsal')    )   CALL iom_put( 'ibgfrcsal'    , frc_sal    )   ! sal - forcing                     (psu*km3 equivalent ocean water)   
-      IF( iom_use('ibgfrctemtop') )   CALL iom_put( 'ibgfrctemtop' , frc_temtop )   ! heat on top of ice/snw/ocean      (1.e20 J)   
-      IF( iom_use('ibgfrctembot') )   CALL iom_put( 'ibgfrctembot' , frc_tembot )   ! heat on top of ocean(below ice)   (1.e20 J)   
-      IF( iom_use('ibgfrchfxtop') )   CALL iom_put( 'ibgfrchfxtop' ,            &   ! heat on top of ice/snw/ocean      (W/m2) 
-         &                                                          frc_temtop / glob_sum( 'icedia', e1e2t(:,:) ) * 1.e-20 * kt*rdt  )
-      IF( iom_use('ibgfrchfxbot') )   CALL iom_put( 'ibgfrchfxbot' ,            &   ! heat on top of ocean(below ice)   (W/m2) 
-         &                                                          frc_tembot / glob_sum( 'icedia', e1e2t(:,:) ) * 1.e-20 * kt*rdt  )
-
-      IF( iom_use('ibgvol_tot' )  )   CALL iom_put( 'ibgvol_tot'  , zbg_ivol     )   ! ice volume                       (km3)
-      IF( iom_use('sbgvol_tot' )  )   CALL iom_put( 'sbgvol_tot'  , zbg_svol     )   ! snow volume                      (km3)
-      IF( iom_use('ibgarea_tot')  )   CALL iom_put( 'ibgarea_tot' , zbg_area     )   ! ice area                         (km2)
-      IF( iom_use('ibgsalt_tot')  )   CALL iom_put( 'ibgsalt_tot' , zbg_isal     )   ! ice salinity content             (pss*km3)
-      IF( iom_use('ibgheat_tot')  )   CALL iom_put( 'ibgheat_tot' , zbg_item     )   ! ice heat content                 (1.e20 J)
-      IF( iom_use('sbgheat_tot')  )   CALL iom_put( 'sbgheat_tot' , zbg_stem     )   ! snow heat content                (1.e20 J)
-      !
+         zdiff_vol = r1_rau0 * glob_sum( 'icedia', ( rhoi*vt_i(:,:) + rhos*vt_s(:,:) - vol_loc_ini(:,:) ) * e1e2t(:,:) ) * 1.e-9   ! freshwater trend (km3) 
+         zdiff_sal = r1_rau0 * glob_sum( 'icedia', ( rhoi*st_i(:,:)                  - sal_loc_ini(:,:) ) * e1e2t(:,:) ) * 1.e-9   ! salt content trend (km3*pss)
+         zdiff_tem =           glob_sum( 'icedia', ( et_i(:,:) + et_s(:,:)           - tem_loc_ini(:,:) ) * e1e2t(:,:) ) * 1.e-20  ! heat content trend (1.e20 J)
+         !                               + SUM( qevap_ice * a_i_b, dim=3 )       !! clem: I think this term should not be there (but needs a check)
+         
+         zdiff_vol = zdiff_vol - ( frc_voltop + frc_volbot )
+         zdiff_sal = zdiff_sal - frc_sal
+         zdiff_tem = zdiff_tem - ( frc_tembot - frc_temtop )
+         
+         CALL iom_put( 'ibgvolume' , zdiff_vol )   ! ice/snow volume  drift            (km3 equivalent ocean water)         
+         CALL iom_put( 'ibgsaltco' , zdiff_sal )   ! ice salt content drift            (psu*km3 equivalent ocean water)
+         CALL iom_put( 'ibgheatco' , zdiff_tem )   ! ice/snow heat content drift       (1.e20 J)
+         !
+      ENDIF
+      
       IF( lrst_ice )   CALL ice_dia_rst( 'WRITE', kt_ice )
       !
@@ -175,13 +175,13 @@
       INTEGER            ::   ios, ierror   ! local integer
       !!
-      NAMELIST/namdia/ ln_icediachk, ln_icediahsb, ln_icectl, iiceprt, jiceprt  
+      NAMELIST/namdia/ ln_icediachk, rn_icechk_cel, rn_icechk_glo, ln_icediahsb, ln_icectl, iiceprt, jiceprt  
       !!----------------------------------------------------------------------
       !
       REWIND( numnam_ice_ref )      ! Namelist namdia in reference namelist : Parameters for ice
       READ  ( numnam_ice_ref, namdia, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdia in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdia in reference namelist' )
       REWIND( numnam_ice_cfg )      ! Namelist namdia in configuration namelist : Parameters for ice
       READ  ( numnam_ice_cfg, namdia, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdia in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdia in configuration namelist' )
       IF(lwm) WRITE ( numoni, namdia )
       !
@@ -191,8 +191,10 @@
          WRITE(numout,*) ' ~~~~~~~~~~~'
          WRITE(numout,*) '   Namelist namdia:'
-         WRITE(numout,*) '      Diagnose online heat/mass/salt budget      ln_icediachk = ', ln_icediachk
-         WRITE(numout,*) '      Output          heat/mass/salt budget      ln_icediahsb = ', ln_icediahsb
-         WRITE(numout,*) '      control prints for a given grid point      ln_icectl    = ', ln_icectl
-         WRITE(numout,*) '         chosen grid point position         (iiceprt,jiceprt) = (', iiceprt,',', jiceprt,')'
+         WRITE(numout,*) '      Diagnose online heat/mass/salt conservation ln_icediachk  = ', ln_icediachk
+         WRITE(numout,*) '         threshold for conservation (gridcell)    rn_icechk_cel = ', rn_icechk_cel
+         WRITE(numout,*) '         threshold for conservation (global)      rn_icechk_glo = ', rn_icechk_glo
+         WRITE(numout,*) '      Output          heat/mass/salt budget       ln_icediahsb  = ', ln_icediahsb
+         WRITE(numout,*) '      control prints for a given grid point       ln_icectl     = ', ln_icectl
+         WRITE(numout,*) '         chosen grid point position          (iiceprt,jiceprt)  = (', iiceprt,',', jiceprt,')'
       ENDIF
       !      
@@ -248,5 +250,5 @@
             vol_loc_ini(:,:) = rhoi * vt_i(:,:) + rhos * vt_s(:,:)  ! ice/snow volume (kg/m2)
             tem_loc_ini(:,:) = et_i(:,:) + et_s(:,:)                ! ice/snow heat content (J)
-            sal_loc_ini(:,:) = rhoi * SUM( sv_i(:,:,:), dim=3 )     ! ice salt content (pss*kg/m2)
+            sal_loc_ini(:,:) = rhoi * st_i(:,:)                     ! ice salt content (pss*kg/m2)
          ENDIF
          !
Index: /NEMO/trunk/src/ICE/icedyn.F90
===================================================================
--- /NEMO/trunk/src/ICE/icedyn.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icedyn.F90	(revision 11536)
@@ -163,5 +163,7 @@
             END DO
             CALL lbc_lnk( 'icedyn', zdivu_i, 'T', 1. )
-            CALL iom_put( "icediv" , zdivu_i(:,:) )
+            ! output
+            CALL iom_put( 'icediv' , zdivu_i )
+
             DEALLOCATE( zdivu_i )
 
@@ -219,13 +221,13 @@
       NAMELIST/namdyn/ ln_dynALL, ln_dynRHGADV, ln_dynADV1D, ln_dynADV2D, rn_uice, rn_vice,  &
          &             rn_ishlat ,                                                           &
-         &             ln_landfast_L16, ln_landfast_home, rn_depfra, rn_icebfr, rn_lfrelax, rn_tensile
+         &             ln_landfast_L16, rn_depfra, rn_icebfr, rn_lfrelax, rn_tensile
       !!-------------------------------------------------------------------
       !
       REWIND( numnam_ice_ref )         ! Namelist namdyn in reference namelist : Ice dynamics
       READ  ( numnam_ice_ref, namdyn, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn in reference namelist' )
       REWIND( numnam_ice_cfg )         ! Namelist namdyn in configuration namelist : Ice dynamics
       READ  ( numnam_ice_cfg, namdyn, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn in configuration namelist' )
       IF(lwm) WRITE( numoni, namdyn )
       !
@@ -242,5 +244,4 @@
          WRITE(numout,*) '      lateral boundary condition for sea ice dynamics        rn_ishlat       = ', rn_ishlat
          WRITE(numout,*) '      Landfast: param from Lemieux 2016                      ln_landfast_L16 = ', ln_landfast_L16
-         WRITE(numout,*) '      Landfast: param from home made                         ln_landfast_home= ', ln_landfast_home
          WRITE(numout,*) '         fraction of ocean depth that ice must reach         rn_depfra       = ', rn_depfra
          WRITE(numout,*) '         maximum bottom stress per unit area of contact      rn_icebfr       = ', rn_icebfr
@@ -269,9 +270,5 @@
       ENDIF
       !                                      !--- Landfast ice
-      IF( .NOT.ln_landfast_L16 .AND. .NOT.ln_landfast_home )   tau_icebfr(:,:) = 0._wp
-      !
-      IF ( ln_landfast_L16 .AND. ln_landfast_home ) THEN
-         CALL ctl_stop( 'ice_dyn_init: choose one and only one landfast parameterization (ln_landfast_L16 or ln_landfast_home)' )
-      ENDIF
+      IF( .NOT.ln_landfast_L16 )   tau_icebfr(:,:) = 0._wp
       !
       CALL ice_dyn_rdgrft_init          ! set ice ridging/rafting parameters
Index: /NEMO/trunk/src/ICE/icedyn_adv.F90
===================================================================
--- /NEMO/trunk/src/ICE/icedyn_adv.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icedyn_adv.F90	(revision 11536)
@@ -100,9 +100,9 @@
       diag_trp_vi(:,:) = SUM(     v_i (:,:,:)          - v_i_b (:,:,:)                  , dim=3 ) * r1_rdtice
       diag_trp_vs(:,:) = SUM(     v_s (:,:,:)          - v_s_b (:,:,:)                  , dim=3 ) * r1_rdtice
-      IF( iom_use('icemtrp') )   CALL iom_put( "icemtrp" , diag_trp_vi * rhoi          )   ! ice mass transport
-      IF( iom_use('snwmtrp') )   CALL iom_put( "snwmtrp" , diag_trp_vs * rhos          )   ! snw mass transport
-      IF( iom_use('salmtrp') )   CALL iom_put( "salmtrp" , diag_trp_sv * rhoi * 1.e-03 )   ! salt mass transport (kg/m2/s)
-      IF( iom_use('dihctrp') )   CALL iom_put( "dihctrp" , -diag_trp_ei                )   ! advected ice heat content (W/m2)
-      IF( iom_use('dshctrp') )   CALL iom_put( "dshctrp" , -diag_trp_es                )   ! advected snw heat content (W/m2)
+      IF( iom_use('icemtrp') )   CALL iom_put( 'icemtrp' ,  diag_trp_vi * rhoi          )   ! ice mass transport
+      IF( iom_use('snwmtrp') )   CALL iom_put( 'snwmtrp' ,  diag_trp_vs * rhos          )   ! snw mass transport
+      IF( iom_use('salmtrp') )   CALL iom_put( 'salmtrp' ,  diag_trp_sv * rhoi * 1.e-03 )   ! salt mass transport (kg/m2/s)
+      IF( iom_use('dihctrp') )   CALL iom_put( 'dihctrp' , -diag_trp_ei                 )   ! advected ice heat content (W/m2)
+      IF( iom_use('dshctrp') )   CALL iom_put( 'dshctrp' , -diag_trp_es                 )   ! advected snw heat content (W/m2)
 
       ! controls
@@ -133,8 +133,8 @@
       REWIND( numnam_ice_ref )         ! Namelist namdyn_adv in reference namelist : Ice dynamics
       READ  ( numnam_ice_ref, namdyn_adv, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_adv in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_adv in reference namelist' )
       REWIND( numnam_ice_cfg )         ! Namelist namdyn_adv in configuration namelist : Ice dynamics
       READ  ( numnam_ice_cfg, namdyn_adv, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_adv in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_adv in configuration namelist' )
       IF(lwm) WRITE( numoni, namdyn_adv )
       !
Index: /NEMO/trunk/src/ICE/icedyn_rdgrft.F90
===================================================================
--- /NEMO/trunk/src/ICE/icedyn_rdgrft.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icedyn_rdgrft.F90	(revision 11536)
@@ -145,4 +145,5 @@
       IF( ln_timing    )   CALL timing_start('icedyn_rdgrft')                                                             ! timing
       IF( ln_icediachk )   CALL ice_cons_hsm(0, 'icedyn_rdgrft', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+      IF( ln_icediachk )   CALL ice_cons2D  (0, 'icedyn_rdgrft',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft) ! conservation
 
       IF( kt == nit000 ) THEN
@@ -276,6 +277,7 @@
 
       ! controls
+      IF( ln_ctl       )   CALL ice_prt3D   ('icedyn_rdgrft')                                                             ! prints
       IF( ln_icediachk )   CALL ice_cons_hsm(1, 'icedyn_rdgrft', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
-      IF( ln_ctl       )   CALL ice_prt3D   ('icedyn_rdgrft')                                                             ! prints
+      IF( ln_icediachk )   CALL ice_cons2D  (1, 'icedyn_rdgrft',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft) ! conservation
       IF( ln_timing    )   CALL timing_stop ('icedyn_rdgrft')                                                             ! timing
       !
@@ -916,8 +918,8 @@
       REWIND( numnam_ice_ref )              ! Namelist namicetdme in reference namelist : Ice mechanical ice redistribution
       READ  ( numnam_ice_ref, namdyn_rdgrft, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_rdgrft in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_rdgrft in reference namelist' )
       REWIND( numnam_ice_cfg )              ! Namelist namdyn_rdgrft in configuration namelist : Ice mechanical ice redistribution
       READ  ( numnam_ice_cfg, namdyn_rdgrft, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_rdgrft in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_rdgrft in configuration namelist' )
       IF(lwm) WRITE ( numoni, namdyn_rdgrft )
       !
Index: /NEMO/trunk/src/ICE/icedyn_rhg.F90
===================================================================
--- /NEMO/trunk/src/ICE/icedyn_rhg.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icedyn_rhg.F90	(revision 11536)
@@ -64,4 +64,5 @@
       IF( ln_timing    )   CALL timing_start('icedyn_rhg')                                                             ! timing
       IF( ln_icediachk )   CALL ice_cons_hsm(0, 'icedyn_rhg', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+      IF( ln_icediachk )   CALL ice_cons2D  (0, 'icedyn_rhg',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft) ! conservation
       !
       IF( kt == nit000 .AND. lwp ) THEN
@@ -69,11 +70,4 @@
          WRITE(numout,*)'ice_dyn_rhg: sea-ice rheology'
          WRITE(numout,*)'~~~~~~~~~~~'
-      ENDIF
-      !
-      IF( ln_landfast_home ) THEN      !-- Landfast ice parameterization
-         tau_icebfr(:,:) = 0._wp
-         DO jl = 1, jpl
-            WHERE( h_i(:,:,jl) > ht_n(:,:) * rn_depfra )   tau_icebfr(:,:) = tau_icebfr(:,:) + a_i(:,:,jl) * rn_icebfr
-         END DO
       ENDIF
       !
@@ -94,6 +88,7 @@
       !
       ! controls
+      IF( ln_ctl       )   CALL ice_prt3D   ('icedyn_rhg')                                                             ! prints
       IF( ln_icediachk )   CALL ice_cons_hsm(1, 'icedyn_rhg', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
-      IF( ln_ctl       )   CALL ice_prt3D   ('icedyn_rhg')                                                             ! prints
+      IF( ln_icediachk )   CALL ice_cons2D  (1, 'icedyn_rhg',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft) ! conservation
       IF( ln_timing    )   CALL timing_stop ('icedyn_rhg')                                                             ! timing
       !
@@ -120,8 +115,8 @@
       REWIND( numnam_ice_ref )         ! Namelist namdyn_rhg in reference namelist : Ice dynamics
       READ  ( numnam_ice_ref, namdyn_rhg, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_rhg in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_rhg in reference namelist' )
       REWIND( numnam_ice_cfg )         ! Namelist namdyn_rhg in configuration namelist : Ice dynamics
       READ  ( numnam_ice_cfg, namdyn_rhg, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namdyn_rhg in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namdyn_rhg in configuration namelist' )
       IF(lwm) WRITE ( numoni, namdyn_rhg )
       !
Index: /NEMO/trunk/src/ICE/icedyn_rhg_evp.F90
===================================================================
--- /NEMO/trunk/src/ICE/icedyn_rhg_evp.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icedyn_rhg_evp.F90	(revision 11536)
@@ -112,6 +112,4 @@
       REAL(wp), DIMENSION(:,:), INTENT(  out) ::   pshear_i  , pdivu_i   , pdelta_i      !
       !!
-      LOGICAL, PARAMETER ::   ll_bdy_substep = .TRUE. ! temporary option to call bdy at each sub-time step (T)
-      !                                                                              or only at the main time step (F)
       INTEGER ::   ji, jj       ! dummy loop indices
       INTEGER ::   jter         ! local integers
@@ -123,5 +121,5 @@
       REAL(wp) ::   zm1, zm2, zm3, zmassU, zmassV, zvU, zvV             ! ice/snow mass and volume
       REAL(wp) ::   zdelta, zp_delf, zds2, zdt, zdt2, zdiv, zdiv2       ! temporary scalars
-      REAL(wp) ::   zTauO, zTauB, zTauE, zvel                           ! temporary scalars
+      REAL(wp) ::   zTauO, zTauB, zRHS, zvel                            ! temporary scalars
       REAL(wp) ::   zkt                                                 ! isotropic tensile strength for landfast ice
       REAL(wp) ::   zvCr                                                ! critical ice volume above which ice is landfast
@@ -132,17 +130,12 @@
       REAL(wp) ::   zshear, zdum1, zdum2
       !
-      REAL(wp), DIMENSION(jpi,jpj) ::   z1_e1t0, z1_e2t0                ! scale factors
       REAL(wp), DIMENSION(jpi,jpj) ::   zp_delt                         ! P/delta at T points
       REAL(wp), DIMENSION(jpi,jpj) ::   zbeta                           ! beta coef from Kimmritz 2017
       !
       REAL(wp), DIMENSION(jpi,jpj) ::   zdt_m                           ! (dt / ice-snow_mass) on T points
-      REAL(wp), DIMENSION(jpi,jpj) ::   zaU   , zaV                     ! ice fraction on U/V points
+      REAL(wp), DIMENSION(jpi,jpj) ::   zaU  , zaV                      ! ice fraction on U/V points
       REAL(wp), DIMENSION(jpi,jpj) ::   zmU_t, zmV_t                    ! (ice-snow_mass / dt) on U/V points
       REAL(wp), DIMENSION(jpi,jpj) ::   zmf                             ! coriolis parameter at T points
-      REAL(wp), DIMENSION(jpi,jpj) ::   zTauU_ia , ztauV_ia             ! ice-atm. stress at U-V points
-      REAL(wp), DIMENSION(jpi,jpj) ::   zTauU_ib , ztauV_ib             ! ice-bottom stress at U-V points (landfast param)
-      REAL(wp), DIMENSION(jpi,jpj) ::   zspgU , zspgV                   ! surface pressure gradient at U/V points
       REAL(wp), DIMENSION(jpi,jpj) ::   v_oceU, u_oceV, v_iceU, u_iceV  ! ocean/ice u/v component on V/U points                           
-      REAL(wp), DIMENSION(jpi,jpj) ::   zfU   , zfV                     ! internal stresses
       !
       REAL(wp), DIMENSION(jpi,jpj) ::   zds                             ! shear
@@ -152,9 +145,14 @@
       !                                                                 !    ocean surface (ssh_m) if ice is not embedded
       !                                                                 !    ice bottom surface if ice is embedded   
-      REAL(wp), DIMENSION(jpi,jpj) ::   zCorx, zCory                    ! Coriolis stress array
-      REAL(wp), DIMENSION(jpi,jpj) ::   ztaux_oi, ztauy_oi              ! Ocean-to-ice stress array
-      !
-      REAL(wp), DIMENSION(jpi,jpj) ::   zswitchU, zswitchV              ! dummy arrays
-      REAL(wp), DIMENSION(jpi,jpj) ::   zmaskU, zmaskV                  ! mask for ice presence
+      REAL(wp), DIMENSION(jpi,jpj) ::   zfU  , zfV                      ! internal stresses
+      REAL(wp), DIMENSION(jpi,jpj) ::   zspgU, zspgV                    ! surface pressure gradient at U/V points
+      REAL(wp), DIMENSION(jpi,jpj) ::   zCorU, zCorV                    ! Coriolis stress array
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztaux_ai, ztauy_ai              ! ice-atm. stress at U-V points
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztaux_oi, ztauy_oi              ! ice-ocean stress at U-V points
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztaux_bi, ztauy_bi              ! ice-OceanBottom stress at U-V points (landfast)
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztaux_base, ztauy_base          ! ice-bottom stress at U-V points (landfast)
+      !
+      REAL(wp), DIMENSION(jpi,jpj) ::   zmsk01x, zmsk01y                ! dummy arrays
+      REAL(wp), DIMENSION(jpi,jpj) ::   zmsk00x, zmsk00y                ! mask for ice presence
       REAL(wp), DIMENSION(jpi,jpj) ::   zfmask, zwf                     ! mask at F points for the ice
 
@@ -163,17 +161,7 @@
       REAL(wp), PARAMETER          ::   zamin  = 0.001_wp               ! ice concentration below which ice velocity becomes very small
       !! --- diags
-      REAL(wp), DIMENSION(jpi,jpj) ::   zswi
+      REAL(wp), DIMENSION(jpi,jpj) ::   zmsk00
       REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zsig1, zsig2, zsig3
       !! --- SIMIP diags
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_sig1      ! Average normal stress in sea ice   
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_sig2      ! Maximum shear stress in sea ice
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_dssh_dx   ! X-direction sea-surface tilt term (N/m2)
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_dssh_dy   ! X-direction sea-surface tilt term (N/m2)
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_corstrx   ! X-direction coriolis stress (N/m2)
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_corstry   ! Y-direction coriolis stress (N/m2)
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_intstrx   ! X-direction internal stress (N/m2)
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_intstry   ! Y-direction internal stress (N/m2)
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_utau_oi   ! X-direction ocean-ice stress
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_vtau_oi   ! Y-direction ocean-ice stress  
       REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_xmtrp_ice ! X-component of ice mass transport (kg/s)
       REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_ymtrp_ice ! Y-component of ice mass transport (kg/s)
@@ -255,15 +243,7 @@
       CALL ice_strength
 
-      ! scale factors
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1
-            z1_e1t0(ji,jj) = 1._wp / ( e1t(ji+1,jj  ) + e1t(ji,jj  ) )
-            z1_e2t0(ji,jj) = 1._wp / ( e2t(ji  ,jj+1) + e2t(ji,jj  ) )
-         END DO
-      END DO
-
       ! landfast param from Lemieux(2016): add isotropic tensile strength (following Konig Beatty and Holland, 2010)
-      IF( ln_landfast_L16 .OR. ln_landfast_home ) THEN   ;   zkt = rn_tensile
-      ELSE                                               ;   zkt = 0._wp
+      IF( ln_landfast_L16 ) THEN   ;   zkt = rn_tensile
+      ELSE                         ;   zkt = 0._wp
       ENDIF
       !
@@ -291,9 +271,6 @@
 
             ! Ocean currents at U-V points
-            v_oceU(ji,jj)   = 0.5_wp * ( ( v_oce(ji  ,jj) + v_oce(ji  ,jj-1) ) * e1t(ji+1,jj)    &
-               &                       + ( v_oce(ji+1,jj) + v_oce(ji+1,jj-1) ) * e1t(ji  ,jj) ) * z1_e1t0(ji,jj) * umask(ji,jj,1)
-            
-            u_oceV(ji,jj)   = 0.5_wp * ( ( u_oce(ji,jj  ) + u_oce(ji-1,jj  ) ) * e2t(ji,jj+1)    &
-               &                       + ( u_oce(ji,jj+1) + u_oce(ji-1,jj+1) ) * e2t(ji,jj  ) ) * z1_e2t0(ji,jj) * vmask(ji,jj,1)
+            v_oceU(ji,jj)   = 0.25_wp * ( v_oce(ji,jj) + v_oce(ji,jj-1) + v_oce(ji+1,jj) + v_oce(ji+1,jj-1) ) * umask(ji,jj,1)
+            u_oceV(ji,jj)   = 0.25_wp * ( u_oce(ji,jj) + u_oce(ji-1,jj) + u_oce(ji,jj+1) + u_oce(ji-1,jj+1) ) * vmask(ji,jj,1)
 
             ! Coriolis at T points (m*f)
@@ -308,6 +285,6 @@
             
             ! Drag ice-atm.
-            zTauU_ia(ji,jj) = zaU(ji,jj) * utau_ice(ji,jj)
-            zTauV_ia(ji,jj) = zaV(ji,jj) * vtau_ice(ji,jj)
+            ztaux_ai(ji,jj) = zaU(ji,jj) * utau_ice(ji,jj)
+            ztauy_ai(ji,jj) = zaV(ji,jj) * vtau_ice(ji,jj)
 
             ! Surface pressure gradient (- m*g*GRAD(ssh)) at U-V points
@@ -316,12 +293,12 @@
 
             ! masks
-            zmaskU(ji,jj) = 1._wp - MAX( 0._wp, SIGN( 1._wp, -zmassU ) )  ! 0 if no ice
-            zmaskV(ji,jj) = 1._wp - MAX( 0._wp, SIGN( 1._wp, -zmassV ) )  ! 0 if no ice
+            zmsk00x(ji,jj) = 1._wp - MAX( 0._wp, SIGN( 1._wp, -zmassU ) )  ! 0 if no ice
+            zmsk00y(ji,jj) = 1._wp - MAX( 0._wp, SIGN( 1._wp, -zmassV ) )  ! 0 if no ice
 
             ! switches
-            IF( zmassU <= zmmin .AND. zaU(ji,jj) <= zamin ) THEN   ;   zswitchU(ji,jj) = 0._wp
-            ELSE                                                   ;   zswitchU(ji,jj) = 1._wp   ;   ENDIF
-            IF( zmassV <= zmmin .AND. zaV(ji,jj) <= zamin ) THEN   ;   zswitchV(ji,jj) = 0._wp
-            ELSE                                                   ;   zswitchV(ji,jj) = 1._wp   ;   ENDIF
+            IF( zmassU <= zmmin .AND. zaU(ji,jj) <= zamin ) THEN   ;   zmsk01x(ji,jj) = 0._wp
+            ELSE                                                   ;   zmsk01x(ji,jj) = 1._wp   ;   ENDIF
+            IF( zmassV <= zmmin .AND. zaV(ji,jj) <= zamin ) THEN   ;   zmsk01y(ji,jj) = 0._wp
+            ELSE                                                   ;   zmsk01y(ji,jj) = 1._wp   ;   ENDIF
 
          END DO
@@ -339,32 +316,23 @@
                ! ice-bottom stress at U points
                zvCr = zaU(ji,jj) * rn_depfra * hu_n(ji,jj)
-               zTauU_ib(ji,jj)   = rn_icebfr * MAX( 0._wp, zvU - zvCr ) * EXP( -rn_crhg * ( 1._wp - zaU(ji,jj) ) )
+               ztaux_base(ji,jj) = - rn_icebfr * MAX( 0._wp, zvU - zvCr ) * EXP( -rn_crhg * ( 1._wp - zaU(ji,jj) ) )
                ! ice-bottom stress at V points
                zvCr = zaV(ji,jj) * rn_depfra * hv_n(ji,jj)
-               zTauV_ib(ji,jj)   = rn_icebfr * MAX( 0._wp, zvV - zvCr ) * EXP( -rn_crhg * ( 1._wp - zaV(ji,jj) ) )
+               ztauy_base(ji,jj) = - rn_icebfr * MAX( 0._wp, zvV - zvCr ) * EXP( -rn_crhg * ( 1._wp - zaV(ji,jj) ) )
                ! ice_bottom stress at T points
                zvCr = at_i(ji,jj) * rn_depfra * ht_n(ji,jj)
-               tau_icebfr(ji,jj) = rn_icebfr * MAX( 0._wp, vt_i(ji,jj) - zvCr ) * EXP( -rn_crhg * ( 1._wp - at_i(ji,jj) ) )
+               tau_icebfr(ji,jj) = - rn_icebfr * MAX( 0._wp, vt_i(ji,jj) - zvCr ) * EXP( -rn_crhg * ( 1._wp - at_i(ji,jj) ) )
             END DO
          END DO
          CALL lbc_lnk( 'icedyn_rhg_evp', tau_icebfr(:,:), 'T', 1. )
          !
-      ELSEIF( ln_landfast_home ) THEN          !-- Home made
+      ELSE                               !-- no landfast
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1
-               zTauU_ib(ji,jj) = tau_icebfr(ji,jj)
-               zTauV_ib(ji,jj) = tau_icebfr(ji,jj)
-            END DO
-         END DO
-         !
-      ELSE                                     !-- no landfast
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               zTauU_ib(ji,jj) = 0._wp
-               zTauV_ib(ji,jj) = 0._wp
+               ztaux_base(ji,jj) = 0._wp
+               ztauy_base(ji,jj) = 0._wp
             END DO
          END DO
       ENDIF
-      IF( iom_use('tau_icebfr') )   CALL iom_put( 'tau_icebfr', tau_icebfr(:,:) )
 
       !------------------------------------------------------------------------------!
@@ -372,7 +340,7 @@
       !------------------------------------------------------------------------------!
       !
-      !                                               !----------------------!
+      !                                               ! ==================== !
       DO jter = 1 , nn_nevp                           !    loop over jter    !
-         !                                            !----------------------!        
+         !                                            ! ==================== !        
          l_full_nf_update = jter == nn_nevp   ! false: disable full North fold update (performances) for iter = 1 to nn_nevp-1
          !
@@ -479,11 +447,8 @@
                   &                  ) * r1_e1e2v(ji,jj)
                !
-               !                !--- u_ice at V point
-               u_iceV(ji,jj) = 0.5_wp * ( ( u_ice(ji,jj  ) + u_ice(ji-1,jj  ) ) * e2t(ji,jj+1)     &
-                  &                     + ( u_ice(ji,jj+1) + u_ice(ji-1,jj+1) ) * e2t(ji,jj  ) ) * z1_e2t0(ji,jj) * vmask(ji,jj,1)
+               !                !--- ice currents at U-V point
+               v_iceU(ji,jj) = 0.25_wp * ( v_ice(ji,jj) + v_ice(ji,jj-1) + v_ice(ji+1,jj) + v_ice(ji+1,jj-1) ) * umask(ji,jj,1)
+               u_iceV(ji,jj) = 0.25_wp * ( u_ice(ji,jj) + u_ice(ji-1,jj) + u_ice(ji,jj+1) + u_ice(ji-1,jj+1) ) * vmask(ji,jj,1)
                !
-               !                !--- v_ice at U point
-               v_iceU(ji,jj) = 0.5_wp * ( ( v_ice(ji  ,jj) + v_ice(ji  ,jj-1) ) * e1t(ji+1,jj)     &
-                  &                     + ( v_ice(ji+1,jj) + v_ice(ji+1,jj-1) ) * e1t(ji  ,jj) ) * z1_e1t0(ji,jj) * umask(ji,jj,1)
             END DO
          END DO
@@ -504,31 +469,34 @@
                   !                 !--- tau_bottom/v_ice
                   zvel  = 5.e-05_wp + SQRT( v_ice(ji,jj) * v_ice(ji,jj) + u_iceV(ji,jj) * u_iceV(ji,jj) )
-                  zTauB = - zTauV_ib(ji,jj) / zvel
+                  zTauB = ztauy_base(ji,jj) / zvel
+                  !                 !--- OceanBottom-to-Ice stress
+                  ztauy_bi(ji,jj) = zTauB * v_ice(ji,jj)
                   !
                   !                 !--- Coriolis at V-points (energy conserving formulation)
-                  zCory(ji,jj)  = - 0.25_wp * r1_e2v(ji,jj) *  &
+                  zCorV(ji,jj)  = - 0.25_wp * r1_e2v(ji,jj) *  &
                      &    ( zmf(ji,jj  ) * ( e2u(ji,jj  ) * u_ice(ji,jj  ) + e2u(ji-1,jj  ) * u_ice(ji-1,jj  ) )  &
                      &    + zmf(ji,jj+1) * ( e2u(ji,jj+1) * u_ice(ji,jj+1) + e2u(ji-1,jj+1) * u_ice(ji-1,jj+1) ) )
                   !
                   !                 !--- Sum of external forces (explicit solution) = F + tau_ia + Coriolis + spg + tau_io
-                  zTauE = zfV(ji,jj) + zTauV_ia(ji,jj) + zCory(ji,jj) + zspgV(ji,jj) + ztauy_oi(ji,jj)
-                  !
-                  !                 !--- landfast switch => 0 = static friction ; 1 = sliding friction
-                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, ztauE - zTauV_ib(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
+                  zRHS = zfV(ji,jj) + ztauy_ai(ji,jj) + zCorV(ji,jj) + zspgV(ji,jj) + ztauy_oi(ji,jj)
+                  !
+                  !                 !--- landfast switch => 0 = static  friction : TauB > RHS & sign(TauB) /= sign(RHS)
+                  !                                         1 = sliding friction : TauB < RHS
+                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, zRHS + ztauy_base(ji,jj) ) - SIGN( 1._wp, zRHS ) ) )
                   !
                   IF( ln_aEVP ) THEN !--- ice velocity using aEVP (Kimmritz et al 2016 & 2017)
-                  v_ice(ji,jj) = ( (          rswitch * ( zmV_t(ji,jj) * ( zbeta(ji,jj) * v_ice(ji,jj) + v_ice_b(ji,jj) )         & ! previous velocity
-                     &                                  + zTauE + zTauO * v_ice(ji,jj)                                            & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
-                     &                                  ) / MAX( zepsi, zmV_t(ji,jj) * ( zbeta(ji,jj) + 1._wp ) + zTauO - zTauB ) & ! m/dt + tau_io(only ice part) + landfast
-                     &                 + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )           & ! static friction => slow decrease to v=0
-                     &             ) * zswitchV(ji,jj) + v_oce(ji,jj) * 0.01_wp * ( 1._wp - zswitchV(ji,jj) )                     & ! v_ice = v_oce/100 if mass < zmmin & conc < zamin
-                     &           ) * zmaskV(ji,jj)
+                     v_ice(ji,jj) = ( (          rswitch * ( zmV_t(ji,jj) * ( zbeta(ji,jj) * v_ice(ji,jj) + v_ice_b(ji,jj) )       & ! previous velocity
+                        &                                  + zRHS + zTauO * v_ice(ji,jj) )                                         & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                        &                                  / MAX( zepsi, zmV_t(ji,jj) * ( zbeta(ji,jj) + 1._wp ) + zTauO - zTauB ) & ! m/dt + tau_io(only ice part) + landfast
+                        &               + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )           & ! static friction => slow decrease to v=0
+                        &             ) * zmsk01y(ji,jj) + v_oce(ji,jj) * 0.01_wp * ( 1._wp - zmsk01y(ji,jj) )                     & ! v_ice = v_oce/100 if mass < zmmin & conc < zamin
+                        &           )   * zmsk00y(ji,jj)
                   ELSE               !--- ice velocity using EVP implicit formulation (cf Madec doc & Bouillon 2009)
-                  v_ice(ji,jj) = ( (           rswitch   * ( zmV_t(ji,jj)  * v_ice(ji,jj)                             &  ! previous velocity
-                     &                                     + zTauE + zTauO * v_ice(ji,jj)                             &  ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
-                     &                                     ) / MAX( zepsi, zmV_t(ji,jj) + zTauO - zTauB )             &  ! m/dt + tau_io(only ice part) + landfast
-                     &              + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )  &  ! static friction => slow decrease to v=0
-                     &              ) * zswitchV(ji,jj) + v_oce(ji,jj) * 0.01_wp * ( 1._wp - zswitchV(ji,jj) )        &  ! v_ice = v_oce/100 if mass < zmmin & conc < zamin
-                     &            ) * zmaskV(ji,jj)
+                     v_ice(ji,jj) = ( (           rswitch   * ( zmV_t(ji,jj)  * v_ice(ji,jj)                                       & ! previous velocity
+                        &                                     + zRHS + zTauO * v_ice(ji,jj) )                                      & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                        &                                     / MAX( zepsi, zmV_t(ji,jj) + zTauO - zTauB )                         & ! m/dt + tau_io(only ice part) + landfast
+                        &                + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )          & ! static friction => slow decrease to v=0
+                        &              ) * zmsk01y(ji,jj) + v_oce(ji,jj) * 0.01_wp * ( 1._wp - zmsk01y(ji,jj) )                    & ! v_ice = v_oce/100 if mass < zmmin & conc < zamin
+                        &            )   * zmsk00y(ji,jj)
                   ENDIF
                END DO
@@ -540,5 +508,5 @@
             CALL agrif_interp_ice( 'V' )
 #endif
-            IF( ln_bdy .AND. ll_bdy_substep ) CALL bdy_ice_dyn( 'V' )
+            IF( ln_bdy )   CALL bdy_ice_dyn( 'V' )
             !
             DO jj = 2, jpjm1
@@ -552,31 +520,34 @@
                   !                 !--- tau_bottom/u_ice
                   zvel  = 5.e-05_wp + SQRT( v_iceU(ji,jj) * v_iceU(ji,jj) + u_ice(ji,jj) * u_ice(ji,jj) )
-                  zTauB = - zTauU_ib(ji,jj) / zvel
+                  zTauB = ztaux_base(ji,jj) / zvel
+                  !                 !--- OceanBottom-to-Ice stress
+                  ztaux_bi(ji,jj) = zTauB * u_ice(ji,jj)
                   !
                   !                 !--- Coriolis at U-points (energy conserving formulation)
-                  zCorx(ji,jj)  =   0.25_wp * r1_e1u(ji,jj) *  &
+                  zCorU(ji,jj)  =   0.25_wp * r1_e1u(ji,jj) *  &
                      &    ( zmf(ji  ,jj) * ( e1v(ji  ,jj) * v_ice(ji  ,jj) + e1v(ji  ,jj-1) * v_ice(ji  ,jj-1) )  &
                      &    + zmf(ji+1,jj) * ( e1v(ji+1,jj) * v_ice(ji+1,jj) + e1v(ji+1,jj-1) * v_ice(ji+1,jj-1) ) )
                   !
                   !                 !--- Sum of external forces (explicit solution) = F + tau_ia + Coriolis + spg + tau_io
-                  zTauE = zfU(ji,jj) + zTauU_ia(ji,jj) + zCorx(ji,jj) + zspgU(ji,jj) + ztaux_oi(ji,jj)
-                  !
-                  !                 !--- landfast switch => 0 = static friction ; 1 = sliding friction
-                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, ztauE - zTauU_ib(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
+                  zRHS = zfU(ji,jj) + ztaux_ai(ji,jj) + zCorU(ji,jj) + zspgU(ji,jj) + ztaux_oi(ji,jj)
+                  !
+                  !                 !--- landfast switch => 0 = static  friction : TauB > RHS & sign(TauB) /= sign(RHS)
+                  !                                         1 = sliding friction : TauB < RHS
+                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, zRHS + ztaux_base(ji,jj) ) - SIGN( 1._wp, zRHS ) ) )
                   !
                   IF( ln_aEVP ) THEN !--- ice velocity using aEVP (Kimmritz et al 2016 & 2017)
-                  u_ice(ji,jj) = ( (          rswitch * ( zmU_t(ji,jj) * ( zbeta(ji,jj) * u_ice(ji,jj) + u_ice_b(ji,jj) )         & ! previous velocity
-                     &                                     + zTauE + zTauO * u_ice(ji,jj)                                         & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
-                     &                                  ) / MAX( zepsi, zmU_t(ji,jj) * ( zbeta(ji,jj) + 1._wp ) + zTauO - zTauB ) & ! m/dt + tau_io(only ice part) + landfast
-                     &              + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )              & ! static friction => slow decrease to v=0
-                     &              ) * zswitchU(ji,jj) + u_oce(ji,jj) * 0.01_wp * ( 1._wp - zswitchU(ji,jj) )                    & ! v_ice = v_oce/100 if mass < zmmin & conc < zamin 
-                     &            ) * zmaskU(ji,jj)
+                     u_ice(ji,jj) = ( (          rswitch * ( zmU_t(ji,jj) * ( zbeta(ji,jj) * u_ice(ji,jj) + u_ice_b(ji,jj) )       & ! previous velocity
+                        &                                  + zRHS + zTauO * u_ice(ji,jj) )                                         & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                        &                                  / MAX( zepsi, zmU_t(ji,jj) * ( zbeta(ji,jj) + 1._wp ) + zTauO - zTauB ) & ! m/dt + tau_io(only ice part) + landfast
+                        &               + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )           & ! static friction => slow decrease to v=0
+                        &             ) * zmsk01x(ji,jj) + u_oce(ji,jj) * 0.01_wp * ( 1._wp - zmsk01x(ji,jj) )                     & ! v_ice = v_oce/100 if mass < zmmin & conc < zamin 
+                        &           )   * zmsk00x(ji,jj)
                   ELSE               !--- ice velocity using EVP implicit formulation (cf Madec doc & Bouillon 2009)
-                  u_ice(ji,jj) = ( (           rswitch   * ( zmU_t(ji,jj)  * u_ice(ji,jj)                             &  ! previous velocity
-                     &                                     + zTauE + zTauO * u_ice(ji,jj)                             &  ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
-                     &                                     ) / MAX( zepsi, zmU_t(ji,jj) + zTauO - zTauB )             &  ! m/dt + tau_io(only ice part) + landfast
-                     &              + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )  &  ! static friction => slow decrease to v=0
-                     &              ) * zswitchU(ji,jj) + u_oce(ji,jj) * 0.01_wp * ( 1._wp - zswitchU(ji,jj) )        &  ! v_ice = v_oce/100 if mass < zmmin & conc < zamin 
-                     &            ) * zmaskU(ji,jj)
+                     u_ice(ji,jj) = ( (           rswitch   * ( zmU_t(ji,jj)  * u_ice(ji,jj)                                       & ! previous velocity
+                        &                                     + zRHS + zTauO * u_ice(ji,jj) )                                      & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                        &                                     / MAX( zepsi, zmU_t(ji,jj) + zTauO - zTauB )                         & ! m/dt + tau_io(only ice part) + landfast
+                        &                + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )          & ! static friction => slow decrease to v=0
+                        &              ) * zmsk01x(ji,jj) + u_oce(ji,jj) * 0.01_wp * ( 1._wp - zmsk01x(ji,jj) )                    & ! v_ice = v_oce/100 if mass < zmmin & conc < zamin 
+                        &            )   * zmsk00x(ji,jj)
                   ENDIF
                END DO
@@ -588,5 +559,5 @@
             CALL agrif_interp_ice( 'U' )
 #endif
-            IF( ln_bdy .AND. ll_bdy_substep ) CALL bdy_ice_dyn( 'U' )
+            IF( ln_bdy )   CALL bdy_ice_dyn( 'U' )
             !
          ELSE ! odd iterations
@@ -602,31 +573,34 @@
                   !                 !--- tau_bottom/u_ice
                   zvel  = 5.e-05_wp + SQRT( v_iceU(ji,jj) * v_iceU(ji,jj) + u_ice(ji,jj) * u_ice(ji,jj) )
-                  zTauB = - zTauU_ib(ji,jj) / zvel
+                  zTauB = ztaux_base(ji,jj) / zvel
+                  !                 !--- OceanBottom-to-Ice stress
+                  ztaux_bi(ji,jj) = zTauB * u_ice(ji,jj)
                   !
                   !                 !--- Coriolis at U-points (energy conserving formulation)
-                  zCorx(ji,jj)  =   0.25_wp * r1_e1u(ji,jj) *  &
+                  zCorU(ji,jj)  =   0.25_wp * r1_e1u(ji,jj) *  &
                      &    ( zmf(ji  ,jj) * ( e1v(ji  ,jj) * v_ice(ji  ,jj) + e1v(ji  ,jj-1) * v_ice(ji  ,jj-1) )  &
                      &    + zmf(ji+1,jj) * ( e1v(ji+1,jj) * v_ice(ji+1,jj) + e1v(ji+1,jj-1) * v_ice(ji+1,jj-1) ) )
                   !
                   !                 !--- Sum of external forces (explicit solution) = F + tau_ia + Coriolis + spg + tau_io
-                  zTauE = zfU(ji,jj) + zTauU_ia(ji,jj) + zCorx(ji,jj) + zspgU(ji,jj) + ztaux_oi(ji,jj)
-                  !
-                  !                 !--- landfast switch => 0 = static friction ; 1 = sliding friction
-                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, ztauE - zTauU_ib(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
+                  zRHS = zfU(ji,jj) + ztaux_ai(ji,jj) + zCorU(ji,jj) + zspgU(ji,jj) + ztaux_oi(ji,jj)
+                  !
+                  !                 !--- landfast switch => 0 = static  friction : TauB > RHS & sign(TauB) /= sign(RHS)
+                  !                                         1 = sliding friction : TauB < RHS
+                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, zRHS + ztaux_base(ji,jj) ) - SIGN( 1._wp, zRHS ) ) )
                   !
                   IF( ln_aEVP ) THEN !--- ice velocity using aEVP (Kimmritz et al 2016 & 2017)
-                  u_ice(ji,jj) = ( (          rswitch * ( zmU_t(ji,jj) * ( zbeta(ji,jj) * u_ice(ji,jj) + u_ice_b(ji,jj) )         & ! previous velocity
-                     &                                     + zTauE + zTauO * u_ice(ji,jj)                                         & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
-                     &                                  ) / MAX( zepsi, zmU_t(ji,jj) * ( zbeta(ji,jj) + 1._wp ) + zTauO - zTauB ) & ! m/dt + tau_io(only ice part) + landfast
-                     &              + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )              & ! static friction => slow decrease to v=0
-                     &              ) * zswitchU(ji,jj) + u_oce(ji,jj) * 0.01_wp * ( 1._wp - zswitchU(ji,jj) )                    & ! v_ice = v_oce/100 if mass < zmmin & conc < zamin 
-                     &            ) * zmaskU(ji,jj)
+                     u_ice(ji,jj) = ( (          rswitch * ( zmU_t(ji,jj) * ( zbeta(ji,jj) * u_ice(ji,jj) + u_ice_b(ji,jj) )       & ! previous velocity
+                        &                                  + zRHS + zTauO * u_ice(ji,jj) )                                         & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                        &                                  / MAX( zepsi, zmU_t(ji,jj) * ( zbeta(ji,jj) + 1._wp ) + zTauO - zTauB ) & ! m/dt + tau_io(only ice part) + landfast
+                        &               + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )           & ! static friction => slow decrease to v=0
+                        &             ) * zmsk01x(ji,jj) + u_oce(ji,jj) * 0.01_wp * ( 1._wp - zmsk01x(ji,jj) )                     & ! v_ice = v_oce/100 if mass < zmmin & conc < zamin 
+                        &           )   * zmsk00x(ji,jj)
                   ELSE               !--- ice velocity using EVP implicit formulation (cf Madec doc & Bouillon 2009)
-                  u_ice(ji,jj) = ( (           rswitch   * ( zmU_t(ji,jj)  * u_ice(ji,jj)                             &  ! previous velocity
-                     &                                     + zTauE + zTauO * u_ice(ji,jj)                             &  ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
-                     &                                     ) / MAX( zepsi, zmU_t(ji,jj) + zTauO - zTauB )             &  ! m/dt + tau_io(only ice part) + landfast
-                     &              + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )  &  ! static friction => slow decrease to v=0
-                     &              ) * zswitchU(ji,jj) + u_oce(ji,jj) * 0.01_wp * ( 1._wp - zswitchU(ji,jj) )        &  ! v_ice = v_oce/100 if mass < zmmin & conc < zamin
-                     &            ) * zmaskU(ji,jj)
+                     u_ice(ji,jj) = ( (           rswitch   * ( zmU_t(ji,jj)  * u_ice(ji,jj)                                       & ! previous velocity
+                        &                                     + zRHS + zTauO * u_ice(ji,jj) )                                      & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                        &                                     / MAX( zepsi, zmU_t(ji,jj) + zTauO - zTauB )                         & ! m/dt + tau_io(only ice part) + landfast
+                        &                + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )          & ! static friction => slow decrease to v=0
+                        &              ) * zmsk01x(ji,jj) + u_oce(ji,jj) * 0.01_wp * ( 1._wp - zmsk01x(ji,jj) )                    & ! v_ice = v_oce/100 if mass < zmmin & conc < zamin
+                        &            )   * zmsk00x(ji,jj)
                   ENDIF
                END DO
@@ -638,5 +612,5 @@
             CALL agrif_interp_ice( 'U' )
 #endif
-            IF( ln_bdy .AND. ll_bdy_substep ) CALL bdy_ice_dyn( 'U' )
+            IF( ln_bdy )   CALL bdy_ice_dyn( 'U' )
             !
             DO jj = 2, jpjm1
@@ -650,31 +624,34 @@
                   !                 !--- tau_bottom/v_ice
                   zvel  = 5.e-05_wp + SQRT( v_ice(ji,jj) * v_ice(ji,jj) + u_iceV(ji,jj) * u_iceV(ji,jj) )
-                  zTauB = - zTauV_ib(ji,jj) / zvel
+                  zTauB = ztauy_base(ji,jj) / zvel
+                  !                 !--- OceanBottom-to-Ice stress
+                  ztauy_bi(ji,jj) = zTauB * v_ice(ji,jj)
                   !
                   !                 !--- Coriolis at v-points (energy conserving formulation)
-                  zCory(ji,jj)  = - 0.25_wp * r1_e2v(ji,jj) *  &
+                  zCorV(ji,jj)  = - 0.25_wp * r1_e2v(ji,jj) *  &
                      &    ( zmf(ji,jj  ) * ( e2u(ji,jj  ) * u_ice(ji,jj  ) + e2u(ji-1,jj  ) * u_ice(ji-1,jj  ) )  &
                      &    + zmf(ji,jj+1) * ( e2u(ji,jj+1) * u_ice(ji,jj+1) + e2u(ji-1,jj+1) * u_ice(ji-1,jj+1) ) )
                   !
                   !                 !--- Sum of external forces (explicit solution) = F + tau_ia + Coriolis + spg + tau_io
-                  zTauE = zfV(ji,jj) + zTauV_ia(ji,jj) + zCory(ji,jj) + zspgV(ji,jj) + ztauy_oi(ji,jj)
-                  !
-                  !                 !--- landfast switch => 0 = static friction ; 1 = sliding friction
-                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, zTauE - zTauV_ib(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
+                  zRHS = zfV(ji,jj) + ztauy_ai(ji,jj) + zCorV(ji,jj) + zspgV(ji,jj) + ztauy_oi(ji,jj)
+                  !
+                  !                 !--- landfast switch => 0 = static  friction : TauB > RHS & sign(TauB) /= sign(RHS)
+                  !                                         1 = sliding friction : TauB < RHS
+                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, zRHS + ztauy_base(ji,jj) ) - SIGN( 1._wp, zRHS ) ) )
                   !
                   IF( ln_aEVP ) THEN !--- ice velocity using aEVP (Kimmritz et al 2016 & 2017)
-                  v_ice(ji,jj) = ( (          rswitch * ( zmV_t(ji,jj) * ( zbeta(ji,jj) * v_ice(ji,jj) + v_ice_b(ji,jj) )         & ! previous velocity
-                     &                                  + zTauE + zTauO * v_ice(ji,jj)                                            & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
-                     &                                  ) / MAX( zepsi, zmV_t(ji,jj) * ( zbeta(ji,jj) + 1._wp ) + zTauO - zTauB ) & ! m/dt + tau_io(only ice part) + landfast
-                     &                 + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )           & ! static friction => slow decrease to v=0
-                     &             ) * zswitchV(ji,jj) + v_oce(ji,jj) * 0.01_wp * ( 1._wp - zswitchV(ji,jj) )                     & ! v_ice = v_oce/100 if mass < zmmin & conc < zamin
-                     &           ) * zmaskV(ji,jj)
+                     v_ice(ji,jj) = ( (          rswitch * ( zmV_t(ji,jj) * ( zbeta(ji,jj) * v_ice(ji,jj) + v_ice_b(ji,jj) )       & ! previous velocity
+                        &                                  + zRHS + zTauO * v_ice(ji,jj) )                                         & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                        &                                  / MAX( zepsi, zmV_t(ji,jj) * ( zbeta(ji,jj) + 1._wp ) + zTauO - zTauB ) & ! m/dt + tau_io(only ice part) + landfast
+                        &               + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )           & ! static friction => slow decrease to v=0
+                        &             ) * zmsk01y(ji,jj) + v_oce(ji,jj) * 0.01_wp * ( 1._wp - zmsk01y(ji,jj) )                     & ! v_ice = v_oce/100 if mass < zmmin & conc < zamin
+                        &           )   * zmsk00y(ji,jj)
                   ELSE               !--- ice velocity using EVP implicit formulation (cf Madec doc & Bouillon 2009)
-                  v_ice(ji,jj) = ( (           rswitch   * ( zmV_t(ji,jj)  * v_ice(ji,jj)                             &  ! previous velocity
-                     &                                     + zTauE + zTauO * v_ice(ji,jj)                             &  ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
-                     &                                     ) / MAX( zepsi, zmV_t(ji,jj) + zTauO - zTauB )             &  ! m/dt + tau_io(only ice part) + landfast
-                     &              + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )  &  ! static friction => slow decrease to v=0
-                     &              ) * zswitchV(ji,jj) + v_oce(ji,jj) * 0.01_wp * ( 1._wp - zswitchV(ji,jj) )        &  ! v_ice = v_oce/100 if mass < zmmin & conc < zamin
-                     &            ) * zmaskV(ji,jj)
+                     v_ice(ji,jj) = ( (           rswitch   * ( zmV_t(ji,jj)  * v_ice(ji,jj)                                       & ! previous velocity
+                        &                                     + zRHS + zTauO * v_ice(ji,jj) )                                      & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                        &                                     / MAX( zepsi, zmV_t(ji,jj) + zTauO - zTauB )                         & ! m/dt + tau_io(only ice part) + landfast
+                        &                + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )          & ! static friction => slow decrease to v=0
+                        &              ) * zmsk01y(ji,jj) + v_oce(ji,jj) * 0.01_wp * ( 1._wp - zmsk01y(ji,jj) )                    & ! v_ice = v_oce/100 if mass < zmmin & conc < zamin
+                        &            )   * zmsk00y(ji,jj)
                   ENDIF
                END DO
@@ -686,5 +663,5 @@
             CALL agrif_interp_ice( 'V' )
 #endif
-            IF( ln_bdy .AND. ll_bdy_substep ) CALL bdy_ice_dyn( 'V' )
+            IF( ln_bdy )   CALL bdy_ice_dyn( 'V' )
             !
          ENDIF
@@ -701,9 +678,4 @@
       END DO                                              !  end loop over jter  !
       !                                                   ! ==================== !
-      !
-      IF( ln_bdy .AND. .NOT.ll_bdy_substep ) THEN
-         CALL bdy_ice_dyn( 'U' )
-         CALL bdy_ice_dyn( 'V' )
-      ENDIF
       !
       !------------------------------------------------------------------------------!
@@ -764,15 +736,30 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            zswi(ji,jj) = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi06 ) ) ! 1 if ice, 0 if no ice
+            zmsk00(ji,jj) = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi06 ) ) ! 1 if ice, 0 if no ice
          END DO
       END DO
 
+      ! --- ice-ocean, ice-atm. & ice-oceanbottom(landfast) stresses --- !
+      IF(  iom_use('utau_oi') .OR. iom_use('vtau_oi') .OR. iom_use('utau_ai') .OR. iom_use('vtau_ai') .OR. &
+         & iom_use('utau_bi') .OR. iom_use('vtau_bi') ) THEN
+         !
+         CALL lbc_lnk_multi( 'icedyn_rhg_evp', ztaux_oi, 'U', -1., ztauy_oi, 'V', -1., ztaux_ai, 'U', -1., ztauy_ai, 'V', -1., &
+            &                                  ztaux_bi, 'U', -1., ztauy_bi, 'V', -1. )
+         !
+         CALL iom_put( 'utau_oi' , ztaux_oi * zmsk00 )
+         CALL iom_put( 'vtau_oi' , ztauy_oi * zmsk00 )
+         CALL iom_put( 'utau_ai' , ztaux_ai * zmsk00 )
+         CALL iom_put( 'vtau_ai' , ztauy_ai * zmsk00 )
+         CALL iom_put( 'utau_bi' , ztaux_bi * zmsk00 )
+         CALL iom_put( 'vtau_bi' , ztauy_bi * zmsk00 )
+      ENDIF
+       
       ! --- divergence, shear and strength --- !
-      IF( iom_use('icediv') )   CALL iom_put( "icediv" , pdivu_i (:,:) * zswi(:,:) )   ! divergence
-      IF( iom_use('iceshe') )   CALL iom_put( "iceshe" , pshear_i(:,:) * zswi(:,:) )   ! shear
-      IF( iom_use('icestr') )   CALL iom_put( "icestr" , strength(:,:) * zswi(:,:) )   ! Ice strength
-
-      ! --- charge ellipse --- !
-      IF( iom_use('isig1') .OR. iom_use('isig2') .OR. iom_use('isig3') ) THEN
+      IF( iom_use('icediv') )   CALL iom_put( 'icediv' , pdivu_i  * zmsk00 )   ! divergence
+      IF( iom_use('iceshe') )   CALL iom_put( 'iceshe' , pshear_i * zmsk00 )   ! shear
+      IF( iom_use('icestr') )   CALL iom_put( 'icestr' , strength * zmsk00 )   ! strength
+
+      ! --- stress tensor --- !
+      IF( iom_use('isig1') .OR. iom_use('isig2') .OR. iom_use('isig3') .OR. iom_use('normstr') .OR. iom_use('sheastr') ) THEN
          !
          ALLOCATE( zsig1(jpi,jpj) , zsig2(jpi,jpj) , zsig3(jpi,jpj) )
@@ -780,11 +767,11 @@
          DO jj = 2, jpjm1
             DO ji = 2, jpim1
-               zdum1 = ( zswi(ji-1,jj) * pstress12_i(ji-1,jj) + zswi(ji  ,jj-1) * pstress12_i(ji  ,jj-1) +  &  ! stress12_i at T-point
-                  &      zswi(ji  ,jj) * pstress12_i(ji  ,jj) + zswi(ji-1,jj-1) * pstress12_i(ji-1,jj-1) )  &
-                  &    / MAX( 1._wp, zswi(ji-1,jj) + zswi(ji,jj-1) + zswi(ji,jj) + zswi(ji-1,jj-1) )
+               zdum1 = ( zmsk00(ji-1,jj) * pstress12_i(ji-1,jj) + zmsk00(ji  ,jj-1) * pstress12_i(ji  ,jj-1) +  &  ! stress12_i at T-point
+                  &      zmsk00(ji  ,jj) * pstress12_i(ji  ,jj) + zmsk00(ji-1,jj-1) * pstress12_i(ji-1,jj-1) )  &
+                  &    / MAX( 1._wp, zmsk00(ji-1,jj) + zmsk00(ji,jj-1) + zmsk00(ji,jj) + zmsk00(ji-1,jj-1) )
 
                zshear = SQRT( pstress2_i(ji,jj) * pstress2_i(ji,jj) + 4._wp * zdum1 * zdum1 ) ! shear stress  
 
-               zdum2 = zswi(ji,jj) / MAX( 1._wp, strength(ji,jj) )
+               zdum2 = zmsk00(ji,jj) / MAX( 1._wp, strength(ji,jj) )
 
 !!               zsig1(ji,jj) = 0.5_wp * zdum2 * ( pstress1_i(ji,jj) + zshear ) ! principal stress (y-direction, see Hunke & Dukowicz 2002)
@@ -799,90 +786,67 @@
          CALL lbc_lnk_multi( 'icedyn_rhg_evp', zsig1, 'T', 1., zsig2, 'T', 1., zsig3, 'T', 1. )
          !
-         IF( iom_use('isig1') )   CALL iom_put( "isig1" , zsig1 )
-         IF( iom_use('isig2') )   CALL iom_put( "isig2" , zsig2 )
-         IF( iom_use('isig3') )   CALL iom_put( "isig3" , zsig3 )
-         !
+         CALL iom_put( 'isig1' , zsig1 )
+         CALL iom_put( 'isig2' , zsig2 )
+         CALL iom_put( 'isig3' , zsig3 )
+         !
+         ! Stress tensor invariants (normal and shear stress N/m)
+         IF( iom_use('normstr') )   CALL iom_put( 'normstr' ,       ( zs1(:,:) + zs2(:,:) )                       * zmsk00(:,:) ) ! Normal stress
+         IF( iom_use('sheastr') )   CALL iom_put( 'sheastr' , SQRT( ( zs1(:,:) - zs2(:,:) )**2 + 4*zs12(:,:)**2 ) * zmsk00(:,:) ) ! Shear stress
+
          DEALLOCATE( zsig1 , zsig2 , zsig3 )
       ENDIF
       
       ! --- SIMIP --- !
-      IF ( iom_use( 'normstr'  ) .OR. iom_use( 'sheastr'  ) .OR. iom_use( 'dssh_dx'  ) .OR. iom_use( 'dssh_dy'  ) .OR. &
-         & iom_use( 'corstrx'  ) .OR. iom_use( 'corstry'  ) .OR. iom_use( 'intstrx'  ) .OR. iom_use( 'intstry'  ) .OR. &
-         & iom_use( 'utau_oi'  ) .OR. iom_use( 'vtau_oi'  ) .OR. iom_use( 'xmtrpice' ) .OR. iom_use( 'ymtrpice' ) .OR. &
-         & iom_use( 'xmtrpsnw' ) .OR. iom_use( 'ymtrpsnw' ) .OR. iom_use( 'xatrp'    ) .OR. iom_use( 'yatrp'    ) ) THEN
-
-         ALLOCATE( zdiag_sig1     (jpi,jpj) , zdiag_sig2     (jpi,jpj) , zdiag_dssh_dx  (jpi,jpj) , zdiag_dssh_dy  (jpi,jpj) ,  &
-            &      zdiag_corstrx  (jpi,jpj) , zdiag_corstry  (jpi,jpj) , zdiag_intstrx  (jpi,jpj) , zdiag_intstry  (jpi,jpj) ,  &
-            &      zdiag_utau_oi  (jpi,jpj) , zdiag_vtau_oi  (jpi,jpj) , zdiag_xmtrp_ice(jpi,jpj) , zdiag_ymtrp_ice(jpi,jpj) ,  &
-            &      zdiag_xmtrp_snw(jpi,jpj) , zdiag_ymtrp_snw(jpi,jpj) , zdiag_xatrp    (jpi,jpj) , zdiag_yatrp    (jpi,jpj) )
-         
+      IF(  iom_use('dssh_dx') .OR. iom_use('dssh_dy') .OR. &
+         & iom_use('corstrx') .OR. iom_use('corstry') .OR. iom_use('intstrx') .OR. iom_use('intstry') ) THEN
+         !
+         CALL lbc_lnk_multi( 'icedyn_rhg_evp', zspgU, 'U', -1., zspgV, 'V', -1., &
+            &                                  zCorU, 'U', -1., zCorV, 'V', -1., zfU, 'U', -1., zfV, 'V', -1. )
+
+         CALL iom_put( 'dssh_dx' , zspgU * zmsk00 )   ! Sea-surface tilt term in force balance (x)
+         CALL iom_put( 'dssh_dy' , zspgV * zmsk00 )   ! Sea-surface tilt term in force balance (y)
+         CALL iom_put( 'corstrx' , zCorU * zmsk00 )   ! Coriolis force term in force balance (x)
+         CALL iom_put( 'corstry' , zCorV * zmsk00 )   ! Coriolis force term in force balance (y)
+         CALL iom_put( 'intstrx' , zfU   * zmsk00 )   ! Internal force term in force balance (x)
+         CALL iom_put( 'intstry' , zfV   * zmsk00 )   ! Internal force term in force balance (y)
+      ENDIF
+
+      IF(  iom_use('xmtrpice') .OR. iom_use('ymtrpice') .OR. &
+         & iom_use('xmtrpsnw') .OR. iom_use('ymtrpsnw') .OR. iom_use('xatrp') .OR. iom_use('yatrp') ) THEN
+         !
+         ALLOCATE( zdiag_xmtrp_ice(jpi,jpj) , zdiag_ymtrp_ice(jpi,jpj) , &
+            &      zdiag_xmtrp_snw(jpi,jpj) , zdiag_ymtrp_snw(jpi,jpj) , zdiag_xatrp(jpi,jpj) , zdiag_yatrp(jpi,jpj) )
+         !
          DO jj = 2, jpjm1
             DO ji = 2, jpim1
-               rswitch  = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi06 ) ) ! 1 if ice, 0 if no ice
-               
-               ! Stress tensor invariants (normal and shear stress N/m)
-               zdiag_sig1(ji,jj) = ( zs1(ji,jj) + zs2(ji,jj) ) * rswitch                                 ! normal stress
-               zdiag_sig2(ji,jj) = SQRT( ( zs1(ji,jj) - zs2(ji,jj) )**2 + 4*zs12(ji,jj)**2 ) * rswitch   ! shear stress
-               
-               ! Stress terms of the momentum equation (N/m2)
-               zdiag_dssh_dx(ji,jj) = zspgU(ji,jj) * rswitch     ! sea surface slope stress term
-               zdiag_dssh_dy(ji,jj) = zspgV(ji,jj) * rswitch
-               
-               zdiag_corstrx(ji,jj) = zCorx(ji,jj) * rswitch     ! Coriolis stress term
-               zdiag_corstry(ji,jj) = zCory(ji,jj) * rswitch
-               
-               zdiag_intstrx(ji,jj) = zfU(ji,jj)   * rswitch     ! internal stress term
-               zdiag_intstry(ji,jj) = zfV(ji,jj)   * rswitch
-               
-               zdiag_utau_oi(ji,jj) = ztaux_oi(ji,jj) * rswitch  ! oceanic stress
-               zdiag_vtau_oi(ji,jj) = ztauy_oi(ji,jj) * rswitch
-               
                ! 2D ice mass, snow mass, area transport arrays (X, Y)
-               zfac_x = 0.5 * u_ice(ji,jj) * e2u(ji,jj) * rswitch
-               zfac_y = 0.5 * v_ice(ji,jj) * e1v(ji,jj) * rswitch
-               
+               zfac_x = 0.5 * u_ice(ji,jj) * e2u(ji,jj) * zmsk00(ji,jj)
+               zfac_y = 0.5 * v_ice(ji,jj) * e1v(ji,jj) * zmsk00(ji,jj)
+
                zdiag_xmtrp_ice(ji,jj) = rhoi * zfac_x * ( vt_i(ji+1,jj) + vt_i(ji,jj) ) ! ice mass transport, X-component
                zdiag_ymtrp_ice(ji,jj) = rhoi * zfac_y * ( vt_i(ji,jj+1) + vt_i(ji,jj) ) !        ''           Y-   ''
-               
+
                zdiag_xmtrp_snw(ji,jj) = rhos * zfac_x * ( vt_s(ji+1,jj) + vt_s(ji,jj) ) ! snow mass transport, X-component
                zdiag_ymtrp_snw(ji,jj) = rhos * zfac_y * ( vt_s(ji,jj+1) + vt_s(ji,jj) ) !          ''          Y-   ''
-               
+
                zdiag_xatrp(ji,jj)     = zfac_x * ( at_i(ji+1,jj) + at_i(ji,jj) )        ! area transport,      X-component
                zdiag_yatrp(ji,jj)     = zfac_y * ( at_i(ji,jj+1) + at_i(ji,jj) )        !        ''            Y-   ''
-               
-            END DO
-         END DO
-         
-         CALL lbc_lnk_multi( 'icedyn_rhg_evp', zdiag_sig1   , 'T',  1., zdiag_sig2   , 'T',  1.,   &
-            &                zdiag_dssh_dx, 'U', -1., zdiag_dssh_dy, 'V', -1.,   &
-            &                zdiag_corstrx, 'U', -1., zdiag_corstry, 'V', -1.,   & 
-            &                zdiag_intstrx, 'U', -1., zdiag_intstry, 'V', -1.    )
-                  
-         CALL lbc_lnk_multi( 'icedyn_rhg_evp', zdiag_utau_oi  , 'U', -1., zdiag_vtau_oi  , 'V', -1.,   &
-            &                zdiag_xmtrp_ice, 'U', -1., zdiag_xmtrp_snw, 'U', -1.,   &
-            &                zdiag_xatrp    , 'U', -1., zdiag_ymtrp_ice, 'V', -1.,   &
-            &                zdiag_ymtrp_snw, 'V', -1., zdiag_yatrp    , 'V', -1.    )
-         
-         IF( iom_use('normstr' ) )   CALL iom_put( 'normstr'  ,  zdiag_sig1(:,:)      )   ! Normal stress
-         IF( iom_use('sheastr' ) )   CALL iom_put( 'sheastr'  ,  zdiag_sig2(:,:)      )   ! Shear stress
-         IF( iom_use('dssh_dx' ) )   CALL iom_put( 'dssh_dx'  ,  zdiag_dssh_dx(:,:)   )   ! Sea-surface tilt term in force balance (x)
-         IF( iom_use('dssh_dy' ) )   CALL iom_put( 'dssh_dy'  ,  zdiag_dssh_dy(:,:)   )   ! Sea-surface tilt term in force balance (y)
-         IF( iom_use('corstrx' ) )   CALL iom_put( 'corstrx'  ,  zdiag_corstrx(:,:)   )   ! Coriolis force term in force balance (x)
-         IF( iom_use('corstry' ) )   CALL iom_put( 'corstry'  ,  zdiag_corstry(:,:)   )   ! Coriolis force term in force balance (y)
-         IF( iom_use('intstrx' ) )   CALL iom_put( 'intstrx'  ,  zdiag_intstrx(:,:)   )   ! Internal force term in force balance (x)
-         IF( iom_use('intstry' ) )   CALL iom_put( 'intstry'  ,  zdiag_intstry(:,:)   )   ! Internal force term in force balance (y)
-         IF( iom_use('utau_oi' ) )   CALL iom_put( 'utau_oi'  ,  zdiag_utau_oi(:,:)   )   ! Ocean stress term in force balance (x)
-         IF( iom_use('vtau_oi' ) )   CALL iom_put( 'vtau_oi'  ,  zdiag_vtau_oi(:,:)   )   ! Ocean stress term in force balance (y)
-         IF( iom_use('xmtrpice') )   CALL iom_put( 'xmtrpice' ,  zdiag_xmtrp_ice(:,:) )   ! X-component of sea-ice mass transport (kg/s)
-         IF( iom_use('ymtrpice') )   CALL iom_put( 'ymtrpice' ,  zdiag_ymtrp_ice(:,:) )   ! Y-component of sea-ice mass transport 
-         IF( iom_use('xmtrpsnw') )   CALL iom_put( 'xmtrpsnw' ,  zdiag_xmtrp_snw(:,:) )   ! X-component of snow mass transport (kg/s)
-         IF( iom_use('ymtrpsnw') )   CALL iom_put( 'ymtrpsnw' ,  zdiag_ymtrp_snw(:,:) )   ! Y-component of snow mass transport
-         IF( iom_use('xatrp'   ) )   CALL iom_put( 'xatrp'    ,  zdiag_xatrp(:,:)     )   ! X-component of ice area transport
-         IF( iom_use('yatrp'   ) )   CALL iom_put( 'yatrp'    ,  zdiag_yatrp(:,:)     )   ! Y-component of ice area transport
-
-         DEALLOCATE( zdiag_sig1      , zdiag_sig2      , zdiag_dssh_dx   , zdiag_dssh_dy   ,  &
-            &        zdiag_corstrx   , zdiag_corstry   , zdiag_intstrx   , zdiag_intstry   ,  &
-            &        zdiag_utau_oi   , zdiag_vtau_oi   , zdiag_xmtrp_ice , zdiag_ymtrp_ice ,  &
-            &        zdiag_xmtrp_snw , zdiag_ymtrp_snw , zdiag_xatrp     , zdiag_yatrp     )
+
+            END DO
+         END DO
+
+         CALL lbc_lnk_multi( 'icedyn_rhg_evp', zdiag_xmtrp_ice, 'U', -1., zdiag_ymtrp_ice, 'V', -1., &
+            &                                  zdiag_xmtrp_snw, 'U', -1., zdiag_ymtrp_snw, 'V', -1., &
+            &                                  zdiag_xatrp    , 'U', -1., zdiag_yatrp    , 'V', -1. )
+
+         CALL iom_put( 'xmtrpice' , zdiag_xmtrp_ice )   ! X-component of sea-ice mass transport (kg/s)
+         CALL iom_put( 'ymtrpice' , zdiag_ymtrp_ice )   ! Y-component of sea-ice mass transport 
+         CALL iom_put( 'xmtrpsnw' , zdiag_xmtrp_snw )   ! X-component of snow mass transport (kg/s)
+         CALL iom_put( 'ymtrpsnw' , zdiag_ymtrp_snw )   ! Y-component of snow mass transport
+         CALL iom_put( 'xatrp'    , zdiag_xatrp     )   ! X-component of ice area transport
+         CALL iom_put( 'yatrp'    , zdiag_yatrp     )   ! Y-component of ice area transport
+
+         DEALLOCATE( zdiag_xmtrp_ice , zdiag_ymtrp_ice , &
+            &        zdiag_xmtrp_snw , zdiag_ymtrp_snw , zdiag_xatrp , zdiag_yatrp )
 
       ENDIF
Index: /NEMO/trunk/src/ICE/iceistate.F90
===================================================================
--- /NEMO/trunk/src/ICE/iceistate.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/iceistate.F90	(revision 11536)
@@ -22,6 +22,8 @@
    USE eosbn2         ! equation of state
    USE domvvl         ! Variable volume
-   USE ice            ! sea-ice variables
-   USE icevar         ! ice_var_salprof
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamics variables
+   USE icetab         ! sea-ice: 1D <==> 2D transformation
+   USE icevar         ! sea-ice: operations
    !
    USE in_out_manager ! I/O manager
@@ -36,29 +38,27 @@
    PUBLIC   ice_istate        ! called by icestp.F90
    PUBLIC   ice_istate_init   ! called by icestp.F90
-
-   INTEGER , PARAMETER ::   jpfldi = 6           ! maximum number of files to read
-   INTEGER , PARAMETER ::   jp_hti = 1           ! index of ice thickness (m)    at T-point
-   INTEGER , PARAMETER ::   jp_hts = 2           ! index of snow thicknes (m)    at T-point
-   INTEGER , PARAMETER ::   jp_ati = 3           ! index of ice fraction (%) at T-point
-   INTEGER , PARAMETER ::   jp_tsu = 4           ! index of ice surface temp (K)    at T-point
-   INTEGER , PARAMETER ::   jp_tmi = 5           ! index of ice temp at T-point
-   INTEGER , PARAMETER ::   jp_smi = 6           ! index of ice sali at T-point
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   si  ! structure of input fields (file informations, fields read)
    !
    !                             !! ** namelist (namini) **
-   LOGICAL  ::   ln_iceini        ! initialization or not
-   LOGICAL  ::   ln_iceini_file   ! Ice initialization state from 2D netcdf file
-   REAL(wp) ::   rn_thres_sst     ! threshold water temperature for initial sea ice
-   REAL(wp) ::   rn_hts_ini_n     ! initial snow thickness in the north
-   REAL(wp) ::   rn_hts_ini_s     ! initial snow thickness in the south
-   REAL(wp) ::   rn_hti_ini_n     ! initial ice thickness in the north
-   REAL(wp) ::   rn_hti_ini_s     ! initial ice thickness in the south
-   REAL(wp) ::   rn_ati_ini_n     ! initial leads area in the north
-   REAL(wp) ::   rn_ati_ini_s     ! initial leads area in the south
-   REAL(wp) ::   rn_smi_ini_n     ! initial salinity 
-   REAL(wp) ::   rn_smi_ini_s     ! initial salinity
-   REAL(wp) ::   rn_tmi_ini_n     ! initial temperature
-   REAL(wp) ::   rn_tmi_ini_s     ! initial temperature
-   
+   LOGICAL, PUBLIC  ::   ln_iceini        !: Ice initialization or not
+   LOGICAL, PUBLIC  ::   ln_iceini_file   !: Ice initialization from 2D netcdf file
+   REAL(wp) ::   rn_thres_sst
+   REAL(wp) ::   rn_hti_ini_n, rn_hts_ini_n, rn_ati_ini_n, rn_smi_ini_n, rn_tmi_ini_n, rn_tsu_ini_n, rn_tms_ini_n
+   REAL(wp) ::   rn_hti_ini_s, rn_hts_ini_s, rn_ati_ini_s, rn_smi_ini_s, rn_tmi_ini_s, rn_tsu_ini_s, rn_tms_ini_s
+   REAL(wp) ::   rn_apd_ini_n, rn_hpd_ini_n
+   REAL(wp) ::   rn_apd_ini_s, rn_hpd_ini_s
+   !
+   !                              ! if ln_iceini_file = T
+   INTEGER , PARAMETER ::   jpfldi = 9           ! maximum number of files to read
+   INTEGER , PARAMETER ::   jp_hti = 1           ! index of ice thickness    (m)
+   INTEGER , PARAMETER ::   jp_hts = 2           ! index of snw thickness    (m)
+   INTEGER , PARAMETER ::   jp_ati = 3           ! index of ice fraction     (-)
+   INTEGER , PARAMETER ::   jp_smi = 4           ! index of ice salinity     (g/kg)
+   INTEGER , PARAMETER ::   jp_tmi = 5           ! index of ice temperature  (K)
+   INTEGER , PARAMETER ::   jp_tsu = 6           ! index of ice surface temp (K)
+   INTEGER , PARAMETER ::   jp_tms = 7           ! index of snw temperature  (K)
+   INTEGER , PARAMETER ::   jp_apd = 8           ! index of pnd fraction     (-)
+   INTEGER , PARAMETER ::   jp_hpd = 9           ! index of pnd depth        (m)
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   si  ! structure of input fields (file informations, fields read)
+   !   
    !!----------------------------------------------------------------------
    !! NEMO/ICE 4.0 , NEMO Consortium (2018)
@@ -68,5 +68,5 @@
 CONTAINS
 
-   SUBROUTINE ice_istate
+   SUBROUTINE ice_istate( kt )
       !!-------------------------------------------------------------------
       !!                    ***  ROUTINE ice_istate  ***
@@ -87,16 +87,19 @@
       !!
       !! ** Notes   : o_i, t_su, t_s, t_i, sz_i must be filled everywhere, even
-      !!              where there is no ice (clem: I do not know why, is it mandatory?) 
+      !!              where there is no ice
       !!--------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! time step 
+      !!
       INTEGER  ::   ji, jj, jk, jl         ! dummy loop indices
-      INTEGER  ::   i_hemis, i_fill, jl0   ! local integers
-      REAL(wp) ::   ztmelts, zdh
-      REAL(wp) ::   zarg, zV, zconv, zdv, zfac
+      REAL(wp) ::   ztmelts
       INTEGER , DIMENSION(4)           ::   itest
       REAL(wp), DIMENSION(jpi,jpj)     ::   z2d
       REAL(wp), DIMENSION(jpi,jpj)     ::   zswitch    ! ice indicator
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zht_i_ini, zat_i_ini, zvt_i_ini            !data from namelist or nc file
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini !data from namelist or nc file
-      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zh_i_ini , za_i_ini                        !data by cattegories to fill
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zht_i_ini, zat_i_ini, ztm_s_ini            !data from namelist or nc file
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zt_su_ini, zht_s_ini, zsm_i_ini, ztm_i_ini !data from namelist or nc file
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zapnd_ini, zhpnd_ini                       !data from namelist or nc file
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zti_3d , zts_3d                            !temporary arrays
+      !!
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   zhi_2d, zhs_2d, zai_2d, zti_2d, zts_2d, ztsu_2d, zsi_2d, zaip_2d, zhip_2d
       !--------------------------------------------------------------------
 
@@ -105,9 +108,13 @@
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
 
-      !--------------------------------------------------------------------
-      ! 1) Set surface and bottom temperatures to initial values
-      !--------------------------------------------------------------------
-      !
-      ! init surface temperature
+      !---------------------------
+      ! 1) 1st init. of the fields
+      !---------------------------
+      !
+      ! basal temperature (considered at freezing point)   [Kelvin]
+      CALL eos_fzp( sss_m(:,:), t_bo(:,:) )
+      t_bo(:,:) = ( t_bo(:,:) + rt0 ) * tmask(:,:,1) 
+      !
+      ! surface temperature and conductivity
       DO jl = 1, jpl
          t_su   (:,:,jl) = rt0 * tmask(:,:,1)  ! temp at the surface
@@ -115,33 +122,110 @@
       END DO
       !
-      ! init basal temperature (considered at freezing point)   [Kelvin]
-      CALL eos_fzp( sss_m(:,:), t_bo(:,:) )
-      t_bo(:,:) = ( t_bo(:,:) + rt0 ) * tmask(:,:,1) 
-
+      ! ice and snw temperatures
+      DO jl = 1, jpl
+         DO jk = 1, nlay_i
+            t_i(:,:,jk,jl) = rt0 * tmask(:,:,1)
+         END DO
+         DO jk = 1, nlay_s
+            t_s(:,:,jk,jl) = rt0 * tmask(:,:,1)
+         END DO
+      END DO
+      !
+      ! specific temperatures for coupled runs
+      tn_ice (:,:,:) = t_i (:,:,1,:)
+      t1_ice (:,:,:) = t_i (:,:,1,:)
+
+      ! heat contents
+      e_i (:,:,:,:) = 0._wp
+      e_s (:,:,:,:) = 0._wp
+      
+      ! general fields
+      a_i (:,:,:) = 0._wp
+      v_i (:,:,:) = 0._wp
+      v_s (:,:,:) = 0._wp
+      sv_i(:,:,:) = 0._wp
+      oa_i(:,:,:) = 0._wp
+      !
+      h_i (:,:,:) = 0._wp
+      h_s (:,:,:) = 0._wp
+      s_i (:,:,:) = 0._wp
+      o_i (:,:,:) = 0._wp
+      !
+      ! melt ponds
+      a_ip     (:,:,:) = 0._wp
+      v_ip     (:,:,:) = 0._wp
+      a_ip_frac(:,:,:) = 0._wp
+      h_ip     (:,:,:) = 0._wp
+      !
+      ! ice velocities
+      u_ice (:,:) = 0._wp
+      v_ice (:,:) = 0._wp
+      !
+      !------------------------------------------------------------------------
+      ! 2) overwrite some of the fields with namelist parameters or netcdf file
+      !------------------------------------------------------------------------
       IF( ln_iceini ) THEN
-         !-----------------------------------------------------------
-         ! 2) Compute or read sea ice variables ===> single category
-         !-----------------------------------------------------------
-         !
          !                             !---------------!
          IF( ln_iceini_file )THEN      ! Read a file   !
             !                          !---------------!
-            !
-            zht_i_ini(:,:)  = si(jp_hti)%fnow(:,:,1)
-            zht_s_ini(:,:)  = si(jp_hts)%fnow(:,:,1)
-            zat_i_ini(:,:)  = si(jp_ati)%fnow(:,:,1)
-            zts_u_ini(:,:)  = si(jp_tsu)%fnow(:,:,1)
-            ztm_i_ini(:,:)  = si(jp_tmi)%fnow(:,:,1)
-            zsm_i_ini(:,:)  = si(jp_smi)%fnow(:,:,1)
-            !
-            WHERE( zat_i_ini(:,:) > 0._wp ) ; zswitch(:,:) = tmask(:,:,1) 
-            ELSEWHERE                       ; zswitch(:,:) = 0._wp
+            WHERE( ff_t(:,:) >= 0._wp )   ;   zswitch(:,:) = 1._wp
+            ELSEWHERE                     ;   zswitch(:,:) = 0._wp
             END WHERE
-            zvt_i_ini(:,:) = zht_i_ini(:,:) * zat_i_ini(:,:)
-            !
+            !
+            CALL fld_read( kt, 1, si ) ! input fields provided at the current time-step
+            !
+            ! -- mandatory fields -- !
+            zht_i_ini(:,:) = si(jp_hti)%fnow(:,:,1)
+            zht_s_ini(:,:) = si(jp_hts)%fnow(:,:,1)
+            zat_i_ini(:,:) = si(jp_ati)%fnow(:,:,1)
+
+            ! -- optional fields -- !
+            !    if fields do not exist then set them to the values present in the namelist (except for snow and surface temperature)
+            !
+            ! ice salinity
+            IF( TRIM(si(jp_smi)%clrootname) == 'NOT USED' ) &
+               &     si(jp_smi)%fnow(:,:,1) = ( rn_smi_ini_n * zswitch + rn_smi_ini_s * (1._wp - zswitch) ) * tmask(:,:,1)
+            zsm_i_ini(:,:) = si(jp_smi)%fnow(:,:,1)
+            !
+            ! ice temperature
+            IF( TRIM(si(jp_tmi)%clrootname) == 'NOT USED' ) &
+               &     si(jp_tmi)%fnow(:,:,1) = ( rn_tmi_ini_n * zswitch + rn_tmi_ini_s * (1._wp - zswitch) ) * tmask(:,:,1)
+            ztm_i_ini(:,:) = si(jp_tmi)%fnow(:,:,1)
+            !
+            ! surface temperature => set to ice temperature if it exists
+            IF    ( TRIM(si(jp_tsu)%clrootname) == 'NOT USED' .AND. TRIM(si(jp_tmi)%clrootname) == 'NOT USED' ) THEN
+                     si(jp_tsu)%fnow(:,:,1) = ( rn_tsu_ini_n * zswitch + rn_tsu_ini_s * (1._wp - zswitch) ) * tmask(:,:,1)
+            ELSEIF( TRIM(si(jp_tsu)%clrootname) == 'NOT USED' .AND. TRIM(si(jp_tmi)%clrootname) /= 'NOT USED' ) THEN
+                     si(jp_tsu)%fnow(:,:,1) = si(jp_tmi)%fnow(:,:,1)
+            ENDIF
+            zt_su_ini(:,:) = si(jp_tsu)%fnow(:,:,1)
+            !
+            ! snow temperature => set to ice temperature if it exists
+            IF    ( TRIM(si(jp_tms)%clrootname) == 'NOT USED' .AND. TRIM(si(jp_tmi)%clrootname) == 'NOT USED' ) THEN
+                     si(jp_tms)%fnow(:,:,1) = ( rn_tms_ini_n * zswitch + rn_tms_ini_s * (1._wp - zswitch) ) * tmask(:,:,1)
+            ELSEIF( TRIM(si(jp_tms)%clrootname) == 'NOT USED' .AND. TRIM(si(jp_tmi)%clrootname) /= 'NOT USED' ) THEN
+                     si(jp_tms)%fnow(:,:,1) = si(jp_tmi)%fnow(:,:,1)
+            ENDIF
+            ztm_s_ini(:,:) = si(jp_tms)%fnow(:,:,1)
+            !
+            ! pond concentration
+            IF( TRIM(si(jp_apd)%clrootname) == 'NOT USED' ) &
+               &     si(jp_apd)%fnow(:,:,1) = ( rn_apd_ini_n * zswitch + rn_apd_ini_s * (1._wp - zswitch) ) * tmask(:,:,1) & ! rn_apd = pond fraction => rn_apnd * a_i = pond conc.
+               &                              * si(jp_ati)%fnow(:,:,1) 
+            zapnd_ini(:,:) = si(jp_apd)%fnow(:,:,1)
+            !
+            ! pond depth
+            IF( TRIM(si(jp_hpd)%clrootname) == 'NOT USED' ) &
+               &     si(jp_hpd)%fnow(:,:,1) = ( rn_hpd_ini_n * zswitch + rn_hpd_ini_s * (1._wp - zswitch) ) * tmask(:,:,1)
+            zhpnd_ini(:,:) = si(jp_hpd)%fnow(:,:,1)
+            !
+            ! change the switch for the following
+            WHERE( zat_i_ini(:,:) > 0._wp )   ;   zswitch(:,:) = tmask(:,:,1) 
+            ELSEWHERE                         ;   zswitch(:,:) = 0._wp
+            END WHERE
             !                          !---------------!
          ELSE                          ! Read namelist !
             !                          !---------------!
-            ! no ice if sst <= t-freez + ttest
+            ! no ice if (sst - Tfreez) >= thresold
             WHERE( ( sst_m(:,:) - (t_bo(:,:) - rt0) ) * tmask(:,:,1) >= rn_thres_sst )   ;   zswitch(:,:) = 0._wp 
             ELSEWHERE                                                                    ;   zswitch(:,:) = tmask(:,:,1)
@@ -153,184 +237,103 @@
                zht_s_ini(:,:) = rn_hts_ini_n * zswitch(:,:)
                zat_i_ini(:,:) = rn_ati_ini_n * zswitch(:,:)
-               zts_u_ini(:,:) = rn_tmi_ini_n * zswitch(:,:)
                zsm_i_ini(:,:) = rn_smi_ini_n * zswitch(:,:)
                ztm_i_ini(:,:) = rn_tmi_ini_n * zswitch(:,:)
+               zt_su_ini(:,:) = rn_tsu_ini_n * zswitch(:,:)
+               ztm_s_ini(:,:) = rn_tms_ini_n * zswitch(:,:)
+               zapnd_ini(:,:) = rn_apd_ini_n * zswitch(:,:) * zat_i_ini(:,:) ! rn_apd = pond fraction => rn_apd * a_i = pond conc. 
+               zhpnd_ini(:,:) = rn_hpd_ini_n * zswitch(:,:)
             ELSEWHERE
                zht_i_ini(:,:) = rn_hti_ini_s * zswitch(:,:)
                zht_s_ini(:,:) = rn_hts_ini_s * zswitch(:,:)
                zat_i_ini(:,:) = rn_ati_ini_s * zswitch(:,:)
-               zts_u_ini(:,:) = rn_tmi_ini_s * zswitch(:,:)
                zsm_i_ini(:,:) = rn_smi_ini_s * zswitch(:,:)
                ztm_i_ini(:,:) = rn_tmi_ini_s * zswitch(:,:)
+               zt_su_ini(:,:) = rn_tsu_ini_s * zswitch(:,:)
+               ztm_s_ini(:,:) = rn_tms_ini_s * zswitch(:,:)
+               zapnd_ini(:,:) = rn_apd_ini_s * zswitch(:,:) * zat_i_ini(:,:) ! rn_apd = pond fraction => rn_apd * a_i = pond conc.
+               zhpnd_ini(:,:) = rn_hpd_ini_s * zswitch(:,:)
             END WHERE
-            zvt_i_ini(:,:) = zht_i_ini(:,:) * zat_i_ini(:,:)
-            !
+            !
+         ENDIF
+
+         ! make sure ponds = 0 if no ponds scheme
+         IF ( .NOT.ln_pnd ) THEN
+            zapnd_ini(:,:) = 0._wp
+            zhpnd_ini(:,:) = 0._wp
          ENDIF
          
-         !------------------------------------------------------------------
-         ! 3) Distribute ice concentration and thickness into the categories
-         !------------------------------------------------------------------
-         ! a gaussian distribution for ice concentration is used
-         ! then we check whether the distribution fullfills
-         ! volume and area conservation, positivity and ice categories bounds
-
-         IF( jpl == 1 ) THEN
-            !
-            zh_i_ini(:,:,1) = zht_i_ini(:,:)
-            za_i_ini(:,:,1) = zat_i_ini(:,:)            
-            !
-         ELSE
-            zh_i_ini(:,:,:) = 0._wp 
-            za_i_ini(:,:,:) = 0._wp
-            !
+         !-------------!
+         ! fill fields !
+         !-------------!
+         ! select ice covered grid points
+         npti = 0 ; nptidx(:) = 0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF ( zht_i_ini(ji,jj) > 0._wp ) THEN
+                  npti         = npti  + 1
+                  nptidx(npti) = (jj - 1) * jpi + ji
+               ENDIF
+            END DO
+         END DO
+
+         ! move to 1D arrays: (jpi,jpj) -> (jpi*jpj)
+         CALL tab_2d_1d( npti, nptidx(1:npti), h_i_1d (1:npti)  , zht_i_ini )
+         CALL tab_2d_1d( npti, nptidx(1:npti), h_s_1d (1:npti)  , zht_s_ini )
+         CALL tab_2d_1d( npti, nptidx(1:npti), at_i_1d(1:npti)  , zat_i_ini )
+         CALL tab_2d_1d( npti, nptidx(1:npti), t_i_1d (1:npti,1), ztm_i_ini )
+         CALL tab_2d_1d( npti, nptidx(1:npti), t_s_1d (1:npti,1), ztm_s_ini )
+         CALL tab_2d_1d( npti, nptidx(1:npti), t_su_1d(1:npti)  , zt_su_ini )
+         CALL tab_2d_1d( npti, nptidx(1:npti), s_i_1d (1:npti)  , zsm_i_ini )
+         CALL tab_2d_1d( npti, nptidx(1:npti), a_ip_1d(1:npti)  , zapnd_ini )
+         CALL tab_2d_1d( npti, nptidx(1:npti), h_ip_1d(1:npti)  , zhpnd_ini )
+
+         ! allocate temporary arrays
+         ALLOCATE( zhi_2d(npti,jpl), zhs_2d(npti,jpl), zai_2d (npti,jpl), &
+            &      zti_2d(npti,jpl), zts_2d(npti,jpl), ztsu_2d(npti,jpl), zsi_2d(npti,jpl), zaip_2d(npti,jpl), zhip_2d(npti,jpl) )
+         
+         ! distribute 1-cat into jpl-cat: (jpi*jpj) -> (jpi*jpj,jpl)
+         CALL ice_var_itd( h_i_1d(1:npti)  , h_s_1d(1:npti)  , at_i_1d(1:npti),                                                   &
+            &              zhi_2d          , zhs_2d          , zai_2d         ,                                                   &
+            &              t_i_1d(1:npti,1), t_s_1d(1:npti,1), t_su_1d(1:npti), s_i_1d(1:npti), a_ip_1d(1:npti), h_ip_1d(1:npti), &
+            &              zti_2d          , zts_2d          , ztsu_2d        , zsi_2d        , zaip_2d        , zhip_2d )
+
+         ! move to 3D arrays: (jpi*jpj,jpl) -> (jpi,jpj,jpl)
+         DO jl = 1, jpl
+            zti_3d(:,:,jl) = rt0 * tmask(:,:,1)
+            zts_3d(:,:,jl) = rt0 * tmask(:,:,1)
+         END DO
+         CALL tab_2d_3d( npti, nptidx(1:npti), zhi_2d   , h_i    )
+         CALL tab_2d_3d( npti, nptidx(1:npti), zhs_2d   , h_s    )
+         CALL tab_2d_3d( npti, nptidx(1:npti), zai_2d   , a_i    )
+         CALL tab_2d_3d( npti, nptidx(1:npti), zti_2d   , zti_3d )
+         CALL tab_2d_3d( npti, nptidx(1:npti), zts_2d   , zts_3d )
+         CALL tab_2d_3d( npti, nptidx(1:npti), ztsu_2d  , t_su   )
+         CALL tab_2d_3d( npti, nptidx(1:npti), zsi_2d   , s_i    )
+         CALL tab_2d_3d( npti, nptidx(1:npti), zaip_2d  , a_ip   )
+         CALL tab_2d_3d( npti, nptidx(1:npti), zhip_2d  , h_ip   )
+
+         ! deallocate temporary arrays
+         DEALLOCATE( zhi_2d, zhs_2d, zai_2d , &
+            &        zti_2d, zts_2d, ztsu_2d, zsi_2d, zaip_2d, zhip_2d )
+
+         ! calculate extensive and intensive variables
+         CALL ice_var_salprof ! for sz_i
+         DO jl = 1, jpl
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  !
-                  IF( zat_i_ini(ji,jj) > 0._wp .AND. zht_i_ini(ji,jj) > 0._wp )THEN
-
-                     ! find which category (jl0) the input ice thickness falls into
-                     jl0 = jpl
-                     DO jl = 1, jpl
-                        IF ( ( zht_i_ini(ji,jj) >  hi_max(jl-1) ) .AND. ( zht_i_ini(ji,jj) <= hi_max(jl) ) ) THEN
-                           jl0 = jl
-                           CYCLE
-                        ENDIF
-                     END DO
-                     !
-                     itest(:) = 0
-                     i_fill   = jpl + 1                                            !------------------------------------
-                     DO WHILE ( ( SUM( itest(:) ) /= 4 ) .AND. ( i_fill >= 2 ) )   ! iterative loop on i_fill categories
-                        !                                                          !------------------------------------
-                        i_fill = i_fill - 1
-                        !
-                        zh_i_ini(ji,jj,:) = 0._wp 
-                        za_i_ini(ji,jj,:) = 0._wp
-                        itest(:) = 0
-                        !
-                        IF ( i_fill == 1 ) THEN      !-- case very thin ice: fill only category 1
-                           zh_i_ini(ji,jj,1) = zht_i_ini(ji,jj)
-                           za_i_ini(ji,jj,1) = zat_i_ini(ji,jj)
-                        ELSE                         !-- case ice is thicker: fill categories >1
-                           ! thickness
-                           DO jl = 1, i_fill-1
-                              zh_i_ini(ji,jj,jl) = hi_mean(jl)
-                           END DO
-                           !
-                           ! concentration
-                           za_i_ini(ji,jj,jl0) = zat_i_ini(ji,jj) / SQRT(REAL(jpl))
-                           DO jl = 1, i_fill - 1
-                              IF( jl /= jl0 )THEN
-                                 zarg               = ( zh_i_ini(ji,jj,jl) - zht_i_ini(ji,jj) ) / ( 0.5_wp * zht_i_ini(ji,jj) )
-                                 za_i_ini(ji,jj,jl) = za_i_ini(ji,jj,jl0) * EXP(-zarg**2)
-                              ENDIF
-                           END DO
-
-                           ! last category
-                           za_i_ini(ji,jj,i_fill) = zat_i_ini(ji,jj) - SUM( za_i_ini(ji,jj,1:i_fill-1) )
-                           zV = SUM( za_i_ini(ji,jj,1:i_fill-1) * zh_i_ini(ji,jj,1:i_fill-1) )
-                           zh_i_ini(ji,jj,i_fill) = ( zvt_i_ini(ji,jj) - zV ) / MAX( za_i_ini(ji,jj,i_fill), epsi10 ) 
-
-                           ! correction if concentration of upper cat is greater than lower cat
-                           !   (it should be a gaussian around jl0 but sometimes it is not)
-                           IF ( jl0 /= jpl ) THEN
-                              DO jl = jpl, jl0+1, -1
-                                 IF ( za_i_ini(ji,jj,jl) > za_i_ini(ji,jj,jl-1) ) THEN
-                                    zdv = zh_i_ini(ji,jj,jl) * za_i_ini(ji,jj,jl)
-                                    zh_i_ini(ji,jj,jl    ) = 0._wp
-                                    za_i_ini(ji,jj,jl    ) = 0._wp
-                                    za_i_ini(ji,jj,1:jl-1) = za_i_ini(ji,jj,1:jl-1)  &
-                                       &                     + zdv / MAX( REAL(jl-1) * zht_i_ini(ji,jj), epsi10 )
-                                 END IF
-                              ENDDO
-                           ENDIF
-                           !
-                        ENDIF
-                        !
-                        ! Compatibility tests
-                        zconv = ABS( zat_i_ini(ji,jj) - SUM( za_i_ini(ji,jj,1:jpl) ) )           ! Test 1: area conservation
-                        IF ( zconv < epsi06 ) itest(1) = 1
-                        !
-                        zconv = ABS(       zat_i_ini(ji,jj)       * zht_i_ini(ji,jj)   &         ! Test 2: volume conservation
-                           &        - SUM( za_i_ini (ji,jj,1:jpl) * zh_i_ini (ji,jj,1:jpl) ) )
-                        IF ( zconv < epsi06 ) itest(2) = 1
-                        !
-                        IF ( zh_i_ini(ji,jj,i_fill) >= hi_max(i_fill-1) ) itest(3) = 1           ! Test 3: thickness of the last category is in-bounds ?
-                        !
-                        itest(4) = 1
-                        DO jl = 1, i_fill
-                           IF ( za_i_ini(ji,jj,jl) < 0._wp ) itest(4) = 0                        ! Test 4: positivity of ice concentrations
-                        END DO
-                        !                                                          !----------------------------
-                     END DO                                                        ! end iteration on categories
-                     !                                                             !----------------------------
-                     IF( lwp .AND. SUM(itest) /= 4 ) THEN 
-                        WRITE(numout,*)
-                        WRITE(numout,*) ' !!!! ALERT itest is not equal to 4      !!! '
-                        WRITE(numout,*) ' !!!! Something is wrong in the SI3 initialization procedure '
-                        WRITE(numout,*)
-                        WRITE(numout,*) ' *** itest_i (i=1,4) = ', itest(:)
-                        WRITE(numout,*) ' zat_i_ini : ', zat_i_ini(ji,jj)
-                        WRITE(numout,*) ' zht_i_ini : ', zht_i_ini(ji,jj)
-                     ENDIF
-                     !
-                  ENDIF
-                  !
+                  v_i (ji,jj,jl) = h_i(ji,jj,jl) * a_i(ji,jj,jl)
+                  v_s (ji,jj,jl) = h_s(ji,jj,jl) * a_i(ji,jj,jl)
+                  sv_i(ji,jj,jl) = MIN( MAX( rn_simin , s_i(ji,jj,jl) ) , rn_simax ) * v_i(ji,jj,jl)
                END DO
             END DO
-         ENDIF
-         
-         !---------------------------------------------------------------------
-         ! 4) Fill in sea ice arrays
-         !---------------------------------------------------------------------
-         !
-         ! Ice concentration, thickness and volume, ice salinity, ice age, surface temperature
-         DO jl = 1, jpl ! loop over categories
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  a_i(ji,jj,jl)  = zswitch(ji,jj) * za_i_ini(ji,jj,jl)                       ! concentration
-                  h_i(ji,jj,jl)  = zswitch(ji,jj) * zh_i_ini(ji,jj,jl)                       ! ice thickness
-                  s_i(ji,jj,jl)  = zswitch(ji,jj) * zsm_i_ini(ji,jj)                         ! salinity
-                  o_i(ji,jj,jl)  = 0._wp                                                     ! age (0 day)
-                  t_su(ji,jj,jl) = zswitch(ji,jj) * zts_u_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rt0 ! surf temp
-                  !
-                  IF( zht_i_ini(ji,jj) > 0._wp )THEN
-                    h_s(ji,jj,jl)= h_i(ji,jj,jl) * ( zht_s_ini(ji,jj) / zht_i_ini(ji,jj) )  ! snow depth
-                  ELSE
-                    h_s(ji,jj,jl)= 0._wp
-                  ENDIF
-                  !
-                  ! This case below should not be used if (h_s/h_i) is ok in namelist
-                  ! In case snow load is in excess that would lead to transformation from snow to ice
-                  ! Then, transfer the snow excess into the ice (different from icethd_dh)
-                  zdh = MAX( 0._wp, ( rhos * h_s(ji,jj,jl) + ( rhoi - rau0 ) * h_i(ji,jj,jl) ) * r1_rau0 ) 
-                  ! recompute h_i, h_s avoiding out of bounds values
-                  h_i(ji,jj,jl) = MIN( hi_max(jl), h_i(ji,jj,jl) + zdh )
-                  h_s(ji,jj,jl) = MAX( 0._wp, h_s(ji,jj,jl) - zdh * rhoi * r1_rhos )
-                  !
-                  ! ice volume, salt content, age content
-                  v_i (ji,jj,jl) = h_i(ji,jj,jl) * a_i(ji,jj,jl)              ! ice volume
-                  v_s (ji,jj,jl) = h_s(ji,jj,jl) * a_i(ji,jj,jl)              ! snow volume
-                  sv_i(ji,jj,jl) = MIN( s_i(ji,jj,jl) , sss_m(ji,jj) ) * v_i(ji,jj,jl) ! salt content
-                  oa_i(ji,jj,jl) = o_i(ji,jj,jl) * a_i(ji,jj,jl)               ! age content
-               END DO
-            END DO
-         END DO
-         !
-         IF( nn_icesal /= 2 )  THEN         ! for constant salinity in time
-            CALL ice_var_salprof
-            sv_i = s_i * v_i
-         ENDIF
-         !  
-         ! Snow temperature and heat content
-         DO jk = 1, nlay_s
-            DO jl = 1, jpl ! loop over categories
+         END DO
+         !
+         DO jl = 1, jpl
+            DO jk = 1, nlay_s
                DO jj = 1, jpj
                   DO ji = 1, jpi
-                     t_s(ji,jj,jk,jl) = zswitch(ji,jj) * ztm_i_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rt0
-                     ! Snow energy of melting
-                     e_s(ji,jj,jk,jl) = zswitch(ji,jj) * rhos * ( rcpi * ( rt0 - t_s(ji,jj,jk,jl) ) + rLfus )
-                     !
-                     ! Mutliply by volume, and divide by number of layers to get heat content in J/m2
-                     e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * v_s(ji,jj,jl) * r1_nlay_s
+                     t_s(ji,jj,jk,jl) = zts_3d(ji,jj,jl)
+                     e_s(ji,jj,jk,jl) = zswitch(ji,jj) * v_s(ji,jj,jl) * r1_nlay_s * &
+                        &               rhos * ( rcpi * ( rt0 - t_s(ji,jj,jk,jl) ) + rLfus )
                   END DO
                END DO
@@ -338,85 +341,37 @@
          END DO
          !
-         ! Ice salinity, temperature and heat content
-         DO jk = 1, nlay_i
-            DO jl = 1, jpl ! loop over categories
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
                DO jj = 1, jpj
                   DO ji = 1, jpi
-                     t_i (ji,jj,jk,jl) = zswitch(ji,jj) * ztm_i_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rt0 
-                     sz_i(ji,jj,jk,jl) = zswitch(ji,jj) * zsm_i_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rn_simin
-                     ztmelts          = - rTmlt * sz_i(ji,jj,jk,jl) + rt0 !Melting temperature in K
-                     !
-                     ! heat content per unit volume
-                     e_i(ji,jj,jk,jl) = zswitch(ji,jj) * rhoi * (   rcpi    * ( ztmelts - t_i(ji,jj,jk,jl) )           &
-                        &             + rLfus * ( 1._wp - (ztmelts-rt0) / MIN( (t_i(ji,jj,jk,jl)-rt0) , -epsi20 )  )   &
-                        &             - rcp  * ( ztmelts - rt0 ) )
-                     !
-                     ! Mutliply by ice volume, and divide by number of layers to get heat content in J/m2
-                     e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * v_i(ji,jj,jl) * r1_nlay_i
+                     t_i (ji,jj,jk,jl) = zti_3d(ji,jj,jl) 
+                     ztmelts          = - rTmlt * sz_i(ji,jj,jk,jl) + rt0 ! melting temperature in K
+                     e_i(ji,jj,jk,jl) = zswitch(ji,jj) * v_i(ji,jj,jl) * r1_nlay_i * &
+                        &               rhoi * (  rcpi  * ( ztmelts - t_i(ji,jj,jk,jl) ) + &
+                        &                         rLfus * ( 1._wp - (ztmelts-rt0) / MIN( (t_i(ji,jj,jk,jl)-rt0), -epsi20 ) ) &
+                        &                       - rcp   * ( ztmelts - rt0 ) )
                   END DO
                END DO
             END DO
          END DO
-         !
-         tn_ice (:,:,:) = t_su (:,:,:)
-         t1_ice (:,:,:) = t_i (:,:,1,:)   ! initialisation of 1st layer temp for coupled simu
-
-         ! Melt pond volume and fraction
-         IF ( ln_pnd_CST .OR. ln_pnd_H12 ) THEN   ;   zfac = 1._wp
-         ELSE                                     ;   zfac = 0._wp
-         ENDIF 
-         DO jl = 1, jpl
-            a_ip_frac(:,:,jl) = rn_apnd * zswitch(:,:) * zfac
-            h_ip     (:,:,jl) = rn_hpnd * zswitch(:,:) * zfac
-         END DO
-         a_ip(:,:,:) = a_ip_frac(:,:,:) * a_i (:,:,:) 
-         v_ip(:,:,:) = h_ip     (:,:,:) * a_ip(:,:,:)
-         !
-      ELSE ! if ln_iceini=false
-         a_i  (:,:,:) = 0._wp
-         v_i  (:,:,:) = 0._wp
-         v_s  (:,:,:) = 0._wp
-         sv_i (:,:,:) = 0._wp
-         oa_i (:,:,:) = 0._wp
-         h_i  (:,:,:) = 0._wp
-         h_s  (:,:,:) = 0._wp
-         s_i  (:,:,:) = 0._wp
-         o_i  (:,:,:) = 0._wp
-         !
-         e_i(:,:,:,:) = 0._wp
-         e_s(:,:,:,:) = 0._wp
-         !
-         DO jl = 1, jpl
-            DO jk = 1, nlay_i
-               t_i(:,:,jk,jl) = rt0 * tmask(:,:,1)
-            END DO
-            DO jk = 1, nlay_s
-               t_s(:,:,jk,jl) = rt0 * tmask(:,:,1)
-            END DO
-         END DO
-
-         tn_ice (:,:,:) = t_i (:,:,1,:)
-         t1_ice (:,:,:) = t_i (:,:,1,:)   ! initialisation of 1st layer temp for coupled simu
-         
-         a_ip(:,:,:)      = 0._wp
-         v_ip(:,:,:)      = 0._wp
-         a_ip_frac(:,:,:) = 0._wp
-         h_ip     (:,:,:) = 0._wp
+
+         ! Melt ponds
+         WHERE( a_i > epsi10 )
+            a_ip_frac(:,:,:) = a_ip(:,:,:) / a_i(:,:,:)
+         ELSEWHERE
+            a_ip_frac(:,:,:) = 0._wp
+         END WHERE
+         v_ip(:,:,:) = h_ip(:,:,:) * a_ip(:,:,:)
+          
+         ! specific temperatures for coupled runs
+         tn_ice(:,:,:) = t_su(:,:,:)
+         t1_ice(:,:,:) = t_i (:,:,1,:)
          !
       ENDIF ! ln_iceini
       !
-      at_i (:,:) = 0.0_wp
-      DO jl = 1, jpl
-         at_i (:,:) = at_i (:,:) + a_i (:,:,jl)
-      END DO
-      !
-      ! --- set ice velocities --- !
-      u_ice (:,:) = 0._wp
-      v_ice (:,:) = 0._wp
-      ! fields needed for ice_dyn_adv_umx
-      l_split_advumx(1) = .FALSE.
+      at_i(:,:) = SUM( a_i, dim=3 )
       !
       !----------------------------------------------
-      ! 5) Snow-ice mass (case ice is fully embedded)
+      ! 3) Snow-ice mass (case ice is fully embedded)
       !----------------------------------------------
       snwice_mass  (:,:) = tmask(:,:,1) * SUM( rhos * v_s(:,:,:) + rhoi * v_i(:,:,:), dim=3  )   ! snow+ice mass
@@ -470,5 +425,5 @@
       
       !------------------------------------
-      ! 6) store fields at before time-step
+      ! 4) store fields at before time-step
       !------------------------------------
       ! it is only necessary for the 1st interpolation by Agrif
@@ -508,24 +463,27 @@
       !
       CHARACTER(len=256) ::  cn_dir          ! Root directory for location of ice files
-      TYPE(FLD_N)                    ::   sn_hti, sn_hts, sn_ati, sn_tsu, sn_tmi, sn_smi
+      TYPE(FLD_N)                    ::   sn_hti, sn_hts, sn_ati, sn_smi, sn_tmi, sn_tsu, sn_tms, sn_apd, sn_hpd
       TYPE(FLD_N), DIMENSION(jpfldi) ::   slf_i                 ! array of namelist informations on the fields to read
       !
-      NAMELIST/namini/ ln_iceini, ln_iceini_file, rn_thres_sst, rn_hts_ini_n, rn_hts_ini_s,  &
-         &             rn_hti_ini_n, rn_hti_ini_s, rn_ati_ini_n, rn_ati_ini_s, rn_smi_ini_n, &
-         &             rn_smi_ini_s, rn_tmi_ini_n, rn_tmi_ini_s,                             &
-         &             sn_hti, sn_hts, sn_ati, sn_tsu, sn_tmi, sn_smi, cn_dir
+      NAMELIST/namini/ ln_iceini, ln_iceini_file, rn_thres_sst, &
+         &             rn_hti_ini_n, rn_hti_ini_s, rn_hts_ini_n, rn_hts_ini_s, &
+         &             rn_ati_ini_n, rn_ati_ini_s, rn_smi_ini_n, rn_smi_ini_s, &
+         &             rn_tmi_ini_n, rn_tmi_ini_s, rn_tsu_ini_n, rn_tsu_ini_s, rn_tms_ini_n, rn_tms_ini_s, &
+         &             rn_apd_ini_n, rn_apd_ini_s, rn_hpd_ini_n, rn_hpd_ini_s, &
+         &             sn_hti, sn_hts, sn_ati, sn_tsu, sn_tmi, sn_smi, sn_tms, sn_apd, sn_hpd, cn_dir
       !!-----------------------------------------------------------------------------
       !
       REWIND( numnam_ice_ref )              ! Namelist namini in reference namelist : Ice initial state
       READ  ( numnam_ice_ref, namini, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namini in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namini in reference namelist' )
       REWIND( numnam_ice_cfg )              ! Namelist namini in configuration namelist : Ice initial state
       READ  ( numnam_ice_cfg, namini, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namini in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namini in configuration namelist' )
       IF(lwm) WRITE ( numoni, namini )
       !
       slf_i(jp_hti) = sn_hti  ;  slf_i(jp_hts) = sn_hts
-      slf_i(jp_ati) = sn_ati  ;  slf_i(jp_tsu) = sn_tsu
-      slf_i(jp_tmi) = sn_tmi  ;  slf_i(jp_smi) = sn_smi
+      slf_i(jp_ati) = sn_ati  ;  slf_i(jp_smi) = sn_smi
+      slf_i(jp_tmi) = sn_tmi  ;  slf_i(jp_tsu) = sn_tsu   ;   slf_i(jp_tms) = sn_tms
+      slf_i(jp_apd) = sn_apd  ;  slf_i(jp_hpd) = sn_hpd
       !
       IF(lwp) THEN                          ! control print
@@ -534,17 +492,18 @@
          WRITE(numout,*) '~~~~~~~~~~~~~~~'
          WRITE(numout,*) '   Namelist namini:'
-         WRITE(numout,*) '      initialization with ice (T) or not (F)                 ln_iceini       = ', ln_iceini
-         WRITE(numout,*) '      ice initialization from a netcdf file                  ln_iceini_file  = ', ln_iceini_file
-         WRITE(numout,*) '      max delta ocean temp. above Tfreeze with initial ice   rn_thres_sst    = ', rn_thres_sst
-         WRITE(numout,*) '      initial snow thickness in the north                    rn_hts_ini_n    = ', rn_hts_ini_n
-         WRITE(numout,*) '      initial snow thickness in the south                    rn_hts_ini_s    = ', rn_hts_ini_s 
-         WRITE(numout,*) '      initial ice thickness  in the north                    rn_hti_ini_n    = ', rn_hti_ini_n
-         WRITE(numout,*) '      initial ice thickness  in the south                    rn_hti_ini_s    = ', rn_hti_ini_s
-         WRITE(numout,*) '      initial ice concentr.  in the north                    rn_ati_ini_n    = ', rn_ati_ini_n
-         WRITE(numout,*) '      initial ice concentr.  in the north                    rn_ati_ini_s    = ', rn_ati_ini_s
-         WRITE(numout,*) '      initial  ice salinity  in the north                    rn_smi_ini_n    = ', rn_smi_ini_n
-         WRITE(numout,*) '      initial  ice salinity  in the south                    rn_smi_ini_s    = ', rn_smi_ini_s
-         WRITE(numout,*) '      initial  ice/snw temp  in the north                    rn_tmi_ini_n    = ', rn_tmi_ini_n
-         WRITE(numout,*) '      initial  ice/snw temp  in the south                    rn_tmi_ini_s    = ', rn_tmi_ini_s
+         WRITE(numout,*) '      ice initialization (T) or not (F)                ln_iceini      = ', ln_iceini
+         WRITE(numout,*) '      ice initialization from a netcdf file            ln_iceini_file = ', ln_iceini_file
+         WRITE(numout,*) '      max ocean temp. above Tfreeze with initial ice   rn_thres_sst   = ', rn_thres_sst
+         IF( ln_iceini .AND. .NOT.ln_iceini_file ) THEN
+            WRITE(numout,*) '      initial snw thickness in the north-south         rn_hts_ini     = ', rn_hts_ini_n,rn_hts_ini_s 
+            WRITE(numout,*) '      initial ice thickness in the north-south         rn_hti_ini     = ', rn_hti_ini_n,rn_hti_ini_s
+            WRITE(numout,*) '      initial ice concentr  in the north-south         rn_ati_ini     = ', rn_ati_ini_n,rn_ati_ini_s
+            WRITE(numout,*) '      initial ice salinity  in the north-south         rn_smi_ini     = ', rn_smi_ini_n,rn_smi_ini_s
+            WRITE(numout,*) '      initial surf temperat in the north-south         rn_tsu_ini     = ', rn_tsu_ini_n,rn_tsu_ini_s
+            WRITE(numout,*) '      initial ice temperat  in the north-south         rn_tmi_ini     = ', rn_tmi_ini_n,rn_tmi_ini_s
+            WRITE(numout,*) '      initial snw temperat  in the north-south         rn_tms_ini     = ', rn_tms_ini_n,rn_tms_ini_s
+            WRITE(numout,*) '      initial pnd fraction  in the north-south         rn_apd_ini     = ', rn_apd_ini_n,rn_apd_ini_s
+            WRITE(numout,*) '      initial pnd depth     in the north-south         rn_hpd_ini     = ', rn_hpd_ini_n,rn_hpd_ini_s
+         ENDIF
       ENDIF
       !
@@ -554,17 +513,21 @@
          ALLOCATE( si(jpfldi), STAT=ierror )
          IF( ierror > 0 ) THEN
-            CALL ctl_stop( 'Ice_ini in iceistate: unable to allocate si structure' )   ;   RETURN
+            CALL ctl_stop( 'ice_istate_ini in iceistate: unable to allocate si structure' )   ;   RETURN
          ENDIF
          !
          DO ifpr = 1, jpfldi
             ALLOCATE( si(ifpr)%fnow(jpi,jpj,1) )
-            ALLOCATE( si(ifpr)%fdta(jpi,jpj,1,2) )
+            IF( slf_i(ifpr)%ln_tint )  ALLOCATE( si(ifpr)%fdta(jpi,jpj,1,2) )
          END DO
          !
          ! fill si with slf_i and control print
-         CALL fld_fill( si, slf_i, cn_dir, 'ice_istate', 'ice istate ini', 'numnam_ice' )
-         !
-         CALL fld_read( nit000, 1, si )                ! input fields provided at the current time-step
-         !
+         CALL fld_fill( si, slf_i, cn_dir, 'ice_istate_ini', 'initialization of sea ice fields', 'numnam_ice' )
+         !
+      ENDIF
+      !
+      IF( .NOT.ln_pnd ) THEN
+         rn_apd_ini_n = 0. ; rn_apd_ini_s = 0.
+         rn_hpd_ini_n = 0. ; rn_hpd_ini_s = 0.
+         CALL ctl_warn( 'rn_apd_ini & rn_hpd_ini = 0 when no ponds' )
       ENDIF
       !
Index: /NEMO/trunk/src/ICE/iceitd.F90
===================================================================
--- /NEMO/trunk/src/ICE/iceitd.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/iceitd.F90	(revision 11536)
@@ -88,4 +88,5 @@
 
       IF( ln_icediachk )   CALL ice_cons_hsm(0, 'iceitd_rem', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft)
+      IF( ln_icediachk )   CALL ice_cons2D  (0, 'iceitd_rem',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft)
 
       !-----------------------------------------------------------------------------------------------
@@ -316,4 +317,5 @@
       !
       IF( ln_icediachk )   CALL ice_cons_hsm(1, 'iceitd_rem', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft)
+      IF( ln_icediachk )   CALL ice_cons2D  (1, 'iceitd_rem',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft)
       !
    END SUBROUTINE ice_itd_rem
@@ -586,4 +588,5 @@
       !
       IF( ln_icediachk )   CALL ice_cons_hsm(0, 'iceitd_reb', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft)
+      IF( ln_icediachk )   CALL ice_cons2D  (0, 'iceitd_reb',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft)
       !
       jdonor(:,:) = 0
@@ -664,4 +667,5 @@
       !
       IF( ln_icediachk )   CALL ice_cons_hsm(1, 'iceitd_reb', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft)
+      IF( ln_icediachk )   CALL ice_cons2D  (1, 'iceitd_reb',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft)
       !
    END SUBROUTINE ice_itd_reb
@@ -685,8 +689,8 @@
       REWIND( numnam_ice_ref )      ! Namelist namitd in reference namelist : Parameters for ice
       READ  ( numnam_ice_ref, namitd, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namitd in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namitd in reference namelist' )
       REWIND( numnam_ice_cfg )      ! Namelist namitd in configuration namelist : Parameters for ice
       READ  ( numnam_ice_cfg, namitd, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namitd in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namitd in configuration namelist' )
       IF(lwm) WRITE( numoni, namitd )
       !
Index: /NEMO/trunk/src/ICE/icerst.F90
===================================================================
--- /NEMO/trunk/src/ICE/icerst.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icerst.F90	(revision 11536)
@@ -14,8 +14,10 @@
    !!   ice_rst_read  : read  restart file 
    !!----------------------------------------------------------------------
-   USE ice            ! sea-ice variables
+   USE ice            ! sea-ice: variables
    USE dom_oce        ! ocean domain
+   USE phycst  , ONLY : rt0
    USE sbc_oce , ONLY : nn_fsbc, ln_cpl
-   USE icectl
+   USE iceistate      ! sea-ice: initial state
+   USE icectl         ! sea-ice: control
    !
    USE in_out_manager ! I/O manager
@@ -53,8 +55,9 @@
       IF( kt == nit000 )   lrst_ice = .FALSE.   ! default definition
 
+      IF( ln_rst_list .OR. nn_stock /= -1 ) THEN
       ! in order to get better performances with NetCDF format, we open and define the ice restart file 
       ! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice 
       ! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1
-      IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nstock == nn_fsbc    &
+      IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nn_stock == nn_fsbc    &
          &                             .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN
          IF( nitrst <= nitend .AND. nitrst > 0 ) THEN
@@ -81,4 +84,5 @@
          ENDIF
       ENDIF
+      ENDIF
       !
       IF( ln_icectl )   CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' )   ! control print
@@ -118,13 +122,14 @@
 
       ! Prognostic variables
-      CALL iom_rstput( iter, nitrst, numriw, 'v_i' , v_i  )
-      CALL iom_rstput( iter, nitrst, numriw, 'v_s' , v_s  )
-      CALL iom_rstput( iter, nitrst, numriw, 'sv_i', sv_i )
-      CALL iom_rstput( iter, nitrst, numriw, 'oa_i', oa_i )
-      CALL iom_rstput( iter, nitrst, numriw, 'a_i' , a_i  )
-      CALL iom_rstput( iter, nitrst, numriw, 't_su', t_su )
-      ! Melt ponds
-      CALL iom_rstput( iter, nitrst, numriw, 'a_ip', a_ip )
-      CALL iom_rstput( iter, nitrst, numriw, 'v_ip', v_ip )
+      CALL iom_rstput( iter, nitrst, numriw, 'v_i'  , v_i   )
+      CALL iom_rstput( iter, nitrst, numriw, 'v_s'  , v_s   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sv_i' , sv_i  )
+      CALL iom_rstput( iter, nitrst, numriw, 'a_i'  , a_i   )
+      CALL iom_rstput( iter, nitrst, numriw, 't_su' , t_su  )
+      CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice )
+      CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice )
+      CALL iom_rstput( iter, nitrst, numriw, 'oa_i' , oa_i  )
+      CALL iom_rstput( iter, nitrst, numriw, 'a_ip' , a_ip  )
+      CALL iom_rstput( iter, nitrst, numriw, 'v_ip' , v_ip  )
       ! Snow enthalpy
       DO jk = 1, nlay_s 
@@ -141,7 +146,4 @@
          CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
       END DO
-      ! ice velocity
-      CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice ) ! u_ice
-      CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice ) ! v_ice
       ! fields needed for Met Office (Jules) coupling
       IF( ln_cpl ) THEN
@@ -169,5 +171,5 @@
       INTEGER           ::   jk
       LOGICAL           ::   llok
-      INTEGER           ::   id1            ! local integer
+      INTEGER           ::   id0, id1, id2, id3, id4   ! local integer
       CHARACTER(len=25) ::   znam
       CHARACTER(len=2)  ::   zchar, zchar1
@@ -184,60 +186,95 @@
       CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kdlev = jpl )
 
-      CALL iom_get( numrir, 'nn_fsbc', zfice )
-      CALL iom_get( numrir, 'kt_ice' , ziter )    
-      IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
-      IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
-
-      ! Control of date
-      IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
-         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart',  &
-         &                   '   verify the file or rerun with the value 0 for the',        &
-         &                   '   control of time parameter  nrstdt' )
-      IF( NINT(zfice) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
-         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart',  &
-         &                   '   verify the file or rerun with the value 0 for the',         &
-         &                   '   control of time parameter  nrstdt' )
-
-      ! Prognostic variables 
-      CALL iom_get( numrir, jpdom_autoglo, 'v_i' , v_i  )
-      CALL iom_get( numrir, jpdom_autoglo, 'v_s' , v_s  )
-      CALL iom_get( numrir, jpdom_autoglo, 'sv_i', sv_i )
-      CALL iom_get( numrir, jpdom_autoglo, 'oa_i', oa_i )
-      CALL iom_get( numrir, jpdom_autoglo, 'a_i' , a_i  )
-      CALL iom_get( numrir, jpdom_autoglo, 't_su', t_su )
-      ! Melt ponds
-      id1 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. )
-      IF( id1 > 0 ) THEN                       ! fields exist (melt ponds)
-         CALL iom_get( numrir, jpdom_autoglo, 'a_ip' , a_ip )
-         CALL iom_get( numrir, jpdom_autoglo, 'v_ip' , v_ip )
-      ELSE                                     ! start from rest
-         IF(lwp) WRITE(numout,*) '   ==>>   previous run without melt ponds output then set it to zero'
-         a_ip(:,:,:) = 0._wp
-         v_ip(:,:,:) = 0._wp
-      ENDIF
-      ! Snow enthalpy
-      DO jk = 1, nlay_s
-         WRITE(zchar1,'(I2.2)') jk
-         znam = 'e_s'//'_l'//zchar1
-         CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
-         e_s(:,:,jk,:) = z3d(:,:,:)
-      END DO
-      ! Ice enthalpy
-      DO jk = 1, nlay_i
-         WRITE(zchar1,'(I2.2)') jk
-         znam = 'e_i'//'_l'//zchar1
-         CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
-         e_i(:,:,jk,:) = z3d(:,:,:)
-      END DO
-      ! ice velocity
-      CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice )
-      CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice )
-
-      CALL iom_delay_rst( 'READ', 'ICE', numrir )   ! read only ice delayed global communication variables
-
-      ! fields needed for Met Office (Jules) coupling
-      IF( ln_cpl ) THEN
-         CALL iom_get( numrir, jpdom_autoglo, 'cnd_ice', cnd_ice )
-         CALL iom_get( numrir, jpdom_autoglo, 't1_ice' , t1_ice  )
+      ! test if v_i exists 
+      id0 = iom_varid( numrir, 'v_i' , ldstop = .FALSE. )
+
+      !                    ! ------------------------------ !
+      IF( id0 > 0 ) THEN   ! == case of a normal restart == !
+         !                 ! ------------------------------ !
+         
+         ! Time info
+         CALL iom_get( numrir, 'nn_fsbc', zfice )
+         CALL iom_get( numrir, 'kt_ice' , ziter )    
+         IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
+         IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
+
+         ! Control of date
+         IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
+            &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart',  &
+            &                   '   verify the file or rerun with the value 0 for the',        &
+            &                   '   control of time parameter  nrstdt' )
+         IF( NINT(zfice) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
+            &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart',  &
+            &                   '   verify the file or rerun with the value 0 for the',         &
+            &                   '   control of time parameter  nrstdt' )
+
+         ! --- mandatory fields --- ! 
+         CALL iom_get( numrir, jpdom_autoglo, 'v_i'  , v_i   )
+         CALL iom_get( numrir, jpdom_autoglo, 'v_s'  , v_s   )
+         CALL iom_get( numrir, jpdom_autoglo, 'sv_i' , sv_i  )
+         CALL iom_get( numrir, jpdom_autoglo, 'a_i'  , a_i   )
+         CALL iom_get( numrir, jpdom_autoglo, 't_su' , t_su  )
+         CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice )
+         CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice )
+         ! Snow enthalpy
+         DO jk = 1, nlay_s
+            WRITE(zchar1,'(I2.2)') jk
+            znam = 'e_s'//'_l'//zchar1
+            CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
+            e_s(:,:,jk,:) = z3d(:,:,:)
+         END DO
+         ! Ice enthalpy
+         DO jk = 1, nlay_i
+            WRITE(zchar1,'(I2.2)') jk
+            znam = 'e_i'//'_l'//zchar1
+            CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
+            e_i(:,:,jk,:) = z3d(:,:,:)
+         END DO
+         ! -- optional fields -- !
+         ! ice age
+         id1 = iom_varid( numrir, 'oa_i' , ldstop = .FALSE. )
+         IF( id1 > 0 ) THEN                       ! fields exist
+            CALL iom_get( numrir, jpdom_autoglo, 'oa_i', oa_i )
+         ELSE                                     ! start from rest
+            IF(lwp) WRITE(numout,*) '   ==>>   previous run without ice age output then set it to zero'
+            oa_i(:,:,:) = 0._wp
+         ENDIF
+         ! melt ponds
+         id2 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. )
+         IF( id2 > 0 ) THEN                       ! fields exist
+            CALL iom_get( numrir, jpdom_autoglo, 'a_ip' , a_ip )
+            CALL iom_get( numrir, jpdom_autoglo, 'v_ip' , v_ip )
+         ELSE                                     ! start from rest
+            IF(lwp) WRITE(numout,*) '   ==>>   previous run without melt ponds output then set it to zero'
+            a_ip(:,:,:) = 0._wp
+            v_ip(:,:,:) = 0._wp
+         ENDIF
+         ! fields needed for Met Office (Jules) coupling
+         IF( ln_cpl ) THEN
+            id3 = iom_varid( numrir, 'cnd_ice' , ldstop = .FALSE. )
+            id4 = iom_varid( numrir, 't1_ice'  , ldstop = .FALSE. )
+            IF( id3 > 0 .AND. id4 > 0 ) THEN         ! fields exist
+               CALL iom_get( numrir, jpdom_autoglo, 'cnd_ice', cnd_ice )
+               CALL iom_get( numrir, jpdom_autoglo, 't1_ice' , t1_ice  )
+            ELSE                                     ! start from rest
+               IF(lwp) WRITE(numout,*) '   ==>>   previous run without conductivity output then set it to zero'
+               cnd_ice(:,:,:) = 0._wp
+               t1_ice (:,:,:) = rt0
+            ENDIF
+         ENDIF
+
+         CALL iom_delay_rst( 'READ', 'ICE', numrir )   ! read only ice delayed global communication variables
+
+         !                 ! ---------------------------------- !
+      ELSE                 ! == case of a simplified restart == !
+         !                 ! ---------------------------------- !
+         CALL ctl_warn('ice_rst_read: you are using a simplified ice restart')
+         !
+         CALL ice_istate_init
+         CALL ice_istate( nit000 )
+         !
+         IF( .NOT.ln_iceini .OR. .NOT.ln_iceini_file ) &
+            &   CALL ctl_stop('STOP', 'ice_rst_read: you need ln_ice_ini=T and ln_iceini_file=T')
+         !
       ENDIF
 
Index: /NEMO/trunk/src/ICE/icesbc.F90
===================================================================
--- /NEMO/trunk/src/ICE/icesbc.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icesbc.F90	(revision 11536)
@@ -114,7 +114,8 @@
       INTEGER, INTENT(in) ::   ksbc   ! flux formulation (user defined, bulk or Pure Coupled)
       !
-      INTEGER  ::   ji, jj, jl                                ! dummy loop index
-      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zalb_os, zalb_cs  ! ice albedo under overcast/clear sky
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zalb              ! 2D workspace
+      INTEGER  ::   ji, jj, jl      ! dummy loop index
+      REAL(wp) ::   zmiss_val       ! missing value retrieved from xios 
+      REAL(wp), DIMENSION(jpi,jpj,jpl)              ::   zalb_os, zalb_cs  ! ice albedo under overcast/clear sky
+      REAL(wp), DIMENSION(:,:)        , ALLOCATABLE ::   zalb, zmsk00      ! 2D workspace
       !!--------------------------------------------------------------------
       !
@@ -126,4 +127,7 @@
          WRITE(numout,*)'~~~~~~~~~~~~~~~'
       ENDIF
+
+      ! get missing value from xml
+      CALL iom_miss_val( "icetemp", zmiss_val )
 
       ! --- cloud-sky and overcast-sky ice albedos --- !
@@ -152,13 +156,23 @@
 
       !--- output ice albedo and surface albedo ---!
-      IF( iom_use('icealb') ) THEN
-         WHERE( at_i_b <= epsi06 )   ;   zalb(:,:) = rn_alb_oce
-         ELSEWHERE                   ;   zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) / at_i_b
+      IF( iom_use('icealb') .OR. iom_use('albedo') ) THEN
+
+         ALLOCATE( zalb(jpi,jpj), zmsk00(jpi,jpj) )
+
+         WHERE( at_i_b <= epsi06 )
+            zmsk00(:,:) = 0._wp
+            zalb  (:,:) = rn_alb_oce
+         ELSEWHERE
+            zmsk00(:,:) = 1._wp            
+            zalb  (:,:) = SUM( alb_ice * a_i_b, dim=3 ) / at_i_b
          END WHERE
-         CALL iom_put( "icealb" , zalb(:,:) )
-      ENDIF
-      IF( iom_use('albedo') ) THEN
+         ! ice albedo
+         CALL iom_put( 'icealb' , zalb * zmsk00 + zmiss_val * ( 1._wp - zmsk00 ) )
+         ! ice+ocean albedo
          zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) + rn_alb_oce * ( 1._wp - at_i_b )
-         CALL iom_put( "albedo" , zalb(:,:) )
+         CALL iom_put( 'albedo' , zalb )
+
+         DEALLOCATE( zalb, zmsk00 )
+
       ENDIF
       !
@@ -272,8 +286,8 @@
       REWIND( numnam_ice_ref )         ! Namelist namsbc in reference namelist : Ice dynamics
       READ  ( numnam_ice_ref, namsbc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc in reference namelist' )
       REWIND( numnam_ice_cfg )         ! Namelist namsbc in configuration namelist : Ice dynamics
       READ  ( numnam_ice_cfg, namsbc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc in configuration namelist' )
       IF(lwm) WRITE( numoni, namsbc )
       !
Index: /NEMO/trunk/src/ICE/icestp.F90
===================================================================
--- /NEMO/trunk/src/ICE/icestp.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icestp.F90	(revision 11536)
@@ -254,5 +254,5 @@
       IF( .NOT. ln_rstart ) THEN              ! start from rest: sea-ice deduced from sst
          CALL ice_istate_init
-         CALL ice_istate
+         CALL ice_istate( nit000 )
       ELSE                                    ! start from a restart file
          CALL ice_rst_read
@@ -303,8 +303,8 @@
       REWIND( numnam_ice_ref )      ! Namelist nampar in reference namelist : Parameters for ice
       READ  ( numnam_ice_ref, nampar, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampar in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampar in reference namelist' )
       REWIND( numnam_ice_cfg )      ! Namelist nampar in configuration namelist : Parameters for ice
       READ  ( numnam_ice_cfg, nampar, IOSTAT = ios, ERR = 902 )
-902   IF( ios > 0 )   CALL ctl_nam ( ios , 'nampar in configuration namelist', lwp )
+902   IF( ios > 0 )   CALL ctl_nam ( ios , 'nampar in configuration namelist' )
       IF(lwm) WRITE( numoni, nampar )
       !
@@ -425,6 +425,4 @@
       wfx_err_sub(:,:) = 0._wp
       !
-      afx_tot(:,:) = 0._wp   ;
-      !
       diag_heat(:,:) = 0._wp ;   diag_sice(:,:) = 0._wp
       diag_vice(:,:) = 0._wp ;   diag_vsnw(:,:) = 0._wp
Index: /NEMO/trunk/src/ICE/icethd.F90
===================================================================
--- /NEMO/trunk/src/ICE/icethd.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icethd.F90	(revision 11536)
@@ -95,4 +95,5 @@
       IF( ln_timing    )   CALL timing_start('icethd')                                                             ! timing
       IF( ln_icediachk )   CALL ice_cons_hsm(0, 'icethd', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+      IF( ln_icediachk )   CALL ice_cons2D  (0, 'icethd',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft) ! conservation
 
       IF( kt == nit000 .AND. lwp ) THEN
@@ -243,4 +244,5 @@
       !
       IF( ln_icediachk )   CALL ice_cons_hsm(1, 'icethd', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft)
+      IF( ln_icediachk )   CALL ice_cons2D  (1, 'icethd',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft)
       !                   
       IF( jpl > 1  )          CALL ice_itd_rem( kt )                ! --- Transport ice between thickness categories --- !
@@ -539,8 +541,8 @@
       REWIND( numnam_ice_ref )              ! Namelist namthd in reference namelist : Ice thermodynamics
       READ  ( numnam_ice_ref, namthd, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namthd in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namthd in reference namelist' )
       REWIND( numnam_ice_cfg )              ! Namelist namthd in configuration namelist : Ice thermodynamics
       READ  ( numnam_ice_cfg, namthd, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namthd in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namthd in configuration namelist' )
       IF(lwm) WRITE( numoni, namthd )
       !
Index: /NEMO/trunk/src/ICE/icethd_da.F90
===================================================================
--- /NEMO/trunk/src/ICE/icethd_da.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icethd_da.F90	(revision 11536)
@@ -179,8 +179,8 @@
       REWIND( numnam_ice_ref )              ! Namelist namthd_da in reference namelist : Ice thermodynamics
       READ  ( numnam_ice_ref, namthd_da, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namthd_da in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namthd_da in reference namelist' )
       REWIND( numnam_ice_cfg )              ! Namelist namthd_da in configuration namelist : Ice thermodynamics
       READ  ( numnam_ice_cfg, namthd_da, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namthd_da in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namthd_da in configuration namelist' )
       IF(lwm) WRITE( numoni, namthd_da )
       !
Index: /NEMO/trunk/src/ICE/icethd_do.F90
===================================================================
--- /NEMO/trunk/src/ICE/icethd_do.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icethd_do.F90	(revision 11536)
@@ -113,4 +113,5 @@
 
       IF( ln_icediachk )   CALL ice_cons_hsm( 0, 'icethd_do', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft )
+      IF( ln_icediachk )   CALL ice_cons2D  ( 0, 'icethd_do',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft )
 
       at_i(:,:) = SUM( a_i, dim=3 )
@@ -420,4 +421,5 @@
       !
       IF( ln_icediachk )   CALL ice_cons_hsm(1, 'icethd_do', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft)
+      IF( ln_icediachk )   CALL ice_cons2D  (1, 'icethd_do',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft)
       !
    END SUBROUTINE ice_thd_do
@@ -443,8 +445,8 @@
       REWIND( numnam_ice_ref )              ! Namelist namthd_do in reference namelist : Ice thermodynamics
       READ  ( numnam_ice_ref, namthd_do, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namthd_do in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namthd_do in reference namelist' )
       REWIND( numnam_ice_cfg )              ! Namelist namthd_do in configuration namelist : Ice thermodynamics
       READ  ( numnam_ice_cfg, namthd_do, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namthd_do in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namthd_do in configuration namelist' )
       IF(lwm) WRITE( numoni, namthd_do )
       !
Index: /NEMO/trunk/src/ICE/icethd_pnd.F90
===================================================================
--- /NEMO/trunk/src/ICE/icethd_pnd.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icethd_pnd.F90	(revision 11536)
@@ -205,13 +205,13 @@
       INTEGER  ::   ios, ioptio   ! Local integer
       !!
-      NAMELIST/namthd_pnd/  ln_pnd_H12, ln_pnd_CST, rn_apnd, rn_hpnd, ln_pnd_alb
+      NAMELIST/namthd_pnd/  ln_pnd, ln_pnd_H12, ln_pnd_CST, rn_apnd, rn_hpnd, ln_pnd_alb
       !!-------------------------------------------------------------------
       !
       REWIND( numnam_ice_ref )              ! Namelist namthd_pnd  in reference namelist : Melt Ponds  
       READ  ( numnam_ice_ref, namthd_pnd, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namthd_pnd  in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namthd_pnd  in reference namelist' )
       REWIND( numnam_ice_cfg )              ! Namelist namthd_pnd  in configuration namelist : Melt Ponds
       READ  ( numnam_ice_cfg, namthd_pnd, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namthd_pnd in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namthd_pnd in configuration namelist' )
       IF(lwm) WRITE ( numoni, namthd_pnd )
       !
@@ -221,17 +221,19 @@
          WRITE(numout,*) '~~~~~~~~~~~~~~~~'
          WRITE(numout,*) '   Namelist namicethd_pnd:'
-         WRITE(numout,*) '      Evolutive  melt pond fraction and depth (Holland et al 2012) ln_pnd_H12 = ', ln_pnd_H12
-         WRITE(numout,*) '      Prescribed melt pond fraction and depth                      ln_pnd_CST = ', ln_pnd_CST
-         WRITE(numout,*) '         Prescribed pond fraction                                  rn_apnd    = ', rn_apnd
-         WRITE(numout,*) '         Prescribed pond depth                                     rn_hpnd    = ', rn_hpnd
-         WRITE(numout,*) '      Melt ponds affect albedo or not                              ln_pnd_alb = ', ln_pnd_alb
+         WRITE(numout,*) '      Melt ponds activated or not                                     ln_pnd     = ', ln_pnd
+         WRITE(numout,*) '         Evolutive  melt pond fraction and depth (Holland et al 2012) ln_pnd_H12 = ', ln_pnd_H12
+         WRITE(numout,*) '         Prescribed melt pond fraction and depth                      ln_pnd_CST = ', ln_pnd_CST
+         WRITE(numout,*) '            Prescribed pond fraction                                  rn_apnd    = ', rn_apnd
+         WRITE(numout,*) '            Prescribed pond depth                                     rn_hpnd    = ', rn_hpnd
+         WRITE(numout,*) '         Melt ponds affect albedo or not                              ln_pnd_alb = ', ln_pnd_alb
       ENDIF
       !
       !                             !== set the choice of ice pond scheme ==!
       ioptio = 0
-                                                            nice_pnd = np_pndNO
-      IF( ln_pnd_CST ) THEN   ;   ioptio = ioptio + 1   ;   nice_pnd = np_pndCST    ;   ENDIF
-      IF( ln_pnd_H12 ) THEN   ;   ioptio = ioptio + 1   ;   nice_pnd = np_pndH12    ;   ENDIF
-      IF( ioptio > 1 )   CALL ctl_stop( 'ice_thd_pnd_init: choose one and only one pond scheme (ln_pnd_H12 or ln_pnd_CST)' )
+      IF( .NOT.ln_pnd ) THEN   ;   ioptio = ioptio + 1   ;   nice_pnd = np_pndNO     ;   ENDIF
+      IF( ln_pnd_CST  ) THEN   ;   ioptio = ioptio + 1   ;   nice_pnd = np_pndCST    ;   ENDIF
+      IF( ln_pnd_H12  ) THEN   ;   ioptio = ioptio + 1   ;   nice_pnd = np_pndH12    ;   ENDIF
+      IF( ioptio /= 1 )   &
+         & CALL ctl_stop( 'ice_thd_pnd_init: choose either none (ln_pnd=F) or only one pond scheme (ln_pnd_H12 or ln_pnd_CST)' )
       !
       SELECT CASE( nice_pnd )
Index: /NEMO/trunk/src/ICE/icethd_sal.F90
===================================================================
--- /NEMO/trunk/src/ICE/icethd_sal.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icethd_sal.F90	(revision 11536)
@@ -134,8 +134,8 @@
       REWIND( numnam_ice_ref )              ! Namelist namthd_sal in reference namelist : Ice salinity
       READ  ( numnam_ice_ref, namthd_sal, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namthd_sal in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namthd_sal in reference namelist' )
       REWIND( numnam_ice_cfg )              ! Namelist namthd_sal in configuration namelist : Ice salinity
       READ  ( numnam_ice_cfg, namthd_sal, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namthd_sal in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namthd_sal in configuration namelist' )
       IF(lwm) WRITE ( numoni, namthd_sal )
       !
Index: /NEMO/trunk/src/ICE/icethd_zdf.F90
===================================================================
--- /NEMO/trunk/src/ICE/icethd_zdf.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icethd_zdf.F90	(revision 11536)
@@ -90,8 +90,8 @@
       REWIND( numnam_ice_ref )              ! Namelist namthd_zdf in reference namelist : Ice thermodynamics
       READ  ( numnam_ice_ref, namthd_zdf, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namthd_zdf in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namthd_zdf in reference namelist' )
       REWIND( numnam_ice_cfg )              ! Namelist namthd_zdf in configuration namelist : Ice thermodynamics
       READ  ( numnam_ice_cfg, namthd_zdf, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namthd_zdf in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namthd_zdf in configuration namelist' )
       IF(lwm) WRITE( numoni, namthd_zdf )
       !
Index: /NEMO/trunk/src/ICE/iceupdate.F90
===================================================================
--- /NEMO/trunk/src/ICE/iceupdate.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/iceupdate.F90	(revision 11536)
@@ -198,89 +198,86 @@
       ! --- salt fluxes [kg/m2/s] --- !
       !                           ! sfxice =  sfxbog + sfxbom + sfxsum + sfxsni + sfxopw + sfxres + sfxdyn + sfxbri + sfxsub + sfxlam
-      IF( iom_use('sfxice'  ) )   CALL iom_put( "sfxice", sfx     * 1.e-03 )   ! salt flux from total ice growth/melt
-      IF( iom_use('sfxbog'  ) )   CALL iom_put( "sfxbog", sfx_bog * 1.e-03 )   ! salt flux from bottom growth
-      IF( iom_use('sfxbom'  ) )   CALL iom_put( "sfxbom", sfx_bom * 1.e-03 )   ! salt flux from bottom melting
-      IF( iom_use('sfxsum'  ) )   CALL iom_put( "sfxsum", sfx_sum * 1.e-03 )   ! salt flux from surface melting
-      IF( iom_use('sfxlam'  ) )   CALL iom_put( "sfxlam", sfx_lam * 1.e-03 )   ! salt flux from lateral melting
-      IF( iom_use('sfxsni'  ) )   CALL iom_put( "sfxsni", sfx_sni * 1.e-03 )   ! salt flux from snow ice formation
-      IF( iom_use('sfxopw'  ) )   CALL iom_put( "sfxopw", sfx_opw * 1.e-03 )   ! salt flux from open water formation
-      IF( iom_use('sfxdyn'  ) )   CALL iom_put( "sfxdyn", sfx_dyn * 1.e-03 )   ! salt flux from ridging rafting
-      IF( iom_use('sfxbri'  ) )   CALL iom_put( "sfxbri", sfx_bri * 1.e-03 )   ! salt flux from brines
-      IF( iom_use('sfxres'  ) )   CALL iom_put( "sfxres", sfx_res * 1.e-03 )   ! salt flux from undiagnosed processes
-      IF( iom_use('sfxsub'  ) )   CALL iom_put( "sfxsub", sfx_sub * 1.e-03 )   ! salt flux from sublimation
+      IF( iom_use('sfxice'  ) )   CALL iom_put( 'sfxice', sfx     * 1.e-03 )   ! salt flux from total ice growth/melt
+      IF( iom_use('sfxbog'  ) )   CALL iom_put( 'sfxbog', sfx_bog * 1.e-03 )   ! salt flux from bottom growth
+      IF( iom_use('sfxbom'  ) )   CALL iom_put( 'sfxbom', sfx_bom * 1.e-03 )   ! salt flux from bottom melting
+      IF( iom_use('sfxsum'  ) )   CALL iom_put( 'sfxsum', sfx_sum * 1.e-03 )   ! salt flux from surface melting
+      IF( iom_use('sfxlam'  ) )   CALL iom_put( 'sfxlam', sfx_lam * 1.e-03 )   ! salt flux from lateral melting
+      IF( iom_use('sfxsni'  ) )   CALL iom_put( 'sfxsni', sfx_sni * 1.e-03 )   ! salt flux from snow ice formation
+      IF( iom_use('sfxopw'  ) )   CALL iom_put( 'sfxopw', sfx_opw * 1.e-03 )   ! salt flux from open water formation
+      IF( iom_use('sfxdyn'  ) )   CALL iom_put( 'sfxdyn', sfx_dyn * 1.e-03 )   ! salt flux from ridging rafting
+      IF( iom_use('sfxbri'  ) )   CALL iom_put( 'sfxbri', sfx_bri * 1.e-03 )   ! salt flux from brines
+      IF( iom_use('sfxres'  ) )   CALL iom_put( 'sfxres', sfx_res * 1.e-03 )   ! salt flux from undiagnosed processes
+      IF( iom_use('sfxsub'  ) )   CALL iom_put( 'sfxsub', sfx_sub * 1.e-03 )   ! salt flux from sublimation
 
       ! --- mass fluxes [kg/m2/s] --- !
-      IF( iom_use('emp_oce' ) )   CALL iom_put( "emp_oce", emp_oce )   ! emp over ocean (taking into account the snow blown away from the ice)
-      IF( iom_use('emp_ice' ) )   CALL iom_put( "emp_ice", emp_ice )   ! emp over ice   (taking into account the snow blown away from the ice)
+      CALL iom_put( 'emp_oce', emp_oce )   ! emp over ocean (taking into account the snow blown away from the ice)
+      CALL iom_put( 'emp_ice', emp_ice )   ! emp over ice   (taking into account the snow blown away from the ice)
 
       !                           ! vfxice = vfxbog + vfxbom + vfxsum + vfxsni + vfxopw + vfxdyn + vfxres + vfxlam + vfxpnd
-      IF( iom_use('vfxice'  ) )   CALL iom_put( "vfxice" , wfx_ice )   ! mass flux from total ice growth/melt
-      IF( iom_use('vfxbog'  ) )   CALL iom_put( "vfxbog" , wfx_bog )   ! mass flux from bottom growth
-      IF( iom_use('vfxbom'  ) )   CALL iom_put( "vfxbom" , wfx_bom )   ! mass flux from bottom melt 
-      IF( iom_use('vfxsum'  ) )   CALL iom_put( "vfxsum" , wfx_sum )   ! mass flux from surface melt 
-      IF( iom_use('vfxlam'  ) )   CALL iom_put( "vfxlam" , wfx_lam )   ! mass flux from lateral melt 
-      IF( iom_use('vfxsni'  ) )   CALL iom_put( "vfxsni" , wfx_sni )   ! mass flux from snow-ice formation
-      IF( iom_use('vfxopw'  ) )   CALL iom_put( "vfxopw" , wfx_opw )   ! mass flux from growth in open water
-      IF( iom_use('vfxdyn'  ) )   CALL iom_put( "vfxdyn" , wfx_dyn )   ! mass flux from dynamics (ridging)
-      IF( iom_use('vfxres'  ) )   CALL iom_put( "vfxres" , wfx_res )   ! mass flux from undiagnosed processes 
-      IF( iom_use('vfxpnd'  ) )   CALL iom_put( "vfxpnd" , wfx_pnd )   ! mass flux from melt ponds
-      IF( iom_use('vfxsub'  ) )   CALL iom_put( "vfxsub" , wfx_ice_sub )   ! mass flux from ice sublimation (ice-atm.)
-      IF( iom_use('vfxsub_err') ) CALL iom_put( "vfxsub_err", wfx_err_sub )   ! "excess" of sublimation sent to ocean      
-
-      IF ( iom_use( "vfxthin" ) ) THEN   ! mass flux from ice growth in open water + thin ice (<20cm) => comparable to observations  
+      CALL iom_put( 'vfxice'    , wfx_ice     )   ! mass flux from total ice growth/melt
+      CALL iom_put( 'vfxbog'    , wfx_bog     )   ! mass flux from bottom growth
+      CALL iom_put( 'vfxbom'    , wfx_bom     )   ! mass flux from bottom melt 
+      CALL iom_put( 'vfxsum'    , wfx_sum     )   ! mass flux from surface melt 
+      CALL iom_put( 'vfxlam'    , wfx_lam     )   ! mass flux from lateral melt 
+      CALL iom_put( 'vfxsni'    , wfx_sni     )   ! mass flux from snow-ice formation
+      CALL iom_put( 'vfxopw'    , wfx_opw     )   ! mass flux from growth in open water
+      CALL iom_put( 'vfxdyn'    , wfx_dyn     )   ! mass flux from dynamics (ridging)
+      CALL iom_put( 'vfxres'    , wfx_res     )   ! mass flux from undiagnosed processes 
+      CALL iom_put( 'vfxpnd'    , wfx_pnd     )   ! mass flux from melt ponds
+      CALL iom_put( 'vfxsub'    , wfx_ice_sub )   ! mass flux from ice sublimation (ice-atm.)
+      CALL iom_put( 'vfxsub_err', wfx_err_sub )   ! "excess" of sublimation sent to ocean      
+
+      IF ( iom_use( 'vfxthin' ) ) THEN   ! mass flux from ice growth in open water + thin ice (<20cm) => comparable to observations  
          WHERE( hm_i(:,:) < 0.2 .AND. hm_i(:,:) > 0. ) ; z2d = wfx_bog
          ELSEWHERE                                     ; z2d = 0._wp
          END WHERE
-         CALL iom_put( "vfxthin", wfx_opw + z2d )
-      ENDIF
-
-      !                              ! vfxsnw = vfxsnw_sni + vfxsnw_dyn + vfxsnw_sum
-      IF( iom_use('vfxsnw'     ) )   CALL iom_put( "vfxsnw"     , wfx_snw     )   ! mass flux from total snow growth/melt
-      IF( iom_use('vfxsnw_sum' ) )   CALL iom_put( "vfxsnw_sum" , wfx_snw_sum )   ! mass flux from snow melt at the surface
-      IF( iom_use('vfxsnw_sni' ) )   CALL iom_put( "vfxsnw_sni" , wfx_snw_sni )   ! mass flux from snow melt during snow-ice formation 
-      IF( iom_use('vfxsnw_dyn' ) )   CALL iom_put( "vfxsnw_dyn" , wfx_snw_dyn )   ! mass flux from dynamics (ridging) 
-      IF( iom_use('vfxsnw_sub' ) )   CALL iom_put( "vfxsnw_sub" , wfx_snw_sub )   ! mass flux from snow sublimation (ice-atm.) 
-      IF( iom_use('vfxsnw_pre' ) )   CALL iom_put( "vfxsnw_pre" , wfx_spr     )   ! snow precip
+         CALL iom_put( 'vfxthin', wfx_opw + z2d )
+      ENDIF
+
+      !                            ! vfxsnw = vfxsnw_sni + vfxsnw_dyn + vfxsnw_sum
+      CALL iom_put( 'vfxsnw'     , wfx_snw     )   ! mass flux from total snow growth/melt
+      CALL iom_put( 'vfxsnw_sum' , wfx_snw_sum )   ! mass flux from snow melt at the surface
+      CALL iom_put( 'vfxsnw_sni' , wfx_snw_sni )   ! mass flux from snow melt during snow-ice formation 
+      CALL iom_put( 'vfxsnw_dyn' , wfx_snw_dyn )   ! mass flux from dynamics (ridging) 
+      CALL iom_put( 'vfxsnw_sub' , wfx_snw_sub )   ! mass flux from snow sublimation (ice-atm.) 
+      CALL iom_put( 'vfxsnw_pre' , wfx_spr     )   ! snow precip
 
       ! --- heat fluxes [W/m2] --- !
       !                              ! qt_atm_oi - qt_oce_ai = hfxdhc - ( dihctrp + dshctrp )
-      IF( iom_use('qsr_oce'    ) )   CALL iom_put( "qsr_oce"    , qsr_oce * ( 1._wp - at_i_b )                               )   !     solar flux at ocean surface
-      IF( iom_use('qns_oce'    ) )   CALL iom_put( "qns_oce"    , qns_oce * ( 1._wp - at_i_b ) + qemp_oce                    )   ! non-solar flux at ocean surface
-      IF( iom_use('qsr_ice'    ) )   CALL iom_put( "qsr_ice"    , SUM( qsr_ice * a_i_b, dim=3 )                              )   !     solar flux at ice surface
-      IF( iom_use('qns_ice'    ) )   CALL iom_put( "qns_ice"    , SUM( qns_ice * a_i_b, dim=3 ) + qemp_ice                   )   ! non-solar flux at ice surface
-      IF( iom_use('qtr_ice_bot') )   CALL iom_put( "qtr_ice_bot", SUM( qtr_ice_bot * a_i_b, dim=3 )                          )   !     solar flux transmitted thru ice
-      IF( iom_use('qtr_ice_top') )   CALL iom_put( "qtr_ice_top", SUM( qtr_ice_top * a_i_b, dim=3 )                          )   !     solar flux transmitted thru ice surface
-      IF( iom_use('qt_oce'     ) )   CALL iom_put( "qt_oce"     ,      ( qsr_oce + qns_oce ) * ( 1._wp - at_i_b ) + qemp_oce )
-      IF( iom_use('qt_ice'     ) )   CALL iom_put( "qt_ice"     , SUM( ( qns_ice + qsr_ice ) * a_i_b, dim=3 )     + qemp_ice )
-      IF( iom_use('qt_oce_ai'  ) )   CALL iom_put( "qt_oce_ai"  , qt_oce_ai * tmask(:,:,1)                                   )   ! total heat flux at the ocean   surface: interface oce-(ice+atm) 
-      IF( iom_use('qt_atm_oi'  ) )   CALL iom_put( "qt_atm_oi"  , qt_atm_oi * tmask(:,:,1)                                   )   ! total heat flux at the oce-ice surface: interface atm-(ice+oce) 
-      IF( iom_use('qemp_oce'   ) )   CALL iom_put( "qemp_oce"   , qemp_oce                                                   )   ! Downward Heat Flux from E-P over ocean
-      IF( iom_use('qemp_ice'   ) )   CALL iom_put( "qemp_ice"   , qemp_ice                                                   )   ! Downward Heat Flux from E-P over ice
+      IF( iom_use('qsr_oce'    ) )   CALL iom_put( 'qsr_oce'    , qsr_oce * ( 1._wp - at_i_b )                               )   !     solar flux at ocean surface
+      IF( iom_use('qns_oce'    ) )   CALL iom_put( 'qns_oce'    , qns_oce * ( 1._wp - at_i_b ) + qemp_oce                    )   ! non-solar flux at ocean surface
+      IF( iom_use('qsr_ice'    ) )   CALL iom_put( 'qsr_ice'    , SUM( qsr_ice * a_i_b, dim=3 )                              )   !     solar flux at ice surface
+      IF( iom_use('qns_ice'    ) )   CALL iom_put( 'qns_ice'    , SUM( qns_ice * a_i_b, dim=3 ) + qemp_ice                   )   ! non-solar flux at ice surface
+      IF( iom_use('qtr_ice_bot') )   CALL iom_put( 'qtr_ice_bot', SUM( qtr_ice_bot * a_i_b, dim=3 )                          )   !     solar flux transmitted thru ice
+      IF( iom_use('qtr_ice_top') )   CALL iom_put( 'qtr_ice_top', SUM( qtr_ice_top * a_i_b, dim=3 )                          )   !     solar flux transmitted thru ice surface
+      IF( iom_use('qt_oce'     ) )   CALL iom_put( 'qt_oce'     ,      ( qsr_oce + qns_oce ) * ( 1._wp - at_i_b ) + qemp_oce )
+      IF( iom_use('qt_ice'     ) )   CALL iom_put( 'qt_ice'     , SUM( ( qns_ice + qsr_ice ) * a_i_b, dim=3 )     + qemp_ice )
+      IF( iom_use('qt_oce_ai'  ) )   CALL iom_put( 'qt_oce_ai'  , qt_oce_ai * tmask(:,:,1)                                   )   ! total heat flux at the ocean   surface: interface oce-(ice+atm) 
+      IF( iom_use('qt_atm_oi'  ) )   CALL iom_put( 'qt_atm_oi'  , qt_atm_oi * tmask(:,:,1)                                   )   ! total heat flux at the oce-ice surface: interface atm-(ice+oce) 
+      IF( iom_use('qemp_oce'   ) )   CALL iom_put( 'qemp_oce'   , qemp_oce                                                   )   ! Downward Heat Flux from E-P over ocean
+      IF( iom_use('qemp_ice'   ) )   CALL iom_put( 'qemp_ice'   , qemp_ice                                                   )   ! Downward Heat Flux from E-P over ice
 
       ! heat fluxes from ice transformations
-      !                              ! hfxdhc = hfxbog + hfxbom + hfxsum + hfxopw + hfxdif + hfxsnw - ( hfxthd + hfxdyn + hfxres + hfxsub + hfxspr )
-      IF( iom_use('hfxbog'     ) )   CALL iom_put ("hfxbog"     , hfx_bog             )   ! heat flux used for ice bottom growth 
-      IF( iom_use('hfxbom'     ) )   CALL iom_put ("hfxbom"     , hfx_bom             )   ! heat flux used for ice bottom melt
-      IF( iom_use('hfxsum'     ) )   CALL iom_put ("hfxsum"     , hfx_sum             )   ! heat flux used for ice surface melt
-      IF( iom_use('hfxopw'     ) )   CALL iom_put ("hfxopw"     , hfx_opw             )   ! heat flux used for ice formation in open water
-      IF( iom_use('hfxdif'     ) )   CALL iom_put ("hfxdif"     , hfx_dif             )   ! heat flux used for ice temperature change
-      IF( iom_use('hfxsnw'     ) )   CALL iom_put ("hfxsnw"     , hfx_snw             )   ! heat flux used for snow melt 
-      IF( iom_use('hfxerr'     ) )   CALL iom_put ("hfxerr"     , hfx_err_dif         )   ! heat flux error after heat diffusion (included in qt_oce_ai)
+      !                            ! hfxdhc = hfxbog + hfxbom + hfxsum + hfxopw + hfxdif + hfxsnw - ( hfxthd + hfxdyn + hfxres + hfxsub + hfxspr )
+      CALL iom_put ('hfxbog'     , hfx_bog     )   ! heat flux used for ice bottom growth 
+      CALL iom_put ('hfxbom'     , hfx_bom     )   ! heat flux used for ice bottom melt
+      CALL iom_put ('hfxsum'     , hfx_sum     )   ! heat flux used for ice surface melt
+      CALL iom_put ('hfxopw'     , hfx_opw     )   ! heat flux used for ice formation in open water
+      CALL iom_put ('hfxdif'     , hfx_dif     )   ! heat flux used for ice temperature change
+      CALL iom_put ('hfxsnw'     , hfx_snw     )   ! heat flux used for snow melt 
+      CALL iom_put ('hfxerr'     , hfx_err_dif )   ! heat flux error after heat diffusion (included in qt_oce_ai)
 
       ! heat fluxes associated with mass exchange (freeze/melt/precip...)
-      IF( iom_use('hfxthd'     ) )   CALL iom_put ("hfxthd"     , hfx_thd             )   !  
-      IF( iom_use('hfxdyn'     ) )   CALL iom_put ("hfxdyn"     , hfx_dyn             )   !  
-      IF( iom_use('hfxres'     ) )   CALL iom_put ("hfxres"     , hfx_res             )   !  
-      IF( iom_use('hfxsub'     ) )   CALL iom_put ("hfxsub"     , hfx_sub             )   !  
-      IF( iom_use('hfxspr'     ) )   CALL iom_put ("hfxspr"     , hfx_spr             )   ! Heat flux from snow precip heat content 
+      CALL iom_put ('hfxthd'     , hfx_thd     )   !  
+      CALL iom_put ('hfxdyn'     , hfx_dyn     )   !  
+      CALL iom_put ('hfxres'     , hfx_res     )   !  
+      CALL iom_put ('hfxsub'     , hfx_sub     )   !  
+      CALL iom_put ('hfxspr'     , hfx_spr     )   ! Heat flux from snow precip heat content 
 
       ! other heat fluxes
-      IF( iom_use('hfxsensib'  ) )   CALL iom_put( "hfxsensib"  ,     -qsb_ice_bot * at_i_b         )   ! Sensible oceanic heat flux
-      IF( iom_use('hfxcndbot'  ) )   CALL iom_put( "hfxcndbot"  , SUM( qcn_ice_bot * a_i_b, dim=3 ) )   ! Bottom conduction flux
-      IF( iom_use('hfxcndtop'  ) )   CALL iom_put( "hfxcndtop"  , SUM( qcn_ice_top * a_i_b, dim=3 ) )   ! Surface conduction flux
-
-      ! diags
-      IF( iom_use('hfxdhc'     ) )   CALL iom_put ("hfxdhc"     , diag_heat           )   ! Heat content variation in snow and ice 
-      !
+      IF( iom_use('hfxsensib'  ) )   CALL iom_put( 'hfxsensib'  ,     -qsb_ice_bot * at_i_b         )   ! Sensible oceanic heat flux
+      IF( iom_use('hfxcndbot'  ) )   CALL iom_put( 'hfxcndbot'  , SUM( qcn_ice_bot * a_i_b, dim=3 ) )   ! Bottom conduction flux
+      IF( iom_use('hfxcndtop'  ) )   CALL iom_put( 'hfxcndtop'  , SUM( qcn_ice_top * a_i_b, dim=3 ) )   ! Surface conduction flux
+
       ! controls
       !---------
@@ -413,5 +410,5 @@
       !! ** Method  :   use of IOM library
       !!----------------------------------------------------------------------
-      CHARACTER(len=*) , INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
+      CHARACTER(len=*) , INTENT(in) ::   cdrw   ! 'READ'/'WRITE' flag
       INTEGER, OPTIONAL, INTENT(in) ::   kt     ! ice time-step
       !
Index: /NEMO/trunk/src/ICE/icevar.F90
===================================================================
--- /NEMO/trunk/src/ICE/icevar.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icevar.F90	(revision 11536)
@@ -32,4 +32,5 @@
    !!                        - vt_s(jpi,jpj)
    !!                        - at_i(jpi,jpj)
+   !!                        - st_i(jpi,jpj)
    !!                        - et_s(jpi,jpj)  total snow heat content
    !!                        - et_i(jpi,jpj)  total ice thermal content 
@@ -46,9 +47,8 @@
    !!   ice_var_zapneg    : remove negative ice fields
    !!   ice_var_roundoff  : remove negative values arising from roundoff erros
-   !!   ice_var_itd       : convert 1-cat to jpl-cat
-   !!   ice_var_itd2      : convert N-cat to jpl-cat
    !!   ice_var_bv        : brine volume
    !!   ice_var_enthalpy  : compute ice and snow enthalpies from temperature
    !!   ice_var_sshdyn    : compute equivalent ssh in lead
+   !!   ice_var_itd       : convert N-cat to M-cat
    !!----------------------------------------------------------------------
    USE dom_oce        ! ocean space and time domain
@@ -104,9 +104,10 @@
       !
       !                                      ! integrated values
-      vt_i(:,:) =       SUM( v_i(:,:,:)           , dim=3 )
-      vt_s(:,:) =       SUM( v_s(:,:,:)           , dim=3 )
-      at_i(:,:) =       SUM( a_i(:,:,:)           , dim=3 )
-      et_s(:,:)  = SUM( SUM( e_s(:,:,:,:), dim=4 ), dim=3 )
-      et_i(:,:)  = SUM( SUM( e_i(:,:,:,:), dim=4 ), dim=3 )
+      vt_i(:,:) =       SUM( v_i (:,:,:)           , dim=3 )
+      vt_s(:,:) =       SUM( v_s (:,:,:)           , dim=3 )
+      st_i(:,:) =       SUM( sv_i(:,:,:)           , dim=3 )
+      at_i(:,:) =       SUM( a_i (:,:,:)           , dim=3 )
+      et_s(:,:)  = SUM( SUM( e_s (:,:,:,:), dim=4 ), dim=3 )
+      et_i(:,:)  = SUM( SUM( e_i (:,:,:,:), dim=4 ), dim=3 )
       !
       at_ip(:,:) = SUM( a_ip(:,:,:), dim=3 ) ! melt ponds
@@ -138,5 +139,5 @@
          tm_si(:,:) = SUM( t_si(:,:,:) * a_i(:,:,:) , dim=3 ) * z1_at_i(:,:)
          om_i (:,:) = SUM( oa_i(:,:,:)              , dim=3 ) * z1_at_i(:,:)
-         sm_i (:,:) = SUM( sv_i(:,:,:)              , dim=3 ) * z1_vt_i(:,:)
+         sm_i (:,:) =      st_i(:,:)                          * z1_vt_i(:,:)
          !
          tm_i(:,:) = 0._wp
@@ -158,6 +159,12 @@
             tm_s (:,:) = rt0
          END WHERE
-
+         !
+         !                           ! mean melt pond depth
+         WHERE( at_ip(:,:) > epsi20 )   ;   hm_ip(:,:) = vt_ip(:,:) / at_ip(:,:)
+         ELSEWHERE                      ;   hm_ip(:,:) = 0._wp
+         END WHERE         
+         !
          DEALLOCATE( z1_at_i , z1_vt_i , z1_vt_s )
+         !
       ENDIF
       !
@@ -263,7 +270,7 @@
       !
       ! integrated values 
-      vt_i (:,:) = SUM( v_i, dim=3 )
-      vt_s (:,:) = SUM( v_s, dim=3 )
-      at_i (:,:) = SUM( a_i, dim=3 )
+      vt_i (:,:) = SUM( v_i , dim=3 )
+      vt_s (:,:) = SUM( v_s , dim=3 )
+      at_i (:,:) = SUM( a_i , dim=3 )
       !
    END SUBROUTINE ice_var_glo2eqv
@@ -533,6 +540,12 @@
 
       ! to be sure that at_i is the sum of a_i(jl)
-      at_i (:,:) = SUM( a_i(:,:,:), dim=3 )
-      vt_i (:,:) = SUM( v_i(:,:,:), dim=3 )
+      at_i (:,:) = SUM( a_i (:,:,:), dim=3 )
+      vt_i (:,:) = SUM( v_i (:,:,:), dim=3 )
+!!clem add?
+!      vt_s (:,:) = SUM( v_s (:,:,:), dim=3 )
+!      st_i (:,:) = SUM( sv_i(:,:,:), dim=3 )
+!      et_s(:,:)  = SUM( SUM( e_s (:,:,:,:), dim=4 ), dim=3 )
+!      et_i(:,:)  = SUM( SUM( e_i (:,:,:,:), dim=4 ), dim=3 )
+!!clem
 
       ! open water = 1 if at_i=0
@@ -652,5 +665,5 @@
       WHERE( pe_i (1:npti,:,:) < 0._wp .AND. pe_i (1:npti,:,:) > -epsi06 )   pe_i (1:npti,:,:) = 0._wp   !  e_i must be >= 0
       WHERE( pe_s (1:npti,:,:) < 0._wp .AND. pe_s (1:npti,:,:) > -epsi06 )   pe_s (1:npti,:,:) = 0._wp   !  e_s must be >= 0
-      IF ( ln_pnd_H12 ) THEN
+      IF( ln_pnd_H12 ) THEN
          WHERE( pa_ip(1:npti,:) < 0._wp .AND. pa_ip(1:npti,:) > -epsi10 )    pa_ip(1:npti,:)   = 0._wp   ! a_ip must be >= 0
          WHERE( pv_ip(1:npti,:) < 0._wp .AND. pv_ip(1:npti,:) > -epsi10 )    pv_ip(1:npti,:)   = 0._wp   ! v_ip must be >= 0
@@ -773,37 +786,82 @@
    !! ** Purpose :  converting N-cat ice to jpl ice categories
    !!-------------------------------------------------------------------
-   SUBROUTINE ice_var_itd_1c1c( zhti, zhts, zati, zh_i, zh_s, za_i )
+   SUBROUTINE ice_var_itd_1c1c( phti, phts, pati ,                       ph_i, ph_s, pa_i, &
+      &                         ptmi, ptms, ptmsu, psmi, patip, phtip,   pt_i, pt_s, pt_su, ps_i, pa_ip, ph_ip )
       !!-------------------------------------------------------------------
       !! ** Purpose :  converting 1-cat ice to 1 ice category
       !!-------------------------------------------------------------------
-      REAL(wp), DIMENSION(:), INTENT(in)    ::   zhti, zhts, zati    ! input ice/snow variables
-      REAL(wp), DIMENSION(:), INTENT(inout) ::   zh_i, zh_s, za_i    ! output ice/snow variables
-      !!-------------------------------------------------------------------
-      zh_i(:) = zhti(:)
-      zh_s(:) = zhts(:)
-      za_i(:) = zati(:)
+      REAL(wp), DIMENSION(:), INTENT(in)    ::   phti, phts, pati    ! input  ice/snow variables
+      REAL(wp), DIMENSION(:), INTENT(inout) ::   ph_i, ph_s, pa_i    ! output ice/snow variables
+      REAL(wp), DIMENSION(:), INTENT(in)    ::   ptmi, ptms, ptmsu, psmi, patip, phtip    ! input  ice/snow temp & sal & ponds
+      REAL(wp), DIMENSION(:), INTENT(inout) ::   pt_i, pt_s, pt_su, ps_i, pa_ip, ph_ip    ! output ice/snow temp & sal & ponds
+      !!-------------------------------------------------------------------
+      ! == thickness and concentration == !
+      ph_i(:) = phti(:)
+      ph_s(:) = phts(:)
+      pa_i(:) = pati(:)
+      !
+      ! == temperature and salinity and ponds == !
+      pt_i (:) = ptmi (:)
+      pt_s (:) = ptms (:)
+      pt_su(:) = ptmsu(:)
+      ps_i (:) = psmi (:)
+      pa_ip(:) = patip(:)
+      ph_ip(:) = phtip(:)
+      
    END SUBROUTINE ice_var_itd_1c1c
 
-   SUBROUTINE ice_var_itd_Nc1c( zhti, zhts, zati, zh_i, zh_s, za_i )
+   SUBROUTINE ice_var_itd_Nc1c( phti, phts, pati ,                       ph_i, ph_s, pa_i, &
+      &                         ptmi, ptms, ptmsu, psmi, patip, phtip,   pt_i, pt_s, pt_su, ps_i, pa_ip, ph_ip )
       !!-------------------------------------------------------------------
       !! ** Purpose :  converting N-cat ice to 1 ice category
       !!-------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:), INTENT(in)    ::   zhti, zhts, zati    ! input ice/snow variables
-      REAL(wp), DIMENSION(:)  , INTENT(inout) ::   zh_i, zh_s, za_i    ! output ice/snow variables
-      !!-------------------------------------------------------------------
-      !
-      za_i(:) = SUM( zati(:,:), dim=2 )
-      !
-      WHERE( za_i(:) /= 0._wp )
-         zh_i(:) = SUM( zhti(:,:) * zati(:,:), dim=2 ) / za_i(:)
-         zh_s(:) = SUM( zhts(:,:) * zati(:,:), dim=2 ) / za_i(:)
-      ELSEWHERE
-         zh_i(:) = 0._wp
-         zh_s(:) = 0._wp
+      REAL(wp), DIMENSION(:,:), INTENT(in)    ::   phti, phts, pati    ! input  ice/snow variables
+      REAL(wp), DIMENSION(:)  , INTENT(inout) ::   ph_i, ph_s, pa_i    ! output ice/snow variables
+      REAL(wp), DIMENSION(:,:), INTENT(in)    ::   ptmi, ptms, ptmsu, psmi, patip, phtip    ! input  ice/snow temp & sal & ponds
+      REAL(wp), DIMENSION(:)  , INTENT(inout) ::   pt_i, pt_s, pt_su, ps_i, pa_ip, ph_ip    ! output ice/snow temp & sal & ponds
+      !
+      REAL(wp), ALLOCATABLE, DIMENSION(:) ::   z1_ai, z1_vi, z1_vs
+      !
+      INTEGER ::   idim  
+      !!-------------------------------------------------------------------
+      !
+      idim = SIZE( phti, 1 )
+      !
+      ! == thickness and concentration == !
+      ALLOCATE( z1_ai(idim), z1_vi(idim), z1_vs(idim) )
+      !
+      pa_i(:) = SUM( pati(:,:), dim=2 )
+
+      WHERE( ( pa_i(:) ) /= 0._wp )   ;   z1_ai(:) = 1._wp / pa_i(:)
+      ELSEWHERE                       ;   z1_ai(:) = 0._wp
       END WHERE
+
+      ph_i(:) = SUM( phti(:,:) * pati(:,:), dim=2 ) * z1_ai(:)
+      ph_s(:) = SUM( phts(:,:) * pati(:,:), dim=2 ) * z1_ai(:)
+      !
+      ! == temperature and salinity == !
+      WHERE( ( pa_i(:) * ph_i(:) ) /= 0._wp )   ;   z1_vi(:) = 1._wp / ( pa_i(:) * ph_i(:) )
+      ELSEWHERE                                 ;   z1_vi(:) = 0._wp
+      END WHERE
+      WHERE( ( pa_i(:) * ph_s(:) ) /= 0._wp )   ;   z1_vs(:) = 1._wp / ( pa_i(:) * ph_s(:) )
+      ELSEWHERE                                 ;   z1_vs(:) = 0._wp
+      END WHERE
+      pt_i (:) = SUM( ptmi (:,:) * pati(:,:) * phti(:,:), dim=2 ) * z1_vi(:)
+      pt_s (:) = SUM( ptms (:,:) * pati(:,:) * phts(:,:), dim=2 ) * z1_vs(:)
+      pt_su(:) = SUM( ptmsu(:,:) * pati(:,:)            , dim=2 ) * z1_ai(:)
+      ps_i (:) = SUM( psmi (:,:) * pati(:,:) * phti(:,:), dim=2 ) * z1_vi(:)
+
+      ! == ponds == !
+      pa_ip(:) = SUM( patip(:,:), dim=2 )
+      WHERE( pa_ip(:) /= 0._wp )   ;   ph_ip(:) = SUM( phtip(:,:) * patip(:,:), dim=2 ) / pa_ip(:)
+      ELSEWHERE                    ;   ph_ip(:) = 0._wp
+      END WHERE
+      !
+      DEALLOCATE( z1_ai, z1_vi, z1_vs )
       !
    END SUBROUTINE ice_var_itd_Nc1c
    
-   SUBROUTINE ice_var_itd_1cMc( zhti, zhts, zati, zh_i, zh_s, za_i )
+   SUBROUTINE ice_var_itd_1cMc( phti, phts, pati ,                       ph_i, ph_s, pa_i, &
+      &                         ptmi, ptms, ptmsu, psmi, patip, phtip,   pt_i, pt_s, pt_su, ps_i, pa_ip, ph_ip )
       !!-------------------------------------------------------------------
       !!
@@ -826,7 +884,7 @@
       !!               4) Iterate until ok (SUM(itest(:) = 4)
       !!
-      !! ** Arguments : zhti: 1-cat ice thickness
-      !!                zhts: 1-cat snow depth
-      !!                zati: 1-cat ice concentration
+      !! ** Arguments : phti: 1-cat ice thickness
+      !!                phts: 1-cat snow depth
+      !!                pati: 1-cat ice concentration
       !!
       !! ** Output    : jpl-cat 
@@ -834,31 +892,35 @@
       !!  (Example of application: BDY forcings when input are cell averaged)  
       !!-------------------------------------------------------------------
-      INTEGER  :: ji, jk, jl             ! dummy loop indices
-      INTEGER  :: idim, i_fill, jl0  
-      REAL(wp) :: zarg, zV, zconv, zdh, zdv
-      REAL(wp), DIMENSION(:),   INTENT(in)    ::   zhti, zhts, zati    ! input  ice/snow variables
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   zh_i, zh_s, za_i    ! output ice/snow variables
-      INTEGER , DIMENSION(4)                  ::   itest
-      !!-------------------------------------------------------------------
-      !
-      ! ----------------------------------------
+      REAL(wp), DIMENSION(:),   INTENT(in)    ::   phti, phts, pati    ! input  ice/snow variables
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   ph_i, ph_s, pa_i    ! output ice/snow variables
+      REAL(wp), DIMENSION(:)  , INTENT(in)    ::   ptmi, ptms, ptmsu, psmi, patip, phtip    ! input  ice/snow temp & sal & ponds
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt_i, pt_s, pt_su, ps_i, pa_ip, ph_ip    ! output ice/snow temp & sal & ponds
+      !
+      INTEGER , DIMENSION(4) ::   itest
+      REAL(wp), ALLOCATABLE, DIMENSION(:) ::   zfra
+      INTEGER  ::   ji, jk, jl
+      INTEGER  ::   idim, i_fill, jl0  
+      REAL(wp) ::   zarg, zV, zconv, zdh, zdv
+      !!-------------------------------------------------------------------
+      !
+      ! == thickness and concentration == !
       ! distribution over the jpl ice categories
-      ! ----------------------------------------
-      ! a gaussian distribution for ice concentration is used
-      ! then we check whether the distribution fullfills
-      ! volume and area conservation, positivity and ice categories bounds
-      idim = SIZE( zhti , 1 )
-      zh_i(1:idim,1:jpl) = 0._wp
-      zh_s(1:idim,1:jpl) = 0._wp
-      za_i(1:idim,1:jpl) = 0._wp
+      !    a gaussian distribution for ice concentration is used
+      !    then we check whether the distribution fullfills
+      !    volume and area conservation, positivity and ice categories bounds
+      idim = SIZE( phti , 1 )
+      !
+      ph_i(1:idim,1:jpl) = 0._wp
+      ph_s(1:idim,1:jpl) = 0._wp
+      pa_i(1:idim,1:jpl) = 0._wp
       !
       DO ji = 1, idim
          !
-         IF( zhti(ji) > 0._wp ) THEN
+         IF( phti(ji) > 0._wp ) THEN
             !
             ! find which category (jl0) the input ice thickness falls into
             jl0 = jpl
             DO jl = 1, jpl
-               IF ( ( zhti(ji) >= hi_max(jl-1) ) .AND. ( zhti(ji) < hi_max(jl) ) ) THEN
+               IF ( ( phti(ji) >= hi_max(jl-1) ) .AND. ( phti(ji) < hi_max(jl) ) ) THEN
                   jl0 = jl
                   CYCLE
@@ -872,30 +934,30 @@
                i_fill = i_fill - 1
                !
-               zh_i(ji,1:jpl) = 0._wp
-               za_i(ji,1:jpl) = 0._wp
+               ph_i(ji,1:jpl) = 0._wp
+               pa_i(ji,1:jpl) = 0._wp
                itest(:)       = 0      
                !
                IF ( i_fill == 1 ) THEN      !-- case very thin ice: fill only category 1
-                  zh_i(ji,1) = zhti(ji)
-                  za_i (ji,1) = zati (ji)
+                  ph_i(ji,1) = phti(ji)
+                  pa_i(ji,1) = pati (ji)
                ELSE                         !-- case ice is thicker: fill categories >1
                   ! thickness
                   DO jl = 1, i_fill - 1
-                     zh_i(ji,jl) = hi_mean(jl)
+                     ph_i(ji,jl) = hi_mean(jl)
                   END DO
                   !
                   ! concentration
-                  za_i(ji,jl0) = zati(ji) / SQRT(REAL(jpl))
+                  pa_i(ji,jl0) = pati(ji) / SQRT(REAL(jpl))
                   DO jl = 1, i_fill - 1
                      IF ( jl /= jl0 ) THEN
-                        zarg        = ( zh_i(ji,jl) - zhti(ji) ) / ( zhti(ji) * 0.5_wp )
-                        za_i(ji,jl) =   za_i (ji,jl0) * EXP(-zarg**2)
+                        zarg        = ( ph_i(ji,jl) - phti(ji) ) / ( phti(ji) * 0.5_wp )
+                        pa_i(ji,jl) =   pa_i (ji,jl0) * EXP(-zarg**2)
                      ENDIF
                   END DO
                   !
                   ! last category
-                  za_i(ji,i_fill) = zati(ji) - SUM( za_i(ji,1:i_fill-1) )
-                  zV = SUM( za_i(ji,1:i_fill-1) * zh_i(ji,1:i_fill-1) )
-                  zh_i(ji,i_fill) = ( zhti(ji) * zati(ji) - zV ) / MAX( za_i(ji,i_fill), epsi10 ) 
+                  pa_i(ji,i_fill) = pati(ji) - SUM( pa_i(ji,1:i_fill-1) )
+                  zV = SUM( pa_i(ji,1:i_fill-1) * ph_i(ji,1:i_fill-1) )
+                  ph_i(ji,i_fill) = ( phti(ji) * pati(ji) - zV ) / MAX( pa_i(ji,i_fill), epsi10 ) 
                   !
                   ! correction if concentration of upper cat is greater than lower cat
@@ -903,9 +965,9 @@
                   IF ( jl0 /= jpl ) THEN
                      DO jl = jpl, jl0+1, -1
-                        IF ( za_i(ji,jl) > za_i(ji,jl-1) ) THEN
-                           zdv = zh_i(ji,jl) * za_i(ji,jl)
-                           zh_i(ji,jl    ) = 0._wp
-                           za_i (ji,jl    ) = 0._wp
-                           za_i (ji,1:jl-1) = za_i(ji,1:jl-1) + zdv / MAX( REAL(jl-1) * zhti(ji), epsi10 )
+                        IF ( pa_i(ji,jl) > pa_i(ji,jl-1) ) THEN
+                           zdv = ph_i(ji,jl) * pa_i(ji,jl)
+                           ph_i(ji,jl    ) = 0._wp
+                           pa_i (ji,jl    ) = 0._wp
+                           pa_i (ji,1:jl-1) = pa_i(ji,1:jl-1) + zdv / MAX( REAL(jl-1) * phti(ji), epsi10 )
                         END IF
                      END DO
@@ -915,15 +977,15 @@
                !
                ! Compatibility tests
-               zconv = ABS( zati(ji) - SUM( za_i(ji,1:jpl) ) ) 
+               zconv = ABS( pati(ji) - SUM( pa_i(ji,1:jpl) ) ) 
                IF ( zconv < epsi06 )   itest(1) = 1                                        ! Test 1: area conservation
                !
-               zconv = ABS( zhti(ji)*zati(ji) - SUM( za_i(ji,1:jpl)*zh_i(ji,1:jpl) ) )
+               zconv = ABS( phti(ji)*pati(ji) - SUM( pa_i(ji,1:jpl)*ph_i(ji,1:jpl) ) )
                IF ( zconv < epsi06 )   itest(2) = 1                                        ! Test 2: volume conservation
                !
-               IF ( zh_i(ji,i_fill) >= hi_max(i_fill-1) )   itest(3) = 1                  ! Test 3: thickness of the last category is in-bounds ?
+               IF ( ph_i(ji,i_fill) >= hi_max(i_fill-1) )   itest(3) = 1                   ! Test 3: thickness of the last category is in-bounds ?
                !
                itest(4) = 1
                DO jl = 1, i_fill
-                  IF ( za_i(ji,jl) < 0._wp ) itest(4) = 0                                ! Test 4: positivity of ice concentrations
+                  IF ( pa_i(ji,jl) < 0._wp ) itest(4) = 0                                  ! Test 4: positivity of ice concentrations
                END DO
                !                                         !----------------------------
@@ -933,22 +995,52 @@
       END DO
 
-      ! Add Snow in each category where za_i is not 0
+      ! Add Snow in each category where pa_i is not 0
       DO jl = 1, jpl
          DO ji = 1, idim
-            IF( za_i(ji,jl) > 0._wp ) THEN
-               zh_s(ji,jl) = zh_i(ji,jl) * ( zhts(ji) / zhti(ji) )
+            IF( pa_i(ji,jl) > 0._wp ) THEN
+               ph_s(ji,jl) = ph_i(ji,jl) * ( phts(ji) / phti(ji) )
                ! In case snow load is in excess that would lead to transformation from snow to ice
                ! Then, transfer the snow excess into the ice (different from icethd_dh)
-               zdh = MAX( 0._wp, ( rhos * zh_s(ji,jl) + ( rhoi - rau0 ) * zh_i(ji,jl) ) * r1_rau0 ) 
+               zdh = MAX( 0._wp, ( rhos * ph_s(ji,jl) + ( rhoi - rau0 ) * ph_i(ji,jl) ) * r1_rau0 ) 
                ! recompute h_i, h_s avoiding out of bounds values
-               zh_i(ji,jl) = MIN( hi_max(jl), zh_i(ji,jl) + zdh )
-               zh_s(ji,jl) = MAX( 0._wp, zh_s(ji,jl) - zdh * rhoi * r1_rhos )
+               ph_i(ji,jl) = MIN( hi_max(jl), ph_i(ji,jl) + zdh )
+               ph_s(ji,jl) = MAX( 0._wp, ph_s(ji,jl) - zdh * rhoi * r1_rhos )
             ENDIF
          END DO
       END DO
       !
+      ! == temperature and salinity == !
+      DO jl = 1, jpl
+         pt_i (:,jl) = ptmi (:)
+         pt_s (:,jl) = ptms (:)
+         pt_su(:,jl) = ptmsu(:)
+         ps_i (:,jl) = psmi (:)
+         ps_i (:,jl) = psmi (:)         
+      END DO
+      !
+      ! == ponds == !
+      ALLOCATE( zfra(idim) )
+      ! keep the same pond fraction atip/ati for each category
+      WHERE( pati(:) /= 0._wp )   ;   zfra(:) = patip(:) / pati(:)
+      ELSEWHERE                   ;   zfra(:) = 0._wp
+      END WHERE
+      DO jl = 1, jpl
+         pa_ip(:,jl) = zfra(:) * pa_i(:,jl)
+      END DO
+      ! keep the same v_ip/v_i ratio for each category
+      WHERE( ( phti(:) * pati(:) ) /= 0._wp )   ;   zfra(:) = ( phtip(:) * patip(:) ) / ( phti(:) * pati(:) )
+      ELSEWHERE                                 ;   zfra(:) = 0._wp
+      END WHERE
+      DO jl = 1, jpl
+         WHERE( pa_ip(:,jl) /= 0._wp )   ;   ph_ip(:,jl) = zfra(:) * ( ph_i(:,jl) * pa_i(:,jl) ) / pa_ip(:,jl)
+         ELSEWHERE                       ;   ph_ip(:,jl) = 0._wp
+         END WHERE
+      END DO
+      DEALLOCATE( zfra )
+      !
    END SUBROUTINE ice_var_itd_1cMc
 
-   SUBROUTINE ice_var_itd_NcMc( zhti, zhts, zati, zh_i, zh_s, za_i )
+   SUBROUTINE ice_var_itd_NcMc( phti, phts, pati ,                       ph_i, ph_s, pa_i, &
+      &                         ptmi, ptms, ptmsu, psmi, patip, phtip,   pt_i, pt_s, pt_su, ps_i, pa_ip, ph_ip )
       !!-------------------------------------------------------------------
       !!
@@ -971,7 +1063,7 @@
       !!                      b) removing 25% ice area from the higher cat (descendant loop jlmax=>jlmin)
       !!
-      !! ** Arguments : zhti: N-cat ice thickness
-      !!                zhts: N-cat snow depth
-      !!                zati: N-cat ice concentration
+      !! ** Arguments : phti: N-cat ice thickness
+      !!                phts: N-cat snow depth
+      !!                pati: N-cat ice concentration
       !!
       !! ** Output    : jpl-cat 
@@ -979,29 +1071,50 @@
       !!  (Example of application: BDY forcings when inputs have N-cat /= jpl)  
       !!-------------------------------------------------------------------
-      INTEGER  ::   ji, jl, jl1, jl2             ! dummy loop indices
+      REAL(wp), DIMENSION(:,:), INTENT(in)    ::   phti, phts, pati    ! input  ice/snow variables
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   ph_i, ph_s, pa_i    ! output ice/snow variables
+      REAL(wp), DIMENSION(:,:), INTENT(in)    ::   ptmi, ptms, ptmsu, psmi, patip, phtip    ! input  ice/snow temp & sal & ponds
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt_i, pt_s, pt_su, ps_i, pa_ip, ph_ip    ! output ice/snow temp & sal & ponds
+      !
+      INTEGER , ALLOCATABLE, DIMENSION(:,:) ::   jlfil, jlfil2
+      INTEGER , ALLOCATABLE, DIMENSION(:)   ::   jlmax, jlmin
+      REAL(wp), ALLOCATABLE, DIMENSION(:)   ::   z1_ai, z1_vi, z1_vs, ztmp, zfra
+      !
+      REAL(wp), PARAMETER ::   ztrans = 0.25_wp
+      INTEGER  ::   ji, jl, jl1, jl2
       INTEGER  ::   idim, icat  
-      REAL(wp), PARAMETER ::   ztrans = 0.25_wp
-      REAL(wp), DIMENSION(:,:), INTENT(in)    ::   zhti, zhts, zati    ! input ice/snow variables
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   zh_i, zh_s, za_i    ! output ice/snow variables
-      INTEGER , DIMENSION(:,:), ALLOCATABLE   ::   jlfil, jlfil2
-      INTEGER , DIMENSION(:)  , ALLOCATABLE   ::   jlmax, jlmin
-      !!-------------------------------------------------------------------
-      !
-      idim = SIZE( zhti, 1 )
-      icat = SIZE( zhti, 2 )
+      !!-------------------------------------------------------------------
+      !
+      idim = SIZE( phti, 1 )
+      icat = SIZE( phti, 2 )
+      !
+      ! == thickness and concentration == !
       !                                 ! ---------------------- !
       IF( icat == jpl ) THEN            ! input cat = output cat !
          !                              ! ---------------------- !
-         zh_i(:,:) = zhti(:,:)
-         zh_s(:,:) = zhts(:,:)
-         za_i(:,:) = zati(:,:)
+         ph_i(:,:) = phti(:,:)
+         ph_s(:,:) = phts(:,:)
+         pa_i(:,:) = pati(:,:)
+         !
+         ! == temperature and salinity and ponds == !
+         pt_i (:,:) = ptmi (:,:)
+         pt_s (:,:) = ptms (:,:)
+         pt_su(:,:) = ptmsu(:,:)
+         ps_i (:,:) = psmi (:,:)
+         pa_ip(:,:) = patip(:,:)
+         ph_ip(:,:) = phtip(:,:)
          !                              ! ---------------------- !
       ELSEIF( icat == 1 ) THEN          ! input cat = 1          !
          !                              ! ---------------------- !
-         CALL  ice_var_itd_1cMc( zhti(:,1), zhts(:,1), zati(:,1), zh_i(:,:), zh_s(:,:), za_i(:,:) )
+         CALL  ice_var_itd_1cMc( phti(:,1), phts(:,1), pati (:,1), &
+            &                    ph_i(:,:), ph_s(:,:), pa_i (:,:), &
+            &                    ptmi(:,1), ptms(:,1), ptmsu(:,1), psmi(:,1), patip(:,1), phtip(:,1), &
+            &                    pt_i(:,:), pt_s(:,:), pt_su(:,:), ps_i(:,:), pa_ip(:,:), ph_ip(:,:)  )
          !                              ! ---------------------- !
       ELSEIF( jpl == 1 ) THEN           ! output cat = 1         !
          !                              ! ---------------------- !
-         CALL  ice_var_itd_Nc1c( zhti(:,:), zhts(:,:), zati(:,:), zh_i(:,1), zh_s(:,1), za_i(:,1) )         
+         CALL  ice_var_itd_Nc1c( phti(:,:), phts(:,:), pati (:,:), &
+            &                    ph_i(:,1), ph_s(:,1), pa_i (:,1), &
+            &                    ptmi(:,:), ptms(:,:), ptmsu(:,:), psmi(:,:), patip(:,:), phtip(:,:), &
+            &                    pt_i(:,1), pt_s(:,1), pt_su(:,1), ps_i(:,1), pa_ip(:,1), ph_ip(:,1)  )
          !                              ! ----------------------- !
       ELSE                              ! input cat /= output cat !
@@ -1012,7 +1125,7 @@
 
          ! --- initialize output fields to 0 --- !
-         zh_i(1:idim,1:jpl) = 0._wp
-         zh_s(1:idim,1:jpl) = 0._wp
-         za_i(1:idim,1:jpl) = 0._wp
+         ph_i(1:idim,1:jpl) = 0._wp
+         ph_s(1:idim,1:jpl) = 0._wp
+         pa_i(1:idim,1:jpl) = 0._wp
          !
          ! --- fill the categories --- !
@@ -1024,9 +1137,9 @@
             DO jl2 = 1, icat
                DO ji = 1, idim
-                  IF( hi_max(jl1-1) <= zhti(ji,jl2) .AND. hi_max(jl1) > zhti(ji,jl2) ) THEN
+                  IF( hi_max(jl1-1) <= phti(ji,jl2) .AND. hi_max(jl1) > phti(ji,jl2) ) THEN
                      ! fill the right category
-                     zh_i(ji,jl1) = zhti(ji,jl2)
-                     zh_s(ji,jl1) = zhts(ji,jl2)
-                     za_i(ji,jl1) = zati(ji,jl2)
+                     ph_i(ji,jl1) = phti(ji,jl2)
+                     ph_s(ji,jl1) = phts(ji,jl2)
+                     pa_i(ji,jl1) = pati(ji,jl2)
                      ! record categories that are filled
                      jlmax(ji) = MAX( jlmax(ji), jl1 )
@@ -1045,15 +1158,15 @@
             IF( jl1 > 1 ) THEN
                ! fill the lower cat (jl1-1)
-               za_i(ji,jl1-1) = ztrans * za_i(ji,jl1)
-               zh_i(ji,jl1-1) = hi_mean(jl1-1)
+               pa_i(ji,jl1-1) = ztrans * pa_i(ji,jl1)
+               ph_i(ji,jl1-1) = hi_mean(jl1-1)
                ! remove from cat jl1
-               za_i(ji,jl1  ) = ( 1._wp - ztrans ) * za_i(ji,jl1)
+               pa_i(ji,jl1  ) = ( 1._wp - ztrans ) * pa_i(ji,jl1)
             ENDIF
             IF( jl2 < jpl ) THEN
                ! fill the upper cat (jl2+1)
-               za_i(ji,jl2+1) = ztrans * za_i(ji,jl2)
-               zh_i(ji,jl2+1) = hi_mean(jl2+1)
+               pa_i(ji,jl2+1) = ztrans * pa_i(ji,jl2)
+               ph_i(ji,jl2+1) = hi_mean(jl2+1)
                ! remove from cat jl2
-               za_i(ji,jl2  ) = ( 1._wp - ztrans ) * za_i(ji,jl2)
+               pa_i(ji,jl2  ) = ( 1._wp - ztrans ) * pa_i(ji,jl2)
             ENDIF
          END DO
@@ -1065,9 +1178,9 @@
                IF( jlfil(ji,jl-1) /= 0 .AND. jlfil(ji,jl) == 0 ) THEN
                   ! fill high
-                  za_i(ji,jl) = ztrans * za_i(ji,jl-1)
-                  zh_i(ji,jl) = hi_mean(jl)
+                  pa_i(ji,jl) = ztrans * pa_i(ji,jl-1)
+                  ph_i(ji,jl) = hi_mean(jl)
                   jlfil(ji,jl) = jl
                   ! remove low
-                  za_i(ji,jl-1) = ( 1._wp - ztrans ) * za_i(ji,jl-1)
+                  pa_i(ji,jl-1) = ( 1._wp - ztrans ) * pa_i(ji,jl-1)
                ENDIF
             END DO
@@ -1079,9 +1192,9 @@
                IF( jlfil2(ji,jl+1) /= 0 .AND. jlfil2(ji,jl) == 0 ) THEN
                   ! fill low
-                  za_i(ji,jl) = za_i(ji,jl) + ztrans * za_i(ji,jl+1)
-                  zh_i(ji,jl) = hi_mean(jl) 
+                  pa_i(ji,jl) = pa_i(ji,jl) + ztrans * pa_i(ji,jl+1)
+                  ph_i(ji,jl) = hi_mean(jl) 
                   jlfil2(ji,jl) = jl
                   ! remove high
-                  za_i(ji,jl+1) = ( 1._wp - ztrans ) * za_i(ji,jl+1)
+                  pa_i(ji,jl+1) = ( 1._wp - ztrans ) * pa_i(ji,jl+1)
                ENDIF
             END DO
@@ -1090,4 +1203,60 @@
          DEALLOCATE( jlfil, jlfil2 )      ! deallocate arrays
          DEALLOCATE( jlmin, jlmax )
+         !
+         ! == temperature and salinity == !
+         !
+         ALLOCATE( z1_ai(idim), z1_vi(idim), z1_vs(idim), ztmp(idim) )
+         !
+         WHERE( SUM( pa_i(:,:), dim=2 ) /= 0._wp )               ;   z1_ai(:) = 1._wp / SUM( pa_i(:,:), dim=2 )
+         ELSEWHERE                                               ;   z1_ai(:) = 0._wp
+         END WHERE
+         WHERE( SUM( pa_i(:,:) * ph_i(:,:), dim=2 ) /= 0._wp )   ;   z1_vi(:) = 1._wp / SUM( pa_i(:,:) * ph_i(:,:), dim=2 )
+         ELSEWHERE                                               ;   z1_vi(:) = 0._wp
+         END WHERE
+         WHERE( SUM( pa_i(:,:) * ph_s(:,:), dim=2 ) /= 0._wp )   ;   z1_vs(:) = 1._wp / SUM( pa_i(:,:) * ph_s(:,:), dim=2 )
+         ELSEWHERE                                               ;   z1_vs(:) = 0._wp
+         END WHERE
+         !
+         ! fill all the categories with the same value
+         ztmp(:) = SUM( ptmi (:,:) * pati(:,:) * phti(:,:), dim=2 ) * z1_vi(:)
+         DO jl = 1, jpl
+            pt_i (:,jl) = ztmp(:)
+         END DO
+         ztmp(:) = SUM( ptms (:,:) * pati(:,:) * phts(:,:), dim=2 ) * z1_vs(:)
+         DO jl = 1, jpl
+            pt_s (:,jl) = ztmp(:)
+         END DO
+         ztmp(:) = SUM( ptmsu(:,:) * pati(:,:)            , dim=2 ) * z1_ai(:)
+         DO jl = 1, jpl
+            pt_su(:,jl) = ztmp(:)
+         END DO
+         ztmp(:) = SUM( psmi (:,:) * pati(:,:) * phti(:,:), dim=2 ) * z1_vi(:)
+         DO jl = 1, jpl
+            ps_i (:,jl) = ztmp(:)
+         END DO
+         !
+         DEALLOCATE( z1_ai, z1_vi, z1_vs, ztmp )
+         !
+         ! == ponds == !
+         ALLOCATE( zfra(idim) )
+         ! keep the same pond fraction atip/ati for each category
+         WHERE( SUM( pati(:,:), dim=2 ) /= 0._wp )   ;   zfra(:) = SUM( patip(:,:), dim=2 ) / SUM( pati(:,:), dim=2 )
+         ELSEWHERE                                   ;   zfra(:) = 0._wp
+         END WHERE
+         DO jl = 1, jpl
+            pa_ip(:,jl) = zfra(:) * pa_i(:,jl)
+         END DO
+         ! keep the same v_ip/v_i ratio for each category
+         WHERE( SUM( phti(:,:) * pati(:,:), dim=2 ) /= 0._wp )
+            zfra(:) = SUM( phtip(:,:) * patip(:,:), dim=2 ) / SUM( phti(:,:) * pati(:,:), dim=2 )
+         ELSEWHERE
+            zfra(:) = 0._wp
+         END WHERE
+         DO jl = 1, jpl
+            WHERE( pa_ip(:,jl) /= 0._wp )   ;   ph_ip(:,jl) = zfra(:) * ( ph_i(:,jl) * pa_i(:,jl) ) / pa_ip(:,jl)
+            ELSEWHERE                       ;   ph_ip(:,jl) = 0._wp
+            END WHERE
+         END DO
+         DEALLOCATE( zfra )
          !
       ENDIF
Index: /NEMO/trunk/src/ICE/icewri.F90
===================================================================
--- /NEMO/trunk/src/ICE/icewri.F90	(revision 11535)
+++ /NEMO/trunk/src/ICE/icewri.F90	(revision 11536)
@@ -50,5 +50,6 @@
       INTEGER  ::   ji, jj, jk, jl  ! dummy loop indices
       REAL(wp) ::   z2da, z2db, zrho1, zrho2
-      REAL(wp), DIMENSION(jpi,jpj)     ::   z2d, zfast !  2D workspace
+      REAL(wp) ::   zmiss_val       ! missing value retrieved from xios 
+      REAL(wp), DIMENSION(jpi,jpj)     ::   z2d, zfast                     ! 2D workspace
       REAL(wp), DIMENSION(jpi,jpj)     ::   zmsk00, zmsk05, zmsk15, zmsksn ! O%, 5% and 15% concentration mask and snow mask
       REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zmsk00l, zmsksnl               ! cat masks
@@ -58,6 +59,9 @@
       REAL(wp) ::   zdiag_area_sh, zdiag_extt_sh, zdiag_volu_sh 
       !!-------------------------------------------------------------------
-
+      !
       IF( ln_timing )   CALL timing_start('icewri')
+
+      ! get missing value from xml
+      CALL iom_miss_val( 'icetemp', zmiss_val )
 
       ! brine volume
@@ -85,84 +89,79 @@
       ! Standard outputs
       !-----------------
-      zrho1 = ( rau0 - rhoi ) * r1_rau0; zrho2 = rhos * r1_rau0
+      zrho1 = ( rau0 - rhoi ) * r1_rau0 ; zrho2 = rhos * r1_rau0
       ! masks
-      IF( iom_use('icemask'  ) )   CALL iom_put( "icemask"  , zmsk00              )   ! ice mask 0%
-      IF( iom_use('icemask05') )   CALL iom_put( "icemask05", zmsk05              )   ! ice mask 5%
-      IF( iom_use('icemask15') )   CALL iom_put( "icemask15", zmsk15              )   ! ice mask 15%
+      CALL iom_put( 'icemask'  , zmsk00 )   ! ice mask 0%
+      CALL iom_put( 'icemask05', zmsk05 )   ! ice mask 5%
+      CALL iom_put( 'icemask15', zmsk15 )   ! ice mask 15%
+      CALL iom_put( 'icepres'  , zmsk00 )   ! Ice presence (1 or 0) 
       !
       ! general fields
-      IF( iom_use('icemass'  ) )   CALL iom_put( "icemass", rhoi * vt_i * zmsk00  )   ! Ice mass per cell area 
-      IF( iom_use('snwmass'  ) )   CALL iom_put( "snwmass", rhos * vt_s * zmsksn  )   ! Snow mass per cell area
-      IF( iom_use('icepres'  ) )   CALL iom_put( "icepres", zmsk00                )   ! Ice presence (1 or 0) 
-      IF( iom_use('iceconc'  ) )   CALL iom_put( "iceconc", at_i  * zmsk00        )   ! ice concentration
-      IF( iom_use('icevolu'  ) )   CALL iom_put( "icevolu", vt_i  * zmsk00        )   ! ice volume = mean ice thickness over the cell
-      IF( iom_use('icethic'  ) )   CALL iom_put( "icethic", hm_i  * zmsk00        )   ! ice thickness
-      IF( iom_use('snwthic'  ) )   CALL iom_put( "snwthic", hm_s  * zmsk00        )   ! snw thickness
-      IF( iom_use('icebrv'   ) )   CALL iom_put( "icebrv" , bvm_i * zmsk00 * 100. )   ! brine volume
-      IF( iom_use('iceage'   ) )   CALL iom_put( "iceage" , om_i  * zmsk15 / rday )   ! ice age
-      IF( iom_use('icehnew'  ) )   CALL iom_put( "icehnew", ht_i_new              )   ! new ice thickness formed in the leads
-      IF( iom_use('snwvolu'  ) )   CALL iom_put( "snwvolu", vt_s  * zmsksn        )   ! snow volume
-      IF( iom_use('icefrb') ) THEN
+      IF( iom_use('icemass' ) )   CALL iom_put( 'icemass', vt_i * rhoi * zmsk00 )                                           ! Ice mass per cell area 
+      IF( iom_use('snwmass' ) )   CALL iom_put( 'snwmass', vt_s * rhos * zmsksn )                                           ! Snow mass per cell area
+      IF( iom_use('iceconc' ) )   CALL iom_put( 'iceconc', at_i        * zmsk00 )                                           ! ice concentration
+      IF( iom_use('icevolu' ) )   CALL iom_put( 'icevolu', vt_i        * zmsk00 )                                           ! ice volume = mean ice thickness over the cell
+      IF( iom_use('icethic' ) )   CALL iom_put( 'icethic', hm_i        * zmsk00 )                                           ! ice thickness
+      IF( iom_use('snwthic' ) )   CALL iom_put( 'snwthic', hm_s        * zmsk00 )                                           ! snw thickness
+      IF( iom_use('icebrv'  ) )   CALL iom_put( 'icebrv' , bvm_i* 100. * zmsk00 )                                           ! brine volume
+      IF( iom_use('iceage'  ) )   CALL iom_put( 'iceage' , om_i / rday * zmsk15 + zmiss_val * ( 1._wp - zmsk15 ) )          ! ice age
+      IF( iom_use('icehnew' ) )   CALL iom_put( 'icehnew', ht_i_new             )                                           ! new ice thickness formed in the leads
+      IF( iom_use('snwvolu' ) )   CALL iom_put( 'snwvolu', vt_s        * zmsksn )                                           ! snow volume
+      IF( iom_use('icefrb'  ) ) THEN                                                                                        ! Ice freeboard
          z2d(:,:) = ( zrho1 * hm_i(:,:) - zrho2 * hm_s(:,:) )                                         
          WHERE( z2d < 0._wp )   z2d = 0._wp
-                                   CALL iom_put( "icefrb" , z2d * zmsk00          )   ! Ice freeboard
+                                  CALL iom_put( 'icefrb' , z2d * zmsk00         )
       ENDIF
-      !
       ! melt ponds
-      IF( iom_use('iceapnd'  ) )   CALL iom_put( "iceapnd", at_ip  * zmsk00       )   ! melt pond total fraction
-      IF( iom_use('icevpnd'  ) )   CALL iom_put( "icevpnd", vt_ip  * zmsk00       )   ! melt pond total volume per unit area
-      !
+      IF( iom_use('iceapnd' ) )   CALL iom_put( 'iceapnd', at_ip  * zmsk00      )                                           ! melt pond total fraction
+      IF( iom_use('icehpnd' ) )   CALL iom_put( 'icehpnd', hm_ip  * zmsk00      )                                           ! melt pond depth
+      IF( iom_use('icevpnd' ) )   CALL iom_put( 'icevpnd', vt_ip  * zmsk00      )                                           ! melt pond total volume per unit area
       ! salt
-      IF( iom_use('icesalt'  ) )   CALL iom_put( "icesalt", sm_i  * zmsk00        )   ! mean ice salinity
-      IF( iom_use('icesalm'  ) )   CALL iom_put( "icesalm", SUM( sv_i, DIM = 3 ) * rhoi * 1.0e-3 * zmsk00 )   ! Mass of salt in sea ice per cell area
-
+      IF( iom_use('icesalt' ) )   CALL iom_put( 'icesalt', sm_i                 * zmsk00 + zmiss_val * ( 1._wp - zmsk00 ) ) ! mean ice salinity
+      IF( iom_use('icesalm' ) )   CALL iom_put( 'icesalm', st_i * rhoi * 1.0e-3 * zmsk00 )                                  ! Mass of salt in sea ice per cell area
       ! heat
-      IF( iom_use('icetemp'  ) )   CALL iom_put( "icetemp", ( tm_i  - rt0 ) * zmsk00 )   ! ice mean temperature
-      IF( iom_use('snwtemp'  ) )   CALL iom_put( "snwtemp", ( tm_s  - rt0 ) * zmsksn )   ! snw mean temperature
-      IF( iom_use('icettop'  ) )   CALL iom_put( "icettop", ( tm_su - rt0 ) * zmsk00 )   ! temperature at the ice surface
-      IF( iom_use('icetbot'  ) )   CALL iom_put( "icetbot", ( t_bo  - rt0 ) * zmsk00 )   ! temperature at the ice bottom
-      IF( iom_use('icetsni'  ) )   CALL iom_put( "icetsni", ( tm_si - rt0 ) * zmsk00 )   ! temperature at the snow-ice interface
-      IF( iom_use('icehc'    ) )   CALL iom_put( "icehc"  ,  -et_i          * zmsk00 )   ! ice heat content
-      IF( iom_use('snwhc'    ) )   CALL iom_put( "snwhc"  ,  -et_s          * zmsksn )   ! snow heat content
-
+      IF( iom_use('icetemp' ) )   CALL iom_put( 'icetemp', ( tm_i  - rt0 ) * zmsk00 + zmiss_val * ( 1._wp - zmsk00 ) )      ! ice mean temperature
+      IF( iom_use('snwtemp' ) )   CALL iom_put( 'snwtemp', ( tm_s  - rt0 ) * zmsksn + zmiss_val * ( 1._wp - zmsksn ) )      ! snw mean temperature
+      IF( iom_use('icettop' ) )   CALL iom_put( 'icettop', ( tm_su - rt0 ) * zmsk00 + zmiss_val * ( 1._wp - zmsk00 ) )      ! temperature at the ice surface
+      IF( iom_use('icetbot' ) )   CALL iom_put( 'icetbot', ( t_bo  - rt0 ) * zmsk00 + zmiss_val * ( 1._wp - zmsk00 ) )      ! temperature at the ice bottom
+      IF( iom_use('icetsni' ) )   CALL iom_put( 'icetsni', ( tm_si - rt0 ) * zmsk00 + zmiss_val * ( 1._wp - zmsk00 ) )      ! temperature at the snow-ice interface
+      IF( iom_use('icehc'   ) )   CALL iom_put( 'icehc'  ,  -et_i          * zmsk00 )                                       ! ice heat content
+      IF( iom_use('snwhc'   ) )   CALL iom_put( 'snwhc'  ,  -et_s          * zmsksn )                                       ! snow heat content
       ! momentum
-      IF( iom_use('uice'     ) )   CALL iom_put( "uice"   , u_ice                 )   ! ice velocity u component
-      IF( iom_use('vice'     ) )   CALL iom_put( "vice"   , v_ice                 )   ! ice velocity v component
-      IF( iom_use('utau_ai'  ) )   CALL iom_put( "utau_ai", utau_ice * zmsk00     )   ! Wind stress term in force balance (x)
-      IF( iom_use('vtau_ai'  ) )   CALL iom_put( "vtau_ai", vtau_ice * zmsk00     )   ! Wind stress term in force balance (y)
-
-      IF( iom_use('icevel') .OR. iom_use('fasticepres') ) THEN 
-        ! module of ice velocity
+      IF( iom_use('uice'    ) )   CALL iom_put( 'uice'   , u_ice    )                                                       ! ice velocity u
+      IF( iom_use('vice'    ) )   CALL iom_put( 'vice'   , v_ice    )                                                       ! ice velocity v
+      !
+      IF( iom_use('icevel') .OR. iom_use('fasticepres') ) THEN                                                              ! module of ice velocity
          DO jj = 2 , jpjm1
             DO ji = 2 , jpim1
-               z2da  = ( u_ice(ji,jj) + u_ice(ji-1,jj) )
-               z2db  = ( v_ice(ji,jj) + v_ice(ji,jj-1) )
+               z2da  = u_ice(ji,jj) + u_ice(ji-1,jj)
+               z2db  = v_ice(ji,jj) + v_ice(ji,jj-1)
                z2d(ji,jj) = 0.5_wp * SQRT( z2da * z2da + z2db * z2db )
            END DO
          END DO
          CALL lbc_lnk( 'icewri', z2d, 'T', 1. )
-         IF( iom_use('icevel') )   CALL iom_put( "icevel" , z2d )
-
-        ! record presence of fast ice
-         WHERE( z2d(:,:) < 5.e-04_wp .AND. zmsk15(:,:) == 1._wp ) ; zfast(:,:) = 1._wp
+         CALL iom_put( 'icevel', z2d )
+
+         WHERE( z2d(:,:) < 5.e-04_wp .AND. zmsk15(:,:) == 1._wp ) ; zfast(:,:) = 1._wp                                      ! record presence of fast ice
          ELSEWHERE                                                ; zfast(:,:) = 0._wp
          END WHERE
-         IF( iom_use('fasticepres') )   CALL iom_put( "fasticepres" , zfast )
+         CALL iom_put( 'fasticepres', zfast )
       ENDIF
 
       ! --- category-dependent fields --- !
-      IF( iom_use('icemask_cat' ) )   CALL iom_put( "icemask_cat" , zmsk00l                                                    )   ! ice mask 0%
-      IF( iom_use('iceconc_cat' ) )   CALL iom_put( "iceconc_cat" , a_i * zmsk00l                                              )   ! area for categories
-      IF( iom_use('icethic_cat' ) )   CALL iom_put( "icethic_cat" , h_i * zmsk00l                                              )   ! thickness for categories
-      IF( iom_use('snwthic_cat' ) )   CALL iom_put( "snwthic_cat" , h_s * zmsksnl                                              )   ! snow depth for categories
-      IF( iom_use('icesalt_cat' ) )   CALL iom_put( "icesalt_cat" , s_i * zmsk00l                                              )   ! salinity for categories
-      IF( iom_use('iceage_cat'  ) )   CALL iom_put( "iceage_cat"  , o_i * zmsk00l / rday                                       )   ! ice age
-      IF( iom_use('icetemp_cat' ) )   CALL iom_put( "icetemp_cat" , ( SUM( t_i(:,:,:,:), dim=3 ) * r1_nlay_i - rt0 ) * zmsk00l )   ! ice temperature
-      IF( iom_use('snwtemp_cat' ) )   CALL iom_put( "snwtemp_cat" , ( SUM( t_s(:,:,:,:), dim=3 ) * r1_nlay_s - rt0 ) * zmsksnl )   ! snow temperature
-      IF( iom_use('icettop_cat' ) )   CALL iom_put( "icettop_cat" , ( t_su - rt0 ) * zmsk00l                                   )   ! surface temperature
-      IF( iom_use('icebrv_cat'  ) )   CALL iom_put( "icebrv_cat"  ,   bv_i * 100.  * zmsk00l                                   )   ! brine volume
-      IF( iom_use('iceapnd_cat' ) )   CALL iom_put( "iceapnd_cat" ,   a_ip         * zmsk00l                                   )   ! melt pond frac for categories
-      IF( iom_use('icehpnd_cat' ) )   CALL iom_put( "icehpnd_cat" ,   h_ip         * zmsk00l                                   )   ! melt pond frac for categories
-      IF( iom_use('iceafpnd_cat') )   CALL iom_put( "iceafpnd_cat",   a_ip_frac    * zmsk00l                                   )   ! melt pond frac for categories
+      IF( iom_use('icemask_cat' ) )   CALL iom_put( 'icemask_cat' ,                  zmsk00l                                   ) ! ice mask 0%
+      IF( iom_use('iceconc_cat' ) )   CALL iom_put( 'iceconc_cat' , a_i            * zmsk00l                                   ) ! area for categories
+      IF( iom_use('icethic_cat' ) )   CALL iom_put( 'icethic_cat' , h_i            * zmsk00l + zmiss_val * ( 1._wp - zmsk00l ) ) ! thickness for categories
+      IF( iom_use('snwthic_cat' ) )   CALL iom_put( 'snwthic_cat' , h_s            * zmsksnl + zmiss_val * ( 1._wp - zmsksnl ) ) ! snow depth for categories
+      IF( iom_use('icesalt_cat' ) )   CALL iom_put( 'icesalt_cat' , s_i            * zmsk00l + zmiss_val * ( 1._wp - zmsk00l ) ) ! salinity for categories
+      IF( iom_use('iceage_cat'  ) )   CALL iom_put( 'iceage_cat'  , o_i / rday     * zmsk00l + zmiss_val * ( 1._wp - zmsk00l ) ) ! ice age
+      IF( iom_use('icetemp_cat' ) )   CALL iom_put( 'icetemp_cat' , ( SUM( t_i, dim=3 ) * r1_nlay_i - rt0 ) &
+         &                                                                         * zmsk00l + zmiss_val * ( 1._wp - zmsk00l ) ) ! ice temperature
+      IF( iom_use('snwtemp_cat' ) )   CALL iom_put( 'snwtemp_cat' , ( SUM( t_s, dim=3 ) * r1_nlay_s - rt0 ) &
+         &                                                                         * zmsksnl + zmiss_val * ( 1._wp - zmsksnl ) ) ! snow temperature
+      IF( iom_use('icettop_cat' ) )   CALL iom_put( 'icettop_cat' , ( t_su - rt0 ) * zmsk00l + zmiss_val * ( 1._wp - zmsk00l ) ) ! surface temperature
+      IF( iom_use('icebrv_cat'  ) )   CALL iom_put( 'icebrv_cat'  ,   bv_i * 100.  * zmsk00l + zmiss_val * ( 1._wp - zmsk00l ) ) ! brine volume
+      IF( iom_use('iceapnd_cat' ) )   CALL iom_put( 'iceapnd_cat' ,   a_ip         * zmsk00l                                   ) ! melt pond frac for categories
+      IF( iom_use('icehpnd_cat' ) )   CALL iom_put( 'icehpnd_cat' ,   h_ip         * zmsk00l + zmiss_val * ( 1._wp - zmsk00l ) ) ! melt pond frac for categories
+      IF( iom_use('iceafpnd_cat') )   CALL iom_put( 'iceafpnd_cat',   a_ip_frac    * zmsk00l                                   ) ! melt pond frac for categories
 
       !------------------
@@ -170,62 +169,48 @@
       !------------------
       ! trends
-      IF( iom_use('dmithd') )   CALL iom_put( "dmithd", - wfx_bog - wfx_bom - wfx_sum - wfx_sni - wfx_opw - wfx_lam - wfx_res ) ! Sea-ice mass change from thermodynamics
-      IF( iom_use('dmidyn') )   CALL iom_put( "dmidyn", - wfx_dyn + rhoi * diag_trp_vi      )   ! Sea-ice mass change from dynamics(kg/m2/s)
-      IF( iom_use('dmiopw') )   CALL iom_put( "dmiopw", - wfx_opw                           )   ! Sea-ice mass change through growth in open water
-      IF( iom_use('dmibog') )   CALL iom_put( "dmibog", - wfx_bog                           )   ! Sea-ice mass change through basal growth
-      IF( iom_use('dmisni') )   CALL iom_put( "dmisni", - wfx_sni                           )   ! Sea-ice mass change through snow-to-ice conversion
-      IF( iom_use('dmisum') )   CALL iom_put( "dmisum", - wfx_sum                           )   ! Sea-ice mass change through surface melting
-      IF( iom_use('dmibom') )   CALL iom_put( "dmibom", - wfx_bom                           )   ! Sea-ice mass change through bottom melting
-      IF( iom_use('dmtsub') )   CALL iom_put( "dmtsub", - wfx_sub                           )   ! Sea-ice mass change through evaporation and sublimation
-      IF( iom_use('dmssub') )   CALL iom_put( "dmssub", - wfx_snw_sub                       )   ! Snow mass change through sublimation
-      IF( iom_use('dmisub') )   CALL iom_put( "dmisub", - wfx_ice_sub                       )   ! Sea-ice mass change through sublimation
-      IF( iom_use('dmsspr') )   CALL iom_put( "dmsspr", - wfx_spr                           )   ! Snow mass change through snow fall
-      IF( iom_use('dmsssi') )   CALL iom_put( "dmsssi",   wfx_sni*rhos*r1_rhoi              )   ! Snow mass change through snow-to-ice conversion
-      IF( iom_use('dmsmel') )   CALL iom_put( "dmsmel", - wfx_snw_sum                       )   ! Snow mass change through melt
-      IF( iom_use('dmsdyn') )   CALL iom_put( "dmsdyn", - wfx_snw_dyn + rhos * diag_trp_vs  )   ! Snow mass change through dynamics(kg/m2/s)
-
+      IF( iom_use('dmithd') )   CALL iom_put( 'dmithd', - wfx_bog - wfx_bom - wfx_sum - wfx_sni - wfx_opw - wfx_lam - wfx_res ) ! Sea-ice mass change from thermodynamics
+      IF( iom_use('dmidyn') )   CALL iom_put( 'dmidyn', - wfx_dyn + rhoi * diag_trp_vi                                        ) ! Sea-ice mass change from dynamics(kg/m2/s)
+      IF( iom_use('dmiopw') )   CALL iom_put( 'dmiopw', - wfx_opw                                                             ) ! Sea-ice mass change through growth in open water
+      IF( iom_use('dmibog') )   CALL iom_put( 'dmibog', - wfx_bog                                                             ) ! Sea-ice mass change through basal growth
+      IF( iom_use('dmisni') )   CALL iom_put( 'dmisni', - wfx_sni                                                             ) ! Sea-ice mass change through snow-to-ice conversion
+      IF( iom_use('dmisum') )   CALL iom_put( 'dmisum', - wfx_sum                                                             ) ! Sea-ice mass change through surface melting
+      IF( iom_use('dmibom') )   CALL iom_put( 'dmibom', - wfx_bom                                                             ) ! Sea-ice mass change through bottom melting
+      IF( iom_use('dmtsub') )   CALL iom_put( 'dmtsub', - wfx_sub                                                             ) ! Sea-ice mass change through evaporation and sublimation
+      IF( iom_use('dmssub') )   CALL iom_put( 'dmssub', - wfx_snw_sub                                                         ) ! Snow mass change through sublimation
+      IF( iom_use('dmisub') )   CALL iom_put( 'dmisub', - wfx_ice_sub                                                         ) ! Sea-ice mass change through sublimation
+      IF( iom_use('dmsspr') )   CALL iom_put( 'dmsspr', - wfx_spr                                                             ) ! Snow mass change through snow fall
+      IF( iom_use('dmsssi') )   CALL iom_put( 'dmsssi',   wfx_sni*rhos*r1_rhoi                                                ) ! Snow mass change through snow-to-ice conversion
+      IF( iom_use('dmsmel') )   CALL iom_put( 'dmsmel', - wfx_snw_sum                                                         ) ! Snow mass change through melt
+      IF( iom_use('dmsdyn') )   CALL iom_put( 'dmsdyn', - wfx_snw_dyn + rhos * diag_trp_vs                                    ) ! Snow mass change through dynamics(kg/m2/s)
+      
       ! Global ice diagnostics
-      IF( iom_use('NH_icearea') .OR. iom_use('NH_icevolu') .OR. iom_use('NH_iceextt') )   THEN   ! NH diagnostics
-         !
-         WHERE( ff_t > 0._wp )   ;   zmsk00(:,:) = 1.0e-12
-         ELSEWHERE               ;   zmsk00(:,:) = 0.
-         END WHERE 
-         zdiag_area_nh = glob_sum( 'icewri', at_i(:,:) * zmsk00(:,:) * e1e2t(:,:) )
-         zdiag_volu_nh = glob_sum( 'icewri', vt_i(:,:) * zmsk00(:,:) * e1e2t(:,:) )
-         !
-         WHERE( ff_t > 0._wp .AND. at_i > 0.15 )   ; zmsk00(:,:) = 1.0e-12
-         ELSEWHERE                                 ; zmsk00(:,:) = 0.
-         END WHERE 
-         zdiag_extt_nh = glob_sum( 'icewri', zmsk00(:,:) * e1e2t(:,:) )
-         !
-         IF( iom_use('NH_icearea') )   CALL iom_put( "NH_icearea" ,  zdiag_area_nh )
-         IF( iom_use('NH_icevolu') )   CALL iom_put( "NH_icevolu" ,  zdiag_volu_nh )
-         IF( iom_use('NH_iceextt') )   CALL iom_put( "NH_iceextt" ,  zdiag_extt_nh )
+      IF(  iom_use('NH_icearea') .OR. iom_use('NH_icevolu') .OR. iom_use('NH_iceextt') .OR. &
+         & iom_use('SH_icearea') .OR. iom_use('SH_icevolu') .OR. iom_use('SH_iceextt') ) THEN
+         !
+         WHERE( ff_t(:,:) > 0._wp )   ;   z2d(:,:) = 1._wp
+         ELSEWHERE                    ;   z2d(:,:) = 0.
+         END WHERE
+         !
+         IF( iom_use('NH_icearea') )   zdiag_area_nh = glob_sum( 'icewri', at_i *           z2d   * e1e2t * 1.e-12 )
+         IF( iom_use('NH_icevolu') )   zdiag_volu_nh = glob_sum( 'icewri', vt_i *           z2d   * e1e2t * 1.e-12 )
+         IF( iom_use('NH_iceextt') )   zdiag_extt_nh = glob_sum( 'icewri',                  z2d   * e1e2t * 1.e-12 * zmsk15 )
+         !
+         IF( iom_use('SH_icearea') )   zdiag_area_sh = glob_sum( 'icewri', at_i * ( 1._wp - z2d ) * e1e2t * 1.e-12 )
+         IF( iom_use('SH_icevolu') )   zdiag_volu_sh = glob_sum( 'icewri', vt_i * ( 1._wp - z2d ) * e1e2t * 1.e-12 )
+         IF( iom_use('SH_iceextt') )   zdiag_extt_sh = glob_sum( 'icewri',        ( 1._wp - z2d ) * e1e2t * 1.e-12 * zmsk15 )
+         !
+         CALL iom_put( 'NH_icearea' , zdiag_area_nh )
+         CALL iom_put( 'NH_icevolu' , zdiag_volu_nh )
+         CALL iom_put( 'NH_iceextt' , zdiag_extt_nh )
+         CALL iom_put( 'SH_icearea' , zdiag_area_sh )
+         CALL iom_put( 'SH_icevolu' , zdiag_volu_sh )
+         CALL iom_put( 'SH_iceextt' , zdiag_extt_sh )
          !
       ENDIF
-      !
-      IF( iom_use('SH_icearea') .OR. iom_use('SH_icevolu') .OR. iom_use('SH_iceextt') )   THEN   ! SH diagnostics
-         !
-         WHERE( ff_t < 0._wp ); zmsk00(:,:) = 1.0e-12; 
-         ELSEWHERE            ; zmsk00(:,:) = 0.
-         END WHERE 
-         zdiag_area_sh = glob_sum( 'icewri', at_i(:,:) * zmsk00(:,:) * e1e2t(:,:) ) 
-         zdiag_volu_sh = glob_sum( 'icewri', vt_i(:,:) * zmsk00(:,:) * e1e2t(:,:) )
-         !
-         WHERE( ff_t < 0._wp .AND. at_i > 0.15 ); zmsk00(:,:) = 1.0e-12
-         ELSEWHERE                              ; zmsk00(:,:) = 0.
-         END WHERE 
-         zdiag_extt_sh = glob_sum( 'icewri', zmsk00(:,:) * e1e2t(:,:) )
-         !
-         IF( iom_use('SH_icearea') ) CALL iom_put( "SH_icearea", zdiag_area_sh )
-         IF( iom_use('SH_icevolu') ) CALL iom_put( "SH_icevolu", zdiag_volu_sh )
-         IF( iom_use('SH_iceextt') ) CALL iom_put( "SH_iceextt", zdiag_extt_sh )
-         !
-      ENDIF 
       !
 !!CR      !     !  Create an output files (output.lim.abort.nc) if S < 0 or u > 20 m/s
 !!CR      !     IF( kindic < 0 )   CALL ice_wri_state( 'output.abort' )
 !!CR      !     not yet implemented
-!!gm  idem for the ocean...  Ask Seb how to get read of ioipsl....
+!!gm  idem for the ocean...  Ask Seb how to get rid of ioipsl....
       !
       IF( ln_timing )  CALL timing_stop('icewri')
Index: /NEMO/trunk/src/NST/agrif_user.F90
===================================================================
--- /NEMO/trunk/src/NST/agrif_user.F90	(revision 11535)
+++ /NEMO/trunk/src/NST/agrif_user.F90	(revision 11536)
@@ -714,8 +714,8 @@
    REWIND( numnam_ref )              ! Namelist namagrif in reference namelist : AGRIF zoom
    READ  ( numnam_ref, namagrif, IOSTAT = ios, ERR = 901)
-901 IF( ios /= 0 )   CALL ctl_nam ( ios , 'namagrif in reference namelist', lwp )
+901 IF( ios /= 0 )   CALL ctl_nam ( ios , 'namagrif in reference namelist' )
    REWIND( numnam_cfg )              ! Namelist namagrif in configuration namelist : AGRIF zoom
    READ  ( numnam_cfg, namagrif, IOSTAT = ios, ERR = 902 )
-902 IF( ios >  0 )   CALL ctl_nam ( ios , 'namagrif in configuration namelist', lwp )
+902 IF( ios >  0 )   CALL ctl_nam ( ios , 'namagrif in configuration namelist' )
    IF(lwm) WRITE ( numond, namagrif )
    !
Index: /NEMO/trunk/src/OCE/ASM/asminc.F90
===================================================================
--- /NEMO/trunk/src/OCE/ASM/asminc.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/ASM/asminc.F90	(revision 11536)
@@ -147,8 +147,8 @@
       REWIND( numnam_ref )              ! Namelist nam_asminc in reference namelist : Assimilation increment
       READ  ( numnam_ref, nam_asminc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_asminc in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_asminc in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist nam_asminc in configuration namelist : Assimilation increment
       READ  ( numnam_cfg, nam_asminc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nam_asminc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nam_asminc in configuration namelist' )
       IF(lwm) WRITE ( numond, nam_asminc )
 
Index: /NEMO/trunk/src/OCE/BDY/bdy_oce.F90
===================================================================
--- /NEMO/trunk/src/OCE/BDY/bdy_oce.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/BDY/bdy_oce.F90	(revision 11536)
@@ -22,8 +22,10 @@
       INTEGER ,          DIMENSION(jpbgrd) ::  nblen
       INTEGER ,          DIMENSION(jpbgrd) ::  nblenrim
+      INTEGER ,          DIMENSION(jpbgrd) ::  nblenrim0
       INTEGER , POINTER, DIMENSION(:,:)    ::  nbi
       INTEGER , POINTER, DIMENSION(:,:)    ::  nbj
       INTEGER , POINTER, DIMENSION(:,:)    ::  nbr
       INTEGER , POINTER, DIMENSION(:,:)    ::  nbmap
+      INTEGER , POINTER, DIMENSION(:,:)    ::  ntreat
       REAL(wp), POINTER, DIMENSION(:,:)    ::  nbw
       REAL(wp), POINTER, DIMENSION(:,:)    ::  nbd
@@ -40,12 +42,9 @@
    TYPE, PUBLIC ::   OBC_DATA     !: Storage for external data
       INTEGER          , DIMENSION(2)   ::  nread
-      LOGICAL                           ::  ll_ssh
-      LOGICAL                           ::  ll_u2d
-      LOGICAL                           ::  ll_v2d
-      LOGICAL                           ::  ll_u3d
-      LOGICAL                           ::  ll_v3d
-      LOGICAL                           ::  ll_tem
-      LOGICAL                           ::  ll_sal
-      LOGICAL                           ::  ll_fvl
+      LOGICAL                           ::  lneed_ssh
+      LOGICAL                           ::  lneed_dyn2d
+      LOGICAL                           ::  lneed_dyn3d
+      LOGICAL                           ::  lneed_tra
+      LOGICAL                           ::  lneed_ice
       REAL(wp), POINTER, DIMENSION(:)   ::  ssh
       REAL(wp), POINTER, DIMENSION(:)   ::  u2d
@@ -55,12 +54,13 @@
       REAL(wp), POINTER, DIMENSION(:,:) ::  tem
       REAL(wp), POINTER, DIMENSION(:,:) ::  sal
-#if defined key_si3
-      LOGICAL                           ::   ll_a_i
-      LOGICAL                           ::   ll_h_i
-      LOGICAL                           ::   ll_h_s
-      REAL(wp), POINTER, DIMENSION(:,:) ::   a_i    !: now ice leads fraction climatology
-      REAL(wp), POINTER, DIMENSION(:,:) ::   h_i    !: Now ice  thickness climatology
-      REAL(wp), POINTER, DIMENSION(:,:) ::   h_s    !: now snow thickness
-#endif
+      REAL(wp), POINTER, DIMENSION(:,:) ::  a_i    !: now ice leads fraction climatology
+      REAL(wp), POINTER, DIMENSION(:,:) ::  h_i    !: Now ice  thickness climatology
+      REAL(wp), POINTER, DIMENSION(:,:) ::  h_s    !: now snow thickness
+      REAL(wp), POINTER, DIMENSION(:,:) ::  t_i    !: now ice  temperature
+      REAL(wp), POINTER, DIMENSION(:,:) ::  t_s    !: now snow temperature
+      REAL(wp), POINTER, DIMENSION(:,:) ::  tsu    !: now surf temperature
+      REAL(wp), POINTER, DIMENSION(:,:) ::  s_i    !: now ice  salinity
+      REAL(wp), POINTER, DIMENSION(:,:) ::  aip    !: now ice  pond concentration
+      REAL(wp), POINTER, DIMENSION(:,:) ::  hip    !: now ice  pond depth
 #if defined key_top
       CHARACTER(LEN=20)                   :: cn_obc  !: type of boundary condition to apply
@@ -74,4 +74,5 @@
    !! Namelist variables
    !!----------------------------------------------------------------------
+   !                                                   !!** nambdy **
    LOGICAL, PUBLIC            ::   ln_bdy                   !: Unstructured Ocean Boundary Condition
 
@@ -85,5 +86,4 @@
    !
    INTEGER                    ::   nb_bdy                   !: number of open boundary sets
-   INTEGER, DIMENSION(jp_bdy) ::   nb_jpk_bdy               !: number of levels in the bdy data (set < 0 if consistent with planned run)
    INTEGER, DIMENSION(jp_bdy) ::   nn_rimwidth              !: boundary rim width for Flow Relaxation Scheme
    INTEGER                    ::   nn_volctl                !: = 0 the total volume will have the variability of the surface Flux E-P 
@@ -108,9 +108,12 @@
    INTEGER , DIMENSION(jp_bdy)          ::   nn_ice_dta     !: = 0 use the initial state as bdy dta ; 
                                                             !: = 1 read it in a NetCDF file
-   REAL(wp), DIMENSION(jp_bdy) ::   rn_ice_tem              !: choice of the temperature of incoming sea ice
-   REAL(wp), DIMENSION(jp_bdy) ::   rn_ice_sal              !: choice of the salinity    of incoming sea ice
-   REAL(wp), DIMENSION(jp_bdy) ::   rn_ice_age              !: choice of the age         of incoming sea ice
+   ! 
+   !                                                   !!** nambdy_dta **
+   REAL(wp), DIMENSION(jp_bdy) ::   rice_tem                !: temperature of incoming sea ice
+   REAL(wp), DIMENSION(jp_bdy) ::   rice_sal                !: salinity    of incoming sea ice
+   REAL(wp), DIMENSION(jp_bdy) ::   rice_age                !: age         of incoming sea ice
+   REAL(wp), DIMENSION(jp_bdy) ::   rice_apnd               !: pond conc.  of incoming sea ice
+   REAL(wp), DIMENSION(jp_bdy) ::   rice_hpnd               !: pond thick. of incoming sea ice
    !
-   
    !!----------------------------------------------------------------------
    !! Global variables
@@ -128,14 +131,14 @@
    INTEGER,  DIMENSION(jp_bdy)                     ::   nn_dta            !: =0 => *all* data is set to initial conditions
                                                                           !: =1 => some data to be read in from data files
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:), TARGET ::   dta_global        !: workspace for reading in global data arrays (unstr.  bdy)
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:), TARGET ::   dta_global_z      !: workspace for reading in global depth arrays (unstr.  bdy)
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:), TARGET ::   dta_global_dz     !: workspace for reading in global depth arrays (unstr.  bdy)
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:), TARGET ::   dta_global2       !: workspace for reading in global data arrays (struct. bdy)
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:), TARGET ::   dta_global2_z     !: workspace for reading in global depth arrays (struct. bdy)
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:), TARGET ::   dta_global2_dz    !: workspace for reading in global depth arrays (struct. bdy)
 !$AGRIF_DO_NOT_TREAT
    TYPE(OBC_INDEX), DIMENSION(jp_bdy), TARGET      ::   idx_bdy           !: bdy indices (local process)
    TYPE(OBC_DATA) , DIMENSION(jp_bdy), TARGET      ::   dta_bdy           !: bdy external data (local process)
 !$AGRIF_END_DO_NOT_TREAT
+   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:,:) ::   lsend_bdy      !: mark needed communication for given boundary, grid and neighbour
+   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:,:) ::   lrecv_bdy      !:  when searching in any direction
+   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:,:) ::   lsend_bdyint   !: mark needed communication for given boundary, grid and neighbour
+   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:,:) ::   lrecv_bdyint   !:  when searching towards the interior of the computational domain
+   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:,:) ::   lsend_bdyext   !: mark needed communication for given boundary, grid and neighbour
+   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:,:) ::   lrecv_bdyext   !:  when searching towards the exterior of the computational domain
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
Index: /NEMO/trunk/src/OCE/BDY/bdydta.F90
===================================================================
--- /NEMO/trunk/src/OCE/BDY/bdydta.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/BDY/bdydta.F90	(revision 11536)
@@ -43,18 +43,28 @@
    PUBLIC   bdy_dta_init     ! routine called by nemogcm.F90
 
-   INTEGER, ALLOCATABLE, DIMENSION(:)   ::   nb_bdy_fld        ! Number of fields to update for each boundary set.
-   INTEGER                              ::   nb_bdy_fld_sum    ! Total number of fields to update for all boundary sets.
-   LOGICAL,           DIMENSION(jp_bdy) ::   ln_full_vel_array ! =T => full velocities in 3D boundary conditions
-                                                               ! =F => baroclinic velocities in 3D boundary conditions
+   INTEGER , PARAMETER ::   jpbdyfld  = 16    ! maximum number of files to read 
+   INTEGER , PARAMETER ::   jp_bdyssh = 1     ! 
+   INTEGER , PARAMETER ::   jp_bdyu2d = 2     ! 
+   INTEGER , PARAMETER ::   jp_bdyv2d = 3     !
+   INTEGER , PARAMETER ::   jp_bdyu3d = 4     !
+   INTEGER , PARAMETER ::   jp_bdyv3d = 5     !
+   INTEGER , PARAMETER ::   jp_bdytem = 6     ! 
+   INTEGER , PARAMETER ::   jp_bdysal = 7     ! 
+   INTEGER , PARAMETER ::   jp_bdya_i = 8     ! 
+   INTEGER , PARAMETER ::   jp_bdyh_i = 9     ! 
+   INTEGER , PARAMETER ::   jp_bdyh_s = 10    ! 
+   INTEGER , PARAMETER ::   jp_bdyt_i = 11    ! 
+   INTEGER , PARAMETER ::   jp_bdyt_s = 12    ! 
+   INTEGER , PARAMETER ::   jp_bdytsu = 13    ! 
+   INTEGER , PARAMETER ::   jp_bdys_i = 14    ! 
+   INTEGER , PARAMETER ::   jp_bdyaip = 15    ! 
+   INTEGER , PARAMETER ::   jp_bdyhip = 16    ! 
+#if ! defined key_si3
+   INTEGER , PARAMETER ::   jpl = 1
+#endif
+
 !$AGRIF_DO_NOT_TREAT
-   TYPE(FLD), PUBLIC, ALLOCATABLE, DIMENSION(:), TARGET ::   bf        ! structure of input fields (file informations, fields read)
+   TYPE(FLD), PUBLIC, ALLOCATABLE, DIMENSION(:,:), TARGET ::   bf   ! structure of input fields (file informations, fields read)
 !$AGRIF_END_DO_NOT_TREAT
-   TYPE(MAP_POINTER), ALLOCATABLE, DIMENSION(:) :: nbmap_ptr   ! array of pointers to nbmap
-
-#if defined key_si3
-   INTEGER ::   nice_cat                      ! number of categories in the input file
-   INTEGER ::   jfld_hti, jfld_hts, jfld_ai   ! indices of ice thickness, snow thickness and concentration in bf structure
-   INTEGER, DIMENSION(jp_bdy) :: jfld_htit, jfld_htst, jfld_ait
-#endif
 
    !!----------------------------------------------------------------------
@@ -65,5 +75,5 @@
 CONTAINS
 
-      SUBROUTINE bdy_dta( kt, jit, time_offset )
+   SUBROUTINE bdy_dta( kt, kit, kt_offset )
       !!----------------------------------------------------------------------
       !!                   ***  SUBROUTINE bdy_dta  ***
@@ -75,17 +85,18 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in)           ::   kt           ! ocean time-step index 
-      INTEGER, INTENT(in), OPTIONAL ::   jit          ! subcycle time-step index (for timesplitting option)
-      INTEGER, INTENT(in), OPTIONAL ::   time_offset  ! time offset in units of timesteps. NB. if jit
+      INTEGER, INTENT(in), OPTIONAL ::   kit          ! subcycle time-step index (for timesplitting option)
+      INTEGER, INTENT(in), OPTIONAL ::   kt_offset    ! time offset in units of timesteps. NB. if kit
       !                                               ! is present then units = subcycle timesteps.
-      !                                               ! time_offset = 0 => get data at "now" time level
-      !                                               ! time_offset = -1 => get data at "before" time level
-      !                                               ! time_offset = +1 => get data at "after" time level
+      !                                               ! kt_offset = 0 => get data at "now" time level
+      !                                               ! kt_offset = -1 => get data at "before" time level
+      !                                               ! kt_offset = +1 => get data at "after" time level
       !                                               ! etc.
       !
-      INTEGER ::  jbdy, jfld, jstart, jend, ib, jl  ! dummy loop indices
-      INTEGER ::  ii, ij, ik, igrd                  ! local integers
-      INTEGER,          DIMENSION(jpbgrd) ::   ilen1 
-      INTEGER, POINTER, DIMENSION(:)      ::   nblen, nblenrim  ! short cuts
-      TYPE(OBC_DATA), POINTER             ::   dta              ! short cut
+      INTEGER ::  jbdy, jfld, jstart, jend, ib, jl    ! dummy loop indices
+      INTEGER ::  ii, ij, ik, igrd, ipl               ! local integers
+      INTEGER,   DIMENSION(jpbgrd)     ::   ilen1 
+      INTEGER,   DIMENSION(:), POINTER ::   nblen, nblenrim  ! short cuts
+      TYPE(OBC_DATA)         , POINTER ::   dta_alias        ! short cut
+      TYPE(FLD), DIMENSION(:), POINTER ::   bf_alias
       !!---------------------------------------------------------------------------
       !
@@ -94,18 +105,17 @@
       ! Initialise data arrays once for all from initial conditions where required
       !---------------------------------------------------------------------------
-      IF( kt == nit000 .AND. .NOT.PRESENT(jit) ) THEN
+      IF( kt == nit000 .AND. .NOT.PRESENT(kit) ) THEN
 
          ! Calculate depth-mean currents
          !-----------------------------
-         
+
          DO jbdy = 1, nb_bdy
             !
             nblen    => idx_bdy(jbdy)%nblen
             nblenrim => idx_bdy(jbdy)%nblenrim
-            dta      => dta_bdy(jbdy)
             !
             IF( nn_dyn2d_dta(jbdy) == 0 ) THEN 
                ilen1(:) = nblen(:)
-               IF( dta%ll_ssh ) THEN 
+               IF( dta_bdy(jbdy)%lneed_ssh ) THEN 
                   igrd = 1
                   DO ib = 1, ilen1(igrd)
@@ -113,7 +123,7 @@
                      ij = idx_bdy(jbdy)%nbj(ib,igrd)
                      dta_bdy(jbdy)%ssh(ib) = sshn(ii,ij) * tmask(ii,ij,1)         
-                  END DO 
-               ENDIF
-               IF( dta%ll_u2d ) THEN 
+                  END DO
+               ENDIF
+               IF( dta_bdy(jbdy)%lneed_dyn2d) THEN 
                   igrd = 2
                   DO ib = 1, ilen1(igrd)
@@ -121,7 +131,5 @@
                      ij = idx_bdy(jbdy)%nbj(ib,igrd)
                      dta_bdy(jbdy)%u2d(ib) = un_b(ii,ij) * umask(ii,ij,1)         
-                  END DO 
-               ENDIF
-               IF( dta%ll_v2d ) THEN 
+                  END DO
                   igrd = 3
                   DO ib = 1, ilen1(igrd)
@@ -129,5 +137,5 @@
                      ij = idx_bdy(jbdy)%nbj(ib,igrd)
                      dta_bdy(jbdy)%v2d(ib) = vn_b(ii,ij) * vmask(ii,ij,1)         
-                  END DO 
+                  END DO
                ENDIF
             ENDIF
@@ -135,5 +143,5 @@
             IF( nn_dyn3d_dta(jbdy) == 0 ) THEN 
                ilen1(:) = nblen(:)
-               IF( dta%ll_u3d ) THEN 
+               IF( dta_bdy(jbdy)%lneed_dyn3d ) THEN 
                   igrd = 2 
                   DO ib = 1, ilen1(igrd)
@@ -143,7 +151,5 @@
                         dta_bdy(jbdy)%u3d(ib,ik) =  ( un(ii,ij,ik) - un_b(ii,ij) ) * umask(ii,ij,ik)         
                      END DO
-                  END DO 
-               ENDIF
-               IF( dta%ll_v3d ) THEN 
+                  END DO
                   igrd = 3 
                   DO ib = 1, ilen1(igrd)
@@ -152,6 +158,6 @@
                         ij = idx_bdy(jbdy)%nbj(ib,igrd)
                         dta_bdy(jbdy)%v3d(ib,ik) =  ( vn(ii,ij,ik) - vn_b(ii,ij) ) * vmask(ii,ij,ik)         
-                        END DO
-                  END DO 
+                     END DO
+                  END DO
                ENDIF
             ENDIF
@@ -159,5 +165,5 @@
             IF( nn_tra_dta(jbdy) == 0 ) THEN 
                ilen1(:) = nblen(:)
-               IF( dta%ll_tem ) THEN
+               IF( dta_bdy(jbdy)%lneed_tra ) THEN
                   igrd = 1 
                   DO ib = 1, ilen1(igrd)
@@ -165,17 +171,8 @@
                         ii = idx_bdy(jbdy)%nbi(ib,igrd)
                         ij = idx_bdy(jbdy)%nbj(ib,igrd)
-                        dta_bdy(jbdy)%tem(ib,ik) = tsn(ii,ij,ik,jp_tem) * tmask(ii,ij,ik)         
+                        dta_bdy(jbdy)%tem(ib,ik) = tsn(ii,ij,ik,jp_bdytem) * tmask(ii,ij,ik)         
+                        dta_bdy(jbdy)%sal(ib,ik) = tsn(ii,ij,ik,jp_bdysal) * tmask(ii,ij,ik)         
                      END DO
-                  END DO 
-               ENDIF
-               IF( dta%ll_sal ) THEN
-                  igrd = 1 
-                  DO ib = 1, ilen1(igrd)
-                     DO ik = 1, jpkm1
-                        ii = idx_bdy(jbdy)%nbi(ib,igrd)
-                        ij = idx_bdy(jbdy)%nbj(ib,igrd)
-                        dta_bdy(jbdy)%sal(ib,ik) = tsn(ii,ij,ik,jp_sal) * tmask(ii,ij,ik)         
-                     END DO
-                  END DO 
+                  END DO
                ENDIF
             ENDIF
@@ -184,5 +181,5 @@
             IF( nn_ice_dta(jbdy) == 0 ) THEN    ! set ice to initial values
                ilen1(:) = nblen(:)
-               IF( dta%ll_a_i ) THEN
+               IF( dta_bdy(jbdy)%lneed_ice ) THEN
                   igrd = 1   
                   DO jl = 1, jpl
@@ -190,25 +187,14 @@
                         ii = idx_bdy(jbdy)%nbi(ib,igrd)
                         ij = idx_bdy(jbdy)%nbj(ib,igrd)
-                        dta_bdy(jbdy)%a_i (ib,jl) =  a_i(ii,ij,jl) * tmask(ii,ij,1) 
-                     END DO
-                  END DO
-               ENDIF
-               IF( dta%ll_h_i ) THEN
-                  igrd = 1   
-                  DO jl = 1, jpl
-                     DO ib = 1, ilen1(igrd)
-                        ii = idx_bdy(jbdy)%nbi(ib,igrd)
-                        ij = idx_bdy(jbdy)%nbj(ib,igrd)
-                        dta_bdy(jbdy)%h_i (ib,jl) =  h_i(ii,ij,jl) * tmask(ii,ij,1) 
-                     END DO
-                  END DO
-               ENDIF
-               IF( dta%ll_h_s ) THEN
-                  igrd = 1   
-                  DO jl = 1, jpl
-                     DO ib = 1, ilen1(igrd)
-                        ii = idx_bdy(jbdy)%nbi(ib,igrd)
-                        ij = idx_bdy(jbdy)%nbj(ib,igrd)
-                        dta_bdy(jbdy)%h_s (ib,jl) =  h_s(ii,ij,jl) * tmask(ii,ij,1) 
+                        dta_bdy(jbdy)%a_i(ib,jl) =  a_i (ii,ij,jl) * tmask(ii,ij,1) 
+                        dta_bdy(jbdy)%h_i(ib,jl) =  h_i (ii,ij,jl) * tmask(ii,ij,1) 
+                        dta_bdy(jbdy)%h_s(ib,jl) =  h_s (ii,ij,jl) * tmask(ii,ij,1) 
+                        dta_bdy(jbdy)%t_i(ib,jl) =  SUM(t_i (ii,ij,:,jl)) * r1_nlay_i * tmask(ii,ij,1) 
+                        dta_bdy(jbdy)%t_s(ib,jl) =  SUM(t_s (ii,ij,:,jl)) * r1_nlay_s * tmask(ii,ij,1)
+                        dta_bdy(jbdy)%tsu(ib,jl) =  t_su(ii,ij,jl) * tmask(ii,ij,1) 
+                        dta_bdy(jbdy)%s_i(ib,jl) =  s_i (ii,ij,jl) * tmask(ii,ij,1)
+                        ! melt ponds
+                        dta_bdy(jbdy)%aip(ib,jl) =  a_ip(ii,ij,jl) * tmask(ii,ij,1) 
+                        dta_bdy(jbdy)%hip(ib,jl) =  h_ip(ii,ij,jl) * tmask(ii,ij,1) 
                      END DO
                   END DO
@@ -222,183 +208,154 @@
       ! update external data from files
       !--------------------------------
-     
-      jstart = 1
-      DO jbdy = 1, nb_bdy   
-         dta => dta_bdy(jbdy)
-         IF( nn_dta(jbdy) == 1 ) THEN ! skip this bit if no external data required
-      
-            IF( PRESENT(jit) ) THEN
-               ! Update barotropic boundary conditions only
-               ! jit is optional argument for fld_read and bdytide_update
-               IF( cn_dyn2d(jbdy) /= 'none' ) THEN
-                  IF( nn_dyn2d_dta(jbdy) == 2 ) THEN ! tidal harmonic forcing ONLY: initialise arrays
-                     IF( dta%ll_ssh ) dta%ssh(:) = 0._wp
-                     IF( dta%ll_u2d ) dta%u2d(:) = 0._wp
-                     IF( dta%ll_u3d ) dta%v2d(:) = 0._wp
-                  ENDIF
-                  IF (cn_tra(jbdy) /= 'runoff') THEN
-                     IF( nn_dyn2d_dta(jbdy) == 1 .OR. nn_dyn2d_dta(jbdy) == 3 ) THEN
-
-                        jend = jstart + dta%nread(2) - 1
-                        IF( ln_full_vel_array(jbdy) ) THEN
-                           CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend), map=nbmap_ptr(jstart:jend),  &
-                                     & kit=jit, kt_offset=time_offset , jpk_bdy=nb_jpk_bdy(jbdy),   &
-                                     & fvl=ln_full_vel_array(jbdy)  )
-                        ELSE
-                           CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend), map=nbmap_ptr(jstart:jend),  &
-                                     & kit=jit, kt_offset=time_offset  )
-                        ENDIF
-
-                        ! If full velocities in boundary data then extract barotropic velocities from 3D fields
-                        IF( ln_full_vel_array(jbdy) .AND.                                             &
-                          &    ( nn_dyn2d_dta(jbdy) == 1 .OR. nn_dyn2d_dta(jbdy) == 3 .OR.  &
-                          &      nn_dyn3d_dta(jbdy) == 1 ) )THEN
-
-                           igrd = 2                      ! zonal velocity
-                           dta%u2d(:) = 0._wp
-                           DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
-                              ii   = idx_bdy(jbdy)%nbi(ib,igrd)
-                              ij   = idx_bdy(jbdy)%nbj(ib,igrd)
-                              DO ik = 1, jpkm1
-                                 dta%u2d(ib) = dta%u2d(ib) &
-                       &                          + e3u_n(ii,ij,ik) * umask(ii,ij,ik) * dta%u3d(ib,ik)
-                              END DO
-                              dta%u2d(ib) =  dta%u2d(ib) * r1_hu_n(ii,ij)
-                           END DO
-                           igrd = 3                      ! meridional velocity
-                           dta%v2d(:) = 0._wp
-                           DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
-                              ii   = idx_bdy(jbdy)%nbi(ib,igrd)
-                              ij   = idx_bdy(jbdy)%nbj(ib,igrd)
-                              DO ik = 1, jpkm1
-                                 dta%v2d(ib) = dta%v2d(ib) &
-                       &                       + e3v_n(ii,ij,ik) * vmask(ii,ij,ik) * dta%v3d(ib,ik)
-                              END DO
-                              dta%v2d(ib) =  dta%v2d(ib) * r1_hv_n(ii,ij)
-                           END DO
-                        ENDIF                    
-                     ENDIF
-                     IF( nn_dyn2d_dta(jbdy) .ge. 2 ) THEN ! update tidal harmonic forcing
-                        CALL bdytide_update( kt=kt, idx=idx_bdy(jbdy), dta=dta, td=tides(jbdy),   & 
-                          &                 jit=jit, time_offset=time_offset )
-                     ENDIF
-                  ENDIF
-               ENDIF
-            ELSE
-               IF (cn_tra(jbdy) == 'runoff') then      ! runoff condition
-                  jend = nb_bdy_fld(jbdy)
-                  CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend),  &
-                               & map=nbmap_ptr(jstart:jend), kt_offset=time_offset )
-                  !
-                  igrd = 2                      ! zonal velocity
-                  DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
-                     ii   = idx_bdy(jbdy)%nbi(ib,igrd)
-                     ij   = idx_bdy(jbdy)%nbj(ib,igrd)
-                     dta%u2d(ib) = dta%u2d(ib) / ( e2u(ii,ij) * hu_0(ii,ij) )
-                  END DO
-                  !
-                  igrd = 3                      ! meridional velocity
-                  DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
-                     ii   = idx_bdy(jbdy)%nbi(ib,igrd)
-                     ij   = idx_bdy(jbdy)%nbj(ib,igrd)
-                     dta%v2d(ib) = dta%v2d(ib) / ( e1v(ii,ij) * hv_0(ii,ij) )
-                  END DO
-               ELSE
-                  IF( nn_dyn2d_dta(jbdy) == 2 ) THEN ! tidal harmonic forcing ONLY: initialise arrays
-                     IF( dta%ll_ssh ) dta%ssh(:) = 0._wp
-                     IF( dta%ll_u2d ) dta%u2d(:) = 0._wp
-                     IF( dta%ll_v2d ) dta%v2d(:) = 0._wp
-                  ENDIF
-                  IF( dta%nread(1) .gt. 0 ) THEN ! update external data
-                     jend = jstart + dta%nread(1) - 1
-                     CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend), &
-                                  & map=nbmap_ptr(jstart:jend), kt_offset=time_offset, jpk_bdy=nb_jpk_bdy(jbdy),   &
-                                  & fvl=ln_full_vel_array(jbdy) )
-                  ENDIF
-                  ! If full velocities in boundary data then split into barotropic and baroclinic data
-                  IF( ln_full_vel_array(jbdy) .and.                                             &
-                    & ( nn_dyn2d_dta(jbdy) == 1 .OR. nn_dyn2d_dta(jbdy) == 3 .OR. &
-                    &   nn_dyn3d_dta(jbdy) == 1 ) ) THEN
-                     igrd = 2                      ! zonal velocity
-                     dta%u2d(:) = 0._wp
-                     DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
-                        ii   = idx_bdy(jbdy)%nbi(ib,igrd)
-                        ij   = idx_bdy(jbdy)%nbj(ib,igrd)
-                        DO ik = 1, jpkm1
-                           dta%u2d(ib) = dta%u2d(ib) &
-                 &                       + e3u_n(ii,ij,ik) * umask(ii,ij,ik) * dta%u3d(ib,ik)
-                        END DO
-                        dta%u2d(ib) =  dta%u2d(ib) * r1_hu_n(ii,ij)
-                        DO ik = 1, jpkm1
-                           dta%u3d(ib,ik) = dta%u3d(ib,ik) - dta%u2d(ib)
-                        END DO
-                     END DO
-                     igrd = 3                      ! meridional velocity
-                     dta%v2d(:) = 0._wp
-                     DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
-                        ii   = idx_bdy(jbdy)%nbi(ib,igrd)
-                        ij   = idx_bdy(jbdy)%nbj(ib,igrd)
-                        DO ik = 1, jpkm1
-                           dta%v2d(ib) = dta%v2d(ib) &
-                 &                       + e3v_n(ii,ij,ik) * vmask(ii,ij,ik) * dta%v3d(ib,ik)
-                        END DO
-                        dta%v2d(ib) =  dta%v2d(ib) * r1_hv_n(ii,ij)
-                        DO ik = 1, jpkm1
-                           dta%v3d(ib,ik) = dta%v3d(ib,ik) - dta%v2d(ib)
-                        END DO
-                     END DO
-                  ENDIF
-
-               ENDIF
+
+      DO jbdy = 1, nb_bdy
+
+         dta_alias => dta_bdy(jbdy)
+         bf_alias  => bf(:,jbdy)
+
+         ! read/update all bdy data
+         ! ------------------------
+         CALL fld_read( kt, 1, bf_alias, kit = kit, kt_offset = kt_offset )
+
+         ! apply some corrections in some specific cases...
+         ! --------------------------------------------------
+         !
+         ! if runoff condition: change river flow we read (in m3/s) into barotropic velocity (m/s)
+         IF( cn_tra(jbdy) == 'runoff' .AND. TRIM(bf_alias(jp_bdyu2d)%clrootname) /= 'NOT USED' ) THEN   ! runoff and we read u/v2d
+            !
+            igrd = 2                      ! zonal flow (m3/s) to barotropic zonal velocity (m/s)
+            DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
+               ii   = idx_bdy(jbdy)%nbi(ib,igrd)
+               ij   = idx_bdy(jbdy)%nbj(ib,igrd)
+               dta_alias%u2d(ib) = dta_alias%u2d(ib) / ( e2u(ii,ij) * hu_0(ii,ij) )
+            END DO
+            igrd = 3                      ! meridional flow (m3/s) to barotropic meridional velocity (m/s)
+            DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
+               ii   = idx_bdy(jbdy)%nbi(ib,igrd)
+               ij   = idx_bdy(jbdy)%nbj(ib,igrd)
+               dta_alias%v2d(ib) = dta_alias%v2d(ib) / ( e1v(ii,ij) * hv_0(ii,ij) )
+            END DO
+         ENDIF
+
+         ! tidal harmonic forcing ONLY: initialise arrays
+         IF( nn_dyn2d_dta(jbdy) == 2 ) THEN   ! we did not read ssh, u/v2d 
+            IF( dta_alias%lneed_ssh   ) dta_alias%ssh(:) = 0._wp
+            IF( dta_alias%lneed_dyn2d ) dta_alias%u2d(:) = 0._wp
+            IF( dta_alias%lneed_dyn2d ) dta_alias%v2d(:) = 0._wp
+         ENDIF
+
+         ! If full velocities in boundary data, then split it into barotropic and baroclinic component
+         IF( bf_alias(jp_bdyu3d)%ltotvel ) THEN     ! if we read 3D total velocity (can be true only if u3d was read)
+            !
+            igrd = 2                       ! zonal velocity
+            dta_alias%u2d(:) = 0._wp       ! compute barotrope zonal velocity and put it in u2d
+            DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
+               ii   = idx_bdy(jbdy)%nbi(ib,igrd)
+               ij   = idx_bdy(jbdy)%nbj(ib,igrd)
+               DO ik = 1, jpkm1
+                  dta_alias%u2d(ib) = dta_alias%u2d(ib) + e3u_n(ii,ij,ik) * umask(ii,ij,ik) * dta_alias%u3d(ib,ik)
+               END DO
+               dta_alias%u2d(ib) =  dta_alias%u2d(ib) * r1_hu_n(ii,ij)
+               DO ik = 1, jpkm1            ! compute barocline zonal velocity and put it in u3d
+                  dta_alias%u3d(ib,ik) = dta_alias%u3d(ib,ik) - dta_alias%u2d(ib)
+               END DO
+            END DO
+            igrd = 3                       ! meridional velocity
+            dta_alias%v2d(:) = 0._wp       ! compute barotrope meridional velocity and put it in v2d
+            DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
+               ii   = idx_bdy(jbdy)%nbi(ib,igrd)
+               ij   = idx_bdy(jbdy)%nbj(ib,igrd)
+               DO ik = 1, jpkm1
+                  dta_alias%v2d(ib) = dta_alias%v2d(ib) + e3v_n(ii,ij,ik) * vmask(ii,ij,ik) * dta_alias%v3d(ib,ik)
+               END DO
+               dta_alias%v2d(ib) =  dta_alias%v2d(ib) * r1_hv_n(ii,ij)
+               DO ik = 1, jpkm1            ! compute barocline meridional velocity and put it in v3d
+                  dta_alias%v3d(ib,ik) = dta_alias%v3d(ib,ik) - dta_alias%v2d(ib)
+               END DO
+            END DO
+         ENDIF   ! ltotvel
+
+         ! update tidal harmonic forcing
+         IF( PRESENT(kit) .AND. nn_dyn2d_dta(jbdy) .GE. 2 ) THEN
+            CALL bdytide_update( kt = kt, idx = idx_bdy(jbdy), dta = dta_alias, td = tides(jbdy),   & 
+               &                 kit = kit, kt_offset = kt_offset )
+         ENDIF
+
+         !  atm surface pressure : add inverted barometer effect to ssh if it was read
+         IF ( ln_apr_obc .AND. TRIM(bf_alias(jp_bdyssh)%clrootname) /= 'NOT USED' ) THEN
+            igrd = 1
+            DO ib = 1, idx_bdy(jbdy)%nblenrim(igrd)   ! ssh is used only on the rim
+               ii   = idx_bdy(jbdy)%nbi(ib,igrd)
+               ij   = idx_bdy(jbdy)%nbj(ib,igrd)
+               dta_alias%ssh(ib) = dta_alias%ssh(ib) + ssh_ib(ii,ij)
+            END DO
+         ENDIF
+
 #if defined key_si3
-               ! convert N-cat fields (input) into jpl-cat (output)
-               IF( cn_ice(jbdy) /= 'none' .AND. nn_ice_dta(jbdy) == 1 ) THEN
-                  jfld_hti = jfld_htit(jbdy)
-                  jfld_hts = jfld_htst(jbdy)
-                  jfld_ai  = jfld_ait(jbdy)
-                  CALL ice_var_itd( bf(jfld_hti)%fnow(:,1,:), bf(jfld_hts)%fnow(:,1,:), bf(jfld_ai)%fnow(:,1,:), &
-                     &              dta_bdy(jbdy)%h_i       , dta_bdy(jbdy)%h_s       , dta_bdy(jbdy)%a_i      )
-               ENDIF
+         IF( dta_alias%lneed_ice ) THEN
+            ! fill temperature and salinity arrays
+            IF( TRIM(bf_alias(jp_bdyt_i)%clrootname) == 'NOT USED' )   bf_alias(jp_bdyt_i)%fnow(:,1,:) = rice_tem (jbdy)
+            IF( TRIM(bf_alias(jp_bdyt_s)%clrootname) == 'NOT USED' )   bf_alias(jp_bdyt_s)%fnow(:,1,:) = rice_tem (jbdy)
+            IF( TRIM(bf_alias(jp_bdytsu)%clrootname) == 'NOT USED' )   bf_alias(jp_bdytsu)%fnow(:,1,:) = rice_tem (jbdy)
+            IF( TRIM(bf_alias(jp_bdys_i)%clrootname) == 'NOT USED' )   bf_alias(jp_bdys_i)%fnow(:,1,:) = rice_sal (jbdy)
+            IF( TRIM(bf_alias(jp_bdyaip)%clrootname) == 'NOT USED' )   bf_alias(jp_bdyaip)%fnow(:,1,:) = rice_apnd(jbdy) * & ! rice_apnd is the pond fraction
+               &                                                                         bf_alias(jp_bdya_i)%fnow(:,1,:)     !   ( a_ip = rice_apnd * a_i )
+            IF( TRIM(bf_alias(jp_bdyhip)%clrootname) == 'NOT USED' )   bf_alias(jp_bdyhip)%fnow(:,1,:) = rice_hpnd(jbdy)
+            ! if T_su is read and not T_i, set T_i = (T_su + T_freeze)/2
+            IF( TRIM(bf_alias(jp_bdytsu)%clrootname) /= 'NOT USED' .AND. TRIM(bf_alias(jp_bdyt_i)%clrootname) == 'NOT USED' ) &
+               &   bf_alias(jp_bdyt_i)%fnow(:,1,:) = 0.5_wp * ( bf_alias(jp_bdytsu)%fnow(:,1,:) + 271.15 )
+            ! if T_su is read and not T_s, set T_s = T_su
+            IF( TRIM(bf_alias(jp_bdytsu)%clrootname) /= 'NOT USED' .AND. TRIM(bf_alias(jp_bdyt_s)%clrootname) == 'NOT USED' ) &
+               &   bf_alias(jp_bdyt_s)%fnow(:,1,:) = bf_alias(jp_bdytsu)%fnow(:,1,:)
+            ! if T_s is read and not T_su, set T_su = T_s
+            IF( TRIM(bf_alias(jp_bdyt_s)%clrootname) /= 'NOT USED' .AND. TRIM(bf_alias(jp_bdytsu)%clrootname) == 'NOT USED' ) &
+               &   bf_alias(jp_bdytsu)%fnow(:,1,:) = bf_alias(jp_bdyt_s)%fnow(:,1,:)
+            ! if T_s is read and not T_i, set T_i = (T_s + T_freeze)/2
+            IF( TRIM(bf_alias(jp_bdyt_s)%clrootname) /= 'NOT USED' .AND. TRIM(bf_alias(jp_bdyt_i)%clrootname) == 'NOT USED' ) &
+               &   bf_alias(jp_bdyt_i)%fnow(:,1,:) = 0.5_wp * ( bf_alias(jp_bdyt_s)%fnow(:,1,:) + 271.15 )
+
+            ! make sure ponds = 0 if no ponds scheme
+            IF ( .NOT.ln_pnd ) THEN
+               bf_alias(jp_bdyaip)%fnow(:,1,:) = 0._wp
+               bf_alias(jp_bdyhip)%fnow(:,1,:) = 0._wp
+            ENDIF
+            
+            ! convert N-cat fields (input) into jpl-cat (output)
+            ipl = SIZE(bf_alias(jp_bdya_i)%fnow, 3)            
+            IF( ipl /= jpl ) THEN      ! ice: convert N-cat fields (input) into jpl-cat (output)
+               CALL ice_var_itd( bf_alias(jp_bdyh_i)%fnow(:,1,:), bf_alias(jp_bdyh_s)%fnow(:,1,:), bf_alias(jp_bdya_i)%fnow(:,1,:), &
+                  &              dta_alias%h_i                  , dta_alias%h_s                  , dta_alias%a_i                  , &
+                  &              bf_alias(jp_bdyt_i)%fnow(:,1,:), bf_alias(jp_bdyt_s)%fnow(:,1,:), &
+                  &              bf_alias(jp_bdytsu)%fnow(:,1,:), bf_alias(jp_bdys_i)%fnow(:,1,:), &
+                  &              bf_alias(jp_bdyaip)%fnow(:,1,:), bf_alias(jp_bdyhip)%fnow(:,1,:), &
+                  &              dta_alias%t_i                  , dta_alias%t_s                  , &
+                  &              dta_alias%tsu                  , dta_alias%s_i                  , &
+                  &              dta_alias%aip                  , dta_alias%hip )
+            ENDIF
+         ENDIF
 #endif
-            ENDIF
-            jstart = jstart + dta%nread(1)
-         ENDIF    ! nn_dta(jbdy) = 1
       END DO  ! jbdy
-
-      IF ( ln_apr_obc ) THEN
-         DO jbdy = 1, nb_bdy
-            IF (cn_tra(jbdy) /= 'runoff')THEN
-               igrd = 1                      ! meridional velocity
-               DO ib = 1, idx_bdy(jbdy)%nblenrim(igrd)
-                  ii   = idx_bdy(jbdy)%nbi(ib,igrd)
-                  ij   = idx_bdy(jbdy)%nbj(ib,igrd)
-                  dta_bdy(jbdy)%ssh(ib) = dta_bdy(jbdy)%ssh(ib) + ssh_ib(ii,ij)
-               END DO
-            ENDIF
-         END DO
-      ENDIF
 
       IF ( ln_tide ) THEN
          IF (ln_dynspg_ts) THEN      ! Fill temporary arrays with slow-varying bdy data                           
-            DO jbdy = 1, nb_bdy    ! Tidal component added in ts loop
-               IF ( nn_dyn2d_dta(jbdy) .ge. 2 ) THEN
+            DO jbdy = 1, nb_bdy      ! Tidal component added in ts loop
+               IF ( nn_dyn2d_dta(jbdy) .GE. 2 ) THEN
                   nblen => idx_bdy(jbdy)%nblen
                   nblenrim => idx_bdy(jbdy)%nblenrim
-                  IF( cn_dyn2d(jbdy) == 'frs' ) THEN; ilen1(:)=nblen(:) ; ELSE ; ilen1(:)=nblenrim(:) ; ENDIF 
-                  IF ( dta_bdy(jbdy)%ll_ssh ) dta_bdy_s(jbdy)%ssh(1:ilen1(1)) = dta_bdy(jbdy)%ssh(1:ilen1(1))
-                  IF ( dta_bdy(jbdy)%ll_u2d ) dta_bdy_s(jbdy)%u2d(1:ilen1(2)) = dta_bdy(jbdy)%u2d(1:ilen1(2))
-                  IF ( dta_bdy(jbdy)%ll_v2d ) dta_bdy_s(jbdy)%v2d(1:ilen1(3)) = dta_bdy(jbdy)%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
-
-      !
-      IF( ln_timing )   CALL timing_stop('bdy_dta')
-      !
-   END SUBROUTINE bdy_dta
+                  IF( cn_dyn2d(jbdy) == 'frs' ) THEN ; ilen1(:)=nblen(:) ; ELSE ; ilen1(:)=nblenrim(:) ; ENDIF 
+                     IF ( dta_bdy(jbdy)%lneed_ssh   ) dta_bdy_s(jbdy)%ssh(1:ilen1(1)) = dta_bdy(jbdy)%ssh(1:ilen1(1))
+                     IF ( dta_bdy(jbdy)%lneed_dyn2d ) dta_bdy_s(jbdy)%u2d(1:ilen1(2)) = dta_bdy(jbdy)%u2d(1:ilen1(2))
+                     IF ( dta_bdy(jbdy)%lneed_dyn2d ) dta_bdy_s(jbdy)%v2d(1:ilen1(3)) = dta_bdy(jbdy)%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, kt_offset=kt_offset )
+            ENDIF
+         ENDIF
+         !
+         IF( ln_timing )   CALL timing_stop('bdy_dta')
+         !
+      END SUBROUTINE bdy_dta
 
 
@@ -413,33 +370,32 @@
       !!                
       !!----------------------------------------------------------------------
-      INTEGER ::   jbdy, jfld, jstart, jend, ierror, ios     ! Local integers
+      INTEGER ::   jbdy, jfld    ! Local integers
+      INTEGER ::   ierror, ios     ! 
       !
+      CHARACTER(len=3)                       ::   cl3           ! 
       CHARACTER(len=100)                     ::   cn_dir        ! Root directory for location of data files
-      CHARACTER(len=100), DIMENSION(nb_bdy)  ::   cn_dir_array  ! Root directory for location of data files
-      CHARACTER(len = 256)::   clname                           ! temporary file name
       LOGICAL                                ::   ln_full_vel   ! =T => full velocities in 3D boundary data
       !                                                         ! =F => baroclinic velocities in 3D boundary data
-      INTEGER                                ::   ilen_global   ! Max length required for global bdy dta arrays
-      INTEGER, ALLOCATABLE, DIMENSION(:)     ::   ilen1, ilen3  ! size of 1st and 3rd dimensions of local arrays
-      INTEGER, ALLOCATABLE, DIMENSION(:)     ::   ibdy           ! bdy set for a particular jfld
-      INTEGER, ALLOCATABLE, DIMENSION(:)     ::   igrid         ! index for grid type (1,2,3 = T,U,V)
-      INTEGER, POINTER, DIMENSION(:)         ::   nblen, nblenrim  ! short cuts
-      TYPE(OBC_DATA), POINTER                ::   dta           ! short cut
-#if defined key_si3
-      INTEGER               ::   kndims   ! number of dimensions in an array (i.e. 3 = wo ice cat; 4 = w ice cat)
-      INTEGER, DIMENSION(4) ::   kdimsz   ! size   of dimensions
-      INTEGER               ::   inum,id1 ! local integer
-#endif
-      TYPE(FLD_N), ALLOCATABLE, DIMENSION(:) ::   blf_i         !  array of namelist information structures
-      TYPE(FLD_N) ::   bn_tem, bn_sal, bn_u3d, bn_v3d   ! 
-      TYPE(FLD_N) ::   bn_ssh, bn_u2d, bn_v2d           ! informations about the fields to be read
-#if defined key_si3
-      TYPE(FLD_N) ::   bn_a_i, bn_h_i, bn_h_s      
-#endif
+      LOGICAL                                ::   ln_zinterp    ! =T => requires a vertical interpolation of the bdydta
+      REAL(wp)                               ::   rn_ice_tem, rn_ice_sal, rn_ice_age, rn_ice_apnd, rn_ice_hpnd 
+      INTEGER                                ::   ipk,ipl       !
+      INTEGER                                ::   idvar         ! variable ID
+      INTEGER                                ::   indims        ! number of dimensions of the variable
+      INTEGER                                ::   iszdim        ! number of dimensions of the variable
+      INTEGER, DIMENSION(4)                  ::   i4dimsz       ! size of variable dimensions 
+      INTEGER                                ::   igrd          ! index for grid type (1,2,3 = T,U,V)
+      LOGICAL                                ::   lluld         ! is the variable using the unlimited dimension
+      LOGICAL                                ::   llneed        !
+      LOGICAL                                ::   llread        !
+      TYPE(FLD_N), DIMENSION(1), TARGET  ::   bn_tem, bn_sal, bn_u3d, bn_v3d   ! must be an array to be used with fld_fill
+      TYPE(FLD_N), DIMENSION(1), TARGET  ::   bn_ssh, bn_u2d, bn_v2d           ! informations about the fields to be read
+      TYPE(FLD_N), DIMENSION(1), TARGET  ::   bn_a_i, bn_h_i, bn_h_s, bn_t_i, bn_t_s, bn_tsu, bn_s_i, bn_aip, bn_hip       
+      TYPE(FLD_N), DIMENSION(:), POINTER ::   bn_alias                        ! must be an array to be used with fld_fill
+      TYPE(FLD  ), DIMENSION(:), POINTER ::   bf_alias
+      !
       NAMELIST/nambdy_dta/ cn_dir, bn_tem, bn_sal, bn_u3d, bn_v3d, bn_ssh, bn_u2d, bn_v2d 
-#if defined key_si3
-      NAMELIST/nambdy_dta/ bn_a_i, bn_h_i, bn_h_s
-#endif
-      NAMELIST/nambdy_dta/ ln_full_vel
+      NAMELIST/nambdy_dta/ bn_a_i, bn_h_i, bn_h_s, bn_t_i, bn_t_s, bn_tsu, bn_s_i, bn_aip, bn_hip
+      NAMELIST/nambdy_dta/ rn_ice_tem, rn_ice_sal, rn_ice_age, rn_ice_apnd, rn_ice_hpnd
+      NAMELIST/nambdy_dta/ ln_full_vel, ln_zinterp
       !!---------------------------------------------------------------------------
       !
@@ -449,389 +405,288 @@
       IF(lwp) WRITE(numout,*) ''
 
-      ! Set nn_dta
-      DO jbdy = 1, nb_bdy
-         nn_dta(jbdy) = MAX(   nn_dyn2d_dta  (jbdy)    &
-            &                , nn_dyn3d_dta  (jbdy)    &
-            &                , nn_tra_dta    (jbdy)    &
-#if defined key_si3
-            &                , nn_ice_dta    (jbdy)    &
-#endif
-                              )
-         IF(nn_dta(jbdy) > 1)   nn_dta(jbdy) = 1
-      END DO
-
-      ! Work out upper bound of how many fields there are to read in and allocate arrays
-      ! ---------------------------------------------------------------------------
-      ALLOCATE( nb_bdy_fld(nb_bdy) )
-      nb_bdy_fld(:) = 0
-      DO jbdy = 1, nb_bdy         
-         IF( cn_dyn2d(jbdy) /= 'none' .AND. ( nn_dyn2d_dta(jbdy) == 1 .or. nn_dyn2d_dta(jbdy) == 3 ) ) THEN
-            nb_bdy_fld(jbdy) = nb_bdy_fld(jbdy) + 3
-         ENDIF
-         IF( cn_dyn3d(jbdy) /= 'none' .AND. nn_dyn3d_dta(jbdy) == 1 ) THEN
-            nb_bdy_fld(jbdy) = nb_bdy_fld(jbdy) + 2
-         ENDIF
-         IF( cn_tra(jbdy) /= 'none' .AND. nn_tra_dta(jbdy) == 1  ) THEN
-            nb_bdy_fld(jbdy) = nb_bdy_fld(jbdy) + 2
-         ENDIF
-#if defined key_si3
-         IF( cn_ice(jbdy) /= 'none' .AND. nn_ice_dta(jbdy) == 1  ) THEN
-            nb_bdy_fld(jbdy) = nb_bdy_fld(jbdy) + 3
-         ENDIF
-#endif               
-         IF(lwp) WRITE(numout,*) 'Maximum number of files to open =', nb_bdy_fld(jbdy)
-      END DO            
-
-      nb_bdy_fld_sum = SUM( nb_bdy_fld )
-
-      ALLOCATE( bf(nb_bdy_fld_sum), STAT=ierror )
+      ALLOCATE( bf(jpbdyfld,nb_bdy), STAT=ierror )
       IF( ierror > 0 ) THEN   
          CALL ctl_stop( 'bdy_dta: unable to allocate bf structure' )   ;   RETURN  
       ENDIF
-      ALLOCATE( blf_i(nb_bdy_fld_sum), STAT=ierror )
-      IF( ierror > 0 ) THEN   
-         CALL ctl_stop( 'bdy_dta: unable to allocate blf_i structure' )   ;   RETURN  
-      ENDIF
-      ALLOCATE( nbmap_ptr(nb_bdy_fld_sum), STAT=ierror )
-      IF( ierror > 0 ) THEN   
-         CALL ctl_stop( 'bdy_dta: unable to allocate nbmap_ptr structure' )   ;   RETURN  
-      ENDIF
-      ALLOCATE( ilen1(nb_bdy_fld_sum), ilen3(nb_bdy_fld_sum) ) 
-      ALLOCATE( ibdy(nb_bdy_fld_sum) ) 
-      ALLOCATE( igrid(nb_bdy_fld_sum) ) 
-
+      bf(:,:)%clrootname = 'NOT USED'   ! default definition used as a flag in fld_read to do nothing.
+      bf(:,:)%lzint      = .FALSE.      ! default definition
+      bf(:,:)%ltotvel    = .FALSE.      ! default definition
+ 
       ! Read namelists
       ! --------------
       REWIND(numnam_cfg)
-      jfld = 0 
-      DO jbdy = 1, nb_bdy         
-         IF( nn_dta(jbdy) == 1 ) THEN
-            REWIND(numnam_ref)
-            READ  ( numnam_ref, nambdy_dta, IOSTAT = ios, ERR = 901)
-901         IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy_dta in reference namelist', lwp )
+      DO jbdy = 1, nb_bdy
+
+         WRITE(ctmp1, '(a,i2)') 'BDY number ', jbdy
+         WRITE(ctmp2, '(a,i2)') 'block nambdy_dta number ', jbdy
+
+         ! There is only one nambdy_dta block in namelist_ref -> use it for each bdy so we do a rewind 
+         REWIND(numnam_ref)
+         READ  ( numnam_ref, nambdy_dta, IOSTAT = ios, ERR = 901)
+901      IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy_dta in reference namelist' )
+
+         !   by-pass nambdy_dta reading if no input data used in this bdy   
+         IF(       ( dta_bdy(jbdy)%lneed_dyn2d .AND. MOD(nn_dyn2d_dta(jbdy),2) == 1 )   &
+            & .OR. ( dta_bdy(jbdy)%lneed_dyn3d .AND.     nn_dyn3d_dta(jbdy)    == 1 )   &
+            & .OR. ( dta_bdy(jbdy)%lneed_tra   .AND.       nn_tra_dta(jbdy)    == 1 )   &
+            & .OR. ( dta_bdy(jbdy)%lneed_ice   .AND.       nn_ice_dta(jbdy)    == 1 )   )   THEN
+            ! WARNING: we don't do a rewind here, each bdy reads its own nambdy_dta block one after another
             READ  ( numnam_cfg, nambdy_dta, IOSTAT = ios, ERR = 902 )
-902         IF( ios >  0 )   CALL ctl_nam ( ios , 'nambdy_dta in configuration namelist', lwp )
-            IF(lwm) WRITE( numond, nambdy_dta )
-
-            cn_dir_array(jbdy) = cn_dir
-            ln_full_vel_array(jbdy) = ln_full_vel
-
-            nblen => idx_bdy(jbdy)%nblen
-            nblenrim => idx_bdy(jbdy)%nblenrim
-            dta => dta_bdy(jbdy)
-            dta%nread(2) = 0
-
-            ! Only read in necessary fields for this set.
-            ! Important that barotropic variables come first.
-            IF( nn_dyn2d_dta(jbdy) == 1 .or. nn_dyn2d_dta(jbdy) == 3 ) THEN 
-
-               IF( dta%ll_ssh ) THEN 
-                  if(lwp) write(numout,*) '++++++ reading in ssh field'
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_ssh
-                  ibdy(jfld) = jbdy
-                  igrid(jfld) = 1
-                  ilen1(jfld) = nblen(igrid(jfld))
-                  ilen3(jfld) = 1
-                  dta%nread(2) = dta%nread(2) + 1
-               ENDIF
-
-               IF( dta%ll_u2d .and. .not. ln_full_vel_array(jbdy) ) THEN
-                  if(lwp) write(numout,*) '++++++ reading in u2d field'
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_u2d
-                  ibdy(jfld) = jbdy
-                  igrid(jfld) = 2
-                  ilen1(jfld) = nblen(igrid(jfld))
-                  ilen3(jfld) = 1
-                  dta%nread(2) = dta%nread(2) + 1
-               ENDIF
-
-               IF( dta%ll_v2d .and. .not. ln_full_vel_array(jbdy) ) THEN
-                  if(lwp) write(numout,*) '++++++ reading in v2d field'
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_v2d
-                  ibdy(jfld) = jbdy
-                  igrid(jfld) = 3
-                  ilen1(jfld) = nblen(igrid(jfld))
-                  ilen3(jfld) = 1
-                  dta%nread(2) = dta%nread(2) + 1
-               ENDIF
-
-            ENDIF
-
-            ! read 3D velocities if baroclinic velocities require OR if
-            ! barotropic velocities required and ln_full_vel set to .true.
-            IF( nn_dyn3d_dta(jbdy) == 1 .OR. &
-           &  ( ln_full_vel_array(jbdy) .AND. ( nn_dyn2d_dta(jbdy) == 1 .OR. nn_dyn2d_dta(jbdy) == 3 ) ) ) THEN
-
-               IF( dta%ll_u3d .OR. ( ln_full_vel_array(jbdy) .and. dta%ll_u2d ) ) THEN
-                  if(lwp) write(numout,*) '++++++ reading in u3d field'
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_u3d
-                  ibdy(jfld) = jbdy
-                  igrid(jfld) = 2
-                  ilen1(jfld) = nblen(igrid(jfld))
-                  ilen3(jfld) = jpk
-                  IF( ln_full_vel_array(jbdy) .and. dta%ll_u2d ) dta%nread(2) = dta%nread(2) + 1
-               ENDIF
-
-               IF( dta%ll_v3d .OR. ( ln_full_vel_array(jbdy) .and. dta%ll_v2d ) ) THEN
-                  if(lwp) write(numout,*) '++++++ reading in v3d field'
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_v3d
-                  ibdy(jfld) = jbdy
-                  igrid(jfld) = 3
-                  ilen1(jfld) = nblen(igrid(jfld))
-                  ilen3(jfld) = jpk
-                  IF( ln_full_vel_array(jbdy) .and. dta%ll_v2d ) dta%nread(2) = dta%nread(2) + 1
-               ENDIF
-
-            ENDIF
-
-            ! temperature and salinity
-            IF( nn_tra_dta(jbdy) == 1 ) THEN
-
-               IF( dta%ll_tem ) THEN
-                  if(lwp) write(numout,*) '++++++ reading in tem field'
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_tem
-                  ibdy(jfld) = jbdy
-                  igrid(jfld) = 1
-                  ilen1(jfld) = nblen(igrid(jfld))
-                  ilen3(jfld) = jpk
-               ENDIF
-
-               IF( dta%ll_sal ) THEN
-                  if(lwp) write(numout,*) '++++++ reading in sal field'
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_sal
-                  ibdy(jfld) = jbdy
-                  igrid(jfld) = 1
-                  ilen1(jfld) = nblen(igrid(jfld))
-                  ilen3(jfld) = jpk
-               ENDIF
-
-            ENDIF
+902         IF( ios >  0 )   CALL ctl_nam ( ios , 'nambdy_dta in configuration namelist' )
+            IF(lwm) WRITE( numond, nambdy_dta )           
+         ENDIF
+
+         ! get the number of ice categories in bdy data file (use a_i information to do this)
+         ipl = jpl   ! default definition
+         IF( dta_bdy(jbdy)%lneed_ice ) THEN    ! if we need ice bdy data
+            IF( nn_ice_dta(jbdy) == 1 ) THEN   ! if we get ice bdy data from netcdf file
+               CALL fld_fill(  bf(jp_bdya_i,jbdy:jbdy), bn_a_i, cn_dir, 'bdy_dta', 'a_i'//' '//ctmp1, ctmp2 )   ! use namelist info
+               CALL fld_clopn( bf(jp_bdya_i,jbdy), nyear, nmonth, nday )   ! not a problem when we call it again after
+               idvar = iom_varid( bf(jp_bdya_i,jbdy)%num, bf(jp_bdya_i,jbdy)%clvar, kndims=indims, kdimsz=i4dimsz, lduld=lluld )
+               IF( indims == 4 .OR. ( indims == 3 .AND. .NOT. lluld ) ) THEN   ;   ipl = i4dimsz(3)   ! xylt or xyl
+               ELSE                                                            ;   ipl = 1            ! xy or xyt
+               ENDIF
+            ENDIF
+         ENDIF
 
 #if defined key_si3
-            ! sea ice
-            IF( nn_ice_dta(jbdy) == 1 ) THEN
-               ! Test for types of ice input (1cat or Xcat) 
-               ! Build file name to find dimensions 
-               clname=TRIM( cn_dir )//TRIM(bn_a_i%clname)
-               IF( .NOT. bn_a_i%ln_clim ) THEN   
-                                                  WRITE(clname, '(a,"_y",i4.4)' ) TRIM( clname ), nyear    ! add year
-                  IF( bn_a_i%cltype /= 'yearly' ) WRITE(clname, '(a,"m" ,i2.2)' ) TRIM( clname ), nmonth   ! add month
-               ELSE
-                  IF( bn_a_i%cltype /= 'yearly' ) WRITE(clname, '(a,"_m",i2.2)' ) TRIM( clname ), nmonth   ! add month
-               ENDIF
-               IF( bn_a_i%cltype == 'daily' .OR. bn_a_i%cltype(1:4) == 'week' ) &
-               &                                  WRITE(clname, '(a,"d" ,i2.2)' ) TRIM( clname ), nday     ! add day
+         IF( .NOT.ln_pnd ) THEN
+            rn_ice_apnd = 0. ; rn_ice_hpnd = 0.
+            CALL ctl_warn( 'rn_ice_apnd & rn_ice_hpnd = 0 when no ponds' )
+         ENDIF
+#endif
+
+         ! temp, salt, age and ponds of incoming ice
+         rice_tem (jbdy) = rn_ice_tem
+         rice_sal (jbdy) = rn_ice_sal
+         rice_age (jbdy) = rn_ice_age
+         rice_apnd(jbdy) = rn_ice_apnd
+         rice_hpnd(jbdy) = rn_ice_hpnd
+         
+         
+         DO jfld = 1, jpbdyfld
+
+            ! =====================
+            !          ssh 
+            ! =====================
+            IF( jfld == jp_bdyssh ) THEN
+               cl3 = 'ssh'
+               igrd = 1                                                    ! T point
+               ipk = 1                                                     ! surface data
+               llneed = dta_bdy(jbdy)%lneed_ssh                            ! dta_bdy(jbdy)%ssh will be needed
+               llread = MOD(nn_dyn2d_dta(jbdy),2) == 1                     ! get data from NetCDF file
+               bf_alias => bf(jp_bdyssh,jbdy:jbdy)                         ! alias for ssh structure of bdy number jbdy
+               bn_alias => bn_ssh                                          ! alias for ssh structure of nambdy_dta 
+               iszdim = idx_bdy(jbdy)%nblenrim(igrd)                       ! length of this bdy on this MPI processus : used only on the rim
+            ENDIF
+            ! =====================
+            !         dyn2d
+            ! =====================
+            IF( jfld == jp_bdyu2d ) THEN
+               cl3 = 'u2d'
+               igrd = 2                                                    ! U point
+               ipk = 1                                                     ! surface data
+               llneed = dta_bdy(jbdy)%lneed_dyn2d                          ! dta_bdy(jbdy)%ssh will be needed
+               llread = .NOT. ln_full_vel .AND. MOD(nn_dyn2d_dta(jbdy),2) == 1   ! don't get u2d from u3d and read NetCDF file
+               bf_alias => bf(jp_bdyu2d,jbdy:jbdy)                         ! alias for u2d structure of bdy number jbdy
+               bn_alias => bn_u2d                                          ! alias for u2d structure of nambdy_dta
+               IF( ln_full_vel ) THEN  ;   iszdim = idx_bdy(jbdy)%nblen(igrd)      ! will be computed from u3d -> need on the full bdy
+               ELSE                    ;   iszdim = idx_bdy(jbdy)%nblenrim(igrd)   ! used only on the rim
+               ENDIF
+            ENDIF
+            IF( jfld == jp_bdyv2d ) THEN
+               cl3 = 'v2d'
+               igrd = 3                                                    ! V point
+               ipk = 1                                                     ! surface data
+               llneed = dta_bdy(jbdy)%lneed_dyn2d                          ! dta_bdy(jbdy)%ssh will be needed
+               llread = .NOT. ln_full_vel .AND. MOD(nn_dyn2d_dta(jbdy),2) == 1   ! don't get v2d from v3d and read NetCDF file
+               bf_alias => bf(jp_bdyv2d,jbdy:jbdy)                         ! alias for v2d structure of bdy number jbdy
+               bn_alias => bn_v2d                                          ! alias for v2d structure of nambdy_dta 
+               IF( ln_full_vel ) THEN  ;   iszdim = idx_bdy(jbdy)%nblen(igrd)      ! will be computed from v3d -> need on the full bdy
+               ELSE                    ;   iszdim = idx_bdy(jbdy)%nblenrim(igrd)   ! used only on the rim
+               ENDIF
+            ENDIF
+            ! =====================
+            !         dyn3d
+            ! =====================
+            IF( jfld == jp_bdyu3d ) THEN
+               cl3 = 'u3d'
+               igrd = 2                                                    ! U point
+               ipk = jpk                                                   ! 3d data
+               llneed = dta_bdy(jbdy)%lneed_dyn3d .OR.               &     ! dta_bdy(jbdy)%u3d will be needed
+                  &   ( dta_bdy(jbdy)%lneed_dyn2d .AND. ln_full_vel )      !   u3d needed to compute u2d
+               llread = nn_dyn3d_dta(jbdy) == 1                            ! get data from NetCDF file
+               bf_alias => bf(jp_bdyu3d,jbdy:jbdy)                         ! alias for u3d structure of bdy number jbdy
+               bn_alias => bn_u3d                                          ! alias for u3d structure of nambdy_dta 
+               iszdim = idx_bdy(jbdy)%nblen(igrd)                          ! length of this bdy on this MPI processus
+           ENDIF
+            IF( jfld == jp_bdyv3d ) THEN
+               cl3 = 'v3d'
+               igrd = 3                                                    ! V point
+               ipk = jpk                                                   ! 3d data
+               llneed = dta_bdy(jbdy)%lneed_dyn3d .OR.               &     ! dta_bdy(jbdy)%v3d will be needed
+                  &   ( dta_bdy(jbdy)%lneed_dyn2d .AND. ln_full_vel )      !   v3d needed to compute v2d
+               llread = nn_dyn3d_dta(jbdy) == 1                            ! get data from NetCDF file
+               bf_alias => bf(jp_bdyv3d,jbdy:jbdy)                         ! alias for v3d structure of bdy number jbdy
+               bn_alias => bn_v3d                                          ! alias for v3d structure of nambdy_dta 
+               iszdim = idx_bdy(jbdy)%nblen(igrd)                          ! length of this bdy on this MPI processus
+           ENDIF
+
+            ! =====================
+            !          tra
+            ! =====================
+            IF( jfld == jp_bdytem ) THEN
+               cl3 = 'tem'
+               igrd = 1                                                    ! T point
+               ipk = jpk                                                   ! 3d data
+               llneed = dta_bdy(jbdy)%lneed_tra                            ! dta_bdy(jbdy)%tem will be needed
+               llread = nn_tra_dta(jbdy) == 1                              ! get data from NetCDF file
+               bf_alias => bf(jp_bdytem,jbdy:jbdy)                         ! alias for ssh structure of bdy number jbdy
+               bn_alias => bn_tem                                          ! alias for ssh structure of nambdy_dta 
+               iszdim = idx_bdy(jbdy)%nblen(igrd)                          ! length of this bdy on this MPI processus
+            ENDIF
+            IF( jfld == jp_bdysal ) THEN
+               cl3 = 'sal'
+               igrd = 1                                                    ! T point
+               ipk = jpk                                                   ! 3d data
+               llneed = dta_bdy(jbdy)%lneed_tra                            ! dta_bdy(jbdy)%sal will be needed
+               llread = nn_tra_dta(jbdy) == 1                              ! get data from NetCDF file
+               bf_alias => bf(jp_bdysal,jbdy:jbdy)                         ! alias for ssh structure of bdy number jbdy
+               bn_alias => bn_sal                                          ! alias for ssh structure of nambdy_dta 
+               iszdim = idx_bdy(jbdy)%nblen(igrd)                          ! length of this bdy on this MPI processus
+            ENDIF
+
+            ! =====================
+            !          ice
+            ! =====================
+            IF(  jfld == jp_bdya_i .OR. jfld == jp_bdyh_i .OR. jfld == jp_bdyh_s .OR. &
+               & jfld == jp_bdyt_i .OR. jfld == jp_bdyt_s .OR. jfld == jp_bdytsu .OR. &
+               & jfld == jp_bdys_i .OR. jfld == jp_bdyaip .OR. jfld == jp_bdyhip      ) THEN
+               igrd = 1                                                    ! T point
+               ipk = ipl                                                   ! jpl-cat data
+               llneed = dta_bdy(jbdy)%lneed_ice                            ! ice will be needed
+               llread = nn_ice_dta(jbdy) == 1                              ! get data from NetCDF file
+               iszdim = idx_bdy(jbdy)%nblen(igrd)                          ! length of this bdy on this MPI processus
+            ENDIF
+            IF( jfld == jp_bdya_i ) THEN
+               cl3 = 'a_i'
+               bf_alias => bf(jp_bdya_i,jbdy:jbdy)                         ! alias for a_i structure of bdy number jbdy
+               bn_alias => bn_a_i                                          ! alias for a_i structure of nambdy_dta 
+            ENDIF
+            IF( jfld == jp_bdyh_i ) THEN
+               cl3 = 'h_i'
+               bf_alias => bf(jp_bdyh_i,jbdy:jbdy)                         ! alias for h_i structure of bdy number jbdy
+               bn_alias => bn_h_i                                          ! alias for h_i structure of nambdy_dta 
+            ENDIF
+            IF( jfld == jp_bdyh_s ) THEN
+               cl3 = 'h_s'
+               bf_alias => bf(jp_bdyh_s,jbdy:jbdy)                         ! alias for h_s structure of bdy number jbdy
+               bn_alias => bn_h_s                                          ! alias for h_s structure of nambdy_dta 
+            ENDIF
+            IF( jfld == jp_bdyt_i ) THEN
+               cl3 = 't_i'
+               bf_alias => bf(jp_bdyt_i,jbdy:jbdy)                         ! alias for t_i structure of bdy number jbdy
+               bn_alias => bn_t_i                                          ! alias for t_i structure of nambdy_dta 
+            ENDIF
+            IF( jfld == jp_bdyt_s ) THEN
+               cl3 = 't_s'
+               bf_alias => bf(jp_bdyt_s,jbdy:jbdy)                         ! alias for t_s structure of bdy number jbdy
+               bn_alias => bn_t_s                                          ! alias for t_s structure of nambdy_dta 
+            ENDIF
+            IF( jfld == jp_bdytsu ) THEN
+               cl3 = 'tsu'
+               bf_alias => bf(jp_bdytsu,jbdy:jbdy)                         ! alias for tsu structure of bdy number jbdy
+               bn_alias => bn_tsu                                          ! alias for tsu structure of nambdy_dta 
+            ENDIF
+            IF( jfld == jp_bdys_i ) THEN
+               cl3 = 's_i'
+               bf_alias => bf(jp_bdys_i,jbdy:jbdy)                         ! alias for s_i structure of bdy number jbdy
+               bn_alias => bn_s_i                                          ! alias for s_i structure of nambdy_dta 
+            ENDIF
+            IF( jfld == jp_bdyaip ) THEN
+               cl3 = 'aip'
+               bf_alias => bf(jp_bdyaip,jbdy:jbdy)                         ! alias for aip structure of bdy number jbdy
+               bn_alias => bn_aip                                          ! alias for aip structure of nambdy_dta 
+            ENDIF
+            IF( jfld == jp_bdyhip ) THEN
+               cl3 = 'hip'
+               bf_alias => bf(jp_bdyhip,jbdy:jbdy)                         ! alias for hip structure of bdy number jbdy
+               bn_alias => bn_hip                                          ! alias for hip structure of nambdy_dta 
+            ENDIF
+
+            IF( llneed ) THEN                                              ! dta_bdy(jbdy)%xxx will be needed
+               !                                                           !   -> must be associated with an allocated target
+               ALLOCATE( bf_alias(1)%fnow( iszdim, 1, ipk ) )              ! allocate the target
                !
-               CALL iom_open  ( clname, inum )
-               id1 = iom_varid( inum, bn_a_i%clvar, kdimsz=kdimsz, kndims=kndims, ldstop = .FALSE. )
-               CALL iom_close ( inum )
-
-      	       IF ( kndims == 4 ) THEN
-                 nice_cat = kdimsz(4)   ! Xcat input
-               ELSE
-                 nice_cat = 1           ! 1cat input      
-               ENDIF
-               ! End test
-
-               IF( dta%ll_a_i ) THEN
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_a_i
-                  ibdy(jfld)  = jbdy
-                  igrid(jfld) = 1
-                  ilen1(jfld) = nblen(igrid(jfld))
-                  ilen3(jfld) = nice_cat
-               ENDIF
-
-               IF( dta%ll_h_i ) THEN
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_h_i
-                  ibdy(jfld)  = jbdy
-                  igrid(jfld) = 1
-                  ilen1(jfld) = nblen(igrid(jfld))
-                  ilen3(jfld) = nice_cat
-               ENDIF
-
-               IF( dta%ll_h_s ) THEN
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_h_s
-                  ibdy(jfld)  = jbdy
-                  igrid(jfld) = 1
-                  ilen1(jfld) = nblen(igrid(jfld))
-                  ilen3(jfld) = nice_cat
-               ENDIF
-
-            ENDIF
-#endif
-            ! Recalculate field counts
-            !-------------------------
-            IF( jbdy == 1 ) THEN 
-               nb_bdy_fld_sum = 0
-               nb_bdy_fld(jbdy) = jfld
-               nb_bdy_fld_sum     = jfld              
-            ELSE
-               nb_bdy_fld(jbdy) = jfld - nb_bdy_fld_sum
-               nb_bdy_fld_sum = nb_bdy_fld_sum + nb_bdy_fld(jbdy)
-            ENDIF
-
-            dta%nread(1) = nb_bdy_fld(jbdy)
-
-         ENDIF ! nn_dta == 1
-      ENDDO ! jbdy
-
-      DO jfld = 1, nb_bdy_fld_sum
-         ALLOCATE( bf(jfld)%fnow(ilen1(jfld),1,ilen3(jfld)) )
-         IF( blf_i(jfld)%ln_tint ) ALLOCATE( bf(jfld)%fdta(ilen1(jfld),1,ilen3(jfld),2) )
-         nbmap_ptr(jfld)%ptr => idx_bdy(ibdy(jfld))%nbmap(:,igrid(jfld))
-         nbmap_ptr(jfld)%ll_unstruc = ln_coords_file(ibdy(jfld))
-      ENDDO
-
-      ! fill bf with blf_i and control print
-      !-------------------------------------
-      jstart = 1
-      DO jbdy = 1, nb_bdy
-         jend = jstart - 1 + nb_bdy_fld(jbdy) 
-         CALL fld_fill( bf(jstart:jend), blf_i(jstart:jend), cn_dir_array(jbdy), 'bdy_dta',   &
-         &              'open boundary conditions', 'nambdy_dta' )
-         jstart = jend + 1
-      ENDDO
-
-      DO jfld = 1, nb_bdy_fld_sum
-         bf(jfld)%igrd = igrid(jfld)
-         bf(jfld)%ibdy = ibdy(jfld)
-      ENDDO
-
-      ! Initialise local boundary data arrays
-      ! nn_xxx_dta=0 : allocate space - will be filled from initial conditions later
-      ! nn_xxx_dta=1 : point to "fnow" arrays
-      !-------------------------------------
-
-      jfld = 0
-      DO jbdy=1, nb_bdy
-
-         nblen => idx_bdy(jbdy)%nblen
-         dta => dta_bdy(jbdy)
-
-         if(lwp) then
-            write(numout,*) '++++++ dta%ll_ssh = ',dta%ll_ssh
-            write(numout,*) '++++++ dta%ll_u2d = ',dta%ll_u2d
-            write(numout,*) '++++++ dta%ll_v2d = ',dta%ll_v2d
-            write(numout,*) '++++++ dta%ll_u3d = ',dta%ll_u3d
-            write(numout,*) '++++++ dta%ll_v3d = ',dta%ll_v3d
-            write(numout,*) '++++++ dta%ll_tem = ',dta%ll_tem
-            write(numout,*) '++++++ dta%ll_sal = ',dta%ll_sal
-         endif
-
-         IF ( nn_dyn2d_dta(jbdy) == 0 .or. nn_dyn2d_dta(jbdy) == 2 ) THEN
-            if(lwp) write(numout,*) '++++++ dta%ssh/u2d/u3d allocated space'
-            IF( dta%ll_ssh ) ALLOCATE( dta%ssh(nblen(1)) )
-            IF( dta%ll_u2d ) ALLOCATE( dta%u2d(nblen(2)) )
-            IF( dta%ll_v2d ) ALLOCATE( dta%v2d(nblen(3)) )
-         ENDIF
-         IF ( nn_dyn2d_dta(jbdy) == 1 .or. nn_dyn2d_dta(jbdy) == 3 ) THEN
-            IF( dta%ll_ssh ) THEN
-               if(lwp) write(numout,*) '++++++ dta%ssh pointing to fnow'
-               jfld = jfld + 1
-               dta%ssh => bf(jfld)%fnow(:,1,1)
-            ENDIF
-            IF ( dta%ll_u2d ) THEN
-               IF ( ln_full_vel_array(jbdy) ) THEN
-                  if(lwp) write(numout,*) '++++++ dta%u2d allocated space'
-                  ALLOCATE( dta%u2d(nblen(2)) )
-               ELSE
-                  if(lwp) write(numout,*) '++++++ dta%u2d pointing to fnow'
-                  jfld = jfld + 1
-                  dta%u2d => bf(jfld)%fnow(:,1,1)
-               ENDIF
-            ENDIF
-            IF ( dta%ll_v2d ) THEN
-               IF ( ln_full_vel_array(jbdy) ) THEN
-                  if(lwp) write(numout,*) '++++++ dta%v2d allocated space'
-                  ALLOCATE( dta%v2d(nblen(3)) )
-               ELSE
-                  if(lwp) write(numout,*) '++++++ dta%v2d pointing to fnow'
-                  jfld = jfld + 1
-                  dta%v2d => bf(jfld)%fnow(:,1,1)
-               ENDIF
-            ENDIF
-         ENDIF
-
-         IF ( nn_dyn3d_dta(jbdy) == 0 ) THEN
-            if(lwp) write(numout,*) '++++++ dta%u3d/v3d allocated space'
-            IF( dta%ll_u3d ) ALLOCATE( dta_bdy(jbdy)%u3d(nblen(2),jpk) )
-            IF( dta%ll_v3d ) ALLOCATE( dta_bdy(jbdy)%v3d(nblen(3),jpk) )
-         ENDIF
-         IF ( nn_dyn3d_dta(jbdy) == 1 .or. &
-           &  ( ln_full_vel_array(jbdy) .and. ( nn_dyn2d_dta(jbdy) == 1 .or. nn_dyn2d_dta(jbdy) == 3 ) ) ) THEN
-            IF ( dta%ll_u3d .or. ( ln_full_vel_array(jbdy) .and. dta%ll_u2d ) ) THEN
-               if(lwp) write(numout,*) '++++++ dta%u3d pointing to fnow'
-               jfld = jfld + 1
-               dta_bdy(jbdy)%u3d => bf(jfld)%fnow(:,1,:)
-            ENDIF
-            IF ( dta%ll_v3d .or. ( ln_full_vel_array(jbdy) .and. dta%ll_v2d ) ) THEN
-               if(lwp) write(numout,*) '++++++ dta%v3d pointing to fnow'
-               jfld = jfld + 1
-               dta_bdy(jbdy)%v3d => bf(jfld)%fnow(:,1,:)
-            ENDIF
-         ENDIF
-
-         IF( nn_tra_dta(jbdy) == 0 ) THEN
-            if(lwp) write(numout,*) '++++++ dta%tem/sal allocated space'
-            IF( dta%ll_tem ) ALLOCATE( dta_bdy(jbdy)%tem(nblen(1),jpk) )
-            IF( dta%ll_sal ) ALLOCATE( dta_bdy(jbdy)%sal(nblen(1),jpk) )
-         ELSE
-            IF( dta%ll_tem ) THEN
-               if(lwp) write(numout,*) '++++++ dta%tem pointing to fnow'
-               jfld = jfld + 1
-               dta_bdy(jbdy)%tem => bf(jfld)%fnow(:,1,:)
-            ENDIF
-            IF( dta%ll_sal ) THEN 
-               if(lwp) write(numout,*) '++++++ dta%sal pointing to fnow'
-               jfld = jfld + 1
-               dta_bdy(jbdy)%sal => bf(jfld)%fnow(:,1,:)
-            ENDIF
-         ENDIF
-
-#if defined key_si3
-         IF (cn_ice(jbdy) /= 'none') THEN
-            IF( nn_ice_dta(jbdy) == 0 ) THEN
-               ALLOCATE( dta_bdy(jbdy)%a_i(nblen(1),jpl) )
-               ALLOCATE( dta_bdy(jbdy)%h_i(nblen(1),jpl) )
-               ALLOCATE( dta_bdy(jbdy)%h_s(nblen(1),jpl) )
-            ELSE
-               IF ( nice_cat == jpl ) THEN ! case input cat = jpl
-                  jfld = jfld + 1
-                  dta_bdy(jbdy)%a_i => bf(jfld)%fnow(:,1,:)
-                  jfld = jfld + 1
-                  dta_bdy(jbdy)%h_i => bf(jfld)%fnow(:,1,:)
-                  jfld = jfld + 1
-                  dta_bdy(jbdy)%h_s => bf(jfld)%fnow(:,1,:)
-               ELSE                        ! case input cat = 1 OR (/=1 and /=jpl)
-                  jfld_ait(jbdy)  = jfld + 1
-                  jfld_htit(jbdy) = jfld + 2
-                  jfld_htst(jbdy) = jfld + 3
-                  jfld     = jfld + 3
-                  ALLOCATE( dta_bdy(jbdy)%a_i(nblen(1),jpl) )
-                  ALLOCATE( dta_bdy(jbdy)%h_i(nblen(1),jpl) )
-                  ALLOCATE( dta_bdy(jbdy)%h_s(nblen(1),jpl) )
-                  dta_bdy(jbdy)%a_i(:,:) = 0._wp
-                  dta_bdy(jbdy)%h_i(:,:) = 0._wp
-                  dta_bdy(jbdy)%h_s(:,:) = 0._wp
-               ENDIF
-
-            ENDIF
-         ENDIF
-#endif
+               IF( llread ) THEN                                           ! get data from NetCDF file
+                  CALL fld_fill( bf_alias, bn_alias, cn_dir, 'bdy_dta', cl3//' '//ctmp1, ctmp2 )   ! use namelist info
+                  IF( bf_alias(1)%ln_tint ) ALLOCATE( bf_alias(1)%fdta( iszdim, 1, ipk, 2 ) )
+                  bf_alias(1)%imap    => idx_bdy(jbdy)%nbmap(1:iszdim,igrd)   ! associate the mapping used for this bdy
+                  bf_alias(1)%igrd    = igrd                                  ! used only for vertical integration of 3D arrays
+                  bf_alias(1)%ltotvel = ln_full_vel                           ! T if u3d is full velocity
+                  bf_alias(1)%lzint   = ln_zinterp                            ! T if it requires a vertical interpolation
+               ENDIF
+
+               ! associate the pointer and get rid of the dimensions with a size equal to 1
+               IF( jfld == jp_bdyssh )        dta_bdy(jbdy)%ssh => bf_alias(1)%fnow(:,1,1)
+               IF( jfld == jp_bdyu2d )        dta_bdy(jbdy)%u2d => bf_alias(1)%fnow(:,1,1)
+               IF( jfld == jp_bdyv2d )        dta_bdy(jbdy)%v2d => bf_alias(1)%fnow(:,1,1)
+               IF( jfld == jp_bdyu3d )        dta_bdy(jbdy)%u3d => bf_alias(1)%fnow(:,1,:)
+               IF( jfld == jp_bdyv3d )        dta_bdy(jbdy)%v3d => bf_alias(1)%fnow(:,1,:)
+               IF( jfld == jp_bdytem )        dta_bdy(jbdy)%tem => bf_alias(1)%fnow(:,1,:)
+               IF( jfld == jp_bdysal )        dta_bdy(jbdy)%sal => bf_alias(1)%fnow(:,1,:)
+               IF( jfld == jp_bdya_i ) THEN
+                  IF( ipk == jpl ) THEN   ;   dta_bdy(jbdy)%a_i => bf_alias(1)%fnow(:,1,:)
+                  ELSE                    ;   ALLOCATE( dta_bdy(jbdy)%a_i(iszdim,jpl) )
+                  ENDIF
+               ENDIF
+               IF( jfld == jp_bdyh_i ) THEN
+                  IF( ipk == jpl ) THEN   ;   dta_bdy(jbdy)%h_i => bf_alias(1)%fnow(:,1,:)
+                  ELSE                    ;   ALLOCATE( dta_bdy(jbdy)%h_i(iszdim,jpl) )
+                  ENDIF
+               ENDIF
+               IF( jfld == jp_bdyh_s ) THEN
+                  IF( ipk == jpl ) THEN   ;   dta_bdy(jbdy)%h_s => bf_alias(1)%fnow(:,1,:)
+                  ELSE                    ;   ALLOCATE( dta_bdy(jbdy)%h_s(iszdim,jpl) )
+                  ENDIF
+               ENDIF
+               IF( jfld == jp_bdyt_i ) THEN
+                  IF( ipk == jpl ) THEN   ;   dta_bdy(jbdy)%t_i => bf_alias(1)%fnow(:,1,:)
+                  ELSE                    ;   ALLOCATE( dta_bdy(jbdy)%t_i(iszdim,jpl) )
+                  ENDIF
+               ENDIF
+               IF( jfld == jp_bdyt_s ) THEN
+                  IF( ipk == jpl ) THEN   ;   dta_bdy(jbdy)%t_s => bf_alias(1)%fnow(:,1,:)
+                  ELSE                    ;   ALLOCATE( dta_bdy(jbdy)%t_s(iszdim,jpl) )
+                  ENDIF
+               ENDIF
+               IF( jfld == jp_bdytsu ) THEN
+                  IF( ipk == jpl ) THEN   ;   dta_bdy(jbdy)%tsu => bf_alias(1)%fnow(:,1,:)
+                  ELSE                    ;   ALLOCATE( dta_bdy(jbdy)%tsu(iszdim,jpl) )
+                  ENDIF
+               ENDIF
+               IF( jfld == jp_bdys_i ) THEN
+                  IF( ipk == jpl ) THEN   ;   dta_bdy(jbdy)%s_i => bf_alias(1)%fnow(:,1,:)
+                  ELSE                    ;   ALLOCATE( dta_bdy(jbdy)%s_i(iszdim,jpl) )
+                  ENDIF
+               ENDIF
+               IF( jfld == jp_bdyaip ) THEN
+                  IF( ipk == jpl ) THEN   ;   dta_bdy(jbdy)%aip => bf_alias(1)%fnow(:,1,:)
+                  ELSE                    ;   ALLOCATE( dta_bdy(jbdy)%aip(iszdim,jpl) )
+                  ENDIF
+               ENDIF
+               IF( jfld == jp_bdyhip ) THEN
+                  IF( ipk == jpl ) THEN   ;   dta_bdy(jbdy)%hip => bf_alias(1)%fnow(:,1,:)
+                  ELSE                    ;   ALLOCATE( dta_bdy(jbdy)%hip(iszdim,jpl) )
+                  ENDIF
+               ENDIF
+            ENDIF
+
+         END DO   ! jpbdyfld
          !
       END DO ! jbdy 
       !
    END SUBROUTINE bdy_dta_init
-
+   
    !!==============================================================================
 END MODULE bdydta
Index: /NEMO/trunk/src/OCE/BDY/bdydyn2d.F90
===================================================================
--- /NEMO/trunk/src/OCE/BDY/bdydyn2d.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/BDY/bdydyn2d.F90	(revision 11536)
@@ -14,5 +14,4 @@
    !!   bdy_ssh            : Duplicate sea level across open boundaries
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers 
    USE dom_oce         ! ocean space and time domain
    USE bdy_oce         ! ocean open boundary conditions
@@ -50,26 +49,65 @@
       REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) :: pssh
       !!
-      INTEGER                                  ::   ib_bdy ! Loop counter
-
-      DO ib_bdy=1, nb_bdy
-
-         SELECT CASE( cn_dyn2d(ib_bdy) )
-         CASE('none')
-            CYCLE
-         CASE('frs')
-            CALL bdy_dyn2d_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, pua2d, pva2d )
-         CASE('flather')
-            CALL bdy_dyn2d_fla( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, pua2d, pva2d, pssh, phur, phvr )
-         CASE('orlanski')
-            CALL bdy_dyn2d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, &
-                                     & pua2d, pva2d, pub2d, pvb2d, ll_npo=.false.)
-         CASE('orlanski_npo')
-            CALL bdy_dyn2d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, &
-                                     & pua2d, pva2d, pub2d, pvb2d, ll_npo=.true. )
-         CASE DEFAULT
-            CALL ctl_stop( 'bdy_dyn2d : unrecognised option for open boundaries for barotropic variables' )
-         END SELECT
-      ENDDO
-
+      INTEGER  ::   ib_bdy, ir     ! BDY set index, rim index
+      LOGICAL  ::   llrim0         ! indicate if rim 0 is treated
+      LOGICAL, DIMENSION(4) :: llsend2, llrecv2, llsend3, llrecv3  ! indicate how communications are to be carried out
+      
+      llsend2(:) = .false.   ;   llrecv2(:) = .false.
+      llsend3(:) = .false.   ;   llrecv3(:) = .false.
+      DO ir = 1, 0, -1   ! treat rim 1 before rim 0
+         IF( ir == 0 ) THEN   ;   llrim0 = .TRUE.
+         ELSE                 ;   llrim0 = .FALSE.
+         END IF
+         DO ib_bdy=1, nb_bdy
+            SELECT CASE( cn_dyn2d(ib_bdy) )
+            CASE('none')
+               CYCLE
+            CASE('frs')   ! treat the whole boundary at once
+               IF( llrim0 )   CALL bdy_dyn2d_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, pua2d, pva2d )
+            CASE('flather')
+               CALL bdy_dyn2d_fla( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, pua2d, pva2d, pssh, phur, phvr, llrim0 )
+            CASE('orlanski')
+               CALL bdy_dyn2d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, &
+                    & pua2d, pva2d, pub2d, pvb2d, llrim0, ll_npo=.false. )
+            CASE('orlanski_npo')
+               CALL bdy_dyn2d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, &
+                    & pua2d, pva2d, pub2d, pvb2d, llrim0, ll_npo=.true.  )
+            CASE DEFAULT
+               CALL ctl_stop( 'bdy_dyn2d : unrecognised option for open boundaries for barotropic variables' )
+            END SELECT
+         ENDDO
+         !
+         IF( nn_hls > 1 .AND. ir == 1 ) CYCLE   ! at least 2 halos will be corrected -> no need to correct rim 1 before rim 0
+         IF( nn_hls == 1 ) THEN
+            llsend2(:) = .false.   ;   llrecv2(:) = .false.
+            llsend3(:) = .false.   ;   llrecv3(:) = .false.
+         END IF
+         DO ib_bdy=1, nb_bdy
+            SELECT CASE( cn_dyn2d(ib_bdy) )
+            CASE('flather')
+               llsend2(1:2) = llsend2(1:2) .OR. lsend_bdyint(ib_bdy,2,1:2,ir)   ! west/east, U points
+               llsend2(1)   = llsend2(1)   .OR. lsend_bdyext(ib_bdy,2,1,ir)     ! neighbour might search point towards its east bdy
+               llrecv2(1:2) = llrecv2(1:2) .OR. lrecv_bdyint(ib_bdy,2,1:2,ir)   ! west/east, U points
+               llrecv2(2)   = llrecv2(2)   .OR. lrecv_bdyext(ib_bdy,2,2,ir)     ! might search point towards bdy on the east
+               llsend3(3:4) = llsend3(3:4) .OR. lsend_bdyint(ib_bdy,3,3:4,ir)   ! north/south, V points
+               llsend3(3)   = llsend3(3)   .OR. lsend_bdyext(ib_bdy,3,3,ir)     ! neighbour might search point towards its north bdy 
+               llrecv3(3:4) = llrecv3(3:4) .OR. lrecv_bdyint(ib_bdy,3,3:4,ir)   ! north/south, V points
+               llrecv3(4)   = llrecv3(4)   .OR. lrecv_bdyext(ib_bdy,3,4,ir)     ! might search point towards bdy on the north
+            CASE('orlanski', 'orlanski_npo')
+               llsend2(:) = llsend2(:) .OR. lsend_bdy(ib_bdy,2,:,ir)   ! possibly every direction, U points
+               llrecv2(:) = llrecv2(:) .OR. lrecv_bdy(ib_bdy,2,:,ir)   ! possibly every direction, U points
+               llsend3(:) = llsend3(:) .OR. lsend_bdy(ib_bdy,3,:,ir)   ! possibly every direction, V points
+               llrecv3(:) = llrecv3(:) .OR. lrecv_bdy(ib_bdy,3,:,ir)   ! possibly every direction, V points
+            END SELECT
+         END DO
+         IF( ANY(llsend2) .OR. ANY(llrecv2) ) THEN   ! if need to send/recv in at least one direction
+            CALL lbc_lnk( 'bdydyn2d', pua2d, 'U', -1., kfillmode=jpfillnothing ,lsend=llsend2, lrecv=llrecv2 )
+         END IF
+         IF( ANY(llsend3) .OR. ANY(llrecv3) ) THEN   ! if need to send/recv in at least one direction
+            CALL lbc_lnk( 'bdydyn2d', pva2d, 'V', -1., kfillmode=jpfillnothing ,lsend=llsend3, lrecv=llrecv3 )
+         END IF
+         !
+      END DO   ! ir
+      !
    END SUBROUTINE bdy_dyn2d
 
@@ -90,5 +128,5 @@
       REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) :: pua2d, pva2d 
       !!
-      INTEGER  ::   jb, jk         ! dummy loop indices
+      INTEGER  ::   jb             ! dummy loop indices
       INTEGER  ::   ii, ij, igrd   ! local integers
       REAL(wp) ::   zwgt           ! boundary weight
@@ -110,11 +148,9 @@
          pva2d(ii,ij) = ( pva2d(ii,ij) + zwgt * ( dta%v2d(jb) - pva2d(ii,ij) ) ) * vmask(ii,ij,1)
       END DO 
-      CALL lbc_bdy_lnk( 'bdydyn2d', pua2d, 'U', -1., ib_bdy ) 
-      CALL lbc_bdy_lnk( 'bdydyn2d', pva2d, 'V', -1., ib_bdy)   ! Boundary points should be updated
       !
    END SUBROUTINE bdy_dyn2d_frs
 
 
-   SUBROUTINE bdy_dyn2d_fla( idx, dta, ib_bdy, pua2d, pva2d, pssh, phur, phvr )
+   SUBROUTINE bdy_dyn2d_fla( idx, dta, ib_bdy, pua2d, pva2d, pssh, phur, phvr, llrim0 )
       !!----------------------------------------------------------------------
       !!                 ***  SUBROUTINE bdy_dyn2d_fla  ***
@@ -139,12 +175,15 @@
       INTEGER,                      INTENT(in) ::   ib_bdy  ! BDY set index
       REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) :: pua2d, pva2d
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pssh, phur, phvr 
-
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pssh, phur, phvr
+      LOGICAL                     , INTENT(in) ::   llrim0   ! indicate if rim 0 is treated
+      INTEGER  ::   ibeg, iend                       ! length of rim to be treated (rim 0 or rim 1)
       INTEGER  ::   jb, igrd                         ! dummy loop indices
-      INTEGER  ::   ii, ij, iim1, iip1, ijm1, ijp1   ! 2D addresses
-      REAL(wp), POINTER :: flagu, flagv              ! short cuts
-      REAL(wp) ::   zcorr                            ! Flather correction
-      REAL(wp) ::   zforc                            ! temporary scalar
-      REAL(wp) ::   zflag, z1_2                      !    "        "
+      INTEGER  ::   ii, ij                           ! 2D addresses
+      INTEGER  ::   iiTrim, ijTrim                   ! T pts i/j-indice on the rim
+      INTEGER  ::   iiToce, ijToce, iiUoce, ijVoce   ! T, U and V pts i/j-indice of the ocean next to the rim
+      REAL(wp) ::   flagu, flagv                     ! short cuts
+      REAL(wp) ::   zfla                             ! Flather correction
+      REAL(wp) ::   z1_2                             ! 
+      REAL(wp), DIMENSION(jpi,jpj) ::   sshdta       ! 2D version of dta%ssh
       !!----------------------------------------------------------------------
 
@@ -153,66 +192,77 @@
       ! ---------------------------------!
       ! Flather boundary conditions     :!
-      ! ---------------------------------! 
-     
-!!! REPLACE spgu with nemo_wrk work space
-
-      ! Fill temporary array with ssh data (here spgu):
+      ! ---------------------------------!
+
+      ! Fill temporary array with ssh data (here we use spgu with the alias sshdta):
       igrd = 1
-      spgu(:,:) = 0.0
-      DO jb = 1, idx%nblenrim(igrd)
+      IF( llrim0 ) THEN   ;   ibeg = 1                       ;   iend = idx%nblenrim0(igrd)
+      ELSE                ;   ibeg = idx%nblenrim0(igrd)+1   ;   iend = idx%nblenrim(igrd)
+      END IF
+      !
+      DO jb = ibeg, iend
          ii = idx%nbi(jb,igrd)
          ij = idx%nbj(jb,igrd)
-         IF( ll_wd ) THEN
-            spgu(ii, ij) = dta%ssh(jb)  - ssh_ref 
-         ELSE
-            spgu(ii, ij) = dta%ssh(jb)
+         IF( ll_wd ) THEN   ;   sshdta(ii, ij) = dta%ssh(jb) - ssh_ref 
+         ELSE               ;   sshdta(ii, ij) = dta%ssh(jb)
          ENDIF
       END DO
-
-      CALL lbc_bdy_lnk( 'bdydyn2d', spgu(:,:), 'T', 1., ib_bdy )
-      !
-      igrd = 2      ! Flather bc on u-velocity; 
+      !
+      igrd = 2      ! Flather bc on u-velocity
       !             ! remember that flagu=-1 if normal velocity direction is outward
       !             ! I think we should rather use after ssh ?
-      DO jb = 1, idx%nblenrim(igrd)
-         ii  = idx%nbi(jb,igrd)
-         ij  = idx%nbj(jb,igrd) 
-         flagu => idx%flagu(jb,igrd)
-         iim1 = ii + MAX( 0, INT( flagu ) )   ! T pts i-indice inside the boundary
-         iip1 = ii - MIN( 0, INT( flagu ) )   ! T pts i-indice outside the boundary 
-         !
-         zcorr = - flagu * SQRT( grav * phur(ii, ij) ) * ( pssh(iim1, ij) - spgu(iip1,ij) )
-
-         ! jchanut tschanges: Set zflag to 0 below to revert to Flather scheme
-         ! Use characteristics method instead
-         zflag = ABS(flagu)
-         zforc = dta%u2d(jb) * (1._wp - z1_2*zflag) + z1_2 * zflag * pua2d(ii+NINT(flagu),ij)
-         pua2d(ii,ij) = zforc + (1._wp - z1_2*zflag) * zcorr * umask(ii,ij,1) 
+      IF( llrim0 ) THEN   ;   ibeg = 1                       ;   iend = idx%nblenrim0(igrd)
+      ELSE                ;   ibeg = idx%nblenrim0(igrd)+1   ;   iend = idx%nblenrim(igrd)
+      END IF
+      DO jb = ibeg, iend
+         ii    = idx%nbi(jb,igrd)
+         ij    = idx%nbj(jb,igrd)
+         flagu = idx%flagu(jb,igrd)
+         IF( flagu == 0. ) THEN
+            pua2d(ii,ij) = dta%u2d(jb)
+         ELSE      ! T pts j-indice       on the rim          on the ocean next to the rim on T and U points
+            IF( flagu ==  1. ) THEN   ;   iiTrim = ii     ;   iiToce = ii+1   ;   iiUoce = ii+1   ;   ENDIF
+            IF( flagu == -1. ) THEN   ;   iiTrim = ii+1   ;   iiToce = ii     ;   iiUoce = ii-1   ;   ENDIF
+            !
+            ! Rare case : rim is parallel to the mpi subdomain border and on the halo : point will be received
+            IF( iiTrim > jpi .OR. iiToce > jpi .OR. iiUoce > jpi .OR. iiUoce < 1 )   CYCLE   
+            !
+            zfla = dta%u2d(jb) - flagu * SQRT( grav * phur(ii, ij) ) * ( pssh(iiToce,ij) - sshdta(iiTrim,ij) )
+            !
+            ! jchanut tschanges, use characteristics method (Blayo et Debreu, 2005) :
+            ! mix Flather scheme with velocity of the ocean next to the rim
+            pua2d(ii,ij) =  z1_2 * ( pua2d(iiUoce,ij) + zfla )
+         END IF
       END DO
       !
       igrd = 3      ! Flather bc on v-velocity
       !             ! remember that flagv=-1 if normal velocity direction is outward
-      DO jb = 1, idx%nblenrim(igrd)
-         ii  = idx%nbi(jb,igrd)
-         ij  = idx%nbj(jb,igrd) 
-         flagv => idx%flagv(jb,igrd)
-         ijm1 = ij + MAX( 0, INT( flagv ) )   ! T pts j-indice inside the boundary
-         ijp1 = ij - MIN( 0, INT( flagv ) )   ! T pts j-indice outside the boundary 
-         !
-         zcorr = - flagv * SQRT( grav * phvr(ii, ij) ) * ( pssh(ii, ijm1) - spgu(ii,ijp1) )
-
-         ! jchanut tschanges: Set zflag to 0 below to revert to std Flather scheme
-         ! Use characteristics method instead
-         zflag = ABS(flagv)
-         zforc  = dta%v2d(jb) * (1._wp - z1_2*zflag) + z1_2 * zflag * pva2d(ii,ij+NINT(flagv))
-         pva2d(ii,ij) = zforc + (1._wp - z1_2*zflag) * zcorr * vmask(ii,ij,1)
-      END DO
-      CALL lbc_bdy_lnk( 'bdydyn2d', pua2d, 'U', -1., ib_bdy )   ! Boundary points should be updated
-      CALL lbc_bdy_lnk( 'bdydyn2d', pva2d, 'V', -1., ib_bdy )   !
+      IF( llrim0 ) THEN   ;   ibeg = 1                       ;   iend = idx%nblenrim0(igrd)
+      ELSE                ;   ibeg = idx%nblenrim0(igrd)+1   ;   iend = idx%nblenrim(igrd)
+      END IF
+      DO jb = ibeg, iend
+         ii    = idx%nbi(jb,igrd)
+         ij    = idx%nbj(jb,igrd)
+         flagv = idx%flagv(jb,igrd)
+         IF( flagv == 0. ) THEN
+            pva2d(ii,ij) = dta%v2d(jb)
+         ELSE      ! T pts j-indice       on the rim          on the ocean next to the rim on T and V points
+            IF( flagv ==  1. ) THEN   ;   ijTrim = ij     ;   ijToce = ij+1   ;   ijVoce = ij+1   ;   ENDIF
+            IF( flagv == -1. ) THEN   ;   ijTrim = ij+1   ;   ijToce = ij     ;   ijVoce = ij-1   ;   ENDIF
+            !
+            ! Rare case : rim is parallel to the mpi subdomain border and on the halo : point will be received
+            IF( ijTrim > jpj .OR. ijToce > jpj .OR. ijVoce > jpj .OR. ijVoce < 1 )   CYCLE
+            !
+            zfla = dta%v2d(jb) - flagv * SQRT( grav * phvr(ii, ij) ) * ( pssh(ii,ijToce) - sshdta(ii,ijTrim) )
+            !
+            ! jchanut tschanges, use characteristics method (Blayo et Debreu, 2005) :
+            ! mix Flather scheme with velocity of the ocean next to the rim
+            pva2d(ii,ij) =  z1_2 * ( pva2d(ii,ijVoce) + zfla )
+         END IF
+      END DO
       !
    END SUBROUTINE bdy_dyn2d_fla
 
 
-   SUBROUTINE bdy_dyn2d_orlanski( idx, dta, ib_bdy, pua2d, pva2d, pub2d, pvb2d, ll_npo )
+   SUBROUTINE bdy_dyn2d_orlanski( idx, dta, ib_bdy, pua2d, pva2d, pub2d, pvb2d, llrim0, ll_npo )
       !!----------------------------------------------------------------------
       !!                 ***  SUBROUTINE bdy_dyn2d_orlanski  ***
@@ -231,5 +281,5 @@
       REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: pub2d, pvb2d 
       LOGICAL,                      INTENT(in) ::   ll_npo  ! flag for NPO version
-
+      LOGICAL,                      INTENT(in) ::   llrim0   ! indicate if rim 0 is treated
       INTEGER  ::   ib, igrd                               ! dummy loop indices
       INTEGER  ::   ii, ij, iibm1, ijbm1                   ! indices
@@ -238,12 +288,9 @@
       igrd = 2      ! Orlanski bc on u-velocity; 
       !            
-      CALL bdy_orlanski_2d( idx, igrd, pub2d, pua2d, dta%u2d, ll_npo )
+      CALL bdy_orlanski_2d( idx, igrd, pub2d, pua2d, dta%u2d, llrim0, ll_npo )
 
       igrd = 3      ! Orlanski bc on v-velocity
       !  
-      CALL bdy_orlanski_2d( idx, igrd, pvb2d, pva2d, dta%v2d, ll_npo )
-      !
-      CALL lbc_bdy_lnk( 'bdydyn2d', pua2d, 'U', -1., ib_bdy )   ! Boundary points should be updated
-      CALL lbc_bdy_lnk( 'bdydyn2d', pva2d, 'V', -1., ib_bdy )   !
+      CALL bdy_orlanski_2d( idx, igrd, pvb2d, pva2d, dta%v2d, llrim0, ll_npo )
       !
    END SUBROUTINE bdy_dyn2d_orlanski
@@ -257,36 +304,28 @@
       !!
       !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   zssh ! Sea level
-      !!
-      INTEGER  ::   ib_bdy, ib, igrd                        ! local integers
-      INTEGER  ::   ii, ij, zcoef, zcoef1, zcoef2, ip, jp   !   "       "
-
-      igrd = 1                       ! Everything is at T-points here
-
-      DO ib_bdy = 1, nb_bdy
-         DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
-            ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-            ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-            ! Set gradient direction:
-            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 = bdytmask(ii-1,ij-1) + bdytmask(ii+1,ij+1) + bdytmask(ii+1,ij-1) + bdytmask(ii-1,ij+1)
-               zssh(ii,ij) = zssh( ii-1, ij-1 ) * bdytmask( ii-1, ij-1) + &
-                 &           zssh( ii+1, ij+1 ) * bdytmask( ii+1, ij+1) + &
-                 &           zssh( ii+1, ij-1 ) * bdytmask( ii+1, ij-1) + &
-                 &           zssh( ii-1, ij+1 ) * bdytmask( ii-1, ij+1)
-               zssh(ii,ij) = ( zssh(ii,ij) / MAX( 1, zcoef) ) * tmask(ii,ij,1)
-            ELSE
-               ip = bdytmask(ii+1,ij  ) - bdytmask(ii-1,ij  )
-               jp = bdytmask(ii  ,ij+1) - bdytmask(ii  ,ij-1)
-               zssh(ii,ij) = zssh(ii+ip,ij+jp) * tmask(ii+ip,ij+jp,1)
-            ENDIF
+      REAL(wp), DIMENSION(jpi,jpj,1), INTENT(inout) ::   zssh ! Sea level, need 3 dimensions to be used by bdy_nmn
+      !!
+      INTEGER ::   ib_bdy, ir      ! bdy index, rim index
+      INTEGER ::   ibeg, iend      ! length of rim to be treated (rim 0 or rim 1)
+      LOGICAL ::   llrim0          ! indicate if rim 0 is treated
+      LOGICAL, DIMENSION(4) :: llsend1, llrecv1  ! indicate how communications are to be carried out
+      !!----------------------------------------------------------------------
+      llsend1(:) = .false.   ;   llrecv1(:) = .false.
+      DO ir = 1, 0, -1   ! treat rim 1 before rim 0
+         IF( nn_hls == 1 ) THEN   ;   llsend1(:) = .false.   ;   llrecv1(:) = .false.   ;   END IF
+         IF( ir == 0 ) THEN   ;   llrim0 = .TRUE.
+         ELSE                 ;   llrim0 = .FALSE.
+         END IF
+         DO ib_bdy = 1, nb_bdy
+            CALL bdy_nmn( idx_bdy(ib_bdy), 1, zssh, llrim0 )   ! zssh is masked
+            llsend1(:) = llsend1(:) .OR. lsend_bdyint(ib_bdy,1,:,ir)   ! possibly every direction, T points
+            llrecv1(:) = llrecv1(:) .OR. lrecv_bdyint(ib_bdy,1,:,ir)   ! possibly every direction, T points
          END DO
-
-         ! Boundary points should be updated
-         CALL lbc_bdy_lnk( 'bdydyn2d', zssh(:,:), 'T', 1., ib_bdy )
-      END DO
-
+         IF( nn_hls > 1 .AND. ir == 1 ) CYCLE   ! at least 2 halos will be corrected -> no need to correct rim 1 before rim 0
+         IF( ANY(llsend1) .OR. ANY(llrecv1) ) THEN   ! if need to send/recv in at least one direction
+            CALL lbc_lnk( 'bdydyn2d', zssh(:,:,1), 'T',  1., kfillmode=jpfillnothing ,lsend=llsend1, lrecv=llrecv1 )
+         END IF
+      END DO
+      !
    END SUBROUTINE bdy_ssh
 
Index: /NEMO/trunk/src/OCE/BDY/bdydyn3d.F90
===================================================================
--- /NEMO/trunk/src/OCE/BDY/bdydyn3d.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/BDY/bdydyn3d.F90	(revision 11536)
@@ -42,21 +42,65 @@
       INTEGER, INTENT(in) ::   kt   ! Main time step counter
       !
-      INTEGER ::   ib_bdy   ! loop index
-      !!----------------------------------------------------------------------
-      !
-      DO ib_bdy=1, nb_bdy
+      INTEGER  ::   ib_bdy, ir     ! BDY set index, rim index
+      LOGICAL  ::   llrim0         ! indicate if rim 0 is treated
+      LOGICAL, DIMENSION(4) :: llsend2, llrecv2, llsend3, llrecv3  ! indicate how communications are to be carried out
+
+      !!----------------------------------------------------------------------
+      llsend2(:) = .false.   ;   llrecv2(:) = .false.
+      llsend3(:) = .false.   ;   llrecv3(:) = .false.
+      DO ir = 1, 0, -1   ! treat rim 1 before rim 0
+         IF( ir == 0 ) THEN   ;   llrim0 = .TRUE.
+         ELSE                 ;   llrim0 = .FALSE.
+         END IF
+         DO ib_bdy=1, nb_bdy
+            !
+            SELECT CASE( cn_dyn3d(ib_bdy) )
+            CASE('none')        ;   CYCLE
+            CASE('frs' )        ! treat the whole boundary at once
+               IF( ir == 0) CALL bdy_dyn3d_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
+            CASE('specified')   ! treat the whole rim      at once
+               IF( ir == 0) CALL bdy_dyn3d_spe( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
+            CASE('zero')        ! treat the whole rim      at once
+               IF( ir == 0) CALL bdy_dyn3d_zro( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
+            CASE('orlanski' )   ;   CALL bdy_dyn3d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, llrim0, ll_npo=.false. )
+            CASE('orlanski_npo');   CALL bdy_dyn3d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, llrim0, ll_npo=.true.  )
+            CASE('zerograd')    ;   CALL bdy_dyn3d_zgrad( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy, llrim0 )
+            CASE('neumann')     ;   CALL bdy_dyn3d_nmn( idx_bdy(ib_bdy), ib_bdy, llrim0 )
+            CASE DEFAULT        ;   CALL ctl_stop( 'bdy_dyn3d : unrecognised option for open boundaries for baroclinic velocities' )
+            END SELECT
+         END DO
          !
-         SELECT CASE( cn_dyn3d(ib_bdy) )
-         CASE('none')        ;   CYCLE
-         CASE('frs' )        ;   CALL bdy_dyn3d_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
-         CASE('specified')   ;   CALL bdy_dyn3d_spe( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
-         CASE('zero')        ;   CALL bdy_dyn3d_zro( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
-         CASE('orlanski' )   ;   CALL bdy_dyn3d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, ll_npo=.false. )
-         CASE('orlanski_npo');   CALL bdy_dyn3d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, ll_npo=.true. )
-         CASE('zerograd')    ;   CALL bdy_dyn3d_zgrad( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
-         CASE('neumann')     ;   CALL bdy_dyn3d_nmn( idx_bdy(ib_bdy), ib_bdy )
-         CASE DEFAULT        ;   CALL ctl_stop( 'bdy_dyn3d : unrecognised option for open boundaries for baroclinic velocities' )
-         END SELECT
-      END DO
+         IF( nn_hls > 1 .AND. ir == 1 ) CYCLE   ! at least 2 halos will be corrected -> no need to correct rim 1 before rim 0
+         IF( nn_hls == 1 ) THEN
+            llsend2(:) = .false.   ;   llrecv2(:) = .false.
+            llsend3(:) = .false.   ;   llrecv3(:) = .false.
+         END IF
+         DO ib_bdy=1, nb_bdy
+            SELECT CASE( cn_dyn3d(ib_bdy) )
+            CASE('orlanski', 'orlanski_npo')
+               llsend2(:) = llsend2(:) .OR. lsend_bdy(ib_bdy,2,:,ir)   ! possibly every direction, U points
+               llrecv2(:) = llrecv2(:) .OR. lrecv_bdy(ib_bdy,2,:,ir)   ! possibly every direction, U points
+               llsend3(:) = llsend3(:) .OR. lsend_bdy(ib_bdy,3,:,ir)   ! possibly every direction, V points
+               llrecv3(:) = llrecv3(:) .OR. lrecv_bdy(ib_bdy,3,:,ir)   ! possibly every direction, V points
+            CASE('zerograd')
+               llsend2(3:4) = llsend2(3:4) .OR. lsend_bdyint(ib_bdy,2,3:4,ir)   ! north/south, U points
+               llrecv2(3:4) = llrecv2(3:4) .OR. lrecv_bdyint(ib_bdy,2,3:4,ir)   ! north/south, U points
+               llsend3(1:2) = llsend3(1:2) .OR. lsend_bdyint(ib_bdy,3,1:2,ir)   ! west/east, V points
+               llrecv3(1:2) = llrecv3(1:2) .OR. lrecv_bdyint(ib_bdy,3,1:2,ir)   ! west/east, V points
+            CASE('neumann')
+               llsend2(:) = llsend2(:) .OR. lsend_bdyint(ib_bdy,2,:,ir)   ! possibly every direction, U points
+               llrecv2(:) = llrecv2(:) .OR. lrecv_bdyint(ib_bdy,2,:,ir)   ! possibly every direction, U points
+               llsend3(:) = llsend3(:) .OR. lsend_bdyint(ib_bdy,3,:,ir)   ! possibly every direction, V points
+               llrecv3(:) = llrecv3(:) .OR. lrecv_bdyint(ib_bdy,3,:,ir)   ! possibly every direction, V points
+            END SELECT
+         END DO
+         !
+         IF( ANY(llsend2) .OR. ANY(llrecv2) ) THEN   ! if need to send/recv in at least one direction
+            CALL lbc_lnk( 'bdydyn2d', ua, 'U', -1., kfillmode=jpfillnothing ,lsend=llsend2, lrecv=llrecv2 )
+         END IF
+         IF( ANY(llsend3) .OR. ANY(llrecv3) ) THEN   ! if need to send/recv in at least one direction
+            CALL lbc_lnk( 'bdydyn2d', va, 'V', -1., kfillmode=jpfillnothing ,lsend=llsend3, lrecv=llrecv3 )
+         END IF
+      END DO   ! ir
       !
    END SUBROUTINE bdy_dyn3d
@@ -78,5 +122,4 @@
       INTEGER  ::   jb, jk         ! dummy loop indices
       INTEGER  ::   ii, ij, igrd   ! local integers
-      REAL(wp) ::   zwgt           ! boundary weight
       !!----------------------------------------------------------------------
       !
@@ -98,13 +141,9 @@
          END DO
       END DO
-      CALL lbc_bdy_lnk( 'bdydyn3d', ua, 'U', -1., ib_bdy )   ! Boundary points should be updated  
-      CALL lbc_bdy_lnk( 'bdydyn3d', va, 'V', -1., ib_bdy )   
-      !
-      IF( kt == nit000 )   CLOSE( unit = 102 )
       !
    END SUBROUTINE bdy_dyn3d_spe
 
 
-   SUBROUTINE bdy_dyn3d_zgrad( idx, dta, kt , ib_bdy )
+   SUBROUTINE bdy_dyn3d_zgrad( idx, dta, kt, ib_bdy, llrim0 )
       !!----------------------------------------------------------------------
       !!                  ***  SUBROUTINE bdy_dyn3d_zgrad  ***
@@ -114,39 +153,54 @@
       !!----------------------------------------------------------------------
       INTEGER                     ::   kt
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
-      INTEGER,         INTENT(in) ::   ib_bdy  ! BDY set index
+      TYPE(OBC_INDEX), INTENT(in) ::   idx      ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta      ! OBC external data
+      INTEGER,         INTENT(in) ::   ib_bdy   ! BDY set index
+      LOGICAL,         INTENT(in) ::   llrim0   ! indicate if rim 0 is treated
       !!
       INTEGER  ::   jb, jk         ! dummy loop indices
       INTEGER  ::   ii, ij, igrd   ! local integers
-      REAL(wp) ::   zwgt           ! boundary weight
-      INTEGER  ::   fu, fv
+      INTEGER  ::   flagu, flagv           ! short cuts
+      INTEGER  ::   ibeg, iend     ! length of rim to be treated (rim 0 or rim 1 or both)
       !!----------------------------------------------------------------------
       !
       igrd = 2                      ! Copying tangential velocity into bdy points
-      DO jb = 1, idx%nblenrim(igrd)
-         DO jk = 1, jpkm1
-            ii   = idx%nbi(jb,igrd)
-            ij   = idx%nbj(jb,igrd)
-            fu   = ABS( ABS (NINT( idx%flagu(jb,igrd) ) ) - 1 )
-            ua(ii,ij,jk) = ua(ii,ij,jk) * REAL( 1 - fu) + ( ua(ii,ij+fu,jk) * umask(ii,ij+fu,jk) &
-                        &+ ua(ii,ij-fu,jk) * umask(ii,ij-fu,jk) ) * umask(ii,ij,jk) * REAL( fu )
-         END DO
+      IF( llrim0 ) THEN   ;   ibeg = 1                       ;   iend = idx%nblenrim0(igrd)
+      ELSE                ;   ibeg = idx%nblenrim0(igrd)+1   ;   iend = idx%nblenrim(igrd)
+      ENDIF
+      DO jb = ibeg, iend
+         ii    = idx%nbi(jb,igrd)
+         ij    = idx%nbj(jb,igrd)
+         flagu = NINT(idx%flagu(jb,igrd))
+         flagv = NINT(idx%flagv(jb,igrd))
+         !
+         IF( flagu == 0 )   THEN              ! north/south bdy
+            IF( ij+flagv > jpj .OR. ij+flagv < 1 )   CYCLE      
+            !
+            DO jk = 1, jpkm1
+               ua(ii,ij,jk) = ua(ii,ij+flagv,jk) * umask(ii,ij+flagv,jk)
+            END DO
+            !
+         END IF
       END DO
       !
       igrd = 3                      ! Copying tangential velocity into bdy points
-      DO jb = 1, idx%nblenrim(igrd)
-         DO jk = 1, jpkm1
-            ii   = idx%nbi(jb,igrd)
-            ij   = idx%nbj(jb,igrd)
-            fv   = ABS( ABS (NINT( idx%flagv(jb,igrd) ) ) - 1 )
-            va(ii,ij,jk) = va(ii,ij,jk) * REAL( 1 - fv ) + ( va(ii+fv,ij,jk) * vmask(ii+fv,ij,jk) &
-                        &+ va(ii-fv,ij,jk) * vmask(ii-fv,ij,jk) ) * vmask(ii,ij,jk) * REAL( fv )
-         END DO
-      END DO
-      CALL lbc_bdy_lnk( 'bdydyn3d', ua, 'U', -1., ib_bdy )   ! Boundary points should be updated  
-      CALL lbc_bdy_lnk( 'bdydyn3d', va, 'V', -1., ib_bdy )   
-      !
-      IF( kt == nit000 )   CLOSE( unit = 102 )
+      IF( llrim0 ) THEN   ;   ibeg = 1                       ;   iend = idx%nblenrim0(igrd)
+      ELSE                ;   ibeg = idx%nblenrim0(igrd)+1   ;   iend = idx%nblenrim(igrd)
+      ENDIF
+      DO jb = ibeg, iend
+         ii    = idx%nbi(jb,igrd)
+         ij    = idx%nbj(jb,igrd)
+         flagu = NINT(idx%flagu(jb,igrd))
+         flagv = NINT(idx%flagv(jb,igrd))
+         !
+         IF( flagv == 0 )   THEN              !  west/east  bdy
+            IF( ii+flagu > jpi .OR. ii+flagu < 1 )   CYCLE      
+            !
+            DO jk = 1, jpkm1
+               va(ii,ij,jk) = va(ii+flagu,ij,jk) * vmask(ii+flagu,ij,jk)
+            END DO
+            !
+         END IF
+      END DO
       !
    END SUBROUTINE bdy_dyn3d_zgrad
@@ -167,5 +221,4 @@
       INTEGER  ::   ib, ik         ! dummy loop indices
       INTEGER  ::   ii, ij, igrd   ! local integers
-      REAL(wp) ::   zwgt           ! boundary weight
       !!----------------------------------------------------------------------
       !
@@ -178,5 +231,5 @@
          END DO
       END DO
-
+      !
       igrd = 3                       ! Everything is at T-points here
       DO ib = 1, idx%nblenrim(igrd)
@@ -187,8 +240,4 @@
          END DO
       END DO
-      !
-      CALL lbc_bdy_lnk( 'bdydyn3d', ua, 'U', -1., ib_bdy )   ;   CALL lbc_bdy_lnk( 'bdydyn3d', va, 'V', -1.,ib_bdy )   ! Boundary points should be updated
-      !
-      IF( kt == nit000 )   CLOSE( unit = 102 )
       !
    END SUBROUTINE bdy_dyn3d_zro
@@ -234,14 +283,10 @@
             va(ii,ij,jk) = ( va(ii,ij,jk) + zwgt * ( dta%v3d(jb,jk) - va(ii,ij,jk) ) ) * vmask(ii,ij,jk)
          END DO
-      END DO 
-      CALL lbc_bdy_lnk( 'bdydyn3d', ua, 'U', -1., ib_bdy )    ! Boundary points should be updated
-      CALL lbc_bdy_lnk( 'bdydyn3d', va, 'V', -1., ib_bdy )   
-      !
-      IF( kt == nit000 )   CLOSE( unit = 102 )
+      END DO   
       !
    END SUBROUTINE bdy_dyn3d_frs
 
 
-   SUBROUTINE bdy_dyn3d_orlanski( idx, dta, ib_bdy, ll_npo )
+   SUBROUTINE bdy_dyn3d_orlanski( idx, dta, ib_bdy, llrim0, ll_npo )
       !!----------------------------------------------------------------------
       !!                 ***  SUBROUTINE bdy_dyn3d_orlanski  ***
@@ -255,6 +300,7 @@
       TYPE(OBC_INDEX),              INTENT(in) ::   idx  ! OBC indices
       TYPE(OBC_DATA),               INTENT(in) ::   dta  ! OBC external data
-      INTEGER,                      INTENT(in) ::   ib_bdy  ! BDY set index
-      LOGICAL,                      INTENT(in) ::   ll_npo  ! switch for NPO version
+      INTEGER,                      INTENT(in) ::   ib_bdy   ! BDY set index
+      LOGICAL,                      INTENT(in) ::   llrim0   ! indicate if rim 0 is treated
+      LOGICAL,                      INTENT(in) ::   ll_npo   ! switch for NPO version
 
       INTEGER  ::   jb, igrd                               ! dummy loop indices
@@ -265,12 +311,9 @@
       igrd = 2      ! Orlanski bc on u-velocity; 
       !            
-      CALL bdy_orlanski_3d( idx, igrd, ub, ua, dta%u3d, ll_npo )
+      CALL bdy_orlanski_3d( idx, igrd, ub, ua, dta%u3d, ll_npo, llrim0 )
 
       igrd = 3      ! Orlanski bc on v-velocity
       !  
-      CALL bdy_orlanski_3d( idx, igrd, vb, va, dta%v3d, ll_npo )
-      !
-      CALL lbc_bdy_lnk( 'bdydyn3d', ua, 'U', -1., ib_bdy )    ! Boundary points should be updated
-      CALL lbc_bdy_lnk( 'bdydyn3d', va, 'V', -1., ib_bdy )   
+      CALL bdy_orlanski_3d( idx, igrd, vb, va, dta%v3d, ll_npo, llrim0 )
       !
    END SUBROUTINE bdy_dyn3d_orlanski
@@ -320,6 +363,4 @@
       END DO
       !
-      CALL lbc_lnk_multi( 'bdydyn3d', ua, 'U', -1.,  va, 'V', -1. )   ! Boundary points should be updated
-      !
       IF( ln_timing )   CALL timing_stop('bdy_dyn3d_dmp')
       !
@@ -327,5 +368,5 @@
 
 
-   SUBROUTINE bdy_dyn3d_nmn( idx, ib_bdy )
+   SUBROUTINE bdy_dyn3d_nmn( idx, ib_bdy, llrim0 )
       !!----------------------------------------------------------------------
       !!                 ***  SUBROUTINE bdy_dyn3d_nmn  ***
@@ -336,8 +377,8 @@
       !!
       !!----------------------------------------------------------------------
-      TYPE(OBC_INDEX),              INTENT(in) ::   idx  ! OBC indices
-      INTEGER,                      INTENT(in) ::   ib_bdy  ! BDY set index
-
-      INTEGER  ::   jb, igrd                               ! dummy loop indices
+      TYPE(OBC_INDEX), INTENT(in) ::   idx      ! OBC indices
+      INTEGER,         INTENT(in) ::   ib_bdy   ! BDY set index
+      LOGICAL,         INTENT(in) ::   llrim0   ! indicate if rim 0 is treated
+      INTEGER  ::   igrd                        ! dummy indice
       !!----------------------------------------------------------------------
       !
@@ -346,12 +387,9 @@
       igrd = 2      ! Neumann bc on u-velocity; 
       !            
-      CALL bdy_nmn( idx, igrd, ua )
+      CALL bdy_nmn( idx, igrd, ua, llrim0 )   ! ua is masked
 
       igrd = 3      ! Neumann bc on v-velocity
       !  
-      CALL bdy_nmn( idx, igrd, va )
-      !
-      CALL lbc_bdy_lnk( 'bdydyn3d', ua, 'U', -1., ib_bdy )    ! Boundary points should be updated
-      CALL lbc_bdy_lnk( 'bdydyn3d', va, 'V', -1., ib_bdy )
+      CALL bdy_nmn( idx, igrd, va, llrim0 )   ! va is masked
       !
    END SUBROUTINE bdy_dyn3d_nmn
Index: /NEMO/trunk/src/OCE/BDY/bdyice.F90
===================================================================
--- /NEMO/trunk/src/OCE/BDY/bdyice.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/BDY/bdyice.F90	(revision 11536)
@@ -55,22 +55,52 @@
       INTEGER, INTENT(in) ::   kt   ! Main time step counter
       !
-      INTEGER ::   jbdy   ! BDY set index
+      INTEGER ::   jbdy, ir                             ! BDY set index, rim index
+      INTEGER ::   ibeg, iend                           ! length of rim to be treated (rim 0 or rim 1)
+      LOGICAL ::   llrim0                               ! indicate if rim 0 is treated
+      LOGICAL, DIMENSION(4)  :: llsend1, llrecv1        ! indicate how communications are to be carried out
       !!----------------------------------------------------------------------
       ! controls
       IF( ln_timing    )   CALL timing_start('bdy_ice_thd')                                                            ! timing
       IF( ln_icediachk )   CALL ice_cons_hsm(0,'bdy_ice_thd', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+      IF( ln_icediachk )   CALL ice_cons2D  (0,'bdy_ice_thd',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft) ! conservation
       !
       CALL ice_var_glo2eqv
       !
-      DO jbdy = 1, nb_bdy
+      llsend1(:) = .false.   ;   llrecv1(:) = .false.
+      DO ir = 1, 0, -1   ! treat rim 1 before rim 0
+         IF( ir == 0 ) THEN   ;   llrim0 = .TRUE.
+         ELSE                 ;   llrim0 = .FALSE.
+         END IF
+         DO jbdy = 1, nb_bdy
+            !
+            SELECT CASE( cn_ice(jbdy) )
+            CASE('none')   ;   CYCLE
+            CASE('frs' )   ;   CALL bdy_ice_frs( idx_bdy(jbdy), dta_bdy(jbdy), kt, jbdy, llrim0 )
+            CASE DEFAULT
+               CALL ctl_stop( 'bdy_ice : unrecognised option for open boundaries for ice fields' )
+            END SELECT
+            !
+         END DO
          !
-         SELECT CASE( cn_ice(jbdy) )
-         CASE('none')   ;   CYCLE
-         CASE('frs' )   ;   CALL bdy_ice_frs( idx_bdy(jbdy), dta_bdy(jbdy), kt, jbdy )
-         CASE DEFAULT
-            CALL ctl_stop( 'bdy_ice : unrecognised option for open boundaries for ice fields' )
-         END SELECT
-         !
-      END DO
+         ! Update bdy points        
+         IF( nn_hls > 1 .AND. ir == 1 ) CYCLE   ! at least 2 halos will be corrected -> no need to correct rim 1 before rim 0
+         IF( nn_hls == 1 ) THEN   ;   llsend1(:) = .false.   ;   llrecv1(:) = .false.   ;   END IF
+         DO jbdy = 1, nb_bdy
+            IF( cn_ice(jbdy) == 'frs' ) THEN
+               llsend1(:) = llsend1(:) .OR. lsend_bdyint(jbdy,1,:,ir)   ! possibly every direction, T points
+               llrecv1(:) = llrecv1(:) .OR. lrecv_bdyint(jbdy,1,:,ir)   ! possibly every direction, T points
+            END IF
+         END DO   ! jbdy
+         IF( ANY(llsend1) .OR. ANY(llrecv1) ) THEN   ! if need to send/recv in at least one direction
+            ! exchange 3d arrays
+            CALL lbc_lnk_multi( 'bdyice', a_i , 'T', 1., h_i , 'T', 1., h_s , 'T', 1., oa_i, 'T', 1. &
+                 &                      , a_ip, 'T', 1., v_ip, 'T', 1., s_i , 'T', 1., t_su, 'T', 1. &
+                 &                      , v_i , 'T', 1., v_s , 'T', 1., sv_i, 'T', 1.                &
+                 &                      , kfillmode=jpfillnothing ,lsend=llsend1, lrecv=llrecv1      )
+            ! exchange 4d arrays :   third dimension = 1   and then   third dimension = jpk
+            CALL lbc_lnk_multi( 'bdyice', t_s , 'T', 1., e_s , 'T', 1., kfillmode=jpfillnothing ,lsend=llsend1, lrecv=llrecv1 )
+            CALL lbc_lnk_multi( 'bdyice', t_i , 'T', 1., e_i , 'T', 1., kfillmode=jpfillnothing ,lsend=llsend1, lrecv=llrecv1 )
+         END IF
+      END DO   ! ir
       !
       CALL ice_cor( kt , 0 )      ! -- In case categories are out of bounds, do a remapping
@@ -80,6 +110,7 @@
       !
       ! controls
+      IF( ln_icectl    )   CALL ice_prt     ( kt, iiceprt, jiceprt, 1, ' - ice thermo bdy - ' )                        ! prints
       IF( ln_icediachk )   CALL ice_cons_hsm(1,'bdy_ice_thd', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
-      IF( ln_icectl    )   CALL ice_prt     ( kt, iiceprt, jiceprt, 1, ' - ice thermo bdy - ' )                        ! prints
+      IF( ln_icediachk )   CALL ice_cons2D  (1,'bdy_ice_thd',  diag_v,  diag_s,  diag_t,  diag_fv,  diag_fs,  diag_ft) ! conservation
       IF( ln_timing    )   CALL timing_stop ('bdy_ice_thd')                                                            ! timing
       !
@@ -87,5 +118,5 @@
 
 
-   SUBROUTINE bdy_ice_frs( idx, dta, kt, jbdy )
+   SUBROUTINE bdy_ice_frs( idx, dta, kt, jbdy, llrim0 )
       !!------------------------------------------------------------------------------
       !!                 ***  SUBROUTINE bdy_ice_frs  ***
@@ -96,29 +127,49 @@
       !!             dimensional baroclinic ocean model with realistic topography. Tellus, 365-382.
       !!------------------------------------------------------------------------------
-      TYPE(OBC_INDEX), INTENT(in) ::   idx     ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta     ! OBC external data
-      INTEGER,         INTENT(in) ::   kt      ! main time-step counter
-      INTEGER,         INTENT(in) ::   jbdy    ! BDY set index
+      TYPE(OBC_INDEX), INTENT(in) ::   idx      ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta      ! OBC external data
+      INTEGER,         INTENT(in) ::   kt       ! main time-step counter
+      INTEGER,         INTENT(in) ::   jbdy     ! BDY set index
+      LOGICAL,         INTENT(in) ::   llrim0   ! indicate if rim 0 is treated
       !
       INTEGER  ::   jpbound            ! 0 = incoming ice
       !                                ! 1 = outgoing ice
+      INTEGER  ::   ibeg, iend         ! length of rim to be treated (rim 0 or rim 1)
       INTEGER  ::   i_bdy, jgrd        ! dummy loop indices
       INTEGER  ::   ji, jj, jk, jl, ib, jb
       REAL(wp) ::   zwgt, zwgt1        ! local scalar
       REAL(wp) ::   ztmelts, zdh
+      REAL(wp), POINTER  :: flagu, flagv              ! short cuts
       !!------------------------------------------------------------------------------
       !
       jgrd = 1      ! Everything is at T-points here
+      IF( llrim0 ) THEN   ;   ibeg = 1                       ;   iend = idx%nblenrim0(jgrd)
+      ELSE                ;   ibeg = idx%nblenrim0(jgrd)+1   ;   iend = idx%nblenrim(jgrd)
+      END IF
       !
       DO jl = 1, jpl
-         DO i_bdy = 1, idx%nblenrim(jgrd)
+         DO i_bdy = ibeg, iend
             ji    = idx%nbi(i_bdy,jgrd)
             jj    = idx%nbj(i_bdy,jgrd)
             zwgt  = idx%nbw(i_bdy,jgrd)
             zwgt1 = 1.e0 - idx%nbw(i_bdy,jgrd)
-            a_i(ji,jj,jl) = ( a_i(ji,jj,jl) * zwgt1 + dta%a_i(i_bdy,jl) * zwgt ) * tmask(ji,jj,1)  ! Leads fraction 
-            h_i(ji,jj,jl) = ( h_i(ji,jj,jl) * zwgt1 + dta%h_i(i_bdy,jl) * zwgt ) * tmask(ji,jj,1)  ! Ice depth 
-            h_s(ji,jj,jl) = ( h_s(ji,jj,jl) * zwgt1 + dta%h_s(i_bdy,jl) * zwgt ) * tmask(ji,jj,1)  ! Snow depth
-
+            a_i (ji,jj,  jl) = ( a_i (ji,jj,  jl) * zwgt1 + dta%a_i(i_bdy,jl) * zwgt ) * tmask(ji,jj,1)  ! Ice  concentration 
+            h_i (ji,jj,  jl) = ( h_i (ji,jj,  jl) * zwgt1 + dta%h_i(i_bdy,jl) * zwgt ) * tmask(ji,jj,1)  ! Ice  depth 
+            h_s (ji,jj,  jl) = ( h_s (ji,jj,  jl) * zwgt1 + dta%h_s(i_bdy,jl) * zwgt ) * tmask(ji,jj,1)  ! Snow depth
+            t_i (ji,jj,:,jl) = ( t_i (ji,jj,:,jl) * zwgt1 + dta%t_i(i_bdy,jl) * zwgt ) * tmask(ji,jj,1)  ! Ice  temperature
+            t_s (ji,jj,:,jl) = ( t_s (ji,jj,:,jl) * zwgt1 + dta%t_s(i_bdy,jl) * zwgt ) * tmask(ji,jj,1)  ! Snow temperature
+            t_su(ji,jj,  jl) = ( t_su(ji,jj,  jl) * zwgt1 + dta%tsu(i_bdy,jl) * zwgt ) * tmask(ji,jj,1)  ! Surf temperature
+            s_i (ji,jj,  jl) = ( s_i (ji,jj,  jl) * zwgt1 + dta%s_i(i_bdy,jl) * zwgt ) * tmask(ji,jj,1)  ! Ice  salinity
+            a_ip(ji,jj,  jl) = ( a_ip(ji,jj,  jl) * zwgt1 + dta%aip(i_bdy,jl) * zwgt ) * tmask(ji,jj,1)  ! Ice  pond concentration
+            h_ip(ji,jj,  jl) = ( h_ip(ji,jj,  jl) * zwgt1 + dta%hip(i_bdy,jl) * zwgt ) * tmask(ji,jj,1)  ! Ice  pond depth
+            !
+            sz_i(ji,jj,:,jl) = s_i(ji,jj,jl)
+            !
+            ! make sure ponds = 0 if no ponds scheme
+            IF( .NOT.ln_pnd ) THEN
+               a_ip(ji,jj,jl) = 0._wp
+               h_ip(ji,jj,jl) = 0._wp
+            ENDIF
+            !
             ! -----------------
             ! Pathological case
@@ -135,24 +186,34 @@
             h_i(ji,jj,jl) = MIN( hi_max(jl), h_i(ji,jj,jl) + zdh )
             h_s(ji,jj,jl) = MAX( 0._wp, h_s(ji,jj,jl) - zdh * rhoi / rhos ) 
-
+            !
          ENDDO
       ENDDO
-      CALL lbc_bdy_lnk( 'bdyice', a_i(:,:,:), 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', h_i(:,:,:), 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', h_s(:,:,:), 'T', 1., jbdy )
 
       DO jl = 1, jpl
-         DO i_bdy = 1, idx%nblenrim(jgrd)
+         DO i_bdy = ibeg, iend
             ji = idx%nbi(i_bdy,jgrd)
             jj = idx%nbj(i_bdy,jgrd)
-
+            flagu => idx%flagu(i_bdy,jgrd)
+            flagv => idx%flagv(i_bdy,jgrd)
             ! condition on ice thickness depends on the ice velocity
             ! if velocity is outward (strictly), then ice thickness, volume... must be equal to adjacent values
             jpbound = 0   ;   ib = ji   ;   jb = jj
             !
-            IF( u_ice(ji  ,jj  ) < 0. .AND. umask(ji-1,jj  ,1) == 0. )   jpbound = 1 ; ib = ji+1
-            IF( u_ice(ji-1,jj  ) > 0. .AND. umask(ji  ,jj  ,1) == 0. )   jpbound = 1 ; ib = ji-1
-            IF( v_ice(ji  ,jj  ) < 0. .AND. vmask(ji  ,jj-1,1) == 0. )   jpbound = 1 ; jb = jj+1
-            IF( v_ice(ji  ,jj-1) > 0. .AND. vmask(ji  ,jj  ,1) == 0. )   jpbound = 1 ; jb = jj-1
+            IF( flagu ==  1. )   THEN
+               IF( ji+1 > jpi )   CYCLE
+               IF( u_ice(ji  ,jj  ) < 0. )   jpbound = 1 ; ib = ji+1
+            END IF
+            IF( flagu == -1. )   THEN
+               IF( ji-1 < 1   )   CYCLE
+               IF( u_ice(ji-1,jj  ) < 0. )   jpbound = 1 ; ib = ji-1
+            END IF
+            IF( flagv ==  1. )   THEN
+               IF( jj+1 > jpj )   CYCLE
+               IF( v_ice(ji  ,jj  ) < 0. )   jpbound = 1 ; jb = jj+1
+            END IF
+            IF( flagv == -1. )   THEN
+               IF( jj-1 < 1   )   CYCLE
+               IF( v_ice(ji  ,jj-1) < 0. )   jpbound = 1 ; jb = jj-1
+            END IF
             !
             IF( nn_ice_dta(jbdy) == 0 )   jpbound = 0 ; ib = ji ; jb = jj   ! case ice boundaries = initial conditions
@@ -161,33 +222,22 @@
             IF( a_i(ib,jb,jl) > 0._wp ) THEN   ! there is ice at the boundary
                !
-               a_i(ji,jj,jl) = a_i(ib,jb,jl) ! concentration
-               h_i(ji,jj,jl) = h_i(ib,jb,jl) ! thickness ice
-               h_s(ji,jj,jl) = h_s(ib,jb,jl) ! thickness snw
-               !
-               SELECT CASE( jpbound )
-                  !
-               CASE( 0 )   ! velocity is inward
-                  !
-                  oa_i(ji,jj,  jl) = rn_ice_age(jbdy) * a_i(ji,jj,jl) ! age
-                  a_ip(ji,jj,  jl) = 0._wp                            ! pond concentration
-                  v_ip(ji,jj,  jl) = 0._wp                            ! pond volume
-                  t_su(ji,jj,  jl) = rn_ice_tem(jbdy)                 ! temperature surface
-                  t_s (ji,jj,:,jl) = rn_ice_tem(jbdy)                 ! temperature snw
-                  t_i (ji,jj,:,jl) = rn_ice_tem(jbdy)                 ! temperature ice
-                  s_i (ji,jj,  jl) = rn_ice_sal(jbdy)                 ! salinity
-                  sz_i(ji,jj,:,jl) = rn_ice_sal(jbdy)                 ! salinity profile
-                  !
-               CASE( 1 )   ! velocity is outward
-                  !
-                  oa_i(ji,jj,  jl) = oa_i(ib,jb,  jl) ! age
-                  a_ip(ji,jj,  jl) = a_ip(ib,jb,  jl) ! pond concentration
-                  v_ip(ji,jj,  jl) = v_ip(ib,jb,  jl) ! pond volume
-                  t_su(ji,jj,  jl) = t_su(ib,jb,  jl) ! temperature surface
-                  t_s (ji,jj,:,jl) = t_s (ib,jb,:,jl) ! temperature snw
-                  t_i (ji,jj,:,jl) = t_i (ib,jb,:,jl) ! temperature ice
-                  s_i (ji,jj,  jl) = s_i (ib,jb,  jl) ! salinity
-                  sz_i(ji,jj,:,jl) = sz_i(ib,jb,:,jl) ! salinity profile
-                  !
-               END SELECT
+               a_i (ji,jj,  jl) = a_i (ib,jb,  jl)
+               h_i (ji,jj,  jl) = h_i (ib,jb,  jl)
+               h_s (ji,jj,  jl) = h_s (ib,jb,  jl)
+               t_i (ji,jj,:,jl) = t_i (ib,jb,:,jl)
+               t_s (ji,jj,:,jl) = t_s (ib,jb,:,jl)
+               t_su(ji,jj,  jl) = t_su(ib,jb,  jl)
+               s_i (ji,jj,  jl) = s_i (ib,jb,  jl)
+               a_ip(ji,jj,  jl) = a_ip(ib,jb,  jl)
+               h_ip(ji,jj,  jl) = h_ip(ib,jb,  jl)
+               !
+               sz_i(ji,jj,:,jl) = sz_i(ib,jb,:,jl)
+               !
+               ! ice age
+               IF    ( jpbound == 0 ) THEN  ! velocity is inward
+                  oa_i(ji,jj,jl) = rice_age(jbdy) * a_i(ji,jj,jl)
+               ELSEIF( jpbound == 1 ) THEN  ! velocity is outward
+                  oa_i(ji,jj,jl) = oa_i(ib,jb,jl)
+               ENDIF
                !
                IF( nn_icesal == 1 ) THEN     ! if constant salinity
@@ -214,4 +264,12 @@
                END DO
                !
+               ! melt ponds
+               IF( a_i(ji,jj,jl) > epsi10 ) THEN
+                  a_ip_frac(ji,jj,jl) = a_ip(ji,jj,jl) / a_i (ji,jj,jl)
+               ELSE
+                  a_ip_frac(ji,jj,jl) = 0._wp
+               ENDIF
+               v_ip(ji,jj,jl) = h_ip(ji,jj,jl) * a_ip(ji,jj,jl)
+               !
             ELSE   ! no ice at the boundary
                !
@@ -225,4 +283,9 @@
                t_s (ji,jj,:,jl) = rt0
                t_i (ji,jj,:,jl) = rt0 
+
+               a_ip_frac(ji,jj,jl) = 0._wp
+               h_ip     (ji,jj,jl) = 0._wp
+               a_ip     (ji,jj,jl) = 0._wp
+               v_ip     (ji,jj,jl) = 0._wp
                
                IF( nn_icesal == 1 ) THEN     ! if constant salinity
@@ -246,20 +309,4 @@
          !
       END DO ! jl
-
-      CALL lbc_bdy_lnk( 'bdyice', a_i (:,:,:)  , 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', h_i (:,:,:)  , 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', h_s (:,:,:)  , 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', oa_i(:,:,:)  , 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', a_ip(:,:,:)  , 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', v_ip(:,:,:)  , 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', s_i (:,:,:)  , 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', t_su(:,:,:)  , 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', v_i (:,:,:)  , 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', v_s (:,:,:)  , 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', sv_i(:,:,:)  , 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', t_s (:,:,:,:), 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', e_s (:,:,:,:), 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', t_i (:,:,:,:), 'T', 1., jbdy )
-      CALL lbc_bdy_lnk( 'bdyice', e_i (:,:,:,:), 'T', 1., jbdy )
       !      
    END SUBROUTINE bdy_ice_frs
@@ -279,77 +326,132 @@
       CHARACTER(len=1), INTENT(in)  ::   cd_type   ! nature of velocity grid-points
       !
-      INTEGER  ::   i_bdy, jgrd      ! dummy loop indices
-      INTEGER  ::   ji, jj           ! local scalar
-      INTEGER  ::   jbdy             ! BDY set index
+      INTEGER  ::   i_bdy, jgrd       ! dummy loop indices
+      INTEGER  ::   ji, jj            ! local scalar
+      INTEGER  ::   jbdy, ir     ! BDY set index, rim index
+      INTEGER  ::   ibeg, iend   ! length of rim to be treated (rim 0 or rim 1)
       REAL(wp) ::   zmsk1, zmsk2, zflag
+      LOGICAL, DIMENSION(4) :: llsend2, llrecv2, llsend3, llrecv3  ! indicate how communications are to be carried out
       !!------------------------------------------------------------------------------
       IF( ln_timing )   CALL timing_start('bdy_ice_dyn')
       !
-      DO jbdy=1, nb_bdy
+      llsend2(:) = .false.   ;   llrecv2(:) = .false.
+      llsend3(:) = .false.   ;   llrecv3(:) = .false.
+      DO ir = 1, 0, -1
+         DO jbdy = 1, nb_bdy
+            !
+            SELECT CASE( cn_ice(jbdy) )
+               !
+            CASE('none')
+               CYCLE
+               !
+            CASE('frs')
+               !
+               IF( nn_ice_dta(jbdy) == 0 ) CYCLE            ! case ice boundaries = initial conditions 
+               !                                            !      do not change ice velocity (it is only computed by rheology)
+               SELECT CASE ( cd_type )
+                  !     
+               CASE ( 'U' )  
+                  jgrd = 2      ! u velocity
+                  IF( ir == 0 ) THEN   ;   ibeg = 1                                 ;   iend = idx_bdy(jbdy)%nblenrim0(jgrd)
+                  ELSE                 ;   ibeg = idx_bdy(jbdy)%nblenrim0(jgrd)+1   ;   iend = idx_bdy(jbdy)%nblenrim(jgrd)
+                  END IF
+                  DO i_bdy = ibeg, iend
+                     ji    = idx_bdy(jbdy)%nbi(i_bdy,jgrd)
+                     jj    = idx_bdy(jbdy)%nbj(i_bdy,jgrd)
+                     zflag = idx_bdy(jbdy)%flagu(i_bdy,jgrd)
+                     !     i-1  i   i    |  !        i  i i+1 |  !          i  i i+1 |
+                     !      >  ice  >    |  !        o  > ice |  !          o  >  o  |      
+                     ! => set at u_ice(i-1) !  => set to O       !  => unchanged
+                     IF( zflag == -1. .AND. ji > 1 .AND. ji < jpi )   THEN  
+                        IF    ( vt_i(ji  ,jj) > 0. )   THEN   ;   u_ice(ji,jj) = u_ice(ji-1,jj) 
+                        ELSEIF( vt_i(ji+1,jj) > 0. )   THEN   ;   u_ice(ji,jj) = 0._wp
+                        END IF
+                     END IF
+                     ! |    i  i+1 i+1        !  |  i   i i+1        !  | i  i i+1
+                     ! |    >  ice  >         !  | ice  >  o         !  | o  >  o   
+                     ! => set at u_ice(i+1)   !     => set to O      !     =>  unchanged
+                     IF( zflag ==  1. .AND. ji+1 < jpi+1 )   THEN
+                        IF    ( vt_i(ji+1,jj) > 0. )   THEN   ;   u_ice(ji,jj) = u_ice(ji+1,jj)
+                        ELSEIF( vt_i(ji  ,jj) > 0. )   THEN   ;   u_ice(ji,jj) = 0._wp
+                        END IF
+                     END IF
+                     !
+                     IF( zflag ==  0. )   u_ice(ji,jj) = 0._wp   ! u_ice = 0  if north/south bdy  
+                     !
+                  END DO
+                  !
+               CASE ( 'V' )
+                  jgrd = 3      ! v velocity
+                  IF( ir == 0 ) THEN   ;   ibeg = 1                                 ;   iend = idx_bdy(jbdy)%nblenrim0(jgrd)
+                  ELSE                 ;   ibeg = idx_bdy(jbdy)%nblenrim0(jgrd)+1   ;   iend = idx_bdy(jbdy)%nblenrim(jgrd)
+                  END IF
+                  DO i_bdy = ibeg, iend
+                     ji    = idx_bdy(jbdy)%nbi(i_bdy,jgrd)
+                     jj    = idx_bdy(jbdy)%nbj(i_bdy,jgrd)
+                     zflag = idx_bdy(jbdy)%flagv(i_bdy,jgrd)
+                     !                         !      ice   (jj+1)       !       o    (jj+1)
+                     !       ^    (jj  )       !       ^    (jj  )       !       ^    (jj  )       
+                     !      ice   (jj  )       !       o    (jj  )       !       o    (jj  )       
+                     !       ^    (jj-1)       !                         !
+                     ! => set to u_ice(jj-1)   !  =>   set to 0          !   => unchanged        
+                     IF( zflag == -1. .AND. jj > 1 .AND. jj < jpj )   THEN                 
+                        IF    ( vt_i(ji,jj  ) > 0. )   THEN   ;   v_ice(ji,jj) = v_ice(ji,jj-1)
+                        ELSEIF( vt_i(ji,jj+1) > 0. )   THEN   ;   v_ice(ji,jj) = 0._wp
+                        END IF
+                     END IF
+                     !       ^    (jj+1)       !                         !              
+                     !      ice   (jj+1)       !       o    (jj+1)       !       o    (jj+1)       
+                     !       ^    (jj  )       !       ^    (jj  )       !       ^    (jj  )
+                     !   ________________      !  ____ice___(jj  )_      !  _____o____(jj  ) 
+                     ! => set to u_ice(jj+1)   !    => set to 0          !    => unchanged  
+                     IF( zflag ==  1. .AND. jj < jpj )   THEN              
+                        IF    ( vt_i(ji,jj+1) > 0. )   THEN   ;   v_ice(ji,jj) = v_ice(ji,jj+1)
+                        ELSEIF( vt_i(ji,jj  ) > 0. )   THEN   ;   v_ice(ji,jj) = 0._wp
+                        END IF
+                     END IF
+                     !
+                     IF( zflag ==  0. )   v_ice(ji,jj) = 0._wp   ! v_ice = 0  if west/east bdy  
+                     !
+                  END DO
+                  !
+               END SELECT
+               !
+            CASE DEFAULT
+               CALL ctl_stop( 'bdy_ice_dyn : unrecognised option for open boundaries for ice fields' )
+            END SELECT
+            !
+         END DO    ! jbdy
          !
-         SELECT CASE( cn_ice(jbdy) )
-         !
-         CASE('none')
-            CYCLE
-            !
-         CASE('frs')
-            !
-            IF( nn_ice_dta(jbdy) == 0 ) CYCLE            ! case ice boundaries = initial conditions 
-            !                                            !      do not change ice velocity (it is only computed by rheology)
-            SELECT CASE ( cd_type )
-            !     
-            CASE ( 'U' )  
-               jgrd = 2      ! u velocity
-               DO i_bdy = 1, idx_bdy(jbdy)%nblenrim(jgrd)
-                  ji    = idx_bdy(jbdy)%nbi(i_bdy,jgrd)
-                  jj    = idx_bdy(jbdy)%nbj(i_bdy,jgrd)
-                  zflag = idx_bdy(jbdy)%flagu(i_bdy,jgrd)
-                  !
-                  IF ( ABS( zflag ) == 1. ) THEN  ! eastern and western boundaries
-                     ! one of the two zmsk is always 0 (because of zflag)
-                     zmsk1 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji+1,jj) ) ) ! 0 if no ice
-                     zmsk2 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji,jj) ) )   ! 0 if no ice
-                     !  
-                     ! u_ice = u_ice of the adjacent grid point except if this grid point is ice-free (then do not change u_ice)
-                     u_ice (ji,jj) = u_ice(ji+1,jj) * 0.5_wp * ABS( zflag + 1._wp ) * zmsk1 + &
-                        &            u_ice(ji-1,jj) * 0.5_wp * ABS( zflag - 1._wp ) * zmsk2 + &
-                        &            u_ice(ji  ,jj) * ( 1._wp - MIN( 1._wp, zmsk1 + zmsk2 ) )
-                  ELSE                             ! everywhere else
-                     u_ice(ji,jj) = 0._wp
-                  ENDIF
-                  !
-               END DO
-               CALL lbc_bdy_lnk( 'bdyice', u_ice(:,:), 'U', -1., jbdy )
-               !
-            CASE ( 'V' )
-               jgrd = 3      ! v velocity
-               DO i_bdy = 1, idx_bdy(jbdy)%nblenrim(jgrd)
-                  ji    = idx_bdy(jbdy)%nbi(i_bdy,jgrd)
-                  jj    = idx_bdy(jbdy)%nbj(i_bdy,jgrd)
-                  zflag = idx_bdy(jbdy)%flagv(i_bdy,jgrd)
-                  !
-                  IF ( ABS( zflag ) == 1. ) THEN  ! northern and southern boundaries
-                     ! one of the two zmsk is always 0 (because of zflag)
-                     zmsk1 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji,jj+1) ) ) ! 0 if no ice
-                     zmsk2 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji,jj) ) )   ! 0 if no ice
-                     !  
-                     ! v_ice = v_ice of the adjacent grid point except if this grid point is ice-free (then do not change v_ice)
-                     v_ice (ji,jj) = v_ice(ji,jj+1) * 0.5_wp * ABS( zflag + 1._wp ) * zmsk1 + &
-                        &            v_ice(ji,jj-1) * 0.5_wp * ABS( zflag - 1._wp ) * zmsk2 + &
-                        &            v_ice(ji,jj  ) * ( 1._wp - MIN( 1._wp, zmsk1 + zmsk2 ) )
-                  ELSE                             ! everywhere else
-                     v_ice(ji,jj) = 0._wp
-                  ENDIF
-                  !
-               END DO
-               CALL lbc_bdy_lnk( 'bdyice', v_ice(:,:), 'V', -1., jbdy )
-               !
-            END SELECT
-            !
-         CASE DEFAULT
-            CALL ctl_stop( 'bdy_ice_dyn : unrecognised option for open boundaries for ice fields' )
+         SELECT CASE ( cd_type )        
+         CASE ( 'U' ) 
+         IF( nn_hls > 1 .AND. ir == 1 ) CYCLE   ! at least 2 halos will be corrected -> no need to correct rim 1 before rim 0
+         IF( nn_hls == 1 ) THEN   ;   llsend2(:) = .false.   ;   llrecv2(:) = .false.   ;   END IF
+            DO jbdy = 1, nb_bdy
+               IF( cn_ice(jbdy) == 'frs' .AND. nn_ice_dta(jbdy) /= 0 ) THEN
+                  llsend2(:) = llsend2(:) .OR. lsend_bdyint(jbdy,2,:,ir)   ! possibly every direction, U points
+                  llsend2(1) = llsend2(1) .OR. lsend_bdyext(jbdy,2,1,ir)   ! neighbour might search point towards its west bdy
+                  llrecv2(:) = llrecv2(:) .OR. lrecv_bdyint(jbdy,2,:,ir)   ! possibly every direction, U points
+                  llrecv2(2) = llrecv2(2) .OR. lrecv_bdyext(jbdy,2,2,ir)   ! might search point towards east bdy
+               END IF
+            END DO
+            IF( ANY(llsend2) .OR. ANY(llrecv2) ) THEN   ! if need to send/recv in at least one direction
+               CALL lbc_lnk( 'bdyice', u_ice, 'U', -1., kfillmode=jpfillnothing ,lsend=llsend2, lrecv=llrecv2 )
+            END IF
+         CASE ( 'V' )
+         IF( nn_hls > 1 .AND. ir == 1 ) CYCLE   ! at least 2 halos will be corrected -> no need to correct rim 1 before rim 0
+         IF( nn_hls == 1 ) THEN   ;   llsend3(:) = .false.   ;   llrecv3(:) = .false.   ;   END IF
+            DO jbdy = 1, nb_bdy
+               IF( cn_ice(jbdy) == 'frs' .AND. nn_ice_dta(jbdy) /= 0 ) THEN
+                  llsend3(:) = llsend3(:) .OR. lsend_bdyint(jbdy,3,:,ir)   ! possibly every direction, V points
+                  llsend3(3) = llsend3(3) .OR. lsend_bdyext(jbdy,3,3,ir)   ! neighbour might search point towards its south bdy
+                  llrecv3(:) = llrecv3(:) .OR. lrecv_bdyint(jbdy,3,:,ir)   ! possibly every direction, V points
+                  llrecv3(4) = llrecv3(4) .OR. lrecv_bdyext(jbdy,3,4,ir)   ! might search point towards north bdy
+               END IF
+            END DO
+            IF( ANY(llsend3) .OR. ANY(llrecv3) ) THEN   ! if need to send/recv in at least one direction
+               CALL lbc_lnk( 'bdyice', v_ice, 'V', -1., kfillmode=jpfillnothing ,lsend=llsend3, lrecv=llrecv3 )
+            END IF
          END SELECT
-         !
-      END DO
+      END DO   ! ir
       !
       IF( ln_timing )   CALL timing_stop('bdy_ice_dyn')
Index: /NEMO/trunk/src/OCE/BDY/bdyini.F90
===================================================================
--- /NEMO/trunk/src/OCE/BDY/bdyini.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/BDY/bdyini.F90	(revision 11536)
@@ -33,9 +33,8 @@
    PRIVATE
 
-   PUBLIC   bdy_init   ! routine called in nemo_init
+   PUBLIC   bdy_init    ! routine called in nemo_init
+   PUBLIC   find_neib   ! routine called in bdy_nmn
 
    INTEGER, PARAMETER ::   jp_nseg = 100   ! 
-   INTEGER, PARAMETER ::   nrimmax =  20   ! maximum rimwidth in structured
-                                               ! open boundary data files
    ! Straight open boundary segment parameters:
    INTEGER  ::   nbdysege, nbdysegw, nbdysegn, nbdysegs 
@@ -68,6 +67,5 @@
          &             ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp, rn_time_dmp_out, &
          &             cn_ice, nn_ice_dta,                                     &
-         &             rn_ice_tem, rn_ice_sal, rn_ice_age,                     &
-         &             ln_vol, nn_volctl, nn_rimwidth, nb_jpk_bdy
+         &             ln_vol, nn_volctl, nn_rimwidth
          !
       INTEGER  ::   ios                 ! Local integer output status for namelist read
@@ -79,11 +77,28 @@
       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 )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy in reference namelist' )
+      ! make sur that all elements of the namelist variables have a default definition from namelist_ref
+      ln_coords_file (2:jp_bdy) = ln_coords_file (1)
+      cn_coords_file (2:jp_bdy) = cn_coords_file (1)
+      cn_dyn2d       (2:jp_bdy) = cn_dyn2d       (1)
+      nn_dyn2d_dta   (2:jp_bdy) = nn_dyn2d_dta   (1)
+      cn_dyn3d       (2:jp_bdy) = cn_dyn3d       (1)
+      nn_dyn3d_dta   (2:jp_bdy) = nn_dyn3d_dta   (1)
+      cn_tra         (2:jp_bdy) = cn_tra         (1)
+      nn_tra_dta     (2:jp_bdy) = nn_tra_dta     (1)    
+      ln_tra_dmp     (2:jp_bdy) = ln_tra_dmp     (1)
+      ln_dyn3d_dmp   (2:jp_bdy) = ln_dyn3d_dmp   (1)
+      rn_time_dmp    (2:jp_bdy) = rn_time_dmp    (1)
+      rn_time_dmp_out(2:jp_bdy) = rn_time_dmp_out(1)
+      cn_ice         (2:jp_bdy) = cn_ice         (1)
+      nn_ice_dta     (2:jp_bdy) = nn_ice_dta     (1)
       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 )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nambdy in configuration namelist' )
       IF(lwm) WRITE ( numond, nambdy )
 
       IF( .NOT. Agrif_Root() ) ln_bdy = .FALSE.   ! forced for Agrif children
+
+      IF( nb_bdy == 0 ) ln_bdy = .FALSE.
       
       ! -----------------------------------------
@@ -96,5 +111,6 @@
          !
          ! Open boundaries definition (arrays and masks)
-         CALL bdy_segs
+         CALL bdy_def
+         IF( ln_meshmask )   CALL bdy_meshwri()
          !
          ! Open boundaries initialisation of external data arrays
@@ -114,5 +130,5 @@
 
 
-   SUBROUTINE bdy_segs
+   SUBROUTINE bdy_def
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE bdy_init  ***
@@ -125,29 +141,23 @@
       !! ** Input   :  bdy_init.nc, input file for unstructured open boundaries
       !!----------------------------------------------------------------------      
-      INTEGER  ::   ib_bdy, ii, ij, ik, igrd, ib, ir, iseg ! dummy loop indices
-      INTEGER  ::   icount, icountr, ibr_max, ilen1, ibm1  ! local integers
+      INTEGER  ::   ib_bdy, ii, ij, igrd, ib, ir, iseg     ! dummy loop indices
+      INTEGER  ::   icount, icountr, icountr0, ibr_max     ! local integers
+      INTEGER  ::   ilen1                                  !   -       -
       INTEGER  ::   iwe, ies, iso, ino, inum, id_dummy     !   -       -
-      INTEGER  ::   igrd_start, igrd_end, jpbdta           !   -       -
-      INTEGER  ::   jpbdtau, jpbdtas                       !   -       -
+      INTEGER  ::   jpbdta                                 !   -       -
       INTEGER  ::   ib_bdy1, ib_bdy2, ib1, ib2             !   -       -
-      INTEGER  ::   i_offset, j_offset                     !   -       -
-      INTEGER , POINTER  ::  nbi, nbj, nbr                 ! short cuts
-      REAL(wp), POINTER, DIMENSION(:,:)       ::   pmask    ! pointer to 2D mask fields
-      REAL(wp) ::   zefl, zwfl, znfl, zsfl                 ! local scalars
-      INTEGER, DIMENSION (2)                  ::   kdimsz
-      INTEGER, DIMENSION(jpbgrd,jp_bdy)       ::   nblendta         ! Length of index arrays 
-      INTEGER, ALLOCATABLE, DIMENSION(:,:,:)  ::   nbidta, nbjdta   ! Index arrays: i and j indices of bdy dta
-      INTEGER, ALLOCATABLE, DIMENSION(:,:,:)  ::   nbrdta           ! Discrete distance from rim points
-      CHARACTER(LEN=1),DIMENSION(jpbgrd)      ::   cgrid
-      INTEGER :: com_east, com_west, com_south, com_north, jpk_max  ! Flags for boundaries sending
-      INTEGER :: com_east_b, com_west_b, com_south_b, com_north_b  ! Flags for boundaries receiving
-      INTEGER :: iw_b(4), ie_b(4), is_b(4), in_b(4)                ! Arrays for neighbours coordinates
-      REAL(wp), TARGET, DIMENSION(jpi,jpj) ::   zfmask  ! temporary fmask array excluding coastal boundary condition (shlat)
-      !!
-      CHARACTER(LEN=1)                     ::   ctypebdy   !     -        - 
-      INTEGER                              ::   nbdyind, nbdybeg, nbdyend
-      !!
-      NAMELIST/nambdy_index/ ctypebdy, nbdyind, nbdybeg, nbdyend
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
+      INTEGER  ::   ii1, ii2, ii3, ij1, ij2, ij3           !   -       -
+      INTEGER  ::   iibe, ijbe, iibi, ijbi                 !   -       -
+      INTEGER  ::   flagu, flagv                           ! short cuts
+      INTEGER  ::   nbdyind, nbdybeg, nbdyend
+      INTEGER              , DIMENSION(4)             ::   kdimsz
+      INTEGER              , DIMENSION(jpbgrd,jp_bdy) ::   nblendta          ! Length of index arrays 
+      INTEGER,  ALLOCATABLE, DIMENSION(:,:,:)         ::   nbidta, nbjdta    ! Index arrays: i and j indices of bdy dta
+      INTEGER,  ALLOCATABLE, DIMENSION(:,:,:)         ::   nbrdta            ! Discrete distance from rim points
+      CHARACTER(LEN=1)     , DIMENSION(jpbgrd)        ::   cgrid
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)     ::   zz_read                 ! work space for 2D global boundary data
+      REAL(wp), POINTER    , DIMENSION(:,:)     ::   zmask                   ! pointer to 2D mask fields
+      REAL(wp)             , DIMENSION(jpi,jpj) ::   zfmask   ! temporary fmask array excluding coastal boundary condition (shlat)
+      REAL(wp)             , DIMENSION(jpi,jpj) ::   ztmask, zumask, zvmask  ! temporary u/v mask array
       !!----------------------------------------------------------------------
       !
@@ -160,247 +170,193 @@
          &                               ' and general open boundary condition are not compatible' )
 
-      IF( nb_bdy == 0 ) THEN 
-        IF(lwp) WRITE(numout,*) 'nb_bdy = 0, NO OPEN BOUNDARIES APPLIED.'
-      ELSE
-        IF(lwp) WRITE(numout,*) 'Number of open boundary sets : ', nb_bdy
+      IF(lwp) WRITE(numout,*) 'Number of open boundary sets : ', nb_bdy
+
+      DO ib_bdy = 1,nb_bdy
+
+         IF(lwp) THEN
+            WRITE(numout,*) ' ' 
+            WRITE(numout,*) '------ Open boundary data set ',ib_bdy,' ------' 
+            IF( ln_coords_file(ib_bdy) ) THEN
+               WRITE(numout,*) 'Boundary definition read from file '//TRIM(cn_coords_file(ib_bdy))
+            ELSE
+               WRITE(numout,*) 'Boundary defined in namelist.'
+            ENDIF
+            WRITE(numout,*)
+         ENDIF
+
+         ! barotropic bdy
+         !----------------
+         IF(lwp) THEN
+            WRITE(numout,*) 'Boundary conditions for barotropic solution:  '
+            SELECT CASE( cn_dyn2d(ib_bdy) )                  
+            CASE( 'none' )           ;   WRITE(numout,*) '      no open boundary condition'        
+            CASE( 'frs' )            ;   WRITE(numout,*) '      Flow Relaxation Scheme'
+            CASE( 'flather' )        ;   WRITE(numout,*) '      Flather radiation condition'
+            CASE( 'orlanski' )       ;   WRITE(numout,*) '      Orlanski (fully oblique) radiation condition with adaptive nudging'
+            CASE( 'orlanski_npo' )   ;   WRITE(numout,*) '      Orlanski (NPO) radiation condition with adaptive nudging'
+            CASE DEFAULT             ;   CALL ctl_stop( 'unrecognised value for cn_dyn2d' )
+            END SELECT
+         ENDIF
+
+         dta_bdy(ib_bdy)%lneed_ssh   = cn_dyn2d(ib_bdy) == 'flather'
+         dta_bdy(ib_bdy)%lneed_dyn2d = cn_dyn2d(ib_bdy) /= 'none'
+
+         IF( lwp .AND. dta_bdy(ib_bdy)%lneed_dyn2d ) THEN
+            SELECT CASE( nn_dyn2d_dta(ib_bdy) )                   ! 
+            CASE( 0 )      ;   WRITE(numout,*) '      initial state used for bdy data'        
+            CASE( 1 )      ;   WRITE(numout,*) '      boundary data taken from file'
+            CASE( 2 )      ;   WRITE(numout,*) '      tidal harmonic forcing taken from file'
+            CASE( 3 )      ;   WRITE(numout,*) '      boundary data AND tidal harmonic forcing taken from files'
+            CASE DEFAULT   ;   CALL ctl_stop( 'nn_dyn2d_dta must be between 0 and 3' )
+            END SELECT
+         ENDIF
+         IF ( dta_bdy(ib_bdy)%lneed_dyn2d .AND. 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
+         IF(lwp) WRITE(numout,*)
+
+         ! baroclinic bdy
+         !----------------
+         IF(lwp) THEN
+            WRITE(numout,*) 'Boundary conditions for baroclinic velocities:  '
+            SELECT CASE( cn_dyn3d(ib_bdy) )                  
+            CASE('none')           ;   WRITE(numout,*) '      no open boundary condition'        
+            CASE('frs')            ;   WRITE(numout,*) '      Flow Relaxation Scheme'
+            CASE('specified')      ;   WRITE(numout,*) '      Specified value'
+            CASE('neumann')        ;   WRITE(numout,*) '      Neumann conditions'
+            CASE('zerograd')       ;   WRITE(numout,*) '      Zero gradient for baroclinic velocities'
+            CASE('zero')           ;   WRITE(numout,*) '      Zero baroclinic velocities (runoff case)'
+            CASE('orlanski')       ;   WRITE(numout,*) '      Orlanski (fully oblique) radiation condition with adaptive nudging'
+            CASE('orlanski_npo')   ;   WRITE(numout,*) '      Orlanski (NPO) radiation condition with adaptive nudging'
+            CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_dyn3d' )
+            END SELECT
+         ENDIF
+
+         dta_bdy(ib_bdy)%lneed_dyn3d = cn_dyn3d(ib_bdy) == 'frs'      .OR. cn_dyn3d(ib_bdy) == 'specified'   &
+            &                     .OR. cn_dyn3d(ib_bdy) == 'orlanski' .OR. cn_dyn3d(ib_bdy) == 'orlanski_npo'
+
+         IF( lwp .AND. dta_bdy(ib_bdy)%lneed_dyn3d ) THEN
+            SELECT CASE( nn_dyn3d_dta(ib_bdy) )                   ! 
+            CASE( 0 )      ;   WRITE(numout,*) '      initial state used for bdy data'        
+            CASE( 1 )      ;   WRITE(numout,*) '      boundary data taken from file'
+            CASE DEFAULT   ;   CALL ctl_stop( 'nn_dyn3d_dta must be 0 or 1' )
+            END SELECT
+         END IF
+
+         IF ( ln_dyn3d_dmp(ib_bdy) ) THEN
+            IF ( cn_dyn3d(ib_bdy) == 'none' ) THEN
+               IF(lwp) WRITE(numout,*) 'No open boundary condition for baroclinic velocities: ln_dyn3d_dmp is set to .false.'
+               ln_dyn3d_dmp(ib_bdy) = .false.
+            ELSEIF ( cn_dyn3d(ib_bdy) == 'frs' ) THEN
+               CALL ctl_stop( 'Use FRS OR relaxation' )
+            ELSE
+               IF(lwp) WRITE(numout,*) '      + baroclinic velocities relaxation zone'
+               IF(lwp) WRITE(numout,*) '      Damping time scale: ',rn_time_dmp(ib_bdy),' days'
+               IF(rn_time_dmp(ib_bdy)<0) CALL ctl_stop( 'Time scale must be positive' )
+               dta_bdy(ib_bdy)%lneed_dyn3d = .TRUE.
+            ENDIF
+         ELSE
+            IF(lwp) WRITE(numout,*) '      NO relaxation on baroclinic velocities'
+         ENDIF
+         IF(lwp) WRITE(numout,*)
+
+         !    tra bdy
+         !----------------
+         IF(lwp) THEN
+            WRITE(numout,*) 'Boundary conditions for temperature and salinity:  '
+            SELECT CASE( cn_tra(ib_bdy) )                  
+            CASE('none')           ;   WRITE(numout,*) '      no open boundary condition'        
+            CASE('frs')            ;   WRITE(numout,*) '      Flow Relaxation Scheme'
+            CASE('specified')      ;   WRITE(numout,*) '      Specified value'
+            CASE('neumann')        ;   WRITE(numout,*) '      Neumann conditions'
+            CASE('runoff')         ;   WRITE(numout,*) '      Runoff conditions : Neumann for T and specified to 0.1 for salinity'
+            CASE('orlanski')       ;   WRITE(numout,*) '      Orlanski (fully oblique) radiation condition with adaptive nudging'
+            CASE('orlanski_npo')   ;   WRITE(numout,*) '      Orlanski (NPO) radiation condition with adaptive nudging'
+            CASE DEFAULT           ;   CALL ctl_stop( 'unrecognised value for cn_tra' )
+            END SELECT
+         ENDIF
+
+         dta_bdy(ib_bdy)%lneed_tra = cn_tra(ib_bdy) == 'frs'       .OR. cn_tra(ib_bdy) == 'specified'   &
+            &                   .OR. cn_tra(ib_bdy) == 'orlanski'  .OR. cn_tra(ib_bdy) == 'orlanski_npo' 
+
+         IF( lwp .AND. dta_bdy(ib_bdy)%lneed_tra ) THEN
+            SELECT CASE( nn_tra_dta(ib_bdy) )                   ! 
+            CASE( 0 )      ;   WRITE(numout,*) '      initial state used for bdy data'        
+            CASE( 1 )      ;   WRITE(numout,*) '      boundary data taken from file'
+            CASE DEFAULT   ;   CALL ctl_stop( 'nn_tra_dta must be 0 or 1' )
+            END SELECT
+         ENDIF
+
+         IF ( ln_tra_dmp(ib_bdy) ) THEN
+            IF ( cn_tra(ib_bdy) == 'none' ) THEN
+               IF(lwp) WRITE(numout,*) 'No open boundary condition for tracers: ln_tra_dmp is set to .false.'
+               ln_tra_dmp(ib_bdy) = .false.
+            ELSEIF ( cn_tra(ib_bdy) == 'frs' ) THEN
+               CALL ctl_stop( 'Use FRS OR relaxation' )
+            ELSE
+               IF(lwp) WRITE(numout,*) '      + T/S relaxation zone'
+               IF(lwp) WRITE(numout,*) '      Damping time scale: ',rn_time_dmp(ib_bdy),' days'
+               IF(lwp) WRITE(numout,*) '      Outflow damping time scale: ',rn_time_dmp_out(ib_bdy),' days'
+               IF(lwp.AND.rn_time_dmp(ib_bdy)<0) CALL ctl_stop( 'Time scale must be positive' )
+               dta_bdy(ib_bdy)%lneed_tra = .TRUE.
+            ENDIF
+         ELSE
+            IF(lwp) WRITE(numout,*) '      NO T/S relaxation'
+         ENDIF
+         IF(lwp) WRITE(numout,*)
+
+#if defined key_si3
+         IF(lwp) THEN
+            WRITE(numout,*) 'Boundary conditions for sea ice:  '
+            SELECT CASE( cn_ice(ib_bdy) )                  
+            CASE('none')   ;   WRITE(numout,*) '      no open boundary condition'        
+            CASE('frs')    ;   WRITE(numout,*) '      Flow Relaxation Scheme'
+            CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_ice' )
+            END SELECT
+         ENDIF
+
+         dta_bdy(ib_bdy)%lneed_ice = cn_ice(ib_bdy) /= 'none'
+
+         IF( lwp .AND. dta_bdy(ib_bdy)%lneed_ice ) THEN 
+            SELECT CASE( nn_ice_dta(ib_bdy) )                   ! 
+            CASE( 0 )      ;   WRITE(numout,*) '      initial state used for bdy data'        
+            CASE( 1 )      ;   WRITE(numout,*) '      boundary data taken from file'
+            CASE DEFAULT   ;   CALL ctl_stop( 'nn_ice_dta must be 0 or 1' )
+            END SELECT
+         ENDIF
+#else
+         dta_bdy(ib_bdy)%lneed_ice = .FALSE.
+#endif
+         !
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '      Width of relaxation zone = ', nn_rimwidth(ib_bdy)
+         IF(lwp) WRITE(numout,*)
+         !
+      END DO   ! nb_bdy
+
+      IF( lwp ) THEN
+         IF( ln_vol ) THEN                     ! check volume conservation (nn_volctl value)
+            WRITE(numout,*) 'Volume correction applied at open boundaries'
+            WRITE(numout,*)
+            SELECT CASE ( nn_volctl )
+            CASE( 1 )      ;   WRITE(numout,*) '      The total volume will be constant'
+            CASE( 0 )      ;   WRITE(numout,*) '      The total volume will vary according to the surface E-P flux'
+            CASE DEFAULT   ;   CALL ctl_stop( 'nn_volctl must be 0 or 1' )
+            END SELECT
+            WRITE(numout,*)
+            !
+            ! sanity check if used with tides        
+            IF( ln_tide ) THEN 
+               WRITE(numout,*) ' The total volume correction is not working with tides. '
+               WRITE(numout,*) ' Set ln_vol to .FALSE. '
+               WRITE(numout,*) ' or '
+               WRITE(numout,*) ' equilibriate your bdy input files '
+               CALL ctl_stop( 'The total volume correction is not working with tides.' )
+            END IF
+         ELSE
+            WRITE(numout,*) 'No volume correction applied at open boundaries'
+            WRITE(numout,*)
+         ENDIF
       ENDIF
-
-      DO ib_bdy = 1,nb_bdy
-        IF(lwp) WRITE(numout,*) ' ' 
-        IF(lwp) WRITE(numout,*) '------ Open boundary data set ',ib_bdy,'------' 
-
-        IF( ln_coords_file(ib_bdy) ) THEN
-           IF(lwp) WRITE(numout,*) 'Boundary definition read from file '//TRIM(cn_coords_file(ib_bdy))
-        ELSE
-           IF(lwp) WRITE(numout,*) 'Boundary defined in namelist.'
-        ENDIF
-        IF(lwp) WRITE(numout,*)
-
-        IF(lwp) WRITE(numout,*) 'Boundary conditions for barotropic solution:  '
-        SELECT CASE( cn_dyn2d(ib_bdy) )                  
-          CASE( 'none' )         
-             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-             dta_bdy(ib_bdy)%ll_ssh = .false.
-             dta_bdy(ib_bdy)%ll_u2d = .false.
-             dta_bdy(ib_bdy)%ll_v2d = .false.
-          CASE( 'frs' )          
-             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-             dta_bdy(ib_bdy)%ll_ssh = .false.
-             dta_bdy(ib_bdy)%ll_u2d = .true.
-             dta_bdy(ib_bdy)%ll_v2d = .true.
-          CASE( 'flather' )      
-             IF(lwp) WRITE(numout,*) '      Flather radiation condition'
-             dta_bdy(ib_bdy)%ll_ssh = .true.
-             dta_bdy(ib_bdy)%ll_u2d = .true.
-             dta_bdy(ib_bdy)%ll_v2d = .true.
-          CASE( 'orlanski' )     
-             IF(lwp) WRITE(numout,*) '      Orlanski (fully oblique) radiation condition with adaptive nudging'
-             dta_bdy(ib_bdy)%ll_ssh = .false.
-             dta_bdy(ib_bdy)%ll_u2d = .true.
-             dta_bdy(ib_bdy)%ll_v2d = .true.
-          CASE( 'orlanski_npo' ) 
-             IF(lwp) WRITE(numout,*) '      Orlanski (NPO) radiation condition with adaptive nudging'
-             dta_bdy(ib_bdy)%ll_ssh = .false.
-             dta_bdy(ib_bdy)%ll_u2d = .true.
-             dta_bdy(ib_bdy)%ll_v2d = .true.
-          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_dyn2d' )
-        END SELECT
-        IF( cn_dyn2d(ib_bdy) /= 'none' ) THEN
-           SELECT CASE( nn_dyn2d_dta(ib_bdy) )                   ! 
-              CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
-              CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
-              CASE( 2 )      ;   IF(lwp) WRITE(numout,*) '      tidal harmonic forcing taken from file'
-              CASE( 3 )      ;   IF(lwp) WRITE(numout,*) '      boundary data AND tidal harmonic forcing taken from files'
-              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.ln_tide)) THEN
-             CALL ctl_stop( 'You must activate with ln_tide to add tidal forcing at open boundaries' )
-           ENDIF
-        ENDIF
-        IF(lwp) WRITE(numout,*)
-
-        IF(lwp) WRITE(numout,*) 'Boundary conditions for baroclinic velocities:  '
-        SELECT CASE( cn_dyn3d(ib_bdy) )                  
-          CASE('none')
-             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-             dta_bdy(ib_bdy)%ll_u3d = .false.
-             dta_bdy(ib_bdy)%ll_v3d = .false.
-          CASE('frs')       
-             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-             dta_bdy(ib_bdy)%ll_u3d = .true.
-             dta_bdy(ib_bdy)%ll_v3d = .true.
-          CASE('specified')
-             IF(lwp) WRITE(numout,*) '      Specified value'
-             dta_bdy(ib_bdy)%ll_u3d = .true.
-             dta_bdy(ib_bdy)%ll_v3d = .true.
-          CASE('neumann')
-             IF(lwp) WRITE(numout,*) '      Neumann conditions'
-             dta_bdy(ib_bdy)%ll_u3d = .false.
-             dta_bdy(ib_bdy)%ll_v3d = .false.
-          CASE('zerograd')
-             IF(lwp) WRITE(numout,*) '      Zero gradient for baroclinic velocities'
-             dta_bdy(ib_bdy)%ll_u3d = .false.
-             dta_bdy(ib_bdy)%ll_v3d = .false.
-          CASE('zero')
-             IF(lwp) WRITE(numout,*) '      Zero baroclinic velocities (runoff case)'
-             dta_bdy(ib_bdy)%ll_u3d = .false.
-             dta_bdy(ib_bdy)%ll_v3d = .false.
-          CASE('orlanski')
-             IF(lwp) WRITE(numout,*) '      Orlanski (fully oblique) radiation condition with adaptive nudging'
-             dta_bdy(ib_bdy)%ll_u3d = .true.
-             dta_bdy(ib_bdy)%ll_v3d = .true.
-          CASE('orlanski_npo')
-             IF(lwp) WRITE(numout,*) '      Orlanski (NPO) radiation condition with adaptive nudging'
-             dta_bdy(ib_bdy)%ll_u3d = .true.
-             dta_bdy(ib_bdy)%ll_v3d = .true.
-          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_dyn3d' )
-        END SELECT
-        IF( cn_dyn3d(ib_bdy) /= 'none' ) THEN
-           SELECT CASE( nn_dyn3d_dta(ib_bdy) )                   ! 
-              CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
-              CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
-              CASE DEFAULT   ;   CALL ctl_stop( 'nn_dyn3d_dta must be 0 or 1' )
-           END SELECT
-        ENDIF
-
-        IF ( ln_dyn3d_dmp(ib_bdy) ) THEN
-           IF ( cn_dyn3d(ib_bdy) == 'none' ) THEN
-              IF(lwp) WRITE(numout,*) 'No open boundary condition for baroclinic velocities: ln_dyn3d_dmp is set to .false.'
-              ln_dyn3d_dmp(ib_bdy)=.false.
-           ELSEIF ( cn_dyn3d(ib_bdy) == 'frs' ) THEN
-              CALL ctl_stop( 'Use FRS OR relaxation' )
-           ELSE
-              IF(lwp) WRITE(numout,*) '      + baroclinic velocities relaxation zone'
-              IF(lwp) WRITE(numout,*) '      Damping time scale: ',rn_time_dmp(ib_bdy),' days'
-              IF((lwp).AND.rn_time_dmp(ib_bdy)<0) CALL ctl_stop( 'Time scale must be positive' )
-              dta_bdy(ib_bdy)%ll_u3d = .true.
-              dta_bdy(ib_bdy)%ll_v3d = .true.
-           ENDIF
-        ELSE
-           IF(lwp) WRITE(numout,*) '      NO relaxation on baroclinic velocities'
-        ENDIF
-        IF(lwp) WRITE(numout,*)
-
-        IF(lwp) WRITE(numout,*) 'Boundary conditions for temperature and salinity:  '
-        SELECT CASE( cn_tra(ib_bdy) )                  
-          CASE('none')
-             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-             dta_bdy(ib_bdy)%ll_tem = .false.
-             dta_bdy(ib_bdy)%ll_sal = .false.
-          CASE('frs')
-             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-             dta_bdy(ib_bdy)%ll_tem = .true.
-             dta_bdy(ib_bdy)%ll_sal = .true.
-          CASE('specified')
-             IF(lwp) WRITE(numout,*) '      Specified value'
-             dta_bdy(ib_bdy)%ll_tem = .true.
-             dta_bdy(ib_bdy)%ll_sal = .true.
-          CASE('neumann')
-             IF(lwp) WRITE(numout,*) '      Neumann conditions'
-             dta_bdy(ib_bdy)%ll_tem = .false.
-             dta_bdy(ib_bdy)%ll_sal = .false.
-          CASE('runoff')
-             IF(lwp) WRITE(numout,*) '      Runoff conditions : Neumann for T and specified to 0.1 for salinity'
-             dta_bdy(ib_bdy)%ll_tem = .false.
-             dta_bdy(ib_bdy)%ll_sal = .false.
-          CASE('orlanski')
-             IF(lwp) WRITE(numout,*) '      Orlanski (fully oblique) radiation condition with adaptive nudging'
-             dta_bdy(ib_bdy)%ll_tem = .true.
-             dta_bdy(ib_bdy)%ll_sal = .true.
-          CASE('orlanski_npo')
-             IF(lwp) WRITE(numout,*) '      Orlanski (NPO) radiation condition with adaptive nudging'
-             dta_bdy(ib_bdy)%ll_tem = .true.
-             dta_bdy(ib_bdy)%ll_sal = .true.
-          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_tra' )
-        END SELECT
-        IF( cn_tra(ib_bdy) /= 'none' ) THEN
-           SELECT CASE( nn_tra_dta(ib_bdy) )                   ! 
-              CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
-              CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
-              CASE DEFAULT   ;   CALL ctl_stop( 'nn_tra_dta must be 0 or 1' )
-           END SELECT
-        ENDIF
-
-        IF ( ln_tra_dmp(ib_bdy) ) THEN
-           IF ( cn_tra(ib_bdy) == 'none' ) THEN
-              IF(lwp) WRITE(numout,*) 'No open boundary condition for tracers: ln_tra_dmp is set to .false.'
-              ln_tra_dmp(ib_bdy)=.false.
-           ELSEIF ( cn_tra(ib_bdy) == 'frs' ) THEN
-              CALL ctl_stop( 'Use FRS OR relaxation' )
-           ELSE
-              IF(lwp) WRITE(numout,*) '      + T/S relaxation zone'
-              IF(lwp) WRITE(numout,*) '      Damping time scale: ',rn_time_dmp(ib_bdy),' days'
-              IF(lwp) WRITE(numout,*) '      Outflow damping time scale: ',rn_time_dmp_out(ib_bdy),' days'
-              IF((lwp).AND.rn_time_dmp(ib_bdy)<0) CALL ctl_stop( 'Time scale must be positive' )
-              dta_bdy(ib_bdy)%ll_tem = .true.
-              dta_bdy(ib_bdy)%ll_sal = .true.
-           ENDIF
-        ELSE
-           IF(lwp) WRITE(numout,*) '      NO T/S relaxation'
-        ENDIF
-        IF(lwp) WRITE(numout,*)
-
-#if defined key_si3
-         IF(lwp) WRITE(numout,*) 'Boundary conditions for sea ice:  '
-         SELECT CASE( cn_ice(ib_bdy) )                  
-         CASE('none')
-             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-             dta_bdy(ib_bdy)%ll_a_i = .false.
-             dta_bdy(ib_bdy)%ll_h_i = .false.
-             dta_bdy(ib_bdy)%ll_h_s = .false.
-         CASE('frs')
-             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-             dta_bdy(ib_bdy)%ll_a_i = .true.
-             dta_bdy(ib_bdy)%ll_h_i = .true.
-             dta_bdy(ib_bdy)%ll_h_s = .true.
-         CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_ice' )
-         END SELECT
-        IF( cn_ice(ib_bdy) /= 'none' ) THEN 
-           SELECT CASE( nn_ice_dta(ib_bdy) )                   ! 
-              CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
-              CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
-              CASE DEFAULT   ;   CALL ctl_stop( 'nn_ice_dta must be 0 or 1' )
-           END SELECT
-        ENDIF
-        IF(lwp) WRITE(numout,*)
-        IF(lwp) WRITE(numout,*) '      tem of bdy sea-ice = ', rn_ice_tem(ib_bdy)         
-        IF(lwp) WRITE(numout,*) '      sal of bdy sea-ice = ', rn_ice_sal(ib_bdy)         
-        IF(lwp) WRITE(numout,*) '      age of bdy sea-ice = ', rn_ice_age(ib_bdy)         
-#endif
-
-        IF(lwp) WRITE(numout,*) '      Width of relaxation zone = ', nn_rimwidth(ib_bdy)
-        IF(lwp) WRITE(numout,*)
-         !
-      END DO
-
-     IF( nb_bdy > 0 ) THEN
-        IF( ln_vol ) THEN                     ! check volume conservation (nn_volctl value)
-          IF(lwp) WRITE(numout,*) 'Volume correction applied at open boundaries'
-          IF(lwp) WRITE(numout,*)
-          SELECT CASE ( nn_volctl )
-            CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      The total volume will be constant'
-            CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      The total volume will vary according to the surface E-P flux'
-            CASE DEFAULT   ;   CALL ctl_stop( 'nn_volctl must be 0 or 1' )
-          END SELECT
-          IF(lwp) WRITE(numout,*)
-          !
-          ! sanity check if used with tides        
-          IF( ln_tide ) THEN 
-             IF(lwp) WRITE(numout,*) ' The total volume correction is not working with tides. '
-             IF(lwp) WRITE(numout,*) ' Set ln_vol to .FALSE. '
-             IF(lwp) WRITE(numout,*) ' or '
-             IF(lwp) WRITE(numout,*) ' equilibriate your bdy input files '
-             CALL ctl_stop( 'The total volume correction is not working with tides.' )
-          END IF
-        ELSE
-          IF(lwp) WRITE(numout,*) 'No volume correction applied at open boundaries'
-          IF(lwp) WRITE(numout,*)
-        ENDIF
-        IF( nb_jpk_bdy(ib_bdy) > 0 ) THEN
-           IF(lwp) WRITE(numout,*) '*** open boundary will be interpolate in the vertical onto the native grid ***'
-        ELSE
-           IF(lwp) WRITE(numout,*) '*** open boundary will be read straight onto the native grid without vertical interpolation ***'
-        ENDIF
-     ENDIF
 
       ! -------------------------------------------------
@@ -408,8 +364,5 @@
       ! -------------------------------------------------
 
-      ! Work out global dimensions of boundary data
-      ! ---------------------------------------------
       REWIND( numnam_cfg )     
-
       nblendta(:,:) = 0
       nbdysege = 0
@@ -417,123 +370,33 @@
       nbdysegn = 0
       nbdysegs = 0
-      icount   = 0 ! count user defined segments
-      ! Dimensions below are used to allocate arrays to read external data
-      jpbdtas = 1 ! Maximum size of boundary data (structured case)
-      jpbdtau = 1 ! Maximum size of boundary data (unstructured case)
-
+
+      ! Define all boundaries 
+      ! ---------------------
       DO ib_bdy = 1, nb_bdy
-
-         IF( .NOT. ln_coords_file(ib_bdy) ) THEN ! Work out size of global arrays from namelist parameters
- 
-            icount = icount + 1
-            ! No REWIND here because may need to read more than one nambdy_index namelist.
-            ! Read only namelist_cfg to avoid unseccessfull overwrite 
-            ! keep full control of the configuration namelist
-            READ  ( numnam_cfg, nambdy_index, IOSTAT = ios, ERR = 904 )
-904         IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy_index in configuration namelist', lwp )
-            IF(lwm) WRITE ( numond, nambdy_index )
-
-            SELECT CASE ( TRIM(ctypebdy) )
-              CASE( 'N' )
-                 IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
-                    nbdyind  = jpjglo - 2  ! set boundary to whole side of model domain.
-                    nbdybeg  = 2
-                    nbdyend  = jpiglo - 1
-                 ENDIF
-                 nbdysegn = nbdysegn + 1
-                 npckgn(nbdysegn) = ib_bdy ! Save bdy package number
-                 jpjnob(nbdysegn) = nbdyind
-                 jpindt(nbdysegn) = nbdybeg
-                 jpinft(nbdysegn) = nbdyend
-                 !
-              CASE( 'S' )
-                 IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
-                    nbdyind  = 2           ! set boundary to whole side of model domain.
-                    nbdybeg  = 2
-                    nbdyend  = jpiglo - 1
-                 ENDIF
-                 nbdysegs = nbdysegs + 1
-                 npckgs(nbdysegs) = ib_bdy ! Save bdy package number
-                 jpjsob(nbdysegs) = nbdyind
-                 jpisdt(nbdysegs) = nbdybeg
-                 jpisft(nbdysegs) = nbdyend
-                 !
-              CASE( 'E' )
-                 IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
-                    nbdyind  = jpiglo - 2  ! set boundary to whole side of model domain.
-                    nbdybeg  = 2
-                    nbdyend  = jpjglo - 1
-                 ENDIF
-                 nbdysege = nbdysege + 1 
-                 npckge(nbdysege) = ib_bdy ! Save bdy package number
-                 jpieob(nbdysege) = nbdyind
-                 jpjedt(nbdysege) = nbdybeg
-                 jpjeft(nbdysege) = nbdyend
-                 !
-              CASE( 'W' )
-                 IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
-                    nbdyind  = 2           ! set boundary to whole side of model domain.
-                    nbdybeg  = 2
-                    nbdyend  = jpjglo - 1
-                 ENDIF
-                 nbdysegw = nbdysegw + 1
-                 npckgw(nbdysegw) = ib_bdy ! Save bdy package number
-                 jpiwob(nbdysegw) = nbdyind
-                 jpjwdt(nbdysegw) = nbdybeg
-                 jpjwft(nbdysegw) = nbdyend
-                 !
-              CASE DEFAULT   ;   CALL ctl_stop( 'ctypebdy must be N, S, E or W' )
-            END SELECT
-
-            ! For simplicity we assume that in case of straight bdy, arrays have the same length
-            ! (even if it is true that last tangential velocity points
-            ! are useless). This simplifies a little bit boundary data format (and agrees with format
-            ! used so far in obc package)
-
-            nblendta(1:jpbgrd,ib_bdy) =  (nbdyend - nbdybeg + 1) * nn_rimwidth(ib_bdy)
-            jpbdtas = MAX(jpbdtas, (nbdyend - nbdybeg + 1))
-            IF (lwp.and.(nn_rimwidth(ib_bdy)>nrimmax)) &
-            & CALL ctl_stop( 'rimwidth must be lower than nrimmax' )
-
-         ELSE            ! Read size of arrays in boundary coordinates file.
+         !
+         IF( .NOT. ln_coords_file(ib_bdy) ) THEN     ! build bdy coordinates with segments defined in namelist
+
+            CALL bdy_read_seg( ib_bdy, nblendta(:,ib_bdy) )
+
+         ELSE                                        ! Read size of arrays in boundary coordinates file.
+            
             CALL iom_open( cn_coords_file(ib_bdy), inum )
             DO igrd = 1, jpbgrd
                id_dummy = iom_varid( inum, 'nbi'//cgrid(igrd), kdimsz=kdimsz )  
                nblendta(igrd,ib_bdy) = MAXVAL(kdimsz)
-               jpbdtau = MAX(jpbdtau, MAXVAL(kdimsz))
             END DO
             CALL iom_close( inum )
-            !
-         ENDIF 
+         ENDIF
          !
       END DO ! ib_bdy
 
-      IF (nb_bdy>0) THEN
-         jpbdta = MAXVAL(nblendta(1:jpbgrd,1:nb_bdy))
-
-         ! Allocate arrays
-         !---------------
-         ALLOCATE( nbidta(jpbdta, jpbgrd, nb_bdy), nbjdta(jpbdta, jpbgrd, nb_bdy),    &
-            &      nbrdta(jpbdta, jpbgrd, nb_bdy) )
-         
-         jpk_max = MAXVAL(nb_jpk_bdy)
-         jpk_max = MAX(jpk_max, jpk)
-
-         ALLOCATE( dta_global(jpbdtau, 1, jpk_max) )
-         ALLOCATE( dta_global_z(jpbdtau, 1, jpk_max) ) ! needed ?? TODO
-         ALLOCATE( dta_global_dz(jpbdtau, 1, jpk_max) )! needed ?? TODO
-
-         IF ( icount>0 ) THEN
-            ALLOCATE( dta_global2(jpbdtas, nrimmax, jpk_max) )
-            ALLOCATE( dta_global2_z(jpbdtas, nrimmax, jpk_max) ) ! needed ?? TODO
-            ALLOCATE( dta_global2_dz(jpbdtas, nrimmax, jpk_max) )! needed ?? TODO  
-         ENDIF
-         ! 
-      ENDIF
-
       ! Now look for crossings in user (namelist) defined open boundary segments:
-      !--------------------------------------------------------------------------
-      IF( icount>0 )   CALL bdy_ctl_seg
-
+      IF( nbdysege > 0 .OR. nbdysegw > 0 .OR. nbdysegn > 0 .OR. nbdysegs > 0)   CALL bdy_ctl_seg
+      
+      ! Allocate arrays
+      !---------------
+      jpbdta = MAXVAL(nblendta(1:jpbgrd,1:nb_bdy))
+      ALLOCATE( nbidta(jpbdta, jpbgrd, nb_bdy), nbjdta(jpbdta, jpbgrd, nb_bdy), nbrdta(jpbdta, jpbgrd, nb_bdy) )
+    
       ! Calculate global boundary index arrays or read in from file
       !------------------------------------------------------------               
@@ -543,17 +406,19 @@
          IF( ln_coords_file(ib_bdy) ) THEN
             !
+            ALLOCATE( zz_read( MAXVAL(nblendta), 1 ) )          
             CALL iom_open( cn_coords_file(ib_bdy), inum )
+            !
             DO igrd = 1, jpbgrd
-               CALL iom_get( inum, jpdom_unknown, 'nbi'//cgrid(igrd), dta_global(1:nblendta(igrd,ib_bdy),:,1) )
+               CALL iom_get( inum, jpdom_unknown, 'nbi'//cgrid(igrd), zz_read(1:nblendta(igrd,ib_bdy),:) )
                DO ii = 1,nblendta(igrd,ib_bdy)
-                  nbidta(ii,igrd,ib_bdy) = INT( dta_global(ii,1,1) )
+                  nbidta(ii,igrd,ib_bdy) = NINT( zz_read(ii,1) )
                END DO
-               CALL iom_get( inum, jpdom_unknown, 'nbj'//cgrid(igrd), dta_global(1:nblendta(igrd,ib_bdy),:,1) )
+               CALL iom_get( inum, jpdom_unknown, 'nbj'//cgrid(igrd), zz_read(1:nblendta(igrd,ib_bdy),:) )
                DO ii = 1,nblendta(igrd,ib_bdy)
-                  nbjdta(ii,igrd,ib_bdy) = INT( dta_global(ii,1,1) )
+                  nbjdta(ii,igrd,ib_bdy) = NINT( zz_read(ii,1) )
                END DO
-               CALL iom_get( inum, jpdom_unknown, 'nbr'//cgrid(igrd), dta_global(1:nblendta(igrd,ib_bdy),:,1) )
+               CALL iom_get( inum, jpdom_unknown, 'nbr'//cgrid(igrd), zz_read(1:nblendta(igrd,ib_bdy),:) )
                DO ii = 1,nblendta(igrd,ib_bdy)
-                  nbrdta(ii,igrd,ib_bdy) = INT( dta_global(ii,1,1) )
+                  nbrdta(ii,igrd,ib_bdy) = NINT( zz_read(ii,1) )
                END DO
                !
@@ -563,192 +428,16 @@
                IF(lwp) WRITE(numout,*) ' nn_rimwidth from namelist is ', nn_rimwidth(ib_bdy)
                IF (ibr_max < nn_rimwidth(ib_bdy))   &
-                     CALL ctl_stop( 'nn_rimwidth is larger than maximum rimwidth in file',cn_coords_file(ib_bdy) )
-            END DO
+                  CALL ctl_stop( 'nn_rimwidth is larger than maximum rimwidth in file',cn_coords_file(ib_bdy) )
+            END DO
+            !
             CALL iom_close( inum )
+            DEALLOCATE( zz_read )
             !
-         ENDIF 
-         !
-      END DO      
-    
+         ENDIF
+         !
+      END DO
+
       ! 2. Now fill indices corresponding to straight open boundary arrays:
-      ! East
-      !-----
-      DO iseg = 1, nbdysege
-         ib_bdy = npckge(iseg)
-         !
-         ! ------------ T points -------------
-         igrd=1
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ij = jpjedt(iseg), jpjeft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 2 - ir
-               nbjdta(icount, igrd, ib_bdy) = ij
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-         !
-         ! ------------ U points -------------
-         igrd=2
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ij = jpjedt(iseg), jpjeft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 1 - ir
-               nbjdta(icount, igrd, ib_bdy) = ij
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-         !
-         ! ------------ V points -------------
-         igrd=3
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-!            DO ij = jpjedt(iseg), jpjeft(iseg) - 1
-            DO ij = jpjedt(iseg), jpjeft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 2 - ir
-               nbjdta(icount, igrd, ib_bdy) = ij
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-            nbidta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-            nbjdta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-         ENDDO
-      ENDDO
-      !
-      ! West
-      !-----
-      DO iseg = 1, nbdysegw
-         ib_bdy = npckgw(iseg)
-         !
-         ! ------------ T points -------------
-         igrd=1
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ij = jpjwdt(iseg), jpjwft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1
-               nbjdta(icount, igrd, ib_bdy) = ij
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-         !
-         ! ------------ U points -------------
-         igrd=2
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ij = jpjwdt(iseg), jpjwft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1
-               nbjdta(icount, igrd, ib_bdy) = ij
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-         !
-         ! ------------ V points -------------
-         igrd=3
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-!            DO ij = jpjwdt(iseg), jpjwft(iseg) - 1
-            DO ij = jpjwdt(iseg), jpjwft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1
-               nbjdta(icount, igrd, ib_bdy) = ij
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-            nbidta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-            nbjdta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-         ENDDO
-      ENDDO
-      !
-      ! North
-      !-----
-      DO iseg = 1, nbdysegn
-         ib_bdy = npckgn(iseg)
-         !
-         ! ------------ T points -------------
-         igrd=1
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ii = jpindt(iseg), jpinft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 2 - ir 
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-         !
-         ! ------------ U points -------------
-         igrd=2
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-!            DO ii = jpindt(iseg), jpinft(iseg) - 1
-            DO ii = jpindt(iseg), jpinft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 2 - ir
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-            nbidta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-            nbjdta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-         ENDDO
-         !
-         ! ------------ V points -------------
-         igrd=3
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ii = jpindt(iseg), jpinft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 1 - ir
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-      ENDDO
-      !
-      ! South
-      !-----
-      DO iseg = 1, nbdysegs
-         ib_bdy = npckgs(iseg)
-         !
-         ! ------------ T points -------------
-         igrd=1
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ii = jpisdt(iseg), jpisft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-         !
-         ! ------------ U points -------------
-         igrd=2
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-!            DO ii = jpisdt(iseg), jpisft(iseg) - 1
-            DO ii = jpisdt(iseg), jpisft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-            nbidta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-            nbjdta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-         ENDDO
-         !
-         ! ------------ V points -------------
-         igrd=3
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ii = jpisdt(iseg), jpisft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-      ENDDO
+      CALL bdy_coords_seg( nbidta, nbjdta, nbrdta )
 
       !  Deal with duplicated points
@@ -764,19 +453,19 @@
                      DO ib2 = 1, nblendta(igrd,ib_bdy2)
                         IF ((nbidta(ib1, igrd, ib_bdy1)==nbidta(ib2, igrd, ib_bdy2)).AND. &
-                        &   (nbjdta(ib1, igrd, ib_bdy1)==nbjdta(ib2, igrd, ib_bdy2))) THEN
-!                           IF ((lwp).AND.(igrd==1)) WRITE(numout,*) ' found coincident point ji, jj:', & 
-!                                                       &              nbidta(ib1, igrd, ib_bdy1),      & 
-!                                                       &              nbjdta(ib2, igrd, ib_bdy2)
+                           &   (nbjdta(ib1, igrd, ib_bdy1)==nbjdta(ib2, igrd, ib_bdy2))) THEN
+                           !                           IF ((lwp).AND.(igrd==1)) WRITE(numout,*) ' found coincident point ji, jj:', & 
+                           !                                                       &              nbidta(ib1, igrd, ib_bdy1),      & 
+                           !                                                       &              nbjdta(ib2, igrd, ib_bdy2)
                            ! keep only points with the lowest distance to boundary:
                            IF (nbrdta(ib1, igrd, ib_bdy1)<nbrdta(ib2, igrd, ib_bdy2)) THEN
-                             nbidta(ib2, igrd, ib_bdy2) =-ib_bdy2
-                             nbjdta(ib2, igrd, ib_bdy2) =-ib_bdy2
+                              nbidta(ib2, igrd, ib_bdy2) =-ib_bdy2
+                              nbjdta(ib2, igrd, ib_bdy2) =-ib_bdy2
                            ELSEIF (nbrdta(ib1, igrd, ib_bdy1)>nbrdta(ib2, igrd, ib_bdy2)) THEN
-                             nbidta(ib1, igrd, ib_bdy1) =-ib_bdy1
-                             nbjdta(ib1, igrd, ib_bdy1) =-ib_bdy1
-                           ! Arbitrary choice if distances are the same:
+                              nbidta(ib1, igrd, ib_bdy1) =-ib_bdy1
+                              nbjdta(ib1, igrd, ib_bdy1) =-ib_bdy1
+                              ! Arbitrary choice if distances are the same:
                            ELSE
-                             nbidta(ib1, igrd, ib_bdy1) =-ib_bdy1
-                             nbjdta(ib1, igrd, ib_bdy1) =-ib_bdy1
+                              nbidta(ib1, igrd, ib_bdy1) =-ib_bdy1
+                              nbjdta(ib1, igrd, ib_bdy1) =-ib_bdy1
                            ENDIF
                         END IF
@@ -787,88 +476,29 @@
          END DO
       END DO
-
-      ! Work out dimensions of boundary data on each processor
-      ! ------------------------------------------------------
-
-      ! Rather assume that boundary data indices are given on global domain
-      ! TO BE DISCUSSED ?
-!      iw = mig(1) + 1            ! if monotasking and no zoom, iw=2
-!      ie = mig(1) + nlci-1 - 1   ! if monotasking and no zoom, ie=jpim1
-!      is = mjg(1) + 1            ! if monotasking and no zoom, is=2
-!      in = mjg(1) + nlcj-1 - 1   ! if monotasking and no zoom, in=jpjm1      
-      iwe = mig(1) - 1 + 2         ! if monotasking and no zoom, iw=2
-      ies = mig(1) + nlci-1 - 1  ! if monotasking and no zoom, ie=jpim1
-      iso = mjg(1) - 1 + 2         ! if monotasking and no zoom, is=2
-      ino = mjg(1) + nlcj-1 - 1  ! if monotasking and no zoom, in=jpjm1
-
-      ALLOCATE( nbondi_bdy(nb_bdy))
-      ALLOCATE( nbondj_bdy(nb_bdy))
-      nbondi_bdy(:)=2
-      nbondj_bdy(:)=2
-      ALLOCATE( nbondi_bdy_b(nb_bdy))
-      ALLOCATE( nbondj_bdy_b(nb_bdy))
-      nbondi_bdy_b(:)=2
-      nbondj_bdy_b(:)=2
-
-      ! Work out dimensions of boundary data on each neighbour process
-      IF(nbondi == 0) THEN
-         iw_b(1) = 1 + nimppt(nowe+1)
-         ie_b(1) = 1 + nimppt(nowe+1)+nlcit(nowe+1)-3
-         is_b(1) = 1 + njmppt(nowe+1)
-         in_b(1) = 1 + njmppt(nowe+1)+nlcjt(nowe+1)-3
-
-         iw_b(2) = 1 + nimppt(noea+1)
-         ie_b(2) = 1 + nimppt(noea+1)+nlcit(noea+1)-3
-         is_b(2) = 1 + njmppt(noea+1)
-         in_b(2) = 1 + njmppt(noea+1)+nlcjt(noea+1)-3
-      ELSEIF(nbondi == 1) THEN
-         iw_b(1) = 1 + nimppt(nowe+1)
-         ie_b(1) = 1 + nimppt(nowe+1)+nlcit(nowe+1)-3
-         is_b(1) = 1 + njmppt(nowe+1)
-         in_b(1) = 1 + njmppt(nowe+1)+nlcjt(nowe+1)-3
-      ELSEIF(nbondi == -1) THEN
-         iw_b(2) = 1 + nimppt(noea+1)
-         ie_b(2) = 1 + nimppt(noea+1)+nlcit(noea+1)-3
-         is_b(2) = 1 + njmppt(noea+1)
-         in_b(2) = 1 + njmppt(noea+1)+nlcjt(noea+1)-3
-      ENDIF
-
-      IF(nbondj == 0) THEN
-         iw_b(3) = 1 + nimppt(noso+1)
-         ie_b(3) = 1 + nimppt(noso+1)+nlcit(noso+1)-3
-         is_b(3) = 1 + njmppt(noso+1)
-         in_b(3) = 1 + njmppt(noso+1)+nlcjt(noso+1)-3
-
-         iw_b(4) = 1 + nimppt(nono+1)
-         ie_b(4) = 1 + nimppt(nono+1)+nlcit(nono+1)-3
-         is_b(4) = 1 + njmppt(nono+1)
-         in_b(4) = 1 + njmppt(nono+1)+nlcjt(nono+1)-3
-      ELSEIF(nbondj == 1) THEN
-         iw_b(3) = 1 + nimppt(noso+1)
-         ie_b(3) = 1 + nimppt(noso+1)+nlcit(noso+1)-3
-         is_b(3) = 1 + njmppt(noso+1)
-         in_b(3) = 1 + njmppt(noso+1)+nlcjt(noso+1)-3
-      ELSEIF(nbondj == -1) THEN
-         iw_b(4) = 1 + nimppt(nono+1)
-         ie_b(4) = 1 + nimppt(nono+1)+nlcit(nono+1)-3
-         is_b(4) = 1 + njmppt(nono+1)
-         in_b(4) = 1 + njmppt(nono+1)+nlcjt(nono+1)-3
-      ENDIF
-
+      !
+      ! Find lenght of boundaries and rim on local mpi domain
+      !------------------------------------------------------
+      !
+      iwe = mig(1)
+      ies = mig(jpi)
+      iso = mjg(1) 
+      ino = mjg(jpj) 
+      !
       DO ib_bdy = 1, nb_bdy
          DO igrd = 1, jpbgrd
-            icount  = 0
-            icountr = 0
-            idx_bdy(ib_bdy)%nblen(igrd)    = 0
-            idx_bdy(ib_bdy)%nblenrim(igrd) = 0
+            icount   = 0   ! initialization of local bdy length
+            icountr  = 0   ! initialization of local rim 0 and rim 1 bdy length
+            icountr0 = 0   ! initialization of local rim 0 bdy length
+            idx_bdy(ib_bdy)%nblen(igrd)     = 0
+            idx_bdy(ib_bdy)%nblenrim(igrd)  = 0
+            idx_bdy(ib_bdy)%nblenrim0(igrd) = 0
             DO ib = 1, nblendta(igrd,ib_bdy)
                ! check that data is in correct order in file
-               ibm1 = MAX(1,ib-1)
-               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
+               IF( ib > 1 ) THEN
+                  IF( nbrdta(ib,igrd,ib_bdy) < nbrdta(ib-1,igrd,ib_bdy) ) THEN
                      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')
-                  ENDIF    
+                        &        ' in order of distance from edge nbr A utility for re-ordering ', &
+                        &        ' boundary coordinates and data files exists in the TOOLS/OBC directory')
+                  ENDIF
                ENDIF
                ! check if point is in local domain
@@ -876,12 +506,13 @@
                   & nbjdta(ib,igrd,ib_bdy) >= iso .AND. nbjdta(ib,igrd,ib_bdy) <= ino      ) THEN
                   !
-                  icount = icount  + 1
-                  !
-                  IF( nbrdta(ib,igrd,ib_bdy) == 1 )   icountr = icountr+1
+                  icount = icount + 1
+                  IF( nbrdta(ib,igrd,ib_bdy) == 1 .OR. nbrdta(ib,igrd,ib_bdy) == 0 )   icountr = icountr + 1
+                  IF( nbrdta(ib,igrd,ib_bdy) == 0 )   icountr0 = icountr0 + 1
                ENDIF
             END DO
-            idx_bdy(ib_bdy)%nblenrim(igrd) = icountr !: length of rim boundary data on each proc
-            idx_bdy(ib_bdy)%nblen   (igrd) = icount  !: length of boundary data on each proc        
-         END DO  ! igrd
+            idx_bdy(ib_bdy)%nblen    (igrd) = icount   !: length of boundary data on each proc
+            idx_bdy(ib_bdy)%nblenrim (igrd) = icountr  !: length of rim 0 and rim 1 boundary data on each proc   
+            idx_bdy(ib_bdy)%nblenrim0(igrd) = icountr0 !: length of rim 0 boundary data on each proc     
+         END DO   ! igrd
 
          ! Allocate index arrays for this boundary set
@@ -893,4 +524,5 @@
             &      idx_bdy(ib_bdy)%nbd   (ilen1,jpbgrd) ,   &
             &      idx_bdy(ib_bdy)%nbdout(ilen1,jpbgrd) ,   &
+            &      idx_bdy(ib_bdy)%ntreat(ilen1,jpbgrd) ,   &
             &      idx_bdy(ib_bdy)%nbmap (ilen1,jpbgrd) ,   &
             &      idx_bdy(ib_bdy)%nbw   (ilen1,jpbgrd) ,   &
@@ -900,19 +532,8 @@
          ! Dispatch mapping indices and discrete distances on each processor
          ! -----------------------------------------------------------------
-
-         com_east  = 0
-         com_west  = 0
-         com_south = 0
-         com_north = 0
-
-         com_east_b  = 0
-         com_west_b  = 0
-         com_south_b = 0
-         com_north_b = 0
-
          DO igrd = 1, jpbgrd
             icount  = 0
-            ! Loop on rimwidth to ensure outermost points come first in the local arrays.
-            DO ir=1, nn_rimwidth(ib_bdy)
+            ! Outer loop on rimwidth to ensure outermost points come first in the local arrays.
+            DO ir = 0, nn_rimwidth(ib_bdy)
                DO ib = 1, nblendta(igrd,ib_bdy)
                   ! check if point is in local domain and equals ir
@@ -922,167 +543,52 @@
                      !
                      icount = icount  + 1
-
-                     ! Rather assume that boundary data indices are given on global domain
-                     ! TO BE DISCUSSED ?
-!                     idx_bdy(ib_bdy)%nbi(icount,igrd)   = nbidta(ib,igrd,ib_bdy)- mig(1)+1
-!                     idx_bdy(ib_bdy)%nbj(icount,igrd)   = nbjdta(ib,igrd,ib_bdy)- mjg(1)+1
-                     idx_bdy(ib_bdy)%nbi(icount,igrd)   = nbidta(ib,igrd,ib_bdy)- mig(1)+1
-                     idx_bdy(ib_bdy)%nbj(icount,igrd)   = nbjdta(ib,igrd,ib_bdy)- mjg(1)+1
-                     ! check if point has to be sent
-                     ii = idx_bdy(ib_bdy)%nbi(icount,igrd)
-                     ij = idx_bdy(ib_bdy)%nbj(icount,igrd)
-                     if((com_east .ne. 1) .and. (ii == (nlci-1)) .and. (nbondi .le. 0)) then
-                        com_east = 1
-                     elseif((com_west .ne. 1) .and. (ii == 2) .and. (nbondi .ge. 0) .and. (nbondi .ne. 2)) then
-                        com_west = 1
-                     endif 
-                     if((com_south .ne. 1) .and. (ij == 2) .and. (nbondj .ge. 0) .and. (nbondj .ne. 2)) then
-                        com_south = 1
-                     elseif((com_north .ne. 1) .and. (ij == (nlcj-1)) .and. (nbondj .le. 0)) then
-                        com_north = 1
-                     endif 
+                     idx_bdy(ib_bdy)%nbi(icount,igrd)   = nbidta(ib,igrd,ib_bdy)- mig(1)+1   ! global to local indexes
+                     idx_bdy(ib_bdy)%nbj(icount,igrd)   = nbjdta(ib,igrd,ib_bdy)- mjg(1)+1   ! global to local indexes
                      idx_bdy(ib_bdy)%nbr(icount,igrd)   = nbrdta(ib,igrd,ib_bdy)
                      idx_bdy(ib_bdy)%nbmap(icount,igrd) = ib
                   ENDIF
-                  ! check if point has to be received from a neighbour
-                  IF(nbondi == 0) THEN
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(1) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(1) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(1) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(1) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ii = nbidta(ib,igrd,ib_bdy)- iw_b(1)+2
-                       if( ii == (nlcit(nowe+1)-1) ) then
-                          ij = nbjdta(ib,igrd,ib_bdy) - is_b(1)+2
-                          if((ij == 2) .and. (nbondj == 0 .or. nbondj == 1)) then
-                            com_south = 1
-                          elseif((ij == nlcjt(nowe+1)-1) .and. (nbondj == 0 .or. nbondj == -1)) then
-                            com_north = 1
-                          endif
-                          com_west_b = 1
-                       endif 
-                     ENDIF
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(2) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(2) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(2) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(2) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ii = nbidta(ib,igrd,ib_bdy)- iw_b(2)+2
-                       if( ii == 2 ) then
-                          ij = nbjdta(ib,igrd,ib_bdy) - is_b(2)+2
-                          if((ij == 2) .and. (nbondj == 0 .or. nbondj == 1)) then
-                            com_south = 1
-                          elseif((ij == nlcjt(noea+1)-1) .and. (nbondj == 0 .or. nbondj == -1)) then
-                            com_north = 1
-                          endif
-                          com_east_b = 1
-                       endif 
-                     ENDIF
-                  ELSEIF(nbondi == 1) THEN
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(1) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(1) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(1) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(1) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ii = nbidta(ib,igrd,ib_bdy)- iw_b(1)+2
-                       if( ii == (nlcit(nowe+1)-1) ) then
-                          ij = nbjdta(ib,igrd,ib_bdy) - is_b(1)+2
-                          if((ij == 2) .and. (nbondj == 0 .or. nbondj == 1)) then
-                            com_south = 1
-                          elseif((ij == nlcjt(nowe+1)-1) .and. (nbondj == 0 .or. nbondj == -1)) then
-                            com_north = 1
-                          endif
-                          com_west_b = 1
-                       endif 
-                     ENDIF
-                  ELSEIF(nbondi == -1) THEN
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(2) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(2) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(2) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(2) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ii = nbidta(ib,igrd,ib_bdy)- iw_b(2)+2
-                       if( ii == 2 ) then
-                          ij = nbjdta(ib,igrd,ib_bdy) - is_b(2)+2
-                          if((ij == 2) .and. (nbondj == 0 .or. nbondj == 1)) then
-                            com_south = 1
-                          elseif((ij == nlcjt(noea+1)-1) .and. (nbondj == 0 .or. nbondj == -1)) then
-                            com_north = 1
-                          endif
-                          com_east_b = 1
-                       endif 
-                     ENDIF
-                  ENDIF
-                  IF(nbondj == 0) THEN
-                     IF(com_north_b .ne. 1 .AND. (nbidta(ib,igrd,ib_bdy) == iw_b(4)-1  &
-                       & .OR. nbidta(ib,igrd,ib_bdy) == ie_b(4)+1) .AND. &
-                       & nbjdta(ib,igrd,ib_bdy) == is_b(4) .AND. nbrdta(ib,igrd,ib_bdy) == ir) THEN
-                       com_north_b = 1 
-                     ENDIF
-                     IF(com_south_b .ne. 1 .AND. (nbidta(ib,igrd,ib_bdy) == iw_b(3)-1  &
-                       &.OR. nbidta(ib,igrd,ib_bdy) == ie_b(3)+1) .AND. &
-                       & nbjdta(ib,igrd,ib_bdy) == in_b(3) .AND. nbrdta(ib,igrd,ib_bdy) == ir) THEN
-                       com_south_b = 1 
-                     ENDIF
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(3) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(3) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(3) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(3) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ij = nbjdta(ib,igrd,ib_bdy)- is_b(3)+2
-                       if((com_south_b .ne. 1) .and. (ij == (nlcjt(noso+1)-1))) then
-                          com_south_b = 1
-                       endif 
-                     ENDIF
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(4) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(4) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(4) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(4) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ij = nbjdta(ib,igrd,ib_bdy)- is_b(4)+2
-                       if((com_north_b .ne. 1) .and. (ij == 2)) then
-                          com_north_b = 1
-                       endif 
-                     ENDIF
-                  ELSEIF(nbondj == 1) THEN
-                     IF( com_south_b .ne. 1 .AND. (nbidta(ib,igrd,ib_bdy) == iw_b(3)-1 .OR. &
-                       & nbidta(ib,igrd,ib_bdy) == ie_b(3)+1) .AND. &
-                       & nbjdta(ib,igrd,ib_bdy) == in_b(3) .AND. nbrdta(ib,igrd,ib_bdy) == ir) THEN
-                       com_south_b = 1 
-                     ENDIF
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(3) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(3) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(3) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(3) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ij = nbjdta(ib,igrd,ib_bdy)- is_b(3)+2
-                       if((com_south_b .ne. 1) .and. (ij == (nlcjt(noso+1)-1))) then
-                          com_south_b = 1
-                       endif 
-                     ENDIF
-                  ELSEIF(nbondj == -1) THEN
-                     IF(com_north_b .ne. 1 .AND. (nbidta(ib,igrd,ib_bdy) == iw_b(4)-1  &
-                       & .OR. nbidta(ib,igrd,ib_bdy) == ie_b(4)+1) .AND. &
-                       & nbjdta(ib,igrd,ib_bdy) == is_b(4) .AND. nbrdta(ib,igrd,ib_bdy) == ir) THEN
-                       com_north_b = 1 
-                     ENDIF
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(4) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(4) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(4) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(4) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ij = nbjdta(ib,igrd,ib_bdy)- is_b(4)+2
-                       if((com_north_b .ne. 1) .and. (ij == 2)) then
-                          com_north_b = 1
-                       endif 
-                     ENDIF
-                  ENDIF
-               ENDDO
-            ENDDO
-         ENDDO 
-
-         ! definition of the i- and j- direction local boundaries arrays used for sending the boundaries
-         IF(     (com_east  == 1) .and. (com_west  == 1) ) THEN   ;   nbondi_bdy(ib_bdy) =  0
-         ELSEIF( (com_east  == 1) .and. (com_west  == 0) ) THEN   ;   nbondi_bdy(ib_bdy) = -1
-         ELSEIF( (com_east  == 0) .and. (com_west  == 1) ) THEN   ;   nbondi_bdy(ib_bdy) =  1
-         ENDIF
-         IF(     (com_north == 1) .and. (com_south == 1) ) THEN   ;   nbondj_bdy(ib_bdy) =  0
-         ELSEIF( (com_north == 1) .and. (com_south == 0) ) THEN   ;   nbondj_bdy(ib_bdy) = -1
-         ELSEIF( (com_north == 0) .and. (com_south == 1) ) THEN   ;   nbondj_bdy(ib_bdy) =  1
-         ENDIF
-
-         ! definition of the i- and j- direction local boundaries arrays used for receiving the boundaries
-         IF(     (com_east_b  == 1) .and. (com_west_b  == 1) ) THEN   ;   nbondi_bdy_b(ib_bdy) =  0
-         ELSEIF( (com_east_b  == 1) .and. (com_west_b  == 0) ) THEN   ;   nbondi_bdy_b(ib_bdy) = -1
-         ELSEIF( (com_east_b  == 0) .and. (com_west_b  == 1) ) THEN   ;   nbondi_bdy_b(ib_bdy) =  1
-         ENDIF
-         IF(     (com_north_b == 1) .and. (com_south_b == 1) ) THEN   ;   nbondj_bdy_b(ib_bdy) =  0
-         ELSEIF( (com_north_b == 1) .and. (com_south_b == 0) ) THEN   ;   nbondj_bdy_b(ib_bdy) = -1
-         ELSEIF( (com_north_b == 0) .and. (com_south_b == 1) ) THEN   ;   nbondj_bdy_b(ib_bdy) =  1
-         ENDIF
+               END DO
+            END DO
+         END DO   ! igrd
+
+      END DO   ! ib_bdy
+
+      ! Initialize array indicating communications in bdy
+      ! -------------------------------------------------
+      ALLOCATE( lsend_bdy(nb_bdy,jpbgrd,4,0:1), lrecv_bdy(nb_bdy,jpbgrd,4,0:1) )
+      lsend_bdy(:,:,:,:) = .false.
+      lrecv_bdy(:,:,:,:) = .false. 
+
+      DO ib_bdy = 1, nb_bdy
+         DO igrd = 1, jpbgrd
+            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)   ! only the rim triggers communications, see bdy routines
+               ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+               ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+               IF( ib .LE. idx_bdy(ib_bdy)%nblenrim0(igrd) ) THEN   ;   ir = 0
+               ELSE                                                 ;   ir = 1
+               END IF
+               !
+               ! check if point has to be sent     to   a neighbour
+               ! W neighbour and on the inner left  side
+               IF( ii == 2     .and. (nbondi == 0 .or. nbondi ==  1) )   lsend_bdy(ib_bdy,igrd,1,ir) = .true.
+               ! E neighbour and on the inner right side
+               IF( ii == jpi-1 .and. (nbondi == 0 .or. nbondi == -1) )   lsend_bdy(ib_bdy,igrd,2,ir) = .true.
+               ! S neighbour and on the inner down side
+               IF( ij == 2     .and. (nbondj == 0 .or. nbondj ==  1) )   lsend_bdy(ib_bdy,igrd,3,ir) = .true.
+               ! N neighbour and on the inner up   side
+               IF( ij == jpj-1 .and. (nbondj == 0 .or. nbondj == -1) )   lsend_bdy(ib_bdy,igrd,4,ir) = .true.
+               !
+               ! check if point has to be received from a neighbour
+               ! W neighbour and on the outter left  side
+               IF( ii == 1     .and. (nbondi == 0 .or. nbondi ==  1) )   lrecv_bdy(ib_bdy,igrd,1,ir) = .true.
+               ! E neighbour and on the outter right side
+               IF( ii == jpi   .and. (nbondi == 0 .or. nbondi == -1) )   lrecv_bdy(ib_bdy,igrd,2,ir) = .true.
+               ! S neighbour and on the outter down side
+               IF( ij == 1     .and. (nbondj == 0 .or. nbondj ==  1) )   lrecv_bdy(ib_bdy,igrd,3,ir) = .true.
+               ! N neighbour and on the outter up   side
+               IF( ij == jpj   .and. (nbondj == 0 .or. nbondj == -1) )   lrecv_bdy(ib_bdy,igrd,4,ir) = .true.
+               !
+            END DO
+         END DO  ! igrd
 
          ! Compute rim weights for FRS scheme
@@ -1090,10 +596,10 @@
          DO igrd = 1, jpbgrd
             DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
-               nbr => idx_bdy(ib_bdy)%nbr(ib,igrd)
-               idx_bdy(ib_bdy)%nbw(ib,igrd) = 1.- TANH( REAL( nbr - 1 ) *0.5 )      ! tanh formulation
-!               idx_bdy(ib_bdy)%nbw(ib,igrd) = (REAL(nn_rimwidth(ib_bdy)+1-nbr)/REAL(nn_rimwidth(ib_bdy)))**2.  ! quadratic
-!               idx_bdy(ib_bdy)%nbw(ib,igrd) =  REAL(nn_rimwidth(ib_bdy)+1-nbr)/REAL(nn_rimwidth(ib_bdy))       ! linear
-            END DO
-         END DO 
+               ir = MAX( 1, idx_bdy(ib_bdy)%nbr(ib,igrd) )   ! both rim 0 and rim 1 have the same weights
+               idx_bdy(ib_bdy)%nbw(ib,igrd) = 1.- TANH( REAL( ir - 1 ) *0.5 )      ! tanh formulation
+               !               idx_bdy(ib_bdy)%nbw(ib,igrd) = (REAL(nn_rimwidth(ib_bdy)+1-ir)/REAL(nn_rimwidth(ib_bdy)))**2.  ! quadratic
+               !               idx_bdy(ib_bdy)%nbw(ib,igrd) =  REAL(nn_rimwidth(ib_bdy)+1-ir)/REAL(nn_rimwidth(ib_bdy))       ! linear
+            END DO
+         END DO
 
          ! Compute damping coefficients
@@ -1101,17 +607,32 @@
          DO igrd = 1, jpbgrd
             DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
-               nbr => idx_bdy(ib_bdy)%nbr(ib,igrd)
+               ir = MAX( 1, idx_bdy(ib_bdy)%nbr(ib,igrd) )   ! both rim 0 and rim 1 have the same damping coefficients
                idx_bdy(ib_bdy)%nbd(ib,igrd) = 1. / ( rn_time_dmp(ib_bdy) * rday ) & 
-               & *(REAL(nn_rimwidth(ib_bdy)+1-nbr)/REAL(nn_rimwidth(ib_bdy)))**2.   ! quadratic
+                  & *(REAL(nn_rimwidth(ib_bdy)+1-ir)/REAL(nn_rimwidth(ib_bdy)))**2.   ! quadratic
                idx_bdy(ib_bdy)%nbdout(ib,igrd) = 1. / ( rn_time_dmp_out(ib_bdy) * rday ) & 
-               & *(REAL(nn_rimwidth(ib_bdy)+1-nbr)/REAL(nn_rimwidth(ib_bdy)))**2.   ! quadratic
-            END DO
-         END DO 
-
-      END DO
+                  & *(REAL(nn_rimwidth(ib_bdy)+1-ir)/REAL(nn_rimwidth(ib_bdy)))**2.   ! quadratic
+            END DO
+         END DO
+
+      END DO ! ib_bdy
 
       ! ------------------------------------------------------
       ! Initialise masks and find normal/tangential directions
       ! ------------------------------------------------------
+
+      ! ------------------------------------------
+      ! handle rim0, do as if rim 1 was free ocean
+      ! ------------------------------------------
+
+      ztmask(:,:) = tmask(:,:,1)   ;   zumask(:,:) = umask(:,:,1)   ;   zvmask(:,:) = vmask(:,:,1)
+      ! For the flagu/flagv calculation below we require a version of fmask without
+      ! the land boundary condition (shlat) included:
+      DO ij = 1, jpjm1
+         DO ii = 1, jpim1
+            zfmask(ii,ij) =  ztmask(ii,ij  ) * ztmask(ii+1,ij  )   &
+               &           * ztmask(ii,ij+1) * ztmask(ii+1,ij+1)
+         END DO
+      END DO
+      CALL lbc_lnk( 'bdyini', zfmask, 'F', 1. )
 
       ! Read global 2D mask at T-points: bdytmask
@@ -1119,60 +640,193 @@
       ! bdytmask = 1  on the computational domain AND on open boundaries
       !          = 0  elsewhere   
- 
+
       bdytmask(:,:) = ssmask(:,:)
 
       ! Derive mask on U and V grid from mask on T grid
-
-      bdyumask(:,:) = 0._wp
-      bdyvmask(:,:) = 0._wp
       DO ij = 1, jpjm1
          DO ii = 1, jpim1
-            bdyumask(ii,ij) = bdytmask(ii,ij) * bdytmask(ii+1, ij )
+            bdyumask(ii,ij) = bdytmask(ii,ij) * bdytmask(ii+1,ij  )
             bdyvmask(ii,ij) = bdytmask(ii,ij) * bdytmask(ii  ,ij+1)  
          END DO
       END DO
-      CALL lbc_lnk_multi( 'bdyini', bdyumask, 'U', 1. , bdyvmask, 'V', 1. )   ! Lateral boundary cond. 
-
-      ! bdy masks are now set to zero on boundary points:
-      !
-      igrd = 1
+      CALL lbc_lnk_multi( 'bdyini', bdyumask, 'U', 1., bdyvmask, 'V', 1. )   ! Lateral boundary cond.
+
+      ! bdy masks are now set to zero on rim 0 points:
       DO ib_bdy = 1, nb_bdy
-        DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)      
-          bdytmask(idx_bdy(ib_bdy)%nbi(ib,igrd), idx_bdy(ib_bdy)%nbj(ib,igrd)) = 0._wp
-        END DO
-      END DO
-      !
-      igrd = 2
+         DO ib = 1, idx_bdy(ib_bdy)%nblenrim0(1)   ! extent of rim 0
+            bdytmask(idx_bdy(ib_bdy)%nbi(ib,1), idx_bdy(ib_bdy)%nbj(ib,1)) = 0._wp
+         END DO
+         DO ib = 1, idx_bdy(ib_bdy)%nblenrim0(2)   ! extent of rim 0
+            bdyumask(idx_bdy(ib_bdy)%nbi(ib,2), idx_bdy(ib_bdy)%nbj(ib,2)) = 0._wp
+         END DO
+         DO ib = 1, idx_bdy(ib_bdy)%nblenrim0(3)   ! extent of rim 0
+            bdyvmask(idx_bdy(ib_bdy)%nbi(ib,3), idx_bdy(ib_bdy)%nbj(ib,3)) = 0._wp
+         END DO
+      END DO
+
+      CALL bdy_rim_treat( zumask, zvmask, zfmask, .true. )   ! compute flagu, flagv, ntreat on rim 0
+
+      ! ------------------------------------
+      ! handle rim1, do as if rim 0 was land
+      ! ------------------------------------
+      
+      ! z[tuv]mask are now set to zero on rim 0 points:
       DO ib_bdy = 1, nb_bdy
-        DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
-          bdyumask(idx_bdy(ib_bdy)%nbi(ib,igrd), idx_bdy(ib_bdy)%nbj(ib,igrd)) = 0._wp
-        END DO
-      END DO
-      !
-      igrd = 3
+         DO ib = 1, idx_bdy(ib_bdy)%nblenrim0(1)   ! extent of rim 0
+            ztmask(idx_bdy(ib_bdy)%nbi(ib,1), idx_bdy(ib_bdy)%nbj(ib,1)) = 0._wp
+         END DO
+         DO ib = 1, idx_bdy(ib_bdy)%nblenrim0(2)   ! extent of rim 0
+            zumask(idx_bdy(ib_bdy)%nbi(ib,2), idx_bdy(ib_bdy)%nbj(ib,2)) = 0._wp
+         END DO
+         DO ib = 1, idx_bdy(ib_bdy)%nblenrim0(3)   ! extent of rim 0
+            zvmask(idx_bdy(ib_bdy)%nbi(ib,3), idx_bdy(ib_bdy)%nbj(ib,3)) = 0._wp
+         END DO
+      END DO
+
+      ! Recompute zfmask
+      DO ij = 1, jpjm1
+         DO ii = 1, jpim1
+            zfmask(ii,ij) =  ztmask(ii,ij  ) * ztmask(ii+1,ij  )   &
+               &           * ztmask(ii,ij+1) * ztmask(ii+1,ij+1)
+         END DO
+      END DO
+      CALL lbc_lnk( 'bdyini', zfmask, 'F', 1. )
+
+      ! bdy masks are now set to zero on rim1 points:
       DO ib_bdy = 1, nb_bdy
-        DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
-          bdyvmask(idx_bdy(ib_bdy)%nbi(ib,igrd), idx_bdy(ib_bdy)%nbj(ib,igrd)) = 0._wp
-        END DO
-      END DO
-
-      ! For the flagu/flagv calculation below we require a version of fmask without
-      ! the land boundary condition (shlat) included:
-      zfmask(:,:) = 0
-      DO ij = 2, jpjm1
-         DO ii = 2, jpim1
-            zfmask(ii,ij) = tmask(ii,ij  ,1) * tmask(ii+1,ij  ,1)   &
-           &              * tmask(ii,ij+1,1) * tmask(ii+1,ij+1,1)
-         END DO      
-      END DO
-
-      ! Lateral boundary conditions
-      CALL lbc_lnk( 'bdyini', zfmask, 'F', 1. ) 
-      CALL lbc_lnk_multi( 'bdyini', bdyumask, 'U', 1. , bdyvmask, 'V', 1., bdytmask, 'T', 1. )
+         DO ib = idx_bdy(ib_bdy)%nblenrim0(1) + 1,  idx_bdy(ib_bdy)%nblenrim(1)   ! extent of rim 1
+            bdytmask(idx_bdy(ib_bdy)%nbi(ib,1), idx_bdy(ib_bdy)%nbj(ib,1)) = 0._wp
+         END DO
+         DO ib = idx_bdy(ib_bdy)%nblenrim0(2) + 1,  idx_bdy(ib_bdy)%nblenrim(2)   ! extent of rim 1
+            bdyumask(idx_bdy(ib_bdy)%nbi(ib,2), idx_bdy(ib_bdy)%nbj(ib,2)) = 0._wp
+         END DO
+         DO ib = idx_bdy(ib_bdy)%nblenrim0(3) + 1,  idx_bdy(ib_bdy)%nblenrim(3)   ! extent of rim 1
+            bdyvmask(idx_bdy(ib_bdy)%nbi(ib,3), idx_bdy(ib_bdy)%nbj(ib,3)) = 0._wp
+         END DO
+      END DO
+
+      CALL bdy_rim_treat( zumask, zvmask, zfmask, .false. )   ! compute flagu, flagv, ntreat on rim 1
+      !
+      ! Check which boundaries might need communication
+      ALLOCATE( lsend_bdyint(nb_bdy,jpbgrd,4,0:1), lrecv_bdyint(nb_bdy,jpbgrd,4,0:1) )
+      lsend_bdyint(:,:,:,:) = .false.
+      lrecv_bdyint(:,:,:,:) = .false. 
+      ALLOCATE( lsend_bdyext(nb_bdy,jpbgrd,4,0:1), lrecv_bdyext(nb_bdy,jpbgrd,4,0:1) )
+      lsend_bdyext(:,:,:,:) = .false.
+      lrecv_bdyext(:,:,:,:) = .false.
+      !
+      DO igrd = 1, jpbgrd
+         DO ib_bdy = 1, nb_bdy
+            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
+               IF( idx_bdy(ib_bdy)%ntreat(ib,igrd) == -1 ) CYCLE
+               ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+               ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+               ir = idx_bdy(ib_bdy)%nbr(ib,igrd)
+               flagu = NINT(idx_bdy(ib_bdy)%flagu(ib,igrd))
+               flagv = NINT(idx_bdy(ib_bdy)%flagv(ib,igrd))
+               iibe = ii - flagu   ! neighbouring point towards the exterior of the computational domain
+               ijbe = ij - flagv
+               iibi = ii + flagu   ! neighbouring point towards the interior of the computational domain
+               ijbi = ij + flagv
+               CALL find_neib( ii, ij, idx_bdy(ib_bdy)%ntreat(ib,igrd), ii1, ij1, ii2, ij2, ii3, ij3 )   ! free ocean neighbours
+               !
+               ! search neighbour in the  west/east  direction
+               ! Rim is on the halo and computed ocean is towards exterior of mpi domain  
+               !      <--    (o exterior)     -->  
+               ! (1)  o|x         OR    (2)   x|o
+               !       |___                 ___| 
+               IF( iibi == 0     .OR. ii1 == 0     .OR. ii2 == 0     .OR. ii3 == 0     )   lrecv_bdyint(ib_bdy,igrd,1,ir) = .true.
+               IF( iibi == jpi+1 .OR. ii1 == jpi+1 .OR. ii2 == jpi+1 .OR. ii3 == jpi+1 )   lrecv_bdyint(ib_bdy,igrd,2,ir) = .true.  
+               IF( iibe == 0                                                           )   lrecv_bdyext(ib_bdy,igrd,1,ir) = .true.
+               IF( iibe == jpi+1                                                       )   lrecv_bdyext(ib_bdy,igrd,2,ir) = .true.  
+               ! Check if neighbour has its rim parallel to its mpi subdomain border and located next to its halo
+               ! :¨¨¨¨¨|¨¨-->    |                                             |    <--¨¨|¨¨¨¨¨: 
+               ! :     |  x:o    |    neighbour limited by ... would need o    |    o:x  |     :
+               ! :.....|_._:_____|   (1) W neighbour         E neighbour (2)   |_____:_._|.....:
+               IF( ii == 2     .AND. ( nbondi ==  1 .OR. nbondi == 0 ) .AND. &
+                  & ( iibi == 3     .OR. ii1 == 3     .OR. ii2 == 3     .OR. ii3 == 3    ) )   lsend_bdyint(ib_bdy,igrd,1,ir)=.true.
+               IF( ii == jpi-1 .AND. ( nbondi == -1 .OR. nbondi == 0 ) .AND. &
+                  & ( iibi == jpi-2 .OR. ii1 == jpi-2 .OR. ii2 == jpi-2 .OR. ii3 == jpi-2) )   lsend_bdyint(ib_bdy,igrd,2,ir)=.true.
+               IF( ii == 2     .AND. ( nbondi ==  1 .OR. nbondi == 0 ) .AND. iibe == 3     )   lsend_bdyext(ib_bdy,igrd,1,ir)=.true.
+               IF( ii == jpi-1 .AND. ( nbondi == -1 .OR. nbondi == 0 ) .AND. iibe == jpi-2 )   lsend_bdyext(ib_bdy,igrd,2,ir)=.true.
+               !
+               ! search neighbour in the north/south direction   
+               ! Rim is on the halo and computed ocean is towards exterior of mpi domain
+               !(3)   |       |         ^   ___o___     
+               !  |   |___x___|   OR    |  |   x   |
+               !  v       o           (4)  |       |
+               IF( ijbi == 0     .OR. ij1 == 0     .OR. ij2 == 0     .OR. ij3 == 0     )   lrecv_bdyint(ib_bdy,igrd,3,ir) = .true.
+               IF( ijbi == jpj+1 .OR. ij1 == jpj+1 .OR. ij2 == jpj+1 .OR. ij3 == jpj+1 )   lrecv_bdyint(ib_bdy,igrd,4,ir) = .true.
+               IF( ijbe == 0                                                           )   lrecv_bdyext(ib_bdy,igrd,3,ir) = .true.
+               IF( ijbe == jpj+1                                                       )   lrecv_bdyext(ib_bdy,igrd,4,ir) = .true.
+               ! Check if neighbour has its rim parallel to its mpi subdomain     _________  border and next to its halo
+               !   ^  |    o    |                                                :         : 
+               !   |  |¨¨¨¨x¨¨¨¨|   neighbour limited by ... would need o     |  |....x....|
+               !      :_________:  (3) S neighbour          N neighbour (4)   v  |    o    |   
+               IF( ij == 2     .AND. ( nbondj ==  1 .OR. nbondj == 0 ) .AND. &
+                  & ( ijbi == 3     .OR. ij1 == 3     .OR. ij2 == 3     .OR. ij3 == 3    ) )   lsend_bdyint(ib_bdy,igrd,3,ir)=.true.
+               IF( ij == jpj-1 .AND. ( nbondj == -1 .OR. nbondj == 0 ) .AND. &
+                  & ( ijbi == jpj-2 .OR. ij1 == jpj-2 .OR. ij2 == jpj-2 .OR. ij3 == jpj-2) )   lsend_bdyint(ib_bdy,igrd,4,ir)=.true.
+               IF( ij == 2     .AND. ( nbondj ==  1 .OR. nbondj == 0 ) .AND. ijbe == 3     )   lsend_bdyext(ib_bdy,igrd,3,ir)=.true.
+               IF( ij == jpj-1 .AND. ( nbondj == -1 .OR. nbondj == 0 ) .AND. ijbe == jpj-2 )   lsend_bdyext(ib_bdy,igrd,4,ir)=.true.
+            END DO
+         END DO
+      END DO
+
+      DO ib_bdy = 1,nb_bdy
+         IF(  cn_dyn2d(ib_bdy) == 'orlanski' .OR. cn_dyn2d(ib_bdy) == 'orlanski_npo' .OR. &
+            & cn_dyn3d(ib_bdy) == 'orlanski' .OR. cn_dyn3d(ib_bdy) == 'orlanski_npo' .OR. &
+            & cn_tra(ib_bdy)   == 'orlanski' .OR. cn_tra(ib_bdy)   == 'orlanski_npo'      ) THEN
+            DO igrd = 1, jpbgrd
+               DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
+                  ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                  ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                  IF(  mig(ii) > 2 .AND. mig(ii) < jpiglo-2 .AND. mjg(ij) > 2 .AND. mjg(ij) < jpjglo-2  ) THEN
+                     WRITE(ctmp1,*) ' Orlanski is not safe when the open boundaries are on the interior of the computational domain'
+                     CALL ctl_stop( ctmp1 )
+                  END IF
+               END DO
+            END DO
+         END IF
+      END DO
+      !
+      DEALLOCATE( nbidta, nbjdta, nbrdta )
+      !
+   END SUBROUTINE bdy_def
+
+
+   SUBROUTINE bdy_rim_treat( pumask, pvmask, pfmask, lrim0 )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE bdy_rim_treat  ***
+      !!
+      !! ** Purpose :   Initialize structures ( flagu, flagv, ntreat ) indicating how rim points
+      !!                  are to be handled in the boundary condition treatment
+      !!
+      !! ** Method  :   - to handle rim 0 zmasks must indicate ocean points      (set at one on rim 0 and rim 1 and interior)
+      !!                            and bdymasks must be set at 0 on rim 0       (set at one on rim 1 and interior)
+      !!                    (as if rim 1 was free ocean)
+      !!                - to handle rim 1 zmasks must be set at 0 on rim 0       (set at one on rim 1 and interior)
+      !!                            and bdymasks must indicate free ocean points (set at one on interior)
+      !!                    (as if rim 0 was land)
+      !!                - we can then check in which direction the interior of the computational domain is with the difference
+      !!                         mask array values on both sides to compute flagu and flagv
+      !!                - and look at the ocean neighbours to compute ntreat
+      !!----------------------------------------------------------------------
+      REAL(wp), TARGET, DIMENSION(jpi,jpj), INTENT (in   ) :: pfmask   ! temporary fmask excluding coastal boundary condition (shlat)
+      REAL(wp), TARGET, DIMENSION(jpi,jpj), INTENT (in   ) :: pumask, pvmask   ! temporary t/u/v mask array
+      LOGICAL                             , INTENT (in   ) :: lrim0    ! .true. -> rim 0   .false. -> rim 1
+      INTEGER  ::   ib_bdy, ii, ij, igrd, ib, icount       ! dummy loop indices
+      INTEGER  ::   i_offset, j_offset, inn                ! local integer
+      INTEGER  ::   ibeg, iend                             ! local integer
+      LOGICAL  ::   llnon, llson, llean, llwen             ! local logicals indicating the presence of a ocean neighbour
+      REAL(wp), POINTER, DIMENSION(:,:)       ::   zmask   ! pointer to 2D mask fields
+      REAL(wp) ::   zefl, zwfl, znfl, zsfl                 ! local scalars
+      CHARACTER(LEN=1), DIMENSION(jpbgrd)     ::   cgrid
+      REAL(wp)        , DIMENSION(jpi,jpj)    ::   ztmp
+      !!----------------------------------------------------------------------
+
+      cgrid = (/'t','u','v'/)
+
       DO ib_bdy = 1, nb_bdy       ! Indices and directions of rim velocity components
-
-         idx_bdy(ib_bdy)%flagu(:,:) = 0._wp
-         idx_bdy(ib_bdy)%flagv(:,:) = 0._wp
-         icount = 0 
 
          ! Calculate relationship of U direction to the local orientation of the boundary
@@ -1180,31 +834,46 @@
          ! flagu =  0 : u is tangential
          ! flagu =  1 : u is normal to the boundary and is direction is inward
-  
          DO igrd = 1, jpbgrd 
             SELECT CASE( igrd )
-               CASE( 1 )   ;   pmask => umask   (:,:,1)   ;   i_offset = 0
-               CASE( 2 )   ;   pmask => bdytmask(:,:)     ;   i_offset = 1
-               CASE( 3 )   ;   pmask => zfmask  (:,:)     ;   i_offset = 0
+               CASE( 1 )   ;   zmask => pumask     ;   i_offset = 0
+               CASE( 2 )   ;   zmask => bdytmask   ;   i_offset = 1
+               CASE( 3 )   ;   zmask => pfmask     ;   i_offset = 0
             END SELECT 
             icount = 0
-            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)  
-               nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
-               nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
-               zefl = pmask(nbi+i_offset-1,nbj)
-               zwfl = pmask(nbi+i_offset,nbj)
+            ztmp(:,:) = -999._wp
+            IF( lrim0 ) THEN   ! extent of rim 0
+               ibeg = 1                                     ;   iend = idx_bdy(ib_bdy)%nblenrim0(igrd)
+            ELSE               ! extent of rim 1
+               ibeg = idx_bdy(ib_bdy)%nblenrim0(igrd) + 1   ;   iend = idx_bdy(ib_bdy)%nblenrim(igrd)
+            END IF
+            DO ib = ibeg, iend 
+               ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+               ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+               IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )  CYCLE
+               zwfl = zmask(ii+i_offset-1,ij)
+               zefl = zmask(ii+i_offset  ,ij)
                ! This error check only works if you are using the bdyXmask arrays
-               IF( i_offset == 1 .and. zefl + zwfl == 2 ) THEN
+               IF( i_offset == 1 .and. zefl + zwfl == 2. ) THEN
                   icount = icount + 1
-                  IF(lwp) WRITE(numout,*) 'Problem with igrd = ',igrd,' at (global) nbi, nbj : ',mig(nbi),mjg(nbj)
+                  IF(lwp) WRITE(numout,*) 'Problem with igrd = ',igrd,' at (global) nbi, nbj : ',mig(ii),mjg(ij)
                ELSE
-                  idx_bdy(ib_bdy)%flagu(ib,igrd) = -zefl + zwfl
+                  ztmp(ii,ij) = -zwfl + zefl
                ENDIF
             END DO
             IF( icount /= 0 ) THEN
-               WRITE(ctmp1,*) ' E R R O R : Some ',cgrid(igrd),' grid points,',   &
+               WRITE(ctmp1,*) 'Some ',cgrid(igrd),' grid points,',   &
                   ' are not boundary points (flagu calculation). Check nbi, nbj, indices for boundary set ',ib_bdy
-               WRITE(ctmp2,*) ' ========== '
-               CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+               CALL ctl_stop( ctmp1 )
             ENDIF 
+            SELECT CASE( igrd )
+               CASE( 1 )   ;   CALL lbc_lnk( 'bdyini', ztmp, 'T', 1. ) 
+               CASE( 2 )   ;   CALL lbc_lnk( 'bdyini', ztmp, 'U', 1. ) 
+               CASE( 3 )   ;   CALL lbc_lnk( 'bdyini', ztmp, 'V', 1. ) 
+            END SELECT 
+            DO ib = ibeg, iend
+               ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+               ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+               idx_bdy(ib_bdy)%flagu(ib,igrd) = ztmp(ii,ij)
+            END DO
          END DO
 
@@ -1213,41 +882,274 @@
          ! flagv =  0 : v is tangential
          ! flagv =  1 : v is normal to the boundary and is direction is inward
-
          DO igrd = 1, jpbgrd 
             SELECT CASE( igrd )
-               CASE( 1 )   ;   pmask => vmask (:,:,1)   ;   j_offset = 0
-               CASE( 2 )   ;   pmask => zfmask(:,:)     ;   j_offset = 0
-               CASE( 3 )   ;   pmask => bdytmask        ;   j_offset = 1
+               CASE( 1 )   ;   zmask => pvmask     ;   j_offset = 0
+               CASE( 2 )   ;   zmask => pfmask     ;   j_offset = 0
+               CASE( 3 )   ;   zmask => bdytmask   ;   j_offset = 1
             END SELECT 
             icount = 0
-            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)  
-               nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
-               nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
-               znfl = pmask(nbi,nbj+j_offset-1)
-               zsfl = pmask(nbi,nbj+j_offset  )
+            ztmp(:,:) = -999._wp
+            IF( lrim0 ) THEN   ! extent of rim 0
+               ibeg = 1                                     ;   iend = idx_bdy(ib_bdy)%nblenrim0(igrd)
+            ELSE               ! extent of rim 1
+               ibeg = idx_bdy(ib_bdy)%nblenrim0(igrd) + 1   ;   iend = idx_bdy(ib_bdy)%nblenrim(igrd)
+            END IF
+            DO ib = ibeg, iend
+               ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+               ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+               IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )  CYCLE
+               zsfl = zmask(ii,ij+j_offset-1)
+               znfl = zmask(ii,ij+j_offset  )
                ! This error check only works if you are using the bdyXmask arrays
-               IF( j_offset == 1 .and. znfl + zsfl == 2 ) THEN
-                  IF(lwp) WRITE(numout,*) 'Problem with igrd = ',igrd,' at (global) nbi, nbj : ',mig(nbi),mjg(nbj)
+               IF( j_offset == 1 .and. znfl + zsfl == 2. ) THEN
+                  IF(lwp) WRITE(numout,*) 'Problem with igrd = ',igrd,' at (global) nbi, nbj : ',mig(ii),mjg(ij)
                   icount = icount + 1
                ELSE
-                  idx_bdy(ib_bdy)%flagv(ib,igrd) = -znfl + zsfl
+                  ztmp(ii,ij) = -zsfl + znfl
                END IF
             END DO
             IF( icount /= 0 ) THEN
-               WRITE(ctmp1,*) ' E R R O R : Some ',cgrid(igrd),' grid points,',   &
+               WRITE(ctmp1,*) 'Some ',cgrid(igrd),' grid points,',   &
                   ' are not boundary points (flagv calculation). Check nbi, nbj, indices for boundary set ',ib_bdy
-               WRITE(ctmp2,*) ' ========== '
-               CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
-            ENDIF 
-         END DO
-         !
-      END DO
-      !
-      ! Tidy up
-      !--------
-      IF( nb_bdy>0 )   DEALLOCATE( nbidta, nbjdta, nbrdta )
-      !
-   END SUBROUTINE bdy_segs
-
+               CALL ctl_stop( ctmp1 )
+            ENDIF
+            SELECT CASE( igrd )
+               CASE( 1 )   ;   CALL lbc_lnk( 'bdyini', ztmp, 'T', 1. ) 
+               CASE( 2 )   ;   CALL lbc_lnk( 'bdyini', ztmp, 'U', 1. ) 
+               CASE( 3 )   ;   CALL lbc_lnk( 'bdyini', ztmp, 'V', 1. ) 
+            END SELECT 
+            DO ib = ibeg, iend
+               ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+               ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+               idx_bdy(ib_bdy)%flagv(ib,igrd) = ztmp(ii,ij)
+            END DO
+         END DO
+         !
+      END DO ! ib_bdy
+      
+      DO ib_bdy = 1, nb_bdy
+         DO igrd = 1, jpbgrd
+            SELECT CASE( igrd )
+               CASE( 1 )   ;   zmask => bdytmask 
+               CASE( 2 )   ;   zmask => bdyumask 
+               CASE( 3 )   ;   zmask => bdyvmask 
+            END SELECT
+            ztmp(:,:) = -999._wp
+            IF( lrim0 ) THEN   ! extent of rim 0
+               ibeg = 1                                     ;   iend = idx_bdy(ib_bdy)%nblenrim0(igrd)
+            ELSE               ! extent of rim 1
+               ibeg = idx_bdy(ib_bdy)%nblenrim0(igrd) + 1   ;   iend = idx_bdy(ib_bdy)%nblenrim(igrd)
+            END IF
+            DO ib = ibeg, iend
+               ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+               ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+               IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )   CYCLE
+               llnon = zmask(ii  ,ij+1) == 1.  
+               llson = zmask(ii  ,ij-1) == 1. 
+               llean = zmask(ii+1,ij  ) == 1. 
+               llwen = zmask(ii-1,ij  ) == 1. 
+               inn  = COUNT( (/ llnon, llson, llean, llwen /) )
+               IF( inn == 0 ) THEN   ! no neighbours -> interior of a corner  or  cluster of rim points
+                  !               !              !     _____     !     _____    !    __     __
+                  !  1 |   o      !  2  o   |    !  3 | x        !  4     x |   !      |   |   -> error
+                  !    |_x_ _     !    _ _x_|    !    |   o      !      o   |   !      |x_x|
+                  IF(     zmask(ii+1,ij+1) == 1. ) THEN   ;   ztmp(ii,ij) = 1.
+                  ELSEIF( zmask(ii-1,ij+1) == 1. ) THEN   ;   ztmp(ii,ij) = 2.
+                  ELSEIF( zmask(ii+1,ij-1) == 1. ) THEN   ;   ztmp(ii,ij) = 3.
+                  ELSEIF( zmask(ii-1,ij-1) == 1. ) THEN   ;   ztmp(ii,ij) = 4.
+                  ELSE                                    ;   ztmp(ii,ij) = -1.
+                     WRITE(ctmp1,*) 'Problem with  ',cgrid(igrd) ,' grid point', ii, ij,   &
+                       ' on boundary set ', ib_bdy, ' has no free ocean neighbour'
+                     IF( lrim0 ) THEN
+                        WRITE(ctmp2,*) ' There seems to be a cluster of rim 0 points.'
+                     ELSE
+                        WRITE(ctmp2,*) ' There seems to be a cluster of rim 1 points.'
+                     END IF
+                     CALL ctl_warn( ctmp1, ctmp2 )
+                  END IF
+               END IF
+               IF( inn == 1 ) THEN   ! middle of linear bdy  or incomplete corner  ! ___ o
+                  !    |         !         |   !      o     !    ______            !    |x___
+                  ! 5  | x o     ! 6   o x |   ! 7  __x__   ! 8    x
+                  !    |         !         |   !            !      o
+                  IF( llean )   ztmp(ii,ij) = 5.
+                  IF( llwen )   ztmp(ii,ij) = 6.
+                  IF( llnon )   ztmp(ii,ij) = 7.
+                  IF( llson )   ztmp(ii,ij) = 8.
+               END IF
+               IF( inn == 2 ) THEN   ! exterior of a corner
+                  !        o      !        o      !    _____|       !       |_____  
+                  !  9 ____x o    ! 10   o x___   ! 11     x o      ! 12   o x      
+                  !         |     !       |       !        o        !        o 
+                  IF( llnon .AND. llean )   ztmp(ii,ij) =  9.
+                  IF( llnon .AND. llwen )   ztmp(ii,ij) = 10.
+                  IF( llson .AND. llean )   ztmp(ii,ij) = 11.
+                  IF( llson .AND. llwen )   ztmp(ii,ij) = 12.
+               END IF
+               IF( inn == 3 ) THEN   ! 3 neighbours     __   __
+                  !    |_  o      !        o  _|  !       |_|     !       o         
+                  ! 13  _| x o    ! 14   o x |_   ! 15   o x o    ! 16  o x o       
+                  !    |   o      !        o   |  !        o      !    __|¨|__    
+                  IF( llnon .AND. llean .AND. llson )   ztmp(ii,ij) = 13.
+                  IF( llnon .AND. llwen .AND. llson )   ztmp(ii,ij) = 14.
+                  IF( llwen .AND. llson .AND. llean )   ztmp(ii,ij) = 15.
+                  IF( llwen .AND. llnon .AND. llean )   ztmp(ii,ij) = 16.
+               END IF
+               IF( inn == 4 ) THEN
+                  WRITE(ctmp1,*)  'Problem with  ',cgrid(igrd) ,' grid point', ii, ij,   &
+                       ' on boundary set ', ib_bdy, ' have 4 neighbours'
+                  CALL ctl_stop( ctmp1 )
+               END IF
+            END DO
+            SELECT CASE( igrd )
+               CASE( 1 )   ;   CALL lbc_lnk( 'bdyini', ztmp, 'T', 1. ) 
+               CASE( 2 )   ;   CALL lbc_lnk( 'bdyini', ztmp, 'U', 1. ) 
+               CASE( 3 )   ;   CALL lbc_lnk( 'bdyini', ztmp, 'V', 1. ) 
+            END SELECT 
+            DO ib = ibeg, iend
+               ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+               ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+               idx_bdy(ib_bdy)%ntreat(ib,igrd) = NINT(ztmp(ii,ij))
+            END DO
+         END DO
+      END DO
+
+    END SUBROUTINE bdy_rim_treat
+
+   
+    SUBROUTINE find_neib( ii, ij, itreat, ii1, ij1, ii2, ij2, ii3, ij3 )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE find_neib  ***
+      !!
+      !! ** Purpose :   get ii1, ij1, ii2, ij2, ii3, ij3, the indices of
+      !!               the free ocean neighbours of (ii,ij) for bdy treatment
+      !!
+      !! ** Method  :  use itreat input to select a case
+      !!               N.B. ntreat is defined for all bdy points in routine bdy_rim_treat
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in   )      ::   ii, ij, itreat
+      INTEGER, INTENT(  out)      ::   ii1, ij1, ii2, ij2, ii3, ij3
+      !!----------------------------------------------------------------------
+      SELECT CASE( itreat )   ! points that will be used by bdy routines, -1 will be discarded
+         !               !               !     _____     !     _____     
+         !  1 |   o      !  2  o   |     !  3 | x        !  4     x |    
+         !    |_x_ _     !    _ _x_|     !    |   o      !      o   |
+      CASE( 1 )    ;   ii1 = ii+1   ;   ij1 = ij+1   ;   ii2 = -1     ;   ij2 = -1     ;   ii3 = -1     ;   ij3 = -1
+      CASE( 2 )    ;   ii1 = ii-1   ;   ij1 = ij+1   ;   ii2 = -1     ;   ij2 = -1     ;   ii3 = -1     ;   ij3 = -1
+      CASE( 3 )    ;   ii1 = ii+1   ;   ij1 = ij-1   ;   ii2 = -1     ;   ij2 = -1     ;   ii3 = -1     ;   ij3 = -1
+      CASE( 4 )    ;   ii1 = ii-1   ;   ij1 = ij-1   ;   ii2 = -1     ;   ij2 = -1     ;   ii3 = -1     ;   ij3 = -1
+         !    |          !         |     !      o        !    ______                   ! or incomplete corner
+         ! 5  | x o      ! 6   o x |     ! 7  __x__      ! 8    x                      !  7  ____ o
+         !    |          !         |     !               !      o                      !         |x___
+      CASE( 5 )    ;   ii1 = ii+1   ;   ij1 = ij     ;   ii2 = -1     ;   ij2 = -1     ;   ii3 = -1     ;   ij3 = -1
+      CASE( 6 )    ;   ii1 = ii-1   ;   ij1 = ij     ;   ii2 = -1     ;   ij2 = -1     ;   ii3 = -1     ;   ij3 = -1
+      CASE( 7 )    ;   ii1 = ii     ;   ij1 = ij+1   ;   ii2 = -1     ;   ij2 = -1     ;   ii3 = -1     ;   ij3 = -1
+      CASE( 8 )    ;   ii1 = ii     ;   ij1 = ij-1   ;   ii2 = -1     ;   ij2 = -1     ;   ii3 = -1     ;   ij3 = -1
+         !        o      !        o      !    _____|     !       |_____  
+         !  9 ____x o    ! 10   o x___   ! 11     x o    ! 12   o x      
+         !         |     !       |       !        o      !        o      
+      CASE( 9  )   ;   ii1 = ii     ;   ij1 = ij+1   ;   ii2 = ii+1   ;   ij2 = ij     ;   ii3 = -1     ;   ij3 = -1 
+      CASE( 10 )   ;   ii1 = ii     ;   ij1 = ij+1   ;   ii2 = ii-1   ;   ij2 = ij     ;   ii3 = -1     ;   ij3 = -1
+      CASE( 11 )   ;   ii1 = ii     ;   ij1 = ij-1   ;   ii2 = ii+1   ;   ij2 = ij     ;   ii3 = -1     ;   ij3 = -1
+      CASE( 12 )   ;   ii1 = ii     ;   ij1 = ij-1   ;   ii2 = ii-1   ;   ij2 = ij     ;   ii3 = -1     ;   ij3 = -1
+         !    |_  o      !        o  _|  !     ¨¨|_|¨¨   !       o         
+         ! 13  _| x o    !  14  o x |_   !  15  o x o    ! 16  o x o       
+         !    |   o      !        o   |  !        o      !    __|¨|__ 
+      CASE( 13 )   ;   ii1 = ii     ;   ij1 = ij+1   ;   ii2 = ii+1   ;   ij2 = ij     ;   ii3 = ii     ;   ij3 = ij-1   
+      CASE( 14 )   ;   ii1 = ii     ;   ij1 = ij+1   ;   ii2 = ii-1   ;   ij2 = ij     ;   ii3 = ii     ;   ij3 = ij-1 
+      CASE( 15 )   ;   ii1 = ii-1   ;   ij1 = ij     ;   ii2 = ii     ;   ij2 = ij-1   ;   ii3 = ii+1   ;   ij3 = ij   
+      CASE( 16 )   ;   ii1 = ii-1   ;   ij1 = ij     ;   ii2 = ii     ;   ij2 = ij+1   ;   ii3 = ii+1   ;   ij3 = ij
+      END SELECT
+   END SUBROUTINE find_neib
+    
+
+   SUBROUTINE bdy_read_seg( kb_bdy, knblendta ) 
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE bdy_coords_seg  ***
+      !!
+      !! ** Purpose :  build bdy coordinates with segments defined in namelist
+      !!
+      !! ** Method  :  read namelist nambdy_index blocks
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER                   , INTENT (in   ) ::   kb_bdy           ! bdy number
+      INTEGER, DIMENSION(jpbgrd), INTENT (  out) ::   knblendta        ! length of index arrays 
+      !!
+      INTEGER          ::   ios                 ! Local integer output status for namelist read
+      INTEGER          ::   nbdyind, nbdybeg, nbdyend
+      CHARACTER(LEN=1) ::   ctypebdy   !     -        - 
+      NAMELIST/nambdy_index/ ctypebdy, nbdyind, nbdybeg, nbdyend
+      !!----------------------------------------------------------------------
+
+      ! No REWIND here because may need to read more than one nambdy_index namelist.
+      ! Read only namelist_cfg to avoid unseccessfull overwrite 
+      ! keep full control of the configuration namelist
+      READ  ( numnam_cfg, nambdy_index, IOSTAT = ios, ERR = 904 )
+904   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy_index in configuration namelist' )
+      IF(lwm) WRITE ( numond, nambdy_index )
+      
+      SELECT CASE ( TRIM(ctypebdy) )
+      CASE( 'N' )
+         IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
+            nbdyind  = jpjglo - 2  ! set boundary to whole side of model domain.
+            nbdybeg  = 2
+            nbdyend  = jpiglo - 1
+         ENDIF
+         nbdysegn = nbdysegn + 1
+         npckgn(nbdysegn) = kb_bdy ! Save bdy package number
+         jpjnob(nbdysegn) = nbdyind
+         jpindt(nbdysegn) = nbdybeg
+         jpinft(nbdysegn) = nbdyend
+         !
+      CASE( 'S' )
+         IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
+            nbdyind  = 2           ! set boundary to whole side of model domain.
+            nbdybeg  = 2
+            nbdyend  = jpiglo - 1
+         ENDIF
+         nbdysegs = nbdysegs + 1
+         npckgs(nbdysegs) = kb_bdy ! Save bdy package number
+         jpjsob(nbdysegs) = nbdyind
+         jpisdt(nbdysegs) = nbdybeg
+         jpisft(nbdysegs) = nbdyend
+         !
+      CASE( 'E' )
+         IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
+            nbdyind  = jpiglo - 2  ! set boundary to whole side of model domain.
+            nbdybeg  = 2
+            nbdyend  = jpjglo - 1
+         ENDIF
+         nbdysege = nbdysege + 1 
+         npckge(nbdysege) = kb_bdy ! Save bdy package number
+         jpieob(nbdysege) = nbdyind
+         jpjedt(nbdysege) = nbdybeg
+         jpjeft(nbdysege) = nbdyend
+         !
+      CASE( 'W' )
+         IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
+            nbdyind  = 2           ! set boundary to whole side of model domain.
+            nbdybeg  = 2
+            nbdyend  = jpjglo - 1
+         ENDIF
+         nbdysegw = nbdysegw + 1
+         npckgw(nbdysegw) = kb_bdy ! Save bdy package number
+         jpiwob(nbdysegw) = nbdyind
+         jpjwdt(nbdysegw) = nbdybeg
+         jpjwft(nbdysegw) = nbdyend
+         !
+      CASE DEFAULT   ;   CALL ctl_stop( 'ctypebdy must be N, S, E or W' )
+      END SELECT
+      
+      ! For simplicity we assume that in case of straight bdy, arrays have the same length
+      ! (even if it is true that last tangential velocity points
+      ! are useless). This simplifies a little bit boundary data format (and agrees with format
+      ! used so far in obc package)
+      
+      knblendta(1:jpbgrd) =  (nbdyend - nbdybeg + 1) * nn_rimwidth(kb_bdy)
+      
+   END SUBROUTINE bdy_read_seg
+
+   
    SUBROUTINE bdy_ctl_seg
       !!----------------------------------------------------------------------
@@ -1279,6 +1181,6 @@
             &(jpjnob(ib).le.1))        CALL ctl_stop( 'nbdyind out of domain' )
          IF (jpindt(ib).ge.jpinft(ib)) CALL ctl_stop( 'Bdy start index is greater than end index' )
-         IF (jpindt(ib).le.1     )     CALL ctl_stop( 'Start index out of domain' )
-         IF (jpinft(ib).ge.jpiglo)     CALL ctl_stop( 'End index out of domain' )
+         IF (jpindt(ib).lt.1     )     CALL ctl_stop( 'Start index out of domain' )
+         IF (jpinft(ib).gt.jpiglo)     CALL ctl_stop( 'End index out of domain' )
       END DO
       !
@@ -1288,6 +1190,6 @@
             &(jpjsob(ib).le.1))        CALL ctl_stop( 'nbdyind out of domain' )
          IF (jpisdt(ib).ge.jpisft(ib)) CALL ctl_stop( 'Bdy start index is greater than end index' )
-         IF (jpisdt(ib).le.1     )     CALL ctl_stop( 'Start index out of domain' )
-         IF (jpisft(ib).ge.jpiglo)     CALL ctl_stop( 'End index out of domain' )
+         IF (jpisdt(ib).lt.1     )     CALL ctl_stop( 'Start index out of domain' )
+         IF (jpisft(ib).gt.jpiglo)     CALL ctl_stop( 'End index out of domain' )
       END DO
       !
@@ -1297,6 +1199,6 @@
             &(jpieob(ib).le.1))        CALL ctl_stop( 'nbdyind out of domain' )
          IF (jpjedt(ib).ge.jpjeft(ib)) CALL ctl_stop( 'Bdy start index is greater than end index' )
-         IF (jpjedt(ib).le.1     )     CALL ctl_stop( 'Start index out of domain' )
-         IF (jpjeft(ib).ge.jpjglo)     CALL ctl_stop( 'End index out of domain' )
+         IF (jpjedt(ib).lt.1     )     CALL ctl_stop( 'Start index out of domain' )
+         IF (jpjeft(ib).gt.jpjglo)     CALL ctl_stop( 'End index out of domain' )
       END DO
       !
@@ -1306,6 +1208,6 @@
             &(jpiwob(ib).le.1))        CALL ctl_stop( 'nbdyind out of domain' )
          IF (jpjwdt(ib).ge.jpjwft(ib)) CALL ctl_stop( 'Bdy start index is greater than end index' )
-         IF (jpjwdt(ib).le.1     )     CALL ctl_stop( 'Start index out of domain' )
-         IF (jpjwft(ib).ge.jpjglo)     CALL ctl_stop( 'End index out of domain' )
+         IF (jpjwdt(ib).lt.1     )     CALL ctl_stop( 'Start index out of domain' )
+         IF (jpjwft(ib).gt.jpjglo)     CALL ctl_stop( 'End index out of domain' )
       ENDDO
       !
@@ -1336,15 +1238,15 @@
                      icorns(ib2,1) = npckgw(ib1)
                   ELSEIF ((jpisft(ib2)==jpiwob(ib1)).AND.(jpjwft(ib1)==jpjsob(ib2))) THEN
-                     WRITE(ctmp1,*) ' E R R O R : Found an acute open boundary corner at point (i,j)= ', &
+                     WRITE(ctmp1,*) ' Found an acute open boundary corner at point (i,j)= ', &
                         &                                     jpisft(ib2), jpjwft(ib1)
-                     WRITE(ctmp2,*) ' ==========  Not allowed yet'
-                     WRITE(ctmp3,*) '             Crossing problem with West segment: ',npckgw(ib1), & 
-                        &                                        ' and South segment: ',npckgs(ib2)
-                     CALL ctl_stop( ' ', ctmp1, ctmp2, ctmp3, ' ' )
+                     WRITE(ctmp2,*) ' Not allowed yet'
+                     WRITE(ctmp3,*) ' Crossing problem with West segment: ',npckgw(ib1), & 
+                        &                            ' and South segment: ',npckgs(ib2)
+                     CALL ctl_stop( ctmp1, ctmp2, ctmp3 )
                   ELSE
-                     WRITE(ctmp1,*) ' E R R O R : Check South and West Open boundary indices'
-                     WRITE(ctmp2,*) ' ==========  Crossing problem with West segment: ',npckgw(ib1) , &
-                        &                                         ' and South segment: ',npckgs(ib2)
-                     CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+                     WRITE(ctmp1,*) ' Check South and West Open boundary indices'
+                     WRITE(ctmp2,*) ' Crossing problem with West segment: ',npckgw(ib1) , &
+                        &                            ' and South segment: ',npckgs(ib2)
+                     CALL ctl_stop( ctmp1, ctmp2 )
                   END IF
                END IF
@@ -1368,15 +1270,15 @@
                      icorns(ib2,2) = npckge(ib1)
                   ELSEIF ((jpjeft(ib1)==jpjsob(ib2)).AND.(jpisdt(ib2)==jpieob(ib1)+1)) THEN
-                     WRITE(ctmp1,*) ' E R R O R : Found an acute open boundary corner at point (i,j)= ', &
+                     WRITE(ctmp1,*) ' Found an acute open boundary corner at point (i,j)= ', &
                         &                                     jpisdt(ib2), jpjeft(ib1)
-                     WRITE(ctmp2,*) ' ==========  Not allowed yet'
-                     WRITE(ctmp3,*) '             Crossing problem with East segment: ',npckge(ib1), &
-                        &                                        ' and South segment: ',npckgs(ib2)
-                     CALL ctl_stop( ' ', ctmp1, ctmp2, ctmp3, ' ' )
+                     WRITE(ctmp2,*) ' Not allowed yet'
+                     WRITE(ctmp3,*) ' Crossing problem with East segment: ',npckge(ib1), &
+                        &                            ' and South segment: ',npckgs(ib2)
+                     CALL ctl_stop( ctmp1, ctmp2, ctmp3 )
                   ELSE
-                     WRITE(ctmp1,*) ' E R R O R : Check South and East Open boundary indices'
-                     WRITE(ctmp2,*) ' ==========  Crossing problem with East segment: ',npckge(ib1), &
-                     &                                           ' and South segment: ',npckgs(ib2)
-                     CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+                     WRITE(ctmp1,*) ' Check South and East Open boundary indices'
+                     WRITE(ctmp2,*) ' Crossing problem with East segment: ',npckge(ib1), &
+                     &                               ' and South segment: ',npckgs(ib2)
+                     CALL ctl_stop( ctmp1, ctmp2 )
                   END IF
                END IF
@@ -1400,15 +1302,15 @@
                      icornn(ib2,1) = npckgw(ib1)
                   ELSEIF ((jpjwdt(ib1)==jpjnob(ib2)+1).AND.(jpinft(ib2)==jpiwob(ib1))) THEN
-                     WRITE(ctmp1,*) ' E R R O R : Found an acute open boundary corner at point (i,j)= ', &
+                     WRITE(ctmp1,*) ' Found an acute open boundary corner at point (i,j)= ', &
                      &                                     jpinft(ib2), jpjwdt(ib1)
-                     WRITE(ctmp2,*) ' ==========  Not allowed yet'
-                     WRITE(ctmp3,*) '             Crossing problem with West segment: ',npckgw(ib1), &
-                     &                                                    ' and North segment: ',npckgn(ib2)
-                     CALL ctl_stop( ' ', ctmp1, ctmp2, ctmp3, ' ' )
+                     WRITE(ctmp2,*) ' Not allowed yet'
+                     WRITE(ctmp3,*) ' Crossing problem with West segment: ',npckgw(ib1), &
+                     &                               ' and North segment: ',npckgn(ib2)
+                     CALL ctl_stop( ctmp1, ctmp2, ctmp3 )
                   ELSE
-                     WRITE(ctmp1,*) ' E R R O R : Check North and West Open boundary indices'
-                     WRITE(ctmp2,*) ' ==========  Crossing problem with West segment: ',npckgw(ib1), &
-                     &                                                    ' and North segment: ',npckgn(ib2)
-                     CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+                     WRITE(ctmp1,*) ' Check North and West Open boundary indices'
+                     WRITE(ctmp2,*) ' Crossing problem with West segment: ',npckgw(ib1), &
+                     &                               ' and North segment: ',npckgn(ib2)
+                     CALL ctl_stop( ctmp1, ctmp2 )
                   END IF
                END IF
@@ -1432,15 +1334,15 @@
                      icornn(ib2,2) = npckge(ib1)
                   ELSEIF ((jpjedt(ib1)==jpjnob(ib2)+1).AND.(jpindt(ib2)==jpieob(ib1)+1)) THEN
-                     WRITE(ctmp1,*) ' E R R O R : Found an acute open boundary corner at point (i,j)= ', &
+                     WRITE(ctmp1,*) ' Found an acute open boundary corner at point (i,j)= ', &
                      &                                     jpindt(ib2), jpjedt(ib1)
-                     WRITE(ctmp2,*) ' ==========  Not allowed yet'
-                     WRITE(ctmp3,*) '             Crossing problem with East segment: ',npckge(ib1), &
-                     &                                           ' and North segment: ',npckgn(ib2)
-                     CALL ctl_stop( ' ', ctmp1, ctmp2, ctmp3, ' ' )
+                     WRITE(ctmp2,*) ' Not allowed yet'
+                     WRITE(ctmp3,*) ' Crossing problem with East segment: ',npckge(ib1), &
+                     &                               ' and North segment: ',npckgn(ib2)
+                     CALL ctl_stop( ctmp1, ctmp2, ctmp3 )
                   ELSE
-                     WRITE(ctmp1,*) ' E R R O R : Check North and East Open boundary indices'
-                     WRITE(ctmp2,*) ' ==========  Crossing problem with East segment: ',npckge(ib1), &
-                     &                                           ' and North segment: ',npckgn(ib2)
-                     CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+                     WRITE(ctmp1,*) ' Check North and East Open boundary indices'
+                     WRITE(ctmp2,*) ' Crossing problem with East segment: ',npckge(ib1), &
+                     &                               ' and North segment: ',npckgn(ib2)
+                     CALL ctl_stop( ctmp1, ctmp2 )
                   END IF
                END IF
@@ -1468,7 +1370,6 @@
          IF (ztestmask(1)==1) THEN 
             IF (icornw(ib,1)==0) THEN
-               WRITE(ctmp1,*) ' E R R O R : Open boundary segment ', npckgw(ib)
-               WRITE(ctmp2,*) ' ==========  does not start on land or on a corner'                                                  
-               CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+               WRITE(ctmp1,*) ' Open boundary segment ', npckgw(ib)
+               CALL ctl_stop( ctmp1, ' does not start on land or on a corner' )
             ELSE
                ! This is a corner
@@ -1480,7 +1381,6 @@
          IF (ztestmask(2)==1) THEN
             IF (icornw(ib,2)==0) THEN
-               WRITE(ctmp1,*) ' E R R O R : Open boundary segment ', npckgw(ib)
-               WRITE(ctmp2,*) ' ==========  does not end on land or on a corner'                                                  
-               CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+               WRITE(ctmp1,*) ' Open boundary segment ', npckgw(ib)
+               CALL ctl_stop( ' ', ctmp1, ' does not end on land or on a corner' )
             ELSE
                ! This is a corner
@@ -1508,7 +1408,6 @@
          IF (ztestmask(1)==1) THEN
             IF (icorne(ib,1)==0) THEN
-               WRITE(ctmp1,*) ' E R R O R : Open boundary segment ', npckge(ib)
-               WRITE(ctmp2,*) ' ==========  does not start on land or on a corner'                                                  
-               CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+               WRITE(ctmp1,*) ' Open boundary segment ', npckge(ib)
+               CALL ctl_stop( ctmp1, ' does not start on land or on a corner' )
             ELSE
                ! This is a corner
@@ -1520,7 +1419,6 @@
          IF (ztestmask(2)==1) THEN
             IF (icorne(ib,2)==0) THEN
-               WRITE(ctmp1,*) ' E R R O R : Open boundary segment ', npckge(ib)
-               WRITE(ctmp2,*) ' ==========  does not end on land or on a corner'                                                  
-               CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+               WRITE(ctmp1,*) ' Open boundary segment ', npckge(ib)
+               CALL ctl_stop( ctmp1, ' does not end on land or on a corner' )
             ELSE
                ! This is a corner
@@ -1547,12 +1445,10 @@
 
          IF ((ztestmask(1)==1).AND.(icorns(ib,1)==0)) THEN
-            WRITE(ctmp1,*) ' E R R O R : Open boundary segment ', npckgs(ib)
-            WRITE(ctmp2,*) ' ==========  does not start on land or on a corner'                                                  
-            CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+            WRITE(ctmp1,*) ' Open boundary segment ', npckgs(ib)
+            CALL ctl_stop( ctmp1, ' does not start on land or on a corner' )
          ENDIF
          IF ((ztestmask(2)==1).AND.(icorns(ib,2)==0)) THEN
-            WRITE(ctmp1,*) ' E R R O R : Open boundary segment ', npckgs(ib)
-            WRITE(ctmp2,*) ' ==========  does not end on land or on a corner'                                                  
-            CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+            WRITE(ctmp1,*) ' Open boundary segment ', npckgs(ib)
+            CALL ctl_stop( ctmp1, ' does not end on land or on a corner' )
          ENDIF
       END DO
@@ -1573,12 +1469,10 @@
 
          IF ((ztestmask(1)==1).AND.(icornn(ib,1)==0)) THEN
-            WRITE(ctmp1,*) ' E R R O R : Open boundary segment ', npckgn(ib)
-            WRITE(ctmp2,*) ' ==========  does not start on land'                                                  
-            CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+            WRITE(ctmp1,*) ' Open boundary segment ', npckgn(ib)
+            CALL ctl_stop( ctmp1, ' does not start on land' )
          ENDIF
          IF ((ztestmask(2)==1).AND.(icornn(ib,2)==0)) THEN
-            WRITE(ctmp1,*) ' E R R O R : Open boundary segment ', npckgn(ib)
-            WRITE(ctmp2,*) ' ==========  does not end on land'                                                  
-            CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+            WRITE(ctmp1,*) ' Open boundary segment ', npckgn(ib)
+            CALL ctl_stop( ctmp1, ' does not end on land' )
          ENDIF
       END DO
@@ -1593,5 +1487,206 @@
    END SUBROUTINE bdy_ctl_seg
 
-
+   
+   SUBROUTINE bdy_coords_seg( nbidta, nbjdta, nbrdta ) 
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE bdy_coords_seg  ***
+      !!
+      !! ** Purpose :  build nbidta, nbidta, nbrdta for bdy built with segments
+      !!
+      !! ** Method  :  
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, DIMENSION(:,:,:), intent(  out)  ::   nbidta, nbjdta, nbrdta   ! Index arrays: i and j indices of bdy dta
+      !!
+      INTEGER  ::   ii, ij, ir, iseg
+      INTEGER  ::   igrd         ! grid type (t=1, u=2, v=3)
+      INTEGER  ::   icount       ! 
+      INTEGER  ::   ib_bdy       ! bdy number
+      !!----------------------------------------------------------------------
+
+      ! East
+      !-----
+      DO iseg = 1, nbdysege
+         ib_bdy = npckge(iseg)
+         !
+         ! ------------ T points -------------
+         igrd=1
+         icount=0
+         DO ir = 1, nn_rimwidth(ib_bdy)
+            DO ij = jpjedt(iseg), jpjeft(iseg)
+               icount = icount + 1
+               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 2 - ir
+               nbjdta(icount, igrd, ib_bdy) = ij
+               nbrdta(icount, igrd, ib_bdy) = ir
+            ENDDO
+         ENDDO
+         !
+         ! ------------ U points -------------
+         igrd=2
+         icount=0
+         DO ir = 1, nn_rimwidth(ib_bdy)
+            DO ij = jpjedt(iseg), jpjeft(iseg)
+               icount = icount + 1
+               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 1 - ir
+               nbjdta(icount, igrd, ib_bdy) = ij
+               nbrdta(icount, igrd, ib_bdy) = ir
+            ENDDO
+         ENDDO
+         !
+         ! ------------ V points -------------
+         igrd=3
+         icount=0
+         DO ir = 1, nn_rimwidth(ib_bdy)
+            !            DO ij = jpjedt(iseg), jpjeft(iseg) - 1
+            DO ij = jpjedt(iseg), jpjeft(iseg)
+               icount = icount + 1
+               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 2 - ir
+               nbjdta(icount, igrd, ib_bdy) = ij
+               nbrdta(icount, igrd, ib_bdy) = ir
+            ENDDO
+            nbidta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
+            nbjdta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
+         ENDDO
+      ENDDO
+      !
+      ! West
+      !-----
+      DO iseg = 1, nbdysegw
+         ib_bdy = npckgw(iseg)
+         !
+         ! ------------ T points -------------
+         igrd=1
+         icount=0
+         DO ir = 1, nn_rimwidth(ib_bdy)
+            DO ij = jpjwdt(iseg), jpjwft(iseg)
+               icount = icount + 1
+               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1
+               nbjdta(icount, igrd, ib_bdy) = ij
+               nbrdta(icount, igrd, ib_bdy) = ir
+            ENDDO
+         ENDDO
+         !
+         ! ------------ U points -------------
+         igrd=2
+         icount=0
+         DO ir = 1, nn_rimwidth(ib_bdy)
+            DO ij = jpjwdt(iseg), jpjwft(iseg)
+               icount = icount + 1
+               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1
+               nbjdta(icount, igrd, ib_bdy) = ij
+               nbrdta(icount, igrd, ib_bdy) = ir
+            ENDDO
+         ENDDO
+         !
+         ! ------------ V points -------------
+         igrd=3
+         icount=0
+         DO ir = 1, nn_rimwidth(ib_bdy)
+            !            DO ij = jpjwdt(iseg), jpjwft(iseg) - 1
+            DO ij = jpjwdt(iseg), jpjwft(iseg)
+               icount = icount + 1
+               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1
+               nbjdta(icount, igrd, ib_bdy) = ij
+               nbrdta(icount, igrd, ib_bdy) = ir
+            ENDDO
+            nbidta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
+            nbjdta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
+         ENDDO
+      ENDDO
+      !
+      ! North
+      !-----
+      DO iseg = 1, nbdysegn
+         ib_bdy = npckgn(iseg)
+         !
+         ! ------------ T points -------------
+         igrd=1
+         icount=0
+         DO ir = 1, nn_rimwidth(ib_bdy)
+            DO ii = jpindt(iseg), jpinft(iseg)
+               icount = icount + 1
+               nbidta(icount, igrd, ib_bdy) = ii
+               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 2 - ir 
+               nbrdta(icount, igrd, ib_bdy) = ir
+            ENDDO
+         ENDDO
+         !
+         ! ------------ U points -------------
+         igrd=2
+         icount=0
+         DO ir = 1, nn_rimwidth(ib_bdy)
+            !            DO ii = jpindt(iseg), jpinft(iseg) - 1
+            DO ii = jpindt(iseg), jpinft(iseg)
+               icount = icount + 1
+               nbidta(icount, igrd, ib_bdy) = ii
+               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 2 - ir
+               nbrdta(icount, igrd, ib_bdy) = ir
+            ENDDO
+            nbidta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
+            nbjdta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
+         ENDDO
+         !
+         ! ------------ V points -------------
+         igrd=3
+         icount=0
+         DO ir = 1, nn_rimwidth(ib_bdy)
+            DO ii = jpindt(iseg), jpinft(iseg)
+               icount = icount + 1
+               nbidta(icount, igrd, ib_bdy) = ii
+               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 1 - ir
+               nbrdta(icount, igrd, ib_bdy) = ir
+            ENDDO
+         ENDDO
+      ENDDO
+      !
+      ! South
+      !-----
+      DO iseg = 1, nbdysegs
+         ib_bdy = npckgs(iseg)
+         !
+         ! ------------ T points -------------
+         igrd=1
+         icount=0
+         DO ir = 1, nn_rimwidth(ib_bdy)
+            DO ii = jpisdt(iseg), jpisft(iseg)
+               icount = icount + 1
+               nbidta(icount, igrd, ib_bdy) = ii
+               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1
+               nbrdta(icount, igrd, ib_bdy) = ir
+            ENDDO
+         ENDDO
+         !
+         ! ------------ U points -------------
+         igrd=2
+         icount=0
+         DO ir = 1, nn_rimwidth(ib_bdy)
+            !            DO ii = jpisdt(iseg), jpisft(iseg) - 1
+            DO ii = jpisdt(iseg), jpisft(iseg)
+               icount = icount + 1
+               nbidta(icount, igrd, ib_bdy) = ii
+               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1
+               nbrdta(icount, igrd, ib_bdy) = ir
+            ENDDO
+            nbidta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
+            nbjdta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
+         ENDDO
+         !
+         ! ------------ V points -------------
+         igrd=3
+         icount=0
+         DO ir = 1, nn_rimwidth(ib_bdy)
+            DO ii = jpisdt(iseg), jpisft(iseg)
+               icount = icount + 1
+               nbidta(icount, igrd, ib_bdy) = ii
+               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1
+               nbrdta(icount, igrd, ib_bdy) = ir
+            ENDDO
+         ENDDO
+      ENDDO
+
+      
+   END SUBROUTINE bdy_coords_seg
+   
+   
    SUBROUTINE bdy_ctl_corn( ib1, ib2 )
       !!----------------------------------------------------------------------
@@ -1619,11 +1714,79 @@
       !
       IF( itest>0 ) THEN
-         WRITE(ctmp1,*) ' E R R O R : Segments ', ib1, 'and ', ib2
-         WRITE(ctmp2,*) ' ==========  have different open bdy schemes'                                                  
-         CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+         WRITE(ctmp1,*) ' Segments ', ib1, 'and ', ib2
+         CALL ctl_stop( ctmp1, ' have different open bdy schemes' )
       ENDIF
       !
    END SUBROUTINE bdy_ctl_corn
 
+
+   SUBROUTINE bdy_meshwri()
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE bdy_meshwri  ***
+      !!         
+      !! ** Purpose :   write netcdf file with nbr, flagu, flagv, ntreat for T, U 
+      !!                and V points in 2D arrays for easier visualisation/control
+      !!
+      !! ** Method  :   use iom_rstput as in domwri.F
+      !!----------------------------------------------------------------------      
+      INTEGER  ::   ib_bdy, ii, ij, igrd, ib     ! dummy loop indices
+      INTEGER  ::   inum                                   !   -       -
+      REAL(wp), POINTER, DIMENSION(:,:)     ::   zmask                   ! pointer to 2D mask fields
+      REAL(wp)         , DIMENSION(jpi,jpj) ::   ztmp
+      CHARACTER(LEN=1) , DIMENSION(jpbgrd)  ::   cgrid
+      !!----------------------------------------------------------------------      
+      cgrid = (/'t','u','v'/)
+      CALL iom_open( 'bdy_mesh', inum, ldwrt = .TRUE. )
+      DO igrd = 1, jpbgrd
+         SELECT CASE( igrd )
+         CASE( 1 )   ;   zmask => tmask(:,:,1)
+         CASE( 2 )   ;   zmask => umask(:,:,1)
+         CASE( 3 )   ;   zmask => vmask(:,:,1)
+         END SELECT
+         ztmp(:,:) = zmask(:,:)
+         DO ib_bdy = 1, nb_bdy
+            DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)      ! nbr deined for all rims
+               ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+               ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+               ztmp(ii,ij) = REAL(idx_bdy(ib_bdy)%nbr(ib,igrd), wp) + 10.
+               IF( zmask(ii,ij) == 0. ) ztmp(ii,ij) = - ztmp(ii,ij)
+            END DO
+         END DO
+         CALL iom_rstput( 0, 0, inum, 'bdy_nbr_'//cgrid(igrd), ztmp(:,:), ktype = jp_i4 )
+         ztmp(:,:) = zmask(:,:)
+         DO ib_bdy = 1, nb_bdy
+            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)   ! flagu defined only for rims 0 and 1
+               ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+               ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+               ztmp(ii,ij) = REAL(idx_bdy(ib_bdy)%flagu(ib,igrd), wp) + 10.
+               IF( zmask(ii,ij) == 0. ) ztmp(ii,ij) = - ztmp(ii,ij)
+            END DO
+         END DO
+         CALL iom_rstput( 0, 0, inum, 'flagu_'//cgrid(igrd), ztmp(:,:), ktype = jp_i4 )
+         ztmp(:,:) = zmask(:,:)
+         DO ib_bdy = 1, nb_bdy
+            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)   ! flagv defined only for rims 0 and 1
+               ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+               ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+               ztmp(ii,ij) = REAL(idx_bdy(ib_bdy)%flagv(ib,igrd), wp) + 10.
+               IF( zmask(ii,ij) == 0. ) ztmp(ii,ij) = - ztmp(ii,ij)
+            END DO
+         END DO
+         CALL iom_rstput( 0, 0, inum, 'flagv_'//cgrid(igrd), ztmp(:,:), ktype = jp_i4 )
+         ztmp(:,:) = zmask(:,:)
+         DO ib_bdy = 1, nb_bdy
+            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)   ! ntreat defined only for rims 0 and 1
+               ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+               ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+               ztmp(ii,ij) = REAL(idx_bdy(ib_bdy)%ntreat(ib,igrd), wp) + 10.
+               IF( zmask(ii,ij) == 0. ) ztmp(ii,ij) = - ztmp(ii,ij)
+            END DO
+         END DO
+         CALL iom_rstput( 0, 0, inum, 'ntreat_'//cgrid(igrd), ztmp(:,:), ktype = jp_i4 )
+      END DO
+      CALL iom_close( inum )
+
+   END SUBROUTINE bdy_meshwri
+   
    !!=================================================================================
 END MODULE bdyini
Index: /NEMO/trunk/src/OCE/BDY/bdylib.F90
===================================================================
--- /NEMO/trunk/src/OCE/BDY/bdylib.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/BDY/bdylib.F90	(revision 11536)
@@ -15,4 +15,5 @@
    USE bdy_oce        ! ocean open boundary conditions
    USE phycst         ! physical constants
+   USE bdyini
    !
    USE in_out_manager !
@@ -75,5 +76,4 @@
       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
@@ -92,5 +92,5 @@
 
 
-   SUBROUTINE bdy_orl( idx, ptb, pta, dta, ll_npo )
+   SUBROUTINE bdy_orl( idx, ptb, pta, dta, lrim0, ll_npo )
       !!----------------------------------------------------------------------
       !!                 ***  SUBROUTINE bdy_orl  ***
@@ -104,4 +104,5 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptb  ! before tracer field
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pta  ! tracer trend
+      LOGICAL                 , OPTIONAL,  INTENT(in) ::   lrim0   ! indicate if rim 0 is treated
       LOGICAL,                             INTENT(in) ::   ll_npo  ! switch for NPO version
       !!
@@ -111,10 +112,10 @@
       igrd = 1                       ! Everything is at T-points here
       !
-      CALL bdy_orlanski_3d( idx, igrd, ptb(:,:,:), pta(:,:,:), dta, ll_npo )
+      CALL bdy_orlanski_3d( idx, igrd, ptb(:,:,:), pta(:,:,:), dta, lrim0, ll_npo )
       !
    END SUBROUTINE bdy_orl
 
 
-   SUBROUTINE bdy_orlanski_2d( idx, igrd, phib, phia, phi_ext, ll_npo )
+   SUBROUTINE bdy_orlanski_2d( idx, igrd, phib, phia, phi_ext, lrim0, ll_npo )
       !!----------------------------------------------------------------------
       !!                 ***  SUBROUTINE bdy_orlanski_2d  ***
@@ -132,4 +133,5 @@
       REAL(wp), DIMENSION(:,:), INTENT(inout) ::   phia     ! model after 2D field (to be updated)
       REAL(wp), DIMENSION(:)  , INTENT(in   ) ::   phi_ext  ! external forcing data
+      LOGICAL, OPTIONAL,        INTENT(in   ) ::   lrim0    ! indicate if rim 0 is treated
       LOGICAL ,                 INTENT(in   ) ::   ll_npo   ! switch for NPO version
       !
@@ -140,4 +142,5 @@
       INTEGER  ::   ii_offset, ij_offset                   ! offsets for mask indices
       INTEGER  ::   flagu, flagv                           ! short cuts
+      INTEGER  ::   ibeg, iend                             ! length of rim to be treated (rim 0 or rim 1 or both)
       REAL(wp) ::   zmask_x, zmask_y1, zmask_y2
       REAL(wp) ::   zex1, zex2, zey, zey1, zey2
@@ -146,7 +149,7 @@
       REAL(wp) ::   zdy_1, zdy_2, zsign_ups
       REAL(wp), PARAMETER :: zepsilon = 1.e-30                 ! local small value
-      REAL(wp), POINTER, DIMENSION(:,:)          :: pmask      ! land/sea mask for field
-      REAL(wp), POINTER, DIMENSION(:,:)          :: pmask_xdif ! land/sea mask for x-derivatives
-      REAL(wp), POINTER, DIMENSION(:,:)          :: pmask_ydif ! land/sea mask for y-derivatives
+      REAL(wp), POINTER, DIMENSION(:,:)          :: zmask      ! land/sea mask for field
+      REAL(wp), POINTER, DIMENSION(:,:)          :: zmask_xdif ! land/sea mask for x-derivatives
+      REAL(wp), POINTER, DIMENSION(:,:)          :: zmask_ydif ! land/sea mask for y-derivatives
       REAL(wp), POINTER, DIMENSION(:,:)          :: pe_xdif    ! scale factors for x-derivatives
       REAL(wp), POINTER, DIMENSION(:,:)          :: pe_ydif    ! scale factors for y-derivatives
@@ -159,7 +162,7 @@
       SELECT CASE(igrd)
          CASE(1)
-            pmask      => tmask(:,:,1)
-            pmask_xdif => umask(:,:,1)
-            pmask_ydif => vmask(:,:,1)
+            zmask      => tmask(:,:,1)
+            zmask_xdif => umask(:,:,1)
+            zmask_ydif => vmask(:,:,1)
             pe_xdif    => e1u(:,:)
             pe_ydif    => e2v(:,:)
@@ -167,7 +170,7 @@
             ij_offset = 0
          CASE(2)
-            pmask      => umask(:,:,1)
-            pmask_xdif => tmask(:,:,1)
-            pmask_ydif => fmask(:,:,1)
+            zmask      => umask(:,:,1)
+            zmask_xdif => tmask(:,:,1)
+            zmask_ydif => fmask(:,:,1)
             pe_xdif    => e1t(:,:)
             pe_ydif    => e2f(:,:)
@@ -175,7 +178,7 @@
             ij_offset = 0
          CASE(3)
-            pmask      => vmask(:,:,1)
-            pmask_xdif => fmask(:,:,1)
-            pmask_ydif => tmask(:,:,1)
+            zmask      => vmask(:,:,1)
+            zmask_xdif => fmask(:,:,1)
+            zmask_ydif => tmask(:,:,1)
             pe_xdif    => e1f(:,:)
             pe_ydif    => e2t(:,:)
@@ -185,7 +188,15 @@
       END SELECT
       !
-      DO jb = 1, idx%nblenrim(igrd)
+      IF( PRESENT(lrim0) ) THEN
+         IF( lrim0 ) THEN   ;   ibeg = 1                       ;   iend = idx%nblenrim0(igrd)   ! rim 0
+         ELSE               ;   ibeg = idx%nblenrim0(igrd)+1   ;   iend = idx%nblenrim(igrd)    ! rim 1
+         END IF
+      ELSE                  ;   ibeg = 1                       ;   iend = idx%nblenrim(igrd)    ! both
+      END IF
+      !
+      DO jb = ibeg, iend
          ii  = idx%nbi(jb,igrd)
          ij  = idx%nbj(jb,igrd) 
+         IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )   CYCLE
          flagu = int( idx%flagu(jb,igrd) )
          flagv = int( idx%flagv(jb,igrd) )
@@ -203,12 +214,12 @@
          !
          ! Calculate scale factors for calculation of spatial derivatives.        
-         zex1 = ( abs(iibm1-iibm2) * pe_xdif(iibm1+ii_offset,ijbm1          )         &
-        &       + abs(ijbm1-ijbm2) * pe_ydif(iibm1          ,ijbm1+ij_offset) ) 
-         zex2 = ( abs(iibm1-iibm2) * pe_xdif(iibm2+ii_offset,ijbm2          )         &
-        &       + abs(ijbm1-ijbm2) * pe_ydif(iibm2          ,ijbm2+ij_offset) ) 
-         zey1 = ( (iibm1-iibm1jm1) * pe_xdif(iibm1jm1+ii_offset,ijbm1jm1          )  & 
+         zex1 = ( abs(iibm1-iibm2) * pe_xdif(iibm1   +ii_offset,ijbm1             )   &
+        &       + abs(ijbm1-ijbm2) * pe_ydif(iibm1             ,ijbm1   +ij_offset) ) 
+         zex2 = ( abs(iibm1-iibm2) * pe_xdif(iibm2   +ii_offset,ijbm2             )   &
+        &       + abs(ijbm1-ijbm2) * pe_ydif(iibm2             ,ijbm2   +ij_offset) ) 
+         zey1 = ( (iibm1-iibm1jm1) * pe_xdif(iibm1jm1+ii_offset,ijbm1jm1          )   & 
         &      +  (ijbm1-ijbm1jm1) * pe_ydif(iibm1jm1          ,ijbm1jm1+ij_offset) ) 
-         zey2 = ( (iibm1jp1-iibm1) * pe_xdif(iibm1+ii_offset,ijbm1)                  &
-        &      +  (ijbm1jp1-ijbm1) * pe_ydif(iibm1          ,ijbm1+ij_offset) ) 
+         zey2 = ( (iibm1jp1-iibm1) * pe_xdif(iibm1   +ii_offset,ijbm1             )   &
+        &      +  (ijbm1jp1-ijbm1) * pe_ydif(iibm1             ,ijbm1   +ij_offset) ) 
          ! make sure scale factors are nonzero
          if( zey1 .lt. rsmall ) zey1 = zey2
@@ -217,11 +228,11 @@
          zey1 = max(zey1,rsmall); zey2 = max(zey2,rsmall); 
          !
-         ! Calculate masks for calculation of spatial derivatives.        
-         zmask_x = ( abs(iibm1-iibm2) * pmask_xdif(iibm2+ii_offset,ijbm2          )         &
-        &          + abs(ijbm1-ijbm2) * pmask_ydif(iibm2          ,ijbm2+ij_offset) ) 
-         zmask_y1 = ( (iibm1-iibm1jm1) * pmask_xdif(iibm1jm1+ii_offset,ijbm1jm1          )  & 
-        &          +  (ijbm1-ijbm1jm1) * pmask_ydif(iibm1jm1          ,ijbm1jm1+ij_offset) ) 
-         zmask_y2 = ( (iibm1jp1-iibm1) * pmask_xdif(iibm1+ii_offset,ijbm1)                  &
-        &          +  (ijbm1jp1-ijbm1) * pmask_ydif(iibm1          ,ijbm1+ij_offset) ) 
+         ! Calculate masks for calculation of spatial derivatives.
+         zmask_x  = ( abs(iibm1-iibm2) * zmask_xdif(iibm2   +ii_offset,ijbm2               )   &
+        &           + abs(ijbm1-ijbm2) * zmask_ydif(iibm2             ,ijbm2   +ij_offset) ) 
+         zmask_y1 = ( (iibm1-iibm1jm1) * zmask_xdif(iibm1jm1+ii_offset,ijbm1jm1            )   & 
+        &          +  (ijbm1-ijbm1jm1) * zmask_ydif(iibm1jm1          ,ijbm1jm1+ij_offset) ) 
+         zmask_y2 = ( (iibm1jp1-iibm1) * zmask_xdif(iibm1   +ii_offset,ijbm1               )   &
+        &          +  (ijbm1jp1-ijbm1) * zmask_ydif(iibm1             ,ijbm1   +ij_offset) ) 
 
          ! Calculation of terms required for both versions of the scheme. 
@@ -231,8 +242,8 @@
          ! Note no rdt factor in expression for zdt because it cancels in the expressions for 
          ! zrx and zry.
-         zdt = phia(iibm1,ijbm1) - phib(iibm1,ijbm1)
-         zdx = ( ( phia(iibm1,ijbm1) - phia(iibm2,ijbm2) ) / zex2 ) * zmask_x 
+         zdt   =     phia(iibm1   ,ijbm1   ) - phib(iibm1   ,ijbm1   )
+         zdx   = ( ( phia(iibm1   ,ijbm1   ) - phia(iibm2   ,ijbm2   ) ) / zex2 ) * zmask_x 
          zdy_1 = ( ( phib(iibm1   ,ijbm1   ) - phib(iibm1jm1,ijbm1jm1) ) / zey1 ) * zmask_y1    
-         zdy_2 = ( ( phib(iibm1jp1,ijbm1jp1) - phib(iibm1   ,ijbm1)    ) / zey2 ) * zmask_y2 
+         zdy_2 = ( ( phib(iibm1jp1,ijbm1jp1) - phib(iibm1   ,ijbm1   ) ) / zey2 ) * zmask_y2 
          zdy_centred = 0.5 * ( zdy_1 + zdy_2 )
 !!$         zdy_centred = phib(iibm1jp1,ijbm1jp1) - phib(iibm1jm1,ijbm1jm1)
@@ -265,5 +276,5 @@
            &                    + zwgt * ( phi_ext(jb) - phib(ii,ij) ) ) / ( 1. + zrx ) 
          end if
-         phia(ii,ij) = phia(ii,ij) * pmask(ii,ij)
+         phia(ii,ij) = phia(ii,ij) * zmask(ii,ij)
       END DO
       !
@@ -271,5 +282,5 @@
 
 
-   SUBROUTINE bdy_orlanski_3d( idx, igrd, phib, phia, phi_ext, ll_npo )
+   SUBROUTINE bdy_orlanski_3d( idx, igrd, phib, phia, phi_ext, lrim0, ll_npo )
       !!----------------------------------------------------------------------
       !!                 ***  SUBROUTINE bdy_orlanski_3d  ***
@@ -287,4 +298,5 @@
       REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   phia     ! model after 3D field (to be updated)
       REAL(wp), DIMENSION(:,:)  , INTENT(in   ) ::   phi_ext  ! external forcing data
+      LOGICAL, OPTIONAL,          INTENT(in   ) ::   lrim0    ! indicate if rim 0 is treated
       LOGICAL ,                   INTENT(in   ) ::   ll_npo   ! switch for NPO version
       !
@@ -295,4 +307,5 @@
       INTEGER  ::   ii_offset, ij_offset                   ! offsets for mask indices
       INTEGER  ::   flagu, flagv                           ! short cuts
+      INTEGER  ::   ibeg, iend                             ! length of rim to be treated (rim 0 or rim 1 or both)
       REAL(wp) ::   zmask_x, zmask_y1, zmask_y2
       REAL(wp) ::   zex1, zex2, zey, zey1, zey2
@@ -301,7 +314,7 @@
       REAL(wp) ::   zdy_1, zdy_2,  zsign_ups
       REAL(wp), PARAMETER :: zepsilon = 1.e-30                 ! local small value
-      REAL(wp), POINTER, DIMENSION(:,:,:)        :: pmask      ! land/sea mask for field
-      REAL(wp), POINTER, DIMENSION(:,:,:)        :: pmask_xdif ! land/sea mask for x-derivatives
-      REAL(wp), POINTER, DIMENSION(:,:,:)        :: pmask_ydif ! land/sea mask for y-derivatives
+      REAL(wp), POINTER, DIMENSION(:,:,:)        :: zmask      ! land/sea mask for field
+      REAL(wp), POINTER, DIMENSION(:,:,:)        :: zmask_xdif ! land/sea mask for x-derivatives
+      REAL(wp), POINTER, DIMENSION(:,:,:)        :: zmask_ydif ! land/sea mask for y-derivatives
       REAL(wp), POINTER, DIMENSION(:,:)          :: pe_xdif    ! scale factors for x-derivatives
       REAL(wp), POINTER, DIMENSION(:,:)          :: pe_ydif    ! scale factors for y-derivatives
@@ -314,7 +327,7 @@
       SELECT CASE(igrd)
          CASE(1)
-            pmask      => tmask(:,:,:)
-            pmask_xdif => umask(:,:,:)
-            pmask_ydif => vmask(:,:,:)
+            zmask      => tmask(:,:,:)
+            zmask_xdif => umask(:,:,:)
+            zmask_ydif => vmask(:,:,:)
             pe_xdif    => e1u(:,:)
             pe_ydif    => e2v(:,:)
@@ -322,7 +335,7 @@
             ij_offset = 0
          CASE(2)
-            pmask      => umask(:,:,:)
-            pmask_xdif => tmask(:,:,:)
-            pmask_ydif => fmask(:,:,:)
+            zmask      => umask(:,:,:)
+            zmask_xdif => tmask(:,:,:)
+            zmask_ydif => fmask(:,:,:)
             pe_xdif    => e1t(:,:)
             pe_ydif    => e2f(:,:)
@@ -330,7 +343,7 @@
             ij_offset = 0
          CASE(3)
-            pmask      => vmask(:,:,:)
-            pmask_xdif => fmask(:,:,:)
-            pmask_ydif => tmask(:,:,:)
+            zmask      => vmask(:,:,:)
+            zmask_xdif => fmask(:,:,:)
+            zmask_ydif => tmask(:,:,:)
             pe_xdif    => e1f(:,:)
             pe_ydif    => e2t(:,:)
@@ -339,10 +352,18 @@
          CASE DEFAULT ;   CALL ctl_stop( 'unrecognised value for igrd in bdy_orlanksi_2d' )
       END SELECT
-
+      !
+      IF( PRESENT(lrim0) ) THEN
+         IF( lrim0 ) THEN   ;   ibeg = 1                       ;   iend = idx%nblenrim0(igrd)   ! rim 0
+         ELSE               ;   ibeg = idx%nblenrim0(igrd)+1   ;   iend = idx%nblenrim(igrd)    ! rim 1
+         END IF
+      ELSE                  ;   ibeg = 1                       ;   iend = idx%nblenrim(igrd)    ! both
+      END IF
+      !
       DO jk = 1, jpk
          !            
-         DO jb = 1, idx%nblenrim(igrd)
+         DO jb = ibeg, iend
             ii  = idx%nbi(jb,igrd)
             ij  = idx%nbj(jb,igrd) 
+            IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )   CYCLE
             flagu = int( idx%flagu(jb,igrd) )
             flagv = int( idx%flagv(jb,igrd) )
@@ -360,12 +381,12 @@
             !
             ! Calculate scale factors for calculation of spatial derivatives.        
-            zex1 = ( abs(iibm1-iibm2) * pe_xdif(iibm1+ii_offset,ijbm1          )         &
-           &       + abs(ijbm1-ijbm2) * pe_ydif(iibm1          ,ijbm1+ij_offset) ) 
-            zex2 = ( abs(iibm1-iibm2) * pe_xdif(iibm2+ii_offset,ijbm2          )         &
-           &       + abs(ijbm1-ijbm2) * pe_ydif(iibm2          ,ijbm2+ij_offset) ) 
-            zey1 = ( (iibm1-iibm1jm1) * pe_xdif(iibm1jm1+ii_offset,ijbm1jm1          )  & 
+            zex1 = ( abs(iibm1-iibm2) * pe_xdif(iibm1   +ii_offset,ijbm1             )   &
+           &       + abs(ijbm1-ijbm2) * pe_ydif(iibm1             ,ijbm1+ij_offset   ) ) 
+            zex2 = ( abs(iibm1-iibm2) * pe_xdif(iibm2   +ii_offset,ijbm2             )   &
+           &       + abs(ijbm1-ijbm2) * pe_ydif(iibm2             ,ijbm2+ij_offset   ) ) 
+            zey1 = ( (iibm1-iibm1jm1) * pe_xdif(iibm1jm1+ii_offset,ijbm1jm1          )   & 
            &      +  (ijbm1-ijbm1jm1) * pe_ydif(iibm1jm1          ,ijbm1jm1+ij_offset) ) 
-            zey2 = ( (iibm1jp1-iibm1) * pe_xdif(iibm1+ii_offset,ijbm1)                  &
-           &      +  (ijbm1jp1-ijbm1) * pe_ydif(iibm1          ,ijbm1+ij_offset) ) 
+            zey2 = ( (iibm1jp1-iibm1) * pe_xdif(iibm1   +ii_offset,ijbm1             )   &
+           &      +  (ijbm1jp1-ijbm1) * pe_ydif(iibm1             ,ijbm1+ij_offset   ) ) 
             ! make sure scale factors are nonzero
             if( zey1 .lt. rsmall ) zey1 = zey2
@@ -375,10 +396,10 @@
             !
             ! Calculate masks for calculation of spatial derivatives.        
-            zmask_x = ( abs(iibm1-iibm2) * pmask_xdif(iibm2+ii_offset,ijbm2          ,jk)          &
-           &          + abs(ijbm1-ijbm2) * pmask_ydif(iibm2          ,ijbm2+ij_offset,jk) ) 
-            zmask_y1 = ( (iibm1-iibm1jm1) * pmask_xdif(iibm1jm1+ii_offset,ijbm1jm1          ,jk)   & 
-           &          +  (ijbm1-ijbm1jm1) * pmask_ydif(iibm1jm1          ,ijbm1jm1+ij_offset,jk) ) 
-            zmask_y2 = ( (iibm1jp1-iibm1) * pmask_xdif(iibm1+ii_offset,ijbm1          ,jk)         &
-           &          +  (ijbm1jp1-ijbm1) * pmask_ydif(iibm1          ,ijbm1+ij_offset,jk) ) 
+            zmask_x  = ( abs(iibm1-iibm2) * zmask_xdif(iibm2   +ii_offset,ijbm2             ,jk)   &
+           &           + abs(ijbm1-ijbm2) * zmask_ydif(iibm2             ,ijbm2   +ij_offset,jk) ) 
+            zmask_y1 = ( (iibm1-iibm1jm1) * zmask_xdif(iibm1jm1+ii_offset,ijbm1jm1          ,jk)   & 
+           &          +  (ijbm1-ijbm1jm1) * zmask_ydif(iibm1jm1          ,ijbm1jm1+ij_offset,jk) ) 
+            zmask_y2 = ( (iibm1jp1-iibm1) * zmask_xdif(iibm1   +ii_offset,ijbm1             ,jk)   &
+           &          +  (ijbm1jp1-ijbm1) * zmask_ydif(iibm1             ,ijbm1   +ij_offset,jk) ) 
             !
             ! Calculate normal (zrx) and tangential (zry) components of radiation velocities.
@@ -386,6 +407,6 @@
             ! Centred derivative is calculated as average of "left" and "right" derivatives for 
             ! this reason. 
-            zdt = phia(iibm1,ijbm1,jk) - phib(iibm1,ijbm1,jk)
-            zdx = ( ( phia(iibm1,ijbm1,jk) - phia(iibm2,ijbm2,jk) ) / zex2 ) * zmask_x                  
+            zdt   =     phia(iibm1   ,ijbm1   ,jk) - phib(iibm1   ,ijbm1   ,jk)
+            zdx   = ( ( phia(iibm1   ,ijbm1   ,jk) - phia(iibm2   ,ijbm2   ,jk) ) / zex2 ) * zmask_x                  
             zdy_1 = ( ( phib(iibm1   ,ijbm1   ,jk) - phib(iibm1jm1,ijbm1jm1,jk) ) / zey1 ) * zmask_y1  
             zdy_2 = ( ( phib(iibm1jp1,ijbm1jp1,jk) - phib(iibm1   ,ijbm1   ,jk) ) / zey2 ) * zmask_y2      
@@ -421,5 +442,5 @@
               &                       + zwgt * ( phi_ext(jb,jk) - phib(ii,ij,jk) ) ) / ( 1. + zrx ) 
             end if
-            phia(ii,ij,jk) = phia(ii,ij,jk) * pmask(ii,ij,jk)
+            phia(ii,ij,jk) = phia(ii,ij,jk) * zmask(ii,ij,jk)
          END DO
          !
@@ -428,5 +449,5 @@
    END SUBROUTINE bdy_orlanski_3d
 
-   SUBROUTINE bdy_nmn( idx, igrd, phia )
+   SUBROUTINE bdy_nmn( idx, igrd, phia, lrim0 )
       !!----------------------------------------------------------------------
       !!                 ***  SUBROUTINE bdy_nmn  ***
@@ -434,63 +455,69 @@
       !! ** Purpose : Duplicate the value at open boundaries, zero gradient.
       !! 
-      !!----------------------------------------------------------------------
-      INTEGER,                    INTENT(in)     ::   igrd     ! grid index
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout)  ::   phia     ! model after 3D field (to be updated)
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
+      !!
+      !! ** Method  : - take the average of free ocean neighbours
+      !!
+      !!      ___   !   |_____|   !   ___|    !   __|x o   !   |_   _|     ! |      
+      !!   __|x     !      x      !     x o   !      o     !     |_|       ! |x o   
+      !!      o     !      o      !     o     !            !    o x o      ! |x_x_ 
+      !!                                                   !      o      
+      !!----------------------------------------------------------------------
+      INTEGER,                    INTENT(in   )  ::   igrd     ! grid index
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout)  ::   phia     ! model after 3D field (to be updated), must be masked
+      TYPE(OBC_INDEX),            INTENT(in   )  ::   idx      ! OBC indices
+      LOGICAL, OPTIONAL,          INTENT(in   )  ::   lrim0    ! indicate if rim 0 is treated
       !! 
-      REAL(wp) ::   zcoef, zcoef1, zcoef2
-      REAL(wp), POINTER, DIMENSION(:,:,:)        :: pmask      ! land/sea mask for field
-      REAL(wp), POINTER, DIMENSION(:,:)        :: bdypmask      ! land/sea mask for field
+      REAL(wp) ::   zweight
+      REAL(wp), POINTER, DIMENSION(:,:,:)      :: zmask         ! land/sea mask for field
       INTEGER  ::   ib, ik   ! dummy loop indices
-      INTEGER  ::   ii, ij, ip, jp   ! 2D addresses
-      !!----------------------------------------------------------------------
+      INTEGER  ::   ii, ij   ! 2D addresses
+      INTEGER  ::   ipkm1    ! size of phia third dimension minus 1
+      INTEGER  ::   ibeg, iend                          ! length of rim to be treated (rim 0 or rim 1 or both)
+      INTEGER  ::   ii1, ii2, ii3, ij1, ij2, ij3, itreat
+      !!----------------------------------------------------------------------
+      !
+      ipkm1 = MAX( SIZE(phia,3) - 1, 1 ) 
       !
       SELECT CASE(igrd)
-         CASE(1)
-            pmask => tmask(:,:,:)
-            bdypmask => bdytmask(:,:)
-         CASE(2)
-            pmask => umask(:,:,:)
-            bdypmask => bdyumask(:,:)
-         CASE(3)
-            pmask => vmask(:,:,:)
-            bdypmask => bdyvmask(:,:)
+         CASE(1)   ;   zmask => tmask(:,:,:)
+         CASE(2)   ;   zmask => umask(:,:,:)
+         CASE(3)   ;   zmask => vmask(:,:,:)
          CASE DEFAULT ;   CALL ctl_stop( 'unrecognised value for igrd in bdy_nmn' )
       END SELECT
-      DO ib = 1, idx%nblenrim(igrd)
+      !
+      IF( PRESENT(lrim0) ) THEN
+         IF( lrim0 ) THEN   ;   ibeg = 1                       ;   iend = idx%nblenrim0(igrd)   ! rim 0
+         ELSE               ;   ibeg = idx%nblenrim0(igrd)+1   ;   iend = idx%nblenrim(igrd)    ! rim 1
+         END IF
+      ELSE                  ;   ibeg = 1                       ;   iend = idx%nblenrim(igrd)    ! both
+      END IF
+      !
+      DO ib = ibeg, iend
          ii = idx%nbi(ib,igrd)
          ij = idx%nbj(ib,igrd)
-         DO ik = 1, jpkm1
-            ! search the sense of the gradient
-            zcoef1 = bdypmask(ii-1,ij  )*pmask(ii-1,ij,ik) +  bdypmask(ii+1,ij  )*pmask(ii+1,ij,ik)
-            zcoef2 = bdypmask(ii  ,ij-1)*pmask(ii,ij-1,ik) +  bdypmask(ii  ,ij+1)*pmask(ii,ij+1,ik)
-            IF ( nint(zcoef1+zcoef2) == 0) THEN
-               ! corner **** we probably only want to set the tangentail component for the dynamics here
-               zcoef = pmask(ii-1,ij,ik) + pmask(ii+1,ij,ik) +  pmask(ii,ij-1,ik) +  pmask(ii,ij+1,ik)
-               IF (zcoef > .5_wp) THEN ! Only set none isolated points.
-                 phia(ii,ij,ik) = phia(ii-1,ij  ,ik) * pmask(ii-1,ij  ,ik) + &
-                   &              phia(ii+1,ij  ,ik) * pmask(ii+1,ij  ,ik) + &
-                   &              phia(ii  ,ij-1,ik) * pmask(ii  ,ij-1,ik) + &
-                   &              phia(ii  ,ij+1,ik) * pmask(ii  ,ij+1,ik)
-                 phia(ii,ij,ik) = ( phia(ii,ij,ik) / zcoef ) * pmask(ii,ij,ik)
-               ELSE
-                 phia(ii,ij,ik) = phia(ii,ij  ,ik) * pmask(ii,ij  ,ik)
-               ENDIF
-            ELSEIF ( nint(zcoef1+zcoef2) == 2) THEN
-               ! oblique corner **** we probably only want to set the normal component for the dynamics here
-               zcoef = pmask(ii-1,ij,ik)*bdypmask(ii-1,ij  ) + pmask(ii+1,ij,ik)*bdypmask(ii+1,ij  ) + &
-                   &   pmask(ii,ij-1,ik)*bdypmask(ii,ij -1 ) +  pmask(ii,ij+1,ik)*bdypmask(ii,ij+1  )
-               phia(ii,ij,ik) = phia(ii-1,ij  ,ik) * pmask(ii-1,ij  ,ik)*bdypmask(ii-1,ij  ) + &
-                   &            phia(ii+1,ij  ,ik) * pmask(ii+1,ij  ,ik)*bdypmask(ii+1,ij  )  + &
-                   &            phia(ii  ,ij-1,ik) * pmask(ii  ,ij-1,ik)*bdypmask(ii,ij -1 ) + &
-                   &            phia(ii  ,ij+1,ik) * pmask(ii  ,ij+1,ik)*bdypmask(ii,ij+1  )
- 
-               phia(ii,ij,ik) = ( phia(ii,ij,ik) / MAX(1._wp, zcoef) ) * pmask(ii,ij,ik)
-            ELSE
-               ip = nint(bdypmask(ii+1,ij  )*pmask(ii+1,ij,ik) - bdypmask(ii-1,ij  )*pmask(ii-1,ij,ik))
-               jp = nint(bdypmask(ii  ,ij+1)*pmask(ii,ij+1,ik) - bdypmask(ii  ,ij-1)*pmask(ii,ij-1,ik))
-               phia(ii,ij,ik) = phia(ii+ip,ij+jp,ik) * pmask(ii+ip,ij+jp,ik)
-            ENDIF
-         END DO
+         itreat = idx%ntreat(ib,igrd)
+         CALL find_neib( ii, ij, itreat, ii1, ij1, ii2, ij2, ii3, ij3 )   ! find free ocean neighbours
+         SELECT CASE( itreat )
+         CASE( 1:8 )
+            IF( ii1 < 1 .OR. ii1 > jpi .OR. ij1 < 1 .OR. ij1 > jpj )   CYCLE
+            DO ik = 1, ipkm1
+               IF( zmask(ii1,ij1,ik) /= 0. )   phia(ii,ij,ik) = phia(ii1,ij1,ik)  
+            END DO
+         CASE( 9:12 )
+            IF( ii1 < 1 .OR. ii1 > jpi .OR. ij1 < 1 .OR. ij1 > jpj )   CYCLE
+            IF( ii2 < 1 .OR. ii2 > jpi .OR. ij2 < 1 .OR. ij2 > jpj )   CYCLE
+            DO ik = 1, ipkm1
+               zweight = zmask(ii1,ij1,ik) + zmask(ii2,ij2,ik)
+               IF( zweight /= 0. )   phia(ii,ij,ik) = ( phia(ii1,ij1,ik) + phia(ii2,ij2,ik) ) / zweight
+            END DO
+         CASE( 13:16 )
+            IF( ii1 < 1 .OR. ii1 > jpi .OR. ij1 < 1 .OR. ij1 > jpj )   CYCLE
+            IF( ii2 < 1 .OR. ii2 > jpi .OR. ij2 < 1 .OR. ij2 > jpj )   CYCLE
+            IF( ii3 < 1 .OR. ii3 > jpi .OR. ij3 < 1 .OR. ij3 > jpj )   CYCLE
+            DO ik = 1, ipkm1
+               zweight = zmask(ii1,ij1,ik) + zmask(ii2,ij2,ik) + zmask(ii3,ij3,ik)
+               IF( zweight /= 0. )   phia(ii,ij,ik) = ( phia(ii1,ij1,ik) + phia(ii2,ij2,ik) + phia(ii3,ij3,ik) ) / zweight
+            END DO
+         END SELECT
       END DO
       !
Index: /NEMO/trunk/src/OCE/BDY/bdytides.F90
===================================================================
--- /NEMO/trunk/src/OCE/BDY/bdytides.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/BDY/bdytides.F90	(revision 11536)
@@ -70,5 +70,4 @@
       INTEGER                                   ::   inum, igrd
       INTEGER, DIMENSION(3)                     ::   ilen0       !: length of boundary data (from OBC arrays)
-      INTEGER, POINTER, DIMENSION(:)            ::   nblen, nblenrim     ! short cuts
       INTEGER                                   ::   ios                 ! Local integer output status for namelist read
       CHARACTER(len=80)                         ::   clfile              !: full file name for tidal input file 
@@ -77,14 +76,11 @@
       !!
       TYPE(TIDES_DATA),  POINTER                ::   td                  !: local short cut   
-      TYPE(MAP_POINTER), DIMENSION(jpbgrd)      ::   ibmap_ptr           !: array of pointers to nbmap
       !!
       NAMELIST/nambdy_tide/filtide, ln_bdytide_2ddta, ln_bdytide_conj
       !!----------------------------------------------------------------------
       !
-      IF (nb_bdy>0) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'bdytide_init : initialization of tidal harmonic forcing at open boundaries'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
-      ENDIF
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'bdytide_init : initialization of tidal harmonic forcing at open boundaries'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
 
       REWIND(numnam_cfg)
@@ -94,15 +90,14 @@
             !
             td => tides(ib_bdy)
-            nblen => idx_bdy(ib_bdy)%nblen
-            nblenrim => idx_bdy(ib_bdy)%nblenrim
 
             ! Namelist nambdy_tide : tidal harmonic forcing at open boundaries
             filtide(:) = ''
 
+            REWIND( numnam_ref )
+            READ  ( numnam_ref, nambdy_tide, IOSTAT = ios, ERR = 901)
+901         IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy_tide in reference namelist' )
             ! Don't REWIND here - may need to read more than one of these namelists. 
-            READ  ( numnam_ref, nambdy_tide, IOSTAT = ios, ERR = 901)
-901         IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy_tide in reference namelist', lwp )
             READ  ( numnam_cfg, nambdy_tide, IOSTAT = ios, ERR = 902 )
-902         IF( ios >  0 )   CALL ctl_nam ( ios , 'nambdy_tide in configuration namelist', lwp )
+902         IF( ios >  0 )   CALL ctl_nam ( ios , 'nambdy_tide in configuration namelist' )
             IF(lwm) WRITE ( numond, nambdy_tide )
             !                                               ! Parameter control and print
@@ -125,6 +120,6 @@
             ! JC: If FRS scheme is used, we assume that tidal is needed over the whole
             ! relaxation area      
-            IF( cn_dyn2d(ib_bdy) == 'frs' ) THEN   ;   ilen0(:) = nblen   (:)
-            ELSE                                   ;   ilen0(:) = nblenrim(:)
+            IF( cn_dyn2d(ib_bdy) == 'frs' ) THEN   ;   ilen0(:) = idx_bdy(ib_bdy)%nblen   (:)
+            ELSE                                   ;   ilen0(:) = idx_bdy(ib_bdy)%nblenrim(:)
             ENDIF
 
@@ -161,4 +156,5 @@
                      ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
                      ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                     IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )  CYCLE   ! to remove?
                      td%ssh0(ib,itide,1) = ztr(ii,ij)
                      td%ssh0(ib,itide,2) = zti(ii,ij)
@@ -177,4 +173,5 @@
                      ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
                      ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                     IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )  CYCLE   ! to remove?
                      td%u0(ib,itide,1) = ztr(ii,ij)
                      td%u0(ib,itide,2) = zti(ii,ij)
@@ -193,4 +190,5 @@
                      ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
                      ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                     IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )  CYCLE   ! to remove?
                      td%v0(ib,itide,1) = ztr(ii,ij)
                      td%v0(ib,itide,2) = zti(ii,ij)
@@ -207,9 +205,4 @@
                ALLOCATE( dta_read( MAXVAL(ilen0(1:3)), 1, 1 ) )
                !
-               ! Set map structure
-               ibmap_ptr(1)%ptr => idx_bdy(ib_bdy)%nbmap(:,1)   ;   ibmap_ptr(1)%ll_unstruc = ln_coords_file(ib_bdy)
-               ibmap_ptr(2)%ptr => idx_bdy(ib_bdy)%nbmap(:,2)   ;   ibmap_ptr(2)%ll_unstruc = ln_coords_file(ib_bdy)
-               ibmap_ptr(3)%ptr => idx_bdy(ib_bdy)%nbmap(:,3)   ;   ibmap_ptr(3)%ll_unstruc = ln_coords_file(ib_bdy)
-
                ! Open files and read in tidal forcing data
                ! -----------------------------------------
@@ -219,7 +212,7 @@
                   clfile = TRIM(filtide)//TRIM(Wave(ntide(itide))%cname_tide)//'_grid_T.nc'
                   CALL iom_open( clfile, inum )
-                  CALL fld_map( inum, 'z1' , dta_read(1:ilen0(1),1:1,1:1) , 1,  ibmap_ptr(1) )
+                  CALL fld_map( inum, 'z1' , dta_read(1:ilen0(1),1:1,1:1) , 1, idx_bdy(ib_bdy)%nbmap(:,1) )
                   td%ssh0(:,itide,1) = dta_read(1:ilen0(1),1,1)
-                  CALL fld_map( inum, 'z2' , dta_read(1:ilen0(1),1:1,1:1) , 1,  ibmap_ptr(1) )
+                  CALL fld_map( inum, 'z2' , dta_read(1:ilen0(1),1:1,1:1) , 1, idx_bdy(ib_bdy)%nbmap(:,1) )
                   td%ssh0(:,itide,2) = dta_read(1:ilen0(1),1,1)
                   CALL iom_close( inum )
@@ -227,7 +220,7 @@
                   clfile = TRIM(filtide)//TRIM(Wave(ntide(itide))%cname_tide)//'_grid_U.nc'
                   CALL iom_open( clfile, inum )
-                  CALL fld_map( inum, 'u1' , dta_read(1:ilen0(2),1:1,1:1) , 1, ibmap_ptr(2) )
+                  CALL fld_map( inum, 'u1' , dta_read(1:ilen0(2),1:1,1:1) , 1, idx_bdy(ib_bdy)%nbmap(:,2) )
                   td%u0(:,itide,1) = dta_read(1:ilen0(2),1,1)
-                  CALL fld_map( inum, 'u2' , dta_read(1:ilen0(2),1:1,1:1) , 1, ibmap_ptr(2) )
+                  CALL fld_map( inum, 'u2' , dta_read(1:ilen0(2),1:1,1:1) , 1, idx_bdy(ib_bdy)%nbmap(:,2) )
                   td%u0(:,itide,2) = dta_read(1:ilen0(2),1,1)
                   CALL iom_close( inum )
@@ -235,7 +228,7 @@
                   clfile = TRIM(filtide)//TRIM(Wave(ntide(itide))%cname_tide)//'_grid_V.nc'
                   CALL iom_open( clfile, inum )
-                  CALL fld_map( inum, 'v1' , dta_read(1:ilen0(3),1:1,1:1) , 1, ibmap_ptr(3) )
+                  CALL fld_map( inum, 'v1' , dta_read(1:ilen0(3),1:1,1:1) , 1, idx_bdy(ib_bdy)%nbmap(:,3) )
                   td%v0(:,itide,1) = dta_read(1:ilen0(3),1,1)
-                  CALL fld_map( inum, 'v2' , dta_read(1:ilen0(3),1:1,1:1) , 1, ibmap_ptr(3) )
+                  CALL fld_map( inum, 'v2' , dta_read(1:ilen0(3),1:1,1:1) , 1, idx_bdy(ib_bdy)%nbmap(:,3) )
                   td%v0(:,itide,2) = dta_read(1:ilen0(3),1,1)
                   CALL iom_close( inum )
@@ -269,5 +262,5 @@
 
 
-   SUBROUTINE bdytide_update( kt, idx, dta, td, jit, time_offset )
+   SUBROUTINE bdytide_update( kt, idx, dta, td, kit, kt_offset )
       !!----------------------------------------------------------------------
       !!                 ***  SUBROUTINE bdytide_update  ***
@@ -280,10 +273,10 @@
       TYPE(OBC_DATA)   , INTENT(inout) ::   dta         ! OBC external data
       TYPE(TIDES_DATA) , INTENT(inout) ::   td          ! tidal harmonics data
-      INTEGER, OPTIONAL, INTENT(in   ) ::   jit         ! Barotropic timestep counter (for timesplitting option)
-      INTEGER, OPTIONAL, INTENT(in   ) ::   time_offset ! time offset in units of timesteps. NB. if jit
+      INTEGER, OPTIONAL, INTENT(in   ) ::   kit         ! Barotropic timestep counter (for timesplitting option)
+      INTEGER, OPTIONAL, INTENT(in   ) ::   kt_offset   ! time offset in units of timesteps. NB. if kit
       !                                                 ! is present then units = subcycle timesteps.
-      !                                                 ! time_offset = 0  => get data at "now"    time level
-      !                                                 ! time_offset = -1 => get data at "before" time level
-      !                                                 ! time_offset = +1 => get data at "after"  time level
+      !                                                 ! kt_offset = 0  => get data at "now"    time level
+      !                                                 ! kt_offset = -1 => get data at "before" time level
+      !                                                 ! kt_offset = +1 => get data at "after"  time level
       !                                                 ! etc.
       !
@@ -300,6 +293,6 @@
 
       zflag=1
-      IF ( PRESENT(jit) ) THEN
-        IF ( jit /= 1 ) zflag=0
+      IF ( PRESENT(kit) ) THEN
+        IF ( kit /= 1 ) zflag=0
       ENDIF
 
@@ -320,10 +313,10 @@
 
       time_add = 0
-      IF( PRESENT(time_offset) ) THEN
-         time_add = time_offset
+      IF( PRESENT(kt_offset) ) THEN
+         time_add = kt_offset
       ENDIF
          
-      IF( PRESENT(jit) ) THEN  
-         z_arg = ((kt-kt_tide) * rdt + (jit+0.5_wp*(time_add-1)) * rdt / REAL(nn_baro,wp) )
+      IF( PRESENT(kit) ) THEN  
+         z_arg = ((kt-kt_tide) * rdt + (kit+0.5_wp*(time_add-1)) * rdt / REAL(nn_baro,wp) )
       ELSE                              
          z_arg = ((kt-kt_tide)+time_add) * rdt
@@ -358,5 +351,5 @@
 
 
-   SUBROUTINE bdy_dta_tides( kt, kit, time_offset )
+   SUBROUTINE bdy_dta_tides( kt, kit, kt_offset )
       !!----------------------------------------------------------------------
       !!                 ***  SUBROUTINE bdy_dta_tides  ***
@@ -367,9 +360,9 @@
       INTEGER,           INTENT(in) ::   kt          ! Main timestep counter
       INTEGER, OPTIONAL, INTENT(in) ::   kit         ! Barotropic timestep counter (for timesplitting option)
-      INTEGER, OPTIONAL, INTENT(in) ::   time_offset ! time offset in units of timesteps. NB. if kit
+      INTEGER, OPTIONAL, INTENT(in) ::   kt_offset   ! time offset in units of timesteps. NB. if kit
       !                                              ! is present then units = subcycle timesteps.
-      !                                              ! time_offset = 0  => get data at "now"    time level
-      !                                              ! time_offset = -1 => get data at "before" time level
-      !                                              ! time_offset = +1 => get data at "after"  time level
+      !                                              ! kt_offset = 0  => get data at "now"    time level
+      !                                              ! kt_offset = -1 => get data at "before" time level
+      !                                              ! kt_offset = +1 => get data at "after"  time level
       !                                              ! etc.
       !
@@ -386,6 +379,6 @@
 
       time_add = 0
-      IF( PRESENT(time_offset) ) THEN
-         time_add = time_offset
+      IF( PRESENT(kt_offset) ) THEN
+         time_add = kt_offset
       ENDIF
       
@@ -432,7 +425,7 @@
             ! If time splitting, initialize arrays from slow varying open boundary data:
             IF ( PRESENT(kit) ) THEN           
-               IF ( dta_bdy(ib_bdy)%ll_ssh ) dta_bdy(ib_bdy)%ssh(1:ilen0(1)) = dta_bdy_s(ib_bdy)%ssh(1:ilen0(1))
-               IF ( dta_bdy(ib_bdy)%ll_u2d ) dta_bdy(ib_bdy)%u2d(1:ilen0(2)) = dta_bdy_s(ib_bdy)%u2d(1:ilen0(2))
-               IF ( dta_bdy(ib_bdy)%ll_v2d ) dta_bdy(ib_bdy)%v2d(1:ilen0(3)) = dta_bdy_s(ib_bdy)%v2d(1:ilen0(3))
+               IF ( dta_bdy(ib_bdy)%lneed_ssh   ) dta_bdy(ib_bdy)%ssh(1:ilen0(1)) = dta_bdy_s(ib_bdy)%ssh(1:ilen0(1))
+               IF ( dta_bdy(ib_bdy)%lneed_dyn2d ) dta_bdy(ib_bdy)%u2d(1:ilen0(2)) = dta_bdy_s(ib_bdy)%u2d(1:ilen0(2))
+               IF ( dta_bdy(ib_bdy)%lneed_dyn2d ) dta_bdy(ib_bdy)%v2d(1:ilen0(3)) = dta_bdy_s(ib_bdy)%v2d(1:ilen0(3))
             ENDIF
             !
@@ -444,5 +437,5 @@
                z_sist = zramp * SIN( z_sarg )
                !
-               IF ( dta_bdy(ib_bdy)%ll_ssh ) THEN
+               IF ( dta_bdy(ib_bdy)%lneed_ssh ) THEN
                   igrd=1                              ! SSH on tracer grid
                   DO ib = 1, ilen0(igrd)
@@ -453,5 +446,5 @@
                ENDIF
                !
-               IF ( dta_bdy(ib_bdy)%ll_u2d ) THEN
+               IF ( dta_bdy(ib_bdy)%lneed_dyn2d ) THEN
                   igrd=2                              ! U grid
                   DO ib = 1, ilen0(igrd)
@@ -460,7 +453,4 @@
                         &                        tides(ib_bdy)%u(ib,itide,2)*z_sist )
                   END DO
-               ENDIF
-               !
-               IF ( dta_bdy(ib_bdy)%ll_v2d ) THEN
                   igrd=3                              ! V grid
                   DO ib = 1, ilen0(igrd) 
Index: /NEMO/trunk/src/OCE/BDY/bdytra.F90
===================================================================
--- /NEMO/trunk/src/OCE/BDY/bdytra.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/BDY/bdytra.F90	(revision 11536)
@@ -49,36 +49,62 @@
       INTEGER, INTENT(in) ::   kt   ! Main time step counter
       !
-      INTEGER                        :: ib_bdy, jn, igrd   ! Loop indeces
-      TYPE(ztrabdy), DIMENSION(jpts) :: zdta               ! Temporary data structure
+      INTEGER                        :: ib_bdy, jn, igrd, ir   ! Loop indeces
+      TYPE(ztrabdy), DIMENSION(jpts) :: zdta                   ! Temporary data structure
+      LOGICAL                        :: llrim0                 ! indicate if rim 0 is treated
+      LOGICAL, DIMENSION(4)          :: llsend1, llrecv1       ! indicate how communications are to be carried out
       !!----------------------------------------------------------------------
       igrd = 1 
-
-      DO ib_bdy=1, nb_bdy
+      llsend1(:) = .false.  ;   llrecv1(:) = .false.
+      DO ir = 1, 0, -1   ! treat rim 1 before rim 0
+         IF( ir == 0 ) THEN   ;   llrim0 = .TRUE.
+         ELSE                 ;   llrim0 = .FALSE.
+         END IF
+         DO ib_bdy=1, nb_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'         )   ! treat the whole boundary at once
+                  IF( ir == 0 ) CALL bdy_frs ( idx_bdy(ib_bdy),                tsa(:,:,:,jn), zdta(jn)%tra )
+               CASE('specified'   )   ! treat the whole rim      at once
+                  IF( ir == 0 ) CALL bdy_spe ( idx_bdy(ib_bdy),                tsa(:,:,:,jn), zdta(jn)%tra )
+               CASE('neumann'     )   ;   CALL bdy_nmn ( idx_bdy(ib_bdy), igrd         , tsa(:,:,:,jn), llrim0 )   ! tsa masked
+               CASE('orlanski'    )   ;   CALL bdy_orl ( idx_bdy(ib_bdy), tsb(:,:,:,jn), tsa(:,:,:,jn), &
+                    & zdta(jn)%tra, llrim0, ll_npo=.false. )
+               CASE('orlanski_npo')   ;   CALL bdy_orl ( idx_bdy(ib_bdy), tsb(:,:,:,jn), tsa(:,:,:,jn), &
+                    & zdta(jn)%tra, llrim0, ll_npo=.true.  )
+               CASE('runoff'      )   ;   CALL bdy_rnf ( idx_bdy(ib_bdy),                tsa(:,:,:,jn), jn, llrim0 )
+               CASE DEFAULT           ;   CALL ctl_stop( 'bdy_tra : unrecognised option for open boundaries for T and S' )
+               END SELECT
+               ! 
+            END DO
+         END DO
          !
-         zdta(1)%tra => dta_bdy(ib_bdy)%tem
-         zdta(2)%tra => dta_bdy(ib_bdy)%sal
+         IF( nn_hls > 1 .AND. ir == 1 ) CYCLE   ! at least 2 halos will be corrected -> no need to correct rim 1 before rim 0
+         IF( nn_hls == 1 ) THEN   ;   llsend1(:) = .false.   ;   llrecv1(:) = .false.   ;   END IF
+         DO ib_bdy=1, nb_bdy
+            SELECT CASE( TRIM(cn_tra(ib_bdy)) )
+            CASE('neumann','runoff')
+               llsend1(:) = llsend1(:) .OR. lsend_bdyint(ib_bdy,1,:,ir)   ! possibly every direction, T points
+               llrecv1(:) = llrecv1(:) .OR. lrecv_bdyint(ib_bdy,1,:,ir)   ! possibly every direction, T points
+            CASE('orlanski', 'orlanski_npo')
+               llsend1(:) = llsend1(:) .OR. lsend_bdy(ib_bdy,1,:,ir)   ! possibly every direction, T points
+               llrecv1(:) = llrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:,ir)   ! possibly every direction, T points
+            END SELECT
+         END DO
+         IF( ANY(llsend1) .OR. ANY(llrecv1) ) THEN   ! if need to send/recv in at least one direction
+            CALL lbc_lnk( 'bdytra', tsa, 'T',  1., kfillmode=jpfillnothing ,lsend=llsend1, lrecv=llrecv1 )
+         END IF
          !
-         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), igrd         , 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( 'bdytra', tsa(:,:,:,jn), 'T', 1., ib_bdy )
-            ! 
-         END DO
-      END DO
+      END DO   ! ir
       !
    END SUBROUTINE bdy_tra
 
 
-   SUBROUTINE bdy_rnf( idx, pta, jpa )
+   SUBROUTINE bdy_rnf( idx, pta, jpa, llrim0 )
       !!----------------------------------------------------------------------
       !!                 ***  SUBROUTINE bdy_rnf  ***
@@ -89,24 +115,24 @@
       !! 
       !!----------------------------------------------------------------------
-      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
+      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
+      LOGICAL,                             INTENT(in) ::   llrim0   ! indicate if rim 0 is treated
       !
-      REAL(wp) ::   zwgt           ! boundary weight
-      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
-      INTEGER  ::   ii, ij, ip, jp ! 2D addresses
+      INTEGER  ::   ib, ii, ij, igrd   ! dummy loop indices
+      INTEGER  ::   ik, ip, jp ! 2D addresses
       !!----------------------------------------------------------------------
       !
       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
-            ip = bdytmask(ii+1,ij  ) - bdytmask(ii-1,ij  )
-            jp = bdytmask(ii  ,ij+1) - bdytmask(ii  ,ij-1)
-            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)
+      IF(      jpa == jp_tem ) THEN
+         CALL bdy_nmn( idx, igrd, pta, llrim0 )
+      ELSE IF( jpa == jp_sal ) THEN
+         IF( .NOT. llrim0 )   RETURN
+         DO ib = 1, idx%nblenrim(igrd)   ! if llrim0 then treat the whole rim
+            ii = idx%nbi(ib,igrd)
+            ij = idx%nbj(ib,igrd)
+            pta(ii,ij,1:jpkm1) = 0.1 * tmask(ii,ij,1:jpkm1)
          END DO
-      END DO
+      END IF
       !
    END SUBROUTINE bdy_rnf
Index: /NEMO/trunk/src/OCE/BDY/bdyvol.F90
===================================================================
--- /NEMO/trunk/src/OCE/BDY/bdyvol.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/BDY/bdyvol.F90	(revision 11536)
@@ -99,4 +99,5 @@
             ii = idx%nbi(jb,jgrd)
             ij = idx%nbj(jb,jgrd)
+            IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )  CYCLE   ! sum : else halo couted twice
             zubtpecor = zubtpecor + idx%flagu(jb,jgrd) * pua2d(ii,ij) * e2u(ii,ij) * phu(ii,ij) * tmask_i(ii,ij) * tmask_i(ii+1,ij)
          END DO
@@ -105,4 +106,5 @@
             ii = idx%nbi(jb,jgrd)
             ij = idx%nbj(jb,jgrd)
+            IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )  CYCLE   ! sum : else halo couted twice
             zubtpecor = zubtpecor + idx%flagv(jb,jgrd) * pva2d(ii,ij) * e1v(ii,ij) * phv(ii,ij) * tmask_i(ii,ij) * tmask_i(ii,ij+1)
          END DO
@@ -126,4 +128,5 @@
                ii = idx%nbi(jb,jgrd)
                ij = idx%nbj(jb,jgrd)
+               !IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )  CYCLE   ! to remove ?
                pua2d(ii,ij) = pua2d(ii,ij) - idx%flagu(jb,jgrd) * zubtpecor * tmask_i(ii,ij) * tmask_i(ii+1,ij)
          END DO
@@ -132,4 +135,5 @@
                ii = idx%nbi(jb,jgrd)
                ij = idx%nbj(jb,jgrd)
+               !IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )  CYCLE   ! to remove ?
                pva2d(ii,ij) = pva2d(ii,ij) - idx%flagv(jb,jgrd) * zubtpecor * tmask_i(ii,ij) * tmask_i(ii,ij+1)
          END DO
@@ -139,5 +143,5 @@
       ! Check the cumulated transport through unstructured OBC once barotropic velocities corrected
       ! ------------------------------------------------------
-      IF( MOD( kt, nwrite ) == 0 .AND. ( kc == 1 ) ) THEN
+      IF( MOD( kt, nn_write ) == 0 .AND. ( kc == 1 ) ) THEN
          !
          ! compute residual transport across boundary
@@ -150,4 +154,5 @@
                   ii = idx%nbi(jb,jgrd)
                   ij = idx%nbj(jb,jgrd)
+                  IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )  CYCLE
                   ztranst = ztranst + idx%flagu(jb,jgrd) * pua2d(ii,ij) * e2u(ii,ij) * phu(ii,ij) * tmask_i(ii,ij) * tmask_i(ii+1,ij)
             END DO
@@ -156,4 +161,5 @@
                   ii = idx%nbi(jb,jgrd)
                   ij = idx%nbj(jb,jgrd)
+                  IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )  CYCLE
                   ztranst = ztranst + idx%flagv(jb,jgrd) * pva2d(ii,ij) * e1v(ii,ij) * phv(ii,ij) * tmask_i(ii,ij) * tmask_i(ii,ij+1)
             END DO
@@ -195,4 +201,5 @@
             nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
             nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
+            IF( nbi == 1 .OR. nbi == jpi .OR. nbj == 1 .OR. nbj == jpj )  CYCLE
             zflagu => idx_bdy(ib_bdy)%flagu(ib,igrd)
             bdy_segs_surf = bdy_segs_surf + phu(nbi, nbj)                              &
@@ -207,4 +214,5 @@
             nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
             nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
+            IF( nbi == 1 .OR. nbi == jpi .OR. nbj == 1 .OR. nbj == jpj )  CYCLE
             zflagv => idx_bdy(ib_bdy)%flagv(ib,igrd)
             bdy_segs_surf = bdy_segs_surf + phv(nbi, nbj)                              &
Index: /NEMO/trunk/src/OCE/C1D/c1d.F90
===================================================================
--- /NEMO/trunk/src/OCE/C1D/c1d.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/C1D/c1d.F90	(revision 11536)
@@ -52,9 +52,9 @@
       REWIND( numnam_ref )              ! Namelist namc1d in reference namelist : Tracer advection scheme
       READ  ( numnam_ref, namc1d, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc1d in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc1d in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist namtra_adv in configuration namelist : Tracer advection scheme
       READ  ( numnam_cfg, namc1d, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc1d in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc1d in configuration namelist' )
       IF(lwm) WRITE ( numond, namc1d )
       !
Index: /NEMO/trunk/src/OCE/C1D/dtauvd.F90
===================================================================
--- /NEMO/trunk/src/OCE/C1D/dtauvd.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/C1D/dtauvd.F90	(revision 11536)
@@ -62,9 +62,9 @@
       REWIND( numnam_ref )              ! Namelist namc1d_uvd in reference namelist : 
       READ  ( numnam_ref, namc1d_uvd, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc1d_uvd in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc1d_uvd in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist namc1d_uvd in configuration namelist : Parameters of the run
       READ  ( numnam_cfg, namc1d_uvd, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc1d_uvd in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc1d_uvd in configuration namelist' )
       IF(lwm) WRITE ( numond, namc1d_uvd )
 
Index: /NEMO/trunk/src/OCE/C1D/dyndmp.F90
===================================================================
--- /NEMO/trunk/src/OCE/C1D/dyndmp.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/C1D/dyndmp.F90	(revision 11536)
@@ -81,8 +81,8 @@
       REWIND( numnam_ref )              ! Namelist namc1d_dyndmp in reference namelist : 
       READ  ( numnam_ref, namc1d_dyndmp, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc1d_dyndmp in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc1d_dyndmp in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namc1d_dyndmp in configuration namelist : Parameters of the run
       READ  ( numnam_cfg, namc1d_dyndmp, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc1d_dyndmp in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc1d_dyndmp in configuration namelist' )
       IF(lwm) WRITE ( numond, namc1d_dyndmp )
       !
Index: /NEMO/trunk/src/OCE/CRS/crsdom.F90
===================================================================
--- /NEMO/trunk/src/OCE/CRS/crsdom.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/CRS/crsdom.F90	(revision 11536)
@@ -296,6 +296,6 @@
       ENDDO
 
-      CALL crs_lbc_lnk( p_e1_crs, cd_type, 1.0, pval=1.0 )
-      CALL crs_lbc_lnk( p_e2_crs, cd_type, 1.0, pval=1.0 )
+      CALL crs_lbc_lnk( p_e1_crs, cd_type, 1.0, pfillval=1.0 )
+      CALL crs_lbc_lnk( p_e2_crs, cd_type, 1.0, pfillval=1.0 )
 
    END SUBROUTINE crs_dom_hgr
@@ -579,5 +579,5 @@
                   ENDDO  
                CASE DEFAULT
-                    STOP
+                  CALL ctl_stop( 'STOP', 'error from crs_dom_ope_3d, you should not be there...' )
                END SELECT
 
@@ -1748,6 +1748,6 @@
        ENDDO
                   
-       CALL crs_lbc_lnk( p_e3_crs    , cd_type, 1.0, pval=1.0 )  
-       CALL crs_lbc_lnk( p_e3_max_crs, cd_type, 1.0, pval=1.0 )  
+       CALL crs_lbc_lnk( p_e3_crs    , cd_type, 1.0, pfillval=1.0 )  
+       CALL crs_lbc_lnk( p_e3_max_crs, cd_type, 1.0, pfillval=1.0 )  
        !              
        !
@@ -1857,6 +1857,6 @@
       ENDDO   
 
-      CALL crs_lbc_lnk( p_surf_crs    , cd_type, 1.0, pval=1.0 )
-      CALL crs_lbc_lnk( p_surf_crs_msk, cd_type, 1.0, pval=1.0 )
+      CALL crs_lbc_lnk( p_surf_crs    , cd_type, 1.0, pfillval=1.0 )
+      CALL crs_lbc_lnk( p_surf_crs_msk, cd_type, 1.0, pfillval=1.0 )
 
    END SUBROUTINE crs_dom_sfc
@@ -1947,5 +1947,5 @@
                 
               CASE DEFAULT
-                 STOP
+                 CALL ctl_stop( 'STOP', 'error from crs_dom_def, you should not be there (1) ...' )
            END SELECT
            IF( nlcjt_crs(jn) > jpj_crs )     jpj_crs = jpj_crs + 1
@@ -1996,5 +1996,5 @@
 
               CASE DEFAULT
-                 STOP
+                 CALL ctl_stop( 'STOP', 'error from crs_dom_def, you should not be there (2) ...' )
            END SELECT
 
Index: /NEMO/trunk/src/OCE/CRS/crsini.F90
===================================================================
--- /NEMO/trunk/src/OCE/CRS/crsini.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/CRS/crsini.F90	(revision 11536)
@@ -82,8 +82,8 @@
       REWIND( numnam_ref )              ! Namelist namrun in reference namelist : Parameters of the run
       READ  ( numnam_ref, namcrs, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcrs in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcrs in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namrun in configuration namelist : Parameters of the run
       READ  ( numnam_cfg, namcrs, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcrs in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcrs in configuration namelist' )
       IF(lwm) WRITE ( numond, namcrs )
 
Index: /NEMO/trunk/src/OCE/CRS/crslbclnk.F90
===================================================================
--- /NEMO/trunk/src/OCE/CRS/crslbclnk.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/CRS/crslbclnk.F90	(revision 11536)
@@ -27,5 +27,5 @@
 CONTAINS
 
-   SUBROUTINE crs_lbc_lnk_3d( pt3d1, cd_type1, psgn, cd_mpp, pval )
+   SUBROUTINE crs_lbc_lnk_3d( pt3d1, cd_type1, psgn, kfillmode, pfillval  )
       !!---------------------------------------------------------------------
       !!                  ***  SUBROUTINE crs_lbc_lnk  ***
@@ -40,22 +40,15 @@
       REAL(wp)                                , INTENT(in   ) ::   psgn     ! control of the sign
       REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(inout) ::   pt3d1    ! 3D array on which the lbc is applied
-      REAL(wp)                      , OPTIONAL, INTENT(in   ) ::   pval     ! valeur sur les halo
-      CHARACTER(len=3)              , OPTIONAL, INTENT(in   ) ::   cd_mpp   ! MPP only (here do nothing)
+      INTEGER                     , OPTIONAL  , INTENT(in   ) ::   kfillmode   ! filling method for halo over land (default = cst)
+      REAL(wp)                    , OPTIONAL  , INTENT(in   ) ::   pfillval    ! background value (used at closed boundaries)
       !
       LOGICAL  ::   ll_grid_crs
-      REAL(wp) ::   zval   ! valeur sur les halo
       !!----------------------------------------------------------------------
       !
       ll_grid_crs = ( jpi == jpi_crs )
       !
-      IF( PRESENT(pval) ) THEN   ;   zval = pval
-      ELSE                       ;   zval = 0._wp
-      ENDIF
-      !
       IF( .NOT.ll_grid_crs )   CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
       !
-      IF( PRESENT( cd_mpp ) ) THEN   ;   CALL lbc_lnk( 'crslbclnk', pt3d1, cd_type1, psgn, cd_mpp, pval=zval  )
-      ELSE                           ;   CALL lbc_lnk( 'crslbclnk', pt3d1, cd_type1, psgn        , pval=zval  )
-      ENDIF
+      CALL lbc_lnk( 'crslbclnk', pt3d1, cd_type1, psgn, kfillmode, pfillval )
       !
       IF( .NOT.ll_grid_crs )   CALL dom_grid_glo   ! Return to parent grid domain
@@ -64,5 +57,5 @@
    
    
-   SUBROUTINE crs_lbc_lnk_2d(pt2d, cd_type, psgn, cd_mpp, pval)
+   SUBROUTINE crs_lbc_lnk_2d(pt2d, cd_type, psgn, kfillmode, pfillval )
       !!---------------------------------------------------------------------
       !!                  ***  SUBROUTINE crs_lbc_lnk  ***
@@ -77,22 +70,15 @@
       REAL(wp)                            , INTENT(in   ) ::   psgn     ! control of the sign
       REAL(wp), DIMENSION(jpi_crs,jpj_crs), INTENT(inout) ::   pt2d     ! 2D array on which the lbc is applied
-      REAL(wp)                  , OPTIONAL, INTENT(in   ) ::   pval     ! valeur sur les halo
-      CHARACTER(len=3)          , OPTIONAL, INTENT(in   ) ::   cd_mpp   ! MPP only (here do nothing)
+      INTEGER                 , OPTIONAL  , INTENT(in   ) ::   kfillmode   ! filling method for halo over land (default = constant)
+      REAL(wp)                , OPTIONAL  , INTENT(in   ) ::   pfillval    ! background value (used at closed boundaries)
       !      
       LOGICAL  ::   ll_grid_crs
-      REAL(wp) ::   zval     ! valeur sur les halo
       !!----------------------------------------------------------------------
       !
       ll_grid_crs = ( jpi == jpi_crs )
       !
-      IF( PRESENT(pval) ) THEN   ;   zval = pval
-      ELSE                       ;   zval = 0._wp
-      ENDIF
-      !
       IF( .NOT.ll_grid_crs )   CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
       !
-      IF( PRESENT( cd_mpp ) ) THEN   ;   CALL lbc_lnk( 'crslbclnk', pt2d, cd_type, psgn, cd_mpp, pval=zval  )
-      ELSE                           ;   CALL lbc_lnk( 'crslbclnk', pt2d, cd_type, psgn        , pval=zval  )
-      ENDIF
+      CALL lbc_lnk( 'crslbclnk', pt2d, cd_type, psgn, kfillmode, pfillval )
       !
       IF( .NOT.ll_grid_crs )   CALL dom_grid_glo   ! Return to parent grid domain
Index: /NEMO/trunk/src/OCE/DIA/dia25h.F90
===================================================================
--- /NEMO/trunk/src/OCE/DIA/dia25h.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DIA/dia25h.F90	(revision 11536)
@@ -55,8 +55,8 @@
       REWIND ( numnam_ref )              ! Read Namelist nam_dia25h in reference namelist : 25hour mean diagnostics
       READ   ( numnam_ref, nam_dia25h, IOSTAT=ios, ERR= 901 )
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_dia25h in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_dia25h in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist nam_dia25h in configuration namelist  25hour diagnostics
       READ  ( numnam_cfg, nam_dia25h, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nam_dia25h in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nam_dia25h in configuration namelist' )
       IF(lwm) WRITE ( numond, nam_dia25h )
 
Index: /NEMO/trunk/src/OCE/DIA/diadct.F90
===================================================================
--- /NEMO/trunk/src/OCE/DIA/diadct.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DIA/diadct.F90	(revision 11536)
@@ -11,8 +11,6 @@
    !!            3.4  ! 09/2011 (C Bricaud)
    !!----------------------------------------------------------------------
-#if defined key_diadct
-   !!----------------------------------------------------------------------
-   !!   'key_diadct' :
-   !!----------------------------------------------------------------------
+   !! does not work with agrif
+#if ! defined key_agrif
    !!----------------------------------------------------------------------
    !!   dia_dct      :  Compute the transport through a sec.
@@ -42,16 +40,11 @@
 
    PUBLIC   dia_dct      ! routine called by step.F90
-   PUBLIC   dia_dct_init ! routine called by opa.F90
-   PUBLIC   diadct_alloc ! routine called by nemo_init in nemogcm.F90 
-   PRIVATE  readsec
-   PRIVATE  removepoints
-   PRIVATE  transport
-   PRIVATE  dia_dct_wri
-
-   LOGICAL, PUBLIC, PARAMETER ::   lk_diadct = .TRUE.   !: model-data diagnostics flag
-
-   INTEGER :: nn_dct        ! Frequency of computation
-   INTEGER :: nn_dctwri     ! Frequency of output
-   INTEGER :: nn_secdebug   ! Number of the section to debug
+   PUBLIC   dia_dct_init ! routine called by nemogcm.F90
+
+   !                         !!** namelist variables **
+   LOGICAL, PUBLIC ::   ln_diadct     !: Calculate transport thru a section or not
+   INTEGER         ::   nn_dct        !  Frequency of computation
+   INTEGER         ::   nn_dctwri     !  Frequency of output
+   INTEGER         ::   nn_secdebug   !  Number of the section to debug
    
    INTEGER, PARAMETER :: nb_class_max  = 10
@@ -104,19 +97,16 @@
 CONTAINS
  
-  INTEGER FUNCTION diadct_alloc() 
-     !!---------------------------------------------------------------------- 
-     !!                   ***  FUNCTION diadct_alloc  *** 
-     !!---------------------------------------------------------------------- 
-     INTEGER :: ierr(2) 
-     !!---------------------------------------------------------------------- 
-
-     ALLOCATE(transports_3d(nb_3d_vars,nb_sec_max,nb_point_max,jpk), STAT=ierr(1) ) 
-     ALLOCATE(transports_2d(nb_2d_vars,nb_sec_max,nb_point_max)    , STAT=ierr(2) ) 
-
-     diadct_alloc = MAXVAL( ierr ) 
-     IF( diadct_alloc /= 0 )   CALL ctl_stop( 'STOP', 'diadct_alloc: failed to allocate arrays' ) 
- 
-  END FUNCTION diadct_alloc 
-
+   INTEGER FUNCTION diadct_alloc() 
+      !!---------------------------------------------------------------------- 
+      !!                   ***  FUNCTION diadct_alloc  *** 
+      !!---------------------------------------------------------------------- 
+
+      ALLOCATE( transports_3d(nb_3d_vars,nb_sec_max,nb_point_max,jpk), &
+         &      transports_2d(nb_2d_vars,nb_sec_max,nb_point_max)    , STAT=diadct_alloc ) 
+
+      CALL mpp_sum( 'diadct', diadct_alloc ) 
+      IF( diadct_alloc /= 0 )   CALL ctl_stop( 'STOP', 'diadct_alloc: failed to allocate arrays' ) 
+
+   END FUNCTION diadct_alloc
 
    SUBROUTINE dia_dct_init
@@ -130,15 +120,15 @@
       INTEGER  ::   ios                 ! Local integer output status for namelist read
       !!
-      NAMELIST/namdct/nn_dct,nn_dctwri,nn_secdebug
+      NAMELIST/nam_diadct/ln_diadct, nn_dct, nn_dctwri, nn_secdebug
       !!---------------------------------------------------------------------
 
-     REWIND( numnam_ref )              ! Namelist namdct in reference namelist : Diagnostic: transport through sections
-     READ  ( numnam_ref, namdct, IOSTAT = ios, ERR = 901)
-901  IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdct in reference namelist', lwp )
-
-     REWIND( numnam_cfg )              ! Namelist namdct in configuration namelist : Diagnostic: transport through sections
-     READ  ( numnam_cfg, namdct, IOSTAT = ios, ERR = 902 )
-902  IF( ios >  0 ) CALL ctl_nam ( ios , 'namdct in configuration namelist', lwp )
-     IF(lwm) WRITE ( numond, namdct )
+     REWIND( numnam_ref )              ! Namelist nam_diadct in reference namelist : Diagnostic: transport through sections
+     READ  ( numnam_ref, nam_diadct, IOSTAT = ios, ERR = 901)
+901  IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diadct in reference namelist' )
+
+     REWIND( numnam_cfg )              ! Namelist nam_diadct in configuration namelist : Diagnostic: transport through sections
+     READ  ( numnam_cfg, nam_diadct, IOSTAT = ios, ERR = 902 )
+902  IF( ios >  0 ) CALL ctl_nam ( ios , 'nam_diadct in configuration namelist' )
+     IF(lwm) WRITE ( numond, nam_diadct )
 
      IF( lwp ) THEN
@@ -146,6 +136,7 @@
         WRITE(numout,*) "diadct_init: compute transports through sections "
         WRITE(numout,*) "~~~~~~~~~~~~~~~~~~~~~"
-        WRITE(numout,*) "       Frequency of computation: nn_dct    = ",nn_dct
-        WRITE(numout,*) "       Frequency of write:       nn_dctwri = ",nn_dctwri
+        WRITE(numout,*) "       Calculate transport thru sections: ln_diadct = ", ln_diadct
+        WRITE(numout,*) "       Frequency of computation:          nn_dct    = ", nn_dct
+        WRITE(numout,*) "       Frequency of write:                nn_dctwri = ", nn_dctwri
 
         IF      ( nn_secdebug .GE. 1 .AND. nn_secdebug .LE. nb_sec_max )THEN
@@ -155,23 +146,29 @@
         ELSE                              ; WRITE(numout,*)"       Wrong value for nn_secdebug : ",nn_secdebug
         ENDIF
-
+     ENDIF
+
+     IF( ln_diadct ) THEN
+        ! control
         IF(nn_dct .GE. nn_dctwri .AND. MOD(nn_dct,nn_dctwri) .NE. 0)  &
-          &  CALL ctl_stop( 'diadct: nn_dct should be smaller and a multiple of nn_dctwri' )
-
+           &  CALL ctl_stop( 'diadct: nn_dct should be smaller and a multiple of nn_dctwri' )
+
+        ! allocate dia_dct arrays
+        IF( diadct_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'diadct_alloc: failed to allocate arrays' )
+
+        !Read section_ijglobal.diadct
+        CALL readsec
+
+        !open output file
+        IF( lwm ) THEN
+           CALL ctl_opn( numdct_vol,  'volume_transport', 'NEW', 'FORMATTED', 'SEQUENTIAL', -1, numout,  .FALSE. )
+           CALL ctl_opn( numdct_heat, 'heat_transport'  , 'NEW', 'FORMATTED', 'SEQUENTIAL', -1, numout,  .FALSE. )
+           CALL ctl_opn( numdct_salt, 'salt_transport'  , 'NEW', 'FORMATTED', 'SEQUENTIAL', -1, numout,  .FALSE. )
+        ENDIF
+
+        ! Initialise arrays to zero 
+        transports_3d(:,:,:,:)=0.0 
+        transports_2d(:,:,:)  =0.0 
+        !
      ENDIF
-
-     !Read section_ijglobal.diadct
-     CALL readsec
-
-     !open output file
-     IF( lwm ) THEN
-        CALL ctl_opn( numdct_vol,  'volume_transport', 'NEW', 'FORMATTED', 'SEQUENTIAL', -1, numout,  .FALSE. )
-        CALL ctl_opn( numdct_heat, 'heat_transport'  , 'NEW', 'FORMATTED', 'SEQUENTIAL', -1, numout,  .FALSE. )
-        CALL ctl_opn( numdct_salt, 'salt_transport'  , 'NEW', 'FORMATTED', 'SEQUENTIAL', -1, numout,  .FALSE. )
-     ENDIF
-
-     ! Initialise arrays to zero 
-     transports_3d(:,:,:,:)=0.0 
-     transports_2d(:,:,:)  =0.0 
      !
   END SUBROUTINE dia_dct_init
@@ -1241,21 +1238,16 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option :                                       Dummy module
+   !!   Dummy module                                             
    !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER ::   lk_diadct = .FALSE.    !: diamht flag
-   PUBLIC 
-   !! $Id$
+   LOGICAL, PUBLIC ::   ln_diadct = .FALSE.
 CONTAINS
-
-   SUBROUTINE dia_dct_init          ! Dummy routine
+   SUBROUTINE dia_dct_init
       IMPLICIT NONE
-      WRITE(*,*) 'dia_dct_init: You should not have seen this print! error?'
    END SUBROUTINE dia_dct_init
-
-   SUBROUTINE dia_dct( kt )         ! Dummy routine
+   SUBROUTINE dia_dct( kt )
       IMPLICIT NONE
-      INTEGER, INTENT( in ) :: kt   ! ocean time-step index
-      WRITE(*,*) 'dia_dct: You should not have seen this print! error?', kt
+      INTEGER, INTENT(in) ::   kt
    END SUBROUTINE dia_dct
+   !
 #endif
 
Index: /NEMO/trunk/src/OCE/DIA/diaharm.F90
===================================================================
--- /NEMO/trunk/src/OCE/DIA/diaharm.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DIA/diaharm.F90	(revision 11536)
@@ -5,8 +5,4 @@
    !!======================================================================
    !! History :  3.1  !  2007  (O. Le Galloudec, J. Chanut)  Original code
-   !!----------------------------------------------------------------------
-#if defined key_diaharm
-   !!----------------------------------------------------------------------
-   !!   'key_diaharm'
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers variables
@@ -26,6 +22,4 @@
    IMPLICIT NONE
    PRIVATE
-
-   LOGICAL, PUBLIC, PARAMETER :: lk_diaharm  = .TRUE.
    
    INTEGER, PARAMETER :: jpincomax    = 2.*jpmax_harmo
@@ -33,8 +27,9 @@
 
    !                         !!** namelist variables **
-   INTEGER ::   nit000_han    ! First time step used for harmonic analysis
-   INTEGER ::   nitend_han    ! Last time step used for harmonic analysis
-   INTEGER ::   nstep_han     ! Time step frequency for harmonic analysis
-   INTEGER ::   nb_ana        ! Number of harmonics to analyse
+   LOGICAL, PUBLIC ::   ln_diaharm    ! Choose tidal harmonic output or not
+   INTEGER         ::   nit000_han    ! First time step used for harmonic analysis
+   INTEGER         ::   nitend_han    ! Last time step used for harmonic analysis
+   INTEGER         ::   nstep_han     ! Time step frequency for harmonic analysis
+   INTEGER         ::   nb_ana        ! Number of harmonics to analyse
 
    INTEGER , ALLOCATABLE, DIMENSION(:)       ::   name
@@ -53,5 +48,6 @@
    CHARACTER (LEN=4), DIMENSION(jpmax_harmo) ::   tname   ! Names of tidal constituents ('M2', 'K1',...)
 
-   PUBLIC   dia_harm   ! routine called by step.F90
+   PUBLIC   dia_harm        ! routine called by step.F90
+   PUBLIC   dia_harm_init   ! routine called by nemogcm.F90
 
    !!----------------------------------------------------------------------
@@ -71,8 +67,8 @@
       !!
       !!--------------------------------------------------------------------
-      INTEGER :: jh, nhan, jk, ji
+      INTEGER ::   jh, nhan, ji
       INTEGER ::   ios                 ! Local integer output status for namelist read
 
-      NAMELIST/nam_diaharm/ nit000_han, nitend_han, nstep_han, tname
+      NAMELIST/nam_diaharm/ ln_diaharm, nit000_han, nitend_han, nstep_han, tname
       !!----------------------------------------------------------------------
 
@@ -83,79 +79,84 @@
       ENDIF
       !
-      IF( .NOT. ln_tide )   CALL ctl_stop( 'dia_harm_init : ln_tide must be true for harmonic analysis')
-      !
-      CALL tide_init_Wave
-      !
       REWIND( numnam_ref )              ! Namelist nam_diaharm in reference namelist : Tidal harmonic analysis
       READ  ( numnam_ref, nam_diaharm, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_diaharm in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_diaharm in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist nam_diaharm in configuration namelist : Tidal harmonic analysis
       READ  ( numnam_cfg, nam_diaharm, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nam_diaharm in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nam_diaharm in configuration namelist' )
       IF(lwm) WRITE ( numond, nam_diaharm )
       !
       IF(lwp) THEN
-         WRITE(numout,*) 'First time step used for analysis:  nit000_han= ', nit000_han
-         WRITE(numout,*) 'Last  time step used for analysis:  nitend_han= ', nitend_han
-         WRITE(numout,*) 'Time step frequency for harmonic analysis:  nstep_han= ', nstep_han
+         WRITE(numout,*) 'Tidal diagnostics = ', ln_diaharm
+         WRITE(numout,*) '   First time step used for analysis:         nit000_han= ', nit000_han
+         WRITE(numout,*) '   Last  time step used for analysis:         nitend_han= ', nitend_han
+         WRITE(numout,*) '   Time step frequency for harmonic analysis: nstep_han = ', nstep_han
       ENDIF
 
-      ! Basic checks on harmonic analysis time window:
-      ! ----------------------------------------------
-      IF( nit000 > nit000_han )   CALL ctl_stop( 'dia_harm_init : nit000_han must be greater than nit000',   &
-         &                                       ' restart capability not implemented' )
-      IF( nitend < nitend_han )   CALL ctl_stop( 'dia_harm_init : nitend_han must be lower than nitend',   &
-         &                                       'restart capability not implemented' )
-
-      IF( MOD( nitend_han-nit000_han+1 , nstep_han ) /= 0 )   &
-         &                        CALL ctl_stop( 'dia_harm_init : analysis time span must be a multiple of nstep_han' )
-
-      nb_ana = 0
-      DO jk=1,jpmax_harmo
-         DO ji=1,jpmax_harmo
-            IF(TRIM(tname(jk)) == Wave(ji)%cname_tide) THEN
-               nb_ana=nb_ana+1
-            ENDIF
-         END DO
-      END DO
-      !
-      IF(lwp) THEN
-         WRITE(numout,*) '        Namelist nam_diaharm'
-         WRITE(numout,*) '        nb_ana    = ', nb_ana
-         CALL flush(numout)
+      IF( ln_diaharm .AND. .NOT.ln_tide )   CALL ctl_stop( 'dia_harm_init : ln_tide must be true for harmonic analysis')
+
+      IF( ln_diaharm ) THEN
+
+         CALL tide_init_Wave
+         !
+         ! Basic checks on harmonic analysis time window:
+         ! ----------------------------------------------
+         IF( nit000 > nit000_han )   CALL ctl_stop( 'dia_harm_init : nit000_han must be greater than nit000',   &
+            &                                       ' restart capability not implemented' )
+         IF( nitend < nitend_han )   CALL ctl_stop( 'dia_harm_init : nitend_han must be lower than nitend',   &
+            &                                       'restart capability not implemented' )
+
+         IF( MOD( nitend_han-nit000_han+1 , nstep_han ) /= 0 )   &
+            &                        CALL ctl_stop( 'dia_harm_init : analysis time span must be a multiple of nstep_han' )
+         !
+         nb_ana = 0
+         DO jh=1,jpmax_harmo
+            DO ji=1,jpmax_harmo
+               IF(TRIM(tname(jh)) == Wave(ji)%cname_tide) THEN
+                  nb_ana=nb_ana+1
+               ENDIF
+            END DO
+         END DO
+         !
+         IF(lwp) THEN
+            WRITE(numout,*) '        Namelist nam_diaharm'
+            WRITE(numout,*) '        nb_ana    = ', nb_ana
+            CALL flush(numout)
+         ENDIF
+         !
+         IF (nb_ana > jpmax_harmo) THEN
+            WRITE(ctmp1,*) ' nb_ana must be lower than jpmax_harmo'
+            WRITE(ctmp2,*) ' jpmax_harmo= ', jpmax_harmo
+            CALL ctl_stop( 'dia_harm_init', ctmp1, ctmp2 )
+         ENDIF
+
+         ALLOCATE(name    (nb_ana))
+         DO jh=1,nb_ana
+            DO ji=1,jpmax_harmo
+               IF (TRIM(tname(jh)) ==  Wave(ji)%cname_tide) THEN
+                  name(jh) = ji
+                  EXIT
+               END IF
+            END DO
+         END DO
+
+         ! Initialize frequency array:
+         ! ---------------------------
+         ALLOCATE( ana_freq(nb_ana), ut(nb_ana), vt(nb_ana), ft(nb_ana) )
+
+         CALL tide_harmo( ana_freq, vt, ut, ft, name, nb_ana )
+
+         IF(lwp) WRITE(numout,*) 'Analysed frequency  : ',nb_ana ,'Frequency '
+
+         DO jh = 1, nb_ana
+            IF(lwp) WRITE(numout,*) '                    : ',tname(jh),' ',ana_freq(jh)
+         END DO
+
+         ! Initialize temporary arrays:
+         ! ----------------------------
+         ALLOCATE( ana_temp(jpi,jpj,2*nb_ana,3) )
+         ana_temp(:,:,:,:) = 0._wp
+
       ENDIF
-      !
-      IF (nb_ana > jpmax_harmo) THEN
-         WRITE(ctmp1,*) ' nb_ana must be lower than jpmax_harmo'
-         WRITE(ctmp2,*) ' jpmax_harmo= ', jpmax_harmo
-         CALL ctl_stop( 'dia_harm_init', ctmp1, ctmp2 )
-      ENDIF
-
-      ALLOCATE(name    (nb_ana))
-      DO jk=1,nb_ana
-       DO ji=1,jpmax_harmo
-          IF (TRIM(tname(jk)) ==  Wave(ji)%cname_tide) THEN
-             name(jk) = ji
-             EXIT
-          END IF
-       END DO
-      END DO
-
-      ! Initialize frequency array:
-      ! ---------------------------
-      ALLOCATE( ana_freq(nb_ana), ut(nb_ana), vt(nb_ana), ft(nb_ana) )
-
-      CALL tide_harmo( ana_freq, vt, ut, ft, name, nb_ana )
-
-      IF(lwp) WRITE(numout,*) 'Analysed frequency  : ',nb_ana ,'Frequency '
-
-      DO jh = 1, nb_ana
-        IF(lwp) WRITE(numout,*) '                    : ',tname(jh),' ',ana_freq(jh)
-      END DO
-
-      ! Initialize temporary arrays:
-      ! ----------------------------
-      ALLOCATE( ana_temp(jpi,jpj,2*nb_ana,3) )
-      ana_temp(:,:,:,:) = 0._wp
 
    END SUBROUTINE dia_harm_init
@@ -177,6 +178,4 @@
       !!--------------------------------------------------------------------
       IF( ln_timing )   CALL timing_start('dia_harm')
-      !
-      IF( kt == nit000 )   CALL dia_harm_init
       !
       IF( kt >= nit000_han .AND. kt <= nitend_han .AND. MOD(kt,nstep_han) == 0 ) THEN
@@ -422,5 +421,5 @@
       INTEGER, INTENT(in) ::   init 
       !
-      INTEGER                         :: ji_sd, jj_sd, ji1_sd, ji2_sd, jk1_sd, jk2_sd
+      INTEGER                         :: ji_sd, jj_sd, ji1_sd, ji2_sd, jh1_sd, jh2_sd
       REAL(wp)                        :: zval1, zval2, zx1
       REAL(wp), DIMENSION(jpincomax) :: ztmpx, zcol1, zcol2
@@ -434,11 +433,11 @@
          ztmp3(:,:) = 0._wp
          !
-         DO jk1_sd = 1, nsparse
-            DO jk2_sd = 1, nsparse
-               nisparse(jk2_sd) = nisparse(jk2_sd)
-               njsparse(jk2_sd) = njsparse(jk2_sd)
-               IF( nisparse(jk2_sd) == nisparse(jk1_sd) ) THEN
-                  ztmp3(njsparse(jk1_sd),njsparse(jk2_sd)) = ztmp3(njsparse(jk1_sd),njsparse(jk2_sd))  &
-                     &                                     + valuesparse(jk1_sd)*valuesparse(jk2_sd)
+         DO jh1_sd = 1, nsparse
+            DO jh2_sd = 1, nsparse
+               nisparse(jh2_sd) = nisparse(jh2_sd)
+               njsparse(jh2_sd) = njsparse(jh2_sd)
+               IF( nisparse(jh2_sd) == nisparse(jh1_sd) ) THEN
+                  ztmp3(njsparse(jh1_sd),njsparse(jh2_sd)) = ztmp3(njsparse(jh1_sd),njsparse(jh2_sd))  &
+                     &                                     + valuesparse(jh1_sd)*valuesparse(jh2_sd)
                ENDIF
             END DO
@@ -515,16 +514,4 @@
    END SUBROUTINE SUR_DETERMINE
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Default case :   Empty module
-   !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER ::   lk_diaharm = .FALSE.
-CONTAINS
-   SUBROUTINE dia_harm ( kt )     ! Empty routine
-      INTEGER, INTENT( IN ) :: kt  
-      WRITE(*,*) 'dia_harm: you should not have seen this print'
-   END SUBROUTINE dia_harm
-#endif
-
    !!======================================================================
 END MODULE diaharm
Index: /NEMO/trunk/src/OCE/DIA/diahsb.F90
===================================================================
--- /NEMO/trunk/src/OCE/DIA/diahsb.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DIA/diahsb.F90	(revision 11536)
@@ -362,8 +362,8 @@
       REWIND( numnam_ref )              ! Namelist namhsb in reference namelist
       READ  ( numnam_ref, namhsb, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namhsb in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namhsb in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namhsb in configuration namelist
       READ  ( numnam_cfg, namhsb, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namhsb in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namhsb in configuration namelist' )
       IF(lwm) WRITE( numond, namhsb )
 
Index: /NEMO/trunk/src/OCE/DIA/diaptr.F90
===================================================================
--- /NEMO/trunk/src/OCE/DIA/diaptr.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DIA/diaptr.F90	(revision 11536)
@@ -393,9 +393,9 @@
       REWIND( numnam_ref )              ! Namelist namptr in reference namelist : Poleward transport
       READ  ( numnam_ref, namptr, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namptr in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namptr in reference namelist' )
 
       REWIND( numnam_cfg )              ! Namelist namptr in configuration namelist : Poleward transport
       READ  ( numnam_cfg, namptr, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namptr in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namptr in configuration namelist' )
       IF(lwm) WRITE ( numond, namptr )
 
Index: /NEMO/trunk/src/OCE/DIA/diatmb.F90
===================================================================
--- /NEMO/trunk/src/OCE/DIA/diatmb.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DIA/diatmb.F90	(revision 11536)
@@ -43,9 +43,9 @@
       REWIND( numnam_ref )              ! Read Namelist nam_diatmb in reference namelist : TMB diagnostics
       READ  ( numnam_ref, nam_diatmb, IOSTAT=ios, ERR= 901 )
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diatmb in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diatmb in reference namelist' )
  
       REWIND( numnam_cfg )              ! Namelist nam_diatmb in configuration namelist  TMB diagnostics
       READ  ( numnam_cfg, nam_diatmb, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nam_diatmb in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nam_diatmb in configuration namelist' )
       IF(lwm) WRITE ( numond, nam_diatmb )
 
Index: /NEMO/trunk/src/OCE/DIA/diawri.F90
===================================================================
--- /NEMO/trunk/src/OCE/DIA/diawri.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DIA/diawri.F90	(revision 11536)
@@ -430,5 +430,5 @@
       !!      define all the NETCDF files and fields
       !!      At each time step call histdef to compute the mean if ncessary
-      !!      Each nwrite time step, output the instantaneous or mean fields
+      !!      Each nn_write time step, output the instantaneous or mean fields
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
@@ -446,6 +446,4 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: zw3d       ! 3D workspace
       !!----------------------------------------------------------------------
-      ! 
-      IF( ln_timing )   CALL timing_start('dia_wri')
       !
       IF( ninist == 1 ) THEN     !==  Output the initial state and forcings  ==!
@@ -454,4 +452,8 @@
       ENDIF
       !
+      IF( nn_write == -1 )   RETURN   ! we will never do any output
+      ! 
+      IF( ln_timing )   CALL timing_start('dia_wri')
+      !
       ! 0. Initialisation
       ! -----------------
@@ -463,5 +465,5 @@
       clop = "x"         ! no use of the mask value (require less cpu time and otherwise the model crashes)
 #if defined key_diainstant
-      zsto = nwrite * rdt
+      zsto = nn_write * rdt
       clop = "inst("//TRIM(clop)//")"
 #else
@@ -469,5 +471,5 @@
       clop = "ave("//TRIM(clop)//")"
 #endif
-      zout = nwrite * rdt
+      zout = nn_write * rdt
       zmax = ( nitend - nit000 + 1 ) * rdt
 
@@ -500,5 +502,5 @@
          ! WRITE root name in date.file for use by postpro
          IF(lwp) THEN
-            CALL dia_nam( clhstnam, nwrite,' ' )
+            CALL dia_nam( clhstnam, nn_write,' ' )
             CALL ctl_opn( inum, 'date.file', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
             WRITE(inum,*) clhstnam
@@ -508,5 +510,5 @@
          ! Define the T grid FILE ( nid_T )
 
-         CALL dia_nam( clhstnam, nwrite, 'grid_T' )
+         CALL dia_nam( clhstnam, nn_write, 'grid_T' )
          IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
@@ -544,5 +546,5 @@
          ! Define the U grid FILE ( nid_U )
 
-         CALL dia_nam( clhstnam, nwrite, 'grid_U' )
+         CALL dia_nam( clhstnam, nn_write, 'grid_U' )
          IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
          CALL histbeg( clhstnam, jpi, glamu, jpj, gphiu,           &  ! Horizontal grid: glamu and gphiu
@@ -557,5 +559,5 @@
          ! Define the V grid FILE ( nid_V )
 
-         CALL dia_nam( clhstnam, nwrite, 'grid_V' )                   ! filename
+         CALL dia_nam( clhstnam, nn_write, 'grid_V' )                   ! filename
          IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
          CALL histbeg( clhstnam, jpi, glamv, jpj, gphiv,           &  ! Horizontal grid: glamv and gphiv
@@ -570,5 +572,5 @@
          ! Define the W grid FILE ( nid_W )
 
-         CALL dia_nam( clhstnam, nwrite, 'grid_W' )                   ! filename
+         CALL dia_nam( clhstnam, nn_write, 'grid_W' )                   ! filename
          IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
@@ -661,5 +663,5 @@
          ENDIF
 
-         IF( .NOT. ln_cpl ) THEN
+         IF( ln_ssr ) THEN
             CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
                &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
@@ -669,14 +671,5 @@
                &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
          ENDIF
-
-         IF( ln_cpl .AND. nn_ice <= 1 ) THEN
-            CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "sosafldp", "Surface salt flux: Damping"         , "Kg/m2/s",   &  ! erp * sn
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         ENDIF
-         
+       
          clmx ="l_max(only(x))"    ! max index on a period
 !         CALL histdef( nid_T, "sobowlin", "Bowl Index"                         , "W-point",   &  ! bowl INDEX 
@@ -754,5 +747,5 @@
       ! donne le nombre d'elements, et ndex la liste des indices a sortir
 
-      IF( lwp .AND. MOD( itmod, nwrite ) == 0 ) THEN 
+      IF( lwp .AND. MOD( itmod, nn_write ) == 0 ) THEN 
          WRITE(numout,*) 'dia_wri : write model outputs in NetCDF files at ', kt, 'time-step'
          WRITE(numout,*) '~~~~~~ '
@@ -818,14 +811,8 @@
       ENDIF
 
-      IF( .NOT. ln_cpl ) THEN
+      IF( ln_ssr ) THEN
          CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
          CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
-         IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
-         CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
-      ENDIF
-      IF( ln_cpl .AND. nn_ice <= 1 ) THEN
-         CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
-         CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
-         IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
+         zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
          CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
       ENDIF
Index: /NEMO/trunk/src/OCE/DIU/diurnal_bulk.F90
===================================================================
--- /NEMO/trunk/src/OCE/DIU/diurnal_bulk.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DIU/diurnal_bulk.F90	(revision 11536)
@@ -54,8 +54,8 @@
       REWIND( numnam_ref )
       READ  ( numnam_ref, namdiu, IOSTAT = ios, ERR = 901 )
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdiu in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdiu in reference namelist' )
       REWIND( numnam_cfg )
       READ  ( numnam_cfg, namdiu, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdiu in configuration namelist', lwp )      
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdiu in configuration namelist' )      
       !
       IF( ln_diurnal_only .AND. ( .NOT. ln_diurnal ) ) THEN
Index: /NEMO/trunk/src/OCE/DOM/domain.F90
===================================================================
--- /NEMO/trunk/src/OCE/DOM/domain.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DOM/domain.F90	(revision 11536)
@@ -101,5 +101,5 @@
          CASE( 0 )   ;   WRITE(numout,*) '         (i.e. closed)'
          CASE( 1 )   ;   WRITE(numout,*) '         (i.e. cyclic east-west)'
-         CASE( 2 )   ;   WRITE(numout,*) '         (i.e. equatorial symmetric)'
+         CASE( 2 )   ;   WRITE(numout,*) '         (i.e. cyclic north-south)'
          CASE( 3 )   ;   WRITE(numout,*) '         (i.e. north fold with T-point pivot)'
          CASE( 4 )   ;   WRITE(numout,*) '         (i.e. cyclic east-west and north fold with T-point pivot)'
@@ -308,8 +308,8 @@
       REWIND( numnam_ref )              ! Namelist namrun in reference namelist : Parameters of the run
       READ  ( numnam_ref, namrun, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namrun in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namrun in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namrun in configuration namelist : Parameters of the run
       READ  ( numnam_cfg, namrun, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namrun in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namrun in configuration namelist' )
       IF(lwm) WRITE ( numond, namrun )
       !
@@ -336,5 +336,7 @@
             WRITE(numout,*) '      frequency of restart file       nn_stock        = ', nn_stock
          ENDIF
+#if ! defined key_iomput
          WRITE(numout,*) '      frequency of output file        nn_write        = ', nn_write
+#endif
          WRITE(numout,*) '      mask land points                ln_mskland      = ', ln_mskland
          WRITE(numout,*) '      additional CF standard metadata ln_cfmeta       = ', ln_cfmeta
@@ -358,7 +360,4 @@
       nleapy = nn_leapy
       ninist = nn_istate
-      nstock = nn_stock
-      nstocklist = nn_stocklist
-      nwrite = nn_write
       neuler = nn_euler
       IF( neuler == 1 .AND. .NOT. ln_rstart ) THEN
@@ -369,14 +368,20 @@
       ENDIF
       !                             ! control of output frequency
-      IF( nstock == 0 .OR. nstock > nitend ) THEN
-         WRITE(ctmp1,*) 'nstock = ', nstock, ' it is forced to ', nitend
+      IF( .NOT. ln_rst_list ) THEN     ! we use nn_stock
+         IF( nn_stock == -1 )   CALL ctl_warn( 'nn_stock = -1 --> no restart will be done' )
+         IF( nn_stock == 0 .OR. nn_stock > nitend ) THEN
+            WRITE(ctmp1,*) 'nn_stock = ', nn_stock, ' it is forced to ', nitend
+            CALL ctl_warn( ctmp1 )
+            nn_stock = nitend
+         ENDIF
+      ENDIF
+#if ! defined key_iomput
+      IF( nn_write == -1 )   CALL ctl_warn( 'nn_write = -1 --> no output files will be done' )
+      IF ( nn_write == 0 ) THEN
+         WRITE(ctmp1,*) 'nn_write = ', nn_write, ' it is forced to ', nitend
          CALL ctl_warn( ctmp1 )
-         nstock = nitend
-      ENDIF
-      IF ( nwrite == 0 ) THEN
-         WRITE(ctmp1,*) 'nwrite = ', nwrite, ' it is forced to ', nitend
-         CALL ctl_warn( ctmp1 )
-         nwrite = nitend
-      ENDIF
+         nn_write = nitend
+      ENDIF
+#endif
 
 #if defined key_agrif
@@ -401,8 +406,8 @@
       REWIND( numnam_ref )              ! Namelist namdom in reference namelist : space & time domain (bathymetry, mesh, timestep)
       READ  ( numnam_ref, namdom, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdom in reference namelist', lwp )
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdom in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namdom in configuration namelist : space & time domain (bathymetry, mesh, timestep)
       READ  ( numnam_cfg, namdom, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdom in configuration namelist', lwp )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdom in configuration namelist' )
       IF(lwm) WRITE( numond, namdom )
       !
@@ -433,8 +438,8 @@
       REWIND( numnam_ref )              ! Namelist namnc4 in reference namelist : NETCDF
       READ  ( numnam_ref, namnc4, IOSTAT = ios, ERR = 907)
-907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namnc4 in reference namelist', lwp )
+907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namnc4 in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namnc4 in configuration namelist : NETCDF
       READ  ( numnam_cfg, namnc4, IOSTAT = ios, ERR = 908 )
-908   IF( ios >  0 )   CALL ctl_nam ( ios , 'namnc4 in configuration namelist', lwp )
+908   IF( ios >  0 )   CALL ctl_nam ( ios , 'namnc4 in configuration namelist' )
       IF(lwm) WRITE( numond, namnc4 )
 
@@ -511,5 +516,5 @@
 
 
-   SUBROUTINE domain_cfg( ldtxt, cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+   SUBROUTINE domain_cfg( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -519,5 +524,4 @@
       !! ** Method  :   read the cn_domcfg NetCDF file
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), DIMENSION(:), INTENT(out) ::   ldtxt           ! stored print information
       CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
       INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
@@ -525,13 +529,15 @@
       INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
       !
-      INTEGER ::   inum, ii   ! local integer
+      INTEGER ::   inum   ! local integer
       REAL(wp) ::   zorca_res                     ! local scalars
-      REAL(wp) ::   ziglo, zjglo, zkglo, zperio   !   -      -
-      !!----------------------------------------------------------------------
-      !
-      ii = 1
-      WRITE(ldtxt(ii),*) '           '                                                    ;   ii = ii+1
-      WRITE(ldtxt(ii),*) 'domain_cfg : domain size read in ', TRIM( cn_domcfg ), ' file'  ;   ii = ii+1
-      WRITE(ldtxt(ii),*) '~~~~~~~~~~ '                                                    ;   ii = ii+1
+      REAL(wp) ::   zperio                        !   -      -
+      INTEGER, DIMENSION(4) ::   idvar, idimsz    ! size   of dimensions
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) THEN
+         WRITE(numout,*) '           '
+         WRITE(numout,*) 'domain_cfg : domain size read in ', TRIM( cn_domcfg ), ' file'
+         WRITE(numout,*) '~~~~~~~~~~ '
+      ENDIF
       !
       CALL iom_open( cn_domcfg, inum )
@@ -544,7 +550,9 @@
          CALL iom_get( inum, 'ORCA_index', zorca_res )   ;   kk_cfg = NINT( zorca_res )
          !
-         WRITE(ldtxt(ii),*) '   .'                                                     ;   ii = ii+1
-         WRITE(ldtxt(ii),*) '   ==>>>   ORCA configuration '                           ;   ii = ii+1
-         WRITE(ldtxt(ii),*) '   .'                                                     ;   ii = ii+1
+         IF(lwp) THEN
+            WRITE(numout,*) '   .'
+            WRITE(numout,*) '   ==>>>   ORCA configuration '
+            WRITE(numout,*) '   .'
+         ENDIF
          !
       ELSE                                !- cd_cfg & k_cfg are not used
@@ -559,16 +567,19 @@
          !
       ENDIF
-      !
-      CALL iom_get( inum, 'jpiglo', ziglo  )   ;   kpi = NINT( ziglo )
-      CALL iom_get( inum, 'jpjglo', zjglo  )   ;   kpj = NINT( zjglo )
-      CALL iom_get( inum, 'jpkglo', zkglo  )   ;   kpk = NINT( zkglo )
+       !
+      idvar = iom_varid( inum, 'e3t_0', kdimsz = idimsz )   ! use e3t_0, that must exist, to get jp(ijk)glo
+      kpi = idimsz(1)
+      kpj = idimsz(2)
+      kpk = idimsz(3)
       CALL iom_get( inum, 'jperio', zperio )   ;   kperio = NINT( zperio )
       CALL iom_close( inum )
       !
-      WRITE(ldtxt(ii),*) '      cn_cfg = ', TRIM(cd_cfg), '   nn_cfg = ', kk_cfg             ;   ii = ii+1
-      WRITE(ldtxt(ii),*) '      jpiglo = ', kpi                                              ;   ii = ii+1
-      WRITE(ldtxt(ii),*) '      jpjglo = ', kpj                                              ;   ii = ii+1
-      WRITE(ldtxt(ii),*) '      jpkglo = ', kpk                                              ;   ii = ii+1
-      WRITE(ldtxt(ii),*) '      type of global domain lateral boundary   jperio = ', kperio  ;   ii = ii+1
+      IF(lwp) THEN
+         WRITE(numout,*) '      cn_cfg = ', TRIM(cd_cfg), '   nn_cfg = ', kk_cfg
+         WRITE(numout,*) '      jpiglo = ', kpi
+         WRITE(numout,*) '      jpjglo = ', kpj
+         WRITE(numout,*) '      jpkglo = ', kpk
+         WRITE(numout,*) '      type of global domain lateral boundary   jperio = ', kperio
+      ENDIF
       !        
    END SUBROUTINE domain_cfg
Index: /NEMO/trunk/src/OCE/DOM/dommsk.F90
===================================================================
--- /NEMO/trunk/src/OCE/DOM/dommsk.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DOM/dommsk.F90	(revision 11536)
@@ -100,14 +100,13 @@
          &             ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp, rn_time_dmp_out, &
          &             cn_ice, nn_ice_dta,                                     &
-         &             rn_ice_tem, rn_ice_sal, rn_ice_age,                     &
-         &             ln_vol, nn_volctl, nn_rimwidth, nb_jpk_bdy
+         &             ln_vol, nn_volctl, nn_rimwidth
       !!---------------------------------------------------------------------
       !
       REWIND( numnam_ref )              ! Namelist namlbc in reference namelist : Lateral momentum boundary condition
       READ  ( numnam_ref, namlbc, IOSTAT = ios, ERR = 901 )
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlbc in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlbc in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namlbc in configuration namelist : Lateral momentum boundary condition
       READ  ( numnam_cfg, namlbc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlbc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlbc in configuration namelist' )
       IF(lwm) WRITE ( numond, namlbc )
       
@@ -151,8 +150,8 @@
       REWIND( numnam_ref )              ! Namelist nambdy in reference namelist :Unstructured open boundaries
       READ  ( numnam_ref, nambdy, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy in reference namelist', lwp )
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist nambdy in configuration namelist :Unstructured open boundaries
       READ  ( numnam_cfg, nambdy, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'nambdy in configuration namelist', lwp )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'nambdy in configuration namelist' )
       ! ------------------------
       IF ( ln_bdy .AND. ln_mask_file ) THEN
Index: /NEMO/trunk/src/OCE/DOM/domvvl.F90
===================================================================
--- /NEMO/trunk/src/OCE/DOM/domvvl.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DOM/domvvl.F90	(revision 11536)
@@ -993,8 +993,8 @@
       REWIND( numnam_ref )              ! Namelist nam_vvl in reference namelist : 
       READ  ( numnam_ref, nam_vvl, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_vvl in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_vvl in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist nam_vvl in configuration namelist : Parameters of the run
       READ  ( numnam_cfg, nam_vvl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nam_vvl in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nam_vvl in configuration namelist' )
       IF(lwm) WRITE ( numond, nam_vvl )
       !
Index: /NEMO/trunk/src/OCE/DOM/dtatsd.F90
===================================================================
--- /NEMO/trunk/src/OCE/DOM/dtatsd.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DOM/dtatsd.F90	(revision 11536)
@@ -67,8 +67,8 @@
       REWIND( numnam_ref )              ! Namelist namtsd in reference namelist : 
       READ  ( numnam_ref, namtsd, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtsd in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtsd in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namtsd in configuration namelist : Parameters of the run
       READ  ( numnam_cfg, namtsd, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtsd in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtsd in configuration namelist' )
       IF(lwm) WRITE ( numond, namtsd )
 
Index: /NEMO/trunk/src/OCE/DOM/iscplhsb.F90
===================================================================
--- /NEMO/trunk/src/OCE/DOM/iscplhsb.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DOM/iscplhsb.F90	(revision 11536)
@@ -186,5 +186,5 @@
 !      CALL lbc_sum(pts_flx (:,:,:,jp_sal),'T',1.)
 !      CALL lbc_sum(pts_flx (:,:,:,jp_tem),'T',1.)
-      STOP ' iscpl_cons:   please modify this module !'
+      CALL ctl_stop( 'STOP', ' iscpl_cons:   please modify this MODULE !' )
 !!gm end
       ! if no neighbour wet cell in case of 2close a cell", need to find the nearest wet point 
Index: /NEMO/trunk/src/OCE/DOM/iscplini.F90
===================================================================
--- /NEMO/trunk/src/OCE/DOM/iscplini.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DOM/iscplini.F90	(revision 11536)
@@ -64,8 +64,8 @@
       REWIND( numnam_ref )              ! Namelist namsbc_iscpl in reference namelist : Ice sheet coupling
       READ  ( numnam_ref, namsbc_iscpl, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_iscpl in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_iscpl in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namsbc_iscpl in configuration namelist : Ice Sheet coupling
       READ  ( numnam_cfg, namsbc_iscpl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_iscpl in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_iscpl in configuration namelist' )
       IF(lwm) WRITE ( numond, namsbc_iscpl )
       !
Index: /NEMO/trunk/src/OCE/DYN/dynadv.F90
===================================================================
--- /NEMO/trunk/src/OCE/DYN/dynadv.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DYN/dynadv.F90	(revision 11536)
@@ -106,8 +106,8 @@
       REWIND( numnam_ref )              ! Namelist namdyn_adv in reference namelist : Momentum advection scheme
       READ  ( numnam_ref, namdyn_adv, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_adv in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_adv in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namdyn_adv in configuration namelist : Momentum advection scheme
       READ  ( numnam_cfg, namdyn_adv, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_adv in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_adv in configuration namelist' )
       IF(lwm) WRITE ( numond, namdyn_adv )
 
Index: /NEMO/trunk/src/OCE/DYN/dynhpg.F90
===================================================================
--- /NEMO/trunk/src/OCE/DYN/dynhpg.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DYN/dynhpg.F90	(revision 11536)
@@ -152,9 +152,9 @@
       REWIND( numnam_ref )              ! Namelist namdyn_hpg in reference namelist : Hydrostatic pressure gradient
       READ  ( numnam_ref, namdyn_hpg, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_hpg in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_hpg in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist namdyn_hpg in configuration namelist : Hydrostatic pressure gradient
       READ  ( numnam_cfg, namdyn_hpg, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_hpg in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_hpg in configuration namelist' )
       IF(lwm) WRITE ( numond, namdyn_hpg )
       !
Index: /NEMO/trunk/src/OCE/DYN/dynkeg.F90
===================================================================
--- /NEMO/trunk/src/OCE/DYN/dynkeg.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DYN/dynkeg.F90	(revision 11536)
@@ -74,10 +74,8 @@
       INTEGER, INTENT( in ) ::   kscheme   ! =0/1   type of KEG scheme 
       !
-      INTEGER  ::   ji, jj, jk, jb           ! dummy loop indices
-      INTEGER  ::   ifu, ifv, igrd, ib_bdy   ! local integers
+      INTEGER  ::   ji, jj, jk             ! dummy loop indices
       REAL(wp) ::   zu, zv                   ! local scalars
       REAL(wp), DIMENSION(jpi,jpj,jpk)        ::   zhke
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdu, ztrdv 
-      REAL(wp)  :: zweightu, zweightv
       !!----------------------------------------------------------------------
       !
@@ -112,29 +110,4 @@
             END DO
          END DO
-         !
-         IF (ln_bdy) THEN
-            ! Maria Luneva & Fred Wobus: July-2016
-            ! compensate for lack of turbulent kinetic energy on liquid bdy points
-            DO ib_bdy = 1, nb_bdy
-               IF( cn_dyn3d(ib_bdy) /= 'none' ) THEN
-                  igrd = 1           ! compensating null velocity on the bdy
-                  DO jb = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
-                     ji   = idx_bdy(ib_bdy)%nbi(jb,igrd)   ! maximum extent : from 2 to jpi-1
-                     jj   = idx_bdy(ib_bdy)%nbj(jb,igrd)   ! maximum extent : from 2 to jpj-1
-                     DO jk = 1, jpkm1
-                        zhke(ji,jj,jk) = 0._wp
-                        zweightu = umask(ji-1,jj  ,jk) + umask(ji,jj,jk)
-                        zweightv = vmask(ji  ,jj-1,jk) + vmask(ji,jj,jk)
-                        zu = un(ji-1,jj  ,jk) * un(ji-1,jj  ,jk)  +  un(ji  ,jj  ,jk) * un(ji  ,jj  ,jk)
-                        zv = vn(ji  ,jj-1,jk) * vn(ji  ,jj-1,jk)  +  vn(ji  ,jj  ,jk) * vn(ji  ,jj  ,jk)
-                        IF( zweightu > 0._wp )   zhke(ji,jj,jk) =  zhke(ji,jj,jk) + zu / (2._wp * zweightu) 
-                        IF( zweightv > 0._wp )   zhke(ji,jj,jk) =  zhke(ji,jj,jk) + zv / (2._wp * zweightv) 
-                     END DO
-                  END DO
-               END IF
-               CALL lbc_bdy_lnk( 'dynkeg', zhke, 'T', 1., ib_bdy )   ! send 2 and recv jpi, jpj used in the computation of the speed tendencies
-            END DO
-         END IF
-         !
       CASE ( nkeg_HW )                          !--  Hollingsworth scheme  --!
          DO jk = 1, jpkm1
@@ -154,34 +127,4 @@
             END DO
          END DO
-         IF (ln_bdy) THEN
-            ! Maria Luneva & Fred Wobus: July-2016
-            ! compensate for lack of turbulent kinetic energy on liquid bdy points
-            DO ib_bdy = 1, nb_bdy
-               IF( cn_dyn3d(ib_bdy) /= 'none' ) THEN
-                  igrd = 1           ! compensation null velocity on land at the bdy
-                  DO jb = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
-                     ji   = idx_bdy(ib_bdy)%nbi(jb,igrd)   ! maximum extent : from 2 to jpi-1
-                     jj   = idx_bdy(ib_bdy)%nbj(jb,igrd)   ! maximum extent : from 2 to jpj-1
-                     DO jk = 1, jpkm1
-                        zhke(ji,jj,jk) = 0._wp
-                        zweightu = 8._wp * ( umask(ji-1,jj  ,jk) + umask(ji  ,jj  ,jk) ) &
-                             &   + 2._wp * ( umask(ji-1,jj-1,jk) + umask(ji-1,jj+1,jk) + umask(ji  ,jj-1,jk) + umask(ji  ,jj+1,jk) ) 
-                        zweightv = 8._wp * ( vmask(ji  ,jj-1,jk) + vmask(ji  ,jj-1,jk) ) &
-                             &   + 2._wp * ( vmask(ji-1,jj-1,jk) + vmask(ji+1,jj-1,jk) + vmask(ji-1,jj  ,jk) + vmask(ji+1,jj  ,jk) )
-                        zu = 8._wp * ( un(ji-1,jj  ,jk) * un(ji-1,jj  ,jk)    &
-                           &         + un(ji  ,jj  ,jk) * un(ji  ,jj  ,jk) )  &
-                           &   +     ( un(ji-1,jj-1,jk) + un(ji-1,jj+1,jk) ) * ( un(ji-1,jj-1,jk) + un(ji-1,jj+1,jk) )   &
-                           &   +     ( un(ji  ,jj-1,jk) + un(ji  ,jj+1,jk) ) * ( un(ji  ,jj-1,jk) + un(ji  ,jj+1,jk) )
-                        zv = 8._wp * ( vn(ji  ,jj-1,jk) * vn(ji  ,jj-1,jk)    &
-                           &         + vn(ji  ,jj  ,jk) * vn(ji  ,jj  ,jk) )  &
-                           &  +      ( vn(ji-1,jj-1,jk) + vn(ji+1,jj-1,jk) ) * ( vn(ji-1,jj-1,jk) + vn(ji+1,jj-1,jk) )   &
-                           &  +      ( vn(ji-1,jj  ,jk) + vn(ji+1,jj  ,jk) ) * ( vn(ji-1,jj  ,jk) + vn(ji+1,jj  ,jk) )
-                        IF( zweightu > 0._wp )   zhke(ji,jj,jk) =  zhke(ji,jj,jk) +  zu / ( 2._wp * zweightu )
-                        IF( zweightv > 0._wp )   zhke(ji,jj,jk) =  zhke(ji,jj,jk) +  zv / ( 2._wp * zweightv )
-                     END DO
-                  END DO
-               END IF
-            END DO
-         END IF
          CALL lbc_lnk( 'dynkeg', zhke, 'T', 1. )
          !
Index: /NEMO/trunk/src/OCE/DYN/dynspg.F90
===================================================================
--- /NEMO/trunk/src/OCE/DYN/dynspg.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DYN/dynspg.F90	(revision 11536)
@@ -202,9 +202,9 @@
       REWIND( numnam_ref )              ! Namelist namdyn_spg in reference namelist : Free surface
       READ  ( numnam_ref, namdyn_spg, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_spg in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_spg in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist namdyn_spg in configuration namelist : Free surface
       READ  ( numnam_cfg, namdyn_spg, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_spg in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_spg in configuration namelist' )
       IF(lwm) WRITE ( numond, namdyn_spg )
       !
Index: /NEMO/trunk/src/OCE/DYN/dynspg_ts.F90
===================================================================
--- /NEMO/trunk/src/OCE/DYN/dynspg_ts.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DYN/dynspg_ts.F90	(revision 11536)
@@ -64,4 +64,6 @@
    USE diatmb          ! Top,middle,bottom output
 
+   USE iom   ! to remove
+
    IMPLICIT NONE
    PRIVATE
@@ -104,8 +106,6 @@
       !
       ALLOCATE( wgtbtp1(3*nn_baro), wgtbtp2(3*nn_baro), zwz(jpi,jpj), STAT=ierr(1) )
-      !
       IF( ln_dynvor_een .OR. ln_dynvor_eeT )   &
-         &     ALLOCATE( ftnw(jpi,jpj) , ftne(jpi,jpj) , & 
-         &               ftsw(jpi,jpj) , ftse(jpi,jpj) , STAT=ierr(2) )
+         &     ALLOCATE( ftnw(jpi,jpj) , ftne(jpi,jpj) , ftsw(jpi,jpj) , ftse(jpi,jpj), STAT=ierr(2)   )
          !
       ALLOCATE( un_adv(jpi,jpj), vn_adv(jpi,jpj)                    , STAT=ierr(3) )
@@ -149,18 +149,16 @@
       LOGICAL  ::   ll_fw_start           ! =T : forward integration 
       LOGICAL  ::   ll_init               ! =T : special startup of 2d equations
-      LOGICAL  ::   ll_tmp1, ll_tmp2      ! local logical variables used in W/D
-      INTEGER  ::   ikbu, iktu, noffset   ! local integers
-      INTEGER  ::   ikbv, iktv            !   -      -
-      REAL(wp) ::   r1_2dt_b, z2dt_bf               ! local scalars
-      REAL(wp) ::   zx1, zx2, zu_spg, zhura, z1_hu  !   -      -
-      REAL(wp) ::   zy1, zy2, zv_spg, zhvra, z1_hv  !   -      -
+      INTEGER  ::   noffset               ! local integers  : time offset for bdy update
+      REAL(wp) ::   r1_2dt_b, z1_hu, z1_hv          ! local scalars
       REAL(wp) ::   za0, za1, za2, za3              !   -      -
-      REAL(wp) ::   zmdi, zztmp            , z1_ht  !   -      -
-      REAL(wp), DIMENSION(jpi,jpj) :: zsshp2_e, zhf
-      REAL(wp), DIMENSION(jpi,jpj) :: zwx, zu_trd, zu_frc, zssh_frc
-      REAL(wp), DIMENSION(jpi,jpj) :: zwy, zv_trd, zv_frc, zhdiv
-      REAL(wp), DIMENSION(jpi,jpj) :: zsshu_a, zhup2_e, zhust_e, zhtp2_e
-      REAL(wp), DIMENSION(jpi,jpj) :: zsshv_a, zhvp2_e, zhvst_e
+      REAL(wp) ::   zmdi, zztmp, zldg               !   -      -
+      REAL(wp) ::   zhu_bck, zhv_bck, zhdiv         !   -      -
+      REAL(wp) ::   zun_save, zvn_save              !   -      -
+      REAL(wp), DIMENSION(jpi,jpj) :: zu_trd, zu_frc, zu_spg, zssh_frc
+      REAL(wp), DIMENSION(jpi,jpj) :: zv_trd, zv_frc, zv_spg
+      REAL(wp), DIMENSION(jpi,jpj) :: zsshu_a, zhup2_e, zhtp2_e
+      REAL(wp), DIMENSION(jpi,jpj) :: zsshv_a, zhvp2_e, zsshp2_e
       REAL(wp), DIMENSION(jpi,jpj) :: zCdU_u, zCdU_v   ! top/bottom stress at u- & v-points
+      REAL(wp), DIMENSION(jpi,jpj) :: zhU, zhV         ! fluxes
       !
       REAL(wp) ::   zwdramp                     ! local scalar - only used if ln_wd_dl = .True. 
@@ -182,9 +180,8 @@
       zwdramp = r_rn_wdmin1               ! simplest ramp 
 !     zwdramp = 1._wp / (rn_wdmin2 - rn_wdmin1) ! more general ramp
-      !                                         ! reciprocal of baroclinic time step 
-      IF( kt == nit000 .AND. neuler == 0 ) THEN   ;   z2dt_bf =          rdt
-      ELSE                                        ;   z2dt_bf = 2.0_wp * rdt
-      ENDIF
-      r1_2dt_b = 1.0_wp / z2dt_bf 
+      !                                         ! inverse of baroclinic time step 
+      IF( kt == nit000 .AND. neuler == 0 ) THEN   ;   r1_2dt_b = 1._wp / (         rdt )
+      ELSE                                        ;   r1_2dt_b = 1._wp / ( 2._wp * rdt )
+      ENDIF
       !
       ll_init     = ln_bt_av                    ! if no time averaging, then no specific restart 
@@ -210,134 +207,7 @@
             ll_fw_start =.FALSE.
          ENDIF
-         !
-         ! Set averaging weights and cycle length:
+         !                    ! Set averaging weights and cycle length:
          CALL ts_wgt( ln_bt_av, ll_fw_start, icycle, wgtbtp1, wgtbtp2 )
          !
-      ENDIF
-      !
-      IF( ln_isfcav ) THEN    ! top+bottom friction (ocean cavities)
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zCdU_u(ji,jj) = r1_2*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) + rCdU_top(ji+1,jj)+rCdU_top(ji,jj) )
-               zCdU_v(ji,jj) = r1_2*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) + rCdU_top(ji,jj+1)+rCdU_top(ji,jj) )
-            END DO
-         END DO
-      ELSE                    ! bottom friction only
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zCdU_u(ji,jj) = r1_2*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) )
-               zCdU_v(ji,jj) = r1_2*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) )
-            END DO
-         END DO
-      ENDIF
-      !
-      ! Set arrays to remove/compute coriolis trend.
-      ! Do it once at kt=nit000 if volume is fixed, else at each long time step.
-      ! Note that these arrays are also used during barotropic loop. These are however frozen
-      ! although they should be updated in the variable volume case. Not a big approximation.
-      ! To remove this approximation, copy lines below inside barotropic loop
-      ! and update depths at T-F points (ht and zhf resp.) at each barotropic time step
-      !
-      IF( kt == nit000 .OR. .NOT.ln_linssh ) THEN
-         !
-         SELECT CASE( nvor_scheme )
-         CASE( np_EEN )                != EEN scheme using e3f (energy & enstrophy scheme)
-            SELECT CASE( nn_een_e3f )              !* ff_f/e3 at F-point
-            CASE ( 0 )                                   ! original formulation  (masked averaging of e3t divided by 4)
-               DO jj = 1, jpjm1
-                  DO ji = 1, jpim1
-                     zwz(ji,jj) =   ( ht_n(ji  ,jj+1) + ht_n(ji+1,jj+1) +                    &
-                        &             ht_n(ji  ,jj  ) + ht_n(ji+1,jj  )   ) * 0.25_wp  
-                     IF( zwz(ji,jj) /= 0._wp )   zwz(ji,jj) = ff_f(ji,jj) / zwz(ji,jj)
-                  END DO
-               END DO
-            CASE ( 1 )                                   ! new formulation  (masked averaging of e3t divided by the sum of mask)
-               DO jj = 1, jpjm1
-                  DO ji = 1, jpim1
-                     zwz(ji,jj) =             (  ht_n  (ji  ,jj+1) + ht_n  (ji+1,jj+1)      &
-                        &                      + ht_n  (ji  ,jj  ) + ht_n  (ji+1,jj  )  )   &
-                        &       / ( MAX( 1._wp,  ssmask(ji  ,jj+1) + ssmask(ji+1,jj+1)      &
-                        &                      + ssmask(ji  ,jj  ) + ssmask(ji+1,jj  )  )   )
-                     IF( zwz(ji,jj) /= 0._wp )   zwz(ji,jj) = ff_f(ji,jj) / zwz(ji,jj)
-                  END DO
-               END DO
-            END SELECT
-            CALL lbc_lnk( 'dynspg_ts', zwz, 'F', 1._wp )
-            !
-            ftne(1,:) = 0._wp ; ftnw(1,:) = 0._wp ; ftse(1,:) = 0._wp ; ftsw(1,:) = 0._wp
-            DO jj = 2, jpj
-               DO ji = 2, jpi
-                  ftne(ji,jj) = zwz(ji-1,jj  ) + zwz(ji  ,jj  ) + zwz(ji  ,jj-1)
-                  ftnw(ji,jj) = zwz(ji-1,jj-1) + zwz(ji-1,jj  ) + zwz(ji  ,jj  )
-                  ftse(ji,jj) = zwz(ji  ,jj  ) + zwz(ji  ,jj-1) + zwz(ji-1,jj-1)
-                  ftsw(ji,jj) = zwz(ji  ,jj-1) + zwz(ji-1,jj-1) + zwz(ji-1,jj  )
-               END DO
-            END DO
-            !
-         CASE( np_EET )                  != EEN scheme using e3t (energy conserving scheme)
-            ftne(1,:) = 0._wp ; ftnw(1,:) = 0._wp ; ftse(1,:) = 0._wp ; ftsw(1,:) = 0._wp
-            DO jj = 2, jpj
-               DO ji = 2, jpi
-                  z1_ht = ssmask(ji,jj) / ( ht_n(ji,jj) + 1._wp - ssmask(ji,jj) )
-                  ftne(ji,jj) = ( ff_f(ji-1,jj  ) + ff_f(ji  ,jj  ) + ff_f(ji  ,jj-1) ) * z1_ht
-                  ftnw(ji,jj) = ( ff_f(ji-1,jj-1) + ff_f(ji-1,jj  ) + ff_f(ji  ,jj  ) ) * z1_ht
-                  ftse(ji,jj) = ( ff_f(ji  ,jj  ) + ff_f(ji  ,jj-1) + ff_f(ji-1,jj-1) ) * z1_ht
-                  ftsw(ji,jj) = ( ff_f(ji  ,jj-1) + ff_f(ji-1,jj-1) + ff_f(ji-1,jj  ) ) * z1_ht
-               END DO
-            END DO
-            !
-         CASE( np_ENE, np_ENS , np_MIX )  != all other schemes (ENE, ENS, MIX) except ENT !
-            !
-            zwz(:,:) = 0._wp
-            zhf(:,:) = 0._wp
-            
-!!gm  assume 0 in both cases (which is almost surely WRONG ! ) as hvatf has been removed 
-!!gm    A priori a better value should be something like :
-!!gm          zhf(i,j) = masked sum of  ht(i,j) , ht(i+1,j) , ht(i,j+1) , (i+1,j+1) 
-!!gm                     divided by the sum of the corresponding mask 
-!!gm 
-!!            
-            IF( .NOT.ln_sco ) THEN
-  
-   !!gm  agree the JC comment  : this should be done in a much clear way
-  
-   ! JC: It not clear yet what should be the depth at f-points over land in z-coordinate case
-   !     Set it to zero for the time being 
-   !              IF( rn_hmin < 0._wp ) THEN    ;   jk = - INT( rn_hmin )                                      ! from a nb of level
-   !              ELSE                          ;   jk = MINLOC( gdepw_0, mask = gdepw_0 > rn_hmin, dim = 1 )  ! from a depth
-   !              ENDIF
-   !              zhf(:,:) = gdepw_0(:,:,jk+1)
-               !
-            ELSE
-               !
-               !zhf(:,:) = hbatf(:,:)
-               DO jj = 1, jpjm1
-                  DO ji = 1, jpim1
-                     zhf(ji,jj) =    (   ht_0  (ji,jj  ) + ht_0  (ji+1,jj  )          &
-                        &              + ht_0  (ji,jj+1) + ht_0  (ji+1,jj+1)   )      &
-                        &       / MAX(   ssmask(ji,jj  ) + ssmask(ji+1,jj  )          &
-                        &              + ssmask(ji,jj+1) + ssmask(ji+1,jj+1) , 1._wp  )
-                  END DO
-               END DO
-            ENDIF
-            !
-            DO jj = 1, jpjm1
-               zhf(:,jj) = zhf(:,jj) * (1._wp- umask(:,jj,1) * umask(:,jj+1,1))
-            END DO
-            !
-            DO jk = 1, jpkm1
-               DO jj = 1, jpjm1
-                  zhf(:,jj) = zhf(:,jj) + e3f_n(:,jj,jk) * umask(:,jj,jk) * umask(:,jj+1,jk)
-               END DO
-            END DO
-            CALL lbc_lnk( 'dynspg_ts', zhf, 'F', 1._wp )
-            ! JC: TBC. hf should be greater than 0 
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  IF( zhf(ji,jj) /= 0._wp )   zwz(ji,jj) = 1._wp / zhf(ji,jj) ! zhf is actually hf here but it saves an array
-               END DO
-            END DO
-            zwz(:,:) = ff_f(:,:) * zwz(:,:)
-         END SELECT
       ENDIF
       !
@@ -348,4 +218,5 @@
          CALL ts_wgt( ln_bt_av, ll_fw_start, icycle, wgtbtp1, wgtbtp2 )
       ENDIF
+      !
                           
       ! -----------------------------------------------------------------------------
@@ -354,26 +225,14 @@
       !      
       !
-      !                                   !* e3*d/dt(Ua) (Vertically integrated)
-      !                                   ! --------------------------------------------------
-      zu_frc(:,:) = 0._wp
-      zv_frc(:,:) = 0._wp
-      !
-      DO jk = 1, jpkm1
-         zu_frc(:,:) = zu_frc(:,:) + e3u_n(:,:,jk) * ua(:,:,jk) * umask(:,:,jk)
-         zv_frc(:,:) = zv_frc(:,:) + e3v_n(:,:,jk) * va(:,:,jk) * vmask(:,:,jk)         
-      END DO
-      !
-      zu_frc(:,:) = zu_frc(:,:) * r1_hu_n(:,:)
-      zv_frc(:,:) = zv_frc(:,:) * r1_hv_n(:,:)
-      !
-      !
-      !                                   !* baroclinic momentum trend (remove the vertical mean trend)
-      DO jk = 1, jpkm1                    ! -----------------------------------------------------------
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ua(ji,jj,jk) = ua(ji,jj,jk) - zu_frc(ji,jj) * umask(ji,jj,jk)
-               va(ji,jj,jk) = va(ji,jj,jk) - zv_frc(ji,jj) * vmask(ji,jj,jk)
-            END DO
-         END DO
+      !                                   !=  zu_frc =  1/H e3*d/dt(Ua)  =!  (Vertical mean of Ua, the 3D trends)
+      !                                   !  ---------------------------  !
+      zu_frc(:,:) = SUM( e3u_n(:,:,:) * ua(:,:,:) * umask(:,:,:) , DIM=3 ) * r1_hu_n(:,:)
+      zv_frc(:,:) = SUM( e3v_n(:,:,:) * va(:,:,:) * vmask(:,:,:) , DIM=3 ) * r1_hv_n(:,:)
+      !
+      !
+      !                                   !=  Ua => baroclinic trend  =!   (remove its vertical mean)
+      DO jk = 1, jpkm1                    !  ------------------------  !
+         ua(:,:,jk) = ( ua(:,:,jk) - zu_frc(:,:) ) * umask(:,:,jk)
+         va(:,:,jk) = ( va(:,:,jk) - zv_frc(:,:) ) * vmask(:,:,jk)
       END DO
       
@@ -381,113 +240,23 @@
 !!gm  Is it correct to do so ?   I think so...
       
-      
-      !                                   !* barotropic Coriolis trends (vorticity scheme dependent)
-      !                                   ! --------------------------------------------------------
-      !
-      zwx(:,:) = un_b(:,:) * hu_n(:,:) * e2u(:,:)        ! now fluxes 
-      zwy(:,:) = vn_b(:,:) * hv_n(:,:) * e1v(:,:)
-      !
-      SELECT CASE( nvor_scheme )
-      CASE( np_ENT )                ! enstrophy conserving scheme (f-point)
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1   ! vector opt.
-               zu_trd(ji,jj) = + r1_4 * r1_e1e2u(ji,jj) * r1_hu_n(ji,jj)                    &
-                  &               * (  e1e2t(ji+1,jj)*ht_n(ji+1,jj)*ff_t(ji+1,jj) * ( vn_b(ji+1,jj) + vn_b(ji+1,jj-1) )   &
-                  &                  + e1e2t(ji  ,jj)*ht_n(ji  ,jj)*ff_t(ji  ,jj) * ( vn_b(ji  ,jj) + vn_b(ji  ,jj-1) )   )
-                  !
-               zv_trd(ji,jj) = - r1_4 * r1_e1e2v(ji,jj) * r1_hv_n(ji,jj)                    &
-                  &               * (  e1e2t(ji,jj+1)*ht_n(ji,jj+1)*ff_t(ji,jj+1) * ( un_b(ji,jj+1) + un_b(ji-1,jj+1) )   & 
-                  &                  + e1e2t(ji,jj  )*ht_n(ji,jj  )*ff_t(ji,jj  ) * ( un_b(ji,jj  ) + un_b(ji-1,jj  ) )   ) 
-            END DO  
-         END DO  
-         !         
-      CASE( np_ENE , np_MIX )        ! energy conserving scheme (t-point) ENE or MIX
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zy1 = ( zwy(ji,jj-1) + zwy(ji+1,jj-1) ) * r1_e1u(ji,jj)
-               zy2 = ( zwy(ji,jj  ) + zwy(ji+1,jj  ) ) * r1_e1u(ji,jj)
-               zx1 = ( zwx(ji-1,jj) + zwx(ji-1,jj+1) ) * r1_e2v(ji,jj)
-               zx2 = ( zwx(ji  ,jj) + zwx(ji  ,jj+1) ) * r1_e2v(ji,jj)
-               ! energy conserving formulation for planetary vorticity term
-               zu_trd(ji,jj) =   r1_4 * ( zwz(ji  ,jj-1) * zy1 + zwz(ji,jj) * zy2 )
-               zv_trd(ji,jj) = - r1_4 * ( zwz(ji-1,jj  ) * zx1 + zwz(ji,jj) * zx2 )
-            END DO
-         END DO
-         !
-      CASE( np_ENS )                ! enstrophy conserving scheme (f-point)
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zy1 =   r1_8 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) &
-                 &            + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) * r1_e1u(ji,jj)
-               zx1 = - r1_8 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) &
-                 &            + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) * r1_e2v(ji,jj)
-               zu_trd(ji,jj)  = zy1 * ( zwz(ji  ,jj-1) + zwz(ji,jj) )
-               zv_trd(ji,jj)  = zx1 * ( zwz(ji-1,jj  ) + zwz(ji,jj) )
-            END DO
-         END DO
-         !
-      CASE( np_EET , np_EEN )      ! energy & enstrophy scheme (using e3t or e3f)         
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zu_trd(ji,jj) = + r1_12 * r1_e1u(ji,jj) * (  ftne(ji,jj  ) * zwy(ji  ,jj  ) &
-                &                                         + ftnw(ji+1,jj) * zwy(ji+1,jj  ) &
-                &                                         + ftse(ji,jj  ) * zwy(ji  ,jj-1) &
-                &                                         + ftsw(ji+1,jj) * zwy(ji+1,jj-1) )
-               zv_trd(ji,jj) = - r1_12 * r1_e2v(ji,jj) * (  ftsw(ji,jj+1) * zwx(ji-1,jj+1) &
-                &                                         + ftse(ji,jj+1) * zwx(ji  ,jj+1) &
-                &                                         + ftnw(ji,jj  ) * zwx(ji-1,jj  ) &
-                &                                         + ftne(ji,jj  ) * zwx(ji  ,jj  ) )
-            END DO
-         END DO
-         !
-      END SELECT
-      !
-      !                                   !* Right-Hand-Side of the barotropic momentum equation
-      !                                   ! ----------------------------------------------------
-      IF( .NOT.ln_linssh ) THEN                 ! Variable volume : remove surface pressure gradient
-         IF( ln_wd_il ) THEN                        ! Calculating and applying W/D gravity filters
+      !                                   !=  remove 2D Coriolis and pressure gradient trends  =!
+      !                                   !  -------------------------------------------------  !
+      !
+      IF( kt == nit000 .OR. .NOT. ln_linssh )   CALL dyn_cor_2D_init   ! Set zwz, the barotropic Coriolis force coefficient
+      !       ! recompute zwz = f/depth  at every time step for (.NOT.ln_linssh) as the water colomn height changes
+      !
+      !                                         !* 2D Coriolis trends
+      zhU(:,:) = un_b(:,:) * hu_n(:,:) * e2u(:,:)        ! now fluxes 
+      zhV(:,:) = vn_b(:,:) * hv_n(:,:) * e1v(:,:)        ! NB: FULL domain : put a value in last row and column
+      !
+      CALL dyn_cor_2d( hu_n, hv_n, un_b, vn_b, zhU, zhV,  &   ! <<== in
+         &                               zu_trd, zv_trd   )   ! ==>> out
+      !
+      IF( .NOT.ln_linssh ) THEN                 !* surface pressure gradient   (variable volume only)
+         !
+         IF( ln_wd_il ) THEN                       ! W/D : limiter applied to spgspg
+            CALL wad_spg( sshn, zcpx, zcpy )          ! Calculating W/D gravity filters, zcpx and zcpy
             DO jj = 2, jpjm1
-               DO ji = 2, jpim1 
-                  ll_tmp1 = MIN(  sshn(ji,jj)               ,  sshn(ji+1,jj) ) >                &
-                     &      MAX( -ht_0(ji,jj)               , -ht_0(ji+1,jj) ) .AND.            &
-                     &      MAX(  sshn(ji,jj) + ht_0(ji,jj) ,  sshn(ji+1,jj) + ht_0(ji+1,jj) )  &
-                     &                                                         > rn_wdmin1 + rn_wdmin2
-                  ll_tmp2 = ( ABS( sshn(ji+1,jj)            -  sshn(ji  ,jj))  > 1.E-12 ).AND.( &
-                     &      MAX(   sshn(ji,jj)              ,  sshn(ji+1,jj) ) >                &
-                     &      MAX(  -ht_0(ji,jj)              , -ht_0(ji+1,jj) ) + rn_wdmin1 + rn_wdmin2 )
-                  IF(ll_tmp1) THEN
-                     zcpx(ji,jj) = 1.0_wp
-                  ELSEIF(ll_tmp2) THEN
-                     ! no worries about  sshn(ji+1,jj) -  sshn(ji  ,jj) = 0, it won't happen ! here
-                     zcpx(ji,jj) = ABS( (sshn(ji+1,jj) + ht_0(ji+1,jj) - sshn(ji,jj) - ht_0(ji,jj)) &
-                                 &    / (sshn(ji+1,jj) - sshn(ji  ,jj)) )
-                     zcpx(ji,jj) = max(min( zcpx(ji,jj) , 1.0_wp),0.0_wp)
-                  ELSE
-                     zcpx(ji,jj) = 0._wp
-                  ENDIF
-                  !
-                  ll_tmp1 = MIN(  sshn(ji,jj)               ,  sshn(ji,jj+1) ) >                &
-                     &      MAX( -ht_0(ji,jj)               , -ht_0(ji,jj+1) ) .AND.            &
-                     &      MAX(  sshn(ji,jj) + ht_0(ji,jj) ,  sshn(ji,jj+1) + ht_0(ji,jj+1) )  &
-                     &                                                       > rn_wdmin1 + rn_wdmin2
-                  ll_tmp2 = ( ABS( sshn(ji,jj)              -  sshn(ji,jj+1))  > 1.E-12 ).AND.( &
-                     &      MAX(   sshn(ji,jj)              ,  sshn(ji,jj+1) ) >                &
-                     &      MAX(  -ht_0(ji,jj)              , -ht_0(ji,jj+1) ) + rn_wdmin1 + rn_wdmin2 )
-  
-                  IF(ll_tmp1) THEN
-                     zcpy(ji,jj) = 1.0_wp
-                  ELSE IF(ll_tmp2) THEN
-                     ! no worries about  sshn(ji,jj+1) -  sshn(ji,jj  ) = 0, it won't happen ! here
-                     zcpy(ji,jj) = ABS( (sshn(ji,jj+1) + ht_0(ji,jj+1) - sshn(ji,jj) - ht_0(ji,jj)) &
-                        &             / (sshn(ji,jj+1) - sshn(ji,jj  )) )
-                     zcpy(ji,jj) = MAX(  0._wp , MIN( zcpy(ji,jj) , 1.0_wp )  )
-                  ELSE
-                     zcpy(ji,jj) = 0._wp
-                  ENDIF
-               END DO
-            END DO
-            !
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
+               DO ji = 2, jpim1                ! SPG with the application of W/D gravity filters
                   zu_trd(ji,jj) = zu_trd(ji,jj) - grav * ( sshn(ji+1,jj  ) - sshn(ji  ,jj ) )   &
                      &                          * r1_e1u(ji,jj) * zcpx(ji,jj)  * wdrampu(ji,jj)  !jth
@@ -496,7 +265,5 @@
                END DO
             END DO
-            !
-         ELSE
-            !
+         ELSE                                      ! now suface pressure gradient
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -516,75 +283,33 @@
       END DO 
       !
-      !                                         ! Add bottom stress contribution from baroclinic velocities:      
-      IF (ln_bt_fw) THEN
-         DO jj = 2, jpjm1                          
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ikbu = mbku(ji,jj)       
-               ikbv = mbkv(ji,jj)    
-               zwx(ji,jj) = un(ji,jj,ikbu) - un_b(ji,jj) ! NOW bottom baroclinic velocities
-               zwy(ji,jj) = vn(ji,jj,ikbv) - vn_b(ji,jj)
-            END DO
-         END DO
-      ELSE
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ikbu = mbku(ji,jj)       
-               ikbv = mbkv(ji,jj)    
-               zwx(ji,jj) = ub(ji,jj,ikbu) - ub_b(ji,jj) ! BEFORE bottom baroclinic velocities
-               zwy(ji,jj) = vb(ji,jj,ikbv) - vb_b(ji,jj)
-            END DO
-         END DO
-      ENDIF
-      !
-      ! Note that the "unclipped" bottom friction parameter is used even with explicit drag
-      IF( ln_wd_il ) THEN
-         zztmp = -1._wp / rdtbt
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zu_frc(ji,jj) = zu_frc(ji,jj) + & 
-               & MAX(r1_hu_n(ji,jj) * r1_2 * ( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) ), zztmp ) * zwx(ji,jj) *  wdrampu(ji,jj)
-               zv_frc(ji,jj) = zv_frc(ji,jj) + & 
-               & MAX(r1_hv_n(ji,jj) * r1_2 * ( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) ), zztmp ) * zwy(ji,jj) *  wdrampv(ji,jj)
-            END DO
-         END DO
-      ELSE
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zu_frc(ji,jj) = zu_frc(ji,jj) + r1_hu_n(ji,jj) * r1_2 * ( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) ) * zwx(ji,jj)
-               zv_frc(ji,jj) = zv_frc(ji,jj) + r1_hv_n(ji,jj) * r1_2 * ( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) ) * zwy(ji,jj)
-            END DO
-         END DO
-      END IF
-      !
-      IF( ln_isfcav ) THEN       ! Add TOP stress contribution from baroclinic velocities:      
-         IF( ln_bt_fw ) THEN
-            DO jj = 2, jpjm1
+      !                                   !=  Add bottom stress contribution from baroclinic velocities  =!
+      !                                   !  -----------------------------------------------------------  !
+      CALL dyn_drg_init( zu_frc, zv_frc,  zCdU_u, zCdU_v )      ! also provide the barotropic drag coefficients
+      !
+      !                                   !=  Add atmospheric pressure forcing  =!
+      !                                   !  ----------------------------------  !
+      IF( ln_apr_dyn ) THEN
+         IF( ln_bt_fw ) THEN                          ! FORWARD integration: use kt+1/2 pressure (NOW+1/2)
+            DO jj = 2, jpjm1              
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  iktu = miku(ji,jj)
-                  iktv = mikv(ji,jj)
-                  zwx(ji,jj) = un(ji,jj,iktu) - un_b(ji,jj) ! NOW top baroclinic velocities
-                  zwy(ji,jj) = vn(ji,jj,iktv) - vn_b(ji,jj)
-               END DO
-            END DO
-         ELSE
-            DO jj = 2, jpjm1
+                  zu_frc(ji,jj) = zu_frc(ji,jj) + grav * (  ssh_ib (ji+1,jj  ) - ssh_ib (ji,jj) ) * r1_e1u(ji,jj)
+                  zv_frc(ji,jj) = zv_frc(ji,jj) + grav * (  ssh_ib (ji  ,jj+1) - ssh_ib (ji,jj) ) * r1_e2v(ji,jj)
+               END DO
+            END DO
+         ELSE                                         ! CENTRED integration: use kt-1/2 + kt+1/2 pressure (NOW)
+            zztmp = grav * r1_2
+            DO jj = 2, jpjm1              
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  iktu = miku(ji,jj)
-                  iktv = mikv(ji,jj)
-                  zwx(ji,jj) = ub(ji,jj,iktu) - ub_b(ji,jj) ! BEFORE top baroclinic velocities
-                  zwy(ji,jj) = vb(ji,jj,iktv) - vb_b(ji,jj)
-               END DO
-            END DO
-         ENDIF
-         !
-         ! Note that the "unclipped" top friction parameter is used even with explicit drag
-         DO jj = 2, jpjm1              
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zu_frc(ji,jj) = zu_frc(ji,jj) + r1_hu_n(ji,jj) * r1_2 * ( rCdU_top(ji+1,jj)+rCdU_top(ji,jj) ) * zwx(ji,jj)
-               zv_frc(ji,jj) = zv_frc(ji,jj) + r1_hv_n(ji,jj) * r1_2 * ( rCdU_top(ji,jj+1)+rCdU_top(ji,jj) ) * zwy(ji,jj)
-            END DO
-         END DO
-      ENDIF
-      !       
+                  zu_frc(ji,jj) = zu_frc(ji,jj) + zztmp * (  ssh_ib (ji+1,jj  ) - ssh_ib (ji,jj)  &
+                       &                                   + ssh_ibb(ji+1,jj  ) - ssh_ibb(ji,jj)  ) * r1_e1u(ji,jj)
+                  zv_frc(ji,jj) = zv_frc(ji,jj) + zztmp * (  ssh_ib (ji  ,jj+1) - ssh_ib (ji,jj)  &
+                       &                                   + ssh_ibb(ji  ,jj+1) - ssh_ibb(ji,jj)  ) * r1_e2v(ji,jj)
+               END DO
+            END DO
+         ENDIF 
+      ENDIF
+      !
+      !                                   !=  Add atmospheric pressure forcing  =!
+      !                                   !  ----------------------------------  !
       IF( ln_bt_fw ) THEN                        ! Add wind forcing
          DO jj = 2, jpjm1
@@ -604,50 +329,28 @@
       ENDIF  
       !
-      IF( ln_apr_dyn ) THEN                     ! Add atm pressure forcing
-         IF( ln_bt_fw ) THEN
-            DO jj = 2, jpjm1              
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zu_spg =  grav * (  ssh_ib (ji+1,jj  ) - ssh_ib (ji,jj) ) * r1_e1u(ji,jj)
-                  zv_spg =  grav * (  ssh_ib (ji  ,jj+1) - ssh_ib (ji,jj) ) * r1_e2v(ji,jj)
-                  zu_frc(ji,jj) = zu_frc(ji,jj) + zu_spg
-                  zv_frc(ji,jj) = zv_frc(ji,jj) + zv_spg
-               END DO
-            END DO
-         ELSE
-            zztmp = grav * r1_2
-            DO jj = 2, jpjm1              
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zu_spg = zztmp * (  ssh_ib (ji+1,jj  ) - ssh_ib (ji,jj)    &
-                      &             + ssh_ibb(ji+1,jj  ) - ssh_ibb(ji,jj)  ) * r1_e1u(ji,jj)
-                  zv_spg = zztmp * (  ssh_ib (ji  ,jj+1) - ssh_ib (ji,jj)    &
-                      &             + ssh_ibb(ji  ,jj+1) - ssh_ibb(ji,jj)  ) * r1_e2v(ji,jj)
-                  zu_frc(ji,jj) = zu_frc(ji,jj) + zu_spg
-                  zv_frc(ji,jj) = zv_frc(ji,jj) + zv_spg
-               END DO
-            END DO
-         ENDIF 
-      ENDIF
-      !                                   !* Right-Hand-Side of the barotropic ssh equation
-      !                                   ! -----------------------------------------------
-      !                                         ! Surface net water flux and rivers
-      IF (ln_bt_fw) THEN
-         zssh_frc(:,:) = r1_rau0 * ( emp(:,:) - rnf(:,:) + fwfisf(:,:) )
-      ELSE
+      !              !----------------!
+      !              !==  sssh_frc  ==!   Right-Hand-Side of the barotropic ssh equation   (over the FULL domain)
+      !              !----------------!
+      !                                   !=  Net water flux forcing applied to a water column  =!
+      !                                   ! ---------------------------------------------------  !
+      IF (ln_bt_fw) THEN                          ! FORWARD integration: use kt+1/2 fluxes (NOW+1/2)
+         zssh_frc(:,:) = r1_rau0 * ( emp(:,:)             - rnf(:,:)              + fwfisf(:,:)                  )
+      ELSE                                        ! CENTRED integration: use kt-1/2 + kt+1/2 fluxes (NOW)
          zztmp = r1_rau0 * r1_2
-         zssh_frc(:,:) = zztmp * (  emp(:,:) + emp_b(:,:) - rnf(:,:) - rnf_b(:,:)   &
-                &                 + fwfisf(:,:) + fwfisf_b(:,:)                     )
-      ENDIF
-      !
-      IF( ln_sdw ) THEN                         ! Stokes drift divergence added if necessary
+         zssh_frc(:,:) = zztmp * (  emp(:,:) + emp_b(:,:) - rnf(:,:) - rnf_b(:,:) + fwfisf(:,:) + fwfisf_b(:,:)  )
+      ENDIF
+      !                                   !=  Add Stokes drift divergence  =!   (if exist)
+      IF( ln_sdw ) THEN                   !  -----------------------------  !
          zssh_frc(:,:) = zssh_frc(:,:) + div_sd(:,:)
       ENDIF
       !
 #if defined key_asminc
-      !                                         ! Include the IAU weighted SSH increment
+      !                                   !=  Add the IAU weighted SSH increment  =!
+      !                                   !  ------------------------------------  !
       IF( lk_asminc .AND. ln_sshinc .AND. ln_asmiau ) THEN
          zssh_frc(:,:) = zssh_frc(:,:) - ssh_iau(:,:)
       ENDIF
 #endif
-      !                                   !* Fill boundary data arrays for AGRIF
+      !                                   != Fill boundary data arrays for AGRIF
       !                                   ! ------------------------------------
 #if defined key_agrif
@@ -671,5 +374,10 @@
          vb_e   (:,:) = 0._wp
       ENDIF
-
+      !
+      IF( ln_linssh ) THEN    ! mid-step ocean depth is fixed (hup2_e=hu_n=hu_0)
+         zhup2_e(:,:) = hu_n(:,:)
+         zhvp2_e(:,:) = hv_n(:,:)
+         zhtp2_e(:,:) = ht_n(:,:)
+      ENDIF
       !
       IF (ln_bt_fw) THEN                  ! FORWARD integration: start from NOW fields                    
@@ -693,6 +401,4 @@
       ENDIF
       !
-      !
-      !
       ! Initialize sums:
       ua_b  (:,:) = 0._wp       ! After barotropic velocities (or transport if flux form)          
@@ -714,12 +420,13 @@
          !
          l_full_nf_update = jn == icycle   ! false: disable full North fold update (performances) for jn = 1 to icycle-1
-         !                                                !  ------------------
-         !                                                !* Update the forcing (BDY and tides)
-         !                                                !  ------------------
-         ! Update only tidal forcing at open boundaries
-         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:
+         !
+         !                    !==  Update the forcing ==! (BDY and tides)
+         !
+         IF( ln_bdy      .AND. ln_tide )   CALL bdy_dta_tides( kt, kit=jn, kt_offset= noffset+1 )
+         IF( ln_tide_pot .AND. ln_tide )   CALL upd_tide     ( kt, kit=jn, kt_offset= noffset   )
+         !
+         !                    !==  extrapolation at mid-step  ==!   (jn+1/2)
+         !
+         !                       !* Set extrapolation coefficients for predictor step:
          IF ((jn<3).AND.ll_init) THEN      ! Forward           
            za1 = 1._wp                                          
@@ -731,6 +438,9 @@
            za3 =  0.281105_wp              ! za3 = bet
          ENDIF
-
-         ! Extrapolate barotropic velocities at step jit+0.5:
+         !
+         !                       !* Extrapolate barotropic velocities at mid-step (jn+1/2)
+         !--        m+1/2               m                m-1           m-2       --!
+         !--       u      = (3/2+beta) u   -(1/2+2beta) u      + beta u          --!
+         !-------------------------------------------------------------------------!
          ua_e(:,:) = za1 * un_e(:,:) + za2 * ub_e(:,:) + za3 * ubb_e(:,:)
          va_e(:,:) = za1 * vn_e(:,:) + za2 * vb_e(:,:) + za3 * vbb_e(:,:)
@@ -739,64 +449,42 @@
             !                                             !  ------------------
             ! Extrapolate Sea Level at step jit+0.5:
+            !--         m+1/2                 m                  m-1             m-2       --!
+            !--      ssh      = (3/2+beta) ssh   -(1/2+2beta) ssh      + beta ssh          --!
+            !--------------------------------------------------------------------------------!
             zsshp2_e(:,:) = za1 * sshn_e(:,:)  + za2 * sshb_e(:,:) + za3 * sshbb_e(:,:)
             
-            ! set wetting & drying mask at tracer points for this barotropic sub-step 
-            IF ( ln_wd_dl ) THEN 
-               !
-               IF ( ln_wd_dl_rmp ) THEN 
-                  DO jj = 1, jpj                                 
-                     DO ji = 1, jpi   ! vector opt.  
-                        IF ( zsshp2_e(ji,jj) + ht_0(ji,jj) >  2._wp * rn_wdmin1 ) THEN 
-!                        IF ( zsshp2_e(ji,jj) + ht_0(ji,jj) >  rn_wdmin2 ) THEN 
-                           ztwdmask(ji,jj) = 1._wp
-                        ELSE IF ( zsshp2_e(ji,jj) + ht_0(ji,jj) >  rn_wdmin1 ) THEN
-                           ztwdmask(ji,jj) = (tanh(50._wp*( ( zsshp2_e(ji,jj) + ht_0(ji,jj) -  rn_wdmin1 )*r_rn_wdmin1)) ) 
-                        ELSE 
-                           ztwdmask(ji,jj) = 0._wp
-                        END IF
-                     END DO
-                  END DO
-               ELSE
-                  DO jj = 1, jpj                                 
-                     DO ji = 1, jpi   ! vector opt.  
-                        IF ( zsshp2_e(ji,jj) + ht_0(ji,jj) >  rn_wdmin1 ) THEN 
-                           ztwdmask(ji,jj) = 1._wp
-                        ELSE 
-                           ztwdmask(ji,jj) = 0._wp
-                        ENDIF
-                     END DO
-                  END DO
-               ENDIF 
-               !
-            ENDIF 
+            ! set wetting & drying mask at tracer points for this barotropic mid-step
+            IF( ln_wd_dl )   CALL wad_tmsk( zsshp2_e, ztwdmask )
             !
-            DO jj = 2, jpjm1                                    ! Sea Surface Height at u- & v-points
-               DO ji = 2, fs_jpim1   ! Vector opt.
-                  zwx(ji,jj) = r1_2 * ssumask(ji,jj)  * r1_e1e2u(ji,jj)     &
-                     &              * ( e1e2t(ji  ,jj) * zsshp2_e(ji  ,jj)  &
-                     &              +   e1e2t(ji+1,jj) * zsshp2_e(ji+1,jj) )
-                  zwy(ji,jj) = r1_2 * ssvmask(ji,jj)  * r1_e1e2v(ji,jj)     &
-                     &              * ( e1e2t(ji,jj  ) * zsshp2_e(ji,jj  )  &
-                     &              +   e1e2t(ji,jj+1) * zsshp2_e(ji,jj+1) )
-               END DO
-            END DO
-            CALL lbc_lnk_multi( 'dynspg_ts', zwx, 'U', 1._wp, zwy, 'V', 1._wp )
+            !                          ! ocean t-depth at mid-step
+            zhtp2_e(:,:) = ht_0(:,:) + zsshp2_e(:,:)
             !
-            zhup2_e(:,:) = hu_0(:,:) + zwx(:,:)                ! Ocean depth at U- and V-points
-            zhvp2_e(:,:) = hv_0(:,:) + zwy(:,:)
-            zhtp2_e(:,:) = ht_0(:,:) + zsshp2_e(:,:)
-         ELSE
-            zhup2_e(:,:) = hu_n(:,:)
-            zhvp2_e(:,:) = hv_n(:,:)
-            zhtp2_e(:,:) = ht_n(:,:)
-         ENDIF
-         !                                                !* after ssh
-         !                                                !  -----------
-         !
-         ! Enforce volume conservation at open boundaries:
+            !                          ! ocean u- and v-depth at mid-step   (separate DO-loops remove the need of a lbc_lnk)
+            DO jj = 1, jpj
+               DO ji = 1, jpim1   ! not jpi-column
+                  zhup2_e(ji,jj) = hu_0(ji,jj) + r1_2 * r1_e1e2u(ji,jj)                        &
+                       &                              * (  e1e2t(ji  ,jj) * zsshp2_e(ji  ,jj)  &
+                       &                                 + e1e2t(ji+1,jj) * zsshp2_e(ji+1,jj)  ) * ssumask(ji,jj)
+               END DO
+            END DO
+            DO jj = 1, jpjm1        ! not jpj-row
+               DO ji = 1, jpi
+                  zhvp2_e(ji,jj) = hv_0(ji,jj) + r1_2 * r1_e1e2v(ji,jj)                        &
+                       &                              * (  e1e2t(ji,jj  ) * zsshp2_e(ji,jj  )  &
+                       &                                 + e1e2t(ji,jj+1) * zsshp2_e(ji,jj+1)  ) * ssvmask(ji,jj)
+               END DO
+            END DO
+            !
+         ENDIF
+         !
+         !                    !==  after SSH  ==!   (jn+1)
+         !
+         !                             ! update (ua_e,va_e) to enforce volume conservation at open boundaries
+         !                             ! values of zhup2_e and zhvp2_e on the halo are not needed in bdy_vol2d
          IF( ln_bdy .AND. ln_vol ) CALL bdy_vol2d( kt, jn, ua_e, va_e, zhup2_e, zhvp2_e )
          !
-         zwx(:,:) = e2u(:,:) * ua_e(:,:) * zhup2_e(:,:)         ! fluxes at jn+0.5
-         zwy(:,:) = e1v(:,:) * va_e(:,:) * zhvp2_e(:,:)
+         !                             ! resulting flux at mid-step (not over the full domain)
+         zhU(1:jpim1,1:jpj  ) = e2u(1:jpim1,1:jpj  ) * ua_e(1:jpim1,1:jpj  ) * zhup2_e(1:jpim1,1:jpj  )   ! not jpi-column
+         zhV(1:jpi  ,1:jpjm1) = e1v(1:jpi  ,1:jpjm1) * va_e(1:jpi  ,1:jpjm1) * zhvp2_e(1:jpi  ,1:jpjm1)   ! not jpj-row
          !
 #if defined key_agrif
@@ -805,78 +493,60 @@
             IF((nbondi == -1).OR.(nbondi == 2)) THEN
                DO jj = 1, jpj
-                  zwx(2:nbghostcells+1,jj) = ubdy_w(1:nbghostcells,jj) * e2u(2:nbghostcells+1,jj)
-                  zwy(2:nbghostcells+1,jj) = vbdy_w(1:nbghostcells,jj) * e1v(2:nbghostcells+1,jj)
+                  zhU(2:nbghostcells+1,jj) = ubdy_w(1:nbghostcells,jj) * e2u(2:nbghostcells+1,jj)
+                  zhV(2:nbghostcells+1,jj) = vbdy_w(1:nbghostcells,jj) * e1v(2:nbghostcells+1,jj)
                END DO
             ENDIF
             IF((nbondi ==  1).OR.(nbondi == 2)) THEN
                DO jj=1,jpj
-                  zwx(nlci-nbghostcells-1:nlci-2,jj) = ubdy_e(1:nbghostcells,jj) * e2u(nlci-nbghostcells-1:nlci-2,jj)
-                  zwy(nlci-nbghostcells  :nlci-1,jj) = vbdy_e(1:nbghostcells,jj) * e1v(nlci-nbghostcells  :nlci-1,jj)
+                  zhU(nlci-nbghostcells-1:nlci-2,jj) = ubdy_e(1:nbghostcells,jj) * e2u(nlci-nbghostcells-1:nlci-2,jj)
+                  zhV(nlci-nbghostcells  :nlci-1,jj) = vbdy_e(1:nbghostcells,jj) * e1v(nlci-nbghostcells  :nlci-1,jj)
                END DO
             ENDIF
             IF((nbondj == -1).OR.(nbondj == 2)) THEN
                DO ji=1,jpi
-                  zwy(ji,2:nbghostcells+1) = vbdy_s(ji,1:nbghostcells) * e1v(ji,2:nbghostcells+1)
-                  zwx(ji,2:nbghostcells+1) = ubdy_s(ji,1:nbghostcells) * e2u(ji,2:nbghostcells+1)
+                  zhV(ji,2:nbghostcells+1) = vbdy_s(ji,1:nbghostcells) * e1v(ji,2:nbghostcells+1)
+                  zhU(ji,2:nbghostcells+1) = ubdy_s(ji,1:nbghostcells) * e2u(ji,2:nbghostcells+1)
                END DO
             ENDIF
             IF((nbondj ==  1).OR.(nbondj == 2)) THEN
                DO ji=1,jpi
-                  zwy(ji,nlcj-nbghostcells-1:nlcj-2) = vbdy_n(ji,1:nbghostcells) * e1v(ji,nlcj-nbghostcells-1:nlcj-2)
-                  zwx(ji,nlcj-nbghostcells  :nlcj-1) = ubdy_n(ji,1:nbghostcells) * e2u(ji,nlcj-nbghostcells  :nlcj-1)
+                  zhV(ji,nlcj-nbghostcells-1:nlcj-2) = vbdy_n(ji,1:nbghostcells) * e1v(ji,nlcj-nbghostcells-1:nlcj-2)
+                  zhU(ji,nlcj-nbghostcells  :nlcj-1) = ubdy_n(ji,1:nbghostcells) * e2u(ji,nlcj-nbghostcells  :nlcj-1)
                END DO
             ENDIF
          ENDIF
 #endif
-         IF( ln_wd_il )   CALL wad_lmt_bt(zwx, zwy, sshn_e, zssh_frc, rdtbt)
-
-         IF ( ln_wd_dl ) THEN 
-            !
-            ! un_e and vn_e are set to zero at faces where the direction of the flow is from dry cells 
-            !
-            DO jj = 1, jpjm1                                 
-               DO ji = 1, jpim1   
-                  IF ( zwx(ji,jj) > 0.0 ) THEN 
-                     zuwdmask(ji, jj) = ztwdmask(ji  ,jj) 
-                  ELSE 
-                     zuwdmask(ji, jj) = ztwdmask(ji+1,jj)  
-                  END IF 
-                  zwx(ji, jj) = zuwdmask(ji,jj)*zwx(ji, jj)
-                  un_e(ji,jj) = zuwdmask(ji,jj)*un_e(ji,jj)
-
-                  IF ( zwy(ji,jj) > 0.0 ) THEN
-                     zvwdmask(ji, jj) = ztwdmask(ji, jj  )
-                  ELSE 
-                     zvwdmask(ji, jj) = ztwdmask(ji, jj+1)  
-                  END IF 
-                  zwy(ji, jj) = zvwdmask(ji,jj)*zwy(ji,jj) 
-                  vn_e(ji,jj) = zvwdmask(ji,jj)*vn_e(ji,jj)
-               END DO
-            END DO
+         IF( ln_wd_il )   CALL wad_lmt_bt(zhU, zhV, sshn_e, zssh_frc, rdtbt)    !!gm wad_lmt_bt use of lbc_lnk on zhU, zhV
+
+         IF( ln_wd_dl ) THEN           ! un_e and vn_e are set to zero at faces where 
+            !                          ! the direction of the flow is from dry cells
+            CALL wad_Umsk( ztwdmask, zhU, zhV, un_e, vn_e, zuwdmask, zvwdmask )   ! not jpi colomn for U, not jpj row for V
             !
          ENDIF    
-         
-         ! Sum over sub-time-steps to compute advective velocities
-         za2 = wgtbtp2(jn)
-         un_adv(:,:) = un_adv(:,:) + za2 * zwx(:,:) * r1_e2u(:,:)
-         vn_adv(:,:) = vn_adv(:,:) + za2 * zwy(:,:) * r1_e1v(:,:)
-         
-         ! sum over sub-time-steps to decide which baroclinic velocities to set to zero (zuwdav2 is only used when ln_wd_dl_bc = True) 
+         !
+         !
+         !     Compute Sea Level at step jit+1
+         !--           m+1        m                               m+1/2          --!
+         !--        ssh    =  ssh   - delta_t' * [ frc + div( flux      ) ]      --!
+         !-------------------------------------------------------------------------!
+         DO jj = 2, jpjm1        ! INNER domain                             
+            DO ji = 2, jpim1
+               zhdiv = (   zhU(ji,jj) - zhU(ji-1,jj) + zhV(ji,jj) - zhV(ji,jj-1)   ) * r1_e1e2t(ji,jj)
+               ssha_e(ji,jj) = (  sshn_e(ji,jj) - rdtbt * ( zssh_frc(ji,jj) + zhdiv )  ) * ssmask(ji,jj)
+            END DO
+         END DO
+         !
+         CALL lbc_lnk_multi( 'dynspg_ts', ssha_e, 'T', 1._wp,  zhU, 'U', -1._wp,  zhV, 'V', -1._wp )
+         !
+         !                             ! Sum over sub-time-steps to compute advective velocities
+         za2 = wgtbtp2(jn)             ! zhU, zhV hold fluxes extrapolated at jn+0.5
+         un_adv(:,:) = un_adv(:,:) + za2 * zhU(:,:) * r1_e2u(:,:)
+         vn_adv(:,:) = vn_adv(:,:) + za2 * zhV(:,:) * r1_e1v(:,:)
+         ! sum over sub-time-steps to decide which baroclinic velocities to set to zero (zuwdav2 is only used when ln_wd_dl_bc=True) 
          IF ( ln_wd_dl_bc ) THEN
-            zuwdav2(:,:) = zuwdav2(:,:) + za2 * zuwdmask(:,:)
-            zvwdav2(:,:) = zvwdav2(:,:) + za2 * zvwdmask(:,:)
-         END IF 
-
-         ! Set next sea level:
-         DO jj = 2, jpjm1                                 
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zhdiv(ji,jj) = (   zwx(ji,jj) - zwx(ji-1,jj)   &
-                  &             + zwy(ji,jj) - zwy(ji,jj-1)   ) * r1_e1e2t(ji,jj)
-            END DO
-         END DO
-         ssha_e(:,:) = (  sshn_e(:,:) - rdtbt * ( zssh_frc(:,:) + zhdiv(:,:) )  ) * ssmask(:,:)
-         
-         CALL lbc_lnk( 'dynspg_ts', ssha_e, 'T',  1._wp )
-
+            zuwdav2(1:jpim1,1:jpj  ) = zuwdav2(1:jpim1,1:jpj  ) + za2 * zuwdmask(1:jpim1,1:jpj  )   ! not jpi-column
+            zvwdav2(1:jpi  ,1:jpjm1) = zvwdav2(1:jpi  ,1:jpjm1) + za2 * zvwdmask(1:jpi  ,1:jpjm1)   ! not jpj-row
+         END IF
+         !
          ! Duplicate sea level across open boundaries (this is only cosmetic if linssh=T)
          IF( ln_bdy )   CALL bdy_ssh( ssha_e )
@@ -887,5 +557,5 @@
          ! Sea Surface Height at u-,v-points (vvl case only)
          IF( .NOT.ln_linssh ) THEN                                
-            DO jj = 2, jpjm1
+            DO jj = 2, jpjm1   ! INNER domain, will be extended to whole domain later
                DO ji = 2, jpim1      ! NO Vector Opt.
                   zsshu_a(ji,jj) = r1_2 * ssumask(ji,jj) * r1_e1e2u(ji,jj)    &
@@ -897,96 +567,26 @@
                END DO
             END DO
-            CALL lbc_lnk_multi( 'dynspg_ts', zsshu_a, 'U', 1._wp, zsshv_a, 'V', 1._wp )
          ENDIF   
-         !                                 
-         ! Half-step back interpolation of SSH for surface pressure computation:
-         !----------------------------------------------------------------------
-         IF ((jn==1).AND.ll_init) THEN
-           za0=1._wp                        ! Forward-backward
-           za1=0._wp                           
-           za2=0._wp
-           za3=0._wp
-         ELSEIF ((jn==2).AND.ll_init) THEN  ! AB2-AM3 Coefficients; bet=0 ; gam=-1/6 ; eps=1/12
-           za0= 1.0833333333333_wp          ! za0 = 1-gam-eps
-           za1=-0.1666666666666_wp          ! za1 = gam
-           za2= 0.0833333333333_wp          ! za2 = eps
-           za3= 0._wp              
-         ELSE                               ! AB3-AM4 Coefficients; bet=0.281105 ; eps=0.013 ; gam=0.0880 
-            IF (rn_bt_alpha==0._wp) THEN
-               za0=0.614_wp                 ! za0 = 1/2 +   gam + 2*eps
-               za1=0.285_wp                 ! za1 = 1/2 - 2*gam - 3*eps
-               za2=0.088_wp                 ! za2 = gam
-               za3=0.013_wp                 ! za3 = eps
-            ELSE
-               zepsilon = 0.00976186_wp - 0.13451357_wp * rn_bt_alpha
-               zgamma = 0.08344500_wp - 0.51358400_wp * rn_bt_alpha
-               za0 = 0.5_wp + zgamma + 2._wp * rn_bt_alpha + 2._wp * zepsilon
-               za1 = 1._wp - za0 - zgamma - zepsilon
-               za2 = zgamma
-               za3 = zepsilon
-            ENDIF 
-         ENDIF
-         !
+         !         
+         ! Half-step back interpolation of SSH for surface pressure computation at step jit+1/2
+         !--            m+1/2           m+1              m               m-1              m-2     --!
+         !--        ssh'    =  za0 * ssh     +  za1 * ssh   +  za2 * ssh      +  za3 * ssh        --!
+         !------------------------------------------------------------------------------------------!
+         CALL ts_bck_interp( jn, ll_init, za0, za1, za2, za3 )   ! coeficients of the interpolation
          zsshp2_e(:,:) = za0 *  ssha_e(:,:) + za1 *  sshn_e (:,:)   &
             &          + za2 *  sshb_e(:,:) + za3 *  sshbb_e(:,:)
-         
-         IF( ln_wd_il ) THEN                   ! Calculating and applying W/D gravity filters
-           DO jj = 2, jpjm1
-              DO ji = 2, jpim1 
-                ll_tmp1 = MIN( zsshp2_e(ji,jj)               , zsshp2_e(ji+1,jj) ) >                &
-                     &    MAX(    -ht_0(ji,jj)               ,    -ht_0(ji+1,jj) ) .AND.            &
-                     &    MAX( zsshp2_e(ji,jj) + ht_0(ji,jj) , zsshp2_e(ji+1,jj) + ht_0(ji+1,jj) ) &
-                     &                                                             > rn_wdmin1 + rn_wdmin2
-                ll_tmp2 = (ABS(zsshp2_e(ji,jj)               - zsshp2_e(ji+1,jj))  > 1.E-12 ).AND.( &
-                     &    MAX( zsshp2_e(ji,jj)               , zsshp2_e(ji+1,jj) ) >                &
-                     &    MAX(    -ht_0(ji,jj)               ,    -ht_0(ji+1,jj) ) + rn_wdmin1 + rn_wdmin2 )
-   
-                IF(ll_tmp1) THEN
-                  zcpx(ji,jj) = 1.0_wp
-                ELSE IF(ll_tmp2) THEN
-                  ! no worries about  zsshp2_e(ji+1,jj) - zsshp2_e(ji  ,jj) = 0, it won't happen ! here
-                  zcpx(ji,jj) = ABS( (zsshp2_e(ji+1,jj) +     ht_0(ji+1,jj) - zsshp2_e(ji,jj) - ht_0(ji,jj)) &
-                              &    / (zsshp2_e(ji+1,jj) - zsshp2_e(ji  ,jj)) )
-                ELSE
-                  zcpx(ji,jj) = 0._wp
-                ENDIF
-                !
-                ll_tmp1 = MIN( zsshp2_e(ji,jj)               , zsshp2_e(ji,jj+1) ) >                &
-                     &    MAX(    -ht_0(ji,jj)               ,    -ht_0(ji,jj+1) ) .AND.            &
-                     &    MAX( zsshp2_e(ji,jj) + ht_0(ji,jj) , zsshp2_e(ji,jj+1) + ht_0(ji,jj+1) ) &
-                     &                                                             > rn_wdmin1 + rn_wdmin2
-                ll_tmp2 = (ABS(zsshp2_e(ji,jj)               - zsshp2_e(ji,jj+1))  > 1.E-12 ).AND.( &
-                     &    MAX( zsshp2_e(ji,jj)               , zsshp2_e(ji,jj+1) ) >                &
-                     &    MAX(    -ht_0(ji,jj)               ,    -ht_0(ji,jj+1) ) + rn_wdmin1 + rn_wdmin2 )
-   
-                IF(ll_tmp1) THEN
-                  zcpy(ji,jj) = 1.0_wp
-                ELSEIF(ll_tmp2) THEN
-                  ! no worries about  zsshp2_e(ji,jj+1) - zsshp2_e(ji,jj  ) = 0, it won't happen ! here
-                  zcpy(ji,jj) = ABS( (zsshp2_e(ji,jj+1) +     ht_0(ji,jj+1) - zsshp2_e(ji,jj) - ht_0(ji,jj)) &
-                              &    / (zsshp2_e(ji,jj+1) - zsshp2_e(ji,jj  )) )
-                ELSE
-                  zcpy(ji,jj) = 0._wp
-                ENDIF
-              END DO
-           END DO
-         ENDIF
-         !
-         ! Compute associated depths at U and V points:
-         IF( .NOT.ln_linssh  .AND. .NOT.ln_dynadv_vec ) THEN     !* Vector form
-            !                                        
-            DO jj = 2, jpjm1                            
-               DO ji = 2, jpim1
-                  zx1 = r1_2 * ssumask(ji  ,jj) *  r1_e1e2u(ji  ,jj)    &
-                     &      * ( e1e2t(ji  ,jj  ) * zsshp2_e(ji  ,jj)    &
-                     &      +   e1e2t(ji+1,jj  ) * zsshp2_e(ji+1,jj  ) )
-                  zy1 = r1_2 * ssvmask(ji  ,jj) *  r1_e1e2v(ji  ,jj  )  &
-                     &       * ( e1e2t(ji ,jj  ) * zsshp2_e(ji  ,jj  )  &
-                     &       +   e1e2t(ji ,jj+1) * zsshp2_e(ji  ,jj+1) )
-                  zhust_e(ji,jj) = hu_0(ji,jj) + zx1 
-                  zhvst_e(ji,jj) = hv_0(ji,jj) + zy1
-               END DO
-            END DO
-            !
+         !
+         !                             ! Surface pressure gradient
+         zldg = ( 1._wp - rn_scal_load ) * grav    ! local factor
+         DO jj = 2, jpjm1                            
+            DO ji = 2, jpim1
+               zu_spg(ji,jj) = - zldg * ( zsshp2_e(ji+1,jj) - zsshp2_e(ji,jj) ) * r1_e1u(ji,jj)
+               zv_spg(ji,jj) = - zldg * ( zsshp2_e(ji,jj+1) - zsshp2_e(ji,jj) ) * r1_e2v(ji,jj)
+            END DO
+         END DO
+         IF( ln_wd_il ) THEN        ! W/D : gravity filters applied on pressure gradient
+            CALL wad_spg( zsshp2_e, zcpx, zcpy )   ! Calculating W/D gravity filters
+            zu_spg(2:jpim1,2:jpjm1) = zu_spg(2:jpim1,2:jpjm1) * zcpx(2:jpim1,2:jpjm1)
+            zv_spg(2:jpim1,2:jpjm1) = zv_spg(2:jpim1,2:jpjm1) * zcpy(2:jpim1,2:jpjm1)
          ENDIF
          !
@@ -994,65 +594,6 @@
          ! zwz array below or triads normally depend on sea level with ln_linssh=F and should be updated
          ! at each time step. We however keep them constant here for optimization.
-         ! Recall that zwx and zwy arrays hold fluxes at this stage:
-         ! zwx(:,:) = e2u(:,:) * ua_e(:,:) * zhup2_e(:,:)   ! fluxes at jn+0.5
-         ! zwy(:,:) = e1v(:,:) * va_e(:,:) * zhvp2_e(:,:)
-         !
-         SELECT CASE( nvor_scheme )
-         CASE( np_ENT )             ! energy conserving scheme (t-point)
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1   ! vector opt.
-
-               z1_hu = ssumask(ji,jj) / ( zhup2_e(ji,jj) + 1._wp - ssumask(ji,jj) )
-               z1_hv = ssvmask(ji,jj) / ( zhvp2_e(ji,jj) + 1._wp - ssvmask(ji,jj) )
-            
-               zu_trd(ji,jj) = + r1_4 * r1_e1e2u(ji,jj) * z1_hu                   &
-                  &               * (  e1e2t(ji+1,jj)*zhtp2_e(ji+1,jj)*ff_t(ji+1,jj) * ( va_e(ji+1,jj) + va_e(ji+1,jj-1) )   &
-                  &                  + e1e2t(ji  ,jj)*zhtp2_e(ji  ,jj)*ff_t(ji  ,jj) * ( va_e(ji  ,jj) + va_e(ji  ,jj-1) )   )
-                  !
-               zv_trd(ji,jj) = - r1_4 * r1_e1e2v(ji,jj) * z1_hv                    &
-                  &               * (  e1e2t(ji,jj+1)*zhtp2_e(ji,jj+1)*ff_t(ji,jj+1) * ( ua_e(ji,jj+1) + ua_e(ji-1,jj+1) )   & 
-                  &                  + e1e2t(ji,jj  )*zhtp2_e(ji,jj  )*ff_t(ji,jj  ) * ( ua_e(ji,jj  ) + ua_e(ji-1,jj  ) )   ) 
-            END DO  
-         END DO  
-         !         
-         CASE( np_ENE, np_MIX )     ! energy conserving scheme (f-point)
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zy1 = ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) ) * r1_e1u(ji,jj)
-                  zy2 = ( zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) * r1_e1u(ji,jj)
-                  zx1 = ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) ) * r1_e2v(ji,jj)
-                  zx2 = ( zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) * r1_e2v(ji,jj)
-                  zu_trd(ji,jj) = r1_4 * ( zwz(ji  ,jj-1) * zy1 + zwz(ji,jj) * zy2 )
-                  zv_trd(ji,jj) =-r1_4 * ( zwz(ji-1,jj  ) * zx1 + zwz(ji,jj) * zx2 )
-               END DO
-            END DO
-            !
-         CASE( np_ENS )             ! enstrophy conserving scheme (f-point)
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zy1 =   r1_8 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) &
-                   &             + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) * r1_e1u(ji,jj)
-                  zx1 = - r1_8 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) &
-                   &             + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) * r1_e2v(ji,jj)
-                  zu_trd(ji,jj)  = zy1 * ( zwz(ji  ,jj-1) + zwz(ji,jj) )
-                  zv_trd(ji,jj)  = zx1 * ( zwz(ji-1,jj  ) + zwz(ji,jj) )
-               END DO
-            END DO
-            !
-         CASE( np_EET , np_EEN )   ! energy & enstrophy scheme (using e3t or e3f)
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zu_trd(ji,jj) = + r1_12 * r1_e1u(ji,jj) * (  ftne(ji,jj  ) * zwy(ji  ,jj  )  &
-                     &                                       + ftnw(ji+1,jj) * zwy(ji+1,jj  )  &
-                     &                                       + ftse(ji,jj  ) * zwy(ji  ,jj-1)  & 
-                     &                                       + ftsw(ji+1,jj) * zwy(ji+1,jj-1)  )
-                  zv_trd(ji,jj) = - r1_12 * r1_e2v(ji,jj) * (  ftsw(ji,jj+1) * zwx(ji-1,jj+1)  & 
-                     &                                       + ftse(ji,jj+1) * zwx(ji  ,jj+1)  &
-                     &                                       + ftnw(ji,jj  ) * zwx(ji-1,jj  )  & 
-                     &                                       + ftne(ji,jj  ) * zwx(ji  ,jj  )  )
-               END DO
-            END DO
-            ! 
-         END SELECT
+         ! Recall that zhU and zhV hold fluxes at jn+0.5 (extrapolated not backward interpolated)
+         CALL dyn_cor_2d( zhup2_e, zhvp2_e, ua_e, va_e, zhU, zhV,    zu_trd, zv_trd   )
          !
          ! Add tidal astronomical forcing if defined
@@ -1060,8 +601,6 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zu_spg = grav * ( pot_astro(ji+1,jj) - pot_astro(ji,jj) ) * r1_e1u(ji,jj)
-                  zv_spg = grav * ( pot_astro(ji,jj+1) - pot_astro(ji,jj) ) * r1_e2v(ji,jj)
-                  zu_trd(ji,jj) = zu_trd(ji,jj) + zu_spg
-                  zv_trd(ji,jj) = zv_trd(ji,jj) + zv_spg
+                  zu_trd(ji,jj) = zu_trd(ji,jj) + grav * ( pot_astro(ji+1,jj) - pot_astro(ji,jj) ) * r1_e1u(ji,jj)
+                  zv_trd(ji,jj) = zv_trd(ji,jj) + grav * ( pot_astro(ji,jj+1) - pot_astro(ji,jj) ) * r1_e2v(ji,jj)
                END DO
             END DO
@@ -1077,36 +616,22 @@
                END DO
             END DO
-         ENDIF 
-         !
-         ! Surface pressure trend:
-         IF( ln_wd_il ) THEN
-           DO jj = 2, jpjm1
-              DO ji = 2, jpim1 
-                 ! Add surface pressure gradient
-                 zu_spg = - grav * ( zsshp2_e(ji+1,jj) - zsshp2_e(ji,jj) ) * r1_e1u(ji,jj)
-                 zv_spg = - grav * ( zsshp2_e(ji,jj+1) - zsshp2_e(ji,jj) ) * r1_e2v(ji,jj)
-                 zwx(ji,jj) = (1._wp - rn_scal_load) * zu_spg * zcpx(ji,jj) 
-                 zwy(ji,jj) = (1._wp - rn_scal_load) * zv_spg * zcpy(ji,jj)
-              END DO
-           END DO
-         ELSE
-           DO jj = 2, jpjm1
-              DO ji = fs_2, fs_jpim1   ! vector opt.
-                 ! Add surface pressure gradient
-                 zu_spg = - grav * ( zsshp2_e(ji+1,jj) - zsshp2_e(ji,jj) ) * r1_e1u(ji,jj)
-                 zv_spg = - grav * ( zsshp2_e(ji,jj+1) - zsshp2_e(ji,jj) ) * r1_e2v(ji,jj)
-                 zwx(ji,jj) = (1._wp - rn_scal_load) * zu_spg
-                 zwy(ji,jj) = (1._wp - rn_scal_load) * zv_spg
-              END DO
-           END DO
-         END IF
-
+         ENDIF
          !
          ! Set next velocities:
+         !     Compute barotropic speeds at step jit+1    (h : total height of the water colomn)
+         !--                              VECTOR FORM
+         !--   m+1                 m               /                                                       m+1/2           \    --!
+         !--  u     =             u   + delta_t' * \         (1-r)*g * grad_x( ssh') -         f * k vect u      +     frc /    --!
+         !--                                                                                                                    --!
+         !--                             FLUX FORM                                                                              --!
+         !--  m+1   __1__  /  m    m               /  m+1/2                             m+1/2              m+1/2    n      \ \  --!
+         !-- u    =   m+1 |  h  * u   + delta_t' * \ h     * (1-r)*g * grad_x( ssh') - h     * f * k vect u      + h * frc /  | --!
+         !--         h     \                                                                                                 /  --!
+         !------------------------------------------------------------------------------------------------------------------------!
          IF( ln_dynadv_vec .OR. ln_linssh ) THEN      !* Vector form
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   ua_e(ji,jj) = (                                 un_e(ji,jj)   & 
-                            &     + rdtbt * (                      zwx(ji,jj)   &
+                            &     + rdtbt * (                   zu_spg(ji,jj)   &
                             &                                 + zu_trd(ji,jj)   &
                             &                                 + zu_frc(ji,jj) ) & 
@@ -1114,9 +639,8 @@
 
                   va_e(ji,jj) = (                                 vn_e(ji,jj)   &
-                            &     + rdtbt * (                      zwy(ji,jj)   &
+                            &     + rdtbt * (                   zv_spg(ji,jj)   &
                             &                                 + zv_trd(ji,jj)   &
                             &                                 + zv_frc(ji,jj) ) &
                             &   ) * ssvmask(ji,jj)
- 
                END DO
             END DO
@@ -1124,23 +648,24 @@
          ELSE                           !* Flux form
             DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-
-                  zhura = hu_0(ji,jj) + zsshu_a(ji,jj)
-                  zhvra = hv_0(ji,jj) + zsshv_a(ji,jj)
-
-                  zhura = ssumask(ji,jj)/(zhura + 1._wp - ssumask(ji,jj))
-                  zhvra = ssvmask(ji,jj)/(zhvra + 1._wp - ssvmask(ji,jj))
-
-                  ua_e(ji,jj) = (                hu_e(ji,jj)  *   un_e(ji,jj)   & 
-                            &     + rdtbt * ( zhust_e(ji,jj)  *    zwx(ji,jj)   & 
-                            &               + zhup2_e(ji,jj)  * zu_trd(ji,jj)   &
-                            &               +    hu_n(ji,jj)  * zu_frc(ji,jj) ) &
-                            &   ) * zhura
-
-                  va_e(ji,jj) = (                hv_e(ji,jj)  *   vn_e(ji,jj)   &
-                            &     + rdtbt * ( zhvst_e(ji,jj)  *    zwy(ji,jj)   &
-                            &               + zhvp2_e(ji,jj)  * zv_trd(ji,jj)   &
-                            &               +    hv_n(ji,jj)  * zv_frc(ji,jj) ) &
-                            &   ) * zhvra
+               DO ji = 2, jpim1
+                  !                    ! hu_e, hv_e hold depth at jn,  zhup2_e, zhvp2_e hold extrapolated depth at jn+1/2
+                  !                    ! backward interpolated depth used in spg terms at jn+1/2
+                  zhu_bck = hu_0(ji,jj) + r1_2*r1_e1e2u(ji,jj) * (  e1e2t(ji  ,jj) * zsshp2_e(ji  ,jj)    &
+                       &                                          + e1e2t(ji+1,jj) * zsshp2_e(ji+1,jj)  ) * ssumask(ji,jj)
+                  zhv_bck = hv_0(ji,jj) + r1_2*r1_e1e2v(ji,jj) * (  e1e2t(ji,jj  ) * zsshp2_e(ji,jj  )    &
+                       &                                          + e1e2t(ji,jj+1) * zsshp2_e(ji,jj+1)  ) * ssvmask(ji,jj)
+                  !                    ! inverse depth at jn+1
+                  z1_hu = ssumask(ji,jj) / ( hu_0(ji,jj) + zsshu_a(ji,jj) + 1._wp - ssumask(ji,jj) )
+                  z1_hv = ssvmask(ji,jj) / ( hv_0(ji,jj) + zsshv_a(ji,jj) + 1._wp - ssvmask(ji,jj) )
+                  !
+                  ua_e(ji,jj) = (               hu_e  (ji,jj) *   un_e (ji,jj)      & 
+                       &            + rdtbt * (  zhu_bck        * zu_spg (ji,jj)  &   !
+                       &                       + zhup2_e(ji,jj) * zu_trd (ji,jj)  &   !
+                       &                       +  hu_n  (ji,jj) * zu_frc (ji,jj)  )   ) * z1_hu
+                  !
+                  va_e(ji,jj) = (               hv_e  (ji,jj) *   vn_e (ji,jj)      &
+                       &            + rdtbt * (  zhv_bck        * zv_spg (ji,jj)  &   !
+                       &                       + zhvp2_e(ji,jj) * zv_trd (ji,jj)  &   !
+                       &                       +  hv_n  (ji,jj) * zv_frc (ji,jj)  )   ) * z1_hv
                END DO
             END DO
@@ -1155,15 +680,17 @@
             END DO
          ENDIF
-
-         
-         IF( .NOT.ln_linssh ) THEN                     !* Update ocean depth (variable volume case only)
-            hu_e (:,:) = hu_0(:,:) + zsshu_a(:,:)
-            hv_e (:,:) = hv_0(:,:) + zsshv_a(:,:)
-            hur_e(:,:) = ssumask(:,:) / ( hu_e(:,:) + 1._wp - ssumask(:,:) )
-            hvr_e(:,:) = ssvmask(:,:) / ( hv_e(:,:) + 1._wp - ssvmask(:,:) )
-            !
-         ENDIF
-         !                                             !* domain lateral boundary
-         CALL lbc_lnk_multi( 'dynspg_ts', ua_e, 'U', -1._wp, va_e , 'V', -1._wp )
+       
+         IF( .NOT.ln_linssh ) THEN   !* Update ocean depth (variable volume case only)
+            hu_e (2:jpim1,2:jpjm1) = hu_0(2:jpim1,2:jpjm1) + zsshu_a(2:jpim1,2:jpjm1)
+            hur_e(2:jpim1,2:jpjm1) = ssumask(2:jpim1,2:jpjm1) / ( hu_e(2:jpim1,2:jpjm1) + 1._wp - ssumask(2:jpim1,2:jpjm1) )
+            hv_e (2:jpim1,2:jpjm1) = hv_0(2:jpim1,2:jpjm1) + zsshv_a(2:jpim1,2:jpjm1)
+            hvr_e(2:jpim1,2:jpjm1) = ssvmask(2:jpim1,2:jpjm1) / ( hv_e(2:jpim1,2:jpjm1) + 1._wp - ssvmask(2:jpim1,2:jpjm1) )
+            CALL lbc_lnk_multi( 'dynspg_ts', ua_e , 'U', -1._wp, va_e , 'V', -1._wp  &
+                 &                         , hu_e , 'U', -1._wp, hv_e , 'V', -1._wp  &
+                 &                         , hur_e, 'U', -1._wp, hvr_e, 'V', -1._wp  )
+         ELSE
+            CALL lbc_lnk_multi( 'dynspg_ts', ua_e , 'U', -1._wp, va_e , 'V', -1._wp  )
+         ENDIF
+         !
          !
          !                                                 ! open boundaries
@@ -1213,20 +740,26 @@
       ! Set advection velocity correction:
       IF (ln_bt_fw) THEN
-         zwx(:,:) = un_adv(:,:)
-         zwy(:,:) = vn_adv(:,:)
          IF( .NOT.( kt == nit000 .AND. neuler==0 ) ) THEN
-            un_adv(:,:) = r1_2 * ( ub2_b(:,:) + zwx(:,:) - atfp * un_bf(:,:) )
-            vn_adv(:,:) = r1_2 * ( vb2_b(:,:) + zwy(:,:) - atfp * vn_bf(:,:) )
-            !
-            ! Update corrective fluxes for next time step:
-            un_bf(:,:)  = atfp * un_bf(:,:) + (zwx(:,:) - ub2_b(:,:))
-            vn_bf(:,:)  = atfp * vn_bf(:,:) + (zwy(:,:) - vb2_b(:,:))
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zun_save = un_adv(ji,jj)
+                  zvn_save = vn_adv(ji,jj)
+                  !                          ! apply the previously computed correction 
+                  un_adv(ji,jj) = r1_2 * ( ub2_b(ji,jj) + zun_save - atfp * un_bf(ji,jj) )
+                  vn_adv(ji,jj) = r1_2 * ( vb2_b(ji,jj) + zvn_save - atfp * vn_bf(ji,jj) )
+                  !                          ! Update corrective fluxes for next time step
+                  un_bf(ji,jj)  = atfp * un_bf(ji,jj) + ( zun_save - ub2_b(ji,jj) )
+                  vn_bf(ji,jj)  = atfp * vn_bf(ji,jj) + ( zvn_save - vb2_b(ji,jj) )
+                  !                          ! Save integrated transport for next computation
+                  ub2_b(ji,jj) = zun_save
+                  vb2_b(ji,jj) = zvn_save
+               END DO
+            END DO
          ELSE
-            un_bf(:,:) = 0._wp
-            vn_bf(:,:) = 0._wp 
-         END IF         
-         ! Save integrated transport for next computation
-         ub2_b(:,:) = zwx(:,:)
-         vb2_b(:,:) = zwy(:,:)
+            un_bf(:,:) = 0._wp            ! corrective fluxes for next time step set to zero
+            vn_bf(:,:) = 0._wp
+            ub2_b(:,:) = un_adv(:,:)      ! Save integrated transport for next computation
+            vb2_b(:,:) = vn_adv(:,:)
+         END IF
       ENDIF
 
@@ -1473,4 +1006,5 @@
       REAL(wp) ::   zxr2, zyr2, zcmax   ! local scalar
       REAL(wp), DIMENSION(jpi,jpj) ::   zcu
+      INTEGER  :: inum
       !!----------------------------------------------------------------------
       !
@@ -1579,4 +1113,498 @@
    END SUBROUTINE dyn_spg_ts_init
 
+   
+   SUBROUTINE dyn_cor_2d_init
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE dyn_cor_2d_init  ***
+      !!
+      !! ** Purpose : Set time splitting options
+      !! Set arrays to remove/compute coriolis trend.
+      !! Do it once during initialization if volume is fixed, else at each long time step.
+      !! Note that these arrays are also used during barotropic loop. These are however frozen
+      !! although they should be updated in the variable volume case. Not a big approximation.
+      !! To remove this approximation, copy lines below inside barotropic loop
+      !! and update depths at T-F points (ht and zhf resp.) at each barotropic time step
+      !!
+      !! Compute zwz = f / ( height of the water colomn )
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji ,jj, jk              ! dummy loop indices
+      REAL(wp) ::   z1_ht
+      REAL(wp), DIMENSION(jpi,jpj) :: zhf
+      !!----------------------------------------------------------------------
+      !
+      SELECT CASE( nvor_scheme )
+      CASE( np_EEN )                != EEN scheme using e3f (energy & enstrophy scheme)
+         SELECT CASE( nn_een_e3f )              !* ff_f/e3 at F-point
+         CASE ( 0 )                                   ! original formulation  (masked averaging of e3t divided by 4)
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  zwz(ji,jj) =   ( ht_n(ji  ,jj+1) + ht_n(ji+1,jj+1) +                    &
+                       &             ht_n(ji  ,jj  ) + ht_n(ji+1,jj  )   ) * 0.25_wp  
+                  IF( zwz(ji,jj) /= 0._wp )   zwz(ji,jj) = ff_f(ji,jj) / zwz(ji,jj)
+               END DO
+            END DO
+         CASE ( 1 )                                   ! new formulation  (masked averaging of e3t divided by the sum of mask)
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  zwz(ji,jj) =             (  ht_n  (ji  ,jj+1) + ht_n  (ji+1,jj+1)      &
+                       &                      + ht_n  (ji  ,jj  ) + ht_n  (ji+1,jj  )  )   &
+                       &       / ( MAX( 1._wp,  ssmask(ji  ,jj+1) + ssmask(ji+1,jj+1)      &
+                       &                      + ssmask(ji  ,jj  ) + ssmask(ji+1,jj  )  )   )
+                  IF( zwz(ji,jj) /= 0._wp )   zwz(ji,jj) = ff_f(ji,jj) / zwz(ji,jj)
+               END DO
+            END DO
+         END SELECT
+         CALL lbc_lnk( 'dynspg_ts', zwz, 'F', 1._wp )
+         !
+         ftne(1,:) = 0._wp ; ftnw(1,:) = 0._wp ; ftse(1,:) = 0._wp ; ftsw(1,:) = 0._wp
+         DO jj = 2, jpj
+            DO ji = 2, jpi
+               ftne(ji,jj) = zwz(ji-1,jj  ) + zwz(ji  ,jj  ) + zwz(ji  ,jj-1)
+               ftnw(ji,jj) = zwz(ji-1,jj-1) + zwz(ji-1,jj  ) + zwz(ji  ,jj  )
+               ftse(ji,jj) = zwz(ji  ,jj  ) + zwz(ji  ,jj-1) + zwz(ji-1,jj-1)
+               ftsw(ji,jj) = zwz(ji  ,jj-1) + zwz(ji-1,jj-1) + zwz(ji-1,jj  )
+            END DO
+         END DO
+         !
+      CASE( np_EET )                  != EEN scheme using e3t (energy conserving scheme)
+         ftne(1,:) = 0._wp ; ftnw(1,:) = 0._wp ; ftse(1,:) = 0._wp ; ftsw(1,:) = 0._wp
+         DO jj = 2, jpj
+            DO ji = 2, jpi
+               z1_ht = ssmask(ji,jj) / ( ht_n(ji,jj) + 1._wp - ssmask(ji,jj) )
+               ftne(ji,jj) = ( ff_f(ji-1,jj  ) + ff_f(ji  ,jj  ) + ff_f(ji  ,jj-1) ) * z1_ht
+               ftnw(ji,jj) = ( ff_f(ji-1,jj-1) + ff_f(ji-1,jj  ) + ff_f(ji  ,jj  ) ) * z1_ht
+               ftse(ji,jj) = ( ff_f(ji  ,jj  ) + ff_f(ji  ,jj-1) + ff_f(ji-1,jj-1) ) * z1_ht
+               ftsw(ji,jj) = ( ff_f(ji  ,jj-1) + ff_f(ji-1,jj-1) + ff_f(ji-1,jj  ) ) * z1_ht
+            END DO
+         END DO
+         !
+      CASE( np_ENE, np_ENS , np_MIX )  != all other schemes (ENE, ENS, MIX) except ENT !
+         !
+         zwz(:,:) = 0._wp
+         zhf(:,:) = 0._wp
+         
+         !!gm  assume 0 in both cases (which is almost surely WRONG ! ) as hvatf has been removed 
+!!gm    A priori a better value should be something like :
+!!gm          zhf(i,j) = masked sum of  ht(i,j) , ht(i+1,j) , ht(i,j+1) , (i+1,j+1) 
+!!gm                     divided by the sum of the corresponding mask 
+!!gm 
+!!            
+         IF( .NOT.ln_sco ) THEN
+  
+   !!gm  agree the JC comment  : this should be done in a much clear way
+  
+   ! JC: It not clear yet what should be the depth at f-points over land in z-coordinate case
+   !     Set it to zero for the time being 
+   !              IF( rn_hmin < 0._wp ) THEN    ;   jk = - INT( rn_hmin )                                      ! from a nb of level
+   !              ELSE                          ;   jk = MINLOC( gdepw_0, mask = gdepw_0 > rn_hmin, dim = 1 )  ! from a depth
+   !              ENDIF
+   !              zhf(:,:) = gdepw_0(:,:,jk+1)
+            !
+         ELSE
+            !
+            !zhf(:,:) = hbatf(:,:)
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  zhf(ji,jj) =    (   ht_0  (ji,jj  ) + ht_0  (ji+1,jj  )          &
+                       &            + ht_0  (ji,jj+1) + ht_0  (ji+1,jj+1)   )      &
+                       &     / MAX(   ssmask(ji,jj  ) + ssmask(ji+1,jj  )          &
+                       &            + ssmask(ji,jj+1) + ssmask(ji+1,jj+1) , 1._wp  )
+               END DO
+            END DO
+         ENDIF
+         !
+         DO jj = 1, jpjm1
+            zhf(:,jj) = zhf(:,jj) * (1._wp- umask(:,jj,1) * umask(:,jj+1,1))
+         END DO
+         !
+         DO jk = 1, jpkm1
+            DO jj = 1, jpjm1
+               zhf(:,jj) = zhf(:,jj) + e3f_n(:,jj,jk) * umask(:,jj,jk) * umask(:,jj+1,jk)
+            END DO
+         END DO
+         CALL lbc_lnk( 'dynspg_ts', zhf, 'F', 1._wp )
+         ! JC: TBC. hf should be greater than 0 
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( zhf(ji,jj) /= 0._wp )   zwz(ji,jj) = 1._wp / zhf(ji,jj)
+            END DO
+         END DO
+         zwz(:,:) = ff_f(:,:) * zwz(:,:)
+      END SELECT
+      
+   END SUBROUTINE dyn_cor_2d_init
+
+
+
+   SUBROUTINE dyn_cor_2d( hu_n, hv_n, un_b, vn_b, zhU, zhV,    zu_trd, zv_trd   )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE dyn_cor_2d  ***
+      !!
+      !! ** Purpose : Compute u and v coriolis trends
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji ,jj                             ! dummy loop indices
+      REAL(wp) ::   zx1, zx2, zy1, zy2, z1_hu, z1_hv   !   -      -
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) :: hu_n, hv_n, un_b, vn_b, zhU, zhV
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) :: zu_trd, zv_trd
+      !!----------------------------------------------------------------------
+      SELECT CASE( nvor_scheme )
+      CASE( np_ENT )                ! enstrophy conserving scheme (f-point)
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               z1_hu = ssumask(ji,jj) / ( hu_n(ji,jj) + 1._wp - ssumask(ji,jj) )
+               z1_hv = ssvmask(ji,jj) / ( hv_n(ji,jj) + 1._wp - ssvmask(ji,jj) )
+               zu_trd(ji,jj) = + r1_4 * r1_e1e2u(ji,jj) * z1_hu                    &
+                  &               * (  e1e2t(ji+1,jj)*ht_n(ji+1,jj)*ff_t(ji+1,jj) * ( vn_b(ji+1,jj) + vn_b(ji+1,jj-1) )   &
+                  &                  + e1e2t(ji  ,jj)*ht_n(ji  ,jj)*ff_t(ji  ,jj) * ( vn_b(ji  ,jj) + vn_b(ji  ,jj-1) )   )
+                  !
+               zv_trd(ji,jj) = - r1_4 * r1_e1e2v(ji,jj) * z1_hv                    &
+                  &               * (  e1e2t(ji,jj+1)*ht_n(ji,jj+1)*ff_t(ji,jj+1) * ( un_b(ji,jj+1) + un_b(ji-1,jj+1) )   & 
+                  &                  + e1e2t(ji,jj  )*ht_n(ji,jj  )*ff_t(ji,jj  ) * ( un_b(ji,jj  ) + un_b(ji-1,jj  ) )   ) 
+            END DO  
+         END DO  
+         !         
+      CASE( np_ENE , np_MIX )        ! energy conserving scheme (t-point) ENE or MIX
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zy1 = ( zhV(ji,jj-1) + zhV(ji+1,jj-1) ) * r1_e1u(ji,jj)
+               zy2 = ( zhV(ji,jj  ) + zhV(ji+1,jj  ) ) * r1_e1u(ji,jj)
+               zx1 = ( zhU(ji-1,jj) + zhU(ji-1,jj+1) ) * r1_e2v(ji,jj)
+               zx2 = ( zhU(ji  ,jj) + zhU(ji  ,jj+1) ) * r1_e2v(ji,jj)
+               ! energy conserving formulation for planetary vorticity term
+               zu_trd(ji,jj) =   r1_4 * ( zwz(ji  ,jj-1) * zy1 + zwz(ji,jj) * zy2 )
+               zv_trd(ji,jj) = - r1_4 * ( zwz(ji-1,jj  ) * zx1 + zwz(ji,jj) * zx2 )
+            END DO
+         END DO
+         !
+      CASE( np_ENS )                ! enstrophy conserving scheme (f-point)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zy1 =   r1_8 * ( zhV(ji  ,jj-1) + zhV(ji+1,jj-1) &
+                 &            + zhV(ji  ,jj  ) + zhV(ji+1,jj  ) ) * r1_e1u(ji,jj)
+               zx1 = - r1_8 * ( zhU(ji-1,jj  ) + zhU(ji-1,jj+1) &
+                 &            + zhU(ji  ,jj  ) + zhU(ji  ,jj+1) ) * r1_e2v(ji,jj)
+               zu_trd(ji,jj)  = zy1 * ( zwz(ji  ,jj-1) + zwz(ji,jj) )
+               zv_trd(ji,jj)  = zx1 * ( zwz(ji-1,jj  ) + zwz(ji,jj) )
+            END DO
+         END DO
+         !
+      CASE( np_EET , np_EEN )      ! energy & enstrophy scheme (using e3t or e3f)         
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zu_trd(ji,jj) = + r1_12 * r1_e1u(ji,jj) * (  ftne(ji,jj  ) * zhV(ji  ,jj  ) &
+                &                                         + ftnw(ji+1,jj) * zhV(ji+1,jj  ) &
+                &                                         + ftse(ji,jj  ) * zhV(ji  ,jj-1) &
+                &                                         + ftsw(ji+1,jj) * zhV(ji+1,jj-1) )
+               zv_trd(ji,jj) = - r1_12 * r1_e2v(ji,jj) * (  ftsw(ji,jj+1) * zhU(ji-1,jj+1) &
+                &                                         + ftse(ji,jj+1) * zhU(ji  ,jj+1) &
+                &                                         + ftnw(ji,jj  ) * zhU(ji-1,jj  ) &
+                &                                         + ftne(ji,jj  ) * zhU(ji  ,jj  ) )
+            END DO
+         END DO
+         !
+      END SELECT
+      !
+   END SUBROUTINE dyn_cor_2D
+
+
+   SUBROUTINE wad_tmsk( pssh, ptmsk )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE wad_lmt  ***
+      !!                    
+      !! ** Purpose :   set wetting & drying mask at tracer points 
+      !!              for the current barotropic sub-step 
+      !!
+      !! ** Method  :   ??? 
+      !!
+      !! ** Action  :  ptmsk : wetting & drying t-mask
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pssh    !
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   ptmsk   !
+      !
+      INTEGER  ::   ji, jj   ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_wd_dl_rmp ) THEN     
+         DO jj = 1, jpj
+            DO ji = 1, jpi                    
+               IF    ( pssh(ji,jj) + ht_0(ji,jj) >  2._wp * rn_wdmin1 ) THEN 
+                  !           IF    ( pssh(ji,jj) + ht_0(ji,jj) >          rn_wdmin2 ) THEN 
+                  ptmsk(ji,jj) = 1._wp
+               ELSEIF( pssh(ji,jj) + ht_0(ji,jj) >          rn_wdmin1 ) THEN
+                  ptmsk(ji,jj) = TANH( 50._wp*( ( pssh(ji,jj) + ht_0(ji,jj) -  rn_wdmin1 )*r_rn_wdmin1) )
+               ELSE 
+                  ptmsk(ji,jj) = 0._wp
+               ENDIF
+            END DO
+         END DO
+      ELSE  
+         DO jj = 1, jpj
+            DO ji = 1, jpi                              
+               IF ( pssh(ji,jj) + ht_0(ji,jj) >  rn_wdmin1 ) THEN   ;   ptmsk(ji,jj) = 1._wp
+               ELSE                                                 ;   ptmsk(ji,jj) = 0._wp
+               ENDIF
+            END DO
+         END DO
+      ENDIF
+      !
+   END SUBROUTINE wad_tmsk
+
+
+   SUBROUTINE wad_Umsk( pTmsk, phU, phV, pu, pv, pUmsk, pVmsk )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE wad_lmt  ***
+      !!                    
+      !! ** Purpose :   set wetting & drying mask at tracer points 
+      !!              for the current barotropic sub-step 
+      !!
+      !! ** Method  :   ??? 
+      !!
+      !! ** Action  :  ptmsk : wetting & drying t-mask
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pTmsk              ! W & D t-mask
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   phU, phV, pu, pv   ! ocean velocities and transports
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pUmsk, pVmsk       ! W & D u- and v-mask
+      !
+      INTEGER  ::   ji, jj   ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      DO jj = 1, jpj
+         DO ji = 1, jpim1   ! not jpi-column
+            IF ( phU(ji,jj) > 0._wp ) THEN   ;   pUmsk(ji,jj) = pTmsk(ji  ,jj) 
+            ELSE                             ;   pUmsk(ji,jj) = pTmsk(ji+1,jj)  
+            ENDIF
+            phU(ji,jj) = pUmsk(ji,jj)*phU(ji,jj)
+            pu (ji,jj) = pUmsk(ji,jj)*pu (ji,jj)
+         END DO
+      END DO
+      !
+      DO jj = 1, jpjm1   ! not jpj-row
+         DO ji = 1, jpi
+            IF ( phV(ji,jj) > 0._wp ) THEN   ;   pVmsk(ji,jj) = pTmsk(ji,jj  )
+            ELSE                             ;   pVmsk(ji,jj) = pTmsk(ji,jj+1)  
+            ENDIF
+            phV(ji,jj) = pVmsk(ji,jj)*phV(ji,jj) 
+            pv (ji,jj) = pVmsk(ji,jj)*pv (ji,jj)
+         END DO
+      END DO
+      !
+   END SUBROUTINE wad_Umsk
+
+
+   SUBROUTINE wad_spg( sshn, zcpx, zcpy )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE  wad_sp  ***
+      !!
+      !! ** Purpose : 
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji ,jj               ! dummy loop indices
+      LOGICAL  ::   ll_tmp1, ll_tmp2
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) :: sshn
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) :: zcpx, zcpy
+      !!----------------------------------------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1 
+            ll_tmp1 = MIN(  sshn(ji,jj)               ,  sshn(ji+1,jj) ) >                &
+                 &      MAX( -ht_0(ji,jj)               , -ht_0(ji+1,jj) ) .AND.            &
+                 &      MAX(  sshn(ji,jj) + ht_0(ji,jj) ,  sshn(ji+1,jj) + ht_0(ji+1,jj) )  &
+                 &                                                         > rn_wdmin1 + rn_wdmin2
+            ll_tmp2 = ( ABS( sshn(ji+1,jj)            -  sshn(ji  ,jj))  > 1.E-12 ).AND.( &
+                 &      MAX(   sshn(ji,jj)              ,  sshn(ji+1,jj) ) >                &
+                 &      MAX(  -ht_0(ji,jj)              , -ht_0(ji+1,jj) ) + rn_wdmin1 + rn_wdmin2 )
+            IF(ll_tmp1) THEN
+               zcpx(ji,jj) = 1.0_wp
+            ELSEIF(ll_tmp2) THEN
+               ! no worries about  sshn(ji+1,jj) -  sshn(ji  ,jj) = 0, it won't happen ! here
+               zcpx(ji,jj) = ABS( (sshn(ji+1,jj) + ht_0(ji+1,jj) - sshn(ji,jj) - ht_0(ji,jj)) &
+                    &    / (sshn(ji+1,jj) - sshn(ji  ,jj)) )
+               zcpx(ji,jj) = max(min( zcpx(ji,jj) , 1.0_wp),0.0_wp)
+            ELSE
+               zcpx(ji,jj) = 0._wp
+            ENDIF
+            !
+            ll_tmp1 = MIN(  sshn(ji,jj)               ,  sshn(ji,jj+1) ) >                &
+                 &      MAX( -ht_0(ji,jj)               , -ht_0(ji,jj+1) ) .AND.            &
+                 &      MAX(  sshn(ji,jj) + ht_0(ji,jj) ,  sshn(ji,jj+1) + ht_0(ji,jj+1) )  &
+                 &                                                       > rn_wdmin1 + rn_wdmin2
+            ll_tmp2 = ( ABS( sshn(ji,jj)              -  sshn(ji,jj+1))  > 1.E-12 ).AND.( &
+                 &      MAX(   sshn(ji,jj)              ,  sshn(ji,jj+1) ) >                &
+                 &      MAX(  -ht_0(ji,jj)              , -ht_0(ji,jj+1) ) + rn_wdmin1 + rn_wdmin2 )
+            
+            IF(ll_tmp1) THEN
+               zcpy(ji,jj) = 1.0_wp
+            ELSE IF(ll_tmp2) THEN
+               ! no worries about  sshn(ji,jj+1) -  sshn(ji,jj  ) = 0, it won't happen ! here
+               zcpy(ji,jj) = ABS( (sshn(ji,jj+1) + ht_0(ji,jj+1) - sshn(ji,jj) - ht_0(ji,jj)) &
+                    &             / (sshn(ji,jj+1) - sshn(ji,jj  )) )
+               zcpy(ji,jj) = MAX(  0._wp , MIN( zcpy(ji,jj) , 1.0_wp )  )
+            ELSE
+               zcpy(ji,jj) = 0._wp
+            ENDIF
+         END DO
+      END DO
+            
+   END SUBROUTINE wad_spg
+     
+
+
+   SUBROUTINE dyn_drg_init( pu_RHSi, pv_RHSi, pCdU_u, pCdU_v )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_drg_init  ***
+      !!                    
+      !! ** Purpose : - add the baroclinic top/bottom drag contribution to 
+      !!              the baroclinic part of the barotropic RHS
+      !!              - compute the barotropic drag coefficients
+      !!
+      !! ** Method  :   computation done over the INNER domain only 
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pu_RHSi, pv_RHSi   ! baroclinic part of the barotropic RHS
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   pCdU_u , pCdU_v    ! barotropic drag coefficients
+      !
+      INTEGER  ::   ji, jj   ! dummy loop indices
+      INTEGER  ::   ikbu, ikbv, iktu, iktv
+      REAL(wp) ::   zztmp
+      REAL(wp), DIMENSION(jpi,jpj) ::   zu_i, zv_i
+      !!----------------------------------------------------------------------
+      !
+      !                    !==  Set the barotropic drag coef.  ==!
+      !
+      IF( ln_isfcav ) THEN          ! top+bottom friction (ocean cavities)
+         
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1     ! INNER domain
+               pCdU_u(ji,jj) = r1_2*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) + rCdU_top(ji+1,jj)+rCdU_top(ji,jj) )
+               pCdU_v(ji,jj) = r1_2*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) + rCdU_top(ji,jj+1)+rCdU_top(ji,jj) )
+            END DO
+         END DO
+      ELSE                          ! bottom friction only
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1  ! INNER domain
+               pCdU_u(ji,jj) = r1_2*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) )
+               pCdU_v(ji,jj) = r1_2*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) )
+            END DO
+         END DO
+      ENDIF
+      !
+      !                    !==  BOTTOM stress contribution from baroclinic velocities  ==!
+      !
+      IF( ln_bt_fw ) THEN                 ! FORWARD integration: use NOW bottom baroclinic velocities
+         
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1  ! INNER domain
+               ikbu = mbku(ji,jj)       
+               ikbv = mbkv(ji,jj)    
+               zu_i(ji,jj) = un(ji,jj,ikbu) - un_b(ji,jj)
+               zv_i(ji,jj) = vn(ji,jj,ikbv) - vn_b(ji,jj)
+            END DO
+         END DO
+      ELSE                                ! CENTRED integration: use BEFORE bottom baroclinic velocities
+         
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1   ! INNER domain
+               ikbu = mbku(ji,jj)       
+               ikbv = mbkv(ji,jj)    
+               zu_i(ji,jj) = ub(ji,jj,ikbu) - ub_b(ji,jj)
+               zv_i(ji,jj) = vb(ji,jj,ikbv) - vb_b(ji,jj)
+            END DO
+         END DO
+      ENDIF
+      !
+      IF( ln_wd_il ) THEN      ! W/D : use the "clipped" bottom friction   !!gm   explain WHY, please !
+         zztmp = -1._wp / rdtbt
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1    ! INNER domain
+               pu_RHSi(ji,jj) = pu_RHSi(ji,jj) + zu_i(ji,jj) *  wdrampu(ji,jj) * MAX(                                 & 
+                    &                              r1_hu_n(ji,jj) * r1_2*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) ) , zztmp  )
+               pv_RHSi(ji,jj) = pv_RHSi(ji,jj) + zv_i(ji,jj) *  wdrampv(ji,jj) * MAX(                                 & 
+                    &                              r1_hv_n(ji,jj) * r1_2*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) ) , zztmp  )
+            END DO
+         END DO
+      ELSE                    ! use "unclipped" drag (even if explicit friction is used in 3D calculation)
+         
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1    ! INNER domain
+               pu_RHSi(ji,jj) = pu_RHSi(ji,jj) + r1_hu_n(ji,jj) * r1_2*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) ) * zu_i(ji,jj)
+               pv_RHSi(ji,jj) = pv_RHSi(ji,jj) + r1_hv_n(ji,jj) * r1_2*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) ) * zv_i(ji,jj)
+            END DO
+         END DO
+      END IF
+      !
+      !                    !==  TOP stress contribution from baroclinic velocities  ==!   (no W/D case)
+      !
+      IF( ln_isfcav ) THEN
+         !
+         IF( ln_bt_fw ) THEN                ! FORWARD integration: use NOW top baroclinic velocity
+            
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1   ! INNER domain
+                  iktu = miku(ji,jj)
+                  iktv = mikv(ji,jj)
+                  zu_i(ji,jj) = un(ji,jj,iktu) - un_b(ji,jj)
+                  zv_i(ji,jj) = vn(ji,jj,iktv) - vn_b(ji,jj)
+               END DO
+            END DO
+         ELSE                                ! CENTRED integration: use BEFORE top baroclinic velocity
+            
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1      ! INNER domain
+                  iktu = miku(ji,jj)
+                  iktv = mikv(ji,jj)
+                  zu_i(ji,jj) = ub(ji,jj,iktu) - ub_b(ji,jj)
+                  zv_i(ji,jj) = vb(ji,jj,iktv) - vb_b(ji,jj)
+               END DO
+            END DO
+         ENDIF
+         !
+         !                    ! use "unclipped" top drag (even if explicit friction is used in 3D calculation)
+         
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1    ! INNER domain
+               pu_RHSi(ji,jj) = pu_RHSi(ji,jj) + r1_hu_n(ji,jj) * r1_2*( rCdU_top(ji+1,jj)+rCdU_top(ji,jj) ) * zu_i(ji,jj)
+               pv_RHSi(ji,jj) = pv_RHSi(ji,jj) + r1_hv_n(ji,jj) * r1_2*( rCdU_top(ji,jj+1)+rCdU_top(ji,jj) ) * zv_i(ji,jj)
+            END DO
+         END DO
+         !
+      ENDIF
+      !
+   END SUBROUTINE dyn_drg_init
+
+   SUBROUTINE ts_bck_interp( jn, ll_init,       &   ! <== in
+      &                      za0, za1, za2, za3 )   ! ==> out
+      !!----------------------------------------------------------------------
+      INTEGER ,INTENT(in   ) ::   jn                   ! index of sub time step
+      LOGICAL ,INTENT(in   ) ::   ll_init              !
+      REAL(wp),INTENT(  out) ::   za0, za1, za2, za3   ! Half-step back interpolation coefficient
+      !
+      REAL(wp) ::   zepsilon, zgamma                   !   -      -
+      !!----------------------------------------------------------------------
+      !                             ! set Half-step back interpolation coefficient
+      IF    ( jn==1 .AND. ll_init ) THEN   !* Forward-backward
+         za0 = 1._wp                        
+         za1 = 0._wp                           
+         za2 = 0._wp
+         za3 = 0._wp
+      ELSEIF( jn==2 .AND. ll_init ) THEN   !* AB2-AM3 Coefficients; bet=0 ; gam=-1/6 ; eps=1/12
+         za0 = 1.0833333333333_wp                 ! za0 = 1-gam-eps
+         za1 =-0.1666666666666_wp                 ! za1 = gam
+         za2 = 0.0833333333333_wp                 ! za2 = eps
+         za3 = 0._wp              
+      ELSE                                 !* AB3-AM4 Coefficients; bet=0.281105 ; eps=0.013 ; gam=0.0880 
+         IF( rn_bt_alpha == 0._wp ) THEN      ! Time diffusion  
+            za0 = 0.614_wp                        ! za0 = 1/2 +   gam + 2*eps
+            za1 = 0.285_wp                        ! za1 = 1/2 - 2*gam - 3*eps
+            za2 = 0.088_wp                        ! za2 = gam
+            za3 = 0.013_wp                        ! za3 = eps
+         ELSE                                 ! no time diffusion
+            zepsilon = 0.00976186_wp - 0.13451357_wp * rn_bt_alpha
+            zgamma   = 0.08344500_wp - 0.51358400_wp * rn_bt_alpha
+            za0 = 0.5_wp + zgamma + 2._wp * rn_bt_alpha + 2._wp * zepsilon
+            za1 = 1._wp - za0 - zgamma - zepsilon
+            za2 = zgamma
+            za3 = zepsilon
+         ENDIF 
+      ENDIF
+   END SUBROUTINE ts_bck_interp
+
+
    !!======================================================================
 END MODULE dynspg_ts
Index: /NEMO/trunk/src/OCE/DYN/dynvor.F90
===================================================================
--- /NEMO/trunk/src/OCE/DYN/dynvor.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DYN/dynvor.F90	(revision 11536)
@@ -851,8 +851,8 @@
       REWIND( numnam_ref )              ! Namelist namdyn_vor in reference namelist : Vorticity scheme options
       READ  ( numnam_ref, namdyn_vor, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_vor in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_vor in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namdyn_vor in configuration namelist : Vorticity scheme options
       READ  ( numnam_cfg, namdyn_vor, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_vor in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_vor in configuration namelist' )
       IF(lwm) WRITE ( numond, namdyn_vor )
       !
Index: /NEMO/trunk/src/OCE/DYN/wet_dry.F90
===================================================================
--- /NEMO/trunk/src/OCE/DYN/wet_dry.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/DYN/wet_dry.F90	(revision 11536)
@@ -81,8 +81,8 @@
       REWIND( numnam_ref )              ! Namelist namwad in reference namelist : Parameters for Wetting/Drying
       READ  ( numnam_ref, namwad, IOSTAT = ios, ERR = 905)
-905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namwad in reference namelist', .TRUE.) 
+905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namwad in reference namelist' ) 
       REWIND( numnam_cfg )              ! Namelist namwad in configuration namelist : Parameters for Wetting/Drying
       READ  ( numnam_cfg, namwad, IOSTAT = ios, ERR = 906)
-906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namwad in configuration namelist', .TRUE. )
+906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namwad in configuration namelist' )
       IF(lwm) WRITE ( numond, namwad )
       !
Index: /NEMO/trunk/src/OCE/FLO/flo4rk.F90
===================================================================
--- /NEMO/trunk/src/OCE/FLO/flo4rk.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/FLO/flo4rk.F90	(revision 11536)
@@ -4,7 +4,5 @@
    !! Ocean floats :   trajectory computation using a 4th order Runge-Kutta
    !!======================================================================
-#if   defined key_floats
-   !!----------------------------------------------------------------------
-   !!   'key_floats'                                     float trajectories
+   !!
    !!----------------------------------------------------------------------
    !!   flo_4rk        : Compute the geographical position of floats
@@ -445,10 +443,4 @@
    END SUBROUTINE flo_interp
 
-#  else
-   !!----------------------------------------------------------------------
-   !!   No floats                                              Dummy module
-   !!----------------------------------------------------------------------
-#endif
-   
    !!======================================================================
 END MODULE flo4rk
Index: /NEMO/trunk/src/OCE/FLO/flo_oce.F90
===================================================================
--- /NEMO/trunk/src/OCE/FLO/flo_oce.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/FLO/flo_oce.F90	(revision 11536)
@@ -6,8 +6,4 @@
    !! History :   OPA  ! 1999-10  (CLIPPER projet)
    !!   NEMO      1.0  ! 2002-11  (G. Madec, A. Bozec)  F90: Free form and module
-   !!----------------------------------------------------------------------
-#if   defined   key_floats
-   !!----------------------------------------------------------------------
-   !!   'key_floats'                                        drifting floats
    !!----------------------------------------------------------------------
    USE par_oce         ! ocean parameters
@@ -20,8 +16,7 @@
    PUBLIC   flo_oce_alloc   ! Routine called in floats.F90
 
-   LOGICAL, PUBLIC, PARAMETER ::   lk_floats = .TRUE.    !: float flag
-
    !! float parameters
    !! ----------------
+   LOGICAL, PUBLIC ::   ln_floats   !: Activate floats or not
    INTEGER, PUBLIC ::   jpnfl       !: total number of floats during the run
    INTEGER, PUBLIC ::   jpnnewflo   !: number of floats added in a new run
@@ -68,11 +63,4 @@
    END FUNCTION flo_oce_alloc
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                 NO drifting floats
-   !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER ::   lk_floats = .FALSE.   !: float flag
-#endif
-
    !!======================================================================
 END MODULE flo_oce
Index: /NEMO/trunk/src/OCE/FLO/floats.F90
===================================================================
--- /NEMO/trunk/src/OCE/FLO/floats.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/FLO/floats.F90	(revision 11536)
@@ -7,7 +7,5 @@
    !!   NEMO     1.0  ! 2002-06  (A. Bozec)  F90, Free form and module
    !!----------------------------------------------------------------------
-#if   defined   key_floats
-   !!----------------------------------------------------------------------
-   !!   'key_floats'                                     float trajectories
+   !!
    !!----------------------------------------------------------------------
    !!   flo_stp   : float trajectories computation
@@ -30,5 +28,5 @@
 
    PUBLIC   flo_stp    ! routine called by step.F90
-   PUBLIC   flo_init   ! routine called by opa.F90
+   PUBLIC   flo_init   ! routine called by nemogcm.F90
 
    !!----------------------------------------------------------------------
@@ -81,5 +79,5 @@
       INTEGER ::   ios                 ! Local integer output status for namelist read
       !
-      NAMELIST/namflo/ jpnfl, jpnnewflo, ln_rstflo, nn_writefl, nn_stockfl, ln_argo, ln_flork4, ln_ariane, ln_flo_ascii
+      NAMELIST/namflo/ ln_floats, jpnfl, jpnnewflo, ln_rstflo, nn_writefl, nn_stockfl, ln_argo, ln_flork4, ln_ariane, ln_flo_ascii
       !!---------------------------------------------------------------------
       !
@@ -90,9 +88,9 @@
       REWIND( numnam_ref )              ! Namelist namflo in reference namelist : Floats
       READ  ( numnam_ref, namflo, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namflo in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namflo in reference namelist' )
 
       REWIND( numnam_cfg )              ! Namelist namflo in configuration namelist : Floats
       READ  ( numnam_cfg, namflo, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namflo in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namflo in configuration namelist' )
       IF(lwm) WRITE ( numond, namflo )
       !
@@ -100,55 +98,44 @@
          WRITE(numout,*)
          WRITE(numout,*) '         Namelist floats :'
-         WRITE(numout,*) '            number of floats                      jpnfl        = ', jpnfl
-         WRITE(numout,*) '            number of new floats                  jpnflnewflo  = ', jpnnewflo
-         WRITE(numout,*) '            restart                               ln_rstflo    = ', ln_rstflo
-         WRITE(numout,*) '            frequency of float output file        nn_writefl   = ', nn_writefl
-         WRITE(numout,*) '            frequency of float restart file       nn_stockfl   = ', nn_stockfl
-         WRITE(numout,*) '            Argo type floats                      ln_argo      = ', ln_argo
-         WRITE(numout,*) '            Computation of T trajectories         ln_flork4    = ', ln_flork4
-         WRITE(numout,*) '            Use of ariane convention              ln_ariane    = ', ln_ariane
-         WRITE(numout,*) '            ascii output (T) or netcdf output (F) ln_flo_ascii = ', ln_flo_ascii
+         WRITE(numout,*) '            Activate floats or not                   ln_floats    = ', ln_floats
+         WRITE(numout,*) '               number of floats                      jpnfl        = ', jpnfl
+         WRITE(numout,*) '               number of new floats                  jpnflnewflo  = ', jpnnewflo
+         WRITE(numout,*) '               restart                               ln_rstflo    = ', ln_rstflo
+         WRITE(numout,*) '               frequency of float output file        nn_writefl   = ', nn_writefl
+         WRITE(numout,*) '               frequency of float restart file       nn_stockfl   = ', nn_stockfl
+         WRITE(numout,*) '               Argo type floats                      ln_argo      = ', ln_argo
+         WRITE(numout,*) '               Computation of T trajectories         ln_flork4    = ', ln_flork4
+         WRITE(numout,*) '               Use of ariane convention              ln_ariane    = ', ln_ariane
+         WRITE(numout,*) '               ascii output (T) or netcdf output (F) ln_flo_ascii = ', ln_flo_ascii
 
       ENDIF
       !
-      !                             ! allocate floats arrays
-      IF( flo_oce_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'flo_init : unable to allocate arrays' )
-      !
-      !                             ! allocate flodom arrays
-      IF( flo_dom_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'flo_dom : unable to allocate arrays' )
-      !
-      !                             ! allocate flowri arrays
-      IF( flo_wri_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'flo_wri : unable to allocate arrays' )
-      !
-      !                             ! allocate florst arrays
-      IF( flo_rst_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'flo_rst : unable to allocate arrays' )
-      !
-      jpnrstflo = jpnfl-jpnnewflo   ! memory allocation 
-      !
-      DO jfl = 1, jpnfl             ! vertical axe for netcdf IOM ouput
-         nfloat(jfl) = jfl 
-      END DO
-      !
-      CALL flo_dom                  ! compute/read initial position of floats
-      !
-      wb(:,:,:) = wn(:,:,:)         ! set wb for computation of floats trajectories at the first time step
+      IF( ln_floats ) THEN
+         !                             ! allocate floats arrays
+         IF( flo_oce_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'flo_init : unable to allocate arrays' )
+         !
+         !                             ! allocate flodom arrays
+         IF( flo_dom_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'flo_dom : unable to allocate arrays' )
+         !
+         !                             ! allocate flowri arrays
+         IF( flo_wri_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'flo_wri : unable to allocate arrays' )
+         !
+         !                             ! allocate florst arrays
+         IF( flo_rst_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'flo_rst : unable to allocate arrays' )
+         !
+         jpnrstflo = jpnfl-jpnnewflo   ! memory allocation 
+         !
+         DO jfl = 1, jpnfl             ! vertical axe for netcdf IOM ouput
+            nfloat(jfl) = jfl 
+         END DO
+         !
+         CALL flo_dom                  ! compute/read initial position of floats
+         !
+         wb(:,:,:) = wn(:,:,:)         ! set wb for computation of floats trajectories at the first time step
+         !
+      ENDIF
       !
    END SUBROUTINE flo_init
 
-#  else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                       Empty module
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE flo_stp( kt )          ! Empty routine
-      IMPLICIT NONE
-      INTEGER, INTENT( in ) :: kt
-      WRITE(*,*) 'flo_stp: You should not have seen this print! error?', kt
-   END SUBROUTINE flo_stp
-   SUBROUTINE flo_init          ! Empty routine
-      IMPLICIT NONE
-   END SUBROUTINE flo_init
-#endif
-
    !!======================================================================
  END MODULE floats
Index: /NEMO/trunk/src/OCE/FLO/floblk.F90
===================================================================
--- /NEMO/trunk/src/OCE/FLO/floblk.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/FLO/floblk.F90	(revision 11536)
@@ -4,7 +4,5 @@
    !! Ocean floats :   trajectory computation
    !!======================================================================
-#if   defined key_floats
-   !!----------------------------------------------------------------------
-   !!   'key_floats'                                     float trajectories
+   !!
    !!----------------------------------------------------------------------
    !!    flotblk     : compute float trajectories with Blanke algorithme
@@ -369,13 +367,4 @@
    END SUBROUTINE flo_blk
 
-#  else
-   !!----------------------------------------------------------------------
-   !!   Default option                                         Empty module
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE flo_blk                  ! Empty routine
-   END SUBROUTINE flo_blk 
-#endif
-   
    !!======================================================================
 END MODULE floblk 
Index: /NEMO/trunk/src/OCE/FLO/flodom.F90
===================================================================
--- /NEMO/trunk/src/OCE/FLO/flodom.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/FLO/flodom.F90	(revision 11536)
@@ -6,8 +6,4 @@
    !! History :  OPA  ! 1998-07 (Y.Drillet, CLIPPER)  Original code
    !!  NEMO      3.3  ! 2011-09 (C.Bricaud,S.Law-Chune Mercator-Ocean): add ARIANE convention + comsecitc changes
-   !!----------------------------------------------------------------------
-#if   defined key_floats
-   !!----------------------------------------------------------------------
-   !!   'key_floats'                                     float trajectories
    !!----------------------------------------------------------------------
    !!   flo_dom               : initialization of floats
@@ -455,15 +451,4 @@
    END FUNCTION flo_dom_alloc
 
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                                         Empty module
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE flo_dom                 ! Empty routine
-         WRITE(*,*) 'flo_dom: : You should not have seen this print! error?'
-   END SUBROUTINE flo_dom
-#endif
-
    !!======================================================================
 END MODULE flodom
Index: /NEMO/trunk/src/OCE/FLO/florst.F90
===================================================================
--- /NEMO/trunk/src/OCE/FLO/florst.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/FLO/florst.F90	(revision 11536)
@@ -8,8 +8,4 @@
    !!   NEMO      1.0  !  2002-10  (A. Bozec)  F90 : Free form and module
    !!             3.2  !  2010-08  (slaw, cbricaud): netcdf outputs and others 
-   !!----------------------------------------------------------------------
-#if   defined key_floats
-   !!----------------------------------------------------------------------
-   !!   'key_floats'                                     float trajectories
    !!----------------------------------------------------------------------
    USE flo_oce         ! ocean drifting floats
@@ -125,13 +121,4 @@
    END SUBROUTINE flo_rst
 
-#  else
-   !!----------------------------------------------------------------------
-   !!   Default option                                         Empty module
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE flo_rst                 ! Empty routine
-   END SUBROUTINE flo_rst
-#endif
-
    !!=======================================================================
 END MODULE florst
Index: /NEMO/trunk/src/OCE/FLO/flowri.F90
===================================================================
--- /NEMO/trunk/src/OCE/FLO/flowri.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/FLO/flowri.F90	(revision 11536)
@@ -10,8 +10,4 @@
    !!   NEMO      1.0  !  2002-10  (A. Bozec)  F90 : Free form and module
    !!             3.2  !  2010-08  (slaw, cbricaud): netcdf outputs and others 
-   !!----------------------------------------------------------------------
-#if   defined key_floats
-   !!----------------------------------------------------------------------
-   !!   'key_floats'                                     float trajectories
    !!----------------------------------------------------------------------
    USE flo_oce         ! ocean drifting floats
@@ -179,5 +175,5 @@
                CALL ctl_opn( numflo, 'trajec_float', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
                irecflo = NINT( (nitend-nn_it000) / FLOAT(nn_writefl) )
-               WRITE(numflo,*)cexper,no,irecflo,jpnfl,nn_writefl
+               WRITE(numflo,*) cexper, irecflo, jpnfl, nn_writefl
             ENDIF
 
@@ -255,12 +251,11 @@
 
                istart = (/jfl,irec/)
-               icfl   = INT( tpkfl(jfl) )            ! K-index of the nearest point before
-
-               CALL flioputv( numflo , 'traj_lon'    , zlon(jfl)        , start=istart )
-               CALL flioputv( numflo , 'traj_lat'    , zlat(jfl)        , start=istart )  
-               CALL flioputv( numflo , 'traj_depth'  , zdep(jfl)        , start=istart )  
-               CALL flioputv( numflo , 'traj_temp'   , ztemp(icfl,jfl)  , start=istart )  
-               CALL flioputv( numflo , 'traj_salt'   , zsal(icfl,jfl)   , start=istart )  
-               CALL flioputv( numflo , 'traj_dens'   , zrho(icfl,jfl)   , start=istart )  
+
+               CALL flioputv( numflo , 'traj_lon'    , zlon(jfl), start=istart )
+               CALL flioputv( numflo , 'traj_lat'    , zlat(jfl), start=istart )  
+               CALL flioputv( numflo , 'traj_depth'  , zdep(jfl), start=istart )  
+               CALL flioputv( numflo , 'traj_temp'   , ztem(jfl), start=istart )  
+               CALL flioputv( numflo , 'traj_salt'   , zsal(jfl), start=istart )  
+               CALL flioputv( numflo , 'traj_dens'   , zrho(jfl), start=istart )  
 
             ENDDO
@@ -277,14 +272,4 @@
    END SUBROUTINE flo_wri
 
-
-#  else
-   !!----------------------------------------------------------------------
-   !!   Default option                                         Empty module
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE flo_wri                 ! Empty routine
-   END SUBROUTINE flo_wri
-#endif
-
    !!=======================================================================
 END MODULE flowri
Index: /NEMO/trunk/src/OCE/ICB/icbini.F90
===================================================================
--- /NEMO/trunk/src/OCE/ICB/icbini.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/ICB/icbini.F90	(revision 11536)
@@ -406,8 +406,8 @@
       REWIND( numnam_ref )              ! Namelist namberg in reference namelist : Iceberg parameters
       READ  ( numnam_ref, namberg, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namberg in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namberg in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namberg in configuration namelist : Iceberg parameters
       READ  ( numnam_cfg, namberg, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namberg in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namberg in configuration namelist' )
       IF(lwm) WRITE ( numond, namberg )
       !
Index: /NEMO/trunk/src/OCE/ICB/icblbc.F90
===================================================================
--- /NEMO/trunk/src/OCE/ICB/icblbc.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/ICB/icblbc.F90	(revision 11536)
@@ -278,5 +278,5 @@
          CALL mppsend( 12, zwebergs(1), 1, ipe_E, iml_req1)
          CALL mpprecv( 11, zewbergs(2), 1, ipe_E )
-         IF( l_isend ) CALL mpi_wait( iml_req1, iml_stat, iml_err )
+         CALL mpi_wait( iml_req1, iml_stat, iml_err )
          ibergs_rcvd_from_e = INT( zewbergs(2) )
       CASE(  0 )
@@ -287,6 +287,6 @@
          CALL mpprecv( 11, zewbergs(2), 1, ipe_E )
          CALL mpprecv( 12, zwebergs(2), 1, ipe_W )
-         IF( l_isend ) CALL mpi_wait( iml_req2, iml_stat, iml_err )
-         IF( l_isend ) CALL mpi_wait( iml_req3, iml_stat, iml_err )
+         CALL mpi_wait( iml_req2, iml_stat, iml_err )
+         CALL mpi_wait( iml_req3, iml_stat, iml_err )
          ibergs_rcvd_from_e = INT( zewbergs(2) )
          ibergs_rcvd_from_w = INT( zwebergs(2) )
@@ -295,5 +295,5 @@
          CALL mppsend( 11, zewbergs(1), 1, ipe_W, iml_req4)
          CALL mpprecv( 12, zwebergs(2), 1, ipe_W )
-         IF( l_isend ) CALL mpi_wait( iml_req4, iml_stat, iml_err )
+         CALL mpi_wait( iml_req4, iml_stat, iml_err )
          ibergs_rcvd_from_w = INT( zwebergs(2) )
       END SELECT
@@ -310,5 +310,5 @@
             CALL mpprecv( 13, ibuffer_e%data, ibergs_rcvd_from_e*jp_buffer_width )
          ENDIF
-         IF( ibergs_to_send_e > 0 .AND. l_isend ) CALL mpi_wait( iml_req1, iml_stat, iml_err )
+         IF( ibergs_to_send_e > 0 ) CALL mpi_wait( iml_req1, iml_stat, iml_err )
          DO i = 1, ibergs_rcvd_from_e
             IF( nn_verbose_level >= 4 ) THEN
@@ -329,6 +329,6 @@
             CALL mpprecv( 14, ibuffer_w%data, ibergs_rcvd_from_w*jp_buffer_width )
          ENDIF
-         IF( ibergs_to_send_w > 0 .AND. l_isend ) CALL mpi_wait( iml_req2, iml_stat, iml_err )
-         IF( ibergs_to_send_e > 0 .AND. l_isend ) CALL mpi_wait( iml_req3, iml_stat, iml_err )
+         IF( ibergs_to_send_w > 0 ) CALL mpi_wait( iml_req2, iml_stat, iml_err )
+         IF( ibergs_to_send_e > 0 ) CALL mpi_wait( iml_req3, iml_stat, iml_err )
          DO i = 1, ibergs_rcvd_from_e
             IF( nn_verbose_level >= 4 ) THEN
@@ -351,5 +351,5 @@
             CALL mpprecv( 14, ibuffer_w%data, ibergs_rcvd_from_w*jp_buffer_width )
          ENDIF
-         IF( ibergs_to_send_w > 0 .AND. l_isend ) CALL mpi_wait( iml_req4, iml_stat, iml_err )
+         IF( ibergs_to_send_w > 0 ) CALL mpi_wait( iml_req4, iml_stat, iml_err )
          DO i = 1, ibergs_rcvd_from_w
             IF( nn_verbose_level >= 4 ) THEN
@@ -409,5 +409,5 @@
          CALL mppsend( 16, zsnbergs(1), 1, ipe_N, iml_req1)
          CALL mpprecv( 15, znsbergs(2), 1, ipe_N )
-         IF( l_isend ) CALL mpi_wait( iml_req1, iml_stat, iml_err )
+         CALL mpi_wait( iml_req1, iml_stat, iml_err )
          ibergs_rcvd_from_n = INT( znsbergs(2) )
       CASE(  0 )
@@ -418,6 +418,6 @@
          CALL mpprecv( 15, znsbergs(2), 1, ipe_N )
          CALL mpprecv( 16, zsnbergs(2), 1, ipe_S )
-         IF( l_isend ) CALL mpi_wait( iml_req2, iml_stat, iml_err )
-         IF( l_isend ) CALL mpi_wait( iml_req3, iml_stat, iml_err )
+         CALL mpi_wait( iml_req2, iml_stat, iml_err )
+         CALL mpi_wait( iml_req3, iml_stat, iml_err )
          ibergs_rcvd_from_n = INT( znsbergs(2) )
          ibergs_rcvd_from_s = INT( zsnbergs(2) )
@@ -426,5 +426,5 @@
          CALL mppsend( 15, znsbergs(1), 1, ipe_S, iml_req4)
          CALL mpprecv( 16, zsnbergs(2), 1, ipe_S )
-         IF( l_isend ) CALL mpi_wait( iml_req4, iml_stat, iml_err )
+         CALL mpi_wait( iml_req4, iml_stat, iml_err )
          ibergs_rcvd_from_s = INT( zsnbergs(2) )
       END SELECT
@@ -441,5 +441,5 @@
             CALL mpprecv( 17, ibuffer_n%data, ibergs_rcvd_from_n*jp_buffer_width )
          ENDIF
-         IF( ibergs_to_send_n > 0 .AND. l_isend ) CALL mpi_wait( iml_req1, iml_stat, iml_err )
+         IF( ibergs_to_send_n > 0 ) CALL mpi_wait( iml_req1, iml_stat, iml_err )
          DO i = 1, ibergs_rcvd_from_n
             IF( nn_verbose_level >= 4 ) THEN
@@ -460,6 +460,6 @@
             CALL mpprecv( 18, ibuffer_s%data, ibergs_rcvd_from_s*jp_buffer_width )
          ENDIF
-         IF( ibergs_to_send_s > 0 .AND. l_isend ) CALL mpi_wait( iml_req2, iml_stat, iml_err )
-         IF( ibergs_to_send_n > 0 .AND. l_isend ) CALL mpi_wait( iml_req3, iml_stat, iml_err )
+         IF( ibergs_to_send_s > 0 ) CALL mpi_wait( iml_req2, iml_stat, iml_err )
+         IF( ibergs_to_send_n > 0 ) CALL mpi_wait( iml_req3, iml_stat, iml_err )
          DO i = 1, ibergs_rcvd_from_n
             IF( nn_verbose_level >= 4 ) THEN
@@ -482,5 +482,5 @@
             CALL mpprecv( 18, ibuffer_s%data, ibergs_rcvd_from_s*jp_buffer_width )
          ENDIF
-         IF( ibergs_to_send_s > 0 .AND. l_isend ) CALL mpi_wait( iml_req4, iml_stat, iml_err )
+         IF( ibergs_to_send_s > 0 ) CALL mpi_wait( iml_req4, iml_stat, iml_err )
          DO i = 1, ibergs_rcvd_from_s
             IF( nn_verbose_level >= 4 ) THEN
@@ -669,6 +669,5 @@
             ifldproc = nicbfldproc(jn)
             IF( ifldproc == narea ) CYCLE
-
-            IF( l_isend ) CALL mpi_wait( nicbfldreq(jn), iml_stat, iml_err )
+            CALL mpi_wait( nicbfldreq(jn), iml_stat, iml_err )
          ENDIF
          !
@@ -770,6 +769,5 @@
             ifldproc = nicbfldproc(jn)
             IF( ifldproc == narea ) CYCLE
-
-            IF( l_isend ) CALL mpi_wait( nicbfldreq(jn), iml_stat, iml_err )
+            CALL mpi_wait( nicbfldreq(jn), iml_stat, iml_err )
          ENDIF
          !
Index: /NEMO/trunk/src/OCE/ICB/icbrst.F90
===================================================================
--- /NEMO/trunk/src/OCE/ICB/icbrst.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/ICB/icbrst.F90	(revision 11536)
@@ -131,6 +131,4 @@
       CALL iom_get( ncid, jpdom_unknown, 'kount' , zdata(:) )
       num_bergs(:) = INT(zdata(:))
-      ! Close file
-      CALL iom_close( ncid )
       !
 
@@ -146,4 +144,6 @@
       IF( lwp )   WRITE(numout,'(a,i5,a,i5,a)') 'icebergs, icb_rst_read: there were',ibergs_in_file,   &
          &                                    ' bergs in the restart file and', jn,' bergs have been read'
+      ! Close file
+      CALL iom_close( ncid )
       !
       ! Confirm that all areas have a suitable base for assigning new iceberg
Index: /NEMO/trunk/src/OCE/ICB/icbstp.F90
===================================================================
--- /NEMO/trunk/src/OCE/ICB/icbstp.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/ICB/icbstp.F90	(revision 11536)
@@ -86,5 +86,5 @@
       !                                   !* write out time
       ll_verbose = .FALSE.
-      IF( nn_verbose_write > 0 .AND. MOD( kt-1 , nn_verbose_write ) == 0 )   ll_verbose = ( nn_verbose_level >= 0 )
+      IF( nn_verbose_write > 0 .AND. MOD( kt-1 , nn_verbose_write ) == 0 )   ll_verbose = ( nn_verbose_level > 0 )
       !
       IF( ll_verbose )   WRITE(numicb,9100) nktberg, ndastp, nsec_day
Index: /NEMO/trunk/src/OCE/IOM/in_out_manager.F90
===================================================================
--- /NEMO/trunk/src/OCE/IOM/in_out_manager.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/IOM/in_out_manager.F90	(revision 11536)
@@ -80,7 +80,4 @@
    INTEGER       ::   nleapy                      !: Leap year calendar flag (0/1 or 30)
    INTEGER       ::   ninist                      !: initial state output flag (0/1)
-   INTEGER       ::   nwrite                      !: model standard output frequency
-   INTEGER       ::   nstock                      !: restart file frequency
-   INTEGER, DIMENSION(10) :: nstocklist           !: restart dump times
 
    !!----------------------------------------------------------------------
@@ -167,6 +164,4 @@
    CHARACTER(lc) ::   ctmp7, ctmp8, ctmp9   !: temporary characters 7 to 9
    CHARACTER(lc) ::   ctmp10                !: temporary character 10
-   CHARACTER(lc) ::   cform_err = "(/,' ===>>> : E R R O R',     /,'         ===========',/)"       !:
-   CHARACTER(lc) ::   cform_war = "(/,' ===>>> : W A R N I N G', /,'         ===============',/)"   !:
    LOGICAL       ::   lwm      = .FALSE.    !: boolean : true on the 1st processor only (always)
    LOGICAL       ::   lwp      = .FALSE.    !: boolean : true on the 1st processor only .OR. ln_ctl
Index: /NEMO/trunk/src/OCE/IOM/iom.F90
===================================================================
--- /NEMO/trunk/src/OCE/IOM/iom.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/IOM/iom.F90	(revision 11536)
@@ -58,5 +58,5 @@
    PUBLIC iom_init, iom_swap, iom_open, iom_close, iom_setkt, iom_varid, iom_get
    PUBLIC iom_chkatt, iom_getatt, iom_putatt, iom_getszuld, iom_rstput, iom_delay_rst, iom_put
-   PUBLIC iom_use, iom_context_finalize
+   PUBLIC iom_use, iom_context_finalize, iom_miss_val
 
    PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
@@ -212,8 +212,5 @@
           CALL iom_set_axis_attr( "depthv", bounds=zw_bnds )
           CALL iom_set_axis_attr( "depthw", bounds=zt_bnds )
-          !
-# if defined key_floats
           CALL iom_set_axis_attr( "nfloat", (/ (REAL(ji,wp), ji=1,jpnfl) /) )
-# endif
 # if defined key_si3
           CALL iom_set_axis_attr( "ncatice", (/ (REAL(ji,wp), ji=1,jpl) /) )
@@ -835,5 +832,5 @@
 
 
-   FUNCTION iom_varid ( kiomid, cdvar, kdimsz, kndims, ldstop )  
+   FUNCTION iom_varid ( kiomid, cdvar, kdimsz, kndims, lduld, ldstop )  
       !!-----------------------------------------------------------------------
       !!                  ***  FUNCTION  iom_varid  ***
@@ -844,5 +841,6 @@
       CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
       INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of each dimension
-      INTEGER,               INTENT(  out), OPTIONAL ::   kndims   ! size of the dimensions
+      INTEGER              , INTENT(  out), OPTIONAL ::   kndims   ! number of dimensions
+      LOGICAL              , INTENT(  out), OPTIONAL ::   lduld    ! true if the last dimension is unlimited (time)
       LOGICAL              , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if looking for non-existing variable (default = .TRUE.)
       !
@@ -874,5 +872,5 @@
                iiv = iiv + 1
                IF( iiv <= jpmax_vars ) THEN
-                  iom_varid = iom_nf90_varid( kiomid, cdvar, iiv, kdimsz, kndims )
+                  iom_varid = iom_nf90_varid( kiomid, cdvar, iiv, kdimsz, kndims, lduld )
                ELSE
                   CALL ctl_stop( trim(clinfo), 'Too many variables in the file '//iom_file(kiomid)%name,   &
@@ -892,4 +890,5 @@
                ENDIF
                IF( PRESENT(kndims) )  kndims = iom_file(kiomid)%ndims(iiv)
+               IF( PRESENT( lduld) )  lduld  = iom_file(kiomid)%luld( iiv)
             ENDIF
          ENDIF
@@ -1270,9 +1269,9 @@
                !--- overlap areas and extra hallows (mpp)
                IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN
-                  CALL lbc_lnk( 'iom', pv_r2d,'Z',-999.,'no0' )
+                  CALL lbc_lnk( 'iom', pv_r2d,'Z', -999., kfillmode = jpfillnothing )
                ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
                   ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
                   IF( icnt(3) == inlev ) THEN
-                     CALL lbc_lnk( 'iom', pv_r3d,'Z',-999.,'no0' )
+                     CALL lbc_lnk( 'iom', pv_r3d,'Z', -999., kfillmode = jpfillnothing )
                   ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
                      DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO
@@ -1299,5 +1298,5 @@
             CALL xios_recv_field( trim(cdvar), pv_r3d)
             IF(idom /= jpdom_unknown ) then
-                CALL lbc_lnk( 'iom', pv_r3d,'Z',-999.,'no0' )
+                CALL lbc_lnk( 'iom', pv_r3d,'Z', -999., kfillmode = jpfillnothing)
             ENDIF
          ELSEIF( PRESENT(pv_r2d) ) THEN
@@ -1306,5 +1305,5 @@
             CALL xios_recv_field( trim(cdvar), pv_r2d)
             IF(idom /= jpdom_unknown ) THEN
-                CALL lbc_lnk('iom', pv_r2d,'Z',-999.,'no0')
+                CALL lbc_lnk('iom', pv_r2d,'Z',-999., kfillmode = jpfillnothing)
             ENDIF
          ELSEIF( PRESENT(pv_r1d) ) THEN
@@ -1669,9 +1668,9 @@
       CHARACTER(LEN=*), INTENT(in) ::   cdname
       REAL(wp)        , INTENT(in) ::   pfield0d
-      REAL(wp)        , DIMENSION(jpi,jpj) ::   zz     ! masson
+!!      REAL(wp)        , DIMENSION(jpi,jpj) ::   zz     ! masson
 #if defined key_iomput
-      zz(:,:)=pfield0d
-      CALL xios_send_field(cdname, zz)
-      !CALL xios_send_field(cdname, (/pfield0d/)) 
+!!clem      zz(:,:)=pfield0d
+!!clem      CALL xios_send_field(cdname, zz)
+      CALL xios_send_field(cdname, (/pfield0d/)) 
 #else
       IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
@@ -1979,6 +1978,6 @@
       ! Cell vertices on boundries
       DO jn = 1, 4
-         CALL lbc_lnk( 'iom', z_bnds(jn,:,:,1), cdgrd, 1., pval=999._wp )
-         CALL lbc_lnk( 'iom', z_bnds(jn,:,:,2), cdgrd, 1., pval=999._wp )
+         CALL lbc_lnk( 'iom', z_bnds(jn,:,:,1), cdgrd, 1., pfillval=999._wp )
+         CALL lbc_lnk( 'iom', z_bnds(jn,:,:,2), cdgrd, 1., pfillval=999._wp )
       END DO
       !
@@ -2389,5 +2388,4 @@
    !!   NOT 'key_iomput'                               a few dummy routines
    !!----------------------------------------------------------------------
-
    SUBROUTINE iom_setkt( kt, cdname )
       INTEGER         , INTENT(in)::   kt 
@@ -2404,8 +2402,5 @@
 
    LOGICAL FUNCTION iom_use( cdname )
-      !!----------------------------------------------------------------------
-      !!----------------------------------------------------------------------
       CHARACTER(LEN=*), INTENT(in) ::   cdname
-      !!----------------------------------------------------------------------
 #if defined key_iomput
       iom_use = xios_field_is_active( cdname )
@@ -2414,5 +2409,16 @@
 #endif
    END FUNCTION iom_use
-   
+
+   SUBROUTINE iom_miss_val( cdname, pmiss_val )
+      CHARACTER(LEN=*), INTENT(in ) ::   cdname
+      REAL(wp)        , INTENT(out) ::   pmiss_val   
+#if defined key_iomput
+      ! get missing value
+      CALL xios_get_field_attr( cdname, default_value = pmiss_val )
+#else
+      IF( .FALSE. )   WRITE(numout,*) cdname, pmiss_val   ! useless test to avoid compilation warnings
+#endif
+   END SUBROUTINE iom_miss_val
+  
    !!======================================================================
 END MODULE iom
Index: /NEMO/trunk/src/OCE/IOM/iom_nf90.F90
===================================================================
--- /NEMO/trunk/src/OCE/IOM/iom_nf90.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/IOM/iom_nf90.F90	(revision 11536)
@@ -187,5 +187,5 @@
 
 
-   FUNCTION iom_nf90_varid ( kiomid, cdvar, kiv, kdimsz, kndims )  
+   FUNCTION iom_nf90_varid ( kiomid, cdvar, kiv, kdimsz, kndims, lduld )  
       !!-----------------------------------------------------------------------
       !!                  ***  FUNCTION  iom_varid  ***
@@ -198,4 +198,5 @@
       INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
       INTEGER,               INTENT(  out), OPTIONAL ::   kndims   ! size of the dimensions
+      LOGICAL              , INTENT(  out), OPTIONAL ::   lduld    ! true if the last dimension is unlimited (time)
       !
       INTEGER                        ::   iom_nf90_varid   ! iom variable Id
@@ -251,4 +252,5 @@
          ENDIF
          IF( PRESENT(kndims) )  kndims = iom_file(kiomid)%ndims(kiv)
+         IF( PRESENT( lduld) )  lduld  = iom_file(kiomid)%luld(kiv)
       ELSE  
          iom_nf90_varid = -1   !   variable not found, return error code: -1
Index: /NEMO/trunk/src/OCE/IOM/restart.F90
===================================================================
--- /NEMO/trunk/src/OCE/IOM/restart.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/IOM/restart.F90	(revision 11536)
@@ -70,14 +70,16 @@
          IF( ln_rst_list ) THEN
             nrst_lst = 1
-            nitrst = nstocklist( nrst_lst )
+            nitrst = nn_stocklist( nrst_lst )
          ELSE
             nitrst = nitend
          ENDIF
       ENDIF
+      
+      IF( .NOT. ln_rst_list .AND. nn_stock == -1 )   RETURN   ! we will never do any restart
 
       ! frequency-based restart dumping (nn_stock)
-      IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nstock ) == 0 ) THEN   
+      IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nn_stock ) == 0 ) THEN   
          ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
-         nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
+         nitrst = kt + nn_stock - 1                  ! define the next value of nitrst for restart writing
          IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
       ENDIF
@@ -85,5 +87,5 @@
       ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1)
       ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1
-      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN
+      IF( kt == nitrst - 1 .OR. nn_stock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN
          IF( nitrst <= nitend .AND. nitrst > 0 ) THEN 
             ! beware of the format used to write kt (default is i8.8, that should be large enough...)
@@ -184,6 +186,6 @@
          lrst_oce = .FALSE.
             IF( ln_rst_list ) THEN
-               nrst_lst = MIN(nrst_lst + 1, SIZE(nstocklist,1))
-               nitrst = nstocklist( nrst_lst )
+               nrst_lst = MIN(nrst_lst + 1, SIZE(nn_stocklist,1))
+               nitrst = nn_stocklist( nrst_lst )
             ENDIF
       ENDIF
Index: MO/trunk/src/OCE/LBC/lbc_lnk_generic.h90
===================================================================
--- /NEMO/trunk/src/OCE/LBC/lbc_lnk_generic.h90	(revision 11535)
+++ 	(revision )
@@ -1,117 +1,0 @@
-#if defined MULTI
-#   define NAT_IN(k)                cd_nat(k)   
-#   define SGN_IN(k)                psgn(k)
-#   define F_SIZE(ptab)             kfld
-#   define OPT_K(k)                 ,ipf
-#   if defined DIM_2d
-#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_2D)                , INTENT(inout) ::   ptab(f)
-#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt2d(i,j)
-#      define K_SIZE(ptab)             1
-#      define L_SIZE(ptab)             1
-#   endif
-#   if defined DIM_3d
-#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_3D),INTENT(inout)::ptab(f)
-#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt3d(i,j,k)
-#      define K_SIZE(ptab)             SIZE(ptab(1)%pt3d,3)
-#      define L_SIZE(ptab)             1
-#   endif
-#   if defined DIM_4d
-#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_4D),INTENT(inout)::ptab(f)
-#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt4d(i,j,k,l)
-#      define K_SIZE(ptab)             SIZE(ptab(1)%pt4d,3)
-#      define L_SIZE(ptab)             SIZE(ptab(1)%pt4d,4)
-#   endif
-#else
-#   define ARRAY_TYPE(i,j,k,l,f)    REAL(wp)                    , INTENT(inout) ::   ARRAY_IN(i,j,k,l,f)
-#   define NAT_IN(k)                cd_nat
-#   define SGN_IN(k)                psgn
-#   define F_SIZE(ptab)             1
-#   define OPT_K(k)                 
-#   if defined DIM_2d
-#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j)
-#      define K_SIZE(ptab)          1
-#      define L_SIZE(ptab)          1
-#   endif
-#   if defined DIM_3d
-#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k)
-#      define K_SIZE(ptab)          SIZE(ptab,3)
-#      define L_SIZE(ptab)          1
-#   endif
-#   if defined DIM_4d
-#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k,l)
-#      define K_SIZE(ptab)          SIZE(ptab,3)
-#      define L_SIZE(ptab)          SIZE(ptab,4)
-#   endif
-#endif
-
-#if defined MULTI
-   SUBROUTINE ROUTINE_LNK( cdname, ptab, cd_nat, psgn, kfld, cd_mpp, pval )
-      INTEGER                     , INTENT(in   ) ::   kfld        ! number of pt3d arrays
-#else
-   SUBROUTINE ROUTINE_LNK( cdname, ptab, cd_nat, psgn      , cd_mpp, pval )
-#endif
-      CHARACTER(len=*)            , INTENT(in   ) ::   cdname      ! name of the calling subroutine
-      ARRAY_TYPE(:,:,:,:,:)                                        ! array or pointer of arrays on which the boundary condition is applied
-      CHARACTER(len=1)            , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
-      REAL(wp)                    , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
-      CHARACTER(len=3), OPTIONAL  , INTENT(in   ) ::   cd_mpp      ! fill the overlap area only
-      REAL(wp)        , OPTIONAL  , INTENT(in   ) ::   pval        ! background value (used at closed boundaries)
-      !
-      INTEGER  ::    ji,  jj,  jk,  jl, jh, jf   ! dummy loop indices
-      INTEGER  ::   ipi, ipj, ipk, ipl, ipf      ! dimension of the input array
-      REAL(wp) ::   zland
-      LOGICAL  ::   ll_nfd
-      !!----------------------------------------------------------------------
-      !
-      ipk = K_SIZE(ptab)   ! 3rd dimension
-      ipl = L_SIZE(ptab)   ! 4th    -
-      ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
-      !
-      ll_nfd    = jperio==3 .OR. jperio==4 .OR. jperio==5 .OR. jperio==6
-      !
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0._wp     ! zero by default
-      ENDIF
-
-      ! ------------------------------- !
-      !   standard boundary treatment   !    ! CAUTION: semi-column notation is often impossible
-      ! ------------------------------- !
-      !
-      IF( .NOT. PRESENT( cd_mpp ) ) THEN  !==  standard close or cyclic treatment  ==!
-         !
-         DO jf = 1, ipf                   ! number of arrays to be treated
-            !
-            !                                ! East-West boundaries
-            IF( l_Iperio ) THEN                   !* cyclic
-               ARRAY_IN( 1 ,:,:,:,jf) = ARRAY_IN(jpim1,:,:,:,jf)
-               ARRAY_IN(jpi,:,:,:,jf) = ARRAY_IN(  2  ,:,:,:,jf)
-            ELSE                                   !* closed
-               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN( 1 ,:,:,:,jf) = zland    ! east except F-point
-                                               ARRAY_IN(jpi,:,:,:,jf) = zland    ! west
-            ENDIF
-            !                                ! North-South boundaries
-            IF( l_Jperio ) THEN                   !* cyclic
-               ARRAY_IN(:, 1 ,:,:,jf) = ARRAY_IN(:, jpjm1,:,:,jf)
-               ARRAY_IN(:,jpj,:,:,jf) = ARRAY_IN(:,   2  ,:,:,jf)
-            ELSEIF( ll_nfd ) THEN                  !* north fold
-               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:, 1 ,:,:,jf) = zland    ! south except F-point
-               CALL lbc_nfd( ptab, NAT_IN(:), SGN_IN(:) OPT_K(:) )                       ! north fold treatment         
-            ELSE                                   !* closed
-               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:, 1 ,:,:,jf) = zland    ! south except F-point
-                                               ARRAY_IN(:,jpj,:,:,jf) = zland    ! north
-            ENDIF
-            !
-         END DO
-         !
-      ENDIF
-      !
-   END SUBROUTINE ROUTINE_LNK
-
-#undef ARRAY_TYPE
-#undef NAT_IN
-#undef SGN_IN
-#undef ARRAY_IN
-#undef K_SIZE
-#undef L_SIZE
-#undef F_SIZE
-#undef OPT_K
Index: /NEMO/trunk/src/OCE/LBC/lbc_lnk_multi_generic.h90
===================================================================
--- /NEMO/trunk/src/OCE/LBC/lbc_lnk_multi_generic.h90	(revision 11535)
+++ /NEMO/trunk/src/OCE/LBC/lbc_lnk_multi_generic.h90	(revision 11536)
@@ -14,23 +14,27 @@
 #   define PTR_ptab              pt4d
 #endif
-   SUBROUTINE ROUTINE_MULTI( cdname                                                    &
-      &                    , pt1, cdna1, psgn1, pt2, cdna2, psgn2, pt3, cdna3, psgn3   &
-      &                    , pt4, cdna4, psgn4, pt5, cdna5, psgn5, pt6, cdna6, psgn6   &
-      &                    , pt7, cdna7, psgn7, pt8, cdna8, psgn8, pt9, cdna9, psgn9, cd_mpp, pval)
+
+   SUBROUTINE ROUTINE_MULTI( cdname                                                                             &
+      &                    , pt1, cdna1, psgn1, pt2 , cdna2 , psgn2 , pt3 , cdna3 , psgn3 , pt4, cdna4, psgn4   &
+      &                    , pt5, cdna5, psgn5, pt6 , cdna6 , psgn6 , pt7 , cdna7 , psgn7 , pt8, cdna8, psgn8   &
+      &                    , pt9, cdna9, psgn9, pt10, cdna10, psgn10, pt11, cdna11, psgn11                      &
+      &                    , kfillmode, pfillval, lsend, lrecv, ihlcom )
       !!---------------------------------------------------------------------
-      CHARACTER(len=*)   ,                   INTENT(in   ) ::   cdname  ! name of the calling subroutine
-      ARRAY_TYPE(:,:,:,:)          , TARGET, INTENT(inout) ::   pt1     ! arrays on which the lbc is applied
-      ARRAY_TYPE(:,:,:,:), OPTIONAL, TARGET, INTENT(inout) ::   pt2  ,  pt3  , pt4  , pt5  , pt6  , pt7  , pt8  , pt9
-      CHARACTER(len=1)                     , INTENT(in   ) ::   cdna1   ! nature of pt2D. array grid-points
-      CHARACTER(len=1)   , OPTIONAL        , INTENT(in   ) ::   cdna2,  cdna3, cdna4, cdna5, cdna6, cdna7, cdna8, cdna9
-      REAL(wp)                             , INTENT(in   ) ::   psgn1   ! sign used across the north fold
-      REAL(wp)           , OPTIONAL        , INTENT(in   ) ::   psgn2,  psgn3, psgn4, psgn5, psgn6, psgn7, psgn8, psgn9   
-      CHARACTER(len=3)   , OPTIONAL        , INTENT(in   ) ::   cd_mpp  ! fill the overlap area only
-      REAL(wp)           , OPTIONAL        , INTENT(in   ) ::   pval    ! background value (used at closed boundaries)
+      CHARACTER(len=*)   ,                   INTENT(in   ) :: cdname  ! name of the calling subroutine
+      ARRAY_TYPE(:,:,:,:)          , TARGET, INTENT(inout) :: pt1     ! arrays on which the lbc is applied
+      ARRAY_TYPE(:,:,:,:), OPTIONAL, TARGET, INTENT(inout) :: pt2  , pt3  , pt4  , pt5  , pt6  , pt7  , pt8  , pt9  , pt10  , pt11
+      CHARACTER(len=1)                     , INTENT(in   ) :: cdna1   ! nature of pt2D. array grid-points
+      CHARACTER(len=1)   , OPTIONAL        , INTENT(in   ) :: cdna2, cdna3, cdna4, cdna5, cdna6, cdna7, cdna8, cdna9, cdna10, cdna11
+      REAL(wp)                             , INTENT(in   ) :: psgn1   ! sign used across the north fold
+      REAL(wp)           , OPTIONAL        , INTENT(in   ) :: psgn2, psgn3, psgn4, psgn5, psgn6, psgn7, psgn8, psgn9, psgn10, psgn11
+      INTEGER            , OPTIONAL        , INTENT(in   ) :: kfillmode   ! filling method for halo over land (default = constant)
+      REAL(wp)           , OPTIONAL        , INTENT(in   ) :: pfillval    ! background value (used at closed boundaries)
+      LOGICAL, DIMENSION(4), OPTIONAL      , INTENT(in   ) :: lsend, lrecv   ! indicate how communications are to be carried out
+      INTEGER            , OPTIONAL        , INTENT(in   ) :: ihlcom         ! number of ranks and rows to be communicated
       !!
-      INTEGER                         ::   kfld        ! number of elements that will be attributed
-      PTR_TYPE         , DIMENSION(9) ::   ptab_ptr    ! pointer array
-      CHARACTER(len=1) , DIMENSION(9) ::   cdna_ptr    ! nature of ptab_ptr grid-points
-      REAL(wp)         , DIMENSION(9) ::   psgn_ptr    ! sign used across the north fold boundary
+      INTEGER                          ::   kfld        ! number of elements that will be attributed
+      PTR_TYPE         , DIMENSION(11) ::   ptab_ptr    ! pointer array
+      CHARACTER(len=1) , DIMENSION(11) ::   cdna_ptr    ! nature of ptab_ptr grid-points
+      REAL(wp)         , DIMENSION(11) ::   psgn_ptr    ! sign used across the north fold boundary
       !!---------------------------------------------------------------------
       !
@@ -41,14 +45,16 @@
       !
       !                 ! Look if more arrays are added
-      IF( PRESENT(psgn2) )   CALL ROUTINE_LOAD( pt2, cdna2, psgn2, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
-      IF( PRESENT(psgn3) )   CALL ROUTINE_LOAD( pt3, cdna3, psgn3, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
-      IF( PRESENT(psgn4) )   CALL ROUTINE_LOAD( pt4, cdna4, psgn4, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
-      IF( PRESENT(psgn5) )   CALL ROUTINE_LOAD( pt5, cdna5, psgn5, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
-      IF( PRESENT(psgn6) )   CALL ROUTINE_LOAD( pt6, cdna6, psgn6, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
-      IF( PRESENT(psgn7) )   CALL ROUTINE_LOAD( pt7, cdna7, psgn7, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
-      IF( PRESENT(psgn8) )   CALL ROUTINE_LOAD( pt8, cdna8, psgn8, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
-      IF( PRESENT(psgn9) )   CALL ROUTINE_LOAD( pt9, cdna9, psgn9, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn2 ) )   CALL ROUTINE_LOAD( pt2 , cdna2 , psgn2 , ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn3 ) )   CALL ROUTINE_LOAD( pt3 , cdna3 , psgn3 , ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn4 ) )   CALL ROUTINE_LOAD( pt4 , cdna4 , psgn4 , ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn5 ) )   CALL ROUTINE_LOAD( pt5 , cdna5 , psgn5 , ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn6 ) )   CALL ROUTINE_LOAD( pt6 , cdna6 , psgn6 , ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn7 ) )   CALL ROUTINE_LOAD( pt7 , cdna7 , psgn7 , ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn8 ) )   CALL ROUTINE_LOAD( pt8 , cdna8 , psgn8 , ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn9 ) )   CALL ROUTINE_LOAD( pt9 , cdna9 , psgn9 , ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn10) )   CALL ROUTINE_LOAD( pt10, cdna10, psgn10, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn11) )   CALL ROUTINE_LOAD( pt11, cdna11, psgn11, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
       !
-      CALL lbc_lnk_ptr( cdname, ptab_ptr, cdna_ptr, psgn_ptr, kfld, cd_mpp, pval )
+      CALL lbc_lnk_ptr    ( cdname,               ptab_ptr, cdna_ptr, psgn_ptr, kfld, kfillmode, pfillval, lsend, lrecv, ihlcom )
       !
    END SUBROUTINE ROUTINE_MULTI
@@ -72,4 +78,5 @@
       !
    END SUBROUTINE ROUTINE_LOAD
+
 #undef ARRAY_TYPE
 #undef PTR_TYPE
Index: /NEMO/trunk/src/OCE/LBC/lbc_nfd_nogather_generic.h90
===================================================================
--- /NEMO/trunk/src/OCE/LBC/lbc_nfd_nogather_generic.h90	(revision 11535)
+++ /NEMO/trunk/src/OCE/LBC/lbc_nfd_nogather_generic.h90	(revision 11536)
@@ -74,9 +74,5 @@
       !
       ! Security check for further developments
-      IF ( ipf > 1 ) THEN
-        write(6,*) 'lbc_nfd_nogather: multiple fields not allowed. Revise implementation' 
-        write(6,*) 'You should not be there...' 
-        STOP
-      ENDIF
+      IF ( ipf > 1 ) CALL ctl_stop( 'STOP', 'lbc_nfd_nogather: multiple fields not allowed. Revise implementation...' )
       !
       ijpj   = 1    ! index of first modified line 
Index: /NEMO/trunk/src/OCE/LBC/lbclnk.F90
===================================================================
--- /NEMO/trunk/src/OCE/LBC/lbclnk.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/LBC/lbclnk.F90	(revision 11536)
@@ -14,8 +14,4 @@
    !!             -   ! 2017-05  (G. Madec) create generic.h90 files to generate all lbc and north fold routines
    !!----------------------------------------------------------------------
-#if defined key_mpp_mpi
-   !!----------------------------------------------------------------------
-   !!   'key_mpp_mpi'             MPI massively parallel processing library
-   !!----------------------------------------------------------------------
    !!           define the generic interfaces of lib_mpp routines
    !!----------------------------------------------------------------------
@@ -23,7 +19,11 @@
    !!   lbc_bdy_lnk   : generic interface for mpp_lnk_bdy_2d and mpp_lnk_bdy_3d routines defined in lib_mpp
    !!----------------------------------------------------------------------
-   USE par_oce        ! ocean dynamics and tracers   
+   USE dom_oce        ! ocean space and time domain
    USE lib_mpp        ! distributed memory computing library
    USE lbcnfd         ! north fold
+   USE in_out_manager ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
 
    INTERFACE lbc_lnk
@@ -37,16 +37,28 @@
    END INTERFACE
    !
-   INTERFACE lbc_bdy_lnk
-      MODULE PROCEDURE mpp_lnk_bdy_2d, mpp_lnk_bdy_3d, mpp_lnk_bdy_4d
-   END INTERFACE
-   !
    INTERFACE lbc_lnk_icb
       MODULE PROCEDURE mpp_lnk_2d_icb
    END INTERFACE
 
+   INTERFACE mpp_nfd
+      MODULE PROCEDURE   mpp_nfd_2d    , mpp_nfd_3d    , mpp_nfd_4d
+      MODULE PROCEDURE   mpp_nfd_2d_ptr, mpp_nfd_3d_ptr, mpp_nfd_4d_ptr
+   END INTERFACE
+
    PUBLIC   lbc_lnk       ! ocean/ice lateral boundary conditions
    PUBLIC   lbc_lnk_multi ! modified ocean/ice lateral boundary conditions
-   PUBLIC   lbc_bdy_lnk   ! ocean lateral BDY boundary conditions
    PUBLIC   lbc_lnk_icb   ! iceberg lateral boundary conditions
+
+#if   defined key_mpp_mpi
+!$AGRIF_DO_NOT_TREAT
+   INCLUDE 'mpif.h'
+!$AGRIF_END_DO_NOT_TREAT
+#endif
+
+   INTEGER, PUBLIC, PARAMETER ::   jpfillnothing = 1
+   INTEGER, PUBLIC, PARAMETER ::   jpfillcst     = 2
+   INTEGER, PUBLIC, PARAMETER ::   jpfillcopy    = 3
+   INTEGER, PUBLIC, PARAMETER ::   jpfillperio   = 4
+   INTEGER, PUBLIC, PARAMETER ::   jpfillmpi     = 5
 
    !!----------------------------------------------------------------------
@@ -56,181 +68,4 @@
    !!----------------------------------------------------------------------
 CONTAINS
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                              shared memory computing
-   !!----------------------------------------------------------------------
-   !!                routines setting the appropriate values
-   !!         on first and last row and column of the global domain
-   !!----------------------------------------------------------------------
-   !!   lbc_lnk_sum_3d: compute sum over the halos on a 3D variable on ocean mesh
-   !!   lbc_lnk_sum_3d: compute sum over the halos on a 2D variable on ocean mesh
-   !!   lbc_lnk       : generic interface for lbc_lnk_3d and lbc_lnk_2d
-   !!   lbc_lnk_3d    : set the lateral boundary condition on a 3D variable on ocean mesh
-   !!   lbc_lnk_2d    : set the lateral boundary condition on a 2D variable on ocean mesh
-   !!   lbc_bdy_lnk   : set the lateral BDY boundary condition
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers   
-   USE dom_oce        ! ocean space and time domain 
-   USE in_out_manager ! I/O manager
-   USE lbcnfd         ! north fold
-
-   IMPLICIT NONE
-   PRIVATE
-
-   INTERFACE lbc_lnk
-      MODULE PROCEDURE   lbc_lnk_2d      , lbc_lnk_3d      , lbc_lnk_4d
-   END INTERFACE
-   INTERFACE lbc_lnk_ptr
-      MODULE PROCEDURE   lbc_lnk_2d_ptr  , lbc_lnk_3d_ptr  , lbc_lnk_4d_ptr
-   END INTERFACE
-   INTERFACE lbc_lnk_multi
-      MODULE PROCEDURE   lbc_lnk_2d_multi, lbc_lnk_3d_multi, lbc_lnk_4d_multi
-   END INTERFACE
-   !
-   INTERFACE lbc_bdy_lnk
-      MODULE PROCEDURE lbc_bdy_lnk_2d, lbc_bdy_lnk_3d, lbc_bdy_lnk_4d
-   END INTERFACE
-   !
-   INTERFACE lbc_lnk_icb
-      MODULE PROCEDURE lbc_lnk_2d_icb
-   END INTERFACE
-   
-   PUBLIC   lbc_lnk       ! ocean/ice  lateral boundary conditions
-   PUBLIC   lbc_lnk_multi ! modified ocean/ice lateral boundary conditions
-   PUBLIC   lbc_bdy_lnk   ! ocean lateral BDY boundary conditions
-   PUBLIC   lbc_lnk_icb   ! iceberg lateral boundary conditions
-   
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id$
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   !!======================================================================
-   !!   Default option                           3D shared memory computing
-   !!======================================================================
-   !!          routines setting land point, or east-west cyclic,
-   !!             or north-south cyclic, or north fold values
-   !!         on first and last row and column of the global domain
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!                   ***  routine lbc_lnk_(2,3,4)d  ***
-   !!
-   !!   * Argument : dummy argument use in lbc_lnk_... routines
-   !!                ptab   :   array or pointer of arrays on which the boundary condition is applied
-   !!                cd_nat :   nature of array grid-points
-   !!                psgn   :   sign used across the north fold boundary
-   !!                kfld   :   optional, number of pt3d arrays
-   !!                cd_mpp :   optional, fill the overlap area only
-   !!                pval   :   optional, background value (used at closed boundaries)
-   !!----------------------------------------------------------------------
-   !
-   !                       !==  2D array and array of 2D pointer  ==!
-   !
-#  define DIM_2d
-#     define ROUTINE_LNK           lbc_lnk_2d
-#     include "lbc_lnk_generic.h90"
-#     undef ROUTINE_LNK
-#     define MULTI
-#     define ROUTINE_LNK           lbc_lnk_2d_ptr
-#     include "lbc_lnk_generic.h90"
-#     undef ROUTINE_LNK
-#     undef MULTI
-#  undef DIM_2d
-   !
-   !                       !==  3D array and array of 3D pointer  ==!
-   !
-#  define DIM_3d
-#     define ROUTINE_LNK           lbc_lnk_3d
-#     include "lbc_lnk_generic.h90"
-#     undef ROUTINE_LNK
-#     define MULTI
-#     define ROUTINE_LNK           lbc_lnk_3d_ptr
-#     include "lbc_lnk_generic.h90"
-#     undef ROUTINE_LNK
-#     undef MULTI
-#  undef DIM_3d
-   !
-   !                       !==  4D array and array of 4D pointer  ==!
-   !
-#  define DIM_4d
-#     define ROUTINE_LNK           lbc_lnk_4d
-#     include "lbc_lnk_generic.h90"
-#     undef ROUTINE_LNK
-#     define MULTI
-#     define ROUTINE_LNK           lbc_lnk_4d_ptr
-#     include "lbc_lnk_generic.h90"
-#     undef ROUTINE_LNK
-#     undef MULTI
-#  undef DIM_4d
-   
-   !!======================================================================
-   !!   identical routines in both C1D and shared memory computing
-   !!======================================================================
-
-   !!----------------------------------------------------------------------
-   !!                   ***  routine lbc_bdy_lnk_(2,3,4)d  ***
-   !!
-   !!   wrapper rountine to 'lbc_lnk_3d'. This wrapper is used
-   !!   to maintain the same interface with regards to the mpp case
-   !!----------------------------------------------------------------------
-   
-   SUBROUTINE lbc_bdy_lnk_4d( cdname, pt4d, cd_type, psgn, ib_bdy )
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*)          , INTENT(in   ) ::   cdname      ! name of the calling subroutine
-      REAL(wp), DIMENSION(:,:,:,:), INTENT(inout) ::   pt4d      ! 3D array on which the lbc is applied
-      CHARACTER(len=1)          , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp)                  , INTENT(in   ) ::   psgn      ! sign used across north fold 
-      INTEGER                   , INTENT(in   ) ::   ib_bdy    ! BDY boundary set
-      !!----------------------------------------------------------------------
-      CALL lbc_lnk_4d( cdname, pt4d, cd_type, psgn)
-   END SUBROUTINE lbc_bdy_lnk_4d
-
-   SUBROUTINE lbc_bdy_lnk_3d( cdname, pt3d, cd_type, psgn, ib_bdy )
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*)          , INTENT(in   ) ::   cdname      ! name of the calling subroutine
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pt3d      ! 3D array on which the lbc is applied
-      CHARACTER(len=1)          , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp)                  , INTENT(in   ) ::   psgn      ! sign used across north fold 
-      INTEGER                   , INTENT(in   ) ::   ib_bdy    ! BDY boundary set
-      !!----------------------------------------------------------------------
-      CALL lbc_lnk_3d( cdname, pt3d, cd_type, psgn)
-   END SUBROUTINE lbc_bdy_lnk_3d
-
-
-   SUBROUTINE lbc_bdy_lnk_2d( cdname, pt2d, cd_type, psgn, ib_bdy )
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*)        , INTENT(in   ) ::   cdname      ! name of the calling subroutine
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2d      ! 3D array on which the lbc is applied
-      CHARACTER(len=1)        , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp)                , INTENT(in   ) ::   psgn      ! sign used across north fold 
-      INTEGER                 , INTENT(in   ) ::   ib_bdy    ! BDY boundary set
-      !!----------------------------------------------------------------------
-      CALL lbc_lnk_2d( cdname, pt2d, cd_type, psgn)
-   END SUBROUTINE lbc_bdy_lnk_2d
-
-
-!!gm  This routine should be removed with an optional halos size added in argument of generic routines
-
-   SUBROUTINE lbc_lnk_2d_icb( cdname, pt2d, cd_type, psgn, ki, kj )
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*)        , INTENT(in   ) ::   cdname      ! name of the calling subroutine
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2d      ! 2D array on which the lbc is applied
-      CHARACTER(len=1)        , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp)                , INTENT(in   ) ::   psgn      ! sign used across north fold 
-      INTEGER                 , INTENT(in   ) ::   ki, kj    ! sizes of extra halo (not needed in non-mpp)
-      !!----------------------------------------------------------------------
-      CALL lbc_lnk_2d( cdname, pt2d, cd_type, psgn )
-   END SUBROUTINE lbc_lnk_2d_icb
-!!gm end
-
-#endif
-
-   !!======================================================================
-   !!   identical routines in both distributed and shared memory computing
-   !!======================================================================
 
    !!----------------------------------------------------------------------
@@ -256,6 +91,6 @@
 
 #  define DIM_2d
+#     define ROUTINE_LOAD           load_ptr_2d
 #     define ROUTINE_MULTI          lbc_lnk_2d_multi
-#     define ROUTINE_LOAD           load_ptr_2d
 #     include "lbc_lnk_multi_generic.h90"
 #     undef ROUTINE_MULTI
@@ -263,8 +98,7 @@
 #  undef DIM_2d
 
-
 #  define DIM_3d
+#     define ROUTINE_LOAD           load_ptr_3d
 #     define ROUTINE_MULTI          lbc_lnk_3d_multi
-#     define ROUTINE_LOAD           load_ptr_3d
 #     include "lbc_lnk_multi_generic.h90"
 #     undef ROUTINE_MULTI
@@ -272,8 +106,7 @@
 #  undef DIM_3d
 
-
 #  define DIM_4d
+#     define ROUTINE_LOAD           load_ptr_4d
 #     define ROUTINE_MULTI          lbc_lnk_4d_multi
-#     define ROUTINE_LOAD           load_ptr_4d
 #     include "lbc_lnk_multi_generic.h90"
 #     undef ROUTINE_MULTI
@@ -281,5 +114,394 @@
 #  undef DIM_4d
 
+   !!----------------------------------------------------------------------
+   !!                   ***  routine mpp_lnk_(2,3,4)d  ***
+   !!
+   !!   * Argument : dummy argument use in mpp_lnk_... routines
+   !!                ptab      :   array or pointer of arrays on which the boundary condition is applied
+   !!                cd_nat    :   nature of array grid-points
+   !!                psgn      :   sign used across the north fold boundary
+   !!                kfld      :   optional, number of pt3d arrays
+   !!                kfillmode :   optional, method to be use to fill the halos (see jpfill* variables)
+   !!                pfillval  :   optional, background value (used with jpfillcopy)
+   !!----------------------------------------------------------------------
+   !
+   !                       !==  2D array and array of 2D pointer  ==!
+   !
+#  define DIM_2d
+#     define ROUTINE_LNK           mpp_lnk_2d
+#     include "mpp_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     define MULTI
+#     define ROUTINE_LNK           mpp_lnk_2d_ptr
+#     include "mpp_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     undef MULTI
+#  undef DIM_2d
+   !
+   !                       !==  3D array and array of 3D pointer  ==!
+   !
+#  define DIM_3d
+#     define ROUTINE_LNK           mpp_lnk_3d
+#     include "mpp_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     define MULTI
+#     define ROUTINE_LNK           mpp_lnk_3d_ptr
+#     include "mpp_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     undef MULTI
+#  undef DIM_3d
+   !
+   !                       !==  4D array and array of 4D pointer  ==!
+   !
+#  define DIM_4d
+#     define ROUTINE_LNK           mpp_lnk_4d
+#     include "mpp_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     define MULTI
+#     define ROUTINE_LNK           mpp_lnk_4d_ptr
+#     include "mpp_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     undef MULTI
+#  undef DIM_4d
+
+   !!----------------------------------------------------------------------
+   !!                   ***  routine mpp_nfd_(2,3,4)d  ***
+   !!
+   !!   * Argument : dummy argument use in mpp_nfd_... routines
+   !!                ptab      :   array or pointer of arrays on which the boundary condition is applied
+   !!                cd_nat    :   nature of array grid-points
+   !!                psgn      :   sign used across the north fold boundary
+   !!                kfld      :   optional, number of pt3d arrays
+   !!                kfillmode :   optional, method to be use to fill the halos (see jpfill* variables)
+   !!                pfillval  :   optional, background value (used with jpfillcopy)
+   !!----------------------------------------------------------------------
+   !
+   !                       !==  2D array and array of 2D pointer  ==!
+   !
+#  define DIM_2d
+#     define ROUTINE_NFD           mpp_nfd_2d
+#     include "mpp_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     define MULTI
+#     define ROUTINE_NFD           mpp_nfd_2d_ptr
+#     include "mpp_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     undef MULTI
+#  undef DIM_2d
+   !
+   !                       !==  3D array and array of 3D pointer  ==!
+   !
+#  define DIM_3d
+#     define ROUTINE_NFD           mpp_nfd_3d
+#     include "mpp_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     define MULTI
+#     define ROUTINE_NFD           mpp_nfd_3d_ptr
+#     include "mpp_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     undef MULTI
+#  undef DIM_3d
+   !
+   !                       !==  4D array and array of 4D pointer  ==!
+   !
+#  define DIM_4d
+#     define ROUTINE_NFD           mpp_nfd_4d
+#     include "mpp_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     define MULTI
+#     define ROUTINE_NFD           mpp_nfd_4d_ptr
+#     include "mpp_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     undef MULTI
+#  undef DIM_4d
+
+
    !!======================================================================
+
+
+
+   SUBROUTINE mpp_lbc_north_icb( pt2d, cd_type, psgn, kextj)
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_icb  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
+      !!              in mpp configuration in case of jpn1 > 1 and for 2d
+      !!              array with outer extra halo
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather
+      !!              the 4+kextj northern lines of the global domain on 1
+      !!              processor and apply lbc north-fold on this sub array.
+      !!              Then we scatter the north fold array back to the processors.
+      !!              This routine accounts for an extra halo with icebergs
+      !!              and assumes ghost rows and columns have been suppressed.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2d     ! 2D array with extra halo
+      CHARACTER(len=1)        , INTENT(in   ) ::   cd_type  ! nature of pt3d grid-points
+      !                                                     !   = T ,  U , V , F or W -points
+      REAL(wp)                , INTENT(in   ) ::   psgn     ! = -1. the sign change across the
+      !!                                                    ! north fold, =  1. otherwise
+      INTEGER                 , INTENT(in   ) ::   kextj    ! Extra halo width at north fold
+      !
+      INTEGER ::   ji, jj, jr
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ipj, ij, iproc
+      !
+      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE  ::  ztab_e, znorthloc_e
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE  ::  znorthgloio_e
+      !!----------------------------------------------------------------------
+#if defined key_mpp_mpi
+      !
+      ipj=4
+      ALLOCATE(        ztab_e(jpiglo, 1-kextj:ipj+kextj)       ,       &
+     &            znorthloc_e(jpimax, 1-kextj:ipj+kextj)       ,       &
+     &          znorthgloio_e(jpimax, 1-kextj:ipj+kextj,jpni)    )
+      !
+      ztab_e(:,:)      = 0._wp
+      znorthloc_e(:,:) = 0._wp
+      !
+      ij = 1 - kextj
+      ! put the last ipj+2*kextj lines of pt2d into znorthloc_e 
+      DO jj = jpj - ipj + 1 - kextj , jpj + kextj
+         znorthloc_e(1:jpi,ij)=pt2d(1:jpi,jj)
+         ij = ij + 1
+      END DO
+      !
+      itaille = jpimax * ( ipj + 2*kextj )
+      !
+      IF( ln_timing ) CALL tic_tac(.TRUE.)
+      CALL MPI_ALLGATHER( znorthloc_e(1,1-kextj)    , itaille, MPI_DOUBLE_PRECISION,    &
+         &                znorthgloio_e(1,1-kextj,1), itaille, MPI_DOUBLE_PRECISION,    &
+         &                ncomm_north, ierr )
+      !
+      IF( ln_timing ) CALL tic_tac(.FALSE.)
+      !
+      DO jr = 1, ndim_rank_north            ! recover the global north array
+         iproc = nrank_north(jr) + 1
+         ildi = nldit (iproc)
+         ilei = nleit (iproc)
+         iilb = nimppt(iproc)
+         DO jj = 1-kextj, ipj+kextj
+            DO ji = ildi, ilei
+               ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
+            END DO
+         END DO
+      END DO
+
+      ! 2. North-Fold boundary conditions
+      ! ----------------------------------
+      CALL lbc_nfd( ztab_e(:,1-kextj:ipj+kextj), cd_type, psgn, kextj )
+
+      ij = 1 - kextj
+      !! Scatter back to pt2d
+      DO jj = jpj - ipj + 1 - kextj , jpj + kextj
+         DO ji= 1, jpi
+            pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
+         END DO
+         ij  = ij +1
+      END DO
+      !
+      DEALLOCATE( ztab_e, znorthloc_e, znorthgloio_e )
+      !
+#endif
+   END SUBROUTINE mpp_lbc_north_icb
+
+
+   SUBROUTINE mpp_lnk_2d_icb( cdname, pt2d, cd_type, psgn, kexti, kextj )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_2d_icb  ***
+      !!
+      !! ** Purpose :   Message passing management for 2d array (with extra halo for icebergs)
+      !!                This routine receives a (1-kexti:jpi+kexti,1-kexti:jpj+kextj)
+      !!                array (usually (0:jpi+1, 0:jpj+1)) from lbc_lnk_icb calls.
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    jpi    : first dimension of the local subdomain
+      !!                    jpj    : second dimension of the local subdomain
+      !!                    kexti  : number of columns for extra outer halo
+      !!                    kextj  : number of rows for extra outer halo
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*)                                        , INTENT(in   ) ::   cdname      ! name of the calling subroutine
+      REAL(wp), DIMENSION(1-kexti:jpi+kexti,1-kextj:jpj+kextj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
+      CHARACTER(len=1)                                        , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
+      REAL(wp)                                                , INTENT(in   ) ::   psgn     ! sign used across the north fold
+      INTEGER                                                 , INTENT(in   ) ::   kexti    ! extra i-halo width
+      INTEGER                                                 , INTENT(in   ) ::   kextj    ! extra j-halo width
+      !
+      INTEGER  ::   jl   ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! local integers
+      INTEGER  ::   ipreci, iprecj             !   -       -
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !!
+      REAL(wp), DIMENSION(1-kexti:jpi+kexti,nn_hls+kextj,2) ::   r2dns, r2dsn
+      REAL(wp), DIMENSION(1-kextj:jpj+kextj,nn_hls+kexti,2) ::   r2dwe, r2dew
+      !!----------------------------------------------------------------------
+
+      ipreci = nn_hls + kexti      ! take into account outer extra 2D overlap area
+      iprecj = nn_hls + kextj
+
+      IF( narea == 1 .AND. numcom == -1 ) CALL mpp_report( cdname, 1, 1, 1, ld_lbc = .TRUE. )
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      ! Order matters Here !!!!
+      !
+      !                                      ! East-West boundaries
+      !                                           !* Cyclic east-west
+      IF( l_Iperio ) THEN
+         pt2d(1-kexti:     1   ,:) = pt2d(jpim1-kexti: jpim1 ,:)       ! east
+         pt2d(  jpi  :jpi+kexti,:) = pt2d(     2     :2+kexti,:)       ! west
+         !
+      ELSE                                        !* closed
+         IF( .NOT. cd_type == 'F' )   pt2d(  1-kexti   :nn_hls   ,:) = 0._wp    ! east except at F-point
+                                      pt2d(jpi-nn_hls+1:jpi+kexti,:) = 0._wp    ! west
+      ENDIF
+      !                                      ! North-South boundaries
+      IF( l_Jperio ) THEN                         !* cyclic (only with no mpp j-split)
+         pt2d(:,1-kextj:     1   ) = pt2d(:,jpjm1-kextj:  jpjm1)       ! north
+         pt2d(:,  jpj  :jpj+kextj) = pt2d(:,     2     :2+kextj)       ! south
+      ELSE                                        !* closed
+         IF( .NOT. cd_type == 'F' )   pt2d(:,  1-kextj   :nn_hls   ) = 0._wp    ! north except at F-point
+                                      pt2d(:,jpj-nn_hls+1:jpj+kextj) = 0._wp    ! south
+      ENDIF
+      !
+
+      ! north fold treatment
+      ! -----------------------
+      IF( npolj /= 0 ) THEN
+         !
+         SELECT CASE ( jpni )
+                   CASE ( 1 )     ;   CALL lbc_nfd          ( pt2d(1:jpi,1:jpj+kextj), cd_type, psgn, kextj )
+                   CASE DEFAULT   ;   CALL mpp_lbc_north_icb( pt2d(1:jpi,1:jpj+kextj), cd_type, psgn, kextj )
+         END SELECT
+         !
+      ENDIF
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = jpi-nreci-kexti
+         DO jl = 1, ipreci
+            r2dew(:,jl,1) = pt2d(nn_hls+jl,:)
+            r2dwe(:,jl,1) = pt2d(iihom +jl,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = ipreci * ( jpj + 2*kextj )
+      !
+      IF( ln_timing ) CALL tic_tac(.TRUE.)
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, r2dwe(1-kextj,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, r2dew(1-kextj,1,2), imigr, noea )
+         CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, r2dew(1-kextj,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, r2dwe(1-kextj,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, r2dew(1-kextj,1,2), imigr, noea )
+         CALL mpprecv( 2, r2dwe(1-kextj,1,2), imigr, nowe )
+         CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, r2dew(1-kextj,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, r2dwe(1-kextj,1,2), imigr, nowe )
+         CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      IF( ln_timing ) CALL tic_tac(.FALSE.)
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = jpi - nn_hls
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, ipreci
+            pt2d(iihom+jl,:) = r2dew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, ipreci
+            pt2d(jl-kexti,:) = r2dwe(:,jl,2)
+            pt2d(iihom+jl,:) = r2dew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, ipreci
+            pt2d(jl-kexti,:) = r2dwe(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = jpj-nrecj-kextj
+         DO jl = 1, iprecj
+            r2dsn(:,jl,1) = pt2d(:,ijhom +jl)
+            r2dns(:,jl,1) = pt2d(:,nn_hls+jl)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = iprecj * ( jpi + 2*kexti )
+      !
+      IF( ln_timing ) CALL tic_tac(.TRUE.)
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, r2dsn(1-kexti,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, r2dns(1-kexti,1,2), imigr, nono )
+         CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, r2dns(1-kexti,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, r2dsn(1-kexti,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, r2dns(1-kexti,1,2), imigr, nono )
+         CALL mpprecv( 4, r2dsn(1-kexti,1,2), imigr, noso )
+         CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, r2dns(1-kexti,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, r2dsn(1-kexti,1,2), imigr, noso )
+         CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      IF( ln_timing ) CALL tic_tac(.FALSE.)
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = jpj - nn_hls
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, iprecj
+            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, iprecj
+            pt2d(:,jl-kextj) = r2dsn(:,jl,2)
+            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, iprecj
+            pt2d(:,jl-kextj) = r2dsn(:,jl,2)
+         END DO
+      END SELECT
+      !
+   END SUBROUTINE mpp_lnk_2d_icb
+   
 END MODULE lbclnk
 
Index: /NEMO/trunk/src/OCE/LBC/lbcnfd.F90
===================================================================
--- /NEMO/trunk/src/OCE/LBC/lbcnfd.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/LBC/lbcnfd.F90	(revision 11536)
@@ -20,4 +20,5 @@
    USE dom_oce        ! ocean space and time domain 
    USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
 
    IMPLICIT NONE
Index: /NEMO/trunk/src/OCE/LBC/lib_mpp.F90
===================================================================
--- /NEMO/trunk/src/OCE/LBC/lib_mpp.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/LBC/lib_mpp.F90	(revision 11536)
@@ -32,12 +32,7 @@
    !!   ctl_opn       : Open file and check if required file is available.
    !!   ctl_nam       : Prints informations when an error occurs while reading a namelist
-   !!   get_unit      : give the index of an unused logical unit
-   !!----------------------------------------------------------------------
-#if   defined key_mpp_mpi
-   !!----------------------------------------------------------------------
-   !!   'key_mpp_mpi'             MPI massively parallel processing library
-   !!----------------------------------------------------------------------
-   !!   lib_mpp_alloc : allocate mpp arrays
-   !!   mynode        : indentify the processor unit
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   mpp_start     : get local communicator its size and rank
    !!   mpp_lnk       : interface (defined in lbclnk) for message passing of 2d or 3d arrays (mpp_lnk_2d, mpp_lnk_3d)
    !!   mpp_lnk_icb   : interface for message passing of 2d arrays with extra halo for icebergs (mpp_lnk_2d_icb)
@@ -57,29 +52,12 @@
    !!----------------------------------------------------------------------
    USE dom_oce        ! ocean space and time domain
-   USE lbcnfd         ! north fold treatment
    USE in_out_manager ! I/O manager
 
    IMPLICIT NONE
    PRIVATE
-
-   INTERFACE mpp_nfd
-      MODULE PROCEDURE   mpp_nfd_2d    , mpp_nfd_3d    , mpp_nfd_4d
-      MODULE PROCEDURE   mpp_nfd_2d_ptr, mpp_nfd_3d_ptr, mpp_nfd_4d_ptr
-   END INTERFACE
-
-   ! Interface associated to the mpp_lnk_... routines is defined in lbclnk
-   PUBLIC   mpp_lnk_2d    , mpp_lnk_3d    , mpp_lnk_4d
-   PUBLIC   mpp_lnk_2d_ptr, mpp_lnk_3d_ptr, mpp_lnk_4d_ptr
    !
-!!gm  this should be useless
-   PUBLIC   mpp_nfd_2d    , mpp_nfd_3d    , mpp_nfd_4d
-   PUBLIC   mpp_nfd_2d_ptr, mpp_nfd_3d_ptr, mpp_nfd_4d_ptr
-!!gm end
-   !
-   PUBLIC   ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam
-   PUBLIC   mynode, mppstop, mppsync, mpp_comm_free
+   PUBLIC   ctl_stop, ctl_warn, ctl_opn, ctl_nam
+   PUBLIC   mpp_start, mppstop, mppsync, mpp_comm_free
    PUBLIC   mpp_ini_north
-   PUBLIC   mpp_lnk_2d_icb
-   PUBLIC   mpp_lbc_north_icb
    PUBLIC   mpp_min, mpp_max, mpp_sum, mpp_minloc, mpp_maxloc
    PUBLIC   mpp_delay_max, mpp_delay_sum, mpp_delay_rcv
@@ -87,5 +65,9 @@
    PUBLIC   mpp_ini_znl
    PUBLIC   mppsend, mpprecv                          ! needed by TAM and ICB routines
-   PUBLIC   mpp_lnk_bdy_2d, mpp_lnk_bdy_3d, mpp_lnk_bdy_4d
+   PUBLIC   mpp_report
+   PUBLIC   tic_tac
+#if ! defined key_mpp_mpi
+   PUBLIC MPI_Wtime
+#endif
    
    !! * Interfaces
@@ -113,9 +95,14 @@
    !!  MPI  variable definition !!
    !! ========================= !!
+#if   defined key_mpp_mpi
 !$AGRIF_DO_NOT_TREAT
    INCLUDE 'mpif.h'
 !$AGRIF_END_DO_NOT_TREAT
-
    LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .TRUE.    !: mpp flag
+#else   
+   INTEGER, PUBLIC, PARAMETER ::   MPI_STATUS_SIZE = 1
+   INTEGER, PUBLIC, PARAMETER ::   MPI_DOUBLE_PRECISION = 8
+   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .FALSE.    !: mpp flag
+#endif
 
    INTEGER, PARAMETER         ::   nprocmax = 2**10   ! maximun dimension (required to be a power of 2)
@@ -145,9 +132,4 @@
    INTEGER, PUBLIC ::   north_root        !: number (in the comm_opa) of proc 0 in the northern comm
    INTEGER, PUBLIC, DIMENSION(:), ALLOCATABLE, SAVE ::   nrank_north   !: dimension ndim_rank_north
-
-   ! Type of send : standard, buffered, immediate
-   CHARACTER(len=1), PUBLIC ::   cn_mpi_send        !: type od mpi send/recieve (S=standard, B=bsend, I=isend)
-   LOGICAL         , PUBLIC ::   l_isend = .FALSE.  !: isend use indicator (T if cn_mpi_send='I')
-   INTEGER         , PUBLIC ::   nn_buffer          !: size of the buffer in case of mpi_bsend
 
    ! Communications summary report
@@ -187,5 +169,5 @@
    LOGICAL, PUBLIC ::   ln_nnogather                !: namelist control of northfold comms
    LOGICAL, PUBLIC ::   l_north_nogather = .FALSE.  !: internal control of northfold comms
-
+   
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
@@ -195,103 +177,30 @@
 CONTAINS
 
-   FUNCTION mynode( ldtxt, ldname, kumnam_ref, kumnam_cfg, kumond, kstop, localComm )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mynode  ***
-      !!
-      !! ** Purpose :   Find processor unit
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*),DIMENSION(:), INTENT(  out) ::   ldtxt        !
-      CHARACTER(len=*)             , INTENT(in   ) ::   ldname       !
-      INTEGER                      , INTENT(in   ) ::   kumnam_ref   ! logical unit for reference namelist
-      INTEGER                      , INTENT(in   ) ::   kumnam_cfg   ! logical unit for configuration namelist
-      INTEGER                      , INTENT(inout) ::   kumond       ! logical unit for namelist output
-      INTEGER                      , INTENT(inout) ::   kstop        ! stop indicator
+   SUBROUTINE mpp_start( localComm )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_start  ***
+      !!
+      !! ** Purpose :   get mpi_comm_oce, mpprank and mppsize
+      !!----------------------------------------------------------------------
       INTEGER         , OPTIONAL   , INTENT(in   ) ::   localComm    !
       !
-      INTEGER ::   mynode, ierr, code, ji, ii, ios
-      LOGICAL ::   mpi_was_called
-      !
-      NAMELIST/nammpp/ cn_mpi_send, nn_buffer, jpni, jpnj, ln_nnogather
-      !!----------------------------------------------------------------------
-      !
-      ii = 1
-      WRITE(ldtxt(ii),*)                                                                  ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'mynode : mpi initialisation'                                    ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~ '                                                        ;   ii = ii + 1
-      !
-      REWIND( kumnam_ref )              ! Namelist nammpp in reference namelist: mpi variables
-      READ  ( kumnam_ref, nammpp, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nammpp in reference namelist', lwp )
-      !
-      REWIND( kumnam_cfg )              ! Namelist nammpp in configuration namelist: mpi variables
-      READ  ( kumnam_cfg, nammpp, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nammpp in configuration namelist', lwp )
-      !
-      !                              ! control print
-      WRITE(ldtxt(ii),*) '   Namelist nammpp'                                             ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      mpi send type          cn_mpi_send = ', cn_mpi_send       ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      size exported buffer   nn_buffer   = ', nn_buffer,' bytes';   ii = ii + 1
-      !
-      IF( jpni < 1 .OR. jpnj < 1  ) THEN
-         WRITE(ldtxt(ii),*) '      jpni and jpnj will be calculated automatically' ;   ii = ii + 1
-      ELSE
-         WRITE(ldtxt(ii),*) '      processor grid extent in i         jpni = ',jpni       ;   ii = ii + 1
-         WRITE(ldtxt(ii),*) '      processor grid extent in j         jpnj = ',jpnj       ;   ii = ii + 1
-      ENDIF
-
-      WRITE(ldtxt(ii),*) '      avoid use of mpi_allgather at the north fold  ln_nnogather = ', ln_nnogather  ; ii = ii + 1
-
-      CALL mpi_initialized ( mpi_was_called, code )
-      IF( code /= MPI_SUCCESS ) THEN
-         DO ji = 1, SIZE(ldtxt)
-            IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-         END DO
-         WRITE(*, cform_err)
-         WRITE(*, *) 'lib_mpp: Error in routine mpi_initialized'
-         CALL mpi_abort( mpi_comm_world, code, ierr )
-      ENDIF
-
-      IF( mpi_was_called ) THEN
-         !
-         SELECT CASE ( cn_mpi_send )
-         CASE ( 'S' )                ! Standard mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'             ;   ii = ii + 1
-         CASE ( 'B' )                ! Buffer mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'              ;   ii = ii + 1
-            IF( Agrif_Root() )   CALL mpi_init_oce( ldtxt, ii, ierr )
-         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'           ;   ii = ii + 1
-            l_isend = .TRUE.
-         CASE DEFAULT
-            WRITE(ldtxt(ii),cform_err)                                                    ;   ii = ii + 1
-            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send     ;   ii = ii + 1
-            kstop = kstop + 1
-         END SELECT
-         !
-      ELSEIF ( PRESENT(localComm) .AND. .NOT. mpi_was_called ) THEN
-         WRITE(ldtxt(ii),cform_err)                                                    ;   ii = ii + 1
-         WRITE(ldtxt(ii),*) ' lib_mpp: You cannot provide a local communicator '          ;   ii = ii + 1
-         WRITE(ldtxt(ii),*) '          without calling MPI_Init before ! '                ;   ii = ii + 1
-         kstop = kstop + 1
-      ELSE
-         SELECT CASE ( cn_mpi_send )
-         CASE ( 'S' )                ! Standard mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'             ;   ii = ii + 1
-            CALL mpi_init( ierr )
-         CASE ( 'B' )                ! Buffer mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'              ;   ii = ii + 1
-            IF( Agrif_Root() )   CALL mpi_init_oce( ldtxt, ii, ierr )
-         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'           ;   ii = ii + 1
-            l_isend = .TRUE.
-            CALL mpi_init( ierr )
-         CASE DEFAULT
-            WRITE(ldtxt(ii),cform_err)                                                    ;   ii = ii + 1
-            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send     ;   ii = ii + 1
-            kstop = kstop + 1
-         END SELECT
-         !
-      ENDIF
-
+      INTEGER ::   ierr
+      LOGICAL ::   llmpi_init
+      !!----------------------------------------------------------------------
+#if defined key_mpp_mpi
+      !
+      CALL mpi_initialized ( llmpi_init, ierr )
+      IF( ierr /= MPI_SUCCESS ) CALL ctl_stop( 'STOP', ' lib_mpp: Error in routine mpi_initialized' )
+
+      IF( .NOT. llmpi_init ) THEN
+         IF( PRESENT(localComm) ) THEN
+            WRITE(ctmp1,*) ' lib_mpp: You cannot provide a local communicator '
+            WRITE(ctmp2,*) '          without calling MPI_Init before ! '
+            CALL ctl_stop( 'STOP', ctmp1, ctmp2 )
+         ENDIF
+         CALL mpi_init( ierr )
+         IF( ierr /= MPI_SUCCESS ) CALL ctl_stop( 'STOP', ' lib_mpp: Error in routine mpi_init' )
+      ENDIF
+       
       IF( PRESENT(localComm) ) THEN
          IF( Agrif_Root() ) THEN
@@ -299,16 +208,9 @@
          ENDIF
       ELSE
-         CALL mpi_comm_dup( mpi_comm_world, mpi_comm_oce, code)
-         IF( code /= MPI_SUCCESS ) THEN
-            DO ji = 1, SIZE(ldtxt)
-               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-            END DO
-            WRITE(*, cform_err)
-            WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
-            CALL mpi_abort( mpi_comm_world, code, ierr )
-         ENDIF
-      ENDIF
-
-#if defined key_agrif
+         CALL mpi_comm_dup( mpi_comm_world, mpi_comm_oce, ierr)
+         IF( ierr /= MPI_SUCCESS ) CALL ctl_stop( 'STOP', ' lib_mpp: Error in routine mpi_comm_dup' )
+      ENDIF
+
+# if defined key_agrif
       IF( Agrif_Root() ) THEN
          CALL Agrif_MPI_Init(mpi_comm_oce)
@@ -316,167 +218,17 @@
          CALL Agrif_MPI_set_grid_comm(mpi_comm_oce)
       ENDIF
-#endif
+# endif
 
       CALL mpi_comm_rank( mpi_comm_oce, mpprank, ierr )
       CALL mpi_comm_size( mpi_comm_oce, mppsize, ierr )
-      mynode = mpprank
-
-      IF( mynode == 0 ) THEN
-         CALL ctl_opn( kumond, TRIM(ldname), 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. , 1 )
-         WRITE(kumond, nammpp)      
-      ENDIF
       !
       CALL MPI_OP_CREATE(DDPDD_MPI, .TRUE., MPI_SUMDD, ierr)
       !
-   END FUNCTION mynode
-
-   !!----------------------------------------------------------------------
-   !!                   ***  routine mpp_lnk_(2,3,4)d  ***
-   !!
-   !!   * Argument : dummy argument use in mpp_lnk_... routines
-   !!                ptab   :   array or pointer of arrays on which the boundary condition is applied
-   !!                cd_nat :   nature of array grid-points
-   !!                psgn   :   sign used across the north fold boundary
-   !!                kfld   :   optional, number of pt3d arrays
-   !!                cd_mpp :   optional, fill the overlap area only
-   !!                pval   :   optional, background value (used at closed boundaries)
-   !!----------------------------------------------------------------------
-   !
-   !                       !==  2D array and array of 2D pointer  ==!
-   !
-#  define DIM_2d
-#     define ROUTINE_LNK           mpp_lnk_2d
-#     include "mpp_lnk_generic.h90"
-#     undef ROUTINE_LNK
-#     define MULTI
-#     define ROUTINE_LNK           mpp_lnk_2d_ptr
-#     include "mpp_lnk_generic.h90"
-#     undef ROUTINE_LNK
-#     undef MULTI
-#  undef DIM_2d
-   !
-   !                       !==  3D array and array of 3D pointer  ==!
-   !
-#  define DIM_3d
-#     define ROUTINE_LNK           mpp_lnk_3d
-#     include "mpp_lnk_generic.h90"
-#     undef ROUTINE_LNK
-#     define MULTI
-#     define ROUTINE_LNK           mpp_lnk_3d_ptr
-#     include "mpp_lnk_generic.h90"
-#     undef ROUTINE_LNK
-#     undef MULTI
-#  undef DIM_3d
-   !
-   !                       !==  4D array and array of 4D pointer  ==!
-   !
-#  define DIM_4d
-#     define ROUTINE_LNK           mpp_lnk_4d
-#     include "mpp_lnk_generic.h90"
-#     undef ROUTINE_LNK
-#     define MULTI
-#     define ROUTINE_LNK           mpp_lnk_4d_ptr
-#     include "mpp_lnk_generic.h90"
-#     undef ROUTINE_LNK
-#     undef MULTI
-#  undef DIM_4d
-
-   !!----------------------------------------------------------------------
-   !!                   ***  routine mpp_nfd_(2,3,4)d  ***
-   !!
-   !!   * Argument : dummy argument use in mpp_nfd_... routines
-   !!                ptab   :   array or pointer of arrays on which the boundary condition is applied
-   !!                cd_nat :   nature of array grid-points
-   !!                psgn   :   sign used across the north fold boundary
-   !!                kfld   :   optional, number of pt3d arrays
-   !!                cd_mpp :   optional, fill the overlap area only
-   !!                pval   :   optional, background value (used at closed boundaries)
-   !!----------------------------------------------------------------------
-   !
-   !                       !==  2D array and array of 2D pointer  ==!
-   !
-#  define DIM_2d
-#     define ROUTINE_NFD           mpp_nfd_2d
-#     include "mpp_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     define MULTI
-#     define ROUTINE_NFD           mpp_nfd_2d_ptr
-#     include "mpp_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     undef MULTI
-#  undef DIM_2d
-   !
-   !                       !==  3D array and array of 3D pointer  ==!
-   !
-#  define DIM_3d
-#     define ROUTINE_NFD           mpp_nfd_3d
-#     include "mpp_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     define MULTI
-#     define ROUTINE_NFD           mpp_nfd_3d_ptr
-#     include "mpp_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     undef MULTI
-#  undef DIM_3d
-   !
-   !                       !==  4D array and array of 4D pointer  ==!
-   !
-#  define DIM_4d
-#     define ROUTINE_NFD           mpp_nfd_4d
-#     include "mpp_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     define MULTI
-#     define ROUTINE_NFD           mpp_nfd_4d_ptr
-#     include "mpp_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     undef MULTI
-#  undef DIM_4d
-
-
-   !!----------------------------------------------------------------------
-   !!                   ***  routine mpp_lnk_bdy_(2,3,4)d  ***
-   !!
-   !!   * Argument : dummy argument use in mpp_lnk_... routines
-   !!                ptab   :   array or pointer of arrays on which the boundary condition is applied
-   !!                cd_nat :   nature of array grid-points
-   !!                psgn   :   sign used across the north fold boundary
-   !!                kb_bdy :   BDY boundary set
-   !!                kfld   :   optional, number of pt3d arrays
-   !!----------------------------------------------------------------------
-   !
-   !                       !==  2D array and array of 2D pointer  ==!
-   !
-#  define DIM_2d
-#     define ROUTINE_BDY           mpp_lnk_bdy_2d
-#     include "mpp_bdy_generic.h90"
-#     undef ROUTINE_BDY
-#  undef DIM_2d
-   !
-   !                       !==  3D array and array of 3D pointer  ==!
-   !
-#  define DIM_3d
-#     define ROUTINE_BDY           mpp_lnk_bdy_3d
-#     include "mpp_bdy_generic.h90"
-#     undef ROUTINE_BDY
-#  undef DIM_3d
-   !
-   !                       !==  4D array and array of 4D pointer  ==!
-   !
-#  define DIM_4d
-#     define ROUTINE_BDY           mpp_lnk_bdy_4d
-#     include "mpp_bdy_generic.h90"
-#     undef ROUTINE_BDY
-#  undef DIM_4d
-
-   !!----------------------------------------------------------------------
-   !!
-   !!   load_array  &   mpp_lnk_2d_9    à generaliser a 3D et 4D
-   
-   
-   !!    mpp_lnk_sum_2d et 3D   ====>>>>>>   à virer du code !!!!
-   
-   
-   !!----------------------------------------------------------------------
-
+#else
+      IF( PRESENT( localComm ) ) mpi_comm_oce = localComm
+      mppsize = 1
+      mpprank = 0
+#endif
+   END SUBROUTINE mpp_start
 
 
@@ -497,13 +249,7 @@
       !!----------------------------------------------------------------------
       !
-      SELECT CASE ( cn_mpi_send )
-      CASE ( 'S' )                ! Standard mpi send (blocking)
-         CALL mpi_send ( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_oce        , iflag )
-      CASE ( 'B' )                ! Buffer mpi send (blocking)
-         CALL mpi_bsend( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_oce        , iflag )
-      CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-         ! be carefull, one more argument here : the mpi request identifier..
-         CALL mpi_isend( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_oce, md_req, iflag )
-      END SELECT
+#if defined key_mpp_mpi
+      CALL mpi_isend( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_oce, md_req, iflag )
+#endif
       !
    END SUBROUTINE mppsend
@@ -527,4 +273,5 @@
       !!----------------------------------------------------------------------
       !
+#if defined key_mpp_mpi
       ! If a specific process number has been passed to the receive call,
       ! use that one. Default is to use mpi_any_source
@@ -533,4 +280,5 @@
       !
       CALL mpi_recv( pmess, kbytes, mpi_double_precision, use_source, ktyp, mpi_comm_oce, istatus, iflag )
+#endif
       !
    END SUBROUTINE mpprecv
@@ -553,6 +301,10 @@
       !
       itaille = jpi * jpj
+#if defined key_mpp_mpi
       CALL mpi_gather( ptab, itaille, mpi_double_precision, pio, itaille     ,   &
          &                            mpi_double_precision, kp , mpi_comm_oce, ierror )
+#else
+      pio(:,:,1) = ptab(:,:)
+#endif
       !
    END SUBROUTINE mppgather
@@ -576,6 +328,10 @@
       itaille = jpi * jpj
       !
+#if defined key_mpp_mpi
       CALL mpi_scatter( pio, itaille, mpi_double_precision, ptab, itaille     ,   &
          &                            mpi_double_precision, kp  , mpi_comm_oce, ierror )
+#else
+      ptab(:,:) = pio(:,:,1)
+#endif
       !
    END SUBROUTINE mppscatter
@@ -601,4 +357,5 @@
       COMPLEX(wp), ALLOCATABLE, DIMENSION(:) ::   ytmp
       !!----------------------------------------------------------------------
+#if defined key_mpp_mpi
       ilocalcomm = mpi_comm_oce
       IF( PRESENT(kcom) )   ilocalcomm = kcom
@@ -639,10 +396,13 @@
 
       ! send y_in into todelay(idvar)%y1d with a non-blocking communication
-#if defined key_mpi2
+# if defined key_mpi2
       IF( ln_timing ) CALL tic_tac( .TRUE., ld_global = .TRUE.)
       CALL  mpi_allreduce( y_in(:), todelay(idvar)%y1d(:), isz, MPI_DOUBLE_COMPLEX, mpi_sumdd, ilocalcomm, ndelayid(idvar), ierr )
       IF( ln_timing ) CALL tic_tac(.FALSE., ld_global = .TRUE.)
+# else
+      CALL mpi_iallreduce( y_in(:), todelay(idvar)%y1d(:), isz, MPI_DOUBLE_COMPLEX, mpi_sumdd, ilocalcomm, ndelayid(idvar), ierr )
+# endif
 #else
-      CALL mpi_iallreduce( y_in(:), todelay(idvar)%y1d(:), isz, MPI_DOUBLE_COMPLEX, mpi_sumdd, ilocalcomm, ndelayid(idvar), ierr )
+      pout(:) = REAL(y_in(:), wp)
 #endif
 
@@ -668,4 +428,5 @@
       INTEGER ::   ierr, ilocalcomm
       !!----------------------------------------------------------------------
+#if defined key_mpp_mpi
       ilocalcomm = mpi_comm_oce
       IF( PRESENT(kcom) )   ilocalcomm = kcom
@@ -702,10 +463,13 @@
 
       ! send p_in into todelay(idvar)%z1d with a non-blocking communication
-#if defined key_mpi2
+# if defined key_mpi2
       IF( ln_timing ) CALL tic_tac( .TRUE., ld_global = .TRUE.)
       CALL  mpi_allreduce( p_in(:), todelay(idvar)%z1d(:), isz, MPI_DOUBLE_PRECISION, mpi_max, ilocalcomm, ndelayid(idvar), ierr )
       IF( ln_timing ) CALL tic_tac(.FALSE., ld_global = .TRUE.)
+# else
+      CALL mpi_iallreduce( p_in(:), todelay(idvar)%z1d(:), isz, MPI_DOUBLE_PRECISION, mpi_max, ilocalcomm, ndelayid(idvar), ierr )
+# endif
 #else
-      CALL mpi_iallreduce( p_in(:), todelay(idvar)%z1d(:), isz, MPI_DOUBLE_PRECISION, mpi_max, ilocalcomm, ndelayid(idvar), ierr )
+      pout(:) = p_in(:)
 #endif
 
@@ -723,4 +487,5 @@
       INTEGER ::   ierr
       !!----------------------------------------------------------------------
+#if defined key_mpp_mpi
       IF( ndelayid(kid) /= -2 ) THEN  
 #if ! defined key_mpi2
@@ -732,4 +497,5 @@
          ndelayid(kid) = -2   ! add flag to know that mpi_wait was already called on kid
       ENDIF
+#endif
    END SUBROUTINE mpp_delay_rcv
 
@@ -890,10 +656,12 @@
       !!-----------------------------------------------------------------------
       !
+#if defined key_mpp_mpi
       CALL mpi_barrier( mpi_comm_oce, ierror )
+#endif
       !
    END SUBROUTINE mppsync
 
 
-   SUBROUTINE mppstop( ldfinal, ld_force_abort ) 
+   SUBROUTINE mppstop( ld_abort ) 
       !!----------------------------------------------------------------------
       !!                  ***  routine mppstop  ***
@@ -902,15 +670,13 @@
       !!
       !!----------------------------------------------------------------------
-      LOGICAL, OPTIONAL, INTENT(in) :: ldfinal    ! source process number
-      LOGICAL, OPTIONAL, INTENT(in) :: ld_force_abort    ! source process number
-      LOGICAL ::   llfinal, ll_force_abort
+      LOGICAL, OPTIONAL, INTENT(in) :: ld_abort    ! source process number
+      LOGICAL ::   ll_abort
       INTEGER ::   info
       !!----------------------------------------------------------------------
-      llfinal = .FALSE.
-      IF( PRESENT(ldfinal) ) llfinal = ldfinal
-      ll_force_abort = .FALSE.
-      IF( PRESENT(ld_force_abort) ) ll_force_abort = ld_force_abort
-      !
-      IF(ll_force_abort) THEN
+      ll_abort = .FALSE.
+      IF( PRESENT(ld_abort) ) ll_abort = ld_abort
+      !
+#if defined key_mpp_mpi
+      IF(ll_abort) THEN
          CALL mpi_abort( MPI_COMM_WORLD )
       ELSE
@@ -918,5 +684,6 @@
          CALL mpi_finalize( info )
       ENDIF
-      IF( .NOT. llfinal ) STOP 123
+#endif
+      IF( ll_abort ) STOP 123
       !
    END SUBROUTINE mppstop
@@ -930,5 +697,7 @@
       !!----------------------------------------------------------------------
       !
+#if defined key_mpp_mpi
       CALL MPI_COMM_FREE(kcom, ierr)
+#endif
       !
    END SUBROUTINE mpp_comm_free
@@ -960,4 +729,5 @@
       INTEGER, ALLOCATABLE, DIMENSION(:) ::   kwork
       !!----------------------------------------------------------------------
+#if defined key_mpp_mpi
       !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ngrp_world     : ', ngrp_world
       !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - mpi_comm_world : ', mpi_comm_world
@@ -965,9 +735,5 @@
       !
       ALLOCATE( kwork(jpnij), STAT=ierr )
-      IF( ierr /= 0 ) THEN
-         WRITE(kumout, cform_err)
-         WRITE(kumout,*) 'mpp_ini_znl : failed to allocate 1D array of length jpnij'
-         CALL mppstop
-      ENDIF
+      IF( ierr /= 0 ) CALL ctl_stop( 'STOP', 'mpp_ini_znl : failed to allocate 1D array of length jpnij')
 
       IF( jpnj == 1 ) THEN
@@ -1031,4 +797,5 @@
 
       DEALLOCATE(kwork)
+#endif
 
    END SUBROUTINE mpp_ini_znl
@@ -1062,4 +829,5 @@
       !!----------------------------------------------------------------------
       !
+#if defined key_mpp_mpi
       njmppmax = MAXVAL( njmppt )
       !
@@ -1093,65 +861,6 @@
       CALL MPI_COMM_CREATE( mpi_comm_oce, ngrp_north, ncomm_north, ierr )
       !
+#endif
    END SUBROUTINE mpp_ini_north
-
-
-   SUBROUTINE mpi_init_oce( ldtxt, ksft, code )
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_init.opa  ***
-      !!
-      !! ** Purpose :: export and attach a MPI buffer for bsend
-      !!
-      !! ** Method  :: define buffer size in namelist, if 0 no buffer attachment
-      !!            but classical mpi_init
-      !!
-      !! History :: 01/11 :: IDRIS initial version for IBM only
-      !!            08/04 :: R. Benshila, generalisation
-      !!---------------------------------------------------------------------
-      CHARACTER(len=*),DIMENSION(:), INTENT(  out) ::   ldtxt
-      INTEGER                      , INTENT(inout) ::   ksft
-      INTEGER                      , INTENT(  out) ::   code
-      INTEGER                                      ::   ierr, ji
-      LOGICAL                                      ::   mpi_was_called
-      !!---------------------------------------------------------------------
-      !
-      CALL mpi_initialized( mpi_was_called, code )      ! MPI initialization
-      IF ( code /= MPI_SUCCESS ) THEN
-         DO ji = 1, SIZE(ldtxt)
-            IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-         END DO
-         WRITE(*, cform_err)
-         WRITE(*, *) ' lib_mpp: Error in routine mpi_initialized'
-         CALL mpi_abort( mpi_comm_world, code, ierr )
-      ENDIF
-      !
-      IF( .NOT. mpi_was_called ) THEN
-         CALL mpi_init( code )
-         CALL mpi_comm_dup( mpi_comm_world, mpi_comm_oce, code )
-         IF ( code /= MPI_SUCCESS ) THEN
-            DO ji = 1, SIZE(ldtxt)
-               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-            END DO
-            WRITE(*, cform_err)
-            WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
-            CALL mpi_abort( mpi_comm_world, code, ierr )
-         ENDIF
-      ENDIF
-      !
-      IF( nn_buffer > 0 ) THEN
-         WRITE(ldtxt(ksft),*) 'mpi_bsend, buffer allocation of  : ', nn_buffer   ;   ksft = ksft + 1
-         ! Buffer allocation and attachment
-         ALLOCATE( tampon(nn_buffer), stat = ierr )
-         IF( ierr /= 0 ) THEN
-            DO ji = 1, SIZE(ldtxt)
-               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-            END DO
-            WRITE(*, cform_err)
-            WRITE(*, *) ' lib_mpp: Error in ALLOCATE', ierr
-            CALL mpi_abort( mpi_comm_world, code, ierr )
-         END IF
-         CALL mpi_buffer_attach( tampon, nn_buffer, code )
-      ENDIF
-      !
-   END SUBROUTINE mpi_init_oce
 
 
@@ -1187,286 +896,4 @@
 
 
-   SUBROUTINE mpp_lbc_north_icb( pt2d, cd_type, psgn, kextj)
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_icb  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
-      !!              in mpp configuration in case of jpn1 > 1 and for 2d
-      !!              array with outer extra halo
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather
-      !!              the 4+kextj northern lines of the global domain on 1
-      !!              processor and apply lbc north-fold on this sub array.
-      !!              Then we scatter the north fold array back to the processors.
-      !!              This routine accounts for an extra halo with icebergs
-      !!              and assumes ghost rows and columns have been suppressed.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)        , INTENT(in   ) ::   cd_type  ! nature of pt3d grid-points
-      !                                                     !   = T ,  U , V , F or W -points
-      REAL(wp)                , INTENT(in   ) ::   psgn     ! = -1. the sign change across the
-      !!                                                    ! north fold, =  1. otherwise
-      INTEGER                 , INTENT(in   ) ::   kextj    ! Extra halo width at north fold
-      !
-      INTEGER ::   ji, jj, jr
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ipj, ij, iproc
-      !
-      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE  ::  ztab_e, znorthloc_e
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE  ::  znorthgloio_e
-      !!----------------------------------------------------------------------
-      !
-      ipj=4
-      ALLOCATE(        ztab_e(jpiglo, 1-kextj:ipj+kextj)       ,       &
-     &            znorthloc_e(jpimax, 1-kextj:ipj+kextj)       ,       &
-     &          znorthgloio_e(jpimax, 1-kextj:ipj+kextj,jpni)    )
-      !
-      ztab_e(:,:)      = 0._wp
-      znorthloc_e(:,:) = 0._wp
-      !
-      ij = 1 - kextj
-      ! put the last ipj+2*kextj lines of pt2d into znorthloc_e 
-      DO jj = jpj - ipj + 1 - kextj , jpj + kextj
-         znorthloc_e(1:jpi,ij)=pt2d(1:jpi,jj)
-         ij = ij + 1
-      END DO
-      !
-      itaille = jpimax * ( ipj + 2*kextj )
-      !
-      IF( ln_timing ) CALL tic_tac(.TRUE.)
-      CALL MPI_ALLGATHER( znorthloc_e(1,1-kextj)    , itaille, MPI_DOUBLE_PRECISION,    &
-         &                znorthgloio_e(1,1-kextj,1), itaille, MPI_DOUBLE_PRECISION,    &
-         &                ncomm_north, ierr )
-      !
-      IF( ln_timing ) CALL tic_tac(.FALSE.)
-      !
-      DO jr = 1, ndim_rank_north            ! recover the global north array
-         iproc = nrank_north(jr) + 1
-         ildi = nldit (iproc)
-         ilei = nleit (iproc)
-         iilb = nimppt(iproc)
-         DO jj = 1-kextj, ipj+kextj
-            DO ji = ildi, ilei
-               ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
-            END DO
-         END DO
-      END DO
-
-      ! 2. North-Fold boundary conditions
-      ! ----------------------------------
-      CALL lbc_nfd( ztab_e(:,1-kextj:ipj+kextj), cd_type, psgn, kextj )
-
-      ij = 1 - kextj
-      !! Scatter back to pt2d
-      DO jj = jpj - ipj + 1 - kextj , jpj + kextj
-         DO ji= 1, jpi
-            pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
-         END DO
-         ij  = ij +1
-      END DO
-      !
-      DEALLOCATE( ztab_e, znorthloc_e, znorthgloio_e )
-      !
-   END SUBROUTINE mpp_lbc_north_icb
-
-
-   SUBROUTINE mpp_lnk_2d_icb( cdname, pt2d, cd_type, psgn, kexti, kextj )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_2d_icb  ***
-      !!
-      !! ** Purpose :   Message passing management for 2d array (with extra halo for icebergs)
-      !!                This routine receives a (1-kexti:jpi+kexti,1-kexti:jpj+kextj)
-      !!                array (usually (0:jpi+1, 0:jpj+1)) from lbc_lnk_icb calls.
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    jpi    : first dimension of the local subdomain
-      !!                    jpj    : second dimension of the local subdomain
-      !!                    kexti  : number of columns for extra outer halo
-      !!                    kextj  : number of rows for extra outer halo
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*)                                        , INTENT(in   ) ::   cdname      ! name of the calling subroutine
-      REAL(wp), DIMENSION(1-kexti:jpi+kexti,1-kextj:jpj+kextj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)                                        , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
-      REAL(wp)                                                , INTENT(in   ) ::   psgn     ! sign used across the north fold
-      INTEGER                                                 , INTENT(in   ) ::   kexti    ! extra i-halo width
-      INTEGER                                                 , INTENT(in   ) ::   kextj    ! extra j-halo width
-      !
-      INTEGER  ::   jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! local integers
-      INTEGER  ::   ipreci, iprecj             !   -       -
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !!
-      REAL(wp), DIMENSION(1-kexti:jpi+kexti,nn_hls+kextj,2) ::   r2dns, r2dsn
-      REAL(wp), DIMENSION(1-kextj:jpj+kextj,nn_hls+kexti,2) ::   r2dwe, r2dew
-      !!----------------------------------------------------------------------
-
-      ipreci = nn_hls + kexti      ! take into account outer extra 2D overlap area
-      iprecj = nn_hls + kextj
-
-      IF( narea == 1 .AND. numcom == -1 ) CALL mpp_report( cdname, 1, 1, 1, ld_lbc = .TRUE. )
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      ! Order matters Here !!!!
-      !
-      !                                      ! East-West boundaries
-      !                                           !* Cyclic east-west
-      IF( l_Iperio ) THEN
-         pt2d(1-kexti:     1   ,:) = pt2d(jpim1-kexti: jpim1 ,:)       ! east
-         pt2d(  jpi  :jpi+kexti,:) = pt2d(     2     :2+kexti,:)       ! west
-         !
-      ELSE                                        !* closed
-         IF( .NOT. cd_type == 'F' )   pt2d(  1-kexti   :nn_hls   ,:) = 0._wp    ! east except at F-point
-                                      pt2d(jpi-nn_hls+1:jpi+kexti,:) = 0._wp    ! west
-      ENDIF
-      !                                      ! North-South boundaries
-      IF( l_Jperio ) THEN                         !* cyclic (only with no mpp j-split)
-         pt2d(:,1-kextj:     1   ) = pt2d(:,jpjm1-kextj:  jpjm1)       ! north
-         pt2d(:,  jpj  :jpj+kextj) = pt2d(:,     2     :2+kextj)       ! south
-      ELSE                                        !* closed
-         IF( .NOT. cd_type == 'F' )   pt2d(:,  1-kextj   :nn_hls   ) = 0._wp    ! north except at F-point
-                                      pt2d(:,jpj-nn_hls+1:jpj+kextj) = 0._wp    ! south
-      ENDIF
-      !
-
-      ! north fold treatment
-      ! -----------------------
-      IF( npolj /= 0 ) THEN
-         !
-         SELECT CASE ( jpni )
-                   CASE ( 1 )     ;   CALL lbc_nfd          ( pt2d(1:jpi,1:jpj+kextj), cd_type, psgn, kextj )
-                   CASE DEFAULT   ;   CALL mpp_lbc_north_icb( pt2d(1:jpi,1:jpj+kextj), cd_type, psgn, kextj )
-         END SELECT
-         !
-      ENDIF
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = jpi-nreci-kexti
-         DO jl = 1, ipreci
-            r2dew(:,jl,1) = pt2d(nn_hls+jl,:)
-            r2dwe(:,jl,1) = pt2d(iihom +jl,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = ipreci * ( jpj + 2*kextj )
-      !
-      IF( ln_timing ) CALL tic_tac(.TRUE.)
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, r2dwe(1-kextj,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, r2dew(1-kextj,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, r2dew(1-kextj,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, r2dwe(1-kextj,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, r2dew(1-kextj,1,2), imigr, noea )
-         CALL mpprecv( 2, r2dwe(1-kextj,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, r2dew(1-kextj,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, r2dwe(1-kextj,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      IF( ln_timing ) CALL tic_tac(.FALSE.)
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = jpi - nn_hls
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, ipreci
-            pt2d(iihom+jl,:) = r2dew(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, ipreci
-            pt2d(jl-kexti,:) = r2dwe(:,jl,2)
-            pt2d(iihom+jl,:) = r2dew(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, ipreci
-            pt2d(jl-kexti,:) = r2dwe(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = jpj-nrecj-kextj
-         DO jl = 1, iprecj
-            r2dsn(:,jl,1) = pt2d(:,ijhom +jl)
-            r2dns(:,jl,1) = pt2d(:,nn_hls+jl)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = iprecj * ( jpi + 2*kexti )
-      !
-      IF( ln_timing ) CALL tic_tac(.TRUE.)
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, r2dsn(1-kexti,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, r2dns(1-kexti,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, r2dns(1-kexti,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, r2dsn(1-kexti,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, r2dns(1-kexti,1,2), imigr, nono )
-         CALL mpprecv( 4, r2dsn(1-kexti,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, r2dns(1-kexti,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, r2dsn(1-kexti,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      IF( ln_timing ) CALL tic_tac(.FALSE.)
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = jpj - nn_hls
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, iprecj
-            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, iprecj
-            pt2d(:,jl-kextj) = r2dsn(:,jl,2)
-            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, iprecj
-            pt2d(:,jl-kextj) = r2dsn(:,jl,2)
-         END DO
-      END SELECT
-      !
-   END SUBROUTINE mpp_lnk_2d_icb
-
-
    SUBROUTINE mpp_report( cdname, kpk, kpl, kpf, ld_lbc, ld_glb, ld_dlg )
       !!----------------------------------------------------------------------
@@ -1484,4 +911,5 @@
       INTEGER ::    ji,  jj,  jk,  jh, jf, jcount   ! dummy loop indices
       !!----------------------------------------------------------------------
+#if defined key_mpp_mpi
       !
       ll_lbc = .FALSE.
@@ -1594,4 +1022,5 @@
          DEALLOCATE(crname_lbc)
       ENDIF
+#endif
    END SUBROUTINE mpp_report
 
@@ -1604,4 +1033,5 @@
     REAL(wp),               SAVE :: tic_ct = 0._wp
     INTEGER :: ii
+#if defined key_mpp_mpi
 
     IF( ncom_stp <= nit000 ) RETURN
@@ -1619,258 +1049,24 @@
        tic_ct = MPI_Wtime()                                                        ! start count tac->tic (waiting time)
     ENDIF
+#endif
     
    END SUBROUTINE tic_tac
 
+#if ! defined key_mpp_mpi
+   SUBROUTINE mpi_wait(request, status, ierror)
+      INTEGER                            , INTENT(in   ) ::   request
+      INTEGER, DIMENSION(MPI_STATUS_SIZE), INTENT(  out) ::   status
+      INTEGER                            , INTENT(  out) ::   ierror
+   END SUBROUTINE mpi_wait
+
    
-#else
-   !!----------------------------------------------------------------------
-   !!   Default case:            Dummy module        share memory computing
-   !!----------------------------------------------------------------------
-   USE in_out_manager
-
-   INTERFACE mpp_sum
-      MODULE PROCEDURE mppsum_int, mppsum_a_int, mppsum_real, mppsum_a_real, mppsum_realdd, mppsum_a_realdd
-   END INTERFACE
-   INTERFACE mpp_max
-      MODULE PROCEDURE mppmax_a_int, mppmax_int, mppmax_a_real, mppmax_real
-   END INTERFACE
-   INTERFACE mpp_min
-      MODULE PROCEDURE mppmin_a_int, mppmin_int, mppmin_a_real, mppmin_real
-   END INTERFACE
-   INTERFACE mpp_minloc
-      MODULE PROCEDURE mpp_minloc2d ,mpp_minloc3d
-   END INTERFACE
-   INTERFACE mpp_maxloc
-      MODULE PROCEDURE mpp_maxloc2d ,mpp_maxloc3d
-   END INTERFACE
-
-   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .FALSE.      !: mpp flag
-   LOGICAL, PUBLIC            ::   ln_nnogather          !: namelist control of northfold comms (needed here in case "key_mpp_mpi" is not used)
-   INTEGER, PUBLIC            ::   mpi_comm_oce          ! opa local communicator
-
-   INTEGER, PARAMETER, PUBLIC               ::   nbdelay = 0   ! make sure we don't enter loops: DO ji = 1, nbdelay
-   CHARACTER(len=32), DIMENSION(1), PUBLIC  ::   c_delaylist = 'empty'
-   CHARACTER(len=32), DIMENSION(1), PUBLIC  ::   c_delaycpnt = 'empty'
-   LOGICAL, PUBLIC                          ::   l_full_nf_update = .TRUE.
-   TYPE ::   DELAYARR
-      REAL(   wp), POINTER, DIMENSION(:) ::  z1d => NULL()
-      COMPLEX(wp), POINTER, DIMENSION(:) ::  y1d => NULL()
-   END TYPE DELAYARR
-   TYPE( DELAYARR ), DIMENSION(1), PUBLIC  ::   todelay              
-   INTEGER,  PUBLIC, DIMENSION(1)           ::   ndelayid = -1
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION lib_mpp_alloc(kumout)          ! Dummy function
-      INTEGER, INTENT(in) ::   kumout
-      lib_mpp_alloc = 0
-   END FUNCTION lib_mpp_alloc
-
-   FUNCTION mynode( ldtxt, ldname, kumnam_ref, knumnam_cfg,  kumond , kstop, localComm ) RESULT (function_value)
-      INTEGER, OPTIONAL            , INTENT(in   ) ::   localComm
-      CHARACTER(len=*),DIMENSION(:) ::   ldtxt
-      CHARACTER(len=*) ::   ldname
-      INTEGER ::   kumnam_ref, knumnam_cfg , kumond , kstop
-      IF( PRESENT( localComm ) ) mpi_comm_oce = localComm
-      function_value = 0
-      IF( .FALSE. )   ldtxt(:) = 'never done'
-      CALL ctl_opn( kumond, TRIM(ldname), 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. , 1 )
-   END FUNCTION mynode
-
-   SUBROUTINE mppsync                       ! Dummy routine
-   END SUBROUTINE mppsync
-
-   !!----------------------------------------------------------------------
-   !!    ***  mppmax_a_int, mppmax_int, mppmax_a_real, mppmax_real  ***
-   !!   
-   !!----------------------------------------------------------------------
-   !!
-#  define OPERATION_MAX
-#  define INTEGER_TYPE
-#  define DIM_0d
-#     define ROUTINE_ALLREDUCE           mppmax_int
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_0d
-#  define DIM_1d
-#     define ROUTINE_ALLREDUCE           mppmax_a_int
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_1d
-#  undef INTEGER_TYPE
-!
-#  define REAL_TYPE
-#  define DIM_0d
-#     define ROUTINE_ALLREDUCE           mppmax_real
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_0d
-#  define DIM_1d
-#     define ROUTINE_ALLREDUCE           mppmax_a_real
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_1d
-#  undef REAL_TYPE
-#  undef OPERATION_MAX
-   !!----------------------------------------------------------------------
-   !!    ***  mppmin_a_int, mppmin_int, mppmin_a_real, mppmin_real  ***
-   !!   
-   !!----------------------------------------------------------------------
-   !!
-#  define OPERATION_MIN
-#  define INTEGER_TYPE
-#  define DIM_0d
-#     define ROUTINE_ALLREDUCE           mppmin_int
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_0d
-#  define DIM_1d
-#     define ROUTINE_ALLREDUCE           mppmin_a_int
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_1d
-#  undef INTEGER_TYPE
-!
-#  define REAL_TYPE
-#  define DIM_0d
-#     define ROUTINE_ALLREDUCE           mppmin_real
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_0d
-#  define DIM_1d
-#     define ROUTINE_ALLREDUCE           mppmin_a_real
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_1d
-#  undef REAL_TYPE
-#  undef OPERATION_MIN
-
-   !!----------------------------------------------------------------------
-   !!    ***  mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real  ***
-   !!   
-   !!   Global sum of 1D array or a variable (integer, real or complex)
-   !!----------------------------------------------------------------------
-   !!
-#  define OPERATION_SUM
-#  define INTEGER_TYPE
-#  define DIM_0d
-#     define ROUTINE_ALLREDUCE           mppsum_int
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_0d
-#  define DIM_1d
-#     define ROUTINE_ALLREDUCE           mppsum_a_int
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_1d
-#  undef INTEGER_TYPE
-!
-#  define REAL_TYPE
-#  define DIM_0d
-#     define ROUTINE_ALLREDUCE           mppsum_real
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_0d
-#  define DIM_1d
-#     define ROUTINE_ALLREDUCE           mppsum_a_real
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_1d
-#  undef REAL_TYPE
-#  undef OPERATION_SUM
-
-#  define OPERATION_SUM_DD
-#  define COMPLEX_TYPE
-#  define DIM_0d
-#     define ROUTINE_ALLREDUCE           mppsum_realdd
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_0d
-#  define DIM_1d
-#     define ROUTINE_ALLREDUCE           mppsum_a_realdd
-#     include "mpp_allreduce_generic.h90"
-#     undef ROUTINE_ALLREDUCE
-#  undef DIM_1d
-#  undef COMPLEX_TYPE
-#  undef OPERATION_SUM_DD
-
-   !!----------------------------------------------------------------------
-   !!    ***  mpp_minloc2d, mpp_minloc3d, mpp_maxloc2d, mpp_maxloc3d
-   !!   
-   !!----------------------------------------------------------------------
-   !!
-#  define OPERATION_MINLOC
-#  define DIM_2d
-#     define ROUTINE_LOC           mpp_minloc2d
-#     include "mpp_loc_generic.h90"
-#     undef ROUTINE_LOC
-#  undef DIM_2d
-#  define DIM_3d
-#     define ROUTINE_LOC           mpp_minloc3d
-#     include "mpp_loc_generic.h90"
-#     undef ROUTINE_LOC
-#  undef DIM_3d
-#  undef OPERATION_MINLOC
-
-#  define OPERATION_MAXLOC
-#  define DIM_2d
-#     define ROUTINE_LOC           mpp_maxloc2d
-#     include "mpp_loc_generic.h90"
-#     undef ROUTINE_LOC
-#  undef DIM_2d
-#  define DIM_3d
-#     define ROUTINE_LOC           mpp_maxloc3d
-#     include "mpp_loc_generic.h90"
-#     undef ROUTINE_LOC
-#  undef DIM_3d
-#  undef OPERATION_MAXLOC
-
-   SUBROUTINE mpp_delay_sum( cdname, cdelay, y_in, pout, ldlast, kcom )
-      CHARACTER(len=*), INTENT(in   )               ::   cdname  ! name of the calling subroutine
-      CHARACTER(len=*), INTENT(in   )               ::   cdelay  ! name (used as id) of the delayed operation
-      COMPLEX(wp),      INTENT(in   ), DIMENSION(:) ::   y_in
-      REAL(wp),         INTENT(  out), DIMENSION(:) ::   pout
-      LOGICAL,          INTENT(in   )               ::   ldlast  ! true if this is the last time we call this routine
-      INTEGER,          INTENT(in   ), OPTIONAL     ::   kcom
-      !
-      pout(:) = REAL(y_in(:), wp)
-   END SUBROUTINE mpp_delay_sum
-
-   SUBROUTINE mpp_delay_max( cdname, cdelay, p_in, pout, ldlast, kcom )
-      CHARACTER(len=*), INTENT(in   )               ::   cdname  ! name of the calling subroutine
-      CHARACTER(len=*), INTENT(in   )               ::   cdelay  ! name (used as id) of the delayed operation
-      REAL(wp),         INTENT(in   ), DIMENSION(:) ::   p_in
-      REAL(wp),         INTENT(  out), DIMENSION(:) ::   pout
-      LOGICAL,          INTENT(in   )               ::   ldlast  ! true if this is the last time we call this routine
-      INTEGER,          INTENT(in   ), OPTIONAL     ::   kcom
-      !
-      pout(:) = p_in(:)
-   END SUBROUTINE mpp_delay_max
-
-   SUBROUTINE mpp_delay_rcv( kid )
-      INTEGER,INTENT(in   )      ::  kid 
-      WRITE(*,*) 'mpp_delay_rcv: You should not have seen this print! error?', kid
-   END SUBROUTINE mpp_delay_rcv
-   
-   SUBROUTINE mppstop( ldfinal, ld_force_abort )
-      LOGICAL, OPTIONAL, INTENT(in) :: ldfinal    ! source process number
-      LOGICAL, OPTIONAL, INTENT(in) :: ld_force_abort    ! source process number
-      STOP      ! non MPP case, just stop the run
-   END SUBROUTINE mppstop
-
-   SUBROUTINE mpp_ini_znl( knum )
-      INTEGER :: knum
-      WRITE(*,*) 'mpp_ini_znl: You should not have seen this print! error?', knum
-   END SUBROUTINE mpp_ini_znl
-
-   SUBROUTINE mpp_comm_free( kcom )
-      INTEGER :: kcom
-      WRITE(*,*) 'mpp_comm_free: You should not have seen this print! error?', kcom
-   END SUBROUTINE mpp_comm_free
-   
-#endif
-
-   !!----------------------------------------------------------------------
-   !!   All cases:         ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam   routines
+   FUNCTION MPI_Wtime()
+      REAL(wp) ::  MPI_Wtime
+      MPI_Wtime = -1.
+   END FUNCTION MPI_Wtime
+#endif
+
+   !!----------------------------------------------------------------------
+   !!   ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam   routines
    !!----------------------------------------------------------------------
 
@@ -1883,15 +1079,20 @@
       !!                increment the error number (nstop) by one.
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd1, cd2, cd3, cd4, cd5
-      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd6, cd7, cd8, cd9, cd10
+      CHARACTER(len=*), INTENT(in   )           ::   cd1
+      CHARACTER(len=*), INTENT(in   ), OPTIONAL ::        cd2, cd3, cd4, cd5
+      CHARACTER(len=*), INTENT(in   ), OPTIONAL ::   cd6, cd7, cd8, cd9, cd10
       !!----------------------------------------------------------------------
       !
       nstop = nstop + 1
-
-      ! force to open ocean.output file
+      !
+      ! force to open ocean.output file if not already opened
       IF( numout == 6 ) CALL ctl_opn( numout, 'ocean.output', 'APPEND', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
-       
-      WRITE(numout,cform_err)
-      IF( PRESENT(cd1 ) )   WRITE(numout,*) TRIM(cd1)
+      !
+                            WRITE(numout,*)
+                            WRITE(numout,*) ' ===>>> : E R R O R'
+                            WRITE(numout,*)
+                            WRITE(numout,*) '         ==========='
+                            WRITE(numout,*)
+                            WRITE(numout,*) TRIM(cd1)
       IF( PRESENT(cd2 ) )   WRITE(numout,*) TRIM(cd2)
       IF( PRESENT(cd3 ) )   WRITE(numout,*) TRIM(cd3)
@@ -1903,5 +1104,6 @@
       IF( PRESENT(cd9 ) )   WRITE(numout,*) TRIM(cd9)
       IF( PRESENT(cd10) )   WRITE(numout,*) TRIM(cd10)
-
+                            WRITE(numout,*)
+      !
                                CALL FLUSH(numout    )
       IF( numstp     /= -1 )   CALL FLUSH(numstp    )
@@ -1910,6 +1112,8 @@
       !
       IF( cd1 == 'STOP' ) THEN
+         WRITE(numout,*)  
          WRITE(numout,*)  'huge E-R-R-O-R : immediate stop'
-         CALL mppstop(ld_force_abort = .true.)
+         WRITE(numout,*)  
+         CALL mppstop( ld_abort = .true. )
       ENDIF
       !
@@ -1930,16 +1134,22 @@
       !
       nwarn = nwarn + 1
+      !
       IF(lwp) THEN
-         WRITE(numout,cform_war)
-         IF( PRESENT(cd1 ) ) WRITE(numout,*) TRIM(cd1)
-         IF( PRESENT(cd2 ) ) WRITE(numout,*) TRIM(cd2)
-         IF( PRESENT(cd3 ) ) WRITE(numout,*) TRIM(cd3)
-         IF( PRESENT(cd4 ) ) WRITE(numout,*) TRIM(cd4)
-         IF( PRESENT(cd5 ) ) WRITE(numout,*) TRIM(cd5)
-         IF( PRESENT(cd6 ) ) WRITE(numout,*) TRIM(cd6)
-         IF( PRESENT(cd7 ) ) WRITE(numout,*) TRIM(cd7)
-         IF( PRESENT(cd8 ) ) WRITE(numout,*) TRIM(cd8)
-         IF( PRESENT(cd9 ) ) WRITE(numout,*) TRIM(cd9)
-         IF( PRESENT(cd10) ) WRITE(numout,*) TRIM(cd10)
+                               WRITE(numout,*)
+                               WRITE(numout,*) ' ===>>> : W A R N I N G'
+                               WRITE(numout,*)
+                               WRITE(numout,*) '         ==============='
+                               WRITE(numout,*)
+         IF( PRESENT(cd1 ) )   WRITE(numout,*) TRIM(cd1)
+         IF( PRESENT(cd2 ) )   WRITE(numout,*) TRIM(cd2)
+         IF( PRESENT(cd3 ) )   WRITE(numout,*) TRIM(cd3)
+         IF( PRESENT(cd4 ) )   WRITE(numout,*) TRIM(cd4)
+         IF( PRESENT(cd5 ) )   WRITE(numout,*) TRIM(cd5)
+         IF( PRESENT(cd6 ) )   WRITE(numout,*) TRIM(cd6)
+         IF( PRESENT(cd7 ) )   WRITE(numout,*) TRIM(cd7)
+         IF( PRESENT(cd8 ) )   WRITE(numout,*) TRIM(cd8)
+         IF( PRESENT(cd9 ) )   WRITE(numout,*) TRIM(cd9)
+         IF( PRESENT(cd10) )   WRITE(numout,*) TRIM(cd10)
+                               WRITE(numout,*)
       ENDIF
       CALL FLUSH(numout)
@@ -1984,6 +1194,5 @@
       IF( TRIM(cdfile) == '/dev/null' )   clfile = TRIM(cdfile)   ! force the use of /dev/null
       !
-      iost=0
-      IF( cdacce(1:6) == 'DIRECT' )  THEN         ! cdacce has always more than 6 characters
+      IF(       cdacce(1:6) == 'DIRECT' )  THEN   ! cdacce has always more than 6 characters
          OPEN( UNIT=knum, FILE=clfile, FORM=cdform, ACCESS=cdacce, STATUS=cdstat, RECL=klengh         , ERR=100, IOSTAT=iost )
       ELSE IF( TRIM(cdstat) == 'APPEND' )  THEN   ! cdstat can have less than 6 characters
@@ -2006,29 +1215,13 @@
 100   CONTINUE
       IF( iost /= 0 ) THEN
-         IF(ldwp) THEN
-            WRITE(kout,*)
-            WRITE(kout,*) ' ===>>>> : bad opening file: ', TRIM(clfile)
-            WRITE(kout,*) ' =======   ===  '
-            WRITE(kout,*) '           unit   = ', knum
-            WRITE(kout,*) '           status = ', cdstat
-            WRITE(kout,*) '           form   = ', cdform
-            WRITE(kout,*) '           access = ', cdacce
-            WRITE(kout,*) '           iostat = ', iost
-            WRITE(kout,*) '           we stop. verify the file '
-            WRITE(kout,*)
-         ELSE  !!! Force writing to make sure we get the information - at least once - in this violent STOP!!
-            WRITE(*,*)
-            WRITE(*,*) ' ===>>>> : bad opening file: ', TRIM(clfile)
-            WRITE(*,*) ' =======   ===  '
-            WRITE(*,*) '           unit   = ', knum
-            WRITE(*,*) '           status = ', cdstat
-            WRITE(*,*) '           form   = ', cdform
-            WRITE(*,*) '           access = ', cdacce
-            WRITE(*,*) '           iostat = ', iost
-            WRITE(*,*) '           we stop. verify the file '
-            WRITE(*,*)
-         ENDIF
-         CALL FLUSH( kout ) 
-         STOP 'ctl_opn bad opening'
+         WRITE(ctmp1,*) ' ===>>>> : bad opening file: ', TRIM(clfile)
+         WRITE(ctmp2,*) ' =======   ===  '
+         WRITE(ctmp3,*) '           unit   = ', knum
+         WRITE(ctmp4,*) '           status = ', cdstat
+         WRITE(ctmp5,*) '           form   = ', cdform
+         WRITE(ctmp6,*) '           access = ', cdacce
+         WRITE(ctmp7,*) '           iostat = ', iost
+         WRITE(ctmp8,*) '           we stop. verify the file '
+         CALL ctl_stop( 'STOP', ctmp1, ctmp2, ctmp3, ctmp4, ctmp5, ctmp6, ctmp7, ctmp8 )
       ENDIF
       !
@@ -2036,5 +1229,5 @@
 
 
-   SUBROUTINE ctl_nam ( kios, cdnam, ldwp )
+   SUBROUTINE ctl_nam ( kios, cdnam )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE ctl_nam  ***
@@ -2044,8 +1237,8 @@
       !! ** Method  :   Fortan open
       !!----------------------------------------------------------------------
-      INTEGER         , INTENT(inout) ::   kios    ! IO status after reading the namelist
-      CHARACTER(len=*), INTENT(in   ) ::   cdnam   ! group name of namelist for which error occurs
-      CHARACTER(len=5)                ::   clios   ! string to convert iostat in character for print
-      LOGICAL         , INTENT(in   ) ::   ldwp    ! boolean term for print
+      INTEGER                                , INTENT(inout) ::   kios    ! IO status after reading the namelist
+      CHARACTER(len=*)                       , INTENT(in   ) ::   cdnam   ! group name of namelist for which error occurs
+      !
+      CHARACTER(len=5) ::   clios   ! string to convert iostat in character for print
       !!----------------------------------------------------------------------
       !
@@ -2061,5 +1254,4 @@
       ENDIF
       kios = 0
-      RETURN
       !
    END SUBROUTINE ctl_nam
@@ -2082,6 +1274,5 @@
       END DO
       IF( (get_unit == 999) .AND. llopn ) THEN
-         CALL ctl_stop( 'get_unit: All logical units until 999 are used...' )
-         get_unit = -1
+         CALL ctl_stop( 'STOP', 'get_unit: All logical units until 999 are used...' )
       ENDIF
       !
Index: MO/trunk/src/OCE/LBC/mpp_bdy_generic.h90
===================================================================
--- /NEMO/trunk/src/OCE/LBC/mpp_bdy_generic.h90	(revision 11535)
+++ 	(revision )
@@ -1,317 +1,0 @@
-#   define ARRAY_TYPE(i,j,k,l,f)    REAL(wp)                    , INTENT(inout) ::   ARRAY_IN(i,j,k,l,f)
-#   define NAT_IN(k)                cd_nat
-#   define SGN_IN(k)                psgn
-#   define IBD_IN(k)                kb_bdy
-#   define F_SIZE(ptab)             1
-#   define OPT_K(k)                 
-#   if defined DIM_2d
-#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j)
-#      define K_SIZE(ptab)          1
-#      define L_SIZE(ptab)          1
-#   endif
-#   if defined DIM_3d
-#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k)
-#      define K_SIZE(ptab)          SIZE(ptab,3)
-#      define L_SIZE(ptab)          1
-#   endif
-#   if defined DIM_4d
-#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k,l)
-#      define K_SIZE(ptab)          SIZE(ptab,3)
-#      define L_SIZE(ptab)          SIZE(ptab,4)
-#   endif
-
-   SUBROUTINE ROUTINE_BDY( cdname, ptab, cd_nat, psgn      , kb_bdy )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_bdy_3d  ***
-      !!
-      !! ** Purpose :   Message passing management
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing BDY boundaries 
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi_bdy : mark for "east-west local boundary"
-      !!                    nbondj_bdy : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors 
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !! ** Action  :   ptab with update value at its periphery
-      !!
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*)            , INTENT(in   ) ::   cdname      ! name of the calling subroutine
-      ARRAY_TYPE(:,:,:,:,:)   ! array or pointer of arrays on which the boundary condition is applied
-      CHARACTER(len=1)            , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
-      REAL(wp)                    , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
-      INTEGER                     , INTENT(in   ) ::   IBD_IN(:)   ! BDY boundary set
-      !
-      INTEGER  ::   ji, jj, jk, jl, jh, jf     ! dummy loop indices
-      INTEGER  ::   ipk, ipl, ipf              ! 3dimension of the input array
-      INTEGER  ::   imigr, iihom, ijhom        ! local integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland                      ! local scalar
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
-      REAL(wp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
-      !!----------------------------------------------------------------------
-      !
-      ipk = K_SIZE(ptab)   ! 3rd dimension
-      ipl = L_SIZE(ptab)   ! 4th    -
-      ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
-      !
-      IF( narea == 1 .AND. numcom == -1 ) CALL mpp_report( cdname, ipk, ipl, ipf, ld_lbc = .TRUE. )
-      !      
-      ALLOCATE( zt3ns(jpi,nn_hls,ipk,ipl,ipf,2), zt3sn(jpi,nn_hls,ipk,ipl,ipf,2),   &
-         &      zt3ew(jpj,nn_hls,ipk,ipl,ipf,2), zt3we(jpj,nn_hls,ipk,ipl,ipf,2)  )
-
-      zland = 0._wp
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      !
-      DO jf = 1, ipf                   ! number of arrays to be treated
-         !
-         !                                ! East-West boundaries
-         !                    
-         IF( nbondi == 2) THEN                  ! neither subdomain to the east nor to the west
-            !                                      !* Cyclic
-            IF( l_Iperio ) THEN
-               ARRAY_IN( 1 ,:,:,:,jf) = ARRAY_IN(jpim1,:,:,:,jf)
-               ARRAY_IN(jpi,:,:,:,jf) = ARRAY_IN(  2  ,:,:,:,jf)
-            ELSE                                   !* Closed
-               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(     1       :nn_hls,:,:,:,jf) = zland  ! east except F-point
-                                               ARRAY_IN(nlci-nn_hls+1:jpi   ,:,:,:,jf) = zland  ! west
-            ENDIF
-         ELSEIF(nbondi == -1) THEN              ! subdomain to the east only
-            IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(1:nn_hls,:,:,:,jf) = zland     ! south except F-point
-            !
-         ELSEIF(nbondi ==  1) THEN              ! subdomain to the west only
-            ARRAY_IN(nlci-nn_hls+1:jpi,:,:,:,jf) = zland    ! north
-         ENDIF
-         !                                ! North-South boundaries
-         !
-         IF( nbondj == 2) THEN                  ! neither subdomain to the north nor to the south
-            !                                      !* Cyclic
-            IF( l_Jperio ) THEN
-               ARRAY_IN(:, 1 ,:,:,jf) = ARRAY_IN(:,jpjm1,:,:,jf)
-               ARRAY_IN(:,jpj,:,:,jf) = ARRAY_IN(:,  2  ,:,:,jf)
-            ELSE                                   !* Closed
-               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:,     1       :nn_hls,:,:,jf) = zland  ! east except F-point
-                                               ARRAY_IN(:,nlcj-nn_hls+1:jpj   ,:,:,jf) = zland  ! west
-            ENDIF
-         ELSEIF(nbondj == -1) THEN              ! subdomain to the east only
-            IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:,1:nn_hls,:,:,jf) = zland     ! south except F-point
-            !
-         ELSEIF(nbondj ==  1) THEN              ! subdomain to the west only
-            ARRAY_IN(:,nlcj-nn_hls+1:jpj,:,:,jf) = zland    ! north
-         ENDIF
-         !
-      END DO
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity 
-      !
-      !
-      DO jf = 1, ipf
-         SELECT CASE ( nbondi_bdy(IBD_IN(jf)) )      ! Read Dirichlet lateral conditions
-         CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-            iihom = nlci-nreci
-               DO jl = 1, ipl
-                  DO jk = 1, ipk
-                     DO jh = 1, nn_hls
-                        zt3ew(:,jh,jk,jl,jf,1) = ARRAY_IN(nn_hls+jh,:,jk,jl,jf)
-                        zt3we(:,jh,jk,jl,jf,1) = ARRAY_IN(iihom +jh,:,jk,jl,jf)
-                     END DO
-                  END DO
-               END DO
-         END SELECT
-         !
-         !                           ! Migrations
-!!gm      imigr = nn_hls * jpj * ipk * ipl * ipf
-         imigr = nn_hls * jpj * ipk * ipl
-         !
-         IF( ln_timing ) CALL tic_tac(.TRUE.)
-         !
-         SELECT CASE ( nbondi_bdy(IBD_IN(jf)) )
-         CASE ( -1 )
-            CALL mppsend( 2, zt3we(1,1,1,1,1,1), imigr, noea, ml_req1 )
-         CASE ( 0 )
-            CALL mppsend( 1, zt3ew(1,1,1,1,1,1), imigr, nowe, ml_req1 )
-            CALL mppsend( 2, zt3we(1,1,1,1,1,1), imigr, noea, ml_req2 )
-         CASE ( 1 )
-            CALL mppsend( 1, zt3ew(1,1,1,1,1,1), imigr, nowe, ml_req1 )
-         END SELECT
-         !
-         SELECT CASE ( nbondi_bdy_b(IBD_IN(jf)) )
-         CASE ( -1 )
-            CALL mpprecv( 1, zt3ew(1,1,1,1,1,2), imigr, noea )
-         CASE ( 0 )
-            CALL mpprecv( 1, zt3ew(1,1,1,1,1,2), imigr, noea )
-            CALL mpprecv( 2, zt3we(1,1,1,1,1,2), imigr, nowe )
-         CASE ( 1 )
-            CALL mpprecv( 2, zt3we(1,1,1,1,1,2), imigr, nowe )
-         END SELECT
-         !
-         SELECT CASE ( nbondi_bdy(IBD_IN(jf)) )
-         CASE ( -1 )
-            IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         CASE ( 0 )
-            IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-            IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-         CASE ( 1 )
-            IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         END SELECT
-         !
-         IF( ln_timing ) CALL tic_tac(.FALSE.)
-         !
-         !                           ! Write Dirichlet lateral conditions
-         iihom = nlci-nn_hls
-         !
-         !
-         SELECT CASE ( nbondi_bdy_b(IBD_IN(jf)) )
-         CASE ( -1 )
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     ARRAY_IN(iihom+jh,:,jk,jl,jf) = zt3ew(:,jh,jk,jl,jf,2)
-                  END DO
-               END DO
-            END DO
-         CASE ( 0 )
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     ARRAY_IN(jh      ,:,jk,jl,jf) = zt3we(:,jh,jk,jl,jf,2)
-                     ARRAY_IN(iihom+jh,:,jk,jl,jf) = zt3ew(:,jh,jk,jl,jf,2)
-                  END DO
-               END DO
-            END DO
-         CASE ( 1 )
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     ARRAY_IN(jh      ,:,jk,jl,jf) = zt3we(:,jh,jk,jl,jf,2)
-                  END DO
-               END DO
-            END DO
-         END SELECT
-         !
-      END DO
-
-      ! 3. north fold treatment
-      ! -----------------------
-      !
-      ! do it before south directions so concerned processes can do it without waiting for the comm with the sourthern neighbor
-      IF( npolj /= 0) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd( ptab, NAT_IN(:), SGN_IN(:) OPT_K(:) )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_nfd( ptab, NAT_IN(:), SGN_IN(:) OPT_K(:) )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-
-      ! 4. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      DO jf = 1, ipf
-         IF( nbondj_bdy(IBD_IN(jf)) /= 2 ) THEN      ! Read Dirichlet lateral conditions
-            ijhom = nlcj-nrecj
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     zt3sn(:,jh,jk,jl,jf,1) = ARRAY_IN(:,ijhom +jh,jk,jl,jf)
-                     zt3ns(:,jh,jk,jl,jf,1) = ARRAY_IN(:,nn_hls+jh,jk,jl,jf)
-                  END DO
-               END DO
-            END DO
-         ENDIF
-         !
-         !                           ! Migrations
-!!gm      imigr = nn_hls * jpi * ipk * ipl * ipf
-         imigr = nn_hls * jpi * ipk * ipl
-         !
-         IF( ln_timing ) CALL tic_tac(.TRUE.)
-         ! 
-         SELECT CASE ( nbondj_bdy(IBD_IN(jf)) )
-         CASE ( -1 )
-            CALL mppsend( 4, zt3sn(1,1,1,1,1,1), imigr, nono, ml_req1 )
-         CASE ( 0 )
-            CALL mppsend( 3, zt3ns(1,1,1,1,1,1), imigr, noso, ml_req1 )
-            CALL mppsend( 4, zt3sn(1,1,1,1,1,1), imigr, nono, ml_req2 )
-         CASE ( 1 )
-            CALL mppsend( 3, zt3ns(1,1,1,1,1,1), imigr, noso, ml_req1 )
-         END SELECT
-         ! 
-         SELECT CASE ( nbondj_bdy_b(IBD_IN(jf)) )
-         CASE ( -1 )
-            CALL mpprecv( 3, zt3ns(1,1,1,1,1,2), imigr, nono )
-         CASE ( 0 )
-            CALL mpprecv( 3, zt3ns(1,1,1,1,1,2), imigr, nono )
-            CALL mpprecv( 4, zt3sn(1,1,1,1,1,2), imigr, noso )
-         CASE ( 1 )
-            CALL mpprecv( 4, zt3sn(1,1,1,1,1,2), imigr, noso )
-         END SELECT
-         ! 
-         SELECT CASE ( nbondj_bdy(IBD_IN(jf)) )
-         CASE ( -1 )
-            IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         CASE ( 0 )
-            IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-            IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-         CASE ( 1 )
-            IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         END SELECT
-         !
-         IF( ln_timing ) CALL tic_tac(.FALSE.)
-         !
-         !                           ! Write Dirichlet lateral conditions
-         ijhom = nlcj-nn_hls
-         !
-         SELECT CASE ( nbondj_bdy_b(IBD_IN(jf)) )
-         CASE ( -1 )
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     ARRAY_IN(:,ijhom+jh,jk,jl,jf) = zt3ns(:,jh,jk,jl,jf,2)
-                  END DO
-               END DO
-            END DO
-         CASE ( 0 )
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     ARRAY_IN(:,      jh,jk,jl,jf) = zt3sn(:,jh,jk,jl,jf,2)
-                     ARRAY_IN(:,ijhom+jh,jk,jl,jf) = zt3ns(:,jh,jk,jl,jf,2)
-                  END DO
-               END DO
-            END DO
-         CASE ( 1 )
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     ARRAY_IN(:,jh,jk,jl,jf) = zt3sn(:,jh,jk,jl,jf,2)
-                  END DO
-               END DO
-            END DO
-         END SELECT
-      END DO
-      !
-      DEALLOCATE( zt3ns, zt3sn, zt3ew, zt3we  )
-      !
-   END SUBROUTINE ROUTINE_BDY
-
-#undef ARRAY_TYPE
-#undef NAT_IN
-#undef SGN_IN
-#undef IBD_IN
-#undef ARRAY_IN
-#undef K_SIZE
-#undef L_SIZE
-#undef F_SIZE
-#undef OPT_K
Index: /NEMO/trunk/src/OCE/LBC/mpp_lnk_generic.h90
===================================================================
--- /NEMO/trunk/src/OCE/LBC/mpp_lnk_generic.h90	(revision 11535)
+++ /NEMO/trunk/src/OCE/LBC/mpp_lnk_generic.h90	(revision 11536)
@@ -46,26 +46,37 @@
 
 #if defined MULTI
-   SUBROUTINE ROUTINE_LNK( cdname, ptab, cd_nat, psgn, kfld, cd_mpp, pval )
-      INTEGER                     , INTENT(in   ) ::   kfld        ! number of pt3d arrays
+   SUBROUTINE ROUTINE_LNK( cdname, ptab, cd_nat, psgn, kfld, kfillmode, pfillval, lsend, lrecv, ihlcom )
+      INTEGER             , INTENT(in   ) ::   kfld        ! number of pt3d arrays
 #else
-   SUBROUTINE ROUTINE_LNK( cdname, ptab, cd_nat, psgn      , cd_mpp, pval )
+   SUBROUTINE ROUTINE_LNK( cdname, ptab, cd_nat, psgn      , kfillmode, pfillval, lsend, lrecv, ihlcom )
 #endif
       ARRAY_TYPE(:,:,:,:,:)                                        ! array or pointer of arrays on which the boundary condition is applied
-      CHARACTER(len=*)            , INTENT(in   ) ::   cdname      ! name of the calling subroutine
-      CHARACTER(len=1)            , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
-      REAL(wp)                    , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
-      CHARACTER(len=3), OPTIONAL  , INTENT(in   ) ::   cd_mpp      ! fill the overlap area only
-      REAL(wp)        , OPTIONAL  , INTENT(in   ) ::   pval        ! background value (used at closed boundaries)
-      !
-      INTEGER  ::    ji,  jj,  jk,  jl, jh, jf   ! dummy loop indices
+      CHARACTER(len=*)              , INTENT(in   ) ::   cdname      ! name of the calling subroutine
+      CHARACTER(len=1)              , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
+      REAL(wp)                      , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
+      INTEGER ,             OPTIONAL, INTENT(in   ) ::   kfillmode   ! filling method for halo over land (default = constant)
+      REAL(wp),             OPTIONAL, INTENT(in   ) ::   pfillval    ! background value (used at closed boundaries)
+      LOGICAL, DIMENSION(4),OPTIONAL, INTENT(in   ) ::   lsend, lrecv  ! communication with other 4 proc
+      INTEGER              ,OPTIONAL, INTENT(in   ) ::   ihlcom        ! number of ranks and rows to be communicated
+      !
+      INTEGER  ::    ji,  jj,  jk,  jl,  jf      ! dummy loop indices
       INTEGER  ::   ipi, ipj, ipk, ipl, ipf      ! dimension of the input array
-      INTEGER  ::   imigr, iihom, ijhom          ! local integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err     ! for key_mpi_isend
+      INTEGER  ::   isize, ishift, ishift2       ! local integers
+      INTEGER  ::   ireq_we, ireq_ea, ireq_so, ireq_no     ! mpi_request id
       INTEGER  ::   ierr
+      INTEGER  ::   ifill_we, ifill_ea, ifill_so, ifill_no
+      INTEGER  ::   ihl                          ! number of ranks and rows to be communicated 
       REAL(wp) ::   zland
-      INTEGER , DIMENSION(MPI_STATUS_SIZE)      ::   ml_stat        ! for key_mpi_isend
-      REAL(wp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! north-south & south-north  halos
-      REAL(wp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! east -west  & west - east  halos
+      INTEGER , DIMENSION(MPI_STATUS_SIZE)        ::   istat          ! for mpi_isend
+      REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE ::   zsnd_we, zrcv_we, zsnd_ea, zrcv_ea   ! east -west  & west - east  halos
+      REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE ::   zsnd_so, zrcv_so, zsnd_no, zrcv_no   ! north-south & south-north  halos
+      LOGICAL  ::   llsend_we, llsend_ea, llsend_no, llsend_so       ! communication send
+      LOGICAL  ::   llrecv_we, llrecv_ea, llrecv_no, llrecv_so       ! communication receive 
+      LOGICAL  ::   lldo_nfd                                     ! do north pole folding
       !!----------------------------------------------------------------------
+      !
+      ! ----------------------------------------- !
+      !     0. local variables initialization     !
+      ! ----------------------------------------- !
       !
       ipk = K_SIZE(ptab)   ! 3rd dimension
@@ -73,151 +84,170 @@
       ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
       !
+      IF( PRESENT(ihlcom) ) THEN   ;   ihl = ihlcom
+      ELSE                         ;   ihl = 1
+      END IF
+      !
       IF( narea == 1 .AND. numcom == -1 ) CALL mpp_report( cdname, ipk, ipl, ipf, ld_lbc = .TRUE. )
       !
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0._wp     ! zero by default
-      ENDIF
-
-      ! ------------------------------- !
-      !   standard boundary treatment   !    ! CAUTION: semi-column notation is often impossible
-      ! ------------------------------- !
-      !
-      IF( .NOT. PRESENT( cd_mpp ) ) THEN     !==  standard close or cyclic treatment  ==!
-         !
-         DO jf = 1, ipf                      ! number of arrays to be treated
-            !
-            !                                ! East-West boundaries
-            IF( l_Iperio ) THEN                    !* cyclic
-               ARRAY_IN( 1 ,:,:,:,jf) = ARRAY_IN(jpim1,:,:,:,jf)
-               ARRAY_IN(jpi,:,:,:,jf) = ARRAY_IN(  2  ,:,:,:,jf)
-            ELSE                                   !* closed
-               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(     1       :nn_hls,:,:,:,jf) = zland    ! east except F-point
-                                               ARRAY_IN(nlci-nn_hls+1:jpi   ,:,:,:,jf) = zland    ! west
-            ENDIF
-            !                                ! North-South boundaries
-            IF( l_Jperio ) THEN                    !* cyclic (only with no mpp j-split)
-               ARRAY_IN(:, 1 ,:,:,jf) = ARRAY_IN(:, jpjm1,:,:,jf)
-               ARRAY_IN(:,jpj,:,:,jf) = ARRAY_IN(:,   2  ,:,:,jf)
-            ELSE                                   !* closed
-               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:,     1       :nn_hls,:,:,jf) = zland    ! south except F-point
-                                               ARRAY_IN(:,nlcj-nn_hls+1:jpj   ,:,:,jf) = zland    ! north
+      IF     ( PRESENT(lsend) .AND. PRESENT(lrecv) ) THEN
+         llsend_we = lsend(1)   ;   llsend_ea = lsend(2)   ;   llsend_so = lsend(3)   ;   llsend_no = lsend(4)
+         llrecv_we = lrecv(1)   ;   llrecv_ea = lrecv(2)   ;   llrecv_so = lrecv(3)   ;   llrecv_no = lrecv(4)
+      ELSE IF( PRESENT(lsend) .OR.  PRESENT(lrecv) ) THEN
+         WRITE(ctmp1,*) ' E R R O R : Routine ', cdname, '  is calling lbc_lnk with only one of the two arguments lsend or lrecv'
+         WRITE(ctmp2,*) ' ========== '
+         CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+      ELSE   ! send and receive with every neighbour
+         llsend_we = nbondi ==  1 .OR. nbondi == 0   ! keep for compatibility, should be defined in mppini
+         llsend_ea = nbondi == -1 .OR. nbondi == 0   ! keep for compatibility, should be defined in mppini
+         llsend_so = nbondj ==  1 .OR. nbondj == 0   ! keep for compatibility, should be defined in mppini
+         llsend_no = nbondj == -1 .OR. nbondj == 0   ! keep for compatibility, should be defined in mppini
+         llrecv_we = llsend_we   ;   llrecv_ea = llsend_ea   ;   llrecv_so = llsend_so   ;   llrecv_no = llsend_no
+      END IF
+         
+         
+      lldo_nfd = npolj /= 0                      ! keep for compatibility, should be defined in mppini
+
+      zland = 0._wp                                     ! land filling value: zero by default
+      IF( PRESENT( pfillval ) )   zland = pfillval      ! set land value
+
+      ! define the method we will use to fill the halos in each direction
+      IF(              llrecv_we ) THEN   ;   ifill_we = jpfillmpi
+      ELSEIF(           l_Iperio ) THEN   ;   ifill_we = jpfillperio
+      ELSEIF( PRESENT(kfillmode) ) THEN   ;   ifill_we = kfillmode
+      ELSE                                ;   ifill_we = jpfillcst
+      END IF
+      !
+      IF(              llrecv_ea ) THEN   ;   ifill_ea = jpfillmpi
+      ELSEIF(           l_Iperio ) THEN   ;   ifill_ea = jpfillperio
+      ELSEIF( PRESENT(kfillmode) ) THEN   ;   ifill_ea = kfillmode
+      ELSE                                ;   ifill_ea = jpfillcst
+      END IF
+      !
+      IF(              llrecv_so ) THEN   ;   ifill_so = jpfillmpi
+      ELSEIF(           l_Jperio ) THEN   ;   ifill_so = jpfillperio
+      ELSEIF( PRESENT(kfillmode) ) THEN   ;   ifill_so = kfillmode
+      ELSE                                ;   ifill_so = jpfillcst
+      END IF
+      !
+      IF(              llrecv_no ) THEN   ;   ifill_no = jpfillmpi
+      ELSEIF(           l_Jperio ) THEN   ;   ifill_no = jpfillperio
+      ELSEIF( PRESENT(kfillmode) ) THEN   ;   ifill_no = kfillmode
+      ELSE                                ;   ifill_no = jpfillcst
+      END IF
+      !
+#if defined PRINT_CAUTION
+      !
+      ! ================================================================================== !
+      ! CAUTION: semi-column notation is often impossible because of the cpp preprocessing !
+      ! ================================================================================== !
+      !
+#endif
+      !
+      ! -------------------------------------------------- !
+      !     1. Do east and west MPI exchange if needed     !
+      ! -------------------------------------------------- !
+      !
+      ! Must exchange the whole column (from 1 to jpj) to get the corners if we have no south/north neighbourg
+      isize = ihl * jpj * ipk * ipl * ipf      
+      !
+      ! Allocate local temporary arrays to be sent/received. Fill arrays to be sent
+      IF( llsend_we )   ALLOCATE( zsnd_we(ihl,jpj,ipk,ipl,ipf) )
+      IF( llsend_ea )   ALLOCATE( zsnd_ea(ihl,jpj,ipk,ipl,ipf) )
+      IF( llrecv_we )   ALLOCATE( zrcv_we(ihl,jpj,ipk,ipl,ipf) )
+      IF( llrecv_ea )   ALLOCATE( zrcv_ea(ihl,jpj,ipk,ipl,ipf) )
+      !
+      IF( llsend_we ) THEN   ! copy western side of the inner mpi domain in local temporary array to be sent by MPI
+         ishift = ihl
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, jpj   ;   DO ji = 1, ihl
+            zsnd_we(ji,jj,jk,jl,jf) = ARRAY_IN(ishift+ji,jj,jk,jl,jf)   ! ihl + 1 -> 2*ihl
+         END DO   ;   END DO   ;   END DO   ;   END DO   ;   END DO
+      ENDIF
+      !
+      IF(llsend_ea  ) THEN   ! copy eastern side of the inner mpi domain in local temporary array to be sent by MPI
+         ishift = jpi - 2 * ihl
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, jpj   ;   DO ji = 1, ihl
+            zsnd_ea(ji,jj,jk,jl,jf) = ARRAY_IN(ishift+ji,jj,jk,jl,jf)   ! jpi - 2*ihl + 1 -> jpi - ihl
+         END DO   ;   END DO   ;   END DO   ;   END DO   ;   END DO
+      ENDIF
+      !
+      IF( ln_timing ) CALL tic_tac(.TRUE.)
+      !
+      ! non-blocking send of the western/eastern side using local temporary arrays
+      IF( llsend_we )   CALL mppsend( 1, zsnd_we(1,1,1,1,1), isize, nowe, ireq_we )
+      IF( llsend_ea )   CALL mppsend( 2, zsnd_ea(1,1,1,1,1), isize, noea, ireq_ea )
+      ! blocking receive of the western/eastern halo in local temporary arrays
+      IF( llrecv_we )   CALL mpprecv( 2, zrcv_we(1,1,1,1,1), isize, nowe )
+      IF( llrecv_ea )   CALL mpprecv( 1, zrcv_ea(1,1,1,1,1), isize, noea )
+      !
+      IF( ln_timing ) CALL tic_tac(.FALSE.)
+      !
+      !
+      ! ----------------------------------- !
+      !     2. Fill east and west halos     !
+      ! ----------------------------------- !
+      !
+      ! 2.1 fill weastern halo
+      ! ----------------------
+      ! ishift = 0                         ! fill halo from ji = 1 to ihl
+      SELECT CASE ( ifill_we )
+      CASE ( jpfillnothing )               ! no filling 
+      CASE ( jpfillmpi   )                 ! use data received by MPI 
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, jpj   ;   DO ji = 1, ihl
+            ARRAY_IN(ji,jj,jk,jl,jf) = zrcv_we(ji,jj,jk,jl,jf)   ! 1 -> ihl
+         END DO;   END DO   ;   END DO   ;   END DO   ;   END DO
+      CASE ( jpfillperio )                 ! use east-weast periodicity
+         ishift2 = jpi - 2 * ihl
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, jpj   ;   DO ji = 1, ihl
+            ARRAY_IN(ji,jj,jk,jl,jf) = ARRAY_IN(ishift2+ji,jj,jk,jl,jf)
+         END DO;   END DO   ;   END DO   ;   END DO   ;   END DO
+      CASE ( jpfillcopy  )                 ! filling with inner domain values
+         DO jf = 1, ipf                               ! number of arrays to be treated
+            IF( .NOT. NAT_IN(jf) == 'F' ) THEN        ! do nothing for F point
+               DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, jpj   ;   DO ji = 1, ihl
+                  ARRAY_IN(ji,jj,jk,jl,jf) = ARRAY_IN(ihl+1,jj,jk,jl,jf)
+               END DO   ;   END DO   ;   END DO   ;   END DO
             ENDIF
          END DO
-         !
-      ENDIF
-
-      ! ------------------------------- !
-      !      East and west exchange     !
-      ! ------------------------------- !
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      IF( ABS(nbondi) == 1 ) ALLOCATE( zt3ew(jpj,nn_hls,ipk,ipl,ipf,1), zt3we(jpj,nn_hls,ipk,ipl,ipf,1) )
-      IF(     nbondi  == 0 ) ALLOCATE( zt3ew(jpj,nn_hls,ipk,ipl,ipf,2), zt3we(jpj,nn_hls,ipk,ipl,ipf,2) )
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1 )
-         iihom = nlci-nreci
-         DO jf = 1, ipf
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     zt3we(:,jh,jk,jl,jf,1) = ARRAY_IN(iihom +jh,:,jk,jl,jf)
-                  END DO
-               END DO
-            END DO
-         END DO
-      CASE ( 0 )
-         iihom = nlci-nreci
-         DO jf = 1, ipf
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     zt3ew(:,jh,jk,jl,jf,1) = ARRAY_IN(nn_hls+jh,:,jk,jl,jf)
-                     zt3we(:,jh,jk,jl,jf,1) = ARRAY_IN(iihom +jh,:,jk,jl,jf)
-                  END DO
-               END DO
-            END DO
-         END DO
-      CASE ( 1 )
-         iihom = nlci-nreci
-         DO jf = 1, ipf
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     zt3ew(:,jh,jk,jl,jf,1) = ARRAY_IN(nn_hls+jh,:,jk,jl,jf)
-                  END DO
-               END DO
-            END DO
+      CASE ( jpfillcst   )                 ! filling with constant value
+         DO jf = 1, ipf                               ! number of arrays to be treated
+            IF( .NOT. NAT_IN(jf) == 'F' ) THEN        ! do nothing for F point
+               DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, jpj   ;   DO ji = 1, ihl
+                  ARRAY_IN(ji,jj,jk,jl,jf) = zland
+               END DO;   END DO   ;   END DO   ;   END DO
+            ENDIF
          END DO
       END SELECT
-      !                           ! Migrations
-      imigr = nn_hls * jpj * ipk * ipl * ipf      
-      !
-      IF( ln_timing ) CALL tic_tac(.TRUE.)
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, zt3we(1,1,1,1,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, zt3ew(1,1,1,1,1,1), imigr, noea )
-         IF(l_isend)   CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, zt3ew(1,1,1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt3we(1,1,1,1,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, zt3ew(1,1,1,1,1,2), imigr, noea )
-         CALL mpprecv( 2, zt3we(1,1,1,1,1,2), imigr, nowe )
-         IF(l_isend)   CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend)   CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, zt3ew(1,1,1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, zt3we(1,1,1,1,1,1), imigr, nowe )
-         IF(l_isend)   CALL mpi_wait(ml_req1, ml_stat, ml_err )
+      !
+      ! 2.2 fill eastern halo
+      ! ---------------------
+      ishift = jpi - ihl                ! fill halo from ji = jpi-ihl+1 to jpi 
+      SELECT CASE ( ifill_ea )
+      CASE ( jpfillnothing )               ! no filling 
+      CASE ( jpfillmpi   )                 ! use data received by MPI 
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, jpj   ;   DO ji = 1, ihl
+            ARRAY_IN(ishift+ji,jj,jk,jl,jf) = zrcv_ea(ji,jj,jk,jl,jf)   ! jpi - ihl + 1 -> jpi
+         END DO   ;   END DO   ;   END DO   ;   END DO   ;   END DO
+      CASE ( jpfillperio )                 ! use east-weast periodicity
+         ishift2 = ihl
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, jpj   ;   DO ji = 1, ihl
+            ARRAY_IN(ishift+ji,jj,jk,jl,jf) = ARRAY_IN(ishift2+ji,jj,jk,jl,jf)
+         END DO   ;   END DO   ;   END DO   ;   END DO   ;   END DO
+      CASE ( jpfillcopy  )                 ! filling with inner domain values
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, jpj   ;   DO ji = 1, ihl
+            ARRAY_IN(ishift+ji,jj,jk,jl,jf) = ARRAY_IN(ishift,jj,jk,jl,jf)
+         END DO   ;   END DO   ;   END DO   ;   END DO   ;   END DO
+      CASE ( jpfillcst   )                 ! filling with constant value
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, jpj   ;   DO ji = 1, ihl
+            ARRAY_IN(ishift+ji,jj,jk,jl,jf) = zland
+         END DO;   END DO   ;   END DO   ;   END DO   ;   END DO
       END SELECT
-      !
-      IF( ln_timing ) CALL tic_tac(.FALSE.)
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci-nn_hls
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jf = 1, ipf
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     ARRAY_IN(iihom+jh,:,jk,jl,jf) = zt3ew(:,jh,jk,jl,jf,1)
-                  END DO
-               END DO
-            END DO
-         END DO
-      CASE ( 0 )
-         DO jf = 1, ipf
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     ARRAY_IN(jh      ,:,jk,jl,jf) = zt3we(:,jh,jk,jl,jf,2)
-                     ARRAY_IN(iihom+jh,:,jk,jl,jf) = zt3ew(:,jh,jk,jl,jf,2)
-                  END DO
-               END DO
-            END DO
-         END DO
-      CASE ( 1 )
-         DO jf = 1, ipf
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     ARRAY_IN(jh      ,:,jk,jl,jf) = zt3we(:,jh,jk,jl,jf,1)
-                  END DO
-               END DO
-            END DO
-         END DO
-      END SELECT
-      !
-      IF( nbondi /= 2 ) DEALLOCATE( zt3ew, zt3we )
       !
       ! ------------------------------- !
       !     3. north fold treatment     !
       ! ------------------------------- !
+      !
       ! do it before south directions so concerned processes can do it without waiting for the comm with the sourthern neighbor
-      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
+      !
+      IF( lldo_nfd .AND. ifill_no /= jpfillnothing ) THEN
          !
          SELECT CASE ( jpni )
@@ -226,113 +256,130 @@
          END SELECT
          !
-      ENDIF
-      !
-      ! ------------------------------- !
-      !  4. North and south directions  !
-      ! ------------------------------- !
-      ! always closed : we play only with the neigbours
-      !
-      IF( ABS(nbondj) == 1 ) ALLOCATE( zt3ns(jpi,nn_hls,ipk,ipl,ipf,1), zt3sn(jpi,nn_hls,ipk,ipl,ipf,1) )
-      IF(     nbondj  == 0 ) ALLOCATE( zt3ns(jpi,nn_hls,ipk,ipl,ipf,2), zt3sn(jpi,nn_hls,ipk,ipl,ipf,2) )
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         ijhom = nlcj-nrecj
-         DO jf = 1, ipf
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     zt3sn(:,jh,jk,jl,jf,1) = ARRAY_IN(:,ijhom +jh,jk,jl,jf)
-                  END DO
-               END DO
-            END DO
+         ifill_no = jpfillnothing  ! force to do nothing for the northern halo as we just done the north pole folding
+         !
+      ENDIF
+      !
+      ! ---------------------------------------------------- !
+      !     4. Do north and south MPI exchange if needed     !
+      ! ---------------------------------------------------- !
+      !
+      IF( llsend_so )   ALLOCATE( zsnd_so(jpi,ihl,ipk,ipl,ipf) )
+      IF( llsend_no )   ALLOCATE( zsnd_no(jpi,ihl,ipk,ipl,ipf) )
+      IF( llrecv_so )   ALLOCATE( zrcv_so(jpi,ihl,ipk,ipl,ipf) )
+      IF( llrecv_no )   ALLOCATE( zrcv_no(jpi,ihl,ipk,ipl,ipf) )
+      !
+      isize = jpi * ihl * ipk * ipl * ipf      
+
+      ! allocate local temporary arrays to be sent/received. Fill arrays to be sent
+      IF( llsend_so ) THEN   ! copy sourhern side of the inner mpi domain in local temporary array to be sent by MPI
+         ishift = ihl
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, ihl   ;   DO ji = 1, jpi
+            zsnd_so(ji,jj,jk,jl,jf) = ARRAY_IN(ji,ishift+jj,jk,jl,jf)   ! ihl+1 -> 2*ihl
+         END DO   ;   END DO   ;   END DO   ;   END DO   ;   END DO
+      ENDIF
+      !
+      IF( llsend_no ) THEN   ! copy eastern side of the inner mpi domain in local temporary array to be sent by MPI
+         ishift = jpj - 2 * ihl
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, ihl   ;   DO ji = 1, jpi
+            zsnd_no(ji,jj,jk,jl,jf) = ARRAY_IN(ji,ishift+jj,jk,jl,jf)   ! jpj-2*ihl+1 -> jpj-ihl
+         END DO   ;   END DO   ;   END DO   ;   END DO   ;   END DO
+      ENDIF
+      !
+      IF( ln_timing ) CALL tic_tac(.TRUE.)
+      !
+      ! non-blocking send of the southern/northern side
+      IF( llsend_so )   CALL mppsend( 3, zsnd_so(1,1,1,1,1), isize, noso, ireq_so )
+      IF( llsend_no )   CALL mppsend( 4, zsnd_no(1,1,1,1,1), isize, nono, ireq_no )
+      ! blocking receive of the southern/northern halo
+      IF( llrecv_so )   CALL mpprecv( 4, zrcv_so(1,1,1,1,1), isize, noso )
+      IF( llrecv_no )   CALL mpprecv( 3, zrcv_no(1,1,1,1,1), isize, nono )
+      !
+      IF( ln_timing ) CALL tic_tac(.FALSE.)
+      !
+      ! ------------------------------------- !
+      !     5. Fill south and north halos     !
+      ! ------------------------------------- !
+      !
+      ! 5.1 fill southern halo
+      ! ----------------------
+      ! ishift = 0                         ! fill halo from jj = 1 to ihl
+      SELECT CASE ( ifill_so )
+      CASE ( jpfillnothing )               ! no filling 
+      CASE ( jpfillmpi   )                 ! use data received by MPI 
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, ihl   ;   DO ji = 1, jpi
+            ARRAY_IN(ji,jj,jk,jl,jf) = zrcv_so(ji,jj,jk,jl,jf)   ! 1 -> ihl
+         END DO;   END DO   ;   END DO   ;   END DO   ;   END DO
+      CASE ( jpfillperio )                 ! use north-south periodicity
+         ishift2 = jpj - 2 * ihl
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, ihl   ;   DO ji = 1, jpi
+            ARRAY_IN(ji,jj,jk,jl,jf) = ARRAY_IN(ji,ishift2+jj,jk,jl,jf)
+         END DO;   END DO   ;   END DO   ;   END DO   ;   END DO
+      CASE ( jpfillcopy  )                 ! filling with inner domain values
+         DO jf = 1, ipf                               ! number of arrays to be treated
+            IF( .NOT. NAT_IN(jf) == 'F' ) THEN        ! do nothing for F point
+               DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, ihl   ;   DO ji = 1, jpi
+                  ARRAY_IN(ji,jj,jk,jl,jf) = ARRAY_IN(ji,ihl+1,jk,jl,jf)
+               END DO   ;   END DO   ;   END DO   ;   END DO
+            ENDIF
          END DO
-      CASE ( 0 )
-         ijhom = nlcj-nrecj
-         DO jf = 1, ipf
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     zt3sn(:,jh,jk,jl,jf,1) = ARRAY_IN(:,ijhom +jh,jk,jl,jf)
-                     zt3ns(:,jh,jk,jl,jf,1) = ARRAY_IN(:,nn_hls+jh,jk,jl,jf)
-                  END DO
-               END DO
-            END DO
-         END DO
-      CASE ( 1 )
-         ijhom = nlcj-nrecj
-         DO jf = 1, ipf
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     zt3ns(:,jh,jk,jl,jf,1) = ARRAY_IN(:,nn_hls+jh,jk,jl,jf)
-                  END DO
-               END DO
-            END DO
+      CASE ( jpfillcst   )                 ! filling with constant value
+         DO jf = 1, ipf                               ! number of arrays to be treated
+            IF( .NOT. NAT_IN(jf) == 'F' ) THEN        ! do nothing for F point
+               DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, ihl   ;   DO ji = 1, jpi 
+                  ARRAY_IN(ji,jj,jk,jl,jf) = zland
+               END DO;   END DO   ;   END DO   ;   END DO
+            ENDIF
          END DO
       END SELECT
       !
-      !                           ! Migrations
-      imigr = nn_hls * jpi * ipk * ipl * ipf
-      !
-      IF( ln_timing ) CALL tic_tac(.TRUE.)
-      ! 
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, zt3sn(1,1,1,1,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, zt3ns(1,1,1,1,1,1), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err )
-      CASE ( 0 )
-         CALL mppsend( 3, zt3ns(1,1,1,1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt3sn(1,1,1,1,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, zt3ns(1,1,1,1,1,2), imigr, nono )
-         CALL mpprecv( 4, zt3sn(1,1,1,1,1,2), imigr, noso )
-         IF(l_isend)   CALL mpi_wait(ml_req1, ml_stat, ml_err )
-         IF(l_isend)   CALL mpi_wait(ml_req2, ml_stat, ml_err )
-      CASE ( 1 )
-         CALL mppsend( 3, zt3ns(1,1,1,1,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, zt3sn(1,1,1,1,1,1), imigr, noso )
-         IF(l_isend)   CALL mpi_wait(ml_req1, ml_stat, ml_err )
+      ! 5.2 fill northern halo
+      ! ----------------------
+      ishift = jpj - ihl                ! fill halo from jj = jpj-ihl+1 to jpj 
+      SELECT CASE ( ifill_no )
+      CASE ( jpfillnothing )               ! no filling 
+      CASE ( jpfillmpi   )                 ! use data received by MPI 
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, ihl   ;   DO ji = 1, jpi
+            ARRAY_IN(ji,ishift+jj,jk,jl,jf) = zrcv_no(ji,jj,jk,jl,jf)   ! jpj-ihl+1 -> jpj
+         END DO   ;   END DO   ;   END DO   ;   END DO   ;   END DO
+      CASE ( jpfillperio )                 ! use north-south periodicity
+         ishift2 = ihl
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, ihl   ;   DO ji = 1, jpi
+            ARRAY_IN(ji,ishift+jj,jk,jl,jf) = ARRAY_IN(ji,ishift2+jj,jk,jl,jf)
+         END DO;   END DO   ;   END DO   ;   END DO   ;   END DO
+      CASE ( jpfillcopy  )                 ! filling with inner domain values
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, ihl   ;   DO ji = 1, jpi
+            ARRAY_IN(ji,ishift+jj,jk,jl,jf) = ARRAY_IN(ji,ishift,jk,jl,jf)
+         END DO;   END DO   ;   END DO   ;   END DO   ;   END DO
+      CASE ( jpfillcst   )                 ! filling with constant value
+         DO jf = 1, ipf   ;   DO jl = 1, ipl   ;   DO jk = 1, ipk   ;   DO jj = 1, ihl   ;   DO ji = 1, jpi
+            ARRAY_IN(ji,ishift+jj,jk,jl,jf) = zland
+         END DO;   END DO   ;   END DO   ;   END DO   ;   END DO
       END SELECT
       !
-      IF( ln_timing ) CALL tic_tac(.FALSE.)
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj-nn_hls
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jf = 1, ipf
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     ARRAY_IN(:,ijhom+jh,jk,jl,jf) = zt3ns(:,jh,jk,jl,jf,1)
-                  END DO
-               END DO
-            END DO
-         END DO
-      CASE ( 0 )
-         DO jf = 1, ipf
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     ARRAY_IN(:,      jh,jk,jl,jf) = zt3sn(:,jh,jk,jl,jf,2)
-                     ARRAY_IN(:,ijhom+jh,jk,jl,jf) = zt3ns(:,jh,jk,jl,jf,2)
-                  END DO
-               END DO
-            END DO
-         END DO
-      CASE ( 1 )
-         DO jf = 1, ipf
-            DO jl = 1, ipl
-               DO jk = 1, ipk
-                  DO jh = 1, nn_hls
-                     ARRAY_IN(:,jh,jk,jl,jf) = zt3sn(:,jh,jk,jl,jf,1)
-                  END DO
-               END DO
-            END DO
-         END DO
-      END SELECT
-      !
-      IF( nbondj /= 2 ) DEALLOCATE( zt3ns, zt3sn )
+      ! -------------------------------------------- !
+      !     6. deallocate local temporary arrays     !
+      ! -------------------------------------------- !
+      !
+      IF( llsend_we ) THEN
+         CALL mpi_wait(ireq_we, istat, ierr )
+         DEALLOCATE( zsnd_we )
+      ENDIF
+      IF( llsend_ea )  THEN
+         CALL mpi_wait(ireq_ea, istat, ierr )
+         DEALLOCATE( zsnd_ea )
+      ENDIF
+      IF( llsend_so ) THEN
+         CALL mpi_wait(ireq_so, istat, ierr )
+         DEALLOCATE( zsnd_so )
+      ENDIF
+      IF( llsend_no ) THEN
+         CALL mpi_wait(ireq_no, istat, ierr )
+         DEALLOCATE( zsnd_no )
+      ENDIF
+      !
+      IF( llrecv_we )   DEALLOCATE( zrcv_we )
+      IF( llrecv_ea )   DEALLOCATE( zrcv_ea )
+      IF( llrecv_so )   DEALLOCATE( zrcv_so )
+      IF( llrecv_no )   DEALLOCATE( zrcv_no )
       !
    END SUBROUTINE ROUTINE_LNK
Index: /NEMO/trunk/src/OCE/LBC/mpp_nfd_generic.h90
===================================================================
--- /NEMO/trunk/src/OCE/LBC/mpp_nfd_generic.h90	(revision 11535)
+++ /NEMO/trunk/src/OCE/LBC/mpp_nfd_generic.h90	(revision 11536)
@@ -76,5 +76,5 @@
       ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
       !
-      IF( l_north_nogather ) THEN      !==  ????  ==!
+      IF( l_north_nogather ) THEN      !==  no allgather exchanges  ==!
 
          ALLOCATE(ipj_s(ipf))
@@ -200,11 +200,9 @@
             ENDIF
          END DO
-         IF( l_isend ) THEN
-            DO jr = 1,nsndto
-               IF( nfipproc(isendto(jr),jpnj) /= narea-1 .AND. nfipproc(isendto(jr),jpnj) /= -1 ) THEN
-                  CALL mpi_wait( ml_req_nf(jr), ml_stat, ml_err )
-               ENDIF
-            END DO
-         ENDIF
+         DO jr = 1,nsndto
+            IF( nfipproc(isendto(jr),jpnj) /= narea-1 .AND. nfipproc(isendto(jr),jpnj) /= -1 ) THEN
+               CALL mpi_wait( ml_req_nf(jr), ml_stat, ml_err )
+            ENDIF
+         END DO
          !
          IF( ln_timing ) CALL tic_tac(.FALSE.)
@@ -213,12 +211,10 @@
          !
          DO jf = 1, ipf
-            CALL lbc_nfd_nogather(ARRAY_IN(:,:,:,:,jf), ztabr(:,1:ipj_s(jf),:,:,jf), cd_nat LBC_ARG, psgn LBC_ARG )
-         END DO
-         !
-         DEALLOCATE( zfoldwk )
-         DEALLOCATE( ztabr ) 
-         DEALLOCATE( jj_s ) 
-         DEALLOCATE( ipj_s ) 
-      ELSE                             !==  ????  ==!
+            CALL lbc_nfd_nogather( ARRAY_IN(:,:,:,:,jf), ztabr(:,1:ipj_s(jf),:,:,jf), cd_nat LBC_ARG, psgn LBC_ARG )
+         END DO
+         !
+         DEALLOCATE( zfoldwk, ztabr, jj_s, ipj_s )
+         !
+      ELSE                             !==  allgather exchanges  ==!
          !
          ipj   = 4            ! 2nd dimension of message transfers (last j-lines)
Index: /NEMO/trunk/src/OCE/LBC/mppini.F90
===================================================================
--- /NEMO/trunk/src/OCE/LBC/mppini.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/LBC/mppini.F90	(revision 11536)
@@ -84,5 +84,7 @@
       nbondj = 2
       nidom  = FLIO_DOM_NONE
-      npolj = jperio
+      npolj = 0
+      IF( jperio == 3 .OR. jperio == 4 )   npolj = 3
+      IF( jperio == 5 .OR. jperio == 6 )   npolj = 5
       l_Iperio = jpni == 1 .AND. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6 .OR. jperio == 7)
       l_Jperio = jpnj == 1 .AND. (jperio == 2 .OR. jperio == 7)
@@ -152,4 +154,5 @@
       LOGICAL ::   llbest, llauto
       LOGICAL ::   llwrtlay
+      LOGICAL ::   ln_listonly
       INTEGER, ALLOCATABLE, DIMENSION(:)     ::   iin, ii_nono, ii_noea          ! 1D workspace
       INTEGER, ALLOCATABLE, DIMENSION(:)     ::   ijn, ii_noso, ii_nowe          !  -     -
@@ -164,19 +167,45 @@
            &             ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp, rn_time_dmp_out, &
            &             cn_ice, nn_ice_dta,                                     &
-           &             rn_ice_tem, rn_ice_sal, rn_ice_age,                     &
-           &             ln_vol, nn_volctl, nn_rimwidth, nb_jpk_bdy
-      !!----------------------------------------------------------------------
-
+           &             ln_vol, nn_volctl, nn_rimwidth
+      NAMELIST/nammpp/ jpni, jpnj, ln_nnogather, ln_listonly
+      !!----------------------------------------------------------------------
+      !
       llwrtlay = lwp .OR. ln_ctl .OR. sn_cfctl%l_layout
+      !
+      !  0. read namelists parameters
+      ! -----------------------------------
+      !
+      REWIND( numnam_ref )              ! Namelist nammpp in reference namelist
+      READ  ( numnam_ref, nammpp, IOSTAT = ios, ERR = 901 )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nammpp in reference namelist' )
+      REWIND( numnam_cfg )              ! Namelist nammpp in confguration namelist
+      READ  ( numnam_cfg, nammpp, IOSTAT = ios, ERR = 902 )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nammpp in configuration namelist' )   
+      !
+      IF(lwp) THEN
+            WRITE(numout,*) '   Namelist nammpp'
+         IF( jpni < 1 .OR. jpnj < 1  ) THEN
+            WRITE(numout,*) '      jpni and jpnj will be calculated automatically'
+         ELSE
+            WRITE(numout,*) '      processor grid extent in i                            jpni = ', jpni
+            WRITE(numout,*) '      processor grid extent in j                            jpnj = ', jpnj
+         ENDIF
+            WRITE(numout,*) '      avoid use of mpi_allgather at the north fold  ln_nnogather = ', ln_nnogather
+      ENDIF
+      !
+      IF(lwm)   WRITE( numond, nammpp )
+
       ! do we need to take into account bdy_msk?
       REWIND( numnam_ref )              ! Namelist nambdy in reference namelist : BDY
       READ  ( numnam_ref, nambdy, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy in reference namelist (mppini)', lwp )
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy in reference namelist (mppini)' )
       REWIND( numnam_cfg )              ! Namelist nambdy in configuration namelist : BDY
       READ  ( numnam_cfg, nambdy, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'nambdy in configuration namelist (mppini)', lwp )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'nambdy in configuration namelist (mppini)' )
       !
       IF(               ln_read_cfg ) CALL iom_open( cn_domcfg,    numbot )
       IF( ln_bdy .AND. ln_mask_file ) CALL iom_open( cn_mask_file, numbdy )
+      !
+      IF( ln_listonly )   CALL mpp_init_bestpartition( MAX(mppsize,jpni*jpnj), ldlist = .TRUE. )   ! must be done by all core
       !
       !  1. Dimension arrays for subdomains
@@ -241,5 +270,4 @@
          CALL ctl_stop( ctmp1, ctmp2, ctmp3, ' ', ctmp4, ' ' )
          CALL mpp_init_bestpartition( mppsize, ldlist = .TRUE. )   ! must be done by all core
-         CALL ctl_stop( 'STOP' )
       ENDIF
 
@@ -266,5 +294,4 @@
          ENDIF
          CALL mpp_init_bestpartition( mppsize, ldlist = .TRUE. )   ! must be done by all core
-         CALL ctl_stop( 'STOP' )
       ENDIF
 
@@ -816,5 +843,5 @@
       INTEGER :: isziref, iszjref
       INTEGER :: inbij, iszij
-      INTEGER :: inbimax, inbjmax, inbijmax
+      INTEGER :: inbimax, inbjmax, inbijmax, inbijold
       INTEGER :: isz0, isz1
       INTEGER, DIMENSION(  :), ALLOCATABLE :: indexok
@@ -941,25 +968,37 @@
       DEALLOCATE( indexok, inbi1, inbj1, iszi1, iszj1 )
 
-      IF( llist ) THEN  ! we print about 21 best partitions
+      IF( llist ) THEN
          IF(lwp) THEN
             WRITE(numout,*)
-            WRITE(numout,         *) '                  For your information:'
-            WRITE(numout,'(a,i5,a)') '  list of the best partitions around ',   knbij, ' mpi processes'
-            WRITE(numout,         *) '  --------------------------------------', '-----', '--------------'
+            WRITE(numout,*) '                  For your information:'
+            WRITE(numout,*) '  list of the best partitions including land supression'
+            WRITE(numout,*) '  -----------------------------------------------------'
             WRITE(numout,*)
          END IF
-         iitarget = MINLOC( inbi0(:)*inbj0(:), mask = inbi0(:)*inbj0(:) >= knbij, dim = 1 )
-         DO ji = MAX(1,iitarget-10), MIN(isz0,iitarget+10)
+         ji = isz0   ! initialization with the largest value
+         ALLOCATE( llisoce(inbi0(ji), inbj0(ji)) )
+         CALL mpp_init_isoce( inbi0(ji), inbj0(ji), llisoce ) ! Warning: must be call by all cores (call mpp_sum)
+         inbijold = COUNT(llisoce)
+         DEALLOCATE( llisoce )
+         DO ji =isz0-1,1,-1
             ALLOCATE( llisoce(inbi0(ji), inbj0(ji)) )
             CALL mpp_init_isoce( inbi0(ji), inbj0(ji), llisoce ) ! Warning: must be call by all cores (call mpp_sum)
             inbij = COUNT(llisoce)
             DEALLOCATE( llisoce )
-            IF(lwp) WRITE(numout,'(a, i5, a, i5, a, i4, a, i4, a, i9, a, i5, a, i5, a)')    &
-               &     'nb_cores ' , inbij,' oce + ', inbi0(ji)*inbj0(ji) - inbij             &
-               &                                , ' land ( ', inbi0(ji),' x ', inbj0(ji),   &
-               & ' ), nb_points ', iszi0(ji)*iszj0(ji),' ( ', iszi0(ji),' x ', iszj0(ji),' )'
+            IF(lwp .AND. inbij < inbijold) THEN
+               WRITE(numout,'(a, i6, a, i6, a, f4.1, a, i9, a, i6, a, i6, a)')                                 &
+                  &   'nb_cores oce: ', inbij, ', land domains excluded: ', inbi0(ji)*inbj0(ji) - inbij,       &
+                  &   ' (', REAL(inbi0(ji)*inbj0(ji) - inbij,wp) / REAL(inbi0(ji)*inbj0(ji),wp) *100.,         &
+                  &   '%), largest oce domain: ', iszi0(ji)*iszj0(ji), ' ( ', iszi0(ji),' x ', iszj0(ji), ' )'
+               inbijold = inbij
+            END IF
          END DO
          DEALLOCATE( inbi0, inbj0, iszi0, iszj0 )
-         RETURN
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*)  '  -----------------------------------------------------------'
+         ENDIF
+         CALL mppsync
+         CALL mppstop( ld_abort = .TRUE. )
       ENDIF
       
Index: /NEMO/trunk/src/OCE/LDF/ldfdyn.F90
===================================================================
--- /NEMO/trunk/src/OCE/LDF/ldfdyn.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/LDF/ldfdyn.F90	(revision 11536)
@@ -117,9 +117,9 @@
       REWIND( numnam_ref )              ! Namelist namdyn_ldf in reference namelist : Lateral physics
       READ  ( numnam_ref, namdyn_ldf, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_ldf in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_ldf in reference namelist' )
 
       REWIND( numnam_cfg )              ! Namelist namdyn_ldf in configuration namelist : Lateral physics
       READ  ( numnam_cfg, namdyn_ldf, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_ldf in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_ldf in configuration namelist' )
       IF(lwm) WRITE ( numond, namdyn_ldf )
 
Index: /NEMO/trunk/src/OCE/LDF/ldftra.F90
===================================================================
--- /NEMO/trunk/src/OCE/LDF/ldftra.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/LDF/ldftra.F90	(revision 11536)
@@ -154,8 +154,8 @@
       REWIND( numnam_ref )              ! Namelist namtra_ldf in reference namelist : Lateral physics on tracers
       READ  ( numnam_ref, namtra_ldf, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_ldf in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_ldf in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namtra_ldf in configuration namelist : Lateral physics on tracers
       READ  ( numnam_cfg, namtra_ldf, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtra_ldf in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtra_ldf in configuration namelist' )
       IF(lwm) WRITE( numond, namtra_ldf )
       !
@@ -512,9 +512,9 @@
       REWIND( numnam_ref )              ! Namelist namtra_eiv in reference namelist : eddy induced velocity param.
       READ  ( numnam_ref, namtra_eiv, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_eiv in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_eiv in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist namtra_eiv in configuration namelist : eddy induced velocity param.
       READ  ( numnam_cfg, namtra_eiv, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtra_eiv in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtra_eiv in configuration namelist' )
       IF(lwm)  WRITE ( numond, namtra_eiv )
 
Index: /NEMO/trunk/src/OCE/OBS/diaobs.F90
===================================================================
--- /NEMO/trunk/src/OCE/OBS/diaobs.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/OBS/diaobs.F90	(revision 11536)
@@ -203,8 +203,8 @@
       REWIND( numnam_ref )   ! Namelist namobs in reference namelist
       READ  ( numnam_ref, namobs, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namobs in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namobs in reference namelist' )
       REWIND( numnam_cfg )   ! Namelist namobs in configuration namelist
       READ  ( numnam_cfg, namobs, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namobs in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namobs in configuration namelist' )
       IF(lwm) WRITE ( numond, namobs )
 
Index: /NEMO/trunk/src/OCE/SBC/fldread.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/fldread.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/fldread.F90	(revision 11536)
@@ -48,5 +48,5 @@
    TYPE, PUBLIC ::   FLD_N      !: Namelist field informations
       CHARACTER(len = 256) ::   clname      ! generic name of the NetCDF flux file
-      REAL(wp)             ::   nfreqh      ! frequency of each flux file
+      REAL(wp)             ::   freqh       ! frequency of each flux file
       CHARACTER(len = 34)  ::   clvar       ! generic name of the variable in the NetCDF flux file
       LOGICAL              ::   ln_tint     ! time interpolation or not (T/F)
@@ -64,5 +64,5 @@
       CHARACTER(len = 256)            ::   clrootname   ! generic name of the NetCDF file
       CHARACTER(len = 256)            ::   clname       ! current name of the NetCDF file
-      REAL(wp)                        ::   nfreqh       ! frequency of each flux file
+      REAL(wp)                        ::   freqh        ! frequency of each flux file
       CHARACTER(len = 34)             ::   clvar        ! generic name of the variable in the NetCDF flux file
       LOGICAL                         ::   ln_tint      ! time interpolation or not (T/F)
@@ -80,12 +80,12 @@
       INTEGER                         ::   nreclast     ! last record to be read in the current file
       CHARACTER(len = 256)            ::   lsmname      ! current name of the NetCDF mask file acting as a key
-      INTEGER                         ::   igrd         ! grid type for bdy data
-      INTEGER                         ::   ibdy         ! bdy set id number
+      !                                                 ! 
+      !                                                 ! Variables related to BDY
+      INTEGER                         ::   igrd         !   grid type for bdy data
+      INTEGER                         ::   ibdy         !   bdy set id number
+      INTEGER, POINTER, DIMENSION(:)  ::   imap         !   Array of integer pointers to 1D arrays
+      LOGICAL                         ::   ltotvel      !   total velocity or not (T/F)
+      LOGICAL                         ::   lzint        !   T if it requires a vertical interpolation
    END TYPE FLD
-
-   TYPE, PUBLIC ::   MAP_POINTER      !: Map from input data file to local domain
-      INTEGER, POINTER, DIMENSION(:)  ::  ptr           ! Array of integer pointers to 1D arrays
-      LOGICAL                         ::  ll_unstruc    ! Unstructured (T) or structured (F) boundary data file
-   END TYPE MAP_POINTER
 
 !$AGRIF_DO_NOT_TREAT
@@ -129,5 +129,5 @@
 CONTAINS
 
-   SUBROUTINE fld_read( kt, kn_fsbc, sd, map, kit, kt_offset, jpk_bdy, fvl )
+   SUBROUTINE fld_read( kt, kn_fsbc, sd, kit, kt_offset )
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE fld_read  ***
@@ -144,5 +144,4 @@
       INTEGER  , INTENT(in   )               ::   kn_fsbc   ! sbc computation period (in time step) 
       TYPE(FLD), INTENT(inout), DIMENSION(:) ::   sd        ! input field related variables
-      TYPE(MAP_POINTER),INTENT(in), OPTIONAL, DIMENSION(:) ::   map   ! global-to-local mapping indices
       INTEGER  , INTENT(in   ), OPTIONAL     ::   kit       ! subcycle timestep for timesplitting option
       INTEGER  , INTENT(in   ), OPTIONAL     ::   kt_offset ! provide fields at time other than "now"
@@ -150,6 +149,4 @@
       !                                                     !   kt_offset = +1 => fields at "after"  time level
       !                                                     !   etc.
-      INTEGER  , INTENT(in   ), OPTIONAL     ::   jpk_bdy   ! number of vertical levels in the BDY data
-      LOGICAL  , INTENT(in   ), OPTIONAL     ::   fvl   ! number of vertical levels in the BDY data
       !!
       INTEGER  ::   itmp         ! local variable
@@ -166,5 +163,4 @@
       REAL(wp) ::   ztintb       ! ratio applied to before records when doing time interpolation
       CHARACTER(LEN=1000) ::   clfmt  ! write format
-      TYPE(MAP_POINTER)   ::   imap   ! global-to-local mapping indices
       !!---------------------------------------------------------------------
       ll_firstcall = kt == nit000
@@ -175,6 +171,4 @@
       ENDIF
       IF( PRESENT(kt_offset) )   it_offset = kt_offset
-
-      imap%ptr => NULL()
 
       ! Note that shifting time to be centrered in the middle of sbc time step impacts only nsec_* variables of the calendar 
@@ -188,10 +182,6 @@
       IF( ll_firstcall ) THEN                      ! initialization
          DO jf = 1, imf 
-            IF( PRESENT(map) ) imap = map(jf)
-               IF( PRESENT(jpk_bdy) ) THEN
-                  CALL fld_init( kn_fsbc, sd(jf), imap, jpk_bdy, fvl )  ! read each before field (put them in after as they will be swapped)
-               ELSE
-                  CALL fld_init( kn_fsbc, sd(jf), imap )  ! read each before field (put them in after as they will be swapped)
-               ENDIF
+            IF( TRIM(sd(jf)%clrootname) == 'NOT USED' )   CYCLE
+            CALL fld_init( kn_fsbc, sd(jf) )       ! read each before field (put them in after as they will be swapped)
          END DO
          IF( lwp ) CALL wgt_print()                ! control print
@@ -202,8 +192,8 @@
          !
          DO jf = 1, imf                            ! ---   loop over field   --- !
-            
+
+            IF( TRIM(sd(jf)%clrootname) == 'NOT USED' )   CYCLE
+                      
             IF( isecsbc > sd(jf)%nrec_a(2) .OR. ll_firstcall ) THEN    ! read/update the after data?
-
-               IF( PRESENT(map) )   imap = map(jf)   ! temporary definition of map
 
                sd(jf)%nrec_b(:) = sd(jf)%nrec_a(:)                                  ! swap before record informations
@@ -213,5 +203,5 @@
                CALL fld_rec( kn_fsbc, sd(jf), kt_offset = it_offset, kit = kit )    ! update after record informations
 
-               ! if kn_fsbc*rdt is larger than nfreqh (which is kind of odd),
+               ! if kn_fsbc*rdt is larger than freqh (which is kind of odd),
                ! it is possible that the before value is no more the good one... we have to re-read it
                ! if before is not the last record of the file currently opened and after is the first record to be read
@@ -222,8 +212,8 @@
                   itmp = sd(jf)%nrec_a(1)                       ! temporary storage
                   sd(jf)%nrec_a(1) = sd(jf)%nreclast            ! read the last record of the file currently opened
-                  CALL fld_get( sd(jf), imap )                  ! read after data
+                  CALL fld_get( sd(jf) )                        ! read after data
                   sd(jf)%fdta(:,:,:,1) = sd(jf)%fdta(:,:,:,2)   ! re-swap before record field
                   sd(jf)%nrec_b(1) = sd(jf)%nrec_a(1)           ! update before record informations
-                  sd(jf)%nrec_b(2) = sd(jf)%nrec_a(2) - NINT( sd(jf)%nfreqh * 3600 )  ! assume freq to be in hours in this case
+                  sd(jf)%nrec_b(2) = sd(jf)%nrec_a(2) - NINT( sd(jf)%freqh * 3600. )  ! assume freq to be in hours in this case
                   sd(jf)%rotn(1)   = sd(jf)%rotn(2)             ! update before rotate informations
                   sd(jf)%nrec_a(1) = itmp                       ! move back to after record 
@@ -234,5 +224,5 @@
                IF( sd(jf)%ln_tint ) THEN
                   
-                  ! if kn_fsbc*rdt is larger than nfreqh (which is kind of odd),
+                  ! if kn_fsbc*rdt is larger than freqh (which is kind of odd),
                   ! it is possible that the before value is no more the good one... we have to re-read it
                   ! if before record is not just just before the after record...
@@ -240,8 +230,8 @@
                      &                   .AND. sd(jf)%nrec_b(1) /= sd(jf)%nrec_a(1) - 1 ) THEN   
                      sd(jf)%nrec_a(1) = sd(jf)%nrec_a(1) - 1       ! move back to before record
-                     CALL fld_get( sd(jf), imap )                  ! read after data
+                     CALL fld_get( sd(jf) )                        ! read after data
                      sd(jf)%fdta(:,:,:,1) = sd(jf)%fdta(:,:,:,2)   ! re-swap before record field
                      sd(jf)%nrec_b(1) = sd(jf)%nrec_a(1)           ! update before record informations
-                     sd(jf)%nrec_b(2) = sd(jf)%nrec_a(2) - NINT( sd(jf)%nfreqh * 3600 )  ! assume freq to be in hours in this case
+                     sd(jf)%nrec_b(2) = sd(jf)%nrec_a(2) - NINT( sd(jf)%freqh * 3600. )  ! assume freq to be in hours in this case
                      sd(jf)%rotn(1)   = sd(jf)%rotn(2)             ! update before rotate informations
                      sd(jf)%nrec_a(1) = sd(jf)%nrec_a(1) + 1       ! move back to after record
@@ -268,5 +258,5 @@
                      ! year/month/week/day, next year/month/week/day file must exist
                      isecend = nsec_year + nsec1jan000 + (nitend - kt) * NINT(rdt)   ! second at the end of the run
-                     llstop = isecend > sd(jf)%nrec_a(2)                                   ! read more than 1 record of next year
+                     llstop = isecend > sd(jf)%nrec_a(2)                             ! read more than 1 record of next year
                      ! we suppose that the date of next file is next day (should be ok even for weekly files...)
                      CALL fld_clopn( sd(jf), nyear  + COUNT((/llnxtyr /))                                           ,         &
@@ -277,5 +267,5 @@
                         CALL ctl_warn('next year/month/week/day file: '//TRIM(sd(jf)%clname)//     &
                            &     ' not present -> back to current year/month/day')
-                        CALL fld_clopn( sd(jf) )       ! back to the current year/month/day
+                        CALL fld_clopn( sd(jf) )               ! back to the current year/month/day
                         sd(jf)%nrec_a(1) = sd(jf)%nreclast     ! force to read the last record in the current year file
                      ENDIF
@@ -285,9 +275,6 @@
                   
                ! read after data
-               IF( PRESENT(jpk_bdy) ) THEN
-                  CALL fld_get( sd(jf), imap, jpk_bdy, fvl)
-               ELSE
-                  CALL fld_get( sd(jf), imap )
-               ENDIF
+               CALL fld_get( sd(jf) )
+               
             ENDIF   ! read new data?
          END DO                                    ! --- end loop over field --- !
@@ -296,4 +283,6 @@
 
          DO jf = 1, imf                            ! ---   loop over field   --- !
+            !
+            IF( TRIM(sd(jf)%clrootname) == 'NOT USED' )   CYCLE
             !
             IF( sd(jf)%ln_tint ) THEN              ! temporal interpolation
@@ -327,5 +316,5 @@
 
 
-   SUBROUTINE fld_init( kn_fsbc, sdjf, map , jpk_bdy, fvl)
+   SUBROUTINE fld_init( kn_fsbc, sdjf )
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE fld_init  ***
@@ -336,7 +325,4 @@
       INTEGER  , INTENT(in   ) ::   kn_fsbc      ! sbc computation period (in time step) 
       TYPE(FLD), INTENT(inout) ::   sdjf         ! input field related variables
-      TYPE(MAP_POINTER),INTENT(in) ::   map      ! global-to-local mapping indices
-      INTEGER  , INTENT(in), OPTIONAL :: jpk_bdy ! number of vertical levels in the BDY data
-      LOGICAL  , INTENT(in), OPTIONAL :: fvl     ! number of vertical levels in the BDY data
       !!
       LOGICAL :: llprevyr              ! are we reading previous year  file?
@@ -351,4 +337,5 @@
       CHARACTER(LEN=1000) ::   clfmt   ! write format
       !!---------------------------------------------------------------------
+      !
       llprevyr   = .FALSE.
       llprevmth  = .FALSE.
@@ -365,5 +352,5 @@
          !
          IF( sdjf%nrec_a(1) == 0  ) THEN   ! we redefine record sdjf%nrec_a(1) with the last record of previous year file
-            IF    ( sdjf%nfreqh == -12 ) THEN   ! yearly mean
+            IF    ( NINT(sdjf%freqh) == -12 ) THEN   ! yearly mean
                IF( sdjf%cltype == 'yearly' ) THEN             ! yearly file
                   sdjf%nrec_a(1) = 1                                                       ! force to read the unique record
@@ -372,5 +359,5 @@
                   CALL ctl_stop( "fld_init: yearly mean file must be in a yearly type of file: "//TRIM(sdjf%clrootname) )
                ENDIF
-            ELSEIF( sdjf%nfreqh ==  -1 ) THEN   ! monthly mean
+            ELSEIF( NINT(sdjf%freqh) ==  -1 ) THEN   ! monthly mean
                IF( sdjf%cltype == 'monthly' ) THEN            ! monthly file
                   sdjf%nrec_a(1) = 1                                                       ! force to read the unique record
@@ -381,20 +368,20 @@
                   llprevyr = .NOT. sdjf%ln_clim                                            ! use previous year  file?
                ENDIF
-            ELSE                                ! higher frequency mean (in hours) 
+            ELSE                                     ! higher frequency mean (in hours) 
                IF    ( sdjf%cltype      == 'monthly' ) THEN   ! monthly file
-                  sdjf%nrec_a(1) = NINT( 24 * nmonth_len(nmonth-1) / sdjf%nfreqh )         ! last record of previous month
+                  sdjf%nrec_a(1) = NINT( 24. * REAL(nmonth_len(nmonth-1),wp) / sdjf%freqh )! last record of previous month
                   llprevmth = .TRUE.                                                       ! use previous month file?
                   llprevyr  = llprevmth .AND. nmonth == 1                                  ! use previous year  file?
                ELSEIF( sdjf%cltype(1:4) == 'week'    ) THEN   ! weekly file
                   llprevweek = .TRUE.                                                      ! use previous week  file?
-                  sdjf%nrec_a(1) = NINT( 24 * 7 / sdjf%nfreqh )                            ! last record of previous week
+                  sdjf%nrec_a(1) = NINT( 24. * 7. / sdjf%freqh )                           ! last record of previous week
                   isec_week = NINT(rday) * 7                                               ! add a shift toward previous week
                ELSEIF( sdjf%cltype      == 'daily'   ) THEN   ! daily file
-                  sdjf%nrec_a(1) = NINT( 24 / sdjf%nfreqh )                                ! last record of previous day
+                  sdjf%nrec_a(1) = NINT( 24. / sdjf%freqh )                                ! last record of previous day
                   llprevday = .TRUE.                                                       ! use previous day   file?
                   llprevmth = llprevday .AND. nday   == 1                                  ! use previous month file?
                   llprevyr  = llprevmth .AND. nmonth == 1                                  ! use previous year  file?
                ELSE                                           ! yearly file
-                  sdjf%nrec_a(1) = NINT( 24 * nyear_len(0) / sdjf%nfreqh )                 ! last record of previous year 
+                  sdjf%nrec_a(1) = NINT( 24. * REAL(nyear_len(0),wp) / sdjf%freqh )        ! last record of previous year 
                   llprevyr = .NOT. sdjf%ln_clim                                            ! use previous year  file?
                ENDIF
@@ -433,9 +420,5 @@
          !
          ! read before data in after arrays(as we will swap it later)
-         IF( PRESENT(jpk_bdy) ) THEN
-            CALL fld_get( sdjf, map, jpk_bdy, fvl )
-         ELSE
-            CALL fld_get( sdjf, map )
-         ENDIF
+         CALL fld_get( sdjf )
          !
          clfmt = "('   fld_init : time-interpolation for ', a, ' read previous record = ', i6, ' at time = ', f7.2, ' days')"
@@ -456,5 +439,5 @@
       !!              if sdjf%ln_tint = .FALSE.
       !!                  nrec_a(1): record number
-      !!                  nrec_b(2) and nrec_a(2): time of the beginning and end of the record (for print only)
+      !!                  nrec_b(2) and nrec_a(2): time of the beginning and end of the record
       !!----------------------------------------------------------------------
       INTEGER  , INTENT(in   )           ::   kn_fsbc   ! sbc computation period (in time step) 
@@ -484,14 +467,14 @@
       ELSE                                      ;   it_offset = 0
       ENDIF
-      IF( PRESENT(kt_offset) )   it_offset = kt_offset
+      IF( PRESENT(kt_offset) )      it_offset = kt_offset
       IF( PRESENT(kit) ) THEN   ;   it_offset = ( kit + it_offset ) * NINT( rdt/REAL(nn_baro,wp) )
       ELSE                      ;   it_offset =         it_offset   * NINT(       rdt            )
       ENDIF
       !
-      !                                      ! =========== !
-      IF    ( sdjf%nfreqh == -12 ) THEN      ! yearly mean
-         !                                   ! =========== !
-         !
-         IF( sdjf%ln_tint ) THEN                 ! time interpolation, shift by 1/2 record
+      !                                           ! =========== !
+      IF    ( NINT(sdjf%freqh) == -12 ) THEN      ! yearly mean
+         !                                        ! =========== !
+         !
+         IF( sdjf%ln_tint ) THEN                  ! time interpolation, shift by 1/2 record
             !
             !                  INT( ztmp )
@@ -505,6 +488,6 @@
             !       forcing record :    1 
             !                            
-            ztmp = REAL( nsec_year, wp ) / ( REAL( nyear_len(1), wp ) * rday ) + 0.5 &
-           &       + REAL( it_offset, wp ) / ( REAL( nyear_len(1), wp ) * rday )
+            ztmp =  REAL( nsec_year, wp ) / ( REAL( nyear_len(1), wp ) * rday ) + 0.5 &
+               &  + REAL( it_offset, wp ) / ( REAL( nyear_len(1), wp ) * rday )
             sdjf%nrec_a(1) = 1 + INT( ztmp ) - COUNT((/llbefore/))
             ! swap at the middle of the year
@@ -514,5 +497,5 @@
                                     & INT(ztmp) * INT(rday) * nyear_len(1) + INT(ztmp) * NINT( 0.5 * rday) * nyear_len(2) 
             ENDIF
-         ELSE                                    ! no time interpolation
+         ELSE                                     ! no time interpolation
             sdjf%nrec_a(1) = 1
             sdjf%nrec_a(2) = NINT(rday) * nyear_len(1) + nsec1jan000   ! swap at the end    of the year
@@ -520,9 +503,9 @@
          ENDIF
          !
-         !                                   ! ============ !
-      ELSEIF( sdjf%nfreqh ==  -1 ) THEN      ! monthly mean !
-         !                                   ! ============ !
-         !
-         IF( sdjf%ln_tint ) THEN                 ! time interpolation, shift by 1/2 record
+         !                                        ! ============ !
+      ELSEIF( NINT(sdjf%freqh) ==  -1 ) THEN      ! monthly mean !
+         !                                        ! ============ !
+         !
+         IF( sdjf%ln_tint ) THEN                  ! time interpolation, shift by 1/2 record
             !
             !                  INT( ztmp )
@@ -536,6 +519,6 @@
             !       forcing record :  nmonth 
             !                            
-            ztmp = REAL( nsec_month, wp ) / ( REAL( nmonth_len(nmonth), wp ) * rday ) + 0.5 &
-           &       + REAL( it_offset, wp ) / ( REAL( nmonth_len(nmonth), wp ) * rday )
+            ztmp =  REAL( nsec_month, wp ) / ( REAL( nmonth_len(nmonth), wp ) * rday ) + 0.5 &
+           &      + REAL(  it_offset, wp ) / ( REAL( nmonth_len(nmonth), wp ) * rday )
             imth = nmonth + INT( ztmp ) - COUNT((/llbefore/))
             IF( sdjf%cltype == 'monthly' ) THEN   ;   sdjf%nrec_a(1) = 1 + INT( ztmp ) - COUNT((/llbefore/))
@@ -551,9 +534,9 @@
          ENDIF
          !
-         !                                   ! ================================ !
-      ELSE                                   ! higher frequency mean (in hours)
-         !                                   ! ================================ !
-         !
-         ifreq_sec = NINT( sdjf%nfreqh * 3600 )                                         ! frequency mean (in seconds)
+         !                                        ! ================================ !
+      ELSE                                        ! higher frequency mean (in hours)
+         !                                        ! ================================ !
+         !
+         ifreq_sec = NINT( sdjf%freqh * 3600. )                                         ! frequency mean (in seconds)
          IF( sdjf%cltype(1:4) == 'week' )   isec_week = ksec_week( sdjf%cltype(6:8) )   ! since the first day of the current week
          ! number of second since the beginning of the file
@@ -565,5 +548,5 @@
          ztmp = ztmp + 0.5 * REAL(kn_fsbc - 1, wp) * rdt + REAL( it_offset, wp )        ! centrered in the middle of sbc time step
          ztmp = ztmp + 0.01 * rdt                                                       ! avoid truncation error 
-         IF( sdjf%ln_tint ) THEN                ! time interpolation, shift by 1/2 record
+         IF( sdjf%ln_tint ) THEN                 ! time interpolation, shift by 1/2 record
             !
             !          INT( ztmp/ifreq_sec + 0.5 )
@@ -579,5 +562,5 @@
             !                   
             ztmp= ztmp / REAL(ifreq_sec, wp) + 0.5
-         ELSE                                   ! no time interpolation
+         ELSE                                    ! no time interpolation
             !
             !           INT( ztmp/ifreq_sec )
@@ -610,8 +593,10 @@
       ENDIF
       !
+      IF( .NOT. sdjf%ln_tint ) sdjf%nrec_a(2) = sdjf%nrec_a(2) - 1   ! last second belongs to bext record : *----(
+      !
    END SUBROUTINE fld_rec
 
 
-   SUBROUTINE fld_get( sdjf, map, jpk_bdy, fvl )
+   SUBROUTINE fld_get( sdjf )
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE fld_get  ***
@@ -620,7 +605,4 @@
       !!----------------------------------------------------------------------
       TYPE(FLD)        , INTENT(inout) ::   sdjf   ! input field related variables
-      TYPE(MAP_POINTER), INTENT(in   ) ::   map    ! global-to-local mapping indices
-      INTEGER  , INTENT(in), OPTIONAL  ::   jpk_bdy ! number of vertical levels in the bdy data
-      LOGICAL  , INTENT(in), OPTIONAL  ::   fvl     ! number of vertical levels in the bdy data
       !
       INTEGER ::   ipk      ! number of vertical levels of sdjf%fdta ( 2D: ipk=1 ; 3D: ipk=jpk )
@@ -634,16 +616,10 @@
       ipk = SIZE( sdjf%fnow, 3 )
       !
-      IF( ASSOCIATED(map%ptr) ) THEN
-         IF( PRESENT(jpk_bdy) ) THEN
-            IF( sdjf%ln_tint ) THEN   ;   CALL fld_map( sdjf%num, sdjf%clvar, sdjf%fdta(:,:,:,2),                &
-                                                        sdjf%nrec_a(1), map, sdjf%igrd, sdjf%ibdy, jpk_bdy, fvl )
-            ELSE                      ;   CALL fld_map( sdjf%num, sdjf%clvar, sdjf%fnow(:,:,:  ),                &
-                                                        sdjf%nrec_a(1), map, sdjf%igrd, sdjf%ibdy, jpk_bdy, fvl )
-            ENDIF
-         ELSE
-            IF( sdjf%ln_tint ) THEN   ;   CALL fld_map( sdjf%num, sdjf%clvar, sdjf%fdta(:,:,:,2), sdjf%nrec_a(1), map )
-            ELSE                      ;   CALL fld_map( sdjf%num, sdjf%clvar, sdjf%fnow(:,:,:  ), sdjf%nrec_a(1), map )
-            ENDIF
-         ENDIF        
+      IF( ASSOCIATED(sdjf%imap) ) THEN
+         IF( sdjf%ln_tint ) THEN   ;   CALL fld_map( sdjf%num, sdjf%clvar, sdjf%fdta(:,:,:,2), sdjf%nrec_a(1),   &
+            &                                        sdjf%imap, sdjf%igrd, sdjf%ibdy, sdjf%ltotvel, sdjf%lzint )
+         ELSE                      ;   CALL fld_map( sdjf%num, sdjf%clvar, sdjf%fnow(:,:,:  ), sdjf%nrec_a(1),   &
+            &                                        sdjf%imap, sdjf%igrd, sdjf%ibdy, sdjf%ltotvel, sdjf%lzint )
+         ENDIF
       ELSE IF( LEN(TRIM(sdjf%wgtname)) > 0 ) THEN
          CALL wgt_list( sdjf, iw )
@@ -700,5 +676,6 @@
    END SUBROUTINE fld_get
 
-   SUBROUTINE fld_map( num, clvar, dta, nrec, map, igrd, ibdy, jpk_bdy, fvl )
+   
+   SUBROUTINE fld_map( knum, cdvar, pdta, krec, kmap, kgrd, kbdy, ldtotvel, ldzint )
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE fld_map  ***
@@ -707,136 +684,144 @@
       !!                using a general mapping (for open boundaries)
       !!----------------------------------------------------------------------
-
-      USE bdy_oce, ONLY: ln_bdy, idx_bdy, dta_global, dta_global_z, dta_global_dz, dta_global2, dta_global2_z, dta_global2_dz                 ! workspace to read in global data arrays
-
-      INTEGER                   , INTENT(in ) ::   num     ! stream number
-      CHARACTER(LEN=*)          , INTENT(in ) ::   clvar   ! variable name
-      REAL(wp), DIMENSION(:,:,:), INTENT(out) ::   dta     ! output field on model grid (2 dimensional)
-      INTEGER                   , INTENT(in ) ::   nrec    ! record number to read (ie time slice)
-      TYPE(MAP_POINTER)         , INTENT(in ) ::   map     ! global-to-local mapping indices
-      INTEGER  , INTENT(in), OPTIONAL         ::   igrd, ibdy, jpk_bdy  ! grid type, set number and number of vertical levels in the bdy data
-      LOGICAL  , INTENT(in), OPTIONAL         ::   fvl     ! grid type, set number and number of vertical levels in the bdy data
-      INTEGER                                 ::   jpkm1_bdy! number of vertical levels in the bdy data minus 1
-      !!
-      INTEGER                                 ::   ipi      ! length of boundary data on local process
-      INTEGER                                 ::   ipj      ! length of dummy dimension ( = 1 )
-      INTEGER                                 ::   ipk      ! number of vertical levels of dta ( 2D: ipk=1 ; 3D: ipk=jpk )
-      INTEGER                                 ::   ilendta  ! length of data in file
-      INTEGER                                 ::   idvar    ! variable ID
-      INTEGER                                 ::   ib, ik, ji, jj   ! loop counters
-      INTEGER                                 ::   ierr
-      REAL(wp)                                ::   fv          ! fillvalue 
-      REAL(wp), POINTER, DIMENSION(:,:,:)     ::   dta_read    ! work space for global data
-      REAL(wp), POINTER, DIMENSION(:,:,:)     ::   dta_read_z  ! work space for global data
-      REAL(wp), POINTER, DIMENSION(:,:,:)     ::   dta_read_dz ! work space for global data
-      !!---------------------------------------------------------------------
-      !
-      ipi = SIZE( dta, 1 )
-      ipj = 1
-      ipk = SIZE( dta, 3 )
-      !
-      idvar   = iom_varid( num, clvar )
-      ilendta = iom_file(num)%dimsz(1,idvar)
-
-      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
-            IF( PRESENT(jpk_bdy) ) THEN
-               IF( jpk_bdy>0 ) THEN
-                  dta_read_z => dta_global_z
-                  dta_read_dz => dta_global_dz
-                  jpkm1_bdy = jpk_bdy-1
-               ENDIF
-            ENDIF
-         ELSE                       ! structured open boundary file
-            dta_read => dta_global2
-            IF( PRESENT(jpk_bdy) ) THEN
-               IF( jpk_bdy>0 ) THEN
-                  dta_read_z => dta_global2_z
-                  dta_read_dz => dta_global2_dz
-                  jpkm1_bdy = jpk_bdy-1
-               ENDIF
-            ENDIF
-         ENDIF
-      ENDIF
-
-      IF(lwp) WRITE(numout,*) 'Dim size for ',        TRIM(clvar),' is ', ilendta
-      IF(lwp) WRITE(numout,*) 'Number of levels for ',TRIM(clvar),' is ', ipk
-      !
-      SELECT CASE( ipk )
-      CASE(1)        ;   
-      CALL iom_get ( num, jpdom_unknown, clvar, dta_read(1:ilendta,1:ipj,1    ), nrec )
-         IF ( map%ll_unstruc) THEN ! unstructured open boundary data file
-            DO ib = 1, ipi
-              DO ik = 1, ipk
-                dta(ib,1,ik) =  dta_read(map%ptr(ib),1,ik)
-              END DO
-            END DO
-         ELSE ! we assume that this is a structured open boundary file
-            DO ib = 1, ipi
-               jj=1+floor(REAL(map%ptr(ib)-1)/REAL(ilendta))
-               ji=map%ptr(ib)-(jj-1)*ilendta
-               DO ik = 1, ipk
-                  dta(ib,1,ik) =  dta_read(ji,jj,ik)
-               END DO
-            END DO
-         ENDIF
+      INTEGER                   , INTENT(in   ) ::   knum         ! stream number
+      CHARACTER(LEN=*)          , INTENT(in   ) ::   cdvar        ! variable name
+      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pdta         ! bdy output field on model grid
+      INTEGER                   , INTENT(in   ) ::   krec         ! record number to read (ie time slice)
+      INTEGER , DIMENSION(:)    , INTENT(in   ) ::   kmap         ! global-to-local bdy mapping indices
+      ! optional variables used for vertical interpolation:
+      INTEGER, OPTIONAL         , INTENT(in   ) ::   kgrd         ! grid type (t, u, v)
+      INTEGER, OPTIONAL         , INTENT(in   ) ::   kbdy         ! bdy number
+      LOGICAL, OPTIONAL         , INTENT(in   ) ::   ldtotvel     ! true if total ( = barotrop + barocline) velocity
+      LOGICAL, OPTIONAL         , INTENT(in   ) ::   ldzint       ! true if 3D variable requires a vertical interpolation
+      !!
+      INTEGER                                   ::   ipi          ! length of boundary data on local process
+      INTEGER                                   ::   ipj          ! length of dummy dimension ( = 1 )
+      INTEGER                                   ::   ipk          ! number of vertical levels of pdta ( 2D: ipk=1 ; 3D: ipk=jpk )
+      INTEGER                                   ::   ipkb         ! number of vertical levels in boundary data file
+      INTEGER                                   ::   idvar        ! variable ID
+      INTEGER                                   ::   indims       ! number of dimensions of the variable
+      INTEGER, DIMENSION(4)                     ::   idimsz       ! size of variable dimensions 
+      REAL(wp)                                  ::   zfv          ! fillvalue 
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   zz_read      ! work space for global boundary data
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   zdta_read    ! work space local data requiring vertical interpolation
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   zdta_read_z  ! work space local data requiring vertical interpolation
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   zdta_read_dz ! work space local data requiring vertical interpolation
+      CHARACTER(LEN=1),DIMENSION(3)             ::   clgrid
+      LOGICAL                                   ::   lluld        ! is the variable using the unlimited dimension
+      LOGICAL                                   ::   llzint       ! local value of ldzint
+      !!---------------------------------------------------------------------
+      !
+      clgrid = (/'t','u','v'/)
+      !
+      ipi = SIZE( pdta, 1 )
+      ipj = SIZE( pdta, 2 )   ! must be equal to 1
+      ipk = SIZE( pdta, 3 )
+      !
+      llzint = .FALSE.
+      IF( PRESENT(ldzint) )   llzint = ldzint
+      !
+      idvar = iom_varid( knum, cdvar, kndims = indims, kdimsz = idimsz, lduld = lluld  )
+      IF( indims == 4 .OR. ( indims == 3 .AND. .NOT. lluld ) ) THEN   ;   ipkb = idimsz(3)   ! xy(zl)t or xy(zl)
+      ELSE                                                            ;   ipkb = 1           ! xy or xyt
+      ENDIF
+      !
+      ALLOCATE( zz_read( idimsz(1), idimsz(2), ipkb ) )  ! ++++++++ !!! this can be very big...         
+      !
+      IF( ipk == 1 ) THEN
+
+         IF( ipkb /= 1 ) CALL ctl_stop( 'fld_map : we must have ipkb = 1 to read surface data' )
+         CALL iom_get ( knum, jpdom_unknown, cdvar, zz_read(:,:,1), krec )   ! call iom_get with a 2D file
+         CALL fld_map_core( zz_read, kmap, pdta )
 
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       ! Do we include something here to adjust barotropic velocities !
       ! in case of a depth difference between bdy files and          !
-      ! bathymetry in the case ln_full_vel = .false. and jpk_bdy>0?  !
+      ! bathymetry in the case ln_totvel = .false. and ipkb>0?       !
       ! [as the enveloping and parital cells could change H]         !
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-      CASE DEFAULT   ;
-
-      IF( PRESENT(jpk_bdy) .AND. jpk_bdy>0 ) THEN       ! boundary data not on model grid: vertical interpolation
-         CALL iom_getatt(num, '_FillValue', fv, cdvar=clvar )
-         dta_read(:,:,:) = -ABS(fv)
-         dta_read_z(:,:,:) = 0._wp
-         dta_read_dz(:,:,:) = 0._wp
-         CALL iom_get ( num, jpdom_unknown, clvar, dta_read(1:ilendta,1:ipj,1:jpk_bdy), nrec )
-         SELECT CASE( igrd )                  
-            CASE(1)
-               CALL iom_get ( num, jpdom_unknown, 'gdept', dta_read_z(1:ilendta,1:ipj,1:jpk_bdy) )
-               CALL iom_get ( num, jpdom_unknown, 'e3t',  dta_read_dz(1:ilendta,1:ipj,1:jpk_bdy) )
-            CASE(2)  
-               CALL iom_get ( num, jpdom_unknown, 'gdepu', dta_read_z(1:ilendta,1:ipj,1:jpk_bdy) )
-               CALL iom_get ( num, jpdom_unknown, 'e3u',  dta_read_dz(1:ilendta,1:ipj,1:jpk_bdy) )
-            CASE(3)
-               CALL iom_get ( num, jpdom_unknown, 'gdepv', dta_read_z(1:ilendta,1:ipj,1:jpk_bdy) )
-               CALL iom_get ( num, jpdom_unknown, 'e3v',  dta_read_dz(1:ilendta,1:ipj,1:jpk_bdy) )
-         END SELECT
-
-      IF ( ln_bdy ) & 
-         CALL fld_bdy_interp(dta_read, dta_read_z, dta_read_dz, map, jpk_bdy, igrd, ibdy, fv, dta, fvl, ilendta)
-
-      ELSE ! boundary data assumed to be on model grid
-         
-         CALL iom_get ( num, jpdom_unknown, clvar, dta_read(1:ilendta,1:ipj,1:ipk), nrec )                    
-         IF ( map%ll_unstruc) THEN ! unstructured open boundary data file
-            DO ib = 1, ipi
-              DO ik = 1, ipk
-                dta(ib,1,ik) =  dta_read(map%ptr(ib),1,ik)
-              END DO
+      ELSE
+         !
+         CALL iom_get ( knum, jpdom_unknown, cdvar, zz_read(:,:,:), krec )   ! call iom_get with a 3D file
+         !
+         IF( ipkb /= ipk .OR. llzint ) THEN   ! boundary data not on model vertical grid : vertical interpolation
+            !
+            IF( ipk == jpk .AND. iom_varid(knum,'gdep'//clgrid(kgrd)) /= -1 .AND. iom_varid(knum,'e3'//clgrid(kgrd)) /= -1 ) THEN
+               
+               ALLOCATE( zdta_read(ipi,ipj,ipkb), zdta_read_z(ipi,ipj,ipkb), zdta_read_dz(ipi,ipj,ipkb) )
+                
+               CALL fld_map_core( zz_read, kmap, zdta_read )
+               CALL iom_get ( knum, jpdom_unknown, 'gdep'//clgrid(kgrd), zz_read )   ! read only once? Potential temporal evolution?
+               CALL fld_map_core( zz_read, kmap, zdta_read_z )
+               CALL iom_get ( knum, jpdom_unknown,   'e3'//clgrid(kgrd), zz_read )   ! read only once? Potential temporal evolution?
+               CALL fld_map_core( zz_read, kmap, zdta_read_dz )
+               
+               CALL iom_getatt(knum, '_FillValue', zfv, cdvar=cdvar )
+               CALL fld_bdy_interp(zdta_read, zdta_read_z, zdta_read_dz, pdta, kgrd, kbdy, zfv, ldtotvel)
+               DEALLOCATE( zdta_read, zdta_read_z, zdta_read_dz )
+               
+            ELSE
+               IF( ipk /= jpk ) CALL ctl_stop( 'fld_map : this should be an impossible case...' )
+               WRITE(ctmp1,*) 'fld_map : vertical interpolation for bdy variable '//TRIM(cdvar)//' requires ' 
+               IF( iom_varid(knum, 'gdep'//clgrid(kgrd)) == -1 ) CALL ctl_stop( ctmp1//'gdep'//clgrid(kgrd)//' variable' )
+               IF( iom_varid(knum,   'e3'//clgrid(kgrd)) == -1 ) CALL ctl_stop( ctmp1//  'e3'//clgrid(kgrd)//' variable' )
+
+            ENDIF
+            !
+         ELSE                            ! bdy data assumed to be the same levels as bdy variables
+            !
+            CALL fld_map_core( zz_read, kmap, pdta )
+            !
+         ENDIF   ! ipkb /= ipk
+      ENDIF   ! ipk == 1
+      
+      DEALLOCATE( zz_read )
+
+   END SUBROUTINE fld_map
+
+     
+   SUBROUTINE fld_map_core( pdta_read, kmap, pdta_bdy )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE fld_map_core  ***
+      !!
+      !! ** Purpose :  inner core of fld_map
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdta_read    ! global boundary data
+      INTEGER,  DIMENSION(:    ), INTENT(in   ) ::   kmap         ! global-to-local bdy mapping indices
+      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pdta_bdy     ! bdy output field on model grid
+      !!
+      INTEGER,  DIMENSION(3) ::   idim_read,  idim_bdy            ! arrays dimensions
+      INTEGER                ::   ji, jj, jk, jb                  ! loop counters
+      INTEGER                ::   im1
+      !!---------------------------------------------------------------------
+      !
+      idim_read = SHAPE( pdta_read )
+      idim_bdy  = SHAPE( pdta_bdy  )
+      !
+      ! in all cases: idim_bdy(2) == 1 .AND. idim_read(1) * idim_read(2) == idim_bdy(1)
+      ! structured BDY with rimwidth > 1                     : idim_read(2) == rimwidth /= 1
+      ! structured BDY with rimwidth == 1 or unstructured BDY: idim_read(2) == 1
+      !
+      IF( idim_read(2) > 1 ) THEN    ! structured BDY with rimwidth > 1  
+         DO jk = 1, idim_bdy(3)
+            DO jb = 1, idim_bdy(1)
+               im1 = kmap(jb) - 1
+               jj = im1 / idim_read(1) + 1
+               ji = MOD( im1, idim_read(1) ) + 1
+               pdta_bdy(jb,1,jk) =  pdta_read(ji,jj,jk)
             END DO
-         ELSE ! we assume that this is a structured open boundary file
-            DO ib = 1, ipi
-               jj=1+floor(REAL(map%ptr(ib)-1)/REAL(ilendta))
-               ji=map%ptr(ib)-(jj-1)*ilendta
-               DO ik = 1, ipk
-                  dta(ib,1,ik) =  dta_read(ji,jj,ik)
-               END DO
+         END DO
+      ELSE
+         DO jk = 1, idim_bdy(3)
+            DO jb = 1, idim_bdy(1)   ! horizontal remap of bdy data on the local bdy 
+               pdta_bdy(jb,1,jk) = pdta_read(kmap(jb),1,jk)
             END DO
-         ENDIF
-      ENDIF ! PRESENT(jpk_bdy)
-      END SELECT
-
-   END SUBROUTINE fld_map
+         END DO
+      ENDIF
+      
+   END SUBROUTINE fld_map_core
    
-   SUBROUTINE fld_bdy_interp(dta_read, dta_read_z, dta_read_dz, map, jpk_bdy, igrd, ibdy, fv, dta, fvl, ilendta)
-
+   
+   SUBROUTINE fld_bdy_interp(pdta_read, pdta_read_z, pdta_read_dz, pdta, kgrd, kbdy, pfv, ldtotvel)
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE fld_bdy_interp  ***
@@ -847,284 +832,159 @@
       USE bdy_oce, ONLY:  idx_bdy         ! indexing for map <-> ij transformation
 
-      REAL(wp), POINTER, DIMENSION(:,:,:), INTENT(in )     ::   dta_read      ! work space for global data
-      REAL(wp), POINTER, DIMENSION(:,:,:), INTENT(in )     ::   dta_read_z    ! work space for global data
-      REAL(wp), POINTER, DIMENSION(:,:,:), INTENT(in )     ::   dta_read_dz   ! work space for global data
-      REAL(wp) , INTENT(in)                                ::   fv            ! fillvalue and alternative -ABS(fv)
-      REAL(wp), DIMENSION(:,:,:), INTENT(out) ::   dta                        ! output field on model grid (2 dimensional)
-      TYPE(MAP_POINTER)         , INTENT(in ) ::   map                        ! global-to-local mapping indices
-      LOGICAL  , INTENT(in), OPTIONAL         ::   fvl                        ! grid type, set number and number of vertical levels in the bdy data
-      INTEGER  , INTENT(in)                   ::   igrd, ibdy, jpk_bdy        ! number of levels in bdy data
-      INTEGER  , INTENT(in)                   ::   ilendta                    ! length of data in file
-      !!
-      INTEGER                                 ::   ipi                        ! length of boundary data on local process
-      INTEGER                                 ::   ipj                        ! length of dummy dimension ( = 1 )
-      INTEGER                                 ::   ipk                        ! number of vertical levels of dta ( 2D: ipk=1 ; 3D: ipk=jpk )
-      INTEGER                                 ::   jpkm1_bdy                  ! number of levels in bdy data minus 1
-      INTEGER                                 ::   ib, ik, ikk                ! loop counters
-      INTEGER                                 ::   ji, jj, zij, zjj           ! temporary indices
-      REAL(wp)                                ::   zl, zi, zh                 ! tmp variable for current depth and interpolation factor
-      REAL(wp)                                ::   fv_alt, ztrans, ztrans_new ! fillvalue and alternative -ABS(fv)
-      CHARACTER (LEN=10)                      ::   ibstr
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdta_read       ! data read in bdy file
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdta_read_z     ! depth of the data read in bdy file
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdta_read_dz    ! thickness of the levels in bdy file
+      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pdta            ! output field on model grid (2 dimensional)
+      REAL(wp)                  , INTENT(in   ) ::   pfv             ! fillvalue of the data read in bdy file
+      LOGICAL                   , INTENT(in   ) ::   ldtotvel        ! true if toal ( = barotrop + barocline) velocity
+      INTEGER                   , INTENT(in   ) ::   kgrd            ! grid type (t, u, v)
+      INTEGER                   , INTENT(in   ) ::   kbdy            ! bdy number
+      !!
+      INTEGER                                   ::   ipi             ! length of boundary data on local process
+      INTEGER                                   ::   ipkb            ! number of vertical levels in boundary data file
+      INTEGER                                   ::   jb, ji, jj, jk, jkb   ! loop counters
+      REAL(wp)                                  ::   zcoef
+      REAL(wp)                                  ::   zl, zi, zh      ! tmp variable for current depth and interpolation factor
+      REAL(wp)                                  ::   zfv_alt, ztrans, ztrans_new ! fillvalue and alternative -ABS(pfv)
+      REAL(wp), DIMENSION(jpk)                  ::   zdepth, zdhalf  ! level and half-level depth
       !!---------------------------------------------------------------------
      
-
-      ipi       = SIZE( dta, 1 )
-      ipj       = SIZE( dta_read, 2 )
-      ipk       = SIZE( dta, 3 )
-      jpkm1_bdy = jpk_bdy-1
+      ipi  = SIZE( pdta, 1 )
+      ipkb = SIZE( pdta_read, 3 )
       
-      fv_alt = -ABS(fv)  ! set _FillValue < 0 as we make use of MAXVAL and MAXLOC later
-      DO ib = 1, ipi
-            zij = idx_bdy(ibdy)%nbi(ib,igrd)
-            zjj = idx_bdy(ibdy)%nbj(ib,igrd)
-         IF(narea==2) WRITE(*,*) 'MAPI', ib, igrd, map%ptr(ib), narea-1, zij, zjj
-      ENDDO
-      !
-      IF ( map%ll_unstruc ) THEN                            ! unstructured open boundary data file
-
-         DO ib = 1, ipi
-            DO ik = 1, jpk_bdy
-               IF( ( dta_read(map%ptr(ib),1,ik) == fv ) ) THEN
-                  dta_read_z(map%ptr(ib),1,ik)  = fv_alt ! safety: put fillvalue into external depth field so consistent with data
-                  dta_read_dz(map%ptr(ib),1,ik) = 0._wp  ! safety: put 0._wp into external thickness factors to ensure transport is correct
+      zfv_alt = -ABS(pfv)  ! set _FillValue < 0 as we make use of MAXVAL and MAXLOC later
+      !
+      WHERE( pdta_read == pfv )
+         pdta_read_z  = zfv_alt ! safety: put fillvalue into external depth field so consistent with data
+         pdta_read_dz = 0._wp   ! safety: put 0._wp into external thickness factors to ensure transport is correct
+      ENDWHERE
+      
+      DO jb = 1, ipi
+         ji = idx_bdy(kbdy)%nbi(jb,kgrd)
+         jj = idx_bdy(kbdy)%nbj(jb,kgrd)
+         zh  = SUM(pdta_read_dz(jb,1,:) )
+         !
+         ! Warnings to flag differences in the input and model topgraphy - is this useful/necessary?
+         SELECT CASE( kgrd )                         
+         CASE(1)
+            IF( ABS( (zh - ht_n(ji,jj)) / ht_n(ji,jj)) * tmask(ji,jj,1) > 0.01_wp ) THEN
+               WRITE(ctmp1,"(I10.10)") jb 
+               CALL ctl_warn('fld_bdy_interp: T depths differ between grids at BDY point '//TRIM(ctmp1)//' by more than 1%')
+               !   IF(lwp) WRITE(numout,*) 'DEPTHT', zh, sum(e3t_n(ji,jj,:), mask=tmask(ji,jj,:)==1),  ht_n(ji,jj), jb, jb, ji, jj
+            ENDIF
+         CASE(2)
+            IF( ABS( (zh - hu_n(ji,jj)) * r1_hu_n(ji,jj)) * umask(ji,jj,1) > 0.01_wp ) THEN
+               WRITE(ctmp1,"(I10.10)") jb 
+               CALL ctl_warn('fld_bdy_interp: U depths differ between grids at BDY point '//TRIM(ctmp1)//' by more than 1%')
+               !   IF(lwp) WRITE(numout,*) 'DEPTHU', zh, SUM(e3u_n(ji,jj,:), mask=umask(ji,jj,:)==1),  SUM(umask(ji,jj,:)), &
+               !      &                hu_n(ji,jj), jb, jb, ji, jj, narea-1, pdta_read(jb,1,:)
+            ENDIF
+         CASE(3)
+            IF( ABS( (zh - hv_n(ji,jj)) * r1_hv_n(ji,jj)) * vmask(ji,jj,1) > 0.01_wp ) THEN
+               WRITE(ctmp1,"(I10.10)") jb
+               CALL ctl_warn('fld_bdy_interp: V depths differ between grids at BDY point '//TRIM(ctmp1)//' by more than 1%')
+            ENDIF
+         END SELECT
+         !
+         SELECT CASE( kgrd )                         
+         CASE(1)
+            ! depth of T points:
+            zdepth(:) = gdept_n(ji,jj,:)
+         CASE(2)
+            ! depth of U points: we must not use gdept_n as we don't want to do a communication
+            !   --> copy what is done for gdept_n in domvvl...
+            zdhalf(1) = 0.0_wp
+            zdepth(1) = 0.5_wp * e3uw_n(ji,jj,1)
+            DO jk = 2, jpk                               ! vertical sum
+               !    zcoef = umask - wumask    ! 0 everywhere tmask = wmask, ie everywhere expect at jk = mikt
+               !                              ! 1 everywhere from mbkt to mikt + 1 or 1 (if no isf)
+               !                              ! 0.5 where jk = mikt     
+               !!gm ???????   BUG ?  gdept_n as well as gde3w_n  does not include the thickness of ISF ??
+               zcoef = ( umask(ji,jj,jk) - wumask(ji,jj,jk) )
+               zdhalf(jk) = zdhalf(jk-1) + e3u_n(ji,jj,jk-1)
+               zdepth(jk) =      zcoef  * ( zdhalf(jk  ) + 0.5 * e3uw_n(ji,jj,jk))  &
+                  &         + (1-zcoef) * ( zdepth(jk-1) +       e3uw_n(ji,jj,jk))
+            END DO
+         CASE(3)
+            ! depth of V points: we must not use gdept_n as we don't want to do a communication
+            !   --> copy what is done for gdept_n in domvvl...
+            zdhalf(1) = 0.0_wp
+            zdepth(1) = 0.5_wp * e3vw_n(ji,jj,1)
+            DO jk = 2, jpk                               ! vertical sum
+               !    zcoef = vmask - wvmask    ! 0 everywhere tmask = wmask, ie everywhere expect at jk = mikt
+               !                              ! 1 everywhere from mbkt to mikt + 1 or 1 (if no isf)
+               !                              ! 0.5 where jk = mikt     
+               !!gm ???????   BUG ?  gdept_n as well as gde3w_n  does not include the thickness of ISF ??
+               zcoef = ( vmask(ji,jj,jk) - wvmask(ji,jj,jk) )
+               zdhalf(jk) = zdhalf(jk-1) + e3v_n(ji,jj,jk-1)
+               zdepth(jk) =      zcoef  * ( zdhalf(jk  ) + 0.5 * e3vw_n(ji,jj,jk))  &
+                  &         + (1-zcoef) * ( zdepth(jk-1) +       e3vw_n(ji,jj,jk))
+            END DO
+         END SELECT
+         !
+         DO jk = 1, jpk                      
+            IF(     zdepth(jk) < pdta_read_z(jb,1,          1) ) THEN                ! above the first level of external data
+               pdta(jb,1,jk) =  pdta_read(jb,1,1)
+            ELSEIF( zdepth(jk) > pdta_read_z(jb,1,ipkb) ) THEN                       ! below the last level of external data 
+               pdta(jb,1,jk) =  pdta_read(jb,1,MAXLOC(pdta_read_z(jb,1,:),1))
+            ELSE                                                             ! inbetween: vertical interpolation between jkb & jkb+1
+               DO jkb = 1, ipkb-1                                            ! when  gdept_n(jkb) < zdepth(jk) < gdept_n(jkb+1)
+                  IF( ( ( zdepth(jk) - pdta_read_z(jb,1,jkb) ) * ( zdepth(jk) - pdta_read_z(jb,1,jkb+1) ) <= 0._wp ) &
+                     &    .AND. ( pdta_read_z(jb,1,jkb+1) /= zfv_alt) ) THEN   ! linear interpolation between 2 levels
+                     zi = ( zdepth(jk) - pdta_read_z(jb,1,jkb) ) / ( pdta_read_z(jb,1,jkb+1) - pdta_read_z(jb,1,jkb) )
+                     pdta(jb,1,jk) = pdta_read(jb,1,jkb) + ( pdta_read  (jb,1,jkb+1) - pdta_read  (jb,1,jkb) ) * zi
+                  ENDIF
+               END DO
+            ENDIF
+         END DO   ! jpk
+         !
+      END DO   ! ipi
+      
+      IF(kgrd == 2) THEN                                  ! do we need to adjust the transport term?
+         DO jb = 1, ipi
+            ji = idx_bdy(kbdy)%nbi(jb,kgrd)
+            jj = idx_bdy(kbdy)%nbj(jb,kgrd)
+            zh  = SUM(pdta_read_dz(jb,1,:) )
+            ztrans = 0._wp
+            ztrans_new = 0._wp
+            DO jkb = 1, ipkb                              ! calculate transport on input grid
+               ztrans     = ztrans     + pdta_read(jb,1,jkb) * pdta_read_dz(jb, 1,jkb)
+            ENDDO
+            DO jk = 1, jpk                                ! calculate transport on model grid
+               ztrans_new = ztrans_new +      pdta(jb,1,jk ) *        e3u_n(ji,jj,jk ) * umask(ji,jj,jk)
+            ENDDO
+            DO jk = 1, jpk                                ! make transport correction
+               IF(ldtotvel) THEN ! bdy data are total velocity so adjust bt transport term to match input data
+                  pdta(jb,1,jk) = ( pdta(jb,1,jk) + ( ztrans - ztrans_new ) * r1_hu_n(ji,jj) ) * umask(ji,jj,jk)
+               ELSE ! we're just dealing with bc velocity so bt transport term should sum to zero
+                  pdta(jb,1,jk) =   pdta(jb,1,jk) + (  0._wp - ztrans_new ) * r1_hu_n(ji,jj)   * umask(ji,jj,jk)
                ENDIF
             ENDDO
-         ENDDO 
-
-         DO ib = 1, ipi
-            zij = idx_bdy(ibdy)%nbi(ib,igrd)
-            zjj = idx_bdy(ibdy)%nbj(ib,igrd)
-            zh  = SUM(dta_read_dz(map%ptr(ib),1,:) )
-            ! Warnings to flag differences in the input and model topgraphy - is this useful/necessary?
-            SELECT CASE( igrd )                         
-               CASE(1)
-                  IF( ABS( (zh - ht_n(zij,zjj)) / ht_n(zij,zjj)) * tmask(zij,zjj,1) > 0.01_wp ) THEN
-                     WRITE(ibstr,"(I10.10)") map%ptr(ib) 
-                     CALL ctl_warn('fld_bdy_interp: T depths differ between grids at BDY point '//TRIM(ibstr)//' by more than 1%')
-                 !   IF(lwp) WRITE(*,*) 'DEPTHT', zh, sum(e3t_n(zij,zjj,:), mask=tmask(zij,zjj,:)==1),  ht_n(zij,zjj), map%ptr(ib), ib, zij, zjj
-                  ENDIF
-               CASE(2)
-                  IF( ABS( (zh - hu_n(zij,zjj)) * r1_hu_n(zij,zjj)) * umask(zij,zjj,1) > 0.01_wp ) THEN
-                     WRITE(ibstr,"(I10.10)") map%ptr(ib) 
-                     CALL ctl_warn('fld_bdy_interp: U depths differ between grids at BDY point '//TRIM(ibstr)//' by more than 1%')
-                     IF(lwp) WRITE(*,*) 'DEPTHU', zh, sum(e3u_n(zij,zjj,:), mask=umask(zij,zjj,:)==1),  sum(umask(zij,zjj,:)), &
-                       &                hu_n(zij,zjj), map%ptr(ib), ib, zij, zjj, narea-1  , &
-                        &                dta_read(map%ptr(ib),1,:)
-                  ENDIF
-               CASE(3)
-                  IF( ABS( (zh - hv_n(zij,zjj)) * r1_hv_n(zij,zjj)) * vmask(zij,zjj,1) > 0.01_wp ) THEN
-                     WRITE(ibstr,"(I10.10)") map%ptr(ib) 
-                     CALL ctl_warn('fld_bdy_interp: V depths differ between grids at BDY point '//TRIM(ibstr)//' by more than 1%')
-                  ENDIF
-            END SELECT
-            DO ik = 1, ipk                      
-               SELECT CASE( igrd )                       
-                  CASE(1)
-                     zl =  gdept_n(zij,zjj,ik)                                          ! if using in step could use fsdept instead of gdept_n?
-                  CASE(2)
-                     IF(ln_sco) THEN
-                        zl =  ( gdept_n(zij,zjj,ik) + gdept_n(zij+1,zjj,ik) ) * 0.5_wp  ! if using in step could use fsdept instead of gdept_n?
-                     ELSE
-                        zl =  MIN( gdept_n(zij,zjj,ik), gdept_n(zij+1,zjj,ik) ) 
-                     ENDIF
-                  CASE(3)
-                     IF(ln_sco) THEN
-                        zl =  ( gdept_n(zij,zjj,ik) + gdept_n(zij,zjj+1,ik) ) * 0.5_wp  ! if using in step could use fsdept instead of gdept_n?
-                     ELSE
-                        zl =  MIN( gdept_n(zij,zjj,ik), gdept_n(zij,zjj+1,ik) )
-                     ENDIF
-               END SELECT
-               IF( zl < dta_read_z(map%ptr(ib),1,1) ) THEN                                         ! above the first level of external data
-                  dta(ib,1,ik) =  dta_read(map%ptr(ib),1,1)
-               ELSEIF( zl > MAXVAL(dta_read_z(map%ptr(ib),1,:),1) ) THEN                           ! below the last level of external data 
-                  dta(ib,1,ik) =  dta_read(map%ptr(ib),1,MAXLOC(dta_read_z(map%ptr(ib),1,:),1))
-               ELSE                                                                                ! inbetween : vertical interpolation between ikk & ikk+1
-                  DO ikk = 1, jpkm1_bdy                                                            ! when  gdept_n(ikk) < zl < gdept_n(ikk+1)
-                     IF( ( (zl-dta_read_z(map%ptr(ib),1,ikk)) * (zl-dta_read_z(map%ptr(ib),1,ikk+1)) <= 0._wp) &
-                    &    .AND. (dta_read_z(map%ptr(ib),1,ikk+1) /= fv_alt)) THEN
-                        zi           = ( zl - dta_read_z(map%ptr(ib),1,ikk) ) / &
-                       &               ( dta_read_z(map%ptr(ib),1,ikk+1) - dta_read_z(map%ptr(ib),1,ikk) )
-                        dta(ib,1,ik) = dta_read(map%ptr(ib),1,ikk) + &
-                       &               ( dta_read(map%ptr(ib),1,ikk+1) - dta_read(map%ptr(ib),1,ikk) ) * zi
-                     ENDIF
-                  END DO
-               ENDIF
-            END DO
-         END DO
-
-         IF(igrd == 2) THEN                                 ! do we need to adjust the transport term?
-            DO ib = 1, ipi
-              zij = idx_bdy(ibdy)%nbi(ib,igrd)
-              zjj = idx_bdy(ibdy)%nbj(ib,igrd)
-              zh  = SUM(dta_read_dz(map%ptr(ib),1,:) )
-              ztrans = 0._wp
-              ztrans_new = 0._wp
-              DO ik = 1, jpk_bdy                            ! calculate transport on input grid
-                  ztrans     = ztrans     + dta_read(map%ptr(ib),1,ik) * dta_read_dz(map%ptr(ib),1,ik)
-              ENDDO
-              DO ik = 1, ipk                                ! calculate transport on model grid
-                  ztrans_new = ztrans_new + dta(ib,1,ik) * e3u_n(zij,zjj,ik) * umask(zij,zjj,ik)
-              ENDDO
-              DO ik = 1, ipk                                ! make transport correction
-                 IF(fvl) THEN ! bdy data are total velocity so adjust bt transport term to match input data
-                    dta(ib,1,ik) = ( dta(ib,1,ik) + ( ztrans - ztrans_new ) * r1_hu_n(zij,zjj) ) * umask(zij,zjj,ik)
-                 ELSE ! we're just dealing with bc velocity so bt transport term should sum to zero
-                    IF( ABS(ztrans * r1_hu_n(zij,zjj)) > 0.01_wp ) &
-                   &   CALL ctl_warn('fld_bdy_interp: barotropic component of > 0.01 ms-1 found in baroclinic velocities at')
-                    dta(ib,1,ik) = dta(ib,1,ik) + ( 0._wp - ztrans_new ) * r1_hu_n(zij,zjj) * umask(zij,zjj,ik)
-                 ENDIF
-              ENDDO
+         ENDDO
+      ENDIF
+      
+      IF(kgrd == 3) THEN                                  ! do we need to adjust the transport term?
+         DO jb = 1, ipi
+            ji = idx_bdy(kbdy)%nbi(jb,kgrd)
+            jj = idx_bdy(kbdy)%nbj(jb,kgrd)
+            zh  = SUM(pdta_read_dz(jb,1,:) )
+            ztrans = 0._wp
+            ztrans_new = 0._wp
+            DO jkb = 1, ipkb                              ! calculate transport on input grid
+               ztrans     = ztrans     + pdta_read(jb,1,jkb) * pdta_read_dz(jb, 1,jkb)
             ENDDO
-         ENDIF
-
-         IF(igrd == 3) THEN                                 ! do we need to adjust the transport term?
-            DO ib = 1, ipi
-              zij = idx_bdy(ibdy)%nbi(ib,igrd)
-              zjj = idx_bdy(ibdy)%nbj(ib,igrd)
-              zh  = SUM(dta_read_dz(map%ptr(ib),1,:) )
-              ztrans = 0._wp
-              ztrans_new = 0._wp
-              DO ik = 1, jpk_bdy                            ! calculate transport on input grid
-                  ztrans     = ztrans     + dta_read(map%ptr(ib),1,ik) * dta_read_dz(map%ptr(ib),1,ik)
-              ENDDO
-              DO ik = 1, ipk                                ! calculate transport on model grid
-                  ztrans_new = ztrans_new + dta(ib,1,ik) * e3v_n(zij,zjj,ik) * vmask(zij,zjj,ik)
-              ENDDO
-              DO ik = 1, ipk                                ! make transport correction
-                 IF(fvl) THEN ! bdy data are total velocity so adjust bt transport term to match input data
-                    dta(ib,1,ik) = ( dta(ib,1,ik) + ( ztrans - ztrans_new ) * r1_hv_n(zij,zjj) ) * vmask(zij,zjj,ik)
-                 ELSE ! we're just dealing with bc velocity so bt transport term should sum to zero
-                    dta(ib,1,ik) = dta(ib,1,ik) + ( 0._wp - ztrans_new ) * r1_hv_n(zij,zjj) * vmask(zij,zjj,ik)
-                 ENDIF
-              ENDDO
+            DO jk = 1, jpk                                ! calculate transport on model grid
+               ztrans_new = ztrans_new +      pdta(jb,1,jk ) *        e3v_n(ji,jj,jk ) * vmask(ji,jj,jk)
             ENDDO
-         ENDIF
-  
-      ELSE ! structured open boundary file
-
-         DO ib = 1, ipi
-            jj=1+floor(REAL(map%ptr(ib)-1)/REAL(ilendta))
-            ji=map%ptr(ib)-(jj-1)*ilendta
-            DO ik = 1, jpk_bdy                      
-               IF( ( dta_read(ji,jj,ik) == fv ) ) THEN
-                  dta_read_z(ji,jj,ik)  = fv_alt ! safety: put fillvalue into external depth field so consistent with data
-                  dta_read_dz(ji,jj,ik) = 0._wp  ! safety: put 0._wp into external thickness factors to ensure transport is correct
+            DO jk = 1, jpk                                ! make transport correction
+               IF(ldtotvel) THEN ! bdy data are total velocity so adjust bt transport term to match input data
+                  pdta(jb,1,jk) = ( pdta(jb,1,jk) + ( ztrans - ztrans_new ) * r1_hv_n(ji,jj) ) * vmask(ji,jj,jk)
+               ELSE ! we're just dealing with bc velocity so bt transport term should sum to zero
+                  pdta(jb,1,jk) =   pdta(jb,1,jk) + (  0._wp - ztrans_new ) * r1_hv_n(ji,jj)   * vmask(ji,jj,jk)
                ENDIF
             ENDDO
-         ENDDO 
-       
-
-         DO ib = 1, ipi
-            jj=1+floor(REAL(map%ptr(ib)-1)/REAL(ilendta))
-            ji=map%ptr(ib)-(jj-1)*ilendta
-            zij = idx_bdy(ibdy)%nbi(ib,igrd)
-            zjj = idx_bdy(ibdy)%nbj(ib,igrd)
-            zh  = SUM(dta_read_dz(ji,jj,:) )
-            ! Warnings to flag differences in the input and model topgraphy - is this useful/necessary?
-            SELECT CASE( igrd )                         
-               CASE(1)
-                  IF( ABS( (zh - ht_n(zij,zjj)) / ht_n(zij,zjj)) * tmask(zij,zjj,1) > 0.01_wp ) THEN
-                     WRITE(ibstr,"(I10.10)") map%ptr(ib) 
-                     CALL ctl_warn('fld_bdy_interp: T depths differ between grids at BDY point '//TRIM(ibstr)//' by more than 1%')
-                 !   IF(lwp) WRITE(*,*) 'DEPTHT', zh, sum(e3t_n(zij,zjj,:), mask=tmask(zij,zjj,:)==1),  ht_n(zij,zjj), map%ptr(ib), ib, zij, zjj
-                  ENDIF
-               CASE(2)
-                  IF( ABS( (zh - hu_n(zij,zjj)) * r1_hu_n(zij,zjj)) * umask(zij,zjj,1) > 0.01_wp ) THEN
-                     WRITE(ibstr,"(I10.10)") map%ptr(ib) 
-                     CALL ctl_warn('fld_bdy_interp: U depths differ between grids at BDY point '//TRIM(ibstr)//' by more than 1%')
-                  ENDIF
-               CASE(3)
-                  IF( ABS( (zh - hv_n(zij,zjj)) * r1_hv_n(zij,zjj)) * vmask(zij,zjj,1) > 0.01_wp ) THEN
-                     WRITE(ibstr,"(I10.10)") map%ptr(ib) 
-                     CALL ctl_warn('fld_bdy_interp: V depths differ between grids at BDY point '//TRIM(ibstr)//' by more than 1%')
-                  ENDIF
-            END SELECT
-            DO ik = 1, ipk                      
-               SELECT CASE( igrd )                          ! coded for sco - need zco and zps option using min
-                  CASE(1)
-                     zl =  gdept_n(zij,zjj,ik)              ! if using in step could use fsdept instead of gdept_n?
-                  CASE(2)
-                     IF(ln_sco) THEN
-                        zl =  ( gdept_n(zij,zjj,ik) + gdept_n(zij+1,zjj,ik) ) * 0.5_wp  ! if using in step could use fsdept instead of gdept_n?
-                     ELSE
-                        zl =  MIN( gdept_n(zij,zjj,ik), gdept_n(zij+1,zjj,ik) )
-                     ENDIF
-                  CASE(3)
-                     IF(ln_sco) THEN
-                        zl =  ( gdept_n(zij,zjj,ik) + gdept_n(zij,zjj+1,ik) ) * 0.5_wp  ! if using in step could use fsdept instead of gdept_n?
-                     ELSE
-                        zl =  MIN( gdept_n(zij,zjj,ik), gdept_n(zij,zjj+1,ik) )
-                     ENDIF
-               END SELECT
-               IF( zl < dta_read_z(ji,jj,1) ) THEN                                      ! above the first level of external data
-                  dta(ib,1,ik) =  dta_read(ji,jj,1)
-               ELSEIF( zl > MAXVAL(dta_read_z(ji,jj,:),1) ) THEN                        ! below the last level of external data 
-                  dta(ib,1,ik) =  dta_read(ji,jj,MAXLOC(dta_read_z(ji,jj,:),1))
-               ELSE                                                                     ! inbetween : vertical interpolation between ikk & ikk+1
-                  DO ikk = 1, jpkm1_bdy                                                 ! when  gdept_n(ikk) < zl < gdept_n(ikk+1)
-                     IF( ( (zl-dta_read_z(ji,jj,ikk)) * (zl-dta_read_z(ji,jj,ikk+1)) <= 0._wp) &
-                    &    .AND. (dta_read_z(ji,jj,ikk+1) /= fv_alt)) THEN
-                        zi           = ( zl - dta_read_z(ji,jj,ikk) ) / &
-                       &               ( dta_read_z(ji,jj,ikk+1) - dta_read_z(ji,jj,ikk) )
-                        dta(ib,1,ik) = dta_read(ji,jj,ikk) + &
-                       &               ( dta_read(ji,jj,ikk+1) - dta_read(ji,jj,ikk) ) * zi
-                     ENDIF
-                  END DO
-               ENDIF
-            END DO
-         END DO
-
-         IF(igrd == 2) THEN                                 ! do we need to adjust the transport term?
-            DO ib = 1, ipi
-               jj=1+floor(REAL(map%ptr(ib)-1)/REAL(ilendta))
-               ji=map%ptr(ib)-(jj-1)*ilendta
-               zij = idx_bdy(ibdy)%nbi(ib,igrd)
-               zjj = idx_bdy(ibdy)%nbj(ib,igrd)
-               zh = SUM(dta_read_dz(ji,jj,:) )
-               ztrans = 0._wp
-               ztrans_new = 0._wp
-               DO ik = 1, jpk_bdy                            ! calculate transport on input grid
-                  ztrans = ztrans + dta_read(ji,jj,ik) * dta_read_dz(ji,jj,ik)
-               ENDDO
-               DO ik = 1, ipk                                ! calculate transport on model grid
-                  ztrans_new = ztrans_new + dta(ib,1,ik) * e3u_n(zij,zjj,ik) * umask(zij,zjj,ik)
-               ENDDO
-               DO ik = 1, ipk                                ! make transport correction
-                  IF(fvl) THEN ! bdy data are total velocity so adjust bt transport term to match input data
-                     dta(ib,1,ik) = ( dta(ib,1,ik) + ( ztrans - ztrans_new ) * r1_hu_n(zij,zjj) ) * umask(zij,zjj,ik)
-                  ELSE ! we're just dealing with bc velocity so bt transport term should sum to zero
-                     dta(ib,1,ik) = ( dta(ib,1,ik) + ( 0._wp  - ztrans_new ) * r1_hu_n(zij,zjj) ) * umask(zij,zjj,ik)
-                  ENDIF
-               ENDDO
-            ENDDO
-         ENDIF
-
-         IF(igrd == 3) THEN                                 ! do we need to adjust the transport term?
-            DO ib = 1, ipi
-               jj  = 1+floor(REAL(map%ptr(ib)-1)/REAL(ilendta))
-               ji  = map%ptr(ib)-(jj-1)*ilendta
-               zij = idx_bdy(ibdy)%nbi(ib,igrd)
-               zjj = idx_bdy(ibdy)%nbj(ib,igrd)
-               zh  = SUM(dta_read_dz(ji,jj,:) )
-               ztrans = 0._wp
-               ztrans_new = 0._wp
-               DO ik = 1, jpk_bdy                            ! calculate transport on input grid
-                  ztrans     = ztrans     + dta_read(ji,jj,ik) * dta_read_dz(ji,jj,ik)
-               ENDDO
-               DO ik = 1, ipk                                ! calculate transport on model grid
-                  ztrans_new = ztrans_new + dta(ib,1,ik) * e3v_n(zij,zjj,ik) * vmask(zij,zjj,ik)
-               ENDDO
-               DO ik = 1, ipk                                ! make transport correction
-                  IF(fvl) THEN ! bdy data are total velocity so adjust bt transport term to match input data
-                     dta(ib,1,ik) = ( dta(ib,1,ik) + ( ztrans - ztrans_new ) * r1_hv_n(zij,zjj) ) * vmask(zij,zjj,ik)
-                  ELSE ! we're just dealing with bc velocity so bt transport term should sum to zero
-                     dta(ib,1,ik) = ( dta(ib,1,ik) + ( 0._wp  - ztrans_new ) * r1_hv_n(zij,zjj) ) * vmask(zij,zjj,ik)
-                  ENDIF
-               ENDDO
-            ENDDO
-         ENDIF
-
-      ENDIF ! endif unstructured or structured
-
+         ENDDO
+      ENDIF
+      
    END SUBROUTINE fld_bdy_interp
 
@@ -1151,4 +1011,5 @@
       imf = SIZE( sd )
       DO ju = 1, imf
+         IF( TRIM(sd(ju)%clrootname) == 'NOT USED' )   CYCLE
          ill = LEN_TRIM( sd(ju)%vcomp )
          DO jn = 2-COUNT((/sd(ju)%ln_tint/)), 2
@@ -1159,4 +1020,5 @@
                   iv = -1
                   DO jv = 1, imf
+                     IF( TRIM(sd(jv)%clrootname) == 'NOT USED' )   CYCLE
                      IF( TRIM(sd(jv)%vcomp) == TRIM(clcomp) )   iv = jv
                   END DO
@@ -1197,11 +1059,11 @@
       LOGICAL, OPTIONAL, INTENT(in   ) ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
       !
-      LOGICAL :: llprevyr              ! are we reading previous year  file?
-      LOGICAL :: llprevmth             ! are we reading previous month file?
-      INTEGER :: iyear, imonth, iday   ! first day of the current file in yyyy mm dd
-      INTEGER :: isec_week             ! number of seconds since start of the weekly file
-      INTEGER :: indexyr               ! year undex (O/1/2: previous/current/next)
-      INTEGER :: iyear_len, imonth_len ! length (days) of iyear and imonth             ! 
-      CHARACTER(len = 256)::   clname  ! temporary file name
+      LOGICAL  :: llprevyr              ! are we reading previous year  file?
+      LOGICAL  :: llprevmth             ! are we reading previous month file?
+      INTEGER  :: iyear, imonth, iday   ! first day of the current file in yyyy mm dd
+      INTEGER  :: isec_week             ! number of seconds since start of the weekly file
+      INTEGER  :: indexyr               ! year undex (O/1/2: previous/current/next)
+      REAL(wp) :: zyear_len, zmonth_len ! length (days) of iyear and imonth             ! 
+      CHARACTER(len = 256) ::   clname  ! temporary file name
       !!----------------------------------------------------------------------
       IF( PRESENT(kyear) ) THEN                             ! use given values 
@@ -1254,22 +1116,22 @@
          ! find the last record to be read -> update sdjf%nreclast
          indexyr = iyear - nyear + 1
-         iyear_len = nyear_len( indexyr )
+         zyear_len = REAL(nyear_len( indexyr ), wp)
          SELECT CASE ( indexyr )
-         CASE ( 0 )   ;   imonth_len = 31   ! previous year -> imonth = 12
-         CASE ( 1 )   ;   imonth_len = nmonth_len(imonth) 
-         CASE ( 2 )   ;   imonth_len = 31   ! next     year -> imonth = 1
+         CASE ( 0 )   ;   zmonth_len = 31.   ! previous year -> imonth = 12
+         CASE ( 1 )   ;   zmonth_len = REAL(nmonth_len(imonth), wp)
+         CASE ( 2 )   ;   zmonth_len = 31.   ! next     year -> imonth = 1
          END SELECT
          !
          ! last record to be read in the current file
-         IF    ( sdjf%nfreqh == -12 ) THEN                 ;   sdjf%nreclast = 1    !  yearly mean
-         ELSEIF( sdjf%nfreqh ==  -1 ) THEN                                          ! monthly mean
+         IF    ( sdjf%freqh == -12. ) THEN                 ;   sdjf%nreclast = 1    !  yearly mean
+         ELSEIF( sdjf%freqh ==  -1. ) THEN                                          ! monthly mean
             IF(     sdjf%cltype      == 'monthly' ) THEN   ;   sdjf%nreclast = 1
             ELSE                                           ;   sdjf%nreclast = 12
             ENDIF
          ELSE                                                                       ! higher frequency mean (in hours)
-            IF(     sdjf%cltype      == 'monthly' ) THEN   ;   sdjf%nreclast = NINT( 24 * imonth_len / sdjf%nfreqh )
-            ELSEIF( sdjf%cltype(1:4) == 'week'    ) THEN   ;   sdjf%nreclast = NINT( 24 * 7          / sdjf%nfreqh )
-            ELSEIF( sdjf%cltype      == 'daily'   ) THEN   ;   sdjf%nreclast = NINT( 24              / sdjf%nfreqh )
-            ELSE                                           ;   sdjf%nreclast = NINT( 24 * iyear_len  / sdjf%nfreqh )
+            IF(     sdjf%cltype      == 'monthly' ) THEN   ;   sdjf%nreclast = NINT( 24. * zmonth_len / sdjf%freqh )
+            ELSEIF( sdjf%cltype(1:4) == 'week'    ) THEN   ;   sdjf%nreclast = NINT( 24. * 7.         / sdjf%freqh )
+            ELSEIF( sdjf%cltype      == 'daily'   ) THEN   ;   sdjf%nreclast = NINT( 24.              / sdjf%freqh )
+            ELSE                                           ;   sdjf%nreclast = NINT( 24. * zyear_len  / sdjf%freqh )
             ENDIF
          ENDIF
@@ -1299,7 +1161,8 @@
       !
       DO jf = 1, SIZE(sdf)
-         sdf(jf)%clrootname = TRIM( cdir )//TRIM( sdf_n(jf)%clname )
+         sdf(jf)%clrootname = sdf_n(jf)%clname
+         IF( TRIM(sdf_n(jf)%clname) /= 'NOT USED' )   sdf(jf)%clrootname = TRIM( cdir )//sdf(jf)%clrootname
          sdf(jf)%clname     = "not yet defined"
-         sdf(jf)%nfreqh     = sdf_n(jf)%nfreqh
+         sdf(jf)%freqh      = sdf_n(jf)%freqh
          sdf(jf)%clvar      = sdf_n(jf)%clvar
          sdf(jf)%ln_tint    = sdf_n(jf)%ln_tint
@@ -1308,7 +1171,7 @@
          sdf(jf)%num        = -1
          sdf(jf)%wgtname    = " "
-         IF( LEN( TRIM(sdf_n(jf)%wname) ) > 0 )   sdf(jf)%wgtname = TRIM( cdir )//TRIM( sdf_n(jf)%wname )
+         IF( LEN( TRIM(sdf_n(jf)%wname) ) > 0 )   sdf(jf)%wgtname = TRIM( cdir )//sdf_n(jf)%wname
          sdf(jf)%lsmname = " "
-         IF( LEN( TRIM(sdf_n(jf)%lname) ) > 0 )   sdf(jf)%lsmname = TRIM( cdir )//TRIM( sdf_n(jf)%lname )
+         IF( LEN( TRIM(sdf_n(jf)%lname) ) > 0 )   sdf(jf)%lsmname = TRIM( cdir )//sdf_n(jf)%lname
          sdf(jf)%vcomp      = sdf_n(jf)%vcomp
          sdf(jf)%rotn(:)    = .TRUE.   ! pretend to be rotated -> won't try to rotate data before the first call to fld_get
@@ -1317,5 +1180,10 @@
          IF( sdf(jf)%cltype(1:4) == 'week' .AND. sdf(jf)%ln_clim )   &
             &   CALL ctl_stop('fld_clopn: weekly file ('//TRIM(sdf(jf)%clrootname)//') needs ln_clim = .FALSE.')
-         sdf(jf)%nreclast = -1 ! Set to non zero default value to avoid errors, is updated to meaningful value during fld_clopn
+         sdf(jf)%nreclast   = -1 ! Set to non zero default value to avoid errors, is updated to meaningful value during fld_clopn
+         sdf(jf)%igrd       = 0
+         sdf(jf)%ibdy       = 0
+         sdf(jf)%imap       => NULL()
+         sdf(jf)%ltotvel    = .FALSE.
+         sdf(jf)%lzint      = .FALSE.
       END DO
       !
@@ -1331,5 +1199,5 @@
          DO jf = 1, SIZE(sdf)
             WRITE(numout,*) '      root filename: '  , TRIM( sdf(jf)%clrootname ), '   variable name: ', TRIM( sdf(jf)%clvar )
-            WRITE(numout,*) '         frequency: '      ,       sdf(jf)%nfreqh      ,   &
+            WRITE(numout,*) '         frequency: '      ,       sdf(jf)%freqh       ,   &
                &                  '   time interp: '    ,       sdf(jf)%ln_tint     ,   &
                &                  '   climatology: '    ,       sdf(jf)%ln_clim
Index: /NEMO/trunk/src/OCE/SBC/sbcapr.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/sbcapr.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/sbcapr.F90	(revision 11536)
@@ -71,9 +71,9 @@
       REWIND( numnam_ref )              ! Namelist namsbc_apr in reference namelist : File for atmospheric pressure forcing
       READ  ( numnam_ref, namsbc_apr, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_apr in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_apr in reference namelist' )
 
       REWIND( numnam_cfg )              ! Namelist namsbc_apr in configuration namelist : File for atmospheric pressure forcing
       READ  ( numnam_cfg, namsbc_apr, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_apr in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_apr in configuration namelist' )
       IF(lwm) WRITE ( numond, namsbc_apr )
       !
Index: /NEMO/trunk/src/OCE/SBC/sbcblk.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/sbcblk.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/sbcblk.F90	(revision 11536)
@@ -182,9 +182,9 @@
       REWIND( numnam_ref )                !* Namelist namsbc_blk in reference namelist : bulk parameters
       READ  ( numnam_ref, namsbc_blk, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_blk in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_blk in reference namelist' )
       !
       REWIND( numnam_cfg )                !* Namelist namsbc_blk in configuration namelist : bulk parameters
       READ  ( numnam_cfg, namsbc_blk, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_blk in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_blk in configuration namelist' )
       !
       IF(lwm) WRITE( numond, namsbc_blk )
@@ -201,5 +201,5 @@
       !
       IF( ln_dm2dc ) THEN                 !* check: diurnal cycle on Qsr
-         IF( sn_qsr%nfreqh /= 24 )   CALL ctl_stop( 'sbc_blk_init: ln_dm2dc=T only with daily short-wave input' )
+         IF( sn_qsr%freqh /= 24. )   CALL ctl_stop( 'sbc_blk_init: ln_dm2dc=T only with daily short-wave input' )
          IF( sn_qsr%ln_tint ) THEN 
             CALL ctl_warn( 'sbc_blk_init: ln_dm2dc=T daily qsr time interpolation done by sbcdcy module',   &
@@ -225,5 +225,5 @@
          ALLOCATE( sf(ifpr)%fnow(jpi,jpj,1) )
          IF( slf_i(ifpr)%ln_tint )   ALLOCATE( sf(ifpr)%fdta(jpi,jpj,1,2) )
-         IF( slf_i(ifpr)%nfreqh > 0. .AND. MOD( 3600. * slf_i(ifpr)%nfreqh , REAL(nn_fsbc) * rdt) /= 0. )   &
+         IF( slf_i(ifpr)%freqh > 0. .AND. MOD( NINT(3600. * slf_i(ifpr)%freqh), nn_fsbc * NINT(rdt) ) /= 0 )   &
             &  CALL ctl_warn( 'sbc_blk_init: sbcmod timestep rdt*nn_fsbc is NOT a submultiple of atmospheric forcing frequency.',   &
             &                 '               This is not ideal. You should consider changing either rdt or nn_fsbc value...' )
Index: /NEMO/trunk/src/OCE/SBC/sbccpl.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/sbccpl.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/sbccpl.F90	(revision 11536)
@@ -266,9 +266,9 @@
       REWIND( numnam_ref )              ! Namelist namsbc_cpl in reference namelist : Variables for OASIS coupling
       READ  ( numnam_ref, namsbc_cpl, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_cpl in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_cpl in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist namsbc_cpl in configuration namelist : Variables for OASIS coupling
       READ  ( numnam_cfg, namsbc_cpl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_cpl in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_cpl in configuration namelist' )
       IF(lwm) WRITE ( numond, namsbc_cpl )
       !
Index: /NEMO/trunk/src/OCE/SBC/sbcflx.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/sbcflx.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/sbcflx.F90	(revision 11536)
@@ -93,13 +93,13 @@
          REWIND( numnam_ref )              ! Namelist namsbc_flx in reference namelist : Files for fluxes
          READ  ( numnam_ref, namsbc_flx, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_flx in reference namelist', lwp )
+901      IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_flx in reference namelist' )
 
          REWIND( numnam_cfg )              ! Namelist namsbc_flx in configuration namelist : Files for fluxes
          READ  ( numnam_cfg, namsbc_flx, IOSTAT = ios, ERR = 902 )
-902      IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_flx in configuration namelist', lwp )
+902      IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_flx in configuration namelist' )
          IF(lwm) WRITE ( numond, namsbc_flx ) 
          !
          !                                         ! check: do we plan to use ln_dm2dc with non-daily forcing?
-         IF( ln_dm2dc .AND. sn_qsr%nfreqh /= 24 )   &
+         IF( ln_dm2dc .AND. sn_qsr%freqh /= 24. )   &
             &   CALL ctl_stop( 'sbc_blk_core: ln_dm2dc can be activated only with daily short-wave forcing' ) 
          !
Index: /NEMO/trunk/src/OCE/SBC/sbcice_cice.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/sbcice_cice.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/sbcice_cice.F90	(revision 11536)
@@ -764,9 +764,9 @@
          REWIND( numnam_ref )              ! Namelist namsbc_cice in reference namelist : 
          READ  ( numnam_ref, namsbc_cice, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_cice in reference namelist', lwp )
+901      IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_cice in reference namelist' )
 
          REWIND( numnam_cfg )              ! Namelist namsbc_cice in configuration namelist : Parameters of the run
          READ  ( numnam_cfg, namsbc_cice, IOSTAT = ios, ERR = 902 )
-902      IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_cice in configuration namelist', lwp )
+902      IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_cice in configuration namelist' )
          IF(lwm) WRITE ( numond, namsbc_cice )
 
Index: /NEMO/trunk/src/OCE/SBC/sbcice_if.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/sbcice_if.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/sbcice_if.F90	(revision 11536)
@@ -76,9 +76,9 @@
          REWIND( numnam_ref )              ! Namelist namsbc_iif in reference namelist : Ice if file
          READ  ( numnam_ref, namsbc_iif, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_iif in reference namelist', lwp )
+901      IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_iif in reference namelist' )
 
          REWIND( numnam_cfg )              ! Namelist Namelist namsbc_iif in configuration namelist : Ice if file
          READ  ( numnam_cfg, namsbc_iif, IOSTAT = ios, ERR = 902 )
-902      IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_iif in configuration namelist', lwp )
+902      IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_iif in configuration namelist' )
          IF(lwm) WRITE ( numond, namsbc_iif )
 
Index: /NEMO/trunk/src/OCE/SBC/sbcisf.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/sbcisf.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/sbcisf.F90	(revision 11536)
@@ -278,9 +278,9 @@
       REWIND( numnam_ref )              ! Namelist namsbc_rnf in reference namelist : Runoffs 
       READ  ( numnam_ref, namsbc_isf, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_isf in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_isf in reference namelist' )
 
       REWIND( numnam_cfg )              ! Namelist namsbc_rnf in configuration namelist : Runoffs
       READ  ( numnam_cfg, namsbc_isf, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_isf in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_isf in configuration namelist' )
       IF(lwm) WRITE ( numond, namsbc_isf )
 
Index: /NEMO/trunk/src/OCE/SBC/sbcmod.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/sbcmod.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/sbcmod.F90	(revision 11536)
@@ -110,8 +110,8 @@
       REWIND( numnam_ref )          !* Namelist namsbc in reference namelist : Surface boundary
       READ  ( numnam_ref, namsbc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc in reference namelist' )
       REWIND( numnam_cfg )          !* Namelist namsbc in configuration namelist : Parameters of the run
       READ  ( numnam_cfg, namsbc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc in configuration namelist' )
       IF(lwm) WRITE( numond, namsbc )
       !
@@ -307,9 +307,13 @@
       !
       !                             !* check consistency between model timeline and nn_fsbc
-      IF( MOD( nitend - nit000 + 1, nn_fsbc) /= 0 .OR.   &
-          MOD( nstock             , nn_fsbc) /= 0 ) THEN
-         WRITE(ctmp1,*) 'sbc_init : experiment length (', nitend - nit000 + 1, ') or nstock (', nstock,   &
-            &           ' is NOT a multiple of nn_fsbc (', nn_fsbc, ')'
-         CALL ctl_stop( ctmp1, 'Impossible to properly do model restart' )
+      IF( ln_rst_list .OR. nn_stock /= -1 ) THEN   ! we will do restart files
+         IF( MOD( nitend - nit000 + 1, nn_fsbc) /= 0 ) THEN
+            WRITE(ctmp1,*) 'sbc_init : experiment length (', nitend - nit000 + 1, ') is NOT a multiple of nn_fsbc (', nn_fsbc, ')'
+            CALL ctl_stop( ctmp1, 'Impossible to properly do model restart' )
+         ENDIF
+         IF( .NOT. ln_rst_list .AND. MOD( nn_stock, nn_fsbc) /= 0 ) THEN   ! we don't use nn_stock if ln_rst_list
+            WRITE(ctmp1,*) 'sbc_init : nn_stock (', nn_stock, ') is NOT a multiple of nn_fsbc (', nn_fsbc, ')'
+            CALL ctl_stop( ctmp1, 'Impossible to properly do model restart' )
+         ENDIF
       ENDIF
       !
Index: /NEMO/trunk/src/OCE/SBC/sbcrnf.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/sbcrnf.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/sbcrnf.F90	(revision 11536)
@@ -267,9 +267,9 @@
       REWIND( numnam_ref )              ! Namelist namsbc_rnf in reference namelist : Runoffs 
       READ  ( numnam_ref, namsbc_rnf, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_rnf in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_rnf in reference namelist' )
 
       REWIND( numnam_cfg )              ! Namelist namsbc_rnf in configuration namelist : Runoffs
       READ  ( numnam_cfg, namsbc_rnf, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_rnf in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_rnf in configuration namelist' )
       IF(lwm) WRITE ( numond, namsbc_rnf )
       !
Index: /NEMO/trunk/src/OCE/SBC/sbcssr.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/sbcssr.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/sbcssr.F90	(revision 11536)
@@ -166,9 +166,9 @@
       REWIND( numnam_ref )              ! Namelist namsbc_ssr in reference namelist : 
       READ  ( numnam_ref, namsbc_ssr, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_ssr in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_ssr in reference namelist' )
 
       REWIND( numnam_cfg )              ! Namelist namsbc_ssr in configuration namelist :
       READ  ( numnam_cfg, namsbc_ssr, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_ssr in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_ssr in configuration namelist' )
       IF(lwm) WRITE ( numond, namsbc_ssr )
 
Index: /NEMO/trunk/src/OCE/SBC/sbcwave.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/sbcwave.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/sbcwave.F90	(revision 11536)
@@ -397,9 +397,9 @@
       REWIND( numnam_ref )              ! Namelist namsbc_wave in reference namelist : File for drag coeff. from wave model
       READ  ( numnam_ref, namsbc_wave, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_wave in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_wave in reference namelist' )
          
       REWIND( numnam_cfg )              ! Namelist namsbc_wave in configuration namelist : File for drag coeff. from wave model
       READ  ( numnam_cfg, namsbc_wave, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_wave in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_wave in configuration namelist' )
       IF(lwm) WRITE ( numond, namsbc_wave )
       !
Index: /NEMO/trunk/src/OCE/SBC/tideini.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/tideini.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/tideini.F90	(revision 11536)
@@ -60,9 +60,9 @@
       REWIND( numnam_ref )              ! Namelist nam_tide in reference namelist : Tides
       READ  ( numnam_ref, nam_tide, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_tide in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_tide in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist nam_tide in configuration namelist : Tides
       READ  ( numnam_cfg, nam_tide, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nam_tide in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nam_tide in configuration namelist' )
       IF(lwm) WRITE ( numond, nam_tide )
       !
Index: /NEMO/trunk/src/OCE/SBC/updtide.F90
===================================================================
--- /NEMO/trunk/src/OCE/SBC/updtide.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/SBC/updtide.F90	(revision 11536)
@@ -27,5 +27,5 @@
 CONTAINS
 
-   SUBROUTINE upd_tide( kt, kit, time_offset )
+   SUBROUTINE upd_tide( kt, kit, kt_offset )
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE upd_tide  ***
@@ -39,9 +39,9 @@
       INTEGER, INTENT(in)           ::   kt      ! ocean time-step index
       INTEGER, INTENT(in), OPTIONAL ::   kit     ! external mode sub-time-step index (lk_dynspg_ts=T)
-      INTEGER, INTENT(in), OPTIONAL ::   time_offset ! time offset in number 
+      INTEGER, INTENT(in), OPTIONAL ::   kt_offset ! time offset in number 
                                                      ! of internal steps             (lk_dynspg_ts=F)
                                                      ! of external steps             (lk_dynspg_ts=T)
       !
-      INTEGER  ::   joffset      ! local integer
+      INTEGER  ::   ioffset      ! local integer
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
       REAL(wp) ::   zt, zramp    ! local scalar
@@ -52,11 +52,11 @@
       zt = ( kt - kt_tide ) * rdt
       !
-      joffset = 0
-      IF( PRESENT( time_offset ) )   joffset = time_offset
+      ioffset = 0
+      IF( PRESENT( kt_offset ) )   ioffset = kt_offset
       !
       IF( PRESENT( kit ) )   THEN
-         zt = zt + ( kit +  joffset - 1 ) * rdt / REAL( nn_baro, wp )
+         zt = zt + ( kit +  ioffset - 1 ) * rdt / REAL( nn_baro, wp )
       ELSE
-         zt = zt + joffset * rdt
+         zt = zt + ioffset * rdt
       ENDIF
       !
@@ -70,5 +70,5 @@
       IF( ln_tide_ramp ) THEN         ! linear increase if asked
          zt = ( kt - nit000 ) * rdt
-         IF( PRESENT( kit ) )   zt = zt + ( kit + joffset -1) * rdt / REAL( nn_baro, wp )
+         IF( PRESENT( kit ) )   zt = zt + ( kit + ioffset -1) * rdt / REAL( nn_baro, wp )
          zramp = MIN(  MAX( zt / (rdttideramp*rday) , 0._wp ) , 1._wp  )
          pot_astro(:,:) = zramp * pot_astro(:,:)
Index: /NEMO/trunk/src/OCE/STO/stopar.F90
===================================================================
--- /NEMO/trunk/src/OCE/STO/stopar.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/STO/stopar.F90	(revision 11536)
@@ -263,9 +263,9 @@
       REWIND( numnam_ref )              ! Namelist namdyn_adv in reference namelist : Momentum advection scheme
       READ  ( numnam_ref, namsto, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsto in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsto in reference namelist' )
 
       REWIND( numnam_cfg )              ! Namelist namdyn_adv in configuration namelist : Momentum advection scheme
       READ  ( numnam_cfg, namsto, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namsto in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namsto in configuration namelist' )
       IF(lwm) WRITE ( numond, namsto )
 
@@ -750,5 +750,8 @@
       CHARACTER(LEN=9)    ::   clsto3d='sto3d_000' ! stochastic parameter variable name
       CHARACTER(LEN=10)   ::   clseed='seed0_0000' ! seed variable name
-
+      !!----------------------------------------------------------------------
+
+      IF( .NOT. ln_rst_list .AND. nn_stock == -1 ) RETURN   ! we will never do any restart
+      
       IF ( jpsto2d > 0 .OR. jpsto3d > 0 ) THEN
 
@@ -790,5 +793,5 @@
          ! Open the restart file one timestep before writing restart
          IF( kt < nitend) THEN
-         IF( kt == nitrst - 1 .OR. nstock == 1 .OR. kt == nitend-1 ) THEN
+         IF( kt == nitrst - 1 .OR. nn_stock == 1 .OR. kt == nitend-1 ) THEN
             ! create the filename
             IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
Index: /NEMO/trunk/src/OCE/TRA/eosbn2.F90
===================================================================
--- /NEMO/trunk/src/OCE/TRA/eosbn2.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/TRA/eosbn2.F90	(revision 11536)
@@ -30,4 +30,6 @@
    !!   eos_insitu_2d : Compute the in situ density for 2d fields
    !!   bn2           : Compute the Brunt-Vaisala frequency
+   !!   bn2           : compute the Brunt-Vaisala frequency
+   !!   eos_pt_from_ct: compute the potential temperature from the Conservative Temperature
    !!   eos_rab       : generic interface of in situ thermal/haline expansion ratio 
    !!   eos_rab_3d    : compute in situ thermal/haline expansion ratio
@@ -74,7 +76,7 @@
 
    !                               !!** Namelist nameos **
-   LOGICAL , PUBLIC ::   ln_TEOS10   ! determine if eos_pt_from_ct is used to compute sst_m
-   LOGICAL , PUBLIC ::   ln_EOS80   ! determine if eos_pt_from_ct is used to compute sst_m
-   LOGICAL , PUBLIC ::   ln_SEOS   ! determine if eos_pt_from_ct is used to compute sst_m
+   LOGICAL , PUBLIC ::   ln_TEOS10
+   LOGICAL , PUBLIC ::   ln_EOS80
+   LOGICAL , PUBLIC ::   ln_SEOS
 
    ! Parameters
@@ -1235,9 +1237,9 @@
       REWIND( numnam_ref )              ! Namelist nameos in reference namelist : equation of state
       READ  ( numnam_ref, nameos, IOSTAT = ios, ERR = 901 )
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nameos in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nameos in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist nameos in configuration namelist : equation of state
       READ  ( numnam_cfg, nameos, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nameos in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nameos in configuration namelist' )
       IF(lwm) WRITE( numond, nameos )
       !
@@ -1647,4 +1649,7 @@
          !
       CASE( np_seos )                        !==  Simplified EOS     ==!
+
+         r1_S0  = 0.875_wp/35.16504_wp   ! Used to convert CT in potential temperature when using bulk formulae (eos_pt_from_ct)
+         
          IF(lwp) THEN
             WRITE(numout,*)
Index: /NEMO/trunk/src/OCE/TRA/traadv.F90
===================================================================
--- /NEMO/trunk/src/OCE/TRA/traadv.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/TRA/traadv.F90	(revision 11536)
@@ -196,9 +196,9 @@
       REWIND( numnam_ref )                   ! Namelist namtra_adv in reference namelist : Tracer advection scheme
       READ  ( numnam_ref, namtra_adv, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_adv in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_adv in reference namelist' )
       !
       REWIND( numnam_cfg )                   ! Namelist namtra_adv in configuration namelist : Tracer advection scheme
       READ  ( numnam_cfg, namtra_adv, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtra_adv in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtra_adv in configuration namelist' )
       IF(lwm) WRITE( numond, namtra_adv )
       !
Index: /NEMO/trunk/src/OCE/TRA/trabbc.F90
===================================================================
--- /NEMO/trunk/src/OCE/TRA/trabbc.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/TRA/trabbc.F90	(revision 11536)
@@ -135,9 +135,9 @@
       REWIND( numnam_ref )              ! Namelist nambbc in reference namelist : Bottom momentum boundary condition
       READ  ( numnam_ref, nambbc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambbc in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambbc in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist nambbc in configuration namelist : Bottom momentum boundary condition
       READ  ( numnam_cfg, nambbc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nambbc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nambbc in configuration namelist' )
       IF(lwm) WRITE ( numond, nambbc )
       !
Index: /NEMO/trunk/src/OCE/TRA/trabbl.F90
===================================================================
--- /NEMO/trunk/src/OCE/TRA/trabbl.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/TRA/trabbl.F90	(revision 11536)
@@ -485,9 +485,9 @@
       REWIND( numnam_ref )              ! Namelist nambbl in reference namelist : Bottom boundary layer scheme
       READ  ( numnam_ref, nambbl, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambbl in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambbl in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist nambbl in configuration namelist : Bottom boundary layer scheme
       READ  ( numnam_cfg, nambbl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nambbl in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nambbl in configuration namelist' )
       IF(lwm) WRITE ( numond, nambbl )
       !
Index: /NEMO/trunk/src/OCE/TRA/tradmp.F90
===================================================================
--- /NEMO/trunk/src/OCE/TRA/tradmp.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/TRA/tradmp.F90	(revision 11536)
@@ -179,9 +179,9 @@
       REWIND( numnam_ref )   ! Namelist namtra_dmp in reference namelist : T & S relaxation
       READ  ( numnam_ref, namtra_dmp, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_dmp in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_dmp in reference namelist' )
       !
       REWIND( numnam_cfg )   ! Namelist namtra_dmp in configuration namelist : T & S relaxation
       READ  ( numnam_cfg, namtra_dmp, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtra_dmp in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtra_dmp in configuration namelist' )
       IF(lwm) WRITE ( numond, namtra_dmp )
       !
Index: /NEMO/trunk/src/OCE/TRA/traldf_iso.F90
===================================================================
--- /NEMO/trunk/src/OCE/TRA/traldf_iso.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/TRA/traldf_iso.F90	(revision 11536)
@@ -289,5 +289,5 @@
          !!----------------------------------------------------------------------
          !
-         ztfw(1,:,:) = 0._wp     ;     ztfw(jpi,:,:) = 0._wp
+         ztfw(fs_2:1,:,:) = 0._wp     ;     ztfw(jpi:fs_jpim1,:,:) = 0._wp   ! avoid to potentially manipulate NaN values
          !
          ! Vertical fluxes
@@ -323,5 +323,5 @@
          IF( ln_traldf_lap ) THEN               ! laplacian case: eddy coef = ah_wslp2 - akz
             DO jk = 2, jpkm1       
-               DO jj = 1, jpjm1
+               DO jj = 2, jpjm1
                   DO ji = fs_2, fs_jpim1
                      ztfw(ji,jj,jk) = ztfw(ji,jj,jk) + e1e2t(ji,jj) / e3w_n(ji,jj,jk) * wmask(ji,jj,jk)   &
@@ -336,5 +336,5 @@
             CASE(  1  )                            ! 1st pass : eddy coef = ah_wslp2
                DO jk = 2, jpkm1 
-                  DO jj = 1, jpjm1
+                  DO jj = 2, jpjm1
                      DO ji = fs_2, fs_jpim1
                         ztfw(ji,jj,jk) = ztfw(ji,jj,jk)    &
@@ -346,5 +346,5 @@
             CASE(  2  )                         ! 2nd pass : eddy flux = ah_wslp2 and akz applied on ptb  and ptbb gradients, resp.
                DO jk = 2, jpkm1 
-                  DO jj = 1, jpjm1
+                  DO jj = 2, jpjm1
                      DO ji = fs_2, fs_jpim1
                         ztfw(ji,jj,jk) = ztfw(ji,jj,jk) + e1e2t(ji,jj) / e3w_n(ji,jj,jk) * wmask(ji,jj,jk)                      &
Index: /NEMO/trunk/src/OCE/TRA/tramle.F90
===================================================================
--- /NEMO/trunk/src/OCE/TRA/tramle.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/TRA/tramle.F90	(revision 11536)
@@ -268,9 +268,9 @@
       REWIND( numnam_ref )              ! Namelist namtra_mle in reference namelist : Tracer advection scheme
       READ  ( numnam_ref, namtra_mle, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_mle in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_mle in reference namelist' )
 
       REWIND( numnam_cfg )              ! Namelist namtra_mle in configuration namelist : Tracer advection scheme
       READ  ( numnam_cfg, namtra_mle, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtra_mle in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtra_mle in configuration namelist' )
       IF(lwm) WRITE ( numond, namtra_mle )
 
Index: /NEMO/trunk/src/OCE/TRA/traqsr.F90
===================================================================
--- /NEMO/trunk/src/OCE/TRA/traqsr.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/TRA/traqsr.F90	(revision 11536)
@@ -338,9 +338,9 @@
       REWIND( numnam_ref )              ! Namelist namtra_qsr in reference     namelist
       READ  ( numnam_ref, namtra_qsr, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_qsr in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_qsr in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist namtra_qsr in configuration namelist
       READ  ( numnam_cfg, namtra_qsr, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtra_qsr in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtra_qsr in configuration namelist' )
       IF(lwm) WRITE ( numond, namtra_qsr )
       !
Index: /NEMO/trunk/src/OCE/TRD/trdini.F90
===================================================================
--- /NEMO/trunk/src/OCE/TRD/trdini.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/TRD/trdini.F90	(revision 11536)
@@ -48,9 +48,9 @@
       REWIND( numnam_ref )              ! Namelist namtrd in reference namelist : trends diagnostic
       READ  ( numnam_ref, namtrd, IOSTAT = ios, ERR = 901 )
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrd in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrd in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist namtrd in configuration namelist : trends diagnostic
       READ  ( numnam_cfg, namtrd, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrd in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrd in configuration namelist' )
       IF(lwm) WRITE( numond, namtrd )
       !
Index: /NEMO/trunk/src/OCE/TRD/trdmxl.F90
===================================================================
--- /NEMO/trunk/src/OCE/TRD/trdmxl.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/TRD/trdmxl.F90	(revision 11536)
@@ -734,9 +734,9 @@
       REWIND( numnam_ref )              ! Namelist namtrd_mxl in reference namelist : mixed layer trends diagnostic
       READ  ( numnam_ref, namtrd_mxl, IOSTAT = ios, ERR = 901 )
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrd_mxl in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrd_mxl in reference namelist' )
 
       REWIND( numnam_cfg )              ! Namelist namtrd_mxl in configuration namelist : mixed layer trends diagnostic
       READ  ( numnam_cfg, namtrd_mxl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrd_mxl in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrd_mxl in configuration namelist' )
       IF(lwm) WRITE( numond, namtrd_mxl )
       !
@@ -764,14 +764,13 @@
 
       IF( MOD( nitend, nn_trd ) /= 0 ) THEN
-         WRITE(numout,cform_err)
-         WRITE(numout,*) '                Your nitend parameter, nitend = ', nitend
-         WRITE(numout,*) '                is no multiple of the trends diagnostics frequency        '
-         WRITE(numout,*) '                          you defined, nn_trd   = ', nn_trd
-         WRITE(numout,*) '                This will not allow you to restart from this simulation.  '
-         WRITE(numout,*) '                You should reconsider this choice.                        ' 
-         WRITE(numout,*) 
-         WRITE(numout,*) '                N.B. the nitend parameter is also constrained to be a     '
-         WRITE(numout,*) '                     multiple of the nn_fsbc parameter '
-         CALL ctl_stop( 'trd_mxl_init: see comment just above' )
+         WRITE(ctmp1,*) '                Your nitend parameter, nitend = ', nitend
+         WRITE(ctmp2,*) '                is no multiple of the trends diagnostics frequency        '
+         WRITE(ctmp3,*) '                          you defined, nn_trd   = ', nn_trd
+         WRITE(ctmp4,*) '                This will not allow you to restart from this simulation.  '
+         WRITE(ctmp5,*) '                You should reconsider this choice.                        ' 
+         WRITE(ctmp6,*) 
+         WRITE(ctmp7,*) '                N.B. the nitend parameter is also constrained to be a     '
+         WRITE(ctmp8,*) '                     multiple of the nn_fsbc parameter '
+         CALL ctl_stop( ctmp1, ctmp2, ctmp3, ctmp4, ctmp5, ctmp6, ctmp7, ctmp8 )
       END IF
 
Index: /NEMO/trunk/src/OCE/TRD/trdmxl_rst.F90
===================================================================
--- /NEMO/trunk/src/OCE/TRD/trdmxl_rst.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/TRD/trdmxl_rst.F90	(revision 11536)
@@ -47,8 +47,10 @@
       !!--------------------------------------------------------------------------------
 
+      IF( .NOT. ln_rst_list .AND. nn_stock == -1 )   RETURN   ! we will never do any restart
+
       ! to get better performances with NetCDF format:
       ! we open and define the ocean restart_mxl file one time step before writing the data (-> at nitrst - 1)
       ! except if we write ocean restart_mxl files every time step or if an ocean restart_mxl file was writen at nitend - 1
-      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. MOD( nitend - 1, nstock ) == 0 ) ) THEN
+      IF( kt == nitrst - 1 .OR. nn_stock == 1 .OR. ( kt == nitend .AND. MOD( nitend - 1, nn_stock ) == 0 ) ) THEN
          ! beware of the format used to write kt (default is i8.8, that should be large enough...)
          IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
Index: /NEMO/trunk/src/OCE/TRD/trdvor.F90
===================================================================
--- /NEMO/trunk/src/OCE/TRD/trdvor.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/TRD/trdvor.F90	(revision 11536)
@@ -46,7 +46,7 @@
    REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   vor_avr      ! average
    REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   vor_avrb     ! before vorticity (kt-1)
-   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   vor_avrbb    ! vorticity at begining of the nwrite-1 timestep averaging period
+   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   vor_avrbb    ! vorticity at begining of the nn_write-1 timestep averaging period
    REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   vor_avrbn    ! after vorticity at time step after the
-   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   rotot        ! begining of the NWRITE-1 timesteps
+   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   rotot        ! begining of the NN_WRITE-1 timesteps
    REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   vor_avrtot   !
    REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   vor_avrres   !
@@ -129,5 +129,5 @@
       !!              from ocean surface down to control surface (NetCDF output)
       !!
-      !! ** Method/usage :   integration done over nwrite-1 time steps
+      !! ** Method/usage :   integration done over nn_write-1 time steps
       !!
       !! ** Action :   trends :
@@ -143,5 +143,5 @@
       !!                  vortrd (,,10) = forcing term
       !!		              vortrd (,,11) = bottom friction term
-      !!                  rotot(,) : total cumulative trends over nwrite-1 time steps
+      !!                  rotot(,) : total cumulative trends over nn_write-1 time steps
       !!                  vor_avrtot(,) : first membre of vrticity equation
       !!                  vor_avrres(,) : residual = dh/dt entrainment
@@ -214,5 +214,5 @@
       !!              from ocean surface down to control surface (NetCDF output)
       !!
-      !! ** Method/usage :   integration done over nwrite-1 time steps
+      !! ** Method/usage :   integration done over nn_write-1 time steps
       !!
       !! ** Action :     trends :
@@ -228,5 +228,5 @@
       !!                  vortrd (,,10) = forcing term
       !!		  vortrd (,,11) = bottom friction term
-      !!                  rotot(,) : total cumulative trends over nwrite-1 time steps
+      !!                  rotot(,) : total cumulative trends over nn_write-1 time steps
       !!                  vor_avrtot(,) : first membre of vrticity equation
       !!                  vor_avrres(,) : residual = dh/dt entrainment
@@ -360,7 +360,7 @@
       ENDIF
 
-      ! II.2 cumulated trends over analysis period (kt=2 to nwrite)
+      ! II.2 cumulated trends over analysis period (kt=2 to nn_write)
       ! ----------------------
-      ! trends cumulated over nwrite-2 time steps
+      ! trends cumulated over nn_write-2 time steps
 
       IF( kt >= nit000+2 ) THEN
@@ -376,5 +376,5 @@
       !   III. Output in netCDF + residual computation
       !  =============================================
-
+      
       ! define time axis
       it    = kt
@@ -504,5 +504,5 @@
       ENDIF
 #if defined key_diainstant
-      zsto = nwrite*rdt
+      zsto = nn_write*rdt
       clop = "inst("//TRIM(clop)//")"
 #else
Index: /NEMO/trunk/src/OCE/USR/usrdef_nam.F90
===================================================================
--- /NEMO/trunk/src/OCE/USR/usrdef_nam.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/USR/usrdef_nam.F90	(revision 11536)
@@ -37,5 +37,5 @@
 CONTAINS
 
-   SUBROUTINE usr_def_nam( ldtxt, ldnam, cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+   SUBROUTINE usr_def_nam( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -49,22 +49,19 @@
       !! ** input   : - namusr_def namelist found in namelist_cfg
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), DIMENSION(:), INTENT(out) ::   ldtxt, ldnam    ! stored print information
-      CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
-      INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
-      INTEGER                       , INTENT(out) ::   kpi, kpj, kpk   ! global domain sizes 
-      INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
+      CHARACTER(len=*), INTENT(out) ::   cd_cfg          ! configuration name
+      INTEGER         , INTENT(out) ::   kk_cfg          ! configuration resolution
+      INTEGER         , INTENT(out) ::   kpi, kpj, kpk   ! global domain sizes 
+      INTEGER         , INTENT(out) ::   kperio          ! lateral global domain b.c. 
       !
-      INTEGER ::   ios, ii   ! Local integer
+      INTEGER ::   ios   ! Local integer
       !!
       NAMELIST/namusr_def/ nn_GYRE, ln_bench, jpkglo
       !!----------------------------------------------------------------------
       !
-      ii = 1
-      !
       REWIND( numnam_cfg )          ! Namelist namusr_def (exist in namelist_cfg only)
       READ  ( numnam_cfg, namusr_def, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist', .TRUE. )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist' )
       !
-      WRITE( ldnam(:), namusr_def )
+      IF(lwm)   WRITE( numond, namusr_def )
       !
       cd_cfg = 'GYRE'               ! name & resolution (not used)
@@ -83,27 +80,27 @@
 #endif
       kpk = jpkglo
-      !
-      !                             ! control print
-      WRITE(ldtxt(ii),*) '   '                                                                            ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'     ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~~~~~~ '                                                                   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Namelist namusr_def : GYRE case'                                             ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      GYRE used as Benchmark (=T)                      ln_bench  = ', ln_bench  ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      inverse resolution & implied domain size         nn_GYRE   = ', nn_GYRE   ;   ii = ii + 1
-#if defined key_agrif
-      IF( Agrif_Root() ) THEN
-#endif
-      WRITE(ldtxt(ii),*) '         jpiglo = 30*nn_GYRE+2                            jpiglo = ', kpi       ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         jpjglo = 20*nn_GYRE+2                            jpjglo = ', kpj       ;   ii = ii + 1
-#if defined key_agrif
-      ENDIF
-#endif
-      WRITE(ldtxt(ii),*) '      number of model levels                              jpkglo = ', kpk       ;   ii = ii + 1
-      !
       !                             ! Set the lateral boundary condition of the global domain
       kperio = 0                    ! GYRE configuration : closed domain
       !
-      WRITE(ldtxt(ii),*) '   '                                                                            ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Lateral b.c. of the global domain set to closed     jperio = ', kperio       ;   ii = ii + 1
+      !                             ! control print
+      IF(lwp) THEN
+         WRITE(numout,*) '   '
+         WRITE(numout,*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '   Namelist namusr_def : GYRE case'
+         WRITE(numout,*) '      GYRE used as Benchmark (=T)                      ln_bench  = ', ln_bench
+         WRITE(numout,*) '      inverse resolution & implied domain size         nn_GYRE   = ', nn_GYRE
+#if defined key_agrif
+         IF( Agrif_Root() ) THEN
+#endif
+         WRITE(numout,*) '         jpiglo = 30*nn_GYRE+2                            jpiglo = ', kpi
+         WRITE(numout,*) '         jpjglo = 20*nn_GYRE+2                            jpjglo = ', kpj
+#if defined key_agrif
+         ENDIF
+#endif
+         WRITE(numout,*) '      number of model levels                              jpkglo = ', kpk
+         WRITE(numout,*) '   '
+         WRITE(numout,*) '   Lateral b.c. of the global domain set to closed        jperio = ', kperio
+      ENDIF
       !
    END SUBROUTINE usr_def_nam
Index: /NEMO/trunk/src/OCE/ZDF/zdfdrg.F90
===================================================================
--- /NEMO/trunk/src/OCE/ZDF/zdfdrg.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/ZDF/zdfdrg.F90	(revision 11536)
@@ -238,8 +238,8 @@
       REWIND( numnam_ref )                   ! Namelist namdrg in reference namelist
       READ  ( numnam_ref, namdrg, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam( ios , 'namdrg in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam( ios , 'namdrg in reference namelist' )
       REWIND( numnam_cfg )                   ! Namelist namdrg in configuration namelist
       READ  ( numnam_cfg, namdrg, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam( ios , 'namdrg in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam( ios , 'namdrg in configuration namelist' )
       IF(lwm) WRITE ( numond, namdrg )
       !
@@ -338,9 +338,9 @@
       IF(ll_top)   READ  ( numnam_ref, namdrg_top, IOSTAT = ios, ERR = 901)
       IF(ll_bot)   READ  ( numnam_ref, namdrg_bot, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam( ios , TRIM(cl_namref), lwp )
+901   IF( ios /= 0 )   CALL ctl_nam( ios , TRIM(cl_namref) )
       REWIND( numnam_cfg )                   ! Namelist cd_namdrg in configuration namelist
       IF(ll_top)   READ  ( numnam_cfg, namdrg_top, IOSTAT = ios, ERR = 902 )
       IF(ll_bot)   READ  ( numnam_cfg, namdrg_bot, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam( ios , TRIM(cl_namcfg), lwp )
+902   IF( ios >  0 )   CALL ctl_nam( ios , TRIM(cl_namcfg) )
       IF(lwm .AND. ll_top)   WRITE ( numond, namdrg_top )
       IF(lwm .AND. ll_bot)   WRITE ( numond, namdrg_bot )
Index: /NEMO/trunk/src/OCE/ZDF/zdfgls.F90
===================================================================
--- /NEMO/trunk/src/OCE/ZDF/zdfgls.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/ZDF/zdfgls.F90	(revision 11536)
@@ -859,9 +859,9 @@
       REWIND( numnam_ref )              ! Namelist namzdf_gls in reference namelist : Vertical eddy diffivity and viscosity using gls turbulent closure scheme
       READ  ( numnam_ref, namzdf_gls, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf_gls in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf_gls in reference namelist' )
 
       REWIND( numnam_cfg )              ! Namelist namzdf_gls in configuration namelist : Vertical eddy diffivity and viscosity using gls turbulent closure scheme
       READ  ( numnam_cfg, namzdf_gls, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namzdf_gls in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namzdf_gls in configuration namelist' )
       IF(lwm) WRITE ( numond, namzdf_gls )
 
Index: /NEMO/trunk/src/OCE/ZDF/zdfiwm.F90
===================================================================
--- /NEMO/trunk/src/OCE/ZDF/zdfiwm.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/ZDF/zdfiwm.F90	(revision 11536)
@@ -424,9 +424,9 @@
       REWIND( numnam_ref )              ! Namelist namzdf_iwm in reference namelist : Wave-driven mixing
       READ  ( numnam_ref, namzdf_iwm, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf_iwm in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf_iwm in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist namzdf_iwm in configuration namelist : Wave-driven mixing
       READ  ( numnam_cfg, namzdf_iwm, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namzdf_iwm in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namzdf_iwm in configuration namelist' )
       IF(lwm) WRITE ( numond, namzdf_iwm )
       !
Index: /NEMO/trunk/src/OCE/ZDF/zdfosm.F90
===================================================================
--- /NEMO/trunk/src/OCE/ZDF/zdfosm.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/ZDF/zdfosm.F90	(revision 11536)
@@ -1386,9 +1386,9 @@
      REWIND( numnam_ref )              ! Namelist namzdf_osm in reference namelist : Osmosis ML model
      READ  ( numnam_ref, namzdf_osm, IOSTAT = ios, ERR = 901)
-901  IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_osm in reference namelist', lwp )
+901  IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_osm in reference namelist' )
 
      REWIND( numnam_cfg )              ! Namelist namzdf_tke in configuration namelist : Turbulent Kinetic Energy
      READ  ( numnam_cfg, namzdf_osm, IOSTAT = ios, ERR = 902 )
-902  IF( ios >  0 ) CALL ctl_nam ( ios , 'namzdf_osm in configuration namelist', lwp )
+902  IF( ios >  0 ) CALL ctl_nam ( ios , 'namzdf_osm in configuration namelist' )
      IF(lwm) WRITE ( numond, namzdf_osm )
 
Index: /NEMO/trunk/src/OCE/ZDF/zdfphy.F90
===================================================================
--- /NEMO/trunk/src/OCE/ZDF/zdfphy.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/ZDF/zdfphy.F90	(revision 11536)
@@ -93,9 +93,9 @@
       REWIND( numnam_ref )              ! Namelist namzdf in reference namelist : Vertical mixing parameters
       READ  ( numnam_ref, namzdf, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist namzdf in reference namelist : Vertical mixing parameters
       READ  ( numnam_cfg, namzdf, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namzdf in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namzdf in configuration namelist' )
       IF(lwm)   WRITE ( numond, namzdf )
       !
Index: /NEMO/trunk/src/OCE/ZDF/zdfric.F90
===================================================================
--- /NEMO/trunk/src/OCE/ZDF/zdfric.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/ZDF/zdfric.F90	(revision 11536)
@@ -80,9 +80,9 @@
       REWIND( numnam_ref )              ! Namelist namzdf_ric in reference namelist : Vertical diffusion Kz depends on Richardson number
       READ  ( numnam_ref, namzdf_ric, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_ric in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_ric in reference namelist' )
 
       REWIND( numnam_cfg )              ! Namelist namzdf_ric in configuration namelist : Vertical diffusion Kz depends on Richardson number
       READ  ( numnam_cfg, namzdf_ric, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namzdf_ric in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namzdf_ric in configuration namelist' )
       IF(lwm) WRITE ( numond, namzdf_ric )
       !
Index: /NEMO/trunk/src/OCE/ZDF/zdftke.F90
===================================================================
--- /NEMO/trunk/src/OCE/ZDF/zdftke.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/ZDF/zdftke.F90	(revision 11536)
@@ -658,9 +658,9 @@
       REWIND( numnam_ref )              ! Namelist namzdf_tke in reference namelist : Turbulent Kinetic Energy
       READ  ( numnam_ref, namzdf_tke, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tke in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tke in reference namelist' )
 
       REWIND( numnam_cfg )              ! Namelist namzdf_tke in configuration namelist : Turbulent Kinetic Energy
       READ  ( numnam_cfg, namzdf_tke, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namzdf_tke in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namzdf_tke in configuration namelist' )
       IF(lwm) WRITE ( numond, namzdf_tke )
       !
Index: /NEMO/trunk/src/OCE/module_example
===================================================================
--- /NEMO/trunk/src/OCE/module_example	(revision 11535)
+++ /NEMO/trunk/src/OCE/module_example	(revision 11536)
@@ -152,9 +152,9 @@
       REWIND( numnam_ref )              ! Namelist namexa in reference namelist : Example
       READ  ( numnam_ref, namexa, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namexa in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namexa in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist namexa in configuration namelist : Example
       READ  ( numnam_cfg, namexa, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namexa in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namexa in configuration namelist' )
    ! Output namelist for control
       WRITE ( numond, namexa )
Index: /NEMO/trunk/src/OCE/nemogcm.F90
===================================================================
--- /NEMO/trunk/src/OCE/nemogcm.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/nemogcm.F90	(revision 11536)
@@ -59,4 +59,5 @@
    USE diaobs         ! Observation diagnostics       (dia_obs_init routine)
    USE diacfl         ! CFL diagnostics               (dia_cfl_init routine)
+   USE diaharm        ! tidal harmonics diagnostics  (dia_harm_init routine)
    USE step           ! NEMO time-stepping                 (stp     routine)
    USE icbini         ! handle bergs, initialisation
@@ -103,4 +104,5 @@
 
 #if defined key_mpp_mpi
+   ! need MPI_Wtime
    INCLUDE 'mpif.h'
 #endif
@@ -128,4 +130,5 @@
       !!----------------------------------------------------------------------
       INTEGER ::   istp   ! time step index
+      REAL(wp)::   zstptiming   ! elapsed time for 1 time step
       !!----------------------------------------------------------------------
       !
@@ -188,11 +191,17 @@
          !
          DO WHILE( istp <= nitend .AND. nstop == 0 )
-#if defined key_mpp_mpi
+
             ncom_stp = istp
-            IF ( istp == ( nit000 + 1 ) ) elapsed_time = MPI_Wtime()
-            IF ( istp ==         nitend ) elapsed_time = MPI_Wtime() - elapsed_time
-#endif
+            IF( ln_timing ) THEN
+               zstptiming = MPI_Wtime()
+               IF ( istp == ( nit000 + 1 ) ) elapsed_time = zstptiming
+               IF ( istp ==         nitend ) elapsed_time = zstptiming - elapsed_time
+            ENDIF
+            
             CALL stp        ( istp ) 
             istp = istp + 1
+
+            IF( lwp .AND. ln_timing )   WRITE(numtime,*) 'timing step ', istp-1, ' : ', MPI_Wtime() - zstptiming
+
          END DO
          !
@@ -220,7 +229,6 @@
       !
       IF( nstop /= 0 .AND. lwp ) THEN        ! error print
-         WRITE(numout,cform_err)
-         WRITE(numout,*) '   ==>>>   nemo_gcm: a total of ', nstop, ' errors have been found'
-         WRITE(numout,*)
+         WRITE(ctmp1,*) '   ==>>>   nemo_gcm: a total of ', nstop, ' errors have been found'
+         CALL ctl_stop( ctmp1 )
       ENDIF
       !
@@ -234,5 +242,5 @@
 #else
       IF    ( lk_oasis ) THEN   ;   CALL cpl_finalize   ! end coupling and mpp communications with OASIS
-      ELSEIF( lk_mpp   ) THEN   ;   CALL mppstop( ldfinal = .TRUE. )   ! end mpp communications
+      ELSEIF( lk_mpp   ) THEN   ;   CALL mppstop      ! end mpp communications
       ENDIF
 #endif
@@ -240,5 +248,5 @@
       IF(lwm) THEN
          IF( nstop == 0 ) THEN   ;   STOP 0
-         ELSE                    ;   STOP 999
+         ELSE                    ;   STOP 123
          ENDIF
       ENDIF
@@ -253,7 +261,5 @@
       !! ** Purpose :   initialization of the NEMO GCM
       !!----------------------------------------------------------------------
-      INTEGER  ::   ji                 ! dummy loop indices
-      INTEGER  ::   ios, ilocal_comm   ! local integers
-      CHARACTER(len=120), DIMENSION(60) ::   cltxt, cltxt2, clnam
+      INTEGER ::   ios, ilocal_comm   ! local integers
       !!
       NAMELIST/namctl/ ln_ctl   , sn_cfctl, nn_print, nn_ictls, nn_ictle,   &
@@ -263,54 +269,21 @@
       !!----------------------------------------------------------------------
       !
-      cltxt  = ''
-      cltxt2 = ''
-      clnam  = ''  
       cxios_context = 'nemo'
       !
-      !                             ! Open reference namelist and configuration namelist files
-      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
-      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
-      !
-      REWIND( numnam_ref )              ! Namelist namctl in reference namelist
-      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
-      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
-      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
-      !
-      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
-      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
-      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
-      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
-
-      !                             !--------------------------!
-      !                             !  Set global domain size  !   (control print return in cltxt2)
-      !                             !--------------------------!
-      IF( ln_read_cfg ) THEN              ! Read sizes in domain configuration file
-         CALL domain_cfg ( cltxt2,        cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
-         !
-      ELSE                                ! user-defined namelist
-         CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
-      ENDIF
-      !
-      !
-      !                             !--------------------------------------------!
-      !                             !  set communicator & select the local node  !
-      !                             !  NB: mynode also opens output.namelist.dyn !
-      !                             !      on unit number numond on first proc   !
-      !                             !--------------------------------------------!
+      !                             !-------------------------------------------------!
+      !                             !     set communicator & select the local rank    !
+      !                             !  must be done as soon as possible to get narea  !
+      !                             !-------------------------------------------------!
+      !
 #if defined key_iomput
       IF( Agrif_Root() ) THEN
          IF( lk_oasis ) THEN
             CALL cpl_init( "oceanx", ilocal_comm )                               ! nemo local communicator given by oasis
-            CALL xios_initialize( "not used"       ,local_comm= ilocal_comm )    ! send nemo communicator to xios
+            CALL xios_initialize( "not used"       , local_comm =ilocal_comm )   ! send nemo communicator to xios
          ELSE
-            CALL xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
+            CALL xios_initialize( "for_xios_mpi_id", return_comm=ilocal_comm )   ! nemo local communicator given by xios
          ENDIF
       ENDIF
-      ! Nodes selection (control print return in cltxt)
-      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
+      CALL mpp_start( ilocal_comm )
 #else
       IF( lk_oasis ) THEN
@@ -318,47 +291,46 @@
             CALL cpl_init( "oceanx", ilocal_comm )          ! nemo local communicator given by oasis
          ENDIF
-         ! Nodes selection (control print return in cltxt)
-         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
+         CALL mpp_start( ilocal_comm )
       ELSE
-         ilocal_comm = 0                                    ! Nodes selection (control print return in cltxt)
-         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )
-      ENDIF
-#endif
-
-      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
-
-      IF( sn_cfctl%l_config ) THEN
-         ! Activate finer control of report outputs
-         ! optionally switch off output from selected areas (note this only
-         ! applies to output which does not involve global communications)
-         IF( ( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax  ) .OR. &
-           & ( MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 ) )    &
-           &   CALL nemo_set_cfctl( sn_cfctl, .FALSE., .FALSE. )
-      ELSE
-         ! Use ln_ctl to turn on or off all options.
-         CALL nemo_set_cfctl( sn_cfctl, ln_ctl, .TRUE. )
-      ENDIF
-
-      lwm = (narea == 1)                                    ! control of output namelists
-      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
-
-      IF(lwm) THEN               ! write merged namelists from earlier to output namelist 
-         !                       ! now that the file has been opened in call to mynode. 
-         !                       ! NB: nammpp has already been written in mynode (if lk_mpp_mpi)
-         WRITE( numond, namctl )
-         WRITE( numond, namcfg )
-         IF( .NOT.ln_read_cfg ) THEN
-            DO ji = 1, SIZE(clnam)
-               IF( TRIM(clnam(ji)) /= '' )   WRITE(numond, * ) clnam(ji)     ! namusr_def print
-            END DO
-         ENDIF
-      ENDIF
-
-      IF(lwp) THEN                            ! open listing units
-         !
-         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
+         CALL mpp_start( )
+      ENDIF
+#endif
+      !
+      narea = mpprank + 1               ! mpprank: the rank of proc (0 --> mppsize -1 )
+      lwm = (narea == 1)                ! control of output namelists
+      !
+      !                             !---------------------------------------------------------------!
+      !                             ! Open output files, reference and configuration namelist files !
+      !                             !---------------------------------------------------------------!
+      !
+      ! open ocean.output as soon as possible to get all output prints (including errors messages)
+      IF( lwm )   CALL ctl_opn(     numout,        'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      ! open reference and configuration namelist files
+                  CALL ctl_opn( numnam_ref,        'namelist_ref',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+                  CALL ctl_opn( numnam_cfg,        'namelist_cfg',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      IF( lwm )   CALL ctl_opn(     numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      ! open /dev/null file to be able to supress output write easily
+                  CALL ctl_opn(     numnul,           '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      !
+      !                             !--------------------!
+      !                             ! Open listing units !  -> need ln_ctl from namctl to define lwp
+      !                             !--------------------!
+      !
+      REWIND( numnam_ref )              ! Namelist namctl in reference namelist
+      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist' )
+      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
+      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist' )
+      !
+      lwp = (narea == 1) .OR. ln_ctl    ! control of all listing output print
+      !
+      IF(lwp) THEN                      ! open listing units
+         !
+         IF( .NOT. lwm )   &            ! alreay opened for narea == 1
+            &            CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE., narea )
          !
          WRITE(numout,*)
-         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
+         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - CMCC'
          WRITE(numout,*) '                       NEMO team'
          WRITE(numout,*) '            Ocean General Circulation Model'
@@ -379,22 +351,47 @@
          WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
          WRITE(numout,*)
-         
-         DO ji = 1, SIZE(cltxt)
-            IF( TRIM(cltxt (ji)) /= '' )   WRITE(numout,*) TRIM(cltxt(ji))    ! control print of mynode
-         END DO
-         WRITE(numout,*)
-         WRITE(numout,*)
-         DO ji = 1, SIZE(cltxt2)
-            IF( TRIM(cltxt2(ji)) /= '' )   WRITE(numout,*) TRIM(cltxt2(ji))   ! control print of domain size
-         END DO
          !
          WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
          !
       ENDIF
-      ! open /dev/null file to be able to supress output write easily
-      CALL ctl_opn( numnul, '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
-      !
-      !                                      ! Domain decomposition
-      CALL mpp_init                          ! MPP
+      !
+      ! finalize the definition of namctl variables
+      IF( sn_cfctl%l_config ) THEN
+         ! Activate finer control of report outputs
+         ! optionally switch off output from selected areas (note this only
+         ! applies to output which does not involve global communications)
+         IF( ( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax  ) .OR. &
+           & ( MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 ) )    &
+           &   CALL nemo_set_cfctl( sn_cfctl, .FALSE., .FALSE. )
+      ELSE
+         ! Use ln_ctl to turn on or off all options.
+         CALL nemo_set_cfctl( sn_cfctl, ln_ctl, .TRUE. )
+      ENDIF
+      !
+      IF(lwm) WRITE( numond, namctl )
+      !
+      !                             !------------------------------------!
+      !                             !  Set global domain size parameters !
+      !                             !------------------------------------!
+      !
+      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
+      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist' )
+      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
+      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist' )   
+      !
+      IF( ln_read_cfg ) THEN            ! Read sizes in domain configuration file
+         CALL domain_cfg ( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
+      ELSE                              ! user-defined namelist
+         CALL usr_def_nam( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
+      ENDIF
+      !
+      IF(lwm)   WRITE( numond, namcfg )
+      !
+      !                             !-----------------------------------------!
+      !                             ! mpp parameters and domain decomposition !
+      !                             !-----------------------------------------!
+      CALL mpp_init
 
       ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
@@ -480,8 +477,8 @@
      
       !                                      ! Diagnostics
-      IF( lk_floats    )   CALL     flo_init    ! drifting Floats
+                           CALL     flo_init    ! drifting Floats
       IF( ln_diacfl    )   CALL dia_cfl_init    ! Initialise CFL diagnostics
                            CALL dia_ptr_init    ! Poleward TRansports initialization
-      IF( lk_diadct    )   CALL dia_dct_init    ! Sections tranports
+                           CALL dia_dct_init    ! Sections tranports
                            CALL dia_hsb_init    ! heat content, salt content and volume budgets
                            CALL     trd_init    ! Mixed-layer/Vorticity/Integral constraints trends
@@ -489,5 +486,6 @@
                            CALL dia_tmb_init    ! TMB outputs
                            CALL dia_25h_init    ! 25h mean  outputs
-      IF( ln_diaobs    )   CALL dia_obs( nit000-1 )   ! Observation operator for restart
+                           CALL dia_harm_init   ! tidal harmonics outputs
+     IF( ln_diaobs    )    CALL dia_obs( nit000-1 )   ! Observation operator for restart
 
       !                                      ! Assimilation increments
@@ -507,5 +505,5 @@
       !! ** Purpose :   control print setting
       !!
-      !! ** Method  : - print namctl information and check some consistencies
+      !! ** Method  : - print namctl and namcfg information and check some consistencies
       !!----------------------------------------------------------------------
       !
@@ -650,7 +648,4 @@
       USE trc_oce   , ONLY : trc_oce_alloc
       USE bdy_oce   , ONLY : bdy_oce_alloc
-#if defined key_diadct 
-      USE diadct    , ONLY : diadct_alloc 
-#endif 
       !
       INTEGER :: ierr
@@ -664,8 +659,4 @@
       ierr = ierr + bdy_oce_alloc()    ! bdy masks (incl. initialization)
       !
-#if defined key_diadct 
-      ierr = ierr + diadct_alloc ()    ! 
-#endif 
-      !
       CALL mpp_sum( 'nemogcm', ierr )
       IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc: unable to allocate standard ocean arrays' )
@@ -673,4 +664,5 @@
    END SUBROUTINE nemo_alloc
 
+   
    SUBROUTINE nemo_set_cfctl(sn_cfctl, setto, for_all )
       !!----------------------------------------------------------------------
Index: /NEMO/trunk/src/OCE/step.F90
===================================================================
--- /NEMO/trunk/src/OCE/step.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/step.F90	(revision 11536)
@@ -112,5 +112,5 @@
       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( ln_bdy     )   CALL bdy_dta ( kstp, time_offset=+1 )   ! update dynamic & tracer data at open boundaries
+      IF( ln_bdy     )   CALL bdy_dta ( kstp, kt_offset = +1 )   ! update dynamic & tracer data at open boundaries
                          CALL sbc     ( kstp )                   ! Sea Boundary Condition (including sea-ice)
 
@@ -203,10 +203,10 @@
       ! diagnostics and outputs
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( lk_floats  )   CALL flo_stp ( kstp )        ! drifting Floats
+      IF( ln_floats  )   CALL flo_stp ( kstp )        ! drifting Floats
       IF( ln_diacfl  )   CALL dia_cfl ( kstp )        ! Courant number diagnostics
       IF( lk_diahth  )   CALL dia_hth ( kstp )        ! Thermocline depth (20 degres isotherm depth)
-      IF( lk_diadct  )   CALL dia_dct ( kstp )        ! Transports
+      IF( ln_diadct  )   CALL dia_dct ( kstp )        ! Transports
                          CALL dia_ar5 ( kstp )        ! ar5 diag
-      IF( lk_diaharm )   CALL dia_harm( kstp )        ! Tidal harmonic analysis
+      IF( ln_diaharm )   CALL dia_harm( kstp )        ! Tidal harmonic analysis
                          CALL dia_wri ( kstp )        ! ocean model: outputs
       !
Index: /NEMO/trunk/src/OCE/timing.F90
===================================================================
--- /NEMO/trunk/src/OCE/timing.F90	(revision 11535)
+++ /NEMO/trunk/src/OCE/timing.F90	(revision 11536)
@@ -347,4 +347,6 @@
 
       ! write output file
+      IF( lwriter ) WRITE(numtime,*) 
+      IF( lwriter ) WRITE(numtime,*) 
       IF( lwriter ) WRITE(numtime,*) 'Total timing (sum) :'
       IF( lwriter ) WRITE(numtime,*) '--------------------'
@@ -657,6 +659,6 @@
          ! Compute cpu/elapsed ratio
          zall_ratio(:) = all_ctime(:) / all_etime(:)
-         ztot_ratio    = SUM(zall_ratio(:))
-         zavg_ratio    = ztot_ratio/REAL(jpnij,wp)
+         ztot_ratio    = SUM(all_ctime(:))/SUM(all_etime(:))
+         zavg_ratio    = SUM(zall_ratio(:))/REAL(jpnij,wp)
          zmax_ratio    = MAXVAL(zall_ratio(:))
          zmin_ratio    = MINVAL(zall_ratio(:))   
@@ -667,6 +669,6 @@
          cllignes(2)='1x,"--------------------",//,'
          cllignes(3)='1x,"Process Rank |"," Elapsed Time (s) |"," CPU Time (s) |"," Ratio CPU/Elapsed",/,'
-         cllignes(4)='    (1x,i4,9x,"|",f12.3,6x,"|",f12.3,2x,"|",4x,f7.3,/),'
-         WRITE(cllignes(4)(1:4),'(I4)') jpnij
+         cllignes(4)='      (4x,i6,4x,"|",f12.3,6x,"|",f12.3,2x,"|",4x,f7.3,/),'
+         WRITE(cllignes(4)(1:6),'(I6)') jpnij
          cllignes(5)='1x,"Total        |",f12.3,6x,"|",F12.3,2x,"|",4x,f7.3,/,'
          cllignes(6)='1x,"Minimum      |",f12.3,6x,"|",F12.3,2x,"|",4x,f7.3,/,'
Index: /NEMO/trunk/src/OFF/dtadyn.F90
===================================================================
--- /NEMO/trunk/src/OFF/dtadyn.F90	(revision 11535)
+++ /NEMO/trunk/src/OFF/dtadyn.F90	(revision 11536)
@@ -227,8 +227,8 @@
       REWIND( numnam_ref )              ! Namelist namdta_dyn in reference namelist : Offline: init. of dynamical data
       READ  ( numnam_ref, namdta_dyn, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdta_dyn in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdta_dyn in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namdta_dyn in configuration namelist : Offline: init. of dynamical data
       READ  ( numnam_cfg, namdta_dyn, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdta_dyn in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdta_dyn in configuration namelist' )
       IF(lwm) WRITE ( numond, namdta_dyn )
       !                                         ! store namelist information in an array
@@ -477,8 +477,8 @@
       REWIND( numnam_ref )              ! Namelist namdta_dyn in reference namelist : Offline: init. of dynamical data
       READ  ( numnam_ref, namdta_dyn, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdta_dyn in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdta_dyn in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namdta_dyn in configuration namelist : Offline: init. of dynamical data
       READ  ( numnam_cfg, namdta_dyn, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdta_dyn in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdta_dyn in configuration namelist' )
       IF(lwm) WRITE ( numond, namdta_dyn )
       !                                         ! store namelist information in an array
Index: /NEMO/trunk/src/OFF/nemogcm.F90
===================================================================
--- /NEMO/trunk/src/OFF/nemogcm.F90	(revision 11535)
+++ /NEMO/trunk/src/OFF/nemogcm.F90	(revision 11536)
@@ -131,7 +131,6 @@
 
       IF( nstop /= 0 .AND. lwp ) THEN                 ! error print
-         WRITE(numout,cform_err)
-         WRITE(numout,*) '   ==>>>   nemo_gcm: a total of ', nstop, ' errors have been found'
-         WRITE(numout,*)
+         WRITE(ctmp1,*) '   ==>>>   nemo_gcm: a total of ', nstop, ' errors have been found'
+         CALL ctl_stop( ctmp1 )
       ENDIF
       !
@@ -146,4 +145,10 @@
 #endif
       !
+      IF(lwm) THEN
+         IF( nstop == 0 ) THEN   ;   STOP 0
+         ELSE                    ;   STOP 123
+         ENDIF
+      ENDIF
+      !
    END SUBROUTINE nemo_gcm
 
@@ -155,7 +160,5 @@
       !! ** Purpose :   initialization of the nemo model in off-line mode
       !!----------------------------------------------------------------------
-      INTEGER  ::   ji                 ! dummy loop indices
-      INTEGER  ::   ios, ilocal_comm   ! local integers
-      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
+      INTEGER ::   ios, ilocal_comm   ! local integers
       !!
       NAMELIST/namctl/ ln_ctl   , sn_cfctl, nn_print, nn_ictls, nn_ictle,   &
@@ -165,54 +168,78 @@
       !!----------------------------------------------------------------------
       !
-      cltxt  = ''
-      cltxt2 = ''
-      clnam  = ''  
       cxios_context = 'nemo'
       !
-      !                             ! Open reference namelist and configuration namelist files
-      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
-      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
+      !                             !-------------------------------------------------!
+      !                             !     set communicator & select the local rank    !
+      !                             !  must be done as soon as possible to get narea  !
+      !                             !-------------------------------------------------!
+      !
+#if defined key_iomput
+      CALL xios_initialize( "for_xios_mpi_id", return_comm=ilocal_comm )   ! nemo local communicator given by xios
+      CALL mpp_start( ilocal_comm )
+#else
+      CALL mpp_start( )
+#endif
+      !
+      narea = mpprank + 1               ! mpprank: the rank of proc (0 --> mppsize -1 )
+      lwm = (narea == 1)                ! control of output namelists
+      !
+      !                             !---------------------------------------------------------------!
+      !                             ! Open output files, reference and configuration namelist files !
+      !                             !---------------------------------------------------------------!
+      !
+      ! open ocean.output as soon as possible to get all output prints (including errors messages)
+      IF( lwm )   CALL ctl_opn(     numout,        'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      ! open reference and configuration namelist files
+                  CALL ctl_opn( numnam_ref,        'namelist_ref',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+                  CALL ctl_opn( numnam_cfg,        'namelist_cfg',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      IF( lwm )   CALL ctl_opn(     numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      ! open /dev/null file to be able to supress output write easily
+                  CALL ctl_opn(     numnul,           '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      !
+      !                             !--------------------!
+      !                             ! Open listing units !  -> need ln_ctl from namctl to define lwp
+      !                             !--------------------!
       !
       REWIND( numnam_ref )              ! Namelist namctl in reference namelist
       READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
       READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
-      !
-      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
-      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
-      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
-      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
-
-      !                             !--------------------------!
-      !                             !  Set global domain size  !   (control print return in cltxt2)
-      !                             !--------------------------!
-      IF( ln_read_cfg ) THEN              ! Read sizes in domain configuration file
-         CALL domain_cfg ( cltxt2,        cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist' )
+      !
+      lwp = (narea == 1) .OR. ln_ctl    ! control of all listing output print
+      !
+      IF(lwp) THEN                            ! open listing units
          !
-      ELSE                                ! user-defined namelist
-         CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
-      ENDIF
-      !
-      l_offline = .true.                  ! passive tracers are run offline
-      !
-      !                             !--------------------------------------------!
-      !                             !  set communicator & select the local node  !
-      !                             !  NB: mynode also opens output.namelist.dyn !
-      !                             !      on unit number numond on first proc   !
-      !                             !--------------------------------------------!
-#if defined key_iomput
-      CALL  xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )
-      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection
-#else
-      ilocal_comm = 0
-      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )                ! Nodes selection (control print return in cltxt)
-#endif
-
-      narea = narea + 1                       ! mynode return the rank of proc (0 --> jpnij -1 )
-
+         IF( .NOT. lwm )   &           ! alreay opened for narea == 1
+            &     CALL ctl_opn(     numout,        'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE., narea )
+         !
+         WRITE(numout,*)
+         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - CMCC'
+         WRITE(numout,*) '                       NEMO team'
+         WRITE(numout,*) '                   Off-line TOP Model'
+         WRITE(numout,*) '                NEMO version 4.0  (2019) '
+         WRITE(numout,*)
+         WRITE(numout,*) "           ._      ._      ._      ._      ._    "
+         WRITE(numout,*) "       _.-._)`\_.-._)`\_.-._)`\_.-._)`\_.-._)`\_ "
+         WRITE(numout,*)
+         WRITE(numout,*) "           o         _,           _,             "
+         WRITE(numout,*) "            o      .' (        .-' /             "
+         WRITE(numout,*) "           o     _/..._'.    .'   /              "
+         WRITE(numout,*) "      (    o .-'`      ` '-./  _.'               "
+         WRITE(numout,*) "       )    ( o)           ;= <_         (       "
+         WRITE(numout,*) "      (      '-.,\\__ __.-;`\   '.        )      "
+         WRITE(numout,*) "       )  )       \) |`\ \)  '.   \      (   (   "
+         WRITE(numout,*) "      (  (           \_/       '-._\      )   )  "
+         WRITE(numout,*) "       )  )                        `     (   (   "
+         WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
+         WRITE(numout,*)
+         !
+         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
+         !
+      ENDIF
+      !
+      ! finalize the definition of namctl variables
       IF( sn_cfctl%l_config ) THEN
          ! Activate finer control of report outputs
@@ -226,61 +253,32 @@
          CALL nemo_set_cfctl( sn_cfctl, ln_ctl, .TRUE. )
       ENDIF
-
-      lwm = (narea == 1)                      ! control of output namelists
-      lwp = (narea == 1) .OR. ln_ctl          ! control of all listing output print
-
-      IF(lwm) THEN               ! write merged namelists from earlier to output namelist 
-         !                       ! now that the file has been opened in call to mynode. 
-         !                       ! NB: nammpp has already been written in mynode (if lk_mpp_mpi)
-         WRITE( numond, namctl )
-         WRITE( numond, namcfg )
-         IF( .NOT.ln_read_cfg ) THEN
-            DO ji = 1, SIZE(clnam)
-               IF( TRIM(clnam(ji)) /= '' )   WRITE(numond, * ) clnam(ji)     ! namusr_def print
-            END DO
-         ENDIF
-      ENDIF
-
-      IF(lwp) THEN                            ! open listing units
-         !
-         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
-         !
-         WRITE(numout,*)
-         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
-         WRITE(numout,*) '                       NEMO team'
-         WRITE(numout,*) '                   Off-line TOP Model'
-         WRITE(numout,*) '                NEMO version 4.0  (2019) '
-         WRITE(numout,*)
-         WRITE(numout,*) "           ._      ._      ._      ._      ._    "
-         WRITE(numout,*) "       _.-._)`\_.-._)`\_.-._)`\_.-._)`\_.-._)`\_ "
-         WRITE(numout,*)
-         WRITE(numout,*) "           o         _,           _,             "
-         WRITE(numout,*) "            o      .' (        .-' /             "
-         WRITE(numout,*) "           o     _/..._'.    .'   /              "
-         WRITE(numout,*) "      (    o .-'`      ` '-./  _.'               "
-         WRITE(numout,*) "       )    ( o)           ;= <_         (       "
-         WRITE(numout,*) "      (      '-.,\\__ __.-;`\   '.        )      "
-         WRITE(numout,*) "       )  )       \) |`\ \)  '.   \      (   (   "
-         WRITE(numout,*) "      (  (           \_/       '-._\      )   )  "
-         WRITE(numout,*) "       )  )                        `     (   (   "
-         WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
-         WRITE(numout,*)
-         DO ji = 1, SIZE(cltxt)
-            IF( TRIM(cltxt (ji)) /= '' )   WRITE(numout,*) TRIM(cltxt(ji))    ! control print of mynode
-         END DO
-         WRITE(numout,*)
-         WRITE(numout,*)
-         DO ji = 1, SIZE(cltxt2)
-            IF( TRIM(cltxt2(ji)) /= '' )   WRITE(numout,*) TRIM(cltxt2(ji))   ! control print of domain size
-         END DO
-         !
-         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
-         !
-      ENDIF
-      ! open /dev/null file to be able to supress output write easily
-      CALL ctl_opn( numnul, '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
-      !
-      !                                      ! Domain decomposition
-      CALL mpp_init                          ! MPP
+      !
+      IF(lwm) WRITE( numond, namctl )
+      !
+      !                             !------------------------------------!
+      !                             !  Set global domain size parameters !
+      !                             !------------------------------------!
+      !     
+      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
+      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist' )
+      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
+      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist' )   
+      !
+      IF( ln_read_cfg ) THEN              ! Read sizes in domain configuration file
+         CALL domain_cfg ( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
+      ELSE                                ! user-defined namelist
+         CALL usr_def_nam( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
+      ENDIF
+      !
+      IF(lwm)   WRITE( numond, namcfg )
+      l_offline = .true.                  ! passive tracers are run offline
+      !
+      !                             !-----------------------------------------!
+      !                             ! mpp parameters and domain decomposition !
+      !                             !-----------------------------------------!
+      !
+      CALL mpp_init
 
       ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
Index: /NEMO/trunk/src/SAO/nemogcm.F90
===================================================================
--- /NEMO/trunk/src/SAO/nemogcm.F90	(revision 11535)
+++ /NEMO/trunk/src/SAO/nemogcm.F90	(revision 11536)
@@ -89,7 +89,5 @@
       !! ** Purpose :   initialization of the NEMO GCM
       !!----------------------------------------------------------------------
-      INTEGER ::   ji                 ! dummy loop indices
       INTEGER ::   ios, ilocal_comm   ! local integer
-      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
       !
       NAMELIST/namctl/ ln_ctl   , sn_cfctl, nn_print, nn_ictls, nn_ictle,   &
@@ -99,103 +97,68 @@
       !!----------------------------------------------------------------------
       !
-      cltxt  = ''
-      cltxt2 = ''
-      clnam  = ''  
       cxios_context = 'nemo'
       !
-      !                             ! Open reference namelist and configuration namelist files
-      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
-      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
-      !
-      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints
-      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
-      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
-      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
-      !
-      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints
-      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
-      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
-      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
-
-      !                             !--------------------------!
-      !                             !  Set global domain size  !   (control print return in cltxt2)
-      !                             !--------------------------!
-      IF( ln_read_cfg ) THEN              ! Read sizes in domain configuration file
-         CALL domain_cfg ( cltxt2,        cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
-         !
-      ELSE                                ! user-defined namelist
-         CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
-      ENDIF
-      !
-      !
-      !                             !--------------------------------------------!
-      !                             !  set communicator & select the local node  !
-      !                             !  NB: mynode also opens output.namelist.dyn !
-      !                             !      on unit number numond on first proc   !
-      !                             !--------------------------------------------!
+      !                             !-------------------------------------------------!
+      !                             !     set communicator & select the local rank    !
+      !                             !  must be done as soon as possible to get narea  !
+      !                             !-------------------------------------------------!
+      !
 #if defined key_iomput
       IF( Agrif_Root() ) THEN
          IF( lk_oasis ) THEN
-            CALL cpl_init( "oceanx", ilocal_comm )                     ! nemo local communicator given by oasis
-            CALL xios_initialize( "not used",local_comm=ilocal_comm )    ! send nemo communicator to xios
+            CALL cpl_init( "oceanx", ilocal_comm )                               ! nemo local communicator given by oasis
+            CALL xios_initialize( "not used"       , local_comm =ilocal_comm )   ! send nemo communicator to xios
          ELSE
-            CALL  xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
+            CALL xios_initialize( "for_xios_mpi_id", return_comm=ilocal_comm )   ! nemo local communicator given by xios
          ENDIF
       ENDIF
-      ! Nodes selection (control print return in cltxt)
-      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
+      CALL mpp_start( ilocal_comm )
 #else
       IF( lk_oasis ) THEN
          IF( Agrif_Root() ) THEN
-            CALL cpl_init( "oceanx", ilocal_comm )                      ! nemo local communicator given by oasis
+            CALL cpl_init( "oceanx", ilocal_comm )          ! nemo local communicator given by oasis
          ENDIF
-         ! Nodes selection (control print return in cltxt)
-         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
+         CALL mpp_start( ilocal_comm )
       ELSE
-         ilocal_comm = 0                                    ! Nodes selection (control print return in cltxt)
-         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )
+         CALL mpp_start( )
       ENDIF
 #endif
-
-      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
-
-      IF( sn_cfctl%l_config ) THEN
-         ! Activate finer control of report outputs
-         ! optionally switch off output from selected areas (note this only
-         ! applies to output which does not involve global communications
-         IF( ( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax  ) .OR. &
-           & ( MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 ) )    &
-           &   CALL nemo_set_cfctl( sn_cfctl, .FALSE., .FALSE. )
-      ELSE
-         ! Use ln_ctl to turn on or off all options.
-         CALL nemo_set_cfctl( sn_cfctl, ln_ctl, .TRUE. )
-      ENDIF
-
-      lwm = (narea == 1)                                    ! control of output namelists
-      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
-
-      IF(lwm) THEN
-         ! write merged namelists from earlier to output namelist now that the
-         ! file has been opened in call to mynode. nammpp has already been
-         ! written in mynode (if lk_mpp_mpi)
-         WRITE( numond, namctl )
-         WRITE( numond, namcfg )
-         IF( .NOT.ln_read_cfg ) THEN
-            DO ji = 1, SIZE(clnam)
-               IF( TRIM(clnam(ji)) /= '' )   WRITE(numond, * ) clnam(ji)     ! namusr_def print
-            END DO
-         ENDIF
-      ENDIF
-
-      IF(lwp) THEN                            ! open listing units
-         !
-         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
-         !
-         WRITE(numout,*)
-         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
+      !
+      narea = mpprank + 1               ! mpprank: the rank of proc (0 --> mppsize -1 )
+      lwm = (narea == 1)                ! control of output namelists
+      !
+      !                             !---------------------------------------------------------------!
+      !                             ! Open output files, reference and configuration namelist files !
+      !                             !---------------------------------------------------------------!
+      !
+      ! open ocean.output as soon as possible to get all output prints (including errors messages)
+      IF( lwm )   CALL ctl_opn(     numout,        'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      ! open reference and configuration namelist files
+                  CALL ctl_opn( numnam_ref,        'namelist_ref',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+                  CALL ctl_opn( numnam_cfg,        'namelist_cfg',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      IF( lwm )   CALL ctl_opn(     numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      ! open /dev/null file to be able to supress output write easily
+                  CALL ctl_opn(     numnul,           '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      !
+      !                             !--------------------!
+      !                             ! Open listing units !  -> need ln_ctl from namctl to define lwp
+      !                             !--------------------!
+      !
+      REWIND( numnam_ref )              ! Namelist namctl in reference namelist
+      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist' )
+      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
+      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist' )
+      !
+      lwp = (narea == 1) .OR. ln_ctl    ! control of all listing output print
+      !
+      IF(lwp) THEN                      ! open listing units
+         !
+         IF( .NOT. lwm )   &            ! alreay opened for narea == 1
+            &            CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE., narea )
+         !
+         WRITE(numout,*)
+         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - CMCC'
          WRITE(numout,*) '                       NEMO team'
          WRITE(numout,*) '            Stand Alone Observation operator'
@@ -213,21 +176,50 @@
          WRITE(numout,*) "       )  )       \) |`\ \)  '.   \      (   (   "
          WRITE(numout,*) "      (  (           \_/       '-._\      )   )  "
-         WRITE(numout,*) "       )  )                        `     (   (   "
+         WRITE(numout,*) "       )  ) jgs                     `    (   (   "
          WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
          WRITE(numout,*)
-         DO ji = 1, SIZE(cltxt)
-            IF( TRIM(cltxt (ji)) /= '' )   WRITE(numout,*) TRIM(cltxt(ji))    ! control print of mynode
-         END DO
-         WRITE(numout,*)
-         WRITE(numout,*)
-         DO ji = 1, SIZE(cltxt2)
-            IF( TRIM(cltxt2(ji)) /= '' )   WRITE(numout,*) TRIM(cltxt2(ji))   ! control print of domain size
-         END DO
          !
          WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
          !
       ENDIF
-      !                                      ! Domain decomposition
-      CALL mpp_init                          ! MPP
+      !
+      ! finalize the definition of namctl variables
+      IF( sn_cfctl%l_config ) THEN
+         ! Activate finer control of report outputs
+         ! optionally switch off output from selected areas (note this only
+         ! applies to output which does not involve global communications)
+         IF( ( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax  ) .OR. &
+           & ( MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 ) )    &
+           &   CALL nemo_set_cfctl( sn_cfctl, .FALSE., .FALSE. )
+      ELSE
+         ! Use ln_ctl to turn on or off all options.
+         CALL nemo_set_cfctl( sn_cfctl, ln_ctl, .TRUE. )
+      ENDIF
+      !
+      IF(lwm) WRITE( numond, namctl )
+      !
+      !                             !------------------------------------!
+      !                             !  Set global domain size parameters !
+      !                             !------------------------------------!
+      !
+      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
+      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist' )
+      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
+      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist' )   
+      !
+      IF( ln_read_cfg ) THEN            ! Read sizes in domain configuration file
+         CALL domain_cfg ( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
+      ELSE                              ! user-defined namelist
+         CALL usr_def_nam( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
+      ENDIF
+      !
+      IF(lwm)   WRITE( numond, namcfg )
+      !
+      !                             !-----------------------------------------!
+      !                             ! mpp parameters and domain decomposition !
+      !                             !-----------------------------------------!
+      CALL mpp_init
 
       ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
Index: /NEMO/trunk/src/SAO/sao_data.F90
===================================================================
--- /NEMO/trunk/src/SAO/sao_data.F90	(revision 11535)
+++ /NEMO/trunk/src/SAO/sao_data.F90	(revision 11536)
@@ -54,8 +54,8 @@
       REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints & Benchmark
       READ  ( numnam_ref, namsao, IOSTAT = ios, ERR = 901 )
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsao in reference namelist', .TRUE. )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsao in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
       READ  ( numnam_cfg, namsao, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsao in configuration namelist', .TRUE. )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsao in configuration namelist' )
      
       lmask(:) = .FALSE.               ! count input files
Index: /NEMO/trunk/src/SAS/diawri.F90
===================================================================
--- /NEMO/trunk/src/SAS/diawri.F90	(revision 11535)
+++ /NEMO/trunk/src/SAS/diawri.F90	(revision 11536)
@@ -125,5 +125,5 @@
       !!      define all the NETCDF files and fields
       !!      At each time step call histdef to compute the mean if ncessary
-      !!      Each nwrite time step, output the instantaneous or mean fields
+      !!      Each nn_write time step, output the instantaneous or mean fields
       !!----------------------------------------------------------------------
       !!
@@ -138,6 +138,4 @@
       REAL(wp) ::   zsto, zout, zmax, zjulian                ! local scalars
       !!----------------------------------------------------------------------
-      ! 
-      IF( ln_timing )   CALL timing_start('dia_wri')
       !
       ! Output the initial state and forcings
@@ -147,4 +145,8 @@
       ENDIF
       !
+      IF( nn_write == -1 )   RETURN   ! we will never do any output
+      ! 
+      IF( ln_timing )   CALL timing_start('dia_wri')
+      !
       ! 0. Initialisation
       ! -----------------
@@ -159,5 +161,5 @@
       ENDIF
 #if defined key_diainstant
-      zsto = nwrite * rdt
+      zsto = nn_write * rdt
       clop = "inst("//TRIM(clop)//")"
 #else
@@ -165,5 +167,5 @@
       clop = "ave("//TRIM(clop)//")"
 #endif
-      zout = nwrite * rdt
+      zout = nn_write * rdt
       zmax = ( nitend - nit000 + 1 ) * rdt
 
@@ -196,5 +198,5 @@
          ! WRITE root name in date.file for use by postpro
          IF(lwp) THEN
-            CALL dia_nam( clhstnam, nwrite,' ' )
+            CALL dia_nam( clhstnam, nn_write,' ' )
             CALL ctl_opn( inum, 'date.file', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
             WRITE(inum,*) clhstnam
@@ -204,5 +206,5 @@
          ! Define the T grid FILE ( nid_T )
 
-         CALL dia_nam( clhstnam, nwrite, 'grid_T' )
+         CALL dia_nam( clhstnam, nn_write, 'grid_T' )
          IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
@@ -216,5 +218,5 @@
          ! Define the U grid FILE ( nid_U )
 
-         CALL dia_nam( clhstnam, nwrite, 'grid_U' )
+         CALL dia_nam( clhstnam, nn_write, 'grid_U' )
          IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
          CALL histbeg( clhstnam, jpi, glamu, jpj, gphiu,           &  ! Horizontal grid: glamu and gphiu
@@ -228,5 +230,5 @@
          ! Define the V grid FILE ( nid_V )
 
-         CALL dia_nam( clhstnam, nwrite, 'grid_V' )                   ! filename
+         CALL dia_nam( clhstnam, nn_write, 'grid_V' )                   ! filename
          IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
          CALL histbeg( clhstnam, jpi, glamv, jpj, gphiv,           &  ! Horizontal grid: glamv and gphiv
@@ -291,5 +293,5 @@
       ! donne le nombre d'elements, et ndex la liste des indices a sortir
 
-      IF( lwp .AND. MOD( itmod, nwrite ) == 0 ) THEN 
+      IF( lwp .AND. MOD( itmod, nn_write ) == 0 ) THEN 
          WRITE(numout,*) 'dia_wri : write model outputs in NetCDF files at ', kt, 'time-step'
          WRITE(numout,*) '~~~~~~ '
Index: /NEMO/trunk/src/SAS/nemogcm.F90
===================================================================
--- /NEMO/trunk/src/SAS/nemogcm.F90	(revision 11535)
+++ /NEMO/trunk/src/SAS/nemogcm.F90	(revision 11536)
@@ -151,7 +151,6 @@
       !
       IF( nstop /= 0 .AND. lwp ) THEN        ! error print
-         WRITE(numout,cform_err)
-         WRITE(numout,*) '   ==>>>   nemo_gcm: a total of ', nstop, ' errors have been found'
-         WRITE(numout,*)
+         WRITE(ctmp1,*) '   ==>>>   nemo_gcm: a total of ', nstop, ' errors have been found'
+         CALL ctl_stop( ctmp1 )
       ENDIF
       !
@@ -165,5 +164,5 @@
 #else
       IF    ( lk_oasis ) THEN   ;   CALL cpl_finalize   ! end coupling and mpp communications with OASIS
-      ELSEIF( lk_mpp   ) THEN   ;   CALL mppstop( ldfinal = .TRUE. )   ! end mpp communications
+      ELSEIF( lk_mpp   ) THEN   ;   CALL mppstop        ! end mpp communications
       ENDIF
 #endif
@@ -171,5 +170,5 @@
       IF(lwm) THEN
          IF( nstop == 0 ) THEN   ;   STOP 0
-         ELSE                    ;   STOP 999
+         ELSE                    ;   STOP 123
          ENDIF
       ENDIF
@@ -184,8 +183,5 @@
       !! ** Purpose :   initialization of the NEMO GCM
       !!----------------------------------------------------------------------
-      INTEGER  ::   ji                 ! dummy loop indices
-      INTEGER  ::   ios, ilocal_comm   ! local integers
-      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
-      CHARACTER(len=80)                 ::   clname
+      INTEGER ::   ios, ilocal_comm   ! local integers
       !!
       NAMELIST/namctl/ ln_ctl   , sn_cfctl, nn_print, nn_ictls, nn_ictle,   &
@@ -195,111 +191,81 @@
       !!----------------------------------------------------------------------
       !
-      cltxt  = ''
-      cltxt2 = ''
-      clnam  = ''  
-      cxios_context = 'nemo'
-      !
-      !                             ! Open reference namelist and configuration namelist files
-      IF( lk_oasis ) THEN 
-         CALL ctl_opn( numnam_ref, 'namelist_sas_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
-         CALL ctl_opn( numnam_cfg, 'namelist_sas_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
-         cxios_context = 'sas'
-         clname = 'output.namelist_sas.dyn'
-      ELSE
-         CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
-         CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
-         cxios_context = 'nemo'
-         clname = 'output.namelist.dyn'
-   ENDIF
-      !
-      REWIND( numnam_ref )              ! Namelist namctl in reference namelist
-      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
-      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
-      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
-      !
-      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
-      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
-      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
-      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
-
-      !                             !--------------------------!
-      !                             !  Set global domain size  !   (control print return in cltxt2)
-      !                             !--------------------------!
-      IF( ln_read_cfg ) THEN              ! Read sizes in domain configuration file
-         CALL domain_cfg ( cltxt2,        cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
-         !
-      ELSE                                ! user-defined namelist
-         CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
-      ENDIF
-      !
-      !
-      !                             !--------------------------------------------!
-      !                             !  set communicator & select the local node  !
-      !                             !  NB: mynode also opens output.namelist.dyn !
-      !                             !      on unit number numond on first proc   !
-      !                             !--------------------------------------------!
+      IF( lk_oasis ) THEN   ;   cxios_context = 'sas'
+      ELSE                  ;   cxios_context = 'nemo'
+      ENDIF
+      !
+      !                             !-------------------------------------------------!
+      !                             !     set communicator & select the local rank    !
+      !                             !  must be done as soon as possible to get narea  !
+      !                             !-------------------------------------------------!
+      !
 #if defined key_iomput
       IF( Agrif_Root() ) THEN
          IF( lk_oasis ) THEN
-            CALL cpl_init( "sas", ilocal_comm )                          ! nemo local communicator given by oasis 
-            CALL xios_initialize( "not used",local_comm=ilocal_comm )    ! send nemo communicator to xios
+            CALL cpl_init( "sas", ilocal_comm )                                  ! nemo local communicator given by oasis 
+            CALL xios_initialize( "not used",local_comm=ilocal_comm )            ! send nemo communicator to xios
          ELSE
             CALL xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
          ENDIF
       ENDIF
-      narea = mynode ( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )  ! Nodes selection
+      CALL mpp_start( ilocal_comm )
 #else
       IF( lk_oasis ) THEN
          IF( Agrif_Root() ) THEN
-            CALL cpl_init( "sas", ilocal_comm )                          ! nemo local communicator given by oasis
+            CALL cpl_init( "sas", ilocal_comm )             ! nemo local communicator given by oasis
          ENDIF
-         narea = mynode( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
+         CALL mpp_start( ilocal_comm )
       ELSE
-         ilocal_comm = 0
-         narea = mynode( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop )                ! Nodes selection (control print return in cltxt)
-      ENDIF
-#endif
-
-      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
-
-      IF( sn_cfctl%l_config ) THEN
-         ! Activate finer control of report outputs
-         ! optionally switch off output from selected areas (note this only
-         ! applies to output which does not involve global communications)
-         IF( ( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax  ) .OR. &
-           & ( MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 ) )    &
-           &   CALL nemo_set_cfctl( sn_cfctl, .FALSE., .FALSE. )
+         CALL mpp_start( )
+      ENDIF
+#endif
+      !
+      narea = mpprank + 1                                   ! mpprank: the rank of proc (0 --> mppsize -1 )
+      lwm = (narea == 1)                ! control of output namelists
+      !
+      !                             !---------------------------------------------------------------!
+      !                             ! Open output files, reference and configuration namelist files !
+      !                             !---------------------------------------------------------------!
+      !
+      ! open ocean.output as soon as possible to get all output prints (including errors messages)
+      IF( lk_oasis ) THEN
+         IF( lwm )   CALL ctl_opn(     numout,              'sas.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+         ! open reference and configuration namelist files
+                     CALL ctl_opn( numnam_ref,        'namelist_sas_ref',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+                     CALL ctl_opn( numnam_cfg,        'namelist_sas_cfg',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+         IF( lwm )   CALL ctl_opn(     numond, 'output.namelist_sas.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
       ELSE
-         ! Use ln_ctl to turn on or off all options.
-         CALL nemo_set_cfctl( sn_cfctl, ln_ctl, .TRUE. )
-      ENDIF
-
-      lwm = (narea == 1)                                    ! control of output namelists
-      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
-
-      IF(lwm) THEN               ! write merged namelists from earlier to output namelist 
-         !                       ! now that the file has been opened in call to mynode. 
-         !                       ! NB: nammpp has already been written in mynode (if lk_mpp_mpi)
-         WRITE( numond, namctl )
-         WRITE( numond, namcfg )
-         IF( .NOT.ln_read_cfg ) THEN
-            DO ji = 1, SIZE(clnam)
-               IF( TRIM(clnam(ji)) /= '' )   WRITE(numond, * ) clnam(ji)     ! namusr_def print
-            END DO
+         IF( lwm )   CALL ctl_opn(     numout,            'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+         ! open reference and configuration namelist files
+                     CALL ctl_opn( numnam_ref,            'namelist_ref',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+                     CALL ctl_opn( numnam_cfg,            'namelist_cfg',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+         IF( lwm )   CALL ctl_opn(     numond,     'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      ENDIF
+      ! open /dev/null file to be able to supress output write easily
+                     CALL ctl_opn(     numnul,               '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+      !
+      !                             !--------------------!
+      !                             ! Open listing units !  -> need ln_ctl from namctl to define lwp
+      !                             !--------------------!
+      !
+      REWIND( numnam_ref )              ! Namelist namctl in reference namelist
+      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist' )
+      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
+      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist' )
+      !
+      lwp = (narea == 1) .OR. ln_ctl    ! control of all listing output print
+      !
+      IF(lwp) THEN                      ! open listing units
+         !
+         IF( .NOT. lwm ) THEN           ! alreay opened for narea == 1
+            IF(lk_oasis) THEN   ;   CALL ctl_opn( numout,   'sas.output','REPLACE','FORMATTED','SEQUENTIAL',-1,-1, .FALSE., narea )
+            ELSE                ;   CALL ctl_opn( numout, 'ocean.output','REPLACE','FORMATTED','SEQUENTIAL',-1,-1, .FALSE., narea )
+            ENDIF
          ENDIF
-      ENDIF
-
-      IF(lwp) THEN                            ! open listing units
-         !
-         IF( lk_oasis ) THEN   ;   CALL ctl_opn( numout,   'sas.output', 'REPLACE','FORMATTED','SEQUENTIAL', -1, 6, .FALSE., narea )
-         ELSE                  ;   CALL ctl_opn( numout, 'ocean.output', 'REPLACE','FORMATTED','SEQUENTIAL', -1, 6, .FALSE., narea )
-         ENDIF
          !
          WRITE(numout,*)
-         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
+         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - CMCC'
          WRITE(numout,*) '                       NEMO team'
          WRITE(numout,*) '            Ocean General Circulation Model'
@@ -320,22 +286,48 @@
          WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
          WRITE(numout,*)
-
-         DO ji = 1, SIZE(cltxt)
-            IF( TRIM(cltxt (ji)) /= '' )   WRITE(numout,*) TRIM(cltxt(ji))    ! control print of mynode
-         END DO
          WRITE(numout,*)
-         WRITE(numout,*)
-         DO ji = 1, SIZE(cltxt2)
-            IF( TRIM(cltxt2(ji)) /= '' )   WRITE(numout,*) TRIM(cltxt2(ji))   ! control print of domain size
-         END DO
          !
          WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
          !
       ENDIF
-      ! open /dev/null file to be able to supress output write easily
-      CALL ctl_opn( numnul, '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
-      !
-      !                                      ! Domain decomposition
-      CALL mpp_init                          ! MPP
+     !
+      ! finalize the definition of namctl variables
+      IF( sn_cfctl%l_config ) THEN
+         ! Activate finer control of report outputs
+         ! optionally switch off output from selected areas (note this only
+         ! applies to output which does not involve global communications)
+         IF( ( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax  ) .OR. &
+           & ( MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 ) )    &
+           &   CALL nemo_set_cfctl( sn_cfctl, .FALSE., .FALSE. )
+      ELSE
+         ! Use ln_ctl to turn on or off all options.
+         CALL nemo_set_cfctl( sn_cfctl, ln_ctl, .TRUE. )
+      ENDIF
+      !
+      IF(lwm) WRITE( numond, namctl )
+      !
+      !                             !------------------------------------!
+      !                             !  Set global domain size parameters !
+      !                             !------------------------------------!
+      !
+      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
+      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist' )
+      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
+      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist' )   
+      !
+      IF( ln_read_cfg ) THEN            ! Read sizes in domain configuration file
+         CALL domain_cfg ( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
+      ELSE                              ! user-defined namelist
+         CALL usr_def_nam( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
+      ENDIF
+      !
+      IF(lwm)   WRITE( numond, namcfg )
+      !
+      !                             !-----------------------------------------!
+      !                             ! mpp parameters and domain decomposition !
+      !                             !-----------------------------------------!
+      CALL mpp_init
 
       ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
Index: /NEMO/trunk/src/SAS/sbcssm.F90
===================================================================
--- /NEMO/trunk/src/SAS/sbcssm.F90	(revision 11535)
+++ /NEMO/trunk/src/SAS/sbcssm.F90	(revision 11536)
@@ -188,8 +188,8 @@
       REWIND( numnam_ref )              ! Namelist namsbc_sas in reference namelist : Input fields
       READ  ( numnam_ref, namsbc_sas, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_sas in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_sas in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist namsbc_sas in configuration namelist : Input fields
       READ  ( numnam_cfg, namsbc_sas, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_sas in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_sas in configuration namelist' )
       IF(lwm) WRITE ( numond, namsbc_sas )
       !           
Index: /NEMO/trunk/src/SAS/step.F90
===================================================================
--- /NEMO/trunk/src/SAS/step.F90	(revision 11535)
+++ /NEMO/trunk/src/SAS/step.F90	(revision 11536)
@@ -96,5 +96,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( ln_bdy     )       CALL bdy_dta ( kstp, time_offset=+1 )   ! update dynamic & tracer data at open boundaries
+      IF( ln_bdy     )       CALL bdy_dta ( kstp, kt_offset=+1 )   ! update dynamic & tracer data at open boundaries
       ! ==>
                              CALL sbc    ( kstp )         ! Sea Boundary Condition (including sea-ice)
Index: /NEMO/trunk/src/TOP/AGE/trcnam_age.F90
===================================================================
--- /NEMO/trunk/src/TOP/AGE/trcnam_age.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/AGE/trcnam_age.F90	(revision 11536)
@@ -56,8 +56,8 @@
       REWIND( numnat_ref )              ! Namelist namagedate in reference namelist : AGE parameters
       READ  ( numnat_ref, namage, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namage in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namage in reference namelist' )
       REWIND( numnat_cfg )              ! Namelist namagedate in configuration namelist : AGE parameters
       READ  ( numnat_cfg, namage, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namage in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namage in configuration namelist' )
       IF(lwm) WRITE ( numont, namage )
       !
Index: /NEMO/trunk/src/TOP/C14/trcnam_c14.F90
===================================================================
--- /NEMO/trunk/src/TOP/C14/trcnam_c14.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/C14/trcnam_c14.F90	(revision 11536)
@@ -63,8 +63,8 @@
       REWIND( numtrc_ref )              ! Namelist namc14_typ in reference namelist :
       READ  ( numtrc_ref, namc14_typ, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc14_typ in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc14_typ in reference namelist' )
       REWIND( numtrc_cfg )              ! Namelist namcfcdate in configuration namelist 
       READ  ( numtrc_cfg, namc14_typ, IOSTAT = ios, ERR = 902)
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc14_typ in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc14_typ in configuration namelist' )
       IF(lwm) WRITE ( numonr, namc14_typ )
       !
@@ -80,8 +80,8 @@
       REWIND( numtrc_ref )              ! Namelist namc14_typ in reference namelist :
       READ  ( numtrc_ref, namc14_sbc, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc14_sbc in reference namelist', lwp )
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc14_sbc in reference namelist' )
       REWIND( numtrc_cfg )              ! Namelist namcfcdate in configuration namelist 
       READ  ( numtrc_cfg, namc14_sbc, IOSTAT = ios, ERR = 904)
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc14_sbc in configuration namelist', lwp )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc14_sbc in configuration namelist' )
       IF(lwm) WRITE( numonr, namc14_sbc )
       !
@@ -96,8 +96,8 @@
       REWIND( numtrc_ref )              ! Namelist namc14_typ in reference namelist :
       READ  ( numtrc_ref, namc14_fcg, IOSTAT = ios, ERR = 905)
-905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc14_fcg in reference namelist', lwp )
+905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc14_fcg in reference namelist' )
       REWIND( numtrc_cfg )              ! Namelist namcfcdate in configuration namelist 
       READ  ( numtrc_cfg, namc14_fcg, IOSTAT = ios, ERR = 906)
-906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc14_fcg in configuration namelist', lwp )
+906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc14_fcg in configuration namelist' )
       IF(lwm) WRITE ( numonr, namc14_fcg )
       !
Index: /NEMO/trunk/src/TOP/CFC/trcnam_cfc.F90
===================================================================
--- /NEMO/trunk/src/TOP/CFC/trcnam_cfc.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/CFC/trcnam_cfc.F90	(revision 11536)
@@ -53,8 +53,8 @@
       REWIND( numtrc_ref )              ! Namelist namcfcdate in reference namelist : CFC parameters
       READ  ( numtrc_ref, namcfc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfc in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfc in reference namelist' )
       REWIND( numtrc_cfg )              ! Namelist namcfcdate in configuration namelist : CFC parameters
       READ  ( numtrc_cfg, namcfc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfc in configuration namelist' )
       IF(lwm) WRITE( numonr, namcfc )
       IF(lwm) CALL FLUSH ( numonr )     ! flush output namelist CFC
Index: /NEMO/trunk/src/TOP/PISCES/P2Z/p2zbio.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P2Z/p2zbio.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P2Z/p2zbio.F90	(revision 11536)
@@ -404,8 +404,8 @@
       REWIND( numnatp_ref )              ! Namelist namlobphy in reference namelist : Lobster biological parameters
       READ  ( numnatp_ref, namlobphy, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobphy in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobphy in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist namlobphy in configuration namelist : Lobster biological parameters
       READ  ( numnatp_cfg, namlobphy, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobphy in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobphy in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobphy )
       !
@@ -421,8 +421,8 @@
       REWIND( numnatp_ref )              ! Namelist namlobnut in reference namelist : Lobster nutriments parameters
       READ  ( numnatp_ref, namlobnut, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobnut in reference namelist', lwp )
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobnut in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist namlobnut in configuration namelist : Lobster nutriments parameters
       READ  ( numnatp_cfg, namlobnut, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobnut in configuration namelist', lwp )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobnut in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobnut )
 
@@ -438,8 +438,8 @@
       REWIND( numnatp_ref )              ! Namelist namlobzoo in reference namelist : Lobster zooplankton parameters
       READ  ( numnatp_ref, namlobzoo, IOSTAT = ios, ERR = 905)
-905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobzoo in reference namelist', lwp )
+905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobzoo in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist namlobzoo in configuration namelist : Lobster zooplankton parameters
       READ  ( numnatp_cfg, namlobzoo, IOSTAT = ios, ERR = 906 )
-906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobzoo in configuration namelist', lwp )
+906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobzoo in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobzoo )
 
@@ -460,8 +460,8 @@
       REWIND( numnatp_ref )              ! Namelist namlobdet in reference namelist : Lobster detritus parameters
       READ  ( numnatp_ref, namlobdet, IOSTAT = ios, ERR = 907)
-907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobdet in reference namelist', lwp )
+907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobdet in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist namlobdet in configuration namelist : Lobster detritus parameters
       READ  ( numnatp_cfg, namlobdet, IOSTAT = ios, ERR = 908 )
-908   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobdet in configuration namelist', lwp )
+908   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobdet in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobdet )
 
@@ -475,8 +475,8 @@
       REWIND( numnatp_ref )              ! Namelist namlobdom in reference namelist : Lobster DOM breakdown rate
       READ  ( numnatp_ref, namlobdom, IOSTAT = ios, ERR = 909)
-909   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobdom in reference namelist', lwp )
+909   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobdom in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist namlobdom in configuration namelist : Lobster DOM breakdown rate
       READ  ( numnatp_cfg, namlobdom, IOSTAT = ios, ERR = 910 )
-910   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobdom in configuration namelist', lwp )
+910   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobdom in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobdom )
 
Index: /NEMO/trunk/src/TOP/PISCES/P2Z/p2zopt.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P2Z/p2zopt.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P2Z/p2zopt.F90	(revision 11536)
@@ -161,9 +161,9 @@
       REWIND( numnatp_ref )              ! Namelist namlobopt in reference namelist : Lobster options
       READ  ( numnatp_ref, namlobopt, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namlobopt in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namlobopt in reference namelist' )
 
       REWIND( numnatp_cfg )              ! Namelist namlobopt in configuration namelist : Lobster options
       READ  ( numnatp_cfg, namlobopt, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namlobopt in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namlobopt in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobopt )
 
@@ -183,9 +183,9 @@
       REWIND( numnatp_ref )              ! Namelist namlobrat in reference namelist : Lobster ratios
       READ  ( numnatp_ref, namlobrat, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namlobrat in reference namelist', lwp )
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namlobrat in reference namelist' )
 
       REWIND( numnatp_cfg )              ! Namelist namlobrat in configuration namelist : Lobster ratios
       READ  ( numnatp_cfg, namlobrat, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 ) CALL ctl_nam ( ios , 'namlobrat in configuration namelist', lwp )
+904   IF( ios >  0 ) CALL ctl_nam ( ios , 'namlobrat in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobrat )
 
Index: /NEMO/trunk/src/TOP/PISCES/P2Z/p2zsed.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P2Z/p2zsed.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P2Z/p2zsed.F90	(revision 11536)
@@ -134,8 +134,8 @@
       REWIND( numnatp_ref )              ! Namelist namlobsed in reference namelist : Lobster sediments
       READ  ( numnatp_ref, namlobsed, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlosed in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlosed in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist namlobsed in configuration namelist : Lobster sediments
       READ  ( numnatp_cfg, namlobsed, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobsed in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobsed in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobsed )
       !
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zfechem.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zfechem.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zfechem.F90	(revision 11536)
@@ -256,8 +256,8 @@
       REWIND( numnatp_ref )            ! Namelist nampisfer in reference namelist : Pisces iron chemistry
       READ  ( numnatp_ref, nampisfer, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisfer in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisfer in reference namelist' )
       REWIND( numnatp_cfg )            ! Namelist nampisfer in configuration namelist : Pisces iron chemistry
       READ  ( numnatp_cfg, nampisfer, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisfer in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisfer in configuration namelist' )
       IF(lwm) WRITE( numonp, nampisfer )
 
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zflx.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zflx.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zflx.F90	(revision 11536)
@@ -241,8 +241,8 @@
       REWIND( numnatp_ref )              ! Namelist nampisext in reference namelist : Pisces atm. conditions
       READ  ( numnatp_ref, nampisext, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisext in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisext in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampisext in configuration namelist : Pisces atm. conditions
       READ  ( numnatp_cfg, nampisext, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisext in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisext in configuration namelist' )
       IF(lwm) WRITE ( numonp, nampisext )
       !
@@ -322,8 +322,8 @@
          REWIND( numnatp_ref )              ! Namelist nampisatm in reference namelist : Pisces atm. sea level pressure file
          READ  ( numnatp_ref, nampisatm, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisatm in reference namelist', lwp )
+901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisatm in reference namelist' )
          REWIND( numnatp_cfg )              ! Namelist nampisatm in configuration namelist : Pisces atm. sea level pressure file 
          READ  ( numnatp_cfg, nampisatm, IOSTAT = ios, ERR = 902 )
-902      IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisatm in configuration namelist', lwp )
+902      IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisatm in configuration namelist' )
          IF(lwm) WRITE ( numonp, nampisatm )
          !
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zligand.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zligand.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zligand.F90	(revision 11536)
@@ -127,8 +127,8 @@
       REWIND( numnatp_ref )              ! Namelist nampislig in reference namelist : Pisces remineralization
       READ  ( numnatp_ref, nampislig, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampislig in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampislig in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampislig in configuration namelist : Pisces remineralization
       READ  ( numnatp_cfg, nampislig, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampislig in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampislig in configuration namelist' )
       IF(lwm) WRITE ( numonp, nampislig )
       !
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zlim.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zlim.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zlim.F90	(revision 11536)
@@ -254,8 +254,8 @@
       REWIND( numnatp_ref )              ! Namelist nampislim in reference namelist : Pisces nutrient limitation parameters
       READ  ( numnatp_ref, namp4zlim, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zlim in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zlim in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampislim in configuration namelist : Pisces nutrient limitation parameters 
       READ  ( numnatp_cfg, namp4zlim, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zlim in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zlim in configuration namelist' )
       IF(lwm) WRITE( numonp, namp4zlim )
       !
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zlys.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zlys.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zlys.F90	(revision 11536)
@@ -164,8 +164,8 @@
       REWIND( numnatp_ref )              ! Namelist nampiscal in reference namelist : Pisces CaCO3 dissolution
       READ  ( numnatp_ref, nampiscal, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampiscal in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampiscal in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampiscal in configuration namelist : Pisces CaCO3 dissolution
       READ  ( numnatp_cfg, nampiscal, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampiscal in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampiscal in configuration namelist' )
       IF(lwm) WRITE( numonp, nampiscal )
       !
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zmeso.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zmeso.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zmeso.F90	(revision 11536)
@@ -292,8 +292,8 @@
       REWIND( numnatp_ref )              ! Namelist nampismes in reference namelist : Pisces mesozooplankton
       READ  ( numnatp_ref, namp4zmes, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zmes in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zmes in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampismes in configuration namelist : Pisces mesozooplankton
       READ  ( numnatp_cfg, namp4zmes, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zmes in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zmes in configuration namelist' )
       IF(lwm) WRITE( numonp, namp4zmes )
       !
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zmicro.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zmicro.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zmicro.F90	(revision 11536)
@@ -245,8 +245,8 @@
       REWIND( numnatp_ref )              ! Namelist nampiszoo in reference namelist : Pisces microzooplankton
       READ  ( numnatp_ref, namp4zzoo, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zzoo in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zzoo in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampiszoo in configuration namelist : Pisces microzooplankton
       READ  ( numnatp_cfg, namp4zzoo, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zzoo in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zzoo in configuration namelist' )
       IF(lwm) WRITE( numonp, namp4zzoo )
       !
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zmort.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zmort.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zmort.F90	(revision 11536)
@@ -229,8 +229,8 @@
       REWIND( numnatp_ref )              ! Namelist nampismort in reference namelist : Pisces phytoplankton
       READ  ( numnatp_ref, namp4zmort, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zmort in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zmort in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampismort in configuration namelist : Pisces phytoplankton
       READ  ( numnatp_cfg, namp4zmort, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zmort in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zmort in configuration namelist' )
       IF(lwm) WRITE( numonp, namp4zmort )
       !
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zopt.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zopt.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zopt.F90	(revision 11536)
@@ -402,8 +402,8 @@
       REWIND( numnatp_ref )              ! Namelist nampisopt in reference namelist : Pisces attenuation coef. and PAR
       READ  ( numnatp_ref, nampisopt, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisopt in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisopt in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampisopt in configuration namelist : Pisces attenuation coef. and PAR
       READ  ( numnatp_cfg, nampisopt, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisopt in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisopt in configuration namelist' )
       IF(lwm) WRITE ( numonp, nampisopt )
 
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zpoc.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zpoc.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zpoc.F90	(revision 11536)
@@ -499,8 +499,8 @@
       REWIND( numnatp_ref )              ! Namelist nampisrem in reference namelist : Pisces remineralization
       READ  ( numnatp_ref, nampispoc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampispoc in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampispoc in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampisrem in configuration namelist : Pisces remineralization
       READ  ( numnatp_cfg, nampispoc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampispoc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampispoc in configuration namelist' )
       IF(lwm) WRITE( numonp, nampispoc )
 
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zprod.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zprod.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zprod.F90	(revision 11536)
@@ -492,8 +492,8 @@
       REWIND( numnatp_ref )              ! Namelist nampisprod in reference namelist : Pisces phytoplankton production
       READ  ( numnatp_ref, namp4zprod, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zprod in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zprod in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampisprod in configuration namelist : Pisces phytoplankton production
       READ  ( numnatp_cfg, namp4zprod, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zprod in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zprod in configuration namelist' )
       IF(lwm) WRITE( numonp, namp4zprod )
 
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zrem.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zrem.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zrem.F90	(revision 11536)
@@ -329,8 +329,8 @@
       REWIND( numnatp_ref )              ! Namelist nampisrem in reference namelist : Pisces remineralization
       READ  ( numnatp_ref, nampisrem, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisrem in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisrem in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampisrem in configuration namelist : Pisces remineralization
       READ  ( numnatp_cfg, nampisrem, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisrem in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisrem in configuration namelist' )
       IF(lwm) WRITE( numonp, nampisrem )
 
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zsbc.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zsbc.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zsbc.F90	(revision 11536)
@@ -232,8 +232,8 @@
       REWIND( numnatp_ref )              ! Namelist nampissbc in reference namelist : Pisces external sources of nutrients
       READ  ( numnatp_ref, nampissbc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampissbc in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampissbc in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampissbc in configuration namelist : Pisces external sources of nutrients
       READ  ( numnatp_cfg, nampissbc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampissbc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampissbc in configuration namelist' )
       IF(lwm) WRITE ( numonp, nampissbc )
 
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p4zsms.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p4zsms.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p4zsms.F90	(revision 11536)
@@ -203,8 +203,8 @@
       REWIND( numnatp_ref )              ! Namelist nampisbio in reference namelist : Pisces variables
       READ  ( numnatp_ref, nampisbio, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisbio in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisbio in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampisbio in configuration namelist : Pisces variables
       READ  ( numnatp_cfg, nampisbio, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisbio in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisbio in configuration namelist' )
       IF(lwm) WRITE( numonp, nampisbio )
       !
@@ -234,8 +234,8 @@
       REWIND( numnatp_ref )              ! Namelist nampisdmp in reference namelist : Pisces damping
       READ  ( numnatp_ref, nampisdmp, IOSTAT = ios, ERR = 905)
-905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisdmp in reference namelist', lwp )
+905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisdmp in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampisdmp in configuration namelist : Pisces damping
       READ  ( numnatp_cfg, nampisdmp, IOSTAT = ios, ERR = 906 )
-906   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisdmp in configuration namelist', lwp )
+906   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisdmp in configuration namelist' )
       IF(lwm) WRITE( numonp, nampisdmp )
       !
@@ -249,8 +249,8 @@
       REWIND( numnatp_ref )              ! Namelist nampismass in reference namelist : Pisces mass conservation check
       READ  ( numnatp_ref, nampismass, IOSTAT = ios, ERR = 907)
-907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampismass in reference namelist', lwp )
+907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampismass in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampismass in configuration namelist : Pisces mass conservation check 
       READ  ( numnatp_cfg, nampismass, IOSTAT = ios, ERR = 908 )
-908   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampismass in configuration namelist', lwp )
+908   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampismass in configuration namelist' )
       IF(lwm) WRITE( numonp, nampismass )
 
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p5zlim.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p5zlim.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p5zlim.F90	(revision 11536)
@@ -450,9 +450,9 @@
       REWIND( numnatp_ref )              ! Namelist nampislim in reference namelist : Pisces nutrient limitation parameters
       READ  ( numnatp_ref, namp5zlim, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampislim in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampislim in reference namelist' )
       !
       REWIND( numnatp_cfg )              ! Namelist nampislim in configuration namelist : Pisces nutrient limitation parameters 
       READ  ( numnatp_cfg, namp5zlim, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampislim in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampislim in configuration namelist' )
       IF(lwm) WRITE ( numonp, namp5zlim )
       !
@@ -491,9 +491,9 @@
       REWIND( numnatp_ref )              ! Namelist nampislim in reference namelist : Pisces nutrient limitation parameters
       READ  ( numnatp_ref, namp5zquota, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisquota in reference namelist', lwp )
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisquota in reference namelist' )
       !
       REWIND( numnatp_cfg )              ! Namelist nampislim in configuration namelist : Pisces nutrient limitation parameters 
       READ  ( numnatp_cfg, namp5zquota, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampisquota in configuration namelist', lwp )
+904   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampisquota in configuration namelist' )
       IF(lwm) WRITE ( numonp, namp5zquota )
       !
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p5zmeso.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p5zmeso.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p5zmeso.F90	(revision 11536)
@@ -409,9 +409,9 @@
       REWIND( numnatp_ref )              ! Namelist nampismes in reference namelist : Pisces mesozooplankton
       READ  ( numnatp_ref, namp5zmes, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampismes in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampismes in reference namelist' )
       !
       REWIND( numnatp_cfg )              ! Namelist nampismes in configuration namelist : Pisces mesozooplankton
       READ  ( numnatp_cfg, namp5zmes, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampismes in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampismes in configuration namelist' )
       IF(lwm) WRITE ( numonp, namp5zmes )
       !
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p5zmicro.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p5zmicro.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p5zmicro.F90	(revision 11536)
@@ -351,9 +351,9 @@
       REWIND( numnatp_ref )              ! Namelist nampiszoo in reference namelist : Pisces microzooplankton
       READ  ( numnatp_ref, namp5zzoo, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namp5zzoo in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namp5zzoo in reference namelist' )
       !
       REWIND( numnatp_cfg )              ! Namelist nampiszoo in configuration namelist : Pisces microzooplankton
       READ  ( numnatp_cfg, namp5zzoo, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namp5zzoo in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namp5zzoo in configuration namelist' )
       IF(lwm) WRITE ( numonp, namp5zzoo )
       !
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p5zmort.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p5zmort.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p5zmort.F90	(revision 11536)
@@ -288,9 +288,9 @@
       REWIND( numnatp_ref )              ! Namelist nampismort in reference namelist : Pisces phytoplankton
       READ  ( numnatp_ref, namp5zmort, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namp5zmort in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namp5zmort in reference namelist' )
 
       REWIND( numnatp_cfg )              ! Namelist nampismort in configuration namelist : Pisces phytoplankton
       READ  ( numnatp_cfg, namp5zmort, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namp5zmort in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namp5zmort in configuration namelist' )
       IF(lwm) WRITE ( numonp, namp5zmort )
 
Index: /NEMO/trunk/src/TOP/PISCES/P4Z/p5zprod.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/P4Z/p5zprod.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/P4Z/p5zprod.F90	(revision 11536)
@@ -584,9 +584,9 @@
       REWIND( numnatp_ref )              ! Namelist nampisprod in reference namelist : Pisces phytoplankton production
       READ  ( numnatp_ref, namp5zprod, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namp5zprod in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namp5zprod in reference namelist' )
 
       REWIND( numnatp_cfg )              ! Namelist nampisprod in configuration namelist : Pisces phytoplankton production
       READ  ( numnatp_cfg, namp5zprod, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namp5zprod in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namp5zprod in configuration namelist' )
       IF(lwm) WRITE ( numonp, namp5zprod )
 
Index: /NEMO/trunk/src/TOP/PISCES/SED/sedini.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/SED/sedini.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/SED/sedini.F90	(revision 11536)
@@ -460,9 +460,9 @@
       REWIND( numnamsed_ref )              ! Namelist nam_run in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_run, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_run in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_run in reference namelist' )
 
       REWIND( numnamsed_cfg )              ! Namelist nam_run in reference namelist : Pisces variables
       READ  ( numnamsed_cfg, nam_run, IOSTAT = ios, ERR = 902)
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_run in configuration namelist', lwp )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_run in configuration namelist' )
 
       IF (lwp) THEN
@@ -476,9 +476,9 @@
       REWIND( numnamsed_ref )              ! Namelist nam_geom in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_geom, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_geom in reference namelist', lwp )
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_geom in reference namelist' )
 
       REWIND( numnamsed_cfg )              ! Namelist nam_geom in reference namelist : Pisces variables
       READ  ( numnamsed_cfg, nam_geom, IOSTAT = ios, ERR = 904)
-904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_geom in configuration namelist', lwp )
+904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_geom in configuration namelist' )
 
       IF (lwp) THEN 
@@ -499,9 +499,9 @@
       REWIND( numnamsed_ref )              ! Namelist nam_trased in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_trased, IOSTAT = ios, ERR = 905)
-905   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_trased in reference namelist', lwp )
+905   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_trased in reference namelist' )
 
       REWIND( numnamsed_cfg )              ! Namelist nam_trased in reference namelist : Pisces variables
       READ  ( numnamsed_cfg, nam_trased, IOSTAT = ios, ERR = 906)
-906   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_trased in configuration namelist', lwp )
+906   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_trased in configuration namelist' )
 
       DO jn = 1, jpsol
@@ -532,9 +532,9 @@
       REWIND( numnamsed_ref )              ! Namelist nam_diased in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_diased, IOSTAT = ios, ERR = 907)
-907   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diased in reference namelist', lwp )
+907   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diased in reference namelist' )
 
       REWIND( numnamsed_cfg )              ! Namelist nam_diased in reference namelist : Pisces variables
       READ  ( numnamsed_cfg, nam_diased, IOSTAT = ios, ERR = 908)
-908   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diased in configuration namelist', lwp )
+908   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diased in configuration namelist' )
       
       DO jn = 1, jpdia3dsed
@@ -574,9 +574,9 @@
       REWIND( numnamsed_ref )              ! Namelist nam_inorg in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_inorg, IOSTAT = ios, ERR = 909)
-909   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_inorg in reference namelist', lwp )
+909   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_inorg in reference namelist' )
 
       REWIND( numnamsed_cfg )              ! Namelist nam_inorg in reference namelist : Pisces variables
       READ  ( numnamsed_cfg, nam_inorg, IOSTAT = ios, ERR = 910)
-910   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_inorg in configuration namelist', lwp )
+910   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_inorg in configuration namelist' )
 
       IF (lwp) THEN
@@ -600,9 +600,9 @@
       REWIND( numnamsed_ref )              ! Namelist nam_poc in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_poc, IOSTAT = ios, ERR = 911)
-911   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_poc in reference namelist', lwp )
+911   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_poc in reference namelist' )
 
       REWIND( numnamsed_cfg )              ! Namelist nam_poc in reference namelist : Pisces variables
       READ  ( numnamsed_cfg, nam_poc, IOSTAT = ios, ERR = 912)
-912   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_poc in configuration namelist', lwp )
+912   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_poc in configuration namelist' )
 
       IF (lwp) THEN
@@ -652,9 +652,9 @@
       REWIND( numnamsed_ref )              ! Namelist nam_btb in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_btb, IOSTAT = ios, ERR = 913)
-913   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_btb in reference namelist', lwp )
+913   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_btb in reference namelist' )
 
       REWIND( numnamsed_cfg )              ! Namelist nam_btb in reference namelist : Pisces variables
       READ  ( numnamsed_cfg, nam_btb, IOSTAT = ios, ERR = 914)
-914   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_btb in configuration namelist', lwp )
+914   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_btb in configuration namelist' )
 
       IF (lwp) THEN
@@ -673,9 +673,9 @@
       REWIND( numnamsed_ref )              ! Namelist nam_rst in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_rst, IOSTAT = ios, ERR = 915)
-915   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_rst in reference namelist', lwp )
+915   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_rst in reference namelist' )
 
       REWIND( numnamsed_cfg )              ! Namelist nam_rst in reference namelist : Pisces variables
       READ  ( numnamsed_cfg, nam_rst, IOSTAT = ios, ERR = 916)
-916   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_rst in configuration namelist', lwp )
+916   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_rst in configuration namelist' )
 
       IF (lwp) THEN
Index: /NEMO/trunk/src/TOP/PISCES/SED/sedrst.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/SED/sedrst.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/SED/sedrst.F90	(revision 11536)
@@ -49,12 +49,12 @@
             IF( ln_rst_list ) THEN
                nrst_lst = 1
-               nitrst = nstocklist( nrst_lst )
+               nitrst = nn_stocklist( nrst_lst )
             ELSE
                nitrst = nitend
             ENDIF
          ENDIF
-         IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nstock ) == 0 ) THEN
+         IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nn_stock ) == 0 ) THEN
             ! we use kt - 1 and not kt - nittrc000 to keep the same periodicity from the beginning of the experiment
-            nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
+            nitrst = kt + nn_stock - 1                  ! define the next value of nitrst for restart writing
             IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
          ENDIF
@@ -62,9 +62,11 @@
          IF( kt == nittrc000 ) lrst_sed = .FALSE.
       ENDIF
+
+      IF( .NOT. ln_rst_list .AND. nn_stock == -1 )   RETURN   ! we will never do any restart
 
       ! to get better performances with NetCDF format:
       ! we open and define the tracer restart file one tracer time step before writing the data (-> at nitrst - 2*nn_dttrc + 1)
       ! except if we write tracer restart files every tracer time step or if a tracer restart file was writen at nitend - 2*nn_dttrc + 1
-      IF( kt == nitrst - 2*nn_dtsed .OR. nstock == nn_dtsed .OR. ( kt == nitend - nn_dtsed .AND. .NOT. lrst_sed ) ) THEN
+      IF( kt == nitrst - 2*nn_dtsed .OR. nn_stock == nn_dtsed .OR. ( kt == nitend - nn_dtsed .AND. .NOT. lrst_sed ) ) THEN
          ! beware of the format used to write kt (default is i8.8, that should be large enough)
          IF( nitrst > 1.0e9 ) THEN   ;   WRITE(clkt,*       ) nitrst
@@ -300,5 +302,5 @@
           IF( l_offline .AND. ln_rst_list ) THEN
              nrst_lst = nrst_lst + 1
-             nitrst = nstocklist( nrst_lst )
+             nitrst = nn_stocklist( nrst_lst )
           ENDIF
       ENDIF
Index: /NEMO/trunk/src/TOP/PISCES/trcnam_pisces.F90
===================================================================
--- /NEMO/trunk/src/TOP/PISCES/trcnam_pisces.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/PISCES/trcnam_pisces.F90	(revision 11536)
@@ -57,8 +57,8 @@
       REWIND( numnatp_ref )              ! Namelist nampisbio in reference namelist : Pisces variables
       READ  ( numnatp_ref, nampismod, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampismod in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampismod in reference namelist' )
       REWIND( numnatp_cfg )              ! Namelist nampisbio in configuration namelist : Pisces variables
       READ  ( numnatp_cfg, nampismod, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampismod in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampismod in configuration namelist' )
       IF(lwm) WRITE( numonp, nampismod )
       !
Index: /NEMO/trunk/src/TOP/TRP/trcadv.F90
===================================================================
--- /NEMO/trunk/src/TOP/TRP/trcadv.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/TRP/trcadv.F90	(revision 11536)
@@ -166,8 +166,8 @@
       REWIND( numnat_ref )                   !  namtrc_adv in reference namelist 
       READ  ( numnat_ref, namtrc_adv, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_adv in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_adv in reference namelist' )
       REWIND( numnat_cfg )                   ! namtrc_adv in configuration namelist
       READ  ( numnat_cfg, namtrc_adv, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_adv in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_adv in configuration namelist' )
       IF(lwm) WRITE ( numont, namtrc_adv )
       !
Index: /NEMO/trunk/src/TOP/TRP/trcdmp.F90
===================================================================
--- /NEMO/trunk/src/TOP/TRP/trcdmp.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/TRP/trcdmp.F90	(revision 11536)
@@ -183,8 +183,8 @@
       REWIND( numnat_ref )              ! Namelist namtrc_dmp in reference namelist : Passive tracers newtonian damping
       READ  ( numnat_ref, namtrc_dmp, IOSTAT = ios, ERR = 909)
-909   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_dmp in reference namelist', lwp )
+909   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_dmp in reference namelist' )
       REWIND( numnat_cfg )              ! Namelist namtrc_dmp in configuration namelist : Passive tracers newtonian damping
       READ  ( numnat_cfg, namtrc_dmp, IOSTAT = ios, ERR = 910)
-910   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_dmp in configuration namelist', lwp )
+910   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_dmp in configuration namelist' )
       IF(lwm) WRITE ( numont, namtrc_dmp )
 
Index: /NEMO/trunk/src/TOP/TRP/trcldf.F90
===================================================================
--- /NEMO/trunk/src/TOP/TRP/trcldf.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/TRP/trcldf.F90	(revision 11536)
@@ -145,9 +145,9 @@
       REWIND( numnat_ref )             !  namtrc_ldf in reference namelist 
       READ  ( numnat_ref, namtrc_ldf, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_ldf in reference namelist', lwp )
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_ldf in reference namelist' )
       !
       REWIND( numnat_cfg )             !  namtrc_ldf in configuration namelist 
       READ  ( numnat_cfg, namtrc_ldf, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_ldf in configuration namelist', lwp )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_ldf in configuration namelist' )
       IF(lwm) WRITE ( numont, namtrc_ldf )
       !
Index: /NEMO/trunk/src/TOP/TRP/trcrad.F90
===================================================================
--- /NEMO/trunk/src/TOP/TRP/trcrad.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/TRP/trcrad.F90	(revision 11536)
@@ -89,8 +89,8 @@
       REWIND( numnat_ref )              ! namtrc_rad in reference namelist 
       READ  ( numnat_ref, namtrc_rad, IOSTAT = ios, ERR = 907)
-907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_rad in reference namelist', lwp )
+907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_rad in reference namelist' )
       REWIND( numnat_cfg )              ! namtrc_rad in configuration namelist 
       READ  ( numnat_cfg, namtrc_rad, IOSTAT = ios, ERR = 908 )
-908   IF( ios > 0 )   CALL ctl_nam ( ios , 'namtrc_rad in configuration namelist', lwp )
+908   IF( ios > 0 )   CALL ctl_nam ( ios , 'namtrc_rad in configuration namelist' )
       IF(lwm) WRITE( numont, namtrc_rad )
 
Index: /NEMO/trunk/src/TOP/TRP/trcsink.F90
===================================================================
--- /NEMO/trunk/src/TOP/TRP/trcsink.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/TRP/trcsink.F90	(revision 11536)
@@ -87,7 +87,10 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               IF( tmask(ji,jj,jk) == 1 ) THEN
+               IF( tmask(ji,jj,jk) == 1.0 ) THEN
                  zwsmax = 0.5 * e3t_n(ji,jj,jk) * rday / rsfact
                  zwsink(ji,jj,jk) = MIN( pwsink(ji,jj,jk), zwsmax * REAL( iiter(ji,jj), wp ) )
+               ELSE
+                 ! provide a default value so there is no use of undefinite value in trc_sink2 for zwsink2 initialization
+                 zwsink(ji,jj,jk) = 0.
                ENDIF
             END DO
@@ -215,8 +218,8 @@
       REWIND( numnat_ref )              ! namtrc_rad in reference namelist 
       READ  ( numnat_ref, namtrc_snk, IOSTAT = ios, ERR = 907)
-907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_snk in reference namelist', lwp )
+907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_snk in reference namelist' )
       REWIND( numnat_cfg )              ! namtrc_rad in configuration namelist 
       READ  ( numnat_cfg, namtrc_snk, IOSTAT = ios, ERR = 908 )
-908   IF( ios > 0 )   CALL ctl_nam ( ios , 'namtrc_snk in configuration namelist', lwp )
+908   IF( ios > 0 )   CALL ctl_nam ( ios , 'namtrc_snk in configuration namelist' )
       IF(lwm) WRITE( numont, namtrc_snk )
 
Index: /NEMO/trunk/src/TOP/TRP/trdmxl_trc.F90
===================================================================
--- /NEMO/trunk/src/TOP/TRP/trdmxl_trc.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/TRP/trdmxl_trc.F90	(revision 11536)
@@ -108,5 +108,5 @@
          ! ... Set nmld(ji,jj) = index of first T point below control surf. or outside mixed-layer
          SELECT CASE ( nn_ctls_trc )                                ! choice of the control surface
-            CASE ( -2  )   ;   STOP 'trdmxl_trc : not ready '     !     -> isopycnal surface (see ???)
+            CASE ( -2  )   ;   CALL ctl_stop( 'STOP', 'trdmxl_trc : not ready ' )     !     -> isopycnal surface (see ???)
             CASE ( -1  )   ;   nmld_trc(:,:) = neln(:,:)          !     -> euphotic layer with light criterion
             CASE (  0  )   ;   nmld_trc(:,:) = nmln(:,:)          !     -> ML with density criterion (see zdfmxl)
@@ -431,5 +431,5 @@
 
 #if defined key_diainstant
-               STOP 'tmltrd_trc : key_diainstant was never checked within trdmxl. Comment this to proceed.'
+               CALL ctl_stop( 'STOP', 'tmltrd_trc : key_diainstant was never checked within trdmxl. Comment this to proceed.' )
 #endif
             ENDIF
@@ -857,5 +857,5 @@
 #  if defined key_diainstant
       IF( .NOT. ln_trdmxl_trc_instant ) THEN
-         STOP 'trd_mxl_trc : this was never checked. Comment this line to proceed...'
+         CALL ctl_stop( 'STOP', 'trd_mxl_trc : this was never checked. Comment this line to proceed...' )
       ENDIF
       zsto = nn_trd_trc * rdt
@@ -928,5 +928,5 @@
       !-- Define miscellaneous passive tracer mixed-layer variables 
       IF( jpltrd_trc /= jpmxl_trc_atf .OR.  jpltrd_trc - 1 /= jpmxl_trc_radb ) THEN
-         STOP 'Error : jpltrd_trc /= jpmxl_trc_atf .OR.  jpltrd_trc - 1 /= jpmxl_trc_radb'  ! see below
+         CALL ctl_stop( 'STOP', 'Error : jpltrd_trc /= jpmxl_trc_atf .OR.  jpltrd_trc - 1 /= jpmxl_trc_radb' ) ! see below
       ENDIF
 
Index: /NEMO/trunk/src/TOP/trcbc.F90
===================================================================
--- /NEMO/trunk/src/TOP/trcbc.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/trcbc.F90	(revision 11536)
@@ -44,5 +44,4 @@
    TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:), TARGET  :: sf_trcobc
 #endif
-   TYPE(MAP_POINTER), ALLOCATABLE, DIMENSION(:) :: nbmap_ptr   ! array of pointers to nbmap
 
    !! * Substitutions
@@ -123,8 +122,8 @@
       REWIND( numnat_ref )              ! Namelist namtrc_bc in reference namelist : Passive tracer data structure
       READ  ( numnat_ref, namtrc_bc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_bc in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_bc in reference namelist' )
       REWIND( numnat_cfg )              ! Namelist namtrc_bc in configuration namelist : Passive tracer data structure
       READ  ( numnat_cfg, namtrc_bc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_bc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_bc in configuration namelist' )
       IF(lwm) WRITE ( numont, namtrc_bc )
 
@@ -132,9 +131,11 @@
          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 )
-
+903      IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_bdy in reference namelist' )
+         ! make sur that all elements of the namelist variables have a default definition from namelist_ref
+         cn_trc     (2:jp_bdy) = cn_trc     (1)
+         cn_trc_dflt(2:jp_bdy) = cn_trc_dflt(1)
          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 )
+904      IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_bdy in configuration namelist' )
          IF(lwm) WRITE ( numont, namtrc_bdy )
       
@@ -234,5 +235,5 @@
       ! OPEN Lateral boundary conditions
       IF( ln_bdy .AND. nb_trcobc > 0 ) THEN 
-         ALLOCATE ( sf_trcobc(nb_trcobc), rf_trofac(nb_trcobc), nbmap_ptr(nb_trcobc), STAT=ierr1 )
+         ALLOCATE ( sf_trcobc(nb_trcobc), rf_trofac(nb_trcobc), STAT=ierr1 )
          IF( ierr1 > 0 ) THEN
             CALL ctl_stop( 'trc_bc_ini: unable to allocate sf_trcobc structure' )   ;   RETURN
@@ -257,8 +258,4 @@
                   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) )
@@ -276,4 +273,13 @@
          !
          CALL fld_fill( sf_trcobc, slf_i, cn_dir_obc, 'trc_bc_ini', 'Passive tracer OBC data', 'namtrc_bc' )
+         DO jn = 1, ntrc   ! define imap pointer, must be done after the call to fld_fill
+            DO ib = 1, nb_bdy
+               IF( ln_trc_obc(jn) ) THEN     !* Initialise from external data *!
+                  jl = n_trc_indobc(jn)
+                  sf_trcobc(jl)%imap => idx_bdy(ib)%nbmap(1:idx_bdy(ib)%nblen(igrd),igrd)
+               ENDIF
+            END DO
+         END DO
+         !
       ENDIF
 
@@ -362,8 +368,8 @@
       IF( PRESENT(jit) ) THEN 
          !
-         ! OPEN boundary conditions (use time_offset=+1 as they are applied at the end of the step)
+         ! OPEN boundary conditions (use kt_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)
+           CALL fld_read( kt=kt, kn_fsbc=1, sd=sf_trcobc, kit=jit, kt_offset=+1)
          ENDIF
          !
@@ -382,8 +388,8 @@
       ELSE
          !
-         ! OPEN boundary conditions (use time_offset=+1 as they are applied at the end of the step)
+         ! OPEN boundary conditions (use kt_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)
+           CALL fld_read( kt=kt, kn_fsbc=1, sd=sf_trcobc, kt_offset=+1)
          ENDIF
          !
Index: /NEMO/trunk/src/TOP/trcbdy.F90
===================================================================
--- /NEMO/trunk/src/TOP/trcbdy.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/trcbdy.F90	(revision 11536)
@@ -22,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       ! ocean open boundary conditions
+   USE bdy_oce                      ! ocean open boundary conditions
 
    IMPLICIT NONE
@@ -46,7 +46,9 @@
       INTEGER, INTENT( in ) :: kt     ! Main time step counter
       !!
-      INTEGER                           :: ib_bdy ,jn ,igrd ! Loop indeces
+      INTEGER                           :: ib_bdy ,ir, jn ,igrd ! Loop indices
       REAL(wp), POINTER, DIMENSION(:,:) ::  ztrc
       REAL(wp), POINTER                 ::  zfac
+      LOGICAL                           :: llrim0               ! indicate if rim 0 is treated
+      LOGICAL, DIMENSION(4)             :: llsend1, llrecv1     ! indicate how communications are to be carried out
       !!----------------------------------------------------------------------
       !
@@ -54,28 +56,50 @@
       !
       igrd = 1 
-      !
-      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), igrd         , 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' )
+      llsend1(:) = .false.  ;   llrecv1(:) = .false.
+      DO ir = 1, 0, -1   ! treat rim 1 before rim 0
+         IF( ir == 0 ) THEN   ;   llrim0 = .TRUE.
+         ELSE                 ;   llrim0 = .FALSE.
+         END IF
+         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'         )   ! treat the whole boundary at once
+                  IF( ir == 0 ) CALL bdy_frs( idx_bdy(ib_bdy),                tra(:,:,:,jn), ztrc*zfac )
+               CASE('specified'   )   ! treat the whole rim      at once
+                  IF( ir == 0 ) CALL bdy_spe( idx_bdy(ib_bdy),                tra(:,:,:,jn), ztrc*zfac )
+               CASE('neumann'     )   ;   CALL bdy_nmn( idx_bdy(ib_bdy), igrd         , tra(:,:,:,jn) )   ! tra masked
+               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
+               !
+            END DO
+         END DO
+         !
+         IF( nn_hls > 1 .AND. ir == 1 ) CYCLE   ! at least 2 halos will be corrected -> no need to correct rim 1 before rim 0
+         IF( nn_hls == 1 ) THEN   ;   llsend1(:) = .false.   ;   llrecv1(:) = .false.   ;   END IF
+         DO ib_bdy=1, nb_bdy
+            SELECT CASE( TRIM(cn_tra(ib_bdy)) )
+            CASE('neumann')
+               llsend1(:) = llsend1(:) .OR. lsend_bdyint(ib_bdy,1,:,ir)   ! possibly every direction, T points
+               llrecv1(:) = llrecv1(:) .OR. lrecv_bdyint(ib_bdy,1,:,ir)   ! possibly every direction, T points
+            CASE('orlanski','orlanski_npo')
+               llsend1(:) = llsend1(:) .OR. lsend_bdy(ib_bdy,1,:,ir)   ! possibly every direction, T points
+               llrecv1(:) = llrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:,ir)   ! possibly every direction, T points
             END SELECT
-            ! Boundary points should be updated
-            CALL lbc_bdy_lnk( 'trcbdy', tra(:,:,:,jn), 'T', 1., ib_bdy )
-            !
          END DO
-      END DO
+         IF( ANY(llsend1) .OR. ANY(llrecv1) ) THEN   ! if need to send/recv in at least one direction
+            CALL lbc_lnk( 'bdytra', tsa, 'T',  1., kfillmode=jpfillnothing ,lsend=llsend1, lrecv=llrecv1 )
+         END IF
+         !
+      END DO   ! ir
       !
       IF( ln_timing )   CALL timing_stop('trc_bdy')
-
+      !
    END SUBROUTINE trc_bdy
 
Index: /NEMO/trunk/src/TOP/trcdta.F90
===================================================================
--- /NEMO/trunk/src/TOP/trcdta.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/trcdta.F90	(revision 11536)
@@ -100,8 +100,8 @@
       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_ini in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_dta_ini in reference namelist' )
       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_ini in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_dta_ini in configuration namelist' )
       IF(lwm) WRITE ( numont, namtrc_dta )
 
Index: /NEMO/trunk/src/TOP/trcice.F90
===================================================================
--- /NEMO/trunk/src/TOP/trcice.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/trcice.F90	(revision 11536)
@@ -87,8 +87,8 @@
       REWIND( numnat_ref )              ! Namelist namtrc_ice in reference namelist : Passive tracer input data
       READ  ( numnat_ref, namtrc_ice, IOSTAT = ios, ERR = 901)
- 901  IF( ios /= 0 )   CALL ctl_nam ( ios , ' namtrc_ice in reference namelist ', lwp )
+ 901  IF( ios /= 0 )   CALL ctl_nam ( ios , ' namtrc_ice in reference namelist ' )
       REWIND( numnat_cfg )              ! Namelist namtrc_ice in configuration namelist : Pisces external sources of nutrients
       READ  ( numnat_cfg, namtrc_ice, IOSTAT = ios, ERR = 902 )
- 902  IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_ice in configuration namelist', lwp )
+ 902  IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_ice in configuration namelist' )
 
       IF( lwp ) THEN
Index: /NEMO/trunk/src/TOP/trcnam.F90
===================================================================
--- /NEMO/trunk/src/TOP/trcnam.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/trcnam.F90	(revision 11536)
@@ -114,8 +114,8 @@
       REWIND( numnat_ref )              ! Namelist namtrc in reference namelist : Passive tracer variables
       READ  ( numnat_ref, namtrc_run, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc in reference namelist' )
       REWIND( numnat_cfg )              ! Namelist namtrc in configuration namelist : Passive tracer variables
       READ  ( numnat_cfg, namtrc_run, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc in configuration namelist' )
       IF(lwm) WRITE( numont, namtrc_run )
 
@@ -160,8 +160,8 @@
       REWIND( numnat_ref )              ! Namelist namtrc in reference namelist : Passive tracer variables
       READ  ( numnat_ref, namtrc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc in reference namelist' )
       REWIND( numnat_cfg )              ! Namelist namtrc in configuration namelist : Passive tracer variables
       READ  ( numnat_cfg, namtrc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc in configuration namelist' )
       IF(lwm) WRITE( numont, namtrc )
 
@@ -263,8 +263,8 @@
       REWIND( numnat_ref )              ! Namelist namtrc_trd in reference namelist : Passive tracer trends
       READ  ( numnat_ref, namtrc_trd, IOSTAT = ios, ERR = 905)
-905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_trd in reference namelist', lwp )
+905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_trd in reference namelist' )
       REWIND( numnat_cfg )              ! Namelist namtrc_trd in configuration namelist : Passive tracer trends
       READ  ( numnat_cfg, namtrc_trd, IOSTAT = ios, ERR = 906 )
-906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_trd in configuration namelist', lwp )
+906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_trd in configuration namelist' )
       IF(lwm) WRITE( numont, namtrc_trd )
 
Index: /NEMO/trunk/src/TOP/trcrst.F90
===================================================================
--- /NEMO/trunk/src/TOP/trcrst.F90	(revision 11535)
+++ /NEMO/trunk/src/TOP/trcrst.F90	(revision 11536)
@@ -58,5 +58,5 @@
             IF( ln_rst_list ) THEN
                nrst_lst = 1
-               nitrst = nstocklist( nrst_lst )
+               nitrst = nn_stocklist( nrst_lst )
             ELSE
                nitrst = nitend
@@ -64,7 +64,7 @@
          ENDIF
 
-         IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nstock ) == 0 ) THEN
+         IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nn_stock ) == 0 ) THEN
             ! we use kt - 1 and not kt - nittrc000 to keep the same periodicity from the beginning of the experiment
-            nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
+            nitrst = kt + nn_stock - 1                  ! define the next value of nitrst for restart writing
             IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
          ENDIF
@@ -72,9 +72,11 @@
          IF( kt == nittrc000 ) lrst_trc = .FALSE.
       ENDIF
+
+      IF( .NOT. ln_rst_list .AND. nn_stock == -1 )   RETURN   ! we will never do any restart
 
       ! to get better performances with NetCDF format:
       ! we open and define the tracer restart file one tracer time step before writing the data (-> at nitrst - 2*nn_dttrc + 1)
       ! except if we write tracer restart files every tracer time step or if a tracer restart file was writen at nitend - 2*nn_dttrc + 1
-      IF( kt == nitrst - 2*nn_dttrc .OR. nstock == nn_dttrc .OR. ( kt == nitend - nn_dttrc .AND. .NOT. lrst_trc ) ) THEN
+      IF( kt == nitrst - 2*nn_dttrc .OR. nn_stock == nn_dttrc .OR. ( kt == nitend - nn_dttrc .AND. .NOT. lrst_trc ) ) THEN
          ! beware of the format used to write kt (default is i8.8, that should be large enough)
          IF( nitrst > 1.0e9 ) THEN   ;   WRITE(clkt,*       ) nitrst
@@ -153,5 +155,5 @@
           IF( l_offline .AND. ln_rst_list ) THEN
              nrst_lst = nrst_lst + 1
-             nitrst = nstocklist( nrst_lst )
+             nitrst = nn_stocklist( nrst_lst )
           ENDIF
       ENDIF
Index: /NEMO/trunk/tests/BENCH/EXPREF/best_jpni_jpnj_eorca025
===================================================================
--- /NEMO/trunk/tests/BENCH/EXPREF/best_jpni_jpnj_eorca025	(revision 11535)
+++ /NEMO/trunk/tests/BENCH/EXPREF/best_jpni_jpnj_eorca025	(revision 11536)
@@ -624,2 +624,16 @@
     nb_cores 36180 ( 180 x 201 ), nb_points 80 ( 10 x 8 )
     nb_cores 38560 ( 160 x 241 ), nb_points 77 ( 11 x 7 )
+    nb_cores 41406 ( 206 x 201 ), nb_points 72 ( 9 x 8 )
+    nb_cores 43380 ( 180 x 241 ), nb_points 70 ( 10 x 7 )
+    nb_cores 48240 ( 240 x 201 ), nb_points 64 ( 8 x 8 )
+    nb_cores 49646 ( 206 x 241 ), nb_points 63 ( 9 x 7 )
+    nb_cores 54360 ( 180 x 302 ), nb_points 60 ( 10 x 6 )
+    nb_cores 54360 ( 360 x 151 ), nb_points 60 ( 6 x 10 )
+    nb_cores 57840 ( 240 x 241 ), nb_points 56 ( 8 x 7 )
+    nb_cores 62212 ( 206 x 302 ), nb_points 54 ( 9 x 6 )
+    nb_cores 69408 ( 288 x 241 ), nb_points 49 ( 7 x 7 )
+    nb_cores 72360 ( 360 x 201 ), nb_points 48 ( 6 x 8 )
+    nb_cores 82812 ( 206 x 402 ), nb_points 45 ( 9 x 5 )
+    nb_cores 86760 ( 360 x 241 ), nb_points 42 ( 6 x 7 )
+    nb_cores 96480 ( 240 x 402 ), nb_points 40 ( 8 x 5 )
+    nb_cores 96480 ( 480 x 201 ), nb_points 40 ( 5 x 8 )
Index: /NEMO/trunk/tests/BENCH/EXPREF/best_jpni_jpnj_eorca12
===================================================================
--- /NEMO/trunk/tests/BENCH/EXPREF/best_jpni_jpnj_eorca12	(revision 11535)
+++ /NEMO/trunk/tests/BENCH/EXPREF/best_jpni_jpnj_eorca12	(revision 11536)
@@ -1300,2 +1300,49 @@
     nb_cores 49852 ( 206 x 242 ), nb_points 345 ( 23 x 15 )
     nb_cores 49950 ( 270 x 185 ), nb_points 342 ( 18 x 19 )
+    nb_cores 50400 ( 288 x 175 ), nb_points 340 ( 17 x 20 )
+    nb_cores 50400 ( 240 x 210 ), nb_points 340 ( 20 x 17 )
+    nb_cores 51294 ( 309 x 166 ), nb_points 336 ( 16 x 21 )
+    nb_cores 52272 ( 216 x 242 ), nb_points 330 ( 22 x 15 )
+    nb_cores 53190 ( 270 x 197 ), nb_points 324 ( 18 x 18 )
+    nb_cores 53280 ( 288 x 185 ), nb_points 323 ( 17 x 19 )
+    nb_cores 54000 ( 240 x 225 ), nb_points 320 ( 20 x 16 )
+    nb_cores 55176 ( 228 x 242 ), nb_points 315 ( 21 x 15 )
+    nb_cores 56199 ( 393 x 143 ), nb_points 312 ( 13 x 24 )
+    nb_cores 56700 ( 270 x 210 ), nb_points 306 ( 18 x 17 )
+    nb_cores 57165 ( 309 x 185 ), nb_points 304 ( 16 x 19 )
+    nb_cores 58080 ( 240 x 242 ), nb_points 300 ( 20 x 15 )
+    nb_cores 58916 ( 206 x 286 ), nb_points 299 ( 23 x 13 )
+    nb_cores 59760 ( 360 x 166 ), nb_points 294 ( 14 x 21 )
+    nb_cores 60480 ( 288 x 210 ), nb_points 289 ( 17 x 17 )
+    nb_cores 60750 ( 270 x 225 ), nb_points 288 ( 18 x 16 )
+    nb_cores 61605 ( 333 x 185 ), nb_points 285 ( 15 x 19 )
+    nb_cores 63000 ( 360 x 175 ), nb_points 280 ( 14 x 20 )
+    nb_cores 64800 ( 288 x 225 ), nb_points 272 ( 17 x 16 )
+    nb_cores 65340 ( 270 x 242 ), nb_points 270 ( 18 x 15 )
+    nb_cores 66600 ( 360 x 185 ), nb_points 266 ( 14 x 19 )
+    nb_cores 68040 ( 216 x 315 ), nb_points 264 ( 22 x 12 )
+    nb_cores 68640 ( 240 x 286 ), nb_points 260 ( 20 x 13 )
+    nb_cores 69525 ( 309 x 225 ), nb_points 256 ( 16 x 16 )
+    nb_cores 69696 ( 288 x 242 ), nb_points 255 ( 17 x 15 )
+    nb_cores 70920 ( 360 x 197 ), nb_points 252 ( 14 x 18 )
+    nb_cores 72705 ( 393 x 185 ), nb_points 247 ( 13 x 19 )
+    nb_cores 74778 ( 309 x 242 ), nb_points 240 ( 16 x 15 )
+    nb_cores 75600 ( 360 x 210 ), nb_points 238 ( 14 x 17 )
+    nb_cores 77220 ( 270 x 286 ), nb_points 234 ( 18 x 13 )
+    nb_cores 79680 ( 480 x 166 ), nb_points 231 ( 11 x 21 )
+    nb_cores 79920 ( 432 x 185 ), nb_points 228 ( 12 x 19 )
+    nb_cores 80586 ( 333 x 242 ), nb_points 225 ( 15 x 15 )
+    nb_cores 81000 ( 360 x 225 ), nb_points 224 ( 14 x 16 )
+    nb_cores 82368 ( 288 x 286 ), nb_points 221 ( 17 x 13 )
+    nb_cores 84000 ( 480 x 175 ), nb_points 220 ( 11 x 20 )
+    nb_cores 84000 ( 240 x 350 ), nb_points 220 ( 20 x 11 )
+    nb_cores 85050 ( 270 x 315 ), nb_points 216 ( 18 x 12 )
+    nb_cores 87120 ( 360 x 242 ), nb_points 210 ( 14 x 15 )
+    nb_cores 88374 ( 309 x 286 ), nb_points 208 ( 16 x 13 )
+    nb_cores 90720 ( 288 x 315 ), nb_points 204 ( 17 x 12 )
+    nb_cores 90720 ( 432 x 210 ), nb_points 204 ( 12 x 17 )
+    nb_cores 94500 ( 270 x 350 ), nb_points 198 ( 18 x 11 )
+    nb_cores 94680 ( 360 x 263 ), nb_points 196 ( 14 x 14 )
+    nb_cores 95106 ( 393 x 242 ), nb_points 195 ( 13 x 15 )
+    nb_cores 97200 ( 432 x 225 ), nb_points 192 ( 12 x 16 )
+    nb_cores 99900 ( 540 x 185 ), nb_points 190 ( 10 x 19 )
Index: /NEMO/trunk/tests/BENCH/EXPREF/namelist_cfg_orca025_like
===================================================================
--- /NEMO/trunk/tests/BENCH/EXPREF/namelist_cfg_orca025_like	(revision 11535)
+++ /NEMO/trunk/tests/BENCH/EXPREF/namelist_cfg_orca025_like	(revision 11536)
@@ -9,6 +9,6 @@
    nn_it000    =       1   !  first time step
    nn_itend    =    1000   !  last time step 
-   nn_stock    =       0   !  frequency of creation of a restart file (modulo referenced to 1)
-   nn_write    =       0   !  frequency of write in the output file   (modulo referenced to nn_it000)
+   nn_stock    =      -1   !  frequency of creation of a restart file (modulo referenced to 1)
+   nn_write    =      -1   !  frequency of write in the output file   (modulo referenced to nn_it000)
 /
 !-----------------------------------------------------------------------
@@ -30,5 +30,4 @@
 &namctl        !   Control prints                                       (default: OFF)
 !-----------------------------------------------------------------------
-   ln_ctl      = .false.   !  trends control print (expensive!)
    nn_print    =    0      !  level of print (0 no extra print)
    ln_timing   = .false.   !  timing by routine write out in timing.output file
Index: /NEMO/trunk/tests/BENCH/EXPREF/namelist_cfg_orca12_like
===================================================================
--- /NEMO/trunk/tests/BENCH/EXPREF/namelist_cfg_orca12_like	(revision 11535)
+++ /NEMO/trunk/tests/BENCH/EXPREF/namelist_cfg_orca12_like	(revision 11536)
@@ -9,6 +9,6 @@
    nn_it000    =       1   !  first time step
    nn_itend    =    1000   !  last time step 
-   nn_stock    =       0   !  frequency of creation of a restart file (modulo referenced to 1)
-   nn_write    =       0   !  frequency of write in the output file   (modulo referenced to nn_it000)
+   nn_stock    =      -1   !  frequency of creation of a restart file (modulo referenced to 1)
+   nn_write    =      -1   !  frequency of write in the output file   (modulo referenced to nn_it000)
 /
 !-----------------------------------------------------------------------
@@ -30,5 +30,4 @@
 &namctl        !   Control prints                                       (default: OFF)
 !-----------------------------------------------------------------------
-   ln_ctl      = .false.   !  trends control print (expensive!)
    nn_print    =    0      !  level of print (0 no extra print)
    ln_timing   = .false.   !  timing by routine write out in timing.output file
Index: /NEMO/trunk/tests/BENCH/EXPREF/namelist_cfg_orca1_like
===================================================================
--- /NEMO/trunk/tests/BENCH/EXPREF/namelist_cfg_orca1_like	(revision 11535)
+++ /NEMO/trunk/tests/BENCH/EXPREF/namelist_cfg_orca1_like	(revision 11536)
@@ -9,6 +9,6 @@
    nn_it000    =       1   !  first time step
    nn_itend    =    1000   !  last time step 
-   nn_stock    =       0   !  frequency of creation of a restart file (modulo referenced to 1)
-   nn_write    =       0   !  frequency of write in the output file   (modulo referenced to nn_it000)
+   nn_stock    =      -1   !  frequency of creation of a restart file (modulo referenced to 1)
+   nn_write    =      -1   !  frequency of write in the output file   (modulo referenced to nn_it000)
 /
 !-----------------------------------------------------------------------
@@ -30,5 +30,4 @@
 &namctl        !   Control prints                                       (default: OFF)
 !-----------------------------------------------------------------------
-   ln_ctl      = .false.   !  trends control print (expensive!)
    nn_print    =    0      !  level of print (0 no extra print)
    ln_timing   = .false.   !  timing by routine write out in timing.output file
Index: /NEMO/trunk/tests/BENCH/EXPREF/namelist_ice_cfg
===================================================================
--- /NEMO/trunk/tests/BENCH/EXPREF/namelist_ice_cfg	(revision 11535)
+++ /NEMO/trunk/tests/BENCH/EXPREF/namelist_ice_cfg	(revision 11536)
@@ -74,4 +74,5 @@
 &namini         !   Ice initialization
 !------------------------------------------------------------------------------
+   rn_thres_sst     =   0.5           !  max delta temp. above Tfreeze with initial ice = (sst - tfreeze)
 /
 !------------------------------------------------------------------------------
Index: /NEMO/trunk/tests/BENCH/EXPREF/namelist_top_cfg
===================================================================
--- /NEMO/trunk/tests/BENCH/EXPREF/namelist_top_cfg	(revision 11535)
+++ /NEMO/trunk/tests/BENCH/EXPREF/namelist_top_cfg	(revision 11536)
@@ -57,12 +57,12 @@
 !          !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
 !          !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_trcdta(1)  = 'data_DIC_nomask'        ,        -12        ,  'DIC'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(2)  = 'data_Alkalini_nomask'   ,        -12        ,  'Alkalini',    .false.   , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(3)  = 'data_O2_nomask'         ,        -1         ,  'O2'      ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(5)  = 'data_PO4_nomask'        ,        -1         ,  'PO4'     ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(7)  = 'data_Si_nomask'         ,        -1         ,  'Si'      ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(10) = 'data_DOC_nomask'        ,        -12        ,  'DOC'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(14) = 'data_Fer_nomask'        ,        -12        ,  'Fer'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
-   sn_trcdta(23) = 'data_NO3_nomask'        ,        -1         ,  'NO3'     ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(1)  = 'data_DIC_nomask'        ,        -12.       ,  'DIC'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(2)  = 'data_Alkalini_nomask'   ,        -12.       ,  'Alkalini',    .false.   , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(3)  = 'data_O2_nomask'         ,        -1.        ,  'O2'      ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(5)  = 'data_PO4_nomask'        ,        -1.        ,  'PO4'     ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(7)  = 'data_Si_nomask'         ,        -1.        ,  'Si'      ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(10) = 'data_DOC_nomask'        ,        -12.       ,  'DOC'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(14) = 'data_Fer_nomask'        ,        -12.       ,  'Fer'     ,    .false.   , .true. , 'yearly'  , ''       , ''   , ''
+   sn_trcdta(23) = 'data_NO3_nomask'        ,        -1.        ,  'NO3'     ,    .true.    , .true. , 'yearly'  , ''       , ''   , ''
    rn_trfac(1)   =   1.0e-06  !  multiplicative factor
    rn_trfac(2)   =   1.0e-06  !  -      -      -     -
Index: /NEMO/trunk/tests/BENCH/EXPREF/sh_bench
===================================================================
--- /NEMO/trunk/tests/BENCH/EXPREF/sh_bench	(revision 11535)
+++ /NEMO/trunk/tests/BENCH/EXPREF/sh_bench	(revision 11536)
@@ -9,4 +9,5 @@
 machine=$( hostname | sed -e "s/[0-9]*//g" )
 case $machine in 
+    "jean-zay")     ncore_node=40 ;;
     "beaufixlogin") ncore_node=40 ;;
     "curie")        ncore_node=16 ;;
Index: /NEMO/trunk/tests/BENCH/EXPREF/submit_bench
===================================================================
--- /NEMO/trunk/tests/BENCH/EXPREF/submit_bench	(revision 11535)
+++ /NEMO/trunk/tests/BENCH/EXPREF/submit_bench	(revision 11536)
@@ -6,5 +6,5 @@
 #
 set -u
-set -vx
+#set -vx
 #
 cores=$1
@@ -15,10 +15,73 @@
 #
 # number of processes for each executable
-    nproc_exe1=$( echo $cores | bc )
-  (( nproc = $nproc_exe1 ))
-(( nnode = $nproc / $ncore_node ))
-[ $nnode -lt 1 ] && nnode=1
+nproc_exe1=$( echo $cores | bc )
+nproc=$nproc_exe1
+nnode=$(( ( $nproc + $ncore_node - 1 )  / $ncore_node ))
 
 nproc5=$( printf "%05d\n" ${nproc_exe1} )
+
+case ${resolution} in
+    "1")
+	if [ $nproc_exe1 -lt 50 ]
+	then
+	    timejob=3600
+	elif [ $nproc_exe1 -lt 100 ]
+	then
+	    timejob=1800
+	elif [ $nproc_exe1 -lt 200 ]
+	then
+	    timejob=900
+	else
+	    timejob=600
+	fi
+	;;
+    "025")
+	if [ $nproc_exe1 -lt 50 ]
+	then
+	    timejob=15000
+	elif [ $nproc_exe1 -lt 100 ]
+	then
+	    timejob=7000
+	elif [ $nproc_exe1 -lt 200 ]
+	then
+	    timejob=3600
+	elif [ $nproc_exe1 -lt 400 ]
+	then
+	    timejob=2000
+	elif [ $nproc_exe1 -lt 800 ]
+	then
+	    timejob=1000
+	else
+	    timejob=600
+	fi
+	;;
+    "12")
+	if [ $nproc_exe1 -lt 200 ]
+	then
+	    timejob=30000
+	elif [ $nproc_exe1 -lt 400 ]
+	then
+	    timejob=15000
+	elif [ $nproc_exe1 -lt 800 ]
+	then
+	    timejob=20000
+	elif [ $nproc_exe1 -lt 1600 ]
+	then
+	    timejob=15000
+	elif [ $nproc_exe1 -lt 3200 ]
+	then
+	    timejob=7500
+	elif [ $nproc_exe1 -lt 10000 ]
+	then
+	    timejob=5000
+	elif [ $nproc_exe1 -lt 20000 ]
+	then
+	    timejob=2500
+	else
+	    timejob=1200
+	fi
+	;;
+esac
+
 
 ######################################################################
@@ -100,65 +163,11 @@
 if [[ ( "$machine" == "curie" ) || ( "$machine" == "irene" ) ]]
 then
-    
-    case ${resolution} in
-	"1")
-	    if [ $nproc_exe1 -lt 50 ]
-	    then
-		timejob=3600
-	    elif [ $nproc_exe1 -lt 100 ]
-	    then
-		timejob=1800
-	    elif [ $nproc_exe1 -lt 200 ]
-	    then
-		timejob=900
-	    else
-		timejob=600
-	    fi
-	    ;;
-	"025")
-	    if [ $nproc_exe1 -lt 50 ]
-	    then
-		timejob=15000
-	    elif [ $nproc_exe1 -lt 100 ]
-	    then
-		timejob=7000
-	    elif [ $nproc_exe1 -lt 200 ]
-	    then
-		timejob=3600
-	    elif [ $nproc_exe1 -lt 400 ]
-	    then
-		timejob=2000
-	    elif [ $nproc_exe1 -lt 800 ]
-	    then
-		timejob=1000
-	    else
-		timejob=600
-	    fi
-	    ;;
-	"12")
-	    if [ $nproc_exe1 -lt 200 ]
-	    then
-		timejob=30000
-	    elif [ $nproc_exe1 -lt 400 ]
-	    then
-		timejob=15000
-	    elif [ $nproc_exe1 -lt 800 ]
-	    then
-		timejob=8000
-	    elif [ $nproc_exe1 -lt 1600 ]
-	    then
-		timejob=5000
-	    elif [ $nproc_exe1 -lt 3200 ]
-	    then
-		timejob=2500
-	    else
-		timejob=1200
-	    fi
-	;;
-    esac
 
     [ "$machine" == "curie" ] && queuename=standard || queuename=skylake
     
-    jobname=$HOME/binrun/jobbench
+    EXPjob=../EXP_${resolution}_${nproc5}_${dateref}
+    mkdir -p ${EXPjob}
+    cd ${EXPjob}
+    jobname=jobbench
     cat > $jobname << EOF
 #!/bin/bash
@@ -176,18 +185,20 @@
 #
 
-cd \${BRIDGE_MSUB_PWD}/..
-
-
-EXPjob=EXP_${resolution}_${nproc5}_${dateref}
-rsync -av --exclude="*eo" EXPREF/ \${EXPjob}/
-rsync -av EXP00/nemo \${EXPjob}/nemo
-cd \${EXPjob}
+cd \${BRIDGE_MSUB_PWD}
+
+for ff in \${BRIDGE_MSUB_PWD}/../EXPREF/namelist_*cfg \${BRIDGE_MSUB_PWD}/../EXPREF/namelist_*ref \${BRIDGE_MSUB_PWD}/../BLD/bin/nemo.exe
+do
+    cp \$ff .
+done
 
 jpni=${cores/\**/}
 jpnj=${cores/?*\*/}
 
-sed -e "s/jpni *=.*/jpni = \${jpni}/" -e "s/jpnj *=.*/jpnj = \${jpnj}/" namelist_cfg_orca${resolution}_like > namelist_cfg
-
-time ccc_mprun -n \${BRIDGE_MSUB_NPROC} ./nemo > jobout_${resolution}_${nproc5}_${dateref}
+sed -e "s/jpni *=.*/jpni = \${jpni}/" \
+    -e "s/jpnj *=.*/jpnj = \${jpnj}/"\
+    -e "s/ln_timing *= *.false./ln_timing   =  .true./" \
+     \${BRIDGE_MSUB_PWD}/../EXPREF/namelist_cfg_orca${resolution}_like > namelist_cfg
+
+time ccc_mprun -n \${BRIDGE_MSUB_NPROC} ./nemo.exe > jobout_${resolution}_${nproc5}_${dateref} 2>&1
 
 EOF
@@ -196,2 +207,70 @@
 
 fi
+
+######################################################################
+### Jean-Zay
+######################################################################
+
+if [ "$machine" == "jean-zay" ]
+then
+    hh=$( printf "%02d\n" $(( ${timejob} / 3600 )) )
+    mm=$( printf "%02d\n" $(( ( ${timejob} % 3600 ) / 60 )) )
+    ss=$( printf "%02d\n" $(( ( ${timejob} % 3600 ) % 60 )) )
+
+    EXPjob=../EXP_${resolution}_${nproc5}_${dateref}
+    mkdir -p ${EXPjob}
+    cd ${EXPjob}
+    jobname=jobbench
+    cat > $jobname << EOF
+#!/bin/bash
+#SBATCH --job-name=Seq        # nom du job
+#SBATCH --partition=cpu_gct3   # demande d'allocation sur la partition CPU
+#SBATCH --nodes=${nnode}             # nombre de noeuds
+#SBATCH --ntasks-per-node=${ncore_node}  # nombre de taches MPI par noeud
+#SBATCH --ntasks-per-core=1        # 1 processus MPI par coeur physique (pas d'hyperthreading)
+#SBATCH --time=${hh}:${mm}:${ss}       # temps d execution maximum demande (HH:MM:SS)
+#SBATCH --output=bench_${resolution}_${nproc5}_%j.eo        # nom du fichier de sortie
+#SBATCH --error=bench_${resolution}_${nproc5}_%j.eo         # nom du fichier d'erreur (ici en commun avec la sortie)
+#==========================================
+set -u
+#set -xv
+#
+#cd \${SLURM_SUBMIT_DIR}
+cd \${JOBSCRATCH}
+pwd
+
+for ff in \${SLURM_SUBMIT_DIR}/../EXPREF/namelist_*cfg \${SLURM_SUBMIT_DIR}/../EXPREF/namelist_*ref \${SLURM_SUBMIT_DIR}/../BLD/bin/nemo.exe
+do
+    cp \$ff .
+done
+
+jpni=${cores/\**/}
+jpnj=${cores/?*\*/}
+
+sed -e "s/jpni *=.*/jpni = \${jpni}/" \
+    -e "s/jpnj *=.*/jpnj = \${jpnj}/" \
+    -e "s/ln_timing *= *.false./ln_timing   =  .true./" \
+    \${SLURM_SUBMIT_DIR}/../EXPREF/namelist_cfg_orca${resolution}_like > namelist_cfg
+
+ls -l
+
+echo 
+echo 
+echo " =========== start the model ==========="
+echo 
+echo 
+
+time srun --mpi=pmi2 --cpu-bind=cores -K1 -n ${nproc} ./nemo.exe > jobout_${resolution}_${nproc5}_${dateref} 2>&1
+
+ls -l
+
+if [ "\$( pwd )" != "\${SLURM_SUBMIT_DIR}" ]
+then 
+    rsync -av namelist_cfg time.step ocean.output jobout_${resolution}_${nproc5}_${dateref} communication_report.txt layout.dat timing.output output.namelist* \${SLURM_SUBMIT_DIR}
+fi
+
+EOF
+
+    sbatch $jobname
+
+fi
Index: MO/trunk/tests/BENCH/MY_SRC/diawri.F90
===================================================================
--- /NEMO/trunk/tests/BENCH/MY_SRC/diawri.F90	(revision 11535)
+++ 	(revision )
@@ -1,491 +1,0 @@
-MODULE diawri
-   !!======================================================================
-   !!                     ***  MODULE  diawri  ***
-   !! Ocean diagnostics :  write ocean output files
-   !!=====================================================================
-   !! History :  OPA  ! 1991-03  (M.-A. Foujols)  Original code
-   !!            4.0  ! 1991-11  (G. Madec)
-   !!                 ! 1992-06  (M. Imbard)  correction restart file
-   !!                 ! 1992-07  (M. Imbard)  split into diawri and rstwri
-   !!                 ! 1993-03  (M. Imbard)  suppress writibm
-   !!                 ! 1998-01  (C. Levy)  NETCDF format using ioipsl INTERFACE
-   !!                 ! 1999-02  (E. Guilyardi)  name of netCDF files + variables
-   !!            8.2  ! 2000-06  (M. Imbard)  Original code (diabort.F)
-   !!   NEMO     1.0  ! 2002-06  (A.Bozec, E. Durand)  Original code (diainit.F)
-   !!             -   ! 2002-09  (G. Madec)  F90: Free form and module
-   !!             -   ! 2002-12  (G. Madec)  merge of diabort and diainit, F90
-   !!                 ! 2005-11  (V. Garnier) Surface pressure gradient organization
-   !!            3.2  ! 2008-11  (B. Lemaire) creation from old diawri
-   !!            3.7  ! 2014-01  (G. Madec) remove eddy induced velocity from no-IOM output
-   !!                 !                     change name of output variables in dia_wri_state
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dia_wri       : create the standart output files
-   !!   dia_wri_state : create an output NetCDF file for a single instantaeous ocean state and forcing fields
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers 
-   USE dom_oce        ! ocean space and time domain
-   USE phycst         ! physical constants
-   USE dianam         ! build name of file (routine)
-   USE diahth         ! thermocline diagnostics
-   USE dynadv   , ONLY: ln_dynadv_vec
-   USE icb_oce        ! Icebergs
-   USE icbdia         ! Iceberg budgets
-   USE ldftra         ! lateral physics: eddy diffusivity coef.
-   USE ldfdyn         ! lateral physics: eddy viscosity   coef.
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE sbc_ice        ! Surface boundary condition: ice fields
-   USE sbcssr         ! restoring term toward SST/SSS climatology
-   USE sbcwave        ! wave parameters
-   USE wet_dry        ! wetting and drying
-   USE zdf_oce        ! ocean vertical physics
-   USE zdfdrg         ! ocean vertical physics: top/bottom friction
-   USE zdfmxl         ! mixed layer
-   !
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE in_out_manager ! I/O manager
-   USE diatmb         ! Top,middle,bottom output
-   USE dia25h         ! 25h Mean output
-   USE iom            ! 
-   USE ioipsl         ! 
-
-#if defined key_si3
-   USE ice
-   USE icewri 
-#endif
-   USE lib_mpp         ! MPP library
-   USE timing          ! preformance summary
-   USE diurnal_bulk    ! diurnal warm layer
-   USE cool_skin       ! Cool skin
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dia_wri                 ! routines called by step.F90
-   PUBLIC   dia_wri_state
-   PUBLIC   dia_wri_alloc           ! Called by nemogcm module
-
-   INTEGER ::   nid_T, nz_T, nh_T, ndim_T, ndim_hT   ! grid_T file
-   INTEGER ::          nb_T              , ndim_bT   ! grid_T file
-   INTEGER ::   nid_U, nz_U, nh_U, ndim_U, ndim_hU   ! grid_U file
-   INTEGER ::   nid_V, nz_V, nh_V, ndim_V, ndim_hV   ! grid_V file
-   INTEGER ::   nid_W, nz_W, nh_W                    ! grid_W file
-   INTEGER ::   ndex(1)                              ! ???
-   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_hT, ndex_hU, ndex_hV
-   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_T, ndex_U, ndex_V
-   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_bT
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: diawri.F90 9598 2018-05-15 22:47:16Z nicolasmartin $
-   !! Software governed by the CeCILL licence     (./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-#if defined key_iomput
-   !!----------------------------------------------------------------------
-   !!   'key_iomput'                                        use IOM library
-   !!----------------------------------------------------------------------
-   INTEGER FUNCTION dia_wri_alloc()
-      !
-      dia_wri_alloc = 0
-      !
-   END FUNCTION dia_wri_alloc
-
-   
-   SUBROUTINE dia_wri( kt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dia_wri  ***
-      !!                   
-      !! ** Purpose :   Standard output of opa: dynamics and tracer fields 
-      !!      NETCDF format is used by default 
-      !!
-      !! ** Method  :  use iom_put
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-      !!
-      INTEGER ::   ji, jj, jk       ! dummy loop indices
-      INTEGER ::   ikbot            ! local integer
-      REAL(wp)::   zztmp , zztmpx   ! local scalar
-      REAL(wp)::   zztmp2, zztmpy   !   -      -
-      REAL(wp), DIMENSION(jpi,jpj)     ::   z2d   ! 2D workspace
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   z3d   ! 3D workspace
-      !!----------------------------------------------------------------------
-      ! 
-      IF( ln_timing )   CALL timing_start('dia_wri')
-      ! 
-      ! Output the initial state and forcings
-      IF( ninist == 1 ) THEN                       
-         CALL dia_wri_state( 'output.init' )
-         ninist = 0
-      ENDIF
-
-      ! Output of initial vertical scale factor
-      CALL iom_put("e3t_0", e3t_0(:,:,:) )
-      CALL iom_put("e3u_0", e3u_0(:,:,:) )
-      CALL iom_put("e3v_0", e3v_0(:,:,:) )
-      !
-      CALL iom_put( "e3t" , e3t_n(:,:,:) )
-      CALL iom_put( "e3u" , e3u_n(:,:,:) )
-      CALL iom_put( "e3v" , e3v_n(:,:,:) )
-      CALL iom_put( "e3w" , e3w_n(:,:,:) )
-      IF( iom_use("e3tdef") )   &
-         CALL iom_put( "e3tdef"  , ( ( e3t_n(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2 )
-
-      IF( ll_wd ) THEN
-         CALL iom_put( "ssh" , (sshn+ssh_ref)*tmask(:,:,1) )   ! sea surface height (brought back to the reference used for wetting and drying)
-      ELSE
-         CALL iom_put( "ssh" , sshn )              ! sea surface height
-      ENDIF
-
-      IF( iom_use("wetdep") )   &                  ! wet depth
-         CALL iom_put( "wetdep" , ht_0(:,:) + sshn(:,:) )
-      
-      CALL iom_put( "toce", tsn(:,:,:,jp_tem) )    ! 3D temperature
-      CALL iom_put(  "sst", tsn(:,:,1,jp_tem) )    ! surface temperature
-      IF ( iom_use("sbt") ) THEN
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ikbot = mbkt(ji,jj)
-               z2d(ji,jj) = tsn(ji,jj,ikbot,jp_tem)
-            END DO
-         END DO
-         CALL iom_put( "sbt", z2d )                ! bottom temperature
-      ENDIF
-      
-      CALL iom_put( "soce", tsn(:,:,:,jp_sal) )    ! 3D salinity
-      CALL iom_put(  "sss", tsn(:,:,1,jp_sal) )    ! surface salinity
-      IF ( iom_use("sbs") ) THEN
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ikbot = mbkt(ji,jj)
-               z2d(ji,jj) = tsn(ji,jj,ikbot,jp_sal)
-            END DO
-         END DO
-         CALL iom_put( "sbs", z2d )                ! bottom salinity
-      ENDIF
-
-      IF ( iom_use("taubot") ) THEN                ! bottom stress
-         zztmp = rau0 * 0.25
-         z2d(:,:) = 0._wp
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zztmp2 = (  ( rCdU_bot(ji+1,jj)+rCdU_bot(ji  ,jj) ) * un(ji  ,jj,mbku(ji  ,jj))  )**2   &
-                  &   + (  ( rCdU_bot(ji  ,jj)+rCdU_bot(ji-1,jj) ) * un(ji-1,jj,mbku(ji-1,jj))  )**2   &
-                  &   + (  ( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj  ) ) * vn(ji,jj  ,mbkv(ji,jj  ))  )**2   &
-                  &   + (  ( rCdU_bot(ji,jj  )+rCdU_bot(ji,jj-1) ) * vn(ji,jj-1,mbkv(ji,jj-1))  )**2
-               z2d(ji,jj) = zztmp * SQRT( zztmp2 ) * tmask(ji,jj,1) 
-               !
-            END DO
-         END DO
-         CALL lbc_lnk( 'diawri', z2d, 'T', 1. )
-         CALL iom_put( "taubot", z2d )           
-      ENDIF
-         
-      CALL iom_put( "uoce", un(:,:,:) )            ! 3D i-current
-      CALL iom_put(  "ssu", un(:,:,1) )            ! surface i-current
-      IF ( iom_use("sbu") ) THEN
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ikbot = mbku(ji,jj)
-               z2d(ji,jj) = un(ji,jj,ikbot)
-            END DO
-         END DO
-         CALL iom_put( "sbu", z2d )                ! bottom i-current
-      ENDIF
-      
-      CALL iom_put( "voce", vn(:,:,:) )            ! 3D j-current
-      CALL iom_put(  "ssv", vn(:,:,1) )            ! surface j-current
-      IF ( iom_use("sbv") ) THEN
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ikbot = mbkv(ji,jj)
-               z2d(ji,jj) = vn(ji,jj,ikbot)
-            END DO
-         END DO
-         CALL iom_put( "sbv", z2d )                ! bottom j-current
-      ENDIF
-
-      CALL iom_put( "woce", wn )                   ! vertical velocity
-      IF( iom_use('w_masstr') .OR. iom_use('w_masstr2') ) THEN   ! vertical mass transport & its square value
-         ! Caution: in the VVL case, it only correponds to the baroclinic mass transport.
-         z2d(:,:) = rau0 * e1e2t(:,:)
-         DO jk = 1, jpk
-            z3d(:,:,jk) = wn(:,:,jk) * z2d(:,:)
-         END DO
-         CALL iom_put( "w_masstr" , z3d )  
-         IF( iom_use('w_masstr2') )   CALL iom_put( "w_masstr2", z3d(:,:,:) * z3d(:,:,:) )
-      ENDIF
-
-      CALL iom_put( "avt" , avt )                  ! T vert. eddy diff. coef.
-      CALL iom_put( "avs" , avs )                  ! S vert. eddy diff. coef.
-      CALL iom_put( "avm" , avm )                  ! T vert. eddy visc. coef.
-
-      IF( iom_use('logavt') )   CALL iom_put( "logavt", LOG( MAX( 1.e-20_wp, avt(:,:,:) ) ) )
-      IF( iom_use('logavs') )   CALL iom_put( "logavs", LOG( MAX( 1.e-20_wp, avs(:,:,:) ) ) )
-
-      IF ( iom_use("sstgrad") .OR. iom_use("sstgrad2") ) THEN
-         DO jj = 2, jpjm1                                    ! sst gradient
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zztmp  = tsn(ji,jj,1,jp_tem)
-               zztmpx = ( tsn(ji+1,jj,1,jp_tem) - zztmp ) * r1_e1u(ji,jj) + ( zztmp - tsn(ji-1,jj  ,1,jp_tem) ) * r1_e1u(ji-1,jj)
-               zztmpy = ( tsn(ji,jj+1,1,jp_tem) - zztmp ) * r1_e2v(ji,jj) + ( zztmp - tsn(ji  ,jj-1,1,jp_tem) ) * r1_e2v(ji,jj-1)
-               z2d(ji,jj) = 0.25 * ( zztmpx * zztmpx + zztmpy * zztmpy )   &
-                  &              * umask(ji,jj,1) * umask(ji-1,jj,1) * vmask(ji,jj,1) * umask(ji,jj-1,1)
-            END DO
-         END DO
-         CALL lbc_lnk( 'diawri', z2d, 'T', 1. )
-         CALL iom_put( "sstgrad2",  z2d )          ! square of module of sst gradient
-         z2d(:,:) = SQRT( z2d(:,:) )
-         CALL iom_put( "sstgrad" ,  z2d )          ! module of sst gradient
-      ENDIF
-         
-      ! heat and salt contents
-      IF( iom_use("heatc") ) THEN
-         z2d(:,:)  = 0._wp 
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  z2d(ji,jj) = z2d(ji,jj) + e3t_n(ji,jj,jk) * tsn(ji,jj,jk,jp_tem) * tmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         CALL iom_put( "heatc", rau0_rcp * z2d )   ! vertically integrated heat content (J/m2)
-      ENDIF
-
-      IF( iom_use("saltc") ) THEN
-         z2d(:,:)  = 0._wp 
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  z2d(ji,jj) = z2d(ji,jj) + e3t_n(ji,jj,jk) * tsn(ji,jj,jk,jp_sal) * tmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         CALL iom_put( "saltc", rau0 * z2d )          ! vertically integrated salt content (PSU*kg/m2)
-      ENDIF
-      !
-      IF ( iom_use("eken") ) THEN
-         z3d(:,:,jpk) = 0._wp 
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zztmp  = 0.25_wp * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
-                  z3d(ji,jj,jk) = zztmp * (  un(ji-1,jj,jk)**2 * e2u(ji-1,jj) * e3u_n(ji-1,jj,jk)   &
-                     &                     + un(ji  ,jj,jk)**2 * e2u(ji  ,jj) * e3u_n(ji  ,jj,jk)   &
-                     &                     + vn(ji,jj-1,jk)**2 * e1v(ji,jj-1) * e3v_n(ji,jj-1,jk)   &
-                     &                     + vn(ji,jj  ,jk)**2 * e1v(ji,jj  ) * e3v_n(ji,jj  ,jk)   )
-               END DO
-            END DO
-         END DO
-         CALL lbc_lnk( 'diawri', z3d, 'T', 1. )
-         CALL iom_put( "eken", z3d )                 ! kinetic energy
-      ENDIF
-      !
-      CALL iom_put( "hdiv", hdivn )                  ! Horizontal divergence
-      !
-      IF( iom_use("u_masstr") .OR. iom_use("u_masstr_vint") .OR. iom_use("u_heattr") .OR. iom_use("u_salttr") ) THEN
-         z3d(:,:,jpk) = 0.e0
-         z2d(:,:) = 0.e0
-         DO jk = 1, jpkm1
-            z3d(:,:,jk) = rau0 * un(:,:,jk) * e2u(:,:) * e3u_n(:,:,jk) * umask(:,:,jk)
-            z2d(:,:) = z2d(:,:) + z3d(:,:,jk)
-         END DO
-         CALL iom_put( "u_masstr"     , z3d )         ! mass transport in i-direction
-         CALL iom_put( "u_masstr_vint", z2d )         ! mass transport in i-direction vertical sum
-      ENDIF
-      
-      IF( iom_use("u_heattr") ) THEN
-         z2d(:,:) = 0._wp 
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
-               END DO
-            END DO
-         END DO
-         CALL lbc_lnk( 'diawri', z2d, 'U', -1. )
-         CALL iom_put( "u_heattr", 0.5*rcp * z2d )    ! heat transport in i-direction
-      ENDIF
-
-      IF( iom_use("u_salttr") ) THEN
-         z2d(:,:) = 0.e0 
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( tsn(ji,jj,jk,jp_sal) + tsn(ji+1,jj,jk,jp_sal) )
-               END DO
-            END DO
-         END DO
-         CALL lbc_lnk( 'diawri', z2d, 'U', -1. )
-         CALL iom_put( "u_salttr", 0.5 * z2d )        ! heat transport in i-direction
-      ENDIF
-
-      
-      IF( iom_use("v_masstr") .OR. iom_use("v_heattr") .OR. iom_use("v_salttr") ) THEN
-         z3d(:,:,jpk) = 0.e0
-         DO jk = 1, jpkm1
-            z3d(:,:,jk) = rau0 * vn(:,:,jk) * e1v(:,:) * e3v_n(:,:,jk) * vmask(:,:,jk)
-         END DO
-         CALL iom_put( "v_masstr", z3d )              ! mass transport in j-direction
-      ENDIF
-      
-      IF( iom_use("v_heattr") ) THEN
-         z2d(:,:) = 0.e0 
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( tsn(ji,jj,jk,jp_tem) + tsn(ji,jj+1,jk,jp_tem) )
-               END DO
-            END DO
-         END DO
-         CALL lbc_lnk( 'diawri', z2d, 'V', -1. )
-         CALL iom_put( "v_heattr", 0.5*rcp * z2d )    !  heat transport in j-direction
-      ENDIF
-
-      IF( iom_use("v_salttr") ) THEN
-         z2d(:,:) = 0._wp 
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( tsn(ji,jj,jk,jp_sal) + tsn(ji,jj+1,jk,jp_sal) )
-               END DO
-            END DO
-         END DO
-         CALL lbc_lnk( 'diawri', z2d, 'V', -1. )
-         CALL iom_put( "v_salttr", 0.5 * z2d )        !  heat transport in j-direction
-      ENDIF
-
-      IF( iom_use("tosmint") ) THEN
-         z2d(:,:) = 0._wp
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z2d(ji,jj) = z2d(ji,jj) + e3t_n(ji,jj,jk) *  tsn(ji,jj,jk,jp_tem)
-               END DO
-            END DO
-         END DO
-         CALL lbc_lnk( 'diawri', z2d, 'T', -1. )
-         CALL iom_put( "tosmint", rau0 * z2d )        ! Vertical integral of temperature
-      ENDIF
-      IF( iom_use("somint") ) THEN
-         z2d(:,:)=0._wp
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z2d(ji,jj) = z2d(ji,jj) + e3t_n(ji,jj,jk) * tsn(ji,jj,jk,jp_sal)
-               END DO
-            END DO
-         END DO
-         CALL lbc_lnk( 'diawri', z2d, 'T', -1. )
-         CALL iom_put( "somint", rau0 * z2d )         ! Vertical integral of salinity
-      ENDIF
-
-      CALL iom_put( "bn2", rn2 )                      ! Brunt-Vaisala buoyancy frequency (N^2)
-      !
-
-      IF (ln_diatmb)   CALL dia_tmb                   ! tmb values 
-          
-      IF (ln_dia25h)   CALL dia_25h( kt )             ! 25h averaging
-
-      IF( ln_timing )   CALL timing_stop('dia_wri')
-      !
-   END SUBROUTINE dia_wri
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                                  use IOIPSL  library
-   !!----------------------------------------------------------------------
-
-   INTEGER FUNCTION dia_wri_alloc()
-      !
-      dia_wri_alloc = 0
-      !
-   END FUNCTION dia_wri_alloc
-
-   SUBROUTINE dia_wri( kt )
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-
-      IF( ninist == 1 ) THEN     !==  Output the initial state and forcings  ==!
-         CALL dia_wri_state( 'output.init' )
-         ninist = 0
-      ENDIF
-
-   END SUBROUTINE dia_wri
-
-#endif
-
-   SUBROUTINE dia_wri_state( cdfile_name )
-      !!---------------------------------------------------------------------
-      !!                 ***  ROUTINE dia_wri_state  ***
-      !!        
-      !! ** Purpose :   create a NetCDF file named cdfile_name which contains 
-      !!      the instantaneous ocean state and forcing fields.
-      !!        Used to find errors in the initial state or save the last
-      !!      ocean state in case of abnormal end of a simulation
-      !!
-      !! ** Method  :   NetCDF files using ioipsl
-      !!      File 'output.init.nc'  is created if ninist = 1 (namelist)
-      !!      File 'output.abort.nc' is created in case of abnormal job end
-      !!----------------------------------------------------------------------
-      CHARACTER (len=* ), INTENT( in ) ::   cdfile_name      ! name of the file created
-      !!
-      INTEGER :: inum
-      !!----------------------------------------------------------------------
-      ! 
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'dia_wri_state : single instantaneous ocean state'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~   and forcing fields file created '
-      IF(lwp) WRITE(numout,*) '                and named :', cdfile_name, '...nc'
-
-#if defined key_si3
-     CALL iom_open( TRIM(cdfile_name), inum, ldwrt = .TRUE., kdlev = jpl )
-#else
-     CALL iom_open( TRIM(cdfile_name), inum, ldwrt = .TRUE. )
-#endif
-
-      CALL iom_rstput( 0, 0, inum, 'votemper', tsn(:,:,:,jp_tem) )    ! now temperature
-      CALL iom_rstput( 0, 0, inum, 'vosaline', tsn(:,:,:,jp_sal) )    ! now salinity
-      CALL iom_rstput( 0, 0, inum, 'sossheig', sshn              )    ! sea surface height
-      CALL iom_rstput( 0, 0, inum, 'vozocrtx', un                )    ! now i-velocity
-      CALL iom_rstput( 0, 0, inum, 'vomecrty', vn                )    ! now j-velocity
-      CALL iom_rstput( 0, 0, inum, 'vovecrtz', wn                )    ! now k-velocity
-      IF( ALLOCATED(ahtu) ) THEN
-         CALL iom_rstput( 0, 0, inum,  'ahtu', ahtu              )    ! aht at u-point
-         CALL iom_rstput( 0, 0, inum,  'ahtv', ahtv              )    ! aht at v-point
-      ENDIF
-      IF( ALLOCATED(ahmt) ) THEN
-         CALL iom_rstput( 0, 0, inum,  'ahmt', ahmt              )    ! ahmt at u-point
-         CALL iom_rstput( 0, 0, inum,  'ahmf', ahmf              )    ! ahmf at v-point
-      ENDIF
-      CALL iom_rstput( 0, 0, inum, 'sowaflup', emp - rnf         )    ! freshwater budget
-      CALL iom_rstput( 0, 0, inum, 'sohefldo', qsr + qns         )    ! total heat flux
-      CALL iom_rstput( 0, 0, inum, 'soshfldo', qsr               )    ! solar heat flux
-      CALL iom_rstput( 0, 0, inum, 'soicecov', fr_i              )    ! ice fraction
-      CALL iom_rstput( 0, 0, inum, 'sozotaux', utau              )    ! i-wind stress
-      CALL iom_rstput( 0, 0, inum, 'sometauy', vtau              )    ! j-wind stress
-      IF(  .NOT.ln_linssh  ) THEN             
-         CALL iom_rstput( 0, 0, inum, 'vovvldep', gdept_n        )    !  T-cell depth 
-         CALL iom_rstput( 0, 0, inum, 'vovvle3t', e3t_n          )    !  T-cell thickness  
-      END IF
-      IF( ln_wave .AND. ln_sdw ) THEN
-         CALL iom_rstput( 0, 0, inum, 'sdzocrtx', usd            )    ! now StokesDrift i-velocity
-         CALL iom_rstput( 0, 0, inum, 'sdmecrty', vsd            )    ! now StokesDrift j-velocity
-         CALL iom_rstput( 0, 0, inum, 'sdvecrtz', wsd            )    ! now StokesDrift k-velocity
-      ENDIF
- 
-#if defined key_si3
-      IF( nn_ice == 2 ) THEN   ! condition needed in case agrif + ice-model but no-ice in child grid
-         CALL ice_wri_state( inum )
-      ENDIF
-#endif
-      !
-      CALL iom_close( inum )
-      ! 
-   END SUBROUTINE dia_wri_state
-
-   !!======================================================================
-END MODULE diawri
Index: /NEMO/trunk/tests/BENCH/MY_SRC/usrdef_istate.F90
===================================================================
--- /NEMO/trunk/tests/BENCH/MY_SRC/usrdef_istate.F90	(revision 11535)
+++ /NEMO/trunk/tests/BENCH/MY_SRC/usrdef_istate.F90	(revision 11536)
@@ -64,5 +64,5 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            z2d(ji,jj) = 0.1 * ( 0.5 - REAL( nimpp + ji - 1 + ( njmpp + jj - 2 ) * jpiglo, wp ) / REAL( jpiglo * jpjglo, wp ) )
+            z2d(ji,jj) = 0.1 * ( 0.5 - REAL( mig(ji) + mjg(jj) * jpiglo, wp ) / REAL( jpiglo * jpjglo, wp ) )
          ENDDO
       ENDDO
@@ -73,7 +73,6 @@
       DO jk = 1, jpk
          zfact = REAL(jk-1,wp) / REAL(jpk-1,wp)   ! 0 to 1 to add a basic stratification
-         ! temperature choosen to lead to 20% ice
-         pts(:,:,jk,jp_tem) = 2._wp - 0.1_wp * zfact + z2d(:,:) * 100._wp ! 2 to 1.9 +/- 5 degG
-         WHERE ( pts(:,:,jk,jp_tem) < -1.5_wp ) pts(:,:,jk,jp_tem) = -1.5_wp + z2d(:,:) * 0.2_wp  
+         ! temperature choosen to lead to ~50% ice at the beginning if rn_thres_sst = 0.5
+         pts(:,:,jk,jp_tem) = 20._wp*z2d(:,:) - 1._wp - 0.5_wp * zfact    ! -1 to -1.5 +/-1.0 degG
          ! salinity:  
          pts(:,:,jk,jp_sal) = 30._wp + 1._wp * zfact + z2d(:,:)           ! 30 to 31 +/- 0.05 psu
@@ -84,7 +83,7 @@
       !
       CALL lbc_lnk('usrdef_istate', pssh, 'T',  1. )            ! apply boundary conditions
-      CALL lbc_lnk( 'usrdef_istate', pts, 'T',  1. )            ! apply boundary conditions
-      CALL lbc_lnk(  'usrdef_istate', pu, 'U', -1. )            ! apply boundary conditions
-      CALL lbc_lnk(  'usrdef_istate', pv, 'V', -1. )            ! apply boundary conditions
+      CALL lbc_lnk('usrdef_istate',  pts, 'T',  1. )            ! apply boundary conditions
+      CALL lbc_lnk('usrdef_istate',   pu, 'U', -1. )            ! apply boundary conditions
+      CALL lbc_lnk('usrdef_istate',   pv, 'V', -1. )            ! apply boundary conditions
       
    END SUBROUTINE usr_def_istate
Index: /NEMO/trunk/tests/BENCH/MY_SRC/usrdef_nam.F90
===================================================================
--- /NEMO/trunk/tests/BENCH/MY_SRC/usrdef_nam.F90	(revision 11535)
+++ /NEMO/trunk/tests/BENCH/MY_SRC/usrdef_nam.F90	(revision 11536)
@@ -29,5 +29,5 @@
 CONTAINS
 
-   SUBROUTINE usr_def_nam( ldtxt, ldnam, cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+   SUBROUTINE usr_def_nam( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -41,5 +41,4 @@
       !! ** input   : - namusr_def namelist found in namelist_cfg
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), DIMENSION(:), INTENT(out) ::   ldtxt, ldnam    ! stored print information
       CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
       INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
@@ -48,5 +47,5 @@
       !
       !
-      INTEGER ::   ios, ii      ! Local integer
+      INTEGER ::   ios         ! Local integer
       !                              !!* namusr_def namelist *!!
       INTEGER ::   nn_isize    ! number of point in i-direction of global(local) domain if >0 (<0)  
@@ -55,29 +54,29 @@
       INTEGER ::   nn_perio    ! periodicity
       !                              !!* nammpp namelist *!!
-      CHARACTER(len=1) ::   cn_mpi_send
-      INTEGER          ::   nn_buffer, jpni, jpnj
+      INTEGER          ::   jpni, jpnj
       LOGICAL          ::   ln_nnogather
       !!
       NAMELIST/namusr_def/ nn_isize, nn_jsize, nn_ksize, nn_perio
-      NAMELIST/nammpp/ cn_mpi_send, nn_buffer, jpni, jpnj, ln_nnogather
+      NAMELIST/nammpp/ jpni, jpnj, ln_nnogather
       !!----------------------------------------------------------------------     
       !
       REWIND( numnam_cfg )          ! Namelist namusr_def (exist in namelist_cfg only)
       READ  ( numnam_cfg, namusr_def, IOSTAT = ios, ERR = 903 )
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist', .TRUE. )
-      WRITE( ldnam(:), namusr_def )      
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist' )
+      !
+      IF(lwm)   WRITE( numond, namusr_def )      
       !
       cd_cfg = 'BENCH'             ! name & resolution (not used)
       kk_cfg = 0
-
+      !
       IF( nn_isize < 0 .AND. nn_jsize < 0 ) THEN
       !
          REWIND( numnam_ref )              ! Namelist nammpp in reference namelist: mpi variables
          READ  ( numnam_ref, nammpp, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 )   CALL ctl_nam ( ios , 'nammpp in reference namelist', lwp )
+901      IF( ios /= 0 )   CALL ctl_nam ( ios , 'nammpp in reference namelist' )
          !
          REWIND( numnam_cfg )              ! Namelist nammpp in configuration namelist: mpi variables
          READ  ( numnam_cfg, nammpp, IOSTAT = ios, ERR = 902 )
-902      IF( ios >  0 )   CALL ctl_nam ( ios , 'nammpp in configuration namelist', lwp )
+902      IF( ios >  0 )   CALL ctl_nam ( ios , 'nammpp in configuration namelist' )
 
          kpi = ( -nn_isize - 2*nn_hls ) * jpni + 2*nn_hls
@@ -87,30 +86,30 @@
          kpj = nn_jsize
       ENDIF
- 
+      !
       kpk = nn_ksize
       kperio = nn_perio
-
       !                             ! control print
-      ii = 1
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~~~~~~ '                                                                 ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Namelist namusr_def : BENCH test case'                                     ;   ii = ii + 1
-      IF( nn_isize > 0 ) THEN
-         WRITE(ldtxt(ii),*) '      global domain size-x            nn_isize = ',  nn_isize              ;   ii = ii + 1
-      ELSE
-         WRITE(ldtxt(ii),*) '                                          jpni = ', jpni                   ;   ii = ii + 1
-         WRITE(ldtxt(ii),*) '       local domain size-x           -nn_isize = ', -nn_isize              ;   ii = ii + 1
-         WRITE(ldtxt(ii),*) '      global domain size-x                 kpi = ', kpi                    ;   ii = ii + 1
+      IF(lwp) THEN
+         WRITE(numout,*) '   '
+         WRITE(numout,*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '   Namelist namusr_def : BENCH test case'
+         IF( nn_isize > 0 ) THEN
+            WRITE(numout,*) '      global domain size-x            nn_isize = ',  nn_isize
+         ELSE
+            WRITE(numout,*) '                                          jpni = ', jpni
+            WRITE(numout,*) '       local domain size-x           -nn_isize = ', -nn_isize
+            WRITE(numout,*) '      global domain size-x                 kpi = ', kpi
+         ENDIF
+         IF( nn_jsize > 0 ) THEN
+            WRITE(numout,*) '      global domain size-y            nn_jsize = ', nn_jsize
+         ELSE
+            WRITE(numout,*) '                                          jpnj = ', jpnj
+            WRITE(numout,*) '       local domain size-y           -nn_jsize = ', -nn_jsize
+            WRITE(numout,*) '      global domain size-y                 kpj = ', kpj
+         ENDIF
+         WRITE(numout,*) '      global domain size-z            nn_ksize = ', nn_ksize
+         WRITE(numout,*) '      LBC of the global domain          kperio = ', kperio
       ENDIF
-      IF( nn_jsize > 0 ) THEN
-         WRITE(ldtxt(ii),*) '      global domain size-y            nn_jsize = ', nn_jsize               ;   ii = ii + 1
-      ELSE
-         WRITE(ldtxt(ii),*) '                                          jpnj = ', jpnj                   ;   ii = ii + 1
-         WRITE(ldtxt(ii),*) '       local domain size-y           -nn_jsize = ', -nn_jsize              ;   ii = ii + 1
-         WRITE(ldtxt(ii),*) '      global domain size-y                 kpj = ', kpj                    ;   ii = ii + 1
-      ENDIF
-      WRITE(ldtxt(ii),*) '      global domain size-z            nn_ksize = ', nn_ksize                  ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      LBC of the global domain          kperio = ', kperio                    ;   ii = ii + 1
       !
    END SUBROUTINE usr_def_nam
Index: /NEMO/trunk/tests/BENCH/MY_SRC/usrdef_zgr.F90
===================================================================
--- /NEMO/trunk/tests/BENCH/MY_SRC/usrdef_zgr.F90	(revision 11535)
+++ /NEMO/trunk/tests/BENCH/MY_SRC/usrdef_zgr.F90	(revision 11536)
@@ -194,4 +194,9 @@
       z2d(:,:) = REAL( jpkm1 , wp )          ! flat bottom
       !
+      IF( jperio == 3 .OR. jperio ==4 ) THEN   ! add a small island in the upper corners to avoid model instabilities...
+         z2d(mi0(       1):mi1(     3),mj0(jpjglo-2):mj1(jpjglo)) = 0.
+         z2d(mi0(jpiglo-2):mi1(jpiglo),mj0(jpjglo-2):mj1(jpjglo)) = 0.
+      ENDIF
+      !
       CALL lbc_lnk( 'usrdef_zgr', z2d, 'T', 1. )           ! set surrounding land to zero (here jperio=0 ==>> closed)
       !
Index: /NEMO/trunk/tests/BENCH/MY_SRC/zdfiwm.F90
===================================================================
--- /NEMO/trunk/tests/BENCH/MY_SRC/zdfiwm.F90	(revision 11535)
+++ /NEMO/trunk/tests/BENCH/MY_SRC/zdfiwm.F90	(revision 11536)
@@ -406,9 +406,9 @@
       REWIND( numnam_ref )              ! Namelist namzdf_iwm in reference namelist : Wave-driven mixing
       READ  ( numnam_ref, namzdf_iwm, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf_iwm in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf_iwm in reference namelist' )
       !
       REWIND( numnam_cfg )              ! Namelist namzdf_iwm in configuration namelist : Wave-driven mixing
       READ  ( numnam_cfg, namzdf_iwm, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namzdf_iwm in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namzdf_iwm in configuration namelist' )
       IF(lwm) WRITE ( numond, namzdf_iwm )
       !
Index: /NEMO/trunk/tests/CANAL/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/trunk/tests/CANAL/EXPREF/context_nemo.xml	(revision 11535)
+++ /NEMO/trunk/tests/CANAL/EXPREF/context_nemo.xml	(revision 11536)
@@ -6,4 +6,14 @@
 <context id="nemo">
 <!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
 <!-- Fields definition -->
     <field_definition src="./field_def_nemo-oce.xml"/>   <!--  NEMO ocean dynamics                     -->
@@ -18,13 +28,13 @@
     
     <axis_definition>
-      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
-      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
-      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
-      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
-      <axis id="nfloat" long_name="Float number"      unit="-"                 />
-      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
-      <axis id="ncatice" long_name="Ice category"       unit="1"               />
-      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
-      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
+      <axis id="deptht"  long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="nfloat"  long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"     unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"      unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"  unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"  unit="degC"              />
     </axis_definition>
  
Index: /NEMO/trunk/tests/CANAL/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/tests/CANAL/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/tests/CANAL/EXPREF/namelist_cfg	(revision 11536)
@@ -275,7 +275,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/tests/CANAL/MY_SRC/diawri.F90
===================================================================
--- /NEMO/trunk/tests/CANAL/MY_SRC/diawri.F90	(revision 11535)
+++ /NEMO/trunk/tests/CANAL/MY_SRC/diawri.F90	(revision 11536)
@@ -531,5 +531,5 @@
       !!      define all the NETCDF files and fields
       !!      At each time step call histdef to compute the mean if ncessary
-      !!      Each nwrite time step, output the instantaneous or mean fields
+      !!      Each nn_write time step, output the instantaneous or mean fields
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
@@ -547,6 +547,4 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: zw3d       ! 3D workspace
       !!----------------------------------------------------------------------
-      ! 
-      IF( ln_timing )   CALL timing_start('dia_wri')
       !
       IF( ninist == 1 ) THEN     !==  Output the initial state and forcings  ==!
@@ -555,4 +553,8 @@
       ENDIF
       !
+      IF( nn_write == -1 )   RETURN   ! we will never do any output
+      ! 
+      IF( ln_timing )   CALL timing_start('dia_wri')
+      !
       ! 0. Initialisation
       ! -----------------
@@ -564,5 +566,5 @@
       clop = "x"         ! no use of the mask value (require less cpu time and otherwise the model crashes)
 #if defined key_diainstant
-      zsto = nwrite * rdt
+      zsto = nn_write * rdt
       clop = "inst("//TRIM(clop)//")"
 #else
@@ -570,5 +572,5 @@
       clop = "ave("//TRIM(clop)//")"
 #endif
-      zout = nwrite * rdt
+      zout = nn_write * rdt
       zmax = ( nitend - nit000 + 1 ) * rdt
 
@@ -601,5 +603,5 @@
          ! WRITE root name in date.file for use by postpro
          IF(lwp) THEN
-            CALL dia_nam( clhstnam, nwrite,' ' )
+            CALL dia_nam( clhstnam, nn_write,' ' )
             CALL ctl_opn( inum, 'date.file', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
             WRITE(inum,*) clhstnam
@@ -609,5 +611,5 @@
          ! Define the T grid FILE ( nid_T )
 
-         CALL dia_nam( clhstnam, nwrite, 'grid_T' )
+         CALL dia_nam( clhstnam, nn_write, 'grid_T' )
          IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
@@ -645,5 +647,5 @@
          ! Define the U grid FILE ( nid_U )
 
-         CALL dia_nam( clhstnam, nwrite, 'grid_U' )
+         CALL dia_nam( clhstnam, nn_write, 'grid_U' )
          IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
          CALL histbeg( clhstnam, jpi, glamu, jpj, gphiu,           &  ! Horizontal grid: glamu and gphiu
@@ -658,5 +660,5 @@
          ! Define the V grid FILE ( nid_V )
 
-         CALL dia_nam( clhstnam, nwrite, 'grid_V' )                   ! filename
+         CALL dia_nam( clhstnam, nn_write, 'grid_V' )                   ! filename
          IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
          CALL histbeg( clhstnam, jpi, glamv, jpj, gphiv,           &  ! Horizontal grid: glamv and gphiv
@@ -671,5 +673,5 @@
          ! Define the W grid FILE ( nid_W )
 
-         CALL dia_nam( clhstnam, nwrite, 'grid_W' )                   ! filename
+         CALL dia_nam( clhstnam, nn_write, 'grid_W' )                   ! filename
          IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
@@ -762,5 +764,5 @@
          ENDIF
 
-         IF( .NOT. ln_cpl ) THEN
+         IF( ln_ssr ) THEN
             CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
                &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
@@ -770,14 +772,5 @@
                &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
          ENDIF
-
-         IF( ln_cpl .AND. nn_ice <= 1 ) THEN
-            CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "sosafldp", "Surface salt flux: Damping"         , "Kg/m2/s",   &  ! erp * sn
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         ENDIF
-         
+       
          clmx ="l_max(only(x))"    ! max index on a period
 !         CALL histdef( nid_T, "sobowlin", "Bowl Index"                         , "W-point",   &  ! bowl INDEX 
@@ -855,5 +848,5 @@
       ! donne le nombre d'elements, et ndex la liste des indices a sortir
 
-      IF( lwp .AND. MOD( itmod, nwrite ) == 0 ) THEN 
+      IF( lwp .AND. MOD( itmod, nn_write ) == 0 ) THEN 
          WRITE(numout,*) 'dia_wri : write model outputs in NetCDF files at ', kt, 'time-step'
          WRITE(numout,*) '~~~~~~ '
@@ -919,14 +912,8 @@
       ENDIF
 
-      IF( .NOT. ln_cpl ) THEN
+      IF( ln_ssr ) THEN
          CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
          CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
-         IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
-         CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
-      ENDIF
-      IF( ln_cpl .AND. nn_ice <= 1 ) THEN
-         CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
-         CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
-         IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
+         zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
          CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
       ENDIF
Index: /NEMO/trunk/tests/CANAL/MY_SRC/domvvl.F90
===================================================================
--- /NEMO/trunk/tests/CANAL/MY_SRC/domvvl.F90	(revision 11535)
+++ /NEMO/trunk/tests/CANAL/MY_SRC/domvvl.F90	(revision 11536)
@@ -994,8 +994,8 @@
       REWIND( numnam_ref )              ! Namelist nam_vvl in reference namelist : 
       READ  ( numnam_ref, nam_vvl, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_vvl in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_vvl in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist nam_vvl in configuration namelist : Parameters of the run
       READ  ( numnam_cfg, nam_vvl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nam_vvl in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nam_vvl in configuration namelist' )
       IF(lwm) WRITE ( numond, nam_vvl )
       !
Index: /NEMO/trunk/tests/CANAL/MY_SRC/usrdef_nam.F90
===================================================================
--- /NEMO/trunk/tests/CANAL/MY_SRC/usrdef_nam.F90	(revision 11535)
+++ /NEMO/trunk/tests/CANAL/MY_SRC/usrdef_nam.F90	(revision 11536)
@@ -58,5 +58,5 @@
 CONTAINS
 
-   SUBROUTINE usr_def_nam( ldtxt, ldnam, cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+   SUBROUTINE usr_def_nam( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -70,5 +70,4 @@
       !! ** input   : - namusr_def namelist found in namelist_cfg
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), DIMENSION(:), INTENT(out) ::   ldtxt, ldnam    ! stored print information
       CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
       INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
@@ -76,6 +75,6 @@
       INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
       !
-      INTEGER ::   ios, ii      ! Local integer
-      REAL(wp)::   zh ! Local scalars
+      INTEGER ::   ios      ! Local integer
+      REAL(wp)::   zh       ! Local scalars
       !!
       NAMELIST/namusr_def/  rn_domszx, rn_domszy, rn_domszz, rn_dx, rn_dy, rn_dz, rn_0xratio, rn_0yratio   &
@@ -85,9 +84,9 @@
       !!----------------------------------------------------------------------
       !
-      ii = 1
-      !
       REWIND( numnam_cfg )          ! Namelist namusr_def (exist in namelist_cfg only)
       READ  ( numnam_cfg, namusr_def, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist', .TRUE. )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist', cdtxt )
+      !
+      IF(lwm)   WRITE( numond, namusr_def )
       !
 #if defined key_agrif 
@@ -103,5 +102,5 @@
 #endif
       !
-      WRITE( ldnam(:), namusr_def )
+      IF(lwm)   WRITE( numond, namusr_def )
       !
       cd_cfg = 'EW_CANAL'             ! name & resolution (not used)
@@ -120,40 +119,40 @@
       !
       zh  = (kpk-1)*rn_dz
-      !                             ! control print
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~~~~~~ '                                                                 ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Namelist namusr_def : EW_CANAL test case'                                  ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal domain size-x          rn_domszx  = ', rn_domszx, ' km'      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal domain size-y          rn_domszy  = ', rn_domszy, ' km'      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      vertical   domain size-z          rn_domszz  = ', rn_domszz, '  m'      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal x-resolution           rn_dx      = ',     rn_dx, ' km'      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal y-resolution           rn_dy      = ',     rn_dy, ' km'      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      vertical resolution               rn_dz      = ',     rn_dz, '  m'      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      x-domain ratio of the 0           rn_0xratio = ', rn_0xratio            ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      y-domain ratio of the 0           rn_0yratio = ', rn_0yratio            ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '          H [m] : ', zh                                                       ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      F computation                     nn_fcase   = ',   nn_fcase            ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      Reference latitude                rn_ppgphi0 = ', rn_ppgphi0            ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      10m wind speed                    rn_u10     = ',     rn_u10, ' m/s'    ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         wind latitudinal extension     rn_windszy = ', rn_windszy, ' km'     ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         wind longitudinal extension    rn_windszx = ', rn_windszx, ' km'     ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         Uoce multiplicative factor     rn_uofac   = ',   rn_uofac            ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      initial Canal max current        rn_vtxmax  = ',  rn_vtxmax, ' m/s'    ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      initial zonal current             rn_uzonal  = ',  rn_uzonal, ' m/s'    ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         Jet latitudinal extension      rn_ujetszy = ', rn_ujetszy, ' km'     ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         Jet longitudinal extension     rn_ujetszx = ', rn_ujetszx, ' km'     ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      bottom definition (0:flat)        nn_botcase = ', nn_botcase            ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      initial condition case            nn_initcase= ', nn_initcase           ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                   (0:rest, 1:zonal current, 10:shear)'                       ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      add random noise on initial ssh   ln_sshnoise= ', ln_sshnoise           ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      Gaussian lambda parameter          rn_lambda = ', rn_lambda             ;   ii = ii + 1
-      !
       !                             ! Set the lateral boundary condition of the global domain
       kperio = 1                    ! EW_CANAL configuration : closed basin
-      !
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Lateral boundary condition of the global domain'                           ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      EW_CANAL : closed basin            jperio = ', kperio                   ;   ii = ii + 1
+      !                             ! control print
+      IF(lwp) THEN
+         WRITE(numout,*) '   '
+         WRITE(numout,*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '   Namelist namusr_def : EW_CANAL test case'
+         WRITE(numout,*) '      horizontal domain size-x          rn_domszx  = ', rn_domszx, ' km'
+         WRITE(numout,*) '      horizontal domain size-y          rn_domszy  = ', rn_domszy, ' km'
+         WRITE(numout,*) '      vertical   domain size-z          rn_domszz  = ', rn_domszz, '  m'
+         WRITE(numout,*) '      horizontal x-resolution           rn_dx      = ',     rn_dx, ' km'
+         WRITE(numout,*) '      horizontal y-resolution           rn_dy      = ',     rn_dy, ' km'
+         WRITE(numout,*) '      vertical resolution               rn_dz      = ',     rn_dz, '  m'
+         WRITE(numout,*) '      x-domain ratio of the 0           rn_0xratio = ', rn_0xratio
+         WRITE(numout,*) '      y-domain ratio of the 0           rn_0yratio = ', rn_0yratio
+         WRITE(numout,*) '          H [m] : ', zh
+         WRITE(numout,*) '      F computation                     nn_fcase   = ',   nn_fcase
+         WRITE(numout,*) '      Reference latitude                rn_ppgphi0 = ', rn_ppgphi0
+         WRITE(numout,*) '      10m wind speed                    rn_u10     = ',     rn_u10, ' m/s'
+         WRITE(numout,*) '         wind latitudinal extension     rn_windszy = ', rn_windszy, ' km'
+         WRITE(numout,*) '         wind longitudinal extension    rn_windszx = ', rn_windszx, ' km'
+         WRITE(numout,*) '         Uoce multiplicative factor     rn_uofac   = ',   rn_uofac
+         WRITE(numout,*) '      initial Canal max current         rn_vtxmax  = ',  rn_vtxmax, ' m/s'
+         WRITE(numout,*) '      initial zonal current             rn_uzonal  = ',  rn_uzonal, ' m/s'
+         WRITE(numout,*) '         Jet latitudinal extension      rn_ujetszy = ', rn_ujetszy, ' km'
+         WRITE(numout,*) '         Jet longitudinal extension     rn_ujetszx = ', rn_ujetszx, ' km'
+         WRITE(numout,*) '      bottom definition (0:flat)        nn_botcase = ', nn_botcase
+         WRITE(numout,*) '      initial condition case            nn_initcase= ', nn_initcase
+         WRITE(numout,*) '                   (0:rest, 1:zonal current, 10:shear)'
+         WRITE(numout,*) '      add random noise on initial ssh   ln_sshnoise= ', ln_sshnoise
+         WRITE(numout,*) '      Gaussian lambda parameter          rn_lambda = ', rn_lambda
+         WRITE(numout,*) '   '
+         WRITE(numout,*) '   Lateral boundary condition of the global domain'
+         WRITE(numout,*) '      EW_CANAL : closed basin               jperio = ', kperio
+      ENDIF
       !
    END SUBROUTINE usr_def_nam
Index: /NEMO/trunk/tests/ICE_ADV1D/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/tests/ICE_ADV1D/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/tests/ICE_ADV1D/EXPREF/namelist_cfg	(revision 11536)
@@ -201,7 +201,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/tests/ICE_ADV1D/EXPREF/namelist_cfg_120pts
===================================================================
--- /NEMO/trunk/tests/ICE_ADV1D/EXPREF/namelist_cfg_120pts	(revision 11535)
+++ /NEMO/trunk/tests/ICE_ADV1D/EXPREF/namelist_cfg_120pts	(revision 11536)
@@ -201,7 +201,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/tests/ICE_ADV1D/EXPREF/namelist_cfg_240pts
===================================================================
--- /NEMO/trunk/tests/ICE_ADV1D/EXPREF/namelist_cfg_240pts	(revision 11535)
+++ /NEMO/trunk/tests/ICE_ADV1D/EXPREF/namelist_cfg_240pts	(revision 11536)
@@ -201,7 +201,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/tests/ICE_ADV1D/EXPREF/namelist_cfg_60pts
===================================================================
--- /NEMO/trunk/tests/ICE_ADV1D/EXPREF/namelist_cfg_60pts	(revision 11535)
+++ /NEMO/trunk/tests/ICE_ADV1D/EXPREF/namelist_cfg_60pts	(revision 11536)
@@ -201,7 +201,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/tests/ICE_ADV1D/MY_SRC/usrdef_nam.F90
===================================================================
--- /NEMO/trunk/tests/ICE_ADV1D/MY_SRC/usrdef_nam.F90	(revision 11535)
+++ /NEMO/trunk/tests/ICE_ADV1D/MY_SRC/usrdef_nam.F90	(revision 11536)
@@ -40,5 +40,5 @@
 CONTAINS
 
-   SUBROUTINE usr_def_nam( ldtxt, ldnam, cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+   SUBROUTINE usr_def_nam( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -52,5 +52,4 @@
       !! ** input   : - namusr_def namelist found in namelist_cfg
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), DIMENSION(:), INTENT(out) ::   ldtxt, ldnam    ! stored print information
       CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
       INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
@@ -58,5 +57,5 @@
       INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
       !
-      INTEGER ::   ios, ii   ! Local integer
+      INTEGER ::   ios       ! Local integer
       REAL(wp)::   zlx, zly  ! Local scalars
       !!
@@ -64,11 +63,9 @@
       !!----------------------------------------------------------------------
       !
-      ii = 1
-      !
       REWIND( numnam_cfg )          ! Namelist namusr_def (exist in namelist_cfg only)
       READ  ( numnam_cfg, namusr_def, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist', .TRUE. )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist' )
       !
-      WRITE( ldnam(:), namusr_def )
+      IF(lwm)   WRITE( numond, namusr_def )
       !
       cd_cfg = 'ICE_ADV1D'           ! name & resolution (not used)
@@ -82,25 +79,25 @@
       zlx = kpi*rn_dx*1.e-3
       zly = kpj*rn_dy*1.e-3
-      !                             ! control print
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~~~~~~ '                                                                 ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Namelist namusr_def : ICE_ADV1D test case'                                 ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal resolution                    rn_dx  = ', rn_dx, ' meters'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal resolution                    rn_dy  = ', rn_dy, ' meters'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      ICE_ADV1D domain  '                                                     ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         LX [km]: ', zlx                                                      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         LY [km]: ', zly                                                      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         resulting global domain size :        jpiglo = ', kpi                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpjglo = ', kpj                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpkglo = ', kpk                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         Coriolis:', ln_corio                                                 ;   ii = ii + 1
-      !
       !                             ! Set the lateral boundary condition of the global domain
       kperio = 0                    ! ICE_ADV1D configuration : bi-periodic basin
-      !
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Lateral boundary condition of the global domain'                           ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      ICE_ADV1D : closed basin                    jperio = ', kperio          ;   ii = ii + 1
+      !                             ! control print
+      IF(lwp) THEN
+         WRITE(numout,*) '   '
+         WRITE(numout,*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '   Namelist namusr_def : ICE_ADV1D test case'
+         WRITE(numout,*) '      horizontal resolution                    rn_dx  = ', rn_dx, ' meters'
+         WRITE(numout,*) '      horizontal resolution                    rn_dy  = ', rn_dy, ' meters'
+         WRITE(numout,*) '      ICE_ADV1D domain  '
+         WRITE(numout,*) '         LX [km]: ', zlx
+         WRITE(numout,*) '         LY [km]: ', zly
+         WRITE(numout,*) '         resulting global domain size :        jpiglo = ', kpi
+         WRITE(numout,*) '                                               jpjglo = ', kpj
+         WRITE(numout,*) '                                               jpkglo = ', kpk
+         WRITE(numout,*) '         Coriolis:', ln_corio
+         WRITE(numout,*) '   '
+         WRITE(numout,*) '   Lateral boundary condition of the global domain'
+         WRITE(numout,*) '      ICE_ADV1D : closed basin                 jperio = ', kperio
+      ENDIF
       !
    END SUBROUTINE usr_def_nam
Index: /NEMO/trunk/tests/ICE_ADV2D/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/tests/ICE_ADV2D/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/tests/ICE_ADV2D/EXPREF/namelist_cfg	(revision 11536)
@@ -201,7 +201,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/tests/ICE_ADV2D/MY_SRC/usrdef_nam.F90
===================================================================
--- /NEMO/trunk/tests/ICE_ADV2D/MY_SRC/usrdef_nam.F90	(revision 11535)
+++ /NEMO/trunk/tests/ICE_ADV2D/MY_SRC/usrdef_nam.F90	(revision 11536)
@@ -40,5 +40,5 @@
 CONTAINS
 
-   SUBROUTINE usr_def_nam( ldtxt, ldnam, cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+   SUBROUTINE usr_def_nam( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -52,5 +52,4 @@
       !! ** input   : - namusr_def namelist found in namelist_cfg
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), DIMENSION(:), INTENT(out) ::   ldtxt, ldnam    ! stored print information
       CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
       INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
@@ -58,5 +57,5 @@
       INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
       !
-      INTEGER ::   ios, ii   ! Local integer
+      INTEGER ::   ios       ! Local integer
       REAL(wp)::   zlx, zly  ! Local scalars
       !!
@@ -64,9 +63,9 @@
       !!----------------------------------------------------------------------
       !
-      ii = 1
-      !
       REWIND( numnam_cfg )          ! Namelist namusr_def (exist in namelist_cfg only)
       READ  ( numnam_cfg, namusr_def, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist', .TRUE. )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist' )
+      !
+      IF(lwm)   WRITE( numond, namusr_def )
       !
 #if defined key_agrif 
@@ -79,18 +78,16 @@
 #endif
       !
-      WRITE( ldnam(:), namusr_def )
+      IF(lwm)   WRITE( numond, namusr_def )
       !
       cd_cfg = 'ICE_ADV2D'           ! name & resolution (not used)
-      kk_cfg = INT( rn_dx )
+      kk_cfg = NINT( rn_dx )
       !
-      ! Global Domain size:  ICE_ADV2D domain is  300 km x 300 Km x 10 m
-      kpi = INT( 300.e3 / rn_dx ) -1
-      kpj = INT( 300.e3 / rn_dy ) -1
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN
+      IF( Agrif_Root() ) THEN        ! Global Domain size:  ICE_AGRIF domain is  300 km x 300 Km x 10 m
+         kpi = NINT( 300.e3 / rn_dx ) - 1
+         kpj = NINT( 300.e3 / rn_dy ) - 1
+      ELSE
          kpi = nbcellsx + 2 + 2*nbghostcells
          kpj = nbcellsy + 2 + 2*nbghostcells
       ENDIF
-#endif
       kpk = 1
       !
@@ -99,30 +96,27 @@
       zlx = kpi*rn_dx*1.e-3
       zly = kpj*rn_dy*1.e-3
+      !
+      IF( Agrif_Root() ) THEN   ;   kperio = 7     ! ICE_AGRIF configuration : bi-periodic basin
+      ELSE                      ;   kperio = 0     ! closed periodicity for the zoom
+      ENDIF
       !                             ! control print
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~~~~~~ '                                                                 ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Namelist namusr_def : ICE_ADV2D test case'                                 ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal resolution                    rn_dx  = ', rn_dx, ' meters'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal resolution                    rn_dy  = ', rn_dy, ' meters'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      ICE_ADV2D domain = 300 km x 300Km x 1 grid-point '                      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         LX [km]: ', zlx                                                      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         LY [km]: ', zly                                                      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         resulting global domain size :        jpiglo = ', kpi                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpjglo = ', kpj                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpkglo = ', kpk                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         Coriolis:', ln_corio                                                 ;   ii = ii + 1
-      !
-      !                             ! Set the lateral boundary condition of the global domain
-      kperio = 7                    ! ICE_ADV2D configuration : bi-periodic basin
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN
-      kperio = 0
+      IF(lwp) THEN
+         WRITE(numout,*) '   '
+         WRITE(numout,*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '   Namelist namusr_def : ICE_ADV2D test case'
+         WRITE(numout,*) '      horizontal resolution                    rn_dx  = ', rn_dx, ' meters'
+         WRITE(numout,*) '      horizontal resolution                    rn_dy  = ', rn_dy, ' meters'
+         WRITE(numout,*) '      ICE_ADV2D domain = 300 km x 300Km x 1 grid-point '
+         WRITE(numout,*) '         LX [km]: ', zlx
+         WRITE(numout,*) '         LY [km]: ', zly
+         WRITE(numout,*) '         resulting global domain size :        jpiglo = ', kpi
+         WRITE(numout,*) '                                               jpjglo = ', kpj
+         WRITE(numout,*) '                                               jpkglo = ', kpk
+         WRITE(numout,*) '         Coriolis:', ln_corio
+         WRITE(numout,*) '   '
+         WRITE(numout,*) '   Lateral boundary condition of the global domain'
+         WRITE(numout,*) '      ICE_ADV2D : bi-periodic basin            jperio = ', kperio
       ENDIF
-#endif
-      !
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Lateral boundary condition of the global domain'                           ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      ICE_ADV2D : bi-periodic basin               jperio = ', kperio          ;   ii = ii + 1
       !
    END SUBROUTINE usr_def_nam
Index: /NEMO/trunk/tests/ICE_AGRIF/EXPREF/1_namelist_cfg
===================================================================
--- /NEMO/trunk/tests/ICE_AGRIF/EXPREF/1_namelist_cfg	(revision 11535)
+++ /NEMO/trunk/tests/ICE_AGRIF/EXPREF/1_namelist_cfg	(revision 11536)
@@ -201,7 +201,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/tests/ICE_AGRIF/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/tests/ICE_AGRIF/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/tests/ICE_AGRIF/EXPREF/namelist_cfg	(revision 11536)
@@ -201,7 +201,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/tests/ICE_AGRIF/MY_SRC/usrdef_nam.F90
===================================================================
--- /NEMO/trunk/tests/ICE_AGRIF/MY_SRC/usrdef_nam.F90	(revision 11535)
+++ /NEMO/trunk/tests/ICE_AGRIF/MY_SRC/usrdef_nam.F90	(revision 11536)
@@ -40,5 +40,5 @@
 CONTAINS
 
-   SUBROUTINE usr_def_nam( ldtxt, ldnam, cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+   SUBROUTINE usr_def_nam( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -52,5 +52,4 @@
       !! ** input   : - namusr_def namelist found in namelist_cfg
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), DIMENSION(:), INTENT(out) ::   ldtxt, ldnam    ! stored print information
       CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
       INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
@@ -58,5 +57,5 @@
       INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
       !
-      INTEGER ::   ios, ii   ! Local integer
+      INTEGER ::   ios       ! Local integer
       REAL(wp)::   zlx, zly  ! Local scalars
       !!
@@ -64,9 +63,9 @@
       !!----------------------------------------------------------------------
       !
-      ii = 1
-      !
       REWIND( numnam_cfg )          ! Namelist namusr_def (exist in namelist_cfg only)
       READ  ( numnam_cfg, namusr_def, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist', .TRUE. )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist' )
+      !
+      IF(lwm)   WRITE( numond, namusr_def )
       !
 #if defined key_agrif 
@@ -79,18 +78,16 @@
 #endif
       !
-      WRITE( ldnam(:), namusr_def )
+      IF(lwm)   WRITE( numond, namusr_def )
       !
       cd_cfg = 'ICE_AGRIF'           ! name & resolution (not used)
-      kk_cfg = INT( rn_dx )
+      kk_cfg = NINT( rn_dx )
       !
-      ! Global Domain size:  ICE_AGRIF domain is  300 km x 300 Km x 10 m
-      kpi = INT( 300.e3 / rn_dx ) -1
-      kpj = INT( 300.e3 / rn_dy ) -1
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN
+      IF( Agrif_Root() ) THEN        ! Global Domain size:  ICE_AGRIF domain is  300 km x 300 Km x 10 m
+         kpi = NINT( 300.e3 / rn_dx ) - 1
+         kpj = NINT( 300.e3 / rn_dy ) - 1
+      ELSE
          kpi = nbcellsx + 2 + 2*nbghostcells
          kpj = nbcellsy + 2 + 2*nbghostcells
       ENDIF
-#endif
       kpk = 1
       !
@@ -99,30 +96,27 @@
       zlx = kpi*rn_dx*1.e-3
       zly = kpj*rn_dy*1.e-3
+      !
+      IF( Agrif_Root() ) THEN   ;   kperio = 7     ! ICE_AGRIF configuration : bi-periodic basin
+      ELSE                      ;   kperio = 0     ! closed periodicity for the zoom
+      ENDIF
       !                             ! control print
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~~~~~~ '                                                                 ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Namelist namusr_def : ICE_AGRIF test case'                                 ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal resolution                    rn_dx  = ', rn_dx, ' meters'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal resolution                    rn_dy  = ', rn_dy, ' meters'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      ICE_AGRIF domain = 300 km x 300Km x 1 grid-point '                      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         LX [km]: ', zlx                                                      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         LY [km]: ', zly                                                      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         resulting global domain size :        jpiglo = ', kpi                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpjglo = ', kpj                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpkglo = ', kpk                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         Coriolis:', ln_corio                                                 ;   ii = ii + 1
-      !
-      !                             ! Set the lateral boundary condition of the global domain
-      kperio = 7                    ! ICE_AGRIF configuration : bi-periodic basin
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN
-      kperio = 0
+      IF(lwp) THEN
+         WRITE(numout,*) '   '
+         WRITE(numout,*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '   Namelist namusr_def : ICE_AGRIF test case'
+         WRITE(numout,*) '      horizontal resolution                    rn_dx  = ', rn_dx, ' meters'
+         WRITE(numout,*) '      horizontal resolution                    rn_dy  = ', rn_dy, ' meters'
+         WRITE(numout,*) '      ICE_AGRIF domain = 300 km x 300Km x 1 grid-point '
+         WRITE(numout,*) '         LX [km]: ', zlx
+         WRITE(numout,*) '         LY [km]: ', zly
+         WRITE(numout,*) '         resulting global domain size :        jpiglo = ', kpi
+         WRITE(numout,*) '                                               jpjglo = ', kpj
+         WRITE(numout,*) '                                               jpkglo = ', kpk
+         WRITE(numout,*) '         Coriolis:', ln_corio
+         WRITE(numout,*) '   '
+         WRITE(numout,*) '   Lateral boundary condition of the global domain'
+         WRITE(numout,*) '      ICE_AGRIF : bi-periodic basin            jperio = ', kperio
       ENDIF
-#endif
-      !
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Lateral boundary condition of the global domain'                           ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      ICE_AGRIF : bi-periodic basin               jperio = ', kperio          ;   ii = ii + 1
       !
    END SUBROUTINE usr_def_nam
Index: /NEMO/trunk/tests/ISOMIP/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/trunk/tests/ISOMIP/EXPREF/context_nemo.xml	(revision 11535)
+++ /NEMO/trunk/tests/ISOMIP/EXPREF/context_nemo.xml	(revision 11536)
@@ -6,4 +6,14 @@
 <context id="nemo">
 <!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
 <!-- Fields definition -->
     <field_definition src="./field_def_nemo-oce.xml"/>   <!--  NEMO ocean dynamics                     -->
@@ -18,13 +28,13 @@
     
     <axis_definition>
-      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
-      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
-      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
-      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
-      <axis id="nfloat" long_name="Float number"      unit="-"                 />
-      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
-      <axis id="ncatice" long_name="Ice category"       unit="1"               />
-      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
-      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
+      <axis id="deptht"  long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="nfloat"  long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"     unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"      unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"  unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"  unit="degC"              />
     </axis_definition>
  
Index: /NEMO/trunk/tests/ISOMIP/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/tests/ISOMIP/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/tests/ISOMIP/EXPREF/namelist_cfg	(revision 11536)
@@ -78,12 +78,12 @@
 !              !           !  (if <0  months)  !   name   !    (logical)   !  (T/F)  ! 'monthly' ! filename ! pairing  ! filename      !
 ! nn_isf == 4
-   sn_fwfisf   = 'rnfisf'  ,         -12       ,'sowflisf',     .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
+   sn_fwfisf   = 'rnfisf'  ,         -12.      ,'sowflisf',     .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
 ! nn_isf == 3
-   sn_rnfisf   = 'rnfisf'  ,         -12       ,'sofwfisf',     .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
+   sn_rnfisf   = 'rnfisf'  ,         -12.      ,'sofwfisf',     .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
 ! nn_isf == 2 and 3
-   sn_depmax_isf = 'rnfisf' ,        -12       ,'sozisfmax' ,   .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
-   sn_depmin_isf = 'rnfisf' ,        -12       ,'sozisfmin' ,   .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
+   sn_depmax_isf = 'rnfisf' ,        -12.      ,'sozisfmax' ,   .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
+   sn_depmin_isf = 'rnfisf' ,        -12.      ,'sozisfmin' ,   .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
 ! nn_isf == 2
-   sn_Leff_isf = 'rnfisf'  ,         -12       ,'Leff'    ,     .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
+   sn_Leff_isf = 'rnfisf'  ,         -12.      ,'Leff'    ,     .false.    , .true.  , 'yearly'  ,  ''      ,   ''     , ''
 ! for all case
    nn_isf      = 1         !  ice shelf melting/freezing
@@ -272,7 +272,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/tests/ISOMIP/MY_SRC/usrdef_nam.F90
===================================================================
--- /NEMO/trunk/tests/ISOMIP/MY_SRC/usrdef_nam.F90	(revision 11535)
+++ /NEMO/trunk/tests/ISOMIP/MY_SRC/usrdef_nam.F90	(revision 11536)
@@ -42,5 +42,5 @@
 CONTAINS
 
-   SUBROUTINE usr_def_nam( ldtxt, ldnam, cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+   SUBROUTINE usr_def_nam( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -54,5 +54,4 @@
       !! ** input   : - namusr_def namelist found in namelist_cfg
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), DIMENSION(:), INTENT(out) ::   ldtxt, ldnam    ! stored print information
       CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
       INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
@@ -60,16 +59,14 @@
       INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
       !
-      INTEGER ::   ios, ii   ! Local integer
+      INTEGER ::   ios   ! Local integer
       !!
       NAMELIST/namusr_def/ ln_zco, ln_zps, ln_sco, rn_e1deg, rn_e2deg, rn_e3
       !!----------------------------------------------------------------------
       !
-      ii = 1
-      !
       REWIND( numnam_cfg )          ! Namelist namusr_def (exist in namelist_cfg only)
       READ  ( numnam_cfg, namusr_def, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist', .TRUE. )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist' )
       !
-      WRITE( ldnam(:), namusr_def )
+      IF(lwm)   WRITE( numond, namusr_def )
       !
       cd_cfg = 'ISOMIP'           ! name & resolution (not used)
@@ -81,29 +78,29 @@
       kpk = INT( rbathy / rn_e3    ) + 1     ! add 1 for t-point in the seafloor
       !
-      !                             ! control print
-      WRITE(ldtxt(ii),*) '   '                                                                              ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'       ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~~~~~~ '                                                                     ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Namelist namusr_def : ISOMIP test case'                                        ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      type of vertical coordinate : '                                             ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         z-coordinate flag                     ln_zco   = ', ln_zco               ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         z-partial-step coordinate flag        ln_zps   = ', ln_zps               ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         s-coordinate flag                     ln_sco   = ', ln_sco               ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      resolution'                                                                 ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         zonal      resolution                 rn_e1deg = ', rn_e1deg, ' degrees' ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         meridional resolution                 rn_e1deg = ', rn_e1deg, ' degrees' ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         vertical   resolution                 rn_e3    = ', rn_e3   , ' meters'  ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      ISOMIP domain = 15° x 10° x 900 m'                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         resulting global domain size :        jpiglo   = ', kpi                  ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpjglo   = ', kpj                  ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpkglo   = ', kpk                  ;   ii = ii + 1
-      !
-      !
       !                             ! Set the lateral boundary condition of the global domain
       kperio = 0                    ! ISOMIP configuration : close basin
       !
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Lateral boundary condition of the global domain'                           ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      ISOMIP : closed basin                    jperio   = ', kperio             ;   ii = ii + 1
+      !                             ! control print
+      IF(lwp) THEN
+         WRITE(numout,*) '   '
+         WRITE(numout,*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '   Namelist namusr_def : ISOMIP test case'
+         WRITE(numout,*) '      type of vertical coordinate : '
+         WRITE(numout,*) '         z-coordinate flag                     ln_zco   = ', ln_zco
+         WRITE(numout,*) '         z-partial-step coordinate flag        ln_zps   = ', ln_zps
+         WRITE(numout,*) '         s-coordinate flag                     ln_sco   = ', ln_sco
+         WRITE(numout,*) '      resolution'
+         WRITE(numout,*) '         zonal      resolution                 rn_e1deg = ', rn_e1deg, ' degrees'
+         WRITE(numout,*) '         meridional resolution                 rn_e1deg = ', rn_e1deg, ' degrees'
+         WRITE(numout,*) '         vertical   resolution                 rn_e3    = ', rn_e3   , ' meters'
+         WRITE(numout,*) '      ISOMIP domain = 15° x 10° x 900 m'
+         WRITE(numout,*) '         resulting global domain size :        jpiglo   = ', kpi
+         WRITE(numout,*) '                                               jpjglo   = ', kpj
+         WRITE(numout,*) '                                               jpkglo   = ', kpk
+         WRITE(numout,*) '   '
+         WRITE(numout,*) '   Lateral boundary condition of the global domain'
+         WRITE(numout,*) '      ISOMIP : closed basin                    jperio   = ', kperio
+      ENDIF
       !
    END SUBROUTINE usr_def_nam
Index: /NEMO/trunk/tests/LOCK_EXCHANGE/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/trunk/tests/LOCK_EXCHANGE/EXPREF/context_nemo.xml	(revision 11535)
+++ /NEMO/trunk/tests/LOCK_EXCHANGE/EXPREF/context_nemo.xml	(revision 11536)
@@ -6,4 +6,14 @@
 <context id="nemo">
 <!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
 <!-- Fields definition -->
     <field_definition src="./field_def_nemo-oce.xml"/>   <!--  NEMO ocean dynamics                     -->
@@ -18,13 +28,13 @@
     
     <axis_definition>
-      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
-      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
-      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
-      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
-      <axis id="nfloat" long_name="Float number"      unit="-"                 />
-      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
-      <axis id="ncatice" long_name="Ice category"       unit="1"               />
-      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
-      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
+      <axis id="deptht"  long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="nfloat"  long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"     unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"      unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"  unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"  unit="degC"              />
     </axis_definition>
  
Index: /NEMO/trunk/tests/LOCK_EXCHANGE/EXPREF/namelist_FCT2_flux_ubs_cfg
===================================================================
--- /NEMO/trunk/tests/LOCK_EXCHANGE/EXPREF/namelist_FCT2_flux_ubs_cfg	(revision 11535)
+++ /NEMO/trunk/tests/LOCK_EXCHANGE/EXPREF/namelist_FCT2_flux_ubs_cfg	(revision 11536)
@@ -277,7 +277,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/tests/LOCK_EXCHANGE/MY_SRC/usrdef_nam.F90
===================================================================
--- /NEMO/trunk/tests/LOCK_EXCHANGE/MY_SRC/usrdef_nam.F90	(revision 11535)
+++ /NEMO/trunk/tests/LOCK_EXCHANGE/MY_SRC/usrdef_nam.F90	(revision 11536)
@@ -38,5 +38,5 @@
 CONTAINS
 
-   SUBROUTINE usr_def_nam( ldtxt, ldnam, cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+   SUBROUTINE usr_def_nam( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -50,5 +50,4 @@
       !! ** input   : - namusr_def namelist found in namelist_cfg
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), DIMENSION(:), INTENT(out) ::   ldtxt, ldnam    ! stored print information
       CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
       INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
@@ -56,16 +55,14 @@
       INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
       !
-      INTEGER ::   ios, ii   ! Local integer
+      INTEGER ::   ios   ! Local integer
       !!
       NAMELIST/namusr_def/ rn_dx, rn_dz
       !!----------------------------------------------------------------------
       !
-      ii = 1
-      !
       REWIND( numnam_cfg )          ! Namelist namusr_def (exist in namelist_cfg only)
       READ  ( numnam_cfg, namusr_def, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist', .TRUE. )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist' )
       !
-      WRITE( ldnam(:), namusr_def )
+      IF(lwm)   WRITE( numond, namusr_def )
       !
       !
@@ -77,23 +74,23 @@
       kpj = 3
       kpk = INT(  20.  / rn_dz ) + 1
-      !
-      !                             ! control print
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~~~~~~ '                                                                 ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Namelist namusr_def : LOCK_EXCHANGE test case'                             ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal resolution                    rn_dx  = ', rn_dx, ' meters'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      vertical   resolution                    rn_dz  = ', rn_dz, ' meters'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      LOCK_EXCHANGE domain = 64 km  x  3 grid-points  x  20 m'                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         resulting global domain size :        jpiglo = ', kpi                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpjglo = ', kpj                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpkglo = ', kpk                ;   ii = ii + 1
-      !
       !                             ! Set the lateral boundary condition of the global domain
       kperio = 0                    ! LOCK_EXCHANGE configuration : closed domain
       !
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Lateral boundary condition of the global domain'                           ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      closed                                   jperio = ', kperio             ;   ii = ii + 1
+      !                             ! control print
+      IF(lwp) THEN
+         WRITE(numout,*) '   '
+         WRITE(numout,*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '   Namelist namusr_def : LOCK_EXCHANGE test case'
+         WRITE(numout,*) '      horizontal resolution                    rn_dx  = ', rn_dx, ' meters'
+         WRITE(numout,*) '      vertical   resolution                    rn_dz  = ', rn_dz, ' meters'
+         WRITE(numout,*) '      LOCK_EXCHANGE domain = 64 km  x  3 grid-points  x  20 m'
+         WRITE(numout,*) '         resulting global domain size :        jpiglo = ', kpi
+         WRITE(numout,*) '                                               jpjglo = ', kpj
+         WRITE(numout,*) '                                               jpkglo = ', kpk
+         WRITE(numout,*) '   '
+         WRITE(numout,*) '   Lateral boundary condition of the global domain'
+         WRITE(numout,*) '      closed                                   jperio = ', kperio
+      ENDIF
       !
    END SUBROUTINE usr_def_nam
Index: /NEMO/trunk/tests/OVERFLOW/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/trunk/tests/OVERFLOW/EXPREF/context_nemo.xml	(revision 11535)
+++ /NEMO/trunk/tests/OVERFLOW/EXPREF/context_nemo.xml	(revision 11536)
@@ -6,4 +6,14 @@
 <context id="nemo">
 <!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
 <!-- Fields definition -->
     <field_definition src="./field_def_nemo-oce.xml"/>   <!--  NEMO ocean dynamics                     -->
@@ -18,13 +28,13 @@
     
     <axis_definition>
-      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
-      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
-      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
-      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
-      <axis id="nfloat" long_name="Float number"      unit="-"                 />
-      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
-      <axis id="ncatice" long_name="Ice category"       unit="1"               />
-      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
-      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
+      <axis id="deptht"  long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="nfloat"  long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"     unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"      unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"  unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"  unit="degC"              />
     </axis_definition>
  
Index: /NEMO/trunk/tests/OVERFLOW/EXPREF/namelist_zps_FCT4_flux_ubs_cfg
===================================================================
--- /NEMO/trunk/tests/OVERFLOW/EXPREF/namelist_zps_FCT4_flux_ubs_cfg	(revision 11535)
+++ /NEMO/trunk/tests/OVERFLOW/EXPREF/namelist_zps_FCT4_flux_ubs_cfg	(revision 11536)
@@ -291,7 +291,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/tests/OVERFLOW/MY_SRC/usrdef_nam.F90
===================================================================
--- /NEMO/trunk/tests/OVERFLOW/MY_SRC/usrdef_nam.F90	(revision 11535)
+++ /NEMO/trunk/tests/OVERFLOW/MY_SRC/usrdef_nam.F90	(revision 11536)
@@ -39,5 +39,5 @@
 CONTAINS
 
-   SUBROUTINE usr_def_nam( ldtxt, ldnam, cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+   SUBROUTINE usr_def_nam( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -51,5 +51,4 @@
       !! ** input   : - namusr_def namelist found in namelist_cfg
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), DIMENSION(:), INTENT(out) ::   ldtxt, ldnam    ! stored print information
       CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
       INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
@@ -57,16 +56,14 @@
       INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
       !
-      INTEGER ::   ios, ii   ! Local integer
+      INTEGER ::   ios   ! Local integer
       !!
       NAMELIST/namusr_def/ ln_zco, ln_zps, ln_sco, rn_dx, rn_dz
       !!----------------------------------------------------------------------
       !
-      ii = 1
-      !
       REWIND( numnam_cfg )          ! Namelist namusr_def (exist in namelist_cfg only)
       READ  ( numnam_cfg, namusr_def, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist', .TRUE. )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist' )
       !
-      WRITE( ldnam(:), namusr_def )
+      IF(lwm)   WRITE( numond, namusr_def )
       !
       cd_cfg = 'OVERFLOW'           ! name & resolution (not used)
@@ -79,25 +76,25 @@
       !
       !                             ! control print
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~~~~~~ '                                                                 ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Namelist namusr_def : OVERFLOW test case'                                  ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      type of vertical coordinate : '                                         ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         z-coordinate flag                     ln_zco = ', ln_zco             ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         z-partial-step coordinate flag        ln_zps = ', ln_zps             ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         s-coordinate flag                     ln_sco = ', ln_sco             ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal resolution                    rn_dx  = ', rn_dx, ' meters'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      vertical   resolution                    rn_dz  = ', rn_dz, ' meters'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      OVERFLOW domain = 200 km x 3 grid-points x 2000 m'                      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         resulting global domain size :        jpiglo = ', kpi                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpjglo = ', kpj                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpkglo = ', kpk                ;   ii = ii + 1
+      WRITE(numout,*) '   '
+      WRITE(numout,*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'
+      WRITE(numout,*) '~~~~~~~~~~~ '
+      WRITE(numout,*) '   Namelist namusr_def : OVERFLOW test case'
+      WRITE(numout,*) '      type of vertical coordinate : '
+      WRITE(numout,*) '         z-coordinate flag                     ln_zco = ', ln_zco
+      WRITE(numout,*) '         z-partial-step coordinate flag        ln_zps = ', ln_zps
+      WRITE(numout,*) '         s-coordinate flag                     ln_sco = ', ln_sco
+      WRITE(numout,*) '      horizontal resolution                    rn_dx  = ', rn_dx, ' meters'
+      WRITE(numout,*) '      vertical   resolution                    rn_dz  = ', rn_dz, ' meters'
+      WRITE(numout,*) '      OVERFLOW domain = 200 km x 3 grid-points x 2000 m'
+      WRITE(numout,*) '         resulting global domain size :        jpiglo = ', kpi
+      WRITE(numout,*) '                                               jpjglo = ', kpj
+      WRITE(numout,*) '                                               jpkglo = ', kpk
       !
       !                             ! Set the lateral boundary condition of the global domain
       kperio = 0                    ! OVERFLOW configuration : close basin
       !
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Lateral boundary condition of the global domain'                           ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      OVERFLOW : closed basin                  jperio = ', kperio             ;   ii = ii + 1
+      WRITE(numout,*) '   '
+      WRITE(numout,*) '   Lateral boundary condition of the global domain'
+      WRITE(numout,*) '      OVERFLOW : closed basin                  jperio = ', kperio
       !
    END SUBROUTINE usr_def_nam
Index: /NEMO/trunk/tests/VORTEX/EXPREF/1_namelist_cfg
===================================================================
--- /NEMO/trunk/tests/VORTEX/EXPREF/1_namelist_cfg	(revision 11535)
+++ /NEMO/trunk/tests/VORTEX/EXPREF/1_namelist_cfg	(revision 11536)
@@ -272,7 +272,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/tests/VORTEX/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/trunk/tests/VORTEX/EXPREF/context_nemo.xml	(revision 11535)
+++ /NEMO/trunk/tests/VORTEX/EXPREF/context_nemo.xml	(revision 11536)
@@ -6,4 +6,14 @@
 <context id="nemo">
 <!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
 <!-- Fields definition -->
     <field_definition src="./field_def_nemo-oce.xml"/>   <!--  NEMO ocean dynamics                     -->
@@ -18,13 +28,13 @@
     
     <axis_definition>
-      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
-      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
-      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
-      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
-      <axis id="nfloat" long_name="Float number"      unit="-"                 />
-      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
-      <axis id="ncatice" long_name="Ice category"       unit="1"               />
-      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
-      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
+      <axis id="deptht"  long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="nfloat"  long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"     unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"      unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"  unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"  unit="degC"              />
     </axis_definition>
  
Index: /NEMO/trunk/tests/VORTEX/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/tests/VORTEX/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/tests/VORTEX/EXPREF/namelist_cfg	(revision 11536)
@@ -263,7 +263,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default; OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
Index: /NEMO/trunk/tests/VORTEX/MY_SRC/domvvl.F90
===================================================================
--- /NEMO/trunk/tests/VORTEX/MY_SRC/domvvl.F90	(revision 11535)
+++ /NEMO/trunk/tests/VORTEX/MY_SRC/domvvl.F90	(revision 11536)
@@ -994,8 +994,8 @@
       REWIND( numnam_ref )              ! Namelist nam_vvl in reference namelist : 
       READ  ( numnam_ref, nam_vvl, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_vvl in reference namelist', lwp )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_vvl in reference namelist' )
       REWIND( numnam_cfg )              ! Namelist nam_vvl in configuration namelist : Parameters of the run
       READ  ( numnam_cfg, nam_vvl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nam_vvl in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nam_vvl in configuration namelist' )
       IF(lwm) WRITE ( numond, nam_vvl )
       !
Index: /NEMO/trunk/tests/VORTEX/MY_SRC/usrdef_nam.F90
===================================================================
--- /NEMO/trunk/tests/VORTEX/MY_SRC/usrdef_nam.F90	(revision 11535)
+++ /NEMO/trunk/tests/VORTEX/MY_SRC/usrdef_nam.F90	(revision 11536)
@@ -40,5 +40,5 @@
 CONTAINS
 
-   SUBROUTINE usr_def_nam( ldtxt, ldnam, cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+   SUBROUTINE usr_def_nam( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -52,5 +52,4 @@
       !! ** input   : - namusr_def namelist found in namelist_cfg
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), DIMENSION(:), INTENT(out) ::   ldtxt, ldnam    ! stored print information
       CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
       INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
@@ -58,5 +57,5 @@
       INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
       !
-      INTEGER ::   ios, ii      ! Local integer
+      INTEGER ::   ios          ! Local integer
       REAL(wp)::   zlx, zly, zh ! Local scalars
       !!
@@ -64,9 +63,7 @@
       !!----------------------------------------------------------------------
       !
-      ii = 1
-      !
       REWIND( numnam_cfg )          ! Namelist namusr_def (exist in namelist_cfg only)
       READ  ( numnam_cfg, namusr_def, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist', .TRUE. )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist' )
       !
 #if defined key_agrif 
@@ -80,43 +77,41 @@
 #endif
       !
-      WRITE( ldnam(:), namusr_def )
+      IF(lwm)   WRITE( numond, namusr_def )
       !
       cd_cfg = 'VORTEX'             ! name & resolution (not used)
-      kk_cfg = INT( rn_dx )
+      kk_cfg = nINT( rn_dx )
       !
-      ! Global Domain size:  VORTEX global domain is  1800 km x 1800 Km x 5000 m
-      kpi = INT( 1800.e3  / rn_dx ) + 3  
-      kpj = INT( 1800.e3  / rn_dy ) + 3 
-      kpk = INT( 5000._wp / rn_dz ) + 1
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN
+      IF( Agrif_Root() ) THEN       ! Global Domain size:  VORTEX global domain is  1800 km x 1800 Km x 5000 m
+         kpi = NINT( 1800.e3  / rn_dx ) + 3  
+         kpj = NINT( 1800.e3  / rn_dy ) + 3 
+      ELSE
          kpi  = nbcellsx + 2 + 2*nbghostcells
          kpj  = nbcellsy + 2 + 2*nbghostcells
       ENDIF
-#endif
+      kpk = NINT( 5000._wp / rn_dz ) + 1
       !
       zlx = (kpi-2)*rn_dx*1.e-3
       zly = (kpj-2)*rn_dy*1.e-3
       zh  = (kpk-1)*rn_dz
-      !                             ! control print
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~~~~~~ '                                                                 ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Namelist namusr_def : VORTEX test case'                                    ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal resolution             rn_dx  = ', rn_dx, ' m'               ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal resolution             rn_dy  = ', rn_dy, ' m'               ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      vertical resolution               rn_dz  = ', rn_dz, ' m'               ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      VORTEX domain: '                                                        ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         LX [km]: ', zlx                                                      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         LY [km]: ', zly                                                      ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '          H [m] : ', zh                                                       ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      Reference latitude            rn_ppgphi0 = ', rn_ppgphi0                ;   ii = ii + 1
-      !
       !                             ! Set the lateral boundary condition of the global domain
       kperio = 0                    ! VORTEX configuration : closed basin
-      !
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Lateral boundary condition of the global domain'                           ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      VORTEX : closed basin            jperio = ', kperio                     ;   ii = ii + 1
+      !                             ! control print
+      IF(lwp) THEN
+         WRITE(numout,*) '   '
+         WRITE(numout,*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '   Namelist namusr_def : VORTEX test case'
+         WRITE(numout,*) '      horizontal resolution             rn_dx  = ', rn_dx, ' m'
+         WRITE(numout,*) '      horizontal resolution             rn_dy  = ', rn_dy, ' m'
+         WRITE(numout,*) '      vertical resolution               rn_dz  = ', rn_dz, ' m'
+         WRITE(numout,*) '      VORTEX domain: '
+         WRITE(numout,*) '         LX [km]: ', zlx
+         WRITE(numout,*) '         LY [km]: ', zly
+         WRITE(numout,*) '          H [m] : ', zh
+         WRITE(numout,*) '      Reference latitude            rn_ppgphi0 = ', rn_ppgphi0
+         WRITE(numout,*) '   '
+         WRITE(numout,*) '   Lateral boundary condition of the global domain'
+         WRITE(numout,*) '      VORTEX : closed basin            jperio = ', kperio
+      ENDIF
       !
    END SUBROUTINE usr_def_nam
Index: /NEMO/trunk/tests/WAD/EXPREF/context_nemo.xml
===================================================================
--- /NEMO/trunk/tests/WAD/EXPREF/context_nemo.xml	(revision 11535)
+++ /NEMO/trunk/tests/WAD/EXPREF/context_nemo.xml	(revision 11536)
@@ -6,4 +6,14 @@
 <context id="nemo">
 <!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
 <!-- Fields definition -->
     <field_definition src="./field_def_nemo-oce.xml"/>   <!--  NEMO ocean dynamics                     -->
@@ -18,13 +28,13 @@
     
     <axis_definition>
-      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
-      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
-      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
-      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
-      <axis id="nfloat" long_name="Float number"      unit="-"                 />
-      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
-      <axis id="ncatice" long_name="Ice category"       unit="1"               />
-      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
-      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
+      <axis id="deptht"  long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="nfloat"  long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"     unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"      unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"  unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"  unit="degC"              />
     </axis_definition>
  
Index: /NEMO/trunk/tests/WAD/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/tests/WAD/EXPREF/namelist_cfg	(revision 11535)
+++ /NEMO/trunk/tests/WAD/EXPREF/namelist_cfg	(revision 11536)
@@ -180,11 +180,15 @@
 &nambdy_dta    !  open boundaries - external data                       
 !-----------------------------------------------------------------------
+   ln_zinterp  = .false.      !  T if a vertical interpolation is required. Variables gdep[tuv] and e3[tuv] must exist in the file
+   !                          !  automatically defined to T if the number of vertical levels in bdy dta /= jpk
+   ln_full_vel = .false.      !  T if [uv]3d are "full" velocities and not only its baroclinic components
+   !                          !  in this case, baroclinic and barotropic velocities will be recomputed -> [uv]2d not needed
+   !
+   cn_dir  =  './'
 !              !  file name      ! frequency (hours) ! variable  ! time interp. !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
 !              !                 !  (if <0  months)  !   name    !  (logical)   !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
-   bn_ssh =     'bdyssh_tc7' ,         1        , 'sshbdy',     .true.     , .true.  ,  'daily'  ,    ''    ,   ''     , ''
-   bn_u2d =     'bdyuv_tc7'  ,         1        , 'ubdy'  ,     .true.     , .true.  ,  'daily'  ,    ''    ,   ''     , ''
-   bn_v2d =     'bdyuv_tc7'  ,         1        , 'vbdy'  ,     .true.     , .true.  ,  'daily'  ,    ''    ,   ''     , ''
-   cn_dir      =    './'   !  root directory for the location of the bulk files
-   ln_full_vel = .false.        !
+   bn_ssh =     'bdyssh_tc7' ,         1.       , 'sshbdy',     .true.     , .true.  ,  'daily'  ,    ''    ,   ''     , ''
+   bn_u2d =     'bdyuv_tc7'  ,         1.       , 'ubdy'  ,     .true.     , .true.  ,  'daily'  ,    ''    ,   ''     , ''
+   bn_v2d =     'bdyuv_tc7'  ,         1.       , 'vbdy'  ,     .true.     , .true.  ,  'daily'  ,    ''    ,   ''     , ''
 /
 !-----------------------------------------------------------------------
@@ -417,7 +421,7 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-!!   namflo       float parameters                                      ("key_float")
-!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
-!!   namdct       transports through some sections                      ("key_diadct")
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
 !!   nam_diatmb   Top Middle Bottom Output                              (default: OFF)
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
@@ -439,6 +443,7 @@
 /
 !-----------------------------------------------------------------------
-&namdct        ! transports through some sections                       ("key_diadct")
-!-----------------------------------------------------------------------
+&nam_diadct    !   transports through some sections                     (default: OFF)
+!-----------------------------------------------------------------------
+    ln_diadct  = .false.   ! Calculate transport thru sections or not
     nn_dct      = 60       !  time step frequency for transports computing
     nn_dctwri   = 60       !  time step frequency for transports writing
Index: MO/trunk/tests/WAD/MY_SRC/bdyini.F90
===================================================================
--- /NEMO/trunk/tests/WAD/MY_SRC/bdyini.F90	(revision 11535)
+++ 	(revision )
@@ -1,1702 +1,0 @@
-MODULE bdyini
-   !!======================================================================
-   !!                       ***  MODULE  bdyini  ***
-   !! Unstructured open boundaries : initialisation
-   !!======================================================================
-   !! History :  1.0  !  2005-01  (J. Chanut, A. Sellar)  Original code
-   !!             -   !  2007-01  (D. Storkey) Update to use IOM module
-   !!             -   !  2007-01  (D. Storkey) Tidal forcing
-   !!            3.0  !  2008-04  (NEMO team)  add in the reference version
-   !!            3.3  !  2010-09  (E.O'Dea) updates for Shelf configurations
-   !!            3.3  !  2010-09  (D.Storkey) add ice boundary conditions
-   !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
-   !!            3.4  !  2012     (J. Chanut) straight open boundary case update
-   !!            3.5  !  2012     (S. Mocavero, I. Epicoco) optimization of BDY communications
-   !!            3.7  !  2016     (T. Lovato) Remove bdy macro, call here init for dta and tides
-   !!----------------------------------------------------------------------
-   !!   bdy_init      : Initialization of unstructured open boundaries
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers variables
-   USE dom_oce        ! ocean space and time domain
-   USE bdy_oce        ! unstructured open boundary conditions
-   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
-   !
-   USE in_out_manager ! I/O units
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp        ! for mpp_sum  
-   USE iom            ! I/O
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   bdy_init   ! routine called in nemo_init
-
-   INTEGER, PARAMETER ::   jp_nseg = 100   ! 
-   INTEGER, PARAMETER ::   nrimmax =  20   ! maximum rimwidth in structured
-                                               ! open boundary data files
-   ! Straight open boundary segment parameters:
-   INTEGER  ::   nbdysege, nbdysegw, nbdysegn, nbdysegs 
-   INTEGER, DIMENSION(jp_nseg) ::   jpieob, jpjedt, jpjeft, npckge   !
-   INTEGER, DIMENSION(jp_nseg) ::   jpiwob, jpjwdt, jpjwft, npckgw   !
-   INTEGER, DIMENSION(jp_nseg) ::   jpjnob, jpindt, jpinft, npckgn   !
-   INTEGER, DIMENSION(jp_nseg) ::   jpjsob, jpisdt, jpisft, npckgs   !
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id$ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-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, nn_ice_dta,                                     &
-         &             rn_ice_tem, rn_ice_sal, rn_ice_age,                     &
-         &             ln_vol, nn_volctl, nn_rimwidth, nb_jpk_bdy
-         !
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      !!----------------------------------------------------------------------
-
-      ! ------------------------
-      ! 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 )
-
-      IF( .NOT. Agrif_Root() ) ln_bdy = .FALSE.   ! forced for Agrif children
-      
-      ! -----------------------------------------
-      ! 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
-      !
-   END SUBROUTINE bdy_init
-
-
-   SUBROUTINE bdy_segs
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE bdy_init  ***
-      !!         
-      !! ** Purpose :   Definition of 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
-      !!----------------------------------------------------------------------      
-      INTEGER  ::   ib_bdy, ii, ij, ik, igrd, ib, ir, iseg ! dummy loop indices
-      INTEGER  ::   icount, icountr, ibr_max, ilen1, ibm1  ! local integers
-      INTEGER  ::   iwe, ies, iso, ino, inum, id_dummy     !   -       -
-      INTEGER  ::   igrd_start, igrd_end, jpbdta           !   -       -
-      INTEGER  ::   jpbdtau, jpbdtas                       !   -       -
-      INTEGER  ::   ib_bdy1, ib_bdy2, ib1, ib2             !   -       -
-      INTEGER  ::   i_offset, j_offset                     !   -       -
-      INTEGER , POINTER  ::  nbi, nbj, nbr                 ! short cuts
-      REAL(wp), POINTER  ::  flagu, flagv                  !    -   -
-      REAL(wp), POINTER, DIMENSION(:,:)       ::   pmask    ! pointer to 2D mask fields
-      REAL(wp) ::   zefl, zwfl, znfl, zsfl                 ! local scalars
-      INTEGER, DIMENSION (2)                  ::   kdimsz
-      INTEGER, DIMENSION(jpbgrd,jp_bdy)       ::   nblendta         ! Length of index arrays 
-      INTEGER, ALLOCATABLE, DIMENSION(:,:,:)  ::   nbidta, nbjdta   ! Index arrays: i and j indices of bdy dta
-      INTEGER, ALLOCATABLE, DIMENSION(:,:,:)  ::   nbrdta           ! Discrete distance from rim points
-      CHARACTER(LEN=1),DIMENSION(jpbgrd)      ::   cgrid
-      INTEGER :: com_east, com_west, com_south, com_north          ! Flags for boundaries sending
-      INTEGER :: com_east_b, com_west_b, com_south_b, com_north_b  ! Flags for boundaries receiving
-      INTEGER :: iw_b(4), ie_b(4), is_b(4), in_b(4)                ! Arrays for neighbours coordinates
-      REAL(wp), TARGET, DIMENSION(jpi,jpj) ::   zfmask  ! temporary fmask array excluding coastal boundary condition (shlat)
-      !!
-      CHARACTER(LEN=1)                     ::   ctypebdy   !     -        - 
-      INTEGER                              ::   nbdyind, nbdybeg, nbdyend
-      !!
-      NAMELIST/nambdy_index/ ctypebdy, nbdyind, nbdybeg, nbdyend
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      !!----------------------------------------------------------------------
-      !
-      cgrid = (/'t','u','v'/)
-
-      ! -----------------------------------------
-      ! Check and write out namelist parameters
-      ! -----------------------------------------
-      IF( jperio /= 0 )   CALL ctl_stop( 'bdy_segs: Cyclic or symmetric,',   &
-         &                               ' and general open boundary condition are not compatible' )
-
-      IF( nb_bdy == 0 ) THEN 
-        IF(lwp) WRITE(numout,*) 'nb_bdy = 0, NO OPEN BOUNDARIES APPLIED.'
-      ELSE
-        IF(lwp) WRITE(numout,*) 'Number of open boundary sets : ', nb_bdy
-      ENDIF
-
-      DO ib_bdy = 1,nb_bdy
-        IF(lwp) WRITE(numout,*) ' ' 
-        IF(lwp) WRITE(numout,*) '------ Open boundary data set ',ib_bdy,'------' 
-
-        IF( ln_coords_file(ib_bdy) ) THEN
-           IF(lwp) WRITE(numout,*) 'Boundary definition read from file '//TRIM(cn_coords_file(ib_bdy))
-        ELSE
-           IF(lwp) WRITE(numout,*) 'Boundary defined in namelist.'
-        ENDIF
-        IF(lwp) WRITE(numout,*)
-
-        IF(lwp) WRITE(numout,*) 'Boundary conditions for barotropic solution:  '
-        SELECT CASE( cn_dyn2d(ib_bdy) )                  
-          CASE( 'none' )         
-             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-             dta_bdy(ib_bdy)%ll_ssh = .false.
-             dta_bdy(ib_bdy)%ll_u2d = .false.
-             dta_bdy(ib_bdy)%ll_v2d = .false.
-          CASE( 'frs' )          
-             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-             dta_bdy(ib_bdy)%ll_ssh = .false.
-             dta_bdy(ib_bdy)%ll_u2d = .true.
-             dta_bdy(ib_bdy)%ll_v2d = .true.
-          CASE( 'flather' )      
-             IF(lwp) WRITE(numout,*) '      Flather radiation condition'
-             dta_bdy(ib_bdy)%ll_ssh = .true.
-             dta_bdy(ib_bdy)%ll_u2d = .true.
-             dta_bdy(ib_bdy)%ll_v2d = .true.
-          CASE( 'orlanski' )     
-             IF(lwp) WRITE(numout,*) '      Orlanski (fully oblique) radiation condition with adaptive nudging'
-             dta_bdy(ib_bdy)%ll_ssh = .false.
-             dta_bdy(ib_bdy)%ll_u2d = .true.
-             dta_bdy(ib_bdy)%ll_v2d = .true.
-          CASE( 'orlanski_npo' ) 
-             IF(lwp) WRITE(numout,*) '      Orlanski (NPO) radiation condition with adaptive nudging'
-             dta_bdy(ib_bdy)%ll_ssh = .false.
-             dta_bdy(ib_bdy)%ll_u2d = .true.
-             dta_bdy(ib_bdy)%ll_v2d = .true.
-          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_dyn2d' )
-        END SELECT
-        IF( cn_dyn2d(ib_bdy) /= 'none' ) THEN
-           SELECT CASE( nn_dyn2d_dta(ib_bdy) )                   ! 
-              CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
-              CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
-              CASE( 2 )      ;   IF(lwp) WRITE(numout,*) '      tidal harmonic forcing taken from file'
-              CASE( 3 )      ;   IF(lwp) WRITE(numout,*) '      boundary data AND tidal harmonic forcing taken from files'
-              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.ln_tide)) THEN
-             CALL ctl_stop( 'You must activate with ln_tide to add tidal forcing at open boundaries' )
-           ENDIF
-        ENDIF
-        IF(lwp) WRITE(numout,*)
-
-        IF(lwp) WRITE(numout,*) 'Boundary conditions for baroclinic velocities:  '
-        SELECT CASE( cn_dyn3d(ib_bdy) )                  
-          CASE('none')
-             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-             dta_bdy(ib_bdy)%ll_u3d = .false.
-             dta_bdy(ib_bdy)%ll_v3d = .false.
-          CASE('frs')       
-             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-             dta_bdy(ib_bdy)%ll_u3d = .true.
-             dta_bdy(ib_bdy)%ll_v3d = .true.
-          CASE('specified')
-             IF(lwp) WRITE(numout,*) '      Specified value'
-             dta_bdy(ib_bdy)%ll_u3d = .true.
-             dta_bdy(ib_bdy)%ll_v3d = .true.
-          CASE('neumann')
-             IF(lwp) WRITE(numout,*) '      Neumann conditions'
-             dta_bdy(ib_bdy)%ll_u3d = .false.
-             dta_bdy(ib_bdy)%ll_v3d = .false.
-          CASE('zerograd')
-             IF(lwp) WRITE(numout,*) '      Zero gradient for baroclinic velocities'
-             dta_bdy(ib_bdy)%ll_u3d = .false.
-             dta_bdy(ib_bdy)%ll_v3d = .false.
-          CASE('zero')
-             IF(lwp) WRITE(numout,*) '      Zero baroclinic velocities (runoff case)'
-             dta_bdy(ib_bdy)%ll_u3d = .false.
-             dta_bdy(ib_bdy)%ll_v3d = .false.
-          CASE('orlanski')
-             IF(lwp) WRITE(numout,*) '      Orlanski (fully oblique) radiation condition with adaptive nudging'
-             dta_bdy(ib_bdy)%ll_u3d = .true.
-             dta_bdy(ib_bdy)%ll_v3d = .true.
-          CASE('orlanski_npo')
-             IF(lwp) WRITE(numout,*) '      Orlanski (NPO) radiation condition with adaptive nudging'
-             dta_bdy(ib_bdy)%ll_u3d = .true.
-             dta_bdy(ib_bdy)%ll_v3d = .true.
-          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_dyn3d' )
-        END SELECT
-        IF( cn_dyn3d(ib_bdy) /= 'none' ) THEN
-           SELECT CASE( nn_dyn3d_dta(ib_bdy) )                   ! 
-              CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
-              CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
-              CASE DEFAULT   ;   CALL ctl_stop( 'nn_dyn3d_dta must be 0 or 1' )
-           END SELECT
-        ENDIF
-
-        IF ( ln_dyn3d_dmp(ib_bdy) ) THEN
-           IF ( cn_dyn3d(ib_bdy) == 'none' ) THEN
-              IF(lwp) WRITE(numout,*) 'No open boundary condition for baroclinic velocities: ln_dyn3d_dmp is set to .false.'
-              ln_dyn3d_dmp(ib_bdy)=.false.
-           ELSEIF ( cn_dyn3d(ib_bdy) == 'frs' ) THEN
-              CALL ctl_stop( 'Use FRS OR relaxation' )
-           ELSE
-              IF(lwp) WRITE(numout,*) '      + baroclinic velocities relaxation zone'
-              IF(lwp) WRITE(numout,*) '      Damping time scale: ',rn_time_dmp(ib_bdy),' days'
-              IF((lwp).AND.rn_time_dmp(ib_bdy)<0) CALL ctl_stop( 'Time scale must be positive' )
-              dta_bdy(ib_bdy)%ll_u3d = .true.
-              dta_bdy(ib_bdy)%ll_v3d = .true.
-           ENDIF
-        ELSE
-           IF(lwp) WRITE(numout,*) '      NO relaxation on baroclinic velocities'
-        ENDIF
-        IF(lwp) WRITE(numout,*)
-
-        IF(lwp) WRITE(numout,*) 'Boundary conditions for temperature and salinity:  '
-        SELECT CASE( cn_tra(ib_bdy) )                  
-          CASE('none')
-             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-             dta_bdy(ib_bdy)%ll_tem = .false.
-             dta_bdy(ib_bdy)%ll_sal = .false.
-          CASE('frs')
-             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-             dta_bdy(ib_bdy)%ll_tem = .true.
-             dta_bdy(ib_bdy)%ll_sal = .true.
-          CASE('specified')
-             IF(lwp) WRITE(numout,*) '      Specified value'
-             dta_bdy(ib_bdy)%ll_tem = .true.
-             dta_bdy(ib_bdy)%ll_sal = .true.
-          CASE('neumann')
-             IF(lwp) WRITE(numout,*) '      Neumann conditions'
-             dta_bdy(ib_bdy)%ll_tem = .false.
-             dta_bdy(ib_bdy)%ll_sal = .false.
-          CASE('runoff')
-             IF(lwp) WRITE(numout,*) '      Runoff conditions : Neumann for T and specified to 0.1 for salinity'
-             dta_bdy(ib_bdy)%ll_tem = .false.
-             dta_bdy(ib_bdy)%ll_sal = .false.
-          CASE('orlanski')
-             IF(lwp) WRITE(numout,*) '      Orlanski (fully oblique) radiation condition with adaptive nudging'
-             dta_bdy(ib_bdy)%ll_tem = .true.
-             dta_bdy(ib_bdy)%ll_sal = .true.
-          CASE('orlanski_npo')
-             IF(lwp) WRITE(numout,*) '      Orlanski (NPO) radiation condition with adaptive nudging'
-             dta_bdy(ib_bdy)%ll_tem = .true.
-             dta_bdy(ib_bdy)%ll_sal = .true.
-          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_tra' )
-        END SELECT
-        IF( cn_tra(ib_bdy) /= 'none' ) THEN
-           SELECT CASE( nn_tra_dta(ib_bdy) )                   ! 
-              CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
-              CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
-              CASE DEFAULT   ;   CALL ctl_stop( 'nn_tra_dta must be 0 or 1' )
-           END SELECT
-        ENDIF
-
-        IF ( ln_tra_dmp(ib_bdy) ) THEN
-           IF ( cn_tra(ib_bdy) == 'none' ) THEN
-              IF(lwp) WRITE(numout,*) 'No open boundary condition for tracers: ln_tra_dmp is set to .false.'
-              ln_tra_dmp(ib_bdy)=.false.
-           ELSEIF ( cn_tra(ib_bdy) == 'frs' ) THEN
-              CALL ctl_stop( 'Use FRS OR relaxation' )
-           ELSE
-              IF(lwp) WRITE(numout,*) '      + T/S relaxation zone'
-              IF(lwp) WRITE(numout,*) '      Damping time scale: ',rn_time_dmp(ib_bdy),' days'
-              IF(lwp) WRITE(numout,*) '      Outflow damping time scale: ',rn_time_dmp_out(ib_bdy),' days'
-              IF((lwp).AND.rn_time_dmp(ib_bdy)<0) CALL ctl_stop( 'Time scale must be positive' )
-              dta_bdy(ib_bdy)%ll_tem = .true.
-              dta_bdy(ib_bdy)%ll_sal = .true.
-           ENDIF
-        ELSE
-           IF(lwp) WRITE(numout,*) '      NO T/S relaxation'
-        ENDIF
-        IF(lwp) WRITE(numout,*)
-
-#if defined key_si3
-         IF(lwp) WRITE(numout,*) 'Boundary conditions for sea ice:  '
-         SELECT CASE( cn_ice(ib_bdy) )                  
-         CASE('none')
-             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-             dta_bdy(ib_bdy)%ll_a_i = .false.
-             dta_bdy(ib_bdy)%ll_h_i = .false.
-             dta_bdy(ib_bdy)%ll_h_s = .false.
-         CASE('frs')
-             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-             dta_bdy(ib_bdy)%ll_a_i = .true.
-             dta_bdy(ib_bdy)%ll_h_i = .true.
-             dta_bdy(ib_bdy)%ll_h_s = .true.
-         CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_ice' )
-         END SELECT
-        IF( cn_ice(ib_bdy) /= 'none' ) THEN 
-           SELECT CASE( nn_ice_dta(ib_bdy) )                   ! 
-              CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
-              CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
-              CASE DEFAULT   ;   CALL ctl_stop( 'nn_ice_dta must be 0 or 1' )
-           END SELECT
-        ENDIF
-        IF(lwp) WRITE(numout,*)
-        IF(lwp) WRITE(numout,*) '      tem of bdy sea-ice = ', rn_ice_tem(ib_bdy)         
-        IF(lwp) WRITE(numout,*) '      sal of bdy sea-ice = ', rn_ice_sal(ib_bdy)         
-        IF(lwp) WRITE(numout,*) '      age of bdy sea-ice = ', rn_ice_age(ib_bdy)         
-#endif
-
-        IF(lwp) WRITE(numout,*) '      Width of relaxation zone = ', nn_rimwidth(ib_bdy)
-        IF(lwp) WRITE(numout,*)
-         !
-      END DO
-
-     IF( nb_bdy > 0 ) THEN
-        IF( ln_vol ) THEN                     ! check volume conservation (nn_volctl value)
-          IF(lwp) WRITE(numout,*) 'Volume correction applied at open boundaries'
-          IF(lwp) WRITE(numout,*)
-          SELECT CASE ( nn_volctl )
-            CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      The total volume will be constant'
-            CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      The total volume will vary according to the surface E-P flux'
-            CASE DEFAULT   ;   CALL ctl_stop( 'nn_volctl must be 0 or 1' )
-          END SELECT
-          IF(lwp) WRITE(numout,*)
-        ELSE
-          IF(lwp) WRITE(numout,*) 'No volume correction applied at open boundaries'
-          IF(lwp) WRITE(numout,*)
-        ENDIF
-        IF( nb_jpk_bdy > 0 ) THEN
-           IF(lwp) WRITE(numout,*) '*** open boundary will be interpolate in the vertical onto the native grid ***'
-        ELSE
-           IF(lwp) WRITE(numout,*) '*** open boundary will be read straight onto the native grid without vertical interpolation ***'
-        ENDIF
-     ENDIF
-
-      ! -------------------------------------------------
-      ! Initialise indices arrays for open boundaries
-      ! -------------------------------------------------
-
-      ! Work out global dimensions of boundary data
-      ! ---------------------------------------------
-      REWIND( numnam_cfg )     
-
-      nblendta(:,:) = 0
-      nbdysege = 0
-      nbdysegw = 0
-      nbdysegn = 0
-      nbdysegs = 0
-      icount   = 0 ! count user defined segments
-      ! Dimensions below are used to allocate arrays to read external data
-      jpbdtas = 1 ! Maximum size of boundary data (structured case)
-      jpbdtau = 1 ! Maximum size of boundary data (unstructured case)
-
-      DO ib_bdy = 1, nb_bdy
-
-         IF( .NOT. ln_coords_file(ib_bdy) ) THEN ! Work out size of global arrays from namelist parameters
- 
-            icount = icount + 1
-            ! No REWIND here because may need to read more than one nambdy_index namelist.
-            ! Read only namelist_cfg to avoid unseccessfull overwrite 
-            ! keep full control of the configuration namelist
-            READ  ( numnam_cfg, nambdy_index, IOSTAT = ios, ERR = 904 )
-904         IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy_index in configuration namelist', lwp )
-            IF(lwm) WRITE ( numond, nambdy_index )
-
-            SELECT CASE ( TRIM(ctypebdy) )
-              CASE( 'N' )
-                 IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
-                    nbdyind  = jpjglo - 2  ! set boundary to whole side of model domain.
-                    nbdybeg  = 2
-                    nbdyend  = jpiglo - 1
-                 ENDIF
-                 nbdysegn = nbdysegn + 1
-                 npckgn(nbdysegn) = ib_bdy ! Save bdy package number
-                 jpjnob(nbdysegn) = nbdyind
-                 jpindt(nbdysegn) = nbdybeg
-                 jpinft(nbdysegn) = nbdyend
-                 !
-              CASE( 'S' )
-                 IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
-                    nbdyind  = 2           ! set boundary to whole side of model domain.
-                    nbdybeg  = 2
-                    nbdyend  = jpiglo - 1
-                 ENDIF
-                 nbdysegs = nbdysegs + 1
-                 npckgs(nbdysegs) = ib_bdy ! Save bdy package number
-                 jpjsob(nbdysegs) = nbdyind
-                 jpisdt(nbdysegs) = nbdybeg
-                 jpisft(nbdysegs) = nbdyend
-                 !
-              CASE( 'E' )
-                 IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
-                    nbdyind  = jpiglo - 2  ! set boundary to whole side of model domain.
-                    nbdybeg  = 2
-                    nbdyend  = jpjglo - 1
-                 ENDIF
-                 nbdysege = nbdysege + 1 
-                 npckge(nbdysege) = ib_bdy ! Save bdy package number
-                 jpieob(nbdysege) = nbdyind
-                 jpjedt(nbdysege) = nbdybeg
-                 jpjeft(nbdysege) = nbdyend
-                 !
-              CASE( 'W' )
-                 IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
-                    nbdyind  = 2           ! set boundary to whole side of model domain.
-                    nbdybeg  = 2
-                    nbdyend  = jpjglo - 1
-                 ENDIF
-                 nbdysegw = nbdysegw + 1
-                 npckgw(nbdysegw) = ib_bdy ! Save bdy package number
-                 jpiwob(nbdysegw) = nbdyind
-                 jpjwdt(nbdysegw) = nbdybeg
-                 jpjwft(nbdysegw) = nbdyend
-                 !
-              CASE DEFAULT   ;   CALL ctl_stop( 'ctypebdy must be N, S, E or W' )
-            END SELECT
-
-            ! For simplicity we assume that in case of straight bdy, arrays have the same length
-            ! (even if it is true that last tangential velocity points
-            ! are useless). This simplifies a little bit boundary data format (and agrees with format
-            ! used so far in obc package)
-
-            nblendta(1:jpbgrd,ib_bdy) =  (nbdyend - nbdybeg + 1) * nn_rimwidth(ib_bdy)
-            jpbdtas = MAX(jpbdtas, (nbdyend - nbdybeg + 1))
-            IF (lwp.and.(nn_rimwidth(ib_bdy)>nrimmax)) &
-            & CALL ctl_stop( 'rimwidth must be lower than nrimmax' )
-
-         ELSE            ! Read size of arrays in boundary coordinates file.
-            CALL iom_open( cn_coords_file(ib_bdy), inum )
-            DO igrd = 1, jpbgrd
-               id_dummy = iom_varid( inum, 'nbi'//cgrid(igrd), kdimsz=kdimsz )  
-               nblendta(igrd,ib_bdy) = MAXVAL(kdimsz)
-               jpbdtau = MAX(jpbdtau, MAXVAL(kdimsz))
-            END DO
-            CALL iom_close( inum )
-            !
-         ENDIF 
-         !
-      END DO ! ib_bdy
-
-      IF (nb_bdy>0) THEN
-         jpbdta = MAXVAL(nblendta(1:jpbgrd,1:nb_bdy))
-
-         ! Allocate arrays
-         !---------------
-         ALLOCATE( nbidta(jpbdta, jpbgrd, nb_bdy), nbjdta(jpbdta, jpbgrd, nb_bdy),    &
-            &      nbrdta(jpbdta, jpbgrd, nb_bdy) )
-
-         IF( nb_jpk_bdy>0 ) THEN
-            ALLOCATE( dta_global(jpbdtau, 1, nb_jpk_bdy) )
-            ALLOCATE( dta_global_z(jpbdtau, 1, nb_jpk_bdy) )
-            ALLOCATE( dta_global_dz(jpbdtau, 1, nb_jpk_bdy) )
-         ELSE
-            ALLOCATE( dta_global(jpbdtau, 1, jpk) )
-            ALLOCATE( dta_global_z(jpbdtau, 1, jpk) ) ! needed ?? TODO
-            ALLOCATE( dta_global_dz(jpbdtau, 1, jpk) )! needed ?? TODO
-         ENDIF
-
-         IF ( icount>0 ) THEN
-            IF( nb_jpk_bdy>0 ) THEN
-               ALLOCATE( dta_global2(jpbdtas, nrimmax, nb_jpk_bdy) )
-               ALLOCATE( dta_global2_z(jpbdtas, nrimmax, nb_jpk_bdy) )
-               ALLOCATE( dta_global2_dz(jpbdtas, nrimmax, nb_jpk_bdy) )
-            ELSE
-               ALLOCATE( dta_global2(jpbdtas, nrimmax, jpk) )
-               ALLOCATE( dta_global2_z(jpbdtas, nrimmax, jpk) ) ! needed ?? TODO
-               ALLOCATE( dta_global2_dz(jpbdtas, nrimmax, jpk) )! needed ?? TODO  
-            ENDIF
-         ENDIF
-         ! 
-      ENDIF
-
-      ! Now look for crossings in user (namelist) defined open boundary segments:
-      !--------------------------------------------------------------------------
-      IF( icount>0 )   CALL bdy_ctl_seg
-
-      ! Calculate global boundary index arrays or read in from file
-      !------------------------------------------------------------               
-      ! 1. Read global index arrays from boundary coordinates file.
-      DO ib_bdy = 1, nb_bdy
-         !
-         IF( ln_coords_file(ib_bdy) ) THEN
-            !
-            CALL iom_open( cn_coords_file(ib_bdy), inum )
-            DO igrd = 1, jpbgrd
-               CALL iom_get( inum, jpdom_unknown, 'nbi'//cgrid(igrd), dta_global(1:nblendta(igrd,ib_bdy),:,1) )
-               DO ii = 1,nblendta(igrd,ib_bdy)
-                  nbidta(ii,igrd,ib_bdy) = INT( dta_global(ii,1,1) )
-               END DO
-               CALL iom_get( inum, jpdom_unknown, 'nbj'//cgrid(igrd), dta_global(1:nblendta(igrd,ib_bdy),:,1) )
-               DO ii = 1,nblendta(igrd,ib_bdy)
-                  nbjdta(ii,igrd,ib_bdy) = INT( dta_global(ii,1,1) )
-               END DO
-               CALL iom_get( inum, jpdom_unknown, 'nbr'//cgrid(igrd), dta_global(1:nblendta(igrd,ib_bdy),:,1) )
-               DO ii = 1,nblendta(igrd,ib_bdy)
-                  nbrdta(ii,igrd,ib_bdy) = INT( dta_global(ii,1,1) )
-               END DO
-               !
-               ibr_max = MAXVAL( nbrdta(:,igrd,ib_bdy) )
-               IF(lwp) WRITE(numout,*)
-               IF(lwp) WRITE(numout,*) ' Maximum rimwidth in file is ', ibr_max
-               IF(lwp) WRITE(numout,*) ' nn_rimwidth from namelist is ', nn_rimwidth(ib_bdy)
-               IF (ibr_max < nn_rimwidth(ib_bdy))   &
-                     CALL ctl_stop( 'nn_rimwidth is larger than maximum rimwidth in file',cn_coords_file(ib_bdy) )
-            END DO
-            CALL iom_close( inum )
-            !
-         ENDIF 
-         !
-      END DO      
-    
-      ! 2. Now fill indices corresponding to straight open boundary arrays:
-      ! East
-      !-----
-      DO iseg = 1, nbdysege
-         ib_bdy = npckge(iseg)
-         !
-         ! ------------ T points -------------
-         igrd=1
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ij = jpjedt(iseg), jpjeft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 2 - ir
-               nbjdta(icount, igrd, ib_bdy) = ij
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-         !
-         ! ------------ U points -------------
-         igrd=2
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ij = jpjedt(iseg), jpjeft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 1 - ir
-               nbjdta(icount, igrd, ib_bdy) = ij
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-         !
-         ! ------------ V points -------------
-         igrd=3
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-!            DO ij = jpjedt(iseg), jpjeft(iseg) - 1
-            DO ij = jpjedt(iseg), jpjeft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 2 - ir
-               nbjdta(icount, igrd, ib_bdy) = ij
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-            nbidta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-            nbjdta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-         ENDDO
-      ENDDO
-      !
-      ! West
-      !-----
-      DO iseg = 1, nbdysegw
-         ib_bdy = npckgw(iseg)
-         !
-         ! ------------ T points -------------
-         igrd=1
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ij = jpjwdt(iseg), jpjwft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1
-               nbjdta(icount, igrd, ib_bdy) = ij
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-         !
-         ! ------------ U points -------------
-         igrd=2
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ij = jpjwdt(iseg), jpjwft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1
-               nbjdta(icount, igrd, ib_bdy) = ij
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-         !
-         ! ------------ V points -------------
-         igrd=3
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-!            DO ij = jpjwdt(iseg), jpjwft(iseg) - 1
-            DO ij = jpjwdt(iseg), jpjwft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1
-               nbjdta(icount, igrd, ib_bdy) = ij
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-            nbidta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-            nbjdta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-         ENDDO
-      ENDDO
-      !
-      ! North
-      !-----
-      DO iseg = 1, nbdysegn
-         ib_bdy = npckgn(iseg)
-         !
-         ! ------------ T points -------------
-         igrd=1
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ii = jpindt(iseg), jpinft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 2 - ir 
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-         !
-         ! ------------ U points -------------
-         igrd=2
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-!            DO ii = jpindt(iseg), jpinft(iseg) - 1
-            DO ii = jpindt(iseg), jpinft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 2 - ir
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-            nbidta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-            nbjdta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-         ENDDO
-         !
-         ! ------------ V points -------------
-         igrd=3
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ii = jpindt(iseg), jpinft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 1 - ir
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-      ENDDO
-      !
-      ! South
-      !-----
-      DO iseg = 1, nbdysegs
-         ib_bdy = npckgs(iseg)
-         !
-         ! ------------ T points -------------
-         igrd=1
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ii = jpisdt(iseg), jpisft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-         !
-         ! ------------ U points -------------
-         igrd=2
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-!            DO ii = jpisdt(iseg), jpisft(iseg) - 1
-            DO ii = jpisdt(iseg), jpisft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-            nbidta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-            nbjdta(icount, igrd, ib_bdy) = -ib_bdy ! Discount this point
-         ENDDO
-         !
-         ! ------------ V points -------------
-         igrd=3
-         icount=0
-         DO ir = 1, nn_rimwidth(ib_bdy)
-            DO ii = jpisdt(iseg), jpisft(iseg)
-               icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1
-               nbrdta(icount, igrd, ib_bdy) = ir
-            ENDDO
-         ENDDO
-      ENDDO
-
-      !  Deal with duplicated points
-      !-----------------------------
-      ! We assign negative indices to duplicated points (to remove them from bdy points to be updated)
-      ! if their distance to the bdy is greater than the other
-      ! If their distance are the same, just keep only one to avoid updating a point twice
-      DO igrd = 1, jpbgrd
-         DO ib_bdy1 = 1, nb_bdy
-            DO ib_bdy2 = 1, nb_bdy
-               IF (ib_bdy1/=ib_bdy2) THEN
-                  DO ib1 = 1, nblendta(igrd,ib_bdy1)
-                     DO ib2 = 1, nblendta(igrd,ib_bdy2)
-                        IF ((nbidta(ib1, igrd, ib_bdy1)==nbidta(ib2, igrd, ib_bdy2)).AND. &
-                        &   (nbjdta(ib1, igrd, ib_bdy1)==nbjdta(ib2, igrd, ib_bdy2))) THEN
-!                           IF ((lwp).AND.(igrd==1)) WRITE(numout,*) ' found coincident point ji, jj:', & 
-!                                                       &              nbidta(ib1, igrd, ib_bdy1),      & 
-!                                                       &              nbjdta(ib2, igrd, ib_bdy2)
-                           ! keep only points with the lowest distance to boundary:
-                           IF (nbrdta(ib1, igrd, ib_bdy1)<nbrdta(ib2, igrd, ib_bdy2)) THEN
-                             nbidta(ib2, igrd, ib_bdy2) =-ib_bdy2
-                             nbjdta(ib2, igrd, ib_bdy2) =-ib_bdy2
-                           ELSEIF (nbrdta(ib1, igrd, ib_bdy1)>nbrdta(ib2, igrd, ib_bdy2)) THEN
-                             nbidta(ib1, igrd, ib_bdy1) =-ib_bdy1
-                             nbjdta(ib1, igrd, ib_bdy1) =-ib_bdy1
-                           ! Arbitrary choice if distances are the same:
-                           ELSE
-                             nbidta(ib1, igrd, ib_bdy1) =-ib_bdy1
-                             nbjdta(ib1, igrd, ib_bdy1) =-ib_bdy1
-                           ENDIF
-                        END IF
-                     END DO
-                  END DO
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      ! Work out dimensions of boundary data on each processor
-      ! ------------------------------------------------------
-
-      ! Rather assume that boundary data indices are given on global domain
-      ! TO BE DISCUSSED ?
-!      iw = mig(1) + 1            ! if monotasking and no zoom, iw=2
-!      ie = mig(1) + nlci-1 - 1   ! if monotasking and no zoom, ie=jpim1
-!      is = mjg(1) + 1            ! if monotasking and no zoom, is=2
-!      in = mjg(1) + nlcj-1 - 1   ! if monotasking and no zoom, in=jpjm1      
-      iwe = mig(1) - 1 + 2         ! if monotasking and no zoom, iw=2
-      ies = mig(1) + nlci-1 - 1  ! if monotasking and no zoom, ie=jpim1
-      iso = mjg(1) - 1 + 2         ! if monotasking and no zoom, is=2
-      ino = mjg(1) + nlcj-1 - 1  ! if monotasking and no zoom, in=jpjm1
-
-      ALLOCATE( nbondi_bdy(nb_bdy))
-      ALLOCATE( nbondj_bdy(nb_bdy))
-      nbondi_bdy(:)=2
-      nbondj_bdy(:)=2
-      ALLOCATE( nbondi_bdy_b(nb_bdy))
-      ALLOCATE( nbondj_bdy_b(nb_bdy))
-      nbondi_bdy_b(:)=2
-      nbondj_bdy_b(:)=2
-
-      ! Work out dimensions of boundary data on each neighbour process
-      IF(nbondi == 0) THEN
-         iw_b(1) = 1 + nimppt(nowe+1)
-         ie_b(1) = 1 + nimppt(nowe+1)+nlcit(nowe+1)-3
-         is_b(1) = 1 + njmppt(nowe+1)
-         in_b(1) = 1 + njmppt(nowe+1)+nlcjt(nowe+1)-3
-
-         iw_b(2) = 1 + nimppt(noea+1)
-         ie_b(2) = 1 + nimppt(noea+1)+nlcit(noea+1)-3
-         is_b(2) = 1 + njmppt(noea+1)
-         in_b(2) = 1 + njmppt(noea+1)+nlcjt(noea+1)-3
-      ELSEIF(nbondi == 1) THEN
-         iw_b(1) = 1 + nimppt(nowe+1)
-         ie_b(1) = 1 + nimppt(nowe+1)+nlcit(nowe+1)-3
-         is_b(1) = 1 + njmppt(nowe+1)
-         in_b(1) = 1 + njmppt(nowe+1)+nlcjt(nowe+1)-3
-      ELSEIF(nbondi == -1) THEN
-         iw_b(2) = 1 + nimppt(noea+1)
-         ie_b(2) = 1 + nimppt(noea+1)+nlcit(noea+1)-3
-         is_b(2) = 1 + njmppt(noea+1)
-         in_b(2) = 1 + njmppt(noea+1)+nlcjt(noea+1)-3
-      ENDIF
-
-      IF(nbondj == 0) THEN
-         iw_b(3) = 1 + nimppt(noso+1)
-         ie_b(3) = 1 + nimppt(noso+1)+nlcit(noso+1)-3
-         is_b(3) = 1 + njmppt(noso+1)
-         in_b(3) = 1 + njmppt(noso+1)+nlcjt(noso+1)-3
-
-         iw_b(4) = 1 + nimppt(nono+1)
-         ie_b(4) = 1 + nimppt(nono+1)+nlcit(nono+1)-3
-         is_b(4) = 1 + njmppt(nono+1)
-         in_b(4) = 1 + njmppt(nono+1)+nlcjt(nono+1)-3
-      ELSEIF(nbondj == 1) THEN
-         iw_b(3) = 1 + nimppt(noso+1)
-         ie_b(3) = 1 + nimppt(noso+1)+nlcit(noso+1)-3
-         is_b(3) = 1 + njmppt(noso+1)
-         in_b(3) = 1 + njmppt(noso+1)+nlcjt(noso+1)-3
-      ELSEIF(nbondj == -1) THEN
-         iw_b(4) = 1 + nimppt(nono+1)
-         ie_b(4) = 1 + nimppt(nono+1)+nlcit(nono+1)-3
-         is_b(4) = 1 + njmppt(nono+1)
-         in_b(4) = 1 + njmppt(nono+1)+nlcjt(nono+1)-3
-      ENDIF
-
-      DO ib_bdy = 1, nb_bdy
-         DO igrd = 1, jpbgrd
-            icount  = 0
-            icountr = 0
-            idx_bdy(ib_bdy)%nblen(igrd)    = 0
-            idx_bdy(ib_bdy)%nblenrim(igrd) = 0
-            DO ib = 1, nblendta(igrd,ib_bdy)
-               ! check that data is in correct order in file
-               ibm1 = MAX(1,ib-1)
-               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_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')
-                  ENDIF    
-               ENDIF
-               ! check if point is in local domain
-               IF(  nbidta(ib,igrd,ib_bdy) >= iwe .AND. nbidta(ib,igrd,ib_bdy) <= ies .AND.   &
-                  & nbjdta(ib,igrd,ib_bdy) >= iso .AND. nbjdta(ib,igrd,ib_bdy) <= ino      ) THEN
-                  !
-                  icount = icount  + 1
-                  !
-                  IF( nbrdta(ib,igrd,ib_bdy) == 1 )   icountr = icountr+1
-               ENDIF
-            END DO
-            idx_bdy(ib_bdy)%nblenrim(igrd) = icountr !: length of rim boundary data on each proc
-            idx_bdy(ib_bdy)%nblen   (igrd) = icount  !: length of boundary data on each proc        
-         END DO  ! igrd
-
-         ! Allocate index arrays for this boundary set
-         !--------------------------------------------
-         ilen1 = MAXVAL( idx_bdy(ib_bdy)%nblen(:) )
-         ALLOCATE( idx_bdy(ib_bdy)%nbi   (ilen1,jpbgrd) ,   &
-            &      idx_bdy(ib_bdy)%nbj   (ilen1,jpbgrd) ,   &
-            &      idx_bdy(ib_bdy)%nbr   (ilen1,jpbgrd) ,   &
-            &      idx_bdy(ib_bdy)%nbd   (ilen1,jpbgrd) ,   &
-            &      idx_bdy(ib_bdy)%nbdout(ilen1,jpbgrd) ,   &
-            &      idx_bdy(ib_bdy)%nbmap (ilen1,jpbgrd) ,   &
-            &      idx_bdy(ib_bdy)%nbw   (ilen1,jpbgrd) ,   &
-            &      idx_bdy(ib_bdy)%flagu (ilen1,jpbgrd) ,   &
-            &      idx_bdy(ib_bdy)%flagv (ilen1,jpbgrd) )
-
-         ! Dispatch mapping indices and discrete distances on each processor
-         ! -----------------------------------------------------------------
-
-         com_east  = 0
-         com_west  = 0
-         com_south = 0
-         com_north = 0
-
-         com_east_b  = 0
-         com_west_b  = 0
-         com_south_b = 0
-         com_north_b = 0
-
-         DO igrd = 1, jpbgrd
-            icount  = 0
-            ! Loop on rimwidth to ensure outermost points come first in the local arrays.
-            DO ir=1, nn_rimwidth(ib_bdy)
-               DO ib = 1, nblendta(igrd,ib_bdy)
-                  ! check if point is in local domain and equals ir
-                  IF(  nbidta(ib,igrd,ib_bdy) >= iwe .AND. nbidta(ib,igrd,ib_bdy) <= ies .AND.   &
-                     & nbjdta(ib,igrd,ib_bdy) >= iso .AND. nbjdta(ib,igrd,ib_bdy) <= ino .AND.   &
-                     & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                     !
-                     icount = icount  + 1
-
-                     ! Rather assume that boundary data indices are given on global domain
-                     ! TO BE DISCUSSED ?
-!                     idx_bdy(ib_bdy)%nbi(icount,igrd)   = nbidta(ib,igrd,ib_bdy)- mig(1)+1
-!                     idx_bdy(ib_bdy)%nbj(icount,igrd)   = nbjdta(ib,igrd,ib_bdy)- mjg(1)+1
-                     idx_bdy(ib_bdy)%nbi(icount,igrd)   = nbidta(ib,igrd,ib_bdy)- mig(1)+1
-                     idx_bdy(ib_bdy)%nbj(icount,igrd)   = nbjdta(ib,igrd,ib_bdy)- mjg(1)+1
-                     ! check if point has to be sent
-                     ii = idx_bdy(ib_bdy)%nbi(icount,igrd)
-                     ij = idx_bdy(ib_bdy)%nbj(icount,igrd)
-                     if((com_east .ne. 1) .and. (ii == (nlci-1)) .and. (nbondi .le. 0)) then
-                        com_east = 1
-                     elseif((com_west .ne. 1) .and. (ii == 2) .and. (nbondi .ge. 0) .and. (nbondi .ne. 2)) then
-                        com_west = 1
-                     endif 
-                     if((com_south .ne. 1) .and. (ij == 2) .and. (nbondj .ge. 0) .and. (nbondj .ne. 2)) then
-                        com_south = 1
-                     elseif((com_north .ne. 1) .and. (ij == (nlcj-1)) .and. (nbondj .le. 0)) then
-                        com_north = 1
-                     endif 
-                     idx_bdy(ib_bdy)%nbr(icount,igrd)   = nbrdta(ib,igrd,ib_bdy)
-                     idx_bdy(ib_bdy)%nbmap(icount,igrd) = ib
-                  ENDIF
-                  ! check if point has to be received from a neighbour
-                  IF(nbondi == 0) THEN
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(1) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(1) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(1) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(1) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ii = nbidta(ib,igrd,ib_bdy)- iw_b(1)+2
-                       if((com_west_b .ne. 1) .and. (ii == (nlcit(nowe+1)-1))) then
-                          ij = nbjdta(ib,igrd,ib_bdy) - is_b(1)+2
-                          if((ij == 2) .and. (nbondj == 0 .or. nbondj == 1)) then
-                            com_south = 1
-                          elseif((ij == nlcjt(nowe+1)-1) .and. (nbondj == 0 .or. nbondj == -1)) then
-                            com_north = 1
-                          endif
-                          com_west_b = 1
-                       endif 
-                     ENDIF
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(2) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(2) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(2) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(2) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ii = nbidta(ib,igrd,ib_bdy)- iw_b(2)+2
-                       if((com_east_b .ne. 1) .and. (ii == 2)) then
-                          ij = nbjdta(ib,igrd,ib_bdy) - is_b(2)+2
-                          if((ij == 2) .and. (nbondj == 0 .or. nbondj == 1)) then
-                            com_south = 1
-                          elseif((ij == nlcjt(noea+1)-1) .and. (nbondj == 0 .or. nbondj == -1)) then
-                            com_north = 1
-                          endif
-                          com_east_b = 1
-                       endif 
-                     ENDIF
-                  ELSEIF(nbondi == 1) THEN
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(1) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(1) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(1) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(1) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ii = nbidta(ib,igrd,ib_bdy)- iw_b(1)+2
-                       if((com_west_b .ne. 1) .and. (ii == (nlcit(nowe+1)-1))) then
-                          ij = nbjdta(ib,igrd,ib_bdy) - is_b(1)+2
-                          if((ij == 2) .and. (nbondj == 0 .or. nbondj == 1)) then
-                            com_south = 1
-                          elseif((ij == nlcjt(nowe+1)-1) .and. (nbondj == 0 .or. nbondj == -1)) then
-                            com_north = 1
-                          endif
-                          com_west_b = 1
-                       endif 
-                     ENDIF
-                  ELSEIF(nbondi == -1) THEN
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(2) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(2) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(2) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(2) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ii = nbidta(ib,igrd,ib_bdy)- iw_b(2)+2
-                       if((com_east_b .ne. 1) .and. (ii == 2)) then
-                          ij = nbjdta(ib,igrd,ib_bdy) - is_b(2)+2
-                          if((ij == 2) .and. (nbondj == 0 .or. nbondj == 1)) then
-                            com_south = 1
-                          elseif((ij == nlcjt(noea+1)-1) .and. (nbondj == 0 .or. nbondj == -1)) then
-                            com_north = 1
-                          endif
-                          com_east_b = 1
-                       endif 
-                     ENDIF
-                  ENDIF
-                  IF(nbondj == 0) THEN
-                     IF(com_north_b .ne. 1 .AND. (nbidta(ib,igrd,ib_bdy) == iw_b(4)-1  &
-                       & .OR. nbidta(ib,igrd,ib_bdy) == ie_b(4)+1) .AND. &
-                       & nbjdta(ib,igrd,ib_bdy) == is_b(4) .AND. nbrdta(ib,igrd,ib_bdy) == ir) THEN
-                       com_north_b = 1 
-                     ENDIF
-                     IF(com_south_b .ne. 1 .AND. (nbidta(ib,igrd,ib_bdy) == iw_b(3)-1  &
-                       &.OR. nbidta(ib,igrd,ib_bdy) == ie_b(3)+1) .AND. &
-                       & nbjdta(ib,igrd,ib_bdy) == in_b(3) .AND. nbrdta(ib,igrd,ib_bdy) == ir) THEN
-                       com_south_b = 1 
-                     ENDIF
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(3) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(3) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(3) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(3) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ij = nbjdta(ib,igrd,ib_bdy)- is_b(3)+2
-                       if((com_south_b .ne. 1) .and. (ij == (nlcjt(noso+1)-1))) then
-                          com_south_b = 1
-                       endif 
-                     ENDIF
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(4) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(4) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(4) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(4) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ij = nbjdta(ib,igrd,ib_bdy)- is_b(4)+2
-                       if((com_north_b .ne. 1) .and. (ij == 2)) then
-                          com_north_b = 1
-                       endif 
-                     ENDIF
-                  ELSEIF(nbondj == 1) THEN
-                     IF( com_south_b .ne. 1 .AND. (nbidta(ib,igrd,ib_bdy) == iw_b(3)-1 .OR. &
-                       & nbidta(ib,igrd,ib_bdy) == ie_b(3)+1) .AND. &
-                       & nbjdta(ib,igrd,ib_bdy) == in_b(3) .AND. nbrdta(ib,igrd,ib_bdy) == ir) THEN
-                       com_south_b = 1 
-                     ENDIF
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(3) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(3) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(3) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(3) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ij = nbjdta(ib,igrd,ib_bdy)- is_b(3)+2
-                       if((com_south_b .ne. 1) .and. (ij == (nlcjt(noso+1)-1))) then
-                          com_south_b = 1
-                       endif 
-                     ENDIF
-                  ELSEIF(nbondj == -1) THEN
-                     IF(com_north_b .ne. 1 .AND. (nbidta(ib,igrd,ib_bdy) == iw_b(4)-1  &
-                       & .OR. nbidta(ib,igrd,ib_bdy) == ie_b(4)+1) .AND. &
-                       & nbjdta(ib,igrd,ib_bdy) == is_b(4) .AND. nbrdta(ib,igrd,ib_bdy) == ir) THEN
-                       com_north_b = 1 
-                     ENDIF
-                     IF( nbidta(ib,igrd,ib_bdy) >= iw_b(4) .AND. nbidta(ib,igrd,ib_bdy) <= ie_b(4) .AND.   &
-                       & nbjdta(ib,igrd,ib_bdy) >= is_b(4) .AND. nbjdta(ib,igrd,ib_bdy) <= in_b(4) .AND.   &
-                       & nbrdta(ib,igrd,ib_bdy) == ir  ) THEN
-                       ij = nbjdta(ib,igrd,ib_bdy)- is_b(4)+2
-                       if((com_north_b .ne. 1) .and. (ij == 2)) then
-                          com_north_b = 1
-                       endif 
-                     ENDIF
-                  ENDIF
-               ENDDO
-            ENDDO
-         ENDDO 
-
-         ! definition of the i- and j- direction local boundaries arrays used for sending the boundaries
-         IF(     (com_east  == 1) .and. (com_west  == 1) ) THEN   ;   nbondi_bdy(ib_bdy) =  0
-         ELSEIF( (com_east  == 1) .and. (com_west  == 0) ) THEN   ;   nbondi_bdy(ib_bdy) = -1
-         ELSEIF( (com_east  == 0) .and. (com_west  == 1) ) THEN   ;   nbondi_bdy(ib_bdy) =  1
-         ENDIF
-         IF(     (com_north == 1) .and. (com_south == 1) ) THEN   ;   nbondj_bdy(ib_bdy) =  0
-         ELSEIF( (com_north == 1) .and. (com_south == 0) ) THEN   ;   nbondj_bdy(ib_bdy) = -1
-         ELSEIF( (com_north == 0) .and. (com_south == 1) ) THEN   ;   nbondj_bdy(ib_bdy) =  1
-         ENDIF
-
-         ! definition of the i- and j- direction local boundaries arrays used for receiving the boundaries
-         IF(     (com_east_b  == 1) .and. (com_west_b  == 1) ) THEN   ;   nbondi_bdy_b(ib_bdy) =  0
-         ELSEIF( (com_east_b  == 1) .and. (com_west_b  == 0) ) THEN   ;   nbondi_bdy_b(ib_bdy) = -1
-         ELSEIF( (com_east_b  == 0) .and. (com_west_b  == 1) ) THEN   ;   nbondi_bdy_b(ib_bdy) =  1
-         ENDIF
-         IF(     (com_north_b == 1) .and. (com_south_b == 1) ) THEN   ;   nbondj_bdy_b(ib_bdy) =  0
-         ELSEIF( (com_north_b == 1) .and. (com_south_b == 0) ) THEN   ;   nbondj_bdy_b(ib_bdy) = -1
-         ELSEIF( (com_north_b == 0) .and. (com_south_b == 1) ) THEN   ;   nbondj_bdy_b(ib_bdy) =  1
-         ENDIF
-
-         ! Compute rim weights for FRS scheme
-         ! ----------------------------------
-         DO igrd = 1, jpbgrd
-            DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
-               nbr => idx_bdy(ib_bdy)%nbr(ib,igrd)
-               idx_bdy(ib_bdy)%nbw(ib,igrd) = 1.- TANH( REAL( nbr - 1 ) *0.5 )      ! tanh formulation
-!               idx_bdy(ib_bdy)%nbw(ib,igrd) = (REAL(nn_rimwidth(ib_bdy)+1-nbr)/REAL(nn_rimwidth(ib_bdy)))**2.  ! quadratic
-!               idx_bdy(ib_bdy)%nbw(ib,igrd) =  REAL(nn_rimwidth(ib_bdy)+1-nbr)/REAL(nn_rimwidth(ib_bdy))       ! linear
-            END DO
-         END DO 
-
-         ! Compute damping coefficients
-         ! ----------------------------
-         DO igrd = 1, jpbgrd
-            DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
-               nbr => idx_bdy(ib_bdy)%nbr(ib,igrd)
-               idx_bdy(ib_bdy)%nbd(ib,igrd) = 1. / ( rn_time_dmp(ib_bdy) * rday ) & 
-               & *(REAL(nn_rimwidth(ib_bdy)+1-nbr)/REAL(nn_rimwidth(ib_bdy)))**2.   ! quadratic
-               idx_bdy(ib_bdy)%nbdout(ib,igrd) = 1. / ( rn_time_dmp_out(ib_bdy) * rday ) & 
-               & *(REAL(nn_rimwidth(ib_bdy)+1-nbr)/REAL(nn_rimwidth(ib_bdy)))**2.   ! quadratic
-            END DO
-         END DO 
-
-      END DO
-
-      ! ------------------------------------------------------
-      ! Initialise masks and find normal/tangential directions
-      ! ------------------------------------------------------
-
-      ! Read global 2D mask at T-points: bdytmask
-      ! -----------------------------------------
-      ! bdytmask = 1  on the computational domain AND on open boundaries
-      !          = 0  elsewhere   
- 
-      bdytmask(:,:) = ssmask(:,:)
-
-      ! Derive mask on U and V grid from mask on T grid
-
-      bdyumask(:,:) = 0._wp
-      bdyvmask(:,:) = 0._wp
-      DO ij = 1, jpjm1
-         DO ii = 1, jpim1
-            bdyumask(ii,ij) = bdytmask(ii,ij) * bdytmask(ii+1, ij )
-            bdyvmask(ii,ij) = bdytmask(ii,ij) * bdytmask(ii  ,ij+1)  
-         END DO
-      END DO
-      CALL lbc_lnk_multi( 'bdyini', bdyumask, 'U', 1. , bdyvmask, 'V', 1. )   ! Lateral boundary cond. 
-
-      ! bdy masks are now set to zero on boundary points:
-      !
-      igrd = 1
-      DO ib_bdy = 1, nb_bdy
-        DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)      
-          bdytmask(idx_bdy(ib_bdy)%nbi(ib,igrd), idx_bdy(ib_bdy)%nbj(ib,igrd)) = 0._wp
-        END DO
-      END DO
-      !
-      igrd = 2
-      DO ib_bdy = 1, nb_bdy
-        DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
-          bdyumask(idx_bdy(ib_bdy)%nbi(ib,igrd), idx_bdy(ib_bdy)%nbj(ib,igrd)) = 0._wp
-        END DO
-      END DO
-      !
-      igrd = 3
-      DO ib_bdy = 1, nb_bdy
-        DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
-          bdyvmask(idx_bdy(ib_bdy)%nbi(ib,igrd), idx_bdy(ib_bdy)%nbj(ib,igrd)) = 0._wp
-        END DO
-      END DO
-
-      ! For the flagu/flagv calculation below we require a version of fmask without
-      ! the land boundary condition (shlat) included:
-      zfmask(:,:) = 0
-      DO ij = 2, jpjm1
-         DO ii = 2, jpim1
-            zfmask(ii,ij) = tmask(ii,ij  ,1) * tmask(ii+1,ij  ,1)   &
-           &              * tmask(ii,ij+1,1) * tmask(ii+1,ij+1,1)
-         END DO      
-      END DO
-
-      ! Lateral boundary conditions
-      CALL lbc_lnk( 'bdyini', zfmask, 'F', 1. ) 
-      CALL lbc_lnk_multi( 'bdyini', bdyumask, 'U', 1. , bdyvmask, 'V', 1., bdytmask, 'T', 1. )
-      DO ib_bdy = 1, nb_bdy       ! Indices and directions of rim velocity components
-
-         idx_bdy(ib_bdy)%flagu(:,:) = 0._wp
-         idx_bdy(ib_bdy)%flagv(:,:) = 0._wp
-         icount = 0 
-
-         ! Calculate relationship of U direction to the local orientation of the boundary
-         ! flagu = -1 : u component is normal to the dynamical boundary and its direction is outward
-         ! flagu =  0 : u is tangential
-         ! flagu =  1 : u is normal to the boundary and is direction is inward
-  
-         DO igrd = 1, jpbgrd 
-            SELECT CASE( igrd )
-               CASE( 1 )   ;   pmask => umask   (:,:,1)   ;   i_offset = 0
-               CASE( 2 )   ;   pmask => bdytmask(:,:)     ;   i_offset = 1
-               CASE( 3 )   ;   pmask => zfmask  (:,:)     ;   i_offset = 0
-            END SELECT 
-            icount = 0
-            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)  
-               nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
-               nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
-               zefl = pmask(nbi+i_offset-1,nbj)
-               zwfl = pmask(nbi+i_offset,nbj)
-               ! This error check only works if you are using the bdyXmask arrays
-               IF( i_offset == 1 .and. zefl + zwfl == 2 ) THEN
-                  icount = icount + 1
-                  IF(lwp) WRITE(numout,*) 'Problem with igrd = ',igrd,' at (global) nbi, nbj : ',mig(nbi),mjg(nbj)
-               ELSE
-                  idx_bdy(ib_bdy)%flagu(ib,igrd) = -zefl + zwfl
-               ENDIF
-            END DO
-            IF( icount /= 0 ) THEN
-               IF(lwp) WRITE(numout,*)
-               IF(lwp) WRITE(numout,*) ' E R R O R : Some ',cgrid(igrd),' grid points,',   &
-                  ' are not boundary points (flagu calculation). Check nbi, nbj, indices for boundary set ',ib_bdy
-               IF(lwp) WRITE(numout,*) ' ========== '
-               IF(lwp) WRITE(numout,*)
-               nstop = nstop + 1
-            ENDIF 
-         END DO
-
-         ! Calculate relationship of V direction to the local orientation of the boundary
-         ! flagv = -1 : v component is normal to the dynamical boundary but its direction is outward
-         ! flagv =  0 : v is tangential
-         ! flagv =  1 : v is normal to the boundary and is direction is inward
-
-         DO igrd = 1, jpbgrd 
-            SELECT CASE( igrd )
-               CASE( 1 )   ;   pmask => vmask (:,:,1)   ;   j_offset = 0
-               CASE( 2 )   ;   pmask => zfmask(:,:)     ;   j_offset = 0
-               CASE( 3 )   ;   pmask => bdytmask        ;   j_offset = 1
-            END SELECT 
-            icount = 0
-            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)  
-               nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
-               nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
-               znfl = pmask(nbi,nbj+j_offset-1)
-               zsfl = pmask(nbi,nbj+j_offset  )
-               ! This error check only works if you are using the bdyXmask arrays
-               IF( j_offset == 1 .and. znfl + zsfl == 2 ) THEN
-                  IF(lwp) WRITE(numout,*) 'Problem with igrd = ',igrd,' at (global) nbi, nbj : ',mig(nbi),mjg(nbj)
-                  icount = icount + 1
-               ELSE
-                  idx_bdy(ib_bdy)%flagv(ib,igrd) = -znfl + zsfl
-               END IF
-            END DO
-            IF( icount /= 0 ) THEN
-               IF(lwp) WRITE(numout,*)
-               IF(lwp) WRITE(numout,*) ' E R R O R : Some ',cgrid(igrd),' grid points,',   &
-                  ' are not boundary points (flagv calculation). Check nbi, nbj, indices for boundary set ',ib_bdy
-               IF(lwp) WRITE(numout,*) ' ========== '
-               IF(lwp) WRITE(numout,*)
-               nstop = nstop + 1
-            ENDIF 
-         END DO
-         !
-      END DO
-
-      ! Compute total lateral surface for volume correction:
-      ! ----------------------------------------------------
-      ! JC: this must be done at each time step with non-linear free surface
-      bdysurftot = 0._wp 
-      IF( ln_vol ) THEN  
-         igrd = 2      ! Lateral surface at U-points
-         DO ib_bdy = 1, nb_bdy
-            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
-               nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
-               nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
-               flagu => idx_bdy(ib_bdy)%flagu(ib,igrd)
-               bdysurftot = bdysurftot + hu_n   (nbi  , nbj)                           &
-                  &                    * e2u    (nbi  , nbj) * ABS( flagu ) &
-                  &                    * tmask_i(nbi  , nbj)                           &
-                  &                    * tmask_i(nbi+1, nbj)                   
-            END DO
-         END DO
-
-         igrd=3 ! Add lateral surface at V-points
-         DO ib_bdy = 1, nb_bdy
-            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
-               nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
-               nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
-               flagv => idx_bdy(ib_bdy)%flagv(ib,igrd)
-               bdysurftot = bdysurftot + hv_n   (nbi, nbj  )                           &
-                  &                    * e1v    (nbi, nbj  ) * ABS( flagv ) &
-                  &                    * tmask_i(nbi, nbj  )                           &
-                  &                    * tmask_i(nbi, nbj+1)
-            END DO
-         END DO
-         !
-         CALL mpp_sum( 'bdyini', bdysurftot )      ! sum over the global domain
-      END IF   
-      !
-      ! Tidy up
-      !--------
-      IF( nb_bdy>0 )   DEALLOCATE( nbidta, nbjdta, nbrdta )
-      !
-   END SUBROUTINE bdy_segs
-
-
-   SUBROUTINE bdy_ctl_seg
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE bdy_ctl_seg  ***
-      !!
-      !! ** Purpose :   Check straight open boundary segments location
-      !!
-      !! ** Method  :   - Look for open boundary corners
-      !!                - Check that segments start or end on land 
-      !!----------------------------------------------------------------------
-      INTEGER  ::   ib, ib1, ib2, ji ,jj, itest  
-      INTEGER, DIMENSION(jp_nseg,2) :: icorne, icornw, icornn, icorns  
-      REAL(wp), DIMENSION(2) ::   ztestmask
-      !!----------------------------------------------------------------------
-      !
-      IF (lwp) WRITE(numout,*) ' '
-      IF (lwp) WRITE(numout,*) 'bdy_ctl_seg: Check analytical segments'
-      IF (lwp) WRITE(numout,*) '~~~~~~~~~~~~'
-      !
-      IF(lwp) WRITE(numout,*) 'Number of east  segments     : ', nbdysege
-      IF(lwp) WRITE(numout,*) 'Number of west  segments     : ', nbdysegw
-      IF(lwp) WRITE(numout,*) 'Number of north segments     : ', nbdysegn
-      IF(lwp) WRITE(numout,*) 'Number of south segments     : ', nbdysegs
-      ! 1. Check bounds
-      !----------------
-      DO ib = 1, nbdysegn
-         IF (lwp) WRITE(numout,*) '**check north seg bounds pckg: ', npckgn(ib)
-         IF ((jpjnob(ib).ge.jpjglo-1).or.& 
-            &(jpjnob(ib).le.1))        CALL ctl_stop( 'nbdyind out of domain' )
-         IF (jpindt(ib).ge.jpinft(ib)) CALL ctl_stop( 'Bdy start index is greater than end index' )
-         IF (jpindt(ib).le.1     )     CALL ctl_stop( 'Start index out of domain' )
-         IF (jpinft(ib).ge.jpiglo)     CALL ctl_stop( 'End index out of domain' )
-      END DO
-      !
-      DO ib = 1, nbdysegs
-         IF (lwp) WRITE(numout,*) '**check south seg bounds pckg: ', npckgs(ib)
-         IF ((jpjsob(ib).ge.jpjglo-1).or.& 
-            &(jpjsob(ib).le.1))        CALL ctl_stop( 'nbdyind out of domain' )
-         IF (jpisdt(ib).ge.jpisft(ib)) CALL ctl_stop( 'Bdy start index is greater than end index' )
-         IF (jpisdt(ib).le.1     )     CALL ctl_stop( 'Start index out of domain' )
-         IF (jpisft(ib).ge.jpiglo)     CALL ctl_stop( 'End index out of domain' )
-      END DO
-      !
-      DO ib = 1, nbdysege
-         IF (lwp) WRITE(numout,*) '**check east  seg bounds pckg: ', npckge(ib)
-         IF ((jpieob(ib).ge.jpiglo-1).or.& 
-            &(jpieob(ib).le.1))        CALL ctl_stop( 'nbdyind out of domain' )
-         IF (jpjedt(ib).ge.jpjeft(ib)) CALL ctl_stop( 'Bdy start index is greater than end index' )
-         IF (jpjedt(ib).lt.1     )     CALL ctl_stop( 'Start index out of domain' )!ACC
-         IF (jpjeft(ib).gt.jpjglo)     CALL ctl_stop( 'End index out of domain' )!ACC
-      END DO
-      !
-      DO ib = 1, nbdysegw
-         IF (lwp) WRITE(numout,*) '**check west  seg bounds pckg: ', npckgw(ib)
-         IF ((jpiwob(ib).ge.jpiglo-1).or.& 
-            &(jpiwob(ib).le.1))        CALL ctl_stop( 'nbdyind out of domain' )
-         IF (jpjwdt(ib).ge.jpjwft(ib)) CALL ctl_stop( 'Bdy start index is greater than end index' )
-         IF (jpjwdt(ib).lt.1     )     CALL ctl_stop( 'Start index out of domain' ) !ACC
-         IF (jpjwft(ib).gt.jpjglo)     CALL ctl_stop( 'End index out of domain' ) !ACC
-      ENDDO
-      !
-      !      
-      ! 2. Look for segment crossings
-      !------------------------------ 
-      IF (lwp) WRITE(numout,*) '**Look for segments corners  :'
-      !
-      itest = 0 ! corner number
-      !
-      ! flag to detect if start or end of open boundary belongs to a corner
-      ! if not (=0), it must be on land.
-      ! if a corner is detected, save bdy package number for further tests
-      icorne(:,:)=0. ; icornw(:,:)=0. ; icornn(:,:)=0. ; icorns(:,:)=0.
-      ! South/West crossings
-      IF ((nbdysegw > 0).AND.(nbdysegs > 0)) THEN
-         DO ib1 = 1, nbdysegw        
-            DO ib2 = 1, nbdysegs
-               IF (( jpisdt(ib2)<=jpiwob(ib1)).AND. &
-                &  ( jpisft(ib2)>=jpiwob(ib1)).AND. &
-                &  ( jpjwdt(ib1)<=jpjsob(ib2)).AND. &
-                &  ( jpjwft(ib1)>=jpjsob(ib2))) THEN
-                  IF ((jpjwdt(ib1)==jpjsob(ib2)).AND.(jpisdt(ib2)==jpiwob(ib1))) THEN 
-                     ! We have a possible South-West corner                      
-!                     WRITE(numout,*) ' Found a South-West corner at (i,j): ', jpisdt(ib2), jpjwdt(ib1) 
-!                     WRITE(numout,*) ' between segments: ', npckgw(ib1), npckgs(ib2)
-                     icornw(ib1,1) = npckgs(ib2)
-                     icorns(ib2,1) = npckgw(ib1)
-                  ELSEIF ((jpisft(ib2)==jpiwob(ib1)).AND.(jpjwft(ib1)==jpjsob(ib2))) THEN
-                     IF(lwp) WRITE(numout,*)
-                     IF(lwp) WRITE(numout,*) ' E R R O R : Found an acute open boundary corner at point (i,j)= ', &
-                     &                                     jpisft(ib2), jpjwft(ib1)
-                     IF(lwp) WRITE(numout,*) ' ==========  Not allowed yet'
-                     IF(lwp) WRITE(numout,*) '             Crossing problem with West segment: ',npckgw(ib1), & 
-                     &                                                    ' and South segment: ',npckgs(ib2)
-                     IF(lwp) WRITE(numout,*)
-                     nstop = nstop + 1
-                  ELSE
-                     IF(lwp) WRITE(numout,*)
-                     IF(lwp) WRITE(numout,*) ' E R R O R : Check South and West Open boundary indices'
-                     IF(lwp) WRITE(numout,*) ' ==========  Crossing problem with West segment: ',npckgw(ib1) , &
-                     &                                                    ' and South segment: ',npckgs(ib2)
-                     IF(lwp) WRITE(numout,*)
-                     nstop = nstop+1
-                  END IF
-               END IF
-            END DO
-         END DO
-      END IF
-      !
-      ! South/East crossings
-      IF ((nbdysege > 0).AND.(nbdysegs > 0)) THEN
-         DO ib1 = 1, nbdysege
-            DO ib2 = 1, nbdysegs
-               IF (( jpisdt(ib2)<=jpieob(ib1)+1).AND. &
-                &  ( jpisft(ib2)>=jpieob(ib1)+1).AND. &
-                &  ( jpjedt(ib1)<=jpjsob(ib2)  ).AND. &
-                &  ( jpjeft(ib1)>=jpjsob(ib2)  )) THEN
-                  IF ((jpjedt(ib1)==jpjsob(ib2)).AND.(jpisft(ib2)==jpieob(ib1)+1)) THEN
-                     ! We have a possible South-East corner 
-!                     WRITE(numout,*) ' Found a South-East corner at (i,j): ', jpisft(ib2), jpjedt(ib1) 
-!                     WRITE(numout,*) ' between segments: ', npckge(ib1), npckgs(ib2)
-                     icorne(ib1,1) = npckgs(ib2)
-                     icorns(ib2,2) = npckge(ib1)
-                  ELSEIF ((jpjeft(ib1)==jpjsob(ib2)).AND.(jpisdt(ib2)==jpieob(ib1)+1)) THEN
-                     IF(lwp) WRITE(numout,*)
-                     IF(lwp) WRITE(numout,*) ' E R R O R : Found an acute open boundary corner at point (i,j)= ', &
-                     &                                     jpisdt(ib2), jpjeft(ib1)
-                     IF(lwp) WRITE(numout,*) ' ==========  Not allowed yet'
-                     IF(lwp) WRITE(numout,*) '             Crossing problem with East segment: ',npckge(ib1), &
-                     &                                                    ' and South segment: ',npckgs(ib2)
-                     IF(lwp) WRITE(numout,*)
-                     nstop = nstop + 1
-                  ELSE
-                     IF(lwp) WRITE(numout,*)
-                     IF(lwp) WRITE(numout,*) ' E R R O R : Check South and East Open boundary indices'
-                     IF(lwp) WRITE(numout,*) ' ==========  Crossing problem with East segment: ',npckge(ib1), &
-                     &                                                    ' and South segment: ',npckgs(ib2)
-                     IF(lwp) WRITE(numout,*)
-                     nstop = nstop + 1
-                  END IF
-               END IF
-            END DO
-         END DO
-      END IF
-      !
-      ! North/West crossings
-      IF ((nbdysegn > 0).AND.(nbdysegw > 0)) THEN
-         DO ib1 = 1, nbdysegw        
-            DO ib2 = 1, nbdysegn
-               IF (( jpindt(ib2)<=jpiwob(ib1)  ).AND. &
-                &  ( jpinft(ib2)>=jpiwob(ib1)  ).AND. &
-                &  ( jpjwdt(ib1)<=jpjnob(ib2)+1).AND. &
-                &  ( jpjwft(ib1)>=jpjnob(ib2)+1)) THEN
-                  IF ((jpjwft(ib1)==jpjnob(ib2)+1).AND.(jpindt(ib2)==jpiwob(ib1))) THEN
-                     ! We have a possible North-West corner 
-!                     WRITE(numout,*) ' Found a North-West corner at (i,j): ', jpindt(ib2), jpjwft(ib1) 
-!                     WRITE(numout,*) ' between segments: ', npckgw(ib1), npckgn(ib2)
-                     icornw(ib1,2) = npckgn(ib2)
-                     icornn(ib2,1) = npckgw(ib1)
-                  ELSEIF ((jpjwdt(ib1)==jpjnob(ib2)+1).AND.(jpinft(ib2)==jpiwob(ib1))) THEN
-                     IF(lwp) WRITE(numout,*)
-                     IF(lwp) WRITE(numout,*) ' E R R O R : Found an acute open boundary corner at point (i,j)= ', &
-                     &                                     jpinft(ib2), jpjwdt(ib1)
-                     IF(lwp) WRITE(numout,*) ' ==========  Not allowed yet'
-                     IF(lwp) WRITE(numout,*) '             Crossing problem with West segment: ',npckgw(ib1), &
-                     &                                                    ' and North segment: ',npckgn(ib2)
-                     IF(lwp) WRITE(numout,*)
-                     nstop = nstop + 1
-                  ELSE
-                     IF(lwp) WRITE(numout,*)
-                     IF(lwp) WRITE(numout,*) ' E R R O R : Check North and West Open boundary indices'
-                     IF(lwp) WRITE(numout,*) ' ==========  Crossing problem with West segment: ',npckgw(ib1), &
-                     &                                                    ' and North segment: ',npckgn(ib2)
-                     IF(lwp) WRITE(numout,*)
-                     nstop = nstop + 1
-                  END IF
-               END IF
-            END DO
-         END DO
-      END IF
-      !
-      ! North/East crossings
-      IF ((nbdysegn > 0).AND.(nbdysege > 0)) THEN
-         DO ib1 = 1, nbdysege        
-            DO ib2 = 1, nbdysegn
-               IF (( jpindt(ib2)<=jpieob(ib1)+1).AND. &
-                &  ( jpinft(ib2)>=jpieob(ib1)+1).AND. &
-                &  ( jpjedt(ib1)<=jpjnob(ib2)+1).AND. &
-                &  ( jpjeft(ib1)>=jpjnob(ib2)+1)) THEN
-                  IF ((jpjeft(ib1)==jpjnob(ib2)+1).AND.(jpinft(ib2)==jpieob(ib1)+1)) THEN
-                     ! We have a possible North-East corner 
-!                     WRITE(numout,*) ' Found a North-East corner at (i,j): ', jpinft(ib2), jpjeft(ib1)
-!                     WRITE(numout,*) ' between segments: ', npckge(ib1), npckgn(ib2)
-                     icorne(ib1,2) = npckgn(ib2)
-                     icornn(ib2,2) = npckge(ib1)
-                  ELSEIF ((jpjedt(ib1)==jpjnob(ib2)+1).AND.(jpindt(ib2)==jpieob(ib1)+1)) THEN
-                     IF(lwp) WRITE(numout,*)
-                     IF(lwp) WRITE(numout,*) ' E R R O R : Found an acute open boundary corner at point (i,j)= ', &
-                     &                                     jpindt(ib2), jpjedt(ib1)
-                     IF(lwp) WRITE(numout,*) ' ==========  Not allowed yet'
-                     IF(lwp) WRITE(numout,*) '             Crossing problem with East segment: ',npckge(ib1), &
-                     &                                                    ' and North segment: ',npckgn(ib2)
-                     IF(lwp) WRITE(numout,*)
-                     nstop = nstop + 1
-                  ELSE
-                     IF(lwp) WRITE(numout,*)
-                     IF(lwp) WRITE(numout,*) ' E R R O R : Check North and East Open boundary indices'
-                     IF(lwp) WRITE(numout,*) ' ==========  Crossing problem with East segment: ',npckge(ib1), &
-                     &                                                    ' and North segment: ',npckgn(ib2)
-                     IF(lwp) WRITE(numout,*)
-                     nstop = nstop + 1
-                  END IF
-               END IF
-            END DO
-         END DO
-      END IF
-      !
-      ! 3. Check if segment extremities are on land
-      !-------------------------------------------- 
-      !
-      ! West segments
-      DO ib = 1, nbdysegw
-         ! get mask at boundary extremities:
-         ztestmask(1:2)=0.
-         DO ji = 1, jpi
-            DO jj = 1, jpj             
-              IF (((ji + nimpp - 1) == jpiwob(ib)).AND. & 
-               &  ((jj + njmpp - 1) == jpjwdt(ib))) ztestmask(1)=tmask(ji,jj,1)
-              IF (((ji + nimpp - 1) == jpiwob(ib)).AND. & 
-               &  ((jj + njmpp - 1) == jpjwft(ib))) ztestmask(2)=tmask(ji,jj,1)  
-            END DO
-         END DO
-         CALL mpp_sum( 'bdyini', ztestmask, 2 )   ! sum over the global domain
-
-         IF (ztestmask(1)==1) THEN 
-            IF (icornw(ib,1)==0) THEN
-               IF(lwp) WRITE(numout,*)
-               IF(lwp) WRITE(numout,*) ' E R R O R : Open boundary segment ', npckgw(ib)
-               IF(lwp) WRITE(numout,*) ' ==========  does not start on land or on a corner'                                                  
-               IF(lwp) WRITE(numout,*)
-               nstop = nstop + 1
-            ELSE
-               ! This is a corner
-               IF(lwp) WRITE(numout,*) 'Found a South-West corner at (i,j): ', jpiwob(ib), jpjwdt(ib)
-               CALL bdy_ctl_corn(npckgw(ib), icornw(ib,1))
-               itest=itest+1
-            ENDIF
-         ENDIF
-         IF (ztestmask(2)==1) THEN
-            IF (icornw(ib,2)==0) THEN
-               IF(lwp) WRITE(numout,*)
-               IF(lwp) WRITE(numout,*) ' E R R O R : Open boundary segment ', npckgw(ib)
-               IF(lwp) WRITE(numout,*) ' ==========  does not end on land or on a corner'                                                  
-               IF(lwp) WRITE(numout,*)
-               nstop = nstop + 1
-            ELSE
-               ! This is a corner
-               IF(lwp) WRITE(numout,*) 'Found a North-West corner at (i,j): ', jpiwob(ib), jpjwft(ib)
-               CALL bdy_ctl_corn(npckgw(ib), icornw(ib,2))
-               itest=itest+1
-            ENDIF
-         ENDIF
-      END DO
-      !
-      ! East segments
-      DO ib = 1, nbdysege
-         ! get mask at boundary extremities:
-         ztestmask(1:2)=0.
-         DO ji = 1, jpi
-            DO jj = 1, jpj             
-              IF (((ji + nimpp - 1) == jpieob(ib)+1).AND. & 
-               &  ((jj + njmpp - 1) == jpjedt(ib))) ztestmask(1)=tmask(ji,jj,1)
-              IF (((ji + nimpp - 1) == jpieob(ib)+1).AND. & 
-               &  ((jj + njmpp - 1) == jpjeft(ib))) ztestmask(2)=tmask(ji,jj,1)  
-            END DO
-         END DO
-         CALL mpp_sum( 'bdyini', ztestmask, 2 )   ! sum over the global domain
-
-         IF (ztestmask(1)==1) THEN
-            IF (icorne(ib,1)==0) THEN
-               IF(lwp) WRITE(numout,*)
-               IF(lwp) WRITE(numout,*) ' E R R O R : Open boundary segment ', npckge(ib)
-               IF(lwp) WRITE(numout,*) ' ==========  does not start on land or on a corner'                                                  
-               IF(lwp) WRITE(numout,*)
-               nstop = nstop + 1 
-            ELSE
-               ! This is a corner
-               IF(lwp) WRITE(numout,*) 'Found a South-East corner at (i,j): ', jpieob(ib)+1, jpjedt(ib)
-               CALL bdy_ctl_corn(npckge(ib), icorne(ib,1))
-               itest=itest+1
-            ENDIF
-         ENDIF
-         IF (ztestmask(2)==1) THEN
-            IF (icorne(ib,2)==0) THEN
-               IF(lwp) WRITE(numout,*)
-               IF(lwp) WRITE(numout,*) ' E R R O R : Open boundary segment ', npckge(ib)
-               IF(lwp) WRITE(numout,*) ' ==========  does not end on land or on a corner'                                                  
-               IF(lwp) WRITE(numout,*)
-               nstop = nstop + 1
-            ELSE
-               ! This is a corner
-               IF(lwp) WRITE(numout,*) 'Found a North-East corner at (i,j): ', jpieob(ib)+1, jpjeft(ib)
-               CALL bdy_ctl_corn(npckge(ib), icorne(ib,2))
-               itest=itest+1
-            ENDIF
-         ENDIF
-      END DO
-      !
-      ! South segments
-      DO ib = 1, nbdysegs
-         ! get mask at boundary extremities:
-         ztestmask(1:2)=0.
-         DO ji = 1, jpi
-            DO jj = 1, jpj             
-              IF (((jj + njmpp - 1) == jpjsob(ib)).AND. & 
-               &  ((ji + nimpp - 1) == jpisdt(ib))) ztestmask(1)=tmask(ji,jj,1)
-              IF (((jj + njmpp - 1) == jpjsob(ib)).AND. & 
-               &  ((ji + nimpp - 1) == jpisft(ib))) ztestmask(2)=tmask(ji,jj,1)  
-            END DO
-         END DO
-         CALL mpp_sum( 'bdyini', ztestmask, 2 )   ! sum over the global domain
-
-         IF ((ztestmask(1)==1).AND.(icorns(ib,1)==0)) THEN
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) ' E R R O R : Open boundary segment ', npckgs(ib)
-            IF(lwp) WRITE(numout,*) ' ==========  does not start on land or on a corner'                                                  
-            IF(lwp) WRITE(numout,*)
-            nstop = nstop + 1
-         ENDIF
-         IF ((ztestmask(2)==1).AND.(icorns(ib,2)==0)) THEN
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) ' E R R O R : Open boundary segment ', npckgs(ib)
-            IF(lwp) WRITE(numout,*) ' ==========  does not end on land or on a corner'                                                  
-            IF(lwp) WRITE(numout,*)
-            nstop = nstop + 1
-         ENDIF
-      END DO
-      !
-      ! North segments
-      DO ib = 1, nbdysegn
-         ! get mask at boundary extremities:
-         ztestmask(1:2)=0.
-         DO ji = 1, jpi
-            DO jj = 1, jpj             
-              IF (((jj + njmpp - 1) == jpjnob(ib)+1).AND. & 
-               &  ((ji + nimpp - 1) == jpindt(ib))) ztestmask(1)=tmask(ji,jj,1)
-              IF (((jj + njmpp - 1) == jpjnob(ib)+1).AND. & 
-               &  ((ji + nimpp - 1) == jpinft(ib))) ztestmask(2)=tmask(ji,jj,1)  
-            END DO
-         END DO
-         CALL mpp_sum( 'bdyini', ztestmask, 2 )   ! sum over the global domain
-
-         IF ((ztestmask(1)==1).AND.(icornn(ib,1)==0)) THEN
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) ' E R R O R : Open boundary segment ', npckgn(ib)
-            IF(lwp) WRITE(numout,*) ' ==========  does not start on land'                                                  
-            IF(lwp) WRITE(numout,*)
-            nstop = nstop + 1
-         ENDIF
-         IF ((ztestmask(2)==1).AND.(icornn(ib,2)==0)) THEN
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) ' E R R O R : Open boundary segment ', npckgn(ib)
-            IF(lwp) WRITE(numout,*) ' ==========  does not end on land'                                                  
-            IF(lwp) WRITE(numout,*)
-            nstop = nstop + 1
-         ENDIF
-      END DO
-      !
-      IF ((itest==0).AND.(lwp)) WRITE(numout,*) 'NO open boundary corner found'
-      !
-      ! Other tests TBD: 
-      ! segments completly on land
-      ! optimized open boundary array length according to landmask
-      ! Nudging layers that overlap with interior domain
-      !
-   END SUBROUTINE bdy_ctl_seg
-
-
-   SUBROUTINE bdy_ctl_corn( ib1, ib2 )
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE bdy_ctl_corn  ***
-      !!
-      !! ** Purpose :   Check numerical schemes consistency between
-      !!                segments having a common corner
-      !!
-      !! ** Method  :   
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in)  ::   ib1, ib2
-      INTEGER :: itest
-      !!----------------------------------------------------------------------
-      itest = 0
-
-      IF( cn_dyn2d(ib1) /= cn_dyn2d(ib2) )   itest = itest + 1
-      IF( cn_dyn3d(ib1) /= cn_dyn3d(ib2) )   itest = itest + 1
-      IF( cn_tra  (ib1) /= cn_tra  (ib2) )   itest = itest + 1
-      !
-      IF( nn_dyn2d_dta(ib1) /= nn_dyn2d_dta(ib2) )   itest = itest + 1
-      IF( nn_dyn3d_dta(ib1) /= nn_dyn3d_dta(ib2) )   itest = itest + 1
-      IF( nn_tra_dta  (ib1) /= nn_tra_dta  (ib2) )   itest = itest + 1
-      !
-      IF( nn_rimwidth(ib1) /= nn_rimwidth(ib2) )   itest = itest + 1   
-      !
-      IF( itest>0 ) THEN
-         IF(lwp) WRITE(numout,*) ' E R R O R : Segments ', ib1, 'and ', ib2
-         IF(lwp) WRITE(numout,*) ' ==========  have different open bdy schemes'                                                  
-         IF(lwp) WRITE(numout,*)
-         nstop = nstop + 1
-      ENDIF
-      !
-   END SUBROUTINE bdy_ctl_corn
-
-   !!=================================================================================
-END MODULE bdyini
Index: /NEMO/trunk/tests/WAD/MY_SRC/usrdef_nam.F90
===================================================================
--- /NEMO/trunk/tests/WAD/MY_SRC/usrdef_nam.F90	(revision 11535)
+++ /NEMO/trunk/tests/WAD/MY_SRC/usrdef_nam.F90	(revision 11536)
@@ -39,5 +39,5 @@
 CONTAINS
 
-   SUBROUTINE usr_def_nam( ldtxt, ldnam, cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+   SUBROUTINE usr_def_nam( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -51,5 +51,4 @@
       !! ** input   : - namusr_def namelist found in namelist_cfg
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), DIMENSION(:), INTENT(out) ::   ldtxt, ldnam    ! stored print information
       CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
       INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
@@ -57,16 +56,14 @@
       INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
       !
-      INTEGER ::   ios, ii   ! Local integer
+      INTEGER ::   ios   ! Local integer
       !!
       NAMELIST/namusr_def/ rn_dx, rn_dz, nn_wad_test
       !!----------------------------------------------------------------------
       !
-      ii = 1
-      !
       REWIND( numnam_cfg )          ! Namelist namusr_def (exist in namelist_cfg only)
       READ  ( numnam_cfg, namusr_def, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist', .TRUE. )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist' )
       !
-      WRITE( ldnam(:), namusr_def )
+      IF(lwm)   WRITE( numond, namusr_def )
       !
       !
@@ -79,24 +76,24 @@
       kpj = INT(  32.e3 / rn_dx ) + 2
       kpk = INT(  10.  / rn_dz ) + 1
-      !
-      !                             ! control print
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~~~~~~ '                                                                 ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Namelist namusr_def : WAD_TEST_CASES test case'                             ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      horizontal resolution                    rn_dx  = ', rn_dx, ' meters'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      vertical   resolution                    rn_dz  = ', rn_dz, ' meters'   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      WAD_TEST_CASES domain = 52 km  x  34 km x 10 m'                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '         resulting global domain size :        jpiglo = ', kpi                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpjglo = ', kpj                ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '                                               jpkglo = ', kpk                ;   ii = ii + 1
-      !
       !                             ! Set the lateral boundary condition of the global domain
       kperio = 0                    ! WAD_TEST_CASES configuration : closed domain
       IF( nn_wad_test == 8 ) kperio = 7 ! North-South cyclic test
       !
-      WRITE(ldtxt(ii),*) '   '                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '   Lateral boundary condition of the global domain'                           ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      closed                                   jperio = ', kperio             ;   ii = ii + 1
+      !                             ! control print
+      IF(lwp) THEN
+         WRITE(numout,*) '   '
+         WRITE(numout,*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '   Namelist namusr_def : WAD_TEST_CASES test case'
+         WRITE(numout,*) '      horizontal resolution                    rn_dx  = ', rn_dx, ' meters'
+         WRITE(numout,*) '      vertical   resolution                    rn_dz  = ', rn_dz, ' meters'
+         WRITE(numout,*) '      WAD_TEST_CASES domain = 52 km  x  34 km x 10 m'
+         WRITE(numout,*) '         resulting global domain size :        jpiglo = ', kpi
+         WRITE(numout,*) '                                               jpjglo = ', kpj
+         WRITE(numout,*) '                                               jpkglo = ', kpk
+         WRITE(numout,*) '   '
+         WRITE(numout,*) '   Lateral boundary condition of the global domain'
+         WRITE(numout,*) '      closed                                   jperio = ', kperio
+      ENDIF
       !
    END SUBROUTINE usr_def_nam
