Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/DOC/NEMO_book.tex
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/DOC/NEMO_book.tex	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/DOC/NEMO_book.tex	(revision 4921)
@@ -215,6 +215,6 @@
 %\date{\today}
 \date{
-January 2012  \\
-{\small  -- version 3.4 --} \\
+November 2014  \\
+{\small  -- version 3.6 --} \\
 ~  \\
 \textit{\small Note du P\^ole de mod\'{e}lisation de l'Institut Pierre-Simon Laplace No 27 }\\
@@ -227,5 +227,5 @@
 \Large Gurvan Madec, and the NEMO team  \\
  \texttt{\small gurvan.madec@locean-ipsl.umpc.fr} \\
- \texttt{\small nemo\_st@hermes.locean-ipsl.umpc.fr} \\
+ \texttt{\small nemo\_st@locean-ipsl.umpc.fr} \\
 %{\small Laboratoire d'Oc\'{e}anographie  et du Climat: Exp\'{e}rimentation et Approches Num\'{e}riques }
 }
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/DOC/TexFiles/Chapters/Chap_SBC.tex
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/DOC/TexFiles/Chapters/Chap_SBC.tex	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/DOC/TexFiles/Chapters/Chap_SBC.tex	(revision 4921)
@@ -348,6 +348,6 @@
 horizontal and vertical dimensions of the associated variable and should 
 be equal to 1 over land and 0 elsewhere.
-The procedure can be recursively applied setting nn_lsm > 1 in namsbc namelist. 
-Note that nn_lsm=0 forces the code to not apply the procedure even if a file for land/sea mask is supplied.
+The procedure can be recursively applied setting nn\_lsm > 1 in namsbc namelist. 
+Note that nn\_lsm=0 forces the code to not apply the procedure even if a file for land/sea mask is supplied.
 
 \subsubsection{Bilinear Interpolation}
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/DOC/TexFiles/Chapters/Introduction.tex
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/DOC/TexFiles/Chapters/Introduction.tex	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/DOC/TexFiles/Chapters/Introduction.tex	(revision 4921)
@@ -19,5 +19,5 @@
 the model design. More specific information about running the model on different 
 computers, or how to set up a configuration, are found on the \NEMO web site 
-(www.locean-ipsl.upmc.fr/NEMO). 
+(www.nemo-ocean.eu). 
 
 The ocean component of \NEMO has been developed from the OPA model, 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-PW6_calypso.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-PW6_calypso.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-PW6_calypso.fcm	(revision 4921)
@@ -17,4 +17,5 @@
 %NCDF_INC            -I/usr/local/netcdf-3.6.3/include
 %NCDF_LIB            -L/usr/local/netcdf-3.6.3/lib -lnetcdf
+%CPP                 cpp
 %FC                  mpxlf90_r
 %FCFLAGS             -O3 -qsuffix=f=f90  -qstrict -qalias=intptr -qsuppress=1501-245 -qarch=pwr6 -q64 -qrealsize=8 -qtune=pwr6 -qextname -qlargepage -qmaxmem=-1
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-PW6_calypso_debug.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-PW6_calypso_debug.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-PW6_calypso_debug.fcm	(revision 4921)
@@ -17,4 +17,5 @@
 %NCDF_INC            -I/usr/local/netcdf-3.6.3/include
 %NCDF_LIB            -L/usr/local/netcdf-3.6.3/lib -lnetcdf
+%CPP                 cpp
 %FC                  mpxlf90_r
 %FCFLAGS             -g -qsuffix=f=f90  -qstrict -qalias=intptr -qsuppress=1501-245 -qarch=pwr6 -q64 -qrealsize=8 -qtune=pwr6 -qextname -qlargepage -qmaxmem=-1
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-PW6_calypso_tools.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-PW6_calypso_tools.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-PW6_calypso_tools.fcm	(revision 4921)
@@ -17,4 +17,5 @@
 %NCDF_INC            -I/usr/local/netcdf-3.6.3/include
 %NCDF_LIB            -L/usr/local/netcdf-3.6.3/lib -lnetcdf
+%CPP                 cpp
 %FC                  xlf90
 %FCFLAGS             -O3 -qsuffix=f=f90  -qstrict -qsuppress=1501-245 -qarch=pwr6 -q64 -qrealsize=8 -qtune=pwr6 -qextname -qlargepage -qmaxmem=-1
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-gfortran_athena_xios.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-gfortran_athena_xios.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-gfortran_athena_xios.fcm	(revision 4921)
@@ -44,4 +44,5 @@
 %XIOS_LIB            -L%XIOS_HOME/lib -lxios
 
+%CPP                 cpp
 %FC                  mpif90
 %FCFLAGS             -fdefault-real-8 -fno-second-underscore -Dgfortran -ffree-line-length-none
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-ifort_athena.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-ifort_athena.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-ifort_athena.fcm	(revision 4921)
@@ -17,4 +17,5 @@
 %NCDF_INC -I$NETCDF/include
 %NCDF_LIB -L$NETCDF/lib -lnetcdf -lnetcdff
+%CPP                 cpp
 %FC mpiifort
 %FCFLAGS -r8 -O3 -xHost -fp-model source -traceback
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-ifort_athena_debug.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-ifort_athena_debug.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-ifort_athena_debug.fcm	(revision 4921)
@@ -17,4 +17,5 @@
 %NCDF_INC -I$NETCDF/include
 %NCDF_LIB -L$NETCDF/lib -lnetcdf -lnetcdff
+%CPP                 cpp
 %FC mpiifort
 %FCFLAGS -fpe0 -g -r8 -O1 -xHost -fp-model source -traceback
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-ifort_athena_tools.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-ifort_athena_tools.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-ifort_athena_tools.fcm	(revision 4921)
@@ -17,4 +17,5 @@
 %NCDF_INC -I$NETCDF/include
 %NCDF_LIB -L$NETCDF/lib -lnetcdf -lnetcdff
+%CPP                 cpp
 %FC ifort
 %FCFLAGS -r8 -O3 -xHost -fp-model source -traceback
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-ifort_athena_xios.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-ifort_athena_xios.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/CMCC/arch-ifort_athena_xios.fcm	(revision 4921)
@@ -41,4 +41,5 @@
 %XIOS_INC            -I/users/home/ans040/SOFTWARE/XIOS_athena/trunk/inc
 %XIOS_LIB            -L/users/home/ans040/SOFTWARE/XIOS_athena/trunk/lib -lxios
+%CPP                 cpp
 %FC                  mpiifort
 %FCFLAGS 	     -g -r8 -O3 -xHost -fp-model source -traceback
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/INGV/arch-IBM_EKMAN_INGV.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/INGV/arch-IBM_EKMAN_INGV.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/INGV/arch-IBM_EKMAN_INGV.fcm	(revision 4921)
@@ -20,4 +20,5 @@
 %XIOS_ROOT           /home/delrosso/XIOS_447/trunk
 %MPI_INTEL           -I/srv/intel/impi/4.1.0.024/include
+%CPP                 cpp
 %FC                  mpiifort
 %FCFLAGS             -r8 -O3 -g -traceback 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-ALTIX_NAUTILUS_MPT.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-ALTIX_NAUTILUS_MPT.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-ALTIX_NAUTILUS_MPT.fcm	(revision 4921)
@@ -42,4 +42,5 @@
 %OASIS_LIB           -L%OASIS_HOME/lib -lpsmile.MPI1 -lmct -lmpeu -lscrip
 
+%CPP	             cpp
 %FC                  ifort
 %FCFLAGS             -r8 -O3 -fp-model precise -xT -ip -vec-report0
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-PW7_C2A_XIO.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-PW7_C2A_XIO.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-PW7_C2A_XIO.fcm	(revision 4921)
@@ -35,4 +35,6 @@
 
 %XLF90_LIB           -lxlf90_r
+
+%CPP	             cpp
 %FC                  mpxlf90_r
 %FCFLAGS             -qsuffix=f=f90 -qsuffix=cpp=F90 -qfree=f90 -O3 -qrealsize=8 -qarch=auto -qtune=auto -qinitauto
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-PW7_METO.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-PW7_METO.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-PW7_METO.fcm	(revision 4921)
@@ -21,7 +21,8 @@
 %XIOS_INC            -I/data/nwp/ofrd/share/NEMO/xios_lib/seq/xios_r451/inc
 %XIOS_LIB            -L/data/nwp/ofrd/share/NEMO/xios_lib/seq/xios_r451/lib -lxios
+%CPP	             cpp
 %FC                  mpxlf90_r
 %FCFLAGS             -qrealsize=8 -qextname -qsuffix=f=f90 -qarch=pwr7 -qtune=pwr7 -g -O2 -qstrict -qinitauto=7FBFFFFF
-%FFLAGS              -qrealsize=8 -qextname -qsuffix=f=f90 -qarch=pwr7 -qtune=pwr7 -g -O2 -qstrict -qinitauto=7FBFFFFF
+%FFLAGS              -qrealsize=8 -qextname -qarch=pwr7 -qtune=pwr7 -g -O2 -qstrict -qinitauto=7FBFFFFF -qfixed
 %LD                  mpCC_r
 %LDFLAGS             -lxlf90 -L/projects/um1/lib -lsig -O2 -L MASS
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-X64_CURIE.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-X64_CURIE.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-X64_CURIE.fcm	(revision 4921)
@@ -41,4 +41,5 @@
 %OASIS_LIB           -L%OASIS_HOME/lib -lpsmile.MPI1 -lmct -lmpeu -lscrip
 
+%CPP	             cpp
 %FC                  mpif90 -c -cpp
 # for Curie Fat Node
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-X64_MOBILIS.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-X64_MOBILIS.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-X64_MOBILIS.fcm	(revision 4921)
@@ -46,4 +46,5 @@
 %OASIS_LIB           
 
+%CPP	             cpp
 %FC                  mpif90 -c -cpp
 %FCFLAGS             -i4 -r8 -O3 -fp-model source -xAVX
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-X64_VAYU.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-X64_VAYU.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-X64_VAYU.fcm	(revision 4921)
@@ -41,4 +41,5 @@
 %OASIS_LIB           -L%OASIS_HOME/lib -lpsmile.MPI1 -lmct -lmpeu -lscrip
 
+%CPP	             cpp
 %FC                  mpif90 -c -cpp
 %FCFLAGS             -i4 -r8
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-X64_YELLOWSTONE.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-X64_YELLOWSTONE.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-X64_YELLOWSTONE.fcm	(revision 4921)
@@ -41,4 +41,5 @@
 %OASIS_LIB           -L%OASIS_HOME/lib -lpsmile.MPI1 -lmct -lmpeu -lscrip
 
+%CPP	             cpp
 %FC                  mpif90 -c -cpp
 %FCFLAGS            -i4 -r8 -O3 -fp-model precise -xAVX
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-XC_ARCHER.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-XC_ARCHER.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-XC_ARCHER.fcm	(revision 4921)
@@ -41,4 +41,5 @@
 #OASIS_LIB           -L%OASIS_HOME/lib -lpsmile.MPI1 -lmct -lmpeu -lscrip
 
+%CPP	             cpp
 %FC                  ftn
 #FCFLAGS             -em -s integer32 -s real64 -O3
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-XC_ARCHER_INTEL.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-XC_ARCHER_INTEL.fcm	(revision 4921)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-XC_ARCHER_INTEL.fcm	(revision 4921)
@@ -0,0 +1,56 @@
+# compiler options for Archer CRAY XC-30 (using intel compiler)
+#
+# NCDF_HOME   root directory containing lib and include subdirectories for netcdf4
+# HDF5_HOME   root directory containing lib and include subdirectories for HDF5
+# XIOS_HOME   root directory containing lib for XIOS
+# OASIS_HOME  root directory containing lib for OASIS
+#
+# NCDF_INC    netcdf4 include file
+# NCDF_LIB    netcdf4 library
+# XIOS_INC    xios include file    (taken into accound only if key_iomput is activated)
+# XIOS_LIB    xios library         (taken into accound only if key_iomput is activated)
+# OASIS_INC   oasis include file   (taken into accound only if key_oasis3 is activated)
+# OASIS_LIB   oasis library        (taken into accound only if key_oasis3 is activated)
+#
+# FC          Fortran compiler command
+# FCFLAGS     Fortran compiler flags
+# FFLAGS      Fortran 77 compiler flags
+# LD          linker
+# LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries
+# FPPFLAGS    pre-processing flags
+# AR          assembler
+# ARFLAGS     assembler flags
+# MK          make
+# USER_INC    complete list of include files
+# USER_LIB    complete list of libraries to pass to the linker
+#
+# Note that:
+#  - unix variables "$..." are accpeted and will be evaluated before calling fcm.
+#  - fcm variables are starting with a % (and not a $)
+#
+%NCDF_HOME           $NETCDF_DIR
+%HDF5_HOME           $HDF5_DIR
+%XIOS_HOME           /work/n01/n01/acc/XIOS_r484
+#OASIS_HOME          
+
+%NCDF_INC            -I%NCDF_HOME/include -I%HDF5_HOME/include
+%NCDF_LIB            -L%HDF5_HOME/lib -L%NCDF_HOME/lib -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz
+%XIOS_INC            -I%XIOS_HOME/inc 
+%XIOS_LIB            -L%XIOS_HOME/lib -lxios
+#OASIS_INC           -I%OASIS_HOME/build/lib/mct -I%OASIS_HOME/build/lib/psmile.MPI1
+#OASIS_LIB           -L%OASIS_HOME/lib -lpsmile.MPI1 -lmct -lmpeu -lscrip
+
+%CPP	             cpp
+%FC                  ftn
+%FCFLAGS             -integer-size 32 -real-size 64 -O3 -fp-model source -zero -fpp -warn all
+%FFLAGS              -integer-size 32 -real-size 64 -O3 -fp-model source -zero -fpp -warn all
+%LD                  CC -Wl,"--allow-multiple-definition"
+%FPPFLAGS            -P -C -traditional
+%LDFLAGS
+%AR                  ar 
+%ARFLAGS             -r
+%MK                  gmake
+%USER_INC            %XIOS_INC %NCDF_INC
+%USER_LIB            %XIOS_LIB %NCDF_LIB
+#USER_INC            %XIOS_INC %OASIS_INC %NCDF_INC
+#USER_LIB            %XIOS_LIB %OASIS_LIB %NCDF_LIB
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-macport_osx.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-macport_osx.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-macport_osx.fcm	(revision 4921)
@@ -50,4 +50,5 @@
 %OASIS_LIB           -L%OASIS_HOME/lib -lpsmile.MPI1 -lmct -lmpeu -lscrip
 
+%CPP	             cpp-mp-4.8
 %FC	             mpif90 
 %FCFLAGS             -fdefault-real-8 -O3 -funroll-all-loops -fcray-pointer 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-openmpi_NAVITI_MERCATOR.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-openmpi_NAVITI_MERCATOR.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-openmpi_NAVITI_MERCATOR.fcm	(revision 4921)
@@ -19,4 +19,5 @@
 %NCDF_LIB            -L$NETCDF_LIB -lnetcdff -lnetcdf -L$HDF5_LIB -lhdf5_hl -lhdf5 -lz
 
+%CPP	             cpp
 %FC                  mpif90
 %FCFLAGS             -O2 -fp-model precise  -traceback -r8  -convert big_endian -assume byterecl
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-x3750_ADA.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-x3750_ADA.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-x3750_ADA.fcm	(revision 4921)
@@ -41,4 +41,5 @@
 %OASIS_LIB           -L%OASIS_HOME/lib -lpsmile.MPI1 -lmct -lmpeu -lscrip
 
+%CPP	             cpp
 %FC                  mpiifort -c -cpp
 %FCFLAGS             -DCPP_PARA -i4 -r8 -O3 -xAVX -fp-model precise
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-x3750_ADA_O0.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-x3750_ADA_O0.fcm	(revision 4921)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/ARCH/arch-x3750_ADA_O0.fcm	(revision 4921)
@@ -0,0 +1,54 @@
+# Ada  IBM x3750 at french IDRIS, http://www.idris.fr/ada/ada-hw-ada.html
+#
+# NCDF_HOME   root directory containing lib and include subdirectories for netcdf4
+# HDF5_HOME   root directory containing lib and include subdirectories for HDF5
+# XIOS_HOME   root directory containing lib for XIOS
+# OASIS_HOME  root directory containing lib for OASIS
+#
+# NCDF_INC    netcdf4 include file
+# NCDF_LIB    netcdf4 library
+# XIOS_INC    xios include file    (taken into accound only if key_iomput is activated)
+# XIOS_LIB    xios library         (taken into accound only if key_iomput is activated)
+# OASIS_INC   oasis include file   (taken into accound only if key_oasis3 is activated)
+# OASIS_LIB   oasis library        (taken into accound only if key_oasis3 is activated)
+#
+# FC          Fortran compiler command
+# FCFLAGS     Fortran compiler flags
+# FFLAGS      Fortran 77 compiler flags
+# LD          linker
+# LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries
+# FPPFLAGS    pre-processing flags
+# AR          assembler
+# ARFLAGS     assembler flags
+# MK          make
+# USER_INC    complete list of include files
+# USER_LIB    complete list of libraries to pass to the linker
+#
+# Note that:
+#  - unix variables "$..." are accpeted and will be evaluated before calling fcm.
+#  - fcm variables are starting with a % (and not a $)
+#
+%NCDF_HOME           /smplocal/pub/NetCDF/4.1.3/mpi
+%HDF5_HOME           /smplocal/pub/HDF5/1.8.9/par
+%XIOS_HOME           $WORKDIR/XIOS
+%OASIS_HOME          /not/yet/defined
+
+%NCDF_INC            -I%NCDF_HOME/include 
+%NCDF_LIB            -L%NCDF_HOME/lib -Bstatic -lnetcdff -lnetcdf -Bdynamic -L%HDF5_HOME/lib -Bstatic -lhdf5hl_fortran -lhdf5_hl -lhdf5_fortran -lhdf5 -Bdynamic -lz 
+%XIOS_INC            -I%XIOS_HOME/inc 
+%XIOS_LIB            -L%XIOS_HOME/lib -lxios
+%OASIS_INC           -I%OASIS_HOME/build/lib/mct -I%OASIS_HOME/build/lib/psmile.MPI1
+%OASIS_LIB           -L%OASIS_HOME/lib -lpsmile.MPI1 -lmct -lmpeu -lscrip
+
+%CPP	             cpp
+%FC                  mpiifort -c -cpp
+%FCFLAGS             -DCPP_PARA -i4 -r8 -O0 -xAVX -fp-model precise
+%FFLAGS              %FCFLAGS
+%LD                  mpiifort
+%LDFLAGS             -lstdc++
+%FPPFLAGS            -P -C -traditional
+%AR                  ar
+%ARFLAGS             rs
+%MK                  gmake
+%USER_INC            %XIOS_INC %OASIS_INC %NCDF_INC
+%USER_LIB            %XIOS_LIB %OASIS_LIB %NCDF_LIB
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/AMM12/EXP00/iodef.xml
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/AMM12/EXP00/iodef.xml	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/AMM12/EXP00/iodef.xml	(revision 4921)
@@ -85,20 +85,4 @@
 	</file>
 	
-	<file id="file8" name_suffix="_icemod" description="ice variables" >
-	  <field field_ref="ice_pres"                     />
-	  <field field_ref="snowthic_cea" name="snd"     long_name="surface_snow_thickness"   />
-	  <field field_ref="icethic_cea"  name="sit"     long_name="sea_ice_thickness"        />
-	  <field field_ref="iceprod_cea"  name="sip"     long_name="sea_ice_thickness"        />
-	  <field field_ref="ist_ipa"      />
-	  <field field_ref="ioceflxb"     />
-	  <field field_ref="uice_ipa"     />
-	  <field field_ref="vice_ipa"     />
-	  <field field_ref="utau_ice"     />
-	  <field field_ref="vtau_ice"     />
-	  <field field_ref="qsr_io_cea"   />
-	  <field field_ref="qns_io_cea"   />
-	  <field field_ref="snowpre"      />
-	</file>
-	
       </file_group>
 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/AMM12/EXP00/namelist_cfg
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/AMM12/EXP00/namelist_cfg	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/AMM12/EXP00/namelist_cfg	(revision 4921)
@@ -14,5 +14,4 @@
    cn_ocerst_in   = "amm12_restart_oce"   !  suffix of ocean restart name (input)
    cn_ocerst_out  = "restart_oce_out"   !  suffix of ocean restart name (input)
-   nn_istate   =       1   !  output the initial state (1) or not (0)
    nn_stock    =    1296   !  frequency of creation of a restart file (modulo referenced to 1)
    nn_write    =     144   !  frequency of write in the output file   (modulo referenced to nit000) 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/C1D_PAPA/EXP00/iodef.xml
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/C1D_PAPA/EXP00/iodef.xml	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/C1D_PAPA/EXP00/iodef.xml	(revision 4921)
@@ -21,5 +21,5 @@
     -->
     
-    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" min_digits="4">
+    <file_definition type="multiple_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" min_digits="4">
     
       <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/C1D_PAPA/EXP00/namelist_cfg
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/C1D_PAPA/EXP00/namelist_cfg	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/C1D_PAPA/EXP00/namelist_cfg	(revision 4921)
@@ -7,9 +7,9 @@
    cn_exp      =  "PAPA"   !  experience name
    nn_it000    =       1   !  first time step
-   nn_itend    =   78840   !  last  time step
+   nn_itend    =   87600   !  last  time step
    nn_date0    =  20100615 !  date at nit_0000 (format yyyymmdd) used if ln_rstart=F or (ln_rstart=T and nn_rstctl=0 or 1)
    nn_leapy    =       1   !  Leap year calendar (1) or not (0)
-   nn_stock    =   78840   !  frequency of creation of a restart file (modulo referenced to 1)
-   nn_write    =      60   !  frequency of write in the output file   (modulo referenced to nn_it000)
+   nn_stock    =   87600   !  frequency of creation of a restart file (modulo referenced to 1)
+   nn_write    =     240   !  frequency of write in the output file   (modulo referenced to nn_it000)
 /
 !-----------------------------------------------------------------------
@@ -38,7 +38,8 @@
 &namdom        !   space and time domain (bathymetry, mesh, timestep)
 !-----------------------------------------------------------------------
+   nn_bathy    =    0      !  compute (=0) or read (=1) the bathymetry file
    rn_bathy    = 4198.     !  value of the bathymetry. if (=0) bottom flat at jpkm1
-   nn_msh      =    3      !  create (=1) a mesh file or not (=0)
-   rn_rdt      =  400.     !  time step for the dynamics (and tracer if nn_acc=0)
+   nn_msh      =    0      !  create (=1) a mesh file or not (=0)
+   rn_rdt      =  360.     !  time step for the dynamics (and tracer if nn_acc=0)
    rn_rdtmin   =  360.           !  minimum time step on tracers (used if nn_acc=1)
    rn_rdtmax   =  360.           !  maximum time step on tracers (used if nn_acc=1)
@@ -72,4 +73,9 @@
 /
 !-----------------------------------------------------------------------
+&namc1d        !   1D configuration options                             ("key_c1d")
+!-----------------------------------------------------------------------
+   ln_c1d_locpt= .false.   ! Localization of 1D config in a grid (T) or independant point (F)
+/
+!-----------------------------------------------------------------------
 &namtsd    !   data : Temperature  & Salinity
 !-----------------------------------------------------------------------
@@ -81,5 +87,5 @@
    cn_dir        = './'     !  root directory for the location of the runoff files
    ln_tsd_init   = .true.   !  Initialisation of ocean T & S with T &S input data (T) or not (F)
-   ln_tsd_tradmp = .true.   !  damping of ocean T & S toward T &S input data (T) or not (F)
+   ln_tsd_tradmp = .false.   !  damping of ocean T & S toward T &S input data (T) or not (F)
 /
 !-----------------------------------------------------------------------
@@ -112,12 +118,12 @@
 !              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
 !              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_wndi     = 'forcing_PAPASTATION' ,         1         , 'wndwe'   ,   .true.     , .false. , 'yearly' , '' , '', ''
-   sn_wndj     = 'forcing_PAPASTATION' ,         1         , 'wndsn'   ,   .true.     , .false. , 'yearly' , '' , '', ''
-   sn_qsr      = 'forcing_PAPASTATION' ,         1         , 'qsr'     ,   .false.    , .false. , 'yearly' , '' , '', ''
-   sn_qlw      = 'forcing_PAPASTATION' ,         1         , 'qlw'     ,   .false.    , .false. , 'yearly' , '' , '', ''
-   sn_tair     = 'forcing_PAPASTATION' ,         1         , 'tair'    ,   .true.     , .false. , 'yearly' , '' , '', ''
-   sn_humi     = 'forcing_PAPASTATION' ,         1         , 'humi'    ,   .true.     , .false. , 'yearly' , '' , '', ''
-   sn_prec     = 'forcing_PAPASTATION' ,         1         , 'prec'    ,   .false.    , .false. , 'yearly' , '' , '', ''
-   sn_snow     = 'forcing_PAPASTATION' ,         1         , 'snow'    ,   .false.    , .false. , 'yearly' , '' , '', ''
+   sn_wndi     = 'forcing_PAPASTATION_1h' ,         1         , 'wndwe'   ,   .true.     , .false. , 'yearly' , '' , '', ''
+   sn_wndj     = 'forcing_PAPASTATION_1h' ,         1         , 'wndsn'   ,   .true.     , .false. , 'yearly' , '' , '', ''
+   sn_qsr      = 'forcing_PAPASTATION_1h' ,         1         , 'qsr'     ,   .false.    , .false. , 'yearly' , '' , '', ''
+   sn_qlw      = 'forcing_PAPASTATION_1h' ,         1         , 'qlw'     ,   .false.    , .false. , 'yearly' , '' , '', ''
+   sn_tair     = 'forcing_PAPASTATION_1h' ,         1         , 'tair'    ,   .true.     , .false. , 'yearly' , '' , '', ''
+   sn_humi     = 'forcing_PAPASTATION_1h' ,         1         , 'humi'    ,   .true.     , .false. , 'yearly' , '' , '', ''
+   sn_prec     = 'forcing_PAPASTATION_1h' ,         1         , 'prec'    ,   .false.    , .false. , 'yearly' , '' , '', ''
+   sn_snow     = 'forcing_PAPASTATION_1h' ,         1         , 'snow'    ,   .false.    , .false. , 'yearly' , '' , '', ''
    ln_2m         = .true.    !  air temperature and humidity referenced at 2m (T) instead 10m (F)
 /
@@ -225,4 +231,7 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !----------------------------------------------------------------------------------
+!----------------------------------------------------------------------------------
+   ln_traldf_hor    =  .true.   !  horizontal (geopotential)   (needs "key_ldfslp" when ln_sco=T)
+   ln_traldf_iso    =  .false.  !  iso-neutral                 (needs "key_ldfslp")
    rn_aeiv_0        =     0.    !  eddy induced velocity coefficient [m2/s]
    rn_aht_0         =     0.    !  horizontal eddy diffusivity for tracers [m2/s]
@@ -244,4 +253,8 @@
 /
 !-----------------------------------------------------------------------
+&namc1d_uvd    !   data: U & V currents                                 ("key_c1d")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
 &namdyn_hpg    !   Hydrostatic pressure gradient option
 !-----------------------------------------------------------------------
@@ -258,6 +271,6 @@
 &namzdf        !   vertical physics
 !-----------------------------------------------------------------------
-   rn_avm0     =   5.0e-6  !rbb 1.2e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   5.0e-6  !rbb 1.2e-5  !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
+!   rn_avm0     =   5.0e-6  !rbb 1.2e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
+!   rn_avt0     =   5.0e-6  !rbb 1.2e-5  !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
    ln_zdfevd   = .false. !rbb .true.    !  enhanced vertical diffusion (evd) (T) or not (F)
 /
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/C1D_PAPA/cpp_C1D_PAPA.fcm
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/C1D_PAPA/cpp_C1D_PAPA.fcm	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/C1D_PAPA/cpp_C1D_PAPA.fcm	(revision 4921)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys key_c1d key_dynspg_flt key_diahth key_zdfgls key_iomput key_mpp_mpi
+ bld::tool::fppkeys key_c1d key_zdfgls
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/iodef.xml
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/iodef.xml	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/iodef.xml	(revision 4921)
@@ -82,5 +82,4 @@
 	  <field field_ref="iceprod_cea"  name="sip"     long_name="sea_ice_thickness"        />
 	  <field field_ref="ist_ipa"      />
-	  <field field_ref="ioceflxb"     />
 	  <field field_ref="uice_ipa"     />
 	  <field field_ref="vice_ipa"     />
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/README
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/README	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/README	(revision 4921)
@@ -24,6 +24,10 @@
 
 
-
-
+#----------------------------------------------------------------------
+# HOW TO USE 
+#----------------------------------------------------------------------
+./std_main.sh -plot -pdf
+or
+./std_main.sh -ts -pdf
 
 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_IceFrac.pro
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_IceFrac.pro	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_IceFrac.pro	(revision 4921)
@@ -21,9 +21,9 @@
   
   IF keyword_set(arc) THEN BEGIN 
-    domdef, 20, 380, 50, 90
+    domdef, 20, 380, 40, 90
     map = [90, 0, 0]
   ENDIF
   IF keyword_set(ant) THEN BEGIN 
-    domdef, 20, 380, -90, -50
+    domdef, 20, 380, -90, -40
     map = [-90, 0, 0]
   ENDIF
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_MLD_ortho.pro
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_MLD_ortho.pro	(revision 4921)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_MLD_ortho.pro	(revision 4921)
@@ -0,0 +1,48 @@
+pro std_plot_MLD_ortho, MLD1, MLD2, ARC = arc, ANT = ant, POSTSCRIPT = postscript, _extra = ex
+
+  compile_opt idl2, strictarrsubs
+
+@common  
+@std_common
+
+  cdti3 = string(cnt, format = '(i3.3)')
+  print, cdti3 + ') ' + blabla
+
+  var = 'MLD'
+  IF keyword_set(arc) THEN var = var+'_Arc'
+  IF keyword_set(ant) THEN var = var+'_Ant'
+
+  filename = cdti3 + '_'+var+'_'+std_file1_T
+  if std_file1_T NE std_file2_T then filename = filename + '_'+std_file2_T
+  if KEYWORD_SET(postscript) then openps, filename+'.ps', portrait = 1
+  
+  IF keyword_set(arc) THEN BEGIN 
+    domdef, 20, 380, 40, 90
+    map = [90, 0, 0]
+  ENDIF
+  IF keyword_set(ant) THEN BEGIN 
+    domdef, 20, 380, -90, -40
+    map = [-90, 0, 0]
+  ENDIF
+;
+;  varunit = .unit
+;
+  title = var+'!C'+std_file1_T
+;                                ;
+  plt, MLD1.arr, label=4, cb_label=[0, 15, 25, 50, 75, 100, 125, 150, 250, 400, 600, 850], format = '(I3)' $
+       , small = [1, 2, 1], COAST_THICK = 2, TITLE = title $
+       , /ORTHO, MAP = map, /PORTRAIT, _extra = ex
+  if std_file1_T NE std_file2_T then begin            
+    title = title + ' - '+ std_file2_T
+    plt, MLD1.arr - MLD2.arr,  MIN = -80., MAX = 80., INTER = 10., format = '(I3)' $
+       , small = [1, 2, 2], COAST_THICK = 2, TITLE = title $
+       , /ORTHO, MAP = map, /NOERASE, _extra = ex
+  endif
+
+  domdef
+
+  htmltxt = [ htmltxt, '<hr>'+blabla, '<br><img width="80%" src='+filename+'.png  />  ' ]
+  if KEYWORD_SET(postscript) then closeps
+
+  return
+end
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_all.pro
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_all.pro	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_all.pro	(revision 4921)
@@ -172,6 +172,6 @@
   Ithi_april_1 = {arr:1./float(cnt) * total(reform(Ithi_1.arr[*, *, temporary(april)],nxt,nyt,cnt), 3), unit:Ithi_1.unit}
   jan = where(mm EQ 1, cnt)
+  Ithi_jan_1 = {arr:1./float(cnt) * total(reform(Ithi_1.arr[*, *, temporary(jan)],nxt,nyt,cnt), 3), unit:Ithi_1.unit} 
   sept = where(mm EQ 9, cnt)
-  Ithi_jan_1 = {arr:1./float(cnt) * total(reform(Ithi_1.arr[*, *, temporary(jan)],nxt,nyt,cnt), 3), unit:Ithi_1.unit} 
   Ithi_sept_1 = {arr:1./float(cnt) * total(reform(Ithi_1.arr[*, *, temporary(sept)],nxt,nyt,cnt), 3), unit:Ithi_1.unit} 
   undefine, Ithi_1
@@ -288,5 +288,5 @@
      Isal_sept_2 = {arr:-1}
    ENDELSE
-;
+
   IvelU_1 = read_ncdf(getenv('VAR1_IvelU'), allrecords = allrec, filename = std_file1_I ) 
   IvelV_1 = read_ncdf(getenv('VAR1_IvelV'), allrecords = allrec, filename = std_file1_I ) 
@@ -335,5 +335,5 @@
     Ivelo_sept_2 = {arr:-1}
   ENDELSE
-;
+
   Iage_1 = read_ncdf(getenv('VAR1_Iage'), allrecords = allrec, filename = std_file1_I ) 
   caldat, time, mm
@@ -396,5 +396,5 @@
   cnt = cnt+1   &   blabla = 'Erp salinity damping term'
   IF doplot EQ cnt OR doplot EQ 0 THEN std_plot_erp, ERP1, ERP2, _extra = ex
-;
+;;
   cnt = cnt+1   &   blabla = 'Evaporation - Precipitation - Runoff term'
   IF doplot EQ cnt OR doplot EQ 0 THEN std_plot_emp, EMP1, EMP2, _extra = ex
@@ -439,4 +439,10 @@
   IF doplot EQ cnt OR doplot EQ 0 THEN std_plot_mld, MLD1, MLD2, MLD, _extra = ex
 ;
+  cnt = cnt+1   &   blabla = 'Mixed layer depth ortho plan ARCTIC'
+  IF doplot EQ cnt OR doplot EQ 0 THEN std_plot_MLD_ortho, MLD1, MLD2, /ARC, _extra = ex
+;sf
+  cnt = cnt+1   &   blabla = 'Mixed layer depth ortho plan ANTARTIC'
+  IF doplot EQ cnt OR doplot EQ 0 THEN std_plot_MLD_ortho, MLD1, MLD2, /ANT, _extra = ex
+;sf
   cnt = cnt+1   &   blabla = 'Zonal mean Mixed layer depth'
   IF doplot EQ cnt OR doplot EQ 0 THEN std_plot_ZonMld, MLD1, MLD2, MLD, _extra = ex
@@ -564,5 +570,5 @@
   cnt = cnt+1   &   blabla = 'Antartic Ice Velocity: SEPT'
   IF doplot EQ cnt OR doplot EQ 0 THEN std_plot_IceVel, IvelU_sept_1, IvelU_sept_2, IvelV_sept_1, IvelV_sept_2, Ivelo_sept_1, Ivelo_sept_2, /ANT,  /SEPT, _extra = ex
-;
+
   cnt = cnt+1   &   blabla = 'Arctic Ice Age: MARCH'
   IF doplot EQ cnt OR doplot EQ 0 THEN std_plot_IceAge, Iage_march_1, Iage_march_2, Ifra_march_1, Ifra_march_2, /ARC, /MARCH, _extra = ex
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_vardef.sh
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_vardef.sh	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_vardef.sh	(revision 4921)
@@ -21,10 +21,10 @@
 #idl_command=idl71
 #
-PS_DIR=$( pwd )/OR2LPv36_ps_plot
-PDF_DIR=$( pwd )/OR2LPv36_pdf_plot
+PS_DIR=$( pwd )/p4H25a50-testht_ps_plot
+PDF_DIR=$( pwd )/p4H25a50-testht_pdf_plot
 HTML_DIR=$( pwd )/html_plot
 SAXO_DIR=/Users/sflod/SAXO_DIR
 #
-DIR_DATA=/Users/sflod/idl_PLOTS/DATA_STORE/RUN_CLIMATO/500y_pisces     # path of data in NetCDF format
+DIR_DATA=/Users/sflod/idl_PLOTS/DATA_STORE/RUN_CLIMATO/lim3_ada     # path of data in NetCDF format
 DIR_CLIMATO=/Users/sflod/idl_PLOTS/CLIMATOLOGIES    # path of climatological data
 DIR_MASK=/Users/sflod/idl_PLOTS/MASK  # path of mask files (ex: subbasins)
@@ -54,48 +54,48 @@
 #
 #===================== EXP1 =====================
-# 23610101_23701231
-FILE1_T=OR2LPv36_23610101_23701231_1Y_grid_T.nc   # exp1 grid T input file
-FILE1_U=OR2LPv36_23610101_23701231_1Y_grid_U.nc   # exp1 grid U input file
-FILE1_V=OR2LPv36_23610101_23701231_1Y_grid_V.nc   # exp1 grid V input file
-FILE1_I=OR2LPv36_23610101_23701231_1M_icemod.nc   # exp1 ice    input file
+#
+FILE1_T=p4H25a50_20410101_20501231_1Y_grid_T.nc   # exp1 grid T input file
+FILE1_U=p4H25a50_20410101_20501231_1Y_grid_U.nc   # exp1 grid U input file
+FILE1_V=p4H25a50_20410101_20501231_1Y_grid_V.nc   # exp1 grid V input file
+FILE1_I=p4H25a50_20410101_20501231_1M_icemod.nc   # exp1 ice    input file
 VAR1_T=thetao
 VAR1_S=so        
-VAR1_QNET=tohfls
-VAR1_ERP=sowafldp      
+VAR1_QNET=qt
+VAR1_ERP=wfcorr
 VAR1_EMP=wfo
 VAR1_MLD=mldr10_1
 VAR1_U=uocetr_eff
 VAR1_V=vocetr_eff
-VAR1_Ithick=iicethic
-VAR1_Ifrac=soicecov
-VAR1_Isnow=isnowthi
-#VAR1_Isal=sisali
-#VAR1_Iage=siages
-VAR1_IvelU=iicevelu
-VAR1_IvelV=iicevelv
-#VAR1_Ivelo=sivelo
+VAR1_Ithick=sithic
+VAR1_Ifrac=siconc
+VAR1_Isnow=snvolu
+VAR1_Isal=sisali
+VAR1_Iage=siages
+VAR1_IvelU=sivelu
+VAR1_IvelV=sivelv
+VAR1_Ivelo=sivelo
 #
 #===================== EXP2 =====================
 #
-FILE2_T=OR2LPv36_23610101_23701231_1Y_grid_T.nc   # exp1 grid T input file
-FILE2_U=OR2LPv36_23610101_23701231_1Y_grid_U.nc   # exp1 grid U input file
-FILE2_V=OR2LPv36_23610101_23701231_1Y_grid_V.nc   # exp1 grid V input file
-FILE2_I=OR2LPv36_23610101_23701231_1M_icemod.nc   # exp1 ice    input file
+FILE2_T=testht_20410101_20501231_1Y_grid_T.nc   # exp1 grid T input file
+FILE2_U=testht_20410101_20501231_1Y_grid_U.nc   # exp1 grid U input file
+FILE2_V=testht_20410101_20501231_1Y_grid_V.nc   # exp1 grid V input file
+FILE2_I=testht_20410101_20501231_1M_icemod.nc   # exp1 ice    input file
 VAR2_T=thetao
 VAR2_S=so
-VAR2_QNET=tohfls
-VAR2_ERP=sowafldp
+VAR2_QNET=qt
+VAR2_ERP=wfcorr
 VAR2_EMP=wfo
 VAR2_MLD=mldr10_1
 VAR2_U=uocetr_eff
 VAR2_V=vocetr_eff
-VAR2_Ithick=iicethic
-VAR2_Ifrac=soicecov
-VAR2_Isnow=isnowthi
-#VAR2_Isal=sisali
-#VAR2_Iage=siages
-VAR2_IvelU=iicevelu
-VAR2_IvelV=iicevelv
-#VAR2_Ivelo=sivelo
+VAR2_Ithick=sithic
+VAR2_Ifrac=siconc
+VAR2_Isnow=snvolu
+VAR2_Isal=sisali
+VAR2_Iage=siages
+VAR2_IvelU=sivelu
+VAR2_IvelV=sivelv
+VAR2_Ivelo=sivelo
 #
 ######################### Export Variables ###############################
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_vardef.sh.old_names
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_vardef.sh.old_names	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_vardef.sh.old_names	(revision 4921)
@@ -74,5 +74,5 @@
 VAR1_IvelU=iicevelu
 VAR1_IvelV=iicevelv
-VAR1_Ivelo=iicevelo
+#VAR1_Ivelo=iicevelo
 #
 #===================== EXP2 =====================
@@ -99,5 +99,5 @@
 VAR2_IvelU=iicevelu
 VAR2_IvelV=iicevelv
-VAR2_Ivelo=iicevelo
+#VAR2_Ivelo=iicevelo
 #
 ######################### Export Variables ###############################
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_vardef.sh.pstar4-testht
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_vardef.sh.pstar4-testht	(revision 4921)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_plot_vardef.sh.pstar4-testht	(revision 4921)
@@ -0,0 +1,129 @@
+#!/bin/sh 
+#
+# AUTHOR - date
+# ===========
+# Sebastien Masson - 04/2011 - LOCEAN
+#
+# DESCRIPTION
+# ===========
+# define all varibles needed by std_plot.sh and std_plot.pro
+#
+# EXAMPLES
+# ========
+# $ . ./std_plot_vardef.sh
+#
+#
+#===================== User PATHS =====================
+#
+#idl_command=/Applications/itt/idl64/bin/idl
+idl_command=/Applications/itt/idl71/bin/idl
+#idl_command=/usr/local_linux/idl/idl_6.4/idl64/bin/idl
+#idl_command=idl71
+#
+PS_DIR=$( pwd )/pstar4-testht_ps_plot
+PDF_DIR=$( pwd )/pstar4-testht_pdf_plot
+HTML_DIR=$( pwd )/html_plot
+SAXO_DIR=/Users/sflod/SAXO_DIR
+#
+DIR_DATA=/Users/sflod/idl_PLOTS/DATA_STORE/RUN_CLIMATO/lim3_ada     # path of data in NetCDF format
+DIR_CLIMATO=/Users/sflod/idl_PLOTS/CLIMATOLOGIES    # path of climatological data
+DIR_MASK=/Users/sflod/idl_PLOTS/MASK  # path of mask files (ex: subbasins)
+#
+#===================== Model GRID =====================
+#
+FILE_MESH_MASK=/Users/sflod/idl_PLOTS/MASK/ORL2PISV35_mesh_mask.nc # meshmask
+FILE_MASK_SUBDOMAIN=subbasins_orca21_nored.nc              # sub-bassin masks
+#
+#===================== DATA =====================
+#
+VAR_TEMP_3D=votemper     ;   FILE_TEMP_3D=potT_annual_mean.nc                         # PHC3
+VAR_SAL_3D=vosaline      ;   FILE_SAL_3D=Salt_1y_corr_PHC3WOA09.nc                    # PHC3
+VAR_SST=sst              ;   FILE_SST=NewREY_ORCA2_1991_2000_1y.nc                   # Reynolds
+VAR_FLUX=qnet            ;   FILE_FLUX=OAFlux_1my_01_12_1984_2004_orca2_qnet.nc      # flux
+VAR_MLD=mld              ;   FILE_MLD=mld_DR003_c1m_ORCA2_1y.nc                      # Mixed layer depth
+VAR_ICE_EXT_NH=extt_NH   ;   FILE_ICE=sea_ice_index_2000.nc                               # Ice Extent North Emisphere
+VAR_ICE_EXT_SH=extt_SH   ;   FILE_ICE=sea_ice_index_2000.nc                               # Ice Extent South Emisphere
+VAR_ICE_area_NH=area_NH  ;   FILE_ICE=sea_ice_index_2000.nc                               # Ice Area North Emisphere
+VAR_ICE_area_SH=area_SH  ;   FILE_ICE=sea_ice_index_2000.nc                               # Ice Area South Emisphere
+VAR_SNOW_NH=SnowDepth    ;   FILE_SNOW_ARC=Warren99_1954_1991_arctic_snowdepth.nc    # Snow arctic 
+VAR_SNOW_SH=sno_dept_mm  ;   FILE_SNOW_ANT=SMMR_SSMI_antarc_sno_dep_mm1979_2004.nc   # Snow antartic
+#
+# Geothermal heating -> define FILE_GEOHEAT to 'NO' if there is not such forcing
+#                    -> define VAR_GEOHEAT to a constant if geothermal heating is constant over the domain
+VAR_GEOHEAT=heatflow   ;   FILE_GEOHEAT=geothermal_heating.nc 
+#
+#===================== EXP1 =====================
+#
+FILE1_T=pstar4_20410101_20501231_1Y_grid_T.nc   # exp1 grid T input file
+FILE1_U=pstar4_20410101_20501231_1Y_grid_U.nc   # exp1 grid U input file
+FILE1_V=pstar4_20410101_20501231_1Y_grid_V.nc   # exp1 grid V input file
+FILE1_I=pstar4_20410101_20501231_1M_icemod.nc   # exp1 ice    input file
+VAR1_T=thetao
+VAR1_S=so        
+VAR1_QNET=qt
+VAR1_ERP=wfcorr
+VAR1_EMP=wfo
+VAR1_MLD=mldr10_1
+VAR1_U=uocetr_eff
+VAR1_V=vocetr_eff
+VAR1_Ithick=sithic
+VAR1_Ifrac=siconc
+VAR1_Isnow=snvolu
+VAR1_Isal=sisali
+VAR1_Iage=siages
+VAR1_IvelU=sivelu
+VAR1_IvelV=sivelv
+VAR1_Ivelo=sivelo
+#
+#===================== EXP2 =====================
+#
+FILE2_T=testht_20410101_20501231_1Y_grid_T.nc   # exp1 grid T input file
+FILE2_U=testht_20410101_20501231_1Y_grid_U.nc   # exp1 grid U input file
+FILE2_V=testht_20410101_20501231_1Y_grid_V.nc   # exp1 grid V input file
+FILE2_I=testht_20410101_20501231_1M_icemod.nc   # exp1 ice    input file
+VAR2_T=thetao
+VAR2_S=so
+VAR2_QNET=qt
+VAR2_ERP=wfcorr
+VAR2_EMP=wfo
+VAR2_MLD=mldr10_1
+VAR2_U=uocetr_eff
+VAR2_V=vocetr_eff
+VAR2_Ithick=sithic
+VAR2_Ifrac=siconc
+VAR2_Isnow=snvolu
+VAR2_Isal=sisali
+VAR2_Iage=siages
+VAR2_IvelU=sivelu
+VAR2_IvelV=sivelv
+VAR2_Ivelo=sivelo
+#
+######################### Export Variables ###############################
+#
+#===================== User PATHS =====================
+export PS_DIR PDF_DIR HTML_DIR SAXO_DIR
+export DIR_DATA DIR_CLIMATO DIR_MASK
+#===================== Model GRID =====================
+export FILE_MESH_MASK FILE_MASK_SUBDOMAIN
+#===================== DATA =====================
+export FILE_TEMP_3D   VAR_TEMP_3D
+export FILE_SAL_3D    VAR_SAL_3D
+export FILE_SST       VAR_SST
+export FILE_GEOHEAT   VAR_GEOHEAT
+export FILE_FLUX      VAR_FLUX
+export FILE_MLD       VAR_MLD
+export FILE_ICE       VAR_ICE_EXT_NH  VAR_ICE_EXT_SH VAR_ICE_area_NH VAR_ICE_area_SH
+export FILE_SNOW_ARC  VAR_SNOW_NH
+export FILE_SNOW_ANT  VAR_SNOW_SH
+#===================== EXP1 =====================
+export READ_ONLY_FIRST_RECORD
+export FILE1_T     FILE1_U  FILE1_V   FILE1_I
+export VAR1_T      VAR1_S   VAR1_QNET VAR1_ERP VAR1_EMP VAR1_MLD 
+export VAR1_U      VAR1_V
+export VAR1_Ithick VAR1_Ifrac VAR1_Isnow VAR1_Isal VAR1_Iage VAR1_IvelU VAR1_IvelV VAR1_Ivelo
+#===================== EXP2 =====================
+export FILE2_T     FILE2_U    FILE2_V   FILE2_I
+export VAR2_T      VAR2_S     VAR2_QNET VAR2_ERP VAR2_EMP VAR2_MLD 
+export VAR2_U      VAR2_V
+export VAR2_Ithick VAR2_Ifrac VAR2_Isnow VAR2_Isal VAR2_Iage VAR2_IvelU VAR2_IvelV VAR2_Ivelo
+#
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_ICE.pro
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_ICE.pro	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_ICE.pro	(revision 4921)
@@ -88,24 +88,25 @@
   ICE_S_15 = {arr:ICE_S_15 * 1.e-12, unit : '10^12 m^2'}
   ;
-  title = 'Northern Hemisphere'+'!C'+prefix+' (BLACK) '+d1_d2+'!C'+'OBSERVATION (light blue) '+'!C'+' Global Annual Mean Ice Area (CONTINUOUS) '+'!C'+ 'and Extend minus 15% (DASHED)'
+  ;;title = 'Northern Hemisphere'+'!C'+prefix+' (BLACK) '+d1_d2+'!C'+'OBSERVATION (light blue) '+'!C'+' Global Annual Mean Ice Area (CONTINUOUS) '+'!C'+ 'and Extend minus 15% (DASHED)'
+  title = 'Northern Hemisphere'+'!C'+prefix+' (BLACK) '+d1_d2+'!C'+'OBSERVATION (light blue) '+'!C'+' Global Annual Mean Ice Area (DASHED) '+'!C'+ 'and Extend minus 15% (CONTINUOUS)'
   jpt=12
   time=julday(1,15,1900)+30*lindgen(12)
-  pltt, ICE_N, 't', MIN = 4., MAX = 16., /REMPLI, /PORTRAIT, XGRIDSTYLE = 1, DATE_FORMAT = '%M' $
+  pltt, ICE_N, 't', MIN = 4., MAX = 16., /REMPLI, /PORTRAIT, LINESTYLE=2, XGRIDSTYLE = 1, DATE_FORMAT = '%M' $
        , COLOR = 000 , small = [1, 2, 1], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex
-  pltt, ICE_N_15, 't', /REMPLI, /PORTRAIT, LINESTYLE=2 $       ;;; dashed lines is LINESTYLE=2  $
+  pltt, ICE_N_15, 't', /REMPLI, /PORTRAIT $       ;;; dashed lines is LINESTYLE=2  $
         , /ov1d, COLOR = 000, small = [1, 2, 1], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex 
-  pltt, vICE_area_NH, 't',  /REMPLI, /PORTRAIT  $ 
+  pltt, vICE_area_NH, 't',  /REMPLI, /PORTRAIT, LINESTYLE=2  $ 
         , /ov1d, COLOR = 100, small = [1, 2, 1], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex
-  pltt, vICE_ext_NH, 't', /REMPLI, /PORTRAIT, LINESTYLE=2 $   ;;; dashed lines is LINESTYLE=2  $
+  pltt, vICE_ext_NH, 't', /REMPLI, /PORTRAIT $   ;;; dashed lines is LINESTYLE=2  $
         , /ov1d, COLOR = 100, small = [1, 2, 1], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex
 ;
-  title = 'Southern Hemisphere'+'!C'+prefix+' (BLACK) '+d1_d2+'!C'+'OBSERVATION (light blue) '+'!C'+' Global Annual Mean Ice Area (CONTINUOUS) '+'!C'+ 'and Extend minus 15% (DASHED)'
-  pltt, ICE_S, 't', MIN = 0., MAX = 20., /REMPLI, /NOERASE , XGRIDSTYLE = 1 , DATE_FORMAT = '%M' $
+  title = 'Southern Hemisphere'+'!C'+prefix+' (BLACK) '+d1_d2+'!C'+'OBSERVATION (light blue) '+'!C'+' Global Annual Mean Ice Area (DASHED) '+'!C'+ 'and Extend minus 15% (CONTINUOUS)'
+  pltt, ICE_S, 't', MIN = 0., MAX = 20., /REMPLI, LINESTYLE=2, /NOERASE , XGRIDSTYLE = 1 , DATE_FORMAT = '%M' $
         ,COLOR = 000, small = [1, 2, 2], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex
-  pltt, ICE_S_15, 't', /REMPLI, /PORTRAIT, LINESTYLE=2 $ 
+  pltt, ICE_S_15, 't', /REMPLI, /PORTRAIT $ 
         , /ov1d, COLOR = 000, small = [1, 2, 1], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex 
-  pltt,  vICE_area_SH, 't', /REMPLI, /PORTRAIT  $ 
+  pltt,  vICE_area_SH, 't', /REMPLI, /PORTRAIT, LINESTYLE=2  $ 
          , /ov1d, COLOR = 100, small = [1, 2, 1], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex
-  pltt,  vICE_ext_SH, 't', /REMPLI, /PORTRAIT, LINESTYLE=2 $ 
+  pltt,  vICE_ext_SH, 't', /REMPLI, /PORTRAIT $ 
         , /ov1d, COLOR = 100, small = [1, 2, 1], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex
 ;
@@ -159,33 +160,34 @@
 
 
-  title = 'Northern Hemisphere'+'!C'+prefix+' (BLACK) - '+prefix2+' (RED) '+d1_d2_2+'!C'+'OBSERVATION (light blue) '+'!C'+' Global Annual Mean Ice Area (CONTINUOUS) '+'!C'+ 'and Extend minus 15% (DASHED)'
+  ;;title = 'Northern Hemisphere'+'!C'+prefix+' (BLACK) - '+prefix2+' (RED) '+d1_d2_2+'!C'+'OBSERVATION (light blue) '+'!C'+' Global Annual Mean Ice Area (CONTINUOUS) '+'!C'+ 'and Extend minus 15% (DASHED)'
+  title = 'Northern Hemisphere'+'!C'+prefix+' (BLACK) - '+prefix2+' (RED) '+d1_d2_2+'!C'+'OBSERVATION (light blue) '+'!C'+' Global Annual Mean Ice Area (DASHED) '+'!C'+ 'and Extend minus 15% (CONTINUOUS)'
   jpt=12
   time=julday(1,15,1900)+30*lindgen(12)
-  pltt, ICE_N, 't', MIN = 4, MAX = 16,  /REMPLI, /PORTRAIT, XGRIDSTYLE = 1, window = 2, DATE_FORMAT = '%M' $
+  pltt, ICE_N, 't', MIN = 4, MAX = 16,  /REMPLI, /PORTRAIT, LINESTYLE=2, XGRIDSTYLE = 1, window = 2, DATE_FORMAT = '%M' $
         , COLOR = 000, small = [1, 2, 1], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex ; BLACK
-  pltt, ICE_N2, 't', /REMPLI, /PORTRAIT  $
+  pltt, ICE_N2, 't', /REMPLI, /PORTRAIT , LINESTYLE=2 $
         , /ov1d, COLOR = 250, small = [1, 2, 1], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex  ; RED
-  pltt, ICE_N_15, 't', /REMPLI, /PORTRAIT, LINESTYLE=2  $ ; linee tratteggiate LINESTYLE=2  $
+  pltt, ICE_N_15, 't', /REMPLI, /PORTRAIT $ ; linee tratteggiate LINESTYLE=2  $
         , /ov1d, COLOR = 000, small = [1, 2, 1], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex 
-  pltt, ICE_N2_15, 't', /REMPLI, /PORTRAIT, LINESTYLE=2 $ ; linee tratteggiate LINESTYLE=2  $
+  pltt, ICE_N2_15, 't', /REMPLI, /PORTRAIT $ ; linee tratteggiate LINESTYLE=2  $
         , /ov1d, COLOR = 250, small = [1, 2, 1], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex
-  pltt, vICE_area_NH, 't', /REMPLI, /PORTRAIT  $ 
+  pltt, vICE_area_NH, 't', /REMPLI, /PORTRAIT, LINESTYLE=2  $ 
         , /ov1d, COLOR = 100, small = [1, 2, 1], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex  ; light blue
-  pltt, vICE_ext_NH, 't', /REMPLI, /PORTRAIT, LINESTYLE=2 $ 
+  pltt, vICE_ext_NH, 't', /REMPLI, /PORTRAIT $ 
         , /ov1d, COLOR = 100, small = [1, 2, 1], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex  ; blu scuro
 ;
-  title ='Southern Hemisphere'+'!C'+prefix+' (BLACK) - '+prefix2+' (RED) '+d1_d2_2+'!C'+'OBSERVATION (light blue) '+'!C'+'Global Annual Mean Ice Area (CONTINUS)'+'!C'+ 'and Extend minus 15% (DASHED)'
+  title ='Southern Hemisphere'+'!C'+prefix+' (BLACK) - '+prefix2+' (RED) '+d1_d2_2+'!C'+'OBSERVATION (light blue) '+'!C'+'Global Annual Mean Ice Area (DASHED)'+'!C'+ 'and Extend minus 15% (CONTINUOUS)'
 ;  title ='Southern Hemisphere'+'!C'
-  pltt, ICE_S, 't', MIN = 0., MAX = 20.,  /REMPLI, /NOERASE, XGRIDSTYLE = 1, DATE_FORMAT = '%M' $
+  pltt, ICE_S, 't', MIN = 0., MAX = 20., /REMPLI, LINESTYLE=2, /NOERASE, XGRIDSTYLE = 1, DATE_FORMAT = '%M' $
          , COLOR = 000, small = [1, 2, 2], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex
-  pltt, ICE_S2, 't', /REMPLI, /NOERASE $
+  pltt, ICE_S2, 't', /REMPLI, /NOERASE, LINESTYLE=2 $
         , /ov1d, COLOR = 250, small = [1, 2, 2], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex
-  pltt, ICE_S_15 , 't', /REMPLI, /PORTRAIT, LINESTYLE=2 $ ; linee tratteggiate LINESTYLE=2  $
+  pltt, ICE_S_15 , 't', /REMPLI, /PORTRAIT $ ; linee tratteggiate LINESTYLE=2  $
         , /ov1d, COLOR = 000, small = [1, 2, 2], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex
-  pltt, ICE_S2_15, 't', /REMPLI, /PORTRAIT, LINESTYLE=2 $ ; linee tratteggiate LINESTYLE=2  $
+  pltt, ICE_S2_15, 't', /REMPLI, /PORTRAIT $ ; linee tratteggiate LINESTYLE=2  $
         , /ov1d, COLOR = 250, small = [1, 2, 2], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex
-  pltt,  vICE_area_SH, 't', /REMPLI, /PORTRAIT $ 
+  pltt,  vICE_area_SH, 't', /REMPLI, /PORTRAIT, LINESTYLE=2 $ 
           , /ov1d, COLOR = 100, small = [1, 2, 2], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex
-  pltt,  vICE_ext_SH, 't', /REMPLI, /PORTRAIT, LINESTYLE=2 $ 
+  pltt,  vICE_ext_SH, 't', /REMPLI, /PORTRAIT $ 
         , /ov1d, COLOR = 100, small = [1, 2, 2], YTITLE = '10^12 m^2 ', TITLE = title, _extra = ex
 ;
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_ICE_FRAM.pro
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_ICE_FRAM.pro	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_ICE_FRAM.pro	(revision 4921)
@@ -5,5 +5,6 @@
 arr2d = arr2d[t1:t2]
 arr2d = reform(arr2d,12,nyear) ; put in 2D array
-arr2d = total(arr2d,2)/nyear ; total over 2th dimension (i.e.years)
+;arr2d = total(arr2d,2)/nyear ; total over 2th dimension (i.e.years)
+arr2d = arr2d[*, nyear-1] ;  select last year
 
 return, arr2d
@@ -34,4 +35,5 @@
 ;
   d1_d2 = '('+strtrim(date1, 1)+' - '+strtrim(date2, 1)+')'
+  d2 = '('+strtrim(date2, 1)+')'
 ;
   iodir = std_iodir_data
@@ -74,5 +76,6 @@
   ;; AREA
   ICE_area_export = reform(ICE_area_export, 12, nyr)
-  ICE_area_export = total(ICE_area_export,2)/nyr
+  ;ICE_area_export = total(ICE_area_export,2)/nyr  ; old version monthly mean average  over all years
+  ICE_area_export = ICE_area_export[*,nyr-1]  ; dim= 12, index 0-11; last year choosen
   ; ICE_area_export = {arr:ICE_area_export * 1.e-12 * 86400 * 365 , unit : '10^6 Km^2/year'}  ; annual mean
   ICE_area_export = {arr:ICE_area_export * 1.e-12 * 86400 * 30 , unit : '10^6 Km^2/month'}    ; monthly mean
@@ -80,10 +83,12 @@
   ;
   ICE_vol_export = reform(ICE_vol_export, 12, nyr)
-  ICE_vol_export = total(ICE_vol_export,2)/nyr
+  ;ICE_vol_export = total(ICE_vol_export,2)/nyr
+  ICE_vol_export = ICE_vol_export[*,nyr-1]
   ; ICE_vol_export = {arr:ICE_vol_export * 1.e-9 * 86400 * 365 , unit : '10^3 Km^3/year'}      ; annual mean
   ICE_vol_export = {arr:ICE_vol_export * 1.e-9 * 86400 * 30 , unit : '10^3 Km^3/month'}      ; monthly mean
 
   ;
-  title = 'Fram Strait Areal Export'+'!C'+prefix+' '+d1_d2
+  ;title = 'Fram Strait Areal Export: LAST YEAR'+'!C'+prefix+' '+d1_d2
+  title = 'Fram Strait Areal Export: LAST YEAR'+'!C'+prefix+' '+d2
   jpt=12
   time=julday(1,15,1900)+30*lindgen(12)
@@ -99,5 +104,6 @@
   xyouts, julday(7,15,1900), 0.41, 'Data from Kwok et al.(2004), 1979-2002 ', ALIGN = 0, CHARTHICK = 2, CHARSIZE=0.8, COLOR=2
   ;
-  title = 'Fram Strait Volume Export'+'!C'+prefix+' '+d1_d2
+  ;title = 'Fram Strait Volume Export LAST YEAR'+'!C'+prefix+' '+d1_d2
+  title = 'Fram Strait Volume Export LAST YEAR'+'!C'+prefix+' '+d2
   pltt, ICE_vol_export, 't',  /REMPLI, MIN = 60., MAX = 500. , /NOERASE, XGRIDSTYLE = 1 $
        , small = [1, 2, 2], YTITLE = '10^3 Km^3/month', TITLE = title, DATE_FORMAT = '%M', _extra = ex
@@ -118,4 +124,5 @@
 
     d1_d2_2 = '('+strtrim(date1_2, 1)+' - '+strtrim(date2_2, 1)+')'
+    d2_2 = '('+strtrim(date2_2, 1)+')'
     tsave = time
     domdef, indx1, indx2, indy1, indy2, /xindex, /yindex,/memeindices
@@ -140,10 +147,12 @@
     ;; AREA
     ICE_area_export_2 = reform(ICE_area_export_2, 12, nyr)
-    ICE_area_export_2 = total(ICE_area_export_2,2)/nyr
+    ;ICE_area_export_2 = total(ICE_area_export_2,2)/nyr
+    ICE_area_export_2 = ICE_area_export_2[*,nyr-1]
     ; ICE_area_export_2 = {arr:ICE_area_export_2 * 1.e-12 * 86400 * 365 , unit : '10^6 Km^2/year'}   ; annual mean
     ICE_area_export_2 = {arr:ICE_area_export_2 * 1.e-12 * 86400 * 30 , unit : '10^6 Km^2/month'}     ; monthly mean
     ;
     ICE_vol_export_2 = reform(ICE_vol_export_2, 12, nyr)
-    ICE_vol_export_2 = total(ICE_vol_export_2,2)/nyr
+    ;ICE_vol_export_2 = total(ICE_vol_export_2,2)/nyr
+    ICE_vol_export_2 = ICE_vol_export_2[*,nyr-1]
     ; ICE_vol_export_2 = {arr:ICE_vol_export_2 * 1.e-12 * 86400 * 365 , unit : '10^3 Km^3/year'}     ; annual mean
     ICE_vol_export_2 = {arr:ICE_vol_export_2 * 1.e-9 * 86400 * 30 , unit : '10^3 Km^3/month'}       ; monthly mean
@@ -152,5 +161,6 @@
     if KEYWORD_SET(postscript) then openps, filename+'_2.ps', portrait = 1
 
-    title = 'Fram Strait Areal Export'+'!C'+prefix+' (BLACK) - '+prefix2+' (RED) '+d1_d2_2
+    ;title = 'Fram Strait Areal Export'+'!C'+prefix+' (BLACK) - '+prefix2+' (RED) '+d1_d2_2
+    title = 'Fram Strait Areal Export LAST YEAR'+'!C'+prefix+' (BLACK) - '+prefix2+' (RED) '+d2_2
     jpt=12
     time=julday(1,15,1900)+30*lindgen(12)
@@ -170,5 +180,6 @@
     xyouts, julday(7,15,1900), 0.41, 'Data from Kwok et al.(2004), 1979-2002 ', ALIGN = 0, CHARTHICK = 2, CHARSIZE=0.8, COLOR=2
     ;
-    title = 'Fram Strait Volume Export'+'!C'+prefix+' (BLACK) - '+prefix2+' (RED) '+d1_d2_2
+    ;title = 'Fram Strait Volume Export'+'!C'+prefix+' (BLACK) - '+prefix2+' (RED) '+d1_d2_2
+    title = 'Fram Strait Volume Export LAST YEAR'+'!C'+prefix+' (BLACK) - '+prefix2+' (RED) '+d2_2
     pltt, ICE_vol_export, 't', /REMPLI,  MIN = 60., MAX = 500., /NOERASE, XGRIDSTYLE = 1 $
         , small = [1, 2, 2], YTITLE = '10^3 Km^3/month', TITLE = title, DATE_FORMAT = '%M', _extra = ex
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_ICE_Vol.pro
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_ICE_Vol.pro	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_ICE_Vol.pro	(revision 4921)
@@ -70,5 +70,5 @@
 ;
   title ='Southern Hemisphere' +'!C'+prefix+' '+d1_d2+' - '+'!C'+'Global Annual Mean Ice Volume (BLACK)'
-  pltt, ICE_vol_S, 't', MIN = 0., MAX = 11000., /REMPLI, /NOERASE, XGRIDSTYLE = 1 , DATE_FORMAT = '%M' $
+  pltt, ICE_vol_S, 't', MIN = 0., MAX = 12000., /REMPLI, /NOERASE, XGRIDSTYLE = 1 , DATE_FORMAT = '%M' $
         , small = [1, 2, 2], YTITLE = '10^9 Km^3 ', TITLE = title, _extra = ex
 ;
@@ -119,5 +119,5 @@
     ;
     title = 'Southern Hemisphere'+'!C'+prefix+' (BLACK) - '+prefix2+' (RED) '+d1_d2_2+'!C'+'Global Annual Mean Ice Volume'
-    pltt, ICE_vol_S, 't', MIN = 0., MAX = 11000., /REMPLI, /NOERASE, XGRIDSTYLE = 1, DATE_FORMAT = '%M' $
+    pltt, ICE_vol_S, 't', MIN = 0., MAX = 12000., /REMPLI, /NOERASE, XGRIDSTYLE = 1, DATE_FORMAT = '%M' $
           , small = [1, 2, 2], YTITLE = '10^9 Km^3 ', TITLE = title, _extra = ex   
     pltt, ICE_vol_S2, 't',  /REMPLI, /NOERASE $
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_all.pro
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_all.pro	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_all.pro	(revision 4921)
@@ -60,6 +60,6 @@
   IF doplot EQ cnt OR doplot EQ 0 THEN std_ts_SSH, masknp, POSTSCRIPT = postscript, _extra = ex
 ;
-  cnt = cnt+1   &   blabla = 'Global Mean Q net'
-  IF doplot EQ cnt OR doplot EQ 0 THEN std_ts_Q, masknp, POSTSCRIPT = postscript, _extra = ex
+;;;;  cnt = cnt+1   &   blabla = 'Global Mean Q net'
+;;;;  IF doplot EQ cnt OR doplot EQ 0 THEN std_ts_Q, masknp, POSTSCRIPT = postscript, _extra = ex
 ;
   cnt = cnt+1   &   blabla = 'Global Mean EMP'
@@ -77,8 +77,8 @@
   cnt = cnt+1   &   blabla = 'Sea-Ice Volume'
   IF doplot EQ cnt OR doplot EQ 0 THEN std_ts_ICE_Vol, masknp, POSTSCRIPT = postscript, _extra = ex
-;
-  cnt = cnt+1   &   blabla = 'ICE Velocity '
-  IF doplot EQ cnt OR doplot EQ 0 THEN std_ts_ICE_Vel, masknp, POSTSCRIPT = postscript, _extra = ex
-;
+;SF; and probably useless
+;SF  cnt = cnt+1   &   blabla = 'ICE Velocity '
+;SF  IF doplot EQ cnt OR doplot EQ 0 THEN std_ts_ICE_Vel, masknp, POSTSCRIPT = postscript, _extra = ex
+;SF;
   cnt = cnt+1   &   blabla = 'Sea-Ice Volume Export at Fram Strait'
   IF doplot EQ cnt OR doplot EQ 0 THEN std_ts_ICE_FRAM, masknp, POSTSCRIPT = postscript, _extra = ex
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_vardef.sh
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_vardef.sh	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM/IDL_scripts/std_ts_vardef.sh	(revision 4921)
@@ -18,10 +18,10 @@
 idl_command=/Applications/itt/idl64/bin/idl
 #
-PS_DIR=$( pwd )/ts_heatbug_ps
-PDF_DIR=$( pwd )/ts_heatbug_pdf
+PS_DIR=$( pwd )/ts_p4H25a50-testht_ps
+PDF_DIR=$( pwd )/ts_p4H25a50-testht_pdf
 HTML_DIR=$( pwd )/html
 SAXO_DIR=/Users/sflod/SAXO_DIR
 #
-DIR_DATA=/Users/sflod/idl_PLOTS/DATA_STORE/RUN_CLIMATO/lim3_ada      # path of data in NetCDF format
+DIR_DATA=/Users/sflod/idl_PLOTS/DATA_STORE/RUN_CLIMATO/lim3_ada     # path of data in NetCDF format
 DIR_CLIMATO=/Users/sflod/idl_PLOTS/CLIMATOLOGIES    # path of climatological data
 DIR_MASK=/Users/sflod/idl_PLOTS/MASK  # path of mask files (ex: subbasins)
@@ -52,39 +52,35 @@
 READ_ONLY_FIRST_RECORD=0   # if 0 then read all records in files else read only the first reacord in each file
 #
-#DATE1=20010101   ;   DATE2=25001231
-DATE1=20310101   ;   DATE2=20401231
-#DATE1=00010101  		;   DATE2=00101231
+DATE1=20010101  		  ;   DATE2=20501231
 #
-VAR1_T=thetao        ;   V1T_PREF=heatbug       ;   V1T_SUFF=_1Y_grid_T.nc
-VAR1_S=so            ;   V1S_PREF=heatbug      ;   V1S_SUFF=_1Y_grid_T.nc
-VAR1_SSH=zos         ;   V1SSH_PREF=heatbug    ;   V1SSH_SUFF=_1Y_grid_T.nc
-VAR1_Q=tohfls        ;   V1Q_PREF=heatbug      ;   V1Q_SUFF=_1Y_grid_T.nc
-VAR1_EMP=wfo         ;   V1EMP_PREF=heatbug    ;   V1EMP_SUFF=_1Y_grid_T.nc
-VAR1_U=uocetr_eff    ;   V1U_PREF=heatbug      ;   V1U_SUFF=_1Y_grid_U.nc
-VAR1_V=vocetr_eff    ;   V1V_PREF=heatbug      ;   V1V_SUFF=_1Y_grid_V.nc
-VAR1_ICE=siconc      ;   V1ICE_PREF=heatbug    ;   V1ICE_SUFF=_1M_icemod.nc
-VAR1_Ithick=sithic   ;   V1It_PREF=heatbug     ;   V1It_SUFF=_1M_icemod.nc
-VAR1_SNOW=sndept     ;   V1SNOW_PREF=heatbug   ;   V1SNOW_SUFF=_1M_icemod.nc
-VAR1_IvelV=sivelv    ;   V1IvV_PREF=heatbug    ;   V1IvV_SUFF=_1M_icemod.nc
-VAR1_Ivel=sivelo     ;   V1Iv_PREF=heatbug     ;   V1Iv_SUFF=_1M_icemod.nc
+VAR1_T=thetao          ;   V1T_PREF=p4H25a50      ;   V1T_SUFF=_1Y_grid_T.nc
+VAR1_S=so              ;   V1S_PREF=p4H25a50      ;   V1S_SUFF=_1Y_grid_T.nc
+VAR1_SSH=zos         ;   V1SSH_PREF=p4H25a50    ;   V1SSH_SUFF=_1Y_grid_T.nc
+##VAR1_Q=qt              ;   V1Q_PREF=p4H25a50      ;   V1Q_SUFF=_1Y_grid_T.nc
+VAR1_EMP=wfo         ;   V1EMP_PREF=p4H25a50    ;   V1EMP_SUFF=_1Y_grid_T.nc
+VAR1_U=uocetr_eff      ;   V1U_PREF=p4H25a50      ;   V1U_SUFF=_1Y_grid_U.nc
+VAR1_V=vocetr_eff      ;   V1V_PREF=p4H25a50      ;   V1V_SUFF=_1Y_grid_V.nc
+VAR1_ICE=siconc      ;   V1ICE_PREF=p4H25a50    ;   V1ICE_SUFF=_1M_icemod.nc
+VAR1_Ithick=sithic    ;   V1It_PREF=p4H25a50     ;   V1It_SUFF=_1M_icemod.nc
+VAR1_SNOW=snthic    ;   V1SNOW_PREF=p4H25a50   ;   V1SNOW_SUFF=_1M_icemod.nc
+VAR1_IvelV=sivelv    ;   V1IvV_PREF=p4H25a50    ;   V1IvV_SUFF=_1M_icemod.nc 
+VAR1_Ivel=sivelo      ;   V1Iv_PREF=p4H25a50     ;   V1Iv_SUFF=_1M_icemod.nc
 #
 #===================== EXP2 =====================
 #
-#DATE1_2=20010101   ;   DATE2_2=20101231
-DATE1_2=20310101   ;   DATE2_2=20401231
-#DATE1_2=20010101   ;   DATE2_2=25001231
+DATE1_2=20010101   	  ;   DATE2_2=20501231
 #
-VAR2_T=thetao      ;   V2T_PREF=heatbug      ;   V2T_SUFF=_1Y_grid_T.nc
-VAR2_S=so          ;   V2S_PREF=heatbug      ;   V2S_SUFF=_1Y_grid_T.nc
-VAR2_SSH=zos       ;   V2SSH_PREF=heatbug    ;   V2SSH_SUFF=_1Y_grid_T.nc
-VAR2_Q=tohfls      ;   V2Q_PREF=heatbug      ;   V2Q_SUFF=_1Y_grid_T.nc
-VAR2_EMP=wfo       ;   V2EMP_PREF=heatbug    ;   V2EMP_SUFF=_1Y_grid_T.nc
-VAR2_U=uocetr_eff  ;   V2U_PREF=heatbug      ;   V2U_SUFF=_1Y_grid_U.nc
-VAR2_V=vocetr_eff  ;   V2V_PREF=heatbug      ;   V2V_SUFF=_1Y_grid_V.nc
-VAR2_ICE=siconc    ;   V2ICE_PREF=heatbug    ;   V2ICE_SUFF=_1M_icemod.nc
-VAR2_Ithick=sithic ;   V2It_PREF=heatbug     ;   V2It_SUFF=_1M_icemod.nc
-VAR2_SNOW=sndept   ;   V2SNOW_PREF=heatbug   ;   V2SNOW_SUFF=_1M_icemod.nc
-VAR2_IvelV=sivelv  ;   V2IvV_PREF=heatbug    ;   V2IvV_SUFF=_1M_icemod.nc
-VAR2_Ivel=sivelo   ;   V2Iv_PREF=heatbug     ;   V2Iv_SUFF=_1M_icemod.nc
+VAR2_T=thetao     	  ;   V2T_PREF=testht     ;   V2T_SUFF=_1Y_grid_T.nc
+VAR2_S=so        	  ;   V2S_PREF=testht     ;   V2S_SUFF=_1Y_grid_T.nc
+VAR2_SSH=zos      	;   V2SSH_PREF=testht   ;   V2SSH_SUFF=_1Y_grid_T.nc
+##VAR2_Q=qt       	  ;   V2Q_PREF=testht     ;   V2Q_SUFF=_1Y_grid_T.nc
+VAR2_EMP=wfo            ;   V2EMP_PREF=testht   ;   V2EMP_SUFF=_1Y_grid_T.nc
+VAR2_U=uocetr_eff   	  ;   V2U_PREF=testht     ;   V2U_SUFF=_1Y_grid_U.nc
+VAR2_V=vocetr_eff   	  ;   V2V_PREF=testht     ;   V2V_SUFF=_1Y_grid_V.nc
+VAR2_ICE=siconc         ;   V2ICE_PREF=testht   ;   V2ICE_SUFF=_1M_icemod.nc
+VAR2_Ithick=sithic       ;   V2It_PREF=testht    ;   V2It_SUFF=_1M_icemod.nc
+VAR2_SNOW=snthic       ;   V2SNOW_PREF=testht  ;   V2SNOW_SUFF=_1M_icemod.nc
+VAR2_IvelV=sivelv       ;   V2IvV_PREF=testht   ;   V2IvV_SUFF=_1M_icemod.nc 
+VAR2_Ivel=sivelo        ;   V2IvV_PREF=testht   ;   V2IvV_SUFF=_1M_icemod.nc 
 #
 ######################### Export Variables ###############################
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/iodef.xml
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/iodef.xml	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/iodef.xml	(revision 4921)
@@ -47,20 +47,25 @@
 	  <field field_ref="mldkz5"       />
 	  <field field_ref="mldr10_1"     />
+      <field field_ref="heatc"        name="heatc"    long_name="Heat content vertically integrated"            />
+      <field field_ref="saltc"        name="saltc"    long_name="Salt content vertically integrated"            />
 	</file>
 
 	<file id="file2" name_suffix="_SBC" description="surface fluxes variables" > <!-- time step automaticaly defined based on nn_fsbc -->
 	  <field field_ref="empmr"        name="wfo"      long_name="water_flux_into_sea_water"                     />
-	  <field field_ref="qsr"          name="rsntds"   long_name="surface_net_downward_shortwave_flux"           />
-	  <field field_ref="qt"           name="tohfls"   long_name="surface_net_downward_total_heat_flux"          />
-	  <field field_ref="saltflx"      name="sosflxdo"  />
+	  <field field_ref="qsr_oce"      name="qsr_oce"  long_name="downward shortwave flux at ocean surface"           />
+	  <field field_ref="qns_oce"      name="qns_oce"  long_name="downward non solar flux at ocean surface"           />
+	  <field field_ref="qt_oce"       name="qt_oce"   long_name="downward total flux at ocean surface"           />
+	  <field field_ref="qsr_ice"      name="qsr_ice"  long_name="downward shortwave flux at ice surface"           />
+	  <field field_ref="qns_ice"      name="qns_ice"  long_name="downward non solar flux at ice surface"           />
+	  <field field_ref="qtr_ice"      name="qtr_ice"  long_name="shortwave flux transmitted thru the ice"           />
+	  <field field_ref="qt_ice"       name="qt_ice"   long_name="downward total flux at ice surface"           />
+	  <field field_ref="saltflx"      name="sfx"  />
 	  <field field_ref="taum"         name="taum" />
-	  <field field_ref="wspd"         name="sowindsp"  />
-          <field field_ref="precip"       name="soprecip" />
+	  <field field_ref="wspd"         name="windsp"  />
+      <field field_ref="precip"       name="precip" />
 	  <!-- ice and snow -->
 	  <field field_ref="snowpre"      />
-          <field field_ref="qsr_io"           name="iicesflx" />
-          <field field_ref="qns_io"           name="iicenflx" />
-          <field field_ref="utau_ice"         name="iicestru" />
-          <field field_ref="vtau_ice"         name="iicestrv" />
+      <field field_ref="utau_ice"         name="utau_ice" />
+      <field field_ref="vtau_ice"         name="vtau_ice" />
 
 	</file>
@@ -73,4 +78,5 @@
 	  <field field_ref="u_masstr"     name="vozomatr"  />
 	  <field field_ref="u_heattr"     name="sozohetr"  />
+      <field field_ref="u_salttr"     name="sozosatr"  />
 	</file>
 	
@@ -82,4 +88,5 @@
 	  <field field_ref="v_masstr"     name="vomematr"  />
 	  <field field_ref="v_heattr"     name="somehetr"  />
+      <field field_ref="v_salttr"     name="somesatr"  />
 	</file>
 	
@@ -90,44 +97,90 @@
 	</file>
 
-	<file id="file6" name_suffix="_icemod" description="ice variables" >
-	  <field field_ref="snowthic_cea" name="snd"     long_name="surface_snow_thickness"   />
-	  <field field_ref="icethic_cea"  name="sit"     long_name="sea_ice_thickness"        />
-          <field field_ref="icevolu"      name="iicevolu" />
-          <field field_ref="snowvol"      name="isnowvol" />
-          <field field_ref="iceconc"      name="iiceconc"  />
-
-          <field field_ref="icebopr"          name="iicebopr" />
-          <field field_ref="icedypr"          name="iicedypr" />
-          <field field_ref="ioceflxb"         name="ioceflxb" />
-          <field field_ref="uice_ipa"         name="iicevelu" />
-          <field field_ref="vice_ipa"         name="iicevelv" />
-          <field field_ref="isst"             name="isstempe" />
-          <field field_ref="isss"             name="isssalin" />
-          <field field_ref="micesalt"         name="iicesali" />
-          <field field_ref="miceage"          name="iiceages" />
-          <field field_ref="icelapr"          name="iicelapr" />
-          <field field_ref="icesipr"          name="iicesipr" />
-          <field field_ref="micet"            name="iicetemp" />
-          <field field_ref="icehc"            name="iiceheco" />
-          <field field_ref="isnowhc"          name="isnoheco" />
-          <field field_ref="icest"            name="iicesurt" />
-          <field field_ref="sfxbri"            name="iicefsbr" />
-          <field field_ref="sfxthd"            name="iicefseq" />
-          <field field_ref="ibrinv"           name="ibrinvol" />
-          <field field_ref="icecolf"          name="iicecolf" />
-          <field field_ref="icestr"           name="iicestre" />
-          <field field_ref="icevel"           name="iicevelo" />
-          <field field_ref="isume"            name="iicesume" />
-          <field field_ref="ibome"            name="iicebome" />
-          <field field_ref="idive"            name="iicedive" />
-          <field field_ref="ishear"           name="iiceshea" />
-          <field field_ref="icerepr"          name="iicerepr" />
-          <field field_ref="sfxmec"            name="iicefsrp" />
-          <field field_ref="sfxres"            name="iicefsre" />
-          <field field_ref="icetrp"           name="iicevtrp" />
-	</file>
-
-
-	<file id="file7" name_suffix="_scalar" description="scalar variables" >
+	<file id="file6" name_suffix="_icemod" description="ice variables" enabled=".true." >
+	  <field field_ref="snowthic_cea"     name="snthic"     long_name="surface_snow_thickness"   />
+	  <field field_ref="icethic_cea"      name="sithic"     long_name="sea_ice_thickness"        />
+          <field field_ref="icevolu"          name="sivolu" />
+          <field field_ref="snowvol"          name="snvolu" />
+          <field field_ref="iceconc"          name="siconc"  />
+
+          <field field_ref="vfxbog"          name="vfxbog" />
+          <field field_ref="vfxdyn"          name="vfxdyn" />
+          <field field_ref="vfxopw"          name="vfxopw" />
+          <field field_ref="vfxsni"          name="vfxsni" />
+          <field field_ref="vfxsum"          name="vfxsum" />
+          <field field_ref="vfxbom"          name="vfxbom" />
+          <field field_ref="vfxres"          name="vfxres" />
+          <field field_ref="vfxice"          name="vfxice" />
+          <field field_ref="vfxsnw"          name="vfxsnw" />
+          <field field_ref="vfxsub"          name="vfxsub" />
+          <field field_ref="vfxspr"          name="vfxspr" />
+
+          <field field_ref="icetrp"          name="sivtrp" />
+          <field field_ref="snwtrp"          name="snvtrp" />
+          <field field_ref="deitrp"          name="deitrp" />
+          <field field_ref="destrp"          name="destrp" />
+
+          <field field_ref="sfxbri"           name="sfxbri" />
+          <field field_ref="sfxdyn"           name="sfxdyn" />
+          <field field_ref="sfxres"           name="sfxres" />
+          <field field_ref="sfxbog"           name="sfxbog" />
+          <field field_ref="sfxbom"           name="sfxbom" />
+          <field field_ref="sfxsum"           name="sfxsum" />
+          <field field_ref="sfxsni"           name="sfxsni" />
+          <field field_ref="sfxopw"           name="sfxopw" />
+          <field field_ref="sfx"              name="sfx" />
+
+          <field field_ref="hfxsum"          name="hfxsum"    />
+          <field field_ref="hfxbom"          name="hfxbom"    />
+          <field field_ref="hfxbog"          name="hfxbog"    />
+          <field field_ref="hfxdif"          name="hfxdif"    />
+          <field field_ref="hfxopw"          name="hfxopw"    />
+          <field field_ref="hfxout"          name="hfxout"    />
+          <field field_ref="hfxin"           name="hfxin"    />
+          <field field_ref="hfxsnw"          name="hfxsnw"    />
+          <field field_ref="hfxerr"          name="hfxerr"    />
+          <field field_ref="hfxerr_rem"      name="hfxerr_rem"    />
+
+	  <!-- ice-ocean heat flux from mass exchange -->
+          <field field_ref="hfxdyn"          name="hfxdyn"    />
+          <field field_ref="hfxres"          name="hfxres"    />
+          <field field_ref="hfxthd"          name="hfxthd"    />
+	  <!-- ice-atm. heat flux from mass exchange -->
+          <field field_ref="hfxsub"          name="hfxsub"    />
+          <field field_ref="hfxspr"          name="hfxspr"    />
+
+	  <!-- diags -->
+          <field field_ref="hfxdhc"          name="hfxdhc"    />
+          <field field_ref="hfxtur"          name="hfxtur"    />
+
+          <field field_ref="isst"             name="sst" />
+          <field field_ref="isss"             name="sss" />
+          <field field_ref="micesalt"         name="sisali" />
+          <field field_ref="micet"            name="sitemp" />
+          <field field_ref="icest"            name="sistem" />
+          <field field_ref="icehc"            name="siheco" />
+          <field field_ref="isnowhc"          name="snheco" />
+          <field field_ref="miceage"          name="siages" />
+
+          <field field_ref="uice_ipa"         name="sivelu" />
+          <field field_ref="vice_ipa"         name="sivelv" />
+          <field field_ref="icevel"           name="sivelo" />
+          <field field_ref="idive"            name="sidive" />
+          <field field_ref="ishear"           name="sishea" />
+          <field field_ref="icestr"           name="sistre" />
+
+          <field field_ref="ibrinv"           name="sibrin" />
+          <field field_ref="icecolf"          name="sicolf" />
+
+          <field field_ref="iceage_cat"       name="siagecat"/>
+          <field field_ref="iceconc_cat"      name="siconcat"/>
+          <field field_ref="icethic_cat"      name="sithicat"/>
+          <field field_ref="snowthic_cat"     name="snthicat"/>
+          <field field_ref="salinity_cat"     name="salincat"/>
+          <field field_ref="brinevol_cat"     name="sibricat"/>
+
+	</file>
+
+        <file id="file7" name_suffix="_scalar" description="scalar variables" enabled=".true." >
           <field field_ref="voltot"       name="scvoltot"  />
           <field field_ref="sshtot"       name="scsshtot"  />
@@ -137,36 +190,67 @@
           <field field_ref="temptot"      name="sctemtot"  />
           <field field_ref="saltot"       name="scsaltot"  />
-	
-          <!-- available with ln_diahsb -->
-	  <field field_ref="bgtemper"     name="bgtemper"    />
-	  <field field_ref="bgsaline"     name="bgsaline"    />
-	  <field field_ref="bgheatco"     name="bgheatco"    />
-	  <field field_ref="bgsaltco"     name="bgsaltco"    />
-	  <field field_ref="bgvolssh"     name="bgvolssh"    />
-	  <field field_ref="bgvoltot"     name="bgvoltot"    />
-	  <field field_ref="bgsshtot"     name="bgsshtot"    />
-	  <field field_ref="bgfrcvol"     name="bgfrcvol"    />
-	  <field field_ref="bgfrctem"     name="bgfrctem"    />
-	  <field field_ref="bgfrcsal"     name="bgfrcsal"    />
-	  <!-- available with ln_limdiahsb -->
-	  <field field_ref="ibgvoltot"    name="ibgvoltot"   />
-	  <field field_ref="sbgvoltot"    name="sbgvoltot"   />
-	  <field field_ref="ibgarea"      name="ibgarea"     />
-	  <field field_ref="ibgsaline"    name="ibgsaline"   />
-	  <field field_ref="ibgtemper"    name="ibgtemper"   />
-	  <field field_ref="ibgheatco"    name="ibgheatco"   />
-	  <field field_ref="ibgsaltco"    name="ibgsaltco"   />
-	  <field field_ref="sbgheatco"    name="sbgheatco"   />
-	  <field field_ref="ibgfrcsfx"    name="ibgfrcsfx"  />
-	  <field field_ref="ibgfrcemp"    name="ibgfrcemp"   />
-	  <field field_ref="ibgsfx"       name="ibgsfx"     />
-	  <field field_ref="ibgemp"       name="ibgemp"      />
-	  <field field_ref="ibgsfxbri"    name="ibgsfxbri"    />
-	  <field field_ref="ibgsfxthd"    name="ibgsfxthd"    />
-	  <field field_ref="ibgsfxres"    name="ibgsfxres" />
-	  <field field_ref="ibgsfxmec"    name="ibgsfxmec" />
-	  <field field_ref="ibggrpme"     name="ibggrpme"    />
-
-	</file>
+
+          <field field_ref="bgtemper"     name="bgtemper"    />
+          <field field_ref="bgsaline"     name="bgsaline"    />
+          <field field_ref="bgheatco"     name="bgheatco"    />
+          <field field_ref="bgsaltco"     name="bgsaltco"    />
+          <field field_ref="bgvolssh"     name="bgvolssh"    /> 
+          <field field_ref="bgvole3t"     name="bgvole3t"    />
+          <field field_ref="bgfrcvol"     name="bgfrcvol"    />
+          <field field_ref="bgfrctem"     name="bgfrctem"    />
+          <field field_ref="bgfrcsal"     name="bgfrcsal"    />
+
+          <field field_ref="ibgvoltot"    name="ibgvoltot"   />
+          <field field_ref="sbgvoltot"    name="sbgvoltot"   />
+          <field field_ref="ibgarea"      name="ibgarea"     />
+          <field field_ref="ibgsaline"    name="ibgsaline"   />
+          <field field_ref="ibgtemper"    name="ibgtemper"   />
+          <field field_ref="ibgheatco"    name="ibgheatco"   />
+          <field field_ref="sbgheatco"    name="sbgheatco"   />
+          <field field_ref="ibgsaltco"    name="ibgsaltco"   />
+
+          <field field_ref="ibgvfx"       name="ibgvfx"      />
+          <field field_ref="ibgvfxbog"    name="ibgvfxbog"      />
+          <field field_ref="ibgvfxopw"    name="ibgvfxopw"      />
+          <field field_ref="ibgvfxsni"    name="ibgvfxsni"      />
+          <field field_ref="ibgvfxdyn"    name="ibgvfxdyn"      />
+          <field field_ref="ibgvfxbom"    name="ibgvfxbom"      />
+          <field field_ref="ibgvfxsum"    name="ibgvfxsum"      />
+          <field field_ref="ibgvfxres"    name="ibgvfxres"      />
+          <field field_ref="ibgvfxspr"    name="ibgvfxspr"      />
+          <field field_ref="ibgvfxsnw"    name="ibgvfxsnw"      />
+          <field field_ref="ibgvfxsub"    name="ibgvfxsub"      />
+
+          <field field_ref="ibgsfx"       name="ibgsfx"     />
+          <field field_ref="ibgsfxbri"    name="ibgsfxbri"    />
+          <field field_ref="ibgsfxdyn"    name="ibgsfxdyn" />
+          <field field_ref="ibgsfxres"    name="ibgsfxres" />
+          <field field_ref="ibgsfxbog"    name="ibgsfxbog"      />
+          <field field_ref="ibgsfxopw"    name="ibgsfxopw"      />
+          <field field_ref="ibgsfxsni"    name="ibgsfxsni"      />
+          <field field_ref="ibgsfxbom"    name="ibgsfxbom"      />
+          <field field_ref="ibgsfxsum"    name="ibgsfxsum"      />
+
+          <field field_ref="ibghfxdhc"    name="ibghfxdhc"    />
+          <field field_ref="ibghfxspr"    name="ibghfxspr"    />
+
+          <field field_ref="ibghfxres"    name="ibghfxres"    />
+          <field field_ref="ibghfxsub"    name="ibghfxsub"    />
+          <field field_ref="ibghfxdyn"    name="ibghfxdyn"    />
+          <field field_ref="ibghfxthd"    name="ibghfxthd"    />
+          <field field_ref="ibghfxsum"    name="ibghfxsum"    />
+          <field field_ref="ibghfxbom"    name="ibghfxbom"    />
+          <field field_ref="ibghfxbog"    name="ibghfxbog"    />
+          <field field_ref="ibghfxdif"    name="ibghfxdif"    />
+          <field field_ref="ibghfxopw"    name="ibghfxopw"    />
+          <field field_ref="ibghfxout"    name="ibghfxout"    />
+          <field field_ref="ibghfxin"    name="ibghfxin"    />
+          <field field_ref="ibghfxsnw"    name="ibghfxsnw"    />
+
+          <field field_ref="ibgfrcvol"    name="ibgfrcvol"   />
+          <field field_ref="ibgfrcsfx"    name="ibgfrcsfx"  />
+          <field field_ref="ibgvolgrm"    name="ibgvolgrm"    />
+
+        </file>
 
 	<!--
@@ -214,4 +298,5 @@
       <axis id="nfloat" long_name="Float number"      unit="-"  />
       <axis id="icbcla" long_name="Iceberg class"     unit="-"  />
+      <axis id="ncatice" long_name="Ice categories"   unit="-"  />
    </axis_definition> 
     
@@ -241,5 +326,5 @@
 	  <variable id="buffer_server_factor_size" type="integer">2</variable>
 	  <variable id="info_level"                type="integer">0</variable>
-	  <variable id="using_server"              type="boolean">true</variable>
+	  <variable id="using_server"              type="boolean">false</variable>
 	  <variable id="using_oasis"               type="boolean">false</variable>
 	  <variable id="oasis_codes_id"            type="string" >oceanx</variable>
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/iodef_default.xml
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/iodef_default.xml	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/iodef_default.xml	(revision 4921)
@@ -47,20 +47,25 @@
 	  <field field_ref="mldkz5"       />
 	  <field field_ref="mldr10_1"     />
+      <field field_ref="heatc"        name="heatc"    long_name="Heat content vertically integrated"            />
+      <field field_ref="saltc"        name="saltc"    long_name="Salt content vertically integrated"            />
 	</file>
 
 	<file id="file2" name_suffix="_SBC" description="surface fluxes variables" > <!-- time step automaticaly defined based on nn_fsbc -->
 	  <field field_ref="empmr"        name="wfo"      long_name="water_flux_into_sea_water"                     />
-	  <field field_ref="qsr"          name="rsntds"   long_name="surface_net_downward_shortwave_flux"           />
-	  <field field_ref="qt"           name="tohfls"   long_name="surface_net_downward_total_heat_flux"          />
-	  <field field_ref="saltflx"      name="sosflxdo"  />
+	  <field field_ref="qsr_oce"      name="qsr_oce"  long_name="downward shortwave flux at ocean surface"           />
+	  <field field_ref="qns_oce"      name="qns_oce"  long_name="downward non solar flux at ocean surface"           />
+	  <field field_ref="qt_oce"       name="qt_oce"   long_name="downward total flux at ocean surface"           />
+	  <field field_ref="qsr_ice"      name="qsr_ice"  long_name="downward shortwave flux at ice surface"           />
+	  <field field_ref="qns_ice"      name="qns_ice"  long_name="downward non solar flux at ice surface"           />
+	  <field field_ref="qtr_ice"      name="qtr_ice"  long_name="shortwave flux transmitted thru the ice"           />
+	  <field field_ref="qt_ice"       name="qt_ice"   long_name="downward total flux at ice surface"           />
+	  <field field_ref="saltflx"      name="sfx"  />
 	  <field field_ref="taum"         name="taum" />
-	  <field field_ref="wspd"         name="sowindsp"  />
-          <field field_ref="precip"       name="soprecip" />
+	  <field field_ref="wspd"         name="windsp"  />
+      <field field_ref="precip"       name="precip" />
 	  <!-- ice and snow -->
 	  <field field_ref="snowpre"      />
-          <field field_ref="qsr_io"           name="iicesflx" />
-          <field field_ref="qns_io"           name="iicenflx" />
-          <field field_ref="utau_ice"         name="iicestru" />
-          <field field_ref="vtau_ice"         name="iicestrv" />
+      <field field_ref="utau_ice"         name="utau_ice" />
+      <field field_ref="vtau_ice"         name="vtau_ice" />
 
 	</file>
@@ -73,4 +78,5 @@
 	  <field field_ref="u_masstr"     name="vozomatr"  />
 	  <field field_ref="u_heattr"     name="sozohetr"  />
+      <field field_ref="u_salttr"     name="sozosatr"  />
 	</file>
 	
@@ -82,4 +88,5 @@
 	  <field field_ref="v_masstr"     name="vomematr"  />
 	  <field field_ref="v_heattr"     name="somehetr"  />
+      <field field_ref="v_salttr"     name="somesatr"  />
 	</file>
 	
@@ -90,44 +97,90 @@
 	</file>
 
-	<file id="file6" name_suffix="_icemod" description="ice variables" >
-	  <field field_ref="snowthic_cea" name="snd"     long_name="surface_snow_thickness"   />
-	  <field field_ref="icethic_cea"  name="sit"     long_name="sea_ice_thickness"        />
-          <field field_ref="icevolu"      name="iicevolu" />
-          <field field_ref="snowvol"      name="isnowvol" />
-          <field field_ref="iceconc"      name="iiceconc"  />
-
-          <field field_ref="icebopr"          name="iicebopr" />
-          <field field_ref="icedypr"          name="iicedypr" />
-          <field field_ref="ioceflxb"         name="ioceflxb" />
-          <field field_ref="uice_ipa"         name="iicevelu" />
-          <field field_ref="vice_ipa"         name="iicevelv" />
-          <field field_ref="isst"             name="isstempe" />
-          <field field_ref="isss"             name="isssalin" />
-          <field field_ref="micesalt"         name="iicesali" />
-          <field field_ref="miceage"          name="iiceages" />
-          <field field_ref="icelapr"          name="iicelapr" />
-          <field field_ref="icesipr"          name="iicesipr" />
-          <field field_ref="micet"            name="iicetemp" />
-          <field field_ref="icehc"            name="iiceheco" />
-          <field field_ref="isnowhc"          name="isnoheco" />
-          <field field_ref="icest"            name="iicesurt" />
-          <field field_ref="sfxbri"            name="iicefsbr" />
-          <field field_ref="sfxthd"            name="iicefseq" />
-          <field field_ref="ibrinv"           name="ibrinvol" />
-          <field field_ref="icecolf"          name="iicecolf" />
-          <field field_ref="icestr"           name="iicestre" />
-          <field field_ref="icevel"           name="iicevelo" />
-          <field field_ref="isume"            name="iicesume" />
-          <field field_ref="ibome"            name="iicebome" />
-          <field field_ref="idive"            name="iicedive" />
-          <field field_ref="ishear"           name="iiceshea" />
-          <field field_ref="icerepr"          name="iicerepr" />
-          <field field_ref="sfxmec"            name="iicefsrp" />
-          <field field_ref="sfxres"            name="iicefsre" />
-          <field field_ref="icetrp"           name="iicevtrp" />
-	</file>
-
-
-	<file id="file7" name_suffix="_scalar" description="scalar variables" >
+	<file id="file6" name_suffix="_icemod" description="ice variables" enabled=".true." >
+	  <field field_ref="snowthic_cea"     name="snthic"     long_name="surface_snow_thickness"   />
+	  <field field_ref="icethic_cea"      name="sithic"     long_name="sea_ice_thickness"        />
+          <field field_ref="icevolu"          name="sivolu" />
+          <field field_ref="snowvol"          name="snvolu" />
+          <field field_ref="iceconc"          name="siconc"  />
+
+          <field field_ref="vfxbog"          name="vfxbog" />
+          <field field_ref="vfxdyn"          name="vfxdyn" />
+          <field field_ref="vfxopw"          name="vfxopw" />
+          <field field_ref="vfxsni"          name="vfxsni" />
+          <field field_ref="vfxsum"          name="vfxsum" />
+          <field field_ref="vfxbom"          name="vfxbom" />
+          <field field_ref="vfxres"          name="vfxres" />
+          <field field_ref="vfxice"          name="vfxice" />
+          <field field_ref="vfxsnw"          name="vfxsnw" />
+          <field field_ref="vfxsub"          name="vfxsub" />
+          <field field_ref="vfxspr"          name="vfxspr" />
+
+          <field field_ref="icetrp"          name="sivtrp" />
+          <field field_ref="snwtrp"          name="snvtrp" />
+          <field field_ref="deitrp"          name="deitrp" />
+          <field field_ref="destrp"          name="destrp" />
+
+          <field field_ref="sfxbri"           name="sfxbri" />
+          <field field_ref="sfxdyn"           name="sfxdyn" />
+          <field field_ref="sfxres"           name="sfxres" />
+          <field field_ref="sfxbog"           name="sfxbog" />
+          <field field_ref="sfxbom"           name="sfxbom" />
+          <field field_ref="sfxsum"           name="sfxsum" />
+          <field field_ref="sfxsni"           name="sfxsni" />
+          <field field_ref="sfxopw"           name="sfxopw" />
+          <field field_ref="sfx"              name="sfx" />
+
+          <field field_ref="hfxsum"          name="hfxsum"    />
+          <field field_ref="hfxbom"          name="hfxbom"    />
+          <field field_ref="hfxbog"          name="hfxbog"    />
+          <field field_ref="hfxdif"          name="hfxdif"    />
+          <field field_ref="hfxopw"          name="hfxopw"    />
+          <field field_ref="hfxout"          name="hfxout"    />
+          <field field_ref="hfxin"           name="hfxin"    />
+          <field field_ref="hfxsnw"          name="hfxsnw"    />
+          <field field_ref="hfxerr"          name="hfxerr"    />
+          <field field_ref="hfxerr_rem"      name="hfxerr_rem"    />
+
+	  <!-- ice-ocean heat flux from mass exchange -->
+          <field field_ref="hfxdyn"          name="hfxdyn"    />
+          <field field_ref="hfxres"          name="hfxres"    />
+          <field field_ref="hfxthd"          name="hfxthd"    />
+	  <!-- ice-atm. heat flux from mass exchange -->
+          <field field_ref="hfxsub"          name="hfxsub"    />
+          <field field_ref="hfxspr"          name="hfxspr"    />
+
+	  <!-- diags -->
+          <field field_ref="hfxdhc"          name="hfxdhc"    />
+          <field field_ref="hfxtur"          name="hfxtur"    />
+
+          <field field_ref="isst"             name="sst" />
+          <field field_ref="isss"             name="sss" />
+          <field field_ref="micesalt"         name="sisali" />
+          <field field_ref="micet"            name="sitemp" />
+          <field field_ref="icest"            name="sistem" />
+          <field field_ref="icehc"            name="siheco" />
+          <field field_ref="isnowhc"          name="snheco" />
+          <field field_ref="miceage"          name="siages" />
+
+          <field field_ref="uice_ipa"         name="sivelu" />
+          <field field_ref="vice_ipa"         name="sivelv" />
+          <field field_ref="icevel"           name="sivelo" />
+          <field field_ref="idive"            name="sidive" />
+          <field field_ref="ishear"           name="sishea" />
+          <field field_ref="icestr"           name="sistre" />
+
+          <field field_ref="ibrinv"           name="sibrin" />
+          <field field_ref="icecolf"          name="sicolf" />
+
+          <field field_ref="iceage_cat"       name="siagecat"/>
+          <field field_ref="iceconc_cat"      name="siconcat"/>
+          <field field_ref="icethic_cat"      name="sithicat"/>
+          <field field_ref="snowthic_cat"     name="snthicat"/>
+          <field field_ref="salinity_cat"     name="salincat"/>
+          <field field_ref="brinevol_cat"     name="sibricat"/>
+
+	</file>
+
+        <file id="file7" name_suffix="_scalar" description="scalar variables" enabled=".true." >
           <field field_ref="voltot"       name="scvoltot"  />
           <field field_ref="sshtot"       name="scsshtot"  />
@@ -137,36 +190,67 @@
           <field field_ref="temptot"      name="sctemtot"  />
           <field field_ref="saltot"       name="scsaltot"  />
-	
-          <!-- available with ln_diahsb -->
-	  <field field_ref="bgtemper"     name="bgtemper"    />
-	  <field field_ref="bgsaline"     name="bgsaline"    />
-	  <field field_ref="bgheatco"     name="bgheatco"    />
-	  <field field_ref="bgsaltco"     name="bgsaltco"    />
-	  <field field_ref="bgvolssh"     name="bgvolssh"    />
-	  <field field_ref="bgvoltot"     name="bgvoltot"    />
-	  <field field_ref="bgsshtot"     name="bgsshtot"    />
-	  <field field_ref="bgfrcvol"     name="bgfrcvol"    />
-	  <field field_ref="bgfrctem"     name="bgfrctem"    />
-	  <field field_ref="bgfrcsal"     name="bgfrcsal"    />
-	  <!-- available with ln_limdiahsb -->
-	  <field field_ref="ibgvoltot"    name="ibgvoltot"   />
-	  <field field_ref="sbgvoltot"    name="sbgvoltot"   />
-	  <field field_ref="ibgarea"      name="ibgarea"     />
-	  <field field_ref="ibgsaline"    name="ibgsaline"   />
-	  <field field_ref="ibgtemper"    name="ibgtemper"   />
-	  <field field_ref="ibgheatco"    name="ibgheatco"   />
-	  <field field_ref="ibgsaltco"    name="ibgsaltco"   />
-	  <field field_ref="sbgheatco"    name="sbgheatco"   />
-	  <field field_ref="ibgfrcsfx"    name="ibgfrcsfx"  />
-	  <field field_ref="ibgfrcemp"    name="ibgfrcemp"   />
-	  <field field_ref="ibgsfx"       name="ibgsfx"     />
-	  <field field_ref="ibgemp"       name="ibgemp"      />
-	  <field field_ref="ibgsfxbri"    name="ibgsfxbri"    />
-	  <field field_ref="ibgsfxthd"    name="ibgsfxthd"    />
-	  <field field_ref="ibgsfxres"    name="ibgsfxres" />
-	  <field field_ref="ibgsfxmec"    name="ibgsfxmec" />
-	  <field field_ref="ibggrpme"     name="ibggrpme"    />
-
-	</file>
+
+          <field field_ref="bgtemper"     name="bgtemper"    />
+          <field field_ref="bgsaline"     name="bgsaline"    />
+          <field field_ref="bgheatco"     name="bgheatco"    />
+          <field field_ref="bgsaltco"     name="bgsaltco"    />
+          <field field_ref="bgvolssh"     name="bgvolssh"    /> 
+          <field field_ref="bgvole3t"     name="bgvole3t"    />
+          <field field_ref="bgfrcvol"     name="bgfrcvol"    />
+          <field field_ref="bgfrctem"     name="bgfrctem"    />
+          <field field_ref="bgfrcsal"     name="bgfrcsal"    />
+
+          <field field_ref="ibgvoltot"    name="ibgvoltot"   />
+          <field field_ref="sbgvoltot"    name="sbgvoltot"   />
+          <field field_ref="ibgarea"      name="ibgarea"     />
+          <field field_ref="ibgsaline"    name="ibgsaline"   />
+          <field field_ref="ibgtemper"    name="ibgtemper"   />
+          <field field_ref="ibgheatco"    name="ibgheatco"   />
+          <field field_ref="sbgheatco"    name="sbgheatco"   />
+          <field field_ref="ibgsaltco"    name="ibgsaltco"   />
+
+          <field field_ref="ibgvfx"       name="ibgvfx"      />
+          <field field_ref="ibgvfxbog"    name="ibgvfxbog"      />
+          <field field_ref="ibgvfxopw"    name="ibgvfxopw"      />
+          <field field_ref="ibgvfxsni"    name="ibgvfxsni"      />
+          <field field_ref="ibgvfxdyn"    name="ibgvfxdyn"      />
+          <field field_ref="ibgvfxbom"    name="ibgvfxbom"      />
+          <field field_ref="ibgvfxsum"    name="ibgvfxsum"      />
+          <field field_ref="ibgvfxres"    name="ibgvfxres"      />
+          <field field_ref="ibgvfxspr"    name="ibgvfxspr"      />
+          <field field_ref="ibgvfxsnw"    name="ibgvfxsnw"      />
+          <field field_ref="ibgvfxsub"    name="ibgvfxsub"      />
+
+          <field field_ref="ibgsfx"       name="ibgsfx"     />
+          <field field_ref="ibgsfxbri"    name="ibgsfxbri"    />
+          <field field_ref="ibgsfxdyn"    name="ibgsfxdyn" />
+          <field field_ref="ibgsfxres"    name="ibgsfxres" />
+          <field field_ref="ibgsfxbog"    name="ibgsfxbog"      />
+          <field field_ref="ibgsfxopw"    name="ibgsfxopw"      />
+          <field field_ref="ibgsfxsni"    name="ibgsfxsni"      />
+          <field field_ref="ibgsfxbom"    name="ibgsfxbom"      />
+          <field field_ref="ibgsfxsum"    name="ibgsfxsum"      />
+
+          <field field_ref="ibghfxdhc"    name="ibghfxdhc"    />
+          <field field_ref="ibghfxspr"    name="ibghfxspr"    />
+
+          <field field_ref="ibghfxres"    name="ibghfxres"    />
+          <field field_ref="ibghfxsub"    name="ibghfxsub"    />
+          <field field_ref="ibghfxdyn"    name="ibghfxdyn"    />
+          <field field_ref="ibghfxthd"    name="ibghfxthd"    />
+          <field field_ref="ibghfxsum"    name="ibghfxsum"    />
+          <field field_ref="ibghfxbom"    name="ibghfxbom"    />
+          <field field_ref="ibghfxbog"    name="ibghfxbog"    />
+          <field field_ref="ibghfxdif"    name="ibghfxdif"    />
+          <field field_ref="ibghfxopw"    name="ibghfxopw"    />
+          <field field_ref="ibghfxout"    name="ibghfxout"    />
+          <field field_ref="ibghfxin"    name="ibghfxin"    />
+          <field field_ref="ibghfxsnw"    name="ibghfxsnw"    />
+
+          <field field_ref="ibgfrcvol"    name="ibgfrcvol"   />
+          <field field_ref="ibgfrcsfx"    name="ibgfrcsfx"  />
+          <field field_ref="ibgvolgrm"    name="ibgvolgrm"    />
+
+        </file>
 
 	<!--
@@ -214,4 +298,5 @@
       <axis id="nfloat" long_name="Float number"      unit="-"  />
       <axis id="icbcla" long_name="Iceberg class"     unit="-"  />
+      <axis id="ncatice" long_name="Ice categories"   unit="-"  />
    </axis_definition> 
     
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/namelist_ice_cfg
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/namelist_ice_cfg	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/namelist_ice_cfg	(revision 4921)
@@ -16,9 +16,17 @@
 /
 !-----------------------------------------------------------------------
-&namicetrp     !   ice transport
+&namicethd     !   ice thermodynamic
 !-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
-&namicethd     !   ice thermodynamic
+&namicesal     !   ice salinity
 !-----------------------------------------------------------------------
 /
+!-----------------------------------------------------------------------
+&namiceitdme   !   parameters for mechanical redistribution of ice 
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namicedia     !   ice diagnostics
+!-----------------------------------------------------------------------
+/
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/iodef.xml
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/iodef.xml	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/iodef.xml	(revision 4921)
@@ -101,5 +101,4 @@
 	  <field field_ref="iceprod_cea"  name="sip"     long_name="sea_ice_thickness"        />
 	  <field field_ref="ist_ipa"      />
-	  <field field_ref="ioceflxb"     />
 	  <field field_ref="uice_ipa"     />
 	  <field field_ref="vice_ipa"     />
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_SAS_LIM/EXP00/iodef.xml
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_SAS_LIM/EXP00/iodef.xml	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/ORCA2_SAS_LIM/EXP00/iodef.xml	(revision 4921)
@@ -84,5 +84,4 @@
 	  <field field_ref="iceprod_cea"  name="sip"     long_name="sea_ice_thickness"        />
 	  <field field_ref="ist_ipa"      />
-	  <field field_ref="ioceflxb"     />
 	  <field field_ref="uice_ipa"     />
 	  <field field_ref="vice_ipa"     />
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/1_namelist_ref
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/1_namelist_ref	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/1_namelist_ref	(revision 4921)
@@ -31,4 +31,5 @@
    nn_leapy    =       0   !  Leap year calendar (1) or not (0)
    ln_rstart   = .false.   !  start from rest (F) or from a restart file (T)
+   nn_euler    =       1   !  = 0 : start with forward time step if ln_rstart=.true.
    nn_rstctl   =       0   !  restart control => activated only if ln_rstart = T
                            !    = 0 nn_date0 read in namelist ; nn_it000 : read in namelist
@@ -119,5 +120,4 @@
                            !
    rn_rdt      = 5760.     !  time step for the dynamics (and tracer if nn_acc=0)
-   nn_baro     =   64      !  number of barotropic time step            ("key_dynspg_ts")
    rn_atfp     =    0.1    !  asselin time filter parameter
    nn_acc      =    0      !  acceleration of convergence : =1      used, rdt < rdttra(k)
@@ -152,4 +152,19 @@
 /
 !-----------------------------------------------------------------------
+&namsplit      !   time splitting parameters                            ("key_dynspg_ts")
+!-----------------------------------------------------------------------
+   ln_bt_fw      =    .TRUE.           !  Forward integration of barotropic equations
+   ln_bt_av      =    .TRUE.           !  Time filtering of barotropic variables
+   ln_bt_nn_auto =    .TRUE.           !  Set nn_baro automatically to be just below
+                                       !  a user defined maximum courant number (rn_bt_cmax)
+   nn_baro       =    30               !  Number of iterations of barotropic mode
+                                       !  during rn_rdt seconds. Only used if ln_bt_nn_auto=F
+   rn_bt_cmax    =    0.8              !  Maximum courant number allowed if ln_bt_nn_auto=T 
+   nn_bt_flt     =    1                !  Time filter choice
+                                       !  = 0 None
+                                       !  = 1 Boxcar over   nn_baro barotropic steps
+                                       !  = 2 Boxcar over 2*nn_baro     "        "  
+/
+!-----------------------------------------------------------------------
 &namcrs        !   Grid coarsening for dynamics output and/or
                !   passive tracer coarsened online simulations
@@ -168,4 +183,11 @@
 /
 !-----------------------------------------------------------------------
+&namc1d        !   1D configuration options                             ("key_c1d")
+!-----------------------------------------------------------------------
+   rn_lat1d    =      50   !  Column latitude (default at PAPA station)
+   rn_lon1d    =    -145   !  Column longitude (default at PAPA station)
+   ln_c1d_locpt=  .true.   ! Localization of 1D config in a grid (T) or independant point (F)
+/
+!-----------------------------------------------------------------------
 &namtsd    !   data : Temperature  & Salinity
 !-----------------------------------------------------------------------
@@ -173,10 +195,10 @@
 !          !  file name                            ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
 !          !                                       !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-   sn_tem  = 'data_1m_potential_temperature_nomask',         -1        ,'votemper' ,    .true.    , .true. , 'yearly'   , ''      ,   ''     ,    ''
-   sn_sal  = 'data_1m_salinity_nomask'             ,         -1        ,'vosaline' ,    .true.    , .true. , 'yearly'   , ''      ,   ''     ,    ''
+   sn_tem  = 'data_1m_potential_temperature_nomask',         -1        ,'votemper' ,    .true.    , .true. , 'yearly'   , ''       ,   ''    ,    ''
+   sn_sal  = 'data_1m_salinity_nomask'             ,         -1        ,'vosaline' ,    .true.    , .true. , 'yearly'   , ''       ,   ''    ,    ''
    !
    cn_dir        = './'     !  root directory for the location of the runoff files
    ln_tsd_init   = .true.   !  Initialisation of ocean T & S with T &S input data (T) or not (F)
-   ln_tsd_tradmp = .false.   !  damping of ocean T & S toward T &S input data (T) or not (F)
+   ln_tsd_tradmp = .true.   !  damping of ocean T & S toward T &S input data (T) or not (F)
 /
 !!======================================================================
@@ -225,4 +247,6 @@
    ln_cdgw = .false.       !  Neutral drag coefficient read from wave model (T => fill namsbc_wave)
    ln_sdw  = .false.       !  Computation of 3D stokes drift                (T => fill namsbc_wave)
+   nn_lsm  = 0             !  =0 land/sea mask for input fields is not applied (keep empty land/sea mask filename field) ,
+                           !  =1:n number of iterations of land/sea mask application for input fields (fill land/sea mask filename field)
    cn_iceflx = 'linear'    !  redistribution of solar input into ice categories during coupling ice/atm.
 /
@@ -268,8 +292,8 @@
 &namsbc_core   !   namsbc_core  CORE bulk formulae
 !-----------------------------------------------------------------------
-!              !  file name                    ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights                            ! rotation ! land/sea mask !
-!              !                               !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename                           ! pairing  ! filename      !
-   sn_wndi     = 'u_10.15JUNE2009_fill'        ,         6         , 'U_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core2_agrif_bicubic.nc'   , 'Uwnd'   , ''
-   sn_wndj     = 'v_10.15JUNE2009_fill'        ,         6         , 'V_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core2_agrif_bicubic.nc'   , 'Vwnd'   , ''
+!              !  file name                    ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights                               ! rotation ! land/sea mask !
+!              !                               !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename                              ! pairing  ! filename      !
+   sn_wndi     = 'u_10.15JUNE2009_fill'        ,         6         , 'U_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core2_agrif_bicubic.nc'      , 'Uwnd'   , ''
+   sn_wndj     = 'v_10.15JUNE2009_fill'        ,         6         , 'V_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core2_agrif_bicubic.nc'      , 'Vwnd'   , ''
    sn_qsr      = 'ncar_rad.15JUNE2009_fill'    ,        24         , 'SWDN_MOD',   .false.    , .true. , 'yearly'  , 'weights_core2_agrif_bilinear.nc'     , ''       , ''
    sn_qlw      = 'ncar_rad.15JUNE2009_fill'    ,        24         , 'LWDN_MOD',   .false.    , .true. , 'yearly'  , 'weights_core2_agrif_bilinear.nc'     , ''       , ''
@@ -346,7 +370,7 @@
 &namtra_qsr    !   penetrative solar radiation
 !-----------------------------------------------------------------------
-!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights          ! rotation ! land/sea mask !
-!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename         ! pairing  ! filename      !
-   sn_chl      ='chlorophyll',        -1         , 'CHLA'    ,   .true.     , .true. , 'yearly'  , 'weights_bilin'  , ''       , ''
+!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights         ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename        ! pairing  ! filename      !
+   sn_chl      ='chlorophyll',        -1         , 'CHLA'    ,   .true.     , .true. , 'yearly'  , 'weights_bilin' , ''       , ''
 
    cn_dir      = './'      !  root directory for the location of the runoff files
@@ -544,4 +568,11 @@
     nn_tra_dta    =  0                    !  = 0, bdy data are equal to the initial state
                                           !  = 1, bdy data are read in 'bdydata   .nc' files
+    cn_ice_lim      =  'none'             !  
+    nn_ice_lim_dta  =  0                  !  = 0, bdy data are equal to the initial state
+                                          !  = 1, bdy data are read in 'bdydata   .nc' files
+    rn_ice_tem      = 270.                !  lim3 only: arbitrary temperature of incoming sea ice
+    rn_ice_sal      = 10.                 !  lim3 only:      --   salinity           --
+    rn_ice_age      = 30.                 !  lim3 only:      --   age                --
+
     ln_tra_dmp    =.false.                !  open boudaries conditions for tracers
     ln_dyn3d_dmp  =.false.                !  open boundary condition for baroclinic velocities
@@ -564,4 +595,12 @@
    bn_tem  =    'amm12_bdyT_tra' ,         24        , 'votemper' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
    bn_sal  =    'amm12_bdyT_tra' ,         24        , 'vosaline' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+! for lim2
+!   bn_frld  =    'amm12_bdyT_ice' ,         24        , 'ileadfra' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_hicif =    'amm12_bdyT_ice' ,         24        , 'iicethic' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_hsnif =    'amm12_bdyT_ice' ,         24        , 'isnowthi' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+! for lim3
+!   bn_a_i  =    'amm12_bdyT_ice' ,         24        , 'ileadfra' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_ht_i =    'amm12_bdyT_ice' ,         24        , 'iicethic' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_ht_s =    'amm12_bdyT_ice' ,         24        , 'isnowthi' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
    cn_dir  =    'bdydta/'
    ln_full_vel = .false.
@@ -588,7 +627,9 @@
                            !                              = 2 : nonlinear friction
    rn_bfri1    =    4.e-4  !  bottom drag coefficient (linear case)
-   rn_bfri2    =    1.e-3  !  bottom drag coefficient (non linear case)
+   rn_bfri2    =    1.e-3  !  bottom drag coefficient (non linear case). Minimum coeft if ln_loglayer=T
+   rn_bfri2_max =   1.e-1  !  max. bottom drag coefficient (non linear case and ln_loglayer=T)
    rn_bfeb2    =    2.5e-3 !  bottom turbulent kinetic energy background  (m2/s2)
-   rn_bfrz0    =    3.e-3  ! bottom roughness for loglayer bfr coeff 
+   rn_bfrz0    =    3.e-3  !  bottom roughness [m] if ln_loglayer=T 
+   ln_loglayer = .false.   !  logarithmic formulation (non linear case)
    ln_bfr2d    = .false.   !  horizontal variation of the bottom friction coef (read a 2D mask file )
    rn_bfrien   =    50.    !  local multiplying factor of bfr (ln_bfr2d=T)
@@ -724,4 +765,5 @@
    ln_vvl_layer  = .false.          !  full layer vertical coordinate
    ln_vvl_ztilde_as_zstar = .false. !  ztilde vertical coordinate emulating zstar
+   ln_vvl_zstar_at_eqtor = .false.  !  ztilde near the equator
    rn_ahe3       = 0.0e0            !  thickness diffusion coefficient
    rn_rst_e3t    = 30.e0            !  ztilde to zstar restoration timescale [days]
@@ -939,10 +981,4 @@
                            !     (no physical validity of the results)
    nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
-/
-!-----------------------------------------------------------------------
-&namc1d        !   1D configuration options                             ("key_c1d")
-!-----------------------------------------------------------------------
-   rn_lat      =    50     !  Column latitude
-   rn_lon      =    -145   !  Column longitude
 /
 !-----------------------------------------------------------------------
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/domain_def.xml
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/domain_def.xml	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/domain_def.xml	(revision 4921)
@@ -5,5 +5,6 @@
 	 <!--   My zoom: example of hand defined zoom   -->
          <domain id="myzoom" zoom_ibegin="10" zoom_jbegin="10" zoom_ni="5" zoom_nj="5" />
-	 <!--   Eq section   -->
+         <domain id="1point" zoom_ibegin="10" zoom_jbegin="10" zoom_ni="1" zoom_nj="1" />
+         <!--   Eq section   -->
          <domain id="EqT" zoom_ibegin="1" zoom_jbegin="0000" zoom_ni="0000" zoom_nj="1" />
          <!--   TAO   -->
@@ -170,5 +171,7 @@
       <domain_group id="scalarpoint">
          <domain id="scalarpoint" long_name="scalar"/>
+         <!--
          <domain id="1point" zoom_ibegin="1" zoom_jbegin="1" zoom_ni="1" zoom_nj="1" />
+         -->
       </domain_group>
 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/field_def.xml
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/field_def.xml	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/field_def.xml	(revision 4921)
@@ -29,4 +29,6 @@
          <field id="mldr10_1"     long_name="Mixed Layer Depth 0.01 ref.10m"            unit="m"                        />
          <field id="rhop"         long_name="potential density (sigma0)"                unit="kg/m3" grid_ref="grid_T_3D"/>
+         <field id="heatc"        long_name="Heat content vertically integrated"        unit="J/m2"                      />
+         <field id="saltc"        long_name="Salt content vertically integrated"        unit="PSU*kg/m2"                />
 	 <field id="eken"         long_name="kinetic energy"                            unit="m2/s2" grid_ref="grid_T_3D"/>
 	 <field id="hdiv"         long_name="horizontal divergence"                     unit="s-1"   grid_ref="grid_T_3D"/>
@@ -158,5 +160,4 @@
 	
          <!-- *_oce variables available with ln_blk_clio or ln_blk_core -->
-         <field id="qns_oce"      long_name="Non solar Downward Heat Flux over open ocean"                 unit="W/m2"     />
          <field id="qlw_oce"      long_name="Longwave Downward Heat Flux over open ocean"                  unit="W/m2"     />
          <field id="qsb_oce"      long_name="Sensible Downward Heat Flux over open ocean"                  unit="W/m2"     />
@@ -194,5 +195,4 @@
          <field id="ice_cover"    long_name="Ice fraction"                                                 unit="1"        />
 
-         <field id="ioceflxb"     long_name="Oceanic flux at the ice base"                                 unit="W/m2"     />
          <field id="qsr_ai_cea"   long_name="Air-Ice downward solar heat flux (cell average)"              unit="W/m2"     />
          <field id="qns_ai_cea"   long_name="Air-Ice downward non-solar heat flux (cell average)"          unit="W/m2"     />
@@ -222,7 +222,4 @@
          
          <field id="iceconc"      long_name="ice concentration"                                            unit="%"        />
-         <field id="icebopr"      long_name="daily bottom thermo ice prod."                                unit="km3/day"   />
-         <field id="icedypr"      long_name="daily  dynamic ice prod."                                     unit="km3/day"   />
-	 <field id="ioceflxb"     long_name="Oceanic flux at the ice base"                                 unit="W/m2"     />
          <field id="uice_ipa"     long_name="Ice velocity along i-axis at I-point (ice presence average)"  unit="m/s"      />
          <field id="vice_ipa"     long_name="Ice velocity along j-axis at I-point (ice presence average)"  unit="m/s"      />
@@ -232,34 +229,81 @@
          <field id="qsr_oce"      long_name="solar heat flux at ocean surface"                             unit="W/m2"     />
          <field id="qns_oce"      long_name="non-solar heat flux at ocean surface"                         unit="W/m2"     />
-         <field id="hfbri"        long_name="heat flux due to brine release"                               unit="W/m2"     />
+         <field id="qt_ice"       long_name="total flux at ice surface"                                    unit="W/m2"     />
+         <field id="qsr_ice"      long_name="solar heat flux at ice surface"                               unit="W/m2"     />
+         <field id="qns_ice"      long_name="non-solar heat flux at ice surface"                           unit="W/m2"     />
+         <field id="qtr_ice"      long_name="solar heat flux transmitted thru the ice"                     unit="W/m2"     />
          <field id="utau_ice"     long_name="Wind stress along i-axis over the ice at i-point"             unit="N/m2"     />
          <field id="vtau_ice"     long_name="Wind stress along j-axis over the ice at i-point"             unit="N/m2"     />
-	 <field id="qsr_io"       long_name="Ice-Oce downward solar heat flux"                             unit="W/m2"     />
-	 <field id="qns_io"       long_name="Ice-Oce downward non-solar heat flux"                         unit="W/m2"     />
          <field id="micesalt"     long_name="Mean ice salinity"                                            unit="psu"      />
          <field id="miceage"      long_name="Mean ice age"                                                 unit="years"    />
-         <field id="icelapr"      long_name="daily lateral thermo ice prod."                               unit="km3/day"   />
-         <field id="icesipr"      long_name="daily snowice ice prod."                                      unit="km3/day"   />
+
+         <field id="iceage_cat"   long_name="Ice age for categories"                                       unit="days"   axis_ref="ncatice" />
+         <field id="iceconc_cat"  long_name="Ice concentration for categories"                             unit="%"      axis_ref="ncatice" />
+         <field id="icethic_cat"  long_name="Ice thickness for categories"                                 unit="m"      axis_ref="ncatice" />
+         <field id="snowthic_cat" long_name="Snow thicknessi for categories"                               unit="m"      axis_ref="ncatice" />
+         <field id="salinity_cat" long_name="Sea-Ice Bulk salinity for categories"                         unit="ppt"    axis_ref="ncatice" />
+         <field id="brinevol_cat" long_name="Brine volume for categories"                                  unit="%"      axis_ref="ncatice" />
+
          <field id="micet"        long_name="Mean ice temperature"                                         unit="degC"     />
-         <field id="icehc"        long_name="ice total heat content"                                       unit="10^9 J"   /> 
+         <field id="icehc"        long_name="ice total heat content"                                       unit="10^9J"   /> 
          <field id="isnowhc"      long_name="snow total heat content"                                      unit="10^9J"    />
          <field id="icest"        long_name="ice surface temperature"                                      unit="degC"     />
-         <field id="sfxbri"       long_name="brine salt flux"                                              unit="psu*kg/m2/day" />
-         <field id="sfxthd"       long_name="equivalent FW salt flux"                                      unit="psu*kg/m2/day" />
          <field id="ibrinv"       long_name="brine volume"                                                 unit="%"        />
          <field id="icecolf"      long_name="frazil ice collection thickness"                              unit="m"        />
          <field id="icestr"       long_name="ice strength"                                                 unit="N/m"      />
          <field id="icevel"       long_name="ice velocity"                                                 unit="m/s"      />
-         <field id="isume"        long_name="surface melt"                                                 unit="km3/day"   />
-         <field id="ibome"        long_name="bottom melt"                                                  unit="km3/day"   />
          <field id="idive"        long_name="divergence"                                                   unit="10-8s-1"  />
          <field id="ishear"       long_name="shear"                                                        unit="10-8s-1"  />
-         <field id="icerepr"      long_name="daily resultant ice prod./melting from limupdate"             unit="km3/day"   />
-         <field id="icevolu"      long_name="ice volume"                                                   unit="km3"      />
-         <field id="snowvol"      long_name="snow volume"                                                  unit="km3"      />
-         <field id="sfxmec"       long_name="salt flux from ridging rafting"                               unit="psu*kg/m2/day" />
+         <field id="icevolu"      long_name="ice volume"                                                   unit="m"      />
+         <field id="snowvol"      long_name="snow volume"                                                  unit="m"      />
+
+         <field id="icetrp"       long_name="ice volume transport"                                         unit="m/day"   />
+         <field id="snwtrp"       long_name="snw volume transport"                                         unit="m/day"   />
+         <field id="deitrp"       long_name="advected ice enhalpy"                                         unit="W/m2"   />
+         <field id="destrp"       long_name="advected snw enhalpy"                                         unit="W/m2"   />
+
+         <field id="sfxbri"       long_name="brine salt flux"                                              unit="psu*kg/m2/day" />
+         <field id="sfxdyn"       long_name="salt flux from ridging rafting"                               unit="psu*kg/m2/day" />
          <field id="sfxres"       long_name="salt flux from lipupdate (resultant)"                         unit="psu*kg/m2/day" />
-         <field id="icetrp"       long_name="ice volume transport"                                         unit="km3/day"   />
-
+         <field id="sfxbog"       long_name="salt flux from bot growth"                                    unit="psu*kg/m2/day" />
+         <field id="sfxbom"       long_name="salt flux from bot melt"                                      unit="psu*kg/m2/day" />
+         <field id="sfxsum"       long_name="salt flux from surf melt"                                     unit="psu*kg/m2/day" />
+         <field id="sfxsni"       long_name="salt flux from snow-ice formation"                            unit="psu*kg/m2/day" />
+         <field id="sfxopw"       long_name="salt flux from open water ice formation"                      unit="psu*kg/m2/day" />
+         <field id="sfx"          long_name="salt flux total"                                              unit="psu*kg/m2/day" />
+
+         <field id="vfxbog"       long_name="daily bottom thermo ice prod."                                unit="m/day"   />
+         <field id="vfxdyn"       long_name="daily  dynamic ice prod."                                     unit="m/day"   />
+         <field id="vfxopw"       long_name="daily lateral thermo ice prod."                               unit="m/day"   />
+         <field id="vfxsni"       long_name="daily snowice ice prod."                                      unit="m/day"   />
+         <field id="vfxsum"       long_name="surface 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"   />
+         <field id="vfxice"       long_name="ice melt/growth"                                              unit="m/day"   />
+         <field id="vfxsnw"       long_name="snw melt/growth"                                              unit="m/day"   />
+         <field id="vfxsub"       long_name="snw sublimation"                                              unit="m/day"   />
+         <field id="vfxspr"       long_name="snw precipitation on ice"                                     unit="m/day"   />
+
+         <field id="hfxsum"   long_name="heat fluxes causing surface ice melt"            unit="W/m2"  />
+         <field id="hfxbom"   long_name="heat fluxes causing bottom ice melt"             unit="W/m2"  />
+         <field id="hfxbog"   long_name="heat fluxes causing bottom ice growth"           unit="W/m2"  />
+         <field id="hfxdif"   long_name="heat fluxes causing ice temperature change"      unit="W/m2"  />
+         <field id="hfxopw"   long_name="heat fluxes causing open water ice formation"    unit="W/m2"  />
+         <field id="hfxsnw"   long_name="heat fluxes causing snow melt"                   unit="W/m2"  />
+         <field id="hfxerr"   long_name="heat fluxes error after heat diffusion"          unit="W/m2"  />
+         <field id="hfxerr_rem" long_name="heat fluxes error after remapping"             unit="W/m2"  />
+         <field id="hfxout"   long_name="total heat fluxes received by the ocean"         unit="W/m2"  />
+         <field id="hfxin"    long_name="total heat fluxes at the ice/ocean surface"      unit="W/m2"  />
+
+	 <!-- heat flux associated with mass exchange -->
+         <field id="hfxthd"   long_name="heat fluxes from ice-ocean mass exchange during thermo"              unit="W/m2"  />
+         <field id="hfxdyn"   long_name="heat fluxes from ice-ocean mass exchange during dynamic"             unit="W/m2"  />
+         <field id="hfxres"   long_name="heat fluxes from ice-ocean mass exchange during resultant"           unit="W/m2"  />
+         <field id="hfxsub"   long_name="heat fluxes from ice-atm. mass exchange during sublimation"          unit="W/m2"  />
+         <field id="hfxspr"   long_name="heat fluxes from ice-atm. mass exchange during snow precip"          unit="W/m2" />
+
+	 <!-- diags -->
+         <field id="hfxdhc"    long_name="Heat content variation in snow and ice"   unit="W/m2" />
+         <field id="hfxtur"    long_name="turbulent heat flux at the ice base"      unit="W/m2"  />
 
       </field_group>
@@ -284,4 +328,5 @@
          <field id="u_masstr"     long_name="ocean eulerian mass transport along i-axis"  unit="kg/s" grid_ref="grid_U_3D" />
          <field id="u_heattr"     long_name="ocean eulerian heat transport along i-axis"  unit="W"    />
+         <field id="u_salttr"     long_name="ocean eulerian salt transport along i-axis"  unit="PSU*kg/s"    />
          <field id="ueiv_heattr"  long_name="ocean bolus heat transport along i-axis"     unit="W"    />
          <field id="udiff_heattr" long_name="ocean diffusion heat transport along i-axis" unit="W"    />
@@ -307,4 +352,5 @@
          <field id="v_masstr"     long_name="ocean eulerian mass transport along j-axis"  unit="kg/s" grid_ref="grid_V_3D" />
          <field id="v_heattr"     long_name="ocean eulerian heat transport along j-axis"  unit="W"     />
+         <field id="v_salttr"     long_name="ocean eulerian salt transport along i-axis"  unit="PSU*kg/s"    />
          <field id="veiv_heattr"  long_name="ocean bolus heat transport along j-axis"     unit="W"     />
          <field id="vdiff_heattr" long_name="ocean diffusion heat transport along j-axis" unit="W"     />
@@ -340,30 +386,28 @@
 
       <field_group id="scalar"  domain_ref="1point" >
-         <field id="voltot"     long_name="global mean volume"                         unit="m3"   />
-         <field id="sshtot"     long_name="global mean ssh"                            unit="m"    />
-         <field id="sshsteric"  long_name="global mean ssh steric"                     unit="m"    />
-         <field id="sshthster"  long_name="global mean ssh thermosteric"               unit="m"    />
-         <field id="masstot"    long_name="global mean mass"                           unit="kg"   />
-         <field id="temptot"    long_name="global mean temperature"                    unit="degC" />
-         <field id="saltot"     long_name="global mean salinity"                       unit="psu"  />
-         <field id="fram_trans" long_name="Sea Ice Mass Transport Through Fram Strait" unit="kg/s" />
-
+     <field id="voltot"     long_name="global mean volume"                         unit="m3"   />
+     <field id="sshtot"     long_name="global mean ssh"                            unit="m"    />
+     <field id="sshsteric"  long_name="global mean ssh steric"                     unit="m"    />
+     <field id="sshthster"  long_name="global mean ssh thermosteric"               unit="m"    />
+     <field id="masstot"    long_name="global mean mass"                           unit="kg"   />
+     <field id="temptot"    long_name="global mean temperature"                    unit="degC" />
+     <field id="saltot"     long_name="global mean salinity"                       unit="psu"  />
+     <field id="fram_trans" long_name="Sea Ice Mass Transport Through Fram Strait" unit="kg/s" />
    	 <!-- available with ln_diahsb -->
-	 <field id="bgtemper"     long_name="global mean temperature"                  unit="degC"   />
-	 <field id="bgsaline"     long_name="global mean salinity"                     unit="psu"    />
-	 <field id="bgheatco"     long_name="global mean heat content"                 unit="10^9J"  />
-	 <field id="bgsaltco"     long_name="global mean salt content"                 unit="psu*m3" />
-	 <field id="bgvolssh"     long_name="global mean ssh volume"                   unit="km3"     />
-	 <field id="bgvoltot"     long_name="global mean volume"                       unit="km3"     />
-	 <field id="bgsshtot"     long_name="global mean ssh"                          unit="m"      />
-	 <field id="bgfrcvol"     long_name="global mean volume from forcing"          unit="km3"     />
-	 <field id="bgfrctem"     long_name="global mean heat content from forcing"    unit="10^9J"  />
-	 <field id="bgfrcsal"     long_name="global mean salt content from forcing"    unit="psu*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="psu"  />
+	 <field id="bgtemper" long_name="global mean temperature variation"            unit="degC"/>
+	 <field id="bgsaline" long_name="global mean salinity variation"               unit="psu"/>
+	 <field id="bgheatco" long_name="global mean heat content variation"           unit="10^20J"/>
+	 <field id="bgsaltco" long_name="global mean salt content variation"           unit="psu*km3" />
+	 <field id="bgvolssh" long_name="global mean volume variation (ssh)"           unit="km3"/>
+	 <field id="bgvole3t" long_name="global mean volume variation (e3t)"           unit="km3"/>
+	 <field id="bgfrcvol" long_name="global mean volume variation from forcing"    unit="km3"/>
+	 <field id="bgfrctem" long_name="global mean forcing from heat content variation"   unit="degC"/>
+	 <field id="bgfrcsal" long_name="global mean forcing salt content variation"        unit="psu"/>
+	 <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="psu"/>
       </field_group>
 
       <field_group id="SBC_scalar"  domain_ref="1point" >
-         <!-- available with ln_limdiahsb -->
+         <!-- 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"   />
@@ -371,16 +415,50 @@
 	 <field id="ibgsaline"    long_name="global mean ice salinity"                 unit="psu"   />
 	 <field id="ibgtemper"    long_name="global mean ice temperature"              unit="degC"   />
-	 <field id="ibgheatco"    long_name="global mean ice heat content"             unit="10^9J"   />
+	 <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="psu*km3"   />
-	 <field id="sbgheatco"    long_name="global mean snow heat content"            unit="10^9J"   />
-	 <field id="ibgfrcsfx"    long_name="global mean salt content from sfx"        unit="psu*km3"   />
-	 <field id="ibgfrcemp"    long_name="global mean volume from emp"              unit="km3"      />
-	 <field id="ibgsfx"       long_name="global mean emps"                         unit="psu*kg/m2/day"   />
-	 <field id="ibgemp"       long_name="global mean emp"                          unit="kg/m2/day"   />
-	 <field id="ibgsfxbri"    long_name="global mean ice sfx_bri"                  unit="psu*kg/m2/day"   />
-	 <field id="ibgsfxthd"    long_name="global mean ice sfx_thd"                  unit="psu*kg/m2/day"   />
-	 <field id="ibgsfxres"    long_name="global mean ice sfx_res"                  unit="psu*kg/m2/day"   />
-	 <field id="ibgsfxmec"    long_name="global mean ice fsalt_rpo"                unit="psu*kg/m2/day"   />
-	 <field id="ibggrpme"     long_name="global mean ice growth+melt volume"       unit="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="psu*m/day"   />
+	 <field id="ibgsfxbri"    long_name="global mean salt flux (brines)"           unit="psu*m/day"   />
+	 <field id="ibgsfxdyn"    long_name="global mean salt flux (dynamic)"          unit="psu*m/day"   />
+	 <field id="ibgsfxres"    long_name="global mean salt flux (resultant)"        unit="psu*m/day"   />
+	 <field id="ibgsfxbog"    long_name="global mean salt flux (thermo)"           unit="psu*m/day"   />
+	 <field id="ibgsfxopw"    long_name="global mean salt flux (thermo)"           unit="psu*m/day"   />
+	 <field id="ibgsfxsni"    long_name="global mean salt flux (thermo)"           unit="psu*m/day"   />
+	 <field id="ibgsfxbom"    long_name="global mean salt flux (thermo)"           unit="psu*m/day"   />
+	 <field id="ibgsfxsum"    long_name="global mean salt flux (thermo)"           unit="psu*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="psu*km3"   />
+	 <field id="ibgvolgrm"    long_name="global mean ice growth+melt volume"       unit="km3"      />
       </field_group>
   
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/namelist_ice_lim3_ref
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/namelist_ice_lim3_ref	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/namelist_ice_lim3_ref	(revision 4921)
@@ -15,25 +15,28 @@
 !-----------------------------------------------------------------------
    cn_icerst_in  = "restart_ice"   !  suffix of ice restart name (input)
-   cn_icerst_out = "restart_ice"      !  suffix of ice restart name (output)
-   ln_limdyn   = .true.    !  ice dynamics (T) or thermodynamics only (F)
-   amax        = 0.999      !  maximum ice concentration
-   cai         =  1.40e-3  !  atmospheric drag over sea ice
-   cao         =  1.00e-3  !  atmospheric drag over ocean
-   ln_nicep    = .false.   !  Ice points output for debug (yes or no)
-   ln_limdiahsb  = .false.    !  check the heat and salt budgets (T) or not (F)
-   ln_limdiaout  = .false.    !  output the heat and salt budgets (T) or not (F)
+   cn_icerst_out = "restart_ice"   !  suffix of ice restart name (output)
+   ln_limdyn     = .true.          !  ice dynamics (T) or thermodynamics only (F)
+   amax          = 0.999           !  maximum ice concentration
+   cai           = 1.40e-3         !  atmospheric drag over sea ice (clio)
+   cao           = 1.00e-3         !  atmospheric drag over ocean   (clio)
+   ln_nicep      = .false.         !  Ice points output for debug (yes or no)
+   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)
 /
 !-----------------------------------------------------------------------
 &namiceini     !   ice initialisation
 !-----------------------------------------------------------------------
-   ttest       =  2.0      !  threshold water temperature for initial sea ice
-   hninn       =  0.3      !  initial snow thickness in the north
-   hnins       =  0.1      !        "            "          south
-   hginn       =  3.50     !  initial undeformed ice thickness in the north
-   hgins       =  1.0      !        "            "              "     south
-   aginn       =  0.95     !  initial undeformed ice concentration in the north
-   agins       =  0.9      !        "            "              "         south
-   sinn        =  6.301    !  initial salinity in the north
-   sins        =  6.301    !        "            "    south
+   ln_limini   = .false.   !  activate ice initialization (T) or not (F)
+   thres_sst   =  0.0      !  threshold water temperature for initial sea ice
+   hts_ini_n   =  0.3      !  initial snow thickness in the north
+   hts_ini_s   =  0.3      !        "            "          south
+   hti_ini_n   =  1.0      !  initial ice thickness in the north
+   hti_ini_s   =  1.0      !        "            "         south
+   ati_ini_n   =  0.9      !  initial ice concentration in the north
+   ati_ini_s   =  0.9      !        "            "             south
+   smi_ini_n   =  6.301    !  initial ice salinity in the north
+   smi_ini_s   =  6.301    !        "            "    south
+   tmi_ini_n   =  270.     !  initial ice/snw temp in the north
+   tmi_ini_s   =  270.     !  initial ice/snw temp in the south
 /
 !-----------------------------------------------------------------------
@@ -41,27 +44,16 @@
 !-----------------------------------------------------------------------
    epsd        =   1.0e-20 !  tolerance parameter
-   alpha       =   0.5     !  coefficient for semi-implicit coriolis
-   dm          =   0.6e+03 !  diffusion constant for dynamics
-   nbiter      =   1       !  number of sub-time steps for relaxation
-   nbitdr      = 500       !  maximum number of iterations for relaxation
    om          =   0.5     !  relaxation constant 
-   resl        =   5.0e-05 !  maximum value for the residual of relaxation
    cw          =   5.0e-03 !  drag coefficient for oceanic stress
    angvg       =   0.0     !  turning angle for oceanic stress
    pstar       =   2.0e+04 !  1st bulk-rheology parameter
    c_rhg       =  20.0     !  2nd bulk-rhelogy parameter
-   etamn       =   0.0e+07 !  minimun value for viscosity
    creepl      =   1.0e-12 !  creep limit
    ecc         =   2.0     !  eccentricity of the elliptical yield curve
    ahi0        = 350.e0    !  horizontal eddy diffusivity coefficient for sea-ice [m2/s]
-   nevp        = 300       !  number of iterations for subcycling in EVP, SB, 400
-   telast      =9600.0     !  timescale for elastic waves, SB, 720.0
+   nevp        = 120       !  number of iterations for subcycling in EVP
+   relast      = 0.333     !  ratio of elastic timescale over ice time step (1/3 if nevp=120 ; 1/9 if nevp=300)
    alphaevp    =   1.0     !  coefficient for the solution of internal ice stresses
    hminrhg     =   0.001   !  ice volume (a*h in m) below which ice velocity equal ocean velocity
-/
-!-----------------------------------------------------------------------
-&namicetrp     !   ice transport
-!-----------------------------------------------------------------------
-   bound       =   0.      !  boundary conditions (=0.0 no-slip, =1.0 free-slip)
 /
 !-----------------------------------------------------------------------
@@ -69,23 +61,13 @@
 !-----------------------------------------------------------------------
    hmelt       = -0.15     !  maximum melting at the bottom
-   hiccrit     = 0.1 , 0.1 !  ice thickness for lateral accretion in the Northern (Southern) Hemisphere
+   hiccrit     = 0.1       !  ice thickness for lateral accretion 
                            !         caution 1.0, 1.0 best value to be used!!! (gilles G.)  ????
-   fraz_swi    = 0.0       !  use of frazil ice collection thickness in function of wind (1.0) or not (0.0)
+   fraz_swi    = 0         !  use of frazil ice collection thickness in function of wind (1.0) or not (0.0)
    maxfrazb    = 0.0       !  maximum portion of frazil ice collecting at the ice bottom
    vfrazb      = 0.4166667 !  thresold drift speed for frazil ice collecting at the ice bottom
    Cfrazb      = 5.0       !  squeezing coefficient for frazil ice collecting at the ice bottom
-   hicmin      = 0.2       !  ice thickness corr. to max. energy stored in brine pocket
    hiclim      = 0.10      !  minimum ice thickness
-   sbeta       = 1.        !  numerical caracteritic of the scheme for diffusion in ice
-                           !        Cranck-Nicholson (=0.5), implicit (=1), explicit (=0)
-   parlat      = 0.0       !  percentage of energy used for lateral ablation
-   hakspl      = 0.25      !  slope of distr. for Hakkinen-Mellor's lateral melting
-   hibspl      = 0.5       !  slope of distribution for Hibler's lateral melting
-   exld        = 2.0       !  exponent for leads-closure rate
-   hakdif      = 1.0       !  coefficient for diffusions of ice and snow
-   thth        = 0.2       !  threshold thickness for comp. of eq. thermal conductivity
    hnzst       = 0.1       !  thickness of the surf. layer in temp. computation
    parsub      = 1.0       !  switch for snow sublimation or not
-   alphs       = 1.0       !  coefficient for snow density when snow ice formation
    betas       = 0.6       !  exponent in lead-ice fractionation of snow precipitation 0.66
                            !        betas = 1 -> equipartition, betas < 1 -> more on leads
@@ -124,11 +106,9 @@
    astar            =   0.05 !  equivalent of gstar (0.05 for TH75 and 0.03 for weaker ice)
    Hstar            = 100.0  !  parameter determining the maximum thickness of ridged ice
-   raftswi          =   1    !  rafting or not
+   raft_swi         =   1    !  rafting or not
    hparmeter        =   0.75 !  threshold thickness for rafting or not
    Craft            =   5.0  !  coefficient used in the rafting function
    ridge_por        =   0.3  !  initial porosity of the ridged ice (typically 0.30)
-   sal_max_ridge    =  15.0  !  maximum ridged ice salinity
    partfun_swi      =   1    !  participation function linear, TH75 (0) or exponential Letal07 (1)
-   transfun_swi     =   0    !  transfer function uniform of H80 (0) or exponential Letal07 (1)
    brinstren_swi    =   0    !  (1) use brine volume to diminish ice strength
 /
@@ -144,58 +124,4 @@
 !&namicehsb       !  Heat and salt budgets 
 !!-----------------------------------------------------------------------
-!
 !/
-!-----------------------------------------------------------------------
-&namiceout     !   parameters for outputs
-!-----------------------------------------------------------------------
-   noumef      =   43      !  number of fields
-   add_diag_swi=    1      !  1 -> diagnose distribution in thickness space
-                           !  0 -> only simple diagnostics
-!
-!           !         title of the field           !  name     !   units   !  save  ! multipl. ! additive !
-!           !                                      !           !           ! or not !  factor  !  factor  !
-   field_1  = 'Ice concentration                  ', 'iiceconc', '%       ',    1   ,  1.0     ,    0.0
-   field_2  = 'Ice thickness                      ', 'iicethic', 'm       ',    1   ,  1.0     ,    0.0
-   field_3  = 'Snow thickness                     ', 'isnowthi', 'm       ',    1   ,  1.0     ,    0.0
-   field_4  = 'Daily bottom thermo ice production ', 'iicebopr', 'km3/day ',    1   , 1.0e-9   ,    0.0
-   field_5  = 'Daily dynamic ice production       ', 'iicedypr', 'km3/day ',    1   , 1.0e-9   ,    0.0
-   field_6  = 'Oceanic flux at the ice base       ', 'ioceflxb', 'w/m2    ',    1   ,  1.0     ,    0.0
-   field_7  = 'Ice velocity u                     ', 'iicevelu', 'm/s     ',    1   ,  1.0     ,    0.0
-   field_8  = 'Ice velocity v                     ', 'iicevelv', 'm/s     ',    1   ,  1.0     ,    0.0
-   field_9  = 'Sea surface temperature            ', 'isstempe', 'C       ',    1   ,  1.0     , -273.15
-   field_10 = 'Sea surface salinity               ', 'isssalin', 'PSU     ',    1   ,  1.0     ,    0.0
-   field_11 = 'Total flux at ocean surface        ', 'iocetflx', 'w/m2    ',    1   ,  1.0     ,    0.0
-   field_12 = 'Solar flux at ocean surface        ', 'iocesflx', 'w/m2    ',    1   ,  1.0     ,    0.0
-   field_13 = 'Non-solar flux at ocean surface    ', 'iocwnsfl', 'w/m2    ',    1   ,  1.0     ,    0.0
-   field_14 = 'Heat flux due to brine release     ', 'iocehebr', 'w/m2    ',    1   ,  1.0     ,    0.0
-   field_15 = 'Wind stress u                      ', 'iocestru', 'Pa      ',    1   ,  1.0     ,    0.0
-   field_16 = 'Wind stress v                      ', 'iocestrv', 'Pa      ',    1   ,  1.0     ,    0.0 
-   field_17 = 'Solar flux at ice/ocean surface    ', 'iicesflx', 'w/m2    ',    1   ,  1.0     ,    0.0
-   field_18 = 'Non-solar flux at ice/ocean surface', 'iicenflx', 'w/m2    ',    1   ,  1.0     ,    0.0
-   field_19 = 'Snow precipitation                 ', 'isnowpre', 'kg/m2/d ',    1   ,  1.0     ,    0.0
-   field_20 = 'Mean ice salinity                  ', 'iicesali', 'psu     ',    1   ,  1.0     ,    0.0
-   field_21 = 'Mean ice age                       ', 'iiceages', 'years   ',    1   ,  0.002739,    0.0
-   field_22 = 'Daily lateral thermo ice prod.     ', 'iicelapr', 'km3/day ',    1   ,1.0e-9    ,    0.0
-   field_23 = 'Daily snowice ice production       ', 'iicesipr', 'km3/day ',    1   ,1.0e-9    ,    0.0
-   field_24 = 'Mean ice temperature               ', 'iicetemp', 'C       ',    1   ,  1.0     , -273.15
-   field_25 = 'Ice total heat content             ', 'iiceheco', '10^9 J  ',    1   ,  1.0     ,    0.0
-   field_26 = 'Ice surface temperature            ', 'iicesurt', 'C       ',    1   ,  1.0     , -273.15
-   field_27 = 'Snow temperature                   ', 'isnotem2', 'C       ',    1   ,  1.0     , -273.15
-   field_28 = 'Fsbri - brine salt flux            ', 'iicefsbr', 'kg/m2/d ',    1   ,  1.0     ,    0.0
-   field_29 = 'Fseqv - equivalent FW salt flux    ', 'iicefseq', 'kg/m2/d ',    1   ,  1.0     ,    0.0
-   field_30 = 'Brine volume                       ', 'ibrinvol', '%       ',    1   ,  100.0   ,    0.0
-   field_31 = 'Frazil ice collection thickness    ', 'iicecolf', 'm       ',    1   ,  1.0     ,    0.0
-   field_32 = 'Ice strength                       ', 'iicestre', 'N/m     ',    1   ,  0.001   ,    0.0
-   field_33 = 'Ice velocity                       ', 'iicevelo', 'm/s     ',    1   ,  1.0     ,    0.0
-   field_34 = 'Surface melt                       ', 'iicesume', 'km3/day ',    1   ,1.0e-9    ,    0.0
-   field_35 = 'Bottom melt                        ', 'iicebome', 'km3/day ',    1   ,1.0e-9    ,    0.0
-   field_36 = 'Divergence                         ', 'iicedive', '10-8s-1 ',    1   ,  1.0e8   ,    0.0
-   field_37 = 'Shear                              ', 'iiceshea', '10-8s-1 ',    1   ,  1.0e8   ,    0.0
-   field_38 = 'Daily resultant ice prod/melt      ', 'iicerepr', 'km3/day ',    1   ,  1.0e-9  ,    0.0
-   field_39 = 'Ice volume                         ', 'iicevolu', 'km3     ',    1   ,  1.0e-9  ,    0.0
-   field_40 = 'Snow volume                        ', 'isnowvol', 'km3     ',    1   ,  1.0e-9  ,    0.0
-   field_41 = 'Fsrpo - salt flux from ridg/raft   ', 'iicefsrp', 'kg/m2/d ',    1   ,  1.0     ,    0.0
-   field_42 = 'Fsres - salt flux from limupdate   ', 'iicefsre', 'kg/m2/d ',    1   ,  1.0     ,    0.0
-   field_43 = 'Ice volume transport               ', 'iicevtrp', 'km3/day ',    1   ,1.0e-9    ,    0.0
-/ 
 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/namelist_ref
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 4921)
@@ -183,4 +183,11 @@
 /
 !-----------------------------------------------------------------------
+&namc1d        !   1D configuration options                             ("key_c1d")
+!-----------------------------------------------------------------------
+   rn_lat1d    =      50   !  Column latitude (default at PAPA station)
+   rn_lon1d    =    -145   !  Column longitude (default at PAPA station)
+   ln_c1d_locpt=  .true.   ! Localization of 1D config in a grid (T) or independant point (F)
+/
+!-----------------------------------------------------------------------
 &namtsd    !   data : Temperature  & Salinity
 !-----------------------------------------------------------------------
@@ -240,4 +247,6 @@
    ln_cdgw = .false.       !  Neutral drag coefficient read from wave model (T => fill namsbc_wave)
    ln_sdw  = .false.       !  Computation of 3D stokes drift                (T => fill namsbc_wave)
+   nn_lsm  = 0             !  =0 land/sea mask for input fields is not applied (keep empty land/sea mask filename field) ,
+                           !  =1:n number of iterations of land/sea mask application for input fields (fill land/sea mask filename field)
    cn_iceflx = 'linear'    !  redistribution of solar input into ice categories during coupling ice/atm.
 /
@@ -559,4 +568,11 @@
     nn_tra_dta    =  0                    !  = 0, bdy data are equal to the initial state
                                           !  = 1, bdy data are read in 'bdydata   .nc' files
+    cn_ice_lim      =  'none'             !  
+    nn_ice_lim_dta  =  0                  !  = 0, bdy data are equal to the initial state
+                                          !  = 1, bdy data are read in 'bdydata   .nc' files
+    rn_ice_tem      = 270.                !  lim3 only: arbitrary temperature of incoming sea ice
+    rn_ice_sal      = 10.                 !  lim3 only:      --   salinity           --
+    rn_ice_age      = 30.                 !  lim3 only:      --   age                --
+
     ln_tra_dmp    =.false.                !  open boudaries conditions for tracers
     ln_dyn3d_dmp  =.false.                !  open boundary condition for baroclinic velocities
@@ -579,4 +595,12 @@
    bn_tem  =    'amm12_bdyT_tra' ,         24        , 'votemper' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
    bn_sal  =    'amm12_bdyT_tra' ,         24        , 'vosaline' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+! for lim2
+!   bn_frld  =    'amm12_bdyT_ice' ,         24        , 'ileadfra' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_hicif =    'amm12_bdyT_ice' ,         24        , 'iicethic' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_hsnif =    'amm12_bdyT_ice' ,         24        , 'isnowthi' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+! for lim3
+!   bn_a_i  =    'amm12_bdyT_ice' ,         24        , 'ileadfra' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_ht_i =    'amm12_bdyT_ice' ,         24        , 'iicethic' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
+!   bn_ht_s =    'amm12_bdyT_ice' ,         24        , 'isnowthi' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''     , ''
    cn_dir  =    'bdydta/'
    ln_full_vel = .false.
@@ -957,10 +981,4 @@
                            !     (no physical validity of the results)
    nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
-/
-!-----------------------------------------------------------------------
-&namc1d        !   1D configuration options                             ("key_c1d")
-!-----------------------------------------------------------------------
-   rn_lat      =    50     !  Column latitude
-   rn_lon      =    -145   !  Column longitude
 /
 !-----------------------------------------------------------------------
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/cfg.txt
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/cfg.txt	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/CONFIG/cfg.txt	(revision 4921)
@@ -6,7 +6,7 @@
 ORCA2_SAS_LIM OPA_SRC SAS_SRC LIM_SRC_2 NST_SRC
 C1D_PAPA OPA_SRC
-ORCA2_LIM3 OPA_SRC LIM_SRC_3 NST_SRC
 ORCA2_LIM OPA_SRC LIM_SRC_2 NST_SRC
 AMM12 OPA_SRC
 GYRE_BFM OPA_SRC TOP_SRC
 ORCA2_LIM_PISCES OPA_SRC LIM_SRC_2 NST_SRC TOP_SRC
+ORCA2_LIM3 OPA_SRC LIM_SRC_3 NST_SRC
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90	(revision 4921)
@@ -440,5 +440,4 @@
       !--------------------------------------------------------------------------------
       ztmp(:,:) = 1. - pfrld(:,:)                                ! fraction of ice after the dynamic, before the thermodynamic
-      CALL iom_put( 'ioceflxb', fbif )                           ! Oceanic flux at the ice base           [W/m2 ???]
       CALL iom_put( 'ist_cea', (sist(:,:) - rt0) * ztmp(:,:) )   ! Ice surface temperature                [Celius]
       CALL iom_put( 'qsr_ai_cea', qsr_ice(:,:,1) * ztmp(:,:) )   ! Solar flux over the ice                [W/m2]
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90	(revision 4921)
@@ -333,5 +333,4 @@
       CALL histdef( kid, "ileadfra", "Ice concentration"       , "-"      , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
       CALL histdef( kid, "iicetemp", "Ice temperature"         , "K"      , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "ioceflxb", "flux at ice base"        , "w/m2"   , 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 ) 
@@ -351,5 +350,4 @@
       CALL histwrite( kid, "ileadfra", kt, 1. - frld(:,:) , jpi*jpj, (/1/) )
       CALL histwrite( kid, "iicetemp", kt, sist(:,:) - rt0, jpi*jpj, (/1/) )
-      CALL histwrite( kid, "ioceflxb", kt, fbif           , jpi*jpj, (/1/) )
       CALL histwrite( kid, "iicevelu", kt, u_ice          , jpi*jpj, (/1/) )
       CALL histwrite( kid, "iicevelv", kt, v_ice          , jpi*jpj, (/1/) )
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/ice.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/ice.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/ice.F90	(revision 4921)
@@ -105,5 +105,5 @@
    !! ** Global variables                                                 |
    !!-------------|-------------|---------------------------------|-------|
-   !! a_i         | a_i_b       |    Ice concentration            |       |
+   !! a_i         | a_i_1d      |    Ice concentration            |       |
    !! v_i         |      -      |    Ice volume per unit area     | m     |
    !! v_s         |      -      |    Snow volume per unit area    | m     |
@@ -111,7 +111,7 @@
    !! oa_i        !      -      !    Sea ice areal age content    | day   |
    !! e_i         !      -      !    Ice enthalpy                 | 10^9 J| 
-   !!      -      ! q_i_b       !    Ice enthalpy per unit vol.   | J/m3  | 
+   !!      -      ! q_i_1d      !    Ice enthalpy per unit vol.   | J/m3  | 
    !! e_s         !      -      !    Snow enthalpy                | 10^9 J| 
-   !!      -      ! q_s_b       !    Snow enthalpy per unit vol.  | J/m3  | 
+   !!      -      ! q_s_1d      !    Snow enthalpy per unit vol.  | J/m3  | 
    !!                                                                     |
    !!-------------|-------------|---------------------------------|-------|
@@ -120,12 +120,12 @@
    !!-------------|-------------|---------------------------------|-------|
    !!                                                                     |
-   !! ht_i        | ht_i_b      |    Ice thickness                | m     |
-   !! ht_s        ! ht_s_b      |    Snow depth                   | m     |
-   !! sm_i        ! sm_i_b      |    Sea ice bulk salinity        ! ppt   |
-   !! s_i         ! s_i_b       |    Sea ice salinity profile     ! ppt   |
+   !! ht_i        | ht_i_1d     |    Ice thickness                | m     |
+   !! ht_s        ! ht_s_1d     |    Snow depth                   | m     |
+   !! sm_i        ! sm_i_1d     |    Sea ice bulk salinity        ! ppt   |
+   !! s_i         ! s_i_1d      |    Sea ice salinity profile     ! ppt   |
    !! o_i         !      -      |    Sea ice Age                  ! days  |
-   !! t_i         ! t_i_b       |    Sea ice temperature          ! K     |
-   !! t_s         ! t_s_b       |    Snow temperature             ! K     |
-   !! t_su        ! t_su_b      |    Sea ice surface temperature  ! K     |
+   !! t_i         ! t_i_1d      |    Sea ice temperature          ! K     |
+   !! t_s         ! t_s_1d      |    Snow temperature             ! K     |
+   !! t_su        ! t_su_1d     |    Sea ice surface temperature  ! K     |
    !!                                                                     |
    !! notes: the ice model only sees a bulk (i.e., vertically averaged)   |
@@ -142,5 +142,5 @@
    !! ***         Category-summed state variables (diagnostic)        *** |
    !! ******************************************************************* |
-   !! at_i        | at_i_b      |    Total ice concentration      |       |
+   !! at_i        | at_i_1d     |    Total ice concentration      |       |
    !! vt_i        |      -      |    Total ice vol. per unit area | m     |
    !! vt_s        |      -      |    Total snow vol. per unit ar. | m     |
@@ -166,27 +166,19 @@
 
    !                                     !!** ice-dynamic namelist (namicedyn) **
-   INTEGER , PUBLIC ::   nbiter           !: number of sub-time steps for relaxation
-   INTEGER , PUBLIC ::   nbitdr           !: maximum number of iterations for relaxation
    INTEGER , PUBLIC ::   nevp             !: number of iterations for subcycling
-   INTEGER , PUBLIC ::   nlay_i = 5            !: number of layers in the ice
-
-   !                                     !!** ice-dynamic namelist (namicedyn) **
    REAL(wp), PUBLIC ::   epsd             !: tolerance parameter for dynamic
-   REAL(wp), PUBLIC ::   alpha            !: coefficient for semi-implicit coriolis
-   REAL(wp), PUBLIC ::   dm               !: diffusion constant for dynamics
    REAL(wp), PUBLIC ::   om               !: relaxation constant
-   REAL(wp), PUBLIC ::   resl             !: maximum value for the residual of relaxation
    REAL(wp), PUBLIC ::   cw               !: drag coefficient for oceanic stress
    REAL(wp), PUBLIC ::   angvg            !: turning angle for oceanic stress
    REAL(wp), PUBLIC ::   pstar            !: determines ice strength (N/M), Hibler JPO79
    REAL(wp), PUBLIC ::   c_rhg            !: determines changes in ice strength
-   REAL(wp), PUBLIC ::   etamn            !: minimun value for viscosity : has to be 0
    REAL(wp), PUBLIC ::   creepl           !: creep limit : has to be under 1.0e-9
    REAL(wp), PUBLIC ::   ecc              !: eccentricity of the elliptical yield curve
    REAL(wp), PUBLIC ::   ahi0             !: sea-ice hor. eddy diffusivity coeff. (m2/s)
-   REAL(wp), PUBLIC ::   telast           !: timescale for elastic waves (s) !SB
-   REAL(wp), PUBLIC ::   alphaevp         !: coeficient of the internal stresses !SB
+   REAL(wp), PUBLIC ::   telast           !: timescale for elastic waves (s)
+   REAL(wp), PUBLIC ::   relast           !: ratio => telast/rdt_ice (1/3 or 1/9 depending on nb of subcycling nevp) 
+   REAL(wp), PUBLIC ::   alphaevp         !: coeficient of the internal stresses 
    REAL(wp), PUBLIC ::   unit_fac = 1.e+09_wp  !: conversion factor for ice / snow enthalpy
-   REAL(wp), PUBLIC ::   hminrhg = 0.001_wp    !: clem : ice volume (a*h, in m) below which ice velocity is set to ocean velocity
+   REAL(wp), PUBLIC ::   hminrhg          !: ice volume (a*h, in m) below which ice velocity is set to ocean velocity
 
    !                                     !!** ice-salinity namelist (namicesal) **
@@ -202,10 +194,9 @@
 
    !                                     !!** ice-salinity namelist (namicesal) **
-   INTEGER , PUBLIC ::   num_sal          !: salinity configuration used in the model
+   INTEGER , PUBLIC ::   num_sal             !: 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 ::   sal_prof    = 1           !: salinity profile or not 
-   INTEGER , PUBLIC ::   thcon_i_swi          !: thermal conductivity: =1 Untersteiner (1964) ; =2 Pringle et al (2007)
+   INTEGER , PUBLIC ::   thcon_i_swi         !: thermal conductivity: =0 Untersteiner (1964) ; =1 Pringle et al (2007)
 
    !                                     !!** ice-mechanical redistribution namelist (namiceitdme)
@@ -220,5 +211,4 @@
    REAL(wp), PUBLIC ::   Craft            !: coefficient for smoothness of the hyperbolic tangent in rafting
    REAL(wp), PUBLIC ::   ridge_por        !: initial porosity of ridges (0.3 regular value)
-   REAL(wp), PUBLIC ::   sal_max_ridge    !: maximum ridged ice salinity (ppt)
    REAL(wp), PUBLIC ::   betas            !: coef. for partitioning of snowfall between leads and sea ice
    REAL(wp), PUBLIC ::   kappa_i          !: coef. for the extinction of radiation Grenfell et al. (2006) [1/m]
@@ -228,7 +218,6 @@
    !                                     !!** ice-mechanical redistribution namelist (namiceitdme)
    INTEGER , PUBLIC ::   ridge_scheme_swi !: scheme used for ice ridging
-   INTEGER , PUBLIC ::   raftswi          !: rafting of ice or not                        
+   INTEGER , PUBLIC ::   raft_swi         !: rafting of ice or not                        
    INTEGER , PUBLIC ::   partfun_swi      !: participation function: =0 Thorndike et al. (1975), =1 Lipscomb et al. (2007)
-   INTEGER , PUBLIC ::   transfun_swi     !: transfer function: =0 Hibler 1980, =1 Lipscomb et al. 2007
    INTEGER , PUBLIC ::   brinstren_swi    !: use brine volume to diminish ice strength
 
@@ -249,46 +238,60 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   shear_i        !: Shear of the velocity field [s-1]
    !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   firic       !: IR flux over the ice (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fcsic       !: Sensible heat flux over the ice (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fleic       !: Latent heat flux over the ice (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qlatic      !: latent flux
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdvosif     !: Variation of volume at surface (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdvobif     !: Variation of ice volume at the bottom ice (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fdvolif     !: Total variation of ice volume (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdvonif     !: Lateral Variation of ice volume (diag only)
    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(:,:) ::   hicifp      !: Ice production/melting==>!obsolete... can be removed
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   frld        !: Leads fraction = 1 - ice fraction
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   pfrld       !: Leads fraction at previous time  
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   phicif      !: Old ice thickness
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fbif        !: Heat flux at the ice base
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdm_snw     !: Variation of snow mass over 1 time step     [Kg/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdq_snw     !: Heat content associated with rdm_snw        [J/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdm_ice     !: Variation of ice mass over 1 time step      [Kg/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdq_ice     !: Heat content associated with rdm_ice        [J/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qldif       !: heat balance of the lead (or of the open ocean)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qcmif       !: Energy needed to bring the ocean to freezing 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fdtcn       !: net downward heat flux from the ice to the ocean
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qdtcn       !: energy from the ice to the ocean
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fstric      !: transmitted solar radiation under ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fscmbq      !: associated with lead chipotage with solar flux
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ffltbif     !: related to max heat contained in brine pockets (?)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fsbbq       !: Also linked with the solar flux below the ice (?)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qfvbq       !: store energy in case of total lateral ablation (?)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   dmgwi       !: Variation of the mass of snow ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx_thd     !: salt flux due to ice growth/melt                      [PSU/m2/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qlead       !: heat balance of the lead (or of the open ocean)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fhtur       !: net downward heat flux from the ice to the ocean
+   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 over 1 time step [kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_spr    !: snow precipitation on ice over 1 time step [kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_sub    !: snow sublimation over 1 time step [kg/m2]
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_ice    !: ice-ocean mass exchange over 1 time step [kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_sni    !: snow ice growth component of wfx_ice [kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_opw    !: lateral ice growth component of wfx_ice [kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_bog    !: bottom ice growth component of wfx_ice [kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_dyn    !: dynamical ice growth component of wfx_ice [kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_bom    !: bottom melt component of wfx_ice [kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_sum    !: surface melt component of wfx_ice [kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_res    !: residual component of wfx_ice [kg/m2]
+
+   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_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]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx_opw     !: salt flux due to ice growth/melt                      [PSU/m2/s]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx_bri     !: salt flux due to brine rejection                      [PSU/m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx_mec     !: salt flux due to porous ridged ice formation          [PSU/m2/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx_dyn     !: salt flux due to porous ridged ice formation          [PSU/m2/s]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx_res     !: residual salt flux due to correction of ice thickness [PSU/m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fhbri       !: heat flux due to brine rejection
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fheat_mec   !: heat flux associated with porous ridged ice formation [???]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fheat_res   !: residual heat flux due to correction of ice thickness
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fmmec       !: mass flux due to snow loss during compression         [Kg/m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fhmec       !: heat flux due to snow loss during compression
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_bog     !: total heat flux causing bottom ice growth 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_bom     !: total heat flux causing bottom ice melt 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_sum     !: total heat flux causing surface ice melt 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_opw     !: total heat flux causing open water ice formation
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_dif     !: total heat flux causing Temp change in the ice 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_snw     !: heat flux for snow melt 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_err     !: heat flux error after heat diffusion 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_err_rem !: heat flux error after heat remapping 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_in      !: heat flux available for thermo transformations 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_out     !: heat flux remaining at the end of thermo transformations 
+
+   ! heat flux associated with ice-atmosphere mass exchange
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_sub     !: heat flux for sublimation 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_spr     !: heat flux of the snow precipitation 
+
+   ! heat flux associated with ice-ocean mass exchange
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_thd     !: ice-ocean heat flux from thermo processes (limthd_dh) 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_dyn     !: ice-ocean heat flux from mecanical processes (limitd_me) 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_res     !: residual heat flux due to correction of ice thickness
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ftr_ice   !: transmitted solar radiation under ice
 
    ! temporary arrays for dummy version of the code
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   dh_i_surf2D, dh_i_bott2D, fstbif, fsup2D, focea2D, q_s
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   dh_i_surf2D, dh_i_bott2D, q_s
 
    !!--------------------------------------------------------------------------
@@ -321,11 +324,6 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   smt_i          !: mean sea ice salinity averaged over all categories [PSU]
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   at_i_typ     !: total area   contained in each ice type [m^2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   vt_i_typ     !: total volume contained in each ice type [m^3]
-
    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(:,:,:)   ::   e_i_cat    !: ! go to trash
       
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   t_i        !: ice temperatures          [K]
@@ -348,9 +346,9 @@
    !! * Old values of global variables
    !!--------------------------------------------------------------------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   old_v_s, old_v_i               !: snow and ice volumes
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   old_a_i, old_smv_i, old_oa_i   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   old_e_s                        !: snow heat content
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   old_e_i                        !: ice temperatures
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   old_u_ice, old_v_ice           !: ice velocity (gv6 and gv7)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   v_s_b, v_i_b               !: snow and ice volumes
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   a_i_b, smv_i_b, oa_i_b     !:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_s_b                      !: snow heat content
+   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
       
 
@@ -375,14 +373,6 @@
    !! * Ice thickness distribution variables
    !!--------------------------------------------------------------------------
-   ! REMOVE
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   ice_types      !: Vector connecting types and categories
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ice_cat_bounds !: Matrix containing the integer upper and 
-   !                                                                       !  lower boundaries of ice thickness categories
-   ! REMOVE
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   ice_ncat_types !: nb of thickness categories in each ice type
    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 
-   ! REMOVE
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hi_max_typ     !: Boundary of ice thickness categories in thickness space
 
    !!--------------------------------------------------------------------------
@@ -404,15 +394,13 @@
    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(:,:)   ::   v_newice   !: volume of ice formed in the leads
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dv_dt_thd  !: thermodynamic growth rates 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   izero, fstroc, fhbricat
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_sni_gr   ! snow ice growth 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_lat_gr   ! lateral ice growth 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_bot_gr   ! bottom ice growth 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_dyn_gr   ! dynamical ice growth 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_bot_me   ! vertical bottom melt 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_sur_me   ! vertical surface melt
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_res_pr   ! production (growth+melt) due to limupdate
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_trp_vi   ! transport of ice volume
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dv_dt_thd     !: thermodynamic growth rates 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   izero
+   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
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_trp_ei   !: transport of ice enthalpy (W/m2)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_trp_es   !: transport of snw enthalpy (W/m2)
+   !
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_heat_dhc !: snw/ice heat content variation   [W/m2] 
+   !
    INTEGER , PUBLIC ::   jiindx, jjindx        !: indexes of the debugging point
 
@@ -447,19 +435,19 @@
 
       ii = ii + 1
-      ALLOCATE( firic    (jpi,jpj) , fcsic  (jpi,jpj) , fleic  (jpi,jpj) , qlatic   (jpi,jpj) ,     &
-         &      rdvosif  (jpi,jpj) , rdvobif(jpi,jpj) , fdvolif(jpi,jpj) , rdvonif  (jpi,jpj) ,     &
-         &      sist     (jpi,jpj) , icethi (jpi,jpj) , t_bo   (jpi,jpj) , hicifp   (jpi,jpj) ,     &
-         &      frld     (jpi,jpj) , pfrld  (jpi,jpj) , phicif (jpi,jpj) , fbif     (jpi,jpj) ,     &
-         &      rdm_snw  (jpi,jpj) , rdq_snw(jpi,jpj) , rdm_ice(jpi,jpj) , rdq_ice  (jpi,jpj) ,     &
-         &                                              qldif  (jpi,jpj) , qcmif    (jpi,jpj) ,     &
-         &      fdtcn    (jpi,jpj) , qdtcn  (jpi,jpj) , fstric (jpi,jpj) , fscmbq   (jpi,jpj) ,     &
-         &      ffltbif  (jpi,jpj) , fsbbq  (jpi,jpj) , qfvbq  (jpi,jpj) , dmgwi    (jpi,jpj) ,     &
-         &      sfx_res  (jpi,jpj) , sfx_bri(jpi,jpj) , sfx_mec(jpi,jpj) , fheat_mec(jpi,jpj) ,     &
-         &      fhbri    (jpi,jpj) , fmmec  (jpi,jpj) , sfx_thd(jpi,jpj) , fhmec    (jpi,jpj) ,     &
-         &      fheat_res(jpi,jpj)                                                            , STAT=ierr(ii) )
-
-      ii = ii + 1
-      ALLOCATE( dh_i_surf2D(jpi,jpj) , dh_i_bott2D(jpi,jpj) , fstbif(jpi,jpj) ,     &
-         &      fsup2D     (jpi,jpj) , focea2D    (jpi,jpj) , q_s   (jpi,jpj) , STAT=ierr(ii) )
+      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) ,    &
+         &      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) ,  qlead  (jpi,jpj) ,     &
+         &      fhtur  (jpi,jpj) , ftr_ice(jpi,jpj,jpl) ,      &
+         &      sfx_res(jpi,jpj) , sfx_bri(jpi,jpj) , sfx_dyn(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_rem(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) )
+
+      ii = ii + 1
+      ALLOCATE( dh_i_surf2D(jpi,jpj) , dh_i_bott2D(jpi,jpj) , q_s(jpi,jpj) , STAT=ierr(ii) )
 
       ! * Ice global state variables
@@ -475,8 +463,8 @@
          &      bv_i (jpi,jpj) , smt_i(jpi,jpj)                                   , STAT=ierr(ii) )
       ii = ii + 1
-      ALLOCATE( t_s(jpi,jpj,nlay_s,jpl) , at_i_typ(jpi,jpj,jpm) ,                            &
-         &      e_s(jpi,jpj,nlay_s,jpl) , vt_i_typ(jpi,jpj,jpm) , e_i_cat(jpi,jpj,jpl) , STAT=ierr(ii) )
-      ii = ii + 1
-      ALLOCATE( t_i(jpi,jpj,jkmax,jpl) , e_i(jpi,jpj,jkmax,jpl) , s_i(jpi,jpj,jkmax,jpl) , STAT=ierr(ii) )
+      ALLOCATE( t_s(jpi,jpj,nlay_s,jpl) ,                            &
+         &      e_s(jpi,jpj,nlay_s,jpl) , STAT=ierr(ii) )
+      ii = ii + 1
+      ALLOCATE( t_i(jpi,jpj,nlay_i+1,jpl) , e_i(jpi,jpj,nlay_i+1,jpl) , s_i(jpi,jpj,nlay_i+1,jpl) , STAT=ierr(ii) )
 
       ! * Moments for advection
@@ -494,13 +482,13 @@
          &      STAT=ierr(ii) )
       ii = ii + 1
-      ALLOCATE( sxe (jpi,jpj,jkmax,jpl) , sye (jpi,jpj,jkmax,jpl) , sxxe(jpi,jpj,jkmax,jpl) ,     &
-         &      syye(jpi,jpj,jkmax,jpl) , sxye(jpi,jpj,jkmax,jpl)                           , STAT=ierr(ii) )
+      ALLOCATE( sxe (jpi,jpj,nlay_i+1,jpl) , sye (jpi,jpj,nlay_i+1,jpl) , sxxe(jpi,jpj,nlay_i+1,jpl) ,     &
+         &      syye(jpi,jpj,nlay_i+1,jpl) , sxye(jpi,jpj,nlay_i+1,jpl)                           , STAT=ierr(ii) )
 
       ! * Old values of global variables
       ii = ii + 1
-      ALLOCATE( old_v_s  (jpi,jpj,jpl) , old_v_i  (jpi,jpj,jpl) , old_e_s(jpi,jpj,nlay_s,jpl) ,     &
-         &      old_a_i  (jpi,jpj,jpl) , old_smv_i(jpi,jpj,jpl) , old_e_i(jpi,jpj,jkmax ,jpl) ,     &
-         &      old_oa_i (jpi,jpj,jpl)                                                        ,     &
-         &      old_u_ice(jpi,jpj)     , old_v_ice(jpi,jpj)                                   , STAT=ierr(ii) )
+      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+1 ,jpl) ,     &
+         &      oa_i_b (jpi,jpj,jpl)                                                        ,     &
+         &      u_ice_b(jpi,jpj)     , v_ice_b(jpi,jpj)                                   , STAT=ierr(ii) )
 
       ! * Increment of global variables
@@ -512,18 +500,16 @@
          &     STAT=ierr(ii) )
       ii = ii + 1
-      ALLOCATE( d_e_s_thd(jpi,jpj,nlay_s,jpl) , d_e_i_thd(jpi,jpj,jkmax,jpl) , d_u_ice_dyn(jpi,jpj) ,     &
-         &      d_e_s_trp(jpi,jpj,nlay_s,jpl) , d_e_i_trp(jpi,jpj,jkmax,jpl) , d_v_ice_dyn(jpi,jpj) , STAT=ierr(ii) )
+      ALLOCATE( d_e_s_thd(jpi,jpj,nlay_s,jpl) , d_e_i_thd(jpi,jpj,nlay_i+1,jpl) , d_u_ice_dyn(jpi,jpj) ,     &
+         &      d_e_s_trp(jpi,jpj,nlay_s,jpl) , d_e_i_trp(jpi,jpj,nlay_i+1,jpl) , d_v_ice_dyn(jpi,jpj) , STAT=ierr(ii) )
       
       ! * Ice thickness distribution variables
       ii = ii + 1
-      ALLOCATE( ice_types(jpl) , ice_cat_bounds(jpm,2) , ice_ncat_types  (jpm) ,     &
-         &      hi_max (0:jpl) , hi_mean(jpl)          , hi_max_typ(0:jpl,jpm) , STAT=ierr(ii) )
+      ALLOCATE( hi_max(0:jpl), hi_mean(jpl),  STAT=ierr(ii) )
 
       ! * Ice diagnostics
       ii = ii + 1
-      ALLOCATE( dv_dt_thd(jpi,jpj,jpl) , diag_sni_gr(jpi,jpj) , diag_lat_gr(jpi,jpj) ,     &
-         &      izero    (jpi,jpj,jpl) , diag_bot_gr(jpi,jpj) , diag_dyn_gr(jpi,jpj) ,     &
-         &      fstroc   (jpi,jpj,jpl) , diag_bot_me(jpi,jpj) , diag_sur_me(jpi,jpj) ,     &
-         &      fhbricat (jpi,jpj,jpl) , diag_res_pr(jpi,jpj) , diag_trp_vi(jpi,jpj) , v_newice(jpi,jpj) , STAT=ierr(ii) )
+      ALLOCATE( dv_dt_thd(jpi,jpj,jpl), izero (jpi,jpj,jpl),    &
+         &      diag_trp_vi(jpi,jpj), diag_trp_vs  (jpi,jpj), diag_trp_ei(jpi,jpj),   & 
+         &      diag_trp_es(jpi,jpj), diag_heat_dhc(jpi,jpj),  STAT=ierr(ii) )
 
       ice_alloc = MAXVAL( ierr(:) )
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/iceini.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/iceini.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/iceini.F90	(revision 4921)
@@ -66,6 +66,6 @@
       !
       !                                ! adequation jpk versus ice/snow layers/categories
-      IF( jpl   > jpk  .OR.  jpm    > jpk .OR.                                    &
-          jkmax > jpk  .OR.  nlay_s > jpk      )   CALL ctl_stop( 'STOP',         &
+      IF( jpl > jpk .OR. (nlay_i+1) > jpk .OR. nlay_s > jpk )   &
+         &      CALL ctl_stop( 'STOP',                     &
          &     'ice_init: the 3rd dimension of workspace arrays is too small.',   &
          &     'use more ocean levels or less ice/snow layers/categories.' )
@@ -89,4 +89,5 @@
       CALL lim_itd_ini                 ! ice thickness distribution initialization
       !
+      CALL lim_itd_me_init             ! ice thickness distribution initialization
       !                                ! Initial sea-ice state
       IF( .NOT. ln_rstart ) THEN              ! start from rest
@@ -173,5 +174,5 @@
       !!              limistate (only) and is changed to 99 m in ice_init
       !!------------------------------------------------------------------
-      INTEGER  ::   jl, jm               ! dummy loop index
+      INTEGER  ::   jl                   ! dummy loop index
       REAL(wp) ::   zc1, zc2, zc3, zx1   ! local scalars
       !!------------------------------------------------------------------
@@ -184,33 +185,6 @@
       ! 1) Ice thickness distribution parameters initialization    
       !------------------------------------------------------------------------------!
-
-      !- Types boundaries (integer)
-      !----------------------------
-      ice_cat_bounds(1,1) = 1
-      ice_cat_bounds(1,2) = jpl
-
-      !- Number of ice thickness categories in each ice type
-      DO jm = 1, jpm
-         ice_ncat_types(jm) = ice_cat_bounds(jm,2) - ice_cat_bounds(jm,1) + 1 
-      END DO
-
-      !- Make the correspondence between thickness categories and ice types
-      !---------------------------------------------------------------------
-      DO jm = 1, jpm       !over types
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2) !over thickness categories
-            ice_types(jl) = jm
-         END DO
-      END DO
-
       IF(lwp) THEN  
-         WRITE(numout,*) ' Number of ice types jpm =      ', jpm
          WRITE(numout,*) ' Number of ice categories jpl = ', jpl
-         DO jm = 1, jpm
-            WRITE(numout,*) ' Ice type ', jm
-            WRITE(numout,*) ' Number of thickness categories ', ice_ncat_types(jm)
-            WRITE(numout,*) ' Thickness category boundaries  ', ice_cat_bounds(jm,1:2)
-         END DO
-         WRITE(numout,*) 'Ice type vector', ice_types(1:jpl)
-         WRITE(numout,*)
       ENDIF
 
@@ -218,33 +192,17 @@
       !----------------------------------
       hi_max(:) = 0._wp
-      hi_max_typ(:,:) = 0._wp
-
-      !- Type 1 - undeformed ice
-      zc1 =  3._wp / REAL( ice_cat_bounds(1,2) - ice_cat_bounds(1,1) + 1 , wp )
+
+      zc1 =  3._wp / REAL( jpl, wp )
       zc2 = 10._wp * zc1
       zc3 =  3._wp
 
-      DO jl = ice_cat_bounds(1,1), ice_cat_bounds(1,2)
-         zx1 = REAL( jl-1 , wp ) / REAL( ice_cat_bounds(1,2) - ice_cat_bounds(1,1) + 1 , wp )
+      DO jl = 1, jpl
+         zx1 = REAL( jl-1, wp ) / REAL( jpl, wp )
          hi_max(jl) = hi_max(jl-1) + zc1 + zc2 * (1._wp + TANH( zc3 * (zx1 - 1._wp ) ) )
       END DO
 
-      !- Fill in the hi_max_typ vector, useful in other circumstances
-      ! Tricky trick: hi_max_typ is actually not used in the code and will be removed in a
-      ! next flyspray at this time, the tricky trick will also be removed (Martin, march 08)
-      DO jl = ice_cat_bounds(1,1), ice_cat_bounds(1,2)
-         hi_max_typ(jl,1) = hi_max(jl)
-      END DO
-
-      IF(lwp) WRITE(numout,*) ' Thickness category boundaries independently of ice type '
+      IF(lwp) WRITE(numout,*) ' Thickness category boundaries '
       IF(lwp) WRITE(numout,*) ' hi_max ', hi_max(0:jpl)
 
-      IF(lwp) WRITE(numout,*) ' Thickness category boundaries inside ice types '
-      IF(lwp) THEN 
-         DO jm = 1, jpm
-            WRITE(numout,*) ' Type number ', jm
-            WRITE(numout,*) ' hi_max_typ : ', hi_max_typ(0:ice_ncat_types(jm),jm)
-         END DO
-      ENDIF
       !
       DO jl = 1, jpl
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limadv.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limadv.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limadv.F90	(revision 4921)
@@ -32,6 +32,4 @@
 
    REAL(wp)  ::   epsi20 = 1.e-20_wp   ! constant values
-   REAL(wp)  ::   rzero  = 0._wp       !    -       -
-   REAL(wp)  ::   rone   = 1._wp       !    -       -
 
    !! * Substitutions
@@ -84,10 +82,10 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            zslpmax = MAX( rzero, ps0(ji,jj) )
+            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) )  )
-            zin0    = ( 1.0 - MAX( rzero, SIGN( rone, -zslpmax) ) ) * tms(ji,jj)   ! Case of empty boxes & Apply mask
+            zin0    = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zslpmax) ) ) * tms(ji,jj)   ! Case of empty boxes & Apply mask
 
             ps0 (ji,jj) = zslpmax  
@@ -106,6 +104,6 @@
       DO jj = 1, jpj                      !  Flux from i to i+1 WHEN u GT 0 
          DO ji = 1, jpi
-            zbet(ji,jj)  =  MAX( rzero, SIGN( rone, put(ji,jj) ) )
-            zalf         =  MAX( rzero, put(ji,jj) ) * zrdt * e2u(ji,jj) / psm(ji,jj)
+            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
@@ -133,5 +131,5 @@
       DO jj = 1, jpjm1                      !  Flux from i+1 to i when u LT 0.
          DO ji = 1, fs_jpim1
-            zalf          = MAX( rzero, -put(ji,jj) ) * zrdt * e2u(ji,jj) / psm(ji+1,jj) 
+            zalf          = MAX( 0._wp, -put(ji,jj) ) * zrdt * e2u(ji,jj) / psm(ji+1,jj) 
             zalg  (ji,jj) = zalf
             zalfq         = zalf * zalf
@@ -269,10 +267,10 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            zslpmax = MAX( rzero, ps0(ji,jj) )
+            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) )  )
-            zin0    = ( 1.0 - MAX( rzero, SIGN( rone, -zslpmax) ) ) * tms(ji,jj)   ! Case of empty boxes & Apply mask
+            zin0    = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zslpmax) ) ) * tms(ji,jj)   ! Case of empty boxes & Apply mask
             !
             ps0 (ji,jj) = zslpmax  
@@ -291,6 +289,6 @@
       DO jj = 1, jpj                     !  Flux from j to j+1 WHEN v GT 0   
          DO ji = 1, jpi
-            zbet(ji,jj)  =  MAX( rzero, SIGN( rone, pvt(ji,jj) ) )
-            zalf         =  MAX( rzero, pvt(ji,jj) ) * zrdt * e1v(ji,jj) / psm(ji,jj)
+            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
@@ -318,5 +316,5 @@
       DO jj = 1, jpjm1                   !  Flux from j+1 to j when v LT 0.
          DO ji = 1, jpi
-            zalf          = ( MAX(rzero, -pvt(ji,jj) ) * zrdt * e1v(ji,jj) ) / psm(ji,jj+1) 
+            zalf          = ( MAX(0._wp, -pvt(ji,jj) ) * zrdt * e1v(ji,jj) ) / psm(ji,jj+1) 
             zalg  (ji,jj) = zalf
             zalfq         = zalf * zalf
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limcons.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limcons.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limcons.F90	(revision 4921)
@@ -7,4 +7,5 @@
    !!            3.0  ! 2004-06  (M. Vancoppenolle)   Energy Conservation 
    !!            4.0  ! 2011-02  (G. Madec)  add mpp considerations
+   !!             -   ! 2014-05  (C. Rousset) add lim_cons_hsm
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -14,4 +15,5 @@
    !!    lim_cons     :   checks whether energy, mass and salt are conserved 
    !!----------------------------------------------------------------------
+   USE phycst         ! physical constants
    USE par_ice        ! LIM-3 parameter
    USE ice            ! LIM-3 variables
@@ -28,4 +30,5 @@
    PUBLIC   lim_column_sum_energy
    PUBLIC   lim_cons_check
+   PUBLIC   lim_cons_hsm
 
    !!----------------------------------------------------------------------
@@ -70,8 +73,8 @@
       !! ** Method  : Arithmetics
       !!---------------------------------------------------------------------
-      INTEGER                               , INTENT(in   ) ::   ksum   !: number of categories
-      INTEGER                               , INTENT(in   ) ::   klay   !: number of vertical layers
-      REAL(wp), DIMENSION(jpi,jpj,jkmax,jpl), INTENT(in   ) ::   pin   !: input field
-      REAL(wp), DIMENSION(jpi,jpj)          , INTENT(  out) ::   pout   !: output field
+      INTEGER                                  , INTENT(in   ) ::   ksum   !: number of categories
+      INTEGER                                  , INTENT(in   ) ::   klay   !: number of vertical layers
+      REAL(wp), DIMENSION(jpi,jpj,nlay_i+1,jpl), INTENT(in   ) ::   pin   !: input field
+      REAL(wp), DIMENSION(jpi,jpj)             , INTENT(  out) ::   pout   !: output field
       !
       INTEGER ::   jk, jl   ! dummy loop indices
@@ -151,4 +154,69 @@
    END SUBROUTINE lim_cons_check
 
+
+   SUBROUTINE lim_cons_hsm( icount, cd_routine, zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b )
+      !!-------------------------------------------------------------------
+      !!               ***  ROUTINE lim_cons_hsm ***
+      !!
+      !! ** Purpose : Test the conservation of heat, salt and mass for each routine
+      !!
+      !! ** Method  :
+      !!---------------------------------------------------------------------
+      INTEGER         , INTENT(in)    :: icount      ! determine wether this is the beggining of the routine (0) or the end (1)
+      CHARACTER(len=*), INTENT(in)    :: cd_routine  ! name of the routine
+      REAL(wp)        , INTENT(inout) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
+      REAL(wp)                        :: zvi,   zsmv,   zei,   zfs,   zfw,   zft
+      REAL(wp)                        :: zvmin, zamin, zamax 
+
+      IF( icount == 0 ) THEN
+
+         zvi_b  = glob_sum( SUM(   v_i(:,:,:)*rhoic + v_s(:,:,:)*rhosn, dim=3 ) * area(:,:) * tms(:,:) )
+         zsmv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zei_b  = glob_sum( SUM(   e_i(:,:,1:nlay_i,:), dim=3 ) + SUM( e_s(:,:,1:nlay_s,:), dim=3 ) )
+         zfw_b  = glob_sum( - ( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) + wfx_opw(:,:) +  &
+            &                   wfx_res(:,:) + wfx_dyn(:,:) + wfx_snw(:,:) + wfx_sub(:,:) + wfx_spr(:,:)    &
+            &             ) * area(:,:) * tms(:,:) )
+         zfs_b  = glob_sum(   ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) +  &
+            &                   sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:)                                  &
+            &                 ) * area(:,:) * tms(:,:) )
+         zft_b  = glob_sum(   ( hfx_sum(:,:) + hfx_bom(:,:) + hfx_bog(:,:) + hfx_dif(:,:) + hfx_opw(:,:) + hfx_snw(:,:)  & 
+            &                 - hfx_thd(:,:) - hfx_dyn(:,:) - hfx_res(:,:) - hfx_sub(:,:) - hfx_spr(:,:)   &
+            &                  ) * area(:,:) / unit_fac * tms(:,:) )
+
+      ELSEIF( icount == 1 ) THEN
+
+         zfs  = glob_sum(   ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) +  &
+            &                 sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:)                                  & 
+            &                ) * area(:,:) * tms(:,:) ) - zfs_b
+         zfw  = glob_sum( - ( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) + wfx_opw(:,:) +  &
+            &                 wfx_res(:,:) + wfx_dyn(:,:) + wfx_snw(:,:) + wfx_sub(:,:) + wfx_spr(:,:)    &
+            &                ) * area(:,:) * tms(:,:) ) - zfw_b
+         zft  = glob_sum(   ( hfx_sum(:,:) + hfx_bom(:,:) + hfx_bog(:,:) + hfx_dif(:,:) + hfx_opw(:,:) + hfx_snw(:,:)  & 
+            &               - hfx_thd(:,:) - hfx_dyn(:,:) - hfx_res(:,:) - hfx_sub(:,:) - hfx_spr(:,:)   &
+            &                ) * area(:,:) / unit_fac * tms(:,:) ) - zft_b
+ 
+         zvi  = ( glob_sum( SUM(   v_i(:,:,:)*rhoic + v_s(:,:,:)*rhosn, dim=3 ) * area(:,:) * tms(:,:) ) - zvi_b ) * r1_rdtice - zfw 
+         zsmv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zsmv_b ) * r1_rdtice + ( zfs / rhoic )
+         zei  =   glob_sum( SUM( e_i(:,:,1:nlay_i,:), dim=3 ) + SUM( e_s(:,:,1:nlay_s,:), dim=3 ) ) * r1_rdtice - zei_b * r1_rdtice + zft
+
+         zvmin = glob_min(v_i)
+         zamax = glob_max(SUM(a_i,dim=3))
+         zamin = glob_min(a_i)
+       
+         IF(lwp) THEN
+            IF ( ABS( zvi    ) >  1.e-4 ) WRITE(numout,*) 'violation volume [kg/day]     (',cd_routine,') = ',(zvi * rday)
+            IF ( ABS( zsmv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (',cd_routine,') = ',(zsmv * rday)
+            IF ( ABS( zei    ) >  1.    ) WRITE(numout,*) 'violation enthalpy [1e9 J]    (',cd_routine,') = ',(zei)
+            IF ( zvmin <  0.            ) WRITE(numout,*) 'violation v_i<0  [m]          (',cd_routine,') = ',(zvmin)
+            IF( cd_routine /= 'limtrp' .AND. cd_routine /= 'limitd_me' .AND. zamax > amax+1.e-10 ) THEN
+                                          WRITE(numout,*) 'violation a_i>amax            (',cd_routine,') = ',zamax
+            ENDIF
+            IF ( zamin <  0.            ) WRITE(numout,*) 'violation a_i<0               (',cd_routine,') = ',zamin
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE lim_cons_hsm
+
 #else
    !!----------------------------------------------------------------------
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90	(revision 4921)
@@ -18,4 +18,5 @@
    USE dom_oce         ! ocean domain
    USE sbc_oce         ! surface boundary condition: ocean fields
+   USE sbc_ice         ! Surface boundary condition: sea-ice fields
    USE daymod          ! model calendar
    USE phycst          ! physical constant
@@ -37,6 +38,4 @@
    REAL(dp) ::   bg_grme            ! global ice growth+melt trends
    REAL(wp) ::   epsi06 = 1.e-6_wp  ! small number
-   REAL(wp) ::   epsi03 = 1.e-3_wp  ! small number
-
 
    !! * Substitutions
@@ -60,6 +59,11 @@
       !!
       REAL(dp)   ::   zbg_ivo, zbg_svo, zbg_are, zbg_sal ,zbg_tem ,zbg_ihc ,zbg_shc
-      REAL(dp)   ::   zbg_sfx, zbg_sfx_bri, zbg_sfx_thd, zbg_sfx_res, zbg_sfx_mec 
-      REAL(dp)   ::   zbg_emp, zbg_emp_bog, zbg_emp_lag, zbg_emp_sig, zbg_emp_dyg, zbg_emp_bom, zbg_emp_sum, zbg_emp_res 
+      REAL(dp)   ::   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 
+      REAL(dp)   ::   zbg_vfx, zbg_vfx_bog, zbg_vfx_opw, zbg_vfx_sni, zbg_vfx_dyn
+      REAL(dp)   ::   zbg_vfx_bom, zbg_vfx_sum, zbg_vfx_res, zbg_vfx_spr, zbg_vfx_snw, zbg_vfx_sub  
+      REAL(dp)   ::   zbg_hfx_dhc, zbg_hfx_spr
+      REAL(dp)   ::   zbg_hfx_res, zbg_hfx_sub, zbg_hfx_dyn, zbg_hfx_thd, zbg_hfx_snw, zbg_hfx_out, zbg_hfx_in   
+      REAL(dp)   ::   zbg_hfx_sum, zbg_hfx_bom, zbg_hfx_bog, zbg_hfx_dif, zbg_hfx_opw
       REAL(dp)   ::   z_frc_vol, z_frc_sal, z_bg_grme 
       REAL(dp)   ::   z1_area                     !    -     -
@@ -86,22 +90,48 @@
       !zbg_shc = glob_sum( et_s(:,:) * area(:,:) * tms(:,:) ) / MAX( zbg_svo,epsi06 ) ! snow heat content
 
-      zbg_ihc = glob_sum( et_i(:,:) * 1.e-11 ) ! ice heat content  [10^9*1.e-11 J]
-      zbg_shc = glob_sum( et_s(:,:) * 1.e-11 ) ! snow heat content [10^9*1.e-11 J]
-
-      zbg_emp     = zinda * glob_sum(         emp(:,:) * area(:,:) * tms(:,:) ) * z1_area         * r1_rau0 * rday
-      zbg_emp_bog = zinda * glob_sum( diag_bot_gr(:,:) * area(:,:) * tms(:,:) ) * z1_area * rhoic * r1_rau0 * rday
-      zbg_emp_lag = zinda * glob_sum( diag_lat_gr(:,:) * area(:,:) * tms(:,:) ) * z1_area * rhoic * r1_rau0 * rday
-      zbg_emp_sig = zinda * glob_sum( diag_sni_gr(:,:) * area(:,:) * tms(:,:) ) * z1_area * rhoic * r1_rau0 * rday
-      zbg_emp_dyg = zinda * glob_sum( diag_dyn_gr(:,:) * area(:,:) * tms(:,:) ) * z1_area * rhoic * r1_rau0 * rday
-      zbg_emp_bom = zinda * glob_sum( diag_bot_me(:,:) * area(:,:) * tms(:,:) ) * z1_area * rhoic * r1_rau0 * rday
-      zbg_emp_sum = zinda * glob_sum( diag_sur_me(:,:) * area(:,:) * tms(:,:) ) * z1_area * rhoic * r1_rau0 * rday
-      zbg_emp_res = zinda * glob_sum( diag_res_pr(:,:) * area(:,:) * tms(:,:) ) * z1_area * rhoic * r1_rau0 * rday
-
+      ! Volume
+      zbg_vfx     = zinda * glob_sum(      emp(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_vfx_bog = zinda * glob_sum( wfx_bog(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_vfx_opw = zinda * glob_sum( wfx_opw(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_vfx_sni = zinda * glob_sum( wfx_sni(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_vfx_dyn = zinda * glob_sum( wfx_dyn(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_vfx_bom = zinda * glob_sum( wfx_bom(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_vfx_sum = zinda * glob_sum( wfx_sum(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_vfx_res = zinda * glob_sum( wfx_res(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_vfx_spr = zinda * glob_sum( wfx_spr(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_vfx_snw = zinda * glob_sum( wfx_snw(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_vfx_sub = zinda * glob_sum( wfx_sub(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+
+      ! Salt
       zbg_sfx     = zinda * glob_sum(     sfx(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
       zbg_sfx_bri = zinda * glob_sum( sfx_bri(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
-      zbg_sfx_thd = zinda * glob_sum( sfx_thd(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
       zbg_sfx_res = zinda * glob_sum( sfx_res(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
-      zbg_sfx_mec = zinda * glob_sum( sfx_mec(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
-      
+      zbg_sfx_dyn = zinda * glob_sum( sfx_dyn(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+
+      zbg_sfx_bog = zinda * glob_sum( sfx_bog(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_sfx_opw = zinda * glob_sum( sfx_opw(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_sfx_sni = zinda * glob_sum( sfx_sni(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_sfx_bom = zinda * glob_sum( sfx_bom(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+      zbg_sfx_sum = zinda * glob_sum( sfx_sum(:,:) * area(:,:) * tms(:,:) ) * z1_area * r1_rau0 * rday
+
+      ! Heat budget
+      zbg_ihc      = glob_sum( et_i(:,:) * 1.e-20 ) ! ice heat content  [1.e-20 J]
+      zbg_shc      = glob_sum( et_s(:,:) * 1.e-20 ) ! snow heat content [1.e-20 J]
+      zbg_hfx_dhc  = glob_sum( diag_heat_dhc(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+      zbg_hfx_spr  = glob_sum( hfx_spr(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+
+      zbg_hfx_thd  = glob_sum( hfx_thd(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+      zbg_hfx_dyn  = glob_sum( hfx_dyn(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+      zbg_hfx_res  = glob_sum( hfx_res(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+      zbg_hfx_sub  = glob_sum( hfx_sub(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+      zbg_hfx_snw  = glob_sum( hfx_snw(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+      zbg_hfx_sum  = glob_sum( hfx_sum(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+      zbg_hfx_bom  = glob_sum( hfx_bom(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+      zbg_hfx_bog  = glob_sum( hfx_bog(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+      zbg_hfx_dif  = glob_sum( hfx_dif(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+      zbg_hfx_opw  = glob_sum( hfx_opw(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+      zbg_hfx_out  = glob_sum( hfx_out(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+      zbg_hfx_in   = glob_sum(  hfx_in(:,:) * area(:,:) * tms(:,:) ) ! [in W]
+    
       ! --------------------------------------------- !
       ! 2 - Trends due to forcing and ice growth/melt !
@@ -109,6 +139,6 @@
       z_frc_vol = r1_rau0 * glob_sum( - emp(:,:) * area(:,:) * tms(:,:) ) ! volume fluxes
       z_frc_sal = r1_rau0 * glob_sum(   sfx(:,:) * area(:,:) * tms(:,:) ) ! salt fluxes
-      z_bg_grme = glob_sum( ( diag_bot_gr(:,:) + diag_lat_gr(:,:) + diag_sni_gr(:,:) + diag_dyn_gr(:,:) + &
-                          &    diag_bot_me(:,:) + diag_sur_me(:,:) + diag_res_pr(:,:) ) * area(:,:) * tms(:,:) ) ! volume fluxes
+      z_bg_grme = glob_sum( - ( wfx_bog(:,:) + wfx_opw(:,:) + wfx_sni(:,:) + wfx_dyn(:,:) + &
+                          &     wfx_bom(:,:) + wfx_sum(:,:) + wfx_res(:,:) + wfx_snw(:,:) + wfx_sub(:,:) ) * area(:,:) * tms(:,:) ) ! volume fluxes
       !
       frc_vol  = frc_vol  + z_frc_vol  * rdt_ice
@@ -134,22 +164,46 @@
       CALL iom_put( 'ibgsaltco' , zbg_sal * rhoic * r1_rau0 * 1.e-9        )   ! ice salt content (psu*km3 equivalent liquid)        
 
-      CALL iom_put( 'ibgemp'    , zbg_emp                                  )   ! volume flux emp (m/day liquid)
-      CALL iom_put( 'ibgempbog' , zbg_emp_bog                              )   ! volume flux bottom growth     -(m/day equivalent liquid)
-      CALL iom_put( 'ibgemplag' , zbg_emp_lag                              )   ! volume flux open water growth -
-      CALL iom_put( 'ibgempsig' , zbg_emp_sig                              )   ! volume flux snow ice growth   -
-      CALL iom_put( 'ibgempdyg' , zbg_emp_dyg                              )   ! volume flux dynamic growth    -
-      CALL iom_put( 'ibgempbom' , zbg_emp_bom                              )   ! volume flux bottom melt       -
-      CALL iom_put( 'ibgempsum' , zbg_emp_sum                              )   ! volume flux surface melt      -
-      CALL iom_put( 'ibgempres' , zbg_emp_res                              )   ! volume flux resultant         -
+      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( 'ibgsfxthd' , zbg_sfx_thd                              )   ! salt flux thermo  -    
-      CALL iom_put( 'ibgsfxmec' , zbg_sfx_mec                              )   ! salt flux dynamic -    
+      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( '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)   
-      CALL iom_put( 'ibggrme'   , bg_grme * rhoic * r1_rau0 * 1.e-9        )   ! vol growth + melt (km3 equivalent liquid)         
+      CALL iom_put( 'ibgvolgrm' , bg_grme * r1_rau0 * 1.e-9                )   ! vol growth + melt (km3 equivalent liquid)         
+
       !
       IF( lrst_ice )   CALL lim_diahsb_rst( numit, 'WRITE' )
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limdyn.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limdyn.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limdyn.F90	(revision 4921)
@@ -30,4 +30,5 @@
    USE lib_fortran      ! glob_sum
    USE timing          ! Timing
+   USE limcons        ! conservation tests
 
    IMPLICIT NONE
@@ -66,6 +67,6 @@
       REAL(wp), POINTER, DIMENSION(:)   ::   zmsk           ! i-averaged of tmask
       REAL(wp), POINTER, DIMENSION(:,:) ::   zu_io, zv_io   ! ice-ocean velocity
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-      REAL(wp) :: zchk_vmin, zchk_amin, zchk_amax ! Check errors (C Rousset)
+      !
+      REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
      !!---------------------------------------------------------------------
 
@@ -75,21 +76,13 @@
       CALL wrk_alloc( jpj, zind, zmsk )
 
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) )
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
       IF( kt == nit000 )   CALL lim_dyn_init   ! Initialization (first time-step only)
 
       IF( ln_limdyn ) THEN
          !
-         old_u_ice(:,:) = u_ice(:,:) * tmu(:,:)
-         old_v_ice(:,:) = v_ice(:,:) * tmv(:,:)
+         ! 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(:,:) * tmu(:,:)
+         v_ice_b(:,:) = v_ice(:,:) * tmv(:,:)
 
          ! Rheology (ice dynamics)
@@ -171,4 +164,7 @@
             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
@@ -224,28 +220,4 @@
       ENDIF
       !
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_fs  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
-
-         zchk_vmin = glob_min(v_i)
-         zchk_amax = glob_max(SUM(a_i,dim=3))
-         zchk_amin = glob_min(a_i)
-
-         IF(lwp) THEN
-            IF ( ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limdyn) = ',(zchk_v_i * rday)
-            IF ( ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limdyn) = ',(zchk_smv * rday)
-            IF ( zchk_vmin <  0.            ) WRITE(numout,*) 'violation v_i<0  [mm]         (limdyn) = ',(zchk_vmin * 1.e-3)
-            !IF ( zchk_amax >  amax+1.e-10   ) WRITE(numout,*) 'violation a_i>amax            (limdyn) = ',zchk_amax
-            IF ( zchk_amin <  0.            ) WRITE(numout,*) 'violation a_i<0               (limdyn) = ',zchk_amin
-         ENDIF
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
       CALL wrk_dealloc( jpi, jpj, zu_io, zv_io )
       CALL wrk_dealloc( jpj, zind, zmsk )
@@ -269,8 +241,7 @@
       !!-------------------------------------------------------------------
       INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicedyn/ epsd, alpha,     &
-         &                dm, nbiter, nbitdr, om, resl, cw, angvg, pstar,   &
-         &                c_rhg, etamn, creepl, ecc, ahi0, &
-         &                nevp, telast, alphaevp, hminrhg
+      NAMELIST/namicedyn/ epsd, om, cw, angvg, pstar,   &
+         &                c_rhg, creepl, ecc, ahi0,     &
+         &                nevp, relast, alphaevp, hminrhg
       !!-------------------------------------------------------------------
 
@@ -289,20 +260,14 @@
          WRITE(numout,*) '~~~~~~~~~~~~'
          WRITE(numout,*) '   tolerance parameter                              epsd   = ', epsd
-         WRITE(numout,*) '   coefficient for semi-implicit coriolis           alpha  = ', alpha
-         WRITE(numout,*) '   diffusion constant for dynamics                  dm     = ', dm
-         WRITE(numout,*) '   number of sub-time steps for relaxation          nbiter = ', nbiter
-         WRITE(numout,*) '   maximum number of iterations for relaxation      nbitdr = ', nbitdr
          WRITE(numout,*) '   relaxation constant                              om     = ', om
-         WRITE(numout,*) '   maximum value for the residual of relaxation     resl   = ', resl
          WRITE(numout,*) '   drag coefficient for oceanic stress              cw     = ', cw
          WRITE(numout,*) '   turning angle for oceanic stress                 angvg  = ', angvg
          WRITE(numout,*) '   first bulk-rheology parameter                    pstar  = ', pstar
          WRITE(numout,*) '   second bulk-rhelogy parameter                    c_rhg  = ', c_rhg
-         WRITE(numout,*) '   minimun value for viscosity                      etamn  = ', etamn
          WRITE(numout,*) '   creep limit                                      creepl = ', creepl
          WRITE(numout,*) '   eccentricity of the elliptical yield curve       ecc    = ', ecc
          WRITE(numout,*) '   horizontal diffusivity coeff. for sea-ice        ahi0   = ', ahi0
          WRITE(numout,*) '   number of iterations for subcycling              nevp   = ', nevp
-         WRITE(numout,*) '   timescale for elastic waves                      telast = ', telast
+         WRITE(numout,*) '   ratio of elastic timescale over ice time step    relast = ', relast
          WRITE(numout,*) '   coefficient for the solution of int. stresses  alphaevp = ', alphaevp
          WRITE(numout,*) '   min ice thickness for rheology calculations     hminrhg = ', hminrhg
@@ -322,4 +287,7 @@
       pstarh = pstar * 0.5_wp
 
+      ! elastic damping
+      telast = relast * rdt_ice
+
       !  Diffusion coefficients.
       ahiu(:,:) = ahi0 * umask(:,:,1)
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 4921)
@@ -26,8 +26,8 @@
    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)  
    USE wrk_nemo         ! work arrays
+   USE cpl_oasis3, ONLY : lk_cpl
 
    IMPLICIT NONE
@@ -38,14 +38,17 @@
    !! * Module variables
    !                          !!** init namelist (namiceini) **
-   REAL(wp) ::   ttest   ! threshold water temperature for initial sea ice
-   REAL(wp) ::   hninn   ! initial snow thickness in the north
-   REAL(wp) ::   hnins   ! initial snow thickness in the south
-   REAL(wp) ::   hginn   ! initial ice thickness in the north
-   REAL(wp) ::   hgins   ! initial ice thickness in the south
-   REAL(wp) ::   aginn   ! initial leads area in the north
-   REAL(wp) ::   agins   ! initial leads area in the south
-   REAL(wp) ::   sinn    ! initial salinity 
-   REAL(wp) ::   sins  
-
+   REAL(wp) ::   thres_sst   ! threshold water temperature for initial sea ice
+   REAL(wp) ::   hts_ini_n   ! initial snow thickness in the north
+   REAL(wp) ::   hts_ini_s   ! initial snow thickness in the south
+   REAL(wp) ::   hti_ini_n   ! initial ice thickness in the north
+   REAL(wp) ::   hti_ini_s   ! initial ice thickness in the south
+   REAL(wp) ::   ati_ini_n   ! initial leads area in the north
+   REAL(wp) ::   ati_ini_s   ! initial leads area in the south
+   REAL(wp) ::   smi_ini_n   ! initial salinity 
+   REAL(wp) ::   smi_ini_s   ! initial salinity
+   REAL(wp) ::   tmi_ini_n   ! initial temperature
+   REAL(wp) ::   tmi_ini_s   ! initial temperature
+
+   LOGICAL  ::  ln_limini    ! initialization or not
    !!----------------------------------------------------------------------
    !!   LIM 3.0,  UCL-LOCEAN-IPSL (2008)
@@ -90,16 +93,17 @@
       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), POINTER, DIMENSION(:)     :: zhm_i_ini, zat_i_ini, zvt_i_ini, zhm_s_ini, zsm_i_ini
-      REAL(wp), POINTER, DIMENSION(:,:)   :: zht_i_ini, za_i_ini, zv_i_ini
-      REAL(wp), POINTER, DIMENSION(:,:)   :: zidto    ! ice indicator
+      REAL(wp), POINTER, DIMENSION(:)     :: zht_i_ini, zat_i_ini, zvt_i_ini, zht_s_ini, zsm_i_ini, ztm_i_ini
+      REAL(wp), POINTER, DIMENSION(:,:)   :: zh_i_ini, za_i_ini, zv_i_ini
+      REAL(wp), POINTER, DIMENSION(:,:)   :: zswitch    ! ice indicator
       INTEGER,  POINTER, DIMENSION(:,:)   :: zhemis   ! hemispheric index
       !--------------------------------------------------------------------
 
-      CALL wrk_alloc( jpi, jpj, zidto )
+      CALL wrk_alloc( jpi, jpj, zswitch )
       CALL wrk_alloc( jpi, jpj, zhemis )
-      CALL wrk_alloc( jpl,   2, zht_i_ini,  za_i_ini,  zv_i_ini )
-      CALL wrk_alloc(   2,      zhm_i_ini, zat_i_ini, zvt_i_ini, zhm_s_ini, zsm_i_ini )
-
-      epsi20   = 1.0e-20
+      CALL wrk_alloc( jpl,   2, zh_i_ini,  za_i_ini,  zv_i_ini )
+      CALL wrk_alloc(   2,      zht_i_ini, zat_i_ini, zvt_i_ini, zht_s_ini, zsm_i_ini, ztm_i_ini )
+
+      epsi20   = 1.e-20_wp
+
       IF(lwp) WRITE(numout,*)
       IF(lwp) WRITE(numout,*) 'lim_istate : Ice initialization '
@@ -112,24 +116,32 @@
       CALL lim_istate_init     !  reading the initials parameters of the ice
 
-!!gm  in lim2  the initialisation if only done if required in the namelist :
-!!gm      IF( .NOT. ln_limini ) THEN
-!!gm  this should be added in lim3 namelist...
+# if defined key_coupled
+      albege(:,:)   = 0.8 * tms(:,:)
+# endif
+
+      ! surface temperature
+      DO jl = 1, jpl ! loop over categories
+         t_su  (:,:,jl) = rtt * tms(:,:)
+         tn_ice(:,:,jl) = rtt * tms(:,:)
+      END DO
+      ! Basal temperature is set to the freezing point of seawater in Kelvin
+      t_bo(:,:) = ( tfreez( tsn(:,:,1,jp_sal) ) + rt0 ) * tms(:,:) 
+
+      IF( ln_limini ) THEN
 
       !--------------------------------------------------------------------
       ! 2) Basal temperature, ice mask and hemispheric index
       !--------------------------------------------------------------------
-
-      ! Basal temperature is set to the freezing point of seawater in Celsius
-      t_bo(:,:) = tfreez( tsn(:,:,1,jp_sal) ) * tmask(:,:,1)       ! freezing/melting point of sea water [Celcius]
-
-      DO jj = 1, jpj                                       ! ice if sst <= t-freez + ttest
+      ! ice if sst <= t-freez + thres_sst
+      DO jj = 1, jpj                                       
          DO ji = 1, jpi
-            IF( tsn(ji,jj,1,jp_tem)  - t_bo(ji,jj) >= ttest ) THEN   ;   zidto(ji,jj) = 0._wp      ! no ice
-            ELSE                                                     ;   zidto(ji,jj) = 1._wp      !    ice
+            IF( ( tsn(ji,jj,1,jp_tem)  - ( t_bo(ji,jj) - rt0 ) ) * tms(ji,jj) >= thres_sst ) THEN 
+               zswitch(ji,jj) = 0._wp * tms(ji,jj)    ! no ice
+            ELSE                                                                                   
+               zswitch(ji,jj) = 1._wp * tms(ji,jj)    !    ice
             ENDIF
          END DO
       END DO
 
-      t_bo(:,:) = t_bo(:,:) + rt0                          ! conversion to Kelvin
 
       ! Hemispheric index
@@ -153,11 +165,12 @@
       ! 3.1) Hemisphere-dependent arrays
       !-----------------------------
-      ! assign initial thickness, concentration, snow depth and salinity to
-      ! an hemisphere-dependent array
-      zhm_i_ini(1) = hginn ; zhm_i_ini(2) = hgins  ! ice thickness
-      zat_i_ini(1) = aginn ; zat_i_ini(2) = agins  ! ice concentration
-      zvt_i_ini(:) = zhm_i_ini(:) * zat_i_ini(:)   ! ice volume
-      zhm_s_ini(1) = hninn ; zhm_s_ini(2) = hnins  ! snow depth
-      zsm_i_ini(1) = sinn  ; zsm_i_ini(2) = sins   ! bulk ice salinity
+      ! assign initial thickness, concentration, snow depth and salinity to an hemisphere-dependent array
+      zht_i_ini(1) = hti_ini_n ; zht_i_ini(2) = hti_ini_s  ! ice thickness
+      zht_s_ini(1) = hts_ini_n ; zht_s_ini(2) = hts_ini_s  ! snow depth
+      zat_i_ini(1) = ati_ini_n ; zat_i_ini(2) = ati_ini_s  ! ice concentration
+      zsm_i_ini(1) = smi_ini_n ; zsm_i_ini(2) = smi_ini_s  ! bulk ice salinity
+      ztm_i_ini(1) = tmi_ini_n ; ztm_i_ini(2) = tmi_ini_s  ! temperature (ice and snow)
+
+      zvt_i_ini(:) = zht_i_ini(:) * zat_i_ini(:)   ! ice volume
 
       !---------------------------------------------------------------------
@@ -183,35 +196,35 @@
             ! *** 1 category to fill
             IF ( i_fill .EQ. 1 ) THEN
-               zht_i_ini(1,i_hemis)       = zhm_i_ini(i_hemis)
-               za_i_ini(1,i_hemis)        = zat_i_ini(i_hemis)
-               zht_i_ini(2:jpl,i_hemis)   = 0._wp
-               za_i_ini(2:jpl,i_hemis)    = 0._wp
+               zh_i_ini(1,i_hemis)       = zht_i_ini(i_hemis)
+               za_i_ini(1,i_hemis)       = zat_i_ini(i_hemis)
+               zh_i_ini(2:jpl,i_hemis)   = 0._wp
+               za_i_ini(2:jpl,i_hemis)   = 0._wp
             ELSE
 
-            ! *** >1 categores to fill
-            !--- Ice thicknesses in the i_fill - 1 first categories
+               ! *** >1 categores to fill
+               !--- Ice thicknesses in the i_fill - 1 first categories
                DO jl = 1, i_fill - 1
-                  zht_i_ini(jl,i_hemis)    = 0.5 * ( hi_max(jl) + hi_max(jl-1) )
+                  zh_i_ini(jl,i_hemis)    = 0.5 * ( hi_max(jl) + hi_max(jl-1) )
                END DO
-
-            !--- jl0: most likely index where cc will be maximum
+               
+               !--- jl0: most likely index where cc will be maximum
                DO jl = 1, jpl
-                  IF ( ( zhm_i_ini(i_hemis) .GT. hi_max(jl-1) ) .AND. &
-                       ( zhm_i_ini(i_hemis) .LE. hi_max(jl)   ) ) THEN
+                  IF ( ( zht_i_ini(i_hemis) .GT. hi_max(jl-1) ) .AND. &
+                     ( zht_i_ini(i_hemis) .LE. hi_max(jl)   ) ) THEN
                      jl0 = jl
                   ENDIF
                END DO
                jl0 = MIN(jl0, i_fill)
-
-            !--- Concentrations
+               
+               !--- Concentrations
                za_i_ini(jl0,i_hemis)      = zat_i_ini(i_hemis) / SQRT(REAL(jpl))
                DO jl = 1, i_fill - 1
                   IF ( jl .NE. jl0 ) THEN
-                     zsigma               = 0.5 * zhm_i_ini(i_hemis)
-                     zarg                 = ( zht_i_ini(jl,i_hemis) - zhm_i_ini(i_hemis) ) / zsigma
+                     zsigma               = 0.5 * zht_i_ini(i_hemis)
+                     zarg                 = ( zh_i_ini(jl,i_hemis) - zht_i_ini(i_hemis) ) / zsigma
                      za_i_ini(jl,i_hemis) = za_i_ini(jl0,i_hemis) * EXP(-zarg**2)
                   ENDIF
-               END DO 
-
+               END DO
+               
                zA = 0. ! sum of the areas in the jpl categories 
                DO jl = 1, i_fill - 1
@@ -221,14 +234,14 @@
                IF ( i_fill .LT. jpl ) za_i_ini(i_fill+1:jpl, i_hemis) = 0._wp
          
-            !--- Ice thickness in the last category
+               !--- 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(jl,i_hemis)*zht_i_ini(jl,i_hemis)
+                  zV = zV + za_i_ini(jl,i_hemis)*zh_i_ini(jl,i_hemis)
                END DO
-               zht_i_ini(i_fill,i_hemis) = ( zvt_i_ini(i_hemis) - zV ) / za_i_ini(i_fill,i_hemis) 
-               IF ( i_fill .LT. jpl ) zht_i_ini(i_fill+1:jpl, i_hemis) = 0._wp
-
-            !--- volumes
-               zv_i_ini(:,i_hemis) = za_i_ini(:,i_hemis) * zht_i_ini(:,i_hemis)
+               zh_i_ini(i_fill,i_hemis) = ( zvt_i_ini(i_hemis) - zV ) / za_i_ini(i_fill,i_hemis) 
+               IF ( i_fill .LT. jpl ) zh_i_ini(i_fill+1:jpl, i_hemis) = 0._wp
+
+               !--- volumes
+               zv_i_ini(:,i_hemis) = za_i_ini(:,i_hemis) * zh_i_ini(:,i_hemis)
                IF ( i_fill .LT. jpl ) zv_i_ini(i_fill+1:jpl, i_hemis) = 0._wp
 
@@ -262,10 +275,10 @@
 
             ! Test 3: thickness of the last category is in-bounds ?
-            IF ( zht_i_ini(i_fill, i_hemis) .GT. hi_max(i_fill-1) ) THEN
+            IF ( zh_i_ini(i_fill, i_hemis) .GT. hi_max(i_fill-1) ) THEN
                ztest_3 = 1
             ELSE
                ! this write is useful
-               IF(lwp) WRITE(numout,*) ' * TEST 3 THICKNESS OF THE LAST CATEGORY OUT OF BOUNDS *** zht_i_ini(i_fill,i_hemis) = ', &
-               zht_i_ini(i_fill,i_hemis), ' hi_max(jpl-1) = ', hi_max(i_fill-1)
+               IF(lwp) WRITE(numout,*) ' * TEST 3 THICKNESS OF THE LAST CATEGORY OUT OF BOUNDS *** zh_i_ini(i_fill,i_hemis) = ', &
+               zh_i_ini(i_fill,i_hemis), ' hi_max(jpl-1) = ', hi_max(i_fill-1)
                ztest_3 = 0
             ENDIF
@@ -291,14 +304,11 @@
          IF ( ztests .NE. 4 ) THEN
             WRITE(numout,*)
-            WRITE(numout,*) ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '
-            WRITE(numout,*) ' !!!! RED ALERT                  !!! '
-            WRITE(numout,*) ' !!!! BIIIIP BIIIP BIIIIP BIIIIP !!!'
+            WRITE(numout,*) ' !!!! ALERT                  !!! '
             WRITE(numout,*) ' !!!! Something is wrong in the LIM3 initialization procedure '
-            WRITE(numout,*) ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '
             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(i_hemis)
-            WRITE(numout,*) ' zhm_i_ini : ', zhm_i_ini(i_hemis)
+            WRITE(numout,*) ' zht_i_ini : ', zht_i_ini(i_hemis)
          ENDIF ! ztests .NE. 4
       ENDIF
@@ -314,10 +324,10 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               a_i(ji,jj,jl)   = zidto(ji,jj) * za_i_ini (jl,zhemis(ji,jj))  ! concentration
-               ht_i(ji,jj,jl)  = zidto(ji,jj) * zht_i_ini(jl,zhemis(ji,jj))  ! ice thickness
-               ht_s(ji,jj,jl)  = ht_i(ji,jj,jl) * ( zhm_s_ini( zhemis(ji,jj) ) / zhm_i_ini( zhemis(ji,jj) ) )  ! snow depth
-               sm_i(ji,jj,jl)  = zidto(ji,jj) * zsm_i_ini(zhemis(ji,jj)) + ( 1._wp - zidto(ji,jj) ) * s_i_min ! salinity
-               o_i(ji,jj,jl)   = zidto(ji,jj) * 1._wp + ( 1._wp - zidto(ji,jj) ) ! age
-               t_su(ji,jj,jl)  = zidto(ji,jj) * 270.0 + ( 1._wp - zidto(ji,jj) ) * 270.0 ! surf temp
+               a_i(ji,jj,jl)   = zswitch(ji,jj) * za_i_ini (jl,zhemis(ji,jj))  ! concentration
+               ht_i(ji,jj,jl)  = zswitch(ji,jj) * zh_i_ini(jl,zhemis(ji,jj))  ! ice thickness
+               ht_s(ji,jj,jl)  = ht_i(ji,jj,jl) * ( zht_s_ini( zhemis(ji,jj) ) / zht_i_ini( zhemis(ji,jj) ) )  ! snow depth
+               sm_i(ji,jj,jl)  = zswitch(ji,jj) * zsm_i_ini(zhemis(ji,jj)) !+ ( 1._wp - zswitch(ji,jj) ) * s_i_min ! salinity
+               o_i(ji,jj,jl)   = zswitch(ji,jj) * 1._wp + ( 1._wp - zswitch(ji,jj) ) ! age
+               t_su(ji,jj,jl)  = zswitch(ji,jj) * ztm_i_ini(zhemis(ji,jj)) + ( 1._wp - zswitch(ji,jj) ) * rtt ! surf temp
 
                ! This case below should not be used if (ht_s/ht_i) is ok in namelist
@@ -343,10 +353,10 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                   t_s(ji,jj,jk,jl) = zidto(ji,jj) * 270.0 + ( 1._wp - zidto(ji,jj) ) * rtt
+                   t_s(ji,jj,jk,jl) = zswitch(ji,jj) * ztm_i_ini(zhemis(ji,jj)) + ( 1._wp - zswitch(ji,jj) ) * rtt
                    ! Snow energy of melting
-                   e_s(ji,jj,jk,jl) = zidto(ji,jj) * rhosn * ( cpic * ( rtt - t_s(ji,jj,jk,jl) ) + lfus )
+                   e_s(ji,jj,jk,jl) = zswitch(ji,jj) * rhosn * ( cpic * ( rtt - t_s(ji,jj,jk,jl) ) + lfus )
                    ! Change dimensions
                    e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) / unit_fac
-                   ! Multiply by volume, so that heat content in 10^9 Joules
+                   ! Multiply by volume, so that heat content in Joules
                    e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * area(ji,jj) * v_s(ji,jj,jl) / nlay_s
                END DO ! ji
@@ -360,10 +370,10 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                   t_i(ji,jj,jk,jl) = zidto(ji,jj) * 270.00 + ( 1._wp - zidto(ji,jj) ) * rtt 
-                   s_i(ji,jj,jk,jl) = zidto(ji,jj) * zsm_i_ini(zhemis(ji,jj)) + ( 1._wp - zidto(ji,jj) ) * s_i_min
+                   t_i(ji,jj,jk,jl) = zswitch(ji,jj) * ztm_i_ini(zhemis(ji,jj)) + ( 1._wp - zswitch(ji,jj) ) * rtt 
+                   s_i(ji,jj,jk,jl) = zswitch(ji,jj) * zsm_i_ini(zhemis(ji,jj)) !+ ( 1._wp - zswitch(ji,jj) ) * s_i_min
                    ztmelts          = - tmut * s_i(ji,jj,jk,jl) + rtt !Melting temperature in K
 
                    ! heat content per unit volume
-                   e_i(ji,jj,jk,jl) = zidto(ji,jj) * rhoic * (   cpic    * ( ztmelts - t_i(ji,jj,jk,jl) ) &
+                   e_i(ji,jj,jk,jl) = zswitch(ji,jj) * rhoic * (   cpic    * ( ztmelts - t_i(ji,jj,jk,jl) ) &
                       +   lfus    * ( 1._wp - (ztmelts-rtt) / MIN((t_i(ji,jj,jk,jl)-rtt),-epsi20) ) &
                       -   rcp     * ( ztmelts - rtt ) )
@@ -372,6 +382,5 @@
                    e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) / unit_fac 
 
-                   ! Mutliply by ice volume, and divide by number of layers 
-                   ! to get heat content in 10^9 J
+                   ! Mutliply by ice volume, and divide by number of layers to get heat content in J
                    e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * area(ji,jj) * v_i(ji,jj,jl) / nlay_i
                END DO ! ji
@@ -380,8 +389,40 @@
       END DO ! jk
 
+      tn_ice (:,:,:) = t_su (:,:,:)
+
+      ELSE 
+         ! if ln_limini=false
+         a_i  (:,:,:) = 0._wp
+         v_i  (:,:,:) = 0._wp
+         v_s  (:,:,:) = 0._wp
+         smv_i(:,:,:) = 0._wp
+         oa_i (:,:,:) = 0._wp
+         ht_i (:,:,:) = 0._wp
+         ht_s (:,:,:) = 0._wp
+         sm_i (:,:,:) = 0._wp
+         o_i  (:,:,:) = 0._wp
+
+         e_i(:,:,:,:) = 0._wp
+         e_s(:,:,:,:) = 0._wp
+
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               t_i(:,:,jk,jl) = rtt * tms(:,:)
+            END DO
+            DO jk = 1, nlay_s
+               t_s(:,:,jk,jl) = rtt * tms(:,:)
+            END DO
+         END DO
+      
+      ENDIF ! ln_limini
+      
+      at_i (:,:) = 0.0_wp
+      DO jl = 1, jpl
+         at_i (:,:) = at_i (:,:) + a_i (:,:,jl)
+      END DO
+      !
       !--------------------------------------------------------------------
       ! 4) Global ice variables for output diagnostics                    | 
       !--------------------------------------------------------------------
-      fsbbq (:,:)     = 0._wp
       u_ice (:,:)     = 0._wp
       v_ice (:,:)     = 0._wp
@@ -390,8 +431,4 @@
       stress12_i(:,:) = 0._wp
 
-# if defined key_coupled
-      albege(:,:)   = 0.8 * tms(:,:)
-# endif
-
       !--------------------------------------------------------------------
       ! 5) Moments for advection
@@ -428,52 +465,9 @@
       sxyage (:,:,:)  = 0._wp
 
-      !--------------------------------------------------------------------
-      ! 6) Lateral boundary conditions                                    | 
-      !--------------------------------------------------------------------
-
-      DO jl = 1, jpl
-
-         CALL lbc_lnk( a_i(:,:,jl)  , 'T', 1. )
-         CALL lbc_lnk( v_i(:,:,jl)  , 'T', 1. )
-         CALL lbc_lnk( v_s(:,:,jl)  , 'T', 1. )
-         CALL lbc_lnk( smv_i(:,:,jl), 'T', 1. )
-         CALL lbc_lnk( oa_i(:,:,jl) , 'T', 1. )
-
-         CALL lbc_lnk( ht_i(:,:,jl) , 'T', 1. )
-         CALL lbc_lnk( ht_s(:,:,jl) , 'T', 1. )
-         CALL lbc_lnk( sm_i(:,:,jl) , 'T', 1. )
-         CALL lbc_lnk( o_i(:,:,jl)  , 'T', 1. )
-         CALL lbc_lnk( t_su(:,:,jl) , 'T', 1. )
-         DO jk = 1, nlay_s
-            CALL lbc_lnk(t_s(:,:,jk,jl), 'T', 1. )
-            CALL lbc_lnk(e_s(:,:,jk,jl), 'T', 1. )
-         END DO
-         DO jk = 1, nlay_i
-            CALL lbc_lnk(t_i(:,:,jk,jl), 'T', 1. )
-            CALL lbc_lnk(e_i(:,:,jk,jl), 'T', 1. )
-         END DO
-         !
-         a_i(:,:,jl) = tms(:,:) * a_i(:,:,jl)
-      END DO
-      
-      at_i (:,:) = 0.0_wp
-      DO jl = 1, jpl
-         at_i (:,:) = at_i (:,:) + a_i (:,:,jl)
-      END DO
-
-      CALL lbc_lnk( at_i , 'T', 1. )
-      at_i(:,:) = tms(:,:) * at_i(:,:)                       ! put 0 over land
-      !
-      CALL lbc_lnk( fsbbq  , 'T', 1. )
-      !
-      !--------------------------------------------------------------------
-      ! 6) ????                                                           | 
-      !--------------------------------------------------------------------
-      tn_ice (:,:,:) = t_su (:,:,:)
-
-      CALL wrk_dealloc( jpi, jpj, zidto )
+
+      CALL wrk_dealloc( jpi, jpj, zswitch )
       CALL wrk_dealloc( jpi, jpj, zhemis )
-      CALL wrk_dealloc( jpl,   2, zht_i_ini,  za_i_ini,  zv_i_ini )
-      CALL wrk_dealloc(   2,      zhm_i_ini, zat_i_ini, zvt_i_ini, zhm_s_ini, zsm_i_ini )
+      CALL wrk_dealloc( jpl,   2, zh_i_ini,  za_i_ini,  zv_i_ini )
+      CALL wrk_dealloc(   2,      zht_i_ini, zat_i_ini, zvt_i_ini, zht_s_ini, zsm_i_ini, ztm_i_ini )
 
    END SUBROUTINE lim_istate
@@ -495,6 +489,6 @@
       !!  8.5  ! 07-11 (M. Vancoppenolle) rewritten initialization
       !!-----------------------------------------------------------------------------
-      NAMELIST/namiceini/ ttest, hninn, hnins, hginn, hgins, aginn, agins, sinn, sins
-      !
+      NAMELIST/namiceini/ ln_limini, thres_sst, hts_ini_n, hts_ini_s, hti_ini_n, hti_ini_s,  &
+         &                                      ati_ini_n, ati_ini_s, smi_ini_n, smi_ini_s, tmi_ini_n, tmi_ini_s
       INTEGER :: ios                 ! Local integer output status for namelist read
       !!-----------------------------------------------------------------------------
@@ -516,13 +510,16 @@
          WRITE(numout,*) 'lim_istate_init : ice parameters inititialisation '
          WRITE(numout,*) '~~~~~~~~~~~~~~~'
-         WRITE(numout,*) '   threshold water temp. for initial sea-ice    ttest      = ', ttest
-         WRITE(numout,*) '   initial snow thickness in the north          hninn      = ', hninn
-         WRITE(numout,*) '   initial snow thickness in the south          hnins      = ', hnins 
-         WRITE(numout,*) '   initial ice thickness  in the north          hginn      = ', hginn
-         WRITE(numout,*) '   initial ice thickness  in the south          hgins      = ', hgins
-         WRITE(numout,*) '   initial ice concentr.  in the north          aginn      = ', aginn
-         WRITE(numout,*) '   initial ice concentr.  in the north          agins      = ', agins
-         WRITE(numout,*) '   initial  ice salinity  in the north          sinn       = ', sinn
-         WRITE(numout,*) '   initial  ice salinity  in the south          sins       = ', sins
+         WRITE(numout,*) '   initialization with ice (T) or not (F)       ln_limini   = ', ln_limini
+         WRITE(numout,*) '   threshold water temp. for initial sea-ice    thres_sst  = ', thres_sst
+         WRITE(numout,*) '   initial snow thickness in the north          hts_ini_n  = ', hts_ini_n
+         WRITE(numout,*) '   initial snow thickness in the south          hts_ini_s  = ', hts_ini_s 
+         WRITE(numout,*) '   initial ice thickness  in the north          hti_ini_n  = ', hti_ini_n
+         WRITE(numout,*) '   initial ice thickness  in the south          hti_ini_s  = ', hti_ini_s
+         WRITE(numout,*) '   initial ice concentr.  in the north          ati_ini_n  = ', ati_ini_n
+         WRITE(numout,*) '   initial ice concentr.  in the north          ati_ini_s  = ', ati_ini_s
+         WRITE(numout,*) '   initial  ice salinity  in the north          smi_ini_n  = ', smi_ini_n
+         WRITE(numout,*) '   initial  ice salinity  in the south          smi_ini_s  = ', smi_ini_s
+         WRITE(numout,*) '   initial  ice/snw temp  in the north          tmi_ini_n  = ', tmi_ini_n
+         WRITE(numout,*) '   initial  ice/snw temp  in the south          tmi_ini_s  = ', tmi_ini_s
       ENDIF
 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90	(revision 4921)
@@ -5,5 +5,5 @@
    !!======================================================================
    !! History :  LIM  ! 2006-02  (M. Vancoppenolle) Original code 
-   !!            3.2  ! 2009-07  (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in smsw & sfx_mec
+   !!            3.2  ! 2009-07  (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in smsw & sfx_dyn
    !!            4.0  ! 2011-02  (G. Madec) dynamical allocation
    !!----------------------------------------------------------------------
@@ -22,5 +22,4 @@
    USE limthd_lac       ! LIM
    USE limvar           ! LIM
-   USE limcons          ! LIM
    USE in_out_manager   ! I/O manager
    USE lbclnk           ! lateral boundary condition - MPP exchanges
@@ -30,7 +29,8 @@
   ! Check budget (Rousset)
    USE iom              ! I/O manager
-   USE lib_fortran     ! glob_sum
+   USE lib_fortran      ! glob_sum
    USE limdiahsb
-   USE timing          ! Timing
+   USE timing           ! Timing
+   USE limcons          ! conservation tests
 
    IMPLICIT NONE
@@ -143,16 +143,10 @@
       REAL(wp), POINTER, DIMENSION(:,:) ::   esnow_mlt       ! energy needed to melt snow in ocean (J m-2)
       REAL(wp), POINTER, DIMENSION(:,:) ::   vt_i_init, vt_i_final  !  ice volume summed over categories
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-      REAL(wp) :: zchk_vmin, zchk_amin, zchk_amax ! Check errors (C Rousset)
-      ! mass and salt flux (clem)
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zviold, zvsold, zsmvold   ! old ice volume...
+      !
+      REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
       !!-----------------------------------------------------------------------------
       IF( nn_timing == 1 )  CALL timing_start('limitd_me')
 
       CALL wrk_alloc( jpi, jpj, closing_net, divu_adv, opning, closing_gross, msnow_mlt, esnow_mlt, vt_i_init, vt_i_final )
-
-      CALL wrk_alloc( jpi, jpj, jpl, zviold, zvsold, zsmvold )   ! clem
-
-      IF( numit == nstart  )   CALL lim_itd_me_init   ! Initialization (first time-step only)
 
       IF(ln_ctl) THEN
@@ -162,19 +156,7 @@
 
       IF( ln_limdyn ) THEN          !   Start ridging and rafting   !
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) )
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
-      ! mass and salt flux init (clem)
-      zviold(:,:,:) = v_i(:,:,:)
-      zvsold(:,:,:) = v_s(:,:,:)
-      zsmvold(:,:,:) = smv_i(:,:,:)
+
+      ! conservation test
+      IF( ln_limdiahsb ) CALL lim_cons_hsm(0, 'limitd_me', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
 
       !-----------------------------------------------------------------------------!
@@ -362,6 +344,6 @@
             ! 5) Heat, salt and freshwater fluxes
             !-----------------------------------------------------------------------------!
-            fmmec(ji,jj) = fmmec(ji,jj) + msnow_mlt(ji,jj) * r1_rdtice     ! fresh water source for ocean
-            fhmec(ji,jj) = fhmec(ji,jj) + esnow_mlt(ji,jj) * r1_rdtice     ! heat sink for ocean
+            wfx_snw(ji,jj) = wfx_snw(ji,jj) + msnow_mlt(ji,jj) * r1_rdtice     ! fresh water source for ocean
+            hfx_dyn(ji,jj) = hfx_dyn(ji,jj) + esnow_mlt(ji,jj) * unit_fac / area(ji,jj) * r1_rdtice  ! heat sink for ocean (<0, W.m-2)
 
          END DO
@@ -399,17 +381,4 @@
       CALL lim_itd_me_zapsmall
 
-      !--------------------------------
-      ! Update mass/salt fluxes (clem)
-      !--------------------------------
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               diag_dyn_gr(ji,jj) = diag_dyn_gr(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) * r1_rdtice
-               rdm_ice(ji,jj) = rdm_ice(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) * rhoic 
-               rdm_snw(ji,jj) = rdm_snw(ji,jj) + ( v_s(ji,jj,jl) - zvsold(ji,jj,jl) ) * rhosn 
-               sfx_mec(ji,jj) = sfx_mec(ji,jj) - ( smv_i(ji,jj,jl) - zsmvold(ji,jj,jl) ) * rhoic * r1_rdtice 
-            END DO
-         END DO
-      END DO
 
       IF(ln_ctl) THEN     ! Control print
@@ -445,33 +414,10 @@
       ENDIF
 
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_fs  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) * r1_rdtice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) * r1_rdtice + ( zchk_fs / rhoic )
-
-         zchk_vmin = glob_min(v_i)
-         zchk_amax = glob_max(SUM(a_i,dim=3))
-         zchk_amin = glob_min(a_i)
-       
-         IF(lwp) THEN
-            IF ( ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limitd_me) = ',(zchk_v_i * rday)
-            IF ( ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limitd_me) = ',(zchk_smv * rday)
-            IF ( zchk_vmin <  0.            ) WRITE(numout,*) 'violation v_i<0  [mm]         (limitd_me) = ',(zchk_vmin * 1.e-3)
-            IF ( zchk_amax >  kamax+epsi10  ) WRITE(numout,*) 'violation a_i>amax            (limitd_me) = ',zchk_amax
-            IF ( zchk_amin <  0.            ) WRITE(numout,*) 'violation a_i<0               (limitd_me) = ',zchk_amin
-         ENDIF
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
+      ! 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.
       !
       CALL wrk_dealloc( jpi, jpj, closing_net, divu_adv, opning, closing_gross, msnow_mlt, esnow_mlt, vt_i_init, vt_i_final )
-      !
-      CALL wrk_dealloc( jpi, jpj, jpl, zviold, zvsold, zsmvold )   ! clem
       !
       IF( nn_timing == 1 )  CALL timing_stop('limitd_me')
@@ -670,5 +616,4 @@
       !!---------------------------------------------------------------------!
       INTEGER ::   ji,jj, jl    ! dummy loop indices
-      INTEGER ::   krdg_index   ! 
       REAL(wp) ::   Gstari, astari, hi, hrmean, zdummy   ! local scalar
       REAL(wp), POINTER, DIMENSION(:,:)   ::   zworka    ! temporary array used here
@@ -746,8 +691,6 @@
       !-----------------------------------------------------------------
 
-      krdg_index = 1
-
-      IF( krdg_index == 0 ) THEN       !--- Linear formulation (Thorndike et al., 1975)
-         DO jl = 0, ice_cat_bounds(1,2)       ! only undeformed ice participates
+      IF( partfun_swi == 0 ) THEN       !--- Linear formulation (Thorndike et al., 1975)
+         DO jl = 0, jpl    
             DO jj = 1, jpj 
                DO ji = 1, jpi
@@ -772,11 +715,11 @@
             Gsum(:,:,jl) = EXP( -Gsum(:,:,jl) * astari ) * zdummy
          END DO !jl
-         DO jl = 0, ice_cat_bounds(1,2)
+         DO jl = 0, jpl
              athorn(:,:,jl) = Gsum(:,:,jl-1) - Gsum(:,:,jl)
          END DO
          !
-      ENDIF ! krdg_index
-
-      IF( raftswi == 1 ) THEN      ! Ridging and rafting ice participation functions
+      ENDIF ! partfun_swi
+
+      IF( raft_swi == 1 ) THEN      ! Ridging and rafting ice participation functions
          !
          DO jl = 1, jpl
@@ -794,5 +737,5 @@
          END DO ! jl
 
-      ELSE  ! raftswi = 0
+      ELSE  ! raft_swi = 0
          !
          DO jl = 1, jpl
@@ -802,5 +745,5 @@
       ENDIF
 
-      IF ( raftswi == 1 ) THEN
+      IF ( raft_swi == 1 ) THEN
 
          IF( MAXVAL(aridge + araft - athorn(:,:,1:jpl)) .GT. epsi10 ) THEN
@@ -908,6 +851,7 @@
       INTEGER ::   ij                ! horizontal index, combines i and j loops
       INTEGER ::   icells            ! number of cells with aicen > puny
-      REAL(wp) ::   zindb, zsrdg2   ! local scalar
+      REAL(wp) ::   zindb    ! local scalar
       REAL(wp) ::   hL, hR, farea, zdummy, zdummy0, ztmelts    ! left and right limits of integration
+      REAL(wp) ::   zsstK            ! SST in Kelvin
 
       INTEGER , POINTER, DIMENSION(:) ::   indxi, indxj   ! compressed indices
@@ -917,5 +861,5 @@
 
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   aicen_init, vicen_init   ! ice  area    & volume before ridging
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   vsnon_init, esnon_init   ! snow volume  & energy before ridging
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   vsnwn_init, esnwn_init   ! snow volume  & energy before ridging
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   smv_i_init, oa_i_init    ! ice salinity & age    before ridging
 
@@ -952,7 +896,7 @@
       CALL wrk_alloc( jpi, jpj,             vrdg1, vrdg2, vsw  , srdg1, srdg2, smsw )
       CALL wrk_alloc( jpi, jpj,             afrft, arft1, arft2, virft, vsrft, esrft, smrft, oirft1, oirft2 )
-      CALL wrk_alloc( jpi, jpj, jpl,        aicen_init, vicen_init, vsnon_init, esnon_init, smv_i_init, oa_i_init )
-      CALL wrk_alloc( jpi, jpj, jkmax,      eirft, erdg1, erdg2, ersw )
-      CALL wrk_alloc( jpi, jpj, jkmax, jpl, eicen_init )
+      CALL wrk_alloc( jpi, jpj, jpl,        aicen_init, vicen_init, vsnwn_init, esnwn_init, smv_i_init, oa_i_init )
+      CALL wrk_alloc( jpi, jpj, nlay_i+1,      eirft, erdg1, erdg2, ersw )
+      CALL wrk_alloc( jpi, jpj, nlay_i+1, jpl, eicen_init )
 
       ! Conservation check
@@ -1008,5 +952,5 @@
          aicen_init(:,:,jl) = a_i(:,:,jl)
          vicen_init(:,:,jl) = v_i(:,:,jl)
-         vsnon_init(:,:,jl) = v_s(:,:,jl)
+         vsnwn_init(:,:,jl) = v_s(:,:,jl)
          !
          smv_i_init(:,:,jl) = smv_i(:,:,jl)
@@ -1014,5 +958,5 @@
       END DO !jl
 
-      esnon_init(:,:,:) = e_s(:,:,1,:)
+      esnwn_init(:,:,:) = e_s(:,:,1,:)
 
       DO jl = 1, jpl  
@@ -1091,17 +1035,17 @@
             !     / rafting category n1.
             !--------------------------------------------------------------------------
-            vrdg1(ji,jj) = vicen_init(ji,jj,jl1) * afrac(ji,jj) / ( 1._wp + ridge_por )
+            vrdg1(ji,jj) = vicen_init(ji,jj,jl1) * afrac(ji,jj)
             vrdg2(ji,jj) = vrdg1(ji,jj) * ( 1. + ridge_por )
             vsw  (ji,jj) = vrdg1(ji,jj) * ridge_por
 
-            vsrdg(ji,jj) = vsnon_init(ji,jj,jl1) * afrac(ji,jj)
-            esrdg(ji,jj) = esnon_init(ji,jj,jl1) * afrac(ji,jj)
-            srdg1(ji,jj) = smv_i_init(ji,jj,jl1) * afrac(ji,jj) / ( 1._wp + ridge_por )
-            srdg2(ji,jj) = smv_i_init(ji,jj,jl1) * afrac(ji,jj)
+            vsrdg(ji,jj) = vsnwn_init(ji,jj,jl1) * afrac(ji,jj)
+            esrdg(ji,jj) = esnwn_init(ji,jj,jl1) * afrac(ji,jj)
+            srdg1(ji,jj) = smv_i_init(ji,jj,jl1) * afrac(ji,jj)
+            srdg2(ji,jj) = smv_i_init(ji,jj,jl1) * afrac(ji,jj) !! MV HC 2014 this line seems useless
 
             ! rafting volumes, heat contents ...
             virft(ji,jj) = vicen_init(ji,jj,jl1) * afrft(ji,jj)
-            vsrft(ji,jj) = vsnon_init(ji,jj,jl1) * afrft(ji,jj)
-            esrft(ji,jj) = esnon_init(ji,jj,jl1) * afrft(ji,jj)
+            vsrft(ji,jj) = vsnwn_init(ji,jj,jl1) * afrft(ji,jj)
+            esrft(ji,jj) = esnwn_init(ji,jj,jl1) * afrft(ji,jj)
             smrft(ji,jj) = smv_i_init(ji,jj,jl1) * afrft(ji,jj) 
 
@@ -1120,14 +1064,11 @@
             ! Salinity
             !-------------
-            smsw(ji,jj)  = sss_m(ji,jj) * vsw(ji,jj) * rhoic / rau0       ! salt content of seawater frozen in voids
-
-            zsrdg2       = srdg1(ji,jj) + smsw(ji,jj)                     ! salt content of new ridge
-
-            srdg2(ji,jj) = MIN( s_i_max * vrdg2(ji,jj) , zsrdg2 )         ! impose a maximum salinity
+            smsw(ji,jj)  = vsw(ji,jj) * sss_m(ji,jj)                      ! salt content of seawater frozen in voids !! MV HC2014
+            srdg2(ji,jj) = srdg1(ji,jj) + smsw(ji,jj)                     ! salt content of new ridge
+
+            !srdg2(ji,jj) = MIN( s_i_max * vrdg2(ji,jj) , zsrdg2 )         ! impose a maximum salinity
             
-            !                                                             ! excess of salt is flushed into the ocean
-            !sfx_mec(ji,jj) = sfx_mec(ji,jj) + ( zsrdg2 - srdg2(ji,jj) ) * rhoic * r1_rdtice
-
-            !rdm_ice(ji,jj) = rdm_ice(ji,jj) + vsw(ji,jj) * rhoic    ! gurvan: increase in ice volume du to seawater frozen in voids             
+            sfx_dyn(ji,jj) = sfx_dyn(ji,jj) - smsw(ji,jj) * rhoic * r1_rdtice
+            wfx_dyn(ji,jj) = wfx_dyn(ji,jj) - vsw (ji,jj) * rhoic * r1_rdtice   ! gurvan: increase in ice volume du to seawater frozen in voids             
 
             !------------------------------------            
@@ -1158,6 +1099,7 @@
                &                                + rhosn*vsrft(ji,jj)*(1.0-fsnowrft)
 
-            esnow_mlt(ji,jj) = esnow_mlt(ji,jj) + esrdg(ji,jj)*(1.0-fsnowrdg)         &   !rafting included
-               &                                + esrft(ji,jj)*(1.0-fsnowrft)          
+            ! in 1e-9 Joules (same as e_s)
+            esnow_mlt(ji,jj) = esnow_mlt(ji,jj) - esrdg(ji,jj)*(1.0-fsnowrdg)         &   !rafting included
+               &                                - esrft(ji,jj)*(1.0-fsnowrft)          
 
             !-----------------------------------------------------------------
@@ -1184,29 +1126,27 @@
                jj = indxj(ij)
                ! heat content of ridged ice
-               erdg1(ji,jj,jk)      = eicen_init(ji,jj,jk,jl1) * afrac(ji,jj) / ( 1._wp + ridge_por ) 
+               erdg1(ji,jj,jk)      = eicen_init(ji,jj,jk,jl1) * afrac(ji,jj) 
                eirft(ji,jj,jk)      = eicen_init(ji,jj,jk,jl1) * afrft(ji,jj)
                e_i  (ji,jj,jk,jl1)  = e_i(ji,jj,jk,jl1) - erdg1(ji,jj,jk) - eirft(ji,jj,jk)
-               ! sea water heat content
-               ztmelts          = - tmut * sss_m(ji,jj) + rtt
-               ! heat content per unit volume
-               zdummy0          = - rcp * ( sst_m(ji,jj) + rt0 - rtt ) * vsw(ji,jj)
-
-               ! corrected sea water salinity
-               zindb  = MAX( 0._wp , SIGN( 1._wp , vsw(ji,jj) - epsi20 ) )
-               zdummy = zindb * ( srdg1(ji,jj) - srdg2(ji,jj) ) / MAX( ridge_por * vsw(ji,jj), epsi20 )
-
-               ztmelts          = - tmut * zdummy + rtt
-               ersw(ji,jj,jk)   = - rcp * ( ztmelts - rtt ) * vsw(ji,jj)
-
-               ! heat flux
-               fheat_mec(ji,jj) = fheat_mec(ji,jj) + ( ersw(ji,jj,jk) - zdummy0 ) * r1_rdtice
+               
+               
+               ! enthalpy of the trapped seawater (J/m2, >0)
+               ! clem: if sst>0, then ersw <0 (is that possible?)
+               zsstK  = sst_m(ji,jj) + rt0
+               ersw(ji,jj,jk)   = - rhoic * vsw(ji,jj) * rcp * ( zsstK - rt0 ) / REAL( nlay_i )
+
+               ! heat flux to the ocean
+               hfx_dyn(ji,jj) = hfx_dyn(ji,jj) + ersw(ji,jj,jk) * r1_rdtice  ! > 0 [W.m-2] ocean->ice flux 
 
                ! Correct dimensions to avoid big values
-               ersw(ji,jj,jk)   = ersw(ji,jj,jk) * 1.e-09
-
-               ! Mutliply by ice volume, and divide by number of layers to get heat content in 10^9 J
-               ersw (ji,jj,jk)  = ersw(ji,jj,jk) * area(ji,jj) * vsw(ji,jj) / REAL( nlay_i )
+               ersw(ji,jj,jk)   = ersw(ji,jj,jk) / unit_fac
+
+               ! Mutliply by ice volume, and divide by number of layers to get heat content in 1.e9 J
+               ! it is added to sea ice because the sign convention is the opposite of the sign convention for the ocean 
+               !! MV HC 2014
+               ersw (ji,jj,jk)  = ersw(ji,jj,jk) * area(ji,jj)
 
                erdg2(ji,jj,jk)  = erdg1(ji,jj,jk) + ersw(ji,jj,jk)
+
             END DO ! ij
          END DO !jk
@@ -1253,5 +1193,5 @@
          !-------------------------------------------------------------------------------
          !        jl1 looping 1-jpl
-         DO jl2  = ice_cat_bounds(1,1), ice_cat_bounds(1,2) 
+         DO jl2  = 1, jpl 
             ! over categories to which ridged ice is transferred
 !CDIR NODEP
@@ -1298,5 +1238,5 @@
          END DO                 ! jl2 (new ridges)            
 
-         DO jl2 = ice_cat_bounds(1,1), ice_cat_bounds(1,2) 
+         DO jl2 = 1, jpl 
 
 !CDIR NODEP
@@ -1361,7 +1301,7 @@
       CALL wrk_dealloc( jpi, jpj,             vrdg1, vrdg2, vsw  , srdg1, srdg2, smsw )
       CALL wrk_dealloc( jpi, jpj,             afrft, arft1, arft2, virft, vsrft, esrft, smrft, oirft1, oirft2 )
-      CALL wrk_dealloc( jpi, jpj, jpl,        aicen_init, vicen_init, vsnon_init, esnon_init, smv_i_init, oa_i_init )
-      CALL wrk_dealloc( jpi, jpj, jkmax,      eirft, erdg1, erdg2, ersw )
-      CALL wrk_dealloc( jpi, jpj, jkmax, jpl, eicen_init )
+      CALL wrk_dealloc( jpi, jpj, jpl,        aicen_init, vicen_init, vsnwn_init, esnwn_init, smv_i_init, oa_i_init )
+      CALL wrk_dealloc( jpi, jpj, nlay_i+1,      eirft, erdg1, erdg2, ersw )
+      CALL wrk_dealloc( jpi, jpj, nlay_i+1, jpl, eicen_init )
       !
    END SUBROUTINE lim_itd_me_ridgeshift
@@ -1404,9 +1344,7 @@
       !!-------------------------------------------------------------------
       INTEGER :: ios                 ! Local integer output status for namelist read
-      NAMELIST/namiceitdme/ ridge_scheme_swi, Cs, Cf, fsnowrdg, fsnowrft,& 
-         Gstar, astar,                                &
-         Hstar, raftswi, hparmeter, Craft, ridge_por, &
-         sal_max_ridge,  partfun_swi, transfun_swi,   &
-         brinstren_swi
+      NAMELIST/namiceitdme/ ridge_scheme_swi, Cs, Cf, fsnowrdg, fsnowrft,              & 
+        &                   Gstar, astar, Hstar, raft_swi, hparmeter, Craft, ridge_por, &
+        &                   partfun_swi, brinstren_swi
       !!-------------------------------------------------------------------
       !
@@ -1432,11 +1370,9 @@
          WRITE(numout,*)'   Equivalent to G* for an exponential part function       astar           ', astar
          WRITE(numout,*)'   Quantity playing a role in max ridged ice thickness     Hstar           ', Hstar
-         WRITE(numout,*)'   Rafting of ice sheets or not                            raftswi         ', raftswi
+         WRITE(numout,*)'   Rafting of ice sheets or not                            raft_swi        ', raft_swi
          WRITE(numout,*)'   Parmeter thickness (threshold between ridge-raft)       hparmeter       ', hparmeter
          WRITE(numout,*)'   Rafting hyperbolic tangent coefficient                  Craft           ', Craft  
          WRITE(numout,*)'   Initial porosity of ridges                              ridge_por       ', ridge_por
-         WRITE(numout,*)'   Maximum salinity of ridging ice                         sal_max_ridge   ', sal_max_ridge
          WRITE(numout,*)'   Switch for part. function (0) linear (1) exponential    partfun_swi     ', partfun_swi
-         WRITE(numout,*)'   Switch for tran. function (0) linear (1) exponential    transfun_swi    ', transfun_swi
          WRITE(numout,*)'   Switch for including brine volume in ice strength comp. brinstren_swi   ', brinstren_swi
       ENDIF
@@ -1462,5 +1398,5 @@
 
       REAL(wp), POINTER, DIMENSION(:,:) ::   zmask   ! 2D workspace
-      REAL(wp)                          ::   zmask_glo
+      REAL(wp)                          ::   zmask_glo, zsal, zvi, zvs, zei, zes
 !!gm      REAL(wp) ::   xtmp      ! temporary variable
       !!-------------------------------------------------------------------
@@ -1468,9 +1404,10 @@
       CALL wrk_alloc( jpi, jpj, zmask )
 
+      ! to be sure that at_i is the sum of a_i(jl)
+      at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
+
       DO jl = 1, jpl
-
          !-----------------------------------------------------------------
          ! Count categories to be zapped.
-         ! Abort model in case of negative area.
          !-----------------------------------------------------------------
          icells = 0
@@ -1478,8 +1415,7 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               IF(  ( a_i(ji,jj,jl) >= -epsi10 .AND. a_i(ji,jj,jl) <  0._wp   ) .OR.   &
-                  & ( a_i(ji,jj,jl) >  0._wp   .AND. a_i(ji,jj,jl) <= epsi10  ) .OR.   &
-                  & ( v_i(ji,jj,jl) == 0._wp   .AND. a_i(ji,jj,jl) >  0._wp   ) .OR.   &
-                  & ( v_i(ji,jj,jl) >  0._wp   .AND. v_i(ji,jj,jl) <= epsi10  ) )   zmask(ji,jj) = 1._wp
+               IF( a_i(ji,jj,jl) <= epsi10 .OR. v_i(ji,jj,jl) <= epsi10 .OR. at_i(ji,jj) <= epsi10 ) THEN
+                  zmask(ji,jj) = 1._wp
+               ENDIF
             END DO
          END DO
@@ -1494,8 +1430,9 @@
             DO jj = 1 , jpj
                DO ji = 1 , jpi
-!!gm                  xtmp = e_i(ji,jj,jk,jl) / area(ji,jj) * r1_rdtice
-!!gm                  xtmp = xtmp * unit_fac
-                  ! fheat_res(ji,jj) = fheat_res(ji,jj) - xtmp
+                  zei  = e_i(ji,jj,jk,jl)
                   e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * ( 1._wp - zmask(ji,jj) )
+                  t_i(ji,jj,jk,jl) = t_i(ji,jj,jk,jl) * ( 1._wp - zmask(ji,jj) ) + rtt * zmask(ji,jj)
+                  ! update exchanges with ocean
+                  hfx_res(ji,jj)   = hfx_res(ji,jj) + ( e_i(ji,jj,jk,jl) - zei ) * unit_fac / area(ji,jj) * r1_rdtice ! W.m-2 <0
                END DO
             END DO
@@ -1504,5 +1441,9 @@
          DO jj = 1 , jpj
             DO ji = 1 , jpi
-
+               
+               zsal = smv_i(ji,jj,jl)
+               zvi  = v_i(ji,jj,jl)
+               zvs  = v_s(ji,jj,jl)
+               zes  = e_s(ji,jj,1,jl)
                !-----------------------------------------------------------------
                ! Zap snow energy and use ocean heat to melt snow
@@ -1514,9 +1455,4 @@
                ! fluxes are positive to the ocean
                ! here the flux has to be negative for the ocean
-!!gm               xtmp = ( rhosn*cpic*( rtt-t_s(ji,jj,1,jl) ) + rhosn*lfus ) * r1_rdtice
-               !           fheat_res(ji,jj) = fheat_res(ji,jj) - xtmp
-
-!!gm               xtmp = ( rhosn*cpic*( rtt-t_s(ji,jj,1,jl) ) + rhosn*lfus ) * r1_rdtice !RB   ???????
-
                t_s(ji,jj,1,jl) = rtt * zmask(ji,jj) + t_s(ji,jj,1,jl) * ( 1._wp - zmask(ji,jj) )
 
@@ -1524,13 +1460,5 @@
                ! zap ice and snow volume, add water and salt to ocean
                !-----------------------------------------------------------------
-
-               !           xtmp = (rhoi*vicen(i,j,n) + rhos*vsnon(i,j,n)) / dt
-               !           sfx_res(ji,jj)  = sfx_res(ji,jj) + ( sss_m(ji,jj)                  )   &
-               !                                            * rhosn * v_s(ji,jj,jl) * r1_rdtice
-               !           sfx_res(ji,jj)  = sfx_res(ji,jj) + ( sss_m(ji,jj) - sm_i(ji,jj,jl) )   & 
-               !                                            * rhoic * v_i(ji,jj,jl) * r1_rdtice
-               !           sfx (i,j)      = sfx (i,j)      + xtmp
-
-               ato_i(ji,jj)    = a_i  (ji,jj,jl) *       zmask(ji,jj)   + ato_i(ji,jj)
+               ato_i(ji,jj)    = a_i  (ji,jj,jl) *           zmask(ji,jj)   + ato_i(ji,jj)
                a_i  (ji,jj,jl) = a_i  (ji,jj,jl) * ( 1._wp - zmask(ji,jj) )
                v_i  (ji,jj,jl) = v_i  (ji,jj,jl) * ( 1._wp - zmask(ji,jj) )
@@ -1539,9 +1467,21 @@
                oa_i (ji,jj,jl) = oa_i (ji,jj,jl) * ( 1._wp - zmask(ji,jj) )
                smv_i(ji,jj,jl) = smv_i(ji,jj,jl) * ( 1._wp - zmask(ji,jj) )
-               !
+               e_s(ji,jj,1,jl) = e_s(ji,jj,1,jl) * ( 1._wp - zmask(ji,jj) )
+               ! additional condition
+               IF( v_s(ji,jj,jl) <= epsi10 ) THEN
+                  v_s(ji,jj,jl)   = 0._wp
+                  e_s(ji,jj,1,jl) = 0._wp
+               ENDIF
+               ! update exchanges with ocean
+               sfx_res(ji,jj)  = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsal ) * rhoic * r1_rdtice
+               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
+               hfx_res(ji,jj)  = hfx_res(ji,jj) + ( e_s(ji,jj,1,jl) - zes ) * unit_fac / area(ji,jj) * r1_rdtice ! W.m-2 <0
             END DO
          END DO
-         !
-      END DO                 ! jl 
+      END DO ! jl 
+
+      ! to be sure that at_i is the sum of a_i(jl)
+      at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
       !
       CALL wrk_dealloc( jpi, jpj, zmask )
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90	(revision 4921)
@@ -6,5 +6,5 @@
    !! History :   -   !          (W. H. Lipscomb and E.C. Hunke) CICE (c) original code
    !!            3.0  ! 2005-12  (M. Vancoppenolle) adaptation to LIM-3
-   !!             -   ! 2006-06  (M. Vancoppenolle) adaptation to include salt, age and types
+   !!             -   ! 2006-06  (M. Vancoppenolle) adaptation to include salt, age
    !!             -   ! 2007-04  (M. Vancoppenolle) Mass conservation checked
    !!----------------------------------------------------------------------
@@ -35,4 +35,5 @@
    USE lib_fortran      ! to use key_nosignedzero
    USE timing          ! Timing
+   USE limcons        ! conservation tests
 
    IMPLICIT NONE
@@ -65,20 +66,12 @@
       INTEGER, INTENT(in) ::   kt   ! time step index
       !
-      INTEGER ::   jl, ja, jm, jbnd1, jbnd2   ! ice types    dummy loop index         
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-      REAL(wp) :: zchk_vmin, zchk_amin, zchk_amax ! Check errors (C Rousset)
+      INTEGER ::   ji, jj, jk, jl   ! dummy loop index         
+      !
+      REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
       !!------------------------------------------------------------------
       IF( nn_timing == 1 )  CALL timing_start('limitd_th')
 
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) )
-       ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
+      ! conservation test
+      IF( ln_limdiahsb ) CALL lim_cons_hsm(0, 'limitd_th', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
 
       IF( kt == nit000 .AND. lwp ) THEN
@@ -93,9 +86,5 @@
       ! Given thermodynamic growth rates, transport ice between
       ! thickness categories.
-      DO jm = 1, jpm
-         jbnd1 = ice_cat_bounds(jm,1)
-         jbnd2 = ice_cat_bounds(jm,2)
-         IF( ice_ncat_types(jm) > 1 )   CALL lim_itd_th_rem( jbnd1, jbnd2, jm, kt )
-      END DO
+      IF( jpl > 1 )   CALL lim_itd_th_rem( 1, jpl, kt )
       !
       CALL lim_var_glo2eqv    ! only for info
@@ -105,9 +94,8 @@
       !  3) Add frazil ice growing in leads.
       !------------------------------------------------------------------------------|
-
       CALL lim_thd_lac
       CALL lim_var_glo2eqv    ! only for info
-
-     IF(ln_ctl) THEN   ! Control print
+     
+      IF(ln_ctl) THEN   ! Control print
          CALL prt_ctl_info(' ')
          CALL prt_ctl_info(' - Cell values : ')
@@ -131,37 +119,16 @@
             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 ja = 1, nlay_i
+            DO jk = 1, nlay_i
                CALL prt_ctl_info(' ')
-               CALL prt_ctl_info(' - Layer : ', ivar1=ja)
+               CALL prt_ctl_info(' - Layer : ', ivar1=jk)
                CALL prt_ctl_info('   ~~~~~~~')
-               CALL prt_ctl(tab2d_1=t_i(:,:,ja,jl) , clinfo1= ' lim_itd_th  : t_i      : ')
-               CALL prt_ctl(tab2d_1=e_i(:,:,ja,jl) , clinfo1= ' lim_itd_th  : e_i      : ')
+               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
       !
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF( ln_limdiahsb ) THEN
-         zchk_fs  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) * r1_rdtice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) * r1_rdtice + ( zchk_fs / rhoic )
-
-         zchk_vmin = glob_min(v_i)
-         zchk_amax = glob_max(SUM(a_i,dim=3))
-         zchk_amin = glob_min(a_i)
-
-         IF(lwp) THEN
-            IF ( ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limitd_th) = ',(zchk_v_i * rday)
-            IF ( ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limitd_th) = ',(zchk_smv * rday)
-            IF ( zchk_vmin <  0.            ) WRITE(numout,*) 'violation v_i<0  [mm]         (limitd_th) = ',(zchk_vmin * 1.e-3)
-            IF ( zchk_amax >  amax+epsi10   ) WRITE(numout,*) 'violation a_i>amax            (limitd_th) = ',zchk_amax
-            IF ( zchk_amin <  0.            ) WRITE(numout,*) 'violation a_i<0               (limitd_th) = ',zchk_amin
-         ENDIF
-       ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
+      ! conservation test
+      IF( ln_limdiahsb ) CALL lim_cons_hsm(1, 'limitd_th', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
       !
      IF( nn_timing == 1 )  CALL timing_stop('limitd_th')
@@ -169,5 +136,5 @@
    !
 
-   SUBROUTINE lim_itd_th_rem( klbnd, kubnd, ntyp, kt )
+   SUBROUTINE lim_itd_th_rem( klbnd, kubnd, kt )
       !!------------------------------------------------------------------
       !!                ***  ROUTINE lim_itd_th_rem ***
@@ -182,5 +149,4 @@
       INTEGER , INTENT (in) ::   klbnd   ! Start thickness category index point
       INTEGER , INTENT (in) ::   kubnd   ! End point on which the  the computation is applied
-      INTEGER , INTENT (in) ::   ntyp    ! Number of the type used
       INTEGER , INTENT (in) ::   kt      ! Ocean time step 
       !
@@ -200,5 +166,5 @@
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   hL          ! left boundary for the ITD for each thickness
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   hR          ! left boundary for the ITD for each thickness
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zht_i_o     ! old ice thickness
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zht_i_b     ! old ice thickness
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   dummy_es
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   zdaice, zdvice          ! local increment of ice area and volume
@@ -218,5 +184,5 @@
       CALL wrk_alloc( jpi,jpj, zremap_flag )    ! integer
       CALL wrk_alloc( jpi,jpj,jpl-1, zdonor )   ! integer
-      CALL wrk_alloc( jpi,jpj,jpl, zdhice, g0, g1, hL, hR, zht_i_o, dummy_es )
+      CALL wrk_alloc( jpi,jpj,jpl, zdhice, g0, g1, hL, hR, zht_i_b, dummy_es )
       CALL wrk_alloc( jpi,jpj,jpl-1, zdaice, zdvice )   
       CALL wrk_alloc( jpi,jpj,jpl+1, zhbnew, kkstart = 0 )   
@@ -247,5 +213,4 @@
          WRITE(numout,*) ' klbnd :       ', klbnd
          WRITE(numout,*) ' kubnd :       ', kubnd
-         WRITE(numout,*) ' ntyp  :       ', ntyp 
       ENDIF
 
@@ -256,7 +221,7 @@
                zindb             = 1.0 - MAX( 0.0, SIGN( 1.0, - a_i(ji,jj,jl) + epsi10 ) )     !0 if no ice and 1 if yes
                ht_i(ji,jj,jl)    = v_i(ji,jj,jl) / MAX( a_i(ji,jj,jl), epsi10 ) * zindb
-               zindb             = 1.0 - MAX( 0.0, SIGN( 1.0, - old_a_i(ji,jj,jl) + epsi10) ) !0 if no ice and 1 if yes
-               zht_i_o(ji,jj,jl) = old_v_i(ji,jj,jl) / MAX( old_a_i(ji,jj,jl), epsi10 ) * zindb
-               IF( a_i(ji,jj,jl) > epsi06 )   zdhice(ji,jj,jl) = ht_i(ji,jj,jl) - zht_i_o(ji,jj,jl) 
+               zindb             = 1.0 - MAX( 0.0, SIGN( 1.0, - a_i_b(ji,jj,jl) + epsi10) ) !0 if no ice and 1 if yes
+               zht_i_b(ji,jj,jl) = v_i_b(ji,jj,jl) / MAX( a_i_b(ji,jj,jl), epsi10 ) * zindb
+               IF( a_i(ji,jj,jl) > epsi10 )   zdhice(ji,jj,jl) = ht_i(ji,jj,jl) - zht_i_b(ji,jj,jl) 
             END DO
          END DO
@@ -302,17 +267,13 @@
             ij = nind_j(ji)
             !
-            IF ( ( zht_i_o(ii,ij,jl) .GT. epsi10 ) .AND. & 
-               ( zht_i_o(ii,ij,jl+1) .GT. epsi10 ) ) THEN
+            zhbnew(ii,ij,jl) = hi_max(jl)
+            IF ( a_i_b(ii,ij,jl) > epsi10 .AND. a_i_b(ii,ij,jl+1) > epsi10 ) THEN
                !interpolate between adjacent category growth rates
-               zslope = ( zdhice(ii,ij,jl+1)     - zdhice(ii,ij,jl) ) / &
-                  ( zht_i_o   (ii,ij,jl+1) - zht_i_o   (ii,ij,jl) )
-               zhbnew(ii,ij,jl) = hi_max(jl) + zdhice(ii,ij,jl) + &
-                  zslope * ( hi_max(jl) - zht_i_o(ii,ij,jl) )
-            ELSEIF (zht_i_o(ii,ij,jl).gt.epsi10) THEN
+               zslope           = ( zdhice(ii,ij,jl+1) - zdhice(ii,ij,jl) ) / ( zht_i_b(ii,ij,jl+1) - zht_i_b(ii,ij,jl) )
+               zhbnew(ii,ij,jl) = hi_max(jl) + zdhice(ii,ij,jl) + zslope * ( hi_max(jl) - zht_i_b(ii,ij,jl) )
+            ELSEIF ( a_i_b(ii,ij,jl) > epsi10) THEN
                zhbnew(ii,ij,jl) = hi_max(jl) + zdhice(ii,ij,jl)
-            ELSEIF (zht_i_o(ii,ij,jl+1).gt.epsi10) THEN
+            ELSEIF ( a_i_b(ii,ij,jl+1) > epsi10) THEN
                zhbnew(ii,ij,jl) = hi_max(jl) + zdhice(ii,ij,jl+1)
-            ELSE
-               zhbnew(ii,ij,jl) = hi_max(jl)
             ENDIF
          END DO
@@ -320,30 +281,17 @@
          !- 4.2 Check that each zhbnew lies between adjacent values of ice thickness
          DO ji = 1, nbrem
-            ! jl, ji
             ii = nind_i(ji)
             ij = nind_j(ji)
-            ! jl, ji
-            IF ( ( a_i(ii,ij,jl) .GT.epsi10) .AND. & 
-               ( ht_i(ii,ij,jl).GE. zhbnew(ii,ij,jl) ) &
-               ) THEN
+            IF( a_i(ii,ij,jl) > epsi10 .AND. ht_i(ii,ij,jl) >= zhbnew(ii,ij,jl) ) THEN
                zremap_flag(ii,ij) = 0
-            ELSEIF ( ( a_i(ii,ij,jl+1) .GT. epsi10 ) .AND. &
-               ( ht_i(ii,ij,jl+1).LE. zhbnew(ii,ij,jl) ) &
-               ) THEN
+            ELSEIF( a_i(ii,ij,jl+1) > epsi10 .AND. ht_i(ii,ij,jl+1) <= zhbnew(ii,ij,jl) ) THEN
                zremap_flag(ii,ij) = 0
             ENDIF
 
             !- 4.3 Check that each zhbnew does not exceed maximal values hi_max  
-            ! jl, ji
-            IF (zhbnew(ii,ij,jl).gt.hi_max(jl+1)) THEN
-               zremap_flag(ii,ij) = 0
-            ENDIF
-            ! jl, ji
-            IF (zhbnew(ii,ij,jl).lt.hi_max(jl-1)) THEN
-               zremap_flag(ii,ij) = 0
-            ENDIF
-            ! jl, ji
-         END DO !ji
-         ! ji
+            IF( zhbnew(ii,ij,jl) > hi_max(jl+1) ) zremap_flag(ii,ij) = 0
+            IF( zhbnew(ii,ij,jl) < hi_max(jl-1) ) zremap_flag(ii,ij) = 0
+         END DO
+
       END DO !jl
 
@@ -354,11 +302,11 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            IF ( zremap_flag(ji,jj) == 1 ) THEN
+            IF( zremap_flag(ji,jj) == 1 ) THEN
                nbrem         = nbrem + 1
                nind_i(nbrem) = ji
                nind_j(nbrem) = jj
             ENDIF
-         END DO !ji
-      END DO !jj
+         END DO 
+      END DO 
 
       !-----------------------------------------------------------------------------------------------
@@ -367,6 +315,6 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            zhb0(ji,jj) = hi_max_typ(0,ntyp) ! 0eme
-            zhb1(ji,jj) = hi_max_typ(1,ntyp) ! 1er
+            zhb0(ji,jj) = hi_max(0) ! 0eme
+            zhb1(ji,jj) = hi_max(1) ! 1er
 
             zhbnew(ji,jj,klbnd-1) = 0._wp
@@ -380,5 +328,5 @@
             ENDIF
 
-            IF( zhbnew(ji,jj,kubnd) < hi_max(kubnd-1) )   zhbnew(ji,jj,kubnd) = hi_max(kubnd-1)
+            IF( zhbnew(ji,jj,kubnd) < hi_max(kubnd-1) ) zhbnew(ji,jj,kubnd) = hi_max(kubnd-1)
 
          END DO !jj
@@ -389,5 +337,5 @@
       !-----------------------------------------------------------------------------------------------
       !- 7.1 g(h) for category 1 at start of time step
-      CALL lim_itd_fitline( klbnd, zhb0, zhb1, zht_i_o(:,:,klbnd),         &
+      CALL lim_itd_fitline( klbnd, zhb0, zhb1, zht_i_b(:,:,klbnd),         &
          &                  g0(:,:,klbnd), g1(:,:,klbnd), hL(:,:,klbnd),   &
          &                  hR(:,:,klbnd), zremap_flag )
@@ -414,5 +362,5 @@
                   ! Constrain new thickness <= ht_i
                   zdamax = a_i(ii,ij,klbnd) * & 
-                     (1.0 - ht_i(ii,ij,klbnd)/zht_i_o(ii,ij,klbnd)) ! zdamax > 0
+                     (1.0 - ht_i(ii,ij,klbnd)/zht_i_b(ii,ij,klbnd)) ! zdamax > 0
                   !ice area lost due to melting of thin ice
                   zda0   = MIN(zda0, zdamax)
@@ -428,10 +376,7 @@
             ELSE ! if ice accretion
                ! ji, a_i > epsi10; zdh0 > 0
-               IF ( ntyp .EQ. 1 ) zhbnew(ii,ij,klbnd-1) = MIN(zdh0,hi_max(klbnd)) 
+               zhbnew(ii,ij,klbnd-1) = MIN(zdh0,hi_max(klbnd)) 
                ! zhbnew was 0, and is shifted to the right to account for thin ice
                ! growth in openwater (F0 = f1)
-               IF ( ntyp .NE. 1 ) zhbnew(ii,ij,0) = 0 
-               ! in other types there is
-               ! no open water growth (F0 = 0)
             ENDIF ! zdh0 
 
@@ -444,6 +389,5 @@
       DO jl = klbnd, kubnd
          CALL lim_itd_fitline(jl, zhbnew(:,:,jl-1), zhbnew(:,:,jl), ht_i(:,:,jl), &
-            g0(:,:,jl), g1(:,:,jl), hL(:,:,jl), hR(:,:,jl),     &
-            zremap_flag)
+            g0(:,:,jl), g1(:,:,jl), hL(:,:,jl), hR(:,:,jl), zremap_flag)
       END DO
 
@@ -493,6 +437,5 @@
             nd   = zdonor(ii,ij,jl)
             zdaice(ii,ij,jl) = g1(ii,ij,nd)*zx2 + g0(ii,ij,nd)*zx1
-            zdvice(ii,ij,jl) = g1(ii,ij,nd)*zx3 + g0(ii,ij,nd)*zx2 + &
-               zdaice(ii,ij,jl)*hL(ii,ij,nd)
+            zdvice(ii,ij,jl) = g1(ii,ij,nd)*zx3 + g0(ii,ij,nd)*zx2 + zdaice(ii,ij,jl)*hL(ii,ij,nd)
 
          END DO ! ji
@@ -511,8 +454,7 @@
          ii = nind_i(ji)
          ij = nind_j(ji)
-         IF ( ( a_i(ii,ij,1) > epsi10 ) .AND. ( ht_i(ii,ij,1) < hiclim ) ) THEN
+         IF ( a_i(ii,ij,1) > epsi10 .AND. ht_i(ii,ij,1) < hiclim ) THEN
             a_i(ii,ij,1)  = a_i(ii,ij,1) * ht_i(ii,ij,1) / hiclim 
             ht_i(ii,ij,1) = hiclim
-            v_i(ii,ij,1)  = a_i(ii,ij,1) * ht_i(ii,ij,1) !clem-useless
          ENDIF
       END DO !ji
@@ -542,5 +484,5 @@
       CALL wrk_dealloc( jpi,jpj, zremap_flag )    ! integer
       CALL wrk_dealloc( jpi,jpj,jpl-1, zdonor )   ! integer
-      CALL wrk_dealloc( jpi,jpj,jpl, zdhice, g0, g1, hL, hR, zht_i_o, dummy_es )
+      CALL wrk_dealloc( jpi,jpj,jpl, zdhice, g0, g1, hL, hR, zht_i_b, dummy_es )
       CALL wrk_dealloc( jpi,jpj,jpl-1, zdaice, zdvice )   
       CALL wrk_dealloc( jpi,jpj,jpl+1, zhbnew, kkstart = 0 )   
@@ -799,5 +741,5 @@
             !--------------
 
-            zdvsnow          = v_s(ii,ij,jl1) * zworka(ii,ij)
+            zdvsnow        = v_s(ii,ij,jl1) * zworka(ii,ij)
             v_s(ii,ij,jl1) = v_s(ii,ij,jl1) - zdvsnow
             v_s(ii,ij,jl2) = v_s(ii,ij,jl2) + zdvsnow 
@@ -807,5 +749,5 @@
             !--------------------
 
-            zdesnow              = e_s(ii,ij,1,jl1) * zworka(ii,ij)
+            zdesnow            = e_s(ii,ij,1,jl1) * zworka(ii,ij)
             e_s(ii,ij,1,jl1)   = e_s(ii,ij,1,jl1) - zdesnow
             e_s(ii,ij,1,jl2)   = e_s(ii,ij,1,jl2) + zdesnow
@@ -815,5 +757,5 @@
             !--------------
 
-            zdo_aice             = oa_i(ii,ij,jl1) * zdaice(ii,ij,jl)
+            zdo_aice           = oa_i(ii,ij,jl1) * zdaice(ii,ij,jl)
             oa_i(ii,ij,jl1)    = oa_i(ii,ij,jl1) - zdo_aice
             oa_i(ii,ij,jl2)    = oa_i(ii,ij,jl2) + zdo_aice
@@ -823,5 +765,5 @@
             !--------------
 
-            zdsm_vice            = smv_i(ii,ij,jl1) * zworka(ii,ij)
+            zdsm_vice          = smv_i(ii,ij,jl1) * zworka(ii,ij)
             smv_i(ii,ij,jl1)   = smv_i(ii,ij,jl1) - zdsm_vice
             smv_i(ii,ij,jl2)   = smv_i(ii,ij,jl2) + zdsm_vice
@@ -831,5 +773,5 @@
             !---------------------
 
-            zdaTsf               = t_su(ii,ij,jl1) * zdaice(ii,ij,jl)
+            zdaTsf             = t_su(ii,ij,jl1) * zdaice(ii,ij,jl)
             zaTsfn(ii,ij,jl1)  = zaTsfn(ii,ij,jl1) - zdaTsf
             zaTsfn(ii,ij,jl2)  = zaTsfn(ii,ij,jl2) + zdaTsf 
@@ -888,5 +830,5 @@
    
 
-   SUBROUTINE lim_itd_th_reb( klbnd, kubnd, ntyp )
+   SUBROUTINE lim_itd_th_reb( klbnd, kubnd )
       !!------------------------------------------------------------------
       !!                ***  ROUTINE lim_itd_th_reb ***
@@ -898,5 +840,4 @@
       INTEGER , INTENT (in) ::   klbnd   ! Start thickness category index point
       INTEGER , INTENT (in) ::   kubnd   ! End point on which the  the computation is applied
-      INTEGER , INTENT (in) ::   ntyp    ! number of the ice type involved in the rebinning process
       !
       INTEGER ::   ji,jj, jl   ! dummy loop indices
@@ -910,4 +851,5 @@
       REAL(wp), POINTER, DIMENSION(:,:) ::   vt_s_init, vt_s_final   ! snow volume summed over categories
       !!------------------------------------------------------------------
+      !! clem 2014/04: be carefull, rebining does not conserve salt(maybe?) => the difference is taken into account in limupdate
       
       CALL wrk_alloc( jpi,jpj,jpl, zdonor )   ! interger
@@ -937,12 +879,12 @@
 
       !------------------------------------------------------------------------------
-      ! 2) Make sure thickness of cat klbnd is at least hi_max_typ(klbnd)
+      ! 2) Make sure thickness of cat klbnd is at least hi_max(klbnd)
       !------------------------------------------------------------------------------
       DO jj = 1, jpj 
          DO ji = 1, jpi 
             IF( a_i(ji,jj,klbnd) > epsi10 ) THEN
-               IF( ht_i(ji,jj,klbnd) <= hi_max_typ(0,ntyp) .AND. hi_max_typ(0,ntyp) > 0._wp ) THEN
-                  a_i(ji,jj,klbnd)  = v_i(ji,jj,klbnd) / hi_max_typ(0,ntyp) 
-                  ht_i(ji,jj,klbnd) = hi_max_typ(0,ntyp)
+               IF( ht_i(ji,jj,klbnd) <= hi_max(0) .AND. hi_max(0) > 0._wp ) THEN
+                  a_i(ji,jj,klbnd)  = v_i(ji,jj,klbnd) / hi_max(0) 
+                  ht_i(ji,jj,klbnd) = hi_max(0)
                ENDIF
             ENDIF
@@ -1015,38 +957,36 @@
 
 !clem-change
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( a_i(ji,jj,jl+1) > epsi10 .AND. ht_i(ji,jj,jl+1) <= hi_max(jl) ) THEN
+                  !
+                  zshiftflag = 1
+                  zdonor(ji,jj,jl) = jl + 1
+                  zdaice(ji,jj,jl) = a_i(ji,jj,jl+1) 
+                  zdvice(ji,jj,jl) = v_i(ji,jj,jl+1)
+               ENDIF
+            END DO                 ! ji
+         END DO                 ! jj
+
+         IF(lk_mpp)   CALL mpp_max( zshiftflag )
+         
+         IF( zshiftflag == 1 ) THEN            ! Shift ice between categories
+            CALL lim_itd_shiftice( klbnd, kubnd, zdonor, zdaice, zdvice )
+            ! Reset shift parameters
+            zdonor(:,:,jl) = 0
+            zdaice(:,:,jl) = 0._wp
+            zdvice(:,:,jl) = 0._wp
+         ENDIF
+!clem-change
+
+!         ! clem-change begin: why not doing that?
 !         DO jj = 1, jpj
 !            DO ji = 1, jpi
-!               IF( a_i(ji,jj,jl+1) >  epsi10 .AND.   &
-!                  ht_i(ji,jj,jl+1) <= hi_max(jl) ) THEN
-!                  !
-!                  zshiftflag = 1
-!                  zdonor(ji,jj,jl) = jl + 1
-!                  zdaice(ji,jj,jl) = a_i(ji,jj,jl+1) 
-!                  zdvice(ji,jj,jl) = v_i(ji,jj,jl+1)
+!               IF( a_i(ji,jj,jl+1) > epsi10 .AND. ht_i(ji,jj,jl+1) <= hi_max(jl) ) THEN
+!                  ht_i(ji,jj,jl+1) = hi_max(jl) + epsi10
+!                  a_i (ji,jj,jl+1) = v_i(ji,jj,jl+1) / ht_i(ji,jj,jl+1) 
 !               ENDIF
 !            END DO                 ! ji
 !         END DO                 ! jj
-!
-!         IF(lk_mpp)   CALL mpp_max( zshiftflag )
-!         
-!         IF( zshiftflag == 1 ) THEN            ! Shift ice between categories
-!            CALL lim_itd_shiftice( klbnd, kubnd, zdonor, zdaice, zdvice )
-!            ! Reset shift parameters
-!            zdonor(:,:,jl) = 0
-!            zdaice(:,:,jl) = 0._wp
-!            zdvice(:,:,jl) = 0._wp
-!         ENDIF
-!clem-change
-
-         ! clem-change begin: why not doing that?
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( a_i(ji,jj,jl+1) >  epsi10 .AND.   &
-                  ht_i(ji,jj,jl+1) <= hi_max(jl) ) THEN
-                  ht_i(ji,jj,jl+1) = hi_max(jl) + epsi10
-                  a_i (ji,jj,jl+1) = v_i(ji,jj,jl+1) / ht_i(ji,jj,jl+1) 
-               ENDIF
-            END DO                 ! ji
-         END DO                 ! jj
          ! clem-change end
 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90	(revision 4921)
@@ -51,6 +51,4 @@
 
    REAL(wp) ::   epsi10 = 1.e-10_wp   !
-   REAL(wp) ::   rzero   = 0._wp   ! constant values
-   REAL(wp) ::   rone    = 1._wp   ! constant values
       
    !! * Substitutions
@@ -514,5 +512,5 @@
 !CDIR NOVERRCHK
                DO ji = fs_2, fs_jpim1
-                  zmask        = (1.0-MAX(rzero,SIGN(rone,-zmass1(ji,jj))))*tmu(ji,jj)
+                  zmask        = (1.0-MAX(0._wp,SIGN(1._wp,-zmass1(ji,jj))))*tmu(ji,jj)
                   zsang        = SIGN ( 1.0 , fcor(ji,jj) ) * sangvg
                   z0           = zmass1(ji,jj)/dtevp
@@ -547,5 +545,5 @@
                DO ji = fs_2, fs_jpim1
 
-                  zmask        = (1.0-MAX(rzero,SIGN(rone,-zmass2(ji,jj))))*tmv(ji,jj)
+                  zmask        = (1.0-MAX(0._wp,SIGN(1._wp,-zmass2(ji,jj))))*tmv(ji,jj)
                   zsang        = SIGN(1.0,fcor(ji,jj))*sangvg
                   z0           = zmass2(ji,jj)/dtevp
@@ -579,5 +577,5 @@
 !CDIR NOVERRCHK
                DO ji = fs_2, fs_jpim1
-                  zmask        = (1.0-MAX(rzero,SIGN(rone,-zmass2(ji,jj))))*tmv(ji,jj)
+                  zmask        = (1.0-MAX(0._wp,SIGN(1._wp,-zmass2(ji,jj))))*tmv(ji,jj)
                   zsang        = SIGN(1.0,fcor(ji,jj))*sangvg
                   z0           = zmass2(ji,jj)/dtevp
@@ -611,5 +609,5 @@
 !CDIR NOVERRCHK
                DO ji = fs_2, fs_jpim1
-                  zmask        = (1.0-MAX(rzero,SIGN(rone,-zmass1(ji,jj))))*tmu(ji,jj)
+                  zmask        = (1.0-MAX(0._wp,SIGN(1._wp,-zmass1(ji,jj))))*tmu(ji,jj)
                   zsang        = SIGN(1.0,fcor(ji,jj))*sangvg
                   z0           = zmass1(ji,jj)/dtevp
@@ -661,6 +659,4 @@
       ! 4) Prevent ice velocities when the ice is thin
       !------------------------------------------------------------------------------!
-      !clem : add hminrhg in the namelist
-      !
       ! If the ice thickness is below hminrhg (5cm) then ice velocity should equal the
       ! ocean velocity, 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90	(revision 4921)
@@ -142,5 +142,5 @@
          CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
       END DO
-
+      
       DO jl = 1, jpl 
          WRITE(zchar,'(I1)') jl
@@ -162,5 +162,4 @@
       CALL iom_rstput( iter, nitrst, numriw, 'u_ice'        , u_ice      )
       CALL iom_rstput( iter, nitrst, numriw, 'v_ice'        , v_ice      )
-      CALL iom_rstput( iter, nitrst, numriw, 'fsbbq'        , fsbbq      )
       CALL iom_rstput( iter, nitrst, numriw, 'stress1_i'    , stress1_i  )
       CALL iom_rstput( iter, nitrst, numriw, 'stress2_i'    , stress2_i  )
@@ -393,5 +392,4 @@
       CALL iom_get( numrir, jpdom_autoglo, 'u_ice'     , u_ice      )
       CALL iom_get( numrir, jpdom_autoglo, 'v_ice'     , v_ice      )
-      CALL iom_get( numrir, jpdom_autoglo, 'fsbbq'     , fsbbq      )
       CALL iom_get( numrir, jpdom_autoglo, 'stress1_i' , stress1_i  )
       CALL iom_get( numrir, jpdom_autoglo, 'stress2_i' , stress2_i  )
@@ -522,4 +520,15 @@
       END DO
       !
+      ! clem: I do not understand why the following IF is needed
+      !       I suspect something inconsistent in the main code with option num_sal=1
+      IF( num_sal == 1 ) THEN
+         DO jl = 1, jpl 
+            sm_i(:,:,jl) = bulk_sal
+            DO jk = 1, nlay_i 
+               s_i(:,:,jk,jl) = bulk_sal
+            END DO
+         END DO
+      ENDIF
+      !
       !CALL iom_close( numrir ) !clem: closed in sbcice_lim.F90
       !
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90	(revision 4921)
@@ -27,6 +27,5 @@
    USE par_ice          ! ice parameters
    USE dom_oce          ! ocean domain
-   USE domvvl           ! ocean vertical scale factors
-   USE dom_ice,    ONLY : tms
+   USE dom_ice,    ONLY : tms, area
    USE ice              ! LIM sea-ice variables
    USE sbc_ice          ! Surface boundary condition: sea-ice fields
@@ -43,4 +42,6 @@
    USE lib_fortran      ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
    USE traqsr           ! clem: add penetration of solar flux into the calculation of heat budget
+   USE iom
+   USE domvvl           ! Variable volume
 
    IMPLICIT NONE
@@ -51,6 +52,6 @@
    PUBLIC   lim_sbc_tau    ! called by sbc_ice_lim
 
-   REAL(wp)  ::   rzero  = 0._wp    
-   REAL(wp)  ::   rone   = 1._wp
+   REAL(wp)  ::   epsi10 = 1.e-10   !
+   REAL(wp)  ::   epsi20 = 1.e-20   !
 
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   utau_oce, vtau_oce   ! air-ocean surface i- & j-stress     [N/m2]
@@ -104,100 +105,62 @@
       INTEGER, INTENT(in) ::   kt    ! number of iteration
       !
-      INTEGER  ::   ji, jj, jl           ! dummy loop indices
-      INTEGER  ::   ierr, ifvt, i1mfr, idfr           ! local integer
-      INTEGER  ::   iflt, ial , iadv , ifral, ifrdv   !   -      -
-      REAL(wp) ::   zinda, zemp, zemp_snow, zfmm      ! local scalars
-      REAL(wp) ::   zemp_snw                          !   -      -
-      REAL(wp) ::   zfcm1 , zfcm2                     !   -      -
+      INTEGER  ::   ji, jj, jl, jk           ! dummy loop indices
+      REAL(wp) ::   zinda, zemp      ! local scalars
+      REAL(wp) ::   zf_mass         ! Heat flux associated with mass exchange ice->ocean (W.m-2)
+      REAL(wp) ::   zfcm1           ! New solar flux received by the ocean
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   zalb, zalbp     ! 2D/3D workspace
-      REAL(wp) ::   zzfcm1, zfscmbq ! clem: for light penetration
       !!---------------------------------------------------------------------
       
       IF( lk_cpl )   CALL wrk_alloc( jpi, jpj, jpl, zalb, zalbp )
 
-      !------------------------------------------!
-      !      heat flux at the ocean surface      !
-      !------------------------------------------!
+      ! make calls for heat fluxes before it is modified
+      CALL iom_put( "qsr_oce" , qsr(:,:) * pfrld(:,:) )   !     solar flux at ocean surface
+      CALL iom_put( "qns_oce" , qns(:,:) * pfrld(:,:) )   ! non-solar flux at ocean surface
+      CALL iom_put( "qsr_ice" , SUM( qsr_ice(:,:,:) * a_i_b(:,:,:), dim=3 ) )  !     solar flux at ice surface
+      CALL iom_put( "qns_ice" , SUM( qns_ice(:,:,:) * a_i_b(:,:,:), dim=3 ) )  ! non-solar flux at ice surface
+      CALL iom_put( "qtr_ice" , SUM( ftr_ice(:,:,:) * a_i_b(:,:,:), dim=3 ) )  !     solar flux transmitted thru ice
+      CALL iom_put( "qt_oce"  , ( qsr(:,:) + qns(:,:) ) * pfrld(:,:) )  
+      CALL iom_put( "qt_ice"  , SUM( ( qns_ice(:,:,:) + qsr_ice(:,:,:) ) * a_i_b(:,:,:), dim=3 ) )
+
       ! pfrld is the lead fraction at the previous time step (actually between TRP and THD)
-      ! changed to old_frld and old ht_i
-
       DO jj = 1, jpj
          DO ji = 1, jpi
-            zinda   = 1.0 - MAX( rzero , SIGN( rone , - ( 1.0 - pfrld(ji,jj) ) ) )
-            ifvt    = zinda  *  MAX( rzero , SIGN( rone, - phicif(ji,jj) ) )  !subscripts are bad here
-            i1mfr   = 1.0 - MAX( rzero , SIGN( rone ,  - at_i(ji,jj) ) )
-            idfr    = 1.0 - MAX( rzero , SIGN( rone , ( 1.0 - at_i(ji,jj) ) - pfrld(ji,jj) ) )
-            iflt    = zinda  * (1 - i1mfr) * (1 - ifvt )
-            ial     = ifvt   * i1mfr + ( 1 - ifvt ) * idfr
-            iadv    = ( 1  - i1mfr ) * zinda
-            ifral   = ( 1  - i1mfr * ( 1 - ial ) )   
-            ifrdv   = ( 1  - ifral * ( 1 - ial ) ) * iadv 
-
-            ! switch --- 1.0 ---------------- 0.0 --------------------
-            ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-            ! zinda   | if pfrld = 1       | if pfrld < 1            |
-            !  -> ifvt| if pfrld old_ht_i
-            ! i1mfr   | if frld = 1        | if frld  < 1            |
-            ! idfr    | if frld <= pfrld    | if frld > pfrld        |
-            ! iflt    | 
-            ! ial     |
-            ! iadv    |
-            ! ifral
-            ! ifrdv
-
-            !   computation the solar flux at ocean surface
-            IF (lk_cpl) THEN ! be carfeful: not been tested yet
+
+            !------------------------------------------!
+            !      heat flux at the ocean surface      !
+            !------------------------------------------!
+            zinda   = 1._wp - MAX( 0._wp , SIGN( 1._wp , - ( 1._wp - pfrld(ji,jj) ) ) ) ! 1 if ice
+
+            ! Solar heat flux reaching the ocean = zfcm1 (W.m-2) 
+            !---------------------------------------------------
+            IF( lk_cpl ) THEN ! be carfeful: not been tested yet
                ! original line
-               !zfcm1 = qsr_tot(ji,jj) + fstric(ji,jj) * at_i(ji,jj)
-               ! new line to include solar penetration (not tested)
-               zfcm1 = qsr_tot(ji,jj) + fstric(ji,jj) * at_i(ji,jj) / ( 1.0 - zinda + zinda * iatte(ji,jj) )
+               zfcm1 = qsr_tot(ji,jj)
+               !!!zfcm1 = qsr_tot(ji,jj) + ftr_ice(ji,jj) * ( 1._wp - pfrld(ji,jj) ) / ( 1._wp - zinda + zinda * iatte(ji,jj) )
                DO jl = 1, jpl
-                  zfcm1 = zfcm1 - qsr_ice(ji,jj,jl) * a_i(ji,jj,jl)
+                  zfcm1 = zfcm1 - ( qsr_ice(ji,jj,jl) - ftr_ice(ji,jj,jl) ) * a_i_b(ji,jj,jl)
                END DO
             ELSE
-               zfcm1   = pfrld(ji,jj) * qsr(ji,jj)  + &
-                    &    ( 1._wp - pfrld(ji,jj) ) * fstric(ji,jj) / ( 1.0 - zinda + zinda * iatte(ji,jj) )
+               !!!zfcm1   = pfrld(ji,jj) * qsr(ji,jj)  + &
+               !!!     &    ( 1._wp - pfrld(ji,jj) ) * ftr_ice(ji,jj) / ( 1._wp - zinda + zinda * iatte(ji,jj) )
+               zfcm1   = pfrld(ji,jj) * qsr(ji,jj)
+               DO jl = 1, jpl
+                  zfcm1   = zfcm1 + a_i_b(ji,jj,jl) * ftr_ice(ji,jj,jl)
+               END DO
             ENDIF
-            ! fstric     Solar flux transmitted trough the ice
-            ! qsr        Net short wave heat flux on free ocean
-            ! new line
-            fscmbq(ji,jj) = ( 1.0 - pfrld(ji,jj) ) * fstric(ji,jj) / ( 1.0 - zinda + zinda * iatte(ji,jj) )
-
-            ! solar flux and fscmbq with light penetration (clem)
-            zzfcm1  = pfrld(ji,jj) * qsr(ji,jj) * oatte(ji,jj) + ( 1. - pfrld(ji,jj) ) * fstric(ji,jj)
-            zfscmbq = ( 1.0 - pfrld(ji,jj) ) * fstric(ji,jj)
-
-            !  computation the non solar heat flux at ocean surface
-            zfcm2 = - zzfcm1                                                                    & !
-               &    + iflt    * zfscmbq                                                         & ! total ablation: heat given to the ocean
-               &    + ifral   * ( ial * qcmif(ji,jj) + (1 - ial) * qldif(ji,jj) ) * r1_rdtice   &
-               &    + ifrdv   * (       qfvbq(ji,jj) +             qdtcn(ji,jj) ) * r1_rdtice   &
-               &    + fhmec(ji,jj)                                                              & ! snow melt when ridging
-               &    + fheat_mec(ji,jj)                                                          & ! ridge formation
-               &    + fheat_res(ji,jj)                                                            ! residual heat flux
-            ! qcmif   Energy needed to bring the ocean surface layer until its freezing (ok)
-            ! qldif   heat balance of the lead (or of the open ocean)
-            ! qfvbq   latent heat uptake/release after accretion/ablation
-            ! qdtcn   Energy from the turbulent oceanic heat flux heat flux coming in the lead
-
-            IF( num_sal == 2 )   zfcm2 = zfcm2 + fhbri(ji,jj)    ! add contribution due to brine drainage 
-
-            ! bottom radiative component is sent to the computation of the oceanic heat flux
-            fsbbq(ji,jj) = ( 1._wp - ( ifvt + iflt ) ) * fscmbq(ji,jj)     
-
-            ! used to compute the oceanic heat flux at the next time step
-            qsr(ji,jj) = zfcm1                                       ! solar heat flux 
-            qns(ji,jj) = zfcm2 - fdtcn(ji,jj)                        ! non solar heat flux
-            !                           ! fdtcn : turbulent oceanic heat flux
-         END DO
-      END DO
-
-      !------------------------------------------!
-      !      mass flux at the ocean surface      !
-      !------------------------------------------!
-
-!!gm   optimisation: this loop have to be merged with the previous one
-      DO jj = 1, jpj
-         DO ji = 1, jpi
+
+            ! Total heat flux reaching the ocean = hfx_out (W.m-2) 
+            !---------------------------------------------------
+            zf_mass        = hfx_thd(ji,jj) + hfx_dyn(ji,jj) + hfx_res(ji,jj) ! heat flux from snow is 0 (T=0 degC)
+            hfx_out(ji,jj) = hfx_out(ji,jj) + zf_mass + zfcm1
+
+            ! New qsr and qns used to compute the oceanic heat flux at the next time step
+            !---------------------------------------------------
+            qsr(ji,jj) = zfcm1                                      
+            qns(ji,jj) = hfx_out(ji,jj) - zfcm1              
+
+            !------------------------------------------!
+            !      mass flux at the ocean surface      !
+            !------------------------------------------!
             !  case of realistic freshwater flux (Tartinville et al., 2001) (presently ACTIVATED)
             !  ------------------------------------------------------------------------------------- 
@@ -208,27 +171,22 @@
             !                     Even if i see Ice melting as a FW and SALT flux
             !        
-
             !  computing freshwater exchanges at the ice/ocean interface
-            IF (lk_cpl) THEN 
+            IF( lk_cpl ) THEN 
                zemp = - emp_tot(ji,jj) + emp_ice(ji,jj) * ( 1. - pfrld(ji,jj) )    &   !
-                  &   - rdm_snw(ji,jj) / rdt_ice
+                  &   + wfx_snw(ji,jj)
             ELSE
-               zemp =   emp(ji,jj)     * ( 1.0 - at_i(ji,jj)          )  &   ! evaporation over oceanic fraction
-                  &   - tprecip(ji,jj) *         at_i(ji,jj)             &   ! all precipitation reach the ocean
-                  &   + sprecip(ji,jj) * ( 1. - (pfrld(ji,jj)**betas) )  &   ! except solid precip intercepted by sea-ice
-                  &   - fmmec(ji,jj)                                         ! snow falling when ridging
+               zemp =   emp(ji,jj)     *           pfrld(ji,jj)            &   ! evaporation over oceanic fraction
+                  &   - tprecip(ji,jj) * ( 1._wp - pfrld(ji,jj) )          &   ! all precipitation reach the ocean
+                  &   + sprecip(ji,jj) * ( 1._wp - pfrld(ji,jj)**betas )       ! except solid precip intercepted by sea-ice
             ENDIF
 
-            ! mass flux at the ocean/ice interface (sea ice fraction)
-            zemp_snw = rdm_snw(ji,jj) * r1_rdtice                         ! snow melting = pure water that enters the ocean
-            zfmm     = rdm_ice(ji,jj) * r1_rdtice                         ! Freezing minus melting  
-
-            fmmflx(ji,jj) = zfmm                                     ! F/M mass flux save at least for biogeochemical model
-
-            emp(ji,jj) = zemp + zemp_snw + zfmm  ! mass flux + F/M mass flux (always ice/ocean mass exchange)
+            ! 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)
+
+            ! mass flux at the ocean/ice interface
+            fmmflx(ji,jj) = - wfx_ice(ji,jj) * rdt_ice                   ! F/M mass flux save at least for biogeochemical model
+            emp(ji,jj)    = zemp - wfx_ice(ji,jj) - wfx_snw(ji,jj)       ! mass flux + F/M mass flux (always ice/ocean mass exchange)
             
-            !  correcting brine salt fluxes   (zinda = 1  if pfrld=1 , =0 otherwise)
-            zinda        = 1.0 - MAX( rzero , SIGN( rone , - ( 1.0 - pfrld(ji,jj) ) ) )
-            sfx_bri(ji,jj) = zinda * sfx_bri(ji,jj)
          END DO
       END DO
@@ -237,18 +195,16 @@
       !      salt flux at the ocean surface      !
       !------------------------------------------!
-
-      IF( num_sal == 2 ) THEN      ! variable ice salinity: brine drainage included in the salt flux
-         sfx(:,:) = sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) + sfx_bri(:,:)
-      ELSE                         ! constant ice salinity:
-         sfx(:,:) = sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:)
-      ENDIF
-      !-----------------------------------------------!
-      !   mass of snow and ice per unit area          !
-      !-----------------------------------------------!
-      IF( nn_ice_embd /= 0 ) THEN                               ! embedded sea-ice (mass required)
-         snwice_mass_b(:,:) = snwice_mass(:,:)                  ! save mass from the previous ice time step
-         !                                                      ! new mass per unit area
+      sfx(:,:) = sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) + sfx_opw(:,:)   &
+         &     + sfx_res(:,:) + sfx_dyn(:,:) + sfx_bri(:,:)
+
+      !-------------------------------------------------------------!
+      !   mass of snow and ice per unit area for embedded sea-ice   !
+      !-------------------------------------------------------------!
+      IF( nn_ice_embd /= 0 ) THEN
+         ! save mass from the previous ice time step
+         snwice_mass_b(:,:) = snwice_mass(:,:)                  
+         ! new mass per unit area
          snwice_mass  (:,:) = tms(:,:) * ( rhosn * vt_s(:,:) + rhoic * vt_i(:,:)  ) 
-         !                                                      ! time evolution of snow+ice mass
+         ! time evolution of snow+ice mass
          snwice_fmass (:,:) = ( snwice_mass(:,:) - snwice_mass_b(:,:) ) * r1_rdtice
       ENDIF
@@ -265,7 +221,7 @@
       IF( lk_cpl ) THEN          ! coupled case
          CALL albedo_ice( t_su, ht_i, ht_s, zalbp, zalb )                  ! snow/ice albedo
-         !
          alb_ice(:,:,:) =  0.5_wp * zalbp(:,:,:) + 0.5_wp * zalb (:,:,:)   ! Ice albedo (mean clear and overcast skys)
       ENDIF
+
 
       IF(ln_ctl) THEN
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 4921)
@@ -8,5 +8,5 @@
    !!            3.0  ! 2005-11 (M. Vancoppenolle)  LIM-3 : Multi-layer thermodynamics + salinity variations
    !!             -   ! 2007-04 (M. Vancoppenolle) add lim_thd_glohec, lim_thd_con_dh and lim_thd_con_dif
-   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in rdm_snw
+   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in wfx_snw
    !!            3.3  ! 2010-11 (G. Madec) corrected snow melting heat (due to factor betas)
    !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
@@ -43,4 +43,6 @@
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
    USE timing         ! Timing
+   USE cpl_oasis3, ONLY : lk_cpl
+   USE limcons        ! conservation tests
 
    IMPLICIT NONE
@@ -51,6 +53,4 @@
 
    REAL(wp) ::   epsi10 = 1.e-10_wp   !
-   REAL(wp) ::   zzero  = 0._wp      !
-   REAL(wp) ::   zone   = 1._wp      !
 
    !! * Substitutions
@@ -84,28 +84,18 @@
       INTEGER, INTENT(in) ::   kt    ! number of iteration
       !!
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      INTEGER  ::   nbpb             ! nb of icy pts for thermo. cal.
-      REAL(wp) ::   zfric_umin = 5e-03_wp    ! lower bound for the friction velocity
-      REAL(wp) ::   zfric_umax = 2e-02_wp    ! upper bound for the friction velocity
-      REAL(wp) ::   zinda, zindb, zthsnice, zfric_u     ! local scalar
-      REAL(wp) ::   zfntlat, zpareff, zareamin, zcoef   !    -         -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zqlbsbq   ! link with lead energy budget qldif
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-      REAL(wp) :: zchk_vmin, zchk_amin, zchk_amax ! Check errors (C Rousset)
+      INTEGER  :: ji, jj, jk, jl   ! dummy loop indices
+      INTEGER  :: nbpb             ! nb of icy pts for thermo. cal.
+      INTEGER  :: ii, ij           ! temporary dummy loop index
+      REAL(wp) :: zfric_umin = 0._wp        ! lower bound for the friction velocity (cice value=5.e-04)
+      REAL(wp) :: zch        = 0.0057_wp    ! heat transfer coefficient
+      REAL(wp) :: zinda, zindb, zareamin 
+      REAL(wp) :: zfric_u, zqld, zqfr
+      !
+      REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
       !!-------------------------------------------------------------------
       IF( nn_timing == 1 )  CALL timing_start('limthd')
 
-      CALL wrk_alloc( jpi, jpj, zqlbsbq )
-   
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) )
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
+      ! conservation test
+      IF( ln_limdiahsb ) CALL lim_cons_hsm(0, 'limthd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
 
       !------------------------------------------------------------------------------!
@@ -121,10 +111,10 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  !Energy of melting q(S,T) [J.m-3]
-                  e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) / ( area(ji,jj) * MAX( v_i(ji,jj,jl) , epsi10 ) ) * REAL( nlay_i )
                   !0 if no ice and 1 if yes
                   zindb = 1.0 - MAX(  0.0 , SIGN( 1.0 , - v_i(ji,jj,jl) + epsi10 )  )
-                  !convert units ! very important that this line is here
-                  e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * unit_fac * zindb 
+                  !Energy of melting q(S,T) [J.m-3]
+                  e_i(ji,jj,jk,jl) = zindb * e_i(ji,jj,jk,jl) / ( area(ji,jj) * MAX( v_i(ji,jj,jl) , epsi10 ) ) * REAL( nlay_i )
+                  !convert units ! very important that this line is here        
+                  e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * unit_fac 
                END DO
             END DO
@@ -133,24 +123,14 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  !Energy of melting q(S,T) [J.m-3]
-                  e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) / ( area(ji,jj) * MAX( v_s(ji,jj,jl) , epsi10 ) ) * REAL( nlay_s )
                   !0 if no ice and 1 if yes
                   zindb = 1.0 - MAX(  0.0 , SIGN( 1.0 , - v_s(ji,jj,jl) + epsi10 )  )
+                  !Energy of melting q(S,T) [J.m-3]
+                  e_s(ji,jj,jk,jl) = zindb * e_s(ji,jj,jk,jl) / ( area(ji,jj) * MAX( v_s(ji,jj,jl) , epsi10 ) ) * REAL( nlay_s )
                   !convert units ! very important that this line is here
-                  e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * unit_fac * zindb 
+                  e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * unit_fac 
                END DO
             END DO
          END DO
       END DO
-
-      !-----------------------------------
-      ! 1.4) Compute global heat content
-      !-----------------------------------
-      qt_i_in  (:,:) = 0.e0
-      qt_s_in  (:,:) = 0.e0
-      qt_i_fin (:,:) = 0.e0
-      qt_s_fin (:,:) = 0.e0
-      sum_fluxq(:,:) = 0.e0
-      fatm     (:,:) = 0.e0
 
       ! 2) Partial computation of forcing for the thermodynamic sea ice model.      !
@@ -161,5 +141,5 @@
 !CDIR NOVERRCHK
          DO ji = 1, jpi
-            zinda          = tms(ji,jj) * ( 1.0 - MAX( zzero , SIGN( zone , - at_i(ji,jj) + epsi10 ) ) )
+            zinda          = tms(ji,jj) * ( 1._wp - MAX( 0._wp , SIGN( 1._wp , - at_i(ji,jj) + epsi10 ) ) ) ! 0 if no ice
             !
             !           !  solar irradiance transmission at the mixed layer bottom and used in the lead heat budget
@@ -168,39 +148,67 @@
             !           !  net downward heat flux from the ice to the ocean, expressed as a function of ocean 
             !           !  temperature and turbulent mixing (McPhee, 1992)
-            ! friction velocity
-            zfric_u        = MAX ( MIN( SQRT( ust2s(ji,jj) ) , zfric_umax ) , zfric_umin ) 
-
-            ! here the drag will depend on ice thickness and type (0.006)
-            fdtcn(ji,jj)  = zinda * rau0 * rcp * 0.006  * zfric_u * ( ( sst_m(ji,jj) + rt0 ) - t_bo(ji,jj) ) 
-            ! also category dependent
-            !           !-- Energy from the turbulent oceanic heat flux heat flux coming in the lead 
-            qdtcn(ji,jj)  = zinda * fdtcn(ji,jj) * ( 1.0 - at_i(ji,jj) ) * rdt_ice
-            !                       
-            !           !-- Lead heat budget, qldif (part 1, next one is in limthd_dh) 
-            !           !   caution: exponent betas used as more snow can fallinto leads
-            qldif(ji,jj) =  tms(ji,jj) * rdt_ice  * (                             &
-               &   pfrld(ji,jj)        * (  qsr(ji,jj) * oatte(ji,jj)             &   ! solar heat + clem modif
-               &                            + qns(ji,jj)                          &   ! non solar heat
-               &                            + fdtcn(ji,jj)                        &   ! turbulent ice-ocean heat
-               &                            + fsbbq(ji,jj) * ( 1.0 - zinda )  )   &   ! residual heat from previous step
-               & - pfrld(ji,jj)**betas * sprecip(ji,jj) * lfus                    )   ! latent heat of sprecip melting
             !
-            ! Positive heat budget is used for bottom ablation
-            zfntlat        = 1.0 - MAX( zzero , SIGN( zone ,  - qldif(ji,jj) ) )
-            != 1 if positive heat budget
-            zpareff        = 1.0 - zinda * zfntlat
-            != 0 if ice and positive heat budget and 1 if one of those two is false
-            zqlbsbq(ji,jj) = qldif(ji,jj) * ( 1.0 - zpareff ) / ( rdt_ice * MAX( at_i(ji,jj), epsi10 ) )
+            ! --- Energy received in the lead, zqld is defined everywhere (J.m-2) --- !
+            zqld =  tms(ji,jj) * rdt_ice *                                       &
+               &  ( pfrld(ji,jj)         * ( qsr(ji,jj) * oatte(ji,jj)           &   ! solar heat + clem modif
+               &                           + qns(ji,jj) )                        &   ! non solar heat
+               ! latent heat of precip (note that precip is included in qns but not in qns_ice)
+               &    + ( pfrld(ji,jj)**betas - pfrld(ji,jj) ) * sprecip(ji,jj)         &
+               &    * ( cpic * ( MIN( tatm_ice(ji,jj), rt0_snow ) - rtt ) - lfus )    &
+               &    + ( 1._wp - pfrld(ji,jj) ) * ( tprecip(ji,jj) - sprecip(ji,jj) )  &
+               &    * rcp * ( tatm_ice(ji,jj) - rtt ) )
+
+            !-- Energy needed to bring ocean surface layer until its freezing (<0, J.m-2) --- !
+            zqfr = tms(ji,jj) * rau0 * rcp * fse3t_m(ji,jj) * ( t_bo(ji,jj) - ( sst_m(ji,jj) + rt0 ) )
+
+            !-- Energy Budget of the leads (J.m-2). Must be < 0 to form ice
+            qlead(ji,jj) = MIN( 0._wp , zqld - zqfr ) 
+
+            ! If there is ice and leads are warming, then transfer energy from the lead budget and use it for bottom melting 
+            IF( at_i(ji,jj) > epsi10 .AND. zqld > 0._wp ) THEN
+               fhld (ji,jj) = zqld * r1_rdtice / at_i(ji,jj) ! divided by at_i since this is (re)multiplied by a_i in limthd_dh.F90
+               qlead(ji,jj) = 0._wp
+            ENDIF
             !
-            ! Heat budget of the lead, energy transferred from ice to ocean
-            qldif  (ji,jj) = zpareff * qldif(ji,jj)
-            qdtcn  (ji,jj) = zpareff * qdtcn(ji,jj)
-            !
-            ! Energy needed to bring ocean surface layer until its freezing (qcmif, limflx)
-            qcmif  (ji,jj) =  rau0 * rcp * fse3t_m(ji,jj) * ( t_bo(ji,jj) - ( sst_m(ji,jj) + rt0 ) )
-            !
-            ! oceanic heat flux (limthd_dh)
-            fbif   (ji,jj) = zinda * (  fsbbq(ji,jj) / MAX( at_i(ji,jj) , epsi10 ) + fdtcn(ji,jj) )
-            !
+            !-- Energy from the turbulent oceanic heat flux --- !
+            !clem zfric_u        = MAX ( MIN( SQRT( ust2s(ji,jj) ) , zfric_umax ) , zfric_umin )
+            zfric_u      = MAX( SQRT( ust2s(ji,jj) ), zfric_umin ) 
+            fhtur(ji,jj) = MAX( 0._wp, zinda * rau0 * rcp * zch  * zfric_u * ( ( sst_m(ji,jj) + rt0 ) - t_bo(ji,jj) ) ) ! W.m-2 
+            ! upper bound for fhtur: we do not want SST to drop below Tfreeze. 
+            ! So we say that the heat retrieved from the ocean (fhtur+fhld) must be < to the heat necessary to reach Tfreeze (zqfr)   
+            ! This is not a clean budget, so that should be corrected at some point
+            fhtur(ji,jj) = zinda * MIN( fhtur(ji,jj), - fhld(ji,jj) - zqfr * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) )
+
+            ! -----------------------------------------
+            ! Net heat flux on top of ice-ocean [W.m-2]
+            ! -----------------------------------------
+            !     First  step here      : heat flux at the ocean surface + precip
+            !     Second step below     : heat flux at the ice   surface (after limthd_dif) 
+            hfx_in(ji,jj) = hfx_in(ji,jj)                                                                                         & 
+               ! heat flux above the ocean
+               &    +             pfrld(ji,jj)   * ( qns(ji,jj) + qsr(ji,jj) )                                                    &
+               ! latent heat of precip (note that precip is included in qns but not in qns_ice)
+               &    +   ( 1._wp - pfrld(ji,jj) ) * sprecip(ji,jj) * ( cpic * ( MIN( tatm_ice(ji,jj), rt0_snow ) - rtt ) - lfus )  &
+               &    +   ( 1._wp - pfrld(ji,jj) ) * ( tprecip(ji,jj) - sprecip(ji,jj) ) * rcp * ( tatm_ice(ji,jj) - rtt )
+
+            ! -----------------------------------------------------------------------------
+            ! Net heat flux that is retroceded to the ocean or taken from the ocean [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
+            hfx_out(ji,jj) = hfx_out(ji,jj)                                                                                   & 
+               ! Non solar heat flux received by the ocean
+               &    +        pfrld(ji,jj) * qns(ji,jj)                                                                        &
+               ! latent heat of precip (note that precip is included in qns but not in qns_ice)
+               &    +      ( pfrld(ji,jj)**betas - pfrld(ji,jj) ) * sprecip(ji,jj)                                            &
+               &    * ( cpic * ( MIN( tatm_ice(ji,jj), rt0_snow ) - rtt ) - lfus )                                            &
+               &    +      ( 1._wp - pfrld(ji,jj) ) * ( tprecip(ji,jj) - sprecip(ji,jj) ) * rcp * ( tatm_ice(ji,jj) - rtt )   &
+               ! heat flux taken from the ocean where there is open water ice formation
+               &    -      qlead(ji,jj) * r1_rdtice                                                                           &
+               ! heat flux taken from the ocean during bottom growth/melt (fhld should be 0 while bott growth)
+               &    -      at_i(ji,jj) * fhtur(ji,jj)                                                                         &
+               &    -      at_i(ji,jj) *  fhld(ji,jj)
+
          END DO
       END DO
@@ -234,4 +242,5 @@
                DO jj = mj0(jjindx), mj1(jjindx)
                   jiindex_1d = (jj - 1) * jpi + ji
+                  WRITE(numout,*) ' lim_thd : Category no : ', jl 
                END DO
             END DO
@@ -250,19 +259,19 @@
             !-------------------------
 
-            CALL tab_2d_1d( nbpb, at_i_b     (1:nbpb), at_i            , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, a_i_b      (1:nbpb), a_i(:,:,jl)     , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, ht_i_b     (1:nbpb), ht_i(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, ht_s_b     (1:nbpb), ht_s(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
-
-            CALL tab_2d_1d( nbpb, t_su_b     (1:nbpb), t_su(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, sm_i_b     (1:nbpb), sm_i(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, at_i_1d     (1:nbpb), at_i            , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, a_i_1d      (1:nbpb), a_i(:,:,jl)     , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, ht_i_1d     (1:nbpb), ht_i(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, ht_s_1d     (1:nbpb), ht_s(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
+
+            CALL tab_2d_1d( nbpb, t_su_1d     (1:nbpb), t_su(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, sm_i_1d     (1:nbpb), sm_i(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
             DO jk = 1, nlay_s
-               CALL tab_2d_1d( nbpb, t_s_b(1:nbpb,jk), t_s(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
-               CALL tab_2d_1d( nbpb, q_s_b(1:nbpb,jk), e_s(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
+               CALL tab_2d_1d( nbpb, t_s_1d(1:nbpb,jk), t_s(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
+               CALL tab_2d_1d( nbpb, q_s_1d(1:nbpb,jk), e_s(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
             END DO
             DO jk = 1, nlay_i
-               CALL tab_2d_1d( nbpb, t_i_b(1:nbpb,jk), t_i(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
-               CALL tab_2d_1d( nbpb, q_i_b(1:nbpb,jk), e_i(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
-               CALL tab_2d_1d( nbpb, s_i_b(1:nbpb,jk), s_i(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
+               CALL tab_2d_1d( nbpb, t_i_1d(1:nbpb,jk), t_i(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
+               CALL tab_2d_1d( nbpb, q_i_1d(1:nbpb,jk), e_i(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
+               CALL tab_2d_1d( nbpb, s_i_1d(1:nbpb,jk), s_i(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
             END DO
 
@@ -271,58 +280,76 @@
             CALL tab_2d_1d( nbpb, fr1_i0_1d  (1:nbpb), fr1_i0          , jpi, jpj, npb(1:nbpb) )
             CALL tab_2d_1d( nbpb, fr2_i0_1d  (1:nbpb), fr2_i0          , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, qnsr_ice_1d(1:nbpb), qns_ice(:,:,jl) , jpi, jpj, npb(1:nbpb) )
-#if ! defined key_coupled
-            CALL tab_2d_1d( nbpb, qla_ice_1d (1:nbpb), qla_ice(:,:,jl) , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, dqla_ice_1d(1:nbpb), dqla_ice(:,:,jl), jpi, jpj, npb(1:nbpb) )
-#endif
+            CALL tab_2d_1d( nbpb, qns_ice_1d (1:nbpb), qns_ice(:,:,jl) , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, ftr_ice_1d (1:nbpb), ftr_ice(:,:,jl) , jpi, jpj, npb(1:nbpb) )
+            IF( .NOT. lk_cpl ) THEN
+               CALL tab_2d_1d( nbpb, qla_ice_1d (1:nbpb), qla_ice(:,:,jl) , jpi, jpj, npb(1:nbpb) )
+               CALL tab_2d_1d( nbpb, dqla_ice_1d(1:nbpb), dqla_ice(:,:,jl), jpi, jpj, npb(1:nbpb) )
+            ENDIF
             CALL tab_2d_1d( nbpb, dqns_ice_1d(1:nbpb), dqns_ice(:,:,jl), jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, t_bo_b     (1:nbpb), t_bo            , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, t_bo_1d     (1:nbpb), t_bo            , jpi, jpj, npb(1:nbpb) )
             CALL tab_2d_1d( nbpb, sprecip_1d (1:nbpb), sprecip         , jpi, jpj, npb(1:nbpb) ) 
-            CALL tab_2d_1d( nbpb, fbif_1d    (1:nbpb), fbif            , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, qldif_1d   (1:nbpb), qldif           , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, rdm_ice_1d (1:nbpb), rdm_ice         , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, rdm_snw_1d (1:nbpb), rdm_snw         , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, dmgwi_1d   (1:nbpb), dmgwi           , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, qlbbq_1d   (1:nbpb), zqlbsbq         , jpi, jpj, npb(1:nbpb) )
-
-            CALL tab_2d_1d( nbpb, sfx_thd_1d (1:nbpb), sfx_thd         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, fhtur_1d   (1:nbpb), fhtur           , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, qlead_1d   (1:nbpb), qlead           , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, fhld_1d    (1:nbpb), fhld            , jpi, jpj, npb(1:nbpb) )
+
+            CALL tab_2d_1d( nbpb, wfx_snw_1d (1:nbpb), wfx_snw         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, wfx_sub_1d (1:nbpb), wfx_sub         , jpi, jpj, npb(1:nbpb) )
+
+            CALL tab_2d_1d( nbpb, wfx_bog_1d (1:nbpb), wfx_bog         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, wfx_bom_1d (1:nbpb), wfx_bom         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, wfx_sum_1d (1:nbpb), wfx_sum         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, wfx_sni_1d (1:nbpb), wfx_sni         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, wfx_res_1d (1:nbpb), wfx_res         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, wfx_spr_1d (1:nbpb), wfx_spr         , jpi, jpj, npb(1:nbpb) )
+
+            CALL tab_2d_1d( nbpb, sfx_bog_1d (1:nbpb), sfx_bog         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, sfx_bom_1d (1:nbpb), sfx_bom         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, sfx_sum_1d (1:nbpb), sfx_sum         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, sfx_sni_1d (1:nbpb), sfx_sni         , jpi, jpj, npb(1:nbpb) )
             CALL tab_2d_1d( nbpb, sfx_bri_1d (1:nbpb), sfx_bri         , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, fhbri_1d   (1:nbpb), fhbri           , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, fstbif_1d  (1:nbpb), fstric          , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, qfvbq_1d   (1:nbpb), qfvbq           , jpi, jpj, npb(1:nbpb) )
-
-            CALL tab_2d_1d( nbpb, iatte_1d   (1:nbpb), iatte           , jpi, jpj, npb(1:nbpb) ) ! clem modif
-            CALL tab_2d_1d( nbpb, oatte_1d   (1:nbpb), oatte           , jpi, jpj, npb(1:nbpb) ) ! clem modif
+            CALL tab_2d_1d( nbpb, sfx_res_1d (1:nbpb), sfx_res         , jpi, jpj, npb(1:nbpb) )
+
+            CALL tab_2d_1d( nbpb, iatte_1d   (1:nbpb), iatte           , jpi, jpj, npb(1:nbpb) ) 
+            CALL tab_2d_1d( nbpb, oatte_1d   (1:nbpb), oatte           , jpi, jpj, npb(1:nbpb) ) 
+
+            CALL tab_2d_1d( nbpb, hfx_thd_1d (1:nbpb), hfx_thd         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, hfx_spr_1d (1:nbpb), hfx_spr         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, hfx_sum_1d (1:nbpb), hfx_sum         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, hfx_bom_1d (1:nbpb), hfx_bom         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, hfx_bog_1d (1:nbpb), hfx_bog         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, hfx_dif_1d (1:nbpb), hfx_dif         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, hfx_opw_1d (1:nbpb), hfx_opw         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, hfx_snw_1d (1:nbpb), hfx_snw         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, hfx_sub_1d (1:nbpb), hfx_sub         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, hfx_err_1d (1:nbpb), hfx_err         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, hfx_res_1d (1:nbpb), hfx_res         , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, hfx_err_rem_1d (1:nbpb), hfx_err_rem , jpi, jpj, npb(1:nbpb) )
+
             !--------------------------------
             ! 4.3) Thermodynamic processes
             !--------------------------------
 
-            IF( con_i .AND. jiindex_1d > 0 )   CALL lim_thd_enmelt( 1, nbpb )   ! computes sea ice energy of melting
-            IF( con_i .AND. jiindex_1d > 0 )   CALL lim_thd_glohec( qt_i_in, qt_s_in, q_i_layer_in, 1, nbpb, jl )
-
-            !                                 !---------------------------------!
-            CALL lim_thd_dif( 1, nbpb, jl )   ! Ice/Snow Temperature profile    !
-            !                                 !---------------------------------!
-
-            CALL lim_thd_enmelt( 1, nbpb )    ! computes sea ice energy of melting compulsory for limthd_dh
-
-            IF( con_i .AND. jiindex_1d > 0 )   CALL lim_thd_glohec ( qt_i_fin, qt_s_fin, q_i_layer_fin, 1, nbpb, jl ) 
-            IF( con_i .AND. jiindex_1d > 0 )   CALL lim_thd_con_dif( 1 , nbpb , jl )
-
-            !                                 !---------------------------------!
-            CALL lim_thd_dh( 1, nbpb, jl )    ! Ice/Snow thickness              ! 
-            !                                 !---------------------------------!
-
-            !                                 !---------------------------------!
-            CALL lim_thd_ent( 1, nbpb, jl )   ! Ice/Snow enthalpy remapping     !
-            !                                 !---------------------------------!
-
-            !                                 !---------------------------------!
-            CALL lim_thd_sal( 1, nbpb )       ! Ice salinity computation        !
-            !                                 !---------------------------------!
-
-            !           CALL lim_thd_enmelt(1,nbpb)   ! computes sea ice energy of melting
-            IF( con_i .AND. jiindex_1d > 0 )   CALL lim_thd_glohec( qt_i_fin, qt_s_fin, q_i_layer_fin, 1, nbpb, jl ) 
-            IF( con_i .AND. jiindex_1d > 0 )   CALL lim_thd_con_dh ( 1 , nbpb , jl )
+            !---------------------------------!
+            ! Ice/Snow Temperature profile    !
+            !---------------------------------!
+            CALL lim_thd_dif( 1, nbpb )
+
+            !---------------------------------!
+            ! Ice/Snow thicnkess              !
+            !---------------------------------!
+            CALL lim_thd_dh( 1, nbpb )    
+
+            ! --- Ice enthalpy remapping --- !
+            CALL lim_thd_ent( 1, nbpb, q_i_1d(1:nbpb,:) ) 
+                                            
+            !---------------------------------!
+            ! --- Ice salinity --- !
+            !---------------------------------!
+            CALL lim_thd_sal( 1, nbpb )    
+
+            !---------------------------------!
+            ! --- temperature update --- !
+            !---------------------------------!
+            CALL lim_thd_temp( 1, nbpb )
 
             !--------------------------------
@@ -330,45 +357,62 @@
             !--------------------------------
 
-               CALL tab_1d_2d( nbpb, at_i          , npb, at_i_b    (1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, ht_i(:,:,jl)  , npb, ht_i_b    (1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, ht_s(:,:,jl)  , npb, ht_s_b    (1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, a_i (:,:,jl)  , npb, a_i_b     (1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, t_su(:,:,jl)  , npb, t_su_b    (1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, sm_i(:,:,jl)  , npb, sm_i_b    (1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, at_i          , npb, at_i_1d    (1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, ht_i(:,:,jl)  , npb, ht_i_1d    (1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, ht_s(:,:,jl)  , npb, ht_s_1d    (1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, a_i (:,:,jl)  , npb, a_i_1d     (1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, t_su(:,:,jl)  , npb, t_su_1d    (1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, sm_i(:,:,jl)  , npb, sm_i_1d    (1:nbpb)   , jpi, jpj )
             DO jk = 1, nlay_s
-               CALL tab_1d_2d( nbpb, t_s(:,:,jk,jl), npb, t_s_b     (1:nbpb,jk), jpi, jpj)
-               CALL tab_1d_2d( nbpb, e_s(:,:,jk,jl), npb, q_s_b     (1:nbpb,jk), jpi, jpj)
+               CALL tab_1d_2d( nbpb, t_s(:,:,jk,jl), npb, t_s_1d     (1:nbpb,jk), jpi, jpj)
+               CALL tab_1d_2d( nbpb, e_s(:,:,jk,jl), npb, q_s_1d     (1:nbpb,jk), jpi, jpj)
             END DO
             DO jk = 1, nlay_i
-               CALL tab_1d_2d( nbpb, t_i(:,:,jk,jl), npb, t_i_b     (1:nbpb,jk), jpi, jpj)
-               CALL tab_1d_2d( nbpb, e_i(:,:,jk,jl), npb, q_i_b     (1:nbpb,jk), jpi, jpj)
-               CALL tab_1d_2d( nbpb, s_i(:,:,jk,jl), npb, s_i_b     (1:nbpb,jk), jpi, jpj)
-            END DO
-               CALL tab_1d_2d( nbpb, fstric        , npb, fstbif_1d (1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, qldif         , npb, qldif_1d  (1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, qfvbq         , npb, qfvbq_1d  (1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, rdm_ice       , npb, rdm_ice_1d(1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, rdm_snw       , npb, rdm_snw_1d(1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, dmgwi         , npb, dmgwi_1d  (1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, rdvosif       , npb, dvsbq_1d  (1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, rdvobif       , npb, dvbbq_1d  (1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, fdvolif       , npb, dvlbq_1d  (1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, rdvonif       , npb, dvnbq_1d  (1:nbpb)   , jpi, jpj ) 
-               CALL tab_1d_2d( nbpb, sfx_thd       , npb, sfx_thd_1d(1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, t_i(:,:,jk,jl), npb, t_i_1d     (1:nbpb,jk), jpi, jpj)
+               CALL tab_1d_2d( nbpb, e_i(:,:,jk,jl), npb, q_i_1d     (1:nbpb,jk), jpi, jpj)
+               CALL tab_1d_2d( nbpb, s_i(:,:,jk,jl), npb, s_i_1d     (1:nbpb,jk), jpi, jpj)
+            END DO
+               CALL tab_1d_2d( nbpb, qlead         , npb, qlead_1d  (1:nbpb)   , jpi, jpj )
+
+               CALL tab_1d_2d( nbpb, wfx_snw       , npb, wfx_snw_1d(1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, wfx_sub       , npb, wfx_sub_1d(1:nbpb)   , jpi, jpj )
+
+               CALL tab_1d_2d( nbpb, wfx_bog       , npb, wfx_bog_1d(1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, wfx_bom       , npb, wfx_bom_1d(1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, wfx_sum       , npb, wfx_sum_1d(1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, wfx_sni       , npb, wfx_sni_1d(1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, wfx_res       , npb, wfx_res_1d(1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, wfx_spr       , npb, wfx_spr_1d(1:nbpb)   , jpi, jpj )
+
+               CALL tab_1d_2d( nbpb, sfx_bog       , npb, sfx_bog_1d(1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, sfx_bom       , npb, sfx_bom_1d(1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, sfx_sum       , npb, sfx_sum_1d(1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, sfx_sni       , npb, sfx_sni_1d(1:nbpb)   , jpi, jpj )
+               CALL tab_1d_2d( nbpb, sfx_res       , npb, sfx_res_1d(1:nbpb)   , jpi, jpj )
             !
             IF( num_sal == 2 ) THEN
                CALL tab_1d_2d( nbpb, sfx_bri       , npb, sfx_bri_1d(1:nbpb)   , jpi, jpj )
-               CALL tab_1d_2d( nbpb, fhbri         , npb, fhbri_1d  (1:nbpb)   , jpi, jpj )
             ENDIF
+
+              CALL tab_1d_2d( nbpb, hfx_thd       , npb, hfx_thd_1d(1:nbpb)   , jpi, jpj )
+              CALL tab_1d_2d( nbpb, hfx_spr       , npb, hfx_spr_1d(1:nbpb)   , jpi, jpj )
+              CALL tab_1d_2d( nbpb, hfx_sum       , npb, hfx_sum_1d(1:nbpb)   , jpi, jpj )
+              CALL tab_1d_2d( nbpb, hfx_bom       , npb, hfx_bom_1d(1:nbpb)   , jpi, jpj )
+              CALL tab_1d_2d( nbpb, hfx_bog       , npb, hfx_bog_1d(1:nbpb)   , jpi, jpj )
+              CALL tab_1d_2d( nbpb, hfx_dif       , npb, hfx_dif_1d(1:nbpb)   , jpi, jpj )
+              CALL tab_1d_2d( nbpb, hfx_opw       , npb, hfx_opw_1d(1:nbpb)   , jpi, jpj )
+              CALL tab_1d_2d( nbpb, hfx_snw       , npb, hfx_snw_1d(1:nbpb)   , jpi, jpj )
+              CALL tab_1d_2d( nbpb, hfx_sub       , npb, hfx_sub_1d(1:nbpb)   , jpi, jpj )
+              CALL tab_1d_2d( nbpb, hfx_err       , npb, hfx_err_1d(1:nbpb)   , jpi, jpj )
+              CALL tab_1d_2d( nbpb, hfx_res       , npb, hfx_res_1d(1:nbpb)   , jpi, jpj )
+              CALL tab_1d_2d( nbpb, hfx_err_rem   , npb, hfx_err_rem_1d(1:nbpb)   , jpi, jpj )
             !
             !+++++       temporary stuff for a dummy version
-            CALL tab_1d_2d( nbpb, dh_i_surf2D, npb, dh_i_surf(1:nbpb)      , jpi, jpj )
-            CALL tab_1d_2d( nbpb, dh_i_bott2D, npb, dh_i_bott(1:nbpb)      , jpi, jpj )
-            CALL tab_1d_2d( nbpb, fsup2D     , npb, fsup     (1:nbpb)      , jpi, jpj )
-            CALL tab_1d_2d( nbpb, focea2D    , npb, focea    (1:nbpb)      , jpi, jpj )
-            CALL tab_1d_2d( nbpb, s_i_newice , npb, s_i_new  (1:nbpb)      , jpi, jpj )
-            CALL tab_1d_2d( nbpb, izero(:,:,jl) , npb, i0    (1:nbpb)      , jpi, jpj )
-            CALL tab_1d_2d( nbpb, qns_ice(:,:,jl), npb, qnsr_ice_1d(1:nbpb), jpi, jpj)
+              CALL tab_1d_2d( nbpb, dh_i_surf2D, npb, dh_i_surf(1:nbpb)      , jpi, jpj )
+              CALL tab_1d_2d( nbpb, dh_i_bott2D, npb, dh_i_bott(1:nbpb)      , jpi, jpj )
+              CALL tab_1d_2d( nbpb, s_i_newice , npb, s_i_new  (1:nbpb)      , jpi, jpj )
+              CALL tab_1d_2d( nbpb, izero(:,:,jl) , npb, i0    (1:nbpb)      , jpi, jpj )
             !+++++
+              CALL tab_1d_2d( nbpb, qns_ice(:,:,jl), npb, qns_ice_1d(1:nbpb) , jpi, jpj)
+              CALL tab_1d_2d( nbpb, ftr_ice(:,:,jl), npb, ftr_ice_1d(1:nbpb) , jpi, jpj )
             !
             IF( lk_mpp )   CALL mpp_comm_free( ncomm_ice ) !RB necessary ??
@@ -384,9 +428,8 @@
       ! 5.1) Ice heat content              
       !------------------------
-      ! Enthalpies are global variables we have to readjust the units (heat content in 10^9 Joules)
-      zcoef = 1._wp / ( unit_fac * REAL( nlay_i ) )
+      ! Enthalpies are global variables we have to readjust the units (heat content in Joules)
       DO jl = 1, jpl
          DO jk = 1, nlay_i
-            e_i(:,:,jk,jl) = e_i(:,:,jk,jl) * area(:,:) * a_i(:,:,jl) * ht_i(:,:,jl) * zcoef
+            e_i(:,:,jk,jl) = e_i(:,:,jk,jl) * area(:,:) * a_i(:,:,jl) * ht_i(:,:,jl) / ( unit_fac * REAL( nlay_i ) )
          END DO
       END DO
@@ -395,9 +438,8 @@
       ! 5.2) Snow heat content              
       !------------------------
-      ! Enthalpies are global variables we have to readjust the units (heat content in 10^9 Joules)
-      zcoef = 1._wp / ( unit_fac * REAL( nlay_s ) )
+      ! Enthalpies are global variables we have to readjust the units (heat content in Joules)
       DO jl = 1, jpl
          DO jk = 1, nlay_s
-            e_s(:,:,jk,jl) = e_s(:,:,jk,jl) * area(:,:) * a_i(:,:,jl) * ht_s(:,:,jl) * zcoef
+            e_s(:,:,jk,jl) = e_s(:,:,jk,jl) * area(:,:) * a_i(:,:,jl) * ht_s(:,:,jl) / ( unit_fac * REAL( nlay_s ) )
          END DO
       END DO
@@ -411,9 +453,4 @@
       ! 5.4) Diagnostic thermodynamic growth rates
       !--------------------------------------------
-!clem@useless      d_v_i_thd(:,:,:) = v_i      (:,:,:) - old_v_i(:,:,:)    ! ice volumes 
-!clem@mv-to-itd    dv_dt_thd(:,:,:) = d_v_i_thd(:,:,:) * r1_rdtice * rday
-
-      IF( con_i .AND. jiindex_1d > 0 )   fbif(:,:) = fbif(:,:) + zqlbsbq(:,:)
-
       IF(ln_ctl) THEN            ! Control print
          CALL prt_ctl_info(' ')
@@ -448,334 +485,15 @@
       ENDIF
       !
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_fs  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) * r1_rdtice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) * r1_rdtice + ( zchk_fs / rhoic )
-
-         zchk_vmin = glob_min(v_i)
-         zchk_amax = glob_max(SUM(a_i,dim=3))
-         zchk_amin = glob_min(a_i)
-       
-         IF(lwp) THEN
-            IF ( ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limthd) = ',(zchk_v_i * rday)
-            IF ( ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limthd) = ',(zchk_smv * rday)
-            IF ( zchk_vmin <  0.            ) WRITE(numout,*) 'violation v_i<0  [mm]         (limthd) = ',(zchk_vmin * 1.e-3)
-            IF ( zchk_amax >  amax+epsi10   ) WRITE(numout,*) 'violation a_i>amax            (limthd) = ',zchk_amax
-            IF ( zchk_amin <  0.            ) WRITE(numout,*) 'violation a_i<0               (limthd) = ',zchk_amin
-         ENDIF
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-      !
-      CALL wrk_dealloc( jpi, jpj, zqlbsbq )
+      ! conservation test
+      IF( ln_limdiahsb ) CALL lim_cons_hsm(1, 'limthd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
       !
       IF( nn_timing == 1 )  CALL timing_stop('limthd')
-   END SUBROUTINE lim_thd
-
-
-   SUBROUTINE lim_thd_glohec( eti, ets, etilayer, kideb, kiut, jl )
+   END SUBROUTINE lim_thd 
+
+   SUBROUTINE lim_thd_temp( kideb, kiut )
       !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_glohec *** 
+      !!                   ***  ROUTINE lim_thd_temp *** 
       !!                 
-      !! ** Purpose :  Compute total heat content for each category
-      !!               Works with 1d vectors only
-      !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                         ::   kideb, kiut   ! bounds for the spatial loop
-      INTEGER , INTENT(in   )                         ::   jl            ! category number
-      REAL(wp), INTENT(  out), DIMENSION (jpij,jpl  ) ::   eti, ets      ! vertically-summed heat content for ice & snow
-      REAL(wp), INTENT(  out), DIMENSION (jpij,jkmax) ::   etilayer      ! heat content for ice layers
-      !!
-      INTEGER  ::   ji,jk   ! loop indices
-      !!-----------------------------------------------------------------------
-      eti(:,:) = 0._wp
-      ets(:,:) = 0._wp
-      !
-      DO jk = 1, nlay_i                ! total q over all layers, ice [J.m-2]
-         DO ji = kideb, kiut
-            etilayer(ji,jk) = q_i_b(ji,jk) * ht_i_b(ji) / REAL( nlay_i )
-            eti     (ji,jl) = eti(ji,jl) + etilayer(ji,jk) 
-         END DO
-      END DO
-      DO ji = kideb, kiut              ! total q over all layers, snow [J.m-2]
-         ets(ji,jl) = ets(ji,jl) + q_s_b(ji,1) * ht_s_b(ji) / REAL( nlay_s )
-      END DO
-      !
-      WRITE(numout,*) ' lim_thd_glohec '
-      WRITE(numout,*) ' qt_i_in : ', eti(jiindex_1d,jl) * r1_rdtice
-      WRITE(numout,*) ' qt_s_in : ', ets(jiindex_1d,jl) * r1_rdtice
-      WRITE(numout,*) ' qt_in   : ', ( eti(jiindex_1d,jl) + ets(jiindex_1d,jl) ) * r1_rdtice
-      !
-   END SUBROUTINE lim_thd_glohec
-
-
-   SUBROUTINE lim_thd_con_dif( kideb, kiut, jl )
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_con_dif *** 
-      !!                 
-      !! ** Purpose :   Test energy conservation after heat diffusion
-      !!-------------------------------------------------------------------
-      INTEGER , INTENT(in   ) ::   kideb, kiut   ! bounds for the spatial loop
-      INTEGER , INTENT(in   ) ::   jl            ! category number
-
-      INTEGER  ::   ji, jk         ! loop indices
-      INTEGER  ::   ii, ij
-      INTEGER  ::   numce          ! number of points for which conservation is violated
-      REAL(wp) ::   meance         ! mean conservation error
-      REAL(wp) ::   max_cons_err, max_surf_err
-      !!---------------------------------------------------------------------
-
-      max_cons_err =  1.0_wp          ! maximum tolerated conservation error
-      max_surf_err =  0.001_wp        ! maximum tolerated surface error
-
-      !--------------------------
-      ! Increment of energy
-      !--------------------------
-      ! global
-      DO ji = kideb, kiut
-         dq_i(ji,jl) = qt_i_fin(ji,jl) - qt_i_in(ji,jl) + qt_s_fin(ji,jl) - qt_s_in(ji,jl)
-      END DO
-      ! layer by layer
-      dq_i_layer(:,:) = q_i_layer_fin(:,:) - q_i_layer_in(:,:)
-
-      !----------------------------------------
-      ! Atmospheric heat flux, ice heat budget
-      !----------------------------------------
-      DO ji = kideb, kiut
-         ii = MOD( npb(ji) - 1 , jpi ) + 1
-         ij =    ( npb(ji) - 1 ) / jpi + 1
-         fatm     (ji,jl) = qnsr_ice_1d(ji) + ( 1._wp - i0(ji) ) * qsr_ice_1d(ji)
-         sum_fluxq(ji,jl) = fc_su(ji) - fc_bo_i(ji) + qsr_ice_1d(ji) * i0(ji) - fstroc(ii,ij,jl)
-      END DO
-
-      !--------------------
-      ! Conservation error
-      !--------------------
-      DO ji = kideb, kiut
-         cons_error(ji,jl) = ABS( dq_i(ji,jl) * r1_rdtice + sum_fluxq(ji,jl) )
-      END DO
-
-      numce  = 0
-      meance = 0._wp
-      DO ji = kideb, kiut
-         IF ( cons_error(ji,jl) .GT. max_cons_err ) THEN
-            numce = numce + 1
-            meance = meance + cons_error(ji,jl)
-         ENDIF
-      END DO
-      IF( numce > 0 )   meance = meance / numce
-
-      WRITE(numout,*) ' Maximum tolerated conservation error : ', max_cons_err
-      WRITE(numout,*) ' After lim_thd_dif, category : ', jl
-      WRITE(numout,*) ' Mean conservation error on big error points ', meance, numit
-      WRITE(numout,*) ' Number of points where there is a cons err gt than c.e. : ', numce, numit
-
-      !-------------------------------------------------------
-      ! Surface error due to imbalance between Fatm and Fcsu
-      !-------------------------------------------------------
-      numce  = 0
-      meance = 0._wp
-
-      DO ji = kideb, kiut
-         surf_error(ji,jl) = ABS ( fatm(ji,jl) - fc_su(ji) )
-         IF( ( t_su_b(ji) .LT. rtt ) .AND. ( surf_error(ji,jl) .GT. max_surf_err ) ) THEN
-            numce = numce + 1 
-            meance = meance + surf_error(ji,jl)
-         ENDIF
-      ENDDO
-      IF( numce > 0 )   meance = meance / numce
-
-      WRITE(numout,*) ' Maximum tolerated surface error : ', max_surf_err
-      WRITE(numout,*) ' After lim_thd_dif, category : ', jl
-      WRITE(numout,*) ' Mean surface error on big error points ', meance, numit
-      WRITE(numout,*) ' Number of points where there is a surf err gt than surf_err : ', numce, numit
-
-      WRITE(numout,*) ' fc_su      : ', fc_su(jiindex_1d)
-      WRITE(numout,*) ' fatm       : ', fatm(jiindex_1d,jl)
-      WRITE(numout,*) ' t_su       : ', t_su_b(jiindex_1d)
-
-      !---------------------------------------
-      ! Write ice state in case of big errors
-      !---------------------------------------
-      DO ji = kideb, kiut
-         IF ( ( ( t_su_b(ji) .LT. rtt ) .AND. ( surf_error(ji,jl) .GT. max_surf_err ) ) .OR. &
-            ( cons_error(ji,jl) .GT. max_cons_err  ) ) THEN
-            ii                 = MOD( npb(ji) - 1, jpi ) + 1
-            ij                 = ( npb(ji) - 1 ) / jpi + 1
-            !
-            WRITE(numout,*) ' alerte 1     '
-            WRITE(numout,*) ' Untolerated conservation / surface error after '
-            WRITE(numout,*) ' heat diffusion in the ice '
-            WRITE(numout,*) ' Category   : ', jl
-            WRITE(numout,*) ' ii , ij  : ', ii, ij
-            WRITE(numout,*) ' lat, lon   : ', gphit(ii,ij), glamt(ii,ij)
-            WRITE(numout,*) ' cons_error : ', cons_error(ji,jl)
-            WRITE(numout,*) ' surf_error : ', surf_error(ji,jl)
-            WRITE(numout,*) ' dq_i       : ', - dq_i(ji,jl) * r1_rdtice
-            WRITE(numout,*) ' Fdt        : ', sum_fluxq(ji,jl)
-            WRITE(numout,*)
-            !        WRITE(numout,*) ' qt_i_in   : ', qt_i_in(ji,jl)
-            !        WRITE(numout,*) ' qt_s_in   : ', qt_s_in(ji,jl)
-            !        WRITE(numout,*) ' qt_i_fin  : ', qt_i_fin(ji,jl)
-            !        WRITE(numout,*) ' qt_s_fin  : ', qt_s_fin(ji,jl)
-            !        WRITE(numout,*) ' qt        : ', qt_i_fin(ji,jl) + qt_s_fin(ji,jl)
-            WRITE(numout,*) ' ht_i       : ', ht_i_b(ji)
-            WRITE(numout,*) ' ht_s       : ', ht_s_b(ji)
-            WRITE(numout,*) ' t_su       : ', t_su_b(ji)
-            WRITE(numout,*) ' t_s        : ', t_s_b(ji,1)
-            WRITE(numout,*) ' t_i        : ', t_i_b(ji,1:nlay_i)
-            WRITE(numout,*) ' t_bo       : ', t_bo_b(ji)
-            WRITE(numout,*) ' q_i        : ', q_i_b(ji,1:nlay_i)
-            WRITE(numout,*) ' s_i        : ', s_i_b(ji,1:nlay_i)
-            WRITE(numout,*) ' tmelts     : ', rtt - tmut*s_i_b(ji,1:nlay_i)
-            WRITE(numout,*)
-            WRITE(numout,*) ' Fluxes '
-            WRITE(numout,*) ' ~~~~~~ '
-            WRITE(numout,*) ' fatm       : ', fatm(ji,jl)
-            WRITE(numout,*) ' fc_su      : ', fc_su    (ji)
-            WRITE(numout,*) ' fstr_inice : ', qsr_ice_1d(ji)*i0(ji)
-            WRITE(numout,*) ' fc_bo      : ', - fc_bo_i  (ji)
-            WRITE(numout,*) ' foc        : ', fbif_1d(ji)
-            WRITE(numout,*) ' fstroc     : ', fstroc   (ii,ij,jl)
-            WRITE(numout,*) ' i0         : ', i0(ji)
-            WRITE(numout,*) ' qsr_ice    : ', (1.0-i0(ji))*qsr_ice_1d(ji)
-            WRITE(numout,*) ' qns_ice    : ', qnsr_ice_1d(ji)
-            WRITE(numout,*) ' Conduction fluxes : '
-            WRITE(numout,*) ' fc_s      : ', fc_s(ji,0:nlay_s)
-            WRITE(numout,*) ' fc_i      : ', fc_i(ji,0:nlay_i)
-            WRITE(numout,*)
-            WRITE(numout,*) ' Layer by layer ... '
-            WRITE(numout,*) ' dq_snow : ', ( qt_s_fin(ji,jl) - qt_s_in(ji,jl) ) * r1_rdtice
-            WRITE(numout,*) ' dfc_snow  : ', fc_s(ji,1) - fc_s(ji,0)
-            DO jk = 1, nlay_i
-               WRITE(numout,*) ' layer  : ', jk
-               WRITE(numout,*) ' dq_ice : ', dq_i_layer(ji,jk) * r1_rdtice  
-               WRITE(numout,*) ' radab  : ', radab(ji,jk)
-               WRITE(numout,*) ' dfc_i  : ', fc_i(ji,jk) - fc_i(ji,jk-1)
-               WRITE(numout,*) ' tot f  : ', fc_i(ji,jk) - fc_i(ji,jk-1) - radab(ji,jk)
-            END DO
-
-         ENDIF
-         !
-      END DO
-      !
-   END SUBROUTINE lim_thd_con_dif
-
-
-   SUBROUTINE lim_thd_con_dh( kideb, kiut, jl )
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_con_dh  *** 
-      !!                 
-      !! ** Purpose :   Test energy conservation after enthalpy redistr.
-      !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kideb, kiut   ! bounds for the spatial loop
-      INTEGER, INTENT(in) ::   jl            ! category number
-      !
-      INTEGER  ::   ji                ! loop indices
-      INTEGER  ::   ii, ij, numce         ! local integers
-      REAL(wp) ::   meance, max_cons_err    !local scalar
-      !!---------------------------------------------------------------------
-
-      max_cons_err = 1._wp
-
-      !--------------------------
-      ! Increment of energy
-      !--------------------------
-      DO ji = kideb, kiut
-         dq_i(ji,jl) = qt_i_fin(ji,jl) - qt_i_in(ji,jl) + qt_s_fin(ji,jl) - qt_s_in(ji,jl)   ! global
-      END DO
-      dq_i_layer(:,:)    = q_i_layer_fin(:,:) - q_i_layer_in(:,:)                            ! layer by layer
-
-      !----------------------------------------
-      ! Atmospheric heat flux, ice heat budget
-      !----------------------------------------
-      DO ji = kideb, kiut
-         ii = MOD( npb(ji) - 1 , jpi ) + 1
-         ij =    ( npb(ji) - 1 ) / jpi + 1
-
-         fatm      (ji,jl) = qnsr_ice_1d(ji) + qsr_ice_1d(ji)                       ! total heat flux
-         sum_fluxq (ji,jl) = fatm(ji,jl) + fbif_1d(ji) - ftotal_fin(ji) - fstroc(ii,ij,jl) 
-         cons_error(ji,jl) = ABS( dq_i(ji,jl) * r1_rdtice + sum_fluxq(ji,jl) )
-      END DO
-
-      !--------------------
-      ! Conservation error
-      !--------------------
-      DO ji = kideb, kiut
-         cons_error(ji,jl) = ABS( dq_i(ji,jl) * r1_rdtice + sum_fluxq(ji,jl) )
-      END DO
-
-      numce = 0
-      meance = 0._wp
-      DO ji = kideb, kiut
-         IF( cons_error(ji,jl) .GT. max_cons_err ) THEN
-            numce = numce + 1
-            meance = meance + cons_error(ji,jl)
-         ENDIF
-      ENDDO
-      IF(numce > 0 ) meance = meance / numce
-
-      WRITE(numout,*) ' Error report - Category : ', jl
-      WRITE(numout,*) ' ~~~~~~~~~~~~ '
-      WRITE(numout,*) ' Maximum tolerated conservation error : ', max_cons_err
-      WRITE(numout,*) ' After lim_thd_ent, category : ', jl
-      WRITE(numout,*) ' Mean conservation error on big error points ', meance, numit
-      WRITE(numout,*) ' Number of points where there is a cons err gt than 0.1 W/m2 : ', numce, numit
-
-      !---------------------------------------
-      ! Write ice state in case of big errors
-      !---------------------------------------
-      DO ji = kideb, kiut
-         IF ( cons_error(ji,jl) .GT. max_cons_err  ) THEN
-            ii = MOD( npb(ji) - 1, jpi ) + 1
-            ij =    ( npb(ji) - 1 ) / jpi + 1
-            !
-            WRITE(numout,*) ' alerte 1 - category : ', jl
-            WRITE(numout,*) ' Untolerated conservation error after limthd_ent '
-            WRITE(numout,*) ' ii , ij  : ', ii, ij
-            WRITE(numout,*) ' lat, lon   : ', gphit(ii,ij), glamt(ii,ij)
-            WRITE(numout,*) ' * '
-            WRITE(numout,*) ' Ftotal     : ', sum_fluxq(ji,jl)
-            WRITE(numout,*) ' dq_t       : ', - dq_i(ji,jl) * r1_rdtice
-            WRITE(numout,*) ' dq_i       : ', - ( qt_i_fin(ji,jl) - qt_i_in(ji,jl) ) * r1_rdtice
-            WRITE(numout,*) ' dq_s       : ', - ( qt_s_fin(ji,jl) - qt_s_in(ji,jl) ) * r1_rdtice
-            WRITE(numout,*) ' cons_error : ', cons_error(ji,jl)
-            WRITE(numout,*) ' * '
-            WRITE(numout,*) ' Fluxes        --- : '
-            WRITE(numout,*) ' fatm       : ', fatm(ji,jl)
-            WRITE(numout,*) ' foce       : ', fbif_1d(ji)
-            WRITE(numout,*) ' fres       : ', ftotal_fin(ji)
-            WRITE(numout,*) ' fhbri      : ', fhbricat(ii,ij,jl)
-            WRITE(numout,*) ' * '
-            WRITE(numout,*) ' Heat contents --- : '
-            WRITE(numout,*) ' qt_s_in    : ', qt_s_in(ji,jl) * r1_rdtice
-            WRITE(numout,*) ' qt_i_in    : ', qt_i_in(ji,jl) * r1_rdtice
-            WRITE(numout,*) ' qt_in      : ', ( qt_i_in(ji,jl) + qt_s_in(ji,jl) ) * r1_rdtice
-            WRITE(numout,*) ' qt_s_fin   : ', qt_s_fin(ji,jl) * r1_rdtice
-            WRITE(numout,*) ' qt_i_fin   : ', qt_i_fin(ji,jl) * r1_rdtice
-            WRITE(numout,*) ' qt_fin     : ', ( qt_i_fin(ji,jl) + qt_s_fin(ji,jl) ) * r1_rdtice
-            WRITE(numout,*) ' * '
-            WRITE(numout,*) ' Ice variables --- : '
-            WRITE(numout,*) ' ht_i       : ', ht_i_b(ji)
-            WRITE(numout,*) ' ht_s       : ', ht_s_b(ji)
-            WRITE(numout,*) ' dh_s_tot  : ', dh_s_tot(ji)
-            WRITE(numout,*) ' dh_snowice: ', dh_snowice(ji)
-            WRITE(numout,*) ' dh_i_surf : ', dh_i_surf(ji)
-            WRITE(numout,*) ' dh_i_bott : ', dh_i_bott(ji)
-         ENDIF
-         !
-      END DO
-      !
-   END SUBROUTINE lim_thd_con_dh
-
-
-   SUBROUTINE lim_thd_enmelt( kideb, kiut )
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_enmelt *** 
-      !!                 
-      !! ** Purpose :   Computes sea ice energy of melting q_i (J.m-3)
+      !! ** Purpose :   Computes sea ice temperature (Kelvin) from enthalpy
       !!
       !! ** Method  :   Formula (Bitz and Lipscomb, 1999)
@@ -784,23 +502,24 @@
       !!
       INTEGER  ::   ji, jk   ! dummy loop indices
-      REAL(wp) ::   ztmelts  ! local scalar 
+      REAL(wp) ::   ztmelts, zswitch, zaaa, zbbb, zccc, zdiscrim  ! local scalar 
       !!-------------------------------------------------------------------
-      !
-      DO jk = 1, nlay_i             ! Sea ice energy of melting
+      ! Recover ice temperature
+      DO jk = 1, nlay_i
          DO ji = kideb, kiut
-            ztmelts      =  - tmut  * s_i_b(ji,jk) + rtt 
-            q_i_b(ji,jk) =    rhoic * ( cpic * ( ztmelts - t_i_b(ji,jk) )                                 &
-               &                      + lfus * ( 1.0 - (ztmelts-rtt) / MIN( t_i_b(ji,jk)-rtt, -epsi10 ) )   &
-               &                      - rcp  * ( ztmelts-rtt  )  ) 
-         END DO
-      END DO
-      DO jk = 1, nlay_s             ! Snow energy of melting
-         DO ji = kideb, kiut
-            q_s_b(ji,jk) = rhosn * ( cpic * ( rtt - t_s_b(ji,jk) ) + lfus )
-         END DO
-      END DO
-      !
-   END SUBROUTINE lim_thd_enmelt
-
+            ztmelts       =  -tmut * s_i_1d(ji,jk) + rtt
+            ! Conversion q(S,T) -> T (second order equation)
+            zaaa          =  cpic
+            zbbb          =  ( rcp - cpic ) * ( ztmelts - rtt ) + q_i_1d(ji,jk) / rhoic - lfus
+            zccc          =  lfus * ( ztmelts - rtt )
+            zdiscrim      =  SQRT( MAX( zbbb * zbbb - 4._wp * zaaa * zccc, 0._wp ) )
+            t_i_1d(ji,jk)  =  rtt - ( zbbb + zdiscrim ) / ( 2._wp * zaaa )
+            
+            ! mask temperature
+            zswitch      =  1._wp - MAX( 0._wp , SIGN( 1._wp , - ht_i_1d(ji) ) ) 
+            t_i_1d(ji,jk) =  zswitch * t_i_1d(ji,jk) + ( 1._wp - zswitch ) * rtt
+         END DO 
+      END DO 
+
+   END SUBROUTINE lim_thd_temp
 
    SUBROUTINE lim_thd_init
@@ -818,7 +537,5 @@
       INTEGER  ::   ios                 ! Local integer output status for namelist read
       NAMELIST/namicethd/ hmelt , hiccrit, fraz_swi, maxfrazb, vfrazb, Cfrazb,   &
-         &                hicmin, hiclim,                                        &
-         &                sbeta  , parlat, hakspl, hibspl, exld,                 &
-         &                hakdif, hnzst  , thth  , parsub, alphs, betas,         & 
+         &                hiclim, hnzst, parsub, betas,                          & 
          &                kappa_i, nconv_i_thd, maxer_i_thd, thcon_i_swi
       !!-------------------------------------------------------------------
@@ -843,22 +560,13 @@
          WRITE(numout,*)'   Namelist of ice parameters for ice thermodynamic computation '
          WRITE(numout,*)'      maximum melting at the bottom                           hmelt        = ', hmelt
-         WRITE(numout,*)'      ice thick. for lateral accretion in NH (SH)             hiccrit(1/2) = ', hiccrit
+         WRITE(numout,*)'      ice thick. for lateral accretion                        hiccrit      = ', hiccrit
          WRITE(numout,*)'      Frazil ice thickness as a function of wind or not       fraz_swi     = ', fraz_swi
          WRITE(numout,*)'      Maximum proportion of frazil ice collecting at bottom   maxfrazb     = ', maxfrazb
          WRITE(numout,*)'      Thresold relative drift speed for collection of frazil  vfrazb       = ', vfrazb
          WRITE(numout,*)'      Squeezing coefficient for collection of frazil          Cfrazb       = ', Cfrazb
-         WRITE(numout,*)'      ice thick. corr. to max. energy stored in brine pocket  hicmin       = ', hicmin  
          WRITE(numout,*)'      minimum ice thickness                                   hiclim       = ', hiclim 
          WRITE(numout,*)'      numerical carac. of the scheme for diffusion in ice '
-         WRITE(numout,*)'      Cranck-Nicholson (=0.5), implicit (=1), explicit (=0)   sbeta        = ', sbeta
-         WRITE(numout,*)'      percentage of energy used for lateral ablation          parlat       = ', parlat
-         WRITE(numout,*)'      slope of distr. for Hakkinen-Mellor lateral melting     hakspl       = ', hakspl  
-         WRITE(numout,*)'      slope of distribution for Hibler lateral melting        hibspl       = ', hibspl
-         WRITE(numout,*)'      exponent for leads-closure rate                         exld         = ', exld
-         WRITE(numout,*)'      coefficient for diffusions of ice and snow              hakdif       = ', hakdif
-         WRITE(numout,*)'      threshold thick. for comp. of eq. thermal conductivity  zhth         = ', thth 
          WRITE(numout,*)'      thickness of the surf. layer in temp. computation       hnzst        = ', hnzst
          WRITE(numout,*)'      switch for snow sublimation  (=1) or not (=0)           parsub       = ', parsub  
-         WRITE(numout,*)'      coefficient for snow density when snow ice formation    alphs        = ', alphs
          WRITE(numout,*)'      coefficient for ice-lead partition of snowfall          betas        = ', betas
          WRITE(numout,*)'      extinction radiation parameter in sea ice (1.0)         kappa_i      = ', kappa_i
@@ -866,8 +574,6 @@
          WRITE(numout,*)'      maximal err. on T for heat diffusion computation        maxer_i_thd  = ', maxer_i_thd
          WRITE(numout,*)'      switch for comp. of thermal conductivity in the ice     thcon_i_swi  = ', thcon_i_swi
+         WRITE(numout,*)'      check heat conservation in the ice/snow                 con_i        = ', con_i
       ENDIF
-      !
-      rcdsn = hakdif * rcdsn 
-      rcdic = hakdif * rcdic
       !
    END SUBROUTINE lim_thd_init
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 4921)
@@ -6,5 +6,5 @@
    !! History :  LIM  ! 2003-05 (M. Vancoppenolle) Original code in 1D
    !!                 ! 2005-06 (M. Vancoppenolle) 3D version 
-   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in rdm_snw & rdm_ice
+   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in wfx_snw & wfx_ice
    !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
    !!            3.5  ! 2012-10 (G. Madec & co) salt flux + bug fixes 
@@ -26,5 +26,6 @@
    USE wrk_nemo       ! work arrays
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
+   USE cpl_oasis3, ONLY : lk_cpl
+   
    IMPLICIT NONE
    PRIVATE
@@ -34,7 +35,4 @@
    REAL(wp) ::   epsi20 = 1.e-20   ! constant values
    REAL(wp) ::   epsi10 = 1.e-10   !
-   REAL(wp) ::   epsi13 = 1.e-13   !
-   REAL(wp) ::   zzero  = 0._wp    !
-   REAL(wp) ::   zone   = 1._wp    !
 
    !!----------------------------------------------------------------------
@@ -45,5 +43,5 @@
 CONTAINS
 
-   SUBROUTINE lim_thd_dh( kideb, kiut, jl )
+   SUBROUTINE lim_thd_dh( kideb, kiut )
       !!------------------------------------------------------------------
       !!                ***  ROUTINE lim_thd_dh  ***
@@ -70,36 +68,35 @@
       !!------------------------------------------------------------------
       INTEGER , INTENT(in) ::   kideb, kiut   ! Start/End point on which the  the computation is applied
-      INTEGER , INTENT(in) ::   jl            ! Thickness cateogry number
       !! 
       INTEGER  ::   ji , jk        ! dummy loop indices
       INTEGER  ::   ii, ij         ! 2D corresponding indices to ji
-      INTEGER  ::   isnow          ! switch for presence (1) or absence (0) of snow
-      INTEGER  ::   isnowic        ! snow ice formation not
-      INTEGER  ::   i_ice_switch   ! ice thickness above a certain treshold or not
       INTEGER  ::   iter
 
-      REAL(wp) ::   zzfmass_i, zihgnew                     ! local scalar
-      REAL(wp) ::   zzfmass_s, zhsnew, ztmelts             ! local scalar
-      REAL(wp) ::   zhn, zdhcf, zdhbf, zhni, zhnfi, zihg   !
-      REAL(wp) ::   zdhnm, zhnnew, zhisn, zihic, zzc       !
+      REAL(wp) ::   ztmelts             ! local scalar
+      REAL(wp) ::   zdh, zfdum  !
       REAL(wp) ::   zfracs       ! fractionation coefficient for bottom salt entrapment
       REAL(wp) ::   zcoeff       ! dummy argument for snowfall partitioning over ice and leads
-      REAL(wp) ::   zsm_snowice  ! snow-ice salinity
+      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
       REAL(wp) ::   zswi2        ! switch for computation of bottom salinity
       REAL(wp) ::   zgrr         ! bottom growth rate
-      REAL(wp) ::   ztform       ! bottom formation temperature
-      !
-      REAL(wp), POINTER, DIMENSION(:) ::   zh_i        ! ice layer thickness
+      REAL(wp) ::   zt_i_new     ! bottom formation temperature
+
+      REAL(wp) ::   zQm          ! enthalpy exchanged with the ocean (J/m2), >0 towards the ocean
+      REAL(wp) ::   zEi          ! specific enthalpy of sea ice (J/kg)
+      REAL(wp) ::   zEw          ! specific enthalpy of exchanged water (J/kg)
+      REAL(wp) ::   zdE          ! specific enthalpy difference (J/kg)
+      REAL(wp) ::   zfmdt        ! exchange mass flux x time step (J/m2), >0 towards the ocean
+      REAL(wp) ::   zsstK        ! SST in Kelvin
+
       REAL(wp), POINTER, DIMENSION(:) ::   zh_s        ! snow layer thickness
-      REAL(wp), POINTER, DIMENSION(:) ::   ztfs        ! melting point
-      REAL(wp), POINTER, DIMENSION(:) ::   zhsold      ! old snow thickness
-      REAL(wp), POINTER, DIMENSION(:) ::   zqprec      ! energy of fallen snow
-      REAL(wp), POINTER, DIMENSION(:) ::   zqfont_su   ! incoming, remaining surface energy
-      REAL(wp), POINTER, DIMENSION(:) ::   zqfont_bo   ! incoming, bottom energy
-      REAL(wp), POINTER, DIMENSION(:) ::   z_f_surf    ! surface heat for ablation
-      REAL(wp), POINTER, DIMENSION(:) ::   zhgnew      ! new ice thickness
-      REAL(wp), POINTER, DIMENSION(:) ::   zfmass_i    ! 
+      REAL(wp), POINTER, DIMENSION(:) ::   zqprec      ! energy of fallen snow                       (J.m-3)
+      REAL(wp), POINTER, DIMENSION(:) ::   zq_su       ! heat for surface ablation                   (J.m-2)
+      REAL(wp), POINTER, DIMENSION(:) ::   zq_bo       ! heat for bottom ablation                    (J.m-2)
+      REAL(wp), POINTER, DIMENSION(:) ::   zq_1cat     ! corrected heat in case 1-cat and hmelt>15cm (J.m-2)
+      REAL(wp), POINTER, DIMENSION(:) ::   zq_rema     ! remaining heat at the end of the routine    (J.m-2)
+      REAL(wp), POINTER, DIMENSION(:) ::   zf_tt     ! Heat budget to determine melting or freezing(W.m-2)
+      INTEGER , POINTER, DIMENSION(:) ::   icount      ! number of layers vanished by melting 
 
       REAL(wp), POINTER, DIMENSION(:) ::   zdh_s_mel   ! snow melt 
@@ -108,87 +105,111 @@
 
       REAL(wp), POINTER, DIMENSION(:,:) ::   zdeltah
-
-      ! Pathological cases
-      REAL(wp), POINTER, DIMENSION(:) ::   zfdt_init   ! total incoming heat for ice melt
-      REAL(wp), POINTER, DIMENSION(:) ::   zfdt_final  ! total remaing heat for ice melt
-      REAL(wp), POINTER, DIMENSION(:) ::   zqt_i       ! total ice heat content
-      REAL(wp), POINTER, DIMENSION(:) ::   zqt_s       ! total snow heat content
-      REAL(wp), POINTER, DIMENSION(:) ::   zqt_dummy   ! dummy heat content
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zqt_i_lay   ! total ice heat content
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zh_i      ! ice layer thickness
+
+      REAL(wp), POINTER, DIMENSION(:) ::   zqh_i       ! total ice heat content  (J.m-2)
+      REAL(wp), POINTER, DIMENSION(:) ::   zqh_s       ! total snow heat content (J.m-2)
+      REAL(wp), POINTER, DIMENSION(:) ::   zq_s        ! total snow enthalpy     (J.m-3)
 
       ! mass and salt flux (clem)
-      REAL(wp) :: zdvres, zdvsur, zdvbot
-      REAL(wp), POINTER, DIMENSION(:) ::   zviold, zvsold   ! old ice volume...
+      REAL(wp) :: zdvres, zswitch_sal, zswitch
 
       ! Heat conservation 
-      INTEGER  ::   num_iter_max, numce_dh
-      REAL(wp) ::   meance_dh
-      REAL(wp) ::   zinda 
-      REAL(wp), POINTER, DIMENSION(:) ::   zinnermelt
-      REAL(wp), POINTER, DIMENSION(:) ::   zfbase, zdq_i
+      INTEGER  ::   num_iter_max
+      REAL(wp) ::   zinda, zindq, zindh 
+      REAL(wp), POINTER, DIMENSION(:) ::   zintermelt   ! debug
+
       !!------------------------------------------------------------------
 
-      CALL wrk_alloc( jpij, zh_i, zh_s, ztfs, zhsold, zqprec, zqfont_su, zqfont_bo, z_f_surf, zhgnew, zfmass_i )
-      CALL wrk_alloc( jpij, zdh_s_mel, zdh_s_pre, zdh_s_sub, zfdt_init, zfdt_final, zqt_i, zqt_s, zqt_dummy )
-      CALL wrk_alloc( jpij, zinnermelt, zfbase, zdq_i )
-      CALL wrk_alloc( jpij, jkmax, zdeltah, zqt_i_lay )
-
-      CALL wrk_alloc( jpij, zviold, zvsold ) ! clem
+      ! Discriminate between varying salinity (num_sal=2) and prescribed cases (other values)
+      SELECT CASE( num_sal )                       ! varying salinity or not
+         CASE( 1, 3, 4 ) ;   zswitch_sal = 0       ! prescribed salinity profile
+         CASE( 2 )       ;   zswitch_sal = 1       ! varying salinity profile
+      END SELECT
+
+      CALL wrk_alloc( jpij, zh_s, zqprec, zq_su, zq_bo, zf_tt, zq_1cat, zq_rema )
+      CALL wrk_alloc( jpij, zdh_s_mel, zdh_s_pre, zdh_s_sub, zqh_i, zqh_s, zq_s )
+      CALL wrk_alloc( jpij, zintermelt )
+      CALL wrk_alloc( jpij, nlay_i+1, zdeltah, zh_i )
+      CALL wrk_alloc( jpij, icount )
       
-      ftotal_fin(:) = 0._wp
-      zfdt_init (:) = 0._wp
-      zfdt_final(:) = 0._wp
-
-      dh_i_surf (:) = 0._wp
-      dh_i_bott (:) = 0._wp
-      dh_snowice(:) = 0._wp
-
-      DO ji = kideb, kiut
-         old_ht_i_b(ji) = ht_i_b(ji)
-         old_ht_s_b(ji) = ht_s_b(ji)
-         zviold(ji) = a_i_b(ji) * ht_i_b(ji) ! clem
-         zvsold(ji) = a_i_b(ji) * ht_s_b(ji) ! clem
-      END DO
+      dh_i_surf  (:) = 0._wp ; dh_i_bott  (:) = 0._wp ; dh_snowice(:) = 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_1cat(:) = 0._wp ; zq_rema(:) = 0._wp
+
+      zh_s     (:) = 0._wp       
+      zdh_s_pre(:) = 0._wp
+      zdh_s_mel(:) = 0._wp
+      zdh_s_sub(:) = 0._wp
+      zqh_s    (:) = 0._wp      
+      zqh_i    (:) = 0._wp   
+
+      zh_i      (:,:) = 0._wp       
+      zdeltah   (:,:) = 0._wp       
+      zintermelt(:)   = 0._wp
+      icount    (:)   = 0
+
+      ! initialize layer thicknesses and enthalpies
+      h_i_old (:,0:nlay_i+1) = 0._wp
+      qh_i_old(:,0:nlay_i+1) = 0._wp
+      DO jk = 1, nlay_i
+         DO ji = kideb, kiut
+            h_i_old (ji,jk) = ht_i_1d(ji) / REAL( nlay_i )
+            qh_i_old(ji,jk) = q_i_1d(ji,jk) * h_i_old(ji,jk)
+         ENDDO
+      ENDDO
       !
       !------------------------------------------------------------------------------!
-      !  1) Calculate available heat for surface ablation                            !
+      !  1) Calculate available heat for surface and bottom ablation                 !
       !------------------------------------------------------------------------------!
       !
       DO ji = kideb, kiut
-         isnow         = INT(  1.0 - MAX(  0.0 , SIGN( 1.0 , - ht_s_b(ji) )  )  )
-         ztfs     (ji) = isnow * rtt + ( 1.0 - isnow ) * rtt
-         z_f_surf (ji) = qnsr_ice_1d(ji) + ( 1.0 - i0(ji) ) * qsr_ice_1d(ji) - fc_su(ji)
-         z_f_surf (ji) = MAX(  zzero , z_f_surf(ji)  ) * MAX(  zzero , SIGN( zone , t_su_b(ji) - ztfs(ji) )  )
-         zfdt_init(ji) = ( z_f_surf(ji) + MAX( fbif_1d(ji) + qlbbq_1d(ji) + fc_bo_i(ji),0.0 ) ) * rdt_ice
-      END DO ! ji
-
-      zqfont_su  (:) = 0._wp
-      zqfont_bo  (:) = 0._wp
-      dsm_i_se_1d(:) = 0._wp     
-      dsm_i_si_1d(:) = 0._wp   
+         zinda         = 1._wp - MAX(  0._wp , SIGN( 1._wp , - ht_s_1d(ji) ) )
+         ztmelts       = zinda * rtt + ( 1._wp - zinda ) * rtt
+
+         zfdum     = qns_ice_1d(ji) + ( 1._wp - i0(ji) ) * qsr_ice_1d(ji) - fc_su(ji) 
+         zf_tt(ji) = fc_bo_i(ji) + fhtur_1d(ji) + fhld_1d(ji) 
+
+         zq_su (ji) = MAX( 0._wp, zfdum     * rdt_ice ) * MAX( 0._wp , SIGN( 1._wp, t_su_1d(ji) - ztmelts ) )
+         zq_bo (ji) = MAX( 0._wp, zf_tt(ji) * rdt_ice )
+      END DO
+
       !
       !------------------------------------------------------------------------------!
-      !  2) Computing layer thicknesses and  snow and sea-ice enthalpies.            !
+      ! If snow temperature is above freezing point, then snow melts 
+      ! (should not happen but sometimes it does)
       !------------------------------------------------------------------------------!
-      !
-      DO ji = kideb, kiut     ! Layer thickness
-         zh_i(ji) = ht_i_b(ji) / REAL( nlay_i )
-         zh_s(ji) = ht_s_b(ji) / REAL( nlay_s )
-      END DO
-      !
-      zqt_s(:) = 0._wp        ! Total enthalpy of the snow
+      DO ji = kideb, kiut
+         IF( t_s_1d(ji,1) > rtt ) THEN !!! Internal melting
+            ! Contribution to heat flux to the ocean [W.m-2], < 0  
+            hfx_res_1d(ji) = hfx_res_1d(ji) + q_s_1d(ji,1) * ht_s_1d(ji) * a_i_1d(ji) * r1_rdtice
+            ! Contribution to mass flux
+            wfx_snw_1d(ji) = wfx_snw_1d(ji) + rhosn * ht_s_1d(ji) * a_i_1d(ji) * r1_rdtice
+            ! updates
+            ht_s_1d(ji)   = 0._wp
+            q_s_1d (ji,1) = 0._wp
+            t_s_1d (ji,1) = rtt
+         END IF
+      END DO
+
+      !------------------------------------------------------------!
+      !  2) Computing layer thicknesses and enthalpies.            !
+      !------------------------------------------------------------!
+      !
+      DO ji = kideb, kiut     
+         zh_s(ji) = ht_s_1d(ji) / REAL( nlay_s )
+      END DO
+      !
       DO jk = 1, nlay_s
          DO ji = kideb, kiut
-            zqt_s(ji) =  zqt_s(ji) + q_s_b(ji,jk) * ht_s_b(ji) / REAL( nlay_s )
+            zqh_s(ji) =  zqh_s(ji) + q_s_1d(ji,jk) * zh_s(ji)
          END DO
       END DO
       !
-      zqt_i(:) = 0._wp        ! Total enthalpy of the ice
       DO jk = 1, nlay_i
          DO ji = kideb, kiut
-            zzc = q_i_b(ji,jk) * ht_i_b(ji) / REAL( nlay_i )
-            zqt_i(ji)        =  zqt_i(ji) + zzc
-            zqt_i_lay(ji,jk) =              zzc
+            zh_i(ji,jk) = ht_i_1d(ji) / REAL( nlay_i )
+            zqh_i(ji)   = zqh_i(ji) + q_i_1d(ji,jk) * zh_i(ji,jk)
          END DO
       END DO
@@ -212,149 +233,166 @@
       ! Martin Vancoppenolle, December 2006
 
-      ! Snow fall
-      DO ji = kideb, kiut
-         zcoeff = ( 1.0 - ( 1.0 - at_i_b(ji) )**betas ) / at_i_b(ji) 
+      DO ji = kideb, kiut
+         !-----------
+         ! Snow fall
+         !-----------
+         ! thickness change
+         zcoeff = ( 1._wp - ( 1._wp - at_i_1d(ji) )**betas ) / at_i_1d(ji) 
          zdh_s_pre(ji) = zcoeff * sprecip_1d(ji) * rdt_ice / rhosn
-      END DO
-      zdh_s_mel(:) =  0._wp
-
-      ! Melt of fallen snow
-      DO ji = kideb, kiut
-         ! tatm_ice is now in K
-         zqprec   (ji)   =  rhosn * ( cpic * ( rtt - tatm_ice_1d(ji) ) + lfus )  
-         zqfont_su(ji)   =  z_f_surf(ji) * rdt_ice
-         zdeltah  (ji,1) =  MIN( 0.e0 , - zqfont_su(ji) / MAX( zqprec(ji) , epsi13 ) )
-         zqfont_su(ji)   =  MAX( 0.e0 , - zdh_s_pre(ji) - zdeltah(ji,1)              ) * zqprec(ji)
-         zdeltah  (ji,1) =  MAX( - zdh_s_pre(ji) , zdeltah(ji,1) )
-         zdh_s_mel(ji)   =  zdh_s_mel(ji) + zdeltah(ji,1)
-         ! heat conservation
-         qt_s_in(ji,jl)  =  qt_s_in(ji,jl) + zqprec(ji) * zdh_s_pre(ji)
-         zqt_s  (ji)     =  zqt_s  (ji)    + zqprec(ji) * zdh_s_pre(ji)
-         zqt_s  (ji)     =  MAX( zqt_s(ji) - zqfont_su(ji) , 0.e0 ) 
-      END DO
-
-
-      ! Snow melt due to surface heat imbalance
+         ! enthalpy of the precip (>0, J.m-3) (tatm_ice is now in K)
+         zqprec   (ji) = rhosn * ( cpic * ( rtt - MIN( tatm_ice_1d(ji), rt0_snow) ) + lfus )   
+         IF( sprecip_1d(ji) == 0._wp ) zqprec(ji) = 0._wp
+         ! heat flux from snow precip (>0, W.m-2)
+         hfx_spr_1d(ji) = hfx_spr_1d(ji) + zdh_s_pre(ji) * a_i_1d(ji) * zqprec(ji) * r1_rdtice
+         ! mass flux, <0
+         wfx_spr_1d(ji) = wfx_spr_1d(ji) - rhosn * a_i_1d(ji) * zdh_s_pre(ji) * r1_rdtice
+         ! update thickness
+         ht_s_1d    (ji) = MAX( 0._wp , ht_s_1d(ji) + zdh_s_pre(ji) )
+
+         !---------------------
+         ! Melt of falling snow
+         !---------------------
+         ! thickness change
+         IF( zdh_s_pre(ji) > 0._wp ) THEN
+         zindq          = 1._wp - MAX( 0._wp , SIGN( 1._wp , - zqprec(ji) + epsi20 ) )
+         zdh_s_mel (ji) = - zindq * zq_su(ji) / MAX( zqprec(ji) , epsi20 )
+         zdh_s_mel (ji) = MAX( - zdh_s_pre(ji), zdh_s_mel(ji) ) ! bound melting 
+         ! heat used to melt snow (W.m-2, >0)
+         hfx_snw_1d(ji) = hfx_snw_1d(ji) - zdh_s_mel(ji) * a_i_1d(ji) * zqprec(ji) * r1_rdtice
+         ! snow melting only = water into the ocean (then without snow precip), >0
+         wfx_snw_1d(ji) = wfx_snw_1d(ji) - rhosn * a_i_1d(ji) * zdh_s_mel(ji) * r1_rdtice
+         
+         ! updates available heat + thickness
+         zq_su (ji) = MAX( 0._wp , zq_su (ji) + zdh_s_mel(ji) * zqprec(ji) )      
+         ht_s_1d(ji) = MAX( 0._wp , ht_s_1d(ji) + zdh_s_mel(ji) )
+         zh_s  (ji) = ht_s_1d(ji) / REAL( nlay_s )
+
+         ENDIF
+      END DO
+
+      ! If heat still available, then melt more snow
+      zdeltah(:,:) = 0._wp ! important
       DO jk = 1, nlay_s
          DO ji = kideb, kiut
-            zdeltah  (ji,jk) = - zqfont_su(ji) / q_s_b(ji,jk)
-            zqfont_su(ji)    =  MAX( 0.0 , - zh_s(ji) - zdeltah(ji,jk) ) * q_s_b(ji,jk) 
-            zdeltah  (ji,jk) =  MAX( zdeltah(ji,jk) , - zh_s(ji) )
-            zdh_s_mel(ji)    =  zdh_s_mel(ji) + zdeltah(ji,jk)        ! resulting melt of snow    
+            ! thickness change
+            zindh            = 1._wp - MAX( 0._wp, SIGN( 1._wp, - ht_s_1d(ji) ) ) 
+            zindq            = 1._wp - MAX( 0._wp, SIGN( 1._wp, - q_s_1d(ji,jk) + epsi20 ) ) 
+            zdeltah  (ji,jk) = - zindh * zindq * zq_su(ji) / MAX( q_s_1d(ji,jk), epsi20 )
+            zdeltah  (ji,jk) = MAX( zdeltah(ji,jk) , - zh_s(ji) ) ! bound melting
+            zdh_s_mel(ji)    = zdh_s_mel(ji) + zdeltah(ji,jk)    
+            ! heat used to melt snow(W.m-2, >0)
+            hfx_snw_1d(ji)   = hfx_snw_1d(ji) - zdeltah(ji,jk) * a_i_1d(ji) * q_s_1d(ji,jk) * r1_rdtice 
+            ! snow melting only = water into the ocean (then without snow precip)
+            wfx_snw_1d(ji)   = wfx_snw_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+
+            ! updates available heat + thickness
+            zq_su (ji) = MAX( 0._wp , zq_su (ji) + zdeltah(ji,jk) * q_s_1d(ji,jk) )
+            ht_s_1d(ji) = MAX( 0._wp , ht_s_1d(ji) + zdeltah(ji,jk) )
+
          END DO
       END DO
 
-      ! Apply snow melt to snow depth
-      DO ji = kideb, kiut
-         dh_s_tot(ji)   =  zdh_s_mel(ji) + zdh_s_pre(ji)
-         ! Old and new snow depths
-         zhsold(ji)     =  ht_s_b(ji)
-         zhsnew         =  ht_s_b(ji) + dh_s_tot(ji)
-         ! If snow is still present zhn = 1, else zhn = 0
-         zhn            =  1.0 - MAX(  zzero , SIGN( zone , - zhsnew )  )
-         ht_s_b(ji)     =  MAX( zzero , zhsnew )
-         ! we recompute dh_s_tot (clem) 
-         dh_s_tot (ji)  =  ht_s_b(ji) - zhsold(ji)
-         ! Volume and mass variations of snow
-         dvsbq_1d  (ji) =  a_i_b(ji) * ( ht_s_b(ji) - zhsold(ji) - zdh_s_pre(ji) )
-         dvsbq_1d  (ji) =  MIN( zzero, dvsbq_1d(ji) )
-         !clem rdm_snw_1d(ji) =  rdm_snw_1d(ji) + rhosn * dvsbq_1d(ji)
+      !----------------------
+      ! 3.2 Snow sublimation 
+      !----------------------
+      ! qla_ice is always >=0 (upwards), heat goes to the atmosphere, therefore snow sublimates
+      ! clem comment: not counted in mass exchange in limsbc since this is an exchange with atm. (not ocean)
+      ! clem comment: ice should also sublimate
+      IF( lk_cpl ) THEN
+         ! coupled mode: sublimation already included in emp_ice (to do in limsbc_ice)
+         zdh_s_sub(:)      =  0._wp 
+      ELSE
+         ! forced  mode: snow thickness change due to sublimation
+         DO ji = kideb, kiut
+            zdh_s_sub(ji)  =  MAX( - ht_s_1d(ji) , - parsub * qla_ice_1d(ji) / ( rhosn * lsub ) * rdt_ice )
+            ! Heat flux by sublimation [W.m-2], < 0
+            !      sublimate first snow that had fallen, then pre-existing snow
+            zcoeff         =      ( MAX( zdh_s_sub(ji), - MAX( 0._wp, zdh_s_pre(ji) + zdh_s_mel(ji) ) )   * zqprec(ji) +   &
+               &  ( zdh_s_sub(ji) - MAX( zdh_s_sub(ji), - MAX( 0._wp, zdh_s_pre(ji) + zdh_s_mel(ji) ) ) ) * q_s_1d(ji,1) )  &
+               &  * a_i_1d(ji) * r1_rdtice
+            hfx_sub_1d(ji) = hfx_sub_1d(ji) + zcoeff
+            ! Mass flux by sublimation
+            wfx_sub_1d(ji) =  wfx_sub_1d(ji) - rhosn * a_i_1d(ji) * zdh_s_sub(ji) * r1_rdtice
+            ! new snow thickness
+            ht_s_1d(ji)     =  MAX( 0._wp , ht_s_1d(ji) + zdh_s_sub(ji) )
+         END DO
+      ENDIF
+
+      ! --- Update snow diags --- !
+      DO ji = kideb, kiut
+         dh_s_tot(ji)   = zdh_s_mel(ji) + zdh_s_pre(ji) + zdh_s_sub(ji)
+         zh_s(ji)       = ht_s_1d(ji) / REAL( nlay_s )
       END DO ! ji
 
+      !-------------------------------------------
+      ! 3.3 Update temperature, energy
+      !-------------------------------------------
+      ! new temp and enthalpy of the snow (remaining snow precip + remaining pre-existing snow)
+      zq_s(:) = 0._wp 
+      DO jk = 1, nlay_s
+         DO ji = kideb,kiut
+            zindh  =  MAX(  0._wp , SIGN( 1._wp, - ht_s_1d(ji) + epsi20 )  )
+            q_s_1d(ji,jk) = ( 1._wp - zindh ) / MAX( ht_s_1d(ji), epsi20 ) *             &
+              &            ( (   MAX( 0._wp, dh_s_tot(ji) )              ) * zqprec(ji) +  &
+              &              ( - MAX( 0._wp, dh_s_tot(ji) ) + ht_s_1d(ji) ) * rhosn * ( cpic * ( rtt - t_s_1d(ji,jk) ) + lfus ) )
+            zq_s(ji)     =  zq_s(ji) + q_s_1d(ji,jk)
+         END DO
+      END DO
+
       !--------------------------
-      ! 3.2 Surface ice ablation 
+      ! 3.4 Surface ice ablation 
       !--------------------------
-      DO ji = kideb, kiut 
-         z_f_surf (ji) =  zqfont_su(ji) * r1_rdtice   ! heat conservation test
-         zdq_i    (ji) =  0._wp
-      END DO ! ji
-
+      zdeltah(:,:) = 0._wp ! important
       DO jk = 1, nlay_i
          DO ji = kideb, kiut 
-            !                                                    ! melt of layer jk
-            zdeltah  (ji,jk) = - zqfont_su(ji) / q_i_b(ji,jk)
-            !                                                    ! recompute heat available
-            zqfont_su(ji   ) = MAX( 0.0 , - zh_i(ji) - zdeltah(ji,jk) ) * q_i_b(ji,jk) 
-            !                                                    ! melt of layer jk cannot be higher than its thickness
-            zdeltah  (ji,jk) = MAX( zdeltah(ji,jk) , - zh_i(ji) )
-            !                                                    ! update surface melt
-            dh_i_surf(ji   ) = dh_i_surf(ji) + zdeltah(ji,jk) 
-            !                                                    ! for energy conservation
-            zdq_i    (ji   ) = zdq_i(ji) + zdeltah(ji,jk) * q_i_b(ji,jk) * r1_rdtice
-            !
-            ! clem
-            sfx_thd_1d(ji) = sfx_thd_1d(ji) - sm_i_b(ji) * a_i_b(ji)    &
-               &                              * MIN( zdeltah(ji,jk) , 0._wp ) * rhoic / rdt_ice
+            zEi            = - q_i_1d(ji,jk) / rhoic                ! Specific enthalpy of layer k [J/kg, <0]
+
+            ztmelts        = - tmut * s_i_1d(ji,jk) + rtt           ! Melting point of layer k [K]
+
+            zEw            =    rcp * ( ztmelts - rt0 )            ! Specific enthalpy of resulting meltwater [J/kg, <0]
+
+            zdE            =    zEi - zEw                          ! Specific enthalpy difference < 0
+
+            zfmdt          = - zq_su(ji) / zdE                     ! Mass flux to the ocean [kg/m2, >0]
+
+            zdeltah(ji,jk) = - zfmdt / rhoic                       ! Melt of layer jk [m, <0]
+
+            zdeltah(ji,jk) = MIN( 0._wp , MAX( zdeltah(ji,jk) , - zh_i(ji,jk) ) )    ! Melt of layer jk cannot exceed the layer thickness [m, <0]
+
+            zq_su(ji)      = MAX( 0._wp , zq_su(ji) - zdeltah(ji,jk) * rhoic * zdE ) ! update available heat
+
+            dh_i_surf(ji)  = dh_i_surf(ji) + zdeltah(ji,jk)        ! Cumulate surface melt
+
+            zfmdt          = - rhoic * zdeltah(ji,jk)              ! Recompute mass flux [kg/m2, >0]
+
+            zQm            = zfmdt * zEw                           ! Energy of the melt water sent to the ocean [J/m2, <0]
+
+            ! Contribution to salt flux (clem: using sm_i_1d and not s_i_1d(jk) is ok)
+            sfx_sum_1d(ji)   = sfx_sum_1d(ji) - sm_i_1d(ji) * a_i_1d(ji) * zdeltah(ji,jk) * rhoic * r1_rdtice
+
+            ! Contribution to heat flux [W.m-2], < 0
+            hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
+
+            ! Total heat flux used in this process [W.m-2], > 0  
+            hfx_sum_1d(ji) = hfx_sum_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
+
+            ! Contribution to mass flux
+            wfx_sum_1d(ji) =  wfx_sum_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+           
+            ! record which layers have disappeared (for bottom melting) 
+            !    => icount=0 : no layer has vanished
+            !    => icount=5 : 5 layers have vanished
+            zindh       = NINT( MAX( 0._wp , SIGN( 1._wp , - ( zh_i(ji,jk) + zdeltah(ji,jk) ) ) ) ) 
+            icount(ji)  = icount(ji) + zindh
+            zh_i(ji,jk) = MAX( 0._wp , zh_i(ji,jk) + zdeltah(ji,jk) )
+
+            ! update heat content (J.m-2) and layer thickness
+            qh_i_old(ji,jk) = qh_i_old(ji,jk) + zdeltah(ji,jk) * q_i_1d(ji,jk)
+            h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
          END DO
       END DO
-
-      !                                          !-------------------
-      IF( con_i .AND. jiindex_1d > 0 ) THEN      ! Conservation test
-         !                                       !-------------------
-         numce_dh  = 0
-         meance_dh = 0._wp
-         DO ji = kideb, kiut
-            IF ( ( z_f_surf(ji) + zdq_i(ji) ) .GE. 1.0e-3 ) THEN
-               numce_dh  = numce_dh + 1
-               meance_dh = meance_dh + z_f_surf(ji) + zdq_i(ji)
-            ENDIF
-            IF( z_f_surf(ji) + zdq_i(ji) .GE. 1.0e-3  ) THEN!
-               WRITE(numout,*) ' ALERTE heat loss for surface melt '
-               WRITE(numout,*) ' ii, ij, jl :', ii, ij, jl
-               WRITE(numout,*) ' ht_i_b       : ', ht_i_b(ji)
-               WRITE(numout,*) ' z_f_surf     : ', z_f_surf(ji)
-               WRITE(numout,*) ' zdq_i        : ', zdq_i(ji)
-               WRITE(numout,*) ' ht_i_b       : ', ht_i_b(ji)
-               WRITE(numout,*) ' fc_bo_i      : ', fc_bo_i(ji)
-               WRITE(numout,*) ' fbif_1d      : ', fbif_1d(ji)
-               WRITE(numout,*) ' qlbbq_1d     : ', qlbbq_1d(ji)
-               WRITE(numout,*) ' s_i_new      : ', s_i_new(ji)
-               WRITE(numout,*) ' sss_m        : ', sss_m(ii,ij)
-            ENDIF
-         END DO
-         !
-         IF( numce_dh > 0 )   meance_dh = meance_dh / numce_dh
-         WRITE(numout,*) ' Error report - Category : ', jl
-         WRITE(numout,*) ' ~~~~~~~~~~~~ '
-         WRITE(numout,*) ' Number of points where there is sur. me. error : ', numce_dh
-         WRITE(numout,*) ' Mean basal growth error on error points : ', meance_dh
-         !
-      ENDIF
-
-      !----------------------
-      ! 3.3 Snow sublimation
-      !----------------------
-
-      DO ji = kideb, kiut
-         ! qla_ice is always >=0 (upwards), heat goes to the atmosphere, therefore snow sublimates
-#if defined key_coupled
-         zdh_s_sub(ji)    =  0._wp      ! coupled mode: sublimation already included in emp_ice (to do in limsbc_ice)
-#else
-         !                              ! forced  mode: snow thickness change due to sublimation
-         zdh_s_sub(ji)    =  - parsub * qla_ice_1d(ji) / ( rhosn * lsub ) * rdt_ice
-#endif
-         dh_s_tot (ji)    =  dh_s_tot(ji) + zdh_s_sub(ji)
-         zdhcf            =  ht_s_b(ji) + zdh_s_sub(ji) 
-         ht_s_b   (ji)    =  MAX( zzero , zdhcf )
-         ! we recompute dh_s_tot 
-         dh_s_tot (ji)    =  ht_s_b(ji) - zhsold(ji)
-         qt_s_in  (ji,jl) =  qt_s_in(ji,jl) + zdh_s_sub(ji)*q_s_b(ji,1)
-      END DO
-
-      zqt_dummy(:) = 0.e0
-      DO jk = 1, nlay_s
-         DO ji = kideb,kiut
-            q_s_b    (ji,jk) = rhosn * ( cpic * ( rtt - t_s_b(ji,jk) ) + lfus )
-            zqt_dummy(ji)    =  zqt_dummy(ji) + q_s_b(ji,jk) * ht_s_b(ji) / REAL( nlay_s )            ! heat conservation
-         END DO
-      END DO
-
-      DO jk = 1, nlay_s
-         DO ji = kideb, kiut
-            ! In case of disparition of the snow, we have to update the snow temperatures
-            zhisn  =  MAX(  zzero , SIGN( zone, - ht_s_b(ji) )  )
-            t_s_b(ji,jk) = ( 1.0 - zhisn ) * t_s_b(ji,jk) + zhisn * rtt
-            q_s_b(ji,jk) = ( 1.0 - zhisn ) * q_s_b(ji,jk)
-         END DO
+      ! update ice thickness
+      DO ji = kideb, kiut
+         ht_i_1d(ji) =  MAX( 0._wp , ht_i_1d(ji) + dh_i_surf(ji) )
       END DO
 
@@ -364,302 +402,251 @@
       !------------------------------------------------------------------------------!
       !
-      ! Ice basal growth / melt is given by the ratio of heat budget over basal
-      ! ice heat content.  Basal heat budget is given by the difference between
-      ! the inner conductive flux  (fc_bo_i), from the open water heat flux 
-      ! (qlbbqb) and the turbulent ocean flux (fbif). 
-      ! fc_bo_i is positive downwards. fbif and qlbbq are positive to the ice 
-
-      !-----------------------------------------------------
-      ! 4.1 Basal growth - (a) salinity not varying in time 
-      !-----------------------------------------------------
-      IF(  num_sal /= 2  ) THEN   ! ice salinity constant in time
+      !------------------
+      ! 4.1 Basal growth 
+      !------------------
+      ! Basal growth is driven by heat imbalance at the ice-ocean interface,
+      ! between the inner conductive flux  (fc_bo_i), from the open water heat flux 
+      ! (fhld) and the turbulent ocean flux (fhtur). 
+      ! fc_bo_i is positive downwards. fhtur and fhld are positive to the ice 
+
+      ! If salinity varies in time, an iterative procedure is required, because
+      ! the involved quantities are inter-dependent.
+      ! Basal growth (dh_i_bott) depends upon new ice specific enthalpy (zEi),
+      ! which depends on forming ice salinity (s_i_new), which depends on dh/dt (dh_i_bott)
+      ! -> need for an iterative procedure, which converges quickly
+
+      IF ( num_sal == 2 ) THEN
+         num_iter_max = 5
+      ELSE
+         num_iter_max = 1
+      ENDIF
+
+      !clem debug. Just to be sure that enthalpy at nlay_i+1 is null
+      DO ji = kideb, kiut
+         q_i_1d(ji,nlay_i+1) = 0._wp
+      END DO
+
+      ! Iterative procedure
+      DO iter = 1, num_iter_max
          DO ji = kideb, kiut
-            IF(  ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) < 0._wp  ) THEN
-               s_i_new(ji)         =  sm_i_b(ji)
-               ! Melting point in K
-               ztmelts             =  - tmut * s_i_new(ji) + rtt 
-               ! New ice heat content (Bitz and Lipscomb, 1999)
-               ztform              =  t_i_b(ji,nlay_i)  ! t_bo_b crashes in the
-               ! Baltic
-               q_i_b(ji,nlay_i+1)  = rhoic * (  cpic * ( ztmelts - ztform )                                &
-                  &                           + lfus * (  1.0 - ( ztmelts - rtt ) / ( ztform - rtt )  )    &
-                  &                           - rcp  * ( ztmelts - rtt )                                 )
-               ! Basal growth rate = - F*dt / q
-               dh_i_bott(ji)       =  - rdt_ice * ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) / q_i_b(ji,nlay_i+1) 
-               sfx_thd_1d(ji) = sfx_thd_1d(ji) - s_i_new(ji) * a_i_b(ji) * dh_i_bott(ji) * rhoic * r1_rdtice
-            ENDIF
-         END DO
-      ENDIF
-
-      !-------------------------------------------------
-      ! 4.1 Basal growth - (b) salinity varying in time 
-      !-------------------------------------------------
-      IF(  num_sal == 2  ) THEN
-         ! the growth rate (dh_i_bott) is function of the new ice heat content (q_i_b(nlay_i+1)). 
-         ! q_i_b depends on the new ice salinity (snewice). 
-         ! snewice depends on dh_i_bott ; it converges quickly, so, no problem
-         ! See Vancoppenolle et al., OM08 for more info on this
-
-         ! Initial value (tested 1D, can be anything between 1 and 20)
-         num_iter_max = 4
-         s_i_new(:)   = 4.0
-
-         ! Iterative procedure
-         DO iter = 1, num_iter_max
-            DO ji = kideb, kiut
-               IF(  fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) < 0.e0  ) THEN
-                  ii = MOD( npb(ji) - 1, jpi ) + 1
-                  ij = ( npb(ji) - 1 ) / jpi + 1
-                  ! Melting point in K
-                  ztmelts             =   - tmut * s_i_new(ji) + rtt 
-                  ! New ice heat content (Bitz and Lipscomb, 1999)
-                  q_i_b(ji,nlay_i+1)  =  rhoic * (  cpic * ( ztmelts - t_bo_b(ji) )                             &
-                     &                            + lfus * ( 1.0 - ( ztmelts - rtt ) / ( t_bo_b(ji) - rtt ) )   &
-                     &                            - rcp * ( ztmelts-rtt )                                     )
-                  ! Bottom growth rate = - F*dt / q
-                  dh_i_bott(ji) =  - rdt_ice * ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) / q_i_b(ji,nlay_i+1)
-                  ! New ice salinity ( Cox and Weeks, JGR, 1988 )
-                  ! zswi2  (1) if dh_i_bott/rdt .GT. 3.6e-7
-                  ! zswi12 (1) if dh_i_bott/rdt .LT. 3.6e-7 and .GT. 2.0e-8
-                  ! zswi1  (1) if dh_i_bott/rdt .LT. 2.0e-8
-                  zgrr   = MIN( 1.0e-3, MAX ( dh_i_bott(ji) * r1_rdtice , epsi13 ) )
-                  zswi2  = MAX( zzero , SIGN( zone , zgrr - 3.6e-7 ) ) 
-                  zswi12 = MAX( zzero , SIGN( zone , zgrr - 2.0e-8 ) ) * ( 1.0 - zswi2 )
-                  zswi1  = 1. - zswi2 * zswi12 
-                  zfracs = zswi1  * 0.12 + zswi12 * ( 0.8925 + 0.0568 * LOG( 100.0 * zgrr ) )   &
-                     &                   + zswi2  * 0.26 / ( 0.26 + 0.74 * EXP ( - 724300.0 * zgrr ) ) 
-                  zfracs = MIN( 0.5 , zfracs )
-                  s_i_new(ji) = zfracs * sss_m(ii,ij)
-               ENDIF ! fc_bo_i
-            END DO ! ji
-         END DO ! iter
-
-         ! Final values
-         DO ji = kideb, kiut
-            IF( ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) .LT. 0.0  ) THEN
-               ! New ice salinity must not exceed 20 psu
-               s_i_new(ji) = MIN( s_i_new(ji), s_i_max )
-               ! Metling point in K
-               ztmelts     =   - tmut * s_i_new(ji) + rtt 
-               ! New ice heat content (Bitz and Lipscomb, 1999)
-               q_i_b(ji,nlay_i+1)  =  rhoic * (  cpic * ( ztmelts - t_bo_b(ji) )                              &
-                  &                            + lfus * ( 1.0 - ( ztmelts - rtt ) / ( t_bo_b(ji) - rtt ) )    &
-                  &                            - rcp * ( ztmelts - rtt )                                    )
-               ! Basal growth rate = - F*dt / q
-               dh_i_bott(ji)       =  - rdt_ice * ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) / q_i_b(ji,nlay_i+1)
-               ! Salinity update
-               ! entrapment during bottom growth
-               sfx_thd_1d(ji) = sfx_thd_1d(ji) - s_i_new(ji) * a_i_b(ji) * dh_i_bott(ji) * rhoic * r1_rdtice
-            ENDIF ! heat budget
-         END DO
-      ENDIF
+            IF(  zf_tt(ji) < 0._wp  ) THEN
+
+               ! New bottom ice salinity (Cox & Weeks, JGR88 )
+               !--- zswi1  if dh/dt < 2.0e-8
+               !--- zswi12 if 2.0e-8 < dh/dt < 3.6e-7 
+               !--- zswi2  if dh/dt > 3.6e-7
+               zgrr               = MIN( 1.0e-3, MAX ( dh_i_bott(ji) * r1_rdtice , epsi10 ) )
+               zswi2              = MAX( 0._wp , SIGN( 1._wp , zgrr - 3.6e-7 ) )
+               zswi12             = MAX( 0._wp , SIGN( 1._wp , zgrr - 2.0e-8 ) ) * ( 1.0 - zswi2 )
+               zswi1              = 1. - zswi2 * zswi12
+               zfracs             = MIN ( zswi1  * 0.12 + zswi12 * ( 0.8925 + 0.0568 * LOG( 100.0 * zgrr ) )   &
+                  &               + zswi2  * 0.26 / ( 0.26 + 0.74 * EXP ( - 724300.0 * zgrr ) )  , 0.5 )
+
+               ii = MOD( npb(ji) - 1, jpi ) + 1 ; ij = ( npb(ji) - 1 ) / jpi + 1
+
+               s_i_new(ji)        = zswitch_sal * zfracs * sss_m(ii,ij)  &  ! New ice salinity
+                                  + ( 1. - zswitch_sal ) * sm_i_1d(ji) 
+               ! New ice growth
+               ztmelts            = - tmut * s_i_new(ji) + rtt          ! New ice melting point (K)
+
+               zt_i_new           = zswitch_sal * t_bo_1d(ji) + ( 1. - zswitch_sal) * t_i_1d(ji, nlay_i)
+               
+               zEi                = cpic * ( zt_i_new - ztmelts ) &     ! Specific enthalpy of forming ice (J/kg, <0)      
+                  &               - lfus * ( 1.0 - ( ztmelts - rtt ) / ( zt_i_new - rtt ) )   &
+                  &               + rcp  * ( ztmelts-rtt )          
+
+               zEw                = rcp  * ( t_bo_1d(ji) - rt0 )         ! Specific enthalpy of seawater (J/kg, < 0)
+
+               zdE                = zEi - zEw                           ! Specific enthalpy difference (J/kg, <0)
+
+               dh_i_bott(ji)      = rdt_ice * MAX( 0._wp , zf_tt(ji) / ( zdE * rhoic ) )
+
+               q_i_1d(ji,nlay_i+1) = -zEi * rhoic                        ! New ice energy of melting (J/m3, >0)
+               
+            ENDIF ! fc_bo_i
+         END DO ! ji
+      END DO ! iter
+
+      ! Contribution to Energy and Salt Fluxes
+      DO ji = kideb, kiut
+         IF(  zf_tt(ji) < 0._wp  ) THEN
+            ! New ice growth
+                                    
+            zfmdt          = - rhoic * dh_i_bott(ji)             ! Mass flux x time step (kg/m2, < 0)
+
+            ztmelts        = - tmut * s_i_new(ji) + rtt          ! New ice melting point (K)
+            
+            zt_i_new       = zswitch_sal * t_bo_1d(ji) + ( 1. - zswitch_sal) * t_i_1d(ji, nlay_i)
+            
+            zEi            = cpic * ( zt_i_new - ztmelts ) &     ! Specific enthalpy of forming ice (J/kg, <0)      
+               &               - lfus * ( 1.0 - ( ztmelts - rtt ) / ( zt_i_new - rtt ) )   &
+               &               + rcp  * ( ztmelts-rtt )          
+            
+            zEw            = rcp  * ( t_bo_1d(ji) - rt0 )         ! Specific enthalpy of seawater (J/kg, < 0)
+            
+            zdE            = zEi - zEw                           ! Specific enthalpy difference (J/kg, <0)
+            
+            ! Contribution to heat flux to the ocean [W.m-2], >0  
+            hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
+
+            ! Total heat flux used in this process [W.m-2], <0  
+            hfx_bog_1d(ji) = hfx_bog_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
+            
+            ! Contribution to salt flux, <0
+            sfx_bog_1d(ji) = sfx_bog_1d(ji) + s_i_new(ji) * a_i_1d(ji) * zfmdt * r1_rdtice
+
+            ! Contribution to mass flux, <0
+            wfx_bog_1d(ji) =  wfx_bog_1d(ji) - rhoic * a_i_1d(ji) * dh_i_bott(ji) * r1_rdtice
+
+            ! update heat content (J.m-2) and layer thickness
+            qh_i_old(ji,nlay_i+1) = qh_i_old(ji,nlay_i+1) + dh_i_bott(ji) * q_i_1d(ji,nlay_i+1)
+            h_i_old (ji,nlay_i+1) = h_i_old (ji,nlay_i+1) + dh_i_bott(ji)
+         ENDIF
+      END DO
 
       !----------------
       ! 4.2 Basal melt
       !----------------
-      meance_dh = 0._wp
-      numce_dh  = 0
-      zinnermelt(:) = 0._wp
-
-      DO ji = kideb, kiut
-         ! heat convergence at the surface > 0
-         IF(  ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) >= 0._wp  ) THEN
-            s_i_new(ji)   =  s_i_b(ji,nlay_i)
-            zqfont_bo(ji) =  rdt_ice * ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) )
-            zfbase(ji)    =  zqfont_bo(ji) * r1_rdtice     ! heat conservation test
-            zdq_i(ji)     =  0._wp
-            dh_i_bott(ji) =  0._wp
-         ENDIF
-      END DO
-
+      zdeltah(:,:) = 0._wp ! important
       DO jk = nlay_i, 1, -1
          DO ji = kideb, kiut
-            IF(  fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji)  >=  0._wp  ) THEN
-               ztmelts = - tmut * s_i_b(ji,jk) + rtt 
-               IF( t_i_b(ji,jk) >= ztmelts ) THEN   !!gm : a comment is needed
-                  zdeltah   (ji,jk) = - zh_i(ji)
-                  dh_i_bott (ji   ) = dh_i_bott(ji) + zdeltah(ji,jk)
-                  zinnermelt(ji   ) = 1._wp
-               ELSE                                  ! normal ablation
-                  zdeltah  (ji,jk) = - zqfont_bo(ji) / q_i_b(ji,jk)
-                  zqfont_bo(ji   ) = MAX( 0.0 , - zh_i(ji) - zdeltah(ji,jk) ) * q_i_b(ji,jk)
-                  zdeltah  (ji,jk) = MAX(zdeltah(ji,jk), - zh_i(ji) )
-                  dh_i_bott(ji   ) = dh_i_bott(ji) + zdeltah(ji,jk)
-                  zdq_i    (ji   ) = zdq_i(ji) + zdeltah(ji,jk) * q_i_b(ji,jk) * r1_rdtice
+            IF(  zf_tt(ji)  >=  0._wp  .AND. jk > icount(ji) ) THEN   ! do not calculate where layer has already disappeared from surface melting 
+
+               ztmelts = - tmut * s_i_1d(ji,jk) + rtt  ! Melting point of layer jk (K)
+
+               IF( t_i_1d(ji,jk) >= ztmelts ) THEN !!! Internal melting
+                  zintermelt(ji)    = 1._wp
+
+                  zEi               = - q_i_1d(ji,jk) / rhoic        ! Specific enthalpy of melting ice (J/kg, <0)
+
+                  !!zEw               = rcp * ( t_i_1d(ji,jk) - rtt )  ! Specific enthalpy of meltwater at T = t_i_1d (J/kg, <0)
+
+                  zdE               = 0._wp                         ! Specific enthalpy difference   (J/kg, <0)
+                                                                    ! set up at 0 since no energy is needed to melt water...(it is already melted)
+
+                  zdeltah   (ji,jk) = MIN( 0._wp , - zh_i(ji,jk) ) ! internal melting occurs when the internal temperature is above freezing     
+                                                                   ! this should normally not happen, but sometimes, heat diffusion leads to this
+
+                  dh_i_bott (ji)    = dh_i_bott(ji) + zdeltah(ji,jk)
+
+                  zfmdt             = - zdeltah(ji,jk) * rhoic          ! Mass flux x time step > 0
+
+                  ! Contribution to heat flux to the ocean [W.m-2], <0 (ice enthalpy zEi is "sent" to the ocean) 
+                  hfx_res_1d(ji) = hfx_res_1d(ji) + zfmdt * a_i_1d(ji) * zEi * r1_rdtice
+
+                  ! Contribution to salt flux (clem: using sm_i_1d and not s_i_1d(jk) is ok)
+                  sfx_res_1d(ji) = sfx_res_1d(ji) - sm_i_1d(ji) * a_i_1d(ji) * zdeltah(ji,jk) * rhoic * r1_rdtice
+                                    
+                  ! Contribution to mass flux
+                  wfx_res_1d(ji) =  wfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+
+                  ! update heat content (J.m-2) and layer thickness
+                  qh_i_old(ji,jk) = qh_i_old(ji,jk) + zdeltah(ji,jk) * q_i_1d(ji,jk)
+                  h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
+
+               ELSE                               !!! Basal melting
+
+                  zEi               = - q_i_1d(ji,jk) / rhoic ! Specific enthalpy of melting ice (J/kg, <0)
+
+                  zEw               = rcp * ( ztmelts - rtt )! Specific enthalpy of meltwater (J/kg, <0)
+
+                  zdE               = zEi - zEw              ! Specific enthalpy difference   (J/kg, <0)
+
+                  zfmdt             = - zq_bo(ji) / zdE  ! Mass flux x time step (kg/m2, >0)
+
+                  zdeltah(ji,jk)    = - zfmdt / rhoic        ! Gross thickness change
+
+                  zdeltah(ji,jk)    = MIN( 0._wp , MAX( zdeltah(ji,jk), - zh_i(ji,jk) ) ) ! bound thickness change
+                  
+                  zq_bo(ji)         = MAX( 0._wp , zq_bo(ji) - zdeltah(ji,jk) * rhoic * zdE ) ! update available heat. MAX is necessary for roundup errors
+
+                  dh_i_bott(ji)     = dh_i_bott(ji) + zdeltah(ji,jk)    ! Update basal melt
+
+                  zfmdt             = - zdeltah(ji,jk) * rhoic          ! Mass flux x time step > 0
+
+                  zQm               = zfmdt * zEw         ! Heat exchanged with ocean
+
+                  ! Contribution to heat flux to the ocean [W.m-2], <0  
+                  hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
+
+                  ! Contribution to salt flux (clem: using sm_i_1d and not s_i_1d(jk) is ok)
+                  sfx_bom_1d(ji) = sfx_bom_1d(ji) - sm_i_1d(ji) * a_i_1d(ji) * zdeltah(ji,jk) * rhoic * r1_rdtice
+                  
+                  ! Total heat flux used in this process [W.m-2], >0  
+                  hfx_bom_1d(ji) = hfx_bom_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
+                  
+                  ! Contribution to mass flux
+                  wfx_bom_1d(ji) =  wfx_bom_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+
+                  ! update heat content (J.m-2) and layer thickness
+                  qh_i_old(ji,jk) = qh_i_old(ji,jk) + zdeltah(ji,jk) * q_i_1d(ji,jk)
+                  h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
                ENDIF
-               ! clem: contribution to salt flux
-               sfx_thd_1d(ji) = sfx_thd_1d(ji) - sm_i_b(ji) * a_i_b(ji)    &
-                    &                              * MIN( zdeltah(ji,jk) , 0._wp ) * rhoic * r1_rdtice
+           
             ENDIF
          END DO ! ji
       END DO ! jk
 
-      !                                          !-------------------
-      IF( con_i .AND. jiindex_1d > 0 ) THEN      ! Conservation test
-      !                                          !-------------------
-         DO ji = kideb, kiut
-            IF(  ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) >= 0.e0  ) THEN
-               IF( ( zfbase(ji) + zdq_i(ji) ) >= 1.e-3 ) THEN
-                  numce_dh  = numce_dh + 1
-                  meance_dh = meance_dh + zfbase(ji) + zdq_i(ji)
-               ENDIF
-               IF ( zfbase(ji) + zdq_i(ji) .GE. 1.0e-3  ) THEN
-                  WRITE(numout,*) ' ALERTE heat loss for basal melt : ii, ij, jl :', ii, ij, jl
-                  WRITE(numout,*) ' ht_i_b    : ', ht_i_b(ji)
-                  WRITE(numout,*) ' zfbase    : ', zfbase(ji)
-                  WRITE(numout,*) ' zdq_i     : ', zdq_i(ji)
-                  WRITE(numout,*) ' ht_i_b    : ', ht_i_b(ji)
-                  WRITE(numout,*) ' fc_bo_i   : ', fc_bo_i(ji)
-                  WRITE(numout,*) ' fbif_1d   : ', fbif_1d(ji)
-                  WRITE(numout,*) ' qlbbq_1d  : ', qlbbq_1d(ji)
-                  WRITE(numout,*) ' s_i_new   : ', s_i_new(ji)
-                  WRITE(numout,*) ' sss_m     : ', sss_m(ii,ij)
-                  WRITE(numout,*) ' dh_i_bott : ', dh_i_bott(ji)
-                  WRITE(numout,*) ' innermelt : ', INT( zinnermelt(ji) )
-               ENDIF
-            ENDIF
-         END DO
-         IF( numce_dh > 0 )   meance_dh = meance_dh / numce_dh
-         WRITE(numout,*) ' Number of points where there is bas. me. error : ', numce_dh
-         WRITE(numout,*) ' Mean basal melt error on error points : ', meance_dh
-         WRITE(numout,*) ' Remaining bottom heat : ', zqfont_bo(jiindex_1d)
-         !
-      ENDIF
-
-      !
       !------------------------------------------------------------------------------!
-      !  5) Pathological cases                                                       !
+      ! Excessive ablation in a 1-category model
+      !     in a 1-category sea ice model, bottom ablation must not exceed hmelt (-0.15)
       !------------------------------------------------------------------------------!
-      !
-      !----------------------------------------------
-      ! 5.1 Excessive ablation in a 1-category model
-      !----------------------------------------------
-
-      DO ji = kideb, kiut
-         !                     ! in a 1-category sea ice model, bottom ablation must not exceed hmelt (-0.15)
-         IF( jpl == 1 ) THEN   ;   zdhbf = MAX( hmelt , dh_i_bott(ji) )
-         ELSE                  ;   zdhbf =              dh_i_bott(ji) 
-         ENDIF
-         zdvres        = zdhbf - dh_i_bott(ji)
-         dh_i_bott(ji) = zdhbf
-         sfx_thd_1d(ji)  = sfx_thd_1d(ji) - sm_i_b(ji) * a_i_b(ji) * zdvres * rhoic * r1_rdtice
-         !                     ! excessive energy is sent to lateral ablation
-         zinda = MAX( 0._wp, SIGN( 1._wp , 1.0 - at_i_b(ji) - epsi10 ) )
-         fsup(ji) =  zinda * rhoic * lfus * at_i_b(ji) / MAX( 1.0 - at_i_b(ji) , epsi10 ) * zdvres * r1_rdtice
-      END DO
-
-      !-----------------------------------
-      ! 5.2 More than available ice melts
-      !-----------------------------------
-      ! then heat applied minus heat content at previous time step should equal heat remaining 
-      !
-      DO ji = kideb, kiut
-         ! Adapt the remaining energy if too much ice melts
-         !--------------------------------------------------
-         zdvres     = MAX( 0._wp, - ht_i_b(ji) - dh_i_surf(ji) - dh_i_bott(ji) )
-         zdvsur     = MIN( 0._wp, dh_i_surf(ji) + zdvres ) - dh_i_surf(ji) ! fill the surface first
-         zdvbot     = MAX( 0._wp, zdvres - zdvsur ) ! then the bottom
-         dh_i_surf (ji) = dh_i_surf(ji) + zdvsur ! clem
-         dh_i_bott (ji) = dh_i_bott(ji) + zdvbot ! clem
-
-         ! new ice thickness (clem)
-         zhgnew(ji) = ht_i_b(ji) + dh_i_surf(ji) + dh_i_bott(ji)
-         zihgnew    = 1.0 - MAX( zzero , SIGN( zone , - zhgnew(ji) ) ) !1 if ice
-         zhgnew(ji) = zihgnew * zhgnew(ji)      ! ice thickness is put to 0
- 
-         !                     !since ice volume is only used for outputs, we keep it global for all categories
-         dvbbq_1d (ji) = a_i_b(ji) * dh_i_bott(ji)
-
-        ! remaining heat
-         zfdt_final(ji) = ( 1.0 - zihgnew ) * ( zqfont_su(ji) +  zqfont_bo(ji) ) 
-
-         ! If snow remains, energy is used to melt snow
-         zhni =  ht_s_b(ji)      ! snow depth at previous time step
-         zihg =  MAX(  zzero , SIGN ( zone , - ht_s_b(ji) )  )   ! =0 if snow 
-
-         ! energy of melting of remaining snow
-         zinda = MAX( 0._wp, SIGN( 1._wp , zhni - epsi10 ) )
-         zqt_s(ji) =    ( 1. - zihg ) * zqt_s(ji) / MAX( zhni, epsi10 ) * zinda
-         zdhnm     =  - ( 1. - zihg ) * ( 1. - zihgnew ) * zfdt_final(ji) / MAX( zqt_s(ji) , epsi13 )
-         zhnfi     =  zhni + zdhnm
-         zfdt_final(ji) =  MAX( zfdt_final(ji) + zqt_s(ji) * zdhnm , 0.0 )
-         ht_s_b(ji)     =  MAX( zzero , zhnfi )
-         zqt_s(ji)      =  zqt_s(ji) * ht_s_b(ji)
-         ! we recompute dh_s_tot (clem)
-         dh_s_tot (ji)  =  ht_s_b(ji) - zhsold(ji)
-
-         ! Mass variations of ice and snow
-         !---------------------------------
-         !                                              ! mass variation of the jl category
-         zzfmass_s = - a_i_b(ji) * ( zhni       - ht_s_b(ji) ) * rhosn   ! snow
-         zzfmass_i =   a_i_b(ji) * ( zhgnew(ji) - ht_i_b(ji) ) * rhoic   ! ice  
-         !
-         zfmass_i(ji) = zzfmass_i                       ! ice variation saved to compute salt flux (see below)
-         !
-         !                                              ! mass variation cumulated over category
-         !clem rdm_snw_1d(ji) = rdm_snw_1d(ji) + zzfmass_s                     ! snow 
-         !clem rdm_ice_1d(ji) = rdm_ice_1d(ji) + zzfmass_i                     ! ice 
-
-         ! Remaining heat to the ocean 
-         !---------------------------------
-         focea(ji)  = - zfdt_final(ji) * r1_rdtice         ! focea is in W.m-2 * dt
-
-         ! residual salt flux (clem)
-         !--------------------------
-         ! surface
-         sfx_thd_1d(ji)    = sfx_thd_1d(ji) - sm_i_b(ji)  * a_i_b(ji) * zdvsur * rhoic * r1_rdtice
-         ! bottom
-         IF ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) >= 0._wp ) THEN ! melting
-            sfx_thd_1d(ji) = sfx_thd_1d(ji) - sm_i_b(ji)  * a_i_b(ji) * zdvbot * rhoic * r1_rdtice
-         ELSE                                                          ! growth
-            sfx_thd_1d(ji) = sfx_thd_1d(ji) - s_i_new(ji) * a_i_b(ji) * zdvbot * rhoic * r1_rdtice
-         ENDIF
-         !
-         ! diagnostic 
-         ii = MOD( npb(ji) - 1, jpi ) + 1
-         ij = ( npb(ji) - 1 ) / jpi + 1
-         diag_bot_gr(ii,ij) = diag_bot_gr(ii,ij) + MAX(dh_i_bott(ji),0.0)*a_i_b(ji) * r1_rdtice
-         diag_sur_me(ii,ij) = diag_sur_me(ii,ij) + MIN(dh_i_surf(ji),0.0)*a_i_b(ji) * r1_rdtice
-         diag_bot_me(ii,ij) = diag_bot_me(ii,ij) + MIN(dh_i_bott(ji),0.0)*a_i_b(ji) * r1_rdtice
-      END DO
-
-      ftotal_fin (:) = zfdt_final(:)  * r1_rdtice
-
-      !---------------------------
-      ! heat fluxes                    
-      !---------------------------
-      DO ji = kideb, kiut
-         zihgnew    =  1.0 - MAX( zzero , SIGN( zone , - zhgnew(ji) ) )   ! =1 if ice
-         !
-         ! Heat flux
-         ! excessive bottom ablation energy (fsup) - 0 except if jpl = 1
-         ! excessive total  ablation energy (focea) sent to the ocean
-         qfvbq_1d(ji)  = qfvbq_1d(ji) + fsup(ji) + ( 1.0 - zihgnew ) * focea(ji) * a_i_b(ji) * rdt_ice
-
-         zihic   = 1.0 - MAX(  zzero , SIGN( zone , -ht_i_b(ji) )  )      ! equals 0 if ht_i = 0, 1 if ht_i gt 0
-         fscbq_1d(ji) =  a_i_b(ji) * fstbif_1d(ji)
-         qldif_1d(ji)  = qldif_1d(ji) + fsup(ji) + ( 1.0 - zihgnew ) * focea   (ji) * a_i_b(ji) * rdt_ice   &
-            &                                    + ( 1.0 - zihic   ) * fscbq_1d(ji)             * rdt_ice
-      END DO  ! ji
-
-      !-------------------------------------------
-      ! Correct temperature, energy and thickness
-      !-------------------------------------------
-      DO ji = kideb, kiut
-         zihgnew    =  1.0 - MAX( zzero , SIGN( zone , - zhgnew(ji) ) ) 
-         t_su_b(ji) =  zihgnew * t_su_b(ji) + ( 1.0 - zihgnew ) * rtt
-      END DO  ! ji
-
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            zihgnew      =  1.0 - MAX( zzero , SIGN( zone , - zhgnew(ji) ) ) 
-            t_i_b(ji,jk) =  zihgnew * t_i_b(ji,jk) + ( 1.0 - zihgnew ) * rtt
-            q_i_b(ji,jk) =  zihgnew * q_i_b(ji,jk)
-         END DO
-      END DO  ! ji
-
-      DO ji = kideb, kiut
-         ht_i_b(ji) = zhgnew(ji)
-      END DO  ! ji
+      ! ??? keep ???
+      ! clem bug: I think this should be included above, so we would not have to 
+      !           track heat/salt/mass fluxes backwards
+!      IF( jpl == 1 ) THEN
+!         DO ji = kideb, kiut
+!            IF(  zf_tt(ji)  >=  0._wp  ) THEN
+!               zdh            = MAX( hmelt , dh_i_bott(ji) )
+!               zdvres         = zdh - dh_i_bott(ji) ! >=0
+!               dh_i_bott(ji)  = zdh
+!
+!               ! excessive energy is sent to lateral ablation
+!               zinda = MAX( 0._wp, SIGN( 1._wp , 1._wp - at_i_1d(ji) - epsi20 ) )
+!               zq_1cat(ji) =  zinda * rhoic * lfus * at_i_1d(ji) / MAX( 1._wp - at_i_1d(ji) , epsi20 ) * zdvres ! J.m-2 >=0
+!
+!               ! correct salt and mass fluxes
+!               sfx_bom_1d(ji) = sfx_bom_1d(ji) - sm_i_1d(ji) * a_i_1d(ji) * zdvres * rhoic * r1_rdtice ! this is only a raw approximation
+!               wfx_bom_1d(ji) = wfx_bom_1d(ji) - rhoic * a_i_1d(ji) * zdvres * r1_rdtice
+!            ENDIF
+!         END DO
+!      ENDIF
+
+      !-------------------------------------------
+      ! Update temperature, energy
+      !-------------------------------------------
+      DO ji = kideb, kiut
+         ht_i_1d(ji) =  MAX( 0._wp , ht_i_1d(ji) + dh_i_bott(ji) )
+      END DO  
+
+      !-------------------------------------------
+      ! 5. What to do with remaining energy
+      !-------------------------------------------
+      ! If heat still available for melting and snow remains, then melt more snow
+      !-------------------------------------------
+      zdeltah(:,:) = 0._wp ! important
+      DO ji = kideb, kiut
+         zq_rema(ji)     = zq_su(ji) + zq_bo(ji) 
+!         zindh           = 1._wp - MAX( 0._wp, SIGN( 1._wp, - ht_s_1d(ji) ) )   ! =1 if snow
+!         zindq           = 1._wp - MAX( 0._wp, SIGN( 1._wp, - zq_s(ji) + epsi20 ) )
+!         zdeltah  (ji,1) = - zindh * zindq * zq_rema(ji) / MAX( zq_s(ji), epsi20 )
+!         zdeltah  (ji,1) = MIN( 0._wp , MAX( zdeltah(ji,1) , - ht_s_1d(ji) ) ) ! bound melting
+!         zdh_s_mel(ji)   = zdh_s_mel(ji) + zdeltah(ji,1)    
+!         dh_s_tot (ji)   = dh_s_tot(ji) + zdeltah(ji,1)
+!         ht_s_1d   (ji)   = ht_s_1d(ji)   + zdeltah(ji,1)
+!        
+!         zq_rema(ji)     = zq_rema(ji) + zdeltah(ji,1) * zq_s(ji)                ! update available heat (J.m-2)
+!         ! heat used to melt snow
+!         hfx_snw_1d(ji)  = hfx_snw_1d(ji) - zdeltah(ji,1) * a_i_1d(ji) * zq_s(ji) * r1_rdtice ! W.m-2 (>0)
+!         ! Contribution to mass flux
+!         wfx_snw_1d(ji)  =  wfx_snw_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,1) * r1_rdtice
+!    
+         ii = MOD( npb(ji) - 1, jpi ) + 1 ; ij = ( npb(ji) - 1 ) / jpi + 1
+         ! Remaining heat flux (W.m-2) is sent to the ocean heat budget
+         hfx_out(ii,ij)  = hfx_out(ii,ij) + ( zq_1cat(ji) + zq_rema(ji) * a_i_1d(ji) ) * r1_rdtice
+
+         IF( ln_nicep .AND. zq_rema(ji) < 0. .AND. lwp ) WRITE(numout,*) 'ALERTE zq_rema <0 = ', zq_rema(ji)
+      END DO
+      
       !
       !------------------------------------------------------------------------------|
@@ -670,63 +657,78 @@
       DO ji = kideb, kiut
          !
-         dh_snowice(ji) = MAX(  zzero , ( rhosn * ht_s_b(ji) + (rhoic-rau0) * ht_i_b(ji) ) / ( rhosn+rau0-rhoic )  )
-         zhgnew(ji)     = MAX(  zhgnew(ji) , zhgnew(ji) + dh_snowice(ji)  )
-         zhnnew         = MIN(  ht_s_b(ji) , ht_s_b(ji) - dh_snowice(ji)  )
-
-         !  Changes in ice volume and ice mass.
-         dvnbq_1d  (ji) =                a_i_b(ji) * ( zhgnew(ji)-ht_i_b(ji) )
-         dmgwi_1d  (ji) = dmgwi_1d(ji) + a_i_b(ji) * ( ht_s_b(ji) - zhnnew ) * rhosn
-
-         !clem rdm_ice_1d(ji) = rdm_ice_1d(ji) + a_i_b(ji) * ( zhgnew(ji) - ht_i_b(ji) ) * rhoic 
-         !clem rdm_snw_1d(ji) = rdm_snw_1d(ji) + a_i_b(ji) * ( zhnnew     - ht_s_b(ji) ) * rhosn 
-
-         !        Equivalent salt flux (1) Snow-ice formation component
-         !        -----------------------------------------------------
-         ii = MOD( npb(ji) - 1, jpi ) + 1
-         ij =    ( npb(ji) - 1 ) / jpi + 1
-
-         IF( num_sal == 2 ) THEN   ;   zsm_snowice = sss_m(ii,ij) * ( rhoic - rhosn ) / rhoic
-         ELSE                      ;   zsm_snowice = sm_i_b(ji)   
-         ENDIF
+         dh_snowice(ji) = MAX(  0._wp , ( rhosn * ht_s_1d(ji) + (rhoic-rau0) * ht_i_1d(ji) ) / ( rhosn+rau0-rhoic )  )
+
+         ht_i_1d(ji)     = ht_i_1d(ji) + dh_snowice(ji)
+         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 ) / rhoic + ( 1. - zswitch_sal ) * sm_i_1d(ji)
+
          ! entrapment during snow ice formation
-         ! clem: new salinity difference stored (to be used in limthd_ent.F90)
+         ! new salinity difference stored (to be used in limthd_ent.F90)
          IF (  num_sal == 2  ) THEN
-            i_ice_switch = MAX( 0._wp , SIGN( 1._wp , zhgnew(ji) - epsi10 ) )
+            zswitch = MAX( 0._wp , SIGN( 1._wp , ht_i_1d(ji) - epsi10 ) )
             ! salinity dif due to snow-ice formation
-            dsm_i_si_1d(ji) = ( zsm_snowice - sm_i_b(ji) ) * dh_snowice(ji) / MAX( zhgnew(ji), epsi10 ) * i_ice_switch     
+            dsm_i_si_1d(ji) = ( zs_snic - sm_i_1d(ji) ) * dh_snowice(ji) / MAX( ht_i_1d(ji), epsi10 ) * zswitch     
             ! salinity dif due to bottom growth 
-            IF (  fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji)  < 0._wp ) THEN
-               dsm_i_se_1d(ji) = ( s_i_new(ji) - sm_i_b(ji) ) * dh_i_bott(ji) / MAX( zhgnew(ji), epsi10 ) * i_ice_switch
+            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), epsi10 ) * zswitch
             ENDIF
          ENDIF
 
-         !  Actualize new snow and ice thickness.
-         ht_s_b(ji)  = zhnnew
-         ht_i_b(ji)  = zhgnew(ji)
-
-         ! Total ablation ! new lines added to debug
-         IF( ht_i_b(ji) <= 0._wp )   a_i_b(ji) = 0._wp
-
-         ! diagnostic ( snow ice growth )
-         ii = MOD( npb(ji) - 1, jpi ) + 1
-         ij =    ( npb(ji) - 1 ) / jpi + 1
-         diag_sni_gr(ii,ij)  = diag_sni_gr(ii,ij) + dh_snowice(ji)*a_i_b(ji) * r1_rdtice
-         !
-         ! salt flux
-         sfx_thd_1d(ji) = sfx_thd_1d(ji) - zsm_snowice * a_i_b(ji) * dh_snowice(ji) * rhoic * r1_rdtice
-         !--------------------------------
-         ! Update mass fluxes (clem)
-         !--------------------------------
-         rdm_ice_1d(ji) = rdm_ice_1d(ji) + ( a_i_b(ji) * ht_i_b(ji) - zviold(ji) ) * rhoic 
-         rdm_snw_1d(ji) = rdm_snw_1d(ji) + ( a_i_b(ji) * ht_s_b(ji) - zvsold(ji) ) * rhosn 
+         ! 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
+         zsstK          = sst_m(ii,ij) + rt0                                
+         zEw            = rcp * ( zsstK - rt0 )
+         zQm            = zfmdt * zEw 
+         
+         ! Contribution to heat flux
+         hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice 
+
+         ! Contribution to salt flux
+         sfx_sni_1d(ji) = sfx_sni_1d(ji) + sss_m(ii,ij) * a_i_1d(ji) * zfmdt * r1_rdtice 
+          
+         ! Contribution to mass flux
+         ! All snow is thrown in the ocean, and seawater is taken to replace the volume
+         wfx_sni_1d(ji) = wfx_sni_1d(ji) - a_i_1d(ji) * dh_snowice(ji) * rhoic * r1_rdtice
+         wfx_snw_1d(ji) = wfx_snw_1d(ji) + a_i_1d(ji) * dh_snowice(ji) * rhosn * r1_rdtice
+
+         ! update heat content (J.m-2) and layer thickness
+         qh_i_old(ji,0) = qh_i_old(ji,0) + dh_snowice(ji) * q_s_1d(ji,1) + zfmdt * zEw
+         h_i_old (ji,0) = h_i_old (ji,0) + dh_snowice(ji)
+         
+         ! Total ablation (to debug)
+         IF( ht_i_1d(ji) <= 0._wp )   a_i_1d(ji) = 0._wp
 
       END DO !ji
-      !
-      CALL wrk_dealloc( jpij, zh_i, zh_s, ztfs, zhsold, zqprec, zqfont_su, zqfont_bo, z_f_surf, zhgnew, zfmass_i )
-      CALL wrk_dealloc( jpij, zdh_s_mel, zdh_s_pre, zdh_s_sub, zfdt_init, zfdt_final, zqt_i, zqt_s, zqt_dummy )
-      CALL wrk_dealloc( jpij, zinnermelt, zfbase, zdq_i )
-      CALL wrk_dealloc( jpij, jkmax, zdeltah, zqt_i_lay )
-      !
-      CALL wrk_dealloc( jpij, zviold, zvsold ) ! clem
+
+      !
+      !-------------------------------------------
+      ! Update temperature, energy
+      !-------------------------------------------
+      !clem bug: we should take snow into account here
+      DO ji = kideb, kiut
+         zindh    =  1.0 - MAX( 0._wp , SIGN( 1._wp , - ht_i_1d(ji) ) ) 
+         t_su_1d(ji) =  zindh * t_su_1d(ji) + ( 1.0 - zindh ) * rtt
+      END DO  ! ji
+
+      DO jk = 1, nlay_s
+         DO ji = kideb,kiut
+            ! mask enthalpy
+            zinda        =  MAX(  0._wp , SIGN( 1._wp, - ht_s_1d(ji) )  )
+            q_s_1d(ji,jk) = ( 1.0 - zinda ) * q_s_1d(ji,jk)
+            ! recalculate t_s_1d from q_s_1d
+            t_s_1d(ji,jk) = rtt + ( 1._wp - zinda ) * ( - q_s_1d(ji,jk) / ( rhosn * cpic ) + lfus / cpic )
+         END DO
+      END DO
+
+      CALL wrk_dealloc( jpij, zh_s, zqprec, zq_su, zq_bo, zf_tt, zq_1cat, zq_rema )
+      CALL wrk_dealloc( jpij, zdh_s_mel, zdh_s_pre, zdh_s_sub, zqh_i, zqh_s, zq_s )
+      CALL wrk_dealloc( jpij, zintermelt )
+      CALL wrk_dealloc( jpij, nlay_i+1, zdeltah, zh_i )
+      CALL wrk_dealloc( jpij, icount )
+      !
       !
    END SUBROUTINE lim_thd_dh
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90	(revision 4921)
@@ -25,4 +25,5 @@
    USE wrk_nemo       ! work arrays
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE cpl_oasis3, ONLY : lk_cpl
 
    IMPLICIT NONE
@@ -31,5 +32,5 @@
    PUBLIC   lim_thd_dif   ! called by lim_thd
 
-   REAL(wp) ::   epsi10      =  1.e-10_wp    !
+   REAL(wp) ::   epsi10 = 1.e-10_wp    !
    !!----------------------------------------------------------------------
    !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
@@ -39,5 +40,5 @@
 CONTAINS
 
-   SUBROUTINE lim_thd_dif( kideb , kiut , jl )
+   SUBROUTINE lim_thd_dif( kideb , kiut )
       !!------------------------------------------------------------------
       !!                ***  ROUTINE lim_thd_dif  ***
@@ -74,10 +75,10 @@
       !!
       !! ** Inputs / Ouputs : (global commons)
-      !!           surface temperature : t_su_b
-      !!           ice/snow temperatures   : t_i_b, t_s_b
-      !!           ice salinities          : s_i_b
+      !!           surface temperature : t_su_1d
+      !!           ice/snow temperatures   : t_i_1d, t_s_1d
+      !!           ice salinities          : s_i_1d
       !!           number of layers in the ice/snow: nlay_i, nlay_s
       !!           profile of the ice/snow layers : z_i, z_s
-      !!           total ice/snow thickness : ht_i_b, ht_s_b
+      !!           total ice/snow thickness : ht_i_1d, ht_s_1d
       !!
       !! ** External : 
@@ -91,7 +92,5 @@
       !!           (04-2007) Energy conservation tested by M. Vancoppenolle
       !!------------------------------------------------------------------
-      INTEGER , INTENT (in) ::   kideb   ! Start point on which the  the computation is applied
-      INTEGER , INTENT (in) ::   kiut    ! End point on which the  the computation is applied
-      INTEGER , INTENT (in) ::   jl      ! Category number
+      INTEGER , INTENT(in) ::   kideb, kiut   ! Start/End point on which the  the computation is applied
 
       !! * Local variables
@@ -99,10 +98,10 @@
       INTEGER ::   ii, ij      ! temporary dummy loop index
       INTEGER ::   numeq       ! current reference number of equation
-      INTEGER ::   layer       ! vertical dummy loop index 
+      INTEGER ::   jk       ! vertical dummy loop index 
       INTEGER ::   nconv       ! number of iterations in iterative procedure
       INTEGER ::   minnumeqmin, maxnumeqmax
-      INTEGER, DIMENSION(kiut) ::   numeqmin   ! reference number of top equation
-      INTEGER, DIMENSION(kiut) ::   numeqmax   ! reference number of bottom equation
-      INTEGER, DIMENSION(kiut) ::   isnow      ! switch for presence (1) or absence (0) of snow
+      INTEGER, POINTER, DIMENSION(:) ::   numeqmin   ! reference number of top equation
+      INTEGER, POINTER, DIMENSION(:) ::   numeqmax   ! reference number of bottom equation
+      INTEGER, POINTER, DIMENSION(:) ::   isnow      ! switch for presence (1) or absence (0) of snow
       REAL(wp) ::   zg1s      =  2._wp        ! for the tridiagonal system
       REAL(wp) ::   zg1       =  2._wp        !
@@ -111,53 +110,73 @@
       REAL(wp) ::   zraext_s  =  1.e+8_wp     ! extinction coefficient of radiation in the snow
       REAL(wp) ::   zkimin    =  0.10_wp      ! minimum ice thermal conductivity
+      REAL(wp) ::   ztsu_err  =  1.e-5_wp     ! range around which t_su is considered as 0°C 
       REAL(wp) ::   ztmelt_i    ! ice melting temperature
       REAL(wp) ::   zerritmax   ! current maximal error on temperature 
-      REAL(wp), DIMENSION(kiut) ::   ztfs        ! ice melting point
-      REAL(wp), DIMENSION(kiut) ::   ztsuold     ! old surface temperature (before the iterative procedure )
-      REAL(wp), DIMENSION(kiut) ::   ztsuoldit   ! surface temperature at previous iteration
-      REAL(wp), DIMENSION(kiut) ::   zh_i        ! ice layer thickness
-      REAL(wp), DIMENSION(kiut) ::   zh_s        ! snow layer thickness
-      REAL(wp), DIMENSION(kiut) ::   zfsw        ! solar radiation absorbed at the surface
-      REAL(wp), DIMENSION(kiut) ::   zf          ! surface flux function
-      REAL(wp), DIMENSION(kiut) ::   dzf         ! derivative of the surface flux function
-      REAL(wp), DIMENSION(kiut) ::   zerrit      ! current error on temperature
-      REAL(wp), DIMENSION(kiut) ::   zdifcase    ! case of the equation resolution (1->4)
-      REAL(wp), DIMENSION(kiut) ::   zftrice     ! solar radiation transmitted through the ice
-      REAL(wp), DIMENSION(kiut) ::   zihic, zhsu
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   ztcond_i    ! Ice thermal conductivity
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zradtr_i    ! Radiation transmitted through the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zradab_i    ! Radiation absorbed in the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zkappa_i    ! Kappa factor in the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   ztiold      ! Old temperature in the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zeta_i      ! Eta factor in the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   ztitemp     ! Temporary temperature in the ice to check the convergence
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zspeche_i   ! Ice specific heat
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   z_i         ! Vertical cotes of the layers in the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zradtr_s    ! Radiation transmited through the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zradab_s    ! Radiation absorbed in the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zkappa_s    ! Kappa factor in the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zeta_s       ! Eta factor in the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   ztstemp      ! Temporary temperature in the snow to check the convergence
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   ztsold       ! Temporary temperature in the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   z_s          ! Vertical cotes of the layers in the snow
-      REAL(wp), DIMENSION(kiut,jkmax+2) ::   zindterm   ! Independent term
-      REAL(wp), DIMENSION(kiut,jkmax+2) ::   zindtbis   ! temporary independent term
-      REAL(wp), DIMENSION(kiut,jkmax+2) ::   zdiagbis
-      REAL(wp), DIMENSION(kiut,jkmax+2,3) ::   ztrid   ! tridiagonal system terms
+      REAL(wp), POINTER, DIMENSION(:) ::   ztfs        ! ice melting point
+      REAL(wp), POINTER, DIMENSION(:) ::   ztsub       ! old surface temperature (before the iterative procedure )
+      REAL(wp), POINTER, DIMENSION(:) ::   ztsubit     ! surface temperature at previous iteration
+      REAL(wp), POINTER, DIMENSION(:) ::   zh_i        ! ice layer thickness
+      REAL(wp), POINTER, DIMENSION(:) ::   zh_s        ! snow layer thickness
+      REAL(wp), POINTER, DIMENSION(:) ::   zfsw        ! solar radiation absorbed at the surface
+      REAL(wp), POINTER, DIMENSION(:) ::   zf          ! surface flux function
+      REAL(wp), POINTER, DIMENSION(:) ::   dzf         ! derivative of the surface flux function
+      REAL(wp), POINTER, DIMENSION(:) ::   zerrit      ! current error on temperature
+      REAL(wp), POINTER, DIMENSION(:) ::   zdifcase    ! case of the equation resolution (1->4)
+      REAL(wp), POINTER, DIMENSION(:) ::   zftrice     ! solar radiation transmitted through the ice
+      REAL(wp), POINTER, DIMENSION(:) ::   zihic, zhsu
+      REAL(wp), POINTER, DIMENSION(:,:) ::   ztcond_i    ! Ice thermal conductivity
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zradtr_i    ! Radiation transmitted through the ice
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zradab_i    ! Radiation absorbed in the ice
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zkappa_i    ! Kappa factor in the ice
+      REAL(wp), POINTER, DIMENSION(:,:) ::   ztib        ! Old temperature in the ice
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zeta_i      ! Eta factor in the ice
+      REAL(wp), POINTER, DIMENSION(:,:) ::   ztitemp     ! Temporary temperature in the ice to check the convergence
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zspeche_i   ! Ice specific heat
+      REAL(wp), POINTER, DIMENSION(:,:) ::   z_i         ! Vertical cotes of the layers in the ice
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zradtr_s    ! Radiation transmited through the snow
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zradab_s    ! Radiation absorbed in the snow
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zkappa_s    ! Kappa factor in the snow
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zeta_s      ! Eta factor in the snow
+      REAL(wp), POINTER, DIMENSION(:,:) ::   ztstemp     ! Temporary temperature in the snow to check the convergence
+      REAL(wp), POINTER, DIMENSION(:,:) ::   ztsb        ! Temporary temperature in the snow
+      REAL(wp), POINTER, DIMENSION(:,:) ::   z_s         ! Vertical cotes of the layers in the snow
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zindterm    ! Independent term
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zindtbis    ! temporary independent term
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zdiagbis
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrid     ! tridiagonal system terms
+      ! diag errors on heat
+      REAL(wp), POINTER, DIMENSION(:) :: zdq, zq_ini
+      REAL(wp)                        :: zhfx_err
       !!------------------------------------------------------------------     
       ! 
+      CALL wrk_alloc( jpij, numeqmin, numeqmax, isnow )
+      CALL wrk_alloc( jpij, ztfs, ztsub, ztsubit, zh_i, zh_s, zfsw )
+      CALL wrk_alloc( jpij, zf, dzf, zerrit, zdifcase, zftrice, zihic, zhsu )
+      CALL wrk_alloc( jpij, nlay_i+1, ztcond_i, zradtr_i, zradab_i, zkappa_i, ztib, zeta_i, ztitemp, z_i, zspeche_i, kjstart=0)
+      CALL wrk_alloc( jpij, nlay_s+1,           zradtr_s, zradab_s, zkappa_s, ztsb, zeta_s, ztstemp, z_s, kjstart=0)
+      CALL wrk_alloc( jpij, nlay_i+3, zindterm, zindtbis, zdiagbis  )
+      CALL wrk_alloc( jpij, nlay_i+3, 3, ztrid )
+
+      CALL wrk_alloc( jpij, zdq, zq_ini )
+
+      ! --- diag error on heat diffusion - PART 1 --- !
+      zdq(:) = 0._wp ; zq_ini(:) = 0._wp      
+      DO ji = kideb, kiut
+         zq_ini(ji) = ( SUM( q_i_1d(ji,1:nlay_i) ) * ht_i_1d(ji) / REAL( nlay_i ) +  &
+            &           SUM( q_s_1d(ji,1:nlay_s) ) * ht_s_1d(ji) / REAL( nlay_s ) ) 
+      END DO
+
       !------------------------------------------------------------------------------!
       ! 1) Initialization                                                            !
       !------------------------------------------------------------------------------!
-      !
+      ! clem clean: replace just ztfs by rtt
       DO ji = kideb , kiut
          ! is there snow or not
-         isnow(ji)= NINT(  1._wp - MAX( 0._wp , SIGN(1._wp, - ht_s_b(ji) ) )  )
+         isnow(ji)= NINT(  1._wp - MAX( 0._wp , SIGN(1._wp, - ht_s_1d(ji) ) )  )
          ! surface temperature of fusion
-!!gm ???  ztfs(ji) = rtt !!!????
          ztfs(ji) = REAL( isnow(ji) ) * rtt + REAL( 1 - isnow(ji) ) * rtt
          ! layer thickness
-         zh_i(ji) = ht_i_b(ji) / REAL( nlay_i )
-         zh_s(ji) = ht_s_b(ji) / REAL( nlay_s )
+         zh_i(ji) = ht_i_1d(ji) / REAL( nlay_i )
+         zh_s(ji) = ht_s_1d(ji) / REAL( nlay_s )
       END DO
 
@@ -169,13 +188,13 @@
       z_i(:,0) = 0._wp   ! vert. coord. of the up. lim. of the 1st ice layer
 
-      DO layer = 1, nlay_s            ! vert. coord of the up. lim. of the layer-th snow layer
-         DO ji = kideb , kiut
-            z_s(ji,layer) = z_s(ji,layer-1) + ht_s_b(ji) / REAL( nlay_s )
-         END DO
-      END DO
-
-      DO layer = 1, nlay_i            ! vert. coord of the up. lim. of the layer-th ice layer
-         DO ji = kideb , kiut
-            z_i(ji,layer) = z_i(ji,layer-1) + ht_i_b(ji) / REAL( nlay_i )
+      DO jk = 1, nlay_s            ! vert. coord of the up. lim. of the layer-th snow layer
+         DO ji = kideb , kiut
+            z_s(ji,jk) = z_s(ji,jk-1) + ht_s_1d(ji) / REAL( nlay_s )
+         END DO
+      END DO
+
+      DO jk = 1, nlay_i            ! vert. coord of the up. lim. of the layer-th ice layer
+         DO ji = kideb , kiut
+            z_i(ji,jk) = z_i(ji,jk-1) + ht_i_1d(ji) / REAL( nlay_i )
          END DO
       END DO
@@ -194,12 +213,12 @@
       ! zfsw    = (1-i0).qsr_ice   is absorbed at the surface 
       ! zftrice = io.qsr_ice       is below the surface 
-      ! fstbif  = io.qsr_ice.exp(-k(h_i)) transmitted below the ice 
+      ! ftr_ice = io.qsr_ice.exp(-k(h_i)) transmitted below the ice 
 
       DO ji = kideb , kiut
          ! switches
-         isnow(ji) = NINT(  1._wp - MAX( 0._wp , SIGN( 1._wp , - ht_s_b(ji) ) )  ) 
+         isnow(ji) = NINT(  1._wp - MAX( 0._wp , SIGN( 1._wp , - ht_s_1d(ji) ) )  ) 
          ! hs > 0, isnow = 1
          zhsu (ji) = hnzst  ! threshold for the computation of i0
-         zihic(ji) = MAX( 0._wp , 1._wp - ( ht_i_b(ji) / zhsu(ji) ) )     
+         zihic(ji) = MAX( 0._wp , 1._wp - ( ht_i_1d(ji) / zhsu(ji) ) )     
 
          i0(ji)    = REAL( 1 - isnow(ji) ) * ( fr1_i0_1d(ji) + zihic(ji) * fr2_i0_1d(ji) )
@@ -208,5 +227,5 @@
          !            a function of the cloud cover
          !
-         !i0(ji)     =  (1.0-FLOAT(isnow(ji)))*3.0/(100*ht_s_b(ji)+10.0)
+         !i0(ji)     =  (1.0-FLOAT(isnow(ji)))*3.0/(100*ht_s_1d(ji)+10.0)
          !formula used in Cice
       END DO
@@ -230,10 +249,10 @@
       END DO
 
-      DO layer = 1, nlay_s          ! Radiation through snow
+      DO jk = 1, nlay_s          ! Radiation through snow
          DO ji = kideb, kiut
             !                             ! radiation transmitted below the layer-th snow layer
-            zradtr_s(ji,layer) = zradtr_s(ji,0) * EXP( - zraext_s * ( MAX ( 0._wp , z_s(ji,layer) ) ) )
+            zradtr_s(ji,jk) = zradtr_s(ji,0) * EXP( - zraext_s * ( MAX ( 0._wp , z_s(ji,jk) ) ) )
             !                             ! radiation absorbed by the layer-th snow layer
-            zradab_s(ji,layer) = zradtr_s(ji,layer-1) - zradtr_s(ji,layer)
+            zradab_s(ji,jk) = zradtr_s(ji,jk-1) - zradtr_s(ji,jk)
          END DO
       END DO
@@ -243,30 +262,16 @@
       END DO
 
-      DO layer = 1, nlay_i          ! Radiation through ice
+      DO jk = 1, nlay_i          ! Radiation through ice
          DO ji = kideb, kiut
             !                             ! radiation transmitted below the layer-th ice layer
-            zradtr_i(ji,layer) = zradtr_i(ji,0) * EXP( - kappa_i * ( MAX ( 0._wp , z_i(ji,layer) ) ) )
+            zradtr_i(ji,jk) = zradtr_i(ji,0) * EXP( - kappa_i * ( MAX ( 0._wp , z_i(ji,jk) ) ) )
             !                             ! radiation absorbed by the layer-th ice layer
-            zradab_i(ji,layer) = zradtr_i(ji,layer-1) - zradtr_i(ji,layer)
+            zradab_i(ji,jk) = zradtr_i(ji,jk-1) - zradtr_i(ji,jk)
          END DO
       END DO
 
       DO ji = kideb, kiut           ! Radiation transmitted below the ice
-         fstbif_1d(ji) = fstbif_1d(ji) + iatte_1d(ji) * zradtr_i(ji,nlay_i) * a_i_b(ji) / at_i_b(ji) ! clem modif
-      END DO
-
-      ! +++++
-      ! just to check energy conservation
-      DO ji = kideb, kiut
-         ii = MOD( npb(ji) - 1 , jpi ) + 1
-         ij =    ( npb(ji) - 1 ) / jpi + 1
-         fstroc(ii,ij,jl) = iatte_1d(ji) * zradtr_i(ji,nlay_i) ! clem modif
-      END DO
-      ! +++++
-
-      DO layer = 1, nlay_i
-         DO ji = kideb, kiut
-            radab(ji,layer) = zradab_i(ji,layer)
-         END DO
+         !!!ftr_ice_1d(ji) = ftr_ice_1d(ji) + iatte_1d(ji) * zradtr_i(ji,nlay_i) * a_i_1d(ji) / at_i_1d(ji) ! clem modif
+         ftr_ice_1d(ji) = zradtr_i(ji,nlay_i) 
       END DO
 
@@ -277,19 +282,19 @@
       !
       DO ji = kideb, kiut        ! Old surface temperature
-         ztsuold  (ji) =  t_su_b(ji)                              ! temperature at the beg of iter pr.
-         ztsuoldit(ji) =  t_su_b(ji)                              ! temperature at the previous iter
-         t_su_b   (ji) =  MIN( t_su_b(ji), ztfs(ji)-0.00001 )     ! necessary
+         ztsub  (ji) =  t_su_1d(ji)                              ! temperature at the beg of iter pr.
+         ztsubit(ji) =  t_su_1d(ji)                              ! temperature at the previous iter
+         t_su_1d   (ji) =  MIN( t_su_1d(ji), ztfs(ji) - ztsu_err )  ! necessary
          zerrit   (ji) =  1000._wp                                ! initial value of error
       END DO
 
-      DO layer = 1, nlay_s       ! Old snow temperature
-         DO ji = kideb , kiut
-            ztsold(ji,layer) =  t_s_b(ji,layer)
-         END DO
-      END DO
-
-      DO layer = 1, nlay_i       ! Old ice temperature
-         DO ji = kideb , kiut
-            ztiold(ji,layer) =  t_i_b(ji,layer)
+      DO jk = 1, nlay_s       ! Old snow temperature
+         DO ji = kideb , kiut
+            ztsb(ji,jk) =  t_s_1d(ji,jk)
+         END DO
+      END DO
+
+      DO jk = 1, nlay_i       ! Old ice temperature
+         DO ji = kideb , kiut
+            ztib(ji,jk) =  t_i_1d(ji,jk)
          END DO
       END DO
@@ -308,12 +313,12 @@
          IF( thcon_i_swi == 0 ) THEN      ! Untersteiner (1964) formula
             DO ji = kideb , kiut
-               ztcond_i(ji,0)        = rcdic + zbeta*s_i_b(ji,1) / MIN(-epsi10,t_i_b(ji,1)-rtt)
+               ztcond_i(ji,0)        = rcdic + zbeta*s_i_1d(ji,1) / MIN(-epsi10,t_i_1d(ji,1)-rtt)
                ztcond_i(ji,0)        = MAX(ztcond_i(ji,0),zkimin)
             END DO
-            DO layer = 1, nlay_i-1
+            DO jk = 1, nlay_i-1
                DO ji = kideb , kiut
-                  ztcond_i(ji,layer) = rcdic + zbeta*( s_i_b(ji,layer) + s_i_b(ji,layer+1) ) /  &
-                     MIN(-2.0_wp * epsi10, t_i_b(ji,layer)+t_i_b(ji,layer+1) - 2.0_wp * rtt)
-                  ztcond_i(ji,layer) = MAX(ztcond_i(ji,layer),zkimin)
+                  ztcond_i(ji,jk) = rcdic + zbeta*( s_i_1d(ji,jk) + s_i_1d(ji,jk+1) ) /  &
+                     MIN(-2.0_wp * epsi10, t_i_1d(ji,jk)+t_i_1d(ji,jk+1) - 2.0_wp * rtt)
+                  ztcond_i(ji,jk) = MAX(ztcond_i(ji,jk),zkimin)
                END DO
             END DO
@@ -322,19 +327,20 @@
          IF( thcon_i_swi == 1 ) THEN      ! Pringle et al formula included: 2.11 + 0.09 S/T - 0.011.T
             DO ji = kideb , kiut
-               ztcond_i(ji,0) = rcdic + 0.090_wp * s_i_b(ji,1) / MIN( -epsi10, t_i_b(ji,1)-rtt )   &
-                  &                   - 0.011_wp * ( t_i_b(ji,1) - rtt )  
+               ztcond_i(ji,0) = rcdic + 0.090_wp * s_i_1d(ji,1) / MIN( -epsi10, t_i_1d(ji,1)-rtt )   &
+                  &                   - 0.011_wp * ( t_i_1d(ji,1) - rtt )  
                ztcond_i(ji,0) = MAX( ztcond_i(ji,0), zkimin )
             END DO
-            DO layer = 1, nlay_i-1
+            DO jk = 1, nlay_i-1
                DO ji = kideb , kiut
-                  ztcond_i(ji,layer) = rcdic + 0.090_wp * ( s_i_b(ji,layer) + s_i_b(ji,layer+1) )   &
-                     &                                  / MIN(-2.0_wp * epsi10, t_i_b(ji,layer)+t_i_b(ji,layer+1) - 2.0_wp * rtt)   &
-                     &                       - 0.0055_wp* ( t_i_b(ji,layer) + t_i_b(ji,layer+1) - 2.0*rtt )  
-                  ztcond_i(ji,layer) = MAX( ztcond_i(ji,layer), zkimin )
+                  ztcond_i(ji,jk) = rcdic +                                                                     & 
+                     &                 0.090_wp * ( s_i_1d(ji,jk) + s_i_1d(ji,jk+1) )                          &
+                     &                 / MIN(-2.0_wp * epsi10, t_i_1d(ji,jk)+t_i_1d(ji,jk+1) - 2.0_wp * rtt)   &
+                     &               - 0.0055_wp* ( t_i_1d(ji,jk) + t_i_1d(ji,jk+1) - 2.0*rtt )  
+                  ztcond_i(ji,jk) = MAX( ztcond_i(ji,jk), zkimin )
                END DO
             END DO
             DO ji = kideb , kiut
-               ztcond_i(ji,nlay_i) = rcdic + 0.090_wp * s_i_b(ji,nlay_i) / MIN(-epsi10,t_bo_b(ji)-rtt)   &
-                  &                        - 0.011_wp * ( t_bo_b(ji) - rtt )  
+               ztcond_i(ji,nlay_i) = rcdic + 0.090_wp * s_i_1d(ji,nlay_i) / MIN(-epsi10,t_bo_1d(ji)-rtt)   &
+                  &                        - 0.011_wp * ( t_bo_1d(ji) - rtt )  
                ztcond_i(ji,nlay_i) = MAX( ztcond_i(ji,nlay_i), zkimin )
             END DO
@@ -352,15 +358,15 @@
          END DO
 
-         DO layer = 1, nlay_s-1
-            DO ji = kideb , kiut
-               zkappa_s(ji,layer)  = 2.0 * rcdsn / &
+         DO jk = 1, nlay_s-1
+            DO ji = kideb , kiut
+               zkappa_s(ji,jk)  = 2.0 * rcdsn / &
                   MAX(epsi10,2.0*zh_s(ji))
             END DO
          END DO
 
-         DO layer = 1, nlay_i-1
+         DO jk = 1, nlay_i-1
             DO ji = kideb , kiut
                !-- Ice kappa factors
-               zkappa_i(ji,layer)  = 2.0*ztcond_i(ji,layer)/ &
+               zkappa_i(ji,jk)  = 2.0*ztcond_i(ji,jk)/ &
                   MAX(epsi10,2.0*zh_i(ji)) 
             END DO
@@ -381,18 +387,18 @@
          !------------------------------------------------------------------------------|
          !
-         DO layer = 1, nlay_i
-            DO ji = kideb , kiut
-               ztitemp(ji,layer)   = t_i_b(ji,layer)
-               zspeche_i(ji,layer) = cpic + zgamma*s_i_b(ji,layer)/ &
-                  MAX((t_i_b(ji,layer)-rtt)*(ztiold(ji,layer)-rtt),epsi10)
-               zeta_i(ji,layer)    = rdt_ice / MAX(rhoic*zspeche_i(ji,layer)*zh_i(ji), &
+         DO jk = 1, nlay_i
+            DO ji = kideb , kiut
+               ztitemp(ji,jk)   = t_i_1d(ji,jk)
+               zspeche_i(ji,jk) = cpic + zgamma*s_i_1d(ji,jk)/ &
+                  MAX((t_i_1d(ji,jk)-rtt)*(ztib(ji,jk)-rtt),epsi10)
+               zeta_i(ji,jk)    = rdt_ice / MAX(rhoic*zspeche_i(ji,jk)*zh_i(ji), &
                   epsi10)
             END DO
          END DO
 
-         DO layer = 1, nlay_s
-            DO ji = kideb , kiut
-               ztstemp(ji,layer) = t_s_b(ji,layer)
-               zeta_s(ji,layer)  = rdt_ice / MAX(rhosn*cpic*zh_s(ji),epsi10)
+         DO jk = 1, nlay_s
+            DO ji = kideb , kiut
+               ztstemp(ji,jk) = t_s_1d(ji,jk)
+               zeta_s(ji,jk)  = rdt_ice / MAX(rhosn*cpic*zh_s(ji),epsi10)
             END DO
          END DO
@@ -403,14 +409,11 @@
          !
          DO ji = kideb , kiut
-
             ! update of the non solar flux according to the update in T_su
-            qnsr_ice_1d(ji) = qnsr_ice_1d(ji) + dqns_ice_1d(ji) * & 
-               ( t_su_b(ji) - ztsuoldit(ji) )
+            qns_ice_1d(ji) = qns_ice_1d(ji) + dqns_ice_1d(ji) * ( t_su_1d(ji) - ztsubit(ji) )
 
             ! update incoming flux
             zf(ji)    =   zfsw(ji)              & ! net absorbed solar radiation
-               + qnsr_ice_1d(ji)           ! non solar total flux 
+               + qns_ice_1d(ji)                  ! non solar total flux 
             ! (LWup, LWdw, SH, LH)
-
          END DO
 
@@ -427,5 +430,5 @@
          !!ice interior terms (top equation has the same form as the others)
 
-         DO numeq=1,jkmax+2
+         DO numeq=1,nlay_i+3
             DO ji = kideb , kiut
                ztrid(ji,numeq,1) = 0.
@@ -440,11 +443,11 @@
          DO numeq = nlay_s + 2, nlay_s + nlay_i 
             DO ji = kideb , kiut
-               layer              = numeq - nlay_s - 1
-               ztrid(ji,numeq,1)  =  - zeta_i(ji,layer)*zkappa_i(ji,layer-1)
-               ztrid(ji,numeq,2)  =  1.0 + zeta_i(ji,layer)*(zkappa_i(ji,layer-1) + &
-                  zkappa_i(ji,layer))
-               ztrid(ji,numeq,3)  =  - zeta_i(ji,layer)*zkappa_i(ji,layer)
-               zindterm(ji,numeq) =  ztiold(ji,layer) + zeta_i(ji,layer)* &
-                  zradab_i(ji,layer)
+               jk              = numeq - nlay_s - 1
+               ztrid(ji,numeq,1)  =  - zeta_i(ji,jk)*zkappa_i(ji,jk-1)
+               ztrid(ji,numeq,2)  =  1.0 + zeta_i(ji,jk)*(zkappa_i(ji,jk-1) + &
+                  zkappa_i(ji,jk))
+               ztrid(ji,numeq,3)  =  - zeta_i(ji,jk)*zkappa_i(ji,jk)
+               zindterm(ji,numeq) =  ztib(ji,jk) + zeta_i(ji,jk)* &
+                  zradab_i(ji,jk)
             END DO
          ENDDO
@@ -457,12 +460,12 @@
                +  zkappa_i(ji,nlay_i-1) )
             ztrid(ji,numeq,3)  =  0.0
-            zindterm(ji,numeq) =  ztiold(ji,nlay_i) + zeta_i(ji,nlay_i)* &
+            zindterm(ji,numeq) =  ztib(ji,nlay_i) + zeta_i(ji,nlay_i)* &
                ( zradab_i(ji,nlay_i) + zkappa_i(ji,nlay_i)*zg1 &
-               *  t_bo_b(ji) ) 
+               *  t_bo_1d(ji) ) 
          ENDDO
 
 
          DO ji = kideb , kiut
-            IF ( ht_s_b(ji).gt.0.0 ) THEN
+            IF ( ht_s_1d(ji).gt.0.0 ) THEN
                !
                !------------------------------------------------------------------------------|
@@ -472,11 +475,11 @@
                !!snow interior terms (bottom equation has the same form as the others)
                DO numeq = 3, nlay_s + 1
-                  layer =  numeq - 1
-                  ztrid(ji,numeq,1)   =  - zeta_s(ji,layer)*zkappa_s(ji,layer-1)
-                  ztrid(ji,numeq,2)   =  1.0 + zeta_s(ji,layer)*( zkappa_s(ji,layer-1) + &
-                     zkappa_s(ji,layer) )
-                  ztrid(ji,numeq,3)   =  - zeta_s(ji,layer)*zkappa_s(ji,layer)
-                  zindterm(ji,numeq)  =  ztsold(ji,layer) + zeta_s(ji,layer)* &
-                     zradab_s(ji,layer)
+                  jk =  numeq - 1
+                  ztrid(ji,numeq,1)   =  - zeta_s(ji,jk)*zkappa_s(ji,jk-1)
+                  ztrid(ji,numeq,2)   =  1.0 + zeta_s(ji,jk)*( zkappa_s(ji,jk-1) + &
+                     zkappa_s(ji,jk) )
+                  ztrid(ji,numeq,3)   =  - zeta_s(ji,jk)*zkappa_s(ji,jk)
+                  zindterm(ji,numeq)  =  ztsb(ji,jk) + zeta_s(ji,jk)* &
+                     zradab_s(ji,jk)
                END DO
 
@@ -485,8 +488,8 @@
                   ztrid(ji,nlay_s+2,3)    =  0.0
                   zindterm(ji,nlay_s+2)   =  zindterm(ji,nlay_s+2) + zkappa_i(ji,1)* &
-                     t_bo_b(ji) 
+                     t_bo_1d(ji) 
                ENDIF
 
-               IF ( t_su_b(ji) .LT. rtt ) THEN
+               IF ( t_su_1d(ji) .LT. rtt ) THEN
 
                   !------------------------------------------------------------------------------|
@@ -501,5 +504,5 @@
                   ztrid(ji,1,2) = dzf(ji) - zg1s*zkappa_s(ji,0)
                   ztrid(ji,1,3) = zg1s*zkappa_s(ji,0)
-                  zindterm(ji,1) = dzf(ji)*t_su_b(ji)   - zf(ji)
+                  zindterm(ji,1) = dzf(ji)*t_su_1d(ji)   - zf(ji)
 
                   !!first layer of snow equation
@@ -507,5 +510,5 @@
                   ztrid(ji,2,2)  =  1.0 + zeta_s(ji,1)*(zkappa_s(ji,1) + zkappa_s(ji,0)*zg1s)
                   ztrid(ji,2,3)  =  - zeta_s(ji,1)* zkappa_s(ji,1)
-                  zindterm(ji,2) =  ztsold(ji,1) + zeta_s(ji,1)*zradab_s(ji,1)
+                  zindterm(ji,2) =  ztsb(ji,1) + zeta_s(ji,1)*zradab_s(ji,1)
 
                ELSE 
@@ -524,7 +527,7 @@
                      zkappa_s(ji,0) * zg1s )
                   ztrid(ji,2,3)  =  - zeta_s(ji,1)*zkappa_s(ji,1) 
-                  zindterm(ji,2) = ztsold(ji,1) + zeta_s(ji,1) *            &
+                  zindterm(ji,2) = ztsb(ji,1) + zeta_s(ji,1) *            &
                      ( zradab_s(ji,1) +                         &
-                     zkappa_s(ji,0) * zg1s * t_su_b(ji) ) 
+                     zkappa_s(ji,0) * zg1s * t_su_1d(ji) ) 
                ENDIF
             ELSE
@@ -534,5 +537,5 @@
                !------------------------------------------------------------------------------|
                !
-               IF (t_su_b(ji) .LT. rtt) THEN
+               IF (t_su_1d(ji) .LT. rtt) THEN
                   !
                   !------------------------------------------------------------------------------|
@@ -548,5 +551,5 @@
                   ztrid(ji,numeqmin(ji),2)   =  dzf(ji) - zkappa_i(ji,0)*zg1    
                   ztrid(ji,numeqmin(ji),3)   =  zkappa_i(ji,0)*zg1
-                  zindterm(ji,numeqmin(ji))  =  dzf(ji)*t_su_b(ji) - zf(ji)
+                  zindterm(ji,numeqmin(ji))  =  dzf(ji)*t_su_1d(ji) - zf(ji)
 
                   !!first layer of ice equation
@@ -555,5 +558,5 @@
                      + zkappa_i(ji,0) * zg1 )
                   ztrid(ji,numeqmin(ji)+1,3) =  - zeta_i(ji,1)*zkappa_i(ji,1)  
-                  zindterm(ji,numeqmin(ji)+1)=  ztiold(ji,1) + zeta_i(ji,1)*zradab_i(ji,1)  
+                  zindterm(ji,numeqmin(ji)+1)=  ztib(ji,1) + zeta_i(ji,1)*zradab_i(ji,1)  
 
                   !!case of only one layer in the ice (surface & ice equations are altered)
@@ -568,6 +571,6 @@
                      ztrid(ji,numeqmin(ji)+1,3)  =  0.0
 
-                     zindterm(ji,numeqmin(ji)+1) =  ztiold(ji,1) + zeta_i(ji,1)* &
-                        ( zradab_i(ji,1) + zkappa_i(ji,1)*t_bo_b(ji) )
+                     zindterm(ji,numeqmin(ji)+1) =  ztib(ji,1) + zeta_i(ji,1)* &
+                        ( zradab_i(ji,1) + zkappa_i(ji,1)*t_bo_1d(ji) )
                   ENDIF
 
@@ -588,6 +591,6 @@
                      zg1)  
                   ztrid(ji,numeqmin(ji),3)      =  - zeta_i(ji,1) * zkappa_i(ji,1)
-                  zindterm(ji,numeqmin(ji))     =  ztiold(ji,1) + zeta_i(ji,1)*( zradab_i(ji,1) + &
-                     zkappa_i(ji,0) * zg1 * t_su_b(ji) ) 
+                  zindterm(ji,numeqmin(ji))     =  ztib(ji,1) + zeta_i(ji,1)*( zradab_i(ji,1) + &
+                     zkappa_i(ji,0) * zg1 * t_su_1d(ji) ) 
 
                   !!case of only one layer in the ice (surface & ice equations are altered)
@@ -597,7 +600,7 @@
                         zkappa_i(ji,1))
                      ztrid(ji,numeqmin(ji),3)  =  0.0
-                     zindterm(ji,numeqmin(ji)) =  ztiold(ji,1) + zeta_i(ji,1)* &
-                        (zradab_i(ji,1) + zkappa_i(ji,1)*t_bo_b(ji)) &
-                        + t_su_b(ji)*zeta_i(ji,1)*zkappa_i(ji,0)*2.0
+                     zindterm(ji,numeqmin(ji)) =  ztib(ji,1) + zeta_i(ji,1)* &
+                        (zradab_i(ji,1) + zkappa_i(ji,1)*t_bo_1d(ji)) &
+                        + t_su_1d(ji)*zeta_i(ji,1)*zkappa_i(ji,0)*2.0
                   ENDIF
 
@@ -618,5 +621,5 @@
 
          maxnumeqmax = 0
-         minnumeqmin = jkmax+4
+         minnumeqmin = nlay_i+5
 
          DO ji = kideb , kiut
@@ -627,7 +630,7 @@
          END DO
 
-         DO layer = minnumeqmin+1, maxnumeqmax
-            DO ji = kideb , kiut
-               numeq               =  min(max(numeqmin(ji)+1,layer),numeqmax(ji))
+         DO jk = minnumeqmin+1, maxnumeqmax
+            DO ji = kideb , kiut
+               numeq               =  min(max(numeqmin(ji)+1,jk),numeqmax(ji))
                zdiagbis(ji,numeq)  =  ztrid(ji,numeq,2) - ztrid(ji,numeq,1)* &
                   ztrid(ji,numeq-1,3)/zdiagbis(ji,numeq-1)
@@ -639,12 +642,12 @@
          DO ji = kideb , kiut
             ! ice temperatures
-            t_i_b(ji,nlay_i)    =  zindtbis(ji,numeqmax(ji))/zdiagbis(ji,numeqmax(ji))
+            t_i_1d(ji,nlay_i)    =  zindtbis(ji,numeqmax(ji))/zdiagbis(ji,numeqmax(ji))
          END DO
 
          DO numeq = nlay_i + nlay_s + 1, nlay_s + 2, -1
             DO ji = kideb , kiut
-               layer    =  numeq - nlay_s - 1
-               t_i_b(ji,layer)  =  (zindtbis(ji,numeq) - ztrid(ji,numeq,3)* &
-                  t_i_b(ji,layer+1))/zdiagbis(ji,numeq)
+               jk    =  numeq - nlay_s - 1
+               t_i_1d(ji,jk)  =  (zindtbis(ji,numeq) - ztrid(ji,numeq,3)* &
+                  t_i_1d(ji,jk+1))/zdiagbis(ji,numeq)
             END DO
          END DO
@@ -652,15 +655,15 @@
          DO ji = kideb , kiut
             ! snow temperatures      
-            IF (ht_s_b(ji).GT.0._wp) &
-               t_s_b(ji,nlay_s)     =  (zindtbis(ji,nlay_s+1) - ztrid(ji,nlay_s+1,3) &
-               *  t_i_b(ji,1))/zdiagbis(ji,nlay_s+1) &
-               *        MAX(0.0,SIGN(1.0,ht_s_b(ji))) 
+            IF (ht_s_1d(ji).GT.0._wp) &
+               t_s_1d(ji,nlay_s)     =  (zindtbis(ji,nlay_s+1) - ztrid(ji,nlay_s+1,3) &
+               *  t_i_1d(ji,1))/zdiagbis(ji,nlay_s+1) &
+               *        MAX(0.0,SIGN(1.0,ht_s_1d(ji))) 
 
             ! surface temperature
-            isnow(ji)     = NINT(  1.0 - MAX( 0.0 , SIGN( 1.0 , -ht_s_b(ji) )  )  )
-            ztsuoldit(ji) = t_su_b(ji)
-            IF( t_su_b(ji) < ztfs(ji) ) &
-               t_su_b(ji) = ( zindtbis(ji,numeqmin(ji)) - ztrid(ji,numeqmin(ji),3)* ( REAL( isnow(ji) )*t_s_b(ji,1)   &
-               &          + REAL( 1 - isnow(ji) )*t_i_b(ji,1) ) ) / zdiagbis(ji,numeqmin(ji))  
+            isnow(ji)     = NINT(  1.0 - MAX( 0.0 , SIGN( 1.0 , -ht_s_1d(ji) )  )  )
+            ztsubit(ji) = t_su_1d(ji)
+            IF( t_su_1d(ji) < ztfs(ji) ) &
+               t_su_1d(ji) = ( zindtbis(ji,numeqmin(ji)) - ztrid(ji,numeqmin(ji),3)* ( REAL( isnow(ji) )*t_s_1d(ji,1)   &
+               &          + REAL( 1 - isnow(ji) )*t_i_1d(ji,1) ) ) / zdiagbis(ji,numeqmin(ji))  
          END DO
          !
@@ -672,22 +675,20 @@
          ! zerrit(ji) is a measure of error, it has to be under maxer_i_thd
          DO ji = kideb , kiut
-            t_su_b(ji) =  MAX(  MIN( t_su_b(ji) , ztfs(ji) ) , 190._wp  )
-            zerrit(ji) =  ABS( t_su_b(ji) - ztsuoldit(ji) )     
-         END DO
-
-         DO layer  =  1, nlay_s
-            DO ji = kideb , kiut
-               ii = MOD( npb(ji) - 1, jpi ) + 1
-               ij = ( npb(ji) - 1 ) / jpi + 1
-               t_s_b(ji,layer) = MAX(  MIN( t_s_b(ji,layer), rtt ), 190._wp  )
-               zerrit(ji)      = MAX(zerrit(ji),ABS(t_s_b(ji,layer) - ztstemp(ji,layer)))
-            END DO
-         END DO
-
-         DO layer  =  1, nlay_i
-            DO ji = kideb , kiut
-               ztmelt_i        = -tmut * s_i_b(ji,layer) + rtt 
-               t_i_b(ji,layer) =  MAX(MIN(t_i_b(ji,layer),ztmelt_i), 190._wp)
-               zerrit(ji)      =  MAX(zerrit(ji),ABS(t_i_b(ji,layer) - ztitemp(ji,layer)))
+            t_su_1d(ji) =  MAX(  MIN( t_su_1d(ji) , ztfs(ji) ) , 190._wp  )
+            zerrit(ji) =  ABS( t_su_1d(ji) - ztsubit(ji) )     
+         END DO
+
+         DO jk  =  1, nlay_s
+            DO ji = kideb , kiut
+               t_s_1d(ji,jk) = MAX(  MIN( t_s_1d(ji,jk), rtt ), 190._wp  )
+               zerrit(ji)      = MAX(zerrit(ji),ABS(t_s_1d(ji,jk) - ztstemp(ji,jk)))
+            END DO
+         END DO
+
+         DO jk  =  1, nlay_i
+            DO ji = kideb , kiut
+               ztmelt_i        = -tmut * s_i_1d(ji,jk) + rtt 
+               t_i_1d(ji,jk) =  MAX(MIN(t_i_1d(ji,jk),ztmelt_i), 190._wp)
+               zerrit(ji)      =  MAX(zerrit(ji),ABS(t_i_1d(ji,jk) - ztitemp(ji,jk)))
             END DO
          END DO
@@ -713,45 +714,87 @@
       !-------------------------------------------------------------------------!
       DO ji = kideb, kiut
-#if ! defined key_coupled
          ! forced mode only : update of latent heat fluxes (sublimation) (always >=0, upward flux) 
-         qla_ice_1d (ji) = MAX( 0._wp, qla_ice_1d (ji) + dqla_ice_1d(ji) * ( t_su_b(ji) - ztsuold(ji) ) )
-#endif
+         IF( .NOT. lk_cpl) qla_ice_1d (ji) = MAX( 0._wp, qla_ice_1d (ji) + dqla_ice_1d(ji) * ( t_su_1d(ji) - ztsub(ji) ) )
          !                                ! surface ice conduction flux
-         isnow(ji)       = NINT(  1._wp - MAX( 0._wp, SIGN( 1._wp, -ht_s_b(ji) ) )  )
-         fc_su(ji)       =  -     REAL( isnow(ji) ) * zkappa_s(ji,0) * zg1s * (t_s_b(ji,1) - t_su_b(ji))   &
-            &               - REAL( 1 - isnow(ji) ) * zkappa_i(ji,0) * zg1  * (t_i_b(ji,1) - t_su_b(ji))
+         isnow(ji)       = NINT(  1._wp - MAX( 0._wp, SIGN( 1._wp, -ht_s_1d(ji) ) )  )
+         fc_su(ji)       =  -     REAL( isnow(ji) ) * zkappa_s(ji,0) * zg1s * (t_s_1d(ji,1) - t_su_1d(ji))   &
+            &               - REAL( 1 - isnow(ji) ) * zkappa_i(ji,0) * zg1  * (t_i_1d(ji,1) - t_su_1d(ji))
          !                                ! bottom ice conduction flux
-         fc_bo_i(ji)     =  - zkappa_i(ji,nlay_i) * ( zg1*(t_bo_b(ji) - t_i_b(ji,nlay_i)) )
-      END DO
-
-      !-------------------------!
-      ! Heat conservation       !
-      !-------------------------!
-      IF( con_i .AND. jiindex_1d > 0 ) THEN
+         fc_bo_i(ji)     =  - zkappa_i(ji,nlay_i) * ( zg1*(t_bo_1d(ji) - t_i_1d(ji,nlay_i)) )
+      END DO
+
+      !-----------------------------------------
+      ! Heat flux used to warm/cool ice in W.m-2
+      !-----------------------------------------
+      DO ji = kideb, kiut
+         IF( t_su_1d(ji) < rtt ) THEN  ! case T_su < 0degC
+            hfx_dif_1d(ji) = hfx_dif_1d(ji)  +   &
+               &            ( qns_ice_1d(ji) + qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) ) * a_i_1d(ji)
+         ELSE                         ! case T_su = 0degC
+            hfx_dif_1d(ji) = hfx_dif_1d(ji) +    &
+               &             ( fc_su(ji) + i0(ji) * qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) ) * a_i_1d(ji)
+         ENDIF
+      END DO
+
+      ! --- computes sea ice energy of melting compulsory for limthd_dh --- !
+      CALL lim_thd_enmelt( kideb, kiut )
+
+      ! --- diag error on heat diffusion - PART 2 --- !
+      DO ji = kideb, kiut
+         zdq(ji)        = - zq_ini(ji) + ( SUM( q_i_1d(ji,1:nlay_i) ) * ht_i_1d(ji) / REAL( nlay_i ) +  &
+            &                              SUM( q_s_1d(ji,1:nlay_s) ) * ht_s_1d(ji) / REAL( nlay_s ) )
+         zhfx_err    = ( fc_su(ji) + i0(ji) * qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) + zdq(ji) * r1_rdtice ) 
+         hfx_err_1d(ji) = hfx_err_1d(ji) + zhfx_err * a_i_1d(ji)
+         ! --- correction of qns_ice and surface conduction flux --- !
+         qns_ice_1d(ji) = qns_ice_1d(ji) - zhfx_err 
+         fc_su     (ji) = fc_su     (ji) - zhfx_err 
+         ! --- Heat flux at the ice surface in W.m-2 --- !
+         ii = MOD( npb(ji) - 1, jpi ) + 1 ; ij = ( npb(ji) - 1 ) / jpi + 1
+         hfx_in (ii,ij) = hfx_in (ii,ij) + a_i_1d(ji) * ( qsr_ice_1d(ji) + qns_ice_1d(ji) )
+      END DO
+   
+      !
+      CALL wrk_dealloc( jpij, numeqmin, numeqmax, isnow )
+      CALL wrk_dealloc( jpij, ztfs, ztsub, ztsubit, zh_i, zh_s, zfsw )
+      CALL wrk_dealloc( jpij, zf, dzf, zerrit, zdifcase, zftrice, zihic, zhsu )
+      CALL wrk_dealloc( jpij, nlay_i+1, ztcond_i, zradtr_i, zradab_i, zkappa_i,   &
+         &              ztib, zeta_i, ztitemp, z_i, zspeche_i, kjstart = 0 )
+      CALL wrk_dealloc( jpij, nlay_s+1,           zradtr_s, zradab_s, zkappa_s, ztsb, zeta_s, ztstemp, z_s, kjstart = 0 )
+      CALL wrk_dealloc( jpij, nlay_i+3, zindterm, zindtbis, zdiagbis )
+      CALL wrk_dealloc( jpij, nlay_i+3, 3, ztrid )
+      CALL wrk_dealloc( jpij, zdq, zq_ini )
+
+   END SUBROUTINE lim_thd_dif
+
+   SUBROUTINE lim_thd_enmelt( kideb, kiut )
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE lim_thd_enmelt *** 
+      !!                 
+      !! ** Purpose :   Computes sea ice energy of melting q_i (J.m-3) from temperature
+      !!
+      !! ** Method  :   Formula (Bitz and Lipscomb, 1999)
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kideb, kiut   ! bounds for the spatial loop
+      !
+      INTEGER  ::   ji, jk   ! dummy loop indices
+      REAL(wp) ::   ztmelts, zindb  ! local scalar 
+      !!-------------------------------------------------------------------
+      !
+      DO jk = 1, nlay_i             ! Sea ice energy of melting
          DO ji = kideb, kiut
-            ! Upper snow value
-            fc_s(ji,0) = - REAL( isnow(ji) ) * zkappa_s(ji,0) * zg1s * ( t_s_b(ji,1) - t_su_b(ji) ) 
-            ! Bott. snow value
-            fc_s(ji,1) = - REAL( isnow(ji) ) * zkappa_s(ji,1) * ( t_i_b(ji,1) - t_s_b(ji,1) ) 
-         END DO
-         DO ji = kideb, kiut         ! Upper ice layer
-            fc_i(ji,0) = - REAL( isnow(ji) ) * &  ! interface flux if there is snow
-               ( zkappa_i(ji,0)  * ( t_i_b(ji,1) - t_s_b(ji,nlay_s ) ) ) &
-               - REAL( 1 - isnow(ji) ) * ( zkappa_i(ji,0) * & 
-               zg1 * ( t_i_b(ji,1) - t_su_b(ji) ) ) ! upper flux if not
-         END DO
-         DO layer = 1, nlay_i - 1         ! Internal ice layers
-            DO ji = kideb, kiut
-               fc_i(ji,layer) = - zkappa_i(ji,layer) * ( t_i_b(ji,layer+1) - t_i_b(ji,layer) )
-               ii = MOD( npb(ji) - 1, jpi ) + 1
-               ij = ( npb(ji) - 1 ) / jpi + 1
-            END DO
-         END DO
-         DO ji = kideb, kiut         ! Bottom ice layers
-            fc_i(ji,nlay_i) = - zkappa_i(ji,nlay_i) * ( zg1*(t_bo_b(ji) - t_i_b(ji,nlay_i)) )
-         END DO
-      ENDIF
+            ztmelts      = - tmut  * s_i_1d(ji,jk) + rtt 
+            zindb        = MAX( 0._wp , SIGN( 1._wp , -(t_i_1d(ji,jk) - rtt) - epsi10 ) )
+            q_i_1d(ji,jk) = rhoic * ( cpic * ( ztmelts - t_i_1d(ji,jk) )                                             &
+               &                   + lfus * ( 1.0 - zindb * ( ztmelts-rtt ) / MIN( t_i_1d(ji,jk)-rtt, -epsi10 ) )   &
+               &                   - rcp  *                 ( ztmelts-rtt )  ) 
+         END DO
+      END DO
+      DO jk = 1, nlay_s             ! Snow energy of melting
+         DO ji = kideb, kiut
+            q_s_1d(ji,jk) = rhosn * ( cpic * ( rtt - t_s_1d(ji,jk) ) + lfus )
+         END DO
+      END DO
       !
-   END SUBROUTINE lim_thd_dif
+   END SUBROUTINE lim_thd_enmelt
 
 #else
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_ent.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_ent.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_ent.F90	(revision 4921)
@@ -10,5 +10,6 @@
    !!                 ! 2006-11 (X. Fettweis) Vectorized 
    !!            3.0  ! 2008-03 (M. Vancoppenolle) Energy conservation and clean code
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
+   !!             -   ! 2014-05 (C. Rousset) complete rewriting
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -22,4 +23,5 @@
    USE domain         !
    USE phycst         ! physical constants
+   USE sbc_oce        ! Surface boundary condition: ocean fields
    USE ice            ! LIM variables
    USE par_ice        ! LIM parameters
@@ -34,10 +36,8 @@
    PRIVATE
 
-   PUBLIC   lim_thd_ent         ! called by lim_thd
+   PUBLIC   lim_thd_ent         ! called by limthd and limthd_lac
 
-   REAL(wp) ::   epsi20 = 1.e-20_wp   ! constant values
-   REAL(wp) ::   epsi10 = 1.e-10_wp   !
-   REAL(wp) ::   zzero  = 0._wp      !
-   REAL(wp) ::   zone   = 1._wp      !
+   REAL(wp) :: epsi20 = 1.e-20   ! constant values
+   REAL(wp) :: epsi10 = 1.e-10   ! constant values
 
    !!----------------------------------------------------------------------
@@ -48,12 +48,11 @@
 CONTAINS
  
-   SUBROUTINE lim_thd_ent( kideb, kiut, jl )
+   SUBROUTINE lim_thd_ent( kideb, kiut, qnew )
       !!-------------------------------------------------------------------
       !!               ***   ROUTINE lim_thd_ent  ***
       !!
       !! ** Purpose :
-      !!           This routine computes new vertical grids 
-      !!           in the ice and in the snow, and consistently redistributes 
-      !!           temperatures in the snow / ice. 
+      !!           This routine computes new vertical grids in the ice, 
+      !!           and consistently redistributes temperatures. 
       !!           Redistribution is made so as to ensure to energy conservation
       !!
@@ -61,633 +60,98 @@
       !! ** Method  : linear conservative remapping
       !!           
-      !! ** Steps : 1) Grid
-      !!            2) Switches
-      !!            3) Snow redistribution
-      !!            4) Ice enthalpy redistribution
-      !!            5) Ice salinity, recover temperature
+      !! ** Steps : 1) cumulative integrals of old enthalpies/thicknesses
+      !!            2) linear remapping on the new layers
+      !!
+      !! ------------ cum0(0)                        ------------- cum1(0)
+      !!                                    NEW      -------------
+      !! ------------ cum0(1)               ==>      -------------
+      !!     ...                                     -------------
+      !! ------------                                -------------
+      !! ------------ cum0(nlay_i+2)                 ------------- cum1(nlay_i)
+      !!
       !!
       !! References : Bitz & Lipscomb, JGR 99; Vancoppenolle et al., GRL, 2005
       !!-------------------------------------------------------------------
       INTEGER , INTENT(in) ::   kideb, kiut   ! Start/End point on which the  the computation is applied
-      INTEGER , INTENT(in) ::   jl            ! Thickness cateogry number
 
-      INTEGER ::   ji,jk   !  dummy loop indices
-      INTEGER ::   ii, ij       ,   &  !  dummy indices
-         ntop0          ,   &  !  old layer top index
-         nbot1          ,   &  !  new layer bottom index
-         ntop1          ,   &  !  new layer top index
-         limsum         ,   &  !  temporary loop index
-         nlayi0,nlays0  ,   &  !  old number of layers
-         maxnbot0       ,   &  !  old layer bottom index
-         layer0, layer1        !  old/new layer indexes
+      REAL(wp), INTENT(inout), DIMENSION(:,:) :: qnew          ! new enthlapies (J.m-3, remapped)
 
-
-      REAL(wp) :: &
-         ztmelts        ,   &  ! ice melting point
-         zqsnic         ,   &  ! enthalpy of snow ice layer
-         zhsnow         ,   &  ! temporary snow thickness variable
-         zswitch        ,   &  ! dummy switch argument
-         zfac1          ,   &  ! dummy factor
-         zfac2          ,   &  ! dummy factor
-         ztform         ,   &  !: bottom formation temperature
-         zaaa           ,   &  !: dummy factor
-         zbbb           ,   &  !: dummy factor
-         zccc           ,   &  !: dummy factor
-         zdiscrim              !: dummy factor
-
-      INTEGER, POINTER, DIMENSION(:) ::   snswi     !  snow switch
-      INTEGER, POINTER, DIMENSION(:) ::   nbot0     !  old layer bottom index
-      INTEGER, POINTER, DIMENSION(:) ::   icsuind   !  ice surface index
-      INTEGER, POINTER, DIMENSION(:) ::   icsuswi   !  ice surface switch
-      INTEGER, POINTER, DIMENSION(:) ::   icboind   !  ice bottom index
-      INTEGER, POINTER, DIMENSION(:) ::   icboswi   !  ice bottom switch
-      INTEGER, POINTER, DIMENSION(:) ::   snicind   !  snow ice index
-      INTEGER, POINTER, DIMENSION(:) ::   snicswi   !  snow ice switch
-      INTEGER, POINTER, DIMENSION(:) ::   snind     !  snow index
+      INTEGER  :: ji         !  dummy loop indices
+      INTEGER  :: jk0, jk1   !  old/new layer indices
+      REAL(wp) :: zswitch
       !
-      REAL(wp), POINTER, DIMENSION(:) ::   zh_i   ! thickness of an ice layer
-      REAL(wp), POINTER, DIMENSION(:) ::   zh_s          ! thickness of a snow layer
-      REAL(wp), POINTER, DIMENSION(:) ::   zqsnow        ! enthalpy of the snow put in snow ice 	
-      REAL(wp), POINTER, DIMENSION(:) ::   zdeltah       ! temporary variable
-      REAL(wp), POINTER, DIMENSION(:) ::   zqti_in, zqts_in
-      REAL(wp), POINTER, DIMENSION(:) ::   zqti_fin, zqts_fin
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zm0       !  old layer-system vertical cotes 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   qm0       !  old layer-system heat content 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   z_s       !  new snow system vertical cotes 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   z_i       !  new ice system vertical cotes 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zthick0   !  old ice thickness 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zhl0      ! old and new layer thicknesses 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zrl01
-
-      REAL(wp) ::   zinda 
+      REAL(wp), POINTER, DIMENSION(:,:) :: zqh_cum0, zh_cum0   ! old cumulative enthlapies and layers interfaces
+      REAL(wp), POINTER, DIMENSION(:,:) :: zqh_cum1, zh_cum1   ! new cumulative enthlapies and layers interfaces
+      REAL(wp), POINTER, DIMENSION(:)   :: zhnew               ! new layers thicknesses
       !!-------------------------------------------------------------------
 
-      CALL wrk_alloc( jpij, snswi, nbot0, icsuind, icsuswi, icboind, icboswi, snicind, snicswi, snind )   ! integer
-      CALL wrk_alloc( jpij, zh_i, zh_s, zqsnow, zdeltah, zqti_in, zqts_in, zqti_fin, zqts_fin )           ! real
-      CALL wrk_alloc( jpij,jkmax+4, zm0, qm0, z_s, z_i, zthick0, zhl0, kjstart = 0 )
-      CALL wrk_alloc( jkmax+4,jkmax+4, zrl01, kistart = 0, kjstart = 0 )
+      CALL wrk_alloc( jpij, nlay_i+3, zqh_cum0, zh_cum0, kjstart = 0 )
+      CALL wrk_alloc( jpij, nlay_i+1, zqh_cum1, zh_cum1, kjstart = 0 )
+      CALL wrk_alloc( jpij, zhnew )
 
-      zthick0(:,:) = 0._wp
-      zm0    (:,:) = 0._wp
-      qm0    (:,:) = 0._wp
-      zrl01  (:,:) = 0._wp
-      zhl0   (:,:) = 0._wp
-      z_i    (:,:) = 0._wp
-      z_s    (:,:) = 0._wp
-
-      !
-      !------------------------------------------------------------------------------|
-      !  1) Grid                                                                     |
-      !------------------------------------------------------------------------------|
-      nlays0 = nlay_s
-      nlayi0 = nlay_i
-
-      DO ji = kideb, kiut
-         zh_i(ji) = old_ht_i_b(ji) / REAL( nlay_i ) 
-         zh_s(ji) = old_ht_s_b(ji) / REAL( nlay_s )
-      END DO
-
-      !
-      !------------------------------------------------------------------------------|
-      !  2) Switches                                                                 |
-      !------------------------------------------------------------------------------|
-      ! 2.1 snind(ji), snswi(ji)
-      ! snow surface behaviour : computation of snind(ji)-snswi(ji)
-      ! snind(ji) : index which equals 
-      ! 	 0 if snow is accumulating
-      ! 	 1 if 1st layer is melting
-      ! 	 2 if 2nd layer is melting ...
-      DO ji = kideb, kiut
-         snind  (ji) = 0
-         zdeltah(ji) = 0._wp
-      ENDDO !ji
-
-      DO jk = 1, nlays0
+      !--------------------------------------------------------------------------
+      !  1) Cumulative integral of old enthalpy * thicnkess and layers interfaces
+      !--------------------------------------------------------------------------
+      zqh_cum0(:,0:nlay_i+2) = 0._wp 
+      zh_cum0 (:,0:nlay_i+2) = 0._wp
+      DO jk0 = 1, nlay_i+2
          DO ji = kideb, kiut
-            snind(ji)  = jk        *      NINT(MAX(0.0,SIGN(1.0,-dh_s_tot(ji)-zdeltah(ji)))) &
-               + snind(ji) * (1 - NINT(MAX(0.0,SIGN(1.0,-dh_s_tot(ji)-zdeltah(ji)))))
-            zdeltah(ji)= zdeltah(ji) + zh_s(ji)
-         END DO ! ji
-      END DO ! jk
-
-      ! snswi(ji) : switch which value equals 1 if snow melts
-      !				   0 if not
-      DO ji = kideb, kiut
-         snswi(ji)     = MAX(0,NINT(-dh_s_tot(ji)/MAX(epsi20,ABS(dh_s_tot(ji)))))
-      END DO ! ji
-
-      ! 2.2 icsuind(ji), icsuswi(ji)
-      ! ice surface behaviour : computation of icsuind(ji)-icsuswi(ji)
-      ! icsuind(ji) : index which equals
-      !	   0 if nothing happens at the surface
-      !	   1 if first layer is melting
-      !	   2 if 2nd layer is reached by melt ...
-      DO ji = kideb, kiut
-         icsuind(ji) = 0
-         zdeltah(ji) = 0._wp
-      END DO !ji
-      DO jk = 1, nlayi0
-         DO ji = kideb, kiut
-            icsuind(ji) = jk          *      NINT(MAX(0.0,SIGN(1.0,-dh_i_surf(ji)-zdeltah(ji)))) &
-               + icsuind(ji) * (1 - NINT(MAX(0.0,SIGN(1.0,-dh_i_surf(ji)-zdeltah(ji)))))
-            zdeltah(ji) = zdeltah(ji) + zh_i(ji)
-         END DO ! ji
-      ENDDO !jk
-
-      ! icsuswi(ji) : switch which equals 
-      ! 	   1 if ice melts at the surface
-      ! 	   0 if not
-      DO ji = kideb, kiut
-         icsuswi(ji)  = MAX(0,NINT(-dh_i_surf(ji)/MAX(epsi20 , ABS(dh_i_surf(ji)) ) ) )
+            zqh_cum0(ji,jk0) = zqh_cum0(ji,jk0-1) + qh_i_old(ji,jk0-1)
+            zh_cum0 (ji,jk0) = zh_cum0 (ji,jk0-1) + h_i_old (ji,jk0-1)
+         ENDDO
       ENDDO
 
-      ! 2.3 icboind(ji), icboswi(ji)
-      ! ice bottom behaviour : computation of icboind(ji)-icboswi(ji)
-      ! icboind(ji) : index which equals
-      ! 	   0 if accretion is on the way
-      ! 	   1 if last layer has started to melt
-      ! 	   2 if penultiem layer is melting ... and so on
-      !            N+1 if all layers melt and that snow transforms into ice
-      DO ji = kideb, kiut 
-         icboind(ji) = 0
-         zdeltah(ji) = 0._wp
-      END DO
-      DO jk = nlayi0, 1, -1
-         DO ji = kideb, kiut
-            icboind(ji) = (nlayi0+1-jk) *      NINT(MAX(0.0,SIGN(1.0,-dh_i_bott(ji)-zdeltah(ji)))) &
-               &          + icboind(ji) * (1 - NINT(MAX(0.0,SIGN(1.0,-dh_i_bott(ji)-zdeltah(ji))))) 
-            zdeltah(ji) = zdeltah(ji) + zh_i(ji)
-         END DO
-      END DO
-
+      !------------------------------------
+      !  2) Interpolation on the new layers
+      !------------------------------------
+      ! new layer thickesses
       DO ji = kideb, kiut
-         ! case of total ablation with remaining snow
-         IF ( ( ht_i_b(ji) .GT. epsi20 ) .AND. &
-            ( ht_i_b(ji) - dh_snowice(ji) .LT. epsi20 ) ) icboind(ji) = nlay_i + 1
-      END DO
-
-      ! icboswi(ji) : switch which equals 
-      ! 	   1 if ice accretion is on the way
-      ! 	   0 if ablation is on the way
-      DO ji = kideb, kiut 
-         icboswi(ji) = MAX(0,NINT(dh_i_bott(ji) / MAX(epsi20,ABS(dh_i_bott(ji)))))
-      END DO
-
-      ! 2.4 snicind(ji), snicswi(ji)
-      ! snow ice formation : calcul de snicind(ji)-snicswi(ji)
-      ! snicind(ji) : index which equals 
-      ! 	   0 if no snow-ice forms
-      ! 	   1 if last layer of snow has started to melt
-      ! 	   2 if penultiem layer ...
-      DO ji = kideb, kiut
-         snicind(ji) = 0
-         zdeltah(ji) = 0._wp
-      END DO
-      DO jk = nlays0, 1, -1
-         DO ji = kideb, kiut
-            snicind(ji) = (nlays0+1-jk) &
-               *      NINT(MAX(0.0,SIGN(1.0,dh_snowice(ji)-zdeltah(ji)))) + snicind(ji)   &
-               * (1 - NINT(MAX(0.0,SIGN(1.0,dh_snowice(ji)-zdeltah(ji)))))
-            zdeltah(ji) = zdeltah(ji) + zh_s(ji)
-         END DO
-      END DO
-
-      ! snicswi(ji) : switch which equals 
-      ! 	   1 if snow-ice forms
-      ! 	   0 if not
-      DO ji = kideb, kiut
-         snicswi(ji)   = MAX(0,NINT(dh_snowice(ji)/MAX(epsi20,ABS(dh_snowice(ji)))))
+         zhnew(ji) = SUM( h_i_old(ji,0:nlay_i+1) ) / REAL( nlay_i )  
       ENDDO
 
-      !
-      !------------------------------------------------------------------------------|
-      !  3) Snow redistribution                                                      |
-      !------------------------------------------------------------------------------|
-      !
-      !-------------
-      ! Old profile
-      !-------------
-
-      ! by 'old', it is meant that layers coming from accretion are included, 
-      ! and that interfacial layers which were partly melted are reduced 
-
-      ! indexes of the vectors
-      !------------------------
-      ntop0    =  1
-      maxnbot0 =  0
-
-      DO ji = kideb, kiut
-         nbot0(ji) =  nlays0  + 1 - snind(ji) + ( 1 - snicind(ji) ) * snicswi(ji)
-         ! cotes of the top of the layers
-         zm0(ji,0) =  0._wp
-         maxnbot0 =  MAX ( maxnbot0 , nbot0(ji) )
-      END DO
-      IF( lk_mpp )   CALL mpp_max( maxnbot0, kcom=ncomm_ice )
-
-      DO jk = 1, maxnbot0
+      ! new layers interfaces
+      zh_cum1(:,0:nlay_i) = 0._wp
+      DO jk1 = 1, nlay_i
          DO ji = kideb, kiut
-            !change
-            limsum = ( 1 - snswi(ji) ) * ( jk - 1 ) + snswi(ji) * ( jk + snind(ji) - 1 )
-            limsum = MIN( limsum , nlay_s )
-            zm0(ji,jk) =  dh_s_tot(ji) + zh_s(ji) * REAL( limsum )
-         END DO
-      END DO
-
-      DO ji = kideb, kiut
-         zm0(ji,nbot0(ji)) =  dh_s_tot(ji) - REAL( snicswi(ji) ) * dh_snowice(ji) + zh_s(ji) * REAL( nlays0 )
-         zm0(ji,1)         =  dh_s_tot(ji) * REAL( 1 - snswi(ji) ) + REAL( snswi(ji) ) * zm0(ji,1)
-      END DO
-
-      DO jk = ntop0, maxnbot0
-         DO ji = kideb, kiut
-            zthick0(ji,jk)  =  zm0(ji,jk) - zm0(ji,jk-1)            ! layer thickness
-         END DO
-      END DO
-
-      zqts_in(:) = 0._wp
-
-      DO ji = kideb, kiut         ! layer heat content
-         qm0    (ji,1) =  rhosn * (  cpic * ( rtt - REAL( 1 - snswi(ji) ) * tatm_ice_1d(ji)        &
-            &                                         - REAL( snswi(ji) ) * t_s_b      (ji,1)  )   &
-            &                      + lfus  ) * zthick0(ji,1)
-         zqts_in(ji)   =  zqts_in(ji) + qm0(ji,1) 
-      END DO
-
-      DO jk = 2, maxnbot0
-         DO ji = kideb, kiut
-            limsum      = ( 1 - snswi(ji) ) * ( jk - 1 ) + snswi(ji) * ( jk + snind(ji) - 1 )
-            limsum      = MIN( limsum , nlay_s )
-            qm0(ji,jk)  = rhosn * ( cpic * ( rtt - t_s_b(ji,limsum) ) + lfus ) * zthick0(ji,jk)
-            zswitch = 1.0 - MAX (0.0, SIGN ( 1.0, - ht_s_b(ji) ) )
-            zqts_in(ji) = zqts_in(ji) + REAL( 1 - snswi(ji) ) * qm0(ji,jk) * zswitch
-         END DO ! jk
-      END DO ! ji
-
-      !------------------------------------------------
-      ! Energy given by the snow in snow-ice formation
-      !------------------------------------------------
-      ! zqsnow, enthalpy of the flooded snow
-      DO ji = kideb, kiut
-         zqsnow (ji) =  rhosn * lfus
-         zdeltah(ji) =  0._wp
-      END DO
-
-      DO jk =  nlays0, 1, -1
-         DO ji = kideb, kiut
-            zhsnow =  MAX( 0._wp , dh_snowice(ji)-zdeltah(ji) )
-            zqsnow (ji) =  zqsnow (ji) + rhosn*cpic*(rtt-t_s_b(ji,jk))
-            zdeltah(ji) =  zdeltah(ji) + zh_s(ji)
-         END DO
-      END DO
-
-      DO ji = kideb, kiut
-         zqsnow(ji) = zqsnow(ji) * dh_snowice(ji)
-      END DO
-
-      !------------------
-      ! new snow profile
-      !------------------
-
-      !--------------
-      ! Vector index   
-      !--------------
-      ntop1 =  1
-      nbot1 =  nlay_s
-
-      !-------------------
-      ! Layer coordinates 
-      !-------------------
-      DO ji = kideb, kiut
-         zh_s(ji)  = ht_s_b(ji) / REAL( nlay_s )
-         z_s(ji,0) =  0._wp
+            zh_cum1(ji,jk1) = zh_cum1(ji,jk1-1) + zhnew(ji)
+         ENDDO
       ENDDO
 
-      DO jk = 1, nlay_s
+      zqh_cum1(:,0:nlay_i) = 0._wp 
+      ! new cumulative q*h => linear interpolation
+      DO jk0 = 1, nlay_i+1
+         DO jk1 = 1, nlay_i-1
+            DO ji = kideb, kiut
+               IF( zh_cum1(ji,jk1) <= zh_cum0(ji,jk0) .AND. zh_cum1(ji,jk1) > zh_cum0(ji,jk0-1) ) THEN
+                  zqh_cum1(ji,jk1) = ( zqh_cum0(ji,jk0-1) * ( zh_cum0(ji,jk0) - zh_cum1(ji,jk1  ) ) +  &
+                     &                 zqh_cum0(ji,jk0  ) * ( zh_cum1(ji,jk1) - zh_cum0(ji,jk0-1) ) )  &
+                     &             / ( zh_cum0(ji,jk0) - zh_cum0(ji,jk0-1) )
+               ENDIF
+            ENDDO
+         ENDDO
+      ENDDO
+      ! to ensure that total heat content is strictly conserved, set:
+      zqh_cum1(:,nlay_i) = zqh_cum0(:,nlay_i+2) 
+
+      ! new enthalpies
+      DO jk1 = 1, nlay_i
          DO ji = kideb, kiut
-            z_s(ji,jk) =  zh_s(ji) * REAL( jk )
-         END DO
-      END DO
-
-      !-----------------
-      ! Layer thickness
-      !-----------------
-      DO layer0 = ntop0, maxnbot0
-         DO ji = kideb, kiut
-            zhl0(ji,layer0) = zm0(ji,layer0) - zm0(ji,layer0-1)
-         END DO
-      END DO
-
-      DO layer1 = ntop1, nbot1
-         DO ji = kideb, kiut
-            q_s_b(ji,layer1) = 0._wp
-         END DO
-      END DO
-
-      !----------------
-      ! Weight factors
-      !----------------
-      DO layer0 = ntop0, maxnbot0
-         DO layer1 = ntop1, nbot1
-            DO ji = kideb, kiut
-               zinda = MAX( 0._wp, SIGN( 1._wp , zhl0(ji,layer0) - epsi10 ) )
-               zrl01(layer1,layer0) = zinda * MAX(0.0,( MIN(zm0(ji,layer0),z_s(ji,layer1))   &
-                  &                 - MAX(zm0(ji,layer0-1), z_s(ji,layer1-1))) / MAX(zhl0(ji,layer0),epsi10)) 
-               q_s_b(ji,layer1) = q_s_b(ji,layer1) + zrl01(layer1,layer0)*qm0(ji,layer0)   &
-                  &                                * MAX(0.0,SIGN(1.0,REAL(nbot0(ji)-layer0)))
-            END DO
-         END DO
-      END DO
-
-      ! Heat conservation
-      zqts_fin(:) = 0._wp
-      DO jk = 1, nlay_s
-         DO ji = kideb, kiut
-            zqts_fin(ji) = zqts_fin(ji) + q_s_b(ji,jk)
-         END DO
-      END DO
-
-      IF ( con_i .AND. jiindex_1d > 0 ) THEN
-         DO ji = kideb, kiut
-            IF ( ABS ( zqts_in(ji) - zqts_fin(ji) ) * r1_rdtice  >  1.0e-6 ) THEN
-               ii                 = MOD( npb(ji) - 1, jpi ) + 1
-               ij                 = ( npb(ji) - 1 ) / jpi + 1
-               WRITE(numout,*) ' violation of heat conservation : ', ABS ( zqts_in(ji) - zqts_fin(ji) ) * r1_rdtice
-               WRITE(numout,*) ' ji, jj   : ', ii, ij
-               WRITE(numout,*) ' ht_s_b   : ', ht_s_b(ji)
-               WRITE(numout,*) ' zqts_in  : ', zqts_in (ji) * r1_rdtice
-               WRITE(numout,*) ' zqts_fin : ', zqts_fin(ji) * r1_rdtice
-               WRITE(numout,*) ' dh_snowice : ', dh_snowice(ji)
-               WRITE(numout,*) ' dh_s_tot : ', dh_s_tot(ji)
-               WRITE(numout,*) ' snswi    : ', snswi(ji)
-            ENDIF
-         END DO
-      ENDIF
-
-      !---------------------
-      ! Recover heat content
-      !---------------------
-      DO jk = 1, nlay_s
-         DO ji = kideb, kiut
-            zinda = MAX( 0._wp, SIGN( 1._wp , zh_s(ji) - epsi10 ) )        
-            q_s_b(ji,jk) = zinda * q_s_b(ji,jk) / MAX( zh_s(ji) , epsi10 )
-         END DO !ji
-      END DO !jk  
-
-      !---------------------
-      ! Recover temperature
-      !---------------------
-      zfac1 = 1. / ( rhosn * cpic )
-      zfac2 = lfus / cpic  
-      DO jk = 1, nlay_s
-         DO ji = kideb, kiut
-            zswitch = MAX ( 0.0 , SIGN ( 1.0, - ht_s_b(ji) ) )
-            t_s_b(ji,jk) = rtt + ( 1.0 - zswitch ) * ( - zfac1 * q_s_b(ji,jk) + zfac2 )
-         END DO
-      END DO
-      !
-      !------------------------------------------------------------------------------|
-      !  4) Ice redistribution                                                       |
-      !------------------------------------------------------------------------------|
-      !
-      !-------------
-      ! OLD PROFILE 
-      !-------------
-
-      !----------------
-      ! Vector indexes
-      !----------------
-      ntop0    =  1
-      maxnbot0 =  0
-
-      DO ji = kideb, kiut
-         ! reference number of the bottommost layer
-         nbot0(ji) =  MAX( 1 ,  MIN( nlayi0 + ( 1 - icboind(ji) ) +        &
-            &                           ( 1 - icsuind(ji) ) * icsuswi(ji) + snicswi(ji) , nlay_i + 2 ) )
-         ! maximum reference number of the bottommost layer over all domain
-         maxnbot0 =  MAX( maxnbot0 , nbot0(ji) )
-      END DO
-
-      !-------------------------
-      ! Cotes of old ice layers
-      !-------------------------
-      zm0(:,0) =  0._wp
-
-      DO jk = 1, maxnbot0
-         DO ji = kideb, kiut
-            ! jk goes from 1 to nbot0
-            ! the ice layer number goes from 1 to nlay_i
-            ! limsum is the real ice layer number corresponding to present jk
-            limsum    =  ( (icsuswi(ji)*(icsuind(ji)+jk-1) + & 
-               (1-icsuswi(ji))*jk))*(1-snicswi(ji)) + (jk-1)*snicswi(ji)
-            zm0(ji,jk)=  REAL(icsuswi(ji))*dh_i_surf(ji) + REAL(snicswi(ji))*dh_snowice(ji) &
-               +  REAL(limsum) * zh_i(ji)
-         END DO
-      END DO
-
-      DO ji = kideb, kiut
-         zm0(ji,nbot0(ji)) =  REAL(icsuswi(ji))*dh_i_surf(ji) + REAL(snicswi(ji))*dh_snowice(ji) + dh_i_bott(ji) &
-            +  zh_i(ji) * REAL(nlayi0)
-         zm0(ji,1)         =  REAL(snicswi(ji))*dh_snowice(ji) + REAL(1-snicswi(ji))*zm0(ji,1)
-      END DO
-
-      !-----------------------------
-      ! Thickness of old ice layers
-      !-----------------------------
-      DO jk = ntop0, maxnbot0
-         DO ji = kideb, kiut
-            zthick0(ji,jk) =  zm0(ji,jk) - zm0(ji,jk-1)
-         END DO
-      END DO
-
-      !---------------------------
-      ! Inner layers heat content
-      !---------------------------
-      qm0(:,:) =  0.0
-      zqti_in(:) = 0.0
-
-      DO jk = ntop0, maxnbot0
-         DO ji = kideb, kiut
-            limsum =  MAX(1,MIN(snicswi(ji)*(jk-1) + icsuswi(ji)*(jk-1+icsuind(ji)) + &
-               (1-icsuswi(ji))*(1-snicswi(ji))*jk,nlay_i))
-            ztmelts = -tmut * s_i_b(ji,limsum) + rtt
-            qm0(ji,jk) = rhoic * ( cpic * (ztmelts-t_i_b(ji,limsum)) + lfus * ( 1.0-(ztmelts-rtt)/ &
-               MIN((t_i_b(ji,limsum)-rtt),-epsi20) ) - rcp*(ztmelts-rtt) ) &
-               * zthick0(ji,jk)
-         END DO
-      END DO
-
-      !----------------------------
-      ! Bottom layers heat content
-      !----------------------------
-      DO ji = kideb, kiut        
-         ztmelts    = REAL( 1 - icboswi(ji) ) * (-tmut * s_i_b  (ji,nlayi0) )   &   ! case of melting ice
-            &       +     REAL( icboswi(ji) ) * (-tmut * s_i_new(ji)        )   &   ! case of forming ice
-            &       + rtt                                                         ! in Kelvin
-
-         ! bottom formation temperature
-         ztform = t_i_b(ji,nlay_i)
-         IF(  num_sal == 2  )   ztform = t_bo_b(ji)
-         qm0(ji,nbot0(ji)) = REAL( 1 - icboswi(ji) )*qm0(ji,nbot0(ji))             &   ! case of melting ice
-            &              + REAL( icboswi(ji) ) * rhoic * ( cpic*(ztmelts-ztform)       &   ! case of forming ice
-            + lfus *( 1.0-(ztmelts-rtt) / MIN ( (ztform-rtt) , - epsi10 ) )      & 
-            - rcp*(ztmelts-rtt) ) * zthick0(ji,nbot0(ji)  )
-      END DO
-
-      !-----------------------------
-      ! Snow ice layer heat content
-      !-----------------------------
-      DO ji = kideb, kiut
-         ! energy of the flooding seawater
-         zqsnic = rau0 * rcp * ( rtt - t_bo_b(ji) ) * dh_snowice(ji) * &
-            (rhoic - rhosn) / rhoic * REAL(snicswi(ji)) ! generally positive
-         ! Heat conservation diagnostic
-         qt_i_in(ji,jl) = qt_i_in(ji,jl) + zqsnic 
-
-         qldif_1d(ji)   = qldif_1d(ji) + zqsnic * a_i_b(ji)
-
-         ! enthalpy of the newly formed snow-ice layer
-         ! = enthalpy of snow + enthalpy of frozen water
-         zqsnic         =  zqsnow(ji) + zqsnic
-         qm0(ji,1)      =  REAL(snicswi(ji)) * zqsnic + REAL( 1 - snicswi(ji) ) * qm0(ji,1)
-
-      END DO ! ji
-
-      DO jk = ntop0, maxnbot0
-         DO ji = kideb, kiut
-            ! Heat conservation
-            zqti_in(ji) = zqti_in(ji) + qm0(ji,jk) * MAX( 0.0 , SIGN(1.0,ht_i_b(ji)-epsi10) ) &
-               &                                   * MAX( 0.0 , SIGN( 1. , REAL(nbot0(ji) - jk) ) )
-         END DO
-      END DO
-
-      !-------------
-      ! NEW PROFILE
-      !-------------
-
-      !---------------
-      ! Vectors index
-      !---------------
-      ntop1 =  1 
-      nbot1 =  nlay_i
-
-      !------------------
-      ! Layers thickness 
-      !------------------
-      DO ji = kideb, kiut
-         zh_i(ji) = ht_i_b(ji) / REAL( nlay_i )
+            zswitch      = 1._wp - MAX( 0._wp , SIGN( 1._wp , - zhnew(ji) + epsi10 ) ) 
+            qnew(ji,jk1) = zswitch * ( zqh_cum1(ji,jk1) - zqh_cum1(ji,jk1-1) ) / MAX( zhnew(ji), epsi10 )
+         ENDDO
       ENDDO
 
-      !-------------
-      ! Layer cotes      
-      !-------------
-      z_i(:,0) =  0._wp
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            z_i(ji,jk) =  zh_i(ji) * jk
-         END DO
+      ! --- diag error on heat remapping --- !
+      ! comment: if input h_i_old and qh_i_old are already multiplied by a_i (as in limthd_lac), 
+      ! then we should not (* a_i) again but not important since this is just to check that remap error is ~0
+      DO ji = kideb, kiut
+         hfx_err_rem_1d(ji) = hfx_err_rem_1d(ji) + a_i_1d(ji) * r1_rdtice *  &
+            &               ( SUM( qnew(ji,1:nlay_i) ) * zhnew(ji) - SUM( qh_i_old(ji,0:nlay_i+1) ) ) 
       END DO
-
-      !--thicknesses of the layers
-      DO layer0 = ntop0, maxnbot0
-         DO ji = kideb, kiut
-            zhl0(ji,layer0) = zm0(ji,layer0) - zm0(ji,layer0-1)   ! thicknesses of the layers
-         END DO
-      END DO
-
-      !------------------------
-      ! Weights for relayering
-      !------------------------
-      q_i_b(:,:) = 0._wp
-      DO layer0 = ntop0, maxnbot0
-         DO layer1 = ntop1, nbot1
-            DO ji = kideb, kiut
-               zinda = MAX( 0._wp, SIGN( 1._wp , zhl0(ji,layer0) - epsi10 ) )
-               zrl01(layer1,layer0) = zinda * MAX(0.0,( MIN(zm0(ji,layer0),z_i(ji,layer1)) &
-                  - MAX(zm0(ji,layer0-1), z_i(ji,layer1-1)))/MAX(zhl0(ji,layer0),epsi10))
-               q_i_b(ji,layer1) = q_i_b(ji,layer1) & 
-                  + zrl01(layer1,layer0)*qm0(ji,layer0) &
-                  * MAX(0.0,SIGN(1.0,ht_i_b(ji)-epsi10)) &
-                  * MAX(0.0,SIGN(1.0,REAL(nbot0(ji)-layer0)))
-            END DO
-         END DO
-      END DO
-
-      !-------------------------
-      ! Heat conservation check
-      !-------------------------
-      zqti_fin(:) = 0._wp
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            zqti_fin(ji) = zqti_fin(ji) + q_i_b(ji,jk)
-         END DO
-      END DO
+      
       !
-      IF ( con_i .AND. jiindex_1d > 0 ) THEN
-         DO ji = kideb, kiut
-            IF ( ABS ( zqti_in(ji) - zqti_fin(ji) ) * r1_rdtice  >  1.0e-6 ) THEN
-               ii                 = MOD( npb(ji) - 1, jpi ) + 1
-               ij                 = ( npb(ji) - 1 ) / jpi + 1
-               WRITE(numout,*) ' violation of heat conservation : ', ABS ( zqti_in(ji) - zqti_fin(ji) ) * r1_rdtice
-               WRITE(numout,*) ' ji, jj   : ', ii, ij
-               WRITE(numout,*) ' ht_i_b   : ', ht_i_b(ji)
-               WRITE(numout,*) ' zqti_in  : ', zqti_in (ji) * r1_rdtice
-               WRITE(numout,*) ' zqti_fin : ', zqti_fin(ji) * r1_rdtice
-               WRITE(numout,*) ' dh_i_bott: ', dh_i_bott(ji)
-               WRITE(numout,*) ' dh_i_surf: ', dh_i_surf(ji)
-               WRITE(numout,*) ' dh_snowice:', dh_snowice(ji)
-               WRITE(numout,*) ' icsuswi  : ', icsuswi(ji)
-               WRITE(numout,*) ' icboswi  : ', icboswi(ji)
-               WRITE(numout,*) ' snicswi  : ', snicswi(ji)
-            ENDIF
-         END DO
-      ENDIF
-
-      !----------------------
-      ! Recover heat content 
-      !----------------------
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            zinda = MAX( 0._wp, SIGN( 1._wp , zh_i(ji) - epsi10 ) )
-            q_i_b(ji,jk) = zinda * q_i_b(ji,jk) / MAX( zh_i(ji) , epsi10 )
-         END DO !ji
-      END DO !jk  
-
-      ! Heat conservation
-      zqti_fin(:) = 0.0
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            zqti_fin(ji) = zqti_fin(ji) + q_i_b(ji,jk) * zh_i(ji)
-         END DO
-      END DO
-
-      !
-      !------------------------------------------------------------------------------|
-      !  5) Update salinity and recover temperature                                  |
-      !------------------------------------------------------------------------------|
-      !
-      ! Update salinity (basal entrapment, snow ice formation)
-      DO ji = kideb, kiut
-         sm_i_b(ji) = sm_i_b(ji) + dsm_i_se_1d(ji) + dsm_i_si_1d(ji)
-      END DO !ji
-
-      ! Recover temperature
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            ztmelts    =  -tmut*s_i_b(ji,jk) + rtt
-            !Conversion q(S,T) -> T (second order equation)
-            zaaa         =  cpic
-            zbbb         =  ( rcp - cpic ) * ( ztmelts - rtt ) + q_i_b(ji,jk) / rhoic - lfus
-            zccc         =  lfus * ( ztmelts - rtt )
-            zdiscrim     =  SQRT( MAX(zbbb*zbbb - 4.0*zaaa*zccc,0.0) )
-            t_i_b(ji,jk) =  rtt - ( zbbb + zdiscrim ) / ( 2.0 *zaaa )
-         END DO !ji
-
-      END DO !jk
-      !
-      CALL wrk_dealloc( jpij, snswi, nbot0, icsuind, icsuswi, icboind, icboswi, snicind, snicswi, snind )   ! integer
-      CALL wrk_dealloc( jpij, zh_i, zh_s, zqsnow, zdeltah, zqti_in, zqts_in, zqti_fin, zqts_fin )           ! real
-      CALL wrk_dealloc( jpij,jkmax+4, zm0, qm0, z_s, z_i, zthick0, zhl0, kjstart = 0 )
-      CALL wrk_dealloc( jkmax+4,jkmax+4, zrl01, kistart = 0, kjstart = 0 )
+      CALL wrk_dealloc( jpij, nlay_i+3, zqh_cum0, zh_cum0, kjstart = 0 )
+      CALL wrk_dealloc( jpij, nlay_i+1, zqh_cum1, zh_cum1, kjstart = 0 )
+      CALL wrk_dealloc( jpij, zhnew )
       !
    END SUBROUTINE lim_thd_ent
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90	(revision 4921)
@@ -29,5 +29,7 @@
    USE lib_mpp        ! MPP library
    USE wrk_nemo       ! work arrays
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE limthd_ent
 
    IMPLICIT NONE
@@ -37,6 +39,5 @@
 
    REAL(wp) ::   epsi10 = 1.e-10_wp   !
-   REAL(wp) ::   zzero  = 0._wp      !
-   REAL(wp) ::   zone   = 1._wp      !
+   REAL(wp) ::   epsi20 = 1.e-20_wp   !
 
    !!----------------------------------------------------------------------
@@ -71,16 +72,23 @@
       !!             - Computation of variation of ice volume and mass
       !!             - Computation of frldb after lateral accretion and 
-      !!               update ht_s_b, ht_i_b and tbif_1d(:,:)      
+      !!               update ht_s_1d, ht_i_1d and tbif_1d(:,:)      
       !!------------------------------------------------------------------------
-      INTEGER ::   ji,jj,jk,jl,jm   ! dummy loop indices
-      INTEGER ::   layer, nbpac     ! local integers 
-      INTEGER ::   ii, ij, iter   !   -       -
-      REAL(wp)  ::   ztmelts, zdv, zqold, zfrazb, zweight, zalphai, zindb, zinda, 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, zindb, zinda, zde  ! local scalars
       REAL(wp) ::   zgamafr, zvfrx, zvgx, ztaux, ztwogp, zf , zhicol_new        !   -      -
       REAL(wp) ::   ztenagm, zvfry, zvgy, ztauy, zvrel2, zfp, zsqcd , zhicrit   !   -      -
       LOGICAL  ::   iterate_frazil   ! iterate frazil ice collection thickness
       CHARACTER (len = 15) :: fieldid
-      !
-      INTEGER , POINTER, DIMENSION(:) ::   zcatac      ! indexes of categories where new ice grows
+
+      REAL(wp) ::   zQm          ! enthalpy exchanged with the ocean (J/m2, >0 towards ocean)
+      REAL(wp) ::   zEi          ! sea ice specific enthalpy (J/kg)
+      REAL(wp) ::   zEw          ! seawater specific enthalpy (J/kg)
+      REAL(wp) ::   zfmdt        ! mass flux x time step (kg/m2, >0 towards ocean)
+     
+      REAL(wp) ::   zv_newfra
+  
+      INTEGER , POINTER, DIMENSION(:) ::   jcat        ! indexes of categories where new ice grows
       REAL(wp), POINTER, DIMENSION(:) ::   zswinew     ! switch for new ice or not
 
@@ -93,56 +101,26 @@
       REAL(wp), POINTER, DIMENSION(:) ::   zdv_res     ! residual volume in case of excessive heat budget
       REAL(wp), POINTER, DIMENSION(:) ::   zda_res     ! residual area in case of excessive heat budget
-      REAL(wp), POINTER, DIMENSION(:) ::   zat_i_ac    ! total ice fraction    
-      REAL(wp), POINTER, DIMENSION(:) ::   zat_i_lev   ! total ice fraction for level ice only (type 1)   
-      REAL(wp), POINTER, DIMENSION(:) ::   zdh_frazb   ! accretion of frazil ice at the ice bottom
-      REAL(wp), POINTER, DIMENSION(:) ::   zvrel_ac    ! relative ice / frazil velocity (1D vector)
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zhice_old   ! previous ice thickness
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zdummy      ! dummy thickness of new ice 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zdhicbot    ! thickness of new ice which is accreted vertically
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zv_old      ! old volume of ice in category jl
-      REAL(wp), POINTER, DIMENSION(:,:) ::   za_old      ! old area of ice in category jl
-      REAL(wp), POINTER, DIMENSION(:,:) ::   za_i_ac     ! 1-D version of a_i
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zv_i_ac     ! 1-D version of v_i
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zoa_i_ac    ! 1-D version of oa_i
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zsmv_i_ac   ! 1-D version of smv_i
-
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ze_i_ac   !: 1-D version of e_i
-
-      REAL(wp), POINTER, DIMENSION(:) ::   zqbgow    ! heat budget of the open water (negative)
-      REAL(wp), POINTER, DIMENSION(:) ::   zdhex     ! excessively thick accreted sea ice (hlead-hice)
-
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zqm0      ! old layer-system heat content
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zthick0   ! old ice thickness
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vt_i_init, vt_i_final   ! ice volume summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vt_s_init, vt_s_final   !  snow volume summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:) ::   et_i_init, et_i_final   !  ice energy summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:) ::   et_s_init               !  snow energy summed over categories
+      REAL(wp), POINTER, DIMENSION(:) ::   zat_i_1d    ! total ice fraction    
+      REAL(wp), POINTER, DIMENSION(:) ::   zv_frazb    ! accretion of frazil ice at the ice bottom
+      REAL(wp), POINTER, DIMENSION(:) ::   zvrel_1d    ! relative ice / frazil velocity (1D vector)
+
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zv_b      ! old volume of ice in category jl
+      REAL(wp), POINTER, DIMENSION(:,:) ::   za_b      ! old area of ice in category jl
+      REAL(wp), POINTER, DIMENSION(:,:) ::   za_i_1d   ! 1-D version of a_i
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zv_i_1d   ! 1-D version of v_i
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zoa_i_1d  ! 1-D version of oa_i
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zsmv_i_1d ! 1-D version of smv_i
+
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ze_i_1d !: 1-D version of e_i
+
       REAL(wp), POINTER, DIMENSION(:,:) ::   zvrel                   ! relative ice / frazil velocity
       !!-----------------------------------------------------------------------!
 
-      CALL wrk_alloc( jpij, zcatac )   ! integer
+      CALL wrk_alloc( jpij, jcat )   ! integer
       CALL wrk_alloc( jpij, zswinew, zv_newice, za_newice, zh_newice, ze_newice, zs_newice, zo_newice )
-      CALL wrk_alloc( jpij, zdv_res, zda_res, zat_i_ac, zat_i_lev, zdh_frazb, zvrel_ac, zqbgow, zdhex )
-      CALL wrk_alloc( jpij,jpl, zhice_old, zdummy, zdhicbot, zv_old, za_old, za_i_ac, zv_i_ac, zoa_i_ac, zsmv_i_ac )
-      CALL wrk_alloc( jpij,jkmax,jpl, ze_i_ac )
-      CALL wrk_alloc( jpij,jkmax+1,jpl, zqm0, zthick0 )
-      CALL wrk_alloc( jpi,jpj, vt_i_init, vt_i_final, vt_s_init, vt_s_final, et_i_init, et_i_final, et_s_init, zvrel )
-
-      et_i_init(:,:) = 0._wp
-      et_s_init(:,:) = 0._wp
-      vt_i_init(:,:) = 0._wp
-      vt_s_init(:,:) = 0._wp
-
-      !------------------------------------------------------------------------------!
-      ! 1) Conservation check and changes in each ice category
-      !------------------------------------------------------------------------------!
-      IF( con_i ) THEN
-         CALL lim_column_sum        ( jpl, v_i          , vt_i_init)
-         CALL lim_column_sum        ( jpl, v_s          , vt_s_init)
-         CALL lim_column_sum_energy ( jpl, nlay_i , e_i , et_i_init)
-         CALL lim_column_sum        ( jpl, e_s(:,:,1,:) , et_s_init)
-      ENDIF
+      CALL wrk_alloc( jpij, zdv_res, zda_res, zat_i_1d, zv_frazb, zvrel_1d )
+      CALL wrk_alloc( jpij,jpl, zv_b, za_b, za_i_1d, zv_i_1d, zoa_i_1d, zsmv_i_1d )
+      CALL wrk_alloc( jpij,nlay_i+1,jpl, ze_i_1d )
+      CALL wrk_alloc( jpi,jpj, zvrel )
 
       !------------------------------------------------------------------------------|
@@ -154,7 +132,7 @@
                DO ji = 1, jpi
                   !Energy of melting q(S,T) [J.m-3]
-                  e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) / MAX( area(ji,jj) * v_i(ji,jj,jl) ,  epsi10 ) * REAL( nlay_i )
                   zindb = 1._wp - MAX(  0._wp , SIGN( 1._wp , -v_i(ji,jj,jl) + epsi10 )  )   !0 if no ice and 1 if yes
-                  e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * unit_fac * zindb
+                  e_i(ji,jj,jk,jl) = zindb * e_i(ji,jj,jk,jl) / ( area(ji,jj) * MAX( v_i(ji,jj,jl) ,  epsi10 ) ) * REAL( nlay_i, wp )
+                  e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * unit_fac
                END DO
             END DO
@@ -179,7 +157,7 @@
 
       ! Default new ice thickness 
-      hicol(:,:) = hiccrit(1)
-
-      IF( fraz_swi == 1._wp ) THEN
+      hicol(:,:) = hiccrit
+
+      IF( fraz_swi == 1 ) THEN
 
          !--------------------
@@ -193,8 +171,7 @@
          zgamafr = 0.03
 
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-
-               IF ( tms(ji,jj) * ( qcmif(ji,jj) - qldif(ji,jj) ) > 0.e0 ) THEN
+         DO jj = 2, jpj
+            DO ji = 2, jpi
+               IF ( qlead(ji,jj) < 0._wp ) THEN
                   !-------------
                   ! Wind stress
@@ -206,11 +183,12 @@
                      &          +   vtau_ice(ji  ,jj  ) * tmv(ji  ,jj  ) ) * 0.5_wp
                   ! Square root of wind stress
-                  ztenagm       =  SQRT( SQRT( ztaux * ztaux + ztauy * ztauy ) )
+                  ztenagm       =  SQRT( SQRT( ztaux**2 + ztauy**2 ) )
 
                   !---------------------
                   ! Frazil ice velocity
                   !---------------------
-                  zvfrx         = zgamafr * zsqcd * ztaux / MAX(ztenagm,epsi10)
-                  zvfry         = zgamafr * zsqcd * ztauy / MAX(ztenagm,epsi10)
+                  zindb = MAX( 0._wp, SIGN( 1._wp , ztenagm - epsi10 ) )
+                  zvfrx = zindb * zgamafr * zsqcd * ztaux / MAX( ztenagm, epsi10 )
+                  zvfry = zindb * zgamafr * zsqcd * ztauy / MAX( ztenagm, epsi10 )
 
                   !-------------------
@@ -264,4 +242,7 @@
             END DO ! loop on ji ends
          END DO ! loop on jj ends
+      ! 
+      CALL lbc_lnk( zvrel(:,:), 'T', 1. )
+      CALL lbc_lnk( hicol(:,:), 'T', 1. )
 
       ENDIF ! End of computation of frazil ice collection thickness
@@ -276,7 +257,9 @@
       ! This occurs if open water energy budget is negative
       nbpac = 0
+      npac(:) = 0
+      !
       DO jj = 1, jpj
          DO ji = 1, jpi
-            IF ( tms(ji,jj) * ( qcmif(ji,jj) - qldif(ji,jj) )  >  0._wp ) THEN
+            IF ( qlead(ji,jj)  <  0._wp ) THEN
                nbpac = nbpac + 1
                npac( nbpac ) = (jj - 1) * jpi + ji
@@ -290,5 +273,5 @@
          DO ji = mi0(jiindx), mi1(jiindx)
             DO jj = mj0(jjindx), mj1(jjindx)
-               IF ( tms(ji,jj) * ( qcmif(ji,jj) - qldif(ji,jj) )  >  0._wp ) THEN
+               IF ( qlead(ji,jj)  <  0._wp ) THEN
                   jiindex_1d = (jj - 1) * jpi + ji
                ENDIF
@@ -307,22 +290,24 @@
       IF ( nbpac > 0 ) THEN
 
-         CALL tab_2d_1d( nbpac, zat_i_ac  (1:nbpac)     , at_i         , jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, zat_i_1d  (1:nbpac)     , at_i         , jpi, jpj, npac(1:nbpac) )
          DO jl = 1, jpl
-            CALL tab_2d_1d( nbpac, za_i_ac  (1:nbpac,jl), a_i  (:,:,jl), jpi, jpj, npac(1:nbpac) )
-            CALL tab_2d_1d( nbpac, zv_i_ac  (1:nbpac,jl), v_i  (:,:,jl), jpi, jpj, npac(1:nbpac) )
-            CALL tab_2d_1d( nbpac, zoa_i_ac (1:nbpac,jl), oa_i (:,:,jl), jpi, jpj, npac(1:nbpac) )
-            CALL tab_2d_1d( nbpac, zsmv_i_ac(1:nbpac,jl), smv_i(:,:,jl), jpi, jpj, npac(1:nbpac) )
+            CALL tab_2d_1d( nbpac, za_i_1d  (1:nbpac,jl), a_i  (:,:,jl), jpi, jpj, npac(1:nbpac) )
+            CALL tab_2d_1d( nbpac, zv_i_1d  (1:nbpac,jl), v_i  (:,:,jl), jpi, jpj, npac(1:nbpac) )
+            CALL tab_2d_1d( nbpac, zoa_i_1d (1:nbpac,jl), oa_i (:,:,jl), jpi, jpj, npac(1:nbpac) )
+            CALL tab_2d_1d( nbpac, zsmv_i_1d(1:nbpac,jl), smv_i(:,:,jl), jpi, jpj, npac(1:nbpac) )
             DO jk = 1, nlay_i
-               CALL tab_2d_1d( nbpac, ze_i_ac(1:nbpac,jk,jl), e_i(:,:,jk,jl) , jpi, jpj, npac(1:nbpac) )
+               CALL tab_2d_1d( nbpac, ze_i_1d(1:nbpac,jk,jl), e_i(:,:,jk,jl) , jpi, jpj, npac(1:nbpac) )
             END DO ! jk
          END DO ! jl
 
-         CALL tab_2d_1d( nbpac, qldif_1d  (1:nbpac)     , qldif  , jpi, jpj, npac(1:nbpac) )
-         CALL tab_2d_1d( nbpac, qcmif_1d  (1:nbpac)     , qcmif  , jpi, jpj, npac(1:nbpac) )
-         CALL tab_2d_1d( nbpac, t_bo_b    (1:nbpac)     , t_bo   , jpi, jpj, npac(1:nbpac) )
-         CALL tab_2d_1d( nbpac, sfx_thd_1d(1:nbpac)     , sfx_thd, jpi, jpj, npac(1:nbpac) )
-         CALL tab_2d_1d( nbpac, rdm_ice_1d(1:nbpac)     , rdm_ice, jpi, jpj, npac(1:nbpac) )
-         CALL tab_2d_1d( nbpac, hicol_b   (1:nbpac)     , hicol  , jpi, jpj, npac(1:nbpac) )
-         CALL tab_2d_1d( nbpac, zvrel_ac  (1:nbpac)     , zvrel  , jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, qlead_1d  (1:nbpac)     , qlead  , jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, t_bo_1d   (1:nbpac)     , t_bo   , jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, sfx_opw_1d(1:nbpac)     , sfx_opw, jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, wfx_opw_1d(1:nbpac)     , wfx_opw, jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, hicol_1d  (1:nbpac)     , hicol  , jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, zvrel_1d  (1:nbpac)     , zvrel  , jpi, jpj, npac(1:nbpac) )
+
+         CALL tab_2d_1d( nbpac, hfx_thd_1d(1:nbpac)     , hfx_thd, jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, hfx_opw_1d(1:nbpac)     , hfx_opw, jpi, jpj, npac(1:nbpac) )
 
          !------------------------------------------------------------------------------!
@@ -330,19 +315,23 @@
          !------------------------------------------------------------------------------!
 
+         !-----------------------------------------
+         ! Keep old ice areas and volume in memory
+         !-----------------------------------------
+         zv_b(1:nbpac,:) = zv_i_1d(1:nbpac,:) 
+         za_b(1:nbpac,:) = za_i_1d(1:nbpac,:)
          !----------------------
          ! Thickness of new ice
          !----------------------
          DO ji = 1, nbpac
-            zh_newice(ji) = hiccrit(1)
-         END DO
-         IF( fraz_swi == 1.0 )   zh_newice(:) = hicol_b(:)
+            zh_newice(ji) = hiccrit
+         END DO
+         IF( fraz_swi == 1 ) zh_newice(1:nbpac) = hicol_1d(1:nbpac)
 
          !----------------------
          ! Salinity of new ice 
          !----------------------
-
          SELECT CASE ( num_sal )
          CASE ( 1 )                    ! Sice = constant 
-            zs_newice(:) = bulk_sal
+            zs_newice(1:nbpac) = bulk_sal
          CASE ( 2 )                    ! Sice = F(z,t) [Vancoppenolle et al (2005)]
             DO ji = 1, nbpac
@@ -352,7 +341,6 @@
             END DO
          CASE ( 3 )                    ! Sice = F(z) [multiyear ice]
-            zs_newice(:) =   2.3
+            zs_newice(1:nbpac) =   2.3
          END SELECT
-
 
          !-------------------------
@@ -362,10 +350,9 @@
          DO ji = 1, nbpac
             ztmelts       = - tmut * zs_newice(ji) + rtt                  ! Melting point (K)
-            ze_newice(ji) =   rhoic * (  cpic * ( ztmelts - t_bo_b(ji) )                             &
-               &                       + lfus * ( 1.0 - ( ztmelts - rtt ) / ( t_bo_b(ji) - rtt ) )   &
+            ze_newice(ji) =   rhoic * (  cpic * ( ztmelts - t_bo_1d(ji) )                             &
+               &                       + lfus * ( 1.0 - ( ztmelts - rtt ) / MIN( t_bo_1d(ji) - rtt, -epsi10 ) )   &
                &                       - rcp  *         ( ztmelts - rtt )  )
-            ze_newice(ji) =   MAX( ze_newice(ji) , 0._wp )    &
-               &          +   MAX(  0.0 , SIGN( 1.0 , - ze_newice(ji) )  ) * rhoic * lfus
          END DO ! ji
+
          !----------------
          ! Age of new ice
@@ -375,39 +362,37 @@
          END DO ! ji
 
-         !--------------------------
-         ! Open water energy budget 
-         !--------------------------
-         DO ji = 1, nbpac
-            zqbgow(ji) = qldif_1d(ji) - qcmif_1d(ji)     !<0
-         END DO ! ji
-
          !-------------------
          ! Volume of new ice
          !-------------------
          DO ji = 1, nbpac
-            zv_newice(ji) = - zqbgow(ji) / ze_newice(ji)
+
+            zEi           = - ze_newice(ji) / rhoic                ! specific enthalpy of forming ice [J/kg]
+
+            zEw           = rcp * ( t_bo_1d(ji) - rt0 )             ! specific enthalpy of seawater at t_bo_1d [J/kg]
+                                                                   ! clem: we suppose we are already at the freezing point (condition qlead<0 is satisfyied) 
+                                                                   
+            zdE           = zEi - zEw                              ! specific enthalpy difference [J/kg]
+                                              
+            zfmdt         = - qlead_1d(ji) / zdE                   ! Fm.dt [kg/m2] (<0) 
+                                                                   ! clem: we use qlead instead of zqld (limthd) because we suppose we are at the freezing point   
+            zv_newice(ji) = - zfmdt / rhoic
+
+            zQm           = zfmdt * zEw                            ! heat to the ocean >0 associated with mass flux  
+
+            ! Contribution to heat flux to the ocean [W.m-2], >0  
+            hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * zEw * r1_rdtice
+            ! Total heat flux used in this process [W.m-2]  
+            hfx_opw_1d(ji) = hfx_opw_1d(ji) - zfmdt * zdE * r1_rdtice
+            ! mass flux
+            wfx_opw_1d(ji) = wfx_opw_1d(ji) - zv_newice(ji) * rhoic * r1_rdtice
+            ! salt flux
+            sfx_opw_1d(ji) = sfx_opw_1d(ji) - zv_newice(ji) * rhoic * zs_newice(ji) * r1_rdtice
 
             ! A fraction zfrazb of frazil ice is accreted at the ice bottom
-            zfrazb        = ( TANH ( Cfrazb * ( zvrel_ac(ji) - vfrazb ) ) + 1.0 ) * 0.5 * maxfrazb
-            zdh_frazb(ji) =         zfrazb   * zv_newice(ji)
+            zinda         = 1._wp - MAX( 0._wp, SIGN( 1._wp , - zat_i_1d(ji) ) )
+            zfrazb        = zinda * ( TANH ( Cfrazb * ( zvrel_1d(ji) - vfrazb ) ) + 1.0 ) * 0.5 * maxfrazb
+            zv_frazb(ji)  =         zfrazb   * zv_newice(ji)
             zv_newice(ji) = ( 1.0 - zfrazb ) * zv_newice(ji)
          END DO
-
-         !------------------------------------
-         ! Diags for energy conservation test
-         !------------------------------------
-         DO ji = 1, nbpac
-            ii = MOD( npac(ji) - 1 , jpi ) + 1
-            ij =    ( npac(ji) - 1 ) / jpi + 1
-            !
-            zde = ze_newice(ji) / unit_fac * area(ii,ij) * zv_newice(ji)
-            !
-            vt_i_init(ii,ij) = vt_i_init(ii,ij) + zv_newice(ji)             ! volume
-            et_i_init(ii,ij) = et_i_init(ii,ij) + zde                       ! Energy
-
-         END DO
-
-         ! keep new ice volume in memory
-         CALL tab_1d_2d( nbpac, v_newice , npac(1:nbpac), zv_newice(1:nbpac) , jpi, jpj )
 
          !-----------------
@@ -415,9 +400,6 @@
          !-----------------
          DO ji = 1, nbpac
-            ii = MOD( npac(ji) - 1 , jpi ) + 1
-            ij =    ( npac(ji) - 1 ) / jpi + 1
             za_newice(ji) = zv_newice(ji) / zh_newice(ji)
-            diag_lat_gr(ii,ij) = diag_lat_gr(ii,ij) + zv_newice(ji) * r1_rdtice ! clem
-         END DO !ji
+         END DO
 
          !------------------------------------------------------------------------------!
@@ -425,18 +407,12 @@
          !------------------------------------------------------------------------------!
 
-         !-----------------------------------------
-         ! Keep old ice areas and volume in memory
-         !-----------------------------------------
-         zv_old(:,:) = zv_i_ac(:,:) 
-         za_old(:,:) = za_i_ac(:,:)
-
-         !-------------------------------------------
-         ! Compute excessive new ice area and volume
-         !-------------------------------------------
+         !------------------------
+         ! 6.1) lateral ice growth
+         !------------------------
          ! If lateral ice growth gives an ice concentration gt 1, then
          ! we keep the excessive volume in memory and attribute it later to bottom accretion
          DO ji = 1, nbpac
-            IF ( za_newice(ji) >  ( amax - zat_i_ac(ji) ) ) THEN
-               zda_res(ji)   = za_newice(ji) - ( amax - zat_i_ac(ji) )
+            IF ( za_newice(ji) >  ( amax - zat_i_1d(ji) ) ) THEN
+               zda_res(ji)   = za_newice(ji) - ( amax - zat_i_1d(ji) )
                zdv_res(ji)   = zda_res  (ji) * zh_newice(ji) 
                za_newice(ji) = za_newice(ji) - zda_res  (ji)
@@ -446,130 +422,64 @@
                zdv_res(ji) = 0._wp
             ENDIF
-         END DO ! ji
-
-         !------------------------------------------------
-         ! Laterally redistribute new ice volume and area
-         !------------------------------------------------
-         zat_i_ac(:) = 0._wp
+         END DO
+
+         ! find which category to fill
+         zat_i_1d(:) = 0._wp
          DO jl = 1, jpl
             DO ji = 1, nbpac
-               IF(  hi_max   (jl-1)  <   zh_newice(ji)   .AND.   &
-                  & zh_newice(ji)    <=  hi_max   (jl)         ) THEN
-                  za_i_ac (ji,jl) = za_i_ac (ji,jl) + za_newice(ji)
-                  zv_i_ac (ji,jl) = zv_i_ac (ji,jl) + zv_newice(ji)
-                  zat_i_ac(ji)    = zat_i_ac(ji)    + za_i_ac  (ji,jl)
-                  zcatac  (ji)    = jl
+               IF( zh_newice(ji) > hi_max(jl-1) .AND. zh_newice(ji) <= hi_max(jl) ) THEN
+                  za_i_1d (ji,jl) = za_i_1d (ji,jl) + za_newice(ji)
+                  zv_i_1d (ji,jl) = zv_i_1d (ji,jl) + zv_newice(ji)
+                  jcat    (ji)    = jl
                ENDIF
-            END DO
-         END DO
-
-         !----------------------------------
-         ! Heat content - lateral accretion
-         !----------------------------------
-         DO ji = 1, nbpac
-            jl = zcatac(ji)                                                           ! categroy in which new ice is put
-            zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , -za_old(ji,jl) + epsi10 ) )             ! zindb=1 if ice =0 otherwise
-            zhice_old(ji,jl) = zv_old(ji,jl) / MAX( za_old(ji,jl) , epsi10 ) * zindb  ! old ice thickness
-            zdhex    (ji) = MAX( 0._wp , zh_newice(ji) - zhice_old(ji,jl) )           ! difference in thickness
-            zswinew  (ji) = MAX( 0._wp , SIGN( 1._wp , - za_old(ji,jl) + epsi10 ) )   ! ice totally new in jl category
+               zat_i_1d(ji) = zat_i_1d(ji) + za_i_1d  (ji,jl)
+            END DO
+         END DO
+
+         ! Heat content
+         DO ji = 1, nbpac
+            jl = jcat(ji)                                                    ! categroy in which new ice is put
+            zswinew  (ji) = MAX( 0._wp , SIGN( 1._wp , - za_b(ji,jl) ) )   ! 0 if old ice
          END DO
 
          DO jk = 1, nlay_i
             DO ji = 1, nbpac
-               jl = zcatac(ji)
-               zqold   = ze_i_ac(ji,jk,jl) ! [ J.m-3 ]
-               zalphai = MIN( zhice_old(ji,jl) * REAL( jk )     / REAL( nlay_i ), zh_newice(ji) )   &
-                  &    - MIN( zhice_old(ji,jl) * REAL( jk - 1 ) / REAL( nlay_i ), zh_newice(ji) )
-               ze_i_ac(ji,jk,jl) = zswinew(ji) * ze_newice(ji)                                     &
-                  + ( 1.0 - zswinew(ji) ) * ( za_old(ji,jl)  * zqold * zhice_old(ji,jl) / REAL( nlay_i )  &
-                  + za_newice(ji)  * ze_newice(ji) * zalphai                                       &
-                  + za_newice(ji)  * ze_newice(ji) * zdhex(ji) / REAL( nlay_i ) ) / ( ( zv_i_ac(ji,jl) ) / REAL( nlay_i ) )
-            END DO
-         END DO
-
-         !-----------------------------------------------
-         ! Add excessive volume of new ice at the bottom
-         !-----------------------------------------------
-         ! If the ice concentration exceeds 1, the remaining volume of new ice
-         ! is equally redistributed among all ice categories in which there is
-         ! ice
-
-         ! Fraction of level ice
-         jm = 1
-         zat_i_lev(:) = 0._wp
-
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
-            DO ji = 1, nbpac
-               zat_i_lev(ji) = zat_i_lev(ji) + za_i_ac(ji,jl) 
-            END DO
-         END DO
-
-         IF( ln_nicep .AND. jiindex_1d > 0 ) WRITE(numout,*) ' zv_i_ac : ', zv_i_ac(jiindex_1d, 1:jpl)
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
-            DO ji = 1, nbpac
-               zindb = MAX( 0._wp, SIGN( 1._wp , zdv_res(ji) ) )
-               zinda = MAX( 0._wp, SIGN( 1._wp , zat_i_lev(ji) - epsi10 ) )  ! clem
-               zv_i_ac(ji,jl) = zv_i_ac(ji,jl) + zindb * zinda * zdv_res(ji) * za_i_ac(ji,jl) / MAX( zat_i_lev(ji) , epsi10 )
-            END DO
-         END DO
-         IF( ln_nicep .AND. jiindex_1d > 0 )   WRITE(numout,*) ' zv_i_ac : ', zv_i_ac(jiindex_1d, 1:jpl)
-
-         !---------------------------------
-         ! Heat content - bottom accretion
-         !---------------------------------
-         jm = 1
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
-            DO ji = 1, nbpac
-               zindb =  1._wp - MAX( 0._wp , SIGN( 1._wp , - za_i_ac(ji,jl ) + epsi10 ) )       ! zindb=1 if ice =0 otherwise
-               zhice_old(ji,jl) = zv_i_ac(ji,jl) / MAX( za_i_ac(ji,jl) , epsi10 ) * zindb
-               zdhicbot (ji,jl) = zdv_res(ji)    / MAX( za_i_ac(ji,jl) , epsi10 ) * zindb    &
-                  &             +  zindb * zdh_frazb(ji)                               ! frazil ice may coalesce
-               zdummy(ji,jl)    = zv_i_ac(ji,jl) / MAX( za_i_ac(ji,jl) , epsi10 ) * zindb      ! thickness of residual ice
-            END DO
-         END DO
-
-         ! old layers thicknesses and enthalpies
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
+               jl = jcat(ji)
+               zinda = MAX( 0._wp, SIGN( 1._wp , zv_i_1d(ji,jl) - epsi20 ) )
+               ze_i_1d(ji,jk,jl) = zswinew(ji)   *   ze_newice(ji) +                                                      &
+                  &        ( 1.0 - zswinew(ji) ) * ( ze_newice(ji) * zv_newice(ji) + ze_i_1d(ji,jk,jl) * zv_b(ji,jl) )  &
+                  &        * zinda / MAX( zv_i_1d(ji,jl), epsi20 )
+            END DO
+         END DO
+
+         !------------------------------------------------
+         ! 6.2) bottom ice growth + ice enthalpy remapping
+         !------------------------------------------------
+         DO jl = 1, jpl
+
+            ! for remapping
+            h_i_old (1:nbpac,0:nlay_i+1) = 0._wp
+            qh_i_old(1:nbpac,0:nlay_i+1) = 0._wp
             DO jk = 1, nlay_i
                DO ji = 1, nbpac
-                  zthick0(ji,jk,jl) =  zhice_old(ji,jl) / REAL( nlay_i )
-                  zqm0   (ji,jk,jl) =  ze_i_ac(ji,jk,jl) * zthick0(ji,jk,jl)
+                  h_i_old (ji,jk) = zv_i_1d(ji,jl) / REAL( nlay_i )
+                  qh_i_old(ji,jk) = ze_i_1d(ji,jk,jl) * h_i_old(ji,jk)
                END DO
             END DO
-         END DO
-!!gm ???  why the previous do loop  if ocerwriten by the following one ?
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
+
+            ! new volumes including lateral/bottom accretion + residual
             DO ji = 1, nbpac
-               zthick0(ji,nlay_i+1,jl) =  zdhicbot(ji,jl)
-               zqm0   (ji,nlay_i+1,jl) =  ze_newice(ji) * zdhicbot(ji,jl)
-            END DO ! ji
-         END DO ! jl
-
-         ! Redistributing energy on the new grid
-         ze_i_ac(:,:,:) = 0._wp
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
-            DO jk = 1, nlay_i
-               DO layer = 1, nlay_i + 1
-                  DO ji = 1, nbpac
-                     zindb =  1._wp -  MAX( 0._wp , SIGN( 1._wp , - za_i_ac(ji,jl) + epsi10 ) ) 
-                     ! Redistributing energy on the new grid
-                     zweight = MAX (  MIN( zhice_old(ji,jl) * REAL( layer ), zdummy(ji,jl) * REAL( jk ) )   &
-                        &    - MAX( zhice_old(ji,jl) * REAL( layer - 1 ) , zdummy(ji,jl) * REAL( jk - 1 ) ) , 0._wp )   &
-                        &    /( MAX(REAL(nlay_i) * zthick0(ji,layer,jl),epsi10) ) * zindb
-                     ze_i_ac(ji,jk,jl) =  ze_i_ac(ji,jk,jl) + zweight * zqm0(ji,layer,jl)  
-                  END DO ! ji
-               END DO ! layer
-            END DO ! jk
-         END DO ! jl
-
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
-            DO jk = 1, nlay_i
-               DO ji = 1, nbpac
-                  zindb =  1._wp -  MAX( 0._wp , SIGN( 1._wp , - zv_i_ac(ji,jl) + epsi10 ) ) 
-                  ze_i_ac(ji,jk,jl) = ze_i_ac(ji,jk,jl)   &
-                     &              / MAX( zv_i_ac(ji,jl) , epsi10) * za_i_ac(ji,jl) * REAL( nlay_i ) * zindb
-               END DO
-            END DO
-         END DO
+               zinda          = MAX( 0._wp, SIGN( 1._wp , zat_i_1d(ji) - epsi20 ) )
+               zv_newfra      = zinda * ( zdv_res(ji) + zv_frazb(ji) ) * za_i_1d(ji,jl) / MAX( zat_i_1d(ji) , epsi20 )
+               za_i_1d(ji,jl) = zinda * za_i_1d(ji,jl)               
+               zv_i_1d(ji,jl) = zv_i_1d(ji,jl) + zv_newfra
+               ! for remapping
+               h_i_old (ji,nlay_i+1) = zv_newfra
+               qh_i_old(ji,nlay_i+1) = ze_newice(ji) * zv_newfra
+            ENDDO
+
+            ! --- Ice enthalpy remapping --- !
+            CALL lim_thd_ent( 1, nbpac, ze_i_1d(1:nbpac,:,jl) ) 
+         ENDDO
 
          !------------
@@ -578,6 +488,6 @@
          DO jl = 1, jpl
             DO ji = 1, nbpac
-               zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - za_i_ac(ji,jl) + epsi10 ) )  ! 0 if no ice and 1 if yes
-               zoa_i_ac(ji,jl)  = za_old(ji,jl) * zoa_i_ac(ji,jl) / MAX( za_i_ac(ji,jl) , epsi10 ) * zindb   
+               zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - za_i_1d(ji,jl) + epsi20 ) )  ! 0 if no ice and 1 if yes
+               zoa_i_1d(ji,jl)  = za_b(ji,jl) * zoa_i_1d(ji,jl) / MAX( za_i_1d(ji,jl) , epsi20 ) * zindb   
             END DO 
          END DO   
@@ -586,92 +496,52 @@
          ! Update salinity
          !-----------------
-         !clem IF(  num_sal == 2  ) THEN
-            DO jl = 1, jpl
-               DO ji = 1, nbpac
-                  zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - zv_i_ac(ji,jl) + epsi10 ) )  ! 0 if no ice and 1 if yes
-                  zdv   = zv_i_ac(ji,jl) - zv_old(ji,jl)
-                  zsmv_i_ac(ji,jl) = zsmv_i_ac(ji,jl) + zdv * zs_newice(ji) * zindb ! clem modif
-               END DO
-            END DO   
-         !clem ENDIF
-
-         !--------------------------------
-         ! Update mass/salt fluxes (clem)
-         !--------------------------------
          DO jl = 1, jpl
             DO ji = 1, nbpac
-               zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - zv_i_ac(ji,jl) + epsi10 ) )  ! 0 if no ice and 1 if yes
-               zdv   = zv_i_ac(ji,jl) - zv_old(ji,jl)
-               rdm_ice_1d(ji) = rdm_ice_1d(ji) + zdv * rhoic * zindb
-               sfx_thd_1d(ji)   =   sfx_thd_1d(ji) - zdv * rhoic * zs_newice(ji) * r1_rdtice * zindb
-           END DO
+               zdv   = zv_i_1d(ji,jl) - zv_b(ji,jl)
+               zsmv_i_1d(ji,jl) = zsmv_i_1d(ji,jl) + zdv * zs_newice(ji)
+            END DO
          END DO
 
          !------------------------------------------------------------------------------!
-         ! 8) Change 2D vectors to 1D vectors 
+         ! 7) Change 2D vectors to 1D vectors 
          !------------------------------------------------------------------------------!
          DO jl = 1, jpl
-            CALL tab_1d_2d( nbpac, a_i (:,:,jl), npac(1:nbpac), za_i_ac (1:nbpac,jl), jpi, jpj )
-            CALL tab_1d_2d( nbpac, v_i (:,:,jl), npac(1:nbpac), zv_i_ac (1:nbpac,jl), jpi, jpj )
-            CALL tab_1d_2d( nbpac, oa_i(:,:,jl), npac(1:nbpac), zoa_i_ac(1:nbpac,jl), jpi, jpj )
-            !clem IF (  num_sal == 2  )   &
-               CALL tab_1d_2d( nbpac, smv_i (:,:,jl), npac(1:nbpac), zsmv_i_ac(1:nbpac,jl) , jpi, jpj )
+            CALL tab_1d_2d( nbpac, a_i (:,:,jl), npac(1:nbpac), za_i_1d (1:nbpac,jl), jpi, jpj )
+            CALL tab_1d_2d( nbpac, v_i (:,:,jl), npac(1:nbpac), zv_i_1d (1:nbpac,jl), jpi, jpj )
+            CALL tab_1d_2d( nbpac, oa_i(:,:,jl), npac(1:nbpac), zoa_i_1d(1:nbpac,jl), jpi, jpj )
+            CALL tab_1d_2d( nbpac, smv_i (:,:,jl), npac(1:nbpac), zsmv_i_1d(1:nbpac,jl) , jpi, jpj )
             DO jk = 1, nlay_i
-               CALL tab_1d_2d( nbpac, e_i(:,:,jk,jl), npac(1:nbpac), ze_i_ac(1:nbpac,jk,jl), jpi, jpj )
-            END DO
-         END DO
-         CALL tab_1d_2d( nbpac, sfx_thd, npac(1:nbpac), sfx_thd_1d(1:nbpac), jpi, jpj )
-         CALL tab_1d_2d( nbpac, rdm_ice, npac(1:nbpac), rdm_ice_1d(1:nbpac), jpi, jpj )
+               CALL tab_1d_2d( nbpac, e_i(:,:,jk,jl), npac(1:nbpac), ze_i_1d(1:nbpac,jk,jl), jpi, jpj )
+            END DO
+         END DO
+         CALL tab_1d_2d( nbpac, sfx_opw, npac(1:nbpac), sfx_opw_1d(1:nbpac), jpi, jpj )
+         CALL tab_1d_2d( nbpac, wfx_opw, npac(1:nbpac), wfx_opw_1d(1:nbpac), jpi, jpj )
+
+         CALL tab_1d_2d( nbpac, hfx_thd, npac(1:nbpac), hfx_thd_1d(1:nbpac), jpi, jpj )
+         CALL tab_1d_2d( nbpac, hfx_opw, npac(1:nbpac), hfx_opw_1d(1:nbpac), jpi, jpj )
          !
       ENDIF ! nbpac > 0
 
       !------------------------------------------------------------------------------!
-      ! 9) Change units for e_i
+      ! 8) Change units for e_i
       !------------------------------------------------------------------------------!    
       DO jl = 1, jpl
-         DO jk = 1, nlay_i          ! heat content in 10^9 Joules
-            e_i(:,:,jk,jl) = e_i(:,:,jk,jl) * area(:,:) * v_i(:,:,jl) / REAL( nlay_i )  / unit_fac 
+         DO jk = 1, nlay_i
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ! heat content in Joules
+                  e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * area(ji,jj) * v_i(ji,jj,jl) / ( REAL( nlay_i ,wp ) * unit_fac ) 
+               END DO
+            END DO
          END DO
       END DO
 
-      !------------------------------------------------------------------------------|
-      ! 10) Conservation check and changes in each ice category
-      !------------------------------------------------------------------------------|
-      IF( con_i ) THEN 
-         CALL lim_column_sum (jpl,   v_i, vt_i_final)
-         fieldid = 'v_i, limthd_lac'
-         CALL lim_cons_check (vt_i_init, vt_i_final, 1.0e-6, fieldid) 
-         !
-         CALL lim_column_sum_energy(jpl, nlay_i, e_i, et_i_final)
-         fieldid = 'e_i, limthd_lac'
-         CALL lim_cons_check (et_i_final, et_i_final, 1.0e-3, fieldid) 
-         !
-         CALL lim_column_sum (jpl,   v_s, vt_s_final)
-         fieldid = 'v_s, limthd_lac'
-         CALL lim_cons_check (vt_s_init, vt_s_final, 1.0e-6, fieldid) 
-         !
-         !     CALL lim_column_sum (jpl,   e_s(:,:,1,:) , et_s_init)
-         !     fieldid = 'e_s, limthd_lac'
-         !     CALL lim_cons_check (et_s_init, et_s_final, 1.0e-3, fieldid) 
-         IF( ln_nicep ) THEN
-            DO ji = mi0(jiindx), mi1(jiindx)
-               DO jj = mj0(jjindx), mj1(jjindx)
-                  WRITE(numout,*) ' vt_i_init : ', vt_i_init (ji,jj)
-                  WRITE(numout,*) ' vt_i_final: ', vt_i_final(ji,jj)
-                  WRITE(numout,*) ' et_i_init : ', et_i_init (ji,jj)
-                  WRITE(numout,*) ' et_i_final: ', et_i_final(ji,jj)
-               END DO
-            END DO
-         ENDIF
-         !
-      ENDIF
       !
-      CALL wrk_dealloc( jpij, zcatac )   ! integer
+      CALL wrk_dealloc( jpij, jcat )   ! integer
       CALL wrk_dealloc( jpij, zswinew, zv_newice, za_newice, zh_newice, ze_newice, zs_newice, zo_newice )
-      CALL wrk_dealloc( jpij, zdv_res, zda_res, zat_i_ac, zat_i_lev, zdh_frazb, zvrel_ac, zqbgow, zdhex )
-      CALL wrk_dealloc( jpij,jpl, zhice_old, zdummy, zdhicbot, zv_old, za_old, za_i_ac, zv_i_ac, zoa_i_ac, zsmv_i_ac )
-      CALL wrk_dealloc( jpij,jkmax,jpl, ze_i_ac )
-      CALL wrk_dealloc( jpij,jkmax+1,jpl, zqm0, zthick0 )
-      CALL wrk_dealloc( jpi,jpj, vt_i_init, vt_i_final, vt_s_init, vt_s_final, et_i_init, et_i_final, et_s_init, zvrel )
+      CALL wrk_dealloc( jpij, zdv_res, zda_res, zat_i_1d, zv_frazb, zvrel_1d )
+      CALL wrk_dealloc( jpij,jpl, zv_b, za_b, za_i_1d, zv_i_1d, zoa_i_1d, zsmv_i_1d )
+      CALL wrk_dealloc( jpij,nlay_i+1,jpl, ze_i_1d )
+      CALL wrk_dealloc( jpi,jpj, zvrel )
       !
    END SUBROUTINE lim_thd_lac
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_sal.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_sal.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limthd_sal.F90	(revision 4921)
@@ -53,19 +53,22 @@
       !
       INTEGER  ::   ji, jk     ! dummy loop indices 
-      REAL(wp) ::   zsold, iflush, iaccrbo, igravdr, isnowic, i_ice_switch,  ztmelts   ! local scalars
-      REAL(wp) ::   zaaa, zbbb, zccc, zdiscrim   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:) ::   ze_init, zhiold, zsiold
+      REAL(wp) ::   iflush, igravdr   ! local scalars
       !!---------------------------------------------------------------------
 
-      CALL wrk_alloc( jpij, ze_init, zhiold, zsiold )
-
+      !---------------------------------------------------------
+      !  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) Constant salinity, constant in time                                       |
       !------------------------------------------------------------------------------|
-!!gm comment: if num_sal = 1 s_i_new, s_i_b and sm_i_b can be set to bulk_sal one for all in the initialisation phase !!
+!!gm comment: if num_sal = 1 s_i_new, s_i_1d and sm_i_1d can be set to bulk_sal one for all in the initialisation phase !!
 !!gm           ===>>>   simplification of almost all test on num_sal value
       IF(  num_sal == 1  ) THEN
-            s_i_b  (kideb:kiut,1:nlay_i) =  bulk_sal
-            sm_i_b (kideb:kiut)          =  bulk_sal 
+            s_i_1d (kideb:kiut,1:nlay_i) =  bulk_sal
+            sm_i_1d(kideb:kiut)          =  bulk_sal 
             s_i_new(kideb:kiut)          =  bulk_sal
       ENDIF
@@ -74,24 +77,5 @@
       !  Module 2 : Constant salinity varying in time                                |
       !------------------------------------------------------------------------------|
-
       IF(  num_sal == 2  ) THEN
-
-         !---------------------------------
-         ! Thickness at previous time step
-         !---------------------------------
-         DO ji = kideb, kiut
-            zhiold(ji) = ht_i_b(ji) - dh_i_bott(ji) - dh_snowice(ji) - dh_i_surf(ji)
-            zsiold(ji) = sm_i_b(ji)
-         END DO
-
-         !---------------------
-         ! Global heat content
-         !---------------------
-         ze_init(:)  =  0._wp
-         DO jk = 1, nlay_i
-            DO ji = kideb, kiut
-               ze_init(ji) = ze_init(ji) + q_i_b(ji,jk) * ht_i_b(ji) / REAL (nlay_i )
-            END DO
-         END DO
 
          DO ji = kideb, kiut
@@ -99,17 +83,14 @@
             ! Switches 
             !----------
-            iflush       =         MAX( 0._wp , SIGN( 1.0 , t_su_b(ji) - rtt )        )    ! =1 if summer 
-            igravdr      =         MAX( 0._wp , SIGN( 1.0 , t_bo_b(ji) - t_su_b(ji) ) )    ! =1 if t_su < t_bo
-            iaccrbo      =         MAX( 0._wp , SIGN( 1.0 , dh_i_bott(ji) )           )    ! =1 if bottom accretion
-            i_ice_switch = 1._wp - MAX ( 0._wp , SIGN( 1._wp , - ht_i_b(ji) + 1.e-2 ) )
-            isnowic      = 1._wp - MAX ( 0._wp , SIGN( 1._wp , - dh_snowice(ji) ) ) * i_ice_switch   ! =1 if snow ice formation
+            iflush  = MAX( 0._wp , SIGN( 1._wp , t_su_1d(ji) - rtt )        )     ! =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_b(ji) - sal_G , 0._wp ) / time_G * rdt_ice 
-            !                                   ! drainage by flushing  
-            dsm_i_fl_1d(ji) = - iflush  * MAX( sm_i_b(ji) - sal_F , 0._wp ) / time_F * rdt_ice
+            ! drainage by gravity drainage
+            dsm_i_gd_1d(ji) = - igravdr * MAX( sm_i_1d(ji) - sal_G , 0._wp ) / time_G * rdt_ice 
+            ! drainage by flushing  
+            dsm_i_fl_1d(ji) = - iflush  * MAX( sm_i_1d(ji) - sal_F , 0._wp ) / time_F * rdt_ice
 
             !-----------------
@@ -118,19 +99,10 @@
             ! only drainage terms ( gravity drainage and flushing )
             ! snow ice / bottom sources are added in lim_thd_ent to conserve energy
-            sm_i_b(ji) = sm_i_b(ji) + dsm_i_fl_1d(ji) + dsm_i_gd_1d(ji)
-
-            ! if no ice, salinity = 0.1
-            i_ice_switch = 1._wp - MAX ( 0._wp, SIGN( 1._wp , - ht_i_b(ji) ) )
-            sm_i_b(ji)   = i_ice_switch * sm_i_b(ji) + s_i_min * ( 1._wp - i_ice_switch )
-
-            !----------------------------
-            ! Heat flux - brine drainage
-            !----------------------------
-            fhbri_1d(ji) = 0._wp
+            sm_i_1d(ji) = sm_i_1d(ji) + dsm_i_fl_1d(ji) + dsm_i_gd_1d(ji)
 
             !----------------------------
             ! Salt flux - brine drainage
             !----------------------------
-            sfx_bri_1d(ji) = sfx_bri_1d(ji) - i_ice_switch * rhoic * a_i_b(ji) * ht_i_b(ji) * ( sm_i_b(ji) - zsiold(ji) ) * r1_rdtice
+            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
 
          END DO
@@ -138,21 +110,4 @@
          ! Salinity profile
          CALL lim_var_salprof1d( kideb, kiut )
-
-
-         ! Only necessary for conservation check since salinity is modified
-         !--------------------
-         ! Temperature update
-         !--------------------
-         DO jk = 1, nlay_i
-            DO ji = kideb, kiut
-               ztmelts    =  -tmut*s_i_b(ji,jk) + rtt
-               !Conversion q(S,T) -> T (second order equation)
-               zaaa         =  cpic
-               zbbb         =  ( rcp - cpic ) * ( ztmelts - rtt ) + q_i_b(ji,jk) / rhoic - lfus
-               zccc         =  lfus * ( ztmelts - rtt )
-               zdiscrim     =  SQRT(  MAX( zbbb*zbbb - 4.0*zaaa*zccc, 0._wp )  )
-               t_i_b(ji,jk) =  rtt - ( zbbb + zdiscrim ) / ( 2.0 *zaaa )
-            END DO
-         END DO
          !
       ENDIF 
@@ -161,9 +116,6 @@
       !  Module 3 : Profile of salinity, constant in time                            |
       !------------------------------------------------------------------------------|
-
       IF(  num_sal == 3  )   CALL lim_var_salprof1d( kideb, kiut )
 
-      !
-      CALL wrk_dealloc( jpij, ze_init, zhiold, zsiold )
       !
    END SUBROUTINE lim_thd_sal
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limtrp.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limtrp.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limtrp.F90	(revision 4921)
@@ -30,4 +30,5 @@
    USE limvar          ! clem for ice thickness correction
    USE timing          ! Timing
+   USE limcons        ! conservation tests
 
    IMPLICIT NONE
@@ -37,6 +38,5 @@
 
    REAL(wp)  ::   epsi10 = 1.e-10_wp  
-   REAL(wp)  ::   rzero  = 0._wp   
-   REAL(wp)  ::   rone   = 1._wp
+   REAL(wp)  ::   epsi20 = 1.e-20_wp  
 
    !! * Substitution
@@ -63,42 +63,29 @@
       INTEGER, INTENT(in) ::   kt   ! number of iteration
       !
-      INTEGER  ::   ji, jj, jk, jl, layer   ! dummy loop indices
+      INTEGER  ::   ji, jj, jk, jl, jn      ! dummy loop indices
       INTEGER  ::   initad                  ! number of sub-timestep for the advection
       INTEGER  ::   ierr                    ! error status
       REAL(wp) ::   zindb  , zindsn , zindic, zindh, zinda      ! local scalar
-      REAL(wp) ::   zusvosn, zusvoic, zbigval     !   -      -
       REAL(wp) ::   zcfl , zusnit                 !   -      -
-      REAL(wp) ::   ze   , zsal   , zage          !   -      -
+      REAL(wp) ::   zsal   , zage          !   -      -
       !
       REAL(wp), POINTER, DIMENSION(:,:)      ::   zui_u, zvi_v, zsm, zs0at, zs0ow
       REAL(wp), POINTER, DIMENSION(:,:,:)    ::   zs0ice, zs0sn, zs0a, zs0c0 , zs0sm , zs0oi
       REAL(wp), POINTER, DIMENSION(:,:,:,:)  ::   zs0e
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-      REAL(wp) :: zchk_vmin, zchk_amin, zchk_amax, zchk_umax ! Check errors (C Rousset)
       ! mass and salt flux (clem)
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zviold   ! old ice volume...
-      ! correct ice thickness (clem)
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zviold, zvsold   ! old ice volume...
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   zaiold, zhimax   ! old ice concentration and thickness
-      REAL(wp) :: zdv, zda, zvi, zvs, zsmv
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   zeiold, zesold   ! old enthalpies
+      REAL(wp) :: zdv, zda, zvi, zvs, zsmv, zes, zei
+      !
+      REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
       !!---------------------------------------------------------------------
       IF( nn_timing == 1 )  CALL timing_start('limtrp')
 
-      CALL wrk_alloc( jpi, jpj, zui_u, zvi_v, zsm, zs0at, zs0ow )
+      CALL wrk_alloc( jpi, jpj, zui_u, zvi_v, zsm, zs0at, zs0ow, zeiold, zesold )
       CALL wrk_alloc( jpi, jpj, jpl, zs0ice, zs0sn, zs0a, zs0c0 , zs0sm , zs0oi )
-      CALL wrk_alloc( jpi, jpj, jkmax, jpl, zs0e )
-
-      CALL wrk_alloc( jpi,jpj,jpl,zviold )   ! clem
-      CALL wrk_alloc( jpi,jpj,jpl,zaiold, zhimax )   ! clem
-
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF( ln_limdiahsb ) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) )
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
+      CALL wrk_alloc( jpi, jpj, nlay_i+1, jpl, zs0e )
+
+      CALL wrk_alloc( jpi, jpj, jpl, zaiold, zhimax, zviold, zvsold )   ! clem
 
       IF( numit == nstart .AND. lwp ) THEN
@@ -115,6 +102,12 @@
       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 (clem)
          zviold(:,:,:)  = v_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. (clem) -------------------------------
@@ -167,5 +160,5 @@
 !         ENDIF
 !!gm end
-         initad = 1 + NINT( MAX( rzero, SIGN( rone, zcfl-0.5 ) ) )
+         initad = 1 + NINT( MAX( 0._wp, SIGN( 1._wp, zcfl-0.5 ) ) )
          zusnit = 1.0 / REAL( initad ) 
          IF( zcfl > 0.5 .AND. lwp )   &
@@ -174,83 +167,83 @@
 
          IF( MOD( ( kt - 1) / nn_fsbc , 2 ) == 0 ) THEN       !==  odd ice time step:  adv_x then adv_y  ==!
-            DO jk = 1,initad
-               CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0ow (:,:), sxopw(:,:),   &             !--- ice open water area
+            DO jn = 1,initad
+               CALL lim_adv_x( zusnit, u_ice, 1._wp , zsm, zs0ow (:,:), sxopw(:,:),   &             !--- ice open water area
                   &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
-               CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0ow (:,:), sxopw(:,:),   &
+               CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, zs0ow (:,:), sxopw(:,:),   &
                   &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
                DO jl = 1, jpl
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
+                  CALL lim_adv_x( zusnit, u_ice, 1._wp , zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
                      &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &
+                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &
                      &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
+                  CALL lim_adv_x( zusnit, u_ice, 1._wp , zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
                      &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &
+                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &
                      &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
+                  CALL lim_adv_x( zusnit, u_ice, 1._wp , zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
                      &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &
+                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &
                      &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &   !--- ice age      ---     
+                  CALL lim_adv_x( zusnit, u_ice, 1._wp , zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &   !--- ice age      ---     
                      &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &
+                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &
                      &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   &   !--- ice concentrations ---
+                  CALL lim_adv_x( zusnit, u_ice, 1._wp , zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   &   !--- ice concentrations ---
                      &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   & 
+                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   & 
                      &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &  !--- snow heat contents ---
+                  CALL lim_adv_x( zusnit, u_ice, 1._wp , zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &  !--- snow heat contents ---
                      &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &
+                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &
                      &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  DO layer = 1, nlay_i                                                           !--- ice heat contents ---
-                     CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0e(:,:,layer,jl), sxe (:,:,layer,jl),   & 
-                        &                                       sxxe(:,:,layer,jl), sye (:,:,layer,jl),   &
-                        &                                       syye(:,:,layer,jl), sxye(:,:,layer,jl) )
-                     CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0e(:,:,layer,jl), sxe (:,:,layer,jl),   & 
-                        &                                       sxxe(:,:,layer,jl), sye (:,:,layer,jl),   &
-                        &                                       syye(:,:,layer,jl), sxye(:,:,layer,jl) )
+                  DO jk = 1, nlay_i                                                           !--- ice heat contents ---
+                     CALL lim_adv_x( zusnit, u_ice, 1._wp , zsm, zs0e(:,:,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, zs0e(:,:,jk,jl), sxe (:,:,jk,jl),   & 
+                        &                                       sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
+                        &                                       syye(:,:,jk,jl), sxye(:,:,jk,jl) )
                   END DO
                END DO
             END DO
          ELSE
-            DO jk = 1, initad
-               CALL lim_adv_y( zusnit, v_ice, rone , zsm, zs0ow (:,:), sxopw(:,:),   &             !--- ice open water area
+            DO jn = 1, initad
+               CALL lim_adv_y( zusnit, v_ice, 1._wp , zsm, zs0ow (:,:), sxopw(:,:),   &             !--- ice open water area
                   &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
-               CALL lim_adv_x( zusnit, u_ice, rzero, zsm, zs0ow (:,:), sxopw(:,:),   &
+               CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, zs0ow (:,:), sxopw(:,:),   &
                   &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
                DO jl = 1, jpl
-                  CALL lim_adv_y( zusnit, v_ice, rone , zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
+                  CALL lim_adv_y( zusnit, v_ice, 1._wp , zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
                      &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rzero, zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &
+                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &
                      &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rone , zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
+                  CALL lim_adv_y( zusnit, v_ice, 1._wp , zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
                      &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rzero, zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &
+                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &
                      &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rone , zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
+                  CALL lim_adv_y( zusnit, v_ice, 1._wp , zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
                      &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rzero, zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &
+                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &
                      &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
 
-                  CALL lim_adv_y( zusnit, v_ice, rone , zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &   !--- ice age      ---
+                  CALL lim_adv_y( zusnit, v_ice, 1._wp , zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &   !--- ice age      ---
                      &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rzero, zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &
+                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &
                      &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rone , zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   &   !--- ice concentrations ---
+                  CALL lim_adv_y( zusnit, v_ice, 1._wp , zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   &   !--- ice concentrations ---
                      &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rzero, zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   &
+                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   &
                      &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rone , zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &  !--- snow heat contents ---
+                  CALL lim_adv_y( zusnit, v_ice, 1._wp , zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &  !--- snow heat contents ---
                      &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rzero, zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &
+                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &
                      &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  DO layer = 1, nlay_i                                                           !--- ice heat contents ---
-                     CALL lim_adv_y( zusnit, v_ice, rone , zsm, zs0e(:,:,layer,jl), sxe (:,:,layer,jl),   & 
-                        &                                       sxxe(:,:,layer,jl), sye (:,:,layer,jl),   &
-                        &                                       syye(:,:,layer,jl), sxye(:,:,layer,jl) )
-                     CALL lim_adv_x( zusnit, u_ice, rzero, zsm, zs0e(:,:,layer,jl), sxe (:,:,layer,jl),   & 
-                        &                                       sxxe(:,:,layer,jl), sye (:,:,layer,jl),   &
-                        &                                       syye(:,:,layer,jl), sxye(:,:,layer,jl) )
+                  DO jk = 1, nlay_i                                                           !--- ice heat contents ---
+                     CALL lim_adv_y( zusnit, v_ice, 1._wp , zsm, zs0e(:,:,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, zs0e(:,:,jk,jl), sxe (:,:,jk,jl),   & 
+                        &                                       sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
+                        &                                       syye(:,:,jk,jl), sxye(:,:,jk,jl) )
                   END DO
                END DO
@@ -268,8 +261,5 @@
             zs0oi (:,:,jl) = zs0oi (:,:,jl) / area(:,:)
             zs0a  (:,:,jl) = zs0a  (:,:,jl) / area(:,:)
-            zs0c0 (:,:,jl) = zs0c0 (:,:,jl) / area(:,:)
-            DO jk = 1, nlay_i
-               zs0e(:,:,jk,jl) = zs0e(:,:,jk,jl) / area(:,:)
-            END DO
+            !
          END DO
 
@@ -289,8 +279,8 @@
          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( rzero, SIGN( rone, -zs0at(ji  ,jj) ) ) )   &
-                  &        * ( 1._wp - MAX( rzero, SIGN( rone, -zs0at(ji+1,jj) ) ) ) * ahiu(ji,jj)
-               pahv(ji,jj) = ( 1._wp - MAX( rzero, SIGN( rone, -zs0at(ji,jj  ) ) ) )   &
-                  &        * ( 1._wp - MAX( rzero, SIGN( rone,- zs0at(ji,jj+1) ) ) ) * ahiv(ji,jj)
+               pahu(ji,jj) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -zs0at(ji  ,jj) ) ) )   &
+                  &        * ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -zs0at(ji+1,jj) ) ) ) * ahiu(ji,jj)
+               pahv(ji,jj) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -zs0at(ji,jj  ) ) ) )   &
+                  &        * ( 1._wp - MAX( 0._wp, SIGN( 1._wp,- zs0at(ji,jj+1) ) ) ) * ahiv(ji,jj)
             END DO
          END DO
@@ -305,8 +295,8 @@
             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( rzero, SIGN( rone, -zs0a(ji  ,jj,jl) ) ) )   &
-                     &        * ( 1._wp - MAX( rzero, SIGN( rone, -zs0a(ji+1,jj,jl) ) ) ) * ahiu(ji,jj)
-                  pahv(ji,jj) = ( 1._wp - MAX( rzero, SIGN( rone, -zs0a(ji,jj  ,jl) ) ) )   &
-                     &        * ( 1._wp - MAX( rzero, SIGN( rone,- zs0a(ji,jj+1,jl) ) ) ) * ahiv(ji,jj)
+                  pahu(ji,jj) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -zs0a(ji  ,jj,jl) ) ) )   &
+                     &        * ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -zs0a(ji+1,jj,jl) ) ) ) * ahiu(ji,jj)
+                  pahv(ji,jj) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -zs0a(ji,jj  ,jl) ) ) )   &
+                     &        * ( 1._wp - MAX( 0._wp, SIGN( 1._wp,- zs0a(ji,jj+1,jl) ) ) ) * ahiv(ji,jj)
                END DO
             END DO
@@ -334,10 +324,10 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zs0sn (ji,jj,jl) = MAX( rzero, zs0sn (ji,jj,jl) )
-                  zs0ice(ji,jj,jl) = MAX( rzero, zs0ice(ji,jj,jl) )
-                  zs0sm (ji,jj,jl) = MAX( rzero, zs0sm (ji,jj,jl) )
-                  zs0oi (ji,jj,jl) = MAX( rzero, zs0oi (ji,jj,jl) )
-                  zs0a  (ji,jj,jl) = MAX( rzero, zs0a  (ji,jj,jl) )
-                  zs0c0 (ji,jj,jl) = MAX( rzero, zs0c0 (ji,jj,jl) )
+                  zs0sn (ji,jj,jl) = MAX( 0._wp, zs0sn (ji,jj,jl) )
+                  zs0ice(ji,jj,jl) = MAX( 0._wp, zs0ice(ji,jj,jl) )
+                  zs0sm (ji,jj,jl) = MAX( 0._wp, zs0sm (ji,jj,jl) )
+                  zs0oi (ji,jj,jl) = MAX( 0._wp, zs0oi (ji,jj,jl) )
+                  zs0a  (ji,jj,jl) = MAX( 0._wp, zs0a  (ji,jj,jl) )
+                  zs0c0 (ji,jj,jl) = MAX( 0._wp, zs0c0 (ji,jj,jl) )
                   zs0at (ji,jj)    = zs0at(ji,jj) + zs0a(ji,jj,jl)
                END DO
@@ -346,40 +336,49 @@
 
          !---------------------------------------------------------
-         ! 5.2) Snow thickness, Ice thickness, Ice concentrations
+         ! 5.2) Update and mask variables
          !---------------------------------------------------------
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zindb        = MAX( 0._wp , SIGN( 1.0, zs0at(ji,jj) - epsi10) )
-               zs0ow(ji,jj) = ( 1._wp - zindb ) + zindb * MAX( zs0ow(ji,jj), 0._wp )
-               ato_i(ji,jj) = zs0ow(ji,jj)
-            END DO
-         END DO
-
-         DO jl = 1, jpl         ! Remove very small areas 
+         DO jl = 1, jpl          
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zvi = zs0ice(ji,jj,jl)
-                  zvs = zs0sn(ji,jj,jl)
+                  zindb= MAX( 0._wp , SIGN( 1._wp, zs0a(ji,jj,jl) - epsi10 ) )
+
+                  zvi  = zs0ice(ji,jj,jl)
+                  zvs  = zs0sn (ji,jj,jl)
+                  zes  = zs0c0 (ji,jj,jl)      
+                  zsmv = zs0sm (ji,jj,jl)
                   !
-                  zindb         = MAX( 0.0 , SIGN( 1.0, zs0a(ji,jj,jl) - epsi10) )
-                  !
-                  v_s(ji,jj,jl)  = zindb * zs0sn (ji,jj,jl) 
-                  v_i(ji,jj,jl)  = zindb * zs0ice(ji,jj,jl)
-                  !
-                  zindsn         = MAX( rzero, SIGN( rone, v_s(ji,jj,jl) - epsi10 ) )
-                  zindic         = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) )
-                  zindb          = MAX( zindsn, zindic )
-                  !
-                  zs0a(ji,jj,jl) = zindb  * zs0a(ji,jj,jl) !ice concentration
-                  a_i (ji,jj,jl) = zs0a(ji,jj,jl)
-                  v_s (ji,jj,jl) = zindsn * v_s(ji,jj,jl)
-                  v_i (ji,jj,jl) = zindic * v_i(ji,jj,jl)
-                  !
-                  ! Update mass fluxes (clem)
-                  rdm_ice(ji,jj) = rdm_ice(ji,jj) + ( v_i(ji,jj,jl) - zvi ) * rhoic 
-                  rdm_snw(ji,jj) = rdm_snw(ji,jj) + ( v_s(ji,jj,jl) - zvs ) * rhosn 
+                  ! Remove very small areas
+                  v_s(ji,jj,jl)   = zindb * zs0sn (ji,jj,jl) 
+                  v_i(ji,jj,jl)   = zindb * zs0ice(ji,jj,jl)
+                  a_i(ji,jj,jl)   = zindb * zs0a  (ji,jj,jl)
+                  e_s(ji,jj,1,jl) = zindb * zs0c0 (ji,jj,jl)      
+                  ! Ice salinity and age
+                  IF(  num_sal == 2  ) THEN
+                     smv_i(ji,jj,jl) = MAX( MIN( s_i_max * v_i(ji,jj,jl), zsmv ), s_i_min * v_i(ji,jj,jl) )
+                  ENDIF
+                  oa_i(ji,jj,jl) = MAX( zindb * zs0oi(ji,jj,jl) / MAX( a_i(ji,jj,jl), epsi10 ), 0._wp ) * a_i(ji,jj,jl)
+
+                 ! Update 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 ) * unit_fac / area(ji,jj) * r1_rdtice ! W.m-2 <0
               END DO
             END DO
          END DO
+
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zindb            = MAX( 0._wp , SIGN( 1._wp, zs0a(ji,jj,jl) - epsi10 ) )
+                     zei              = zs0e(ji,jj,jk,jl)      
+                     e_i(ji,jj,jk,jl) = zindb * MAX( 0._wp, zs0e(ji,jj,jk,jl) )
+                     ! Update fluxes
+                     hfx_res(ji,jj) = hfx_res(ji,jj) + ( e_i(ji,jj,jk,jl) - zei ) * unit_fac / area(ji,jj) * r1_rdtice ! W.m-2 <0
+                  END DO !ji
+               END DO ! jj
+            END DO ! jk
+         END DO ! jl
 
          !--- Thickness correction in case too high (clem) --------------------------------------------------------
@@ -390,7 +389,10 @@
 
                   IF ( v_i(ji,jj,jl) > 0._wp ) THEN
-                     zvi = v_i(ji,jj,jl)
-                     zvs = v_s(ji,jj,jl)
-                     zdv = v_i(ji,jj,jl) - zviold(ji,jj,jl)   
+                     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,:,jl) )
+                     zdv  = v_i(ji,jj,jl) - zviold(ji,jj,jl)   
                      !zda = a_i(ji,jj,jl) - zaiold(ji,jj,jl)   
                      
@@ -399,107 +401,72 @@
                         & ( zdv < 0.0 .AND. ht_i(ji,jj,jl) > zhimax(ji,jj,jl) ) ) THEN                                          
                         ht_i(ji,jj,jl) = MIN( zhimax(ji,jj,jl), hi_max(jl) )
-                        zindh   =  MAX( rzero, SIGN( rone, ht_i(ji,jj,jl) - epsi10 ) )
-                        a_i(ji,jj,jl)  = zindh * v_i(ji,jj,jl) / MAX( ht_i(ji,jj,jl), epsi10 )
+                        zindh   =  MAX( 0._wp, SIGN( 1._wp, ht_i(ji,jj,jl) - epsi20 ) )
+                        a_i(ji,jj,jl)  = zindh * v_i(ji,jj,jl) / MAX( ht_i(ji,jj,jl), epsi20 )
                      ELSE
                         ht_i(ji,jj,jl) = MAX( MIN( ht_i(ji,jj,jl), hi_max(jl) ), hi_max(jl-1) )
-                        zindh   =  MAX( rzero, SIGN( rone, ht_i(ji,jj,jl) - epsi10 ) )
-                        a_i(ji,jj,jl)  = zindh * v_i(ji,jj,jl) / MAX( ht_i(ji,jj,jl), epsi10 )
+                        zindh   =  MAX( 0._wp, SIGN( 1._wp, ht_i(ji,jj,jl) - epsi20 ) )
+                        a_i(ji,jj,jl)  = zindh * v_i(ji,jj,jl) / MAX( ht_i(ji,jj,jl), epsi20 )
                      ENDIF
 
                      ! small correction due to *zindh for a_i
-                     v_i(ji,jj,jl) = zindh * v_i(ji,jj,jl)
-                     v_s(ji,jj,jl) = zindh * v_s(ji,jj,jl)
+                     v_i  (ji,jj,jl) = zindh * v_i  (ji,jj,jl)
+                     v_s  (ji,jj,jl) = zindh * v_s  (ji,jj,jl)
+                     smv_i(ji,jj,jl) = zindh * smv_i(ji,jj,jl)
+                     e_s(ji,jj,1,jl) = zindh * e_s(ji,jj,1,jl)
+                     e_i(ji,jj,:,jl) = zindh * e_i(ji,jj,:,jl)
 
                      ! Update mass fluxes
-                     rdm_ice(ji,jj) = rdm_ice(ji,jj) + ( v_i(ji,jj,jl) - zvi ) * rhoic
-                     rdm_snw(ji,jj) = rdm_snw(ji,jj) + ( v_s(ji,jj,jl) - zvs ) * rhosn
+                     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 ) * unit_fac / area(ji,jj) * r1_rdtice ! W.m-2 <0
+                     hfx_res(ji,jj) = hfx_res(ji,jj) + ( SUM( e_i(ji,jj,:,jl) ) - zei ) * unit_fac / area(ji,jj) * r1_rdtice ! W.m-2 <0
 
                   ENDIF
 
                   diag_trp_vi(ji,jj) = diag_trp_vi(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) * r1_rdtice
-
-               END DO
-            END DO
-         END DO
-
-         ! ---
+                  diag_trp_vs(ji,jj) = diag_trp_vs(ji,jj) + ( v_s(ji,jj,jl) - zvsold(ji,jj,jl) ) * r1_rdtice
+
+               END DO
+            END DO
+         END DO
+         ! -------------------------------------------------
+
+         ! --- diags ---
          DO jj = 1, jpj
             DO ji = 1, jpi
-               zs0at(ji,jj) = SUM( zs0a(ji,jj,1:jpl) ) ! clem@useless??
-            END DO
-         END DO
-
-         !----------------------
-         ! 5.3) Ice properties
-         !----------------------
-
-         zbigval = 1.e+13
-
+               diag_trp_ei(ji,jj) = ( SUM( e_i(ji,jj,1:nlay_i,:) ) - zeiold(ji,jj) ) / area(ji,jj) * unit_fac * r1_rdtice
+               diag_trp_es(ji,jj) = ( SUM( e_s(ji,jj,1:nlay_s,:) ) - zesold(ji,jj) ) / area(ji,jj) * unit_fac * r1_rdtice
+            END DO
+         END DO
+
+         ! --- agglomerate variables (clem) -----------------
+         vt_i (:,:) = 0._wp
+         vt_s (:,:) = 0._wp
+         at_i (:,:) = 0._wp
+         !
          DO jl = 1, jpl
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zsmv = zs0sm(ji,jj,jl)
-
-                  ! Switches and dummy variables
-                  zusvosn         = 1.0/MAX( v_s(ji,jj,jl) , epsi10 )
-                  zusvoic         = 1.0/MAX( v_i(ji,jj,jl) , epsi10 )
-                  zindsn          = MAX( rzero, SIGN( rone, v_s(ji,jj,jl) - epsi10 ) )
-                  zindic          = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) )
-                  zindb           = MAX( zindsn, zindic )
-
-                  ! Ice salinity and age
-                  !clem zsal = MAX( MIN( (rhoic-rhosn)/rhoic*sss_m(ji,jj), zusvoic * zs0sm(ji,jj,jl) ), s_i_min ) * v_i(ji,jj,jl)
-                  IF(  num_sal == 2  ) THEN
-                     smv_i(ji,jj,jl) = MAX( MIN( s_i_max * v_i(ji,jj,jl), zsmv ), s_i_min * v_i(ji,jj,jl) )
-                  ENDIF
-
-                  zage = MAX( MIN( zbigval, zs0oi(ji,jj,jl) / MAX( a_i(ji,jj,jl), epsi10 ) ), 0._wp  ) * a_i(ji,jj,jl)
-                  oa_i (ji,jj,jl)  = zindic * zage 
-
-                  ! Snow heat content
-                  ze              =  MIN( MAX( 0.0, zs0c0(ji,jj,jl)*area(ji,jj) ), zbigval )
-                  e_s(ji,jj,1,jl) = zindsn * ze      
-
-                  ! Update salt fluxes (clem)
-                  sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsmv ) * rhoic * r1_rdtice 
-               END DO !ji
-            END DO !jj
-         END DO ! jl
-
-         DO jl = 1, jpl
-            DO jk = 1, nlay_i
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     ! Ice heat content
-                     zindic          =  MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) )
-                     ze              =  MIN( MAX( 0.0, zs0e(ji,jj,jk,jl)*area(ji,jj) ), zbigval )
-                     e_i(ji,jj,jk,jl) = zindic * ze
-                  END DO !ji
-               END DO ! jj
-            END DO ! jk
-         END DO ! jl
-
-
-      ! --- agglomerate variables (clem) -----------------
-      vt_i (:,:) = 0._wp
-      vt_s (:,:) = 0._wp
-      at_i (:,:) = 0._wp
-      !
-      DO jl = 1, jpl
+                  !
+                  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
+               END DO
+            END DO
+         END DO
+         ! -------------------------------------------------
+
+         ! open water
          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
-               !
-               zinda = MAX( rzero , SIGN( rone , at_i(ji,jj) - epsi10 ) )
-               icethi(ji,jj) = vt_i(ji,jj) / MAX( at_i(ji,jj) , epsi10 ) * zinda  ! ice thickness
-            END DO
-         END DO
-      END DO
-      ! -------------------------------------------------
-
-
+               ! open water = 1 if at_i=0
+               zindb        = MAX( 0._wp , SIGN( 1._wp, - at_i(ji,jj) ) )
+               ato_i(ji,jj) = zindb + (1._wp - zindb ) * zs0ow(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
@@ -536,37 +503,10 @@
          END DO
       ENDIF
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF( ln_limdiahsb ) THEN
-         zchk_fs  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
-
-         zchk_vmin = glob_min(v_i)
-         zchk_amax = glob_max(SUM(a_i,dim=3))
-         zchk_amin = glob_min(a_i)
-         zchk_umax = glob_max(SQRT(u_ice**2 + v_ice**2))
-
-         IF(lwp) THEN
-            IF ( ABS( zchk_v_i   ) >  1.e-5 ) THEN
-               WRITE(numout,*) 'violation volume [m3/day]     (limtrp) = ',(zchk_v_i * rday)
-               WRITE(numout,*) 'u_ice max [m/s]               (limtrp) = ',zchk_umax
-               WRITE(numout,*) 'number of time steps          (limtrp) =',kt
-            ENDIF
-            IF ( ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limtrp) = ',(zchk_smv * rday)
-            IF ( zchk_vmin <  0.            ) WRITE(numout,*) 'violation v_i<0  [mm]         (limtrp) = ',(zchk_vmin * 1.e-3)
-            IF ( zchk_amin <  0.            ) WRITE(numout,*) 'violation a_i<0               (limtrp) = ',zchk_amin
-         ENDIF
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
       !
-      CALL wrk_dealloc( jpi, jpj, zui_u, zvi_v, zsm, zs0at, zs0ow )
+      CALL wrk_dealloc( jpi, jpj, zui_u, zvi_v, zsm, zs0at, zs0ow, zeiold, zesold )
       CALL wrk_dealloc( jpi, jpj, jpl, zs0ice, zs0sn, zs0a, zs0c0 , zs0sm , zs0oi )
-      CALL wrk_dealloc( jpi, jpj, jkmax, jpl, zs0e )
-
-      CALL wrk_dealloc( jpi,jpj,jpl,zaiold, zhimax )   ! clem
+      CALL wrk_dealloc( jpi, jpj, nlay_i+1, jpl, zs0e )
+
+      CALL wrk_dealloc( jpi, jpj, jpl, zviold, zvsold, zaiold, zhimax )   ! clem
       !
       IF( nn_timing == 1 )  CALL timing_stop('limtrp')
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limupdate1.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limupdate1.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limupdate1.F90	(revision 4921)
@@ -5,4 +5,5 @@
    !!======================================================================
    !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
+   !!            3.6  !  2014-06  (C. Rousset)       Complete rewriting/cleaning
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -32,4 +33,5 @@
    USE par_ice
    USE limitd_th
+   USE limitd_me
    USE limvar
    USE prtctl           ! Print control
@@ -37,9 +39,9 @@
    USE wrk_nemo         ! work arrays
    USE lib_fortran     ! glob_sum
-   ! Check budget (Rousset)
    USE in_out_manager   ! I/O manager
    USE iom              ! I/O manager
    USE lib_mpp          ! MPP library
    USE timing          ! Timing
+   USE limcons        ! conservation tests
 
    IMPLICIT NONE
@@ -49,6 +51,4 @@
 
       REAL(wp)  ::   epsi10 = 1.e-10_wp   !    -       -
-      REAL(wp)  ::   rzero  = 0._wp       !    -       -
-      REAL(wp)  ::   rone   = 1._wp       !    -       -
          
    !! * Substitutions
@@ -66,122 +66,32 @@
       !!               
       !! ** Purpose :  Computes update of sea-ice global variables at 
-      !!               the end of the time step.
-      !!               Address pathological cases
-      !!               This place is very important
+      !!               the end of the dynamics.
       !!                
-      !! ** Method  :  
-      !!    Ice speed from ice dynamics
-      !!    Ice thickness, Snow thickness, Temperatures, Lead fraction
-      !!      from advection and ice thermodynamics 
-      !!
-      !! ** Action  : - 
       !!---------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk, jl, jm    ! dummy loop indices
-      INTEGER ::   jbnd1, jbnd2
-      INTEGER ::   i_ice_switch
-      INTEGER ::   ind_im, layer      ! indices for internal melt
-      REAL(wp) ::   zweight, zesum, z_da_i, zhimax
-      REAL(wp) ::   zinda, zindb, zindsn, zindic
-      REAL(wp) ::   zindg, zh, zdvres, zviold2
-      REAL(wp) ::   zbigvalue, zvsold2, z_da_ex
-      REAL(wp) ::   z_prescr_hi, zat_i_old, ztmelts, ze_s
-
-      REAL(wp), POINTER, DIMENSION(:) ::   zthick0, zqm0      ! thickness of the layers and heat contents for
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-      REAL(wp) :: zchk_vmin, zchk_amin, zchk_amax ! Check errors (C Rousset)
-      ! mass and salt flux (clem)
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zviold, zvsold, zsmvold   ! old ice volume...
+      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
+      INTEGER  ::   i_ice_switch
+      REAL(wp) ::   zsal
+      !
+      REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
       !!-------------------------------------------------------------------
       IF( nn_timing == 1 )  CALL timing_start('limupdate1')
 
-      CALL wrk_alloc( jkmax, zthick0, zqm0 )
-
-      CALL wrk_alloc( jpi,jpj,jpl,zviold, zvsold, zsmvold )   ! clem
-
-      !------------------------------------------------------------------------------
-      ! 1. Update of Global variables                                               |
-      !------------------------------------------------------------------------------
-
-      !-----------------
-      !  Trend terms
-      !-----------------
-      d_u_ice_dyn(:,:)     = u_ice(:,:)     - old_u_ice(:,:)
-      d_v_ice_dyn(:,:)     = v_ice(:,:)     - old_v_ice(:,:)
-      d_a_i_trp  (:,:,:)   = a_i  (:,:,:)   - old_a_i  (:,:,:)
-      d_v_s_trp  (:,:,:)   = v_s  (:,:,:)   - old_v_s  (:,:,:)  
-      d_v_i_trp  (:,:,:)   = v_i  (:,:,:)   - old_v_i  (:,:,:)   
-      d_e_s_trp  (:,:,:,:) = e_s  (:,:,:,:) - old_e_s  (:,:,:,:)  
-      d_e_i_trp  (:,:,:,:) = e_i  (:,:,:,:) - old_e_i  (:,:,:,:)
-      d_oa_i_trp (:,:,:)   = oa_i (:,:,:)   - old_oa_i (:,:,:)
-      d_smv_i_trp(:,:,:)   = 0._wp
-      IF(  num_sal == 2  )   d_smv_i_trp(:,:,:)  = smv_i(:,:,:) - old_smv_i(:,:,:)
-
-      ! mass and salt flux init (clem)
-      zviold(:,:,:) = v_i(:,:,:)
-      zvsold(:,:,:) = v_s(:,:,:)
-      zsmvold(:,:,:) = smv_i(:,:,:)
-
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) )
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
+      IF( ln_limdyn ) THEN 
+
+      ! conservation test
+      IF( ln_limdiahsb ) CALL lim_cons_hsm(0, 'limupdate1', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      !-----------------
+      ! zap small values
+      !-----------------
+      CALL lim_itd_me_zapsmall
 
       CALL lim_var_glo2eqv
-
-      !--------------------------------------
-      ! 2. Review of all pathological cases
-      !--------------------------------------
-
-! clem: useless now
-      !-------------------------------------------
-      ! 2.1) Advection of ice in an ice-free cell
-      !-------------------------------------------
-      ! should be removed since it is treated after dynamics now
-!      zhimax = 5._wp
-!      ! first category
-!      DO jj = 1, jpj
-!         DO ji = 1, jpi
-!            !--- the thickness of such an ice is often out of bounds
-!            !--- thus we recompute a new area while conserving ice volume
-!            zat_i_old = SUM( old_a_i(ji,jj,:) )
-!            zindb     = MAX( 0._wp, SIGN( 1._wp, ABS( d_a_i_trp(ji,jj,1) ) - epsi10 ) ) 
-!            IF( ( ABS( d_v_i_trp(ji,jj,1) ) / MAX( ABS( d_a_i_trp(ji,jj,1) ), epsi10 ) * zindb .GT. zhimax ) &
-!              &   .AND.( ( v_i(ji,jj,1) / MAX( a_i(ji,jj,1), epsi10 ) * zindb ) .GT. zhimax ) &
-!              &   .AND.( zat_i_old .LT. 1.e-6 ) )  THEN ! new line
-!               ht_i(ji,jj,1) = hi_max(1) * 0.5_wp
-!               a_i (ji,jj,1) = v_i(ji,jj,1) / ht_i(ji,jj,1)
-!            ENDIF
-!         END DO
-!      END DO
-!
-!      zhimax = 20._wp
-!      ! other categories
-!      DO jl = 2, jpl
-!         jm = ice_types(jl)
-!         DO jj = 1, jpj
-!            DO ji = 1, jpi
-!               zindb =  MAX( rzero, SIGN( rone, ABS( d_a_i_trp(ji,jj,jl) ) - epsi10 ) ) 
-!               ! this correction is very tricky... sometimes, advection gets wrong i don't know why
-!               ! it makes problems when the advected volume and concentration do not seem to be 
-!               ! related with each other
-!               ! the new thickness is sometimes very big!
-!               ! and sometimes d_a_i_trp and d_v_i_trp have different sign
-!               ! which of course is plausible
-!               ! but fuck! it fucks everything up :)
-!               IF ( ( ABS( d_v_i_trp(ji,jj,jl) ) / MAX( ABS( d_a_i_trp(ji,jj,jl) ), epsi10 ) * zindb .GT. zhimax ) &
-!                  &  .AND. ( v_i(ji,jj,jl) / MAX( a_i(ji,jj,jl), epsi10 ) * zindb ) .GT. zhimax ) THEN
-!                  ht_i(ji,jj,jl) = ( hi_max_typ(jl-ice_cat_bounds(jm,1),jm) + hi_max_typ(jl-ice_cat_bounds(jm,1)+1,jm) ) * 0.5_wp
-!                  a_i (ji,jj,jl) = v_i(ji,jj,jl) / ht_i(ji,jj,jl)
-!               ENDIF
-!            END DO ! ji
-!         END DO !jj
-!      END DO !jl
      
+      !----------------------------------------------------
+      ! Rebin categories with thickness out of bounds
+      !----------------------------------------------------
+      IF ( jpl > 1 )   CALL lim_itd_th_reb(1, jpl)
+
       at_i(:,:) = 0._wp
       DO jl = 1, jpl
@@ -190,10 +100,15 @@
 
       !----------------------------------------------------
-      ! 2.2) Rebin categories with thickness out of bounds
-      !----------------------------------------------------
-      DO jm = 1, jpm
-         jbnd1 = ice_cat_bounds(jm,1)
-         jbnd2 = ice_cat_bounds(jm,2)
-         IF (ice_ncat_types(jm) .GT. 1 )   CALL lim_itd_th_reb(jbnd1, jbnd2, jm)
+      ! ice concentration should not exceed amax 
+      !-----------------------------------------------------
+      DO jl  = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( at_i(ji,jj) > amax .AND. a_i(ji,jj,jl) > 0._wp ) THEN
+                  a_i(ji,jj,jl)  = a_i(ji,jj,jl) * ( 1._wp - ( 1._wp - amax / at_i(ji,jj) ) )
+                  ht_i(ji,jj,jl) = v_i(ji,jj,jl) / a_i(ji,jj,jl)
+               ENDIF
+            END DO
+         END DO
       END DO
 
@@ -202,190 +117,50 @@
          at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
       END DO
-
-      zbigvalue      = 1.0e+20
-
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-
-               !switches
-               zindb         = MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - epsi10 ) ) 
-               !switch = 1 if a_i > 1e-06 and 0 if not
-               zindsn        = MAX( rzero, SIGN( rone, v_s(ji,jj,jl) - epsi10 ) ) !=1 if hs > 1e-10 and 0 if not
-               zindic        = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) ) !=1 if hi > 1e-10 and 0 if not
-               ! bug fix 25 avril 2007
-               zindb         = zindb*zindic
-
-               !--- 2.3 Correction to ice age 
-               !------------------------------
-               !                IF ((o_i(ji,jj,jl)-1.0)*rday.gt.(rdt_ice*float(numit))) THEN
-               !                   o_i(ji,jj,jl) = rdt_ice*FLOAT(numit)/rday
-               !                ENDIF
-               IF ((oa_i(ji,jj,jl)-1.0)*rday.gt.(rdt_ice*numit*a_i(ji,jj,jl))) THEN
-                  oa_i(ji,jj,jl) = rdt_ice*numit/rday*a_i(ji,jj,jl)
-               ENDIF
-               oa_i(ji,jj,jl) = zindb*zindic*oa_i(ji,jj,jl)
-
-               !--- 2.4 Correction to snow thickness
-               !-------------------------------------
-               !          ! snow thickness has to be greater than 0, and if ice concentration smaller than 1e-6 then hs = 0
-               !             v_s(ji,jj,jl)  = MAX( zindb * v_s(ji,jj,jl), 0.0) 
-               ! snow thickness cannot be smaller than 1e-6
-               zdvres = (zindsn * zindb - 1._wp) * v_s(ji,jj,jl)
-               v_s(ji,jj,jl) = v_s(ji,jj,jl) + zdvres
-
-               !rdm_snw(ji,jj) = rdm_snw(ji,jj) + zdvres * rhosn
- 
-               !--- 2.5 Correction to ice thickness
-               !-------------------------------------
-               zdvres = (zindb - 1._wp) * v_i(ji,jj,jl)
-               v_i(ji,jj,jl) = v_i(ji,jj,jl) + zdvres
-
-               !rdm_ice(ji,jj) = rdm_ice(ji,jj) + zdvres * rhoic
-               !sfx_res(ji,jj)  = sfx_res(ji,jj) - sm_i(ji,jj,jl) * ( rhoic * zdvres / rdt_ice )
-
-               !--- 2.6 Snow is transformed into ice if the original ice cover disappears
-               !----------------------------------------------------------------------------
-               zindg          = tms(ji,jj) *  MAX( 0._wp, SIGN( 1._wp, -v_i(ji,jj,jl) ) )
-               zdvres         = zindg * rhosn * v_s(ji,jj,jl) / rau0
-               v_i(ji,jj,jl)  = v_i(ji,jj,jl)  + zdvres
-
-               zdvres         = zindsn*zindb * ( - zindg * v_s(ji,jj,jl) + zindg * v_i(ji,jj,jl) * ( rau0 - rhoic ) / rhosn )
-               v_s(ji,jj,jl)  = v_s(ji,jj,jl)  + zdvres
-
-               !--- 2.7 Correction to ice concentrations 
-               !--------------------------------------------
-               ! if greater than 0, ice concentration cannot be smaller than 1e-10
-               a_i(ji,jj,jl) = zindb * a_i(ji,jj,jl)
-
-               !-------------------------
-               ! 2.8) Snow heat content
-               !-------------------------
-               e_s(ji,jj,1,jl) = zindsn * ( MIN ( MAX ( 0._wp, e_s(ji,jj,1,jl) ), zbigvalue ) )
-
-            END DO ! ji
-         END DO ! jj
-      END DO ! jl
-
-      !------------------------
-      ! 2.9) Ice heat content 
-      !------------------------
-
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
+    
+      ! --------------------------------------
+      ! Final thickness distribution rebinning
+      ! --------------------------------------
+      IF ( jpl > 1 ) CALL lim_itd_th_reb(1, jpl)
+
+      !-----------------
+      ! zap small values
+      !-----------------
+      CALL lim_itd_me_zapsmall
+
+      !---------------------
+      ! Ice salinity bounds
+      !---------------------
+      IF (  num_sal == 2  ) THEN 
+         DO jl = 1, jpl
             DO jj = 1, jpj 
                DO ji = 1, jpi
-                  zindic        = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) ) 
-                  e_i(ji,jj,jk,jl)= zindic * ( MIN ( MAX ( 0.0, e_i(ji,jj,jk,jl) ), zbigvalue ) )
-               END DO ! ji
-            END DO ! jj
-         END DO !jk
-      END DO !jl
- 
-      at_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      !--- 2.13 ice concentration should not exceed amax 
-      !         (it should not be the case) 
-      !-----------------------------------------------------
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            z_da_ex =  MAX( at_i(ji,jj) - amax , 0.0 )        
-            zindb   =  MAX( rzero, SIGN( rone, at_i(ji,jj) - epsi10 ) ) 
-            DO jl  = 1, jpl
-               z_da_i = a_i(ji,jj,jl) * z_da_ex / MAX( at_i(ji,jj), epsi10 ) * zindb
-               a_i(ji,jj,jl) = MAX( 0._wp, a_i(ji,jj,jl) - z_da_i )
-               !
-               zinda   =  MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - epsi10 ) ) 
-               ht_i(ji,jj,jl) = v_i(ji,jj,jl) / MAX( a_i(ji,jj,jl), epsi10 ) * zinda
-               !v_i(ji,jj,jl) = ht_i(ji,jj,jl) * a_i(ji,jj,jl) ! makes ice shrinken but should not be used
+                  zsal            = smv_i(ji,jj,jl)
+                  smv_i(ji,jj,jl) = sm_i(ji,jj,jl) * v_i(ji,jj,jl)
+                  ! salinity stays in bounds
+                  i_ice_switch    = 1._wp - MAX( 0._wp, SIGN( 1._wp, - v_i(ji,jj,jl) ) )
+                  smv_i(ji,jj,jl) = i_ice_switch * MAX( MIN( s_i_max * v_i(ji,jj,jl), smv_i(ji,jj,jl) ), s_i_min * v_i(ji,jj,jl) )
+                  ! associated salt flux
+                  sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsal ) * rhoic * r1_rdtice
+               END DO
             END DO
          END DO
-      END DO
-      at_i(:,:) = a_i(:,:,1)
-      DO jl = 2, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-
-      ! Final thickness distribution rebinning
-      ! --------------------------------------
-      DO jm = 1, jpm
-         jbnd1 = ice_cat_bounds(jm,1)
-         jbnd2 = ice_cat_bounds(jm,2)
-         IF (ice_ncat_types(jm) .GT. 1 ) CALL lim_itd_th_reb(jbnd1, jbnd2, jm)
-         IF (ice_ncat_types(jm) .EQ. 1 ) THEN
-         ENDIF
-      END DO
-
-
-      !---------------------
-      ! 2.11) Ice salinity
-      !---------------------
-      ! clem correct bug on smv_i
-      smv_i(:,:,:) = sm_i(:,:,:) * v_i(:,:,:)
-
-      IF (  num_sal == 2  ) THEN ! general case
-         DO jl = 1, jpl
-            !DO jk = 1, nlay_i
-               DO jj = 1, jpj 
-                  DO ji = 1, jpi
-                     ! salinity stays in bounds
-                     !clem smv_i(ji,jj,jl)  =  MAX(MIN((rhoic-rhosn)/rhoic*sss_m(ji,jj),smv_i(ji,jj,jl)),0.1 * v_i(ji,jj,jl) )
-                     smv_i(ji,jj,jl) = MAX( MIN( s_i_max * v_i(ji,jj,jl), smv_i(ji,jj,jl) ), s_i_min * v_i(ji,jj,jl) )
-                     i_ice_switch    = 1._wp - MAX( 0._wp, SIGN( 1._wp, -v_i(ji,jj,jl) ) )
-                     smv_i(ji,jj,jl) = i_ice_switch * smv_i(ji,jj,jl) !+ s_i_min * ( 1._wp - i_ice_switch ) * v_i(ji,jj,jl)
-                  END DO ! ji
-               END DO ! jj
-            !END DO !jk
-         END DO !jl
       ENDIF
 
-      at_i(:,:) = a_i(:,:,1)
-      DO jl = 2, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-
-      !--------------------------------
-      ! Update mass/salt fluxes (clem)
-      !--------------------------------
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               diag_res_pr(ji,jj) = diag_res_pr(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) / rdt_ice 
-               rdm_ice(ji,jj) = rdm_ice(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) * rhoic 
-               rdm_snw(ji,jj) = rdm_snw(ji,jj) + ( v_s(ji,jj,jl) - zvsold(ji,jj,jl) ) * rhosn 
-               sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsmvold(ji,jj,jl) ) * rhoic / rdt_ice 
-            END DO
-         END DO
-      END DO
-  
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-
-         zchk_fs  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) * r1_rdtice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) * r1_rdtice + ( zchk_fs / rhoic )
-
-         zchk_vmin = glob_min(v_i)
-         zchk_amax = glob_max(SUM(a_i,dim=3))
-         zchk_amin = glob_min(a_i)
-       
-         IF(lwp) THEN
-            IF ( ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limupdate1) = ',(zchk_v_i * rday)
-            IF ( ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limupdate1) = ',(zchk_smv * rday)
-            IF ( zchk_vmin <  0.            ) WRITE(numout,*) 'violation v_i<0  [mm]         (limupdate1) = ',(zchk_vmin * 1.e-3)
-            IF ( zchk_amax >  amax+epsi10   ) WRITE(numout,*) 'violation a_i>amax            (limupdate1) = ',zchk_amax
-            IF ( zchk_amin <  0.            ) WRITE(numout,*) 'violation a_i<0               (limupdate1) = ',zchk_amin
-         ENDIF
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
+      ! -------------------------------------------------
+      ! Diagnostics
+      ! -------------------------------------------------
+      d_u_ice_dyn(:,:)     = u_ice(:,:)     - u_ice_b(:,:)
+      d_v_ice_dyn(:,:)     = v_ice(:,:)     - v_ice_b(:,:)
+      d_a_i_trp  (:,:,:)   = a_i  (:,:,:)   - a_i_b  (:,:,:)
+      d_v_s_trp  (:,:,:)   = v_s  (:,:,:)   - v_s_b  (:,:,:)  
+      d_v_i_trp  (:,:,:)   = v_i  (:,:,:)   - v_i_b  (:,:,:)   
+      d_e_s_trp  (:,:,:,:) = e_s  (:,:,:,:) - e_s_b  (:,:,:,:)  
+      d_e_i_trp  (:,:,1:nlay_i,:) = e_i  (:,:,1:nlay_i,:) - e_i_b(:,:,1:nlay_i,:)
+      d_oa_i_trp (:,:,:)   = oa_i (:,:,:)   - oa_i_b (:,:,:)
+      d_smv_i_trp(:,:,:)   = 0._wp
+      IF(  num_sal == 2  ) d_smv_i_trp(:,:,:) = smv_i(:,:,:) - smv_i_b(:,:,:)
+
+      ! 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_ctl) THEN   ! Control print
@@ -400,5 +175,5 @@
          CALL prt_ctl(tab2d_1=u_ice      , clinfo1=' lim_update1  : u_ice       :', tab2d_2=v_ice      , clinfo2=' v_ice       :')
          CALL prt_ctl(tab2d_1=d_u_ice_dyn, clinfo1=' lim_update1  : d_u_ice_dyn :', tab2d_2=d_v_ice_dyn, clinfo2=' d_v_ice_dyn :')
-         CALL prt_ctl(tab2d_1=old_u_ice  , clinfo1=' lim_update1  : old_u_ice   :', tab2d_2=old_v_ice  , clinfo2=' old_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     :')
 
          DO jl = 1, jpl
@@ -413,26 +188,26 @@
             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=old_a_i    (:,:,jl)        , clinfo1= ' lim_update1  : old_a_i     : ')
+            CALL prt_ctl(tab2d_1=a_i_b      (:,:,jl)        , clinfo1= ' lim_update1  : a_i_b       : ')
             CALL prt_ctl(tab2d_1=d_a_i_trp  (:,:,jl)        , clinfo1= ' lim_update1  : d_a_i_trp   : ')
             CALL prt_ctl(tab2d_1=v_i        (:,:,jl)        , clinfo1= ' lim_update1  : v_i         : ')
-            CALL prt_ctl(tab2d_1=old_v_i    (:,:,jl)        , clinfo1= ' lim_update1  : old_v_i     : ')
+            CALL prt_ctl(tab2d_1=v_i_b      (:,:,jl)        , clinfo1= ' lim_update1  : v_i_b       : ')
             CALL prt_ctl(tab2d_1=d_v_i_trp  (:,:,jl)        , clinfo1= ' lim_update1  : d_v_i_trp   : ')
             CALL prt_ctl(tab2d_1=v_s        (:,:,jl)        , clinfo1= ' lim_update1  : v_s         : ')
-            CALL prt_ctl(tab2d_1=old_v_s    (:,:,jl)        , clinfo1= ' lim_update1  : old_v_s     : ')
+            CALL prt_ctl(tab2d_1=v_s_b      (:,:,jl)        , clinfo1= ' lim_update1  : v_s_b       : ')
             CALL prt_ctl(tab2d_1=d_v_s_trp  (:,:,jl)        , clinfo1= ' lim_update1  : d_v_s_trp   : ')
             CALL prt_ctl(tab2d_1=e_i        (:,:,1,jl)/1.0e9, clinfo1= ' lim_update1  : e_i1        : ')
-            CALL prt_ctl(tab2d_1=old_e_i    (:,:,1,jl)/1.0e9, clinfo1= ' lim_update1  : old_e_i1    : ')
+            CALL prt_ctl(tab2d_1=e_i_b      (:,:,1,jl)/1.0e9, clinfo1= ' lim_update1  : e_i1_b      : ')
             CALL prt_ctl(tab2d_1=d_e_i_trp  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update1  : de_i1_trp   : ')
             CALL prt_ctl(tab2d_1=e_i        (:,:,2,jl)/1.0e9, clinfo1= ' lim_update1  : e_i2        : ')
-            CALL prt_ctl(tab2d_1=old_e_i    (:,:,2,jl)/1.0e9, clinfo1= ' lim_update1  : old_e_i2    : ')
+            CALL prt_ctl(tab2d_1=e_i_b      (:,:,2,jl)/1.0e9, clinfo1= ' lim_update1  : e_i2_b      : ')
             CALL prt_ctl(tab2d_1=d_e_i_trp  (:,:,2,jl)/1.0e9, clinfo1= ' lim_update1  : de_i2_trp   : ')
             CALL prt_ctl(tab2d_1=e_s        (:,:,1,jl)      , clinfo1= ' lim_update1  : e_snow      : ')
-            CALL prt_ctl(tab2d_1=old_e_s    (:,:,1,jl)      , clinfo1= ' lim_update1  : old_e_snow  : ')
+            CALL prt_ctl(tab2d_1=e_s_b      (:,:,1,jl)      , clinfo1= ' lim_update1  : e_snow_b    : ')
             CALL prt_ctl(tab2d_1=d_e_s_trp  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update1  : d_e_s_trp   : ')
             CALL prt_ctl(tab2d_1=smv_i      (:,:,jl)        , clinfo1= ' lim_update1  : smv_i       : ')
-            CALL prt_ctl(tab2d_1=old_smv_i  (:,:,jl)        , clinfo1= ' lim_update1  : old_smv_i   : ')
+            CALL prt_ctl(tab2d_1=smv_i_b    (:,:,jl)        , clinfo1= ' lim_update1  : smv_i_b     : ')
             CALL prt_ctl(tab2d_1=d_smv_i_trp(:,:,jl)        , clinfo1= ' lim_update1  : d_smv_i_trp : ')
             CALL prt_ctl(tab2d_1=oa_i       (:,:,jl)        , clinfo1= ' lim_update1  : oa_i        : ')
-            CALL prt_ctl(tab2d_1=old_oa_i   (:,:,jl)        , clinfo1= ' lim_update1  : old_oa_i    : ')
+            CALL prt_ctl(tab2d_1=oa_i_b     (:,:,jl)        , clinfo1= ' lim_update1  : oa_i_b      : ')
             CALL prt_ctl(tab2d_1=d_oa_i_trp (:,:,jl)        , clinfo1= ' lim_update1  : d_oa_i_trp  : ')
 
@@ -446,7 +221,5 @@
          CALL prt_ctl_info(' - Heat / FW fluxes : ')
          CALL prt_ctl_info('   ~~~~~~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=fmmec  , clinfo1= ' lim_update1 : fmmec : ', tab2d_2=fhmec     , clinfo2= ' fhmec     : ')
          CALL prt_ctl(tab2d_1=sst_m  , clinfo1= ' lim_update1 : sst   : ', tab2d_2=sss_m     , clinfo2= ' sss       : ')
-         CALL prt_ctl(tab2d_1=fhbri  , clinfo1= ' lim_update1 : fhbri : ', tab2d_2=fheat_mec , clinfo2= ' fheat_mec : ')
 
          CALL prt_ctl_info(' ')
@@ -458,8 +231,5 @@
       ENDIF
    
-
-      CALL wrk_dealloc( jkmax, zthick0, zqm0 )
-
-      CALL wrk_dealloc( jpi,jpj,jpl,zviold, zvsold, zsmvold )   ! clem
+      ENDIF ! ln_limdyn
 
       IF( nn_timing == 1 )  CALL timing_stop('limupdate1')
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limupdate2.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limupdate2.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limupdate2.F90	(revision 4921)
@@ -5,4 +5,5 @@
    !!======================================================================
    !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
+   !!            3.6  !  2014-06  (C. Rousset)       Complete rewriting/cleaning
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -39,4 +40,5 @@
    USE lib_fortran     ! glob_sum
    USE timing          ! Timing
+   USE limcons        ! conservation tests
 
    IMPLICIT NONE
@@ -45,8 +47,7 @@
    PUBLIC   lim_update2   ! routine called by ice_step
 
-      REAL(wp)  ::   epsi10 = 1.e-10_wp   !    -       -
-      REAL(wp)  ::   rzero  = 0._wp       !    -       -
-      REAL(wp)  ::   rone   = 1._wp       !    -       -
-         
+   REAL(wp)  ::   epsi10 = 1.e-10_wp   !    -       -
+   REAL(wp)  ::   epsi20 = 1.e-20_wp   
+      
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
@@ -64,120 +65,46 @@
       !! ** Purpose :  Computes update of sea-ice global variables at 
       !!               the end of the time step.
-      !!               Address pathological cases
-      !!               This place is very important
-      !!                
-      !! ** Method  :  
-      !!    Ice speed from ice dynamics
-      !!    Ice thickness, Snow thickness, Temperatures, Lead fraction
-      !!      from advection and ice thermodynamics 
       !!
-      !! ** Action  : - 
       !!---------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk, jl, jm    ! dummy loop indices
-      INTEGER ::   jbnd1, jbnd2
-      INTEGER ::   i_ice_switch
-      INTEGER ::   ind_im, layer      ! indices for internal melt
-      REAL(wp) ::   zweight, zesum, zhimax, z_da_i
-      REAL(wp) ::   zinda, zindb, zindsn, zindic
-      REAL(wp) ::   zindg, zh, zdvres, zviold2
-      REAL(wp) ::   zbigvalue, zvsold2, z_da_ex
-      REAL(wp) ::   z_prescr_hi, zat_i_old, ztmelts, ze_s
-
-      INTEGER , POINTER, DIMENSION(:,:,:) ::  internal_melt
-      REAL(wp), POINTER, DIMENSION(:) ::   zthick0, zqm0      ! thickness of the layers and heat contents for
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-      REAL(wp) :: zchk_vmin, zchk_amin, zchk_amax ! Check errors (C Rousset)
-      ! mass and salt flux (clem)
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zviold, zvsold, zsmvold   ! old ice volume...
+      INTEGER  ::   ji, jj, jk, jl    ! dummy loop indices
+      INTEGER  ::   i_ice_switch
+      REAL(wp) ::   zh, zsal
+      !
+      REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
       !!-------------------------------------------------------------------
       IF( nn_timing == 1 )  CALL timing_start('limupdate2')
 
-      CALL wrk_alloc( jpi,jpj,jpl, internal_melt )   ! integer
-      CALL wrk_alloc( jkmax, zthick0, zqm0 )
-
-      CALL wrk_alloc( jpi,jpj,jpl,zviold, zvsold, zsmvold )   ! clem
-
-      !----------------------------------------------------------------------------------------
-      ! 1. Computation of trend terms      
-      !----------------------------------------------------------------------------------------
-      !- Trend terms
-      d_a_i_thd(:,:,:)   = a_i(:,:,:)   - old_a_i(:,:,:) 
-      d_v_s_thd(:,:,:)   = v_s(:,:,:)   - old_v_s(:,:,:)
-      d_v_i_thd(:,:,:)   = v_i(:,:,:)   - old_v_i(:,:,:)  
-      d_e_s_thd(:,:,:,:) = e_s(:,:,:,:) - old_e_s(:,:,:,:) 
-      d_e_i_thd(:,:,:,:) = e_i(:,:,:,:) - old_e_i(:,:,:,:)
-      !?? d_oa_i_thd(:,:,:)  = oa_i (:,:,:) - old_oa_i (:,:,:)
-      d_smv_i_thd(:,:,:) = 0._wp
-      IF( num_sal == 2 )   d_smv_i_thd(:,:,:) = smv_i(:,:,:) - old_smv_i(:,:,:)
-      ! diag only (clem)
-      dv_dt_thd(:,:,:) = d_v_i_thd(:,:,:) * r1_rdtice * rday
-
-      ! mass and salt flux init (clem)
-      zviold(:,:,:) = v_i(:,:,:)
-      zvsold(:,:,:) = v_s(:,:,:)
-      zsmvold(:,:,:) = smv_i(:,:,:)
-
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) )
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
+      ! conservation test
+      IF( ln_limdiahsb ) CALL lim_cons_hsm(0, 'limupdate2', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      !-----------------
+      ! zap small values
+      !-----------------
+      CALL lim_itd_me_zapsmall
 
       CALL lim_var_glo2eqv
 
-      !--------------------------------------
-      ! 2. Review of all pathological cases
-      !--------------------------------------
-
-! clem: useless now
-      !-------------------------------------------
-      ! 2.1) Advection of ice in an ice-free cell
-      !-------------------------------------------
-      ! should be removed since it is treated after dynamics now
-!      zhimax = 5._wp
-!      ! first category
-!      DO jj = 1, jpj
-!         DO ji = 1, jpi
-!            !--- the thickness of such an ice is often out of bounds
-!            !--- thus we recompute a new area while conserving ice volume
-!            zat_i_old = SUM( old_a_i(ji,jj,:) )
-!            zindb     = MAX( 0._wp, SIGN( 1._wp, ABS( d_a_i_thd(ji,jj,1) ) - epsi10 ) ) 
-!            IF ( ( ABS( d_v_i_thd(ji,jj,1) ) / MAX( ABS( d_a_i_thd(ji,jj,1) ),epsi10 ) * zindb .GT. zhimax ) &
-!               &  .AND. ( ( v_i(ji,jj,1) / MAX( a_i(ji,jj,1), epsi10 ) * zindb ) .GT. zhimax ) &
-!               &  .AND. ( zat_i_old .LT. 1.e-6 ) )  THEN ! new line
-!               ht_i(ji,jj,1) = hi_max(1) * 0.5_wp
-!               a_i (ji,jj,1) = v_i(ji,jj,1) / ht_i(ji,jj,1)
-!            ENDIF
-!         END DO
-!      END DO
-
-!      zhimax = 20._wp
-!      ! other categories
-!      DO jl = 2, jpl
-!         jm = ice_types(jl)
-!         DO jj = 1, jpj
-!            DO ji = 1, jpi
-!               zindb =  MAX( rzero, SIGN( rone, ABS( d_a_i_thd(ji,jj,jl)) - epsi10 ) ) 
-!              ! this correction is very tricky... sometimes, advection gets wrong i don't know why
-!               ! it makes problems when the advected volume and concentration do not seem to be 
-!               ! related with each other
-!               ! the new thickness is sometimes very big!
-!               ! and sometimes d_a_i_trp and d_v_i_trp have different sign
-!               ! which of course is plausible
-!               ! but fuck! it fucks everything up :)
-!               IF ( ( ABS( d_v_i_thd(ji,jj,jl) ) / MAX( ABS( d_a_i_thd(ji,jj,jl) ), epsi10 ) * zindb .GT. zhimax ) &
-!                  &  .AND. ( v_i(ji,jj,jl) / MAX( a_i(ji,jj,jl), epsi10 ) * zindb ) .GT. zhimax ) THEN
-!                  ht_i(ji,jj,jl) = ( hi_max_typ(jl-ice_cat_bounds(jm,1),jm) + hi_max_typ(jl-ice_cat_bounds(jm,1)+1,jm) ) * 0.5_wp
-!                  a_i (ji,jj,jl) = v_i(ji,jj,jl) / ht_i(ji,jj,jl)
-!               ENDIF
-!            END DO ! ji
-!         END DO !jj
-!      END DO !jl
-     
+      !----------------------------------------------------
+      ! Rebin categories with thickness out of bounds
+      !----------------------------------------------------
+      IF ( jpl > 1 )   CALL lim_itd_th_reb(1, jpl)
+
+      !----------------------------------------------------------------------
+      ! Constrain the thickness of the smallest category above hiclim
+      !----------------------------------------------------------------------
+      DO jj = 1, jpj 
+         DO ji = 1, jpi
+            IF( v_i(ji,jj,1) > 0._wp .AND. ht_i(ji,jj,1) < hiclim ) THEN
+               zh             = hiclim / ht_i(ji,jj,1)
+               ht_s(ji,jj,1) = ht_s(ji,jj,1) * zh
+               ht_i(ji,jj,1) = ht_i(ji,jj,1) * zh
+               a_i (ji,jj,1) = a_i(ji,jj,1)  / zh
+            ENDIF
+         END DO
+      END DO
+      
+      !-----------------------------------------------------
+      ! ice concentration should not exceed amax 
+      !-----------------------------------------------------
       at_i(:,:) = 0._wp
       DO jl = 1, jpl
@@ -185,232 +112,14 @@
       END DO
 
-      !----------------------------------------------------
-      ! 2.2) Rebin categories with thickness out of bounds
-      !----------------------------------------------------
-      DO jm = 1, jpm
-         jbnd1 = ice_cat_bounds(jm,1)
-         jbnd2 = ice_cat_bounds(jm,2)
-         IF (ice_ncat_types(jm) .GT. 1 )   CALL lim_itd_th_reb(jbnd1, jbnd2, jm)
-      END DO
-
-      !---------------------------------
-      ! 2.3) Melt of an internal layer
-      !---------------------------------
-      internal_melt(:,:,:) = 0
-
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  ztmelts = - tmut * s_i(ji,jj,jk,jl) + rtt
-                  IF ( ( ( e_i(ji,jj,jk,jl) .LE. 0.0 ) .OR. ( t_i(ji,jj,jk,jl) .GE. ztmelts ) ) &
-                    & .AND. ( v_i(ji,jj,jl) .GT. 0.0 ) .AND. ( a_i(ji,jj,jl) .GT. 0.0 ) ) THEN
-                     internal_melt(ji,jj,jl) = 1
-                  ENDIF
-               END DO ! ji
-            END DO ! jj
-         END DO !jk
-      END DO !jl
-
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
+      DO jl  = 1, jpl
+         DO jj = 1, jpj
             DO ji = 1, jpi
-               IF( internal_melt(ji,jj,jl) == 1 ) THEN
-                  ! initial ice thickness
-                  !-----------------------
+               IF( at_i(ji,jj) > amax .AND. a_i(ji,jj,jl) > 0._wp ) THEN
+                  a_i(ji,jj,jl)  = a_i(ji,jj,jl) * ( 1._wp - ( 1._wp - amax / at_i(ji,jj) ) )
                   ht_i(ji,jj,jl) = v_i(ji,jj,jl) / a_i(ji,jj,jl)
-
-                  ! reduce ice thickness
-                  !-----------------------
-                  ind_im = 0
-                  zesum = 0.0
-                  DO jk = 1, nlay_i
-                     ztmelts = - tmut * s_i(ji,jj,jk,jl) + rtt
-                     IF ( ( e_i(ji,jj,jk,jl) .LE. 0.0 ) .OR. ( t_i(ji,jj,jk,jl) .GE. ztmelts ) ) ind_im = ind_im + 1
-                     zesum = zesum + e_i(ji,jj,jk,jl)
-                  END DO
-                  ht_i(ji,jj,jl) = ht_i(ji,jj,jl) - REAL(ind_im)*ht_i(ji,jj,jl) / REAL(nlay_i)
-                  v_i(ji,jj,jl)  = ht_i(ji,jj,jl) * a_i(ji,jj,jl)
-
-                  !CLEM
-                  zdvres = REAL(ind_im)*ht_i(ji,jj,jl) / REAL(nlay_i) * a_i(ji,jj,jl)
-                  !rdm_ice(ji,jj) = rdm_ice(ji,jj) - zdvres * rhoic
-                  !sfx_res(ji,jj)  = sfx_res(ji,jj) + sm_i(ji,jj,jl) * ( rhoic * zdvres / rdt_ice )
-
-                  ! redistribute heat
-                  !-----------------------
-                  ! old thicknesses and enthalpies
-                  ind_im = 0
-                  DO jk = 1, nlay_i
-                     ztmelts = - tmut * s_i(ji,jj,jk,jl) + rtt
-                     IF ( ( e_i(ji,jj,jk,jl) .GT. 0.0 ) .AND.  & 
-                        ( t_i(ji,jj,jk,jl) .LT. ztmelts ) ) THEN
-                        ind_im = ind_im + 1
-                        zthick0(ind_im) = ht_i(ji,jj,jl) * REAL(ind_im / nlay_i)
-                        zqm0   (ind_im) = MAX( e_i(ji,jj,jk,jl) , 0.0 )
-                     ENDIF
-                  END DO
-
-                  ! Redistributing energy on the new grid
-                  IF ( ind_im .GT. 0 ) THEN
-
-                     DO jk = 1, nlay_i
-                        e_i(ji,jj,jk,jl) = 0.0
-                        DO layer = 1, ind_im
-                           zweight         = MAX (  &
-                              MIN( ht_i(ji,jj,jl) * REAL(layer/ind_im) , ht_i(ji,jj,jl) * REAL(jk / nlay_i) ) -       &
-                              MAX( ht_i(ji,jj,jl) * REAL((layer-1)/ind_im) , ht_i(ji,jj,jl) * REAL((jk-1) / nlay_i) ) , 0.0 ) &
-                              /  ( ht_i(ji,jj,jl) / REAL(ind_im) )
-
-                           e_i(ji,jj,jk,jl) =  e_i(ji,jj,jk,jl) + zweight*zqm0(layer)
-                        END DO !layer
-                     END DO ! jk
-
-                     zesum = 0.0
-                     DO jk = 1, nlay_i
-                        zesum = zesum + e_i(ji,jj,jk,jl)
-                     END DO
-
-                  ELSE ! ind_im .EQ. 0, total melt
-                     e_i(ji,jj,jk,jl) = 0.0
-                  ENDIF
-
-               ENDIF ! internal_melt
-
-            END DO ! ji
-         END DO !jj
-      END DO !jl
-
-      internal_melt(:,:,:) = 0
-
-
-      ! Melt of snow
-      !--------------
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               ! snow energy of melting
-               zinda   =  MAX( 0._wp, SIGN( 1._wp, v_s(ji,jj,jl) - epsi10 ) )
-               ze_s = zinda * e_s(ji,jj,1,jl) * unit_fac / area(ji,jj) / MAX( v_s(ji,jj,jl), epsi10 )  ! snow energy of melting
-
-               ! If snow energy of melting smaller then Lf
-               ! Then all snow melts and meltwater, heat go to the ocean
-               IF ( ze_s .LE. rhosn * lfus ) internal_melt(ji,jj,jl) = 1
-
+               ENDIF
             END DO
          END DO
       END DO
-
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               IF ( internal_melt(ji,jj,jl) == 1 ) THEN
-                  zdvres = v_s(ji,jj,jl)
-                  ! release heat
-                  fheat_res(ji,jj) = fheat_res(ji,jj) + ze_s * zdvres / rdt_ice
-                  ! release mass
-                  !rdm_snw(ji,jj) =  rdm_snw(ji,jj) - zdvres * rhosn
-                  !
-                  v_s(ji,jj,jl)   = 0.0
-                  e_s(ji,jj,1,jl) = 0.0
-                 ENDIF
-            END DO
-         END DO
-      END DO
-
-      zbigvalue      = 1.0e+20
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-
-               !switches
-               zindb         = MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - epsi10 ) ) 
-               !switch = 1 if a_i > 1e-06 and 0 if not
-               zindsn        = MAX( rzero, SIGN( rone, v_s(ji,jj,jl) - epsi10 ) ) !=1 if hs > 1e-10 and 0 if not
-               zindic        = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) ) !=1 if hi > 1e-10 and 0 if not
-               ! bug fix 25 avril 2007
-               zindb         = zindb*zindic
-
-               !--- 2.3 Correction to ice age 
-               !------------------------------
-               !                IF ((o_i(ji,jj,jl)-1.0)*rday.gt.(rdt_ice*float(numit))) THEN
-               !                   o_i(ji,jj,jl) = rdt_ice*FLOAT(numit)/rday
-               !                ENDIF
-               IF ((oa_i(ji,jj,jl)-1.0)*rday.gt.(rdt_ice*numit*a_i(ji,jj,jl))) THEN
-                  oa_i(ji,jj,jl) = rdt_ice*numit/rday*a_i(ji,jj,jl)
-               ENDIF
-               oa_i(ji,jj,jl) = zindb*zindic*oa_i(ji,jj,jl)
-
-               !--- 2.4 Correction to snow thickness
-               !-------------------------------------
-               zdvres = (zindsn * zindb - 1._wp) * v_s(ji,jj,jl)
-               v_s(ji,jj,jl) = v_s(ji,jj,jl) + zdvres
-
-               !rdm_snw(ji,jj) = rdm_snw(ji,jj) + zdvres * rhosn
- 
-               !--- 2.5 Correction to ice thickness
-               !-------------------------------------
-               zdvres = (zindb - 1._wp) * v_i(ji,jj,jl)
-               v_i(ji,jj,jl) = v_i(ji,jj,jl) + zdvres
-
-               !rdm_ice(ji,jj) = rdm_ice(ji,jj) + zdvres * rhoic
-               !sfx_res(ji,jj)  = sfx_res(ji,jj) - sm_i(ji,jj,jl) * ( rhoic * zdvres / rdt_ice )
-
-               !--- 2.6 Snow is transformed into ice if the original ice cover disappears
-               !----------------------------------------------------------------------------
-               zindg          = tms(ji,jj) *  MAX( 0._wp, SIGN( 1._wp, -v_i(ji,jj,jl) ) )
-               zdvres         = zindg * rhosn * v_s(ji,jj,jl) / rau0
-               v_i(ji,jj,jl)  = v_i(ji,jj,jl)  + zdvres
-
-               zdvres         = zindsn*zindb * ( - zindg * v_s(ji,jj,jl) + zindg * v_i(ji,jj,jl) * ( rau0 - rhoic ) / rhosn )
-               v_s(ji,jj,jl)  = v_s(ji,jj,jl)  + zdvres
-
-               !--- 2.7 Correction to ice concentrations 
-               !--------------------------------------------
-               a_i(ji,jj,jl) = zindb * a_i(ji,jj,jl)
-
-               !-------------------------
-               ! 2.8) Snow heat content
-               !-------------------------
-               e_s(ji,jj,1,jl) = zindsn * ( MIN ( MAX ( 0.0, e_s(ji,jj,1,jl) ), zbigvalue ) )
-
-            END DO ! ji
-         END DO ! jj
-      END DO ! jl
-
-      !------------------------
-      ! 2.9) Ice heat content 
-      !------------------------
-
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  zindic        = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) ) 
-                  e_i(ji,jj,jk,jl)= zindic * ( MIN ( MAX ( 0.0, e_i(ji,jj,jk,jl) ), zbigvalue ) )
-               END DO ! ji
-            END DO ! jj
-         END DO !jk
-      END DO !jl
-
-
-      DO jm = 1, jpm
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               jl = ice_cat_bounds(jm,1)
-               !--- 2.12 Constrain the thickness of the smallest category above 5 cm
-               !----------------------------------------------------------------------
-               zindb         = MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - epsi10 ) ) 
-               ht_i(ji,jj,jl) = zindb*v_i(ji,jj,jl)/MAX(a_i(ji,jj,jl), epsi10)
-               zh            = MAX( rone , zindb * hiclim  / MAX( ht_i(ji,jj,jl) , epsi10 ) )
-               ht_s(ji,jj,jl) = ht_s(ji,jj,jl)* zh
-               ht_i(ji,jj,jl) = ht_i(ji,jj,jl)* zh
-               a_i (ji,jj,jl) = a_i(ji,jj,jl) / zh
-               !CLEM
-               v_i (ji,jj,jl) = a_i(ji,jj,jl) * ht_i(ji,jj,jl)
-               v_s (ji,jj,jl) = a_i(ji,jj,jl) * ht_s(ji,jj,jl)
-            END DO !ji
-         END DO !jj
-      END DO !jm
 
       at_i(:,:) = 0.0
@@ -418,64 +127,33 @@
          at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
       END DO
-      
-      !--- 2.13 ice concentration should not exceed amax 
-      !         (it should not be the case) 
-      !-----------------------------------------------------
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            z_da_ex =  MAX( at_i(ji,jj) - amax , 0.0 )        
-            zindb   =  MAX( rzero, SIGN( rone, at_i(ji,jj) - epsi10 ) ) 
-            DO jl  = 1, jpl
-               z_da_i = a_i(ji,jj,jl) * z_da_ex / MAX( at_i(ji,jj), epsi10 ) * zindb
-               a_i(ji,jj,jl) = MAX( 0._wp, a_i(ji,jj,jl) - z_da_i )
-               !
-               zinda   =  MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - epsi10 ) ) 
-               ht_i(ji,jj,jl) = v_i(ji,jj,jl) / MAX( a_i(ji,jj,jl), epsi10 ) * zinda
-               !v_i(ji,jj,jl) = ht_i(ji,jj,jl) * a_i(ji,jj,jl) ! makes ice shrinken but should not be used
-            END DO
-         END DO
-      END DO
-      at_i(:,:) = 0.0
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
+
+      ! --------------------------------------
       ! Final thickness distribution rebinning
       ! --------------------------------------
-      DO jm = 1, jpm
-         jbnd1 = ice_cat_bounds(jm,1)
-         jbnd2 = ice_cat_bounds(jm,2)
-         IF (ice_ncat_types(jm) .GT. 1 ) CALL lim_itd_th_reb(jbnd1, jbnd2, jm)
-         IF (ice_ncat_types(jm) .EQ. 1 ) THEN
-         ENDIF
-      END DO
+      IF ( jpl > 1 ) CALL lim_itd_th_reb( 1, jpl )
+
+      !-----------------
+      ! zap small values
+      !-----------------
+      CALL lim_itd_me_zapsmall
 
       !---------------------
       ! 2.11) Ice salinity
       !---------------------
-      ! clem correct bug on smv_i
-      smv_i(:,:,:) = sm_i(:,:,:) * v_i(:,:,:)
-
-      IF (  num_sal == 2  ) THEN ! general case
+      IF (  num_sal == 2  ) THEN 
          DO jl = 1, jpl
-            !DO jk = 1, nlay_i
-               DO jj = 1, jpj 
-                  DO ji = 1, jpi
-                     ! salinity stays in bounds
-                     !clem smv_i(ji,jj,jl)  =  MAX(MIN((rhoic-rhosn)/rhoic*sss_m(ji,jj),smv_i(ji,jj,jl)),0.1 * v_i(ji,jj,jl) )
-                     smv_i(ji,jj,jl) = MAX( MIN( s_i_max * v_i(ji,jj,jl), smv_i(ji,jj,jl) ), s_i_min * v_i(ji,jj,jl) )
-                     i_ice_switch    = 1._wp - MAX( 0._wp, SIGN( 1._wp, -v_i(ji,jj,jl) ) )
-                     smv_i(ji,jj,jl) = i_ice_switch * smv_i(ji,jj,jl) !+ s_i_min * ( 1._wp - i_ice_switch ) * v_i(ji,jj,jl)
-                  END DO ! ji
-               END DO ! jj
-            !END DO !jk
+            DO jj = 1, jpj 
+               DO ji = 1, jpi
+                  zsal            = smv_i(ji,jj,jl)
+                  smv_i(ji,jj,jl) = sm_i(ji,jj,jl) * v_i(ji,jj,jl)
+                  ! salinity stays in bounds
+                  i_ice_switch    = 1._wp - MAX( 0._wp, SIGN( 1._wp, - v_i(ji,jj,jl) ) )
+                  smv_i(ji,jj,jl) = i_ice_switch * MAX( MIN( s_i_max * v_i(ji,jj,jl), smv_i(ji,jj,jl) ), s_i_min * v_i(ji,jj,jl) ) !+ s_i_min * ( 1._wp - i_ice_switch ) * v_i(ji,jj,jl)
+                  ! associated salt flux
+                  sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsal ) * rhoic * r1_rdtice
+               END DO ! ji
+            END DO ! jj
          END DO !jl
       ENDIF
-
-      ! -------------------
-      at_i(:,:) = a_i(:,:,1)
-      DO jl = 2, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
 
       !------------------------------------------------------------------------------
@@ -486,9 +164,9 @@
       DO jj = 2, jpjm1
          DO ji = 2, jpim1
-            IF ( at_i(ji,jj) .EQ. 0.0 ) THEN ! what to do if there is no ice
-               IF ( at_i(ji+1,jj) .EQ. 0.0 ) u_ice(ji,jj)   = 0.0 ! right side
-               IF ( at_i(ji-1,jj) .EQ. 0.0 ) u_ice(ji-1,jj) = 0.0 ! left side
-               IF ( at_i(ji,jj+1) .EQ. 0.0 ) v_ice(ji,jj)   = 0.0 ! upper side
-               IF ( at_i(ji,jj-1) .EQ. 0.0 ) v_ice(ji,jj-1) = 0.0 ! bottom side
+            IF ( at_i(ji,jj) == 0._wp ) THEN ! what to do if there is no ice
+               IF ( at_i(ji+1,jj) == 0._wp ) u_ice(ji,jj)   = 0._wp ! right side
+               IF ( at_i(ji-1,jj) == 0._wp ) u_ice(ji-1,jj) = 0._wp ! left side
+               IF ( at_i(ji,jj+1) == 0._wp ) v_ice(ji,jj)   = 0._wp ! upper side
+               IF ( at_i(ji,jj-1) == 0._wp ) v_ice(ji,jj-1) = 0._wp ! bottom side
             ENDIF
          END DO
@@ -501,42 +179,29 @@
       v_ice(:,:) = v_ice(:,:) * tmv(:,:)
  
-      !--------------------------------
-      ! Update mass/salt fluxes (clem)
-      !--------------------------------
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               diag_res_pr(ji,jj) = diag_res_pr(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) / rdt_ice 
-               rdm_ice(ji,jj) = rdm_ice(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) * rhoic 
-               rdm_snw(ji,jj) = rdm_snw(ji,jj) + ( v_s(ji,jj,jl) - zvsold(ji,jj,jl) ) * rhosn 
-               sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsmvold(ji,jj,jl) ) * rhoic / rdt_ice 
-            END DO
-         END DO
-      END DO
-
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-
-         zchk_fs  = glob_sum( ( sfx_bri(:,:) + sfx_thd(:,:) + sfx_res(:,:) + sfx_mec(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdm_ice(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) * r1_rdtice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) * r1_rdtice + ( zchk_fs / rhoic )
-
-         zchk_vmin = glob_min(v_i)
-         zchk_amax = glob_max(SUM(a_i,dim=3))
-         zchk_amin = glob_min(a_i)
-
-         IF(lwp) THEN
-            IF ( ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limupdate2) = ',(zchk_v_i * rday)
-            IF ( ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limupdate2) = ',(zchk_smv * rday)
-            IF ( zchk_vmin <  0.            ) WRITE(numout,*) 'violation v_i<0  [mm]         (limupdate2) = ',(zchk_vmin * 1.e-3)
-            IF ( zchk_amax >  amax+epsi10   ) WRITE(numout,*) 'violation a_i>amax            (limupdate2) = ',zchk_amax
-            IF ( zchk_amin <  0.            ) WRITE(numout,*) 'violation a_i<0               (limupdate2) = ',zchk_amin
-         ENDIF
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
+      ! -------------------------------------------------
+      ! Diagnostics
+      ! -------------------------------------------------
+      d_a_i_thd(:,:,:)   = a_i(:,:,:)   - a_i_b(:,:,:) 
+      d_v_s_thd(:,:,:)   = v_s(:,:,:)   - v_s_b(:,:,:)
+      d_v_i_thd(:,:,:)   = v_i(:,:,:)   - v_i_b(:,:,:)  
+      d_e_s_thd(:,:,:,:) = e_s(:,:,:,:) - e_s_b(:,:,:,:) 
+      d_e_i_thd(:,:,1:nlay_i,:) = e_i(:,:,1:nlay_i,:) - e_i_b(:,:,1:nlay_i,:)
+      !?? d_oa_i_thd(:,:,:)  = oa_i (:,:,:) - oa_i_b (:,:,:)
+      d_smv_i_thd(:,:,:) = 0._wp
+      IF( num_sal == 2 )   d_smv_i_thd(:,:,:) = smv_i(:,:,:) - smv_i_b(:,:,:)
+      ! diag only (clem)
+      dv_dt_thd(:,:,:) = d_v_i_thd(:,:,:) * r1_rdtice * rday
+
+      ! heat content variation (W.m-2)
+      DO jj = 1, jpj
+         DO ji = 1, jpi            
+            diag_heat_dhc(ji,jj) = ( SUM( d_e_i_trp(ji,jj,1:nlay_i,:) + d_e_i_thd(ji,jj,1:nlay_i,:) ) +  & 
+               &                     SUM( d_e_s_trp(ji,jj,1:nlay_s,:) + d_e_s_thd(ji,jj,1:nlay_s,:) )    &
+               &                   ) * unit_fac * r1_rdtice / area(ji,jj)   
+         END DO
+      END DO
+
+      ! 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_ctl) THEN   ! Control print
@@ -550,5 +215,5 @@
          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=old_u_ice  , clinfo1=' lim_update2  : old_u_ice   :', tab2d_2=old_v_ice  , clinfo2=' old_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
@@ -563,26 +228,26 @@
             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=old_a_i    (:,:,jl)        , clinfo1= ' lim_update2  : old_a_i     : ')
+            CALL prt_ctl(tab2d_1=a_i_b      (:,:,jl)        , clinfo1= ' lim_update2  : a_i_b       : ')
             CALL prt_ctl(tab2d_1=d_a_i_thd  (:,:,jl)        , clinfo1= ' lim_update2  : d_a_i_thd   : ')
             CALL prt_ctl(tab2d_1=v_i        (:,:,jl)        , clinfo1= ' lim_update2  : v_i         : ')
-            CALL prt_ctl(tab2d_1=old_v_i    (:,:,jl)        , clinfo1= ' lim_update2  : old_v_i     : ')
+            CALL prt_ctl(tab2d_1=v_i_b      (:,:,jl)        , clinfo1= ' lim_update2  : v_i_b       : ')
             CALL prt_ctl(tab2d_1=d_v_i_thd  (:,:,jl)        , clinfo1= ' lim_update2  : d_v_i_thd   : ')
             CALL prt_ctl(tab2d_1=v_s        (:,:,jl)        , clinfo1= ' lim_update2  : v_s         : ')
-            CALL prt_ctl(tab2d_1=old_v_s    (:,:,jl)        , clinfo1= ' lim_update2  : old_v_s     : ')
+            CALL prt_ctl(tab2d_1=v_s_b      (:,:,jl)        , clinfo1= ' lim_update2  : v_s_b       : ')
             CALL prt_ctl(tab2d_1=d_v_s_thd  (:,:,jl)        , clinfo1= ' lim_update2  : d_v_s_thd   : ')
             CALL prt_ctl(tab2d_1=e_i        (:,:,1,jl)/1.0e9, clinfo1= ' lim_update2  : e_i1        : ')
-            CALL prt_ctl(tab2d_1=old_e_i    (:,:,1,jl)/1.0e9, clinfo1= ' lim_update2  : old_e_i1    : ')
+            CALL prt_ctl(tab2d_1=e_i_b      (:,:,1,jl)/1.0e9, clinfo1= ' lim_update2  : e_i1_b      : ')
             CALL prt_ctl(tab2d_1=d_e_i_thd  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update2  : de_i1_thd   : ')
             CALL prt_ctl(tab2d_1=e_i        (:,:,2,jl)/1.0e9, clinfo1= ' lim_update2  : e_i2        : ')
-            CALL prt_ctl(tab2d_1=old_e_i    (:,:,2,jl)/1.0e9, clinfo1= ' lim_update2  : old_e_i2    : ')
+            CALL prt_ctl(tab2d_1=e_i_b      (:,:,2,jl)/1.0e9, clinfo1= ' lim_update2  : e_i2_b      : ')
             CALL prt_ctl(tab2d_1=d_e_i_thd  (:,:,2,jl)/1.0e9, clinfo1= ' lim_update2  : de_i2_thd   : ')
             CALL prt_ctl(tab2d_1=e_s        (:,:,1,jl)      , clinfo1= ' lim_update2  : e_snow      : ')
-            CALL prt_ctl(tab2d_1=old_e_s    (:,:,1,jl)      , clinfo1= ' lim_update2  : old_e_snow  : ')
+            CALL prt_ctl(tab2d_1=e_s_b      (:,:,1,jl)      , clinfo1= ' lim_update2  : e_snow_b    : ')
             CALL prt_ctl(tab2d_1=d_e_s_thd  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update2  : d_e_s_thd   : ')
             CALL prt_ctl(tab2d_1=smv_i      (:,:,jl)        , clinfo1= ' lim_update2  : smv_i       : ')
-            CALL prt_ctl(tab2d_1=old_smv_i  (:,:,jl)        , clinfo1= ' lim_update2  : old_smv_i   : ')
+            CALL prt_ctl(tab2d_1=smv_i_b    (:,:,jl)        , clinfo1= ' lim_update2  : smv_i_b     : ')
             CALL prt_ctl(tab2d_1=d_smv_i_thd(:,:,jl)        , clinfo1= ' lim_update2  : d_smv_i_thd : ')
             CALL prt_ctl(tab2d_1=oa_i       (:,:,jl)        , clinfo1= ' lim_update2  : oa_i        : ')
-            CALL prt_ctl(tab2d_1=old_oa_i   (:,:,jl)        , clinfo1= ' lim_update2  : old_oa_i    : ')
+            CALL prt_ctl(tab2d_1=oa_i_b     (:,:,jl)        , clinfo1= ' lim_update2  : oa_i_b      : ')
             CALL prt_ctl(tab2d_1=d_oa_i_thd (:,:,jl)        , clinfo1= ' lim_update2  : d_oa_i_thd  : ')
 
@@ -596,7 +261,5 @@
          CALL prt_ctl_info(' - Heat / FW fluxes : ')
          CALL prt_ctl_info('   ~~~~~~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=fmmec  , clinfo1= ' lim_update2 : fmmec : ', tab2d_2=fhmec     , clinfo2= ' fhmec     : ')
          CALL prt_ctl(tab2d_1=sst_m  , clinfo1= ' lim_update2 : sst   : ', tab2d_2=sss_m     , clinfo2= ' sss       : ')
-         CALL prt_ctl(tab2d_1=fhbri  , clinfo1= ' lim_update2 : fhbri : ', tab2d_2=fheat_mec , clinfo2= ' fheat_mec : ')
 
          CALL prt_ctl_info(' ')
@@ -608,10 +271,6 @@
       ENDIF
    
-      CALL wrk_dealloc( jpi,jpj,jpl, internal_melt )   ! integer
-      CALL wrk_dealloc( jkmax, zthick0, zqm0 )
-
-      CALL wrk_dealloc( jpi,jpj,jpl,zviold, zvsold, zsmvold )   ! clem
-
       IF( nn_timing == 1 )  CALL timing_stop('limupdate2')
+
    END SUBROUTINE lim_update2
 #else
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90	(revision 4921)
@@ -67,6 +67,4 @@
 
    REAL(wp) ::   epsi10 = 1.e-10_wp   !    -       -
-   REAL(wp) ::   zzero = 0.e0        !    -       -
-   REAL(wp) ::   zone  = 1.e0        !    -       -
 
    !!----------------------------------------------------------------------
@@ -113,5 +111,5 @@
                at_i(ji,jj) = at_i(ji,jj) + a_i(ji,jj,jl) ! ice concentration
                !
-               zinda = MAX( zzero , SIGN( zone , at_i(ji,jj) - epsi10 ) ) 
+               zinda = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) ) 
                icethi(ji,jj) = vt_i(ji,jj) / MAX( at_i(ji,jj) , epsi10 ) * zinda  ! ice thickness
             END DO
@@ -134,6 +132,6 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zinda = MAX( zzero , SIGN( zone , vt_i(ji,jj) - epsi10 ) ) 
-                  zindb = MAX( zzero , SIGN( zone , at_i(ji,jj) - epsi10 ) ) 
+                  zinda = MAX( 0._wp , SIGN( 1._wp , vt_i(ji,jj) - epsi10 ) ) 
+                  zindb = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) ) 
                   et_s(ji,jj)  = et_s(ji,jj)  + e_s(ji,jj,1,jl)                                       ! snow heat content
                   smt_i(ji,jj) = smt_i(ji,jj) + smv_i(ji,jj,jl) / MAX( vt_i(ji,jj) , epsi10 ) * zinda   ! ice salinity
@@ -205,7 +203,7 @@
                DO ji = 1, jpi
                   !                                                              ! Energy of melting q(S,T) [J.m-3]
-                  zq_i    = e_i(ji,jj,jk,jl) / area(ji,jj) / MAX( v_i(ji,jj,jl) , epsi10 ) * REAL(nlay_i,wp) 
                   zindb   = 1.0 - MAX( 0.0 , SIGN( 1.0 , - v_i(ji,jj,jl) + epsi10 ) )     ! zindb = 0 if no ice and 1 if yes
-                  zq_i    = zq_i * unit_fac * zindb                              !convert units
+                  zq_i    = zindb * e_i(ji,jj,jk,jl) / area(ji,jj) / MAX( v_i(ji,jj,jl) , epsi10 ) * REAL(nlay_i,wp) 
+                  zq_i    = zq_i * unit_fac                             !convert units
                   ztmelts = -tmut * s_i(ji,jj,jk,jl) + rtt                       ! Ice layer melt temperature
                   !
@@ -231,7 +229,7 @@
                DO ji = 1, jpi
                   !Energy of melting q(S,T) [J.m-3]
-                  zq_s  = e_s(ji,jj,jk,jl) / ( area(ji,jj) * MAX( v_s(ji,jj,jl) , epsi10 ) ) * REAL(nlay_s,wp)
                   zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - v_s(ji,jj,jl) + epsi10 ) )     ! zindb = 0 if no ice and 1 if yes
-                  zq_s  = zq_s * unit_fac * zindb                                    ! convert units
+                  zq_s  = zindb * e_s(ji,jj,jk,jl) / ( area(ji,jj) * MAX( v_s(ji,jj,jl) , epsi10 ) ) * REAL(nlay_s,wp)
+                  zq_s  = zq_s * unit_fac                                    ! convert units
                   !
                   t_s(ji,jj,jk,jl) = rtt + zindb * ( - zfac1 * zq_s + zfac2 )
@@ -320,5 +318,5 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  z_slope_s(ji,jj,jl) = 2._wp * sm_i(ji,jj,jl) / MAX( 0.01 , ht_i(ji,jj,jl) )
+                  z_slope_s(ji,jj,jl) = 2._wp * sm_i(ji,jj,jl) / MAX( epsi10 , ht_i(ji,jj,jl) )
                END DO
             END DO
@@ -466,5 +464,5 @@
       ! Vertically constant, constant in time
       !---------------------------------------
-      IF( num_sal == 1 )   s_i_b(:,:) = bulk_sal
+      IF( num_sal == 1 )   s_i_1d(:,:) = bulk_sal
 
       !------------------------------------------------------
@@ -475,5 +473,5 @@
          !
          DO ji = kideb, kiut          ! Slope of the linear profile zs_zero
-            z_slope_s(ji) = 2._wp * sm_i_b(ji) / MAX( 0.01 , ht_i_b(ji) )
+            z_slope_s(ji) = 2._wp * sm_i_1d(ji) / MAX( epsi10 , ht_i_1d(ji) )
          END DO
 
@@ -491,16 +489,16 @@
                ij =     ( npb(ji) - 1 ) / jpi + 1
                ! zind0 = 1 if sm_i le s_i_0 and 0 otherwise
-               zind0  = MAX( 0._wp , SIGN( 1._wp  , s_i_0 - sm_i_b(ji) ) ) 
+               zind0  = MAX( 0._wp , SIGN( 1._wp  , s_i_0 - sm_i_1d(ji) ) ) 
                ! zind01 = 1 if sm_i is between s_i_0 and s_i_1 and 0 othws 
-               zind01 = ( 1._wp - zind0 ) * MAX( 0._wp , SIGN( 1._wp , s_i_1 - sm_i_b(ji) ) ) 
+               zind01 = ( 1._wp - zind0 ) * MAX( 0._wp , SIGN( 1._wp , s_i_1 - sm_i_1d(ji) ) ) 
                ! if 2.sm_i GE sss_m then zindbal = 1
                ! this is to force a constant salinity profile in the Baltic Sea
-               zindbal = MAX( 0._wp , SIGN( 1._wp , 2._wp * sm_i_b(ji) - sss_m(ii,ij) ) )
+               zindbal = MAX( 0._wp , SIGN( 1._wp , 2._wp * sm_i_1d(ji) - sss_m(ii,ij) ) )
                !
-               zalpha = (  zind0 + zind01 * ( sm_i_b(ji) * dummy_fac0 + dummy_fac1 )  ) * ( 1.0 - zindbal )
+               zalpha = (  zind0 + zind01 * ( sm_i_1d(ji) * dummy_fac0 + dummy_fac1 )  ) * ( 1.0 - zindbal )
                !
-               zs_zero = z_slope_s(ji) * ( REAL(jk,wp) - 0.5_wp ) * ht_i_b(ji) * dummy_fac2
+               zs_zero = z_slope_s(ji) * ( REAL(jk,wp) - 0.5_wp ) * ht_i_1d(ji) * dummy_fac2
                ! weighting the profile
-               s_i_b(ji,jk) = zalpha * zs_zero + ( 1._wp - zalpha ) * sm_i_b(ji)
+               s_i_1d(ji,jk) = zalpha * zs_zero + ( 1._wp - zalpha ) * sm_i_1d(ji)
             END DO ! ji
          END DO ! jk
@@ -514,5 +512,5 @@
       IF( num_sal == 3 ) THEN      ! Schwarzacher (1959) multiyear salinity profile (mean = 2.30)
          !
-         sm_i_b(:) = 2.30_wp
+         sm_i_1d(:) = 2.30_wp
          !
 !CDIR NOVERRCHK
@@ -521,5 +519,5 @@
             zsal =  1.6_wp * (  1._wp - COS( rpi * zargtemp**(0.407_wp/(0.573_wp+zargtemp)) )  )
             DO ji = kideb, kiut
-               s_i_b(ji,jk) = zsal
+               s_i_1d(ji,jk) = zsal
             END DO
          END DO
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90	(revision 4921)
@@ -9,5 +9,4 @@
    !!----------------------------------------------------------------------
    !!   lim_wri      : write of the diagnostics variables in ouput file 
-   !!   lim_wri_init : initialization and namelist read
    !!   lim_wri_state : write for initial state or/and abandon
    !!----------------------------------------------------------------------
@@ -36,23 +35,5 @@
    PUBLIC lim_wri_state  ! called by dia_wri_state 
 
-   INTEGER, PARAMETER ::   jpnoumax = 43   !: maximum number of variable for ice output
-   
-   INTEGER  ::   noumef             ! number of fields
-   INTEGER  ::   noumefa            ! number of additional fields
-   INTEGER  ::   add_diag_swi       ! additional diagnostics
-   INTEGER  ::   nz                                         ! dimension for the itd field
-
-   REAL(wp) , DIMENSION(jpnoumax) ::   cmulti         ! multiplicative constant
-   REAL(wp) , DIMENSION(jpnoumax) ::   cadd           ! additive constant
-   REAL(wp) , DIMENSION(jpnoumax) ::   cmultia        ! multiplicative constant
-   REAL(wp) , DIMENSION(jpnoumax) ::   cadda          ! additive constant
-   CHARACTER(len = 35), DIMENSION(jpnoumax) ::   titn, titna   ! title of the field
-   CHARACTER(len = 8 ), DIMENSION(jpnoumax) ::   nam , nama    ! name of the field
-   CHARACTER(len = 8 ), DIMENSION(jpnoumax) ::   uni , unia    ! unit of the field
-   INTEGER            , DIMENSION(jpnoumax) ::   nc  , nca     ! switch for saving field ( = 1 ) or not ( = 0 )
-
    REAL(wp)  ::   epsi06 = 1.e-6_wp
-   REAL(wp)  ::   zzero  = 0._wp
-   REAL(wp)  ::   zone   = 1._wp      
    !!----------------------------------------------------------------------
    !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
@@ -78,300 +59,198 @@
       INTEGER, INTENT(in) ::   kindic   ! if kindic < 0 there has been an error somewhere
       !
-      INTEGER ::  ji, jj, jk, jl, jf, ipl ! dummy loop indices
-      INTEGER ::  ierr
-      REAL(wp),DIMENSION(1) ::   zdept
-      REAL(wp) ::  zsto, zjulian, zout, zindh, zinda, zindb, zindc
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zcmo, zcmoa
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zfield
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zmaskitd, zoi, zei
-
-      CHARACTER(len = 60) ::   clhstnam, clop, clhstnama
-
-      INTEGER , SAVE ::   nice, nhorid, ndim, niter, ndepid
-      INTEGER , SAVE ::   nicea, nhorida, ndimitd
-      INTEGER , ALLOCATABLE, DIMENSION(:), SAVE ::   ndex51
-      INTEGER , ALLOCATABLE, DIMENSION(:), SAVE ::   ndexitd
+      INTEGER ::  ji, jj, jk, jl  ! dummy loop indices
+      REAL(wp) ::  zinda, zindb, z1_365
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zoi, zei
+      REAL(wp), POINTER, DIMENSION(:,:)   :: z2d, z2da, z2db, zind    ! 2D workspace
       !!-------------------------------------------------------------------
 
       IF( nn_timing == 1 )  CALL timing_start('limwri')
 
-      CALL wrk_alloc( jpi, jpj, zfield )
-      CALL wrk_alloc( jpi, jpj, jpnoumax, zcmo, zcmoa )
-      CALL wrk_alloc( jpi, jpj, jpl, zmaskitd, zoi, zei )
-
-      ipl = jpl
-
-      IF( numit == nstart ) THEN 
-
-         ALLOCATE( ndex51(jpij), ndexitd(jpij*jpl), STAT=ierr )
-         IF( lk_mpp    )   CALL mpp_sum ( ierr )
-         IF( ierr /= 0 ) THEN
-            CALL ctl_stop( 'lim_wri : unable to allocate standard arrays' )   ;   RETURN
-         ENDIF
-
-         CALL lim_wri_init 
-
-         IF(lwp) WRITE(numout,*) ' lim_wri, first time step '
-         IF(lwp) WRITE(numout,*) ' add_diag_swi ', add_diag_swi
-
-         !--------------------
-         !  1) Initialization
-         !--------------------
-
-         !-------------
-         ! Normal file
-         !-------------
-         niter    = ( nit000 - 1 ) / nn_fsbc
-         CALL ymds2ju ( nyear, nmonth, nday, rdt, zjulian )
-         zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
-!clem
-!         zsto     = rdt_ice
-!         IF( ln_mskland )   THEN   ;   clop = "ave(only(x))"   ! put 1.e+20 on land (very expensive!!)
-!         ELSE                      ;   clop = "ave(x)"         ! no use of the mask value (require less cpu time)
-!         ENDIF
-!         zout     = nwrite * rdt_ice / nn_fsbc
-!         zdept(1) = 0.
-!
-!         CALL dia_nam ( clhstnam, nwrite, 'icemod_old' )
-!         CALL histbeg ( clhstnam, jpi, glamt, jpj, gphit, 1, jpi, 1, jpj, niter, zjulian, rdt_ice,   &
-!            &           nhorid, nice, domain_id=nidom, snc4chunks=snc4set )
-!         CALL histvert( nice, "deptht", "Vertical T levels", "m", 1, zdept, ndepid, "down")
-!         CALL wheneq  ( jpij , tmask(:,:,1), 1, 1., ndex51, ndim)
-!
-!         DO jf = 1 , noumef
-!            IF(lwp) WRITE(numout,*) 'jf', jf
-!            IF ( nc(jf) == 1 ) THEN
-!               CALL histdef( nice, nam(jf), titn(jf), uni(jf), jpi, jpj &
-!                  , nhorid, 1, 1, 1, -99, 32, clop, zsto, zout )
-!               IF(lwp) WRITE(numout,*) 'nice, nam(jf), titn(jf), uni(jf), nhorid, clop, zsto, zout'
-!               IF(lwp) WRITE(numout,*)  nice, nam(jf), titn(jf), uni(jf), nhorid, clop, zsto, zout 
-!            ENDIF
-!         END DO
-!
-!         CALL histend(nice, snc4set)
-!clem
-         !
-         !-----------------
-         ! ITD file output
-         !-----------------
-         zsto     = rdt_ice
-         clop     = "ave(x)"
-         zout     = nwrite * rdt_ice / nn_fsbc
-         zdept(1) = 0.
-
-         CALL dia_nam ( clhstnama, nwrite, 'icemoa' )
-         CALL histbeg ( clhstnama, jpi, glamt, jpj, gphit,         &
-            1, jpi, 1, jpj,            & ! zoom
-            niter, zjulian, rdt_ice,   & ! time
-            nhorida,                   & ! ? linked with horizontal ...
-            nicea , domain_id=nidom, snc4chunks=snc4set)                  ! file 
-         CALL histvert( nicea, "icethi", "L levels","m", ipl , hi_mean , nz )
+      CALL wrk_alloc( jpi, jpj, jpl, zoi, zei )
+      CALL wrk_alloc( jpi, jpj     , z2d, z2da, z2db, zind )
+
+      !-----------------------------
+      ! Mean category values
+      !-----------------------------
+
+      CALL lim_var_icetm      ! mean sea ice temperature
+
+      CALL lim_var_bv         ! brine volume
+
+      DO jj = 1, jpj          ! presence indicator of ice
+         DO ji = 1, jpi
+            zind(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 ji = 1, jpi
+               z2d(ji,jj)  = vt_i(ji,jj) / MAX( at_i(ji,jj), epsi06 ) * zind(ji,jj)
+            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 ) * zind(ji,jj)
+            END DO
+         END DO
+         CALL iom_put( "snowthic_cea" , z2d              )       
+      ENDIF
+      !
+      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) * tmu(ji,jj) + u_ice(ji-1,jj) * tmu(ji-1,jj) ) * 0.5_wp
+               z2db(ji,jj)  = (  v_ice(ji,jj) * tmv(ji,jj) + v_ice(ji,jj-1) * tmv(ji,jj-1) ) * 0.5_wp
+           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
+      ENDIF
+      !
+      IF ( iom_use( "miceage" ) ) THEN 
+         z2d(:,:) = 0.e0
          DO jl = 1, jpl
-            zmaskitd(:,:,jl) = tmask(:,:,1)
-         END DO
-         CALL wheneq  ( jpij , tmask(:,:,1), 1, 1., ndex51, ndim)
-         CALL wheneq( jpi*jpj*jpl, zmaskitd, 1, 1., ndexitd, ndimitd  )  
-         CALL histdef( nicea, "iice_itd", "Ice area in categories"         , "-"    ,   &  
-            jpi, jpj, nhorida, jpl, 1, jpl, nz, 15, clop, zsto, zout )
-         CALL histdef( nicea, "iice_hid", "Ice thickness in categories"    , "m"    ,   &  
-            jpi, jpj, nhorida, jpl, 1, jpl, nz, 15, clop, zsto, zout )
-         CALL histdef( nicea, "iice_hsd", "Snow depth in in categories"    , "m"    ,   &  
-            jpi, jpj, nhorida, jpl, 1, jpl, nz, 15, clop, zsto, zout )
-         CALL histdef( nicea, "iice_std", "Ice salinity distribution"      , "ppt"  ,   &  
-            jpi, jpj, nhorida, jpl, 1, jpl, nz, 15, clop, zsto, zout )
-         CALL histdef( nicea, "iice_otd", "Ice age distribution"               , "days",   &  
-            jpi, jpj, nhorida, jpl, 1, jpl, nz, 15, clop, zsto, zout )
-         CALL histdef( nicea, "iice_etd", "Brine volume distr. "               , "%"    ,   &  
-            jpi, jpj, nhorida, jpl, 1, jpl, nz, 15, clop, zsto, zout )
-         CALL histend(nicea, snc4set)
-      ENDIF
-
-      !     !-----------------------------------------------------------------------!
-      !     !--2. Computation of instantaneous values                               ! 
-      !     !-----------------------------------------------------------------------!
-
-      !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-      !IF( ln_nicep ) THEN
-      !   WRITE(numout,*)
-      !   WRITE(numout,*) 'lim_wri : write ice outputs in NetCDF files at time : ', nyear, nmonth, nday, numit
-      !   WRITE(numout,*) '~~~~~~~ '
-      !   WRITE(numout,*) ' kindic = ', kindic
-      !ENDIF
-      !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
-      !-- calculs des valeurs instantanees
-      zcmo ( 1:jpi, 1:jpj, 1:jpnoumax ) = 0._wp
-      zcmoa( 1:jpi, 1:jpj, 1:jpnoumax ) = 0._wp
-
-      ! Ice surface temperature and some fluxes
-      DO jl = 1, jpl
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  z2d(ji,jj) = z2d(ji,jj) + zind(ji,jj) * oa_i(ji,jj,jl)
+               END DO
+            END DO
+         END DO
+         z1_365 = 1._wp / 365._wp
+         CALL iom_put( "miceage"     , z2d * z1_365         )        ! mean ice age
+      ENDIF
+
+      IF ( iom_use( "micet" ) ) THEN 
          DO jj = 1, jpj
             DO ji = 1, jpi
-               zinda  = MAX( zzero , SIGN( zone , at_i(ji,jj) - epsi06 ) )
-               zcmo(ji,jj,17) = zcmo(ji,jj,17) + a_i(ji,jj,jl)*qsr_ice (ji,jj,jl) 
-               zcmo(ji,jj,18) = zcmo(ji,jj,18) + a_i(ji,jj,jl)*qns_ice(ji,jj,jl) 
-               zcmo(ji,jj,27) = zcmo(ji,jj,27) + zinda*(t_su(ji,jj,jl)-rtt)*a_i(ji,jj,jl)/MAX(at_i(ji,jj),epsi06)
-               zcmo(ji,jj,21) = zcmo(ji,jj,21) + zinda*oa_i(ji,jj,jl)/MAX(at_i(ji,jj),epsi06) 
-            END DO
-         END DO
-      END DO
-
-      ! Mean sea ice temperature
-      CALL lim_var_icetm
-
-      ! Brine volume
-      CALL lim_var_bv
-
-      DO jj = 2 , jpjm1
-         DO ji = 2 , jpim1
-            zinda  = MAX( zzero , SIGN( zone , at_i(ji,jj) - epsi06 ) )
-            zindb  = MAX( zzero , SIGN( zone , at_i(ji,jj) ) )
-
-            zcmo(ji,jj,1)  = at_i(ji,jj)
-            zcmo(ji,jj,2)  = vt_i(ji,jj) / MAX( at_i(ji,jj), epsi06 ) * zinda
-            zcmo(ji,jj,3)  = vt_s(ji,jj) / MAX( at_i(ji,jj), epsi06 ) * zinda
-            zcmo(ji,jj,4)  = diag_bot_gr(ji,jj) * rday     ! Bottom thermodynamic ice production
-            zcmo(ji,jj,5)  = diag_dyn_gr(ji,jj) * rday     ! Dynamic ice production (rid/raft)
-            zcmo(ji,jj,22) = diag_lat_gr(ji,jj) * rday     ! Lateral thermodynamic ice production
-            zcmo(ji,jj,23) = diag_sni_gr(ji,jj) * rday     ! Snow ice production ice production
-            zcmo(ji,jj,24) = (tm_i(ji,jj) - rtt) * zinda
-
-            zcmo(ji,jj,6)  = fbif(ji,jj)*at_i(ji,jj)
-            zcmo(ji,jj,7)  = (  u_ice(ji,jj) * tmu(ji,jj) + u_ice(ji-1,jj) * tmu(ji-1,jj) ) * 0.5_wp
-            zcmo(ji,jj,8)  = (  v_ice(ji,jj) * tmv(ji,jj) + v_ice(ji,jj-1) * tmv(ji,jj-1) ) * 0.5_wp
-            zcmo(ji,jj,9)  = sst_m(ji,jj)
-            zcmo(ji,jj,10) = sss_m(ji,jj)
-
-            zcmo(ji,jj,11) = qns(ji,jj) + qsr(ji,jj)
-            zcmo(ji,jj,12) = qsr(ji,jj)
-            zcmo(ji,jj,13) = qns(ji,jj)
-            zcmo(ji,jj,14) = fhbri(ji,jj)
-            zcmo(ji,jj,15) = utau_ice(ji,jj)
-            zcmo(ji,jj,16) = vtau_ice(ji,jj)
-            zcmo(ji,jj,17) = zcmo(ji,jj,17) + ( 1._wp - at_i(ji,jj) ) * qsr(ji,jj)
-            zcmo(ji,jj,18) = zcmo(ji,jj,18) + ( 1._wp - at_i(ji,jj) ) * qns(ji,jj)
-            zcmo(ji,jj,19) = sprecip(ji,jj)
-            zcmo(ji,jj,20) = smt_i(ji,jj)
-            zcmo(ji,jj,25) = et_i(ji,jj)
-            zcmo(ji,jj,26) = et_s(ji,jj)
-            zcmo(ji,jj,28) = sfx_bri(ji,jj)
-            zcmo(ji,jj,29) = sfx_thd(ji,jj)
-
-            zcmo(ji,jj,30) = bv_i(ji,jj)
-            zcmo(ji,jj,31) = hicol(ji,jj) * zindb
-            zcmo(ji,jj,32) = strength(ji,jj)
-            zcmo(ji,jj,33) = SQRT(  zcmo(ji,jj,7)*zcmo(ji,jj,7) + zcmo(ji,jj,8)*zcmo(ji,jj,8)  )
-            zcmo(ji,jj,34) = diag_sur_me(ji,jj) * rday     ! Surface melt
-            zcmo(ji,jj,35) = diag_bot_me(ji,jj) * rday     ! Bottom melt
-            zcmo(ji,jj,36) = divu_i(ji,jj)
-            zcmo(ji,jj,37) = shear_i(ji,jj)
-            zcmo(ji,jj,38) = diag_res_pr(ji,jj) * rday     ! Bottom melt
-            zcmo(ji,jj,39) = vt_i(ji,jj)  ! ice volume
-            zcmo(ji,jj,40) = vt_s(ji,jj)  ! snow volume
-
-            zcmo(ji,jj,41) = sfx_mec(ji,jj)
-            zcmo(ji,jj,42) = sfx_res(ji,jj)
-
-            zcmo(ji,jj,43) = diag_trp_vi(ji,jj) * rday     ! transport of ice volume
-
-        END DO
-      END DO
-
-      !
-      ! ecriture d'un fichier netcdf
-      !
-      niter = niter + 1
-!clem
-!      DO jf = 1 , noumef
-!         !
-!         zfield(:,:) = zcmo(:,:,jf) * cmulti(jf) + cadd(jf)
-!         !
-!         IF( jf == 7  .OR. jf == 8  .OR. jf == 15 .OR. jf == 16 ) THEN   ;   CALL lbc_lnk( zfield, 'T', -1. )
-!         ELSE                                                            ;   CALL lbc_lnk( zfield, 'T',  1. )
-!         ENDIF
-!         !
-!         IF( ln_nicep ) THEN 
-!            WRITE(numout,*)
-!            WRITE(numout,*) 'nc(jf), nice, nam(jf), niter, ndim'
-!            WRITE(numout,*) nc(jf), nice, nam(jf), niter, ndim
-!         ENDIF
-!         IF( nc(jf) == 1 ) CALL histwrite( nice, nam(jf), niter, zfield, ndim, ndex51 )
-!         !
-!      END DO
-!
-!      IF( ( nn_fsbc * niter ) >= nitend .OR. kindic < 0 ) THEN
-!         IF( lwp) WRITE(numout,*) ' Closing the icemod file '
-!         CALL histclo( nice )
-!      ENDIF
-!clem
-      !
-       CALL iom_put ('iceconc', zcmo(:,:,1) )          ! field1: ice concentration
-       CALL iom_put ('icethic_cea', zcmo(:,:,2) )      ! field2: ice thickness (i.e. icethi(:,:))
-       CALL iom_put ('snowthic_cea', zcmo(:,:,3))      ! field3: snow thickness
-       CALL iom_put ('icebopr', zcmo(:,:,4) )   ! field4: daily bottom thermo ice production
-       CALL iom_put ('icedypr', zcmo(:,:,5) )   ! field5: daily dynamic ice production
-       CALL iom_put ('ioceflxb', zcmo(:,:,6) )         ! field6: Oceanic flux at the ice base
-       CALL iom_put ('uice_ipa', zcmo(:,:,7) )         ! field7: ice velocity u component
-       CALL iom_put ('vice_ipa', zcmo(:,:,8) )         ! field8: ice velocity v component
-       CALL iom_put ('isst', zcmo(:,:,9) )             ! field 9: sea surface temperature
-       CALL iom_put ('isss', zcmo(:,:,10) )            ! field 10: sea surface salinity
-       CALL iom_put ('qt_oce', zcmo(:,:,11) )           ! field 11: total flux at ocean surface
-       CALL iom_put ('qsr_oce', zcmo(:,:,12) )          ! field 12: solar flux at ocean surface
-       CALL iom_put ('qns_oce', zcmo(:,:,13) )          ! field 13: non-solar flux at ocean surface
-       !CALL iom_put ('hfbri', fhbri )                  ! field 14: heat flux due to brine release
-       CALL iom_put( 'utau_ice', zcmo(:,:,15)  )     ! Wind stress over ice along i-axis at I-point
-       CALL iom_put( 'vtau_ice', zcmo(:,:,16) )     ! Wind stress over ice along j-axis at I-point
-       CALL iom_put ('qsr_io', zcmo(:,:,17) )          ! field 17: solar flux at ice/ocean surface
-       CALL iom_put ('qns_io', zcmo(:,:,18) )          ! field 18: non-solar flux at ice/ocean surface
-       !CALL iom_put ('snowpre', zcmo(:,:,19) * rday ! field 19 :snow precip          
-       CALL iom_put ('micesalt', zcmo(:,:,20) )        ! field 20 :mean ice salinity
-       CALL iom_put ('miceage', zcmo(:,:,21) / 365)    ! field 21: mean ice age
-       CALL iom_put ('icelapr',zcmo(:,:,22) )   ! field 22: daily lateral thermo ice prod.
-       CALL iom_put ('icesipr',zcmo(:,:,23) )   ! field 23: daily snowice ice prod.
-       CALL iom_put ('micet', zcmo(:,:,24) )           ! field 24: mean ice temperature
-       CALL iom_put ('icehc', zcmo(:,:,25) )           ! field 25: ice total heat content
-       CALL iom_put ('isnowhc', zcmo(:,:,26) )         ! field 26: snow total heat content
-       CALL iom_put ('icest', zcmo(:,:,27) )           ! field 27: ice surface temperature
-       CALL iom_put ('sfxbri', zcmo(:,:,28) * rday )           ! field 28: brine salt flux
-       CALL iom_put ('sfxthd', zcmo(:,:,29) * rday )           ! field 29: equivalent FW salt flux
-       CALL iom_put ('ibrinv', zcmo(:,:,30) *100 )     ! field 30: brine volume
-       CALL iom_put ('icecolf', zcmo(:,:,31) )         ! field 31: frazil ice collection thickness
-       CALL iom_put ('icestr', zcmo(:,:,32) * 0.001 )  ! field 32: ice strength
-       CALL iom_put ('icevel', zcmo(:,:,33) )          ! field 33: ice velocity
-       CALL iom_put ('isume', zcmo(:,:,34) )    ! field 34: surface melt
-       CALL iom_put ('ibome', zcmo(:,:,35) )     ! field 35: bottom melt
-       CALL iom_put ('idive', zcmo(:,:,36) * 1.0e8)    ! field 36: divergence
-       CALL iom_put ('ishear', zcmo(:,:,37) * 1.0e8 )  ! field 37: shear
-       CALL iom_put ('icerepr', zcmo(:,:,38) ) ! field 38: daily prod./melting due to limupdate
-       CALL iom_put ('icevolu', zcmo(:,:,39) ) ! field 39: ice volume
-       CALL iom_put ('snowvol', zcmo(:,:,40) ) ! field 40: snow volume
-       CALL iom_put ('sfxmec', zcmo(:,:,41) * rday )           ! field 41: salt flux from ridging rafting
-       CALL iom_put ('sfxres', zcmo(:,:,42) * rday )           ! field 42: salt flux from limupdate (resultant)
-       CALL iom_put ('icetrp', zcmo(:,:,43) )    ! field 43: ice volume transport
-
-      !-----------------------------
-      ! Thickness distribution file
-      !-----------------------------
-      IF( add_diag_swi == 1 ) THEN
-
-         DO jl = 1, jpl 
-            CALL lbc_lnk( a_i(:,:,jl)  , 'T' ,  1. )
-            CALL lbc_lnk( sm_i(:,:,jl) , 'T' ,  1. )
-            CALL lbc_lnk( oa_i(:,:,jl) , 'T' ,  1. )
-            CALL lbc_lnk( ht_i(:,:,jl) , 'T' ,  1. )
-            CALL lbc_lnk( ht_s(:,:,jl) , 'T' ,  1. )
-         END DO
-
-         ! Compute ice age
+               z2d(ji,jj) = ( tm_i(ji,jj) - rtt ) * zind(ji,jj)
+            END DO
+         END DO
+         CALL iom_put( "micet"       , z2d                  )        ! mean ice temperature
+      ENDIF
+      !
+      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) + zind(ji,jj) * ( t_su(ji,jj,jl) - rtt ) * 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" ) ) THEN 
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zindb  = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) ) )
+               z2d(ji,jj) = hicol(ji,jj) * zindb
+            END DO
+         END DO
+         CALL iom_put( "icecolf"     , z2d                 )        ! frazil ice collection thickness
+      ENDIF
+
+      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( "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             )        ! 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( "icetrp"      , diag_trp_vi * rday  )        ! ice volume transport
+      CALL iom_put( "snwtrp"      , diag_trp_vs * rday  )        ! snw volume transport
+      CALL iom_put( "deitrp"      , diag_trp_ei         )        ! advected ice enthalpy (W/m2)
+      CALL iom_put( "destrp"      , diag_trp_es         )        ! advected snw enthalpy (W/m2)
+
+      CALL iom_put( "sfxbog"      , sfx_bog * rday      )        ! salt flux from brines
+      CALL iom_put( "sfxbom"      , sfx_bom * rday      )        ! salt flux from brines
+      CALL iom_put( "sfxsum"      , sfx_sum * rday      )        ! salt flux from brines
+      CALL iom_put( "sfxsni"      , sfx_sni * rday      )        ! salt flux from brines
+      CALL iom_put( "sfxopw"      , sfx_opw * rday      )        ! salt flux from brines
+      CALL iom_put( "sfxdyn"      , sfx_dyn * rday      )        ! salt flux from ridging rafting
+      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( "sfx"         , sfx     * rday      )        ! total salt flux
+
+      CALL iom_put( "vfxres"     , wfx_res * rday / rhoic  )        ! daily prod./melting due to limupdate 
+      CALL iom_put( "vfxopw"     , wfx_opw * rday / rhoic  )        ! daily lateral thermodynamic ice production
+      CALL iom_put( "vfxsni"     , wfx_sni * rday / rhoic  )        ! daily snowice ice production
+      CALL iom_put( "vfxbog"     , wfx_bog * rday / rhoic  )       ! daily bottom thermodynamic ice production
+      CALL iom_put( "vfxdyn"     , wfx_dyn * rday / rhoic  )       ! daily dynamic ice production (rid/raft)
+      CALL iom_put( "vfxsum"     , wfx_sum * rday / rhoic  )        ! surface melt 
+      CALL iom_put( "vfxbom"     , wfx_bom * rday / rhoic  )        ! bottom melt 
+      CALL iom_put( "vfxice"     , wfx_ice * rday / rhoic  )        ! total ice growth/melt 
+      CALL iom_put( "vfxsnw"     , wfx_snw * rday / rhoic  )        ! total snw growth/melt 
+      CALL iom_put( "vfxsub"     , wfx_sub * rday / rhoic  )        ! sublimation (snow) 
+      CALL iom_put( "vfxspr"     , wfx_spr * rday / rhoic  )        ! precip (snow) 
+
+      CALL iom_put ('hfxthd', hfx_thd(:,:) )   !  
+      CALL iom_put ('hfxdyn', hfx_dyn(:,:) )   !  
+      CALL iom_put ('hfxres', hfx_res(:,:) )   !  
+      CALL iom_put ('hfxout', hfx_out(:,:) )   !  
+      CALL iom_put ('hfxin' , hfx_in(:,:) )   !  
+      CALL iom_put ('hfxsnw', hfx_snw(:,:) )   !  
+      CALL iom_put ('hfxsub', hfx_sub(:,:) )   !  
+      CALL iom_put ('hfxerr', hfx_err(:,:) )   !  
+      CALL iom_put ('hfxerr_rem', hfx_err_rem(:,:) )   !  
+      
+      CALL iom_put ('hfxsum', hfx_sum(:,:) )   !  
+      CALL iom_put ('hfxbom', hfx_bom(:,:) )   !  
+      CALL iom_put ('hfxbog', hfx_bog(:,:) )   !  
+      CALL iom_put ('hfxdif', hfx_dif(:,:) )   !  
+      CALL iom_put ('hfxopw', hfx_opw(:,:) )   !  
+      CALL iom_put ('hfxtur', fhtur(:,:) * at_i(:,:) )   ! turbulent heat flux at ice base 
+      CALL iom_put ('hfxdhc', diag_heat_dhc(:,:) )          ! Heat content variation in snow and ice 
+      CALL iom_put ('hfxspr', hfx_spr(:,:) )          ! Heat content of snow precip 
+      
+      !--------------------------------
+      ! 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
+
+      ! Compute ice age
+      IF ( iom_use( "iceage_cat" ) ) THEN 
          DO jl = 1, jpl 
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zinda = MAX( zzero , SIGN( zone , a_i(ji,jj,jl) - epsi06 ) )
+                  zinda = MAX( 0._wp , SIGN( 1._wp , a_i(ji,jj,jl) - epsi06 ) )
                   zoi(ji,jj,jl) = oa_i(ji,jj,jl)  / MAX( a_i(ji,jj,jl) , epsi06 ) * zinda
                END DO
             END DO
          END DO
-
-         ! Compute brine volume
+         CALL iom_put( "iceage_cat"     , zoi         )        ! ice age for categories
+      ENDIF
+
+      ! Compute brine volume
+      IF ( iom_use( "brinevol_cat" ) ) THEN 
          zei(:,:,:) = 0._wp
          DO jl = 1, jpl 
@@ -379,5 +258,5 @@
                DO jj = 1, jpj
                   DO ji = 1, jpi
-                     zinda = MAX( zzero , SIGN( zone , a_i(ji,jj,jl) - epsi06 ) )
+                     zinda = 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) - rtt ), - epsi06 ) ) * &
@@ -387,30 +266,13 @@
             END DO
          END DO
-
-         DO jl = 1, jpl 
-            CALL lbc_lnk( zei(:,:,jl) , 'T' ,  1. )
-         END DO
-
-         CALL histwrite( nicea, "iice_itd", niter, a_i  , ndimitd , ndexitd  )   ! area
-         CALL histwrite( nicea, "iice_hid", niter, ht_i , ndimitd , ndexitd  )   ! thickness
-         CALL histwrite( nicea, "iice_hsd", niter, ht_s , ndimitd , ndexitd  )   ! snow depth
-         CALL histwrite( nicea, "iice_std", niter, sm_i , ndimitd , ndexitd  )   ! salinity
-         CALL histwrite( nicea, "iice_otd", niter, zoi  , ndimitd , ndexitd  )   ! age
-         CALL histwrite( nicea, "iice_etd", niter, zei  , ndimitd , ndexitd  )   ! brine volume
-
-         !     !  Create an output files (output.lim.abort.nc) if S < 0 or u > 20 m/s
-         !     IF( kindic < 0 )   CALL lim_wri_state( 'output.abort' )
-         !     not yet implemented
-
-         IF( ( nn_fsbc * niter ) >= nitend .OR. kindic < 0 ) THEN
-            IF(lwp) WRITE(numout,*) ' Closing the icemod file '
-            CALL histclo( nicea ) 
-         ENDIF
-         !
-      ENDIF
-
-      CALL wrk_dealloc( jpi, jpj, zfield )
-      CALL wrk_dealloc( jpi, jpj, jpnoumax, zcmo, zcmoa )
-      CALL wrk_dealloc( jpi, jpj, jpl, zmaskitd, zoi, zei )
+         CALL iom_put( "brinevol_cat"     , zei         )        ! brine volume for categories
+      ENDIF
+
+      !     !  Create an output files (output.lim.abort.nc) if S < 0 or u > 20 m/s
+      !     IF( kindic < 0 )   CALL lim_wri_state( 'output.abort' )
+      !     not yet implemented
+      
+      CALL wrk_dealloc( jpi, jpj, jpl, zoi, zei )
+      CALL wrk_dealloc( jpi, jpj     , z2d, zind, z2da, z2db )
 
       IF( nn_timing == 1 )  CALL timing_stop('limwri')
@@ -419,124 +281,4 @@
 #endif
 
-   SUBROUTINE lim_wri_init
-      !!-------------------------------------------------------------------
-      !!                    ***   ROUTINE lim_wri_init  ***
-      !!                
-      !! ** Purpose :   ???
-      !!
-      !! ** Method  : Read the namicewri namelist and check the parameter 
-      !!       values called at the first timestep (nit000)
-      !!
-      !! ** input   :   Namelist namicewri
-      !!-------------------------------------------------------------------
-      INTEGER ::   nf      ! ???
-      INTEGER ::   ios     ! Local integer output status for namelist read
-
-      TYPE FIELD 
-         CHARACTER(len = 35) :: ztitle 
-         CHARACTER(len = 8 ) :: zname          
-         CHARACTER(len = 8 ) :: zunit
-         INTEGER             :: znc   
-         REAL                :: zcmulti 
-         REAL                :: zcadd        
-      END TYPE FIELD
-
-      TYPE(FIELD) ::  &
-         field_1 , field_2 , field_3 , field_4 , field_5 , field_6 ,   &
-         field_7 , field_8 , field_9 , field_10, field_11, field_12,   &
-         field_13, field_14, field_15, field_16, field_17, field_18,   &
-         field_19, field_20, field_21, field_22, field_23, field_24,   &
-         field_25, field_26, field_27, field_28, field_29, field_30,   &
-         field_31, field_32, field_33, field_34, field_35, field_36,   &
-         field_37, field_38, field_39, field_40, field_41, field_42, field_43
-
-      TYPE(FIELD) , DIMENSION(jpnoumax) :: zfield
-      !
-      NAMELIST/namiceout/ noumef, &
-         field_1 , field_2 , field_3 , field_4 , field_5 , field_6 ,   &
-         field_7 , field_8 , field_9 , field_10, field_11, field_12,   &
-         field_13, field_14, field_15, field_16, field_17, field_18,   &
-         field_19, field_20, field_21, field_22, field_23, field_24,   &
-         field_25, field_26, field_27, field_28, field_29, field_30,   &
-         field_31, field_32, field_33, field_34, field_35, field_36,   &
-         field_37, field_38, field_39, field_40, field_41, field_42, field_43, add_diag_swi
-      !!-------------------------------------------------------------------
-      REWIND( numnam_ice_ref )              ! Namelist namiceout in reference namelist : Ice outputs
-      READ  ( numnam_ice_ref, namiceout, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceout in reference namelist', lwp )
-
-      REWIND( numnam_ice_cfg )              ! Namelist namiceout in configuration namelist : Ice outputs
-      READ  ( numnam_ice_cfg, namiceout, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceout in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namiceout )
-
-      zfield(1)  = field_1
-      zfield(2)  = field_2
-      zfield(3)  = field_3
-      zfield(4)  = field_4
-      zfield(5)  = field_5
-      zfield(6)  = field_6
-      zfield(7)  = field_7
-      zfield(8)  = field_8
-      zfield(9)  = field_9
-      zfield(10) = field_10
-      zfield(11) = field_11
-      zfield(12) = field_12
-      zfield(13) = field_13
-      zfield(14) = field_14
-      zfield(15) = field_15
-      zfield(16) = field_16
-      zfield(17) = field_17
-      zfield(18) = field_18
-      zfield(19) = field_19
-      zfield(20) = field_20
-      zfield(21) = field_21
-      zfield(22) = field_22
-      zfield(23) = field_23
-      zfield(24) = field_24
-      zfield(25) = field_25
-      zfield(26) = field_26
-      zfield(27) = field_27
-      zfield(28) = field_28
-      zfield(29) = field_29
-      zfield(30) = field_30
-      zfield(31) = field_31
-      zfield(32) = field_32
-      zfield(33) = field_33
-      zfield(34) = field_34
-      zfield(35) = field_35
-      zfield(36) = field_36
-      zfield(37) = field_37
-      zfield(38) = field_38
-      zfield(39) = field_39
-      zfield(40) = field_40
-      zfield(41) = field_41
-      zfield(42) = field_42
-      zfield(43) = field_43
-
-      DO nf = 1, noumef
-         titn  (nf) = zfield(nf)%ztitle
-         nam   (nf) = zfield(nf)%zname
-         uni   (nf) = zfield(nf)%zunit
-         nc    (nf) = zfield(nf)%znc
-         cmulti(nf) = zfield(nf)%zcmulti
-         cadd  (nf) = zfield(nf)%zcadd
-      END DO
-
-      IF(lwp) THEN                        ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_wri_init : Ice parameters for outputs'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '    number of fields to be stored         noumef = ', noumef
-         WRITE(numout,*) '           title                            name     unit      Saving (1/0) ',   &
-            &            '    multiplicative constant       additive constant '
-         DO nf = 1 , noumef         
-            WRITE(numout,*) '   ', titn(nf), '   '    , nam   (nf), '      '  , uni (nf),   &
-               &            '  ' , nc  (nf),'        ', cmulti(nf), '        ', cadd(nf)
-         END DO
-         WRITE(numout,*) ' add_diag_swi ', add_diag_swi
-      ENDIF
-      !
-   END SUBROUTINE lim_wri_init
  
    SUBROUTINE lim_wri_state( kt, kid, kh_i )
@@ -555,35 +297,49 @@
       INTEGER, INTENT( in ) ::   kid , kh_i       
       !!----------------------------------------------------------------------
-      !CALL histvert( kid, "icethi", "L levels","m", jpl , hi_mean , nz )
-
-      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"   , 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"      , 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, "iisfxthd", "Salt flux from thermo"   , ""      , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iisfxmec", "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, "iice_itd", "Ice concentration by cat", "%"      , jpi, jpj, kh_i, jpl, 1, jpl, -99, 32, "inst(x)", rdt, rdt ) 
-      !CALL histdef( kid, "iice_hid", "Ice thickness by cat"    , "m"      , jpi, jpj, kh_i, jpl, 1, jpl, -99, 32, "inst(x)", rdt, rdt ) 
-      !CALL histdef( kid, "iice_hsd", "Snow thickness by cat"   , "m"      , jpi, jpj, kh_i, jpl, 1, jpl, -99, 32, "inst(x)", rdt, rdt ) 
-      !CALL histdef( kid, "iice_std", "Ice salinity by cat"     , "PSU"    , jpi, jpj, kh_i, jpl, 1, jpl, -99, 32, "inst(x)", rdt, rdt ) 
+
+      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" ,   &
+      &      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"    ,   &
+      &       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 histend( kid, snc4set )   ! end of the file definition
@@ -603,19 +359,17 @@
       CALL histwrite( kid, "iicedive", kt, divu_i*1.0e8   , jpi*jpj, (/1/) )
 
-      CALL histwrite( kid, "iicebopr", kt, diag_bot_gr        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicedypr", kt, diag_dyn_gr        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicelapr", kt, diag_lat_gr        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicesipr", kt, diag_sni_gr        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicerepr", kt, diag_res_pr        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicebome", kt, diag_bot_me        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicesume", kt, diag_sur_me        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iisfxthd", kt, sfx_thd        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iisfxmec", kt, sfx_mec        , 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, "iice_itd", kt, a_i  , jpi*jpj*jpl, (/1/)  )   ! area
-      !CALL histwrite( kid, "iice_hid", kt, ht_i , jpi*jpj*jpl, (/1/)  )   ! thickness
-      !CALL histwrite( kid, "iice_hsd", kt, ht_s , jpi*jpj*jpl, (/1/)  )   ! snow depth
-      !CALL histwrite( kid, "iice_std", kt, sm_i , jpi*jpj*jpl, (/1/)  )   ! salinity
+      ! Close the file
+      ! -----------------
+      !CALL histclo( kid )
 
     END SUBROUTINE lim_wri_state
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limwri_dimg.h90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limwri_dimg.h90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/limwri_dimg.h90	(revision 4921)
@@ -89,14 +89,14 @@
    DO jj = 2 , jpjm1
       DO ji = 2 , jpim1   ! NO vector opt.
-         zindh  = MAX( zzero , SIGN( zone , ht_i(ji,jj,1) * (1.0 - frld(ji,jj) ) - 0.10 ) )
-         zinda  = MAX( zzero , SIGN( zone , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
+         zindh  = MAX( 0._wp , SIGN( 1._wp , ht_i(ji,jj,1) * (1.0 - frld(ji,jj) ) - 0.10 ) )
+         zinda  = MAX( 0._wp , SIGN( 1._wp , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
          zindb  = zindh * zinda
-         ztmu   = MAX( 0.5 * zone , ( tmu(ji,jj) + tmu(ji+1,jj) + tmu(ji,jj+1) + tmu(ji+1,jj+1) ) ) 
+         ztmu   = MAX( 0.5 * 1._wp , ( tmu(ji,jj) + tmu(ji+1,jj) + tmu(ji,jj+1) + tmu(ji+1,jj+1) ) ) 
          zcmo(ji,jj,1)  = ht_s (ji,jj,1)
          zcmo(ji,jj,2)  = ht_i (ji,jj,1)
-         zcmo(ji,jj,3)  = hicifp(ji,jj)
+         zcmo(ji,jj,3)  = 0.
          zcmo(ji,jj,4)  = frld  (ji,jj)
          zcmo(ji,jj,5)  = sist  (ji,jj)
-         zcmo(ji,jj,6)  = fbif  (ji,jj)
+         zcmo(ji,jj,6)  = fhtur  (ji,jj)
          zcmo(ji,jj,7)  = zindb * (  u_ice(ji,jj  ) * tmu(ji,jj  ) + u_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
             + u_ice(ji,jj+1) * tmu(ji,jj+1) + u_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
@@ -132,14 +132,14 @@
          DO jj = 2 , jpjm1
             DO ji = 2 , jpim1   ! NO vector opt.
-               zindh  = MAX( zzero , SIGN( zone , ht_i(ji,jj,1) * (1.0 - frld(ji,jj) ) - 0.10 ) )
-               zinda  = MAX( zzero , SIGN( zone , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
+               zindh  = MAX( 0._wp , SIGN( 1._wp , ht_i(ji,jj,1) * (1.0 - frld(ji,jj) ) - 0.10 ) )
+               zinda  = MAX( 0._wp , SIGN( 1._wp , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
                zindb  = zindh * zinda
-               ztmu   = MAX( 0.5 * zone , ( tmu(ji,jj) + tmu(ji+1,jj) + tmu(ji,jj+1) + tmu(ji+1,jj+1) ) )
+               ztmu   = MAX( 0.5 * 1._wp , ( tmu(ji,jj) + tmu(ji+1,jj) + tmu(ji,jj+1) + tmu(ji+1,jj+1) ) )
                rcmoy(ji,jj,1)  = ht_s (ji,jj,1)
                rcmoy(ji,jj,2)  = ht_i (ji,jj,1)
-               rcmoy(ji,jj,3)  = hicifp(ji,jj)
+               rcmoy(ji,jj,3)  = 0.
                rcmoy(ji,jj,4)  = frld  (ji,jj)
                rcmoy(ji,jj,5)  = sist  (ji,jj)
-               rcmoy(ji,jj,6)  = fbif  (ji,jj)
+               rcmoy(ji,jj,6)  = fhtur  (ji,jj)
                rcmoy(ji,jj,7)  = zindb * (  u_ice(ji,jj  ) * tmu(ji,jj  ) + u_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
                   + u_ice(ji,jj+1) * tmu(ji,jj+1) + u_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/par_ice.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/par_ice.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/par_ice.F90	(revision 4921)
@@ -12,10 +12,9 @@
 
    !                                             !!! ice thermodynamics
-   INTEGER, PUBLIC, PARAMETER ::   jkmax    = 6   !: maximum number of ice layers
+   INTEGER, PUBLIC, PARAMETER ::   nlay_i   = 5   !: number of ice layers
    INTEGER, PUBLIC, PARAMETER ::   nlay_s   = 1   !: number of snow layers
 
    !                                             !!! ice mechanical redistribution
    INTEGER, PUBLIC, PARAMETER ::   jpl      = 5   !: number of ice categories
-   INTEGER, PUBLIC, PARAMETER ::   jpm      = 1   !: number of ice types
 
    !!----------------------------------------------------------------------
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90	(revision 4921)
@@ -20,22 +20,13 @@
    !                               !!! ** ice-thermo namelist (namicethd) **
    REAL(wp), PUBLIC ::   hmelt       !: maximum melting at the bottom; active only for one category
-   REAL(wp), PUBLIC ::   hicmin      !: (REMOVE)
    REAL(wp), PUBLIC ::   hiclim      !: minimum ice thickness
-   REAL(wp), PUBLIC ::   sbeta       !: numerical scheme for diffusion in ice  (REMOVE)
-   REAL(wp), PUBLIC ::   parlat      !: (REMOVE)
-   REAL(wp), PUBLIC ::   hakspl      !: (REMOVE)
-   REAL(wp), PUBLIC ::   hibspl      !: (REMOVE)
-   REAL(wp), PUBLIC ::   exld        !: (REMOVE)
-   REAL(wp), PUBLIC ::   hakdif      !: (REMOVE)
-   REAL(wp), PUBLIC ::   thth        !: (REMOVE)
    REAL(wp), PUBLIC ::   hnzst       !: thick. of the surf. layer in temp. comp.
    REAL(wp), PUBLIC ::   parsub      !: switch for snow sublimation or not
-   REAL(wp), PUBLIC ::   alphs       !: coef. for snow density when snow-ice formation
-   REAL(wp), PUBLIC ::   fraz_swi    !: use of frazil ice collection in function of wind (1.0) or not (0.0)
    REAL(wp), PUBLIC ::   maxfrazb    !: maximum portion of frazil ice collecting at the ice bottom
    REAL(wp), PUBLIC ::   vfrazb      !: threshold drift speed for collection of bottom frazil ice
    REAL(wp), PUBLIC ::   Cfrazb      !: squeezing coefficient for collection of bottom frazil ice
+   REAL(wp), PUBLIC ::   hiccrit     !: ice th. for lateral accretion in the NH (SH) (m)
 
-   REAL(wp), PUBLIC, DIMENSION(2) ::   hiccrit   !: ice th. for lateral accretion in the NH (SH) (m)
+   INTEGER , PUBLIC ::   fraz_swi    !: use of frazil ice collection in function of wind (1) or not (0)
 
    !!-----------------------------
@@ -43,5 +34,5 @@
    !!-----------------------------
    !: In ice thermodynamics, to spare memory, the vectors are folded
-   !: from 1D to 2D vectors. The following variables, with ending _1d (or _b)
+   !: from 1D to 2D vectors. The following variables, with ending _1d
    !: are the variables corresponding to 2d vectors
 
@@ -49,28 +40,53 @@
    INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   npac   !: correspondance between points (lateral accretion)
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qldif_1d      !: <==> the 2D  qldif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qcmif_1d      !: <==> the 2D  qcmif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fstbif_1d     !: <==> the 2D  fstric
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fltbif_1d     !: <==> the 2D  ffltbif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fscbq_1d      !: <==> the 2D  fscmcbq
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qsr_ice_1d    !: <==> the 2D  qsr_ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fr1_i0_1d     !: <==> the 2D  fr1_i0
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fr2_i0_1d     !: <==> the 2D  fr2_i0
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qnsr_ice_1d   !: <==> the 2D  qns_ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qfvbq_1d      !: <==> the 2D  qfvbq
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   t_bo_b        !: <==> the 2D  t_bo
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qlead_1d     
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ftr_ice_1d   
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qsr_ice_1d  
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fr1_i0_1d   
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fr2_i0_1d   
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qns_ice_1d  
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   t_bo_1d     
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_sum_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_bom_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_bog_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_dif_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_opw_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_snw_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_err_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_err_rem_1d
+
+   ! heat flux associated with ice-atmosphere mass exchange
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_sub_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_spr_1d
+
+   ! heat flux associated with ice-ocean mass exchange
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_thd_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_res_1d
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_snw_1d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_sub_1d
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_bog_1d    
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_bom_1d   
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_sum_1d  
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_sni_1d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_opw_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_res_1d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_spr_1d
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_bri_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_bog_1d    
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_bom_1d    
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_sum_1d    
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_sni_1d    
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_opw_1d   
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_res_1d  
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sprecip_1d    !: <==> the 2D  sprecip
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   frld_1d       !: <==> the 2D  frld
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   at_i_b        !: <==> the 2D  frld
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fbif_1d       !: <==> the 2D  fbif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   rdm_ice_1d    !: <==> the 2D  rdm_ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   rdm_snw_1d    !: <==> the 2D  rdm_snw
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qlbbq_1d      !: <==> the 2D  qlbsbq
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dmgwi_1d      !: <==> the 2D  dmgwi
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dvsbq_1d      !: <==> the 2D  rdvosif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dvbbq_1d      !: <==> the 2D  rdvobif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dvlbq_1d      !: <==> the 2D  rdvolif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dvnbq_1d      !: <==> the 2D  rdvolif
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   at_i_1d        !: <==> the 2D  at_i
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fhtur_1d      !: <==> the 2D  fhtur
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fhld_1d       !: <==> the 2D  fhld
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dqns_ice_1d   !: <==> the 2D  dqns_ice
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qla_ice_1d    !: <==> the 2D  qla_ice
@@ -78,63 +94,36 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   tatm_ice_1d   !: <==> the 2D  tatm_ice
    !                                                     ! to reintegrate longwave flux inside the ice thermodynamics
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fsup          !: Energy flux sent from bottom to lateral ablation if |dhb|> 0.15 m
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   focea         !: Remaining energy in case of total ablation
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   i0            !: fraction of radiation transmitted to the ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   old_ht_i_b    !: Ice thickness at the beginnning of the time step [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   old_ht_s_b    !: Snow thickness at the beginning of the time step [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_bri_1d    !: <==> the 2D sfx_bri
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fhbri_1d      !: Heat flux due to brine drainage
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_thd_1d    !: <==> the 2D sfx_thd
    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_b       !: Ice collection thickness accumulated in fleads
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hicol_1d      !: Ice collection thickness accumulated in leads
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   t_su_b      !: <==> the 2D  t_su
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   a_i_b       !: <==> the 2D  a_i
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ht_i_b      !: <==> the 2D  ht_s
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ht_s_b      !: <==> the 2D  ht_i
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fc_su       !: Surface Conduction flux 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fc_bo_i     !: Bottom  Conduction flux 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_s_tot    !: Snow accretion/ablation        [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_i_surf   !: Ice surface accretion/ablation [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_i_bott   !: Ice bottom accretion/ablation  [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_snowice  !: Snow ice formation             [m of ice]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sm_i_b      !: Ice bulk salinity [ppt]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   s_i_new     !: Salinity of new ice at the bottom
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   s_snowice   !: Salinity of new snow ice on top of the ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   o_i_b       !: Ice age                        [days]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   t_su_1d       !: <==> the 2D  t_su
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   a_i_1d        !: <==> the 2D  a_i
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ht_i_1d       !: <==> the 2D  ht_s
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ht_s_1d       !: <==> the 2D  ht_i
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fc_su         !: Surface Conduction flux 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fc_bo_i       !: Bottom  Conduction flux 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_s_tot      !: Snow accretion/ablation        [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_i_surf     !: Ice surface accretion/ablation [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_i_bott     !: Ice bottom accretion/ablation  [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_snowice    !: Snow ice formation             [m of ice]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sm_i_1d       !: Ice bulk salinity [ppt]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   s_i_new       !: Salinity of new ice at the bottom
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   iatte_1d   !: clem attenuation coef of the input solar flux (unitless)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   oatte_1d   !: clem attenuation coef of the input solar flux (unitless)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   iatte_1d   !: attenuation coef of the input solar flux (unitless)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   oatte_1d   !: attenuation coef of the input solar flux (unitless)
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_s_b   !: corresponding to the 2D var  t_s
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_i_b   !: corresponding to the 2D var  t_i
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   s_i_b   !: profiled ice salinity
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   q_i_b   !:    Ice  enthalpy per unit volume
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   q_s_b   !:    Snow enthalpy per unit volume
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_s_1d   !: corresponding to the 2D var  t_s
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_i_1d   !: corresponding to the 2D var  t_i
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   s_i_1d   !: profiled ice salinity
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   q_i_1d   !:    Ice  enthalpy per unit volume
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   q_s_1d   !:    Snow enthalpy per unit volume
 
-   ! Clean the following ...
-   ! These variables are coded for conservation checks
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qt_i_in                  !: ice energy summed over categories (initial)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qt_i_fin                 !: ice energy summed over categories (final)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qt_s_in, qt_s_fin        !: snow energy summed over categories
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   dq_i, sum_fluxq          !: increment of energy, sum of fluxes
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fatm, foce               !: atmospheric, oceanic, heat flux
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   cons_error, surf_error   !: conservation, surface error
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qh_i_old !: ice heat content (q*h, J.m-2)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   h_i_old  !: ice thickness layer (m)
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   q_i_layer_in        !: goes to trash
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   q_i_layer_fin       !: goes to trash
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   dq_i_layer, radab   !: goes to trash
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ftotal_in    !: initial total heat flux
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ftotal_fin   !: final total heat flux
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fc_s
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fc_i
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   de_s_lay
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   de_i_lay
-   
    INTEGER , PUBLIC ::   jiindex_1d   ! 1D index of debugging point
 
@@ -151,50 +140,40 @@
       !!---------------------------------------------------------------------!
       INTEGER ::   thd_ice_alloc   ! return value
-      INTEGER ::   ierr(4)
+      INTEGER ::   ierr(3)
       !!---------------------------------------------------------------------!
 
       ALLOCATE( npb      (jpij) , npac     (jpij),                          &
          !                                                                  !
-         &      qldif_1d (jpij) , qcmif_1d (jpij) , fstbif_1d  (jpij) ,     &
-         &      fltbif_1d(jpij) , fscbq_1d (jpij) , qsr_ice_1d (jpij) ,     &
-         &      fr1_i0_1d(jpij) , fr2_i0_1d(jpij) , qnsr_ice_1d(jpij) ,     &
-         &      qfvbq_1d (jpij) , t_bo_b   (jpij) , iatte_1d   (jpij) ,     &
-         &      oatte_1d (jpij)                                       , STAT=ierr(1) )
+         &      qlead_1d (jpij) , ftr_ice_1d  (jpij) ,     &
+         &      qsr_ice_1d (jpij) ,     &
+         &      fr1_i0_1d(jpij) , fr2_i0_1d(jpij) , qns_ice_1d(jpij) ,     &
+         &      t_bo_1d   (jpij) , iatte_1d  (jpij) , oatte_1d (jpij) ,     &
+         &      hfx_sum_1d(jpij) , hfx_bom_1d(jpij) ,hfx_bog_1d(jpij),     &
+         &      hfx_dif_1d(jpij) ,hfx_opw_1d(jpij) , &
+         &      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),       STAT=ierr(1) )
       !
-      ALLOCATE( sprecip_1d (jpij) , frld_1d    (jpij) , at_i_b     (jpij) ,     &
-         &      fbif_1d    (jpij) , rdm_ice_1d (jpij) , rdm_snw_1d (jpij) ,     &
-         &      qlbbq_1d   (jpij) , dmgwi_1d   (jpij) , dvsbq_1d   (jpij) ,     &
-         &      dvbbq_1d   (jpij) , dvlbq_1d   (jpij) , dvnbq_1d   (jpij) ,     &
+      ALLOCATE( sprecip_1d (jpij) , frld_1d    (jpij) , at_i_1d     (jpij) ,     &
+         &      fhtur_1d   (jpij) , wfx_snw_1d (jpij) , wfx_spr_1d (jpij) ,     &
+         &      fhld_1d    (jpij) , wfx_sub_1d (jpij) , wfx_bog_1d(jpij) , wfx_bom_1d(jpij) , &
+         &      wfx_sum_1d(jpij)  , wfx_sni_1d (jpij) , wfx_opw_1d (jpij) ,  wfx_res_1d (jpij) ,  &
          &      dqns_ice_1d(jpij) , qla_ice_1d (jpij) , dqla_ice_1d(jpij) ,     &
-         &      tatm_ice_1d(jpij) , fsup       (jpij) , focea      (jpij) ,     &   
-         &      i0         (jpij) , old_ht_i_b (jpij) , old_ht_s_b (jpij) ,     &  
-         &      sfx_bri_1d (jpij) , fhbri_1d   (jpij) , sfx_thd_1d (jpij) ,     &
+         &      tatm_ice_1d(jpij) ,      &   
+         &      i0         (jpij) ,     &  
+         &      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) , &
          &      dsm_i_fl_1d(jpij) , dsm_i_gd_1d(jpij) , dsm_i_se_1d(jpij) ,     &     
-         &      dsm_i_si_1d(jpij) , hicol_b    (jpij)                     , STAT=ierr(2) )
+         &      dsm_i_si_1d(jpij) , hicol_1d    (jpij)                     , STAT=ierr(2) )
       !
-      ALLOCATE( t_su_b    (jpij) , a_i_b    (jpij) , ht_i_b   (jpij) ,    &   
-         &      ht_s_b    (jpij) , fc_su    (jpij) , fc_bo_i  (jpij) ,    &    
+      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_bott(jpij) ,    &    
-         &      dh_snowice(jpij) , sm_i_b   (jpij) , s_i_new  (jpij) ,    &    
-         &      s_snowice (jpij) , o_i_b    (jpij)                   ,    &
-         !                                                                !
-         &      t_s_b(jpij,nlay_s),                                       &
-         !                                                                !
-         &      t_i_b(jpij,jkmax), s_i_b(jpij,jkmax)                ,     &            
-         &      q_i_b(jpij,jkmax), q_s_b(jpij,jkmax)                , STAT=ierr(3))
+         &      dh_snowice(jpij) , sm_i_1d   (jpij) , s_i_new  (jpij) ,    &
+         &      t_s_1d(jpij,nlay_s),                                       &
+         &      t_i_1d(jpij,nlay_i+1), s_i_1d(jpij,nlay_i+1)                ,     &            
+         &      q_i_1d(jpij,nlay_i+1), q_s_1d(jpij,nlay_i+1)                ,     &
+         &      qh_i_old(jpij,0:nlay_i+1), h_i_old(jpij,0:nlay_i+1) , STAT=ierr(3))
       !
-      ALLOCATE( qt_i_in   (jpij,jpl) , qt_i_fin(jpij,jpl) , qt_s_in   (jpij,jpl) ,     &
-         &      qt_s_fin  (jpij,jpl) , dq_i    (jpij,jpl) , sum_fluxq (jpij,jpl) ,     &
-         &      fatm      (jpij,jpl) , foce    (jpij,jpl) , cons_error(jpij,jpl) ,     &
-         &      surf_error(jpij,jpl)                                             ,     &
-         !                                                                             !
-         &      q_i_layer_in(jpij,jkmax) , q_i_layer_fin(jpij,jkmax)             ,     &
-         &      dq_i_layer  (jpij,jkmax) , radab        (jpij,jkmax)             ,     &
-         !                                                                             !
-         &      ftotal_in(jpij), ftotal_fin(jpij)                                ,     &
-         !                                                                             !
-         &      fc_s(jpij,0:nlay_s) , de_s_lay(jpij,nlay_s)                      ,     &
-         &      fc_i(jpij,0:jkmax)  , de_i_lay(jpij,jkmax)                       , STAT=ierr(4) )
-
       thd_ice_alloc = MAXVAL( ierr )
 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 4921)
@@ -51,4 +51,5 @@
    USE trcnam
    USE trcrst
+   USE diaptr         ! Need to initialise this as some variables are used in if statements later
 
    IMPLICIT NONE
@@ -298,5 +299,9 @@
       !                                     ! Passive tracers
                             CALL     trc_init   ! Passive tracers initialization
-
+      !
+      ! Initialise diaptr as some variables are used in if statements later (in
+      ! various advection and diffusion routines.
+                            CALL dia_ptr_init
+      !
       IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
       !
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 4921)
@@ -104,9 +104,10 @@
    REAL(wp),    DIMENSION(jp_bdy) ::   rn_time_dmp_out          !: Damping time scale in days at radiation outflow points
 
-#if ( defined key_lim2 || defined key_lim3 )
    CHARACTER(len=20), DIMENSION(jp_bdy) ::   cn_ice_lim       ! Choice of boundary condition for sea ice variables 
    INTEGER, DIMENSION(jp_bdy)           ::   nn_ice_lim_dta   !: = 0 use the initial state as bdy dta ; 
                                                               !: = 1 read it in a NetCDF file
-#endif
+   REAL(wp),    DIMENSION(jp_bdy) ::   rn_ice_tem             !: choice of the temperature of incoming sea ice
+   REAL(wp),    DIMENSION(jp_bdy) ::   rn_ice_sal             !: choice of the salinity    of incoming sea ice
+   REAL(wp),    DIMENSION(jp_bdy) ::   rn_ice_age             !: choice of the age         of incoming sea ice
    !
    
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 4921)
@@ -676,5 +676,5 @@
                CALL iom_close ( inum )
                !CALL fld_clopn ( bn_a_i, nyear, nmonth, nday, ldstop=.TRUE. )
-               !CALL iom_open ( bn_a_i %clname, inum )
+               !CALL iom_open ( bn_a_i%clname, inum )
                !id1 = iom_varid ( bn_a_i%num, bn_a_i%clvar, kdimsz=zdimsz, kndims=zndims, ldstop = .FALSE. )
       	       IF ( zndims == 4 ) THEN
@@ -740,5 +740,5 @@
       jstart = 1
       DO ib_bdy = 1, nb_bdy
-         jend = nb_bdy_fld(ib_bdy) 
+         jend = jstart - 1 + nb_bdy_fld(ib_bdy) 
          CALL fld_fill( bf(jstart:jend), blf_i(jstart:jend), cn_dir_array(ib_bdy), 'bdy_dta',   &
          &              'open boundary conditions', 'nambdy_dta' )
@@ -907,4 +907,2 @@
    !!==============================================================================
 END MODULE bdydta
-
-
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90	(revision 4921)
@@ -30,5 +30,5 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE in_out_manager  !
-   USE domvvl
+   USE domvvl          ! variable volume
 
    IMPLICIT NONE
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90	(revision 4921)
@@ -24,11 +24,12 @@
    USE par_ice_2
    USE ice_2           ! LIM_2 ice variables
+   USE dom_ice_2       ! sea-ice domain
 #elif defined key_lim3
    USE par_ice
    USE ice             ! LIM_3 ice variables
+   USE dom_ice         ! sea-ice domain
 #endif 
    USE par_oce         ! ocean parameters
    USE dom_oce         ! ocean space and time domain variables 
-   USE dom_ice          ! sea-ice domain
    USE sbc_oce         ! Surface boundary condition: ocean fields
    USE bdy_oce         ! ocean open boundary conditions
@@ -99,7 +100,4 @@
       REAL(wp) ::   zinda, ztmelts, zdh
 
-      REAL(wp), PARAMETER  ::   zsal = 6.3    ! arbitrary salinity    for incoming ice
-      REAL(wp), PARAMETER  ::   ztem = 270.0  ! arbitrary temperature for incoming ice
-      REAL(wp), PARAMETER  ::   zage = 30.0   ! arbitrary age         for incoming ice
       !!------------------------------------------------------------------------------
       !
@@ -233,13 +231,13 @@
 
                ! Ice salinity, age, temperature
-               sm_i(ji,jj,jl)   = zinda * zsal  + ( 1.0 - zinda ) * s_i_min
-               o_i(ji,jj,jl)    = zinda * zage  + ( 1.0 - zinda )
-               t_su(ji,jj,jl)   = zinda * ztem  + ( 1.0 - zinda ) * ztem
+               sm_i(ji,jj,jl)   = zinda * rn_ice_sal(ib_bdy)  + ( 1.0 - zinda ) * s_i_min
+               o_i(ji,jj,jl)    = zinda * rn_ice_age(ib_bdy)  + ( 1.0 - zinda )
+               t_su(ji,jj,jl)   = zinda * rn_ice_tem(ib_bdy)  + ( 1.0 - zinda ) * rn_ice_tem(ib_bdy)
                DO jk = 1, nlay_s
-                  t_s(ji,jj,jk,jl) = zinda * ztem + ( 1.0 - zinda ) * rtt
+                  t_s(ji,jj,jk,jl) = zinda * rn_ice_tem(ib_bdy) + ( 1.0 - zinda ) * rtt
                END DO
                DO jk = 1, nlay_i
-                  t_i(ji,jj,jk,jl) = zinda * ztem + ( 1.0 - zinda ) * rtt 
-                  s_i(ji,jj,jk,jl) = zinda * zsal + ( 1.0 - zinda ) * s_i_min
+                  t_i(ji,jj,jk,jl) = zinda * rn_ice_tem(ib_bdy) + ( 1.0 - zinda ) * rtt 
+                  s_i(ji,jj,jk,jl) = zinda * rn_ice_sal(ib_bdy) + ( 1.0 - zinda ) * s_i_min
                END DO
                
@@ -259,4 +257,10 @@
 
             END SELECT
+
+            ! if salinity is constant, then overwrite rn_ice_sal
+            IF( num_sal == 1 ) THEN
+               sm_i(ji,jj,jl)   = bulk_sal
+               s_i (ji,jj,:,jl) = bulk_sal
+            ENDIF
 
             ! contents
@@ -338,5 +342,5 @@
       DO ib_bdy=1, nb_bdy
          !
-         SELECT CASE( nn_ice_lim(ib_bdy) )
+         SELECT CASE( cn_ice_lim(ib_bdy) )
 
          CASE('none')
@@ -355,5 +359,5 @@
                   ji    = idx_bdy(ib_bdy)%nbi(jb,jgrd)
                   jj    = idx_bdy(ib_bdy)%nbj(jb,jgrd)
-                  zflag = idx_bdy(ib_bdy)%flagu(jb)
+                  zflag = idx_bdy(ib_bdy)%flagu(jb,jgrd)
                   
                   IF ( ABS( zflag ) == 1. ) THEN  ! eastern and western boundaries
@@ -384,5 +388,5 @@
                   ji    = idx_bdy(ib_bdy)%nbi(jb,jgrd)
                   jj    = idx_bdy(ib_bdy)%nbj(jb,jgrd)
-                  zflag = idx_bdy(ib_bdy)%flagv(jb)
+                  zflag = idx_bdy(ib_bdy)%flagv(jb,jgrd)
                   
                   IF ( ABS( zflag ) == 1. ) THEN  ! northern and southern boundaries
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 4921)
@@ -100,7 +100,6 @@
          &             cn_dyn3d, nn_dyn3d_dta, cn_tra, nn_tra_dta,             &  
          &             ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp, rn_time_dmp_out, &
-#if ( defined key_lim2 || defined key_lim3 )
          &             cn_ice_lim, nn_ice_lim_dta,                           &
-#endif
+         &             rn_ice_tem, rn_ice_sal, rn_ice_age,                 &
          &             ln_vol, nn_volctl, nn_rimwidth
       !!
@@ -359,4 +358,7 @@
         ENDIF
         IF(lwp) WRITE(numout,*)
+        IF(lwp) WRITE(numout,*) '      tem of bdy sea-ice = ', rn_ice_tem(ib_bdy)         
+        IF(lwp) WRITE(numout,*) '      sal of bdy sea-ice = ', rn_ice_sal(ib_bdy)         
+        IF(lwp) WRITE(numout,*) '      age of bdy sea-ice = ', rn_ice_age(ib_bdy)         
 #endif
 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 4921)
@@ -418,7 +418,4 @@
       DO ib_bdy = 1,nb_bdy
 
-         ! line below should be simplified (runoff case)
-!! CHANUT: TO BE SORTED OUT
-!!         IF (( nn_dyn2d_dta(ib_bdy) .ge. 2 ).AND.(nn_tra(ib_bdy).NE.4)) THEN
          IF ( nn_dyn2d_dta(ib_bdy) .ge. 2 ) THEN
 
@@ -453,12 +450,12 @@
             IF ( PRESENT(kit) ) THEN
                IF ( lk_first_btstp ) THEN ! Save slow varying open boundary data:
-                  dta_bdy_s(ib_bdy)%ssh(1:ilen0(1)) = dta_bdy(ib_bdy)%ssh(1:ilen0(1))
-                  dta_bdy_s(ib_bdy)%u2d(1:ilen0(2)) = dta_bdy(ib_bdy)%u2d(1:ilen0(2))
-                  dta_bdy_s(ib_bdy)%v2d(1:ilen0(3)) = dta_bdy(ib_bdy)%v2d(1:ilen0(3))
+                  IF ( dta_bdy(ib_bdy)%ll_ssh ) dta_bdy_s(ib_bdy)%ssh(1:ilen0(1)) = dta_bdy(ib_bdy)%ssh(1:ilen0(1))
+                  IF ( dta_bdy(ib_bdy)%ll_u2d ) dta_bdy_s(ib_bdy)%u2d(1:ilen0(2)) = dta_bdy(ib_bdy)%u2d(1:ilen0(2))
+                  IF ( dta_bdy(ib_bdy)%ll_v2d ) dta_bdy_s(ib_bdy)%v2d(1:ilen0(3)) = dta_bdy(ib_bdy)%v2d(1:ilen0(3))
 
                ELSE ! Initialize arrays from slow varying open boundary data:            
-                  dta_bdy(ib_bdy)%ssh(1:ilen0(1)) = dta_bdy_s(ib_bdy)%ssh(1:ilen0(1))
-                  dta_bdy(ib_bdy)%u2d(1:ilen0(2)) = dta_bdy_s(ib_bdy)%u2d(1:ilen0(2))
-                  dta_bdy(ib_bdy)%v2d(1:ilen0(3)) = dta_bdy_s(ib_bdy)%v2d(1:ilen0(3))
+                  IF ( dta_bdy(ib_bdy)%ll_ssh ) dta_bdy(ib_bdy)%ssh(1:ilen0(1)) = dta_bdy_s(ib_bdy)%ssh(1:ilen0(1))
+                  IF ( dta_bdy(ib_bdy)%ll_u2d ) dta_bdy(ib_bdy)%u2d(1:ilen0(2)) = dta_bdy_s(ib_bdy)%u2d(1:ilen0(2))
+                  IF ( dta_bdy(ib_bdy)%ll_v2d ) dta_bdy(ib_bdy)%v2d(1:ilen0(3)) = dta_bdy_s(ib_bdy)%v2d(1:ilen0(3))
                ENDIF
             ENDIF
@@ -471,25 +468,31 @@
                z_sist = zramp * SIN( z_sarg )
                !
-               igrd=1                              ! SSH on tracer grid
-               DO ib = 1, ilen0(igrd)
-                  dta_bdy(ib_bdy)%ssh(ib) = dta_bdy(ib_bdy)%ssh(ib) + &
-                     &                      ( tides(ib_bdy)%ssh(ib,itide,1)*z_cost + &
-                     &                        tides(ib_bdy)%ssh(ib,itide,2)*z_sist )
-               END DO
-               !
-               igrd=2                              ! U grid
-               DO ib = 1, ilen0(igrd)
-                  dta_bdy(ib_bdy)%u2d(ib) = dta_bdy(ib_bdy)%u2d(ib) + &
-                     &                      ( tides(ib_bdy)%u(ib,itide,1)*z_cost + &
-                     &                        tides(ib_bdy)%u(ib,itide,2)*z_sist )
-               END DO
-               !
-               igrd=3                              ! V grid
-               DO ib = 1, ilen0(igrd) 
-                  dta_bdy(ib_bdy)%v2d(ib) = dta_bdy(ib_bdy)%v2d(ib) + &
-                     &                      ( tides(ib_bdy)%v(ib,itide,1)*z_cost + &
-                     &                        tides(ib_bdy)%v(ib,itide,2)*z_sist )
-               END DO
-            END DO
+               IF ( dta_bdy(ib_bdy)%ll_ssh ) THEN
+                  igrd=1                              ! SSH on tracer grid
+                  DO ib = 1, ilen0(igrd)
+                     dta_bdy(ib_bdy)%ssh(ib) = dta_bdy(ib_bdy)%ssh(ib) + &
+                        &                      ( tides(ib_bdy)%ssh(ib,itide,1)*z_cost + &
+                        &                        tides(ib_bdy)%ssh(ib,itide,2)*z_sist )
+                  END DO
+               ENDIF
+               !
+               IF ( dta_bdy(ib_bdy)%ll_u2d ) THEN
+                  igrd=2                              ! U grid
+                  DO ib = 1, ilen0(igrd)
+                     dta_bdy(ib_bdy)%u2d(ib) = dta_bdy(ib_bdy)%u2d(ib) + &
+                        &                      ( tides(ib_bdy)%u(ib,itide,1)*z_cost + &
+                        &                        tides(ib_bdy)%u(ib,itide,2)*z_sist )
+                  END DO
+               ENDIF
+               !
+               IF ( dta_bdy(ib_bdy)%ll_v2d ) THEN
+                  igrd=3                              ! V grid
+                  DO ib = 1, ilen0(igrd) 
+                     dta_bdy(ib_bdy)%v2d(ib) = dta_bdy(ib_bdy)%v2d(ib) + &
+                        &                      ( tides(ib_bdy)%v(ib,itide,1)*z_cost + &
+                        &                        tides(ib_bdy)%v(ib,itide,2)*z_sist )
+                  END DO
+               ENDIF
+            END DO             
          END IF
       END DO
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/C1D/c1d.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/C1D/c1d.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/C1D/c1d.F90	(revision 4921)
@@ -27,4 +27,5 @@
    REAL(wp), PUBLIC            ::  rn_lat1d     ! Column latitude
    REAL(wp), PUBLIC            ::  rn_lon1d     ! Column longitude
+   LOGICAL , PUBLIC            ::  ln_c1d_locpt ! Localization (or not) of 1D column in a grid
 
    !!----------------------------------------------------------------------
@@ -44,5 +45,5 @@
       !!----------------------------------------------------------------------
       INTEGER ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namc1d/ rn_lat1d, rn_lon1d
+      NAMELIST/namc1d/ rn_lat1d, rn_lon1d , ln_c1d_locpt
       !!----------------------------------------------------------------------
       !
@@ -63,6 +64,7 @@
          WRITE(numout,*) '~~~~~~~~'
          WRITE(numout,*) '   Namelist namc1d : set options for the C1D model'
-         WRITE(numout,*) '      column latitude                 rn_lat1d = ', rn_lat1d
-         WRITE(numout,*) '      column longitude                rn_lon1d = ', rn_lon1d
+         WRITE(numout,*) '      column latitude                 rn_lat1d     = ', rn_lat1d
+         WRITE(numout,*) '      column longitude                rn_lon1d     = ', rn_lon1d
+         WRITE(numout,*) '      column localization in a grid   ln_c1d_locpt = ', ln_c1d_locpt
       ENDIF
       !
@@ -78,4 +80,6 @@
    LOGICAL, PUBLIC, PARAMETER ::   lk_c1d = .FALSE.   !: 1D config. flag de-activated
    REAL(wp)                   ::   rn_lat1d, rn_lon1d
+   LOGICAL , PUBLIC           ::   ln_c1d_locpt = .FALSE. 
+
 CONTAINS
 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/C1D/domc1d.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/C1D/domc1d.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/C1D/domc1d.F90	(revision 4921)
@@ -43,7 +43,16 @@
       !! ** Action  : Recalculate jpizoom, jpjzoom (indices of C1D zoom)
       !!----------------------------------------------------------------------
+      NAMELIST/namdom/ nn_bathy, rn_bathy , rn_e3zps_min, rn_e3zps_rat, nn_msh, rn_hmin,   &
+         &             nn_acc   , rn_atfp     , rn_rdt      , rn_rdtmin ,                  &
+         &             rn_rdtmax, rn_rdth     , nn_closea , ln_crs,    &
+         &             jphgr_msh, &
+         &             ppglam0, ppgphi0, ppe1_deg, ppe2_deg, ppe1_m, ppe2_m, &
+         &             ppsur, ppa0, ppa1, ppkth, ppacr, ppdzmin, pphmax, ldbletanh, &
+         &             ppa2, ppkth2, ppacr2
+
       INTEGER  ::  ji, jj                          ! Dummy loop indices
       INTEGER  ::  inum                            ! Coordinate file handle (case 0)
       INTEGER  ::  ijeq                            ! Index of equator T point (case 4)
+      INTEGER  ::  ios                             ! Local integer output status for namelist read
 
       INTEGER , DIMENSION(2) ::   iloc             ! Minloc returned indices
@@ -63,4 +72,13 @@
       IF( nn_timing == 1 )   CALL timing_start('dom_c1d')
 
+      REWIND( numnam_ref )              ! Namelist namdom in reference namelist : space & time domain (bathymetry, mesh, timestep)
+      READ  ( numnam_ref, namdom, IOSTAT = ios, ERR = 901 )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdom in reference namelist', lwp )
+  
+      !
+      REWIND( numnam_cfg )              ! Namelist namdom in configuration namelist : space & time domain (bathymetry, mesh, timestep)
+      READ  ( numnam_cfg, namdom, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdom in configuration namelist', lwp )
+
       CALL wrk_alloc( jpidta, jpjdta, gphidta, glamdta, zdist )
 
@@ -80,9 +98,4 @@
          CALL iom_get( inum, jpdom_unknown, 'gphit', gphidta ) ! so use jpdom_unknown not jpdom_data
          CALL iom_close ( inum )
-
-         PRINT *,'Check dom_c1d coordinates file data read in:' !!!
-         PRINT *,'Bottom-left most glamdta is ', glamdta(1,1)    !!! Need to check
-         PRINT *,'Bottom-left most gphidta is ', gphidta(1,1)    !!! field read
-         PRINT *,'We are using nimpp,njmpp = ' , nimpp,njmpp     !!!
 
       CASE ( 1 )                 ! geographical mesh on the sphere with regular grid-spacing
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90	(revision 4921)
@@ -18,4 +18,5 @@
    USE daymod
    USE tide_mod
+   !
    USE in_out_manager  ! I/O units
    USE iom             ! I/0 library
@@ -34,9 +35,9 @@
    INTEGER, PARAMETER :: jpdimsparse  = jpincomax*300*24
 
-   !                            !!!namelist variables
+   !                         !!** namelist variables **
    INTEGER ::   nit000_han    ! First time step used for harmonic analysis
    INTEGER ::   nitend_han    ! Last time step used for harmonic analysis
    INTEGER ::   nstep_han     ! Time step frequency for harmonic analysis
-   INTEGER ::   nb_ana           ! Number of harmonics to analyse
+   INTEGER ::   nb_ana        ! Number of harmonics to analyse
 
    INTEGER , ALLOCATABLE, DIMENSION(:)       ::   name
@@ -119,5 +120,5 @@
             ENDIF
          END DO
-      ENDDO
+      END DO
       !
       IF(lwp) THEN
@@ -158,5 +159,5 @@
       ! ----------------------------
       ALLOCATE( ana_temp(jpi,jpj,2*nb_ana,3) )
-      ana_temp(:,:,:,:) = 0.e0
+      ana_temp(:,:,:,:) = 0._wp
 
    END SUBROUTINE dia_harm_init
@@ -179,32 +180,31 @@
       IF( nn_timing == 1 )   CALL timing_start('dia_harm')
 
-      IF ( kt == nit000 ) CALL dia_harm_init
-
-      IF ( ((kt.GE.nit000_han).AND.(kt.LE.nitend_han)).AND. &
-           (MOD(kt,nstep_han).EQ.0) ) THEN
-
-        ztime = (kt-nit000+1)*rdt 
+      IF( kt == nit000 ) CALL dia_harm_init
+
+      IF( kt >= nit000_han .AND. kt <= nitend_han .AND. MOD(kt,nstep_han) == 0 ) THEN
+
+         ztime = (kt-nit000+1) * rdt 
        
-        nhc = 0
-        DO jh = 1,nb_ana
-          DO jc = 1,2
-            nhc = nhc+1
-            ztemp =(     MOD(jc,2) * ft(jh) *COS(ana_freq(jh)*ztime + vt(jh) + ut(jh))  &
-                    +(1.-MOD(jc,2))* ft(jh) *SIN(ana_freq(jh)*ztime + vt(jh) + ut(jh)))
-
-            DO jj = 1,jpj
-              DO ji = 1,jpi
-                ! Elevation
-                ana_temp(ji,jj,nhc,1) = ana_temp(ji,jj,nhc,1) + ztemp*sshn(ji,jj)           *tmask(ji,jj,1)        
+         nhc = 0
+         DO jh = 1, nb_ana
+            DO jc = 1, 2
+               nhc = nhc+1
+               ztemp =(     MOD(jc,2) * ft(jh) *COS(ana_freq(jh)*ztime + vt(jh) + ut(jh))  &
+                  &    +(1.-MOD(jc,2))* ft(jh) *SIN(ana_freq(jh)*ztime + vt(jh) + ut(jh)))
+
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     ! Elevation
+                     ana_temp(ji,jj,nhc,1) = ana_temp(ji,jj,nhc,1) + ztemp*sshn(ji,jj)           *tmask(ji,jj,1)
 #if defined key_dynspg_ts
-                ana_temp(ji,jj,nhc,2) = ana_temp(ji,jj,nhc,2) + ztemp*un_b(ji,jj)*hur(ji,jj)*umask(ji,jj,1)
-                ana_temp(ji,jj,nhc,3) = ana_temp(ji,jj,nhc,3) + ztemp*vn_b(ji,jj)*hvr(ji,jj)*vmask(ji,jj,1)
-#endif
-              END DO
-            END DO
-
-          END DO
-        END DO
-       
+                     ana_temp(ji,jj,nhc,2) = ana_temp(ji,jj,nhc,2) + ztemp*un_b(ji,jj)*hur(ji,jj)*umask(ji,jj,1)
+                     ana_temp(ji,jj,nhc,3) = ana_temp(ji,jj,nhc,3) + ztemp*vn_b(ji,jj)*hvr(ji,jj)*vmask(ji,jj,1)
+#endif
+                  END DO
+               END DO
+               !
+            END DO
+         END DO
+         !       
       END IF
 
@@ -249,6 +249,6 @@
          keq = keq + 1
          kun = 0
-         DO jh = 1,nb_ana
-            DO jc = 1,2
+         DO jh = 1, nb_ana
+            DO jc = 1, 2
                kun = kun + 1
                ksp = ksp + 1
@@ -296,7 +296,7 @@
                out_eta(ji,jj,jh       ) = X1 * tmask(ji,jj,1)
                out_eta(ji,jj,jh+nb_ana) = X2 * tmask(ji,jj,1)
-            ENDDO
-         ENDDO
-      ENDDO
+            END DO
+         END DO
+      END DO
 
       ! ubar:
@@ -309,6 +309,6 @@
                   kun = kun + 1
                   ztmp4(kun)=ana_temp(ji,jj,kun,2)
-               ENDDO
-            ENDDO
+               END DO
+            END DO
 
             CALL SUR_DETERMINE(jj+1)
@@ -316,6 +316,6 @@
             ! Fill output array
             DO jh = 1, nb_ana
-               ana_amp(ji,jj,jh,1)=ztmp7((jh-1)*2+1)
-               ana_amp(ji,jj,jh,2)=ztmp7((jh-1)*2+2)
+               ana_amp(ji,jj,jh,1) = ztmp7((jh-1)*2+1)
+               ana_amp(ji,jj,jh,2) = ztmp7((jh-1)*2+2)
             END DO
 
@@ -326,11 +326,11 @@
          DO ji = 1, jpi
             DO jh = 1, nb_ana 
-               X1=ana_amp(ji,jj,jh,1)
-               X2=-ana_amp(ji,jj,jh,2)
-               out_u(ji,jj,jh) = X1 * umask(ji,jj,1)
-               out_u (ji,jj,nb_ana+jh) = X2 * umask(ji,jj,1)
-            ENDDO
-         ENDDO
-      ENDDO
+               X1 = ana_amp(ji,jj,jh,1)
+               X2 =-ana_amp(ji,jj,jh,2)
+               out_u(ji,jj,jh       ) = X1 * umask(ji,jj,1)
+               out_u(ji,jj,nb_ana+jh) = X2 * umask(ji,jj,1)
+            END DO
+         END DO
+      END DO
 
       ! vbar:
@@ -343,6 +343,6 @@
                   kun = kun + 1
                   ztmp4(kun)=ana_temp(ji,jj,kun,3)
-               ENDDO
-            ENDDO
+               END DO
+            END DO
 
             CALL SUR_DETERMINE(jj+1)
@@ -364,7 +364,7 @@
                out_v(ji,jj,jh)=X1 * vmask(ji,jj,1)
                out_v(ji,jj,nb_ana+jh)=X2 * vmask(ji,jj,1)
-            ENDDO
-         ENDDO
-      ENDDO
+            END DO
+         END DO
+      END DO
 
       CALL dia_wri_harm ! Write results in files
@@ -437,118 +437,118 @@
 #else
       DO jh = 1, nb_ana
-         CALL iom_put( TRIM(tname(jh))//'x_v', out_u(:,:,jh       ) )
-         CALL iom_put( TRIM(tname(jh))//'y_v', out_u(:,:,jh+nb_ana) )
-      END DO
-#endif
-
+         CALL iom_put( TRIM(tname(jh))//'x_v', out_v(:,:,jh       ) )
+         CALL iom_put( TRIM(tname(jh))//'y_v', out_v(:,:,jh+nb_ana) )
+      END DO
+#endif
+      !
    END SUBROUTINE dia_wri_harm
 
 
    SUBROUTINE SUR_DETERMINE(init)
-   !!---------------------------------------------------------------------------------
-   !!                      *** ROUTINE SUR_DETERMINE ***
-   !!    
-   !!    
-   !!       
-   !!---------------------------------------------------------------------------------
-   INTEGER, INTENT(in) ::   init 
-   !
-   INTEGER                         :: ji_sd, jj_sd, ji1_sd, ji2_sd, jk1_sd, jk2_sd
-   REAL(wp)                        :: zval1, zval2, zx1
-   REAL(wp), POINTER, DIMENSION(:) :: ztmpx, zcol1, zcol2
-   INTEGER , POINTER, DIMENSION(:) :: ipos2, ipivot
-   !---------------------------------------------------------------------------------
-   CALL wrk_alloc( jpincomax , ztmpx , zcol1 , zcol2 )
-   CALL wrk_alloc( jpincomax , ipos2 , ipivot        )
+      !!---------------------------------------------------------------------------------
+      !!                      *** ROUTINE SUR_DETERMINE ***
+      !!    
+      !!    
+      !!       
+      !!---------------------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   init 
+      !
+      INTEGER                         :: ji_sd, jj_sd, ji1_sd, ji2_sd, jk1_sd, jk2_sd
+      REAL(wp)                        :: zval1, zval2, zx1
+      REAL(wp), POINTER, DIMENSION(:) :: ztmpx, zcol1, zcol2
+      INTEGER , POINTER, DIMENSION(:) :: ipos2, ipivot
+      !---------------------------------------------------------------------------------
+      CALL wrk_alloc( jpincomax , ztmpx , zcol1 , zcol2 )
+      CALL wrk_alloc( jpincomax , ipos2 , ipivot        )
             
-   IF( init == 1 ) THEN
-      IF( nsparse > jpdimsparse )   CALL ctl_stop( 'STOP', 'SUR_DETERMINE : nsparse .GT. jpdimsparse')
-      IF( ninco   > jpincomax   )   CALL ctl_stop( 'STOP', 'SUR_DETERMINE : ninco .GT. jpincomax')
-      !
-      ztmp3(:,:) = 0._wp
-      !
-      DO jk1_sd = 1, nsparse
-         DO jk2_sd = 1, nsparse
-            nisparse(jk2_sd) = nisparse(jk2_sd)
-            njsparse(jk2_sd) = njsparse(jk2_sd)
-            IF( nisparse(jk2_sd) == nisparse(jk1_sd) ) THEN
-               ztmp3(njsparse(jk1_sd),njsparse(jk2_sd)) = ztmp3(njsparse(jk1_sd),njsparse(jk2_sd))  &
-                                                        + valuesparse(jk1_sd)*valuesparse(jk2_sd)
-            ENDIF
-         END DO
-      END DO
-
-      DO jj_sd = 1 ,ninco
-          ipos1(jj_sd) = jj_sd
-          ipos2(jj_sd) = jj_sd
-      ENDDO
-
-      DO ji_sd = 1 , ninco
-
-         !find greatest non-zero pivot:
-         zval1 = ABS(ztmp3(ji_sd,ji_sd))
-
-         ipivot(ji_sd) = ji_sd
-         DO jj_sd = ji_sd, ninco
-            zval2 = ABS(ztmp3(ji_sd,jj_sd))
-            IF( zval2.GE.zval1 )THEN
-               ipivot(ji_sd) = jj_sd
-               zval1         = zval2
-            ENDIF
-         ENDDO
-
-         DO ji1_sd = 1, ninco
-            zcol1(ji1_sd)               = ztmp3(ji1_sd,ji_sd)
-            zcol2(ji1_sd)               = ztmp3(ji1_sd,ipivot(ji_sd))
-            ztmp3(ji1_sd,ji_sd)         = zcol2(ji1_sd)
-            ztmp3(ji1_sd,ipivot(ji_sd)) = zcol1(ji1_sd)
-         ENDDO
-
-         ipos2(ji_sd)         = ipos1(ipivot(ji_sd))
-         ipos2(ipivot(ji_sd)) = ipos1(ji_sd)
-         ipos1(ji_sd)         = ipos2(ji_sd)
-         ipos1(ipivot(ji_sd)) = ipos2(ipivot(ji_sd))
-         zpivot(ji_sd)        = ztmp3(ji_sd,ji_sd)
-         DO jj_sd = 1, ninco
-            ztmp3(ji_sd,jj_sd) = ztmp3(ji_sd,jj_sd) / zpivot(ji_sd)
-         ENDDO
-
+      IF( init == 1 ) THEN
+         IF( nsparse > jpdimsparse )   CALL ctl_stop( 'STOP', 'SUR_DETERMINE : nsparse .GT. jpdimsparse')
+         IF( ninco   > jpincomax   )   CALL ctl_stop( 'STOP', 'SUR_DETERMINE : ninco .GT. jpincomax')
+         !
+         ztmp3(:,:) = 0._wp
+         !
+         DO jk1_sd = 1, nsparse
+            DO jk2_sd = 1, nsparse
+               nisparse(jk2_sd) = nisparse(jk2_sd)
+               njsparse(jk2_sd) = njsparse(jk2_sd)
+               IF( nisparse(jk2_sd) == nisparse(jk1_sd) ) THEN
+                  ztmp3(njsparse(jk1_sd),njsparse(jk2_sd)) = ztmp3(njsparse(jk1_sd),njsparse(jk2_sd))  &
+                     &                                     + valuesparse(jk1_sd)*valuesparse(jk2_sd)
+               ENDIF
+            END DO
+         END DO
+         !
+         DO jj_sd = 1 ,ninco
+            ipos1(jj_sd) = jj_sd
+            ipos2(jj_sd) = jj_sd
+         END DO
+         !
+         DO ji_sd = 1 , ninco
+            !
+            !find greatest non-zero pivot:
+            zval1 = ABS(ztmp3(ji_sd,ji_sd))
+            !
+            ipivot(ji_sd) = ji_sd
+            DO jj_sd = ji_sd, ninco
+               zval2 = ABS(ztmp3(ji_sd,jj_sd))
+               IF( zval2.GE.zval1 )THEN
+                  ipivot(ji_sd) = jj_sd
+                  zval1         = zval2
+               ENDIF
+            END DO
+            !
+            DO ji1_sd = 1, ninco
+               zcol1(ji1_sd)               = ztmp3(ji1_sd,ji_sd)
+               zcol2(ji1_sd)               = ztmp3(ji1_sd,ipivot(ji_sd))
+               ztmp3(ji1_sd,ji_sd)         = zcol2(ji1_sd)
+               ztmp3(ji1_sd,ipivot(ji_sd)) = zcol1(ji1_sd)
+            END DO
+            !
+            ipos2(ji_sd)         = ipos1(ipivot(ji_sd))
+            ipos2(ipivot(ji_sd)) = ipos1(ji_sd)
+            ipos1(ji_sd)         = ipos2(ji_sd)
+            ipos1(ipivot(ji_sd)) = ipos2(ipivot(ji_sd))
+            zpivot(ji_sd)        = ztmp3(ji_sd,ji_sd)
+            DO jj_sd = 1, ninco
+               ztmp3(ji_sd,jj_sd) = ztmp3(ji_sd,jj_sd) / zpivot(ji_sd)
+            END DO
+            !
+            DO ji2_sd = ji_sd+1, ninco
+               zpilier(ji2_sd,ji_sd)=ztmp3(ji2_sd,ji_sd)
+               DO jj_sd=1,ninco
+                  ztmp3(ji2_sd,jj_sd)=  ztmp3(ji2_sd,jj_sd) - ztmp3(ji_sd,jj_sd) * zpilier(ji2_sd,ji_sd)
+               END DO
+            END DO
+            !
+         END DO
+         !
+      ENDIF ! End init==1
+
+      DO ji_sd = 1, ninco
+         ztmp4(ji_sd) = ztmp4(ji_sd) / zpivot(ji_sd)
          DO ji2_sd = ji_sd+1, ninco
-            zpilier(ji2_sd,ji_sd)=ztmp3(ji2_sd,ji_sd)
-            DO jj_sd=1,ninco
-               ztmp3(ji2_sd,jj_sd)=  ztmp3(ji2_sd,jj_sd) - ztmp3(ji_sd,jj_sd) * zpilier(ji2_sd,ji_sd)
-            ENDDO
-         ENDDO
-
-      ENDDO
-
-   ENDIF ! End init==1
-
-   DO ji_sd = 1, ninco
-      ztmp4(ji_sd) = ztmp4(ji_sd) / zpivot(ji_sd)
-      DO ji2_sd = ji_sd+1, ninco
-         ztmp4(ji2_sd) = ztmp4(ji2_sd) - ztmp4(ji_sd) * zpilier(ji2_sd,ji_sd)
-      ENDDO
-   ENDDO
-
-   !system solving: 
-   ztmpx(ninco) = ztmp4(ninco) / ztmp3(ninco,ninco)
-   ji_sd = ninco
-   DO ji_sd = ninco-1, 1, -1
-      zx1=0.
-      DO jj_sd = ji_sd+1, ninco
-         zx1 = zx1 + ztmpx(jj_sd) * ztmp3(ji_sd,jj_sd)
-      ENDDO
-      ztmpx(ji_sd) = ztmp4(ji_sd)-zx1
-   ENDDO
-
-   DO jj_sd =1, ninco
-      ztmp7(ipos1(jj_sd))=ztmpx(jj_sd)
-   ENDDO
-
-   CALL wrk_dealloc( jpincomax , ztmpx , zcol1 , zcol2 )
-   CALL wrk_dealloc( jpincomax , ipos2 , ipivot        )
-
-  END SUBROUTINE SUR_DETERMINE
+            ztmp4(ji2_sd) = ztmp4(ji2_sd) - ztmp4(ji_sd) * zpilier(ji2_sd,ji_sd)
+         END DO
+      END DO
+
+      !system solving: 
+      ztmpx(ninco) = ztmp4(ninco) / ztmp3(ninco,ninco)
+      ji_sd = ninco
+      DO ji_sd = ninco-1, 1, -1
+         zx1 = 0._wp
+         DO jj_sd = ji_sd+1, ninco
+            zx1 = zx1 + ztmpx(jj_sd) * ztmp3(ji_sd,jj_sd)
+         END DO
+         ztmpx(ji_sd) = ztmp4(ji_sd)-zx1
+      END DO
+
+      DO jj_sd =1, ninco
+         ztmp7(ipos1(jj_sd))=ztmpx(jj_sd)
+      END DO
+
+      CALL wrk_dealloc( jpincomax , ztmpx , zcol1 , zcol2 )
+      CALL wrk_dealloc( jpincomax , ipos2 , ipivot        )
+      !
+   END SUBROUTINE SUR_DETERMINE
 
 #else
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 4921)
@@ -45,5 +45,4 @@
    USE diadimg         ! dimg direct access file format output
    USE diaar5, ONLY :   lk_diaar5
-   USE dynadv, ONLY :   ln_dynadv_vec
    USE iom
    USE ioipsl
@@ -131,5 +130,6 @@
       REAL(wp)                     ::   zztmp, zztmpx, zztmpy   ! 
       !!
-      REAL(wp), POINTER, DIMENSION(:,:)   :: z2d       ! 2D workspace
+      REAL(wp), POINTER, DIMENSION(:,:)   :: z2d      ! 2D workspace
+      REAL(wp), POINTER, DIMENSION(:,:)   :: z2ds     ! 2D workspace
       REAL(wp), POINTER, DIMENSION(:,:,:) :: z3d      ! 3D workspace
       !!----------------------------------------------------------------------
@@ -137,5 +137,5 @@
       IF( nn_timing == 1 )   CALL timing_start('dia_wri')
       ! 
-      CALL wrk_alloc( jpi , jpj      , z2d )
+      CALL wrk_alloc( jpi , jpj      , z2d , z2ds )
       CALL wrk_alloc( jpi , jpj, jpk , z3d )
       !
@@ -193,38 +193,88 @@
       CALL iom_put( "sstgrad" ,  z2d               )    ! module of sst gradient
 
+      ! clem: heat and salt content
+      z2d(:,:)  = 0._wp 
+      z2ds(:,:) = 0._wp 
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               z2d(ji,jj) = z2d(ji,jj) + rau0 * rcp * fse3t(ji,jj,jk) * tsn(ji,jj,jk,jp_tem) * tmask(ji,jj,jk)
+               z2ds(ji,jj) = z2ds(ji,jj) + rau0 * fse3t(ji,jj,jk) * tsn(ji,jj,jk,jp_sal) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk( z2d, 'T', 1. )
+      CALL lbc_lnk( z2ds, 'T', 1. )
+      CALL iom_put( "heatc", z2d )    ! vertically integrated heat content (J/m2)
+      CALL iom_put( "saltc", z2ds )   ! vertically integrated salt content (PSU*kg/m2)
+  
+      !
+      rke(:,:,jk) = 0._wp                               !      kinetic energy 
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zztmp   = 1._wp / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
+               zztmpx  = 0.5 * (  un(ji-1,jj,jk) * un(ji-1,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk)    &
+                  &             + un(ji  ,jj,jk) * un(ji  ,jj,jk) * e2u(ji  ,jj) * fse3u(ji  ,jj,jk) )  &
+                  &          *  zztmp 
+               !
+               zztmpy  = 0.5 * (  vn(ji,jj-1,jk) * vn(ji,jj-1,jk) * e1v(ji,jj-1) * fse3v(ji,jj-1,jk)    &
+                  &             + vn(ji,jj  ,jk) * vn(ji,jj  ,jk) * e1v(ji,jj  ) * fse3v(ji,jj  ,jk) )  &
+                  &          *  zztmp 
+               !
+               rke(ji,jj,jk) = 0.5_wp * ( zztmpx + zztmpy )
+               !
+            ENDDO
+         ENDDO
+      ENDDO
+      CALL lbc_lnk( rke, 'T', 1. )
+      CALL iom_put( "eken", rke )           
+
       IF( lk_diaar5 ) THEN
          z3d(:,:,jpk) = 0.e0
          DO jk = 1, jpkm1
-            z3d(:,:,jk) = rau0 * un(:,:,jk) * e2u(:,:) * fse3u(:,:,jk)
+            z3d(:,:,jk) = rau0 * un(:,:,jk) * e2u(:,:) * fse3u(:,:,jk) * umask(:,:,jk)
          END DO
          CALL iom_put( "u_masstr", z3d )                  ! mass transport in i-direction
+
          zztmp = 0.5 * rcp
          z2d(:,:) = 0.e0 
+         z2ds(:,:) = 0.e0 
          DO jk = 1, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * zztmp * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
+                  z2ds(ji,jj) = z2ds(ji,jj) + z3d(ji,jj,jk) * 0.5_wp * ( tsn(ji,jj,jk,jp_sal) + tsn(ji+1,jj,jk,jp_sal) )
                END DO
             END DO
          END DO
          CALL lbc_lnk( z2d, 'U', -1. )
+         CALL lbc_lnk( z2ds, 'U', -1. )
          CALL iom_put( "u_heattr", z2d )                  ! heat transport in i-direction
+         CALL iom_put( "u_salttr", z2ds )                 ! salt transport in i-direction
+
+         z3d(:,:,jpk) = 0.e0
          DO jk = 1, jpkm1
-            z3d(:,:,jk) = rau0 * vn(:,:,jk) * e1v(:,:) * fse3v(:,:,jk)
+            z3d(:,:,jk) = rau0 * vn(:,:,jk) * e1v(:,:) * fse3v(:,:,jk) * vmask(:,:,jk)
          END DO
          CALL iom_put( "v_masstr", z3d )                  ! mass transport in j-direction
+
          z2d(:,:) = 0.e0 
+         z2ds(:,:) = 0.e0 
          DO jk = 1, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * zztmp * ( tsn(ji,jj,jk,jp_tem) + tsn(ji,jj+1,jk,jp_tem) )
+                  z2ds(ji,jj) = z2ds(ji,jj) + z3d(ji,jj,jk) * 0.5_wp * ( tsn(ji,jj,jk,jp_sal) + tsn(ji,jj+1,jk,jp_sal) )
                END DO
             END DO
          END DO
          CALL lbc_lnk( z2d, 'V', -1. )
-         CALL iom_put( "v_heattr", z2d )                  !  heat transport in i-direction
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi , jpj      , z2d )
+         CALL lbc_lnk( z2ds, 'V', -1. )
+         CALL iom_put( "v_heattr", z2d )                  !  heat transport in j-direction
+         CALL iom_put( "v_salttr", z2ds )                 !  salt transport in j-direction
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi , jpj      , z2d , z2ds )
       CALL wrk_dealloc( jpi , jpj, jpk , z3d )
       !
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 4921)
@@ -153,4 +153,5 @@
    INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   nldit , nldjt    !: first, last indoor index for each i-domain
    INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   nleit , nlejt    !: first, last indoor index for each j-domain
+   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: nfiimpp, nfipproc, nfilcit
 
    !!----------------------------------------------------------------------
@@ -329,5 +330,6 @@
       ierr(:) = 0
       !
-      ALLOCATE( rdttra(jpk), r2dtra(jpk), mig(jpi), mjg(jpj), STAT=ierr(1) )
+      ALLOCATE( rdttra(jpk), r2dtra(jpk), mig(jpi), mjg(jpj), nfiimpp(jpni,jpnj),  &
+         &      nfipproc(jpni,jpnj), nfilcit(jpni,jpnj), STAT=ierr(1) )
          !
       ALLOCATE( nimppt(jpnij) , ibonit(jpnij) , nlcit(jpnij) , nlcjt(jpnij) ,     &
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/domcfg.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/domcfg.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/domcfg.F90	(revision 4921)
@@ -82,5 +82,5 @@
       !!----------------------------------------------------------------------
       !                              ! recalculate jpizoom/jpjzoom given lat/lon
-      IF( lk_c1d )  CALL dom_c1d( rn_lat1d, rn_lon1d )
+      IF( lk_c1d .AND. ln_c1d_locpt )  CALL dom_c1d( rn_lat1d, rn_lon1d )
       !
       !                        ! ============== !
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 4921)
@@ -808,5 +808,5 @@
             id3 = iom_varid( numror, 'tilde_e3t_b', ldstop = .FALSE. )
             id4 = iom_varid( numror, 'tilde_e3t_n', ldstop = .FALSE. )
-            id5 = iom_varid( numror, 'hdif_lf', ldstop = .FALSE. )
+            id5 = iom_varid( numror, 'hdiv_lf', ldstop = .FALSE. )
             !                             ! --------- !
             !                             ! all cases !
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4921)
@@ -1445,6 +1445,6 @@
             DO jk = 1, jpkm1
                IF( scobot(ji,jj) >= fsdept(ji,jj,jk) )   mbathy(ji,jj) = MAX( 2, jk )
-               IF( scobot(ji,jj) == 0._wp            )   mbathy(ji,jj) = 0
-            END DO
+            END DO
+            IF( scobot(ji,jj) == 0._wp               )   mbathy(ji,jj) = 0
          END DO
       END DO
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/phycst.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/phycst.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DOM/phycst.F90	(revision 4921)
@@ -54,6 +54,6 @@
    REAL(wp), PUBLIC ::   r1_rau0                     !: = 1. / rau0                   [m3/kg]
    REAL(wp), PUBLIC ::   rauw     = 1000._wp         !: volumic mass of pure water    [m3/kg]
-   REAL(wp), PUBLIC ::   rcp      =    4.e3_wp       !: ocean specific heat           [J/Kelvin]
-   REAL(wp), PUBLIC ::   r1_rcp                      !: = 1. / rcp                    [Kelvin/J]
+   REAL(wp), PUBLIC ::   rcp      =    4.e3_wp       !: ocean specific heat           [J/kg/K]
+   REAL(wp), PUBLIC ::   r1_rcp                      !: = 1. / rcp                    [kg.K/J]
    REAL(wp), PUBLIC ::   r1_rau0_rcp                 !: = 1. / ( rau0 * rcp )
 
@@ -69,10 +69,10 @@
 #if defined key_lim3 || defined key_cice
    REAL(wp), PUBLIC ::   rhoic    =  917._wp         !: volumic mass of sea ice                               [kg/m3]
-   REAL(wp), PUBLIC ::   rcdic    =    2.034396_wp   !: thermal conductivity of fresh ice
-   REAL(wp), PUBLIC ::   rcdsn    =    0.31_wp       !: thermal conductivity of snow
-   REAL(wp), PUBLIC ::   cpic     = 2067.0_wp        !: specific heat for ice 
+   REAL(wp), PUBLIC ::   rcdic    =    2.034396_wp   !: thermal conductivity of fresh ice                     [W/m/K]
+   REAL(wp), PUBLIC ::   rcdsn    =    0.31_wp       !: thermal conductivity of snow                          [W/m/K] 
+   REAL(wp), PUBLIC ::   cpic     = 2067.0_wp        !: specific heat for ice                                 [J/kg/K]
    REAL(wp), PUBLIC ::   lsub     =    2.834e+6_wp   !: pure ice latent heat of sublimation                   [J/kg]
    REAL(wp), PUBLIC ::   lfus     =    0.334e+6_wp   !: latent heat of fusion of fresh ice                    [J/kg]
-   REAL(wp), PUBLIC ::   tmut     =    0.054_wp      !: decrease of seawater meltpoint with salinity
+   REAL(wp), PUBLIC ::   tmut     =    0.054_wp      !: decrease of seawater meltpoint with salinity          [degC/ppt]
    REAL(wp), PUBLIC ::   xlsn                        !: = lfus*rhosn (volumetric latent heat fusion of snow)  [J/m3]
 #else
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 4921)
@@ -44,5 +44,7 @@
    USE agrif_opa_interp ! agrif
 #endif
-
+#if defined key_asminc   
+   USE asminc          ! Assimilation increment
+#endif
 
    IMPLICIT NONE
@@ -290,15 +292,6 @@
       !
       DO jk = 1, jpkm1
-#if defined key_vectopt_loop
-         DO jj = 1, 1         !Vector opt. => forced unrolling
-            DO ji = 1, jpij
-#else 
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-#endif                                                                   
-               zu_frc(ji,jj) = zu_frc(ji,jj) + fse3u_n(ji,jj,jk) * ua(ji,jj,jk) * umask(ji,jj,jk)
-               zv_frc(ji,jj) = zv_frc(ji,jj) + fse3v_n(ji,jj,jk) * va(ji,jj,jk) * vmask(ji,jj,jk)         
-            END DO
-         END DO
+         zu_frc(:,:) = zu_frc(:,:) + fse3u_n(:,:,jk) * ua(:,:,jk) * umask(:,:,jk)
+         zv_frc(:,:) = zv_frc(:,:) + fse3v_n(:,:,jk) * va(:,:,jk) * vmask(:,:,jk)         
       END DO
       !
@@ -464,4 +457,13 @@
       !                                             ! ==================== !  
       ! Initialize barotropic variables:      
+      IF( ll_init )THEN
+         sshbb_e(:,:) = 0._wp
+         ubb_e  (:,:) = 0._wp
+         vbb_e  (:,:) = 0._wp
+         sshb_e (:,:) = 0._wp
+         ub_e   (:,:) = 0._wp
+         vb_e   (:,:) = 0._wp
+      ENDIF
+      !
       IF (ln_bt_fw) THEN                  ! FORWARD integration: start from NOW fields                    
          sshn_e(:,:) = sshn (:,:)            
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 4921)
@@ -32,4 +32,9 @@
    USE trc_oce, ONLY :   nn_dttrc        !  !: frequency of step on passive tracers
    USE icb_oce, ONLY :   nclasses, class_num       !  !: iceberg classes
+#if defined key_lim3
+   USE par_ice
+#elif defined key_lim2
+   USE par_ice_2
+#endif
    USE domngb          ! ocean space and time domain
    USE phycst          ! physical constants
@@ -49,5 +54,5 @@
 #endif
    PUBLIC iom_init, iom_swap, iom_open, iom_close, iom_setkt, iom_varid, iom_get, iom_gettime, iom_rstput, iom_put
-   PUBLIC iom_getatt, iom_context_finalize
+   PUBLIC iom_getatt, iom_use, iom_context_finalize
 
    PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
@@ -143,4 +148,7 @@
       CALL iom_set_axis_attr( "nfloat", (/ (REAL(ji,wp), ji=1,nfloat) /) )
 # endif
+#if defined key_lim3 || defined key_lim2
+      CALL iom_set_axis_attr( "ncatice", (/ (REAL(ji,wp), ji=1,jpl) /) )
+#endif
       CALL iom_set_axis_attr( "icbcla", class_num )
       
@@ -1015,6 +1023,9 @@
       CHARACTER(LEN=*), INTENT(in) ::   cdname
       REAL(wp)        , INTENT(in) ::   pfield0d
+      REAL(wp)        , DIMENSION(jpi,jpj) ::   zz     ! masson
 #if defined key_iomput
-      CALL xios_send_field(cdname, (/pfield0d/))
+      zz(:,:)=pfield0d
+      CALL xios_send_field(cdname, zz)
+      !CALL xios_send_field(cdname, (/pfield0d/)) 
 #else
       IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
@@ -1207,9 +1218,10 @@
       !!
       !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(1,1) ::   zz = 1.
+      REAL(wp), DIMENSION(1) ::   zz = 1.
       !!----------------------------------------------------------------------
       CALL iom_set_domain_attr('scalarpoint', ni_glo=jpnij, nj_glo=1, ibegin=narea, jbegin=1, ni=1, nj=1)
-      CALL iom_set_domain_attr('scalarpoint', data_dim=1)
-      CALL iom_set_domain_attr('scalarpoint', lonvalue=(/ zz /), latvalue=(/ zz /))
+      CALL iom_set_domain_attr('scalarpoint', data_dim=2, data_ibegin = 1, data_ni = 1, data_jbegin = 1, data_nj = 1)
+      zz=REAL(narea,wp)
+      CALL iom_set_domain_attr('scalarpoint', lonvalue=zz, latvalue=zz)
 
    END SUBROUTINE set_scalar
@@ -1499,4 +1511,13 @@
 
 #endif
+
+   LOGICAL FUNCTION iom_use( cdname )
+      CHARACTER(LEN=*), INTENT(in) ::   cdname
+#if defined key_iomput
+      iom_use = xios_field_is_active( cdname )
+#else
+      iom_use = .FALSE.
+#endif
+   END FUNCTION iom_use
    
    !!======================================================================
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 4921)
@@ -217,5 +217,5 @@
          CALL iom_nf90_check(NF90_Inquire_Variable(if90id, ivarid, dimids = idimid(1:i_nvd)), clinfo)   ! dimensions ids
          iom_file(kiomid)%luld(kiv) = .FALSE.   ! default value
-         iom_file(kiomid)%dimsz(:,kiv) = 0   ! reset dimsz in case previously used
+         iom_file(kiomid)%dimsz(:,kiv) = 0      ! reset dimsz in case previously used
          DO ji = 1, i_nvd                       ! dimensions size
             CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, idimid(ji), len = iom_file(kiomid)%dimsz(ji,kiv)), clinfo)   
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 4921)
@@ -120,4 +120,5 @@
                      CALL iom_rstput( kt, nitrst, numrow, 'hdivb'  , hdivb     )
                      CALL iom_rstput( kt, nitrst, numrow, 'sshb'   , sshb      )
+      IF( lk_lim3 )  CALL iom_rstput( kt, nitrst, numrow, 'fse3t_b', fse3t_b(:,:,:) )
                      !
                      CALL iom_rstput( kt, nitrst, numrow, 'un'     , un        )     ! now fields
@@ -210,4 +211,5 @@
          CALL iom_get( numror, jpdom_autoglo, 'hdivb'  , hdivb   )
          CALL iom_get( numror, jpdom_autoglo, 'sshb'   , sshb    )
+         IF( lk_lim3 )   CALL iom_get( numror, jpdom_autoglo, 'fse3t_b', fse3t_b(:,:,:) )
       ELSE
          neuler = 0
@@ -245,7 +247,12 @@
          hdivb(:,:,:)   = hdivn(:,:,:)
          sshb (:,:)     = sshn (:,:)
-      ENDIF
-      !
-      IF( lk_lim3 ) THEN 
+         IF( lk_lim3 ) THEN
+            DO jk = 1, jpk
+               fse3t_b(:,:,jk) = fse3t_n(:,:,jk)
+            END DO
+         ENDIF
+      ENDIF
+      !
+      IF( lk_lim3 ) THEN
          CALL iom_get( numror, jpdom_autoglo, 'iatte' , iatte ) ! clem modif
          CALL iom_get( numror, jpdom_autoglo, 'oatte' , oatte ) ! clem modif
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/LBC/lbcnfd.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/LBC/lbcnfd.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/LBC/lbcnfd.F90	(revision 4921)
@@ -33,5 +33,5 @@
 
    INTEGER, PUBLIC,  PARAMETER :: jpmaxngh = 3
-   INTEGER, PUBLIC                                  ::   nsndto
+   INTEGER, PUBLIC                                  ::   nsndto, nfsloop, nfeloop
    INTEGER, PUBLIC,  DIMENSION (jpmaxngh)           ::   isendto ! processes to which communicate
 
@@ -412,5 +412,5 @@
             SELECT CASE ( cd_type )
             CASE ( 'T' , 'W' )                         ! T-, W-point
-               IF (narea .ne. (jpnij - jpni + 1)) THEN
+               IF (nimpp .ne. 1) THEN
                  startloop = 1
                ELSE
@@ -420,7 +420,10 @@
                DO jk = 1, jpk
                   DO ji = startloop, nlci
-                     ijt = jpiglo - ji - nimpp - nimppt(isendto(1)) + 4
+                     ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
                      pt3dl(ji,ijpj,jk) = psgn * pt3dr(ijt,ijpj-2,jk)
                   END DO
+                  IF(nimpp .eq. 1) THEN
+                     pt3dl(1,ijpj,jk) = psgn * pt3dl(3,ijpj-2,jk)
+                  ENDIF
                END DO
 
@@ -435,5 +438,5 @@
                  DO jk = 1, jpk
                     DO ji = startloop, nlci
-                       ijt = jpiglo - ji - nimpp - nimppt(isendto(1)) + 4
+                       ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
                        jia = ji + nimpp - 1
                        ijta = jpiglo - jia + 2
@@ -448,7 +451,6 @@
 
 
-
             CASE ( 'U' )                               ! U-point
-               IF (narea .ne. (jpnij)) THEN
+               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                   endloop = nlci
                ELSE
@@ -457,10 +459,16 @@
                DO jk = 1, jpk
                   DO ji = 1, endloop
-                     iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 3
+                     iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
                      pt3dl(ji,ijpj,jk) = psgn * pt3dr(iju,ijpj-2,jk)
                   END DO
-               END DO
-
-               IF (narea .ne. (jpnij)) THEN
+                  IF(nimpp .eq. 1) THEN
+                     pt3dl(   1  ,ijpj,jk) = psgn * pt3dl(    2   ,ijpj-2,jk)
+                  ENDIF
+                  IF((nimpp + nlci - 1) .eq. jpiglo) THEN
+                     pt3dl(nlci,ijpj,jk) = psgn * pt3dl(nlci-1,ijpj-2,jk)
+                  ENDIF
+               END DO
+
+               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                   endloop = nlci
                ELSE
@@ -477,5 +485,5 @@
                  DO jk = 1, jpk
                     DO ji = startloop, endloop
-                      iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 3
+                      iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
                       jia = ji + nimpp - 1
                       ijua = jpiglo - jia + 1
@@ -490,5 +498,5 @@
 
             CASE ( 'V' )                               ! V-point
-               IF (narea .ne. (jpnij - jpni + 1)) THEN
+               IF (nimpp .ne. 1) THEN
                   startloop = 1
                ELSE
@@ -497,11 +505,14 @@
                DO jk = 1, jpk
                   DO ji = startloop, nlci
-                     ijt = jpiglo - ji - nimpp - nimppt(isendto(1)) + 4
+                     ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
                      pt3dl(ji,ijpj-1,jk) = psgn * pt3dr(ijt,ijpj-2,jk)
                      pt3dl(ji,ijpj  ,jk) = psgn * pt3dr(ijt,ijpj-3,jk)
                   END DO
+                  IF(nimpp .eq. 1) THEN
+                     pt3dl(1,ijpj,jk) = psgn * pt3dl(3,ijpj-3,jk)
+                  ENDIF
                END DO
             CASE ( 'F' )                               ! F-point
-               IF (narea .ne. (jpnij)) THEN
+               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                   endloop = nlci
                ELSE
@@ -510,8 +521,14 @@
                DO jk = 1, jpk
                   DO ji = 1, endloop
-                     iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 3
+                     iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
                      pt3dl(ji,ijpj-1,jk) = psgn * pt3dr(iju,ijpj-2,jk)
                      pt3dl(ji,ijpj  ,jk) = psgn * pt3dr(iju,ijpj-3,jk)
                   END DO
+                  IF(nimpp .eq. 1) THEN
+                     pt3dl(   1  ,ijpj,jk) = psgn * pt3dl(    2   ,ijpj-3,jk)
+                  ENDIF
+                  IF((nimpp + nlci - 1) .eq. jpiglo) THEN
+                     pt3dl(nlci,ijpj,jk) = psgn * pt3dl(nlci-1,ijpj-3,jk)
+                  ENDIF
                END DO
             END SELECT
@@ -524,5 +541,5 @@
                DO jk = 1, jpk
                   DO ji = 1, nlci
-                     ijt = jpiglo - ji - nimpp - nimppt(isendto(1)) + 3
+                     ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
                      pt3dl(ji,ijpj,jk) = psgn * pt3dr(ijt,ijpj-1,jk)
                   END DO
@@ -530,5 +547,5 @@
 
             CASE ( 'U' )                               ! U-point
-               IF (narea .ne. (jpnij)) THEN
+               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                   endloop = nlci
                ELSE
@@ -537,7 +554,10 @@
                DO jk = 1, jpk
                   DO ji = 1, endloop
-                     iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 2
+                     iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
                      pt3dl(ji,ijpj,jk) = psgn * pt3dr(iju,ijpj-1,jk)
                   END DO
+                  IF((nimpp + nlci - 1) .eq. jpiglo) THEN
+                     pt3dl(nlci,ijpj,jk) = psgn * pt3dr(1,ijpj-1,jk)
+                  ENDIF
                END DO
 
@@ -545,5 +565,5 @@
                DO jk = 1, jpk
                   DO ji = 1, nlci
-                     ijt = jpiglo - ji- nimpp - nimppt(isendto(1)) + 3
+                     ijt = jpiglo - ji- nimpp - nfiimpp(isendto(1),jpnj) + 3
                      pt3dl(ji,ijpj,jk) = psgn * pt3dr(ijt,ijpj-2,jk)
                   END DO
@@ -560,5 +580,5 @@
                  DO jk = 1, jpk
                     DO ji = startloop, nlci
-                       ijt = jpiglo - ji - nimpp - nimppt(isendto(1)) + 3
+                       ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
                        pt3dl(ji,ijpjm1,jk) = psgn * pt3dr(ijt,ijpjm1,jk)
                     END DO
@@ -567,5 +587,5 @@
 
             CASE ( 'F' )                               ! F-point
-               IF (narea .ne. (jpnij)) THEN
+               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                   endloop = nlci
                ELSE
@@ -574,10 +594,13 @@
                DO jk = 1, jpk
                   DO ji = 1, endloop
-                     iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 2
+                     iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
                      pt3dl(ji,ijpj ,jk) = psgn * pt3dr(iju,ijpj-2,jk)
                   END DO
-               END DO
-
-               IF (narea .ne. (jpnij)) THEN
+                  IF((nimpp + nlci - 1) .eq. jpiglo) THEN
+                     pt3dl(nlci,ijpj,jk) = psgn * pt3dr(1,ijpj-2,jk)
+                  ENDIF
+               END DO
+
+               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                   endloop = nlci
                ELSE
@@ -594,5 +617,5 @@
                   DO jk = 1, jpk
                      DO ji = startloop, endloop
-                        iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 2
+                        iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
                         pt3dl(ji,ijpjm1,jk) = psgn * pt3dr(iju,ijpjm1,jk)
                      END DO
@@ -656,5 +679,5 @@
          !
          CASE ( 'T' , 'W' )                               ! T- , W-points
-            IF (narea .ne. (jpnij - jpni + 1)) THEN
+            IF (nimpp .ne. 1) THEN
               startloop = 1
             ELSE
@@ -662,7 +685,10 @@
             ENDIF
             DO ji = startloop, nlci
-              ijt=jpiglo - ji - nimpp - nimppt(isendto(1)) + 4
+              ijt=jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
               pt2dl(ji,ijpj) = psgn * pt2dr(ijt,ijpjm1-1)
             END DO
+            IF (nimpp .eq. 1) THEN
+              pt2dl(1,ijpj)   = psgn * pt2dl(3,ijpj-2)
+            ENDIF
 
             IF(nimpp .ge. (jpiglo/2+1)) THEN
@@ -674,5 +700,5 @@
             ENDIF
             DO ji = startloop, nlci
-               ijt=jpiglo - ji - nimpp - nimppt(isendto(1)) + 4
+               ijt=jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
                jia = ji + nimpp - 1
                ijta = jpiglo - jia + 2
@@ -685,5 +711,5 @@
 
          CASE ( 'U' )                                     ! U-point
-            IF (narea .ne. (jpnij)) THEN
+            IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                endloop = nlci
             ELSE
@@ -691,9 +717,17 @@
             ENDIF
             DO ji = 1, endloop
-               iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 3
+               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
                pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1-1)
             END DO
 
-            IF (narea .ne. (jpnij)) THEN
+            IF (nimpp .eq. 1) THEN
+              pt2dl(   1  ,ijpj  ) = psgn * pt2dl(    2   ,ijpj-2)
+              pt2dl(1     ,ijpj-1) = psgn * pt2dr(jpiglo - nfiimpp(isendto(1), jpnj) + 1, ijpj-1)
+            ENDIF
+            IF((nimpp + nlci - 1) .eq. jpiglo) THEN
+              pt2dl(nlci,ijpj  ) = psgn * pt2dl(nlci-1,ijpj-2)
+            ENDIF
+
+            IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                endloop = nlci
             ELSE
@@ -708,5 +742,5 @@
             ENDIF
             DO ji = startloop, endloop
-               iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 3
+               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
                jia = ji + nimpp - 1
                ijua = jpiglo - jia + 1
@@ -719,5 +753,5 @@
 
          CASE ( 'V' )                                     ! V-point
-            IF (narea .ne. (jpnij - jpni + 1)) THEN
+            IF (nimpp .ne. 1) THEN
               startloop = 1
             ELSE
@@ -725,11 +759,14 @@
             ENDIF
             DO ji = startloop, nlci
-              ijt=jpiglo - ji - nimpp - nimppt(isendto(1)) + 4
+              ijt=jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
               pt2dl(ji,ijpjm1) = psgn * pt2dr(ijt,ijpjm1-1)
               pt2dl(ji,ijpj) = psgn * pt2dr(ijt,ijpjm1-2)
             END DO
+            IF (nimpp .eq. 1) THEN
+              pt2dl( 1 ,ijpj)   = psgn * pt2dl( 3 ,ijpj-3) 
+            ENDIF
 
          CASE ( 'F' )                                     ! F-point
-            IF (narea .ne. (jpnij)) THEN
+            IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                endloop = nlci
             ELSE
@@ -737,11 +774,19 @@
             ENDIF
             DO ji = 1, endloop
-               iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 3
+               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
                pt2dl(ji,ijpjm1) = psgn * pt2dr(iju,ijpjm1-1)
                pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1-2)
             END DO
+            IF (nimpp .eq. 1) THEN
+              pt2dl(   1  ,ijpj)   = psgn * pt2dl(    2   ,ijpj-3)
+              pt2dl(   1  ,ijpj-1) = psgn * pt2dl(    2   ,ijpj-2)
+            ENDIF
+            IF((nimpp + nlci - 1) .eq. jpiglo) THEN
+              pt2dl(nlci,ijpj)   = psgn * pt2dl(nlci-1,ijpj-3)
+              pt2dl(nlci,ijpj-1) = psgn * pt2dl(nlci-1,ijpj-2) 
+            ENDIF
 
          CASE ( 'I' )                                     ! ice U-V point (I-point)
-            IF (narea .ne. (jpnij - jpni + 1)) THEN
+            IF (nimpp .ne. 1) THEN
                startloop = 1
             ELSE
@@ -750,10 +795,10 @@
             ENDIF
             DO ji = startloop, nlci
-               iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 5
+               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 5
                pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1)
             END DO
 
          CASE ( 'J' )                                     ! first ice U-V point
-            IF (narea .ne. (jpnij - jpni + 1)) THEN
+            IF (nimpp .ne. 1) THEN
                startloop = 1
             ELSE
@@ -762,10 +807,10 @@
             ENDIF
             DO ji = startloop, nlci
-               iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 5
+               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 5
                pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1)
             END DO
 
          CASE ( 'K' )                                     ! second ice U-V point
-            IF (narea .ne. (jpnij - jpni + 1)) THEN
+            IF (nimpp .ne. 1) THEN
                startloop = 1
             ELSE
@@ -774,5 +819,5 @@
             ENDIF
             DO ji = startloop, nlci
-               iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 5
+               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 5
                pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1)
             END DO
@@ -785,10 +830,10 @@
          CASE ( 'T' , 'W' )                               ! T-, W-point
             DO ji = 1, nlci
-               ijt = jpiglo - ji - nimpp - nimppt(isendto(1)) + 3
+               ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
                pt2dl(ji,ijpj) = psgn * pt2dr(ijt,ijpjm1)
             END DO
 
          CASE ( 'U' )                                     ! U-point
-            IF (narea .ne. (jpnij)) THEN
+            IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                endloop = nlci
             ELSE
@@ -796,11 +841,14 @@
             ENDIF
             DO ji = 1, endloop
-               iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 2
+               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
                pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1)
             END DO
+            IF((nimpp + nlci - 1) .eq. jpiglo) THEN
+               pt2dl(nlci,ijpj) = psgn * pt2dr(1,ijpj-1)
+            ENDIF
 
          CASE ( 'V' )                                     ! V-point
             DO ji = 1, nlci
-               ijt = jpiglo - ji - nimpp - nimppt(isendto(1)) + 3
+               ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
                pt2dl(ji,ijpj) = psgn * pt2dr(ijt,ijpjm1-1)
             END DO
@@ -813,10 +861,10 @@
             ENDIF
             DO ji = startloop, nlci
-               ijt = jpiglo - ji - nimpp - nimppt(isendto(1)) + 3
+               ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
                pt2dl(ji,ijpjm1) = psgn * pt2dr(ijt,ijpjm1)
             END DO
 
          CASE ( 'F' )                               ! F-point
-            IF (narea .ne. (jpnij)) THEN
+            IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                endloop = nlci
             ELSE
@@ -824,9 +872,12 @@
             ENDIF
             DO ji = 1, endloop
-               iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 2
+               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
                pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1-1)
             END DO
-
-            IF (narea .ne. (jpnij)) THEN
+            IF((nimpp + nlci - 1) .eq. jpiglo) THEN
+                pt2dl(nlci,ijpj) = psgn * pt2dr(1,ijpj-2)
+            ENDIF
+
+            IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                endloop = nlci
             ELSE
@@ -842,15 +893,15 @@
 
             DO ji = startloop, endloop
-               iju = jpiglo - ji - nimpp - nimppt(isendto(1)) + 2
+               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
                pt2dl(ji,ijpjm1) = psgn * pt2dr(iju,ijpjm1)
             END DO
 
          CASE ( 'I' )                                  ! ice U-V point (I-point)
-               IF (narea .ne. (jpnij - jpni + 1)) THEN
+               IF (nimpp .ne. 1) THEN
                   startloop = 1
                ELSE
                   startloop = 2
                ENDIF
-               IF (narea .ne. jpnij) THEN
+               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                   endloop = nlci
                ELSE
@@ -858,15 +909,15 @@
                ENDIF
                DO ji = startloop , endloop
-                  ijt = jpiglo - ji - nimpp - nimppt(isendto(1)) + 4
+                  ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
                   pt2dl(ji,ijpj)= 0.5 * (pt2dr(ji,ijpjm1) + psgn * pt2dr(ijt,ijpjm1))
                END DO
 
          CASE ( 'J' )                                  ! first ice U-V point
-               IF (narea .ne. (jpnij - jpni + 1)) THEN
+               IF (nimpp .ne. 1) THEN
                   startloop = 1
                ELSE
                   startloop = 2
                ENDIF
-               IF (narea .ne. jpnij) THEN
+               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                   endloop = nlci
                ELSE
@@ -874,15 +925,15 @@
                ENDIF
                DO ji = startloop , endloop
-                  ijt = jpiglo - ji - nimpp - nimppt(isendto(1)) + 4
+                  ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
                   pt2dl(ji,ijpj) = pt2dr(ji,ijpjm1)
                END DO
 
          CASE ( 'K' )                                  ! second ice U-V point
-               IF (narea .ne. (jpnij - jpni + 1)) THEN
+               IF (nimpp .ne. 1) THEN
                   startloop = 1
                ELSE
                   startloop = 2
                ENDIF
-               IF (narea .ne. jpnij) THEN
+               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
                   endloop = nlci
                ELSE
@@ -890,5 +941,5 @@
                ENDIF
                DO ji = startloop, endloop
-                  ijt = jpiglo - ji - nimpp - nimppt(isendto(1)) + 4
+                  ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
                   pt2dl(ji,ijpj) = pt2dr(ijt,ijpjm1)
                END DO
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 4921)
@@ -2026,4 +2026,5 @@
       ijpjm1 = 3
       !
+      znorthloc(:,:,:) = 0
       DO jk = 1, jpk
          DO jj = nlcj - ijpj +1, nlcj          ! put in xnorthloc the last 4 jlines of pt3d
@@ -2036,12 +2037,13 @@
       itaille = jpi * jpk * ijpj
 
-
       IF ( l_north_nogather ) THEN
          !
         ztabr(:,:,:) = 0
+        ztabl(:,:,:) = 0
+
         DO jk = 1, jpk
            DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
               ij = jj - nlcj + ijpj
-              DO ji = 1, nlci
+              DO ji = nfsloop, nfeloop
                  ztabl(ji,ij,jk) = pt3d(ji,jj,jk)
               END DO
@@ -2050,24 +2052,28 @@
 
          DO jr = 1,nsndto
-            IF (isendto(jr) .ne. narea) CALL mppsend( 5, znorthloc, itaille, isendto(jr)-1, ml_req_nf(jr) )
+            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+              CALL mppsend( 5, znorthloc, itaille, nfipproc(isendto(jr),jpnj), ml_req_nf(jr) )
+            ENDIF
          END DO
          DO jr = 1,nsndto
-            iproc = isendto(jr)
-            ildi = nldit (iproc)
-            ilei = nleit (iproc)
-            iilb = nimppt(isendto(jr)) - nimppt(isendto(1))
-            IF(isendto(jr) .ne. narea) THEN
-              CALL mpprecv(5, zfoldwk, itaille, isendto(jr)-1)
+            iproc = nfipproc(isendto(jr),jpnj)
+            IF(iproc .ne. -1) THEN
+               ilei = nleit (iproc+1)
+               ildi = nldit (iproc+1)
+               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
+            ENDIF
+            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
+              CALL mpprecv(5, zfoldwk, itaille, iproc)
               DO jk = 1, jpk
                  DO jj = 1, ijpj
-                    DO ji = 1, ilei
+                    DO ji = ildi, ilei
                        ztabr(iilb+ji,jj,jk) = zfoldwk(ji,jj,jk)
                     END DO
                  END DO
               END DO
-           ELSE
+           ELSE IF (iproc .eq. (narea-1)) THEN
               DO jk = 1, jpk
                  DO jj = 1, ijpj
-                    DO ji = 1, ilei
+                    DO ji = ildi, ilei
                        ztabr(iilb+ji,jj,jk) = pt3d(ji,nlcj-ijpj+jj,jk)
                     END DO
@@ -2078,9 +2084,10 @@
          IF (l_isend) THEN
             DO jr = 1,nsndto
-               IF (isendto(jr) .ne. narea) CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
+               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
+               ENDIF    
             END DO
          ENDIF
          CALL mpp_lbc_nfd( ztabl, ztabr, cd_type, psgn )   ! North fold boundary condition
-         !
          DO jk = 1, jpk
             DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt3d
@@ -2190,7 +2197,9 @@
          !
          ztabr(:,:) = 0
+         ztabl(:,:) = 0
+
          DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
             ij = jj - nlcj + ijpj
-            DO ji = 1, nlci
+              DO ji = nfsloop, nfeloop
                ztabl(ji,ij) = pt2d(ji,jj)
             END DO
@@ -2198,21 +2207,25 @@
 
          DO jr = 1,nsndto
-            IF (isendto(jr) .ne. narea) CALL mppsend(5, znorthloc, itaille, isendto(jr)-1, ml_req_nf(jr))
+            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+               CALL mppsend(5, znorthloc, itaille, nfipproc(isendto(jr),jpnj), ml_req_nf(jr))
+            ENDIF
          END DO
          DO jr = 1,nsndto
-            iproc = isendto(jr)
-            ildi = nldit (iproc)
-            ilei = nleit (iproc)
-            iilb = nimppt(isendto(jr)) - nimppt(isendto(1))
-            IF(isendto(jr) .ne. narea) THEN
-              CALL mpprecv(5, zfoldwk, itaille, isendto(jr)-1)
+            iproc = nfipproc(isendto(jr),jpnj)
+            IF(iproc .ne. -1) THEN
+               ilei = nleit (iproc+1)
+               ildi = nldit (iproc+1)
+               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
+            ENDIF
+            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
+              CALL mpprecv(5, zfoldwk, itaille, iproc)
               DO jj = 1, ijpj
-                 DO ji = 1, ilei
+                 DO ji = ildi, ilei
                     ztabr(iilb+ji,jj) = zfoldwk(ji,jj)
                  END DO
               END DO
-            ELSE
+            ELSE IF (iproc .eq. (narea-1)) THEN
               DO jj = 1, ijpj
-                 DO ji = 1, ilei
+                 DO ji = ildi, ilei
                     ztabr(iilb+ji,jj) = pt2d(ji,nlcj-ijpj+jj)
                  END DO
@@ -2222,5 +2235,7 @@
          IF (l_isend) THEN
             DO jr = 1,nsndto
-               IF (isendto(jr) .ne. narea) CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
+               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
+               ENDIF
             END DO
          ENDIF
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90	(revision 4921)
@@ -177,4 +177,5 @@
       
 #endif
+      nfilcit(:,:) = ilcit(:,:)
       IF( irestj == 0 )   irestj = jpnj
 
@@ -255,4 +256,5 @@
          END DO
       ENDIF
+      nfiimpp(:,:)=iimppt(:,:)
 
       IF( jpnj > 1 ) THEN
@@ -270,4 +272,5 @@
          ii = 1 + MOD( jn-1, jpni )
          ij = 1 + (jn-1) / jpni
+         nfipproc(ii,ij) = jn - 1
          nimppt(jn) = iimppt(ii,ij)
          njmppt(jn) = ijmppt(ii,ij)
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/LBC/mppini_2.h90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/LBC/mppini_2.h90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/LBC/mppini_2.h90	(revision 4921)
@@ -144,4 +144,6 @@
 #endif
 
+      nfilcit(:,:) = ilci(:,:)
+
       IF(lwp) WRITE(numout,*)
       IF(lwp) WRITE(numout,*) ' mpp_init2: defines mpp subdomains'
@@ -175,4 +177,5 @@
          END DO
       ENDIF
+      nfiimpp(:,:) = iimppt(:,:)
 
       IF( jpnj > 1 )THEN
@@ -195,10 +198,8 @@
          ili = ilci(ii,ij)
          ilj = ilcj(ii,ij)
-
          ibondj(ii,ij) = -1
          IF( jarea >  jpni          )   ibondj(ii,ij) = 0
          IF( jarea >  (jpnj-1)*jpni )   ibondj(ii,ij) = 1
          IF( jpnj  == 1             )   ibondj(ii,ij) = 2
-
          ibondi(ii,ij) = 0
          IF( MOD(jarea,jpni) == 1 )   ibondi(ii,ij) = -1
@@ -308,4 +309,7 @@
       END DO
 
+      nfipproc(:,:) = ipproc(:,:)
+
+
       ! Control
       IF(icont+1 /= jpnij) THEN
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 4921)
@@ -208,6 +208,29 @@
       !-----------------------------------------------------------------------
 
+      !Initalise all values in namelist arrays
+      enactfiles(:) = ''
+      coriofiles(:) = ''
+      profbfiles(:) = ''
+      slafilesact(:) = ''
+      slafilespas(:) = ''
+      slafbfiles(:) = ''
+      sstfiles(:)   = ''
+      sstfbfiles(:) = ''
+      seaicefiles(:) = ''
       velcurfiles(:) = ''
       veladcpfiles(:) = ''
+      velavcurfiles(:) = ''
+      velhrcurfiles(:) = ''
+      velavadcpfiles(:) = ''
+      velhradcpfiles(:) = ''
+      velfbfiles(:) = ''
+      velcurfiles(:) = ''
+      veladcpfiles(:) = ''
+      endailyavtypes(:) = -1
+      endailyavtypes(1) = 820
+      ln_profb_ena(:) = .FALSE.
+      ln_profb_enatim(:) = .TRUE.
+      ln_velfb_av(:) = .FALSE.
+      ln_ignmis = .FALSE.
       CALL ini_date( dobsini )
       CALL fin_date( dobsend )
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90	(revision 4921)
@@ -286,5 +286,4 @@
          IF ( llaction ) THEN
             
-            kinfo = OASIS_Rcv
             pdata(nldi:nlei, nldj:nlej,jc) = exfld(:,:)
             
@@ -304,4 +303,9 @@
                WRITE(numout,*) '****************'
             ENDIF
+
+            ! Ideally we would not reuse kinfo, but define a separate variable
+            ! for use as the return code from this routine to avoid confusion
+            ! with the return code previously obtained from the coupler.
+            kinfo = OASIS_Rcv
             
          ELSE
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 4921)
@@ -40,5 +40,5 @@
       LOGICAL              ::   ln_clim     ! climatology or not (T/F)
       CHARACTER(len = 8)   ::   cltype      ! type of data file 'daily', 'monthly' or yearly'
-      CHARACTER(len = 34)  ::   wname       ! generic name of a NetCDF weights file to be used, blank if not
+      CHARACTER(len = 256) ::   wname       ! generic name of a NetCDF weights file to be used, blank if not
       CHARACTER(len = 34)  ::   vcomp       ! symbolic component name if a vector that needs rotation
       !                                     ! a string starting with "U" or "V" for each component   
@@ -473,9 +473,12 @@
             !       forcing record :    1 
             !                            
-            ztmp = REAL( nday, wp ) / REAL( nyear_len(1), wp ) + 0.5 + REAL( it_offset, wp )
+            ztmp = REAL( nsec_year, wp ) / ( REAL( nyear_len(1), wp ) * rday ) + 0.5 &
+           &       + REAL( it_offset, wp ) / ( REAL( nyear_len(1), wp ) * rday )
             sdjf%nrec_a(1) = 1 + INT( ztmp ) - COUNT((/llbefore/))
             ! swap at the middle of the year
-            IF( llbefore ) THEN   ;   sdjf%nrec_a(2) = nsec1jan000 - NINT(0.5 * rday) * nyear_len(0)
-            ELSE                  ;   sdjf%nrec_a(2) = nsec1jan000 + NINT(0.5 * rday) * nyear_len(1)   
+            IF( llbefore ) THEN   ;   sdjf%nrec_a(2) = nsec1jan000 - (1 - INT(ztmp)) * NINT(0.5 * rday) * nyear_len(0) + &
+                                    & INT(ztmp) * NINT( 0.5 * rday) * nyear_len(1) 
+            ELSE                  ;   sdjf%nrec_a(2) = nsec1jan000 + (1 - INT(ztmp)) * NINT(0.5 * rday) * nyear_len(1) + &
+                                    & INT(ztmp) * INT(rday) * nyear_len(1) + INT(ztmp) * NINT( 0.5 * rday) * nyear_len(2) 
             ENDIF
          ELSE                                    ! no time interpolation
@@ -501,5 +504,6 @@
             !       forcing record :  nmonth 
             !                            
-            ztmp = REAL( nday, wp ) / REAL( nmonth_len(nmonth), wp ) + 0.5 + REAL( it_offset, wp )
+            ztmp = REAL( nsec_month, wp ) / ( REAL( nmonth_len(nmonth), wp ) * rday ) + 0.5 &
+           &       + REAL( it_offset, wp ) / ( REAL( nmonth_len(nmonth), wp ) * rday )
             imth = nmonth + INT( ztmp ) - COUNT((/llbefore/))
             IF( sdjf%cltype == 'monthly' ) THEN   ;   sdjf%nrec_a(1) = 1 + INT( ztmp ) - COUNT((/llbefore/))
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 4921)
@@ -563,4 +563,6 @@
       zcoef_dqsb   = rhoa * cpa * Cice
       zcoef_frca   = 1.0  - 0.3
+      ! MV 2014 the proper cloud fraction (mean summer months from the CLIO climato, NH+SH) is 0.19
+      zcoef_frca   = 1.0  - 0.19
 
 !!gm brutal....
@@ -648,10 +650,5 @@
                p_qsr(ji,jj,jl) = zztmp * ( 1. - palb(ji,jj,jl) ) * qsr(ji,jj)
                ! Long  Wave (lw)
-               ! iovino
-               IF( ff(ji,jj) .GT. 0._wp ) THEN
-                  z_qlw(ji,jj,jl) = ( 0.95 * sf(jp_qlw)%fnow(ji,jj,1) - Stef * pst(ji,jj,jl) * zst3 ) * tmask(ji,jj,1)
-               ELSE
-                  z_qlw(ji,jj,jl) = 0.95 * ( sf(jp_qlw)%fnow(ji,jj,1) - Stef * pst(ji,jj,jl) * zst3 ) * tmask(ji,jj,1)
-               ENDIF
+               z_qlw(ji,jj,jl) = 0.95 * ( sf(jp_qlw)%fnow(ji,jj,1) - Stef * pst(ji,jj,jl) * zst3 ) * tmask(ji,jj,1)
                ! lw sensitivity
                z_dqlw(ji,jj,jl) = zcoef_dqlw * zst3                                               
@@ -668,5 +665,11 @@
                   &                         * (  11637800. * EXP( -5897.8 / pst(ji,jj,jl) ) / rhoa - sf(jp_humi)%fnow(ji,jj,1)  ) )
                ! Latent heat sensitivity for ice (Dqla/Dt)
-               p_dqla(ji,jj,jl) = rn_efac * zcoef_dqla * z_wnds_t(ji,jj) / ( zst2 ) * EXP( -5897.8 / pst(ji,jj,jl) )
+               ! MV we also have to cap the sensitivity if the flux is zero
+               IF ( p_qla(ji,jj,jl) .GT. 0.0 ) THEN
+                  p_dqla(ji,jj,jl) = rn_efac * zcoef_dqla * z_wnds_t(ji,jj) / ( zst2 ) * EXP( -5897.8 / pst(ji,jj,jl) )
+               ELSE
+                  p_dqla(ji,jj,jl) = 0.0
+               ENDIF
+                             
                ! Sensible heat sensitivity (Dqsb_ice/Dtn_ice)
                z_dqsb(ji,jj,jl) = zcoef_dqsb * z_wnds_t(ji,jj)
@@ -820,6 +823,9 @@
            sqrt_Cd=kappa/((kappa/sqrt_Cd_n10) - zpsi_m) ; Cd=sqrt_Cd*sqrt_Cd;
          ELSE
-           !! Shifting the wind speed to 10m and neutral stability :
-           U_n10 = dU10*1./(1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m)) !  L & Y eq. (9a)
+           !! Shifting the wind speed to 10m and neutral stability :  L & Y eq. (9a)
+           !   In very rare low-wind conditions, the old way of estimating the
+           !   neutral wind speed at 10m leads to a negative value that causes the code
+           !   to crash. To prevent this a threshold of 0.25m/s is now imposed.
+           U_n10 = MAX( 0.25 , dU10/(1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m)) )
 
            !! Updating the neutral 10m transfer coefficients :
@@ -956,7 +962,9 @@
          zpsi_m  = psi_m(zeta_u)
          !!
-         !! Shifting the wind speed to 10m and neutral stability : (L & Y eq.(9a))
-!        U_n10 = dU10/(1. + sqrt_Cd_n10/kappa*(log(zu/10.) - psi_m(zeta_u)))
-         U_n10 = dU10/(1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m))
+         !! Shifting the wind speed to 10m and neutral stability : L & Y eq.(9a)
+         !   In very rare low-wind conditions, the old way of estimating the
+         !   neutral wind speed at 10m leads to a negative value that causes the code
+         !   to crash. To prevent this a threshold of 0.25m/s is now imposed.
+         U_n10 = MAX( 0.25 , dU10/(1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m)) )
          !!
          !! Shifting temperature and humidity at zu :          (L & Y eq. (9b-9c))
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 4921)
@@ -1374,5 +1374,5 @@
             END SELECT
          CASE( 'mixed oce-ice'        )   
-            ztmp1(:,:) = ( tsn(:,:,1,1) + rt0 ) * zfr_l(:,:) 
+            ztmp1(:,:) = ( tsn(:,:,1,jp_tem) + rt0 ) * zfr_l(:,:) 
             DO jl=1,jpl
                ztmp1(:,:) = ztmp1(:,:) + tn_ice(:,:,jl) * a_i(:,:,jl)
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90	(revision 4921)
@@ -57,4 +57,6 @@
       !!                =1 global mean of emp set to zero at each nn_fsbc time step
       !!                =2 annual global mean corrected from previous year
+      !!                =3 global mean of emp set to zero at each nn_fsbc time step
+      !!                   & spread out over erp area depending its sign
       !! Note: if sea ice is embedded it is taken into account when computing the budget 
       !!----------------------------------------------------------------------
@@ -81,5 +83,8 @@
             IF( kn_fwb == 1 )   WRITE(numout,*) '          instantaneously set to zero'
             IF( kn_fwb == 2 )   WRITE(numout,*) '          adjusted from previous year budget'
-         ENDIF
+            IF( kn_fwb == 3 )   WRITE(numout,*) '          fwf set to zero and spread out over erp area'
+         ENDIF
+         !
+         IF( kn_fwb == 3 .AND. nn_sssr /= 2 )   CALL ctl_stop( 'sbc_fwb: nn_fwb = 3 requires nn_sssr = 2, we stop ' )
          !
          area = glob_sum( e1e2t(:,:) )           ! interior global domain surface
@@ -142,6 +147,58 @@
          ENDIF
          !
+      CASE ( 3 )                             !==  global fwf set to zero and spread out over erp area  ==!
+         !
+         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN
+            ztmsk_pos(:,:) = tmask_i(:,:)                      ! Select <0 and >0 area of erp
+            WHERE( erp < 0._wp )   ztmsk_pos = 0._wp
+            ztmsk_neg(:,:) = tmask_i(:,:) - ztmsk_pos(:,:)
+            !
+            zsurf_neg = glob_sum( e1e2t(:,:)*ztmsk_neg(:,:) )  ! Area filled by <0 and >0 erp 
+            zsurf_pos = glob_sum( e1e2t(:,:)*ztmsk_pos(:,:) )
+            !                                                  ! fwf global mean (excluding ocean to ice/snow exchanges) 
+            z_fwf     = glob_sum( e1e2t(:,:) * ( emp(:,:) - rnf(:,:) - snwice_fmass(:,:) ) ) / area
+            !            
+            IF( z_fwf < 0._wp ) THEN         ! spread out over >0 erp area to increase evaporation
+                zsurf_tospread      = zsurf_pos
+                ztmsk_tospread(:,:) = ztmsk_pos(:,:)
+            ELSE                             ! spread out over <0 erp area to increase precipitation
+                zsurf_tospread      = zsurf_neg
+                ztmsk_tospread(:,:) = ztmsk_neg(:,:)
+            ENDIF
+            !
+            zsum_fwf   = glob_sum( e1e2t(:,:) * z_fwf )         ! fwf global mean over <0 or >0 erp area
+!!gm :  zsum_fwf   = z_fwf * area   ???  it is right?  I think so....
+            z_fwf_nsrf =  zsum_fwf / ( zsurf_tospread + rsmall )
+            !                                                  ! weight to respect erp field 2D structure 
+            zsum_erp   = glob_sum( ztmsk_tospread(:,:) * erp(:,:) * e1e2t(:,:) )
+            z_wgt(:,:) = ztmsk_tospread(:,:) * erp(:,:) / ( zsum_erp + rsmall )
+            !                                                  ! final correction term to apply
+            zerp_cor(:,:) = -1. * z_fwf_nsrf * zsurf_tospread * z_wgt(:,:)
+            !
+!!gm   ===>>>>  lbc_lnk should be useless as all the computation is done over the whole domain !
+            CALL lbc_lnk( zerp_cor, 'T', 1. )
+            !
+            emp(:,:) = emp(:,:) + zerp_cor(:,:)
+            qns(:,:) = qns(:,:) - zerp_cor(:,:) * rcp * sst_m(:,:)  ! account for change to the heat budget due to fw correction
+            erp(:,:) = erp(:,:) + zerp_cor(:,:)
+            !
+            IF( nprint == 1 .AND. lwp ) THEN                   ! control print
+               IF( z_fwf < 0._wp ) THEN
+                  WRITE(numout,*)'   z_fwf < 0'
+                  WRITE(numout,*)'   SUM(erp+)     = ', SUM( ztmsk_tospread(:,:)*erp(:,:)*e1e2t(:,:) )*1.e-9,' Sv'
+               ELSE
+                  WRITE(numout,*)'   z_fwf >= 0'
+                  WRITE(numout,*)'   SUM(erp-)     = ', SUM( ztmsk_tospread(:,:)*erp(:,:)*e1e2t(:,:) )*1.e-9,' Sv'
+               ENDIF
+               WRITE(numout,*)'   SUM(empG)     = ', SUM( z_fwf*e1e2t(:,:) )*1.e-9,' Sv'
+               WRITE(numout,*)'   z_fwf         = ', z_fwf      ,' Kg/m2/s'
+               WRITE(numout,*)'   z_fwf_nsrf    = ', z_fwf_nsrf ,' Kg/m2/s'
+               WRITE(numout,*)'   MIN(zerp_cor) = ', MINVAL(zerp_cor) 
+               WRITE(numout,*)'   MAX(zerp_cor) = ', MAXVAL(zerp_cor) 
+            ENDIF
+         ENDIF
+         !
       CASE DEFAULT                           !==  you should never be there  ==!
-         CALL ctl_stop( 'sbc_fwb : wrong nn_fwb value for the FreshWater Budget correction, choose either 1 or 2' )
+         CALL ctl_stop( 'sbc_fwb : wrong nn_fwb value for the FreshWater Budget correction, choose either 1, 2 or 3' )
          !
       END SELECT
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 4921)
@@ -59,4 +59,5 @@
    USE prtctl          ! Print control
    USE lib_fortran     ! 
+   USE cpl_oasis3, ONLY : lk_cpl
 
 #if defined key_bdy 
@@ -68,4 +69,5 @@
 
    PUBLIC sbc_ice_lim  ! routine called by sbcmod.F90
+   PUBLIC lim_prt_state
    
    !! * Substitutions
@@ -133,5 +135,5 @@
       INTEGER, INTENT(in) ::   kblk    ! type of bulk (=3 CLIO, =4 CORE)
       !!
-      INTEGER  ::   jl      ! dummy loop index
+      INTEGER  ::   ji, jj, jl, jk      ! dummy loop index
       REAL(wp) ::   zcoef   ! local scalar
       REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalb_ice_os, zalb_ice_cs  ! albedo of the ice under overcast/clear sky
@@ -146,4 +148,6 @@
       REAL(wp), POINTER, DIMENSION(:,:) :: z_dqns_ice_all  ! Mean d(qns)/dT over all categories
       REAL(wp), POINTER, DIMENSION(:,:) :: z_dqla_ice_all  ! Mean d(qla)/dT over all categories
+      REAL(wp) ::   ztmelts           ! clem 2014: for HC diags
+      REAL(wp) ::   epsi20 = 1.e-20   !
       !!----------------------------------------------------------------------
 
@@ -152,11 +156,11 @@
       IF( nn_timing == 1 )  CALL timing_start('sbc_ice_lim')
 
-      CALL wrk_alloc( jpi,jpj,jpl, zalb_ice_os, zalb_ice_cs )
-
-#if defined key_coupled
-      IF ( ln_cpl .OR. ln_iceflx_ave .OR. ln_iceflx_linear ) CALL wrk_alloc( jpi,jpj,jpl, zalb_ice)
-      IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) &
-         &   CALL wrk_alloc( jpi,jpj, ztem_ice_all, zalb_ice_all, z_qsr_ice_all, z_qns_ice_all, z_qla_ice_all, z_dqns_ice_all, z_dqla_ice_all)
-#endif
+      CALL wrk_alloc( jpi,jpj,jpl, zalb_ice_os, zalb_ice_cs, zalb_ice )
+
+      IF( lk_cpl ) THEN
+         IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) &
+            &   CALL wrk_alloc( jpi, jpj, ztem_ice_all , zalb_ice_all  , z_qsr_ice_all, z_qns_ice_all,   &
+            &                             z_qla_ice_all, z_dqns_ice_all, z_dqla_ice_all)
+      ENDIF
 
       IF( kt == nit000 ) THEN
@@ -168,5 +172,5 @@
          !
          IF( ln_nicep ) THEN      ! control print at a given point
-            jiindx = 177   ;   jjindx = 112
+            jiindx = 15    ;   jjindx =  44
             IF(lwp) WRITE(numout,*) ' The debugging point is : jiindx : ',jiindx, ' jjindx : ',jjindx
          ENDIF
@@ -176,12 +180,13 @@
       IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN     !  Ice time-step only  !
          !                                     !----------------------!
-         !                                           !  Bulk Formulea !
+         !                                           !  Bulk Formulae !
          !                                           !----------------!
          !
          u_oce(:,:) = ssu_m(:,:)                     ! mean surface ocean current at ice velocity point
          v_oce(:,:) = ssv_m(:,:)                     ! (C-grid dynamics :  U- & V-points as the ocean)
-         !
-         t_bo(:,:) = tfreez( sss_m ) +  rt0          ! masked sea surface freezing temperature [Kelvin]
-         !                                           ! (set to rt0 over land)
+
+         ! masked sea surface freezing temperature [Kelvin]
+         t_bo(:,:) = ( tfreez( sss_m ) +  rt0 ) * tmask(:,:,1) + rt0 * ( 1. - tmask(:,:,1) )
+
          CALL albedo_ice( t_su, ht_i, ht_s, zalb_ice_cs, zalb_ice_os )  ! ... ice albedo
 
@@ -192,13 +197,13 @@
          IF ( ln_cpl ) zalb_ice (:,:,:) = 0.5 * ( zalb_ice_cs (:,:,:) +  zalb_ice_os (:,:,:) )
          
-#if defined key_coupled
-         IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) THEN
-            !
-            ! Compute mean albedo and temperature
-            zalb_ice_all (:,:) = fice_ice_ave ( zalb_ice (:,:,:) ) 
-            ztem_ice_all (:,:) = fice_ice_ave ( tn_ice   (:,:,:) ) 
-            !
+         IF( lk_cpl ) THEN
+            IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) THEN
+               !
+               ! Compute mean albedo and temperature
+               zalb_ice_all (:,:) = fice_ice_ave ( zalb_ice (:,:,:) ) 
+               ztem_ice_all (:,:) = fice_ice_ave ( tn_ice   (:,:,:) ) 
+               !
+            ENDIF
          ENDIF
-#endif
                                                ! Bulk formulea - provides the following fields:
          ! utau_ice, vtau_ice : surface ice stress                     (U- & V-points)   [N/m2]
@@ -218,5 +223,13 @@
             !         
          CASE( 4 )                                       ! CORE bulk formulation
-            CALL blk_ice_core( t_su , u_ice     , v_ice     , zalb_ice_cs,               &
+            ! MV 2014
+            ! We must account for cloud fraction in the computation of the albedo
+            ! The present ref just uses the clear sky value
+            ! The overcast sky value is 0.06 higher, and polar skies are mostly overcast
+            ! CORE has no cloud fraction, hence we must prescribe it
+            ! Mean summer cloud fraction computed from CLIO = 0.81
+            zalb_ice(:,:,:) = 0.19 * zalb_ice_cs(:,:,:) + 0.81 * zalb_ice_os(:,:,:)
+            ! Following line, we replace zalb_ice_cs by simply zalb_ice
+            CALL blk_ice_core( t_su , u_ice     , v_ice     , zalb_ice   ,               &
                &                      utau_ice  , vtau_ice  , qns_ice    , qsr_ice   ,   &
                &                      qla_ice   , dqns_ice  , dqla_ice   ,               &
@@ -239,5 +252,5 @@
 
          ! Average over all categories
-#if defined key_coupled
+         IF( lk_cpl ) THEN
          IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) THEN
 
@@ -269,5 +282,5 @@
             END IF
          END IF
-#endif
+         ENDIF
          !                                           !----------------------!
          !                                           ! LIM-3  time-stepping !
@@ -277,16 +290,15 @@
          !
          !                                           ! Store previous ice values
-!!gm : remark   old_...   should becomes ...b  as tn versus tb  
-         old_a_i  (:,:,:)   = a_i  (:,:,:)     ! ice area
-         old_e_i  (:,:,:,:) = e_i  (:,:,:,:)   ! ice thermal energy
-         old_v_i  (:,:,:)   = v_i  (:,:,:)     ! ice volume
-         old_v_s  (:,:,:)   = v_s  (:,:,:)     ! snow volume 
-         old_e_s  (:,:,:,:) = e_s  (:,:,:,:)   ! snow thermal energy
-         old_smv_i(:,:,:)   = smv_i(:,:,:)     ! salt content
-         old_oa_i (:,:,:)   = oa_i (:,:,:)     ! areal age content
-         !
-         old_u_ice(:,:) = u_ice(:,:)
-         old_v_ice(:,:) = v_ice(:,:)
-         !                                           ! intialisation to zero    !!gm is it truly necessary ???
+         a_i_b  (:,:,:)   = a_i  (:,:,:)     ! ice area
+         e_i_b  (:,:,:,:) = e_i  (:,:,:,:)   ! ice thermal energy
+         v_i_b  (:,:,:)   = v_i  (:,:,:)     ! ice volume
+         v_s_b  (:,:,:)   = v_s  (:,:,:)     ! snow volume 
+         e_s_b  (:,:,:,:) = e_s  (:,:,:,:)   ! snow thermal energy
+         smv_i_b(:,:,:)   = smv_i(:,:,:)     ! salt content
+         oa_i_b (:,:,:)   = oa_i (:,:,:)     ! areal age content
+         u_ice_b(:,:)     = u_ice(:,:)
+         v_ice_b(:,:)     = v_ice(:,:)
+
+         ! trends    !!gm is it truly necessary ???
          d_a_i_thd  (:,:,:)   = 0._wp   ;   d_a_i_trp  (:,:,:)   = 0._wp
          d_v_i_thd  (:,:,:)   = 0._wp   ;   d_v_i_trp  (:,:,:)   = 0._wp
@@ -296,33 +308,40 @@
          d_smv_i_thd(:,:,:)   = 0._wp   ;   d_smv_i_trp(:,:,:)   = 0._wp
          d_oa_i_thd (:,:,:)   = 0._wp   ;   d_oa_i_trp (:,:,:)   = 0._wp
-         !
-         d_u_ice_dyn(:,:) = 0._wp
-         d_v_ice_dyn(:,:) = 0._wp
-         !
-         sfx    (:,:) = 0._wp   ;   sfx_thd  (:,:) = 0._wp
-         sfx_bri(:,:) = 0._wp   ;   sfx_mec  (:,:) = 0._wp   ;   sfx_res  (:,:) = 0._wp
-         fhbri  (:,:) = 0._wp   ;   fheat_mec(:,:) = 0._wp   ;   fheat_res(:,:) = 0._wp
-         fhmec  (:,:) = 0._wp   ;   
-         fmmec  (:,:) = 0._wp
-         fmmflx (:,:) = 0._wp     
-         focea2D(:,:) = 0._wp
-         fsup2D (:,:) = 0._wp
-
-         ! used in limthd.F90
-         rdvosif(:,:) = 0._wp   ! variation of ice volume at surface
-         rdvobif(:,:) = 0._wp   ! variation of ice volume at bottom
-         fdvolif(:,:) = 0._wp   ! total variation of ice volume
-         rdvonif(:,:) = 0._wp   ! lateral variation of ice volume
-         fstric (:,:) = 0._wp   ! part of solar radiation transmitted through the ice
-         ffltbif(:,:) = 0._wp   ! linked with fstric
-         qfvbq  (:,:) = 0._wp   ! linked with fstric
-         rdm_snw(:,:) = 0._wp   ! variation of snow mass per unit area
-         rdm_ice(:,:) = 0._wp   ! variation of ice mass per unit area
-         hicifp (:,:) = 0._wp   ! daily thermodynamic ice production. 
-         !
-         diag_sni_gr(:,:) = 0._wp   ;   diag_lat_gr(:,:) = 0._wp
-         diag_bot_gr(:,:) = 0._wp   ;   diag_dyn_gr(:,:) = 0._wp
-         diag_bot_me(:,:) = 0._wp   ;   diag_sur_me(:,:) = 0._wp
-         diag_res_pr(:,:) = 0._wp   ;   diag_trp_vi(:,:) = 0._wp
+         d_u_ice_dyn(:,:)     = 0._wp   ;   d_v_ice_dyn(:,:)     = 0._wp
+
+         ! salt, heat and mass fluxes
+         sfx    (:,:) = 0._wp   ;
+         sfx_bri(:,:) = 0._wp   ; 
+         sfx_sni(:,:) = 0._wp   ;   sfx_opw(:,:) = 0._wp
+         sfx_bog(:,:) = 0._wp   ;   sfx_dyn(:,:) = 0._wp
+         sfx_bom(:,:) = 0._wp   ;   sfx_sum(:,:) = 0._wp
+         sfx_res(:,:) = 0._wp
+
+         wfx_snw(:,:) = 0._wp   ;   wfx_ice(:,:) = 0._wp
+         wfx_sni(:,:) = 0._wp   ;   wfx_opw(:,:) = 0._wp
+         wfx_bog(:,:) = 0._wp   ;   wfx_dyn(:,:) = 0._wp
+         wfx_bom(:,:) = 0._wp   ;   wfx_sum(:,:) = 0._wp
+         wfx_res(:,:) = 0._wp   ;   wfx_sub(:,:) = 0._wp
+         wfx_spr(:,:) = 0._wp   ;   
+
+         hfx_in (:,:) = 0._wp   ;   hfx_out(:,:) = 0._wp
+         hfx_thd(:,:) = 0._wp   ;   
+         hfx_snw(:,:) = 0._wp   ;   hfx_opw(:,:) = 0._wp
+         hfx_bog(:,:) = 0._wp   ;   hfx_dyn(:,:) = 0._wp
+         hfx_bom(:,:) = 0._wp   ;   hfx_sum(:,:) = 0._wp
+         hfx_res(:,:) = 0._wp   ;   hfx_sub(:,:) = 0._wp
+         hfx_spr(:,:) = 0._wp   ;   hfx_dif(:,:) = 0._wp 
+         hfx_err(:,:) = 0._wp   ;   hfx_err_rem(:,:) = 0._wp
+
+         !
+         fhld  (:,:)    = 0._wp 
+         fmmflx(:,:)    = 0._wp     
+         ! part of solar radiation transmitted through the ice
+         ftr_ice(:,:,:) = 0._wp
+
+         ! diags
+         diag_trp_vi  (:,:) = 0._wp  ; diag_trp_vs(:,:) = 0._wp  ;  diag_trp_ei(:,:) = 0._wp  ;  diag_trp_es(:,:) = 0._wp
+         diag_heat_dhc(:,:) = 0._wp  
+
          ! dynamical invariants
          delta_i(:,:) = 0._wp       ;   divu_i(:,:) = 0._wp       ;   shear_i(:,:) = 0._wp
@@ -352,13 +371,13 @@
          ENDIF
 !                         !- Change old values for new values
-                          old_u_ice(:,:)   = u_ice (:,:)
-                          old_v_ice(:,:)   = v_ice (:,:)
-                          old_a_i(:,:,:)   = a_i (:,:,:)
-                          old_v_s(:,:,:)   = v_s (:,:,:)
-                          old_v_i(:,:,:)   = v_i (:,:,:)
-                          old_e_s(:,:,:,:) = e_s (:,:,:,:)
-                          old_e_i(:,:,:,:) = e_i (:,:,:,:)
-                          old_oa_i(:,:,:)  = oa_i(:,:,:)
-                          old_smv_i(:,:,:) = smv_i (:,:,:)
+                          u_ice_b(:,:)     = u_ice(:,:)
+                          v_ice_b(:,:)     = v_ice(:,:)
+                          a_i_b  (:,:,:)   = a_i  (:,:,:)
+                          v_s_b  (:,:,:)   = v_s  (:,:,:)
+                          v_i_b  (:,:,:)   = v_i  (:,:,:)
+                          e_s_b  (:,:,:,:) = e_s  (:,:,:,:)
+                          e_i_b  (:,:,:,:) = e_i  (:,:,:,:)
+                          oa_i_b (:,:,:)   = oa_i (:,:,:)
+                          smv_i_b(:,:,:)   = smv_i(:,:,:)
  
          ! ----------------------------------------------
@@ -375,5 +394,4 @@
                           zcoef = rdt_ice /rday           !  Ice natural aging
                           oa_i(:,:,:) = oa_i(:,:,:) + a_i(:,:,:) * zcoef
-                          CALL lim_var_glo2eqv            ! this CALL is maybe not necessary (Martin)
          IF( ln_nicep )   CALL lim_prt_state( kt, jiindx, jjindx, 1, ' - ice thermodyn. - ' )   ! control print
                           CALL lim_itd_th( kt )           !  Remap ice categories, lateral accretion  !
@@ -391,7 +409,7 @@
          !                                           ! Diagnostics and outputs 
          IF (ln_limdiaout) CALL lim_diahsb
-!clem # if ! defined key_iomput
+
                           CALL lim_wri( 1  )              ! Ice outputs 
-!clem # endif
+
          IF( kt == nit000 .AND. ln_rstart )   &
             &             CALL iom_close( numrir )        ! clem: close input ice restart file
@@ -413,12 +431,11 @@
       
 !!gm   remark, the ocean-ice stress is not saved in ice diag call above .....  find a solution!!!
-      !
-      CALL wrk_dealloc( jpi,jpj,jpl, zalb_ice_os, zalb_ice_cs )
-
-#if defined key_coupled
-      IF ( ln_cpl .OR. ln_iceflx_ave .OR. ln_iceflx_linear ) CALL wrk_dealloc( jpi,jpj,jpl, zalb_ice)
-      IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) &
-         &    CALL wrk_dealloc( jpi,jpj, ztem_ice_all, zalb_ice_all, z_qsr_ice_all, z_qns_ice_all, z_qla_ice_all, z_dqns_ice_all, z_dqla_ice_all)
-#endif
+      CALL wrk_dealloc( jpi,jpj,jpl, zalb_ice_os, zalb_ice_cs, zalb_ice )
+
+      IF( lk_cpl ) THEN
+         IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) &
+            &    CALL wrk_dealloc( jpi, jpj, ztem_ice_all , zalb_ice_all , z_qsr_ice_all, z_qns_ice_all,   &
+            &                                z_qla_ice_all, z_dqns_ice_all, z_dqla_ice_all)
+      ENDIF
       !
       IF( nn_timing == 1 )  CALL timing_stop('sbc_ice_lim')
@@ -456,6 +473,6 @@
                   !WRITE(numout,*) ' at_i     ', at_i(ji,jj)
                   !WRITE(numout,*) ' Point - category', ji, jj, jl
-                  !WRITE(numout,*) ' a_i *** a_i_old ', a_i      (ji,jj,jl), old_a_i  (ji,jj,jl)
-                  !WRITE(numout,*) ' v_i *** v_i_old ', v_i      (ji,jj,jl), old_v_i  (ji,jj,jl)
+                  !WRITE(numout,*) ' a_i *** a_i_b   ', a_i      (ji,jj,jl), a_i_b  (ji,jj,jl)
+                  !WRITE(numout,*) ' v_i *** v_i_b   ', v_i      (ji,jj,jl), v_i_b  (ji,jj,jl)
                   !WRITE(numout,*) ' d_a_i_thd/trp   ', d_a_i_thd(ji,jj,jl), d_a_i_trp(ji,jj,jl)
                   !WRITE(numout,*) ' d_v_i_thd/trp   ', d_v_i_thd(ji,jj,jl), d_v_i_trp(ji,jj,jl)
@@ -534,5 +551,4 @@
 !                 WRITE(numout,*) ' sst                  : ', sst_m(ji,jj)
 !                 WRITE(numout,*) ' sss                  : ', sss_m(ji,jj)
-!                 WRITE(numout,*) ' s_i_newice           : ', s_i_newice(ji,jj,1:jpl)
 !                 WRITE(numout,*) 
                   inb_alp(ialert_id) = inb_alp(ialert_id) + 1
@@ -568,7 +584,7 @@
                !DO jl = 1, jpl
                   !WRITE(numout,*) ' Category no: ', jl
-                  !WRITE(numout,*) ' a_i        : ', a_i      (ji,jj,jl) , ' old_a_i    : ', old_a_i  (ji,jj,jl)   
+                  !WRITE(numout,*) ' a_i        : ', a_i      (ji,jj,jl) , ' a_i_b      : ', a_i_b  (ji,jj,jl)   
                   !WRITE(numout,*) ' d_a_i_trp  : ', d_a_i_trp(ji,jj,jl) , ' d_a_i_thd  : ', d_a_i_thd(ji,jj,jl) 
-                  !WRITE(numout,*) ' v_i        : ', v_i      (ji,jj,jl) , ' old_v_i    : ', old_v_i  (ji,jj,jl)   
+                  !WRITE(numout,*) ' v_i        : ', v_i      (ji,jj,jl) , ' v_i_b      : ', v_i_b  (ji,jj,jl)   
                   !WRITE(numout,*) ' d_v_i_trp  : ', d_v_i_trp(ji,jj,jl) , ' d_v_i_thd  : ', d_v_i_thd(ji,jj,jl) 
                   !WRITE(numout,*) ' '
@@ -591,17 +607,4 @@
                !WRITE(numout,*) ' sst       : ', sst_m(ji,jj)
                !WRITE(numout,*) ' sss       : ', sss_m(ji,jj)
-               !WRITE(numout,*) ' qcmif     : ', qcmif(ji,jj)
-               !WRITE(numout,*) ' qldif     : ', qldif(ji,jj)
-               !WRITE(numout,*) ' qcmif     : ', qcmif(ji,jj) / rdt_ice
-               !WRITE(numout,*) ' qldif     : ', qldif(ji,jj) / rdt_ice
-               !WRITE(numout,*) ' qfvbq     : ', qfvbq(ji,jj)
-               !WRITE(numout,*) ' qdtcn     : ', qdtcn(ji,jj)
-               !WRITE(numout,*) ' qfvbq / dt: ', qfvbq(ji,jj) / rdt_ice
-               !WRITE(numout,*) ' qdtcn / dt: ', qdtcn(ji,jj) / rdt_ice
-               !WRITE(numout,*) ' fdtcn     : ', fdtcn(ji,jj) 
-               !WRITE(numout,*) ' fhmec     : ', fhmec(ji,jj) 
-               !WRITE(numout,*) ' fheat_mec : ', fheat_mec(ji,jj) 
-               !WRITE(numout,*) ' fheat_res : ', fheat_res(ji,jj) 
-               !WRITE(numout,*) ' fhbri     : ', fhbri(ji,jj) 
                !
                !CALL lim_prt_state( kt, ji, jj, 2, '   ')
@@ -759,5 +762,5 @@
                WRITE(numout,*) ' strength      : ', strength(ji,jj)
                WRITE(numout,*) ' d_u_ice_dyn   : ', d_u_ice_dyn(ji,jj), ' d_v_ice_dyn   : ', d_v_ice_dyn(ji,jj)
-               WRITE(numout,*) ' old_u_ice     : ', old_u_ice(ji,jj)  , ' old_v_ice     : ', old_v_ice(ji,jj)  
+               WRITE(numout,*) ' u_ice_b       : ', u_ice_b(ji,jj)    , ' v_ice_b       : ', v_ice_b(ji,jj)  
                WRITE(numout,*)
                
@@ -769,19 +772,19 @@
                   WRITE(numout,*) ' t_su       : ', t_su(ji,jj,jl)             , ' t_s        : ', t_s(ji,jj,1,jl)
                   WRITE(numout,*) ' sm_i       : ', sm_i(ji,jj,jl)             , ' o_i        : ', o_i(ji,jj,jl)
-                  WRITE(numout,*) ' a_i        : ', a_i(ji,jj,jl)              , ' old_a_i    : ', old_a_i(ji,jj,jl)   
+                  WRITE(numout,*) ' a_i        : ', a_i(ji,jj,jl)              , ' a_i_b      : ', a_i_b(ji,jj,jl)   
                   WRITE(numout,*) ' d_a_i_trp  : ', d_a_i_trp(ji,jj,jl)        , ' d_a_i_thd  : ', d_a_i_thd(ji,jj,jl) 
-                  WRITE(numout,*) ' v_i        : ', v_i(ji,jj,jl)              , ' old_v_i    : ', old_v_i(ji,jj,jl)   
+                  WRITE(numout,*) ' v_i        : ', v_i(ji,jj,jl)              , ' v_i_b      : ', v_i_b(ji,jj,jl)   
                   WRITE(numout,*) ' d_v_i_trp  : ', d_v_i_trp(ji,jj,jl)        , ' d_v_i_thd  : ', d_v_i_thd(ji,jj,jl) 
-                  WRITE(numout,*) ' v_s        : ', v_s(ji,jj,jl)              , ' old_v_s    : ', old_v_s(ji,jj,jl)  
+                  WRITE(numout,*) ' v_s        : ', v_s(ji,jj,jl)              , ' v_s_b      : ', v_s_b(ji,jj,jl)  
                   WRITE(numout,*) ' d_v_s_trp  : ', d_v_s_trp(ji,jj,jl)        , ' d_v_s_thd  : ', d_v_s_thd(ji,jj,jl)
-                  WRITE(numout,*) ' e_i1       : ', e_i(ji,jj,1,jl)/1.0e9      , ' old_ei1    : ', old_e_i(ji,jj,1,jl)/1.0e9 
+                  WRITE(numout,*) ' e_i1       : ', e_i(ji,jj,1,jl)/1.0e9      , ' ei1        : ', e_i_b(ji,jj,1,jl)/1.0e9 
                   WRITE(numout,*) ' de_i1_trp  : ', d_e_i_trp(ji,jj,1,jl)/1.0e9, ' de_i1_thd  : ', d_e_i_thd(ji,jj,1,jl)/1.0e9
-                  WRITE(numout,*) ' e_i2       : ', e_i(ji,jj,2,jl)/1.0e9      , ' old_ei2    : ', old_e_i(ji,jj,2,jl)/1.0e9  
+                  WRITE(numout,*) ' e_i2       : ', e_i(ji,jj,2,jl)/1.0e9      , ' ei2_b      : ', e_i_b(ji,jj,2,jl)/1.0e9  
                   WRITE(numout,*) ' de_i2_trp  : ', d_e_i_trp(ji,jj,2,jl)/1.0e9, ' de_i2_thd  : ', d_e_i_thd(ji,jj,2,jl)/1.0e9
-                  WRITE(numout,*) ' e_snow     : ', e_s(ji,jj,1,jl)            , ' old_e_snow : ', old_e_s(ji,jj,1,jl) 
+                  WRITE(numout,*) ' e_snow     : ', e_s(ji,jj,1,jl)            , ' e_snow_b   : ', e_s_b(ji,jj,1,jl) 
                   WRITE(numout,*) ' d_e_s_trp  : ', d_e_s_trp(ji,jj,1,jl)      , ' d_e_s_thd  : ', d_e_s_thd(ji,jj,1,jl)
-                  WRITE(numout,*) ' smv_i      : ', smv_i(ji,jj,jl)            , ' old_smv_i  : ', old_smv_i(ji,jj,jl)   
+                  WRITE(numout,*) ' smv_i      : ', smv_i(ji,jj,jl)            , ' smv_i_b    : ', smv_i_b(ji,jj,jl)   
                   WRITE(numout,*) ' d_smv_i_trp: ', d_smv_i_trp(ji,jj,jl)      , ' d_smv_i_thd: ', d_smv_i_thd(ji,jj,jl) 
-                  WRITE(numout,*) ' oa_i       : ', oa_i(ji,jj,jl)             , ' old_oa_i   : ', old_oa_i(ji,jj,jl)
+                  WRITE(numout,*) ' oa_i       : ', oa_i(ji,jj,jl)             , ' oa_i_b     : ', oa_i_b(ji,jj,jl)
                   WRITE(numout,*) ' d_oa_i_trp : ', d_oa_i_trp(ji,jj,jl)       , ' d_oa_i_thd : ', d_oa_i_thd(ji,jj,jl)
                END DO !jl
@@ -790,14 +793,8 @@
                WRITE(numout,*) ' - Heat / FW fluxes '
                WRITE(numout,*) '   ~~~~~~~~~~~~~~~~ '
-               WRITE(numout,*) ' emp        : ', emp      (ji,jj)
-               WRITE(numout,*) ' sfx        : ', sfx      (ji,jj)
-               WRITE(numout,*) ' sfx_thd    : ', sfx_thd(ji,jj)
-               WRITE(numout,*) ' sfx_bri    : ', sfx_bri  (ji,jj)
-               WRITE(numout,*) ' sfx_mec    : ', sfx_mec  (ji,jj)
-               WRITE(numout,*) ' sfx_res    : ', sfx_res(ji,jj)
-               WRITE(numout,*) ' fmmec      : ', fmmec    (ji,jj)
-               WRITE(numout,*) ' fhmec      : ', fhmec    (ji,jj)
-               WRITE(numout,*) ' fhbri      : ', fhbri    (ji,jj)
-               WRITE(numout,*) ' fheat_mec  : ', fheat_mec(ji,jj)
+               WRITE(numout,*) ' - Heat fluxes in and out the ice ***'
+               WRITE(numout,*) ' qsr_ini       : ', pfrld(ji,jj) * qsr(ji,jj) + SUM( a_i_b(ji,jj,:) * qsr_ice(ji,jj,:) )
+               WRITE(numout,*) ' qns_ini       : ', pfrld(ji,jj) * qns(ji,jj) + SUM( a_i_b(ji,jj,:) * qns_ice(ji,jj,:) )
+               WRITE(numout,*)
                WRITE(numout,*) 
                WRITE(numout,*) ' sst        : ', sst_m(ji,jj)  
@@ -829,21 +826,27 @@
                WRITE(numout,*) ' qsr       : ', qsr(ji,jj)
                WRITE(numout,*) ' qns       : ', qns(ji,jj)
-               WRITE(numout,*) ' fdtcn     : ', fdtcn(ji,jj)
-               WRITE(numout,*) ' qcmif     : ', qcmif(ji,jj) * r1_rdtice
-               WRITE(numout,*) ' qldif     : ', qldif(ji,jj) * r1_rdtice
+               WRITE(numout,*)
+               WRITE(numout,*) ' hfx_mass     : ', hfx_thd(ji,jj) + hfx_dyn(ji,jj) + hfx_snw(ji,jj) + hfx_res(ji,jj)
+               WRITE(numout,*) ' hfx_in       : ', hfx_in(ji,jj)
+               WRITE(numout,*) ' hfx_out      : ', hfx_out(ji,jj)
+               WRITE(numout,*) ' dhc          : ', diag_heat_dhc(ji,jj)              
+               WRITE(numout,*)
+               WRITE(numout,*) ' hfx_dyn      : ', hfx_dyn(ji,jj)
+               WRITE(numout,*) ' hfx_thd      : ', hfx_thd(ji,jj)
+               WRITE(numout,*) ' hfx_res      : ', hfx_res(ji,jj)
+               WRITE(numout,*) ' fhtur        : ', fhtur(ji,jj) 
+               WRITE(numout,*) ' qlead        : ', qlead(ji,jj) * r1_rdtice
                WRITE(numout,*)
                WRITE(numout,*) ' - Salt fluxes at bottom interface ***'
                WRITE(numout,*) ' emp       : ', emp    (ji,jj)
-               WRITE(numout,*) ' sfx_bri   : ', sfx_bri(ji,jj)
                WRITE(numout,*) ' sfx       : ', sfx    (ji,jj)
                WRITE(numout,*) ' sfx_res   : ', sfx_res(ji,jj)
-               WRITE(numout,*) ' sfx_mec   : ', sfx_mec(ji,jj)
-               WRITE(numout,*) ' - Heat fluxes at bottom interface ***'
-               WRITE(numout,*) ' fheat_res : ', fheat_res(ji,jj)
+               WRITE(numout,*) ' sfx_bri   : ', sfx_bri(ji,jj)
+               WRITE(numout,*) ' sfx_dyn   : ', sfx_dyn(ji,jj)
                WRITE(numout,*)
                WRITE(numout,*) ' - Momentum fluxes '
                WRITE(numout,*) ' utau      : ', utau(ji,jj) 
                WRITE(numout,*) ' vtau      : ', vtau(ji,jj)
-            ENDIF
+            ENDIF 
             WRITE(numout,*) ' '
             !
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90	(revision 4921)
@@ -53,4 +53,8 @@
    USE agrif_lim2_update
 # endif
+
+#if defined key_bdy 
+   USE bdyice_lim       ! unstructured open boundary data  (bdy_ice_lim routine)
+#endif
 
    IMPLICIT NONE
@@ -205,4 +209,7 @@
                            CALL lim_trp_2      ( kt )      ! Ice transport   ( Advection/diffusion )
            IF( ln_limdmp ) CALL lim_dmp_2      ( kt )      ! Ice damping 
+#if defined key_bdy
+                           CALL bdy_ice_lim( kt ) ! bdy ice thermo
+#endif
          END IF
 #if defined key_coupled
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 4921)
@@ -186,4 +186,6 @@
  
       fmmflx(:,:) = 0.0_wp                        ! freezing-melting array initialisation
+      
+      taum(:,:) = 0.0_wp                           ! Initialise taum for use in gls in case of reduced restart
 
       !                                            ! restartability   
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mle.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mle.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mle.F90	(revision 4921)
@@ -203,6 +203,11 @@
       !
       !                                      !==  structure function value at uw- and vw-points  ==!
-      zhu(:,:) = 1._wp / zhu(:,:)                   ! hu --> 1/hu
-      zhv(:,:) = 1._wp / zhv(:,:)
+      DO jj = 1, jpjm1
+         DO ji = 1, fs_jpim1   ! vector opt.
+            zhu(ji,jj) = 1._wp / zhu(ji,jj)                   ! hu --> 1/hu
+            zhv(ji,jj) = 1._wp / zhv(ji,jj)
+         END DO
+      END DO
+      !
       zpsi_uw(:,:,:) = 0._wp
       zpsi_vw(:,:,:) = 0._wp
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 4921)
@@ -129,4 +129,6 @@
       IF( kt == nit000 ) THEN                     ! Set the forcing field at nit000 - 1
          !                                        ! -----------------------------------
+         qsr_hc(:,:,:) = 0.e0
+         !
          IF( ln_rstart .AND.    &                    ! Restart: read in restart file
               & iom_varid( numror, 'qsr_hc_b', ldstop = .FALSE. ) > 0 ) THEN
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 4921)
@@ -1258,4 +1258,8 @@
                en  (:,:,:) = rn_emin
                mxln(:,:,:) = 0.001        
+               avt_k (:,:,:) = avt (:,:,:)
+               avm_k (:,:,:) = avm (:,:,:)
+               avmu_k(:,:,:) = avmu(:,:,:)
+               avmv_k(:,:,:) = avmv(:,:,:)
                DO jit = nit000 + 1, nit000 + 10   ;   CALL zdf_gls( jit )   ;   END DO
             ENDIF
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfini.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfini.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfini.F90	(revision 4921)
@@ -121,4 +121,8 @@
       IF(lwp) WRITE(numout,*)
       IF(lwp) WRITE(numout,*) '   convection :'
+      !
+      IF( ln_zdfnpc )   CALL ctl_stop( ' zdf_init: non penetrative convective scheme is not working',   &
+         &                                       ' set ln_zdfnpc to FALSE' )
+      !
       ioptio = 0
       IF( ln_zdfnpc ) THEN
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 4921)
@@ -86,5 +86,5 @@
    USE sbctide, ONLY: lk_tide
    USE crsini          ! initialise grid coarsening utility
-   USE lbcnfd, ONLY: isendto, nsndto ! Setup of north fold exchanges 
+   USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges 
 
    IMPLICIT NONE
@@ -568,8 +568,4 @@
       ENDIF
       !
-      IF( lk_c1d .AND. .NOT.lk_iomput )   CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ',   &
-         &                                               'with the IOM Input/Output manager. '         ,   &
-         &                                               'Compile with key_iomput enabled' )
-      !
       IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
          &                                               'f2003 standard. '                              ,  &
@@ -803,24 +799,36 @@
           !loop over the other north-fold processes to find the processes
           !managing the points belonging to the sxT-dxT range
-          DO jn = jpnij - jpni +1, jpnij
-             IF ( njmppt(jn) == njmppmax ) THEN
+  
+          DO jn = 1, jpni
                 !sxT is the first point (in the global domain) of the jn
                 !process
-                sxT = nimppt(jn)
+                sxT = nfiimpp(jn, jpnj)
                 !dxT is the last point (in the global domain) of the jn
                 !process
-                dxT = nimppt(jn) + nlcit(jn) - 1
+                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
                 IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
                    nsndto = nsndto + 1
-                   isendto(nsndto) = jn
+                     isendto(nsndto) = jn
                 ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
                    nsndto = nsndto + 1
-                   isendto(nsndto) = jn
+                     isendto(nsndto) = jn
                 ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
                    nsndto = nsndto + 1
-                   isendto(nsndto) = jn
+                     isendto(nsndto) = jn
                 END IF
-             END IF
           END DO
+          nfsloop = 1
+          nfeloop = nlci
+          DO jn = 2,jpni-1
+           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
+              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
+                 nfsloop = nldi
+              ENDIF
+              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
+                 nfeloop = nlei
+              ENDIF
+           ENDIF
+        END DO
+
       ENDIF
       l_north_nogather = .TRUE.
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/oce.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/oce.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/oce.F90	(revision 4921)
@@ -85,4 +85,5 @@
       ALLOCATE(rhd (jpi,jpj,jpk) ,                                         &
          &     rhop(jpi,jpj,jpk) ,                                         &
+         &     rke(jpi,jpj,jpk)  ,                                         &
          &     sshb(jpi,jpj)     , sshn(jpi,jpj)   , ssha(jpi,jpj)   ,     &
          &     ub_b(jpi,jpj)     , un_b(jpi,jpj)   , ua_b(jpi,jpj)   ,     &
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 4921)
@@ -302,5 +302,4 @@
       IF( lk_diaobs  )         CALL dia_obs( kstp )         ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
 
-      IF( lrst_oce .AND. ln_diahsb )   CALL dia_hsb_rst( kstp, 'WRITE' )
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Control and restarts
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zfechem.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zfechem.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zfechem.F90	(revision 4921)
@@ -244,5 +244,5 @@
                ztrc   = ( trn(ji,jj,jk,jppoc) + trn(ji,jj,jk,jpgoc) + trn(ji,jj,jk,jpcal) + trn(ji,jj,jk,jpgsi) ) * 1.e6 
 #endif
-               IF( ln_dust )  zdust  = dust(ji,jj) / ( wdust * rday ) * tmask(ji,jj,jk) ! dust in kg/m2/s
+               IF( ln_dust )  zdust  = dust(ji,jj) / ( wdust / rday ) * tmask(ji,jj,jk) ! dust in kg/m2/s
                zlam1b = 3.e-5 + xlamdust * zdust + xlam1 * ztrc
                zscave = zfeequi * zlam1b * zstep
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zmeso.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zmeso.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zmeso.F90	(revision 4921)
@@ -163,5 +163,5 @@
               zfrac     = zproport * grazflux  * zstep * wsbio4(ji,jj,jk)      &
                &          * trn(ji,jj,jk,jpgoc) * trn(ji,jj,jk,jpmes)          &
-               &          * ( 0.1 + 3.9 * zratio2 / ( 1.**2 + zratio2 ) )
+               &          * ( 0.2 + 3.8 * zratio2 / ( 1.**2 + zratio2 ) )
               zfracfe   = zfrac * trn(ji,jj,jk,jpbfe) / (trn(ji,jj,jk,jpgoc) + rtrn)
 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zmicro.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zmicro.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zmicro.F90	(revision 4921)
@@ -137,6 +137,6 @@
                !    Various remineralization and excretion terms
                !    --------------------------------------------
-               zgrasrat  = zgraztotf / ( zgraztot + rtrn )
-               zgrasratn = zgraztotn / ( zgraztot + rtrn )
+               zgrasrat  = ( zgraztotf + rtrn ) / ( zgraztot + rtrn )
+               zgrasratn = ( zgraztotn + rtrn ) / ( zgraztot + rtrn )
                zepshert  =  MIN( 1., zgrasratn, zgrasrat / ferat3)
                zepsherv  = zepshert * MIN( epsher, (1. - unass) * zgrasrat / ferat3, (1. - unass) * zgrasratn )
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsed.F90
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsed.F90	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsed.F90	(revision 4921)
@@ -35,5 +35,4 @@
    REAL(wp) :: ryyss                    !: number of seconds per year 
    REAL(wp) :: r1_ryyss                 !: inverse of ryyss
-   REAL(wp) :: rmtss                    !: number of seconds per month
    REAL(wp) :: r1_rday                  !: inverse of rday
 
@@ -85,5 +84,4 @@
       IF( kt == nittrc000 .AND. jnt == 1 )  THEN
          ryyss    = nyear_len(1) * rday    ! number of seconds per year and per month
-         rmtss    = ryyss / raamo
          r1_rday  = 1. / rday
          r1_ryyss = 1. / ryyss
@@ -99,4 +97,8 @@
       zdenit2d(:,:) = 0.e0
       zbureff (:,:) = 0.e0
+      zwork1  (:,:) = 0.e0
+      zwork2  (:,:) = 0.e0
+      zwork3  (:,:) = 0.e0
+      zwork4  (:,:) = 0.e0
 
       ! Iron input/uptake due to sea ice : Crude parameterization based on Lancelot et al.
@@ -132,10 +134,10 @@
          !                                              ! Iron and Si deposition at the surface
          IF( ln_solub ) THEN
-            zirondep(:,:,1) = solub(:,:) * dust(:,:) * mfrac * rfact2 / fse3t(:,:,1) / ( 55.85 * rmtss ) + 3.e-10 * r1_ryyss 
+            zirondep(:,:,1) = solub(:,:) * dust(:,:) * mfrac * rfact2 / fse3t(:,:,1) / 55.85 + 3.e-10 * r1_ryyss 
          ELSE
-            zirondep(:,:,1) = dustsolub  * dust(:,:) * mfrac * rfact2 / fse3t(:,:,1) / ( 55.85 * rmtss ) + 3.e-10 * r1_ryyss 
+            zirondep(:,:,1) = dustsolub  * dust(:,:) * mfrac * rfact2 / fse3t(:,:,1) / 55.85 + 3.e-10 * r1_ryyss 
          ENDIF
-         zsidep(:,:) = 8.8 * 0.075 * dust(:,:) * mfrac * rfact2 / fse3t(:,:,1) / ( 28.1  * rmtss )
-         zpdep (:,:) = 0.1 * 0.021 * dust(:,:) * mfrac * rfact2 / fse3t(:,:,1) / ( 31.   * rmtss ) / po4r 
+         zsidep(:,:) = 8.8 * 0.075 * dust(:,:) * mfrac * rfact2 / fse3t(:,:,1) / 28.1 
+         zpdep (:,:) = 0.1 * 0.021 * dust(:,:) * mfrac * rfact2 / fse3t(:,:,1) / 31. / po4r 
          !                                              ! Iron solubilization of particles in the water column
          !                                              ! dust in kg/m2/s ---> 1/55.85 to put in mol/Fe ;  wdust in m/j
@@ -250,16 +252,18 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            ikt = mbkt(ji,jj) 
+            IF( tmask(ji,jj,1) == 1 ) THEN
+               ikt = mbkt(ji,jj) 
 # if defined key_kriest
-            zwork1(ji,jj) = trn(ji,jj,ikt,jpgsi) * zwscal (ji,jj)
-            zwork2(ji,jj) = trn(ji,jj,ikt,jppoc) * zwsbio3(ji,jj)
+               zwork1(ji,jj) = trn(ji,jj,ikt,jpgsi) * zwscal (ji,jj)
+               zwork2(ji,jj) = trn(ji,jj,ikt,jppoc) * zwsbio3(ji,jj)
 # else
-            zwork1(ji,jj) = trn(ji,jj,ikt,jpgsi) * zwsbio4(ji,jj)
-            zwork2(ji,jj) = trn(ji,jj,ikt,jpgoc) * zwsbio4(ji,jj) + trn(ji,jj,ikt,jppoc) * zwsbio3(ji,jj) 
+               zwork1(ji,jj) = trn(ji,jj,ikt,jpgsi) * zwsbio4(ji,jj)
+               zwork2(ji,jj) = trn(ji,jj,ikt,jpgoc) * zwsbio4(ji,jj) + trn(ji,jj,ikt,jppoc) * zwsbio3(ji,jj) 
 # endif
-            ! For calcite, burial efficiency is made a function of saturation
-            zfactcal      = MIN( excess(ji,jj,ikt), 0.2 )
-            zfactcal      = MIN( 1., 1.3 * ( 0.2 - zfactcal ) / ( 0.4 - zfactcal ) )
-            zwork3(ji,jj) = trn(ji,jj,ikt,jpcal) * zwscal(ji,jj) * 2.e0 * zfactcal
+               ! For calcite, burial efficiency is made a function of saturation
+               zfactcal      = MIN( excess(ji,jj,ikt), 0.2 )
+               zfactcal      = MIN( 1., 1.3 * ( 0.2 - zfactcal ) / ( 0.4 - zfactcal ) )
+               zwork3(ji,jj) = trn(ji,jj,ikt,jpcal) * zwscal(ji,jj) * 2.e0 * zfactcal
+            ENDIF
          END DO
       END DO
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_MOBILIS
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_MOBILIS	(revision 4921)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_MOBILIS	(revision 4921)
@@ -0,0 +1,94 @@
+#!/bin/bash
+#SBATCH -N NODES
+#SBATCH --time=00:59:00 
+
+module purge
+module load shared
+module load gcc
+module load intel/compiler/64/14.0/2013_sp1.2.144
+module load openmpi/intel/64/1.6.5
+module load slurm/2.5.7
+
+#
+  export OMP_NUM_THREADS=1
+  export OCORES=NPROCS
+  export XCORES=NXIOPROCS
+  export SETTE_DIR=DEF_SETTE_DIR
+  export XIO_HOME=/home/acc/XIOS
+#
+# load sette functions (only post_test_tidyup needed)
+#
+  . ${SETTE_DIR}/all_functions.sh
+###############################################################
+#
+# set up mpp computing environment
+#
+#
+# Local settings. These settings are for a particular machine (the MOBILIS ClusterVision 
+# system at NOCS) at a particular stage of that machine's evolution. This template file
+# is provided for illustration purposes only and will not work on any other machine. There
+# should, however, be sufficient similarity with other MPP platforms and batch systems
+# for this example to provide a useful guide for experienced users
+#
+# Don't remove neither change the following line
+# BODY
+#
+# Test specific settings. Do not hand edit these lines; the fcm_job.sh script will set these
+# (via sed operating on this template job file). Note that the number of compute nodes required
+# is also set by the fcm_job.sh on the PBS select header line above.
+#
+# These variables are needed by post_test_tidyup function in all_functions.sh
+#
+  export INPUT_DIR=DEF_INPUT_DIR
+  export CONFIG_DIR=DEF_CONFIG_DIR
+  export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
+  export NEW_CONF=DEF_NEW_CONF
+  export CMP_NAM=DEF_CMP_NAM
+  export TEST_NAME=DEF_TEST_NAME
+  export EXE_DIR=DEF_EXE_DIR
+#
+# end of set up
+###############################################################
+#
+# change to the working directory 
+#
+  cd $EXE_DIR
+  echo Directory is `pwd`
+  if [ $XCORES -eq 0 ]; then
+#
+# Run SPMD case
+#
+       echo time `which mpirun` --report-bindings -x MALLOC_MMAP_MAX_=-1                 \
+                                -x MALLOC_TRIM_THRESHOLD_=33554432 -np $OCORES --bynode  \
+                                --mca mpi_paffinity_alone 1 ./opa 
+            time `which mpirun` --report-bindings -x MALLOC_MMAP_MAX_=-1                 \
+                                -x MALLOC_TRIM_THRESHOLD_=33554432 -np $OCORES --bynode  \
+                                --mca mpi_paffinity_alone 1 ./opa 
+  else
+       if [ ! -f ./xios_server.exe ] && [ -f ${XIO_HOME}/bin/xios_server.exe ]; then
+          cp ${XIO_HOME}/bin/xios_server.exe .
+       fi
+       if [ ! -f ./xios_server.exe ]; then
+          echo "./xios_server.exe not found"
+          echo "run aborted"
+          exit
+       fi
+#
+#  Run MPMD case
+#
+       echo time `which mpirun` --report-bindings -x MALLOC_MMAP_MAX_=-1 \
+                                -x MALLOC_TRIM_THRESHOLD_=33554432       \
+                                -np $XCORES ./xios_server.exe            \
+                              : -np $OCORES --bynode  --mca mpi_paffinity_alone 1 ./opa 
+#
+            time `which mpirun` --report-bindings -x MALLOC_MMAP_MAX_=-1 \
+                                -x MALLOC_TRIM_THRESHOLD_=33554432       \
+                                -np $XCORES ./xios_server.exe            \
+                              : -np $OCORES --bynode  --mca mpi_paffinity_alone 1 ./opa 
+#
+  fi
+#
+  post_test_tidyup
+# END_BODY
+# Don't remove neither change the previous line
+  exit
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-XC_ARCHER_INTEL
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-XC_ARCHER_INTEL	(revision 4921)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-XC_ARCHER_INTEL	(revision 4921)
@@ -0,0 +1,94 @@
+#!/bin/bash 
+#!
+#PBS -N nemo_sette
+#PBS -l walltime=00:59:00
+#PBS -l select=NODES
+#PBS -j oe
+#PBS -A n01-Global
+
+
+  export PBS_O_WORKDIR=$(readlink -f $PBS_O_WORKDIR)               
+  export OMP_NUM_THREADS=1
+  cd $PBS_O_WORKDIR
+#
+  echo " ";
+  export OMP_NUM_THREADS=1
+  O_PER_NODE=24
+  X_PER_NODE=4
+  OCORES=NPROCS
+  if [ $OCORES -le 23 ] ; then O_PER_NODE=$OCORES; fi
+  XCORES=NXIOPROCS
+  if [ $XCORES -le 3 ] ; then X_PER_NODE=$XCORES; fi
+  export SETTE_DIR=DEF_SETTE_DIR
+  export XIO_HOME=/home/acc/XIOS
+###############################################################
+#
+#
+# load sette functions (only post_test_tidyup needed)
+#
+  . ${SETTE_DIR}/all_functions.sh
+###############################################################
+#
+# set up mpp computing environment
+#
+#
+# Local settings. These settings are for a particular machine (the MOBILIS ClusterVision 
+# system at NOCS) at a particular stage of that machine's evolution. This template file
+# is provided for illustration purposes only and will not work on any other machine. There
+# should, however, be sufficient similarity with other MPP platforms and batch systems
+# for this example to provide a useful guide for experienced users
+#
+# Don't remove neither change the following line
+# BODY
+#
+# Test specific settings. Do not hand edit these lines; the fcm_job.sh script will set these
+# (via sed operating on this template job file). Note that the number of compute nodes required
+# is also set by the fcm_job.sh on the PBS select header line above.
+#
+# These variables are needed by post_test_tidyup function in all_functions.sh
+#
+  export INPUT_DIR=DEF_INPUT_DIR
+  export CONFIG_DIR=DEF_CONFIG_DIR
+  export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
+  export NEW_CONF=DEF_NEW_CONF
+  export CMP_NAM=DEF_CMP_NAM
+  export TEST_NAME=DEF_TEST_NAME
+  export EXE_DIR=DEF_EXE_DIR
+  ulimit -c unlimited
+  ulimit -s unlimited
+  export FORT_FMT_RECL=132
+#
+# end of set up
+###############################################################
+#
+# change to the working directory 
+#
+  cd $EXE_DIR
+  echo Directory is `pwd`
+  if [ $XCORES -eq 0 ]; then
+#
+# Run SPMD case
+#
+       echo time aprun -b  -n $OCORES -N $O_PER_NODE ./opa
+            time aprun -b  -n $OCORES -N $O_PER_NODE ./opa
+  else
+       if [ ! -f ./xios_server.exe ] && [ -f ${XIO_HOME}/bin/xios_server.exe ]; then
+          cp ${XIO_HOME}/bin/xios_server.exe .
+       fi
+       if [ ! -f ./xios_server.exe ]; then
+          echo "./xios_server.exe not found"
+          echo "run aborted"
+          exit
+       fi
+#
+#  Run MPMD case
+#
+       echo time aprun -b -n $XCORES -N $X_PER_NODE ./xios_server.exe : -n $OCORES -N $O_PER_NODE ./opa
+            time aprun -b -n $XCORES -N $X_PER_NODE ./xios_server.exe : -n $OCORES -N $O_PER_NODE ./opa
+#
+  fi
+#
+  post_test_tidyup
+# END_BODY
+# Don't remove neither change the previous line
+  exit
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-x3750_ADA
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-x3750_ADA	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-x3750_ADA	(revision 4921)
@@ -65,6 +65,6 @@
 #
   if [ MPI_FLAG == "yes" ]; then
-     echo "Running time ${MPIRUN} ./opa"
-     time ${MPIRUN} ./opa
+     echo "Running time ${MPIRUN} ./opa -procs $OCEANCORES"
+     time ${MPIRUN} ./opa -procs $OCEANCORES
   else
      echo "Running time ./opa"
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-x3750_ADA_O0
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-x3750_ADA_O0	(revision 4921)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-x3750_ADA_O0	(revision 4921)
@@ -0,0 +1,82 @@
+#!/bin/bash 
+#!
+# @ job_name = MPI_config
+# standard output file  
+# @ output = $(job_name).$(jobid)
+# standard error file
+# @ error =  $(job_name).$(jobid)
+# job type
+# @ job_type = parallel
+# Number of procs 
+# @ total_tasks = NPROCS
+# time
+# @ wall_clock_limit = 0:30:00
+# @ queue
+
+#
+# Test specific settings. Do not hand edit these lines; the fcm_job.sh script will set these
+# (via sed operating on this template job file). 
+#
+  OCEANCORES=NPROCS
+  export SETTE_DIR=DEF_SETTE_DIR
+
+###############################################################
+#
+# set up mpp computing environment
+#
+# Local settings for machine IBM Power6 (VARGAS at IDRIS France)
+#
+#export MPIRUN="poe -procs $OCEANCORES"
+export MPIRUN="poe"
+
+#
+# load sette functions (only post_test_tidyup needed)
+#
+  . ${SETTE_DIR}/all_functions.sh
+#
+
+# Don't remove neither change the following line
+# BODY
+
+#
+# These variables are needed by post_test_tidyup function in all_functions.sh
+#
+  export EXE_DIR=DEF_EXE_DIR
+  export INPUT_DIR=DEF_INPUT_DIR
+  export CONFIG_DIR=DEF_CONFIG_DIR
+  export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
+  export NEW_CONF=DEF_NEW_CONF
+  export CMP_NAM=DEF_CMP_NAM
+  export TEST_NAME=DEF_TEST_NAME
+#
+# end of set up
+###############################################################
+#
+# change to the working directory 
+#
+cd ${EXE_DIR}
+
+  echo Running on host `hostname`
+  echo Time is `date`
+  echo Directory is `pwd`
+# 
+#  Run the parallel MPI executable 
+#
+#  echo "Running time ${MPIRUN} ./opa"
+#
+  if [ MPI_FLAG == "yes" ]; then
+     echo "Running time ${MPIRUN} ./opa -procs $OCEANCORES"
+     time ${MPIRUN} ./opa  -procs $OCEANCORES
+  else
+     echo "Running time ./opa"
+     time ./opa
+  fi
+
+#
+  post_test_tidyup
+
+# END_BODY
+# Don't remove neither change the previous line
+
+
+  exit
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/input_ORCA2_LIM3.cfg
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/input_ORCA2_LIM3.cfg	(revision 4921)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/input_ORCA2_LIM3.cfg	(revision 4921)
@@ -0,0 +1,1 @@
+ORCA2_LIM_nemo_v3.6.tar ORCA2_LIM_nemo_v3.6
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/iodef_sette.xml
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/iodef_sette.xml	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/iodef_sette.xml	(revision 4921)
@@ -2,5 +2,5 @@
 <simulation> 
 
- <context id="nemo" time_origin="1900-01-01 00:00:00" >
+ <context id="nemo" time_origin="1950-01-01 00:00:00" >
     
     <!-- $id$ -->
@@ -21,27 +21,25 @@
     -->
     
-    <file_definition type="multiple_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" min_digits="4">
+    <file_definition type="multiple_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="10d" min_digits="4">
     
-      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".FALSE."/> <!-- 1h files -->
-      <file_group id="2h" output_freq="2h"  output_level="10" enabled=".FALSE."/> <!-- 2h files -->
-      <file_group id="3h" output_freq="3h"  output_level="10" enabled=".FALSE."/> <!-- 3h files -->     
-      <file_group id="4h" output_freq="4h"  output_level="10" enabled=".FALSE."/> <!-- 4h files -->
-      <file_group id="6h" output_freq="6h"  output_level="10" enabled=".FALSE."/> <!-- 6h files -->
-     
-      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".FALSE."/> <!-- 1d files -->
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
+      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="2h" output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
+      <file_group id="3h" output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
+      <file_group id="4h" output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
+      <file_group id="6h" output_freq="6h"  output_level="10" enabled=".TRUE."/> <!-- 6h files -->     
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="3d" output_freq="3d"  output_level="10" enabled=".TRUE."/> <!-- 3d files -->    
+      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE."/>  <!-- 5d files -->  
+      <file_group id="1m" output_freq="1mo" output_level="10" enabled=".TRUE."/> <!-- real monthly files -->
+      <file_group id="2m" output_freq="2mo" output_level="10" enabled=".TRUE."/> <!-- real 2m files -->
+      <file_group id="3m" output_freq="3mo" output_level="10" enabled=".TRUE."/> <!-- real 3m files -->
+      <file_group id="4m" output_freq="4mo" output_level="10" enabled=".TRUE."/> <!-- real 4m files -->
+      <file_group id="6m" output_freq="6mo" output_level="10" enabled=".TRUE."/> <!-- real 6m files -->
 
-      <file_group id="3d" output_freq="3d"  output_level="10" enabled=".FALSE."/> <!-- 3d files -->
-      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".FALSE."/> <!-- 5d files -->
-
-      <file_group id="1m" output_freq="1mo" output_level="10" enabled=".FALSE."/> <!-- real monthly files -->
-      <file_group id="2m" output_freq="2mo" output_level="10" enabled=".FALSE."/> <!-- real 2m files -->
-      <file_group id="3m" output_freq="3mo" output_level="10" enabled=".FALSE."/> <!-- real 3m files -->
-      <file_group id="4m" output_freq="4mo" output_level="10" enabled=".FALSE."/> <!-- real 4m files -->
-      <file_group id="6m" output_freq="6mo" output_level="10" enabled=".FALSE."/> <!-- real 6m files -->
-
-      <file_group id="1y"  output_freq="1y" output_level="10" enabled=".FALSE."/> <!-- real yearly files -->
-      <file_group id="2y"  output_freq="2y" output_level="10" enabled=".FALSE."/> <!-- real 2y files -->
-      <file_group id="5y"  output_freq="5y" output_level="10" enabled=".FALSE."/> <!-- real 5y files -->
-      <file_group id="10y" output_freq="10y" output_level="10" enabled=".FALSE."/> <!-- real 10y files -->
+      <file_group id="1y"  output_freq="1y" output_level="10" enabled=".TRUE."/> <!-- real yearly files -->
+      <file_group id="2y"  output_freq="2y" output_level="10" enabled=".TRUE."/> <!-- real 2y files -->
+      <file_group id="5y"  output_freq="5y" output_level="10" enabled=".TRUE."/> <!-- real 5y files -->
+      <file_group id="10y" output_freq="10y" output_level="10" enabled=".TRUE."/> <!-- real 10y files -->
 
    </file_definition>
@@ -64,6 +62,14 @@
    <domain_definition src="./domain_def.xml"/>
    
-   <grid_definition />    
-  
+   <grid_definition>    
+     <grid id="grid_T_2D" domain_ref="grid_T"/>
+     <grid id="grid_T_3D" domain_ref="grid_T" axis_ref="deptht"/>
+     <grid id="grid_U_2D" domain_ref="grid_U"/>
+     <grid id="grid_U_3D" domain_ref="grid_U" axis_ref="depthu"/>
+     <grid id="grid_V_2D" domain_ref="grid_V"/>
+     <grid id="grid_V_3D" domain_ref="grid_V" axis_ref="depthv"/>
+     <grid id="grid_W_2D" domain_ref="grid_W"/>
+     <grid id="grid_W_3D" domain_ref="grid_W" axis_ref="depthw"/>
+    </grid_definition>   
   </context>
   
@@ -86,34 +92,27 @@
 ============================================================================================================
     -->
- 
+    
     <file_definition type="multiple_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="10d" min_digits="4">
     
-      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".FALSE."/> <!-- 1h files -->
-      <file_group id="2h" output_freq="2h"  output_level="10" enabled=".FALSE."/> <!-- 2h files -->
-      <file_group id="3h" output_freq="3h"  output_level="10" enabled=".FALSE."/> <!-- 3h files -->     
-      <file_group id="4h" output_freq="4h"  output_level="10" enabled=".FALSE."/> <!-- 4h files -->
-      <file_group id="6h" output_freq="6h"  output_level="10" enabled=".FALSE."/> <!-- 6h files -->
-     
-      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".FALSE."/> <!-- 1d files -->
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
+      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="2h" output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
+      <file_group id="3h" output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
+      <file_group id="4h" output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
+      <file_group id="6h" output_freq="6h"  output_level="10" enabled=".TRUE."/> <!-- 6h files -->     
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="3d" output_freq="3d"  output_level="10" enabled=".TRUE."/> <!-- 3d files -->    
+      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE."/>  <!-- 5d files -->  
+      <file_group id="1m" output_freq="1mo" output_level="10" enabled=".TRUE."/> <!-- real monthly files -->
+      <file_group id="2m" output_freq="2mo" output_level="10" enabled=".TRUE."/> <!-- real 2m files -->
+      <file_group id="3m" output_freq="3mo" output_level="10" enabled=".TRUE."/> <!-- real 3m files -->
+      <file_group id="4m" output_freq="4mo" output_level="10" enabled=".TRUE."/> <!-- real 4m files -->
+      <file_group id="6m" output_freq="6mo" output_level="10" enabled=".TRUE."/> <!-- real 6m files -->
 
-      <file_group id="3d" output_freq="3d"  output_level="10" enabled=".FALSE."/> <!-- 3d files -->
-      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".FALSE."/> <!-- 5d files -->
+      <file_group id="1y"  output_freq="1y" output_level="10" enabled=".TRUE."/> <!-- real yearly files -->
+      <file_group id="2y"  output_freq="2y" output_level="10" enabled=".TRUE."/> <!-- real 2y files -->
+      <file_group id="5y"  output_freq="5y" output_level="10" enabled=".TRUE."/> <!-- real 5y files -->
+      <file_group id="10y" output_freq="10y" output_level="10" enabled=".TRUE."/> <!-- real 10y files -->
 
-      <file_group id="1m" output_freq="1mo" output_level="10" enabled=".FALSE."/> <!-- real monthly files -->
-      <file_group id="2m" output_freq="2mo" output_level="10" enabled=".FALSE."/> <!-- real 2m files -->
-      <file_group id="3m" output_freq="3mo" output_level="10" enabled=".FALSE."/> <!-- real 3m files -->
-      <file_group id="4m" output_freq="4mo" output_level="10" enabled=".FALSE."/> <!-- real 4m files -->
-      <file_group id="6m" output_freq="6mo" output_level="10" enabled=".FALSE."/> <!-- real 6m files -->
-
-      <file_group id="1y"  output_freq="1y" output_level="10" enabled=".FALSE."/> <!-- real yearly files -->
-      <file_group id="2y"  output_freq="2y" output_level="10" enabled=".FALSE."/> <!-- real 2y files -->
-      <file_group id="5y"  output_freq="5y" output_level="10" enabled=".FALSE."/> <!-- real 5y files -->
-      <file_group id="10y" output_freq="10y" output_level="10" enabled=".FALSE."/> <!-- real 10y files -->
-      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".FALSE."/> <!-- 1h files -->
-      <file_group id="2h" output_freq="2h"  output_level="10" enabled=".FALSE."/> <!-- 2h files -->
-      <file_group id="3h" output_freq="3h"  output_level="10" enabled=".FALSE."/> <!-- 3h files -->     
-      <file_group id="4h" output_freq="4h"  output_level="10" enabled=".FALSE."/> <!-- 4h files -->
-      <file_group id="6h" output_freq="6h"  output_level="10" enabled=".FALSE."/> <!-- 6h files -->
-     
    </file_definition>
     
@@ -130,4 +129,5 @@
       <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
       <axis id="nfloat" long_name="Float number"      unit="-"  />
+      <axis id="icbcla" long_name="Iceberg class"     unit="-"  />
    </axis_definition> 
     
@@ -146,5 +146,4 @@
   </context>
 
-
   <context id="xios">
 
@@ -154,5 +153,5 @@
         We must have buffer_size > jpi*jpj*jpk*8 (with jpi and jpj the subdomain size)
 -->
-	  <variable id="buffer_size"               type="integer">10000000</variable>
+	  <variable id="buffer_size"               type="integer">10155778</variable>
 	  <variable id="buffer_server_factor_size" type="integer">2</variable>
 	  <variable id="info_level"                type="integer">0</variable>
@@ -164,4 +163,3 @@
                
   </context>
-  
 </simulation>
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/prepare_exe_dir.sh
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/prepare_exe_dir.sh	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/prepare_exe_dir.sh	(revision 4921)
@@ -71,4 +71,4 @@
 
 cp -r ${CONFIG_DIR}/${NEW_CONF}/EXP00/* ${EXE_DIR}/.
-#cp -r ${SETTE_DIR}/iodef_sette.xml ${EXE_DIR}/iodef.xml
+cp -r ${SETTE_DIR}/iodef_sette.xml ${EXE_DIR}/iodef.xml
 cd ${EXE_DIR}
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/prepare_job.sh
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/prepare_job.sh	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/prepare_job.sh	(revision 4921)
@@ -182,22 +182,51 @@
 fi
 
-# example for NOCS Altix system using PBS batch submission (requires ${SETTE_DIR}/sette_batch_template file)
+# example for NOCS ClusterVision system using SLURM batch submission (requires ${SETTE_DIR}/sette_batch_template file)
 #
   #  if [ ${MPI_FLAG} == "no" ] ; then
 		case ${COMPILER} in 
-			ALTIX_NAUTILUS_MPT)
-                                NB_REM=$( echo $NB_PROC $NXIO_PROC | awk '{print ( $1 + $2 ) % 4}')
+			X64_MOBILIS)
+                                NB_REM=$( echo $NB_PROC $NXIO_PROC | awk '{print ( $1 + $2 ) % 16}')
 		        	if [ ${NB_REM} == 0 ] ; then
-					# number of processes required is an integer multiple of 4
+					# number of processes required is an integer multiple of 16
 					#
-					NB_NODES=$( echo $NB_PROC $NXIO_PROC | awk '{print ($1 + $2 ) / 4}')
+					NB_NODES=$( echo $NB_PROC $NXIO_PROC | awk '{print ($1 + $2 ) / 16}')
 				else
 					#
-					# number of processes required is not an integer multiple of 4
+					# number of processes required is not an integer multiple of 16
 					# round up the number of nodes required.
 					#
-					NB_NODES=$( echo $NB_PROC $NXIO_PROC | awk '{printf("%d",($1 + $2 ) / 4 + 1 )}')
+					NB_NODES=$( echo $NB_PROC $NXIO_PROC | awk '{printf("%d",($1 + $2 ) / 16 + 1 )}')
 	       			fi
 				;;
+                        XC_ARCHER_INTEL)
+                                # ocean cores are packed 24 to a node
+                                NB_REM=$( echo $NB_PROC | awk '{print ( $1 % 24 ) }')
+                                if [ ${NB_REM} == 0 ] ; then
+                                        # number of processes required is an integer multiple of 24
+                                        #
+                                        NB_NODES=$( echo $NB_PROC $NXIO_PROC | awk '{print ($1) / 24}')
+                                else
+                                        #
+                                        # number of processes required is not an integer multiple of 24
+                                        # round up the number of nodes required.
+                                        #
+                                        NB_NODES=$( echo $NB_PROC | awk '{printf("%d",($1) / 24 + 1 )}')
+                                fi
+                                # xios cores are sparsely packed at 4 to a node
+                                # but can not share nodes with the ocean cores
+                                NB_REM=$( echo $NXIO_PROC | awk '{print ( $2 % 4 ) }')
+                                if [ ${NB_REM} == 0 ] ; then
+                                        # number of processes required is an integer multiple of 4                           
+                                        #
+                                        NB_NODES=$( echo $NB_NODES $NXIO_PROC | awk '{print ($1 + ( $2 / 4 ))}')                    
+                                else
+                                        #
+                                        # number of processes required is not an integer multiple of 4                             
+                                        # round up the number of nodes required.
+                                        #
+                                        NB_NODES=$( echo $NB_NODES $NXIO_PROC | awk '{print ($1 + ( $2 / 4 ) + 1)}')                    
+                                fi
+                                ;;
                         ifort_MERCATOR_CLUSTER)
                                 echo NB_PROCS ${NB_PROC}
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/sette.sh
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/sette.sh	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/sette.sh	(revision 4921)
@@ -136,8 +136,9 @@
 # ORCA2_LIM_PISCES: 3 &  4
 # ORCA2_OFF_PISCES: 5 &  6
-# AMM12           : 7 &  8
-# SAS             : 9 & 10
-# ORCA2_AGRIF_LIM: 11
-for config in 1 2 3 4 5 6 7 8 9 10 11
+# ORCA2_LIM3      : 7 &  8
+# AMM12           : 9 & 10 
+# SAS             :11 & 12
+# ORCA2_AGRIF_LIM :13
+for config in 1 2 3 4 5 6 7 8 9 10 11 12 13
 
 do
@@ -629,6 +630,134 @@
 fi
 
+
+# TESTS FOR ORCA2_LIM3 CONFIGURATION
+if [ ${config} -eq 7 ] ;  then
+    ## Restartability tests for ORCA2_LIM3
+    export TEST_NAME="LONG"
+    cd ${CONFIG_DIR}
+    . ./makenemo -m ${CMP_NAM} -n ORCA2LIM3_LONG -r ORCA2_LIM3 -j 8 del_key ${DEL_KEYS}
+    cd ${SETTE_DIR}
+    . ./param.cfg
+    . ./all_functions.sh
+    . ./prepare_exe_dir.sh
+    JOB_FILE=${EXE_DIR}/run_job.sh
+    NPROC=4
+    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
+    cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"O2L3_LONG\"
+    set_namelist namelist_cfg nn_it000 1
+    set_namelist namelist_cfg nn_itend 150
+    set_namelist namelist_cfg nn_stock 75
+    set_namelist namelist_cfg ln_clobber .true.
+    set_namelist namelist_cfg nn_fwb 0
+    set_namelist namelist_cfg jpni 2
+    set_namelist namelist_cfg jpnj 2
+    set_namelist namelist_cfg jpnij 4
+    set_namelist namelist_cfg nn_solv 2
+    if [ ${USING_MPMD} == "yes" ] ; then
+       set_xio_using_server iodef.xml true
+    else
+       set_xio_using_server iodef.xml false
+    fi
+    cd ${SETTE_DIR}
+    . ./prepare_job.sh input_ORCA2_LIM3.cfg $NPROC ${TEST_NAME} ${MPIRUN_FLAG} ${JOB_FILE} ${NUM_XIOSERVERS}
+    
+    cd ${SETTE_DIR}
+    export TEST_NAME="SHORT"
+    . ./prepare_exe_dir.sh
+    cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"O2L3_SHORT\"
+    set_namelist namelist_cfg nn_it000 76
+    set_namelist namelist_cfg nn_itend 150
+    set_namelist namelist_cfg nn_stock 75
+    set_namelist namelist_cfg ln_rstart .true.
+    set_namelist namelist_cfg nn_rstctl 2
+    set_namelist namelist_cfg ln_clobber .true.
+    set_namelist namelist_cfg nn_fwb 0
+    set_namelist namelist_cfg jpni 2
+    set_namelist namelist_cfg jpnj 2
+    set_namelist namelist_cfg jpnij 4
+    set_namelist namelist_cfg nn_solv 2
+    set_namelist namelist_cfg cn_ocerst_in \"O2L3_LONG_00000075_restart\"
+    set_namelist namelist_ice_cfg cn_icerst_in \"O2L3_LONG_00000075_restart_ice\"
+    for (( i=1; i<=$NPROC; i++)) ; do
+        L_NPROC=$(( $i - 1 ))
+        L_NPROC=`printf "%04d\n" ${L_NPROC}`
+        ln -sf ../LONG/O2L3_LONG_00000075_restart_${L_NPROC}.nc .
+        ln -sf ../LONG/O2L3_LONG_00000075_restart_ice_${L_NPROC}.nc .
+    done
+    if [ ${USING_MPMD} == "yes" ] ; then
+       set_xio_using_server iodef.xml true
+    else
+       set_xio_using_server iodef.xml false
+    fi
+    cd ${SETTE_DIR}
+    . ./prepare_job.sh input_ORCA2_LIM3.cfg $NPROC ${TEST_NAME} ${MPIRUN_FLAG} ${JOB_FILE} ${NUM_XIOSERVERS}
+    cd ${SETTE_DIR}
+    . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
+fi
+
+if [ ${config} -eq 8 ] ;  then
+    ## Reproducibility tests for ORCA2_LIM3
+    export TEST_NAME="REPRO_4_4"
+    cd ${CONFIG_DIR}
+    . ./makenemo -m ${CMP_NAM} -n ORCA2LIM3_16 -r ORCA2_LIM3 -j 8 add_key "key_mpp_rep" del_key ${DEL_KEYS}
+    cd ${SETTE_DIR}
+    . ./param.cfg
+    . ./all_functions.sh
+    . ./prepare_exe_dir.sh
+    JOB_FILE=${EXE_DIR}/run_job.sh
+    NPROC=16
+    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
+    cd ${EXE_DIR}
+    set_namelist namelist_cfg nn_it000 1
+    set_namelist namelist_cfg nn_itend 75
+    set_namelist namelist_cfg nn_fwb 0
+    set_namelist namelist_cfg ln_ctl .false.
+    set_namelist namelist_cfg ln_clobber .true.
+    set_namelist namelist_cfg jpni 4
+    set_namelist namelist_cfg jpnj 4
+    set_namelist namelist_cfg jpnij 16
+    set_namelist namelist_cfg nn_solv 2
+    if [ ${USING_MPMD} == "yes" ] ; then
+       set_xio_using_server iodef.xml true
+    else
+       set_xio_using_server iodef.xml false
+    fi
+    cd ${SETTE_DIR}
+    . ./prepare_job.sh input_ORCA2_LIM3.cfg $NPROC ${TEST_NAME} ${MPIRUN_FLAG} ${JOB_FILE} ${NUM_XIOSERVERS}
+    cd ${SETTE_DIR}
+    . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
+
+    cd ${SETTE_DIR}
+    export TEST_NAME="REPRO_2_8"
+    . ./prepare_exe_dir.sh
+    JOB_FILE=${EXE_DIR}/run_job.sh
+    NPROC=16
+    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
+    cd ${EXE_DIR}
+    set_namelist namelist_cfg nn_it000 1
+    set_namelist namelist_cfg nn_itend 75
+    set_namelist namelist_cfg ln_clobber .true.
+    set_namelist namelist_cfg nn_fwb 0
+    set_namelist namelist_cfg jpni 2
+    set_namelist namelist_cfg jpnj 8
+    set_namelist namelist_cfg jpnij 16
+    set_namelist namelist_cfg nn_solv 2
+    if [ ${USING_MPMD} == "yes" ] ; then
+       set_xio_using_server iodef.xml true
+    else
+       set_xio_using_server iodef.xml false
+    fi
+
+    cd ${SETTE_DIR}
+    . ./prepare_job.sh input_ORCA2_LIM3.cfg $NPROC ${TEST_NAME} ${MPIRUN_FLAG} ${JOB_FILE} ${NUM_XIOSERVERS}
+    cd ${SETTE_DIR}
+    . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
+fi
+
+
 # TESTS FOR AMM12 CONFIGURATION
-if [ ${config} -eq 7 ] ;  then
+if [ ${config} -eq 9 ] ;  then
     ## Restartability tests for AMM12
     export TEST_NAME="LONG"
@@ -692,5 +821,5 @@
 fi
 
-if [ ${config} -eq 8 ] ;  then
+if [ ${config} -eq 10 ] ;  then
 ## Reproducibility tests for AMM12
     export TEST_NAME="REPRO_8_4"
@@ -748,5 +877,5 @@
 
 # TESTS FOR ORCA2_SAS_LIM CONFIGURATION
-if [ ${config} -eq 9 ] ;  then
+if [ ${config} -eq 11 ] ;  then
     ## Restartability tests for SAS
     export TEST_NAME="LONG"
@@ -810,5 +939,5 @@
 fi
 
-if [ ${config} -eq 10 ] ;  then
+if [ ${config} -eq 12 ] ;  then
 ## Reproducibility tests for ORCA2_SAS_LIM
     export TEST_NAME="REPRO_8_4"
@@ -866,5 +995,5 @@
 
 # TEST FOR ORCA2_LIM_AGRIF : simple test of running AGRIF (no restartability neither reproducibility tests)
-if [ ${config} -eq 11 ] ;  then
+if [ ${config} -eq 13 ] ;  then
     ## ORCA2_LIM with Agulhas AGRIF zoom in MPI
     export TEST_NAME="SHORT"
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/sette_beginner.sh
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/sette_beginner.sh	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/sette_beginner.sh	(revision 4921)
@@ -4,5 +4,5 @@
 # Contact : sflod@locean-ipsl.upmc.fr
 #
-# sette.sh   : principal script of SET TEsts for NEMO (SETTE)
+# sette_beginner.sh   : example of script of SET TEsts for NEMO (SETTE)
 # ----------------------------------------------------------------------
 # NEMO/SETTE , NEMO Consortium (2010)
@@ -21,26 +21,102 @@
 # ===================
 #
-# ----------------------------------------------
-# Set of tests for NEMO for beginners
-# ----------------------------------------------
+# COMPILER          : name of compiler as defined in NEMOGCM/ARCH directory 
+# BATCH_COMMAND_PAR :  name of the command for submitting parallel batch jobs
+# BATCH_COMMAND_SEQ :  name of the command for submitting sequential batch jobs  
+# INTERACT_FLAG     : flag to run in interactive mode "yes"
+#                           to run in batch mode "no"
+# MPIRUN_FLAG       : flag to run in parallel (MPI) "yes"
+#                           to run in sequential mode (NB_PROC = 1) "no"
+# USING_XIOS        : flag to control the activation of key_iomput
+#                      "yes" to compile using key_iomput and link to the external XIOS library
+#                      "no"  to compile without key_iomput and link to the old IOIPSL library
+# USING_MPMD        : flag to control the use of stand-alone IO servers
+#                     requires USING_XIOS="yes"
+#                      "yes" to run in MPMD (detached) mode with stand-alone IO servers
+#                      "no"  to run in SPMD (attached) mode without separate IO servers 
+# NUM_XIOSERVERS    : number of stand-alone IO servers to employ
+#                     set to zero if USING_MPMD="no"
 #
-# SYNOPSIS
-# ========
+# Principal script is sette.sh, that calls 
 #
-# ::
+#  makenemo  : to create successive exectuables in ${CONFIG_NAME}/BLD/bin/nemo.exe 
+#              and links to opa in ${CONFIG_NAME}/EXP00)
 #
-#  $ ./sette_beginner.sh
+#  param.cfg : sets and loads following directories:
 #
-# DESCRIPTION
-# ===========
-# First simple example of how to use SETTE: create GYRE_SHORT configuration, compile it with 1 proc, and test it for a SHORT test: 5days
-#-
+#   FORCING_DIR         : is the directory for forcing files (tarfile)
+#   INPUT_DIR           : is the directory for input files storing 
+#   TMPDIR              : is the temporary directory (if needed)
+#   NEMO_VALIDATION_DIR : is the validation directory
+#
+#   (NOTE: this file is the same for all configrations to be tested with sette)
+#
+#   all_functions.sh : loads functions used by sette (note: new functions can be added here)
+#   set_namelist     : function declared in all_functions that sets namelist parameters 
+#   post_test_tidyup : creates validation storage directory and copies required output files 
+#                      (solver.stat and ocean.output) in it after execution of test.
+#
+#  VALIDATION tree is:
+#
+#   NEMO_VALIDATION_DIR/WCONFIG_NAME/WCOMPILER_NAME/TEST_NAME/REVISION_NUMBER(or DATE)
+#
+#  prepare_exe_dir.sh : defines and creates directory where the test is executed
+#                       execution directory takes name of TEST_NAME defined for every test 
+#                       in sette.sh. (each test in executed in its own directory)
+#
+#  prepare_job.sh     : to generate the script run_job.sh
+#
+#  fcm_job.sh         : run in batch (INTERACT_FLAG="no") or interactive (INTERACT_FLAG="yes")
+#                        see sette.sh and BATCH_TEMPLATE directory
+#
+#  NOTE: jobs requiring initial or forcing data need to have an input_CONFIG.cfg in which 
+#        can be found paths to the input tar file)
+#  NOTE: if job is not launched for any reason you have the executable ready in ${EXE_DIR} 
+#        directory
+#  NOTE: the changed namelists are left in ${EXE_DIR} directory whereas original namelists 
+#        remain in ${NEW_CONF}/EXP00
+# 
+#  NOTE: a log file, output.sette, is created in ${SETTE_DIR} with the echoes of 
+#        executed commands
+#
+#  NOTE: if sette.sh is stopped in output.sette there is written the last command 
+#        executed by sette.sh
+#
+# example use: ./sette_beginner.sh 
+#########################################################################################
 #
 # Compiler among those in NEMOGCM/ARCH
-COMPILER=macport_osx
+COMPILER=x3750_ADA
 export BATCH_COMMAND_PAR="llsubmit"
 export BATCH_COMMAND_SEQ=$BATCH_COMMAND_PAR
 export INTERACT_FLAG="yes"
 export MPIRUN_FLAG="yes"
+
+export DEL_KEYS="key_iomput"
+if [ ${USING_XIOS} == "yes" ]
+ then 
+   export DEL_KEYS=""
+fi
+
+#
+# Settings which control the use of stand alone servers (only relevant if using xios)
+#
+export USING_MPMD="no"
+export NUM_XIOSERVERS=4
+export JOB_PREFIX=batch-mpmd
+#
+if [ ${USING_MPMD} == "no" ] 
+ then
+   export NUM_XIOSERVERS=0
+   export JOB_PREFIX=batch
+fi
+#
+#
+if [ ${USING_MPMD} == "yes" ] && [ ${USING_XIOS} == "no"]
+ then
+   echo "Incompatible choices. MPMD mode requires the XIOS server"
+   exit
+fi
+#
 
 # Directory to run the tests
@@ -54,7 +130,5 @@
 # Copy job_batch_COMPILER file for specific compiler into job_batch_template
 cd ${SETTE_DIR}
-##if [ ${INTERACT_FLAG} == no ] ;  then
-    cp BATCH_TEMPLATE/batch-${COMPILER} job_batch_template || exit
-##fi 
+cp BATCH_TEMPLATE/batch-${COMPILER} job_batch_template || exit
 
 # Run for GYRE CONFIG
@@ -63,13 +137,14 @@
 export TEST_NAME="SHORT_TEST"
 cd ${CONFIG_DIR}
-. ./makenemo -m ${CMP_NAM} -n GYRE_SHORT -r GYRE -j 10 add_key "key_mpp_mpi key_nosignedzero"
+. ./makenemo -m ${CMP_NAM} -n GYRE_SHORT -r GYRE -j 10 add_key "key_nosignedzero" del_key ${DEL_KEYS}
 cd ${SETTE_DIR}
-. param.cfg 
-. all_functions.sh
+. ./param.cfg 
+. ./all_functions.sh
+. ./prepare_exe_dir.sh
 # creation of execution directory
-. prepare_exe_dir.sh
 JOB_FILE=${EXE_DIR}/run_job.sh
+# setting number of procs used
 NPROC=4
-\rm $JOB_FILE
+if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
 cd ${EXE_DIR}
 # setting namelist parameters
@@ -82,7 +157,11 @@
 # frequency of creation of a restart file
 set_namelist namelist_cfg nn_stock 60
-
+if [ ${USING_MPMD} == "yes" ] ; then
+      set_xio_using_server iodef.xml true
+   else
+      set_xio_using_server iodef.xml false
+fi
 cd ${SETTE_DIR}
-. ./prepare_job.sh input_GYRE.cfg $NPROC ${TEST_NAME} ${MPIRUN_FLAG} ${JOB_FILE}
+. ./prepare_job.sh input_GYRE.cfg $NPROC ${TEST_NAME} ${MPIRUN_FLAG} ${JOB_FILE} ${NUM_XIOSERVERS}
 # run job, with 4 processors, test named SHORT (= 60 time steps)
 cd ${SETTE_DIR}   
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/sette_rpt
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/sette_rpt	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/sette_rpt	(revision 4921)
@@ -17,9 +17,6 @@
   cd $NEMO_VALID
 #
-# The script also needs the date or revision tag. Currently this is taken from the latest sub-directory
-# found in the WGYRE_LONG directory
-#
-  set dorv = `ls -1rtd ./WGYRE_LONG/{$mach}/* | tail -1l `
-  set dorv = $dorv:t
+# The script also needs the date or revision tag. Currently this is taken from the latest sub-directory found in each directory
+#
 #
 # Now loop through all the test directories. On the second pass the user can optionally examine any mismatched
@@ -30,4 +27,6 @@
 foreach pass (0 1 )
   if ( -d ./WGYRE_LONG ) then
+    set dorv = `ls -1rtd ./WGYRE_LONG/{$mach}/* | tail -1l `
+    set dorv = $dorv:t
     set f1o = ./WGYRE_LONG/{$mach}/{$dorv}/LONG/ocean.output
     set f1s = ./WGYRE_LONG/{$mach}/{$dorv}/LONG/solver.stat
@@ -39,7 +38,7 @@
     cmp -s f1.tmp$$ $f2s
     if ( $status == 0 ) then
-      echo "GYRE     restartability  passed"
-    else
-      echo "GYRE     restartability  FAILED"
+      echo "GYRE        restartability  passed"
+    else
+      echo "GYRE        restartability  FAILED"
       if ( $pass == 1 ) then
         echo "<return> to view solver.stat differences"
@@ -57,4 +56,6 @@
   
   if ( -d ./WORCA2LIMPIS_LONG ) then
+    set dorv = `ls -1rtd ./WORCA2LIMPIS_LONG/{$mach}/* | tail -1l `
+    set dorv = $dorv:t
     set f1o = ./WORCA2LIMPIS_LONG/{$mach}/{$dorv}/LONG/ocean.output
     set f1s = ./WORCA2LIMPIS_LONG/{$mach}/{$dorv}/LONG/solver.stat
@@ -84,4 +85,6 @@
 
   if ( -d ./WORCA2OFFPIS_LONG ) then
+    set dorv = `ls -1rtd ./WORCA2OFFPIS_LONG/{$mach}/* | tail -1l `
+    set dorv = $dorv:t
     set f1o = ./WORCA2OFFPIS_LONG/{$mach}/{$dorv}/LONG/ocean.output
     set f1s = ./WORCA2OFFPIS_LONG/{$mach}/{$dorv}/LONG/tracer.stat
@@ -111,4 +114,6 @@
   
   if ( -d ./WAMM12_LONG ) then
+    set dorv = `ls -1rtd ./WAMM12_LONG/{$mach}/* | tail -1l `
+    set dorv = $dorv:t
     set f1o = ./WAMM12_LONG/{$mach}/{$dorv}/LONG/ocean.output
     set f1s = ./WAMM12_LONG/{$mach}/{$dorv}/LONG/solver.stat
@@ -136,8 +141,47 @@
     rm f1.tmp$$
   endif
-
+NEXT0:
+  if ( -d ./WSAS_LONG ) then
+    set dorv = `ls -1rtd ./WSAS_LONG/{$mach}/* | tail -1l `
+    set dorv = $dorv:t
+    set f1o = ./WSAS_LONG/{$mach}/{$dorv}/LONG/ocean.output
+    set f1s = ./WSAS_LONG/{$mach}/{$dorv}/LONG/solver.stat
+    set f2o = ./WSAS_LONG/{$mach}/{$dorv}/SHORT/ocean.output
+    set f2s = ./WSAS_LONG/{$mach}/{$dorv}/SHORT/solver.stat
+
+    foreach f ( $f1o $f1s $f2o $f2s )
+     if ( ! -f $f ) then
+      echo 'SAS         restartability  inconclusive ( ' $f:t ' not found )'
+      goto NEXT
+     endif
+    end
+
+    set nl = `wc -l $f2s`
+    tail -$nl[1] $f1s > f1.tmp$$
+    cmp -s f1.tmp$$ $f2s
+    if ( $status == 0 ) then
+      echo "SAS         restartability  passed"
+    else
+      echo "SAS         restartability  FAILED"
+      if ( $pass == 1 ) then
+        echo "<return> to view solver.stat differences"
+        set y = $<
+        sdiff f1.tmp$$ $f2s
+        echo "<return> to view ocean.output differences"
+        set y = $<
+        sdiff $f1o $f2o | grep "|"
+        echo "<return> to continue"
+        set y = $<
+      endif
+    endif
+    rm f1.tmp$$
+  endif
+
+NEXT:
 echo
   
   if ( -d ./WGYRE_4 ) then
+    set dorv = `ls -1rtd ./WGYRE_4/{$mach}/* | tail -1l `
+    set dorv = $dorv:t
     set f1o = ./WGYRE_4/{$mach}/{$dorv}/REPRO_1_4/ocean.output
     set f1s = ./WGYRE_4/{$mach}/{$dorv}/REPRO_1_4/solver.stat
@@ -147,7 +191,7 @@
     cmp -s $f1s $f2s
     if ( $status == 0 ) then
-      echo "GYRE     reproducibility passed"
-    else
-      echo "GYRE     reproducibility FAILED"
+      echo "GYRE        reproducibility passed"
+    else
+      echo "GYRE        reproducibility FAILED"
       if ( $pass == 1 ) then
         echo "<return> to view solver.stat differences"
@@ -164,4 +208,6 @@
   
   if ( -d ./WORCA2LIMPIS_16 ) then
+    set dorv = `ls -1rtd ./WORCA2LIMPIS_16/{$mach}/* | tail -1l `
+    set dorv = $dorv:t
     set f1o = ./WORCA2LIMPIS_16/{$mach}/{$dorv}/REPRO_2_8/ocean.output
     set f1s = ./WORCA2LIMPIS_16/{$mach}/{$dorv}/REPRO_2_8/solver.stat
@@ -188,4 +234,6 @@
 
   if ( -d ./WORCA2OFFPIS_16 ) then
+    set dorv = `ls -1rtd ./WORCA2OFFPIS_16/{$mach}/* | tail -1l `
+    set dorv = $dorv:t
     set f1o = ./WORCA2OFFPIS_16/{$mach}/{$dorv}/REPRO_2_8/ocean.output
     set f1s = ./WORCA2OFFPIS_16/{$mach}/{$dorv}/REPRO_2_8/tracer.stat
@@ -212,4 +260,6 @@
   
   if ( -d ./WAMM12_32 ) then
+    set dorv = `ls -1rtd ./WAMM12_32/{$mach}/* | tail -1l `
+    set dorv = $dorv:t
     set f1o = ./WAMM12_32/{$mach}/{$dorv}/REPRO_4_8/ocean.output
     set f1s = ./WAMM12_32/{$mach}/{$dorv}/REPRO_4_8/solver.stat
@@ -235,5 +285,41 @@
   endif
 
+  if ( -d ./WSAS_32 ) then
+    set dorv = `ls -1rtd ./WSAS_32/{$mach}/* | tail -1l `
+    set dorv = $dorv:t
+    set f1o = ./WSAS_32/{$mach}/{$dorv}/REPRO_4_8/ocean.output
+    set f1s = ./WSAS_32/{$mach}/{$dorv}/REPRO_4_8/solver.stat
+    set f2o = ./WSAS_32/{$mach}/{$dorv}/REPRO_8_4/ocean.output
+    set f2s = ./WSAS_32/{$mach}/{$dorv}/REPRO_8_4/solver.stat
+
+    foreach f ( $f1o $f1s $f2o $f2s )
+     if ( ! -f $f ) then
+      echo 'SAS         reproducibility inconclusive ( ' $f:t ' not found )'
+      goto NEXT1
+     endif
+    end
+
+    cmp -s $f1s $f2s
+    if ( $status == 0 ) then
+      echo "SAS reproducibility passed"
+    else
+      echo "SAS reproducibility FAILED"
+      if ( $pass == 1 ) then
+        echo "<return> to view solver.stat differences"
+        set y = $<
+        sdiff $f1s $f2s
+        echo "<return> to view ocean.output differences"
+        set y = $<
+        sdiff $f1o $f2o | grep "|"
+        echo "<return> to continue"
+        set y = $<
+      endif
+    endif
+  endif
+NEXT1:
+
   if ( -d ./WORCA2AGUL_1_2 ) then
+    set dorv = `ls -1rtd ./WORCA2AGUL_1_2/{$mach}/* | tail -1l `
+    set dorv = $dorv:t
     set f1o = ./WORCA2AGUL_1_2/{$mach}/{$dorv}/SHORT/ocean.output
     set f1s = ./WORCA2AGUL_1_2/{$mach}/{$dorv}/SHORT/solver.stat
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/sette_xios.sh
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/sette_xios.sh	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/SETTE/sette_xios.sh	(revision 4921)
@@ -1,11 +1,11 @@
 #!/bin/bash
 ############################################################
-# Author : Simona Flavoni for NEMO
-# Contact: sflod@locean-ipsl.upmc.fr
-# 2013   : A.C. Coward added options for testing with XIOS in dettached mode
-#
-# sette.sh   : principal script of SET TEsts for NEMO (SETTE)
+# Author : Italo Epicoco - CMCC
+# Contact: italo.epicoco@unisalento.it
+# 2014   : A.C. Coward added new namelist settings for GYRE configuration
+#
+# sette_xios.sh   : additional script of SET TEsts for XIOS within NEMO
 # ----------------------------------------------------------------------
-# NEMO/SETTE , NEMO Consortium (2010)
+# NEMO/SETTE , NEMO Consortium (2014)
 # Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
 # ----------------------------------------------------------------------
@@ -29,15 +29,11 @@
 # MPIRUN_FLAG       : flag to run in parallel (MPI) "yes"
 #                           to run in sequential mode (NB_PROC = 1) "no"
-# USING_XIOS        : flag to control the activation of key_iomput
-#                      "yes" to compile using key_iomput and link to the external XIOS library
-#                      "no"  to compile without key_iomput and link to the old IOIPSL library
 # USING_MPMD        : flag to control the use of stand-alone IO servers
-#                     requires USING_XIOS="yes"
-#                      "yes" to run in MPMD (detached) mode with stand-alone IO servers
-#                      "no"  to run in SPMD (attached) mode without separate IO servers 
+#                      "true" to run in MPMD (detached) mode with stand-alone IO servers
+#                      "false"  to run in SPMD (attached) mode without separate IO servers 
 # NUM_XIOSERVERS    : number of stand-alone IO servers to employ
-#                     set to zero if USING_MPMD="no"
-#
-# Principal script is sette.sh, that calls 
+#                     set to zero if USING_MPMD="false"
+#
+# Principal script is sette_xios.sh, that calls 
 #
 #  makenemo  : to create successive exectuables in ${CONFIG_NAME}/BLD/bin/nemo.exe 
@@ -81,8 +77,8 @@
 #        executed commands
 #
-#  NOTE: if sette.sh is stopped in output.sette there is written the last command 
-#        executed by sette.sh
-#
-# example use: ./sette.sh 
+#  NOTE: if sette_xios.sh is stopped in output.sette there is written the last command 
+#        executed by sette_xios.sh
+#
+# example use: ./sette_xios.sh 
 #########################################################################################
 #
@@ -103,17 +99,31 @@
 
 CMP_NAM=${1:-$COMPILER}
+#
+#=================================================================================
 # Copy job_batch_COMPILER file for specific compiler into job_batch_template
+# Note this batch template needs to be capable of launching both SPMD and MPMD
+# tasks with internal selection depending on the value of NUM_XIOSERVERS
+# (0=SPMD; >0 = MPMD)
+#=================================================================================
+#
 cd ${SETTE_DIR}
 cp BATCH_TEMPLATE/batch-${COMPILER} job_batch_template || exit
 
-for config in 2  
+for config in 1 2  
 
 do
 
-# TESTS FOR GYRE CONFIGURATION
+#==========================================================
+# TESTS FOR XIOS USING GYRE CONFIGURATION AT LOW RESOLUTION
+#==========================================================
+
 if [ ${config} -eq 1 ] ;  then
-    ## Restartability tests for GYRE
+    ## Test of XIOS configured in attached mode with multiple output files (one for each process). 
+    ## $NPROC processes are used 
 
     NPROC=4
+    jp_cfg=1
+    jpni=2
+    jpnj=2
     export NUM_XIOSERVERS=0
     export USING_MPMD="false"
@@ -124,7 +134,7 @@
     . ../CONFIG/makenemo -m ${CMP_NAM} -n GYRE_XIOS_LR -r GYRE_XIOS -j 8 
     cd ${SETTE_DIR}
-    . param.cfg
-    . all_functions.sh
-    . prepare_exe_dir.sh
+    . ./param.cfg
+    . ./all_functions.sh
+    . ./prepare_exe_dir.sh
     JOB_FILE=${EXE_DIR}/run_job.sh
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
@@ -133,9 +143,13 @@
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 120
-    set_namelist namelist_cfg nn_stock 60
-    set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg jp_cfg 1
-    set_namelist namelist_cfg jpni 2
-    set_namelist namelist_cfg jpnj 2
+    set_namelist namelist_cfg nn_stock 120
+    set_namelist namelist_cfg ln_clobber .true.
+    set_namelist namelist_cfg jp_cfg $jp_cfg
+    set_namelist namelist_cfg jpidta $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjdta $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpiglo $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjglo $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpni $jpni
+    set_namelist namelist_cfg jpnj $jpnj
     set_namelist namelist_cfg jpnij $NPROC
 
@@ -149,4 +163,6 @@
     . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
 
+
+    ## Test of XIOS configured in attached mode with a single output file. 
 
     export TEST_NAME="ATTACHED_ONE"
@@ -154,5 +170,5 @@
     export USING_MPMD="false"
     cd ${SETTE_DIR} 
-    . prepare_exe_dir.sh
+    . ./prepare_exe_dir.sh
     JOB_FILE=${EXE_DIR}/run_job.sh
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
@@ -161,9 +177,13 @@
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 120
-    set_namelist namelist_cfg nn_stock 60
-    set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg jp_cfg 1
-    set_namelist namelist_cfg jpni 2
-    set_namelist namelist_cfg jpnj 2
+    set_namelist namelist_cfg nn_stock 120
+    set_namelist namelist_cfg ln_clobber .true.
+    set_namelist namelist_cfg jp_cfg $jp_cfg
+    set_namelist namelist_cfg jpidta $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjdta $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpiglo $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjglo $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpni $jpni
+    set_namelist namelist_cfg jpnj $jpnj
     set_namelist namelist_cfg jpnij $NPROC
 
@@ -177,4 +197,8 @@
     . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
 
+
+    ## Test of XIOS configured in detached mode with a single output file. 
+    ## $NUM_XIOSERVERS IO server are used.
+    ## the total number of allocated cores is $NUM_XIOSERVERS + $NPROC 
 
     export TEST_NAME="DETACHED_ONE"
@@ -182,5 +206,6 @@
     export USING_MPMD="true"
     cd ${SETTE_DIR}
-    . prepare_exe_dir.sh
+#
+    . ./prepare_exe_dir.sh
     JOB_FILE=${EXE_DIR}/run_job.sh
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
@@ -189,9 +214,13 @@
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 120
-    set_namelist namelist_cfg nn_stock 60
-    set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg jp_cfg 1
-    set_namelist namelist_cfg jpni 2
-    set_namelist namelist_cfg jpnj 2
+    set_namelist namelist_cfg nn_stock 120
+    set_namelist namelist_cfg ln_clobber .true.
+    set_namelist namelist_cfg jp_cfg $jp_cfg
+    set_namelist namelist_cfg jpidta $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjdta $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpiglo $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjglo $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpni $jpni
+    set_namelist namelist_cfg jpnj $jpnj
     set_namelist namelist_cfg jpnij $NPROC
 
@@ -204,4 +233,9 @@
     cd ${SETTE_DIR}
     . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
+
+    ## Test of XIOS configured in detached mode with multiple output files (one for each IO server). 
+    ## $NUM_XIOSERVERS IO server are used.
+    ## the total number of allocated cores is $NUM_XIOSERVERS + $NPROC 
+
 
     export TEST_NAME="DETACHED_MULTIPLE"
@@ -209,5 +243,5 @@
     export USING_MPMD="true"
     cd ${SETTE_DIR}
-    . prepare_exe_dir.sh
+    . ./prepare_exe_dir.sh
     JOB_FILE=${EXE_DIR}/run_job.sh
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
@@ -216,9 +250,13 @@
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 120
-    set_namelist namelist_cfg nn_stock 60
-    set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg jp_cfg 1
-    set_namelist namelist_cfg jpni 2
-    set_namelist namelist_cfg jpnj 2
+    set_namelist namelist_cfg nn_stock 120
+    set_namelist namelist_cfg ln_clobber .true.
+    set_namelist namelist_cfg jp_cfg $jp_cfg
+    set_namelist namelist_cfg jpidta $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjdta $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpiglo $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjglo $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpni $jpni
+    set_namelist namelist_cfg jpnj $jpnj
     set_namelist namelist_cfg jpnij $NPROC
 
@@ -234,8 +272,16 @@
 fi
 
+#==========================================================
+# TESTS FOR XIOS USING GYRE CONFIGURATION AT HIGH RESOLUTION
+#==========================================================
+
 if [ ${config} -eq 2 ] ;  then
-    ## Restartability tests for GYRE
-
-    NPROC=152
+    ## Test of XIOS configured in attached mode with multiple output files (one for each process). 
+    ## $NPROC processes are used 
+
+    NPROC=64
+    jp_cfg=30
+    jpni=8
+    jpnj=8
     export NUM_XIOSERVERS=0
     export USING_MPMD="false"
@@ -246,7 +292,9 @@
     . ../CONFIG/makenemo -m ${CMP_NAM} -n GYRE_XIOS_HR -r GYRE_XIOS -j 8
     cd ${SETTE_DIR}
-    . param.cfg
-    . all_functions.sh
-    . prepare_exe_dir.sh
+#
+    . ./param.cfg
+    . ./all_functions.sh
+    . ./prepare_exe_dir.sh
+#
     JOB_FILE=${EXE_DIR}/run_job.sh
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
@@ -258,7 +306,11 @@
     set_namelist namelist_cfg nn_bench 1
     set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg jp_cfg 144
-    set_namelist namelist_cfg jpni 19
-    set_namelist namelist_cfg jpnj 8
+    set_namelist namelist_cfg jp_cfg $jp_cfg
+    set_namelist namelist_cfg jpidta $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjdta $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpiglo $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjglo $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpni $jpni
+    set_namelist namelist_cfg jpnj $jpnj
     set_namelist namelist_cfg jpnij $NPROC
 
@@ -273,4 +325,5 @@
 
 
+    ## Test of XIOS configured in attached mode with a single output file. 
 
     export TEST_NAME="ATTACHED_ONE"
@@ -278,5 +331,7 @@
     export USING_MPMD="false"
     cd ${SETTE_DIR}
-    . prepare_exe_dir.sh
+#
+    . ./prepare_exe_dir.sh
+#
     JOB_FILE=${EXE_DIR}/run_job.sh
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
@@ -288,7 +343,11 @@
     set_namelist namelist_cfg nn_bench 1
     set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg jp_cfg 144
-    set_namelist namelist_cfg jpni 19
-    set_namelist namelist_cfg jpnj 8
+    set_namelist namelist_cfg jp_cfg $jp_cfg
+    set_namelist namelist_cfg jpidta $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjdta $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpiglo $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjglo $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpni $jpni
+    set_namelist namelist_cfg jpnj $jpnj
     set_namelist namelist_cfg jpnij $NPROC
 
@@ -301,4 +360,9 @@
     cd ${SETTE_DIR}
     . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
+
+
+    ## Test of XIOS configured in detached mode with a single output file. 
+    ## $NUM_XIOSERVERS IO server are used.
+    ## the total number of allocated cores is $NUM_XIOSERVERS + $NPROC 
 
     export TEST_NAME="DETACHED_ONE"
@@ -306,5 +370,7 @@
     export USING_MPMD="true"
     cd ${SETTE_DIR}
-    . prepare_exe_dir.sh
+#
+    . ./prepare_exe_dir.sh
+#
     JOB_FILE=${EXE_DIR}/run_job.sh
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
@@ -316,7 +382,11 @@
     set_namelist namelist_cfg nn_bench 1
     set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg jp_cfg 144
-    set_namelist namelist_cfg jpni 19
-    set_namelist namelist_cfg jpnj 8
+    set_namelist namelist_cfg jp_cfg $jp_cfg
+    set_namelist namelist_cfg jpidta $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjdta $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpiglo $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjglo $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpni $jpni
+    set_namelist namelist_cfg jpnj $jpnj
     set_namelist namelist_cfg jpnij $NPROC
 
@@ -329,4 +399,8 @@
     cd ${SETTE_DIR}
     . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
+
+    ## Test of XIOS configured in detached mode with multiple output files (one for each IO server). 
+    ## $NUM_XIOSERVERS IO server are used.
+    ## the total number of allocated cores is $NUM_XIOSERVERS + $NPROC 
 
     export TEST_NAME="DETACHED_MULTIPLE"
@@ -334,5 +408,5 @@
     export USING_MPMD="true"
     cd ${SETTE_DIR}
-    . prepare_exe_dir.sh
+    . ./prepare_exe_dir.sh
     JOB_FILE=${EXE_DIR}/run_job.sh
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
@@ -344,7 +418,11 @@
     set_namelist namelist_cfg nn_bench 1
     set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg jp_cfg 144
-    set_namelist namelist_cfg jpni 19
-    set_namelist namelist_cfg jpnj 8
+    set_namelist namelist_cfg jp_cfg $jp_cfg
+    set_namelist namelist_cfg jpidta $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjdta $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpiglo $(( $jp_cfg * 30 + 2 ))
+    set_namelist namelist_cfg jpjglo $(( $jp_cfg * 20 + 2 ))
+    set_namelist namelist_cfg jpni $jpni
+    set_namelist namelist_cfg jpnj $jpnj
     set_namelist namelist_cfg jpnij $NPROC
 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/TOOLS/COMPILE/bld.cfg
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/TOOLS/COMPILE/bld.cfg	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/TOOLS/COMPILE/bld.cfg	(revision 4921)
@@ -24,4 +24,6 @@
 
 
+bld::tool::cpp       %CPP
+bld::tool::fpp       %CPP
 bld::tool::fc        %FC 
 bld::tool::fflags    %FCFLAGS %USER_INC
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/TOOLS/COMPILE/bld_preproagr.cfg
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/TOOLS/COMPILE/bld_preproagr.cfg	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/TOOLS/COMPILE/bld_preproagr.cfg	(revision 4921)
@@ -34,5 +34,6 @@
 bld::pp::nemo     1
 bld::pp::nemo/agrif2model     0
-bld::tool::fpp       cpp
+bld::tool::cpp       %CPP
+bld::tool::fpp       %CPP
 bld::tool::fppflags::nemo  %FPPFLAGS
 
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/TOOLS/COMPILE/bld_tools.cfg
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/TOOLS/COMPILE/bld_tools.cfg	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/TOOLS/COMPILE/bld_tools.cfg	(revision 4921)
@@ -16,4 +16,6 @@
 dir::root            $NEMO_TDIR/$NEW_CONF/BLD
 
+bld::tool::cpp       %CPP
+bld::tool::fpp       %CPP
 bld::tool::fc        %FC 
 bld::tool::fflags    %FCFLAGS %USER_INC
Index: /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/TOOLS/COMPILE/bldxag.cfg
===================================================================
--- /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/TOOLS/COMPILE/bldxag.cfg	(revision 4920)
+++ /branches/2014/dev_r4650_UKMO13_CICE_changes_take2/NEMOGCM/TOOLS/COMPILE/bldxag.cfg	(revision 4921)
@@ -23,4 +23,6 @@
 
 
+bld::tool::cpp       %CPP
+bld::tool::fpp       %CPP
 bld::tool::fc        %FC 
 bld::tool::fflags    %FCFLAGS %USER_INC
