Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/iodef.xml
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/iodef.xml	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/iodef.xml	(revision 7309)
@@ -61,4 +61,6 @@
 	<file id="file2" name_suffix="_SBC" description="surface fluxes variables" > <!-- time step automaticaly defined based on nn_fsbc -->
 	  <field field_ref="empmr"        name="wfo"      />
+      <field field_ref="emp_oce"      name="emp_oce"  long_name="Evap minus Precip over ocean"              />
+      <field field_ref="emp_ice"      name="emp_ice"  long_name="Evap minus Precip over ice"                />
 	  <field field_ref="qsr_oce"      name="qsr_oce"  />
 	  <field field_ref="qns_oce"      name="qns_oce"  />
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/namelist_ice_cfg
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/namelist_ice_cfg	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/namelist_ice_cfg	(revision 7309)
@@ -1,32 +1,48 @@
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!! NEMO/LIM-2 : Ice configuration namelist. Overwrites SHARED/namelist_ice_lim2_ref
+!! LIM3 configuration namelist: Overwrites SHARED/namelist_ice_lim3_ref
+!!              1 - Generic parameters                 (namicerun)
+!!              2 - Diagnostics                        (namicediag)
+!!              3 - Ice initialization                 (namiceini)
+!!              4 - Ice discretization                 (namiceitd)
+!!              5 - Ice dynamics and transport         (namicedyn)
+!!              6 - Ice diffusion                      (namicehdf)
+!!              7 - Ice thermodynamics                 (namicethd)
+!!              8 - Ice salinity                       (namicesal)
+!!              9 - Ice mechanical redistribution      (namiceitdme)
 !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
-!-----------------------------------------------------------------------
-&namicerun     !   Share parameters for dynamics/advection/thermo
-!-----------------------------------------------------------------------
+!------------------------------------------------------------------------------
+&namicerun     !   Generic parameters
+!------------------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namiceini     !   ice initialisation
-!-----------------------------------------------------------------------
+!------------------------------------------------------------------------------
+&namicediag    !   Diagnostics
+!------------------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namicedyn     !   ice dynamic
-!-----------------------------------------------------------------------
+!------------------------------------------------------------------------------
+&namiceini     !   Ice initialization
+!------------------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namicethd     !   ice thermodynamic
-!-----------------------------------------------------------------------
+!------------------------------------------------------------------------------
+&namiceitd     !   Ice discretization
+!------------------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namicesal     !   ice salinity
-!-----------------------------------------------------------------------
+!------------------------------------------------------------------------------
+&namicedyn     !   Ice dynamics and transport
+!------------------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namiceitdme   !   parameters for mechanical redistribution of ice 
-!-----------------------------------------------------------------------
+!------------------------------------------------------------------------------
+&namicehdf     !   Ice horizontal diffusion
+!------------------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namicedia     !   ice diagnostics
-!-----------------------------------------------------------------------
+!------------------------------------------------------------------------------
+&namicethd     !   Ice thermodynamics
+!------------------------------------------------------------------------------
 /
+!------------------------------------------------------------------------------
+&namicesal     !   Ice salinity
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namiceitdme   !   Ice mechanical redistribution (ridging and rafting)
+!------------------------------------------------------------------------------
+/
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/SHARED/field_def.xml
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/SHARED/field_def.xml	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/SHARED/field_def.xml	(revision 7309)
@@ -239,5 +239,7 @@
          <field id="hflx_rain_cea" long_name="heat flux due to rainfall"                                standard_name="temperature_flux_due_to_rainfall_expressed_as_heat_flux_into_sea_water"        unit="W/m2"     />
          <field id="hflx_evap_cea" long_name="heat flux due to evaporation"                             standard_name="temperature_flux_due_to_evaporation_expressed_as_heat_flux_out_of_sea_water"   unit="W/m2"     />
-         <field id="hflx_snow_cea" long_name="heat flux due to snow falling over ice-free ocean"        standard_name="heat_flux_into_sea_water_due_to_snow_thermodynamics"                           unit="W/m2"     />
+         <field id="hflx_snow_cea" long_name="heat flux due to snow falling"                            standard_name="heat_flux_onto_ocean_and_ice_due_to_snow_thermodynamics"                       unit="W/m2"     />
+         <field id="hflx_snow_ai_cea" long_name="heat flux due to snow falling over ice"                standard_name="heat_flux_onto_ice_due_to_snow_thermodynamics"                                 unit="W/m2"     />
+         <field id="hflx_snow_ao_cea" long_name="heat flux due to snow falling over ice-free ocean"     standard_name="heat_flux_onto_sea_water_due_to_snow_thermodynamics"                           unit="W/m2"     />
          <field id="hflx_ice_cea"  long_name="heat flux due to ice thermodynamics"                      standard_name="heat_flux_into_sea_water_due_to_sea_ice_thermodynamics"                        unit="W/m2"     />
          <field id="hflx_rnf_cea"  long_name="heat flux due to runoffs"                                 standard_name="temperature_flux_due_to_runoff_expressed_as_heat_flux_into_sea_water"          unit="W/m2"     />
@@ -317,4 +319,5 @@
          <field id="icevolu"      long_name="ice volume"                                                   unit="m"        />
          <field id="snowvol"      long_name="snow volume"                                                  unit="m"        />
+         <field id="tau_icebfr"   long_name="ice friction on ocean bottom for landfast ice"                unit="N/m2"     />
 
          <field id="icetrp"       long_name="ice volume transport"                                         unit="m/day"          />
@@ -330,4 +333,5 @@
          <field id="sfxbom"       long_name="salt flux from bot melt"                                      unit="1e-3*kg/m2/day" />
          <field id="sfxsum"       long_name="salt flux from surf melt"                                     unit="1e-3*kg/m2/day" />
+         <field id="sfxlam"       long_name="salt flux from lateral melt"                                  unit="1e-3*kg/m2/day" />
          <field id="sfxsni"       long_name="salt flux from snow-ice formation"                            unit="1e-3*kg/m2/day" />
          <field id="sfxopw"       long_name="salt flux from open water ice formation"                      unit="1e-3*kg/m2/day" />
@@ -340,4 +344,5 @@
          <field id="vfxsni"       long_name="daily snowice ice prod."                                      unit="m/day"   />
          <field id="vfxsum"       long_name="surface melt"                                                 unit="m/day"   />
+         <field id="vfxlam"       long_name="lateral melt"                                                 unit="m/day"   />
          <field id="vfxbom"       long_name="bottom melt"                                                  unit="m/day"   />
          <field id="vfxres"       long_name="daily resultant ice prod./melting from limupdate"             unit="m/day"   />
@@ -345,6 +350,7 @@
          <field id="vfxsnw"       long_name="snw melt/growth"                                              unit="m/day"   />
          <field id="vfxsub"       long_name="snw sublimation"                                              unit="m/day"   />
+         <field id="vfxsub_err"   long_name="excess of snw sublimation sent to ocean"                      unit="m/day"   />
          <field id="vfxspr"       long_name="snw precipitation on ice"                                     unit="m/day"   />
-         <field id="vfxthin"      long_name="daily thermo ice prod. for thin ice(<20cm) + open water"      unit="m/day"   />
+         <field id="vfxthin"      long_name="daily thermo ice prod. for thin ice(20cm) + open water"       unit="m/day"   />
 
          <field id="afxtot"       long_name="area tendency (total)"                                        unit="day-1"   />
@@ -521,19 +527,18 @@
 
       	 <!-- available with ln_diahsb -->
-    	 <field id="bgtemper"     long_name="drift in global mean temperature wrt timestep 1"                 standard_name="change_over_time_in_sea_water_potential_temperature"   unit="degC"     />
+     	 <field id="bgtemper"     long_name="drift in global mean temperature wrt timestep 1"                 standard_name="change_over_time_in_sea_water_potential_temperature"   unit="degC"     />
     	 <field id="bgsaline"     long_name="drift in global mean salinity wrt timestep 1"                    standard_name="change_over_time_in_sea_water_practical_salinity"      unit="1e-3"     />
-    	 <field id="bgheatco"     long_name="drift in global mean heat content wrt timestep 1"                                                                                      unit="10^9J"    />
-    	 <field id="bgsaltco"     long_name="drift in global mean salt content wrt timestep 1"                                                                                      unit="1e-3*m3"  />
+    	 <field id="bgheatco"     long_name="drift in global mean heat content wrt timestep 1"                                                                                      unit="1.e20J"   />
+     	 <field id="bgheatfx"     long_name="drift in global mean heat flux    wrt timestep 1"                                                                                      unit="W/m2"     />
+   	     <field id="bgsaltco"     long_name="drift in global mean salt content wrt timestep 1"                                                                                      unit="1e-3*km3" />
     	 <field id="bgvolssh"     long_name="drift in global mean ssh volume wrt timestep 1"                                                                                        unit="km3"      />
          <field id="bgvole3t"     long_name="drift in global mean volume variation (e3t) wrt timestep 1"                                                                            unit="km3"      />
-    	 <field id="bgvoltot"     long_name="drift in global mean volume wrt timestep 1"                                                                                            unit="km3"      />
-         <!-- NOTE: No matching iom_put call -->
-    	 <field id="bgsshtot"     long_name="drift in global mean ssh wrt timestep 1"                         standard_name="global_average_sea_level_change"                       unit="m"        />
-    	 <field id="bgfrcvol"     long_name="drift in global mean volume from forcing wrt timestep 1"                                                                               unit="km3"      />
-    	 <field id="bgfrctem"     long_name="drift in global mean heat content from forcing wrt timestep 1"                                                                         unit="10^9J"    />
-    	 <field id="bgfrcsal"     long_name="drift in global mean salt content from forcing wrt timestep 1"                                                                         unit="1e-3*km3" />
-    	 <field id="bgmistem"     long_name="global mean temperature error due to free surface"                                                                                     unit="degC"     />
-    	 <field id="bgmissal"     long_name="global mean salinity error due to free surface"                                                                                        unit="1e-3"     />
-      </field_group>
+    	 <field id="bgfrcvol"     long_name="global mean volume from forcing"                                                                                                       unit="km3"      />
+    	 <field id="bgfrctem"     long_name="global mean heat content from forcing"                                                                                                 unit="1.e20J"   />
+         <field id="bgfrchfx"     long_name="global mean heat flux from forcing"                                                                                                    unit="W/m2"     />
+    	 <field id="bgfrcsal"     long_name="global mean salt content from forcing"                                                                                                 unit="1e-3*km3" />
+    	 <field id="bgmistem"     long_name="global mean temperature error due to free surface (no vvl)"                                                                            unit="degC"     />
+    	 <field id="bgmissal"     long_name="global mean salinity error due to free surface (no vvl)"                                                                               unit="1e-3"     />
+     </field_group>
 
       <!-- LIM3 scalar variables -->
@@ -541,55 +546,23 @@
       <field_group id="SBC_scalar"  domain_ref="1point" >
          <!-- available with ln_limdiaout -->
-         <field id="ibgvoltot"    long_name="global mean ice volume"                                 unit="km3"        />
-         <field id="sbgvoltot"    long_name="global mean snow volume"                                unit="km3"        />
-         <field id="ibgarea"      long_name="global mean ice area"                                   unit="km2"        />
-         <field id="ibgsaline"    long_name="global mean ice salinity"                               unit="1e-3"       />
-         <field id="ibgtemper"    long_name="global mean ice temperature"                            unit="degC"       />
-         <field id="ibgheatco"    long_name="global mean ice heat content"                           unit="10^20J"     />
-         <field id="sbgheatco"    long_name="global mean snow heat content"                          unit="10^20J"     />
-         <field id="ibgsaltco"    long_name="global mean ice salt content"                           unit="1e-3*km3"   />
-
-         <field id="ibgvfx"       long_name="global mean volume flux (emp)"                          unit="m/day"      />
-         <field id="ibgvfxbog"    long_name="global mean volume flux (bottom growth)"                unit="m/day"      />
-         <field id="ibgvfxopw"    long_name="global mean volume flux (open water growth)"            unit="m/day"      />
-         <field id="ibgvfxsni"    long_name="global mean volume flux (snow-ice growth)"              unit="m/day"      />
-         <field id="ibgvfxdyn"    long_name="global mean volume flux (dynamic growth)"               unit="m/day"      />
-         <field id="ibgvfxbom"    long_name="global mean volume flux (bottom melt)"                  unit="m/day"      />
-         <field id="ibgvfxsum"    long_name="global mean volume flux (surface melt)"                 unit="m/day"      />
-         <field id="ibgvfxres"    long_name="global mean volume flux (resultant)"                    unit="m/day"      />
-         <field id="ibgvfxspr"    long_name="global mean volume flux (snow precip)"                  unit="m/day"      />
-         <field id="ibgvfxsnw"    long_name="global mean volume flux (snow melt)"                    unit="m/day"      />
-         <field id="ibgvfxsub"    long_name="global mean volume flux (snow sublimation)"             unit="m/day"      />
-
-         <field id="ibgsfx"       long_name="global mean salt flux (total)"                          unit="1e-3*m/day" />
-         <field id="ibgsfxbri"    long_name="global mean salt flux (brines)"                         unit="1e-3*m/day" />
-         <field id="ibgsfxdyn"    long_name="global mean salt flux (dynamic)"                        unit="1e-3*m/day" />
-         <field id="ibgsfxres"    long_name="global mean salt flux (resultant)"                      unit="1e-3*m/day" />
-         <field id="ibgsfxbog"    long_name="global mean salt flux (thermo)"                         unit="1e-3*m/day" />
-         <field id="ibgsfxopw"    long_name="global mean salt flux (thermo)"                         unit="1e-3*m/day" />
-         <field id="ibgsfxsni"    long_name="global mean salt flux (thermo)"                         unit="1e-3*m/day" />
-         <field id="ibgsfxbom"    long_name="global mean salt flux (thermo)"                         unit="1e-3*m/day" />
-         <field id="ibgsfxsum"    long_name="global mean salt flux (thermo)"                         unit="1e-3*m/day" />
-         <field id="ibgsfxsub"    long_name="global mean salt flux (thermo)"                         unit="1e-3*m/day" />
-
-         <field id="ibghfxdhc"    long_name="Heat content variation in snow and ice"                 unit="W"          />
-         <field id="ibghfxspr"    long_name="Heat content of snow precip"                            unit="W"          />
-
-         <field id="ibghfxthd"    long_name="heat fluxes from ice-ocean exchange during thermo"      unit="W"          />
-         <field id="ibghfxsum"    long_name="heat fluxes causing surface ice melt"                   unit="W"          />
-         <field id="ibghfxbom"    long_name="heat fluxes causing bottom ice melt"                    unit="W"          />
-         <field id="ibghfxbog"    long_name="heat fluxes causing bottom ice growth"                  unit="W"          />
-         <field id="ibghfxdif"    long_name="heat fluxes causing ice temperature change"             unit="W"          />
-         <field id="ibghfxopw"    long_name="heat fluxes causing open water ice formation"           unit="W"          />
-         <field id="ibghfxdyn"    long_name="heat fluxes from ice-ocean exchange during dynamic"     unit="W"          />
-         <field id="ibghfxres"    long_name="heat fluxes from ice-ocean exchange during resultant"   unit="W"          />
-         <field id="ibghfxsub"    long_name="heat fluxes from sublimation"                           unit="W"          />
-         <field id="ibghfxsnw"    long_name="heat fluxes from snow-ocean exchange"                   unit="W"          />
-         <field id="ibghfxout"    long_name="non solar heat fluxes received by the ocean"            unit="W"          />
-         <field id="ibghfxin"     long_name="total heat fluxes at the ice surface"                   unit="W"          />
-
-         <field id="ibgfrcvol"    long_name="global mean forcing volume (emp)"                       unit="km3"        />
-         <field id="ibgfrcsfx"    long_name="global mean forcing salt   (sfx)"                       unit="1e-3*km3"   />
-         <field id="ibgvolgrm"    long_name="global mean ice growth+melt volume"                     unit="km3"        />
+         <field id="ibgfrcvoltop"    long_name="global mean ice/snow forcing at interface ice/snow-atm (volume equivalent ocean volume)"   unit="km3"       />
+         <field id="ibgfrcvolbot"    long_name="global mean ice/snow forcing at interface ice/snow-ocean (volume equivalent ocean volume)" unit="km3"       />
+         <field id="ibgfrctemtop"    long_name="global mean heat on top of ice/snw/ocean-atm "                                             unit="1e20J"     />
+         <field id="ibgfrctembot"    long_name="global mean heat below ice (on top of ocean) "                                             unit="1e20J"     />
+         <field id="ibgfrcsal"       long_name="global mean ice/snow forcing (salt equivalent ocean volume)"                               unit="pss*km3"   />
+         <field id="ibgfrchfxtop"    long_name="global mean heat flux on top of ice/snw/ocean-atm "                                        unit="W/m2"      />
+         <field id="ibgfrchfxbot"    long_name="global mean heat flux below ice (on top of ocean) "                                        unit="W/m2"      />
+ 
+         <field id="ibgvolume"    long_name="drift in ice/snow volume (equivalent ocean volume)"            unit="km3"        />
+         <field id="ibgsaltco"    long_name="drift in ice salt content (equivalent ocean volume)"           unit="pss*km3"    />
+         <field id="ibgheatco"    long_name="drift in ice/snow heat content"                                unit="1e20J"      />
+         <field id="ibgheatfx"    long_name="drift in ice/snow heat flux"                                   unit="W/m2"       />
+
+         <field id="ibgvol_tot"    long_name="global mean ice volume"                                       unit="km3"        />
+         <field id="sbgvol_tot"    long_name="global mean snow volume"                                      unit="km3"        />
+         <field id="ibgarea_tot"   long_name="global mean ice area"                                         unit="km2"        />
+         <field id="ibgsalt_tot"   long_name="global mean ice salt content"                                 unit="1e-3*km3"   />
+         <field id="ibgheat_tot"   long_name="global mean ice heat content"                                 unit="1e20J"      />
+         <field id="sbgheat_tot"   long_name="global mean snow heat content"                                unit="1e20J"      />
       </field_group>
   
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/SHARED/namelist_ice_lim3_ref
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/SHARED/namelist_ice_lim3_ref	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/SHARED/namelist_ice_lim3_ref	(revision 7309)
@@ -1,47 +1,62 @@
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!! LIM3 namelist :  
+!! LIM3 namelist:  
 !!              1 - Generic parameters                 (namicerun)
-!!              2 - Ice initialization                 (namiceini)
-!!              3 - Ice discretization                 (namiceitd)
-!!              4 - Ice dynamics and transport         (namicedyn)
-!!              5 - Ice thermodynamics                 (namicethd)
-!!              6 - Ice salinity                       (namicesal)
-!!              7 - Ice mechanical redistribution      (namiceitdme)
-!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!!              2 - Diagnostics                        (namicediag)
+!!              3 - Ice initialization                 (namiceini)
+!!              4 - Ice discretization                 (namiceitd)
+!!              5 - Ice dynamics and transport         (namicedyn)
+!!              6 - Ice diffusion                      (namicehdf)
+!!              7 - Ice thermodynamics                 (namicethd)
+!!              8 - Ice salinity                       (namicesal)
+!!              9 - Ice mechanical redistribution      (namiceitdme)
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 !
 !------------------------------------------------------------------------------
 &namicerun     !   Generic parameters
 !------------------------------------------------------------------------------
-   jpl            =    5           !  number of ice  categories
-   nlay_i         =    2           !  number of ice  layers
-   nlay_s         =    1           !  number of snow layers (only 1 is working)
-   cn_icerst_in  = "restart_ice"   !  suffix of ice restart name (input)
-   cn_icerst_indir = "."           !  directory from which to read input ice restarts
-   cn_icerst_out = "restart_ice"   !  suffix of ice restart name (output)
-   cn_icerst_outdir = "."          !  directory in which to write output ice restarts
-   ln_limdyn     = .true.          !  ice dynamics (T) or thermodynamics only (F)
-   rn_amax_n     = 0.999           !  maximum tolerated ice concentration NH
-   rn_amax_s     = 0.999           !  maximum tolerated ice concentration SH
-   ln_limdiahsb  = .false.         !  check the heat and salt budgets (T) or not (F)
-   ln_limdiaout  = .true.          !  output the heat and salt budgets (T) or not (F)
-   ln_icectl     = .false.         !  ice points output for debug (T or F)
-   iiceprt       = 10              !  i-index for debug
-   jiceprt       = 10              !  j-index for debug
+   jpl              =    5          !  number of ice  categories
+   nlay_i           =    2          !  number of ice  layers
+   nlay_s           =    1          !  number of snow layers (only 1 is working)
+   rn_amax_n        =   0.997       !  maximum tolerated ice concentration NH
+   rn_amax_s        =   0.997       !  maximum tolerated ice concentration SH
+   cn_icerst_in     = "restart_ice" !  suffix of ice restart name (input)
+   cn_icerst_out    = "restart_ice" !  suffix of ice restart name (output)
+   cn_icerst_indir  = "."           !  directory to read   input ice restarts
+   cn_icerst_outdir = "."           !  directory to write output ice restarts
+   ln_limthd        =  .true.       !  ice thermo   (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
+   ln_limdyn        =  .true.       !  ice dynamics (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
+   nn_limdyn        =   2           !     (ln_limdyn=T) switch for ice dynamics   
+                                    !      2: total
+                                    !      1: advection only (no diffusion, no ridging/rafting)
+                                    !      0: advection only (as 1 but with prescribed velocity, bypass rheology)
+   rn_uice          =   0.00001     !     (nn_limdyn=0) ice u-velocity
+   rn_vice          =  -0.00001     !     (nn_limdyn=0) ice v-velocity
+/
+!------------------------------------------------------------------------------
+&namicediag    !   Diagnostics
+!------------------------------------------------------------------------------
+   ln_limdiachk   =  .false.        !  check online the heat, mass & salt budgets (T) or not (F)
+   ln_limdiahsb   =  .false.        !  output the heat, mass & salt budgets (T) or not (F)
+   ln_limctl      =  .false.        !  ice points output for debug (T or F)
+   iiceprt        =    10           !  i-index for debug
+   jiceprt        =    10           !  j-index for debug
 /
 !------------------------------------------------------------------------------
 &namiceini     !   Ice initialization
 !------------------------------------------------------------------------------
-   ln_iceini      = .true.         !  activate ice initialization (T) or not (F)
-   rn_thres_sst   =  2.0           !  maximum water temperature with initial ice (degC)
-   rn_hts_ini_n   =  0.3           !  initial real 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_s   =  270.          !        "            "             South
+                  ! -- limistate -- !
+   ln_limini      = .true.          !  activate ice initialization (T) or not (F)
+   ln_limini_file = .false.         !  netcdf file provided for initialization (T) or not (F)
+   rn_thres_sst   =  2.0            !  maximum water temperature with initial ice (degC)
+   rn_hts_ini_n   =  0.3            !  initial real 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_s   =  270.           !        "            "             South
 /
 !------------------------------------------------------------------------------
@@ -56,82 +71,115 @@
 &namicedyn     !   Ice dynamics and transport
 !------------------------------------------------------------------------------
-   nn_icestr      =    0           !  ice strength parameteriztaion                      
-                                   !     0: Hibler_79     P = pstar*<h>*exp(-c_rhg*A)
-                                   !     1: Rothrock_75   P = Cf*coeff*integral(wr.h^2)    
-   ln_icestr_bvf  =    .false.     !  ice strength function brine volume (T) or not (F)     
-   rn_pe_rdg      =   17.0         !  ridging work divided by pot. energy change in ridging, if nn_icestr = 1
-   rn_pstar       =    2.0e+04     !  ice strength thickness parameter (N/m2), nn_icestr = 0 
-   rn_crhg        =   20.0         !  ice strength conc. parameter (-), nn_icestr = 0       
-   rn_cio         =    5.0e-03     !  ice-ocean drag coefficient           (-)             
-   rn_creepl      =    1.0e-12     !  creep limit (s-1)                                   
-   rn_ecc         =    2.0         !  eccentricity of the elliptical yield curve          
-   nn_nevp        =  120           !  number of EVP subcycles                             
-   rn_relast      =    0.333       !  ratio of elastic timescale to ice time step: Telast = dt_ice * rn_relast 
-                                   !     advised value: 1/3 (rn_nevp=120) or 1/9 (rn_nevp=300)
-   nn_ahi0        =    2           !  horizontal diffusivity computation
-                                   !     0: use rn_ahi0_ref
-                                   !     1: use rn_ahi0_ref x mean grid cell length / ( 2deg mean grid cell length )
-                                   !     2: use rn_ahi0_ref x grid cell length      / ( 2deg mean grid cell length )
-   rn_ahi0_ref    = 350.0          !  horizontal sea ice diffusivity (m2/s) 
-                                   !     if nn_ahi0 > 0, rn_ahi0_ref is the reference value at a nominal 2 deg resolution
+                  ! -- limtrp & limadv -- !
+   nn_limadv      =    0            !  choose the advection scheme (-1=Prather ; 0=Ultimate-Macho)
+   nn_limadv_ord  =    5            !  choose the order of the advection scheme (if nn_limadv=0)
+                  ! -- limitd_me -- !
+   nn_icestr      =    0            !  ice strength parameteriztaion                      
+                                    !     0: Hibler_79     P = pstar*<h>*exp(-c_rhg*A)
+                                    !     1: Rothrock_75   P = Cf*coeff*integral(wr.h^2)    
+   rn_pe_rdg      =   17.0          !     (nn_icestr=1) ridging work divided by pot. energy change in ridging
+   rn_pstar       =    2.0e+04      !     (nn_icestr=0) ice strength thickness parameter (N/m2) 
+   rn_crhg        =   20.0          !     (nn_icestr=0) ice strength conc. parameter (-)
+   ln_icestr_bvf  =    .false.      !     ice strength function brine volume (T) or not (F)
+                                    !
+            ! -- limdyn & limrhg -- !
+   rn_cio         =    5.0e-03      !  ice-ocean drag coefficient (-)
+   rn_creepl      =    1.0e-12      !  creep limit (s-1)
+   rn_ecc         =    2.0          !  eccentricity of the elliptical yield curve          
+   nn_nevp        =  120            !  number of EVP subcycles                             
+   rn_relast      =    0.333        !  ratio of elastic timescale to ice time step: Telast = dt_ice * rn_relast 
+                                    !     advised value: 1/3 (rn_nevp=120) or 1/9 (rn_nevp=300)
+   ln_landfast    =  .false.        !  landfast ice parameterization (T or F)                           
+   rn_gamma       =    0.15         !     (ln_landfast=T)  fraction of ocean depth that ice must reach to initiate landfast
+                                    !                      recommended range: [0.1 ; 0.25]
+   rn_icebfr      =    10.          !     (ln_landfast=T)  maximum bottom stress per unit area of contact (N/m2)                 
+                                    !                      a very large value ensures ice velocity=0 even with a small contact area
+                                    !                      recommended range: ?? (should be greater than atm-ice stress => >0.1 N/m2)
+   rn_lfrelax     =    1.e-5        !     (ln_landfast=T)  relaxation time scale to reach static friction (s-1)                 
 /
 !------------------------------------------------------------------------------
 &namicehdf     !   Ice horizontal diffusion
 !------------------------------------------------------------------------------
-   nn_convfrq     = 5              !  convergence check frequency of the Crant-Nicholson scheme (perf. optimization)
+                     ! -- limhdf -- !
+   nn_ahi0        =    -1           !  horizontal diffusivity computation
+                                    !    -1: no diffusion (bypass limhdf)
+                                    !     0: use rn_ahi0_ref
+                                    !     1: use rn_ahi0_ref x mean grid cell length / ( 2deg mean grid cell length )
+                                    !     2: use rn_ahi0_ref x grid cell length      / ( 2deg mean grid cell length )
+   rn_ahi0_ref    = 350.0           !  horizontal sea ice diffusivity (m2/s) 
+                                    !     if nn_ahi0 > 0, rn_ahi0_ref is the reference value at a nominal 2 deg resolution
 /
 !------------------------------------------------------------------------------
 &namicethd     !   Ice thermodynamics
 !------------------------------------------------------------------------------
-   rn_hnewice  = 0.1               !  thickness for new ice formation in open water (m)
-   ln_frazil   = .false.           !  use frazil ice collection thickness as a function of wind (T) or not (F)
-   rn_maxfrazb = 1.0               !  maximum fraction of frazil ice collecting at the ice base
-   rn_vfrazb   = 0.417             !  thresold drift speed for frazil ice collecting at the ice bottom (m/s)
-   rn_Cfrazb   = 5.0               !  squeezing coefficient for frazil ice collecting at the ice bottom
-   rn_himin    = 0.10              !  minimum ice thickness (m) used in remapping, must be smaller than rn_hnewice
-   rn_betas    = 0.66              !  exponent in lead-ice repratition of snow precipitation
-                                   !     betas = 1 -> equipartition, betas < 1 -> more on leads
-   rn_kappa_i  = 1.0               !  radiation attenuation coefficient in sea ice (m-1)
-   nn_conv_dif = 50                !  maximal number of iterations for heat diffusion computation
-   rn_terr_dif = 0.0001            !  maximum temperature after heat diffusion (degC)
-   nn_ice_thcon= 1                 !  sea ice thermal conductivity
-                                   !     0: k = k0 + beta.S/T (Untersteiner, 1964)
-                                   !     1: k = k0 + beta1.S/T - beta2.T (Pringle et al., 2007)
-   nn_monocat  = 0                 !  virtual ITD mono-category parameterizations (1, jpl = 1 only) or not (0)
-                                   !     2: simple piling instead of ridging --- temporary option
-                                   !     3: activate G(he) only              --- temporary option
-                                   !     4: activate lateral melting only    --- temporary option
-  ln_it_qnsice = .true.            !  iterate the surface non-solar flux with surface temperature (T) or not (F)
+                 ! -- limthd_dif -- !
+   rn_kappa_i     = 1.0             !  radiation attenuation coefficient in sea ice (m-1)
+   nn_conv_dif    = 50              !  maximal number of iterations for heat diffusion computation
+   rn_terr_dif    = 1.0e-04         !  maximum temperature after heat diffusion (degC)
+   nn_ice_thcon   = 1               !  sea ice thermal conductivity
+                                    !     0: k = k0 + beta.S/T            (Untersteiner, 1964)
+                                    !     1: k = k0 + beta1.S/T - beta2.T (Pringle et al., 2007)
+   ln_it_qnsice   = .true.          !  iterate the surface non-solar flux with surface temperature (T) or not (F)
+   nn_monocat     = 0               !  virtual ITD mono-category parameterizations (1, jpl = 1 only) or not (0)
+                                    !     2: simple piling instead of ridging    --- temporary option
+                                    !     3: activate G(he) only                 --- temporary option
+                                    !     4: activate extra lateral melting only --- temporary option
+                  ! -- limthd_dh -- !
+   ln_limdH       = .true.          !  activate ice thickness change from growing/melting (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
+   rn_betas       = 0.66            !  exponent in lead-ice repratition of snow precipitation
+                                    !     betas = 1 -> equipartition, betas < 1 -> more on leads
+                  ! -- limthd_da -- !
+   ln_limdA       = .true.          !  activate lateral melting param. (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
+   rn_beta        = 1.0             !     (ln_latmelt=T) coef. beta for lateral melting param. Recommended range=[0.8-1.2]
+                                    !      => decrease = more melt and melt peaks toward higher concentration (A~0.5 for beta=1 ; A~0.8 for beta=0.2)
+                                    !         0.3 = best fit for western Fram Strait and Antarctica
+                                    !         1.4 = best fit for eastern Fram Strait      
+   rn_dmin        = 8.              !     (ln_latmelt=T) minimum floe diameter for lateral melting param. Recommended range=[6-10]
+                                    !      => 6  vs 8m = +40% melting at the peak (A~0.5)
+                                    !         10 vs 8m = -20% melting
+                 ! -- limthd_lac -- !
+   ln_limdO       = .true.          !  activate ice growth in open-water (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
+   rn_hnewice     = 0.1             !  thickness for new ice formation in open water (m)
+   ln_frazil      = .false.         !  Frazil ice parameterization (ice collection as a function of wind)
+   rn_maxfrazb    = 1.0             !     (ln_frazil=T) maximum fraction of frazil ice collecting at the ice base
+   rn_vfrazb      = 0.417           !     (ln_frazil=T) thresold drift speed for frazil ice collecting at the ice bottom (m/s)
+   rn_Cfrazb      = 5.0             !     (ln_frazil=T) squeezing coefficient for frazil ice collecting at the ice bottom
+                  ! -- limitd_th -- !
+   rn_himin       = 0.1             !  minimum ice thickness (m) used in remapping, must be smaller than rn_hnewice
 /
 !------------------------------------------------------------------------------
 &namicesal     !   Ice salinity
 !------------------------------------------------------------------------------
-   nn_icesal   =  2                !  ice salinity option
-                                   !     1: constant ice salinity (S=rn_icesal)
-                                   !     2: varying salinity parameterization S(z,t)
-                                   !     3: prescribed salinity profile S(z), Schwarzacher, 1959
-   rn_icesal   =  4.               !  ice salinity (g/kg, nn_icesal = 1 only)
-   rn_sal_gd   =  5.               !  restoring ice salinity, gravity drainage (g/kg)
-   rn_time_gd  =  1.73e+6          !  restoring time scale, gravity drainage  (s)
-   rn_sal_fl   =  2.               !  restoring ice salinity, flushing (g/kg)
-   rn_time_fl  =  8.64e+5          !  restoring time scale, flushing (s)
-   rn_simax    = 20.               !  maximum tolerated ice salinity (g/kg)
-   rn_simin    =  0.1              !  minimum tolerated ice salinity (g/kg)
+                 ! -- limthd_sal -- !
+   ln_limdS       = .true.          !  activate gravity drainage and flushing (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
+   nn_icesal      =  2              !  ice salinity option
+                                    !     1: constant ice salinity (S=rn_icesal)
+                                    !     2: varying salinity parameterization S(z,t)
+                                    !     3: prescribed salinity profile S(z), Schwarzacher, 1959
+   rn_icesal      =  4.             !    (nn_icesal=1) ice salinity (g/kg)
+   rn_sal_gd      =  5.             !  restoring ice salinity, gravity drainage (g/kg)
+   rn_time_gd     =  1.73e+6        !  restoring time scale, gravity drainage  (s)
+   rn_sal_fl      =  2.             !  restoring ice salinity, flushing (g/kg)
+   rn_time_fl     =  8.64e+5        !  restoring time scale, flushing (s)
+   rn_simax       = 20.             !  maximum tolerated ice salinity (g/kg)
+   rn_simin       =  0.1            !  minimum tolerated ice salinity (g/kg)
 /
 !------------------------------------------------------------------------------
 &namiceitdme   !   Ice mechanical redistribution (ridging and rafting)
 !------------------------------------------------------------------------------
-   rn_Cs       =   0.5             !  fraction of shearing energy contributing to ridging
-   rn_fsnowrdg =   0.5             !  snow volume fraction that survives in ridging
-   rn_fsnowrft =   0.5             !  snow volume fraction that survives in rafting
-   nn_partfun  =   1               !  type of ridging participation function
-                                   !     0: linear (Thorndike et al, 1975)
-                                   !     1: exponential (Lipscomb, 2007
-   rn_gstar    =   0.15            !  fractional area of thin ice being ridged (nn_partfun = 0)
-   rn_astar    =   0.05            !  exponential measure of ridging ice fraction (nn_partfun = 1)
-   rn_hstar    = 100.0             !  determines the maximum thickness of ridged ice (m) (Hibler, 1980)
-   ln_rafting  =   .true.          !  rafting activated (T) or not (F)
-   rn_hraft    =   0.75            !  threshold thickness for rafting (m)
-   rn_craft    =   5.0             !  squeezing coefficient used in the rafting function
-   rn_por_rdg  =   0.3             !  porosity of newly ridged ice (Lepparanta et al., 1995)
+                  ! -- limitd_me -- !
+   rn_cs          =   0.5           !  fraction of shearing energy contributing to ridging
+   nn_partfun     =   1             !  type of ridging participation function
+                                    !     0: linear      (Thorndike et al, 1975)
+                                    !     1: exponential (Lipscomb, 2007)
+   rn_gstar       =   0.15          !     (nn_partfun = 0) fractional area of thin ice being ridged 
+   rn_astar       =   0.05          !     (nn_partfun = 1) exponential measure of ridging ice fraction
+   ln_ridging     =   .true.        !  ridging activated (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
+   rn_hstar       = 100.0           !     (ln_ridging = T) determines the maximum thickness of ridged ice (m) (Hibler, 1980)
+   rn_por_rdg     =   0.3           !     (ln_ridging = T) porosity of newly ridged ice (Lepparanta et al., 1995)
+   rn_fsnowrdg    =   0.5           !     (ln_ridging = T) snow volume fraction that survives in ridging
+   ln_rafting     =   .true.        !  rafting activated (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
+   rn_hraft       =   0.75          !     (ln_rafting = T) threshold thickness for rafting (m)
+   rn_craft       =   5.0           !     (ln_rafting = T) squeezing coefficient used in the rafting function
+   rn_fsnowrft    =   0.5           !     (ln_rafting = T) snow volume fraction that survives in rafting
 /
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/SHARED/namelist_ref
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 7309)
@@ -11,5 +11,5 @@
 !!              6 - Tracer           (nameos, namtra_adv, namtra_ldf, namtra_ldfeiv, namtra_dmp)
 !!              7 - dynamics         (namdyn_adv, namdyn_vor, namdyn_hpg, namdyn_spg, namdyn_ldf)
-!!              8 - Verical physics  (namzdf, namzdf_ric, namzdf_tke, namzdf_ddm, namzdf_tmx)
+!!              8 - Verical physics  (namzdf, namzdf_ric, namzdf_tke, namzdf_ddm, namzdf_tmx, namzdf_tmx_new)
 !!              9 - diagnostics      (namnc4, namtrd, namspr, namflo, namhsb, namsto)
 !!             10 - miscellaneous    (nammpp, namctl)
@@ -295,4 +295,5 @@
 &namsbc_ana    !   analytical surface boundary condition
 !-----------------------------------------------------------------------
+   ! --- oce variables --- !
    nn_tau000   =   0       !  gently increase the stress over the first ntau_rst time-steps
    rn_utau0    =   0.5     !  uniform value for the i-stress
@@ -301,4 +302,11 @@
    rn_qsr0     =   0.e0    !  uniform value for the solar radiation
    rn_emp0     =   0.e0    !  uniform value for the freswater budget (E-P)
+   ! --- ice variables --- !
+   rn_iutau0   =   0.e0    !  uniform value for the i-stress over ice
+   rn_ivtau0   =   0.e0    !  uniform value for the j-stress over ice
+   rn_iqns0    =   0.e0    !  uniform value for the total heat flux over ice
+   rn_iqsr0    =   0.e0    !  uniform value for the solar radiation over ice
+   rn_sprec0   =   0.e0    !  uniform value for snow precip
+   rn_ievap0   =   0.e0    !  uniform value for sublimation
 /
 !-----------------------------------------------------------------------
@@ -353,4 +361,6 @@
    rn_vfac     = 0.        !  multiplicative factor for ocean/ice velocity
                            !  in the calculation of the wind stress (0.=absolute winds or 1.=relative winds)
+   ln_Cd_L12   = .false.   !  Modify the drag ice-atm and oce-atm depending on ice concentration
+                           !  This parameterization is from Lupkes et al. (JGR 2012)
 /
 !-----------------------------------------------------------------------
@@ -401,4 +411,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      !
+   l_sasread   = .TRUE.   ! Read fields in a file if .TRUE. , or initialize to 0. in sbcssm.F90 if .FALSE.
    sn_usp      = 'sas_grid_U',     120           , 'vozocrtx',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
    sn_vsp      = 'sas_grid_V',     120           , 'vomecrty',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_2/iceini_2.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_2/iceini_2.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_2/iceini_2.F90	(revision 7309)
@@ -83,5 +83,5 @@
       CALL ice_run_2                   ! read in namelist some run parameters
       !          
-      rdt_ice = nn_fsbc * rdt           ! sea-ice time step
+      rdt_ice = nn_fsbc * rdt          ! sea-ice time step
       numit   = nit000 - 1
       !
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_2/limmsh_2.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_2/limmsh_2.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_2/limmsh_2.F90	(revision 7309)
@@ -80,5 +80,5 @@
       njeqm1 = njeq - 1 
 
-      fcor(:,:) = 2. * omega * SIN( gphit(:,:) * rad )   !  coriolis factor at T-point
+      fcor(:,:) = 2. * omega * SIN( gphif(:,:) * rad )   !  coriolis factor at T-point
  
 !i    DO jj = 1, jpj
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/dom_ice.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/dom_ice.F90	(revision 7308)
+++ 	(revision )
@@ -1,46 +1,0 @@
-MODULE dom_ice
-   !!======================================================================
-   !!                   ***  MODULE  dom_ice  ***
-   !! LIM-3 Sea Ice :   Domain  variables
-   !!======================================================================
-   !! History :  3.0  ! 2003-08  (M. Vancoppenolle)  LIM-3 original code
-   !!            3.5  ! 2011-02  (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC dom_ice_alloc   ! Routine called by nemogcm.F90
-
-   LOGICAL, PUBLIC ::   l_jeq = .TRUE.       !: Equator inside the domain flag
-
-   INTEGER, PUBLIC ::   njeq , njeqm1        !: j-index of the equator if it is inside the domain
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   fcor   !: coriolis coefficient
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   wght   !: weight of the 4 neighbours to compute averages
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   FUNCTION dom_ice_alloc()
-      !!-------------------------------------------------------------------
-      !!            *** Routine dom_ice_alloc ***
-      !!-------------------------------------------------------------------
-      INTEGER :: dom_ice_alloc
-      !!-------------------------------------------------------------------
-      !
-      ALLOCATE( fcor(jpi,jpj), wght(jpi,jpj,2,2), STAT = dom_ice_alloc )
-      !
-      IF( dom_ice_alloc /= 0 )   CALL ctl_warn( 'dom_ice_alloc: failed to allocate arrays.' )
-      !
-   END FUNCTION dom_ice_alloc
-
-   !!======================================================================
-END MODULE dom_ice
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/ice.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/ice.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/ice.F90	(revision 7309)
@@ -146,8 +146,7 @@
    !! smt_i       |      -      |    Mean sea ice salinity        | ppt   |
    !! tm_i        |      -      |    Mean sea ice temperature     | K     |
-   !! ot_i        !      -      !    Sea ice areal age content    | day   |
    !! et_i        !      -      !    Total ice enthalpy           | J/m2  | 
    !! et_s        !      -      !    Total snow enthalpy          | J/m2  | 
-   !! bv_i        !      -      !    Mean relative brine volume   | ???   | 
+   !! bv_i        !      -      !    relative brine volume        | ???   | 
    !!=====================================================================
 
@@ -157,4 +156,126 @@
    !! * Share Module variables
    !!--------------------------------------------------------------------------
+   !                                     !!** ice-generic parameters namelist (namicerun) **
+   INTEGER           , PUBLIC ::   jpl             !: number of ice  categories 
+   INTEGER           , PUBLIC ::   nlay_i          !: number of ice  layers 
+   INTEGER           , PUBLIC ::   nlay_s          !: number of snow layers 
+   REAL(wp)          , PUBLIC ::   rn_amax_n       !: maximum ice concentration Northern hemisphere
+   REAL(wp)          , PUBLIC ::   rn_amax_s       !: maximum ice concentration Southern hemisphere
+   CHARACTER(len=32) , PUBLIC ::   cn_icerst_in    !: suffix of ice restart name (input)
+   CHARACTER(len=32) , PUBLIC ::   cn_icerst_out   !: suffix of ice restart name (output)
+   CHARACTER(len=256), PUBLIC ::   cn_icerst_indir !: ice restart input directory
+   CHARACTER(len=256), PUBLIC ::   cn_icerst_outdir!: ice restart output directory
+   LOGICAL           , PUBLIC ::   ln_limthd       !: flag for ice thermo (T) or not (F)
+   LOGICAL           , PUBLIC ::   ln_limdyn       !: flag for ice dynamics (T) or not (F)
+   INTEGER           , PUBLIC ::   nn_limdyn       !: flag for ice dynamics
+   REAL(wp)          , PUBLIC ::   rn_uice         !: prescribed u-vel (case nn_limdyn=0)
+   REAL(wp)          , PUBLIC ::   rn_vice         !: prescribed v-vel (case nn_limdyn=0)
+   
+   !                                     !!** ice-diagnostics namelist (namicediag) **
+   LOGICAL , PUBLIC ::   ln_limdiachk     !: flag for ice diag (T) or not (F)
+   LOGICAL , PUBLIC ::   ln_limdiahsb     !: flag for ice diag (T) or not (F)
+   LOGICAL , PUBLIC ::   ln_limctl        !: flag for sea-ice points output (T) or not (F)
+   INTEGER , PUBLIC ::   iiceprt          !: debug i-point
+   INTEGER , PUBLIC ::   jiceprt          !: debug j-point
+
+   !                                     !!** ice-init namelist (namiceini) **
+                                          ! -- limistate -- !
+   LOGICAL , PUBLIC ::   ln_limini        ! initialization or not
+   LOGICAL , PUBLIC ::   ln_limini_file   ! Ice initialization state from 2D netcdf file
+   REAL(wp), PUBLIC ::   rn_thres_sst     ! threshold water temperature for initial sea ice
+   REAL(wp), PUBLIC ::   rn_hts_ini_n     ! initial snow thickness in the north
+   REAL(wp), PUBLIC ::   rn_hts_ini_s     ! initial snow thickness in the south
+   REAL(wp), PUBLIC ::   rn_hti_ini_n     ! initial ice thickness in the north
+   REAL(wp), PUBLIC ::   rn_hti_ini_s     ! initial ice thickness in the south
+   REAL(wp), PUBLIC ::   rn_ati_ini_n     ! initial leads area in the north
+   REAL(wp), PUBLIC ::   rn_ati_ini_s     ! initial leads area in the south
+   REAL(wp), PUBLIC ::   rn_smi_ini_n     ! initial salinity 
+   REAL(wp), PUBLIC ::   rn_smi_ini_s     ! initial salinity
+   REAL(wp), PUBLIC ::   rn_tmi_ini_n     ! initial temperature
+   REAL(wp), PUBLIC ::   rn_tmi_ini_s     ! initial temperature
+   
+   !                                     !!** ice-thickness distribution namelist (namiceitd) **
+   INTEGER , PUBLIC ::   nn_catbnd        !: categories distribution following: tanh function (1), or h^(-alpha) function (2)
+   REAL(wp), PUBLIC ::   rn_himean        !: mean thickness of the domain (used to compute the distribution, nn_itdshp = 2 only)
+
+   !                                     !!** ice-dynamics namelist (namicedyn) **
+                                          ! -- limtrp & limadv -- !
+   INTEGER , PUBLIC ::   nn_limadv        !: choose the advection scheme (-1=Prather ; 0=Ultimate-Macho)
+   INTEGER , PUBLIC ::   nn_limadv_ord    !: choose the order of the advection scheme (if Ultimate-Macho)   
+                                          ! -- limitd_me -- !
+   INTEGER , PUBLIC ::   nn_icestr        !: ice strength parameterization (0=Hibler79 1=Rothrock75)
+   REAL(wp), PUBLIC ::   rn_pe_rdg        !: ridging work divided by pot. energy change in ridging, nn_icestr = 1
+   REAL(wp), PUBLIC ::   rn_pstar         !: determines ice strength, Hibler JPO79
+   REAL(wp), PUBLIC ::   rn_crhg          !: determines changes in ice strength
+   LOGICAL , PUBLIC ::   ln_icestr_bvf    !: use brine volume to diminish ice strength
+                                          ! -- limdyn & limrhg -- !
+   REAL(wp), PUBLIC ::   rn_cio           !: drag coefficient for oceanic stress
+   REAL(wp), PUBLIC ::   rn_creepl        !: creep limit : has to be under 1.0e-9
+   REAL(wp), PUBLIC ::   rn_ecc           !: eccentricity of the elliptical yield curve
+   INTEGER , PUBLIC ::   nn_nevp          !: number of iterations for subcycling
+   REAL(wp), PUBLIC ::   rn_relast        !: ratio => telast/rdt_ice (1/3 or 1/9 depending on nb of subcycling nevp) 
+   LOGICAL , PUBLIC ::   ln_landfast      !: landfast ice parameterization (T or F) 
+   REAL(wp), PUBLIC ::   rn_gamma         !: 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 (landfast ice) 
+   REAL(wp), PUBLIC ::   rn_lfrelax       !: relaxation time scale (s-1) to reach static friction (landfast ice) 
+
+   !                                     !!** ice-diffusion namelist (namicehdf) **
+   INTEGER , PUBLIC ::   nn_ahi0          !: sea-ice hor. eddy diffusivity coeff. (3 ways of calculation)
+   REAL(wp), PUBLIC ::   rn_ahi0_ref      !: sea-ice hor. eddy diffusivity coeff. (m2/s)
+
+   !                                     !!** ice-thermodynamics namelist (namicethd) **
+                                          ! -- limthd_dif -- !
+   REAL(wp), PUBLIC ::   rn_kappa_i       !: coef. for the extinction of radiation Grenfell et al. (2006) [1/m]
+   REAL(wp), PUBLIC ::   nn_conv_dif      !: maximal number of iterations for heat diffusion
+   REAL(wp), PUBLIC ::   rn_terr_dif      !: maximal tolerated error (C) for heat diffusion
+   INTEGER , PUBLIC ::   nn_ice_thcon     !: thermal conductivity: =0 Untersteiner (1964) ; =1 Pringle et al (2007)
+   LOGICAL , PUBLIC ::   ln_it_qnsice     !: iterate surface flux with changing surface temperature or not (F)
+   INTEGER , PUBLIC ::   nn_monocat       !: virtual ITD mono-category parameterizations (1) or not (0)
+                                          ! -- limthd_dh -- !
+   LOGICAL , PUBLIC ::   ln_limdH         !: activate ice thickness change from growing/melting (T) or not (F)
+   REAL(wp), PUBLIC ::   rn_betas         !: coef. for partitioning of snowfall between leads and sea ice
+                                          ! -- limthd_da -- !
+   LOGICAL , PUBLIC ::   ln_limdA         !: activate lateral melting param. (T) or not (F)
+   REAL(wp), PUBLIC ::   rn_beta          !: coef. beta for lateral melting param.
+   REAL(wp), PUBLIC ::   rn_dmin          !: minimum floe diameter for lateral melting param.
+                                          ! -- limthd_lac -- !
+   LOGICAL , PUBLIC ::   ln_limdO         !: activate ice growth in open-water (T) or not (F)
+   REAL(wp), PUBLIC ::   rn_hnewice       !: thickness for new ice formation (m)
+   LOGICAL , PUBLIC ::   ln_frazil        !: use of frazil ice collection as function of wind (T) or not (F)
+   REAL(wp), PUBLIC ::   rn_maxfrazb      !: maximum portion of frazil ice collecting at the ice bottom
+   REAL(wp), PUBLIC ::   rn_vfrazb        !: threshold drift speed for collection of bottom frazil ice
+   REAL(wp), PUBLIC ::   rn_Cfrazb        !: squeezing coefficient for collection of bottom frazil ice
+                                          ! -- limitd_th -- !
+   REAL(wp), PUBLIC ::   rn_himin         !: minimum ice thickness
+
+   !                                     !!** ice-salinity namelist (namicesal) **
+   LOGICAL , PUBLIC ::   ln_limdS         !: activate gravity drainage and flushing (T) or not (F)
+   INTEGER , PUBLIC ::   nn_icesal        !: salinity configuration used in the model
+   !                                      ! 1 - constant salinity in both space and time
+   !                                      ! 2 - prognostic salinity (s(z,t))
+   !                                      ! 3 - salinity profile, constant in time
+   REAL(wp), PUBLIC ::   rn_icesal        !: bulk salinity (ppt) in case of constant salinity
+   REAL(wp), PUBLIC ::   rn_sal_gd        !: restoring salinity for gravity drainage [PSU]
+   REAL(wp), PUBLIC ::   rn_time_gd       !: restoring time constant for gravity drainage (= 20 days) [s]
+   REAL(wp), PUBLIC ::   rn_sal_fl        !: restoring salinity for flushing [PSU]
+   REAL(wp), PUBLIC ::   rn_time_fl       !: restoring time constant for gravity drainage (= 10 days) [s]
+   REAL(wp), PUBLIC ::   rn_simax         !: maximum ice salinity [PSU]
+   REAL(wp), PUBLIC ::   rn_simin         !: minimum ice salinity [PSU]
+
+   !                                     !!** ice-mechanical redistribution namelist (namiceitdme)
+   REAL(wp), PUBLIC ::   rn_cs            !: fraction of shearing energy contributing to ridging            
+   INTEGER , PUBLIC ::   nn_partfun       !: participation function: =0 Thorndike et al. (1975), =1 Lipscomb et al. (2007)
+   REAL(wp), PUBLIC ::   rn_gstar         !: fractional area of young ice contributing to ridging
+   REAL(wp), PUBLIC ::   rn_astar         !: equivalent of G* for an exponential participation function
+   LOGICAL , PUBLIC ::   ln_ridging       !: ridging of ice or not                        
+   REAL(wp), PUBLIC ::   rn_hstar         !: thickness that determines the maximal thickness of ridged ice
+   REAL(wp), PUBLIC ::   rn_por_rdg       !: initial porosity of ridges (0.3 regular value)
+   REAL(wp), PUBLIC ::   rn_fsnowrdg      !: fractional snow loss to the ocean during ridging
+   LOGICAL , PUBLIC ::   ln_rafting       !: rafting of ice or not                        
+   REAL(wp), PUBLIC ::   rn_hraft         !: threshold thickness (m) for rafting / ridging 
+   REAL(wp), PUBLIC ::   rn_craft         !: coefficient for smoothness of the hyperbolic tangent in rafting
+   REAL(wp), PUBLIC ::   rn_fsnowrft      !: fractional snow loss to the ocean during ridging
+
+   !                                     !!** some other parameters 
    INTEGER , PUBLIC ::   nstart           !: iteration number of the begining of the run 
    INTEGER , PUBLIC ::   nlast            !: iteration number of the end of the run 
@@ -163,85 +284,21 @@
    REAL(wp), PUBLIC ::   rdt_ice          !: ice time step
    REAL(wp), PUBLIC ::   r1_rdtice        !: = 1. / rdt_ice
-
-   !                                     !!** ice-thickness distribution namelist (namiceitd) **
-   INTEGER , PUBLIC ::   nn_catbnd        !: categories distribution following: tanh function (1), or h^(-alpha) function (2)
-   REAL(wp), PUBLIC ::   rn_himean        !: mean thickness of the domain (used to compute the distribution, nn_itdshp = 2 only)
-
-   !                                     !!** ice-dynamics namelist (namicedyn) **
-   LOGICAL , PUBLIC ::   ln_icestr_bvf    !: use brine volume to diminish ice strength
-   INTEGER , PUBLIC ::   nn_icestr        !: ice strength parameterization (0=Hibler79 1=Rothrock75)
-   INTEGER , PUBLIC ::   nn_nevp          !: number of iterations for subcycling
-   INTEGER , PUBLIC ::   nn_ahi0          !: sea-ice hor. eddy diffusivity coeff. (3 ways of calculation)
-   REAL(wp), PUBLIC ::   rn_pe_rdg        !: ridging work divided by pot. energy change in ridging, nn_icestr = 1
-   REAL(wp), PUBLIC ::   rn_cio           !: drag coefficient for oceanic stress
-   REAL(wp), PUBLIC ::   rn_pstar         !: determines ice strength (N/M), Hibler JPO79
-   REAL(wp), PUBLIC ::   rn_crhg          !: determines changes in ice strength
-   REAL(wp), PUBLIC ::   rn_creepl        !: creep limit : has to be under 1.0e-9
-   REAL(wp), PUBLIC ::   rn_ecc           !: eccentricity of the elliptical yield curve
-   REAL(wp), PUBLIC ::   rn_ahi0_ref      !: sea-ice hor. eddy diffusivity coeff. (m2/s)
-   REAL(wp), PUBLIC ::   rn_relast        !: ratio => telast/rdt_ice (1/3 or 1/9 depending on nb of subcycling nevp) 
-
-   !                                     !!** ice-salinity namelist (namicesal) **
-   REAL(wp), PUBLIC ::   rn_simax         !: maximum ice salinity [PSU]
-   REAL(wp), PUBLIC ::   rn_simin         !: minimum ice salinity [PSU]
-   REAL(wp), PUBLIC ::   rn_sal_gd        !: restoring salinity for gravity drainage [PSU]
-   REAL(wp), PUBLIC ::   rn_sal_fl        !: restoring salinity for flushing [PSU]
-   REAL(wp), PUBLIC ::   rn_time_gd       !: restoring time constant for gravity drainage (= 20 days) [s]
-   REAL(wp), PUBLIC ::   rn_time_fl       !: restoring time constant for gravity drainage (= 10 days) [s]
-   REAL(wp), PUBLIC ::   rn_icesal        !: bulk salinity (ppt) in case of constant salinity
-
-   !                                     !!** ice-salinity namelist (namicesal) **
-   INTEGER , PUBLIC ::   nn_icesal           !: salinity configuration used in the model
-   !                                         ! 1 - constant salinity in both space and time
-   !                                         ! 2 - prognostic salinity (s(z,t))
-   !                                         ! 3 - salinity profile, constant in time
-   INTEGER , PUBLIC ::   nn_ice_thcon        !: thermal conductivity: =0 Untersteiner (1964) ; =1 Pringle et al (2007)
-   INTEGER , PUBLIC ::   nn_monocat          !: virtual ITD mono-category parameterizations (1) or not (0)
-   LOGICAL , PUBLIC ::   ln_it_qnsice        !: iterate surface flux with changing surface temperature or not (F)
-
-   !                                     !!** ice-mechanical redistribution namelist (namiceitdme)
-   REAL(wp), PUBLIC ::   rn_cs            !: fraction of shearing energy contributing to ridging            
-   REAL(wp), PUBLIC ::   rn_fsnowrdg      !: fractional snow loss to the ocean during ridging
-   REAL(wp), PUBLIC ::   rn_fsnowrft      !: fractional snow loss to the ocean during ridging
-   REAL(wp), PUBLIC ::   rn_gstar         !: fractional area of young ice contributing to ridging
-   REAL(wp), PUBLIC ::   rn_astar         !: equivalent of G* for an exponential participation function
-   REAL(wp), PUBLIC ::   rn_hstar         !: thickness that determines the maximal thickness of ridged ice
-   REAL(wp), PUBLIC ::   rn_hraft         !: threshold thickness (m) for rafting / ridging 
-   REAL(wp), PUBLIC ::   rn_craft         !: coefficient for smoothness of the hyperbolic tangent in rafting
-   REAL(wp), PUBLIC ::   rn_por_rdg       !: initial porosity of ridges (0.3 regular value)
-   REAL(wp), PUBLIC ::   rn_betas         !: coef. for partitioning of snowfall between leads and sea ice
-   REAL(wp), PUBLIC ::   rn_kappa_i       !: coef. for the extinction of radiation Grenfell et al. (2006) [1/m]
-   REAL(wp), PUBLIC ::   nn_conv_dif      !: maximal number of iterations for heat diffusion
-   REAL(wp), PUBLIC ::   rn_terr_dif      !: maximal tolerated error (C) for heat diffusion
-
-   !                                     !!** ice-mechanical redistribution namelist (namiceitdme)
-   LOGICAL , PUBLIC ::   ln_rafting      !: rafting of ice or not                        
-   INTEGER , PUBLIC ::   nn_partfun      !: participation function: =0 Thorndike et al. (1975), =1 Lipscomb et al. (2007)
-
-   REAL(wp), PUBLIC ::   usecc2           !:  = 1.0 / ( rn_ecc * rn_ecc )
-   REAL(wp), PUBLIC ::   rhoco            !: = rau0 * cio
    REAL(wp), PUBLIC ::   r1_nlay_i        !: 1 / nlay_i
    REAL(wp), PUBLIC ::   r1_nlay_s        !: 1 / nlay_s 
-   !
-   !                                     !!** switch for presence of ice or not 
-   REAL(wp), PUBLIC ::   rswitch
-   !
-   !                                     !!** define some parameters 
+   REAL(wp), PUBLIC ::   rswitch          !: switch for the presence of ice (1) or not (0)
    REAL(wp), PUBLIC, PARAMETER ::   epsi06   = 1.e-06_wp  !: small number 
    REAL(wp), PUBLIC, PARAMETER ::   epsi10   = 1.e-10_wp  !: small number 
    REAL(wp), PUBLIC, PARAMETER ::   epsi20   = 1.e-20_wp  !: small number 
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   u_oce, v_oce   !: surface ocean velocity used in ice dynamics
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ahiu , ahiv    !: hor. diffusivity coeff. at U- and V-points [m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ust2s, hicol   !: friction velocity, ice collection thickness accreted in leads
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   strp1, strp2   !: strength at previous time steps
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   strength       !: ice strength
+   !                                     !!** define arrays
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   u_oce, v_oce !: surface ocean velocity used in ice dynamics
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ahiu , ahiv !: hor. diffusivity coeff. at U- and V-points [m2/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hicol       !: ice collection thickness accreted in leads
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   strength    !: ice strength
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   stress1_i, stress2_i, stress12_i   !: 1st, 2nd & diagonal stress tensor element
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   delta_i        !: ice rheology elta factor (Flato & Hibler 95) [s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   divu_i         !: Divergence of the velocity field [s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   shear_i        !: Shear of the velocity field [s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   delta_i     !: ice rheology elta factor (Flato & Hibler 95) [s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   divu_i      !: Divergence of the velocity field [s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   shear_i     !: Shear of the velocity field [s-1]
    !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sist        !: Average Sea-Ice Surface Temperature [Kelvin]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   icethi      !: total ice thickness (for all categories) (diag only)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_bo        !: Sea-Ice bottom temperature [Kelvin]     
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   frld        !: Leads fraction = 1 - ice fraction
@@ -252,16 +309,17 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fhld        !: heat flux from the lead used for bottom melting
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_snw    !: snow-ocean mass exchange   [kg.m-2.s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_spr    !: snow precipitation on ice  [kg.m-2.s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_sub    !: snow/ice sublimation       [kg.m-2.s-1]
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_ice    !: ice-ocean mass exchange                   [kg.m-2.s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_sni    !: snow ice growth component of wfx_ice      [kg.m-2.s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_opw    !: lateral ice growth component of wfx_ice   [kg.m-2.s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_bog    !: bottom ice growth component of wfx_ice    [kg.m-2.s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_dyn    !: dynamical ice growth component of wfx_ice [kg.m-2.s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_bom    !: bottom melt component of wfx_ice          [kg.m-2.s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_sum    !: surface melt component of wfx_ice         [kg.m-2.s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_res    !: residual component of wfx_ice             [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_snw     !: snow-ocean mass exchange   [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_spr     !: snow precipitation on ice  [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_sub     !: snow/ice sublimation       [kg.m-2.s-1]
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_ice     !: ice-ocean mass exchange                   [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_sni     !: snow ice growth component of wfx_ice      [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_opw     !: lateral ice growth component of wfx_ice   [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_bog     !: bottom ice growth component of wfx_ice    [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_dyn     !: dynamical ice growth component of wfx_ice [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_bom     !: bottom melt component of wfx_ice          [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_sum     !: surface melt component of wfx_ice         [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_lam     !: lateral melt component of wfx_ice         [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_res     !: residual component of wfx_ice             [kg.m-2.s-1]
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   afx_tot     !: ice concentration tendency (total)          [s-1]
@@ -271,4 +329,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx_bog     !: salt flux due to ice growth/melt                      [PSU/m2/s]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx_bom     !: salt flux due to ice growth/melt                      [PSU/m2/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx_lam     !: salt flux due to ice growth/melt                      [PSU/m2/s]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx_sum     !: salt flux due to ice growth/melt                      [PSU/m2/s]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx_sni     !: salt flux due to ice growth/melt                      [PSU/m2/s]
@@ -302,7 +361,7 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_res     !: residual heat flux due to correction of ice thickness [W.m-2]
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ftr_ice   !: transmitted solar radiation under ice   
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   pahu3D , pahv3D
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   rn_amax_2d  !: maximum ice concentration 2d array
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   rn_amax_2d     !: maximum ice concentration 2d array
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ftr_ice        !: transmitted solar radiation under ice
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   pahu3D, pahv3D !: ice hor. eddy diffusivity coef. at U- and V-points
 
    !!--------------------------------------------------------------------------
@@ -310,35 +369,38 @@
    !!--------------------------------------------------------------------------
    !! Variables defined for each ice category
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ht_i    !: Ice thickness (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   a_i     !: Ice fractional areas (concentration)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   v_i     !: Ice volume per unit area (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   v_s     !: Snow volume per unit area(m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ht_s    !: Snow thickness (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   t_su    !: Sea-Ice Surface Temperature (K)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   sm_i    !: Sea-Ice Bulk salinity (ppt)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   smv_i   !: Sea-Ice Bulk salinity times volume per area (ppt.m)
-   !                                                                  !  this is an extensive variable that has to be transported
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   o_i     !: Sea-Ice Age (days)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ov_i    !: Sea-Ice Age times volume per area (days.m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   oa_i    !: Sea-Ice Age times ice area (days)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ht_i      !: Ice thickness (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   a_i       !: Ice fractional areas (concentration)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   v_i       !: Ice volume per unit area (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   v_s       !: Snow volume per unit area(m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ht_s      !: Snow thickness (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   t_su      !: Sea-Ice Surface Temperature (K)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   sm_i      !: Sea-Ice Bulk salinity (ppt)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   smv_i     !: Sea-Ice Bulk salinity times volume per area (ppt.m)
+   !                                                                    !  this is an extensive variable that has to be transported
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   o_i       !: Sea-Ice Age (days)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   oa_i      !: Sea-Ice Age times ice area (days)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   bv_i      !: brine volume
 
    !! Variables summed over all categories, or associated to all the ice in a single grid cell
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   u_ice, v_ice   !: components of the ice velocity (m/s)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tio_u, tio_v   !: components of the ice-ocean stress (N/m2)
-   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(:,:) ::   at_i           !: ice total fractional area (ice concentration)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ato_i          !: =1-at_i ; total open water fractional area
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   et_i , et_s    !: ice and snow total heat content
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ot_i           !: mean age over all categories
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tm_i           !: mean ice temperature over all categories
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bv_i           !: brine volume averaged over all categories
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   smt_i          !: mean sea ice salinity averaged over all categories [PSU]
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   t_s        !: Snow temperatures [K]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_s        !: Snow ...      
+   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(:,:) ::   at_i         !: ice total fractional area (ice concentration)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ato_i        !: =1-at_i ; total open water fractional area
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   et_i , et_s  !: ice and snow total heat content
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tm_i         !: mean ice temperature over all categories
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bvm_i        !: brine volume averaged over all categories
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   smt_i        !: mean sea ice salinity averaged over all categories [PSU]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tm_su        !: mean surface temperature over all categories
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   htm_i        !: mean ice  thickness over all categories
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   htm_s        !: mean snow thickness over all categories
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   om_i         !: mean ice age over all categories
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tau_icebfr   !: ice friction with bathy (landfast param activated)
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   t_s      !: Snow temperatures [K]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_s      !: Snow ...      
       
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   t_i        !: ice temperatures          [K]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_i        !: ice thermal contents    [J/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   s_i        !: ice salinities          [PSU]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   t_i      !: ice temperatures          [K]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_i      !: ice thermal contents    [J/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   s_i      !: ice salinities          [PSU]
 
    !!--------------------------------------------------------------------------
@@ -362,4 +424,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_i_b                      !: ice temperatures
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   u_ice_b, v_ice_b           !: ice velocity
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   at_i_b                     !: ice concentration (total)
             
    !!--------------------------------------------------------------------------
@@ -368,31 +431,11 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   hi_max         !: Boundary of ice thickness categories in thickness space
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   hi_mean        !: Mean ice thickness in catgories 
-
-   !!--------------------------------------------------------------------------
-   !! * Ice Run
-   !!--------------------------------------------------------------------------
-   !                                                  !!: ** Namelist namicerun read in sbc_lim_init **
-   INTEGER           , PUBLIC ::   jpl             !: number of ice  categories 
-   INTEGER           , PUBLIC ::   nlay_i          !: number of ice  layers 
-   INTEGER           , PUBLIC ::   nlay_s          !: number of snow layers 
-   CHARACTER(len=32) , PUBLIC ::   cn_icerst_in    !: suffix of ice restart name (input)
-   CHARACTER(len=256), PUBLIC ::   cn_icerst_indir !: ice restart input directory
-   CHARACTER(len=32) , PUBLIC ::   cn_icerst_out   !: suffix of ice restart name (output)
-   CHARACTER(len=256), PUBLIC ::   cn_icerst_outdir!: ice restart output directory
-   LOGICAL           , PUBLIC ::   ln_limdyn       !: flag for ice dynamics (T) or not (F)
-   LOGICAL           , PUBLIC ::   ln_icectl       !: flag for sea-ice points output (T) or not (F)
-   REAL(wp)          , PUBLIC ::   rn_amax_n       !: maximum ice concentration Northern hemisphere
-   REAL(wp)          , PUBLIC ::   rn_amax_s       !: maximum ice concentration Southern hemisphere
-   INTEGER           , PUBLIC ::   iiceprt         !: debug i-point
-   INTEGER           , PUBLIC ::   jiceprt         !: debug j-point
    !
    !!--------------------------------------------------------------------------
    !! * Ice diagnostics
    !!--------------------------------------------------------------------------
-   ! Increment of global variables
    ! thd refers to changes induced by thermodynamics
    ! trp   ''         ''     ''       advection (transport of ice)
-   LOGICAL , PUBLIC                                        ::   ln_limdiahsb  !: flag for ice diag (T) or not (F)
-   LOGICAL , PUBLIC                                        ::   ln_limdiaout  !: flag for ice diag (T) or not (F)
+   !
    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
@@ -419,5 +462,5 @@
       INTEGER :: ice_alloc
       !
-      INTEGER :: ierr(17), ii
+      INTEGER :: ierr(15), ii
       !!-----------------------------------------------------------------
 
@@ -427,39 +470,37 @@
       ! stay within Fortran's max-line length limit.
       ii = 1
-      ALLOCATE( u_oce    (jpi,jpj) , v_oce    (jpi,jpj) ,                           &
-         &      ahiu     (jpi,jpj) , ahiv     (jpi,jpj) ,                           &
-         &      ust2s    (jpi,jpj) , hicol    (jpi,jpj) ,                           &
-         &      strp1    (jpi,jpj) , strp2    (jpi,jpj) , strength  (jpi,jpj) ,     &
-         &      stress1_i(jpi,jpj) , stress2_i(jpi,jpj) , stress12_i(jpi,jpj) ,     &
-         &      delta_i  (jpi,jpj) , divu_i   (jpi,jpj) , shear_i   (jpi,jpj) , STAT=ierr(ii) )
-
-      ii = ii + 1
-      ALLOCATE( sist   (jpi,jpj) , icethi (jpi,jpj) , t_bo   (jpi,jpj) ,                        &
-         &      frld   (jpi,jpj) , pfrld  (jpi,jpj) , phicif (jpi,jpj) ,                        &
-         &      wfx_snw(jpi,jpj) , wfx_ice(jpi,jpj) , wfx_sub(jpi,jpj) ,                        &
+      ALLOCATE( u_oce   (jpi,jpj) , v_oce    (jpi,jpj) ,                                             &
+         &      ahiu    (jpi,jpj) , ahiv     (jpi,jpj) , hicol    (jpi,jpj) ,                        &
+         &      strength(jpi,jpj) , stress1_i(jpi,jpj) , stress2_i(jpi,jpj) , stress12_i(jpi,jpj) ,  &
+         &      delta_i (jpi,jpj) , divu_i   (jpi,jpj) , shear_i  (jpi,jpj) , STAT=ierr(ii) )
+
+      ii = ii + 1
+      ALLOCATE( t_bo   (jpi,jpj) , frld   (jpi,jpj) , pfrld  (jpi,jpj) , phicif (jpi,jpj) ,     &
+         &      wfx_snw(jpi,jpj) , wfx_ice(jpi,jpj) , wfx_sub(jpi,jpj) , wfx_lam(jpi,jpj) ,     &
          &      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) , afx_thd(jpi,jpj),  afx_dyn(jpi,jpj) ,                        &
-         &      fhtur  (jpi,jpj) , ftr_ice(jpi,jpj,jpl), pahu3D(jpi,jpj,jpl+1), pahv3D(jpi,jpj,jpl+1),            &
-         &      rn_amax_2d (jpi,jpj) , qlead  (jpi,jpj) ,                                                         &
-         &      sfx_res(jpi,jpj) , sfx_bri(jpi,jpj) , sfx_dyn(jpi,jpj) , sfx_sub(jpi,jpj),                        &
-         &      sfx_bog(jpi,jpj) , sfx_bom(jpi,jpj) , sfx_sum(jpi,jpj) , sfx_sni(jpi,jpj) , sfx_opw(jpi,jpj) ,    &
+         &      afx_tot(jpi,jpj) , afx_thd(jpi,jpj),  afx_dyn(jpi,jpj) , rn_amax_2d(jpi,jpj),   &
+         &      fhtur  (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) ,  &
+         &      sfx_bog(jpi,jpj) , sfx_bom(jpi,jpj) , sfx_sum(jpi,jpj) , sfx_sni(jpi,jpj) , sfx_opw(jpi,jpj) ,  &
          &      hfx_res(jpi,jpj) , hfx_snw(jpi,jpj) , hfx_sub(jpi,jpj) , hfx_err(jpi,jpj) ,     & 
-         &      hfx_err_dif(jpi,jpj) , hfx_err_rem(jpi,jpj) , wfx_err_sub(jpi,jpj) ,       &
-         &      hfx_in (jpi,jpj) , hfx_out(jpi,jpj) , fhld(jpi,jpj) ,                           &
-         &      hfx_sum(jpi,jpj) , hfx_bom(jpi,jpj) , hfx_bog(jpi,jpj) , hfx_dif(jpi,jpj) , hfx_opw(jpi,jpj) ,    &
-         &      hfx_thd(jpi,jpj) , hfx_dyn(jpi,jpj) , hfx_spr(jpi,jpj) ,  STAT=ierr(ii) )
+         &      hfx_in (jpi,jpj) , hfx_out(jpi,jpj) , fhld   (jpi,jpj) ,                        &
+         &      hfx_sum(jpi,jpj) , hfx_bom(jpi,jpj) , hfx_bog(jpi,jpj) , hfx_dif(jpi,jpj) ,     &
+         &      hfx_opw(jpi,jpj) , hfx_thd(jpi,jpj) , hfx_dyn(jpi,jpj) , hfx_spr(jpi,jpj) ,     &
+         &      hfx_err_dif(jpi,jpj) , hfx_err_rem(jpi,jpj) , wfx_err_sub(jpi,jpj)        ,  STAT=ierr(ii) )
 
       ! * Ice global state variables
       ii = ii + 1
-      ALLOCATE( ht_i (jpi,jpj,jpl) , a_i  (jpi,jpj,jpl) , v_i  (jpi,jpj,jpl) ,     &
-         &      v_s  (jpi,jpj,jpl) , ht_s (jpi,jpj,jpl) , t_su (jpi,jpj,jpl) ,     &
-         &      sm_i (jpi,jpj,jpl) , smv_i(jpi,jpj,jpl) , o_i  (jpi,jpj,jpl) ,     &
-         &      ov_i (jpi,jpj,jpl) , oa_i (jpi,jpj,jpl)                      , STAT=ierr(ii) )
-      ii = ii + 1
-      ALLOCATE( u_ice(jpi,jpj) , v_ice(jpi,jpj) , tio_u(jpi,jpj) , tio_v(jpi,jpj) ,     &
+      ALLOCATE( ftr_ice(jpi,jpj,jpl) , pahu3D(jpi,jpj,jpl+1) , pahv3D(jpi,jpj,jpl+1) , &
+         &      ht_i   (jpi,jpj,jpl) , a_i   (jpi,jpj,jpl) , v_i   (jpi,jpj,jpl) ,     &
+         &      v_s    (jpi,jpj,jpl) , ht_s  (jpi,jpj,jpl) , t_su  (jpi,jpj,jpl) ,     &
+         &      sm_i   (jpi,jpj,jpl) , smv_i (jpi,jpj,jpl) , o_i   (jpi,jpj,jpl) ,     &
+         &      oa_i   (jpi,jpj,jpl) , bv_i  (jpi,jpj,jpl) ,  STAT=ierr(ii) )
+      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) , ot_i (jpi,jpj) , tm_i (jpi,jpj) ,     &
-         &      bv_i (jpi,jpj) , smt_i(jpi,jpj)                                   , STAT=ierr(ii) )
+         &      et_i (jpi,jpj) , et_s (jpi,jpj) , tm_i (jpi,jpj) , bvm_i(jpi,jpj) ,     &
+         &      smt_i(jpi,jpj) , tm_su(jpi,jpj) , htm_i(jpi,jpj) , htm_s(jpi,jpj) ,     &
+         &      om_i (jpi,jpj) , tau_icebfr(jpi,jpj)                              , STAT=ierr(ii) )
       ii = ii + 1
       ALLOCATE( t_s(jpi,jpj,nlay_s,jpl) , e_s(jpi,jpj,nlay_s,jpl) , STAT=ierr(ii) )
@@ -488,5 +529,7 @@
       ALLOCATE( v_s_b  (jpi,jpj,jpl) , v_i_b  (jpi,jpj,jpl) , e_s_b(jpi,jpj,nlay_s,jpl) ,     &
          &      a_i_b  (jpi,jpj,jpl) , smv_i_b(jpi,jpj,jpl) , e_i_b(jpi,jpj,nlay_i,jpl) ,     &
-         &      oa_i_b (jpi,jpj,jpl) , u_ice_b(jpi,jpj)     , v_ice_b(jpi,jpj)          , STAT=ierr(ii) )
+         &      oa_i_b (jpi,jpj,jpl)                                                    , STAT=ierr(ii) )
+      ii = ii + 1
+      ALLOCATE( u_ice_b(jpi,jpj) , v_ice_b(jpi,jpj) , at_i_b(jpi,jpj) , STAT=ierr(ii) )
       
       ! * Ice thickness distribution variables
@@ -496,10 +539,10 @@
       ! * Ice diagnostics
       ii = ii + 1
-      ALLOCATE( diag_trp_vi(jpi,jpj), diag_trp_vs (jpi,jpj), diag_trp_ei(jpi,jpj),   & 
-         &      diag_trp_es(jpi,jpj), diag_trp_smv(jpi,jpj), diag_heat  (jpi,jpj),   &
-         &      diag_smvi  (jpi,jpj), diag_vice   (jpi,jpj), diag_vsnw  (jpi,jpj), STAT=ierr(ii) )
+      ALLOCATE( diag_trp_vi(jpi,jpj) , diag_trp_vs (jpi,jpj) , diag_trp_ei(jpi,jpj),   & 
+         &      diag_trp_es(jpi,jpj) , diag_trp_smv(jpi,jpj) , diag_heat  (jpi,jpj),   &
+         &      diag_smvi  (jpi,jpj) , diag_vice   (jpi,jpj) , diag_vsnw  (jpi,jpj), STAT=ierr(ii) )
 
       ice_alloc = MAXVAL( ierr(:) )
-      IF( ice_alloc /= 0 )   CALL ctl_warn('ice_alloc_2: failed to allocate arrays.')
+      IF( ice_alloc /= 0 )   CALL ctl_warn('ice_alloc: failed to allocate arrays.')
       !
    END FUNCTION ice_alloc
@@ -513,3 +556,2 @@
    !!======================================================================
 END MODULE ice
-
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limadv.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limadv.F90	(revision 7308)
+++ 	(revision )
@@ -1,419 +1,0 @@
-MODULE limadv 
-   !!======================================================================
-   !!                       ***  MODULE limadv   ***
-   !! LIM sea-ice model : sea-ice advection
-   !!======================================================================
-   !! History :  LIM  ! 2008-03 (M. Vancoppenolle)  LIM-3 from LIM-2 code
-   !!            3.2  ! 2009-06 (F. Dupont)  correct a error in the North fold b. c.
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!--------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                     LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_adv_x  : advection of sea ice on x axis
-   !!   lim_adv_y  : advection of sea ice on y axis
-   !!----------------------------------------------------------------------
-   USE dom_oce          ! ocean domain
-   USE dom_ice          ! LIM-3 domain
-   USE ice              ! LIM-3 variables
-   USE lbclnk           ! lateral boundary condition - MPP exchanges
-   USE in_out_manager   ! I/O manager
-   USE prtctl           ! Print control
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE lib_fortran      ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_adv_x   ! called by lim_trp
-   PUBLIC   lim_adv_y   ! called by lim_trp
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_adv_x( pdf, put , pcrh, psm , ps0 ,   &
-      &                  psx, psxx, psy , psyy, psxy )
-      !!---------------------------------------------------------------------
-      !!                **  routine lim_adv_x  **
-      !!  
-      !! ** purpose :   Computes and adds the advection trend to sea-ice
-      !!              variable on i-axis
-      !!
-      !! ** method  :   Uses Prather second order scheme that advects tracers
-      !!              but also theirquadratic forms. The method preserves
-      !!              tracer structures by conserving second order moments.
-      !!
-      !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
-      !!--------------------------------------------------------------------
-      REAL(wp)                    , INTENT(in   ) ::   pdf                ! reduction factor for the time step
-      REAL(wp)                    , INTENT(in   ) ::   pcrh               ! call lim_adv_x then lim_adv_y (=1) or the opposite (=0)
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   put                ! i-direction ice velocity at U-point [m/s]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psm                ! area
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ps0                ! field to be advected
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psx , psy          ! 1st moments 
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psxx, psyy, psxy   ! 2nd moments
-      !! 
-      INTEGER  ::   ji, jj                               ! dummy loop indices
-      REAL(wp) ::   zs1max, zrdt, zslpmax, ztemp         ! local scalars
-      REAL(wp) ::   zs1new, zalf , zalfq , zbt           !   -      -
-      REAL(wp) ::   zs2new, zalf1, zalf1q, zbt1          !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zf0 , zfx  , zfy   , zbet   ! 2D workspace
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zfm , zfxx , zfyy  , zfxy   !  -      -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zalg, zalg1, zalg1q         !  -      -
-      !---------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
-      CALL wrk_alloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
-
-      ! Limitation of moments.                                           
-
-      zrdt = rdt_ice * pdf      ! If ice drift field is too fast, use an appropriate time step for advection.
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zslpmax = MAX( 0._wp, ps0(ji,jj) )
-            zs1max  = 1.5 * zslpmax
-            zs1new  = MIN( zs1max, MAX( -zs1max, psx(ji,jj) ) )
-            zs2new  = MIN(  2.0 * zslpmax - 0.3334 * ABS( zs1new ),      &
-               &            MAX( ABS( zs1new ) - zslpmax, psxx(ji,jj) )  )
-            rswitch = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zslpmax) ) ) * tmask(ji,jj,1)   ! Case of empty boxes & Apply mask
-
-            ps0 (ji,jj) = zslpmax  
-            psx (ji,jj) = zs1new      * rswitch
-            psxx(ji,jj) = zs2new      * rswitch
-            psy (ji,jj) = psy (ji,jj) * rswitch
-            psyy(ji,jj) = psyy(ji,jj) * rswitch
-            psxy(ji,jj) = MIN( zslpmax, MAX( -zslpmax, psxy(ji,jj) ) ) * rswitch
-         END DO
-      END DO
-
-      !  Initialize volumes of boxes  (=area if adv_x first called, =psm otherwise)                                     
-      psm (:,:)  = MAX( pcrh * e1e2t(:,:) + ( 1.0 - pcrh ) * psm(:,:) , epsi20 )
-
-      !  Calculate fluxes and moments between boxes i<-->i+1              
-      DO jj = 1, jpj                      !  Flux from i to i+1 WHEN u GT 0 
-         DO ji = 1, jpi
-            zbet(ji,jj)  =  MAX( 0._wp, SIGN( 1._wp, put(ji,jj) ) )
-            zalf         =  MAX( 0._wp, put(ji,jj) ) * zrdt * e2u(ji,jj) / psm(ji,jj)
-            zalfq        =  zalf * zalf
-            zalf1        =  1.0 - zalf
-            zalf1q       =  zalf1 * zalf1
-            !
-            zfm (ji,jj)  =  zalf  *   psm (ji,jj)
-            zf0 (ji,jj)  =  zalf  * ( ps0 (ji,jj) + zalf1 * ( psx(ji,jj) + (zalf1 - zalf) * psxx(ji,jj) )  )
-            zfx (ji,jj)  =  zalfq * ( psx (ji,jj) + 3.0 * zalf1 * psxx(ji,jj) )
-            zfxx(ji,jj)  =  zalf  *   psxx(ji,jj) * zalfq
-            zfy (ji,jj)  =  zalf  * ( psy (ji,jj) + zalf1 * psxy(ji,jj) )
-            zfxy(ji,jj)  =  zalfq *   psxy(ji,jj)
-            zfyy(ji,jj)  =  zalf  *   psyy(ji,jj)
-
-            !  Readjust moments remaining in the box.
-            psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
-            ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
-            psx (ji,jj)  =  zalf1q * ( psx(ji,jj) - 3.0 * zalf * psxx(ji,jj) )
-            psxx(ji,jj)  =  zalf1  * zalf1q * psxx(ji,jj)
-            psy (ji,jj)  =  psy (ji,jj) - zfy(ji,jj)
-            psyy(ji,jj)  =  psyy(ji,jj) - zfyy(ji,jj)
-            psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
-         END DO
-      END DO
-
-      DO jj = 1, jpjm1                      !  Flux from i+1 to i when u LT 0.
-         DO ji = 1, fs_jpim1
-            zalf          = MAX( 0._wp, -put(ji,jj) ) * zrdt * e2u(ji,jj) / psm(ji+1,jj) 
-            zalg  (ji,jj) = zalf
-            zalfq         = zalf * zalf
-            zalf1         = 1.0 - zalf
-            zalg1 (ji,jj) = zalf1
-            zalf1q        = zalf1 * zalf1
-            zalg1q(ji,jj) = zalf1q
-            !
-            zfm   (ji,jj) = zfm (ji,jj) + zalf  *   psm (ji+1,jj)
-            zf0   (ji,jj) = zf0 (ji,jj) + zalf  * ( ps0 (ji+1,jj) - zalf1 * ( psx(ji+1,jj) - (zalf1 - zalf ) * psxx(ji+1,jj) ) )
-            zfx   (ji,jj) = zfx (ji,jj) + zalfq * ( psx (ji+1,jj) - 3.0 * zalf1 * psxx(ji+1,jj) )
-            zfxx  (ji,jj) = zfxx(ji,jj) + zalf  *   psxx(ji+1,jj) * zalfq
-            zfy   (ji,jj) = zfy (ji,jj) + zalf  * ( psy (ji+1,jj) - zalf1 * psxy(ji+1,jj) )
-            zfxy  (ji,jj) = zfxy(ji,jj) + zalfq *   psxy(ji+1,jj)
-            zfyy  (ji,jj) = zfyy(ji,jj) + zalf  *   psyy(ji+1,jj)
-         END DO
-      END DO
-
-      DO jj = 2, jpjm1                     !  Readjust moments remaining in the box. 
-         DO ji = fs_2, fs_jpim1
-            zbt  =       zbet(ji-1,jj)
-            zbt1 = 1.0 - zbet(ji-1,jj)
-            !
-            psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji-1,jj) )
-            ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji-1,jj) )
-            psx (ji,jj) = zalg1q(ji-1,jj) * ( psx(ji,jj) + 3.0 * zalg(ji-1,jj) * psxx(ji,jj) )
-            psxx(ji,jj) = zalg1 (ji-1,jj) * zalg1q(ji-1,jj) * psxx(ji,jj)
-            psy (ji,jj) = zbt * psy (ji,jj) + zbt1 * ( psy (ji,jj) - zfy (ji-1,jj) )
-            psyy(ji,jj) = zbt * psyy(ji,jj) + zbt1 * ( psyy(ji,jj) - zfyy(ji-1,jj) )
-            psxy(ji,jj) = zalg1q(ji-1,jj) * psxy(ji,jj)
-         END DO
-      END DO
-
-      !   Put the temporary moments into appropriate neighboring boxes.    
-      DO jj = 2, jpjm1                     !   Flux from i to i+1 IF u GT 0.
-         DO ji = fs_2, fs_jpim1
-            zbt  =       zbet(ji-1,jj)
-            zbt1 = 1.0 - zbet(ji-1,jj)
-            psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji-1,jj) ) + zbt1 * psm(ji,jj)
-            zalf        = zbt * zfm(ji-1,jj) / psm(ji,jj)
-            zalf1       = 1.0 - zalf
-            ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji-1,jj)
-            !
-            ps0 (ji,jj) = zbt * ( ps0(ji,jj) + zf0(ji-1,jj) ) + zbt1 * ps0(ji,jj)
-            psx (ji,jj) = zbt * ( zalf * zfx(ji-1,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp ) + zbt1 * psx(ji,jj)
-            psxx(ji,jj) = zbt * ( zalf * zalf * zfxx(ji-1,jj) + zalf1 * zalf1 * psxx(ji,jj)                               &
-               &                + 5.0 * ( zalf * zalf1 * ( psx (ji,jj) - zfx(ji-1,jj) ) - ( zalf1 - zalf ) * ztemp )  )   &
-               &                                                + zbt1 * psxx(ji,jj)
-            psxy(ji,jj) = zbt * ( zalf * zfxy(ji-1,jj) + zalf1 * psxy(ji,jj)             &
-               &                + 3.0 * (- zalf1*zfy(ji-1,jj)  + zalf * psy(ji,jj) ) )   &
-               &                                                + zbt1 * psxy(ji,jj)
-            psy (ji,jj) = zbt * ( psy (ji,jj) + zfy (ji-1,jj) ) + zbt1 * psy (ji,jj)
-            psyy(ji,jj) = zbt * ( psyy(ji,jj) + zfyy(ji-1,jj) ) + zbt1 * psyy(ji,jj)
-         END DO
-      END DO
-
-      DO jj = 2, jpjm1                     !  Flux from i+1 to i IF u LT 0.
-         DO ji = fs_2, fs_jpim1
-            zbt  =       zbet(ji,jj)
-            zbt1 = 1.0 - zbet(ji,jj)
-            psm(ji,jj)  = zbt * psm(ji,jj)  + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
-            zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
-            zalf1       = 1.0 - zalf
-            ztemp       = - zalf * ps0(ji,jj) + zalf1 * zf0(ji,jj)
-            !
-            ps0(ji,jj)  = zbt * ps0 (ji,jj) + zbt1 * ( ps0(ji,jj) + zf0(ji,jj) )
-            psx(ji,jj)  = zbt * psx (ji,jj) + zbt1 * ( zalf * zfx(ji,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp )
-            psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( zalf * zalf * zfxx(ji,jj)  + zalf1 * zalf1 * psxx(ji,jj)  &
-               &                                      + 5.0 *( zalf * zalf1 * ( - psx(ji,jj) + zfx(ji,jj) )      &
-               &                                      + ( zalf1 - zalf ) * ztemp ) )
-            psxy(ji,jj) = zbt * psxy(ji,jj) + zbt1 * (  zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)  &
-               &                                      + 3.0 * ( zalf1 * zfy(ji,jj) - zalf * psy(ji,jj) )  )
-            psy(ji,jj)  = zbt * psy (ji,jj)  + zbt1 * ( psy (ji,jj) + zfy (ji,jj) )
-            psyy(ji,jj) = zbt * psyy(ji,jj)  + zbt1 * ( psyy(ji,jj) + zfyy(ji,jj) )
-         END DO
-      END DO
-
-      !-- Lateral boundary conditions
-      CALL lbc_lnk_multi( psm , 'T',  1., ps0 , 'T',  1.   &
-         &              , psx , 'T', -1., psy , 'T', -1.   &   ! caution gradient ==> the sign changes
-         &              , psxx, 'T',  1., psyy, 'T',  1.   &
-         &              , psxy, 'T',  1. )
-
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab2d_1=psm  , clinfo1=' lim_adv_x: psm  :', tab2d_2=ps0 , clinfo2=' ps0  : ')
-         CALL prt_ctl(tab2d_1=psx  , clinfo1=' lim_adv_x: psx  :', tab2d_2=psxx, clinfo2=' psxx : ')
-         CALL prt_ctl(tab2d_1=psy  , clinfo1=' lim_adv_x: psy  :', tab2d_2=psyy, clinfo2=' psyy : ')
-         CALL prt_ctl(tab2d_1=psxy , clinfo1=' lim_adv_x: psxy :')
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
-      CALL wrk_dealloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
-      !
-   END SUBROUTINE lim_adv_x
-
-
-   SUBROUTINE lim_adv_y( pdf, pvt , pcrh, psm , ps0 ,   &
-      &                  psx, psxx, psy , psyy, psxy )
-      !!---------------------------------------------------------------------
-      !!                **  routine lim_adv_y  **
-      !!            
-      !! ** purpose :   Computes and adds the advection trend to sea-ice 
-      !!              variable on y axis
-      !!
-      !! ** method  :   Uses Prather second order scheme that advects tracers
-      !!              but also their quadratic forms. The method preserves 
-      !!              tracer structures by conserving second order moments.
-      !! 
-      !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
-      !!---------------------------------------------------------------------
-      REAL(wp)                    , INTENT(in   ) ::   pdf                ! reduction factor for the time step
-      REAL(wp)                    , INTENT(in   ) ::   pcrh               ! call lim_adv_x then lim_adv_y (=1) or the opposite (=0)
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pvt                ! j-direction ice velocity at V-point [m/s]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psm                ! area
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ps0                ! field to be advected
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psx , psy          ! 1st moments 
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psxx, psyy, psxy   ! 2nd moments
-      !!
-      INTEGER  ::   ji, jj                               ! dummy loop indices
-      REAL(wp) ::   zs1max, zrdt, zslpmax, ztemp         ! temporary scalars
-      REAL(wp) ::   zs1new, zalf , zalfq , zbt           !    -         -
-      REAL(wp) ::   zs2new, zalf1, zalf1q, zbt1          !    -         -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zf0, zfx , zfy , zbet   ! 2D workspace
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zfm, zfxx, zfyy, zfxy   !  -      -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zalg, zalg1, zalg1q     !  -      -
-      !---------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
-      CALL wrk_alloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
-
-      ! Limitation of moments.
-
-      zrdt = rdt_ice * pdf ! If ice drift field is too fast, use an appropriate time step for advection.
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zslpmax = MAX( 0._wp, ps0(ji,jj) )
-            zs1max  = 1.5 * zslpmax
-            zs1new  = MIN( zs1max, MAX( -zs1max, psy(ji,jj) ) )
-            zs2new  = MIN(  ( 2.0 * zslpmax - 0.3334 * ABS( zs1new ) ),   &
-               &             MAX( ABS( zs1new )-zslpmax, psyy(ji,jj) )  )
-            rswitch = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zslpmax) ) ) * tmask(ji,jj,1)   ! Case of empty boxes & Apply mask
-            !
-            ps0 (ji,jj) = zslpmax  
-            psx (ji,jj) = psx (ji,jj) * rswitch
-            psxx(ji,jj) = psxx(ji,jj) * rswitch
-            psy (ji,jj) = zs1new * rswitch
-            psyy(ji,jj) = zs2new * rswitch
-            psxy(ji,jj) = MIN( zslpmax, MAX( -zslpmax, psxy(ji,jj) ) ) * rswitch
-         END DO
-      END DO
-
-      !  Initialize volumes of boxes (=area if adv_x first called, =psm otherwise)
-      psm(:,:)  = MAX(  pcrh * e1e2t(:,:) + ( 1.0 - pcrh ) * psm(:,:) , epsi20  )
-
-      !  Calculate fluxes and moments between boxes j<-->j+1              
-      DO jj = 1, jpj                     !  Flux from j to j+1 WHEN v GT 0   
-         DO ji = 1, jpi
-            zbet(ji,jj)  =  MAX( 0._wp, SIGN( 1._wp, pvt(ji,jj) ) )
-            zalf         =  MAX( 0._wp, pvt(ji,jj) ) * zrdt * e1v(ji,jj) / psm(ji,jj)
-            zalfq        =  zalf * zalf
-            zalf1        =  1.0 - zalf
-            zalf1q       =  zalf1 * zalf1
-            !
-            zfm (ji,jj)  =  zalf  * psm(ji,jj)
-            zf0 (ji,jj)  =  zalf  * ( ps0(ji,jj) + zalf1 * ( psy(ji,jj)  + (zalf1-zalf) * psyy(ji,jj)  ) ) 
-            zfy (ji,jj)  =  zalfq *( psy(ji,jj) + 3.0*zalf1*psyy(ji,jj) )
-            zfyy(ji,jj)  =  zalf  * zalfq * psyy(ji,jj)
-            zfx (ji,jj)  =  zalf  * ( psx(ji,jj) + zalf1 * psxy(ji,jj) )
-            zfxy(ji,jj)  =  zalfq * psxy(ji,jj)
-            zfxx(ji,jj)  =  zalf  * psxx(ji,jj)
-            !
-            !  Readjust moments remaining in the box.
-            psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
-            ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
-            psy (ji,jj)  =  zalf1q * ( psy(ji,jj) -3.0 * zalf * psyy(ji,jj) )
-            psyy(ji,jj)  =  zalf1 * zalf1q * psyy(ji,jj)
-            psx (ji,jj)  =  psx (ji,jj) - zfx(ji,jj)
-            psxx(ji,jj)  =  psxx(ji,jj) - zfxx(ji,jj)
-            psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
-         END DO
-      END DO
-      !
-      DO jj = 1, jpjm1                   !  Flux from j+1 to j when v LT 0.
-         DO ji = 1, jpi
-            zalf          = ( MAX(0._wp, -pvt(ji,jj) ) * zrdt * e1v(ji,jj) ) / psm(ji,jj+1) 
-            zalg  (ji,jj) = zalf
-            zalfq         = zalf * zalf
-            zalf1         = 1.0 - zalf
-            zalg1 (ji,jj) = zalf1
-            zalf1q        = zalf1 * zalf1
-            zalg1q(ji,jj) = zalf1q
-            !
-            zfm   (ji,jj) = zfm (ji,jj) + zalf  *   psm (ji,jj+1)
-            zf0   (ji,jj) = zf0 (ji,jj) + zalf  * ( ps0 (ji,jj+1) - zalf1 * (psy(ji,jj+1) - (zalf1 - zalf ) * psyy(ji,jj+1) ) )
-            zfy   (ji,jj) = zfy (ji,jj) + zalfq * ( psy (ji,jj+1) - 3.0 * zalf1 * psyy(ji,jj+1) )
-            zfyy  (ji,jj) = zfyy(ji,jj) + zalf  *   psyy(ji,jj+1) * zalfq
-            zfx   (ji,jj) = zfx (ji,jj) + zalf  * ( psx (ji,jj+1) - zalf1 * psxy(ji,jj+1) )
-            zfxy  (ji,jj) = zfxy(ji,jj) + zalfq *   psxy(ji,jj+1)
-            zfxx  (ji,jj) = zfxx(ji,jj) + zalf  *   psxx(ji,jj+1)
-         END DO
-      END DO
-
-      !  Readjust moments remaining in the box. 
-      DO jj = 2, jpj
-         DO ji = 1, jpi
-            zbt  =         zbet(ji,jj-1)
-            zbt1 = ( 1.0 - zbet(ji,jj-1) )
-            !
-            psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji,jj-1) )
-            ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji,jj-1) )
-            psy (ji,jj) = zalg1q(ji,jj-1) * ( psy(ji,jj) + 3.0 * zalg(ji,jj-1) * psyy(ji,jj) )
-            psyy(ji,jj) = zalg1 (ji,jj-1) * zalg1q(ji,jj-1) * psyy(ji,jj)
-            psx (ji,jj) = zbt * psx (ji,jj) + zbt1 * ( psx (ji,jj) - zfx (ji,jj-1) )
-            psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) - zfxx(ji,jj-1) )
-            psxy(ji,jj) = zalg1q(ji,jj-1) * psxy(ji,jj)
-         END DO
-      END DO
-
-      !   Put the temporary moments into appropriate neighboring boxes.    
-      DO jj = 2, jpjm1                    !   Flux from j to j+1 IF v GT 0.
-         DO ji = 1, jpi
-            zbt  =         zbet(ji,jj-1)
-            zbt1 = ( 1.0 - zbet(ji,jj-1) )
-            psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji,jj-1) ) + zbt1 * psm(ji,jj) 
-            zalf        = zbt * zfm(ji,jj-1) / psm(ji,jj) 
-            zalf1       = 1.0 - zalf
-            ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji,jj-1)
-            !
-            ps0(ji,jj)  = zbt  * ( ps0(ji,jj) + zf0(ji,jj-1) ) + zbt1 * ps0(ji,jj)
-            psy(ji,jj)  = zbt  * ( zalf * zfy(ji,jj-1) + zalf1 * psy(ji,jj) + 3.0 * ztemp )   &
-               &                                               + zbt1 * psy(ji,jj)  
-            psyy(ji,jj) = zbt  * ( zalf * zalf * zfyy(ji,jj-1) + zalf1 * zalf1 * psyy(ji,jj)                             &
-               &                 + 5.0 * ( zalf * zalf1 * ( psy(ji,jj) - zfy(ji,jj-1) ) - ( zalf1 - zalf ) * ztemp ) )   & 
-               &                                               + zbt1 * psyy(ji,jj)
-            psxy(ji,jj) = zbt  * (  zalf * zfxy(ji,jj-1) + zalf1 * psxy(ji,jj)               &
-               &                  + 3.0 * (- zalf1 * zfx(ji,jj-1) + zalf * psx(ji,jj) )  )   &
-               &                                                + zbt1 * psxy(ji,jj)
-            psx (ji,jj) = zbt * ( psx (ji,jj) + zfx (ji,jj-1) ) + zbt1 * psx (ji,jj)
-            psxx(ji,jj) = zbt * ( psxx(ji,jj) + zfxx(ji,jj-1) ) + zbt1 * psxx(ji,jj)
-         END DO
-      END DO
-
-      DO jj = 2, jpjm1                   !  Flux from j+1 to j IF v LT 0.
-         DO ji = 1, jpi
-            zbt  =         zbet(ji,jj)
-            zbt1 = ( 1.0 - zbet(ji,jj) )
-            psm(ji,jj)  = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
-            zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
-            zalf1       = 1.0 - zalf
-            ztemp       = - zalf * ps0 (ji,jj) + zalf1 * zf0(ji,jj)
-            ps0 (ji,jj) =   zbt  * ps0 (ji,jj) + zbt1  * ( ps0(ji,jj) + zf0(ji,jj) )
-            psy (ji,jj) =   zbt  * psy (ji,jj) + zbt1  * ( zalf * zfy(ji,jj) + zalf1 * psy(ji,jj) + 3.0 * ztemp )
-            psyy(ji,jj) =   zbt  * psyy(ji,jj) + zbt1 * (  zalf * zalf * zfyy(ji,jj) + zalf1 * zalf1 * psyy(ji,jj)   &
-               &                                         + 5.0 *( zalf *zalf1 *( -psy(ji,jj) + zfy(ji,jj) )          &
-               &                                         + ( zalf1 - zalf ) * ztemp )                                )
-            psxy(ji,jj) =   zbt  * psxy(ji,jj) + zbt1 * (  zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)       &
-               &                                         + 3.0 * ( zalf1 * zfx(ji,jj) - zalf * psx(ji,jj) )  )
-            psx (ji,jj) =   zbt  * psx (ji,jj) + zbt1 * ( psx (ji,jj) + zfx (ji,jj) )
-            psxx(ji,jj) =   zbt  * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) + zfxx(ji,jj) )
-         END DO
-      END DO
-
-      !-- Lateral boundary conditions
-      CALL lbc_lnk_multi( psm , 'T',  1.,  ps0 , 'T',  1.   &
-         &              , psx , 'T', -1.,  psy , 'T', -1.   &   ! caution gradient ==> the sign changes
-         &              , psxx, 'T',  1.,  psyy, 'T',  1.   &
-         &              , psxy, 'T',  1. )
-
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab2d_1=psm  , clinfo1=' lim_adv_y: psm  :', tab2d_2=ps0 , clinfo2=' ps0  : ')
-         CALL prt_ctl(tab2d_1=psx  , clinfo1=' lim_adv_y: psx  :', tab2d_2=psxx, clinfo2=' psxx : ')
-         CALL prt_ctl(tab2d_1=psy  , clinfo1=' lim_adv_y: psy  :', tab2d_2=psyy, clinfo2=' psyy : ')
-         CALL prt_ctl(tab2d_1=psxy , clinfo1=' lim_adv_y: psxy :')
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
-      CALL wrk_dealloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
-      !
-   END SUBROUTINE lim_adv_y
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option            Dummy module         NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-
-   !!======================================================================
-END MODULE limadv
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limadv_prather.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limadv_prather.F90	(revision 7309)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limadv_prather.F90	(revision 7309)
@@ -0,0 +1,418 @@
+MODULE limadv_prather 
+   !!======================================================================
+   !!                       ***  MODULE limadv_prather   ***
+   !! LIM sea-ice model : sea-ice advection => Prather scheme
+   !!======================================================================
+   !! History :  LIM  ! 2008-03 (M. Vancoppenolle)  LIM-3 from LIM-2 code
+   !!            3.2  ! 2009-06 (F. Dupont)  correct a error in the North fold b. c.
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!--------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                     LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_adv_x  : advection of sea ice on x axis
+   !!   lim_adv_y  : advection of sea ice on y axis
+   !!----------------------------------------------------------------------
+   USE dom_oce          ! ocean domain
+   USE ice              ! LIM-3 variables
+   USE lbclnk           ! lateral boundary condition - MPP exchanges
+   USE in_out_manager   ! I/O manager
+   USE prtctl           ! Print control
+   USE lib_mpp          ! MPP library
+   USE wrk_nemo         ! work arrays
+   USE lib_fortran      ! to use key_nosignedzero
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   lim_adv_x   ! called by lim_trp
+   PUBLIC   lim_adv_y   ! called by lim_trp
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! $Id: limadv.F90 6746 2016-06-27 17:20:57Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE lim_adv_x( pdf, put , pcrh, psm , ps0 ,   &
+      &                  psx, psxx, psy , psyy, psxy )
+      !!---------------------------------------------------------------------
+      !!                **  routine lim_adv_x  **
+      !!  
+      !! ** purpose :   Computes and adds the advection trend to sea-ice
+      !!              variable on i-axis
+      !!
+      !! ** method  :   Uses Prather second order scheme that advects tracers
+      !!              but also theirquadratic forms. The method preserves
+      !!              tracer structures by conserving second order moments.
+      !!
+      !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
+      !!--------------------------------------------------------------------
+      REAL(wp)                    , INTENT(in   ) ::   pdf                ! reduction factor for the time step
+      REAL(wp)                    , INTENT(in   ) ::   pcrh               ! call lim_adv_x then lim_adv_y (=1) or the opposite (=0)
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   put                ! i-direction ice velocity at U-point [m/s]
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psm                ! area
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ps0                ! field to be advected
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psx , psy          ! 1st moments 
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psxx, psyy, psxy   ! 2nd moments
+      !! 
+      INTEGER  ::   ji, jj                               ! dummy loop indices
+      REAL(wp) ::   zs1max, zrdt, zslpmax, ztemp         ! local scalars
+      REAL(wp) ::   zs1new, zalf , zalfq , zbt           !   -      -
+      REAL(wp) ::   zs2new, zalf1, zalf1q, zbt1          !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zf0 , zfx  , zfy   , zbet   ! 2D workspace
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zfm , zfxx , zfyy  , zfxy   !  -      -
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zalg, zalg1, zalg1q         !  -      -
+      !---------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
+      CALL wrk_alloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
+
+      ! Limitation of moments.                                           
+
+      zrdt = rdt_ice * pdf      ! If ice drift field is too fast, use an appropriate time step for advection.
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zslpmax = MAX( 0._wp, ps0(ji,jj) )
+            zs1max  = 1.5 * zslpmax
+            zs1new  = MIN( zs1max, MAX( -zs1max, psx(ji,jj) ) )
+            zs2new  = MIN(  2.0 * zslpmax - 0.3334 * ABS( zs1new ),      &
+               &            MAX( ABS( zs1new ) - zslpmax, psxx(ji,jj) )  )
+            rswitch = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zslpmax) ) ) * tmask(ji,jj,1)   ! Case of empty boxes & Apply mask
+
+            ps0 (ji,jj) = zslpmax  
+            psx (ji,jj) = zs1new      * rswitch
+            psxx(ji,jj) = zs2new      * rswitch
+            psy (ji,jj) = psy (ji,jj) * rswitch
+            psyy(ji,jj) = psyy(ji,jj) * rswitch
+            psxy(ji,jj) = MIN( zslpmax, MAX( -zslpmax, psxy(ji,jj) ) ) * rswitch
+         END DO
+      END DO
+
+      !  Initialize volumes of boxes  (=area if adv_x first called, =psm otherwise)                                     
+      psm (:,:)  = MAX( pcrh * e1e2t(:,:) + ( 1.0 - pcrh ) * psm(:,:) , epsi20 )
+
+      !  Calculate fluxes and moments between boxes i<-->i+1              
+      DO jj = 1, jpj                      !  Flux from i to i+1 WHEN u GT 0 
+         DO ji = 1, jpi
+            zbet(ji,jj)  =  MAX( 0._wp, SIGN( 1._wp, put(ji,jj) ) )
+            zalf         =  MAX( 0._wp, put(ji,jj) ) * zrdt * e2u(ji,jj) / psm(ji,jj)
+            zalfq        =  zalf * zalf
+            zalf1        =  1.0 - zalf
+            zalf1q       =  zalf1 * zalf1
+            !
+            zfm (ji,jj)  =  zalf  *   psm (ji,jj)
+            zf0 (ji,jj)  =  zalf  * ( ps0 (ji,jj) + zalf1 * ( psx(ji,jj) + (zalf1 - zalf) * psxx(ji,jj) )  )
+            zfx (ji,jj)  =  zalfq * ( psx (ji,jj) + 3.0 * zalf1 * psxx(ji,jj) )
+            zfxx(ji,jj)  =  zalf  *   psxx(ji,jj) * zalfq
+            zfy (ji,jj)  =  zalf  * ( psy (ji,jj) + zalf1 * psxy(ji,jj) )
+            zfxy(ji,jj)  =  zalfq *   psxy(ji,jj)
+            zfyy(ji,jj)  =  zalf  *   psyy(ji,jj)
+
+            !  Readjust moments remaining in the box.
+            psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
+            ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
+            psx (ji,jj)  =  zalf1q * ( psx(ji,jj) - 3.0 * zalf * psxx(ji,jj) )
+            psxx(ji,jj)  =  zalf1  * zalf1q * psxx(ji,jj)
+            psy (ji,jj)  =  psy (ji,jj) - zfy(ji,jj)
+            psyy(ji,jj)  =  psyy(ji,jj) - zfyy(ji,jj)
+            psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
+         END DO
+      END DO
+
+      DO jj = 1, jpjm1                      !  Flux from i+1 to i when u LT 0.
+         DO ji = 1, fs_jpim1
+            zalf          = MAX( 0._wp, -put(ji,jj) ) * zrdt * e2u(ji,jj) / psm(ji+1,jj) 
+            zalg  (ji,jj) = zalf
+            zalfq         = zalf * zalf
+            zalf1         = 1.0 - zalf
+            zalg1 (ji,jj) = zalf1
+            zalf1q        = zalf1 * zalf1
+            zalg1q(ji,jj) = zalf1q
+            !
+            zfm   (ji,jj) = zfm (ji,jj) + zalf  *   psm (ji+1,jj)
+            zf0   (ji,jj) = zf0 (ji,jj) + zalf  * ( ps0 (ji+1,jj) - zalf1 * ( psx(ji+1,jj) - (zalf1 - zalf ) * psxx(ji+1,jj) ) )
+            zfx   (ji,jj) = zfx (ji,jj) + zalfq * ( psx (ji+1,jj) - 3.0 * zalf1 * psxx(ji+1,jj) )
+            zfxx  (ji,jj) = zfxx(ji,jj) + zalf  *   psxx(ji+1,jj) * zalfq
+            zfy   (ji,jj) = zfy (ji,jj) + zalf  * ( psy (ji+1,jj) - zalf1 * psxy(ji+1,jj) )
+            zfxy  (ji,jj) = zfxy(ji,jj) + zalfq *   psxy(ji+1,jj)
+            zfyy  (ji,jj) = zfyy(ji,jj) + zalf  *   psyy(ji+1,jj)
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1                     !  Readjust moments remaining in the box. 
+         DO ji = fs_2, fs_jpim1
+            zbt  =       zbet(ji-1,jj)
+            zbt1 = 1.0 - zbet(ji-1,jj)
+            !
+            psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji-1,jj) )
+            ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji-1,jj) )
+            psx (ji,jj) = zalg1q(ji-1,jj) * ( psx(ji,jj) + 3.0 * zalg(ji-1,jj) * psxx(ji,jj) )
+            psxx(ji,jj) = zalg1 (ji-1,jj) * zalg1q(ji-1,jj) * psxx(ji,jj)
+            psy (ji,jj) = zbt * psy (ji,jj) + zbt1 * ( psy (ji,jj) - zfy (ji-1,jj) )
+            psyy(ji,jj) = zbt * psyy(ji,jj) + zbt1 * ( psyy(ji,jj) - zfyy(ji-1,jj) )
+            psxy(ji,jj) = zalg1q(ji-1,jj) * psxy(ji,jj)
+         END DO
+      END DO
+
+      !   Put the temporary moments into appropriate neighboring boxes.    
+      DO jj = 2, jpjm1                     !   Flux from i to i+1 IF u GT 0.
+         DO ji = fs_2, fs_jpim1
+            zbt  =       zbet(ji-1,jj)
+            zbt1 = 1.0 - zbet(ji-1,jj)
+            psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji-1,jj) ) + zbt1 * psm(ji,jj)
+            zalf        = zbt * zfm(ji-1,jj) / psm(ji,jj)
+            zalf1       = 1.0 - zalf
+            ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji-1,jj)
+            !
+            ps0 (ji,jj) = zbt * ( ps0(ji,jj) + zf0(ji-1,jj) ) + zbt1 * ps0(ji,jj)
+            psx (ji,jj) = zbt * ( zalf * zfx(ji-1,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp ) + zbt1 * psx(ji,jj)
+            psxx(ji,jj) = zbt * ( zalf * zalf * zfxx(ji-1,jj) + zalf1 * zalf1 * psxx(ji,jj)                               &
+               &                + 5.0 * ( zalf * zalf1 * ( psx (ji,jj) - zfx(ji-1,jj) ) - ( zalf1 - zalf ) * ztemp )  )   &
+               &                                                + zbt1 * psxx(ji,jj)
+            psxy(ji,jj) = zbt * ( zalf * zfxy(ji-1,jj) + zalf1 * psxy(ji,jj)             &
+               &                + 3.0 * (- zalf1*zfy(ji-1,jj)  + zalf * psy(ji,jj) ) )   &
+               &                                                + zbt1 * psxy(ji,jj)
+            psy (ji,jj) = zbt * ( psy (ji,jj) + zfy (ji-1,jj) ) + zbt1 * psy (ji,jj)
+            psyy(ji,jj) = zbt * ( psyy(ji,jj) + zfyy(ji-1,jj) ) + zbt1 * psyy(ji,jj)
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1                     !  Flux from i+1 to i IF u LT 0.
+         DO ji = fs_2, fs_jpim1
+            zbt  =       zbet(ji,jj)
+            zbt1 = 1.0 - zbet(ji,jj)
+            psm(ji,jj)  = zbt * psm(ji,jj)  + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
+            zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
+            zalf1       = 1.0 - zalf
+            ztemp       = - zalf * ps0(ji,jj) + zalf1 * zf0(ji,jj)
+            !
+            ps0(ji,jj)  = zbt * ps0 (ji,jj) + zbt1 * ( ps0(ji,jj) + zf0(ji,jj) )
+            psx(ji,jj)  = zbt * psx (ji,jj) + zbt1 * ( zalf * zfx(ji,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp )
+            psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( zalf * zalf * zfxx(ji,jj)  + zalf1 * zalf1 * psxx(ji,jj)  &
+               &                                      + 5.0 *( zalf * zalf1 * ( - psx(ji,jj) + zfx(ji,jj) )      &
+               &                                      + ( zalf1 - zalf ) * ztemp ) )
+            psxy(ji,jj) = zbt * psxy(ji,jj) + zbt1 * (  zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)  &
+               &                                      + 3.0 * ( zalf1 * zfy(ji,jj) - zalf * psy(ji,jj) )  )
+            psy(ji,jj)  = zbt * psy (ji,jj)  + zbt1 * ( psy (ji,jj) + zfy (ji,jj) )
+            psyy(ji,jj) = zbt * psyy(ji,jj)  + zbt1 * ( psyy(ji,jj) + zfyy(ji,jj) )
+         END DO
+      END DO
+
+      !-- Lateral boundary conditions
+      CALL lbc_lnk_multi( psm , 'T',  1., ps0 , 'T',  1.   &
+         &              , psx , 'T', -1., psy , 'T', -1.   &   ! caution gradient ==> the sign changes
+         &              , psxx, 'T',  1., psyy, 'T',  1.   &
+         &              , psxy, 'T',  1. )
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab2d_1=psm  , clinfo1=' lim_adv_x: psm  :', tab2d_2=ps0 , clinfo2=' ps0  : ')
+         CALL prt_ctl(tab2d_1=psx  , clinfo1=' lim_adv_x: psx  :', tab2d_2=psxx, clinfo2=' psxx : ')
+         CALL prt_ctl(tab2d_1=psy  , clinfo1=' lim_adv_x: psy  :', tab2d_2=psyy, clinfo2=' psyy : ')
+         CALL prt_ctl(tab2d_1=psxy , clinfo1=' lim_adv_x: psxy :')
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
+      CALL wrk_dealloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
+      !
+   END SUBROUTINE lim_adv_x
+
+
+   SUBROUTINE lim_adv_y( pdf, pvt , pcrh, psm , ps0 ,   &
+      &                  psx, psxx, psy , psyy, psxy )
+      !!---------------------------------------------------------------------
+      !!                **  routine lim_adv_y  **
+      !!            
+      !! ** purpose :   Computes and adds the advection trend to sea-ice 
+      !!              variable on y axis
+      !!
+      !! ** method  :   Uses Prather second order scheme that advects tracers
+      !!              but also their quadratic forms. The method preserves 
+      !!              tracer structures by conserving second order moments.
+      !! 
+      !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
+      !!---------------------------------------------------------------------
+      REAL(wp)                    , INTENT(in   ) ::   pdf                ! reduction factor for the time step
+      REAL(wp)                    , INTENT(in   ) ::   pcrh               ! call lim_adv_x then lim_adv_y (=1) or the opposite (=0)
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pvt                ! j-direction ice velocity at V-point [m/s]
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psm                ! area
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ps0                ! field to be advected
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psx , psy          ! 1st moments 
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psxx, psyy, psxy   ! 2nd moments
+      !!
+      INTEGER  ::   ji, jj                               ! dummy loop indices
+      REAL(wp) ::   zs1max, zrdt, zslpmax, ztemp         ! temporary scalars
+      REAL(wp) ::   zs1new, zalf , zalfq , zbt           !    -         -
+      REAL(wp) ::   zs2new, zalf1, zalf1q, zbt1          !    -         -
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zf0, zfx , zfy , zbet   ! 2D workspace
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zfm, zfxx, zfyy, zfxy   !  -      -
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zalg, zalg1, zalg1q     !  -      -
+      !---------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
+      CALL wrk_alloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
+
+      ! Limitation of moments.
+
+      zrdt = rdt_ice * pdf ! If ice drift field is too fast, use an appropriate time step for advection.
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zslpmax = MAX( 0._wp, ps0(ji,jj) )
+            zs1max  = 1.5 * zslpmax
+            zs1new  = MIN( zs1max, MAX( -zs1max, psy(ji,jj) ) )
+            zs2new  = MIN(  ( 2.0 * zslpmax - 0.3334 * ABS( zs1new ) ),   &
+               &             MAX( ABS( zs1new )-zslpmax, psyy(ji,jj) )  )
+            rswitch = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zslpmax) ) ) * tmask(ji,jj,1)   ! Case of empty boxes & Apply mask
+            !
+            ps0 (ji,jj) = zslpmax  
+            psx (ji,jj) = psx (ji,jj) * rswitch
+            psxx(ji,jj) = psxx(ji,jj) * rswitch
+            psy (ji,jj) = zs1new * rswitch
+            psyy(ji,jj) = zs2new * rswitch
+            psxy(ji,jj) = MIN( zslpmax, MAX( -zslpmax, psxy(ji,jj) ) ) * rswitch
+         END DO
+      END DO
+
+      !  Initialize volumes of boxes (=area if adv_x first called, =psm otherwise)
+      psm(:,:)  = MAX(  pcrh * e1e2t(:,:) + ( 1.0 - pcrh ) * psm(:,:) , epsi20  )
+
+      !  Calculate fluxes and moments between boxes j<-->j+1              
+      DO jj = 1, jpj                     !  Flux from j to j+1 WHEN v GT 0   
+         DO ji = 1, jpi
+            zbet(ji,jj)  =  MAX( 0._wp, SIGN( 1._wp, pvt(ji,jj) ) )
+            zalf         =  MAX( 0._wp, pvt(ji,jj) ) * zrdt * e1v(ji,jj) / psm(ji,jj)
+            zalfq        =  zalf * zalf
+            zalf1        =  1.0 - zalf
+            zalf1q       =  zalf1 * zalf1
+            !
+            zfm (ji,jj)  =  zalf  * psm(ji,jj)
+            zf0 (ji,jj)  =  zalf  * ( ps0(ji,jj) + zalf1 * ( psy(ji,jj)  + (zalf1-zalf) * psyy(ji,jj)  ) ) 
+            zfy (ji,jj)  =  zalfq *( psy(ji,jj) + 3.0*zalf1*psyy(ji,jj) )
+            zfyy(ji,jj)  =  zalf  * zalfq * psyy(ji,jj)
+            zfx (ji,jj)  =  zalf  * ( psx(ji,jj) + zalf1 * psxy(ji,jj) )
+            zfxy(ji,jj)  =  zalfq * psxy(ji,jj)
+            zfxx(ji,jj)  =  zalf  * psxx(ji,jj)
+            !
+            !  Readjust moments remaining in the box.
+            psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
+            ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
+            psy (ji,jj)  =  zalf1q * ( psy(ji,jj) -3.0 * zalf * psyy(ji,jj) )
+            psyy(ji,jj)  =  zalf1 * zalf1q * psyy(ji,jj)
+            psx (ji,jj)  =  psx (ji,jj) - zfx(ji,jj)
+            psxx(ji,jj)  =  psxx(ji,jj) - zfxx(ji,jj)
+            psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
+         END DO
+      END DO
+      !
+      DO jj = 1, jpjm1                   !  Flux from j+1 to j when v LT 0.
+         DO ji = 1, jpi
+            zalf          = ( MAX(0._wp, -pvt(ji,jj) ) * zrdt * e1v(ji,jj) ) / psm(ji,jj+1) 
+            zalg  (ji,jj) = zalf
+            zalfq         = zalf * zalf
+            zalf1         = 1.0 - zalf
+            zalg1 (ji,jj) = zalf1
+            zalf1q        = zalf1 * zalf1
+            zalg1q(ji,jj) = zalf1q
+            !
+            zfm   (ji,jj) = zfm (ji,jj) + zalf  *   psm (ji,jj+1)
+            zf0   (ji,jj) = zf0 (ji,jj) + zalf  * ( ps0 (ji,jj+1) - zalf1 * (psy(ji,jj+1) - (zalf1 - zalf ) * psyy(ji,jj+1) ) )
+            zfy   (ji,jj) = zfy (ji,jj) + zalfq * ( psy (ji,jj+1) - 3.0 * zalf1 * psyy(ji,jj+1) )
+            zfyy  (ji,jj) = zfyy(ji,jj) + zalf  *   psyy(ji,jj+1) * zalfq
+            zfx   (ji,jj) = zfx (ji,jj) + zalf  * ( psx (ji,jj+1) - zalf1 * psxy(ji,jj+1) )
+            zfxy  (ji,jj) = zfxy(ji,jj) + zalfq *   psxy(ji,jj+1)
+            zfxx  (ji,jj) = zfxx(ji,jj) + zalf  *   psxx(ji,jj+1)
+         END DO
+      END DO
+
+      !  Readjust moments remaining in the box. 
+      DO jj = 2, jpj
+         DO ji = 1, jpi
+            zbt  =         zbet(ji,jj-1)
+            zbt1 = ( 1.0 - zbet(ji,jj-1) )
+            !
+            psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji,jj-1) )
+            ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji,jj-1) )
+            psy (ji,jj) = zalg1q(ji,jj-1) * ( psy(ji,jj) + 3.0 * zalg(ji,jj-1) * psyy(ji,jj) )
+            psyy(ji,jj) = zalg1 (ji,jj-1) * zalg1q(ji,jj-1) * psyy(ji,jj)
+            psx (ji,jj) = zbt * psx (ji,jj) + zbt1 * ( psx (ji,jj) - zfx (ji,jj-1) )
+            psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) - zfxx(ji,jj-1) )
+            psxy(ji,jj) = zalg1q(ji,jj-1) * psxy(ji,jj)
+         END DO
+      END DO
+
+      !   Put the temporary moments into appropriate neighboring boxes.    
+      DO jj = 2, jpjm1                    !   Flux from j to j+1 IF v GT 0.
+         DO ji = 1, jpi
+            zbt  =         zbet(ji,jj-1)
+            zbt1 = ( 1.0 - zbet(ji,jj-1) )
+            psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji,jj-1) ) + zbt1 * psm(ji,jj) 
+            zalf        = zbt * zfm(ji,jj-1) / psm(ji,jj) 
+            zalf1       = 1.0 - zalf
+            ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji,jj-1)
+            !
+            ps0(ji,jj)  = zbt  * ( ps0(ji,jj) + zf0(ji,jj-1) ) + zbt1 * ps0(ji,jj)
+            psy(ji,jj)  = zbt  * ( zalf * zfy(ji,jj-1) + zalf1 * psy(ji,jj) + 3.0 * ztemp )   &
+               &                                               + zbt1 * psy(ji,jj)  
+            psyy(ji,jj) = zbt  * ( zalf * zalf * zfyy(ji,jj-1) + zalf1 * zalf1 * psyy(ji,jj)                             &
+               &                 + 5.0 * ( zalf * zalf1 * ( psy(ji,jj) - zfy(ji,jj-1) ) - ( zalf1 - zalf ) * ztemp ) )   & 
+               &                                               + zbt1 * psyy(ji,jj)
+            psxy(ji,jj) = zbt  * (  zalf * zfxy(ji,jj-1) + zalf1 * psxy(ji,jj)               &
+               &                  + 3.0 * (- zalf1 * zfx(ji,jj-1) + zalf * psx(ji,jj) )  )   &
+               &                                                + zbt1 * psxy(ji,jj)
+            psx (ji,jj) = zbt * ( psx (ji,jj) + zfx (ji,jj-1) ) + zbt1 * psx (ji,jj)
+            psxx(ji,jj) = zbt * ( psxx(ji,jj) + zfxx(ji,jj-1) ) + zbt1 * psxx(ji,jj)
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1                   !  Flux from j+1 to j IF v LT 0.
+         DO ji = 1, jpi
+            zbt  =         zbet(ji,jj)
+            zbt1 = ( 1.0 - zbet(ji,jj) )
+            psm(ji,jj)  = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
+            zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
+            zalf1       = 1.0 - zalf
+            ztemp       = - zalf * ps0 (ji,jj) + zalf1 * zf0(ji,jj)
+            ps0 (ji,jj) =   zbt  * ps0 (ji,jj) + zbt1  * ( ps0(ji,jj) + zf0(ji,jj) )
+            psy (ji,jj) =   zbt  * psy (ji,jj) + zbt1  * ( zalf * zfy(ji,jj) + zalf1 * psy(ji,jj) + 3.0 * ztemp )
+            psyy(ji,jj) =   zbt  * psyy(ji,jj) + zbt1 * (  zalf * zalf * zfyy(ji,jj) + zalf1 * zalf1 * psyy(ji,jj)   &
+               &                                         + 5.0 *( zalf *zalf1 *( -psy(ji,jj) + zfy(ji,jj) )          &
+               &                                         + ( zalf1 - zalf ) * ztemp )                                )
+            psxy(ji,jj) =   zbt  * psxy(ji,jj) + zbt1 * (  zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)       &
+               &                                         + 3.0 * ( zalf1 * zfx(ji,jj) - zalf * psx(ji,jj) )  )
+            psx (ji,jj) =   zbt  * psx (ji,jj) + zbt1 * ( psx (ji,jj) + zfx (ji,jj) )
+            psxx(ji,jj) =   zbt  * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) + zfxx(ji,jj) )
+         END DO
+      END DO
+
+      !-- Lateral boundary conditions
+      CALL lbc_lnk_multi( psm , 'T',  1.,  ps0 , 'T',  1.   &
+         &              , psx , 'T', -1.,  psy , 'T', -1.   &   ! caution gradient ==> the sign changes
+         &              , psxx, 'T',  1.,  psyy, 'T',  1.   &
+         &              , psxy, 'T',  1. )
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab2d_1=psm  , clinfo1=' lim_adv_y: psm  :', tab2d_2=ps0 , clinfo2=' ps0  : ')
+         CALL prt_ctl(tab2d_1=psx  , clinfo1=' lim_adv_y: psx  :', tab2d_2=psxx, clinfo2=' psxx : ')
+         CALL prt_ctl(tab2d_1=psy  , clinfo1=' lim_adv_y: psy  :', tab2d_2=psyy, clinfo2=' psyy : ')
+         CALL prt_ctl(tab2d_1=psxy , clinfo1=' lim_adv_y: psxy :')
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
+      CALL wrk_dealloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
+      !
+   END SUBROUTINE lim_adv_y
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option            Dummy module         NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE limadv_prather
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limadv_umx.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limadv_umx.F90	(revision 7309)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limadv_umx.F90	(revision 7309)
@@ -0,0 +1,587 @@
+MODULE limadv_umx
+   !!==============================================================================
+   !!                       ***  MODULE  limadv_umx  ***
+   !! LIM sea-ice model : sea-ice advection using the ULTIMATE-MACHO scheme
+   !!==============================================================================
+   !! History :  3.5  !  2014-11  (C. Rousset, G. Madec)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   lim_adv_umx   : update the tracer trend with the 3D advection trends using a TVD scheme
+   !!   ultimate      : compute a tracer value at velocity points using ULTIMATE scheme at various orders
+   !!   macho         : 
+   !!   nonosc_2d     : compute monotonic tracer fluxes by a non-oscillatory algorithm 
+   !!----------------------------------------------------------------------
+   USE phycst         ! physical constant
+   USE dom_oce        ! ocean domain
+   USE sbc_oce        ! ocean surface boundary condition
+   USE ice            ! ice variables
+   !
+   USE in_out_manager ! I/O manager
+   USE lbclnk         ! lateral boundary conditions -- MPP exchanges
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! work arrays
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   lim_adv_umx    ! routine called by limtrp.F90
+      
+   REAL(wp) ::   z1_6   = 1._wp / 6._wp   ! =1/6
+   REAL(wp) ::   z1_120 = 1._wp / 120._wp ! =1/120
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: limadv_umx.F90 4499 2014-02-18 15:14:31Z timgraham $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE lim_adv_umx( kt, pdt, puc, pvc, pubox, pvbox, ptc )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_adv_umx  ***
+      !! 
+      !! **  Purpose :   Compute the now trend due to total advection of 
+      !!       tracers and add it to the general trend of tracer equations
+      !!
+      !! **  Method  :   TVD scheme, i.e. 2nd order centered scheme with
+      !!       corrected flux (monotonic correction)
+      !!       note: - this advection scheme needs a leap-frog time scheme
+      !!
+      !! ** Action : - pt  the after advective tracer
+      !!----------------------------------------------------------------------
+      INTEGER                     , INTENT(in   )           ::   kt         ! number of iteration
+      REAL(wp)                    , INTENT(in   )           ::   pdt        ! tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   )           ::   puc, pvc   ! 2 ice velocity components => u*e2
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   )           ::   pubox, pvbox   ! upstream velocity
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout)           ::   ptc        ! tracer content field
+      !
+      INTEGER  ::   ji, jj           ! dummy loop indices  
+      REAL(wp) ::   ztra             ! local scalar
+      REAL(wp) ::   zfp_ui, zfp_vj   !   -      -
+      REAL(wp) ::   zfm_ui, zfm_vj   !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:) :: zt_ups, zfu_ups, zfv_ups, ztrd, zfu_ho, zfv_ho, zt_u, zt_v
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('lim_adv_umx')
+      !
+      CALL wrk_alloc( jpi,jpj,   zt_ups, zfu_ups, zfv_ups, ztrd, zfu_ho, zfv_ho, zt_u, zt_v )
+      !
+      !
+      !  upstream advection with initial mass fluxes & intermediate update
+      ! --------------------------------------------------------------------
+      DO jj = 1, jpjm1         ! upstream tracer flux in the i and j direction
+         DO ji = 1, fs_jpim1   ! vector opt.
+            zfp_ui = puc(ji,jj) + ABS( puc(ji,jj) )
+            zfm_ui = puc(ji,jj) - ABS( puc(ji,jj) )
+            zfp_vj = pvc(ji,jj) + ABS( pvc(ji,jj) )
+            zfm_vj = pvc(ji,jj) - ABS( pvc(ji,jj) )
+            zfu_ups(ji,jj) = 0.5_wp * ( zfp_ui * ptc(ji,jj) + zfm_ui * ptc(ji+1,jj  ) )
+            zfv_ups(ji,jj) = 0.5_wp * ( zfp_vj * ptc(ji,jj) + zfm_vj * ptc(ji  ,jj+1) )
+         END DO
+      END DO
+      
+      DO jj = 2, jpjm1            ! total intermediate advective trends
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ztra = - (   zfu_ups(ji,jj) - zfu_ups(ji-1,jj  )   &
+               &       + zfv_ups(ji,jj) - zfv_ups(ji  ,jj-1)   ) * r1_e1e2t(ji,jj)
+            !
+            ztrd(ji,jj) =                         ztra                         ! upstream trend [ -div(uh) or -div(uhT) ]  
+            zt_ups (ji,jj) = ( ptc(ji,jj) + pdt * ztra ) * tmask(ji,jj,1)      ! guess after content field with monotonic scheme
+         END DO
+      END DO
+      CALL lbc_lnk( zt_ups, 'T', 1. )        ! Lateral boundary conditions   (unchanged sign)
+      
+      ! High order (_ho) fluxes 
+      ! -----------------------
+      SELECT CASE( nn_limadv_ord )
+      CASE ( 20 )                          ! centered second order
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zfu_ho(ji,jj) = 0.5 * puc(ji,jj) * ( ptc(ji,jj) + ptc(ji+1,jj) )
+               zfv_ho(ji,jj) = 0.5 * pvc(ji,jj) * ( ptc(ji,jj) + ptc(ji,jj+1) )
+            END DO
+         END DO
+         !
+      CASE ( 1:5 )                      ! 1st to 5th order ULTIMATE-MACHO scheme
+         CALL macho( kt, nn_limadv_ord, pdt, ptc, puc, pvc, pubox, pvbox, zt_u, zt_v )
+         !
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zfu_ho(ji,jj) = puc(ji,jj) * zt_u(ji,jj)
+               zfv_ho(ji,jj) = pvc(ji,jj) * zt_v(ji,jj)
+            END DO
+         END DO
+         !
+      END SELECT
+         
+      ! antidiffusive flux : high order minus low order
+      ! --------------------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zfu_ho(ji,jj) = zfu_ho(ji,jj) - zfu_ups(ji,jj)
+            zfv_ho(ji,jj) = zfv_ho(ji,jj) - zfv_ups(ji,jj)
+         END DO
+      END DO
+      CALL lbc_lnk_multi( zfu_ho, 'U', -1., zfv_ho, 'V', -1. )         ! Lateral bondary conditions
+      
+      ! monotonicity algorithm
+      ! -------------------------
+      CALL nonosc_2d( ptc, zfu_ho, zfv_ho, zt_ups, pdt )
+      
+      ! final trend with corrected fluxes
+      ! ------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.  
+            ztra       = ztrd(ji,jj)  - (  zfu_ho(ji,jj) - zfu_ho(ji-1,jj  )   &
+               &                         + zfv_ho(ji,jj) - zfv_ho(ji  ,jj-1) ) * r1_e1e2t(ji,jj)  
+            ptc(ji,jj) = ptc(ji,jj) + pdt * ztra
+         END DO
+      END DO
+      CALL lbc_lnk( ptc(:,:) , 'T',  1. )
+      !
+      !
+      CALL wrk_dealloc( jpi,jpj,   zt_ups, zfu_ups, zfv_ups, ztrd, zfu_ho, zfv_ho, zt_u, zt_v )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('lim_adv_umx')
+      !
+   END SUBROUTINE lim_adv_umx
+
+
+   SUBROUTINE macho( kt, k_order, pdt, ptc, puc, pvc, pubox, pvbox, pt_u, pt_v )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE ultimate_x  ***
+      !!     
+      !! **  Purpose :   compute  
+      !!
+      !! **  Method  :   ... ???
+      !!                 TIM = transient interpolation Modeling 
+      !!
+      !! Reference : Leonard, B.P., 1991, Comput. Methods Appl. Mech. Eng., 88, 17-74. 
+      !!----------------------------------------------------------------------
+      INTEGER                     , INTENT(in   ) ::   kt         ! number of iteration
+      INTEGER                     , INTENT(in   ) ::   k_order    ! order of the ULTIMATE scheme
+      REAL(wp)                    , INTENT(in   ) ::   pdt        ! tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   ptc        ! tracer fields
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   puc, pvc   ! 2 ice velocity components
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pubox, pvbox   ! upstream velocity
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   pt_u, pt_v ! tracer at u- and v-points 
+      !
+      INTEGER  ::   ji, jj    ! dummy loop indices
+      REAL(wp) ::   zc_box    !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:) :: zzt
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('macho')
+      !
+      CALL wrk_alloc( jpi,jpj,   zzt )
+      !
+      IF( MOD( (kt - 1) / nn_fsbc , 2 ) == 0 ) THEN         !==  odd ice time step:  adv_x then adv_y  ==!
+         !
+         !                                                           !--  ultimate interpolation of pt at u-point  --!
+         CALL ultimate_x( k_order, pdt, ptc, puc, pt_u )
+         !
+         !                                                           !--  advective form update in zzt  --!
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zzt(ji,jj) = ptc(ji,jj) - pubox(ji,jj) * pdt * ( pt_u(ji,jj) - pt_u(ji-1,jj) ) * r1_e1t(ji,jj)  &
+                  &                    - ptc  (ji,jj) * pdt * ( puc (ji,jj) - puc (ji-1,jj) ) * r1_e1e2t(ji,jj)
+               zzt(ji,jj) = zzt(ji,jj) * tmask(ji,jj,1)
+            END DO
+         END DO
+         CALL lbc_lnk( zzt, 'T', 1. )
+         !
+         !                                                           !--  ultimate interpolation of pt at v-point  --!
+         CALL ultimate_y( k_order, pdt, zzt, pvc, pt_v )
+         !
+      ELSE                                                  !==  even ice time step:  adv_y then adv_x  ==!
+         !
+         !                                                           !--  ultimate interpolation of pt at v-point  --!
+         CALL ultimate_y( k_order, pdt, ptc, pvc, pt_v )
+         !
+         !                                                           !--  advective form update in zzt  --!
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zzt(ji,jj) = ptc(ji,jj) - pvbox(ji,jj) * pdt * ( pt_v(ji,jj) - pt_v(ji,jj-1) ) * r1_e2t(ji,jj)  &
+                  &                    - ptc  (ji,jj) * pdt * ( pvc (ji,jj) - pvc (ji,jj-1) ) * r1_e1e2t(ji,jj)
+               zzt(ji,jj) = zzt(ji,jj) * tmask(ji,jj,1)
+            END DO
+         END DO
+         CALL lbc_lnk( zzt, 'T', 1. )
+         !
+         !                                                           !--  ultimate interpolation of pt at u-point  --!
+         CALL ultimate_x( k_order, pdt, zzt, puc, pt_u )
+         !      
+      ENDIF      
+      !
+      CALL wrk_dealloc( jpi,jpj,   zzt )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('macho')
+      !
+   END SUBROUTINE macho
+
+
+   SUBROUTINE ultimate_x( k_order, pdt, pt, puc, pt_u )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE ultimate_x  ***
+      !!     
+      !! **  Purpose :   compute  
+      !!
+      !! **  Method  :   ... ???
+      !!                 TIM = transient interpolation Modeling 
+      !!
+      !! Reference : Leonard, B.P., 1991, Comput. Methods Appl. Mech. Eng., 88, 17-74. 
+      !!----------------------------------------------------------------------
+      INTEGER                     , INTENT(in   ) ::   k_order   ! ocean time-step index
+      REAL(wp)                    , INTENT(in   ) ::   pdt       ! tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   puc       ! ice i-velocity component
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pt        ! tracer fields
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   pt_u      ! tracer at u-point 
+      !
+      INTEGER  ::   ji, jj       ! dummy loop indices
+      REAL(wp) ::   zcu, zdx2, zdx4    !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:) :: ztu1, ztu2, ztu3, ztu4
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('ultimate_x')
+      !
+      CALL wrk_alloc( jpi,jpj,   ztu1, ztu2, ztu3, ztu4 )
+      !
+      !                                                     !--  Laplacian in i-direction  --!
+      DO jj = 2, jpjm1         ! First derivative (gradient)
+         DO ji = 1, fs_jpim1
+            ztu1(ji,jj) = ( pt(ji+1,jj) - pt(ji,jj) ) * r1_e1u(ji,jj) * umask(ji,jj,1)
+         END DO
+         !                     ! Second derivative (Laplacian)
+         DO ji = fs_2, fs_jpim1
+            ztu2(ji,jj) = ( ztu1(ji,jj) - ztu1(ji-1,jj) ) * r1_e1t(ji,jj)
+         END DO
+      END DO
+      CALL lbc_lnk( ztu2, 'T', 1. )
+      !
+      !                                                     !--  BiLaplacian in i-direction  --!
+      DO jj = 2, jpjm1         ! Third derivative
+         DO ji = 1, fs_jpim1
+            ztu3(ji,jj) = ( ztu2(ji+1,jj) - ztu2(ji,jj) ) * r1_e1u(ji,jj) * umask(ji,jj,1)
+         END DO
+         !                     ! Fourth derivative
+         DO ji = fs_2, fs_jpim1
+            ztu4(ji,jj) = ( ztu3(ji,jj) - ztu3(ji-1,jj) ) * r1_e1t(ji,jj)
+         END DO
+      END DO
+      CALL lbc_lnk( ztu4, 'T', 1. )
+      !
+      !
+      SELECT CASE (k_order )
+      !
+      CASE( 1 )                                                   !==  1st order central TIM  ==! (Eq. 21)
+         !        
+         DO jj = 1, jpj
+            DO ji = 1, fs_jpim1   ! vector opt.
+               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (                               pt(ji+1,jj) + pt(ji,jj)   &
+                  &                                    - SIGN( 1._wp, puc(ji,jj) ) * ( pt(ji+1,jj) - pt(ji,jj) ) )
+            END DO
+         END DO
+         !
+      CASE( 2 )                                                   !==  2nd order central TIM  ==! (Eq. 23)
+         !
+         DO jj = 1, jpj
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zcu  = puc(ji,jj) * r1_e2u(ji,jj) * pdt * r1_e1u(ji,jj)
+               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (                                   pt(ji+1,jj) + pt(ji,jj)   &
+                  &                                               -              zcu   * ( pt(ji+1,jj) - pt(ji,jj) ) ) 
+            END DO
+         END DO
+         CALL lbc_lnk( pt_u(:,:) , 'U',  1. )
+         !  
+      CASE( 3 )                                                   !==  3rd order central TIM  ==! (Eq. 24)
+         !
+         DO jj = 1, jpj
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zcu  = puc(ji,jj) * r1_e2u(ji,jj) * pdt * r1_e1u(ji,jj)
+               zdx2 = e1u(ji,jj) * e1u(ji,jj)
+!!rachid       zdx2 = e1u(ji,jj) * e1t(ji,jj)
+               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (         (                         pt  (ji+1,jj) + pt  (ji,jj)        &
+                  &                                               -              zcu   * ( pt  (ji+1,jj) - pt  (ji,jj) )  )   &
+                  &        + z1_6 * zdx2 * ( zcu*zcu - 1._wp ) * (                         ztu2(ji+1,jj) + ztu2(ji,jj)        &
+                  &                                               - SIGN( 1._wp, zcu ) * ( ztu2(ji+1,jj) - ztu2(ji,jj) )  )   )
+            END DO
+         END DO
+         !
+      CASE( 4 )                                                   !==  4th order central TIM  ==! (Eq. 27)
+         !
+         DO jj = 1, jpj
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zcu  = puc(ji,jj) * r1_e2u(ji,jj) * pdt * r1_e1u(ji,jj)
+               zdx2 = e1u(ji,jj) * e1u(ji,jj)
+!!rachid       zdx2 = e1u(ji,jj) * e1t(ji,jj)
+               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (         (                   pt  (ji+1,jj) + pt  (ji,jj)        &
+                  &                                               -          zcu * ( pt  (ji+1,jj) - pt  (ji,jj) )  )   &
+                  &        + z1_6 * zdx2 * ( zcu*zcu - 1._wp ) * (                   ztu2(ji+1,jj) + ztu2(ji,jj)        &
+                  &                                               - 0.5_wp * zcu * ( ztu2(ji+1,jj) - ztu2(ji,jj) )  )   )
+            END DO
+         END DO
+         !
+      CASE( 5 )                                                   !==  5th order central TIM  ==! (Eq. 29)
+         !
+         DO jj = 1, jpj
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zcu  = puc(ji,jj) * r1_e2u(ji,jj) * pdt * r1_e1u(ji,jj)
+               zdx2 = e1u(ji,jj) * e1u(ji,jj)
+!!rachid       zdx2 = e1u(ji,jj) * e1t(ji,jj)
+               zdx4 = zdx2 * zdx2
+               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (               (                   pt  (ji+1,jj) + pt  (ji,jj)       &
+                  &                                                     -          zcu * ( pt  (ji+1,jj) - pt  (ji,jj) ) )   &
+                  &        + z1_6   * zdx2 * ( zcu*zcu - 1._wp ) *     (                   ztu2(ji+1,jj) + ztu2(ji,jj)       &
+                  &                                                     - 0.5_wp * zcu * ( ztu2(ji+1,jj) - ztu2(ji,jj) ) )   &
+                  &        + z1_120 * zdx4 * ( zcu*zcu - 1._wp ) * ( zcu*zcu - 4._wp ) * ( ztu4(ji+1,jj) + ztu4(ji,jj)       &
+                  &                                               - SIGN( 1._wp, zcu ) * ( ztu4(ji+1,jj) - ztu4(ji,jj) ) ) )
+            END DO
+         END DO
+         !
+      END SELECT
+      !
+      CALL wrk_dealloc( jpi,jpj,   ztu1, ztu2, ztu3, ztu4 )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('ultimate_x')
+      !
+   END SUBROUTINE ultimate_x
+   
+ 
+   SUBROUTINE ultimate_y( k_order, pdt, pt, pvc, pt_v )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE ultimate_y  ***
+      !!     
+      !! **  Purpose :   compute  
+      !!
+      !! **  Method  :   ... ???
+      !!                 TIM = transient interpolation Modeling 
+      !!
+      !! Reference : Leonard, B.P., 1991, Comput. Methods Appl. Mech. Eng., 88, 17-74. 
+      !!----------------------------------------------------------------------
+      INTEGER                     , INTENT(in   ) ::   k_order   ! ocean time-step index
+      REAL(wp)                    , INTENT(in   ) ::   pdt       ! tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pvc       ! ice j-velocity component
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pt        ! tracer fields
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   pt_v      ! tracer at v-point 
+      !
+      INTEGER  ::   ji, jj       ! dummy loop indices
+      REAL(wp) ::   zcv, zdy2, zdy4    !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:) :: ztv1, ztv2, ztv3, ztv4
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('ultimate_y')
+      !
+      CALL wrk_alloc( jpi,jpj,   ztv1, ztv2, ztv3, ztv4 )
+      !
+      !                                                     !--  Laplacian in j-direction  --!
+      DO jj = 1, jpjm1         ! First derivative (gradient)
+         DO ji = fs_2, fs_jpim1
+            ztv1(ji,jj) = ( pt(ji,jj+1) - pt(ji,jj) ) * r1_e2v(ji,jj) * vmask(ji,jj,1)
+         END DO
+      END DO
+      DO jj = 2, jpjm1         ! Second derivative (Laplacian)
+         DO ji = fs_2, fs_jpim1
+            ztv2(ji,jj) = ( ztv1(ji,jj) - ztv1(ji,jj-1) ) * r1_e2t(ji,jj)
+         END DO
+      END DO
+      CALL lbc_lnk( ztv2, 'T', 1. )
+      !
+      !                                                     !--  BiLaplacian in j-direction  --!
+      DO jj = 1, jpjm1         ! First derivative
+         DO ji = fs_2, fs_jpim1
+            ztv3(ji,jj) = ( ztv2(ji,jj+1) - ztv2(ji,jj) ) * r1_e2v(ji,jj) * vmask(ji,jj,1)
+         END DO
+      END DO
+      DO jj = 2, jpjm1         ! Second derivative
+         DO ji = fs_2, fs_jpim1
+            ztv4(ji,jj) = ( ztv3(ji,jj) - ztv3(ji,jj-1) ) * r1_e2t(ji,jj)
+         END DO
+      END DO
+      CALL lbc_lnk( ztv4, 'T', 1. )
+      !
+      !
+      SELECT CASE (k_order )
+         !
+      CASE( 1 )                                                   !==  1st order central TIM  ==! (Eq. 21)
+         !        
+         DO jj = 1, jpjm1
+            DO ji = 1, jpi
+               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (                              ( pt(ji,jj+1) + pt(ji,jj) )  &
+                  &                                     - SIGN( 1._wp, pvc(ji,jj) ) * ( pt(ji,jj+1) - pt(ji,jj) ) )
+            END DO
+         END DO
+         !
+      CASE( 2 )                                                   !==  2nd order central TIM  ==! (Eq. 23)
+         DO jj = 1, jpjm1
+            DO ji = 1, jpi
+               zcv  = pvc(ji,jj) * r1_e1v(ji,jj) * pdt * r1_e2v(ji,jj)
+               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (        ( pt(ji,jj+1) + pt(ji,jj) )  &
+                  &                                     - zcv * ( pt(ji,jj+1) - pt(ji,jj) ) )
+            END DO
+         END DO
+         CALL lbc_lnk( pt_v(:,:) , 'V',  1. )
+         !
+      CASE( 3 )                                                   !==  3rd order central TIM  ==! (Eq. 24)
+         !
+         DO jj = 1, jpjm1
+            DO ji = 1, jpi
+               zcv  = pvc(ji,jj) * r1_e1v(ji,jj) * pdt * r1_e2v(ji,jj)
+               zdy2 = e2v(ji,jj) * e2v(ji,jj)
+!!rachid       zdy2 = e2v(ji,jj) * e2t(ji,jj)
+               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (                                 ( pt  (ji,jj+1) + pt  (ji,jj)       &
+                  &                                     -                        zcv   * ( pt  (ji,jj+1) - pt  (ji,jj) ) )   &
+                  &        + z1_6 * zdy2 * ( zcv*zcv - 1._wp ) * (                         ztv2(ji,jj+1) + ztv2(ji,jj)       &
+                  &                                               - SIGN( 1._wp, zcv ) * ( ztv2(ji,jj+1) - ztv2(ji,jj) ) ) )
+            END DO
+         END DO
+         !
+      CASE( 4 )                                                   !==  4th order central TIM  ==! (Eq. 27)
+         !
+         DO jj = 1, jpjm1
+            DO ji = 1, jpi
+               zcv  = pvc(ji,jj) * r1_e1v(ji,jj) * pdt * r1_e2v(ji,jj)
+               zdy2 = e2v(ji,jj) * e2v(ji,jj)
+!!rachid       zdy2 = e2v(ji,jj) * e2t(ji,jj)
+               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (                           ( pt  (ji,jj+1) + pt  (ji,jj)       &
+                  &                                               -          zcv * ( pt  (ji,jj+1) - pt  (ji,jj) ) )   &
+                  &        + z1_6 * zdy2 * ( zcv*zcv - 1._wp ) * (                   ztv2(ji,jj+1) + ztv2(ji,jj)       &
+                  &                                               - 0.5_wp * zcv * ( ztv2(ji,jj+1) - ztv2(ji,jj) ) ) )
+            END DO
+         END DO
+         !
+      CASE( 5 )                                                   !==  5th order central TIM  ==! (Eq. 29)
+         !
+         DO jj = 1, jpjm1
+            DO ji = 1, jpi
+               zcv  = pvc(ji,jj) * r1_e1v(ji,jj) * pdt * r1_e2v(ji,jj)
+               zdy2 = e2v(ji,jj) * e2v(ji,jj)
+!!rachid       zdy2 = e2v(ji,jj) * e2t(ji,jj)
+               zdy4 = zdy2 * zdy2
+               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (                                 ( pt  (ji,jj+1) + pt  (ji,jj)      &
+                  &                                                     -          zcv * ( pt  (ji,jj+1) - pt  (ji,jj) ) )  &
+                  &        + z1_6   * zdy2 * ( zcv*zcv - 1._wp ) *     (                   ztv2(ji,jj+1) + ztv2(ji,jj)      &
+                  &                                                     - 0.5_wp * zcv * ( ztv2(ji,jj+1) - ztv2(ji,jj) ) )  &
+                  &        + z1_120 * zdy4 * ( zcv*zcv - 1._wp ) * ( zcv*zcv - 4._wp ) * ( ztv4(ji,jj+1) + ztv4(ji,jj)      &
+                  &                                               - SIGN( 1._wp, zcv ) * ( ztv4(ji,jj+1) - ztv4(ji,jj) ) ) )
+            END DO
+         END DO
+         !
+      END SELECT
+      !
+      CALL wrk_dealloc( jpi,jpj,   ztv1, ztv2, ztv3, ztv4 )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('ultimate_y')
+      !
+   END SUBROUTINE ultimate_y
+   
+  
+   SUBROUTINE nonosc_2d( pbef, paa, pbb, paft, pdt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE nonosc  ***
+      !!     
+      !! **  Purpose :   compute monotonic tracer fluxes from the upstream 
+      !!       scheme and the before field by a nonoscillatory algorithm 
+      !!
+      !! **  Method  :   ... ???
+      !!       warning : pbef and paft must be masked, but the boundaries
+      !!       conditions on the fluxes are not necessary zalezak (1979)
+      !!       drange (1995) multi-dimensional forward-in-time and upstream-
+      !!       in-space based differencing for fluid
+      !!----------------------------------------------------------------------
+      REAL(wp)                     , INTENT(in   ) ::   pdt          ! tracer time-step
+      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   pbef, paft   ! before & after field
+      REAL(wp), DIMENSION (jpi,jpj), INTENT(inout) ::   paa, pbb     ! monotonic fluxes in the 2 directions
+      !
+      INTEGER  ::   ji, jj    ! dummy loop indices
+      INTEGER  ::   ikm1      ! local integer
+      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zsml, z1_dt   ! local scalars
+      REAL(wp) ::   zau, zbu, zcu, zav, zbv, zcv, zup, zdo            !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:) :: zbetup, zbetdo, zbup, zbdo, zmsk, zdiv
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('nonosc_2d')
+      !
+      CALL wrk_alloc( jpi,jpj,   zbetup, zbetdo, zbup, zbdo, zmsk, zdiv )
+      !
+      zbig = 1.e+40_wp
+      zsml = 1.e-15_wp
+
+      ! clem test
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.  
+            zdiv(ji,jj) =  - (  paa(ji,jj) - paa(ji-1,jj  )   &
+               &              + pbb(ji,jj) - pbb(ji  ,jj-1) )  
+         END DO
+      END DO
+      CALL lbc_lnk( zdiv, 'T', 1. )        ! Lateral boundary conditions   (unchanged sign)
+
+      ! Determine ice masks for before and after tracers 
+      WHERE( pbef(:,:) == 0._wp .AND. paft(:,:) == 0._wp .AND. zdiv(:,:) == 0._wp )   ;   zmsk(:,:) = 0._wp
+      ELSEWHERE                                                                       ;   zmsk(:,:) = 1._wp * tmask(:,:,1)
+      END WHERE
+
+      ! Search local extrema
+      ! --------------------
+      ! max/min of pbef & paft with large negative/positive value (-/+zbig) inside land
+!      zbup(:,:) = MAX( pbef(:,:) * tmask(:,:,1) - zbig * ( 1.e0 - tmask(:,:,1) ),   &
+!         &             paft(:,:) * tmask(:,:,1) - zbig * ( 1.e0 - tmask(:,:,1) )  )
+!      zbdo(:,:) = MIN( pbef(:,:) * tmask(:,:,1) + zbig * ( 1.e0 - tmask(:,:,1) ),   &
+!         &             paft(:,:) * tmask(:,:,1) + zbig * ( 1.e0 - tmask(:,:,1) )  )
+      zbup(:,:) = MAX( pbef(:,:) * zmsk(:,:) - zbig * ( 1.e0 - zmsk(:,:) ),   &
+         &             paft(:,:) * zmsk(:,:) - zbig * ( 1.e0 - zmsk(:,:) )  )
+      zbdo(:,:) = MIN( pbef(:,:) * zmsk(:,:) + zbig * ( 1.e0 - zmsk(:,:) ),   &
+         &             paft(:,:) * zmsk(:,:) + zbig * ( 1.e0 - zmsk(:,:) )  )
+
+      z1_dt = 1._wp / pdt
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            !
+            zup  = MAX(   zbup(ji,jj), zbup(ji-1,jj  ), zbup(ji+1,jj  ),   &        ! search max/min in neighbourhood
+               &                       zbup(ji  ,jj-1), zbup(ji  ,jj+1)    )
+            zdo  = MIN(   zbdo(ji,jj), zbdo(ji-1,jj  ), zbdo(ji+1,jj  ),   &
+               &                       zbdo(ji  ,jj-1), zbdo(ji  ,jj+1)    )
+               !
+            zpos = MAX( 0., paa(ji-1,jj  ) ) - MIN( 0., paa(ji  ,jj  ) )   &        ! positive/negative  part of the flux
+               & + MAX( 0., pbb(ji  ,jj-1) ) - MIN( 0., pbb(ji  ,jj  ) )
+            zneg = MAX( 0., paa(ji  ,jj  ) ) - MIN( 0., paa(ji-1,jj  ) )   &
+               & + MAX( 0., pbb(ji  ,jj  ) ) - MIN( 0., pbb(ji  ,jj-1) )
+               !
+            zbt = e1e2t(ji,jj) * z1_dt                                   ! up & down beta terms
+            zbetup(ji,jj) = ( zup         - paft(ji,jj) ) / ( zpos + zsml ) * zbt
+            zbetdo(ji,jj) = ( paft(ji,jj) - zdo         ) / ( zneg + zsml ) * zbt
+         END DO
+      END DO
+      CALL lbc_lnk_multi( zbetup, 'T', 1., zbetdo, 'T', 1. )   ! lateral boundary cond. (unchanged sign)
+
+      ! monotonic flux in the i & j direction (paa & pbb)
+      ! -------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zau = MIN( 1._wp , zbetdo(ji,jj) , zbetup(ji+1,jj) )
+            zbu = MIN( 1._wp , zbetup(ji,jj) , zbetdo(ji+1,jj) )
+            zcu = 0.5  + SIGN( 0.5 , paa(ji,jj) )
+            !
+            zav = MIN( 1._wp , zbetdo(ji,jj) , zbetup(ji,jj+1) )
+            zbv = MIN( 1._wp , zbetup(ji,jj) , zbetdo(ji,jj+1) )
+            zcv = 0.5  + SIGN( 0.5 , pbb(ji,jj) )
+            !
+            paa(ji,jj) = paa(ji,jj) * ( zcu * zau + ( 1._wp - zcu) * zbu )
+            pbb(ji,jj) = pbb(ji,jj) * ( zcv * zav + ( 1._wp - zcv) * zbv )
+            !
+         END DO
+      END DO
+      CALL lbc_lnk_multi( paa, 'U', -1., pbb, 'V', -1. )   ! lateral boundary condition (changed sign)
+      !
+      CALL wrk_dealloc( jpi,jpj,   zbetup, zbetdo, zbup, zbdo, zmsk, zdiv )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('nonosc_2d')
+      !
+   END SUBROUTINE nonosc_2d
+
+   !!======================================================================
+END MODULE limadv_umx
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limcons.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limcons.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limcons.F90	(revision 7309)
@@ -18,5 +18,4 @@
    USE phycst         ! physical constants
    USE ice            ! LIM-3 variables
-   USE dom_ice        ! LIM-3 domain
    USE dom_oce        ! ocean domain
    USE in_out_manager ! I/O manager
@@ -165,5 +164,5 @@
       !!                     + test if ice concentration and volume are > 0
       !!
-      !! ** Method  : This is an online diagnostics which can be activated with ln_limdiahsb=true
+      !! ** Method  : This is an online diagnostics which can be activated with ln_limdiachk=true
       !!              It prints in ocean.output if there is a violation of conservation at each time-step
       !!              The thresholds (zv_sill, zs_sill, zh_sill) which determine violations are set to
@@ -185,10 +184,10 @@
          ! salt flux
          zfs_b  = glob_sum(  ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) +  &
-            &                  sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:)                   &
+            &                  sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:) + sfx_lam(:,:)    &
             &                ) *  e1e2t(:,:) * tmask(:,:,1) * zconv )
 
          ! water flux
-         zfw_b  = glob_sum( -( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) + wfx_opw(:,:) +  &
-            &                  wfx_res(:,:) + wfx_dyn(:,:) + wfx_snw(:,:) + wfx_sub(:,:) + wfx_spr(:,:)    &
+         zfw_b  = glob_sum( -( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) + wfx_opw(:,:) +               &
+            &                  wfx_res(:,:) + wfx_dyn(:,:) + wfx_snw(:,:) + wfx_sub(:,:) + wfx_spr(:,:) + wfx_lam(:,:)  &
             &                ) *  e1e2t(:,:) * tmask(:,:,1) * zconv )
 
@@ -210,10 +209,10 @@
          ! salt flux
          zfs  = glob_sum(  ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) +  &
-            &                sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:)                   & 
+            &                sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:) + sfx_lam(:,:)    & 
             &              ) * e1e2t(:,:) * tmask(:,:,1) * zconv ) - zfs_b
 
          ! water flux
-         zfw  = glob_sum( -( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) + wfx_opw(:,:) +  &
-            &                wfx_res(:,:) + wfx_dyn(:,:) + wfx_snw(:,:) + wfx_sub(:,:) + wfx_spr(:,:)    &
+         zfw  = glob_sum( -( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) + wfx_opw(:,:) +                &
+            &                wfx_res(:,:) + wfx_dyn(:,:) + wfx_snw(:,:) + wfx_sub(:,:) + wfx_spr(:,:) + wfx_lam(:,:)   &
             &              ) * e1e2t(:,:) * tmask(:,:,1) * zconv ) - zfw_b
 
@@ -260,4 +259,5 @@
                &                         cd_routine /= 'limtrp' .AND. cd_routine /= 'limitd_me' ) THEN
                                          WRITE(numout,*) 'violation a_i>amax            (',cd_routine,') = ',zamax
+            IF (     zamax   > 1._wp   ) WRITE(numout,*) 'violation a_i>1               (',cd_routine,') = ',zamax
             ENDIF
             IF (      zamin  < -epsi10 ) WRITE(numout,*) 'violation a_i<0               (',cd_routine,') = ',zamin
@@ -274,5 +274,5 @@
       !! ** Purpose : Test the conservation of heat, salt and mass at the end of each ice time-step
       !!
-      !! ** Method  : This is an online diagnostics which can be activated with ln_limdiahsb=true
+      !! ** Method  : This is an online diagnostics which can be activated with ln_limdiachk=true
       !!              It prints in ocean.output if there is a violation of conservation at each time-step
       !!              The thresholds (zv_sill, zs_sill, zh_sill) which determine the violation are set to
@@ -288,6 +288,7 @@
 #if ! defined key_bdy
       ! heat flux
-      zhfx  = glob_sum( ( hfx_in - hfx_out - diag_heat - diag_trp_ei - diag_trp_es - SUM( qevap_ice * a_i_b, dim=3 ) )  &
-         &              * e1e2t * tmask(:,:,1) * zconv ) 
+      zhfx  = glob_sum( ( hfx_in - hfx_out - diag_heat - diag_trp_ei - diag_trp_es   &
+      !  &              - SUM( qevap_ice * a_i_b, dim=3 )                           & !!clem: I think this line must be commented (but need check)
+         &              ) * e1e2t * tmask(:,:,1) * zconv ) 
       ! salt flux
       zsfx  = glob_sum( ( sfx + diag_smvi ) * e1e2t * tmask(:,:,1) * zconv ) * rday
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limctl.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limctl.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limctl.F90	(revision 7309)
@@ -5,4 +5,5 @@
    !!======================================================================
    !! History :  3.5  !  2015-01  (M. Vancoppenolle) Original code
+   !!            3.7  !  2016-10  (C. Rousset)       Add routine lim_prt3D
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -12,4 +13,5 @@
    !!    lim_ctl   : control prints in case of crash
    !!    lim_prt   : ice control print at a given grid point
+   !!    lim_prt3D : control prints of ice arrays
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers
@@ -17,5 +19,4 @@
    USE ice             ! LIM-3: ice variables
    USE thd_ice         ! LIM-3: thermodynamical variables
-   USE dom_ice         ! LIM-3: ice domain
    USE sbc_oce         ! Surface boundary condition: ocean fields
    USE sbc_ice         ! Surface boundary condition: ice   fields
@@ -35,4 +36,5 @@
    PUBLIC   lim_ctl
    PUBLIC   lim_prt
+   PUBLIC   lim_prt3D
 
    !! * Substitutions
@@ -445,4 +447,73 @@
    END SUBROUTINE lim_prt
 
+   SUBROUTINE lim_prt3D( cd_routine )
+      !!---------------------------------------------------------------------------------------------------------
+      !!                                   ***  ROUTINE lim_prt3D ***
+      !!
+      !! ** Purpose : CTL prints of ice arrays in case ln_ctl is activated 
+      !!
+      !!---------------------------------------------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(in)  :: cd_routine    ! name of the routine
+      INTEGER                       :: jk, jl        ! dummy loop indices
+      
+      CALL prt_ctl_info(' ========== ')
+      CALL prt_ctl_info( cd_routine )
+      CALL prt_ctl_info(' ========== ')
+      CALL prt_ctl_info(' - Cell values : ')
+      CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
+      CALL prt_ctl(tab2d_1=e1e2t      , clinfo1=' cell area   :')
+      CALL prt_ctl(tab2d_1=at_i       , clinfo1=' at_i        :')
+      CALL prt_ctl(tab2d_1=ato_i      , clinfo1=' ato_i       :')
+      CALL prt_ctl(tab2d_1=vt_i       , clinfo1=' vt_i        :')
+      CALL prt_ctl(tab2d_1=vt_s       , clinfo1=' vt_s        :')
+      CALL prt_ctl(tab2d_1=divu_i     , clinfo1=' divu_i      :')
+      CALL prt_ctl(tab2d_1=delta_i    , clinfo1=' delta_i     :')
+      CALL prt_ctl(tab2d_1=stress1_i  , clinfo1=' stress1_i   :')
+      CALL prt_ctl(tab2d_1=stress2_i  , clinfo1=' stress2_i   :')
+      CALL prt_ctl(tab2d_1=stress12_i , clinfo1=' stress12_i  :')
+      CALL prt_ctl(tab2d_1=strength   , clinfo1=' strength    :')
+      CALL prt_ctl(tab2d_1=delta_i    , clinfo1=' delta_i     :')
+      CALL prt_ctl(tab2d_1=u_ice      , clinfo1=' u_ice       :', tab2d_2=v_ice      , clinfo2=' v_ice       :')
+       
+      DO jl = 1, jpl
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Category : ', ivar1=jl)
+         CALL prt_ctl_info('   ~~~~~~~~~~')
+         CALL prt_ctl(tab2d_1=ht_i       (:,:,jl)        , clinfo1= ' ht_i        : ')
+         CALL prt_ctl(tab2d_1=ht_s       (:,:,jl)        , clinfo1= ' ht_s        : ')
+         CALL prt_ctl(tab2d_1=t_su       (:,:,jl)        , clinfo1= ' t_su        : ')
+         CALL prt_ctl(tab2d_1=t_s        (:,:,1,jl)      , clinfo1= ' t_snow      : ')
+         CALL prt_ctl(tab2d_1=sm_i       (:,:,jl)        , clinfo1= ' sm_i        : ')
+         CALL prt_ctl(tab2d_1=o_i        (:,:,jl)        , clinfo1= ' o_i         : ')
+         CALL prt_ctl(tab2d_1=a_i        (:,:,jl)        , clinfo1= ' a_i         : ')
+         CALL prt_ctl(tab2d_1=v_i        (:,:,jl)        , clinfo1= ' v_i         : ')
+         CALL prt_ctl(tab2d_1=v_s        (:,:,jl)        , clinfo1= ' v_s         : ')
+         CALL prt_ctl(tab2d_1=e_i        (:,:,1,jl)      , clinfo1= ' e_i1        : ')
+         CALL prt_ctl(tab2d_1=e_s        (:,:,1,jl)      , clinfo1= ' e_snow      : ')
+         CALL prt_ctl(tab2d_1=smv_i      (:,:,jl)        , clinfo1= ' smv_i       : ')
+         CALL prt_ctl(tab2d_1=oa_i       (:,:,jl)        , clinfo1= ' oa_i        : ')
+         
+         DO jk = 1, nlay_i
+            CALL prt_ctl_info(' - Layer : ', ivar1=jk)
+            CALL prt_ctl(tab2d_1=t_i(:,:,jk,jl) , clinfo1= ' t_i       : ')
+         END DO
+      END DO
+      
+      CALL prt_ctl_info(' ')
+      CALL prt_ctl_info(' - Heat / FW fluxes : ')
+      CALL prt_ctl_info('   ~~~~~~~~~~~~~~~~~~ ')
+      CALL prt_ctl(tab2d_1=sst_m  , clinfo1= ' sst   : ', tab2d_2=sss_m     , clinfo2= ' sss       : ')
+      CALL prt_ctl(tab2d_1=qsr    , clinfo1= ' qsr   : ', tab2d_2=qns       , clinfo2= ' qns       : ')
+      CALL prt_ctl(tab2d_1=emp    , clinfo1= ' emp   : ', tab2d_2=sfx       , clinfo2= ' sfx       : ')
+      
+      CALL prt_ctl_info(' ')
+      CALL prt_ctl_info(' - Stresses : ')
+      CALL prt_ctl_info('   ~~~~~~~~~~ ')
+      CALL prt_ctl(tab2d_1=utau       , clinfo1= ' utau      : ', tab2d_2=vtau       , clinfo2= ' vtau      : ')
+      CALL prt_ctl(tab2d_1=utau_ice   , clinfo1= ' utau_ice  : ', tab2d_2=vtau_ice   , clinfo2= ' vtau_ice  : ')
+      CALL prt_ctl(tab2d_1=u_oce      , clinfo1= ' u_oce     : ', tab2d_2=v_oce      , clinfo2= ' v_oce     : ')
+      
+   END SUBROUTINE lim_prt3D
+
 #else
    !!--------------------------------------------------------------------------
@@ -454,4 +525,6 @@
    SUBROUTINE lim_prt     ! Empty routine
    END SUBROUTINE lim_prt
+   SUBROUTINE lim_prt3D   ! Empty routine
+   END SUBROUTINE lim_prt3D
 #endif
    !!======================================================================
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90	(revision 7309)
@@ -14,5 +14,4 @@
    !!----------------------------------------------------------------------
    USE ice             ! LIM-3: sea-ice variable
-   USE dom_ice         ! LIM-3: sea-ice domain
    USE dom_oce         ! ocean domain
    USE sbc_oce         ! surface boundary condition: ocean fields
@@ -31,8 +30,9 @@
 
    PUBLIC   lim_diahsb        ! routine called by ice_step.F90
-
-   real(wp) ::   frc_sal, frc_vol   ! global forcing trends
-   real(wp) ::   bg_grme            ! global ice growth+melt trends
-
+   PUBLIC   lim_diahsb_init   ! routine called in sbcice_lim.F90
+
+   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
+   
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
@@ -46,5 +46,5 @@
 CONTAINS
 
-   SUBROUTINE lim_diahsb
+   SUBROUTINE lim_diahsb( kt )
       !!---------------------------------------------------------------------------
       !!                  ***  ROUTINE lim_diahsb  ***
@@ -53,169 +53,86 @@
       !!	
       !!---------------------------------------------------------------------------
+      INTEGER, INTENT(in) :: kt    ! number of iteration
       !!
-      real(wp)   ::   zbg_ivo, zbg_svo, zbg_are, zbg_sal ,zbg_tem ,zbg_ihc ,zbg_shc
-      real(wp)   ::   zbg_sfx, zbg_sfx_bri, zbg_sfx_bog, zbg_sfx_bom, zbg_sfx_sum, zbg_sfx_sni,   &
-      &               zbg_sfx_opw, zbg_sfx_res, zbg_sfx_dyn, zbg_sfx_sub 
-      real(wp)   ::   zbg_vfx, zbg_vfx_bog, zbg_vfx_opw, zbg_vfx_sni, zbg_vfx_dyn
-      real(wp)   ::   zbg_vfx_bom, zbg_vfx_sum, zbg_vfx_res, zbg_vfx_spr, zbg_vfx_snw, zbg_vfx_sub  
-      real(wp)   ::   zbg_hfx_dhc, zbg_hfx_spr
-      real(wp)   ::   zbg_hfx_res, zbg_hfx_sub, zbg_hfx_dyn, zbg_hfx_thd, zbg_hfx_snw, zbg_hfx_out, zbg_hfx_in   
-      real(wp)   ::   zbg_hfx_sum, zbg_hfx_bom, zbg_hfx_bog, zbg_hfx_dif, zbg_hfx_opw
-      real(wp)   ::   z_frc_vol, z_frc_sal, z_bg_grme 
-      real(wp)   ::   z1_area                     !    -     -
-      REAL(wp)   ::   ztmp
+      real(wp)   ::   zbg_ivol, zbg_svol, zbg_area, zbg_isal, zbg_item ,zbg_stem
+      REAL(wp)   ::   z_frc_voltop, z_frc_volbot, z_frc_sal, z_frc_temtop, z_frc_tembot  
+      REAL(wp)   ::   zdiff_vol, zdiff_sal, zdiff_tem  
       !!---------------------------------------------------------------------------
       IF( nn_timing == 1 )   CALL timing_start('lim_diahsb')
 
-      IF( numit == nstart ) CALL lim_diahsb_init 
-
-      ! 1/area
-      z1_area = 1._wp / MAX( glob_sum( e1e2t(:,:) * tmask(:,:,1) ), epsi06 )
-
-      rswitch = MAX( 0._wp , SIGN( 1._wp , glob_sum( e1e2t(:,:) * tmask(:,:,1) ) - epsi06 ) )
-      ! ----------------------- !
-      ! 1 -  Content variations !
-      ! ----------------------- !
-      zbg_ivo = glob_sum( vt_i(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! volume ice 
-      zbg_svo = glob_sum( vt_s(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! volume snow
-      zbg_are = glob_sum( at_i(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! area
-      zbg_sal = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * e1e2t(:,:) * tmask(:,:,1) )       ! mean salt content
-      zbg_tem = glob_sum( ( tm_i(:,:) - rt0 ) * vt_i(:,:) * e1e2t(:,:) * tmask(:,:,1) )  ! mean temp content
-
-      !zbg_ihc = glob_sum( et_i(:,:) * e1e2t(:,:) * tmask(:,:,1) ) / MAX( zbg_ivo,epsi06 ) ! ice heat content
-      !zbg_shc = glob_sum( et_s(:,:) * e1e2t(:,:) * tmask(:,:,1) ) / MAX( zbg_svo,epsi06 ) ! snow heat content
-
-      ! Volume
-      ztmp = rswitch * z1_area * r1_rau0 * rday
-      zbg_vfx     = ztmp * glob_sum(     emp(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_vfx_bog = ztmp * glob_sum( wfx_bog(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_vfx_opw = ztmp * glob_sum( wfx_opw(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_vfx_sni = ztmp * glob_sum( wfx_sni(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_vfx_dyn = ztmp * glob_sum( wfx_dyn(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_vfx_bom = ztmp * glob_sum( wfx_bom(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_vfx_sum = ztmp * glob_sum( wfx_sum(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_vfx_res = ztmp * glob_sum( wfx_res(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_vfx_spr = ztmp * glob_sum( wfx_spr(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_vfx_snw = ztmp * glob_sum( wfx_snw(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_vfx_sub = ztmp * glob_sum( wfx_sub(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-
-      ! Salt
-      zbg_sfx     = ztmp * glob_sum(     sfx(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_sfx_bri = ztmp * glob_sum( sfx_bri(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_sfx_res = ztmp * glob_sum( sfx_res(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_sfx_dyn = ztmp * glob_sum( sfx_dyn(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-
-      zbg_sfx_bog = ztmp * glob_sum( sfx_bog(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_sfx_opw = ztmp * glob_sum( sfx_opw(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_sfx_sni = ztmp * glob_sum( sfx_sni(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_sfx_bom = ztmp * glob_sum( sfx_bom(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_sfx_sum = ztmp * glob_sum( sfx_sum(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-      zbg_sfx_sub = ztmp * glob_sum( sfx_sub(:,:) * e1e2t(:,:) * tmask(:,:,1) )
-
-      ! Heat budget
-      zbg_ihc      = glob_sum( et_i(:,:) * e1e2t(:,:) * 1.e-20 ) ! ice heat content  [1.e20 J]
-      zbg_shc      = glob_sum( et_s(:,:) * e1e2t(:,:) * 1.e-20 ) ! snow heat content [1.e20 J]
-      zbg_hfx_dhc  = glob_sum( diag_heat(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-      zbg_hfx_spr  = glob_sum( hfx_spr(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-
-      zbg_hfx_thd  = glob_sum( hfx_thd(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-      zbg_hfx_dyn  = glob_sum( hfx_dyn(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-      zbg_hfx_res  = glob_sum( hfx_res(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-      zbg_hfx_sub  = glob_sum( hfx_sub(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-      zbg_hfx_snw  = glob_sum( hfx_snw(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-      zbg_hfx_sum  = glob_sum( hfx_sum(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-      zbg_hfx_bom  = glob_sum( hfx_bom(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-      zbg_hfx_bog  = glob_sum( hfx_bog(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-      zbg_hfx_dif  = glob_sum( hfx_dif(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-      zbg_hfx_opw  = glob_sum( hfx_opw(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-      zbg_hfx_out  = glob_sum( hfx_out(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-      zbg_hfx_in   = glob_sum(  hfx_in(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! [in W]
-    
-      ! --------------------------------------------- !
-      ! 2 - Trends due to forcing and ice growth/melt !
-      ! --------------------------------------------- !
-      z_frc_vol = r1_rau0 * glob_sum( - emp(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! volume fluxes
-      z_frc_sal = r1_rau0 * glob_sum(   sfx(:,:) * e1e2t(:,:) * tmask(:,:,1) ) ! salt fluxes
-      z_bg_grme = glob_sum( - ( wfx_bog(:,:) + wfx_opw(:,:) + wfx_sni(:,:) + wfx_dyn(:,:) + &
-                          &     wfx_bom(:,:) + wfx_sum(:,:) + wfx_res(:,:) + wfx_snw(:,:) + &
-                          &     wfx_sub(:,:) ) * e1e2t(:,:) * tmask(:,:,1) ) ! volume fluxes
-      !
-      frc_vol  = frc_vol  + z_frc_vol  * rdt_ice
-      frc_sal  = frc_sal  + z_frc_sal  * rdt_ice
-      bg_grme  = bg_grme  + z_bg_grme  * rdt_ice
+      ! ----------------------- !
+      ! 1 -  Contents !
+      ! ----------------------- !
+      zbg_ivol = glob_sum( vt_i(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )                  ! ice volume (km3)
+      zbg_svol = glob_sum( vt_s(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )                  ! snow volume (km3)
+      zbg_area = glob_sum( at_i(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-6 )                  ! area (km2)
+      zbg_isal = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 ) ! salt content (pss*km3)
+      zbg_item = glob_sum( et_i * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )                      ! heat content (1.e20 J)
+      zbg_stem = glob_sum( et_s * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )                      ! heat content (1.e20 J)
       
-      ! difference
-      !frc_vol = zbg_ivo - frc_vol
-      !frc_sal = zbg_sal - frc_sal
-      
-      ! ----------------------- !
-      ! 3 - Diagnostics writing !
-      ! ----------------------- !
-      rswitch = MAX( 0._wp , SIGN( 1._wp , zbg_ivo - epsi06 ) )
-      !
-      IF( iom_use('ibgvoltot') )   &
-      CALL iom_put( 'ibgvoltot' , zbg_ivo * rhoic * r1_rau0 * 1.e-9        )   ! ice volume (km3 equivalent liquid)         
-      IF( iom_use('sbgvoltot') )   &
-      CALL iom_put( 'sbgvoltot' , zbg_svo * rhosn * r1_rau0 * 1.e-9        )   ! snw volume (km3 equivalent liquid)       
-      IF( iom_use('ibgarea') )   &
-      CALL iom_put( 'ibgarea'   , zbg_are * 1.e-6                          )   ! ice area   (km2)
-      IF( iom_use('ibgsaline') )   &
-      CALL iom_put( 'ibgsaline' , rswitch * zbg_sal / MAX( zbg_ivo, epsi06 ) )   ! ice saline (psu)
-      IF( iom_use('ibgtemper') )   &
-      CALL iom_put( 'ibgtemper' , rswitch * zbg_tem / MAX( zbg_ivo, epsi06 ) )   ! ice temper (C)
-      CALL iom_put( 'ibgheatco' , zbg_ihc                                  )   ! ice heat content (1.e20 J)        
-      CALL iom_put( 'sbgheatco' , zbg_shc                                  )   ! snw heat content (1.e20 J)
-      IF( iom_use('ibgsaltco') )   &
-      CALL iom_put( 'ibgsaltco' , zbg_sal * rhoic * r1_rau0 * 1.e-9        )   ! ice salt content (psu*km3 equivalent liquid)        
-
-      CALL iom_put( 'ibgvfx'    , zbg_vfx                                  )   ! volume flux emp (m/day liquid)
-      CALL iom_put( 'ibgvfxbog' , zbg_vfx_bog                              )   ! volume flux bottom growth     -(m/day equivalent liquid)
-      CALL iom_put( 'ibgvfxopw' , zbg_vfx_opw                              )   ! volume flux open water growth -
-      CALL iom_put( 'ibgvfxsni' , zbg_vfx_sni                              )   ! volume flux snow ice growth   -
-      CALL iom_put( 'ibgvfxdyn' , zbg_vfx_dyn                              )   ! volume flux dynamic growth    -
-      CALL iom_put( 'ibgvfxbom' , zbg_vfx_bom                              )   ! volume flux bottom melt       -
-      CALL iom_put( 'ibgvfxsum' , zbg_vfx_sum                              )   ! volume flux surface melt      -
-      CALL iom_put( 'ibgvfxres' , zbg_vfx_res                              )   ! volume flux resultant         -
-      CALL iom_put( 'ibgvfxspr' , zbg_vfx_spr                              )   ! volume flux from snow precip         -
-      CALL iom_put( 'ibgvfxsnw' , zbg_vfx_snw                              )   ! volume flux from snow melt         -
-      CALL iom_put( 'ibgvfxsub' , zbg_vfx_sub                              )   ! volume flux from sublimation         -
-          
-      CALL iom_put( 'ibgsfx'    , zbg_sfx                                  )   ! salt flux         -(psu*m/day equivalent liquid)       
-      CALL iom_put( 'ibgsfxbri' , zbg_sfx_bri                              )   ! salt flux brines  -      
-      CALL iom_put( 'ibgsfxdyn' , zbg_sfx_dyn                              )   ! salt flux dynamic -    
-      CALL iom_put( 'ibgsfxres' , zbg_sfx_res                              )   ! salt flux result  -    
-      CALL iom_put( 'ibgsfxbog' , zbg_sfx_bog                              )   ! salt flux bottom growth   
-      CALL iom_put( 'ibgsfxopw' , zbg_sfx_opw                              )   ! salt flux open water growth -
-      CALL iom_put( 'ibgsfxsni' , zbg_sfx_sni                              )   ! salt flux snow ice growth   -
-      CALL iom_put( 'ibgsfxbom' , zbg_sfx_bom                              )   ! salt flux bottom melt       -
-      CALL iom_put( 'ibgsfxsum' , zbg_sfx_sum                              )   ! salt flux surface melt      -
-      CALL iom_put( 'ibgsfxsub' , zbg_sfx_sub                              )   ! salt flux sublimation      -
-
-      CALL iom_put( 'ibghfxdhc' , zbg_hfx_dhc                              )   ! Heat content variation in snow and ice [W]
-      CALL iom_put( 'ibghfxspr' , zbg_hfx_spr                              )   ! Heat content of snow precip [W]
-
-      CALL iom_put( 'ibghfxres' , zbg_hfx_res                              )   ! 
-      CALL iom_put( 'ibghfxsub' , zbg_hfx_sub                              )   ! 
-      CALL iom_put( 'ibghfxdyn' , zbg_hfx_dyn                              )   ! 
-      CALL iom_put( 'ibghfxthd' , zbg_hfx_thd                              )   ! 
-      CALL iom_put( 'ibghfxsnw' , zbg_hfx_snw                              )   ! 
-      CALL iom_put( 'ibghfxsum' , zbg_hfx_sum                              )   ! 
-      CALL iom_put( 'ibghfxbom' , zbg_hfx_bom                              )   ! 
-      CALL iom_put( 'ibghfxbog' , zbg_hfx_bog                              )   ! 
-      CALL iom_put( 'ibghfxdif' , zbg_hfx_dif                              )   ! 
-      CALL iom_put( 'ibghfxopw' , zbg_hfx_opw                              )   ! 
-      CALL iom_put( 'ibghfxout' , zbg_hfx_out                              )   ! 
-      CALL iom_put( 'ibghfxin'  , zbg_hfx_in                               )   ! 
-
-      CALL iom_put( 'ibgfrcvol' , frc_vol * 1.e-9                          )   ! vol - forcing     (km3 equivalent liquid) 
-      CALL iom_put( 'ibgfrcsfx' , frc_sal * 1.e-9                          )   ! sal - forcing     (psu*km3 equivalent liquid)   
-      IF( iom_use('ibgvolgrm') )   &
-      CALL iom_put( 'ibgvolgrm' , bg_grme * r1_rau0 * 1.e-9                )   ! vol growth + melt (km3 equivalent liquid)         
-
+      ! ---------------------------!
+      ! 2 - Trends due to forcing  !
+      ! ---------------------------!
+      z_frc_volbot = r1_rau0 * glob_sum( - ( wfx_ice(:,:) + wfx_snw(:,:) + wfx_err_sub(:,:) ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )  ! freshwater flux ice/snow-ocean 
+      z_frc_voltop = r1_rau0 * glob_sum( - ( wfx_sub(:,:) + wfx_spr(:,:) ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )                     ! freshwater flux ice/snow-atm
+      z_frc_sal    = r1_rau0 * glob_sum( - sfx(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )                                            ! salt fluxes ice/snow-ocean
+      z_frc_tembot =           glob_sum( hfx_out(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )                                         ! heat on top of ocean (and below ice)
+      z_frc_temtop =           glob_sum( hfx_in (:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )                                         ! heat on top of ice-coean
+      !
+      frc_voltop  = frc_voltop  + z_frc_voltop  * rdt_ice ! km3
+      frc_volbot  = frc_volbot  + z_frc_volbot  * rdt_ice ! km3
+      frc_sal     = frc_sal     + z_frc_sal     * rdt_ice ! km3*pss
+      frc_temtop  = frc_temtop  + z_frc_temtop  * rdt_ice ! 1.e20 J
+      frc_tembot  = frc_tembot  + z_frc_tembot  * rdt_ice ! 1.e20 J
+            
+      ! ----------------------- !
+      ! 3 -  Content variations !
+      ! ----------------------- !
+      zdiff_vol = r1_rau0 * glob_sum( ( rhoic * vt_i(:,:) + rhosn * vt_s(:,:) - vol_loc_ini(:,:)  &  ! freshwater trend (km3) 
+         &                            ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 ) 
+      zdiff_sal = r1_rau0 * glob_sum( ( rhoic * SUM( smv_i(:,:,:), dim=3 ) - sal_loc_ini(:,:)     &  ! salt content trend (km3*pss)
+         &                            ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )
+      zdiff_tem =           glob_sum( ( et_i(:,:) + et_s(:,:) - tem_loc_ini(:,:)                  &  ! heat content trend (1.e20 J)
+      !  &                            + SUM( qevap_ice * a_i_b, dim=3 ) &     !! clem: I think this line should be commented (but needs a check)
+         &                            ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )
+
+      ! ----------------------- !
+      ! 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 !
+      ! ----------------------- !
+      !
+      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' , zdiff_tem /      &   ! ice/snow heat flux drift          (W/m2)
+         &                                                    glob_sum( e1e2t(:,:) * tmask(:,:,1) * 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' , frc_temtop / & ! heat on top of ice/snw/ocean      (W/m2) 
+         &                                                    glob_sum( e1e2t(:,:) * tmask(:,:,1) * 1.e-20 * kt*rdt ) )
+      IF( iom_use('ibgfrchfxbot') )  CALL iom_put( 'ibgfrchfxbot' , frc_tembot / & ! heat on top of ocean(below ice)   (W/m2) 
+         &                                                    glob_sum( e1e2t(:,:) * tmask(:,:,1) * 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)
       !
       IF( lrst_ice )   CALL lim_diahsb_rst( numit, 'WRITE' )
       !
       IF( nn_timing == 1 )   CALL timing_stop('lim_diahsb')
-!
+      !
    END SUBROUTINE lim_diahsb
 
@@ -233,5 +150,4 @@
       !!             - Compute coefficients for conversion
       !!---------------------------------------------------------------------------
-      INTEGER            ::   jk       ! dummy loop indice
       INTEGER            ::   ierror   ! local integer
       !!
@@ -247,5 +163,11 @@
          WRITE(numout,*) '~~~~~~~~~~~~'
       ENDIF
-      !
+      !      
+      ALLOCATE( vol_loc_ini(jpi,jpj), sal_loc_ini(jpi,jpj), tem_loc_ini(jpi,jpj), STAT=ierror )
+      IF( ierror > 0 )  THEN
+         CALL ctl_stop( 'lim_diahsb: unable to allocate vol_loc_ini' )
+         RETURN
+      ENDIF
+
       CALL lim_diahsb_rst( nstart, 'READ' )  !* read or initialize all required files
       !
@@ -263,24 +185,35 @@
      CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
      !
-     INTEGER ::   id1, id2, id3   ! local integers
      !!----------------------------------------------------------------------
      !
      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
         IF( ln_rstart ) THEN                   !* Read the restart file
-           !id1 = iom_varid( numrir, 'frc_vol'  , ldstop = .TRUE. )
            !
            IF(lwp) WRITE(numout,*) '~~~~~~~'
-           IF(lwp) WRITE(numout,*) ' lim_diahsb_rst at it= ', kt,' date= ', ndastp
-           IF(lwp) WRITE(numout,*) '~~~~~~~'
-           CALL iom_get( numrir, 'frc_vol', frc_vol )
-           CALL iom_get( numrir, 'frc_sal', frc_sal )
-           CALL iom_get( numrir, 'bg_grme', bg_grme )
+           IF(lwp) WRITE(numout,*) ' lim_diahsb_rst read at it= ', kt,' date= ', ndastp
+           IF(lwp) WRITE(numout,*) '~~~~~~~'
+           CALL iom_get( numrir, 'frc_voltop' , frc_voltop  )
+           CALL iom_get( numrir, 'frc_volbot' , frc_volbot  )
+           CALL iom_get( numrir, 'frc_temtop' , frc_temtop  )
+           CALL iom_get( numrir, 'frc_tembot' , frc_tembot  )
+           CALL iom_get( numrir, 'frc_sal'    , frc_sal     )
+           CALL iom_get( numrir, jpdom_autoglo, 'vol_loc_ini', vol_loc_ini )
+           CALL iom_get( numrir, jpdom_autoglo, 'tem_loc_ini', tem_loc_ini )
+           CALL iom_get( numrir, jpdom_autoglo, 'sal_loc_ini', sal_loc_ini )
         ELSE
            IF(lwp) WRITE(numout,*) '~~~~~~~'
            IF(lwp) WRITE(numout,*) ' lim_diahsb at initial state '
            IF(lwp) WRITE(numout,*) '~~~~~~~'
-           frc_vol  = 0._wp                                          
-           frc_sal  = 0._wp                                                 
-           bg_grme  = 0._wp                                       
+           ! set trends to 0
+           frc_voltop  = 0._wp                                          
+           frc_volbot  = 0._wp                                          
+           frc_temtop  = 0._wp                                                 
+           frc_tembot  = 0._wp                                                 
+           frc_sal     = 0._wp                                                 
+           ! record initial ice volume, salt and temp
+           vol_loc_ini(:,:) = rhoic * vt_i(:,:) + rhosn * vt_s(:,:)  ! ice/snow volume (kg/m2)
+           tem_loc_ini(:,:) = et_i(:,:) + et_s(:,:)                  ! ice/snow heat content (J)
+           sal_loc_ini(:,:) = rhoic * SUM( smv_i(:,:,:), dim=3 )     ! ice salt content (pss*kg/m2)
+           
        ENDIF
 
@@ -288,9 +221,14 @@
         !                                   ! -------------------
         IF(lwp) WRITE(numout,*) '~~~~~~~'
-        IF(lwp) WRITE(numout,*) ' lim_diahsb_rst at it= ', kt,' date= ', ndastp
+        IF(lwp) WRITE(numout,*) ' lim_diahsb_rst write at it= ', kt,' date= ', ndastp
         IF(lwp) WRITE(numout,*) '~~~~~~~'
-        CALL iom_rstput( kt, nitrst, numriw, 'frc_vol'   , frc_vol     )
-        CALL iom_rstput( kt, nitrst, numriw, 'frc_sal'   , frc_sal     )
-        CALL iom_rstput( kt, nitrst, numriw, 'bg_grme'   , bg_grme     )
+        CALL iom_rstput( kt, nitrst, numriw, 'frc_voltop' , frc_voltop  )
+        CALL iom_rstput( kt, nitrst, numriw, 'frc_volbot' , frc_volbot  )
+        CALL iom_rstput( kt, nitrst, numriw, 'frc_temtop' , frc_temtop  )
+        CALL iom_rstput( kt, nitrst, numriw, 'frc_tembot' , frc_tembot  )
+        CALL iom_rstput( kt, nitrst, numriw, 'frc_sal'    , frc_sal     )
+        CALL iom_rstput( kt, nitrst, numriw, 'vol_loc_ini', vol_loc_ini )
+        CALL iom_rstput( kt, nitrst, numriw, 'tem_loc_ini', tem_loc_ini )
+        CALL iom_rstput( kt, nitrst, numriw, 'sal_loc_ini', sal_loc_ini )
         !
      ENDIF
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limdyn.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limdyn.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limdyn.F90	(revision 7309)
@@ -17,8 +17,6 @@
    USE phycst           ! physical constants
    USE dom_oce          ! ocean space and time domain
-   USE sbc_oce          ! Surface boundary condition: ocean fields
    USE sbc_ice          ! Surface boundary condition: ice   fields
    USE ice              ! LIM-3 variables
-   USE dom_ice          ! LIM-3 domain
    USE limrhg           ! LIM-3 rheology
    USE lbclnk           ! lateral boundary conditions - MPP exchanges
@@ -26,8 +24,8 @@
    USE wrk_nemo         ! work arrays
    USE in_out_manager   ! I/O manager
-   USE prtctl           ! Print control
    USE lib_fortran      ! glob_sum
-   USE timing          ! Timing
-   USE limcons        ! conservation tests
+   USE timing           ! Timing
+   USE limcons          ! conservation tests
+   USE limctl           ! control prints
    USE limvar
 
@@ -35,5 +33,6 @@
    PRIVATE
 
-   PUBLIC   lim_dyn   ! routine called by ice_step
+   PUBLIC   lim_dyn        ! routine called by sbcice_lim.F90
+   PUBLIC   lim_dyn_init   ! routine called by sbcice_lim.F90
 
    !! * Substitutions
@@ -50,5 +49,5 @@
       !!               ***  ROUTINE lim_dyn  ***
       !!               
-      !! ** Purpose :   compute ice velocity and ocean-ice stress
+      !! ** Purpose :   compute ice velocity
       !!                
       !! ** Method  : 
@@ -56,16 +55,8 @@
       !! ** Action  : - Initialisation
       !!              - Call of the dynamic routine for each hemisphere
-      !!              - computation of the stress at the ocean surface         
-      !!              - treatment of the case if no ice dynamic
       !!------------------------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt     ! number of iteration
       !!
-      INTEGER  ::   ji, jj, jl, ja    ! dummy loop indices
-      INTEGER  ::   i_j1, i_jpj       ! Starting/ending j-indices for rheology
-      REAL(wp) ::   zcoef             ! local scalar
-      REAL(wp), POINTER, DIMENSION(:)   ::   zswitch        ! i-averaged indicator of sea-ice
-      REAL(wp), POINTER, DIMENSION(:)   ::   zmsk           ! i-averaged of tmask
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zu_io, zv_io   ! ice-ocean velocity
-      !
+      INTEGER  :: jl, jk ! dummy loop indices
       REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
      !!---------------------------------------------------------------------
@@ -73,155 +64,30 @@
       IF( nn_timing == 1 )  CALL timing_start('limdyn')
 
-      CALL wrk_alloc( jpi, jpj, zu_io, zv_io )
-      CALL wrk_alloc( jpj, zswitch, zmsk )
-
-      CALL lim_var_agg(1)             ! aggregate ice categories
-
-      IF( kt == nit000 )   CALL lim_dyn_init   ! Initialization (first time-step only)
-
-      IF( ln_limdyn ) THEN
-         !
-         ! conservation test
-         IF( ln_limdiahsb ) CALL lim_cons_hsm(0, 'limdyn', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-         u_ice_b(:,:) = u_ice(:,:) * umask(:,:,1)
-         v_ice_b(:,:) = v_ice(:,:) * vmask(:,:,1)
-
-         ! Rheology (ice dynamics)
-         ! ========
-
-         !  Define the j-limits where ice rheology is computed
-         ! ---------------------------------------------------
-
-         IF( lk_mpp .OR. lk_mpp_rep ) THEN                    ! mpp: compute over the whole domain
-            i_j1 = 1
-            i_jpj = jpj
-            IF(ln_ctl) CALL prt_ctl_info( 'lim_dyn  :    i_j1 = ', ivar1=i_j1, clinfo2=' ij_jpj = ', ivar2=i_jpj )
-            CALL lim_rhg( i_j1, i_jpj )
-         ELSE                                 ! optimization of the computational area
-            !
-            DO jj = 1, jpj
-               zswitch(jj) = SUM( 1.0 - at_i(:,jj) )   ! = REAL(jpj) if ocean everywhere on a j-line
-               zmsk   (jj) = SUM( tmask(:,jj,1)    )   ! = 0         if land  everywhere on a j-line
-            END DO
-
-            IF( l_jeq ) THEN                     ! local domain include both hemisphere
-               !                                 ! Rheology is computed in each hemisphere
-               !                                 ! only over the ice cover latitude strip
-               ! Northern hemisphere
-               i_j1  = njeq
-               i_jpj = jpj
-               DO WHILE ( i_j1 <= jpj .AND. zswitch(i_j1) == FLOAT(jpi) .AND. zmsk(i_j1) /=0 )
-                  i_j1 = i_j1 + 1
-               END DO
-               i_j1 = MAX( 1, i_j1-2 )
-               IF(ln_ctl) CALL prt_ctl_info( 'lim_dyn  : NH  i_j1 = ', ivar1=i_j1, clinfo2=' ij_jpj = ', ivar2=i_jpj )
-               CALL lim_rhg( i_j1, i_jpj )
-               !
-               ! Southern hemisphere
-               i_j1  =  1
-               i_jpj = njeq
-               DO WHILE ( i_jpj >= 1 .AND. zswitch(i_jpj) == FLOAT(jpi) .AND. zmsk(i_jpj) /=0 )
-                  i_jpj = i_jpj - 1
-               END DO
-               i_jpj = MIN( jpj, i_jpj+1 )
-               IF(ln_ctl) CALL prt_ctl_info( 'lim_dyn  : SH  i_j1 = ', ivar1=i_j1, clinfo2=' ij_jpj = ', ivar2=i_jpj )
-               !
-               CALL lim_rhg( i_j1, i_jpj )
-               !
-            ELSE                                 ! local domain extends over one hemisphere only
-               !                                 ! Rheology is computed only over the ice cover
-               !                                 ! latitude strip
-               i_j1  = 1
-               DO WHILE ( i_j1 <= jpj .AND. zswitch(i_j1) == FLOAT(jpi) .AND. zmsk(i_j1) /=0 )
-                  i_j1 = i_j1 + 1
-               END DO
-               i_j1 = MAX( 1, i_j1-2 )
-
-               i_jpj  = jpj
-               DO WHILE ( i_jpj >= 1  .AND. zswitch(i_jpj) == FLOAT(jpi) .AND. zmsk(i_jpj) /=0 )
-                  i_jpj = i_jpj - 1
-               END DO
-               i_jpj = MIN( jpj, i_jpj+1)
-               !
-               IF(ln_ctl) CALL prt_ctl_info( 'lim_dyn  : one hemisphere:  i_j1 = ', ivar1=i_j1, clinfo2=' ij_jpj = ', ivar2=i_jpj )
-               !
-               CALL lim_rhg( i_j1, i_jpj )
-               !
-            ENDIF
-            !
-         ENDIF
-
-         ! computation of friction velocity
-         ! --------------------------------
-         ! ice-ocean velocity at U & V-points (u_ice v_ice at U- & V-points ; ssu_m, ssv_m at U- & V-points)
-         zu_io(:,:) = u_ice(:,:) - ssu_m(:,:)
-         zv_io(:,:) = v_ice(:,:) - ssv_m(:,:)
-         ! frictional velocity at T-point
-         zcoef = 0.5_wp * rn_cio
-         DO jj = 2, jpjm1 
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ust2s(ji,jj) = zcoef * (  zu_io(ji,jj) * zu_io(ji,jj) + zu_io(ji-1,jj) * zu_io(ji-1,jj)   &
-                  &                    + zv_io(ji,jj) * zv_io(ji,jj) + zv_io(ji,jj-1) * zv_io(ji,jj-1) ) * tmask(ji,jj,1)
-            END DO
-         END DO
-         !
-         ! conservation test
-         IF( ln_limdiahsb ) CALL lim_cons_hsm(1, 'limdyn', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-         !
-      ELSE      ! no ice dynamics : transmit directly the atmospheric stress to the ocean
-         !
-         zcoef = SQRT( 0.5_wp ) * r1_rau0
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ust2s(ji,jj) = zcoef * SQRT(  utau(ji,jj) * utau(ji,jj) + utau(ji-1,jj) * utau(ji-1,jj)   &
-                  &                        + vtau(ji,jj) * vtau(ji,jj) + vtau(ji,jj-1) * vtau(ji,jj-1) ) * tmask(ji,jj,1)
-            END DO
-         END DO
-         !
-      ENDIF
-      CALL lbc_lnk( ust2s, 'T',  1. )   ! T-point
-
-      IF(ln_ctl) THEN   ! Control print
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Cell values : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=ust2s     , clinfo1=' lim_dyn  : ust2s     :')
-         CALL prt_ctl(tab2d_1=divu_i    , clinfo1=' lim_dyn  : divu_i    :')
-         CALL prt_ctl(tab2d_1=delta_i   , clinfo1=' lim_dyn  : delta_i   :')
-         CALL prt_ctl(tab2d_1=strength  , clinfo1=' lim_dyn  : strength  :')
-         CALL prt_ctl(tab2d_1=e1e2t     , clinfo1=' lim_dyn  : cell area :')
-         CALL prt_ctl(tab2d_1=at_i      , clinfo1=' lim_dyn  : at_i      :')
-         CALL prt_ctl(tab2d_1=vt_i      , clinfo1=' lim_dyn  : vt_i      :')
-         CALL prt_ctl(tab2d_1=vt_s      , clinfo1=' lim_dyn  : vt_s      :')
-         CALL prt_ctl(tab2d_1=stress1_i , clinfo1=' lim_dyn  : stress1_i :')
-         CALL prt_ctl(tab2d_1=stress2_i , clinfo1=' lim_dyn  : stress2_i :')
-         CALL prt_ctl(tab2d_1=stress12_i, clinfo1=' lim_dyn  : stress12_i:')
+      CALL lim_var_agg(1)                      ! aggregate ice categories
+      !
+      ! conservation test
+      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limdyn', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      
+      ! ice velocities before rheology
+      u_ice_b(:,:) = u_ice(:,:) * umask(:,:,1)
+      v_ice_b(:,:) = v_ice(:,:) * vmask(:,:,1)
+      
+      ! Landfast ice parameterization: define max bottom friction
+      tau_icebfr(:,:) = 0._wp
+      IF( ln_landfast ) THEN
          DO jl = 1, jpl
-            CALL prt_ctl_info(' ')
-            CALL prt_ctl_info(' - Category : ', ivar1=jl)
-            CALL prt_ctl_info('   ~~~~~~~~~~')
-            CALL prt_ctl(tab2d_1=a_i   (:,:,jl)   , clinfo1= ' lim_dyn  : a_i      : ')
-            CALL prt_ctl(tab2d_1=ht_i  (:,:,jl)   , clinfo1= ' lim_dyn  : ht_i     : ')
-            CALL prt_ctl(tab2d_1=ht_s  (:,:,jl)   , clinfo1= ' lim_dyn  : ht_s     : ')
-            CALL prt_ctl(tab2d_1=v_i   (:,:,jl)   , clinfo1= ' lim_dyn  : v_i      : ')
-            CALL prt_ctl(tab2d_1=v_s   (:,:,jl)   , clinfo1= ' lim_dyn  : v_s      : ')
-            CALL prt_ctl(tab2d_1=e_s   (:,:,1,jl) , clinfo1= ' lim_dyn  : e_s      : ')
-            CALL prt_ctl(tab2d_1=t_su  (:,:,jl)   , clinfo1= ' lim_dyn  : t_su     : ')
-            CALL prt_ctl(tab2d_1=t_s   (:,:,1,jl) , clinfo1= ' lim_dyn  : t_snow   : ')
-            CALL prt_ctl(tab2d_1=sm_i  (:,:,jl)   , clinfo1= ' lim_dyn  : sm_i     : ')
-            CALL prt_ctl(tab2d_1=smv_i (:,:,jl)   , clinfo1= ' lim_dyn  : smv_i    : ')
-            DO ja = 1, nlay_i
-               CALL prt_ctl_info(' ')
-               CALL prt_ctl_info(' - Layer : ', ivar1=ja)
-               CALL prt_ctl_info('   ~~~~~~~')
-               CALL prt_ctl(tab2d_1=t_i(:,:,ja,jl) , clinfo1= ' lim_dyn  : t_i      : ')
-               CALL prt_ctl(tab2d_1=e_i(:,:,ja,jl) , clinfo1= ' lim_dyn  : e_i      : ')
-            END DO
+            WHERE( ht_i(:,:,jl) > ht(:,:) * rn_gamma )  tau_icebfr(:,:) = tau_icebfr(:,:) + a_i(:,:,jl) * rn_icebfr
          END DO
       ENDIF
+      
+      ! Rheology (ice dynamics)
+      ! ========     
+      CALL lim_rhg
       !
-      CALL wrk_dealloc( jpi, jpj, zu_io, zv_io )
-      CALL wrk_dealloc( jpj, zswitch, zmsk )
+      ! conservation test
+      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limdyn', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      ! Control prints
+      IF( ln_ctl )       CALL lim_prt3D( 'limdyn' )
       !
       IF( nn_timing == 1 )  CALL timing_stop('limdyn')
@@ -243,8 +109,7 @@
       !!-------------------------------------------------------------------
       INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicedyn/ nn_icestr, ln_icestr_bvf, rn_pe_rdg, rn_pstar, rn_crhg, rn_cio,  rn_creepl, rn_ecc, &
-         &                nn_nevp, rn_relast, nn_ahi0, rn_ahi0_ref
-      INTEGER  ::   ji, jj
-      REAL(wp) ::   za00, zd_max
+      NAMELIST/namicedyn/ nn_limadv, nn_limadv_ord,  &
+         &                nn_icestr, ln_icestr_bvf, rn_pe_rdg, rn_pstar, rn_crhg, rn_cio, rn_creepl, rn_ecc, &
+         &                nn_nevp, rn_relast, ln_landfast, rn_gamma, rn_icebfr, rn_lfrelax
       !!-------------------------------------------------------------------
 
@@ -262,64 +127,24 @@
          WRITE(numout,*) 'lim_dyn_init : ice parameters for ice dynamics '
          WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*)'    ice strength parameterization (0=Hibler 1=Rothrock)  nn_icestr     = ', nn_icestr 
-         WRITE(numout,*)'    Including brine volume in ice strength comp.         ln_icestr_bvf = ', ln_icestr_bvf
-         WRITE(numout,*)'   Ratio of ridging work to PotEner change in ridging    rn_pe_rdg     = ', rn_pe_rdg 
-         WRITE(numout,*) '   drag coefficient for oceanic stress                  rn_cio        = ', rn_cio
-         WRITE(numout,*) '   first bulk-rheology parameter                        rn_pstar      = ', rn_pstar
-         WRITE(numout,*) '   second bulk-rhelogy parameter                        rn_crhg       = ', rn_crhg
-         WRITE(numout,*) '   creep limit                                          rn_creepl     = ', rn_creepl
-         WRITE(numout,*) '   eccentricity of the elliptical yield curve           rn_ecc        = ', rn_ecc
-         WRITE(numout,*) '   number of iterations for subcycling                  nn_nevp       = ', nn_nevp
-         WRITE(numout,*) '   ratio of elastic timescale over ice time step        rn_relast     = ', rn_relast
-         WRITE(numout,*) '   horizontal diffusivity calculation                   nn_ahi0       = ', nn_ahi0
-         WRITE(numout,*) '   horizontal diffusivity coeff. (orca2 grid)           rn_ahi0_ref   = ', rn_ahi0_ref
+         ! limtrp
+         WRITE(numout,*)'    choose the advection scheme (-1=Prather, 0=Ulimate-Macho)   nn_limadv     = ', nn_limadv 
+         WRITE(numout,*)'    choose the order of the scheme (if ultimate)                nn_limadv_ord = ', nn_limadv_ord  
+         ! limrhg
+         WRITE(numout,*)'    ice strength parameterization (0=Hibler 1=Rothrock)         nn_icestr     = ', nn_icestr 
+         WRITE(numout,*)'    Including brine volume in ice strength comp.                ln_icestr_bvf = ', ln_icestr_bvf
+         WRITE(numout,*)'    Ratio of ridging work to PotEner change in ridging          rn_pe_rdg     = ', rn_pe_rdg 
+         WRITE(numout,*) '   drag coefficient for oceanic stress                         rn_cio        = ', rn_cio
+         WRITE(numout,*) '   first bulk-rheology parameter                               rn_pstar      = ', rn_pstar
+         WRITE(numout,*) '   second bulk-rhelogy parameter                               rn_crhg       = ', rn_crhg
+         WRITE(numout,*) '   creep limit                                                 rn_creepl     = ', rn_creepl
+         WRITE(numout,*) '   eccentricity of the elliptical yield curve                  rn_ecc        = ', rn_ecc
+         WRITE(numout,*) '   number of iterations for subcycling                         nn_nevp       = ', nn_nevp
+         WRITE(numout,*) '   ratio of elastic timescale over ice time step               rn_relast     = ', rn_relast
+         WRITE(numout,*) '   Landfast: param (T or F)                                    ln_landfast   = ', ln_landfast
+         WRITE(numout,*) '   Landfast: fraction of ocean depth that ice must reach       rn_gamma      = ', rn_gamma
+         WRITE(numout,*) '   Landfast: maximum bottom stress per unit area of contact    rn_icebfr     = ', rn_icebfr
+         WRITE(numout,*) '   Landfast: relax time scale (s-1) to reach static friction   rn_lfrelax    = ', rn_lfrelax
       ENDIF
       !
-      usecc2 = 1._wp / ( rn_ecc * rn_ecc )
-      rhoco  = rau0  * rn_cio
-      !
-      !  Diffusion coefficients
-      SELECT CASE( nn_ahi0 )
-
-      CASE( 0 )
-         ahiu(:,:) = rn_ahi0_ref
-         ahiv(:,:) = rn_ahi0_ref
-
-         IF(lwp) WRITE(numout,*) ''
-         IF(lwp) WRITE(numout,*) '   laplacian operator: ahim constant = rn_ahi0_ref'
-
-      CASE( 1 ) 
-
-         zd_max = MAX( MAXVAL( e1t(:,:) ), MAXVAL( e2t(:,:) ) )
-         IF( lk_mpp )   CALL mpp_max( zd_max )          ! max over the global domain
-         
-         ahiu(:,:) = rn_ahi0_ref * zd_max * 1.e-05_wp   ! 1.e05 = 100km = max grid space at 60° latitude in orca2
-                                                        !                    (60° = min latitude for ice cover)  
-         ahiv(:,:) = rn_ahi0_ref * zd_max * 1.e-05_wp
-
-         IF(lwp) WRITE(numout,*) ''
-         IF(lwp) WRITE(numout,*) '   laplacian operator: ahim proportional to max of e1 e2 over the domain (', zd_max, ')'
-         IF(lwp) WRITE(numout,*) '   value for ahim = ', rn_ahi0_ref * zd_max * 1.e-05_wp 
-         
-      CASE( 2 ) 
-
-         zd_max = MAX( MAXVAL( e1t(:,:) ), MAXVAL( e2t(:,:) ) )
-         IF( lk_mpp )   CALL mpp_max( zd_max )   ! max over the global domain
-         
-         za00 = rn_ahi0_ref * 1.e-05_wp          ! 1.e05 = 100km = max grid space at 60° latitude in orca2
-                                                 !                    (60° = min latitude for ice cover)  
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ahiu(ji,jj) = za00 * MAX( e1t(ji,jj), e2t(ji,jj) ) * umask(ji,jj,1)
-               ahiv(ji,jj) = za00 * MAX( e1f(ji,jj), e2f(ji,jj) ) * vmask(ji,jj,1)
-            END DO
-         END DO
-         !
-         IF(lwp) WRITE(numout,*) ''
-         IF(lwp) WRITE(numout,*) '   laplacian operator: ahim proportional to e1'
-         IF(lwp) WRITE(numout,*) '   maximum grid-spacing = ', zd_max, ' maximum value for ahim = ', za00*zd_max
-         
-      END SELECT
-
    END SUBROUTINE lim_dyn_init
 
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limhdf.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limhdf.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limhdf.F90	(revision 7309)
@@ -7,5 +7,5 @@
    !!             -   !  2001-05 (G. Madec, R. Hordoir) opa norm
    !!            1.0  !  2002-08 (C. Ethe)  F90, free form
-   !!            3.0  !  2015-08 (O. Tintó and M. Castrillo)  added lim_hdf (multiple)
+   !!            3.6  !  2015-08 (O. Tintó and M. Castrillo)  added lim_hdf (multiple)
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -28,9 +28,8 @@
    PRIVATE
 
-   PUBLIC   lim_hdf ! called by lim_trp
+   PUBLIC   lim_hdf         ! called by lim_trp
    PUBLIC   lim_hdf_init    ! called by sbc_lim_init
 
    LOGICAL  ::   linit = .TRUE.                             ! initialization flag (set to flase after the 1st call)
-   INTEGER  ::   nn_convfrq                                 !:  convergence check frequency of the Crant-Nicholson scheme
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   efact   ! metric coefficient
 
@@ -44,5 +43,5 @@
 CONTAINS
 
-   SUBROUTINE lim_hdf( ptab , ihdf_vars , jpl , nlay_i )
+   SUBROUTINE lim_hdf( ptab, ihdf_vars )
       !!-------------------------------------------------------------------
       !!                  ***  ROUTINE lim_hdf  ***
@@ -55,41 +54,41 @@
       !! ** Action  :    update ptab with the diffusive contribution
       !!-------------------------------------------------------------------
-      INTEGER                           :: jpl, nlay_i, isize, ihdf_vars
-      REAL(wp),  DIMENSION(:,:,:), INTENT( inout ),TARGET ::   ptab    ! Field on which the diffusion is applied
-      !
-      INTEGER                           ::  ji, jj, jk, jl , jm               ! dummy loop indices
-      INTEGER                           ::  iter, ierr           ! local integers
-      REAL(wp)                          ::  zrlxint     ! local scalars
-      REAL(wp), POINTER , DIMENSION ( : )        :: zconv     ! local scalars
-      REAL(wp), POINTER , DIMENSION(:,:,:) ::  zrlx,zdiv0, ztab0
-      REAL(wp), POINTER , DIMENSION(:,:) ::  zflu, zflv, zdiv
-      CHARACTER(lc)                     ::  charout                   ! local character
-      REAL(wp), PARAMETER               ::  zrelax = 0.5_wp           ! relaxation constant for iterative procedure
-      REAL(wp), PARAMETER               ::  zalfa  = 0.5_wp           ! =1.0/0.5/0.0 = implicit/Cranck-Nicholson/explicit
-      INTEGER , PARAMETER               ::  its    = 100              ! Maximum number of iteration
+      INTEGER,                    INTENT( in )            ::  ihdf_vars ! number of fields to diffuse
+      REAL(wp), DIMENSION(:,:,:), INTENT( inout ), TARGET ::  ptab      ! Field on which the diffusion is applied
+      !
+      INTEGER                             ::  ji, jj, jk, jl, jm        ! dummy loop indices
+      INTEGER                             ::  iter, ierr, isize         ! local integers
+      REAL(wp)                            ::  zrlxint
+      CHARACTER(lc)                       ::  charout                   ! local character
+      REAL(wp), PARAMETER                 ::  zrelax = 0.5_wp           ! relaxation constant for iterative procedure
+      REAL(wp), PARAMETER                 ::  zalfa  = 0.5_wp           ! =1.0/0.5/0.0 = implicit/Cranck-Nicholson/explicit
+      INTEGER , PARAMETER                 ::  num_iter_max = 100        ! Maximum number of iteration
+      INTEGER , PARAMETER                 ::  num_convfrq  = 5          ! convergence check frequency of the Crant-Nicholson scheme (perf. optimization)
+      REAL(wp), POINTER, DIMENSION(:)     ::  zconv
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zrlx, zdiv0, ztab0
+      REAL(wp), POINTER, DIMENSION(:,:)   ::  zflu, zflv, zdiv
       !!-------------------------------------------------------------------
       TYPE(arrayptr)   , ALLOCATABLE, DIMENSION(:) ::   pt2d_array, zrlx_array
-      CHARACTER(len=1) , ALLOCATABLE, DIMENSION(:) ::   type_array ! define the nature of ptab array grid-points
-      !                                                            ! = T , U , V , F , W and I points
-      REAL(wp)        , ALLOCATABLE, DIMENSION(:)  ::   psgn_array    ! =-1 the sign change across the north fold boundary
-
-     !!--------------------------------------------------------------------- 
-
+      CHARACTER(len=1) , ALLOCATABLE, DIMENSION(:) ::   type_array      ! define the nature of ptab array grid-points
+      !                                                                 ! = T , U , V , F , W and I points
+      REAL(wp)         , ALLOCATABLE, DIMENSION(:) ::   psgn_array      ! =-1 the sign change across the north fold boundary
+      !!-------------------------------------------------------------------
+      
       !                       !==  Initialisation  ==!
       ! +1 open water diffusion
-      isize = jpl*(ihdf_vars+nlay_i)+1
+      isize = jpl * ( ihdf_vars + nlay_i ) + 1
       ALLOCATE( zconv (isize) )
       ALLOCATE( pt2d_array(isize) , zrlx_array(isize) )
       ALLOCATE( type_array(isize) )
       ALLOCATE( psgn_array(isize) )
+
+      CALL wrk_alloc( jpi,jpj,       zflu, zflv, zdiv )
+      CALL wrk_alloc( jpi,jpj,isize, zrlx, zdiv0, ztab0 )
       
-      CALL wrk_alloc( jpi, jpj, isize, zrlx, zdiv0, ztab0 )
-      CALL wrk_alloc( jpi, jpj, zflu, zflv, zdiv )
-
-      DO jk= 1 , isize
-         pt2d_array(jk)%pt2d=>ptab(:,:,jk)
-         zrlx_array(jk)%pt2d=>zrlx(:,:,jk)
-         type_array(jk)='T'
-         psgn_array(jk)=1.
+      DO jk= 1, isize
+         pt2d_array(jk)%pt2d => ptab(:,:,jk)
+         zrlx_array(jk)%pt2d => zrlx(:,:,jk)
+         type_array(jk) = 'T'
+         psgn_array(jk) = 1.
       END DO
 
@@ -99,5 +98,5 @@
          IF( lk_mpp    )   CALL mpp_sum( ierr )
          IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'lim_hdf : unable to allocate arrays' )
-         DO jj = 2, jpjm1
+         DO jj = 2, jpjm1  
             DO ji = fs_2 , fs_jpim1   ! vector opt.
                efact(ji,jj) = ( e2u(ji,jj) + e2u(ji-1,jj) + e1v(ji,jj) + e1v(ji,jj-1) ) * r1_e1e2t(ji,jj)
@@ -106,11 +105,10 @@
          linit = .FALSE.
       ENDIF
-      !                             ! Time integration parameters
-      !
-      zflu (jpi,: ) = 0._wp
-      zflv (jpi,: ) = 0._wp
-
+      !
+      ! Arrays initialization
+      zflu(jpi,:) = 0._wp   
+      zflv(jpi,:) = 0._wp
       DO jk=1 , isize
-         ztab0(:, : , jk ) = ptab(:,:,jk)      ! Arrays initialization
+         ztab0(:, : , jk ) = ptab(:,:,jk)
          zdiv0(:, 1 , jk ) = 0._wp
          zdiv0(:,jpj, jk ) = 0._wp
@@ -119,14 +117,15 @@
       END DO
 
-      zconv = 1._wp           !==  horizontal diffusion using a Crant-Nicholson scheme  ==!
-      iter  = 0
-      !
-      DO WHILE( MAXVAL(zconv(:)) > ( 2._wp * 1.e-04 ) .AND. iter <= its )   ! Sub-time step loop
+      !                !==  horizontal diffusion using a Crant-Nicholson scheme  ==!
+      zconv(:) = 1._wp
+      iter     = 0
+      !
+      DO WHILE( MAXVAL( zconv(:) ) > ( 2._wp * 1.e-04 ) .AND. iter <= num_iter_max )   ! Sub-time step loop
          !
          iter = iter + 1                                 ! incrementation of the sub-time step number
          !
          DO jk = 1 , isize
-            jl = (jk-1) /( ihdf_vars+nlay_i)+1
-            IF (zconv(jk) > ( 2._wp * 1.e-04 )) THEN
+            jl = ( jk - 1 ) / ( ihdf_vars + nlay_i ) + 1
+            IF ( zconv(jk) > ( 2._wp * 1.e-04 ) ) THEN
                DO jj = 1, jpjm1                                ! diffusive fluxes in U- and V- direction
                   DO ji = 1 , fs_jpim1   ! vector opt.
@@ -159,6 +158,7 @@
          CALL lbc_lnk_multi( zrlx_array, type_array , psgn_array , isize ) ! Multiple interchange of all the variables
          !
-         IF ( MOD( iter-1 , nn_convfrq ) == 0 )  THEN   !Convergence test every nn_convfrq iterations (perf. optimization ) 
-            DO jk=1,isize
+
+         IF ( MOD( iter-1 , num_convfrq ) == 0 )  THEN   ! Convergence test every num_convfrq iterations (perf. optimization ) 
+            DO jk = 1, isize
                zconv(jk) = 0._wp                                   ! convergence test
                DO jj = 2, jpjm1
@@ -175,10 +175,9 @@
          END DO
          !
-      END DO                                       ! end of sub-time step loop
-
-     ! -----------------------
-      !!! final step (clem) !!!
+      END DO  ! end of sub-time step loop
+
+     ! --- final step --- !
       DO jk = 1, isize
-         jl = (jk-1) /( ihdf_vars+nlay_i)+1
+         jl = ( jk - 1 ) / ( ihdf_vars + nlay_i ) + 1
          DO jj = 1, jpjm1                                ! diffusive fluxes in U- and V- direction
             DO ji = 1 , fs_jpim1   ! vector opt.
@@ -198,7 +197,5 @@
       CALL lbc_lnk_multi( pt2d_array, type_array , psgn_array , isize ) ! Multiple interchange of all the variables
 
-      !!! final step (clem) !!!
-      ! -----------------------
-
+      !
       IF(ln_ctl)   THEN
          DO jk = 1 , isize
@@ -209,7 +206,7 @@
       ENDIF
       !
-      CALL wrk_dealloc( jpi, jpj, isize, zrlx, zdiv0, ztab0 )
-      CALL wrk_dealloc( jpi, jpj, zflu, zflv, zdiv )
-
+      CALL wrk_dealloc( jpi,jpj,       zflu, zflv, zdiv )
+      CALL wrk_dealloc( jpi,jpj,isize, zrlx, zdiv0, ztab0 )
+      !
       DEALLOCATE( zconv )
       DEALLOCATE( pt2d_array , zrlx_array )
@@ -219,5 +216,4 @@
    END SUBROUTINE lim_hdf
 
-
    
    SUBROUTINE lim_hdf_init
@@ -232,12 +228,8 @@
       !!-------------------------------------------------------------------
       INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicehdf/ nn_convfrq 
-      !!-------------------------------------------------------------------
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_hdf : Ice horizontal diffusion'
-         WRITE(numout,*) '~~~~~~~'
-      ENDIF
+      NAMELIST/namicehdf/ nn_ahi0, rn_ahi0_ref
+      INTEGER  ::   ji, jj
+      REAL(wp) ::   za00, zd_max
+      !!-------------------------------------------------------------------
       !
       REWIND( numnam_ice_ref )              ! Namelist namicehdf in reference namelist : Ice horizontal diffusion
@@ -252,7 +244,52 @@
       IF(lwp) THEN                          ! control print
          WRITE(numout,*)
-         WRITE(numout,*)'   Namelist of ice parameters for ice horizontal diffusion computation '
-         WRITE(numout,*)'      convergence check frequency of the Crant-Nicholson scheme   nn_convfrq   = ', nn_convfrq
+         WRITE(numout,*) 'lim_hdf_init : Ice horizontal diffusion'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '   horizontal diffusivity calculation                          nn_ahi0      = ', nn_ahi0
+         WRITE(numout,*) '   horizontal diffusivity coeff. (orca2 grid)                  rn_ahi0_ref  = ', rn_ahi0_ref
       ENDIF
+      !
+      !  Diffusion coefficients
+      SELECT CASE( nn_ahi0 )
+
+      CASE( 0 )
+         ahiu(:,:) = rn_ahi0_ref
+         ahiv(:,:) = rn_ahi0_ref
+
+         IF(lwp) WRITE(numout,*) ''
+         IF(lwp) WRITE(numout,*) '   laplacian operator: ahim constant = rn_ahi0_ref'
+
+      CASE( 1 ) 
+
+         zd_max = MAX( MAXVAL( e1t(:,:) ), MAXVAL( e2t(:,:) ) )
+         IF( lk_mpp )   CALL mpp_max( zd_max )          ! max over the global domain
+         
+         ahiu(:,:) = rn_ahi0_ref * zd_max * 1.e-05_wp   ! 1.e05 = 100km = max grid space at 60deg latitude in orca2
+                                                        !                    (60deg = min latitude for ice cover)  
+         ahiv(:,:) = rn_ahi0_ref * zd_max * 1.e-05_wp
+
+         IF(lwp) WRITE(numout,*) ''
+         IF(lwp) WRITE(numout,*) '   laplacian operator: ahim proportional to max of e1 e2 over the domain (', zd_max, ')'
+         IF(lwp) WRITE(numout,*) '   value for ahim = ', rn_ahi0_ref * zd_max * 1.e-05_wp 
+         
+      CASE( 2 ) 
+
+         zd_max = MAX( MAXVAL( e1t(:,:) ), MAXVAL( e2t(:,:) ) )
+         IF( lk_mpp )   CALL mpp_max( zd_max )   ! max over the global domain
+         
+         za00 = rn_ahi0_ref * 1.e-05_wp          ! 1.e05 = 100km = max grid space at 60deg latitude in orca2
+                                                 !                    (60deg = min latitude for ice cover)  
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ahiu(ji,jj) = za00 * MAX( e1t(ji,jj), e2t(ji,jj) ) * umask(ji,jj,1)
+               ahiv(ji,jj) = za00 * MAX( e1f(ji,jj), e2f(ji,jj) ) * vmask(ji,jj,1)
+            END DO
+         END DO
+         !
+         IF(lwp) WRITE(numout,*) ''
+         IF(lwp) WRITE(numout,*) '   laplacian operator: ahim proportional to e1'
+         IF(lwp) WRITE(numout,*) '   maximum grid-spacing = ', zd_max, ' maximum value for ahim = ', za00*zd_max
+         
+      END SELECT
       !
    END SUBROUTINE lim_hdf_init
@@ -265,3 +302,2 @@
    !!======================================================================
 END MODULE limhdf
-
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 7309)
@@ -23,5 +23,4 @@
    USE ice              ! sea-ice variables
    USE par_oce          ! ocean parameters
-   USE dom_ice          ! sea-ice domain
    USE limvar           ! lim_var_salprof
    USE in_out_manager   ! I/O manager
@@ -37,17 +36,4 @@
    PUBLIC   lim_istate      ! routine called by lim_init.F90
 
-   !                          !!** init namelist (namiceini) **
-   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
-
    INTEGER , PARAMETER ::   jpfldi = 6           ! maximum number of files to read
    INTEGER , PARAMETER ::   jp_hti = 1           ! index of ice thickness (m)    at T-point
@@ -57,8 +43,5 @@
    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)
-
-   LOGICAL  ::  ln_iceini        ! initialization or not
-   LOGICAL  ::  ln_iceini_file   ! Ice initialization state from 2D netcdf file
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   si  ! structure of input fields (file informations, fields read)
    !!----------------------------------------------------------------------
    !!   LIM 3.0,  UCL-LOCEAN-IPSL (2008)
@@ -101,14 +84,16 @@
       REAL(wp)   :: ztmelts, zdh
       INTEGER    :: i_hemis, i_fill, jl0  
-      REAL(wp)   :: ztest_1, ztest_2, ztest_3, ztest_4, ztests, zsigma, zarg, zA, zV, zA_cons, zV_cons, zconv 
+      REAL(wp)   :: zarg, zV, zconv, zdv 
       REAL(wp), POINTER, DIMENSION(:,:)   :: zswitch    ! ice indicator
       REAL(wp), POINTER, DIMENSION(:,:)   :: zht_i_ini, zat_i_ini, zvt_i_ini            !data from namelist or nc file
       REAL(wp), POINTER, DIMENSION(:,:)   :: zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini !data from namelist or nc file
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zh_i_ini, za_i_ini, zv_i_ini               !data by cattegories to fill
-      !--------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, jpl, zh_i_ini,  za_i_ini,  zv_i_ini )
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zh_i_ini, za_i_ini                         !data by cattegories to fill
+      INTEGER , POINTER, DIMENSION(:)     :: itest
+      !--------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, jpl, zh_i_ini,  za_i_ini )
       CALL wrk_alloc( jpi, jpj,      zht_i_ini, zat_i_ini, zvt_i_ini, zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini )
       CALL wrk_alloc( jpi, jpj,      zswitch )
+      Call wrk_alloc( 4,             itest )
 
       IF(lwp) WRITE(numout,*)
@@ -119,38 +104,23 @@
       ! 1) Read namelist
       !--------------------------------------------------------------------
-
-      CALL lim_istate_init     !  reading the initials parameters of the ice
-
-      ! surface temperature
-      DO jl = 1, jpl ! loop over categories
+      CALL lim_istate_init
+
+      ! init surface temperature
+      DO jl = 1, jpl
          t_su  (:,:,jl) = rt0 * tmask(:,:,1)
          tn_ice(:,:,jl) = rt0 * tmask(:,:,1)
       END DO
 
-      ! basal temperature (considered at freezing point)
+      ! init basal temperature (considered at freezing point)
       CALL eos_fzp( sss_m(:,:), t_bo(:,:) )
       t_bo(:,:) = ( t_bo(:,:) + rt0 ) * tmask(:,:,1) 
 
 
-      IF( ln_iceini ) THEN
-
-         !--------------------------------------------------------------------
-         ! 2) Basal temperature, ice mask and hemispheric index
-         !--------------------------------------------------------------------
-
-         DO jj = 1, jpj                                       ! ice if sst <= t-freez + ttest
-            DO ji = 1, jpi
-               IF( ( sst_m(ji,jj)  - ( t_bo(ji,jj) - rt0 ) ) * tmask(ji,jj,1) >= rn_thres_sst ) THEN 
-                  zswitch(ji,jj) = 0._wp * tmask(ji,jj,1)    ! no ice
-               ELSE                                                                                   
-                  zswitch(ji,jj) = 1._wp * tmask(ji,jj,1)    !    ice
-               ENDIF
-            END DO
-         END DO
-
-         !--------------------------------------------------------------------
-         ! 3) Initialization of sea ice state variables
-         !--------------------------------------------------------------------
-         IF( ln_iceini_file )THEN
+      !--------------------------------------------------------------------
+      ! 2) Initialization of sea ice state variables
+      !--------------------------------------------------------------------
+      IF( ln_limini ) THEN
+
+         IF( ln_limini_file )THEN
 
             zht_i_ini(:,:)  = si(jp_hti)%fnow(:,:,1)
@@ -161,5 +131,17 @@
             zsm_i_ini(:,:)  = si(jp_smi)%fnow(:,:,1)
 
-         ELSE ! ln_iceini_file = F
+            WHERE( zat_i_ini(:,:) > 0._wp ) ; zswitch(:,:) = tmask(:,:,1) 
+            ELSEWHERE                       ; zswitch(:,:) = 0._wp
+            END WHERE
+
+         ELSE ! ln_limini_file = F
+
+            !--------------------------------------------------------------------
+            ! 3) Basal temperature, ice mask
+            !--------------------------------------------------------------------
+            ! no ice if sst <= t-freez + ttest
+            WHERE( ( sst_m(:,:) - (t_bo(:,:) - rt0) ) * tmask(:,:,1) >= rn_thres_sst ) ; zswitch(:,:) = 0._wp 
+            ELSEWHERE                                                                  ; zswitch(:,:) = tmask(:,:,1)
+            END WHERE
 
             !-----------------------------
@@ -169,26 +151,25 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  IF( fcor(ji,jj) >= 0._wp ) THEN
-                     zht_i_ini(ji,jj) = rn_hti_ini_n
-                     zht_s_ini(ji,jj) = rn_hts_ini_n
-                     zat_i_ini(ji,jj) = rn_ati_ini_n
-                     zts_u_ini(ji,jj) = rn_tmi_ini_n
-                     zsm_i_ini(ji,jj) = rn_smi_ini_n
-                     ztm_i_ini(ji,jj) = rn_tmi_ini_n
+                  IF( ff(ji,jj) >= 0._wp ) THEN
+                     zht_i_ini(ji,jj) = rn_hti_ini_n * zswitch(ji,jj)
+                     zht_s_ini(ji,jj) = rn_hts_ini_n * zswitch(ji,jj)
+                     zat_i_ini(ji,jj) = rn_ati_ini_n * zswitch(ji,jj)
+                     zts_u_ini(ji,jj) = rn_tmi_ini_n * zswitch(ji,jj)
+                     zsm_i_ini(ji,jj) = rn_smi_ini_n * zswitch(ji,jj)
+                     ztm_i_ini(ji,jj) = rn_tmi_ini_n * zswitch(ji,jj)
                   ELSE
-                     zht_i_ini(ji,jj) = rn_hti_ini_s
-                     zht_s_ini(ji,jj) = rn_hts_ini_s
-                     zat_i_ini(ji,jj) = rn_ati_ini_s
-                     zts_u_ini(ji,jj) = rn_tmi_ini_s
-                     zsm_i_ini(ji,jj) = rn_smi_ini_s
-                     ztm_i_ini(ji,jj) = rn_tmi_ini_s
+                     zht_i_ini(ji,jj) = rn_hti_ini_s * zswitch(ji,jj)
+                     zht_s_ini(ji,jj) = rn_hts_ini_s * zswitch(ji,jj)
+                     zat_i_ini(ji,jj) = rn_ati_ini_s * zswitch(ji,jj)
+                     zts_u_ini(ji,jj) = rn_tmi_ini_s * zswitch(ji,jj)
+                     zsm_i_ini(ji,jj) = rn_smi_ini_s * zswitch(ji,jj)
+                     ztm_i_ini(ji,jj) = rn_tmi_ini_s * zswitch(ji,jj)
                   ENDIF
                END DO
             END DO
 
-         ENDIF ! ln_iceini_file
-
+         ENDIF ! ln_limini_file
+         
          zvt_i_ini(:,:) = zht_i_ini(:,:) * zat_i_ini(:,:)   ! ice volume
-
          !---------------------------------------------------------------------
          ! 3.2) Distribute ice concentration and thickness into the categories
@@ -199,5 +180,4 @@
          zh_i_ini(:,:,:) = 0._wp 
          za_i_ini(:,:,:) = 0._wp
-         zv_i_ini(:,:,:) = 0._wp
 
          DO jj = 1, jpj
@@ -206,128 +186,109 @@
                IF( zat_i_ini(ji,jj) > 0._wp .AND. zht_i_ini(ji,jj) > 0._wp )THEN
 
-                  ztest_1 = 0 ; ztest_2 = 0 ; ztest_3 = 0 ; ztest_4 = 0
-!                  ztests  = 0 
-
-                  DO i_fill = jpl, 1, -1
-
-!                     IF( ztests .NE. 4 ) THEN
-                     IF ( ( ztest_1 + ztest_2 + ztest_3 + ztest_4 ) .NE. 4 ) THEN
-                        !----------------------------
-                        ! fill the i_fill categories
-                        !----------------------------
-                        ! *** 1 category to fill
-                        IF ( i_fill .EQ. 1 ) THEN
-                           zh_i_ini(ji,jj,    1)   = zht_i_ini(ji,jj)
-                           za_i_ini(ji,jj,    1)   = zat_i_ini(ji,jj)
-                           zh_i_ini(ji,jj,2:jpl)   = 0._wp
-                           za_i_ini(ji,jj,2:jpl)   = 0._wp
-                        ELSE
-
-                           ! *** >1 categores to fill
-                           !--- Ice thicknesses in the i_fill - 1 first categories
-                           DO jl = 1, i_fill - 1
-                              zh_i_ini(ji,jj,jl) = hi_mean(jl)
-                           END DO
+                  !--- jl0: most likely index where cc will be maximum
+                  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
+
+                  ! initialisation of tests
+                  itest(:)  = 0
+                  
+                  i_fill = jpl + 1                                             !====================================
+                  DO WHILE ( ( SUM( itest(:) ) /= 4 ) .AND. ( i_fill >= 2 ) )  ! iterative loop on i_fill categories
+                     ! iteration                                               !====================================
+                     i_fill = i_fill - 1
+
+                     ! initialisation of ice variables for each try
+                     zh_i_ini(ji,jj,:) = 0._wp 
+                     za_i_ini(ji,jj,:) = 0._wp
+                     itest(:) = 0
+
+                     ! *** case very thin ice: fill only category 1
+                     IF ( i_fill == 1 ) THEN
+                        zh_i_ini(ji,jj,1) = zht_i_ini(ji,jj)
+                        za_i_ini(ji,jj,1) = zat_i_ini(ji,jj)
+
+                     ! *** case ice is thicker: fill categories >1
+                     ELSE
+
+                        ! Fill ice thicknesses in the (i_fill-1) cat by hmean 
+                        DO jl = 1, i_fill-1
+                           zh_i_ini(ji,jj,jl) = hi_mean(jl)
+                        END DO
                
-                           !--- jl0: most likely index where cc will be maximum
-                           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
-                              ENDIF
-                           END DO
-                           jl0 = MIN(jl0, i_fill)
-               
-                           !--- Concentrations
-                           za_i_ini(ji,jj,jl0) = zat_i_ini(ji,jj) / SQRT(REAL(jpl))
-                           DO jl = 1, i_fill - 1
-                              IF( jl .NE. jl0 )THEN
-                                 zsigma             = 0.5 * zht_i_ini(ji,jj)
-                                 zarg               = ( zh_i_ini(ji,jj,jl) - zht_i_ini(ji,jj) ) / zsigma
-                                 za_i_ini(ji,jj,jl) = za_i_ini(ji,jj,jl0) * EXP(-zarg**2)
-                              ENDIF
-                           END DO
-               
-                           zA = 0. ! sum of the areas in the jpl categories 
-                           DO jl = 1, i_fill - 1
-                              zA = zA + za_i_ini(ji,jj,jl)
-                           END DO
-                           za_i_ini(ji,jj,i_fill)   = zat_i_ini(ji,jj) - zA ! ice conc in the last category
-                           IF ( i_fill .LT. jpl ) za_i_ini(ji,jj,i_fill+1:jpl) = 0._wp
-         
-                           !--- Ice thickness in the last category
-                           zV = 0. ! sum of the volumes of the N-1 categories
-                           DO jl = 1, i_fill - 1
-                              zV = zV + za_i_ini(ji,jj,jl)*zh_i_ini(ji,jj,jl)
-                           END DO
-                           zh_i_ini(ji,jj,i_fill) = ( zvt_i_ini(ji,jj) - zV ) / za_i_ini(ji,jj,i_fill) 
-                           IF ( i_fill .LT. jpl ) zh_i_ini(ji,jj,i_fill+1:jpl) = 0._wp
-
-                           !--- volumes
-                           zv_i_ini(ji,jj,:) = za_i_ini(ji,jj,:) * zh_i_ini(ji,jj,:)
-                           IF ( i_fill .LT. jpl ) zv_i_ini(ji,jj,i_fill+1:jpl) = 0._wp
-
-                        ENDIF ! i_fill
-
-                        !---------------------
-                        ! Compatibility tests
-                        !---------------------
-                        ! Test 1: area conservation
-                        zA_cons = SUM(za_i_ini(ji,jj,:)) ; zconv = ABS(zat_i_ini(ji,jj) - zA_cons )
-                        IF ( zconv .LT. 1.0e-6 ) THEN
-                           ztest_1 = 1
-                        ELSE 
-                          ztest_1 = 0
-                        ENDIF
-
-                        ! Test 2: volume conservation
-                        zV_cons = SUM(zv_i_ini(ji,jj,:))
-                        zconv = ABS(zvt_i_ini(ji,jj) - zV_cons)
-
-                        IF( zconv .LT. 1.0e-6 ) THEN
-                           ztest_2 = 1
-                        ELSE
-                           ztest_2 = 0
-                        ENDIF
-
-                        ! Test 3: thickness of the last category is in-bounds ?
-                        IF ( zh_i_ini(ji,jj,i_fill) > hi_max(i_fill-1) ) THEN
-                           ztest_3 = 1
-                        ELSE
-                           ztest_3 = 0
-                        ENDIF
-
-                        ! Test 4: positivity of ice concentrations
-                        ztest_4 = 1
-                        DO jl = 1, jpl
-                           IF ( za_i_ini(ji,jj,jl) .LT. 0._wp ) THEN 
-                              ztest_4 = 0
+                        !--- Concentrations
+                        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
-
-                     ENDIF ! ztest_1 + ztest_2 + ztest_3 + ztest_4
- 
-                     ztests = ztest_1 + ztest_2 + ztest_3 + ztest_4
-
-                  END DO ! i_fill
-
-                  IF(lwp) THEN 
-                     WRITE(numout,*) ' ztests : ', ztests
-                     IF( ztests .NE. 4 )THEN
-                        WRITE(numout,*)
-                        WRITE(numout,*) ' !!!! ALERT                  !!! '
-                        WRITE(numout,*) ' !!!! Something is wrong in the LIM3 initialization procedure '
-                        WRITE(numout,*)
-                        WRITE(numout,*) ' *** ztests is not equal to 4 '
-                        WRITE(numout,*) ' *** ztest_i (i=1,4) = ', ztest_1, ztest_2, ztest_3, ztest_4
-                        WRITE(numout,*) ' zat_i_ini : ', zat_i_ini(ji,jj)
-                        WRITE(numout,*) ' zht_i_ini : ', zht_i_ini(ji,jj)
-                     ENDIF ! ztests .NE. 4
+               
+                        ! Concentration in the last (i_fill) category
+                        za_i_ini(ji,jj,i_fill) = zat_i_ini(ji,jj) - SUM( za_i_ini(ji,jj,1:i_fill-1) )
+
+                        ! Ice thickness in the last (i_fill) category
+                        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 ) 
+
+                        ! clem: 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 ! case ice is thick or thin
+
+                     !---------------------
+                     ! Compatibility tests
+                     !---------------------
+                     ! Test 1: area conservation
+                     zconv = ABS( zat_i_ini(ji,jj) - SUM( za_i_ini(ji,jj,1:jpl) ) )
+                     IF ( zconv < epsi06 ) itest(1) = 1
+                     
+                     ! Test 2: volume conservation
+                     zconv = ABS(       zat_i_ini(ji,jj)       * zht_i_ini(ji,jj)   &
+                        &        - SUM( za_i_ini (ji,jj,1:jpl) * zh_i_ini (ji,jj,1:jpl) ) )
+                     IF ( zconv < epsi06 ) itest(2) = 1
+                     
+                     ! Test 3: thickness of the last category is in-bounds ?
+                     IF ( zh_i_ini(ji,jj,i_fill) >= hi_max(i_fill-1) ) itest(3) = 1
+                     
+                     ! Test 4: positivity of ice concentrations
+                     itest(4) = 1
+                     DO jl = 1, i_fill
+                        IF ( za_i_ini(ji,jj,jl) < 0._wp ) itest(4) = 0
+                     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 LIM3 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 !  zat_i_ini(ji,jj) > 0._wp .AND. zhm_i_ini(ji,jj) > 0._wp
-
-            ENDDO   
-         ENDDO   
+               
+               ENDIF !  zat_i_ini(ji,jj) > 0._wp .AND. zht_i_ini(ji,jj) > 0._wp
+            
+            ENDDO
+         ENDDO
 
          !---------------------------------------------------------------------
@@ -373,5 +334,5 @@
             smv_i = sm_i * v_i
          ENDIF
-         
+            
          ! Snow temperature and heat content
          DO jk = 1, nlay_s
@@ -413,5 +374,5 @@
          tn_ice (:,:,:) = t_su (:,:,:)
 
-      ELSE ! if ln_iceini=false
+      ELSE ! if ln_limini=false
          a_i  (:,:,:) = 0._wp
          v_i  (:,:,:) = 0._wp
@@ -436,5 +397,5 @@
          END DO
 
-      ENDIF ! ln_iceini
+      ENDIF ! ln_limini
       
       at_i (:,:) = 0.0_wp
@@ -486,8 +447,13 @@
       sxyage (:,:,:)  = 0._wp
 
-
-      CALL wrk_dealloc( jpi, jpj, jpl, zh_i_ini,  za_i_ini,  zv_i_ini )
+!!!clem
+!!      ! Output the initial state and forcings
+!!      CALL dia_wri_state( 'output.init', nit000 )
+!!!      
+
+      CALL wrk_dealloc( jpi, jpj, jpl, zh_i_ini,  za_i_ini )
       CALL wrk_dealloc( jpi, jpj,      zht_i_ini, zat_i_ini, zvt_i_ini, zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini )
       CALL wrk_dealloc( jpi, jpj,      zswitch )
+      Call wrk_dealloc( 4,             itest )
 
    END SUBROUTINE lim_istate
@@ -518,5 +484,5 @@
       TYPE(FLD_N), DIMENSION(jpfldi) ::   slf_i                 ! array of namelist informations on the fields to read
       !
-      NAMELIST/namiceini/ ln_iceini, ln_iceini_file, rn_thres_sst, rn_hts_ini_n, rn_hts_ini_s,  &
+      NAMELIST/namiceini/ ln_limini, ln_limini_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,                             &
@@ -544,6 +510,6 @@
          WRITE(numout,*) 'lim_istate_init : ice parameters inititialisation '
          WRITE(numout,*) '~~~~~~~~~~~~~~~'
-         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,*) '   initialization with ice (T) or not (F)       ln_limini     = ', ln_limini
+         WRITE(numout,*) '   ice initialization from a netcdf file      ln_limini_file  = ', ln_limini_file
          WRITE(numout,*) '   threshold water temp. for initial sea-ice    rn_thres_sst  = ', rn_thres_sst
          WRITE(numout,*) '   initial snow thickness in the north          rn_hts_ini_n  = ', rn_hts_ini_n
@@ -559,5 +525,5 @@
       ENDIF
 
-      IF( ln_iceini_file ) THEN                      ! Ice initialization using input file
+      IF( ln_limini_file ) THEN                      ! Ice initialization using input file
          !
          ! set si structure
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90	(revision 7309)
@@ -18,17 +18,15 @@
    USE thd_ice          ! LIM thermodynamics
    USE ice              ! LIM variables
-   USE dom_ice          ! LIM domain
    USE limvar           ! LIM
    USE lbclnk           ! lateral boundary condition - MPP exchanges
    USE lib_mpp          ! MPP library
    USE wrk_nemo         ! work arrays
-   USE prtctl           ! Print control
 
    USE in_out_manager   ! I/O manager
    USE iom              ! I/O manager
    USE lib_fortran      ! glob_sum
-   USE limdiahsb
    USE timing           ! Timing
    USE limcons          ! conservation tests
+   USE limctl           ! control prints
 
    IMPLICIT NONE
@@ -70,10 +68,9 @@
       !!                ***  ROUTINE lim_itd_me_alloc ***
       !!---------------------------------------------------------------------!
-      ALLOCATE(                                                                     &
+      ALLOCATE(                                                                      &
          !* Variables shared among ridging subroutines
-         &      asum (jpi,jpj)     , athorn(jpi,jpj,0:jpl)                    ,     &
-         &      aksum(jpi,jpj)                                                ,     &
-         &      hrmin(jpi,jpj,jpl) , hraft(jpi,jpj,jpl) , aridge(jpi,jpj,jpl) ,     &
-         &      hrmax(jpi,jpj,jpl) , krdg (jpi,jpj,jpl) , araft (jpi,jpj,jpl) , STAT=lim_itd_me_alloc )
+         &      asum (jpi,jpj)     , athorn(jpi,jpj,0:jpl) , aksum (jpi,jpj)     ,   &
+         &      hrmin(jpi,jpj,jpl) , hraft(jpi,jpj,jpl)    , aridge(jpi,jpj,jpl) ,   &
+         &      hrmax(jpi,jpj,jpl) , krdg (jpi,jpj,jpl)    , araft (jpi,jpj,jpl) , STAT=lim_itd_me_alloc )
          !
       IF( lim_itd_me_alloc /= 0 )   CALL ctl_warn( 'lim_itd_me_alloc: failed to allocate arrays' )
@@ -127,13 +124,6 @@
       CALL wrk_alloc( jpi,jpj, closing_net, divu_adv, opning, closing_gross )
 
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab2d_1=ato_i , clinfo1=' lim_itd_me: ato_i  : ', tab2d_2=at_i   , clinfo2=' at_i    : ')
-         CALL prt_ctl(tab2d_1=divu_i, clinfo1=' lim_itd_me: divu_i : ', tab2d_2=delta_i, clinfo2=' delta_i : ')
-      ENDIF
-
-      IF( ln_limdyn ) THEN          !   Start ridging and rafting   !
-
       ! conservation test
-      IF( ln_limdiahsb ) CALL lim_cons_hsm(0, 'limitd_me', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limitd_me', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
 
       !-----------------------------------------------------------------------------!
@@ -211,9 +201,9 @@
             DO ji = 1, jpi
                za   = ( opning(ji,jj) - athorn(ji,jj,0) * closing_gross(ji,jj) ) * rdt_ice
-               IF( za < 0._wp .AND. za > - ato_i(ji,jj) ) THEN  ! would lead to negative ato_i
-                  zfac = - ato_i(ji,jj) / za
+               IF    ( za < 0._wp .AND. za > - ato_i(ji,jj) ) THEN                  ! would lead to negative ato_i
+                  zfac          = - ato_i(ji,jj) / za
                   opning(ji,jj) = athorn(ji,jj,0) * closing_gross(ji,jj) - ato_i(ji,jj) * r1_rdtice 
                ELSEIF( za > 0._wp .AND. za > ( asum(ji,jj) - ato_i(ji,jj) ) ) THEN  ! would lead to ato_i > asum
-                  zfac = ( asum(ji,jj) - ato_i(ji,jj) ) / za
+                  zfac          = ( asum(ji,jj) - ato_i(ji,jj) ) / za
                   opning(ji,jj) = athorn(ji,jj,0) * closing_gross(ji,jj) + ( asum(ji,jj) - ato_i(ji,jj) ) * r1_rdtice 
                ENDIF
@@ -259,4 +249,5 @@
                   closing_net(ji,jj) = 0._wp
                   opning     (ji,jj) = 0._wp
+                  ato_i      (ji,jj) = MAX( 0._wp, 1._wp - SUM( a_i(ji,jj,:) ) )
                ELSE
                   iterate_ridging    = 1
@@ -292,43 +283,10 @@
       ! control prints
       !-----------------------------------------------------------------------------!
-      IF(ln_ctl) THEN 
-         CALL lim_var_glo2eqv
-
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Cell values : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=e1e2t , clinfo1=' lim_itd_me  : cell area :')
-         CALL prt_ctl(tab2d_1=at_i , clinfo1=' lim_itd_me  : at_i      :')
-         CALL prt_ctl(tab2d_1=vt_i , clinfo1=' lim_itd_me  : vt_i      :')
-         CALL prt_ctl(tab2d_1=vt_s , clinfo1=' lim_itd_me  : vt_s      :')
-         DO jl = 1, jpl
-            CALL prt_ctl_info(' ')
-            CALL prt_ctl_info(' - Category : ', ivar1=jl)
-            CALL prt_ctl_info('   ~~~~~~~~~~')
-            CALL prt_ctl(tab2d_1=a_i   (:,:,jl)   , clinfo1= ' lim_itd_me  : a_i      : ')
-            CALL prt_ctl(tab2d_1=ht_i  (:,:,jl)   , clinfo1= ' lim_itd_me  : ht_i     : ')
-            CALL prt_ctl(tab2d_1=ht_s  (:,:,jl)   , clinfo1= ' lim_itd_me  : ht_s     : ')
-            CALL prt_ctl(tab2d_1=v_i   (:,:,jl)   , clinfo1= ' lim_itd_me  : v_i      : ')
-            CALL prt_ctl(tab2d_1=v_s   (:,:,jl)   , clinfo1= ' lim_itd_me  : v_s      : ')
-            CALL prt_ctl(tab2d_1=e_s   (:,:,1,jl) , clinfo1= ' lim_itd_me  : e_s      : ')
-            CALL prt_ctl(tab2d_1=t_su  (:,:,jl)   , clinfo1= ' lim_itd_me  : t_su     : ')
-            CALL prt_ctl(tab2d_1=t_s   (:,:,1,jl) , clinfo1= ' lim_itd_me  : t_snow   : ')
-            CALL prt_ctl(tab2d_1=sm_i  (:,:,jl)   , clinfo1= ' lim_itd_me  : sm_i     : ')
-            CALL prt_ctl(tab2d_1=smv_i (:,:,jl)   , clinfo1= ' lim_itd_me  : smv_i    : ')
-            DO jk = 1, nlay_i
-               CALL prt_ctl_info(' ')
-               CALL prt_ctl_info(' - Layer : ', ivar1=jk)
-               CALL prt_ctl_info('   ~~~~~~~')
-               CALL prt_ctl(tab2d_1=t_i(:,:,jk,jl) , clinfo1= ' lim_itd_me  : t_i      : ')
-               CALL prt_ctl(tab2d_1=e_i(:,:,jk,jl) , clinfo1= ' lim_itd_me  : e_i      : ')
-            END DO
-         END DO
-      ENDIF
-
       ! conservation test
-      IF( ln_limdiahsb ) CALL lim_cons_hsm(1, 'limitd_me', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      ENDIF  ! ln_limdyn=.true.
-      !
+      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limitd_me', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      ! control prints
+      IF( ln_ctl )       CALL lim_prt3D( 'limitd_me' )
+
       CALL wrk_dealloc( jpi, jpj, closing_net, divu_adv, opning, closing_gross )
       !
@@ -368,5 +326,5 @@
                rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )
                ht_i(ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-            END DO
+           END DO
          END DO
       END DO
@@ -438,5 +396,6 @@
       ENDIF
 
-      IF( ln_rafting ) THEN      ! Ridging and rafting ice participation functions
+      ! --- Ridging and rafting participation concentrations --- !
+      IF( ln_rafting .AND. ln_ridging ) THEN
          !
          DO jl = 1, jpl
@@ -445,13 +404,19 @@
                   zdummy           = TANH ( rn_craft * ( ht_i(ji,jj,jl) - rn_hraft ) )
                   aridge(ji,jj,jl) = ( 1._wp + zdummy ) * 0.5_wp * athorn(ji,jj,jl)
-                  araft (ji,jj,jl) = ( 1._wp - zdummy ) * 0.5_wp * athorn(ji,jj,jl)
+                  araft (ji,jj,jl) = athorn(ji,jj,jl) - aridge(ji,jj,jl)
                END DO
             END DO
          END DO
-
-      ELSE
+         !
+      ELSEIF( ln_ridging .AND. .NOT. ln_rafting ) THEN
          !
          DO jl = 1, jpl
             aridge(:,:,jl) = athorn(:,:,jl)
+         END DO
+         !
+      ELSEIF( ln_rafting .AND. .NOT. ln_ridging ) THEN
+         !
+         DO jl = 1, jpl
+            araft(:,:,jl) = athorn(:,:,jl)
          END DO
          !
@@ -657,5 +622,5 @@
                   &                            - sm_i(ji,jj,jl1) * vsw(ij) * rhoic * r1_rdtice     ! and get  sm_i  from the ocean 
             ENDIF
-            
+               
             !------------------------------------------            
             ! 3.7 Put the snow somewhere in the ocean
@@ -795,8 +760,9 @@
       INTEGER             ::   numts_rm    ! number of time steps for the P smoothing
       REAL(wp)            ::   zp, z1_3    ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zworka   ! temporary array used here
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zworka           ! temporary array used here
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zstrp1, zstrp2   ! strength at previous time steps
       !!----------------------------------------------------------------------
 
-      CALL wrk_alloc( jpi, jpj, zworka )
+      CALL wrk_alloc( jpi,jpj, zworka, zstrp1, zstrp2 )
 
       !------------------------------------------------------------------------------!
@@ -844,14 +810,14 @@
          END DO
    
-         strength(:,:) = rn_pe_rdg * Cp * strength(:,:) / aksum(:,:)
+         strength(:,:) = rn_pe_rdg * Cp * strength(:,:) / aksum(:,:) * tmask(:,:,1)
                          ! where Cp = (g/2)*(rhow-rhoi)*(rhoi/rhow) and rn_pe_rdg accounts for frictional dissipation
          ksmooth = 1
 
-         !------------------------------------------------------------------------------!
-         ! 4) Hibler (1979)' method
-         !------------------------------------------------------------------------------!
+      !------------------------------------------------------------------------------!
+      ! 4) Hibler (1979)' method
+      !------------------------------------------------------------------------------!
       ELSE                      ! kstrngth ne 1:  Hibler (1979) form
          !
-         strength(:,:) = rn_pstar * vt_i(:,:) * EXP( - rn_crhg * ( 1._wp - at_i(:,:) )  )
+         strength(:,:) = rn_pstar * vt_i(:,:) * EXP( - rn_crhg * ( 1._wp - at_i(:,:) )  ) * tmask(:,:,1)
          !
          ksmooth = 1
@@ -866,5 +832,5 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               strength(ji,jj) = strength(ji,jj) * exp(-5.88*SQRT(MAX(bv_i(ji,jj),0.0)))
+               strength(ji,jj) = strength(ji,jj) * exp(-5.88*SQRT(MAX(bvm_i(ji,jj),0.0)))
             END DO
          END DO
@@ -880,9 +846,7 @@
       IF ( ksmooth == 1 ) THEN
 
-         CALL lbc_lnk( strength, 'T', 1. )
-
          DO jj = 2, jpjm1
             DO ji = 2, jpim1
-               IF ( ( asum(ji,jj) - ato_i(ji,jj) ) > 0._wp) THEN 
+               IF ( ( asum(ji,jj) - ato_i(ji,jj) ) > 0._wp ) THEN 
                   zworka(ji,jj) = ( 4.0 * strength(ji,jj)              &
                      &                  + strength(ji-1,jj) * tmask(ji-1,jj,1) + strength(ji+1,jj) * tmask(ji+1,jj,1) &  
@@ -907,33 +871,30 @@
       ! Temporal smoothing
       !--------------------
-      IF ( numit == nit000 + nn_fsbc - 1 ) THEN
-         strp1(:,:) = 0.0            
-         strp2(:,:) = 0.0            
-      ENDIF
-
       IF ( ksmooth == 2 ) THEN
 
-         CALL lbc_lnk( strength, 'T', 1. )
-
-         DO jj = 1, jpj - 1
-            DO ji = 1, jpi - 1
-               IF ( ( asum(ji,jj) - ato_i(ji,jj) ) > 0._wp) THEN 
+         IF ( numit == nit000 + nn_fsbc - 1 ) THEN
+            zstrp1(:,:) = 0._wp
+            zstrp2(:,:) = 0._wp
+         ENDIF
+
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               IF ( ( asum(ji,jj) - ato_i(ji,jj) ) > 0._wp ) THEN 
                   numts_rm = 1 ! number of time steps for the running mean
-                  IF ( strp1(ji,jj) > 0._wp ) numts_rm = numts_rm + 1
-                  IF ( strp2(ji,jj) > 0._wp ) numts_rm = numts_rm + 1
-                  zp = ( strength(ji,jj) + strp1(ji,jj) + strp2(ji,jj) ) / numts_rm
-                  strp2(ji,jj) = strp1(ji,jj)
-                  strp1(ji,jj) = strength(ji,jj)
+                  IF ( zstrp1(ji,jj) > 0._wp ) numts_rm = numts_rm + 1
+                  IF ( zstrp2(ji,jj) > 0._wp ) numts_rm = numts_rm + 1
+                  zp = ( strength(ji,jj) + zstrp1(ji,jj) + zstrp2(ji,jj) ) / numts_rm
+                  zstrp2(ji,jj) = zstrp1(ji,jj)
+                  zstrp1(ji,jj) = strength(ji,jj)
                   strength(ji,jj) = zp
-
                ENDIF
             END DO
          END DO
 
+         CALL lbc_lnk( strength, 'T', 1. )      ! Boundary conditions
+
       ENDIF ! ksmooth
 
-      CALL lbc_lnk( strength, 'T', 1. )      ! Boundary conditions
-
-      CALL wrk_dealloc( jpi, jpj, zworka )
+      CALL wrk_dealloc( jpi,jpj, zworka, zstrp1, zstrp2 )
       !
    END SUBROUTINE lim_itd_me_icestrength
@@ -953,7 +914,6 @@
       !!-------------------------------------------------------------------
       INTEGER :: ios                 ! Local integer output status for namelist read
-      NAMELIST/namiceitdme/ rn_cs, rn_fsnowrdg, rn_fsnowrft,              & 
-        &                   rn_gstar, rn_astar, rn_hstar, ln_rafting, rn_hraft, rn_craft, rn_por_rdg, &
-        &                   nn_partfun
+      NAMELIST/namiceitdme/ rn_cs, nn_partfun, rn_gstar, rn_astar,             & 
+        &                   ln_ridging, rn_hstar, rn_por_rdg, rn_fsnowrdg, ln_rafting, rn_hraft, rn_craft, rn_fsnowrft
       !!-------------------------------------------------------------------
       !
@@ -969,17 +929,18 @@
       IF (lwp) THEN                          ! control print
          WRITE(numout,*)
-         WRITE(numout,*)' lim_itd_me_init : ice parameters for mechanical ice redistribution '
-         WRITE(numout,*)' ~~~~~~~~~~~~~~~'
+         WRITE(numout,*)'lim_itd_me_init : ice parameters for mechanical ice redistribution '
+         WRITE(numout,*)'~~~~~~~~~~~~~~~'
          WRITE(numout,*)'   Fraction of shear energy contributing to ridging        rn_cs       = ', rn_cs 
-         WRITE(numout,*)'   Fraction of snow volume conserved during ridging        rn_fsnowrdg = ', rn_fsnowrdg 
-         WRITE(numout,*)'   Fraction of snow volume conserved during ridging        rn_fsnowrft = ', rn_fsnowrft 
+         WRITE(numout,*)'   Switch for part. function (0) linear (1) exponential    nn_partfun  = ', nn_partfun
          WRITE(numout,*)'   Fraction of total ice coverage contributing to ridging  rn_gstar    = ', rn_gstar
          WRITE(numout,*)'   Equivalent to G* for an exponential part function       rn_astar    = ', rn_astar
+         WRITE(numout,*)'   Ridging of ice sheets or not                            ln_ridging  = ', ln_ridging
          WRITE(numout,*)'   Quantity playing a role in max ridged ice thickness     rn_hstar    = ', rn_hstar
+         WRITE(numout,*)'   Initial porosity of ridges                              rn_por_rdg  = ', rn_por_rdg
+         WRITE(numout,*)'   Fraction of snow volume conserved during ridging        rn_fsnowrdg = ', rn_fsnowrdg 
          WRITE(numout,*)'   Rafting of ice sheets or not                            ln_rafting  = ', ln_rafting
          WRITE(numout,*)'   Parmeter thickness (threshold between ridge-raft)       rn_hraft    = ', rn_hraft
          WRITE(numout,*)'   Rafting hyperbolic tangent coefficient                  rn_craft    = ', rn_craft  
-         WRITE(numout,*)'   Initial porosity of ridges                              rn_por_rdg  = ', rn_por_rdg
-         WRITE(numout,*)'   Switch for part. function (0) linear (1) exponential    nn_partfun  = ', nn_partfun
+         WRITE(numout,*)'   Fraction of snow volume conserved during ridging        rn_fsnowrft = ', rn_fsnowrft 
       ENDIF
       !
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90	(revision 7309)
@@ -18,5 +18,4 @@
    !!   lim_itd_shiftice :
    !!----------------------------------------------------------------------
-   USE dom_ice          ! LIM-3 domain
    USE par_oce          ! ocean parameters
    USE dom_oce          ! ocean domain
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limmsh.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limmsh.F90	(revision 7308)
+++ 	(revision )
@@ -1,117 +1,0 @@
-MODULE limmsh
-   !!======================================================================
-   !!                     ***  MODULE  limmsh  ***
-   !! LIM ice model :   definition of the ice mesh parameters
-   !!======================================================================
-   !! History :  3.2  !  2008-01 (NEMO team)  LIM-3: adaptation from LIM-2
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_msh       : definition of the ice mesh
-   !!----------------------------------------------------------------------
-   USE phycst         ! physical constants
-   USE dom_oce        ! ocean domain
-   USE dom_ice        ! sea-ice domain
-   USE in_out_manager ! I/O manager
-   USE lbclnk         ! lateral boundary condition - MPP exchanges
-   USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_msh   ! routine called by sbcice_lim.F90
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_msh
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_msh  ***
-      !!              
-      !! ** Purpose : Definition of the charact. of the numerical grid
-      !!       
-      !! ** Action  : - Initialisation of some variables
-      !!              - Definition of some constants linked with the grid
-      !!              - Definition of the metric coef. for the sea/ice
-      !! 
-      !! Reference  : Deleersnijder et al. Ocean Modelling 100, 7-10 
-      !!--------------------------------------------------------------------- 
-      INTEGER  ::   ji, jj   ! dummy loop indices
-      REAL(wp) ::   zusden   ! local scalar
-      !!---------------------------------------------------------------------
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_msh : LIM-3 sea-ice model, mesh initialization'
-         WRITE(numout,*) '~~~~~~~'
-      ENDIF
-
-      IF( jphgr_msh == 2 .OR. jphgr_msh == 3 .OR. jphgr_msh == 5 )   &
-          &      CALL ctl_stop(' Coriolis parameter in LIM not set for f- or beta-plane')
-
-      !                           !==  coriolis factor & Equator position ==!
-      njeq   = INT( jpj / 2 ) 
-      njeqm1 = njeq - 1 
-      !
-      fcor(:,:) = 2. * omega * SIN( gphit(:,:) * rad )   ! coriolis factor
-      !
-      IF( fcor(1,1) * fcor(1,nlcj) < 0.e0 ) THEN   ! local domain include both hemisphere
-         l_jeq = .TRUE.
-         njeq  = 1
-         DO WHILE ( njeq <= jpj .AND. fcor(1,njeq) < 0.e0 )
-            njeq = njeq + 1
-         END DO
-         IF(lwp ) WRITE(numout,*) '          the equator is inside the domain at about njeq = ', njeq
-      ELSEIF( fcor(1,1) < 0.e0 ) THEN
-         l_jeq = .FALSE.
-         njeq = jpj
-         IF(lwp ) WRITE(numout,*) '          the model domain is entirely in the southern hemisphere: njeq = ', njeq
-      ELSE
-         l_jeq = .FALSE.
-         njeq = 2
-         IF(lwp ) WRITE(numout,*) '          the model domain is entirely in the northern hemisphere: njeq = ', njeq
-      ENDIF
-      !
-      njeqm1 = njeq - 1
-
-
-      !                           !==  metric coefficients for sea ice dynamic  ==!
-      wght(:,:,:,:) = 0.e0
-!!gm  Optimisation :  wght to be defined at F-point, not I-point  and change in limrhg
-      DO jj = 2, jpj
-         DO ji = 2, jpi
-            zusden = 1.e0 / (  ( e1t(ji,jj) + e1t(ji-1,jj  ) )   &
-               &             * ( e2t(ji,jj) + e2t(ji  ,jj-1) ) )
-            wght(ji,jj,1,1) = zusden * e1t(ji  ,jj) * e2t(ji,jj  )
-            wght(ji,jj,1,2) = zusden * e1t(ji  ,jj) * e2t(ji,jj-1)
-            wght(ji,jj,2,1) = zusden * e1t(ji-1,jj) * e2t(ji,jj  )
-            wght(ji,jj,2,2) = zusden * e1t(ji-1,jj) * e2t(ji,jj-1)
-         END DO
-      END DO
-      CALL lbc_lnk( wght(:,:,1,1), 'I', 1. )      ! CAUTION: even with the lbc_lnk at ice U-V-point
-      CALL lbc_lnk( wght(:,:,1,2), 'I', 1. )      ! the value of wght at jpj is wrong
-      CALL lbc_lnk( wght(:,:,2,1), 'I', 1. )      ! but it is never used
-      CALL lbc_lnk( wght(:,:,2,2), 'I', 1. )
-!!gm end
-
-      !
-   END SUBROUTINE lim_msh
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option            Dummy Module         NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_msh           ! Dummy routine
-   END SUBROUTINE lim_msh
-#endif
-
-   !!======================================================================
-END MODULE limmsh
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90	(revision 7309)
@@ -9,10 +9,10 @@
    !!            3.3  !  2009-05  (G.Garric) addition of the lim2_evp cas
    !!            3.4  !  2011-01  (A. Porter)  dynamical allocation 
-   !!            3.5  !  2012-08  (R. Benshila)  AGRIF 
+   !!            3.5  !  2012-08  (R. Benshila)  AGRIF
+   !!            3.6  !  2016-06  (C. Rousset) Rewriting + landfast ice + possibility to use mEVP (Bouillon 2013)
    !!----------------------------------------------------------------------
-#if defined key_lim3 || (  defined key_lim2 && ! defined key_lim2_vp )
+#if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'               OR                     LIM-3 sea-ice model
-   !!   'key_lim2' AND NOT 'key_lim2_vp'            EVP LIM-2 sea-ice model
+   !!   'key_lim3'                                      LIM-3 sea-ice model
    !!----------------------------------------------------------------------
    !!   lim_rhg       : computes ice velocities
@@ -24,12 +24,6 @@
    USE sbc_oce        ! Surface boundary condition: ocean fields
    USE sbc_ice        ! Surface boundary condition: ice fields
-#if defined key_lim3
-   USE ice            ! LIM-3: ice variables
-   USE dom_ice        ! LIM-3: ice domain
-   USE limitd_me      ! LIM-3: 
-#else
-   USE ice_2          ! LIM-2: ice variables
-   USE dom_ice_2      ! LIM-2: ice domain
-#endif
+   USE ice            ! ice variables
+   USE limitd_me      ! ice strength
    USE lbclnk         ! Lateral Boundary Condition / MPP link
    USE lib_mpp        ! MPP library
@@ -38,6 +32,6 @@
    USE prtctl         ! Print control
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-#if defined key_agrif && defined key_lim2
-   USE agrif_lim2_interp
+#if defined key_agrif
+   USE agrif_lim3_interp
 #endif
 #if defined key_bdy
@@ -48,5 +42,5 @@
    PRIVATE
 
-   PUBLIC   lim_rhg        ! routine called by lim_dyn (or lim_dyn_2)
+   PUBLIC   lim_rhg        ! routine called by lim_dyn
 
    !! * Substitutions
@@ -59,5 +53,5 @@
 CONTAINS
 
-   SUBROUTINE lim_rhg( k_j1, k_jpj )
+   SUBROUTINE lim_rhg
       !!-------------------------------------------------------------------
       !!                 ***  SUBROUTINE lim_rhg  ***
@@ -106,129 +100,149 @@
       !!                 e.g. in the Canadian Archipelago
       !!
+      !! ** Notes   : There is the possibility to use mEVP from Bouillon 2013
+      !!              (by uncommenting some lines in part 3 and changing alpha and beta parameters)
+      !!              but this solution appears very unstable (see Kimmritz et al 2016)
+      !!
       !! References : Hunke and Dukowicz, JPO97
       !!              Bouillon et al., Ocean Modelling 2009
+      !!              Bouillon et al., Ocean Modelling 2013
       !!-------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   k_j1    ! southern j-index for ice computation
-      INTEGER, INTENT(in) ::   k_jpj   ! northern j-index for ice computation
-      !!
-      INTEGER ::   ji, jj   ! dummy loop indices
-      INTEGER ::   jter     ! local integers
+      INTEGER ::   ji, jj       ! dummy loop indices
+      INTEGER ::   jter         ! local integers
       CHARACTER (len=50) ::   charout
-      REAL(wp) ::   zt11, zt12, zt21, zt22, ztagnx, ztagny, delta                         !
-      REAL(wp) ::   za, zstms          ! local scalars
-      REAL(wp) ::   zc1, zc2, zc3      ! ice mass
-
-      REAL(wp) ::   dtevp , z1_dtevp              ! time step for subcycling
-      REAL(wp) ::   dtotel, z1_dtotel, ecc2, ecci ! square of yield ellipse eccenticity
-      REAL(wp) ::   z0, zr, zcca, zccb            ! temporary scalars
-      REAL(wp) ::   zu_ice2, zv_ice1              !
-      REAL(wp) ::   zddc, zdtc                    ! delta on corners and on centre
-      REAL(wp) ::   zdst                          ! shear at the center of the grid point
-      REAL(wp) ::   zdsshx, zdsshy                ! term for the gradient of ocean surface
-      REAL(wp) ::   sigma1, sigma2                ! internal ice stress
-
-      REAL(wp) ::   zresm         ! Maximal error on ice velocity
-      REAL(wp) ::   zintb, zintn  ! dummy argument
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zpresh           ! temporary array for ice strength
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zpreshc          ! Ice strength on grid cell corners (zpreshc)
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zfrld1, zfrld2   ! lead fraction on U/V points
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zmass1, zmass2   ! ice/snow mass on U/V points
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zcorl1, zcorl2   ! coriolis parameter on U/V points
-      REAL(wp), POINTER, DIMENSION(:,:) ::   za1ct , za2ct    ! temporary arrays
-      REAL(wp), POINTER, DIMENSION(:,:) ::   v_oce1           ! ocean u/v component on U points                           
-      REAL(wp), POINTER, DIMENSION(:,:) ::   u_oce2           ! ocean u/v component on V points
-      REAL(wp), POINTER, DIMENSION(:,:) ::   u_ice2, v_ice1   ! ice u/v component on V/U point
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zf1   , zf2      ! arrays for internal stresses
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zmask            ! mask ocean grid points
+
+      REAL(wp) ::   zrhoco                                                   ! rau0 * rn_cio
+      REAL(wp) ::   zdtevp, z1_dtevp                                         ! time step for subcycling
+      REAL(wp) ::   ecc2, z1_ecc2                                            ! square of yield ellipse eccenticity
+      REAL(wp) ::   zbeta, zalph1, z1_alph1, zalph2, z1_alph2                ! alpha and beta from Bouillon 2009 and 2013
+      REAL(wp) ::   zm1, zm2, zm3, zmassU, zmassV                            ! ice/snow mass
+      REAL(wp) ::   zdelta, zp_delf, zds2, zdt, zdt2, zdiv, zdiv2            ! temporary scalars
+      REAL(wp) ::   zTauO, zTauB, zTauE, zCor, zvel                          ! temporary scalars
+
+      REAL(wp) ::   zsig1, zsig2                                             ! internal ice stress
+      REAL(wp) ::   zresm                                                    ! Maximal error on ice velocity
+      REAL(wp) ::   zintb, zintn                                             ! dummy argument
       
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zdt              ! tension at centre of grid cells
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zds              ! Shear on northeast corner of grid cells
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zs1   , zs2      ! Diagonal stress tensor components zs1 and zs2 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zs12             ! Non-diagonal stress tensor component zs12
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zu_ice, zv_ice, zresr   ! Local error on velocity
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zpice            ! array used for the calculation of ice surface slope:
-                                                              !   ocean surface (ssh_m) if ice is not embedded
-                                                              !   ice top surface if ice is embedded   
-
-      REAL(wp), PARAMETER               ::   zepsi = 1.0e-20_wp ! tolerance parameter
-      REAL(wp), PARAMETER               ::   zvmin = 1.0e-03_wp ! ice volume below which ice velocity equals ocean velocity
+      REAL(wp), POINTER, DIMENSION(:,:) ::   z1_e1t0, z1_e2t0                ! scale factors
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zp_delt                         ! P/delta at T points
+      !
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zaU   , zaV                     ! ice fraction on U/V points
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zmU_t, zmV_t                    ! ice/snow mass/dt on U/V points
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zmf                             ! coriolis parameter at T points
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zTauU_ia , ztauV_ia             ! ice-atm. stress at U-V points
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zspgU , zspgV                   ! surface pressure gradient at U/V points
+      REAL(wp), POINTER, DIMENSION(:,:) ::   v_oceU, u_oceV, v_iceU, u_iceV  ! ocean/ice u/v component on V/U points                           
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zfU   , zfV                     ! internal stresses
+      
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zds                             ! shear
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zs1, zs2, zs12                  ! stress tensor components
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zu_ice, zv_ice, zresr           ! check convergence
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zpice                           ! array used for the calculation of ice surface slope:
+                                                                             !   ocean surface (ssh_m) if ice is not embedded
+                                                                             !   ice top surface if ice is embedded   
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zswitchU, zswitchV              ! dummy arrays
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zmaskU, zmaskV                  ! mask for ice presence
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zfmask, zwf                     ! mask at F points for the ice
+
+      REAL(wp), PARAMETER               ::   zepsi  = 1.0e-20_wp             ! tolerance parameter
+      REAL(wp), PARAMETER               ::   zmmin  = 1._wp                  ! ice mass (kg/m2) below which ice velocity equals ocean velocity
+      REAL(wp), PARAMETER               ::   zshlat = 2._wp                  ! boundary condition for sea-ice velocity (2=no slip ; 0=free slip)
       !!-------------------------------------------------------------------
 
-      CALL wrk_alloc( jpi,jpj, zpresh, zfrld1, zmass1, zcorl1, za1ct , zpreshc, zfrld2, zmass2, zcorl2, za2ct )
-      CALL wrk_alloc( jpi,jpj, u_oce2, u_ice2, v_oce1 , v_ice1 , zmask               )
-      CALL wrk_alloc( jpi,jpj, zf1   , zu_ice, zf2   , zv_ice , zdt    , zds  )
-      CALL wrk_alloc( jpi,jpj, zs1   , zs2   , zs12   , zresr , zpice                 )
-
-#if  defined key_lim2 && ! defined key_lim2_vp
-# if defined key_agrif
-      USE ice_2, vt_s => hsnm
-      USE ice_2, vt_i => hicm
-# else
-      vt_s => hsnm
-      vt_i => hicm
-# endif
-      at_i(:,:) = 1. - frld(:,:)
-#endif
-#if defined key_agrif && defined key_lim2 
-      CALL agrif_rhg_lim2_load      ! First interpolation of coarse values
+      CALL wrk_alloc( jpi,jpj, z1_e1t0, z1_e2t0, zp_delt )
+      CALL wrk_alloc( jpi,jpj, zaU, zaV, zmU_t, zmV_t, zmf, zTauU_ia, ztauV_ia )
+      CALL wrk_alloc( jpi,jpj, zspgU, zspgV, v_oceU, u_oceV, v_iceU, u_iceV, zfU, zfV )
+      CALL wrk_alloc( jpi,jpj, zds, zs1, zs2, zs12, zu_ice, zv_ice, zresr, zpice )
+      CALL wrk_alloc( jpi,jpj, zswitchU, zswitchV, zmaskU, zmaskV, zfmask, zwf )
+
+#if defined key_agrif 
+      CALL agrif_interp_lim3( 'U', 0, nn_nevp )   ! First interpolation of coarse values
+      CALL agrif_interp_lim3( 'V', 0, nn_nevp )
 #endif
       !
       !------------------------------------------------------------------------------!
-      ! 1) Ice strength (zpresh)                                !
-      !------------------------------------------------------------------------------!
+      ! 0) mask at F points for the ice
+      !------------------------------------------------------------------------------!
+      ! ocean/land mask
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1      ! NO vector opt.
+            zfmask(ji,jj) = tmask(ji,jj,1) * tmask(ji+1,jj,1) * tmask(ji,jj+1,1) * tmask(ji+1,jj+1,1)
+         END DO
+      END DO
+      CALL lbc_lnk( zfmask, 'F', 1._wp )
+
+      ! Lateral boundary conditions on velocity (modify zfmask)
+      zwf(:,:) = zfmask(:,:)
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            IF( zfmask(ji,jj) == 0._wp ) THEN
+               zfmask(ji,jj) = zshlat * MIN( 1._wp , MAX( zwf(ji+1,jj), zwf(ji,jj+1), zwf(ji-1,jj), zwf(ji,jj-1) ) )
+            ENDIF
+         END DO
+      END DO
+      DO jj = 2, jpjm1
+         IF( zfmask(1,jj) == 0._wp ) THEN
+            zfmask(1  ,jj) = zshlat * MIN( 1._wp , MAX( zwf(2,jj), zwf(1,jj+1), zwf(1,jj-1) ) )
+         ENDIF
+         IF( zfmask(jpi,jj) == 0._wp ) THEN
+            zfmask(jpi,jj) = zshlat * MIN( 1._wp , MAX( zwf(jpi,jj+1), zwf(jpim1,jj), zwf(jpi,jj-1) ) )
+         ENDIF
+      END DO
+      DO ji = 2, jpim1
+         IF( zfmask(ji,1) == 0._wp ) THEN
+            zfmask(ji,1  ) = zshlat * MIN( 1._wp , MAX( zwf(ji+1,1), zwf(ji,2), zwf(ji-1,1) ) )
+         ENDIF
+         IF( zfmask(ji,jpj) == 0._wp ) THEN
+            zfmask(ji,jpj) = zshlat * MIN( 1._wp , MAX( zwf(ji+1,jpj), zwf(ji-1,jpj), zwf(ji,jpjm1) ) )
+         ENDIF
+      END DO
+      CALL lbc_lnk( zfmask, 'F', 1._wp )
+
+      !------------------------------------------------------------------------------!
+      ! 1) define some variables and initialize arrays
+      !------------------------------------------------------------------------------!
+      zrhoco = rau0 * rn_cio 
+
+      ! ecc2: square of yield ellipse eccenticrity
+      ecc2    = rn_ecc * rn_ecc
+      z1_ecc2 = 1._wp / ecc2
+
+      ! Time step for subcycling
+      zdtevp   = rdt_ice / REAL( nn_nevp )
+      z1_dtevp = 1._wp / zdtevp
+
+      ! alpha parameters (Bouillon 2009)
+      zalph1 = ( 2._wp * rn_relast * rdt_ice ) * z1_dtevp
+      zalph2 = zalph1 * z1_ecc2
+
+      ! alpha and beta parameters (Bouillon 2013)
+      !!zalph1 = 40.
+      !!zalph2 = 40.
+      !!zbeta  = 3000.
+      !!zbeta = REAL( nn_nevp )   ! close to classical EVP of Hunke (2001)
+
+      z1_alph1 = 1._wp / ( zalph1 + 1._wp )
+      z1_alph2 = 1._wp / ( zalph2 + 1._wp )
+
+      ! Initialise stress tensor 
+      zs1 (:,:) = stress1_i (:,:) 
+      zs2 (:,:) = stress2_i (:,:)
+      zs12(:,:) = stress12_i(:,:)
+
+      ! Ice strength
+      CALL lim_itd_me_icestrength( nn_icestr )
+
+      ! 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
+            
       !
-      ! Put every vector to 0
-      delta_i(:,:) = 0._wp   ;
-      zpresh (:,:) = 0._wp   ;  
-      zpreshc(:,:) = 0._wp
-      u_ice2 (:,:) = 0._wp   ;   v_ice1(:,:) = 0._wp
-      divu_i (:,:) = 0._wp   ;   zdt   (:,:) = 0._wp   ;   zds(:,:) = 0._wp
-      shear_i(:,:) = 0._wp
-
-#if defined key_lim3
-      CALL lim_itd_me_icestrength( nn_icestr )      ! LIM-3: Ice strength on T-points
-#endif
-
-      DO jj = k_j1 , k_jpj       ! Ice mass and temp variables
-         DO ji = 1 , jpi
-#if defined key_lim3
-            zpresh(ji,jj) = tmask(ji,jj,1) *  strength(ji,jj)
-#endif
-#if defined key_lim2
-            zpresh(ji,jj) = tmask(ji,jj,1) *  pstar * vt_i(ji,jj) * EXP( -c_rhg * (1. - at_i(ji,jj) ) )
-#endif
-            ! zmask = 1 where there is ice or on land
-            zmask(ji,jj)    = 1._wp - ( 1._wp - MAX( 0._wp , SIGN ( 1._wp , vt_i(ji,jj) - zepsi ) ) ) * tmask(ji,jj,1)
-         END DO
-      END DO
-
-      ! Ice strength on grid cell corners (zpreshc)
-      ! needed for calculation of shear stress 
-      DO jj = k_j1+1, k_jpj-1
-         DO ji = 2, jpim1 !RB caution no fs_ (ji+1,jj+1)
-            zstms          =  tmask(ji+1,jj+1,1) * wght(ji+1,jj+1,2,2) + tmask(ji,jj+1,1) * wght(ji+1,jj+1,1,2) +   &
-               &              tmask(ji+1,jj,1)   * wght(ji+1,jj+1,2,1) + tmask(ji,jj,1)   * wght(ji+1,jj+1,1,1)
-            zpreshc(ji,jj) = ( zpresh(ji+1,jj+1) * wght(ji+1,jj+1,2,2) + zpresh(ji,jj+1) * wght(ji+1,jj+1,1,2) +   &
-               &               zpresh(ji+1,jj)   * wght(ji+1,jj+1,2,1) + zpresh(ji,jj)   * wght(ji+1,jj+1,1,1)     &
-               &             ) / MAX( zstms, zepsi )
-         END DO
-      END DO
-      CALL lbc_lnk( zpreshc(:,:), 'F', 1. )
-      !
       !------------------------------------------------------------------------------!
       ! 2) Wind / ocean stress, mass terms, coriolis terms
       !------------------------------------------------------------------------------!
-      !
-      !  Wind stress, coriolis and mass terms on the sides of the squares        
-      !  zfrld1: lead fraction on U-points                                      
-      !  zfrld2: lead fraction on V-points                                     
-      !  zmass1: ice/snow mass on U-points                                    
-      !  zmass2: ice/snow mass on V-points                                   
-      !  zcorl1: Coriolis parameter on U-points                             
-      !  zcorl2: Coriolis parameter on V-points                            
-      !  (ztagnx,ztagny): wind stress on U/V points                       
-      !  v_oce1: ocean v component on u points                          
-      !  u_oce2: ocean u component on v points                         
 
       IF( nn_ice_embd == 2 ) THEN             !== embedded sea ice: compute representative ice top surface ==!
@@ -242,5 +256,5 @@
          zintb = REAL( nn_fsbc + 1 ) / REAL( nn_fsbc ) * 0.5_wp
          !
-         zpice(:,:) = ssh_m(:,:) + (  zintn * snwice_mass(:,:) +  zintb * snwice_mass_b(:,:)  ) * r1_rau0
+         zpice(:,:) = ssh_m(:,:) + ( zintn * snwice_mass(:,:) + zintb * snwice_mass_b(:,:) ) * r1_rau0
          !
       ELSE                                    !== non-embedded sea ice: use ocean surface for slope calculation ==!
@@ -248,56 +262,51 @@
       ENDIF
 
-      DO jj = k_j1+1, k_jpj-1
+      DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1
 
-            zc1 = tmask(ji  ,jj  ,1) * ( rhosn * vt_s(ji  ,jj  ) + rhoic * vt_i(ji  ,jj  ) )
-            zc2 = tmask(ji+1,jj  ,1) * ( rhosn * vt_s(ji+1,jj  ) + rhoic * vt_i(ji+1,jj  ) )
-            zc3 = tmask(ji  ,jj+1,1) * ( rhosn * vt_s(ji  ,jj+1) + rhoic * vt_i(ji  ,jj+1) )
-
-            zt11 = tmask(ji  ,jj,1) * e1t(ji  ,jj)
-            zt12 = tmask(ji+1,jj,1) * e1t(ji+1,jj)
-            zt21 = tmask(ji,jj  ,1) * e2t(ji,jj  )
-            zt22 = tmask(ji,jj+1,1) * e2t(ji,jj+1)
-
-            ! Leads area.
-            zfrld1(ji,jj) = ( zt12 * ( 1.0 - at_i(ji,jj) ) + zt11 * ( 1.0 - at_i(ji+1,jj) ) ) / ( zt11 + zt12 + zepsi )
-            zfrld2(ji,jj) = ( zt22 * ( 1.0 - at_i(ji,jj) ) + zt21 * ( 1.0 - at_i(ji,jj+1) ) ) / ( zt21 + zt22 + zepsi )
-
-            ! Mass, coriolis coeff. and currents
-            zmass1(ji,jj) = ( zt12 * zc1 + zt11 * zc2 ) / ( zt11 + zt12 + zepsi )
-            zmass2(ji,jj) = ( zt22 * zc1 + zt21 * zc3 ) / ( zt21 + zt22 + zepsi )
-            zcorl1(ji,jj) = zmass1(ji,jj) * ( e1t(ji+1,jj) * fcor(ji,jj) + e1t(ji,jj) * fcor(ji+1,jj) )   &
-               &                          / ( e1t(ji,jj) + e1t(ji+1,jj) + zepsi )
-            zcorl2(ji,jj) = zmass2(ji,jj) * ( e2t(ji,jj+1) * fcor(ji,jj) + e2t(ji,jj) * fcor(ji,jj+1) )   &
-               &                          / ( e2t(ji,jj+1) + e2t(ji,jj) + zepsi )
-            !
-            ! Ocean has no slip boundary condition
-            v_oce1(ji,jj)  = 0.5 * ( ( v_oce(ji  ,jj) + v_oce(ji  ,jj-1) ) * e1t(ji,jj)      &
-               &                   + ( v_oce(ji+1,jj) + v_oce(ji+1,jj-1) ) * e1t(ji+1,jj) )  &
-               &                   / ( e1t(ji+1,jj) + e1t(ji,jj) ) * umask(ji,jj,1)  
-
-            u_oce2(ji,jj)  = 0.5 * ( ( u_oce(ji,jj  ) + u_oce(ji-1,jj  ) ) * e2t(ji,jj)      &
-               &                   + ( u_oce(ji,jj+1) + u_oce(ji-1,jj+1) ) * e2t(ji,jj+1) )  &
-               &                   / ( e2t(ji,jj+1) + e2t(ji,jj) ) * vmask(ji,jj,1)
-
-            ! Wind stress at U,V-point
-            ztagnx = ( 1. - zfrld1(ji,jj) ) * utau_ice(ji,jj)
-            ztagny = ( 1. - zfrld2(ji,jj) ) * vtau_ice(ji,jj)
-
-            ! Computation of the velocity field taking into account the ice internal interaction.
-            ! Terms that are independent of the velocity field.
-
-            ! SB On utilise maintenant le gradient de la pente de l'ocean
-            ! include it later
-
-            zdsshx =  ( zpice(ji+1,jj) - zpice(ji,jj) ) * r1_e1u(ji,jj)
-            zdsshy =  ( zpice(ji,jj+1) - zpice(ji,jj) ) * r1_e2v(ji,jj)
-
-            za1ct(ji,jj) = ztagnx - zmass1(ji,jj) * grav * zdsshx
-            za2ct(ji,jj) = ztagny - zmass2(ji,jj) * grav * zdsshy
+            ! ice fraction at U-V points
+            zaU(ji,jj) = 0.5_wp * ( at_i(ji,jj) * e1e2t(ji,jj) + at_i(ji+1,jj) * e1e2t(ji+1,jj) ) * r1_e1e2u(ji,jj) * umask(ji,jj,1)
+            zaV(ji,jj) = 0.5_wp * ( at_i(ji,jj) * e1e2t(ji,jj) + at_i(ji,jj+1) * e1e2t(ji,jj+1) ) * r1_e1e2v(ji,jj) * vmask(ji,jj,1)
+
+            ! Ice/snow mass at U-V points
+            zm1 = ( rhosn * vt_s(ji  ,jj  ) + rhoic * vt_i(ji  ,jj  ) )
+            zm2 = ( rhosn * vt_s(ji+1,jj  ) + rhoic * vt_i(ji+1,jj  ) )
+            zm3 = ( rhosn * vt_s(ji  ,jj+1) + rhoic * vt_i(ji  ,jj+1) )
+            zmassU = 0.5_wp * ( zm1 * e1e2t(ji,jj) + zm2 * e1e2t(ji+1,jj) ) * r1_e1e2u(ji,jj) * umask(ji,jj,1)
+            zmassV = 0.5_wp * ( zm1 * e1e2t(ji,jj) + zm3 * e1e2t(ji,jj+1) ) * r1_e1e2v(ji,jj) * vmask(ji,jj,1)
+
+            ! 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)
+
+            ! Coriolis at T points (m*f)
+            zmf(ji,jj)      = zm1 * ff_t(ji,jj)
+
+            ! m/dt
+            zmU_t(ji,jj)    = zmassU * z1_dtevp
+            zmV_t(ji,jj)    = zmassV * z1_dtevp
+
+            ! 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)
+
+            ! Surface pressure gradient (- m*g*GRAD(ssh)) at U-V points
+            zspgU(ji,jj)    = - zmassU * grav * ( zpice(ji+1,jj) - zpice(ji,jj) ) * r1_e1u(ji,jj)
+            zspgV(ji,jj)    = - zmassV * grav * ( zpice(ji,jj+1) - zpice(ji,jj) ) * r1_e2v(ji,jj)
+
+            ! 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
+
+            ! switches
+            zswitchU(ji,jj) = MAX( 0._wp, SIGN( 1._wp, zmassU - zmmin ) ) ! 0 if ice mass < zmmin
+            zswitchV(ji,jj) = MAX( 0._wp, SIGN( 1._wp, zmassV - zmmin ) ) ! 0 if ice mass < zmmin
 
          END DO
       END DO
-
+      CALL lbc_lnk( zmf, 'T', 1. )
       !
       !------------------------------------------------------------------------------!
@@ -305,252 +314,304 @@
       !------------------------------------------------------------------------------!
       !
-      ! Time step for subcycling
-      dtevp  = rdt_ice / nn_nevp
-#if defined key_lim3
-      dtotel = dtevp / ( 2._wp * rn_relast * rdt_ice )
-#else
-      dtotel = dtevp / ( 2._wp * telast )
-#endif
-      z1_dtotel = 1._wp / ( 1._wp + dtotel )
-      z1_dtevp  = 1._wp / dtevp
-      !-ecc2: square of yield ellipse eccenticrity (reminder: must become a namelist parameter)
-      ecc2 = rn_ecc * rn_ecc
-      ecci = 1. / ecc2
-
-      !-Initialise stress tensor 
-      zs1 (:,:) = stress1_i (:,:) 
-      zs2 (:,:) = stress2_i (:,:)
-      zs12(:,:) = stress12_i(:,:)
-
       !                                               !----------------------!
       DO jter = 1 , nn_nevp                           !    loop over jter    !
          !                                            !----------------------!        
-         DO jj = k_j1, k_jpj-1
-            zu_ice(:,jj) = u_ice(:,jj)    ! velocity at previous time step
-            zv_ice(:,jj) = v_ice(:,jj)
-         END DO
-
-         DO jj = k_j1+1, k_jpj-1
-            DO ji = fs_2, fs_jpim1   !RB bug no vect opt due to zmask
-
-               !  
-               !- Divergence, tension and shear (Section a. Appendix B of Hunke & Dukowicz, 2002)
-               !- divu_i(:,:), zdt(:,:): divergence and tension at centre of grid cells
-               !- zds(:,:): shear on northeast corner of grid cells
-               !
-               !- IMPORTANT REMINDER: Dear Gurvan, note that, the way these terms are coded, 
-               !                      there are many repeated calculations. 
-               !                      Speed could be improved by regrouping terms. For
-               !                      the moment, however, the stress is on clarity of coding to avoid
-               !                      bugs (Martin, for Miguel).
-               !
-               !- ALSO: arrays zdt, zds and delta could 
-               !  be removed in the future to minimise memory demand.
-               !
-               !- MORE NOTES: Note that we are calculating deformation rates and stresses on the corners of
-               !              grid cells, exactly as in the B grid case. For simplicity, the indexation on
-               !              the corners is the same as in the B grid.
-               !
-               !
-               divu_i(ji,jj) = (  e2u(ji,jj) * u_ice(ji,jj) - e2u(ji-1,jj) * u_ice(ji-1,jj)   &
-                  &             + e1v(ji,jj) * v_ice(ji,jj) - e1v(ji,jj-1) * v_ice(ji,jj-1)   &
-                  &            ) * r1_e1e2t(ji,jj)
-
-               zdt(ji,jj) = ( ( u_ice(ji,jj) * r1_e2u(ji,jj) - u_ice(ji-1,jj) * r1_e2u(ji-1,jj) ) * e2t(ji,jj) * e2t(ji,jj)   &
-                  &         - ( v_ice(ji,jj) * r1_e1v(ji,jj) - v_ice(ji,jj-1) * r1_e1v(ji,jj-1) ) * e1t(ji,jj) * e1t(ji,jj)   &
-                  &         ) * r1_e1e2t(ji,jj)
-
-               !
+         IF(ln_ctl) THEN   ! Convergence test
+            DO jj = 1, jpjm1
+               zu_ice(:,jj) = u_ice(:,jj) ! velocity at previous time step
+               zv_ice(:,jj) = v_ice(:,jj)
+            END DO
+         ENDIF
+
+         ! --- divergence, tension & shear (Appendix B of Hunke & Dukowicz, 2002) --- !
+         DO jj = 1, jpjm1         ! loops start at 1 since there is no boundary condition (lbc_lnk) at i=1 and j=1 for F points
+            DO ji = 1, jpim1
+
+               ! shear at F points
                zds(ji,jj) = ( ( u_ice(ji,jj+1) * r1_e1u(ji,jj+1) - u_ice(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj)   &
                   &         + ( v_ice(ji+1,jj) * r1_e2v(ji+1,jj) - v_ice(ji,jj) * r1_e2v(ji,jj) ) * e2f(ji,jj) * e2f(ji,jj)   &
-                  &         ) * r1_e1e2f(ji,jj) * ( 2._wp - fmask(ji,jj,1) )   &
-                  &         * zmask(ji,jj) * zmask(ji,jj+1) * zmask(ji+1,jj) * zmask(ji+1,jj+1)
-
-
-               v_ice1(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) )   &
-                  &                      / ( e1t(ji+1,jj) + e1t(ji,jj) ) * umask(ji,jj,1) 
-
-               u_ice2(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  ) )   &
-                  &                      / ( e2t(ji,jj+1) + e2t(ji,jj) ) * vmask(ji,jj,1)
-            END DO
-         END DO
-
-         CALL lbc_lnk_multi( v_ice1, 'U', -1., u_ice2, 'V', -1. )      ! lateral boundary cond.
-         
-         DO jj = k_j1+1, k_jpj-1
-            DO ji = fs_2, fs_jpim1
-
-               !- Calculate Delta at centre of grid cells
-               zdst          = ( e2u(ji,jj) * v_ice1(ji,jj) - e2u(ji-1,jj  ) * v_ice1(ji-1,jj  )   &
-                  &            + e1v(ji,jj) * u_ice2(ji,jj) - e1v(ji  ,jj-1) * u_ice2(ji  ,jj-1)   &
-                  &            ) * r1_e1e2t(ji,jj)
-
-               delta          = SQRT( divu_i(ji,jj)**2 + ( zdt(ji,jj)**2 + zdst**2 ) * usecc2 )  
-               delta_i(ji,jj) = delta + rn_creepl
-
-               !- Calculate Delta on corners
-               zddc  = (  ( v_ice1(ji,jj+1) * r1_e1u(ji,jj+1) - v_ice1(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj)  &
-                  &     + ( u_ice2(ji+1,jj) * r1_e2v(ji+1,jj) - u_ice2(ji,jj) * r1_e2v(ji,jj) ) * e2f(ji,jj) * e2f(ji,jj)  &
-                  &    ) * r1_e1e2f(ji,jj)
-
-               zdtc  = (- ( v_ice1(ji,jj+1) * r1_e1u(ji,jj+1) - v_ice1(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj)  &
-                  &     + ( u_ice2(ji+1,jj) * r1_e2v(ji+1,jj) - u_ice2(ji,jj) * r1_e2v(ji,jj) ) * e2f(ji,jj) * e2f(ji,jj)  &
-                  &    ) * r1_e1e2f(ji,jj)
-
-               zddc = SQRT( zddc**2 + ( zdtc**2 + zds(ji,jj)**2 ) * usecc2 ) + rn_creepl
-
-               !-Calculate stress tensor components zs1 and zs2 at centre of grid cells (see section 3.5 of CICE user's guide).
-               zs1(ji,jj)  = ( zs1 (ji,jj) + dtotel * ( divu_i(ji,jj) - delta ) / delta_i(ji,jj)   * zpresh(ji,jj)   &
-                  &          ) * z1_dtotel
-               zs2(ji,jj)  = ( zs2 (ji,jj) + dtotel *         ecci * zdt(ji,jj) / delta_i(ji,jj)   * zpresh(ji,jj)   &
-                  &          ) * z1_dtotel
-               !-Calculate stress tensor component zs12 at corners
-               zs12(ji,jj) = ( zs12(ji,jj) + dtotel *         ecci * zds(ji,jj) / ( 2._wp * zddc ) * zpreshc(ji,jj)  &
-                  &          ) * z1_dtotel 
-
-            END DO
-         END DO
-
-         CALL lbc_lnk_multi( zs1 , 'T', 1., zs2, 'T', 1., zs12, 'F', 1. )
+                  &         ) * r1_e1e2f(ji,jj) * zfmask(ji,jj)
+
+            END DO
+         END DO
+         CALL lbc_lnk( zds, 'F', 1. )
+
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1 ! no vector loop
+
+               ! shear**2 at T points (doc eq. A16)
+               zds2 = ( zds(ji,jj  ) * zds(ji,jj  ) * e1e2f(ji,jj  ) + zds(ji-1,jj  ) * zds(ji-1,jj  ) * e1e2f(ji-1,jj  )  &
+                  &   + zds(ji,jj-1) * zds(ji,jj-1) * e1e2f(ji,jj-1) + zds(ji-1,jj-1) * zds(ji-1,jj-1) * e1e2f(ji-1,jj-1)  &
+                  &   ) * 0.25_wp * r1_e1e2t(ji,jj)
+              
+               ! divergence at T points
+               zdiv  = ( e2u(ji,jj) * u_ice(ji,jj) - e2u(ji-1,jj) * u_ice(ji-1,jj)   &
+                  &    + e1v(ji,jj) * v_ice(ji,jj) - e1v(ji,jj-1) * v_ice(ji,jj-1)   &
+                  &    ) * r1_e1e2t(ji,jj)
+               zdiv2 = zdiv * zdiv
+               
+               ! tension at T points
+               zdt  = ( ( u_ice(ji,jj) * r1_e2u(ji,jj) - u_ice(ji-1,jj) * r1_e2u(ji-1,jj) ) * e2t(ji,jj) * e2t(ji,jj)   &
+                  &   - ( v_ice(ji,jj) * r1_e1v(ji,jj) - v_ice(ji,jj-1) * r1_e1v(ji,jj-1) ) * e1t(ji,jj) * e1t(ji,jj)   &
+                  &   ) * r1_e1e2t(ji,jj)
+               zdt2 = zdt * zdt
+               
+               ! delta at T points
+               zdelta = SQRT( zdiv2 + ( zdt2 + zds2 ) * z1_ecc2 )  
+
+               ! P/delta at T points
+               zp_delt(ji,jj) = strength(ji,jj) / ( zdelta + rn_creepl )
+               
+               ! stress at T points
+               zs1(ji,jj) = ( zs1(ji,jj) * zalph1 + zp_delt(ji,jj) * ( zdiv - zdelta ) ) * z1_alph1
+               zs2(ji,jj) = ( zs2(ji,jj) * zalph2 + zp_delt(ji,jj) * ( zdt * z1_ecc2 ) ) * z1_alph2
+             
+            END DO
+         END DO
+         CALL lbc_lnk( zp_delt, 'T', 1. )
+
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+
+               ! P/delta at F points
+               zp_delf = 0.25_wp * ( zp_delt(ji,jj) + zp_delt(ji+1,jj) + zp_delt(ji,jj+1) + zp_delt(ji+1,jj+1) )
+               
+               ! stress at F points
+               zs12(ji,jj)= ( zs12(ji,jj) * zalph2 + zp_delf * ( zds(ji,jj) * z1_ecc2 ) * 0.5_wp ) * z1_alph2
+
+            END DO
+         END DO
+         CALL lbc_lnk_multi( zs1, 'T', 1., zs2, 'T', 1., zs12, 'F', 1. )
  
-         ! Ice internal stresses (Appendix C of Hunke and Dukowicz, 2002)
-         DO jj = k_j1+1, k_jpj-1
-            DO ji = fs_2, fs_jpim1
-               !- contribution of zs1, zs2 and zs12 to zf1
-               zf1(ji,jj) = 0.5 * ( ( zs1(ji+1,jj) - zs1(ji,jj) ) * e2u(ji,jj)  &
-                  &             + ( zs2(ji+1,jj) * e2t(ji+1,jj)**2 - zs2(ji,jj) * e2t(ji,jj)**2 ) * r1_e2u(ji,jj)          &
-                  &             + 2.0 * ( zs12(ji,jj) * e1f(ji,jj)**2 - zs12(ji,jj-1) * e1f(ji,jj-1)**2 ) * r1_e1u(ji,jj)  &
-                  &                ) * r1_e1e2u(ji,jj)
-               ! contribution of zs1, zs2 and zs12 to zf2
-               zf2(ji,jj) = 0.5 * ( ( zs1(ji,jj+1) - zs1(ji,jj) ) * e1v(ji,jj)  &
-                  &             - ( zs2(ji,jj+1) * e1t(ji,jj+1)**2 - zs2(ji,jj) * e1t(ji,jj)**2 ) * r1_e1v(ji,jj)          &
-                  &             + 2.0 * ( zs12(ji,jj) * e2f(ji,jj)**2 - zs12(ji-1,jj) * e2f(ji-1,jj)**2 ) * r1_e2v(ji,jj)  &
-                  &               )  * r1_e1e2v(ji,jj)
+
+         ! --- Ice internal stresses (Appendix C of Hunke and Dukowicz, 2002) --- !
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1               
+
+               ! U points
+               zfU(ji,jj) = 0.5_wp * ( ( zs1(ji+1,jj) - zs1(ji,jj) ) * e2u(ji,jj)                                             &
+                  &                  + ( zs2(ji+1,jj) * e2t(ji+1,jj) * e2t(ji+1,jj) - zs2(ji,jj) * e2t(ji,jj) * e2t(ji,jj)    &
+                  &                    ) * r1_e2u(ji,jj)                                                                      &
+                  &                  + ( zs12(ji,jj) * e1f(ji,jj) * e1f(ji,jj) - zs12(ji,jj-1) * e1f(ji,jj-1) * e1f(ji,jj-1)  &
+                  &                    ) * 2._wp * r1_e1u(ji,jj)                                                              &
+                  &                  ) * r1_e1e2u(ji,jj)
+
+               ! V points
+               zfV(ji,jj) = 0.5_wp * ( ( zs1(ji,jj+1) - zs1(ji,jj) ) * e1v(ji,jj)                                             &
+                  &                  - ( zs2(ji,jj+1) * e1t(ji,jj+1) * e1t(ji,jj+1) - zs2(ji,jj) * e1t(ji,jj) * e1t(ji,jj)    &
+                  &                    ) * r1_e1v(ji,jj)                                                                      &
+                  &                  + ( zs12(ji,jj) * e2f(ji,jj) * e2f(ji,jj) - zs12(ji-1,jj) * e2f(ji-1,jj) * e2f(ji-1,jj)  &
+                  &                    ) * 2._wp * r1_e2v(ji,jj)                                                              &
+                  &                  ) * 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)
+               
+               ! 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
          !
-         ! Computation of ice velocity
-         !
-         ! Both the Coriolis term and the ice-ocean drag are solved semi-implicitly.
-         !
-         IF (MOD(jter,2).eq.0) THEN 
-
-            DO jj = k_j1+1, k_jpj-1
+         ! --- Computation of ice velocity --- !
+         !  Bouillon et al. 2013 (eq 47-48) => unstable unless alpha, beta are chosen wisely and large nn_nevp
+         !  Bouillon et al. 2009 (eq 34-35) => stable
+         IF( MOD(jter,2) .EQ. 0 ) THEN ! even iterations
+            
+            DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1
-                  rswitch      = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zmass1(ji,jj) ) ) ) * umask(ji,jj,1)
-                  z0           = zmass1(ji,jj) * z1_dtevp
-
-                  ! SB modif because ocean has no slip boundary condition
-                  zv_ice1      = 0.5 * ( ( v_ice(ji  ,jj) + v_ice(ji  ,jj-1) ) * e1t(ji  ,jj)     &
-                     &                 + ( v_ice(ji+1,jj) + v_ice(ji+1,jj-1) ) * e1t(ji+1,jj) )   &
-                     &                 / ( e1t(ji+1,jj) + e1t(ji,jj) ) * umask(ji,jj,1)
-                  za           = rhoco * SQRT( ( u_ice(ji,jj) - u_oce(ji,jj) )**2 +  &
-                     &                         ( zv_ice1 - v_oce1(ji,jj) )**2 ) * ( 1.0 - zfrld1(ji,jj) )
-                  zr           = z0 * u_ice(ji,jj) + zf1(ji,jj) + za1ct(ji,jj) + za * u_oce(ji,jj)
-                  zcca         = z0 + za
-                  zccb         = zcorl1(ji,jj)
-                  u_ice(ji,jj) = ( zr + zccb * zv_ice1 ) / ( zcca + zepsi ) * rswitch 
+
+                  ! tau_io/(v_oce - v_ice)
+                  zTauO = zaV(ji,jj) * zrhoco * SQRT( ( v_ice (ji,jj) - v_oce (ji,jj) ) * ( v_ice (ji,jj) - v_oce (ji,jj) )  &
+                     &                              + ( u_iceV(ji,jj) - u_oceV(ji,jj) ) * ( u_iceV(ji,jj) - u_oceV(ji,jj) ) )
+
+                  ! tau_bottom/v_ice
+                  zvel  = MAX( zepsi, SQRT( v_ice(ji,jj) * v_ice(ji,jj) + u_iceV(ji,jj) * u_iceV(ji,jj) ) )
+                  zTauB = - tau_icebfr(ji,jj) / zvel
+
+                  ! Coriolis at V-points (energy conserving formulation)
+                  zCor  = - 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) + zCor + zspgV(ji,jj) + zTauO * ( v_oce(ji,jj) - v_ice(ji,jj) )
+
+                  ! landfast switch => 0 = static friction ; 1 = sliding friction
+                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, ztauE - tau_icebfr(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
+                  
+                  ! ice velocity using 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) * ( 1._wp - zswitchV(ji,jj) )        &  ! v_ice = v_oce if mass < zmmin
+                     &           ) * zmaskV(ji,jj)
+                  ! Bouillon 2013
+                  !!v_ice(ji,jj) = ( zmV_t(ji,jj) * ( zbeta * v_ice(ji,jj) + v_ice_b(ji,jj) )                  &
+                  !!   &           + zfV(ji,jj) + zCor + zTauV_ia(ji,jj) + zTauO * v_oce(ji,jj) + zspgV(ji,jj)  &
+                  !!   &           ) / MAX( zmV_t(ji,jj) * ( zbeta + 1._wp ) + zTauO - zTauB, zepsi ) * zswitchV(ji,jj)
+
                END DO
             END DO
-
-            CALL lbc_lnk( u_ice(:,:), 'U', -1. )
-#if defined key_agrif && defined key_lim2
-            CALL agrif_rhg_lim2( jter, nn_nevp, 'U' )
+            CALL lbc_lnk( v_ice, 'V', -1. )
+            
+#if defined key_agrif
+!!            CALL agrif_interp_lim3( 'V', jter, nn_nevp )
+            CALL agrif_interp_lim3( 'V' )
 #endif
 #if defined key_bdy
-         CALL bdy_ice_lim_dyn( 'U' )
+            CALL bdy_ice_lim_dyn( 'V' )
 #endif         
 
-            DO jj = k_j1+1, k_jpj-1
+            DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1
-
-                  rswitch      = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zmass2(ji,jj) ) ) ) * vmask(ji,jj,1)
-                  z0           = zmass2(ji,jj) * z1_dtevp
-                  ! SB modif because ocean has no slip boundary condition
-                  zu_ice2      = 0.5 * ( ( u_ice(ji,jj  ) + u_ice(ji-1,jj  ) ) * e2t(ji,jj)       &
-                     &                 + ( u_ice(ji,jj+1) + u_ice(ji-1,jj+1) ) * e2t(ji,jj+1) )   &
-                     &                 / ( e2t(ji,jj+1) + e2t(ji,jj) ) * vmask(ji,jj,1)
-                  za           = rhoco * SQRT( ( zu_ice2 - u_oce2(ji,jj) )**2 +  & 
-                     &                         ( v_ice(ji,jj) - v_oce(ji,jj))**2 ) * ( 1.0 - zfrld2(ji,jj) )
-                  zr           = z0 * v_ice(ji,jj) + zf2(ji,jj) + za2ct(ji,jj) + za * v_oce(ji,jj)
-                  zcca         = z0 + za
-                  zccb         = zcorl2(ji,jj)
-                  v_ice(ji,jj) = ( zr - zccb * zu_ice2 ) / ( zcca + zepsi ) * rswitch
+                               
+                  ! tau_io/(u_oce - u_ice)
+                  zTauO = zaU(ji,jj) * zrhoco * SQRT( ( u_ice (ji,jj) - u_oce (ji,jj) ) * ( u_ice (ji,jj) - u_oce (ji,jj) )  &
+                     &                              + ( v_iceU(ji,jj) - v_oceU(ji,jj) ) * ( v_iceU(ji,jj) - v_oceU(ji,jj) ) )
+
+                  ! tau_bottom/u_ice
+                  zvel  = MAX( zepsi, SQRT( v_iceU(ji,jj) * v_iceU(ji,jj) + u_ice(ji,jj) * u_ice(ji,jj) ) )
+                  zTauB = - tau_icebfr(ji,jj) / zvel
+
+                  ! Coriolis at U-points (energy conserving formulation)
+                  zCor  =   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) + zCor + zspgU(ji,jj) + zTauO * ( u_oce(ji,jj) - u_ice(ji,jj) )
+
+                  ! landfast switch => 0 = static friction ; 1 = sliding friction
+                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, ztauE - tau_icebfr(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
+
+                  ! ice velocity using 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) * ( 1._wp - zswitchU(ji,jj) )        &  ! v_ice = v_oce if mass < zmmin 
+                     &           ) * zmaskU(ji,jj)
+                  ! Bouillon 2013
+                  !!u_ice(ji,jj) = ( zmU_t(ji,jj) * ( zbeta * u_ice(ji,jj) + u_ice_b(ji,jj) )                  &
+                  !!   &           + zfU(ji,jj) + zCor + zTauU_ia(ji,jj) + zTauO * u_oce(ji,jj) + zspgU(ji,jj)  &
+                  !!   &           ) / MAX( zmU_t(ji,jj) * ( zbeta + 1._wp ) + zTauO - zTauB, zepsi ) * zswitchU(ji,jj)
                END DO
             END DO
-
-            CALL lbc_lnk( v_ice(:,:), 'V', -1. )
-#if defined key_agrif && defined key_lim2
-            CALL agrif_rhg_lim2( jter, nn_nevp, 'V' )
+            CALL lbc_lnk( u_ice, 'U', -1. )
+            
+#if defined key_agrif
+!!            CALL agrif_interp_lim3( 'U', jter, nn_nevp )
+            CALL agrif_interp_lim3( 'U' )
 #endif
 #if defined key_bdy
-         CALL bdy_ice_lim_dyn( 'V' )
+            CALL bdy_ice_lim_dyn( 'U' )
 #endif         
 
-         ELSE 
-            DO jj = k_j1+1, k_jpj-1
+         ELSE ! odd iterations
+
+            DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1
-                  rswitch      = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zmass2(ji,jj) ) ) ) * vmask(ji,jj,1)
-                  z0           = zmass2(ji,jj) * z1_dtevp
-                  ! SB modif because ocean has no slip boundary condition
-                  zu_ice2      = 0.5 * ( ( u_ice(ji,jj  ) + u_ice(ji-1,jj  ) ) * e2t(ji,jj)       &
-                     &                  +( u_ice(ji,jj+1) + u_ice(ji-1,jj+1) ) * e2t(ji,jj+1) )   &
-                     &                 / ( e2t(ji,jj+1) + e2t(ji,jj) ) * vmask(ji,jj,1)   
-
-                  za           = rhoco * SQRT( ( zu_ice2 - u_oce2(ji,jj) )**2 +  &
-                     &                         ( v_ice(ji,jj) - v_oce(ji,jj) )**2 ) * ( 1.0 - zfrld2(ji,jj) )
-                  zr           = z0 * v_ice(ji,jj) + zf2(ji,jj) + za2ct(ji,jj) + za * v_oce(ji,jj)
-                  zcca         = z0 + za
-                  zccb         = zcorl2(ji,jj)
-                  v_ice(ji,jj) = ( zr - zccb * zu_ice2 ) / ( zcca + zepsi ) * rswitch
+
+                  ! tau_io/(u_oce - u_ice)
+                  zTauO = zaU(ji,jj) * zrhoco * SQRT( ( u_ice (ji,jj) - u_oce (ji,jj) ) * ( u_ice (ji,jj) - u_oce (ji,jj) )  &
+                     &                              + ( v_iceU(ji,jj) - v_oceU(ji,jj) ) * ( v_iceU(ji,jj) - v_oceU(ji,jj) ) )
+
+                  ! tau_bottom/u_ice
+                  zvel  = MAX( zepsi, SQRT( v_iceU(ji,jj) * v_iceU(ji,jj) + u_ice(ji,jj) * u_ice(ji,jj) ) )
+                  zTauB = - tau_icebfr(ji,jj) / zvel
+
+                  ! Coriolis at U-points (energy conserving formulation)
+                  zCor  =   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) + zCor + zspgU(ji,jj) + zTauO * ( u_oce(ji,jj) - u_ice(ji,jj) )
+
+                  ! landfast switch => 0 = static friction ; 1 = sliding friction
+                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, ztauE - tau_icebfr(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
+
+                  ! ice velocity using 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) * ( 1._wp - zswitchU(ji,jj) )        &  ! v_ice = v_oce if mass < zmmin
+                     &           ) * zmaskU(ji,jj)
+                  ! Bouillon 2013
+                  !!u_ice(ji,jj) = ( zmU_t(ji,jj) * ( zbeta * u_ice(ji,jj) + u_ice_b(ji,jj) )                  &
+                  !!   &           + zfU(ji,jj) + zCor + zTauU_ia(ji,jj) + zTauO * u_oce(ji,jj) + zspgU(ji,jj)  &
+                  !!   &           ) / MAX( zmU_t(ji,jj) * ( zbeta + 1._wp ) + zTauO - zTauB, zepsi ) * zswitchU(ji,jj)
                END DO
             END DO
-
-            CALL lbc_lnk( v_ice(:,:), 'V', -1. )
-#if defined key_agrif && defined key_lim2
-            CALL agrif_rhg_lim2( jter, nn_nevp, 'V' )
+            CALL lbc_lnk( u_ice, 'U', -1. )
+            
+#if defined key_agrif
+!!            CALL agrif_interp_lim3( 'U', jter, nn_nevp )
+            CALL agrif_interp_lim3( 'U' )
 #endif
 #if defined key_bdy
-         CALL bdy_ice_lim_dyn( 'V' )
+            CALL bdy_ice_lim_dyn( 'U' )
 #endif         
 
-            DO jj = k_j1+1, k_jpj-1
+            DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1
-                  rswitch      = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zmass1(ji,jj) ) ) ) * umask(ji,jj,1)
-                  z0           = zmass1(ji,jj) * z1_dtevp
-                  zv_ice1      = 0.5 * ( ( v_ice(ji  ,jj) + v_ice(ji  ,jj-1) ) * e1t(ji,jj)       &
-                     &                 + ( v_ice(ji+1,jj) + v_ice(ji+1,jj-1) ) * e1t(ji+1,jj) )   &
-                     &                 / ( e1t(ji+1,jj) + e1t(ji,jj) ) * umask(ji,jj,1)
-
-                  za           = rhoco * SQRT( ( u_ice(ji,jj) - u_oce(ji,jj) )**2 +  &
-                     &                         ( zv_ice1 - v_oce1(ji,jj) )**2 ) * ( 1.0 - zfrld1(ji,jj) )
-                  zr           = z0 * u_ice(ji,jj) + zf1(ji,jj) + za1ct(ji,jj) + za * u_oce(ji,jj)
-                  zcca         = z0 + za
-                  zccb         = zcorl1(ji,jj)
-                  u_ice(ji,jj) = ( zr + zccb * zv_ice1 ) / ( zcca + zepsi ) * rswitch 
+         
+                  ! tau_io/(v_oce - v_ice)
+                  zTauO = zaV(ji,jj) * zrhoco * SQRT( ( v_ice (ji,jj) - v_oce (ji,jj) ) * ( v_ice (ji,jj) - v_oce (ji,jj) )  &
+                     &                              + ( u_iceV(ji,jj) - u_oceV(ji,jj) ) * ( u_iceV(ji,jj) - u_oceV(ji,jj) ) )
+
+                  ! tau_bottom/v_ice
+                  zvel  = MAX( zepsi, SQRT( v_ice(ji,jj) * v_ice(ji,jj) + u_iceV(ji,jj) * u_iceV(ji,jj) ) )
+                  ztauB = - tau_icebfr(ji,jj) / zvel
+                  
+                  ! Coriolis at V-points (energy conserving formulation)
+                  zCor  = - 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) + zCor + zspgV(ji,jj) + zTauO * ( v_oce(ji,jj) - v_ice(ji,jj) )
+
+                  ! landfast switch => 0 = static friction (tau_icebfr > zTauE); 1 = sliding friction
+                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, zTauE - tau_icebfr(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
+                  
+                  ! ice velocity using 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) * ( 1._wp - zswitchV(ji,jj) )        &  ! v_ice = v_oce if mass < zmmin
+                     &           ) * zmaskV(ji,jj)
+                  ! Bouillon 2013
+                  !!v_ice(ji,jj) = ( zmV_t(ji,jj) * ( zbeta * v_ice(ji,jj) + v_ice_b(ji,jj) )                  &
+                  !!   &           + zfV(ji,jj) + zCor + zTauV_ia(ji,jj) + zTauO * v_oce(ji,jj) + zspgV(ji,jj)  &
+                  !!   &           ) / MAX( zmV_t(ji,jj) * ( zbeta + 1._wp ) + zTauO - zTauB, zepsi ) * zswitchV(ji,jj)
                END DO
             END DO
-
-            CALL lbc_lnk( u_ice(:,:), 'U', -1. )
-#if defined key_agrif && defined key_lim2
-            CALL agrif_rhg_lim2( jter, nn_nevp, 'U' )
+            CALL lbc_lnk( v_ice, 'V', -1. )
+            
+#if defined key_agrif
+!!            CALL agrif_interp_lim3( 'V', jter, nn_nevp )
+            CALL agrif_interp_lim3( 'V' )
 #endif
 #if defined key_bdy
-         CALL bdy_ice_lim_dyn( 'U' )
+            CALL bdy_ice_lim_dyn( 'V' )
 #endif         
 
          ENDIF
          
-         IF(ln_ctl) THEN
-            !---  Convergence test.
-            DO jj = k_j1+1 , k_jpj-1
+         IF(ln_ctl) THEN   ! Convergence test
+            DO jj = 2 , jpjm1
                zresr(:,jj) = MAX( ABS( u_ice(:,jj) - zu_ice(:,jj) ), ABS( v_ice(:,jj) - zv_ice(:,jj) ) )
             END DO
-            zresm = MAXVAL( zresr( 1:jpi, k_j1+1:k_jpj-1 ) )
+            zresm = MAXVAL( zresr( 1:jpi, 2:jpjm1 ) )
             IF( lk_mpp )   CALL mpp_max( zresm )   ! max over the global domain
          ENDIF
-
+         !
          !                                                ! ==================== !
       END DO                                              !  end loop over jter  !
@@ -558,99 +619,57 @@
       !
       !------------------------------------------------------------------------------!
-      ! 4) Prevent ice velocities when the ice is thin
-      !------------------------------------------------------------------------------!
-      ! If the ice volume is below zvmin then ice velocity should equal the
-      ! ocean velocity. This prevents high velocity when ice is thin
-      DO jj = k_j1+1, k_jpj-1
-         DO ji = fs_2, fs_jpim1
-            IF ( vt_i(ji,jj) <= zvmin ) THEN
-               u_ice(ji,jj) = u_oce(ji,jj)
-               v_ice(ji,jj) = v_oce(ji,jj)
-            ENDIF
+      ! 4) Recompute delta, shear and div (inputs for mechanical redistribution) 
+      !------------------------------------------------------------------------------!
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+
+            ! shear at F points
+            zds(ji,jj) = ( ( u_ice(ji,jj+1) * r1_e1u(ji,jj+1) - u_ice(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj)   &
+               &         + ( v_ice(ji+1,jj) * r1_e2v(ji+1,jj) - v_ice(ji,jj) * r1_e2v(ji,jj) ) * e2f(ji,jj) * e2f(ji,jj)   &
+               &         ) * r1_e1e2f(ji,jj) * zfmask(ji,jj)
+
+         END DO
+      END DO           
+      CALL lbc_lnk( zds, 'F', 1. )
+      
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1 ! no vector loop
+            
+            ! tension**2 at T points
+            zdt  = ( ( u_ice(ji,jj) * r1_e2u(ji,jj) - u_ice(ji-1,jj) * r1_e2u(ji-1,jj) ) * e2t(ji,jj) * e2t(ji,jj)   &
+               &   - ( v_ice(ji,jj) * r1_e1v(ji,jj) - v_ice(ji,jj-1) * r1_e1v(ji,jj-1) ) * e1t(ji,jj) * e1t(ji,jj)   &
+               &   ) * r1_e1e2t(ji,jj)
+            zdt2 = zdt * zdt
+            
+            ! shear**2 at T points (doc eq. A16)
+            zds2 = ( zds(ji,jj  ) * zds(ji,jj  ) * e1e2f(ji,jj  ) + zds(ji-1,jj  ) * zds(ji-1,jj  ) * e1e2f(ji-1,jj  )  &
+               &   + zds(ji,jj-1) * zds(ji,jj-1) * e1e2f(ji,jj-1) + zds(ji-1,jj-1) * zds(ji-1,jj-1) * e1e2f(ji-1,jj-1)  &
+               &   ) * 0.25_wp * r1_e1e2t(ji,jj)
+            
+            ! shear at T points
+            shear_i(ji,jj) = SQRT( zdt2 + zds2 )
+
+            ! divergence at T points
+            divu_i(ji,jj) = ( e2u(ji,jj) * u_ice(ji,jj) - e2u(ji-1,jj) * u_ice(ji-1,jj)   &
+               &            + e1v(ji,jj) * v_ice(ji,jj) - e1v(ji,jj-1) * v_ice(ji,jj-1)   &
+               &            ) * r1_e1e2t(ji,jj)
+            
+            ! delta at T points
+            zdelta         = SQRT( divu_i(ji,jj) * divu_i(ji,jj) + ( zdt2 + zds2 ) * z1_ecc2 )  
+            rswitch        = 1._wp - MAX( 0._wp, SIGN( 1._wp, -zdelta ) ) ! 0 if delta=0
+            delta_i(ji,jj) = zdelta + rn_creepl * rswitch
+
          END DO
       END DO
-
-      CALL lbc_lnk_multi( u_ice(:,:), 'U', -1., v_ice(:,:), 'V', -1. )
-
-#if defined key_agrif && defined key_lim2
-      CALL agrif_rhg_lim2( nn_nevp , nn_nevp, 'U' )
-      CALL agrif_rhg_lim2( nn_nevp , nn_nevp, 'V' )
-#endif
-#if defined key_bdy
-      CALL bdy_ice_lim_dyn( 'U' )
-      CALL bdy_ice_lim_dyn( 'V' )
-#endif         
-
-      DO jj = k_j1+1, k_jpj-1 
-         DO ji = fs_2, fs_jpim1
-            IF ( vt_i(ji,jj) <= zvmin ) THEN
-               v_ice1(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) )   &
-                  &                      / ( e1t(ji+1,jj) + e1t(ji,jj) ) * umask(ji,jj,1)
-
-               u_ice2(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  ) )   &
-                  &                      / ( e2t(ji,jj+1) + e2t(ji,jj) ) * vmask(ji,jj,1)
-            ENDIF 
-         END DO
-      END DO
-
-      CALL lbc_lnk_multi( u_ice2(:,:), 'V', -1., v_ice1(:,:), 'U', -1. )
-
-      ! Recompute delta, shear and div, inputs for mechanical redistribution 
-      DO jj = k_j1+1, k_jpj-1
-         DO ji = fs_2, jpim1   !RB bug no vect opt due to zmask
-            !- divu_i(:,:), zdt(:,:): divergence and tension at centre 
-            !- zds(:,:): shear on northeast corner of grid cells
-            IF ( vt_i(ji,jj) <= zvmin ) THEN
-
-               divu_i(ji,jj) = (  e2u(ji,jj) * u_ice(ji,jj) - e2u(ji-1,jj  ) * u_ice(ji-1,jj  )   &
-                  &             + e1v(ji,jj) * v_ice(ji,jj) - e1v(ji  ,jj-1) * v_ice(ji  ,jj-1)   &
-                  &            ) * r1_e1e2t(ji,jj)
-
-               zdt(ji,jj) = ( ( u_ice(ji,jj) * r1_e2u(ji,jj) - u_ice(ji-1,jj) * r1_e2u(ji-1,jj) ) * e2t(ji,jj) * e2t(ji,jj)  &
-                  &          -( v_ice(ji,jj) * r1_e1v(ji,jj) - v_ice(ji,jj-1) * r1_e1v(ji,jj-1) ) * e1t(ji,jj) * e1t(ji,jj)  &
-                  &         ) * r1_e1e2t(ji,jj)
-               !
-               ! SB modif because ocean has no slip boundary condition 
-               zds(ji,jj) = ( ( u_ice(ji,jj+1) * r1_e1u(ji,jj+1) - u_ice(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj)  &
-                  &          +( v_ice(ji+1,jj) * r1_e2v(ji+1,jj) - v_ice(ji,jj) * r1_e2v(ji,jj) ) * e2f(ji,jj) * e2f(ji,jj)  &
-                  &         ) * r1_e1e2f(ji,jj) * ( 2.0 - fmask(ji,jj,1) )                                     &
-                  &         * zmask(ji,jj) * zmask(ji,jj+1) * zmask(ji+1,jj) * zmask(ji+1,jj+1)
-
-               zdst = ( e2u(ji,jj) * v_ice1(ji,jj) - e2u(ji-1,jj  ) * v_ice1(ji-1,jj  )    &
-                  &   + e1v(ji,jj) * u_ice2(ji,jj) - e1v(ji  ,jj-1) * u_ice2(ji  ,jj-1) ) * r1_e1e2t(ji,jj)
-
-               delta = SQRT( divu_i(ji,jj)**2 + ( zdt(ji,jj)**2 + zdst**2 ) * usecc2 )  
-               delta_i(ji,jj) = delta + rn_creepl
-            
-            ENDIF
-         END DO
-      END DO
-      !
-      !------------------------------------------------------------------------------!
-      ! 5) Store stress tensor and its invariants
-      !------------------------------------------------------------------------------!
-      ! * Invariants of the stress tensor are required for limitd_me
-      !   (accelerates convergence and improves stability)
-      DO jj = k_j1+1, k_jpj-1
-         DO ji = fs_2, fs_jpim1
-            zdst           = (  e2u(ji,jj) * v_ice1(ji,jj) - e2u( ji-1, jj   ) * v_ice1(ji-1,jj)  &   
-               &              + e1v(ji,jj) * u_ice2(ji,jj) - e1v( ji  , jj-1 ) * u_ice2(ji,jj-1) ) * r1_e1e2t(ji,jj) 
-            shear_i(ji,jj) = SQRT( zdt(ji,jj) * zdt(ji,jj) + zdst * zdst )
-         END DO
-      END DO
-
-      ! Lateral boundary condition
-      CALL lbc_lnk_multi( divu_i (:,:), 'T', 1., delta_i(:,:), 'T', 1.,  shear_i(:,:), 'T', 1. )
-
-      ! * Store the stress tensor for the next time step
+      CALL lbc_lnk_multi( shear_i, 'T', 1., divu_i, 'T', 1., delta_i, 'T', 1. )
+      
+      ! --- Store the stress tensor for the next time step --- !
       stress1_i (:,:) = zs1 (:,:)
       stress2_i (:,:) = zs2 (:,:)
       stress12_i(:,:) = zs12(:,:)
-
       !
-      !------------------------------------------------------------------------------!
-      ! 6) Control prints of residual and charge ellipse
+
+      !------------------------------------------------------------------------------!
+      ! 5) Control prints of residual and charge ellipse
       !------------------------------------------------------------------------------!
       !
@@ -672,9 +691,9 @@
             WRITE(charout,FMT="('lim_rhg  :', I4, I6, I1, I1, A10)") 1000, numit, 0, 0, ' ch. ell. '
             CALL prt_ctl_info(charout)
-            DO jj = k_j1+1, k_jpj-1
+            DO jj = 2, jpjm1
                DO ji = 2, jpim1
-                  IF (zpresh(ji,jj) > 1.0) THEN
-                     sigma1 = ( zs1(ji,jj) + (zs2(ji,jj)**2 + 4*zs12(ji,jj)**2 )**0.5 ) / ( 2*zpresh(ji,jj) ) 
-                     sigma2 = ( zs1(ji,jj) - (zs2(ji,jj)**2 + 4*zs12(ji,jj)**2 )**0.5 ) / ( 2*zpresh(ji,jj) )
+                  IF (strength(ji,jj) > 1.0) THEN
+                     zsig1 = ( zs1(ji,jj) + SQRT(zs2(ji,jj)**2 + 4*zs12(ji,jj)**2 ) ) / ( 2*strength(ji,jj) ) 
+                     zsig2 = ( zs1(ji,jj) - SQRT(zs2(ji,jj)**2 + 4*zs12(ji,jj)**2 ) ) / ( 2*strength(ji,jj) )
                      WRITE(charout,FMT="('lim_rhg  :', I4, I4, D23.16, D23.16, D23.16, D23.16, A10)")
                      CALL prt_ctl_info(charout)
@@ -686,9 +705,11 @@
          ENDIF
       ENDIF
-      !
-      CALL wrk_dealloc( jpi,jpj, zpresh, zfrld1, zmass1, zcorl1, za1ct , zpreshc, zfrld2, zmass2, zcorl2, za2ct )
-      CALL wrk_dealloc( jpi,jpj, u_oce2, u_ice2, v_oce1 , v_ice1 , zmask               )
-      CALL wrk_dealloc( jpi,jpj, zf1   , zu_ice, zf2   , zv_ice , zdt    , zds  )
-      CALL wrk_dealloc( jpi,jpj, zs1   , zs2   , zs12   , zresr , zpice                 )
+      !     
+      
+      CALL wrk_dealloc( jpi,jpj, z1_e1t0, z1_e2t0, zp_delt )
+      CALL wrk_dealloc( jpi,jpj, zaU, zaV, zmU_t, zmV_t, zmf, zTauU_ia, ztauV_ia )
+      CALL wrk_dealloc( jpi,jpj, zspgU, zspgV, v_oceU, u_oceV, v_iceU, u_iceV, zfU, zfV )
+      CALL wrk_dealloc( jpi,jpj, zds, zs1, zs2, zs12, zu_ice, zv_ice, zresr, zpice )
+      CALL wrk_dealloc( jpi,jpj, zswitchU, zswitchV, zmaskU, zmaskV, zfmask, zwf )
 
    END SUBROUTINE lim_rhg
@@ -699,6 +720,6 @@
    !!----------------------------------------------------------------------
 CONTAINS
-   SUBROUTINE lim_rhg( k1 , k2 )         ! Dummy routine
-      WRITE(*,*) 'lim_rhg: You should not have seen this print! error?', k1, k2
+   SUBROUTINE lim_rhg         ! Dummy routine
+      WRITE(*,*) 'lim_rhg: You should not have seen this print! error?'
    END SUBROUTINE lim_rhg
 #endif
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90	(revision 7309)
@@ -53,6 +53,6 @@
       INTEGER, INTENT(in) ::   kt       ! number of iteration
       !
-      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step define as a character
-      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
+      CHARACTER(len=20)   ::   clkt     ! ocean time-step define as a character
+      CHARACTER(len=50)   ::   clname   ! ice output restart file name
       CHARACTER(len=256)  ::   clpath   ! full path to ice output restart file 
       !!----------------------------------------------------------------------
@@ -91,5 +91,5 @@
       ENDIF
       !
-      IF( ln_icectl )   CALL lim_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' )   ! control print
+      IF( ln_limctl )   CALL lim_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' )   ! control print
    END SUBROUTINE lim_rst_opn
 
@@ -105,6 +105,6 @@
       INTEGER ::   ji, jj, jk ,jl   ! dummy loop indices
       INTEGER ::   iter
-      CHARACTER(len=15) ::   znam
-      CHARACTER(len=1)  ::   zchar, zchar1
+      CHARACTER(len=25) ::   znam
+      CHARACTER(len=2)  ::   zchar, zchar1
       REAL(wp), POINTER, DIMENSION(:,:) :: z2d
       !!----------------------------------------------------------------------
@@ -128,5 +128,5 @@
       ! Prognostic variables 
       DO jl = 1, jpl 
-         WRITE(zchar,'(I1)') jl
+         WRITE(zchar,'(I2.2)') jl
          znam = 'v_i'//'_htc'//zchar
          z2d(:,:) = v_i(:,:,jl)
@@ -150,5 +150,5 @@
 
       DO jl = 1, jpl 
-         WRITE(zchar,'(I1)') jl
+         WRITE(zchar,'(I2.2)') jl
          znam = 'tempt_sl1'//'_htc'//zchar
          z2d(:,:) = e_s(:,:,1,jl)
@@ -157,7 +157,7 @@
 
       DO jl = 1, jpl 
-         WRITE(zchar,'(I1)') jl
+         WRITE(zchar,'(I2.2)') jl
          DO jk = 1, nlay_i 
-            WRITE(zchar1,'(I1)') jk
+            WRITE(zchar1,'(I2.2)') jk
             znam = 'tempt'//'_il'//zchar1//'_htc'//zchar
             z2d(:,:) = e_i(:,:,jk,jl)
@@ -174,128 +174,136 @@
       CALL iom_rstput( iter, nitrst, numriw, 'snwice_mass_b', snwice_mass_b )
 
-      DO jl = 1, jpl 
-         WRITE(zchar,'(I1)') jl
-         znam = 'sxice'//'_htc'//zchar
-         z2d(:,:) = sxice(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'syice'//'_htc'//zchar
-         z2d(:,:) = syice(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxxice'//'_htc'//zchar
-         z2d(:,:) = sxxice(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'syyice'//'_htc'//zchar
-         z2d(:,:) = syyice(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxyice'//'_htc'//zchar
-         z2d(:,:) = sxyice(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxsn'//'_htc'//zchar
-         z2d(:,:) = sxsn(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sysn'//'_htc'//zchar
-         z2d(:,:) = sysn(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxxsn'//'_htc'//zchar
-         z2d(:,:) = sxxsn(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'syysn'//'_htc'//zchar
-         z2d(:,:) = syysn(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxysn'//'_htc'//zchar
-         z2d(:,:) = sxysn(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxa'//'_htc'//zchar
-         z2d(:,:) = sxa(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sya'//'_htc'//zchar
-         z2d(:,:) = sya(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxxa'//'_htc'//zchar
-         z2d(:,:) = sxxa(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'syya'//'_htc'//zchar
-         z2d(:,:) = syya(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxya'//'_htc'//zchar
-         z2d(:,:) = sxya(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxc0'//'_htc'//zchar
-         z2d(:,:) = sxc0(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'syc0'//'_htc'//zchar
-         z2d(:,:) = syc0(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxxc0'//'_htc'//zchar
-         z2d(:,:) = sxxc0(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'syyc0'//'_htc'//zchar
-         z2d(:,:) = syyc0(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxyc0'//'_htc'//zchar
-         z2d(:,:) = sxyc0(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxsal'//'_htc'//zchar
-         z2d(:,:) = sxsal(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sysal'//'_htc'//zchar
-         z2d(:,:) = sysal(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxxsal'//'_htc'//zchar
-         z2d(:,:) = sxxsal(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'syysal'//'_htc'//zchar
-         z2d(:,:) = syysal(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxysal'//'_htc'//zchar
-         z2d(:,:) = sxysal(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxage'//'_htc'//zchar
-         z2d(:,:) = sxage(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'syage'//'_htc'//zchar
-         z2d(:,:) = syage(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxxage'//'_htc'//zchar
-         z2d(:,:) = sxxage(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'syyage'//'_htc'//zchar
-         z2d(:,:) = syyage(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'sxyage'//'_htc'//zchar
-         z2d(:,:) = sxyage(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-      END DO
-
-      CALL iom_rstput( iter, nitrst, numriw, 'sxopw ' ,  sxopw  )
-      CALL iom_rstput( iter, nitrst, numriw, 'syopw ' ,  syopw  )
-      CALL iom_rstput( iter, nitrst, numriw, 'sxxopw' ,  sxxopw )
-      CALL iom_rstput( iter, nitrst, numriw, 'syyopw' ,  syyopw )
-      CALL iom_rstput( iter, nitrst, numriw, 'sxyopw' ,  sxyopw )
-
-      DO jl = 1, jpl 
-         WRITE(zchar,'(I1)') jl
-         DO jk = 1, nlay_i 
-            WRITE(zchar1,'(I1)') jk
-            znam = 'sxe'//'_il'//zchar1//'_htc'//zchar
-            z2d(:,:) = sxe(:,:,jk,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sye'//'_il'//zchar1//'_htc'//zchar
-            z2d(:,:) = sye(:,:,jk,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxxe'//'_il'//zchar1//'_htc'//zchar
-            z2d(:,:) = sxxe(:,:,jk,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'syye'//'_il'//zchar1//'_htc'//zchar
-            z2d(:,:) = syye(:,:,jk,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxye'//'_il'//zchar1//'_htc'//zchar
-            z2d(:,:) = sxye(:,:,jk,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         END DO
-      END DO
-
+      ! In case Prather scheme is used for advection, write second order moments
+      ! ------------------------------------------------------------------------
+      IF( nn_limadv == -1 ) THEN
+         
+         DO jl = 1, jpl 
+            WRITE(zchar,'(I2.2)') jl
+            znam = 'sxice'//'_htc'//zchar
+            z2d(:,:) = sxice(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'syice'//'_htc'//zchar
+            z2d(:,:) = syice(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxxice'//'_htc'//zchar
+            z2d(:,:) = sxxice(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'syyice'//'_htc'//zchar
+            z2d(:,:) = syyice(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxyice'//'_htc'//zchar
+            z2d(:,:) = sxyice(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxsn'//'_htc'//zchar
+            z2d(:,:) = sxsn(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sysn'//'_htc'//zchar
+            z2d(:,:) = sysn(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxxsn'//'_htc'//zchar
+            z2d(:,:) = sxxsn(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'syysn'//'_htc'//zchar
+            z2d(:,:) = syysn(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxysn'//'_htc'//zchar
+            z2d(:,:) = sxysn(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxa'//'_htc'//zchar
+            z2d(:,:) = sxa(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sya'//'_htc'//zchar
+            z2d(:,:) = sya(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxxa'//'_htc'//zchar
+            z2d(:,:) = sxxa(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'syya'//'_htc'//zchar
+            z2d(:,:) = syya(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxya'//'_htc'//zchar
+            z2d(:,:) = sxya(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxc0'//'_htc'//zchar
+            z2d(:,:) = sxc0(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'syc0'//'_htc'//zchar
+            z2d(:,:) = syc0(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxxc0'//'_htc'//zchar
+            z2d(:,:) = sxxc0(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'syyc0'//'_htc'//zchar
+            z2d(:,:) = syyc0(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxyc0'//'_htc'//zchar
+            z2d(:,:) = sxyc0(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxsal'//'_htc'//zchar
+            z2d(:,:) = sxsal(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sysal'//'_htc'//zchar
+            z2d(:,:) = sysal(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxxsal'//'_htc'//zchar
+            z2d(:,:) = sxxsal(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'syysal'//'_htc'//zchar
+            z2d(:,:) = syysal(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxysal'//'_htc'//zchar
+            z2d(:,:) = sxysal(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxage'//'_htc'//zchar
+            z2d(:,:) = sxage(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'syage'//'_htc'//zchar
+            z2d(:,:) = syage(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxxage'//'_htc'//zchar
+            z2d(:,:) = sxxage(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'syyage'//'_htc'//zchar
+            z2d(:,:) = syyage(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxyage'//'_htc'//zchar
+            z2d(:,:) = sxyage(:,:,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         END DO
+
+         CALL iom_rstput( iter, nitrst, numriw, 'sxopw ' ,  sxopw  )
+         CALL iom_rstput( iter, nitrst, numriw, 'syopw ' ,  syopw  )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxopw' ,  sxxopw )
+         CALL iom_rstput( iter, nitrst, numriw, 'syyopw' ,  syyopw )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxyopw' ,  sxyopw )
+         
+         DO jl = 1, jpl 
+            WRITE(zchar,'(I2.2)') jl
+            DO jk = 1, nlay_i 
+               WRITE(zchar1,'(I2.2)') jk
+               znam = 'sxe'//'_il'//zchar1//'_htc'//zchar
+               z2d(:,:) = sxe(:,:,jk,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+               znam = 'sye'//'_il'//zchar1//'_htc'//zchar
+               z2d(:,:) = sye(:,:,jk,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+               znam = 'sxxe'//'_il'//zchar1//'_htc'//zchar
+               z2d(:,:) = sxxe(:,:,jk,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+               znam = 'syye'//'_il'//zchar1//'_htc'//zchar
+               z2d(:,:) = syye(:,:,jk,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+               znam = 'sxye'//'_il'//zchar1//'_htc'//zchar
+               z2d(:,:) = sxye(:,:,jk,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            END DO
+         END DO
+
+      ENDIF
+      
+      ! close restart file
+      ! ------------------
       IF( iter == nitrst ) THEN
-         CALL iom_close( numriw )                         ! close the restart file
+         CALL iom_close( numriw )
          lrst_ice = .FALSE.
       ENDIF
@@ -315,6 +323,6 @@
       REAL(wp) ::   zfice, ziter
       REAL(wp), POINTER, DIMENSION(:,:) ::   z2d
-      CHARACTER(len=15) ::   znam
-      CHARACTER(len=1)  ::   zchar, zchar1
+      CHARACTER(len=25) ::   znam
+      CHARACTER(len=2)  ::   zchar, zchar1
       INTEGER           ::   jlibalt = jprstlib
       LOGICAL           ::   llok
@@ -347,6 +355,7 @@
          &                   '   control of time parameter  nrstdt' )
 
+      ! Prognostic variables 
       DO jl = 1, jpl 
-         WRITE(zchar,'(I1)') jl
+         WRITE(zchar,'(I2.2)') jl
          znam = 'v_i'//'_htc'//zchar
          CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
@@ -370,5 +379,5 @@
 
       DO jl = 1, jpl 
-         WRITE(zchar,'(I1)') jl
+         WRITE(zchar,'(I2.2)') jl
          znam = 'tempt_sl1'//'_htc'//zchar
          CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
@@ -377,7 +386,7 @@
 
       DO jl = 1, jpl 
-         WRITE(zchar,'(I1)') jl
+         WRITE(zchar,'(I2.2)') jl
          DO jk = 1, nlay_i 
-            WRITE(zchar1,'(I1)') jk
+            WRITE(zchar1,'(I2.2)') jk
             znam = 'tempt'//'_il'//zchar1//'_htc'//zchar
             CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
@@ -394,126 +403,132 @@
       CALL iom_get( numrir, jpdom_autoglo, 'snwice_mass_b', snwice_mass_b )
 
-      DO jl = 1, jpl 
-         WRITE(zchar,'(I1)') jl
-         znam = 'sxice'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxice(:,:,jl) = z2d(:,:)
-         znam = 'syice'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         syice(:,:,jl) = z2d(:,:)
-         znam = 'sxxice'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxxice(:,:,jl) = z2d(:,:)
-         znam = 'syyice'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         syyice(:,:,jl) = z2d(:,:)
-         znam = 'sxyice'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxyice(:,:,jl) = z2d(:,:)
-         znam = 'sxsn'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxsn(:,:,jl) = z2d(:,:)
-         znam = 'sysn'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sysn(:,:,jl) = z2d(:,:)
-         znam = 'sxxsn'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxxsn(:,:,jl) = z2d(:,:)
-         znam = 'syysn'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         syysn(:,:,jl) = z2d(:,:)
-         znam = 'sxysn'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxysn(:,:,jl) = z2d(:,:)
-         znam = 'sxa'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxa(:,:,jl) = z2d(:,:)
-         znam = 'sya'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sya(:,:,jl) = z2d(:,:)
-         znam = 'sxxa'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxxa(:,:,jl) = z2d(:,:)
-         znam = 'syya'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         syya(:,:,jl) = z2d(:,:)
-         znam = 'sxya'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxya(:,:,jl) = z2d(:,:)
-         znam = 'sxc0'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxc0(:,:,jl) = z2d(:,:)
-         znam = 'syc0'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         syc0(:,:,jl) = z2d(:,:)
-         znam = 'sxxc0'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxxc0(:,:,jl) = z2d(:,:)
-         znam = 'syyc0'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         syyc0(:,:,jl) = z2d(:,:)
-         znam = 'sxyc0'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxyc0(:,:,jl) = z2d(:,:)
-         znam = 'sxsal'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxsal(:,:,jl) = z2d(:,:)
-         znam = 'sysal'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sysal(:,:,jl) = z2d(:,:)
-         znam = 'sxxsal'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxxsal(:,:,jl) = z2d(:,:)
-         znam = 'syysal'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         syysal(:,:,jl) = z2d(:,:)
-         znam = 'sxysal'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxysal(:,:,jl) = z2d(:,:)
-         znam = 'sxage'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxage(:,:,jl) = z2d(:,:)
-         znam = 'syage'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         syage(:,:,jl) = z2d(:,:)
-         znam = 'sxxage'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxxage(:,:,jl) = z2d(:,:)
-         znam = 'syyage'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         syyage(:,:,jl) = z2d(:,:)
-         znam = 'sxyage'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sxyage(:,:,jl)= z2d(:,:)
-      END DO
-
-      CALL iom_get( numrir, jpdom_autoglo, 'sxopw ' ,  sxopw  )
-      CALL iom_get( numrir, jpdom_autoglo, 'syopw ' ,  syopw  )
-      CALL iom_get( numrir, jpdom_autoglo, 'sxxopw' ,  sxxopw )
-      CALL iom_get( numrir, jpdom_autoglo, 'syyopw' ,  syyopw )
-      CALL iom_get( numrir, jpdom_autoglo, 'sxyopw' ,  sxyopw )
-
-      DO jl = 1, jpl 
-         WRITE(zchar,'(I1)') jl
-         DO jk = 1, nlay_i 
-            WRITE(zchar1,'(I1)') jk
-            znam = 'sxe'//'_il'//zchar1//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxe(:,:,jk,jl) = z2d(:,:)
-            znam = 'sye'//'_il'//zchar1//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sye(:,:,jk,jl) = z2d(:,:)
-            znam = 'sxxe'//'_il'//zchar1//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxxe(:,:,jk,jl) = z2d(:,:)
-            znam = 'syye'//'_il'//zchar1//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            syye(:,:,jk,jl) = z2d(:,:)
-            znam = 'sxye'//'_il'//zchar1//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxye(:,:,jk,jl) = z2d(:,:)
-         END DO
-      END DO
-      !
+      ! In case Prather scheme is used for advection, read second order moments
+      ! ------------------------------------------------------------------------
+      IF( nn_limadv == -1 ) THEN
+
+         DO jl = 1, jpl 
+            WRITE(zchar,'(I2.2)') jl
+            znam = 'sxice'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxice(:,:,jl) = z2d(:,:)
+            znam = 'syice'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            syice(:,:,jl) = z2d(:,:)
+            znam = 'sxxice'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxxice(:,:,jl) = z2d(:,:)
+            znam = 'syyice'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            syyice(:,:,jl) = z2d(:,:)
+            znam = 'sxyice'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxyice(:,:,jl) = z2d(:,:)
+            znam = 'sxsn'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxsn(:,:,jl) = z2d(:,:)
+            znam = 'sysn'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sysn(:,:,jl) = z2d(:,:)
+            znam = 'sxxsn'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxxsn(:,:,jl) = z2d(:,:)
+            znam = 'syysn'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            syysn(:,:,jl) = z2d(:,:)
+            znam = 'sxysn'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxysn(:,:,jl) = z2d(:,:)
+            znam = 'sxa'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxa(:,:,jl) = z2d(:,:)
+            znam = 'sya'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sya(:,:,jl) = z2d(:,:)
+            znam = 'sxxa'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxxa(:,:,jl) = z2d(:,:)
+            znam = 'syya'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            syya(:,:,jl) = z2d(:,:)
+            znam = 'sxya'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxya(:,:,jl) = z2d(:,:)
+            znam = 'sxc0'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxc0(:,:,jl) = z2d(:,:)
+            znam = 'syc0'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            syc0(:,:,jl) = z2d(:,:)
+            znam = 'sxxc0'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxxc0(:,:,jl) = z2d(:,:)
+            znam = 'syyc0'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            syyc0(:,:,jl) = z2d(:,:)
+            znam = 'sxyc0'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxyc0(:,:,jl) = z2d(:,:)
+            znam = 'sxsal'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxsal(:,:,jl) = z2d(:,:)
+            znam = 'sysal'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sysal(:,:,jl) = z2d(:,:)
+            znam = 'sxxsal'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxxsal(:,:,jl) = z2d(:,:)
+            znam = 'syysal'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            syysal(:,:,jl) = z2d(:,:)
+            znam = 'sxysal'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxysal(:,:,jl) = z2d(:,:)
+            znam = 'sxage'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxage(:,:,jl) = z2d(:,:)
+            znam = 'syage'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            syage(:,:,jl) = z2d(:,:)
+            znam = 'sxxage'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxxage(:,:,jl) = z2d(:,:)
+            znam = 'syyage'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            syyage(:,:,jl) = z2d(:,:)
+            znam = 'sxyage'//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxyage(:,:,jl)= z2d(:,:)
+         END DO
+
+         CALL iom_get( numrir, jpdom_autoglo, 'sxopw ' ,  sxopw  )
+         CALL iom_get( numrir, jpdom_autoglo, 'syopw ' ,  syopw  )
+         CALL iom_get( numrir, jpdom_autoglo, 'sxxopw' ,  sxxopw )
+         CALL iom_get( numrir, jpdom_autoglo, 'syyopw' ,  syyopw )
+         CALL iom_get( numrir, jpdom_autoglo, 'sxyopw' ,  sxyopw )
+
+         DO jl = 1, jpl 
+            WRITE(zchar,'(I2.2)') jl
+            DO jk = 1, nlay_i 
+               WRITE(zchar1,'(I2.2)') jk
+               znam = 'sxe'//'_il'//zchar1//'_htc'//zchar
+               CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+               sxe(:,:,jk,jl) = z2d(:,:)
+               znam = 'sye'//'_il'//zchar1//'_htc'//zchar
+               CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+               sye(:,:,jk,jl) = z2d(:,:)
+               znam = 'sxxe'//'_il'//zchar1//'_htc'//zchar
+               CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+               sxxe(:,:,jk,jl) = z2d(:,:)
+               znam = 'syye'//'_il'//zchar1//'_htc'//zchar
+               CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+               syye(:,:,jk,jl) = z2d(:,:)
+               znam = 'sxye'//'_il'//zchar1//'_htc'//zchar
+               CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+               sxye(:,:,jk,jl) = z2d(:,:)
+            END DO
+         END DO
+         !
+      END IF
+      
       ! clem: I do not understand why the following IF is needed
       !       I suspect something inconsistent in the main code with option nn_icesal=1
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90	(revision 7309)
@@ -42,5 +42,4 @@
    USE lib_mpp        ! MPP library
    USE wrk_nemo       ! work arrays
-   USE prtctl         ! Print control
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
 
@@ -48,5 +47,5 @@
    PRIVATE
 
-   PUBLIC   lim_sbc_init   ! called by sbcice_lim
+   PUBLIC   lim_sbc_init   ! called by sbc_lim_init
    PUBLIC   lim_sbc_flx    ! called by sbc_ice_lim
    PUBLIC   lim_sbc_tau    ! called by sbc_ice_lim
@@ -94,5 +93,5 @@
       !!              - fr_i    : ice fraction
       !!              - tn_ice  : sea-ice surface temperature
-      !!              - alb_ice : sea-ice albedo (only useful in coupled mode)
+      !!              - alb_ice : sea-ice albedo (recomputed only for coupled mode)
       !!
       !! References : Goosse, H. et al. 1996, Bul. Soc. Roy. Sc. Liege, 65, 87-90.
@@ -109,30 +108,25 @@
       REAL(wp), POINTER, DIMENSION(:,:)   ::   zalb                 ! 2D workspace
       !!---------------------------------------------------------------------
-      !
-      ! make calls for heat fluxes before it is modified
-      ! pfrld is the lead fraction at the previous time step (actually between TRP and THD)
-      IF( iom_use('qsr_oce') )   CALL iom_put( "qsr_oce" , qsr_oce(:,:) * pfrld(:,:) )                                   !     solar flux at ocean surface
-      IF( iom_use('qns_oce') )   CALL iom_put( "qns_oce" , qns_oce(:,:) * pfrld(:,:) + 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') )   CALL iom_put( "qtr_ice" , SUM( ftr_ice(:,:,:) * a_i_b(:,:,:), dim=3 ) )                 !     solar flux transmitted thru ice
-      IF( iom_use('qt_oce' ) )   CALL iom_put( "qt_oce"  , ( qsr_oce(:,:) + qns_oce(:,:) ) * pfrld(:,:) + 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('qemp_oce') )  CALL iom_put( "qemp_oce" , qemp_oce(:,:) )  
-      IF( iom_use('qemp_ice') )  CALL iom_put( "qemp_ice" , qemp_ice(:,:) )  
-      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)
-
+
+      ! --- case we bypass ice thermodynamics --- !
+      IF( .NOT. ln_limthd ) THEN   ! we suppose ice is impermeable => ocean is isolated from atmosphere
+         hfx_in   (:,:)   = pfrld(:,:) * ( qns_oce(:,:) + qsr_oce(:,:) ) + qemp_oce(:,:)
+         hfx_out  (:,:)   = pfrld(:,:) *   qns_oce(:,:)                  + qemp_oce(:,:)
+         ftr_ice  (:,:,:) = 0._wp
+         emp_ice  (:,:)   = 0._wp
+         qemp_ice (:,:)   = 0._wp
+         qevap_ice(:,:,:) = 0._wp
+      ENDIF
+      
       ! albedo output
       CALL wrk_alloc( jpi,jpj, zalb )    
 
       zalb(:,:) = 0._wp
-      WHERE     ( SUM( a_i_b, dim=3 ) <= epsi06 )  ;  zalb(:,:) = 0.066_wp
-      ELSEWHERE                                    ;  zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) / SUM( a_i_b, dim=3 )
+      WHERE     ( at_i_b <= epsi06 )  ;  zalb(:,:) = 0.066_wp
+      ELSEWHERE                       ;  zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) / at_i_b
       END WHERE
       IF( iom_use('alb_ice' ) )  CALL iom_put( "alb_ice"  , zalb(:,:) )           ! ice albedo output
 
-      zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) + 0.066_wp * ( 1._wp - SUM( a_i_b, dim=3 ) )      
+      zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) + 0.066_wp * ( 1._wp - at_i_b )      
       IF( iom_use('albedo'  ) )  CALL iom_put( "albedo"  , zalb(:,:) )           ! ice albedo output
 
@@ -180,9 +174,9 @@
             ! mass flux from ice/ocean
             wfx_ice(ji,jj) = wfx_bog(ji,jj) + wfx_bom(ji,jj) + wfx_sum(ji,jj) + wfx_sni(ji,jj)   &
-                           + wfx_opw(ji,jj) + wfx_dyn(ji,jj) + wfx_res(ji,jj)
+                           + wfx_opw(ji,jj) + wfx_dyn(ji,jj) + wfx_res(ji,jj) + wfx_lam(ji,jj) 
 
             ! mass flux at the ocean/ice interface
             fmmflx(ji,jj) = - ( wfx_ice(ji,jj) + wfx_snw(ji,jj) + wfx_err_sub(ji,jj) )              ! F/M mass flux save at least for biogeochemical model
-            emp(ji,jj)    = emp_oce(ji,jj) - wfx_ice(ji,jj) - wfx_snw(ji,jj) - wfx_err_sub(ji,jj)   ! mass flux + F/M mass flux (always ice/ocean mass exchange)            
+            emp(ji,jj)    = emp_oce(ji,jj) - wfx_ice(ji,jj) - wfx_snw(ji,jj) - wfx_err_sub(ji,jj)   ! mass flux + F/M mass flux (always ice/ocean mass exchange)
          END DO
       END DO
@@ -192,5 +186,5 @@
       !------------------------------------------!
       sfx(:,:) = sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) + sfx_opw(:,:)   &
-         &     + sfx_res(:,:) + sfx_dyn(:,:) + sfx_bri(:,:) + sfx_sub(:,:)
+         &     + sfx_res(:,:) + sfx_dyn(:,:) + sfx_bri(:,:) + sfx_sub(:,:) + sfx_lam(:,:)
 
       !-------------------------------------------------------------!
@@ -221,16 +215,10 @@
 
       ! conservation test
-      IF( ln_limdiahsb )   CALL lim_cons_final( 'limsbc' )
+      IF( ln_limdiachk )  CALL lim_cons_final( 'limsbc' )
 
       ! control prints
-      IF( ln_icectl )   CALL lim_prt( kt, iiceprt, jiceprt, 3, ' - Final state lim_sbc - ' )
-      !
-      IF(ln_ctl) THEN
-         CALL prt_ctl( tab2d_1=qsr   , clinfo1=' lim_sbc: qsr    : ', tab2d_2=qns , clinfo2=' qns     : ' )
-         CALL prt_ctl( tab2d_1=emp   , clinfo1=' lim_sbc: emp    : ', tab2d_2=sfx , clinfo2=' sfx     : ' )
-         CALL prt_ctl( tab2d_1=fr_i  , clinfo1=' lim_sbc: fr_i   : ' )
-         CALL prt_ctl( tab3d_1=tn_ice, clinfo1=' lim_sbc: tn_ice : ', kdim=jpl )
-      ENDIF
-      !
+      IF( ln_limctl )   CALL lim_prt( kt, iiceprt, jiceprt, 3, ' - Final state lim_sbc - ' )
+      IF( ln_ctl )      CALL lim_prt3D( 'limsbc' )
+
    END SUBROUTINE lim_sbc_flx
 
@@ -266,6 +254,7 @@
       INTEGER  ::   ji, jj   ! dummy loop indices
       REAL(wp) ::   zat_u, zutau_ice, zu_t, zmodt   ! local scalar
-      REAL(wp) ::   zat_v, zvtau_ice, zv_t          !   -      -
+      REAL(wp) ::   zat_v, zvtau_ice, zv_t, zrhoco  !   -      -
       !!---------------------------------------------------------------------
+      zrhoco = rau0 * rn_cio
       !
       IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN     !==  Ice time-step only  ==!   (i.e. surface module time-step)
@@ -278,9 +267,9 @@
                zmodt =  0.25_wp * (  zu_t * zu_t + zv_t * zv_t  )
                !                                               ! update the ocean stress modulus
-               taum(ji,jj) = ( 1._wp - at_i(ji,jj) ) * taum(ji,jj) + at_i(ji,jj) * rhoco * zmodt
-               tmod_io(ji,jj) = rhoco * SQRT( zmodt )          ! rhoco * |U_ice-U_oce| at T-point
+               taum(ji,jj) = ( 1._wp - at_i(ji,jj) ) * taum(ji,jj) + at_i(ji,jj) * zrhoco * zmodt
+               tmod_io(ji,jj) = zrhoco * SQRT( zmodt )          ! rhoco * |U_ice-U_oce| at T-point
             END DO
          END DO
-         CALL lbc_lnk( taum, 'T', 1. )   ;   CALL lbc_lnk( tmod_io, 'T', 1. )
+         CALL lbc_lnk_multi( taum, 'T', 1., tmod_io, 'T', 1. )
          !
          utau_oce(:,:) = utau(:,:)                    !* save the air-ocean stresses at ice time-step
@@ -303,8 +292,6 @@
          END DO
       END DO
-      CALL lbc_lnk( utau, 'U', -1. )   ;   CALL lbc_lnk( vtau, 'V', -1. )   ! lateral boundary condition
-      !
-      IF(ln_ctl)   CALL prt_ctl( tab2d_1=utau, clinfo1=' lim_sbc: utau   : ', mask1=umask,   &
-         &                       tab2d_2=vtau, clinfo2=' vtau    : '        , mask2=vmask )
+      CALL lbc_lnk_multi( utau, 'U', -1., vtau, 'V', -1. )   ! lateral boundary condition
+      !
       !  
    END SUBROUTINE lim_sbc_tau
@@ -355,5 +342,5 @@
             sshb(:,:) = sshb(:,:) - snwice_mass(:,:) * r1_rau0
 
-!!gm I really don't like this staff here...  Find a way to put that elsewhere or differently
+!!gm I really don't like this stuff here...  Find a way to put that elsewhere or differently
 !!gm
             IF( .NOT.ln_linssh ) THEN
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 7309)
@@ -22,22 +22,21 @@
    USE phycst         ! physical constants
    USE dom_oce        ! ocean space and time domain variables
-   USE ice            ! LIM: sea-ice variables
+   USE ice            ! sea-ice variables
    USE sbc_oce        ! Surface boundary condition: ocean fields
    USE sbc_ice        ! Surface boundary condition: ice fields
-   USE dom_ice        ! LIM: sea-ice domain
-   USE thd_ice        ! LIM: thermodynamic sea-ice variables
-   USE limthd_dif     ! LIM: thermodynamics, vertical diffusion
-   USE limthd_dh      ! LIM: thermodynamics, ice and snow thickness variation
-   USE limthd_sal     ! LIM: thermodynamics, ice salinity
-   USE limthd_ent     ! LIM: thermodynamics, ice enthalpy redistribution
-   USE limthd_lac     ! LIM: lateral accretion
-   USE limitd_th      ! LIM: remapping thickness distribution
-   USE limtab         ! LIM: 1D <==> 2D transformation
-   USE limvar         ! LIM: sea-ice variables
-   USE limcons        ! LIM: conservation tests
-   USE limctl         ! LIM: control print
+   USE thd_ice        ! thermodynamic sea-ice variables
+   USE limthd_dif     ! vertical diffusion
+   USE limthd_dh      ! ice-snow growth and melt
+   USE limthd_da      ! lateral melting
+   USE limthd_sal     ! ice salinity
+   USE limthd_ent     ! ice enthalpy redistribution
+   USE limthd_lac     ! lateral accretion
+   USE limitd_th      ! remapping thickness distribution
+   USE limtab         ! 1D <==> 2D transformation
+   USE limvar         !
+   USE limcons        ! conservation tests
+   USE limctl         ! control print
    !
    USE in_out_manager ! I/O manager
-   USE prtctl         ! Print control
    USE lbclnk         ! lateral boundary condition - MPP links
    USE lib_mpp        ! MPP library
@@ -88,20 +87,52 @@
       REAL(wp), PARAMETER :: zfric_umin = 0._wp           ! lower bound for the friction velocity (cice value=5.e-04)
       REAL(wp), PARAMETER :: zch        = 0.0057_wp       ! heat transfer coefficient
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zu_io, zv_io, zfric   ! ice-ocean velocity (m/s) and frictional velocity (m2/s2)
+      !
       !!-------------------------------------------------------------------
 
       IF( nn_timing == 1 )   CALL timing_start('limthd')
 
+      CALL wrk_alloc( jpi,jpj, zu_io, zv_io, zfric )
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)'' 
+         WRITE(numout,*)' lim_thd '
+         WRITE(numout,*)' ~~~~~~~~'
+      ENDIF
+      
       ! conservation test
-      IF( ln_limdiahsb )   CALL lim_cons_hsm( 0, 'limthd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b )
+      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limthd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
 
       CALL lim_var_glo2eqv
-      !------------------------------------------------------------------------!
-      ! 1) Initialization of some variables                                    !
-      !------------------------------------------------------------------------!
+
+      !---------------------------------------------!
+      ! computation of friction velocity at T points
+      !---------------------------------------------!
+      IF( ln_limdyn ) THEN
+         zu_io(:,:) = u_ice(:,:) - ssu_m(:,:)
+         zv_io(:,:) = v_ice(:,:) - ssv_m(:,:)
+         DO jj = 2, jpjm1 
+            DO ji = fs_2, fs_jpim1
+               zfric(ji,jj) = rn_cio * ( 0.5_wp *  &
+                  &                    (  zu_io(ji,jj) * zu_io(ji,jj) + zu_io(ji-1,jj) * zu_io(ji-1,jj)   &
+                  &                     + zv_io(ji,jj) * zv_io(ji,jj) + zv_io(ji,jj-1) * zv_io(ji,jj-1) ) ) * tmask(ji,jj,1)
+            END DO
+         END DO
+      ELSE      !  if no ice dynamics => transmit directly the atmospheric stress to the ocean
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zfric(ji,jj) = r1_rau0 * SQRT( 0.5_wp *  &
+                  &                         (  utau(ji,jj) * utau(ji,jj) + utau(ji-1,jj) * utau(ji-1,jj)   &
+                  &                          + vtau(ji,jj) * vtau(ji,jj) + vtau(ji,jj-1) * vtau(ji,jj-1) ) ) * tmask(ji,jj,1)
+            END DO
+         END DO
+      ENDIF
+      CALL lbc_lnk( zfric, 'T',  1. )
+      !
+      !----------------------------------!
+      ! Initialization and units change
+      !----------------------------------!
       ftr_ice(:,:,:) = 0._wp  ! part of solar radiation transmitted through the ice
 
-      !--------------------
-      ! 1.2) Heat content    
-      !--------------------
       ! Change the units of heat content; from J/m2 to J/m3
       DO jl = 1, jpl
@@ -109,5 +140,4 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  !0 if no ice and 1 if yes
                   rswitch = MAX(  0._wp , SIGN( 1._wp , v_i(ji,jj,jl) - epsi20 )  )
                   !Energy of melting q(S,T) [J.m-3]
@@ -119,5 +149,4 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  !0 if no ice and 1 if yes
                   rswitch = MAX(  0._wp , SIGN( 1._wp , v_s(ji,jj,jl) - epsi20 )  )
                   !Energy of melting q(S,T) [J.m-3]
@@ -128,6 +157,7 @@
       END DO
 
-      ! 2) Partial computation of forcing for the thermodynamic sea ice model.      !
-      !-----------------------------------------------------------------------------!
+      !--------------------------------------------------------------------!
+      ! Partial computation of forcing for the thermodynamic sea ice model
+      !--------------------------------------------------------------------!
       DO jj = 1, jpj
          DO ji = 1, jpi
@@ -148,5 +178,5 @@
 
             ! --- Energy from the turbulent oceanic heat flux (W/m2) --- !
-            zfric_u      = MAX( SQRT( ust2s(ji,jj) ), zfric_umin ) 
+            zfric_u      = MAX( SQRT( zfric(ji,jj) ), zfric_umin ) 
             fhtur(ji,jj) = MAX( 0._wp, rswitch * rau0 * rcp * zch  * zfric_u * ( ( sst_m(ji,jj) + rt0 ) - t_bo(ji,jj) ) ) ! W.m-2
             fhtur(ji,jj) = rswitch * MIN( fhtur(ji,jj), - zqfr * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) )
@@ -166,15 +196,24 @@
             ENDIF
             !
-            ! -----------------------------------------
-            ! Net heat flux on top of ice-ocean [W.m-2]
-            ! -----------------------------------------
+            ! Net heat flux on top of the ice-ocean [W.m-2]
+            ! ---------------------------------------------
             hfx_in(ji,jj) = qns_tot(ji,jj) + qsr_tot(ji,jj) 
-
-            ! -----------------------------------------------------------------------------
-            ! Net heat flux on top of the ocean after ice thermo (1st step) [W.m-2]
-            ! -----------------------------------------------------------------------------
-            !     First  step here              :  non solar + precip - qlead - qturb
-            !     Second step in limthd_dh      :  heat remaining if total melt (zq_rema) 
-            !     Third  step in limsbc         :  heat from ice-ocean mass exchange (zf_mass) + solar
+         END DO
+      END DO
+      
+      ! In case we bypass open-water ice formation
+      IF( .NOT. ln_limdO )  qlead(:,:) = 0._wp
+      ! In case we bypass growing/melting from top and bottom: we suppose ice is impermeable => ocean is isolated from atmosphere
+      IF( .NOT. ln_limdH )  hfx_in(:,:) = pfrld(:,:) * ( qns_oce(:,:) + qsr_oce(:,:) ) + qemp_oce(:,:)
+      IF( .NOT. ln_limdH )  fhtur (:,:) = 0._wp  ;  fhld  (:,:) = 0._wp
+
+      ! ---------------------------------------------------------------------
+      ! Net heat flux on top of the ocean after ice thermo (1st step) [W.m-2]
+      ! ---------------------------------------------------------------------
+      !     First  step here              :  non solar + precip - qlead - qturb
+      !     Second step in limthd_dh      :  heat remaining if total melt (zq_rema) 
+      !     Third  step in limsbc         :  heat from ice-ocean mass exchange (zf_mass) + solar
+      DO jj = 1, jpj
+         DO ji = 1, jpi
             hfx_out(ji,jj) =   pfrld(ji,jj) * qns_oce(ji,jj) + qemp_oce(ji,jj)  &  ! Non solar heat flux received by the ocean               
                &             - qlead(ji,jj) * r1_rdtice                         &  ! heat flux taken from the ocean where there is open water ice formation
@@ -186,14 +225,10 @@
 
       !------------------------------------------------------------------------------!
-      ! 3) Select icy points and fulfill arrays for the vectorial grid.            
+      ! Thermodynamic computation (only on grid points covered by ice)
       !------------------------------------------------------------------------------!
 
       DO jl = 1, jpl      !loop over ice categories
 
-         IF( kt == nit000 .AND. lwp ) THEN
-            WRITE(numout,*) ' lim_thd : transfer to 1D vectors. Category no : ', jl 
-            WRITE(numout,*) ' ~~~~~~~~'
-         ENDIF
-
+         ! select ice covered grid points
          nbpb = 0
          DO jj = 1, jpj
@@ -208,5 +243,5 @@
          ! debug point to follow
          jiindex_1d = 0
-         IF( ln_icectl ) THEN
+         IF( ln_limctl ) THEN
             DO ji = mi0(iiceprt), mi1(iiceprt)
                DO jj = mj0(jiceprt), mj1(jiceprt)
@@ -217,43 +252,39 @@
          ENDIF
 
-         !------------------------------------------------------------------------------!
-         ! 4) Thermodynamic computation
-         !------------------------------------------------------------------------------!
-
-         IF( lk_mpp )   CALL mpp_ini_ice( nbpb , numout )
+         IF( lk_mpp )         CALL mpp_ini_ice( nbpb , numout )
 
          IF( nbpb > 0 ) THEN  ! If there is no ice, do nothing.
-            !
-            CALL lim_thd_1d2d( nbpb, jl, 1 )                ! --- Move to 1D arrays ---!
-            !
-            CALL lim_thd_dif ( 1, nbpb )                    ! --- Ice/Snow Temperature profile --- !
-            !
-            CALL lim_thd_dh  ( 1, nbpb )                    ! --- Ice/Snow thickness ---!
-            !
-            CALL lim_thd_ent ( 1, nbpb, q_i_1d(1:nbpb,:) )  ! --- Ice enthalpy remapping --- !
-            !
-            CALL lim_thd_sal ( 1, nbpb )                    ! --- Ice salinity ---            !
-            !
-            CALL lim_thd_temp( 1, nbpb )                    ! --- temperature update ---      !
-            !
-            !                                               ! --- lateral melting if monocat --- !
-            IF ( ( nn_monocat == 1 .OR. nn_monocat == 4 ) .AND. jpl == 1 ) THEN
-               CALL lim_thd_lam( 1, nbpb )
+            !                                                                
+            s_i_new   (:) = 0._wp ; dh_s_tot (:) = 0._wp                     ! --- some init --- !
+            dh_i_surf (:) = 0._wp ; dh_i_bott(:) = 0._wp
+            dh_snowice(:) = 0._wp ; dh_i_sub (:) = 0._wp
+
+                              CALL lim_thd_1d2d( nbpb, jl, 1 )               ! --- Move to 1D arrays --- !
+            !
+            IF( ln_limdH )    CALL lim_thd_dif( 1, nbpb )                    ! --- Ice/Snow Temperature profile --- !
+            !
+            IF( ln_limdH )    CALL lim_thd_dh( 1, nbpb )                     ! --- Ice/Snow thickness --- !    
+            !
+            IF( ln_limdH )    CALL lim_thd_ent( 1, nbpb, q_i_1d(1:nbpb,:) )  ! --- Ice enthalpy remapping --- !
+            !
+                              CALL lim_thd_sal( 1, nbpb )                    ! --- Ice salinity --- !    
+            !
+                              CALL lim_thd_temp( 1, nbpb )                   ! --- temperature update --- !
+            !
+            IF( ln_limdH ) THEN
+               IF ( ( nn_monocat == 1 .OR. nn_monocat == 4 ) .AND. jpl == 1 ) THEN
+                              CALL lim_thd_lam( 1, nbpb )                    ! --- extra lateral melting if monocat --- !
+               END IF
             END IF
             !
-            CALL lim_thd_1d2d( nbpb, jl, 2 )                ! --- Move to 2D arrays ---
-            !
-            IF( lk_mpp )   CALL mpp_comm_free( ncomm_ice )  !RB necessary ??
+                              CALL lim_thd_1d2d( nbpb, jl, 2 )               ! --- Move to 2D arrays --- !
+            !
+            IF( lk_mpp )      CALL mpp_comm_free( ncomm_ice ) !RB necessary ??
          ENDIF
          !
       END DO !jl
 
-      !------------------------------------------------------------------------------!
-      ! 5) Global variables, diagnostics
-      !------------------------------------------------------------------------------!
-
-      !------------------------
-      ! Ice heat content              
-      !------------------------
+      IF( ln_limdA)           CALL lim_thd_da                                ! --- lateral melting --- !
+
       ! Enthalpies are global variables we have to readjust the units (heat content in J/m2)
       DO jl = 1, jpl
@@ -261,11 +292,4 @@
             e_i(:,:,jk,jl) = e_i(:,:,jk,jl) * a_i(:,:,jl) * ht_i(:,:,jl) * r1_nlay_i
          END DO
-      END DO
-
-      !------------------------
-      ! Snow heat content              
-      !------------------------
-      ! Enthalpies are global variables we have to readjust the units (heat content in J/m2)
-      DO jl = 1, jpl
          DO jk = 1, nlay_s
             e_s(:,:,jk,jl) = e_s(:,:,jk,jl) * a_i(:,:,jl) * ht_s(:,:,jl) * r1_nlay_s
@@ -273,7 +297,5 @@
       END DO
  
-      !----------------------------------
       ! Change thickness to volume
-      !----------------------------------
       v_i(:,:,:)   = ht_i(:,:,:) * a_i(:,:,:)
       v_s(:,:,:)   = ht_s(:,:,:) * a_i(:,:,:)
@@ -292,100 +314,36 @@
       CALL lim_var_zapsmall
 
-      !--------------------------------------------
-      ! Diagnostic thermodynamic growth rates
-      !--------------------------------------------
-      IF( ln_icectl )   CALL lim_prt( kt, iiceprt, jiceprt, 1, ' - ice thermodyn. - ' )   ! control print
-
-      IF(ln_ctl) THEN            ! Control print
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Cell values : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=e1e2t, clinfo1=' lim_thd  : cell area :')
-         CALL prt_ctl(tab2d_1=at_i , clinfo1=' lim_thd  : at_i      :')
-         CALL prt_ctl(tab2d_1=vt_i , clinfo1=' lim_thd  : vt_i      :')
-         CALL prt_ctl(tab2d_1=vt_s , clinfo1=' lim_thd  : vt_s      :')
-         DO jl = 1, jpl
-            CALL prt_ctl_info(' ')
-            CALL prt_ctl_info(' - Category : ', ivar1=jl)
-            CALL prt_ctl_info('   ~~~~~~~~~~')
-            CALL prt_ctl(tab2d_1=a_i   (:,:,jl)   , clinfo1= ' lim_thd  : a_i      : ')
-            CALL prt_ctl(tab2d_1=ht_i  (:,:,jl)   , clinfo1= ' lim_thd  : ht_i     : ')
-            CALL prt_ctl(tab2d_1=ht_s  (:,:,jl)   , clinfo1= ' lim_thd  : ht_s     : ')
-            CALL prt_ctl(tab2d_1=v_i   (:,:,jl)   , clinfo1= ' lim_thd  : v_i      : ')
-            CALL prt_ctl(tab2d_1=v_s   (:,:,jl)   , clinfo1= ' lim_thd  : v_s      : ')
-            CALL prt_ctl(tab2d_1=e_s   (:,:,1,jl) , clinfo1= ' lim_thd  : e_s      : ')
-            CALL prt_ctl(tab2d_1=t_su  (:,:,jl)   , clinfo1= ' lim_thd  : t_su     : ')
-            CALL prt_ctl(tab2d_1=t_s   (:,:,1,jl) , clinfo1= ' lim_thd  : t_snow   : ')
-            CALL prt_ctl(tab2d_1=sm_i  (:,:,jl)   , clinfo1= ' lim_thd  : sm_i     : ')
-            CALL prt_ctl(tab2d_1=smv_i (:,:,jl)   , clinfo1= ' lim_thd  : smv_i    : ')
-            DO jk = 1, nlay_i
-               CALL prt_ctl_info(' ')
-               CALL prt_ctl_info(' - Layer : ', ivar1=jk)
-               CALL prt_ctl_info('   ~~~~~~~')
-               CALL prt_ctl(tab2d_1=t_i(:,:,jk,jl) , clinfo1= ' lim_thd  : t_i      : ')
-               CALL prt_ctl(tab2d_1=e_i(:,:,jk,jl) , clinfo1= ' lim_thd  : e_i      : ')
-            END DO
-         END DO
-      ENDIF
-      !
-      !
-      IF( ln_limdiahsb ) CALL lim_cons_hsm(1, 'limthd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      !------------------------------------------------------------------------------|
-      !  6) Transport of ice between thickness categories.                           |
-      !------------------------------------------------------------------------------|
+      ! control checks
+      IF( ln_limctl )    CALL lim_prt( kt, iiceprt, jiceprt, 1, ' - ice thermodyn. - ' )   ! control print
+      !
+      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limthd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      !------------------------------------------------!
+      !  Transport ice between thickness categories
+      !------------------------------------------------!
       ! Given thermodynamic growth rates, transport ice between thickness categories.
-      IF( ln_limdiahsb ) CALL lim_cons_hsm(0, 'limitd_th_rem', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limitd_th_rem', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
 
       IF( jpl > 1 )      CALL lim_itd_th_rem( 1, jpl, kt )
 
-      IF( ln_limdiahsb ) CALL lim_cons_hsm(1, 'limitd_th_rem', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      !------------------------------------------------------------------------------|
-      !  7) Add frazil ice growing in leads.
-      !------------------------------------------------------------------------------|
-      IF( ln_limdiahsb ) CALL lim_cons_hsm(0, 'limthd_lac', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      CALL lim_thd_lac
+      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limitd_th_rem', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      !------------------------------------------------!
+      !  Add frazil ice growing in leads
+      !------------------------------------------------!
+      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limthd_lac', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      IF( ln_limdO )     CALL lim_thd_lac
       
-      IF( ln_limdiahsb ) CALL lim_cons_hsm(1, 'limthd_lac', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      ! conservation test
+      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limthd_lac', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
 
       ! Control print
-      IF(ln_ctl) THEN
-         CALL lim_var_glo2eqv
-
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Cell values : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=e1e2t, clinfo1=' lim_itd_th  : cell area :')
-         CALL prt_ctl(tab2d_1=at_i , clinfo1=' lim_itd_th  : at_i      :')
-         CALL prt_ctl(tab2d_1=vt_i , clinfo1=' lim_itd_th  : vt_i      :')
-         CALL prt_ctl(tab2d_1=vt_s , clinfo1=' lim_itd_th  : vt_s      :')
-         DO jl = 1, jpl
-            CALL prt_ctl_info(' ')
-            CALL prt_ctl_info(' - Category : ', ivar1=jl)
-            CALL prt_ctl_info('   ~~~~~~~~~~')
-            CALL prt_ctl(tab2d_1=a_i   (:,:,jl)   , clinfo1= ' lim_itd_th  : a_i      : ')
-            CALL prt_ctl(tab2d_1=ht_i  (:,:,jl)   , clinfo1= ' lim_itd_th  : ht_i     : ')
-            CALL prt_ctl(tab2d_1=ht_s  (:,:,jl)   , clinfo1= ' lim_itd_th  : ht_s     : ')
-            CALL prt_ctl(tab2d_1=v_i   (:,:,jl)   , clinfo1= ' lim_itd_th  : v_i      : ')
-            CALL prt_ctl(tab2d_1=v_s   (:,:,jl)   , clinfo1= ' lim_itd_th  : v_s      : ')
-            CALL prt_ctl(tab2d_1=e_s   (:,:,1,jl) , clinfo1= ' lim_itd_th  : e_s      : ')
-            CALL prt_ctl(tab2d_1=t_su  (:,:,jl)   , clinfo1= ' lim_itd_th  : t_su     : ')
-            CALL prt_ctl(tab2d_1=t_s   (:,:,1,jl) , clinfo1= ' lim_itd_th  : t_snow   : ')
-            CALL prt_ctl(tab2d_1=sm_i  (:,:,jl)   , clinfo1= ' lim_itd_th  : sm_i     : ')
-            CALL prt_ctl(tab2d_1=smv_i (:,:,jl)   , clinfo1= ' lim_itd_th  : smv_i    : ')
-            DO jk = 1, nlay_i
-               CALL prt_ctl_info(' ')
-               CALL prt_ctl_info(' - Layer : ', ivar1=jk)
-               CALL prt_ctl_info('   ~~~~~~~')
-               CALL prt_ctl(tab2d_1=t_i(:,:,jk,jl) , clinfo1= ' lim_itd_th  : t_i      : ')
-               CALL prt_ctl(tab2d_1=e_i(:,:,jk,jl) , clinfo1= ' lim_itd_th  : e_i      : ')
-            END DO
-         END DO
-      ENDIF
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('limthd')
-      !
+      IF( ln_ctl )       CALL lim_prt3D( 'limthd' )
+      !
+      CALL wrk_dealloc( jpi,jpj, zu_io, zv_io, zfric )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('limthd')
+
    END SUBROUTINE lim_thd 
 
@@ -449,5 +407,5 @@
             zda_mel     = rswitch * a_i_1d(ji) * zdh_mel / ( 2._wp * MAX( zhi_bef, epsi20 ) )
             a_i_1d(ji)  = MAX( epsi20, a_i_1d(ji) + zda_mel ) 
-             ! adjust thickness
+            ! adjust thickness
             ht_i_1d(ji) = zvi / a_i_1d(ji)            
             ht_s_1d(ji) = zvs / a_i_1d(ji)            
@@ -613,15 +571,9 @@
       !!-------------------------------------------------------------------
       INTEGER  ::   ios                 ! Local integer output status for namelist read
-      !!
-      NAMELIST/namicethd/ rn_hnewice, ln_frazil, rn_maxfrazb, rn_vfrazb, rn_Cfrazb,                &
-         &                rn_himin, rn_betas, rn_kappa_i, nn_conv_dif, rn_terr_dif, nn_ice_thcon,  &
-         &                nn_monocat, ln_it_qnsice
+      NAMELIST/namicethd/ rn_kappa_i, nn_conv_dif, rn_terr_dif, nn_ice_thcon,ln_it_qnsice,nn_monocat,  &
+         &                ln_limdH, rn_betas,                                                          &
+         &                ln_limdA, rn_beta, rn_dmin,                                                  &
+         &                ln_limdO, rn_hnewice, ln_frazil, rn_maxfrazb, rn_vfrazb, rn_Cfrazb, rn_himin
       !!-------------------------------------------------------------------
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_thd : Ice Thermodynamics'
-         WRITE(numout,*) '~~~~~~~'
-      ENDIF
       !
       REWIND( numnam_ice_ref )              ! Namelist namicethd in reference namelist : Ice thermodynamics
@@ -642,5 +594,22 @@
       IF(lwp) THEN                          ! control print
          WRITE(numout,*)
-         WRITE(numout,*)'   Namelist of ice parameters for ice thermodynamic computation '
+         WRITE(numout,*) 'lim_thd_init : Ice Thermodynamics'
+         WRITE(numout,*) '~~~~~~~~~~~~~'
+         WRITE(numout,*)'   -- limthd_dif --'
+         WRITE(numout,*)'      extinction radiation parameter in sea ice               rn_kappa_i   = ', rn_kappa_i
+         WRITE(numout,*)'      maximal n. of iter. for heat diffusion computation      nn_conv_dif  = ', nn_conv_dif
+         WRITE(numout,*)'      maximal err. on T for heat diffusion computation        rn_terr_dif  = ', rn_terr_dif
+         WRITE(numout,*)'      switch for comp. of thermal conductivity in the ice     nn_ice_thcon = ', nn_ice_thcon
+         WRITE(numout,*)'      iterate the surface non-solar flux (T) or not (F)       ln_it_qnsice = ', ln_it_qnsice
+         WRITE(numout,*)'      virtual ITD mono-category parameterizations (1) or not  nn_monocat   = ', nn_monocat
+         WRITE(numout,*)'   -- limthd_dh --'
+         WRITE(numout,*)'      activate ice thick change from top/bot (T) or not (F)   ln_limdH     = ', ln_limdH
+         WRITE(numout,*)'      coefficient for ice-lead partition of snowfall          rn_betas     = ', rn_betas
+         WRITE(numout,*)'   -- limthd_da --'
+         WRITE(numout,*)'      activate lateral melting (T) or not (F)                 ln_limdA     = ', ln_limdA
+         WRITE(numout,*)'      Coef. beta for lateral melting param.                   rn_beta      = ', rn_beta
+         WRITE(numout,*)'      Minimum floe diameter for lateral melting param.        rn_dmin      = ', rn_dmin
+         WRITE(numout,*)'   -- limthd_lac --'
+         WRITE(numout,*)'      activate ice growth in open-water (T) or not (F)        ln_limdO     = ', ln_limdO
          WRITE(numout,*)'      ice thick. for lateral accretion                        rn_hnewice   = ', rn_hnewice
          WRITE(numout,*)'      Frazil ice thickness as a function of wind or not       ln_frazil    = ', ln_frazil
@@ -648,14 +617,7 @@
          WRITE(numout,*)'      Thresold relative drift speed for collection of frazil  rn_vfrazb    = ', rn_vfrazb
          WRITE(numout,*)'      Squeezing coefficient for collection of frazil          rn_Cfrazb    = ', rn_Cfrazb
+         WRITE(numout,*)'   -- limitd_th --'
          WRITE(numout,*)'      minimum ice thickness                                   rn_himin     = ', rn_himin 
-         WRITE(numout,*)'      numerical carac. of the scheme for diffusion in ice '
-         WRITE(numout,*)'      coefficient for ice-lead partition of snowfall          rn_betas     = ', rn_betas
-         WRITE(numout,*)'      extinction radiation parameter in sea ice               rn_kappa_i   = ', rn_kappa_i
-         WRITE(numout,*)'      maximal n. of iter. for heat diffusion computation      nn_conv_dif  = ', nn_conv_dif
-         WRITE(numout,*)'      maximal err. on T for heat diffusion computation        rn_terr_dif  = ', rn_terr_dif
-         WRITE(numout,*)'      switch for comp. of thermal conductivity in the ice     nn_ice_thcon = ', nn_ice_thcon
          WRITE(numout,*)'      check heat conservation in the ice/snow                 con_i        = ', con_i
-         WRITE(numout,*)'      virtual ITD mono-category parameterizations (1) or not  nn_monocat   = ', nn_monocat
-         WRITE(numout,*)'      iterate the surface non-solar flux (T) or not (F)       ln_it_qnsice = ', ln_it_qnsice
       ENDIF
       !
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_da.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_da.F90	(revision 7309)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_da.F90	(revision 7309)
@@ -0,0 +1,183 @@
+MODULE limthd_da
+   !!======================================================================
+   !!                       ***  MODULE limthd_da ***
+   !! LIM-3 sea-ice :  computation of lateral melting in the ice
+   !!======================================================================
+   !! History :   4.0   ! 2016-03 (C. Rousset) original code
+   !!---------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM-3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_thd_da   : sea ice lateral melting
+   !!----------------------------------------------------------------------
+   USE par_oce                ! ocean parameters
+   USE phycst                 ! physical constants (ocean directory)
+   USE sbc_oce, ONLY: sst_m   ! Surface boundary condition: ocean fields
+   USE ice                    ! LIM variables
+   USE lib_mpp                ! MPP library
+   USE wrk_nemo               ! work arrays
+   USE lib_fortran            ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   lim_thd_da        ! called by limthd module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! $Id: limthd_da.F90 5123 2015-03-04 16:06:03Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE lim_thd_da
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE lim_thd_da  ***    
+      !!   
+      !! ** Purpose :   computes sea ice lateral melting
+      !!
+      !! ** Method  :   dA/dt = - P * W   [s-1]
+      !!                   W = melting velocity [m.s-1]
+      !!                   P = perimeter of ice-ocean lateral interface normalized by grid cell area [m.m-2]
+      !!
+      !!                   W = m1 * (Tw -Tf)**m2                    --- originally from Josberger 1979 ---
+      !!                      (Tw - Tf) = elevation of water temp above freezing
+      !!                      m1 and m2 = (1.6e-6 , 1.36) best fit from field experiment near the coast of Prince Patrick Island (Perovich 1983) => static ice
+      !!                      m1 and m2 = (3.0e-6 , 1.36) best fit from MIZEX 84 experiment (Maykut and Perovich 1987) => moving ice
+      !!
+      !!                   P = N * pi * D                           --- from Rothrock and Thorndike 1984 ---
+      !!                      D = mean floe caliper diameter
+      !!                      N = number of floes = ice area / floe area(average) = A / (Cs * D**2)
+      !!                         A = ice concentration
+      !!                         Cs = deviation from a square (square:Cs=1 ; circle:Cs=pi/4 ; floe:Cs=0.66)
+      !!
+      !!                   D = Dmin * ( Astar / (Astar-A) )**beta   --- from Lupkes et al., 2012 (eq. 26-27) ---
+      !!                                                             
+      !!                      Astar = 1 / ( 1 - (Dmin/Dmax)**(1/beta) )
+      !!                      Dmin = minimum floe diameter (recommended to be 8m +- 20%)
+      !!                      Dmax = maximum floe diameter (recommended to be 300m, but it does not impact melting much except for Dmax<100m)
+      !!                      beta = 1.0 +-20% (recommended value)
+      !!                           = 0.3 best fit for western Fram Strait and Antarctica
+      !!                           = 1.4 best fit for eastern Fram Strait
+      !!
+      !! ** Tunable parameters  :   We propose to tune the lateral melting via 2 parameters
+      !!                               Dmin [6-10m]   => 6  vs 8m = +40% melting at the peak (A~0.5)
+      !!                                                 10 vs 8m = -20% melting
+      !!                               beta [0.8-1.2] => decrease = more melt and melt peaks toward higher concentration
+      !!                                                                  (A~0.5 for beta=1 ; A~0.8 for beta=0.2)
+      !!                                                 0.3 = best fit for western Fram Strait and Antarctica
+      !!                                                 1.4 = best fit for eastern Fram Strait
+      !!
+      !! ** Note   :   Former and more simple formulations for floe diameters can be found in Mai (1995), 
+      !!               Birnbaum and Lupkes (2002), Lupkes and Birnbaum (2005). They are reviewed in Lupkes et al 2012
+      !!               A simpler implementation for CICE can be found in Bitz et al (2001) and Tsamados et al (2015)
+      !!
+      !! ** References
+      !!    Bitz, C. M., Holland, M. M., Weaver, A. J., & Eby, M. (2001).
+      !!              Simulating the ice‐thickness distribution in a coupled climate model.
+      !!              Journal of Geophysical Research: Oceans, 106(C2), 2441-2463.
+      !!    Josberger, E. G. (1979).
+      !!              Laminar and turbulent boundary layers adjacent to melting vertical ice walls in salt water
+      !!              (No. SCIENTIFIC-16). WASHINGTON UNIV SEATTLE DEPT OF ATMOSPHERIC SCIENCES.
+      !!    Lüpkes, C., Gryanik, V. M., Hartmann, J., & Andreas, E. L. (2012).
+      !!              A parametrization, based on sea ice morphology, of the neutral atmospheric drag coefficients
+      !!              for weather prediction and climate models.
+      !!              Journal of Geophysical Research: Atmospheres, 117(D13).
+      !!    Maykut, G. A., & Perovich, D. K. (1987).
+      !!              The role of shortwave radiation in the summer decay of a sea ice cover.
+      !!              Journal of Geophysical Research: Oceans, 92(C7), 7032-7044.
+      !!    Perovich, D. K. (1983).
+      !!              On the summer decay of a sea ice cover. (Doctoral dissertation, University of Washington).
+      !!    Rothrock, D. A., & Thorndike, A. S. (1984).
+      !!              Measuring the sea ice floe size distribution.
+      !!              Journal of Geophysical Research: Oceans, 89(C4), 6477-6486.
+      !!    Tsamados, M., Feltham, D., Petty, A., Schroeder, D., & Flocco, D. (2015).
+      !!              Processes controlling surface, bottom and lateral melt of Arctic sea ice in a state of the art sea ice model.
+      !!              Phil. Trans. R. Soc. A, 373(2052), 20140167.
+      !!---------------------------------------------------------------------
+      INTEGER             ::   ji, jj, jl      ! dummy loop indices
+      REAL(wp)            ::   zastar, zdfloe, zperi, zwlat, zda
+      REAL(wp), PARAMETER ::   zdmax = 300._wp
+      REAL(wp), PARAMETER ::   zcs   = 0.66_wp
+      REAL(wp), PARAMETER ::   zm1   = 3.e-6_wp
+      REAL(wp), PARAMETER ::   zm2   = 1.36_wp
+      !
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zda_tot
+      !!---------------------------------------------------------------------
+      CALL wrk_alloc( jpi,jpj, zda_tot )
+
+      !------------------------------------------------------------!
+      ! --- Calculate reduction of total sea ice concentration --- !
+      !------------------------------------------------------------!
+      zastar = 1._wp / ( 1._wp - (rn_dmin / zdmax)**(1._wp/rn_beta) )
+      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            
+            ! Mean floe caliper diameter [m]
+            zdfloe = rn_dmin * ( zastar / ( zastar - at_i(ji,jj) ) )**rn_beta
+            
+            ! Mean perimeter of the floe = N*pi*D = (A/cs*D^2)*pi*D [m.m-2]
+            zperi = at_i(ji,jj) * rpi / ( zcs * zdfloe )
+            
+            ! Melt speed rate [m/s]
+            zwlat = zm1 * ( MAX( 0._wp, sst_m(ji,jj) - ( t_bo(ji,jj) - rt0 ) ) )**zm2
+            
+            ! sea ice concentration decrease
+            zda_tot(ji,jj) = - MIN( zwlat * zperi * rdt_ice, at_i(ji,jj) )
+            
+         END DO
+      END DO
+      
+      !---------------------------------------------------------------------------------------------!
+      ! --- Distribute reduction among ice categories and calculate associated ice-ocean fluxes --- !
+      !---------------------------------------------------------------------------------------------!
+      DO jl = jpl, 1, -1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               
+               ! decrease of concentration for the category jl
+               !    1st option: each category contributes to melting in proportion to its concentration
+               rswitch = MAX( 0._wp , SIGN( 1._wp, at_i(ji,jj) - epsi10 ) )
+               zda     = rswitch * zda_tot(ji,jj) * a_i(ji,jj,jl) / MAX( at_i(ji,jj), epsi10 )
+               !    2d option: melting of the upper cat first
+               !!zda = MAX( zda_tot(ji,jj), - a_i(ji,jj,jl) )
+               !!zda_tot(ji,jj) = zda_tot(ji,jj) + zda
+               
+               ! Contribution to salt flux
+               sfx_lam(ji,jj) = sfx_lam(ji,jj) - rhoic *  ht_i(ji,jj,jl) * zda * sm_i(ji,jj,jl) * r1_rdtice
+               
+               ! Contribution to heat flux into the ocean [W.m-2], <0  
+               hfx_thd(ji,jj) = hfx_thd(ji,jj) + zda * r1_rdtice * ( ht_i(ji,jj,jl) * SUM( e_i(ji,jj,:,jl) ) * r1_nlay_i  &
+                  &                                                + ht_s(ji,jj,jl) *      e_s(ji,jj,1,jl)   * r1_nlay_s )
+               
+               ! Contribution to mass flux
+               wfx_lam(ji,jj) =  wfx_lam(ji,jj) - zda * r1_rdtice * ( rhoic * ht_i(ji,jj,jl) + rhosn * ht_s(ji,jj,jl) )
+               
+               ! new concentration
+               a_i(ji,jj,jl) = a_i(ji,jj,jl) + zda
+            END DO
+         END DO
+      END DO
+      
+      ! total concentration
+      at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
+      
+      ! --- ensure that ht_i = 0 where a_i = 0 ---
+      WHERE( a_i == 0._wp ) ht_i = 0._wp
+      !
+      CALL wrk_dealloc( jpi,jpj, zda_tot )
+      !
+   END SUBROUTINE lim_thd_da
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Dummy Module          No LIM-3 sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_thd_da          ! Empty routine
+   END SUBROUTINE lim_thd_da
+#endif
+   !!======================================================================
+END MODULE limthd_da
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 7309)
@@ -76,5 +76,4 @@
       REAL(wp) ::   zdum       
       REAL(wp) ::   zfracs       ! fractionation coefficient for bottom salt entrapment
-      REAL(wp) ::   zs_snic      ! snow-ice salinity
       REAL(wp) ::   zswi1        ! switch for computation of bottom salinity
       REAL(wp) ::   zswi12       ! switch for computation of bottom salinity
@@ -116,5 +115,5 @@
 
       ! Discriminate between varying salinity (nn_icesal=2) and prescribed cases (other values)
-      SELECT CASE( nn_icesal )                       ! varying salinity or not
+      SELECT CASE( nn_icesal )                  ! varying salinity or not
          CASE( 1, 3 ) ;   zswitch_sal = 0       ! prescribed salinity profile
          CASE( 2 )    ;   zswitch_sal = 1       ! varying salinity profile
@@ -126,7 +125,4 @@
       CALL wrk_alloc( jpij, nlay_i, icount )
        
-      dh_i_surf  (:) = 0._wp ; dh_i_bott  (:) = 0._wp ; dh_snowice(:) = 0._wp ; dh_i_sub(:) = 0._wp
-      dsm_i_se_1d(:) = 0._wp ; dsm_i_si_1d(:) = 0._wp   
-
       zqprec   (:) = 0._wp ; zq_su    (:) = 0._wp ; zq_bo    (:) = 0._wp ; zf_tt(:) = 0._wp
       zq_rema  (:) = 0._wp ; zsnw     (:) = 0._wp ; zevap_rema(:) = 0._wp ;
@@ -135,5 +131,4 @@
       zdeltah(:,:) = 0._wp ; zh_i(:,:) = 0._wp       
       icount (:,:) = 0
-
 
       ! Initialize enthalpy at nlay_i+1
@@ -618,5 +613,5 @@
          hfx_out(ii,ij)  = hfx_out(ii,ij) + ( zq_rema(ji) * a_i_1d(ji) ) * r1_rdtice
 
-         IF( ln_icectl .AND. zq_rema(ji) < 0. .AND. lwp ) WRITE(numout,*) 'ALERTE zq_rema <0 = ', zq_rema(ji)
+         IF( ln_limctl .AND. zq_rema(ji) < 0. .AND. lwp ) WRITE(numout,*) 'ALERTE zq_rema <0 = ', zq_rema(ji)
       END DO
       
@@ -634,23 +629,7 @@
          ht_s_1d(ji)    = ht_s_1d(ji) - dh_snowice(ji)
 
-         ! Salinity of snow ice
-         ii = MOD( npb(ji) - 1, jpi ) + 1 ; ij = ( npb(ji) - 1 ) / jpi + 1
-         zs_snic = zswitch_sal * sss_m(ii,ij) * ( rhoic - rhosn ) * r1_rhoic + ( 1. - zswitch_sal ) * sm_i_1d(ji)
-
-         ! entrapment during snow ice formation
-         ! new salinity difference stored (to be used in limthd_sal.F90)
-         IF (  nn_icesal == 2  ) THEN
-            rswitch = MAX( 0._wp , SIGN( 1._wp , ht_i_1d(ji) - epsi20 ) )
-            ! salinity dif due to snow-ice formation
-            dsm_i_si_1d(ji) = ( zs_snic - sm_i_1d(ji) ) * dh_snowice(ji) / MAX( ht_i_1d(ji), epsi20 ) * rswitch     
-            ! salinity dif due to bottom growth 
-            IF (  zf_tt(ji)  < 0._wp ) THEN
-               dsm_i_se_1d(ji) = ( s_i_new(ji) - sm_i_1d(ji) ) * dh_i_bott(ji) / MAX( ht_i_1d(ji), epsi20 ) * rswitch
-            ENDIF
-         ENDIF
-
          ! Contribution to energy flux to the ocean [J/m2], >0 (if sst<0)
          ii = MOD( npb(ji) - 1, jpi ) + 1 ; ij = ( npb(ji) - 1 ) / jpi + 1
-         zfmdt          = ( rhosn - rhoic ) * MAX( dh_snowice(ji), 0._wp )    ! <0
+         zfmdt          = ( rhosn - rhoic ) * dh_snowice(ji)    ! <0
          zsstK          = sst_m(ii,ij) + rt0                                
          zEw            = rcp * ( zsstK - rt0 )
@@ -662,9 +641,9 @@
          ! Contribution to salt flux
          sfx_sni_1d(ji) = sfx_sni_1d(ji) + sss_m(ii,ij) * a_i_1d(ji) * zfmdt * r1_rdtice 
-          
+
          ! virtual salt flux to keep salinity constant
          IF( nn_icesal == 1 .OR. nn_icesal == 3 )  THEN
-            sfx_bri_1d(ji) = sfx_bri_1d(ji) - sss_m(ii,ij) * a_i_1d(ji) * zfmdt                  * r1_rdtice  & ! put back sss_m into the ocean
-               &                            - sm_i_1d(ji)  * a_i_1d(ji) * dh_snowice(ji) * rhoic * r1_rdtice    ! and get  sm_i  from the ocean 
+            sfx_bri_1d(ji) = sfx_bri_1d(ji) - sss_m(ii,ij) * a_i_1d(ji) * zfmdt                  * r1_rdtice  & ! put back sss_m     into the ocean
+               &                            - sm_i_1d(ji)  * a_i_1d(ji) * dh_snowice(ji) * rhoic * r1_rdtice    ! and get  rn_icesal from the ocean 
          ENDIF
 
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90	(revision 7309)
@@ -734,5 +734,5 @@
       END DO  ! End of the do while iterative procedure
 
-      IF( ln_icectl .AND. lwp ) THEN
+      IF( ln_limctl .AND. lwp ) THEN
          WRITE(numout,*) ' zerritmax : ', zerritmax
          WRITE(numout,*) ' nconv     : ', nconv
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90	(revision 7309)
@@ -21,5 +21,4 @@
    USE sbc_ice        ! Surface boundary condition: ice fields
    USE thd_ice        ! LIM thermodynamics
-   USE dom_ice        ! LIM domain
    USE ice            ! LIM variables
    USE limtab         ! LIM 2D <==> 1D
@@ -71,8 +70,8 @@
       !!               update ht_s_1d, ht_i_1d and tbif_1d(:,:)      
       !!------------------------------------------------------------------------
-      INTEGER ::   ji,jj,jk,jl      ! dummy loop indices
-      INTEGER ::   nbpac            ! local integers 
-      INTEGER ::   ii, ij, iter     !   -       -
-      REAL(wp)  ::   ztmelts, zdv, zfrazb, zweight, zde                         ! local scalars
+      INTEGER  ::   ji,jj,jk,jl      ! dummy loop indices
+      INTEGER  ::   nbpac            ! local integers 
+      INTEGER  ::   ii, ij, iter     !   -       -
+      REAL(wp) ::   ztmelts, zdv, zfrazb, zweight, zde                          ! local scalars
       REAL(wp) ::   zgamafr, zvfrx, zvgx, ztaux, ztwogp, zf                     !   -      -
       REAL(wp) ::   ztenagm, zvfry, zvgy, ztauy, zvrel2, zfp, zsqcd , zhicrit   !   -      -
@@ -154,6 +153,6 @@
 
       ! Default new ice thickness
-      WHERE( qlead(:,:) < 0._wp ) ; hicol = rn_hnewice
-      ELSEWHERE                   ; hicol = 0._wp
+      WHERE( qlead(:,:) < 0._wp ) ; hicol(:,:) = rn_hnewice
+      ELSEWHERE                   ; hicol(:,:) = 0._wp
       END WHERE
 
@@ -170,7 +169,7 @@
          zgamafr = 0.03
 
-         DO jj = 2, jpj
-            DO ji = 2, jpi
-               IF ( qlead(ji,jj) < 0._wp ) THEN
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               IF ( qlead(ji,jj) < 0._wp .AND. tau_icebfr(ji,jj) == 0._wp ) THEN ! activated if cooling and no landfast
                   !-------------
                   ! Wind stress
@@ -195,7 +194,6 @@
                   !-------------------
                   ! C-grid ice velocity
-                  rswitch = MAX(  0._wp, SIGN( 1._wp , at_i(ji,jj) )  )
-                  zvgx    = rswitch * ( u_ice(ji-1,jj  ) * umask(ji-1,jj  ,1)  + u_ice(ji,jj) * umask(ji,jj,1) ) * 0.5_wp
-                  zvgy    = rswitch * ( v_ice(ji  ,jj-1) * vmask(ji  ,jj-1,1)  + v_ice(ji,jj) * vmask(ji,jj,1) ) * 0.5_wp
+                  zvgx    = ( u_ice(ji-1,jj  ) * umask(ji-1,jj  ,1)  + u_ice(ji,jj) * umask(ji,jj,1) ) * 0.5_wp
+                  zvgy    = ( v_ice(ji  ,jj-1) * vmask(ji  ,jj-1,1)  + v_ice(ji,jj) * vmask(ji,jj,1) ) * 0.5_wp
 
                   !-----------------------------------
@@ -203,6 +201,7 @@
                   !-----------------------------------
                   ! absolute relative velocity
-                  zvrel2 = MAX(  ( zvfrx - zvgx ) * ( zvfrx - zvgx )   &
-                     &         + ( zvfry - zvgy ) * ( zvfry - zvgy ) , 0.15 * 0.15 )
+                  rswitch      = MAX( 0._wp, SIGN( 1._wp , at_i(ji,jj) - epsi10 ) )
+                  zvrel2       = MAX(  ( zvfrx - zvgx ) * ( zvfrx - zvgx )   &
+                     &               + ( zvfry - zvgy ) * ( zvfry - zvgy ) , 0.15 * 0.15 ) * rswitch
                   zvrel(ji,jj) = SQRT( zvrel2 )
 
@@ -219,5 +218,5 @@
                      zfp = ( hicol(ji,jj) - zhicrit ) * ( 3.0 * hicol(ji,jj) + zhicrit ) - zhicrit * ztwogp * zvrel2
 
-                     hicol(ji,jj) = hicol(ji,jj) - zf/zfp
+                     hicol(ji,jj) = hicol(ji,jj) - zf / MAX( zfp, epsi20 )
                      iter = iter + 1
                   END DO
@@ -228,6 +227,6 @@
          END DO 
          ! 
-         CALL lbc_lnk( zvrel(:,:), 'T', 1. )
-         CALL lbc_lnk( hicol(:,:), 'T', 1. )
+         CALL lbc_lnk( zvrel, 'T', 1. )
+         CALL lbc_lnk( hicol, 'T', 1. )
 
       ENDIF ! End of computation of frazil ice collection thickness
@@ -240,5 +239,5 @@
       ! Select points for new ice formation
       !-------------------------------------
-      ! This occurs if open water energy budget is negative
+      ! This occurs if open water energy budget is negative (cooling) and there is no landfast ice
       nbpac = 0
       npac(:) = 0
@@ -246,5 +245,5 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            IF ( qlead(ji,jj)  <  0._wp ) THEN
+            IF ( qlead(ji,jj)  <  0._wp .AND. tau_icebfr(ji,jj) == 0._wp ) THEN
                nbpac = nbpac + 1
                npac( nbpac ) = (jj - 1) * jpi + ji
@@ -255,5 +254,5 @@
       ! debug point to follow
       jiindex_1d = 0
-      IF( ln_icectl ) THEN
+      IF( ln_limctl ) THEN
          DO ji = mi0(iiceprt), mi1(iiceprt)
             DO jj = mj0(jiceprt), mj1(jiceprt)
@@ -265,5 +264,5 @@
       ENDIF
    
-      IF( ln_icectl ) WRITE(numout,*) 'lim_thd_lac : nbpac = ', nbpac
+      IF( ln_limctl ) WRITE(numout,*) 'lim_thd_lac : nbpac = ', nbpac
 
       !------------------------------
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_sal.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_sal.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limthd_sal.F90	(revision 7309)
@@ -51,15 +51,9 @@
       INTEGER, INTENT(in) ::   kideb, kiut   ! thickness category index
       !
-      INTEGER  ::   ji, jk     ! dummy loop indices 
-      REAL(wp) ::   iflush, igravdr   ! local scalars
+      INTEGER  ::   ii, ij, ji, jk               ! dummy loop indices 
+      REAL(wp) ::   iflush, igravdr              ! local scalars
+      REAL(wp) ::   zs_sni, zsm_i_gd, zsm_i_fl, zsm_i_si, zsm_i_bg   ! local scalars
       !!---------------------------------------------------------------------
 
-      !---------------------------------------------------------
-      !  0) Update ice salinity from snow-ice and bottom growth
-      !---------------------------------------------------------
-      DO ji = kideb, kiut
-         sm_i_1d(ji) = sm_i_1d(ji) + dsm_i_se_1d(ji) + dsm_i_si_1d(ji)
-      END DO
- 
       !--------------------------------------------------------------------|
       ! 1) salinity constant in time                                       |
@@ -73,30 +67,32 @@
 
          DO ji = kideb, kiut
-            !
-            ! Switches 
-            !----------
-            iflush  = MAX( 0._wp , SIGN( 1._wp , t_su_1d(ji) - rt0 )        )     ! =1 if summer 
-            igravdr = MAX( 0._wp , SIGN( 1._wp , t_bo_1d(ji) - t_su_1d(ji) ) )    ! =1 if t_su < t_bo
 
-            !---------------------
-            ! Salinity tendencies
-            !---------------------
-            ! drainage by gravity drainage
-            dsm_i_gd_1d(ji) = - igravdr * MAX( sm_i_1d(ji) - rn_sal_gd , 0._wp ) / rn_time_gd * rdt_ice 
-            ! drainage by flushing  
-            dsm_i_fl_1d(ji) = - iflush  * MAX( sm_i_1d(ji) - rn_sal_fl , 0._wp ) / rn_time_fl * rdt_ice
+            ii = MOD( npb(ji) - 1, jpi ) + 1 ; ij = ( npb(ji) - 1 ) / jpi + 1
+            !---------------------------------------------------------
+            !  Update ice salinity from snow-ice and bottom growth
+            !---------------------------------------------------------
+            zs_sni   = sss_m(ii,ij) * ( rhoic - rhosn ) * r1_rhoic   ! Salinity of snow ice
+            rswitch  = MAX( 0._wp , SIGN( 1._wp , ht_i_1d(ji) - epsi20 ) )
+            zsm_i_si = ( zs_sni      - sm_i_1d(ji) ) *             dh_snowice(ji)  / MAX( ht_i_1d(ji), epsi20 ) * rswitch ! snow-ice    
+            zsm_i_bg = ( s_i_new(ji) - sm_i_1d(ji) ) * MAX( 0._wp, dh_i_bott(ji) ) / MAX( ht_i_1d(ji), epsi20 ) * rswitch ! bottom growth
 
-            !-----------------
-            ! Update salinity   
-            !-----------------
-            ! only drainage terms ( gravity drainage and flushing )
-            ! snow ice / bottom sources are added in lim_thd_ent to conserve energy
-            sm_i_1d(ji) = sm_i_1d(ji) + dsm_i_fl_1d(ji) + dsm_i_gd_1d(ji)
+            ! Update salinity (nb: salt flux already included in limthd_dh)
+            sm_i_1d(ji) = sm_i_1d(ji) + zsm_i_bg + zsm_i_si
 
-            !----------------------------
-            ! Salt flux - brine drainage
-            !----------------------------
-            sfx_bri_1d(ji) = sfx_bri_1d(ji) - rhoic * a_i_1d(ji) * ht_i_1d(ji) * ( dsm_i_fl_1d(ji) + dsm_i_gd_1d(ji) ) * r1_rdtice
-
+            IF( ln_limdS ) THEN
+               !---------------------------------------------------------
+               !  Update ice salinity from brine drainage and flushing
+               !---------------------------------------------------------
+               iflush   = MAX( 0._wp , SIGN( 1._wp , t_su_1d(ji) - rt0         ) )  ! =1 if summer 
+               igravdr  = MAX( 0._wp , SIGN( 1._wp , t_bo_1d(ji) - t_su_1d(ji) ) )  ! =1 if t_su < t_bo
+               zsm_i_gd = - igravdr * MAX( sm_i_1d(ji) - rn_sal_gd , 0._wp ) / rn_time_gd * rdt_ice  ! gravity drainage 
+               zsm_i_fl = - iflush  * MAX( sm_i_1d(ji) - rn_sal_fl , 0._wp ) / rn_time_fl * rdt_ice  ! flushing
+               
+               ! Update salinity   
+               sm_i_1d(ji) = sm_i_1d(ji) + zsm_i_fl + zsm_i_gd
+               
+               ! Salt flux
+               sfx_bri_1d(ji) = sfx_bri_1d(ji) - rhoic * a_i_1d(ji) * ht_i_1d(ji) * ( zsm_i_fl + zsm_i_gd ) * r1_rdtice
+            ENDIF
          END DO
 
@@ -127,6 +123,6 @@
       !!-------------------------------------------------------------------
       INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicesal/ nn_icesal, rn_icesal, rn_sal_gd, rn_time_gd, rn_sal_fl, rn_time_fl,   &
-         &                rn_simax, rn_simin 
+      NAMELIST/namicesal/ ln_limdS, nn_icesal, rn_icesal, rn_sal_gd, rn_time_gd,   &
+         &                rn_sal_fl, rn_time_fl, rn_simax, rn_simin 
       !!-------------------------------------------------------------------
       !
@@ -144,12 +140,13 @@
          WRITE(numout,*) 'lim_thd_sal_init : Ice parameters for salinity '
          WRITE(numout,*) '~~~~~~~~~~~~~~~~'
-         WRITE(numout,*) '   switch for salinity nn_icesal        = ', nn_icesal
-         WRITE(numout,*) '   bulk salinity value if nn_icesal = 1 = ', rn_icesal
-         WRITE(numout,*) '   restoring salinity for GD            = ', rn_sal_gd
-         WRITE(numout,*) '   restoring time for GD                = ', rn_time_gd
-         WRITE(numout,*) '   restoring salinity for flushing      = ', rn_sal_fl
-         WRITE(numout,*) '   restoring time for flushing          = ', rn_time_fl
-         WRITE(numout,*) '   Maximum tolerated ice salinity       = ', rn_simax
-         WRITE(numout,*) '   Minimum tolerated ice salinity       = ', rn_simin
+         WRITE(numout,*) '   activate gravity drainage and flushing (T) or not (F)   ln_limdS   = ', ln_limdS
+         WRITE(numout,*) '   switch for salinity                                     nn_icesal  = ', nn_icesal
+         WRITE(numout,*) '   bulk salinity value if nn_icesal = 1                    rn_icesal  = ', rn_icesal
+         WRITE(numout,*) '   restoring salinity for gravity drainage                 rn_sal_gd  = ', rn_sal_gd
+         WRITE(numout,*) '   restoring time for for gravity drainage                 rn_time_gd = ', rn_time_gd
+         WRITE(numout,*) '   restoring salinity for flushing                         rn_sal_fl  = ', rn_sal_fl
+         WRITE(numout,*) '   restoring time for flushing                             rn_time_fl = ', rn_time_fl
+         WRITE(numout,*) '   Maximum tolerated ice salinity                          rn_simax   = ', rn_simax
+         WRITE(numout,*) '   Minimum tolerated ice salinity                          rn_simin   = ', rn_simin
       ENDIF
       !
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limtrp.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limtrp.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limtrp.F90	(revision 7309)
@@ -17,9 +17,9 @@
    USE dom_oce        ! ocean domain
    USE sbc_oce        ! ocean surface boundary condition
-   USE dom_ice        ! ice domain
    USE ice            ! ice variables
-   USE limadv         ! ice advection
    USE limhdf         ! ice horizontal diffusion
    USE limvar         ! 
+   USE limadv_prather ! advection scheme (Prather)
+   USE limadv_umx     ! advection scheme (ultimate-macho)
    !
    USE in_out_manager ! I/O manager
@@ -57,112 +57,179 @@
       !! ** method  : variables included in the process are scalar,   
       !!     other values are considered as second order. 
-      !!     For advection, a second order Prather scheme is used.  
+      !!     For advection, one can choose between
+      !!     a) an Ultimate-Macho scheme (whose order is defined by nn_limadv_ord) => nn_limadv=0
+      !!     b) and a second order Prather scheme => nn_limadv=-1
       !!
       !! ** action :
       !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt           ! number of iteration
+      INTEGER, INTENT(in) ::   kt   ! number of iteration
       !
-      INTEGER  ::   ji, jj, jk, jm , jl, jt      ! dummy loop indices
+      INTEGER  ::   ji, jj, jk, jm, jl, jt  ! dummy loop indices
       INTEGER  ::   initad                  ! number of sub-timestep for the advection
       REAL(wp) ::   zcfl , zusnit           !   -      -
-      CHARACTER(len=80) ::   cltmp
+      CHARACTER(len=80) :: cltmp
       !
-      REAL(wp), POINTER, DIMENSION(:,:)      ::   zsm
+      REAL(wp) ::    zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b
+      REAL(wp) ::    zdv, zda
+      REAL(wp), POINTER, DIMENSION(:,:)      ::   zatold, zeiold, zesold, zsmvold 
+      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   zhimax, zviold, zvsold
+      ! --- diffusion --- !
+      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   zhdfptab
+      INTEGER , PARAMETER                    ::   ihdf_vars  = 6 ! Number of variables in which we apply horizontal diffusion
+                                                                 !  inside limtrp for each ice category , not counting the 
+                                                                 !  variables corresponding to ice_layers 
+      ! --- ultimate macho only --- !
+      REAL(wp)                               ::   zdt
+      REAL(wp), POINTER, DIMENSION(:,:)      ::   zudy, zvdx, zcu_box, zcv_box
+      ! --- prather only --- !
+      REAL(wp), POINTER, DIMENSION(:,:)      ::   zarea
+      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   z0opw
       REAL(wp), POINTER, DIMENSION(:,:,:)    ::   z0ice, z0snw, z0ai, z0es , z0smi , z0oi
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   z0opw
       REAL(wp), POINTER, DIMENSION(:,:,:,:)  ::   z0ei
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   zviold, zvsold, zsmvold  ! old ice volume...
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   zhimax                   ! old ice thickness
-      REAL(wp), POINTER, DIMENSION(:,:)      ::   zatold, zeiold, zesold   ! old concentration, enthalpies
-      REAL(wp), POINTER, DIMENSION(:,:,:)             ::   zhdfptab
-      REAL(wp) ::    zdv, zvi, zvs, zsmv, zes, zei
-      REAL(wp) ::    zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b
-      !!---------------------------------------------------------------------
-      INTEGER                                ::  ihdf_vars  = 6  !!Number of variables in which we apply horizontal diffusion
-                                                                   !!  inside limtrp for each ice category , not counting the 
-                                                                   !!  variables corresponding to ice_layers 
+      !!
       !!---------------------------------------------------------------------
       IF( nn_timing == 1 )  CALL timing_start('limtrp')
 
-      CALL wrk_alloc( jpi,jpj,            zsm, zatold, zeiold, zesold )
-      CALL wrk_alloc( jpi,jpj,jpl,        z0ice, z0snw, z0ai, z0es , z0smi , z0oi )
-      CALL wrk_alloc( jpi,jpj,1,          z0opw )
-      CALL wrk_alloc( jpi,jpj,nlay_i,jpl, z0ei )
-      CALL wrk_alloc( jpi,jpj,jpl,        zhimax, zviold, zvsold, zsmvold )
-      CALL wrk_alloc( jpi,jpj,jpl*(ihdf_vars + nlay_i)+1,zhdfptab)
-
-      IF( numit == nstart .AND. lwp ) THEN
-         WRITE(numout,*)
-         IF( ln_limdyn ) THEN   ;   WRITE(numout,*) 'lim_trp : Ice transport '
-         ELSE                   ;   WRITE(numout,*) 'lim_trp : No ice advection as ln_limdyn = ', ln_limdyn
-         ENDIF
-         WRITE(numout,*) '~~~~~~~~~~~~'
+      CALL wrk_alloc( jpi,jpj,                            zatold, zeiold, zesold, zsmvold )
+      CALL wrk_alloc( jpi,jpj,jpl,                        zhimax, zviold, zvsold )
+      CALL wrk_alloc( jpi,jpj,jpl*(ihdf_vars + nlay_i)+1, zhdfptab)
+ 
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)''
+         WRITE(numout,*)'limtrp'
+         WRITE(numout,*)'~~~~~~'
          ncfl = 0                ! nb of time step with CFL > 1/2
       ENDIF
-
-      zsm(:,:) = e1e2t(:,:)
-      
-      !                             !-------------------------------------!
-      IF( ln_limdyn ) THEN          !   Advection of sea ice properties   !
-         !                          !-------------------------------------!
-
-         ! conservation test
-         IF( ln_limdiahsb )   CALL lim_cons_hsm(0, 'limtrp', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-         ! mass and salt flux init
-         zviold(:,:,:)  = v_i(:,:,:)
-         zvsold(:,:,:)  = v_s(:,:,:)
-         zsmvold(:,:,:) = smv_i(:,:,:)
-         zeiold(:,:)    = SUM( SUM( e_i(:,:,1:nlay_i,:), dim=4 ), dim=3 ) 
-         zesold(:,:)    = SUM( SUM( e_s(:,:,1:nlay_s,:), dim=4 ), dim=3 ) 
-
-         !--- Thickness correction init. -------------------------------
-         zatold(:,:) = SUM( a_i(:,:,:), dim=3 )
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch          = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )
-                  ht_i  (ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-                  ht_s  (ji,jj,jl) = v_s (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
+      
+      CALL lim_var_agg( 1 ) ! integrated values + ato_i
+
+      !-------------------------------------!
+      !   Advection of sea ice properties   !
+      !-------------------------------------!
+
+      ! conservation test
+      IF( ln_limdiachk )   CALL lim_cons_hsm(0, 'limtrp', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      
+      ! store old values for diag
+      zviold = v_i
+      zvsold = v_s
+      zsmvold(:,:) = SUM( smv_i(:,:,:), dim=3 )
+      zeiold (:,:) = et_i
+      zesold (:,:) = et_s 
+
+      !--- Thickness correction init. --- !
+      zatold(:,:) = at_i
+      DO jl = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               rswitch          = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )
+               ht_i  (ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
+               ht_s  (ji,jj,jl) = v_s (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
+            END DO
+         END DO
+      END DO
+      ! --- Record max of the surrounding ice thicknesses for correction in case advection creates ice too thick --- !
+      zhimax(:,:,:) = ht_i(:,:,:) + ht_s(:,:,:)
+      DO jl = 1, jpl
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               zhimax(ji,jj,jl) = MAXVAL( ht_i(ji-1:ji+1,jj-1:jj+1,jl) + ht_s(ji-1:ji+1,jj-1:jj+1,jl) )
+            END DO
+         END DO
+         CALL lbc_lnk(zhimax(:,:,jl),'T',1.)
+      END DO
+         
+      ! --- If ice drift field is too fast, use an appropriate time step for advection --- !        
+      zcfl  =            MAXVAL( ABS( u_ice(:,:) ) * rdt_ice * r1_e1u(:,:) )    ! CFL test for stability
+      zcfl  = MAX( zcfl, MAXVAL( ABS( v_ice(:,:) ) * rdt_ice * r1_e2v(:,:) ) )
+      IF( lk_mpp )   CALL mpp_max( zcfl )
+      
+      IF( zcfl > 0.5 ) THEN   ;   initad = 2   ;   zusnit = 0.5_wp
+      ELSE                    ;   initad = 1   ;   zusnit = 1.0_wp
+      ENDIF
+      
+!!      IF( zcfl > 0.5_wp .AND. lwp ) THEN
+!!         ncfl = ncfl + 1
+!!         IF( ncfl > 0 ) THEN   
+!!            WRITE(cltmp,'(i6.1)') ncfl
+!!            CALL ctl_warn( 'lim_trp: ncfl= ', TRIM(cltmp), 'advective ice time-step using a split in sub-time-step ')
+!!         ENDIF
+!!      ENDIF
+
+      SELECT CASE ( nn_limadv )
+         
+                       !=============================!
+      CASE ( 0 )       !==  Ultimate-MACHO scheme  ==!                   
+                       !=============================!
+      
+         CALL wrk_alloc( jpi,jpj, zudy, zvdx, zcu_box, zcv_box )
+      
+         IF( kt == nit000 .AND. lwp ) THEN
+            WRITE(numout,*)''
+            WRITE(numout,*)'lim_adv_umx : Ultimate-MACHO advection scheme'
+            WRITE(numout,*)'~~~~~~~~~~~'
+         ENDIF
+         !
+         zdt = rdt_ice / REAL(initad)
+         
+         ! transport
+         zudy(:,:) = u_ice(:,:) * e2u(:,:)
+         zvdx(:,:) = v_ice(:,:) * e1v(:,:)
+         
+         ! define velocity for advection: u*grad(H)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               IF    ( u_ice(ji,jj) * u_ice(ji-1,jj) <= 0._wp ) THEN   ;   zcu_box(ji,jj) = 0._wp
+               ELSEIF( u_ice(ji,jj)                  >  0._wp ) THEN   ;   zcu_box(ji,jj) = u_ice(ji-1,jj)
+               ELSE                                                    ;   zcu_box(ji,jj) = u_ice(ji  ,jj)
+               ENDIF
+               
+               IF    ( v_ice(ji,jj) * v_ice(ji,jj-1) <= 0._wp ) THEN   ;   zcv_box(ji,jj) = 0._wp
+               ELSEIF( v_ice(ji,jj)                  >  0._wp ) THEN   ;   zcv_box(ji,jj) = v_ice(ji,jj-1)
+               ELSE                                                    ;   zcv_box(ji,jj) = v_ice(ji,jj  )
+               ENDIF
+            END DO
+         END DO
+         
+         ! advection
+         DO jt = 1, initad
+            CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, ato_i(:,:) )       ! Open water area 
+            DO jl = 1, jpl
+               CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, a_i(:,:,jl) )      ! Ice area
+               CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, v_i(:,:,jl) )      ! Ice  volume
+               CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, smv_i(:,:,jl) )    ! Salt content
+               CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, oa_i (:,:,jl) )    ! Age content
+               DO jk = 1, nlay_i
+                  CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, e_i(:,:,jk,jl) )   ! Ice  heat content
                END DO
-            END DO
-         END DO
-         !---------------------------------------------------------------------
-         ! Record max of the surrounding ice thicknesses for correction
-         ! in case advection creates ice too thick.
-         !---------------------------------------------------------------------
-         zhimax(:,:,:) = ht_i(:,:,:) + ht_s(:,:,:)
-         DO jl = 1, jpl
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  zhimax(ji,jj,jl) = MAXVAL( ht_i(ji-1:ji+1,jj-1:jj+1,jl) + ht_s(ji-1:ji+1,jj-1:jj+1,jl) )
-               END DO
-            END DO
-            CALL lbc_lnk(zhimax(:,:,jl),'T',1.)
-         END DO
-         
-         !=============================!
-         !==      Prather scheme     ==!
-         !=============================!
-
-         ! If ice drift field is too fast, use an appropriate time step for advection.         
-         zcfl  =            MAXVAL( ABS( u_ice(:,:) ) * rdt_ice * r1_e1u(:,:) )         ! CFL test for stability
-         zcfl  = MAX( zcfl, MAXVAL( ABS( v_ice(:,:) ) * rdt_ice * r1_e2v(:,:) ) )
-         IF(lk_mpp )   CALL mpp_max( zcfl )
-
-         IF( zcfl > 0.5 ) THEN   ;   initad = 2   ;   zusnit = 0.5_wp
-         ELSE                    ;   initad = 1   ;   zusnit = 1.0_wp
+               CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, v_s(:,:,jl) )      ! Snow volume
+               CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, e_s(:,:,1,jl) )    ! Snow heat content
+            END DO
+         END DO
+         !
+         at_i(:,:) = a_i(:,:,1)      ! total ice fraction
+         DO jl = 2, jpl
+            at_i(:,:) = at_i(:,:) + a_i(:,:,jl)
+         END DO
+         !
+         CALL wrk_dealloc( jpi,jpj, zudy, zvdx, zcu_box, zcv_box )
+         
+                       !=============================!
+      CASE ( -1 )      !==     Prather scheme      ==!                   
+                       !=============================!
+
+         CALL wrk_alloc( jpi,jpj,            zarea )
+         CALL wrk_alloc( jpi,jpj,1,          z0opw )
+         CALL wrk_alloc( jpi,jpj,jpl,        z0ice, z0snw, z0ai, z0es , z0smi , z0oi )
+         CALL wrk_alloc( jpi,jpj,nlay_i,jpl, z0ei )
+         
+         IF( kt == nit000 .AND. lwp ) THEN
+            WRITE(numout,*)''
+            WRITE(numout,*)'lim_adv_xy : Prather advection scheme'
+            WRITE(numout,*)'~~~~~~~~~~~'
          ENDIF
-
-         IF( zcfl > 0.5_wp .AND. lwp )   ncfl = ncfl + 1
-!!         IF( lwp ) THEN
-!!            IF( ncfl > 0 ) THEN   
-!!               WRITE(cltmp,'(i6.1)') ncfl
-!!               CALL ctl_warn( 'lim_trp: ncfl= ', TRIM(cltmp), 'advective ice time-step using a split in sub-time-step ')
-!!            ELSE
-!!            !  WRITE(numout,*) 'lim_trp : CFL criterion for ice advection is always smaller than 1/2 '
-!!            ENDIF
-!!         ENDIF
-
+         
+         zarea(:,:) = e1e2t(:,:)
+         
          !-------------------------
          ! transported fields                                        
@@ -176,5 +243,5 @@
             z0oi (:,:,jl)   = oa_i (:,:,  jl) * e1e2t(:,:)  ! Age content
             z0es (:,:,jl)   = e_s  (:,:,1,jl) * e1e2t(:,:)  ! Snow heat content
-           DO jk = 1, nlay_i
+            DO jk = 1, nlay_i
                z0ei  (:,:,jk,jl) = e_i  (:,:,jk,jl) * e1e2t(:,:) ! Ice  heat content
             END DO
@@ -184,40 +251,40 @@
          IF( MOD( ( kt - 1) / nn_fsbc , 2 ) == 0 ) THEN       !==  odd ice time step:  adv_x then adv_y  ==!
             DO jt = 1, initad
-               CALL lim_adv_x( zusnit, u_ice, 1._wp, zsm, z0opw (:,:,1), sxopw(:,:),   &             !--- ice open water area
-                  &                                       sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
-               CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, z0opw (:,:,1), sxopw(:,:),   &
-                  &                                       sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
+               CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0opw (:,:,1), sxopw(:,:),   &             !--- ice open water area
+                  &                                         sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
+               CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0opw (:,:,1), sxopw(:,:),   &
+                  &                                         sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
                DO jl = 1, jpl
-                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zsm, z0ice (:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
-                     &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, z0ice (:,:,jl), sxice(:,:,jl),   &
-                     &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zsm, z0snw (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
-                     &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, z0snw (:,:,jl), sxsn (:,:,jl),   &
-                     &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zsm, z0smi (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
-                     &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, z0smi (:,:,jl), sxsal(:,:,jl),   &
-                     &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zsm, z0oi  (:,:,jl), sxage(:,:,jl),   &    !--- ice age      ---     
-                     &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, z0oi  (:,:,jl), sxage(:,:,jl),   &
-                     &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zsm, z0ai  (:,:,jl), sxa  (:,:,jl),   &    !--- ice concentrations ---
-                     &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, z0ai  (:,:,jl), sxa  (:,:,jl),   & 
-                     &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zsm, z0es  (:,:,jl), sxc0 (:,:,jl),   &    !--- snow heat contents ---
-                     &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, z0es  (:,:,jl), sxc0 (:,:,jl),   &
-                     &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
+                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0ice (:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
+                     &                                         sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
+                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0ice (:,:,jl), sxice(:,:,jl),   &
+                     &                                         sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
+                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0snw (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
+                     &                                         sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
+                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0snw (:,:,jl), sxsn (:,:,jl),   &
+                     &                                         sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
+                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0smi (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
+                     &                                         sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
+                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0smi (:,:,jl), sxsal(:,:,jl),   &
+                     &                                         sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
+                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0oi  (:,:,jl), sxage(:,:,jl),   &    !--- ice age      ---     
+                     &                                         sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
+                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0oi  (:,:,jl), sxage(:,:,jl),   &
+                     &                                         sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
+                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0ai  (:,:,jl), sxa  (:,:,jl),   &    !--- ice concentrations ---
+                     &                                         sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
+                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0ai  (:,:,jl), sxa  (:,:,jl),   & 
+                     &                                         sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
+                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0es  (:,:,jl), sxc0 (:,:,jl),   &    !--- snow heat contents ---
+                     &                                         sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
+                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0es  (:,:,jl), sxc0 (:,:,jl),   &
+                     &                                         sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
                   DO jk = 1, nlay_i                                                                !--- ice heat contents ---
-                     CALL lim_adv_x( zusnit, u_ice, 1._wp, zsm, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
-                        &                                       sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
-                        &                                       syye(:,:,jk,jl), sxye(:,:,jk,jl) )
-                     CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
-                        &                                       sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
-                        &                                       syye(:,:,jk,jl), sxye(:,:,jk,jl) )
+                     CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
+                        &                                         sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
+                        &                                         syye(:,:,jk,jl), sxye(:,:,jk,jl) )
+                     CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
+                        &                                         sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
+                        &                                         syye(:,:,jk,jl), sxye(:,:,jk,jl) )
                   END DO
                END DO
@@ -225,40 +292,40 @@
          ELSE
             DO jt = 1, initad
-               CALL lim_adv_y( zusnit, v_ice, 1._wp, zsm, z0opw (:,:,1), sxopw(:,:),   &             !--- ice open water area
-                  &                                       sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
-               CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, z0opw (:,:,1), sxopw(:,:),   &
-                  &                                       sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
+               CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0opw (:,:,1), sxopw(:,:),   &             !--- ice open water area
+                  &                                         sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
+               CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0opw (:,:,1), sxopw(:,:),   &
+                  &                                         sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
                DO jl = 1, jpl
-                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zsm, z0ice (:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
-                     &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, z0ice (:,:,jl), sxice(:,:,jl),   &
-                     &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zsm, z0snw (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
-                     &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, z0snw (:,:,jl), sxsn (:,:,jl),   &
-                     &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zsm, z0smi (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
-                     &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, z0smi (:,:,jl), sxsal(:,:,jl),   &
-                     &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zsm, z0oi  (:,:,jl), sxage(:,:,jl),   &   !--- ice age      ---
-                     &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, z0oi  (:,:,jl), sxage(:,:,jl),   &
-                     &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zsm, z0ai  (:,:,jl), sxa  (:,:,jl),   &   !--- ice concentrations ---
-                     &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, z0ai  (:,:,jl), sxa  (:,:,jl),   &
-                     &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zsm, z0es  (:,:,jl), sxc0 (:,:,jl),   &  !--- snow heat contents ---
-                     &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, z0es  (:,:,jl), sxc0 (:,:,jl),   &
-                     &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
+                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0ice (:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
+                     &                                         sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
+                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0ice (:,:,jl), sxice(:,:,jl),   &
+                     &                                         sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
+                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0snw (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
+                     &                                         sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
+                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0snw (:,:,jl), sxsn (:,:,jl),   &
+                     &                                         sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
+                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0smi (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
+                     &                                         sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
+                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0smi (:,:,jl), sxsal(:,:,jl),   &
+                     &                                         sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
+                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0oi  (:,:,jl), sxage(:,:,jl),   &   !--- ice age      ---
+                     &                                         sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
+                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0oi  (:,:,jl), sxage(:,:,jl),   &
+                     &                                         sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
+                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0ai  (:,:,jl), sxa  (:,:,jl),   &   !--- ice concentrations ---
+                     &                                         sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
+                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0ai  (:,:,jl), sxa  (:,:,jl),   &
+                     &                                         sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
+                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0es  (:,:,jl), sxc0 (:,:,jl),   &  !--- snow heat contents ---
+                     &                                         sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
+                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0es  (:,:,jl), sxc0 (:,:,jl),   &
+                     &                                         sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
                   DO jk = 1, nlay_i                                                           !--- ice heat contents ---
-                     CALL lim_adv_y( zusnit, v_ice, 1._wp, zsm, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
-                        &                                       sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
-                        &                                       syye(:,:,jk,jl), sxye(:,:,jk,jl) )
-                     CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
-                        &                                       sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
-                        &                                       syye(:,:,jk,jl), sxye(:,:,jk,jl) )
+                     CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
+                        &                                         sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
+                        &                                         syye(:,:,jk,jl), sxye(:,:,jk,jl) )
+                     CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
+                        &                                         sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
+                        &                                         syye(:,:,jk,jl), sxye(:,:,jk,jl) )
                   END DO
                END DO
@@ -286,24 +353,23 @@
             at_i(:,:) = at_i(:,:) + a_i(:,:,jl)
          END DO
-
-         !------------------------------------------------------------------------------!
-         ! Diffusion of Ice fields                  
-         !------------------------------------------------------------------------------!
-         !------------------------------------
-         !  Diffusion of other ice variables
-         !------------------------------------
+         
+         CALL wrk_dealloc( jpi,jpj,            zarea )
+         CALL wrk_dealloc( jpi,jpj,1,          z0opw )
+         CALL wrk_dealloc( jpi,jpj,jpl,        z0ice, z0snw, z0ai, z0es , z0smi , z0oi )
+         CALL wrk_dealloc( jpi,jpj,nlay_i,jpl, z0ei )
+
+      END SELECT
+      
+      !------------------------------!
+      ! Diffusion of Ice fields                  
+      !------------------------------!
+      IF( nn_ahi0 /= -1 .AND. nn_limdyn == 2 ) THEN
+         !
+         ! --- Prepare diffusion for variables with categories --- !
+         !     mask eddy diffusivity coefficient at ocean U- and V-points
          jm=1
          DO jl = 1, jpl
-         !                             ! Masked eddy diffusivity coefficient at ocean U- and V-points
-         !   DO jj = 1, jpjm1                 ! NB: has not to be defined on jpj line and jpi row
-         !      DO ji = 1 , fs_jpim1   ! vector opt.
-         !         pahu(ji,jj) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -a_i(ji  ,jj,jl) ) ) )   &
-         !            &        * ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -a_i(ji+1,jj,jl) ) ) ) * ahiu(ji,jj)
-         !         pahv(ji,jj) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -a_i(ji,jj  ,jl) ) ) )   &
-         !            &        * ( 1._wp - MAX( 0._wp, SIGN( 1._wp,- a_i(ji,jj+1,jl) ) ) ) * ahiv(ji,jj)
-         !      END DO
-         !   END DO
             DO jj = 1, jpjm1                 ! NB: has not to be defined on jpj line and jpi row
-               DO ji = 1 , fs_jpim1   ! vector opt.
+               DO ji = 1 , fs_jpim1
                   pahu3D(ji,jj,jl) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -a_i(ji  ,jj,  jl ) ) ) )   &
                   &                * ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -a_i(ji+1,jj,  jl ) ) ) ) * ahiu(ji,jj)
@@ -313,36 +379,22 @@
             END DO
 
-            zhdfptab(:,:,jm)= a_i  (:,:,  jl); jm = jm + 1    
+            zhdfptab(:,:,jm)= a_i  (:,:,  jl); jm = jm + 1
             zhdfptab(:,:,jm)= v_i  (:,:,  jl); jm = jm + 1
-            zhdfptab(:,:,jm)= v_s  (:,:,  jl); jm = jm + 1 
+            zhdfptab(:,:,jm)= v_s  (:,:,  jl); jm = jm + 1
             zhdfptab(:,:,jm)= smv_i(:,:,  jl); jm = jm + 1
             zhdfptab(:,:,jm)= oa_i (:,:,  jl); jm = jm + 1
             zhdfptab(:,:,jm)= e_s  (:,:,1,jl); jm = jm + 1
-         ! Sample of adding more variables to apply lim_hdf using lim_hdf optimization---
-         !   zhdfptab(:,:,jm) = variable_1 (:,:,1,jl); jm = jm + 1  
-         !   zhdfptab(:,:,jm) = variable_2 (:,:,1,jl); jm = jm + 1 
-         !
-         ! and in this example the parameter ihdf_vars musb be changed to 8 (necessary for allocation)
-         !----------------------------------------------------------------------------------------
+            ! Sample of adding more variables to apply lim_hdf (ihdf_vars must be increased)
+            !   zhdfptab(:,:,jm) = variable_1 (:,:,1,jl); jm = jm + 1  
+            !   zhdfptab(:,:,jm) = variable_2 (:,:,1,jl); jm = jm + 1 
             DO jk = 1, nlay_i
               zhdfptab(:,:,jm)=e_i(:,:,jk,jl); jm= jm+1
             END DO
          END DO
-         !
-         !--------------------------------
-         !  diffusion of open water area
-         !--------------------------------
-         !                             ! Masked eddy diffusivity coefficient at ocean U- and V-points
-         !DO jj = 1, jpjm1                    ! NB: has not to be defined on jpj line and jpi row
-         !   DO ji = 1 , fs_jpim1   ! vector opt.
-         !      pahu(ji,jj) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -at_i(ji  ,jj) ) ) )   &
-         !         &        * ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -at_i(ji+1,jj) ) ) ) * ahiu(ji,jj)
-         !      pahv(ji,jj) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -at_i(ji,jj  ) ) ) )   &
-         !         &        * ( 1._wp - MAX( 0._wp, SIGN( 1._wp,- at_i(ji,jj+1) ) ) ) * ahiv(ji,jj)
-         !   END DO
-         !END DO
-         
+
+         ! --- Prepare diffusion for open water area --- !
+         !     mask eddy diffusivity coefficient at ocean U- and V-points
          DO jj = 1, jpjm1                    ! NB: has not to be defined on jpj line and jpi row
-            DO ji = 1 , fs_jpim1   ! vector opt.
+            DO ji = 1 , fs_jpim1
                pahu3D(ji,jj,jpl+1) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -at_i(ji  ,jj) ) ) )   &
                   &                * ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -at_i(ji+1,jj) ) ) ) * ahiu(ji,jj)
@@ -353,91 +405,63 @@
          !
          zhdfptab(:,:,jm)= ato_i  (:,:);
-         CALL lim_hdf( zhdfptab, ihdf_vars, jpl, nlay_i) 
-
+
+         ! --- Apply diffusion --- !
+         CALL lim_hdf( zhdfptab, ihdf_vars )
+
+         ! --- Recover properties --- !
          jm=1
          DO jl = 1, jpl
-            a_i  (:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1      
-            v_i  (:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1 
-            v_s  (:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1 
-            smv_i(:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1 
-            oa_i (:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1 
-            e_s  (:,:,1,jl) = zhdfptab(:,:,jm); jm = jm + 1 
-         ! Sample of adding more variables to apply lim_hdf---------
-         !   variable_1  (:,:,1,jl) = zhdfptab(:,:, jm  ) ; jm + 1 
-         !   variable_2  (:,:,1,jl) = zhdfptab(:,:, jm  ) ; jm + 1
-         !-----------------------------------------------------------
+            a_i  (:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1
+            v_i  (:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1
+            v_s  (:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1
+            smv_i(:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1
+            oa_i (:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1
+            e_s  (:,:,1,jl) = zhdfptab(:,:,jm); jm = jm + 1
+            ! Sample of adding more variables to apply lim_hdf
+            !   variable_1  (:,:,1,jl) = zhdfptab(:,:, jm  ) ; jm + 1 
+            !   variable_2  (:,:,1,jl) = zhdfptab(:,:, jm  ) ; jm + 1
             DO jk = 1, nlay_i
-               e_i(:,:,jk,jl) = zhdfptab(:,:,jm);jm= jm + 1 
-            END DO
-         END DO
-
+               e_i(:,:,jk,jl) = zhdfptab(:,:,jm);jm= jm + 1
+            END DO
+         END DO
          ato_i  (:,:) = zhdfptab(:,:,jm)
-
-         !------------------------------------------------------------------------------!
-         ! limit ice properties after transport                           
-         !------------------------------------------------------------------------------!
-!!gm & cr   :  MAX should not be active if adv scheme is positive !
+              
+      ENDIF
+
+      ! --- diags ---
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            diag_trp_ei (ji,jj) = ( SUM( e_i  (ji,jj,1:nlay_i,:) ) -  zeiold(ji,jj) ) * r1_rdtice
+            diag_trp_es (ji,jj) = ( SUM( e_s  (ji,jj,1:nlay_s,:) ) -  zesold(ji,jj) ) * r1_rdtice
+            diag_trp_smv(ji,jj) = ( SUM( smv_i(ji,jj,:)          ) - zsmvold(ji,jj) ) * r1_rdtice
+            diag_trp_vi (ji,jj) =   SUM(   v_i(ji,jj,:)            -  zviold(ji,jj,:) ) * r1_rdtice
+            diag_trp_vs (ji,jj) =   SUM(   v_s(ji,jj,:)            -  zvsold(ji,jj,:) ) * r1_rdtice
+         END DO
+      END DO
+      
+      IF( nn_limdyn == 2) THEN
+
+         ! zap small areas
+         CALL lim_var_zapsmall
+           
+         !--- Thickness correction in case too high --- !
          DO jl = 1, jpl
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  v_s  (ji,jj,jl)   = MAX( 0._wp, v_s  (ji,jj,jl) )
-                  v_i  (ji,jj,jl)   = MAX( 0._wp, v_i  (ji,jj,jl) )
-                  smv_i(ji,jj,jl)   = MAX( 0._wp, smv_i(ji,jj,jl) )
-                  oa_i (ji,jj,jl)   = MAX( 0._wp, oa_i (ji,jj,jl) )
-                  a_i  (ji,jj,jl)   = MAX( 0._wp, a_i  (ji,jj,jl) )
-                  e_s  (ji,jj,1,jl) = MAX( 0._wp, e_s  (ji,jj,1,jl) )
-               END DO
-            END DO
-
-            DO jk = 1, nlay_i
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     e_i(ji,jj,jk,jl) = MAX( 0._wp, e_i(ji,jj,jk,jl) )
-                  END DO
-               END DO
-            END DO
-         END DO
-!!gm & cr 
-
-         ! --- diags ---
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               diag_trp_ei(ji,jj) = ( SUM( e_i(ji,jj,1:nlay_i,:) ) - zeiold(ji,jj) ) * r1_rdtice
-               diag_trp_es(ji,jj) = ( SUM( e_s(ji,jj,1:nlay_s,:) ) - zesold(ji,jj) ) * r1_rdtice
-
-               diag_trp_vi (ji,jj) = SUM(   v_i(ji,jj,:) -  zviold(ji,jj,:) ) * r1_rdtice
-               diag_trp_vs (ji,jj) = SUM(   v_s(ji,jj,:) -  zvsold(ji,jj,:) ) * r1_rdtice
-               diag_trp_smv(ji,jj) = SUM( smv_i(ji,jj,:) - zsmvold(ji,jj,:) ) * r1_rdtice
-            END DO
-         END DO
-
-         ! zap small areas
-         CALL lim_var_zapsmall
-
-         !--- Thickness correction in case too high --------------------------------------------------------
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-
+                  
                   IF ( v_i(ji,jj,jl) > 0._wp ) THEN
-
+                     
                      rswitch          = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )
                      ht_i  (ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
                      ht_s  (ji,jj,jl) = v_s (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
                      
-                     zvi  = v_i  (ji,jj,jl)
-                     zvs  = v_s  (ji,jj,jl)
-                     zsmv = smv_i(ji,jj,jl)
-                     zes  = e_s  (ji,jj,1,jl)
-                     zei  = SUM( e_i(ji,jj,1:nlay_i,jl) )
-
                      zdv  = v_i(ji,jj,jl) + v_s(ji,jj,jl) - zviold(ji,jj,jl) - zvsold(ji,jj,jl)  
-
+                     
                      IF ( ( zdv >  0.0 .AND. (ht_i(ji,jj,jl)+ht_s(ji,jj,jl)) > zhimax(ji,jj,jl) .AND. zatold(ji,jj) < 0.80 ) .OR. &
                         & ( zdv <= 0.0 .AND. (ht_i(ji,jj,jl)+ht_s(ji,jj,jl)) > zhimax(ji,jj,jl) ) ) THEN
-
+                        
                         rswitch        = MAX( 0._wp, SIGN( 1._wp, zhimax(ji,jj,jl) - epsi20 ) )
                         a_i(ji,jj,jl)  = rswitch * ( v_i(ji,jj,jl) + v_s(ji,jj,jl) ) / MAX( zhimax(ji,jj,jl), epsi20 )
-
+                        
                         ! small correction due to *rswitch for a_i
                         v_i  (ji,jj,jl)        = rswitch * v_i  (ji,jj,jl)
@@ -446,16 +470,9 @@
                         e_s(ji,jj,1,jl)        = rswitch * e_s(ji,jj,1,jl)
                         e_i(ji,jj,1:nlay_i,jl) = rswitch * e_i(ji,jj,1:nlay_i,jl)
-
-                        ! Update mass fluxes
-                        wfx_res(ji,jj) = wfx_res(ji,jj) - ( v_i(ji,jj,jl) - zvi ) * rhoic * r1_rdtice
-                        wfx_snw(ji,jj) = wfx_snw(ji,jj) - ( v_s(ji,jj,jl) - zvs ) * rhosn * r1_rdtice
-                        sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsmv ) * rhoic * r1_rdtice 
-                        hfx_res(ji,jj) = hfx_res(ji,jj) + ( e_s(ji,jj,1,jl) - zes ) * r1_rdtice ! W.m-2 <0
-                        hfx_res(ji,jj) = hfx_res(ji,jj) + ( SUM( e_i(ji,jj,1:nlay_i,jl) ) - zei ) * r1_rdtice ! W.m-2 <0
-
+                                                
                      ENDIF
-
+                     
                   ENDIF
-
+                
                END DO
             END DO
@@ -463,57 +480,55 @@
          ! -------------------------------------------------
          
-         !--------------------------------------
-         ! Impose a_i < amax in mono-category
-         !--------------------------------------
-         !
-         IF ( ( nn_monocat == 2 ) .AND. ( jpl == 1 ) ) THEN ! simple conservative piling, comparable with LIM2
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  a_i(ji,jj,1)  = MIN( a_i(ji,jj,1), rn_amax_2d(ji,jj) )
-               END DO
-            END DO
-         ENDIF
-
-         ! --- agglomerate variables -----------------
-         vt_i (:,:) = 0._wp
-         vt_s (:,:) = 0._wp
-         at_i (:,:) = 0._wp
+         ! Force the upper limit of ht_i to always be < hi_max (99 m).
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               rswitch         = MAX( 0._wp , SIGN( 1._wp, ht_i(ji,jj,jpl) - epsi20 ) )
+               ht_i(ji,jj,jpl) = MIN( ht_i(ji,jj,jpl) , hi_max(jpl) )
+               a_i (ji,jj,jpl) = v_i(ji,jj,jpl) / MAX( ht_i(ji,jj,jpl) , epsi20 ) * rswitch
+            END DO
+         END DO
+
+      ENDIF
+         
+      !------------------------------------------------------------
+      ! Impose a_i < amax if no ridging/rafting or in mono-category
+      !------------------------------------------------------------
+      !
+      at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
+      IF ( nn_limdyn == 1 .OR. ( ( nn_monocat == 2 ) .AND. ( jpl == 1 ) ) ) THEN ! simple conservative piling, comparable with LIM2
          DO jl = 1, jpl
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  vt_i(ji,jj) = vt_i(ji,jj) + v_i(ji,jj,jl)
-                  vt_s(ji,jj) = vt_s(ji,jj) + v_s(ji,jj,jl)
-                  at_i(ji,jj) = at_i(ji,jj) + a_i(ji,jj,jl)
+                  rswitch       = MAX( 0._wp, SIGN( 1._wp, at_i(ji,jj) - epsi20 ) )
+                  zda           = rswitch * MIN( rn_amax_2d(ji,jj) - at_i(ji,jj), 0._wp )  &
+                     &                    * a_i(ji,jj,jl) / MAX( at_i(ji,jj), epsi20 )
+                  a_i(ji,jj,jl) = a_i(ji,jj,jl) + zda
                END DO
             END DO
          END DO
-
-         ! --- open water = 1 if at_i=0 --------------------------------
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch      = MAX( 0._wp , SIGN( 1._wp, - at_i(ji,jj) ) )
-               ato_i(ji,jj) = rswitch + (1._wp - rswitch ) * ato_i(ji,jj)
-            END DO
-         END DO      
-
-         ! conservation test
-         IF( ln_limdiahsb ) CALL lim_cons_hsm(1, 'limtrp', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
       ENDIF
-
+      
+      ! --- agglomerate variables -----------------
+      vt_i(:,:) = SUM( v_i(:,:,:), dim=3 )
+      vt_s(:,:) = SUM( v_s(:,:,:), dim=3 )
+      at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
+      
+      ! --- open water = 1 if at_i=0 --------------------------------
+      WHERE( at_i == 0._wp ) ato_i = 1._wp 
+      
+      ! conservation test
+      IF( ln_limdiachk )   CALL lim_cons_hsm(1, 'limtrp', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+        
       ! -------------------------------------------------
       ! control prints
       ! -------------------------------------------------
-      IF( ln_icectl )   CALL lim_prt( kt, iiceprt, jiceprt,-1, ' - ice dyn & trp - ' )
+      IF( ln_limctl )   CALL lim_prt( kt, iiceprt, jiceprt,-1, ' - ice dyn & trp - ' )
       !
-      CALL wrk_dealloc( jpi,jpj,            zsm, zatold, zeiold, zesold )
-      CALL wrk_dealloc( jpi,jpj,jpl,        z0ice, z0snw, z0ai, z0es , z0smi , z0oi )
-      CALL wrk_dealloc( jpi,jpj,1,          z0opw )
-      CALL wrk_dealloc( jpi,jpj,nlay_i,jpl, z0ei )
-      CALL wrk_dealloc( jpi,jpj,jpl,        zviold, zvsold, zhimax, zsmvold )
-      CALL wrk_dealloc( jpi,jpj,jpl*(ihdf_vars+nlay_i)+1,zhdfptab)
+      CALL wrk_dealloc( jpi,jpj,                            zatold, zeiold, zesold, zsmvold )
+      CALL wrk_dealloc( jpi,jpj,jpl,                        zhimax, zviold, zvsold )
+      CALL wrk_dealloc( jpi,jpj,jpl*(ihdf_vars + nlay_i)+1, zhdfptab)
       !
       IF( nn_timing == 1 )  CALL timing_stop('limtrp')
-
+      !
    END SUBROUTINE lim_trp
 
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limupdate1.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limupdate1.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limupdate1.F90	(revision 7309)
@@ -15,5 +15,4 @@
    USE sbc_oce         ! Surface boundary condition: ocean fields
    USE sbc_ice         ! Surface boundary condition: ice fields
-   USE dom_ice
    USE dom_oce
    USE phycst          ! physical constants
@@ -22,8 +21,8 @@
    USE limitd_th
    USE limvar
-   USE prtctl          ! Print control
    USE wrk_nemo        ! work arrays
    USE timing          ! Timing
    USE limcons         ! conservation tests
+   USE limctl          ! control prints
    USE lib_mpp         ! MPP library
    USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
@@ -59,13 +58,12 @@
       IF( nn_timing == 1 )  CALL timing_start('limupdate1')
 
-      IF( ln_limdyn ) THEN 
-
       IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*) ' lim_update1 ' 
-         WRITE(numout,*) ' ~~~~~~~~~~~ '
+         WRITE(numout,*)'' 
+         WRITE(numout,*)' lim_update1 ' 
+         WRITE(numout,*)' ~~~~~~~~~~~ '
       ENDIF
 
       ! conservation test
-      IF( ln_limdiahsb ) CALL lim_cons_hsm(0, 'limupdate1', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limupdate1', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
 
       !----------------------------------------------------
@@ -137,71 +135,13 @@
 
       ! conservation test
-      IF( ln_limdiahsb ) CALL lim_cons_hsm(1, 'limupdate1', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limupdate1', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
 
-      ! -------------------------------------------------
       ! control prints
-      ! -------------------------------------------------
-      IF(ln_ctl) THEN   ! Control print
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Cell values : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=e1e2t      , clinfo1=' lim_update1  : cell area   :')
-         CALL prt_ctl(tab2d_1=at_i       , clinfo1=' lim_update1  : at_i        :')
-         CALL prt_ctl(tab2d_1=vt_i       , clinfo1=' lim_update1  : vt_i        :')
-         CALL prt_ctl(tab2d_1=vt_s       , clinfo1=' lim_update1  : vt_s        :')
-         CALL prt_ctl(tab2d_1=strength   , clinfo1=' lim_update1  : strength    :')
-         CALL prt_ctl(tab2d_1=u_ice      , clinfo1=' lim_update1  : u_ice       :', tab2d_2=v_ice      , clinfo2=' v_ice       :')
-         CALL prt_ctl(tab2d_1=u_ice_b    , clinfo1=' lim_update1  : u_ice_b     :', tab2d_2=v_ice_b    , clinfo2=' v_ice_b     :')
+      IF( ln_ctl )       CALL lim_prt3D( 'limupdate1' )
+   
+      IF( nn_timing == 1 )  CALL timing_stop('limupdate1')
 
-         DO jl = 1, jpl
-            CALL prt_ctl_info(' ')
-            CALL prt_ctl_info(' - Category : ', ivar1=jl)
-            CALL prt_ctl_info('   ~~~~~~~~~~')
-            CALL prt_ctl(tab2d_1=ht_i       (:,:,jl)        , clinfo1= ' lim_update1  : ht_i        : ')
-            CALL prt_ctl(tab2d_1=ht_s       (:,:,jl)        , clinfo1= ' lim_update1  : ht_s        : ')
-            CALL prt_ctl(tab2d_1=t_su       (:,:,jl)        , clinfo1= ' lim_update1  : t_su        : ')
-            CALL prt_ctl(tab2d_1=t_s        (:,:,1,jl)      , clinfo1= ' lim_update1  : t_snow      : ')
-            CALL prt_ctl(tab2d_1=sm_i       (:,:,jl)        , clinfo1= ' lim_update1  : sm_i        : ')
-            CALL prt_ctl(tab2d_1=o_i        (:,:,jl)        , clinfo1= ' lim_update1  : o_i         : ')
-            CALL prt_ctl(tab2d_1=a_i        (:,:,jl)        , clinfo1= ' lim_update1  : a_i         : ')
-            CALL prt_ctl(tab2d_1=a_i_b      (:,:,jl)        , clinfo1= ' lim_update1  : a_i_b       : ')
-            CALL prt_ctl(tab2d_1=v_i        (:,:,jl)        , clinfo1= ' lim_update1  : v_i         : ')
-            CALL prt_ctl(tab2d_1=v_i_b      (:,:,jl)        , clinfo1= ' lim_update1  : v_i_b       : ')
-            CALL prt_ctl(tab2d_1=v_s        (:,:,jl)        , clinfo1= ' lim_update1  : v_s         : ')
-            CALL prt_ctl(tab2d_1=v_s_b      (:,:,jl)        , clinfo1= ' lim_update1  : v_s_b       : ')
-            CALL prt_ctl(tab2d_1=e_i        (:,:,1,jl)      , clinfo1= ' lim_update1  : e_i1        : ')
-            CALL prt_ctl(tab2d_1=e_i_b      (:,:,1,jl)      , clinfo1= ' lim_update1  : e_i1_b      : ')
-            CALL prt_ctl(tab2d_1=e_i        (:,:,2,jl)      , clinfo1= ' lim_update1  : e_i2        : ')
-            CALL prt_ctl(tab2d_1=e_i_b      (:,:,2,jl)      , clinfo1= ' lim_update1  : e_i2_b      : ')
-            CALL prt_ctl(tab2d_1=e_s        (:,:,1,jl)      , clinfo1= ' lim_update1  : e_snow      : ')
-            CALL prt_ctl(tab2d_1=e_s_b      (:,:,1,jl)      , clinfo1= ' lim_update1  : e_snow_b    : ')
-            CALL prt_ctl(tab2d_1=smv_i      (:,:,jl)        , clinfo1= ' lim_update1  : smv_i       : ')
-            CALL prt_ctl(tab2d_1=smv_i_b    (:,:,jl)        , clinfo1= ' lim_update1  : smv_i_b     : ')
-            CALL prt_ctl(tab2d_1=oa_i       (:,:,jl)        , clinfo1= ' lim_update1  : oa_i        : ')
-            CALL prt_ctl(tab2d_1=oa_i_b     (:,:,jl)        , clinfo1= ' lim_update1  : oa_i_b      : ')
+   END SUBROUTINE lim_update1
 
-            DO jk = 1, nlay_i
-               CALL prt_ctl_info(' - Layer : ', ivar1=jk)
-               CALL prt_ctl(tab2d_1=t_i(:,:,jk,jl) , clinfo1= ' lim_update1  : t_i       : ')
-            END DO
-         END DO
-
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Heat / FW fluxes : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=sst_m  , clinfo1= ' lim_update1 : sst   : ', tab2d_2=sss_m     , clinfo2= ' sss       : ')
-
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Stresses : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=utau       , clinfo1= ' lim_update1 : utau      : ', tab2d_2=vtau       , clinfo2= ' vtau      : ')
-         CALL prt_ctl(tab2d_1=utau_ice   , clinfo1= ' lim_update1 : utau_ice  : ', tab2d_2=vtau_ice   , clinfo2= ' vtau_ice  : ')
-         CALL prt_ctl(tab2d_1=u_oce      , clinfo1= ' lim_update1 : u_oce     : ', tab2d_2=v_oce      , clinfo2= ' v_oce     : ')
-      ENDIF
-   
-      ENDIF ! ln_limdyn
-
-      IF( nn_timing == 1 )  CALL timing_stop('limupdate1')
-   END SUBROUTINE lim_update1
 #else
    !!----------------------------------------------------------------------
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limupdate2.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limupdate2.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limupdate2.F90	(revision 7309)
@@ -15,5 +15,4 @@
    USE sbc_oce         ! Surface boundary condition: ocean fields
    USE sbc_ice         ! Surface boundary condition: ice fields
-   USE dom_ice
    USE dom_oce
    USE phycst          ! physical constants
@@ -22,5 +21,4 @@
    USE limitd_th
    USE limvar
-   USE prtctl          ! Print control
    USE lbclnk          ! lateral boundary condition - MPP exchanges
    USE wrk_nemo        ! work arrays
@@ -62,10 +60,11 @@
 
       IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*) ' lim_update2 '
-         WRITE(numout,*) ' ~~~~~~~~~~~ '
+         WRITE(numout,*)''
+         WRITE(numout,*)' lim_update2 '
+         WRITE(numout,*)' ~~~~~~~~~~~ '
       ENDIF
 
       ! conservation test
-      IF( ln_limdiahsb ) CALL lim_cons_hsm(0, 'limupdate2', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limupdate2', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
 
       !----------------------------------------------------------------------
@@ -176,76 +175,14 @@
 
       ! conservation test
-      IF( ln_limdiahsb ) CALL lim_cons_hsm(1, 'limupdate2', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limupdate2', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
 
-      ! necessary calls (at least for coupling)
-      CALL lim_var_glo2eqv
-      CALL lim_var_agg(2)
-
-      ! -------------------------------------------------
       ! control prints
-      ! -------------------------------------------------
-      IF( ln_icectl )   CALL lim_prt( kt, iiceprt, jiceprt, 2, ' - Final state - ' )   ! control print
-
-      IF(ln_ctl) THEN   ! Control print
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Cell values : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=e1e2t      , clinfo1=' lim_update2  : cell area   :')
-         CALL prt_ctl(tab2d_1=at_i       , clinfo1=' lim_update2  : at_i        :')
-         CALL prt_ctl(tab2d_1=vt_i       , clinfo1=' lim_update2  : vt_i        :')
-         CALL prt_ctl(tab2d_1=vt_s       , clinfo1=' lim_update2  : vt_s        :')
-         CALL prt_ctl(tab2d_1=strength   , clinfo1=' lim_update2  : strength    :')
-         CALL prt_ctl(tab2d_1=u_ice      , clinfo1=' lim_update2  : u_ice       :', tab2d_2=v_ice      , clinfo2=' v_ice       :')
-         CALL prt_ctl(tab2d_1=u_ice_b    , clinfo1=' lim_update2  : u_ice_b     :', tab2d_2=v_ice_b    , clinfo2=' v_ice_b     :')
-
-         DO jl = 1, jpl
-            CALL prt_ctl_info(' ')
-            CALL prt_ctl_info(' - Category : ', ivar1=jl)
-            CALL prt_ctl_info('   ~~~~~~~~~~')
-            CALL prt_ctl(tab2d_1=ht_i       (:,:,jl)        , clinfo1= ' lim_update2  : ht_i        : ')
-            CALL prt_ctl(tab2d_1=ht_s       (:,:,jl)        , clinfo1= ' lim_update2  : ht_s        : ')
-            CALL prt_ctl(tab2d_1=t_su       (:,:,jl)        , clinfo1= ' lim_update2  : t_su        : ')
-            CALL prt_ctl(tab2d_1=t_s        (:,:,1,jl)      , clinfo1= ' lim_update2  : t_snow      : ')
-            CALL prt_ctl(tab2d_1=sm_i       (:,:,jl)        , clinfo1= ' lim_update2  : sm_i        : ')
-            CALL prt_ctl(tab2d_1=o_i        (:,:,jl)        , clinfo1= ' lim_update2  : o_i         : ')
-            CALL prt_ctl(tab2d_1=a_i        (:,:,jl)        , clinfo1= ' lim_update2  : a_i         : ')
-            CALL prt_ctl(tab2d_1=a_i_b      (:,:,jl)        , clinfo1= ' lim_update2  : a_i_b       : ')
-            CALL prt_ctl(tab2d_1=v_i        (:,:,jl)        , clinfo1= ' lim_update2  : v_i         : ')
-            CALL prt_ctl(tab2d_1=v_i_b      (:,:,jl)        , clinfo1= ' lim_update2  : v_i_b       : ')
-            CALL prt_ctl(tab2d_1=v_s        (:,:,jl)        , clinfo1= ' lim_update2  : v_s         : ')
-            CALL prt_ctl(tab2d_1=v_s_b      (:,:,jl)        , clinfo1= ' lim_update2  : v_s_b       : ')
-            CALL prt_ctl(tab2d_1=e_i        (:,:,1,jl)      , clinfo1= ' lim_update2  : e_i1        : ')
-            CALL prt_ctl(tab2d_1=e_i_b      (:,:,1,jl)      , clinfo1= ' lim_update2  : e_i1_b      : ')
-            CALL prt_ctl(tab2d_1=e_i        (:,:,2,jl)      , clinfo1= ' lim_update2  : e_i2        : ')
-            CALL prt_ctl(tab2d_1=e_i_b      (:,:,2,jl)      , clinfo1= ' lim_update2  : e_i2_b      : ')
-            CALL prt_ctl(tab2d_1=e_s        (:,:,1,jl)      , clinfo1= ' lim_update2  : e_snow      : ')
-            CALL prt_ctl(tab2d_1=e_s_b      (:,:,1,jl)      , clinfo1= ' lim_update2  : e_snow_b    : ')
-            CALL prt_ctl(tab2d_1=smv_i      (:,:,jl)        , clinfo1= ' lim_update2  : smv_i       : ')
-            CALL prt_ctl(tab2d_1=smv_i_b    (:,:,jl)        , clinfo1= ' lim_update2  : smv_i_b     : ')
-            CALL prt_ctl(tab2d_1=oa_i       (:,:,jl)        , clinfo1= ' lim_update2  : oa_i        : ')
-            CALL prt_ctl(tab2d_1=oa_i_b     (:,:,jl)        , clinfo1= ' lim_update2  : oa_i_b      : ')
-
-            DO jk = 1, nlay_i
-               CALL prt_ctl_info(' - Layer : ', ivar1=jk)
-               CALL prt_ctl(tab2d_1=t_i(:,:,jk,jl) , clinfo1= ' lim_update2  : t_i       : ')
-            END DO
-         END DO
-
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Heat / FW fluxes : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=sst_m  , clinfo1= ' lim_update2 : sst   : ', tab2d_2=sss_m     , clinfo2= ' sss       : ')
-
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Stresses : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=utau       , clinfo1= ' lim_update2 : utau      : ', tab2d_2=vtau       , clinfo2= ' vtau      : ')
-         CALL prt_ctl(tab2d_1=utau_ice   , clinfo1= ' lim_update2 : utau_ice  : ', tab2d_2=vtau_ice   , clinfo2= ' vtau_ice  : ')
-         CALL prt_ctl(tab2d_1=u_oce      , clinfo1= ' lim_update2 : u_oce     : ', tab2d_2=v_oce      , clinfo2= ' v_oce     : ')
-      ENDIF
+      IF( ln_limctl )    CALL lim_prt( kt, iiceprt, jiceprt, 2, ' - Final state - ' )
+      IF( ln_ctl )       CALL lim_prt3D( 'limupdate2' )
    
       IF( nn_timing == 1 )  CALL timing_stop('limupdate2')
 
    END SUBROUTINE lim_update2
+
 #else
    !!----------------------------------------------------------------------
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90	(revision 7309)
@@ -27,5 +27,5 @@
    !!                        - et_i(jpi,jpj)  !total ice thermal content 
    !!                        - smt_i(jpi,jpj) !mean ice salinity
-   !!                        - ot_i(jpi,jpj)  !average ice age
+   !!                        - tm_i (jpi,jpj) !mean ice temperature
    !!======================================================================
    !! History :   -   ! 2006-01 (M. Vancoppenolle) Original code
@@ -41,5 +41,4 @@
    USE ice            ! ice variables
    USE thd_ice        ! ice variables (thermodynamics)
-   USE dom_ice        ! ice domain
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
@@ -54,5 +53,4 @@
    PUBLIC   lim_var_eqv2glo      
    PUBLIC   lim_var_salprof      
-   PUBLIC   lim_var_icetm        
    PUBLIC   lim_var_bv           
    PUBLIC   lim_var_salprof1d    
@@ -86,55 +84,58 @@
       !!------------------------------------------------------------------
 
-      !--------------------
-      ! Compute variables
-      !--------------------
-      vt_i (:,:) = 0._wp
-      vt_s (:,:) = 0._wp
-      at_i (:,:) = 0._wp
-      ato_i(:,:) = 1._wp
-      !
-      DO jl = 1, jpl
+      ! 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 )
+
+      ! open water fraction
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ato_i(ji,jj) = MAX( 1._wp - at_i(ji,jj), 0._wp )   
+         END DO
+      END DO
+
+      IF( kn > 1 ) THEN
+
+         ! mean ice/snow thickness
          DO jj = 1, jpj
             DO ji = 1, jpi
-               !
-               vt_i(ji,jj) = vt_i(ji,jj) + v_i(ji,jj,jl) ! ice volume
-               vt_s(ji,jj) = vt_s(ji,jj) + v_s(ji,jj,jl) ! snow volume
-               at_i(ji,jj) = at_i(ji,jj) + a_i(ji,jj,jl) ! ice concentration
-               !
-               rswitch = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) ) 
-               icethi(ji,jj) = vt_i(ji,jj) / MAX( at_i(ji,jj) , epsi10 ) * rswitch  ! ice thickness
-            END DO
-         END DO
-      END DO
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            ato_i(ji,jj) = MAX( 1._wp - at_i(ji,jj), 0._wp )   ! open water fraction
-         END DO
-      END DO
-
-      IF( kn > 1 ) THEN
-         et_s (:,:) = 0._wp
-         ot_i (:,:) = 0._wp
+               rswitch      = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) ) 
+               htm_i(ji,jj) = vt_i(ji,jj) / MAX( at_i(ji,jj) , epsi10 ) * rswitch
+               htm_s(ji,jj) = vt_s(ji,jj) / MAX( at_i(ji,jj) , epsi10 ) * rswitch
+            ENDDO
+         ENDDO
+
+         ! mean temperature (K), salinity and age
          smt_i(:,:) = 0._wp
-         et_i (:,:) = 0._wp
-         !
+         tm_i(:,:)  = 0._wp
+         tm_su(:,:) = 0._wp
+         om_i (:,:) = 0._wp
          DO jl = 1, jpl
+            
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  et_s(ji,jj)  = et_s(ji,jj)  + e_s(ji,jj,1,jl)                                           ! snow heat content
-                  rswitch = MAX( 0._wp , SIGN( 1._wp , vt_i(ji,jj) - epsi20 ) ) 
-                  smt_i(ji,jj) = smt_i(ji,jj) + smv_i(ji,jj,jl) / MAX( vt_i(ji,jj) , epsi20 ) * rswitch   ! ice salinity
-                  rswitch = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi20 ) ) 
-                  ot_i(ji,jj)  = ot_i(ji,jj)  + oa_i(ji,jj,jl)  / MAX( at_i(ji,jj) , epsi20 ) * rswitch   ! ice age
-               END DO
-            END DO
-         END DO
-         !
-         DO jl = 1, jpl
+                  rswitch      = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) )
+                  tm_su(ji,jj) = tm_su(ji,jj) + rswitch * ( t_su(ji,jj,jl) - rt0 ) * a_i(ji,jj,jl) / MAX( at_i(ji,jj) , epsi10 )
+                  om_i (ji,jj) = om_i (ji,jj) + rswitch *   oa_i(ji,jj,jl)                         / MAX( at_i(ji,jj) , epsi10 )
+               END DO
+            END DO
+            
             DO jk = 1, nlay_i
-               et_i(:,:) = et_i(:,:) + e_i(:,:,jk,jl)       ! ice heat content
-            END DO
-         END DO
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     rswitch = MAX( 0._wp , SIGN( 1._wp , vt_i(ji,jj) - epsi10 ) )
+                     tm_i(ji,jj)  = tm_i(ji,jj)  + r1_nlay_i * rswitch * ( t_i(ji,jj,jk,jl) - rt0 ) * v_i(ji,jj,jl)  &
+                        &            / MAX( vt_i(ji,jj) , epsi10 )
+                     smt_i(ji,jj) = smt_i(ji,jj) + r1_nlay_i * rswitch * s_i(ji,jj,jk,jl) * v_i(ji,jj,jl)  &
+                        &            / MAX( vt_i(ji,jj) , epsi10 )
+                  END DO
+               END DO
+            END DO
+         END DO
+         tm_i  = tm_i  + rt0
+         tm_su = tm_su + rt0
          !
       ENDIF
@@ -243,25 +244,9 @@
       END DO
 
-      !-------------------
-      ! Mean temperature
-      !-------------------
-      vt_i (:,:) = 0._wp
-      DO jl = 1, jpl
-         vt_i(:,:) = vt_i(:,:) + v_i(:,:,jl)
-      END DO
-
-      tm_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch = MAX( 0._wp , SIGN( 1._wp , vt_i(ji,jj) - epsi10 ) )
-                  tm_i(ji,jj) = tm_i(ji,jj) + r1_nlay_i * rswitch * ( t_i(ji,jj,jk,jl) - rt0 ) * v_i(ji,jj,jl)  &
-                     &            / MAX( vt_i(ji,jj) , epsi10 )
-               END DO
-            END DO
-         END DO
-      END DO
-      tm_i = tm_i + rt0
+      ! integrated values
+      vt_i (:,:) = SUM( v_i, dim=3 )
+      vt_s (:,:) = SUM( v_s, dim=3 )
+      at_i (:,:) = SUM( a_i, dim=3 )
+
       !
    END SUBROUTINE lim_var_glo2eqv
@@ -398,66 +383,34 @@
 
 
-   SUBROUTINE lim_var_icetm
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_var_icetm ***
-      !!
-      !! ** Purpose :   computes mean sea ice temperature
+   SUBROUTINE lim_var_bv
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE lim_var_bv ***
+      !!
+      !! ** Purpose :   computes mean brine volume (%) in sea ice
+      !!
+      !! ** Method  : e = - 0.054 * S (ppt) / T (C)
+      !!
+      !! References : Vancoppenolle et al., JGR, 2007
       !!------------------------------------------------------------------
       INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
       !!------------------------------------------------------------------
-
-      ! Mean sea ice temperature
-      vt_i (:,:) = 0._wp
-      DO jl = 1, jpl
-         vt_i(:,:) = vt_i(:,:) + v_i(:,:,jl)
-      END DO
-
-      tm_i(:,:) = 0._wp
+      !
+      bvm_i(:,:)   = 0._wp
+      bv_i (:,:,:) = 0._wp
       DO jl = 1, jpl
          DO jk = 1, nlay_i
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  rswitch = MAX( 0._wp , SIGN( 1._wp , vt_i(ji,jj) - epsi10 ) )
-                  tm_i(ji,jj) = tm_i(ji,jj) + r1_nlay_i * rswitch * ( t_i(ji,jj,jk,jl) - rt0 ) * v_i(ji,jj,jl)  &
-                     &            / MAX( vt_i(ji,jj) , epsi10 )
-               END DO
-            END DO
-         END DO
-      END DO
-      tm_i = tm_i + rt0
-
-   END SUBROUTINE lim_var_icetm
-
-
-   SUBROUTINE lim_var_bv
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_var_bv ***
-      !!
-      !! ** Purpose :   computes mean brine volume (%) in sea ice
-      !!
-      !! ** Method  : e = - 0.054 * S (ppt) / T (C)
-      !!
-      !! References : Vancoppenolle et al., JGR, 2007
-      !!------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) ::   zbvi             ! local scalars
-      !!------------------------------------------------------------------
-      !
-      vt_i (:,:) = 0._wp
-      DO jl = 1, jpl
-         vt_i(:,:) = vt_i(:,:) + v_i(:,:,jl)
-      END DO
-
-      bv_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch = (  1._wp - MAX( 0._wp , SIGN( 1._wp , (t_i(ji,jj,jk,jl) - rt0) + epsi10 ) )  )
-                  zbvi  = - rswitch * tmut * s_i(ji,jj,jk,jl) / MIN( t_i(ji,jj,jk,jl) - rt0, - epsi10 )   &
-                     &                   * v_i(ji,jj,jl) * r1_nlay_i
-                  rswitch = (  1._wp - MAX( 0._wp , SIGN( 1._wp , - vt_i(ji,jj) + epsi20 ) )  )
-                  bv_i(ji,jj) = bv_i(ji,jj) + rswitch * zbvi  / MAX( vt_i(ji,jj) , epsi20 )
-               END DO
+                  rswitch        = ( 1._wp - MAX( 0._wp , SIGN( 1._wp , (t_i(ji,jj,jk,jl) - rt0) + epsi10 ) )  )
+                  bv_i(ji,jj,jl) = bv_i(ji,jj,jl) - rswitch * tmut * s_i(ji,jj,jk,jl) * r1_nlay_i  &
+                     &                            / MIN( t_i(ji,jj,jk,jl) - rt0, - epsi10 )
+               END DO
+            END DO
+         END DO
+         
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               rswitch      = MAX( 0._wp , SIGN( 1._wp , vt_i(ji,jj) - epsi10 ) )
+               bvm_i(ji,jj) = bvm_i(ji,jj) + rswitch * bv_i(ji,jj,jl) * v_i(ji,jj,jl) / MAX( vt_i(ji,jj), epsi10 )
             END DO
          END DO
@@ -683,5 +636,5 @@
       INTEGER  :: ji, jk, jl             ! dummy loop indices
       INTEGER  :: ijpij, i_fill, jl0  
-      REAL(wp) :: zarg, zV, zconv, zdh
+      REAL(wp) :: zarg, zV, zconv, zdh, zdv
       REAL(wp), DIMENSION(:),   INTENT(in)    ::   zhti, zhts, zai    ! input ice/snow variables
       REAL(wp), DIMENSION(:,:), INTENT(inout) ::   zht_i, zht_s, za_i ! output ice/snow variables
@@ -704,80 +657,95 @@
          IF( zhti(ji) > 0._wp ) THEN
 
-         ! initialisation of tests
-         itest(:)  = 0
+            ! 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
+                  jl0 = jl
+                  CYCLE
+               ENDIF
+            END DO
+
+            ! initialisation of tests
+            itest(:)  = 0
          
-         i_fill = jpl + 1                                             !====================================
-         DO WHILE ( ( SUM( itest(:) ) /= 4 ) .AND. ( i_fill >= 2 ) )  ! iterative loop on i_fill categories  
-            ! iteration                                               !====================================
-            i_fill = i_fill - 1
+            i_fill = jpl + 1                                             !====================================
+            DO WHILE ( ( SUM( itest(:) ) /= 4 ) .AND. ( i_fill >= 2 ) )  ! iterative loop on i_fill categories
+               ! iteration                                               !====================================
+               i_fill = i_fill - 1
+               
+               ! initialisation of ice variables for each try
+               zht_i(ji,1:jpl) = 0._wp
+               za_i (ji,1:jpl) = 0._wp
+               itest(:)        = 0           
+               
+               ! *** case very thin ice: fill only category 1
+               IF ( i_fill == 1 ) THEN
+                  zht_i(ji,1) = zhti(ji)
+                  za_i (ji,1) = zai (ji)
+                  
+               ! *** case ice is thicker: fill categories >1
+               ELSE
+
+                  ! Fill ice thicknesses in the (i_fill-1) cat by hmean 
+                  DO jl = 1, i_fill - 1
+                     zht_i(ji,jl) = hi_mean(jl)
+                  END DO
+                  
+                  ! Concentrations in the (i_fill-1) categories 
+                  za_i(ji,jl0) = zai(ji) / SQRT(REAL(jpl))
+                  DO jl = 1, i_fill - 1
+                     IF ( jl /= jl0 ) THEN
+                        zarg        = ( zht_i(ji,jl) - zhti(ji) ) / ( zhti(ji) * 0.5_wp )
+                        za_i(ji,jl) =   za_i (ji,jl0) * EXP(-zarg**2)
+                     ENDIF
+                  END DO
+                  
+                  ! Concentration in the last (i_fill) category
+                  za_i(ji,i_fill) = zai(ji) - SUM( za_i(ji,1:i_fill-1) )
+                  
+                  ! Ice thickness in the last (i_fill) category
+                  zV = SUM( za_i(ji,1:i_fill-1) * zht_i(ji,1:i_fill-1) )
+                  zht_i(ji,i_fill) = ( zhti(ji) * zai(ji) - zV ) / MAX( za_i(ji,i_fill), epsi10 ) 
+                  
+                  ! clem: 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(ji,jl) > za_i(ji,jl-1) ) THEN
+                           zdv = zht_i(ji,jl) * za_i(ji,jl)
+                           zht_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 )
+                        END IF
+                     ENDDO
+                  ENDIF
+               
+               ENDIF ! case ice is thick or thin
+               
+               !---------------------
+               ! Compatibility tests
+               !--------------------- 
+               ! Test 1: area conservation
+               zconv = ABS( zai(ji) - SUM( za_i(ji,1:jpl) ) )
+               IF ( zconv < epsi06 ) itest(1) = 1
             
-            ! initialisation of ice variables for each try
-            zht_i(ji,1:jpl) = 0._wp
-            za_i (ji,1:jpl) = 0._wp
-            
-            ! *** case very thin ice: fill only category 1
-            IF ( i_fill == 1 ) THEN
-               zht_i(ji,1) = zhti(ji)
-               za_i (ji,1) = zai (ji)
-
-            ! *** case ice is thicker: fill categories >1
-            ELSE
-
-               ! Fill ice thicknesses except the last one (i_fill) by hmean 
-               DO jl = 1, i_fill - 1
-                  zht_i(ji,jl) = hi_mean(jl)
-               END DO
+               ! Test 2: volume conservation
+               zconv = ABS( zhti(ji)*zai(ji) - SUM( za_i(ji,1:jpl)*zht_i(ji,1:jpl) ) )
+               IF ( zconv < epsi06 ) itest(2) = 1
                
-               ! find which category (jl0) the input ice thickness falls into
-               jl0 = i_fill
+               ! Test 3: thickness of the last category is in-bounds ?
+               IF ( zht_i(ji,i_fill) >= hi_max(i_fill-1) ) itest(3) = 1
+               
+               ! Test 4: positivity of ice concentrations
+               itest(4) = 1
                DO jl = 1, i_fill
-                  IF ( ( zhti(ji) >= hi_max(jl-1) ) .AND. ( zhti(ji) < hi_max(jl) ) ) THEN
-                     jl0 = jl
-		     CYCLE
-                  ENDIF
-               END DO
-               
-               ! Concentrations in the (i_fill-1) categories 
-               za_i(ji,jl0) = zai(ji) / SQRT(REAL(jpl))
-               DO jl = 1, i_fill - 1
-                  IF ( jl == jl0 ) CYCLE
-                  zarg        = ( zht_i(ji,jl) - zhti(ji) ) / ( zhti(ji) * 0.5_wp )
-                  za_i(ji,jl) =   za_i (ji,jl0) * EXP(-zarg**2)
-               END DO
-               
-               ! Concentration in the last (i_fill) category
-               za_i(ji,i_fill) = zai(ji) - SUM( za_i(ji,1:i_fill-1) )
-               
-               ! Ice thickness in the last (i_fill) category
-               zV = SUM( za_i(ji,1:i_fill-1) * zht_i(ji,1:i_fill-1) )
-               zht_i(ji,i_fill) = ( zhti(ji) * zai(ji) - zV ) / za_i(ji,i_fill) 
-               
-            ENDIF ! case ice is thick or thin
-            
-            !---------------------
-            ! Compatibility tests
-            !--------------------- 
-            ! Test 1: area conservation
-            zconv = ABS( zai(ji) - SUM( za_i(ji,1:jpl) ) )
-            IF ( zconv < epsi06 ) itest(1) = 1
-            
-            ! Test 2: volume conservation
-            zconv = ABS( zhti(ji)*zai(ji) - SUM( za_i(ji,1:jpl)*zht_i(ji,1:jpl) ) )
-            IF ( zconv < epsi06 ) itest(2) = 1
-            
-            ! Test 3: thickness of the last category is in-bounds ?
-            IF ( zht_i(ji,i_fill) >= hi_max(i_fill-1) ) itest(3) = 1
-            
-            ! Test 4: positivity of ice concentrations
-            itest(4) = 1
-            DO jl = 1, i_fill
-               IF ( za_i(ji,jl) < 0._wp ) itest(4) = 0
-            END DO            
-                                                           !============================
-         END DO                                            ! end iteration on categories
-                                                           !============================
+                  IF ( za_i(ji,jl) < 0._wp ) itest(4) = 0
+               END DO
+               !                                         !============================
+            END DO                                       ! end iteration on categories
+               !                                         !============================
          ENDIF ! if zhti > 0
       END DO ! i loop
-
+      
       ! ------------------------------------------------
       ! Adding Snow in each category where za_i is not 0
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90	(revision 7309)
@@ -17,5 +17,4 @@
    USE sbc_oce         ! Surface boundary condition: ocean fields
    USE sbc_ice         ! Surface boundary condition: ice fields
-   USE dom_ice
    USE ice
    USE limvar
@@ -56,13 +55,13 @@
       INTEGER  ::  ji, jj, jk, jl  ! dummy loop indices
       REAL(wp) ::  z1_365
-      REAL(wp) ::  ztmp
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zoi, zei, zt_i, zt_s
-      REAL(wp), POINTER, DIMENSION(:,:)   ::  z2d, z2da, z2db, zswi    ! 2D workspace
+      REAL(wp) ::  z2da, z2db, ztmp
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zswi2
+      REAL(wp), POINTER, DIMENSION(:,:)   ::  z2d, zswi    ! 2D workspace
       !!-------------------------------------------------------------------
 
       IF( nn_timing == 1 )  CALL timing_start('limwri')
 
-      CALL wrk_alloc( jpi, jpj, jpl, zoi, zei, zt_i, zt_s )
-      CALL wrk_alloc( jpi, jpj     , z2d, z2da, z2db, zswi )
+      CALL wrk_alloc( jpi,jpj,jpl, zswi2 )
+      CALL wrk_alloc( jpi,jpj    , z2d, zswi )
 
       !-----------------------------
@@ -71,105 +70,76 @@
       z1_365 = 1._wp / 365._wp
 
-      CALL lim_var_icetm      ! mean sea ice temperature
-
-      CALL lim_var_bv         ! brine volume
-
-      DO jj = 1, jpj          ! presence indicator of ice
+      ! brine volume
+      CALL lim_var_bv 
+
+      ! tresholds for outputs
+      DO jj = 1, jpj
          DO ji = 1, jpi
             zswi(ji,jj)  = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi06 ) )
          END DO
       END DO
-      !
-      !
-      !                                             
-      IF ( iom_use( "icethic_cea" ) ) THEN                       ! mean ice thickness
-         DO jj = 1, jpj 
+      DO jl = 1, jpl
+         DO jj = 1, jpj
             DO ji = 1, jpi
-               z2d(ji,jj)  = vt_i(ji,jj) / MAX( at_i(ji,jj), epsi06 ) * zswi(ji,jj)
+               zswi2(ji,jj,jl)  = MAX( 0._wp , SIGN( 1._wp , a_i(ji,jj,jl) - epsi06 ) )
             END DO
          END DO
-         CALL iom_put( "icethic_cea"  , z2d              )
-      ENDIF
-
-      IF ( iom_use( "snowthic_cea" ) ) THEN                      ! snow thickness = mean snow thickness over the cell 
-         DO jj = 1, jpj                                            
-            DO ji = 1, jpi
-               z2d(ji,jj)  = vt_s(ji,jj) / MAX( at_i(ji,jj), epsi06 ) * zswi(ji,jj)
-            END DO
-         END DO
-         CALL iom_put( "snowthic_cea" , z2d              )       
-      ENDIF
+      END DO
       !
+      ! fluxes
+      ! pfrld is the lead fraction at the previous time step (actually between TRP and THD)
+      IF( iom_use('qsr_oce') )   CALL iom_put( "qsr_oce" , qsr_oce(:,:) * pfrld(:,:) )                                   !     solar flux at ocean surface
+      IF( iom_use('qns_oce') )   CALL iom_put( "qns_oce" , qns_oce(:,:) * pfrld(:,:) + 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') )   CALL iom_put( "qtr_ice" , SUM( ftr_ice(:,:,:) * a_i_b(:,:,:), dim=3 ) )                 !     solar flux transmitted thru ice
+      IF( iom_use('qt_oce' ) )   CALL iom_put( "qt_oce"  , ( qsr_oce(:,:) + qns_oce(:,:) ) * pfrld(:,:) + 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('qemp_oce') )  CALL iom_put( "qemp_oce" , qemp_oce(:,:) )  
+      IF( iom_use('qemp_ice') )  CALL iom_put( "qemp_ice" , qemp_ice(:,:) )  
+      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)
+
+      ! velocity
       IF ( iom_use( "uice_ipa" ) .OR. iom_use( "vice_ipa" ) .OR. iom_use( "icevel" ) ) THEN 
          DO jj = 2 , jpjm1
             DO ji = 2 , jpim1
-               z2da(ji,jj)  = (  u_ice(ji,jj) * umask(ji,jj,1) + u_ice(ji-1,jj) * umask(ji-1,jj,1) ) * 0.5_wp
-               z2db(ji,jj)  = (  v_ice(ji,jj) * vmask(ji,jj,1) + v_ice(ji,jj-1) * vmask(ji,jj-1,1) ) * 0.5_wp
+               z2da  = ( u_ice(ji,jj) * umask(ji,jj,1) + u_ice(ji-1,jj) * umask(ji-1,jj,1) ) * 0.5_wp
+               z2db  = ( v_ice(ji,jj) * vmask(ji,jj,1) + v_ice(ji,jj-1) * vmask(ji,jj-1,1) ) * 0.5_wp
+               z2d(ji,jj) = SQRT( z2da * z2da + z2db * z2db )
            END DO
          END DO
-         CALL lbc_lnk( z2da, 'T', -1. )
-         CALL lbc_lnk( z2db, 'T', -1. )
-         CALL iom_put( "uice_ipa"     , z2da             )       ! ice velocity u component
-         CALL iom_put( "vice_ipa"     , z2db             )       ! ice velocity v component
-         DO jj = 1, jpj                                 
-            DO ji = 1, jpi
-               z2d(ji,jj)  = SQRT( z2da(ji,jj) * z2da(ji,jj) + z2db(ji,jj) * z2db(ji,jj) ) 
-            END DO
-         END DO
-         CALL iom_put( "icevel"       , z2d              )       ! ice velocity module
+         CALL lbc_lnk( z2d, 'T', 1. )
+         CALL iom_put( "uice_ipa"     , u_ice      )       ! ice velocity u component
+         CALL iom_put( "vice_ipa"     , v_ice      )       ! ice velocity v component
+         CALL iom_put( "icevel"       , z2d        )       ! ice velocity module
       ENDIF
+
+      IF ( iom_use( "tau_icebfr" ) )    CALL iom_put( "tau_icebfr"  , tau_icebfr             )  ! ice friction with ocean bottom (landfast ice)  
       !
-      IF ( iom_use( "miceage" ) ) THEN 
-         z2d(:,:) = 0.e0
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch    = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - 0.1 ) )
-                  z2d(ji,jj) = z2d(ji,jj) + rswitch * oa_i(ji,jj,jl) / MAX( at_i(ji,jj), 0.1 )
-               END DO
-            END DO
-         END DO
-         CALL iom_put( "miceage"     , z2d * z1_365      )        ! mean ice age
-      ENDIF
-
-      IF ( iom_use( "micet" ) ) THEN 
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               z2d(ji,jj) = ( tm_i(ji,jj) - rt0 ) * zswi(ji,jj)
-            END DO
-         END DO
-         CALL iom_put( "micet"       , z2d               )        ! mean ice temperature
-      ENDIF
+      IF ( iom_use( "miceage" ) )       CALL iom_put( "miceage"     , om_i * zswi * z1_365   )  ! mean ice age
+      IF ( iom_use( "icethic_cea" ) )   CALL iom_put( "icethic_cea" , htm_i * zswi           )  ! ice thickness mean
+      IF ( iom_use( "snowthic_cea" ) )  CALL iom_put( "snowthic_cea", htm_s * zswi           )  ! snow thickness mean
+      IF ( iom_use( "micet" ) )         CALL iom_put( "micet"       , ( tm_i  - rt0 ) * zswi )  ! ice mean    temperature
+      IF ( iom_use( "icest" ) )         CALL iom_put( "icest"       , ( tm_su - rt0 ) * zswi )  ! ice surface temperature
+      IF ( iom_use( "icecolf" ) )       CALL iom_put( "icecolf"     , hicol                  )  ! frazil ice collection thickness
       !
-      IF ( iom_use( "icest" ) ) THEN 
-         z2d(:,:) = 0.e0
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  z2d(ji,jj) = z2d(ji,jj) + zswi(ji,jj) * ( t_su(ji,jj,jl) - rt0 ) * a_i(ji,jj,jl) / MAX( at_i(ji,jj) , epsi06 )
-               END DO
-            END DO
-         END DO
-         CALL iom_put( "icest"       , z2d              )        ! ice surface temperature
-      ENDIF
-
-      IF ( iom_use( "icecolf" ) )   CALL iom_put( "icecolf", hicol )  ! frazil ice collection thickness
- 
       CALL iom_put( "isst"        , sst_m               )        ! sea surface temperature
       CALL iom_put( "isss"        , sss_m               )        ! sea surface salinity
-      CALL iom_put( "iceconc"     , at_i                )        ! ice concentration
-      CALL iom_put( "icevolu"     , vt_i                )        ! ice volume = mean ice thickness over the cell
-      CALL iom_put( "icehc"       , et_i                )        ! ice total heat content
-      CALL iom_put( "isnowhc"     , et_s                )        ! snow total heat content
-      CALL iom_put( "ibrinv"      , bv_i * 100._wp      )        ! brine volume
+      CALL iom_put( "iceconc"     , at_i  * zswi        )        ! ice concentration
+      CALL iom_put( "icevolu"     , vt_i  * zswi        )        ! ice volume = mean ice thickness over the cell
+      CALL iom_put( "icehc"       , et_i  * zswi        )        ! ice total heat content
+      CALL iom_put( "isnowhc"     , et_s  * zswi        )        ! snow total heat content
+      CALL iom_put( "ibrinv"      , bvm_i * zswi * 100. )        ! brine volume
       CALL iom_put( "utau_ice"    , utau_ice            )        ! wind stress over ice along i-axis at I-point
       CALL iom_put( "vtau_ice"    , vtau_ice            )        ! wind stress over ice along j-axis at I-point
       CALL iom_put( "snowpre"     , sprecip * 86400.    )        ! snow precipitation 
-      CALL iom_put( "micesalt"    , smt_i               )        ! mean ice salinity
-
-      CALL iom_put( "icestr"      , strength * 0.001    )        ! ice strength
-      CALL iom_put( "idive"       , divu_i * 1.0e8      )        ! divergence
-      CALL iom_put( "ishear"      , shear_i * 1.0e8     )        ! shear
-      CALL iom_put( "snowvol"     , vt_s                )        ! snow volume
+      CALL iom_put( "micesalt"    , smt_i   * zswi      )        ! mean ice salinity
+
+      CALL iom_put( "icestr"      , strength * zswi )    ! ice strength
+      CALL iom_put( "idive"       , divu_i * 1.0e8      )    ! divergence
+      CALL iom_put( "ishear"      , shear_i * 1.0e8     )    ! shear
+      CALL iom_put( "snowvol"     , vt_s   * zswi       )        ! snow volume
       
       CALL iom_put( "icetrp"      , diag_trp_vi * rday  )        ! ice volume transport
@@ -180,10 +150,11 @@
 
       CALL iom_put( "sfxbog"      , sfx_bog * rday      )        ! salt flux from bottom growth
-      CALL iom_put( "sfxbom"      , sfx_bom * rday      )        ! salt flux from bottom melt
-      CALL iom_put( "sfxsum"      , sfx_sum * rday      )        ! salt flux from surface melt
+      CALL iom_put( "sfxbom"      , sfx_bom * rday      )        ! salt flux from bottom melting
+      CALL iom_put( "sfxsum"      , sfx_sum * rday      )        ! salt flux from surface melting
+      CALL iom_put( "sfxlam"      , sfx_lam * rday      )        ! salt flux from lateral melting
       CALL iom_put( "sfxsni"      , sfx_sni * rday      )        ! salt flux from snow ice formation
       CALL iom_put( "sfxopw"      , sfx_opw * rday      )        ! salt flux from open water formation
       CALL iom_put( "sfxdyn"      , sfx_dyn * rday      )        ! salt flux from ridging rafting
-      CALL iom_put( "sfxres"      , sfx_res * rday      )        ! salt flux from residual
+      CALL iom_put( "sfxres"      , sfx_res * rday      )        ! salt flux from limupdate (resultant)
       CALL iom_put( "sfxbri"      , sfx_bri * rday      )        ! salt flux from brines
       CALL iom_put( "sfxsub"      , sfx_sub * rday      )        ! salt flux from sublimation
@@ -198,8 +169,19 @@
       CALL iom_put( "vfxsum"     , wfx_sum * ztmp       )        ! surface melt 
       CALL iom_put( "vfxbom"     , wfx_bom * ztmp       )        ! bottom melt 
+      CALL iom_put( "vfxlam"     , wfx_lam * ztmp       )        ! lateral melt 
       CALL iom_put( "vfxice"     , wfx_ice * ztmp       )        ! total ice growth/melt 
+
+      IF ( iom_use( "vfxthin" ) ) THEN   ! ice production for open water + thin ice (<20cm) => comparable to observations  
+         WHERE( htm_i(:,:) < 0.2 .AND. htm_i(:,:) > 0. ) ; z2d = wfx_bog
+         ELSEWHERE                                       ; z2d = 0._wp
+         END WHERE
+         CALL iom_put( "vfxthin", ( wfx_opw + z2d ) * ztmp )
+      ENDIF
+
+      ztmp = rday / rhosn
+      CALL iom_put( "vfxspr"     , wfx_spr * ztmp       )        ! precip (snow)
       CALL iom_put( "vfxsnw"     , wfx_snw * ztmp       )        ! total snw growth/melt 
-      CALL iom_put( "vfxsub"     , wfx_sub * ztmp       )        ! sublimation (snow) 
-      CALL iom_put( "vfxspr"     , wfx_spr * ztmp       )        ! precip (snow)
+      CALL iom_put( "vfxsub"     , wfx_sub * ztmp       )        ! sublimation (snow/ice) 
+      CALL iom_put( "vfxsub_err" , wfx_err_sub * ztmp   )        ! "excess" of sublimation sent to ocean 
       
       CALL iom_put( "afxtot"     , afx_tot * rday       )        ! concentration tendency (total)
@@ -222,71 +204,24 @@
       CALL iom_put ('hfxdif'     , hfx_dif(:,:)         )   !  
       CALL iom_put ('hfxopw'     , hfx_opw(:,:)         )   !  
-      CALL iom_put ('hfxtur'     , fhtur(:,:) * SUM(a_i_b(:,:,:), dim=3) ) ! turbulent heat flux at ice base 
+      CALL iom_put ('hfxtur'     , fhtur(:,:) * at_i_b(:,:) ) ! turbulent heat flux at ice base 
       CALL iom_put ('hfxdhc'     , diag_heat(:,:)       )   ! Heat content variation in snow and ice 
       CALL iom_put ('hfxspr'     , hfx_spr(:,:)         )   ! Heat content of snow precip 
-      
-      IF ( iom_use( "vfxthin" ) ) THEN   ! ice production for open water + thin ice (<20cm) => comparable to observations  
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               z2d(ji,jj)  = vt_i(ji,jj) / MAX( at_i(ji,jj), epsi06 ) * zswi(ji,jj) ! mean ice thickness
-            END DO
-         END DO
-         WHERE( z2d(:,:) < 0.2 .AND. z2d(:,:) > 0. ) ; z2da = wfx_bog
-         ELSEWHERE                                   ; z2da = 0._wp
-         END WHERE
-         CALL iom_put( "vfxthin", ( wfx_opw + z2da ) * ztmp )
-      ENDIF
-
+
+      
       !--------------------------------
       ! Output values for each category
       !--------------------------------
-      CALL iom_put( "iceconc_cat"      , a_i         )        ! area for categories
-      CALL iom_put( "icethic_cat"      , ht_i        )        ! thickness for categories
-      CALL iom_put( "snowthic_cat"     , ht_s        )        ! snow depth for categories
-      CALL iom_put( "salinity_cat"     , sm_i        )        ! salinity for categories
-
+      IF ( iom_use( "iceconc_cat"  ) )  CALL iom_put( "iceconc_cat"      , a_i   * zswi2   )        ! area for categories
+      IF ( iom_use( "icethic_cat"  ) )  CALL iom_put( "icethic_cat"      , ht_i  * zswi2   )        ! thickness for categories
+      IF ( iom_use( "snowthic_cat" ) )  CALL iom_put( "snowthic_cat"     , ht_s  * zswi2   )        ! snow depth for categories
+      IF ( iom_use( "salinity_cat" ) )  CALL iom_put( "salinity_cat"     , sm_i  * zswi2   )        ! salinity for categories
       ! ice temperature
-      IF ( iom_use( "icetemp_cat" ) ) THEN 
-         zt_i(:,:,:) = SUM( t_i(:,:,:,:), dim=3 ) * r1_nlay_i
-         CALL iom_put( "icetemp_cat"   , zt_i - rt0  )
-      ENDIF
-      
+      IF ( iom_use( "icetemp_cat"  ) )  CALL iom_put( "icetemp_cat", ( SUM( t_i(:,:,:,:), dim=3 ) * r1_nlay_i - rt0 ) * zswi2 )
       ! snow temperature
-      IF ( iom_use( "snwtemp_cat" ) ) THEN 
-         zt_s(:,:,:) = SUM( t_s(:,:,:,:), dim=3 ) * r1_nlay_s
-         CALL iom_put( "snwtemp_cat"   , zt_s - rt0  )
-      ENDIF
-
-      ! Compute ice age
-      IF ( iom_use( "iceage_cat" ) ) THEN 
-         DO jl = 1, jpl 
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - 0.1 ) )
-                  rswitch = rswitch * MAX( 0._wp , SIGN( 1._wp , a_i(ji,jj,jl) - 0.1 ) )
-                  zoi(ji,jj,jl) = oa_i(ji,jj,jl)  / MAX( a_i(ji,jj,jl) , 0.1 ) * rswitch
-               END DO
-            END DO
-         END DO
-         CALL iom_put( "iceage_cat"   , zoi * z1_365 )        ! ice age for categories
-      ENDIF
-
-      ! Compute brine volume
-      IF ( iom_use( "brinevol_cat" ) ) THEN 
-         zei(:,:,:) = 0._wp
-         DO jl = 1, jpl 
-            DO jk = 1, nlay_i
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     rswitch = MAX( 0._wp , SIGN( 1._wp , a_i(ji,jj,jl) - epsi06 ) )
-                     zei(ji,jj,jl) = zei(ji,jj,jl) + 100.0 *  &
-                        ( - tmut * s_i(ji,jj,jk,jl) / MIN( ( t_i(ji,jj,jk,jl) - rt0 ), - epsi06 ) ) * &
-                        rswitch * r1_nlay_i
-                  END DO
-               END DO
-            END DO
-         END DO
-         CALL iom_put( "brinevol_cat"     , zei      )        ! brine volume for categories
-      ENDIF
+      IF ( iom_use( "snwtemp_cat"  ) )  CALL iom_put( "snwtemp_cat", ( SUM( t_s(:,:,:,:), dim=3 ) * r1_nlay_s - rt0 ) * zswi2 )
+      ! ice age
+      IF ( iom_use( "iceage_cat"   ) )  CALL iom_put( "iceage_cat" , o_i * zswi2 * z1_365 )
+      ! brine volume
+      IF ( iom_use( "brinevol_cat" ) )  CALL iom_put( "brinevol_cat", bv_i * 100. * zswi2 )
 
       !     !  Create an output files (output.lim.abort.nc) if S < 0 or u > 20 m/s
@@ -294,6 +229,6 @@
       !     not yet implemented
       
-      CALL wrk_dealloc( jpi, jpj, jpl, zoi, zei, zt_i, zt_s )
-      CALL wrk_dealloc( jpi, jpj     , z2d, zswi, z2da, z2db )
+      CALL wrk_dealloc( jpi, jpj, jpl, zswi2 )
+      CALL wrk_dealloc( jpi, jpj     , z2d, zswi )
 
       IF( nn_timing == 1 )  CALL timing_stop('limwri')
@@ -312,80 +247,102 @@
       !!
       !! History :
-      !!   4.1  !  2013-06  (C. Rousset)
+      !!   4.0  !  2013-06  (C. Rousset)
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt               ! ocean time-step index)
-      INTEGER, INTENT( in ) ::   kid , kh_i       
+      INTEGER, INTENT( in )   ::   kt               ! ocean time-step index)
+      INTEGER, INTENT( in )   ::   kid , kh_i
+      INTEGER                 ::   nz_i, jl
+      REAL(wp), DIMENSION(jpl) :: jcat
       !!----------------------------------------------------------------------
-
-      CALL histdef( kid, "iicethic", "Ice thickness"           , "m"      ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iiceconc", "Ice concentration"       , "%"      ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicetemp", "Ice temperature"         , "C"      ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicevelu", "i-Ice speed (I-point)"   , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicevelv", "j-Ice speed (I-point)"   , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "iicestru", "i-Wind stress over ice (I-pt)", "Pa",   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicestrv", "j-Wind stress over ice (I-pt)", "Pa",   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "iicesflx", "Solar flux over ocean"     , "w/m2" ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "iicenflx", "Non-solar flux over ocean" , "w/m2" ,   &
+      DO jl = 1, jpl
+         jcat(jl) = REAL(jl)
+      ENDDO
+      
+      CALL histvert( kid, "ncatice", "Ice Categories","", jpl, jcat, nz_i, "up")
+
+      CALL histdef( kid, "sithic", "Ice thickness"           , "m"      ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "siconc", "Ice concentration"       , "%"      ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "sitemp", "Ice temperature"         , "C"      ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "sivelu", "i-Ice speed "            , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "sivelv", "j-Ice speed "            , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "sistru", "i-Wind stress over ice " , "Pa"     ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "sistrv", "j-Wind stress over ice " , "Pa"     ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "sisflx", "Solar flux over ocean"     , "w/m2" ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "sinflx", "Non-solar flux over ocean" , "w/m2" ,   &
       &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
       CALL histdef( kid, "isnowpre", "Snow precipitation"      , "kg/m2/s",   &
       &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "iicesali", "Ice salinity"            , "PSU"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "iicevolu", "Ice volume"              , "m"      ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "iicedive", "Ice divergence"          , "10-8s-1",   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "iicebopr", "Ice bottom production"   , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicedypr", "Ice dynamic production"  , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicelapr", "Ice open water prod"     , "m/s"    ,   &
+      CALL histdef( kid, "sisali", "Ice salinity"            , "PSU"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "sivolu", "Ice volume"              , "m"      ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "sidive", "Ice divergence"          , "10-8s-1",   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+
+      CALL histdef( kid, "vfxbog", "Ice bottom production"   , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxdyn", "Ice dynamic production"  , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxopw", "Ice open water prod"     , "m/s"    ,   &
       &       jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicesipr", "Snow ice production "    , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicerepr", "Ice prod from limupdate" , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicebome", "Ice bottom melt"         , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicesume", "Ice surface melt"        , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iisfxdyn", "Salt flux from dynmics"  , ""       ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iisfxres", "Salt flux from limupdate", ""       ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxsni", "Snow ice production "    , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxres", "Ice prod from limupdate" , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxbom", "Ice bottom melt"         , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxsum", "Ice surface melt"        , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+
+      CALL histdef( kid, "sithicat", "Ice thickness"         , "m"      ,   &
+      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "siconcat", "Ice concentration"     , "%"      ,   &
+      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "sisalcat", "Ice salinity"           , ""      ,   &
+      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "sitemcat", "Ice temperature"       , "C"      ,   &
+      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "snthicat", "Snw thickness"         , "m"      ,   &
+      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "sntemcat", "Snw temperature"       , "C"      ,   &
+      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
 
       CALL histend( kid, snc4set )   ! end of the file definition
 
-      CALL histwrite( kid, "iicethic", kt, icethi        , jpi*jpj, (/1/) )    
-      CALL histwrite( kid, "iiceconc", kt, at_i          , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicetemp", kt, tm_i - rt0    , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicevelu", kt, u_ice          , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicevelv", kt, v_ice          , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicestru", kt, utau_ice       , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicestrv", kt, vtau_ice       , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicesflx", kt, qsr , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicenflx", kt, qns , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sithic", kt, htm_i         , jpi*jpj, (/1/) )    
+      CALL histwrite( kid, "siconc", kt, at_i          , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sitemp", kt, tm_i - rt0    , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sivelu", kt, u_ice          , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sivelv", kt, v_ice          , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sistru", kt, utau_ice       , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sistrv", kt, vtau_ice       , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sisflx", kt, qsr , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sinflx", kt, qns , jpi*jpj, (/1/) )
       CALL histwrite( kid, "isnowpre", kt, sprecip        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicesali", kt, smt_i          , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicevolu", kt, vt_i           , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicedive", kt, divu_i*1.0e8   , jpi*jpj, (/1/) )
-
-      CALL histwrite( kid, "iicebopr", kt, wfx_bog        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicedypr", kt, wfx_dyn        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicelapr", kt, wfx_opw        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicesipr", kt, wfx_sni        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicerepr", kt, wfx_res        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicebome", kt, wfx_bom        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicesume", kt, wfx_sum        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iisfxdyn", kt, sfx_dyn        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iisfxres", kt, sfx_res        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sisali", kt, smt_i          , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sivolu", kt, vt_i           , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sidive", kt, divu_i*1.0e8   , jpi*jpj, (/1/) )
+
+      CALL histwrite( kid, "vfxbog", kt, wfx_bog        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "vfxdyn", kt, wfx_dyn        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "vfxopw", kt, wfx_opw        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "vfxsni", kt, wfx_sni        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "vfxres", kt, wfx_res        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "vfxbom", kt, wfx_bom        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "vfxsum", kt, wfx_sum        , jpi*jpj, (/1/) )
+
+      CALL histwrite( kid, "sithicat", kt, ht_i        , jpi*jpj*jpl, (/1/) )    
+      CALL histwrite( kid, "siconcat", kt, a_i         , jpi*jpj*jpl, (/1/) )    
+      CALL histwrite( kid, "sisalcat", kt, sm_i        , jpi*jpj*jpl, (/1/) )    
+      CALL histwrite( kid, "sitemcat", kt, tm_i - rt0  , jpi*jpj*jpl, (/1/) )    
+      CALL histwrite( kid, "snthicat", kt, ht_s        , jpi*jpj*jpl, (/1/) )    
+      CALL histwrite( kid, "sntemcat", kt, tm_su - rt0 , jpi*jpj*jpl, (/1/) )    
 
       ! Close the file
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90	(revision 7309)
@@ -14,16 +14,4 @@
 
    PUBLIC thd_ice_alloc ! Routine called by nemogcm.F90
-
-   !!---------------------------
-   !! * Share Module variables
-   !!---------------------------
-   !                               !!! ** ice-thermo namelist (namicethd) **
-   REAL(wp), PUBLIC ::   rn_himin    !: minimum ice thickness
-   REAL(wp), PUBLIC ::   rn_maxfrazb !: maximum portion of frazil ice collecting at the ice bottom
-   REAL(wp), PUBLIC ::   rn_vfrazb   !: threshold drift speed for collection of bottom frazil ice
-   REAL(wp), PUBLIC ::   rn_Cfrazb   !: squeezing coefficient for collection of bottom frazil ice
-   REAL(wp), PUBLIC ::   rn_hnewice  !: thickness for new ice formation (m)
-
-   LOGICAL , PUBLIC ::   ln_frazil   !: use of frazil ice collection as function of wind (T) or not (F)
 
    !!-----------------------------
@@ -97,8 +85,4 @@
    !                                                     ! to reintegrate longwave flux inside the ice thermodynamics
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   i0            !: fraction of radiation transmitted to the ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dsm_i_fl_1d   !: Ice salinity variations due to flushing
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dsm_i_gd_1d   !: Ice salinity variations due to gravity drainage
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dsm_i_se_1d   !: Ice salinity variations due to basal salt entrapment
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dsm_i_si_1d   !: Ice salinity variations due to lateral accretion    
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hicol_1d      !: Ice collection thickness accumulated in leads
 
@@ -140,7 +124,9 @@
       !!---------------------------------------------------------------------!
       INTEGER ::   thd_ice_alloc   ! return value
-      INTEGER ::   ierr(3)
+      INTEGER ::   ierr(4), ii
       !!---------------------------------------------------------------------!
+      ierr(:) = 0
 
+      ii = 1
       ALLOCATE( npb      (jpij) , nplm      (jpij) , npac       (jpij) ,   &
          &      qlead_1d (jpij) , ftr_ice_1d(jpij) , qsr_ice_1d (jpij) ,   &
@@ -152,6 +138,7 @@
          &      hfx_thd_1d(jpij) , hfx_spr_1d(jpij) ,                      &
          &      hfx_snw_1d(jpij) , hfx_sub_1d(jpij) , hfx_err_1d(jpij) ,   &
-         &      hfx_res_1d(jpij) , hfx_err_rem_1d(jpij) , hfx_err_dif_1d(jpij) , STAT=ierr(1) )
+         &      hfx_res_1d(jpij) , hfx_err_rem_1d(jpij) , hfx_err_dif_1d(jpij) , STAT=ierr(ii) )
       !
+      ii = ii + 1
       ALLOCATE( sprecip_1d (jpij) , frld_1d    (jpij) , at_i_1d    (jpij) ,                     &
          &      fhtur_1d   (jpij) , wfx_snw_1d (jpij) , wfx_spr_1d (jpij) ,                     &
@@ -162,17 +149,19 @@
          &      sfx_bri_1d (jpij) , sfx_bog_1d (jpij) , sfx_bom_1d (jpij) , sfx_sum_1d (jpij),  &
          &      sfx_sni_1d (jpij) , sfx_opw_1d (jpij) , sfx_res_1d (jpij) , sfx_sub_1d (jpij),  &
-         &      dsm_i_fl_1d(jpij) , dsm_i_gd_1d(jpij) , dsm_i_se_1d(jpij) ,                     &     
-         &      dsm_i_si_1d(jpij) , hicol_1d    (jpij)                     , STAT=ierr(2) )
+         &      hicol_1d   (jpij) , STAT=ierr(ii) )
       !
-      ALLOCATE( t_su_1d   (jpij) , a_i_1d   (jpij) , ht_i_1d  (jpij) ,    &   
-         &      ht_s_1d   (jpij) , fc_su    (jpij) , fc_bo_i  (jpij) ,    &    
-         &      dh_s_tot  (jpij) , dh_i_surf(jpij) , dh_i_sub (jpij) ,    &    
-         &      dh_i_bott (jpij) ,dh_snowice(jpij) , sm_i_1d  (jpij) , s_i_new  (jpij) ,    &
-         &      t_s_1d(jpij,nlay_s) , t_i_1d(jpij,nlay_i) , s_i_1d(jpij,nlay_i) ,           &            
-         &      q_i_1d(jpij,nlay_i+1) , q_s_1d(jpij,nlay_s) ,                               &
-         &      qh_i_old(jpij,0:nlay_i+1), h_i_old(jpij,0:nlay_i+1) , STAT=ierr(3))
+      ii = ii + 1
+      ALLOCATE( t_su_1d   (jpij) , a_i_1d    (jpij) , ht_i_1d  (jpij) ,                      &
+         &      ht_s_1d   (jpij) , fc_su     (jpij) , fc_bo_i  (jpij) ,                      &    
+         &      dh_s_tot  (jpij) , dh_i_surf (jpij) , dh_i_sub (jpij) ,                      &    
+         &      dh_i_bott (jpij) , dh_snowice(jpij) , sm_i_1d  (jpij) , s_i_new  (jpij) ,    &
+         &      STAT=ierr(ii) )
       !
-      thd_ice_alloc = MAXVAL( ierr )
-
+      ii = ii + 1
+      ALLOCATE( t_s_1d  (jpij,nlay_s)     , t_i_1d (jpij,nlay_i)     , s_i_1d(jpij,nlay_i) ,  &            
+         &      q_i_1d  (jpij,nlay_i+1)   , q_s_1d (jpij,nlay_s)     ,                        &
+         &      qh_i_old(jpij,0:nlay_i+1) , h_i_old(jpij,0:nlay_i+1) , STAT=ierr(ii) )
+      !
+      thd_ice_alloc = MAXVAL( ierr(:) )
       IF( thd_ice_alloc /= 0 )   CALL ctl_warn( 'thd_ice_alloc: failed to allocate arrays.' )
       !
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/NST_SRC/agrif_ice.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/NST_SRC/agrif_ice.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/NST_SRC/agrif_ice.F90	(revision 7309)
@@ -5,4 +5,5 @@
    !!----------------------------------------------------------------------
    !! History :  3.4  ! 2012-08  (R. Benshila)  Original code
+   !!            3.6  ! 2016-05  (C. Rousset)   Add LIM3 compatibility
    !!----------------------------------------------------------------------
 #if defined key_agrif && defined key_lim2
@@ -59,4 +60,20 @@
    END FUNCTION agrif_ice_alloc
 
+#elif defined key_agrif && defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_agrif'                                              AGRIF zoom
+   !!----------------------------------------------------------------------   
+   IMPLICIT NONE
+   PRIVATE 
+
+   INTEGER, PUBLIC ::  u_ice_id, v_ice_id, tra_ice_id
+   INTEGER, PUBLIC ::  lim_nbstep = 0    ! child time position in sea-ice model
+
+   !!----------------------------------------------------------------------
+   !! NEMO/NST 3.6 , NEMO Consortium (2016)
+   !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
 #endif
    !!======================================================================
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90	(revision 7309)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90	(revision 7309)
@@ -0,0 +1,323 @@
+MODULE agrif_lim3_interp
+   !!=====================================================================================
+   !!                       ***  MODULE agrif_lim3_interp ***
+   !! Nesting module :  interp surface ice boundary condition from a parent grid
+   !! Sea-Ice model  :  LIM 3.6 Sea ice model time-stepping
+   !!=====================================================================================
+   !! History :  2.0   !  04-2008  (F. Dupont)  initial version
+   !!            3.4   !  09-2012  (R. Benshila, C. Herbaut) update and EVP
+   !!            3.6   !  05-2016  (C. Rousset)  Add LIM3 compatibility
+   !!----------------------------------------------------------------------
+#if defined key_agrif && defined key_lim3 
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'  :                                 LIM 3.6 sea-ice model
+   !!   'key_agrif' :                                 AGRIF library
+   !!----------------------------------------------------------------------
+   !!  agrif_interp_lim3    : interpolation of ice at "after" sea-ice time step
+   !!  agrif_interp_u_ice   : atomic routine to interpolate u_ice 
+   !!  agrif_interp_v_ice   : atomic routine to interpolate v_ice 
+   !!  agrif_interp_tra_ice : atomic routine to interpolate ice properties 
+   !!----------------------------------------------------------------------
+   USE par_oce
+   USE dom_oce
+   USE sbc_oce
+   USE ice
+   USE agrif_ice
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC agrif_interp_lim3
+
+   !!----------------------------------------------------------------------
+   !! NEMO/NST 3.6 , NEMO Consortium (2016)
+   !! $Id: agrif_lim3_interp.F90 6204 2016-01-04 13:47:06Z cetlod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE agrif_interp_lim3( cd_type, kiter, kitermax )
+      !!-----------------------------------------------------------------------
+      !!                 *** ROUTINE agrif_rhg_lim3  ***
+      !!
+      !!  ** Method  : simple call to atomic routines using stored values to
+      !!  fill the boundaries depending of the position of the point and
+      !!  computing factor for time interpolation
+      !!-----------------------------------------------------------------------
+      CHARACTER(len=1), INTENT( in )           :: cd_type
+      INTEGER         , INTENT( in ), OPTIONAL :: kiter, kitermax
+      !!
+      REAL(wp) :: zbeta
+      !!-----------------------------------------------------------------------
+      !
+      IF( Agrif_Root() )  RETURN
+      !
+      IF( PRESENT( kiter ) ) THEN  ! interpolation at the child sub-time step (for ice rheology)
+         zbeta = ( REAL(lim_nbstep) - REAL(kitermax - kiter) / REAL(kitermax) ) /  &
+            &    ( Agrif_Rhot() * REAL(Agrif_Parent(nn_fsbc)) / REAL(nn_fsbc) )
+      ELSE                         ! interpolation at the child time step
+         zbeta = REAL(lim_nbstep) / ( Agrif_Rhot() * REAL(Agrif_Parent(nn_fsbc)) / REAL(nn_fsbc) )
+      ENDIF
+      !
+      Agrif_SpecialValue=-9999.
+      Agrif_UseSpecialValue = .TRUE.
+      SELECT CASE(cd_type)
+      CASE('U')
+         CALL Agrif_Bc_variable( u_ice_id  , procname=interp_u_ice  , calledweight=zbeta )
+      CASE('V')
+         CALL Agrif_Bc_variable( v_ice_id  , procname=interp_v_ice  , calledweight=zbeta )
+      CASE('T')
+         CALL Agrif_Bc_variable( tra_ice_id, procname=interp_tra_ice, calledweight=zbeta )
+      END SELECT
+      Agrif_SpecialValue=0.
+      Agrif_UseSpecialValue = .FALSE.
+      !
+   END SUBROUTINE agrif_interp_lim3
+
+   !!------------------
+   !! Local subroutines
+   !!------------------
+   SUBROUTINE interp_u_ice( ptab, i1, i2, j1, j2, before )
+      !!-----------------------------------------------------------------------
+      !!                     *** ROUTINE interp_u_ice ***
+      !!
+      !! i1 i2 j1 j2 are the index of the boundaries parent(when before) and child (when after)
+      !! To solve issues when parent grid is "land" masked but not all the corresponding child grid points,
+      !! put -9999 WHERE the parent grid is masked. The child solution will be found in the 9(?) points around
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT(in) :: i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
+      LOGICAL , INTENT(in) :: before
+      !!
+      REAL(wp) :: zrhoy
+      !!-----------------------------------------------------------------------
+      !
+      IF( before ) THEN  ! parent grid
+         ptab(:,:) = e2u(i1:i2,j1:j2) * u_ice_b(i1:i2,j1:j2)
+         WHERE( umask(i1:i2,j1:j2,1) == 0. )  ptab(:,:) = -9999.
+      ELSE               ! child grid
+         zrhoy = Agrif_Rhoy()
+         u_ice(i1:i2,j1:j2) = ptab(:,:) / ( e2u(i1:i2,j1:j2) * zrhoy ) * umask(i1:i2,j1:j2,1)
+      ENDIF
+      !
+   END SUBROUTINE interp_u_ice
+
+
+   SUBROUTINE interp_v_ice( ptab, i1, i2, j1, j2, before )
+      !!-----------------------------------------------------------------------
+      !!                    *** ROUTINE interp_v_ice ***
+      !!
+      !! i1 i2 j1 j2 are the index of the boundaries parent(when before) and child (when after)
+      !! To solve issues when parent grid is "land" masked but not all the corresponding child grid points,
+      !! put -9999 WHERE the parent grid is masked. The child solution will be found in the 9(?) points around
+      !!-----------------------------------------------------------------------      
+      INTEGER , INTENT(in) :: i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
+      LOGICAL , INTENT(in) :: before
+      !!
+      REAL(wp) :: zrhox
+      !!-----------------------------------------------------------------------
+      !
+      IF( before ) THEN  ! parent grid
+         ptab(:,:) = e1v(i1:i2,j1:j2) * v_ice_b(i1:i2,j1:j2)
+         WHERE( vmask(i1:i2,j1:j2,1) == 0. )  ptab(:,:) = -9999.
+      ELSE               ! child grid
+         zrhox = Agrif_Rhox()
+         v_ice(i1:i2,j1:j2) = ptab(:,:) / ( e1v(i1:i2,j1:j2) * zrhox ) * vmask(i1:i2,j1:j2,1)
+      ENDIF
+      !
+   END SUBROUTINE interp_v_ice
+
+
+   SUBROUTINE interp_tra_ice( ptab, i1, i2, j1, j2, k1, k2, before, nb, ndir )
+      !!-----------------------------------------------------------------------
+      !!                    *** ROUTINE interp_tra_ice ***                           
+      !!
+      !! i1 i2 j1 j2 are the index of the boundaries parent(when before) and child (when after)
+      !! To solve issues when parent grid is "land" masked but not all the corresponding child grid points,
+      !! put -9999 WHERE the parent grid is masked. The child solution will be found in the 9(?) points around
+      !!-----------------------------------------------------------------------
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
+      INTEGER , INTENT(in) :: i1, i2, j1, j2, k1, k2
+      LOGICAL , INTENT(in) :: before
+      INTEGER , INTENT(in) :: nb, ndir
+      !!
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: ztab
+      INTEGER  ::   ji, jj, jk, jl, jm
+      INTEGER  ::   imin, imax, jmin, jmax
+      REAL(wp) ::   zrhox, z1, z2, z3, z4, z5, z6, z7
+      LOGICAL  ::   western_side, eastern_side, northern_side, southern_side
+
+      !!-----------------------------------------------------------------------
+      ! clem: pkoi on n'utilise pas les quantités intégrées ici => before: * e1e2t ; after: * r1_e1e2t / rhox / rhoy
+      ! a priori c'est ok comme ca (cf ce qui est fait dans l'ocean). Je ne sais pas pkoi ceci dit
+      ALLOCATE( ztab(SIZE(a_i_b,1),SIZE(a_i_b,2),SIZE(ptab,3)) )
+     
+      IF( before ) THEN  ! parent grid
+         jm = 1
+         DO jl = 1, jpl
+            ptab(i1:i2,j1:j2,jm) = a_i_b  (i1:i2,j1:j2,jl) ; jm = jm + 1
+            ptab(i1:i2,j1:j2,jm) = v_i_b  (i1:i2,j1:j2,jl) ; jm = jm + 1
+            ptab(i1:i2,j1:j2,jm) = v_s_b  (i1:i2,j1:j2,jl) ; jm = jm + 1
+            ptab(i1:i2,j1:j2,jm) = smv_i_b(i1:i2,j1:j2,jl) ; jm = jm + 1
+            ptab(i1:i2,j1:j2,jm) = oa_i_b (i1:i2,j1:j2,jl) ; jm = jm + 1
+            DO jk = 1, nlay_s
+               ptab(i1:i2,j1:j2,jm) = e_s_b(i1:i2,j1:j2,jk,jl) ; jm = jm + 1
+            ENDDO
+            DO jk = 1, nlay_i
+               ptab(i1:i2,j1:j2,jm) = e_i_b(i1:i2,j1:j2,jk,jl) ; jm = jm + 1
+            ENDDO
+         ENDDO
+         
+         DO jk = k1, k2
+            WHERE( tmask(i1:i2,j1:j2,1) == 0. )  ptab(i1:i2,j1:j2,jk) = -9999.
+         ENDDO
+         
+      ELSE               ! child grid
+!! ==> The easiest interpolation is the following commented lines
+!!         jm = 1
+!!         DO jl = 1, jpl
+!!            a_i  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+!!            v_i  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+!!            v_s  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+!!            smv_i(i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+!!            oa_i (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+!!            DO jk = 1, nlay_s
+!!               e_s(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+!!            ENDDO
+!!            DO jk = 1, nlay_i
+!!               e_i(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+!!            ENDDO
+!!         ENDDO
+
+!! ==> this is a more complex interpolation since we mix solutions over a couple of grid points
+!!     it is advised to use it for fields modified by high order schemes (e.g. advection UM5...)
+         ! record ztab
+         jm = 1
+         DO jl = 1, jpl
+            ztab(:,:,jm) = a_i_b  (:,:,jl) ; jm = jm + 1
+            ztab(:,:,jm) = v_i_b  (:,:,jl) ; jm = jm + 1
+            ztab(:,:,jm) = v_s_b  (:,:,jl) ; jm = jm + 1
+            ztab(:,:,jm) = smv_i_b(:,:,jl) ; jm = jm + 1
+            ztab(:,:,jm) = oa_i_b (:,:,jl) ; jm = jm + 1
+            DO jk = 1, nlay_s
+               ztab(:,:,jm) = e_s_b(:,:,jk,jl) ; jm = jm + 1
+            ENDDO
+            DO jk = 1, nlay_i
+               ztab(:,:,jm) = e_i_b(:,:,jk,jl) ; jm = jm + 1
+            ENDDO
+         ENDDO
+         !
+         ! borders of the domain
+         western_side  = (nb == 1).AND.(ndir == 1)  ;  eastern_side  = (nb == 1).AND.(ndir == 2)
+         southern_side = (nb == 2).AND.(ndir == 1)  ;  northern_side = (nb == 2).AND.(ndir == 2)
+         !
+         ! spatial smoothing
+         zrhox = Agrif_Rhox()
+         z1 =      ( zrhox - 1. ) * 0.5 
+         z3 =      ( zrhox - 1. ) / ( zrhox + 1. )
+         z6 = 2. * ( zrhox - 1. ) / ( zrhox + 1. )
+         z7 =    - ( zrhox - 1. ) / ( zrhox + 3. )
+         z2 = 1. - z1
+         z4 = 1. - z3
+         z5 = 1. - z6 - z7
+         !
+         ! Remove corners
+         imin = i1  ;  imax = i2  ;  jmin = j1  ;  jmax = j2
+         IF( (nbondj == -1) .OR. (nbondj == 2) )   jmin = 3
+         IF( (nbondj == +1) .OR. (nbondj == 2) )   jmax = nlcj-2
+         IF( (nbondi == -1) .OR. (nbondi == 2) )   imin = 3
+         IF( (nbondi == +1) .OR. (nbondi == 2) )   imax = nlci-2
+
+         ! smoothed fields
+         IF( eastern_side ) THEN
+            ztab(nlci,j1:j2,:) = z1 * ptab(nlci,j1:j2,:) + z2 * ptab(nlci-1,j1:j2,:)
+            DO jj = jmin, jmax
+               rswitch = 0.
+               IF( u_ice(nlci-2,jj) > 0._wp ) rswitch = 1.
+               ztab(nlci-1,jj,:) = ( 1. - umask(nlci-2,jj,1) ) * ztab(nlci,jj,:)  &
+                  &                +      umask(nlci-2,jj,1)   *  &
+                  &                ( ( 1. - rswitch ) * ( z4 * ztab(nlci,jj,:)   + z3 * ztab(nlci-2,jj,:) )  &
+                  &                  +      rswitch   * ( z6 * ztab(nlci-2,jj,:) + z5 * ztab(nlci,jj,:) + z7 * ztab(nlci-3,jj,:) ) )
+               ztab(nlci-1,jj,:) = ztab(nlci-1,jj,:) * tmask(nlci-1,jj,1)
+            END DO
+         ENDIF
+         ! 
+         IF( northern_side ) THEN
+            ztab(i1:i2,nlcj,:) = z1 * ptab(i1:i2,nlcj,:) + z2 * ptab(i1:i2,nlcj-1,:)
+            DO ji = imin, imax
+               rswitch = 0.
+               IF( v_ice(ji,nlcj-2) > 0._wp ) rswitch = 1.
+               ztab(ji,nlcj-1,:) = ( 1. - vmask(ji,nlcj-2,1) ) * ztab(ji,nlcj,:)  &
+                  &                +      vmask(ji,nlcj-2,1)   *  &
+                  &                ( ( 1. - rswitch ) * ( z4 * ztab(ji,nlcj,:)   + z3 * ztab(ji,nlcj-2,:) ) &
+                  &                  +      rswitch   * ( z6 * ztab(ji,nlcj-2,:) + z5 * ztab(ji,nlcj,:) + z7 * ztab(ji,nlcj-3,:) ) )
+               ztab(ji,nlcj-1,:) = ztab(ji,nlcj-1,:) * tmask(ji,nlcj-1,1)
+            END DO
+         END IF
+         !
+         IF( western_side) THEN
+            ztab(1,j1:j2,:) = z1 * ptab(1,j1:j2,:) + z2 * ptab(2,j1:j2,:)
+            DO jj = jmin, jmax
+               rswitch = 0.
+               IF( u_ice(2,jj) > 0._wp ) rswitch = 1.
+               ztab(2,jj,:) = ( 1. - umask(2,jj,1) ) * ztab(1,jj,:)  &
+                  &           +      umask(2,jj,1)   *   &
+                  &           ( ( 1. - rswitch ) * ( z4 * ztab(1,jj,:) + z3 * ztab(3,jj,:) ) &
+                  &             +      rswitch   * ( z6 * ztab(3,jj,:) + z5 * ztab(1,jj,:) + z7 * ztab(4,jj,:) ) )
+               ztab(2,jj,:) = ztab(2,jj,:) * tmask(2,jj,1)
+            END DO
+         ENDIF
+         !
+         IF( southern_side ) THEN
+            ztab(i1:i2,1,:) = z1 * ptab(i1:i2,1,:) + z2 * ptab(i1:i2,2,:)
+            DO ji = imin, imax
+               rswitch = 0.
+               IF( v_ice(ji,2) > 0._wp ) rswitch = 1.
+               ztab(ji,2,:) = ( 1. - vmask(ji,2,1) ) * ztab(ji,1,:)  &
+                  &           +      vmask(ji,2,1)   *  &
+                  &           ( ( 1. - rswitch ) * ( z4 * ztab(ji,1,:) + z3 * ztab(ji,3,:) ) &
+                  &             +      rswitch   * ( z6 * ztab(ji,3,:) + z5 * ztab(ji,1,:) + z7 * ztab(ji,4,:) ) )
+               ztab(ji,2,:) = ztab(ji,2,:) * tmask(ji,2,1)
+            END DO
+         END IF
+         !
+         ! Treatment of corners
+         IF( (eastern_side) .AND. ((nbondj == -1).OR.(nbondj == 2)) )  ztab(nlci-1,2,:)      = ptab(nlci-1,2,:)      ! East south
+         IF( (eastern_side) .AND. ((nbondj ==  1).OR.(nbondj == 2)) )  ztab(nlci-1,nlcj-1,:) = ptab(nlci-1,nlcj-1,:) ! East north
+         IF( (western_side) .AND. ((nbondj == -1).OR.(nbondj == 2)) )  ztab(2,2,:)           = ptab(2,2,:)           ! West south
+         IF( (western_side) .AND. ((nbondj ==  1).OR.(nbondj == 2)) )  ztab(2,nlcj-1,:)      = ptab(2,nlcj-1,:)      ! West north
+
+         ! retrieve ice tracers
+         jm = 1
+         DO jl = 1, jpl
+            a_i  (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            v_i  (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            v_s  (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            smv_i(i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            oa_i (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            DO jk = 1, nlay_s
+               e_s(i1:i2,j1:j2,jk,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            ENDDO
+            DO jk = 1, nlay_i
+               e_i(i1:i2,j1:j2,jk,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            ENDDO
+         ENDDO
+         
+      ENDIF
+      
+      DEALLOCATE( ztab )
+      !
+   END SUBROUTINE interp_tra_ice
+
+#else
+CONTAINS
+   SUBROUTINE agrif_lim3_interp_empty
+      !!---------------------------------------------
+      !!   *** ROUTINE agrif_lim3_interp_empty ***
+      !!---------------------------------------------
+      WRITE(*,*)  'agrif_lim3_interp : You should not have seen this print! error?'
+   END SUBROUTINE agrif_lim3_interp_empty
+#endif
+END MODULE agrif_lim3_interp
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/NST_SRC/agrif_lim3_update.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/NST_SRC/agrif_lim3_update.F90	(revision 7309)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/NST_SRC/agrif_lim3_update.F90	(revision 7309)
@@ -0,0 +1,196 @@
+#define TWO_WAY
+
+MODULE agrif_lim3_update
+   !!=====================================================================================
+   !!                       ***  MODULE agrif_lim3_update ***
+   !! Nesting module :  update surface ocean boundary condition over ice from a child grid
+   !! Sea-Ice model  :  LIM 3.6 Sea ice model time-stepping
+   !!=====================================================================================
+   !! History :  2.0   !  04-2008  (F. Dupont)  initial version
+   !!            3.4   !  08-2012  (R. Benshila, C. Herbaut) update and EVP
+   !!            3.6   !  05-2016  (C. Rousset)  Add LIM3 compatibility
+   !!----------------------------------------------------------------------
+#if defined key_agrif && defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'  :                                 LIM 3.6 sea-ice model
+   !!   'key_agrif' :                                 AGRIF library 
+   !!----------------------------------------------------------------------
+   !!   agrif_update_lim3  : update sea-ice on boundaries or total
+   !!                        child domain for velocities and ice properties
+   !!   update_tra_ice     : sea-ice properties
+   !!   update_u_ice       : zonal      ice velocity
+   !!   update_v_ice       : meridional ice velocity
+   !!----------------------------------------------------------------------
+   USE dom_oce
+   USE sbc_oce
+   USE agrif_oce
+   USE ice
+   USE agrif_ice 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC agrif_update_lim3
+
+   !!----------------------------------------------------------------------
+   !! NEMO/NST 3.6 , LOCEAN-IPSL (2016)
+   !! $Id: agrif_lim3_update.F90 6204 2016-01-04 13:47:06Z cetlod $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE agrif_update_lim3( kt )
+      !!----------------------------------------------------------------------
+      !!                     *** ROUTINE agrif_update_lim3 ***
+      !! ** Method  :   Call the hydrostaticupdate pressure at the boundary or the entire domain 
+      !!
+      !! ** Action : - Update (u_ice,v_ice) and ice tracers
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) :: kt
+      !!
+      !!----------------------------------------------------------------------
+      !
+!      IF( ( MOD( kt-nit000, Agrif_irhot() * Agrif_Parent(nn_fsbc) ) /=0 ) .AND. (kt /= 0) ) THEN
+!         PRINT *, 'clem NOT udpate, kt=',kt,Agrif_NbStepint()
+!      ELSE
+!         PRINT *, 'clem     UPDATE, kt=',kt,Agrif_NbStepint()
+!      ENDIF
+
+      !! clem: I think the update should take place each time the ocean sees the surface forcings (but maybe I am wrong and we should update every rhot time steps) 
+      IF( ( MOD( kt-nit000, Agrif_irhot() * Agrif_Parent(nn_fsbc) ) /=0 ) .AND. (kt /= 0) ) RETURN ! do not update if nb of child time steps differ from time refinement
+                                                                                                   ! i.e. update only at the parent time step
+      !! clem: this condition is clearly wrong if nn_fsbc/=1 (==> Agrif_NbStepint /= (Agrif_irhot()-1) all the time)
+      !!IF( ( Agrif_NbStepint() .NE. (Agrif_irhot()-1) ) .AND. (kt /= 0) )  RETURN
+      
+      Agrif_UseSpecialValueInUpdate = .TRUE.
+      Agrif_SpecialValueFineGrid = -9999.
+# if defined TWO_WAY
+      IF( MOD(nbcline,nbclineupdate) == 0) THEN ! update the whole basin at each nbclineupdate (=nn_cln_update) baroclinic parent time steps
+                                                ! nbcline is incremented (+1) at the end of each parent time step from 0 (1st time step)
+         CALL Agrif_Update_Variable( tra_ice_id , procname = update_tra_ice  )
+         CALL Agrif_Update_Variable( u_ice_id   , procname = update_u_ice    )
+         CALL Agrif_Update_Variable( v_ice_id   , procname = update_v_ice    )
+      ELSE                                      ! update only the boundaries defined par locupdate
+         CALL Agrif_Update_Variable( tra_ice_id , locupdate=(/0,2/), procname = update_tra_ice  )
+         CALL Agrif_Update_Variable( u_ice_id   , locupdate=(/0,1/), procname = update_u_ice    )
+         CALL Agrif_Update_Variable( v_ice_id   , locupdate=(/0,1/), procname = update_v_ice    )
+      ENDIF
+# endif
+      Agrif_UseSpecialValueInUpdate = .FALSE.
+      !
+   END SUBROUTINE agrif_update_lim3
+
+
+   !!------------------
+   !! Local subroutines
+   !!------------------
+   SUBROUTINE update_tra_ice( ptab, i1, i2, j1, j2, k1, k2, before )
+      !!-----------------------------------------------------------------------
+      !!                        *** ROUTINE update_tra_ice ***
+      !! ** Method  : Compute the mass properties on the fine grid and recover
+      !!              the properties per mass on the coarse grid
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT(in) :: i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
+      LOGICAL , INTENT(in) :: before
+      !!
+      INTEGER  :: jk, jl, jm
+      !!-----------------------------------------------------------------------
+      ! clem: it is ok not to multiply by e1 e2 since we conserve tracers here (cf ce qui est fait dans opa).
+      IF( before ) THEN
+         jm = 1
+         DO jl = 1, jpl
+            ptab(:,:,jm) = a_i  (i1:i2,j1:j2,jl) ; jm = jm + 1
+            ptab(:,:,jm) = v_i  (i1:i2,j1:j2,jl) ; jm = jm + 1
+            ptab(:,:,jm) = v_s  (i1:i2,j1:j2,jl) ; jm = jm + 1
+            ptab(:,:,jm) = smv_i(i1:i2,j1:j2,jl) ; jm = jm + 1
+            ptab(:,:,jm) = oa_i (i1:i2,j1:j2,jl) ; jm = jm + 1
+            DO jk = 1, nlay_s
+               ptab(:,:,jm) = e_s(i1:i2,j1:j2,jk,jl) ; jm = jm + 1
+            ENDDO
+            DO jk = 1, nlay_i
+               ptab(:,:,jm) = e_i(i1:i2,j1:j2,jk,jl) ; jm = jm + 1
+            ENDDO
+         ENDDO
+
+         DO jk = k1, k2
+            WHERE( tmask(i1:i2,j1:j2,1) == 0. )  ptab(:,:,jk) = -9999.
+         ENDDO
+                  
+      ELSE
+         jm = 1
+         DO jl = 1, jpl
+            a_i  (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            v_i  (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            v_s  (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            smv_i(i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            oa_i (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            DO jk = 1, nlay_s
+               e_s(i1:i2,j1:j2,jk,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            ENDDO
+            DO jk = 1, nlay_i
+               e_i(i1:i2,j1:j2,jk,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            ENDDO
+         ENDDO
+
+      ENDIF
+      !
+   END SUBROUTINE update_tra_ice
+
+
+   SUBROUTINE update_u_ice( ptab, i1, i2, j1, j2, before )
+      !!-----------------------------------------------------------------------
+      !!                        *** ROUTINE update_u_ice ***
+      !! ** Method  : Update the fluxes and recover the properties (C-grid)
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT(in) :: i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
+      LOGICAL , INTENT(in) :: before
+      !!
+      REAL(wp) :: zrhoy
+      !!-----------------------------------------------------------------------
+      !
+      IF( before ) THEN
+         zrhoy = Agrif_Rhoy()
+         ptab(:,:) = e2u(i1:i2,j1:j2) * u_ice(i1:i2,j1:j2) * zrhoy
+         WHERE( umask(i1:i2,j1:j2,1) == 0. )  ptab(:,:) = -9999.
+      ELSE
+         u_ice(i1:i2,j1:j2) = ptab(:,:) / e2u(i1:i2,j1:j2) * umask(i1:i2,j1:j2,1)
+      ENDIF
+      ! 
+   END SUBROUTINE update_u_ice
+
+
+   SUBROUTINE update_v_ice( ptab, i1, i2, j1, j2, before )
+      !!-----------------------------------------------------------------------
+      !!                    *** ROUTINE update_v_ice ***
+      !! ** Method  : Update the fluxes and recover the properties (C-grid)
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT(in) :: i1,i2,j1,j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2),  INTENT(inout) :: ptab
+      LOGICAL , INTENT(in) :: before
+      !!
+      REAL(wp) :: zrhox
+      !!-----------------------------------------------------------------------
+      !
+      IF( before ) THEN
+         zrhox = Agrif_Rhox()
+         ptab(:,:) = e1v(i1:i2,j1:j2) * v_ice(i1:i2,j1:j2) * zrhox
+         WHERE( vmask(i1:i2,j1:j2,1) == 0. )  ptab(:,:) = -9999.
+      ELSE
+         v_ice(i1:i2,j1:j2) = ptab(:,:) / e1v(i1:i2,j1:j2) * vmask(i1:i2,j1:j2,1)
+      ENDIF
+      !
+   END SUBROUTINE update_v_ice
+
+#else
+CONTAINS
+   SUBROUTINE agrif_lim3_update_empty
+      !!---------------------------------------------
+      !!   *** ROUTINE agrif_lim3_update_empty ***
+      !!---------------------------------------------
+      WRITE(*,*)  'agrif_lim3_update : You should not have seen this print! error?'
+   END SUBROUTINE agrif_lim3_update_empty
+#endif
+END MODULE agrif_lim3_update
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90	(revision 7309)
@@ -27,6 +27,6 @@
 #elif defined key_lim3
    USE ice             ! LIM_3 ice variables
-   USE dom_ice         ! sea-ice domain
    USE limvar
+   USE limctl
 #endif 
    USE par_oce         ! ocean parameters
@@ -82,6 +82,7 @@
       !
 #if defined key_lim3
-      CALL lim_var_zapsmall
-      CALL lim_var_agg(1)
+                        CALL lim_var_zapsmall
+                        CALL lim_var_agg(1)
+      IF( ln_limctl )   CALL lim_prt( kt, iiceprt, jiceprt, 1, ' - ice thermo bdy - ' )
 #endif
       !
@@ -121,5 +122,5 @@
       !
 #if defined key_lim2
-      DO jb = 1, idx%nblen(jgrd)
+      DO jb = 1, idx%nblenrim(jgrd)
          ji    = idx%nbi(jb,jgrd)
          jj    = idx%nbj(jb,jgrd)
@@ -141,5 +142,5 @@
 
       DO jl = 1, jpl
-         DO jb = 1, idx%nblen(jgrd)
+         DO jb = 1, idx%nblenrim(jgrd)
             ji    = idx%nbi(jb,jgrd)
             jj    = idx%nbj(jb,jgrd)
@@ -177,5 +178,5 @@
 
       DO jl = 1, jpl
-         DO jb = 1, idx%nblen(jgrd)
+         DO jb = 1, idx%nblenrim(jgrd)
             ji    = idx%nbi(jb,jgrd)
             jj    = idx%nbj(jb,jgrd)
@@ -236,5 +237,5 @@
             END SELECT
             !
-            IF( nn_icesal == 1 ) THEN     ! constant salinity : overwrite rn_ice_sal
+            IF( nn_icesal == 1 ) THEN     ! constant salinity : overwrite rn_icesal
                sm_i(ji,jj  ,jl) = rn_icesal
                s_i (ji,jj,:,jl) = rn_icesal
@@ -325,5 +326,5 @@
             CASE ( 'U' )  
                jgrd = 2      ! u velocity
-               DO jb = 1, idx_bdy(ib_bdy)%nblen(jgrd)
+               DO jb = 1, idx_bdy(ib_bdy)%nblenrim(jgrd)
                   ji    = idx_bdy(ib_bdy)%nbi(jb,jgrd)
                   jj    = idx_bdy(ib_bdy)%nbj(jb,jgrd)
@@ -352,5 +353,5 @@
             CASE ( 'V' )
                jgrd = 3      ! v velocity
-               DO jb = 1, idx_bdy(ib_bdy)%nblen(jgrd)
+               DO jb = 1, idx_bdy(ib_bdy)%nblenrim(jgrd)
                   ji    = idx_bdy(ib_bdy)%nbi(jb,jgrd)
                   jj    = idx_bdy(ib_bdy)%nbj(jb,jgrd)
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 7309)
@@ -38,5 +38,4 @@
    PUBLIC   dia_hsb        ! routine called by step.F90
    PUBLIC   dia_hsb_init   ! routine called by nemogcm.F90
-   PUBLIC   dia_hsb_rst    ! routine called by step.F90
 
    LOGICAL, PUBLIC ::   ln_diahsb   !: check the heat and salt budgets
@@ -86,4 +85,5 @@
       !!---------------------------------------------------------------------------
       IF( nn_timing == 1 )   CALL timing_start('dia_hsb')      
+      !
       CALL wrk_alloc( jpi,jpj,   z2d0, z2d1 )
       !
@@ -171,5 +171,7 @@
       ENDDO
 
-      ! Substract forcing from heat content, salt content and volume variations
+      ! ------------------------ !
+      ! 3 -  Drifts              !
+      ! ------------------------ !
       zdiff_v1 = zdiff_v1 - frc_v
       IF( .NOT.ln_linssh )   zdiff_v2 = zdiff_v2 - frc_v
@@ -184,5 +186,5 @@
 
       ! ----------------------- !
-      ! 3 - Diagnostics writing !
+      ! 4 - Diagnostics writing !
       ! ----------------------- !
       zvol_tot = 0._wp                    ! total ocean volume (calculated with scale factors)
@@ -197,25 +199,29 @@
 !!gm end
 
-      IF( ln_linssh ) THEN
-        CALL iom_put( 'bgtemper' , zdiff_hc1 / zvol_tot)              ! Heat content variation (C) 
-        CALL iom_put( 'bgsaline' , zdiff_sc1 / zvol_tot)              ! Salt content variation (psu)
-        CALL iom_put( 'bgheatco' , zdiff_hc1 * 1.e-20 * rau0 * rcp )  ! Heat content variation (1.e20 J) 
-        CALL iom_put( 'bgsaltco' , zdiff_sc1 * 1.e-9   )              ! Salt content variation (psu*km3)
-        CALL iom_put( 'bgvolssh' , zdiff_v1  * 1.e-9   )              ! volume ssh variation (km3)  
-        CALL iom_put( 'bgfrcvol' , frc_v    * 1.e-9    )              ! vol - surface forcing (km3) 
-        CALL iom_put( 'bgfrctem' , frc_t / zvol_tot    )              ! hc  - surface forcing (C) 
-        CALL iom_put( 'bgfrcsal' , frc_s / zvol_tot    )              ! sc  - surface forcing (psu) 
+      CALL iom_put(   'bgfrcvol' , frc_v    * 1.e-9    )              ! vol - surface forcing (km3) 
+      CALL iom_put(   'bgfrctem' , frc_t    * rau0 * rcp * 1.e-20 )   ! hc  - surface forcing (1.e20 J) 
+      CALL iom_put(   'bgfrchfx' , frc_t    * rau0 * rcp /  &         ! hc  - surface forcing (W/m2) 
+         &                       ( surf_tot * kt * rdt )        )
+      CALL iom_put(   'bgfrcsal' , frc_s    * 1.e-9    )              ! sc  - surface forcing (psu*km3) 
+
+      IF( .NOT. ln_linssh ) THEN
+        CALL iom_put( 'bgtemper' , zdiff_hc / zvol_tot )              ! Temperature drift     (C) 
+        CALL iom_put( 'bgsaline' , zdiff_sc / zvol_tot )              ! Salinity    drift     (pss)
+        CALL iom_put( 'bgheatco' , zdiff_hc * 1.e-20 * rau0 * rcp )   ! Heat content drift    (1.e20 J) 
+        CALL iom_put( 'bgheatfx' , zdiff_hc * rau0 * rcp /  &         ! Heat flux drift       (W/m2) 
+           &                       ( surf_tot * kt * rdt )        )
+        CALL iom_put( 'bgsaltco' , zdiff_sc * 1.e-9    )              ! Salt content drift    (psu*km3)
+        CALL iom_put( 'bgvolssh' , zdiff_v1 * 1.e-9    )              ! volume ssh drift      (km3)  
+        CALL iom_put( 'bgvole3t' , zdiff_v2 * 1.e-9    )              ! volume e3t drift      (km3)  
+      ELSE
+        CALL iom_put( 'bgtemper' , zdiff_hc1 / zvol_tot)              ! Heat content drift    (C) 
+        CALL iom_put( 'bgsaline' , zdiff_sc1 / zvol_tot)              ! Salt content drift    (pss)
+        CALL iom_put( 'bgheatco' , zdiff_hc1 * 1.e-20 * rau0 * rcp )  ! Heat content drift    (1.e20 J) 
+        CALL iom_put( 'bgheatfx' , zdiff_hc1 * rau0 * rcp /  &        ! Heat flux drift       (W/m2) 
+           &                       ( surf_tot * kt * rdt )         )
+        CALL iom_put( 'bgsaltco' , zdiff_sc1 * 1.e-9    )             ! Salt content drift    (psu*km3)
+        CALL iom_put( 'bgvolssh' , zdiff_v1 * 1.e-9    )              ! volume ssh drift      (km3)  
         CALL iom_put( 'bgmistem' , zerr_hc1 / zvol_tot )              ! hc  - error due to free surface (C)
         CALL iom_put( 'bgmissal' , zerr_sc1 / zvol_tot )              ! sc  - error due to free surface (psu)
-      ELSE
-        CALL iom_put( 'bgtemper' , zdiff_hc / zvol_tot )              ! Temperature variation (C) 
-        CALL iom_put( 'bgsaline' , zdiff_sc / zvol_tot )              ! Salinity    variation (psu)
-        CALL iom_put( 'bgheatco' , zdiff_hc * 1.e-20 * rau0 * rcp )   ! Heat content variation (1.e20 J) 
-        CALL iom_put( 'bgsaltco' , zdiff_sc * 1.e-9    )              ! Salt content variation (psu*km3)
-        CALL iom_put( 'bgvolssh' , zdiff_v1 * 1.e-9    )              ! volume ssh variation (km3)  
-        CALL iom_put( 'bgvole3t' , zdiff_v2 * 1.e-9    )              ! volume e3t variation (km3)  
-        CALL iom_put( 'bgfrcvol' , frc_v    * 1.e-9    )              ! vol - surface forcing (km3) 
-        CALL iom_put( 'bgfrctem' , frc_t / zvol_tot    )              ! hc  - surface forcing (C) 
-        CALL iom_put( 'bgfrcsal' , frc_s / zvol_tot    )              ! sc  - surface forcing (psu) 
       ENDIF
       !
@@ -231,5 +237,5 @@
    SUBROUTINE dia_hsb_rst( kt, cdrw )
      !!---------------------------------------------------------------------
-     !!                   ***  ROUTINE limdia_rst  ***
+     !!                   ***  ROUTINE dia_hsb_rst  ***
      !!                     
      !! ** Purpose :   Read or write DIA file in restart file
@@ -241,10 +247,8 @@
      !
      INTEGER ::   ji, jj, jk   ! dummy loop indices
-     INTEGER ::   id1          ! local integers
      !!----------------------------------------------------------------------
      !
      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
         IF( ln_rstart ) THEN                   !* Read the restart file
-           !id1 = iom_varid( numror, 'frc_vol'  , ldstop = .FALSE. )
            !
            IF(lwp) WRITE(numout,*) '~~~~~~~'
@@ -259,11 +263,11 @@
            ENDIF
            CALL iom_get( numror, jpdom_autoglo, 'surf_ini', surf_ini ) ! ice sheet coupling
-           CALL iom_get( numror, jpdom_autoglo, 'ssh_ini', ssh_ini )
-           CALL iom_get( numror, jpdom_autoglo, 'e3t_ini', e3t_ini )
-           CALL iom_get( numror, jpdom_autoglo, 'hc_loc_ini', hc_loc_ini )
-           CALL iom_get( numror, jpdom_autoglo, 'sc_loc_ini', sc_loc_ini )
+           CALL iom_get( numror, jpdom_autoglo, 'ssh_ini', ssh_ini(:,:) )
+           CALL iom_get( numror, jpdom_autoglo, 'e3t_ini', e3t_ini(:,:,:) )
+           CALL iom_get( numror, jpdom_autoglo, 'hc_loc_ini', hc_loc_ini(:,:,:) )
+           CALL iom_get( numror, jpdom_autoglo, 'sc_loc_ini', sc_loc_ini(:,:,:) )
            IF( ln_linssh ) THEN
-              CALL iom_get( numror, jpdom_autoglo, 'ssh_hc_loc_ini', ssh_hc_loc_ini )
-              CALL iom_get( numror, jpdom_autoglo, 'ssh_sc_loc_ini', ssh_sc_loc_ini )
+              CALL iom_get( numror, jpdom_autoglo, 'ssh_hc_loc_ini', ssh_hc_loc_ini(:,:) )
+              CALL iom_get( numror, jpdom_autoglo, 'ssh_sc_loc_ini', ssh_sc_loc_ini(:,:) )
            ENDIF
        ELSE
@@ -313,11 +317,11 @@
         ENDIF
         CALL iom_rstput( kt, nitrst, numrow, 'surf_ini', surf_ini )      ! ice sheet coupling
-        CALL iom_rstput( kt, nitrst, numrow, 'ssh_ini', ssh_ini )
-        CALL iom_rstput( kt, nitrst, numrow, 'e3t_ini', e3t_ini )
-        CALL iom_rstput( kt, nitrst, numrow, 'hc_loc_ini', hc_loc_ini )
-        CALL iom_rstput( kt, nitrst, numrow, 'sc_loc_ini', sc_loc_ini )
+        CALL iom_rstput( kt, nitrst, numrow, 'ssh_ini', ssh_ini(:,:) )
+        CALL iom_rstput( kt, nitrst, numrow, 'e3t_ini', e3t_ini(:,:,:) )
+        CALL iom_rstput( kt, nitrst, numrow, 'hc_loc_ini', hc_loc_ini(:,:,:) )
+        CALL iom_rstput( kt, nitrst, numrow, 'sc_loc_ini', sc_loc_ini(:,:,:) )
         IF( ln_linssh ) THEN
-           CALL iom_rstput( kt, nitrst, numrow, 'ssh_hc_loc_ini', ssh_hc_loc_ini )
-           CALL iom_rstput( kt, nitrst, numrow, 'ssh_sc_loc_ini', ssh_sc_loc_ini )
+           CALL iom_rstput( kt, nitrst, numrow, 'ssh_hc_loc_ini', ssh_hc_loc_ini(:,:) )
+           CALL iom_rstput( kt, nitrst, numrow, 'ssh_sc_loc_ini', ssh_sc_loc_ini(:,:) )
         ENDIF
         !
@@ -339,5 +343,4 @@
       !!             - Compute coefficients for conversion
       !!---------------------------------------------------------------------------
-      INTEGER ::   jk       ! dummy loop indice
       INTEGER ::   ierror   ! local integer
       INTEGER ::   ios
@@ -345,10 +348,4 @@
       NAMELIST/namhsb/ ln_diahsb
       !!----------------------------------------------------------------------
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'dia_hsb_init : check the heat and salt budgets'
-         WRITE(numout,*) '~~~~~~~~ '
-      ENDIF
 
       REWIND( numnam_ref )              ! Namelist namhsb in reference namelist
@@ -361,14 +358,11 @@
       IF(lwm) WRITE ( numond, namhsb )
 
-      !
-      IF(lwp) THEN                   ! Control print
+      IF(lwp) THEN
          WRITE(numout,*)
-         WRITE(numout,*) 'dia_hsb_init : check the heat and salt budgets'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist namhsb : set hsb parameters'
-         WRITE(numout,*) '      Switch for hsb diagnostic (T) or not (F)  ln_diahsb  = ', ln_diahsb
-         WRITE(numout,*)
-      ENDIF
-
+         WRITE(numout,*) 'dia_hsb_init'
+         WRITE(numout,*) '~~~~~~~~ '
+         WRITE(numout,*) '  check the heat and salt budgets (T) or not (F)       ln_diahsb = ', ln_diahsb
+      ENDIF
+      !
       IF( .NOT. ln_diahsb )   RETURN
          !      IF( .NOT. lk_mpp_rep ) &
@@ -388,5 +382,5 @@
       IF( ln_linssh )   ALLOCATE( ssh_hc_loc_ini(jpi,jpj), ssh_sc_loc_ini(jpi,jpj),STAT=ierror )
       IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN
+         CALL ctl_stop( 'dia_hsb: unable to allocate ssh_hc_loc_ini' )   ;   RETURN
       ENDIF
 
@@ -394,8 +388,6 @@
       ! 2 - Time independant variables and file opening !
       ! ----------------------------------------------- !
-      IF(lwp) WRITE(numout,*) "dia_hsb: heat salt volume budgets activated"
-      IF(lwp) WRITE(numout,*) '~~~~~~~'
       surf(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)      ! masked surface grid cell area
-      surf_tot  = glob_sum( surf(:,:) )                                       ! total ocean surface area
+      surf_tot  = glob_sum( surf(:,:) )                   ! total ocean surface area
 
       IF( lk_bdy ) CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' )         
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 7309)
@@ -166,6 +166,6 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   e1e2f , r1_e1e2f                !: associated metrics at f-point
    !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ff                              !: coriolis factor                   [1/s]
-
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ff                              !: coriolis factor at F_point [1/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ff_t                            !: coriolis factor at T-point [1/s]
    !!----------------------------------------------------------------------
    !! vertical coordinate and scale factors
@@ -289,5 +289,5 @@
    !!----------------------------------------------------------------------
    !! NEMO/OPA 4.0 , NEMO Consortium (2011)
-   !! $Id$
+   !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -309,5 +309,5 @@
    INTEGER FUNCTION dom_oce_alloc()
       !!----------------------------------------------------------------------
-      INTEGER, DIMENSION(13) :: ierr
+      INTEGER, DIMENSION(12) :: ierr
       !!----------------------------------------------------------------------
       ierr(:) = 0
@@ -332,5 +332,5 @@
          &      e1e2v(jpi,jpj) , r1_e1e2v(jpi,jpj) , e1_e2v(jpi,jpj)                   ,     &
          &      e1e2f(jpi,jpj) , r1_e1e2f(jpi,jpj)                                     ,     &
-         &        ff (jpi,jpj)                                                         , STAT=ierr(3) )
+         &        ff (jpi,jpj) , ff_t    (jpi,jpj)                                     , STAT=ierr(3) )
          !
       ALLOCATE( gdept_0(jpi,jpj,jpk) , gdepw_0(jpi,jpj,jpk) , gde3w_0(jpi,jpj,jpk) ,     &
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 7309)
@@ -92,8 +92,8 @@
       IF( ln_sco )   CALL dom_stiff             ! Maximum stiffness ratio/hydrostatic consistency
       !
-      ht_0(:,:) = e3t_0(:,:,1) * tmask(:,:,1)   ! Reference ocean thickness
-      hu_0(:,:) = e3u_0(:,:,1) * umask(:,:,1)
-      hv_0(:,:) = e3v_0(:,:,1) * vmask(:,:,1)
-      DO jk = 2, jpk
+      ht_0(:,:) = 0._wp  ! Reference ocean thickness
+      hu_0(:,:) = 0._wp
+      hv_0(:,:) = 0._wp
+      DO jk = 1, jpk
          ht_0(:,:) = ht_0(:,:) + e3t_0(:,:,jk) * tmask(:,:,jk)
          hu_0(:,:) = hu_0(:,:) + e3u_0(:,:,jk) * umask(:,:,jk)
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/domcfg.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/domcfg.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/domcfg.F90	(revision 7309)
@@ -56,7 +56,8 @@
          IF( jperio == 5 )   WRITE(numout,*) '      jperio= 5, north fold with F-point pivot'
          IF( jperio == 6 )   WRITE(numout,*) '      jperio= 6, cyclic east-west and north fold with F-point pivot'
-      ENDIF
-      !
-      IF( jperio <  0 .OR. jperio > 6 )   CALL ctl_stop( 'jperio is out of range' )
+         IF( jperio == 7 )   WRITE(numout,*) '      jperio= 7, cyclic east-west and north-south'
+      ENDIF
+      !
+      IF( jperio <  0 .OR. jperio > 7 )   CALL ctl_stop( 'jperio is out of range' )
       !
       CALL dom_glo                   ! global domain versus zoom and/or local domain
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/domhgr.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/domhgr.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/domhgr.F90	(revision 7309)
@@ -38,5 +38,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -321,5 +321,75 @@
          e1v(:,:) =  ze1     ;      e2v(:,:) = ze1
          e1f(:,:) =  ze1     ;      e2f(:,:) = ze1
-         !
+
+      CASE ( 6 )                   ! clem: f-plane with irregular grid-spacing
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '          f-plane with irregular grid-spacing (+- 10%)'
+         IF(lwp) WRITE(numout,*) '          the max is given by ppe1_m and ppe2_m' 
+
+         ! Position coordinates (in kilometers)
+         !                          ==========
+         glam0 = 0._wp
+         gphi0 = 0._wp
+         
+#if defined key_agrif 
+         IF( .NOT. Agrif_Root() ) THEN
+            glam0  = Agrif_Parent(glam0) + (Agrif_ix())*Agrif_Parent(ppe1_m) * 1.e-5
+            gphi0  = Agrif_Parent(gphi0) + (Agrif_iy())*Agrif_Parent(ppe2_m) * 1.e-5
+            ppe1_m = Agrif_Parent(ppe1_m)/Agrif_Rhox()
+            ppe2_m = Agrif_Parent(ppe2_m)/Agrif_Rhoy()          
+         ENDIF
+#endif         
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zti = FLOAT( ji - 1 + nimpp - 1 )         ;   ztj = FLOAT( jj - 1 + njmpp - 1 )
+               zui = FLOAT( ji - 1 + nimpp - 1 ) + 0.5   ;   zuj = FLOAT( jj - 1 + njmpp - 1 )
+               zvi = FLOAT( ji - 1 + nimpp - 1 )         ;   zvj = FLOAT( jj - 1 + njmpp - 1 ) + 0.5
+               zfi = FLOAT( ji - 1 + nimpp - 1 ) + 0.5   ;   zfj = FLOAT( jj - 1 + njmpp - 1 ) + 0.5
+
+               glamt(ji,jj) = glam0 + ppe1_m * 1.e-5 * zti
+               glamu(ji,jj) = glam0 + ppe1_m * 1.e-5 * zui
+               glamv(ji,jj) = glam0 + ppe1_m * 1.e-5 * zvi
+               glamf(ji,jj) = glam0 + ppe1_m * 1.e-5 * zfi
+   
+               gphit(ji,jj) = gphi0 + ppe2_m * 1.e-5 * ztj
+               gphiu(ji,jj) = gphi0 + ppe2_m * 1.e-5 * zuj
+               gphiv(ji,jj) = gphi0 + ppe2_m * 1.e-5 * zvj
+               gphif(ji,jj) = gphi0 + ppe2_m * 1.e-5 * zfj
+            END DO
+         END DO
+         
+         ! Horizontal scale factors (in meters)
+         !                              ======
+!! ==> EITHER 1) variable scale factors
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               !!e1t(ji,jj) = ppe1_m * EXP( -0.8/REAL(jpiglo**2) * (mi0(ji)-REAL(jpiglo+1)*0.5)**2 )  ! gaussian shape
+               !!e2t(ji,jj) = ppe2_m * EXP( -0.8/REAL(jpjglo**2) * (mj0(jj)-REAL(jpjglo+1)*0.5)**2 )  ! gaussian shape
+               e1t(ji,jj) = ppe1_m * ( 1. -0.1 * ABS(REAL(mi0(ji))-REAL(jpiglo+1)*0.5) / (1.-REAL(jpiglo+1)*0.5) ) ! linear shape
+               e2t(ji,jj) = ppe2_m * ( 1. -0.1 * ABS(REAL(mj0(jj))-REAL(jpjglo+1)*0.5) / (1.-REAL(jpjglo+1)*0.5) ) ! linear shape
+            END DO
+         END DO
+#if defined key_agrif 
+         IF( .NOT. Agrif_Root() ) THEN ! only works if the zoom is positioned at the center of the parent grid
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  e1t(ji,jj) = ppe1_m * ( 1. -0.1 * ABS(REAL(mi0(ji))-REAL(jpiglo+1)*0.5) / (1.-REAL(jpiglo+1)*0.5)  &
+                     &                            * REAL(jpiglo) / REAL(Agrif_Parent(jpiglo) * Agrif_Rhox()) )       ! factor to match parent grid
+                  e2t(ji,jj) = ppe2_m * ( 1. -0.1 * ABS(REAL(mj0(jj))-REAL(jpjglo+1)*0.5) / (1.-REAL(jpjglo+1)*0.5)  &
+                     &                            * REAL(jpjglo) / REAL(Agrif_Parent(jpjglo) * Agrif_Rhoy()) )       ! factor to match parent grid
+               END DO
+            END DO
+         ENDIF
+#endif
+!! ==> OR 2) constant scale factors
+!!         e1t(:,:) = ppe1_m
+!!         e2t(:,:) = ppe2_m
+         
+         e1u(:,:) = e1t(:,:)      ;      e2u(:,:) = e2t(:,:)
+         e1v(:,:) = e1t(:,:)      ;      e2v(:,:) = e2t(:,:)
+         e1f(:,:) = e1t(:,:)      ;      e2f(:,:) = e2t(:,:)
+
       CASE DEFAULT
          WRITE(ctmp1,*) '          bad flag value for jphgr_msh = ', jphgr_msh
@@ -377,9 +447,11 @@
       CASE ( 0, 1, 4 )               ! mesh on the sphere
          !
-         ff(:,:) = 2. * omega * SIN( rad * gphif(:,:) ) 
+         ff  (:,:) = 2. * omega * SIN( rad * gphif(:,:) ) 
+         ff_t(:,:) = 2. * omega * SIN( rad * gphit(:,:) ) 
          !
       CASE ( 2 )                     ! f-plane at ppgphi0 
          !
-         ff(:,:) = 2. * omega * SIN( rad * ppgphi0 )
+         ff  (:,:) = 2. * omega * SIN( rad * ppgphi0 )
+         ff_t(:,:) = 2. * omega * SIN( rad * ppgphi0 )  ! clem: coriolis at T-point
          !
          IF(lwp) WRITE(numout,*) '          f-plane: Coriolis parameter = constant = ', ff(1,1)
@@ -399,5 +471,6 @@
          zf0     = 2. * omega * SIN( rad * zphi0 )                              ! compute f0 1st point south
          !
-         ff(:,:) = ( zf0  + zbeta * gphif(:,:) * 1.e+3 )                        ! f = f0 +beta* y ( y=0 at south)
+         ff  (:,:) = ( zf0  + zbeta * gphif(:,:) * 1.e+3 )                        ! f = f0 +beta* y ( y=0 at south)
+         ff_t(:,:) = ( zf0  + zbeta * gphit(:,:) * 1.e+3 )                        ! clem: coriolis at T-point
          !
          IF(lwp) THEN
@@ -420,5 +493,6 @@
          zf0   = 2. * omega * SIN( rad * zphi0 )                            ! compute f0 1st point south
          !
-         ff(:,:) = ( zf0 + zbeta * ABS( gphif(:,:) - zphi0 ) * rad * ra )   ! f = f0 +beta* y ( y=0 at south)
+         ff  (:,:) = ( zf0 + zbeta * ABS( gphif(:,:) - zphi0 ) * rad * ra )   ! f = f0 +beta* y ( y=0 at south)
+         ff_t(:,:) = ( zf0 + zbeta * ABS( gphit(:,:) - zphi0 ) * rad * ra )   ! clem: coriolis at T-point
          !
          IF(lwp) THEN
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 7309)
@@ -145,4 +145,21 @@
       ! Build the vertical coordinate system
       ! ------------------------------------
+#if defined key_sas2D
+      WRITE(numout,*) ' domzgr: we use SAS2D (i.e. no ocean) with jpk=',jpk
+      mbathy(:,:) = 1   ;   bathy(:,:) = rn_hmin
+
+      gdept_0 (:,:,:) = rn_hmin
+      gdepw_0 (:,:,:) = rn_hmin   ;   gdep3w_0(:,:,:) = rn_hmin
+      gdept_1d(:)     = rn_hmin   ;   gdepw_1d(:)     = rn_hmin
+
+      e3t_0 (:,:,:) = rn_hmin
+      e3u_0 (:,:,:) = rn_hmin   ;   e3v_0 (:,:,:) = rn_hmin
+      e3f_0 (:,:,:) = rn_hmin   ;   e3w_0 (:,:,:) = rn_hmin
+      e3uw_0(:,:,:) = rn_hmin   ;   e3vw_0(:,:,:) = rn_hmin
+      e3t_1d(:)     = rn_hmin   ;   e3w_1d(:)     = rn_hmin
+
+      mikt(:,:) = 1   ;   mikv(:,:) = 1
+      miku(:,:) = 1   ;   mikf(:,:) = 1
+#else
                           CALL zgr_z            ! Reference z-coordinate system (always called)
                           CALL zgr_bat          ! Bathymetry fields (levels and meters)
@@ -164,4 +181,6 @@
       END IF
       !
+#endif
+      
       IF( nprint == 1 .AND. lwp )   THEN
          WRITE(numout,*) ' MIN val mbathy  ', MINVAL(  mbathy(:,:) ), ' MAX ', MAXVAL( mbathy(:,:) )
@@ -476,4 +495,6 @@
             idta( 1    , :    ) = 0                 ;      zdta( 1    , :    ) =  0._wp
             idta(jpidta, :    ) = 0                 ;      zdta(jpidta, :    ) =  0._wp
+         ELSEIF( jperio == 7 ) THEN
+!           Nothing to do here
          ELSE
             ih = 0                                  ;      zh = 0._wp
@@ -738,8 +759,8 @@
          IF( lk_mpp ) THEN
             IF( nbondi == -1 .OR. nbondi == 2 ) THEN
-               IF( jperio /= 1 )   mbathy(1,:) = 0
+               IF( jperio /= 1 .AND. jperio /= 7 )   mbathy(1,:) = 0
             ENDIF
             IF( nbondi == 1 .OR. nbondi == 2 ) THEN
-               IF( jperio /= 1 )   mbathy(nlci,:) = 0
+               IF( jperio /= 1 .AND. jperio /= 7 )   mbathy(nlci,:) = 0
             ENDIF
          ELSE
@@ -756,4 +777,9 @@
          mbathy( 1 ,:) = mbathy(jpim1,:)
          mbathy(jpi,:) = mbathy(  2  ,:)
+         IF (jperio == 7) THEN
+            IF(lwp) WRITE(numout,*)' north south boundary conditions on mbathy: jperio = ', jperio
+            mbathy( : ,1) = mbathy(:, jpjm1)
+            mbathy(:, jpj)= mbathy(:,2)
+         ENDIF
       ELSEIF( nperio == 2 ) THEN
          IF(lwp) WRITE(numout,*) '   equatorial boundary conditions on mbathy: nperio = ', nperio
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 7309)
@@ -96,5 +96,5 @@
       CHARACTER(len=19) :: cldate 
       CHARACTER(len=10) :: clname
-      INTEGER           ::   ji
+      INTEGER           :: ji, jkmin
       !
       REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_bnds
@@ -169,13 +169,14 @@
 
       ! Add vertical grid bounds
+      jkmin = MIN(2,jpk)  ! in case jpk=1 (i.e. sas2D)
       z_bnds(:      ,1) = gdepw_1d(:)
-      z_bnds(1:jpkm1,2) = gdepw_1d(2:jpk)
+      z_bnds(1:jpkm1,2) = gdepw_1d(jkmin:jpk)
       z_bnds(jpk:   ,2) = gdepw_1d(jpk) + e3t_1d(jpk)
       CALL iom_set_axis_attr( "deptht", bounds=z_bnds )
       CALL iom_set_axis_attr( "depthu", bounds=z_bnds )
       CALL iom_set_axis_attr( "depthv", bounds=z_bnds )
-      z_bnds(:    ,2) = gdept_1d(:)
-      z_bnds(2:jpk,1) = gdept_1d(1:jpkm1)
-      z_bnds(1    ,1) = gdept_1d(1) - e3w_1d(1)
+      z_bnds(:        ,2) = gdept_1d(:)
+      z_bnds(jkmin:jpk,1) = gdept_1d(1:jpkm1)
+      z_bnds(1        ,1) = gdept_1d(1) - e3w_1d(1)
       CALL iom_set_axis_attr( "depthw", bounds=z_bnds )
 
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/IOM/iom_def.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/IOM/iom_def.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/IOM/iom_def.F90	(revision 7309)
@@ -39,6 +39,6 @@
    INTEGER, PARAMETER, PUBLIC ::   jp_i1    = 204      !: write INTEGER(1)
 
-   INTEGER, PARAMETER, PUBLIC ::   jpmax_files  = 100   !: maximum number of simultaneously opened file
-   INTEGER, PARAMETER, PUBLIC ::   jpmax_vars   = 600  !: maximum number of variables in one file
+   INTEGER, PARAMETER, PUBLIC ::   jpmax_files  = 100  !: maximum number of simultaneously opened file
+   INTEGER, PARAMETER, PUBLIC ::   jpmax_vars   = 1200 !: maximum number of variables in one file
    INTEGER, PARAMETER, PUBLIC ::   jpmax_dims   =  4   !: maximum number of dimensions for one variable
    INTEGER, PARAMETER, PUBLIC ::   jpmax_digits =  5   !: maximum number of digits for the cpu number in the file name
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 7309)
@@ -405,7 +405,12 @@
                                          ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
          ENDIF
-         !                                   ! North-South boundaries (always closed)
-         IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj,:) = zland       ! south except F-point
-                                      ptab(:,nlcj-jprecj+1:jpj   ,:) = zland       ! north
+                                          ! North-south cyclic
+         IF ( nbondj == 2 .AND. jperio == 7 )    THEN !* cyclic north south only with no mpp split in latitude
+            ptab(:,1 , :) = ptab(:, jpjm1,:)
+            ptab(:,jpj,:) = ptab(:,     2,:)
+         ELSE   !                                   ! North-South boundaries (closed)
+            IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj,:) = zland       ! south except F-point
+                                         ptab(:,nlcj-jprecj+1:jpj   ,:) = zland       ! north
+         ENDIF
          !
       ENDIF
@@ -608,9 +613,15 @@
                                                    pt2d_array(ii)%pt2d(nlci-jpreci+1 : jpi   ,:) = zland    ! north
             ENDIF
-            !                                   ! North-South boundaries (always closed)
+                                                ! Noth-South boundaries
+            IF ( nbondj == 2 .AND. jperio == 7 )    THEN !* cyclic north south
+               pt2d_array(ii)%pt2d(:, 1   ) =   pt2d_array(ii)%pt2d(:, jpjm1 )
+               pt2d_array(ii)%pt2d(:, jpj ) =   pt2d_array(ii)%pt2d(:, 2 )          
+            ELSE   !             
+               !                                   ! North-South boundaries (closed)
                IF( .NOT. type_array(ii) == 'F' )   pt2d_array(ii)%pt2d(:,             1:jprecj ) = zland    ! south except F-point
                                                    pt2d_array(ii)%pt2d(:, nlcj-jprecj+1:jpj    ) = zland    ! north
             !
-         ENDIF
+            ENDIF
+          ENDIF
       END DO
 
@@ -888,8 +899,13 @@
                                          pt2d(nlci-jpreci+1:jpi   ,:) = zland    ! north
          ENDIF
-         !                                   ! North-South boundaries (always closed)
+                                            ! North-South boudaries
+         IF ( nbondj == 2 .AND. jperio == 7 )    THEN !* cyclic north south
+            pt2d(:,  1 ) = pt2d(:,jpjm1)
+            pt2d(:, jpj) = pt2d(:,    2)
+         ELSE    
+         !                                   ! North-South boundaries (closed)
             IF( .NOT. cd_type == 'F' )   pt2d(:,     1       :jprecj) = zland    !south except F-point
                                          pt2d(:,nlcj-jprecj+1:jpj   ) = zland    ! north
-         !
+         ENDIF     
       ENDIF
 
@@ -1071,12 +1087,17 @@
                                        ptab2(nlci-jpreci+1:jpi   ,:,:) = 0.e0
       ENDIF
-
-
-      !                                      ! North-South boundaries
+                                            ! North-South boundaries
+      IF ( nbondj == 2 .AND. jperio == 7 )    THEN !* cyclic north south
+         ptab1(:,     1       ,:) = ptab1(: ,  jpjm1 , :)
+         ptab1(:,   jpj       ,:) = ptab1(: ,      2 , :)
+         ptab2(:,     1       ,:) = ptab2(: ,  jpjm1 , :)
+         ptab2(:,   jpj       ,:) = ptab2(: ,      2 , :)
+      ELSE     
+      !                                      ! North-South boundaries closed
       IF( .NOT. cd_type1 == 'F' )   ptab1(:,     1       :jprecj,:) = 0.e0    ! south except at F-point
       IF( .NOT. cd_type2 == 'F' )   ptab2(:,     1       :jprecj,:) = 0.e0
                                     ptab1(:,nlcj-jprecj+1:jpj   ,:) = 0.e0    ! north
                                     ptab2(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
-
+      ENDIF     
 
       ! 2. East and west directions exchange
@@ -1267,8 +1288,15 @@
       ! Order matters Here !!!!
       !
-      !                                      !* North-South boundaries (always colsed)
+                                           ! North-South cyclic
+      IF ( nbondj == 2 .AND. jperio == 7 )    THEN !* cyclic north south
+         pt2d(:, 1-jprj:  1     ) = pt2d ( :, jpjm1-jprj:jpjm1)
+         pt2d(:, jpj   :jpj+jprj) = pt2d ( :, 2         :2+jprj)
+      ELSE
+        
+      !                                      !* North-South boundaries (closed)
       IF( .NOT. cd_type == 'F' )   pt2d(:,  1-jprj   :  jprecj  ) = 0.e0    ! south except at F-point
                                    pt2d(:,nlcj-jprecj+1:jpj+jprj) = 0.e0    ! north
-
+      ENDIF
+                                
       !                                      ! East-West boundaries
       !                                           !* Cyclic east-west
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90	(revision 7309)
@@ -76,4 +76,6 @@
           &              'the domain is lay out for distributed memory computing! ' )
 
+      IF( jperio == 7 ) CALL ctl_stop( ' jperio = 7 needs distributed memory computing ',   &
+          &              ' with 1 process. Add key_mpp_mpi in the list of active cpp keys ' )
    END SUBROUTINE mpp_init
 
@@ -379,5 +381,5 @@
       ! w a r n i n g  narea (zone) /= nproc (processors)!
 
-      IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) THEN
+      IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 .OR. jperio == 7 ) THEN
          IF( jpni == 1 )THEN
             nbondi = 2
@@ -446,4 +448,6 @@
       ENDIF
 
+      IF( jperio == 7 .AND. ( jpni /= 1 .OR. jpnj /= 1 ) ) &
+         &                  CALL ctl_stop( ' mpp_init: error jperio = 7 works only with jpni = jpnj = 1' )
       IF( nperio == 1 .AND. jpni /= 1 ) CALL ctl_stop( ' mpp_init: error on cyclicity' )
 
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcana.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcana.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcana.F90	(revision 7309)
@@ -4,6 +4,7 @@
    !! Ocean forcing:  analytical momentum, heat and freshwater forcings
    !!=====================================================================
-   !! History :  3.0   ! 2006-06  (G. Madec)  Original code
-   !!            3.2   ! 2009-07  (G. Madec)  Style only
+   !! History :  3.0   ! 2006-06  (G. Madec)    Original code
+   !!            3.2   ! 2009-07  (G. Madec)    Style only
+   !!            3.7   ! 2016-10  (C. Rousset)  Add analytic for LIM3 (ana_ice)
    !!----------------------------------------------------------------------
 
@@ -15,4 +16,5 @@
    USE dom_oce         ! ocean space and time domain
    USE sbc_oce         ! Surface boundary condition: ocean fields
+   USE sbc_ice         ! Surface boundary condition: ice   fields
    USE phycst          ! physical constants
    USE in_out_manager  ! I/O manager
@@ -20,19 +22,36 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE lib_fortran
-
+   USE wrk_nemo
+#if defined key_lim3
+   USE ice, ONLY       : pfrld, a_i_b
+   USE limthd_dh       ! for CALL lim_thd_snwblow
+#endif
+   
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   sbc_ana    ! routine called in sbcmod module
-   PUBLIC   sbc_gyre   ! routine called in sbcmod module
+   PUBLIC   sbc_ana         ! routine called in sbcmod module
+   PUBLIC   sbc_gyre        ! routine called in sbcmod module
+#if defined key_lim3
+   PUBLIC   ana_ice_tau     ! routine called in sbc_ice_lim module
+   PUBLIC   ana_ice_flx     ! routine called in sbc_ice_lim module
+#endif
 
    !                       !!* Namelist namsbc_ana *
-   INTEGER  ::   nn_tau000  ! nb of time-step during which the surface stress
-   !                        ! increase from 0 to its nominal value 
-   REAL(wp) ::   rn_utau0   ! constant wind stress value in i-direction
-   REAL(wp) ::   rn_vtau0   ! constant wind stress value in j-direction
-   REAL(wp) ::   rn_qns0    ! non solar heat flux
-   REAL(wp) ::   rn_qsr0    !     solar heat flux
-   REAL(wp) ::   rn_emp0    ! net freshwater flux
+   ! --- oce variables --- !
+   INTEGER  ::   nn_tau000 ! nb of time-step during which the surface stress
+   !                       ! increase from 0 to its nominal value 
+   REAL(wp) ::   rn_utau0  ! constant wind stress value in i-direction
+   REAL(wp) ::   rn_vtau0  ! constant wind stress value in j-direction
+   REAL(wp) ::   rn_qns0   ! non solar heat flux
+   REAL(wp) ::   rn_qsr0   !     solar heat flux
+   REAL(wp) ::   rn_emp0   ! net freshwater flux
+   ! --- ice variables --- !
+   REAL(wp) ::   rn_iutau0 ! constant wind stress value in i-direction over ice
+   REAL(wp) ::   rn_ivtau0 ! constant wind stress value in j-direction over ice
+   REAL(wp) ::   rn_iqns0  ! non solar heat flux over ice
+   REAL(wp) ::   rn_iqsr0  !     solar heat flux over ice
+   REAL(wp) ::   rn_sprec0 ! snow precip
+   REAL(wp) ::   rn_ievap0 ! sublimation
    
    !! * Substitutions
@@ -68,5 +87,6 @@
       REAL(wp) ::   zcoef, zty, zmod      !   -      -
       !!
-      NAMELIST/namsbc_ana/ nn_tau000, rn_utau0, rn_vtau0, rn_qns0, rn_qsr0, rn_emp0
+      NAMELIST/namsbc_ana/ nn_tau000, rn_utau0, rn_vtau0, rn_qns0, rn_qsr0, rn_emp0,  &
+         &                 rn_iutau0, rn_ivtau0, rn_iqsr0, rn_iqns0, rn_sprec0, rn_ievap0
       !!---------------------------------------------------------------------
       !
@@ -85,10 +105,16 @@
          IF(lwp) WRITE(numout,*)' sbc_ana : Constant surface fluxes read in namsbc_ana namelist'
          IF(lwp) WRITE(numout,*)' ~~~~~~~ '
-         IF(lwp) WRITE(numout,*)'              spin up of the stress  nn_tau000 = ', nn_tau000, ' time-steps'
-         IF(lwp) WRITE(numout,*)'              constant i-stress      rn_utau0  = ', rn_utau0 , ' N/m2'
-         IF(lwp) WRITE(numout,*)'              constant j-stress      rn_vtau0  = ', rn_vtau0 , ' N/m2'
-         IF(lwp) WRITE(numout,*)'              non solar heat flux    rn_qns0   = ', rn_qns0  , ' W/m2'
-         IF(lwp) WRITE(numout,*)'              solar heat flux        rn_qsr0   = ', rn_qsr0  , ' W/m2'
-         IF(lwp) WRITE(numout,*)'              net heat flux          rn_emp0   = ', rn_emp0  , ' Kg/m2/s'
+         IF(lwp) WRITE(numout,*)'              spin up of the stress         nn_tau000 = ', nn_tau000 , ' time-steps'
+         IF(lwp) WRITE(numout,*)'              constant i-stress             rn_utau0  = ', rn_utau0  , ' N/m2'
+         IF(lwp) WRITE(numout,*)'              constant j-stress             rn_vtau0  = ', rn_vtau0  , ' N/m2'
+         IF(lwp) WRITE(numout,*)'              non solar heat flux           rn_qns0   = ', rn_qns0   , ' W/m2'
+         IF(lwp) WRITE(numout,*)'              solar heat flux               rn_qsr0   = ', rn_qsr0   , ' W/m2'
+         IF(lwp) WRITE(numout,*)'              net freshwater flux           rn_emp0   = ', rn_emp0   , ' Kg/m2/s'
+         IF(lwp) WRITE(numout,*)'              constant ice-atm stress       rn_iutau0 = ', rn_iutau0 , ' N/m2'
+         IF(lwp) WRITE(numout,*)'              constant ice-atm stress       rn_ivtau0 = ', rn_ivtau0 , ' N/m2'
+         IF(lwp) WRITE(numout,*)'              solar heat flux over ice      rn_iqsr0  = ', rn_iqsr0  , ' W/m2'
+         IF(lwp) WRITE(numout,*)'              non solar heat flux over ice  rn_iqns0  = ', rn_iqns0  , ' W/m2'
+         IF(lwp) WRITE(numout,*)'              snow precip                   rn_sprec0 = ', rn_sprec0 , ' Kg/m2/s'
+         IF(lwp) WRITE(numout,*)'              sublimation                   rn_ievap0 = ', rn_ievap0 , ' Kg/m2/s'
          !
          nn_tau000 = MAX( nn_tau000, 1 )     ! must be >= 1
@@ -132,5 +158,66 @@
    END SUBROUTINE sbc_ana
 
-
+#if defined key_lim3
+   SUBROUTINE ana_ice_tau
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE ana_ice_tau  ***
+      !!
+      !! ** Purpose :   provide the surface boundary (momentum) condition over sea-ice
+      !!---------------------------------------------------------------------
+      utau_ice(:,:) = rn_iutau0
+      vtau_ice(:,:) = rn_ivtau0
+     
+   END SUBROUTINE ana_ice_tau
+   
+   SUBROUTINE ana_ice_flx
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE ana_ice_flx  ***
+      !!
+      !! ** Purpose :   provide the surface boundary (flux) condition over sea-ice
+      !!---------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:), POINTER ::   zsnw       ! snw distribution after wind blowing
+      !!---------------------------------------------------------------------
+      CALL wrk_alloc( jpi,jpj, zsnw ) 
+
+      ! ocean variables (renaming)
+      emp_oce (:,:)   = rn_emp0
+      qsr_oce (:,:)   = rn_qsr0
+      qns_oce (:,:)   = rn_qns0
+      
+      ! ice variables
+      alb_ice (:,:,:) = 0.7_wp ! useless
+      qsr_ice (:,:,:) = rn_iqsr0
+      qns_ice (:,:,:) = rn_iqns0
+      sprecip (:,:)   = rn_sprec0
+      evap_ice(:,:,:) = rn_ievap0
+
+      ! ice variables deduced from above
+      zsnw(:,:) = 1._wp
+      !!CALL lim_thd_snwblow( pfrld, zsnw )  ! snow distribution over ice after wind blowing 
+      emp_ice  (:,:)   = SUM( a_i_b(:,:,:) * evap_ice(:,:,:), dim=3 ) - sprecip(:,:) * zsnw(:,:)
+      emp_oce  (:,:)   = emp_oce(:,:) - sprecip(:,:) * (1._wp - zsnw(:,:) )
+      qevap_ice(:,:,:) =   0._wp
+      qprec_ice(:,:)   =   rhosn * ( sst_m(:,:) * cpic - lfus ) * tmask(:,:,1) ! in J/m3
+      qemp_oce (:,:)   = - emp_oce(:,:) * sst_m(:,:) * rcp
+      qemp_ice (:,:)   =   sprecip(:,:) * zsnw * ( sst_m(:,:) * cpic - lfus ) * tmask(:,:,1) ! solid precip (only)
+
+      ! total fluxes
+      emp_tot (:,:) = emp_ice  + emp_oce 
+      qns_tot (:,:) = pfrld(:,:) * qns_oce(:,:) + SUM( a_i_b(:,:,:) * qns_ice(:,:,:), dim=3 ) + qemp_ice(:,:) + qemp_oce(:,:)
+      qsr_tot (:,:) = pfrld(:,:) * qsr_oce(:,:) + SUM( a_i_b(:,:,:) * qsr_ice(:,:,:), dim=3 )
+
+      !--------------------------------------------------------------------
+      ! FRACTIONs of net shortwave radiation which is not absorbed in the
+      ! thin surface layer and penetrates inside the ice cover
+      ! ( Maykut and Untersteiner, 1971 ; Ebert and Curry, 1993 )
+      fr1_i0(:,:) = ( 0.18 * ( 1.0 - cldf_ice ) + 0.35 * cldf_ice )
+      fr2_i0(:,:) = ( 0.82 * ( 1.0 - cldf_ice ) + 0.65 * cldf_ice )
+
+      CALL wrk_dealloc( jpi,jpj, zsnw ) 
+      
+   END SUBROUTINE ana_ice_flx
+#endif
+
+   
    SUBROUTINE sbc_gyre( kt )
       !!---------------------------------------------------------------------
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 7309)
@@ -16,4 +16,5 @@
    !!            3.4  !  2011-11  (C. Harris) Fill arrays required by CICE
    !!            3.7  !  2014-06  (L. Brodeau) simplification and optimization of CORE bulk
+   !!            4.0  !  2016-06  (C. Rousset) Add new param of drags with sea-ice (Lupkes at al 2012)
    !!----------------------------------------------------------------------
 
@@ -38,9 +39,9 @@
    USE lib_fortran    ! to use key_nosignedzero
 #if defined key_lim3
-   USE ice     , ONLY :   u_ice, v_ice, jpl, pfrld, a_i_b
+   USE ice, ONLY      : u_ice, v_ice, jpl, pfrld, a_i_b, at_i_b
    USE limthd_dh      ! for CALL lim_thd_snwblow
 #elif defined key_lim2
-   USE ice_2   , ONLY :   u_ice, v_ice
-   USE par_ice_2      ! LIM-2 parameters
+   USE ice_2, ONLY    : u_ice, v_ice
+   USE par_ice_2
 #endif
    !
@@ -61,5 +62,5 @@
    PUBLIC   blk_ice_core_flx     ! routine called in sbc_ice_lim module
 #endif
-   PUBLIC   turb_core_2z         ! routine calles in sbcblk_mfs module
+   PUBLIC   turb_core_2z         ! routine called in sbcblk_mfs module
 
    INTEGER , PARAMETER ::   jpfld   = 9           ! maximum number of files to read
@@ -77,11 +78,11 @@
 
    !                                             !!! CORE bulk parameters
-   REAL(wp), PARAMETER ::   rhoa =    1.22        ! air density
-   REAL(wp), PARAMETER ::   cpa  = 1000.5         ! specific heat of air
-   REAL(wp), PARAMETER ::   Lv   =    2.5e6       ! latent heat of vaporization
-   REAL(wp), PARAMETER ::   Ls   =    2.839e6     ! latent heat of sublimation
-   REAL(wp), PARAMETER ::   Stef =    5.67e-8     ! Stefan Boltzmann constant
-   REAL(wp), PARAMETER ::   Cice =    1.4e-3      ! iovi 1.63e-3     ! transfer coefficient over ice
-   REAL(wp), PARAMETER ::   albo =    0.066       ! ocean albedo assumed to be constant
+   REAL(wp), PARAMETER ::   rhoa   =    1.22        ! air density
+   REAL(wp), PARAMETER ::   cpa    = 1000.5         ! specific heat of air
+   REAL(wp), PARAMETER ::   Lv     =    2.5e6       ! latent heat of vaporization
+   REAL(wp), PARAMETER ::   Ls     =    2.839e6     ! latent heat of sublimation
+   REAL(wp), PARAMETER ::   Stef   =    5.67e-8     ! Stefan Boltzmann constant
+   REAL(wp), PARAMETER ::   Cd_ice =    1.4e-3      ! transfer coefficient over ice
+   REAL(wp), PARAMETER ::   albo   =    0.066       ! ocean albedo assumed to be constant
 
    !                        !!* Namelist namsbc_core : CORE bulk parameters
@@ -92,5 +93,9 @@
    REAL(wp) ::   rn_zqt      ! z(q,t) : height of humidity and temperature measurements
    REAL(wp) ::   rn_zu       ! z(u)   : height of wind measurements
-
+   LOGICAL  ::   ln_Cd_L12 = .FALSE. !  Modify the drag ice-atm and oce-atm depending on ice concentration (from Lupkes et al. JGR2012)
+
+   !
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   Cd_oce   ! air-ocean drag (clem)
+   
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
@@ -102,4 +107,15 @@
 CONTAINS
 
+   INTEGER FUNCTION sbc_blk_core_alloc()
+      !!-------------------------------------------------------------------
+      !!             ***  ROUTINE sbc_blk_core_alloc (clem) ***
+      !!-------------------------------------------------------------------
+      ALLOCATE( Cd_oce(jpi,jpj) , STAT=sbc_blk_core_alloc )
+      !
+      IF( lk_mpp                  )   CALL mpp_sum( sbc_blk_core_alloc )
+      IF( sbc_blk_core_alloc /= 0 )   CALL ctl_warn('sbc_blk_core_alloc: failed to allocate arrays')
+   END FUNCTION sbc_blk_core_alloc
+
+   
    SUBROUTINE sbc_blk_core( kt )
       !!---------------------------------------------------------------------
@@ -149,7 +165,7 @@
       TYPE(FLD_N) ::   sn_tdif                                 !   "                                 "
       NAMELIST/namsbc_core/ cn_dir , ln_taudif, rn_pfac, rn_efac, rn_vfac,  &
-         &                  sn_wndi, sn_wndj  , sn_humi, sn_qsr ,           &
-         &                  sn_qlw , sn_tair  , sn_prec, sn_snow,           &
-         &                  sn_tdif, rn_zqt   ,  rn_zu
+         &                  sn_wndi, sn_wndj, sn_humi  , sn_qsr ,           &
+         &                  sn_qlw , sn_tair, sn_prec  , sn_snow,           &
+         &                  sn_tdif, rn_zqt,  rn_zu    , ln_Cd_L12
       !!---------------------------------------------------------------------
       !
@@ -157,4 +173,7 @@
       IF( kt == nit000 ) THEN                   !  First call kt=nit000  !
          !                                      ! ====================== !
+         !
+         !                                      ! allocate sbc_blk_core array (clem)
+         IF( sbc_blk_core_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sbc_blk_core : unable to allocate standard arrays' )
          !
          REWIND( numnam_ref )              ! Namelist namsbc_core in reference namelist : CORE bulk parameters
@@ -321,4 +340,6 @@
          &               Cd, Ch, Ce, zt_zu, zq_zu )
     
+      Cd_oce(:,:) = Cd(:,:)  ! record value of pure ocean-atm. drag (clem)
+     
       ! ... tau module, i and j component
       DO jj = 1, jpj
@@ -439,14 +460,21 @@
       !!---------------------------------------------------------------------
       INTEGER  ::   ji, jj    ! dummy loop indices
-      REAL(wp) ::   zcoef_wnorm, zcoef_wnorm2
       REAL(wp) ::   zwnorm_f, zwndi_f , zwndj_f               ! relative wind module and components at F-point
       REAL(wp) ::             zwndi_t , zwndj_t               ! relative wind components at T-point
+      REAL(wp), DIMENSION(:,:), POINTER ::   Cd               ! transfer coefficient for momentum      (tau)
       !!---------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('blk_ice_core_tau')
       !
-      ! local scalars ( place there for vector optimisation purposes)
-      zcoef_wnorm  = rhoa * Cice
-      zcoef_wnorm2 = rhoa * Cice * 0.5
+      CALL wrk_alloc( jpi,jpj, Cd )
+
+      Cd(:,:) = Cd_ice
+      
+      ! Make ice-atm. drag dependent on ice concentration (see Lupkes et al. 2012) (clem)
+#if defined key_lim3
+      IF( ln_Cd_L12 ) THEN
+         CALL Cdn10_Lupkes2012( Cd ) ! calculate new drag from Lupkes(2012) equations
+      ENDIF
+#endif
 
 !!gm brutal....
@@ -469,5 +497,5 @@
                zwndj_f = 0.25 * (  sf(jp_wndj)%fnow(ji-1,jj  ,1) + sf(jp_wndj)%fnow(ji  ,jj  ,1)   &
                   &              + sf(jp_wndj)%fnow(ji-1,jj-1,1) + sf(jp_wndj)%fnow(ji  ,jj-1,1)  ) - rn_vfac * v_ice(ji,jj)
-               zwnorm_f = zcoef_wnorm * SQRT( zwndi_f * zwndi_f + zwndj_f * zwndj_f )
+               zwnorm_f = rhoa * Cd(ji,jj) * SQRT( zwndi_f * zwndi_f + zwndj_f * zwndj_f )
                ! ... ice stress at I-point
                utau_ice(ji,jj) = zwnorm_f * zwndi_f
@@ -478,5 +506,5 @@
                zwndj_t = sf(jp_wndj)%fnow(ji,jj,1) - rn_vfac * 0.25 * (  v_ice(ji,jj+1) + v_ice(ji+1,jj+1)   &
                   &                                                    + v_ice(ji,jj  ) + v_ice(ji+1,jj  )  )
-               wndm_ice(ji,jj)  = SQRT( zwndi_t * zwndi_t + zwndj_t * zwndj_t ) * tmask(ji,jj,1)
+               wndm_ice(ji,jj) = SQRT( zwndi_t * zwndi_t + zwndj_t * zwndj_t ) * tmask(ji,jj,1)
             END DO
          END DO
@@ -495,7 +523,7 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vect. opt.
-               utau_ice(ji,jj) = zcoef_wnorm2 * ( wndm_ice(ji+1,jj  ) + wndm_ice(ji,jj) )                          &
+               utau_ice(ji,jj) = rhoa * Cd(ji,jj) * 0.5_wp * ( wndm_ice(ji+1,jj  ) + wndm_ice(ji,jj) )                          &
                   &          * ( 0.5 * (sf(jp_wndi)%fnow(ji+1,jj,1) + sf(jp_wndi)%fnow(ji,jj,1) ) - rn_vfac * u_ice(ji,jj) )
-               vtau_ice(ji,jj) = zcoef_wnorm2 * ( wndm_ice(ji,jj+1  ) + wndm_ice(ji,jj) )                          &
+               vtau_ice(ji,jj) = rhoa * Cd(ji,jj) * 0.5_wp * ( wndm_ice(ji,jj+1  ) + wndm_ice(ji,jj) )                          &
                   &          * ( 0.5 * (sf(jp_wndj)%fnow(ji,jj+1,1) + sf(jp_wndj)%fnow(ji,jj,1) ) - rn_vfac * v_ice(ji,jj) )
             END DO
@@ -511,4 +539,6 @@
          CALL prt_ctl(tab2d_1=wndm_ice  , clinfo1=' blk_ice_core: wndm_ice : ')
       ENDIF
+
+      CALL wrk_dealloc( jpi,jpj, Cd )
 
       IF( nn_timing == 1 )  CALL timing_stop('blk_ice_core_tau')
@@ -542,4 +572,5 @@
       REAL(wp), DIMENSION(:,:,:), POINTER ::   z_dqsb            ! sensible  heat sensitivity over ice
       REAL(wp), DIMENSION(:,:)  , POINTER ::   zevap, zsnw       ! evaporation and snw distribution after wind blowing (LIM3)
+      REAL(wp), DIMENSION(:,:)  , POINTER ::   Cd                ! transfer coefficient for momentum      (tau)
       !!---------------------------------------------------------------------
       !
@@ -547,9 +578,19 @@
       !
       CALL wrk_alloc( jpi,jpj,jpl, z_qlw, z_qsb, z_dqlw, z_dqsb ) 
+      CALL wrk_alloc( jpi,jpj, Cd )
+
+      Cd(:,:) = Cd_ice
+
+      ! Make ice-atm. drag dependent on ice concentration (see Lupkes et al. 2012) (clem)
+#if defined key_lim3
+      IF( ln_Cd_L12 ) THEN
+         CALL Cdn10_Lupkes2012( Cd ) ! calculate new drag from Lupkes(2012) equations
+      ENDIF
+#endif
 
       ! local scalars ( place there for vector optimisation purposes)
       zcoef_dqlw   = 4.0 * 0.95 * Stef
-      zcoef_dqla   = -Ls * Cice * 11637800. * (-5897.8)
-      zcoef_dqsb   = rhoa * cpa * Cice
+      zcoef_dqla   = -Ls * 11637800. * (-5897.8)
+      zcoef_dqsb   = rhoa * cpa
 
       zztmp = 1. / ( 1. - albo )
@@ -577,11 +618,11 @@
                ! ... turbulent heat fluxes
                ! Sensible Heat
-               z_qsb(ji,jj,jl) = rhoa * cpa * Cice * wndm_ice(ji,jj) * ( ptsu(ji,jj,jl) - sf(jp_tair)%fnow(ji,jj,1) )
+               z_qsb(ji,jj,jl) = rhoa * cpa * Cd(ji,jj) * wndm_ice(ji,jj) * ( ptsu(ji,jj,jl) - sf(jp_tair)%fnow(ji,jj,1) )
                ! Latent Heat
-               qla_ice(ji,jj,jl) = rn_efac * MAX( 0.e0, rhoa * Ls  * Cice * wndm_ice(ji,jj)   &                           
+               qla_ice(ji,jj,jl) = rn_efac * MAX( 0.e0, rhoa * Ls  * Cd(ji,jj) * wndm_ice(ji,jj)   &                           
                   &                         * (  11637800. * EXP( -5897.8 / ptsu(ji,jj,jl) ) / rhoa - sf(jp_humi)%fnow(ji,jj,1)  ) )
               ! Latent heat sensitivity for ice (Dqla/Dt)
                IF( qla_ice(ji,jj,jl) > 0._wp ) THEN
-                  dqla_ice(ji,jj,jl) = rn_efac * zcoef_dqla * wndm_ice(ji,jj) / ( zst2 ) * EXP( -5897.8 / ptsu(ji,jj,jl) )
+                  dqla_ice(ji,jj,jl) = rn_efac * zcoef_dqla * Cd(ji,jj) * wndm_ice(ji,jj) / ( zst2 ) * EXP( -5897.8 / ptsu(ji,jj,jl) )
                ELSE
                   dqla_ice(ji,jj,jl) = 0._wp
@@ -589,5 +630,5 @@
 
                ! Sensible heat sensitivity (Dqsb_ice/Dtn_ice)
-               z_dqsb(ji,jj,jl) = zcoef_dqsb * wndm_ice(ji,jj)
+               z_dqsb(ji,jj,jl) = zcoef_dqsb * Cd(ji,jj) * wndm_ice(ji,jj)
 
                ! ----------------------------!
@@ -668,4 +709,5 @@
 
       CALL wrk_dealloc( jpi,jpj,jpl, z_qlw, z_qsb, z_dqlw, z_dqsb )
+      CALL wrk_dealloc( jpi,jpj, Cd )
       !
       IF( nn_timing == 1 )  CALL timing_stop('blk_ice_core_flx')
@@ -905,4 +947,57 @@
    END FUNCTION psi_h
 
+
+#if defined key_lim3
+   SUBROUTINE Cdn10_Lupkes2012( Cd )
+      !!----------------------------------------------------------------------
+      !!                      ***  ROUTINE  Cdn10_Lupkes2012  ***
+      !!
+      !! ** Purpose :    Recompute the ice-atm drag at 10m height to make
+      !!                 it dependent on edges at leads, melt ponds and flows.
+      !!                 After some approximations, this can be resumed to a dependency
+      !!                 on ice concentration.
+      !!                
+      !! ** Method :     The parameterization is taken from Lupkes et al. (2012) eq.(50)
+      !!                 with the highest level of approximation: level4, eq.(59)
+      !!                 The generic drag over a cell partly covered by ice can be re-written as follows:
+      !!
+      !!                 Cd = Cdw * (1-A) + Cdi * A + Ce * (1-A)**(nu+1/(10*beta)) * A**mu
+      !!
+      !!                    Ce = 2.23e-3       , as suggested by Lupkes (eq. 59)
+      !!                    nu = mu = beta = 1 , as suggested by Lupkes (eq. 59)
+      !!                    A is the concentration of ice minus melt ponds (if any)
+      !!
+      !!                 This new drag has a parabolic shape (as a function of A) starting at
+      !!                 Cdw(say 1.5e-3) for A=0, reaching 1.97e-3 for A~0.5 
+      !!                 and going down to Cdi(say 1.4e-3) for A=1
+      !!
+      !!                 It is theoretically applicable to all ice conditions (not only MIZ)
+      !!                 => see Lupkes et al (2013)
+      !!
+      !! ** References : Lupkes et al. JGR 2012 (theory)
+      !!                 Lupkes et al. GRL 2013 (application to GCM)
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   Cd
+      REAL(wp), PARAMETER ::   zCe   = 2.23e-03_wp
+      REAL(wp), PARAMETER ::   znu   = 1._wp
+      REAL(wp), PARAMETER ::   zmu   = 1._wp
+      REAL(wp), PARAMETER ::   zbeta = 1._wp
+      REAL(wp)            ::   zcoef
+      !!----------------------------------------------------------------------
+      zcoef = znu + 1._wp / ( 10._wp * zbeta )
+
+      ! generic drag over a cell partly covered by ice
+      !!Cd(:,:) = Cd_oce(:,:) * ( 1._wp - at_i_b(:,:) ) +  &                        ! pure ocean drag
+      !!   &      Cd_ice      *           at_i_b(:,:)   +  &                        ! pure ice drag
+      !!   &      zCe         * ( 1._wp - at_i_b(:,:) )**zcoef * at_i_b(:,:)**zmu   ! change due to sea-ice morphology
+
+      ! ice-atm drag
+      Cd(:,:) = Cd_ice +  &                                                          ! pure ice drag
+         &      zCe    * ( 1._wp - at_i_b(:,:) )**zcoef * at_i_b(:,:)**(zmu-1._wp)   ! change due to sea-ice morphology
+      
+   END SUBROUTINE Cdn10_Lupkes2012
+#endif
+   
    !!======================================================================
 END MODULE sbcblk_core
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 7309)
@@ -168,5 +168,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -1599,10 +1599,9 @@
       ENDIF
 
-      !! clem: we should output qemp_oce and qemp_ice (at least)
-      IF( iom_use('hflx_snow_cea') )   CALL iom_put( 'hflx_snow_cea', sprecip(:,:) * ( zcptn(:,:) - Lfus ) )   ! heat flux from snow (cell average)
-      !! these diags are not outputed yet
-!!      IF( iom_use('hflx_rain_cea') )   CALL iom_put( 'hflx_rain_cea', ( tprecip(:,:) - sprecip(:,:) ) * zcptn(:,:) )   ! heat flux from rain (cell average)
-!!      IF( iom_use('hflx_snow_ao_cea') ) CALL iom_put( 'hflx_snow_ao_cea', sprecip(:,:) * ( zcptn(:,:) - Lfus ) * (1._wp - zsnw(:,:)) ) ! heat flux from snow (cell average)
-!!      IF( iom_use('hflx_snow_ai_cea') ) CALL iom_put( 'hflx_snow_ai_cea', sprecip(:,:) * ( zcptn(:,:) - Lfus ) * zsnw(:,:) ) ! heat flux from snow (cell average)
+      ! some more outputs
+      IF( iom_use('hflx_snow_cea') )    CALL iom_put('hflx_snow_cea',   sprecip(:,:) * ( zcptn(:,:) - Lfus ) )                       ! heat flux from snow (cell average)
+      IF( iom_use('hflx_rain_cea') )    CALL iom_put('hflx_rain_cea', ( tprecip(:,:) - sprecip(:,:) ) * zcptn(:,:) )                 ! heat flux from rain (cell average)
+      IF( iom_use('hflx_snow_ao_cea') ) CALL iom_put('hflx_snow_ao_cea',sprecip(:,:) * ( zcptn(:,:) - Lfus ) * (1._wp - zsnw(:,:)) ) ! heat flux from snow (cell average)
+      IF( iom_use('hflx_snow_ai_cea') ) CALL iom_put('hflx_snow_ai_cea',sprecip(:,:) * ( zcptn(:,:) - Lfus ) * zsnw(:,:) )           ! heat flux from snow (cell average)
 
 #else
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 7309)
@@ -24,5 +24,4 @@
    USE ice             ! LIM-3: ice variables
    USE thd_ice         ! LIM-3: thermodynamical variables
-   USE dom_ice         ! LIM-3: ice domain
    !
    USE sbc_oce         ! Surface boundary condition: ocean fields
@@ -31,4 +30,5 @@
    USE sbcblk_clio     ! Surface boundary condition: CLIO bulk
    USE sbccpl          ! Surface boundary condition: coupled interface
+   USE sbcana          ! Surface boundary condition: analytic formulation
    USE albedo          ! ocean & ice albedo
    !
@@ -48,5 +48,4 @@
    USE limvar          ! Ice variables switch
    USE limctl          ! 
-   USE limmsh          ! LIM mesh
    USE limistate       ! LIM initial state
    USE limthd_sal      ! LIM ice thermodynamics: salinity
@@ -65,4 +64,9 @@
    USE bdyice_lim       ! unstructured open boundary data  (bdy_ice_lim routine)
 #endif
+# if defined key_agrif
+   USE agrif_ice
+   USE agrif_lim3_update
+   USE agrif_lim3_interp
+# endif
 
    IMPLICIT NONE
@@ -102,7 +106,7 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt      ! ocean time step
-      INTEGER, INTENT(in) ::   kblk    ! type of bulk (=3 CLIO, =4 CORE, =5 COUPLED)
-      !!
-      INTEGER  ::    jl                 ! dummy loop index
+      INTEGER, INTENT(in) ::   kblk    ! type of bulk (=1 ANALYTIC, =3 CLIO, =4 CORE, =5 COUPLED)
+      !!
+      INTEGER  ::   jl                 ! dummy loop index
       REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalb_os, zalb_cs  ! ice albedo under overcast/clear sky
       REAL(wp), POINTER, DIMENSION(:,:  )   ::   zutau_ice, zvtau_ice 
@@ -110,4 +114,11 @@
 
       IF( nn_timing == 1 )  CALL timing_start('sbc_ice_lim')
+
+      ! clem: it is important to initialize agrif_lim3 variables here and not in sbc_lim_init
+# if defined key_agrif
+      IF( kt == nit000 ) THEN
+         IF( .NOT. Agrif_Root() )   CALL Agrif_InitValues_cont_lim3
+      ENDIF
+# endif
 
       !-----------------------!
@@ -115,4 +126,8 @@
       !-----------------------!
       IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN
+
+# if defined key_agrif
+         IF( .NOT. Agrif_Root() )  lim_nbstep = MOD( lim_nbstep, Agrif_irhot() * Agrif_Parent(nn_fsbc) / nn_fsbc ) + 1
+# endif
 
          ! mean surface ocean current at ice velocity point (C-grid dynamics :  U- & V-points as the ocean)
@@ -136,12 +151,13 @@
          !-----------------------------------------------------------------
          SELECT CASE( kblk )
-         CASE( jp_clio    )   ;   CALL blk_ice_clio_tau                         ! CLIO bulk formulation            
-         CASE( jp_core    )   ;   CALL blk_ice_core_tau                         ! CORE bulk formulation
-         CASE( jp_purecpl )   ;   CALL sbc_cpl_ice_tau( utau_ice , vtau_ice )   ! Coupled   formulation
+            CASE( jp_ana     )   ;    CALL ana_ice_tau                              ! analytic formulation            
+            CASE( jp_clio    )   ;    CALL blk_ice_clio_tau                         ! CLIO bulk formulation            
+            CASE( jp_core    )   ;    CALL blk_ice_core_tau                         ! CORE bulk formulation
+            CASE( jp_purecpl )   ;    CALL sbc_cpl_ice_tau( utau_ice , vtau_ice )   ! Coupled   formulation
          END SELECT
          
-         IF( ln_mixcpl) THEN   ! Case of a mixed Bulk/Coupled formulation
+         IF( ln_mixcpl) THEN                                                       ! Case of a mixed Bulk/Coupled formulation
             CALL wrk_alloc( jpi,jpj    , zutau_ice, zvtau_ice)
-            CALL sbc_cpl_ice_tau( zutau_ice , zvtau_ice )
+                                      CALL sbc_cpl_ice_tau( zutau_ice , zvtau_ice )
             utau_ice(:,:) = utau_ice(:,:) * xcplmask(:,:,0) + zutau_ice(:,:) * ( 1. - xcplmask(:,:,0) )
             vtau_ice(:,:) = vtau_ice(:,:) * xcplmask(:,:,0) + zvtau_ice(:,:) * ( 1. - xcplmask(:,:,0) )
@@ -154,29 +170,37 @@
          numit = numit + nn_fsbc                  ! Ice model time step
          !                                                   
-         CALL sbc_lim_bef                         ! Store previous ice values
-         CALL sbc_lim_diag0                       ! set diag of mass, heat and salt fluxes to 0
-         CALL lim_rst_opn( kt )                   ! Open Ice restart file
-         !
-         IF( .NOT. lk_c1d ) THEN
+                                      CALL sbc_lim_bef         ! Store previous ice values
+                                      CALL sbc_lim_diag0       ! set diag of mass, heat and salt fluxes to 0
+                                      CALL lim_rst_opn( kt )   ! Open Ice restart file
+         !
+         ! --- zap this if no ice dynamics --- !
+         IF( .NOT. lk_c1d .AND. ln_limdyn ) THEN
             !
-            CALL lim_dyn( kt )                    ! Ice dynamics    ( rheology/dynamics )   
-            !
-            CALL lim_trp( kt )                    ! Ice transport   ( Advection/diffusion )
-            !
-            IF( nn_monocat /= 2 ) CALL lim_itd_me ! Mechanical redistribution ! (ridging/rafting)
-            !
-#if defined key_bdy
-            CALL bdy_ice_lim( kt )                ! bdy ice thermo 
-            IF( ln_icectl )       CALL lim_prt( kt, iiceprt, jiceprt, 1, ' - ice thermo bdy - ' )
-#endif
-            !
-            CALL lim_update1( kt )                ! Corrections
+            IF( nn_limdyn /= 0 ) THEN                          ! -- Ice dynamics
+                                      CALL lim_dyn( kt )       !     rheology  
+            ELSE
+               u_ice(:,:) = rn_uice * umask(:,:,1)             !     or prescribed velocity
+               v_ice(:,:) = rn_vice * vmask(:,:,1)
+            ENDIF
+                                      CALL lim_trp( kt )       ! -- Ice transport (Advection/diffusion)
+            IF( nn_limdyn == 2 .AND. nn_monocat /= 2 )  &      ! -- Mechanical redistribution (ridging/rafting)
+               &                      CALL lim_itd_me         
+            IF( nn_limdyn == 2 )      CALL lim_update1( kt )   ! -- Corrections
             !
          ENDIF
-         
+
+         ! ---
+#if defined key_agrif
+         IF( .NOT. Agrif_Root() )     CALL agrif_interp_lim3('T')
+#endif
+#if defined key_bdy
+         IF( ln_limthd )              CALL bdy_ice_lim( kt )   ! -- bdy ice thermo 
+#endif
+
          ! previous lead fraction and ice volume for flux calculations
-         CALL sbc_lim_bef                        
-         CALL lim_var_glo2eqv                     ! ht_i and ht_s for ice albedo calculation
-         CALL lim_var_agg(1)                      ! at_i for coupling (via pfrld) 
+                                      CALL sbc_lim_bef                        
+                                      CALL lim_var_glo2eqv     ! ht_i and ht_s for ice albedo calculation
+                                      CALL lim_var_agg(1)      ! at_i for coupling (via pfrld) 
+         !
          pfrld(:,:)   = 1._wp - at_i(:,:)
          phicif(:,:)  = vt_i(:,:)
@@ -193,25 +217,33 @@
          !----------------------------------------------------------------------------------------
          CALL wrk_alloc( jpi,jpj,jpl, zalb_os, zalb_cs )
-         CALL albedo_ice( t_su, ht_i, ht_s, zalb_cs, zalb_os ) ! cloud-sky and overcast-sky ice albedos
-
+         
+                                      CALL albedo_ice( t_su, ht_i, ht_s, zalb_cs, zalb_os ) ! cloud-sky and overcast-sky ice albedos
          SELECT CASE( kblk )
-         CASE( jp_clio )                                       ! CLIO bulk formulation
-            ! In CLIO the cloud fraction is read in the climatology and the all-sky albedo 
-            ! (alb_ice) is computed within the bulk routine
-                                 CALL blk_ice_clio_flx( t_su, zalb_cs, zalb_os, alb_ice )
-            IF( ln_mixcpl      ) CALL sbc_cpl_ice_flx( p_frld=pfrld, palbi=alb_ice, psst=sst_m, pist=t_su )
-            IF( nn_limflx /= 2 ) CALL ice_lim_flx( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_limflx )
-         CASE( jp_core )                                       ! CORE bulk formulation
-            ! albedo depends on cloud fraction because of non-linear spectral effects
-            alb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
-                                 CALL blk_ice_core_flx( t_su, alb_ice )
-            IF( ln_mixcpl      ) CALL sbc_cpl_ice_flx( p_frld=pfrld, palbi=alb_ice, psst=sst_m, pist=t_su )
-            IF( nn_limflx /= 2 ) CALL ice_lim_flx( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_limflx )
-         CASE ( jp_purecpl )
-            ! albedo depends on cloud fraction because of non-linear spectral effects
-            alb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
-                                 CALL sbc_cpl_ice_flx( p_frld=pfrld, palbi=alb_ice, psst=sst_m, pist=t_su )
-            IF( nn_limflx == 2 ) CALL ice_lim_flx( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_limflx )
+
+            CASE( jp_ana )                                        ! analytic formulation
+                                      CALL ana_ice_flx
+               
+            CASE( jp_clio )                                       ! CLIO bulk formulation
+               ! In CLIO the cloud fraction is read in the climatology and the all-sky albedo 
+               ! (alb_ice) is computed within the bulk routine
+                                      CALL blk_ice_clio_flx( t_su, zalb_cs, zalb_os, alb_ice )
+               IF( ln_mixcpl      )   CALL sbc_cpl_ice_flx( p_frld=pfrld, palbi=alb_ice, psst=sst_m, pist=t_su )
+               IF( nn_limflx /= 2 )   CALL ice_lim_flx( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_limflx )
+               
+            CASE( jp_core )                                       ! CORE bulk formulation
+               ! albedo depends on cloud fraction because of non-linear spectral effects
+               alb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
+                                      CALL blk_ice_core_flx( t_su, alb_ice )
+               IF( ln_mixcpl      )   CALL sbc_cpl_ice_flx( p_frld=pfrld, palbi=alb_ice, psst=sst_m, pist=t_su )
+               IF( nn_limflx /= 2 )   CALL ice_lim_flx( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_limflx )
+               
+            CASE ( jp_purecpl )                                    ! Coupled formulation
+               ! albedo depends on cloud fraction because of non-linear spectral effects
+               alb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
+                                      CALL sbc_cpl_ice_flx( p_frld=pfrld, palbi=alb_ice, psst=sst_m, pist=t_su )
+               IF( nn_limflx == 2 )   CALL ice_lim_flx( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_limflx )
+
          END SELECT
+
          CALL wrk_dealloc( jpi,jpj,jpl, zalb_os, zalb_cs )
 
@@ -219,20 +251,31 @@
          ! --- ice thermodynamics --- !
          !----------------------------!
-         CALL lim_thd( kt )                         ! Ice thermodynamics      
-         !
-         CALL lim_update2( kt )                     ! Corrections
-         !
-         CALL lim_sbc_flx( kt )                     ! Update surface ocean mass, heat and salt fluxes
-         !
-         IF(ln_limdiaout) CALL lim_diahsb           ! Diagnostics and outputs 
-         !
-         CALL lim_wri( 1 )                          ! Ice outputs 
+         ! --- zap this if no ice thermo --- !
+         IF( ln_limthd )              CALL lim_thd( kt )        ! -- Ice thermodynamics      
+         IF( ln_limthd )              CALL lim_update2( kt )    ! -- Corrections
+         ! ---
+# if defined key_agrif
+         IF( .NOT. Agrif_Root() )     CALL agrif_update_lim3( kt )
+# endif
+                                      CALL lim_var_glo2eqv      ! necessary calls (at least for coupling)
+                                      CALL lim_var_agg( 2 )     ! necessary calls (at least for coupling)
+                                      !
+# if defined key_agrif
+!!         IF( .NOT. Agrif_Root() )     CALL Agrif_ChildGrid_To_ParentGrid()  ! clem: should be called at the update frequency only (cf agrif_lim3_update)
+# endif
+                                      CALL lim_sbc_flx( kt )    ! -- Update surface ocean mass, heat and salt fluxes
+# if defined key_agrif
+!!         IF( .NOT. Agrif_Root() )     CALL Agrif_ParentGrid_To_ChildGrid()  ! clem: should be called at the update frequency only (cf agrif_lim3_update)
+# endif
+         IF( ln_limdiahsb )           CALL lim_diahsb( kt )     ! -- Diagnostics and outputs 
+         !
+                                      CALL lim_wri( 1 )         ! -- Ice outputs 
          !
          IF( kt == nit000 .AND. ln_rstart )   &
-            &             CALL iom_close( numrir )  ! close input ice restart file
-         !
-         IF( lrst_ice )   CALL lim_rst_write( kt )  ! Ice restart file 
-         !
-         IF( ln_icectl )  CALL lim_ctl( kt )        ! alerts in case of model crash
+            &                         CALL iom_close( numrir )  ! close input ice restart file
+         !
+         IF( lrst_ice )               CALL lim_rst_write( kt )  ! -- Ice restart file 
+         !
+         IF( ln_limctl )              CALL lim_ctl( kt )        ! alerts in case of model crash
          !
       ENDIF   ! End sea-ice time step only
@@ -242,5 +285,6 @@
       !-------------------------!
       ! Update surface ocean stresses (only in ice-dynamic case) otherwise the atm.-ocean stresses are used everywhere
-      IF( ln_limdyn )     CALL lim_sbc_tau( kt, ub(:,:,1), vb(:,:,1) )  ! using before instantaneous surf. currents
+      !    using before instantaneous surf. currents
+      IF( ln_limdyn )                 CALL lim_sbc_tau( kt, ub(:,:,1), vb(:,:,1) )
 !!gm   remark, the ocean-ice stress is not saved in ice diag call above .....  find a solution!!!
       !
@@ -259,5 +303,5 @@
       !!----------------------------------------------------------------------
       IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'sbc_ice_lim : update ocean surface boudary condition' 
+      IF(lwp) WRITE(numout,*) 'sbc_lim_init : update ocean surface boudary condition' 
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   via Louvain la Neuve Ice Model (LIM-3) time stepping'
       !
@@ -271,17 +315,12 @@
       !                                ! Allocate the ice arrays
       ierr =        ice_alloc        ()      ! ice variables
-      ierr = ierr + dom_ice_alloc    ()      ! domain
       ierr = ierr + sbc_ice_alloc    ()      ! surface forcing
       ierr = ierr + thd_ice_alloc    ()      ! thermodynamics
-      ierr = ierr + lim_itd_me_alloc ()      ! ice thickness distribution - mechanics
+      IF( ln_limdyn )   ierr = ierr + lim_itd_me_alloc ()      ! ice thickness distribution - mechanics
       !
       IF( lk_mpp    )   CALL mpp_sum( ierr )
       IF( ierr /= 0 )   CALL ctl_stop('STOP', 'sbc_lim_init : unable to allocate ice arrays')
       !
-      !                                ! adequation jpk versus ice/snow layers/categories
-      IF( jpl > jpk .OR. (nlay_i+1) > jpk .OR. nlay_s > jpk )   &
-         &      CALL ctl_stop( 'STOP',                          &
-         &     'sbc_lim_init: the 3rd dimension of workspace arrays is too small.',   &
-         &     'use more ocean levels or less ice/snow layers/categories.' )
+      CALL lim_dyn_init                ! set ice dynamics parameters
       !
       CALL lim_itd_init                ! ice thickness distribution initialization
@@ -293,7 +332,5 @@
       CALL lim_thd_sal_init            ! set ice salinity parameters
       !
-      CALL lim_msh                     ! ice mesh initialization
-      !
-      CALL lim_itd_me_init             ! ice thickness distribution initialization for mecanical deformation
+      IF( ln_limdyn )   CALL lim_itd_me_init             ! ice thickness distribution initialization for mecanical deformation
       !                                ! Initial sea-ice state
       IF( .NOT. ln_rstart ) THEN              ! start from rest: sea-ice deduced from sst
@@ -305,8 +342,10 @@
          numit = nit000 - 1
       ENDIF
-      CALL lim_var_agg(1)
+      CALL lim_var_agg(2)
       CALL lim_var_glo2eqv
       !
       CALL lim_sbc_init                 ! ice surface boundary condition   
+      !
+      IF( ln_limdiahsb) CALL lim_diahsb_init  ! initialization for diags
       !
       fr_i(:,:)     = at_i(:,:)         ! initialisation of sea-ice fraction
@@ -342,16 +381,26 @@
       !!-------------------------------------------------------------------
       INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicerun/ jpl, nlay_i, nlay_s, cn_icerst_in, cn_icerst_indir, cn_icerst_out, cn_icerst_outdir,  &
-         &                ln_limdyn, rn_amax_n, rn_amax_s, ln_limdiahsb, ln_limdiaout, ln_icectl, iiceprt, jiceprt  
+      NAMELIST/namicerun/ jpl, nlay_i, nlay_s, rn_amax_n, rn_amax_s, cn_icerst_in, cn_icerst_indir,   &
+         &                cn_icerst_out, cn_icerst_outdir, ln_limthd, ln_limdyn, nn_limdyn, rn_uice, rn_vice  
+      NAMELIST/namicediag/ ln_limdiachk, ln_limdiahsb, ln_limctl, iiceprt, jiceprt  
       !!-------------------------------------------------------------------
       !                    
       REWIND( numnam_ice_ref )              ! Namelist namicerun in reference namelist : Parameters for ice
       READ  ( numnam_ice_ref, namicerun, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namicerun in reference namelist', lwp )
-      !
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicerun in reference namelist', lwp )
+
       REWIND( numnam_ice_cfg )              ! Namelist namicerun in configuration namelist : Parameters for ice
       READ  ( numnam_ice_cfg, namicerun, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namicerun in configuration namelist', lwp )
-      IF(lwm) WRITE( numoni, namicerun )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicerun in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namicerun )
+      !
+      REWIND( numnam_ice_ref )              ! Namelist namicediag in reference namelist : Parameters for ice
+      READ  ( numnam_ice_ref, namicediag, IOSTAT = ios, ERR = 903)
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicediag in reference namelist', lwp )
+
+      REWIND( numnam_ice_cfg )              ! Namelist namicediag in configuration namelist : Parameters for ice
+      READ  ( numnam_ice_cfg, namicediag, IOSTAT = ios, ERR = 904 )
+904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicediag in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namicediag )
       !
       IF(lwp) THEN                        ! control print
@@ -362,16 +411,26 @@
          WRITE(numout,*) '   number of ice  layers                                   = ', nlay_i
          WRITE(numout,*) '   number of snow layers                                   = ', nlay_s
-         WRITE(numout,*) '   switch for ice dynamics (1) or not (0)      ln_limdyn   = ', ln_limdyn
          WRITE(numout,*) '   maximum ice concentration for NH                        = ', rn_amax_n 
          WRITE(numout,*) '   maximum ice concentration for SH                        = ', rn_amax_s
-         WRITE(numout,*) '   Diagnose heat/salt budget or not          ln_limdiahsb  = ', ln_limdiahsb
-         WRITE(numout,*) '   Output   heat/salt budget or not          ln_limdiaout  = ', ln_limdiaout
-         WRITE(numout,*) '   control prints in ocean.out for (i,j)=(iiceprt,jiceprt) = ', ln_icectl
-         WRITE(numout,*) '   i-index for control prints (ln_icectl=true)             = ', iiceprt
-         WRITE(numout,*) '   j-index for control prints (ln_icectl=true)             = ', jiceprt
+         WRITE(numout,*) '   Ice thermodynamics (T) or not (F)            ln_limthd  = ', ln_limthd
+         WRITE(numout,*) '   Ice dynamics       (T) or not (F)            ln_limdyn  = ', ln_limdyn
+         WRITE(numout,*) '     (ln_limdyn=T) Ice dynamics switch          nn_limdyn  = ', nn_limdyn
+         WRITE(numout,*) '       2: total'
+         WRITE(numout,*) '       1: advection only (no diffusion, no ridging/rafting)'
+         WRITE(numout,*) '       0: advection only (as 1 + prescribed velocity, bypass rheology)'
+         WRITE(numout,*) '     (ln_limdyn=T) prescribed u-vel (case nn_limdyn=0)     = ', rn_uice
+         WRITE(numout,*) '     (ln_limdyn=T) prescribed v-vel (case nn_limdyn=0)     = ', rn_vice
+         WRITE(numout,*)
+         WRITE(numout,*) '...and ice diagnostics'
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Diagnose online heat/mass/salt budget     ln_limdiachk  = ', ln_limdiachk
+         WRITE(numout,*) '   Output          heat/mass/salt budget     ln_limdiahsb  = ', ln_limdiahsb
+         WRITE(numout,*) '   control prints in ocean.out for (i,j)=(iiceprt,jiceprt) = ', ln_limctl
+         WRITE(numout,*) '   i-index for control prints (ln_limctl=true)             = ', iiceprt
+         WRITE(numout,*) '   j-index for control prints (ln_limctl=true)             = ', jiceprt
       ENDIF
       !
       ! sea-ice timestep and inverse
-      rdt_ice   = nn_fsbc * rdt  
+      rdt_ice   = REAL(nn_fsbc) * rdt  
       r1_rdtice = 1._wp / rdt_ice 
 
@@ -381,6 +440,8 @@
       !
 #if defined key_bdy
-      IF( lwp .AND. ln_limdiahsb )  CALL ctl_warn('online conservation check activated but it does not work with BDY')
+      IF( lwp .AND. ln_limdiachk )  CALL ctl_warn('online conservation check activated but it does not work with BDY')
 #endif
+      !
+      IF( lwp ) WRITE(numout,*) '   ice timestep rdt_ice  = ', rdt_ice
       !
    END SUBROUTINE ice_run
@@ -404,18 +465,18 @@
       !
       REWIND( numnam_ice_ref )              ! Namelist namiceitd in reference namelist : Parameters for ice
-      READ  ( numnam_ice_ref, namiceitd, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namiceitd in reference namelist', lwp )
-      !
+      READ  ( numnam_ice_ref, namiceitd, IOSTAT = ios, ERR = 905)
+905   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceitd in reference namelist', lwp )
+
       REWIND( numnam_ice_cfg )              ! Namelist namiceitd in configuration namelist : Parameters for ice
-      READ  ( numnam_ice_cfg, namiceitd, IOSTAT = ios, ERR = 904 )
-904   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namiceitd in configuration namelist', lwp )
-      IF(lwm) WRITE( numoni, namiceitd )
+      READ  ( numnam_ice_cfg, namiceitd, IOSTAT = ios, ERR = 906 )
+906   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceitd in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namiceitd )
       !
       IF(lwp) THEN                        ! control print
          WRITE(numout,*)
-         WRITE(numout,*) 'ice_itd : ice cat distribution'
-         WRITE(numout,*) ' ~~~~~~'
-         WRITE(numout,*) '   shape of ice categories distribution                     nn_catbnd = ', nn_catbnd
-         WRITE(numout,*) '   mean ice thickness in the domain (used if nn_catbnd=2)   rn_himean = ', rn_himean
+         WRITE(numout,*) 'lim_itd_init : Initialization of ice cat distribution '
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   shape of ice categories distribution                          nn_catbnd = ', nn_catbnd
+         WRITE(numout,*) '   mean ice thickness in the domain (only active if nn_catbnd=2) rn_himean = ', rn_himean
       ENDIF
       !
@@ -423,8 +484,4 @@
       !- Thickness categories boundaries 
       !----------------------------------
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'lim_itd_init : Initialization of ice cat distribution '
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
-      !
       hi_max(:) = 0._wp
       !
@@ -463,6 +520,5 @@
 
    
-   SUBROUTINE ice_lim_flx( ptn_ice , palb_ice, pqns_ice ,    &
-      &                    pqsr_ice, pdqn_ice, pevap_ice, pdevap_ice, k_limflx )
+   SUBROUTINE ice_lim_flx( ptn_ice, palb_ice, pqns_ice, pqsr_ice, pdqn_ice, pevap_ice, pdevap_ice, k_limflx )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE ice_lim_flx  ***
@@ -557,5 +613,6 @@
       u_ice_b(:,:)     = u_ice(:,:)
       v_ice_b(:,:)     = v_ice(:,:)
-      !      
+      at_i_b (:,:)     = SUM( a_i_b(:,:,:), dim=3 )
+      
    END SUBROUTINE sbc_lim_bef
 
@@ -569,5 +626,5 @@
       !!----------------------------------------------------------------------
       sfx    (:,:) = 0._wp   ;
-      sfx_bri(:,:) = 0._wp   ; 
+      sfx_bri(:,:) = 0._wp   ;   sfx_lam(:,:) = 0._wp
       sfx_sni(:,:) = 0._wp   ;   sfx_opw(:,:) = 0._wp
       sfx_bog(:,:) = 0._wp   ;   sfx_dyn(:,:) = 0._wp
@@ -580,6 +637,6 @@
       wfx_bom(:,:) = 0._wp   ;   wfx_sum(:,:) = 0._wp
       wfx_res(:,:) = 0._wp   ;   wfx_sub(:,:) = 0._wp
-      wfx_spr(:,:) = 0._wp   ;   
-      !
+      wfx_spr(:,:) = 0._wp   ;   wfx_lam(:,:) = 0._wp  
+      
       hfx_thd(:,:) = 0._wp   ;   
       hfx_snw(:,:) = 0._wp   ;   hfx_opw(:,:) = 0._wp
@@ -597,5 +654,7 @@
       diag_heat(:,:) = 0._wp ;   diag_smvi(:,:) = 0._wp ;
       diag_vice(:,:) = 0._wp ;   diag_vsnw(:,:) = 0._wp ;
-      !
+
+      tau_icebfr(:,:) = 0._wp; ! landfast ice param only (clem: important to keep the init here)
+      
    END SUBROUTINE sbc_lim_diag0
 
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 7309)
@@ -115,14 +115,18 @@
       !
       !                          ! overwrite namelist parameter using CPP key information
-      IF( Agrif_Root() ) THEN                ! AGRIF zoom
-        IF( lk_lim2 )   nn_ice      = 2
-        IF( lk_lim3 )   nn_ice      = 3
-        IF( lk_cice )   nn_ice      = 4
-      ENDIF
-      IF( cp_cfg == 'gyre' ) THEN            ! GYRE configuration
-          ln_ana      = .TRUE.   
-          nn_ice      =   0
-      ENDIF
-      !
+#if defined key_agrif
+      IF( Agrif_Root() ) THEN                ! AGRIF zoom (cf r1242: possibility to run without ice in fine grid)
+         IF( lk_lim2 )   nn_ice      = 2
+         IF( lk_lim3 )   nn_ice      = 3
+         IF( lk_cice )   nn_ice      = 4
+      ENDIF
+#else
+      IF( lk_lim2 )   nn_ice      = 2
+      IF( lk_lim3 )   nn_ice      = 3
+      IF( lk_cice )   nn_ice      = 4     
+#endif
+
+      IF( cp_cfg == 'gyre' )   ln_ana = .TRUE.          ! GYRE configuration
+             
       IF(lwp) THEN               ! Control print
          WRITE(numout,*) '        Namelist namsbc (partly overwritten with CPP key setting)'
@@ -200,6 +204,4 @@
 
       !                                            ! restartability   
-      IF( ( nn_ice == 2 .OR. nn_ice ==3 ) .AND. .NOT.( ln_blk_clio .OR. ln_blk_core .OR. ln_cpl ) )   &
-         &   CALL ctl_stop( 'LIM sea-ice model requires a bulk formulation or coupled configuration' )
       IF( nn_ice == 4 .AND. .NOT.( ln_blk_core .OR. ln_cpl ) )   &
          &   CALL ctl_stop( 'CICE sea-ice model requires ln_blk_core or ln_cpl' )
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 7309)
@@ -205,5 +205,5 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1
-               IF( fsdept(ji,jj,jk) < ekm_dep(ji,jj) ) THEN
+               IF( gdept_n(ji,jj,jk) < ekm_dep(ji,jj) ) THEN
                   avmv(ji,jj,jk) = MAX( avmv(ji,jj,jk), rn_wvmix )
                   avmu(ji,jj,jk) = MAX( avmu(ji,jj,jk), rn_wvmix )
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/lib_fortran.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/lib_fortran.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/lib_fortran.F90	(revision 7309)
@@ -25,5 +25,5 @@
 
    PUBLIC   glob_sum      ! used in many places (masked with tmask_i)
-   PUBLIC   glob_sum_full ! used in many places (masked with tmask_h, ie omly over the halos)
+   PUBLIC   glob_sum_full ! used in many places (masked with tmask_h, ie only over the halos)
    PUBLIC   DDPDD         ! also used in closea module
    PUBLIC   glob_min, glob_max
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 7309)
@@ -104,5 +104,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2016)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -141,5 +141,8 @@
 # endif
 # if defined key_lim2
-      CALL Agrif_Declare_Var_lim2  !  "      "   "   "      "  LIM
+      CALL Agrif_Declare_Var_lim2  !  "      "   "   "      "  LIM2
+# endif
+# if defined key_lim3
+      CALL Agrif_Declare_Var_lim3  !  "      "   "   "      "  LIM3
 # endif
 #endif
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 7309)
@@ -295,4 +295,5 @@
       IF(.NOT.ln_linssh) CALL dom_vvl_sf_swp( kstp )  ! swap of vertical scale factors
       !
+      IF( ln_diahsb        )   CALL dia_hsb( kstp )         ! - ML - global conservation diagnostics
 
 !!gm : This does not only concern the dynamics ==>>> add a new title
@@ -316,5 +317,4 @@
       ENDIF
 #endif
-      IF( ln_diahsb  )   CALL dia_hsb( kstp )         ! - ML - global conservation diagnostics
       IF( ln_diaobs  )   CALL dia_obs( kstp )         ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
 
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/SAS_SRC/daymod.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/SAS_SRC/daymod.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/SAS_SRC/daymod.F90	(revision 7309)
@@ -268,5 +268,9 @@
 
       ! since we no longer call rst_opn, need to define nitrst here, used by ice restart routine
-      IF( kt == nit000 ) nitrst = nitend
+      IF( kt == nit000 )  THEN
+         nitrst = nitend
+         lrst_oce = .FALSE.  ! init restart ocean (done in rst_opn when not SAS)
+      ENDIF
+
       IF( MOD( kt - 1, nstock ) == 0 ) THEN
          ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 7309)
@@ -49,7 +49,5 @@
    USE step            ! NEMO time-stepping                 (stp     routine)
    USE lib_mpp         ! distributed memory computing
-#if defined key_nosignedzero
    USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
-#endif
 #if defined key_iomput
    USE xios
@@ -58,11 +56,11 @@
    USE sbcssm
    USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
+   USE icbini          ! handle bergs, initialisation
    USE icbstp          ! handle bergs, calving, themodynamics and transport
-#if defined key_bdy
+
    USE bdyini          ! open boundary cond. setting       (bdy_init routine). clem: mandatory for LIM3
-   USE bdydta          ! open boundary cond. setting   (bdy_dta_init routine). clem: mandatory for LIM3
-#endif
+   USE bdydta          ! open boundary cond. setting   (bdy_dta_init routine)           - -
    USE bdy_par
-
+   
    IMPLICIT NONE
    PRIVATE
@@ -98,7 +96,7 @@
       !
 #if defined key_agrif
-      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
-#endif
-
+     CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
+#endif
+      
       !                            !-----------------------!
       CALL nemo_init               !==  Initialisations  ==!
@@ -113,4 +111,7 @@
       CALL Agrif_Declare_Var_lim2  !  "      "   "   "      "  LIM
 # endif
+# if defined key_lim3
+      CALL Agrif_Declare_Var_lim3  !  "      "   "   "      "  LIM3
+# endif
 #endif
       ! check that all process are still there... If some process have an error,
@@ -124,8 +125,12 @@
       !                            !-----------------------!
       istp = nit000
+
+#if defined key_agrif
+          CALL Agrif_Regrid()
+#endif
         
       DO WHILE ( istp <= nitend .AND. nstop == 0 )
 #if defined key_agrif
-         CALL Agrif_Step( stp )           ! AGRIF: time stepping
+         CALL stp                         ! AGRIF: time stepping
 #else
          CALL stp( istp )                 ! standard time stepping
@@ -148,7 +153,9 @@
       !
 #if defined key_agrif
-      CALL Agrif_ParentGrid_To_ChildGrid()
-      IF( nn_timing == 1 )   CALL timing_finalize
-      CALL Agrif_ChildGrid_To_ParentGrid()
+      IF( .NOT. Agrif_Root() ) THEN
+         CALL Agrif_ParentGrid_To_ChildGrid()
+         IF( nn_timing == 1 )   CALL timing_finalize
+         CALL Agrif_ChildGrid_To_ParentGrid()
+      ENDIF
 #endif
       IF( nn_timing == 1 )   CALL timing_finalize
@@ -287,5 +294,5 @@
          jpnij = jpni*jpnj
 #endif
-      END IF
+      ENDIF
 
       ! Calculate domain dimensions given calculated jpni and jpnj
@@ -301,8 +308,21 @@
 #endif
       ENDIF
-         jpk = jpkdta                                             ! third dim
+#if defined key_sas2D
+         jpk = 1                                             ! third dim
+         jpkm1 = 1                                           !   "           "
+#else
+         jpk = jpkdta                                        ! third dim
+         jpkm1 = jpk-1                                       !   "           "
+#endif
+#if defined key_agrif
+         ! simple trick to use same vertical grid as parent
+         ! but different number of levels: 
+         ! Save maximum number of levels in jpkdta, then define all vertical grids
+         ! with this number.
+         ! Suppress once vertical online interpolation is ok
+         IF(.NOT.Agrif_Root()) jpkdta = Agrif_Parent(jpkdta)
+#endif
          jpim1 = jpi-1                                            ! inner domain indices
          jpjm1 = jpj-1                                            !   "           "
-         jpkm1 = jpk-1                                            !   "           "
          jpij  = jpi*jpj                                          !  jpi x j
 
@@ -330,6 +350,5 @@
       ENDIF
 
-      ! Now we know the dimensions of the grid and numout has been set we can 
-      ! allocate arrays
+      ! Now we know the dimensions of the grid and numout has been set we can allocate arrays
       CALL nemo_alloc()
 
@@ -353,11 +372,11 @@
                             CALL dom_init   ! Domain
 
-      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
-
-      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
+     IF( ln_nnogather )     CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
+
+      IF( ln_ctl      )     CALL prt_ctl_init   ! Print control
                             CALL day_init   ! model calendar (using both namelist and restart infos)
 
                             CALL sbc_init   ! Forcings : surface module 
-                            
+
       ! ==> clem: open boundaries init. is mandatory for LIM3 because ice BDY is not decoupled from  
       !           the environment of ocean BDY. Therefore bdy is called in both OPA and SAS modules. 
@@ -366,4 +385,5 @@
       IF( lk_bdy        )   CALL bdy_dta_init
       ! ==>
+                            CALL icb_init( rdt, nit000)   ! initialise icebergs instance
       
       IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
@@ -514,38 +534,17 @@
       USE diawri    , ONLY: dia_wri_alloc
       USE dom_oce   , ONLY: dom_oce_alloc
+      USE oce 
 #if defined key_bdy   
       USE bdy_oce   , ONLY: bdy_oce_alloc
-      USE oce         ! clem: mandatory for LIM3 because needed for bdy arrays
-#else
-      USE oce       , ONLY : sshn, sshb, snwice_mass, snwice_mass_b, snwice_fmass
-#endif
-      !
-      INTEGER :: ierr,ierr1,ierr2,ierr3,ierr4,ierr5,ierr6,ierr7,ierr8
-      INTEGER :: jpm
+#endif
+      !
+      INTEGER :: ierr
       !!----------------------------------------------------------------------
       !
       ierr =        dia_wri_alloc   ()
       ierr = ierr + dom_oce_alloc   ()          ! ocean domain
+      ierr = ierr + oce_alloc       ()          ! (tsn...) needed for agrif and/or lim3 and bdy
 #if defined key_bdy
       ierr = ierr + bdy_oce_alloc   ()          ! bdy masks (incl. initialization)
-      ierr = ierr + oce_alloc       ()          ! (tsn...)
-#endif
-
-#if ! defined key_bdy
-       ALLOCATE( snwice_mass(jpi,jpj)  , snwice_mass_b(jpi,jpj),             &
-         &      snwice_fmass(jpi,jpj)  , STAT= ierr1 )
-      !
-      ! lim code currently uses surface temperature and salinity in tsn array for initialisation
-      ! and ub, vb arrays in ice dynamics, so allocate enough of arrays to use
-      ! clem: should not be needed. To be checked out
-      jpm = MAX(jp_tem, jp_sal)
-      ALLOCATE( tsn(jpi,jpj,1,jpm)  , STAT=ierr2 )
-      ALLOCATE( ub(jpi,jpj,1)       , STAT=ierr3 )
-      ALLOCATE( vb(jpi,jpj,1)       , STAT=ierr4 )
-      ALLOCATE( tsb(jpi,jpj,1,jpm)  , STAT=ierr5 )
-      ALLOCATE( sshn(jpi,jpj)       , STAT=ierr6 )
-      ALLOCATE( un(jpi,jpj,1)       , STAT=ierr7 )
-      ALLOCATE( vn(jpi,jpj,1)       , STAT=ierr8 )
-      ierr = ierr + ierr1 + ierr2 + ierr3 + ierr4 + ierr5 + ierr6 + ierr7 + ierr8
 #endif
       !
@@ -618,10 +617,9 @@
       INTEGER :: ifac, jl, inu
       INTEGER, PARAMETER :: ntest = 14
-      INTEGER :: ilfax(ntest)
+      INTEGER, DIMENSION(ntest) :: ilfax
+      !!----------------------------------------------------------------------
       !
       ! lfax contains the set of allowed factors.
-      data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
-         &                            128,   64,   32,   16,    8,   4,   2  /
-      !!----------------------------------------------------------------------
+      ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
 
       ! Clear the error flag and initialise output vars
@@ -721,5 +719,5 @@
                    nsndto = nsndto + 1
                    isendto(nsndto) = jn
-                END IF
+                ENDIF
           END DO
           nfsloop = 1
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90	(revision 7309)
@@ -39,4 +39,5 @@
    LOGICAL              ::   ln_3d_uve     !: specify whether input velocity data is 3D
    LOGICAL              ::   ln_read_frq   !: specify whether we must read frq or not
+   LOGICAL              ::   l_sasread     !: Ice intilisation: read a file (.TRUE.) or anaytical initilaistion in namelist &namsbc_sas
    LOGICAL              ::   l_initdone = .false.
    INTEGER     ::   nfld_3d
@@ -81,23 +82,38 @@
       !
       IF( nn_timing == 1 )  CALL timing_start( 'sbc_ssm')
-
-      IF( nfld_3d > 0 ) CALL fld_read( kt, 1, sf_ssm_3d )      !==   read data at kt time step   ==!
-      IF( nfld_2d > 0 ) CALL fld_read( kt, 1, sf_ssm_2d )      !==   read data at kt time step   ==!
-      ! 
-      IF( ln_3d_uve ) THEN
-         ssu_m(:,:) = sf_ssm_3d(jf_usp)%fnow(:,:,1) * umask(:,:,1)    ! u-velocity
-         ssv_m(:,:) = sf_ssm_3d(jf_vsp)%fnow(:,:,1) * vmask(:,:,1)    ! v-velocity 
-         IF( .NOT.ln_linssh )   e3t_m(:,:) = sf_ssm_3d(jf_e3t)%fnow(:,:,1) * tmask(:,:,1)    ! v-velocity 
+     
+      IF ( l_sasread ) THEN
+         IF( nfld_3d > 0 ) CALL fld_read( kt, 1, sf_ssm_3d )      !==   read data at kt time step   ==!
+         IF( nfld_2d > 0 ) CALL fld_read( kt, 1, sf_ssm_2d )      !==   read data at kt time step   ==!
+         ! 
+         IF( ln_3d_uve ) THEN
+            IF( .NOT. ln_linssh )   e3t_m(:,:) = sf_ssm_3d(jf_e3t)%fnow(:,:,1) * tmask(:,:,1)    ! v-velocity 
+                                    ssu_m(:,:) = sf_ssm_3d(jf_usp)%fnow(:,:,1) * umask(:,:,1)    ! u-velocity
+                                    ssv_m(:,:) = sf_ssm_3d(jf_vsp)%fnow(:,:,1) * vmask(:,:,1)    ! v-velocity 
+         ELSE
+            IF( .NOT. ln_linssh )   e3t_m(:,:) = sf_ssm_2d(jf_e3t)%fnow(:,:,1) * tmask(:,:,1)    ! v-velocity 
+                                    ssu_m(:,:) = sf_ssm_2d(jf_usp)%fnow(:,:,1) * umask(:,:,1)    ! u-velocity
+                                    ssv_m(:,:) = sf_ssm_2d(jf_vsp)%fnow(:,:,1) * vmask(:,:,1)    ! v-velocity 
+         ENDIF
+         !
+         sst_m(:,:) = sf_ssm_2d(jf_tem)%fnow(:,:,1) * tmask(:,:,1)    ! temperature
+         sss_m(:,:) = sf_ssm_2d(jf_sal)%fnow(:,:,1) * tmask(:,:,1)    ! salinity
+         ssh_m(:,:) = sf_ssm_2d(jf_ssh)%fnow(:,:,1) * tmask(:,:,1)    ! sea surface height
+         IF( ln_read_frq ) THEN
+            frq_m(:,:) = sf_ssm_2d(jf_frq)%fnow(:,:,1) * tmask(:,:,1) ! solar penetration
+         ELSE
+            frq_m(:,:) = 1._wp
+         ENDIF
       ELSE
-         ssu_m(:,:) = sf_ssm_2d(jf_usp)%fnow(:,:,1) * umask(:,:,1)    ! u-velocity
-         ssv_m(:,:) = sf_ssm_2d(jf_vsp)%fnow(:,:,1) * vmask(:,:,1)    ! v-velocity 
-         IF( .NOT.ln_linssh )   e3t_m(:,:) = sf_ssm_2d(jf_e3t)%fnow(:,:,1) * tmask(:,:,1)    ! v-velocity 
-      ENDIF
-      !
-      sst_m(:,:) = sf_ssm_2d(jf_tem)%fnow(:,:,1) * tmask(:,:,1)    ! temperature
-      sss_m(:,:) = sf_ssm_2d(jf_sal)%fnow(:,:,1) * tmask(:,:,1)    ! salinity
-      ssh_m(:,:) = sf_ssm_2d(jf_ssh)%fnow(:,:,1) * tmask(:,:,1)    ! sea surface height
-      IF( ln_read_frq )   frq_m(:,:) = sf_ssm_2d(jf_frq)%fnow(:,:,1) * tmask(:,:,1)    ! sea surface height
-      !
+         sst_m(:,:) = 0._wp
+         sss_m(:,:) = 0._wp
+         ssu_m(:,:) = 0._wp
+         ssv_m(:,:) = 0._wp
+         ssh_m(:,:) = 0._wp
+         e3t_m(:,:) = e3t_0(:,:,1) !clem: necessary at least for sas2D
+         frq_m(:,:) = 1._wp        !              - -
+         sshn (:,:) = 0._wp        !              - -
+      ENDIF
+      
       IF ( nn_ice == 1 ) THEN
          tsn(:,:,1,jp_tem) = sst_m(:,:)
@@ -108,5 +124,5 @@
       ub (:,:,1) = ssu_m(:,:)
       vb (:,:,1) = ssv_m(:,:)
-
+ 
       IF(ln_ctl) THEN                  ! print control
          CALL prt_ctl(tab2d_1=sst_m, clinfo1=' sst_m   - : ', mask1=tmask, ovlap=1   )
@@ -155,5 +171,5 @@
       TYPE(FLD_N) :: sn_ssh, sn_e3t, sn_frq
       !
-      NAMELIST/namsbc_sas/cn_dir, ln_3d_uve, ln_read_frq, sn_tem, sn_sal, sn_usp, sn_vsp, sn_ssh, sn_e3t, sn_frq
+      NAMELIST/namsbc_sas/l_sasread, cn_dir, ln_3d_uve, ln_read_frq, sn_tem, sn_sal, sn_usp, sn_vsp, sn_ssh, sn_e3t, sn_frq
       !!----------------------------------------------------------------------
       
@@ -176,4 +192,5 @@
          WRITE(numout,*) '~~~~~~~~~~~ '
          WRITE(numout,*) '   Namelist namsbc_sas'
+         WRITE(numout,*) '      Initialisation using an input file  = ',l_sasread 
          WRITE(numout,*) '      Are we supplying a 3D u,v and e3 field                             ln_3d_uve   = ', ln_3d_uve
          WRITE(numout,*) '      Are we reading frq (fraction of qsr absorbed in the 1st T level)   ln_read_frq = ', ln_read_frq
@@ -204,4 +221,5 @@
          nn_closea = 0
       ENDIF
+      IF (l_sasread) THEN
       ! 
       !! following code is a bit messy, but distinguishes between when u,v are 3d arrays and
@@ -285,4 +303,6 @@
       IF( nfld_2d > 0 ) DEALLOCATE( slf_2d, STAT=ierr )
 
+   ENDIF
+ 
       CALL sbc_ssm( nit000 )   ! need to define ss?_m arrays used in limistate
       IF( .NOT. ln_read_frq )   frq_m(:,:) = 1.
Index: branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/SAS_SRC/step.F90
===================================================================
--- branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/SAS_SRC/step.F90	(revision 7308)
+++ branches/2016/dev_CNRS_AGRIF_2016/NEMOGCM/NEMO/SAS_SRC/step.F90	(revision 7309)
@@ -24,7 +24,5 @@
    USE diawri           ! Standard run outputs             (dia_wri routine)
    USE bdy_par          ! clem: mandatory for LIM3
-#if defined key_bdy
    USE bdydta           ! clem: mandatory for LIM3
-#endif
    USE stpctl           ! time stepping control            (stp_ctl routine)
    !
@@ -38,4 +36,8 @@
 #endif
 
+#if defined key_agrif
+   USE agrif_oce, ONLY: lk_agrif_debug  !clem
+#endif
+   
    IMPLICIT NONE
    PRIVATE
@@ -70,8 +72,17 @@
 #if defined key_agrif
       kstp = nit000 + Agrif_Nb_Step()
+      IF ( lk_agrif_debug ) THEN
+         IF ( Agrif_Root() .and. lwp) Write(*,*) '---'
+         IF (lwp) Write(*,*) 'Grid Number',Agrif_Fixed(),' time step ',kstp, 'int tstep',Agrif_NbStepint()
+      ENDIF
+
+      IF ( kstp == (nit000 + 1) ) lk_agrif_fstep = .FALSE.
+
 # if defined key_iomput
       IF( Agrif_Nbstepint() == 0 )   CALL iom_swap( cxios_context )
 # endif   
 #endif   
+                             indic = 0                    ! although indic is not changed in stp_ctl
+                                                          ! need to keep the same interface 
       IF( kstp == nit000 )   CALL iom_init( cxios_context ) ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
       IF( kstp /= nit000 )   CALL day( kstp )             ! Calendar (day was already called at nit000 in day_init)
@@ -90,7 +101,21 @@
                              CALL dia_wri( kstp )         ! ocean model: outputs
 
-                             indic = 0                    ! although indic is not changed in stp_ctl
-                                                          ! need to keep the same interface 
+#if defined key_agrif
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! AGRIF
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<      
+                             CALL Agrif_Integrate_ChildGrids( stp )  
+#endif
+                             
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Control
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                              CALL stp_ctl( kstp, indic )
+      IF( indic < 0  )  THEN
+                             CALL ctl_stop( 'step: indic < 0' )
+                             CALL dia_wri_state( 'output.abort', kstp )
+      ENDIF
+      IF( kstp == nit000   ) CALL iom_close( numror )     ! close input  ocean restart file (clem: not sure...)
+      
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Coupled mode
