Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/dom_ice.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/dom_ice.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/dom_ice.F90	(revision 884)
@@ -0,0 +1,46 @@
+MODULE dom_ice
+   !!======================================================================
+   !!                   ***  MODULE  dom_ice  ***
+   !! LIM Sea Ice :   Domain  variables
+   !!======================================================================
+   !! History :
+   !!   2.0  !  03-08  (C. Ethe)  Free form and module
+   !!   3.0  !  03-08  (M. Vancoppenolle), Ice cats, salinity and EVP-C
+   !!----------------------------------------------------------------------
+   !!   LIM 3.0, UCL-ASTR-LOCEAN-IPSL (2005)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/dom_ice.F90,v 1.4 2005/03/27 18:34:40 opalod Exp $
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_ice
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Share module variables
+   LOGICAL, PUBLIC ::   &  !:
+      l_jeq = .TRUE.       !: Equator inside the domain flag
+
+   INTEGER, PUBLIC ::   &  !:
+      njeq , njeqm1        !: j-index of the equator if it is inside the domain
+      !                    !  (otherwise = jpj+10 (SH) or -10 (SH) )
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      fs2cor ,          &  !: coriolis factor
+      fcor   ,          &  !: coriolis coefficient
+      covrai ,          &  !: sine of geographic latitude
+      area   ,          &  !: surface of grid cell 
+      tms , tmi ,       &  !: temperature mask, mask for stress
+      tmu , tmv ,       &  !: mask at u-v velocity points
+      tmf
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,2,2) ::   &  !:
+      wght   ,          &  !: weight of the 4 neighbours to compute averages
+      akappa ,          &  !: first group of metric coefficients
+      bkappa               !: third group of metric coefficients
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,2,2,2,2) ::   &  !:
+      alambd               !: second group of metric coefficients
+
+   !!======================================================================
+END MODULE dom_ice
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/ice.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/ice.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/ice.F90	(revision 884)
@@ -0,0 +1,506 @@
+MODULE ice
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' :                                   LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !! History :
+   !!   2.0  !  03-08  (C. Ethe)  F90: Free form and module
+   !!   3.0  !  08-03  (M. Vancoppenolle) : LIM3 !
+   !!----------------------------------------------------------------------
+   !!  LIM 3.0, UCL-LOCEAN-IPSL (2005)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/ice.F90,v 1.4 2005/03/27 18:34:41 opalod Exp $
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_ice          ! LIM sea-ice parameters
+
+   IMPLICIT NONE
+   PRIVATE
+   !!
+   !!======================================================================
+   !!                        ***  MODULE ice  ***
+   !!
+   !!                           **************
+   !!                           * L I M  3.0 *
+   !!                           **************
+   !!
+   !!                         ''in ice we trust''
+   !!
+   !!                   This module contains the sea ice 
+   !!                 diagnostics variables of ice defined 
+   !!                             in memory
+   !!
+   !!======================================================================
+   !!
+   !! LIM3 by the use of sweat, agile fingers and sometimes brain juice, 
+   !!  was developed in Louvain-la-Neuve by : 
+   !!
+   !!    * Martin Vancoppenolle (UCL-ASTR, Belgium)
+   !!    * Sylvain Bouillon (UCL-ASTR, Belgium)
+   !!    * Miguel Angel Morales Maqueda (POL, UK)
+   !! 
+   !! Based on extremely valuable earlier work by
+   !!
+   !!    * Thierry Fichefet
+   !!    * Hugues Goosse
+   !!
+   !! The following persons also contributed to the code in various ways
+   !!
+   !!    * Gurvan Madec, Claude Talandier, Christian Ethe 
+   !!      and Rachid Benshila (LOCEAN-IPSL, France)
+   !!    * Xavier Fettweis (UCL-ASTR), Ralph Timmermann (AWI, Germany)
+   !!    * Bill Lipscomb (LANL), Cecilia Bitz (UWa) 
+   !!      and Elisabeth Hunke (LANL), USA.
+   !! 
+   !! (c) UCL-ASTR, 2005-2008
+   !!
+   !! For more info, the interested user is kindly invited to consult the
+   !! following references
+   !!    For model description and validation :
+   !!    * Vancoppenolle et al., Ocean Modelling, 2008a.
+   !!    * Vancoppenolle et al., Ocean Modelling, 2008b.
+   !!
+   !!    For a specific description of EVP :
+   !!    * Bouillon et al., in prep for 2008.
+   !!
+   !!    Or the reference manual, that should be available by 2009
+   !!
+   !!======================================================================
+   !!                                                                     |
+   !!            *****************************************                |
+   !!            *                                       *                |
+   !! ************ I C E   S T A T E   V A R I A B L E S **************** |
+   !!            *                                       *                |
+   !!            *****************************************                |
+   !!                                                                     |
+   !! Introduction :                                                      |
+   !! --------------                                                      |
+   !!                                                                     |
+   !! Every ice-covered grid cell is characterized by a series of state   |
+   !! variables. To account for unresolved spatial variability in ice     |
+   !! thickness, the ice cover in divided in ice thickness categories.    |
+   !!                                                                     |
+   !! Sea ice state variables depend on the ice thickness category        |
+   !!                                                                     |
+   !! Those variables are divided into two groups                         |
+   !! * Extensive (or global) variables.                                  |
+   !!   These are the variables that are transported by all means         |
+   !! * Intensive (or equivalent) variables.                              |
+   !!   These are the variables that are either physically more           |
+   !!   meaningful and/or used in ice thermodynamics                      |
+   !!                                                                     |
+   !! Routines in limvar.F90 perform conversions                          |
+   !!  - lim_var_glo2eqv  : from global to equivalent variables           |
+   !!  - lim_var_eqv2glo  : from equivalent to global variables           |
+   !!                                                                     |
+   !! For various purposes, the sea ice state variables have sometimes    |
+   !! to be aggregated over all ice thickness categories. This operation  |
+   !! is done in :                                                        |
+   !!  - lim_var_agg                                                      |
+   !!                                                                     |
+   !! in icestp.F90, the routines that compute the changes in the ice     |
+   !! state variables are called                                          |
+   !! - lim_dyn : ice dynamics                                            |
+   !! - lim_trp : ice transport                                           |
+   !! - lim_itd_me : mechanical redistribution (ridging and rafting)      |
+   !! - lim_thd : ice halo-thermodynamics                                 |
+   !! - lim_itd_th : thermodynamic changes in ice thickness distribution  |
+   !!                and creation of new ice                              |
+   !!                                                                     |
+   !! See the associated routines for more information                    |
+   !!                                                                     |
+   !! List of ice state variables :                                       |
+   !! -----------------------------                                       |
+   !!                                                                     |
+   !!-------------|-------------|---------------------------------|-------|
+   !!   name in   |   name in   |              meaning            | units |
+   !! 2D routines | 1D routines |                                 |       |
+   !!-------------|-------------|---------------------------------|-------|
+   !!                                                                     |
+   !! ******************************************************************* |
+   !! ***         Dynamical variables (prognostic)                    *** |
+   !! ******************************************************************* |
+   !!                                                                     |
+   !! u_ice       |      -      |    Comp. U of the ice velocity  | m/s   |
+   !! v_ice       |      -      |    Comp. V of the ice velocity  | m/s   |
+   !!                                                                     |
+   !! ******************************************************************* |
+   !! ***         Category dependent state variables (prognostic)     *** |
+   !! ******************************************************************* |
+   !!                                                                     |
+   !! ** Global variables                                                 |
+   !!                                                                     |
+   !!-------------|-------------|---------------------------------|-------|
+   !! a_i         | a_i_b       |    Ice concentration            |       |
+   !! v_i         |      -      |    Ice volume per unit area     | m     |
+   !! v_s         |      -      |    Snow volume per unit area    | m     |
+   !! smv_i       |      -      |    Sea ice salt content         | ppt.m |
+   !! 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  | 
+   !! e_s         !      -      !    Snow enthalpy                | 10^9 J| 
+   !!      -      ! q_s_b       !    Snow enthalpy per unit vol.  | J/m3  | 
+   !!                                                                     |
+   !!-------------|-------------|---------------------------------|-------|
+   !!                                                                     |
+   !! ** Equivalent variables                                             |
+   !!                                                                     |
+   !!-------------|-------------|---------------------------------|-------|
+   !!                                                                     |
+   !! 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   |
+   !! 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     |
+   !!                                                                     |
+   !! notes: the ice model only sees a bulk (i.e., vertically averaged)   |
+   !!        salinity, except in thermodynamic computations, for which    |
+   !!        the salinity profile is computed as a function of bulk       |
+   !!        salinity                                                     |
+   !!                                                                     |
+   !!        the sea ice surface temperature is not associated to any     |
+   !!        heat content. Therefore, it is not a state variable and      |
+   !!        does not have to be advected. Nevertheless, it has to be     |
+   !!        computed to determine whether the ice is melting or not      |
+   !!                                                                     |
+   !! ******************************************************************* |
+   !! ***         Category-summed state variables (diagnostic)        *** |
+   !! ******************************************************************* |
+   !! at_i        | at_i_b      |    Total ice concentration      |       |
+   !! vt_i        |      -      |    Total ice vol. per unit area | m     |
+   !! vt_s        |      -      |    Total snow vol. per unit ar. | m     |
+   !! smt_i       |      -      |    Mean sea ice salinity        | ppt   |
+   !! tm_i        |      -      |    Mean sea ice temperature     | K     |
+   !! ot_i        !      -      !    Sea ice areal age content    | day   |
+   !! et_i        !      -      !    Total ice enthalpy           | 10^9 J| 
+   !! et_s        !      -      !    Total snow enthalpy          | 10^9 J| 
+   !! bv_i        !      -      !    Mean relative brine volume   | ???   | 
+   !!                                                                     |
+   !!                                                                     |
+   !!=====================================================================
+
+   LOGICAL, PUBLIC ::    &
+      con_i = .false.           ! switch for conservation test
+
+   !!--------------------------------------------------------------------------
+   !! * Share Module variables
+   !!--------------------------------------------------------------------------
+   INTEGER , PUBLIC ::   &     !!: ** ice-dynamic namelist (namicedyn) **
+      nbiter = 1      ,  &     !: number of sub-time steps for relaxation
+      nbitdr = 250    ,  &     !: maximum number of iterations for relaxation
+      nevp   = 400    ,  &     !: number of iterations for subcycling
+      nlay_i = 5               !: number of layers in the ice
+
+   REAL(wp), PUBLIC ::   &     !!: ** ice-dynamic namelist (namicedyn) **
+      epsd   = 1.0e-20,  &     !: tolerance parameter for dynamic
+      alpha  = 0.5    ,  &     !: coefficient for semi-implicit coriolis
+      dm     = 0.6e+03,  &     !: diffusion constant for dynamics
+      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  = 1.0e+04,  &     !: determines ice strength (N/M), Hibler JPO79
+      c_rhg  = 20.0   ,  &     !: determines changes in ice strength
+      etamn  = 0.0e+07,  &     !: minimun value for viscosity : has to be 0
+      creepl = 2.0e-08,  &     !: creep limit : has to be under 1.0e-9
+      ecc    = 2.0    ,  &  !: eccentricity of the elliptical yield curve
+      ahi0   = 350.e0 ,  &  !: sea-ice hor. eddy diffusivity coeff. (m2/s)
+      telast = 2880.0 ,  &  !: timescale for elastic waves (s) !SB
+      alphaevp = 1.0  ,  &  !: coeficient of the internal stresses !SB
+      unit_fac = 1.0e9      !: conversion factor for ice / snow enthalpy
+
+   REAL(wp), PUBLIC ::   & !!: ** ice-salinity namelist (namicesal) **
+      s_i_max  = 20.0 ,  &  !: maximum ice salinity (ppt)
+      s_i_min  =  0.1 ,  &  !: minimum ice salinity (ppt)
+      s_i_0    =  3.5 ,  &  !: 1st sal. value for the computation of sal .prof.
+                            !: (ppt)
+      s_i_1    =  4.5 ,  &  !: 2nd sal. value for the computation of sal .prof.
+                            !: (ppt)
+      sal_G    = 5.00 ,  &  !: restoring salinity for gravity drainage
+                            !: (ppt)
+      sal_F    = 2.50 ,  &  !: restoring salinity for flushing
+                            !: (ppt)
+      time_G   = 1.728e+06,&!: restoring time constant for gravity drainage
+                            !: (= 20 days, in s)
+      time_F   = 8.640e+05,&!: restoring time constant for gravity drainage 
+                            !: (= 10 days, in s)
+      bulk_sal = 4.0        !: bulk salinity (ppt) in case of constant salinity
+
+   INTEGER , PUBLIC ::   & !!: ** ice-salinity namelist (namicesal) **
+      num_sal  = 1    ,  &  !: salinity configuration used in the model
+                            !: 1 - s constant in space and time
+                            !: 2 - prognostic salinity (s(z,t))
+                            !: 3 - salinity profile, constant in time
+                            !: 4 - salinity variations affect only ice
+                            !      thermodynamics
+      sal_prof = 1    ,  &  !: salinity profile or not 
+      thcon_i_swi = 1       !: thermal conductivity of Untersteiner (1964) (1) or
+                            !: Pringle et al (2007) (2)
+
+   REAL(wp), PUBLIC ::   & !!: ** ice-mechanical redistribution namelist (namiceitdme)
+      Cs = 0.25       ,  & !!: fraction of shearing energy contributing to ridging            
+      Cf = 17.0       ,  & !!: ratio of ridging work to PE loss
+      fsnowrdg = 0.5  ,  & !!: fractional snow loss to the ocean during ridging
+      fsnowrft = 0.5  ,  & !!: fractional snow loss to the ocean during ridging
+      Gstar = 0.15    ,  & !!: fractional area of young ice contributing to ridging
+      astar = 0.05    ,  & !!: equivalent of G* for an exponential participation function
+      Hstar = 100.0   ,  & !!: thickness that determines the maximal thickness of ridged
+                           !!: ice
+      hparmeter = 0.75,  & !!: threshold thickness (m) for rafting / ridging 
+      Craft = 5.0     ,  & !!: coefficient for smoothness of the hyperbolic tangent in rafting
+      ridge_por = 0.0 ,  & !!: initial porosity of ridges (0.3 regular value)
+      sal_max_ridge = 15.0, & !!: maximum ridged ice salinity (ppt)
+      betas    = 1.0      , & !:: coef. for partitioning of snowfall between leads and sea ice
+      kappa_i  = 1.0      , & !!: coefficient for the extinction of radiation
+                              !!: Grenfell et al. (2006) (m-1)
+      nconv_i_thd = 50    , & !!: maximal number of iterations for heat diffusion
+      maxer_i_thd = 1.0e-4    !!: maximal tolerated error (C) for heat diffusion
+
+   INTEGER , PUBLIC ::   & !!: ** ice-mechanical redistribution namelist (namiceitdme)
+      ridge_scheme_swi = 0, & !!: scheme used for ice ridging
+      raftswi          = 1, & !!: rafting of ice or not                        
+      partfun_swi      = 1, & !!: participation function Thorndike et al. JGR75 (0) 
+                              !!: or Lipscomb et al. JGR07 (1) 
+      transfun_swi     = 0, & !!: transfer function of Hibler, MWR80 (0) 
+                              !!: or Lipscomb et al., 2007 (1)
+      brinstren_swi    = 0    !!: use brine volume to diminish ice strength
+
+   REAL(wp), PUBLIC ::   &  !:
+      usecc2          ,  &  !:  = 1.0 / ( ecc * ecc )
+      rhoco           ,  &  !: = rau0 * cw
+      sangvg, cangvg  ,  &  !: sin and cos of the turning angle for ocean stress
+      pstarh                !: pstar / 2.0
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::  &  !:
+      u_oce, v_oce    ,  &  !: surface ocean velocity used in ice dynamics
+      ahiu , ahiv     ,  &  !: hor. diffusivity coeff. at ocean U- and V-points (m2/s)
+      pahu , pahv     ,  &  !: ice hor. eddy diffusivity coef. at ocean U- and V-points
+      ust2s, hicol    ,  &  !: friction velocity, ice collection thickness accreted in leads
+      strength        ,  &  !: ice strength
+      strp1, strp2    ,  &  !: strength at previous time steps
+      stress1_i       ,  &  !: first stress tensor element
+      stress2_i       ,  &  !: second stress tensor element
+      stress12_i      ,  &  !: diagonal stress tensor element
+      delta_i         ,  &  !: Delta factor for the ice rheology (see Flato and Hibler 95) [s-1] -> limrhg.F90
+      divu_i          ,  &  !: Divergence of the velocity field [s-1] -> limrhg.F90
+      shear_i               !: Shear of the velocity field [s-1] -> limrhg.F90
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      firic  ,   &  !: IR flux over the ice (only used for outputs)
+      fcsic  ,   &  !: Sensible heat flux over the ice (only used for outputs)
+      fleic  ,   &  !: Latent heat flux over the ice (only used for outputs)
+      qlatic ,   &  !: latent flux
+      rdvosif,   &  !: Variation of volume at surface (only used for outputs)
+      rdvobif,   &  !: Variation of ice volume at the bottom ice (only used for outputs)
+      fdvolif,   &  !: Total variation of ice volume (only used for outputs)
+      rdvonif,   &  !: Lateral Variation of ice volume (only used for outputs)
+      sist   ,   &  !: Average Sea-Ice Surface Temperature (Kelvin ??? degree ??? I don't know)
+      t_bo   ,   &  !: Sea-Ice bottom temperature (Kelvin)      
+      hicifp ,   &  !: Ice production/melting
+      !obsolete... can be removed
+      frld   ,   &  !: Leads fraction = 1-a/totalarea REFERS TO LEAD FRACTION everywhere
+                    !: except in the OUTPUTS!!!!
+      pfrld  ,   &  !: Leads fraction at previous time  
+      phicif ,   &  !: Old ice thickness
+      fbif   ,   &  !: Heat flux at the ice base
+      rdmsnif,   &  !: Variation of snow mass
+      rdmicif,   &  !: Variation of ice mass
+      qldif  ,   &  !: heat balance of the lead (or of the open ocean)
+      qcmif  ,   &  !: Energy needed to bring the ocean surface layer until its freezing 
+      fdtcn  ,   &  !: net downward heat flux from the ice to the ocean
+      qdtcn  ,   &  !: energy from the ice to the ocean
+      fstric ,   &  !: transmitted solar radiation under ice
+      fscmbq ,   &  !: associated with lead chipotage with solar flux
+      ffltbif,   &  !: Array linked with the max heat contained in brine pockets (?)
+      fsbbq  ,   &  !: Also linked with the solar flux below the ice (?)
+      qfvbq  ,   &  !: Array used to store energy in case of toral lateral ablation (?)
+      dmgwi  ,   &  !: Variation of the mass of snow ice
+      fsalt_res, &  !: Residual salt flux due to correction of ice thickness
+      fsbri  ,   &  !: Salt flux due to brine rejection
+      fsalt_rpo, &  !: Salt flux associated with porous ridged ice formation
+      fheat_rpo, &  !: Heat flux associated with porous ridged ice formation
+      fhbri  ,   &  !: heat flux due to brine rejection
+      fmmec  ,   &  !: Mass flux due to snow loss during compression
+      fseqv  ,   &  !: Equivalent salt flux due to ice growth/melt
+      fheat_res, &  !: Residual heat flux due to correction of ice thickness
+      fhmec         !: Heat flux due to snow loss during compression
+      
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::       &  !:
+      albege ,   &  !: Albedo of the snow or ice (only for outputs)
+      albecn ,   &  !: Albedo of the ocean (only for outputs)
+      tauc   ,   &  !: Cloud optical depth
+      sdvt          !: u*^2/(Stress/density)
+
+! temporary arrays for dummy version of the code
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      dh_i_surf2D, dh_i_bott2D, fstbif, fsup2D, focea2D, q_s
+
+   INTEGER, PUBLIC, DIMENSION(jpi, jpj, jpl) ::          &   !::
+      patho_case ! number of the pathological case (if any, of course)
+
+   !!--------------------------------------------------------------------------
+   !! * Ice global state variables
+   !!--------------------------------------------------------------------------
+   !! Variables defined for each ice category
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpl)        ::   &  !:
+      ht_i   ,   &  !: Ice thickness (m)
+      a_i    ,   &  !: Ice fractional areas (concentration)
+      v_i    ,   &  !: Ice volume per unit area (m)
+      v_s    ,   &  !: Snow volume per unit area(m)
+      ht_s   ,   &  !: Snow thickness (m)
+      t_su   ,   &  !: Sea-Ice Surface Temperature (K)
+      sm_i   ,   &  !: Sea-Ice Bulk salinity (ppt)
+      smv_i  ,   &  !: Sea-Ice Bulk salinity times volume per area (ppt.m)
+                    !: this is an extensive variable that has to be transported
+      o_i    ,   &  !: Sea-Ice Age (days)
+      ov_i   ,   &  !: Sea-Ice Age times volume per area (days.m)
+      oa_i          !: Sea-Ice Age times ice area (days)
+
+   !! Variables summed over all categories, or associated to 
+   !! all the ice in a single grid cell
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      u_ice, v_ice,   &  !: two components of the ice velocity (m/s)
+      tio_u, tio_v,   &  !: two components of the ice-ocean stress (N/m2)
+      vt_i        ,   &  !: ice total volume per unit area (m)
+      vt_s        ,   &  !: snow total volume per unit area (m)
+      at_i        ,   &  !: ice total fractional area (ice concentration)
+      ato_i       ,   &  !: total open water fractional area (1-at_i)
+      et_i        ,   &  !: total ice heat content
+      et_s        ,   &  !: total snow heat content
+      ot_i        ,   &  !: mean age over all categories
+      tm_i        ,   &  !: mean ice temperature over all categories
+      bv_i        ,   &  !: brine volume averaged over all categories
+      smt_i              !: mean sea ice salinity averaged over all categories
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpm) ::   &  !:
+      at_i_typ    ,   &  !: total area contained in each ice type
+      vt_i_typ           !: total volume contained in each ice type
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpsmax) ::   &  !:
+      scal0              !: ???
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,nlay_s,jpl) :: & !:
+      t_s,            &  !: Snow temperatures (K)
+      e_s
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpl) ::   &  !: ! go to trash
+      e_i_cat
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jkmax,jpl) :: & !:
+      t_i,            &  !: Ice temperatures     [ Kelvins     ]
+      e_i,            &  !: Ice thermal contents [ Joules*10^9 ]
+      s_i                !: Ice salinities
+
+   REAL(wp), DIMENSION(jpi,jpj,0:jpkmax+1) ::    &  !:
+      reslum        !: Relative absorption of solar radiation in each ocean level
+
+   !!--------------------------------------------------------------------------
+   !! * Moments for advection
+   !!--------------------------------------------------------------------------
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)     ::   &  !:
+         sxopw, syopw, sxxopw, syyopw, sxyopw          !: open water in sea ice
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpl) ::   &  !:
+         sxice, syice, sxxice, syyice, sxyice,      &  !: ice thickness moments for advection
+         sxsn,  sysn,  sxxsn,  syysn,  sxysn,       &  !: snow thickness
+         sxa,   sya,   sxxa,   syya,   sxya,        &  !: lead fraction
+         sxc0,  syc0,  sxxc0,  syyc0,  sxyc0,       &  !: snow thermal content
+         sxsal, sysal, sxxsal, syysal, sxysal,      &  !: ice salinity
+         sxage, syage, sxxage, syyage, sxyage          !: ice age
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jkmax,jpl) ::   &  !:
+         sxe ,  sye ,  sxxe ,  syye ,  sxye            !: ice layers heat content
+
+   !!--------------------------------------------------------------------------
+   !! * Old values of global variables
+   !!--------------------------------------------------------------------------
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpl) ::   &  !: 
+      old_v_s, old_v_i,                          &  !: snow and ice volumes
+      old_a_i, old_smv_i, old_oa_i
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,nlay_s,jpl) ::   &  !:
+      old_e_s                                       !: snow heat content
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jkmax,jpl) ::   &  !:
+      old_e_i                          !: ice temperatures
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !: ice velocity (gv6 and gv7)
+      old_u_ice, old_v_ice
+
+   !!--------------------------------------------------------------------------
+   !! * Increment of global variables
+   !!--------------------------------------------------------------------------
+   ! thd refers to changes induced by thermodynamics
+   ! trp   ''         ''     ''       advection (transport of ice)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpl) ::   &  !: 
+      d_a_i_thd  , d_a_i_trp ,                   &  !: icefractions                  
+      d_v_s_thd  , d_v_s_trp,                    &  !: snow volume
+      d_v_i_thd  , d_v_i_trp,                    &  !: ice  volume
+      d_smv_i_thd, d_smv_i_trp,                  &     
+      d_sm_i_fl  , d_sm_i_gd ,                   &
+      d_sm_i_se  , d_sm_i_si , d_sm_i_la ,       &
+      d_oa_i_thd , d_oa_i_trp, s_i_newice
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,nlay_s,jpl) ::  &  !:
+      d_e_s_thd, d_e_s_trp
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jkmax,jpl) ::   &  !:
+      d_e_i_thd, d_e_i_trp
+   
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::       &  !: ice velocity 
+      d_u_ice_dyn, d_v_ice_dyn
+
+   !!--------------------------------------------------------------------------
+   !! * Ice thickness distribution variables
+   !!--------------------------------------------------------------------------
+   ! REMOVE
+   INTEGER(wp), PUBLIC, DIMENSION(jpl)                ::   &  !:
+      ice_types      !: Vector making the connection between types and categories
+
+   INTEGER(wp), PUBLIC, DIMENSION(jpm,2)              ::   &  !:
+      ice_cat_bounds !: Matrix containing the integer upper and 
+                     !: lower boundaries of ice thickness categories
+
+   ! REMOVE
+   INTEGER(wp), PUBLIC, DIMENSION(jpm)                ::   &  !:
+      ice_ncat_types !: Vector containing the number of thickness categories in each ice type
+
+   REAL(wp), PUBLIC, DIMENSION(0:jpl)             ::   &  !:
+      hi_max          !: Boundary of ice thickness categories in thickness space
+
+   REAL(wp), PUBLIC, DIMENSION(jpl)               ::   &  !:
+      hi_mean         !: Mean ice thickness in catgories 
+
+   ! REMOVE
+   REAL(wp), PUBLIC, DIMENSION(0:jpl,jpm)         ::   &  !:
+      hi_max_typ     !: Boundary of ice thickness categories 
+                     !:in thickness space (same but specific for each ice type)
+
+   !!--------------------------------------------------------------------------
+   !! * Ice diagnostics
+   !!--------------------------------------------------------------------------
+   !! Check if everything down here is necessary
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !: volume of ice formed in the leads
+      v_newice
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpl) ::   &  !: thermodynamic growth rates 
+      dv_dt_thd,  &
+      izero, fstroc, fhbricat
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   & 
+      diag_sni_gr,                           & ! snow ice growth 
+      diag_lat_gr,                           & ! lateral ice growth 
+      diag_bot_gr,                           & ! bottom ice growth 
+      diag_dyn_gr,                           & ! dynamical ice growth 
+      diag_bot_me,                           & ! vertical bottom melt 
+      diag_sur_me                              ! vertical surface melt
+   INTEGER , PUBLIC ::   &                      !: indexes of the debugging
+      jiindex,           &                      !  point
+      jjindex
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty module            NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE ice
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/iceini.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/iceini.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/iceini.F90	(revision 884)
@@ -0,0 +1,281 @@
+MODULE iceini
+   !!======================================================================
+   !!                       ***  MODULE iceini   ***
+   !!   Sea-ice model : LIM Sea ice model Initialization
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' :                                   LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_init       : sea-ice model initialization
+   !!----------------------------------------------------------------------
+   USE dom_oce
+   USE in_out_manager
+   USE ice_oce         ! ice variables
+   USE flx_oce
+   USE phycst          ! Define parameters for the routines
+   USE ocfzpt
+   USE ice
+   USE limmsh
+   USE limistate
+   USE limrst
+   USE par_ice
+   USE limvar
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC ice_init                 ! called by opa.F90
+   PUBLIC lim_itd_ini
+
+   !! * Share Module variables
+   LOGICAL , PUBLIC  ::     & !!! ** init namelist (namicerun) **
+      ln_limdyn   = .TRUE., & !: flag for ice dynamics (T) or not (F)
+      ln_nicep    = .TRUE.    !: flag for sea-ice points output (T) or not (F)
+   INTEGER , PUBLIC  ::   &  !:
+      nstart ,            &  !: iteration number of the begining of the run 
+      nlast  ,            &  !: iteration number of the end of the run 
+      nitrun ,            &  !: number of iteration
+      numit                  !: iteration number
+   REAL(wp), PUBLIC  ::   &  !:
+      hsndif = 0.e0    ,  &  !: computation of temp. in snow (0) or not (9999)
+      hicdif = 0.e0    ,  &  !: computation of temp. in ice (0) or not (9999)
+      tpstot           ,  &  !: time of the run in seconds
+      cai    = 1.40e-3 ,  &  !: atmospheric drag over sea ice
+      cao    = 1.00e-3       !: atmospheric drag over ocean
+   REAL(wp), PUBLIC, DIMENSION(2)  ::  &  !:
+      acrit  = (/ 1.e-06 , 1.e-06 /)    !: minimum fraction for leads in 
+      !                                   !  north and south hemisphere
+   !!----------------------------------------------------------------------
+   !!   LIM 3.0,  UCL-ASTR-LOCEAN-IPSL (2008) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/iceini.F90,v 1.4 2005/03/27 18:34:41 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE ice_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_init  ***
+      !!
+      !! ** purpose :   
+      !!
+      !! History :
+      !!   2.0  !  02-08  (G. Madec)  F90: Free form and modules
+      !!   3.0  !  08-03  (M. Vancop) ITD, salinity, EVP-C
+      !!----------------------------------------------------------------------
+
+      ! Open the namelist file 
+      CALL ctlopn(numnam_ice,'namelist_ice','OLD', 'FORMATTED', 'SEQUENTIAL', 1,numout,.FALSE.,1)
+
+      CALL ice_run                    !  read in namelist some run parameters
+                 
+      ! Louvain la Neuve Ice model
+      IF( nacc == 1 ) THEN
+          dtsd2   = nfice * rdtmin * 0.5
+          rdt_ice = nfice * rdtmin
+      ELSE
+          dtsd2   = nfice * rdt * 0.5
+          rdt_ice = nfice * rdt
+      ENDIF
+
+      CALL lim_msh                    ! ice mesh initialization
+     
+      CALL lim_itd_ini                ! initialize the ice thickness
+                                      ! distribution
+      ! Initial sea-ice state
+      IF( .NOT.ln_rstart ) THEN
+         numit = 0
+         numit = nit000 - 1
+         CALL lim_istate              ! start from rest: sea-ice deduced from sst
+         CALL lim_var_agg(1)          ! aggregate category variables in
+                                      ! bulk variables
+         CALL lim_var_glo2eqv         ! convert global variables in equivalent
+                                      ! variables
+      ELSE
+         CALL lim_rst_read            ! start from a restart file
+
+         numit = nit000 - 1
+         CALL lim_var_agg(1)          ! aggregate ice variables
+         CALL lim_var_glo2eqv         ! convert global var in equivalent variables
+      ENDIF
+
+      freeze(:,:) = at_i(:,:)   ! initialisation of sea/ice cover    
+# if defined key_coupled
+      alb_ice(:,:) = albege(:,:)      ! sea-ice albedo
+# endif
+      
+      nstart = numit  + nfice      
+      nitrun = nitend - nit000 + 1 
+      nlast  = numit  + nitrun 
+
+      IF( nstock == 0  )  nstock = nlast + 1
+
+   END SUBROUTINE ice_init
+
+   SUBROUTINE ice_run
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_run ***
+      !!                 
+      !! ** Purpose :   Definition some run parameter for ice model
+      !!
+      !! ** Method  :   Read the namicerun namelist and check the parameter 
+      !!       values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namicerun
+      !!
+      !! history :
+      !!   2.0  !  03-08 (C. Ethe)  Original code
+      !!   3.0  !  08-03 (M. Vancop) LIM3
+      !!-------------------------------------------------------------------
+      NAMELIST/namicerun/ ln_limdyn, acrit, hsndif, hicdif, cai, cao, ln_nicep
+      !!-------------------------------------------------------------------
+
+      !                                           ! Read Namelist namicerun 
+      REWIND ( numnam_ice )
+      READ   ( numnam_ice , namicerun )
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_run : ice share parameters for dynamics/advection/thermo of sea-ice'
+         WRITE(numout,*) ' ~~~~~~'
+         WRITE(numout,*) '   switch for ice dynamics (1) or not (0)      ln_limdyn   = ', ln_limdyn
+         WRITE(numout,*) '   minimum fraction for leads in the NH (SH)  acrit(1/2)   = ', acrit(:)
+         WRITE(numout,*) '   computation of temp. in snow (=0) or not (=9999) hsndif = ', hsndif
+         WRITE(numout,*) '   computation of temp. in ice  (=0) or not (=9999) hicdif = ', hicdif
+         WRITE(numout,*) '   atmospheric drag over sea ice                           = ', cai
+         WRITE(numout,*) '   atmospheric drag over ocean                             = ', cao
+         WRITE(numout,*) '   Several ice points in the ice or not in ocean.output = ', ln_nicep
+      ENDIF
+      
+   END SUBROUTINE ice_run
+
+   SUBROUTINE lim_itd_ini
+        !!------------------------------------------------------------------
+        !!                ***  ROUTINE lim_itd_ini ***
+        !! ** Purpose :
+        !!            Initializes the ice thickness distribution
+        !! ** Method  :
+        !!            Very simple. Currently there are no ice types in the
+        !!            model...
+        !!
+        !! ** Arguments :
+        !!           kideb , kiut : Starting and ending points on which the
+        !!                         the computation is applied
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !!
+        !! ** External :
+        !!
+        !! ** References :
+        !!
+        !! ** History :
+        !!           (12-2005) Martin Vancoppenolle
+        !!
+        !!------------------------------------------------------------------
+        !! * Arguments
+
+       !! * Local variables
+       INTEGER ::   jl,       &   ! ice category dummy loop index
+                    jm            ! ice types    dummy loop index
+
+       REAL(wp)  ::           &  ! constant values
+          zeps      =  1.0e-10,   & !
+          zc1                 ,   & !
+          zc2                 ,   & !
+          zc3                 ,   & !
+          zx1
+
+       WRITE(numout,*) 'lim_itd_ini : Initialization of ice thickness distribution '
+       WRITE(numout,*) '~~~~~~~~~~~~~~~'
+
+!!-- End of declarations
+!!------------------------------------------------------------------------------
+
+!------------------------------------------------------------------------------!
+! 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
+
+      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,*)
+
+      !- Thickness categories boundaries 
+      !----------------------------------
+      hi_max(:) = 0.0
+      hi_max_typ(:,:) = 0.0
+
+      !- Type 1 - undeformed ice
+      zc1 = 3./REAL(ice_cat_bounds(1,2)-ice_cat_bounds(1,1)+1)
+      zc2 = 10.0*zc1
+      zc3 = 3.0
+
+      DO jl = ice_cat_bounds(1,1), ice_cat_bounds(1,2)
+         zx1 = REAL(jl-1) / REAL(ice_cat_bounds(1,2)-ice_cat_bounds(1,1)+1)
+         hi_max(jl) = hi_max(jl-1) + zc1 + zc2 * (1.0 + TANH ( zc3 * (zx1 - 1.0 ) ) )
+      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
+
+      WRITE(numout,*) ' Thickness category boundaries independently of ice type '
+      WRITE(numout,*) ' hi_max ', hi_max(0:jpl)
+
+      WRITE(numout,*) ' Thickness category boundaries inside ice types '
+      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
+
+      DO jl = 1, jpl
+         hi_mean(jl) = ( hi_max(jl) + hi_max(jl-1) ) / 2.0
+      END DO
+
+      tn_ice(:,:,:) = t_su(:,:,:)
+
+    END SUBROUTINE lim_itd_ini
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :        Empty module           NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ice_init        ! Empty routine
+   END SUBROUTINE ice_init
+
+   SUBROUTINE lim_itd_ini
+   END SUBROUTINE lim_itd_ini
+#endif
+
+   !!======================================================================
+END MODULE iceini
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/icestp.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/icestp.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/icestp.F90	(revision 884)
@@ -0,0 +1,891 @@
+MODULE icestp
+   !!======================================================================
+   !!                       ***  MODULE icestp   ***
+   !!   Sea-Ice model : LIM Sea ice model time-stepping
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' :                                   LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_stp       : sea-ice model time-stepping
+   !!----------------------------------------------------------------------
+   USE par_ice
+   USE dom_oce
+   USE oce             ! dynamics and tracers variables
+   USE in_out_manager
+   USE ice_oce         ! ice variables
+   USE flx_oce         ! forcings variables
+   USE dom_ice
+   USE cpl_oce         ! nemo add
+   USE daymod
+   USE phycst          ! Define parameters for the routines
+   USE taumod
+   USE ice
+   USE iceini
+   USE ocesbc
+   USE lbclnk
+   USE limdyn
+   USE limtrp
+   USE limthd
+   USE limitd_th
+   USE limitd_me
+   USE limflx
+   USE limdia
+   USE limwri
+   USE limrst
+   USE limupdate       ! update of global variables
+   USE limvar
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC ice_stp  ! called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!-----------------------------------------------------
+   !!   LIM 2.0 , UCL-LODYC-IPSL  (2003)
+   !!-----------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE ice_stp ( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_stp  ***
+      !!                   
+      !! ** Purpose :   Louvain la Neuve Sea Ice Model time stepping 
+      !!
+      !! ** Action  : - call the ice dynamics routine 
+      !!              - call the ice advection/diffusion routine 
+      !!              - call the ice thermodynamics routine 
+      !!              - call the routine that computes mass and 
+      !!                heat fluxes at the ice/ocean interface
+      !!              - save the outputs 
+      !!              - save the outputs for restart when necessary
+      !!
+      !! History :
+      !!   1.0  !  99-11  (M. Imbard)  Original code
+      !!        !  01-03  (D. Ludicone, E. Durand, G. Madec) free surf.
+      !!   2.0  !  02-09  (G. Madec, C. Ethe)  F90: Free form and module
+      !!   3.0  !  05-10  (M. Vancoppenolle)   Trend terms, ice salinity, multi-layer model
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER   ::              & 
+         ji, jj, jk, jl,        &  ! loop indexes
+         index,                 &  ! indexes for ice points
+         numaltests,            &  ! number of alert tests (max 20)
+         alert_id                  ! number of the current alert
+
+      INTEGER, DIMENSION(20) :: &
+         numal                     ! number of alerts positive
+
+      REAL(wp) ::               &
+         ztmelts                   ! ice layer melting point
+      REAL(wp) , DIMENSION(jpi,jpj)    :: &
+         zsss_io, zsss2_io, zsss3_io          ! tempory workspaces
+
+      CHARACTER (len=30), DIMENSION(20) :: &  ! name of alert
+         alname
+      
+      !!----------------------------------------------------------------------
+
+!-------------------------------------------------------------------------------
+! 1) First time step
+!-------------------------------------------------------------------------------
+      !+++++
+      index = 12
+      jiindex = 44
+      jjindex = 140
+
+      WRITE(numout,*) ' The debugging point is : jiindex : ',jiindex,  &
+                                               ' jjindex : ',jjindex
+      !+++++
+
+      IF( kt == nit000 ) THEN
+
+         IF( lk_cpl ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'ice_stp : Louvain la Neuve Ice Model (LIM)'
+            IF(lwp) WRITE(numout,*) '~~~~~~~   coupled case'
+         ELSE
+            IF(lwp) WRITE(numout,*) 'ice_stp : Louvain la Neuve Ice Model (LIM)' 
+            IF(lwp) WRITE(numout,*) '~~~~~~~   forced case using bulk formulea'
+         ENDIF
+
+         gtaux(:,:) = 0.e0  ! Set wind stress to 0 
+         gtauy(:,:) = 0.e0
+
+      ENDIF ! Initial time step
+
+      IF(lwp) WRITE(numout,*) ' ~~~ LIM-@ ~~~      '
+      IF(lwp) WRITE(numout,*) ' Time step : ', kt
+
+!-------------------------------------------------------------------------------
+! 2) SST, SSS, wind stress, ocean velocity and seawater freezing point
+!-------------------------------------------------------------------------------
+
+      !-------------------------------------
+      ! Update SST, SSS and ocean velocity
+      !-------------------------------------
+
+      sst_io(:,:) = sst_io(:,:) + tn(:,:,1) + rt0
+      sss_io(:,:) = sss_io(:,:) + sn(:,:,1)
+
+      ! vectors at F-point
+      DO jj = 2, jpj
+         DO ji = fs_2, jpi  
+            u_io(ji,jj) = u_io(ji,jj) + un(ji,jj,1) 
+            v_io(ji,jj) = v_io(ji,jj) + vn(ji,jj,1) 
+         END DO
+      END DO
+      
+      !------------------------
+      ! Ice model loop starts           
+      !------------------------
+
+      IF( MOD( kt-1, nfice ) == 0 ) THEN
+         
+         !-------------------
+         ! Average SST, SSS
+         !-------------------
+
+         sst_io(:,:) = sst_io(:,:) / FLOAT( nfice ) * tmask(:,:,1)
+         sss_io(:,:) = sss_io(:,:) / FLOAT( nfice )
+
+         !----------------------------------------
+         ! Atmospheric stress and ocean velocity
+         !----------------------------------------
+
+         DO jj = 2, jpj
+            DO ji = fs_2, jpi
+
+               gtaux(ji,jj) = cai / cao * tauxw(ji,jj)
+               gtauy(ji,jj) = cai / cao * tauyw(ji,jj)
+
+               u_io (ji,jj) = u_io(ji,jj) / FLOAT( nfice ) * tmu(ji,jj)
+               v_io (ji,jj) = v_io(ji,jj) / FLOAT( nfice ) * tmv(ji,jj)
+
+            END DO
+         END DO
+
+         ! Boundary conditions
+         CALL lbc_lnk( gtaux(:,:), 'U', -1. )   ! I-point (i.e. ice U-V point)
+         CALL lbc_lnk( gtauy(:,:), 'V', -1. )   ! I-point (i.e. ice U-V point)
+         CALL lbc_lnk( u_io (:,:), 'U', -1. )   ! I-point (i.e. ice U-V point)
+         CALL lbc_lnk( v_io (:,:), 'V', -1. )   ! I-point (i.e. ice U-V point)
+
+         !--------------------------
+         ! Seawater freezing point
+         !--------------------------
+
+         zsss_io (:,:) = SQRT( sss_io(:,:) ) 
+         zsss2_io(:,:) = sss_io(:,:) * sss_io(:,:)
+         zsss3_io(:,:) = zsss_io(:,:) * zsss_io(:,:) * zsss_io(:,:)
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               t_bo(ji,jj)  = ABS ( rt0 - 0.0575      * sss_io(ji,jj)      &
+                  &                    + 1.710523e-03 * zsss3_io(ji,jj)    &
+                  &                    - 2.154996e-04 * zsss2_io(ji,jj) )  &
+                            * tms(ji,jj)
+            END DO
+         END DO
+
+         !+++++
+         IF(ln_ctl) THEN         ! print mean trends (used for debugging)
+            CALL prt_ctl_info('Ice Forcings ')
+            CALL prt_ctl(tab2d_1=qsr_oce ,clinfo1=' qsr_oce  : ')
+            CALL prt_ctl(tab2d_1=qnsr_oce,clinfo1=' qnsr_oce : ')
+            CALL prt_ctl(tab2d_1=evap    ,clinfo1=' evap     : ')
+            CALL prt_ctl(tab2d_1=tprecip ,clinfo1=' precip   : ')
+            CALL prt_ctl(tab2d_1=gtaux   ,clinfo1=' u-stress : ', tab2d_2=gtauy   , clinfo2=' v-stress  : ')
+            CALL prt_ctl(tab2d_1=sst_io  ,clinfo1=' sst      : ', tab2d_2=sss_io  , clinfo2=' sss       : ')
+            CALL prt_ctl(tab2d_1=u_io    ,clinfo1=' u_io     : ', tab2d_2=v_io    , clinfo2=' v_io      : ')
+            CALL prt_ctl(tab2d_1=frld    ,clinfo1=' frld   1 : ')
+
+            DO jl = 1, jpl
+               CALL prt_ctl_info('* - category number ', ivar1=jl)
+               CALL prt_ctl(tab3d_1=t_su    , clinfo1=' t_su      : ', kdim=jl)
+               CALL prt_ctl(tab3d_1=qsr_ice , clinfo1=' qsr_ice   : ', kdim=jl)
+               CALL prt_ctl(tab3d_1=qnsr_ice, clinfo1=' qnsr_ice  : ', kdim=jl)
+               CALL prt_ctl(tab3d_1=dqns_ice, clinfo1=' dqns_ice  : ', kdim=jl)
+               CALL prt_ctl(tab3d_1=qla_ice , clinfo1=' qla_ice   : ', kdim=jl)
+               CALL prt_ctl(tab3d_1=dqla_ice, clinfo1=' dqla_ice  : ', kdim=jl)
+            END DO
+         ENDIF
+         !+++++
+
+!----------------------------------------------------------------------------
+! 3) Store old values of ice model global variables
+!----------------------------------------------------------------------------
+
+         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
+
+         d_a_i_thd(:,:,:)   = 0.0 ; d_a_i_trp(:,:,:)   = 0.0
+         d_v_i_thd(:,:,:)   = 0.0 ; d_v_i_trp(:,:,:)   = 0.0
+         d_e_i_thd(:,:,:,:) = 0.0 ; d_e_i_trp(:,:,:,:) = 0.0
+         d_v_s_thd(:,:,:)   = 0.0 ; d_v_s_trp(:,:,:)   = 0.0
+         d_e_s_thd(:,:,:,:) = 0.0 ; d_e_s_trp(:,:,:,:) = 0.0
+         d_smv_i_thd(:,:,:) = 0.0 ; d_smv_i_trp(:,:,:) = 0.0
+         d_oa_i_thd(:,:,:)  = 0.0 ; d_oa_i_trp(:,:,:)  = 0.0
+
+         fsalt(:,:)     = 0.0     ; fseqv(:,:)     = 0.0
+         fsbri(:,:)     = 0.0     ; fsalt_res(:,:) = 0.0
+         fsalt_rpo(:,:) = 0.0
+         fhmec(:,:)     = 0.0     ; fhbri(:,:) = 0.0; 
+         fmmec(:,:)     = 0.0     ; fheat_res(:,:) = 0.0
+         fheat_rpo(:,:) = 0.0     ; focea2D(:,:) = 0.0
+         fsup2D(:,:)    = 0.0
+
+         diag_sni_gr(:,:) = 0.0   ; diag_lat_gr(:,:) = 0.0
+         diag_bot_gr(:,:) = 0.0   ; diag_dyn_gr(:,:) = 0.0
+         diag_bot_me(:,:) = 0.0   ; diag_sur_me(:,:) = 0.0
+
+         ! dynamical invariants
+         delta_i(:,:) = 0.0
+         divu_i(:,:)  = 0.0
+         shear_i(:,:) = 0.0
+
+         !----------------------
+         ! Ice model time step
+         !----------------------
+         numit = numit + nfice 
+         
+!----------------------------------------------------------------------------
+! 4) Ice routines, compute the trend terms of global variables
+!----------------------------------------------------------------------------
+
+         !                                                           !-----------------------!
+         CALL lim_rst_opn( kt )                                      ! Open Ice restart file !
+         !                                                           !-----------------------!
+
+         !+++++
+         WRITE(numout,*) ' - Beginning the time step - '
+         CALL lim_inst_state(jiindex,jjindex,1)
+         WRITE(numout,*) ' '
+         !+++++
+
+        !---------------------------
+        ! 4.1) Dynamical processes         
+        !---------------------------
+
+        !                                                            !--------------------!
+        CALL lim_dyn                                                 !  Ice dynamics      !  ( rheology/dynamics )
+        !                                                            !--------------------!
+
+        !                                                            !--------------------!
+        CALL lim_trp                                                 !  Ice transport     !
+        !                                                            !--------------------!
+   
+        CALL lim_var_agg(1)  ! aggregate categories, requested
+        CALL lim_var_glo2eqv ! equivalent variables, requested for rafting
+
+        !+++++
+        WRITE(numout,*) ' - After ice dynamics and transport '
+        CALL lim_inst_state(jiindex,jjindex,1)
+        WRITE(numout,*) ' '
+        WRITE(numout,*)
+        WRITE(numout,*) ' Mechanical Check ************** '
+        WRITE(numout,*) ' Check what means ice divergence '
+        WRITE(numout,*) ' Total ice concentration ', at_i (jiindex,jjindex)
+        WRITE(numout,*) ' Total lead fraction     ', ato_i(jiindex,jjindex)
+        WRITE(numout,*) ' Sum of both             ', ato_i(jiindex,jjindex) + at_i(jiindex,jjindex)
+        WRITE(numout,*) ' Sum of both minus 1     ', ato_i(jiindex,jjindex) + at_i(jiindex,jjindex) - 1.00
+        !+++++
+
+        !                                                            !------------------------------------------------!
+        CALL lim_itd_me                                              !  Mechanical redistribution ! (ridging/rafting) !
+        !                                                            !------------------------------------------------!
+
+        !-------------------------
+        ! 4.2 Ice thermodynamics
+        !-------------------------
+
+        CALL lim_var_glo2eqv ! equivalent variables
+        CALL lim_var_agg(1)  ! aggregate ice categories
+        CALL lim_var_bv      ! bulk brine volume (diag)
+
+        !                                                            !--------------------------------!
+        CALL lim_thd                                                 !  Heat diffusion, growth, melt  !
+        !                                                            !--------------------------------!
+     
+        !                                                            !---------------------!
+        !                                                            !  Ice natural aging  !
+        !                                                            !---------------------!
+
+        oa_i(:,:,:) = oa_i(:,:,:) + a_i(:,:,:) * rdt_ice / 86400.00
+
+        !+++++
+        CALL lim_var_glo2eqv ! except the info message that follows, i dont
+                             ! think this one is necessary
+        WRITE(numout,*) ' - After ice thermodynamics '
+        CALL lim_inst_state(jiindex,jjindex,1)
+        !+++++
+
+
+        !                                                            !-------------------------------------------!
+        CALL lim_itd_th                                              !  Remap ice categories, lateral accretion  !
+        !                                                            !-------------------------------------------!
+
+!----------------------------------------------------------------------------
+! 5) Global variables update 
+!----------------------------------------------------------------------------
+
+        CALL lim_var_agg(1)   ! requested by limupdate
+        !                                                            !-------------------------!
+        CALL lim_update                                              ! Global variables update !
+        !                                                            !-------------------------!
+
+        CALL lim_var_glo2eqv ! equivalent variables (outputs)
+        CALL lim_var_agg(2)   ! aggregate ice thickness categories
+
+        !+++++
+        IF(ln_nicep) THEN
+           WRITE(numout,*) ' - Final ice state after lim_update '
+           CALL lim_inst_state(jiindex,jjindex,2)
+           WRITE(numout,*) ' '
+        ENDIF
+        !+++++
+
+!----------------------------------------------------------------------------
+! 6) Fluxes of mass and heat to the ocean
+!----------------------------------------------------------------------------
+
+        !                                                            !------------------------------!
+        CALL lim_flx                                                 ! Ice/Ocean Mass & Heat fluxes !
+        !                                                            !------------------------------!
+
+        !+++++
+        WRITE(numout,*) ' - Final ice state after lim_flx    '
+        CALL lim_inst_state(jiindex,jjindex,3)
+        WRITE(numout,*) ' '
+        !+++++
+
+!----------------------------------------------------------------------------
+! 7) Diagnostics and outputs
+!----------------------------------------------------------------------------
+
+         IF( MOD( numit, ninfo ) == 0 .OR. ntmoy == 1 )  THEN        
+         !                                                           !-------------------------------!
+         CALL lim_dia                                                ! Ice Diagnostics in evolu file !
+         ENDIF                                                       !-------------------------------!
+
+         !                                                           !----------------------------!
+         CALL lim_wri( 1 )                                           ! Ice outputs in icemod file !
+         !                                                           !----------------------------!
+
+         !                                                           !------------------!
+         IF( lrst_ice ) CALL lim_rst_write( kt )                     ! Ice restart file !
+         !                                                           !------------------!
+
+         CALL lim_var_glo2eqv
+
+         ! Re-initialization of forcings
+         qsr_oce (:,:) = 0.e0
+         qsr_ice (:,:,:) = 0.e0
+         qnsr_oce(:,:) = 0.e0
+         qnsr_ice(:,:,:) = 0.e0 
+         dqns_ice(:,:,:) = 0.e0 
+         tprecip (:,:) = 0.e0 
+         sprecip (:,:) = 0.e0
+#if defined key_coupled 
+         rrunoff (:,:) = 0.e0
+         calving (:,:) = 0.e0
+#else
+         qla_ice (:,:,:) = 0.e0
+         dqla_ice(:,:,:) = 0.e0
+         fr1_i0  (:,:) = 0.e0
+         fr2_i0  (:,:) = 0.e0
+         evap    (:,:) = 0.e0
+#endif
+
+!----------------------------------------------------------------------------
+! 7) Alerts in case of model crash
+!----------------------------------------------------------------------------
+
+     numaltests = 10
+     numal(:) = 0
+
+     ! Alert if incompatible volume and concentration
+     alert_id = 2 ! reference number of this alert
+     alname(alert_id) = ' Incompat vol and con         ' ! name of the alert
+
+     DO jl = 1, jpl
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+                 IF ((v_i(ji,jj,jl).NE.0.0).AND.(a_i(ji,jj,jl).EQ.0.0)) THEN
+                    WRITE(numout,*) ' ALERTE 2 '
+                    WRITE(numout,*) ' Incompatible volume and concentration '
+                    WRITE(numout,*) ' at_i     ', at_i(ji,jj)
+                    WRITE(numout,*) ' Point - category', ji, jj, jl
+                    WRITE(numout,*)
+                    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,*) ' 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)
+                    numal(alert_id) = numal(alert_id) + 1
+                 ENDIF
+           END DO
+        END DO
+     END DO
+
+     ! Alerte if very thick ice
+     alert_id = 3 ! reference number of this alert
+     alname(alert_id) = ' Very thick ice               ' ! name of the alert
+     jl = jpl 
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           IF (ht_i(ji,jj,jl) .GT. 50.0 ) THEN
+              WRITE(numout,*) ' ALERTE 3 '
+              WRITE(numout,*) ' Very thick ice '
+              CALL lim_inst_state(ji,jj,2)
+              WRITE(numout,*) ' '
+              numal(alert_id) = numal(alert_id) + 1
+           ENDIF
+        END DO
+     END DO
+
+     ! Alert if very fast ice
+     alert_id = 4 ! reference number of this alert
+     alname(alert_id) = ' Very fast ice               ' ! name of the alert
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           IF ( ( ( ABS( u_ice(ji,jj) ) .GT. 0.50) .OR. &
+                  ( ABS( v_ice(ji,jj) ) .GT. 0.50) ) .AND. &
+                ( at_i(ji,jj) .GT. 0.0 ) ) THEN
+              WRITE(numout,*) ' ALERTE 4 '
+              WRITE(numout,*) ' Very fast ice '
+              CALL lim_inst_state(ji,jj,1)
+              WRITE(numout,*) ' ice strength         : ', strength(ji,jj)
+              WRITE(numout,*) ' oceanic stress ftaux : ', ftaux(ji,jj) 
+              WRITE(numout,*) ' oceanic stress ftauy : ', ftauy(ji,jj)
+              WRITE(numout,*) ' atmosph stress gtaux : ', gtaux(ji,jj) 
+              WRITE(numout,*) ' atmosph stress gtauy : ', gtauy(ji,jj)
+              WRITE(numout,*) ' oceanic speed u      : ', u_io(ji,jj)
+              WRITE(numout,*) ' oceanic speed v      : ', v_io(ji,jj)
+              WRITE(numout,*) ' sst                  : ', sst_io(ji,jj)
+              WRITE(numout,*) ' sss                  : ', sss_io(ji,jj)
+              WRITE(numout,*) 
+              numal(alert_id) = numal(alert_id) + 1
+           ENDIF
+        END DO
+     END DO
+
+     ! Alert if there is ice on continents
+     alert_id = 6 ! reference number of this alert
+     alname(alert_id) = ' Ice on continents           ' ! name of the alert
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           IF ( ( tms(ji,jj) .LE. 0.0 ) .AND. ( at_i(ji,jj) .GT. 0.0 ) ) THEN 
+              WRITE(numout,*) ' ALERTE 6 '
+              WRITE(numout,*) ' Ice on continents '
+              CALL lim_inst_state(ji,jj,1)
+              WRITE(numout,*) ' masks s, u, v        : ', tms(ji,jj), &
+                                                          tmu(ji,jj), &
+                                                          tmv(ji,jj) 
+              WRITE(numout,*) ' sst                  : ', sst_io(ji,jj)
+              WRITE(numout,*) ' sss                  : ', sss_io(ji,jj)
+              WRITE(numout,*) ' at_i(ji,jj)          : ', at_i(ji,jj)
+              WRITE(numout,*) ' v_ice(ji,jj)         : ', v_ice(ji,jj)
+              WRITE(numout,*) ' v_ice(ji,jj-1)       : ', v_ice(ji,jj-1)
+              WRITE(numout,*) ' u_ice(ji-1,jj)       : ', u_ice(ji-1,jj)
+              WRITE(numout,*) ' u_ice(ji,jj)         : ', v_ice(ji,jj)
+
+              numal(alert_id) = numal(alert_id) + 1
+
+           ENDIF
+        END DO
+     END DO
+
+!
+!    ! Alert if very fresh ice
+     alert_id = 7 ! reference number of this alert
+     alname(alert_id) = ' Very fresh ice               ' ! name of the alert
+     DO jl = 1, jpl
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           IF ( ( ( ABS( sm_i(ji,jj,jl) ) .LT. 0.50) .OR. &
+                  ( ABS( sm_i(ji,jj,jl) ) .LT. 0.50) ) .AND. &
+                ( a_i(ji,jj,jl) .GT. 0.0 ) ) THEN
+!             WRITE(numout,*) ' ALERTE 7 '
+!             WRITE(numout,*) ' Very fresh ice '
+!             CALL lim_inst_state(ji,jj,1)
+!             WRITE(numout,*) ' sst                  : ', sst_io(ji,jj)
+!             WRITE(numout,*) ' sss                  : ', sss_io(ji,jj)
+!             WRITE(numout,*) ' s_i_newice           : ', s_i_newice(ji,jj,1:jpl)
+!             WRITE(numout,*) 
+              numal(alert_id) = numal(alert_id) + 1
+           ENDIF
+        END DO
+     END DO
+     END DO
+!
+
+!    ! Alert if too old ice
+     alert_id = 9 ! reference number of this alert
+     alname(alert_id) = ' Very old   ice               ' ! name of the alert
+     DO jl = 1, jpl
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           IF ( ( ( ABS( o_i(ji,jj,jl) ) .GT. rdt_ice ) .OR. &
+                  ( ABS( o_i(ji,jj,jl) ) .LT. 0.00) ) .AND. &
+                ( a_i(ji,jj,jl) .GT. 0.0 ) ) THEN
+              WRITE(numout,*) ' ALERTE 9 '
+              WRITE(numout,*) ' Wrong ice age '
+              CALL lim_inst_state(ji,jj,1)
+              WRITE(numout,*) 
+              numal(alert_id) = numal(alert_id) + 1
+           ENDIF
+        END DO
+     END DO
+
+     END DO
+
+     ! Alert on salt flux
+     alert_id = 5 ! reference number of this alert
+     alname(alert_id) = ' High salt flux               ' ! name of the alert
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           IF (ABS(fsalt(ji,jj)).gt.1.0e-2) THEN
+           WRITE(numout,*) ' ALERTE 5 '
+           WRITE(numout,*) ' High salt flux '
+           CALL lim_inst_state(ji,jj,3)
+           WRITE(numout,*) ' '
+           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,*) ' 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,*) ' d_v_i_trp  : ', d_v_i_trp(ji,jj,jl) , &
+                              ' d_v_i_thd  : ', d_v_i_thd(ji,jj,jl) 
+              WRITE(numout,*) ' '
+              END DO
+              numal(alert_id) = numal(alert_id) + 1
+           ENDIF
+        END DO
+     END DO
+
+     ! Alert if fnsolar very big
+     alert_id = 8 ! reference number of this alert
+     alname(alert_id) = ' fnsolar very big             ' ! name of the alert
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           IF ( ( ABS( fnsolar(ji,jj) ) .GT. 1500.0 ) .AND. &
+                ( at_i(ji,jj) .GT. 0.0 ) )  THEN
+
+              WRITE(numout,*) ' ALERTE 8 '
+              WRITE(numout,*) ' ji, jj    : ', ji, jj
+              WRITE(numout,*) ' fnsolar : ', fnsolar(ji,jj)
+              WRITE(numout,*) ' Very high non-solar heat flux '
+              WRITE(numout,*) ' sst       : ', sst_io(ji,jj)
+              WRITE(numout,*) ' sss       : ', sss_io(ji,jj)
+              WRITE(numout,*) ' qcmif     : ', qcmif(jiindex,jjindex)
+              WRITE(numout,*) ' qldif     : ', qldif(jiindex,jjindex)
+              WRITE(numout,*) ' qcmif     : ', qcmif(jiindex,jjindex) / rdt_ice
+              WRITE(numout,*) ' qldif     : ', qldif(jiindex,jjindex) / rdt_ice
+              WRITE(numout,*) ' qfvbq     : ', qfvbq(jiindex,jjindex)
+              WRITE(numout,*) ' qdtcn     : ', qdtcn(jiindex,jjindex)
+              WRITE(numout,*) ' qfvbq / dt: ', qfvbq(jiindex,jjindex) / rdt_ice
+              WRITE(numout,*) ' qdtcn / dt: ', qdtcn(jiindex,jjindex) / rdt_ice
+              WRITE(numout,*) ' fdtcn     : ', fdtcn(jiindex,jjindex) 
+              WRITE(numout,*) ' fhmec     : ', fhmec(jiindex,jjindex) 
+              WRITE(numout,*) ' fheat_rpo : ', fheat_rpo(jiindex,jjindex) 
+              WRITE(numout,*) ' fheat_res : ', fheat_res(jiindex,jjindex) 
+              WRITE(numout,*) ' fhbri     : ', fhbri(jiindex,jjindex) 
+
+              CALL lim_inst_state(ji,jj,2)
+              numal(alert_id) = numal(alert_id) + 1
+
+           ENDIF
+        END DO
+     END DO
+     !+++++
+ 
+     ! Alert if very warm ice
+     alert_id = 10 ! reference number of this alert
+     alname(alert_id) = ' Very warm ice                ' ! name of the alert
+     numal(alert_id) = 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 ( ( t_i(ji,jj,jk,jl) .GE. ztmelts) .AND. &
+                ( v_i(ji,jj,jl)   .GT. 1.0e-6)   .AND. &
+                ( a_i(ji,jj,jl) .GT. 0.0     )  ) THEN
+              WRITE(numout,*) ' ALERTE 10 '
+              WRITE(numout,*) ' ji, jj, jk, jl : ', ji, jj, jk, jl
+              WRITE(numout,*) ' Very warm ice '
+              WRITE(numout,*) ' t_i : ', t_i(ji,jj,jk,jl)
+              WRITE(numout,*) ' e_i : ', e_i(ji,jj,jk,jl)
+              WRITE(numout,*) ' s_i : ', s_i(ji,jj,jk,jl)
+              WRITE(numout,*) ' ztmelts : ', ztmelts
+              numal(alert_id) = numal(alert_id) + 1
+           ENDIF
+        END DO
+     END DO
+     END DO
+     END DO
+
+     alert_id = 1 ! reference number of this alert
+     alname(alert_id) = ' Il n''y a pas d''alerte 1       ' ! name of the alert
+     WRITE(numout,*)
+     WRITE(numout,*) ' All alerts at the end of ice model '
+     DO alert_id = 1, numaltests
+        WRITE(numout,*) alert_id, alname(alert_id)//' : ', numal(alert_id), ' times ! '
+     END DO
+!
+
+      ENDIF ! kt EQ ice time step
+
+   END SUBROUTINE ice_stp
+   
+!------------------------------------------------------------------------------
+   SUBROUTINE lim_inst_state(i,j,n)
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE lim_inst_state *** 
+      !!                 
+      !! ** Purpose :   Writes global ice state on the (i,j) point 
+      !!                in ocean.ouput 
+      !!                3 possibilities exist 
+      !!                n = 1 -> simple ice state
+      !!                n = 2 -> exhaustive state
+      !!                n = 3 -> ice/ocean salt fluxes
+      !!
+      !! ** input   :   point coordinates (i,j) 
+      !!                n : number of the option
+      !!
+      !! history :
+      !!  9.0  ! 06-12 (M. Vancoppenolle) Original code
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   i,j,n     ! ocean time-step index
+
+      INTEGER :: jl
+
+      !!-------------------------------------------------------------------
+
+      !----------------
+      !  Simple state
+      !----------------
+
+      IF ( n .EQ. 1 ) THEN
+         WRITE(numout,*) ' lim_inst_state - Point : ',i,j
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
+         WRITE(numout,*) ' Simple state '
+         WRITE(numout,*) ' masks s,u,v   : ', tms(i,j), tmu(i,j), tmv(i,j)
+         WRITE(numout,*) ' lat - long    : ', gphit(i,j), glamt(i,j)
+         WRITE(numout,*) ' Time step     : ', numit
+         WRITE(numout,*) ' - Ice drift   '
+         WRITE(numout,*) '   ~~~~~~~~~~~ '
+         WRITE(numout,*) ' u_ice(i-1,j)  : ', u_ice(i-1,j)
+         WRITE(numout,*) ' u_ice(i  ,j)  : ', u_ice(i,j)
+         WRITE(numout,*) ' v_ice(i  ,j-1): ', v_ice(i,j-1)
+         WRITE(numout,*) ' v_ice(i  ,j)  : ', v_ice(i,j)
+         WRITE(numout,*) ' strength      : ', strength(i,j)
+         WRITE(numout,*)
+         WRITE(numout,*) ' - Cell values '
+         WRITE(numout,*) '   ~~~~~~~~~~~ '
+         WRITE(numout,*) ' cell area     : ', area(i,j)
+         WRITE(numout,*) ' at_i          : ', at_i(i,j)       
+         WRITE(numout,*) ' vt_i          : ', vt_i(i,j)       
+         WRITE(numout,*) ' vt_s          : ', vt_s(i,j)       
+         DO jl = 1, jpl
+            WRITE(numout,*) ' - Category (', jl,')'
+            WRITE(numout,*) ' a_i           : ', a_i(i,j,jl)
+            WRITE(numout,*) ' ht_i          : ', ht_i(i,j,jl)
+            WRITE(numout,*) ' ht_s          : ', ht_s(i,j,jl)
+            WRITE(numout,*) ' v_i           : ', v_i(i,j,jl)
+            WRITE(numout,*) ' v_s           : ', v_s(i,j,jl)
+            WRITE(numout,*) ' e_s           : ', e_s(i,j,1,jl)/1.0e9
+            WRITE(numout,*) ' e_i           : ', e_i(i,j,1:nlay_i,jl)/1.0e9
+            WRITE(numout,*) ' t_su          : ', t_su(i,j,jl)
+            WRITE(numout,*) ' t_snow        : ', t_s(i,j,1,jl)
+            WRITE(numout,*) ' t_i           : ', t_i(i,j,1:nlay_i,jl)
+            WRITE(numout,*) ' sm_i          : ', sm_i(i,j,jl)
+            WRITE(numout,*) ' smv_i         : ', smv_i(i,j,jl)
+            WRITE(numout,*)
+            WRITE(numout,*) ' Pathological case : ', patho_case(i,j,jl)
+         END DO
+      ENDIF
+
+      !--------------------
+      !  Exhaustive state
+      !--------------------
+
+      IF ( n .EQ. 2 ) THEN
+         WRITE(numout,*) ' lim_inst_state - Point : ',i,j
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
+         WRITE(numout,*) ' Exhaustive state '
+         WRITE(numout,*) ' lat - long ', gphit(i,j), glamt(i,j)
+         WRITE(numout,*) ' Time step ', numit
+         WRITE(numout,*) 
+         WRITE(numout,*) ' - Cell values '
+         WRITE(numout,*) '   ~~~~~~~~~~~ '
+         WRITE(numout,*) ' cell area     : ', area(i,j)
+         WRITE(numout,*) ' at_i          : ', at_i(i,j)       
+         WRITE(numout,*) ' vt_i          : ', vt_i(i,j)       
+         WRITE(numout,*) ' vt_s          : ', vt_s(i,j)       
+         WRITE(numout,*) ' sdvt          : ', sdvt(i,j)       
+         WRITE(numout,*) ' u_ice(i-1,j)  : ', u_ice(i-1,j)
+         WRITE(numout,*) ' u_ice(i  ,j)  : ', u_ice(i,j)
+         WRITE(numout,*) ' v_ice(i  ,j-1): ', v_ice(i,j-1)
+         WRITE(numout,*) ' v_ice(i  ,j)  : ', v_ice(i,j)
+         WRITE(numout,*) ' strength      : ', strength(i,j)
+         WRITE(numout,*) ' d_u_ice_dyn   : ', d_u_ice_dyn(i,j), &
+                         ' d_v_ice_dyn   : ', d_v_ice_dyn(i,j)
+         WRITE(numout,*) ' old_u_ice     : ', old_u_ice(i,j)  , &
+                         ' old_v_ice     : ', old_v_ice(i,j)  
+         WRITE(numout,*)
+
+         DO jl = 1, jpl
+              WRITE(numout,*) ' - Category (',jl,')'
+              WRITE(numout,*) '   ~~~~~~~~         ' 
+              WRITE(numout,*) ' ht_i       : ', ht_i(i,j,jl)             , &
+                              ' ht_s       : ', ht_s(i,j,jl)
+              WRITE(numout,*) ' t_i        : ', t_i(i,j,1:nlay_i,jl)
+              WRITE(numout,*) ' t_su       : ', t_su(i,j,jl)             , &
+                              ' t_s        : ', t_s(i,j,1,jl)
+              WRITE(numout,*) ' sm_i       : ', sm_i(i,j,jl)             , &    
+                              ' o_i        : ', o_i(i,j,jl)
+              WRITE(numout,*) ' a_i        : ', a_i(i,j,jl)              , &
+                              ' old_a_i    : ', old_a_i(i,j,jl)   
+              WRITE(numout,*) ' d_a_i_trp  : ', d_a_i_trp(i,j,jl)        , &
+                              ' d_a_i_thd  : ', d_a_i_thd(i,j,jl) 
+              WRITE(numout,*) ' v_i        : ', v_i(i,j,jl)              , &
+                              ' old_v_i    : ', old_v_i(i,j,jl)   
+              WRITE(numout,*) ' d_v_i_trp  : ', d_v_i_trp(i,j,jl)        , &
+                              ' d_v_i_thd  : ', d_v_i_thd(i,j,jl) 
+              WRITE(numout,*) ' v_s        : ', v_s(i,j,jl)              , &
+                              ' old_v_s    : ', old_v_s(i,j,jl)  
+              WRITE(numout,*) ' d_v_s_trp  : ', d_v_s_trp(i,j,jl)        , &
+                              ' d_v_s_thd  : ', d_v_s_thd(i,j,jl)
+              WRITE(numout,*) ' e_i1       : ', e_i(i,j,1,jl)/1.0e9      , &
+                              ' old_ei1    : ', old_e_i(i,j,1,jl)/1.0e9 
+              WRITE(numout,*) ' de_i1_trp  : ', d_e_i_trp(i,j,1,jl)/1.0e9, &
+                              ' de_i1_thd  : ', d_e_i_thd(i,j,1,jl)/1.0e9
+              WRITE(numout,*) ' e_i2       : ', e_i(i,j,2,jl)/1.0e9      , &
+                              ' old_ei2    : ', old_e_i(i,j,2,jl)/1.0e9  
+              WRITE(numout,*) ' de_i2_trp  : ', d_e_i_trp(i,j,2,jl)/1.0e9, &
+                              ' de_i2_thd  : ', d_e_i_thd(i,j,2,jl)/1.0e9
+              WRITE(numout,*) ' e_snow     : ', e_s(i,j,1,jl)            , &
+                              ' old_e_snow : ', old_e_s(i,j,1,jl) 
+              WRITE(numout,*) ' d_e_s_trp  : ', d_e_s_trp(i,j,1,jl)      , &
+                              ' d_e_s_thd  : ', d_e_s_thd(i,j,1,jl)
+              WRITE(numout,*) ' smv_i      : ', smv_i(i,j,jl)            , &
+                              ' old_smv_i  : ', old_smv_i(i,j,jl)   
+              WRITE(numout,*) ' d_smv_i_trp: ', d_smv_i_trp(i,j,jl)      , &
+                              ' d_smv_i_thd: ', d_smv_i_thd(i,j,jl) 
+              WRITE(numout,*) ' oa_i       : ', oa_i(i,j,jl)             , &
+                              ' old_oa_i   : ', old_oa_i(i,j,jl)
+              WRITE(numout,*) ' d_oa_i_trp : ', d_oa_i_trp(i,j,jl)       , &
+                              ' d_oa_i_thd : ', d_oa_i_thd(i,j,jl)
+              WRITE(numout,*) ' Path. case : ', patho_case(i,j,jl)
+        END DO !jl
+
+        WRITE(numout,*)
+        WRITE(numout,*) ' - Heat / FW fluxes '
+        WRITE(numout,*) '   ~~~~~~~~~~~~~~~~ '
+!       WRITE(numout,*) ' fsalt      : ', fsalt(i,j)
+!       WRITE(numout,*) ' fmass      : ', fmass(i,j)
+!       WRITE(numout,*) ' fsbri      : ', fsbri(i,j)
+!       WRITE(numout,*) ' fseqv      : ', fseqv(i,j)
+!       WRITE(numout,*) ' fsalt_res  : ', fsalt_res(i,j)
+        WRITE(numout,*) ' fmmec      : ', fmmec(i,j)
+        WRITE(numout,*) ' fhmec      : ', fhmec(i,j)
+        WRITE(numout,*) ' fhbri      : ', fhbri(i,j)
+        WRITE(numout,*) ' fheat_rpo  : ', fheat_rpo(i,j)
+        WRITE(numout,*) 
+        WRITE(numout,*) ' sst        : ', sst_io(i,j)  
+        WRITE(numout,*) ' sss        : ', sss_io(i,j)  
+        WRITE(numout,*) 
+        WRITE(numout,*) ' - Stresses '
+        WRITE(numout,*) '   ~~~~~~~~ '
+        WRITE(numout,*) ' tauxw      : ', tauxw(i,j) 
+        WRITE(numout,*) ' tauyw      : ', tauyw(i,j)
+        WRITE(numout,*) ' taux       : ', taux(i,j) 
+        WRITE(numout,*) ' tauy       : ', tauy(i,j)
+        WRITE(numout,*) ' ftaux      : ', ftaux(i,j) 
+        WRITE(numout,*) ' ftauy      : ', ftauy(i,j)
+        WRITE(numout,*) ' gtaux      : ', gtaux(i,j) 
+        WRITE(numout,*) ' gtauy      : ', gtauy(i,j)
+        WRITE(numout,*) ' oc. vel. u : ', u_io(i,j)
+        WRITE(numout,*) ' oc. vel. v : ', v_io(i,j)
+     ENDIF
+
+     !---------------------
+     ! Salt / heat fluxes
+     !---------------------
+
+     IF ( n .EQ. 3 ) THEN
+        WRITE(numout,*) ' lim_inst_state - Point : ',i,j
+        WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
+        WRITE(numout,*) ' - Salt / Heat Fluxes '
+        WRITE(numout,*) '   ~~~~~~~~~~~~~~~~ '
+        WRITE(numout,*) ' lat - long ', gphit(i,j), glamt(i,j)
+        WRITE(numout,*) ' Time step ', numit
+        WRITE(numout,*)
+        WRITE(numout,*) ' - Heat fluxes at bottom interface ***'
+        WRITE(numout,*) ' fsolar     : ', fsolar(i,j)
+        WRITE(numout,*) ' fnsolar    : ', fnsolar(i,j)
+        WRITE(numout,*)
+        WRITE(numout,*) ' - Salt fluxes at bottom interface ***'
+        WRITE(numout,*) ' fsalt      : ', fsalt(i,j)
+        WRITE(numout,*) ' fmass      : ', fmass(i,j)
+        WRITE(numout,*) ' fsbri      : ', fsbri(i,j)
+        WRITE(numout,*) ' fseqv      : ', fseqv(i,j)
+        WRITE(numout,*) ' fsalt_res  : ', fsalt_res(i,j)
+        WRITE(numout,*) ' fsalt_rpo  : ', fsalt_rpo(i,j)
+        WRITE(numout,*) ' - Heat fluxes at bottom interface ***'
+        WRITE(numout,*) ' fheat_res  : ', fheat_res(i,j)
+        WRITE(numout,*)
+        WRITE(numout,*) ' - Momentum fluxes '
+        WRITE(numout,*) ' ftaux      : ', ftaux(i,j) 
+        WRITE(numout,*) ' ftauy      : ', ftauy(i,j)
+        WRITE(numout,*) ' gtaux      : ', gtaux(i,j) 
+        WRITE(numout,*) ' gtauy      : ', gtauy(i,j)
+      ENDIF
+
+   END SUBROUTINE
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                 NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+   USE in_out_manager
+
+CONTAINS
+
+   SUBROUTINE ice_stp ( kt )            ! Empty routine
+      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'No Sea Ice Model'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+   END SUBROUTINE ice_stp
+   
+   SUBROUTINE lim_inst_state(i,j,n)        ! Empty routine
+      INTEGER, INTENT( in ) :: i, j, n
+   END SUBROUTINE
+
+#endif
+
+   !!======================================================================
+END MODULE icestp
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limadv.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limadv.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limadv.F90	(revision 884)
@@ -0,0 +1,451 @@
+MODULE limadv 
+   !!======================================================================
+   !!                       ***  MODULE limadv   ***
+   !! LIM sea-ice model : sea-ice advection
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                     LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_adv_x  : advection of sea ice on x axis
+   !!   lim_adv_y  : advection of sea ice on y axis
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce
+   USE dom_ice
+   USE ice_oce         ! ice variables
+   USE in_out_manager  ! I/O manager
+   USE lbclnk
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_adv_x    ! called by lim_trp
+   PUBLIC lim_adv_y    ! called by lim_trp
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+
+   !! * Module variables
+   REAL(wp)  ::            &  ! constant values
+      epsi20 = 1e-20    ,  &
+      rzero  = 0.e0     ,  &
+      rone   = 1.e0
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limadv.F90,v 1.4 2005/03/27 18:34:41 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_adv_x( pdf, put , pcrh, psm , ps0 ,   &
+      &                  psx, psxx, psy , psyy, psxy )
+      !!---------------------------------------------------------------------
+      !!                **  routine lim_adv_x  **
+      !!  
+      !! ** purpose :   Computes and adds the advection trend to sea-ice
+      !!      variable on x axis
+      !!
+      !! ** method  :   Uses Prather second order scheme that advects
+      !!      tracers but also theirquadratic forms. The method preserves
+      !!      tracer structures by conserving second order moments.
+      !!      Ref.: "Numerical Advection by Conservation of Second Order
+      !!      Moments", JGR, VOL. 91. NO. D6. PAGES 6671-6681. MAY 20, 1986
+      !!     
+      !! History :
+      !!        !  00-01 (LIM)
+      !!        !  01-05 (G. Madec, R. Hordoir) opa norm
+      !!        !  03-10 (C. Ethe) F90, module
+      !!        !  03-12 (R. Hordoir, G. Madec) mpp
+      !!--------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp)                    , INTENT(in)  ::  &
+         pdf ,       &  ! ???
+         pcrh           ! = 1. : lim_adv_x is called before lim_adv_y
+         !              ! = 0. : lim_adv_x is called after  lim_adv_y
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in)  ::  &
+         put            ! i-direction ice velocity at ocean U-point (m/s)
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::  & 
+         ps0 , psm , &  ! ???
+         psx , psy , &  ! ??? 
+         psxx, psyy, psxy
+
+      !! * Local declarations
+      INTEGER ::   ji, jj      ! dummy loop indices
+      REAL(wp)       ::  &
+         zrdt, zslpmax, ztemp, zin0,     &  ! temporary scalars
+         zs1max, zs1new, zs2new,         &  !    "         "
+         zalf, zalfq, zalf1, zalf1q,     &  !    "         "
+         zbt , zbt1                         !    "         "
+      REAL(wp), DIMENSION(jpi,jpj)  ::   &  ! temporary workspace
+         zf0 , zfx , zfy , zbet,         &  !    "           "
+         zfxx, zfyy, zfxy,               &  !    "           "
+         zfm, zalg, zalg1, zalg1q           !    "           "
+      !---------------------------------------------------------------------
+
+      ! Limitation of moments.                                           
+
+      zrdt      = rdt_ice * pdf   ! If ice drift field is too fast, use an appropriate time step for advection.
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zslpmax = MAX( rzero, 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
+
+            ps0 (ji,jj) = zslpmax  
+            psx (ji,jj) = zs1new      * zin0
+            psxx(ji,jj) = zs2new      * zin0
+            psy (ji,jj) = psy (ji,jj) * zin0
+            psyy(ji,jj) = psyy(ji,jj) * zin0
+            psxy(ji,jj) = MIN( zslpmax, MAX( -zslpmax, psxy(ji,jj) ) ) * zin0
+         END DO
+      END DO
+
+      !  Initialize volumes of boxes  (=area if adv_x first called, =psm otherwise)                                     
+      psm (:,:)  = MAX( pcrh * area(:,:) + ( 1.0 - pcrh ) * psm(:,:) , epsi20 )
+
+      !  Calculate fluxes and moments between boxes i<-->i+1              
+      DO jj = 1, jpj                      !  Flux from i to i+1 WHEN u GT 0 
+!i bug   DO ji = 1, jpim1 
+!i    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)
+            zalfq        =  zalf * zalf
+            zalf1        =  1.0 - zalf
+            zalf1q       =  zalf1 * zalf1
+            zfm (ji,jj)  =  zalf  * psm(ji,jj)
+            zf0 (ji,jj)  =  zalf  * ( ps0(ji,jj) + zalf1 * ( psx(ji,jj) + (zalf1 - zalf) * psxx(ji,jj)  ) )
+            zfx (ji,jj)  =  zalfq * ( psx(ji,jj) + 3.0 * zalf1 * psxx(ji,jj) )
+            zfxx(ji,jj)  =  zalf  * zalfq * psxx(ji,jj)
+            zfy (ji,jj)  =  zalf  * ( psy(ji,jj) + zalf1 * psxy(ji,jj) )
+            zfxy(ji,jj)  =  zalfq * psxy(ji,jj)
+            zfyy(ji,jj)  =  zalf  * psyy(ji,jj)
+
+            !  Readjust moments remaining in the box.
+            psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
+            ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
+            psx (ji,jj)  =  zalf1q * ( psx(ji,jj) - 3.0 * zalf * psxx(ji,jj) )
+            psxx(ji,jj)  =  zalf1  * zalf1q * psxx(ji,jj)
+            psy (ji,jj)  =  psy (ji,jj) - zfy(ji,jj)
+            psyy(ji,jj)  =  psyy(ji,jj) - zfyy(ji,jj)
+            psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
+         END DO
+      END DO
+
+      DO jj = 1, jpjm1                      !  Flux from i+1 to i when u LT 0.
+!i    DO jj = 1, fs_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) 
+            zalg  (ji,jj) = zalf
+            zalfq         = zalf * zalf
+            zalf1         = 1.0 - zalf
+            zalg1 (ji,jj) = zalf1
+            zalf1q        = zalf1 * zalf1
+            zalg1q(ji,jj) = zalf1q
+            zfm   (ji,jj) = zfm (ji,jj) + zalf  * psm(ji+1,jj)
+            zf0   (ji,jj) = zf0 (ji,jj) + zalf  * ( ps0(ji+1,jj) - zalf1 * ( psx(ji+1,jj) - (zalf1 - zalf ) * psxx(ji+1,jj) ) )
+            zfx   (ji,jj) = zfx (ji,jj) + zalfq * ( psx(ji+1,jj) - 3.0 * zalf1 * psxx(ji+1,jj) )
+            zfxx  (ji,jj) = zfxx(ji,jj) + zalf  * zalfq * psxx(ji+1,jj)
+            zfy   (ji,jj) = zfy (ji,jj) + zalf  * ( psy(ji+1,jj) - zalf1 * psxy(ji+1,jj) )
+            zfxy  (ji,jj) = zfxy(ji,jj) + zalfq * psxy(ji+1,jj)
+            zfyy  (ji,jj) = zfyy(ji,jj) + zalf  * psyy(ji+1,jj)
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1                     !  Readjust moments remaining in the box. 
+         DO ji = fs_2, jpi
+            zbt  =       zbet(ji-1,jj)
+            zbt1 = 1.0 - zbet(ji-1,jj)
+            psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji-1,jj) )
+            ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji-1,jj) )
+            psx (ji,jj) = zalg1q(ji-1,jj) * ( psx(ji,jj) + 3.0 * zalg(ji-1,jj) * psxx(ji,jj) )
+            psxx(ji,jj) = zalg1 (ji-1,jj) * zalg1q(ji-1,jj) * psxx(ji,jj)
+            psy (ji,jj) = zbt * psy (ji,jj) + zbt1 * ( psy (ji,jj) - zfy (ji-1,jj) )
+            psyy(ji,jj) = zbt * psyy(ji,jj) + zbt1 * ( psyy(ji,jj) - zfyy(ji-1,jj) )
+            psxy(ji,jj) = zalg1q(ji-1,jj) * psxy(ji,jj)
+         END DO
+      END DO
+
+      !   Put the temporary moments into appropriate neighboring boxes.    
+      DO jj = 2, jpjm1                     !   Flux from i to i+1 IF u GT 0.
+         DO ji = fs_2, fs_jpim1
+            zbt  =       zbet(ji-1,jj)
+            zbt1 = 1.0 - zbet(ji-1,jj)
+            psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji-1,jj) ) + zbt1 * psm(ji,jj)
+            zalf        = zbt * zfm(ji-1,jj) / psm(ji,jj)
+            zalf1       = 1.0 - zalf
+            ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji-1,jj)
+            ps0(ji,jj)  = zbt * (ps0(ji,jj) + zf0(ji-1,jj)) + zbt1 * ps0(ji,jj)
+            psx(ji,jj)  = zbt * ( zalf * zfx(ji-1,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp ) + zbt1 * psx(ji,jj)
+            psxx(ji,jj) = zbt * ( zalf * zalf * zfxx(ji-1,jj) + zalf1 * zalf1 * psxx(ji,jj)   &
+               &                + 5.0 * ( zalf * zalf1 * ( psx (ji,jj) - zfx(ji-1,jj) ) - ( zalf1 - zalf ) * ztemp )  )   &
+               &        + zbt1 * psxx(ji,jj)
+            psxy(ji,jj) = zbt * ( zalf * zfxy(ji-1,jj) + zalf1 * psxy(ji,jj)             &
+               &                + 3.0 * (- zalf1*zfy(ji-1,jj)  + zalf * psy(ji,jj) ) )   &
+               &         + zbt1 * psxy(ji,jj)
+            psy (ji,jj) = zbt * ( psy (ji,jj) + zfy (ji-1,jj) ) + zbt1 * psy (ji,jj)
+            psyy(ji,jj) = zbt * ( psyy(ji,jj) + zfyy(ji-1,jj) ) + zbt1 * psyy(ji,jj)
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1                     !  Flux from i+1 to i IF u LT 0.
+         DO ji = fs_2, fs_jpim1
+            zbt  =       zbet(ji,jj)
+            zbt1 = 1.0 - zbet(ji,jj)
+            psm(ji,jj)  = zbt * psm(ji,jj)  + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
+            zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
+            zalf1       = 1.0 - zalf
+            ztemp       = -zalf * ps0(ji,jj) + zalf1 * zf0(ji,jj)
+            ps0(ji,jj)  = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) + zf0(ji,jj) )
+            psx(ji,jj)  = zbt  * psx(ji,jj)   &
+               &        + zbt1 * ( zalf * zfx(ji,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp )
+            psxx(ji,jj) = zbt  * psxx(ji,jj)   &
+               &        + zbt1 * (  zalf * zalf * zfxx(ji,jj)  + zalf1 * zalf1 * psxx(ji,jj)  &
+               &                 + 5.0 *( zalf * zalf1 * ( - psx(ji,jj) + zfx(ji,jj) ) + ( zalf1 - zalf ) * ztemp ) )
+            psxy(ji,jj) = zbt  * psxy(ji,jj)   &
+               &        + zbt1 * (  zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)  &
+               &                 + 3.0 * ( zalf1 * zfy(ji,jj) - zalf * psy(ji,jj) )  )
+            psy(ji,jj)  = zbt * psy (ji,jj)  + zbt1 * ( psy (ji,jj) + zfy (ji,jj) )
+            psyy(ji,jj) = zbt * psyy(ji,jj)  + zbt1 * ( psyy(ji,jj) + zfyy(ji,jj) )
+         END DO
+      END DO
+
+      !-- Lateral boundary conditions
+      CALL lbc_lnk( psm , 'T', 1. )
+      CALL lbc_lnk( ps0 , 'T', 1. )
+      CALL lbc_lnk( psx , 'T', 1. )
+      CALL lbc_lnk( psxx, 'T', 1. )
+      CALL lbc_lnk( psy , 'T', 1. )
+      CALL lbc_lnk( psyy, 'T', 1. )
+      CALL lbc_lnk( psxy, 'T', 1. )
+
+     IF(ln_ctl) THEN
+         CALL prt_ctl(tab2d_1=psm  , clinfo1=' lim_adv_x: psm  :', tab2d_2=ps0 , clinfo2=' ps0  : ')
+         CALL prt_ctl(tab2d_1=psx  , clinfo1=' lim_adv_x: psx  :', tab2d_2=psxx, clinfo2=' psxx : ')
+         CALL prt_ctl(tab2d_1=psy  , clinfo1=' lim_adv_x: psy  :', tab2d_2=psyy, clinfo2=' psyy : ')
+         CALL prt_ctl(tab2d_1=psxy , clinfo1=' lim_adv_x: psxy :')
+     ENDIF
+
+   END SUBROUTINE lim_adv_x
+
+
+   SUBROUTINE lim_adv_y( pdf, pvt , pcrh, psm , ps0 ,   &
+      &                  psx, psxx, psy , psyy, psxy )
+      !!---------------------------------------------------------------------
+      !!                **  routine lim_adv_y  **
+      !!            
+      !! ** purpose :   Computes and adds the advection trend to sea-ice 
+      !!      variable on y axis
+      !!
+      !! ** method  :   Uses Prather second order scheme that advects tracers
+      !!      but also their quadratic forms. The method preserves tracer
+      !!      structures by conserving second order moments.
+      !!
+      !! History :
+      !!   1.0  !  00-01 (LIM)
+      !!        !  01-05 (G. Madec, R. Hordoir) opa norm
+      !!   2.0  !  03-10 (C. Ethe) F90, module
+      !!        !  03-12 (R. Hordoir, G. Madec) mpp
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp),                     INTENT(in)  :: &
+         pdf,        &  ! ???
+         pcrh           ! = 1. : lim_adv_x is called before lim_adv_y
+         !              ! = 0. : lim_adv_x is called after  lim_adv_y
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in)  :: &
+         pvt            ! j-direction ice velocity at ocean V-point (m/s)
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) :: &
+         psm , ps0 , psx , psy,   &
+         psxx, psyy, psxy
+
+      !! * Local Variables
+      INTEGER  ::   ji, jj                ! dummy loop indices
+      REAL(wp) ::   &
+         zrdt, zslpmax, zin0, ztemp,  &   ! temporary scalars
+         zs1max, zs1new, zs2new,      &   !    "         "
+         zalf, zalfq, zalf1, zalf1q,  &   !    "         "
+         zbt , zbt1                       !
+      REAL(wp), DIMENSION(jpi,jpj)  :: &
+         zf0 , zfx , zfy ,             &  ! temporary workspace
+         zfxx, zfyy, zfxy,             &  !    "           "
+         zfm , zbet,                   &  !    "           "
+         zalg, zalg1, zalg1q              !    "           "
+      !---------------------------------------------------------------------
+
+      ! Limitation of moments.
+
+      zrdt = rdt_ice * pdf ! If ice drift field is too fast, use an appropriate time step for advection.
+
+       DO jj = 1, jpj
+          DO ji = 1, jpi
+             zslpmax = MAX( rzero, 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
+             ps0 (ji,jj) = zslpmax  
+             psx (ji,jj)  = psx (ji,jj) * zin0
+             psxx(ji,jj)  = psxx(ji,jj) * zin0
+             psy (ji,jj) = zs1new * zin0
+             psyy(ji,jj) = zs2new * zin0
+             psxy(ji,jj) = MIN( zslpmax, MAX( -zslpmax, psxy(ji,jj) ) ) * zin0
+          END DO
+       END DO
+
+       !  Initialize volumes of boxes (=area if adv_x first called, =psm otherwise)
+       psm (:,:)  = MAX( pcrh * area(:,:) + ( 1.0 - pcrh ) * psm(:,:) , epsi20 )
+
+       !  Calculate fluxes and moments between boxes j<-->j+1              
+!!bug  DO jj = 2, jpjm1
+       DO jj = 1, jpj
+          DO ji = 1, jpi
+!!bug     DO ji = 1, jpim1
+             !  Flux from j to j+1 WHEN v GT 0   
+             zbet(ji,jj)  =  MAX( rzero, SIGN( rone, pvt(ji,jj) ) )
+             zalf         =  MAX( rzero, pvt(ji,jj) ) * zrdt * e1v(ji,jj) / psm(ji,jj)
+             zalfq        =  zalf * zalf
+             zalf1        =  1.0 - zalf
+             zalf1q       =  zalf1 * zalf1
+             zfm (ji,jj)  =  zalf  * psm(ji,jj)
+             zf0 (ji,jj)  =  zalf  * ( ps0(ji,jj) + zalf1 * ( psy(ji,jj)  + (zalf1-zalf) * psyy(ji,jj)  ) ) 
+             zfy (ji,jj)  =  zalfq *( psy(ji,jj) + 3.0*zalf1*psyy(ji,jj) )
+             zfyy(ji,jj)  =  zalf  * zalfq * psyy(ji,jj)
+             zfx (ji,jj)  =  zalf  * ( psx(ji,jj) + zalf1 * psxy(ji,jj) )
+             zfxy(ji,jj)  =  zalfq * psxy(ji,jj)
+             zfxx(ji,jj)  =  zalf  * psxx(ji,jj)
+
+             !  Readjust moments remaining in the box.
+             psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
+             ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
+             psy (ji,jj)  =  zalf1q * ( psy(ji,jj) -3.0 * zalf * psyy(ji,jj) )
+             psyy(ji,jj)  =  zalf1 * zalf1q * psyy(ji,jj)
+             psx (ji,jj)  =  psx (ji,jj) - zfx(ji,jj)
+             psxx(ji,jj)  =  psxx(ji,jj) - zfxx(ji,jj)
+             psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
+          END DO
+       END DO
+
+       DO jj = 1, jpjm1                   !  Flux from j+1 to j when v LT 0.
+          DO ji = 1, jpi
+!i     DO jj = 1, jpjm1                   !  Flux from j+1 to j when v LT 0.
+!i        DO ji = 2, jpim1
+             zalf          = ( MAX(rzero, -pvt(ji,jj) ) * zrdt * e1v(ji,jj) ) / psm(ji,jj+1) 
+             zalg  (ji,jj) = zalf
+             zalfq         = zalf * zalf
+             zalf1         = 1.0 - zalf
+             zalg1 (ji,jj) = zalf1
+             zalf1q        = zalf1 * zalf1
+             zalg1q(ji,jj) = zalf1q
+             zfm   (ji,jj) = zfm (ji,jj) + zalf  * psm(ji,jj+1)
+             zf0   (ji,jj) = zf0 (ji,jj) + zalf  * ( ps0(ji,jj+1) - zalf1 * (psy(ji,jj+1) - (zalf1 - zalf ) * psyy(ji,jj+1) ) )
+             zfy   (ji,jj) = zfy (ji,jj) + zalfq * ( psy(ji,jj+1) - 3.0 * zalf1 * psyy(ji,jj+1) )
+             zfyy  (ji,jj) = zfyy(ji,jj) + zalf  * zalfq * psyy(ji,jj+1)
+             zfx   (ji,jj) = zfx (ji,jj) + zalf  * ( psx(ji,jj+1) - zalf1 * psxy(ji,jj+1) )
+             zfxy  (ji,jj) = zfxy(ji,jj) + zalfq * psxy(ji,jj+1)
+             zfxx  (ji,jj) = zfxx(ji,jj) + zalf  * psxx(ji,jj+1)
+          END DO
+       END DO
+ 
+       !  Readjust moments remaining in the box. 
+       DO jj = 2, jpj
+          DO ji = 1, jpi
+             zbt  =         zbet(ji,jj-1)
+             zbt1 = ( 1.0 - zbet(ji,jj-1) )
+             psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji,jj-1) )
+             ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji,jj-1) )
+             psy (ji,jj) = zalg1q(ji,jj-1) * ( psy(ji,jj) + 3.0 * zalg(ji,jj-1) * psyy(ji,jj) )
+             psyy(ji,jj) = zalg1 (ji,jj-1)  * zalg1q(ji,jj-1) * psyy(ji,jj)
+             psx (ji,jj) = zbt * psx (ji,jj) + zbt1 * ( psx (ji,jj) - zfx (ji,jj-1) )
+             psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) - zfxx(ji,jj-1) )
+             psxy(ji,jj) = zalg1q(ji,jj-1) * psxy(ji,jj)
+          END DO
+       END DO
+
+       !   Put the temporary moments into appropriate neighboring boxes.    
+       DO jj = 2, jpjm1                    !   Flux from j to j+1 IF v GT 0.
+          DO ji = 1, jpi
+             zbt  =         zbet(ji,jj-1)
+             zbt1 = ( 1.0 - zbet(ji,jj-1) )
+             psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji,jj-1) ) + zbt1 * psm(ji,jj) 
+             zalf        = zbt * zfm(ji,jj-1) / psm(ji,jj) 
+             zalf1       = 1.0 - zalf
+             ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji,jj-1)
+             ps0(ji,jj)  = zbt * (ps0(ji,jj) + zf0(ji,jj-1)) + zbt1 * ps0(ji,jj)
+
+             psy(ji,jj)  = zbt  * ( zalf * zfy(ji,jj-1) + zalf1 * psy(ji,jj) + 3.0 * ztemp )   &
+                &        + zbt1 * psy(ji,jj)  
+
+             psyy(ji,jj) = zbt  * ( zalf * zalf * zfyy(ji,jj-1) + zalf1 * zalf1 * psyy(ji,jj)                             &
+                &                 + 5.0 * ( zalf * zalf1 * ( psy(ji,jj) - zfy(ji,jj-1) ) - ( zalf1 - zalf ) * ztemp ) )   & 
+                &        + zbt1 * psyy(ji,jj)
+
+             psxy(ji,jj) = zbt  * ( zalf * zfxy(ji,jj-1) + zalf1 * psxy(ji,jj)              &
+                                  + 3.0 * (- zalf1 * zfx(ji,jj-1) + zalf * psx(ji,jj) ) )   &
+                         + zbt1 * psxy(ji,jj)
+             psx (ji,jj) = zbt * ( psx (ji,jj) + zfx (ji,jj-1) ) + zbt1 * psx (ji,jj)
+             psxx(ji,jj) = zbt * ( psxx(ji,jj) + zfxx(ji,jj-1) ) + zbt1 * psxx(ji,jj)
+          END DO
+       END DO
+
+       DO jj = 2, jpjm1                   !  Flux from j+1 to j IF v LT 0.
+          DO ji = 1, jpi
+             zbt  =         zbet(ji,jj)
+             zbt1 = ( 1.0 - zbet(ji,jj) )
+             psm(ji,jj)  = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
+             zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
+             zalf1       = 1.0 - zalf
+             ztemp       = -zalf * ps0(ji,jj) + zalf1 * zf0(ji,jj)
+             ps0(ji,jj)  = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) + zf0(ji,jj) )
+             psy(ji,jj)  = zbt  * psy(ji,jj)  &
+                &        + zbt1 * ( zalf*zfy(ji,jj) + zalf1 * psy(ji,jj) + 3.0 * ztemp )
+             psyy(ji,jj) = zbt  * psyy(ji,jj)  &
+                &        + zbt1 * ( zalf * zalf * zfyy(ji,jj) + zalf1 * zalf1 * psyy(ji,jj)   &
+                &                 + 5.0 *( zalf *zalf1 *( -psy(ji,jj) + zfy(ji,jj) ) + ( zalf1 - zalf ) * ztemp ) )
+             psxy(ji,jj) = zbt  * psxy(ji,jj)   &
+                &        + zbt1 * ( zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)   &
+                &                 + 3.0 * ( zalf1 * zfx(ji,jj) - zalf * psx(ji,jj) ) )
+             psx(ji,jj)  = zbt * psx (ji,jj) + zbt1 * ( psx (ji,jj) + zfx (ji,jj) )
+             psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) + zfxx(ji,jj) )
+          END DO
+       END DO
+
+      !-- Lateral boundary conditions
+      CALL lbc_lnk( psm , 'T', 1. )
+      CALL lbc_lnk( ps0 , 'T', 1. )
+      CALL lbc_lnk( psx , 'T', 1. )
+      CALL lbc_lnk( psxx, 'T', 1. )
+      CALL lbc_lnk( psy , 'T', 1. )
+      CALL lbc_lnk( psyy, 'T', 1. )
+      CALL lbc_lnk( psxy, 'T', 1. )
+
+     IF(ln_ctl) THEN
+         CALL prt_ctl(tab2d_1=psm  , clinfo1=' lim_adv_y: psm  :', tab2d_2=ps0 , clinfo2=' ps0  : ')
+         CALL prt_ctl(tab2d_1=psx  , clinfo1=' lim_adv_y: psx  :', tab2d_2=psxx, clinfo2=' psxx : ')
+         CALL prt_ctl(tab2d_1=psy  , clinfo1=' lim_adv_y: psy  :', tab2d_2=psyy, clinfo2=' psyy : ')
+         CALL prt_ctl(tab2d_1=psxy , clinfo1=' lim_adv_y: psxy :')
+     ENDIF
+
+   END SUBROUTINE lim_adv_y
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option            Dummy module         NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_adv_x         ! Empty routine
+   END SUBROUTINE lim_adv_x
+   SUBROUTINE lim_adv_y           ! Empty routine
+   END SUBROUTINE lim_adv_y
+
+#endif
+
+END MODULE limadv
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limcons.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limcons.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limcons.F90	(revision 884)
@@ -0,0 +1,232 @@
+MODULE limcons
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' :                                   LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!
+   !!======================================================================
+   !!                     ***  MODULE  limcons  ***
+   !!
+   !! This module checks whether
+   !!   Ice Total Energy
+   !!   Ice Total Mass
+   !!   Salt Mass
+   !! Are conserved !
+   !! 
+   !!======================================================================
+   !!    lim_cons   :   checks whether energy/mass are conserved 
+   !!----------------------------------------------------------------------
+   !!
+   !! * Modules used
+
+   USE par_ice
+   USE dom_oce
+   USE dom_ice
+   USE ice
+   USE ice_oce         ! ice variables
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC lim_column_sum
+   PUBLIC lim_column_sum_energy
+   PUBLIC lim_cons_check
+
+   !! * Module variables
+   !!----------------------------------------------------------------------
+   !!   LIM 3.0 , UCL-ASTR-LODYC-IPSL  (2008)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+!===============================================================================
+
+   SUBROUTINE lim_column_sum(nsum,xin,xout)
+!     !!-------------------------------------------------------------------
+!     !!               ***  ROUTINE lim_column_sum ***
+!     !!
+!     !! ** Purpose : Compute the sum of xin over nsum categories
+!     !!
+!     !! ** Method  : Arithmetics
+!     !!
+!     !! ** Action  : Gets xin(ji,jj,jl) and computes xout(ji,jj)
+!     !!
+!     !! History :
+!     !!   author: William H. Lipscomb, LANL
+!     !!   2.1  !  04-06  (M. Vancoppenolle)   Energy Conservation 
+!     !!---------------------------------------------------------------------
+!     !! * Local variables
+      INTEGER, INTENT(in) ::     &
+           nsum                  ! number of categories/layers
+
+      REAL (wp), DIMENSION(jpi, jpj, jpl), INTENT(IN) ::   &
+           xin                   ! input field
+
+      REAL (wp), DIMENSION(jpi, jpj), INTENT(OUT) ::  &
+           xout                  ! output field
+      INTEGER ::                 &
+           ji, jj, jl         ! horizontal indices
+
+!     !!---------------------------------------------------------------------
+!     WRITE(numout,*) ' lim_column_sum '
+!     WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
+
+      xout(:,:) = 0.00
+
+      DO jl = 1, nsum
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               xout(ji,jj) = xout(ji,jj) + xin(ji,jj,jl)
+            END DO ! ji 
+         END DO  ! jj 
+      END DO  ! jl 
+
+   END SUBROUTINE lim_column_sum
+
+!===============================================================================
+
+   SUBROUTINE lim_column_sum_energy(nsum,nlay,xin,xout)
+
+      !!-------------------------------------------------------------------
+      !!               ***  ROUTINE lim_column_sum_energy ***
+      !!
+      !! ** Purpose : Compute the sum of xin over nsum categories
+      !!              and nlay layers
+      !!
+      !! ** Method  : Arithmetics
+      !!
+      !! ** Action  : Gets xin(ji,jj,jl) and computes xout(ji,jj)
+      !!
+      !! History :
+      !!   author: William H. Lipscomb, LANL
+      !!   2.1  !  04-06  (M. Vancoppenolle)   Energy Conservation 
+      !!---------------------------------------------------------------------
+      !! * Local variables
+      INTEGER, INTENT(in) ::  &
+           nsum,              &  !: number of categories
+           nlay                  !: number of vertical layers
+
+      REAL (wp), DIMENSION(jpi, jpj, jkmax, jpl), INTENT(IN) :: &
+           xin                   !: input field
+
+      REAL (wp), DIMENSION(jpi, jpj), INTENT(OUT) ::  &
+           xout                  !: output field
+
+      INTEGER ::              &
+           ji, jj,            &  !: horizontal indices
+           jk, jl                !: layer and category  indices
+      !!---------------------------------------------------------------------
+
+!     WRITE(numout,*) ' lim_column_sum_energy '
+!     WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~ '
+
+      xout(:,:) = 0.00
+
+      DO jl = 1, nsum
+         DO jk = 1, nlay 
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  xout(ji,jj) = xout(ji,jj) + xin(ji,jj,jk,jl)
+               END DO ! ji 
+            END DO  ! jj 
+         END DO  ! jk
+      END DO ! jl
+
+   END SUBROUTINE lim_column_sum_energy
+
+!===============================================================================
+   
+   SUBROUTINE lim_cons_check(x1, x2, max_err, fieldid)
+      !!-------------------------------------------------------------------
+      !!               ***  ROUTINE lim_cons_check ***
+      !!
+      !! ** Purpose : Test the conservation of a certain variable
+      !!              For each physical grid cell, check that initial 
+      !!              and final values
+      !!              of a conserved field are equal to within a small value.
+      !!
+      !! ** Method  :
+      !!
+      !! ** Action  : -
+      !! History :
+      !!   author: William H. Lipscomb, LANL
+      !!   2.1  !  04-06  (M. Vancoppenolle)   Energy Conservation 
+      !!---------------------------------------------------------------------
+      !! * Local variables
+
+      REAL (wp), DIMENSION(jpi, jpj), INTENT(IN) ::   &
+         x1 (jpi,jpj) , & !: initial field
+         x2 (jpi,jpj)     !: final field
+
+      REAL (wp) , INTENT ( IN )                  ::   &
+         max_err          !: max allowed error
+
+      REAL (wp)                                  ::   &
+         mean_error       !: mean error on error points
+
+      INTEGER                                    ::   &
+         num_error        !: number of g.c where there is a cons. error
+
+      CHARACTER(len=15) , INTENT(IN)             ::   &
+         fieldid          !: field identifyer
+
+      INTEGER ::              &
+         ji, jj           !: horizontal indices      
+
+      LOGICAL ::              &
+         conserv_err      !: = .true. if conservation check failed
+
+      !!---------------------------------------------------------------------
+      WRITE(numout,*) ' lim_cons_check '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
+
+      conserv_err = .FALSE.
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF (ABS(x2(ji,jj) - x1(ji,jj)) .GT. max_err) THEN
+               conserv_err = .TRUE.
+            ENDIF
+         END DO
+      END DO
+
+      IF ( conserv_err ) THEN
+
+         num_error  = 0
+         mean_error = 0.0
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+               IF (ABS(x2(ji,jj) - x1(ji,jj)) .GT. max_err ) THEN
+                  num_error  = num_error + 1
+                  mean_error = mean_error + ABS(x2(ji,jj) - x1(ji,jj))
+
+                  WRITE (numout,*) ' ALERTE 99 '
+                  WRITE (numout,*) ' Conservation error: ', fieldid
+                  WRITE (numout,*) ' Point         : ', ji, jj 
+                  WRITE (numout,*) ' lat, lon      : ', gphit(ji,jj), & 
+                                                        glamt(ji,jj)
+                  WRITE (numout,*) ' Initial value : ', x1(ji,jj)
+                  WRITE (numout,*) ' Final value   : ', x2(ji,jj)
+                  WRITE (numout,*) ' Difference    : ', x2(ji,jj) - x1(ji,jj)
+
+               ENDIF
+            END DO
+         END DO
+
+         IF ( num_error .GT. 0 ) mean_error = mean_error / num_error
+         WRITE(numout,*) ' Conservation check for : ', fieldid
+         WRITE(numout,*) ' Number of error points : ', num_error
+         WRITE(numout,*) ' Mean error on these pts: ', mean_error
+
+      ENDIF ! conserv_err
+
+   END SUBROUTINE lim_cons_check
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty module            NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+   !!======================================================================
+END MODULE limcons
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limdia.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limdia.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limdia.F90	(revision 884)
@@ -0,0 +1,621 @@
+MODULE limdia
+   !!======================================================================
+   !!                       ***  MODULE limdia   ***
+   !!                      diagnostics of ice model 
+   !!======================================================================
+   !! To add a new field
+   !! 1) in lim_dia : add its definition for both hemispheres if wished
+   !! 2) add the new titles in lim_dia_init
+   !!
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' :                                   LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_dia      : computation of the time evolution of keys var.
+   !!   lim_dia_init : initialization and namelist read
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE phycst
+   USE in_out_manager
+   USE par_ice         ! ice parameters
+   USE ice_oce         ! ice variables
+   USE daymod
+   USE dom_ice
+   USE ice
+   USE iceini
+   USE limistate
+   USE dom_oce
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_dia       ! called by ice_step
+
+   !! * Shared module variables
+   INTEGER, PUBLIC  ::  &
+      ntmoy   = 1 ,     &  !: instantaneous values of ice evolution or averaging ntmoy
+      ninfo   = 1          !: frequency of ouputs on file ice_evolu in case of averaging
+
+   !! * Module variables
+   INTEGER, PARAMETER ::   &  ! Parameters for outputs to files "evolu"
+      jpinfmx = 100         ,    &  ! maximum number of key variables
+      jpchinf = 5           ,    &  ! ???
+      jpchsep = jpchinf + 2         ! ???
+
+   INTEGER          ::  &
+      nfrinf  = 4    ,  &  ! number of variables written in one line 
+      nferme ,          &  ! last time step at which the var. are written on file
+      nvinfo ,          &  ! number of total variables 
+      nbvt   ,          &  ! number of time variables
+      naveg                ! number of step for accumulation before averaging
+
+   CHARACTER(len=8) ::  &
+      fmtinf  = '1PE13.5 ' ! format of the output values  
+
+   CHARACTER(len=30) :: &
+      fmtw  ,           &  ! formats
+      fmtr  ,           &  ! ???
+      fmtitr               ! ???
+
+   CHARACTER(len=jpchsep), DIMENSION(jpinfmx) ::   &
+      titvar               ! title of key variables
+
+   REAL(wp), DIMENSION(jpinfmx) ::  &
+      vinfom               ! temporary working space
+   REAL(wp) :: &
+      epsi06 = 1.e-06
+   REAL(wp), DIMENSION(jpi,jpj) ::   &
+      aire                 ! masked grid cell area
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limdia.F90,v 1.5 2005/03/27 18:34:41 opalod Exp $
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_dia
+      !!--------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_dia  ***
+      !!   
+      !! ** Purpose : Computation and outputs on file ice.evolu 
+      !!      the temporal evolution of some key variables
+      !!
+      !! History :
+      !!   8.0  !  97-06  (Louvain-La-Neuve)  Original code
+      !!   8.5  !  02-09  (C. Ethe , G. Madec )  F90: Free form and module
+      !!   9.0  !  05-06  (M. Vancoppenolle LLN) Rehabilitation and fixing a few bugs
+      !!           01-07  (M. Vancoppenolle LLN) added new fields + fram strait
+      !!                                         export
+      !!-------------------------------------------------------------------
+      !! * Local variables
+       INTEGER  ::   jv,ji,jj,jl ! dummy loop indices
+       REAL(wp), DIMENSION(jpinfmx) ::  & 
+          vinfor           ! temporary working space 
+       REAL(wp) ::    &
+          zshift_date   , & ! date from the minimum ice extent
+          zday, zday_min, & ! current day, day of minimum extent
+          zafy, zamy,     & ! temporary area of fy and my ice
+          zindb
+       !!-------------------------------------------------------------------
+
+       ! 0) date from the minimum of ice extent
+       !---------------------------------------
+       zday_min = 273.0        ! zday_min = date of minimum extent, here September 30th
+       zday = FLOAT(numit-nit000) * rdt_ice / ( 86400.0 * FLOAT(nfice) )
+       IF (zday.GT.zday_min) THEN 
+          zshift_date  =  zday - zday_min
+       ELSE
+          zshift_date  =  zday - (365.0 - zday_min)
+       ENDIF
+
+       IF( numit == nstart )   CALL lim_dia_init   ! initialisation of ice_evolu file      
+
+       ! temporal diagnostics 
+       vinfor(1) = REAL(numit)
+       vinfor(2) = nyear
+ 
+       ! put everything to zero
+       DO jv = nbvt + 1, nvinfo
+          vinfor(jv) = 0.0
+       END DO
+
+       !!-------------------------------------------------------------------
+       !! 1) Northern hemisphere
+       !!-------------------------------------------------------------------
+       !! 1.1) Diagnostics independent on age
+       !!------------------------------------
+       DO jj = njeq, jpjm1
+          DO ji = fs_2, fs_jpim1   ! vector opt.
+             IF( tms(ji,jj) == 1 ) THEN
+                vinfor(3)  = vinfor(3)  + at_i(ji,jj)*aire(ji,jj) / 1.0e12 !ice area
+                IF (at_i(ji,jj).GT.0.15) vinfor(5) = vinfor(5) + aire(ji,jj) / 1.0e12 !ice extent
+                vinfor(7)  = vinfor(7)  + vt_i(ji,jj)*aire(ji,jj) / 1.0e12 !ice volume
+                vinfor(9)  = vinfor(9)  + vt_s(ji,jj)*aire(ji,jj) / 1.0e12 !snow volume
+                vinfor(15) = vinfor(15) + ot_i(ji,jj) *vt_i(ji,jj)*aire(ji,jj) / 1.0e12 !mean age
+                vinfor(29) = vinfor(29) + smt_i(ji,jj)*vt_i(ji,jj)*aire(ji,jj) / 1.0e12 !mean salinity
+                ! the computation of this diagnostic is not reliable
+                vinfor(31) = vinfor(31) + vt_i(ji,jj)*( u_ice(ji,jj)*u_ice(ji,jj) + & 
+                                                        v_ice(ji,jj)*v_ice(ji,jj) )*aire(ji,jj)/1.0e12 
+                vinfor(53) = vinfor(53) + fsalt(ji,jj)*aire(ji,jj) / 1.0e12 !salt flux
+                vinfor(55) = vinfor(55) + fsbri(ji,jj)*aire(ji,jj) / 1.0e12 !brine drainage flux
+                vinfor(57) = vinfor(57) + fseqv(ji,jj)*aire(ji,jj) / 1.0e12 !equivalent salt flux
+                vinfor(59) = vinfor(59) + sst_io(ji,jj)*at_i(ji,jj)*aire(ji,jj) / 1.0e12  !SST
+                vinfor(61) = vinfor(61) + sss_io(ji,jj)*at_i(ji,jj)*aire(ji,jj) / 1.0e12  !SSS
+                vinfor(65) = vinfor(65) + et_s(ji,jj)/1.0e9*aire(ji,jj) / 1.0e12  ! snow temperature
+                vinfor(67) = vinfor(67) + et_i(ji,jj)/1.0e9*aire(ji,jj) / 1.0e12       ! ice heat content
+                vinfor(69) = vinfor(69) + v_i(ji,jj,1)*aire(ji,jj) / 1.0e12 !ice volume
+                vinfor(71) = vinfor(71) + v_i(ji,jj,2)*aire(ji,jj) / 1.0e12 !ice volume
+                vinfor(73) = vinfor(73) + v_i(ji,jj,3)*aire(ji,jj) / 1.0e12 !ice volume
+                vinfor(75) = vinfor(75) + v_i(ji,jj,4)*aire(ji,jj) / 1.0e12 !ice volume
+                vinfor(77) = vinfor(77) + v_i(ji,jj,5)*aire(ji,jj) / 1.0e12 !ice volume
+                vinfor(79) = 0.0
+                vinfor(81) = vinfor(81) + fmass(ji,jj)*aire(ji,jj) / 1.0e12 ! mass flux
+             ENDIF
+          END DO
+       END DO
+
+       DO jl = ice_cat_bounds(1,1), ice_cat_bounds(1,2)
+          DO jj = njeq, jpjm1
+             DO ji = fs_2, fs_jpim1   ! vector opt.
+                IF( tms(ji,jj) == 1 ) THEN
+                   vinfor(11) = vinfor(11) + v_i(ji,jj,jl)*aire(ji,jj) / 1.0e12 !undef def ice volume
+                ENDIF
+             END DO
+          END DO
+       END DO
+
+       vinfor(13) = 0.0
+
+       vinfor(15) = vinfor(15) / MAX(vinfor(7),epsi06) ! these have to be divided by total ice volume to have the
+       vinfor(29) = vinfor(29) / MAX(vinfor(7),epsi06) ! right value
+       vinfor(31) = SQRT( vinfor(31) / MAX( vinfor(7) , epsi06 ) )
+       vinfor(67) = vinfor(67) / MAX(vinfor(7),epsi06)
+
+       vinfor(53) = vinfor(53) / MAX(vinfor(5),epsi06) ! these have to be divided by total ice extent to have the
+       vinfor(55) = vinfor(55) / MAX(vinfor(5),epsi06) ! right value 
+       vinfor(57) = vinfor(57) / MAX(vinfor(5),epsi06) ! 
+       vinfor(79) = vinfor(79) / MAX(vinfor(5),epsi06) !
+
+       zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(3))) !
+       vinfor(59) = zindb*vinfor(59) / MAX(vinfor(3),epsi06) ! divide by ice area
+       vinfor(61) = zindb*vinfor(61) / MAX(vinfor(3),epsi06) !
+
+       zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(9))) !
+       vinfor(65) = zindb*vinfor(65) / MAX(vinfor(9),epsi06) ! divide it by snow volume
+
+
+       DO jl = 1, jpl
+          DO jj = njeq, jpjm1
+             DO ji = fs_2, fs_jpim1   ! vector opt.
+                IF( tms(ji,jj) == 1 ) THEN
+                   vinfor(33) = vinfor(33) + d_v_i_trp(ji,jj,jl)*aire(ji,jj) / 1.0e12 !ice volume
+                   vinfor(35) = vinfor(35) + d_v_i_thd(ji,jj,jl)*aire(ji,jj) / 1.0e12 !ice volume
+                ENDIF
+             END DO
+          END DO
+       END DO
+
+       DO jj = njeq, jpjm1
+          DO ji = fs_2, fs_jpim1   ! vector opt.
+                IF( tms(ji,jj) == 1 ) THEN
+                   vinfor(37) = vinfor(37) + diag_sni_gr(ji,jj)*aire(ji,jj) / 1.0e12 !th growth rates
+                   vinfor(39) = vinfor(39) + diag_lat_gr(ji,jj)*aire(ji,jj) / 1.0e12 
+                   vinfor(41) = vinfor(41) + diag_bot_gr(ji,jj)*aire(ji,jj) / 1.0e12
+                   vinfor(43) = vinfor(43) + diag_dyn_gr(ji,jj)*aire(ji,jj) / 1.0e12 
+                   vinfor(45) = vinfor(45) + dv_dt_thd(ji,jj,5)*aire(ji,jj) / 1.0e12
+                   vinfor(47) = vinfor(47) + v_newice(ji,jj) *aire(ji,jj) / 1.0e12 / rdt_ice ! volume acc in OW
+                ENDIF
+          END DO
+       END DO
+
+       DO jl = 1, jpl
+          DO jj = njeq, jpjm1
+             DO ji = fs_2, fs_jpim1   ! vector opt.
+                IF( tms(ji,jj) == 1 ) THEN
+                   vinfor(63) = vinfor(63) + t_su(ji,jj,jl)*a_i(ji,jj,jl)*aire(ji,jj) / 1.0e12
+                ENDIF
+             END DO
+          END DO
+       END DO
+       vinfor(63) = vinfor(63) / MAX(vinfor(3),epsi06) ! these have to be divided by total ice area
+
+       !! 1.2) Diagnostics dependent on age
+       !!------------------------------------
+       DO jj = njeq, jpjm1
+          DO ji = fs_2, fs_jpim1   ! vector opt.
+             IF( tms(ji,jj) == 1 ) THEN
+                zafy = 0.0
+                zamy = 0.0
+                DO jl = 1, jpl
+                   IF ((o_i(ji,jj,jl) - zshift_date).LT.0.0) THEN
+                      vinfor(17) = vinfor(17) + a_i(ji,jj,jl)*aire(ji,jj) / 1.0e12 ! FY ice area
+                      vinfor(25) = vinfor(25) + v_i(ji,jj,jl)*aire(ji,jj) / 1.0e12 ! FY ice volume
+                      vinfor(49) = vinfor(49) + sm_i(ji,jj,jl)*v_i(ji,jj,jl)*aire(ji,jj) / 1.0e12 !FY ice salinity
+                      zafy = zafy + a_i(ji,jj,jl)
+                   ENDIF
+                   IF ((o_i(ji,jj,jl) - zshift_date).GT.0.0) THEN
+                      vinfor(19) = vinfor(19) + a_i(ji,jj,jl)*aire(ji,jj) / 1.0e12    ! MY ice area
+                      vinfor(27) = vinfor(27) + v_i(ji,jj,jl)*aire(ji,jj) / 1.0e12 ! MY ice volume
+                      vinfor(51) = vinfor(51) + sm_i(ji,jj,jl)*v_i(ji,jj,jl)*aire(ji,jj) / 1.0e12 !MY ice salinity
+                      zamy = zamy + a_i(ji,jj,jl)
+                   ENDIF
+                END DO
+                IF ((at_i(ji,jj).GT.0.15).AND.(zafy.GT.zamy)) THEN
+                   vinfor(21) = vinfor(21) + aire(ji,jj) / 1.0e12 ! Seasonal ice extent
+                ENDIF
+                IF ((at_i(ji,jj).GT.0.15).AND.(zafy.LE.zamy)) THEN
+                   vinfor(23) = vinfor(23) + aire(ji,jj) / 1.0e12 ! Perennial ice extent
+                ENDIF
+             ENDIF
+          END DO
+       END DO
+       zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(25))) !=0 if no multiyear ice 1 if yes
+       vinfor(49) = zindb*vinfor(49) / MAX(vinfor(25),epsi06)
+       zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(27))) !=0 if no multiyear ice 1 if yes
+       vinfor(51) = zindb*vinfor(51) / MAX(vinfor(27),epsi06)
+       
+       !! Fram Strait Export
+       !! 83 = area export
+       !! 84 = volume export
+       !! Fram strait in ORCA2 = 5 points
+       !! export = -v_ice*e1t*ddtb*at_i or -v_ice*e1t*ddtb*at_i*h_i
+       jj = 136 ! C grid
+       vinfor(83) = 0.0
+       vinfor(84) = 0.0
+       DO ji = 134, 138
+          vinfor(83) = vinfor(83) - v_ice(ji,jj) * & 
+                                      e1t(ji,jj)*at_i(ji,jj)*rdt_ice / 1.0e12
+          vinfor(84) = vinfor(84) - v_ice(ji,jj) * & 
+                                      e1t(ji,jj)*vt_i(ji,jj)*rdt_ice / 1.0e12
+       END DO
+
+       !!-------------------------------------------------------------------
+       !! 2) Southern hemisphere
+       !!-------------------------------------------------------------------
+       !! 2.1) Diagnostics independent on age
+       !!------------------------------------
+       DO jj = 2, njeqm1
+          DO ji = fs_2, fs_jpim1   ! vector opt.
+             IF( tms(ji,jj) == 1 ) THEN
+                vinfor(4)  = vinfor(4)  + at_i(ji,jj)*aire(ji,jj) / 1.0e12 !ice area
+                IF (at_i(ji,jj).GT.0.15) vinfor(6) = vinfor(6) + aire(ji,jj) / 1.0e12 !ice extent
+                vinfor(8)  = vinfor(8)  + vt_i(ji,jj)*aire(ji,jj) / 1.0e12 !ice volume
+                vinfor(10) = vinfor(10) + vt_s(ji,jj)*aire(ji,jj) / 1.0e12 !snow volume
+                vinfor(16) = vinfor(16) + ot_i(ji,jj)*vt_i(ji,jj)*aire(ji,jj) / 1.0e12 !mean age
+                vinfor(30) = vinfor(30) + smt_i(ji,jj)*vt_i(ji,jj)*aire(ji,jj) / 1.0e12 !mean salinity
+                ! this diagnostic is not well computed (weighted by vol instead
+                ! of area)
+                vinfor(32) = vinfor(32) + vt_i(ji,jj)*( u_ice(ji,jj)*u_ice(ji,jj) + & 
+                                                        v_ice(ji,jj)*v_ice(ji,jj) )*aire(ji,jj)/1.0e12 !ice vel
+                vinfor(54) = vinfor(54) + at_i(ji,jj)*fsalt(ji,jj)*aire(ji,jj) / 1.0e12 ! Total salt flux
+                vinfor(56) = vinfor(56) + at_i(ji,jj)*fsbri(ji,jj)*aire(ji,jj) / 1.0e12 ! Brine drainage salt flux
+                vinfor(58) = vinfor(58) + at_i(ji,jj)*fseqv(ji,jj)*aire(ji,jj) / 1.0e12 ! Equivalent salt flux
+                vinfor(60) = vinfor(60) + sst_io(ji,jj)*at_i(ji,jj)*aire(ji,jj) / 1.0e12  !SST
+                vinfor(62) = vinfor(62) + sss_io(ji,jj)*at_i(ji,jj)*aire(ji,jj) / 1.0e12  !SSS
+                vinfor(66) = vinfor(66) + et_s(ji,jj)/1.0e9*aire(ji,jj) / 1.0e12 ! snow temperature
+                vinfor(68) = vinfor(68) + et_i(ji,jj)/1.0e9*aire(ji,jj) / 1.0e12 ! ice enthalpy
+                vinfor(70) = vinfor(70) + v_i(ji,jj,1)*aire(ji,jj) / 1.0e12 !ice volume
+                vinfor(72) = vinfor(72) + v_i(ji,jj,2)*aire(ji,jj) / 1.0e12 !ice volume
+                vinfor(74) = vinfor(74) + v_i(ji,jj,3)*aire(ji,jj) / 1.0e12 !ice volume
+                vinfor(76) = vinfor(76) + v_i(ji,jj,4)*aire(ji,jj) / 1.0e12 !ice volume
+                vinfor(78) = vinfor(78) + v_i(ji,jj,5)*aire(ji,jj) / 1.0e12 !ice volume
+                vinfor(80) = 0.0
+                vinfor(82) = vinfor(82) + fmass(ji,jj)*aire(ji,jj) / 1.0e12 ! mass flux
+             ENDIF
+          END DO
+       END DO
+
+       DO jl = ice_cat_bounds(1,1), ice_cat_bounds(1,2)
+          DO jj = 2, njeqm1
+             DO ji = fs_2, fs_jpim1   ! vector opt.
+                vinfor(12) = vinfor(12) + v_i(ji,jj,jl)*aire(ji,jj) / 1.0e12 !undef def ice volume
+             END DO
+          END DO
+       END DO
+
+       vinfor(14) = 0.0
+
+       zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(8))) 
+       vinfor(16) = zindb * vinfor(16) / MAX(vinfor(8),epsi06) ! these have to be divided by ice vol
+       vinfor(30) = zindb * vinfor(30) / MAX(vinfor(8),epsi06) ! 
+       vinfor(32) = zindb * SQRT( vinfor(32) / MAX( vinfor(8) , epsi06 ) )
+       vinfor(68) = zindb * vinfor(68) / MAX(vinfor(8),epsi06) ! 
+
+       zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(6))) 
+       vinfor(54) = zindb * vinfor(54) / MAX(vinfor(6),epsi06) ! these have to be divided by ice extt
+       vinfor(56) = zindb * vinfor(56) / MAX(vinfor(6),epsi06) ! 
+       vinfor(58) = zindb * vinfor(58) / MAX(vinfor(6),epsi06) ! 
+       vinfor(80) = zindb * vinfor(80) / MAX(vinfor(6),epsi06) !
+!      vinfor(84) = vinfor(84) / vinfor(6) !
+ 
+       zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(4))) !
+       vinfor(60) = zindb*vinfor(60) / ( MAX(vinfor(4), epsi06) ) ! divide by ice area
+       vinfor(62) = zindb*vinfor(62) / ( MAX(vinfor(4), epsi06) ) !
+
+       zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(10))) !
+       vinfor(66) = zindb*vinfor(66) / MAX(vinfor(10),epsi06) ! divide it by snow volume
+
+       DO jl = 1, jpl
+          DO jj = 2, njeqm1
+             DO ji = fs_2, fs_jpim1   ! vector opt.
+                IF( tms(ji,jj) == 1 ) THEN
+                   vinfor(34) = vinfor(34) + d_v_i_trp(ji,jj,jl)*aire(ji,jj) / 1.0e12 !ice volume
+                   vinfor(36) = vinfor(36) + d_v_i_thd(ji,jj,jl)*aire(ji,jj) / 1.0e12 !ice volume
+                ENDIF
+             END DO
+          END DO
+       END DO
+
+       DO jj = 2, njeqm1
+          DO ji = fs_2, fs_jpim1   ! vector opt.
+                IF( tms(ji,jj) == 1 ) THEN
+                   vinfor(38) = vinfor(38) + diag_sni_gr(ji,jj)*aire(ji,jj) / 1.0e12 !th growth rates
+                   vinfor(40) = vinfor(40) + diag_lat_gr(ji,jj)*aire(ji,jj) / 1.0e12 
+                   vinfor(42) = vinfor(42) + diag_bot_gr(ji,jj)*aire(ji,jj) / 1.0e12
+                   vinfor(44) = vinfor(44) + diag_dyn_gr(ji,jj)*aire(ji,jj) / 1.0e12 
+                   vinfor(46) = vinfor(46) + dv_dt_thd(ji,jj,5)*aire(ji,jj) / 1.0e12
+                   vinfor(48) = vinfor(48) + v_newice(ji,jj) *aire(ji,jj) / 1.0e12 / rdt_ice ! volume acc in OW
+                ENDIF
+          END DO
+       END DO
+
+
+       DO jl = 1, jpl
+          DO jj = 2, njeqm1
+             DO ji = fs_2, fs_jpim1   ! vector opt.
+                IF( tms(ji,jj) == 1 ) THEN
+                   vinfor(64) = vinfor(64) + t_su(ji,jj,jl)*a_i(ji,jj,jl)*aire(ji,jj) / 1.0e12
+                ENDIF
+             END DO
+          END DO
+       END DO
+       zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(4))) !
+       vinfor(64) = zindb * vinfor(64) / MAX(vinfor(4),epsi06) ! divide by ice extt
+       !! 2.2) Diagnostics dependent on age
+       !!------------------------------------
+       DO jj = 2, njeqm1
+          DO ji = fs_2, fs_jpim1   ! vector opt.
+             IF( tms(ji,jj) == 1 ) THEN
+                zafy = 0.0
+                zamy = 0.0
+                DO jl = 1, jpl
+                   IF ((o_i(ji,jj,jl) - zshift_date).LT.0.0) THEN
+                      vinfor(18) = vinfor(18) + a_i(ji,jj,jl)*aire(ji,jj) / 1.0e12 ! FY ice area
+                      vinfor(26) = vinfor(26) + v_i(ji,jj,jl)*aire(ji,jj) / 1.0e12 ! FY ice volume
+                      zafy = zafy + a_i(ji,jj,jl)
+                      vinfor(50) = vinfor(50) + sm_i(ji,jj,jl)*v_i(ji,jj,jl)*aire(ji,jj) / 1.0e12 !FY ice salinity
+                   ENDIF
+                   IF ((o_i(ji,jj,jl) - zshift_date).GT.0.0) THEN
+                      vinfor(20) = vinfor(20) + a_i(ji,jj,jl)*aire(ji,jj) / 1.0e12    ! MY ice area
+                      vinfor(28) = vinfor(28) + v_i(ji,jj,jl)*aire(ji,jj) / 1.0e12
+                      vinfor(52) = vinfor(52) + sm_i(ji,jj,jl)*v_i(ji,jj,jl)*aire(ji,jj) / 1.0e12 !FY ice salinity
+                      zamy = zamy + a_i(ji,jj,jl)
+                   ENDIF
+                END DO ! jl
+                IF ((at_i(ji,jj).GT.0.15).AND.(zafy.GT.zamy)) THEN
+                   vinfor(22) = vinfor(22) + aire(ji,jj) / 1.0e12 ! Seasonal ice extent
+                ENDIF
+                IF ((at_i(ji,jj).GT.0.15).AND.(zafy.LE.zamy)) THEN
+                   vinfor(24) = vinfor(24) + aire(ji,jj) / 1.0e12 ! Perennial ice extent
+                ENDIF
+             ENDIF ! tms
+          END DO ! jj
+       END DO ! ji
+       zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(26))) !=0 if no multiyear ice 1 if yes
+       vinfor(50) = zindb*vinfor(50) / MAX(vinfor(26),epsi06)
+       zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(28))) !=0 if no multiyear ice 1 if yes
+       vinfor(52) = zindb*vinfor(52) / MAX(vinfor(28),epsi06)
+
+       !  Accumulation before averaging 
+       DO jv = 1, nvinfo
+          vinfom(jv) = vinfom(jv) + vinfor(jv)
+       END DO
+       naveg = naveg + 1  
+    
+       ! oututs on file ice_evolu    
+!MV      IF( MOD( numit , ninfo ) == 0 ) THEN
+          WRITE(90,fmtw) ( titvar(jv), vinfom(jv)/naveg, jv = 1, nvinfo )
+          naveg = 0
+          DO jv = 1, nvinfo
+             vinfom(jv)=0.0
+          END DO
+!MV      ENDIF
+  
+    END SUBROUTINE lim_dia
+ 
+    SUBROUTINE lim_dia_init
+       !!-------------------------------------------------------------------
+       !!                  ***  ROUTINE lim_dia_init  ***
+       !!             
+       !! ** Purpose : Preparation of the file ice_evolu for the output of
+       !!      the temporal evolution of key variables
+       !!
+       !! ** input   : Namelist namicedia
+       !!
+       !! history :
+       !!  8.5  ! 03-08 (C. Ethe) original code
+       !!  9.0  ! 08-03 (M. Vancoppenolle) LIM3
+       !!-------------------------------------------------------------------
+       NAMELIST/namicedia/fmtinf, nfrinf, ninfo, ntmoy
+
+       INTEGER  ::   jv   ,     &  ! dummy loop indice
+          &          ntot ,     &
+          &          ndeb ,     &
+          &          irecl
+
+       REAL(wp) ::   zxx0, zxx1    ! temporary scalars
+
+       CHARACTER(len=jpchinf) ::   titinf
+       !!-------------------------------------------------------------------
+
+
+       ! Read Namelist namicedia
+       REWIND ( numnam_ice )
+       READ   ( numnam_ice  , namicedia )
+       IF(lwp) THEN
+          WRITE(numout,*)
+          WRITE(numout,*) 'lim_dia_init : ice parameters for ice diagnostics '
+          WRITE(numout,*) '~~~~~~~~~~~~'
+          WRITE(numout,*) '   format of the output values                                 fmtinf = ', fmtinf
+          WRITE(numout,*) '   number of variables written in one line                     nfrinf = ', nfrinf 
+          WRITE(numout,*) '   Instantaneous values of ice evolution or averaging          ntmoy  = ', ntmoy
+          WRITE(numout,*) '   frequency of ouputs on file ice_evolu in case of averaging  ninfo  = ', ninfo
+       ENDIF
+
+       ! masked grid cell area
+       aire(:,:) = area(:,:) * tms(:,:)
+
+       ! Titles of ice key variables :
+       titvar(1) = 'NoIt'  ! iteration number
+       titvar(2) = 'T yr'  ! time step in years
+       nbvt = 2            ! number of time variables
+
+       titvar(3) = 'AI_N'  ! sea ice area in the northern Hemisp.(10^12 km2)
+       titvar(4) = 'AI_S'  ! sea ice area in the southern Hemisp.(10^12 km2)
+       titvar(5) = 'EI_N'  ! sea ice extent (15%) in the northern Hemisp.(10^12 km2)
+       titvar(6) = 'EI_S'  ! sea ice extent (15%) in the southern Hemisp.(10^12 km2)
+       titvar(7) = 'VI_N'  ! sea ice volume in the northern Hemisp.(10^3 km3)
+       titvar(8) = 'VI_S'  ! sea ice volume in the southern Hemisp.(10^3 km3)
+       titvar(9) = 'VS_N'  ! snow volume over sea ice in the northern Hemisp.(10^3 km3)
+       titvar(10)= 'VS_S'  ! snow volume over sea ice in the northern Hemisp.(10^3 km3)
+       titvar(11)= 'VuIN'  ! undeformed sea ice volume in the northern Hemisp.(10^3 km3)
+       titvar(12)= 'VuIS'  ! undeformed sea ice volume in the southern Hemisp.(10^3 km3)
+       titvar(13)= 'VdIN'  ! deformed sea ice volume in the northern Hemisp.(10^3 km3)
+       titvar(14)= 'VdIS'  ! deformed sea ice volume in the southern Hemisp.(10^3 km3)
+       titvar(15)= 'OI_N'  ! sea ice mean age in the northern Hemisp.(years)
+       titvar(16)= 'OI_S'  ! sea ice mean age in the southern Hemisp.(years)
+       titvar(17)= 'AFYN'  ! total FY ice area northern Hemisp.(10^12 km2)
+       titvar(18)= 'AFYS'  ! total FY ice area southern Hemisp.(10^12 km2)
+       titvar(19)= 'AMYN'  ! total MY ice area northern Hemisp.(10^12 km2)
+       titvar(20)= 'AMYS'  ! total MY ice area southern Hemisp.(10^12 km2)
+       titvar(21)= 'EFYN'  ! total FY ice extent northern Hemisp.(10^12 km2) (with more 50% FY ice)
+       titvar(22)= 'EFYS'  ! total FY ice extent southern Hemisp.(10^12 km2) (with more 50% FY ice)
+       titvar(23)= 'EMYN'  ! total MY ice extent northern Hemisp.(10^12 km2) (with more 50% MY ice)
+       titvar(24)= 'EMYS'  ! total MY ice extent southern Hemisp.(10^12 km2) (with more 50% MY ice)
+       titvar(25)= 'VFYN'  ! total undeformed FY ice volume northern Hemisp.(10^3 km3) 
+       titvar(26)= 'VFYS'  ! total undeformed FY ice volume southern Hemisp.(10^3 km3)
+       titvar(27)= 'VMYN'  ! total undeformed MY ice volume northern Hemisp.(10^3 km3) 
+       titvar(28)= 'VMYS'  ! total undeformed MY ice volume southern Hemisp.(10^3 km3) 
+       titvar(29)= 'IS_N'  ! sea ice mean salinity in the northern hemisphere (ppt)  
+       titvar(30)= 'IS_S'  ! sea ice mean salinity in the southern hemisphere (ppt)  
+       titvar(31)= 'IVeN'  ! sea ice mean velocity in the northern hemisphere (m/s) 
+       titvar(32)= 'IVeS'  ! sea ice mean velocity in the southern hemisphere (m/s) 
+       titvar(33)= 'DVDN'  ! variation of sea ice volume due to dynamics in the northern hemisphere
+       titvar(34)= 'DVDS'  ! variation of sea ice volume due to dynamics in the southern hemisphere
+       titvar(35)= 'DVTN'  ! variation of sea ice volume due to thermo in the   northern hemisphere
+       titvar(36)= 'DVTS'  ! variation of sea ice volume due to thermo in the   southern hemisphere
+       titvar(37)= 'TG1N'  ! thermodynamic vertical growth rate in the northern hemisphere, cat 1  
+       titvar(38)= 'TG1S'  ! thermodynamic vertical growth rate in the souhtern hemisphere, cat 1  
+       titvar(39)= 'TG2N'  ! thermodynamic vertical growth rate in the northern hemisphere, cat 2  
+       titvar(40)= 'TG2S'  ! thermodynamic vertical growth rate in the souhtern hemisphere, cat 2  
+       titvar(41)= 'TG3N'  ! thermodynamic vertical growth rate in the northern hemisphere, cat 3  
+       titvar(42)= 'TG3S'  ! thermodynamic vertical growth rate in the souhtern hemisphere, cat 3  
+       titvar(43)= 'TG4N'  ! thermodynamic vertical growth rate in the northern hemisphere, cat 4  
+       titvar(44)= 'TG4S'  ! thermodynamic vertical growth rate in the souhtern hemisphere, cat 4  
+       titvar(45)= 'TG5N'  ! thermodynamic vertical growth rate in the northern hemisphere, cat 5  
+       titvar(46)= 'TG5S'  ! thermodynamic vertical growth rate in the souhtern hemisphere, cat 5  
+       titvar(47)= 'LA_N'  ! lateral accretion growth rate, northern hemisphere
+       titvar(48)= 'LA_S'  ! lateral accretion growth rate, southern hemisphere 
+       titvar(49)= 'SF_N'  ! Salinity FY, NH 
+       titvar(50)= 'SF_S'  ! Salinity FY, SH 
+       titvar(51)= 'SF_N'  ! Salinity MY, NH 
+       titvar(52)= 'SF_S'  ! Salinity MY, SH 
+       titvar(53)= 'Fs_N'  ! Total salt flux NH
+       titvar(54)= 'Fs_S'  ! Total salt flux SH
+       titvar(55)= 'FsbN'  ! Salt - brine drainage flux NH
+       titvar(56)= 'FsbS'  ! Salt - brine drainage flux SH
+       titvar(57)= 'FseN'  ! Salt - Equivalent salt flux NH
+       titvar(58)= 'FseS'  ! Salt - Equivalent salt flux SH
+       titvar(59)= 'SSTN'  ! SST, NH
+       titvar(60)= 'SSTS'  ! SST, SH
+       titvar(61)= 'SSSN'  ! SSS, NH
+       titvar(62)= 'SSSS'  ! SSS, SH
+       titvar(63)= 'TsuN'  ! Tsu, NH
+       titvar(64)= 'TsuS'  ! Tsu, SH
+       titvar(65)= 'TsnN'  ! Tsn, NH
+       titvar(66)= 'TsnS'  ! Tsn, SH
+       titvar(67)= 'ei_N'  ! ei, NH
+       titvar(68)= 'ei_S'  ! ei, SH
+       titvar(69)= 'vi1N'  ! vi1, NH
+       titvar(70)= 'vi1S'  ! vi1, SH
+       titvar(71)= 'vi2N'  ! vi2, NH
+       titvar(72)= 'vi2S'  ! vi2, SH
+       titvar(73)= 'vi3N'  ! vi3, NH
+       titvar(74)= 'vi3S'  ! vi3, SH
+       titvar(75)= 'vi4N'  ! vi4, NH
+       titvar(76)= 'vi4S'  ! vi4, SH
+       titvar(77)= 'vi5N'  ! vi5, NH
+       titvar(78)= 'vi5S'  ! vi5, SH
+       titvar(79)= 'vi6N'  ! vi6, NH
+       titvar(80)= 'vi6S'  ! vi6, SH
+       titvar(81)= 'fmaN'  ! mass flux in the ocean, NH
+       titvar(82)= 'fmaS'  ! mass flux in the ocean, SH
+       titvar(83)= 'AFSE'  ! Fram Strait Area export
+       titvar(84)= 'VFSE'  ! Fram Strait Volume export
+       nvinfo = 84
+
+       ! Definition et Ecriture de l'entete : nombre d'enregistrements 
+       ndeb   = ( nstart - 1 ) / ninfo
+       IF( nstart == 1 ) ndeb = -1
+
+       nferme = ( nstart - 1 + nitrun) / ninfo
+       ntot   = nferme - ndeb
+       ndeb   = ninfo * ( 1 + ndeb )
+       nferme = ninfo * nferme
+
+       ! definition of formats 
+       WRITE( fmtw  , '(A,I3,A2,I1,A)' )  '(', nfrinf, '(A', jpchsep, ','//fmtinf//'))'
+       WRITE( fmtr  , '(A,I3,A,I1,A)'  )  '(', nfrinf, '(', jpchsep, 'X,'//fmtinf//'))'
+       WRITE( fmtitr, '(A,I3,A,I1,A)'  )  '(', nvinfo, 'A', jpchinf, ')'
+
+       ! opening  "ice_evolu" file
+       irecl = ( jpchinf + 1 ) * nvinfo 
+       OPEN( 90, file='ice.evolu', status='unknown', RECL = irecl)
+       OPEN( 90, file='ice.evolu', status='unknown')
+
+       !- ecriture de 2 lignes d''entete :
+       WRITE(90,1000) fmtr, fmtw, fmtitr, nvinfo, ntot, 0, nfrinf
+       zxx0 = 0.001 * REAL(ninfo)
+       zxx1 = 0.001 * REAL(ndeb)
+       WRITE(90,1111) REAL(jpchinf), 0., zxx1, zxx0, 0., 0., 0
+
+       !- ecriture de 2 lignes de titre :
+       WRITE(90,'(A,I8,A,I8,A,I5)')                                      &
+          'Evolution chronologique - Experience '//cexper   &
+          //'   de', ndeb, ' a', nferme, ' pas', ninfo
+       WRITE(90,fmtitr) ( titvar(jv), jv = 1, nvinfo )
+
+
+       !--preparation de "titvar" pour l''ecriture parmi les valeurs numeriques :
+       DO  jv = 2 , nvinfo
+          titinf     = titvar(jv)(:jpchinf)
+          titvar(jv) = '  '//titinf
+       END DO
+
+       !--Initialisation of the arrays for the accumulation
+       DO  jv = 1, nvinfo
+          vinfom(jv) = 0.
+       END DO
+       naveg = 0
+
+1000   FORMAT( 3(A20),4(1x,I6) )
+1111   FORMAT( 3(F7.1,1X,F7.3,1X),I3,A )  
+
+    END SUBROUTINE lim_dia_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                               NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_dia         ! Empty routine
+   END SUBROUTINE lim_dia
+#endif
+
+   !!======================================================================
+END MODULE limdia
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limdyn.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limdyn.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limdyn.F90	(revision 884)
@@ -0,0 +1,386 @@
+MODULE limdyn
+   !!======================================================================
+   !!                     ***  MODULE  limdyn  ***
+   !!   Sea-Ice dynamics :  
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' :                                 LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!    lim_dyn      : computes ice velocities
+   !!    lim_dyn_init : initialization and namelist read
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE phycst
+   USE in_out_manager  ! I/O manager
+   USE dom_ice
+   USE dom_oce         ! ocean space and time domain
+   USE taumod
+   USE ice
+   USE par_ice
+   USE ice_oce
+   USE iceini
+   USE limistate
+   USE limrhg          ! ice rheology
+   USE lbclnk
+   USE lib_mpp
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC lim_dyn  ! routine called by ice_step
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+
+   !! * Module variables
+   REAL(wp)  ::  rone    = 1.e0   ! constant value
+
+   !!----------------------------------------------------------------------
+   !!   LIM 3.0,  UCL-ASTR-LOCEAN-IPSL (2008)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limdyn.F90,v 1.5 2005/03/27 18:34:41 opalod Exp $
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_dyn
+      !!-------------------------------------------------------------------
+      !!               ***  ROUTINE lim_dyn  ***
+      !!               
+      !! ** Purpose :   compute ice velocity and ocean-ice stress
+      !!                
+      !! ** Method  : 
+      !!
+      !! ** Action  : - Initialisation
+      !!              - Call of the dynamic routine for each hemisphere
+      !!              - computation of the stress at the ocean surface         
+      !!              - treatment of the case if no ice dynamic
+      !! History :
+      !!   1.0  !  01-04   (LIM)  Original code
+      !!   2.0  !  02-08   (C. Ethe, G. Madec)  F90, mpp
+      !!   3.0  !  2007-03 (M.A. Morales Maqueda, S. Bouillon, M. Vancoppenolle) 
+      !!                   LIM3, EVP, C-grid
+      !!------------------------------------------------------------------------------------
+      !! * Local variables
+      INTEGER ::   ji, jj, jl, ja    ! dummy loop indices
+      INTEGER :: i_j1, i_jpj         ! Starting/ending j-indices for rheology
+
+      REAL(wp) ::   &
+         ztairx, ztairy,          &  ! tempory scalars
+         zsang , zmod,            &
+         ztglx , ztgly ,          &
+         zt11, zt12, zt21, zt22 , &
+         zustm,                   &
+         zsfrldmx2, zsfrldmy2,    &
+         zu_ice, zv_ice, ztair2
+
+      REAL(wp),DIMENSION(jpj) ::   &
+           zind,                     &  ! i-averaged indicator of sea-ice
+           zmsk                         ! i-averaged of tmask
+      !!---------------------------------------------------------------------
+
+      WRITE(numout,*) ' lim_dyn : Ice dynamics '
+      WRITE(numout,*) ' ~~~~~~~ '
+
+      IF( numit == nstart  )   CALL lim_dyn_init   ! Initialization (first time-step only)
+      
+      IF ( ln_limdyn ) THEN
+
+         ! ocean velocity
+         u_oce(:,:)  = u_io(:,:) * tmu(:,:)
+         v_oce(:,:)  = v_io(:,:) * tmv(:,:)
+         
+         old_u_ice(:,:) = u_ice(:,:) * tmu(:,:)
+         old_v_ice(:,:) = v_ice(:,:) * tmv(:,:)
+
+         ! Rheology (ice dynamics)
+         ! ========
+
+         !  Define the j-limits where ice rheology is computed
+         ! ---------------------------------------------------
+
+         IF( lk_mpp .OR. nbit_cmp == 1 ) THEN                    ! mpp: compute over the whole domain
+            i_j1 = 1
+            i_jpj = jpj
+            IF(ln_ctl) CALL prt_ctl_info( 'lim_dyn  :    i_j1 = ', ivar1=i_j1, clinfo2=' ij_jpj = ', ivar2=i_jpj )
+            CALL lim_rhg( i_j1, i_jpj )
+         ELSE                                 ! optimization of the computational area
+
+            DO jj = 1, jpj
+               zind(jj) = SUM( 1.0 - at_i (:,jj  ) )   ! = FLOAT(jpj) if ocean everywhere on a j-line
+               zmsk(jj) = SUM( tmask(:,jj,1) )   ! = 0          if land  everywhere on a j-line
+            END DO
+
+            IF( l_jeq ) THEN                     ! local domain include both hemisphere
+               !                                 ! Rheology is computed in each hemisphere
+               !                                 ! only over the ice cover latitude strip
+               ! Northern hemisphere
+               i_j1  = njeq
+               i_jpj = jpj
+               DO WHILE ( i_j1 <= jpj .AND. zind(i_j1) == FLOAT(jpi) .AND. zmsk(i_j1) /=0 )
+                  i_j1 = i_j1 + 1
+               END DO
+               i_j1 = MAX( 1, i_j1-1 )
+               IF(ln_ctl) CALL prt_ctl_info( 'lim_dyn  : NH  i_j1 = ', ivar1=i_j1, clinfo2=' ij_jpj = ', ivar2=i_jpj )
+               CALL lim_rhg( i_j1, i_jpj )
+
+               ! Southern hemisphere
+               i_j1  =  1
+               i_jpj = njeq
+               DO WHILE ( i_jpj >= 1 .AND. zind(i_jpj) == FLOAT(jpi) .AND. zmsk(i_jpj) /=0 )
+                  i_jpj = i_jpj - 1
+               END DO
+               i_jpj = MIN( jpj, i_jpj+2 )
+               IF(ln_ctl) CALL prt_ctl_info( 'lim_dyn  : SH  i_j1 = ', ivar1=i_j1, clinfo2=' ij_jpj = ', ivar2=i_jpj )
+
+               CALL lim_rhg( i_j1, i_jpj )
+
+            ELSE                                 ! local domain extends over one hemisphere only
+               !                                 ! Rheology is computed only over the ice cover
+               !                                 ! latitude strip
+               i_j1  = 1
+               DO WHILE ( i_j1 <= jpj .AND. zind(i_j1) == FLOAT(jpi) .AND. zmsk(i_j1) /=0 )
+                  i_j1 = i_j1 + 1
+               END DO
+               i_j1 = MAX( 1, i_j1-1 )
+
+               i_jpj  = jpj
+               DO WHILE ( i_jpj >= 1  .AND. zind(i_jpj) == FLOAT(jpi) .AND. zmsk(i_jpj) /=0 )
+                  i_jpj = i_jpj - 1
+               END DO
+               i_jpj = MIN( jpj, i_jpj+2)
+
+               IF(ln_ctl) CALL prt_ctl_info( 'lim_dyn  : one hemisphere:  i_j1 = ', ivar1=i_j1, clinfo2=' ij_jpj = ', ivar2=i_jpj )
+
+               CALL lim_rhg( i_j1, i_jpj )
+
+            ENDIF
+
+         ENDIF
+
+         ! Ice-Ocean stress
+         ! ================
+         DO jj = 2, jpjm1
+            zsang  = SIGN(1.e0, gphif(1,jj-1) ) * sangvg
+
+            DO ji = fs_2, fs_jpim1
+               ! computation of wind stress over ocean in X and Y direction
+#if defined key_coupled && defined key_lim_cp1
+!              ztairx =  ( 1.0 - at_i(ji-1,jj)   ) * gtaux(ji-1,jj)   + &
+!                        ( 1.0 - at_i(ji,jj)     ) * gtaux(ji,jj  )   + &
+!                        ( 1.0 - at_i(ji-1,jj-1) ) * gtaux(ji-1,jj-1) + & 
+!                        ( 1.0 - at_i(ji,jj-1)   ) * gtaux(ji,jj-1)
+
+!              ztairy =  ( 1.0 - at_i(ji-1,jj)   ) * gtauy(ji-1,jj  ) + &
+!                        ( 1.0 - at_i(ji,jj  )   ) * gtauy(ji,jj    ) + &
+!                        ( 1.0 - at_i(ji-1,jj-1) ) * gtauy(ji-1,jj-1) + & 
+!                        ( 1.0 - at_i(ji,jj-1)   ) * gtauy(ji,jj-1)
+#else
+               ztairx =  ( 2.0 - at_i(ji,jj) - at_i(ji+1,jj) ) * gtaux(ji,jj) / cai * cao
+               ztairy =  ( 2.0 - at_i(ji,jj) - at_i(ji,jj+1) ) * gtauy(ji,jj) / cai * cao
+
+               zsfrldmx2 = at_i(ji,jj) + at_i(ji+1,jj)
+               zsfrldmy2 = at_i(ji,jj) + at_i(ji,jj+1)
+
+#endif
+               zu_ice   = u_ice(ji,jj) - u_oce(ji,jj)
+               zv_ice   = v_ice(ji,jj) - v_oce(ji,jj)
+               zmod     = SQRT( zu_ice * zu_ice + zv_ice * zv_ice ) 
+
+               ! quadratic drag formulation
+               ztglx   = zsfrldmx2 * rhoco * zmod * ( cangvg * zu_ice - zsang * zv_ice ) 
+               ztgly   = zsfrldmy2 * rhoco * zmod * ( cangvg * zv_ice + zsang * zu_ice ) 
+!
+!              ! IMPORTANT
+!              ! these lignes are bound to prevent numerical oscillations
+!              ! in the ice-ocean stress
+!              ! They are physically ill-based. There is a cleaner solution
+!              ! to try (remember discussion in Paris Gurvan)
+!
+               ztglx   = ztglx * exp( - zmod / 0.5 )
+               ztgly   = ztglx * exp( - zmod / 0.5 )
+
+               tio_u(ji,jj) = - ( ztairx + 1.0 * ztglx ) / ( 2. * rau0 )
+               tio_v(ji,jj) = - ( ztairy + 1.0 * ztgly ) / ( 2. * rau0 )
+            END DO
+         END DO
+         
+         ! computation of friction velocity
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+
+               zu_ice   = u_ice(ji,jj) - u_io(ji,jj)
+               zt11  = rhoco * zu_ice * zu_ice
+
+               zu_ice   = u_ice(ji-1,jj) - u_io(ji-1,jj)
+               zt12  = rhoco * zu_ice * zu_ice
+
+               zv_ice   = v_ice(ji,jj) - v_io(ji,jj)
+               zt21  = rhoco * zv_ice * zv_ice
+
+               zv_ice   = v_ice(ji,jj-1) - v_io(ji,jj-1)
+               zt22  = rhoco * zv_ice * zv_ice
+               ztair2 = ( ( gtaux(ji,jj) + gtaux(ji-1,jj) ) / 2. )**2 + &
+                        ( ( gtauy(ji,jj) + gtauy(ji,jj-1) ) / 2. )**2
+
+               ! should not be weighted
+               zustm =  ( at_i(ji,jj)       ) * 0.5 * ( zt11 + zt12 + zt21 + zt22 )        &
+                  &  +  ( 1.0 - at_i(ji,jj) ) * SQRT( ztair2 )
+
+               ust2s(ji,jj) = ( zustm / rau0 ) * ( rone + sdvt(ji,jj) ) * tms(ji,jj)
+
+            END DO
+         END DO
+
+       ELSE      ! If no ice dynamics  
+                    
+               ! virer ca (key_lim_cp1)
+          DO jj = 2, jpjm1
+             DO ji = fs_2, fs_jpim1
+#if defined key_coupled && defined key_lim_cp1
+                tio_u(ji,jj) = - (  gtaux(ji  ,jj  ) + gtaux(ji-1,jj  )       &
+                   &              + gtaux(ji-1,jj-1) + gtaux(ji  ,jj-1) ) / ( 4 * rau0 )
+
+                tio_v(ji,jj) = - (  gtauy(ji  ,jj )  + gtauy(ji-1,jj  )       &
+                   &              + gtauy(ji-1,jj-1) + gtauy(ji  ,jj-1) ) / ( 4 * rau0 )
+#else
+                tio_u(ji,jj) = - gtaux(ji,jj) / cai * cao / rau0
+                tio_v(ji,jj) = - gtauy(ji,jj) / cai * cao / rau0 
+#endif
+                ztair2 = ( ( gtaux(ji,jj) + gtaux(ji-1,jj) ) / 2. )**2 + &
+                         ( ( gtauy(ji,jj) + gtauy(ji,jj-1) ) / 2. )**2
+                zustm        = SQRT( ztair2  )
+
+                ust2s(ji,jj) = ( zustm / rau0 ) * ( rone + sdvt(ji,jj) ) * tms(ji,jj)
+            END DO
+         END DO
+
+      ENDIF
+
+      CALL lbc_lnk( ust2s, 'T',  1. )   ! T-point
+      CALL lbc_lnk( tio_u, 'U', -1. )   ! I-point (i.e. ice U-V point)
+      CALL lbc_lnk( tio_v, 'V', -1. )   ! I-point (i.e. ice U-V point)
+
+      IF(ln_ctl) THEN   ! Control print
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Cell values : ')
+         CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
+         CALL prt_ctl(tab2d_1=tio_u     , clinfo1=' lim_dyn  : tio_u     :', tab2d_2=tio_v , clinfo2=' tio_v :')
+         CALL prt_ctl(tab2d_1=ust2s     , clinfo1=' lim_dyn  : ust2s     :')
+         CALL prt_ctl(tab2d_1=divu_i    , clinfo1=' lim_dyn  : divu_i    :')
+         CALL prt_ctl(tab2d_1=delta_i   , clinfo1=' lim_dyn  : delta_i   :')
+         CALL prt_ctl(tab2d_1=strength  , clinfo1=' lim_dyn  : strength  :')
+         CALL prt_ctl(tab2d_1=area      , clinfo1=' lim_dyn  : cell area :')
+         CALL prt_ctl(tab2d_1=at_i      , clinfo1=' lim_dyn  : at_i      :')
+         CALL prt_ctl(tab2d_1=vt_i      , clinfo1=' lim_dyn  : vt_i      :')
+         CALL prt_ctl(tab2d_1=vt_s      , clinfo1=' lim_dyn  : vt_s      :')
+         CALL prt_ctl(tab2d_1=stress1_i , clinfo1=' lim_dyn  : stress1_i :')
+         CALL prt_ctl(tab2d_1=stress2_i , clinfo1=' lim_dyn  : stress2_i :')
+         CALL prt_ctl(tab2d_1=stress12_i, clinfo1=' lim_dyn  : stress12_i:')
+         DO jl = 1, jpl
+            CALL prt_ctl_info(' ')
+            CALL prt_ctl_info(' - Category : ', ivar1=jl)
+            CALL prt_ctl_info('   ~~~~~~~~~~')
+            CALL prt_ctl(tab2d_1=a_i   (:,:,jl)   , clinfo1= ' lim_dyn  : a_i      : ')
+            CALL prt_ctl(tab2d_1=ht_i  (:,:,jl)   , clinfo1= ' lim_dyn  : ht_i     : ')
+            CALL prt_ctl(tab2d_1=ht_s  (:,:,jl)   , clinfo1= ' lim_dyn  : ht_s     : ')
+            CALL prt_ctl(tab2d_1=v_i   (:,:,jl)   , clinfo1= ' lim_dyn  : v_i      : ')
+            CALL prt_ctl(tab2d_1=v_s   (:,:,jl)   , clinfo1= ' lim_dyn  : v_s      : ')
+            CALL prt_ctl(tab2d_1=e_s   (:,:,1,jl) , clinfo1= ' lim_dyn  : e_s      : ')
+            CALL prt_ctl(tab2d_1=t_su  (:,:,jl)   , clinfo1= ' lim_dyn  : t_su     : ')
+            CALL prt_ctl(tab2d_1=t_s   (:,:,1,jl) , clinfo1= ' lim_dyn  : t_snow   : ')
+            CALL prt_ctl(tab2d_1=sm_i  (:,:,jl)   , clinfo1= ' lim_dyn  : sm_i     : ')
+            CALL prt_ctl(tab2d_1=smv_i (:,:,jl)   , clinfo1= ' lim_dyn  : smv_i    : ')
+            DO ja = 1, nlay_i
+               CALL prt_ctl_info(' ')
+               CALL prt_ctl_info(' - Layer : ', ivar1=ja)
+               CALL prt_ctl_info('   ~~~~~~~')
+               CALL prt_ctl(tab2d_1=t_i(:,:,ja,jl) , clinfo1= ' lim_dyn  : t_i      : ')
+               CALL prt_ctl(tab2d_1=e_i(:,:,ja,jl) , clinfo1= ' lim_dyn  : e_i      : ')
+            END DO
+         END DO
+      ENDIF
+
+   END SUBROUTINE lim_dyn
+
+    SUBROUTINE lim_dyn_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_dyn_init  ***
+      !!
+      !! ** Purpose : Physical constants and parameters linked to the ice
+      !!      dynamics
+      !!
+      !! ** Method  :  Read the namicedyn namelist and check the ice-dynamic
+      !!       parameter values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namicedyn
+      !!
+      !! history :
+      !!  8.5  ! 03-08 (C. Ethe) original code
+      !!  9.0  ! 07-03 (MA Morales Maqueda, S. Bouillon, M. Vancoppenolle)
+      !!               EVP-Cgrid-LIM3
+      !!-------------------------------------------------------------------
+      NAMELIST/namicedyn/ epsd, alpha,     &
+         &                dm, nbiter, nbitdr, om, resl, cw, angvg, pstar,   &
+         &                c_rhg, etamn, creepl, ecc, ahi0, &
+         &                nevp, telast, alphaevp
+      !!-------------------------------------------------------------------
+
+      ! Define the initial parameters
+      ! -------------------------
+
+      ! Read Namelist namicedyn
+      REWIND ( numnam_ice )
+      READ   ( numnam_ice  , namicedyn )
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_dyn_init : ice parameters for ice dynamics '
+         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,*) '   coefficient for the solution of int. stresses  alphaevp = ', alphaevp
+
+      ENDIF
+
+      usecc2 = 1.0 / ( ecc * ecc )
+      rhoco  = rau0 * cw
+      angvg  = angvg * rad
+      sangvg = SIN( angvg )
+      cangvg = COS( angvg )
+      pstarh = pstar / 2.0
+
+      !  Diffusion coefficients.
+      ahiu(:,:) = ahi0 * umask(:,:,1)
+      ahiv(:,:) = ahi0 * vmask(:,:,1)
+
+   END SUBROUTINE lim_dyn_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option          Empty module           NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_dyn         ! Empty routine
+   END SUBROUTINE lim_dyn
+#endif 
+
+   !!======================================================================
+END MODULE limdyn
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limflx.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limflx.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limflx.F90	(revision 884)
@@ -0,0 +1,348 @@
+MODULE limflx
+   !!======================================================================
+   !!                       ***  MODULE limflx   ***
+   !!           computation of the flux at the sea ice/ocean interface
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_flx  : flux at the ice / ocean interface
+   !! * Modules used
+   USE par_oce
+   USE phycst
+   USE ocfzpt
+   USE ice_oce
+   USE flx_oce
+   USE dom_oce
+   USE ice
+   USE flxblk
+   USE lbclnk
+   USE in_out_manager
+   USE albedo
+   USE par_ice
+   USE prtctl           ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_flx       ! called by lim_step
+
+  !! * Module variables
+     REAL(wp)  ::            &  ! constant values
+         epsi16 = 1e-16   ,  &
+         rzero  = 0.0    ,  &
+         rone   = 1.0
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limflx.F90,v 1.6 2005/03/27 18:34:41 opalod Exp $
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE lim_flx
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE lim_flx ***
+      !!                
+      !!  
+      !! ** Purpose : Computes the mass and heat fluxes to the ocean
+      !!         
+      !! ** Action  : - Initialisation of some variables
+      !!              - comput. of the fluxes at the sea ice/ocean interface
+      !!     
+      !! ** Outputs : - fsolar  : solar heat flux at sea ice/ocean interface
+      !!              - fnsolar : non solar heat flux 
+      !!              - fsalt   : salt flux at sea ice/ocean interface
+      !!              - fmass   : freshwater flux at sea ice/ocean interface
+      !!
+      !!
+      !! ** References :
+      !!       H. Goosse et al. 1996, Bul. Soc. Roy. Sc. Liege, 65, 87-90
+      !!         original    : 00-01 (LIM)
+      !!         addition    : 02-07 (C. Ethe, G. Madec)
+      !!---------------------------------------------------------------------
+
+      !! * Modules used
+      !! * Local variables
+      INTEGER ::   ji, jj             ! dummy loop indices
+
+      INTEGER ::   &
+         ifvt, i1mfr, idfr ,   &  ! some switches
+         iflt, ial, iadv, ifral, ifrdv
+      
+      REAL(wp) ::   &
+         zinda  ,              &  ! switch for testing the values of ice concentration
+!!         zfcm1  ,              &  ! solar  heat fluxes
+!!         zfcm2  ,              &  !  non solar heat fluxes
+           zfold  ,            &
+#if defined key_lim_fdd   
+         zfons,                &  ! salt exchanges at the ice/ocean interface
+         zpme                     ! freshwater exchanges at the ice/ocean interface
+#else
+         zprs  , zfons,        &  ! salt exchanges at the ice/ocean interface
+         zpmess                   ! freshwater exchanges at the ice/ocean interface
+#endif
+      REAL(wp), DIMENSION(jpi,jpj) ::  &
+         zfcm1  ,              &  ! solar  heat fluxes
+         zfcm2                    !  non solar heat fluxes      
+#if defined key_coupled    
+      REAL(wp), DIMENSION(jpi,jpj) ::  &
+         zalb  ,               &  ! albedo of ice under overcast sky
+         zalcn ,               &  ! albedo of ocean under overcast sky
+         zalbp ,               &  ! albedo of ice under clear sky
+         zaldum                   ! albedo of ocean under clear sky
+#endif
+      !!---------------------------------------------------------------------
+     
+      !---------------------------------!
+      !      Sea ice/ocean interface    !
+      !---------------------------------!
+       
+      !      heat flux at the ocean surface
+      !-------------------------------------------------------
+      ! 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
+            zfcm1(ji,jj)   = pfrld(ji,jj) * qsr_oce(ji,jj)  + ( 1. - pfrld(ji,jj) ) * fstric(ji,jj)
+                ! fstric     Solar flux transmitted trough the ice
+                ! qsr_oce    Net short wave heat flux on free ocean
+! new line
+            fscmbq(ji,jj) = ( 1.0 - pfrld(ji,jj) ) * fstric(ji,jj)
+
+            !  computation the non solar heat flux at ocean surface
+            zfcm2(ji,jj) = - zfcm1(ji,jj)                  &
+               &           + iflt    * ( fscmbq(ji,jj) )   & ! total abl -> fscmbq is given to the ocean
+! fscmbq and ffltbif are obsolete
+!              &           + iflt * ffltbif(ji,jj) !!! only if one category is used
+               &           + ifral   * ( ial * qcmif(ji,jj) + (1 - ial) * qldif(ji,jj) ) / rdt_ice   &
+               &           + ifrdv   * ( qfvbq(ji,jj) + qdtcn(ji,jj) ) / rdt_ice                     &
+               &           + fhmec(ji,jj)     & ! new contribution due to snow melt in ridging!!
+               &           + fheat_rpo(ji,jj) & ! contribution from ridge formation
+               &           + fheat_res(ji,jj)
+                ! fscmbq  Part of the solar radiation transmitted through the ice and going to the ocean
+                !         computed in limthd_zdf.F90
+                ! ffltbif Total heat content of the ice (brine pockets+ice) / delta_t
+                ! 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   i think this is wrong!
+                ! ---> Array used to store energy in case of total lateral ablation
+                ! 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 .EQ. 2 ) zfcm2(ji,jj) = zfcm2(ji,jj) + &
+                                  fhbri(ji,jj) ! new contribution due to brine drainage 
+
+            ! bottom radiative component is sent to the computation of the
+            ! oceanic heat flux
+            fsbbq(ji,jj) = ( 1.0 - ( ifvt + iflt ) ) * fscmbq(ji,jj)     
+
+            ! used to compute the oceanic heat flux at the next time step
+            fsolar (ji,jj) = zfcm1(ji,jj)                                       ! solar heat flux 
+            fnsolar(ji,jj) = zfcm2(ji,jj) - fdtcn(ji,jj)                        ! non solar heat flux
+!                           ! fdtcn : turbulent oceanic heat flux
+
+
+            IF ( ( ji .EQ. jiindex ) .AND. ( jj .EQ. jjindex) ) THEN
+               WRITE(numout,*) ' lim_flx : heat fluxes '
+               WRITE(numout,*) ' fsolar    : ', fsolar(jiindex,jjindex)
+               WRITE(numout,*) ' zfcm1     : ', zfcm1(jiindex,jjindex)
+               WRITE(numout,*) ' pfrld     : ', pfrld(jiindex,jjindex)
+               WRITE(numout,*) ' qsr_oce   : ', qsr_oce(jiindex,jjindex)
+               WRITE(numout,*) ' fstric    : ', fstric (jiindex,jjindex)
+               WRITE(numout,*)
+               WRITE(numout,*) ' fnsolar   : ', fnsolar(jiindex,jjindex)
+               WRITE(numout,*) ' zfcm2     : ', zfcm2(jiindex,jjindex)
+               WRITE(numout,*) ' zfcm1     : ', zfcm1(jiindex,jjindex)
+               WRITE(numout,*) ' ifral     : ', ifral
+               WRITE(numout,*) ' ial       : ', ial  
+               WRITE(numout,*) ' qcmif     : ', qcmif(jiindex,jjindex)
+               WRITE(numout,*) ' qldif     : ', qldif(jiindex,jjindex)
+               WRITE(numout,*) ' qcmif / dt: ', qcmif(jiindex,jjindex) / rdt_ice
+               WRITE(numout,*) ' qldif / dt: ', qldif(jiindex,jjindex) / rdt_ice
+               WRITE(numout,*) ' ifrdv     : ', ifrdv
+               WRITE(numout,*) ' qfvbq     : ', qfvbq(jiindex,jjindex)
+               WRITE(numout,*) ' qdtcn     : ', qdtcn(jiindex,jjindex)
+               WRITE(numout,*) ' qfvbq / dt: ', qfvbq(jiindex,jjindex) / rdt_ice
+               WRITE(numout,*) ' qdtcn / dt: ', qdtcn(jiindex,jjindex) / rdt_ice
+               WRITE(numout,*) ' '
+               WRITE(numout,*) ' fdtcn     : ', fdtcn(jiindex,jjindex)
+               WRITE(numout,*) ' fhmec     : ', fhmec(jiindex,jjindex)
+               WRITE(numout,*) ' fheat_rpo : ', fheat_rpo(jiindex,jjindex)
+               WRITE(numout,*) ' fhbri     : ', fhbri(jiindex,jjindex)
+               WRITE(numout,*) ' fheat_res : ', fheat_res(jiindex,jjindex)
+            ENDIF
+         END DO
+      END DO
+       
+      !      mass flux at the ocean surface
+      !-------------------------------------------------------
+!     DO jl = 1, jpl
+!        DO jj = 1, jpj
+!           DO ji = 1, jpi
+!              ! this is probably wrong since rdmicif has already been computed
+!              rdmicif(ji,jj) = rdmicif(ji,jj) + rhoic*d_v_i_thd(ji,jj,jl)
+!           END DO
+!        END DO
+!     END DO
+       
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+#if defined key_lim_fdd
+            !  case of realistic freshwater flux (Tartinville et al., 2001) (presently ACTIVATED)
+            !  ------------------------------------------------------------------------------------- 
+            !  The idea of this approach is that the system that we consider is the ICE-OCEAN system
+            !  Thus  FW  flux  =  External ( E-P+snow melt)
+            !       Salt flux  =  Exchanges in the ice-ocean system then converted into FW
+            !                     Associated to Ice formation AND Ice melting
+            !                     Even if i see Ice melting as a FW and SALT flux
+            !        
+
+            !  computing freshwater exchanges at the ice/ocean interface
+            zpme = - evap(ji,jj) * ( 1.0 - at_i(ji,jj) )     &   !  evaporation over oceanic fraction
+               &   + tprecip(ji,jj)                          &   !  total precipitation
+! old fashioned way               
+!              &   - sprecip(ji,jj) * ( 1. - pfrld(ji,jj) )  &   !  remov. snow precip over ice
+               &   - sprecip(ji,jj) * ( 1. - (pfrld(ji,jj)**betas) )  &   !  remov. snow precip over ice
+               &   - rdmsnif(ji,jj) / rdt_ice                &   !  freshwaterflux due to snow melting 
+! new contribution from snow falling when ridging
+               &   + fmmec(ji,jj)
+            
+            !  computing salt exchanges at the ice/ocean interface
+            !  sice should be the same as computed with the ice model
+            zfons =  ( soce - sice ) * ( rdmicif(ji,jj) / rdt_ice ) 
+! SOCE
+            zfons =  ( sss_io(ji,jj) - sice ) * ( rdmicif(ji,jj) / rdt_ice ) 
+            
+            !  salt flux for constant salinity
+            fsalt(ji,jj)      =  zfons / ( sss_io(ji,jj) + epsi16 ) + fsalt_res(ji,jj)
+            zfold             = fsalt(ji,jj)
+            
+            !  salt flux for variable salinity
+            zinda             = 1.0 - MAX( rzero , SIGN( rone , - ( 1.0 - pfrld(ji,jj) ) ) )
+            !correcting brine and salt fluxes
+            fsbri(ji,jj)      =  zinda*fsbri(ji,jj)
+            !  converting the salt fluxes from ice to a freshwater flux from ocean
+            fsalt_res(ji,jj)  =  fsalt_res(ji,jj) / ( sss_io(ji,jj) + epsi16 )
+            fseqv(ji,jj)      =  fseqv(ji,jj)     / ( sss_io(ji,jj) + epsi16 )
+            fsbri(ji,jj)      =  fsbri(ji,jj)     / ( sss_io(ji,jj) + epsi16 )
+            fsalt_rpo(ji,jj)  =  fsalt_rpo(ji,jj) / ( sss_io(ji,jj) + epsi16 )
+
+            !  freshwater mass exchange (positive to the ice, negative for the ocean ?)
+            !  actually it's a salt flux (so it's minus freshwater flux)
+            !  if sea ice grows, zfons is positive, fsalt also
+            !  POSITIVE SALT FLUX FROM THE ICE TO THE OCEAN
+            !  POSITIVE FRESHWATER FLUX FROM THE OCEAN TO THE ICE [kg.m-2.s-1]
+
+            fmass(ji,jj) = - zpme 
+
+#else
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+! ON S'EN TAPE hhhhhhaaaaaaaaaaaaaaaaaahahahahahahahahahahahaha
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+            !  case of freshwater flux equivalent as salt flux
+            !  dilution effect due to evaporation and precipitation
+            zprs  = ( tprecip(ji,jj) - sprecip(ji,jj) * ( 1. - pfrld(ji,jj) ) ) * soce  
+!SOCE
+            zprs  = ( tprecip(ji,jj) - sprecip(ji,jj) * ( 1. - pfrld(ji,jj) ) ) * sss_io(ji,jj)
+            !  freshwater flux
+            zfons = rdmicif(ji,jj) * ( soce - sice )  &  !  fwf : ice formation and melting
+               &   -  dmgwi(ji,jj) * sice             &  !  fwf : salt flx needed to bring the fresh snow to sea/ice salinity
+               &   + rdmsnif(ji,jj) * soce               !  fwf to ocean due to snow melting 
+!SOCE
+            zfons = rdmicif(ji,jj) * ( sss_io(ji,jj) - sice )  &  !  fwf : ice formation and melting
+               &   -  dmgwi(ji,jj) * sice             &  !  fwf : salt flx needed to bring the fresh snow to sea/ice salinity
+               &   + rdmsnif(ji,jj) * sss_io(ji,jj)      !  fwf to ocean due to snow melting 
+            !  salt exchanges at the ice/ocean interface
+            zpmess         =  zprs - zfons / rdt_ice - evap(ji,jj) * soce * ( 1.0 - at_i(ji,jj) )
+!SOCE
+            zpmess         =  zprs - zfons / rdt_ice - evap(ji,jj) * sss_io(ji,jj) * ( 1.0 - at_i(ji,jj) )
+
+            fsalt(ji,jj) =  - zpmess
+#endif
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+         END DO
+      END DO
+
+      fsalt(:,:) = fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:)
+      IF (num_sal.eq.2) THEN
+         !In case of variable salinity the salt flux has to be accounted for differently
+         ! Brine drainage has to be added
+         fsalt(:,:) = fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:)
+      ENDIF
+
+      !-------------------------------------------------------------------!
+      !  computation of others transmitting variables from ice to ocean   !
+      !------------------------------------------ ------------------------!
+
+      !-----------------------------------------------!
+      !   Storing the transmitted variables           !
+      !-----------------------------------------------!
+
+      ftaux (:,:) = - tio_u(:,:) * rau0   ! taux ( ice: N/m2/rau0, ocean: N/m2 )
+      ftauy (:,:) = - tio_v(:,:) * rau0   ! tauy ( ice: N/m2/rau0, ocean: N/m2 )
+      freeze(:,:) = at_i(:,:)             ! Sea ice cover
+      tn_ice(:,:,:) = t_su(:,:,:)
+
+#if defined key_coupled            
+      zalb  (:,:) = 0.e0
+      zalcn (:,:) = 0.e0
+      zalbp (:,:) = 0.e0
+      zaldum(:,:) = 0.e0
+
+      !------------------------------------------------!
+      !  2) Computation of snow/ice and ocean albedo   !
+      !------------------------------------------------!
+      CALL flx_blk_albedo( zalb, zalcn, zalbp, zaldum )
+
+      alb_ice(:,:) =  0.5 * zalbp(:,:) + 0.5 * zalb (:,:)   ! Ice albedo
+#endif
+
+     IF(ln_ctl) THEN
+        CALL prt_ctl(tab2d_1=fsolar, clinfo1=' lim_flx: fsolar : ', tab2d_2=fnsolar, clinfo2=' fnsolar : ')
+        CALL prt_ctl(tab2d_1=fmass , clinfo1=' lim_flx: fmass  : ', tab2d_2=fsalt  , clinfo2=' fsalt   : ')
+        CALL prt_ctl(tab2d_1=ftaux , clinfo1=' lim_flx: ftaux  : ', tab2d_2=ftauy  , clinfo2=' ftauy   : ')
+        CALL prt_ctl(tab2d_1=freeze, clinfo1=' lim_flx: freeze : ')
+        CALL prt_ctl(tab3d_1=tn_ice, clinfo1=' lim_flx: tn_ice : ', kdim=jpl)
+     ENDIF
+
+    END SUBROUTINE lim_flx
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :        Empty module           NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_flx         ! Empty routine
+   END SUBROUTINE lim_flx
+#endif 
+
+END MODULE limflx
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limhdf.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limhdf.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limhdf.F90	(revision 884)
@@ -0,0 +1,190 @@
+MODULE limhdf
+   !!======================================================================
+   !!                    ***  MODULE limhdf   ***
+   !! LIM ice model : horizontal diffusion of sea-ice quantities
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_hdf  : diffusion trend on sea-ice variable
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce
+   USE ice_oce         ! ice variables
+   USE in_out_manager
+   USE ice
+   USE lbclnk
+   USE lib_mpp
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_hdf    ! called by lim_tra
+
+   !! * Module variables
+   LOGICAL  ::   linit = .TRUE.              ! ???
+   REAL(wp) ::   epsi04 = 1e-04              ! constant
+   REAL(wp), DIMENSION(jpi,jpj) ::   zfact   ! ???
+
+   !! * Substitution 
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limhdf.F90,v 1.5 2005/03/27 18:34:41 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_hdf( ptab )
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_hdf  ***
+      !!
+      !! ** purpose :   Compute and add the diffusive trend on sea-ice
+      !!      variables
+      !!
+      !! ** method  :   Second order diffusive operator evaluated using a
+      !!      Cranck-Nicholson time Scheme.
+      !!
+      !! ** Action  :    update ptab with the diffusive contribution
+      !!
+      !! History :
+      !!        !  00-01 (LIM) Original code
+      !!        !  01-05 (G. Madec, R. Hordoir) opa norm
+      !!        !  02-08 (C. Ethe)  F90, free form
+      !!-------------------------------------------------------------------
+      ! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         ptab                 ! Field on which the diffusion is applied  
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         ptab0                ! ???
+
+      ! * Local variables
+      INTEGER ::  ji, jj      ! dummy loop indices
+      INTEGER ::  &
+         its, iter            ! temporary integers
+      CHARACTER (len=55) :: charout
+      REAL(wp) ::  &
+         zalfa, zrlxint, zconv, zeps   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::  & 
+         zrlx, zflu, zflv, &  ! temporary workspaces
+         zdiv0, zdiv          !    "           "
+      !!-------------------------------------------------------------------
+
+      ! Initialisation
+      ! ---------------   
+      ! Time integration parameters
+      zalfa = 0.5       ! =1.0/0.5/0.0 = implicit/Cranck-Nicholson/explicit
+      its   = 100       ! Maximum number of iteration
+      zeps  =  2. * epsi04
+
+      ! Arrays initialization
+      ptab0 (:, : ) = ptab(:,:)
+!bug  zflu (:,jpj) = 0.e0
+!bug  zflv (:,jpj) = 0.e0
+      zdiv0(:, 1 ) = 0.e0
+      zdiv0(:,jpj) = 0.e0
+      IF( .NOT.lk_vopt_loop ) THEN
+         zflu (jpi,:) = 0.e0   
+         zflv (jpi,:) = 0.e0
+         zdiv0(1,  :) = 0.e0
+         zdiv0(jpi,:) = 0.e0
+      ENDIF
+
+      ! Metric coefficient (compute at the first call and saved in
+      IF( linit ) THEN
+         DO jj = 2, jpjm1  
+            DO ji = fs_2 , fs_jpim1   ! vector opt.
+               zfact(ji,jj) = ( e2u(ji,jj) + e2u(ji-1,jj  ) + e1v(ji,jj) + e1v(ji,jj-1) ) &
+                  &          / ( e1t(ji,jj) * e2t(ji,jj) )
+            END DO
+         END DO
+         linit = .FALSE.
+      ENDIF
+
+
+      ! Sub-time step loop
+      zconv = 1.e0
+      iter  = 0
+
+      !                                                   !===================
+      DO WHILE ( ( zconv > zeps ) .AND. (iter <= its) )   ! Sub-time step loop
+         !                                                !===================
+         ! incrementation of the sub-time step number
+         iter = iter + 1
+
+         ! diffusive fluxes in U- and V- direction
+         DO jj = 1, jpjm1
+            DO ji = 1 , fs_jpim1   ! vector opt.
+               zflu(ji,jj) = pahu(ji,jj) * e2u(ji,jj) / e1u(ji,jj) * ( ptab(ji+1,jj) - ptab(ji,jj) )
+               zflv(ji,jj) = pahv(ji,jj) * e1v(ji,jj) / e2v(ji,jj) * ( ptab(ji,jj+1) - ptab(ji,jj) )
+            END DO
+         END DO
+
+         ! diffusive trend : divergence of the fluxes
+         DO jj= 2, jpjm1
+            DO ji = fs_2 , fs_jpim1   ! vector opt. 
+               zdiv (ji,jj) = (  zflu(ji,jj) - zflu(ji-1,jj  )   &
+                  &            + zflv(ji,jj) - zflv(ji  ,jj-1)  ) / ( e1t (ji,jj) * e2t (ji,jj) )
+            END DO
+         END DO
+
+         ! save the first evaluation of the diffusive trend in zdiv0
+         IF( iter == 1 )   zdiv0(:,:) = zdiv(:,:)       
+
+         ! XXXX iterative evaluation?????
+         DO jj = 2, jpjm1
+            DO ji = fs_2 , fs_jpim1   ! vector opt.
+               zrlxint = (   ptab0(ji,jj)    &
+                  &       +  rdt_ice * (           zalfa   * ( zdiv(ji,jj) + zfact(ji,jj) * ptab(ji,jj) )   &
+                  &                      + ( 1.0 - zalfa ) *   zdiv0(ji,jj) )  )                             & 
+                  &    / ( 1.0 + zalfa * rdt_ice * zfact(ji,jj) )
+               zrlx(ji,jj) = ptab(ji,jj) + om * ( zrlxint - ptab(ji,jj) )
+            END DO
+         END DO
+
+         ! lateral boundary condition on zrlx
+         CALL lbc_lnk( zrlx, 'T', 1. )
+
+         ! convergence test
+         zconv = 0.e0
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zconv = MAX( zconv, ABS( zrlx(ji,jj) - ptab(ji,jj) )  )
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_max( zconv )   ! max over the global domain
+
+         DO jj = 1, jpj
+            DO ji = 1 , jpi
+               ptab(ji,jj) = zrlx(ji,jj)
+            END DO
+         END DO
+
+         !                                         !==========================
+      END DO                                       ! end of sub-time step loop
+      !                                            !==========================
+
+      IF(ln_ctl)   THEN
+         zrlx(:,:) = ptab(:,:) - ptab0(:,:)
+         WRITE(charout,FMT="(' lim_hdf  : zconv =',D23.16, ' iter =',I4,2X)") zconv, iter
+         CALL prt_ctl(tab2d_1=zrlx, clinfo1=charout)
+      ENDIF
+
+
+   END SUBROUTINE lim_hdf
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option          Dummy module           NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_hdf         ! Empty routine
+   END SUBROUTINE lim_hdf
+#endif
+
+   !!======================================================================
+END MODULE limhdf
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limistate.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limistate.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limistate.F90	(revision 884)
@@ -0,0 +1,600 @@
+MODULE limistate
+   !!======================================================================
+   !!                     ***  MODULE  limistate  ***
+   !!              Initialisation of diagnostics ice variables
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' :                                    LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_istate      :  Initialisation of diagnostics ice variables
+   !!   lim_istate_init :  initialization of ice state and namelist read
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE phycst
+   USE ocfzpt
+   USE oce             ! dynamics and tracers variables
+   USE dom_oce
+   USE par_ice         ! ice parameters
+   USE ice_oce         ! ice variables
+   USE in_out_manager
+   USE dom_ice
+   USE ice
+   USE lbclnk
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC lim_istate      ! routine called by lim_init.F90
+
+   !! * Module variables
+   REAL(wp) ::             & !!! ** init namelist (namiceini) **
+      ttest    = 2.0  ,    &  ! threshold water temperature for initial sea ice
+      hninn    = 0.5  ,    &  ! initial snow thickness in the north
+      hginn_u  = 2.5  ,    &  ! initial ice thickness in the north
+      aginn_u  = 0.7  ,    &  ! initial leads area in the north
+      hginn_d  = 5.0  ,    &  ! initial ice thickness in the north
+      aginn_d  = 0.25 ,    &  ! initial leads area in the north
+      hnins    = 0.1  ,    &  ! initial snow thickness in the south
+      hgins_u  = 1.0  ,    &  ! initial ice thickness in the south
+      agins_u  = 0.7  ,    &  ! initial leads area in the south
+      hgins_d  = 2.0  ,    &  ! initial ice thickness in the south
+      agins_d  = 0.2  ,    &  ! initial leads area in the south
+      sinn     = 6.301 ,   &  ! initial salinity 
+      sins     = 6.301
+
+   REAL(wp)  ::            &  ! constant values
+      zzero   = 0.0     ,  &
+      zone    = 1.0
+
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limistate.F90,v 1.3 2005/03/27 18:34:41 opalod Exp $
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_istate
+      !!-------------------------------------------------------------------
+      !!                    ***  ROUTINE lim_istate  ***
+      !!
+      !! ** Purpose :   defined the sea-ice initial state
+      !!
+      !! ** Method  :   restart from a state defined in a binary file
+      !!                or from arbitrary sea-ice conditions
+      !!
+      !! History :
+      !!   2.0  !  01-04  (C. Ethe, G. Madec)  Original code
+      !!--------------------------------------------------------------------
+
+      !! * Local variables
+      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
+
+      REAL(wp) ::   zidto,    &  ! temporary scalar
+         zs0, ztf, zbin, &
+         zeps6, zeps, ztmelts, &
+         epsi06
+      REAL(wp), DIMENSION(jpm) ::   &
+         zgfactorn, zhin, &
+         zgfactors, zhis
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         ztn  
+      REAL(wp) ::  &
+         zvol, zare, zh, zh1, zh2, zh3, zan, zbn, zas, zbs 
+      !--------------------------------------------------------------------
+ 
+      !--------------------------------------------------------------------
+      ! 1) Preliminary things 
+      !--------------------------------------------------------------------
+      epsi06 = 1.0e-6
+
+      CALL lim_istate_init     !  reading the initials parameters of the ice
+
+      !-- Initialisation of sst,sss,u,v do i=1,jpi
+      u_io(:,:)  = 0.e0       ! ice velocity in x direction
+      v_io(:,:)  = 0.e0       ! ice velocity in y direction
+
+      ! Initialisation at tn or -2 if ice
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zbin = MAX( 0., SIGN( 1., fzptn(ji,jj) - tn(ji,jj,1) ) )
+            ztn(ji,jj) = ( (1.-zbin) * tn(ji,jj,1) - 2. * zbin + rt0 ) * tmask(ji,jj,1)
+         END DO
+      END DO
+
+      u_io  (:,:) = 0.
+      v_io  (:,:) = 0.
+      sst_io(:,:) = ( nfice - 1 ) * ( tn(:,:,1) + rt0 )   ! use the ocean initial values
+      sss_io(:,:) = ( nfice - 1 ) *   sn(:,:,1)           ! tricky trick *(nfice-1) !
+
+      !--------------------------------------------------------------------
+      ! 2) Ice initialization (hi,hs,frld,t_su,sm_i,t_i,t_s)              | 
+      !--------------------------------------------------------------------
+
+      WRITE(numout,*)
+      WRITE(numout,*) 'lim_istate : Ice initialization '
+      WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+
+      ! reference salinity 34psu
+      zs0 = 34.e0
+      ztf = ABS ( rt0 - 0.0575       * zs0                               &
+               &                    + 1.710523e-03 * zs0 * SQRT( zs0 )   &
+               &                    - 2.154996e-04 * zs0 *zs0          )
+
+      ! constants for heat contents
+      zeps   = 1.0d-20
+      zeps6  = 1.0d-06
+
+      !  t_bo: Seawater freezing point
+      t_bo(:,:)  = ztf   
+
+      ! zgfactor for initial ice distribution
+      zgfactorn(:) = 0.0
+      zgfactors(:) = 0.0
+
+      ! first ice type
+      DO jl = ice_cat_bounds(1,1), ice_cat_bounds(1,2)
+         zhin (1)     = ( hi_max(jl-1) + hi_max(jl) ) / 2.0
+         zgfactorn(1) = zgfactorn(1) + exp(-(zhin(1)-hginn_u)*(zhin(1)-hginn_u)/2.0)
+         zhis (1)     = ( hi_max(jl-1) + hi_max(jl) ) / 2.0
+         zgfactors(1) = zgfactors(1) + exp(-(zhis(1)-hgins_u)*(zhis(1)-hgins_u)/2.0)
+      END DO ! jl
+      zgfactorn(1) = aginn_u / zgfactorn(1)
+      zgfactors(1) = agins_u / zgfactors(1)
+
+      ! -------------
+      ! new distribution, polynom of second order, conserving area and volume
+      zh1 = 0.0
+      zh2 = 0.0
+      zh3 = 0.0
+      DO jl = 1, jpl
+         zh = ( hi_max(jl-1) + hi_max(jl) ) / 2.0
+         zh1 = zh1 + zh
+         zh2 = zh2 + zh*zh
+         zh3 = zh3 + zh*zh*zh
+      END DO
+      WRITE(numout,*) ' zh1 : ', zh1
+      WRITE(numout,*) ' zh2 : ', zh2
+      WRITE(numout,*) ' zh3 : ', zh3
+
+      zvol = aginn_u*hginn_u
+      zare = aginn_u
+      IF ( jpl .GE. 2 ) THEN
+         zbn = ( zvol*zh2 - zare*zh3 ) / ( zh2*zh2 - zh1*zh3)
+         zan = ( zare - zbn*zh1 ) / zh2
+      ENDIF
+
+      WRITE(numout,*) ' zvol: ', zvol
+      WRITE(numout,*) ' zare: ', zare
+      WRITE(numout,*) ' zbn : ', zbn 
+      WRITE(numout,*) ' zan : ', zan 
+
+      zvol = agins_u*hgins_u
+      zare = agins_u
+      IF ( jpl .GE. 2 ) THEN
+         zbs = ( zvol*zh2 - zare*zh3 ) / ( zh2*zh2 - zh1*zh3)
+         zas = ( zare - zbs*zh1 ) / zh2
+      ENDIF
+
+      WRITE(numout,*) ' zvol: ', zvol
+      WRITE(numout,*) ' zare: ', zare
+      WRITE(numout,*) ' zbn : ', zbn 
+      WRITE(numout,*) ' zan : ', zan 
+
+      !end of new lines
+      ! -------------
+!!!
+! retour a LIMA_MEC
+!     ! second ice type
+!     zdummy  = hi_max(ice_cat_bounds(2,1)-1)
+!     hi_max(ice_cat_bounds(2,1)-1) = 0.0
+
+!     ! here to change !!!!
+!     jm = 2
+!     DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
+!        zhin (2)     = ( hi_max(jl-1) + hi_max(jl) ) / 2.0
+!        zhin (2)     = ( hi_max_typ(jl-ice_cat_bounds(2,1),jm    ) + &
+!                         hi_max_typ(jl-ice_cat_bounds(2,1) + 1,jm)   ) / 2.0
+!        zgfactorn(2) = zgfactorn(2) + exp(-(zhin(2)-hginn_d)*(zhin(2)-hginn_d)/2.0)
+!        zhis (2)     = ( hi_max(jl-1) + hi_max(jl) ) / 2.0
+!        zhis (2)     = ( hi_max_typ(jl-ice_cat_bounds(2,1),jm    ) + &
+!                         hi_max_typ(jl-ice_cat_bounds(2,1) + 1,jm)   ) / 2.0
+!        zgfactors(2) = zgfactors(2) + exp(-(zhis(2)-hgins_d)*(zhis(2)-hgins_d)/2.0)
+!     END DO ! jl
+!     zgfactorn(2) = aginn_d / zgfactorn(2)
+!     zgfactors(2) = agins_d / zgfactors(2)
+!     hi_max(ice_cat_bounds(2,1)-1) = zdummy
+! END retour a LIMA_MEC
+!!!
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+
+            !--- Criterion for presence (zidto=1) or absence (zidto=0) of ice
+            zidto  = tms(ji,jj) * ( 1.0 - MAX(zzero, SIGN( zone, ztn(ji,jj) - t_bo(ji,jj) - ttest) ) )
+
+            !--- Northern hemisphere
+            !----------------------------------------------------------------
+            IF( fcor(ji,jj) >= 0.e0 ) THEN    
+
+               !-----------------------
+               ! Ice area / thickness
+               !-----------------------
+
+               IF ( jpl .EQ. 1) THEN ! one category
+
+                  DO jl = ice_cat_bounds(1,1), ice_cat_bounds(1,2) ! loop over ice thickness categories
+                     a_i(ji,jj,jl)    = zidto * aginn_u
+                     ht_i(ji,jj,jl)   = zidto * hginn_u
+                     v_i(ji,jj,jl)    = ht_i(ji,jj,jl)*a_i(ji,jj,jl)
+                  END DO
+
+               ELSE ! several categories
+
+                  DO jl = ice_cat_bounds(1,1), ice_cat_bounds(1,2) ! loop over ice thickness categories
+                     zhin(1)          = ( hi_max(jl-1) + hi_max(jl) ) / 2.0
+                     a_i(ji,jj,jl)    = zidto * MAX( zgfactorn(1) * exp(-(zhin(1)-hginn_u)* & 
+                                            (zhin(1)-hginn_u)/2.0) , epsi06)
+                     ! new line
+                     a_i(ji,jj,jl)    = zidto * ( zan * zhin(1) * zhin(1) + zbn * zhin(1) )
+                     ht_i(ji,jj,jl)   = zidto * zhin(1) 
+                     v_i(ji,jj,jl)    = ht_i(ji,jj,jl)*a_i(ji,jj,jl)
+                  END DO
+
+               ENDIF
+
+
+!!!
+! retour a LIMA_MEC
+!              !ridged ice
+!              zdummy  = hi_max(ice_cat_bounds(2,1)-1)
+!              hi_max(ice_cat_bounds(2,1)-1) = 0.0
+!              DO jl = ice_cat_bounds(2,1), ice_cat_bounds(2,2) ! loop over ice thickness categories
+!                 zhin(2)          = ( hi_max(jl-1) + hi_max(jl) ) / 2.0
+!                 a_i(ji,jj,jl)    = zidto * MAX( zgfactorn(2) * exp(-(zhin(2)-hginn_d)* &
+!                                    (zhin(2)-hginn_d)/2.0) , epsi06)
+!                 ht_i(ji,jj,jl)   = zidto * zhin(2) 
+!                 v_i(ji,jj,jl)    = ht_i(ji,jj,jl)*a_i(ji,jj,jl)
+!              END DO
+!              hi_max(ice_cat_bounds(2,1)-1) = zdummy
+
+!              !rafted ice
+!              jl = 6
+!              a_i(ji,jj,jl)       = 0.0
+!              ht_i(ji,jj,jl)      = 0.0
+!              v_i(ji,jj,jl)       = 0.0
+! END retour a LIMA_MEC
+!!!
+
+               DO jl = 1, jpl
+
+                  !-------------
+                  ! Snow depth
+                  !-------------
+                  ht_s(ji,jj,jl)   = zidto * hninn
+                  v_s(ji,jj,jl)    = ht_s(ji,jj,jl)*a_i(ji,jj,jl)
+
+                  !---------------
+                  ! Ice salinity
+                  !---------------
+                  sm_i(ji,jj,jl)   = zidto * sinn  + ( 1.0 - zidto ) * 0.1
+                  smv_i(ji,jj,jl)  = MIN( sm_i(ji,jj,jl) , sss_io(ji,jj) ) * v_i(ji,jj,jl)
+
+                  !----------
+                  ! Ice age
+                  !----------
+                  o_i(ji,jj,jl)    = zidto * 1.0   + ( 1.0 - zidto )
+                  oa_i(ji,jj,jl)   = o_i(ji,jj,jl) * a_i(ji,jj,jl)
+                     
+                  !------------------------------
+                  ! Sea ice surface temperature
+                  !------------------------------
+
+                  t_su(ji,jj,jl)   = zidto * 270.0 + ( 1.0 - zidto ) * t_bo(ji,jj)
+
+                  !------------------------------------
+                  ! Snow temperature and heat content
+                  !------------------------------------
+
+                  DO jk = 1, nlay_s
+                     t_s(ji,jj,jk,jl) = zidto * 270.00 + ( 1.0 - zidto ) * rtt
+                     ! Snow energy of melting
+                     e_s(ji,jk,jk,jl) = zidto * 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
+                     e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * area(ji,jj) * &
+                                        v_s(ji,jj,jl)  / nlay_s
+                  END DO !jk
+
+                  !-----------------------------------------------
+                  ! Ice salinities, temperature and heat content 
+                  !-----------------------------------------------
+
+                  DO jk = 1, nlay_i
+                     t_i(ji,jj,jk,jl) = zidto*270.00 + ( 1.0 - zidto ) * rtt 
+                     s_i(ji,jj,jk,jl) = zidto * sinn + ( 1.0 - zidto ) * 0.1
+                     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 * rhoic * &
+                     (   cpic    * ( ztmelts - t_i(ji,jj,jk,jl) ) &
+                     +   lfus    * ( 1.0 - (ztmelts-rtt) / MIN((t_i(ji,jj,jk,jl)-rtt),-zeps) ) &
+                     - rcp      * ( ztmelts - rtt ) &
+                     )
+
+                  ! Correct dimensions to avoid big values
+                     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
+                     e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * & 
+                                  area(ji,jj) * a_i(ji,jj,jl) * ht_i(ji,jj,jl) / &
+                                  nlay_i
+                  END DO ! jk
+
+               END DO ! jl 
+
+            ELSE ! on fcor 
+
+            !--- Southern hemisphere
+            !----------------------------------------------------------------
+
+               !-----------------------
+               ! Ice area / thickness
+               !-----------------------
+
+               IF ( jpl .EQ. 1) THEN ! one category
+
+                  DO jl = ice_cat_bounds(1,1), ice_cat_bounds(1,2) ! loop over ice thickness categories
+                     a_i(ji,jj,jl)    = zidto * agins_u
+                     ht_i(ji,jj,jl)   = zidto * hgins_u
+                     v_i(ji,jj,jl)    = ht_i(ji,jj,jl)*a_i(ji,jj,jl)
+                  END DO
+
+               ELSE ! several categories
+               
+               !level ice
+                  DO jl = ice_cat_bounds(1,1), ice_cat_bounds(1,2) !over thickness categories
+
+                     zhis(1)       = ( hi_max(jl-1) + hi_max(jl) ) / 2.0
+                     a_i(ji,jj,jl) = zidto * MAX( zgfactors(1) * exp(-(zhis(1)-hgins_u) * & 
+                                        (zhis(1)-hgins_u)/2.0) , epsi06 )
+                     ! new line square distribution volume conserving
+                     a_i(ji,jj,jl)    = zidto * ( zas * zhis(1) * zhis(1) + zbs * zhis(1) )
+                     ht_i(ji,jj,jl)   = zidto * zhis(1) 
+                     v_i(ji,jj,jl)    = ht_i(ji,jj,jl)*a_i(ji,jj,jl)
+                  
+                  END DO ! jl
+
+               ENDIF
+
+!!!
+! retour a LIMA_MEC
+!              !ridged ice
+!              zdummy  = hi_max(ice_cat_bounds(2,1)-1)
+!              hi_max(ice_cat_bounds(2,1)-1) = 0.0
+!              DO jl = ice_cat_bounds(2,1), ice_cat_bounds(2,2) !over thickness categories
+!                 zhis(2)       = ( hi_max(jl-1) + hi_max(jl) ) / 2.0
+!                 a_i(ji,jj,jl) = zidto*MAX( zgfactors(2) * exp(-(zhis(2)-hgins_d)*(zhis(2)-hgins_d)/2.0), epsi06 )
+!                 ht_i(ji,jj,jl)   = zidto * zhis(2) 
+!                 v_i(ji,jj,jl)    = ht_i(ji,jj,jl)*a_i(ji,jj,jl)
+!              END DO
+!              hi_max(ice_cat_bounds(2,1)-1) = zdummy
+
+!              !rafted ice
+!              jl = 6
+!              a_i(ji,jj,jl)       = 0.0
+!              ht_i(ji,jj,jl)      = 0.0
+!              v_i(ji,jj,jl)       = 0.0
+! END retour a LIMA_MEC
+!!!
+
+               DO jl = 1, jpl !over thickness categories
+
+                  !---------------
+                  ! Snow depth
+                  !---------------
+
+                  ht_s(ji,jj,jl)   = zidto * hnins
+                  v_s(ji,jj,jl)    = ht_s(ji,jj,jl)*a_i(ji,jj,jl)
+
+                  !---------------
+                  ! Ice salinity
+                  !---------------
+
+                  sm_i(ji,jj,jl)   = zidto * sins  + ( 1.0 - zidto ) * 0.1
+                  smv_i(ji,jj,jl)  = MIN( sm_i(ji,jj,jl) , sss_io(ji,jj) ) * v_i(ji,jj,jl)
+
+                  !----------
+                  ! Ice age
+                  !----------
+
+                  o_i(ji,jj,jl)    = zidto * 1.0   + ( 1.0 - zidto )
+                  oa_i(ji,jj,jl)   = o_i(ji,jj,jl) * a_i(ji,jj,jl)
+
+                  !------------------------------
+                  ! Sea ice surface temperature
+                  !------------------------------
+
+                  t_su(ji,jj,jl)   = zidto * 270.0 + ( 1.0 - zidto ) * t_bo(ji,jj)
+
+                  !----------------------------------
+                  ! Snow temperature / heat content
+                  !----------------------------------
+
+                  DO jk = 1, nlay_s
+                     t_s(ji,jj,jk,jl) = zidto * 270.00 + ( 1.0 - zidto ) * rtt
+                     ! Snow energy of melting
+                     e_s(ji,jj,jk,jl) = zidto * 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
+                     e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * area(ji,jj) * &
+                                        v_s(ji,jj,jl)  / nlay_s
+                  END DO
+
+                  !---------------------------------------------
+                  ! Ice temperature, salinity and heat content
+                  !---------------------------------------------
+
+                  DO jk = 1, nlay_i
+                     t_i(ji,jj,jk,jl) = zidto*270.00 + ( 1.0 - zidto ) * rtt 
+                     s_i(ji,jj,jk,jl) = zidto * sins + ( 1.0 - zidto ) * 0.1
+                     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 * rhoic * &
+                     (   cpic    * ( ztmelts - t_i(ji,jj,jk,jl) ) &
+                     +   lfus  * ( 1.0 - (ztmelts-rtt) / MIN((t_i(ji,jj,jk,jl)-rtt),-zeps) ) &
+                     - rcp      * ( ztmelts - rtt ) &
+                     )
+
+                  ! Correct dimensions to avoid big values
+                     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
+                     e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * & 
+                                     area(ji,jj) * a_i(ji,jj,jl) * ht_i(ji,jj,jl) / &
+                                     nlay_i
+                  END DO !jk
+
+               END DO ! jl 
+
+            ENDIF ! on fcor
+
+         ENDDO
+      ENDDO
+
+      !--------------------------------------------------------------------
+      ! 3) Global ice variables for output diagnostics                    | 
+      !--------------------------------------------------------------------
+
+      fsbbq (:,:)     = 0.e0
+      u_ice (:,:)     = 0.e0
+      v_ice (:,:)     = 0.e0
+      stress1_i(:,:)  = 0.0
+      stress2_i(:,:)  = 0.0
+      stress12_i(:,:) = 0.0
+
+# if defined key_coupled
+      albege(:,:)   = 0.8 * tms(:,:)
+# endif
+
+      !--------------------------------------------------------------------
+      ! 4) Moments for advection
+      !--------------------------------------------------------------------
+
+      sxice (:,:,:)  = 0.e0   ;   sxsn (:,:,:)  = 0.e0   ;   sxa  (:,:,:)  = 0.e0
+      syice (:,:,:)  = 0.e0   ;   sysn (:,:,:)  = 0.e0   ;   sya  (:,:,:)  = 0.e0
+      sxxice(:,:,:)  = 0.e0   ;   sxxsn(:,:,:)  = 0.e0   ;   sxxa (:,:,:)  = 0.e0
+      syyice(:,:,:)  = 0.e0   ;   syysn(:,:,:)  = 0.e0   ;   syya (:,:,:)  = 0.e0
+      sxyice(:,:,:)  = 0.e0   ;   sxysn(:,:,:)  = 0.e0   ;   sxya (:,:,:)  = 0.e0
+
+      sxc0  (:,:,:)  = 0.e0   ;   sxe  (:,:,:,:)= 0.e0   
+      syc0  (:,:,:)  = 0.e0   ;   sye  (:,:,:,:)= 0.e0   
+      sxxc0 (:,:,:)  = 0.e0   ;   sxxe (:,:,:,:)= 0.e0   
+      syyc0 (:,:,:)  = 0.e0   ;   syye (:,:,:,:)= 0.e0   
+      sxyc0 (:,:,:)  = 0.e0   ;   sxye (:,:,:,:)= 0.e0   
+
+      sxsal  (:,:,:)  = 0.e0
+      sysal  (:,:,:)  = 0.e0
+      sxxsal (:,:,:)  = 0.e0
+      syysal (:,:,:)  = 0.e0
+      sxysal (:,:,:)  = 0.e0
+
+      !--------------------------------------------------------------------
+      ! 5) 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
+
+      CALL lbc_lnk( at_i , 'T', 1. )
+      at_i(:,:) = tms(:,:) * at_i(:,:)                       ! put 0 over land
+
+      CALL lbc_lnk( fsbbq  , 'T', 1. )
+      CALL lbc_lnk( sss_io , 'T', 1. )
+
+   END SUBROUTINE lim_istate
+
+   SUBROUTINE lim_istate_init
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE lim_istate_init  ***
+      !!        
+      !! ** Purpose : Definition of initial state of the ice 
+      !!
+      !! ** Method : Read the namiceini namelist and check the parameter 
+      !!       values called at the first timestep (nit000)
+      !!
+      !! ** input : 
+      !!        Namelist namiceini
+      !!
+      !! history :
+      !!  8.5  ! 03-08 (C. Ethe) original code
+      !!-----------------------------------------------------------------------------
+      NAMELIST/namiceini/ ttest, hninn, hginn_u, aginn_u, hginn_d, aginn_d, hnins, &
+                          hgins_u, agins_u, hgins_d, agins_d, sinn, sins
+      !!-----------------------------------------------------------------------------
+
+      ! Define the initial parameters
+      ! -------------------------
+
+      ! Read Namelist namiceini 
+      REWIND ( numnam_ice )
+      READ   ( numnam_ice , namiceini )
+      IF(lwp) THEN
+         WRITE(numout,*)
+         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 undef ice thickness in the north     hginn_u    = ', hginn_u
+         WRITE(numout,*) '   initial undef ice concentr. in the north     aginn_u    = ', aginn_u          
+         WRITE(numout,*) '   initial  def  ice thickness in the north     hginn_d    = ', hginn_d
+         WRITE(numout,*) '   initial  def  ice concentr. in the north     aginn_d    = ', aginn_d          
+         WRITE(numout,*) '   initial snow thickness in the south          hnins      = ', hnins 
+         WRITE(numout,*) '   initial undef ice thickness in the north     hgins_u    = ', hgins_u
+         WRITE(numout,*) '   initial undef ice concentr. in the north     agins_u    = ', agins_u          
+         WRITE(numout,*) '   initial  def  ice thickness in the north     hgins_d    = ', hgins_d
+         WRITE(numout,*) '   initial  def  ice concentr. in the north     agins_d    = ', agins_d          
+         WRITE(numout,*) '   initial  ice salinity       in the north     sinn       = ', sinn
+         WRITE(numout,*) '   initial  ice salinity       in the south     sins       = ', sins
+      ENDIF
+            
+   END SUBROUTINE lim_istate_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :         Empty module          NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_istate          ! Empty routine
+   END SUBROUTINE lim_istate
+#endif
+
+   !!======================================================================
+END MODULE limistate
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limitd_me.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limitd_me.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limitd_me.F90	(revision 884)
@@ -0,0 +1,1890 @@
+MODULE limitd_me
+
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' :                                    LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!
+   !!======================================================================
+   !!                       ***  MODULE limitd_me ***
+   !!            Mechanical impact on ice thickness distribution
+   !!                     computation of changes in g(h)      
+   !!======================================================================
+   !!
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_ice
+   USE par_oce          ! ocean parameters
+   USE dom_oce
+   USE lbclnk
+   USE phycst           ! physical constants (ocean directory) 
+   USE ice_oce          ! ice variables
+   USE thd_ice
+   USE limistate
+   USE in_out_manager
+   USE ice
+   USE par_ice
+   USE limthd_lac
+   USE limvar
+   USE iceini
+   USE limcons
+   USE prtctl           ! Print control
+   USE lib_mpp
+ 
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_itd_me        ! called by ice_stp
+   PUBLIC lim_itd_me_icestrength
+   PUBLIC lim_itd_me_ridgeprep
+   PUBLIC lim_itd_me_ridgeshift
+   PUBLIC lim_itd_me_asumr
+   PUBLIC lim_itd_me_init
+   PUBLIC lim_itd_me_zapsmall
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      epsi20 = 1e-20   ,  &
+      epsi13 = 1e-13   ,  &
+      epsi11 = 1e-11   ,  &
+      zzero  = 0.e0    ,  &
+      zone   = 1.e0
+
+!-----------------------------------------------------------------------
+! Variables shared among ridging subroutines
+!-----------------------------------------------------------------------
+      REAL(wp), DIMENSION (jpi,jpj) ::    &
+         asum         , & ! sum of total ice and open water area
+         aksum            ! ratio of area removed to area ridged
+
+      REAL(wp), DIMENSION(jpi,jpj,0:jpl) :: &     
+         athorn           ! participation function; fraction of ridging/
+                          !  closing associated w/ category n
+
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::  &
+         hrmin      , &   ! minimum ridge thickness
+         hrmax      , &   ! maximum ridge thickness
+         hraft      , &   ! thickness of rafted ice
+         krdg       , &   ! mean ridge thickness/thickness of ridging ice 
+         aridge     , &   ! participating ice ridging
+         araft            ! participating ice rafting
+
+      REAL(wp), PARAMETER :: &
+         krdgmin = 1.1, &    ! min ridge thickness multiplier
+         kraft   = 2.0       ! rafting multipliyer
+
+      REAL(wp) :: &                               
+         Cp 
+!
+!-----------------------------------------------------------------------
+! Ridging diagnostic arrays for history files
+!-----------------------------------------------------------------------
+!
+      REAL (wp), DIMENSION(jpi,jpj) :: &
+         dardg1dt     , & ! rate of fractional area loss by ridging ice (1/s)
+         dardg2dt     , & ! rate of fractional area gain by new ridges (1/s)
+         dvirdgdt     , & ! rate of ice volume ridged (m/s)
+         opening          ! rate of opening due to divergence/shear (1/s)
+                                       
+
+   !!----------------------------------------------------------------------
+   !!   LIM-@ 3.0,  UCL-ASTR (2008)
+   !!   (c) UCL-ASTR and Martin Vancoppenolle
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+!!-----------------------------------------------------------------------------!
+!!-----------------------------------------------------------------------------!
+
+   SUBROUTINE lim_itd_me ! (subroutine 1/6)
+        !!---------------------------------------------------------------------!
+        !!                ***  ROUTINE lim_itd_me ***
+        !! ** Purpose :
+        !!        This routine computes the mechanical redistribution
+        !!                      of ice thickness
+        !!
+        !! ** Method  : a very simple method :-)
+        !!
+        !! ** Arguments :
+        !!           kideb , kiut : Starting and ending points on which the 
+        !!                         the computation is applied
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !!
+        !! ** External : 
+        !!
+        !! ** Steps :
+        !!  1) Thickness categories boundaries, ice / o.w. concentrations
+        !!     Ridge preparation
+        !!  2) Dynamical inputs (closing rate, divu_adv, opning)
+        !!  3) Ridging iteration
+        !!  4) Ridging diagnostics
+        !!  5) Heat, salt and freshwater fluxes
+        !!  6) Compute increments of tate variables and come back to old values
+        !!
+        !! ** References : There are a lot of references and can be difficult / 
+        !!                 boring to read
+        !!
+        !! Flato, G. M., and W. D. Hibler III, 1995: Ridging and strength
+        !!  in modeling the thickness distribution of Arctic sea ice,
+        !!  J. Geophys. Res., 100, 18,611-18,626.
+        !!
+        !! Hibler, W. D. III, 1980: Modeling a variable thickness sea ice
+        !!  cover, Mon. Wea. Rev., 108, 1943-1973, 1980.
+        !!
+        !! Rothrock, D. A., 1975: The energetics of the plastic deformation of
+        !!  pack ice by ridging, J. Geophys. Res., 80, 4514-4519.
+        !!
+        !! Thorndike, A. S., D. A. Rothrock, G. A. Maykut, and R. Colony, 
+        !!  1975: The thickness distribution of sea ice, J. Geophys. Res., 
+        !!  80, 4501-4513. 
+        !!
+        !! Bitz et al., JGR 2001
+        !!
+        !! Amundrud and Melling, JGR 2005
+        !!
+        !! Babko et al., JGR 2002 
+        !!
+        !! ** History :
+        !!           This routine is based on CICE code
+        !!           and authors William H. Lipscomb,
+        !!           and Elizabeth C. Hunke, LANL
+        !!           are gratefully acknowledged
+        !!
+        !!           (02-2006) Martin Vancoppenolle, UCL-ASTR 
+        !!
+        !!--------------------------------------------------------------------!
+        !! * Arguments
+
+        !! * Local variables
+        INTEGER ::   ji,       &   ! spatial dummy loop index
+                     jj,       &   ! spatial dummy loop index
+                     jk,       &   ! vertical layering dummy loop index
+                     jl,       &   ! ice category dummy loop index
+                     niter,    &   ! iteration counter
+                     nitermax = 20 ! max number of ridging iterations 
+
+        REAL(wp)  ::             &  ! constant values
+           zeps      =  1.0e-10, &
+           epsi10    =  1.0e-10, &
+           epsi06    =  1.0e-6
+
+        REAL(wp), DIMENSION(jpi,jpj) :: &
+           closing_net,        &  ! net rate at which area is removed    (1/s)
+                                  ! (ridging ice area - area of new ridges) / dt
+           divu_adv   ,        &  ! divu as implied by transport scheme  (1/s)
+           opning     ,        &  ! rate of opening due to divergence/shear
+           closing_gross,      &  ! rate at which area removed, not counting
+                                  ! area of new ridges
+           msnow_mlt  ,        &  ! mass of snow added to ocean (kg m-2)
+           esnow_mlt              ! energy needed to melt snow in ocean (J m-2)
+
+        REAL(wp) ::            &
+           w1,                 &  ! temporary variable
+           tmpfac,             &  ! factor by which opening/closing rates are cut
+           dti                    ! 1 / dt
+
+        LOGICAL   ::           &
+           asum_error              ! flag for asum .ne. 1
+
+        INTEGER :: iterate_ridging ! if true, repeat the ridging
+
+        REAL(wp) ::  &         
+           big = 1.0e8
+
+        REAL (wp), DIMENSION(jpi,jpj) :: &  ! 
+           vt_i_init, vt_i_final       !  ice volume summed over categories
+
+        CHARACTER (len = 15) :: fieldid
+
+!!-- End of declarations
+!-----------------------------------------------------------------------------!
+
+      IF( numit == nstart  ) CALL lim_itd_me_init ! Initialization (first time-step only)
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab2d_1=ato_i , clinfo1=' lim_itd_me: ato_i  : ', tab2d_2=at_i   , clinfo2=' at_i    : ')
+         CALL prt_ctl(tab2d_1=divu_i, clinfo1=' lim_itd_me: divu_i : ', tab2d_2=delta_i, clinfo2=' delta_i : ')
+      ENDIF
+
+!-----------------------------------------------------------------------------!
+! 1) Thickness categories boundaries, ice / o.w. concentrations, init_ons
+!-----------------------------------------------------------------------------!
+! Set hi_max(ncat) to a big value to ensure that all ridged ice 
+! is thinner than hi_max(ncat).
+
+      hi_max(jpl) = 999.99
+
+      Cp = 0.5* grav * (rau0-rhoic)*rhoic/rau0    ! proport const for PE
+      CALL lim_itd_me_ridgeprep ! prepare ridging
+
+      ! conservation check
+      IF ( con_i) CALL lim_column_sum (jpl,   v_i, vt_i_init)
+
+! Initialize arrays.
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+
+         msnow_mlt(ji,jj) = 0.0
+         esnow_mlt(ji,jj) = 0.0
+         dardg1dt(ji,jj)  = 0.0
+         dardg2dt(ji,jj)  = 0.0
+         dvirdgdt(ji,jj)  = 0.0
+         opening (ji,jj)  = 0.0
+
+!-----------------------------------------------------------------------------!
+! 2) Dynamical inputs (closing rate, divu_adv, opning)
+!-----------------------------------------------------------------------------!
+!
+! 2.1 closing_net
+!-----------------
+! Compute the net rate of closing due to convergence 
+! and shear, based on Flato and Hibler (1995).
+! 
+! The energy dissipation rate is equal to the net closing rate
+! times the ice strength.
+!
+! NOTE: The NET closing rate is equal to the rate that open water 
+!  area is removed, plus the rate at which ice area is removed by 
+!  ridging, minus the rate at which area is added in new ridges.
+!  The GROSS closing rate is equal to the first two terms (open
+!  water closing and thin ice ridging) without the third term
+!  (thick, newly ridged ice).
+
+         closing_net(ji,jj) = &
+              Cs*0.5*(Delta_i(ji,jj)-ABS(divu_i(ji,jj))) - MIN(divu_i(ji,jj),0.0)
+
+! 2.2 divu_adv
+!--------------
+! Compute divu_adv, the divergence rate given by the transport/
+! advection scheme, which may not be equal to divu as computed 
+! from the velocity field.
+!
+! If divu_adv < 0, make sure the closing rate is large enough
+! to give asum = 1.0 after ridging.
+
+         divu_adv(ji,jj) = (1.0-asum(ji,jj)) / rdt_ice  ! asum found in ridgeprep
+
+         IF (divu_adv(ji,jj) .LT. 0.0) &
+              closing_net(ji,jj) = max(closing_net(ji,jj), -divu_adv(ji,jj))
+
+! 2.3 opning
+!------------
+! Compute the (non-negative) opening rate that will give 
+! asum = 1.0 after ridging.
+         opning(ji,jj) = closing_net(ji,jj) + divu_adv(ji,jj)
+
+         END DO
+      END DO
+
+!-----------------------------------------------------------------------------!
+! 3) Ridging iteration
+!-----------------------------------------------------------------------------!
+      niter = 1                 ! iteration counter
+      iterate_ridging = 1
+
+
+      DO WHILE ( iterate_ridging > 0 .AND. niter < nitermax )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+
+! 3.2 closing_gross
+!-----------------------------------------------------------------------------!
+! Based on the ITD of ridging and ridged ice, convert the net
+!  closing rate to a gross closing rate.  
+! NOTE: 0 < aksum <= 1
+            closing_gross(ji,jj) = closing_net(ji,jj) / aksum(ji,jj)
+
+! correction to closing rate and opening if closing rate is excessive
+!---------------------------------------------------------------------
+! Reduce the closing rate if more than 100% of the open water 
+! would be removed.  Reduce the opening rate proportionately.
+            IF ( ato_i(ji,jj) .GT. epsi11 .AND. athorn(ji,jj,0) .GT. 0.0 ) THEN
+               w1 = athorn(ji,jj,0) * closing_gross(ji,jj) * rdt_ice
+               IF ( w1 .GT. ato_i(ji,jj)) THEN
+                  tmpfac = ato_i(ji,jj) / w1
+                  closing_gross(ji,jj) = closing_gross(ji,jj) * tmpfac
+                  opning(ji,jj) = opning(ji,jj) * tmpfac
+               ENDIF !w1
+            ENDIF !at0i and athorn
+
+         END DO ! ji
+      END DO ! jj
+
+! correction to closing rate / opening if excessive ice removal
+!---------------------------------------------------------------
+! Reduce the closing rate if more than 100% of any ice category 
+! would be removed.  Reduce the opening rate proportionately.
+
+      DO jl = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF ( a_i(ji,jj,jl) .GT. epsi11 .AND. athorn(ji,jj,jl) .GT. 0.0 ) THEN
+                  w1 = athorn(ji,jj,jl) * closing_gross(ji,jj) * rdt_ice
+                  IF ( w1 .GT. a_i(ji,jj,jl) ) THEN
+                     tmpfac = a_i(ji,jj,jl) / w1
+                     closing_gross(ji,jj) = closing_gross(ji,jj) * tmpfac
+                     opning(ji,jj) = opning(ji,jj) * tmpfac
+                  ENDIF
+               ENDIF
+            END DO !ji
+         END DO ! jj
+      END DO !jl
+
+! 3.3 Redistribute area, volume, and energy.
+!-----------------------------------------------------------------------------!
+
+      CALL lim_itd_me_ridgeshift (opning,    closing_gross, &
+                        msnow_mlt, esnow_mlt)
+
+! 3.4 Compute total area of ice plus open water after ridging.
+!-----------------------------------------------------------------------------!
+
+      CALL lim_itd_me_asumr
+
+! 3.5 Do we keep on iterating ???
+!-----------------------------------------------------------------------------!
+! Check whether asum = 1.  If not (because the closing and opening
+! rates were reduced above), ridge again with new rates.
+
+      iterate_ridging = 0
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF (ABS(asum(ji,jj) - 1.0) .LT. epsi11) THEN
+               closing_net(ji,jj) = 0.0 
+               opning(ji,jj)      = 0.0
+            ELSE
+               iterate_ridging    = 1
+               divu_adv(ji,jj)    = (1.0 - asum(ji,jj)) / rdt_ice
+               closing_net(ji,jj) = MAX(0.0, -divu_adv(ji,jj))
+               opning(ji,jj)      = MAX(0.0, divu_adv(ji,jj))
+            ENDIF
+         END DO
+      END DO
+
+      IF( lk_mpp ) CALL mpp_max(iterate_ridging)
+
+! Repeat if necessary.
+! NOTE: If strength smoothing is turned on, the ridging must be
+! iterated globally because of the boundary update in the 
+! smoothing.
+
+      niter = niter + 1
+
+      IF (iterate_ridging == 1) THEN
+         IF (niter .GT. nitermax) THEN
+            WRITE(numout,*) ' ALERTE : non-converging ridging scheme '
+            WRITE(numout,*) ' niter, iterate_ridging ', niter, iterate_ridging
+         ENDIF
+         CALL lim_itd_me_ridgeprep
+      ENDIF
+
+      END DO !! on the do while over iter
+
+!-----------------------------------------------------------------------------!
+! 4) Ridging diagnostics
+!-----------------------------------------------------------------------------!
+! Convert ridging rate diagnostics to correct units.
+! Update fresh water and heat fluxes due to snow melt.
+
+      dti = 1.0/rdt_ice
+
+      asum_error = .false. 
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+
+         IF (ABS(asum(ji,jj) - 1.0) .GT. epsi11) asum_error = .true.
+
+         dardg1dt(ji,jj) = dardg1dt(ji,jj) * dti
+         dardg2dt(ji,jj) = dardg2dt(ji,jj) * dti
+         dvirdgdt(ji,jj) = dvirdgdt(ji,jj) * dti
+         opening (ji,jj) = opening (ji,jj) * dti
+
+!-----------------------------------------------------------------------------!
+! 5) Heat, salt and freshwater fluxes
+!-----------------------------------------------------------------------------!
+         ! fresh water source for ocean
+         fmmec(ji,jj)      = fmmec(ji,jj)      + msnow_mlt(ji,jj)*dti  
+      
+         ! heat sink for ocean
+         fhmec(ji,jj)      = fhmec(ji,jj)      + esnow_mlt(ji,jj)*dti
+
+         END DO
+      END DO
+
+      ! Check if there is a ridging error
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF (ABS(asum(ji,jj) - 1.0) .GT. epsi11) THEN ! there is a bug
+               WRITE(numout,*) ' '
+               WRITE(numout,*) ' ALERTE : Ridging error: total area = ', asum(ji,jj)
+               WRITE(numout,*) ' limitd_me '
+               WRITE(numout,*) ' POINT : ', ji, jj
+               WRITE(numout,*) ' jpl, a_i, athorn '
+               WRITE(numout,*) 0, ato_i(ji,jj), athorn(ji,jj,0)
+               DO jl = 1, jpl
+                  WRITE(numout,*) jl, a_i(ji,jj,jl), athorn(ji,jj,jl)
+               END DO
+            ENDIF  ! asum
+
+         END DO !ji
+      END DO !jj
+
+      ! Conservation check
+      IF ( con_i ) THEN
+         CALL lim_column_sum (jpl,   v_i, vt_i_final)
+         fieldid = ' v_i : limitd_me '
+         CALL lim_cons_check (vt_i_init, vt_i_final, 1.0e-6, fieldid) 
+      ENDIF
+
+!-----------------------------------------------------------------------------!
+! 6) Updating state variables and trend terms
+!-----------------------------------------------------------------------------!
+
+      CALL lim_var_glo2eqv
+      CALL lim_itd_me_zapsmall
+
+      !-----------------
+      !  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.0
+      IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) &
+      d_smv_i_trp(:,:,:)  = smv_i(:,:,:) - old_smv_i(:,:,:)
+
+      IF(ln_ctl) THEN     ! Control print
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Cell values : ')
+         CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
+         CALL prt_ctl(tab2d_1=area , clinfo1=' lim_itd_me  : cell area :')
+         CALL prt_ctl(tab2d_1=at_i , clinfo1=' lim_itd_me  : at_i      :')
+         CALL prt_ctl(tab2d_1=vt_i , clinfo1=' lim_itd_me  : vt_i      :')
+         CALL prt_ctl(tab2d_1=vt_s , clinfo1=' lim_itd_me  : vt_s      :')
+         DO jl = 1, jpl
+            CALL prt_ctl_info(' ')
+            CALL prt_ctl_info(' - Category : ', ivar1=jl)
+            CALL prt_ctl_info('   ~~~~~~~~~~')
+            CALL prt_ctl(tab2d_1=a_i   (:,:,jl)   , clinfo1= ' lim_itd_me  : a_i      : ')
+            CALL prt_ctl(tab2d_1=ht_i  (:,:,jl)   , clinfo1= ' lim_itd_me  : ht_i     : ')
+            CALL prt_ctl(tab2d_1=ht_s  (:,:,jl)   , clinfo1= ' lim_itd_me  : ht_s     : ')
+            CALL prt_ctl(tab2d_1=v_i   (:,:,jl)   , clinfo1= ' lim_itd_me  : v_i      : ')
+            CALL prt_ctl(tab2d_1=v_s   (:,:,jl)   , clinfo1= ' lim_itd_me  : v_s      : ')
+            CALL prt_ctl(tab2d_1=e_s   (:,:,1,jl) , clinfo1= ' lim_itd_me  : e_s      : ')
+            CALL prt_ctl(tab2d_1=t_su  (:,:,jl)   , clinfo1= ' lim_itd_me  : t_su     : ')
+            CALL prt_ctl(tab2d_1=t_s   (:,:,1,jl) , clinfo1= ' lim_itd_me  : t_snow   : ')
+            CALL prt_ctl(tab2d_1=sm_i  (:,:,jl)   , clinfo1= ' lim_itd_me  : sm_i     : ')
+            CALL prt_ctl(tab2d_1=smv_i (:,:,jl)   , clinfo1= ' lim_itd_me  : smv_i    : ')
+            DO jk = 1, nlay_i
+               CALL prt_ctl_info(' ')
+               CALL prt_ctl_info(' - Layer : ', ivar1=jk)
+               CALL prt_ctl_info('   ~~~~~~~')
+               CALL prt_ctl(tab2d_1=t_i(:,:,jk,jl) , clinfo1= ' lim_itd_me  : t_i      : ')
+               CALL prt_ctl(tab2d_1=e_i(:,:,jk,jl) , clinfo1= ' lim_itd_me  : e_i      : ')
+            END DO
+         END DO
+      ENDIF
+
+      !-------------------------!
+      ! Back to initial values
+      !-------------------------!
+
+      ! update of fields will be made later in lim update
+      u_ice(:,:)    = old_u_ice(:,:)
+      v_ice(:,:)    = old_v_ice(:,:)
+      a_i(:,:,:)    = old_a_i(:,:,:)
+      v_s(:,:,:)    = old_v_s(:,:,:)
+      v_i(:,:,:)    = old_v_i(:,:,:)
+      e_s(:,:,:,:)  = old_e_s(:,:,:,:)
+      e_i(:,:,:,:)  = old_e_i(:,:,:,:)
+      oa_i(:,:,:)   = old_oa_i(:,:,:)
+      IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) & 
+      smv_i(:,:,:)  = old_smv_i(:,:,:)
+
+      !----------------------------------------------------!
+      ! Advection of ice in a free cell, newly ridged ice
+      !----------------------------------------------------!
+
+      ! to allow for thermodynamics to melt new ice
+      ! we immediately advect ice in free cells
+
+      ! heat content has to be corrected before ice volume
+      DO jl = 1, jpl
+         DO jk = 1, nlay_i
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF ( ( old_v_i(ji,jj,jl) .LT. epsi06 ) .AND. &
+                       ( d_v_i_trp(ji,jj,jl) .GT. epsi06 ) ) THEN
+                      old_e_i(ji,jj,jk,jl)   = d_e_i_trp(ji,jj,jk,jl)
+                      d_e_i_trp(ji,jj,jk,jl) = 0.0
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      END DO
+
+      DO jl = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF ( ( old_v_i(ji,jj,jl) .LT. epsi06 ) .AND. &
+                    ( d_v_i_trp(ji,jj,jl) .GT. epsi06 ) ) THEN
+                   old_v_i(ji,jj,jl)     = d_v_i_trp(ji,jj,jl)
+                   d_v_i_trp(ji,jj,jl)   = 0.0
+                   old_a_i(ji,jj,jl)     = d_a_i_trp(ji,jj,jl)
+                   d_a_i_trp(ji,jj,jl)   = 0.0
+                   old_v_s(ji,jj,jl)     = d_v_s_trp(ji,jj,jl)
+                   d_v_s_trp(ji,jj,jl)   = 0.0
+                   old_e_s(ji,jj,1,jl)   = d_e_s_trp(ji,jj,1,jl)
+                   d_e_s_trp(ji,jj,1,jl) = 0.0
+                   old_oa_i(ji,jj,jl)    = d_oa_i_trp(ji,jj,jl)
+                   d_oa_i_trp(ji,jj,jl)  = 0.0
+                   IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) & 
+                   old_smv_i(ji,jj,jl)   = d_smv_i_trp(ji,jj,jl)
+                   d_smv_i_trp(ji,jj,jl) = 0.0
+               ENDIF
+            END DO
+         END DO
+      END DO
+         
+   END SUBROUTINE lim_itd_me
+
+!===============================================================================
+
+   SUBROUTINE lim_itd_me_icestrength (kstrngth) ! (subroutine 2/6)
+
+        !!----------------------------------------------------------------------
+        !!                ***  ROUTINE lim_itd_me_icestrength ***
+        !! ** Purpose :
+        !!        This routine computes ice strength used in dynamics routines
+        !!                      of ice thickness
+        !!
+        !! ** Method  :
+        !!       Compute the strength of the ice pack, defined as the energy (J m-2) 
+        !! dissipated per unit area removed from the ice pack under compression,
+        !! and assumed proportional to the change in potential energy caused
+        !! by ridging. Note that only Hibler's formulation is stable and that
+        !! ice strength has to be smoothed
+        !!
+        !! ** Inputs / Ouputs : kstrngth (what kind of ice strength we are using)
+        !!
+        !! ** External : 
+        !!
+        !! ** References :
+        !!                
+        !!----------------------------------------------------------------------
+        !! * Arguments
+ 
+      INTEGER, INTENT(in) :: &
+         kstrngth    ! = 1 for Rothrock formulation, 0 for Hibler (1979)
+
+      INTEGER ::   &
+         ji,jj,    &         !: horizontal indices
+         jl,       &         !: thickness category index
+         ksmooth,  &         !: smoothing the resistance to deformation
+         numts_rm            !: number of time steps for the P smoothing
+
+      REAL(wp) ::  &  
+         hi,       &         !: ice thickness (m)
+         zw1,      &         !: temporary variable
+         zp,       &         !: temporary ice strength 
+         zdummy
+
+      REAL(wp), DIMENSION(jpi,jpj) :: &
+         zworka              !: temporary array used here
+
+!------------------------------------------------------------------------------!
+! 1) Initialize
+!------------------------------------------------------------------------------!
+      strength(:,:) = 0.0
+
+!------------------------------------------------------------------------------!
+! 2) Compute thickness distribution of ridging and ridged ice
+!------------------------------------------------------------------------------!
+      CALL lim_itd_me_ridgeprep
+
+!------------------------------------------------------------------------------!
+! 3) Rothrock(1975)'s method
+!------------------------------------------------------------------------------!
+      IF (kstrngth == 1) then
+
+         DO jl = 1, jpl
+            DO jj= 1, jpj
+               DO ji = 1, jpi
+
+                  IF                                                           &
+                  (       ( a_i(ji,jj,jl)    .GT. epsi11 )                     &
+                    .AND. ( athorn(ji,jj,jl) .GT. 0.0    ) ) THEN
+                     hi = v_i(ji,jj,jl) / a_i(ji,jj,jl)
+                     !----------------------------
+                     ! PE loss from deforming ice
+                     !----------------------------
+                     strength(ji,jj) = strength(ji,jj) - athorn(ji,jj,jl) *    &
+                     hi * hi
+
+                     !--------------------------
+                     ! PE gain from rafting ice
+                     !--------------------------
+                     strength(ji,jj) = strength(ji,jj) + 2.0 * araft(ji,jj,jl) &
+                     * hi * hi
+
+                     !----------------------------
+                     ! PE gain from ridging ice
+                     !----------------------------
+                     strength(ji,jj) = strength(ji,jj)                         &
+                     + aridge(ji,jj,jl)/krdg(ji,jj,jl)                         &
+                     * 1.0/3.0 * (hrmax(ji,jj,jl)**3 - hrmin(ji,jj,jl)**3)     &
+                     / (hrmax(ji,jj,jl)-hrmin(ji,jj,jl))                      
+                  ENDIF            ! aicen > epsi11
+
+               END DO ! ji
+            END DO !jj
+         END DO !jl
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               strength(ji,jj) = Cf * Cp * strength(ji,jj) / aksum(ji,jj) 
+                          ! Cp = (g/2)*(rhow-rhoi)*(rhoi/rhow)
+                          ! Cf accounts for frictional dissipation
+               
+            END DO              ! j
+         END DO                 ! i
+
+         ksmooth = 1
+
+!------------------------------------------------------------------------------!
+! 4) Hibler (1979)' method
+!------------------------------------------------------------------------------!
+      ELSE                      ! kstrngth ne 1:  Hibler (1979) form
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               strength(ji,jj) = Pstar*vt_i(ji,jj)*exp(-C_rhg*(1.0-at_i(ji,jj)))
+            END DO              ! j
+         END DO                 ! i
+
+         ksmooth = 1
+
+      ENDIF                     ! kstrngth
+
+!
+!------------------------------------------------------------------------------!
+! 5) Impact of brine volume
+!------------------------------------------------------------------------------!
+! CAN BE REMOVED
+!
+      IF ( brinstren_swi .EQ. 1 ) THEN
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF ( bv_i(ji,jj) .GT. 0.0 ) THEN
+                  zdummy = MIN ( bv_i(ji,jj), 0.10 ) * MIN( bv_i(ji,jj), 0.10 )
+               ELSE
+                  zdummy = 0.0
+               ENDIF
+               strength(ji,jj) = strength(ji,jj) * exp(-5.88*SQRT(MAX(bv_i(ji,jj),0.0)))
+            END DO              ! j
+         END DO                 ! i
+
+      ENDIF
+
+!
+!------------------------------------------------------------------------------!
+! 6) Smoothing ice strength
+!------------------------------------------------------------------------------!
+!
+      !-------------------
+      ! Spatial smoothing
+      !-------------------
+      IF ( ksmooth .EQ. 1 ) THEN
+
+         CALL lbc_lnk( strength, 'T', 1. )
+
+         DO jj = 2, jpj - 1
+            DO ji = 2, jpi - 1
+               IF ( ( asum(ji,jj) - ato_i(ji,jj) ) .GT. epsi11) THEN ! ice is
+                                                                     ! present
+                  zworka(ji,jj) = 4.0 * strength(ji,jj)              &
+                                  + strength(ji-1,jj) * tms(ji-1,jj) &  
+                                  + strength(ji+1,jj) * tms(ji+1,jj) &  
+                                  + strength(ji,jj-1) * tms(ji,jj-1) &  
+                                  + strength(ji,jj+1) * tms(ji,jj+1)    
+
+                  zw1 = 4.0 + tms(ji-1,jj) + tms(ji+1,jj)            &
+                            + tms(ji,jj-1) + tms(ji,jj+1)
+                  zworka(ji,jj) = zworka(ji,jj) / zw1
+               ELSE
+                  zworka(ji,jj) = 0.0
+               ENDIF
+            END DO
+         END DO
+
+         DO jj = 2, jpj - 1
+            DO ji = 2, jpi - 1
+               strength(ji,jj) = zworka(ji,jj)
+            END DO
+         END DO
+         CALL lbc_lnk( strength, 'T', 1. )
+
+      ENDIF ! ksmooth
+
+      !--------------------
+      ! Temporal smoothing
+      !--------------------
+      IF ( numit .EQ. nit000 + nfice - 1 ) THEN
+         strp1(:,:) = 0.0            
+         strp2(:,:) = 0.0            
+      ENDIF
+
+      IF ( ksmooth .EQ. 2 ) THEN
+                 
+         
+         CALL lbc_lnk( strength, 'T', 1. )
+            
+         DO jj = 1, jpj - 1
+            DO ji = 1, jpi - 1
+               IF ( ( asum(ji,jj) - ato_i(ji,jj) ) .GT. epsi11) THEN ! ice is
+                                                                     ! present
+                  numts_rm = 1 ! number of time steps for the running mean
+                  IF ( strp1(ji,jj) .GT. 0.0 ) numts_rm = numts_rm + 1
+                  IF ( strp2(ji,jj) .GT. 0.0 ) numts_rm = numts_rm + 1
+                  zp = ( strength(ji,jj) + strp1(ji,jj) + strp2(ji,jj) ) /   &
+                       numts_rm
+                  strp2(ji,jj) = strp1(ji,jj)
+                  strp1(ji,jj) = strength(ji,jj)
+                  strength(ji,jj) = zp
+
+               ENDIF
+            END DO
+         END DO
+
+      ENDIF ! ksmooth
+      
+      ! Boundary conditions
+      CALL lbc_lnk( strength, 'T', 1. )
+
+      END SUBROUTINE lim_itd_me_icestrength
+
+!===============================================================================
+
+      SUBROUTINE lim_itd_me_ridgeprep !(subroutine 3/6)
+
+        !!---------------------------------------------------------------------!
+        !!                ***  ROUTINE lim_itd_me_ridgeprep ***
+        !! ** Purpose :
+        !!         preparation for ridging and strength calculations
+        !!
+        !! ** Method  :
+        !! Compute the thickness distribution of the ice and open water 
+        !! participating in ridging and of the resulting ridges.
+        !!
+        !! ** Arguments :
+        !!
+        !! ** External : 
+        !!
+        !!---------------------------------------------------------------------!
+        !! * Arguments
+ 
+      INTEGER :: &
+         ji,jj,  &          ! horizontal indices
+         jl,     &          ! thickness category index
+         krdg_index         ! which participation function using
+
+      REAL(wp)            ::     &
+         Gstari, &          !  = 1.0/Gstar    
+         astari             !  = 1.0/astar
+
+      REAL(wp), DIMENSION(jpi,jpj,-1:jpl) ::    &
+         Gsum             ! Gsum(n) = sum of areas in categories 0 to n
+
+      REAL(wp) ::    &
+         hi,         &    ! ice thickness for each cat (m)
+         hrmean           ! mean ridge thickness (m)
+
+      REAL(wp), DIMENSION(jpi,jpj) :: &
+         zworka            ! temporary array used here
+
+      REAL(wp)            ::     &
+         zdummy,                 &
+         epsi06 = 1.0e-6
+
+!------------------------------------------------------------------------------!
+
+      Gstari     = 1.0/Gstar    
+      astari     = 1.0/astar    
+      aksum(:,:)    = 0.0
+      athorn(:,:,:) = 0.0
+      aridge(:,:,:) = 0.0
+      araft (:,:,:) = 0.0
+      hrmin(:,:,:)  = 0.0 
+      hrmax(:,:,:)  = 0.0 
+      hraft(:,:,:)  = 0.0 
+      krdg (:,:,:)  = 1.0
+
+!     ! Zero out categories with very small areas
+      CALL lim_itd_me_zapsmall
+
+!------------------------------------------------------------------------------!
+! 1) Participation function 
+!------------------------------------------------------------------------------!
+
+      ! Compute total area of ice plus open water.
+      CALL lim_itd_me_asumr
+      ! This is in general not equal to one 
+      ! because of divergence during transport
+
+      ! Compute cumulative thickness distribution function
+      ! Compute the cumulative thickness distribution function Gsum,
+      ! where Gsum(n) is the fractional area in categories 0 to n.
+      ! initial value (in h = 0) equals open water area
+
+      Gsum(:,:,-1) = 0.0
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF (ato_i(ji,jj) .GT. epsi11) THEN
+               Gsum(ji,jj,0) = ato_i(ji,jj)
+            ELSE
+               Gsum(ji,jj,0) = 0.0
+            ENDIF
+         END DO
+      END DO
+
+      ! for each value of h, you have to add ice concentration then
+      DO jl = 1, jpl
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+               IF ( a_i(ji,jj,jl) .GT. epsi11 ) THEN
+                  Gsum(ji,jj,jl) = Gsum(ji,jj,jl-1) + a_i(ji,jj,jl)
+               ELSE
+                  Gsum(ji,jj,jl) = Gsum(ji,jj,jl-1)
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      ! Normalize the cumulative distribution to 1
+      DO jj = 1, jpj 
+         DO ji = 1, jpi
+            zworka(ji,jj) = 1.0 / Gsum(ji,jj,jpl)
+         END DO
+      END DO
+
+      DO jl = 0, jpl
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+               Gsum(ji,jj,jl) = Gsum(ji,jj,jl) * zworka(ji,jj)
+            END DO 
+         END DO
+      END DO
+
+! 1.3 Compute participation function a(h) = b(h).g(h) (athorn)
+!--------------------------------------------------------------------------------------------------
+! Compute the participation function athorn; this is analogous to
+! a(h) = b(h)g(h) as defined in Thorndike et al. (1975).
+! area lost from category n due to ridging/closing
+! athorn(n)   = total area lost due to ridging/closing
+! assume b(h) = (2/Gstar) * (1 - G(h)/Gstar). 
+!
+! The expressions for athorn are found by integrating b(h)g(h) between
+! the category boundaries.
+!-----------------------------------------------------------------
+
+      krdg_index = 1
+
+      IF ( krdg_index .EQ. 0 ) THEN
+
+      !--- Linear formulation (Thorndike et al., 1975)
+      DO jl = 0, ice_cat_bounds(1,2) ! only undeformed ice participates
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+               IF (Gsum(ji,jj,jl) < Gstar) THEN
+                  athorn(ji,jj,jl) = Gstari * (Gsum(ji,jj,jl)-Gsum(ji,jj,jl-1)) * &
+                       (2.0 - (Gsum(ji,jj,jl-1)+Gsum(ji,jj,jl))*Gstari)
+               ELSEIF (Gsum(ji,jj,jl-1) < Gstar) THEN
+                  athorn(ji,jj,jl) = Gstari * (Gstar-Gsum(ji,jj,jl-1)) *  &
+                       (2.0 - (Gsum(ji,jj,jl-1)+Gstar)*Gstari)
+               ELSE
+                  athorn(ji,jj,jl) = 0.0
+               ENDIF
+            END DO ! ji
+         END DO ! jj
+      END DO ! jl 
+
+      ELSE ! krdg_index = 1
+      
+      !--- Exponential, more stable formulation (Lipscomb et al, 2007)
+      ! precompute exponential terms using Gsum as a work array
+      zdummy = 1.0 / (1.0-EXP(-astari))
+
+      DO jl = -1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               Gsum(ji,jj,jl) = EXP(-Gsum(ji,jj,jl)*astari)*zdummy
+            END DO !ji
+         END DO !jj
+      END DO !jl
+
+      ! compute athorn
+      DO jl = 0, ice_cat_bounds(1,2)
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               athorn(ji,jj,jl) = Gsum(ji,jj,jl-1) - Gsum(ji,jj,jl)
+            END DO !ji
+         END DO ! jj
+      END DO !jl
+
+      ENDIF ! krdg_index
+
+      ! Ridging and rafting ice participation functions
+      IF ( raftswi .EQ. 1 ) THEN
+
+         DO jl = 1, jpl
+            DO jj = 1, jpj 
+               DO ji = 1, jpi
+                  IF ( athorn(ji,jj,jl) .GT. 0.0 ) THEN
+                     aridge(ji,jj,jl) = ( TANH ( Craft * ( ht_i(ji,jj,jl) - &
+                                          hparmeter ) ) + 1.0 ) / 2.0 * & 
+                                          athorn(ji,jj,jl)
+                     araft (ji,jj,jl) = ( TANH ( - Craft * ( ht_i(ji,jj,jl) - &
+                                          hparmeter ) ) + 1.0 ) / 2.0 * &
+                                          athorn(ji,jj,jl)
+                     IF ( araft(ji,jj,jl) .LT. epsi06 ) araft(ji,jj,jl)  = 0.0
+                     aridge(ji,jj,jl) = MAX( athorn(ji,jj,jl) - araft(ji,jj,jl), 0.0)
+                  ENDIF ! athorn
+               END DO ! ji
+            END DO ! jj
+         END DO ! jl
+
+      ELSE  ! raftswi = 0
+
+         DO jl = 1, jpl
+            DO jj = 1, jpj 
+               DO ji = 1, jpi
+                  aridge(ji,jj,jl) = 1.0*athorn(ji,jj,jl)
+               END DO
+            END DO
+         END DO
+
+      ENDIF
+
+      IF ( raftswi .EQ. 1 ) THEN
+
+      IF( MAXVAL(aridge + araft - athorn(:,:,1:jpl)) .GT. epsi11 ) THEN
+         DO jl = 1, jpl
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF ( aridge(ji,jj,jl) + araft(ji,jj,jl) - athorn(ji,jj,jl) .GT. &
+                  epsi11 ) THEN
+                     WRITE(numout,*) ' ALERTE 96 : wrong participation function ... '
+                     WRITE(numout,*) ' ji, jj, jl : ', ji, jj, jl
+                     WRITE(numout,*) ' lat, lon   : ', gphit(ji,jj), glamt(ji,jj)
+                     WRITE(numout,*) ' aridge     : ', aridge(ji,jj,1:jpl)
+                     WRITE(numout,*) ' araft      : ', araft(ji,jj,1:jpl)
+                     WRITE(numout,*) ' athorn     : ', athorn(ji,jj,1:jpl)
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      ENDIF
+
+!-----------------------------------------------------------------
+! 2) Transfer function
+!-----------------------------------------------------------------
+! Compute max and min ridged ice thickness for each ridging category.
+! Assume ridged ice is uniformly distributed between hrmin and hrmax.
+! 
+! This parameterization is a modified version of Hibler (1980).
+! The mean ridging thickness, hrmean, is proportional to hi^(0.5)
+!  and for very thick ridging ice must be >= krdgmin*hi
+!
+! The minimum ridging thickness, hrmin, is equal to 2*hi 
+!  (i.e., rafting) and for very thick ridging ice is
+!  constrained by hrmin <= (hrmean + hi)/2.
+! 
+! The maximum ridging thickness, hrmax, is determined by
+!  hrmean and hrmin.
+!
+! These modifications have the effect of reducing the ice strength
+! (relative to the Hibler formulation) when very thick ice is
+! ridging.
+!
+! aksum = net area removed/ total area removed
+! where total area removed = area of ice that ridges
+!         net area removed = total area removed - area of new ridges
+!-----------------------------------------------------------------
+
+      ! Transfer function
+      DO jl = 1, jpl !all categories have a specific transfer function
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+               IF (a_i(ji,jj,jl) .GT. epsi11 .AND. athorn(ji,jj,jl) .GT. 0.0 ) THEN
+                  hi = v_i(ji,jj,jl) / a_i(ji,jj,jl)
+                  hrmean          = MAX(SQRT(Hstar*hi), hi*krdgmin)
+                  hrmin(ji,jj,jl) = MIN(2.0*hi, 0.5*(hrmean + hi))
+                  hrmax(ji,jj,jl) = 2.0*hrmean - hrmin(ji,jj,jl)
+                  hraft(ji,jj,jl) = kraft*hi
+                  krdg(ji,jj,jl)  = hrmean / hi
+               ELSE
+                  hraft(ji,jj,jl) = 0.0
+                  hrmin(ji,jj,jl) = 0.0 
+                  hrmax(ji,jj,jl) = 0.0 
+                  krdg (ji,jj,jl) = 1.0
+               ENDIF
+
+            END DO ! ji
+         END DO ! jj
+      END DO ! jl
+
+      ! Normalization factor : aksum, ensures mass conservation
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            aksum(ji,jj) = athorn(ji,jj,0)
+         END DO
+      END DO
+
+      DO jl = 1, jpl 
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               aksum(ji,jj)    = aksum(ji,jj)                          &
+                       + aridge(ji,jj,jl) * (1.0 - 1.0/krdg(ji,jj,jl))    &
+                       + araft (ji,jj,jl) * (1.0 - 1.0/kraft)
+            END DO
+         END DO
+      END DO
+
+      END SUBROUTINE lim_itd_me_ridgeprep
+
+!===============================================================================
+
+      SUBROUTINE lim_itd_me_ridgeshift(opning,    closing_gross,       &
+                              msnow_mlt, esnow_mlt) ! (subroutine 4/6)
+
+        !!-----------------------------------------------------------------------------
+        !!                ***  ROUTINE lim_itd_me_icestrength ***
+        !! ** Purpose :
+        !!        This routine shift ridging ice among thickness categories
+        !!                      of ice thickness
+        !!
+        !! ** Method  :
+        !! Remove area, volume, and energy from each ridging category
+        !! and add to thicker ice categories.
+        !!
+        !! ** Arguments :
+        !!
+        !! ** Inputs / Ouputs : 
+        !!
+        !! ** External : 
+        !!
+
+      REAL (wp), DIMENSION(jpi,jpj), INTENT(IN)   :: &
+         opning,         & ! rate of opening due to divergence/shear
+         closing_gross     ! rate at which area removed, not counting
+                           ! area of new ridges
+
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) :: &
+         msnow_mlt,     & ! mass of snow added to ocean (kg m-2)
+         esnow_mlt        ! energy needed to melt snow in ocean (J m-2)
+
+      INTEGER :: &
+         ji, jj, &         ! horizontal indices
+         jl, jl1, jl2, &   ! thickness category indices
+         jk,           &   ! ice layer index
+         ij,           &   ! horizontal index, combines i and j loops
+         icells            ! number of cells with aicen > puny
+
+      INTEGER, DIMENSION(1:(jpi+1)*(jpj+1)) :: &
+         indxi, indxj      ! compressed indices
+
+      REAL(wp), DIMENSION(jpi,jpj) ::          &
+         vice_init, vice_final, &  ! ice volume summed over categories
+         eice_init, eice_final     ! ice energy summed over layers
+
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::      &
+         aicen_init,            &  ! ice area before ridging
+         vicen_init,            &  ! ice volume before ridging
+         vsnon_init,            &  ! snow volume before ridging
+         esnon_init,            &  ! snow energy before ridging
+         smv_i_init,            &  ! ice salinity before ridging
+         oa_i_init                 ! ice age before ridging
+
+      REAL(wp), DIMENSION(jpi,jpj,jkmax,jpl) :: &
+         eicen_init        ! ice energy before ridging
+
+      REAL(wp), DIMENSION(jpi,jpj) ::           &
+         afrac      , &     ! fraction of category area ridged
+         ardg1      , &     ! area of ice ridged
+         ardg2      , &     ! area of new ridges
+         vsrdg      , &     ! snow volume of ridging ice
+         esrdg      , &     ! snow energy of ridging ice
+         oirdg1     , &     ! areal age content of ridged ice
+         oirdg2     , &     ! areal age content of ridging ice
+         dhr        , &     ! hrmax - hrmin
+         dhr2       , &     ! hrmax^2 - hrmin^2
+         fvol               ! fraction of new ridge volume going to n2
+
+      REAL(wp), DIMENSION(jpi,jpj) :: &
+         vrdg1      , &     ! volume of ice ridged
+         vrdg2      , &     ! volume of new ridges
+         vsw        , &     ! volume of seawater trapped into ridges
+         srdg1      , &     ! sal*volume of ice ridged
+         srdg2      , &     ! sal*volume of new ridges
+         smsw               ! sal*volume of water trapped into ridges
+
+      REAL(wp), DIMENSION(jpi,jpj) ::           &
+         afrft      , &     ! fraction of category area rafted
+         arft1      , &     ! area of ice rafted
+         arft2      , &     ! area of new rafted zone
+         virft      , &     ! ice volume of rafting ice
+         vsrft      , &     ! snow volume of rafting ice
+         esrft      , &     ! snow energy of rafting ice
+         smrft      , &     ! salinity of rafting ice
+         oirft1     , &     ! areal age content of rafted ice
+         oirft2             ! areal age content of rafting ice
+
+      REAL(wp), DIMENSION(jpi,jpj,jkmax) ::    &
+         eirft      , &     ! ice energy of rafting ice
+         erdg1      , &     ! enth*volume of ice ridged
+         erdg2      , &     ! enth*volume of new ridges
+         ersw               ! enth of water trapped into ridges
+
+      REAL(wp) ::     &
+         hL, hR     , &    ! left and right limits of integration
+         farea      , &    ! fraction of new ridge area going to n2
+         zdummy     , &    ! dummy argument
+         zdummy0    , &    ! dummy argument
+         ztmelts    , &    ! ice melting point
+         sm_newridge       ! new ridged ice salinity
+
+      CHARACTER (len=80) :: &
+         fieldid           ! field identifier
+
+      LOGICAL, PARAMETER :: &
+         l_conservation_check = .true.  ! if true, check conservation 
+                                        ! (useful for debugging)
+      LOGICAL ::         &
+         neg_ato_i     , &  ! flag for ato_i(i,j) < -puny
+         large_afrac   , &  ! flag for afrac > 1
+         large_afrft        ! flag for afrac > 1
+
+      REAL(wp) ::        &
+         zeps          , &
+         epsi10        , &
+         zindb              ! switch for the presence of ridge poros or not
+
+   !----------------------------------------------------------------------------
+
+      ! Conservation check
+      eice_init(:,:) = 0.0 
+
+      IF ( con_i ) THEN
+         CALL lim_column_sum (jpl,   v_i, vice_init )
+         WRITE(numout,*) ' vice_init  : ', vice_init(jiindex,jjindex)
+         CALL lim_column_sum_energy (jpl, nlay_i,  e_i, eice_init )
+         WRITE(numout,*) ' eice_init  : ', eice_init(jiindex,jjindex)
+      ENDIF
+
+      zeps   = 1.0d-20
+      epsi10 = 1.0d-10
+
+!-------------------------------------------------------------------------------
+! 1) Compute change in open water area due to closing and opening.
+!-------------------------------------------------------------------------------
+
+      neg_ato_i = .false.
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ato_i(ji,jj) = ato_i(ji,jj)                                   &
+                    - athorn(ji,jj,0)*closing_gross(ji,jj)*rdt_ice        &
+                    + opning(ji,jj)*rdt_ice
+            IF (ato_i(ji,jj) .LT. -epsi11) THEN
+               neg_ato_i = .true.
+            ELSEIF (ato_i(ji,jj) .LT. 0.0) THEN    ! roundoff error
+               ato_i(ji,jj) = 0.0
+            ENDIF
+         END DO !jj
+      END DO !ji
+
+      ! if negative open water area alert it
+      IF (neg_ato_i) THEN       ! there is a bug
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+               IF (ato_i(ji,jj) .LT. -epsi11) THEN 
+                  WRITE(numout,*) ''  
+                  WRITE(numout,*) 'Ridging error: ato_i < 0'
+                  WRITE(numout,*) 'ato_i : ', ato_i(ji,jj)
+               ENDIF               ! ato_i < -epsi11
+            END DO              ! ji
+         END DO                 ! jj
+      ENDIF                     ! neg_ato_i
+
+!-----------------------------------------------------------------
+! 2) Save initial state variables
+!-----------------------------------------------------------------
+
+      DO jl = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               aicen_init(ji,jj,jl) = a_i(ji,jj,jl)
+               vicen_init(ji,jj,jl) = v_i(ji,jj,jl)
+               vsnon_init(ji,jj,jl) = v_s(ji,jj,jl)
+
+               smv_i_init(ji,jj,jl) = smv_i(ji,jj,jl)
+               oa_i_init (ji,jj,jl) = oa_i(ji,jj,jl)
+            END DO !ji
+         END DO ! jj
+      END DO !jl
+
+      esnon_init(:,:,:) = e_s(:,:,1,:)
+            
+      DO jl = 1, jpl  
+         DO jk = 1, nlay_i
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  eicen_init(ji,jj,jk,jl) = e_i(ji,jj,jk,jl)
+               END DO !ji
+            END DO !jj
+         END DO !jk
+      END DO !jl
+
+!
+!-----------------------------------------------------------------
+! 3) Pump everything from ice which is being ridged / rafted
+!-----------------------------------------------------------------
+! Compute the area, volume, and energy of ice ridging in each
+! category, along with the area of the resulting ridge.
+
+      DO jl1 = 1, jpl !jl1 describes the ridging category
+
+      !------------------------------------------------
+      ! 3.1) Identify grid cells with nonzero ridging
+      !------------------------------------------------
+
+         icells = 0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF (aicen_init(ji,jj,jl1) .GT. epsi11 .AND. athorn(ji,jj,jl1) .GT. 0.0       &
+                    .AND. closing_gross(ji,jj) > 0.0) THEN
+                  icells = icells + 1
+                  indxi(icells) = ji
+                  indxj(icells) = jj
+               ENDIF ! test on a_icen_init 
+            END DO ! ji
+         END DO ! jj
+
+         large_afrac = .false.
+         large_afrft = .false.
+
+!CDIR NODEP
+         DO ij = 1, icells
+            ji = indxi(ij)
+            jj = indxj(ij)
+
+      !--------------------------------------------------------------------
+      ! 3.2) Compute area of ridging ice (ardg1) and of new ridge (ardg2)
+      !--------------------------------------------------------------------
+
+            ardg1(ji,jj) = aridge(ji,jj,jl1)*closing_gross(ji,jj)*rdt_ice
+            arft1(ji,jj) = araft (ji,jj,jl1)*closing_gross(ji,jj)*rdt_ice
+            ardg2(ji,jj) = ardg1(ji,jj) / krdg(ji,jj,jl1)
+            arft2(ji,jj) = arft1(ji,jj) / kraft
+
+            oirdg1(ji,jj)= aridge(ji,jj,jl1)*closing_gross(ji,jj)*rdt_ice
+            oirft1(ji,jj)= araft (ji,jj,jl1)*closing_gross(ji,jj)*rdt_ice
+            oirdg2(ji,jj)= oirdg1(ji,jj) / krdg(ji,jj,jl1)
+            oirft2(ji,jj)= oirft1(ji,jj) / kraft
+
+      !---------------------------------------------------------------
+      ! 3.3) Compute ridging /rafting fractions, make sure afrac <=1 
+      !---------------------------------------------------------------
+
+            afrac(ji,jj) = ardg1(ji,jj) / aicen_init(ji,jj,jl1) !ridging
+            afrft(ji,jj) = arft1(ji,jj) / aicen_init(ji,jj,jl1) !rafting
+
+            IF (afrac(ji,jj) > 1.0 + epsi11) THEN  !riging
+               large_afrac = .true.
+            ELSEIF (afrac(ji,jj) > 1.0) THEN  ! roundoff error
+               afrac(ji,jj) = 1.0
+            ENDIF
+            IF (afrft(ji,jj) > 1.0 + epsi11) THEN !rafting
+               large_afrft = .true.
+            ELSEIF (afrft(ji,jj) > 1.0) THEN  ! roundoff error
+               afrft(ji,jj) = 1.0
+            ENDIF
+
+      !--------------------------------------------------------------------------
+      ! 3.4) Subtract area, volume, and energy from ridging 
+      !     / rafting category n1.
+      !--------------------------------------------------------------------------
+            vrdg1(ji,jj) = vicen_init(ji,jj,jl1) * afrac(ji,jj) /             &
+                           ( 1.0 + ridge_por )
+            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. + ridge_por )
+            srdg2(ji,jj) = smv_i_init(ji,jj,jl1) * afrac(ji,jj)
+
+            ! 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)
+            smrft(ji,jj) = smv_i_init(ji,jj,jl1) * afrft(ji,jj) 
+
+            ! substract everything
+            a_i(ji,jj,jl1)   = a_i(ji,jj,jl1)   - ardg1(ji,jj)  - arft1(ji,jj)
+            v_i(ji,jj,jl1)   = v_i(ji,jj,jl1)   - vrdg1(ji,jj)  - virft(ji,jj)
+            v_s(ji,jj,jl1)   = v_s(ji,jj,jl1)   - vsrdg(ji,jj)  - vsrft(ji,jj)
+            e_s(ji,jj,1,jl1) = e_s(ji,jj,1,jl1) - esrdg(ji,jj)  - esrft(ji,jj)
+            oa_i(ji,jj,jl1)  = oa_i(ji,jj,jl1)  - oirdg1(ji,jj) - oirft1(ji,jj)
+            smv_i(ji,jj,jl1) = smv_i(ji,jj,jl1) - srdg1(ji,jj)  - smrft(ji,jj)
+
+      !-----------------------------------------------------------------
+      ! 3.5) Compute properties of new ridges
+      !-----------------------------------------------------------------
+            !-------------
+            ! Salinity
+            !-------------
+            smsw(ji,jj)       = sss_io(ji,jj) * vsw(ji,jj) * ridge_por 
+
+            ! salinity of new ridge
+            sm_newridge       = ( srdg1(ji,jj) + smsw(ji,jj) ) / vrdg2(ji,jj)
+            zdummy            = sm_newridge * vrdg2(ji,jj)
+            ! has to be smaller than s_i_max
+            sm_newridge       = MIN( s_i_max, sm_newridge )
+
+            ! salt flux due to ridge creation
+            fsalt_rpo(ji,jj)  = fsalt_rpo(ji,jj) + & 
+            MAX ( zdummy - srdg2(ji,jj) , 0.0 )    &
+            * rhoic / rdt_ice
+
+            ! sal times volume for new ridges
+            srdg2(ji,jj)      = sm_newridge * vrdg2(ji,jj) 
+
+      !------------------------------------            
+      ! 3.6 Increment ridging diagnostics
+      !------------------------------------            
+
+!        jl1 looping 1-jpl
+!           ij looping 1-icells
+
+            dardg1dt(ji,jj) = dardg1dt(ji,jj) + ardg1(ji,jj) + arft1(ji,jj)
+            dardg2dt(ji,jj) = dardg2dt(ji,jj) + ardg2(ji,jj) + arft2(ji,jj)
+            diag_dyn_gr(ji,jj) = diag_dyn_gr(ji,jj) + ( vrdg2(ji,jj) + virft(ji,jj) ) / rdt_ice
+            opening(ji,jj)  = opening (ji,jj) + opning(ji,jj)*rdt_ice
+
+            IF (con_i) vice_init(ji,jj) = vice_init(ji,jj) + vrdg2(ji,jj) - vrdg1(ji,jj)
+
+      !------------------------------------------            
+      ! 3.7 Put the snow somewhere in the ocean
+      !------------------------------------------            
+
+!  Place part of the snow lost by ridging into the ocean. 
+!  Note that esnow_mlt < 0; the ocean must cool to melt snow.
+!  If the ocean temp = Tf already, new ice must grow.
+!  During the next time step, thermo_rates will determine whether
+!  the ocean cools or new ice grows.
+!        jl1 looping 1-jpl
+!           ij looping 1-icells
+               
+            msnow_mlt(ji,jj) = msnow_mlt(ji,jj)                  &
+                           + rhosn*vsrdg(ji,jj)*(1.0-fsnowrdg)   &
+                           !rafting included
+                           + 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)          
+
+      !-----------------------------------------------------------------
+      ! 3.8 Compute quantities used to apportion ice among categories
+      ! in the n2 loop below
+      !-----------------------------------------------------------------
+
+!        jl1 looping 1-jpl
+!           ij looping 1-icells
+
+            dhr(ji,jj)  = hrmax(ji,jj,jl1) - hrmin(ji,jj,jl1)
+            dhr2(ji,jj) = hrmax(ji,jj,jl1) * hrmax(ji,jj,jl1)    &
+                      - hrmin(ji,jj,jl1)   * hrmin(ji,jj,jl1)
+
+
+         END DO                 ! ij
+
+      !--------------------------------------------------------------------
+      ! 3.9 Compute ridging ice enthalpy, remove it from ridging ice and
+      !      compute ridged ice enthalpy 
+      !--------------------------------------------------------------------
+         DO jk = 1, nlay_i
+!CDIR NODEP
+            DO ij = 1, icells
+            ji = indxi(ij)
+            jj = indxj(ij)
+            ! heat content of ridged ice
+            erdg1(ji,jj,jk)      = eicen_init(ji,jj,jk,jl1) * afrac(ji,jj) / & 
+                                   ( 1.0 + ridge_por ) 
+            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_io(ji,jj) + rtt
+            ! heat content per unit volume
+            zdummy0          = - rcp * ( sst_io(ji,jj) - rtt ) * vsw(ji,jj)
+
+            ! corrected sea water salinity
+            zindb  = MAX( 0.0, SIGN( 1.0, vsw(ji,jj) - zeps ) )
+            zdummy = zindb * ( srdg1(ji,jj) - srdg2(ji,jj) ) / &
+                     MAX( ridge_por * vsw(ji,jj), zeps )
+
+            ztmelts          = - tmut * zdummy + rtt
+            ersw(ji,jj,jk)   = - rcp * ( ztmelts - rtt ) * vsw(ji,jj)
+
+            ! heat flux
+            fheat_rpo(ji,jj) = fheat_rpo(ji,jj) + ( ersw(ji,jj,jk) - zdummy0 ) / &
+                                     rdt_ice
+
+            ! Correct dimensions to avoid big values
+            ersw(ji,jj,jk)   = ersw(ji,jj,jk) / 1.0d+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) / &
+                               nlay_i
+
+            erdg2(ji,jj,jk)  = erdg1(ji,jj,jk) + ersw(ji,jj,jk)
+            END DO ! ij
+         END DO !jk
+
+
+         IF ( con_i ) THEN
+            DO jk = 1, nlay_i
+!CDIR NODEP
+               DO ij = 1, icells
+                  ji = indxi(ij)
+                  jj = indxj(ij)
+                  eice_init(ji,jj) = eice_init(ji,jj) + erdg2(ji,jj,jk) - &
+                  erdg1(ji,jj,jk)
+               END DO ! ij
+            END DO !jk
+         ENDIF
+
+         IF (large_afrac) THEN  ! there is a bug
+!CDIR NODEP
+            DO ij = 1, icells
+               ji = indxi(ij)
+               jj = indxj(ij)
+               IF ( afrac(ji,jj) > 1.0 + epsi11 ) THEN 
+                  WRITE(numout,*) ''
+                  WRITE(numout,*) ' ardg > a_i'
+                  WRITE(numout,*) ' ardg, aicen_init : ', &
+                       ardg1(ji,jj), aicen_init(ji,jj,jl1)
+               ENDIF            ! afrac > 1 + puny
+            ENDDO               ! if
+         ENDIF                  ! large_afrac
+         IF (large_afrft) THEN  ! there is a bug
+!CDIR NODEP
+            DO ij = 1, icells
+               ji = indxi(ij)
+               jj = indxj(ij)
+               IF ( afrft(ji,jj) > 1.0 + epsi11 ) THEN 
+                  WRITE(numout,*) ''
+                  WRITE(numout,*) ' arft > a_i'
+                  WRITE(numout,*) ' arft, aicen_init : ', &
+                       arft1(ji,jj), aicen_init(ji,jj,jl1)
+               ENDIF            ! afrft > 1 + puny
+            ENDDO               ! if
+         ENDIF                  ! large_afrft
+
+!-------------------------------------------------------------------------------
+! 4) Add area, volume, and energy of new ridge to each category jl2
+!-------------------------------------------------------------------------------
+!        jl1 looping 1-jpl
+         DO jl2  = ice_cat_bounds(1,1), ice_cat_bounds(1,2) 
+         ! over categories to which ridged ice is transferred
+!CDIR NODEP
+            DO ij = 1, icells
+               ji = indxi(ij)
+               jj = indxj(ij)
+
+               ! Compute the fraction of ridged ice area and volume going to 
+               ! thickness category jl2.
+               ! Transfer area, volume, and energy accordingly.
+
+               IF (hrmin(ji,jj,jl1) .GE. hi_max(jl2) .OR.        &
+                   hrmax(ji,jj,jl1) .LE. hi_max(jl2-1)) THEN
+                  hL = 0.0
+                  hR = 0.0
+               ELSE
+                  hL = MAX (hrmin(ji,jj,jl1), hi_max(jl2-1))
+                  hR = MIN (hrmax(ji,jj,jl1), hi_max(jl2))
+               ENDIF
+
+               ! fraction of ridged ice area and volume going to n2
+               farea = (hR-hL) / dhr(ji,jj) 
+               fvol(ji,jj) = (hR*hR - hL*hL) / dhr2(ji,jj)
+
+               a_i(ji,jj,jl2)    = a_i(ji,jj,jl2) + farea * ardg2(ji,jj)
+               v_i(ji,jj,jl2)    = v_i(ji,jj,jl2) + fvol(ji,jj) * vrdg2(ji,jj)
+               v_s(ji,jj,jl2)    = v_s(ji,jj,jl2)                             &
+                                 + fvol(ji,jj) * vsrdg(ji,jj) * fsnowrdg
+               e_s(ji,jj,1,jl2)  = e_s(ji,jj,1,jl2)                           &
+                                 + fvol(ji,jj) * esrdg(ji,jj) * fsnowrdg
+               smv_i(ji,jj,jl2)  = smv_i(ji,jj,jl2) + fvol(ji,jj) * srdg2(ji,jj)
+               oa_i(ji,jj,jl2)   = oa_i(ji,jj,jl2)  + farea * oirdg2(ji,jj)
+
+            END DO ! ij
+
+            ! Transfer ice energy to category jl2 by ridging
+            DO jk = 1, nlay_i
+!CDIR NODEP
+               DO ij = 1, icells
+                  ji = indxi(ij)
+                  jj = indxj(ij)
+                  e_i(ji,jj,jk,jl2) = e_i(ji,jj,jk,jl2)          &
+                                    + fvol(ji,jj)*erdg2(ji,jj,jk)
+               END DO           ! ij
+            END DO !jk
+
+
+         END DO                 ! jl2 (new ridges)            
+
+         DO jl2  = ice_cat_bounds(1,1), ice_cat_bounds(1,2) 
+
+!CDIR NODEP
+            DO ij = 1, icells
+               ji = indxi(ij)
+               jj = indxj(ij)
+               ! Compute the fraction of rafted ice area and volume going to 
+               ! thickness category jl2, transfer area, volume, and energy accordingly.
+            
+               IF (hraft(ji,jj,jl1) .LE. hi_max(jl2) .AND.        &
+                   hraft(ji,jj,jl1) .GT. hi_max(jl2-1)) THEN
+                  a_i(ji,jj,jl2) = a_i(ji,jj,jl2) + arft2(ji,jj)
+                  v_i(ji,jj,jl2) = v_i(ji,jj,jl2) + virft(ji,jj)
+                  v_s(ji,jj,jl2) = v_s(ji,jj,jl2)                   &
+                                 + vsrft(ji,jj)*fsnowrft
+                  e_s(ji,jj,1,jl2) = e_s(ji,jj,1,jl2)                   &
+                                 + esrft(ji,jj)*fsnowrft
+                  smv_i(ji,jj,jl2) = smv_i(ji,jj,jl2)                 &
+                                 + smrft(ji,jj)    
+                  oa_i(ji,jj,jl2)  = oa_i(ji,jj,jl2)                  &
+                                   + oirft2(ji,jj)    
+               ENDIF ! hraft
+
+            END DO ! ij
+
+            ! Transfer rafted ice energy to category jl2 
+            DO jk = 1, nlay_i
+!CDIR NODEP
+               DO ij = 1, icells
+                  ji = indxi(ij)
+                  jj = indxj(ij)
+                  IF (hraft(ji,jj,jl1) .LE. hi_max(jl2) .AND.        &
+                      hraft(ji,jj,jl1) .GT. hi_max(jl2-1)) THEN
+                     e_i(ji,jj,jk,jl2) = e_i(ji,jj,jk,jl2)             &
+                                       + eirft(ji,jj,jk)
+                  ENDIF
+               END DO           ! ij
+            END DO !jk
+
+         END DO ! jl2
+
+      END DO ! jl1 (deforming categories)
+
+      ! Conservation check
+      IF ( con_i ) THEN
+         CALL lim_column_sum (jpl,   v_i, vice_final)
+         fieldid = ' v_i : limitd_me '
+         CALL lim_cons_check (vice_init, vice_final, 1.0e-6, fieldid) 
+         WRITE(numout,*) ' vice_init  : ', vice_init(jiindex,jjindex)
+         WRITE(numout,*) ' vice_final : ', vice_final(jiindex,jjindex)
+
+         CALL lim_column_sum_energy (jpl, nlay_i,  e_i, eice_final )
+         fieldid = ' e_i : limitd_me '
+         CALL lim_cons_check (eice_init, eice_final, 1.0e-2, fieldid) 
+         WRITE(numout,*) ' eice_init  : ', eice_init(jiindex,jjindex)
+         WRITE(numout,*) ' eice_final : ', eice_final(jiindex,jjindex)
+      ENDIF
+
+   END SUBROUTINE lim_itd_me_ridgeshift
+
+!==============================================================================
+
+   SUBROUTINE lim_itd_me_asumr !(subroutine 5/6)
+
+        !!-----------------------------------------------------------------------------
+        !!                ***  ROUTINE lim_itd_me_asumr ***
+        !! ** Purpose :
+        !!        This routine finds total fractional area
+        !!
+        !! ** Method  :
+        !! Find the total area of ice plus open water in each grid cell.
+        !!
+        !! This is similar to the aggregate_area subroutine except that the
+        !! total area can be greater than 1, so the open water area is 
+        !! included in the sum instead of being computed as a residual. 
+        !!
+        !! ** Arguments :
+
+      INTEGER :: ji, jj, jl
+
+      !-----------------------------------------------------------------
+      ! open water
+      !-----------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            asum(ji,jj) = ato_i(ji,jj)
+         END DO
+      END DO
+
+      !-----------------------------------------------------------------
+      ! ice categories
+      !-----------------------------------------------------------------
+
+      DO jl = 1, jpl
+         DO jj= 1, jpj
+            DO ji = 1, jpi
+               asum(ji,jj) = asum(ji,jj) + a_i(ji,jj,jl)
+            END DO !ji
+         END DO !jj
+      END DO ! jl
+
+   END SUBROUTINE lim_itd_me_asumr
+
+!==============================================================================
+
+   SUBROUTINE lim_itd_me_init ! (subroutine 6/6)
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE lim_itd_me_init ***
+      !!
+      !! ** Purpose :   Physical constants and parameters linked 
+      !!                to the mechanical ice redistribution
+      !!
+      !! ** Method  :   Read the namiceitdme namelist 
+      !!                and check the parameters values 
+      !!                called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namiceitdme
+      !!
+      !! history :
+      !!  9.0, LIM3.0 - 02-2006 (M. Vancoppenolle) original code
+      !!-------------------------------------------------------------------
+      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
+      !!-------------------------------------------------------------------
+
+      ! Define the initial parameters
+      ! -------------------------
+      REWIND( numnam_ice )
+      READ  ( numnam_ice , namiceitdme)
+      IF (lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*)' lim_itd_me_init : ice parameters for mechanical ice redistribution '
+         WRITE(numout,*)' ~~~~~~~~~~~~~~~'
+         WRITE(numout,*)'   Switch choosing the ice redistribution scheme           ridge_scheme_swi', ridge_scheme_swi 
+         WRITE(numout,*)'   Fraction of shear energy contributing to ridging        Cs              ', Cs 
+         WRITE(numout,*)'   Ratio of ridging work to PotEner change in ridging      Cf              ', Cf 
+         WRITE(numout,*)'   Fraction of snow volume conserved during ridging        fsnowrdg        ', fsnowrdg 
+         WRITE(numout,*)'   Fraction of snow volume conserved during ridging        fsnowrft        ', fsnowrft 
+         WRITE(numout,*)'   Fraction of total ice coverage contributing to ridging  Gstar           ', Gstar
+         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,*)'   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
+
+   END SUBROUTINE lim_itd_me_init
+
+!==============================================================================
+
+   SUBROUTINE lim_itd_me_zapsmall
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE lim_itd_me_zapsmall ***
+      !!
+      !! ** Purpose :   Remove too small sea ice areas and correct salt fluxes
+      !!
+      !!
+      !! history :
+      !! author: William H. Lipscomb, LANL
+      !! Nov 2003:  Modified by Julie Schramm to conserve volume and energy
+      !! Sept 2004: Modified by William Lipscomb; replaced normalize_state with
+      !!            additions to local freshwater, salt, and heat fluxes
+      !!  9.0, LIM3.0 - 02-2006 (M. Vancoppenolle) original code
+      !!-------------------------------------------------------------------
+
+      INTEGER ::   &
+           ji,jj,  & ! horizontal indices
+           jl,     & ! ice category index
+           jk,     & ! ice layer index
+!           ij,     &   ! combined i/j horizontal index
+           icells      ! number of cells with ice to zap
+
+!      INTEGER, DIMENSION(1:(jpi+1)*(jpj+1)) :: &
+!           indxi,  & ! compressed indices for i/j directions
+!           indxj
+
+      INTEGER, DIMENSION(jpi,jpj) :: zmask
+
+
+      REAL(wp) :: &
+           xtmp      ! temporary variable
+
+      DO jl = 1, jpl
+
+      !-----------------------------------------------------------------
+      ! Count categories to be zapped.
+      ! Abort model in case of negative area.
+      !-----------------------------------------------------------------
+         IF( MINVAL(a_i(:,:,jl)) .LT. -epsi11 ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF ( a_i(ji,jj,jl) .LT. -epsi11 ) THEN
+                     WRITE (numout,*) ' ALERTE 98 ' 
+                     WRITE (numout,*) ' Negative ice area: ji, jj, jl: ', ji, jj,jl
+                     WRITE (numout,*) ' a_i    ', a_i(ji,jj,jl)
+                  ENDIF
+               END DO
+            END DO 
+         ENDIF
+ 
+       icells = 0
+       zmask = 0.e0
+       DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF ( ( a_i(ji,jj,jl) .GE. -epsi11 .AND. a_i(ji,jj,jl) .LT. 0.0)       &
+                                         .OR.                                         &
+                     ( a_i(ji,jj,jl) .GT. 0.0     .AND. a_i(ji,jj,jl) .LE. 1.0e-11 )  &
+                                         .OR.                                         &
+                                         !new line
+                     ( v_i(ji,jj,jl) .EQ. 0.0     .AND. a_i(ji,jj,jl) .GT. 0.0    )   &
+                                         .OR.                                         &
+                     ( v_i(ji,jj,jl) .GT. 0.0     .AND. v_i(ji,jj,jl) .LT. 1.e-12 ) ) THEN
+                zmask(ji,jj) = 1
+            ENDIF
+         END DO
+         END DO
+         WRITE(numout,*) SUM(zmask), ' cells of ice zapped in the ocean '
+
+      !-----------------------------------------------------------------
+      ! Zap ice energy and use ocean heat to melt ice
+      !-----------------------------------------------------------------
+
+         DO jk = 1, nlay_i
+            DO jj = 1 , jpj
+               DO ji = 1 , jpi
+
+               xtmp = e_i(ji,jj,jk,jl) / area(ji,jj) / rdt_ice
+               xtmp = xtmp * unit_fac
+!              fheat_res(ji,jj) = fheat_res(ji,jj) - xtmp
+               e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * ( 1 - zmask(ji,jj) )
+               END DO           ! ji
+            END DO           ! jj
+         END DO           ! jk
+
+         DO jj = 1 , jpj
+            DO ji = 1 , jpi
+
+      !-----------------------------------------------------------------
+      ! Zap snow energy and use ocean heat to melt snow
+      !-----------------------------------------------------------------
+
+!           xtmp = esnon(i,j,n) / dt ! < 0
+!           fhnet(i,j)      = fhnet(i,j)      + xtmp
+!           fhnet_hist(i,j) = fhnet_hist(i,j) + xtmp
+            ! xtmp is greater than 0
+            ! fluxes are positive to the ocean
+            ! here the flux has to be negative for the ocean
+            xtmp = ( rhosn*cpic*( rtt-t_s(ji,jj,1,jl) ) + rhosn*lfus ) / rdt_ice
+!           fheat_res(ji,jj) = fheat_res(ji,jj) - xtmp
+
+            xtmp = ( rhosn*cpic*( rtt-t_s(ji,jj,1,jl) ) + rhosn*lfus ) / rdt_ice !RB   ???????
+
+            t_s(ji,jj,1,jl) = rtt * zmask(ji,jj) + t_s(ji,jj,1,jl) * ( 1 - zmask(ji,jj) )
+
+      !-----------------------------------------------------------------
+      ! zap ice and snow volume, add water and salt to ocean
+      !-----------------------------------------------------------------
+
+!           xtmp = (rhoi*vicen(i,j,n) + rhos*vsnon(i,j,n)) / dt
+!           fresh(i,j)      = fresh(i,j)      + xtmp
+!           fresh_hist(i,j) = fresh_hist(i,j) + xtmp
+
+!           fsalt_res(ji,jj)  = fsalt_res(ji,jj) + ( sss_io(ji,jj)                  ) * & 
+!                               rhosn * v_s(ji,jj,jl) / rdt_ice
+
+!           fsalt_res(ji,jj)  = fsalt_res(ji,jj) + ( sss_io(ji,jj) - sm_i(ji,jj,jl) ) * & 
+!                               rhoic * v_i(ji,jj,jl) / rdt_ice
+
+!           fsalt(i,j)      = fsalt(i,j)      + xtmp
+!           fsalt_hist(i,j) = fsalt_hist(i,j) + xtmp
+
+            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 - zmask(ji,jj) )
+            v_i(ji,jj,jl)  = v_i(ji,jj,jl) * ( 1 - zmask(ji,jj) )
+            v_s(ji,jj,jl)  = v_s(ji,jj,jl) * ( 1 - zmask(ji,jj) )
+            t_su(ji,jj,jl) = t_su(ji,jj,jl) * (1 -zmask(ji,jj) ) + t_bo(ji,jj) * zmask(ji,jj)
+            oa_i(ji,jj,jl) = oa_i(ji,jj,jl) * ( 1 - zmask(ji,jj) )
+            smv_i(ji,jj,jl) = smv_i(ji,jj,jl) * ( 1 - zmask(ji,jj) )
+
+            END DO                 ! ji
+         END DO                 ! jj
+
+      END DO                 ! jl 
+
+   END SUBROUTINE lim_itd_me_zapsmall
+
+#else
+   !!======================================================================
+   !!                       ***  MODULE limitd_me    ***
+   !!                            no sea ice model
+   !!======================================================================
+
+CONTAINS
+
+   SUBROUTINE lim_itd_me           ! Empty routines
+   END SUBROUTINE lim_itd_me
+   SUBROUTINE lim_itd_me_icestrength
+   END SUBROUTINE lim_itd_me_icestrength
+   SUBROUTINE lim_itd_me_ridgeprep
+   END SUBROUTINE lim_itd_me_ridgeprep
+   SUBROUTINE lim_itd_th_me_ridgeshift
+   END SUBROUTINE lim_itd_me_ridgeshift
+   SUBROUTINE lim_itd_me_asumr
+   END SUBROUTINE lim_itd_me_asumr
+   SUBROUTINE lim_itd_me_sort
+   END SUBROUTINE lim_itd_me_sort
+   SUBROUTINE lim_itd_me_init
+   END SUBROUTINE lim_itd_me_init
+   SUBROUTINE lim_itd_me_zapsmall
+   END SUBROUTINE lim_itd_me_zapsmall
+#endif
+END MODULE limitd_me
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limitd_th.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limitd_th.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limitd_th.F90	(revision 884)
@@ -0,0 +1,1270 @@
+MODULE limitd_th
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' :                                   LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!======================================================================
+   !!                       ***  MODULE limitd_th ***
+   !!              Thermodynamics of ice thickness distribution
+   !!                   computation of changes in g(h)      
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_ice
+   USE par_oce          ! ocean parameters
+   USE dom_oce
+   USE phycst           ! physical constants (ocean directory) 
+   USE ice_oce          ! ice variables
+   USE thd_ice
+   USE limistate
+   USE in_out_manager
+   USE ice
+   USE par_ice
+   USE limthd_lac
+   USE limvar
+   USE iceini
+   USE limcons
+   USE prtctl           ! Print control
+   USE lib_mpp 
+ 
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_itd_th        ! called by ice_stp
+   PUBLIC lim_itd_th_rem
+   PUBLIC lim_itd_th_reb
+   PUBLIC lim_itd_fitline
+   PUBLIC lim_itd_shiftice
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      epsi20 = 1e-20   ,  &
+      epsi13 = 1e-13   ,  &
+      zzero  = 0.e0    ,  &
+      zone   = 1.e0
+
+   !!----------------------------------------------------------------------
+   !!   LIM3.0,  UCL-ASTR (2008)
+   !!   (c) UCL-ASTR and Martin Vancoppenolle
+   !!----------------------------------------------------------------------
+
+!!----------------------------------------------------------------------------------------------
+!!----------------------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_itd_th
+        !!------------------------------------------------------------------
+        !!                ***  ROUTINE lim_itd_th ***
+        !! ** Purpose :
+        !!        This routine computes the thermodynamics of ice thickness
+        !!         distribution
+        !! ** Method  :
+        !!
+        !! ** Arguments :
+        !!           kideb , kiut : Starting and ending points on which the 
+        !!                         the computation is applied
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !!
+        !! ** External : 
+        !!
+        !! ** References :
+        !!
+        !! ** History :
+        !!           (12-2005) Martin Vancoppenolle 
+        !!
+        !!------------------------------------------------------------------
+        !! * Arguments
+
+       !! * Local variables
+       INTEGER ::   jl, ja,   &   ! ice category, layers
+                    jm,       &   ! ice types    dummy loop index
+                    jbnd1,    &
+                    jbnd2
+
+       REAL(wp)  ::           &  ! constant values
+          zeps      =  1.0e-10, &
+          epsi10    =  1.0e-10
+
+!!-- End of declarations
+!!----------------------------------------------------------------------------------------------
+
+       IF (lwp) THEN
+          WRITE(numout,*)
+          WRITE(numout,*) 'lim_itd_th  : Thermodynamics of the ice thickness distribution'
+          WRITE(numout,*) '~~~~~~~~~~~'
+       ENDIF
+
+!------------------------------------------------------------------------------|
+!  1) Transport of ice between thickness categories.                           |
+!------------------------------------------------------------------------------|
+      ! 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) .GT. 1 ) CALL lim_itd_th_rem(jbnd1, jbnd2, jm)
+      END DO
+
+      CALL lim_var_glo2eqv ! only for info
+      CALL lim_var_agg(1)
+
+!------------------------------------------------------------------------------|
+!  3) Add frazil ice growing in leads.
+!------------------------------------------------------------------------------|
+
+      CALL lim_thd_lac
+      CALL lim_var_glo2eqv ! only for info
+
+!----------------------------------------------------------------------------------------
+!  4) Computation of trend terms and get back to old values      
+!----------------------------------------------------------------------------------------
+
+      !- 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_smv_i_thd(:,:,:) = 0.0
+      IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) &
+      d_smv_i_thd(:,:,:) = smv_i(:,:,:) - old_smv_i(:,:,:)
+
+      IF(ln_ctl) THEN   ! Control print
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Cell values : ')
+         CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
+         CALL prt_ctl(tab2d_1=area , clinfo1=' lim_itd_th  : cell area :')
+         CALL prt_ctl(tab2d_1=at_i , clinfo1=' lim_itd_th  : at_i      :')
+         CALL prt_ctl(tab2d_1=vt_i , clinfo1=' lim_itd_th  : vt_i      :')
+         CALL prt_ctl(tab2d_1=vt_s , clinfo1=' lim_itd_th  : vt_s      :')
+         DO jl = 1, jpl
+            CALL prt_ctl_info(' ')
+            CALL prt_ctl_info(' - Category : ', ivar1=jl)
+            CALL prt_ctl_info('   ~~~~~~~~~~')
+            CALL prt_ctl(tab2d_1=a_i   (:,:,jl)   , clinfo1= ' lim_itd_th  : a_i      : ')
+            CALL prt_ctl(tab2d_1=ht_i  (:,:,jl)   , clinfo1= ' lim_itd_th  : ht_i     : ')
+            CALL prt_ctl(tab2d_1=ht_s  (:,:,jl)   , clinfo1= ' lim_itd_th  : ht_s     : ')
+            CALL prt_ctl(tab2d_1=v_i   (:,:,jl)   , clinfo1= ' lim_itd_th  : v_i      : ')
+            CALL prt_ctl(tab2d_1=v_s   (:,:,jl)   , clinfo1= ' lim_itd_th  : v_s      : ')
+            CALL prt_ctl(tab2d_1=e_s   (:,:,1,jl) , clinfo1= ' lim_itd_th  : e_s      : ')
+            CALL prt_ctl(tab2d_1=t_su  (:,:,jl)   , clinfo1= ' lim_itd_th  : t_su     : ')
+            CALL prt_ctl(tab2d_1=t_s   (:,:,1,jl) , clinfo1= ' lim_itd_th  : t_snow   : ')
+            CALL prt_ctl(tab2d_1=sm_i  (:,:,jl)   , clinfo1= ' lim_itd_th  : sm_i     : ')
+            CALL prt_ctl(tab2d_1=smv_i (:,:,jl)   , clinfo1= ' lim_itd_th  : smv_i    : ')
+            DO ja = 1, nlay_i
+               CALL prt_ctl_info(' ')
+               CALL prt_ctl_info(' - Layer : ', ivar1=ja)
+               CALL prt_ctl_info('   ~~~~~~~')
+               CALL prt_ctl(tab2d_1=t_i(:,:,ja,jl) , clinfo1= ' lim_itd_th  : t_i      : ')
+               CALL prt_ctl(tab2d_1=e_i(:,:,ja,jl) , clinfo1= ' lim_itd_th  : e_i      : ')
+            END DO
+         END DO
+      ENDIF
+      
+      !- Recover Old values
+      a_i(:,:,:)         = old_a_i (:,:,:)
+      v_s(:,:,:)         = old_v_s (:,:,:)
+      v_i(:,:,:)         = old_v_i (:,:,:)
+      e_s(:,:,:,:)       = old_e_s (:,:,:,:)
+      e_i(:,:,:,:)       = old_e_i (:,:,:,:)
+
+      IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) &
+      smv_i(:,:,:)       = old_smv_i (:,:,:)
+
+
+      END SUBROUTINE lim_itd_th
+
+!!----------------------------------------------------------------------------------------------
+!!----------------------------------------------------------------------------------------------
+
+    SUBROUTINE lim_itd_th_rem(klbnd,kubnd,ntyp)
+        !!------------------------------------------------------------------
+        !!                ***  ROUTINE lim_itd_th_rem ***
+        !! ** Purpose :
+        !!        This routine computes the redistribution of ice thickness
+        !!        after thermodynamic growth of ice thickness
+        !!
+        !! ** Method  : Linear remapping 
+        !!
+        !! ** Arguments :
+        !!           klbnd, kubnd : Starting and ending category index on which the 
+        !!                         the computation is applied
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !!
+        !! ** External : 
+        !!
+        !! ** References : W.H. Lipscomb, JGR 2001
+        !!
+        !! ** History :
+        !!           largely inspired from CICE (c) W. H. Lipscomb and E.C. Hunke
+        !! 
+        !!           (01-2006) Martin Vancoppenolle, UCL-ASTR, translation from
+        !!                     CICE
+        !!           (06-2006) Adaptation to include salt, age and types
+        !!           (04-2007) Mass conservation checked
+        !!------------------------------------------------------------------
+        !! * Arguments
+
+       INTEGER , INTENT (IN) ::  &
+          klbnd ,  &  ! Start thickness category index point
+          kubnd ,  &  ! End point on which the  the computation is applied
+          ntyp        ! Number of the type used
+
+       !! * Local variables
+       INTEGER ::   ji,       &   ! spatial dummy loop index
+                    jj,       &   ! spatial dummy loop index
+                    jl,       &   ! ice category dummy loop index
+                    zji, zjj, &   ! dummy indices used when changing coordinates
+                    nd            ! used for thickness categories
+
+       INTEGER , DIMENSION(jpi,jpj,jpl-1) :: & 
+                    zdonor        ! donor category index
+  
+       REAL(wp)  ::           &   ! constant values
+          zeps      =  1.0e-10
+
+       REAL(wp)  ::           &  ! constant values for ice enthalpy
+          zindb     ,         &
+          zareamin  ,         &  ! minimum tolerated area in a thickness category
+          zwk1, zwk2,         &  ! all the following are dummy arguments
+          zx1, zx2, zx3,      &  !
+          zetamin   ,         &  ! minimum value of eta
+          zetamax   ,         &  ! maximum value of eta
+          zdh0      ,         &  ! 
+          zda0      ,         &  !
+          zdamax    ,         &  !
+          zhimin
+
+       REAL(wp), DIMENSION(jpi,jpj,jpl) :: &
+          zdhice           ,  &  ! ice thickness increment
+          g0               ,  &  ! coefficients for fitting the line of the ITD
+          g1               ,  &  ! coefficients for fitting the line of the ITD
+          hL               ,  &  ! left boundary for the ITD for each thickness
+          hR               ,  &  ! left boundary for the ITD for each thickness
+          zht_i_o          ,  &  ! old ice thickness
+          dummy_es
+
+       REAL(wp), DIMENSION(jpi,jpj,jpl-1) :: &
+          zdaice           ,  &  ! local increment of ice area 
+          zdvice                 ! local increment of ice volume
+
+       REAL(wp), DIMENSION(jpi,jpj,0:jpl) :: &
+          zhbnew                 ! new boundaries of ice categories
+
+       REAL(wp), DIMENSION(jpi,jpj) :: &
+          zhb0, zhb1             ! category boundaries for thinnes categories
+
+       REAL, DIMENSION(1:(jpi+1)*(jpj+1)) :: &
+          zvetamin, zvetamax     ! maximum values for etas
+ 
+       INTEGER, DIMENSION(1:(jpi+1)*(jpj+1)) :: &
+          nind_i      ,  &  ! compressed indices for i/j directions
+          nind_j
+
+       INTEGER :: &
+          nbrem             ! number of cells with ice to transfer
+
+       LOGICAL, DIMENSION(jpi,jpj) ::   &  !:
+          zremap_flag             ! compute remapping or not ????
+       
+       REAL(wp)  ::           &  ! constant values for ice enthalpy
+          zslope                 ! used to compute local thermodynamic "speeds"
+
+       REAL (wp), DIMENSION(jpi,jpj) :: &  ! 
+               vt_i_init, vt_i_final,   &  !  ice volume summed over categories
+               vt_s_init, vt_s_final,   &  !  snow volume summed over categories
+               et_i_init, et_i_final,   &  !  ice energy summed over categories
+               et_s_init, et_s_final       !  snow energy summed over categories
+
+       CHARACTER (len = 15) :: fieldid
+       
+!!-- End of declarations
+!!----------------------------------------------------------------------------------------------
+      zhimin = 0.1      !minimum ice thickness tolerated by the model
+      zareamin = zeps   !minimum area in thickness categories tolerated by the conceptors of the model
+
+!!----------------------------------------------------------------------------------------------
+!! 0) Conservation checkand 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)
+         dummy_es(:,:,:) = e_s(:,:,1,:)
+         CALL lim_column_sum (jpl, dummy_es(:,:,:) , et_s_init)
+      ENDIF
+ 
+!!----------------------------------------------------------------------------------------------
+!! 1) Compute thickness and changes in each ice category
+!!----------------------------------------------------------------------------------------------
+       IF (lwp) THEN
+       WRITE(numout,*)
+       WRITE(numout,*) 'lim_itd_th_rem  : Remapping the ice thickness distribution'
+       WRITE(numout,*) '~~~~~~~~~~~~~~~'
+       WRITE(numout,*) ' klbnd :       ', klbnd
+       WRITE(numout,*) ' kubnd :       ', kubnd
+       WRITE(numout,*) ' ntyp  :       ', ntyp 
+       ENDIF
+
+       zdhice(:,:,:) = 0.0
+       DO jl = klbnd, kubnd
+          DO jj = 1, jpj
+             DO ji = 1, jpi
+                zindb             = 1.0-MAX(0.0,SIGN(1.0,-a_i(ji,jj,jl)))     !0 if no ice and 1 if yes
+                ht_i(ji,jj,jl)    = v_i(ji,jj,jl) / MAX(a_i(ji,jj,jl),zeps) * zindb
+                zindb             = 1.0-MAX(0.0,SIGN(1.0,-old_a_i(ji,jj,jl))) !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),zeps) * zindb
+                IF (a_i(ji,jj,jl).gt.1e-6) THEN
+                   zdhice(ji,jj,jl) = ht_i(ji,jj,jl) - zht_i_o(ji,jj,jl) 
+                ENDIF
+             END DO
+          END DO
+       END DO
+
+!-----------------------------------------------------------------------------------------------
+!  2) Compute fractional ice area in each grid cell
+!-----------------------------------------------------------------------------------------------
+      at_i(:,:) = 0.0
+      DO jl = klbnd, kubnd
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               at_i(ji,jj) = at_i(ji,jj) + a_i(ji,jj,jl)
+            END DO
+         END DO
+      END DO
+
+!-----------------------------------------------------------------------------------------------
+!  3) Identify grid cells with ice
+!-----------------------------------------------------------------------------------------------
+      nbrem = 0
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF ( at_i(ji,jj) .gt. zareamin ) THEN
+               nbrem         = nbrem + 1
+               nind_i(nbrem) = ji
+               nind_j(nbrem) = jj
+               zremap_flag(ji,jj) = .true.
+            ELSE
+               zremap_flag(ji,jj) = .false.
+            ENDIF
+         END DO !ji
+      END DO !jj
+
+!-----------------------------------------------------------------------------------------------
+!  4) Compute new category boundaries
+!-----------------------------------------------------------------------------------------------
+      !- 4.1 Compute category boundaries
+      ! Tricky trick see limitd_me.F90
+      ! will be soon removed, CT
+      ! hi_max(kubnd) = 999.99
+      zhbnew(:,:,:) = 0.0
+
+      DO jl = klbnd, kubnd - 1
+         ! jl
+         DO ji = 1, nbrem
+            ! jl, ji
+            zji = nind_i(ji)
+            zjj = nind_j(ji)
+            !
+            IF ( ( zht_i_o(zji,zjj,jl)  .GT.zeps ) .AND. & 
+                 ( zht_i_o(zji,zjj,jl+1).GT.zeps ) ) THEN
+               !interpolate between adjacent category growth rates
+               zslope = ( zdhice(zji,zjj,jl+1)     - zdhice(zji,zjj,jl) ) / &
+                        ( zht_i_o   (zji,zjj,jl+1) - zht_i_o   (zji,zjj,jl) )
+               zhbnew(zji,zjj,jl) = hi_max(jl) + zdhice(zji,zjj,jl) + &
+                                    zslope * ( hi_max(jl) - zht_i_o(zji,zjj,jl) )
+            ELSEIF (zht_i_o(zji,zjj,jl).gt.zeps) THEN
+               zhbnew(zji,zjj,jl) = hi_max(jl) + zdhice(zji,zjj,jl)
+            ELSEIF (zht_i_o(zji,zjj,jl+1).gt.zeps) THEN
+               zhbnew(zji,zjj,jl) = hi_max(jl) + zdhice(zji,zjj,jl+1)
+            ELSE
+               zhbnew(zji,zjj,jl) = hi_max(jl)
+            ENDIF
+            ! jl, ji
+         END DO !ji
+         ! jl
+
+      !- 4.2 Check that each zhbnew lies between adjacent values of ice thickness
+         DO ji = 1, nbrem
+            ! jl, ji
+            zji = nind_i(ji)
+            zjj = nind_j(ji)
+            ! jl, ji
+            IF ( ( a_i(zji,zjj,jl) .GT.zeps) .AND. & 
+                 ( ht_i(zji,zjj,jl).GE. zhbnew(zji,zjj,jl) ) &
+               ) THEN
+               zremap_flag(zji,zjj) = .false.
+            ELSEIF ( ( a_i(zji,zjj,jl+1) .GT. zeps ) .AND. &
+                     ( ht_i(zji,zjj,jl+1).LE. zhbnew(zji,zjj,jl) ) &
+                   ) THEN
+               zremap_flag(zji,zjj) = .false.
+            ENDIF
+
+      !- 4.3 Check that each zhbnew does not exceed maximal values hi_max  
+            ! jl, ji
+            IF (zhbnew(zji,zjj,jl).gt.hi_max(jl+1)) THEN
+               zremap_flag(zji,zjj) = .false.
+            ENDIF
+            ! jl, ji
+            IF (zhbnew(zji,zjj,jl).lt.hi_max(jl-1)) THEN
+               zremap_flag(zji,zjj) = .false.
+            ENDIF
+            ! jl, ji
+         END DO !ji
+         ! ji
+      END DO !jl
+            
+!-----------------------------------------------------------------------------------------------
+!  5) Identify cells where ITD is to be remapped
+!-----------------------------------------------------------------------------------------------
+     nbrem = 0
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           IF ( zremap_flag(ji,jj) ) THEN
+              nbrem         = nbrem + 1
+              nind_i(nbrem) = ji
+              nind_j(nbrem) = jj
+           ENDIF
+        END DO !ji
+     END DO !jj
+
+!-----------------------------------------------------------------------------------------------
+!  6) Fill arrays with lowermost / uppermost boundaries of 'new' categories
+!-----------------------------------------------------------------------------------------------
+     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
+
+           zhbnew(ji,jj,klbnd-1) = 0.0
+           
+           IF ( a_i(ji,jj,kubnd) .GT. zeps ) THEN
+              zhbnew(ji,jj,kubnd) = 3.0*ht_i(ji,jj,kubnd) - 2.0*zhbnew(ji,jj,kubnd-1)
+           ELSE
+              zhbnew(ji,jj,kubnd) = hi_max(kubnd)
+           ENDIF
+
+           IF ( zhbnew(ji,jj,kubnd) .LT. hi_max(kubnd-1) ) &
+              zhbnew(ji,jj,kubnd) = hi_max(kubnd-1)
+
+        END DO !jj
+     END DO !jj
+
+!-----------------------------------------------------------------------------------------------
+!  7) Compute g(h) 
+!-----------------------------------------------------------------------------------------------
+     !- 7.1 g(h) for category 1 at start of time step
+     CALL lim_itd_fitline(klbnd, zhb0, zhb1, zht_i_o(:,:,klbnd), &
+                          g0(:,:,klbnd), g1(:,:,klbnd), hL(:,:,klbnd), &
+                          hR(:,:,klbnd), zremap_flag)
+
+     !- 7.2 Area lost due to melting of thin ice (first category,  klbnd)
+     DO ji = 1, nbrem
+        zji = nind_i(ji) 
+        zjj = nind_j(ji) 
+      
+        !ji
+        IF (a_i(zji,zjj,klbnd) .gt. zeps) THEN
+           zdh0 = zdhice(zji,zjj,klbnd) !decrease of ice thickness in the lower category
+           ! ji, a_i > zeps
+           IF (zdh0 .lt. 0.0) THEN !remove area from category 1
+              ! ji, a_i > zeps; zdh0 < 0
+              zdh0 = MIN(-zdh0,hi_max(klbnd))
+        
+              !Integrate g(1) from 0 to dh0 to estimate area melted
+              zetamax = MIN(zdh0,hR(zji,zjj,klbnd)) - hL(zji,zjj,klbnd)
+              IF (zetamax.gt.0.0) THEN
+                 zx1  = zetamax
+                 zx2  = 0.5 * zetamax*zetamax 
+                 zda0 = g1(zji,zjj,klbnd) * zx2 + g0(zji,zjj,klbnd) * zx1 !ice area removed
+              ! Constrain new thickness <= ht_i
+                 zdamax = a_i(zji,zjj,klbnd) * & 
+                          (1.0 - ht_i(zji,zjj,klbnd)/zht_i_o(zji,zjj,klbnd)) ! zdamax > 0
+              !ice area lost due to melting of thin ice
+                 zda0   = MIN(zda0, zdamax)
+
+              ! Remove area, conserving volume
+                 ht_i(zji,zjj,klbnd) = ht_i(zji,zjj,klbnd) & 
+                               * a_i(zji,zjj,klbnd) / ( a_i(zji,zjj,klbnd) - zda0 )
+                 a_i(zji,zjj,klbnd)  = a_i(zji,zjj,klbnd) - zda0
+                 v_i(zji,zjj,klbnd)  = a_i(zji,zjj,klbnd)*ht_i(zji,zjj,klbnd)
+              ENDIF     ! zetamax > 0
+           ! ji, a_i > zeps
+
+           ELSE ! if ice accretion
+              ! ji, a_i > zeps; zdh0 > 0
+              IF ( ntyp .EQ. 1 ) zhbnew(zji,zjj,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(zji,zjj,0) = 0 
+              ! in other types there is
+              ! no open water growth (F0 = 0)
+           ENDIF ! zdh0 
+
+           ! a_i > zeps
+        ENDIF ! a_i > zeps
+
+     END DO ! ji
+
+     !- 7.3 g(h) for each thickness category  
+     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)
+     END DO
+
+!-----------------------------------------------------------------------------------------------
+!  8) Compute area and volume to be shifted across each boundary
+!-----------------------------------------------------------------------------------------------
+
+     DO jl = klbnd, kubnd - 1
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              zdonor(ji,jj,jl) = 0
+              zdaice(ji,jj,jl) = 0.0
+              zdvice(ji,jj,jl) = 0.0
+           END DO
+        END DO
+
+        DO ji = 1, nbrem
+           zji = nind_i(ji)
+           zjj = nind_j(ji)
+           
+           IF (zhbnew(zji,zjj,jl) .gt. hi_max(jl)) THEN ! transfer from jl to jl+1
+
+              ! left and right integration limits in eta space
+              zvetamin(ji) = MAX(hi_max(jl), hL(zji,zjj,jl)) - hL(zji,zjj,jl)
+              zvetamax(ji) = MIN(zhbnew(zji,zjj,jl), hR(zji,zjj,jl)) - hL(zji,zjj,jl)
+              zdonor(zji,zjj,jl) = jl
+
+           ELSE  ! zhbnew(jl) <= hi_max(jl) ; transfer from jl+1 to jl
+
+              ! left and right integration limits in eta space
+              zvetamin(ji) = 0.0
+              zvetamax(ji) = MIN(hi_max(jl), hR(zji,zjj,jl+1)) - hL(zji,zjj,jl+1)
+              zdonor(zji,zjj,jl) = jl + 1
+
+           ENDIF  ! zhbnew(jl) > hi_max(jl)
+
+           zetamax = MAX(zvetamax(ji), zvetamin(ji)) ! no transfer if etamax < etamin
+           zetamin = zvetamin(ji)
+
+           zx1  = zetamax - zetamin
+           zwk1 = zetamin*zetamin
+           zwk2 = zetamax*zetamax
+           zx2  = 0.5 * (zwk2 - zwk1)
+           zwk1 = zwk1 * zetamin
+           zwk2 = zwk2 * zetamax
+           zx3  = 1.0/3.0 * (zwk2 - zwk1)
+           nd   = zdonor(zji,zjj,jl)
+           zdaice(zji,zjj,jl) = g1(zji,zjj,nd)*zx2 + g0(zji,zjj,nd)*zx1
+           zdvice(zji,zjj,jl) = g1(zji,zjj,nd)*zx3 + g0(zji,zjj,nd)*zx2 + &
+                              zdaice(zji,zjj,jl)*hL(zji,zjj,nd)
+
+        END DO ! ji
+     END DO ! jl klbnd -> kubnd - 1
+
+!!----------------------------------------------------------------------------------------------
+!! 9) Shift ice between categories
+!!----------------------------------------------------------------------------------------------
+     CALL lim_itd_shiftice ( klbnd, kubnd, zdonor, zdaice, zdvice )
+
+!!----------------------------------------------------------------------------------------------
+!! 10) Make sure ht_i >= minimum ice thickness hi_min
+!!----------------------------------------------------------------------------------------------
+
+    DO ji = 1, nbrem
+        zji = nind_i(ji)
+        zjj = nind_j(ji)
+        IF ( ( zhimin .GT. 0.0 ) .AND. & 
+             ( ( a_i(zji,zjj,1) .GT. zeps ) .AND. ( ht_i(zji,zjj,1) .LT. zhimin ) ) &
+           ) THEN
+           a_i(zji,zjj,1)  = a_i(zji,zjj,1) * ht_i(zji,zjj,1) / zhimin 
+           ht_i(zji,zjj,1) = zhimin
+           v_i(zji,zjj,1)  = a_i(zji,zjj,1)*ht_i(zji,zjj,1)
+        ENDIF
+    END DO !ji
+
+!!----------------------------------------------------------------------------------------------
+!! 11) Conservation check
+!!----------------------------------------------------------------------------------------------
+      IF ( con_i ) THEN
+         CALL lim_column_sum (jpl,   v_i, vt_i_final)
+         fieldid = ' v_i : limitd_th '
+         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 : limitd_th '
+         CALL lim_cons_check (et_i_init, et_i_final, 1.0e-3, fieldid) 
+
+         CALL lim_column_sum (jpl,   v_s, vt_s_final)
+         fieldid = ' v_s : limitd_th '
+         CALL lim_cons_check (vt_s_init, vt_s_final, 1.0e-6, fieldid) 
+
+         dummy_es(:,:,:) = e_s(:,:,1,:)
+         CALL lim_column_sum (jpl, dummy_es(:,:,:) , et_s_final)
+         fieldid = ' e_s : limitd_th '
+         CALL lim_cons_check (et_s_init, et_s_final, 1.0e-3, fieldid) 
+      ENDIF
+
+    END SUBROUTINE lim_itd_th_rem
+
+!!----------------------------------------------------------------------------------------------
+!!----------------------------------------------------------------------------------------------
+
+    SUBROUTINE lim_itd_fitline(num_cat, HbL, Hbr, hice, g0, g1, hL, hR, zremap_flag )
+
+        !!------------------------------------------------------------------
+        !!                ***  ROUTINE lim_itd_fitline ***
+        !! ** Purpose :
+        !! fit g(h) with a line using area, volume constraints
+        !!
+        !! ** Method  :
+        !! Fit g(h) with a line, satisfying area and volume constraints.
+        !! To reduce roundoff errors caused by large values of g0 and g1,
+        !! we actually compute g(eta), where eta = h - hL, and hL is the
+        !! left boundary.
+        !!
+        !! ** Arguments :
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !!
+        !! ** External : 
+        !!
+        !! ** References :
+        !!
+        !! ** History :
+        !! authors: William H. Lipscomb, LANL, Elizabeth C. Hunke, LANL
+        !!          (01-2006) Martin Vancoppenolle 
+        !!
+        !!------------------------------------------------------------------
+        !! * Arguments
+
+      INTEGER, INTENT(in) :: num_cat      ! category index
+
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN)   ::   &  !:
+         HbL, HbR        ! left and right category boundaries
+
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(IN)   ::   &  !:
+         hice            ! ice thickness
+
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(OUT)  ::   &  !:
+         g0, g1      , & ! coefficients in linear equation for g(eta)
+         hL          , & ! min value of range over which g(h) > 0
+         hR              ! max value of range over which g(h) > 0
+
+      LOGICAL, DIMENSION(jpi,jpj), INTENT(IN)    ::   &  !:
+         zremap_flag
+
+      INTEGER :: &              
+         ji,jj           ! horizontal indices
+
+      REAL(wp) :: &           
+         zh13        , & ! HbL + 1/3 * (HbR - HbL)
+         zh23        , & ! HbL + 2/3 * (HbR - HbL)
+         zdhr        , & ! 1 / (hR - hL)
+         zwk1, zwk2  , & ! temporary variables
+         zacrith         ! critical minimum concentration in an ice category
+
+      REAL(wp)  ::           &  ! constant values
+          zeps      =  1.0e-10
+
+      zacrith       = 1.0e-6
+!!-- End of declarations
+!!----------------------------------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+
+            IF ( zremap_flag(ji,jj) .AND. a_i(ji,jj,num_cat) .gt. zacrith &
+                 .AND. hice(ji,jj) .GT. 0.0 ) THEN
+  
+            ! Initialize hL and hR
+
+               hL(ji,jj) = HbL(ji,jj)
+               hR(ji,jj) = HbR(ji,jj)
+
+            ! Change hL or hR if hice falls outside central third of range
+
+               zh13 = 1.0/3.0 * (2.0*hL(ji,jj) + hR(ji,jj))
+               zh23 = 1.0/3.0 * (hL(ji,jj) + 2.0*hR(ji,jj))
+
+               IF (hice(ji,jj) < zh13) THEN
+                  hR(ji,jj) = 3.0*hice(ji,jj) - 2.0*hL(ji,jj)
+               ELSEIF (hice(ji,jj) > zh23) THEN
+                  hL(ji,jj) = 3.0*hice(ji,jj) - 2.0*hR(ji,jj)
+               ENDIF
+
+            ! Compute coefficients of g(eta) = g0 + g1*eta
+                  
+               zdhr = 1.0 / (hR(ji,jj) - hL(ji,jj))
+               zwk1 = 6.0 * a_i(ji,jj,num_cat) * zdhr
+               zwk2 = (hice(ji,jj) - hL(ji,jj)) * zdhr
+               g0(ji,jj) = zwk1 * (2.0/3.0 - zwk2)
+               g1(ji,jj) = 2.0*zdhr * zwk1 * (zwk2 - 0.5)
+
+            ELSE                   ! remap_flag = .false. or a_i < zeps 
+
+               hL(ji,jj) = 0.0
+               hR(ji,jj) = 0.0
+               g0(ji,jj) = 0.0
+               g1(ji,jj) = 0.0
+
+            ENDIF                  ! a_i > zeps
+
+         END DO !ji
+      END DO ! jj
+
+    END SUBROUTINE lim_itd_fitline
+
+!----------------------------------------------------------------------------------------------
+!----------------------------------------------------------------------------------------------
+
+    SUBROUTINE lim_itd_shiftice (klbnd, kubnd, zdonor, zdaice, zdvice)
+        !!------------------------------------------------------------------
+        !!                ***  ROUTINE lim_itd_shiftice ***
+        !! ** Purpose : shift ice across category boundaries, conserving everything
+        !!              ( area, volume, energy, age*vol, and mass of salt )
+        !!
+        !! ** Method  :
+        !!
+        !! ** Arguments :
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !!
+        !! ** External : 
+        !!
+        !! ** References :
+        !!
+        !! ** History :
+        !! authors: William H. Lipscomb, LANL, Elizabeth C. Hunke, LANL
+        !!          (01-2006) Martin Vancoppenolle 
+        !!
+        !!------------------------------------------------------------------
+        !! * Arguments
+
+      INTEGER , INTENT (IN) ::  &
+          klbnd ,  &  ! Start thickness category index point
+          kubnd       ! End point on which the  the computation is applied
+
+      INTEGER , DIMENSION(jpi,jpj,jpl-1), INTENT(IN) :: & 
+         zdonor             ! donor category index
+
+      REAL(wp), DIMENSION(jpi,jpj,jpl-1), INTENT(INOUT) :: & 
+         zdaice     ,  &   ! ice area transferred across boundary
+         zdvice            ! ice volume transferred across boundary
+
+      INTEGER :: &
+         ji,jj,jl,      &  ! horizontal indices, thickness category index
+         jl2,           &  ! receiver category
+         jl1,           &  ! donor category
+         jk,            &  ! ice layer index
+         zji, zjj          ! indices when changing from 2D-1D is done
+
+      REAL(wp), DIMENSION(jpi,jpj,jpl) :: &
+         zaTsfn
+
+      REAL(wp), DIMENSION(jpi,jpj) :: &
+         zworka            ! temporary array used here
+
+      REAL(wp) :: &          
+         zdvsnow     ,  &  ! snow volume transferred
+         zdesnow     ,  &  ! snow energy transferred
+         zdeice      ,  &  ! ice energy transferred
+         zdsm_vice      ,  &  ! ice salinity times volume transferred
+         zdo_aice      ,  &  ! ice age times volume transferred
+         zdaTsf      ,  &  ! aicen*Tsfcn transferred
+         zindsn      ,  &  ! snow or not
+         zindb             ! ice or not
+
+      INTEGER, DIMENSION(1:(jpi+1)*(jpj+1)) :: &
+         nind_i      ,  &  ! compressed indices for i/j directions
+         nind_j
+
+      INTEGER :: &
+         nbrem             ! number of cells with ice to transfer
+
+      LOGICAL :: &
+        zdaice_negative       , & ! true if daice < -puny
+        zdvice_negative       , & ! true if dvice < -puny
+        zdaice_greater_aicen  , & ! true if daice > aicen
+        zdvice_greater_vicen      ! true if dvice > vicen
+
+       REAL(wp)  ::           &  ! constant values
+          zeps      =  1.0e-10
+
+!!-- End of declarations
+
+!----------------------------------------------------------------------------------------------
+! 1) Define a variable equal to a_i*T_su
+!----------------------------------------------------------------------------------------------
+
+      DO jl = klbnd, kubnd
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zaTsfn(ji,jj,jl) = a_i(ji,jj,jl)*t_su(ji,jj,jl)
+            END DO ! ji
+         END DO ! jj
+      END DO ! jl
+
+!----------------------------------------------------------------------------------------------
+! 2) Check for daice or dvice out of range, allowing for roundoff error
+!----------------------------------------------------------------------------------------------
+      ! Note: zdaice < 0 or zdvice < 0 usually happens when category jl
+      ! has a small area, with h(n) very close to a boundary.  Then
+      ! the coefficients of g(h) are large, and the computed daice and
+      ! dvice can be in error. If this happens, it is best to transfer
+      ! either the entire category or nothing at all, depending on which
+      ! side of the boundary hice(n) lies.
+      !-----------------------------------------------------------------
+      DO jl = klbnd, kubnd-1
+
+         zdaice_negative = .false.
+         zdvice_negative = .false.
+         zdaice_greater_aicen = .false.
+         zdvice_greater_vicen = .false.
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+            IF (zdonor(ji,jj,jl) .GT. 0) THEN
+               jl1 = zdonor(ji,jj,jl)
+
+               IF (zdaice(ji,jj,jl) .LT. 0.0) THEN
+                  IF (zdaice(ji,jj,jl) .GT. -zeps) THEN
+                     IF ( ( jl1.EQ.jl   .AND. ht_i(ji,jj,jl1) .GT. hi_max(jl) )           &
+                                                .OR.                                      &
+                          ( jl1.EQ.jl+1 .AND. ht_i(ji,jj,jl1) .LE. hi_max(jl) )           &  
+                        ) THEN                                                             
+                        zdaice(ji,jj,jl) = a_i(ji,jj,jl1)  ! shift entire category
+                        zdvice(ji,jj,jl) = v_i(ji,jj,jl1)
+                     ELSE
+                        zdaice(ji,jj,jl) = 0.0 ! shift no ice
+                        zdvice(ji,jj,jl) = 0.0
+                     ENDIF
+                  ELSE
+                     zdaice_negative = .true.
+                  ENDIF
+               ENDIF
+
+               IF (zdvice(ji,jj,jl) .LT. 0.0) THEN
+                  IF (zdvice(ji,jj,jl) .GT. -zeps ) THEN
+                     IF ( ( jl1.EQ.jl .AND. ht_i(ji,jj,jl1).GT.hi_max(jl) )     &
+                                       .OR.                                     &
+                          ( jl1.EQ.jl+1 .AND. ht_i(ji,jj,jl1) .LE. hi_max(jl) ) &
+                        ) THEN
+                        zdaice(ji,jj,jl) = a_i(ji,jj,jl1) ! shift entire category
+                        zdvice(ji,jj,jl) = v_i(ji,jj,jl1) 
+                     ELSE
+                        zdaice(ji,jj,jl) = 0.0    ! shift no ice
+                        zdvice(ji,jj,jl) = 0.0
+                     ENDIF
+                  ELSE
+                     zdvice_negative = .true.
+                  ENDIF
+               ENDIF
+
+            ! If daice is close to aicen, set daice = aicen.
+               IF (zdaice(ji,jj,jl) .GT. a_i(ji,jj,jl1) - zeps ) THEN
+                  IF (zdaice(ji,jj,jl) .LT. a_i(ji,jj,jl1)+zeps) THEN
+                     zdaice(ji,jj,jl) = a_i(ji,jj,jl1)
+                     zdvice(ji,jj,jl) = v_i(ji,jj,jl1) 
+                  ELSE
+                     zdaice_greater_aicen = .true.
+                  ENDIF
+               ENDIF
+
+               IF (zdvice(ji,jj,jl) .GT. v_i(ji,jj,jl1)-zeps) THEN
+                  IF (zdvice(ji,jj,jl) .LT. v_i(ji,jj,jl1)+zeps) THEN
+                     zdaice(ji,jj,jl) = a_i(ji,jj,jl1)
+                     zdvice(ji,jj,jl) = v_i(ji,jj,jl1) 
+                  ELSE
+                     zdvice_greater_vicen = .true.
+                  ENDIF
+               ENDIF
+
+            ENDIF               ! donor > 0
+         END DO                   ! i
+         END DO                 ! j
+
+      END DO !jl
+
+!-------------------------------------------------------------------------------
+! 3) Transfer volume and energy between categories
+!-------------------------------------------------------------------------------
+
+      DO jl = klbnd, kubnd - 1
+         nbrem = 0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF (zdaice(ji,jj,jl) .GT. 0.0 ) THEN ! daice(n) can be < puny
+                  nbrem = nbrem + 1
+                  nind_i(nbrem) = ji
+                  nind_j(nbrem) = jj
+               ENDIF ! tmask
+            END DO
+         END DO
+
+         DO ji = 1, nbrem 
+            zji = nind_i(ji)
+            zjj = nind_j(ji)
+
+            jl1 = zdonor(zji,zjj,jl)
+            zindb             = MAX( 0.0 , SIGN( 1.0 , v_i(zji,zjj,jl1) - zeps ) )
+            zworka(zji,zjj)   = zdvice(zji,zjj,jl) / MAX(v_i(zji,zjj,jl1),zeps) * zindb
+            IF (jl1 .eq. jl) THEN
+               jl2 = jl1+1
+            ELSE                ! n1 = n+1
+               jl2 = jl 
+            ENDIF
+
+            !--------------
+            ! Ice areas
+            !--------------
+
+            a_i(zji,zjj,jl1) = a_i(zji,zjj,jl1) - zdaice(zji,zjj,jl)
+            a_i(zji,zjj,jl2) = a_i(zji,zjj,jl2) + zdaice(zji,zjj,jl)
+
+            !--------------
+            ! Ice volumes
+            !--------------
+
+            v_i(zji,zjj,jl1) = v_i(zji,zjj,jl1) - zdvice(zji,zjj,jl) 
+            v_i(zji,zjj,jl2) = v_i(zji,zjj,jl2) + zdvice(zji,zjj,jl)
+
+            !--------------
+            ! Snow volumes
+            !--------------
+
+            zdvsnow          = v_s(zji,zjj,jl1) * zworka(zji,zjj)
+            v_s(zji,zjj,jl1) = v_s(zji,zjj,jl1) - zdvsnow
+            v_s(zji,zjj,jl2) = v_s(zji,zjj,jl2) + zdvsnow 
+
+            !--------------------
+            ! Snow heat content  
+            !--------------------
+
+            zdesnow              = e_s(zji,zjj,1,jl1) * zworka(zji,zjj)
+            e_s(zji,zjj,1,jl1)   = e_s(zji,zjj,1,jl1) - zdesnow
+            e_s(zji,zjj,1,jl2)   = e_s(zji,zjj,1,jl2) + zdesnow
+
+            !--------------
+            ! Ice age 
+            !--------------
+
+            zdo_aice             = oa_i(zji,zjj,jl1) * zdaice(zji,zjj,jl)
+            oa_i(zji,zjj,jl1)    = oa_i(zji,zjj,jl1) - zdo_aice
+            oa_i(zji,zjj,jl2)    = oa_i(zji,zjj,jl2) + zdo_aice
+
+            !--------------
+            ! Ice salinity
+            !--------------
+
+            zdsm_vice            = smv_i(zji,zjj,jl1) * zworka(zji,zjj)
+            smv_i(zji,zjj,jl1)   = smv_i(zji,zjj,jl1) - zdsm_vice
+            smv_i(zji,zjj,jl2)   = smv_i(zji,zjj,jl2) + zdsm_vice
+
+            !---------------------
+            ! Surface temperature
+            !---------------------
+
+            zdaTsf               = t_su(zji,zjj,jl1) * zdaice(zji,zjj,jl)
+            zaTsfn(zji,zjj,jl1)  = zaTsfn(zji,zjj,jl1) - zdaTsf
+            zaTsfn(zji,zjj,jl2)  = zaTsfn(zji,zjj,jl2) + zdaTsf 
+
+         END DO                 ! ji
+
+         !------------------
+         ! Ice heat content
+         !------------------
+
+         DO jk = 1, nlay_i
+!CDIR NODEP
+            DO ji = 1, nbrem
+               zji = nind_i(ji)
+               zjj = nind_j(ji)
+
+               jl1 = zdonor(zji,zjj,jl)
+               IF (jl1 .EQ. jl) THEN
+                  jl2 = jl+1
+               ELSE             ! n1 = n+1
+                  jl2 = jl 
+               ENDIF
+
+               zdeice = e_i(zji,zjj,jk,jl1) * zworka(zji,zjj)
+               e_i(zji,zjj,jk,jl1) =  e_i(zji,zjj,jk,jl1) - zdeice
+               e_i(zji,zjj,jk,jl2) =  e_i(zji,zjj,jk,jl2) + zdeice 
+            END DO              ! ji
+         END DO                 ! jk
+
+      END DO                   ! boundaries, 1 to ncat-1
+
+      !-----------------------------------------------------------------
+      ! Update ice thickness and temperature
+      !-----------------------------------------------------------------
+
+      DO jl = klbnd, kubnd
+         DO jj = 1, jpj
+         DO ji = 1, jpi 
+            IF ( a_i(ji,jj,jl) .GT. zeps ) THEN 
+               ht_i(ji,jj,jl)  =  v_i(ji,jj,jl) / a_i(ji,jj,jl) 
+               t_su(ji,jj,jl)  =  zaTsfn(ji,jj,jl) / a_i(ji,jj,jl) 
+               zindsn          =  1.0 - MAX(0.0,SIGN(1.0,-v_s(ji,jj,jl))) !0 if no ice and 1 if yes
+            ELSE
+               ht_i(ji,jj,jl)  = 0.0
+               t_su(ji,jj,jl)  = rtt
+            ENDIF
+         END DO                 ! ji
+         END DO                 ! jj
+      END DO                    ! jl
+
+    END SUBROUTINE lim_itd_shiftice
+
+!----------------------------------------------------------------------------------------
+!----------------------------------------------------------------------------------------
+
+    SUBROUTINE lim_itd_th_reb(klbnd, kubnd, ntyp)
+        !!------------------------------------------------------------------
+        !!                ***  ROUTINE lim_itd_th_reb ***
+        !! ** Purpose : rebin - rebins thicknesses into defined categories
+        !!
+        !! ** Method  :
+        !!
+        !! ** Arguments :
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !!
+        !! ** External : 
+        !!
+        !! ** References :
+        !!
+        !! ** History : (2005) Translation from CICE
+        !!              (2006) Adaptation to include salt, age and types
+        !!              (2007) Mass conservation checked
+        !!
+        !! authors: William H. Lipscomb, LANL, Elizabeth C. Hunke, LANL
+        !!          (01-2006) Martin Vancoppenolle (adaptation)
+        !!
+        !!------------------------------------------------------------------
+        !! * Arguments
+      INTEGER , INTENT (in) ::  &
+          klbnd ,  &  ! Start thickness category index point
+          kubnd ,  &  ! End point on which the  the computation is applied
+          ntyp        ! number of the ice type involved in the rebinning process
+
+      INTEGER :: &
+         ji,jj,          &  ! horizontal indices
+         jl                 ! category index
+
+      INTEGER ::   &  !:
+         zshiftflag          ! = .true. if ice must be shifted
+
+      INTEGER, DIMENSION(jpi,jpj,jpl) :: &
+         zdonor             ! donor category index
+
+      REAL(wp), DIMENSION(jpi, jpj, jpl) :: &
+         zdaice         , & ! ice area transferred
+         zdvice             ! ice volume transferred
+
+      REAL(wp)  ::           &  ! constant values
+         zeps      =  1.0e-10, &
+         epsi10    =  1.0e-10
+
+      REAL (wp), DIMENSION(jpi,jpj) :: &  ! 
+         vt_i_init, vt_i_final,   &  !  ice volume summed over categories
+         vt_s_init, vt_s_final       !  snow volume summed over categories
+
+       CHARACTER (len = 15) :: fieldid
+
+!!-- End of declarations
+!------------------------------------------------------------------------------
+
+!     ! conservation check
+      IF ( con_i ) THEN
+         CALL lim_column_sum (jpl,   v_i, vt_i_init)
+         CALL lim_column_sum (jpl,   v_s, vt_s_init)
+      ENDIF
+
+!
+!------------------------------------------------------------------------------
+! 1) Compute ice thickness.
+!------------------------------------------------------------------------------
+      DO jl = klbnd, kubnd
+         DO jj = 1, jpj
+         DO ji = 1, jpi 
+            IF (a_i(ji,jj,jl) .GT. zeps) THEN 
+               ht_i(ji,jj,jl) = v_i(ji,jj,jl) / a_i(ji,jj,jl)
+            ELSE
+               ht_i(ji,jj,jl) = 0.0
+            ENDIF
+         END DO                 ! i
+         END DO                 ! j
+      END DO                    ! n
+
+!------------------------------------------------------------------------------
+! 2) Make sure thickness of cat klbnd is at least hi_max_typ(klbnd)
+!------------------------------------------------------------------------------
+      DO jj = 1, jpj 
+      DO ji = 1, jpi 
+
+         IF (a_i(ji,jj,klbnd) > zeps) THEN
+            IF (ht_i(ji,jj,klbnd) .LE. hi_max_typ(0,ntyp) .AND. hi_max_typ(0,ntyp) .GT. 0.0 ) 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)
+            ENDIF
+         ENDIF
+      END DO                    ! i
+      END DO                    ! j
+
+!------------------------------------------------------------------------------
+! 3) If a category thickness is not in bounds, shift the
+! entire area, volume, and energy to the neighboring category
+!------------------------------------------------------------------------------
+      !-------------------------
+      ! Initialize shift arrays
+      !-------------------------
+
+      DO jl = klbnd, kubnd
+         DO jj = 1, jpj 
+         DO ji = 1, jpi
+            zdonor(ji,jj,jl) = 0
+            zdaice(ji,jj,jl) = 0.0
+            zdvice(ji,jj,jl) = 0.0
+         END DO
+         END DO
+      END DO
+
+      !-------------------------
+      ! Move thin categories up
+      !-------------------------
+
+      DO jl = klbnd, kubnd - 1  ! loop over category boundaries
+
+      !---------------------------------------
+      ! identify thicknesses that are too big
+      !---------------------------------------
+         zshiftflag = 0
+
+         DO jj = 1, jpj 
+            DO ji = 1, jpi 
+               IF (a_i(ji,jj,jl) .GT. zeps .AND. ht_i(ji,jj,jl) .GT. hi_max(jl) ) THEN 
+                  zshiftflag        = 1
+                  zdonor(ji,jj,jl)  = jl 
+                  zdaice(ji,jj,jl)  = a_i(ji,jj,jl)
+                  zdvice(ji,jj,jl)  = v_i(ji,jj,jl)
+               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
+      !------------------------
+            DO jj = 1, jpj
+            DO ji = 1, jpi
+               zdonor(ji,jj,jl) = 0
+               zdaice(ji,jj,jl) = 0.0
+               zdvice(ji,jj,jl) = 0.0
+            END DO
+            END DO
+
+         ENDIF                  ! zshiftflag
+
+      END DO                    ! jl
+
+      !----------------------------
+      ! Move thick categories down
+      !----------------------------
+
+      DO jl = kubnd - 1, 1, -1       ! loop over category boundaries
+
+      !-----------------------------------------
+      ! Identify thicknesses that are too small
+      !-----------------------------------------
+         zshiftflag = 0
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF (a_i(ji,jj,jl+1) .GT. zeps .AND. &
+                  ht_i(ji,jj,jl+1) .LE. 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
+      !------------------------
+            DO jj = 1, jpj 
+            DO ji = 1, jpi 
+               zdonor(ji,jj,jl)  = 0
+               zdaice(ji,jj,jl)  = 0.0
+               zdvice(ji,jj,jl)  = 0.0
+            END DO
+            END DO
+
+         ENDIF                  ! zshiftflag
+
+      END DO                    ! jl
+
+!------------------------------------------------------------------------------
+! 4) Conservation check
+!------------------------------------------------------------------------------
+
+    IF ( con_i ) THEN
+       CALL lim_column_sum (jpl,   v_i, vt_i_final)
+       fieldid = ' v_i : limitd_reb '
+       CALL lim_cons_check (vt_i_init, vt_i_final, 1.0e-6, fieldid) 
+
+       CALL lim_column_sum (jpl,   v_s, vt_s_final)
+       fieldid = ' v_s : limitd_reb '
+       CALL lim_cons_check (vt_s_init, vt_s_final, 1.0e-6, fieldid) 
+    ENDIF
+
+    END SUBROUTINE lim_itd_th_reb
+
+#else
+   !!======================================================================
+   !!                       ***  MODULE limitd_th    ***
+   !!                              no sea ice model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE lim_itd_th           ! Empty routines
+   END SUBROUTINE lim_itd_th
+   SUBROUTINE lim_itd_th_ini
+   END SUBROUTINE lim_itd_th_ini
+   SUBROUTINE lim_itd_th_rem
+   END SUBROUTINE lim_itd_th_rem
+   SUBROUTINE lim_itd_fitline
+   END SUBROUTINE lim_itd_fitline
+   SUBROUTINE lim_itd_shiftice
+   END SUBROUTINE lim_itd_shiftice
+   SUBROUTINE lim_itd_th_reb
+   END SUBROUTINE lim_itd_th_reb
+#endif
+ END MODULE limitd_th
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limmsh.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limmsh.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limmsh.F90	(revision 884)
@@ -0,0 +1,252 @@
+MODULE limmsh
+   !!======================================================================
+   !!                     ***  MODULE  limmsh  ***
+   !! LIM ice model :   definition of the ice mesh parameters
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_msh   : definition of the ice mesh
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE phycst
+   USE dom_oce
+   USE dom_ice
+   USE lbclnk
+   USE in_out_manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC lim_msh      ! routine called by ice_ini.F90
+
+   !!----------------------------------------------------------------------
+   !!   LIM 3.0,  UCL-ASTR-LOCEAN-IPSL (2008) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limmsh.F90,v 1.5 2005/03/27 18:34:42 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_msh
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_msh  ***
+      !!              
+      !! ** Purpose : Definition of the charact. of the numerical grid
+      !!       
+      !! ** Action  : - Initialisation of some variables
+      !!              - Definition of some constants linked with the grid
+      !!              - Definition of the metric coef. for the sea/ice
+      !!              - Initialization of the ice masks (tmsk, umsk)
+      !! 
+      !! ** Refer.  : Deleersnijder et al. Ocean Modelling 100, 7-10 
+      !!
+      !! ** History :
+      !!         original    : 01-04 (LIM)
+      !!         addition    : 02-08 (C. Ethe, G. Madec)
+      !!--------------------------------------------------------------------- 
+      !! * Local variables
+      INTEGER :: ji, jj      ! dummy loop indices
+
+      REAL(wp), DIMENSION(jpi,jpj) ::  &
+         zd2d1 , zd1d2       ! Derivative of zh2 (resp. zh1) in the x direction
+         !                   ! (resp. y direction) (defined at the center)
+      REAL(wp) ::         &
+         zh1p  , zh2p   , &  ! Idem zh1, zh2 for the bottom left corner of the grid
+         zd2d1p, zd1d2p , &  ! Idem zd2d1, zd1d2 for the bottom left corner of the grid
+         zusden, zusden2     ! temporary scalars
+      !!---------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_msh : LIM sea-ice model, mesh initialization'
+         WRITE(numout,*) '~~~~~~~'
+      ENDIF
+      
+      !----------------------------------------------------------                          
+      !    Initialization of local and some global (common) variables 
+      !------------------------------------------------------------------ 
+      
+      njeq   = INT( jpj / 2 )   !i bug mpp potentiel
+      njeqm1 = njeq - 1 
+
+      fcor(:,:) = 2. * omega * SIN( gphit(:,:) * rad )   !  coriolis factor
+ 
+      IF( fcor(1,1) * fcor(1,nlcj) < 0.e0 ) THEN   ! local domain include both hemisphere
+         l_jeq = .TRUE.
+         njeq  = 1
+         DO WHILE ( njeq <= jpj .AND. fcor(1,njeq) < 0.e0 )
+            njeq = njeq + 1
+         END DO
+         IF(lwp ) WRITE(numout,*) '          the equator is inside the domain at about njeq = ', njeq
+      ELSEIF( fcor(1,1) < 0.e0 ) THEN
+         l_jeq = .FALSE.
+         njeq = jpj
+         IF(lwp ) WRITE(numout,*) '          the model domain is entirely in the southern hemisphere: njeq = ', njeq
+      ELSE
+         l_jeq = .FALSE.
+         njeq = 2
+         IF(lwp ) WRITE(numout,*) '          the model domain is entirely in the northern hemisphere: njeq = ', njeq
+      ENDIF
+
+      njeqm1 = njeq - 1
+
+
+      !   For each grid, definition of geometric tables 
+      !------------------------------------------------------------------
+      
+      !-------------------
+      ! Conventions :    !
+      !-------------------
+      !  indices 1 \ 2 <-> localisation in the 2 direction x \ y
+      !  3rd indice <-> localisation on the mesh :
+      !  0 = Centre ;  1 = corner W x(i-1/2) ; 2 = corner S y(j-1/2) ;
+      !  3 = corner SW x(i-1/2),y(j-1/2)
+      !-------------------
+!!ibug ???
+      akappa(:,:,:,:) = 0.e0
+      wght(:,:,:,:) = 0.e0
+      alambd(:,:,:,:,:,:) = 0.e0
+      tmu(:,:) = 0.e0
+      tmv(:,:) = 0.0e0 ! CGrid EVP
+!!i
+      ! metric coefficients for sea ice dynamic
+      !----------------------------------------
+      !                                                       ! akappa
+      DO jj = 2, jpj
+         zd1d2(:,jj) = e1v(:,jj) - e1v(:,jj-1)
+      END DO
+      CALL lbc_lnk( zd1d2, 'T', -1. )
+
+      DO ji = 2, jpi
+         zd2d1(ji,:) = e2u(ji,:) - e2u(ji-1,:)
+      END DO
+      CALL lbc_lnk( zd2d1, 'T', -1. )
+
+      akappa(:,:,1,1) =        1.0 / ( 2.0 * e1t(:,:) )
+      akappa(:,:,1,2) = zd1d2(:,:) / ( 4.0 * e1t(:,:) * e2t(:,:) )
+      akappa(:,:,2,1) = zd2d1(:,:) / ( 4.0 * e1t(:,:) * e2t(:,:) )
+      akappa(:,:,2,2) =        1.0 / ( 2.0 * e2t(:,:) )
+      
+      !                                                      ! weights (wght)
+      DO jj = 2, jpj
+         DO ji = 2, jpi
+            zusden = 1. / (  ( e1t(ji,jj) + e1t(ji-1,jj  ) )   &
+               &           * ( e2t(ji,jj) + e2t(ji  ,jj-1) ) )
+            wght(ji,jj,1,1) = zusden * e1t(ji  ,jj) * e2t(ji,jj  )
+            wght(ji,jj,1,2) = zusden * e1t(ji  ,jj) * e2t(ji,jj-1)
+            wght(ji,jj,2,1) = zusden * e1t(ji-1,jj) * e2t(ji,jj  )
+            wght(ji,jj,2,2) = zusden * e1t(ji-1,jj) * e2t(ji,jj-1)
+         END DO
+      END DO
+      CALL lbc_lnk( wght(:,:,1,1), 'I', 1. )      ! CAUTION: even with the lbc_lnk at ice U-V-point
+      CALL lbc_lnk( wght(:,:,1,2), 'I', 1. )      ! the value of wght at jpj is wrong
+      CALL lbc_lnk( wght(:,:,2,1), 'I', 1. )      ! but it is never used
+      CALL lbc_lnk( wght(:,:,2,2), 'I', 1. )
+    
+      ! Coefficients for divergence of the stress tensor
+      !-------------------------------------------------
+
+      DO jj = 2, jpj
+         DO ji = 2, jpi
+            zh1p  =  e1t(ji  ,jj  ) * wght(ji,jj,2,2)   &
+               &   + e1t(ji-1,jj  ) * wght(ji,jj,1,2)   &
+               &   + e1t(ji  ,jj-1) * wght(ji,jj,2,1)   &
+               &   + e1t(ji-1,jj-1) * wght(ji,jj,1,1)
+
+            zh2p  =  e2t(ji  ,jj  ) * wght(ji,jj,2,2)   &
+               &   + e2t(ji-1,jj  ) * wght(ji,jj,1,2)   &
+               &   + e2t(ji  ,jj-1) * wght(ji,jj,2,1)   &
+               &   + e2t(ji-1,jj-1) * wght(ji,jj,1,1)
+
+            zusden = 1.0 / MAX( zh1p * zh2p * 4.e0 , 1.e-20 )
+            zusden2 = zusden * 2.0 
+
+            zd1d2p = zusden * 0.5 * ( -e1t(ji-1,jj-1) + e1t(ji-1,jj  ) - e1t(ji,jj-1) + e1t(ji  ,jj)   )
+            zd2d1p = zusden * 0.5 * (  e2t(ji  ,jj-1) - e2t(ji-1,jj-1) + e2t(ji,jj  ) - e2t(ji-1,jj)   )
+
+            alambd(ji,jj,2,2,2,1) = zusden2 * e2t(ji  ,jj-1)
+            alambd(ji,jj,2,2,2,2) = zusden2 * e2t(ji  ,jj  )
+            alambd(ji,jj,2,2,1,1) = zusden2 * e2t(ji-1,jj-1)
+            alambd(ji,jj,2,2,1,2) = zusden2 * e2t(ji-1,jj  )
+
+            alambd(ji,jj,1,1,2,1) = zusden2 * e1t(ji  ,jj-1)
+            alambd(ji,jj,1,1,2,2) = zusden2 * e1t(ji  ,jj  )
+            alambd(ji,jj,1,1,1,1) = zusden2 * e1t(ji-1,jj-1)
+            alambd(ji,jj,1,1,1,2) = zusden2 * e1t(ji-1,jj  )
+
+            alambd(ji,jj,1,2,2,1) = zd1d2p
+            alambd(ji,jj,1,2,2,2) = zd1d2p
+            alambd(ji,jj,1,2,1,1) = zd1d2p
+            alambd(ji,jj,1,2,1,2) = zd1d2p
+
+            alambd(ji,jj,2,1,2,1) = zd2d1p
+            alambd(ji,jj,2,1,2,2) = zd2d1p
+            alambd(ji,jj,2,1,1,1) = zd2d1p
+            alambd(ji,jj,2,1,1,2) = zd2d1p
+         END DO
+      END DO
+
+      CALL lbc_lnk( alambd(:,:,2,2,2,1), 'I', 1. )      ! CAUTION: even with the lbc_lnk at ice U-V point
+      CALL lbc_lnk( alambd(:,:,2,2,2,2), 'I', 1. )      ! the value of wght at jpj is wrong
+      CALL lbc_lnk( alambd(:,:,2,2,1,1), 'I', 1. )      ! but it is never used
+      CALL lbc_lnk( alambd(:,:,2,2,1,2), 'I', 1. )      ! 
+
+      CALL lbc_lnk( alambd(:,:,1,1,2,1), 'I', 1. )      ! CAUTION: idem
+      CALL lbc_lnk( alambd(:,:,1,1,2,2), 'I', 1. )      ! 
+      CALL lbc_lnk( alambd(:,:,1,1,1,1), 'I', 1. )      !
+      CALL lbc_lnk( alambd(:,:,1,1,1,2), 'I', 1. )      !
+
+      CALL lbc_lnk( alambd(:,:,1,2,2,1), 'I', 1. )      ! CAUTION: idem
+      CALL lbc_lnk( alambd(:,:,1,2,2,2), 'I', 1. )      !
+      CALL lbc_lnk( alambd(:,:,1,2,1,1), 'I', 1. )      !
+      CALL lbc_lnk( alambd(:,:,1,2,1,2), 'I', 1. )      !
+
+      CALL lbc_lnk( alambd(:,:,2,1,2,1), 'I', 1. )      ! CAUTION: idem
+      CALL lbc_lnk( alambd(:,:,2,1,2,2), 'I', 1. )      !
+      CALL lbc_lnk( alambd(:,:,2,1,1,1), 'I', 1. )      !
+      CALL lbc_lnk( alambd(:,:,2,1,1,2), 'I', 1. )      !
+            
+
+      ! Initialization of ice masks
+      !----------------------------
+      
+      tms(:,:) = tmask(:,:,1)      ! ice T-point  : use surface tmask
+
+!      tmu(:,1) = 0.e0
+!      tmu(1,:) = 0.e0
+!      tmv(:,1) = 0.e0
+!      tmv(1,:) = 0.e0
+
+      DO jj = 1, jpj - 1
+         DO ji = 1 , jpi - 1
+            tmu(ji,jj) =  tms(ji,jj) * tms(ji+1,jj)
+            tmv(ji,jj) =  tms(ji,jj) * tms(ji,jj+1)
+            tmf(ji,jj) =  tms(ji,jj) * tms(ji+1,jj) * tms(ji,jj+1) * &
+                          tms(ji+1,jj+1)
+         END DO
+      END DO
+      
+      !--lateral boundary conditions    
+      CALL lbc_lnk( tmu(:,:), 'U', 1. )
+      CALL lbc_lnk( tmv(:,:), 'V', 1. )
+      CALL lbc_lnk( tmf(:,:), 'F', 1. )
+      
+      ! unmasked and masked area of T-grid cell
+      area(:,:) = e1t(:,:) * e2t(:,:)
+      
+   END SUBROUTINE lim_msh
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option            Dummy Module         NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_msh           ! Dummy routine
+   END SUBROUTINE lim_msh
+#endif
+
+   !!======================================================================
+END MODULE limmsh
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limrhg.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limrhg.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limrhg.F90	(revision 884)
@@ -0,0 +1,780 @@
+MODULE limrhg
+   !!======================================================================
+   !!                     ***  MODULE  limrhg  ***
+   !!   Ice rheology : sea ice rheology
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_rhg   : computes ice velocities
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE phycst
+   USE par_oce
+   USE ice_oce         ! ice variables
+   USE dom_oce
+   USE dom_ice
+   USE ice
+   USE iceini
+   USE lbclnk
+   USE lib_mpp
+   USE in_out_manager  ! I/O manager
+   USE limitd_me
+   USE prtctl          ! Print control
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_rhg  ! routine called by lim_dyn
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      rzero   = 0.e0   ,  &
+      rone    = 1.e0
+   !!----------------------------------------------------------------------
+   !!   LIM 3.0,  UCL-LOCEAN-IPSL (2008) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limrhg.F90,v 1.5 2005/03/27 18:34:42 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_rhg( k_j1, k_jpj )
+
+      !!-------------------------------------------------------------------
+      !!                 ***  SUBROUTINE lim_rhg  ***
+      !!                          EVP-C-grid
+      !!
+      !! ** purpose : determines sea ice drift from wind stress, ice-ocean
+      !!  stress and sea-surface slope. Ice-ice interaction is described by 
+      !!  a non-linear elasto-viscous-plastic (EVP) law including shear 
+      !!  strength and a bulk rheology (Hunke and Dukowicz, 2002).	
+      !!
+      !!  The points in the C-grid look like this, dear reader
+      !!
+      !!                              (ji,jj)
+      !!                                 |
+      !!                                 |
+      !!                      (ji-1,jj)  |  (ji,jj)
+      !!                             ---------   
+      !!                            |         |
+      !!                            | (ji,jj) |------(ji,jj)
+      !!                            |         |
+      !!                             ---------   
+      !!                     (ji-1,jj-1)     (ji,jj-1)
+      !!
+      !! ** Inputs  : - wind forcing (stress), oceanic currents
+      !!                ice total volume (vt_i) per unit area
+      !!                snow total volume (vt_s) per unit area
+      !!
+      !! ** Action  : - compute u_ice, v_ice : the components of the 
+      !!                sea-ice velocity vector
+      !!              - compute delta_i, shear_i, divu_i, which are inputs
+      !!                of the ice thickness distribution
+      !!
+      !! ** Steps   : 1) Compute ice snow mass, ice strength 
+      !!              2) Compute wind, oceanic stresses, mass terms and
+      !!                 coriolis terms of the momentum equation
+      !!              3) Solve the momentum equation (iterative procedure)
+      !!              4) Prevent high velocities if the ice is thin
+      !!              5) Recompute invariants of the strain rate tensor
+      !!                 which are inputs of the ITD, store stress
+      !!                 for the next time step
+      !!              6) Control prints of residual (convergence)
+      !!                 and charge ellipse.
+      !!                 The user should make sure that the parameters
+      !!                 nevp, telast and creepl maintain stress state
+      !!                 on the charge ellipse for plastic flow
+      !!                 e.g. in the Canadian Archipelago
+      !!
+      !! ** References : Hunke and Dukowicz, JPO97
+      !!                 Bouillon et al., 08, in prep (update this when
+      !!                 published)
+      !!                 Vancoppenolle et al., OM08
+      !!
+      !! History :
+      !!   1.0  !  07-03  (M.A. Morales Maqueda, S. Bouillon)
+      !!   2.0  !  08-03  M. Vancoppenolle : LIM3
+      !!
+      !!-------------------------------------------------------------------
+      ! * Arguments
+      !
+      INTEGER, INTENT(in) :: &
+         k_j1 ,                      & !: southern j-index for ice computation
+         k_jpj                         !: northern j-index for ice computation
+
+      ! * Local variables
+      INTEGER ::   ji, jj              !: dummy loop indices
+
+      INTEGER  :: &
+         jter                          !: temporary integers
+
+      CHARACTER (len=50) ::   charout
+
+      REAL(wp) :: &
+         zt11, zt12, zt21, zt22,     & !: temporary scalars
+         ztagnx, ztagny,             & !: wind stress on U/V points                       
+         delta                         !
+
+      REAL(wp) :: &
+         za,                         & !:
+         zstms,                      & !: temporary scalar for ice strength
+         zsang,                      & !: temporary scalar for coriolis term
+         zmask                         !: mask for the computation of ice mass
+
+      REAL(wp),DIMENSION(jpi,jpj) :: &
+         zpresh        ,             & !: temporary array for ice strength
+         zpreshc       ,             & !: Ice strength on grid cell corners (zpreshc)
+         zfrld1, zfrld2,             & !: lead fraction on U/V points                                    
+         zmass1, zmass2,             & !: ice/snow mass on U/V points                                    
+         zcorl1, zcorl2,             & !: coriolis parameter on U/V points
+         za1ct, za2ct  ,             & !: temporary arrays
+         zc1           ,             & !: ice mass
+         zusw          ,             & !: temporary weight for the computation
+                                       !: of ice strength
+         u_oce1, v_oce1,             & !: ocean u/v component on U points                           
+         u_oce2, v_oce2,             & !: ocean u/v component on V points
+         u_ice2,                     & !: ice u component on V point
+         v_ice1                        !: ice v component on U point
+
+      REAL(wp) :: &
+         dtevp,                      & !: time step for subcycling
+         dtotel,                     & !:
+         ecc2,                       & !: square of yield ellipse eccenticity
+         z0,                         & !: temporary scalar
+         zr,                         & !: temporary scalar
+         zcca, zccb,                 & !: temporary scalars
+         zu_ice2,                    & !: 
+         zv_ice1,                    & !:
+         zddc, zdtc,                 & !: temporary array for delta on corners
+         zdst,                       & !: temporary array for delta on centre
+         zdsshx, zdsshy,             & !: term for the gradient of ocean surface
+         sigma1, sigma2                !: internal ice stress
+
+      REAL(wp),DIMENSION(jpi,jpj) :: &
+         zf1, zf2                      !: arrays for internal stresses
+
+      REAL(wp),DIMENSION(jpi,jpj) :: &
+         zdd, zdt,                   & !: Divergence and tension at centre of grid cells
+         zds,                        & !: Shear on northeast corner of grid cells
+         deltat,                     & !: Delta at centre of grid cells
+         deltac,                     & !: Delta on corners
+         zs1, zs2,                   & !: Diagonal stress tensor components zs1 and zs2 
+         zs12                          !: Non-diagonal stress tensor component zs12
+
+      REAL(wp) :: &
+         zresm            ,          & !: Maximal error on ice velocity
+         zindb            ,          & !: ice (1) or not (0)      
+         zdummy                        !: dummy argument
+
+      REAL(wp),DIMENSION(jpi,jpj) :: &
+         zu_ice           ,          & !: Ice velocity on previous time step
+         zv_ice           ,          &
+         zresr                         !: Local error on velocity
+
+!
+!------------------------------------------------------------------------------!
+! 1) Ice-Snow mass (zc1), ice strength (zpresh)                                !
+!------------------------------------------------------------------------------!
+!
+      ! Put every vector to 0
+      zpresh(:,:) = 0.0 ; zc1(:,:) = 0.0
+      zpreshc(:,:) = 0.0
+      u_ice2(:,:)  = 0.0 ; v_ice1(:,:)  = 0.0
+      zdd(:,:)     = 0.0 ; zdt(:,:)     = 0.0 ; zds(:,:)     = 0.0
+
+      ! Ice strength on T-points
+      CALL lim_itd_me_icestrength(ridge_scheme_swi)
+
+      ! Ice mass and temp variables
+!CDIR NOVERRCHK
+      DO jj = k_j1 , k_jpj
+!CDIR NOVERRCHK
+         DO ji = 1 , jpi
+            zc1(ji,jj)    = tms(ji,jj) * ( rhosn * vt_s(ji,jj) + rhoic * vt_i(ji,jj) )
+            zpresh(ji,jj) = tms(ji,jj) *  strength(ji,jj) / 2.
+            ! tmi = 1 where there is ice or on land
+            tmi(ji,jj)    = 1.0 - ( 1.0 - MAX( 0.0 , SIGN ( 1.0 , vt_i(ji,jj) - &
+                                    epsd ) ) ) * tms(ji,jj)
+         END DO
+      END DO
+
+      ! Ice strength on grid cell corners (zpreshc)
+      ! needed for calculation of shear stress 
+!CDIR NOVERRCHK
+      DO jj = k_j1+1, k_jpj-1
+!CDIR NOVERRCHK
+         DO ji = 2, jpim1 !RB caution no fs_ (ji+1,jj+1)
+             zstms          =  tms(ji+1,jj+1) * wght(ji+1,jj+1,2,2) + &
+                &              tms(ji,jj+1)   * wght(ji+1,jj+1,1,2) + &
+                &              tms(ji+1,jj)   * wght(ji+1,jj+1,2,1) + &
+                &              tms(ji,jj)     * wght(ji+1,jj+1,1,1)
+             zusw(ji,jj)    = 1.0 / MAX( zstms, epsd )
+             zpreshc(ji,jj) = (  zpresh(ji+1,jj+1) * wght(ji+1,jj+1,2,2) + &
+                &                zpresh(ji,jj+1)   * wght(ji+1,jj+1,1,2) + &
+                &                zpresh(ji+1,jj)   * wght(ji+1,jj+1,2,1) + & 
+                &                zpresh(ji,jj)     * wght(ji+1,jj+1,1,1)   &
+                &             ) * zusw(ji,jj)
+         END DO
+      END DO
+
+      CALL lbc_lnk( zpreshc(:,:), 'F', 1. )
+!
+!------------------------------------------------------------------------------!
+! 2) Wind / ocean stress, mass terms, coriolis terms
+!------------------------------------------------------------------------------!
+!
+      !  Wind stress, coriolis and mass terms on the sides of the squares        
+      !  zfrld1: lead fraction on U-points                                      
+      !  zfrld2: lead fraction on V-points                                     
+      !  zmass1: ice/snow mass on U-points                                    
+      !  zmass2: ice/snow mass on V-points                                   
+      !  zcorl1: Coriolis parameter on U-points                             
+      !  zcorl2: Coriolis parameter on V-points                            
+      !  (ztagnx,ztagny): wind stress on U/V points                       
+      !  u_oce1: ocean u component on u points                           
+      !  v_oce1: ocean v component on u points                          
+      !  u_oce2: ocean u component on v points                         
+      !  v_oce2: ocean v component on v points                        
+         
+      DO jj = k_j1+1, k_jpj-1
+         DO ji = fs_2, fs_jpim1
+
+            zt11 = tms(ji,jj)*e1t(ji,jj)
+            zt12 = tms(ji+1,jj)*e1t(ji+1,jj)
+            zt21 = tms(ji,jj)*e2t(ji,jj)
+            zt22 = tms(ji,jj+1)*e2t(ji,jj+1)
+
+            ! Leads area.
+            zfrld1(ji,jj) = ( zt12 * ( 1.0 - at_i(ji,jj) ) + &
+     &                        zt11 * ( 1.0 - at_i(ji+1,jj) ) ) / ( zt11 + zt12 + epsd )
+            zfrld2(ji,jj) = ( zt22 * ( 1.0 - at_i(ji,jj) ) + &
+     &                        zt21 * ( 1.0 - at_i(ji,jj+1) ) ) / ( zt21 + zt22 + epsd )
+
+            ! Mass, coriolis coeff. and currents
+            zmass1(ji,jj) = ( zt12*zc1(ji,jj) + zt11*zc1(ji+1,jj) ) / (zt11+zt12+epsd)
+            zmass2(ji,jj) = ( zt22*zc1(ji,jj) + zt21*zc1(ji,jj+1) ) / (zt21+zt22+epsd)
+            zcorl1(ji,jj) = zmass1(ji,jj) * ( e1t(ji+1,jj)*fcor(ji,jj) + &
+                                              e1t(ji,jj)*fcor(ji+1,jj) ) &
+                                           / (e1t(ji,jj) + e1t(ji+1,jj) + epsd )
+            zcorl2(ji,jj) = zmass2(ji,jj) * ( e2t(ji,jj+1)*fcor(ji,jj) + &
+                                              e2t(ji,jj)*fcor(ji,jj+1) ) &
+                                          / ( e2t(ji,jj+1) + e2t(ji,jj) + epsd )
+            !
+            u_oce1(ji,jj)  = u_io(ji,jj)
+            v_oce2(ji,jj)  = v_io(ji,jj)
+
+            ! Ocean has no slip boundary condition
+            v_oce1(ji,jj)  = 0.5*( (v_io(ji,jj)+v_io(ji,jj-1))*e1t(ji,jj)    &
+                &                 +(v_io(ji+1,jj)+v_io(ji+1,jj-1))*e1t(ji+1,jj)) &
+                &               /(e1t(ji+1,jj)+e1t(ji,jj)) * tmu(ji,jj)  
+
+            u_oce2(ji,jj)  = 0.5*((u_io(ji,jj)+u_io(ji-1,jj))*e2t(ji,jj)     &
+                &                 +(u_io(ji,jj+1)+u_io(ji-1,jj+1))*e2t(ji,jj+1)) &
+                &                / (e2t(ji,jj+1)+e2t(ji,jj)) * tmv(ji,jj)
+
+            ! Wind stress.
+            ztagnx = ( 1. - zfrld1(ji,jj) ) * gtaux(ji,jj)
+            ztagny = ( 1. - zfrld2(ji,jj) ) * gtauy(ji,jj)
+
+            ! Computation of the velocity field taking into account the ice internal interaction.
+            ! Terms that are independent of the velocity field.
+
+            ! SB On utilise maintenant le gradient de la pente de l'ocean
+            ! include it later
+            !    zdsshx =  (ssh_io(ji+1,jj) - ssh_io(ji,jj))/e1u(ji,jj)
+            !    zdsshy =  (ssh_io(ji,jj+1) - ssh_io(ji,jj))/e2v(ji,jj)  
+
+            zdsshx = 0.0
+            zdsshy = 0.0 
+
+            za1ct(ji,jj) = ztagnx - zmass1(ji,jj) * grav * zdsshx
+            za2ct(ji,jj) = ztagny - zmass2(ji,jj) * grav * zdsshy
+
+         END DO
+      END DO
+
+!
+!------------------------------------------------------------------------------!
+! 3) Solution of the momentum equation, iterative procedure
+!------------------------------------------------------------------------------!
+!
+      ! Time step for subcycling
+      dtevp  = rdt_ice / nevp
+      dtotel = dtevp / ( 2.0 * telast )
+
+      !-ecc2: square of yield ellipse eccenticrity (reminder: must become a namelist parameter)
+      ecc2 = ecc*ecc
+
+      !-Initialise stress tensor 
+      zs1(:,:)  = stress1_i(:,:) 
+      zs2(:,:)  = stress2_i(:,:)
+      zs12(:,:) = stress12_i(:,:)
+
+                                                      !----------------------!
+      DO jter = 1 , nevp                              !    loop over jter    !
+                                                      !----------------------!        
+         DO jj = k_j1, k_jpj-1
+            zu_ice(:,jj) = u_ice(:,jj) ! velocity at previous time step
+            zv_ice(:,jj) = v_ice(:,jj)
+         END DO      
+
+         DO jj = k_j1+1, k_jpj-1
+            DO ji = fs_2, fs_jpim1
+
+         !  
+         !- Divergence, tension and shear (Section a. Appendix B of Hunke & Dukowicz, 2002)
+         !- zdd(:,:), zdt(:,:): divergence and tension at centre of grid cells
+         !- zds(:,:): shear on northeast corner of grid cells
+                 !
+                 !- IMPORTANT REMINDER: Dear Gurvan, note that, the way these terms are coded, 
+                 !                      there are many repeated calculations. 
+                 !                      Speed could be improved by regrouping terms. For
+                 !                      the moment, however, the stress is on clarity of coding to avoid
+                 !                      bugs (Martin, for Miguel).
+                 !
+                 !- ALSO: arrays zdd, zdt, zds and delta could 
+                 !  be removed in the future to minimise memory demand.
+                 !
+                 !- MORE NOTES: Note that we are calculating deformation rates and stresses on the corners of
+                 !              grid cells, exactly as in the B grid case. For simplicity, the indexation on
+                 !              the corners is the same as in the B grid.
+                 !
+                 !
+                 zdd(ji,jj) = ( e2u(ji,jj)*u_ice(ji,jj)                      &
+                    &          -e2u(ji-1,jj)*u_ice(ji-1,jj)                  &
+                    &          +e1v(ji,jj)*v_ice(ji,jj)                      &
+                    &          -e1v(ji,jj-1)*v_ice(ji,jj-1)                  &
+                    &          )                                             &
+                    &         / area(ji,jj)
+
+                 zdt(ji,jj) = ( ( u_ice(ji,jj)/e2u(ji,jj)                    &
+                    &            -u_ice(ji-1,jj)/e2u(ji-1,jj)                &
+                    &           )*e2t(ji,jj)*e2t(ji,jj)                      &
+                    &          -( v_ice(ji,jj)/e1v(ji,jj)                    &
+                    &            -v_ice(ji,jj-1)/e1v(ji,jj-1)                &
+                    &           )*e1t(ji,jj)*e1t(ji,jj)                      &
+                    &         )                                              &
+                    &        / area(ji,jj)
+
+                 !
+                 zds(ji,jj) = ( ( u_ice(ji,jj+1)/e1u(ji,jj+1)                &
+                    &            -u_ice(ji,jj)/e1u(ji,jj)                    &
+                    &           )*e1f(ji,jj)*e1f(ji,jj)                      &
+                    &          +( v_ice(ji+1,jj)/e2v(ji+1,jj)                &
+                    &            -v_ice(ji,jj)/e2v(ji,jj)                    &
+                    &           )*e2f(ji,jj)*e2f(ji,jj)                      &
+                    &         )                                              &
+                    &        / ( e1f(ji,jj) * e2f(ji,jj) ) * ( 2.0 - tmf(ji,jj) ) &
+                    &        * tmi(ji,jj) * tmi(ji,jj+1)                     &
+                    &        * tmi(ji+1,jj) * tmi(ji+1,jj+1)
+
+ 
+                 v_ice1(ji,jj)  = 0.5*( (v_ice(ji,jj)+v_ice(ji,jj-1))*e1t(ji+1,jj)   &
+                    &                 +(v_ice(ji+1,jj)+v_ice(ji+1,jj-1))*e1t(ji,jj)) &
+                    &               /(e1t(ji+1,jj)+e1t(ji,jj)) * tmu(ji,jj) 
+
+                 u_ice2(ji,jj)  = 0.5*( (u_ice(ji,jj)+u_ice(ji-1,jj))*e2t(ji,jj+1)   &
+                    &                 +(u_ice(ji,jj+1)+u_ice(ji-1,jj+1))*e2t(ji,jj)) &
+                    &               /(e2t(ji,jj+1)+e2t(ji,jj)) * tmv(ji,jj)
+
+              END DO
+           END DO
+           CALL lbc_lnk( v_ice1(:,:), 'U', -1. )
+           CALL lbc_lnk( u_ice2(:,:), 'V', -1. )
+
+!CDIR NOVERRCHK
+           DO jj = k_j1+1, k_jpj-1
+!CDIR NOVERRCHK
+              DO ji = fs_2, fs_jpim1
+
+                 !- Calculate Delta at centre of grid cells
+                 zdst       = (  e2u( ji  , jj   ) * v_ice1(ji,jj)            &
+                    &          - e2u( ji-1, jj   ) * v_ice1(ji-1,jj)          &
+                    &          + e1v( ji  , jj   ) * u_ice2(ji,jj)            &
+                    &          - e1v( ji  , jj-1 ) * u_ice2(ji,jj-1)          &
+                    &          )                                              &
+                    &         / area(ji,jj)
+
+                 delta = SQRT( zdd(ji,jj)*zdd(ji,jj) +                        & 
+     &                       ( zdt(ji,jj)*zdt(ji,jj) + zdst*zdst ) * usecc2 )  
+                 deltat(ji,jj) = MAX( SQRT(zdd(ji,jj)**2 +                    &
+                                 (zdt(ji,jj)**2 + zdst**2)*usecc2), creepl )
+
+                 !-Calculate stress tensor components zs1 and zs2 
+                 !-at centre of grid cells (see section 3.5 of CICE user's guide).
+                 zs1(ji,jj) = ( zs1(ji,jj) &
+                    &          - dtotel*( ( 1.0 - alphaevp) * zs1(ji,jj) +    &
+                    &            ( delta / deltat(ji,jj) - zdd(ji,jj) / deltat(ji,jj) ) &
+                                 * zpresh(ji,jj) ) )                          &       
+                    &        / ( 1.0 + alphaevp * dtotel )
+
+                 zs2(ji,jj) = ( zs2(ji,jj)   &
+                    &          - dtotel*((1.0-alphaevp)*ecc2*zs2(ji,jj) -  &
+                                 zdt(ji,jj)/deltat(ji,jj)*zpresh(ji,jj)) ) &
+                    &        / ( 1.0 + alphaevp*ecc2*dtotel )
+
+              END DO
+           END DO
+
+           CALL lbc_lnk( zs1(:,:), 'T', 1. )
+           CALL lbc_lnk( zs2(:,:), 'T', 1. )
+
+!CDIR NOVERRCHK
+           DO jj = k_j1+1, k_jpj-1
+!CDIR NOVERRCHK
+              DO ji = fs_2, fs_jpim1
+                 !- Calculate Delta on corners
+                 zddc  =      ( ( v_ice1(ji,jj+1)/e1u(ji,jj+1)                &
+                    &            -v_ice1(ji,jj)/e1u(ji,jj)                    &
+                    &           )*e1f(ji,jj)*e1f(ji,jj)                       &
+                    &          +( u_ice2(ji+1,jj)/e2v(ji+1,jj)                &
+                    &            -u_ice2(ji,jj)/e2v(ji,jj)                    &
+                    &           )*e2f(ji,jj)*e2f(ji,jj)                       &
+                    &         )                                               &
+                    &        / ( e1f(ji,jj) * e2f(ji,jj) )
+
+                 zdtc  =      (-( v_ice1(ji,jj+1)/e1u(ji,jj+1)                &
+                    &            -v_ice1(ji,jj)/e1u(ji,jj)                    &
+                    &           )*e1f(ji,jj)*e1f(ji,jj)                       &
+                    &          +( u_ice2(ji+1,jj)/e2v(ji+1,jj)                &
+                    &            -u_ice2(ji,jj)/e2v(ji,jj)                    &
+                    &           )*e2f(ji,jj)*e2f(ji,jj)                       &
+                    &         )                                               &
+                    &        / ( e1f(ji,jj) * e2f(ji,jj) )
+
+                 deltac(ji,jj) = SQRT(zddc**2+(zdtc**2+zds(ji,jj)**2)*usecc2) + creepl
+
+                 !-Calculate stress tensor component zs12 at corners (see section 3.5 of CICE user's guide).
+                 zs12(ji,jj) = ( zs12(ji,jj)      &
+                    &        - dtotel*( (1.0-alphaevp)*ecc2*zs12(ji,jj) - zds(ji,jj) / &
+                    &          ( 2.0*deltac(ji,jj) ) * zpreshc(ji,jj))) &
+                    &         / ( 1.0 + alphaevp*ecc2*dtotel ) 
+
+              END DO ! ji
+           END DO ! jj
+
+           CALL lbc_lnk( zs12(:,:), 'F', 1. )
+
+           ! Ice internal stresses (Appendix C of Hunke and Dukowicz, 2002)
+           DO jj = k_j1+1, k_jpj-1
+              DO ji = fs_2, fs_jpim1
+                !- contribution of zs1, zs2 and zs12 to zf1
+                zf1(ji,jj) = 0.5*( (zs1(ji+1,jj)-zs1(ji,jj))*e2u(ji,jj) &
+                   &              +(zs2(ji+1,jj)*e2t(ji+1,jj)**2-zs2(ji,jj)*e2t(ji,jj)**2)/e2u(ji,jj) &
+                   &              +2.0*(zs12(ji,jj)*e1f(ji,jj)**2-zs12(ji,jj-1)*e1f(ji,jj-1)**2)/e1u(ji,jj) &
+                   &             ) / ( e1u(ji,jj)*e2u(ji,jj) )
+                ! contribution of zs1, zs2 and zs12 to zf2
+                zf2(ji,jj) = 0.5*( (zs1(ji,jj+1)-zs1(ji,jj))*e1v(ji,jj) &
+                   &              -(zs2(ji,jj+1)*e1t(ji,jj+1)**2 - zs2(ji,jj)*e1t(ji,jj)**2)/e1v(ji,jj) &
+                   &              + 2.0*(zs12(ji,jj)*e2f(ji,jj)**2 -    &
+                                    zs12(ji-1,jj)*e2f(ji-1,jj)**2)/e2v(ji,jj) &
+                   &             ) / ( e1v(ji,jj)*e2v(ji,jj) )
+              END DO
+           END DO
+         !
+         ! Computation of ice velocity
+         !
+         ! Both the Coriolis term and the ice-ocean drag are solved semi-implicitly.
+         !
+           IF (MOD(jter,2).eq.0) THEN 
+
+!CDIR NOVERRCHK
+              DO jj = k_j1+1, k_jpj-1
+!CDIR NOVERRCHK
+                 DO ji = fs_2, fs_jpim1
+                    zmask        = (1.0-MAX(rzero,SIGN(rone,-zmass1(ji,jj))))*tmu(ji,jj)
+                    zsang        = SIGN ( 1.0 , fcor(ji,jj) ) * sangvg
+                    z0           = zmass1(ji,jj)/dtevp
+
+                    ! SB modif because ocean has no slip boundary condition
+                    zv_ice1       = 0.5*( (v_ice(ji,jj)+v_ice(ji,jj-1))*e1t(ji,jj)         &
+                      &                 +(v_ice(ji+1,jj)+v_ice(ji+1,jj-1))*e1t(ji+1,jj))   &
+                      &               /(e1t(ji+1,jj)+e1t(ji,jj)) * tmu(ji,jj)
+                    za           = rhoco*SQRT((u_ice(ji,jj)-u_oce1(ji,jj))**2 + &
+                                              (zv_ice1-v_oce1(ji,jj))**2) * (1.0-zfrld1(ji,jj))
+                    zr           = z0*u_ice(ji,jj) + zf1(ji,jj) + za1ct(ji,jj) + &
+                                   za*(cangvg*u_oce1(ji,jj)-zsang*v_oce1(ji,jj))
+                    zcca         = z0+za*cangvg
+                    zccb         = zcorl1(ji,jj)+za*zsang
+                    u_ice(ji,jj) = (zr+zccb*zv_ice1)/(zcca+epsd)*zmask 
+
+                 END DO
+              END DO
+
+              CALL lbc_lnk( u_ice(:,:), 'U', -1. )
+
+!CDIR NOVERRCHK
+              DO jj = k_j1+1, k_jpj-1
+!CDIR NOVERRCHK
+                 DO ji = fs_2, fs_jpim1
+
+                    zmask        = (1.0-MAX(rzero,SIGN(rone,-zmass2(ji,jj))))*tmv(ji,jj)
+                    zsang        = SIGN(1.0,fcor(ji,jj))*sangvg
+                    z0           = zmass2(ji,jj)/dtevp
+                    ! SB modif because ocean has no slip boundary condition
+                    zu_ice2       = 0.5*( (u_ice(ji,jj)+u_ice(ji-1,jj))*e2t(ji,jj)     &
+                &                 + (u_ice(ji,jj+1)+u_ice(ji-1,jj+1))*e2t(ji,jj+1))   &
+                &               /(e2t(ji,jj+1)+e2t(ji,jj)) * tmv(ji,jj)
+                    za           = rhoco*SQRT((zu_ice2-u_oce2(ji,jj))**2 + & 
+                                   (v_ice(ji,jj)-v_oce2(ji,jj))**2)*(1.0-zfrld2(ji,jj))
+                    zr           = z0*v_ice(ji,jj) + zf2(ji,jj) + &
+                                   za2ct(ji,jj) + za*(cangvg*v_oce2(ji,jj)+zsang*u_oce2(ji,jj))
+                    zcca         = z0+za*cangvg
+                    zccb         = zcorl2(ji,jj)+za*zsang
+                    v_ice(ji,jj) = (zr-zccb*zu_ice2)/(zcca+epsd)*zmask
+
+                 END DO
+              END DO
+
+              CALL lbc_lnk( v_ice(:,:), 'V', -1. )
+
+         ELSE 
+!CDIR NOVERRCHK
+              DO jj = k_j1+1, k_jpj-1
+!CDIR NOVERRCHK
+                 DO ji = fs_2, fs_jpim1
+                    zmask        = (1.0-MAX(rzero,SIGN(rone,-zmass2(ji,jj))))*tmv(ji,jj)
+                    zsang        = SIGN(1.0,fcor(ji,jj))*sangvg
+                    z0           = zmass2(ji,jj)/dtevp
+                    ! SB modif because ocean has no slip boundary condition
+                    zu_ice2       = 0.5*( (u_ice(ji,jj)+u_ice(ji-1,jj))*e2t(ji,jj)      &
+                       &                 +(u_ice(ji,jj+1)+u_ice(ji-1,jj+1))*e2t(ji,jj+1))   &
+                       &               /(e2t(ji,jj+1)+e2t(ji,jj)) * tmv(ji,jj)   
+
+                    za           = rhoco*SQRT((zu_ice2-u_oce2(ji,jj))**2 + &
+                                   (v_ice(ji,jj)-v_oce2(ji,jj))**2)*(1.0-zfrld2(ji,jj))
+                    zr           = z0*v_ice(ji,jj) + zf2(ji,jj) + &
+                                   za2ct(ji,jj) + za*(cangvg*v_oce2(ji,jj)+zsang*u_oce2(ji,jj))
+                    zcca         = z0+za*cangvg
+                    zccb         = zcorl2(ji,jj)+za*zsang
+                    v_ice(ji,jj) = (zr-zccb*zu_ice2)/(zcca+epsd)*zmask
+
+                 END DO
+              END DO
+
+              CALL lbc_lnk( v_ice(:,:), 'V', -1. )
+
+!CDIR NOVERRCHK
+              DO jj = k_j1+1, k_jpj-1
+!CDIR NOVERRCHK
+                 DO ji = fs_2, fs_jpim1
+                    zmask        = (1.0-MAX(rzero,SIGN(rone,-zmass1(ji,jj))))*tmu(ji,jj)
+                    zsang        = SIGN(1.0,fcor(ji,jj))*sangvg
+                    z0           = zmass1(ji,jj)/dtevp
+                    ! SB modif because ocean has no slip boundary condition
+! GG Bug
+!                   zv_ice1       = 0.5*( (v_ice(ji,jj)+v_ice(ji,jj-1))*e1t(ji+1,jj)      &
+!                      &                 +(v_ice(ji+1,jj)+v_ice(ji+1,jj-1))*e1t(ji,jj))   &
+!                      &               /(e1t(ji+1,jj)+e1t(ji,jj)) * tmu(ji,jj)
+                    zv_ice1       = 0.5*( (v_ice(ji,jj)+v_ice(ji,jj-1))*e1t(ji,jj)      &
+                       &                 +(v_ice(ji+1,jj)+v_ice(ji+1,jj-1))*e1t(ji+1,jj))   &
+                       &               /(e1t(ji+1,jj)+e1t(ji,jj)) * tmu(ji,jj)
+    
+                    za           = rhoco*SQRT((u_ice(ji,jj)-u_oce1(ji,jj))**2 + &
+                                   (zv_ice1-v_oce1(ji,jj))**2)*(1.0-zfrld1(ji,jj))
+                    zr           = z0*u_ice(ji,jj) + zf1(ji,jj) + za1ct(ji,jj) + &
+                                   za*(cangvg*u_oce1(ji,jj)-zsang*v_oce1(ji,jj))
+                    zcca         = z0+za*cangvg
+                    zccb         = zcorl1(ji,jj)+za*zsang
+                    u_ice(ji,jj) = (zr+zccb*zv_ice1)/(zcca+epsd)*zmask 
+                 END DO ! ji
+              END DO ! jj
+
+              CALL lbc_lnk( u_ice(:,:), 'U', -1. )
+
+      ENDIF 
+
+      IF(ln_ctl) THEN
+         !---  Convergence test.
+         DO jj = k_j1+1 , k_jpj-1
+            zresr(:,jj) = MAX( ABS( u_ice(:,jj) - zu_ice(:,jj) ) ,           &
+                          ABS( v_ice(:,jj) - zv_ice(:,jj) ) )
+         END DO
+         zresm = MAXVAL( zresr( 1:jpi , k_j1+1:k_jpj-1 ) )
+         IF( lk_mpp )   CALL mpp_max( zresm )   ! max over the global domain
+      ENDIF
+
+      !                                                   ! ==================== !
+      END DO                                              !  end loop over jter  !
+      !                                                   ! ==================== !
+
+!
+!------------------------------------------------------------------------------!
+! 4) Prevent ice velocities when the ice is thin
+!------------------------------------------------------------------------------!
+!
+      ! If the ice thickness is below 1cm then ice velocity should equal the
+      ! ocean velocity, 
+      ! This prevents high velocity when ice is thin
+!CDIR NOVERRCHK
+      DO jj = k_j1+1, k_jpj-1
+!CDIR NOVERRCHK
+         DO ji = fs_2, fs_jpim1
+            zindb  = MAX( 0.0, SIGN( 1.0, at_i(ji,jj) - 1.0e-6 ) ) 
+            zdummy = zindb * vt_i(ji,jj) / MAX(at_i(ji,jj) , 1.0e-06 )
+            IF ( zdummy .LE. 5.0e-2 ) THEN
+               u_ice(ji,jj) = u_io(ji,jj)
+               v_ice(ji,jj) = v_io(ji,jj)
+            ENDIF ! zdummy
+         END DO
+      END DO
+
+      CALL lbc_lnk( u_ice(:,:), 'U', -1. ) 
+      CALL lbc_lnk( v_ice(:,:), 'V', -1. ) 
+
+      DO jj = k_j1+1, k_jpj-1 
+         DO ji = fs_2, fs_jpim1
+            zindb  = MAX( 0.0, SIGN( 1.0, at_i(ji,jj) - 1.0e-6 ) ) 
+            zdummy = zindb * vt_i(ji,jj) / MAX(at_i(ji,jj) , 1.0e-06 )
+            IF ( zdummy .LE. 5.0e-2 ) THEN
+                v_ice1(ji,jj)  = 0.5*( (v_ice(ji,jj)+v_ice(ji,jj-1))*e1t(ji+1,jj)   &
+                   &                 +(v_ice(ji+1,jj)+v_ice(ji+1,jj-1))*e1t(ji,jj)) &
+                   &               /(e1t(ji+1,jj)+e1t(ji,jj)) * tmu(ji,jj)
+
+                u_ice2(ji,jj)  = 0.5*( (u_ice(ji,jj)+u_ice(ji-1,jj))*e2t(ji,jj+1)   &
+                   &                 +(u_ice(ji,jj+1)+u_ice(ji-1,jj+1))*e2t(ji,jj)) &
+                   &               /(e2t(ji,jj+1)+e2t(ji,jj)) * tmv(ji,jj)
+             ENDIF ! zdummy
+         END DO
+      END DO
+
+      CALL lbc_lnk( u_ice2(:,:), 'V', -1. ) 
+      CALL lbc_lnk( v_ice1(:,:), 'U', -1. )
+
+      ! Recompute delta, shear and div, inputs for mechanical redistribution 
+!CDIR NOVERRCHK
+      DO jj = k_j1+1, k_jpj-1
+!CDIR NOVERRCHK
+         DO ji = fs_2, fs_jpim1
+            !- zdd(:,:), zdt(:,:): divergence and tension at centre 
+            !- zds(:,:): shear on northeast corner of grid cells
+            zindb  = MAX( 0.0, SIGN( 1.0, at_i(ji,jj) - 1.0e-6 ) ) 
+            zdummy = zindb * vt_i(ji,jj) / MAX(at_i(ji,jj) , 1.0e-06 )
+
+            IF ( zdummy .LE. 5.0e-2 ) THEN
+
+            zdd(ji,jj) = ( e2u(ji,jj)*u_ice(ji,jj)                      &
+               &          -e2u(ji-1,jj)*u_ice(ji-1,jj)                  &
+               &          +e1v(ji,jj)*v_ice(ji,jj)                      &
+               &          -e1v(ji,jj-1)*v_ice(ji,jj-1)                  &
+               &         )                                              &
+               &         / area(ji,jj)
+
+            zdt(ji,jj) = ( ( u_ice(ji,jj)/e2u(ji,jj)                    &
+               &            -u_ice(ji-1,jj)/e2u(ji-1,jj)                &
+               &           )*e2t(ji,jj)*e2t(ji,jj)                      &
+               &          -( v_ice(ji,jj)/e1v(ji,jj)                    &
+               &            -v_ice(ji,jj-1)/e1v(ji,jj-1)                &
+               &           )*e1t(ji,jj)*e1t(ji,jj)                      &
+               &         )                                              &
+               &        / area(ji,jj)
+            !
+            ! SB modif because ocean has no slip boundary condition 
+            zds(ji,jj) = ( ( u_ice(ji,jj+1) / e1u(ji,jj+1)              &
+               &           - u_ice(ji,jj)   / e1u(ji,jj) )              &
+               &           * e1f(ji,jj) * e1f(ji,jj)                    &
+               &          + ( v_ice(ji+1,jj) / e2v(ji+1,jj)             &
+               &            - v_ice(ji,jj)  / e2v(ji,jj) )              &
+               &           * e2f(ji,jj) * e2f(ji,jj) )                  &
+               &        / ( e1f(ji,jj) * e2f(ji,jj) ) * ( 2.0 - tmf(ji,jj) ) &
+               &        * tmi(ji,jj) * tmi(ji,jj+1)                     &
+               &        * tmi(ji+1,jj) * tmi(ji+1,jj+1)
+
+             zdst       = (  e2u( ji  , jj   ) * v_ice1(ji,jj)          &
+               &          - e2u( ji-1, jj   ) * v_ice1(ji-1,jj)         &
+               &          + e1v( ji  , jj   ) * u_ice2(ji,jj)           &
+               &          - e1v( ji  , jj-1 ) * u_ice2(ji,jj-1)         & 
+               &          )                                             &
+               &         / area(ji,jj)
+
+             deltat(ji,jj) = SQRT( zdd(ji,jj)*zdd(ji,jj) + & 
+     &                          ( zdt(ji,jj)*zdt(ji,jj) + zdst*zdst ) * usecc2 & 
+     &                          ) + creepl
+
+             ENDIF ! zdummy
+
+         END DO !jj
+      END DO !ji
+!
+!------------------------------------------------------------------------------!
+! 5) Store stress tensor and its invariants
+!------------------------------------------------------------------------------!
+!
+      ! * Invariants of the stress tensor are required for limitd_me
+      ! accelerates convergence and improves stability
+      DO jj = k_j1+1, k_jpj-1
+         DO ji = fs_2, fs_jpim1
+            divu_i (ji,jj) = zdd   (ji,jj)
+            delta_i(ji,jj) = deltat(ji,jj)
+            shear_i(ji,jj) = zds   (ji,jj)
+         END DO
+      END DO
+
+      ! Lateral boundary condition
+      CALL lbc_lnk( divu_i (:,:), 'T', 1. )
+      CALL lbc_lnk( delta_i(:,:), 'T', 1. )
+      CALL lbc_lnk( shear_i(:,:), 'F', 1. )
+
+      ! * Store the stress tensor for the next time step
+      stress1_i (:,:) = zs1 (:,:)
+      stress2_i (:,:) = zs2 (:,:)
+      stress12_i(:,:) = zs12(:,:)
+
+!
+!------------------------------------------------------------------------------!
+! 6) Control prints of residual and charge ellipse
+!------------------------------------------------------------------------------!
+!
+      ! print the residual for convergence
+      IF(ln_ctl) THEN
+         WRITE(charout,FMT="('lim_rhg  : res =',D23.16, ' iter =',I4)") zresm, jter
+         CALL prt_ctl_info(charout)
+         CALL prt_ctl(tab2d_1=u_ice, clinfo1=' lim_rhg  : u_ice :', tab2d_2=v_ice, clinfo2=' v_ice :')
+      ENDIF
+
+      ! print charge ellipse
+      ! This can be desactivated once the user is sure that the stress state
+      ! lie on the charge ellipse. See Bouillon et al. 08 for more details
+      IF(ln_ctl) THEN
+         CALL prt_ctl_info('lim_rhg  : numit  :',ivar1=numit)
+         CALL prt_ctl_info('lim_rhg  : nwrite :',ivar1=nwrite)
+         CALL prt_ctl_info('lim_rhg  : MOD    :',ivar1=MOD(numit,nwrite))
+         IF( MOD(numit,nwrite) .EQ. 0 ) THEN
+            WRITE(charout,FMT="('lim_rhg  :', I4, I6, I1, I1, A10)") 1000, numit, 0, 0, ' ch. ell. '
+            CALL prt_ctl_info(charout)
+            DO jj = k_j1+1, k_jpj-1
+               DO ji = 2, jpim1
+                  IF (zpresh(ji,jj) .GT. 1.0) THEN
+                     sigma1 = ( zs1(ji,jj) + (zs2(ji,jj)**2 + 4*zs12(ji,jj)**2 )**0.5 ) / ( 2*zpresh(ji,jj) ) 
+                     sigma2 = ( zs1(ji,jj) - (zs2(ji,jj)**2 + 4*zs12(ji,jj)**2 )**0.5 ) / ( 2*zpresh(ji,jj) )
+                     WRITE(charout,FMT="('lim_rhg  :', I4, I4, D23.16, D23.16, D23.16, D23.16, A10)")
+                     CALL prt_ctl_info(charout)
+                  ENDIF
+               END DO
+            END DO
+            WRITE(charout,FMT="('lim_rhg  :', I4, I6, I1, I1, A10)") 2000, numit, 0, 0, ' ch. ell. '
+            CALL prt_ctl_info(charout)
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE lim_rhg
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option          Dummy module           NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_rhg( k1 , k2 )         ! Dummy routine
+      WRITE(*,*) 'lim_rhg: You should not have seen this print! error?', k1, k2
+   END SUBROUTINE lim_rhg
+#endif
+
+   !!==============================================================================
+END MODULE limrhg
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limrst.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limrst.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limrst.F90	(revision 884)
@@ -0,0 +1,745 @@
+MODULE limrst
+   !!======================================================================
+   !!                     ***  MODULE  limrst  ***
+   !! Ice restart :  write the ice restart file
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' :                                   LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_rst_opn     : open ice restart file
+   !!   lim_rst_write   : write of the restart file 
+   !!   lim_rst_read    : read  the restart file 
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE ice
+   USE par_ice
+   USE in_out_manager
+   USE dom_oce
+   USE ice_oce         ! ice variables
+   USE daymod
+   USE iom
+   
+   IMPLICIT NONE
+   PRIVATE
+   
+   !! * Accessibility
+   PUBLIC lim_rst_opn    ! routine called by icestep.F90
+   PUBLIC lim_rst_write  ! routine called by icestep.F90
+   PUBLIC lim_rst_read   ! routine called by iceinit.F90
+
+   LOGICAL, PUBLIC ::   lrst_ice         !: logical to control the ice restart write 
+   INTEGER, PUBLIC ::   numrir, numriw   !: logical unit for ice restart (read and write)
+
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005)
+   !! $Id:$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_rst_opn( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  lim_rst_opn  ***
+      !!
+      !! ** purpose  :   output of sea-ice variable in a netcdf file
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt       ! number of iteration
+      !
+      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
+      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 )   lrst_ice = .FALSE.   ! default definition
+      
+      ! to get better performances with NetCDF format:
+      ! we open and define the ice restart file one ice time step before writing the data (-> at nitrst - 2*nfice + 1)
+      ! except if we write ice restart files every ice time step or if an ice restart file was writen at nitend - 2*nfice + 1
+      IF( kt == nitrst - 2*nfice + 1 .OR. nstock == nfice .OR. ( kt == nitend - nfice + 1 .AND. .NOT. lrst_ice ) ) THEN
+         ! beware of the format used to write kt (default is i8.8, that should be large enough...)
+         IF( nitrst > 99999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
+         ELSE                           ;   WRITE(clkt, '(i8.8)') nitrst
+         ENDIF
+         ! create the file
+         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_restart_ice"
+         IF(lwp) THEN
+            WRITE(numout,*)
+            SELECT CASE ( jprstlib )
+            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ice restart binary file: '//clname
+            CASE DEFAULT         ;   WRITE(numout,*) '             open ice restart NetCDF file: '//clname
+            END SELECT
+            IF( kt == nitrst - 2*nfice + 1 ) THEN   
+               WRITE(numout,*)         '             kt = nitrst - 2*nfice + 1 = ', kt,' date= ', ndastp
+            ELSE   ;   WRITE(numout,*) '             kt = '                       , kt,' date= ', ndastp
+            ENDIF
+         ENDIF
+
+         CALL iom_open( clname, numriw, ldwrt = .TRUE., kiolib = jprstlib )
+         lrst_ice = .TRUE.
+      ENDIF
+      !
+   END SUBROUTINE lim_rst_opn
+
+   SUBROUTINE lim_rst_write( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  lim_rst_write  ***
+      !!
+      !! ** purpose  :   output of sea-ice variable in a netcdf file
+      !!
+      !!----------------------------------------------------------------------
+      ! Arguments :
+      INTEGER, INTENT(in) ::   kt     ! number of iteration
+
+      ! Local variables :
+      REAL(wp), DIMENSION(jpi,jpj) :: z2d
+      INTEGER :: ji, jj, jk ,jl
+      INTEGER :: iter
+      CHARACTER(len=15) :: znam
+      CHARACTER(len=1)  :: zchar, zchar1
+      !!----------------------------------------------------------------------
+   
+      iter = kt + nfice - 1   ! ice restarts are written at kt == nitrst - nfice + 1
+
+      IF( iter == nitrst ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'lim_rst_write : write ice restart file  kt =', kt
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'         
+      ENDIF
+
+      ! Write in numriw (if iter == nitrst)
+      ! ------------------ 
+      !                                                                        ! calendar control
+      CALL iom_rstput( iter, nitrst, numriw, 'nfice' , REAL( nfice, wp) )      ! time-step 
+      CALL iom_rstput( iter, nitrst, numriw, 'kt_ice', REAL( iter , wp) )      ! date
+
+      ! Prognostic variables 
+      DO jl = 1, jpl 
+         WRITE(zchar,'(I1)') jl
+         znam = 'v_i'//'_htc'//zchar
+         z2d(:,:) = v_i(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'v_s'//'_htc'//zchar
+         z2d(:,:) = v_s(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'smv_i'//'_htc'//zchar
+         z2d(:,:) = smv_i(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'oa_i'//'_htc'//zchar
+         z2d(:,:) = oa_i(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'a_i'//'_htc'//zchar
+         z2d(:,:) = a_i(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 't_su'//'_htc'//zchar
+         z2d(:,:) = t_su(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+      END DO
+# if defined key_coupled
+      CALL iom_rstput( iter, nitrst, numriw, 'albege', albege(:,:) )
+# endif
+      DO jl = 1, jpl 
+         WRITE(zchar,'(I1)') jl
+         znam = 'tempt_sl1'//'_htc'//zchar
+         z2d(:,:) = e_s(:,:,1,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+      END DO
+
+      DO jl = 1, jpl 
+         WRITE(zchar,'(I1)') jl
+         DO jk = 1, nlay_i 
+            WRITE(zchar1,'(I1)') jk
+            znam = 'tempt'//'_il'//zchar1//'_htc'//zchar
+            z2d(:,:) = e_i(:,:,jk,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         END DO
+      END DO
+
+      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, 'gtaux'     , gtaux      )
+      CALL iom_rstput( iter, nitrst, numriw, 'gtauy'     , gtauy      )
+      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  )
+      CALL iom_rstput( iter, nitrst, numriw, 'stress12_i', stress12_i )
+
+      DO jl = 1, jpl 
+         WRITE(zchar,'(I1)') jl
+         znam = 'sxice'//'_htc'//zchar
+         z2d(:,:) = sxice(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'syice'//'_htc'//zchar
+         z2d(:,:) = syice(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxxice'//'_htc'//zchar
+         z2d(:,:) = sxxice(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'syyice'//'_htc'//zchar
+         z2d(:,:) = syyice(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxyice'//'_htc'//zchar
+         z2d(:,:) = sxyice(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxsn'//'_htc'//zchar
+         z2d(:,:) = sxsn(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sysn'//'_htc'//zchar
+         z2d(:,:) = sysn(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxxsn'//'_htc'//zchar
+         z2d(:,:) = sxxsn(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'syysn'//'_htc'//zchar
+         z2d(:,:) = syysn(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxysn'//'_htc'//zchar
+         z2d(:,:) = sxysn(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxa'//'_htc'//zchar
+         z2d(:,:) = sxa(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sya'//'_htc'//zchar
+         z2d(:,:) = sya(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxxa'//'_htc'//zchar
+         z2d(:,:) = sxxa(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'syya'//'_htc'//zchar
+         z2d(:,:) = syya(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxya'//'_htc'//zchar
+         z2d(:,:) = sxya(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxc0'//'_htc'//zchar
+         z2d(:,:) = sxc0(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'syc0'//'_htc'//zchar
+         z2d(:,:) = syc0(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxxc0'//'_htc'//zchar
+         z2d(:,:) = sxxc0(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'syyc0'//'_htc'//zchar
+         z2d(:,:) = syyc0(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxyc0'//'_htc'//zchar
+         z2d(:,:) = sxyc0(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxsal'//'_htc'//zchar
+         z2d(:,:) = sxsal(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sysal'//'_htc'//zchar
+         z2d(:,:) = sysal(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxxsal'//'_htc'//zchar
+         z2d(:,:) = sxxsal(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'syysal'//'_htc'//zchar
+         z2d(:,:) = syysal(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxysal'//'_htc'//zchar
+         z2d(:,:) = sxysal(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxage'//'_htc'//zchar
+         z2d(:,:) = sxage(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'syage'//'_htc'//zchar
+         z2d(:,:) = syage(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxxage'//'_htc'//zchar
+         z2d(:,:) = sxxage(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'syyage'//'_htc'//zchar
+         z2d(:,:) = syyage(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         znam = 'sxyage'//'_htc'//zchar
+         z2d(:,:) = sxyage(:,:,jl)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+      END DO
+
+      CALL iom_rstput( iter, nitrst, numriw, 'sxopw ' ,  sxopw  )
+      CALL iom_rstput( iter, nitrst, numriw, 'syopw ' ,  syopw  )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxxopw' ,  sxxopw )
+      CALL iom_rstput( iter, nitrst, numriw, 'syyopw' ,  syyopw )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxyopw' ,  sxyopw )
+
+      DO jl = 1, jpl 
+         WRITE(zchar,'(I1)') jl
+         DO jk = 1, nlay_i 
+            WRITE(zchar1,'(I1)') jk
+            znam = 'sxe'//'_il'//zchar1//'_htc'//zchar
+            z2d(:,:) = sxe(:,:,jk,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sye'//'_il'//zchar1//'_htc'//zchar
+            z2d(:,:) = sye(:,:,jk,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxxe'//'_il'//zchar1//'_htc'//zchar
+            z2d(:,:) = sxxe(:,:,jk,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'syye'//'_il'//zchar1//'_htc'//zchar
+            z2d(:,:) = syye(:,:,jk,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            znam = 'sxye'//'_il'//zchar1//'_htc'//zchar
+            z2d(:,:) = sxye(:,:,jk,jl)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+         END DO
+      END DO
+
+      IF( iter == nitrst ) THEN
+         CALL iom_close( numriw )                         ! close the restart file
+         lrst_ice = .FALSE.
+      ENDIF
+      !
+   
+   !+++++++++++ CHECK EVERYTHING ++++++++++
+               WRITE(numout,*)
+               WRITE(numout,*) ' lim_rst_write : CHUKCHI SEA POINT '
+               WRITE(numout,*) ' ~~~~~~~~~~'
+               WRITE(numout,*) ' ~~~ Arctic'
+   
+               ji = jiindex
+               jj = jjindex
+   
+               WRITE(numout,*) ' ji, jj ', ji, jj
+               WRITE(numout,*) ' ICE VARIABLES '
+               WRITE(numout,*) ' open water ', ato_i(ji,jj)
+               DO jl = 1, jpl
+                  WRITE(numout,*) ' *** CATEGORY NUMBER *** ', jl
+                  WRITE(numout,*) ' '
+                  WRITE(numout,*) ' a_i        : ', a_i(ji,jj,jl)     
+                  WRITE(numout,*) ' v_i        : ', v_i(ji,jj,jl) 
+                  WRITE(numout,*) ' v_s        : ', v_s(ji,jj,jl)    
+                  WRITE(numout,*) ' e_s        : ', e_s(ji,jj,1,jl)/1.0e9
+                  WRITE(numout,*) ' e_i1       : ', e_i(ji,jj,1,jl)/1.0e9      
+                  WRITE(numout,*) ' e_i2       : ', e_i(ji,jj,2,jl)/1.0e9      
+                  WRITE(numout,*) ' smv_i      : ', smv_i(ji,jj,jl)  
+                  WRITE(numout,*) ' oa_i       : ', oa_i(ji,jj,jl)
+                  WRITE(numout,*) ' t_su       : ', t_su(ji,jj,jl)
+               END DO
+   
+               WRITE(numout,*) ' MOMENTS OF ADVECTION '
+   
+               WRITE(numout,*) ' open water '
+               WRITE(numout,*) ' sxopw  ', sxopw(ji,jj)
+               WRITE(numout,*) ' syopw  ', syopw(ji,jj)
+               WRITE(numout,*) ' sxxopw ', sxxopw(ji,jj)
+               WRITE(numout,*) ' syyopw ', syyopw(ji,jj)
+               WRITE(numout,*) ' sxyopw ', sxyopw(ji,jj)
+               DO jl = 1, jpl
+                  WRITE(numout,*) ' jl, ice volume content ', jl
+                  WRITE(numout,*) ' sxice  ', sxice(ji,jj,jl)
+                  WRITE(numout,*) ' syice  ', syice(ji,jj,jl)
+                  WRITE(numout,*) ' sxxice ', sxxice(ji,jj,jl)
+                  WRITE(numout,*) ' syyice ', syyice(ji,jj,jl)
+                  WRITE(numout,*) ' sxyice ', sxyice(ji,jj,jl)
+                  WRITE(numout,*) ' jl, snow volume content ', jl
+                  WRITE(numout,*) ' sxsn   ', sxsn(ji,jj,jl)
+                  WRITE(numout,*) ' sysn   ', sysn(ji,jj,jl)
+                  WRITE(numout,*) ' sxxsn  ', sxxsn(ji,jj,jl)
+                  WRITE(numout,*) ' syysn  ', syysn(ji,jj,jl)
+                  WRITE(numout,*) ' sxysn  ', sxysn(ji,jj,jl)
+                  WRITE(numout,*) ' jl, ice area in category ', jl
+                  WRITE(numout,*) ' sxa    ', sxa (ji,jj,jl)
+                  WRITE(numout,*) ' sya    ', sya (ji,jj,jl)
+                  WRITE(numout,*) ' sxxa   ', sxxa (ji,jj,jl)
+                  WRITE(numout,*) ' syya   ', syya (ji,jj,jl)
+                  WRITE(numout,*) ' sxya   ', sxya (ji,jj,jl)
+                  WRITE(numout,*) ' jl, snow temp ', jl
+                  WRITE(numout,*) ' sxc0   ', sxc0(ji,jj,jl)
+                  WRITE(numout,*) ' syc0   ', syc0(ji,jj,jl)
+                  WRITE(numout,*) ' sxxc0  ', sxxc0(ji,jj,jl)
+                  WRITE(numout,*) ' syyc0  ', syyc0(ji,jj,jl)
+                  WRITE(numout,*) ' sxyc0  ', sxyc0(ji,jj,jl)
+                  WRITE(numout,*) ' jl, ice salinity ', jl
+                  WRITE(numout,*) ' sxsal  ', sxsal(ji,jj,jl)
+                  WRITE(numout,*) ' sysal  ', sysal(ji,jj,jl)
+                  WRITE(numout,*) ' sxxsal ', sxxsal(ji,jj,jl)
+                  WRITE(numout,*) ' syysal ', syysal(ji,jj,jl)
+                  WRITE(numout,*) ' sxysal ', sxysal(ji,jj,jl)
+                  WRITE(numout,*) ' jl, ice age      ', jl
+                  WRITE(numout,*) ' sxage  ', sxage(ji,jj,jl)
+                  WRITE(numout,*) ' syage  ', syage(ji,jj,jl)
+                  WRITE(numout,*) ' sxxage ', sxxage(ji,jj,jl)
+                  WRITE(numout,*) ' syyage ', syyage(ji,jj,jl)
+                  WRITE(numout,*) ' sxyage ', sxyage(ji,jj,jl)
+               END DO
+               DO jl = 1, jpl
+                  DO jk = 1, nlay_i
+                     WRITE(numout,*) ' jk, jl, ice heat content', jk, jl
+                     WRITE(numout,*) ' sxe    ', sxe(ji,jj,jk,jl)
+                     WRITE(numout,*) ' sye    ', sye(ji,jj,jk,jl)
+                     WRITE(numout,*) ' sxxe   ', sxxe(ji,jj,jk,jl)
+                     WRITE(numout,*) ' syye   ', syye(ji,jj,jk,jl)
+                     WRITE(numout,*) ' sxye   ', sxye(ji,jj,jk,jl)
+                  END DO
+               END DO
+   
+   !+++++++++++ END CHECK +++++++++++++++++
+   
+      END SUBROUTINE lim_rst_write
+   
+   SUBROUTINE lim_rst_read
+      !!----------------------------------------------------------------------
+      !!                    ***  lim_rst_read  ***
+      !!
+      !! ** purpose  :   read of sea-ice variable restart in a netcdf file
+      !!----------------------------------------------------------------------
+      ! Local variables
+      INTEGER :: ji, jj, jk, jl, index
+      REAL(wp) ::   zfice, ziter
+      REAL(wp) :: & !parameters for the salinity profile
+         zs_inf, z_slope_s, zsmax, zsmin, zalpha, zindb
+      REAL(wp), DIMENSION(nlay_i) :: zs_zero 
+      REAL(wp), DIMENSION(jpi,jpj) :: z2d
+      CHARACTER(len=15) :: znam
+      CHARACTER(len=1) :: zchar, zchar1
+      !!----------------------------------------------------------------------
+   
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_rst_read : read ice NetCDF restart file'
+         WRITE(numout,*) '~~~~~~~~~~~~~~'
+      ENDIF
+
+      CALL iom_open ( 'restart_ice_in', numrir, kiolib = jprstlib )
+
+      CALL iom_get( numrir, 'nfice' , zfice )
+      CALL iom_get( numrir, 'kt_ice', ziter )    
+      IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
+      IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
+
+      !Control of date
+      
+      IF( ( nit000 - INT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
+         &     CALL ctl_stop( 'lim_rst_read ===>>>> : problem with nit000 in ice restart',  &
+         &                   '   verify the file or rerun with the value 0 for the',        &
+         &                   '   control of time parameter  nrstdt' )
+      IF( INT(zfice) /= nfice          .AND. ABS( nrstdt ) == 1 )   &
+         &     CALL ctl_stop( 'lim_rst_read ===>>>> : problem with nfice in ice restart',  &
+         &                   '   verify the file or rerun with the value 0 for the',        &
+         &                   '   control of time parameter  nrstdt' )
+
+      DO jl = 1, jpl 
+         WRITE(zchar,'(I1)') jl
+         znam = 'v_i'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         v_i(:,:,jl) = z2d(:,:)
+         znam = 'v_s'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         v_s(:,:,jl) = z2d(:,:) 
+         znam = 'smv_i'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         smv_i(:,:,jl) = z2d(:,:)
+         znam = 'oa_i'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         oa_i(:,:,jl) = z2d(:,:)
+         znam = 'a_i'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         a_i(:,:,jl) = z2d(:,:)
+         znam = 't_su'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         t_su(:,:,jl) = z2d(:,:)
+      END DO
+
+      ! we first with bulk ice salinity
+      DO jl = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zindb          = MAX( 0.0 , SIGN( 1.0 , v_i(ji,jj,jl) - 1.0e-4 ) ) 
+               sm_i(ji,jj,jl) = smv_i(ji,jj,jl) / MAX(v_i(ji,jj,jl),1.0e-6) * zindb
+               ht_i(ji,jj,jl) = v_i(ji,jj,jl)   / MAX(a_i(ji,jj,jl),1.0e-6) * zindb
+            END DO
+         END DO
+      END DO
+   
+      DO jk = 1, nlay_i
+         s_i(:,:,jk,:) = sm_i(:,:,:)
+      END DO
+   
+      ! Salinity profile
+      !-----------------
+      WRITE(numout,*) ' num_sal - will restart understand salinity profile ', num_sal
+   
+      num_sal = 2
+      IF(num_sal.eq.2) THEN
+   !     CALL lim_var_salprof
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zs_inf        = sm_i(ji,jj,jl)
+                     z_slope_s     = 2.0*sm_i(ji,jj,jl)/MAX(0.01,ht_i(ji,jj,jl))
+                                     !- slope of the salinity profile
+                     zs_zero(jk)   = z_slope_s * ( FLOAT(jk)-1.0/2.0 ) * &
+                                                  ht_i(ji,jj,jl) / FLOAT(nlay_i)
+                     zsmax = 4.5
+                     zsmin = 3.5
+                     IF( sm_i(ji,jj,jl) .LT. zsmin ) THEN
+                        zalpha = 1.0
+                     ELSEIF( sm_i(ji,jj,jl) .LT.zsmax ) THEN
+                        zalpha = sm_i(ji,jj,jl) / (zsmin-zsmax) + zsmax / (zsmax-zsmin)
+                     ELSE
+                        zalpha = 0.0
+                     ENDIF
+                     s_i(ji,jj,jk,jl) = zalpha*zs_zero(jk) + ( 1.0 - zalpha )*zs_inf
+                  END DO
+               END DO
+            END DO
+         END DO
+      ENDIF
+         
+# if defined key_coupled 
+      CALL iom_get( numrir, jpdom_autoglo, 'albege'   , albege )
+# endif
+      DO jl = 1, jpl 
+         WRITE(zchar,'(I1)') jl
+         znam = 'tempt_sl1'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         e_s(:,:,1,jl) = z2d(:,:)
+      END DO
+   
+      DO jl = 1, jpl 
+         WRITE(zchar,'(I1)') jl
+         DO jk = 1, nlay_i 
+            WRITE(zchar1,'(I1)') jk
+            znam = 'tempt'//'_il'//zchar1//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            e_i(:,:,jk,jl) = z2d(:,:)
+         END DO
+      END DO
+
+      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, 'gtaux'     , gtaux      )
+      CALL iom_get( numrir, jpdom_autoglo, 'gtauy'     , gtauy      )
+      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  )
+      CALL iom_get( numrir, jpdom_autoglo, 'stress12_i', stress12_i )
+
+      DO jl = 1, jpl 
+         WRITE(zchar,'(I1)') jl
+         znam = 'sxice'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxice(:,:,jl) = z2d(:,:)
+         znam = 'syice'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         syice(:,:,jl) = z2d(:,:)
+         znam = 'sxxice'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxxice(:,:,jl) = z2d(:,:)
+         znam = 'syyice'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         syyice(:,:,jl) = z2d(:,:)
+         znam = 'sxyice'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxyice(:,:,jl) = z2d(:,:)
+         znam = 'sxsn'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxsn(:,:,jl) = z2d(:,:)
+         znam = 'sysn'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sysn(:,:,jl) = z2d(:,:)
+         znam = 'sxxsn'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxxsn(:,:,jl) = z2d(:,:)
+         znam = 'syysn'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         syysn(:,:,jl) = z2d(:,:)
+         znam = 'sxysn'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxysn(:,:,jl) = z2d(:,:)
+         znam = 'sxa'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxa(:,:,jl) = z2d(:,:)
+         znam = 'sya'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sya(:,:,jl) = z2d(:,:)
+         znam = 'sxxa'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxxa(:,:,jl) = z2d(:,:)
+         znam = 'syya'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         syya(:,:,jl) = z2d(:,:)
+         znam = 'sxya'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxya(:,:,jl) = z2d(:,:)
+         znam = 'sxc0'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxc0(:,:,jl) = z2d(:,:)
+         znam = 'syc0'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         syc0(:,:,jl) = z2d(:,:)
+         znam = 'sxxc0'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxxc0(:,:,jl) = z2d(:,:)
+         znam = 'syyc0'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         syyc0(:,:,jl) = z2d(:,:)
+         znam = 'sxyc0'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxyc0(:,:,jl) = z2d(:,:)
+         znam = 'sxsal'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxsal(:,:,jl) = z2d(:,:)
+         znam = 'sysal'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sysal(:,:,jl) = z2d(:,:)
+         znam = 'sxxsal'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxxsal(:,:,jl) = z2d(:,:)
+         znam = 'syysal'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         syysal(:,:,jl) = z2d(:,:)
+         znam = 'sxysal'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxysal(:,:,jl) = z2d(:,:)
+         znam = 'sxage'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxage(:,:,jl) = z2d(:,:)
+         znam = 'syage'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         syage(:,:,jl) = z2d(:,:)
+         znam = 'sxxage'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxxage(:,:,jl) = z2d(:,:)
+         znam = 'syyage'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         syyage(:,:,jl) = z2d(:,:)
+         znam = 'sxyage'//'_htc'//zchar
+         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+         sxyage(:,:,jl)= z2d(:,:)
+      END DO
+
+      CALL iom_get( numrir, jpdom_autoglo, 'sxopw ' ,  sxopw  )
+      CALL iom_get( numrir, jpdom_autoglo, 'syopw ' ,  syopw  )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxxopw' ,  sxxopw )
+      CALL iom_get( numrir, jpdom_autoglo, 'syyopw' ,  syyopw )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxyopw' ,  sxyopw )
+
+      DO jl = 1, jpl 
+         WRITE(zchar,'(I1)') jl
+         DO jk = 1, nlay_i 
+            WRITE(zchar1,'(I1)') jk
+            znam = 'sxe'//'_il'//zchar1//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxe(:,:,jk,jl) = z2d(:,:)
+            znam = 'sye'//'_il'//zchar1//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sye(:,:,jk,jl) = z2d(:,:)
+            znam = 'sxxe'//'_il'//zchar1//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxxe(:,:,jk,jl) = z2d(:,:)
+            znam = 'syye'//'_il'//zchar1//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            syye(:,:,jk,jl) = z2d(:,:)
+            znam = 'sxye'//'_il'//zchar1//'_htc'//zchar
+            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+            sxye(:,:,jk,jl) = z2d(:,:)
+         END DO
+      END DO
+
+      CALL iom_close( numrir )
+
+   !+++++++++++ CHECK EVERYTHING ++++++++++
+   
+               WRITE(numout,*)
+               WRITE(numout,*) ' lim_rst_read  : CHUKCHI SEA POINT '
+               WRITE(numout,*) ' ~~~~~~~~~~'
+               WRITE(numout,*) ' ~~~ Arctic'
+   
+               index = 1
+               ji = 24
+               jj = 24
+               WRITE(numout,*) ' ji, jj ', ji, jj
+               WRITE(numout,*) ' ICE VARIABLES '
+               WRITE(numout,*) ' open water ', ato_i(ji,jj)
+   
+               DO jl = 1, jpl
+                  WRITE(numout,*) ' *** CATEGORY NUMBER *** ', jl
+                  WRITE(numout,*) ' '
+                  WRITE(numout,*) ' a_i        : ', a_i(ji,jj,jl)     
+                  WRITE(numout,*) ' v_i        : ', v_i(ji,jj,jl) 
+                  WRITE(numout,*) ' v_s        : ', v_s(ji,jj,jl)    
+                  WRITE(numout,*) ' e_i1       : ', e_i(ji,jj,1,jl)/1.0e9      
+                  WRITE(numout,*) ' e_i2       : ', e_i(ji,jj,2,jl)/1.0e9      
+                  WRITE(numout,*) ' e_s        : ', e_s(ji,jj,1,jl)      
+                  WRITE(numout,*) ' smv_i      : ', smv_i(ji,jj,jl)  
+                  WRITE(numout,*) ' oa_i       : ', oa_i(ji,jj,jl)
+                  WRITE(numout,*) ' t_su       : ', t_su(ji,jj,jl)
+               END DO
+   
+               WRITE(numout,*) ' open water '
+               WRITE(numout,*) ' sxopw  ', sxopw(ji,jj)
+               WRITE(numout,*) ' syopw  ', syopw(ji,jj)
+               WRITE(numout,*) ' sxxopw ', sxxopw(ji,jj)
+               WRITE(numout,*) ' syyopw ', syyopw(ji,jj)
+               WRITE(numout,*) ' sxyopw ', sxyopw(ji,jj)
+               DO jl = 1, jpl
+                  WRITE(numout,*) ' jl, ice volume content ', jl
+                  WRITE(numout,*) ' sxice  ', sxice(ji,jj,jl)
+                  WRITE(numout,*) ' syice  ', syice(ji,jj,jl)
+                  WRITE(numout,*) ' sxxice ', sxxice(ji,jj,jl)
+                  WRITE(numout,*) ' syyice ', syyice(ji,jj,jl)
+                  WRITE(numout,*) ' sxyice ', sxyice(ji,jj,jl)
+                  WRITE(numout,*) ' jl, snow volume content ', jl
+                  WRITE(numout,*) ' sxsn   ', sxsn(ji,jj,jl)
+                  WRITE(numout,*) ' sysn   ', sysn(ji,jj,jl)
+                  WRITE(numout,*) ' sxxsn  ', sxxsn(ji,jj,jl)
+                  WRITE(numout,*) ' syysn  ', syysn(ji,jj,jl)
+                  WRITE(numout,*) ' sxysn  ', sxysn(ji,jj,jl)
+                  WRITE(numout,*) ' jl, ice area in category ', jl
+                  WRITE(numout,*) ' sxa    ', sxa (ji,jj,jl)
+                  WRITE(numout,*) ' sya    ', sya (ji,jj,jl)
+                  WRITE(numout,*) ' sxxa   ', sxxa (ji,jj,jl)
+                  WRITE(numout,*) ' syya   ', syya (ji,jj,jl)
+                  WRITE(numout,*) ' sxya   ', sxya (ji,jj,jl)
+                  WRITE(numout,*) ' jl, snow temp ', jl
+                  WRITE(numout,*) ' sxc0   ', sxc0(ji,jj,jl)
+                  WRITE(numout,*) ' syc0   ', syc0(ji,jj,jl)
+                  WRITE(numout,*) ' sxxc0  ', sxxc0(ji,jj,jl)
+                  WRITE(numout,*) ' syyc0  ', syyc0(ji,jj,jl)
+                  WRITE(numout,*) ' sxyc0  ', sxyc0(ji,jj,jl)
+                  WRITE(numout,*) ' jl, ice salinity ', jl
+                  WRITE(numout,*) ' sxsal  ', sxsal(ji,jj,jl)
+                  WRITE(numout,*) ' sysal  ', sysal(ji,jj,jl)
+                  WRITE(numout,*) ' sxxsal ', sxxsal(ji,jj,jl)
+                  WRITE(numout,*) ' syysal ', syysal(ji,jj,jl)
+                  WRITE(numout,*) ' sxysal ', sxysal(ji,jj,jl)
+                  WRITE(numout,*) ' jl, ice age      ', jl
+                  WRITE(numout,*) ' sxage  ', sxage(ji,jj,jl)
+                  WRITE(numout,*) ' syage  ', syage(ji,jj,jl)
+                  WRITE(numout,*) ' sxxage ', sxxage(ji,jj,jl)
+                  WRITE(numout,*) ' syyage ', syyage(ji,jj,jl)
+                  WRITE(numout,*) ' sxyage ', sxyage(ji,jj,jl)
+               END DO
+               DO jl = 1, jpl
+                  DO jk = 1, nlay_i
+                     WRITE(numout,*) ' jk, jl, ice heat content', jk, jl
+                     WRITE(numout,*) ' sxe    ', sxe(ji,jj,jk,jl)
+                     WRITE(numout,*) ' sye    ', sye(ji,jj,jk,jl)
+                     WRITE(numout,*) ' sxxe   ', sxxe(ji,jj,jk,jl)
+                     WRITE(numout,*) ' syye   ', syye(ji,jj,jk,jl)
+                     WRITE(numout,*) ' sxye   ', sxye(ji,jj,jk,jl)
+                  END DO
+               END DO
+   
+   !+++++++++++ END CHECK +++++++++++++++++
+   
+      END SUBROUTINE lim_rst_read
+   
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :       Empty module            NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_rst_read             ! Empty routine
+   END SUBROUTINE lim_rst_read
+   SUBROUTINE lim_rst_write            ! Empty routine
+   END SUBROUTINE lim_rst_write
+#endif
+
+   !!======================================================================
+END MODULE limrst
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limrst_dimg.h90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limrst_dimg.h90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limrst_dimg.h90	(revision 884)
@@ -0,0 +1,304 @@
+   !!----------------------------------------------------------------------
+   !!                     *** limrst_dimg.h90  ***
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limrst_dimg.h90,v 1.2 2005/03/27 18:34:42 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE lim_rst_write( kt )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_rst_write  ***
+      !!
+      !! ** Purpose : Write restart fields for the LIM in mpp.
+      !!    one file per process, in the same manner as the ocean.
+      !!  
+      !! ** Methode : Each nstock time step, save  which are necessary
+      !!      for restart
+      !!      Record #1 hold general information on the state of the run
+      !!      Data fields (either 3D or 2D ) starts ar record #2
+      !!
+      !! History :
+      !!   9.0   : 04-05 (J.M. Molines ) from limrst_fdir.h90
+      !!-----------------------------------------------------------------------
+      !! * Arguments
+      USE par_ice
+      INTEGER, INTENT(in)  ::   kt        ! number of iteration
+
+      !- dummy variables :
+      INTEGER :: ji, jj, jf
+      INTEGER :: inum=61, it0, irecl8, irec
+
+      REAL(wp),DIMENSION(jpi,jpj,35) ::  zmoment
+      REAL(wp),DIMENSION(2)          :: zinfo
+
+      CHARACTER(len=45)  ::   ccfile = 'restart_ice_out', clres
+      !!-----------------------------------------------------------------------
+           
+      !! This routine is called from icestep if it is the right time to use it.
+      !! no additional check is necessary.
+
+       ! 0. Initializations
+       ! ------------------
+
+       IF(lwp) THEN
+          WRITE(numout,*) ' '
+          WRITE(numout,*) ' lim_rst_write: output done in inum = ',   &
+               inum,' at it= ',kt,' date= ',ndastp
+          WRITE(numout,*) ' -------'
+       ENDIF
+
+       ! Open direct access file, with reclength for 2D wp fields
+       irecl8= jpi * jpj * wp
+       WRITE(clres,'(a,".",i3.3)') TRIM(ccfile),narea
+       OPEN(inum,FILE=clres,FORM='UNFORMATTED', ACCESS='DIRECT', RECL=irecl8 )
+
+
+      it0      = kt
+      
+      zinfo(1) = FLOAT( nfice )   ! iteration number
+      zinfo(2) = FLOAT( it0 )        ! time-step in second
+
+      ! Write in inum
+
+      zmoment(:,:,1)  = sxice (:,:)
+      zmoment(:,:,2)  = syice (:,:)
+      zmoment(:,:,3)  = sxxice(:,:)
+      zmoment(:,:,4)  = syyice(:,:)
+      zmoment(:,:,5)  = sxyice(:,:)
+      zmoment(:,:,6)  = sxsn  (:,:)
+      zmoment(:,:,7)  = sysn  (:,:)
+      zmoment(:,:,8)  = sxxsn (:,:)
+      zmoment(:,:,9)  = syysn (:,:)
+      zmoment(:,:,10) = sxysn (:,:)
+      zmoment(:,:,11) = sxa   (:,:)
+      zmoment(:,:,12) = sya   (:,:)
+      zmoment(:,:,13) = sxxa  (:,:)
+      zmoment(:,:,14) = syya  (:,:)
+      zmoment(:,:,15) = sxya  (:,:)
+      zmoment(:,:,16) = sxc0  (:,:)
+      zmoment(:,:,17) = syc0  (:,:)
+      zmoment(:,:,18) = sxxc0 (:,:)
+      zmoment(:,:,19) = syyc0 (:,:)
+      zmoment(:,:,20) = sxyc0 (:,:)
+      zmoment(:,:,21) = sxc1  (:,:)
+      zmoment(:,:,22) = syc1  (:,:)
+      zmoment(:,:,23) = sxxc1 (:,:)
+      zmoment(:,:,24) = syyc1 (:,:)
+      zmoment(:,:,25) = sxyc1 (:,:)
+      zmoment(:,:,26) = sxc2  (:,:)
+      zmoment(:,:,27) = syc2  (:,:)
+      zmoment(:,:,28) = sxxc2 (:,:)
+      zmoment(:,:,29) = syyc2 (:,:)
+      zmoment(:,:,30) = sxyc2 (:,:)
+      zmoment(:,:,31) = sxst  (:,:)
+      zmoment(:,:,32) = syst  (:,:)
+      zmoment(:,:,33) = sxxst (:,:)
+      zmoment(:,:,34) = syyst (:,:)
+      zmoment(:,:,35) = sxyst (:,:)
+
+      WRITE(inum,REC=1) irecl8, nfice, it0, &
+          &              ndastp, adatrj, jpi, jpj, jpk,  &
+          &              jpni, jpnj, jpnij, narea, jpiglo, jpjglo, &
+          &              nlcit, nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt
+
+      irec= 2
+      WRITE(inum,REC=irec)  ht_i(:,:,1)          ! prognostic variables
+      irec = irec + 1
+      WRITE(inum,REC=irec)  ht_s(:,:,1)
+      irec = irec + 1
+      WRITE(inum,REC=irec)  frld(:,:)
+      irec = irec + 1
+!     WRITE(inum,REC=irec)  sist(:,:)
+!     irec = irec + 1
+      WRITE(inum,REC=irec)  t_su(:,:,1)
+      irec = irec + 1
+# if defined key_coupled 
+      WRITE(inum,REC=irec)  albege(:,:)
+      irec = irec + 1
+# endif
+!     DO jf=1, jplayersp1
+!     WRITE(inum,REC=irec)  tbif(:,:,jf)
+!     irec = irec + 1
+!     END DO
+! MV 2005
+      DO jf=1, nlay_s
+      WRITE(inum,REC=irec)  t_s(:,:,jf,1)
+      irec = irec + 1
+      END DO
+! END MV 2005
+! MV 2005
+      DO jf=1, nlay_i 
+      WRITE(inum,REC=irec)  t_i(:,:,jf,1)
+      irec = irec + 1
+      END DO
+! END MV 2005
+      WRITE(inum,REC=irec)  u_ice(:,:)
+      irec = irec + 1
+      WRITE(inum,REC=irec)  v_ice(:,:)
+      irec = irec + 1
+      WRITE(inum,REC=irec)  gtaux(:,:)
+      irec = irec + 1
+      WRITE(inum,REC=irec)  gtauy(:,:)
+      irec = irec + 1
+! MV 2005
+!     WRITE(inum,REC=irec)  qstoif(:,:)
+!     irec = irec + 1
+! END MV 2005
+      WRITE(inum,REC=irec)  fsbbq(:,:)
+      irec = irec + 1
+      DO jf=1,35
+      WRITE(inum,REC=irec)  zmoment(:,:,jf)
+      irec = irec + 1
+      END DO
+ 
+      CLOSE(inum)
+      
+   END SUBROUTINE lim_rst_write
+
+
+   SUBROUTINE lim_rst_read(kt )
+      !!-----------------------------------------------------------------------
+      !!  restart from a state defined in a binary file
+      !!-----------------------------------------------------------------------
+      !! * Arguments
+      USE par_ice
+      INTEGER ,INTENT(out)  ::   kt        ! number of iteration
+
+      !- dummy variables :
+
+      INTEGER :: ji, jj, jf
+      INTEGER :: inum=71, it0, it1, ifice, irecl8, irec
+
+      REAL(wp),DIMENSION(jpi,jpj,35) ::  zmoment
+      REAL(wp),DIMENSION(2) :: zinfo
+
+      CHARACTER(len=45)  ::   ccfile = 'restart_ice_in',clres
+      !!-----------------------------------------------------------------------
+
+      !Initialisations
+
+       ! Open direct access file, with reclength for 2D wp fields
+       WRITE(clres,'(a,".",i3.3)') TRIM(ccfile),narea
+       OPEN(inum,FILE=clres,FORM='UNFORMATTED', ACCESS='DIRECT', RECL=8)
+       READ(inum,REC=1) irecl8
+       CLOSE(inum)
+
+       OPEN(inum,FILE=clres,FORM='UNFORMATTED', ACCESS='DIRECT', RECL=irecl8)
+       READ(inum,REC=1) irecl8, ifice, it1
+      
+
+      !Read inumrst
+
+      it0          = nit000
+
+
+      IF (lwp) THEN
+      WRITE(numout,*)
+      WRITE(numout,*) 'lim_rst_fdir :  READ restart file name ', ccfile, ' at time step : ', it1
+      WRITE(numout,*) '~~~~~~~~~~~~'
+      END IF
+
+
+      !Control of date
+      
+      IF( ( it0 - it1 ) /= 1 .AND. ABS( nrstdt ) == 1 ) THEN
+         IF (lwp) THEN
+         WRITE(numout,cform_err)
+         WRITE(numout,*) ' ===>>>> : problem with nit000 for the restart'
+         WRITE(numout,*) ' we stop. verify the file or rerun with the value  0 for the'
+         WRITE(numout,*) ' control of time parameter  nrstdt'
+         END IF
+         nstop = nstop + 1
+      ENDIF
+
+
+      irec = 2
+      READ(inum,REC=irec)  ht_i(:,:,1)    ! prognostic variables
+      irec = irec +1
+      READ(inum,REC=irec)  ht_s(:,:,1)
+      irec = irec +1
+      READ(inum,REC=irec)  frld(:,:)
+      irec = irec +1
+!     READ(inum,REC=irec)  sist(:,:)
+!     irec = irec +1
+!RB bug
+      READ(inum,REC=irec)  t_su(:,:)
+      irec = irec +1
+# if defined key_coupled
+      READ(inum,REC=irec)  albege(:,:)
+      irec = irec +1
+# endif
+!     DO jf = 1, jplayersp1
+!     READ(inum,REC=irec)  tbif(:,:,jf)
+!     irec = irec +1
+!     END DO
+! MV 2005
+      DO jf = 1, nlay_s 
+      READ(inum,REC=irec)  t_s(:,:,jf,1)
+      irec = irec +1
+      END DO
+      DO jf = 1, nlay_i 
+      READ(inum,REC=irec)  t_i(:,:,jf)
+      irec = irec +1
+      END DO
+! MV 2005
+      READ(inum,REC=irec)  u_ice(:,:)
+      irec = irec +1
+      READ(inum,REC=irec)  v_ice(:,:)
+      irec = irec +1
+      READ(inum,REC=irec)  gtaux(:,:)
+      irec = irec +1
+      READ(inum,REC=irec)  gtauy(:,:)
+      irec = irec +1
+! MV 2005
+!     READ(inum,REC=irec)  qstoif(:,:)
+!     irec = irec +1
+! END MV 2005
+      READ(inum,REC=irec)  fsbbq(:,:)
+      irec = irec +1
+      DO jf = 1, 35
+      READ(inum,REC=irec)  zmoment(:,:,jf)
+      irec = irec +1
+      END DO
+ 
+      CLOSE(inum)
+
+      kt = it1
+            sxice(:,:)  = zmoment(:,:,1)
+            syice(:,:)  = zmoment(:,:,2)
+            sxxice(:,:) = zmoment(:,:,3)
+            syyice(:,:) = zmoment(:,:,4)
+            sxyice(:,:) = zmoment(:,:,5)
+            sxsn(:,:)   = zmoment(:,:,6)
+            sysn(:,:)   = zmoment(:,:,7)
+            sxxsn(:,:)  = zmoment(:,:,8)
+            syysn(:,:)  = zmoment(:,:,9)
+            sxysn(:,:)  = zmoment(:,:,10)
+            sxa(:,:)    = zmoment(:,:,11)
+            sya(:,:)    = zmoment(:,:,12)
+            sxxa(:,:)   = zmoment(:,:,13)
+            syya(:,:)   = zmoment(:,:,14)
+            sxya(:,:)   = zmoment(:,:,15)
+            sxc0(:,:)   = zmoment(:,:,16)
+            syc0(:,:)   = zmoment(:,:,17)
+            sxxc0(:,:)  = zmoment(:,:,18)
+            syyc0(:,:)  = zmoment(:,:,19)
+            sxyc0(:,:)  = zmoment(:,:,20)
+            sxc1(:,:)   = zmoment(:,:,21)
+            syc1(:,:)   = zmoment(:,:,22)
+            sxxc1(:,:)  = zmoment(:,:,23)
+            syyc1(:,:)  = zmoment(:,:,24)
+            sxyc1(:,:)  = zmoment(:,:,25)
+            sxc2(:,:)   = zmoment(:,:,26)
+            syc2(:,:)   = zmoment(:,:,27)
+            sxxc2(:,:)  = zmoment(:,:,28)
+            syyc2(:,:)  = zmoment(:,:,29)
+            sxyc2(:,:)  = zmoment(:,:,30)
+            sxst(:,:)   = zmoment(:,:,31)
+            syst(:,:)   = zmoment(:,:,32)
+            sxxst(:,:)  = zmoment(:,:,33)
+            syyst(:,:)  = zmoment(:,:,34)
+            sxyst(:,:)  = zmoment(:,:,35)
+      
+   END SUBROUTINE lim_rst_read
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limtab.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limtab.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limtab.F90	(revision 884)
@@ -0,0 +1,82 @@
+MODULE limtab
+   !!======================================================================
+   !!                       ***  MODULE limtab   ***
+   !!              transform 1D (2D) array to a 2D (1D) table
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   tab_2d_1d  : 2-D to 1-D
+   !!   tab_1d_2d  : 1-D to 2-D
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC tab_2d_1d  ! called by lim_ther
+   PUBLIC tab_1d_2d  ! called by lim_ther
+
+   !!----------------------------------------------------------------------
+   !!   LIM 3.0,  UCL-ASTR-LOCEAN-IPSL (2008) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limtab.F90,v 1.2 2005/03/27 18:34:42 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE tab_2d_1d ( ndim1d, tab1d, tab2d, ndim2d_x, ndim2d_y, tab_ind )
+
+      INTEGER, INTENT(in) :: &
+         ndim1d, ndim2d_x, ndim2d_y
+
+      REAL(wp), DIMENSION (ndim2d_x, ndim2d_y), INTENT(in) ::  &
+         tab2d
+
+      INTEGER, DIMENSION ( ndim1d), INTENT ( in) :: &
+         tab_ind
+
+      REAL(wp), DIMENSION(ndim1d), INTENT ( out) ::  & 
+         tab1d
+
+      INTEGER ::  &
+         jn , jid, jjd
+        
+      DO jn = 1, ndim1d
+         jid        = MOD( tab_ind(jn) - 1, ndim2d_x ) + 1
+         jjd        = ( tab_ind(jn) - 1 ) / ndim2d_x + 1
+         tab1d( jn) = tab2d( jid, jjd)
+      END DO 
+
+   END SUBROUTINE tab_2d_1d
+
+
+   SUBROUTINE tab_1d_2d ( ndim1d, tab2d, tab_ind, tab1d, ndim2d_x, ndim2d_y )
+
+      INTEGER, INTENT ( in) :: &
+         ndim1d, ndim2d_x, ndim2d_y
+
+      INTEGER, DIMENSION (ndim1d) , INTENT (in) :: &
+         tab_ind
+
+      REAL(wp), DIMENSION(ndim1d), INTENT (in) ::  &
+         tab1d  
+
+      REAL(wp), DIMENSION (ndim2d_x, ndim2d_y), INTENT ( out) :: &
+         tab2d
+
+      INTEGER :: &
+         jn, jid, jjd
+
+      DO jn = 1, ndim1d
+         jid             = MOD( tab_ind(jn) - 1, ndim2d_x) + 1
+         jjd             =    ( tab_ind(jn) - 1 ) / ndim2d_x  + 1
+         tab2d(jid, jjd) = tab1d( jn)
+      END DO
+
+   END SUBROUTINE tab_1d_2d
+
+#endif
+END MODULE limtab
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd.F90	(revision 884)
@@ -0,0 +1,1017 @@
+MODULE limthd
+   !!======================================================================
+   !!                  ***  MODULE limthd   ***
+   !!              LIM thermo ice model : ice thermodynamic
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_thd      : thermodynamic of sea ice
+   !!   lim_thd_init : initialisation of sea-ice thermodynamic
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE phycst          ! physical constants
+   USE dom_oce         ! ocean space and time domain variables
+   USE lbclnk
+   USE in_out_manager  ! I/O manager
+   USE ice             ! LIM sea-ice variables
+   USE ice_oce         ! sea-ice/ocean variables
+   USE flx_oce         ! sea-ice/ocean forcings variables 
+   USE thd_ice         ! LIM thermodynamic sea-ice variables
+   USE dom_ice         ! LIM sea-ice domain
+   USE iceini
+   USE limthd_dif
+   USE limthd_dh
+   USE limthd_sal
+   USE limthd_ent
+   USE limtab
+   USE par_ice
+   USE limvar
+   USE prtctl          ! Print control
+   USE lib_mpp
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_thd         ! called by lim_step
+
+  !! * Module variables
+     REAL(wp)  ::            &  ! constant values
+         epsi20 = 1e-20   ,  &
+         epsi16 = 1e-16   ,  &
+         epsi06 = 1e-06   ,  &
+         epsi04 = 1e-04   ,  &
+         zzero  = 0.e0     , &
+         zone   = 1.e0
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limthd.F90,v 1.6 2005/03/27 18:34:42 opalod Exp $
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_thd
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE lim_thd  ***       
+      !!  
+      !! ** Purpose : This routine manages the ice thermodynamic.
+      !!         
+      !! ** Action : - Initialisation of some variables
+      !!             - Some preliminary computation (oceanic heat flux
+      !!               at the ice base, snow acc.,heat budget of the leads)
+      !!             - selection of the icy points and put them in an array
+      !!             - call lim_vert_ther for vert ice thermodynamic
+      !!             - back to the geographic grid
+      !!             - selection of points for lateral accretion
+      !!             - call lim_lat_acc  for the ice accretion
+      !!             - back to the geographic grid
+      !!     
+      !! ** References :
+      !!       H. Goosse et al. 1996, Bul. Soc. Roy. Sc. Liege, 65, 87-90
+      !!
+      !! History :
+      !!   1.0  !  00-01 (M.A. Morales Maqueda, H. Goosse, T. Fichefet)
+      !!   2.0  !  02-07 (C. Ethe, G. Madec) F90
+      !!   3.0  !  05-11 (M. Vancoppenolle ) Multi-layer thermodynamics, 
+      !!                                     salinity variations
+      !!---------------------------------------------------------------------
+      !! * Local variables
+      INTEGER  ::  ji, jj, jk, jl,  &
+                   zji  , zjj,      &   ! dummy loop indices
+                   nbpb ,           &   ! nb of icy pts for thermo. cal.
+                   index
+
+      REAL(wp) ::  &
+         zfric_umin = 5e-03 ,  &   ! lower bound for the friction velocity
+         zfric_umax = 2e-02        ! upper bound for the friction velocity
+      
+      REAL(wp) ::   &
+         zinda              ,  &   ! switch for test. the val. of concen.
+         zindb,                &   ! switches for test. the val of arg
+         zthsnice           ,  &
+         zfric_u            ,  &   ! friction velocity 
+         zfnsol             ,  &   ! total non solar heat
+         zfontn             ,  &   ! heat flux from snow thickness
+         zfntlat, zpareff   ,  &   ! test. the val. of lead heat budget
+         zeps
+
+      REAL(wp) ::   &
+         zareamin
+         
+      REAL(wp), DIMENSION(jpi,jpj) :: &
+         zhicifp            ,  &   ! ice thickness for outputs
+         zqlbsbq                   ! link with lead energy budget qldif
+
+      !!-------------------------------------------------------------------
+
+      IF( numit == nstart  )   CALL lim_thd_init  ! Initialization (first time-step only)
+
+      WRITE(numout,*) 'limthd : Ice Thermodynamics'
+      WRITE(numout,*) '~~~~~~'
+
+      IF( numit == nstart  )   CALL lim_thd_sal_init  ! Initialization (first time-step only)
+!------------------------------------------------------------------------------!
+! 1) Initialization of diagnostic variables                                    !
+!------------------------------------------------------------------------------!
+      zeps = 1.0e-10
+      tatm_ice(:,:) = tatm_ice(:,:) + 273.15 ! convert C to K
+
+      !--------------------
+      ! 1.2) Heat content    
+      !--------------------
+      ! Change the units of heat content; from global units to 
+      ! J.m3
+
+      DO jl = 1, jpl
+        DO jk = 1, nlay_i
+          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) , epsi06 ) * nlay_i
+               !0 if no ice and 1 if yes
+               zindb            = 1.0 - MAX ( 0.0 , SIGN ( 1.0 , - ht_i(ji,jj,jl) ) ) 
+               !convert units ! very important that this line is here
+               e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * unit_fac * zindb 
+            END DO
+          END DO
+        END DO
+      END DO
+
+      DO jl = 1, jpl
+        DO jk = 1, nlay_s
+          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) , epsi06 ) * nlay_s
+               !0 if no ice and 1 if yes
+               zindb            = 1.0 - MAX ( 0.0 , SIGN ( 1.0 , - ht_s(ji,jj,jl) ) ) 
+               !convert units ! very important that this line is here
+               e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * unit_fac * zindb 
+            END DO
+          END DO
+        END DO
+      END DO
+
+      !-----------------------------
+      ! 1.3) Set some dummies to 0
+      !-----------------------------
+      rdvosif(:,:) = 0.e0   ! variation of ice volume at surface
+      rdvobif(:,:) = 0.e0   ! variation of ice volume at bottom
+      fdvolif(:,:) = 0.e0   ! total variation of ice volume
+      rdvonif(:,:) = 0.e0   ! lateral variation of ice volume
+      fstric (:,:) = 0.e0   ! part of solar radiation transmitted through the ice
+      ffltbif(:,:) = 0.e0   ! linked with fstric
+      qfvbq  (:,:) = 0.e0   ! linked with fstric
+      rdmsnif(:,:) = 0.e0   ! variation of snow mass per unit area
+      rdmicif(:,:) = 0.e0   ! variation of ice mass per unit area
+      hicifp (:,:) = 0.e0   ! daily thermodynamic ice production. 
+      fsbri  (:,:) = 0.e0   ! brine flux contribution to salt flux to the ocean
+      fhbri  (:,:) = 0.e0   ! brine flux contribution to heat flux to the ocean
+      fseqv  (:,:) = 0.e0   ! equivalent salt flux to the ocean due to ice/growth decay
+
+      !-----------------------------------
+      ! 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.      !
+!-----------------------------------------------------------------------------!
+
+!     !CDIR NOVERRCHK
+         DO jj = 1, jpj
+!        !CDIR NOVERRCHK
+            DO ji = 1, jpi
+            zthsnice       = SUM( ht_s(ji,jj,1:jpl) ) + SUM( ht_i(ji,jj,1:jpl) )
+            zindb          = tms(ji,jj) * ( 1.0 - MAX( zzero , SIGN( zone , - zthsnice ) ) ) 
+            phicif(ji,jj)  = vt_i(ji,jj)
+            pfrld(ji,jj)   = 1.0 - at_i(ji,jj)
+            zinda          = 1.0 - MAX( zzero , SIGN( zone , - ( 1.0 - pfrld(ji,jj) ) ) )
+            
+!           !  solar irradiance transmission at the mixed layer bottom and used in the lead heat budget
+!           !  practically no "direct lateral ablation"
+!           
+!           !  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)  = zindb * rau0 * rcp * 0.006  * zfric_u * ( sst_io(ji,jj) - t_bo(ji,jj) ) 
+            ! also category dependent
+!           !-- Energy from the turbulent oceanic heat flux heat flux coming in the lead 
+            qdtcn(ji,jj)  = zindb * fdtcn(ji,jj) * (1.0 - at_i(ji,jj)) * rdt_ice
+!                       
+
+! still need to be updated : fdtcn !!!!
+!           !-- Lead heat budget (part 1, next one is in limthd_dh
+!           !-- qldif -- (or qldif_1d in 1d routines)
+            zfontn         = sprecip(ji,jj) * lfus              !   energy of melting
+            zfnsol         = qnsr_oce(ji,jj)  !  total non solar flux
+            qldif(ji,jj)   = tms(ji,jj) * ( qsr_oce(ji,jj)                          &
+               &                               + zfnsol + fdtcn(ji,jj) - zfontn     &
+               &                               + ( 1.0 - zindb ) * fsbbq(ji,jj) )   &
+               &                               * ( 1.0 - at_i(ji,jj) ) * rdt_ice    
+
+            ! 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 ) / &
+                             MAX( at_i(ji,jj) * rdt_ice , epsi16 )
+
+            ! 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(ji,jj,1) * ( t_bo(ji,jj) - sst_io(ji,jj) ) * ( 1. - zinda )
+
+            !  calculate oceanic heat flux (limthd_dh)
+            fbif   (ji,jj) = zindb * (  fsbbq(ji,jj) / MAX( at_i(ji,jj) , epsi20 ) + fdtcn(ji,jj) )
+            
+            ! computation of the daily thermodynamic ice production (only needed for output)
+            zhicifp(ji,jj) = ht_i(ji,jj,1) * at_i(ji,jj) 
+            zhicifp(ji,jj) = ht_i(ji,jj,1) * at_i(ji,jj)
+         END DO
+      END DO
+
+!------------------------------------------------------------------------------!
+! 3) Select icy points and fulfill arrays for the vectorial grid.            
+!------------------------------------------------------------------------------!
+
+      DO jl = 1, jpl      !loop over ice categories
+
+         WRITE(numout,*) ' lim_thd : transfer to 1D vectors. Category no : ', jl 
+         WRITE(numout,*) ' ~~~~~~~~'
+
+         zareamin = 1.0e-10
+         nbpb = 0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF ( a_i(ji,jj,jl) .gt. zareamin ) THEN     
+                  nbpb      = nbpb  + 1
+                  npb(nbpb) = (jj - 1) * jpi + ji
+               ENDIF
+               ! debug point to follow
+               IF ( (ji.eq.jiindex).AND.(jj.eq.jjindex) ) THEN
+                   jiindex_1d = nbpb
+               ENDIF
+            END DO
+         END DO
+
+!------------------------------------------------------------------------------!
+! 4) Thermodynamic computation
+!------------------------------------------------------------------------------!
+
+         IF( lk_mpp ) CALL mpp_ini_ice(nbpb)
+
+         IF (nbpb > 0) THEN  ! If there is no ice, do nothing.
+
+         !-------------------------
+         ! 4.1 Move to 1D arrays
+         !-------------------------
+
+            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) )
+            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) )
+            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) )
+            END DO
+
+            CALL tab_2d_1d( nbpb, tatm_ice_1d(1:nbpb)     , tatm_ice(:,:)   , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, qsr_ice_1d (1:nbpb)     , qsr_ice(:,:,jl) , jpi, jpj, npb(1:nbpb) )
+            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)     , qnsr_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, 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, 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, rdmicif_1d (1:nbpb)     , rdmicif    , 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, fseqv_1d   (1:nbpb)     , fseqv      , jpi, jpj, npb(1:nbpb) )
+            CALL tab_2d_1d( nbpb, fsbri_1d   (1:nbpb)     , fsbri      , 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) )
+
+         !--------------------------------
+         ! 4.3) Thermodynamic processes
+         !--------------------------------
+            
+            IF ( con_i ) CALL lim_thd_enmelt(1,nbpb)   ! computes sea ice energy of melting
+            IF ( con_i ) 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 ) CALL lim_thd_glohec( qt_i_fin , qt_s_fin ,           &
+                                              q_i_layer_fin , 1 , nbpb , jl ) 
+            IF ( con_i ) 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,jl)   ! Ice salinity computation        !
+                                          !---------------------------------!
+
+!           CALL lim_thd_enmelt(1,nbpb)   ! computes sea ice energy of melting
+            IF ( con_i ) CALL lim_thd_glohec( qt_i_fin, qt_s_fin,             &
+                                              q_i_layer_fin , 1 , nbpb , jl ) 
+            IF ( con_i ) CALL lim_thd_con_dh ( 1 , nbpb , jl )
+
+         !--------------------------------
+         ! 4.4) Move 1D to 2D vectors
+         !--------------------------------
+
+            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 )
+
+            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)
+            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, rdmicif    , npb, rdmicif_1d(1:nbpb)     , jpi, jpj )
+            CALL tab_1d_2d( nbpb, dmgwi      , npb, dmgwi_1d  (1:nbpb)     , jpi, jpj )
+            CALL tab_1d_2d( nbpb, rdmsnif    , npb, rdmsnif_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, fseqv      , npb, fseqv_1d  (1:nbpb)     , jpi, jpj )
+
+            IF ( num_sal .EQ. 2 ) THEN
+               CALL tab_1d_2d( nbpb, fsbri      , npb, fsbri_1d  (1:nbpb)     , jpi, jpj )
+               CALL tab_1d_2d( nbpb, fhbri      , npb, fhbri_1d  (1:nbpb)     , jpi, jpj )
+            ENDIF
+
+            !+++++
+            !temporary stuff for a dummyversion
+            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, qnsr_ice(:,:,jl), npb, qnsr_ice_1d(1:nbpb), jpi, jpj)
+            !+++++
+
+         IF( lk_mpp ) CALL mpp_comm_free(ncomm_ice) !RB necessary ??
+         ENDIF ! nbpb
+
+      END DO ! jl
+
+!------------------------------------------------------------------------------!
+! 5) Global variables, diagnostics
+!------------------------------------------------------------------------------!
+
+      !------------------------
+      ! 5.1) Ice heat content              
+      !------------------------
+
+      ! Enthalpies are global variables we have to readjust the units
+      DO jl = 1, jpl
+      DO jk = 1, nlay_i
+         DO jj = 1, jpj
+         DO ji = 1, jpi
+            ! Change dimensions
+            e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) / unit_fac
+
+            ! Multiply by volume, divide by nlayers so that heat content in 10^9 Joules
+            e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * &
+                               area(ji,jj) * a_i(ji,jj,jl) * &
+                               ht_i(ji,jj,jl) / nlay_i
+         END DO !ji
+         END DO !jj
+      END DO !jk
+      END DO !jl
+
+      !------------------------
+      ! 5.2) Snow heat content              
+      !------------------------
+
+      ! Enthalpies are global variables we have to readjust the units
+      DO jl = 1, jpl
+         DO jk = 1, nlay_s
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ! 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
+                  e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * area(ji,jj) * &
+                                     a_i(ji,jj,jl) * ht_s(ji,jj,jl)  / nlay_s
+               END DO !ji
+            END DO !jj
+         END DO !jk
+      END DO !jl
+
+      !----------------------------------
+      ! 5.3) Change thickness to volume
+      !----------------------------------
+      CALL lim_var_eqv2glo
+
+      !--------------------------------------------
+      ! 5.4) Diagnostic thermodynamic growth rates
+      !--------------------------------------------
+      d_v_i_thd (:,:,:)   = v_i(:,:,:)   - old_v_i(:,:,:)    ! ice volumes 
+      dv_dt_thd(:,:,:)    = d_v_i_thd(:,:,:) / rdt_ice * 86400.0
+
+      IF ( con_i ) fbif(:,:) = fbif(:,:) + zqlbsbq(:,:)
+
+      IF(ln_ctl) THEN   ! Control print
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Cell values : ')
+         CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
+         CALL prt_ctl(tab2d_1=area , clinfo1=' lim_thd  : cell area :')
+         CALL prt_ctl(tab2d_1=at_i , clinfo1=' lim_thd  : at_i      :')
+         CALL prt_ctl(tab2d_1=vt_i , clinfo1=' lim_thd  : vt_i      :')
+         CALL prt_ctl(tab2d_1=vt_s , clinfo1=' lim_thd  : vt_s      :')
+         DO jl = 1, jpl
+            CALL prt_ctl_info(' ')
+            CALL prt_ctl_info(' - Category : ', ivar1=jl)
+            CALL prt_ctl_info('   ~~~~~~~~~~')
+            CALL prt_ctl(tab2d_1=a_i   (:,:,jl)   , clinfo1= ' lim_thd  : a_i      : ')
+            CALL prt_ctl(tab2d_1=ht_i  (:,:,jl)   , clinfo1= ' lim_thd  : ht_i     : ')
+            CALL prt_ctl(tab2d_1=ht_s  (:,:,jl)   , clinfo1= ' lim_thd  : ht_s     : ')
+            CALL prt_ctl(tab2d_1=v_i   (:,:,jl)   , clinfo1= ' lim_thd  : v_i      : ')
+            CALL prt_ctl(tab2d_1=v_s   (:,:,jl)   , clinfo1= ' lim_thd  : v_s      : ')
+            CALL prt_ctl(tab2d_1=e_s   (:,:,1,jl) , clinfo1= ' lim_thd  : e_s      : ')
+            CALL prt_ctl(tab2d_1=t_su  (:,:,jl)   , clinfo1= ' lim_thd  : t_su     : ')
+            CALL prt_ctl(tab2d_1=t_s   (:,:,1,jl) , clinfo1= ' lim_thd  : t_snow   : ')
+            CALL prt_ctl(tab2d_1=sm_i  (:,:,jl)   , clinfo1= ' lim_thd  : sm_i     : ')
+            CALL prt_ctl(tab2d_1=smv_i (:,:,jl)   , clinfo1= ' lim_thd  : smv_i    : ')
+            DO jk = 1, nlay_i
+               CALL prt_ctl_info(' ')
+               CALL prt_ctl_info(' - Layer : ', ivar1=jk)
+               CALL prt_ctl_info('   ~~~~~~~')
+               CALL prt_ctl(tab2d_1=t_i(:,:,jk,jl) , clinfo1= ' lim_thd  : t_i      : ')
+               CALL prt_ctl(tab2d_1=e_i(:,:,jk,jl) , clinfo1= ' lim_thd  : e_i      : ')
+            END DO
+         END DO
+
+      ENDIF
+
+   END SUBROUTINE lim_thd
+
+!===============================================================================
+
+   SUBROUTINE lim_thd_glohec(eti,ets,etilayer,kideb,kiut,jl)
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE lim_thd_glohec *** 
+      !!                 
+      !! ** Purpose :  Compute total heat content for each category
+      !!               Works with 1d vectors only
+      !!
+      !! history :
+      !!  9.9  ! 07-04 (M.Vancoppenolle) original code
+      !!-----------------------------------------------------------------------
+      !! * Local variables
+      INTEGER, INTENT(in) :: &
+         kideb, kiut,        &  ! bounds for the spatial loop
+         jl                     ! category number
+
+      REAL(wp), DIMENSION (jpij,jpl), INTENT(out) ::  &
+         eti, ets            ! vertically-summed heat content for ice /snow
+
+      REAL(wp), DIMENSION (jpij,jkmax), INTENT(out) ::  &
+         etilayer            ! heat content for ice layers
+
+      REAL(wp) :: &
+         zdes,    &          ! snow heat content increment (dummy)
+         zeps                ! very small value (1.e-10)
+
+      INTEGER  :: &
+         ji,jj,jk            ! loop indices
+
+      !!-----------------------------------------------------------------------
+      eti(:,:) = 0.0
+      ets(:,:) = 0.0
+      zeps     = 1.0e-10
+
+      ! total q over all layers, ice [J.m-2]
+      DO jk = 1, nlay_i
+         DO ji = kideb, kiut
+            etilayer(ji,jk) = q_i_b(ji,jk) &
+                            * ht_i_b(ji) / nlay_i
+            eti(ji,jl) = eti(ji,jl) + etilayer(ji,jk) 
+         END DO
+      END DO
+
+      ! total q over all layers, snow [J.m-2]
+      DO ji = kideb, kiut
+         zdes = q_s_b(ji,1) * ht_s_b(ji) / nlay_s 
+         ets(ji,jl) = ets(ji,jl) + zdes        
+      END DO
+
+      WRITE(numout,*) ' lim_thd_glohec '
+      WRITE(numout,*) ' qt_i_in : ', eti(jiindex_1d,jl) / rdt_ice
+      WRITE(numout,*) ' qt_s_in : ', ets(jiindex_1d,jl) / rdt_ice
+      WRITE(numout,*) ' qt_in   : ', ( eti(jiindex_1d,jl) +         &
+                                     ets(jiindex_1d,jl) ) / rdt_ice
+
+   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
+      !!
+      !! history :
+      !!  9.9  ! 07-04 (M.Vancoppenolle) original code
+      !!-------------------------------------------------------------------
+      !! * Local variables
+      INTEGER, INTENT(in) ::        &
+         kideb, kiut,               &  !: bounds for the spatial loop
+         jl                            !: category number
+
+      REAL(wp)                 ::   &  !: ! goes to trash
+         meance,                    &  !: mean conservation error
+         max_cons_err,              &  !: maximum tolerated conservation error
+         max_surf_err                  !: maximum tolerated surface error
+
+      INTEGER ::                    &
+         numce                         !: number of points for which conservation
+                                       !  is violated
+      INTEGER  :: &
+         ji,jj,jk,                  &  !: loop indices
+         zji, zjj
+      !!---------------------------------------------------------------------
+
+      max_cons_err =  1.0
+      max_surf_err =  0.001
+            
+      !--------------------------
+      ! 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
+          zji                 = MOD( npb(ji) - 1, jpi ) + 1
+          zjj                 = ( npb(ji) - 1 ) / jpi + 1
+
+          fatm(ji,jl) = &
+          qnsr_ice_1d(ji)                  + & ! atm non solar
+          (1.0-i0(ji))*qsr_ice_1d(ji)          ! atm solar
+
+          sum_fluxq(ji,jl) = fc_su(ji) - fc_bo_i(ji) + qsr_ice_1d(ji)*i0(ji) &
+                           - fstroc(zji,zjj,jl)
+      END DO
+
+      !--------------------
+      ! Conservation error
+      !--------------------
+
+      DO ji = kideb, kiut
+          cons_error(ji,jl) = ABS( dq_i(ji,jl) / rdt_ice + sum_fluxq(ji,jl) )
+      END DO
+
+      numce = 0
+      meance = 0.0
+      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 .GT. 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.0
+      meance = 0.0
+
+      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 .GT. 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
+
+      IF (jiindex_1D.GT.0) WRITE(numout,*) ' fc_su      : ', fc_su(jiindex_1d)
+      IF (jiindex_1D.GT.0) WRITE(numout,*) ' fatm       : ', fatm(jiindex_1d,jl)
+      IF (jiindex_1D.GT.0) 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
+         zji                 = MOD( npb(ji) - 1, jpi ) + 1
+         zjj                 = ( 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,*) ' zji , zjj  : ', zji, zjj
+         WRITE(numout,*) ' lat, lon   : ', gphit(zji,zjj), glamt(zji,zjj)
+         WRITE(numout,*) ' cons_error : ', cons_error(ji,jl)
+         WRITE(numout,*) ' surf_error : ', surf_error(ji,jl)
+         WRITE(numout,*) ' dq_i       : ', - dq_i(ji,jl) / rdt_ice
+         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   (zji,zjj,jl)
+         WRITE(numout,*) ' i0        : ', i0(ji)
+         WRITE(numout,*) ' fsolar     : ', (1.0-i0(ji))*qsr_ice_1d(ji)
+         WRITE(numout,*) ' fnsolar    : ', 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) )  & 
+                                                 / rdt_ice
+         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) / rdt_ice  
+            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.
+      !!
+      !! history :
+      !!  9.9  ! 07-04 (M.Vancoppenolle) original code
+      !!-----------------------------------------------------------------------
+      !! * Local variables
+      INTEGER, INTENT(in) ::        &
+         kideb, kiut,               &  !: bounds for the spatial loop
+         jl                            !: category number
+
+      REAL(wp)                 ::   &  !: ! goes to trash
+         meance,                    &  !: mean conservation error
+         max_cons_err                  !: maximum tolerated conservation error
+
+      INTEGER ::                    &
+         numce                         !: number of points for which conservation
+                                       !  is violated
+      INTEGER  :: &
+         ji,jj,jk,                  &  !: loop indices
+         zji, zjj
+
+      !!---------------------------------------------------------------------
+
+      max_cons_err = 1.0
+            
+      !--------------------------
+      ! 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
+          zji                 = MOD( npb(ji) - 1, jpi ) + 1
+          zjj                 = ( npb(ji) - 1 ) / jpi + 1
+
+          fatm(ji,jl) = &
+          qnsr_ice_1d(ji)                  + & ! atm non solar
+!         (1.0-i0(ji))*qsr_ice_1d(ji)          ! atm solar
+          qsr_ice_1d(ji)                       ! atm solar
+
+          sum_fluxq(ji,jl)     = fatm(ji,jl) + fbif_1d(ji) - ftotal_fin(ji) & 
+                               - fstroc(zji,zjj,jl) 
+          cons_error(ji,jl)   = ABS( dq_i(ji,jl) / rdt_ice + sum_fluxq(ji,jl) )
+      END DO
+
+      !--------------------
+      ! Conservation error
+      !--------------------
+
+      DO ji = kideb, kiut
+          cons_error(ji,jl) = ABS( dq_i(ji,jl) / rdt_ice + sum_fluxq(ji,jl) )
+      END DO
+
+      numce = 0
+      meance = 0.0
+      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 .GT. 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
+         zji                 = MOD( npb(ji) - 1, jpi ) + 1
+         zjj                 = ( npb(ji) - 1 ) / jpi + 1
+
+         WRITE(numout,*) ' alerte 1 - category : ', jl
+         WRITE(numout,*) ' Untolerated conservation error after limthd_ent '
+         WRITE(numout,*) ' zji , zjj  : ', zji, zjj
+         WRITE(numout,*) ' lat, lon   : ', gphit(zji,zjj), glamt(zji,zjj)
+         WRITE(numout,*) ' * '
+         WRITE(numout,*) ' Ftotal     : ', sum_fluxq(ji,jl)
+         WRITE(numout,*) ' dq_t       : ', - dq_i(ji,jl) / rdt_ice
+         WRITE(numout,*) ' dq_i       : ', - ( qt_i_fin(ji,jl) - qt_i_in(ji,jl) ) / rdt_ice
+         WRITE(numout,*) ' dq_s       : ', - ( qt_s_fin(ji,jl) - qt_s_in(ji,jl) ) / rdt_ice
+         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(zji,zjj,jl)
+         WRITE(numout,*) ' * '
+         WRITE(numout,*) ' Heat contents --- : '
+         WRITE(numout,*) ' qt_s_in    : ', qt_s_in(ji,jl) / rdt_ice
+         WRITE(numout,*) ' qt_i_in    : ', qt_i_in(ji,jl) / rdt_ice
+         WRITE(numout,*) ' qt_in      : ', ( qt_i_in(ji,jl) + &
+                                           qt_s_in(ji,jl) ) / rdt_ice
+         WRITE(numout,*) ' qt_s_fin   : ', qt_s_fin(ji,jl) / rdt_ice
+         WRITE(numout,*) ' qt_i_fin   : ', qt_i_fin(ji,jl) / rdt_ice
+         WRITE(numout,*) ' qt_fin     : ', ( qt_i_fin(ji,jl) + &
+                                           qt_s_fin(ji,jl) ) / rdt_ice
+         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)
+      !!
+      !! ** Method  :   Formula (Bitz and Lipscomb, 1999)
+      !!
+      !! history : Martin Vancoppenolle, May 2007
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT(in) ::        &
+         kideb, kiut                   !: bounds for the spatial loop
+         
+      REAL(wp)                 ::   &  !: goes to trash
+         ztmelts               ,    &  !: sea ice freezing point in K
+         zeps 
+
+      INTEGER             ::        &
+         ji,                        &  !: spatial loop index
+         jk                            !: vertical index
+
+      !!-------------------------------------------------------------------
+      zeps = 1.0e-10
+
+      ! Sea ice energy of melting
+      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),-zeps) )  &
+                         - rcp      * ( ztmelts-rtt  ) ) 
+         END DO !ji
+      END DO !jk
+
+      ! Snow energy of melting
+      DO jk = 1, nlay_s
+         DO ji = kideb,kiut
+            q_s_b(ji,jk) = rhosn * ( cpic * ( rtt - t_s_b(ji,jk) ) + lfus )
+         END DO !ji
+      END DO !jk
+
+   END SUBROUTINE lim_thd_enmelt
+
+!==============================================================================
+
+   SUBROUTINE lim_thd_init
+
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE lim_thd_init *** 
+      !!                 
+      !! ** Purpose :   Physical constants and parameters linked to the ice 
+      !!      thermodynamics
+      !!
+      !! ** Method  :   Read the namicethd namelist and check the ice-thermo
+      !!       parameter values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namicether
+      !!
+      !! history :
+      !!  8.5  ! 03-08 (C. Ethe) original code
+      !!-------------------------------------------------------------------
+      NAMELIST/namicethd/ hmelt , hiccrit, fraz_swi, maxfrazb, vfrazb, Cfrazb, &
+         &                hicmin, hiclim, amax  ,    &
+         &                sbeta  , parlat, hakspl, hibspl, exld,  &
+         &                hakdif, hnzst  , thth  , parsub, alphs, betas, & 
+         &                kappa_i, nconv_i_thd, maxer_i_thd, thcon_i_swi
+      !!-------------------------------------------------------------------
+      
+      ! Define the initial parameters
+      ! -------------------------
+      REWIND( numnam_ice )
+      READ  ( numnam_ice , namicethd )
+      IF (lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*)'lim_thd_init : ice parameters for ice thermodynamic computation '
+         WRITE(numout,*)'~~~~~~~~~~~~'
+         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,*)'   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,*)'   maximum lead fraction                                   amax         = ', amax 
+         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
+         WRITE(numout,*)'   maximal n. of iter. for heat diffusion computation      nconv_i_thd  = ', nconv_i_thd
+         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,*)
+      ENDIF
+            
+      rcdsn = hakdif * rcdsn 
+      rcdic = hakdif * rcdic
+      
+
+   END SUBROUTINE lim_thd_init
+
+#else
+   !!======================================================================
+   !!                       ***  MODULE limthd   ***
+   !!                        No sea ice model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE lim_thd         ! Empty routine
+   END SUBROUTINE lim_thd
+   SUBROUTINE lim_thd_con_dif
+   END SUBROUTINE lim_thd_con_dif
+#endif
+
+   !!======================================================================
+END MODULE limthd
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_dh.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 884)
@@ -0,0 +1,833 @@
+MODULE limthd_dh
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!======================================================================
+   !!                       ***  MODULE limthd_dh ***
+   !!                thermodynamic growth and decay of the ice 
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   lim_thd_dh  : vertical accr./abl. and lateral ablation of sea ice
+   !! * Modules used
+
+   USE par_oce          ! ocean parameters
+   USE phycst           ! physical constants (OCE directory) 
+   USE ice_oce          ! ice variables
+   USE thd_ice
+   USE iceini
+   USE limistate
+   USE in_out_manager
+   USE ice
+   USE par_ice
+   USE lib_mpp
+      
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_thd_dh        ! called by lim_thd
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      epsi20 = 1e-20   ,  &
+      epsi13 = 1e-13   ,  &
+      epsi16 = 1e-16   ,  &
+      zzero  = 0.e0    ,  &
+      zone   = 1.e0
+
+   !!----------------------------------------------------------------------
+   !!   LIM 3.0,  UCL-ASTR-LOCEAN-IPSL (2008)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_thd_dh(kideb,kiut,jl)
+       !!------------------------------------------------------------------
+       !!                ***  ROUTINE lim_thd_dh  ***
+       !!------------------------------------------------------------------
+       !! ** Purpose :
+       !!           This routine determines variations of ice and snow thicknesses.
+       !! ** Method  :
+       !!           Ice/Snow surface melting arises from imbalance in surface fluxes
+       !!           Bottom accretion/ablation arises from flux budget
+       !!           Snow thickness can increase by precipitation and decrease by 
+       !!              sublimation
+       !!           If snow load excesses Archmiede limit, snow-ice is formed by
+       !!              the flooding of sea-water in the snow
+       !! ** Steps  
+       !!           1) Compute available flux of heat for surface ablation
+       !!           2) Compute snow and sea ice enthalpies
+       !!           3) Surface ablation and sublimation
+       !!           4) Bottom accretion/ablation
+       !!           5) Case of Total ablation
+       !!           6) Snow ice formation
+       !!
+       !! ** Arguments
+       !!
+       !! ** Inputs / Outputs
+       !!
+       !! ** External
+       !!
+       !! ** References : Bitz and Lipscomb, JGR 99
+       !!                 Fichefet T. and M. Maqueda 1997, J. Geophys. Res., 102(C6), 12609-12646   
+       !!                 Vancoppenolle, Fichefet and Bitz, GRL 2005
+       !!                 Vancoppenolle et al., OM08
+       !!
+       !! ** History  : 
+       !!   original code    01-04 (LIM)
+       !!   original routine
+       !!               (05-2003) M. Vancoppenolle, Louvain-La-Neuve, Belgium
+       !!               (06/07-2005) 3D version
+       !!               (03-2008)    Clean code
+       !!
+       !!------------------------------------------------------------------
+       !! * Arguments
+       INTEGER , INTENT (IN) ::  &
+          kideb     ,         &  !: Start point on which the  the computation is applied
+          kiut      ,         &  !: End point on which the  the computation is applied
+          jl                     !: Thickness cateogry number
+
+       !! * Local variables
+       INTEGER ::             & 
+          ji        ,         &  !: space index 
+          jk        ,         &  !: ice layer index
+          isnow     ,         &  !: switch for presence (1) or absence (0) of snow
+          zji       ,         &  !: 2D corresponding indices to ji
+          zjj       ,         &
+          isnowic   ,         &  !: snow ice formation not
+          i_ice_switch   ,    &  !: ice thickness above a certain treshold or not
+          iter
+
+       REAL(wp) ::            &
+          zhsnew    ,         &  !: new snow thickness
+          zihgnew   ,         &  !: switch for total ablation
+          ztmelts   ,         &  !: melting point
+          zhn       ,         &
+          zdhcf     ,         &
+          zdhbf     ,         &
+          zhni      ,         &
+          zhnfi     ,         &
+          zihg      ,         &
+          zdhnm     ,         &
+          zhnnew    ,         &
+          zeps = 1.0e-13,     &
+          zhisn     ,         &
+          zfracs    ,         &  !: fractionation coefficient for bottom salt
+                                 !: entrapment
+          zds       ,         &  !: increment of bottom ice salinity
+          zcoeff    ,         &  !: dummy argument for snowfall partitioning
+                                 !: over ice and leads
+          zsm_snowice,        &  !: snow-ice salinity
+          zswi1     ,         &  !: switch for computation of bottom salinity
+          zswi12    ,         &  !: switch for computation of bottom salinity
+          zswi2     ,         &  !: switch for computation of bottom salinity
+          zgrr      ,         &  !: bottom growth rate
+          zihic     ,         &  !: 
+          ztform                 !: bottom formation temperature
+
+       REAL(wp) , DIMENSION(jpij) ::  &
+          zh_i      ,         &  ! ice layer thickness
+          zh_s      ,         &  ! snow layer thickness
+          ztfs      ,         &  ! melting point
+          zhsold    ,         &  ! old snow thickness
+          zqprec    ,         &  !: energy of fallen snow
+          zqfont_su ,         &  ! incoming, remaining surface energy
+          zqfont_bo              ! incoming, bottom energy
+
+       REAL(wp) , DIMENSION(jpij) :: &
+          z_f_surf,           &  ! surface heat for ablation
+          zhgnew                 ! new ice thickness
+
+       REAL(wp), DIMENSION(jpij) :: &
+          zdh_s_mel  ,        &  ! snow melt 
+          zdh_s_pre  ,        &  ! snow precipitation 
+          zdh_s_sub  ,        &  ! snow sublimation
+          zfsalt_melt            ! salt flux due to ice melt
+
+       REAL(wp) , DIMENSION(jpij,jkmax) :: &
+          zdeltah
+
+       ! Pathological cases
+       REAL(wp), DIMENSION(jpij) :: &
+          zfdt_init  ,        &  !: total incoming heat for ice melt
+          zfdt_final ,        &  !: total remaing heat for ice melt
+          zqt_i      ,        &  !: total ice heat content
+          zqt_s      ,        &  !: total snow heat content
+          zqt_dummy              !: dummy heat content
+
+       REAL(wp), DIMENSION(jpij,jkmax) :: &
+          zqt_i_lay              !: total ice heat content
+
+       ! Heat conservation 
+       REAL(wp), DIMENSION(jpij) :: &
+          zfbase,             &
+          zdq_i
+
+       INTEGER, DIMENSION(jpij) ::  &
+          innermelt
+
+       REAL(wp) :: &
+          meance_dh
+
+       INTEGER ::                   &
+          num_iter_max,       &
+          numce_dh
+
+!!-----------------------------------------------------------------------------
+
+      WRITE(numout,*) 'lim_thd_dh : computation of vertical snow/ice accretion/ablation'
+      WRITE(numout,*) '~~~~~~~~~'
+
+      zfsalt_melt(:)  = 0.0
+      ftotal_fin(:)   = 0.0
+      zfdt_init(:)    = 0.0
+      zfdt_final(:)   = 0.0
+
+      DO ji = kideb, kiut
+         old_ht_i_b(ji) = ht_i_b(ji)
+         old_ht_s_b(ji) = ht_s_b(ji)
+      END DO
+!
+!------------------------------------------------------------------------------!
+!  1) Calculate available heat for surface 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.0
+      zqfont_bo(:) = 0.0
+      dsm_i_se_1d(:) = 0.0     
+      dsm_i_si_1d(:) = 0.0     
+!
+!------------------------------------------------------------------------------!
+!  2) Computing layer thicknesses and  snow and sea-ice enthalpies.            !
+!------------------------------------------------------------------------------!
+!
+      ! Layer thickness
+      DO ji = kideb,kiut
+         zh_i(ji) = ht_i_b(ji) / nlay_i
+         zh_s(ji) = ht_s_b(ji) / nlay_s
+      END DO
+
+      ! Total enthalpy of the snow
+      zqt_s(:) = 0.0
+      DO jk = 1, nlay_s
+         DO ji = kideb,kiut
+            zqt_s(ji)    =  zqt_s(ji) + q_s_b(ji,jk) * ht_s_b(ji) / nlay_s
+         END DO
+      END DO
+
+      ! Total enthalpy of the ice
+      zqt_i(:) = 0.0
+      DO jk = 1, nlay_i
+         DO ji = kideb,kiut
+            zqt_i(ji)        =  zqt_i(ji) + q_i_b(ji,jk) * ht_i_b(ji) / nlay_i
+            zqt_i_lay(ji,jk) =  q_i_b(ji,jk) * ht_i_b(ji) / nlay_i
+         END DO
+      END DO
+!
+!------------------------------------------------------------------------------|
+!  3) Surface ablation and sublimation                                         |
+!------------------------------------------------------------------------------|
+!
+      !-------------------------
+      ! 3.1 Snow precips / melt
+      !-------------------------
+      ! Snow accumulation in one thermodynamic time step
+      ! snowfall is partitionned between leads and ice
+      ! if snow fall was uniform, a fraction (1-at_i) would fall into leads
+      ! but because of the winds, more snow falls on leads than on sea ice
+      ! and a greater fraction (1-at_i)^beta of the total mass of snow 
+      ! (beta < 1) falls in leads.
+      ! In reality, beta depends on wind speed, 
+      ! and should decrease with increasing wind speed but here, it is 
+      ! considered as a constant. an average value is 0.66
+      ! Martin Vancoppenolle, December 2006
+
+      ! Snow fall
+      DO ji = kideb, kiut
+         zcoeff = ( 1.0 - ( 1.0 - at_i_b(ji) )**betas ) / at_i_b(ji) 
+         zdh_s_pre(ji) = zcoeff * sprecip_1d(ji) * rdt_ice / rhosn
+      END DO
+      zdh_s_mel(:) =  0.0
+
+      ! 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.0 , - zqfont_su(ji) / MAX( zqprec(ji) , epsi13 ) )
+         zqfont_su(ji)  =  MAX( 0.0 , - 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)
+      END DO
+
+      ! Update total snow heat content
+      zqt_s(ji)         =  MAX ( zqt_s(ji) - zqfont_su(ji) , 0.0 ) 
+      IF( lk_mpp ) CALL mpp_max(zqt_s(ji), kcom = ncomm_ice ) 
+
+      ! Snow melt due to surface heat imbalance
+      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    
+         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 )
+         ! Volume and mass variations of snow
+         dvsbq_1d(ji)   =  a_i_b(ji) * ( ht_s_b(ji) - zhsold(ji)              &
+                        - zdh_s_mel(ji) )
+         dvsbq_1d(ji)   =  MIN( zzero, dvsbq_1d(ji) )
+         rdmsnif_1d(ji) =  rhosn*dvsbq_1d(ji)
+      END DO ! ji
+
+      !--------------------------
+      ! 3.2 Surface ice ablation 
+      !--------------------------
+      DO ji = kideb, kiut 
+         dh_i_surf(ji) =  0.0
+         ! For heat conservation test
+         z_f_surf(ji)  =  zqfont_su(ji) / rdt_ice ! heat conservation test
+         zdq_i(ji)     =  0.0
+      END DO ! ji
+
+      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) / rdt_ice
+            ! contribution to ice-ocean salt flux 
+            zji                 = MOD( npb(ji) - 1, jpi ) + 1
+            zjj                 = ( npb(ji) - 1 ) / jpi + 1
+            zfsalt_melt(ji)     = zfsalt_melt(ji) +                           &
+                                  ( sss_io(zji,zjj) - sm_i_b(ji)   ) *        &
+                                  a_i_b(ji) *                                 &
+                                  MIN( zdeltah(ji,jk) , 0.0 ) * rhoic / rdt_ice 
+         END DO ! ji
+      END DO ! jk
+
+      !-------------------
+      ! Conservation test
+      !-------------------
+      IF ( con_i ) THEN
+      numce_dh = 0
+      meance_dh = 0.0
+      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,*) ' zji, zjj, jl :', zji, zjj, 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_io  : ', sss_io(zji,zjj)
+         ENDIF
+
+      END DO ! ji
+
+      IF ( numce_dh .GT. 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 ! con_i
+
+      !----------------------
+      ! 3.3 Snow sublimation
+      !----------------------
+
+      DO ji = kideb, kiut
+         ! if qla is positive (upwards), heat goes to the atmosphere, therefore
+         ! snow sublimates, if qla is negative (downwards), snow condensates
+         zdh_s_sub(ji)   =  - parsub * qla_ice_1d(ji) / ( rhosn * lsub ) * rdt_ice
+         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  !ji
+
+      zqt_dummy(:) = 0.0
+      DO jk = 1, nlay_s
+         DO ji = kideb,kiut
+            q_s_b(ji,jk) = rhosn * ( cpic * ( rtt - t_s_b(ji,jk) ) + lfus )
+            ! heat conservation
+            zqt_dummy(ji)    =  zqt_dummy(ji) + q_s_b(ji,jk) * ht_s_b(ji) / nlay_s
+         END DO
+      END DO
+
+      DO jk = 1, nlay_s !n 
+         DO ji = kideb, kiut !n
+         ! 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
+      END DO 
+
+!
+!------------------------------------------------------------------------------!
+! 4) Basal growth / melt                                                       !
+!------------------------------------------------------------------------------!
+!
+      ! 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 .NE. 2 ) .AND. ( num_sal .NE. 4 ) ) THEN
+         DO ji = kideb, kiut
+            IF (  ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) .LT. 0.0  ) 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) 
+            ENDIF ! heat budget
+         END DO ! ji
+      ENDIF ! num_sal
+
+      !-------------------------------------------------
+      ! 4.1 Basal growth - (b) salinity varying in time 
+      !-------------------------------------------------
+      IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) 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) ) .LT. 0.0  ) THEN
+                  zji = MOD( npb(ji) - 1, jpi ) + 1
+                  zjj = ( 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) / rdt_ice , zeps ) )
+                  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 ) ) 
+                  zds         = zfracs*sss_io(zji,zjj) - s_i_new(ji)
+                  s_i_new(ji) = zfracs * sss_io(zji,zjj)
+               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 15 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
+               dsm_i_se_1d(ji) =  ( s_i_new(ji)*dh_i_bott(ji) +              & 
+                                   sm_i_b(ji)*ht_i_b(ji) ) /                 & 
+                                   MAX( ht_i_b(ji) + dh_i_bott(ji) ,zeps )   &
+                                   - sm_i_b(ji)
+            ENDIF ! heat budget
+         END DO ! ji
+      ENDIF ! num_sal
+
+      !----------------
+      ! 4.2 Basal melt
+      !----------------
+      meance_dh = 0.0
+      numce_dh = 0
+      innermelt(:) = 0
+
+      DO ji = kideb, kiut
+         ! heat convergence at the surface > 0
+         IF (  ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) .GE. 0.0  ) 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) / rdt_ice ! heat conservation test
+            zdq_i(ji)     =  0.0
+
+            dh_i_bott(ji) =  0.0
+         ENDIF
+      END DO
+
+      DO jk = nlay_i, 1, -1
+         DO ji = kideb, kiut
+            IF (  ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) .GE. 0.0  ) THEN
+               ztmelts             =   - tmut * s_i_b(ji,jk) + rtt 
+               IF ( t_i_b(ji,jk) .GE. ztmelts ) THEN
+                  zdeltah(ji,jk)  = - zh_i(ji)
+                  dh_i_bott(ji)   = dh_i_bott(ji) + zdeltah(ji,jk)
+                  innermelt(ji)   = 1
+               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) / rdt_ice
+               ! contribution to salt flux
+                  zji             = MOD( npb(ji) - 1, jpi ) + 1
+                  zjj             = ( npb(ji) - 1 ) / jpi + 1
+                  zfsalt_melt(ji) = zfsalt_melt(ji) +                         &
+                                   ( sss_io(zji,zjj) - sm_i_b(ji)   ) *       &
+                                   a_i_b(ji) * &
+                                   MIN( zdeltah(ji,jk) , 0.0 ) * rhoic / rdt_ice 
+               ENDIF
+            ENDIF
+         END DO ! ji
+      END DO ! jk
+
+      !-------------------
+      ! Conservation test
+      !-------------------
+      IF ( con_i ) THEN
+      DO ji = kideb, kiut
+         IF (  ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) .GE. 0.0  ) THEN
+            IF ( ( zfbase(ji) + zdq_i(ji) ) .GE. 1.0e-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 '
+                WRITE(numout,*) ' zji, zjj, jl :', zji, zjj, 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_io  : ', sss_io(zji,zjj)
+                WRITE(numout,*) ' dh_i_bott : ', dh_i_bott(ji)
+                WRITE(numout,*) ' innermelt : ', innermelt(ji)
+            ENDIF
+         ENDIF ! heat convergence at the surface
+      END DO ! ji
+
+      IF ( numce_dh .GT. 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 ! con_i
+
+!
+!------------------------------------------------------------------------------!
+!  5) Pathological cases                                                       !
+!------------------------------------------------------------------------------!
+!
+      !----------------------------------------------
+      ! 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)
+         zdhbf = dh_i_bott(ji) 
+         IF (jpl.EQ.1) zdhbf = MAX( hmelt , dh_i_bott(ji) )
+         ! excessive energy is sent to lateral ablation
+         fsup(ji)            =  rhoic*lfus * at_i_b(ji) / MAX( ( 1.0 - at_i_b(ji) ),epsi13) &
+                             *  ( zdhbf - dh_i_bott(ji) ) / rdt_ice
+
+         dh_i_bott(ji)  = zdhbf
+         !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)
+         !new ice thickness
+         zhgnew(ji)     = ht_i_b(ji) + dh_i_surf(ji) + dh_i_bott(ji)
+
+         ! diagnostic ( bottom ice growth )
+         zji                 = MOD( npb(ji) - 1, jpi ) + 1
+         zjj                 = ( npb(ji) - 1 ) / jpi + 1
+         diag_bot_gr(zji,zjj) = diag_bot_gr(zji,zjj) + MAX(dh_i_bott(ji),0.0)*a_i_b(ji) &
+                              / rdt_ice
+         diag_sur_me(zji,zjj) = diag_sur_me(zji,zjj) + MIN(dh_i_surf(ji),0.0)*a_i_b(ji) &
+                              / rdt_ice
+         diag_bot_me(zji,zjj) = diag_bot_me(zji,zjj) + MIN(dh_i_bott(ji),0.0)*a_i_b(ji) &
+                              / rdt_ice
+      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
+         !--------------------------------------------------
+         zihgnew    =  1.0 - MAX( zzero , SIGN( zone , - zhgnew(ji) ) ) !1 if ice
+         ! 0 if no more ice
+         zhgnew(ji) =  zihgnew * zhgnew(ji) ! ice thickness is put to 0
+         ! 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
+         zqt_s(ji)  =  ( 1. - zihg) * zqt_s(ji) / MAX( zhni, zeps )
+         zdhnm      =  - ( 1. - zihg ) * ( 1. - zihgnew ) * ( zfdt_final(ji) /  &
+                           MAX( zqt_s(ji) , zeps ) )
+         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)
+
+         ! Mass variations of ice and snow
+         !---------------------------------
+         rdmicif_1d(ji) =  rdmicif_1d(ji) + a_i_b(ji) *                        &
+                           (zhgnew(ji)-ht_i_b(ji))*rhoic ! good
+
+         rdmsnif_1d(ji) =  rdmsnif_1d(ji) + a_i_b(ji) * &
+                           (ht_s_b(ji)-zhni)*rhosn ! good too
+
+         ! Remaining heat to the ocean 
+         !---------------------------------
+         ! focea is in W.m-2 * dt
+         focea(ji)  = - zfdt_final(ji) / rdt_ice
+
+      END DO
+
+      ftotal_fin (:) = zfdt_final(:)  / rdt_ice
+
+      !---------------------------
+      ! Salt flux and heat fluxes                    
+      !---------------------------
+      DO ji = kideb, kiut
+         zihgnew    =  1.0 - MAX( zzero , SIGN( zone , - zhgnew(ji) ) ) !1 if ice
+
+         ! Salt flux
+         zji           = MOD( npb(ji) - 1, jpi ) + 1
+         zjj           = ( npb(ji) - 1 ) / jpi + 1
+         IF ( num_sal .NE. 4 ) &
+         fseqv_1d(ji)  = fseqv_1d(ji) + zihgnew * zfsalt_melt(ji) +           &
+                          (1.0 - zihgnew) * rdmicif_1d(ji) *                  &
+                          ( sss_io(zji,zjj) - sm_i_b(ji) ) / rdt_ice
+         ! new lines
+         IF ( num_sal .EQ. 4 ) &
+         fseqv_1d(ji)  = fseqv_1d(ji) + zihgnew * zfsalt_melt(ji) +           &
+                          (1.0 - zihgnew) * rdmicif_1d(ji) *                  &
+                          ( sss_io(zji,zjj) - bulk_sal ) / rdt_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
+!
+!------------------------------------------------------------------------------|
+!  6) Snow-Ice formation                                                       |
+!------------------------------------------------------------------------------|
+!
+      ! When snow load excesses Archimede's limit, snow-ice interface goes down
+      ! under sea-level, flooding of seawater transforms snow into ice
+      ! dh_snowice is positive for the ice
+      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
+
+#if defined key_lim_fdd 
+!(presently Activated) 
+         rdmicif_1d(ji) = rdmicif_1d(ji) + a_i_b(ji) & 
+                                         * ( zhgnew(ji) - ht_i_b(ji) )*rhoic 
+         rdmsnif_1d(ji) = rdmsnif_1d(ji) + a_i_b(ji) & 
+                                         * ( zhnnew       - ht_s_b(ji) )*rhosn
+
+!        Equivalent salt flux (1) Snow-ice formation component
+!        -----------------------------------------------------
+         zji                 = MOD( npb(ji) - 1, jpi ) + 1
+         zjj                 = ( npb(ji) - 1 ) / jpi + 1
+
+         zsm_snowice  = ( rhoic - rhosn ) / rhoic *            &
+                        sss_io(zji,zjj) 
+
+         IF ( num_sal .NE. 2 ) zsm_snowice = sm_i_b(ji)
+
+         IF ( num_sal .NE. 4 ) &
+         fseqv_1d(ji)   = fseqv_1d(ji)   + &
+                          ( sss_io(zji,zjj) - zsm_snowice ) * &
+                            a_i_b(ji)   * &
+                          ( zhgnew(ji) - ht_i_b(ji) ) * rhoic / rdt_ice
+         ! new lines
+         IF ( num_sal .EQ. 4 ) &
+         fseqv_1d(ji)   = fseqv_1d(ji)   + &
+                          ( sss_io(zji,zjj) - bulk_sal    ) * &
+                            a_i_b(ji)   * &
+                          ( zhgnew(ji) - ht_i_b(ji) ) * rhoic / rdt_ice
+
+         ! entrapment during snow ice formation
+         i_ice_switch = 1.0 - MAX ( 0.0 , SIGN ( 1.0 , - ht_i_b(ji) + 1.0e-6 ) )
+         isnowic      = 1.0 - MAX ( 0.0 , SIGN ( 1.0 , - dh_snowice(ji) ) ) * &
+                        i_ice_switch
+         IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) &
+             dsm_i_si_1d(ji)  = ( zsm_snowice*dh_snowice(ji) &
+                            + sm_i_b(ji) * ht_i_b(ji)                          & 
+                            / MAX( ht_i_b(ji) + dh_snowice(ji), zeps)          &
+                            - sm_i_b(ji) ) * isnowic     
+
+#else
+         rdmicif_1d(ji) = rdmicif_1d(ji) + a_i_b(ji) &
+                                         * ( zhgnew(ji) - ht_i_b(ji) ) * rhoic &
+                                         + ( zhnnew - ht_s_b(ji) ) * rhosn )
+#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).LE.0.0 ) a_i_b(ji) = 0.0
+
+         ! diagnostic ( snow ice growth )
+         zji                 = MOD( npb(ji) - 1, jpi ) + 1
+         zjj                 = ( npb(ji) - 1 ) / jpi + 1
+         diag_sni_gr(zji,zjj)  = diag_sni_gr(zji,zjj) + dh_snowice(ji)*a_i_b(ji) / &
+                                 rdt_ice
+
+      END DO !ji
+
+    END SUBROUTINE lim_thd_dh
+#else
+   !!======================================================================
+   !!                       ***  MODULE limthd_dh   ***
+   !!                              no sea ice model  
+   !!======================================================================
+CONTAINS
+   SUBROUTINE lim_thd_dh          ! Empty routine
+   END SUBROUTINE lim_thd_dh
+#endif
+ END MODULE limthd_dh
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_dif.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_dif.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_dif.F90	(revision 884)
@@ -0,0 +1,878 @@
+MODULE limthd_dif
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!======================================================================
+   !!                       ***  MODULE limthd_dif ***
+   !!                       heat diffusion in sea ice 
+   !!                   computation of surface and inner T  
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce          ! ocean parameters
+   USE phycst           ! physical constants (ocean directory) 
+   USE ice_oce          ! ice variables
+   USE thd_ice
+   USE iceini
+   USE limistate
+   USE in_out_manager
+   USE ice
+   USE par_ice
+   USE lib_mpp 
+ 
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_thd_dif        ! called by lim_thd
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      epsi20 = 1e-20   ,  &
+      epsi13 = 1e-13   ,  &
+      zzero  = 0.e0    ,  &
+      zone   = 1.e0
+
+   !!----------------------------------------------------------------------
+   !!   LIM 3.0,  UCL-ASTR-LOCEAN-IPSL (2008)
+   !!   (c) UCL-ASTR and Martin Vancoppenolle
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_thd_dif( kideb , kiut , jl )
+        !!------------------------------------------------------------------
+        !!                ***  ROUTINE lim_thd_dif  ***
+        !! ** Purpose :
+        !!           This routine determines the time evolution of snow and sea-ice 
+        !!           temperature profiles.
+        !! ** Method  :
+        !!           This is done by solving the heat equation diffusion with
+        !!           a Neumann boundary condition at the surface and a Dirichlet one
+        !!           at the bottom. Solar radiation is partially absorbed into the ice.
+        !!           The specific heat and thermal conductivities depend on ice salinity
+        !!           and temperature to take into account brine pocket melting. The 
+        !!           numerical
+        !!           scheme is an iterative Crank-Nicolson on a non-uniform multilayer grid 
+        !!           in the ice and snow system.
+        !!
+        !!           The successive steps of this routine are
+        !!           1.  Thermal conductivity at the interfaces of the ice layers
+        !!           2.  Internal absorbed radiation
+        !!           3.  Scale factors due to non-uniform grid
+        !!           4.  Kappa factors
+        !!           Then iterative procedure begins
+        !!           5.  specific heat in the ice
+        !!           6.  eta factors
+        !!           7.  surface flux computation
+        !!           8.  tridiagonal system terms
+        !!           9.  solving the tridiagonal system with Gauss elimination
+        !!           Iterative procedure ends according to a criterion on evolution
+        !!           of temperature
+        !!
+        !! ** Arguments :
+        !!           kideb , kiut : Starting and ending points on which the 
+        !!                         the computation is applied
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !!           surface temperature : t_su_b
+        !!           ice/snow temperatures   : t_i_b, t_s_b
+        !!           ice salinities          : s_i_b
+        !!           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
+        !!
+        !! ** External : 
+        !!
+        !! ** References :
+        !!
+        !! ** History :
+        !!           (02-2003) Martin Vancoppenolle, Louvain-la-Neuve, Belgium
+        !!           (06-2005) Martin Vancoppenolle, 3d version
+        !!           (11-2006) Vectorized by Xavier Fettweis (UCL-ASTR)
+        !!           (04-2007) Energy conservation tested by M. Vancoppenolle
+        !!
+        !!------------------------------------------------------------------
+        !! * Arguments
+
+       INTEGER , INTENT (in) ::  &
+          kideb ,  &  ! Start point on which the  the computation is applied
+          kiut  ,  &  ! End point on which the  the computation is applied
+          jl          ! Category number
+
+       !! * Local variables
+       INTEGER ::   ji,       &   ! spatial loop index
+                    zji, zjj, &   ! temporary dummy loop index
+                    numeq,    &   ! current reference number of equation
+                    layer,    &   ! vertical dummy loop index 
+                    nconv,    &   ! number of iterations in iterative procedure
+                    minnumeqmin, & !
+                    maxnumeqmax
+
+       INTEGER , DIMENSION(jpij) :: &
+                    numeqmin, &   ! reference number of top equation
+                    numeqmax, &   ! reference number of bottom equation
+                    isnow         ! switch for presence (1) or absence (0) of snow
+
+       !! * New local variables       
+       REAL(wp) , DIMENSION(jpij,0:nlay_i) ::    &
+          ztcond_i,    & !Ice thermal conductivity
+          zradtr_i,    & !Radiation transmitted through the ice
+          zradab_i,    & !Radiation absorbed in the ice
+          zkappa_i       !Kappa factor in the ice
+
+       REAL(wp) , DIMENSION(jpij,0:nlay_s) ::    &
+          zradtr_s,    & !Radiation transmited through the snow
+          zradab_s,    & !Radiation absorbed in the snow
+          zkappa_s       !Kappa factor in the snow
+       
+       REAL(wp) , DIMENSION(jpij,0:nlay_i) :: &
+          ztiold,      & !Old temperature in the ice
+          zeta_i,      & !Eta factor in the ice 
+          ztitemp,     & !Temporary temperature in the ice to check the convergence
+          zspeche_i,   & !Ice specific heat
+          z_i            !Vertical cotes of the layers in the ice
+
+       REAL(wp) , DIMENSION(jpij,0:nlay_s) :: &
+          zeta_s,      & !Eta factor in the snow
+          ztstemp,     & !Temporary temperature in the snow to check the convergence
+          ztsold,      & !Temporary temperature in the snow
+          z_s            !Vertical cotes of the layers in the snow
+
+       REAL(wp) , DIMENSION(jpij,jkmax+2) ::    &
+          zindterm,    & ! Independent term
+          zindtbis,    & ! temporary independent term
+          zdiagbis
+
+       REAL(wp) , DIMENSION(jpij,jkmax+2,3) ::  &
+          ztrid          ! tridiagonal system terms
+          
+       REAL(wp), DIMENSION(jpij) ::  &
+          ztfs     ,   & ! ice melting point
+          ztsuold  ,   & ! old surface temperature (before the iterative
+                         !          procedure )
+          ztsuoldit,   & ! surface temperature at previous iteration
+          zh_i     ,   & !ice layer thickness
+          zh_s     ,   & !snow layer thickness
+          zfsw     ,   & !solar radiation absorbed at the surface
+          zf       ,   & ! surface flux function
+          dzf            ! derivative of the surface flux function
+
+       REAL(wp)  ::           &  ! constant values
+          zeps      =  1.0e-10,   & !
+          zg1s      =  2.0,       & !: for the tridiagonal system
+          zg1       =  2.0,       &
+          zgamma    =  18009.0,   & !: for specific heat
+          zbeta     =  0.117,     & !: for thermal conductivity (could be 0.13)
+          zraext_s  =  1.0e08,    & !: extinction coefficient of radiation in the snow
+          zkimin    =  0.10 ,     & !: minimum ice thermal conductivity
+          zht_smin  =  1.0e-4       !: minimum snow depth
+
+        REAL(wp)  ::          &  ! local variables 
+          ztmelt_i,           &  ! ice melting temperature
+          zerritmax              ! current maximal error on temperature 
+
+        REAL(wp), DIMENSION(jpij)  :: &
+          zerrit,             &  ! current error on temperature 
+          zdifcase,           &  ! case of the equation resolution (1->4)
+          zftrice,            &  ! solar radiation transmitted through the ice
+          zihic, zhsu
+
+!!-- End of declarations
+!!----------------------------------------------------------------------------------------------
+
+       IF(lwp) WRITE(numout,*)'lim_thd_dif : Heat diffusion in sea ice for cat :', jl
+
+!
+!------------------------------------------------------------------------------!
+! 1) Initialization                                                            !
+!------------------------------------------------------------------------------!
+!
+       DO ji = kideb , kiut
+          ! is there snow or not
+          isnow(ji)= INT ( 1.0 - MAX( 0.0 , SIGN (1.0, - ht_s_b(ji) ) ) )
+          ! surface temperature of fusion
+          ztfs(ji) = isnow(ji) * rtt + (1.0-isnow(ji)) * rtt
+          ! layer thickness
+          zh_i(ji)              = ht_i_b(ji) / nlay_i
+          zh_s(ji)              = ht_s_b(ji) / nlay_s
+       END DO
+
+       !--------------------
+       ! Ice / snow layers
+       !--------------------
+
+       z_s(:,0)      = 0.0 ! vert. coord. of the up. lim. of the 1st snow layer
+       z_i(:,0)      = 0.0 ! vert. coord. of the up. lim. of the 1st ice layer
+
+       DO layer = 1, nlay_s
+          DO ji = kideb , kiut
+             ! vert. coord of the up. lim. of the layer-th snow layer
+             z_s(ji,layer)      = z_s(ji,layer-1) + ht_s_b(ji) / nlay_s
+          END DO 
+       END DO
+
+       DO layer = 1, nlay_i
+          DO ji = kideb , kiut
+             ! vert. coord of the up. lim. of the layer-th ice layer
+             z_i(ji,layer)      = z_i(ji,layer-1) + ht_i_b(ji) / nlay_i
+          END DO
+       END DO
+!
+!------------------------------------------------------------------------------|
+! 2) Radiations                                                                |
+!------------------------------------------------------------------------------|
+!
+       !-------------------
+       ! Computation of i0
+       !-------------------
+       ! i0 describes the fraction of solar radiation which does not contribute
+       ! to the surface energy budget but rather penetrates inside the ice.
+       ! We assume that no radiation is transmitted through the snow
+       ! If there is no no snow
+       ! 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 
+
+       DO ji = kideb , kiut
+          ! switches
+          isnow(ji)  = INT ( 1.0 - MAX ( 0.0 , SIGN ( 1.0 , - ht_s_b(ji) ) ) ) 
+                     ! hs > 0, isnow = 1
+          zhsu(ji)   = hnzst  !threshold for the computation of i0
+          zihic(ji)  = MAX( zzero , 1.0 - ( ht_i_b(ji) / zhsu(ji) ) )     
+ 
+          i0(ji)     = ( 1.0 - isnow(ji) ) * &
+                       ( fr1_i0_1d(ji) + zihic(ji) * fr2_i0_1d(ji) )
+                 !fr1_i0_1d = i0 for a thin ice surface
+                 !fr1_i0_2d = i0 for a thick ice surface
+                 !            a function of the cloud cover
+          !
+          !i0(ji)     =  (1.0-FLOAT(isnow(ji)))*3.0/(100*ht_s_b(ji)+10.0)
+          !formula used in Cice
+       END DO
+
+       !-------------------------------------------------------
+       ! Solar radiation absorbed / transmitted at the surface
+       ! Derivative of the non solar flux
+       !-------------------------------------------------------
+       DO ji = kideb , kiut
+
+          ! Shortwave radiation absorbed at surface
+          zfsw(ji)   =  qsr_ice_1d(ji) * ( 1 - i0(ji) )
+
+          ! Solar radiation transmitted below the surface layer
+          zftrice(ji)=  qsr_ice_1d(ji) * i0(ji)
+
+          ! derivative of incoming nonsolar flux 
+          dzf(ji)   =    dqns_ice_1d(ji)  
+
+       END DO
+
+       !---------------------------------------------------------
+       ! Transmission - absorption of solar radiation in the ice
+       !---------------------------------------------------------
+
+       DO ji = kideb , kiut
+          ! Initialization
+          zradtr_s(ji,0) = zftrice(ji) ! radiation penetrating through snow
+       END DO
+
+       ! Radiation through snow
+       DO layer = 1, nlay_s
+          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.0 , &
+                                  z_s(ji,layer) ) ) )
+             ! radiation absorbed by the layer-th snow layer
+             zradab_s(ji,layer) = zradtr_s(ji,layer-1) - zradtr_s(ji,layer)
+          END DO 
+       END DO
+
+       ! Radiation through ice
+       DO ji = kideb , kiut
+          zradtr_i(ji,0)        = zradtr_s(ji,nlay_s) * isnow(ji) + & 
+                                  zftrice(ji) * ( 1 - isnow(ji) )
+       END DO
+
+       DO layer = 1, nlay_i
+          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.0 , &
+                                  z_i(ji,layer) ) ) )
+             ! radiation absorbed by the layer-th ice layer
+             zradab_i(ji,layer) = zradtr_i(ji,layer-1) - zradtr_i(ji,layer)
+          END DO
+       END DO
+
+       ! Radiation transmitted below the ice
+       DO ji = kideb , kiut
+          fstbif_1d(ji)  =  fstbif_1d(ji) + &
+                            zradtr_i(ji,nlay_i) * a_i_b(ji) / at_i_b(ji)
+       END DO
+
+       ! +++++
+       ! just to check energy conservation
+       DO ji = kideb , kiut
+          zji                 = MOD( npb(ji) - 1, jpi ) + 1
+          zjj                 = ( npb(ji) - 1 ) / jpi + 1
+          fstroc(zji,zjj,jl)  = &
+                        zradtr_i(ji,nlay_i)
+       END DO
+       ! +++++
+
+       DO layer = 1, nlay_i
+          DO ji = kideb , kiut
+             radab(ji,layer) = zradab_i(ji,layer)
+          END DO
+       END DO
+
+       
+!
+!------------------------------------------------------------------------------|
+!  3) Iterative procedure begins                                               |
+!------------------------------------------------------------------------------|
+!
+       ! Old surface temperature
+       DO ji = kideb, kiut
+          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
+          zerrit(ji)           =  1000.0     ! initial value of error
+       END DO
+!RB Min global ??
+
+       ! Old snow temperature
+       DO layer = 1, nlay_s
+          DO ji = kideb , kiut
+             ztsold(ji,layer)     =  t_s_b(ji,layer)
+          END DO
+       END DO
+          
+       ! Old ice temperature
+       DO layer = 1, nlay_i
+          DO ji = kideb , kiut
+             ztiold(ji,layer)     =  t_i_b(ji,layer)
+          END DO
+       END DO
+
+       nconv     =  0         ! number of iterations
+       zerritmax =  1000.0    ! maximal value of error on all points
+
+       DO WHILE ((zerritmax > maxer_i_thd).AND.(nconv < nconv_i_thd))
+
+       nconv   =  nconv+1
+
+!
+!------------------------------------------------------------------------------|
+! 4) Sea ice thermal conductivity                                              |
+!------------------------------------------------------------------------------|
+!
+       IF ( thcon_i_swi .EQ. 0 ) THEN
+       ! Untersteiner (1964) formula
+       DO ji = kideb , kiut
+          ztcond_i(ji,0)        = rcdic + zbeta*s_i_b(ji,1) / &
+                                  MIN(-zeps,t_i_b(ji,1)-rtt)
+          ztcond_i(ji,0)        = MAX(ztcond_i(ji,0),zkimin)
+       END DO
+       ENDIF
+
+       IF ( thcon_i_swi .EQ. 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.09*s_i_b(ji,1) / &
+                                  MIN(-zeps,t_i_b(ji,1)-rtt) - &
+                                  0.011* ( t_i_b(ji,1) - rtt )  
+          ztcond_i(ji,0)        = MAX(ztcond_i(ji,0),zkimin)
+       END DO
+       ENDIF
+
+       IF ( thcon_i_swi .EQ. 0 ) THEN ! Untersteiner
+       DO layer = 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(-zeps,     &
+                           t_i_b(ji,layer)+t_i_b(ji,layer+1)-2.0*rtt)
+             ztcond_i(ji,layer)   = MAX(ztcond_i(ji,layer),zkimin)
+          END DO
+       END DO
+       ENDIF
+
+       IF ( thcon_i_swi .EQ. 1 ) THEN ! Pringle
+       DO layer = 1, nlay_i-1
+          DO ji = kideb , kiut
+             ztcond_i(ji,layer) = rcdic + 0.09*( s_i_b(ji,layer)   &
+                           + s_i_b(ji,layer+1) ) / MIN(-zeps,      &
+                           t_i_b(ji,layer)+t_i_b(ji,layer+1)-2.0*rtt) - &
+                           0.011* ( t_i_b(ji,layer) + t_i_b(ji,layer+1) - 2.0*rtt )  
+             ztcond_i(ji,layer) = MAX(ztcond_i(ji,layer),zkimin)
+          END DO
+       END DO
+       ENDIF
+
+       IF ( thcon_i_swi .EQ. 0 ) THEN ! Untersteiner
+       DO ji = kideb , kiut
+          ztcond_i(ji,nlay_i)   = rcdic + zbeta*s_i_b(ji,nlay_i) / &
+                           MIN(-zeps,t_bo_b(ji)-rtt)
+          ztcond_i(ji,nlay_i)   = MAX(ztcond_i(ji,nlay_i),zkimin)
+       END DO
+       ENDIF
+
+       IF ( thcon_i_swi .EQ. 1 ) THEN ! Pringle
+       DO ji = kideb , kiut
+          ztcond_i(ji,nlay_i)   = rcdic + 0.09*s_i_b(ji,nlay_i) / &
+                                  MIN(-zeps,t_bo_b(ji)-rtt) - &
+                                  0.011* ( t_bo_b(ji) - rtt )  
+          ztcond_i(ji,nlay_i)   = MAX(ztcond_i(ji,nlay_i),zkimin)
+       END DO
+       ENDIF
+!
+!------------------------------------------------------------------------------|
+!  5) kappa factors                                                            |
+!------------------------------------------------------------------------------|
+!
+       DO ji = kideb, kiut
+
+       !-- Snow kappa factors
+          zkappa_s(ji,0)         = rcdsn / MAX(zeps,zh_s(ji))
+          zkappa_s(ji,nlay_s)    = rcdsn / MAX(zeps,zh_s(ji))
+       END DO
+
+       DO layer = 1, nlay_s-1
+          DO ji = kideb , kiut
+             zkappa_s(ji,layer)  = 2.0 * rcdsn / &
+             MAX(zeps,2.0*zh_s(ji))
+          END DO 
+       END DO
+
+       DO layer = 1, nlay_i-1
+          DO ji = kideb , kiut
+          !-- Ice kappa factors
+             zkappa_i(ji,layer)  = 2.0*ztcond_i(ji,layer)/ &
+             MAX(zeps,2.0*zh_i(ji)) 
+          END DO 
+       END DO
+
+       DO ji = kideb , kiut
+          zkappa_i(ji,0)        = ztcond_i(ji,0)/MAX(zeps,zh_i(ji))
+          zkappa_i(ji,nlay_i)   = ztcond_i(ji,nlay_i) / MAX(zeps,zh_i(ji))
+       !-- Interface
+          zkappa_s(ji,nlay_s)   = 2.0*rcdsn*ztcond_i(ji,0)/MAX(zeps, &
+                       (ztcond_i(ji,0)*zh_s(ji) + rcdsn*zh_i(ji)))
+          zkappa_i(ji,0)        = zkappa_s(ji,nlay_s)*isnow(ji) &
+                                + zkappa_i(ji,0)*(1.0-isnow(ji))
+       END DO
+!
+!------------------------------------------------------------------------------|
+! 6) Sea ice specific heat, eta factors                                        |
+!------------------------------------------------------------------------------|
+!
+          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),zeps)
+                zeta_i(ji,layer)    = rdt_ice / MAX(rhoic*zspeche_i(ji,layer)*zh_i(ji), &
+                                              zeps)
+             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),zeps)
+             END DO
+          END DO
+!
+!------------------------------------------------------------------------------|
+! 7) surface flux computation                                                  |
+!------------------------------------------------------------------------------|
+!
+          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) )
+
+          ! update incoming flux
+             zf(ji)    =   zfsw(ji)              & ! net absorbed solar radiation
+                       + qnsr_ice_1d(ji)           ! non solar total flux 
+                                                   ! (LWup, LWdw, SH, LH)
+
+          END DO
+
+!
+!------------------------------------------------------------------------------|
+! 8) tridiagonal system terms                                                  |
+!------------------------------------------------------------------------------|
+!
+!!layer denotes the number of the layer in the snow or in the ice
+!!numeq denotes the reference number of the equation in the tridiagonal
+!!system, terms of tridiagonal system are indexed as following :
+!!1 is subdiagonal term, 2 is diagonal and 3 is superdiagonal one
+
+!!ice interior terms (top equation has the same form as the others)
+
+          DO numeq=1,jkmax+2
+             DO ji = kideb , kiut
+                ztrid(ji,numeq,1) = 0.
+                ztrid(ji,numeq,2) = 0.
+                ztrid(ji,numeq,3) = 0.
+                zindterm(ji,numeq)= 0.
+                zindtbis(ji,numeq)= 0.
+                zdiagbis(ji,numeq)= 0.
+             ENDDO
+          ENDDO
+
+          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)
+             END DO
+          ENDDO
+
+          numeq =  nlay_s + nlay_i + 1
+          DO ji = kideb , kiut
+            !!ice bottom term
+            ztrid(ji,numeq,1)  =  - zeta_i(ji,nlay_i)*zkappa_i(ji,nlay_i-1)   
+            ztrid(ji,numeq,2)  =  1.0 + zeta_i(ji,nlay_i)*( zkappa_i(ji,nlay_i)*zg1 &
+                               +  zkappa_i(ji,nlay_i-1) )
+            ztrid(ji,numeq,3)  =  0.0
+            zindterm(ji,numeq) =  ztiold(ji,nlay_i) + zeta_i(ji,nlay_i)* &
+                                 ( zradab_i(ji,nlay_i) + zkappa_i(ji,nlay_i)*zg1 &
+                              *  t_bo_b(ji) ) 
+          ENDDO
+
+
+          DO ji = kideb , kiut
+            IF ( ht_s_b(ji).gt.0.0 ) THEN
+!
+!------------------------------------------------------------------------------|
+!  snow-covered cells                                                          |
+!------------------------------------------------------------------------------|
+!
+                !!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)
+                END DO
+     
+                !!case of only one layer in the ice (ice equation is altered)
+                IF ( nlay_i.eq.1 ) THEN
+                   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) 
+                ENDIF
+
+                IF ( t_su_b(ji) .LT. rtt ) THEN
+ 
+!------------------------------------------------------------------------------|
+!  case 1 : no surface melting - snow present                                  |
+!------------------------------------------------------------------------------|
+                   zdifcase(ji)    =  1.0
+                   numeqmin(ji)    =  1
+                   numeqmax(ji)    =  nlay_i + nlay_s + 1
+
+                   !!surface equation
+                   ztrid(ji,1,1) = 0.0
+                   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)
+
+                   !!first layer of snow equation
+                   ztrid(ji,2,1)  =  - zkappa_s(ji,0)*zg1s*zeta_s(ji,1)
+                   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)
+
+                ELSE 
+!
+!------------------------------------------------------------------------------|
+!  case 2 : surface is melting - snow present                                  |
+!------------------------------------------------------------------------------|
+!
+                   zdifcase(ji)    =  2.0
+                   numeqmin(ji)    =  2
+                   numeqmax(ji)    =  nlay_i + nlay_s + 1
+
+                   !!first layer of snow equation
+                   ztrid(ji,2,1)  =  0.0
+                   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) +                         &
+                                    zkappa_s(ji,0) * zg1s * t_su_b(ji) ) 
+                ENDIF
+             ELSE
+!
+!------------------------------------------------------------------------------|
+!  cells without snow                                                          |
+!------------------------------------------------------------------------------|
+!
+                IF (t_su_b(ji) .LT. rtt) THEN
+!
+!------------------------------------------------------------------------------|
+!  case 3 : no surface melting - no snow                                       |
+!------------------------------------------------------------------------------|
+!
+                   zdifcase(ji)      =  3.0
+                   numeqmin(ji)      =  nlay_s + 1
+                   numeqmax(ji)      =  nlay_i + nlay_s + 1
+
+                   !!surface equation	
+                   ztrid(ji,numeqmin(ji),1)   =  0.0
+                   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)
+
+                   !!first layer of ice equation
+                   ztrid(ji,numeqmin(ji)+1,1) =  - zkappa_i(ji,0) * zg1 * zeta_i(ji,1)
+                   ztrid(ji,numeqmin(ji)+1,2) =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,1) & 
+                                              + 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)  
+
+                   !!case of only one layer in the ice (surface & ice equations are altered)
+
+                   IF (nlay_i.eq.1) THEN
+                      ztrid(ji,numeqmin(ji),1)    =  0.0
+                      ztrid(ji,numeqmin(ji),2)    =  dzf(ji) - zkappa_i(ji,0)*2.0
+                      ztrid(ji,numeqmin(ji),3)    =  zkappa_i(ji,0)*2.0
+                      ztrid(ji,numeqmin(ji)+1,1)  =  -zkappa_i(ji,0)*2.0*zeta_i(ji,1)
+                      ztrid(ji,numeqmin(ji)+1,2)  =  1.0 + zeta_i(ji,1)*(zkappa_i(ji,0)*2.0 + &
+                                              zkappa_i(ji,1))
+                      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) )
+                   ENDIF     
+
+                ELSE
+ 
+!
+!------------------------------------------------------------------------------|
+! case 4 : surface is melting - no snow                                        |
+!------------------------------------------------------------------------------|
+!
+                   zdifcase(ji)    =  4.0
+                   numeqmin(ji)    =  nlay_s + 2
+                   numeqmax(ji)    =  nlay_i + nlay_s + 1
+
+                   !!first layer of ice equation
+                   ztrid(ji,numeqmin(ji),1)      =  0.0
+                   ztrid(ji,numeqmin(ji),2)      =  1.0 + zeta_i(ji,1)*(zkappa_i(ji,1) + zkappa_i(ji,0)* &
+                                             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) ) 
+
+                   !!case of only one layer in the ice (surface & ice equations are altered)
+                   IF (nlay_i.eq.1) THEN
+                      ztrid(ji,numeqmin(ji),1)  =  0.0
+                      ztrid(ji,numeqmin(ji),2)  =  1.0 + zeta_i(ji,1)*(zkappa_i(ji,0)*2.0 + &
+                                         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
+                   ENDIF
+
+                ENDIF
+             ENDIF
+ 
+          END DO
+
+!
+!------------------------------------------------------------------------------|
+! 9) tridiagonal system solving                                                |
+!------------------------------------------------------------------------------|
+!
+
+! Solve the tridiagonal system with Gauss elimination method.
+! Thomas algorithm, from Computational fluid Dynamics, J.D. ANDERSON, 
+! McGraw-Hill 1984.	
+
+          maxnumeqmax = 0
+          minnumeqmin = jkmax+4
+
+          DO ji = kideb , kiut
+             zindtbis(ji,numeqmin(ji)) =  zindterm(ji,numeqmin(ji))
+             zdiagbis(ji,numeqmin(ji)) =  ztrid(ji,numeqmin(ji),2)
+             minnumeqmin               =  MIN(numeqmin(ji),minnumeqmin)
+             maxnumeqmax               =  MAX(numeqmax(ji),maxnumeqmax)
+          END DO
+
+          DO layer = minnumeqmin+1, maxnumeqmax
+             DO ji = kideb , kiut
+                numeq               =  min(max(numeqmin(ji)+1,layer),numeqmax(ji))
+                zdiagbis(ji,numeq)  =  ztrid(ji,numeq,2) - ztrid(ji,numeq,1)* &
+                                       ztrid(ji,numeq-1,3)/zdiagbis(ji,numeq-1)
+                zindtbis(ji,numeq)  =  zindterm(ji,numeq) - ztrid(ji,numeq,1)* &
+                                       zindtbis(ji,numeq-1)/zdiagbis(ji,numeq-1)
+             END DO
+          END DO
+
+          DO ji = kideb , kiut
+          ! ice temperatures
+             t_i_b(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)
+             END DO
+          END DO
+
+          DO ji = kideb , kiut
+            ! snow temperatures      
+            IF (ht_s_b(ji).GT.0) &
+            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)-zeps)) 
+
+            ! surface temperature
+            isnow(ji)            = INT(1.0-max(0.0,sign(1.0,-ht_s_b(ji))))
+            ztsuoldit(ji)        = t_su_b(ji)
+            IF (t_su_b(ji) .LT. ztfs(ji)) &
+            t_su_b(ji)           = ( zindtbis(ji,numeqmin(ji)) - ztrid(ji,numeqmin(ji),3)* &
+                                   ( isnow(ji)*t_s_b(ji,1) + &
+                                   (1.0-isnow(ji))*t_i_b(ji,1) ) ) / &
+                                   zdiagbis(ji,numeqmin(ji))  
+          END DO
+!
+!--------------------------------------------------------------------------
+!  10) Has the scheme converged ?, end of the iterative procedure         |
+!--------------------------------------------------------------------------
+!
+          ! check that nowhere it has started to melt
+          ! 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.0)
+             zerrit(ji)          =  ABS(t_su_b(ji)-ztsuoldit(ji))     
+          END DO
+
+          DO layer  =  1, nlay_s
+             DO ji = kideb , kiut
+                zji                 = MOD( npb(ji) - 1, jpi ) + 1
+                zjj                 = ( npb(ji) - 1 ) / jpi + 1
+                t_s_b(ji,layer)  =  MAX(MIN(t_s_b(ji,layer),rtt),190.0)
+                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.0)
+                zerrit(ji)       =  MAX(zerrit(ji),ABS(t_i_b(ji,layer) - ztitemp(ji,layer)))
+             END DO
+          END DO
+
+          ! Compute spatial maximum over all errors
+          ! note that this could be optimized substantially by iterating only
+          ! the non-converging points
+          zerritmax = 0.0
+          DO ji = kideb , kiut
+             zerritmax           =  MAX(zerritmax,zerrit(ji))   
+          END DO
+          IF( lk_mpp ) CALL mpp_max(zerritmax, kcom=ncomm_ice)
+
+      END DO  ! End of the do while iterative procedure
+
+      WRITE(numout,*) ' zerritmax : ', zerritmax
+      WRITE(numout,*) ' nconv     : ', nconv
+
+
+!
+!--------------------------------------------------------------------------
+!   11) Fluxes at the interfaces                                          |
+!--------------------------------------------------------------------------
+!
+       DO ji = kideb, kiut
+       ! update of latent heat fluxes
+          qla_ice_1d (ji) = qla_ice_1d (ji) + &
+                            dqla_ice_1d(ji) * ( t_su_b(ji) - ztsuold(ji) )
+
+       ! surface ice conduction flux
+          isnow(ji)       = int(1.0-max(0.0,sign(1.0,-ht_s_b(ji))))
+          fc_su(ji)       =  - isnow(ji)*zkappa_s(ji,0)*zg1s*(t_s_b(ji,1) - &
+                               t_su_b(ji)) &
+                             - (1.0-isnow(ji))*zkappa_i(ji,0)*zg1* &
+                               (t_i_b(ji,1) - t_su_b(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 ) THEN
+
+       DO ji = kideb, kiut
+       ! Upper snow value
+          fc_s(ji,0) = - isnow(ji)* &
+                       zkappa_s(ji,0) * zg1s * ( t_s_b(ji,1) - &
+                               t_su_b(ji) ) 
+       ! Bott. snow value
+          fc_s(ji,1) = - isnow(ji)* &
+                       zkappa_s(ji,1) * ( t_i_b(ji,1) - &
+                               t_s_b(ji,1) ) 
+       END DO
+
+       ! Upper ice layer
+       DO ji = kideb, kiut
+          fc_i(ji,0) = - isnow(ji) * &  ! interface flux if there is snow
+                       ( zkappa_i(ji,0)  * ( t_i_b(ji,1) - t_s_b(ji,nlay_s ) ) ) &
+                     - ( 1.0 - isnow(ji) ) * ( zkappa_i(ji,0) * & 
+                     zg1 * ( t_i_b(ji,1) - t_su_b(ji) ) ) ! upper flux if not
+       END DO
+
+       ! Internal ice layers
+       DO layer = 1, nlay_i - 1
+       DO ji = kideb, kiut
+          fc_i(ji,layer) = - zkappa_i(ji,layer) * ( t_i_b(ji,layer+1) - &
+                                                    t_i_b(ji,layer) )
+          zji                 = MOD( npb(ji) - 1, jpi ) + 1
+          zjj                 = ( npb(ji) - 1 ) / jpi + 1
+       END DO
+       END DO
+
+       ! Bottom ice layers
+       DO ji = kideb, kiut
+          fc_i(ji,nlay_i) = - zkappa_i(ji,nlay_i)* &
+                             ( zg1*(t_bo_b(ji) - t_i_b(ji,nlay_i)) )
+       END DO
+
+       ENDIF
+
+    END SUBROUTINE lim_thd_dif
+
+#else
+   !!======================================================================
+   !!                       ***  MODULE limthd_dif   ***
+   !!                              no sea ice model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE lim_thd_dif          ! Empty routine
+   END SUBROUTINE lim_thd_dif
+#endif
+ END MODULE limthd_dif
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_ent.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_ent.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_ent.F90	(revision 884)
@@ -0,0 +1,742 @@
+MODULE limthd_ent
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!======================================================================
+   !!                       ***  MODULE limthd_ent   ***
+   !!                  Redistribution of Enthalpy in the ice
+   !!                        on the new vertical grid
+   !!                       after vertical growth/decay
+   !!======================================================================
+   !!   lim_thd_ent : ice redistribution of enthalpy
+
+   !! * Modules used
+   USE par_oce          ! ocean parameters
+   USE dom_oce
+   USE domain
+   USE in_out_manager
+   USE phycst
+   USE ice_oce         ! ice variables
+   USE thd_ice
+   USE iceini
+   USE limistate
+   USE ice
+   USE limvar
+   USE par_ice
+   USE lib_mpp 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC  lim_thd_ent     ! called by lim_thd
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      epsi20 = 1.e-20  ,  &
+      epsi13 = 1.e-13  ,  &
+      zzero  = 0.e0    ,  &
+      zone   = 1.e0    ,  &
+      epsi10 = 1.0e-10
+
+   !!----------------------------------------------------------------------
+   !!   LIM 3.0,  UCL-ASTR-LOCEAN-IPSL (2008)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+      SUBROUTINE lim_thd_ent(kideb,kiut,jl)
+      !!-------------------------------------------------------------------
+      !!               ***   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. 
+      !!           Redistribution is made so as to ensure to energy conservation
+      !!
+      !!
+      !! ** Method  : linear conservative remapping
+      !!           
+      !! ** Steps : 1) Grid
+      !!            2) Switches
+      !!            3) Snow redistribution
+      !!            4) Ice enthalpy redistribution
+      !!            5) Ice salinity, recover temperature
+      !!
+      !! ** Arguments
+      !!
+      !! ** Inputs / Outputs
+      !!
+      !! ** External
+      !!
+      !! ** References : Bitz & Lipscomb, JGR 99; Vancoppenolle et al., GRL, 2005
+      !!
+      !! ** History  : (05-2003) Martin V. UCL-Astr
+      !!               (07-2005) Martin for 3d adapatation
+      !!               (11-2006) Vectorized by Xavier Fettweis (ASTR)
+      !!               (03-2008) Energy conservation and clean code
+      !! * Arguments
+
+      INTEGER , INTENT(IN)::  &
+         kideb          ,   &  ! start point on which the the computation is applied
+         kiut           ,   &  ! end point on which the the computation is applied
+         jl                    ! thickness category number
+
+      INTEGER ::            &
+         ji,jk          ,   &  !  dummy loop indices
+         zji, zjj       ,   &  !  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
+
+      INTEGER, DIMENSION(jpij) :: &
+         snswi          ,   &  !  snow switch
+         nbot0          ,   &  !  old layer bottom index
+         icsuind        ,   &  !  ice surface index
+         icsuswi        ,   &  !  ice surface switch
+         icboind        ,   &  !  ice bottom index
+         icboswi        ,   &  !  ice bottom switch
+         snicind        ,   &  !  snow ice index
+         snicswi        ,   &  !  snow ice switch
+         snind                 !  snow index
+
+      REAL(wp) :: &
+         zeps, zeps6    ,   &  ! numerical constant very small
+         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
+
+      REAL(wp), DIMENSION(jpij) :: &  
+         zh_i           ,   &  ! thickness of an ice layer
+         zh_s           ,   &  ! thickness of a snow layer
+         zqsnow         ,   &  ! enthalpy of the snow put in snow ice 	
+         zdeltah               ! temporary variable
+
+      REAL(wp), DIMENSION(jpij,0:jkmax+3) :: &
+         zm0            ,   &  !  old layer-system vertical cotes
+         qm0            ,   &  !  old layer-system heat content
+         z_s            ,   &  !  new snow system vertical cotes
+         z_i            ,   &  !  new ice system vertical cotes
+         zthick0               !  old ice thickness
+
+      REAL(wp), DIMENSION(jpij,0:jkmax+3) :: &
+         zhl0                  ! old and new layer thicknesses
+ 
+      REAL(wp), DIMENSION(0:jkmax+3,0:jkmax+3) :: &
+         zrl01
+
+      ! Energy conservation
+      REAL(wp), DIMENSION(jpij) :: &
+         zqti_in, zqts_in,         &
+         zqti_fin, zqts_fin
+
+!------------------------------------------------------------------------------|
+
+      zeps   = 1.0d-20
+      zeps6  = 1.0d-06
+      zthick0(:,:) = 0.0
+      zm0(:,:)     = 0.0
+      qm0(:,:)     = 0.0
+      zrl01(:,:)   = 0.0
+      zhl0(:,:)    = 0.0
+      z_i(:,:)     = 0.0
+      z_s(:,:)     = 0.0
+
+!
+!------------------------------------------------------------------------------|
+!  1) Grid                                                                     |
+!------------------------------------------------------------------------------|
+!
+      nlays0        = nlay_s
+      nlayi0        = nlay_i
+
+      DO ji = kideb, kiut
+         zh_i(ji)   = old_ht_i_b(ji) / nlay_i 
+         zh_s(ji)   = old_ht_s_b(ji) / nlay_s
+      ENDDO
+
+!
+!------------------------------------------------------------------------------|
+!  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.0
+      ENDDO !ji
+
+      DO jk = 1, nlays0
+        DO ji = kideb, kiut
+           snind(ji)  = jk        *      INT(MAX(0.0,SIGN(1.0,-dh_s_tot(ji)-zdeltah(ji)-zeps))) &
+                      + snind(ji) * (1 - INT(MAX(0.0,SIGN(1.0,-dh_s_tot(ji)-zdeltah(ji)-zeps))))
+           zdeltah(ji)= zdeltah(ji) + zh_s(ji)
+        END DO ! ji
+      ENDDO ! jk
+
+      ! snswi(ji) : switch which value equals 1 if snow melts
+      !				   0 if not
+      DO ji = kideb, kiut
+         snswi(ji)     = MAX(0,INT(-dh_s_tot(ji)/MAX(zeps,ABS(dh_s_tot(ji)))))
+      ENDDO ! 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.0
+      ENDDO !ji
+      DO jk = 1, nlayi0
+        DO ji = kideb, kiut
+          icsuind(ji) = jk          *      INT(MAX(0.0,SIGN(1.0,-dh_i_surf(ji)-zdeltah(ji)-zeps))) &
+                      + icsuind(ji) * (1 - INT(MAX(0.0,SIGN(1.0,-dh_i_surf(ji)-zdeltah(ji)-zeps))))
+          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,INT(-dh_i_surf(ji)/MAX(zeps , ABS(dh_i_surf(ji)) ) ) )
+      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.0
+      ENDDO
+      DO jk = nlayi0, 1, -1
+        DO ji = kideb, kiut
+          icboind(ji) = (nlayi0+1-jk) &
+                      *      INT(MAX(0.0,SIGN(1.0,-dh_i_bott(ji)-zdeltah(ji)-zeps))) &
+                      + icboind(ji) &
+                      * (1 - INT(MAX(0.0,SIGN(1.0,-dh_i_bott(ji)-zdeltah(ji)-zeps)))) 
+          zdeltah(ji) = zdeltah(ji) + zh_i(ji)
+        END DO
+      ENDDO
+
+      DO ji = kideb, kiut
+         ! case of total ablation with remaining snow
+         IF ( ( ht_i_b(ji) .GT. zeps ) .AND. &
+              ( ht_i_b(ji) - dh_snowice(ji) .LT. zeps ) ) 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,INT(dh_i_bott(ji) / MAX(zeps,ABS(dh_i_bott(ji)))))
+      ENDDO
+
+      ! 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.0
+      ENDDO
+      DO jk = nlays0, 1, -1
+        DO ji = kideb, kiut
+          snicind(ji) = (nlays0+1-jk) &
+                      *      INT(MAX(0.0,SIGN(1.0,dh_snowice(ji)-zdeltah(ji)-zeps))) &
+                      + snicind(ji) &
+                      * (1 - INT(MAX(0.0,SIGN(1.0,dh_snowice(ji)-zdeltah(ji)-zeps))))
+          zdeltah(ji) = zdeltah(ji) + zh_s(ji)
+        END DO
+      ENDDO
+
+      ! snicswi(ji) : switch which equals 
+      ! 	   1 if snow-ice forms
+      ! 	   0 if not
+      DO ji = kideb, kiut
+        snicswi(ji)   = MAX(0,INT(dh_snowice(ji)/MAX(zeps,ABS(dh_snowice(ji)))))
+      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.0
+        maxnbot0           =  MAX ( maxnbot0 , nbot0(ji) )
+      ENDDO 
+      IF( lk_mpp ) CALL mpp_max( maxnbot0, kcom=ncomm_ice )
+
+      DO jk = 1, maxnbot0
+        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) * limsum
+        END DO
+      ENDDO
+
+      DO ji = kideb, kiut
+         zm0(ji,nbot0(ji)) =  dh_s_tot(ji) - snicswi(ji) * dh_snowice(ji) + &
+                              zh_s(ji) * nlays0
+         zm0(ji,1)         =  dh_s_tot(ji) * (1 -snswi(ji) ) +              &
+                              snswi(ji) * zm0(ji,1)
+      ENDDO
+
+      DO jk = ntop0, maxnbot0
+        DO ji = kideb, kiut
+        ! layer thickness
+           zthick0(ji,jk)  =  zm0(ji,jk) - zm0(ji,jk-1)
+        END DO
+      ENDDO
+
+      zqts_in(:) = 0.0
+      
+      DO ji = kideb, kiut
+        ! layer heat content
+        qm0(ji,1)   =  rhosn * ( cpic * ( rtt - ( 1. - snswi(ji) ) * ( tatm_ice_1d(ji) ) &
+                                            - snswi(ji) * t_s_b(ji,1) )         &
+                               + lfus ) * zthick0(ji,1)
+        zqts_in(ji) =  zqts_in(ji) + qm0(ji,1) 
+      ENDDO
+
+      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, zeps - ht_s_b(ji) ) )
+          zqts_in(ji) = zqts_in(ji) + ( 1. - snswi(ji) ) * qm0(ji,jk) * zswitch
+        END DO ! jk
+      ENDDO ! 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.0
+      ENDDO
+
+      DO jk =  nlays0, 1, -1
+        DO ji = kideb, kiut
+           zhsnow      =  MAX(0.0,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
+      ENDDO
+
+      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) / nlay_s
+         z_s(ji,0) =  0.0
+      ENDDO
+
+      DO jk = 1, nlay_s
+        DO ji = kideb, kiut
+           z_s(ji,jk) =  zh_s(ji) * jk
+        END DO
+      ENDDO
+
+      !-----------------
+      ! Layer thickness
+      !-----------------
+      DO layer0 = ntop0, maxnbot0
+        DO ji = kideb, kiut
+           zhl0(ji,layer0) = zm0(ji,layer0) - zm0(ji,layer0-1)
+        END DO
+      ENDDO
+
+      DO layer1 = ntop1, nbot1
+        DO ji = kideb, kiut
+           q_s_b(ji,layer1)= 0.0
+        END DO
+      ENDDO
+
+      !----------------
+      ! Weight factors
+      !----------------
+      DO layer0 = ntop0, maxnbot0
+        DO layer1 = ntop1, nbot1
+           DO ji = kideb, kiut
+              zrl01(layer1,layer0) = 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,nbot0(ji)-layer0+zeps))
+           END DO
+        END DO
+      ENDDO
+
+      ! Heat conservation
+      zqts_fin(:) = 0.0
+      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 ) THEN
+      DO ji = kideb, kiut
+         IF ( ABS ( zqts_in(ji) - zqts_fin(ji) ) / rdt_ice .GT. 1.0e-6 ) THEN
+            zji                 = MOD( npb(ji) - 1, jpi ) + 1
+            zjj                 = ( npb(ji) - 1 ) / jpi + 1
+            WRITE(numout,*) ' violation of heat conservation : ',             &
+                            ABS ( zqts_in(ji) - zqts_fin(ji) ) / rdt_ice
+            WRITE(numout,*) ' ji, jj   : ', zji, zjj
+            WRITE(numout,*) ' ht_s_b   : ', ht_s_b(ji)
+            WRITE(numout,*) ' zqts_in  : ', zqts_in(ji) / rdt_ice
+            WRITE(numout,*) ' zqts_fin : ', zqts_fin(ji) / rdt_ice
+            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_i
+         DO ji = kideb, kiut
+            q_s_b(ji,jk) = q_s_b(ji,jk) / MAX( zh_s(ji) , zeps )
+         END DO !ji
+      ENDDO !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, zeps - ht_s_b(ji) ) )
+           t_s_b(ji,jk) = rtt                                                  &
+                        + ( 1.0 - zswitch ) *                                  &
+                          ( - zfac1 * q_s_b(ji,jk) + zfac2 )
+        END DO
+      ENDDO
+!
+!------------------------------------------------------------------------------|
+!  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) )
+      ENDDO
+
+      !-------------------------
+      ! Cotes of old ice layers
+      !-------------------------
+      zm0(:,0)    =  0.0
+      
+      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)=  icsuswi(ji)*dh_i_surf(ji) + snicswi(ji)*dh_snowice(ji) &
+                      +  limsum * zh_i(ji)
+         END DO
+      ENDDO
+
+      DO ji = kideb, kiut
+         zm0(ji,nbot0(ji)) =  icsuswi(ji)*dh_i_surf(ji) + snicswi(ji)*dh_snowice(ji) + dh_i_bott(ji) &
+                           +  zh_i(ji) * nlayi0
+         zm0(ji,1)         =  snicswi(ji)*dh_snowice(ji) + (1-snicswi(ji))*zm0(ji,1)
+      ENDDO
+
+      !-----------------------------
+      ! 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
+      ENDDO
+
+      !---------------------------
+      ! 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),-zeps) ) - rcp*(ztmelts-rtt) ) &
+                      * zthick0(ji,jk)
+         END DO
+      ENDDO
+
+      !----------------------------
+      ! Bottom layers heat content
+      !----------------------------
+      DO ji = kideb, kiut        
+        ztmelts    = ( 1.0 - icboswi(ji) ) * (-tmut * s_i_b(ji,nlayi0)) &   ! case of melting ice
+                   +      icboswi(ji)      * (-tmut * s_i_new(ji))      &   ! case of forming ice
+                   + rtt                        ! this temperature is in Celsius
+
+        ! bottom formation temperature
+        ztform = t_i_b(ji,nlay_i)
+        IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) ztform = t_bo_b(ji)
+        qm0(ji,nbot0(ji)) = ( 1.0 - icboswi(ji) )*qm0(ji,nbot0(ji)) &   ! case of melting ice
+                   + icboswi(ji) *                                  &   ! case of forming ice
+                     rhoic*( cpic*(ztmelts-ztform)                  &
+                           + lfus *( 1.0-(ztmelts-rtt)/             &
+                             MIN ( (ztform-rtt) , - epsi10 ) )      & 
+                           - rcp*(ztmelts-rtt) )                    &
+                    *zthick0(ji,nbot0(ji))
+      ENDDO
+
+      !-----------------------------
+      ! 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 * 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)      =  snicswi(ji) * zqsnic + ( 1 - snicswi(ji) ) * qm0(ji,1)
+
+      ENDDO ! 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)-zeps6+zeps) ) &
+                       * MAX( 0.0 , SIGN( 1. , nbot0(ji) - jk + zeps ) )
+        END DO
+      ENDDO
+
+      !-------------
+      ! NEW PROFILE
+      !-------------
+
+      !---------------
+      ! Vectors index
+      !---------------
+
+      ntop1    =  1 
+      nbot1    =  nlay_i
+
+      !------------------
+      ! Layers thickness 
+      !------------------
+      DO ji = kideb, kiut
+        zh_i(ji)      = ht_i_b(ji) / nlay_i
+      ENDDO
+
+      !-------------
+      ! Layer cotes      
+      !-------------
+      z_i(:,0) =  0.0
+      DO jk = 1, nlay_i
+        DO ji = kideb, kiut
+           z_i(ji,jk) =  zh_i(ji) * jk
+        END DO
+      ENDDO
+
+      !--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
+      ENDDO
+
+      !------------------------
+      ! Weights for relayering
+      !------------------------
+
+      q_i_b(:,:) = 0.0
+      DO layer0 = ntop0, maxnbot0
+        DO layer1 = ntop1, nbot1
+           DO ji = kideb, kiut
+              zrl01(layer1,layer0) = 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)-zeps6+zeps)) &
+                               * MAX(0.0,SIGN(1.0,nbot0(ji)-layer0+zeps))
+           END DO
+        END DO
+      ENDDO
+
+      !-------------------------
+      ! Heat conservation check
+      !-------------------------
+      zqti_fin(:) = 0.0
+      DO jk = 1, nlay_i
+         DO ji = kideb, kiut
+            zqti_fin(ji) = zqti_fin(ji) + q_i_b(ji,jk)
+         END DO
+      END DO
+!
+      DO ji = kideb, kiut
+         IF ( ABS ( zqti_in(ji) - zqti_fin(ji) ) / rdt_ice .GT. 1.0e-6 ) THEN
+            zji                 = MOD( npb(ji) - 1, jpi ) + 1
+            zjj                 = ( npb(ji) - 1 ) / jpi + 1
+            WRITE(numout,*) ' violation of heat conservation : ',             &
+                            ABS ( zqti_in(ji) - zqti_fin(ji) ) / rdt_ice
+            WRITE(numout,*) ' ji, jj   : ', zji, zjj
+            WRITE(numout,*) ' ht_i_b   : ', ht_i_b(ji)
+            WRITE(numout,*) ' zqti_in  : ', zqti_in(ji) / rdt_ice
+            WRITE(numout,*) ' zqti_fin : ', zqti_fin(ji) / rdt_ice
+            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
+
+      !----------------------
+      ! Recover heat content 
+      !----------------------
+      DO jk = 1, nlay_i
+         DO ji = kideb, kiut
+            q_i_b(ji,jk) = q_i_b(ji,jk) / MAX( zh_i(ji) , zeps )
+         END DO !ji
+      ENDDO !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
+
+      END SUBROUTINE lim_thd_ent
+
+#else
+   !!======================================================================
+   !!                       ***  MODULE limthd_ent   ***
+   !!                             no sea ice model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE lim_thd_ent          ! Empty routine
+   END SUBROUTINE lim_thd_ent
+#endif
+ END MODULE limthd_ent
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_lac.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_lac.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_lac.F90	(revision 884)
@@ -0,0 +1,816 @@
+MODULE limthd_lac
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!======================================================================
+   !!                       ***  MODULE limthd_lac   ***
+   !!                lateral thermodynamic growth of the ice 
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   lim_lat_acr    : lateral accretion of ice
+   !! * Modules used
+   USE par_oce          ! ocean parameters
+   USE dom_oce
+   USE in_out_manager
+   USE phycst
+   USE ice_oce         ! ice variables
+   USE thd_ice
+   USE dom_ice
+   USE par_ice
+   USE ice
+   USE iceini
+   USE limtab
+   USE taumod
+   USE blk_oce
+   USE limcons
+     
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_thd_lac     ! called by lim_thd
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      epsi20 = 1.e-20  ,  &
+      epsi13 = 1.e-13  ,  &
+      epsi11 = 1.e-13  ,  &
+      epsi03 = 1.e-03  ,  &
+      epsi06 = 1.e-06  ,  &
+      zeps   = 1.e-10  ,  &
+      zzero  = 0.e0    ,  &
+      zone   = 1.e0
+
+   !!----------------------------------------------------------------------
+   !!   LIM 3.0,  UCL-ASTR-LOCEAN-IPSL (2008) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limthd_lac.F90,v 1.5 2005/03/27 18:34:42 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+    
+   SUBROUTINE lim_thd_lac
+      !!-------------------------------------------------------------------
+      !!               ***   ROUTINE lim_thd_lac  ***
+      !!  
+      !! ** Purpose : Computation of the evolution of the ice thickness and 
+      !!      concentration as a function of the heat balance in the leads.
+      !!      It is only used for lateral accretion
+      !!       
+      !! ** Method  : Ice is formed in the open water when ocean lose heat
+      !!      (heat budget of open water Bl is negative) .
+      !!      Computation of the increase of 1-A (ice concentration) fol-
+      !!      lowing the law :
+      !!      (dA/dt)acc = F[ (1-A)/(1-a) ] * [ Bl / (Li*h0) ]
+      !!       where - h0 is the thickness of ice created in the lead
+      !!             - a is a minimum fraction for leads
+      !!             - F is a monotonic non-increasing function defined as:
+      !!                  F(X)=( 1 - X**exld )**(1.0/exld)
+      !!             - exld is the exponent closure rate (=2 default val.)
+      !! 
+      !! ** Action : - Adjustment of snow and ice thicknesses and heat
+      !!                content in brine pockets
+      !!             - Updating ice internal temperature
+      !!             - 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(:,:)      
+      !! 
+      !! ** References : Not available yet
+      !!
+      !! History :
+      !!   3.0  !  12-05 (M. Vancoppenolle)  Thorough rewrite of the routine
+      !!                                     Salinity variations in sea ice, 
+      !!                                     Multi-layer code
+      !!   3.1  !  01-06 (M. Vancoppenolle)  ITD
+      !!   3.2  !  04-07 (M. Vancoppenolle)  Mass and energy conservation tested
+      !!------------------------------------------------------------------------
+      !! * Arguments
+      !! * Local variables
+      INTEGER ::             &
+         ji,jj,jk,jl,jm  ,   &  !: dummy loop indices
+         layer           ,   &  !: layer index
+         nbpac                  !: nb of pts for lateral accretion 
+
+      INTEGER ::             &
+         zji             ,   &  !: ji of dummy test point 
+         zjj             ,   &  !: jj of dummy test point
+         iter                   !: iteration for frazil ice computation
+
+      INTEGER, DIMENSION(jpij) :: &
+         zcatac          ,   &  !:  indexes of categories where new ice grows
+         zswinew                !: switch for new ice or not
+
+      REAL(wp), DIMENSION(jpij) :: &
+         zv_newice       ,   &  !: volume of accreted ice
+         za_newice       ,   &  !: fractional area of accreted ice
+         zh_newice       ,   &  !: thickness of accreted ice
+         ze_newice       ,   &  !: heat content of accreted ice
+         zs_newice       ,   &  !: salinity of accreted ice
+         zo_newice       ,   &  !: age of accreted ice
+         zdv_res         ,   &  !: residual volume in case of excessive heat budget
+         zda_res         ,   &  !: residual area in case of excessive heat budget
+         zat_i_ac        ,   &  !: total ice fraction    
+         zat_i_lev       ,   &  !: total ice fraction for level ice only (type 1)   
+         zdh_frazb       ,   &  !: accretion of frazil ice at the ice bottom
+         zvrel_ac               !: relative ice / frazil velocity (1D vector)
+
+      REAL(wp), DIMENSION(jpij,jpl) :: &
+         zhice_old       ,   &  !: previous ice thickness
+         zdummy          ,   &  !: dummy thickness of new ice 
+         zdhicbot        ,   &  !: thickness of new ice which is accreted vertically
+         zv_old          ,   &  !: old volume of ice in category jl
+         za_old          ,   &  !: old area of ice in category jl
+         za_i_ac         ,   &  !: 1-D version of a_i
+         zv_i_ac         ,   &  !: 1-D version of v_i
+         zoa_i_ac        ,   &  !: 1-D version of oa_i
+         zsmv_i_ac              !: 1-D version of smv_i
+
+      REAL(wp), DIMENSION(jpij,jkmax,jpl) :: &
+         ze_i_ac                !: 1-D version of e_i
+
+      REAL(wp), DIMENSION(jpij) :: &
+         zqbgow          ,   &  !: heat budget of the open water (negative)
+         zdhex                  !: excessively thick accreted sea ice (hlead-hice)
+
+      REAL(wp)  ::           &
+         ztmelts         ,   &  !: melting point of an ice layer
+         zdv             ,   &  !: increase in ice volume in each category
+         zfrazb                 !: fraction of frazil ice accreted at the ice bottom
+
+      ! Redistribution of energy after bottom accretion
+      REAL(wp)  ::           &  !: Energy redistribution
+         zqold           ,   &  !: old ice enthalpy
+         zweight         ,   &  !: weight of redistribution
+         zeps6           ,   &  !: epsilon value
+         zalphai         ,   &  !: factor describing how old and new layers overlap each other [m]
+         zindb            
+         
+      REAL(wp), DIMENSION(jpij,jkmax+1,jpl) :: &
+         zqm0            ,   &  !: old layer-system heat content
+         zthick0                !: old ice thickness
+
+      ! Frazil ice collection thickness
+      LOGICAL :: &              !: iterate frazil ice collection thickness
+         iterate_frazil
+
+      REAL(wp), DIMENSION(jpi,jpj) :: &
+         zvrel                  !: relative ice / frazil velocity
+
+      REAL(wp) ::            &
+         zgamafr          ,  &  !: mult. coeff. between frazil vel. and wind speed
+         ztenagm          ,  &  !: square root of wind stress
+         zvfrx            ,  &  !: x-component of frazil velocity
+         zvfry            ,  &  !: y-component of frazil velocity
+         zvgx             ,  &  !: x-component of ice velocity
+         zvgy             ,  &  !: y-component of ice velocity
+         ztaux            ,  &  !: x-component of wind stress
+         ztauy            ,  &  !: y-component of wind stress
+         ztwogp           ,  &  !: dummy factor including reduced gravity
+         zvrel2           ,  &  !: square of the relative ice-frazil velocity
+         zf               ,  &  !: F for Newton-Raphson procedure
+         zfp              ,  &  !: dF for Newton-Raphson procedure
+         zhicol_new       ,  &  !: updated collection thickness
+         zsqcd            ,  &  !: 1 / square root of ( airdensity * drag )
+         zhicrit                !: minimum thickness of frazil ice
+
+      ! Variables for energy conservation
+      REAL (wp), DIMENSION(jpi,jpj) :: &  ! 
+         vt_i_init, vt_i_final,   &  !  ice volume summed over categories
+         vt_s_init, vt_s_final,   &  !  snow volume summed over categories
+         et_i_init, et_i_final,   &  !  ice energy summed over categories
+         et_s_init, et_s_final       !  snow energy summed over categories
+
+      REAL(wp) ::            &
+         zde                         ! :increment of energy in category jl
+
+      CHARACTER (len = 15) :: fieldid
+
+      !!-----------------------------------------------------------------------!
+          
+      et_i_init(:,:) = 0.0
+      et_s_init(:,:) = 0.0
+      vt_i_init(:,:) = 0.0
+      vt_s_init(:,:) = 0.0
+      zeps6   = 1.0e-6
+
+!------------------------------------------------------------------------------!
+! 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
+
+!------------------------------------------------------------------------------|
+! 2) Convert units for ice internal energy
+!------------------------------------------------------------------------------|
+      DO jl = 1, jpl
+        DO jk = 1, nlay_i
+          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) / &
+                            MAX( area(ji,jj) * v_i(ji,jj,jl) ,  zeps ) * &
+                            nlay_i
+               zindb      = 1.0-MAX(0.0,SIGN(1.0,-v_i(ji,jj,jl))) !0 if no ice and 1 if yes
+               e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl)*unit_fac*zindb
+            END DO
+          END DO
+        END DO
+      END DO
+
+!------------------------------------------------------------------------------!
+! 3) Collection thickness of ice formed in leads and polynyas
+!------------------------------------------------------------------------------!    
+      ! hicol is the thickness of new ice formed in open water
+      ! hicol can be either prescribed (frazswi = 0)
+      ! or computed (frazswi = 1)
+      ! Frazil ice forms in open water, is transported by wind
+      ! accumulates at the edge of the consolidated ice edge
+      ! where it forms aggregates of a specific thickness called
+      ! collection thickness.
+
+      ! Note : the following algorithm currently breaks vectorization
+      ! 
+
+      zvrel(:,:) = 0.0
+
+      ! Default new ice thickness 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            hicol(ji,jj) = hiccrit(1)
+         END DO
+      END DO
+
+      IF (fraz_swi.eq.1.0) THEN
+
+          !--------------------
+          ! Physical constants
+          !--------------------
+          hicol(:,:) = 0.0
+
+          zhicrit = 0.04 ! frazil ice thickness
+          ztwogp  = 2. * rau0 / ( grav * 0.3 * ( rau0 - rhoic ) ) ! reduced grav
+          zsqcd   = 1.0 / SQRT( 1.3 * cai ) ! 1/SQRT(airdensity*drag)
+          zgamafr = 0.03
+
+          DO jj = 1, jpj
+          DO ji = 1, jpi
+
+          IF ( tms(ji,jj) * ( qcmif(ji,jj) - qldif(ji,jj) ) > 0.e0 ) THEN
+            !-------------
+            ! Wind stress
+            !-------------
+            ! C-grid wind stress components
+            ztaux         = ( gtaux(ji-1,jj  ) * tmu(ji-1,jj  ) &
+                          +   gtaux(ji  ,jj  ) * tmu(ji  ,jj  ) ) / 2.0
+            ztauy         = ( gtauy(ji  ,jj-1) * tmv(ji  ,jj-1) &
+                          +   gtauy(ji  ,jj  ) * tmv(ji  ,jj  ) ) / 2.0
+            ! Square root of wind stress
+            ztenagm       =  SQRT( SQRT( ztaux * ztaux + ztauy * ztauy ) )
+
+            !---------------------
+            ! Frazil ice velocity
+            !---------------------
+            zvfrx         = zgamafr * zsqcd * ztaux / MAX(ztenagm,zeps)
+            zvfry         = zgamafr * zsqcd * ztauy / MAX(ztenagm,zeps)
+
+            !-------------------
+            ! Pack ice velocity
+            !-------------------
+            ! C-grid ice velocity
+            zindb = MAX(0.0, SIGN(1.0, at_i(ji,jj) ))
+            zvgx  = zindb * ( u_ice(ji-1,jj  ) * tmu(ji-1,jj  ) &
+                            + u_ice(ji,jj    ) * tmu(ji  ,jj  ) ) / 2.0
+            zvgy  = zindb * ( v_ice(ji  ,jj-1) * tmv(ji  ,jj-1) &
+                            + v_ice(ji,jj    ) * tmv(ji  ,jj  ) ) / 2.0
+
+            !-----------------------------------
+            ! Relative frazil/pack ice velocity
+            !-----------------------------------
+            ! absolute relative velocity
+            zvrel2        = MAX( ( zvfrx - zvgx ) * ( zvfrx - zvgx ) + &
+                                 ( zvfry - zvgy ) * ( zvfry - zvgy )   &
+                               , 0.15 * 0.15 )
+            zvrel(ji,jj)  = SQRT(zvrel2)
+
+            !---------------------
+            ! Iterative procedure
+            !---------------------
+            hicol(ji,jj) = zhicrit + 0.1 
+            hicol(ji,jj) = zhicrit + hicol(ji,jj) /      & 
+                         ( hicol(ji,jj) * hicol(ji,jj) - &
+                           zhicrit * zhicrit ) * ztwogp * zvrel2
+
+            iter = 1
+            iterate_frazil = .true.
+
+            DO WHILE ( iter .LT. 100 .AND. iterate_frazil ) 
+               zf = ( hicol(ji,jj) - zhicrit ) * ( hicol(ji,jj)**2 - zhicrit**2 ) &
+                                 - hicol(ji,jj) * zhicrit * ztwogp * zvrel2
+               zfp = ( hicol(ji,jj) - zhicrit ) * ( 3.0*hicol(ji,jj) + zhicrit ) &
+                                 - zhicrit * ztwogp * zvrel2
+               zhicol_new = hicol(ji,jj) - zf/zfp
+               hicol(ji,jj)   = zhicol_new
+
+               iter = iter + 1
+
+            END DO ! do while
+
+          ENDIF ! end of selection of pixels where ice forms
+
+      END DO ! loop on ji ends
+      END DO ! loop on jj ends
+
+      ENDIF ! End of computation of frazil ice collection thickness
+
+!------------------------------------------------------------------------------!
+! 4) Identify grid points where new ice forms
+!------------------------------------------------------------------------------!
+
+      !-------------------------------------
+      ! Select points for new ice formation
+      !-------------------------------------
+      ! This occurs if open water energy budget is negative
+      nbpac = 0
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF ( tms(ji,jj) * ( qcmif(ji,jj) - qldif(ji,jj) ) > 0.e0 ) THEN
+               nbpac = nbpac + 1
+               npac( nbpac ) = (jj - 1) * jpi + ji
+               IF ( (ji.eq.jiindex).AND.(jj.eq.jjindex) ) THEN
+                  jiindex_1d = nbpac
+               ENDIF
+            ENDIF
+         END DO
+      END DO
+
+      IF(lwp) THEN
+         WRITE(numout,*) 'lim_thd_lac : nbpac = ', nbpac
+      ENDIF
+
+      !------------------------------
+      ! Move from 2-D to 1-D vectors
+      !------------------------------
+      ! If ocean gains heat do nothing 
+      ! 0therwise compute new ice formation
+
+      IF ( nbpac > 0 ) THEN
+         
+        CALL tab_2d_1d( nbpac, zat_i_ac  (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) )
+           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) )
+           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, fseqv_1d  (1:nbpac)     , fseqv ,              &
+                        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) )
+
+!------------------------------------------------------------------------------!
+! 5) Compute thickness, salinity, enthalpy, age, area and volume of new ice
+!------------------------------------------------------------------------------!
+
+        !----------------------
+        ! Thickness of new ice
+        !----------------------
+        DO ji = 1, nbpac
+           zh_newice(ji)     = hiccrit(1)
+        END DO
+        IF ( fraz_swi .EQ. 1.0 ) zh_newice(:) = hicol_b(:)
+
+        !----------------------
+        ! Salinity of new ice 
+        !----------------------
+
+        IF ( num_sal .EQ. 1 ) THEN
+           zs_newice(:)      =   bulk_sal
+        ENDIF ! num_sal
+
+        IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) THEN
+
+           DO ji = 1, nbpac
+              zs_newice(ji)  =   MIN( 4.606 + 0.91 / zh_newice(ji) , s_i_max )
+              zji            =   MOD( npac(ji) - 1, jpi ) + 1
+              zjj            =   ( npac(ji) - 1 ) / jpi + 1
+              zs_newice(ji)  =   MIN( 0.5*sss_io(zji,zjj) , zs_newice(ji) )
+           END DO ! jl
+
+        ENDIF ! num_sal
+
+        IF ( num_sal .EQ. 3 ) THEN
+           zs_newice(:)      =   2.3
+        ENDIF ! num_sal
+
+        !-------------------------
+        ! Heat content of new ice
+        !-------------------------
+        ! We assume that new ice is formed at the seawater freezing point
+        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 ) )           &
+                                         - rcp * ( ztmelts-rtt ) )
+           ze_newice(ji)     =   MAX( ze_newice(ji) , 0.0 ) +                 &
+                                 MAX( 0.0 , SIGN( 1.0 , - ze_newice(ji) ) )   & 
+                                 * rhoic * lfus
+        END DO ! ji
+        !----------------
+        ! Age of new ice
+        !----------------
+        DO ji = 1, nbpac
+           zo_newice(ji)     = 0.0
+        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)
+
+           ! A fraction zfrazb of frazil ice is accreted at the ice bottom
+           zfrazb        = ( TANH ( Cfrazb * ( zvrel_ac(ji) - vfrazb ) )     & 
+                             + 1.0 ) / 2.0 * maxfrazb
+           zdh_frazb(ji) = zfrazb*zv_newice(ji)
+           zv_newice(ji) = ( 1.0 - zfrazb ) * zv_newice(ji)
+        END DO
+
+        !---------------------------------
+        ! Salt flux due to new ice growth
+        !---------------------------------
+        IF ( ( num_sal .EQ. 4 ) ) THEN 
+           DO ji = 1, nbpac
+              zji            = MOD( npac(ji) - 1, jpi ) + 1
+              zjj            = ( npac(ji) - 1 ) / jpi + 1
+              fseqv_1d(ji)   = fseqv_1d(ji) +                                     &
+                               ( sss_io(zji,zjj) - bulk_sal      ) * rhoic *      &
+                               zv_newice(ji) / rdt_ice
+           END DO
+        ELSE
+           DO ji = 1, nbpac
+              zji            = MOD( npac(ji) - 1, jpi ) + 1
+              zjj            = ( npac(ji) - 1 ) / jpi + 1
+              fseqv_1d(ji)   = fseqv_1d(ji) +                                     &
+                               ( sss_io(zji,zjj) - zs_newice(ji) ) * rhoic *      &
+                               zv_newice(ji) / rdt_ice
+           END DO ! ji
+        ENDIF
+
+        !------------------------------------
+        ! Diags for energy conservation test
+        !------------------------------------
+        DO ji = 1, nbpac
+           ! Volume
+           zji                  = MOD( npac(ji) - 1, jpi ) + 1
+           zjj                  = ( npac(ji) - 1 ) / jpi + 1
+           vt_i_init(zji,zjj)   = vt_i_init(zji,zjj) + zv_newice(ji)
+           ! Energy
+           zde                  = ze_newice(ji) / unit_fac
+           zde                  = zde * area(zji,zjj) * zv_newice(ji)
+           et_i_init(zji,zjj)   = et_i_init(zji,zjj) + zde
+        END DO
+
+        ! keep new ice volume in memory
+        CALL tab_1d_2d( nbpac, v_newice , npac(1:nbpac), zv_newice(1:nbpac) , &
+                        jpi, jpj )
+
+        !-----------------
+        ! Area of new ice
+        !-----------------
+        DO ji = 1, nbpac
+           za_newice(ji)     = zv_newice(ji) / zh_newice(ji)
+           ! diagnostic
+           zji                  = MOD( npac(ji) - 1, jpi ) + 1
+           zjj                  = ( npac(ji) - 1 ) / jpi + 1
+           diag_lat_gr(zji,zjj) = zv_newice(ji) / rdt_ice
+        END DO !ji
+
+!------------------------------------------------------------------------------!
+! 6) Redistribute new ice area and volume into ice categories                  !
+!------------------------------------------------------------------------------!
+
+        !-----------------------------------------
+        ! 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
+        !-------------------------------------------
+        ! 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
+           ! vectorize
+           IF ( za_newice(ji) .GT. ( 1.0 - zat_i_ac(ji) ) ) THEN
+              zda_res(ji)    = za_newice(ji) - (1.0 - zat_i_ac(ji) )
+              zdv_res(ji)    = zda_res(ji) * zh_newice(ji) 
+              za_newice(ji)  = za_newice(ji) - zda_res(ji)
+              zv_newice(ji)  = zv_newice(ji) - zdv_res(ji)
+           ELSE
+              zda_res(ji) = 0.0
+              zdv_res(ji) = 0.0
+           ENDIF
+        END DO ! ji
+
+        !------------------------------------------------
+        ! Laterally redistribute new ice volume and area
+        !------------------------------------------------
+        zat_i_ac(:) = 0.0
+
+        DO jl = 1, jpl
+           DO ji = 1, nbpac
+              ! vectorize
+              IF (       ( hi_max(jl-1)  .LT. zh_newice(ji) ) &
+                   .AND. ( zh_newice(ji) .LE. 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
+              ENDIF
+           END DO ! ji
+        END DO ! jl
+             
+        !----------------------------------
+        ! Heat content - lateral accretion
+        !----------------------------------
+        DO ji = 1, nbpac
+           jl = zcatac(ji) ! categroy in which new ice is put
+           ! zindb = 0 if no ice and 1 if yes
+           zindb            = 1.0 - MAX ( 0.0 , SIGN ( 1.0 , -za_old(ji,jl) ) ) 
+           ! old ice thickness
+           zhice_old(ji,jl)  = zv_old(ji,jl)                                  &
+                             / MAX ( za_old(ji,jl) , zeps ) * zindb
+           ! difference in thickness
+           zdhex(ji)      = MAX( 0.0, zh_newice(ji) - zhice_old(ji,jl) ) 
+           ! is ice totally new in category jl ?
+           zswinew(ji)    = MAX( 0.0, SIGN( 1.0 , - za_old(ji,jl) + epsi11 ) )
+        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) * jk  / nlay_i ,     &
+                                        zh_newice(ji) )                       &
+                                 - MIN( zhice_old(ji,jl) * ( jk - 1 )         &
+                                        / 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) / nlay_i            &
+              + za_newice(ji)  * ze_newice(ji) * zalphai                      &
+              + za_newice(ji)  * ze_newice(ji) * zdhex(ji) / nlay_i ) /       &
+              ( ( zv_i_ac(ji,jl) ) / nlay_i )
+
+           END DO !ji
+        END DO !jl
+
+        !-----------------------------------------------
+        ! 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.0
+
+        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
+
+        WRITE(numout,*) ' zv_i_ac : ', zv_i_ac(jiindex, 1:jpl)
+        DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
+           DO ji = 1, nbpac
+              zindb      =  MAX( 0.0, SIGN( 1.0, zdv_res(ji) ) )
+              zv_i_ac(ji,jl) = zv_i_ac(ji,jl) +                               &
+                               zindb * zdv_res(ji) * za_i_ac(ji,jl) /         &
+                               MAX( zat_i_lev(ji) , epsi06 )
+           END DO ! ji
+        END DO ! jl
+        WRITE(numout,*) ' zv_i_ac : ', zv_i_ac(jiindex, 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 = 0 if no ice and 1 if yes
+              zindb            =  1.0 -  MAX( 0.0 , SIGN( 1.0                 & 
+                                            , - za_i_ac(ji,jl ) ) ) 
+              zhice_old(ji,jl) =  zv_i_ac(ji,jl) /                            &
+                                    MAX( za_i_ac(ji,jl) , zeps ) * zindb
+              zdhicbot(ji,jl)  =  zdv_res(ji) / MAX( za_i_ac(ji,jl) , zeps )  & 
+                               *  zindb &
+                               +  zindb * zdh_frazb(ji) ! frazil ice 
+                                                        ! may coalesce
+              ! thickness of residual ice
+              zdummy(ji,jl)    = zv_i_ac(ji,jl)/MAX(za_i_ac(ji,jl),zeps)*zindb
+           END DO !ji
+        END DO !jl
+
+        ! old layers thicknesses and enthalpies
+        DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
+           DO jk = 1, nlay_i
+              DO ji = 1, nbpac
+                 zthick0(ji,jk,jl)=  zhice_old(ji,jl) / nlay_i
+                 zqm0   (ji,jk,jl)=  ze_i_ac(ji,jk,jl) * zthick0(ji,jk,jl)
+              END DO !ji
+           END DO !jk
+        END DO !jl
+
+        DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
+           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.0
+        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.0 -  MAX( 0.0 , SIGN( 1.0 ,         & 
+                                                    - za_i_ac(ji,jl ) ) ) 
+                    ! Redistributing energy on the new grid
+                    zweight         =  MAX (  &
+                    MIN( zhice_old(ji,jl) * layer , zdummy(ji,jl) * jk ) -    &
+                    MAX( zhice_old(ji,jl) * ( layer - 1 ) , zdummy(ji,jl) *   &
+                        ( jk - 1 ) ) , 0.0 )                                  &
+                    /  ( MAX(nlay_i * zthick0(ji,layer,jl),zeps) ) * 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.0 - MAX( 0.0 , SIGN( 1.0           &
+                                      , - zv_i_ac(ji,jl) ) ) !0 if no ice 
+                 ze_i_ac(ji,jk,jl)    = ze_i_ac(ji,jk,jl) /                   &
+                                        MAX( zv_i_ac(ji,jl) , zeps)           &
+                                        * za_i_ac(ji,jl) * nlay_i * zindb
+              END DO
+           END DO
+        END DO
+
+        !------------
+        ! Update age 
+        !------------
+        DO jl = 1, jpl
+           DO ji = 1, nbpac
+              !--ice age
+              zindb            = 1.0 - MAX( 0.0 , SIGN( 1.0 , -               &
+                                 za_i_ac(ji,jl) ) )  ! 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) , zeps ) * zindb   
+           END DO ! ji
+        END DO ! jl   
+
+        !-----------------
+        ! Update salinity
+        !-----------------
+        IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) THEN
+
+        DO jl = 1, jpl
+           DO ji = 1, nbpac
+              !zindb = 0 if no ice and 1 if yes
+              zindb            = 1.0 - MAX( 0.0 , SIGN( 1.0 , -               &
+                                 zv_i_ac(ji,jl) ) )  ! 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
+           END DO ! ji
+        END DO ! jl   
+
+        ENDIF ! num_sal
+  
+
+!------------------------------------------------------------------------------!
+! 8) 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 )
+           IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) &
+           CALL tab_1d_2d( nbpac, smv_i(:,:,jl) , npac(1:nbpac) ,             &
+                                     zsmv_i_ac(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 ! jk
+        END DO !jl
+        CALL tab_1d_2d( nbpac, fseqv , npac(1:nbpac), fseqv_1d  (1:nbpac) ,   &
+                        jpi, jpj )
+
+     ENDIF ! nbpac > 0
+
+!------------------------------------------------------------------------------!
+! 9) Change units for e_i
+!------------------------------------------------------------------------------!    
+
+      DO jl = 1, jpl
+         DO jk = 1, nlay_i
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ! Correct dimensions to avoid big values
+                  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 Joules
+                  e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * &
+                                       area(ji,jj) * v_i(ji,jj,jl) / &
+                                       nlay_i
+               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) 
+
+      WRITE(numout,*) ' vt_i_init : ', vt_i_init(jiindex,jjindex)
+      WRITE(numout,*) ' vt_i_final: ', vt_i_final(jiindex,jjindex)
+      WRITE(numout,*) ' et_i_init : ', et_i_init(jiindex,jjindex)
+      WRITE(numout,*) ' et_i_final: ', et_i_final(jiindex,jjindex)
+
+      ENDIF
+
+   END SUBROUTINE lim_thd_lac
+
+#else
+   !!======================================================================
+   !!                       ***  MODULE limthd_lac   ***
+   !!                           no sea ice model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE lim_thd_lac           ! Empty routine
+   END SUBROUTINE lim_thd_lac
+#endif
+END MODULE limthd_lac
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_sal.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_sal.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limthd_sal.F90	(revision 884)
@@ -0,0 +1,387 @@
+MODULE limthd_sal
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!======================================================================
+   !!                       ***  MODULE limthd_sal ***
+   !!                   computation salinity variations in
+   !!                               the ice
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   lim_thd_sal : salinity variations in the ice
+   !! * Modules used
+   USE par_oce          ! ocean parameters
+   USE phycst           ! physical constants (ocean directory)
+   USE ice_oce          ! ice variables
+   USE thd_ice
+   USE iceini
+   USE ice
+   USE limistate
+   USE in_out_manager
+   USE limvar
+   USE par_ice
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_thd_sal        ! called by lim_thd
+   PUBLIC lim_thd_sal_init   ! called by lim_thd
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      epsi20 = 1e-20   ,  &
+      epsi13 = 1e-13   ,  &
+      zzero  = 0.e0    ,  &
+      zone   = 1.e0
+
+   CONTAINS
+
+   SUBROUTINE lim_thd_sal(kideb,kiut,jl)
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE lim_thd_sal  ***       
+      !! ** Purpose :
+      !!        This routine computes new salinities in the ice
+      !!
+      !! ** Method  :  4 possibilities
+      !!               -> num_sal = 1 -> constant salinity for z,t
+      !!               -> num_sal = 2 -> S = S(z,t) [simple Vancoppenolle et al 2005]
+      !!               -> num_sal = 3 -> S = S(z)   [multiyear ice]
+      !!               -> num_sal = 4 -> S = S(h)   [Cox and Weeks 74]
+      !!           
+      !! ** Steps
+      !!
+      !! ** Arguments
+      !!
+      !! ** Inputs / Outputs
+      !!
+      !! ** External
+      !!
+      !! ** References
+      !!
+      !! ** History  : 
+      !!
+      !! "Je ne suis pour l'instant qu'a 80% de ma condition, mais c'est 
+      !!  les 30% qui restent qui seront les plus difficiles"
+      !!                                           E. Mpenza
+      !!
+      !!-------------------------------------------------------------------
+      !! History :
+      !!   ori  !  03-05 M. Vancoppenolle UCL-ASTR first coding for LIM-1D
+      !!   3.0  !  05-12 Routine rewritten for the 3-D version
+      !!---------------------------------------------------------------------
+      !!
+      !! * Local variables
+      INTEGER, INTENT(in) :: &
+         kideb, kiut, jl         !: thickness category index
+
+      INTEGER ::             &
+         ji, jk ,            &   !: geographic and layer index 
+         zji, zjj
+
+      REAL(wp) ::            &
+         zsold,              &   !: old salinity
+         zeps=1.0e-06   ,    &   !: very small
+         iflush         ,    &   !: flushing (1) or not (0)
+         iaccrbo        ,    &   !: bottom accretion (1) or not (0)
+         igravdr        ,    &   !: gravity drainage or not
+         isnowic        ,    &   !: gravity drainage or not
+         i_ice_switch   ,    &   !: ice thickness above a certain treshold or not
+         ztmelts        ,    &   !: freezing point of sea ice
+         zaaa           ,    &   !: dummy factor
+         zbbb           ,    &   !: dummy factor
+         zccc           ,    &   !: dummy factor
+         zdiscrim                !: dummy factor
+ 
+      REAL(wp), DIMENSION(jpij) ::          &
+         ze_init        ,    &   !initial total enthalpy
+         zhiold         ,    &
+         zsiold
+
+      !!---------------------------------------------------------------------
+
+!------------------------------------------------------------------------------|
+! 1) Constant salinity, constant in time                                       |
+!------------------------------------------------------------------------------|
+
+      IF (num_sal.eq.1) THEN
+
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_thd_sal : Ice salinity computation module ', &
+         num_sal
+         WRITE(numout,*) '~~~~~~~~~~~~'
+
+         DO jk = 1, nlay_i
+            DO ji = kideb, kiut
+               s_i_b(ji,jk) =  bulk_sal
+            END DO ! ji
+         END DO ! jk
+
+         DO ji = kideb, kiut
+            sm_i_b(ji)      =  bulk_sal 
+         END DO ! ji
+
+      ENDIF ! num_sal .EQ. 1
+
+!------------------------------------------------------------------------------|
+!  Module 2 : Constant salinity varying in time                                |
+!------------------------------------------------------------------------------|
+
+      IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) THEN
+
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_thd_sal : Ice salinity computation module ', &
+         num_sal
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*)
+
+         !---------------------------------
+         ! 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)
+         END DO ! ji
+
+         !---------------------
+         ! Global heat content
+         !---------------------
+
+         ze_init(:)  =  0.0
+         DO jk = 1, nlay_i
+            DO ji = kideb, kiut
+               ze_init(ji) = ze_init(ji) + q_i_b(ji,jk) * ht_i_b(ji) / nlay_i
+            END DO ! ji
+         END DO ! jk
+
+         DO ji = kideb, kiut
+
+            !----------
+            ! Switches 
+            !----------
+
+            ! iflush  : 1 if summer 
+            iflush       =  MAX( 0.0 , SIGN ( 1.0 , t_su_b(ji) - rtt ) ) 
+            ! igravdr : 1 if t_su lt t_bo
+            igravdr      =  MAX( 0.0 , SIGN ( 1.0 , t_bo_b(ji) - t_su_b(ji) ) )
+            ! iaccrbo : 1 if bottom accretion
+            iaccrbo      =  MAX( 0.0 , SIGN ( 1.0 , dh_i_bott(ji) ) )
+            ! isnowic : 1 if snow ice formation
+            i_ice_switch = 1.0 - MAX ( 0.0 , SIGN ( 1.0 , - ht_i_b(ji) + 1.0e-2 ) )
+            isnowic      = 1.0 - MAX ( 0.0 , SIGN ( 1.0 , - dh_snowice(ji) ) ) * &
+                           i_ice_switch
+
+            !---------------------
+            ! Salinity tendencies
+            !---------------------
+
+            ! drainage by gravity drainage
+            dsm_i_gd_1d(ji) = - igravdr *                                     & 
+                                MAX( sm_i_b(ji) - sal_G , 0.0 ) /             &
+                                time_G * rdt_ice 
+
+            ! drainage by flushing  
+            dsm_i_fl_1d(ji)  = - iflush *                                     &
+                                MAX( sm_i_b(ji) - sal_F , 0.0 ) /             & 
+                                time_F * rdt_ice
+
+            !-----------------
+            ! Update salinity   
+            !-----------------
+
+            ! only drainage terms ( gravity drainage and flushing )
+            ! snow ice / bottom sources are added in lim_thd_ent
+            ! to conserve energy
+            zsiold(ji) = sm_i_b(ji)
+            sm_i_b(ji) = sm_i_b(ji)                                           &
+                       + dsm_i_fl_1d(ji) + dsm_i_gd_1d(ji)  !                 &
+
+            ! if no ice, salinity eq 0.1
+            i_ice_switch  = 1.0 - MAX ( 0.0, SIGN (1.0 , - ht_i_b(ji) ) )
+            sm_i_b(ji)    = i_ice_switch*sm_i_b(ji) + s_i_min * ( 1.0 -       &
+                            i_ice_switch )
+         END DO ! ji
+
+         ! Salinity profile
+         CALL lim_var_salprof1d(kideb,kiut)
+
+         !----------------------------
+         ! Heat flux - brine drainage
+         !----------------------------
+
+         DO ji = kideb, kiut
+            ! iflush  : 1 if summer 
+            iflush       =  MAX( 0.0 , SIGN ( 1.0 , t_su_b(ji) - rtt ) ) 
+            ! igravdr : 1 if t_su lt t_bo
+            igravdr      =  MAX( 0.0 , SIGN ( 1.0 , t_bo_b(ji) - t_su_b(ji) ) ) 
+            ! iaccrbo : 1 if bottom accretion
+            iaccrbo      =  MAX( 0.0 , SIGN ( 1.0 , dh_i_bott(ji) ) )
+
+            fhbri_1d(ji) = 0.0
+         END DO ! ji
+
+         !----------------------------
+         ! Salt flux - brine drainage
+         !----------------------------
+         DO ji = kideb, kiut
+            i_ice_switch  = 1.0 - MAX ( 0.0, SIGN (1.0 , - ht_i_b(ji) ) )
+            fsbri_1d(ji) = fsbri_1d(ji) -  &
+                           i_ice_switch * rhoic * a_i_b(ji) * ht_i_b(ji) *  &
+                           ( MAX(dsm_i_gd_1d(ji) + dsm_i_fl_1d(ji), &
+                             sm_i_b(ji) - zsiold(ji) ) ) / rdt_ice
+            IF ( num_sal .EQ. 4 ) fsbri_1d(ji) = 0.0
+
+         END DO ! ji
+
+         ! 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.0) )
+               t_i_b(ji,jk) =  rtt - ( zbbb + zdiscrim ) / & 
+                                     ( 2.0 *zaaa )
+            END DO !ji
+
+         END DO !jk
+
+      ENDIF ! num_sal .EQ. 2
+
+!------------------------------------------------------------------------------|
+!  Module 3 : Profile of salinity, constant in time                            |
+!------------------------------------------------------------------------------|
+
+      IF ( num_sal .EQ. 3 ) THEN
+
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_thd_sal : Ice salinity computation module ', &
+         num_sal
+         WRITE(numout,*) '~~~~~~~~~~~~'
+
+         CALL lim_var_salprof1d(kideb,kiut)
+
+      ENDIF ! num_sal .EQ. 3
+
+!------------------------------------------------------------------------------|
+!  Module 4 : Constant salinity varying in time                                |
+!------------------------------------------------------------------------------|
+
+      ! Cox and Weeks, 1974
+      IF (num_sal.eq.5) THEN
+
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_thd_sal : Ice salinity computation module ', &
+         num_sal
+         WRITE(numout,*) '~~~~~~~~~~~~'
+
+         DO ji = kideb, kiut
+
+            zsold = sm_i_b(ji)
+
+            IF (ht_i_b(ji).lt.0.4) THEN
+               sm_i_b(ji)    = 14.24 - 19.39*ht_i_b(ji) 
+            ELSE
+               sm_i_b(ji)    =  7.88 - 1.59*ht_i_b(ji)
+               sm_i_b(ji)    = MIN(sm_i_b(ji),zsold)  
+            ENDIF
+         
+            IF ( ht_i_b(ji) .GT. 3.06918239 ) THEN 
+               sm_i_b(ji)     = 3.0
+            ENDIF
+
+            DO jk = 1, nlay_i
+               s_i_b(ji,jk)   = sm_i_b(ji)
+            END DO
+      
+         END DO ! ji
+
+      ENDIF ! num_sal
+
+!------------------------------------------------------------------------------|
+! 5) Computation of salt flux due to Bottom growth
+!------------------------------------------------------------------------------|
+
+      IF ( num_sal .EQ. 4 ) THEN
+         DO ji = kideb, kiut
+            zji                 = MOD( npb(ji) - 1, jpi ) + 1
+            zjj                 = ( npb(ji) - 1 ) / jpi + 1
+            fseqv_1d(ji) = fseqv_1d(ji)              + & 
+                           ( sss_io(zji,zjj) - bulk_sal    ) * & 
+                           rhoic * a_i_b(ji) * &
+                           MAX( dh_i_bott(ji) , 0.0 ) / rdt_ice
+         END DO
+      ELSE
+         DO ji = kideb, kiut
+            zji                 = MOD( npb(ji) - 1, jpi ) + 1
+            zjj                 = ( npb(ji) - 1 ) / jpi + 1
+            fseqv_1d(ji) = fseqv_1d(ji)              + & 
+                           ( sss_io(zji,zjj) - s_i_new(ji) ) * & 
+                             rhoic * a_i_b(ji) * &
+                             MAX( dh_i_bott(ji) , 0.0 ) / rdt_ice
+         END DO ! ji
+      ENDIF
+
+!-- End of salinity computations
+   END SUBROUTINE lim_thd_sal
+!==============================================================================
+
+   SUBROUTINE lim_thd_sal_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_thd_sal_init  ***
+      !!
+      !! ** Purpose :   initialization of ice salinity parameters
+      !!
+      !! ** Method  : Read the namicesal namelist and check the parameter
+      !!       values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namicesal
+      !!
+      !! history :
+      !!   3.0  !  July 2005 M. Vancoppenolle  Original code
+      !!-------------------------------------------------------------------
+      NAMELIST/namicesal/ num_sal, bulk_sal, sal_G, time_G, sal_F, time_F, &
+                          s_i_max, s_i_min, s_i_0, s_i_1
+      !!-------------------------------------------------------------------
+
+      ! Read Namelist namicesal
+      REWIND ( numnam_ice )
+      READ   ( numnam_ice  , namicesal )
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_thd_sal_init : Ice parameters for salinity '
+         WRITE(numout,*) '~~~~~~~~~~~~~~~~'
+         WRITE(numout,*) ' switch for salinity num_sal        : ', num_sal
+         WRITE(numout,*) ' bulk salinity value if num_sal = 1 : ', bulk_sal
+         WRITE(numout,*) ' restoring salinity for GD          : ', sal_G
+         WRITE(numout,*) ' restoring time for GD              : ', time_G
+         WRITE(numout,*) ' restoring salinity for flushing    : ', sal_F
+         WRITE(numout,*) ' restoring time for flushing        : ', time_F
+         WRITE(numout,*) ' Maximum tolerated ice salinity     : ', s_i_max
+         WRITE(numout,*) ' Minimum tolerated ice salinity     : ', s_i_min
+         WRITE(numout,*) ' 1st salinity for salinity profile  : ', s_i_0
+         WRITE(numout,*) ' 2nd salinity for salinity profile  : ', s_i_1
+      ENDIF
+
+   END SUBROUTINE lim_thd_sal_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty Module                No sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_thd_sal        ! Empty routine
+   END SUBROUTINE lim_thd_sal
+#endif
+   !!======================================================================
+END MODULE limthd_sal
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limtrp.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limtrp.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limtrp.F90	(revision 884)
@@ -0,0 +1,630 @@
+MODULE limtrp
+   !!======================================================================
+   !!                       ***  MODULE limtrp   ***
+   !! LIM transport ice model : sea-ice advection/diffusion
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_trp      : advection/diffusion process of sea ice
+   !!   lim_trp_init : initialization and namelist read
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE phycst
+   USE dom_oce
+   USE daymod
+   USE in_out_manager  ! I/O manager
+   USE ice_oce         ! ice variables
+   USE dom_ice
+   USE ice
+   USE iceini
+   USE limistate
+   USE limadv
+   USE limhdf
+   USE lbclnk
+   USE lib_mpp
+   USE par_ice
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_trp       ! called by ice_step
+
+   !! * Shared module variables
+   REAL(wp), PUBLIC  ::   &  !:
+      bound  = 0.e0           !: boundary condit. (0.0 no-slip, 1.0 free-slip)
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      epsi06 = 1.e-06  ,  &
+      epsi03 = 1.e-03  ,  &
+      epsi16 = 1.e-16  ,  &
+      rzero  = 0.e0    ,  &
+      rone   = 1.e0    ,  &
+      zeps10 = 1.e-10
+
+   !! * Substitution
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   LIM 3.0,  UCL-ASTR-LOCEAN-IPSL (2008)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limtrp.F90,v 1.5 2005/03/27 18:34:42 opalod Exp $
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE lim_trp
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE lim_trp ***
+      !!                    
+      !! ** purpose : advection/diffusion process of sea ice
+      !!
+      !! ** method  : variables included in the process are scalar,   
+      !!     other values are considered as second order. 
+      !!     For advection, a second order Prather scheme is used.  
+      !!
+      !! ** action :
+      !!
+      !! History :
+      !!   1.0  !  00-01 (M.A. Morales Maqueda, H. Goosse, and T. Fichefet)  Original code
+      !!        !  01-05 (G. Madec, R. Hordoir) opa norm
+      !!   2.0  !  04-01 (G. Madec, C. Ethe)  F90, mpp
+      !!   3.0  !  05-11 (M. Vancoppenolle)   Multi-layer sea ice, salinity variations
+      !!---------------------------------------------------------------------
+      !! * Local Variables
+      INTEGER  ::   ji, jj, jk, jl, layer, &  ! dummy loop indices
+                    initad           ! number of sub-timestep for the advection
+      INTEGER  ::   ji_maxu, ji_maxv, jj_maxu, jj_maxv
+
+      REAL(wp) ::  &                              
+         zindb  ,  &
+         zindsn ,  &
+         zindic ,  &
+         zusvosn,  &
+         zusvoic,  &
+         zvbord ,  &
+         zcfl   ,  &
+         zusnit ,  &
+         zrtt, zsal, zage, &
+         zbigval, ze, &
+         zmaxu, zmaxv
+
+      REAL(wp), DIMENSION(jpi,jpj)  ::   &  ! temporary workspace
+         zui_u , zvi_v , zsm   ,         &
+         zs0at, zs0ow
+
+      REAL(wp), DIMENSION(jpi,jpj,jpl):: &  ! temporary workspace
+         zs0ice, zs0sn, zs0a   ,         &
+         zs0c0 ,                         &
+         zs0sm , zs0oi
+
+! MHE Multilayer heat content
+      REAL(wp), DIMENSION(jpi,jpj,jkmax,jpl)  ::   &  ! temporary workspace
+         zs0e
+
+      !---------------------------------------------------------------------
+
+      IF( numit == nstart  )   CALL lim_trp_init      ! Initialization (first time-step only)
+
+      zsm(:,:) = area(:,:)
+      
+      IF( ln_limdyn ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' lim_trp : Ice Advection'
+         WRITE(numout,*) ' ~~~~~~~'
+
+!-----------------------------------------------------------------------------!
+! 1) CFL Test                                                             
+!-----------------------------------------------------------------------------!
+
+         !------------------------------------------
+         ! ice velocities at ocean U- and V-points 
+         !------------------------------------------
+         
+         ! zvbord factor between 1 and 2 to take into account slip or no-slip boundary conditions.        
+         zvbord = 1.0 + ( 1.0 - bound )
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1
+               zui_u(ji,jj) = u_ice(ji,jj)
+               zvi_v(ji,jj) = v_ice(ji,jj)
+            END DO
+         END DO
+
+         ! Lateral boundary conditions
+         CALL lbc_lnk( zui_u, 'U', -1. )
+         CALL lbc_lnk( zvi_v, 'V', -1. )
+
+         !-------------------------
+         ! CFL test for stability
+         !-------------------------
+
+         zcfl  = 0.e0
+         zcfl  = MAX( zcfl, MAXVAL( ABS( zui_u(1:jpim1, :     ) ) * rdt_ice / e1u(1:jpim1, :     ) ) )
+         zcfl  = MAX( zcfl, MAXVAL( ABS( zvi_v( :     ,1:jpjm1) ) * rdt_ice / e2v( :     ,1:jpjm1) ) )
+
+         zmaxu = 0.0
+         zmaxv = 0.0
+         DO ji = 1, jpim1
+            DO jj = 1, jpjm1
+               IF ( (ABS(zui_u(ji,jj)) .GT. zmaxu) ) THEN 
+                  zmaxu = MAX(zui_u(ji,jj), zmaxu )
+                  ji_maxu = ji
+                  jj_maxu = jj
+               ENDIF
+               IF ( (ABS(zvi_v(ji,jj)) .GT. zmaxv) ) THEN 
+                  zmaxv = MAX(zvi_v(ji,jj), zmaxv )
+                  ji_maxv = ji
+                  jj_maxv = jj
+               ENDIF
+            END DO
+         END DO
+
+         IF (lk_mpp ) CALL mpp_max(zcfl)
+
+         IF ( zcfl > 0.5 .AND. lwp ) &
+         WRITE(numout,*) 'lim_trp : violation of cfl criterion the ',nday,'th day, cfl = ',zcfl
+
+!-----------------------------------------------------------------------------!
+! 2) Computation of transported fields                                        
+!-----------------------------------------------------------------------------!
+
+         !------------------------------------------------------
+         ! 1.1) Snow vol, ice vol, salt and age contents, area
+         !------------------------------------------------------
+
+         zs0ow (:,:) =  ato_i(:,:)    * area(:,:)           ! Open water area 
+         DO jl = 1, jpl  !sum over thickness categories
+            ! area -> is the unmasked and masked area of T-grid cell
+            zs0sn (:,:,jl) =  v_s(:,:,jl)    * area(:,:)    ! Snow volume.
+            zs0ice(:,:,jl) =  v_i(:,:,jl)    * area(:,:)    ! Ice volume.
+            zs0a  (:,:,jl) =  a_i(:,:,jl)    * area(:,:)    ! Ice area
+            zs0sm (:,:,jl) =  smv_i(:,:,jl)  * area(:,:)    ! Salt content
+            zs0oi (:,:,jl) =  oa_i (:,:,jl)  * area(:,:)    ! Age content
+
+         !----------------------------------
+         ! 1.2) Ice and snow heat contents
+         !----------------------------------
+
+            zs0c0 (:,:,jl)     = e_s(:,:,1,jl)              ! Snow heat cont.
+            DO jk = 1, nlay_i
+               zs0e(:,:,jk,jl) = e_i(:,:,jk,jl)             ! Ice heat content
+            END DO
+         END DO
+
+!-----------------------------------------------------------------------------!
+! 3) Advection of Ice fields                                              
+!-----------------------------------------------------------------------------!
+
+         ! If ice drift field is too fast, use an appropriate time step for advection.         
+         initad = 1 + INT( MAX( rzero, SIGN( rone, zcfl-0.5 ) ) )
+         zusnit = 1.0 / REAL( initad ) 
+         
+         IF ( MOD( nday , 2 ) == 0) THEN
+            DO jk = 1,initad
+               !--- ice open water area
+               CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0ow(:,:) , sxopw(:,:) , & 
+                                                          sxxopw(:,:), syopw(:,:) , & 
+                                                          syyopw(:,:), sxopw(:,:) )
+               CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0ow(:,:) , sxopw (:,:) , &
+                                                          sxxopw(:,:), syopw (:,:) , & 
+                                                          syyopw(:,:), sxyopw(:,:) )
+               DO jl = 1, jpl
+                  !--- ice volume  ---
+                  CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0ice(:,:,jl) , sxice (:,:,jl) , & 
+                                                             sxxice(:,:,jl) , syice (:,:,jl) , & 
+                                                             syyice(:,:,jl) , sxyice(:,:,jl) )
+                  CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0ice(:,:,jl) , sxice (:,:,jl) , &
+                                                             sxxice(:,:,jl) , syice (:,:,jl) , & 
+                                                             syyice(:,:,jl) , sxyice(:,:,jl) )
+                  !--- snow volume  ---
+                  CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0sn (:,:,jl) , sxsn  (:,:,jl) , &
+                                                             sxxsn (:,:,jl) , sysn  (:,:,jl) , &
+                                                             syysn (:,:,jl) , sxysn (:,:,jl) )
+                  CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0sn (:,:,jl) , sxsn  (:,:,jl) , &
+                                                             sxxsn (:,:,jl) , sysn  (:,:,jl) , &
+                                                             syysn (:,:,jl) , sxysn (:,:,jl) )
+                  !--- ice salinity ---
+                  CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0sm (:,:,jl) , sxsal (:,:,jl) , &
+                                                             sxxsal(:,:,jl) , sysal (:,:,jl) , &
+                                                             syysal(:,:,jl) , sxysal(:,:,jl)  )
+                  CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0sm (:,:,jl) , sxsal (:,:,jl) , &
+                                                             sxxsal(:,:,jl) , sysal (:,:,jl) , &
+                                                             syysal(:,:,jl) , sxysal(:,:,jl)  )
+                  !--- ice age      ---     
+                  CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0oi (:,:,jl) , sxage (:,:,jl) , &
+                                                             sxxage(:,:,jl) , syage (:,:,jl) , &
+                                                             syyage(:,:,jl) , sxyage(:,:,jl)  )
+                  CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0oi (:,:,jl) , sxage (:,:,jl) , &
+                                                             sxxage(:,:,jl) , syage (:,:,jl) , &
+                                                             syyage(:,:,jl) , sxyage(:,:,jl)  )
+                  !--- ice concentrations ---
+                  CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0a  (:,:,jl) , sxa   (:,:,jl) , &
+                                                             sxxa  (:,:,jl) , sya   (:,:,jl) , & 
+                                                             syya  (:,:,jl) , sxya  (:,:,jl)  )
+                  CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0a  (:,:,jl) , sxa   (:,:,jl) , & 
+                                                             sxxa  (:,:,jl) , sya   (:,:,jl) , & 
+                                                             syya  (:,:,jl) , sxya  (:,:,jl)  )
+                  !--- ice / snow thermal energetic contents ---
+                  CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0c0 (:,:,jl) , sxc0  (:,:,jl) , & 
+                                                             sxxc0 (:,:,jl) , syc0  (:,:,jl) , &
+                                                             syyc0 (:,:,jl) , sxyc0 (:,:,jl)  )
+                  CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0c0 (:,:,jl) , sxc0  (:,:,jl) , &
+                                                             sxxc0 (:,:,jl) , syc0  (:,:,jl) , &
+                                                             syyc0 (:,:,jl) , sxyc0 (:,:,jl)  )
+                  DO layer = 1, nlay_i
+                     CALL lim_adv_x( zusnit, zui_u, 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, zvi_v, rzero, zsm, & 
+                                                             zs0e(:,:,layer,jl) , sxe (:,:,layer,jl) , & 
+                                                             sxxe(:,:,layer,jl) , sye (:,:,layer,jl) , &
+                                                             syye(:,:,layer,jl) , sxye(:,:,layer,jl) )
+                  END DO
+               END DO
+            END DO
+         ELSE
+            DO jk = 1, initad
+               !--- ice volume  ---
+               CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0ow (:,:) , sxopw (:,:) , &
+                                                          sxxopw(:,:) , syopw (:,:) , & 
+                                                          syyopw(:,:) , sxyopw(:,:) )
+               CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0ow (:,:) , sxopw (:,:) , & 
+                                                          sxxopw(:,:) , syopw (:,:) , &
+                                                          syyopw(:,:) , sxyopw(:,:) )
+               DO jl = 1, jpl
+                  !--- ice volume  ---
+                  CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0ice(:,:,jl) , sxice (:,:,jl) , &
+                                                             sxxice(:,:,jl) , syice (:,:,jl) , & 
+                                                             syyice(:,:,jl) , sxyice(:,:,jl) )
+                  CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0ice(:,:,jl) , sxice (:,:,jl) , & 
+                                                             sxxice(:,:,jl) , syice (:,:,jl) , &
+                                                             syyice(:,:,jl) , sxyice(:,:,jl) )
+                  !--- snow volume  ---
+                  CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0sn (:,:,jl) , sxsn  (:,:,jl) , & 
+                                                             sxxsn (:,:,jl) , sysn  (:,:,jl) , & 
+                                                             syysn (:,:,jl) , sxysn (:,:,jl) )
+                  CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0sn (:,:,jl) , sxsn  (:,:,jl) , & 
+                                                             sxxsn (:,:,jl) , sysn  (:,:,jl) , & 
+                                                             syysn (:,:,jl) , sxysn (:,:,jl) )
+                  !--- ice salinity ---
+                  CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0sm (:,:,jl) , sxsal (:,:,jl) , &
+                                                             sxxsal(:,:,jl) , sysal (:,:,jl) , &
+                                                             syysal(:,:,jl) , sxysal(:,:,jl) )
+                  CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0sm (:,:,jl) , sxsal (:,:,jl) , &
+                                                             sxxsal(:,:,jl) , sysal (:,:,jl) , &
+                                                             syysal(:,:,jl) , sxysal(:,:,jl) )
+                  !--- ice age      ---
+                  CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0oi (:,:,jl) , sxage (:,:,jl) , &
+                                                             sxxage(:,:,jl) , syage (:,:,jl) , & 
+                                                             syyage(:,:,jl) , sxyage(:,:,jl)  )
+                  CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0oi (:,:,jl) , sxage (:,:,jl) , &
+                                                             sxxage(:,:,jl) , syage (:,:,jl) , &
+                                                             syyage(:,:,jl) , sxyage(:,:,jl)   )
+                  !--- ice concentration ---
+                  CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0a  (:,:,jl) , sxa   (:,:,jl) , & 
+                                                             sxxa  (:,:,jl) , sya   (:,:,jl) , & 
+                                                             syya  (:,:,jl) , sxya  (:,:,jl)  )
+                  CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0a  (:,:,jl) , sxa   (:,:,jl) , & 
+                                                             sxxa  (:,:,jl) , sya   (:,:,jl) , & 
+                                                             syya  (:,:,jl) , sxya  (:,:,jl)  )
+                  !--- ice / snow thermal energetic contents ---
+                  CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0c0 (:,:,jl) , sxc0  (:,:,jl) , & 
+                                                             sxxc0 (:,:,jl) , syc0  (:,:,jl) , &
+                                                             syyc0 (:,:,jl) , sxyc0 (:,:,jl)  )
+                  CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0c0 (:,:,jl) , sxc0  (:,:,jl) , &
+                                                             sxxc0 (:,:,jl) , syc0  (:,:,jl) , &
+                                                             syyc0 (:,:,jl) , sxyc0 (:,:,jl)  )
+                  DO layer = 1, nlay_i
+                     CALL lim_adv_y( zusnit, zvi_v, 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, zui_u, rzero, zsm, zs0e(:,:,layer,jl) , &
+                                     sxe (:,:,layer,jl) , sxxe (:,:,layer,jl) , sye (:,:,layer,jl) , &
+                                     syye (:,:,layer,jl), sxye (:,:,layer,jl)  )
+                  END DO
+
+               END DO
+            END DO
+         ENDIF
+
+         !-------------------------------------------
+         ! Recover the properties from their contents
+         !-------------------------------------------
+
+         zs0ow (:,:)       = zs0ow(:,:) / area(:,:)
+         DO jl = 1, jpl
+            zs0ice(:,:,jl) = zs0ice(:,:,jl) / area(:,:)
+            zs0sn (:,:,jl) = zs0sn (:,:,jl) / area(:,:)
+            zs0sm (:,:,jl) = zs0sm (:,:,jl) / area(:,:)
+            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
+
+!------------------------------------------------------------------------------!
+! 4) Diffusion of Ice fields                  
+!------------------------------------------------------------------------------!
+
+      !------------------------------------
+      ! 4.1) diffusion of open water area
+      !------------------------------------
+
+         ! Compute total ice fraction
+         zs0at(:,:) = 0.0
+         DO jl = 1, jpl
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zs0at (ji,jj) = zs0at(ji,jj) + zs0a(ji,jj,jl) !
+               END DO
+            END DO 
+         END DO
+
+         ! Masked eddy diffusivity coefficient at ocean U- and V-points
+         DO jj = 1, jpjm1          ! NB: has not to be defined on jpj line and jpi row
+            DO ji = 1 , fs_jpim1   ! vector opt.
+               pahu(ji,jj) = ( 1.0 - MAX( rzero, SIGN( rone, -zs0at(ji  ,jj) ) ) )   &
+                  &        * ( 1.0 - MAX( rzero, SIGN( rone, -zs0at(ji+1,jj) ) ) ) * ahiu(ji,jj)
+               pahv(ji,jj) = ( 1.0 - MAX( rzero, SIGN( rone, -zs0at(ji,jj  ) ) ) )   &
+                  &        * ( 1.0 - MAX( rzero, SIGN( rone,- zs0at(ji,jj+1) ) ) ) * ahiv(ji,jj)
+            END DO !jj
+         END DO ! ji
+
+         ! Diffusion
+         CALL lim_hdf( zs0ow (:,:) )
+
+      !----------------------------------------
+      ! 4.2) Diffusion of other ice variables
+      !----------------------------------------
+         DO jl = 1, jpl
+
+         ! Masked eddy diffusivity coefficient at ocean U- and V-points
+            DO jj = 1, jpjm1          ! NB: has not to be defined on jpj line and jpi row
+               DO ji = 1 , fs_jpim1   ! vector opt.
+                  pahu(ji,jj) = ( 1.0 - MAX( rzero, SIGN( rone, -zs0a(ji  ,jj,jl) ) ) )   &
+                     &        * ( 1.0 - MAX( rzero, SIGN( rone, -zs0a(ji+1,jj,jl) ) ) ) * ahiu(ji,jj)
+                  pahv(ji,jj) = ( 1.0 - MAX( rzero, SIGN( rone, -zs0a(ji,jj,jl  ) ) ) )   &
+                     &        * ( 1.0 - MAX( rzero, SIGN( rone,- zs0a(ji,jj+1,jl) ) ) ) * ahiv(ji,jj)
+               END DO !jj
+            END DO ! ji
+
+            CALL lim_hdf( zs0ice (:,:,jl) )
+            CALL lim_hdf( zs0sn  (:,:,jl) )
+            CALL lim_hdf( zs0sm  (:,:,jl) )
+            CALL lim_hdf( zs0oi  (:,:,jl) )
+            CALL lim_hdf( zs0a   (:,:,jl) )
+            CALL lim_hdf( zs0c0  (:,:,jl) )
+            DO jk = 1, nlay_i
+               CALL lim_hdf( zs0e (:,:,jk,jl) )
+            END DO ! jk
+         END DO !jl
+
+      !-----------------------------------------
+      ! 4.3) Remultiply everything by ice area
+      !-----------------------------------------
+         zs0ow(:,:) = MAX(rzero, zs0ow(:,:) * area(:,:) )
+         DO jl = 1, jpl
+            zs0ice(:,:,jl) = MAX( rzero, zs0ice(:,:,jl) * area(:,:) )    !!bug:  est-ce utile
+            zs0sn (:,:,jl) = MAX( rzero, zs0sn (:,:,jl) * area(:,:) )    !!bug:  cf /area  juste apres
+            zs0sm (:,:,jl) = MAX( rzero, zs0sm (:,:,jl) * area(:,:) )    !!bug:  cf /area  juste apres
+            zs0oi (:,:,jl) = MAX( rzero, zs0oi (:,:,jl) * area(:,:) )
+            zs0a  (:,:,jl) = MAX( rzero, zs0a  (:,:,jl) * area(:,:) )    !! suppress both change le resultat
+            zs0c0 (:,:,jl) = MAX( rzero, zs0c0 (:,:,jl) * area(:,:) )
+            DO jk = 1, nlay_i
+               zs0e(:,:,jk,jl) = MAX( rzero, zs0e (:,:,jk,jl) * area(:,:) )
+            END DO ! jk
+         END DO ! jl
+
+!------------------------------------------------------------------------------!
+! 5) Update and limit ice properties after transport                           
+!------------------------------------------------------------------------------!
+
+      !--------------------------------------------------
+      ! 5.1) Recover mean values over the grid squares.
+      !--------------------------------------------------
+
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zs0e (ji,jj,jk,jl) =  &
+                     MAX( rzero, zs0e (ji,jj,jk,jl) / area(ji,jj) )
+                  END DO
+               END DO
+            END DO
+         END DO
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zs0ow (ji,jj) = MAX( rzero, zs0ow (ji,jj) / area(ji,jj) )
+            END DO
+         END DO
+         
+         zs0at(:,:) = 0.0
+         DO jl = 1, jpl
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zs0sn (ji,jj,jl) = MAX( rzero, zs0sn (ji,jj,jl)/area(ji,jj) )
+                  zs0ice(ji,jj,jl) = MAX( rzero, zs0ice(ji,jj,jl)/area(ji,jj) )
+                  zs0sm (ji,jj,jl) = MAX( rzero, zs0sm (ji,jj,jl)/area(ji,jj) )
+                  zs0oi (ji,jj,jl) = MAX( rzero, zs0oi (ji,jj,jl)/area(ji,jj) )
+                  zs0a  (ji,jj,jl) = MAX( rzero, zs0a  (ji,jj,jl)/area(ji,jj) )
+                  zs0c0 (ji,jj,jl) = MAX( rzero, zs0c0 (ji,jj,jl)/area(ji,jj) )
+                  zs0at (ji,jj)    = zs0at(ji,jj) + zs0a(ji,jj,jl)
+               END DO
+            END DO
+         END DO
+
+      !---------------------------------------------------------
+      ! 5.2) Snow thickness, Ice thickness, Ice concentrations
+      !---------------------------------------------------------
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zindb         = MAX( 0.0 , SIGN( 1.0, zs0at(ji,jj) - zeps10) )
+               zs0ow(ji,jj)  = (1.0 - zindb) + zindb*MAX( zs0ow(ji,jj), 0.00 )
+               ato_i(ji,jj)  = zs0ow(ji,jj)
+            END DO
+         END DO
+
+         ! Remove very small areas 
+         DO jl = 1, jpl
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zindb         = MAX( 0.0 , SIGN( 1.0, zs0a(ji,jj,jl) - zeps10) )
+
+                  zs0a(ji,jj,jl)  = zindb * MIN( zs0a(ji,jj,jl), 0.99 )
+                  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) - zeps10 ) )
+                  zindic          = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - zeps10 ) )
+                  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)
+               END DO
+            END DO
+         END DO
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zs0at(ji,jj)       = SUM( zs0a(ji,jj,1:jpl) )
+            END DO
+         END DO
+
+      !----------------------
+      ! 5.3) Ice properties
+      !----------------------
+
+         zbigval         =  1.0d+13
+
+         DO jl = 1, jpl
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+
+                  ! Switches and dummy variables
+                  zusvosn         = 1.0/MAX( v_s(ji,jj,jl) , epsi16 )
+                  zusvoic         = 1.0/MAX( v_i(ji,jj,jl) , epsi16 )
+                  zrtt            = 173.15 * rone 
+                  zindsn          = MAX( rzero, SIGN( rone, v_s(ji,jj,jl) - zeps10 ) )
+                  zindic          = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - zeps10 ) )
+                  zindb           = MAX( zindsn, zindic )
+
+                  ! Ice salinity and age
+                  zsal            = MAX( MIN( (rhoic-rhosn)/rhoic*sss_io(ji,jj)  , &
+                                            zusvoic * zs0sm(ji,jj,jl) ), s_i_min ) * &
+                                            v_i(ji,jj,jl)
+                  IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) & 
+                     smv_i(ji,jj,jl) = zindic*zsal + (1.0-zindic)*0.0
+
+                  zage            = MAX( MIN( zbigval, zs0oi(ji,jj,jl) / & 
+                                              MAX( a_i(ji,jj,jl), epsi16 )  ), 0.0 ) * &
+                                              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 + (1.0 - zindsn) * 0.0      
+
+               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) - zeps10 ) )
+                     ze              =  MIN( MAX( 0.0, zs0e(ji,jj,jk,jl)*area(ji,jj) ), zbigval )
+                     e_i(ji,jj,jk,jl) = zindic * ze    + ( 1.0 - zindic ) * 0.0
+                  END DO !ji
+               END DO ! jj
+            END DO ! jk
+         END DO ! jl
+
+      ENDIF
+
+      IF(ln_ctl) THEN   ! Control print
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Cell values : ')
+         CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
+         CALL prt_ctl(tab2d_1=area , clinfo1=' lim_trp  : cell area :')
+         CALL prt_ctl(tab2d_1=at_i , clinfo1=' lim_trp  : at_i      :')
+         CALL prt_ctl(tab2d_1=vt_i , clinfo1=' lim_trp  : vt_i      :')
+         CALL prt_ctl(tab2d_1=vt_s , clinfo1=' lim_trp  : vt_s      :')
+         DO jl = 1, jpl
+            CALL prt_ctl_info(' ')
+            CALL prt_ctl_info(' - Category : ', ivar1=jl)
+            CALL prt_ctl_info('   ~~~~~~~~~~')
+            CALL prt_ctl(tab2d_1=a_i   (:,:,jl)   , clinfo1= ' lim_trp  : a_i      : ')
+            CALL prt_ctl(tab2d_1=ht_i  (:,:,jl)   , clinfo1= ' lim_trp  : ht_i     : ')
+            CALL prt_ctl(tab2d_1=ht_s  (:,:,jl)   , clinfo1= ' lim_trp  : ht_s     : ')
+            CALL prt_ctl(tab2d_1=v_i   (:,:,jl)   , clinfo1= ' lim_trp  : v_i      : ')
+            CALL prt_ctl(tab2d_1=v_s   (:,:,jl)   , clinfo1= ' lim_trp  : v_s      : ')
+            CALL prt_ctl(tab2d_1=e_s   (:,:,1,jl) , clinfo1= ' lim_trp  : e_s      : ')
+            CALL prt_ctl(tab2d_1=t_su  (:,:,jl)   , clinfo1= ' lim_trp  : t_su     : ')
+            CALL prt_ctl(tab2d_1=t_s   (:,:,1,jl) , clinfo1= ' lim_trp  : t_snow   : ')
+            CALL prt_ctl(tab2d_1=sm_i  (:,:,jl)   , clinfo1= ' lim_trp  : sm_i     : ')
+            CALL prt_ctl(tab2d_1=smv_i (:,:,jl)   , clinfo1= ' lim_trp  : smv_i    : ')
+            DO jk = 1, nlay_i
+               CALL prt_ctl_info(' ')
+               CALL prt_ctl_info(' - Layer : ', ivar1=jk)
+               CALL prt_ctl_info('   ~~~~~~~')
+               CALL prt_ctl(tab2d_1=t_i(:,:,jk,jl) , clinfo1= ' lim_trp  : t_i      : ')
+               CALL prt_ctl(tab2d_1=e_i(:,:,jk,jl) , clinfo1= ' lim_trp  : e_i      : ')
+            END DO
+         END DO
+      ENDIF
+
+   END SUBROUTINE lim_trp
+
+
+   SUBROUTINE lim_trp_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_trp_init  ***
+      !!
+      !! ** Purpose :   initialization of ice advection parameters
+      !!
+      !! ** Method  : Read the namicetrp namelist and check the parameter 
+      !!       values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namicetrp
+      !!
+      !! history :
+      !!   2.0  !  03-08 (C. Ethe)  Original code
+      !!-------------------------------------------------------------------
+      NAMELIST/namicetrp/ bound
+      !!-------------------------------------------------------------------
+
+      ! Read Namelist namicetrp
+      REWIND ( numnam_ice )
+      READ   ( numnam_ice  , namicetrp )
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_trp_init : Ice parameters for advection '
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) ' boundary conditions (0.0 no-slip, 1.0 free-slip) bound  = ', bound
+         WRITE(numout,*) 
+      ENDIF
+            
+   END SUBROUTINE lim_trp_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty Module                No sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_trp        ! Empty routine
+   END SUBROUTINE lim_trp
+#endif
+
+   !!======================================================================
+END MODULE limtrp
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limupdate.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limupdate.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limupdate.F90	(revision 884)
@@ -0,0 +1,1115 @@
+MODULE limupdate
+   !!======================================================================
+   !!                     ***  MODULE  limupdate  ***
+   !!    Update of sea-ice global variables
+   !!    at the end of the time step
+   !!    
+   !!    Ice speed from ice dynamics
+   !!    Ice thickness, Snow thickness, Temperatures, Lead fraction
+   !!      from advection and ice thermodynamics 
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!    lim_update   : computes update of sea-ice global variables 
+   !!                   from trend terms
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE limistate
+   USE limrhg          ! ice rheology
+   USE lbclnk
+
+   USE dom_oce
+   USE oce             ! dynamics and tracers variables
+   USE in_out_manager
+   USE ice_oce         ! ice variables
+   USE flx_oce         ! forcings variables
+   USE dom_ice
+   USE daymod
+   USE phycst          ! Define parameters for the routines
+   USE taumod
+   USE ice
+   USE iceini
+   USE ocesbc
+   USE lbclnk
+   USE limdyn
+   USE limtrp
+   USE limthd
+   USE limflx
+   USE limdia
+   USE limwri
+   USE limrst
+   USE thd_ice         ! LIM thermodynamic sea-ice variables
+   USE par_ice
+   USE limitd_th
+   USE limvar
+   USE prtctl          ! Print control
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC lim_update ! routine called by ice_step
+
+   !! * Module variables
+
+   !!----------------------------------------------------------------------
+   !!   LIM 2.1 , UCL-ASTR-LODYC-IPSL  (2004)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_update
+      !!-------------------------------------------------------------------
+      !!               ***  ROUTINE lim_update  ***
+      !!               
+      !! ** Purpose :  Computes update of sea-ice global variables at 
+      !!               the end of the time step.
+      !!               Address pathological cases
+      !!               This place is very important
+      !!                
+      !! ** Method  :  Mathematical
+      !!
+      !! ** Action  : - 
+      !!
+      !! History : This routine was new for LIM 3.0 
+      !!   3.0  !  04-06  (M. Vancoppenolle) Tendencies
+      !!---------------------------------------------------------------------
+      !! * Local variables
+      INTEGER ::      &
+          ji, jj,     & ! geographical indices
+          jk, jl, jm    ! layer, category and type indices
+      INTEGER ::      &
+          jbnd1, jbnd2
+      INTEGER ::      &
+          i_ice_switch
+
+      REAL(wp)  ::           &  ! constant values
+         epsi06 = 1.e-06  ,  &
+         epsi03 = 1.e-03  ,  &
+         epsi16 = 1.e-16  ,  &
+         epsi20 = 1.e-20  ,  &
+         epsi04 = 1.e-04  ,  &
+         epsi10 = 1.e-10  ,  &
+         rzero  = 0.e0    ,  &
+         rone   = 1.e0    ,  &
+         zhimax                   ! maximum thickness tolerated for advection of
+                                  ! in an ice-free cell
+      REAL(wp) ::            &  ! dummy switches and arguments
+         zindb, zindsn, zindic, zacrith,  &
+         zrtt, zindg, zh, zdvres, zviold,                       &
+         zbigvalue, zvsold, z_da_ex, zamax,                     &
+         z_prescr_hi, zat_i_old,                                &
+         ztmelts, ze_s
+
+      REAL(wp), DIMENSION(jpl) :: z_da_i, z_dv_i
+
+      LOGICAL, DIMENSION(jpi,jpj,jpl) ::  &
+         internal_melt
+
+      INTEGER ::      &
+         ind_im, layer      ! indices for internal melt
+      REAL(wp), DIMENSION(jkmax) :: &
+         zthick0, zqm0      ! thickness of the layers and heat contents for
+                            ! internal melt
+      REAL(wp) ::                   &
+         zweight, zesum
+        
+
+      !!-------------------------------------------------------------------
+
+      WRITE(numout,*) ' lim_update '
+      WRITE(numout,*) ' ~~~~~~~~~~ '
+
+!+++++ [
+        WRITE(numout,*) ' O) Initial values '
+        WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' at_i: ', at_i(jiindex,jjindex)
+        WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+        DO jk = 1, nlay_i
+        WRITE(numout,*) ' e_i : ', e_i(jiindex, jjindex, jk, 1:jpl)
+        END DO
+!+++++ ]
+
+!------------------------------------------------------------------------------
+! 1. Update of Global variables                                               |
+!------------------------------------------------------------------------------
+
+     !---------------------
+     ! Ice dynamics  
+     !---------------------
+
+     u_ice(:,:) = u_ice(:,:) + d_u_ice_dyn(:,:)
+     v_ice(:,:) = v_ice(:,:) + d_v_ice_dyn(:,:)
+
+     !-----------------------------
+     ! Update ice and snow volumes  
+     !-----------------------------
+
+     DO jl = 1, jpl
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+
+              v_i(ji,jj,jl)  = v_i(ji,jj,jl) + d_v_i_trp(ji,jj,jl)  &
+                                             + d_v_i_thd(ji,jj,jl) 
+              v_s(ji,jj,jl)  = v_s(ji,jj,jl) + d_v_s_trp(ji,jj,jl)  &
+                                             + d_v_s_thd(ji,jj,jl)
+           END DO
+        END DO
+     END DO
+
+     !---------------------------------
+     ! Classify the pathological cases
+     !---------------------------------
+     ! (1) v_i (new) > 0; d_v_i_thd + v_i(old) > 0 (easy case)
+     ! (2) v_i (new) > 0; d_v_i_thd + v_i(old) = 0 (total thermodynamic ablation)
+     ! (3) v_i (new) < 0; d_v_i_thd + v_i(old) > 0 (combined total ablation)
+     ! (4) v_i (new) < 0; d_v_i_thd + v_i(old) = 0 (total thermodynamic ablation 
+     ! with negative advection, very pathological )
+     ! (5) v_i (old) = 0; d_v_i_trp > 0 (advection of ice in a free-cell)
+
+     DO jl = 1, jpl
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              patho_case(ji,jj,jl) = 1
+              IF ( v_i(ji,jj,jl) .GE. 0.0 ) THEN
+                 IF ( old_v_i(ji,jj,jl) + d_v_i_thd(ji,jj,jl) .LT. epsi10 ) THEN 
+                    patho_case(ji,jj,jl) = 2
+                 ENDIF
+              ELSE
+                 patho_case(ji,jj,jl) = 3
+                 IF ( old_v_i(ji,jj,jl) + d_v_i_thd(ji,jj,jl) .LT. epsi10 ) THEN 
+                    patho_case(ji,jj,jl) = 4
+                 ENDIF
+              ENDIF
+              IF ( ( old_v_i(ji,jj,jl) .LE. epsi10 ) .AND. &
+                   ( d_v_i_trp(ji,jj,jl) .GT. epsi06 ) ) THEN
+                 patho_case(ji,jj,jl) = 5 ! advection of ice in an ice-free
+                                             ! cell
+                 WRITE(numout,*) ' ALERTE patho_case still equal to 5 '
+                 WRITE(numout,*) ' ji , jj   : ', ji, jj
+                 WRITE(numout,*) ' old_v_i   : ', old_v_i(ji,jj,jl)
+                 WRITE(numout,*) ' d_v_i_trp : ', d_v_i_trp(ji,jj,jl)
+
+              ENDIF
+           END DO
+        END DO
+     END DO
+
+     !--------------------
+     ! Excessive ablation 
+     !--------------------
+
+     DO jl = 1, jpl
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              IF (      ( patho_case(ji,jj,jl) .EQ. 3 ) &
+                   .OR. ( patho_case(ji,jj,jl) .EQ. 4 ) ) THEN
+              zviold         = old_v_i(ji,jj,jl)
+              zvsold         = old_v_s(ji,jj,jl)
+              ! in cases 3 ( combined total ablation )
+              !      and 4 ( total ablation with negative advection )
+              ! there is excessive total ablation
+              ! advection is chosen to be prioritary in order to conserve mass. 
+              ! dv_i_thd is computed as a residual
+              ! negative energy has to be kept in memory and to be given to the ocean
+              ! equivalent salt flux is given to the ocean
+              !
+              ! This was the best solution found. Otherwise, mass conservation in advection
+              ! scheme should have been revised, which could have been a big problem
+              ! Martin Vancoppenolle (2006, updated 2007)
+
+              ! is there any ice left ?
+              zindic        = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) ) 
+              !=1 if hi > 1e-3 and 0 if not
+              zdvres        = MAX(0.0,-v_i(ji,jj,jl)) !residual volume if too much ice was molten
+                                                      !this quantity is positive
+              v_i(ji,jj,jl) = zindic*v_i(ji,jj,jl)    !ice volume cannot be negative
+                                 !correct thermodynamic ablation
+              d_v_i_thd(ji,jj,jl)  = zindic  *  d_v_i_thd(ji,jj,jl) + & 
+                                (1.0-zindic) * (-zviold - d_v_i_trp(ji,jj,jl)) 
+              ! THIS IS NEW
+              d_a_i_thd(ji,jj,jl)  = zindic  *  d_a_i_thd(ji,jj,jl) + & 
+                                (1.0-zindic) * (-old_a_i(ji,jj,jl)) 
+
+              !residual salt flux if ice is over-molten
+              fsalt_res(ji,jj)  = fsalt_res(ji,jj) + ( sss_io(ji,jj) - sm_i(ji,jj,jl) ) * & 
+                             ( rhoic * zdvres / rdt_ice )
+!             fheat_res(ji,jj)  = fheat_res(ji,jj) + rhoic * lfus * zdvres / rdt_ice
+
+              ! is there any snow left ?
+              zindsn        = MAX( rzero, SIGN( rone, v_s(ji,jj,jl) - epsi10 ) ) 
+              zvsold        = v_s(ji,jj,jl)
+              zdvres        = MAX(0.0,-v_s(ji,jj,jl)) !residual volume if too much ice was molten
+                                                      !this quantity is positive
+              v_s(ji,jj,jl) = zindsn*v_s(ji,jj,jl)    !snow volume cannot be negative
+                                                      !correct thermodynamic ablation
+              d_v_s_thd(ji,jj,jl)  = zindsn  *  d_v_s_thd(ji,jj,jl) + & 
+                                 (1.0-zindsn) * (-zvsold - d_v_s_trp(ji,jj,jl)) 
+              !unsure correction on salt flux.... maybe future will tell it was not that right
+
+              !residual salt flux if snow is over-molten
+              fsalt_res(ji,jj)  = fsalt_res(ji,jj) + sss_io(ji,jj) * & 
+                             ( rhosn * zdvres / rdt_ice )
+                             !this flux will be positive if snow was over-molten
+!             fheat_res(ji,jj)  = fheat_res(ji,jj) + rhosn * lfus * zdvres / rdt_ice
+              ENDIF
+           END DO !ji
+        END DO !jj
+     END DO !jl
+
+!+++++ [
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           IF ( ABS(fsalt_res(ji,jj)) .GT. 1.0 ) THEN 
+              WRITE(numout,*) ' ALERTE 1000 : residual salt flux of -> ', &
+              fsalt_res(ji,jj)
+              WRITE(numout,*) ' ji, jj : ', ji, jj, ' gphit, glamt : ', &
+              gphit(ji,jj), glamt(ji,jj)
+           ENDIF
+        END DO
+     END DO
+
+     WRITE(numout,*) ' 1. Before update of Global variables '
+     WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+     WRITE(numout,*) ' at_i: ', at_i(jiindex,jjindex)
+     WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+     WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+        DO jk = 1, nlay_i
+        WRITE(numout,*) ' e_i : ', e_i(jiindex, jjindex, jk, 1:jpl)
+        END DO
+!+++++ ]
+
+     !---------------------------------------------
+     ! Ice concentration and ice heat content
+     !---------------------------------------------
+
+     a_i (:,:,:) = a_i (:,:,:)   + d_a_i_trp(:,:,:)     &
+                                 + d_a_i_thd(:,:,:)
+     CALL lim_var_glo2eqv ! useless, just for debug
+        DO jk = 1, nlay_i
+        WRITE(numout,*) ' t_i : ', t_i(jiindex, jjindex, jk, 1:jpl)
+        END DO
+     e_i(:,:,:,:) = e_i(:,:,:,:) + d_e_i_trp(:,:,:,:)  
+     CALL lim_var_glo2eqv ! useless, just for debug
+        WRITE(numout,*) ' After transport update '
+        DO jk = 1, nlay_i
+        WRITE(numout,*) ' t_i : ', t_i(jiindex, jjindex, jk, 1:jpl)
+        END DO
+     e_i(:,:,:,:) = e_i(:,:,:,:) + d_e_i_thd(:,:,:,:)  
+     CALL lim_var_glo2eqv ! useless, just for debug
+        WRITE(numout,*) ' After thermodyn update '
+        DO jk = 1, nlay_i
+        WRITE(numout,*) ' t_i : ', t_i(jiindex, jjindex, jk, 1:jpl)
+        END DO
+
+     at_i(:,:) = 0.0
+     DO jl = 1, jpl
+        at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+     END DO
+
+!+++++ [
+     WRITE(numout,*) ' 1. After update of Global variables (2) '
+     WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+     WRITE(numout,*) ' at_i: ', at_i(jiindex,jjindex)
+     WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+     WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+     WRITE(numout,*) ' oa_i : ', oa_i(jiindex, jjindex, 1:jpl)
+     WRITE(numout,*) ' e_s : ', e_s(jiindex, jjindex, 1, 1:jpl)
+        DO jk = 1, nlay_i
+        WRITE(numout,*) ' e_i : ', e_i(jiindex, jjindex, jk, 1:jpl)
+        END DO
+!+++++ ]
+
+     !------------------------------
+     ! Snow temperature and ice age
+     !------------------------------
+
+     e_s(:,:,:,:) = e_s(:,:,:,:)        + &
+                    d_e_s_trp(:,:,:,:)  + &
+                    d_e_s_thd(:,:,:,:)
+
+     oa_i(:,:,:)  = oa_i(:,:,:)         + &
+                    d_oa_i_trp(:,:,:)   + &
+                    d_oa_i_thd(:,:,:)
+
+     !--------------
+     ! Ice salinity    
+     !--------------
+
+     IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) THEN ! general case
+
+!+++++
+     WRITE(numout,*) ' Before everything '
+     WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+     WRITE(numout,*) ' oa_i:  ', oa_i(jiindex, jjindex, 1:jpl)
+        DO jk = 1, nlay_i
+        WRITE(numout,*) ' e_i : ', e_i(jiindex, jjindex, jk, 1:jpl)
+        END DO
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+!+++++
+
+     smv_i(:,:,:) = smv_i(:,:,:)       + &
+                    d_smv_i_thd(:,:,:) + &
+                    d_smv_i_trp(:,:,:)
+
+!+++++
+     WRITE(numout,*) ' After advection   '
+     WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+!+++++
+
+     ENDIF ! num_sal .EQ. 2
+              
+     CALL lim_var_glo2eqv
+
+!--------------------------------------
+! 2. Review of all pathological cases
+!--------------------------------------
+
+     zrtt          = 173.15 * rone
+     zacrith       = 1.0e-6
+
+     !-------------------------------------------
+     ! 2.1) Advection of ice in an ice-free cell
+     !-------------------------------------------
+     ! should be removed since it is treated after dynamics now
+
+     zhimax = 5.0
+     ! 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( rzero, SIGN( rone, 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.zacrith ) )  THEN ! new line
+              z_prescr_hi      = hi_max(1) / 2.0
+              a_i(ji,jj,1)     = v_i(ji,jj,1) / z_prescr_hi
+           ENDIF
+        END DO
+     END DO
+
+!+++++ [
+        WRITE(numout,*) ' 2.1 '
+        WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' at_i: ', at_i(jiindex,jjindex)
+        WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+        DO jk = 1, nlay_i
+        WRITE(numout,*) ' e_i : ', e_i(jiindex, jjindex, jk, 1:jpl)
+        END DO
+!+++++ ]
+
+!change this 14h44
+     zhimax = 20.0 ! line added up
+     ! change this also 17 aug
+     zhimax = 30.0 ! line added up
+
+     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
+                 z_prescr_hi  =  ( hi_max_typ(jl-ice_cat_bounds(jm,1)  ,jm) + &
+                                   hi_max_typ(jl-ice_cat_bounds(jm,1)+1,jm) ) / &
+                                   2.0
+                 a_i(ji,jj,jl) = v_i(ji,jj,jl) / z_prescr_hi
+                 ht_i(ji,jj,jl) = v_i(ji,jj,jl) / a_i(ji,jj,jl)
+              ENDIF
+           zat_i_old = SUM(old_a_i(ji,jj,:))
+
+           END DO ! ji
+        END DO !jj
+     END DO !jl
+
+!+++++ [
+        WRITE(numout,*) ' 2.1 initial '
+        WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' at_i: ', at_i(jiindex,jjindex)
+        WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+        DO jk = 1, nlay_i
+        WRITE(numout,*) ' e_i : ', e_i(jiindex, jjindex, jk, 1:jpl)
+        END DO
+!+++++ ]
+
+     at_i(:,:) = 0.0
+     DO jl = 1, jpl
+        at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+     END DO
+
+     !----------------------------------------------------
+     ! 2.2) Rebin categories with thickness out of bounds
+     !----------------------------------------------------
+!+++++ [
+        WRITE(numout,*) ' 2.1 before rebinning '
+        WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' at_i: ', at_i(jiindex,jjindex)
+        WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+        DO jk = 1, nlay_i
+        WRITE(numout,*) ' e_i : ', e_i(jiindex, jjindex, jk, 1:jpl)
+        END DO
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+!+++++ ]
+
+      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
+
+
+!+++++ [
+        WRITE(numout,*) ' 2.1 after rebinning'
+        WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' at_i: ', at_i(jiindex,jjindex)
+        WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+        DO jk = 1, nlay_i
+        WRITE(numout,*) ' e_i : ', e_i(jiindex, jjindex, jk, 1:jpl)
+        WRITE(numout,*) ' t_i : ', t_i(jiindex, jjindex, jk, 1:jpl)
+        END DO
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+!+++++ ]
+
+     at_i(:,:) = 0.0
+     DO jl = 1, jpl
+        at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+     END DO
+
+     !---------------------------------
+     ! 2.3) Melt of an internal layer
+     !---------------------------------
+     internal_melt(:,:,:) = .false.
+
+     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
+!                    WRITE(numout,*) ' Internal layer melt : '
+!                    WRITE(numout,*) ' ji, jj, jk, jl : ', ji,jj,jk,jl
+!                    WRITE(numout,*) ' e_i : ', e_i(ji,jj,jk,jl)
+!                    WRITE(numout,*) ' v_i : ', v_i(ji,jj,jl)
+                     internal_melt(ji,jj,jl) = .true.
+                 ENDIF
+              END DO ! ji
+           END DO ! jj
+        END DO !jk
+     END DO !jl
+
+     DO jl = 1, jpl
+        DO jj = 1, jpj 
+           DO ji = 1, jpi
+              IF ( internal_melt(ji,jj,jl) ) THEN
+              ! initial ice thickness
+              !-----------------------
+              ht_i(ji,jj,jl) = v_i(ji,jj,jl) / a_i(ji,jj,jl)
+!             WRITE(numout,*) ' ji,jj,jl : ', ji,jj,jl
+!             WRITE(numout,*) ' old ht_i: ', ht_i(ji,jj,jl)
+!             WRITE(numout,*) ' Enthalpy at the beg : ', e_i(ji,jj,1:nlay_i,jl)
+!             WRITE(numout,*) ' smv_i   : ', smv_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
+              IF (ind_im .LT.nlay_i ) smv_i(ji,jj,jl)= smv_i(ji,jj,jl) / ht_i(ji,jj,jl) * & 
+                             ( ht_i(ji,jj,jl) - ind_im*ht_i(ji,jj,jl) / nlay_i )
+              ht_i(ji,jj,jl) = ht_i(ji,jj,jl) - ind_im*ht_i(ji,jj,jl) / nlay_i
+              v_i(ji,jj,jl)  = ht_i(ji,jj,jl) * a_i(ji,jj,jl)
+
+!             WRITE(numout,*) ' ind_im  : ', ind_im
+!             WRITE(numout,*) ' new ht_i: ', ht_i(ji,jj,jl)
+!             WRITE(numout,*) ' smv_i   : ', smv_i(ji,jj,jl)
+!             WRITE(numout,*) ' zesum   : ', zesum
+
+              ! 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) * ind_im / nlay_i
+                    zqm0   (ind_im) = MAX( e_i(ji,jj,jk,jl) , 0.0 )
+                 ENDIF
+              END DO
+
+!             WRITE(numout,*) ' Old thickness, enthalpy '
+!             WRITE(numout,*) ' Number of layer : ind_im ', ind_im
+!             WRITE(numout,*) ' zthick0 : ', zthick0(1:ind_im)
+!             WRITE(numout,*) ' zqm0    : ', zqm0(1:ind_im)
+
+              ! 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) * layer / ind_im , ht_i(ji,jj,jl) * jk / nlay_i ) -       &
+                 MAX( ht_i(ji,jj,jl) * (layer-1) / ind_im , ht_i(ji,jj,jl) * (jk-1) / nlay_i ) , 0.0 ) &
+                                 /  ( ht_i(ji,jj,jl) / 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
+
+!             WRITE(numout,*) ' Enthalpy at the end : ', e_i(ji,jj,1:nlay_i,jl)
+!             WRITE(numout,*) ' Volume   at the end : ', v_i(ji,jj,jl)
+!             WRITE(numout,*) ' zesum : ', zesum
+
+              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
+!+++++ [
+        WRITE(numout,*) ' 2.3 after melt of an internal ice layer '
+        WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' at_i: ', at_i(jiindex,jjindex)
+        WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+        DO jk = 1, nlay_i
+        WRITE(numout,*) ' e_i : ', e_i(jiindex, jjindex, jk, 1:jpl)
+        WRITE(numout,*) ' t_i : ', t_i(jiindex, jjindex, jk, 1:jpl)
+        END DO
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+!+++++ ]
+
+     internal_melt(:,:,:) = .false.
+
+     ! Melt of snow
+     !--------------
+     DO jl = 1, jpl
+        DO jj = 1, jpj 
+           DO ji = 1, jpi
+              ! snow energy of melting
+              ze_s = e_s(ji,jj,1,jl) * unit_fac / area(ji,jj) /              &
+              MAX( v_s(ji,jj,jl), 1.0e-6 )  ! 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) = .true.
+
+              !++++++
+              IF ( (ji.eq.jiindex) .AND. (jj.eq.jjindex) ) THEN
+                 WRITE(numout,*) ' jl    : ', jl
+                 WRITE(numout,*) ' ze_s  : ', ze_s
+                 WRITE(numout,*) ' v_s   : ', v_s(ji,jj,jl)
+                 WRITE(numout,*) ' rhosn : ', rhosn
+                 WRITE(numout,*) ' rhosn : ', lfus 
+                 WRITE(numout,*) ' area  : ', area(ji,jj)
+                 WRITE(numout,*) ' rhosn * lfus : ', rhosn * lfus 
+                 WRITE(numout,*) ' internal_melt : ', internal_melt(ji,jj,jl)
+              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) ) THEN
+                  v_s(ji,jj,jl)   = 0.0
+                  e_s(ji,jj,1,jl) = 0.0
+              !   ! release heat
+                  fheat_res(ji,jj) = fheat_res(ji,jj)  &
+                                  + ze_s * v_s(ji,jj,jl) / rdt_ice
+                  ! release mass
+                  rdmsnif(ji,jj) =  rdmsnif(ji,jj) + rhosn * v_s(ji,jj,jl)
+              ENDIF
+           END DO
+        END DO
+     END DO
+
+     zbigvalue      = 1.0d+20
+
+     DO jl = 1, jpl
+        DO jj = 1, jpj 
+           DO ji = 1, jpi
+
+           !switches
+              zindb         = MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - epsi06 ) ) 
+                            !switch = 1 if a_i > 1e-06 and 0 if not
+              zindsn        = MAX( rzero, SIGN( rone, v_s(ji,jj,jl) - epsi06 ) ) !=1 if hs > 1e-6 and 0 if not
+              zindic        = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi04 ) ) !=1 if hi > 1e-3 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)*86400.0.gt.(rdt_ice*float(numit))) THEN
+!                   o_i(ji,jj,jl) = rdt_ice*FLOAT(numit)/86400.0
+!                ENDIF
+                 IF ((oa_i(ji,jj,jl)-1.0)*86400.0.gt.(rdt_ice*numit*a_i(ji,jj,jl))) THEN
+                    oa_i(ji,jj,jl) = rdt_ice*numit/86400.0*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
+              v_s(ji,jj,jl)  = zindsn*v_s(ji,jj,jl)*zindb
+              v_s(ji,jj,jl)  = v_s(ji,jj,jl) *  MAX( 0.0 , SIGN( 1.0 , v_s(ji,jj,jl) - epsi06 ) )
+
+           !--- 2.5 Correction to ice thickness
+           !-------------------------------------
+           ! ice thickness has to be greater than 0, and if ice concentration smaller than 1e-6 then hi = 0
+              v_i(ji,jj,jl) = MAX( zindb * v_i(ji,jj,jl), 0.0)
+           ! ice thickness cannot be smaller than 1e-3
+              v_i(ji,jj,jl)  = zindic*v_i(ji,jj,jl)
+
+           !--- 2.6 Snow is transformed into ice if the original ice cover disappears
+           !----------------------------------------------------------------------------
+             zindg          = tms(ji,jj) *  MAX( rzero , SIGN( rone , -v_i(ji,jj,jl) ) )
+             v_i(ji,jj,jl)  = v_i(ji,jj,jl) + zindg * rhosn * v_s(ji,jj,jl) / rau0
+             v_s(ji,jj,jl)  = ( rone - zindg ) * v_s(ji,jj,jl) + & 
+                              zindg * v_i(ji,jj,jl) * ( rau0 - rhoic ) / rhosn
+
+           !--- 2.7 Correction to ice concentrations 
+           !--------------------------------------------
+           ! if greater than 0, ice concentration cannot be smaller than 1e-10
+              a_i(ji,jj,jl) = zindb * MAX(zindsn, zindic) * MAX( a_i(ji,jj,jl), epsi06 )
+           ! then ice volume has to be corrected too...
+           ! instead, zap small areas
+
+           !-------------------------
+           ! 2.8) Snow heat content
+           !-------------------------
+
+              e_s(ji,jj,1,jl) = zindsn *                                &
+                 ( MIN ( MAX ( 0.0, e_s(ji,jj,1,jl) ), zbigvalue ) ) + &
+                 ( 1.0 - zindsn ) * 0.0
+
+           END DO ! ji
+        END DO ! jj
+     END DO ! jl
+
+!+++++ [
+        WRITE(numout,*) ' 2.8 '
+        WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' at_i: ', at_i(jiindex,jjindex)
+        WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+        DO jk = 1, nlay_i
+        WRITE(numout,*) ' e_i : ', e_i(jiindex, jjindex, jk, 1:jpl)
+        END DO
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+!+++++ ]
+
+     !------------------------
+     ! 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) - epsi06 ) ) 
+                               ! =1 if v_i > 1e-6 and 0 if not
+                 e_i(ji,jj,jk,jl)= zindic * & 
+                    ( MIN ( MAX ( 0.0, e_i(ji,jj,jk,jl) ), zbigvalue ) ) + &
+                    ( 1.0 - zindic ) * 0.0
+              END DO ! ji
+           END DO ! jj
+        END DO !jk
+     END DO !jl
+        
+     WRITE(numout,*) ' 2.9 '
+     DO jk = 1, nlay_i
+        WRITE(numout,*) ' e_i : ', e_i(jiindex, jjindex, jk, 1:jpl)
+     END DO
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+
+     !---------------------
+     ! 2.11) Ice salinity
+     !---------------------
+
+     IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) THEN ! general case
+
+     DO jl = 1, jpl
+        DO jk = 1, nlay_i
+           DO jj = 1, jpj 
+              DO ji = 1, jpi
+                 ! salinity stays in bounds
+                 smv_i(ji,jj,jl)  =  MAX(MIN((rhoic-rhosn)/rhoic*sss_io(ji,jj),smv_i(ji,jj,jl)), &
+                  0.1 * v_i(ji,jj,jl) )
+                 i_ice_switch    =  1.0-MAX(0.0,SIGN(1.0,-v_i(ji,jj,jl)))
+                 smv_i(ji,jj,jl)  = i_ice_switch*smv_i(ji,jj,jl) + &
+                                     0.1*(1.0-i_ice_switch)*v_i(ji,jj,jl)
+              END DO ! ji
+           END DO ! jj
+        END DO !jk
+     END DO !jl
+
+     ENDIF
+
+!+++++ [
+        WRITE(numout,*) ' 2.11 '
+        WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' at_i    ', at_i(jiindex,jjindex)
+        WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+!+++++ ]
+
+     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
+              !----------------------------------------------------------------------
+              ! the ice thickness of the smallest category should be higher than 5 cm
+              ! we changed hiclim to 10
+              zindb         = MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - epsi06 ) ) 
+              ht_i(ji,jj,jl) = zindb*v_i(ji,jj,jl)/MAX(a_i(ji,jj,jl), epsi06)
+              zh            = MAX( rone , zindb * hiclim  / MAX( ht_i(ji,jj,jl) , epsi20 ) )
+              ht_s(ji,jj,jl) = ht_s(ji,jj,jl)* zh
+!             v_s(ji,jj,jl)  = v_s(ji,jj,jl) * zh
+              ht_i(ji,jj,jl) = ht_i(ji,jj,jl)* zh
+!             v_i(ji,jj,jl)  = v_i(ji,jj,jl) * zh
+              a_i (ji,jj,jl) = a_i(ji,jj,jl) /zh
+           END DO !ji
+        END DO !jj
+     END DO !jm
+!+++++ [
+        WRITE(numout,*) ' 2.12 '
+        WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' at_i    ', at_i(jiindex,jjindex)
+        WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+!+++++ ]
+
+     !--- 2.13 Total ice concentration should not exceed 1
+     !-----------------------------------------------------
+     zamax = amax
+     ! 2.13.1) individual concentrations cannot exceed zamax
+     !------------------------------------------------------
+
+     at_i(:,:) = 0.0
+     DO jl = 1, jpl
+        at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+     END DO
+
+     ! 2.13.2) Total ice concentration cannot exceed zamax
+     !----------------------------------------------------
+     at_i(:,:) = 0.0
+     DO jl = 1, jpl
+        at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+     END DO
+
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           
+           ! 0) Excessive area ?
+           z_da_ex =  MAX( at_i(ji,jj) - zamax , 0.0 )        
+
+           ! 1) Count the number of existing categories
+           DO jl  = 1, jpl
+              zindb   =  MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi03 ) ) 
+              zindb   =  MAX( rzero, SIGN( rone, v_i(ji,jj,jl) ) ) 
+              z_da_i(jl) = a_i(ji,jj,jl)*zindb*z_da_ex/MAX(at_i(ji,jj),epsi06)
+              z_dv_i(jl) = v_i(ji,jj,jl)*z_da_i(jl)/MAX(at_i(ji,jj),epsi06)
+              a_i(ji,jj,jl) = a_i(ji,jj,jl) - z_da_i(jl)
+              v_i(ji,jj,jl) = v_i(ji,jj,jl) + z_dv_i(jl)
+
+           END DO
+               
+        END DO !ji
+     END DO !jj
+
+!+++++ [
+        WRITE(numout,*) ' 2.13 '
+        WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' at_i    ', at_i(jiindex,jjindex)
+        WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+!+++++ ]
+
+     at_i(:,:) = 0.0
+     DO jl = 1, jpl
+        at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+     END DO
+
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           IF (at_i(ji,jj).GT.1.0) THEN
+              WRITE(numout,*) ' lim_update ! : at_i > 1 -> PAS BIEN -> ALERTE '
+              WRITE(numout,*) ' ~~~~~~~~~~   at_i     ', at_i(ji,jj)
+              WRITE(numout,*) ' Point ', ji, jj
+              WRITE(numout,*) ' lat - long ', gphit(ji,jj), glamt(ji,jj)
+              DO jl = 1, jpl
+                 WRITE(numout,*) ' a_i ***         ', a_i(ji,jj,jl), ' CAT no ', jl
+                 WRITE(numout,*) ' a_i_old ***     ', old_a_i(ji,jj,jl), ' CAT no ', jl
+                 WRITE(numout,*) ' d_a_i_thd / trp ', d_a_i_thd(ji,jj,jl), d_a_i_trp(ji,jj,jl)
+              END DO
+!             WRITE(numout,*) ' CORRECTION BARBARE '
+!             z_da_ex =  MAX( at_i(ji,jj) - zamax , 0.0 )        
+           ENDIF
+        END DO
+     END DO
+
+     ! Final thickness distribution rebinning
+     ! --------------------------------------
+!+++++ [
+        WRITE(numout,*) ' rebinning before'
+        WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' at_i    ', at_i(jiindex,jjindex)
+        WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+!+++++ ]
+!old version
+!    CALL lim_itd_th_reb(1,jpl)
+
+      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
+!+++++ [
+        WRITE(numout,*) ' rebinning final'
+        WRITE(numout,*) ' a_i : ', a_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' at_i    ', at_i(jiindex,jjindex)
+        WRITE(numout,*) ' v_i : ', v_i(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' v_s : ', v_s(jiindex, jjindex, 1:jpl)
+        WRITE(numout,*) ' smv_i: ', smv_i(jiindex, jjindex, 1:jpl)
+!+++++ ]
+
+     at_i(:,:) = 0.0
+     DO jl = 1, jpl
+        at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+     END DO
+
+!------------------------------------------------------------------------------
+! 2) Corrections to avoid wrong values                                        |
+!------------------------------------------------------------------------------
+! Ice drift
+!------------
+
+!RB had to split the loop for mpp reproducibility, why ???
+      DO jj = 1, jpj
+         DO ji = 1, jpim1
+            IF ( at_i(ji,jj) .EQ. 0.0 ) THEN ! what to do if there is no ice
+               ! mask u
+               IF ( at_i(ji+1,jj) .EQ. 0.0 ) u_ice(ji,jj)   = 0.0 ! right side
+            ENDIF
+         END DO
+      END DO
+      DO jj = 1, jpj 
+         DO ji = 2, jpi
+            IF ( at_i(ji,jj) .EQ. 0.0 ) THEN ! what to do if there is no ice
+               ! mask u
+               IF ( at_i(ji-1,jj) .EQ. 0.0 ) u_ice(ji-1,jj) = 0.0 ! left side
+            ENDIF
+         END DO
+      END DO
+      DO jj = 1, jpj - 1
+         DO ji = 1, jpi
+            IF ( at_i(ji,jj) .EQ. 0.0 ) THEN ! what to do if there is no ice
+               ! mask u
+               IF ( at_i(ji,jj+1) .EQ. 0.0 ) v_ice(ji,jj)   = 0.0 ! upper side
+            ENDIF
+         END DO
+      END DO
+      DO jj = 2, jpj 
+         DO ji = 1, jpi
+            IF ( at_i(ji,jj) .EQ. 0.0 ) THEN ! what to do if there is no ice
+               ! mask u
+               IF ( at_i(ji,jj-1) .EQ. 0.0 ) v_ice(ji-1,jj) = 0.0 ! bottom side
+            ENDIF
+         END DO
+      END DO
+      !mask velocities
+      u_ice(:,:) = u_ice(:,:) * tmu(:,:)
+      v_ice(:,:) = v_ice(:,:) * tmv(:,:)
+      !lateral boundary conditions
+      CALL lbc_lnk( u_ice(:,:), 'U', -1. )
+      CALL lbc_lnk( v_ice(:,:), 'V', -1. )
+
+!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+! ALERTES
+!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+              DO jl = 1, jpl
+!                IF ((v_i(ji,jj,jl).NE.0.0).AND.(a_i(ji,jj,jl).EQ.0.0)) THEN
+!                   WRITE(numout,*) ' lim_update : incompatible volume and concentration '
+              END DO ! jl
+
+           DO jl = 1, jpl
+              IF ( (a_i(ji,jj,jl).GT.1.0).OR.(at_i(ji,jj).GT.1.0) ) THEN
+                 zindb          =  MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - epsi06 ) ) 
+                 WRITE(numout,*) ' lim_update : a_i > 1 '
+                 WRITE(numout,*) ' PAS BIEN ----> ALERTE !!! '
+                 WRITE(numout,*) ' ~~~~~~~~~~   at_i     ', at_i(ji,jj)
+                 WRITE(numout,*) ' Point - category', ji, jj, jl
+                 WRITE(numout,*) ' lat - long ', gphit(ji,jj), glamt(ji,jj)
+                 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,*) ' ht_i ***        ', v_i(ji,jj,jl)/MAX(a_i(ji,jj,jl),epsi06)*zindb 
+                 WRITE(numout,*) ' hi_max(jl), hi_max(jl-1) ', hi_max(jl), hi_max(jl-1)
+                 WRITE(numout,*) ' d_v_i_thd / trp ', d_v_i_thd(ji,jj,jl), d_v_i_trp(ji,jj,jl)
+                 WRITE(numout,*) ' d_a_i_thd / trp ', d_a_i_thd(ji,jj,jl), d_a_i_trp(ji,jj,jl)
+              ENDIF
+           END DO
+
+        END DO !jj
+     END DO !ji
+
+     WRITE(numout,*) ' TESTOSC1 ', tio_u(jiindex,jjindex), tio_v(jiindex,jjindex)
+     WRITE(numout,*) ' TESTOSC2 ', u_ice(jiindex,jjindex), v_ice(jiindex,jjindex)
+     WRITE(numout,*) ' TESTOSC3 ', u_oce(jiindex,jjindex), v_oce(jiindex,jjindex)
+     WRITE(numout,*) ' TESTOSC4 ', tauxw(jiindex,jjindex), tauxw(jiindex,jjindex)
+
+
+      IF(ln_ctl) THEN   ! Control print
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Cell values : ')
+         CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
+         CALL prt_ctl(tab2d_1=area       , clinfo1=' lim_update  : cell area   :')
+         CALL prt_ctl(tab2d_1=at_i       , clinfo1=' lim_update  : at_i        :')
+         CALL prt_ctl(tab2d_1=vt_i       , clinfo1=' lim_update  : vt_i        :')
+         CALL prt_ctl(tab2d_1=vt_s       , clinfo1=' lim_update  : vt_s        :')
+         CALL prt_ctl(tab2d_1=strength   , clinfo1=' lim_update  : strength    :')
+         CALL prt_ctl(tab2d_1=u_ice      , clinfo1=' lim_update  : u_ice       :', tab2d_2=v_ice      , clinfo2=' v_ice       :')
+         CALL prt_ctl(tab2d_1=d_u_ice_dyn, clinfo1=' lim_update  : 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_update  : old_u_ice   :', tab2d_2=old_v_ice  , clinfo2=' old_v_ice   :')
+
+         DO jl = 1, jpl
+            CALL prt_ctl_info(' ')
+            CALL prt_ctl_info(' - Category : ', ivar1=jl)
+            CALL prt_ctl_info('   ~~~~~~~~~~')
+            CALL prt_ctl(tab2d_1=ht_i       (:,:,jl)        , clinfo1= ' lim_update  : ht_i        : ')
+            CALL prt_ctl(tab2d_1=ht_s       (:,:,jl)        , clinfo1= ' lim_update  : ht_s        : ')
+            CALL prt_ctl(tab2d_1=t_su       (:,:,jl)        , clinfo1= ' lim_update  : t_su        : ')
+            CALL prt_ctl(tab2d_1=t_s        (:,:,1,jl)      , clinfo1= ' lim_update  : t_snow      : ')
+            CALL prt_ctl(tab2d_1=sm_i       (:,:,jl)        , clinfo1= ' lim_update  : sm_i        : ')
+            CALL prt_ctl(tab2d_1=o_i        (:,:,jl)        , clinfo1= ' lim_update  : o_i         : ')
+            CALL prt_ctl(tab2d_1=a_i        (:,:,jl)        , clinfo1= ' lim_update  : a_i         : ')
+            CALL prt_ctl(tab2d_1=old_a_i    (:,:,jl)        , clinfo1= ' lim_update  : old_a_i     : ')
+            CALL prt_ctl(tab2d_1=d_a_i_trp  (:,:,jl)        , clinfo1= ' lim_update  : d_a_i_trp   : ')
+            CALL prt_ctl(tab2d_1=d_a_i_thd  (:,:,jl)        , clinfo1= ' lim_update  : d_a_i_thd   : ')
+            CALL prt_ctl(tab2d_1=v_i        (:,:,jl)        , clinfo1= ' lim_update  : v_i         : ')
+            CALL prt_ctl(tab2d_1=old_v_i    (:,:,jl)        , clinfo1= ' lim_update  : old_v_i     : ')
+            CALL prt_ctl(tab2d_1=d_v_i_trp  (:,:,jl)        , clinfo1= ' lim_update  : d_v_i_trp   : ')
+            CALL prt_ctl(tab2d_1=d_v_i_thd  (:,:,jl)        , clinfo1= ' lim_update  : d_v_i_thd   : ')
+            CALL prt_ctl(tab2d_1=v_s        (:,:,jl)        , clinfo1= ' lim_update  : v_s         : ')
+            CALL prt_ctl(tab2d_1=old_v_s    (:,:,jl)        , clinfo1= ' lim_update  : old_v_s     : ')
+            CALL prt_ctl(tab2d_1=d_v_s_trp  (:,:,jl)        , clinfo1= ' lim_update  : d_v_s_trp   : ')
+            CALL prt_ctl(tab2d_1=d_v_s_thd  (:,:,jl)        , clinfo1= ' lim_update  : d_v_s_thd   : ')
+            CALL prt_ctl(tab2d_1=e_i        (:,:,1,jl)/1.0e9, clinfo1= ' lim_update  : e_i1        : ')
+            CALL prt_ctl(tab2d_1=old_e_i    (:,:,1,jl)/1.0e9, clinfo1= ' lim_update  : old_e_i1    : ')
+            CALL prt_ctl(tab2d_1=d_e_i_trp  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update  : de_i1_trp   : ')
+            CALL prt_ctl(tab2d_1=d_e_i_thd  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update  : de_i1_thd   : ')
+            CALL prt_ctl(tab2d_1=e_i        (:,:,2,jl)/1.0e9, clinfo1= ' lim_update  : e_i2        : ')
+            CALL prt_ctl(tab2d_1=old_e_i    (:,:,2,jl)/1.0e9, clinfo1= ' lim_update  : old_e_i2    : ')
+            CALL prt_ctl(tab2d_1=d_e_i_trp  (:,:,2,jl)/1.0e9, clinfo1= ' lim_update  : de_i2_trp   : ')
+            CALL prt_ctl(tab2d_1=d_e_i_thd  (:,:,2,jl)/1.0e9, clinfo1= ' lim_update  : de_i2_thd   : ')
+            CALL prt_ctl(tab2d_1=e_s        (:,:,1,jl)      , clinfo1= ' lim_update  : e_snow      : ')
+            CALL prt_ctl(tab2d_1=old_e_s    (:,:,1,jl)      , clinfo1= ' lim_update  : old_e_snow  : ')
+            CALL prt_ctl(tab2d_1=d_e_s_trp  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update  : d_e_s_trp   : ')
+            CALL prt_ctl(tab2d_1=d_e_s_thd  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update  : d_e_s_thd   : ')
+            CALL prt_ctl(tab2d_1=smv_i      (:,:,jl)        , clinfo1= ' lim_update  : smv_i       : ')
+            CALL prt_ctl(tab2d_1=old_smv_i  (:,:,jl)        , clinfo1= ' lim_update  : old_smv_i   : ')
+            CALL prt_ctl(tab2d_1=d_smv_i_trp(:,:,jl)        , clinfo1= ' lim_update  : d_smv_i_trp : ')
+            CALL prt_ctl(tab2d_1=d_smv_i_thd(:,:,jl)        , clinfo1= ' lim_update  : d_smv_i_thd : ')
+            CALL prt_ctl(tab2d_1=oa_i       (:,:,jl)        , clinfo1= ' lim_update  : oa_i        : ')
+            CALL prt_ctl(tab2d_1=old_oa_i   (:,:,jl)        , clinfo1= ' lim_update  : old_oa_i    : ')
+            CALL prt_ctl(tab2d_1=d_oa_i_trp (:,:,jl)        , clinfo1= ' lim_update  : d_oa_i_trp  : ')
+            CALL prt_ctl(tab2d_1=d_oa_i_thd (:,:,jl)        , clinfo1= ' lim_update  : d_oa_i_thd  : ')
+            CALL prt_ctl(tab2d_1=REAL(patho_case(:,:,jl))   , clinfo1= ' lim_update  : Path. case  : ')
+
+            DO jk = 1, nlay_i
+               CALL prt_ctl_info(' - Layer : ', ivar1=jk)
+               CALL prt_ctl(tab2d_1=t_i(:,:,jk,jl) , clinfo1= ' lim_update  : t_i       : ')
+            END DO
+         END DO
+
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Heat / FW fluxes : ')
+         CALL prt_ctl_info('   ~~~~~~~~~~~~~~~~~~ ')
+         CALL prt_ctl(tab2d_1=fmmec  , clinfo1= ' lim_update : fmmec : ', tab2d_2=fhmec     , clinfo2= ' fhmec     : ')
+         CALL prt_ctl(tab2d_1=sst_io , clinfo1= ' lim_update : sst   : ', tab2d_2=sss_io    , clinfo2= ' sss       : ')
+         CALL prt_ctl(tab2d_1=fhbri  , clinfo1= ' lim_update : fhbri : ', tab2d_2=fheat_rpo , clinfo2= ' fheat_rpo : ')
+
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Stresses : ')
+         CALL prt_ctl_info('   ~~~~~~~~~~ ')
+         CALL prt_ctl(tab2d_1=tauxw , clinfo1= ' lim_update : tauxw : ', tab2d_2=tauyw , clinfo2= ' tauyw : ')
+         CALL prt_ctl(tab2d_1=taux  , clinfo1= ' lim_update : taux  : ', tab2d_2=tauy  , clinfo2= ' tauy  : ')
+         CALL prt_ctl(tab2d_1=ftaux , clinfo1= ' lim_update : ftaux : ', tab2d_2=ftauy , clinfo2= ' ftauy : ')
+         CALL prt_ctl(tab2d_1=gtaux , clinfo1= ' lim_update : gtaux : ', tab2d_2=gtauy , clinfo2= ' gtauy : ')
+         CALL prt_ctl(tab2d_1=u_io  , clinfo1= ' lim_update : u_io  : ', tab2d_2=v_io  , clinfo2= ' v_io  : ')
+      ENDIF
+
+     !---------------------
+
+   END SUBROUTINE lim_update
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty Module               No sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_update     ! Empty routine
+   END SUBROUTINE lim_update
+
+#endif
+
+END MODULE limupdate
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limvar.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limvar.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limvar.F90	(revision 884)
@@ -0,0 +1,758 @@
+MODULE limvar
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!======================================================================
+   !!                       ***  MODULE limvar ***
+   !!                 Different sets of ice model variables 
+   !!                   how to switch from one to another
+   !!
+   !!                 There are three sets of variables
+   !!                 VGLO : global variables of the model
+   !!                        - v_i (jpi,jpj,jpl)
+   !!                        - v_s (jpi,jpj,jpl)
+   !!                        - a_i (jpi,jpj,jpl)
+   !!                        - t_s (jpi,jpj,jpl)
+   !!                        - e_i (jpi,jpj,nlay_i,jpl)
+   !!                        - smv_i(jpi,jpj,jpl)
+   !!                        - oa_i (jpi,jpj,jpl)
+   !!                 VEQV : equivalent variables sometimes used in the model
+   !!                        - ht_i(jpi,jpj,jpl)
+   !!                        - ht_s(jpi,jpj,jpl)
+   !!                        - t_i (jpi,jpj,nlay_i,jpl)
+   !!                        ...
+   !!                 VAGG : aggregate variables, averaged/summed over all
+   !!                        thickness categories
+   !!                        - vt_i(jpi,jpj)
+   !!                        - vt_s(jpi,jpj)
+   !!                        - at_i(jpi,jpj)
+   !!                        - et_s(jpi,jpj)  !total snow heat content
+   !!                        - et_i(jpi,jpj)  !total ice thermal content 
+   !!                        - smt_i(jpi,jpj) !mean ice salinity
+   !!                        - ot_i(jpi,jpj)  !average ice age
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_ice
+   USE par_oce          ! ocean parameters
+   USE phycst           ! physical constants (ocean directory) 
+   USE ice_oce          ! ice variables
+   USE thd_ice
+   USE in_out_manager
+   USE ice
+   USE par_ice
+ 
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_var_agg
+   PUBLIC lim_var_glo2eqv
+   PUBLIC lim_var_eqv2glo
+   PUBLIC lim_var_salprof
+   PUBLIC lim_var_bv
+   PUBLIC lim_var_salprof1d
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      epsi20 = 1e-20   ,  &
+      epsi13 = 1e-13   ,  &
+      zzero  = 0.e0    ,  &
+      zone   = 1.e0
+
+   !!----------------------------------------------------------------------
+   !!   LIM3.0,  UCL-ASTR-LOCEAN-IPSL (2008)
+   !!   (c) UCL-ASTR and Martin Vancoppenolle
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_var_agg(n)
+        !!------------------------------------------------------------------
+        !!                ***  ROUTINE lim_var_agg  ***
+        !! ** Purpose :
+        !!        This routine aggregates ice-thickness-category variables to  
+        !!                                all-ice variables
+        !!        i.e. it turns VGLO into VAGG
+        !! ** Method  :
+        !!
+        !! ** Arguments :
+        !!           kideb , kiut : Starting and ending points on which the 
+        !!                         the computation is applied
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !! ** Arguments : n = 1, at_i vt_i only
+        !!                n = 2 everything
+        !!
+        !! ** External : 
+        !!
+        !! ** References :
+        !!
+        !! ** History :
+        !!           (01-2006) Martin Vancoppenolle, UCL-ASTR
+        !!
+        !! note : you could add an argument when you need only at_i, vt_i
+        !!        and when you need everything
+        !!------------------------------------------------------------------
+        !! * Arguments
+
+        !! * Local variables
+        INTEGER ::   ji,       &   ! spatial dummy loop index
+                     jj,       &   ! spatial dummy loop index
+                     jk,       &   ! vertical layering dummy loop index
+                     jl            ! ice category dummy loop index
+ 
+        REAL ::      zeps, epsi16, zinda, epsi06
+ 
+        INTEGER, INTENT( in ) ::   n     ! describes what is needed
+        
+!!-- End of declarations
+!!----------------------------------------------------------------------------------------------
+       zeps = 1.0e-13
+       epsi16 = 1.0e-16
+       epsi06 = 1.0e-6
+
+       !------------------
+       ! Zero everything
+       !------------------
+
+       vt_i(:,:)  = 0.0
+       vt_s(:,:)  = 0.0
+       at_i(:,:)  = 0.0 
+       ato_i(:,:) = 1.0 
+
+       IF ( n .GT. 1 ) THEN
+          et_s(:,:)  = 0.0
+          ot_i(:,:)  = 0.0
+          smt_i(:,:) = 0.0
+          et_i(:,:)  = 0.0
+       ENDIF
+      
+       !--------------------
+       ! Compute variables
+       !--------------------
+
+       DO jl = 1, jpl
+          DO jj = 1, jpj
+             DO ji = 1, jpi
+
+                vt_i(ji,jj) = vt_i(ji,jj) + v_i(ji,jj,jl) ! 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( zzero , SIGN( zone , at_i(ji,jj) - 0.10 ) ) 
+                icethi(ji,jj) = vt_i(ji,jj) / MAX(at_i(ji,jj),epsi16)*zinda  
+                   ! ice thickness
+             END DO
+          END DO
+       END DO
+
+       DO jj = 1, jpj
+          DO ji = 1, jpi
+             ato_i(ji,jj) = MAX(1.0 - at_i(ji,jj), 0.0)   ! open water fraction
+          END DO
+       END DO 
+
+       IF ( n .GT. 1 ) THEN
+
+       DO jl = 1, jpl
+          DO jj = 1, jpj
+             DO ji = 1, jpi
+                et_s(ji,jj)  = et_s(ji,jj)  +     &       ! snow heat content
+                               e_s(ji,jj,1,jl)
+                zinda = MAX( zzero , SIGN( zone , vt_i(ji,jj) - 0.10 ) ) 
+                smt_i(ji,jj) = smt_i(ji,jj) +     &       ! ice salinity
+                               smv_i(ji,jj,jl) / MAX( vt_i(ji,jj) , zeps ) * &
+                               zinda
+                zinda = MAX( zzero , SIGN( zone , at_i(ji,jj) - 0.10 ) ) 
+                ot_i(ji,jj)  = ot_i(ji,jj)  +     &       ! ice age
+                               oa_i(ji,jj,jl)  / MAX( at_i(ji,jj) , zeps ) * &
+                               zinda
+             END DO
+          END DO
+       END DO
+                
+       DO jl = 1, jpl
+          DO jk = 1, nlay_i
+             DO jj = 1, jpj
+                DO ji = 1, jpi
+                   et_i(ji,jj) = et_i(ji,jj) + e_i(ji,jj,jk,jl) ! ice heat
+                                                                ! content
+                END DO
+             END DO
+          END DO
+       END DO
+
+       ENDIF ! n .GT. 1
+
+    END SUBROUTINE lim_var_agg
+
+!==============================================================================
+
+    SUBROUTINE lim_var_glo2eqv
+        !!------------------------------------------------------------------
+        !!                ***  ROUTINE lim_var_glo2eqv ***'
+        !! ** Purpose :
+        !!        This routine computes equivalent variables as function of    
+        !!                              global variables 
+        !!        i.e. it turns VGLO into VEQV
+        !! ** Method  :
+        !!
+        !! ** Arguments :
+        !!           kideb , kiut : Starting and ending points on which the 
+        !!                         the computation is applied
+        !!
+        !! ** Inputs / Ouputs : 
+        !!
+        !! ** External : 
+        !!
+        !! ** References :
+        !!
+        !! ** History :
+        !!           (01-2006) Martin Vancoppenolle, UCL-ASTR
+        !!
+        !!------------------------------------------------------------------
+
+        !! * Local variables
+        INTEGER ::   ji,       &   ! spatial dummy loop index
+                     jj,       &   ! spatial dummy loop index
+                     jk,       &   ! vertical layering dummy loop index
+                     jl            ! ice category dummy loop index
+
+        REAL :: zq_i, zaaa, zbbb, zccc, zdiscrim, &
+                ztmelts, zindb, zq_s, zfac1, zfac2
+
+        REAL :: zeps, epsi06
+
+        zeps    = 1.0e-10
+        epsi06  = 1.0e-06
+
+!!-- End of declarations
+!!------------------------------------------------------------------------------
+
+      !-------------------------------------------------------
+      ! Ice thickness, snow thickness, ice salinity, ice age
+      !-------------------------------------------------------
+!CDIR NOVERRCHK
+      DO jl = 1, jpl
+!CDIR NOVERRCHK
+         DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+               zindb          = 1.0-MAX(0.0,SIGN(1.0,- a_i(ji,jj,jl))) !0 if no ice and 1 if yes
+               ht_i(ji,jj,jl) = v_i(ji,jj,jl)   / MAX( a_i(ji,jj,jl) , zeps ) * zindb
+               ht_s(ji,jj,jl) = v_s(ji,jj,jl)   / MAX( a_i(ji,jj,jl) , zeps ) * zindb
+               o_i(ji,jj,jl)  = oa_i(ji,jj,jl)  / MAX( a_i(ji,jj,jl) , zeps ) * zindb
+            END DO
+         END DO
+      END DO
+
+      IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) )THEN
+
+!CDIR NOVERRCHK
+      DO jl = 1, jpl
+!CDIR NOVERRCHK
+         DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+               zindb          = 1.0-MAX(0.0,SIGN(1.0,-a_i(ji,jj,jl))) !0 if no ice and 1 if yes
+               sm_i(ji,jj,jl) = smv_i(ji,jj,jl) / MAX(v_i(ji,jj,jl),zeps) * zindb
+            END DO
+         END DO
+      END DO
+
+      ENDIF
+
+      ! salinity profile
+      CALL lim_var_salprof
+
+      !-------------------
+      ! Ice temperatures
+      !-------------------
+!CDIR NOVERRCHK
+      DO jl = 1, jpl
+!CDIR NOVERRCHK
+        DO jk = 1, nlay_i
+!CDIR NOVERRCHK
+          DO jj = 1, jpj
+!CDIR NOVERRCHK
+            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) , epsi06 ) * nlay_i 
+              ! zindb = 0 if no ice and 1 if yes
+              zindb      = 1.0 - MAX( 0.0 , SIGN( 1.0 , - v_i(ji,jj,jl) ) )
+              !convert units ! very important that this line is here
+              zq_i       = zq_i * unit_fac * zindb
+              !Ice layer melt temperature
+              ztmelts    =  -tmut*s_i(ji,jj,jk,jl) + rtt
+              !Conversion q(S,T) -> T (second order equation)
+              zaaa       =  cpic
+              zbbb       =  ( rcp - cpic ) * ( ztmelts - rtt ) + &
+                            zq_i / rhoic - lfus
+              zccc       =  lfus * (ztmelts-rtt)
+              zdiscrim   =  SQRT( MAX(zbbb*zbbb - 4.0*zaaa*zccc,0.0) )
+              t_i(ji,jj,jk,jl) = rtt + zindb *( - zbbb - zdiscrim ) / & 
+                                 ( 2.0 *zaaa )
+              t_i(ji,jj,jk,jl) = MIN( rtt, MAX(173.15, t_i(ji,jj,jk,jl) ) )
+            END DO
+          END DO
+        END DO
+      END DO
+
+      !--------------------
+      ! Snow temperatures
+      !--------------------
+      zfac1 = 1. / ( rhosn * cpic )
+      zfac2 = lfus / cpic  
+!CDIR NOVERRCHK
+      DO jl = 1, jpl
+!CDIR NOVERRCHK
+        DO jk = 1, nlay_s
+!CDIR NOVERRCHK
+          DO jj = 1, jpj
+!CDIR NOVERRCHK
+            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) , epsi06 ) * nlay_s 
+              ! zindb = 0 if no ice and 1 if yes
+              zindb      = 1.0 - MAX( 0.0 , SIGN( 1.0 , - v_s(ji,jj,jl) ) )
+              !convert units ! very important that this line is here
+              zq_s       = zq_s * unit_fac * zindb
+              t_s(ji,jj,jk,jl) = rtt + zindb * ( - zfac1 * zq_s + zfac2 )
+              t_s(ji,jj,jk,jl) = MIN( rtt, MAX(173.15, t_s(ji,jj,jk,jl) ) )
+
+            END DO
+          END DO
+        END DO
+      END DO
+
+      !-------------------
+      ! Mean temperature
+      !-------------------
+      tm_i(:,:) = 0.0
+!CDIR NOVERRCHK
+      DO jl = 1, jpl
+!CDIR NOVERRCHK
+         DO jk = 1, nlay_i
+!CDIR NOVERRCHK
+            DO jj = 1, jpj
+!CDIR NOVERRCHK
+               DO ji = 1, jpi
+                  zindb          = 1.0-MAX(0.0,SIGN(1.0,-a_i(ji,jj,jl)))
+                  zindb          = zindb*1.0-MAX(0.0,SIGN(1.0,-v_i(ji,jj,jl)))
+                  tm_i(ji,jj) = tm_i(ji,jj) + t_i(ji,jj,jk,jl)*v_i(ji,jj,jl) / &
+                                REAL(nlay_i) / MAX( vt_i(ji,jj) , zeps )
+               END DO
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE lim_var_glo2eqv
+
+!===============================================================================
+
+   SUBROUTINE lim_var_eqv2glo
+        !!------------------------------------------------------------------
+        !!                ***  ROUTINE lim_var_eqv2glo ***'
+        !! ** Purpose :
+        !!        This routine computes global     variables as function of    
+        !!                              equivalent variables
+        !!        i.e. it turns VEQV into VGLO
+        !! ** Method  :
+        !!
+        !! ** Arguments :
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !!
+        !! ** External : 
+        !!
+        !! ** References :
+        !!
+        !! ** History :
+        !!           (01-2006) Martin Vancoppenolle, UCL-ASTR
+        !!                     Take it easy man
+        !!                     Life is just a simple game, between 
+        !!                     ups / and downs \ :@)
+        !!
+        !!------------------------------------------------------------------
+
+       v_i(:,:,:)   = ht_i(:,:,:) * a_i(:,:,:)
+       v_s(:,:,:)   = ht_s(:,:,:) * a_i(:,:,:)
+       smv_i(:,:,:) = sm_i(:,:,:) * v_i(:,:,:)
+       oa_i (:,:,:) = o_i (:,:,:) * a_i(:,:,:)
+
+    END SUBROUTINE lim_var_eqv2glo
+
+!===============================================================================
+
+    SUBROUTINE lim_var_salprof
+        !!------------------------------------------------------------------
+        !!                ***  ROUTINE lim_var_salprof ***'
+        !! ** Purpose :
+        !!        This routine computes salinity profile in function of
+        !!        bulk salinity     
+        !!
+        !! ** Method  : If bulk salinity greater than s_i_1, 
+        !!              the profile is assumed to be constant (S_inf)
+        !!              If bulk salinity lower than s_i_0,
+        !!              the profile is linear with 0 at the surface (S_zero)
+        !!              If it is between s_i_0 and s_i_1, it is a
+        !!              alpha-weighted linear combination of s_inf and s_zero
+        !!
+        !! ** References : Vancoppenolle et al., 2007 (in preparation)
+        !!
+        !! ** History :
+        !!           (08-2006) Martin Vancoppenolle, UCL-ASTR
+        !!                     Take it easy man
+        !!                     Life is just a simple game, between ups 
+        !!                     / and downs \ :@)
+        !!
+        !!------------------------------------------------------------------
+        !! * Arguments
+
+        !! * Local variables
+        INTEGER ::             &
+           ji            ,     & !: spatial dummy loop index
+           jj            ,     & !: spatial dummy loop index
+           jk            ,     & !: vertical layering dummy loop index
+           jl                    !: ice category dummy loop index
+
+        REAL(wp) ::            &
+           dummy_fac0    ,     & !: dummy factor used in computations
+           dummy_fac1    ,     & !: dummy factor used in computations
+           dummy_fac     ,     & !: dummy factor used in computations
+           zind0         ,     & !: switch, = 1 if sm_i lt s_i_0
+           zind01        ,     & !: switch, = 1 if sm_i between s_i_0 and s_i_1
+           zindbal       ,     & !: switch, = 1, if 2*sm_i gt sss_io
+           zargtemp              !: dummy factor
+
+        REAL(wp), DIMENSION(nlay_i) ::      &
+           zs_zero               !: linear salinity profile for salinities under
+                                 !: s_i_0
+
+        REAL(wp), DIMENSION(jpi,jpj,jpl) :: &
+           z_slope_s     ,     & !: slope of the salinity profile
+           zalpha                !: weight factor for s between s_i_0 and s_i_1
+
+!!-- End of declarations
+!!------------------------------------------------------------------------------
+
+      !---------------------------------------
+      ! Vertically constant, constant in time
+      !---------------------------------------
+
+      IF ( num_sal .EQ. 1 ) THEN
+
+         s_i(:,:,:,:) = bulk_sal
+
+      ENDIF
+
+      !-----------------------------------
+      ! Salinity profile, varying in time
+      !-----------------------------------
+
+      IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) )THEN
+
+         DO jk = 1, nlay_i
+            s_i(:,:,jk,:)  = sm_i(:,:,:)
+         END DO ! jk
+
+         ! Slope of the linear profile zs_zero
+         !-------------------------------------
+         DO jl = 1, jpl
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  z_slope_s(ji,jj,jl) = 2.0 * sm_i(ji,jj,jl) / MAX( 0.01      &
+                                      , ht_i(ji,jj,jl) )
+               END DO ! ji
+            END DO ! jj
+         END DO ! jl
+
+         ! Weighting factor between zs_zero and zs_inf
+         !---------------------------------------------
+         dummy_fac0 = 1. / ( ( s_i_0 - s_i_1 ) )
+         dummy_fac1 = s_i_1 / ( s_i_1 - s_i_0 )
+
+         zalpha(:,:,:) = 0.0
+
+!CDIR NOVERRCHK
+         DO jl = 1, jpl
+!CDIR NOVERRCHK
+            DO jj = 1, jpj
+!CDIR NOVERRCHK
+               DO ji = 1, jpi
+                  ! zind0 = 1 if sm_i le s_i_0 and 0 otherwise
+                  zind0  = MAX( 0.0   , SIGN( 1.0  , s_i_0 - sm_i(ji,jj,jl) ) ) 
+                  ! zind01 = 1 if sm_i is between s_i_0 and s_i_1 and 0 othws 
+                  zind01 = ( 1.0 - zind0 ) *                                  &
+                           MAX( 0.0   , SIGN( 1.0  , s_i_1 - sm_i(ji,jj,jl) ) ) 
+                  ! If 2.sm_i GE sss_io then zindbal = 1
+                  zindbal = MAX( 0.0 , SIGN( 1.0 , 2. * sm_i(ji,jj,jl) -      &
+                  sss_io(ji,jj) ) )
+                  zalpha(ji,jj,jl) = zind0  * 1.0                             &
+                                   + zind01 * ( sm_i(ji,jj,jl) * dummy_fac0 + &
+                                                dummy_fac1 )
+                  zalpha(ji,jj,jl) = zalpha(ji,jj,jl) * ( 1.0 - zindbal )
+               END DO
+            END DO
+         END DO
+
+         ! Computation of the profile
+         !----------------------------
+         dummy_fac = 1. / nlay_i
+
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     ! linear profile with 0 at the surface
+                     zs_zero(jk)      = z_slope_s(ji,jj,jl) * ( jk - 1./2. ) * &
+                                        ht_i(ji,jj,jl) * dummy_fac
+                     ! weighting the profile
+                     s_i(ji,jj,jk,jl) = zalpha(ji,jj,jl) * zs_zero(jk) +       &
+                                     ( 1.0 - zalpha(ji,jj,jl) ) * sm_i(ji,jj,jl)
+                  END DO ! ji
+               END DO ! jj
+            END DO ! jk
+         END DO ! jl
+
+      ENDIF ! num_sal
+
+      !-------------------------------------------------------
+      ! Vertically varying salinity profile, constant in time
+      !-------------------------------------------------------
+      ! Schwarzacher (1959) multiyear salinity profile (mean = 2.30)
+      
+      IF ( num_sal .EQ. 3 ) THEN
+
+         sm_i(:,:,:) = 2.30
+
+!CDIR NOVERRCHK
+         DO jl = 1, jpl
+!CDIR NOVERRCHK
+            DO jk = 1, nlay_i
+!CDIR NOVERRCHK
+               DO jj = 1, jpj
+!CDIR NOVERRCHK
+                  DO ji = 1, jpi
+                     zargtemp  = ( jk - 0.5 ) / nlay_i
+                     s_i(ji,jj,jk,jl) =  1.6 - 1.6 * COS( 3.14169265 * &
+                                         ( zargtemp**(0.407/           &
+                                         ( 0.573 + zargtemp ) ) ) )
+                  END DO ! ji
+               END DO ! jj
+            END DO ! jk
+         END DO ! jl
+
+      ENDIF ! num_sal
+
+   END SUBROUTINE lim_var_salprof
+
+!===============================================================================
+
+   SUBROUTINE lim_var_bv
+        !!------------------------------------------------------------------
+        !!                ***  ROUTINE lim_var_bv ***'
+        !! ** Purpose :
+        !!        This routine computes mean brine volume (%) in sea ice
+        !!
+        !! ** Method  : e = - 0.054 * S (ppt) / T (C)
+        !!
+        !! ** Arguments :
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !!
+        !! ** External : 
+        !!
+        !! ** References : Vancoppenolle et al., JGR, 2007
+        !!
+        !! ** History :
+        !!           (08-2006) Martin Vancoppenolle, UCL-ASTR
+        !!
+        !!------------------------------------------------------------------
+        !! * Arguments
+
+        !! * Local variables
+        INTEGER ::   ji,       &   ! spatial dummy loop index
+                     jj,       &   ! spatial dummy loop index
+                     jk,       &   ! vertical layering dummy loop index
+                     jl            ! ice category dummy loop index
+
+        REAL :: zbvi,          &   ! brine volume for a single ice category
+                zeps,          &   ! very small value
+                zindb              ! is there ice or not
+
+!!-- End of declarations
+!!------------------------------------------------------------------------------
+
+       zeps = 1.0e-13
+       bv_i(:,:) = 0.0
+!CDIR NOVERRCHK
+       DO jl = 1, jpl
+!CDIR NOVERRCHK
+          DO jk = 1, nlay_i
+!CDIR NOVERRCHK
+             DO jj = 1, jpj
+!CDIR NOVERRCHK
+                DO ji = 1, jpi
+                   zindb          = 1.0-MAX(0.0,SIGN(1.0,-a_i(ji,jj,jl))) !0 if no ice and 1 if yes
+                   zbvi = - zindb * tmut *s_i(ji,jj,jk,jl) /             & 
+                            MIN( t_i(ji,jj,jk,jl) - 273.15 , zeps )         &
+                            * v_i(ji,jj,jl) / REAL(nlay_i)
+                   bv_i(ji,jj) = bv_i(ji,jj) + zbvi  &
+                            / MAX( vt_i(ji,jj) , zeps )
+                END DO
+             END DO
+          END DO
+       END DO
+
+   END SUBROUTINE lim_var_bv 
+
+!===============================================================================
+
+   SUBROUTINE lim_var_salprof1d(kideb,kiut)
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_thd_salprof1d  ***
+      !!
+      !! ** Purpose :   1d computation of the sea ice salinity profile
+      !!                Works with 1d vectors and is used by thermodynamic
+      !!                modules
+      !!
+      !! history :
+      !!   3.0  !  May  2007 M. Vancoppenolle  Original code
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT(in) :: &
+         kideb, kiut             ! thickness category index
+
+      INTEGER ::             &
+         ji, jk,             &   ! geographic and layer index 
+         zji, zjj
+
+      REAL(wp) ::            &
+         dummy_fac0,         &   ! dummy factors
+         dummy_fac1,         &
+         dummy_fac2,         &
+         zalpha    ,         &   ! weighting factor
+         zind0     ,         &   ! switches as in limvar
+         zind01    ,         &   ! switch
+         zindbal   ,         &   ! switch if in freshwater area
+         zargtemp
+   
+      REAL(wp), DIMENSION(jpij) ::            &
+         z_slope_s
+
+      REAL(wp), DIMENSION(jpij,jkmax) ::      &
+         zs_zero
+      !!-------------------------------------------------------------------
+         
+      !---------------------------------------
+      ! Vertically constant, constant in time
+      !---------------------------------------
+
+      IF ( num_sal .EQ. 1 ) THEN
+
+         s_i_b(:,:) = bulk_sal
+
+      ENDIF
+
+      !------------------------------------------------------
+      ! Vertically varying salinity profile, varying in time
+      !------------------------------------------------------
+
+      IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) THEN
+
+         ! Slope of the linear profile zs_zero
+         !-------------------------------------
+!CDIR NOVERRCHK
+         DO ji = kideb, kiut 
+               z_slope_s(ji) = 2.0 * sm_i_b(ji) / MAX( 0.01      &
+                                      , ht_i_b(ji) )
+         END DO ! ji
+
+         ! Weighting factor between zs_zero and zs_inf
+         !---------------------------------------------
+         dummy_fac0 = 1. / ( ( s_i_0 - s_i_1 ) )
+         dummy_fac1 = s_i_1 / ( s_i_1 - s_i_0 )
+         dummy_fac2 = 1. / nlay_i
+
+!CDIR NOVERRCHK
+         DO jk = 1, nlay_i
+!CDIR NOVERRCHK
+            DO ji = kideb, kiut
+               zji    =  MOD( npb(ji) - 1, jpi ) + 1
+               zjj    =  ( npb(ji) - 1 ) / jpi + 1
+               zalpha = 0.0
+               ! zind0 = 1 if sm_i le s_i_0 and 0 otherwise
+               zind0  = MAX( 0.0   , SIGN( 1.0  , s_i_0 - sm_i_b(ji) ) ) 
+               ! zind01 = 1 if sm_i is between s_i_0 and s_i_1 and 0 othws 
+               zind01 = ( 1.0 - zind0 ) *                                  &
+                        MAX( 0.0   , SIGN( 1.0  , s_i_1 - sm_i_b(ji) ) ) 
+               ! if 2.sm_i GE sss_io then zindbal = 1
+               zindbal = MAX( 0.0 , SIGN( 1.0 , 2. * sm_i_b(ji) -      &
+               sss_io(zji,zjj) ) )
+
+               zalpha = zind0  * 1.0                                       &
+                      + zind01 * ( sm_i_b(ji) * dummy_fac0 +           &
+                                                dummy_fac1 )
+               zalpha = zalpha * ( 1.0 - zindbal )
+
+               zs_zero(ji,jk) = z_slope_s(ji) * ( jk - 1./2. ) * &
+                                ht_i_b(ji) * dummy_fac2
+               ! weighting the profile
+               s_i_b(ji,jk) = zalpha * zs_zero(ji,jk) +       &
+                           ( 1.0 - zalpha ) * sm_i_b(ji)
+            END DO ! ji
+         END DO ! jk
+
+      ENDIF ! num_sal
+
+      !-------------------------------------------------------
+      ! Vertically varying salinity profile, constant in time
+      !-------------------------------------------------------
+      ! Schwarzacher (1959) multiyear salinity profile (mean = 2.30)
+
+      IF ( num_sal .EQ. 3 ) THEN
+
+         sm_i_b(:) = 2.30
+
+!CDIR NOVERRCHK
+         DO ji = kideb, kiut
+!CDIR NOVERRCHK
+            DO jk = 1, nlay_i
+               zargtemp  = ( jk - 0.5 ) / nlay_i
+               s_i_b(ji,jk)  =  1.6 - 1.6*cos(3.14169265*(zargtemp**(0.407/ &
+                                (0.573+zargtemp))))
+            END DO ! jk
+         END DO ! ji
+
+      ENDIF ! num_sal
+
+   END SUBROUTINE lim_var_salprof1d
+
+!===============================================================================
+
+#else
+   !!======================================================================
+   !!                       ***  MODULE limvar  ***
+   !!                          no sea ice model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE lim_var_agg          ! Empty routines
+   END SUBROUTINE lim_var_agg
+   SUBROUTINE lim_var_glo2eqv      ! Empty routines
+   END SUBROUTINE lim_var_glo2eqv
+   SUBROUTINE lim_var_eqv2glo      ! Empty routines
+   END SUBROUTINE lim_var_eqv2glo
+   SUBROUTINE lim_var_salprof      ! Empty routines
+   END SUBROUTINE lim_var_salprof
+   SUBROUTINE lim_var_bv           ! Emtpy routines
+   END SUBROUTINE lim_var_bv 
+   SUBROUTINE lim_var_salprof1d    ! Emtpy routines
+   END SUBROUTINE lim_var_salprof1d
+
+#endif
+END MODULE limvar
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limwri.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limwri.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limwri.F90	(revision 884)
@@ -0,0 +1,510 @@
+MODULE limwri
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!======================================================================
+   !!                     ***  MODULE  limwri  ***
+   !!         Ice diagnostics :  write ice output files
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !!  LIM 2.0, UCL-LOCEAN-IPSL (2005)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limwri.F90,v 1.4 2005/03/27 18:34:42 opalod Exp $
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !!   lim_wri      : write of the diagnostics variables in ouput file 
+   !!   lim_wri_init : initialization and namelist read
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE ioipsl
+   USE dianam    ! build name of file (routine)
+   USE phycst
+   USE dom_oce
+   USE daymod
+   USE in_out_manager
+   USE ice_oce         ! ice variables
+   USE flx_oce
+   USE dom_ice
+   USE ice
+   USE iceini
+   USE lbclnk
+   USE par_ice
+   USE limvar
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC lim_wri        ! routine called by lim_step.F90
+
+   !! * Module variables
+   INTEGER, PARAMETER ::   &  !:
+      jpnoumax = 40             !: maximum number of variable for ice output
+   INTEGER  ::                                &
+      noumef          ,                       &  ! number of fields
+      noumefa         ,                       &  ! number of additional fields
+      add_diag_swi    ,                       &  ! additional diagnostics
+      nz                                         ! dimension for the itd field
+
+   REAL(wp)           , DIMENSION(jpnoumax) ::  &
+      cmulti          ,                       &  ! multiplicative constant
+      cadd            ,                       &  ! additive constant
+      cmultia         ,                       &  ! multiplicative constant
+      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)  ::            &  ! constant values
+      epsi16 = 1e-16   ,  &
+      zzero  = 0.e0     ,  &
+      zone   = 1.e0
+
+CONTAINS
+#if defined key_dimgout
+
+# include "limwri_dimg.h90"
+
+#else
+
+   SUBROUTINE lim_wri( kindic )
+      !!-------------------------------------------------------------------
+      !!  This routine computes the average of some variables and write it
+      !!  on the ouput files.
+      !!  ATTENTION cette routine n'est valable que si le pas de temps est
+      !!  egale a une fraction entiere de 1 jours.
+      !!  Diff 1-D 3-D : suppress common also included in etat
+      !!                 suppress cmoymo 11-18
+      !!  modif : 03/06/98
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT(in) :: &
+          kindic                 ! if kindic < 0 there has been an error somewhere
+
+      !! * Local variables
+      REAL(wp),DIMENSION(1) ::   zdept
+      
+      REAL(wp) :: &
+         zsto, zsec, zjulian,zout, &
+         zindh,zinda,zindb
+      REAL(wp), DIMENSION(jpi,jpj,jpnoumax) :: &
+         zcmo,               &
+         zcmoa                   ! additional fields
+         
+      REAL(wp), DIMENSION(jpi,jpj) ::  &
+         zfield
+
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::  &
+         zmaskitd, zoi, zei
+
+      INTEGER ::  ji, jj, jk, jl, jf, ipl ! dummy loop indices
+
+      CHARACTER(len = 40)  :: &
+         clhstnam, clop, &
+         clhstnama
+
+      INTEGER , SAVE ::      &
+         nice, nhorid, ndim, niter, ndepid
+      INTEGER , SAVE ::      &
+         nicea, nhorida, nitera, ndimitd
+      INTEGER , DIMENSION( jpij ) , SAVE ::  &
+         ndex51
+      INTEGER , DIMENSION( jpij*jpl ) , SAVE ::  &
+         ndexitd
+      !!-------------------------------------------------------------------
+      
+      ipl = jpl
+
+      IF ( numit == nstart ) THEN 
+
+         CALL lim_wri_init 
+         
+         WRITE(numout,*) ' lim_wri, first time step '
+         WRITE(numout,*) ' add_diag_swi ', add_diag_swi
+
+         !--------------------
+         !  1) Initialization
+         !--------------------
+
+         !-------------
+         ! Normal file
+         !-------------
+         
+         zsto     = rdt_ice
+         clop     = "ave(x)"
+         zout     = nwrite * rdt_ice / nfice
+         zsec     = 0.
+         niter    = 0
+         zdept(1) = 0.
+
+         CALL ymds2ju ( nyear, nmonth, nday, zsec, zjulian )
+         CALL dia_nam ( clhstnam, nwrite, 'icemod' )
+         CALL histbeg ( clhstnam, jpi, glamt, jpj, gphit, 1, jpi, 1, jpj, 0, zjulian, rdt_ice, nhorid, nice, domain_id=nidom )
+         CALL histvert( nice, "deptht", "Vertical T levels", "m", 1, zdept, ndepid)
+         CALL wheneq  ( jpij , tmask(:,:,1), 1, 1., ndex51, ndim)
+         
+         DO jf = 1 , noumef
+            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 )
+               WRITE(numout,*) 'nice, nam(jf), titn(jf), uni(jf), nhorid, clop, zsto, zout'
+               WRITE(numout,*)  nice, nam(jf), titn(jf), uni(jf), nhorid, clop, zsto, zout 
+            ENDIF
+         END DO
+
+         CALL histend(nice)
+         
+         !-----------------
+         ! ITD file output
+         !-----------------
+         zsto     = rdt_ice
+         clop     = "ave(x)"
+         zout     = nwrite * rdt_ice / nfice
+         zsec     = 0.
+         nitera   = 0
+         zdept(1) = 0.
+
+         CALL dia_nam ( clhstnama, nwrite, 'icemoa' )
+         CALL histbeg ( clhstnama, jpi, glamt, jpj, gphit,         &
+                        1, jpi, 1, jpj,        & ! zoom
+                        0, zjulian, rdt_ice,   & ! time
+                        nhorida,               & ! ? linked with horizontal ...
+                        nicea , domain_id=nidom)                  ! file 
+         CALL histvert( nicea, "icethi", "L levels",               &
+                        "m", ipl , hi_mean , nz )
+         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)
+      ENDIF
+      
+!     !-----------------------------------------------------------------------!
+!     !--2. Computation of instantaneous values                               ! 
+!     !-----------------------------------------------------------------------!
+
+!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      IF(lwp) 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.0 
+      zcmoa( 1:jpi, 1:jpj, 1:jpnoumax ) = 0.0 
+
+      DO jl = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zindh  = MAX( zzero , SIGN( zone , vt_i(ji,jj) * at_i(ji,jj) - 0.10 ) )
+               zinda  = MAX( zzero , SIGN( zone , at_i(ji,jj) - 0.10 ) )
+               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)*qnsr_ice(ji,jj,jl) 
+               zcmo(ji,jj,27) = zcmo(ji,jj,27) + t_su(ji,jj,jl)*a_i(ji,jj,jl)/MAX(at_i(ji,jj),epsi16)*zinda
+            END DO
+         END DO
+      END DO
+
+      CALL lim_var_bv
+      
+      DO jj = 2 , jpjm1
+         DO ji = 2 , jpim1
+            zindh  = MAX( zzero , SIGN( zone , vt_i(ji,jj) * at_i(ji,jj) - 0.10 ) )
+            zinda  = MAX( zzero , SIGN( zone , at_i(ji,jj) - 0.10 ) )
+            zindb  = zindh * zinda
+
+            zcmo(ji,jj,1)  = at_i(ji,jj)
+            zcmo(ji,jj,2)  = vt_i(ji,jj)/MAX(at_i(ji,jj),epsi16)*zinda
+            zcmo(ji,jj,3)  = vt_s(ji,jj)/MAX(at_i(ji,jj),epsi16)*zinda
+            zcmo(ji,jj,4)  = diag_bot_gr(ji,jj) * &
+                             86400.0 * zinda !Bottom thermodynamic ice production
+            zcmo(ji,jj,5)  = diag_dyn_gr(ji,jj) * &
+                             86400.0 * zinda !Dynamic ice production (rid/raft)
+            zcmo(ji,jj,22) = diag_lat_gr(ji,jj) * &
+                             86400.0 * zinda !Lateral thermodynamic ice production
+            zcmo(ji,jj,23) = diag_sni_gr(ji,jj) * &
+                             86400.0 * zinda !Snow ice production ice production
+            zcmo(ji,jj,24) = tm_i(ji,jj) - rtt
+
+            zcmo(ji,jj,6)  = fbif  (ji,jj)
+            zcmo(ji,jj,7)  = zindb * (  u_ice(ji,jj  ) * tmu(ji,jj)        &
+     &                                + u_ice(ji-1,jj) * tmu(ji-1,jj) )    &
+     &                     / 2.0 
+            zcmo(ji,jj,8)  = zindb * (  v_ice(ji,jj  ) * tmv(ji,jj)        &
+     &                              + v_ice(ji,jj-1) * tmv(ji,jj-1) )      &
+     &                     / 2.0
+            zcmo(ji,jj,9)  = sst_io(ji,jj)
+            zcmo(ji,jj,10) = sss_io(ji,jj)
+
+            zcmo(ji,jj,11) = fnsolar(ji,jj) + fsolar(ji,jj)
+            zcmo(ji,jj,12) = fsolar (ji,jj)
+            zcmo(ji,jj,13) = fnsolar(ji,jj)
+            zcmo(ji,jj,14) = fhbri(ji,jj)
+            zcmo(ji,jj,15) = gtaux(ji,jj)
+            zcmo(ji,jj,16) = gtauy(ji,jj)
+            zcmo(ji,jj,17) = zcmo(ji,jj,17) + (1.0-at_i(ji,jj))*qsr_oce(ji,jj)
+            zcmo(ji,jj,18) = zcmo(ji,jj,18) + (1.0-at_i(ji,jj))*qnsr_oce (ji,jj)
+            zcmo(ji,jj,19) = sprecip(ji,jj)
+            zcmo(ji,jj,20) = smt_i(ji,jj)
+            zcmo(ji,jj,21) = ot_i(ji,jj)
+            zcmo(ji,jj,25) = et_i(ji,jj)
+            zcmo(ji,jj,26) = et_s(ji,jj)
+            zcmo(ji,jj,28) = fsbri(ji,jj)
+            zcmo(ji,jj,29) = fseqv(ji,jj)
+          
+            zcmo(ji,jj,30) = bv_i(ji,jj)
+            zcmo(ji,jj,31) = hicol(ji,jj)
+            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) * &
+                             86400.0 * zinda ! Surface melt
+            zcmo(ji,jj,35) = diag_bot_me(ji,jj) * &
+                             86400.0 * zinda ! Bottom melt
+            zcmo(ji,jj,36) = divu_i(ji,jj)
+            zcmo(ji,jj,37) = shear_i(ji,jj)
+         END DO
+      END DO
+
+      !
+      ! ecriture d'un fichier netcdf
+      !
+      niter = niter + 1
+      DO jf = 1 , noumef
+         DO jj = 1 , jpj
+            DO ji = 1 , jpi
+               zfield(ji,jj) = zcmo(ji,jj,jf) * cmulti(jf) + cadd(jf)
+            END DO
+         END DO
+         
+         IF ( jf == 7  .OR. jf == 8  .OR. jf == 11 .OR. jf == 12 .OR. jf == 15 .OR.   &
+            jf == 16 ) THEN 
+            CALL lbc_lnk( zfield, 'T', -1. )
+         ELSE 
+            CALL lbc_lnk( zfield, 'T',  1. )
+         ENDIF
+
+!+++++
+         WRITE(numout,*)
+         WRITE(numout,*) 'nc(jf), nice, nam(jf), niter, ndim'
+         WRITE(numout,*) nc(jf), nice, nam(jf), niter, ndim
+!+++++
+         IF ( nc(jf) == 1 ) CALL histwrite( nice, nam(jf), niter, zfield, ndim, ndex51 )
+         
+      END DO
+
+      IF ( ( nfice * niter + nit000 - 1 ) >= nitend .OR. kindic < 0 ) THEN
+          WRITE(numout,*) ' Closing the icemod file '
+          CALL histclo( nice )
+      ENDIF
+
+      !-----------------------------
+      ! Thickness distribution file
+      !-----------------------------
+      IF ( add_diag_swi .EQ. 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
+      DO jl = 1, jpl 
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zinda = MAX( zzero , SIGN( zone , a_i(ji,jj,jl) - 1.0e-6 ) )
+               zoi(ji,jj,jl) = oa_i(ji,jj,jl)  / MAX( a_i(ji,jj,jl) , 1.0e-6 ) * &
+                               zinda
+            END DO
+         END DO
+      END DO        
+
+      ! Compute brine volume
+      zei(:,:,:) = 0.0
+      DO jl = 1, jpl 
+         DO jk = 1, nlay_i
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zinda = MAX( zzero , SIGN( zone , a_i(ji,jj,jl) - 1.0e-6 ) )
+                  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 ), -1.0e-6 ) ) * &
+                                  zinda / nlay_i
+               END DO
+            END DO
+         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 ( ( nfice * niter + nit000 - 1 ) >= nitend .OR. kindic < 0 ) THEN
+         WRITE(numout,*) ' Closing the icemod file '
+         CALL histclo( nicea ) 
+      ENDIF
+
+      ENDIF
+
+   END SUBROUTINE lim_wri
+#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
+      !!
+      !! history :
+      !!  8.5  ! 03-08 (C. Ethe) original code
+      !!-------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   nf      ! ???
+
+      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
+
+      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, add_diag_swi
+      !!-------------------------------------------------------------------
+
+      ! Read Namelist namicewri
+      REWIND ( numnam_ice )
+      READ   ( numnam_ice  , 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
+      
+      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
+         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
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :         Empty module          NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_wri          ! Empty routine
+   END SUBROUTINE lim_wri
+#endif
+
+   !!======================================================================
+END MODULE limwri
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/limwri_dimg.h90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/limwri_dimg.h90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/limwri_dimg.h90	(revision 884)
@@ -0,0 +1,204 @@
+    SUBROUTINE lim_wri
+   !!----------------------------------------------------------------------
+   !!  LIM 2.0, UCL-LOCEAN-IPSL (2005)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limwri_dimg.h90,v 1.2 2005/03/27 18:34:42 opalod Exp $
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+    !!-------------------------------------------------------------------
+    !!  This routine computes the average of some variables and write it
+    !!  on the ouput files.
+    !!  ATTENTION cette routine n'est valable que si le pas de temps est
+    !!  egale a une fraction entiere de 1 jours.
+    !!  Diff 1-D 3-D : suppress common also included in etat
+    !!                 suppress cmoymo 11-18
+    !!  modif : 03/06/98
+    !!-------------------------------------------------------------------
+    !! * Local variables
+    USE  diawri, ONLY : dia_wri_dimg
+    REAL(wp),DIMENSION(1) ::   zdept
+
+    REAL(wp) :: &
+         zsto, zsec, zjulian,zout, &
+         zindh,zinda,zindb,  &
+         ztmu
+    REAL(wp), DIMENSION(jpi,jpj,jpnoumax) :: &
+         zcmo
+    REAL(wp), DIMENSION(jpi,jpj) ::  &
+         zfield
+    INTEGER, SAVE :: nmoyice, &  !: counter for averaging
+         &             nwf         !: number of fields to write on disk
+    INTEGER, SAVE,DIMENSION (:), ALLOCATABLE  :: nsubindex   !: subindex to be saved
+    ! according to namelist
+
+    REAL(wp), SAVE, DIMENSION(jpi,jpj,jpnoumax) :: rcmoy
+#if ! defined key_diainstant
+    LOGICAL, PARAMETER :: ll_dia_inst=.false.      ! local logical variable 
+#else
+    LOGICAL, PARAMETER :: ll_dia_inst=.true.
+#endif
+    INTEGER ::  ji, jj, jf, ii   ! dummy loop indices and array index
+    INTEGER :: iyear, iday, imon ! 
+
+    CHARACTER(LEN=80) :: clname, cltext, clmode
+
+
+    INTEGER , SAVE ::      &
+         nice, nhorid, ndim, niter, ndepid
+    INTEGER , DIMENSION( jpij ) , SAVE ::  &
+         ndex51  
+    !!-------------------------------------------------------------------
+    IF ( numit == nstart ) THEN 
+
+       CALL lim_wri_init 
+
+       nwf = 0 
+       ii  = 0
+
+       IF (lwp ) THEN
+          WRITE(numout,*) 'lim_wri : Write ice outputs in dimg'
+          WRITE(numout,*) '~~~~~~~~'
+          WRITE(numout,*) '   According to namelist_ice, following fields saved:'
+          DO jf =1, noumef
+             IF (nc(jf) == 1 ) THEN
+                WRITE(numout,* ) '    -',titn(jf), nam(jf), uni(jf)
+             ENDIF
+          END DO
+       ENDIF
+
+       DO jf = 1, noumef
+          IF (nc(jf) == 1 ) nwf = nwf + 1
+       END DO
+
+       ALLOCATE( nsubindex (nwf) )
+
+       DO jf = 1, noumef
+          IF (nc(jf) == 1 ) THEN 
+             ii = ii +1 
+             nsubindex(ii) = jf
+          END IF
+       END DO
+
+       zsto     = rdt_ice
+       zout     = nwrite * rdt_ice / nfice
+       zsec     = 0.
+       niter    = 0
+       zdept(1) = 0.
+       nmoyice  = 0
+
+    ENDIF
+
+#if ! defined key_diainstant 
+    !-- calculs des valeurs instantanees
+
+    zcmo(:,:, 1:jpnoumax ) = 0.e0 
+    DO jj = 2 , jpjm1
+       DO ji = 2 , jpim1
+          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 ) )
+          zindb  = zindh * zinda
+          ztmu   = MAX( 0.5 * zone , ( 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,4)  = frld  (ji,jj)
+          zcmo(ji,jj,5)  = sist  (ji,jj)
+          zcmo(ji,jj,6)  = fbif  (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) ) &
+               / ztmu 
+
+          zcmo(ji,jj,8)  = zindb * (  v_ice(ji,jj  ) * tmu(ji,jj  ) + v_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
+               + v_ice(ji,jj+1) * tmu(ji,jj+1) + v_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
+               / ztmu
+          zcmo(ji,jj,9)  = sst_io(ji,jj)
+          zcmo(ji,jj,10) = sss_io(ji,jj)
+
+          zcmo(ji,jj,11) = fnsolar(ji,jj) + fsolar(ji,jj)
+          zcmo(ji,jj,12) = fsolar (ji,jj)
+          zcmo(ji,jj,13) = fnsolar(ji,jj)
+          ! See thersf for the coefficient
+          zcmo(ji,jj,14) = - fsalt(ji,jj) * rday * ( sss_io(ji,jj) + epsi16 ) / soce
+          zcmo(ji,jj,15) = gtaux(ji,jj)
+          zcmo(ji,jj,16) = gtauy(ji,jj)
+          zcmo(ji,jj,17) = ( 1.0 - frld(ji,jj) ) * qsr_ice (ji,jj) + frld(ji,jj) * qsr_oce (ji,jj)
+          zcmo(ji,jj,18) = ( 1.0 - frld(ji,jj) ) * qnsr_ice(ji,jj) + frld(ji,jj) * qnsr_oce(ji,jj)
+          zcmo(ji,jj,19) = sprecip(ji,jj)
+       END DO
+    END DO
+    ! Cumulates values between outputs           
+    rcmoy(:,:,:)= rcmoy(:,:,:) + zcmo(:,:,:)
+    nmoyice = nmoyice + 1 
+    ! compute mean value if it is time to write on file
+    IF ( MOD(numit,nwrite) == 0 ) THEN
+       rcmoy(:,:,:) = rcmoy(:,:,:) / FLOAT(nmoyice)
+#else  
+       IF ( MOD(numit,nwrite) == 0 ) THEN 
+          !  case of instantaneaous output rcmoy(:,:, 1:jpnoumax ) = 0.e0
+          DO jj = 2 , jpjm1
+             DO ji = 2 , jpim1
+                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 ) )
+                zindb  = zindh * zinda
+                ztmu   = MAX( 0.5 * zone , ( 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,4)  = frld  (ji,jj)
+                rcmoy(ji,jj,5)  = sist  (ji,jj)
+                rcmoy(ji,jj,6)  = fbif  (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) ) &
+                     / ztmu
+
+                rcmoy(ji,jj,8)  = zindb * (  v_ice(ji,jj  ) * tmu(ji,jj  ) + v_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
+                     + v_ice(ji,jj+1) * tmu(ji,jj+1) + v_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
+                     / ztmu
+                rcmoy(ji,jj,9)  = sst_io(ji,jj)
+                rcmoy(ji,jj,10) = sss_io(ji,jj)
+
+                rcmoy(ji,jj,11) = fnsolar(ji,jj) + fsolar(ji,jj)
+                rcmoy(ji,jj,12) = fsolar (ji,jj)
+                rcmoy(ji,jj,13) = fnsolar(ji,jj)
+                ! See thersf for the coefficient
+                rcmoy(ji,jj,14) = - fsalt(ji,jj) * rday * ( sss_io(ji,jj) + epsi16 ) / soce
+                rcmoy(ji,jj,15) = gtaux(ji,jj)
+                rcmoy(ji,jj,16) = gtauy(ji,jj)
+                rcmoy(ji,jj,17) = ( 1.0 - frld(ji,jj) ) * qsr_ice (ji,jj) + frld(ji,jj) * qsr_oce (ji,jj)
+                rcmoy(ji,jj,18) = ( 1.0 - frld(ji,jj) ) * qnsr_ice(ji,jj) + frld(ji,jj) * qnsr_oce(ji,jj)
+                rcmoy(ji,jj,19) = sprecip(ji,jj)
+             END DO
+          END DO
+#endif
+
+          !
+          niter = niter + 1
+          DO jf = 1 , noumef
+             zfield(:,:) = (rcmoy(:,:,jf) * cmulti(jf) + cadd(jf)) * tmask(:,:,1)
+
+             IF ( jf == 7  .OR. jf == 8  .OR. jf == 11 .OR. jf == 12 .OR. jf == 15 .OR.   &
+                  jf == 23 .OR. jf == 24 .OR. jf == 16 ) THEN 
+                CALL lbc_lnk( zfield, 'T', -1. )
+             ELSE 
+                CALL lbc_lnk( zfield, 'T',  1. )
+             ENDIF
+             rcmoy(:,:,jf) = zfield(:,:)
+          END DO
+
+          IF (ll_dia_inst) THEN
+           clmode='instantaneous'
+          ELSE
+           WRITE(clmode,'(f5.1,a)' ) nwrite*rdt/86400.,' days average'
+          END IF
+          iyear = ndastp/10000
+          imon = (ndastp-iyear*10000)/100
+          iday = ndastp - imon*100 - iyear*10000
+          WRITE(clname,9000) TRIM(cexper),'ICEMOD',iyear,imon,iday
+          cltext=TRIM(cexper)//' ice modele output'//TRIM(clmode)
+          CALL dia_wri_dimg (clname, cltext, rcmoy, nwf , 'I', nsubindex)
+9000      FORMAT(a,"_",a,"_y",i4.4,"m",i2.2,"d",i2.2,".dimgproc")
+
+          rcmoy(:,:,:) = 0.0
+          nmoyice = 0 
+       END IF     !  MOD(numit, nwrite == 0 ) !
+
+     END SUBROUTINE lim_wri
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/par_ice.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/par_ice.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/par_ice.F90	(revision 884)
@@ -0,0 +1,32 @@
+MODULE par_ice
+   !!======================================================================
+   !!                       ***  MODULE par_ice   ***
+   !! Sea-Ice model : definition of the parameters
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !!  LIM 2.0, UCL-LOCEAN-IPSL (2005)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/par_ice.F90,v 1.4 2005/03/27 18:34:42 opalod Exp $
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce
+
+   IMPLICIT NONE
+   PUBLIC               ! allows par_oce and par_kind to be known in ice modules
+
+   INTEGER, PARAMETER ::   &  !:
+      jpkmax =   1    ,      &  !: ???
+      jpsmax =  2              !: ???
+
+   !ICE THERMODYNAMICS
+   INTEGER , PARAMETER ::      &  !:
+      jkmax    = 6 ,           &  !: maximum number of ice layers
+      nlay_s   = 1                !: number of snow layers
+ 
+   !ICE MECHANICAL REDISTRIBUTION
+   INTEGER , PARAMETER ::      &  !:
+      jpl      = 5,            &  !: number of ice categories
+      jpm      = 1                !: number of ice types
+
+   !!======================================================================
+END MODULE par_ice
Index: branches/dev_001_SBC/NEMO/LIM_SRC_3/thd_ice.F90
===================================================================
--- branches/dev_001_SBC/NEMO/LIM_SRC_3/thd_ice.F90	(revision 884)
+++ branches/dev_001_SBC/NEMO/LIM_SRC_3/thd_ice.F90	(revision 884)
@@ -0,0 +1,163 @@
+MODULE thd_ice
+   !!======================================================================
+   !!                       ***  MODULE thd_ice  ***
+   !! LIM sea-ice :   Ice thermodynamics in 1D
+   !!=====================================================================
+   !! History :
+   !!   2.0  !  02-11  (C. Ethe)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0, UCL-LOCEAN-IPSL (2005)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/thd_ice.F90,v 1.4 2005/03/27 18:34:42 opalod Exp $
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_ice
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !!---------------------------
+   !! * Share Module variables
+   !!---------------------------
+   REAL(wp) , PUBLIC ::   & !!! ** ice-thermo namelist (namicethd) **
+      hmelt   = -0.15  ,  &  !: maximum melting at the bottom; active only for
+                             !: one category
+      hicmin  = 0.2    ,  &  !: (REMOVE)
+      hiclim  = 0.05   ,  &  !: minimum ice thickness
+      amax    = 0.999  ,  &  !: maximum lead fraction
+      sbeta   = 1.0    ,  &  !: numerical scheme for diffusion in ice  (REMOVE)
+      parlat  = 0.0    ,  &  !: (REMOVE)
+      hakspl  = 0.5    ,  &  !: (REMOVE)
+      hibspl  = 0.5    ,  &  !: (REMOVE)
+      exld    = 2.0    ,  &  !: (REMOVE)
+      hakdif  = 1.0    ,  &  !: (REMOVE)
+      thth    = 0.2    ,  &  !: (REMOVE)
+      hnzst   = 0.1    ,  &  !: thick. of the surf. layer in temp. comp.
+      parsub  = 1.0    ,  &  !: switch for snow sublimation or not
+      alphs   = 1.0    ,  &  !: coef. for snow density when snow-ice formation
+      fraz_swi= 1.0    ,  &  !: use of frazil ice collection in function of wind (1.0) or not (0.0)
+      maxfrazb= 0.7    ,  &  !: maximum portion of frazil ice collecting at the ice bottom
+      vfrazb  = 0.41667,  &  !: threshold drift speed for collection of bottom frazil ice
+      Cfrazb  = 5.0          !: squeezing coefficient for collection of bottom frazil ice
+
+   REAL(wp), PUBLIC, DIMENSION(2)  ::  &  !:   
+      hiccrit = (/0.3,0.3/)  !: ice th. for lateral accretion in the NH (SH) (m)
+
+   !!-----------------------------
+   !! * Share 1D Module variables
+   !!-----------------------------
+   !: In ice thermodynamics, to spare memory, the vectors are folded
+   !: from 1D to 2D vectors. The following variables, with ending _1d (or _b)
+   !: are the variables corresponding to 2d vectors
+
+   INTEGER , PUBLIC, DIMENSION(jpij) ::   &  !:
+      npb     ,   &   !: number of points where computations has to be done
+      npac            !: correspondance between the points (lateral accretion)
+
+   REAL(wp), PUBLIC, DIMENSION(jpij) ::   &  !: 
+      qldif_1d    ,     &  !: corresponding to the 2D var  qldif
+      qcmif_1d    ,     &  !: corresponding to the 2D var  qcmif
+      fstbif_1d   ,     &  !:    "                  "      fstric
+      fltbif_1d   ,     &  !:    "                  "      ffltbif
+      fscbq_1d    ,     &  !:    "                  "      fscmcbq
+      qsr_ice_1d  ,     &  !:    "                  "      qsr_ice
+      fr1_i0_1d   ,     &  !:    "                  "      fr1_i0
+      fr2_i0_1d   ,     &  !:    "                  "      fr2_i0
+      qnsr_ice_1d ,     &  !:    "                  "      qns_ice
+      qfvbq_1d    ,     &  !:    "                  "      qfvbq
+      t_bo_b               !:    "                  "      t_bo
+
+   REAL(wp), PUBLIC, DIMENSION(jpij) ::   &  !: 
+      sprecip_1d  ,     &  !:    "                  "      sprecip
+      frld_1d     ,     &  !:    "                  "      frld
+      at_i_b      ,     &  !:    "                  "      frld
+      fbif_1d     ,     &  !:    "                  "      fbif
+      rdmicif_1d  ,     &  !:    "                  "      rdmicif
+      rdmsnif_1d  ,     &  !:    "                  "      rdmsnif
+      qlbbq_1d    ,     &  !:    "                  "      qlbsbq
+      dmgwi_1d    ,     &  !:    "                  "      dmgwi
+      dvsbq_1d    ,     &  !:    "                  "      rdvosif
+      dvbbq_1d    ,     &  !:    "                  "      rdvobif
+      dvlbq_1d    ,     &  !:    "                  "      rdvolif
+      dvnbq_1d    ,     &  !:    "                  "      rdvolif
+      dqns_ice_1d ,     &  !:    "                  "      dqns_ice
+      qla_ice_1d  ,     &  !:    "                  "      qla_ice
+      dqla_ice_1d ,     &  !:    "                  "      dqla_ice
+      ! to reintegrate longwave flux inside the ice thermodynamics
+      qtur_ice_1d ,     &  !:    "                  "      qtur_ice
+      dqtu_ice_1d ,     &  !:    "                  "      dqtu_ice
+      catm_ice_1d ,     &  !:    "                  "      catm_ice
+      tatm_ice_1d ,     &  !:    "                  "      tatm_ice
+      evsq_ice_1d ,     &  !:    "                  "      evsq_ice
+      sbud_ice_1d ,     &  !:    "                  "      sbud_ice
+      fsup        ,     &  !:    Energy flux sent from bottom to lateral ablation if |dhb|> 0.15 m
+      focea       ,     &  !:    Remaining energy in case of total ablation
+      i0          ,     &  !:    fraction of radiation transmitted to the ice interior
+      old_ht_i_b  ,     &  !:    Ice thickness at the beginnning of the time step [m]
+      old_ht_s_b  ,     &  !:    Snow thickness at the beginning of the time step [m]
+      fsbri_1d    ,     &  !:    Salt flux due to brine drainage
+      fhbri_1d    ,     &  !:    Heat flux due to brine drainage
+      fseqv_1d    ,     &  !:    Equivalent Salt flux due to ice growth/decay
+      dsm_i_fl_1d ,     &  !:    Ice salinity variations due to flushing
+      dsm_i_gd_1d ,     &  !:    Ice salinity variations due to gravity drainage
+      dsm_i_se_1d ,     &  !:    Ice salinity variations due to basal salt entrapment
+      dsm_i_la_1d ,     &  !:    Ice salinity variations due to lateral accretion    
+      dsm_i_si_1d ,     &  !:    Ice salinity variations due to lateral accretion    
+      hicol_b              !:    Ice collection thickness accumulated in fleads
+
+   REAL(wp), PUBLIC, DIMENSION(jpij) ::   &  !:
+      t_su_b      ,     &  !:    "                  "      t_su
+      a_i_b       ,     &  !:                              a_i
+      ht_i_b      ,     &  !:    "                  "      ht_s
+      ht_s_b      ,     &  !:    "                  "      ht_i
+      fc_su       ,     &  !:    Surface Conduction flux 
+      fc_bo_i     ,     &  !:    Bottom  Conduction flux 
+      dh_s_tot    ,     &  !:    Snow accretion/ablation        [m]
+      dh_i_surf   ,     &  !:    Ice surface accretion/ablation [m]
+      dh_i_bott   ,     &  !:    Ice bottom accretion/ablation  [m]
+      dh_snowice  ,     &  !:    Snow ice formation             [m of ice]
+      sm_i_b      ,     &  !:    Ice bulk salinity [ppt]
+      s_i_new     ,     &  !:    Salinity of new ice at the bottom
+      s_snowice   ,     &  !:    Salinity of new snow ice on top of the ice
+      o_i_b                !:    Ice age                        [days]
+
+   REAL(wp), PUBLIC, DIMENSION(jpij,nlay_s) ::   &  !:
+      t_s_b              !: corresponding to the 2D var  t_s
+   REAL(wp), PUBLIC, DIMENSION(jpij,jkmax) ::   &  !:
+      t_i_b,            &  !: corresponding to the 2D var  t_i
+      s_i_b,            &  !: profiled ice salinity
+      q_i_b,            &  !:    Ice  enthalpy per unit volume
+      q_s_b                !:    Snow enthalpy per unit volume
+
+  ! Clean the following ...
+  ! These variables are coded for conservation checks
+   REAL(wp), PUBLIC, DIMENSION(jpij,jpl)    ::   &  !
+      qt_i_in   ,           &  !: ice energy summed over categories (initial)
+      qt_i_fin  ,           &  !: ice energy summed over categories (final)
+      qt_s_in, qt_s_fin  ,  &  !: snow energy summed over categories
+      dq_i, sum_fluxq    ,  &  !: increment of energy, sum of fluxes
+      fatm, foce,           &  !: atmospheric, oceanic, heat flux
+      cons_error, surf_error   !: conservation, surface error
+
+   REAL(wp), PUBLIC, DIMENSION(jpij,jkmax)::   &  !:  goes to trash
+      q_i_layer_in,         &
+      q_i_layer_fin,        &
+      dq_i_layer, radab
+
+   REAL(wp), PUBLIC, DIMENSION(jpij) ::   &  !:
+      ftotal_in  ,          &  !: initial total heat flux
+      ftotal_fin               !: final total heat flux
+
+   REAL(wp), PUBLIC, DIMENSION(jpij,0:nlay_s) ::   &  !:
+      fc_s
+   REAL(wp), PUBLIC, DIMENSION(jpij,0:jkmax)  ::   &  !:
+      fc_i
+   REAL(wp), PUBLIC, DIMENSION(jpij,nlay_s) ::   &  !:
+      de_s_lay
+   REAL(wp), PUBLIC, DIMENSION(jpij,jkmax)  ::   &  !:
+      de_i_lay
+   INTEGER , PUBLIC ::                           &
+      jiindex_1d   ! 1D index of debugging point
+
+   !!======================================================================
+END MODULE thd_ice
