Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/Job_mpi
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/Job_mpi	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/Job_mpi	(revision 3938)
@@ -7,5 +7,4 @@
 # Type de travail
 # @ job_type = parallel
-# @ as_limit = 7.0Gb
 # Fichier de sortie standard
 # @ output = Script_Output
@@ -13,6 +12,6 @@
 # @ error = error
 # Nombre de processus demandes
-# @ total_tasks =  30
-# @ environment = "BATCH_NUM_PROC_TOT=30"
+# @ total_tasks = 24 
+# @ environment = "BATCH_NUM_PROC_TOT=24"
 # Temps CPU max. par processus MPI hh:mm:ss
 # @ wall_clock_limit = 4:30:00
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/xmlio_server.def
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/xmlio_server.def	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/EXP00/xmlio_server.def	(revision 3938)
@@ -30,5 +30,5 @@
                               !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
                               !  is optimal for postprocessing which works exclusively with horizontal slabs
-   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+   ln_nc4zip      =   .FALSE.  !  (T) use netcdf4 chunking and compression
                               !  (F) ignore chunking information and produce netcdf3-compatible files  
 /
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/daymod.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/daymod.F90	(revision 3937)
+++ 	(revision )
@@ -1,361 +1,0 @@
-MODULE daymod
-   !!======================================================================
-   !!                       ***  MODULE  daymod  ***
-   !! Ocean        :  calendar 
-   !!=====================================================================
-   !! History :  OPA  ! 1994-09  (M. Pontaud M. Imbard)  Original code
-   !!                 ! 1997-03  (O. Marti)
-   !!                 ! 1997-05  (G. Madec) 
-   !!                 ! 1997-08  (M. Imbard)
-   !!   NEMO     1.0  ! 2003-09  (G. Madec)  F90 + nyear, nmonth, nday
-   !!                 ! 2004-01  (A.M. Treguier) new calculation based on adatrj
-   !!                 ! 2006-08  (G. Madec)  surface module major update
-   !!----------------------------------------------------------------------      
-
-   !!----------------------------------------------------------------------
-   !!   day        : calendar
-   !!  
-   !!           -------------------------------
-   !!           ----------- WARNING -----------
-   !!
-   !!   we suppose that the time step is deviding the number of second of in a day
-   !!             ---> MOD( rday, rdttra(1) ) == 0
-   !!
-   !!           ----------- WARNING -----------
-   !!           -------------------------------
-   !!  
-   !!----------------------------------------------------------------------
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE in_out_manager  ! I/O manager
-   USE iom             ! 
-   USE ioipsl, ONLY :   ymds2ju   ! for calendar
-   USE prtctl          ! Print control
-   USE restart         ! 
-   USE trc_oce, ONLY : lk_offline ! offline flag
-   USE timing          ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   day        ! called by step.F90
-   PUBLIC   day_init   ! called by istate.F90
-
-   INTEGER ::   nsecd, nsecd05, ndt, ndt05
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: daymod.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE day_init
-      !!----------------------------------------------------------------------
-      !!                   ***  ROUTINE day_init  ***
-      !! 
-      !! ** Purpose :   Initialization of the calendar values to their values 1 time step before nit000 
-      !!                because day will be called at the beginning of step
-      !!
-      !! ** Action  : - nyear        : current year
-      !!              - nmonth       : current month of the year nyear
-      !!              - nday         : current day of the month nmonth
-      !!              - nday_year    : current day of the year nyear
-      !!              - nsec_year    : current time step counted in second since 00h jan 1st of the current year
-      !!              - nsec_month   : current time step counted in second since 00h 1st day of the current month
-      !!              - nsec_day     : current time step counted in second since 00h of the current day
-      !!              - nsec1jan000  : second since Jan. 1st 00h of nit000 year and Jan. 1st 00h of the current year
-      !!              - nmonth_len, nyear_len, nmonth_half, nmonth_end through day_mth
-      !!----------------------------------------------------------------------
-      INTEGER  ::   inbday, idweek
-      REAL(wp) ::   zjul
-      !!----------------------------------------------------------------------
-      !
-      ! all calendar staff is based on the fact that MOD( rday, rdttra(1) ) == 0
-      IF( MOD( rday     , rdttra(1) ) /= 0. )   CALL ctl_stop( 'the time step must devide the number of second of in a day' )
-      IF( MOD( rday     , 2.        ) /= 0. )   CALL ctl_stop( 'the number of second of in a day must be an even number'    )
-      IF( MOD( rdttra(1), 2.        ) /= 0. )   CALL ctl_stop( 'the time step (in second) must be an even number'           )
-      nsecd   = NINT(rday           )
-      nsecd05 = NINT(0.5 * rday     )
-      ndt     = NINT(      rdttra(1))
-      ndt05   = NINT(0.5 * rdttra(1))
-
-      IF( .NOT. lk_offline ) CALL day_rst( nit000, 'READ' ) 
-
-      ! set the calandar from ndastp (read in restart file and namelist)
-
-      nyear   =   ndastp / 10000
-      nmonth  = ( ndastp - (nyear * 10000) ) / 100
-      nday    =   ndastp - (nyear * 10000) - ( nmonth * 100 ) 
-
-      CALL ymds2ju( nyear, nmonth, nday, 0.0, fjulday )  ! we assume that we start run at 00:00
-      IF( ABS(fjulday - REAL(NINT(fjulday),wp)) < 0.1 / rday )   fjulday = REAL(NINT(fjulday),wp)   ! avoid truncation error
-      fjulday = fjulday + 1.                             ! move back to the day at nit000 (and not at nit000 - 1)
-
-      nsec1jan000 = 0
-      CALL day_mth
-      
-      IF ( nday == 0 ) THEN     !   for ex if ndastp = ndate0 - 1
-         nmonth = nmonth - 1  
-         nday = nmonth_len(nmonth)
-      ENDIF
-      IF ( nmonth == 0 ) THEN   ! go at the end of previous year
-         nmonth = 12
-         nyear = nyear - 1
-         nsec1jan000 = nsec1jan000 - nsecd * nyear_len(0)
-         IF( nleapy == 1 )   CALL day_mth
-      ENDIF
-      
-      ! day since january 1st
-      nday_year = nday + SUM( nmonth_len(1:nmonth - 1) )
-
-      !compute number of days between last monday and today      
-      CALL ymds2ju( 1900, 01, 01, 0.0, zjul )  ! compute julian day value of 01.01.1900 (our reference that was a Monday)
-      inbday = NINT(fjulday - zjul)            ! compute nb day between  01.01.1900 and current day  
-      idweek = MOD(inbday, 7)                  ! compute nb day between last monday and current day  
-
-      ! number of seconds since the beginning of current year/month/week/day at the middle of the time-step
-      nsec_year  = nday_year * nsecd - ndt05   ! 1 time step before the middle of the first time step
-      nsec_month = nday      * nsecd - ndt05   ! because day will be called at the beginning of step
-      nsec_week  = idweek    * nsecd - ndt05
-      nsec_day   =             nsecd - ndt05
-
-      ! control print
-      IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i6)')' ==============>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
-           &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day, '  nsec_week:', nsec_week
-
-      ! Up to now, calendar parameters are related to the end of previous run (nit000-1)
-      ! call day to set the calendar parameters at the begining of the current simulaton. needed by iom_init
-      CALL day( nit000 )
-      !
-   END SUBROUTINE day_init
-
-
-   SUBROUTINE day_mth
-      !!----------------------------------------------------------------------
-      !!                   ***  ROUTINE day_init  ***
-      !! 
-      !! ** Purpose :   calendar values related to the months
-      !!
-      !! ** Action  : - nmonth_len    : length in days of the months of the current year
-      !!              - nyear_len     : length in days of the previous/current year
-      !!              - nmonth_half   : second since the beginning of the year and the halft of the months
-      !!              - nmonth_end    : second since the beginning of the year and the end of the months
-      !!----------------------------------------------------------------------
-      INTEGER  ::   jm               ! dummy loop indice
-      !!----------------------------------------------------------------------
-
-      ! length of the month of the current year (from nleapy, read in namelist)
-      IF ( nleapy < 2 ) THEN 
-         nmonth_len(:) = (/ 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31 /)
-         nyear_len(:) = 365
-         IF ( nleapy == 1 ) THEN   ! we are using calandar with leap years
-            IF ( MOD(nyear-1, 4) == 0 .AND. ( MOD(nyear-1, 400) == 0 .OR. MOD(nyear-1, 100) /= 0 ) ) THEN
-               nyear_len(0) = 366
-            ENDIF
-            IF ( MOD(nyear, 4) == 0 .AND. ( MOD(nyear, 400) == 0 .OR. MOD(nyear, 100) /= 0 ) ) THEN
-               nmonth_len(2) = 29
-               nyear_len(1) = 366
-            ENDIF
-         ENDIF
-      ELSE
-         nmonth_len(:) = nleapy   ! all months with nleapy days per year
-         nyear_len(:) = 12 * nleapy
-      ENDIF
-
-      ! half month in second since the begining of the year:
-      ! time since Jan 1st   0     1     2    ...    11    12    13
-      !          ---------*--|--*--|--*--| ... |--*--|--*--|--*--|--------------------------------------
-      !                 <---> <---> <--->  ...  <---> <---> <--->        
-      ! month number      0     1     2    ...    11    12    13
-      !
-      ! nmonth_half(jm) = rday * REAL( 0.5 * nmonth_len(jm) + SUM(nmonth_len(1:jm-1)) )
-      nmonth_half(0) = - nsecd05 * nmonth_len(0)
-      DO jm = 1, 13
-         nmonth_half(jm) = nmonth_half(jm-1) + nsecd05 * ( nmonth_len(jm-1) + nmonth_len(jm) )
-      END DO
-
-      nmonth_end(0) = 0
-      DO jm = 1, 13
-         nmonth_end(jm) = nmonth_end(jm-1) + nsecd * nmonth_len(jm)
-      END DO
-      !           
-   END SUBROUTINE 
-
-
-   SUBROUTINE day( kt )
-      !!----------------------------------------------------------------------
-      !!                      ***  ROUTINE day  ***
-      !! 
-      !! ** Purpose :   Compute the date with a day iteration IF necessary.
-      !!
-      !! ** Method  : - ???
-      !!
-      !! ** Action  : - nyear     : current year
-      !!              - nmonth    : current month of the year nyear
-      !!              - nday      : current day of the month nmonth
-      !!              - nday_year : current day of the year nyear
-      !!              - ndastp    : = nyear*10000 + nmonth*100 + nday
-      !!              - adatrj    : date in days since the beginning of the run
-      !!              - nsec_year : current time of the year (in second since 00h, jan 1st)
-      !!----------------------------------------------------------------------      
-      INTEGER, INTENT(in) ::   kt        ! ocean time-step indices
-      !
-      CHARACTER (len=25) ::   charout
-      REAL(wp)           ::   zprec      ! fraction of day corresponding to 0.1 second
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('day')
-      !
-      zprec = 0.1 / rday
-      !                                                 ! New time-step
-      nsec_year  = nsec_year  + ndt 
-      nsec_month = nsec_month + ndt                 
-      nsec_week  = nsec_week  + ndt
-      nsec_day   = nsec_day   + ndt                
-      adatrj  = adatrj  + rdttra(1) / rday
-      fjulday = fjulday + rdttra(1) / rday
-      IF( ABS(fjulday - REAL(NINT(fjulday),wp)) < zprec )   fjulday = REAL(NINT(fjulday),wp)   ! avoid truncation error
-      IF( ABS(adatrj  - REAL(NINT(adatrj ),wp)) < zprec )   adatrj  = REAL(NINT(adatrj ),wp)   ! avoid truncation error
-      
-      IF( nsec_day > nsecd ) THEN                       ! New day
-         !
-         nday      = nday + 1
-         nday_year = nday_year + 1
-         nsec_day  = ndt05
-         !
-         IF( nday == nmonth_len(nmonth) + 1 ) THEN      ! New month
-            nday   = 1
-            nmonth = nmonth + 1
-            nsec_month = ndt05
-            IF( nmonth == 13 ) THEN                     ! New year
-               nyear     = nyear + 1
-               nmonth    = 1
-               nday_year = 1
-               nsec_year = ndt05
-               nsec1jan000 = nsec1jan000 + nsecd * nyear_len(1)
-               IF( nleapy == 1 )   CALL day_mth
-            ENDIF
-         ENDIF
-         !
-         ndastp = nyear * 10000 + nmonth * 100 + nday   ! New date
-         !
-         !compute first day of the year in julian days
-         CALL ymds2ju( nyear, 01, 01, 0.0, fjulstartyear )
-         !
-         IF(lwp) WRITE(numout,'(a,i8,a,i4.4,a,i2.2,a,i2.2,a,i3.3)') '======>> time-step =', kt,   &
-              &   '      New day, DATE Y/M/D = ', nyear, '/', nmonth, '/', nday, '      nday_year = ', nday_year
-         IF(lwp) WRITE(numout,'(a,i8,a,i7,a,i5)') '         nsec_year = ', nsec_year,   &
-              &   '   nsec_month = ', nsec_month, '   nsec_day = ', nsec_day, '   nsec_week = ', nsec_week
-      ENDIF
-
-      IF( nsec_week > 7*nsecd )   nsec_week = ndt05     ! New week
-      
-      IF(ln_ctl) THEN
-         WRITE(charout,FMT="('kt =', I4,'  d/m/y =',I2,I2,I4)") kt, nday, nmonth, nyear
-         CALL prt_ctl_info(charout)
-      ENDIF
-
-      IF( .NOT. lk_offline ) CALL rst_opn( kt )               ! Open the restart file if needed and control lrst_oce
-      IF( lrst_oce         ) CALL day_rst( kt, 'WRITE' )      ! write day restart information
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('day')
-      !
-   END SUBROUTINE day
-
-
-   SUBROUTINE day_rst( kt, cdrw )
-      !!---------------------------------------------------------------------
-      !!                   ***  ROUTINE ts_rst  ***
-      !! 
-      !!  ** Purpose : Read or write calendar in restart file:
-      !! 
-      !!  WRITE(READ) mode:
-      !!       kt        : number of time step since the begining of the experiment at the 
-      !!                   end of the current(previous) run
-      !!       adatrj(0) : number of elapsed days since the begining of the experiment at the 
-      !!                   end of the current(previous) run (REAL -> keep fractions of day)
-      !!       ndastp    : date at the end of the current(previous) run (coded as yyyymmdd integer)
-      !! 
-      !!   According to namelist parameter nrstdt,
-      !!       nrstdt = 0  no control on the date (nit000 is  arbitrary).
-      !!       nrstdt = 1  we verify that nit000 is equal to the last
-      !!                   time step of previous run + 1.
-      !!       In both those options, the  exact duration of the experiment
-      !!       since the beginning (cumulated duration of all previous restart runs)
-      !!       is not stored in the restart and is assumed to be (nit000-1)*rdt.
-      !!       This is valid is the time step has remained constant.
-      !!
-      !!       nrstdt = 2  the duration of the experiment in days (adatrj)
-      !!                    has been stored in the restart file.
-      !!----------------------------------------------------------------------
-      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
-      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
-      !
-      REAL(wp) ::   zkt, zndastp
-      !!----------------------------------------------------------------------
-      
-      IF( TRIM(cdrw) == 'READ' ) THEN
-
-         IF( iom_varid( numror, 'kt', ldstop = .FALSE. ) > 0 ) THEN
-            ! Get Calendar informations
-            CALL iom_get( numror, 'kt', zkt )   ! last time-step of previous run
-            IF(lwp) THEN
-               WRITE(numout,*) ' *** Info read in restart : '
-               WRITE(numout,*) '   previous time-step                               : ', NINT( zkt )
-               WRITE(numout,*) ' *** restart option'
-               SELECT CASE ( nrstdt )
-               CASE ( 0 )   ;   WRITE(numout,*) ' nrstdt = 0 : no control of nit000'
-               CASE ( 1 )   ;   WRITE(numout,*) ' nrstdt = 1 : no control the date at nit000 (use ndate0 read in the namelist)'
-               CASE ( 2 )   ;   WRITE(numout,*) ' nrstdt = 2 : calendar parameters read in restart'
-               END SELECT
-               WRITE(numout,*)
-            ENDIF
-            ! Control of date 
-            !clem IF( nit000 - NINT( zkt ) /= 1 .AND. nrstdt /= 0 )                                         & 
-            !clem      &   CALL ctl_stop( ' ===>>>> : problem with nit000 for the restart',                 & 
-            !clem      &                  ' verify the restart file or rerun with nrstdt = 0 (namelist)' )
-            ! define ndastp and adatrj
-            IF ( nrstdt == 2 ) THEN 
-               ! read the parameters correspondting to nit000 - 1 (last time step of previous run)
-               CALL iom_get( numror, 'ndastp', zndastp )
-               ndastp = NINT( zndastp )
-               CALL iom_get( numror, 'adatrj', adatrj  )
-            ELSE 
-               ! parameters correspondting to nit000 - 1 (as we start the step loop with a call to day)
-               ndastp = ndate0 - 1     ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00
-               adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday 
-               ! note this is wrong if time step has changed during run 
-            ENDIF
-         ELSE
-            ! parameters correspondting to nit000 - 1 (as we start the step loop with a call to day)
-            ndastp = ndate0 - 1        ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00
-            adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday 
-         ENDIF
-         IF( ABS(adatrj  - REAL(NINT(adatrj),wp)) < 0.1 / rday )   adatrj = REAL(NINT(adatrj),wp)   ! avoid truncation error
-         !
-         IF(lwp) THEN
-            WRITE(numout,*) ' *** Info used values : '
-            WRITE(numout,*) '   date ndastp                                      : ', ndastp
-            WRITE(numout,*) '   number of elapsed days since the begining of run : ', adatrj
-            WRITE(numout,*)
-         ENDIF
-         !
-      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN
-         !
-         IF( kt == nitrst ) THEN
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'rst_write : write oce restart file  kt =', kt
-            IF(lwp) WRITE(numout,*) '~~~~~~~'         
-         ENDIF
-         ! calendar control
-         CALL iom_rstput( kt, nitrst, numrow, 'kt'     , REAL( kt    , wp) )   ! time-step 
-         CALL iom_rstput( kt, nitrst, numrow, 'ndastp' , REAL( ndastp, wp) )   ! date
-         CALL iom_rstput( kt, nitrst, numrow, 'adatrj' , adatrj            )   ! number of elapsed days since
-         !                                                                     ! the begining of the run [s]
-      ENDIF
-      !
-   END SUBROUTINE day_rst
-
-   !!======================================================================
-END MODULE daymod
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/diahsb.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/diahsb.F90	(revision 3937)
+++ 	(revision )
@@ -1,330 +1,0 @@
-MODULE diahsb
-   !!======================================================================
-   !!                       ***  MODULE  diahsb  ***
-   !! Ocean diagnostics: Heat, salt and volume budgets
-   !!======================================================================
-   !! History :  3.3  ! 2010-09  (M. Leclair)  Original code 
-   !!                 ! 2012-10  (C. Rousset)  add iom_put
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE sbc_oce         ! surface thermohaline fluxes
-   USE in_out_manager  ! I/O manager
-   USE domvvl          ! vertical scale factors
-   USE traqsr          ! penetrative solar radiation
-   USE trabbc          ! bottom boundary condition 
-   USE lib_mpp         ! distributed memory computing library
-   USE trabbc          ! bottom boundary condition
-   USE obc_par         ! (for lk_obc)
-   USE bdy_par         ! (for lk_bdy)
-   USE timing          ! preformance summary
-   USE iom             ! I/O manager
-   USE lib_fortran     ! glob_sum
-   USE restart         ! ocean restart
-   USE wrk_nemo         ! work arrays
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dia_hsb        ! routine called by step.F90
-   PUBLIC   dia_hsb_init   ! routine called by nemogcm.F90
-   PUBLIC   dia_hsb_rst    ! routine called by step.F90
-
-   LOGICAL, PUBLIC ::   ln_diahsb  = .FALSE.   !: check the heat and salt budgets
-
-   REAL(wp), SAVE                                ::   frc_t      , frc_s     , frc_v   ! global forcing trends
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ssh_ini              !
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hc_loc_ini, sc_loc_ini, e3t_ini  !
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hcssh_loc_ini, scssh_loc_ini     !
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: diahsb.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE dia_hsb( kt )
-      !!---------------------------------------------------------------------------
-      !!                  ***  ROUTINE dia_hsb  ***
-      !!     
-      !! ** Purpose: Compute the ocean global heat content, salt content and volume conservation
-      !!	
-      !! ** Method : - Compute the deviation of heat content, salt content and volume
-      !!	            at the current time step from their values at nit000
-      !!	            - Compute the contribution of forcing and remove it from these deviations
-      !!
-      !!---------------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      !!
-      INTEGER    ::   jk                          ! dummy loop indice
-      REAL(wp)   ::   zdiff_hc    , zdiff_sc      ! heat and salt content variations
-      REAL(wp)   ::   zdiff_v1    , zdiff_v2      ! volume variation
-      REAL(wp)   ::   z_hc        , z_sc          ! heat and salt content
-      REAL(wp)   ::   z_v1        , z_v2          ! volume
-      REAL(wp)   ::   z1_rau0                     ! local scalars
-      REAL(wp)   ::   zdeltat                     !    -     -
-      REAL(wp)   ::   z_frc_trd_t , z_frc_trd_s   !    -     -
-      REAL(wp)   ::   z_frc_trd_v                 !    -     -
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zsurf              !
-      !!---------------------------------------------------------------------------
-      IF( nn_timing == 1 )   CALL timing_start('dia_hsb')      
-
-      CALL wrk_alloc( jpi, jpj, zsurf )
-  
-      zsurf(:,:) = e1t(:,:) * e2t(:,:) * tmask(:,:,1) * tmask_i(:,:)      ! masked surface grid cell area
-      
-      ! ------------------------- !
-      ! 1 - Trends due to forcing !
-      ! ------------------------- !
-      z1_rau0 = 1.e0 / rau0
-      z_frc_trd_v = z1_rau0 * glob_sum( - ( emp(:,:) - rnf(:,:) ) * zsurf(:,:) ) ! volume fluxes
-      z_frc_trd_t =           glob_sum( sbc_tsc(:,:,jp_tem) * zsurf(:,:) )       ! heat fluxes
-      z_frc_trd_s =           glob_sum( sbc_tsc(:,:,jp_sal) * zsurf(:,:) )       ! salt fluxes
-      ! Add penetrative solar radiation
-      IF( ln_traqsr )   z_frc_trd_t = z_frc_trd_t + ro0cpr * glob_sum( qsr     (:,:) * zsurf(:,:) )
-      ! Add geothermal heat flux
-      IF( ln_trabbc )   z_frc_trd_t = z_frc_trd_t + ro0cpr * glob_sum( qgh_trd0(:,:) * zsurf(:,:) )
-      !
-      frc_v = frc_v + z_frc_trd_v * rdt
-      frc_t = frc_t + z_frc_trd_t * rdt
-      frc_s = frc_s + z_frc_trd_s * rdt
-
-      ! ------------------------ !
-      ! 2a -  Content variations !
-      ! ------------------------ !
-      zdiff_v2 = 0._wp
-      zdiff_hc = 0._wp
-      zdiff_sc = 0._wp
-      ! volume variation (calculated with ssh)
-      zdiff_v1 = glob_sum( zsurf(:,:) * ( sshn(:,:) - ssh_ini(:,:) ) )
-      DO jk = 1, jpkm1
-         ! volume variation (calculated with scale factors)
-         zdiff_v2 = zdiff_v2 + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) - e3t_ini(:,:,jk) ) )
-         ! heat content variation
-         zdiff_hc = zdiff_hc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_tem)   &
-            &                           - hc_loc_ini(:,:,jk) ) )
-         ! salt content variation
-         zdiff_sc = zdiff_sc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_sal)   &
-            &                           - sc_loc_ini(:,:,jk) ) )
-      ENDDO
-
-      ! Substract forcing from heat content, salt content and volume variations
-      !frc_v = zdiff_v2 - frc_v
-      !frc_t = zdiff_hc - frc_t
-      !frc_s = zdiff_sc - frc_s
-      
-      ! add ssh if not vvl
-#ifndef key_vvl
-     zdiff_v2 = zdiff_v2 + zdiff_v1
-     zdiff_hc = zdiff_hc + glob_sum( zsurf(:,:) * ( sshn(:,:) * tsn(:,:,1,jp_tem)   &
-            &                           - hcssh_loc_ini(:,:) ) )
-     zdiff_sc = zdiff_sc + glob_sum( zsurf(:,:) * ( sshn(:,:) * tsn(:,:,1,jp_sal)   &
-            &                           - scssh_loc_ini(:,:) ) )
-#endif 
-      !
-      ! ----------------------- !
-      ! 2b -  Content           !
-      ! ----------------------- !
-      z_v2 = 0._wp
-      z_hc = 0._wp
-      z_sc = 0._wp
-      ! volume (calculated with ssh)
-      z_v1 = glob_sum( zsurf(:,:) * sshn(:,:) )
-      DO jk = 1, jpkm1
-         ! volume (calculated with scale factors)
-         z_v2 = z_v2 + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) )
-         ! heat content
-         z_hc = z_hc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) * tsn(:,:,jk,jp_tem) )
-         ! salt content
-         z_sc = z_sc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) * tsn(:,:,jk,jp_sal) )
-      ENDDO
-      ! add ssh if not vvl
-#ifndef key_vvl
-     z_v2 = z_v2 + z_v1
-     z_hc = z_hc + glob_sum( zsurf(:,:) * sshn(:,:) * tsn(:,:,1,jp_tem) )
-     z_sc = z_sc + glob_sum( zsurf(:,:) * sshn(:,:) * tsn(:,:,1,jp_sal) )
-#endif 
-
-      ! ----------------------- !
-      ! 3 - Diagnostics writing !
-      ! ----------------------- !
-      zdeltat  = 1.e0 / ( ( kt - nit000 + 1 ) * rdt )
-!
-      CALL iom_put( 'bgtemper',z_hc / z_v2 )               ! Temperature (C) 
-      CALL iom_put( 'bgsaline',z_sc / z_v2 )               ! Salinity (psu)
-      !CALL iom_put( 'bgheatco',zdiff_hc*fact1*zdeltat )      ! Equivalent heat flux (W/m2)
-      !CALL iom_put( 'bgsaltco',zdiff_sc*fact21*zdeltat )     ! Equivalent water flux (mm/s)
-      CALL iom_put( 'bgheatco',zdiff_hc * rau0 * rcp * 1.e-9_wp ) ! Heat content variation (10^9 J)
-      CALL iom_put( 'bgsaltco',zdiff_sc * 1.e-9 )                        ! Salt content variation (psu*km3) 
-      CALL iom_put( 'bgvolssh',zdiff_v1 * 1.e-9 )                         ! volume ssh (km3)  
-      CALL iom_put( 'bgsshtot',zdiff_v1 / glob_sum(zsurf) )              ! ssh (m)  
-      CALL iom_put( 'bgvoltot',zdiff_v2 * 1.e-9 )                         ! volume total (km3) 
-      CALL iom_put( 'bgfrcvol',frc_v * 1.e-9 )                         ! vol - surface forcing (volume) 
-      CALL iom_put( 'bgfrctem',frc_t * rau0 * rcp * 1.e-9_wp ) ! hc  - surface forcing (heat content) 
-      CALL iom_put( 'bgfrcsal',frc_s * 1.e-9 )                         ! sc  - surface forcing (salt content) 
-      !
-      CALL wrk_dealloc( jpi, jpj, zsurf )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('dia_hsb')
-!
-   END SUBROUTINE dia_hsb
-
-
-   SUBROUTINE dia_hsb_init
-      !!---------------------------------------------------------------------------
-      !!                  ***  ROUTINE dia_hsb  ***
-      !!     
-      !! ** Purpose: Initialization for the heat salt volume budgets
-      !!	
-      !! ** Method : Compute initial heat content, salt content and volume
-      !!
-      !! ** Action : - Compute initial heat content, salt content and volume
-      !!             - Initialize forcing trends
-      !!             - Compute coefficients for conversion
-      !!---------------------------------------------------------------------------
-      INTEGER            ::   jk       ! dummy loop indice
-      INTEGER            ::   ierror   ! local integer
-      !!
-      NAMELIST/namhsb/ ln_diahsb
-      !!----------------------------------------------------------------------
-      !
-      REWIND ( numnam )              ! Read Namelist namhsb 
-      READ   ( numnam, namhsb )
-      !
-      IF(lwp) THEN                   ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'dia_hsb_init : check the heat and salt budgets'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist namhsb : set hsb parameters'
-         WRITE(numout,*) '      Switch for hsb diagnostic (T) or not (F)  ln_diahsb  = ', ln_diahsb
-      ENDIF
-
-      IF( .NOT. ln_diahsb )   RETURN
-
-         ! ------------------- !
-         ! 1 - Allocate memory !
-         ! ------------------- !
-         ALLOCATE( hc_loc_ini(jpi,jpj,jpk), STAT=ierror )
-         IF( ierror > 0 ) THEN
-            CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN
-         ENDIF
-         ALLOCATE( sc_loc_ini(jpi,jpj,jpk), STAT=ierror )
-         IF( ierror > 0 ) THEN
-            CALL ctl_stop( 'dia_hsb: unable to allocate sc_loc_ini' )   ;   RETURN
-         ENDIF
-         ALLOCATE( hcssh_loc_ini(jpi,jpj), STAT=ierror )
-         IF( ierror > 0 ) THEN
-            CALL ctl_stop( 'dia_hsb: unable to allocate hcssh_loc_ini' )   ;   RETURN
-         ENDIF
-         ALLOCATE( scssh_loc_ini(jpi,jpj), STAT=ierror )
-         IF( ierror > 0 ) THEN
-            CALL ctl_stop( 'dia_hsb: unable to allocate scssh_loc_ini' )   ;   RETURN
-         ENDIF
-         ALLOCATE( e3t_ini(jpi,jpj,jpk)   , STAT=ierror )
-         IF( ierror > 0 ) THEN
-            CALL ctl_stop( 'dia_hsb: unable to allocate e3t_ini' )      ;   RETURN
-         ENDIF
-         ALLOCATE( ssh_ini(jpi,jpj)       , STAT=ierror )
-         IF( ierror > 0 ) THEN
-            CALL ctl_stop( 'dia_hsb: unable to allocate ssh_ini' )      ;   RETURN
-         ENDIF
-         
-         ! ----------------------------------------------- !
-         ! 2 - Time independant variables and file opening !
-         ! ----------------------------------------------- !
-         WRITE(numout,*) "dia_hsb: heat salt volume budgets activated"
-         IF( lk_obc .or. lk_bdy ) THEN
-            CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' )         
-         ENDIF
-         
-         ! ---------------------------------- !
-         ! 4 - initial conservation variables !
-         ! ---------------------------------- !
-         !ssh_ini(:,:) = sshn(:,:)                                       ! initial ssh
-         !DO jk = 1, jpk
-         !   e3t_ini   (:,:,jk) = fse3t_n(:,:,jk)                        ! initial vertical scale factors
-         !   hc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_tem) * fse3t_n(:,:,jk)   ! initial heat content
-         !   sc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_sal) * fse3t_n(:,:,jk)   ! initial salt content
-         !END DO
-         !hcssh_loc_ini(:,:) = tsn(:,:,1,jp_tem) * sshn(:,:)   ! initial heat content in ssh
-         !scssh_loc_ini(:,:) = tsn(:,:,1,jp_sal) * sshn(:,:)   ! initial salt content in ssh
-         !frc_v = 0._wp                                           ! volume       trend due to forcing
-         !frc_t = 0._wp                                           ! heat content   -    -   -    -   
-         !frc_s = 0._wp                                           ! salt content   -    -   -    -         
-         !
-         CALL dia_hsb_rst( nit000, 'READ' )  !* read or initialize all required files
-      !
-   END SUBROUTINE dia_hsb_init
-
-   SUBROUTINE dia_hsb_rst( kt, cdrw )
-     !!---------------------------------------------------------------------
-     !!                   ***  ROUTINE limdia_rst  ***
-     !!                     
-     !! ** Purpose :   Read or write DIA file in restart file
-     !!
-     !! ** Method  :   use of IOM library
-     !!----------------------------------------------------------------------
-     INTEGER         , INTENT(in) ::   kt     ! ocean time-step
-     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
-     !
-     INTEGER ::   jk   ! 
-     INTEGER ::   id1   ! local integers
-     !!----------------------------------------------------------------------
-     !
-     IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
-        IF( ln_rstart ) THEN                   !* Read the restart file
-           !id1 = iom_varid( numror, 'frc_vol'  , ldstop = .FALSE. )
-           !
-           CALL iom_get( numror, 'frc_v', frc_v )
-           CALL iom_get( numror, 'frc_t', frc_t )
-           CALL iom_get( numror, 'frc_s', frc_s )
-
-           CALL iom_get( numror, jpdom_autoglo, 'ssh_ini', ssh_ini )
-           CALL iom_get( numror, jpdom_autoglo, 'e3t_ini', e3t_ini )
-           CALL iom_get( numror, jpdom_autoglo, 'hc_loc_ini', hc_loc_ini )
-           CALL iom_get( numror, jpdom_autoglo, 'sc_loc_ini', sc_loc_ini )
-           CALL iom_get( numror, jpdom_autoglo, 'hcssh_loc_ini', hcssh_loc_ini )
-           CALL iom_get( numror, jpdom_autoglo, 'scssh_loc_ini', scssh_loc_ini )
-       ELSE
-          ssh_ini(:,:) = sshn(:,:)                                       ! initial ssh
-          DO jk = 1, jpk
-             e3t_ini   (:,:,jk) = fse3t_n(:,:,jk)                        ! initial vertical scale factors
-             hc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_tem) * fse3t_n(:,:,jk)   ! initial heat content
-             sc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_sal) * fse3t_n(:,:,jk)   ! initial salt content
-          END DO
-          hcssh_loc_ini(:,:) = tsn(:,:,1,jp_tem) * sshn(:,:)   ! initial heat content in ssh
-          scssh_loc_ini(:,:) = tsn(:,:,1,jp_sal) * sshn(:,:)   ! initial salt content in ssh
-          frc_v = 0._wp                                           
-          frc_t = 0._wp                                           
-          frc_s = 0._wp                                                  
-       ENDIF	
-
-     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
-        !                                   ! -------------------
-        IF(lwp) WRITE(numout,*) '---- dia-rst ----'
-        CALL iom_rstput( kt, nitrst, numrow, 'frc_v'   , frc_v     )
-        CALL iom_rstput( kt, nitrst, numrow, 'frc_t'   , frc_t     )
-        CALL iom_rstput( kt, nitrst, numrow, 'frc_s'   , frc_s     )
-        
-        CALL iom_rstput( kt, nitrst, numrow, 'ssh_ini', ssh_ini )
-        CALL iom_rstput( kt, nitrst, numrow, 'e3t_ini', e3t_ini )
-        CALL iom_rstput( kt, nitrst, numrow, 'hc_loc_ini', hc_loc_ini )
-        CALL iom_rstput( kt, nitrst, numrow, 'sc_loc_ini', sc_loc_ini )
-        CALL iom_rstput( kt, nitrst, numrow, 'hcssh_loc_ini', hcssh_loc_ini )
-        CALL iom_rstput( kt, nitrst, numrow, 'scssh_loc_ini', scssh_loc_ini )
-        !
-     ENDIF
-     !
-   END SUBROUTINE dia_hsb_rst
-
-   !!======================================================================
-END MODULE diahsb
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/diawri.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/diawri.F90	(revision 3937)
+++ 	(revision )
@@ -1,807 +1,0 @@
-MODULE diawri
-   !!======================================================================
-   !!                     ***  MODULE  diawri  ***
-   !! Ocean diagnostics :  write ocean output files
-   !!=====================================================================
-   !! History :  OPA  ! 1991-03  (M.-A. Foujols)  Original code
-   !!            4.0  ! 1991-11  (G. Madec)
-   !!                 ! 1992-06  (M. Imbard)  correction restart file
-   !!                 ! 1992-07  (M. Imbard)  split into diawri and rstwri
-   !!                 ! 1993-03  (M. Imbard)  suppress writibm
-   !!                 ! 1998-01  (C. Levy)  NETCDF format using ioipsl INTERFACE
-   !!                 ! 1999-02  (E. Guilyardi)  name of netCDF files + variables
-   !!            8.2  ! 2000-06  (M. Imbard)  Original code (diabort.F)
-   !!   NEMO     1.0  ! 2002-06  (A.Bozec, E. Durand)  Original code (diainit.F)
-   !!             -   ! 2002-09  (G. Madec)  F90: Free form and module
-   !!             -   ! 2002-12  (G. Madec)  merge of diabort and diainit, F90
-   !!                 ! 2005-11  (V. Garnier) Surface pressure gradient organization
-   !!            3.2  ! 2008-11  (B. Lemaire) creation from old diawri
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dia_wri       : create the standart output files
-   !!   dia_wri_state : create an output NetCDF file for a single instantaeous ocean state and forcing fields
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers 
-   USE dom_oce         ! ocean space and time domain
-   USE zdf_oce         ! ocean vertical physics
-   USE ldftra_oce      ! ocean active tracers: lateral physics
-   USE ldfdyn_oce      ! ocean dynamics: lateral physics
-   USE traldf_iso_grif, ONLY : psix_eiv, psiy_eiv
-   USE sol_oce         ! solver variables
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice fields
-   USE sbcssr          ! restoring term toward SST/SSS climatology
-   USE phycst          ! physical constants
-   USE zdfmxl          ! mixed layer
-   USE dianam          ! build name of file (routine)
-   USE zdfddm          ! vertical  physics: double diffusion
-   USE diahth          ! thermocline diagnostics
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE in_out_manager  ! I/O manager
-   USE diadimg         ! dimg direct access file format output
-   USE diaar5, ONLY :   lk_diaar5
-   USE iom
-   USE ioipsl
-#if defined key_lim2
-   USE limwri_2 
-#elif defined key_lim3
-   USE limwri 
-#endif
-   USE lib_mpp         ! MPP library
-   USE timing          ! preformance summary
-   USE wrk_nemo        ! working array
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dia_wri                 ! routines called by step.F90
-   PUBLIC   dia_wri_state
-   PUBLIC   dia_wri_alloc           ! Called by nemogcm module
-
-   INTEGER ::   nid_T, nz_T, nh_T, ndim_T, ndim_hT   ! grid_T file
-   INTEGER ::   nid_U, nz_U, nh_U, ndim_U, ndim_hU   ! grid_U file
-   INTEGER ::   nid_V, nz_V, nh_V, ndim_V, ndim_hV   ! grid_V file
-   INTEGER ::   nid_W, nz_W, nh_W                    ! grid_W file
-   INTEGER ::   ndex(1)                              ! ???
-   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_hT, ndex_hU, ndex_hV
-   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_T, ndex_U, ndex_V
-
-   !! * Substitutions
-#  include "zdfddm_substitute.h90"
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION dia_wri_alloc()
-      !!----------------------------------------------------------------------
-      INTEGER, DIMENSION(2) :: ierr
-      !!----------------------------------------------------------------------
-      !
-      ierr = 0
-      !
-      ALLOCATE( ndex_hT(jpi*jpj) , ndex_T(jpi*jpj*jpk) ,     &
-         &      ndex_hU(jpi*jpj) , ndex_U(jpi*jpj*jpk) ,     &
-         &      ndex_hV(jpi*jpj) , ndex_V(jpi*jpj*jpk) , STAT=ierr(1) )
-         !
-      dia_wri_alloc = MAXVAL(ierr)
-      IF( lk_mpp )   CALL mpp_sum( dia_wri_alloc )
-      !
-  END FUNCTION dia_wri_alloc
-
-#if defined key_dimgout
-   !!----------------------------------------------------------------------
-   !!   'key_dimgout'                                      DIMG output file
-   !!----------------------------------------------------------------------
-#   include "diawri_dimg.h90"
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                                   NetCDF output file
-   !!----------------------------------------------------------------------
-# if defined key_iomput
-   !!----------------------------------------------------------------------
-   !!   'key_iomput'                                        use IOM library
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE dia_wri( kt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dia_wri  ***
-      !!                   
-      !! ** Purpose :   Standard output of opa: dynamics and tracer fields 
-      !!      NETCDF format is used by default 
-      !!
-      !! ** Method  :  use iom_put
-      !!----------------------------------------------------------------------
-      !!
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-      !!
-      INTEGER                      ::   ji, jj, jk              ! dummy loop indices
-      REAL(wp)                     ::   zztmp, zztmpx, zztmpy   ! 
-      !!
-      REAL(wp), POINTER, DIMENSION(:,:)   :: z2d       ! 2D workspace
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: z3d      ! 3D workspace
-      !!----------------------------------------------------------------------
-      ! 
-      IF( nn_timing == 1 )   CALL timing_start('dia_wri')
-      ! 
-      CALL wrk_alloc( jpi , jpj      , z2d )
-      CALL wrk_alloc( jpi , jpj, jpk , z3d )
-      !
-      ! Output the initial state and forcings
-      IF( ninist == 1 ) THEN                       
-         CALL dia_wri_state( 'output.init', kt )
-         ninist = 0
-      ENDIF
-
-      CALL iom_put( "toce"   , tsn(:,:,:,jp_tem)                     )    ! temperature
-      CALL iom_put( "soce"   , tsn(:,:,:,jp_sal)                     )    ! salinity
-      CALL iom_put( "sst"    , tsn(:,:,1,jp_tem)                     )    ! sea surface temperature
-      CALL iom_put( "sst2"   , tsn(:,:,1,jp_tem) * tsn(:,:,1,jp_tem) )    ! square of sea surface temperature
-      CALL iom_put( "sss"    , tsn(:,:,1,jp_sal)                     )    ! sea surface salinity
-      CALL iom_put( "sss2"   , tsn(:,:,1,jp_sal) * tsn(:,:,1,jp_sal) )    ! square of sea surface salinity
-      CALL iom_put( "uoce"   , un                                    )    ! i-current      
-      CALL iom_put( "voce"   , vn                                    )    ! j-current
-      
-      CALL iom_put( "avt"    , avt                                   )    ! T vert. eddy diff. coef.
-      CALL iom_put( "avm"    , avmu                                  )    ! T vert. eddy visc. coef.
-      IF( lk_zdfddm ) THEN
-         CALL iom_put( "avs" , fsavs(:,:,:)                          )    ! S vert. eddy diff. coef.
-      ENDIF
-
-      DO jj = 2, jpjm1                                    ! sst gradient
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            zztmp      = tsn(ji,jj,1,jp_tem)
-            zztmpx     = ( tsn(ji+1,jj  ,1,jp_tem) - zztmp ) / e1u(ji,jj) + ( zztmp - tsn(ji-1,jj  ,1,jp_tem) ) / e1u(ji-1,jj  )
-            zztmpy     = ( tsn(ji  ,jj+1,1,jp_tem) - zztmp ) / e2v(ji,jj) + ( zztmp - tsn(ji  ,jj-1,1,jp_tem) ) / e2v(ji  ,jj-1)
-            z2d(ji,jj) = 0.25 * ( zztmpx * zztmpx + zztmpy * zztmpy )   &
-               &              * umask(ji,jj,1) * umask(ji-1,jj,1) * vmask(ji,jj,1) * umask(ji,jj-1,1)
-         END DO
-      END DO
-      CALL lbc_lnk( z2d, 'T', 1. )
-      CALL iom_put( "sstgrad2",  z2d               )    ! square of module of sst gradient
-!CDIR NOVERRCHK
-      z2d(:,:) = SQRT( z2d(:,:) )
-      CALL iom_put( "sstgrad" ,  z2d               )    ! module of sst gradient
-
-      IF( lk_diaar5 ) THEN
-         z3d(:,:,jpk) = 0.e0
-         DO jk = 1, jpkm1
-            z3d(:,:,jk) = rau0 * un(:,:,jk) * e2u(:,:) * fse3u(:,:,jk)
-         END DO
-         CALL iom_put( "u_masstr", z3d )                  ! mass transport in i-direction
-         zztmp = 0.5 * rcp
-         z2d(:,:) = 0.e0 
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * zztmp * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
-               END DO
-            END DO
-         END DO
-         CALL lbc_lnk( z2d, 'U', -1. )
-         CALL iom_put( "u_heattr", z2d )                  ! heat transport in i-direction
-         DO jk = 1, jpkm1
-            z3d(:,:,jk) = rau0 * vn(:,:,jk) * e1v(:,:) * fse3v(:,:,jk)
-         END DO
-         CALL iom_put( "v_masstr", z3d )                  ! mass transport in j-direction
-         z2d(:,:) = 0.e0 
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * zztmp * ( tsn(ji,jj,jk,jp_tem) + tsn(ji,jj+1,jk,jp_tem) )
-               END DO
-            END DO
-         END DO
-         CALL lbc_lnk( z2d, 'V', -1. )
-         CALL iom_put( "v_heattr", z2d )                  !  heat transport in i-direction
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi , jpj      , z2d )
-      CALL wrk_dealloc( jpi , jpj, jpk , z3d )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('dia_wri')
-      !
-   END SUBROUTINE dia_wri
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                                  use IOIPSL  library
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE dia_wri( kt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dia_wri  ***
-      !!                   
-      !! ** Purpose :   Standard output of opa: dynamics and tracer fields 
-      !!      NETCDF format is used by default 
-      !!
-      !! ** Method  :   At the beginning of the first time step (nit000), 
-      !!      define all the NETCDF files and fields
-      !!      At each time step call histdef to compute the mean if ncessary
-      !!      Each nwrite time step, output the instantaneous or mean fields
-      !!----------------------------------------------------------------------
-      !!
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-      !!
-      LOGICAL ::   ll_print = .FALSE.                        ! =T print and flush numout
-      CHARACTER (len=40) ::   clhstnam, clop, clmx           ! local names
-      INTEGER  ::   inum = 11                                ! temporary logical unit
-      INTEGER  ::   ji, jj, jk                               ! dummy loop indices
-      INTEGER  ::   ierr                                     ! error code return from allocation
-      INTEGER  ::   iimi, iima, ipk, it, itmod, ijmi, ijma   ! local integers
-      REAL(wp) ::   zsto, zout, zmax, zjulian, zdt           ! local scalars
-      !!
-      REAL(wp), POINTER, DIMENSION(:,:)   :: zw2d       ! 2D workspace
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zw3d       ! 3D workspace
-      !!----------------------------------------------------------------------
-      ! 
-      IF( nn_timing == 1 )   CALL timing_start('dia_wri')
-      !
-      CALL wrk_alloc( jpi , jpj      , zw2d )
-      IF ( ln_traldf_gdia )  call wrk_alloc( jpi , jpj , jpk  , zw3d )
-      !
-      ! Output the initial state and forcings
-      IF( ninist == 1 ) THEN                       
-         CALL dia_wri_state( 'output.init', kt )
-         ninist = 0
-      ENDIF
-      !
-      ! 0. Initialisation
-      ! -----------------
-
-      ! local variable for debugging
-      ll_print = .FALSE.
-      ll_print = ll_print .AND. lwp
-
-      ! Define frequency of output and means
-      zdt = rdt
-      IF( nacc == 1 ) zdt = rdtmin
-      IF( ln_mskland )   THEN   ;   clop = "only(x)"   ! put 1.e+20 on land (very expensive!!)
-      ELSE                      ;   clop = "x"         ! no use of the mask value (require less cpu time)
-      ENDIF
-#if defined key_diainstant
-      zsto = nwrite * zdt
-      clop = "inst("//TRIM(clop)//")"
-#else
-      zsto=zdt
-      clop = "ave("//TRIM(clop)//")"
-#endif
-      zout = nwrite * zdt
-      zmax = ( nitend - nit000 + 1 ) * zdt
-
-      ! Define indices of the horizontal output zoom and vertical limit storage
-      iimi = 1      ;      iima = jpi
-      ijmi = 1      ;      ijma = jpj
-      ipk = jpk
-
-      ! define time axis
-      it = kt
-      itmod = kt - nit000 + 1
-
-
-      ! 1. Define NETCDF files and fields at beginning of first time step
-      ! -----------------------------------------------------------------
-
-      IF( kt == nit000 ) THEN
-
-         ! Define the NETCDF files (one per grid)
-
-         ! Compute julian date from starting date of the run
-         CALL ymds2ju( nyear, nmonth, nday, rdt, zjulian )
-         zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
-         IF(lwp)WRITE(numout,*)
-         IF(lwp)WRITE(numout,*) 'Date 0 used :', nit000, ' YEAR ', nyear,   &
-            &                    ' MONTH ', nmonth, ' DAY ', nday, 'Julian day : ', zjulian
-         IF(lwp)WRITE(numout,*) ' indexes of zoom = ', iimi, iima, ijmi, ijma,   &
-                                 ' limit storage in depth = ', ipk
-
-         ! WRITE root name in date.file for use by postpro
-         IF(lwp) THEN
-            CALL dia_nam( clhstnam, nwrite,' ' )
-            CALL ctl_opn( inum, 'date.file', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
-            WRITE(inum,*) clhstnam
-            CLOSE(inum)
-         ENDIF
-
-         ! Define the T grid FILE ( nid_T )
-
-         CALL dia_nam( clhstnam, nwrite, 'grid_T' )
-         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
-         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
-            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_T, nid_T, domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nid_T, "deptht", "Vertical T levels",      &  ! Vertical grid: gdept
-            &           "m", ipk, gdept_0, nz_T, "down" )
-         !                                                            ! Index of ocean points
-         CALL wheneq( jpi*jpj*ipk, tmask, 1, 1., ndex_T , ndim_T  )      ! volume
-         CALL wheneq( jpi*jpj    , tmask, 1, 1., ndex_hT, ndim_hT )      ! surface
-
-         ! Define the U grid FILE ( nid_U )
-
-         CALL dia_nam( clhstnam, nwrite, 'grid_U' )
-         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
-         CALL histbeg( clhstnam, jpi, glamu, jpj, gphiu,           &  ! Horizontal grid: glamu and gphiu
-            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_U, nid_U, domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nid_U, "depthu", "Vertical U levels",      &  ! Vertical grid: gdept
-            &           "m", ipk, gdept_0, nz_U, "down" )
-         !                                                            ! Index of ocean points
-         CALL wheneq( jpi*jpj*ipk, umask, 1, 1., ndex_U , ndim_U  )      ! volume
-         CALL wheneq( jpi*jpj    , umask, 1, 1., ndex_hU, ndim_hU )      ! surface
-
-         ! Define the V grid FILE ( nid_V )
-
-         CALL dia_nam( clhstnam, nwrite, 'grid_V' )                   ! filename
-         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
-         CALL histbeg( clhstnam, jpi, glamv, jpj, gphiv,           &  ! Horizontal grid: glamv and gphiv
-            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_V, nid_V, domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nid_V, "depthv", "Vertical V levels",      &  ! Vertical grid : gdept
-            &          "m", ipk, gdept_0, nz_V, "down" )
-         !                                                            ! Index of ocean points
-         CALL wheneq( jpi*jpj*ipk, vmask, 1, 1., ndex_V , ndim_V  )      ! volume
-         CALL wheneq( jpi*jpj    , vmask, 1, 1., ndex_hV, ndim_hV )      ! surface
-
-         ! Define the W grid FILE ( nid_W )
-
-         CALL dia_nam( clhstnam, nwrite, 'grid_W' )                   ! filename
-         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
-         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
-            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_W, nid_W, domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nid_W, "depthw", "Vertical W levels",      &  ! Vertical grid: gdepw
-            &          "m", ipk, gdepw_0, nz_W, "down" )
-
-
-         ! Declare all the output fields as NETCDF variables
-
-         !                                                                                      !!! nid_T : 3D
-         CALL histdef( nid_T, "votemper", "Temperature"                        , "C"      ,   &  ! tn
-            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
-         CALL histdef( nid_T, "vosaline", "Salinity"                           , "PSU"    ,   &  ! sn
-            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
-         !                                                                                      !!! nid_T : 2D
-         CALL histdef( nid_T, "sosstsst", "Sea Surface temperature"            , "C"      ,   &  ! sst
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sosaline", "Sea Surface Salinity"               , "PSU"    ,   &  ! sss
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sossheig", "Sea Surface Height"                 , "m"      ,   &  ! ssh
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-!!$#if defined key_lim3 || defined key_lim2 
-!!$         ! sowaflup = sowaflep + sorunoff + sowafldp + a term associated to
-!!$         !    internal damping to Levitus that can be diagnosed from others
-!!$         ! sowaflcd = sowaflep + sorunoff + sowafldp + iowaflup
-!!$         CALL histdef( nid_T, "iowaflup", "Ice=>ocean net freshwater"          , "kg/m2/s",   &  ! fsalt
-!!$            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-!!$         CALL histdef( nid_T, "sowaflep", "atmos=>ocean net freshwater"        , "kg/m2/s",   &  ! fmass
-!!$            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-!!$#endif
-         CALL histdef( nid_T, "sowaflup", "Net Upward Water Flux"              , "Kg/m2/s",   &  ! (emp-rnf)
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-!!$         CALL histdef( nid_T, "sorunoff", "Runoffs"                            , "Kg/m2/s",   &  ! runoffs
-!!$            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sowaflcd", "concentration/dilution water flux"  , "kg/m2/s",   &  ! (emps-rnf)
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sosalflx", "Surface Salt Flux"                  , "Kg/m2/s",   &  ! (emps-rnf) * sn
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sohefldo", "Net Downward Heat Flux"             , "W/m2"   ,   &  ! qns + qsr
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "soshfldo", "Shortwave Radiation"                , "W/m2"   ,   &  ! qsr
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "somixhgt", "Turbocline Depth"                   , "m"      ,   &  ! hmld
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "somxl010", "Mixed Layer Depth 0.01"             , "m"      ,   &  ! hmlp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "soicecov", "Ice fraction"                       , "[0,1]"  ,   &  ! fr_i
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sowindsp", "wind speed at 10m"                  , "m/s"    ,   &  ! wndm
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#if ! defined key_coupled 
-         CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sosafldp", "Surface salt flux: damping"         , "Kg/m2/s",   &  ! erp * sn
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#endif
-
-
-
-#if ( defined key_coupled && ! defined key_lim3 && ! defined key_lim2 ) 
-         CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sosafldp", "Surface salt flux: Damping"         , "Kg/m2/s",   &  ! erp * sn
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#endif
-         clmx ="l_max(only(x))"    ! max index on a period
-         CALL histdef( nid_T, "sobowlin", "Bowl Index"                         , "W-point",   &  ! bowl INDEX 
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clmx, zsto, zout )
-#if defined key_diahth
-         CALL histdef( nid_T, "sothedep", "Thermocline Depth"                  , "m"      ,   & ! hth
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "so20chgt", "Depth of 20C isotherm"              , "m"      ,   & ! hd20
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "so28chgt", "Depth of 28C isotherm"              , "m"      ,   & ! hd28
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sohtc300", "Heat content 300 m"                 , "W"      ,   & ! htc3
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#endif
-
-#if defined key_coupled 
-# if defined key_lim3
-         Must be adapted to LIM3
-# else
-         CALL histdef( nid_T,"soicetem" , "Ice Surface Temperature"            , "K"      ,   &  ! tn_ice
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T,"soicealb" , "Ice Albedo"                         , "[0,1]"  ,   &  ! alb_ice
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-# endif 
-#endif 
-
-         CALL histend( nid_T, snc4chunks=snc4set )
-
-         !                                                                                      !!! nid_U : 3D
-         CALL histdef( nid_U, "vozocrtx", "Zonal Current"                      , "m/s"    ,   &  ! un
-            &          jpi, jpj, nh_U, ipk, 1, ipk, nz_U, 32, clop, zsto, zout )
-         IF( ln_traldf_gdia ) THEN
-            CALL histdef( nid_U, "vozoeivu", "Zonal EIV Current"                  , "m/s"    ,   &  ! u_eiv
-                 &          jpi, jpj, nh_U, ipk, 1, ipk, nz_U, 32, clop, zsto, zout )
-         ELSE
-#if defined key_diaeiv
-            CALL histdef( nid_U, "vozoeivu", "Zonal EIV Current"                  , "m/s"    ,   &  ! u_eiv
-            &          jpi, jpj, nh_U, ipk, 1, ipk, nz_U, 32, clop, zsto, zout )
-#endif
-         END IF
-         !                                                                                      !!! nid_U : 2D
-         CALL histdef( nid_U, "sozotaux", "Wind Stress along i-axis"           , "N/m2"   ,   &  ! utau
-            &          jpi, jpj, nh_U, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
-
-         CALL histend( nid_U, snc4chunks=snc4set )
-
-         !                                                                                      !!! nid_V : 3D
-         CALL histdef( nid_V, "vomecrty", "Meridional Current"                 , "m/s"    ,   &  ! vn
-            &          jpi, jpj, nh_V, ipk, 1, ipk, nz_V, 32, clop, zsto, zout )
-         IF( ln_traldf_gdia ) THEN
-            CALL histdef( nid_V, "vomeeivv", "Meridional EIV Current"             , "m/s"    ,   &  ! v_eiv
-                 &          jpi, jpj, nh_V, ipk, 1, ipk, nz_V, 32, clop, zsto, zout )
-         ELSE 
-#if defined key_diaeiv
-            CALL histdef( nid_V, "vomeeivv", "Meridional EIV Current"             , "m/s"    ,   &  ! v_eiv
-            &          jpi, jpj, nh_V, ipk, 1, ipk, nz_V, 32, clop, zsto, zout )
-#endif
-         END IF
-         !                                                                                      !!! nid_V : 2D
-         CALL histdef( nid_V, "sometauy", "Wind Stress along j-axis"           , "N/m2"   ,   &  ! vtau
-            &          jpi, jpj, nh_V, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
-
-         CALL histend( nid_V, snc4chunks=snc4set )
-
-         !                                                                                      !!! nid_W : 3D
-         CALL histdef( nid_W, "vovecrtz", "Vertical Velocity"                  , "m/s"    ,   &  ! wn
-            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-         IF( ln_traldf_gdia ) THEN
-            CALL histdef( nid_W, "voveeivw", "Vertical EIV Velocity"              , "m/s"    ,   &  ! w_eiv
-                 &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-         ELSE
-#if defined key_diaeiv
-            CALL histdef( nid_W, "voveeivw", "Vertical EIV Velocity"              , "m/s"    ,   &  ! w_eiv
-                 &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-#endif
-         END IF
-         CALL histdef( nid_W, "votkeavt", "Vertical Eddy Diffusivity"          , "m2/s"   ,   &  ! avt
-            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-         CALL histdef( nid_W, "votkeavm", "Vertical Eddy Viscosity"             , "m2/s"  ,   &  ! avmu
-            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-
-         IF( lk_zdfddm ) THEN
-            CALL histdef( nid_W,"voddmavs","Salt Vertical Eddy Diffusivity"    , "m2/s"   ,   &  ! avs
-               &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-         ENDIF
-         !                                                                                      !!! nid_W : 2D
-#if defined key_traldf_c2d
-         CALL histdef( nid_W, "soleahtw", "lateral eddy diffusivity"           , "m2/s"   ,   &  ! ahtw
-            &          jpi, jpj, nh_W, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
-# if defined key_traldf_eiv 
-            CALL histdef( nid_W, "soleaeiw", "eddy induced vel. coeff. at w-point", "m2/s",   &  ! aeiw
-               &       jpi, jpj, nh_W, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
-# endif
-#endif
-
-         CALL histend( nid_W, snc4chunks=snc4set )
-
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization'
-         IF(ll_print) CALL FLUSH(numout )
-
-      ENDIF
-
-      ! 2. Start writing data
-      ! ---------------------
-
-      ! ndex(1) est utilise ssi l'avant dernier argument est diffferent de 
-      ! la taille du tableau en sortie. Dans ce cas , l'avant dernier argument
-      ! donne le nombre d'elements, et ndex la liste des indices a sortir
-
-      IF( lwp .AND. MOD( itmod, nwrite ) == 0 ) THEN 
-         WRITE(numout,*) 'dia_wri : write model outputs in NetCDF files at ', kt, 'time-step'
-         WRITE(numout,*) '~~~~~~ '
-      ENDIF
-
-      ! Write fields on T grid
-      CALL histwrite( nid_T, "votemper", it, tsn(:,:,:,jp_tem), ndim_T , ndex_T  )   ! temperature
-      CALL histwrite( nid_T, "vosaline", it, tsn(:,:,:,jp_sal), ndim_T , ndex_T  )   ! salinity
-      CALL histwrite( nid_T, "sosstsst", it, tsn(:,:,1,jp_tem), ndim_hT, ndex_hT )   ! sea surface temperature
-      CALL histwrite( nid_T, "sosaline", it, tsn(:,:,1,jp_sal), ndim_hT, ndex_hT )   ! sea surface salinity
-      CALL histwrite( nid_T, "sossheig", it, sshn          , ndim_hT, ndex_hT )   ! sea surface height
-!!$#if  defined key_lim3 || defined key_lim2 
-!!$      CALL histwrite( nid_T, "iowaflup", it, fsalt(:,:)    , ndim_hT, ndex_hT )   ! ice=>ocean water flux
-!!$      CALL histwrite( nid_T, "sowaflep", it, fmass(:,:)    , ndim_hT, ndex_hT )   ! atmos=>ocean water flux
-!!$#endif
-      CALL histwrite( nid_T, "sowaflup", it, ( emp-rnf )   , ndim_hT, ndex_hT )   ! upward water flux
-!!$      CALL histwrite( nid_T, "sorunoff", it, runoff        , ndim_hT, ndex_hT )   ! runoff
-      CALL histwrite( nid_T, "sowaflcd", it, ( emps-rnf )  , ndim_hT, ndex_hT )   ! c/d water flux
-      zw2d(:,:) = ( emps(:,:) - rnf(:,:) ) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
-      CALL histwrite( nid_T, "sosalflx", it, zw2d          , ndim_hT, ndex_hT )   ! c/d salt flux
-      CALL histwrite( nid_T, "sohefldo", it, qns + qsr     , ndim_hT, ndex_hT )   ! total heat flux
-      CALL histwrite( nid_T, "soshfldo", it, qsr           , ndim_hT, ndex_hT )   ! solar heat flux
-      CALL histwrite( nid_T, "somixhgt", it, hmld          , ndim_hT, ndex_hT )   ! turbocline depth
-      CALL histwrite( nid_T, "somxl010", it, hmlp          , ndim_hT, ndex_hT )   ! mixed layer depth
-      CALL histwrite( nid_T, "soicecov", it, fr_i          , ndim_hT, ndex_hT )   ! ice fraction   
-      CALL histwrite( nid_T, "sowindsp", it, wndm          , ndim_hT, ndex_hT )   ! wind speed   
-#if ! defined key_coupled
-      CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
-      CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
-      IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
-      CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
-#endif
-#if ( defined key_coupled && ! defined key_lim3 && ! defined key_lim2 ) 
-      CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
-      CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
-         IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
-      CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
-#endif
-      zw2d(:,:) = FLOAT( nmln(:,:) ) * tmask(:,:,1)
-      CALL histwrite( nid_T, "sobowlin", it, zw2d          , ndim_hT, ndex_hT )   ! ???
-
-#if defined key_diahth
-      CALL histwrite( nid_T, "sothedep", it, hth           , ndim_hT, ndex_hT )   ! depth of the thermocline
-      CALL histwrite( nid_T, "so20chgt", it, hd20          , ndim_hT, ndex_hT )   ! depth of the 20 isotherm
-      CALL histwrite( nid_T, "so28chgt", it, hd28          , ndim_hT, ndex_hT )   ! depth of the 28 isotherm
-      CALL histwrite( nid_T, "sohtc300", it, htc3          , ndim_hT, ndex_hT )   ! first 300m heaat content
-#endif
-
-#if defined key_coupled 
-# if defined key_lim3
-      Must be adapted for LIM3
-      CALL histwrite( nid_T, "soicetem", it, tn_ice        , ndim_hT, ndex_hT )   ! surf. ice temperature
-      CALL histwrite( nid_T, "soicealb", it, alb_ice       , ndim_hT, ndex_hT )   ! ice albedo
-# else
-      CALL histwrite( nid_T, "soicetem", it, tn_ice(:,:,1) , ndim_hT, ndex_hT )   ! surf. ice temperature
-      CALL histwrite( nid_T, "soicealb", it, alb_ice(:,:,1), ndim_hT, ndex_hT )   ! ice albedo
-# endif
-#endif
-         ! Write fields on U grid
-      CALL histwrite( nid_U, "vozocrtx", it, un            , ndim_U , ndex_U )    ! i-current
-      IF( ln_traldf_gdia ) THEN
-         IF (.not. ALLOCATED(psix_eiv))THEN
-            ALLOCATE( psix_eiv(jpi,jpj,jpk) , psiy_eiv(jpi,jpj,jpk) , STAT=ierr )
-            IF( lk_mpp   )   CALL mpp_sum ( ierr )
-            IF( ierr > 0 )   CALL ctl_stop('STOP', 'diawri: unable to allocate psi{x,y}_eiv')
-            psix_eiv(:,:,:) = 0.0_wp
-            psiy_eiv(:,:,:) = 0.0_wp
-         ENDIF
-         DO jk=1,jpkm1
-            zw3d(:,:,jk) = (psix_eiv(:,:,jk+1) - psix_eiv(:,:,jk))/fse3u(:,:,jk)  ! u_eiv = -dpsix/dz
-         END DO
-         zw3d(:,:,jpk) = 0._wp
-         CALL histwrite( nid_U, "vozoeivu", it, zw3d, ndim_U , ndex_U )           ! i-eiv current
-      ELSE
-#if defined key_diaeiv
-         CALL histwrite( nid_U, "vozoeivu", it, u_eiv, ndim_U , ndex_U )          ! i-eiv current
-#endif
-      ENDIF
-      CALL histwrite( nid_U, "sozotaux", it, utau          , ndim_hU, ndex_hU )   ! i-wind stress
-
-         ! Write fields on V grid
-      CALL histwrite( nid_V, "vomecrty", it, vn            , ndim_V , ndex_V  )   ! j-current
-      IF( ln_traldf_gdia ) THEN
-         DO jk=1,jpk-1
-            zw3d(:,:,jk) = (psiy_eiv(:,:,jk+1) - psiy_eiv(:,:,jk))/fse3v(:,:,jk)  ! v_eiv = -dpsiy/dz
-         END DO
-         zw3d(:,:,jpk) = 0._wp
-         CALL histwrite( nid_V, "vomeeivv", it, zw3d, ndim_V , ndex_V )           ! j-eiv current
-      ELSE
-#if defined key_diaeiv
-         CALL histwrite( nid_V, "vomeeivv", it, v_eiv, ndim_V , ndex_V )          ! j-eiv current
-#endif
-      ENDIF
-      CALL histwrite( nid_V, "sometauy", it, vtau          , ndim_hV, ndex_hV )   ! j-wind stress
-
-         ! Write fields on W grid
-      CALL histwrite( nid_W, "vovecrtz", it, wn             , ndim_T, ndex_T )    ! vert. current
-      IF( ln_traldf_gdia ) THEN
-         DO jk=1,jpk-1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1  ! vector opt.
-                  zw3d(ji,jj,jk) = (psiy_eiv(ji,jj,jk) - psiy_eiv(ji,jj-1,jk))/e2v(ji,jj) + &
-                       &    (psix_eiv(ji,jj,jk) - psix_eiv(ji-1,jj,jk))/e1u(ji,jj) ! w_eiv = dpsiy/dy + dpsiy/dx
-               END DO
-            END DO
-         END DO
-         zw3d(:,:,jpk) = 0._wp
-         CALL histwrite( nid_W, "voveeivw", it, zw3d          , ndim_T, ndex_T )    ! vert. eiv current
-      ELSE
-#   if defined key_diaeiv
-         CALL histwrite( nid_W, "voveeivw", it, w_eiv          , ndim_T, ndex_T )    ! vert. eiv current
-#   endif
-      ENDIF
-      CALL histwrite( nid_W, "votkeavt", it, avt            , ndim_T, ndex_T )    ! T vert. eddy diff. coef.
-      CALL histwrite( nid_W, "votkeavm", it, avmu           , ndim_T, ndex_T )    ! T vert. eddy visc. coef.
-      IF( lk_zdfddm ) THEN
-         CALL histwrite( nid_W, "voddmavs", it, fsavs(:,:,:), ndim_T, ndex_T )    ! S vert. eddy diff. coef.
-      ENDIF
-#if defined key_traldf_c2d
-      CALL histwrite( nid_W, "soleahtw", it, ahtw          , ndim_hT, ndex_hT )   ! lateral eddy diff. coef.
-# if defined key_traldf_eiv
-         CALL histwrite( nid_W, "soleaeiw", it, aeiw       , ndim_hT, ndex_hT )   ! EIV coefficient at w-point
-# endif
-#endif
-
-      ! 3. Close all files
-      ! ---------------------------------------
-      IF( kt == nitend ) THEN
-         CALL histclo( nid_T )
-         CALL histclo( nid_U )
-         CALL histclo( nid_V )
-         CALL histclo( nid_W )
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi , jpj      , zw2d )
-      IF ( ln_traldf_gdia )  call wrk_dealloc( jpi , jpj , jpk  , zw3d )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('dia_wri')
-      !
-   END SUBROUTINE dia_wri
-# endif
-
-#endif
-
-   SUBROUTINE dia_wri_state( cdfile_name, kt )
-      !!---------------------------------------------------------------------
-      !!                 ***  ROUTINE dia_wri_state  ***
-      !!        
-      !! ** Purpose :   create a NetCDF file named cdfile_name which contains 
-      !!      the instantaneous ocean state and forcing fields.
-      !!        Used to find errors in the initial state or save the last
-      !!      ocean state in case of abnormal end of a simulation
-      !!
-      !! ** Method  :   NetCDF files using ioipsl
-      !!      File 'output.init.nc'  is created if ninist = 1 (namelist)
-      !!      File 'output.abort.nc' is created in case of abnormal job end
-      !!----------------------------------------------------------------------
-      CHARACTER (len=* ), INTENT( in ) ::   cdfile_name      ! name of the file created
-      INTEGER           , INTENT( in ) ::   kt               ! ocean time-step index
-      !! 
-      CHARACTER (len=32) :: clname
-      CHARACTER (len=40) :: clop
-      INTEGER  ::   id_i , nz_i, nh_i       
-      INTEGER, DIMENSION(1) ::   idex             ! local workspace
-      REAL(wp) ::   zsto, zout, zmax, zjulian, zdt
-      !!----------------------------------------------------------------------
-      ! 
-      IF( nn_timing == 1 )   CALL timing_start('dia_wri_state')
-
-      ! 0. Initialisation
-      ! -----------------
-
-      ! Define name, frequency of output and means
-      clname = cdfile_name
-      IF( .NOT. Agrif_Root() ) clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
-      zdt  = rdt
-      zsto = rdt
-      clop = "inst(x)"           ! no use of the mask value (require less cpu time)
-      zout = rdt
-      zmax = ( nitend - nit000 + 1 ) * zdt
-
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'dia_wri_state : single instantaneous ocean state'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~   and forcing fields file created '
-      IF(lwp) WRITE(numout,*) '                and named :', clname, '.nc'
-
-
-      ! 1. Define NETCDF files and fields at beginning of first time step
-      ! -----------------------------------------------------------------
-
-      ! Compute julian date from starting date of the run
-      CALL ymds2ju( nyear, nmonth, nday, rdt, zjulian )         ! time axis 
-      zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
-      CALL histbeg( clname, jpi, glamt, jpj, gphit,   &
-          1, jpi, 1, jpj, nit000-1, zjulian, zdt, nh_i, id_i, domain_id=nidom, snc4chunks=snc4set ) ! Horizontal grid : glamt and gphit
-      CALL histvert( id_i, "deptht", "Vertical T levels",   &    ! Vertical grid : gdept
-          "m", jpk, gdept_0, nz_i, "down")
-
-      ! Declare all the output fields as NetCDF variables
-
-      CALL histdef( id_i, "vosaline", "Salinity"              , "PSU"    ,   &   ! salinity
-         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
-      CALL histdef( id_i, "votemper", "Temperature"           , "C"      ,   &   ! temperature
-         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
-      CALL histdef( id_i, "sossheig", "Sea Surface Height"    , "m"      ,   &  ! ssh
-         &          jpi, jpj, nh_i, 1  , 1, 1  , nz_i, 32, clop, zsto, zout )
-      CALL histdef( id_i, "vozocrtx", "Zonal Current"         , "m/s"    ,   &   ! zonal current
-         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
-      CALL histdef( id_i, "vomecrty", "Meridional Current"    , "m/s"    ,   &   ! meridonal current
-         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout ) 
-      CALL histdef( id_i, "vovecrtz", "Vertical Velocity"     , "m/s"    ,   &   ! vertical current
-         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout ) 
-      CALL histdef( id_i, "sowaflup", "Net Upward Water Flux" , "Kg/m2/S",   &   ! net freshwater 
-         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( id_i, "sosaltfx", "Net Upward Salt Flux"  , "Kg/m2/S",   &   ! net salt flux 
-         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( id_i, "sohefldo", "Net Downward Heat Flux", "W/m2"   ,   &   ! net heat flux
-         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( id_i, "soshfldo", "Shortwave Radiation"   , "W/m2"   ,   &   ! solar flux
-         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( id_i, "soicecov", "Ice fraction"          , "[0,1]"  ,   &   ! fr_i
-         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( id_i, "sozotaux", "Zonal Wind Stress"     , "N/m2"   ,   &   ! i-wind stress
-         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( id_i, "sometauy", "Meridional Wind Stress", "N/m2"   ,   &   ! j-wind stress
-         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-
-#if defined key_lim2
-      CALL lim_wri_state_2( kt, id_i, nh_i )
-#elif defined key_lim3
-      CALL lim_wri_state( kt, id_i, nh_i )
-#else
-      CALL histend( id_i, snc4chunks=snc4set )
-#endif
-
-      ! 2. Start writing data
-      ! ---------------------
-      ! idex(1) est utilise ssi l'avant dernier argument est diffferent de 
-      ! la taille du tableau en sortie. Dans ce cas , l'avant dernier argument
-      ! donne le nombre d'elements, et idex la liste des indices a sortir
-      idex(1) = 1   ! init to avoid compil warning
-
-      ! Write all fields on T grid
-      CALL histwrite( id_i, "votemper", kt, tsn(:,:,:,jp_tem), jpi*jpj*jpk, idex )    ! now temperature
-      CALL histwrite( id_i, "vosaline", kt, tsn(:,:,:,jp_sal), jpi*jpj*jpk, idex )    ! now salinity
-      CALL histwrite( id_i, "sossheig", kt, sshn             , jpi*jpj    , idex )    ! sea surface height
-      CALL histwrite( id_i, "vozocrtx", kt, un               , jpi*jpj*jpk, idex )    ! now i-velocity
-      CALL histwrite( id_i, "vomecrty", kt, vn               , jpi*jpj*jpk, idex )    ! now j-velocity
-      CALL histwrite( id_i, "vovecrtz", kt, wn               , jpi*jpj*jpk, idex )    ! now k-velocity
-      CALL histwrite( id_i, "sowaflup", kt, (emp-rnf )       , jpi*jpj    , idex )    ! freshwater budget
-      CALL histwrite( id_i, "sosaltfx", kt, emps             , jpi*jpj    , idex )    ! freshwater budget
-      CALL histwrite( id_i, "sohefldo", kt, qsr + qns        , jpi*jpj    , idex )    ! total heat flux
-      CALL histwrite( id_i, "soshfldo", kt, qsr              , jpi*jpj    , idex )    ! solar heat flux
-      CALL histwrite( id_i, "soicecov", kt, fr_i             , jpi*jpj    , idex )    ! ice fraction
-      CALL histwrite( id_i, "sozotaux", kt, utau             , jpi*jpj    , idex )    ! i-wind stress
-      CALL histwrite( id_i, "sometauy", kt, vtau             , jpi*jpj    , idex )    ! j-wind stress
-
-      ! 3. Close the file
-      ! -----------------
-      CALL histclo( id_i )
-#if ! defined key_iomput && ! defined key_dimgout
-      IF( ninist /= 1  ) THEN
-         CALL histclo( nid_T )
-         CALL histclo( nid_U )
-         CALL histclo( nid_V )
-         CALL histclo( nid_W )
-      ENDIF
-#endif
-       
-      IF( nn_timing == 1 )   CALL timing_stop('dia_wri_state')
-      ! 
-
-   END SUBROUTINE dia_wri_state
-   !!======================================================================
-END MODULE diawri
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/ice.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/ice.F90	(revision 3937)
+++ 	(revision )
@@ -1,542 +1,0 @@
-MODULE ice
-   !!======================================================================
-   !!                        ***  MODULE ice  ***
-   !! LIM-3 Sea Ice physics:  diagnostics variables of ice defined in memory
-   !!=====================================================================
-   !! History :  3.0  ! 2008-03  (M. Vancoppenolle) original code LIM-3
-   !!            4.0  ! 2011-02  (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                   LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   USE par_ice          ! LIM sea-ice parameters
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp         ! MPP library
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC    ice_alloc  !  Called in iceini.F90
-
-   !!======================================================================
-   !! 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 (NOC-L, 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 (LOCEAN, France)
-   !!    * Xavier Fettweis (UCL-ASTR), Ralph Timmermann (AWI, Germany)
-   !!    * Bill Lipscomb (LANL), Cecilia Bitz (UWa) 
-   !!      and Elisabeth Hunke (LANL), USA.
-   !! 
-   !! 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., Ocean Modelling 2009.
-   !!
-   !!    Or the reference manual, that should be available by 2011
-   !!======================================================================
-   !!                                                                     |
-   !!              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 ::   nstart    !: iteration number of the begining of the run 
-   INTEGER , PUBLIC ::   nlast     !: iteration number of the end of the run 
-   INTEGER , PUBLIC ::   nitrun    !: number of iteration
-   INTEGER , PUBLIC ::   numit     !: iteration number
-   REAL(wp), PUBLIC ::   rdt_ice   !: ice time step
-
-   !                                          !!** ice-dynamic namelist (namicedyn) **
-   INTEGER , PUBLIC ::   nbiter = 1            !: number of sub-time steps for relaxation
-   INTEGER , PUBLIC ::   nbitdr = 250          !: maximum number of iterations for relaxation
-   INTEGER , PUBLIC ::   nevp   = 400          !: number of iterations for subcycling
-   INTEGER , PUBLIC ::   nlay_i = 5            !: number of layers in the ice
-
-   !                                          !!** ice-dynamic namelist (namicedyn) **
-   REAL(wp), PUBLIC ::   epsd   = 1.0e-20_wp   !: tolerance parameter for dynamic
-   REAL(wp), PUBLIC ::   alpha  = 0.5_wp       !: coefficient for semi-implicit coriolis
-   REAL(wp), PUBLIC ::   dm     = 0.6e+03_wp   !: diffusion constant for dynamics
-   REAL(wp), PUBLIC ::   om     = 0.5_wp       !: relaxation constant
-   REAL(wp), PUBLIC ::   resl   = 5.0e-05_wp   !: maximum value for the residual of relaxation
-   REAL(wp), PUBLIC ::   cw     = 5.0e-03_wp   !: drag coefficient for oceanic stress
-   REAL(wp), PUBLIC ::   angvg  = 0._wp        !: turning angle for oceanic stress
-   REAL(wp), PUBLIC ::   pstar  = 1.0e+04_wp   !: determines ice strength (N/M), Hibler JPO79
-   REAL(wp), PUBLIC ::   c_rhg  = 20._wp       !: determines changes in ice strength
-   REAL(wp), PUBLIC ::   etamn  = 0.0e+07_wp   !: minimun value for viscosity : has to be 0
-   REAL(wp), PUBLIC ::   creepl = 2.0e-08_wp   !: creep limit : has to be under 1.0e-9
-   REAL(wp), PUBLIC ::   ecc    = 2._wp        !: eccentricity of the elliptical yield curve
-   REAL(wp), PUBLIC ::   ahi0   = 350._wp      !: sea-ice hor. eddy diffusivity coeff. (m2/s)
-   REAL(wp), PUBLIC ::   telast = 2880._wp     !: timescale for elastic waves (s) !SB
-   REAL(wp), PUBLIC ::   alphaevp = 1._wp      !: coeficient of the internal stresses !SB
-   REAL(wp), PUBLIC ::   unit_fac = 1.e+09_wp  !: conversion factor for ice / snow enthalpy
-   REAL(wp), PUBLIC ::   hminrhg = 0.05_wp     !: clem : ice thickness (in m) below which ice velocity is set to ocean velocity
-
-   !                                              !!** ice-salinity namelist (namicesal) **
-   REAL(wp), PUBLIC ::   s_i_max  = 20.0_wp        !: maximum ice salinity [PSU]
-   REAL(wp), PUBLIC ::   s_i_min  =  0.1_wp        !: minimum ice salinity [PSU]
-   REAL(wp), PUBLIC ::   s_i_0    =  3.5_wp        !: 1st sal. value for the computation of sal .prof. [PSU]
-   REAL(wp), PUBLIC ::   s_i_1    =  4.5_wp        !: 2nd sal. value for the computation of sal .prof. [PSU]
-   REAL(wp), PUBLIC ::   sal_G    =  5.0_wp        !: restoring salinity for gravity drainage [PSU]
-   REAL(wp), PUBLIC ::   sal_F    =  2.5_wp        !: restoring salinity for flushing [PSU]
-   REAL(wp), PUBLIC ::   time_G   =  1.728e+06_wp  !: restoring time constant for gravity drainage (= 20 days) [s]
-   REAL(wp), PUBLIC ::   time_F   =  8.640e+05_wp  !: restoring time constant for gravity drainage (= 10 days) [s]
-   REAL(wp), PUBLIC ::   bulk_sal =  4.0_wp        !: bulk salinity (ppt) in case of constant salinity
-
-   !                                              !!** ice-salinity namelist (namicesal) **
-   INTEGER , PUBLIC ::   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
-   INTEGER , PUBLIC ::   sal_prof    = 1           !: salinity profile or not 
-   INTEGER , PUBLIC ::   thcon_i_swi = 1           !: thermal conductivity: =1 Untersteiner (1964) ; =2 Pringle et al (2007)
-
-   !                                              !!** ice-mechanical redistribution namelist (namiceitdme)
-   REAL(wp), PUBLIC ::   Cs        = 0.25_wp       !: fraction of shearing energy contributing to ridging            
-   REAL(wp), PUBLIC ::   Cf        = 17.0_wp       !: ratio of ridging work to PE loss
-   REAL(wp), PUBLIC ::   fsnowrdg  = 0.5_wp        !: fractional snow loss to the ocean during ridging
-   REAL(wp), PUBLIC ::   fsnowrft  = 0.5_wp        !: fractional snow loss to the ocean during ridging
-   REAL(wp), PUBLIC ::   Gstar     = 0.15_wp       !: fractional area of young ice contributing to ridging
-   REAL(wp), PUBLIC ::   astar     = 0.05_wp       !: equivalent of G* for an exponential participation function
-   REAL(wp), PUBLIC ::   Hstar     = 100.0_wp      !: thickness that determines the maximal thickness of ridged ice
-   REAL(wp), PUBLIC ::   hparmeter = 0.75_wp       !: threshold thickness (m) for rafting / ridging 
-   REAL(wp), PUBLIC ::   Craft     = 5.0_wp        !: coefficient for smoothness of the hyperbolic tangent in rafting
-   REAL(wp), PUBLIC ::   ridge_por = 0.0_wp        !: initial porosity of ridges (0.3 regular value)
-   REAL(wp), PUBLIC ::   sal_max_ridge = 15.0_wp   !: maximum ridged ice salinity (ppt)
-   REAL(wp), PUBLIC ::   betas    = 1.0_wp         !: coef. for partitioning of snowfall between leads and sea ice
-   REAL(wp), PUBLIC ::   kappa_i  = 1.0_wp         !: coef. for the extinction of radiation Grenfell et al. (2006) [1/m]
-   REAL(wp), PUBLIC ::   nconv_i_thd = 50_wp       !: maximal number of iterations for heat diffusion
-   REAL(wp), PUBLIC ::   maxer_i_thd = 1.0e-4_wp   !: maximal tolerated error (C) for heat diffusion
-
-   !                                              !!** ice-mechanical redistribution namelist (namiceitdme)
-   INTEGER , PUBLIC ::   ridge_scheme_swi = 0      !: scheme used for ice ridging
-   INTEGER , PUBLIC ::   raftswi          = 1      !: rafting of ice or not                        
-   INTEGER , PUBLIC ::   partfun_swi      = 1      !: participation function: =0 Thorndike et al. (1975), =1 Lipscomb et al. (2007)
-   INTEGER , PUBLIC ::   transfun_swi     = 0      !: transfer function: =0 Hibler 1980, =1 Lipscomb et al. 2007
-   INTEGER , PUBLIC ::   brinstren_swi    = 0      !: use brine volume to diminish ice strength
-
-   REAL(wp), PUBLIC ::   usecc2           !:  = 1.0 / ( ecc * ecc )
-   REAL(wp), PUBLIC ::   rhoco            !: = rau0 * cw
-   REAL(wp), PUBLIC ::   sangvg, cangvg   !: sin and cos of the turning angle for ocean stress
-   REAL(wp), PUBLIC ::   pstarh           !: pstar / 2.0
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   u_oce, v_oce   !: surface ocean velocity used in ice dynamics
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ahiu , ahiv    !: hor. diffusivity coeff. at U- and V-points [m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   pahu , pahv    !: ice hor. eddy diffusivity coef. at U- and V-points
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ust2s, hicol   !: friction velocity, ice collection thickness accreted in leads
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   strp1, strp2   !: strength at previous time steps
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   strength       !: ice strength
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   stress1_i, stress2_i, stress12_i   !: 1st, 2nd & diagonal stress tensor element
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   delta_i        !: ice rheology elta factor (Flato & Hibler 95) [s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   divu_i         !: Divergence of the velocity field [s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   shear_i        !: Shear of the velocity field [s-1]
-   !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   firic       !: IR flux over the ice (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fcsic       !: Sensible heat flux over the ice (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fleic       !: Latent heat flux over the ice (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qlatic      !: latent flux
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdvosif     !: Variation of volume at surface (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdvobif     !: Variation of ice volume at the bottom ice (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fdvolif     !: Total variation of ice volume (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdvonif     !: Lateral Variation of ice volume (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sist        !: Average Sea-Ice Surface Temperature [Kelvin]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   icethi      !: total ice thickness (for all categories) (diag only)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_bo        !: Sea-Ice bottom temperature [Kelvin]     
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hicifp      !: Ice production/melting==>!obsolete... can be removed
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   frld        !: Leads fraction = 1 - ice fraction
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   pfrld       !: Leads fraction at previous time  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   phicif      !: Old ice thickness
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fbif        !: Heat flux at the ice base
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdmsnif     !: Variation of snow mass
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdmicif     !: Variation of ice mass
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qldif       !: heat balance of the lead (or of the open ocean)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qcmif       !: Energy needed to bring the ocean to freezing 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fdtcn       !: net downward heat flux from the ice to the ocean
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qdtcn       !: energy from the ice to the ocean
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fstric      !: transmitted solar radiation under ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fscmbq      !: associated with lead chipotage with solar flux
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ffltbif     !: related to max heat contained in brine pockets (?)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fsbbq       !: Also linked with the solar flux below the ice (?)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qfvbq       !: store energy in case of total lateral ablation (?)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   dmgwi       !: Variation of the mass of snow ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fsalt_res   !: Residual salt flux due to correction of ice thickness
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fsbri       !: Salt flux due to brine rejection
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fsalt_rpo   !: Salt flux associated with porous ridged ice formation
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fheat_rpo   !: Heat flux associated with porous ridged ice formation
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fhbri       !: heat flux due to brine rejection
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fmmec       !: Mass flux due to snow loss during compression
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fseqv       !: Equivalent salt flux due to ice growth/melt
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fhmec       !: Heat flux due to snow loss during compression
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fheat_res   !: Residual heat flux due to correction of ice thickness
-
-   ! temporary arrays for dummy version of the code
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   dh_i_surf2D, dh_i_bott2D, fstbif, fsup2D, focea2D, q_s
-
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   patho_case ! number of the pathological case (if any, of course)
-
-   !!--------------------------------------------------------------------------
-   !! * Ice global state variables
-   !!--------------------------------------------------------------------------
-   !! Variables defined for each ice category
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ht_i    !: Ice thickness (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   a_i     !: Ice fractional areas (concentration)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   v_i     !: Ice volume per unit area (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   v_s     !: Snow volume per unit area(m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ht_s    !: Snow thickness (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   t_su    !: Sea-Ice Surface Temperature (K)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   sm_i    !: Sea-Ice Bulk salinity (ppt)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   smv_i   !: Sea-Ice Bulk salinity times volume per area (ppt.m)
-   !                                                                  !  this is an extensive variable that has to be transported
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   o_i     !: Sea-Ice Age (days)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ov_i    !: Sea-Ice Age times volume per area (days.m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   oa_i    !: Sea-Ice Age times ice area (days)
-
-   !! Variables summed over all categories, or associated to all the ice in a single grid cell
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   u_ice, v_ice   !: components of the ice velocity (m/s)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tio_u, tio_v   !: components of the ice-ocean stress (N/m2)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   vt_i , vt_s    !: ice and snow total volume per unit area (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   at_i           !: ice total fractional area (ice concentration)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ato_i          !: =1-at_i ; total open water fractional area
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   et_i , et_s    !: ice and snow total heat content
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ot_i           !: mean age over all categories
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tm_i           !: mean ice temperature over all categories
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bv_i           !: brine volume averaged over all categories
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   smt_i          !: mean sea ice salinity averaged over all categories [PSU]
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   at_i_typ     !: total area   contained in each ice type [m^2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   vt_i_typ     !: total volume contained in each ice type [m^3]
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   t_s        !: Snow temperatures [K]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_s        !: Snow ...      
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   e_i_cat    !: ! go to trash
-      
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   t_i        !: ice temperatures          [K]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_i        !: ice thermal contents [Giga J]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   s_i        !: ice salinities          [PSU]
-
-   !!--------------------------------------------------------------------------
-   !! * Moments for advection
-   !!--------------------------------------------------------------------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   sxopw, syopw, sxxopw, syyopw, sxyopw   !: open water in sea ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxice, syice, sxxice, syyice, sxyice   !: ice thickness 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxsn , sysn , sxxsn , syysn , sxysn    !: snow thickness
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxa  , sya  , sxxa  , syya  , sxya     !: lead fraction
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxc0 , syc0 , sxxc0 , syyc0 , sxyc0    !: snow thermal content
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxsal, sysal, sxxsal, syysal, sxysal   !: ice salinity
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxage, syage, sxxage, syyage, sxyage   !: ice age
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   sxe  , sye  , sxxe  , syye  , sxye     !: ice layers heat content
-
-   !!--------------------------------------------------------------------------
-   !! * Old values of global variables
-   !!--------------------------------------------------------------------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   old_v_s, old_v_i               !: snow and ice volumes
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   old_a_i, old_smv_i, old_oa_i   !: ???
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   old_e_s                        !: snow heat content
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   old_e_i                        !: ice temperatures
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   old_u_ice, old_v_ice           !: ice velocity (gv6 and gv7)
-      
-
-   !!--------------------------------------------------------------------------
-   !! * Increment of global variables
-   !!--------------------------------------------------------------------------
-   ! thd refers to changes induced by thermodynamics
-   ! trp   ''         ''     ''       advection (transport of ice)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   d_a_i_thd  , d_a_i_trp                 !: icefractions                  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   d_v_s_thd  , d_v_s_trp                 !: snow volume
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   d_v_i_thd  , d_v_i_trp                 !: ice  volume
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   d_smv_i_thd, d_smv_i_trp               !:     
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   d_sm_i_fl  , d_sm_i_gd                 !:
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   d_sm_i_se  , d_sm_i_si  , d_sm_i_la    !:
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   d_oa_i_thd , d_oa_i_trp , s_i_newice   !:
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   d_e_s_thd  , d_e_s_trp     !:
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   d_e_i_thd  , d_e_i_trp     !:
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   d_u_ice_dyn, d_v_ice_dyn   !: ice velocity 
-      
-   !!--------------------------------------------------------------------------
-   !! * Ice thickness distribution variables
-   !!--------------------------------------------------------------------------
-   ! REMOVE
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   ice_types      !: Vector connecting types and categories
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ice_cat_bounds !: Matrix containing the integer upper and 
-   !                                                                       !  lower boundaries of ice thickness categories
-   ! REMOVE
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   ice_ncat_types !: nb of thickness categories in each ice type
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   hi_max         !: Boundary of ice thickness categories in thickness space
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   hi_mean        !: Mean ice thickness in catgories 
-   ! REMOVE
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hi_max_typ     !: Boundary of ice thickness categories in thickness space
-
-   !!--------------------------------------------------------------------------
-   !! * Ice Run
-   !!--------------------------------------------------------------------------
-   !                                                                     !!: ** Namelist namicerun read in iceini **
-   CHARACTER(len=32)     , PUBLIC ::   cn_icerst_in  = "restart_ice_in"   !: suffix of ice restart name (input)
-   CHARACTER(len=32)     , PUBLIC ::   cn_icerst_out = "restart_ice"      !: suffix of ice restart name (output)
-   LOGICAL               , PUBLIC ::   ln_limdyn     = .TRUE.             !: flag for ice dynamics (T) or not (F)
-   LOGICAL               , PUBLIC ::   ln_nicep      = .TRUE.             !: flag for sea-ice points output (T) or not (F)
-   REAL(wp)              , PUBLIC ::   cai           = 1.40e-3            !: atmospheric drag over sea ice
-   REAL(wp)              , PUBLIC ::   cao           = 1.00e-3            !: atmospheric drag over ocean
-   REAL(wp)              , PUBLIC ::   amax          = 0.99               !: maximum ice concentration
-   !                                                                      !
-   !!--------------------------------------------------------------------------
-   !! * Ice diagnostics
-   !!--------------------------------------------------------------------------
-   !! Check if everything down here is necessary
-   LOGICAL , PUBLIC                                      ::   ln_limdiahsb  = .TRUE. !: flag for ice diag (T) or not (F)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   v_newice   !: volume of ice formed in the leads
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dv_dt_thd  !: thermodynamic growth rates 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   izero, fstroc, fhbricat
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_sni_gr   ! snow ice growth 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_lat_gr   ! lateral ice growth 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_bot_gr   ! bottom ice growth 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_dyn_gr   ! dynamical ice growth 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_bot_me   ! vertical bottom melt 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_sur_me   ! vertical surface melt
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_res_pr   ! production (growth+melt) due to limupdate
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_trp_vi   ! transport of ice volume
-   INTEGER , PUBLIC ::   jiindx, jjindx        !: indexes of the debugging point
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
-   !! $Id: ice.F90 2777 2011-06-07 09:55:02Z smasson $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   FUNCTION ice_alloc()
-      !!-----------------------------------------------------------------
-      !!               *** Routine ice_alloc_2 ***
-      !!-----------------------------------------------------------------
-      INTEGER :: ice_alloc
-      !
-      INTEGER :: ierr(20), ii
-      !!-----------------------------------------------------------------
-
-      ierr(:) = 0
-
-      ! What could be one huge allocate statement is broken-up to try to
-      ! stay within Fortran's max-line length limit.
-      ii = 1
-      ALLOCATE( u_oce    (jpi,jpj) , v_oce    (jpi,jpj) ,                           &
-         &      ahiu     (jpi,jpj) , ahiv     (jpi,jpj) ,                           &
-         &      pahu     (jpi,jpj) , pahv     (jpi,jpj) ,                           &
-         &      ust2s    (jpi,jpj) , hicol    (jpi,jpj) ,                           &
-         &      strp1    (jpi,jpj) , strp2    (jpi,jpj) , strength  (jpi,jpj) ,     &
-         &      stress1_i(jpi,jpj) , stress2_i(jpi,jpj) , stress12_i(jpi,jpj) ,     &
-         &      delta_i  (jpi,jpj) , divu_i   (jpi,jpj) , shear_i   (jpi,jpj) , STAT=ierr(ii) )
-
-      ii = ii + 1
-      ALLOCATE( firic    (jpi,jpj) , fcsic  (jpi,jpj) , fleic    (jpi,jpj) , qlatic   (jpi,jpj) ,     &
-         &      rdvosif  (jpi,jpj) , rdvobif(jpi,jpj) , fdvolif  (jpi,jpj) , rdvonif  (jpi,jpj) ,     &
-         &      sist     (jpi,jpj) , icethi (jpi,jpj) , t_bo     (jpi,jpj) , hicifp   (jpi,jpj) ,     &
-         &      frld     (jpi,jpj) , pfrld  (jpi,jpj) , phicif   (jpi,jpj) , fbif     (jpi,jpj) ,     &
-         &      rdmsnif  (jpi,jpj) , rdmicif(jpi,jpj) , qldif    (jpi,jpj) , qcmif    (jpi,jpj) ,     &
-         &      fdtcn    (jpi,jpj) , qdtcn  (jpi,jpj) , fstric   (jpi,jpj) , fscmbq   (jpi,jpj) ,     &
-         &      ffltbif  (jpi,jpj) , fsbbq  (jpi,jpj) , qfvbq    (jpi,jpj) , dmgwi    (jpi,jpj) ,     &
-         &      fsalt_res(jpi,jpj) , fsbri  (jpi,jpj) , fsalt_rpo(jpi,jpj) , fheat_rpo(jpi,jpj) ,     &
-         &      fhbri    (jpi,jpj) , fmmec  (jpi,jpj) , fseqv    (jpi,jpj) , fhmec    (jpi,jpj) ,     &
-         &      fheat_res(jpi,jpj)                                                              , STAT=ierr(ii) )
-
-      ii = ii + 1
-      ALLOCATE( dh_i_surf2D(jpi,jpj) , dh_i_bott2D(jpi,jpj) , fstbif(jpi,jpj) ,     &
-         &      fsup2D     (jpi,jpj) , focea2D    (jpi,jpj) , q_s   (jpi,jpj) , STAT=ierr(ii) )
-
-      ii = ii + 1
-      ALLOCATE( patho_case(jpi,jpj,jpl) , STAT=ierr(ii) )
-
-      ! * Ice global state variables
-      ii = ii + 1
-      ALLOCATE( ht_i (jpi,jpj,jpl) , a_i  (jpi,jpj,jpl) , v_i  (jpi,jpj,jpl) ,     &
-         &      v_s  (jpi,jpj,jpl) , ht_s (jpi,jpj,jpl) , t_su (jpi,jpj,jpl) ,     &
-         &      sm_i (jpi,jpj,jpl) , smv_i(jpi,jpj,jpl) , o_i  (jpi,jpj,jpl) ,     &
-         &      ov_i (jpi,jpj,jpl) , oa_i (jpi,jpj,jpl)                      , STAT=ierr(ii) )
-      ii = ii + 1
-      ALLOCATE( u_ice(jpi,jpj) , v_ice(jpi,jpj) , tio_u(jpi,jpj) , tio_v(jpi,jpj) ,     &
-         &      vt_i (jpi,jpj) , vt_s (jpi,jpj) , at_i (jpi,jpj) , ato_i(jpi,jpj) ,     &
-         &      et_i (jpi,jpj) , et_s (jpi,jpj) , ot_i (jpi,jpj) , tm_i (jpi,jpj) ,     &
-         &      bv_i (jpi,jpj) , smt_i(jpi,jpj)                                   , STAT=ierr(ii) )
-      ii = ii + 1
-      ALLOCATE( t_s(jpi,jpj,nlay_s,jpl) , at_i_typ(jpi,jpj,jpm) ,                            &
-         &      e_s(jpi,jpj,nlay_s,jpl) , vt_i_typ(jpi,jpj,jpm) , e_i_cat(jpi,jpj,jpl) , STAT=ierr(ii) )
-      ii = ii + 1
-      ALLOCATE( t_i(jpi,jpj,jkmax,jpl) , e_i(jpi,jpj,jkmax,jpl) , s_i(jpi,jpj,jkmax,jpl) , STAT=ierr(ii) )
-
-      ! * Moments for advection
-      ii = ii + 1
-      ALLOCATE( sxopw(jpi,jpj) , syopw(jpi,jpj) , sxxopw(jpi,jpj) , syyopw(jpi,jpj) , sxyopw(jpi,jpj) , STAT=ierr(ii) )
-      ii = ii + 1
-      ALLOCATE( sxice(jpi,jpj,jpl) , syice(jpi,jpj,jpl) , sxxice(jpi,jpj,jpl) , syyice(jpi,jpj,jpl) , sxyice(jpi,jpj,jpl) ,   &
-         &      sxsn (jpi,jpj,jpl) , sysn (jpi,jpj,jpl) , sxxsn (jpi,jpj,jpl) , syysn (jpi,jpj,jpl) , sxysn (jpi,jpj,jpl) ,   &
-         &      STAT=ierr(ii) )
-      ii = ii + 1
-      ALLOCATE( sxa  (jpi,jpj,jpl) , sya  (jpi,jpj,jpl) , sxxa  (jpi,jpj,jpl) , syya  (jpi,jpj,jpl) , sxya  (jpi,jpj,jpl) ,   &
-         &      sxc0 (jpi,jpj,jpl) , syc0 (jpi,jpj,jpl) , sxxc0 (jpi,jpj,jpl) , syyc0 (jpi,jpj,jpl) , sxyc0 (jpi,jpj,jpl) ,   &
-         &      sxsal(jpi,jpj,jpl) , sysal(jpi,jpj,jpl) , sxxsal(jpi,jpj,jpl) , syysal(jpi,jpj,jpl) , sxysal(jpi,jpj,jpl) ,   &
-         &      sxage(jpi,jpj,jpl) , syage(jpi,jpj,jpl) , sxxage(jpi,jpj,jpl) , syyage(jpi,jpj,jpl) , sxyage(jpi,jpj,jpl) ,   &
-         &      STAT=ierr(ii) )
-      ii = ii + 1
-      ALLOCATE( sxe (jpi,jpj,jkmax,jpl) , sye (jpi,jpj,jkmax,jpl) , sxxe(jpi,jpj,jkmax,jpl) ,     &
-         &      syye(jpi,jpj,jkmax,jpl) , sxye(jpi,jpj,jkmax,jpl)                           , STAT=ierr(ii) )
-
-      ! * Old values of global variables
-      ii = ii + 1
-      ALLOCATE( old_v_s  (jpi,jpj,jpl) , old_v_i  (jpi,jpj,jpl) , old_e_s(jpi,jpj,nlay_s,jpl) ,     &
-         &      old_a_i  (jpi,jpj,jpl) , old_smv_i(jpi,jpj,jpl) , old_e_i(jpi,jpj,jkmax ,jpl) ,     &
-         &      old_oa_i (jpi,jpj,jpl)                                                        ,     &
-         &      old_u_ice(jpi,jpj)     , old_v_ice(jpi,jpj)                                   , STAT=ierr(ii) )
-
-      ! * Increment of global variables
-      ii = ii + 1
-      ALLOCATE( d_a_i_thd(jpi,jpj,jpl) , d_a_i_trp (jpi,jpj,jpl) , d_v_s_thd  (jpi,jpj,jpl) , d_v_s_trp  (jpi,jpj,jpl) ,   &
-         &      d_v_i_thd(jpi,jpj,jpl) , d_v_i_trp (jpi,jpj,jpl) , d_smv_i_thd(jpi,jpj,jpl) , d_smv_i_trp(jpi,jpj,jpl) ,   &     
-         &      d_sm_i_fl(jpi,jpj,jpl) , d_sm_i_gd (jpi,jpj,jpl) , d_sm_i_se  (jpi,jpj,jpl) , d_sm_i_si  (jpi,jpj,jpl) ,   &
-         &      d_sm_i_la(jpi,jpj,jpl) , d_oa_i_thd(jpi,jpj,jpl) , d_oa_i_trp (jpi,jpj,jpl) , s_i_newice (jpi,jpj,jpl) ,   &
-         &     STAT=ierr(ii) )
-      ii = ii + 1
-      ALLOCATE( d_e_s_thd(jpi,jpj,nlay_s,jpl) , d_e_i_thd(jpi,jpj,jkmax,jpl) , d_u_ice_dyn(jpi,jpj) ,     &
-         &      d_e_s_trp(jpi,jpj,nlay_s,jpl) , d_e_i_trp(jpi,jpj,jkmax,jpl) , d_v_ice_dyn(jpi,jpj) , STAT=ierr(ii) )
-      
-      ! * Ice thickness distribution variables
-      ii = ii + 1
-      ALLOCATE( ice_types(jpl) , ice_cat_bounds(jpm,2) , ice_ncat_types  (jpm) ,     &
-         &      hi_max (0:jpl) , hi_mean(jpl)          , hi_max_typ(0:jpl,jpm) , STAT=ierr(ii) )
-
-      ! * Ice diagnostics
-      ii = ii + 1
-      ALLOCATE( dv_dt_thd(jpi,jpj,jpl) , diag_sni_gr(jpi,jpj) , diag_lat_gr(jpi,jpj) ,     &
-         &      izero    (jpi,jpj,jpl) , diag_bot_gr(jpi,jpj) , diag_dyn_gr(jpi,jpj) ,     &
-         &      fstroc   (jpi,jpj,jpl) , diag_bot_me(jpi,jpj) , diag_sur_me(jpi,jpj) ,     &
-         &      fhbricat (jpi,jpj,jpl) , diag_res_pr(jpi,jpj) , diag_trp_vi(jpi,jpj) , v_newice(jpi,jpj) , STAT=ierr(ii) )
-
-      ice_alloc = MAXVAL( ierr(:) )
-      IF( ice_alloc /= 0 )   CALL ctl_warn('ice_alloc_2: failed to allocate arrays.')
-      !
-   END FUNCTION ice_alloc
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty module            NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-
-   !!======================================================================
-END MODULE ice
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/iceini.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/iceini.F90	(revision 3937)
+++ 	(revision )
@@ -1,252 +1,0 @@
-MODULE iceini
-   !!======================================================================
-   !!                       ***  MODULE iceini   ***
-   !!   Sea-ice model : LIM Sea ice model Initialization
-   !!======================================================================
-   !! History :  3.0  ! 2008-03  (M. Vancoppenolle) LIM-3 original code
-   !!            3.3  ! 2010-12  (G. Madec) add call to lim_thd_init and lim_thd_sal_init
-   !!            4.0  ! 2011-02  (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                   LIM sea-ice model
-   !!----------------------------------------------------------------------
-   !!   ice_init       : sea-ice model initialization
-   !!----------------------------------------------------------------------
-   USE phycst           ! physical constants
-   USE dom_oce          ! ocean domain
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE sbc_ice          ! Surface boundary condition: ice   fields
-   USE ice              ! LIM variables
-   USE par_ice          ! LIM parameters
-   USE dom_ice          ! LIM domain
-   USE thd_ice          ! LIM thermodynamical variables
-   USE limitd_me        ! LIM ice thickness distribution
-   USE limmsh           ! LIM mesh
-   USE limistate        ! LIM initial state
-   USE limrst           ! LIM restart
-   USE limthd           ! LIM ice thermodynamics
-   USE limthd_sal       ! LIM ice thermodynamics: salinity
-   USE limvar           ! LIM variables
-   USE limsbc           ! LIM surface boundary condition
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   ice_init   ! called by sbcice_lim.F90
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: iceini.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE ice_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ice_init  ***
-      !!
-      !! ** purpose :   Allocate all the dynamic arrays of the LIM-3 modules
-      !!----------------------------------------------------------------------
-      INTEGER :: ierr
-      !!----------------------------------------------------------------------
-
-      !                                ! Allocate the ice arrays
-      ierr =        ice_alloc        ()      ! ice variables
-      ierr = ierr + dom_ice_alloc    ()      ! domain
-      ierr = ierr + sbc_ice_alloc    ()      ! surface forcing
-      ierr = ierr + thd_ice_alloc    ()      ! thermodynamics
-      ierr = ierr + lim_itd_me_alloc ()      ! ice thickness distribution - mechanics
-      !
-      IF( lk_mpp    )   CALL mpp_sum( ierr )
-      IF( ierr /= 0 )   CALL ctl_stop('STOP', 'ice_init : unable to allocate ice arrays')
-      !
-      !                                ! adequation jpk versus ice/snow layers/categories
-      IF( jpl   > jpk  .OR.  jpm    > jpk .OR.                                    &
-          jkmax > jpk  .OR.  nlay_s > jpk      )   CALL ctl_stop( 'STOP',         &
-         &     'ice_init: the 3rd dimension of workspace arrays is too small.',   &
-         &     'use more ocean levels or less ice/snow layers/categories.' )
-
-      !                                ! Open the namelist file 
-      CALL ctl_opn( numnam_ice, 'namelist_ice', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp )
-      !
-      CALL ice_run                     ! set some ice run parameters
-      !
-      CALL lim_thd_init                ! set ice thermodynics parameters
-      !
-      CALL lim_thd_sal_init            ! set ice salinity parameters
-      !
-      rdt_ice = nn_fsbc * rdttra(1)    ! sea-ice timestep
-      !
-      CALL lim_msh                     ! ice mesh initialization
-      !
-      CALL lim_itd_ini                 ! ice thickness distribution initialization
-      !
-      CALL lim_sbc_init                ! ice surface boundary condition   
-
-
-      !                                ! Initial sea-ice state
-      IF( .NOT.ln_rstart ) THEN              ! start from rest
-         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                                   ! start from a restart file
-         CALL lim_rst_read                      ! read the restart file
-         numit = nit000 - 1
-         CALL lim_var_agg(1)                    ! aggregate ice variables
-         CALL lim_var_glo2eqv                   ! convert global var in equivalent variables
-      ENDIF
-      !
-      fr_i(:,:) = at_i(:,:)           ! initialisation of sea-ice fraction
-      !
-      nstart = numit  + nn_fsbc      
-      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
-      !!-------------------------------------------------------------------
-      NAMELIST/namicerun/ cn_icerst_in, cn_icerst_out, ln_limdyn, amax, cai, cao, ln_nicep, ln_limdiahsb
-      !!-------------------------------------------------------------------
-      !                    
-      REWIND( numnam_ice )                ! Read Namelist namicerun 
-      READ  ( numnam_ice , namicerun )
-      !
-      IF( lk_mpp .AND. ln_nicep ) THEN
-         ln_nicep = .FALSE.
-         CALL ctl_warn( 'ice_run : specific control print for LIM3 desactivated with MPI' )
-      ENDIF       
-      !
-      IF(lwp) THEN                        ! control print
-         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,*) '   maximum ice concentration                               = ', amax 
-         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
-         WRITE(numout,*) '   Diagnose heat/salt budget or not          ln_limdiahsb  = ', ln_limdiahsb
-      ENDIF
-      !
-   END SUBROUTINE ice_run
-
-
-   SUBROUTINE lim_itd_ini
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_ini ***
-      !!
-      !! ** Purpose :   Initializes the ice thickness distribution
-      !! ** Method  :   ...
-      !!------------------------------------------------------------------
-      INTEGER  ::   jl, jm               ! dummy loop index
-      REAL(wp) ::   zc1, zc2, zc3, zx1   ! local scalars
-      !!------------------------------------------------------------------
-
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'lim_itd_ini : Initialization of ice thickness distribution '
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
-
-      !------------------------------------------------------------------------------!
-      ! 1) Ice thickness distribution parameters initialization    
-      !------------------------------------------------------------------------------!
-
-      !- Types boundaries (integer)
-      !----------------------------
-      ice_cat_bounds(1,1) = 1
-      ice_cat_bounds(1,2) = jpl
-
-      !- Number of ice thickness categories in each ice type
-      DO jm = 1, jpm
-         ice_ncat_types(jm) = ice_cat_bounds(jm,2) - ice_cat_bounds(jm,1) + 1 
-      END DO
-
-      !- Make the correspondence between thickness categories and ice types
-      !---------------------------------------------------------------------
-      DO jm = 1, jpm       !over types
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2) !over thickness categories
-            ice_types(jl) = jm
-         END DO
-      END DO
-
-      IF(lwp) THEN  
-         WRITE(numout,*) ' Number of ice types jpm =      ', jpm
-         WRITE(numout,*) ' Number of ice categories jpl = ', jpl
-         DO jm = 1, jpm
-            WRITE(numout,*) ' Ice type ', jm
-            WRITE(numout,*) ' Number of thickness categories ', ice_ncat_types(jm)
-            WRITE(numout,*) ' Thickness category boundaries  ', ice_cat_bounds(jm,1:2)
-         END DO
-         WRITE(numout,*) 'Ice type vector', ice_types(1:jpl)
-         WRITE(numout,*)
-      ENDIF
-
-      !- Thickness categories boundaries 
-      !----------------------------------
-      hi_max(:) = 0._wp
-      hi_max_typ(:,:) = 0._wp
-
-      !- Type 1 - undeformed ice
-      zc1 =  3._wp / REAL( ice_cat_bounds(1,2) - ice_cat_bounds(1,1) + 1 , wp )
-      zc2 = 10._wp * zc1
-      zc3 =  3._wp
-
-      DO jl = ice_cat_bounds(1,1), ice_cat_bounds(1,2)
-         zx1 = REAL( jl-1 , wp ) / REAL( ice_cat_bounds(1,2) - ice_cat_bounds(1,1) + 1 , wp )
-         hi_max(jl) = hi_max(jl-1) + zc1 + zc2 * (1._wp + TANH( zc3 * (zx1 - 1._wp ) ) )
-      END DO
-
-      !- Fill in the hi_max_typ vector, useful in other circumstances
-      ! Tricky trick: hi_max_typ is actually not used in the code and will be removed in a
-      ! next flyspray at this time, the tricky trick will also be removed (Martin, march 08)
-      DO jl = ice_cat_bounds(1,1), ice_cat_bounds(1,2)
-         hi_max_typ(jl,1) = hi_max(jl)
-      END DO
-
-      IF(lwp) WRITE(numout,*) ' Thickness category boundaries independently of ice type '
-      IF(lwp) WRITE(numout,*) ' hi_max ', hi_max(0:jpl)
-
-      IF(lwp) WRITE(numout,*) ' Thickness category boundaries inside ice types '
-      IF(lwp) THEN 
-         DO jm = 1, jpm
-            WRITE(numout,*) ' Type number ', jm
-            WRITE(numout,*) ' hi_max_typ : ', hi_max_typ(0:ice_ncat_types(jm),jm)
-         END DO
-      ENDIF
-      !
-      DO jl = 1, jpl
-         hi_mean(jl) = ( hi_max(jl) + hi_max(jl-1) ) * 0.5_wp
-      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
-#endif
-
-   !!======================================================================
-END MODULE iceini
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/iom.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/iom.F90	(revision 3937)
+++ 	(revision )
@@ -1,1220 +1,0 @@
-MODULE iom
-   !!=====================================================================
-   !!                    ***  MODULE  iom ***
-   !! Input/Output manager :  Library to read input files
-   !!====================================================================
-   !! History :  9.0  ! 05 12  (J. Belier) Original code
-   !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
-   !!             "   ! 07 07  (D. Storkey) Changes to iom_gettime
-   !!--------------------------------------------------------------------
-   !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
-
-   !!--------------------------------------------------------------------
-   !!   iom_open       : open a file read only
-   !!   iom_close      : close a file or all files opened by iom
-   !!   iom_get        : read a field (interfaced to several routines)
-   !!   iom_gettime    : read the time axis cdvar in the file
-   !!   iom_varid      : get the id of a variable in a file
-   !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
-   !!--------------------------------------------------------------------
-   USE dom_oce         ! ocean space and time domain
-   USE flo_oce         ! floats module declarations
-   USE lbclnk          ! lateal boundary condition / mpp exchanges
-   USE iom_def         ! iom variables definitions
-   USE iom_ioipsl      ! NetCDF format with IOIPSL library
-   USE iom_nf90        ! NetCDF format with native NetCDF library
-   USE iom_rstdimg     ! restarts access direct format "dimg" style...
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp           ! MPP library
-   USE timing          ! Timing
-#if defined key_iomput
-   USE sbc_oce, ONLY :   nn_fsbc         ! ocean space and time domain
-   USE domngb          ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE dianam          ! build name of file
-   USE mod_event_client
-   USE mod_attribut
-# endif
-
-   IMPLICIT NONE
-   PUBLIC   !   must be public to be able to access iom_def through iom
-   
-#if defined key_iomput
-   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .TRUE.        !: iom_put flag
-#else
-   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .FALSE.       !: iom_put flag
-#endif
-   PUBLIC iom_init, iom_swap, iom_open, iom_close, iom_setkt, iom_varid, iom_get, iom_gettime, iom_rstput, iom_put
-   PUBLIC iom_getatt
-
-   PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
-   PRIVATE iom_g0d, iom_g1d, iom_g2d, iom_g3d, iom_get_123d
-   PRIVATE iom_p1d, iom_p2d, iom_p3d
-#if defined key_iomput
-   PRIVATE set_grid
-# endif
-
-   INTERFACE iom_get
-      MODULE PROCEDURE iom_g0d, iom_g1d, iom_g2d, iom_g3d
-   END INTERFACE
-   INTERFACE iom_getatt
-      MODULE PROCEDURE iom_g0d_intatt
-   END INTERFACE
-   INTERFACE iom_rstput
-      MODULE PROCEDURE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
-   END INTERFACE
-  INTERFACE iom_put
-     MODULE PROCEDURE iom_p0d, iom_p1d, iom_p2d, iom_p3d
-  END INTERFACE
-#if defined key_iomput
-   INTERFACE iom_setkt
-      MODULE PROCEDURE event__set_timestep
-   END INTERFACE
-# endif
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: iom.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE iom_init
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE   ***
-      !!
-      !! ** Purpose :   
-      !!
-      !!----------------------------------------------------------------------
-#if defined key_iomput
-      REAL(wp) ::   ztmp
-      !!----------------------------------------------------------------------
-      ! read the xml file
-      IF( Agrif_Root() ) CALL event__parse_xml_file( 'iodef.xml' )   ! <- to get from the nameliste (namrun)...
-      CALL iom_swap
-
-      ! calendar parameters
-      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
-      CASE ( 1)   ;   CALL event__set_calendar('gregorian')
-      CASE ( 0)   ;   CALL event__set_calendar('noleap'   )
-      CASE (30)   ;   CALL event__set_calendar('360d'     )
-      END SELECT
-      ztmp = fjulday - adatrj
-      IF( ABS(ztmp  - REAL(NINT(ztmp),wp)) < 0.1 / rday )   ztmp = REAL(NINT(ztmp),wp)   ! avoid truncation error
-      CALL event__set_time_parameters( nit000 - 1, ztmp, rdt )
-
-      ! horizontal grid definition
-      CALL set_scalar
-      CALL set_grid( "grid_T", glamt, gphit )
-      CALL set_grid( "grid_U", glamu, gphiu )
-      CALL set_grid( "grid_V", glamv, gphiv )
-      CALL set_grid( "grid_W", glamt, gphit )
-
-      ! vertical grid definition
-      CALL event__set_vert_axis( "deptht", gdept_0 )
-      CALL event__set_vert_axis( "depthu", gdept_0 )
-      CALL event__set_vert_axis( "depthv", gdept_0 )
-      CALL event__set_vert_axis( "depthw", gdepw_0 )
-# if defined key_floats
-      CALL event__set_vert_axis( "nfloat", REAL(nfloat,wp)  )
-# endif
-      
-      ! automatic definitions of some of the xml attributs
-      CALL set_xmlatt
-
-      ! end file definition
-      CALL event__close_io_definition
-#endif
-
-   END SUBROUTINE iom_init
-
-
-   SUBROUTINE iom_swap
-      !!---------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_swap  ***
-      !!
-      !! ** Purpose :  swap context between different agrif grid for xmlio_server
-      !!---------------------------------------------------------------------
-#if defined key_iomput
-
-     IF( TRIM(Agrif_CFixed()) == '0' ) THEN
-        CALL event__swap_context("nemo")
-     ELSE
-        CALL event__swap_context(TRIM(Agrif_CFixed())//"_nemo")
-     ENDIF
-
-#endif
-   END SUBROUTINE iom_swap
-
-
-   SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, kiolib, ldstop, ldiof )
-      !!---------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_open  ***
-      !!
-      !! ** Purpose :  open an input file (return 0 if not found)
-      !!---------------------------------------------------------------------
-      CHARACTER(len=*), INTENT(in   )           ::   cdname   ! File name
-      INTEGER         , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file
-      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldwrt    ! open in write modeb          (default = .FALSE.)
-      INTEGER         , INTENT(in   ), OPTIONAL ::   kdom     ! Type of domain to be written (default = jpdom_local_noovlap)
-      INTEGER         , INTENT(in   ), OPTIONAL ::   kiolib   ! library used to open the file (default = jpnf90) 
-      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
-      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldiof    ! Interp On the Fly, needed for AGRIF (default = .FALSE.)
-
-      CHARACTER(LEN=100)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
-      CHARACTER(LEN=100)    ::   cltmpn    ! tempory name to store clname (in writting mode)
-      CHARACTER(LEN=10)     ::   clsuffix  ! ".nc" or ".dimg"
-      CHARACTER(LEN=15)     ::   clcpu     ! the cpu number (max jpmax_digits digits)
-      CHARACTER(LEN=100)    ::   clinfo    ! info character
-      LOGICAL               ::   llok      ! check the existence 
-      LOGICAL               ::   llwrt     ! local definition of ldwrt
-      LOGICAL               ::   llnoov    ! local definition to read overlap
-      LOGICAL               ::   llstop    ! local definition of ldstop
-      LOGICAL               ::   lliof     ! local definition of ldiof
-      INTEGER               ::   iolib     ! library do we use to open the file
-      INTEGER               ::   icnt      ! counter for digits in clcpu (max = jpmax_digits)
-      INTEGER               ::   iln, ils  ! lengths of character
-      INTEGER               ::   idom      ! type of domain
-      INTEGER               ::   istop     ! 
-      INTEGER, DIMENSION(2,5) ::   idompar ! domain parameters: 
-      ! local number of points for x,y dimensions
-      ! position of first local point for x,y dimensions
-      ! position of last local point for x,y dimensions
-      ! start halo size for x,y dimensions
-      ! end halo size for x,y dimensions
-      !---------------------------------------------------------------------
-      ! Initializations and control
-      ! =============
-      kiomid = -1
-      clinfo = '                    iom_open ~~~  '
-      istop = nstop
-      ! if iom_open is called for the first time: initialize iom_file(:)%nfid to 0
-      ! (could be done when defining iom_file in f95 but not in f90)
-      IF( Agrif_Root() ) THEN
-         IF( iom_open_init == 0 ) THEN
-            iom_file(:)%nfid = 0
-            iom_open_init = 1
-         ENDIF
-      ENDIF
-      ! do we read or write the file?
-      IF( PRESENT(ldwrt) ) THEN   ;   llwrt = ldwrt
-      ELSE                        ;   llwrt = .FALSE.
-      ENDIF
-      ! do we call ctl_stop if we try to open a non-existing file in read mode?
-      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
-      ELSE                         ;   llstop = .TRUE.
-      ENDIF
-      ! what library do we use to open the file?
-      IF( PRESENT(kiolib) ) THEN   ;   iolib = kiolib
-      ELSE                         ;   iolib = jpnf90
-      ENDIF
-      ! are we using interpolation on the fly?
-      IF( PRESENT(ldiof) ) THEN   ;   lliof = ldiof
-      ELSE                        ;   lliof = .FALSE.
-      ENDIF
-      ! do we read the overlap 
-      ! ugly patch SM+JMM+RB to overwrite global definition in some cases
-      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
-      ! create the file name by added, if needed, TRIM(Agrif_CFixed()) and TRIM(clsuffix)
-      ! =============
-      clname   = trim(cdname)
-      IF ( .NOT. Agrif_Root() .AND. .NOT. lliof ) THEN
-         iln    = INDEX(clname,'/') 
-         cltmpn = clname(1:iln)
-         clname = clname(iln+1:LEN_TRIM(clname))
-         clname=TRIM(cltmpn)//TRIM(Agrif_CFixed())//'_'//TRIM(clname)
-      ENDIF
-      ! which suffix should we use?
-      SELECT CASE (iolib)
-      CASE (jpioipsl ) ;   clsuffix = '.nc'
-      CASE (jpnf90   ) ;   clsuffix = '.nc'
-      CASE (jprstdimg) ;   clsuffix = '.dimg'
-      CASE DEFAULT     ;   clsuffix = ''
-         CALL ctl_stop( TRIM(clinfo), 'accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-      END SELECT
-      ! Add the suffix if needed
-      iln = LEN_TRIM(clname)
-      ils = LEN_TRIM(clsuffix)
-      IF( iln <= ils .OR. INDEX( TRIM(clname), TRIM(clsuffix), back = .TRUE. ) /= iln - ils + 1 )   &
-         &   clname = TRIM(clname)//TRIM(clsuffix)
-      cltmpn = clname   ! store this name
-      ! try to find if the file to be opened already exist
-      ! =============
-      INQUIRE( FILE = clname, EXIST = llok )
-      IF( .NOT.llok ) THEN
-         ! we try to add the cpu number to the name
-         IF( iolib == jprstdimg ) THEN   ;   WRITE(clcpu,*) narea
-         ELSE                            ;   WRITE(clcpu,*) narea-1
-         ENDIF
-         clcpu  = TRIM(ADJUSTL(clcpu))
-         iln = INDEX(clname,TRIM(clsuffix), back = .TRUE.)
-         clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
-         icnt = 0
-         INQUIRE( FILE = clname, EXIST = llok ) 
-         ! we try different formats for the cpu number by adding 0
-         DO WHILE( .NOT.llok .AND. icnt < jpmax_digits )
-            clcpu  = "0"//trim(clcpu)
-            clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
-            INQUIRE( FILE = clname, EXIST = llok )
-            icnt = icnt + 1
-         END DO
-      ENDIF
-      IF( llwrt ) THEN
-         ! check the domain definition
-! JMM + SM: ugly patch before getting the new version of lib_mpp)
-!         idom = jpdom_local_noovlap   ! default definition
-         IF( llnoov ) THEN   ;   idom = jpdom_local_noovlap   ! default definition
-         ELSE                ;   idom = jpdom_local_full      ! default definition
-         ENDIF
-         IF( PRESENT(kdom) )   idom = kdom
-         ! create the domain informations
-         ! =============
-         SELECT CASE (idom)
-         CASE (jpdom_local_full)
-            idompar(:,1) = (/ jpi             , jpj              /)
-            idompar(:,2) = (/ nimpp           , njmpp            /)
-            idompar(:,3) = (/ nimpp + jpi - 1 , njmpp + jpj - 1  /)
-            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
-            idompar(:,5) = (/ jpi - nlei      , jpj - nlej       /)
-         CASE (jpdom_local_noextra)
-            idompar(:,1) = (/ nlci            , nlcj             /)
-            idompar(:,2) = (/ nimpp           , njmpp            /)
-            idompar(:,3) = (/ nimpp + nlci - 1, njmpp + nlcj - 1 /)
-            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
-            idompar(:,5) = (/ nlci - nlei     , nlcj - nlej      /)
-         CASE (jpdom_local_noovlap)
-            idompar(:,1) = (/ nlei  - nldi + 1, nlej  - nldj + 1 /)
-            idompar(:,2) = (/ nimpp + nldi - 1, njmpp + nldj - 1 /)
-            idompar(:,3) = (/ nimpp + nlei - 1, njmpp + nlej - 1 /)
-            idompar(:,4) = (/ 0               , 0                /)
-            idompar(:,5) = (/ 0               , 0                /)
-         CASE DEFAULT
-            CALL ctl_stop( TRIM(clinfo), 'wrong value of kdom, only jpdom_local* cases are accepted' )
-         END SELECT
-      ENDIF
-      ! Open the NetCDF or RSTDIMG file
-      ! =============
-      ! do we have some free file identifier?
-      IF( MINVAL(iom_file(:)%nfid) /= 0 )   &
-         &   CALL ctl_stop( TRIM(clinfo), 'No more free file identifier', 'increase jpmax_files in iom_def' )
-      ! if no file was found...
-      IF( .NOT. llok ) THEN
-         IF( .NOT. llwrt ) THEN   ! we are in read mode 
-            IF( llstop ) THEN   ;   CALL ctl_stop( TRIM(clinfo), 'File '//TRIM(cltmpn)//'* not found' )
-            ELSE                ;   istop = nstop + 1   ! make sure that istop /= nstop so we don't open the file
-            ENDIF
-         ELSE                     ! we are in write mode so we 
-            clname = cltmpn       ! get back the file name without the cpu number
-         ENDIF
-      ELSE
-         IF( llwrt .AND. .NOT. ln_clobber ) THEN   ! we stop as we want to write in a new file 
-            CALL ctl_stop( TRIM(clinfo), 'We want to write in a new file but '//TRIM(clname)//' already exists...' )
-            istop = nstop + 1                      ! make sure that istop /= nstop so we don't open the file
-         ENDIF
-      ENDIF
-      IF( istop == nstop ) THEN   ! no error within this routine
-         SELECT CASE (iolib)
-         CASE (jpioipsl )   ;   CALL iom_ioipsl_open(  clname, kiomid, llwrt, llok, idompar )
-         CASE (jpnf90   )   ;   CALL iom_nf90_open(    clname, kiomid, llwrt, llok, idompar )
-         CASE (jprstdimg)   ;   CALL iom_rstdimg_open( clname, kiomid, llwrt, llok, idompar )
-         CASE DEFAULT
-            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-         END SELECT
-      ENDIF
-      !
-   END SUBROUTINE iom_open
-
-
-   SUBROUTINE iom_close( kiomid )
-      !!--------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_close  ***
-      !!
-      !! ** Purpose : close an input file, or all files opened by iom
-      !!--------------------------------------------------------------------
-      INTEGER, INTENT(inout), OPTIONAL ::   kiomid   ! iom identifier of the file to be closed
-      !                                              ! return 0 when file is properly closed
-      !                                              ! No argument: all files opened by iom are closed
-
-      INTEGER ::   jf         ! dummy loop indices
-      INTEGER ::   i_s, i_e   ! temporary integer
-      CHARACTER(LEN=100)    ::   clinfo    ! info character
-      !---------------------------------------------------------------------
-      !
-      clinfo = '                    iom_close ~~~  '
-      IF( PRESENT(kiomid) ) THEN
-         i_s = kiomid
-         i_e = kiomid
-      ELSE
-         i_s = 1
-         i_e = jpmax_files
-#if defined key_iomput
-         CALL event__stop_ioserver
-#endif
-      ENDIF
-
-      IF( i_s > 0 ) THEN
-         DO jf = i_s, i_e
-            IF( iom_file(jf)%nfid > 0 ) THEN
-               SELECT CASE (iom_file(jf)%iolib)
-               CASE (jpioipsl )   ;   CALL iom_ioipsl_close(  jf )
-               CASE (jpnf90   )   ;   CALL iom_nf90_close(    jf )
-               CASE (jprstdimg)   ;   CALL iom_rstdimg_close( jf )
-               CASE DEFAULT
-                  CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-               END SELECT
-               iom_file(jf)%nfid       = 0          ! free the id 
-               IF( PRESENT(kiomid) )   kiomid = 0   ! return 0 as id to specify that the file was closed
-               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' close file: '//TRIM(iom_file(jf)%name)//' ok'
-            ELSEIF( PRESENT(kiomid) ) THEN
-               WRITE(ctmp1,*) '--->',  kiomid
-               CALL ctl_stop( TRIM(clinfo)//' Invalid file identifier', ctmp1 )
-            ENDIF
-         END DO
-      ENDIF
-      !    
-   END SUBROUTINE iom_close
-
-
-   FUNCTION iom_varid ( kiomid, cdvar, kdimsz, kndims, ldstop )  
-      !!-----------------------------------------------------------------------
-      !!                  ***  FUNCTION  iom_varid  ***
-      !!
-      !! ** Purpose : get the id of a variable in a file (return 0 if not found)
-      !!-----------------------------------------------------------------------
-      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
-      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
-      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
-      INTEGER,               INTENT(  out), OPTIONAL ::   kndims   ! size of the dimensions
-      LOGICAL              , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if looking for non-existing variable (default = .TRUE.)
-      !
-      INTEGER                        ::   iom_varid, iiv, i_nvd
-      LOGICAL                        ::   ll_fnd
-      CHARACTER(LEN=100)             ::   clinfo                   ! info character
-      LOGICAL                        ::   llstop                   ! local definition of ldstop
-      !!-----------------------------------------------------------------------
-      iom_varid = 0                         ! default definition
-      ! do we call ctl_stop if we look for non-existing variable?
-      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
-      ELSE                         ;   llstop = .TRUE.
-      ENDIF
-      !
-      IF( kiomid > 0 ) THEN
-         clinfo = 'iom_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
-         IF( iom_file(kiomid)%nfid == 0 ) THEN 
-            CALL ctl_stop( trim(clinfo), 'the file is not open' )
-         ELSE
-            ll_fnd  = .FALSE.
-            iiv = 0
-            !
-            DO WHILE ( .NOT.ll_fnd .AND. iiv < iom_file(kiomid)%nvars )
-               iiv = iiv + 1
-               ll_fnd  = ( TRIM(cdvar) == TRIM(iom_file(kiomid)%cn_var(iiv)) )
-            END DO
-            !
-            IF( .NOT.ll_fnd ) THEN
-               iiv = iiv + 1
-               IF( iiv <= jpmax_vars ) THEN
-                  SELECT CASE (iom_file(kiomid)%iolib)
-                  CASE (jpioipsl )   ;   iom_varid = iom_ioipsl_varid( kiomid, cdvar, iiv, kdimsz )
-                  CASE (jpnf90   )   ;   iom_varid = iom_nf90_varid  ( kiomid, cdvar, iiv, kdimsz, kndims )
-                  CASE (jprstdimg)   ;   iom_varid = -1   ! all variables are listed in iom_file
-                  CASE DEFAULT   
-                     CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-                  END SELECT
-               ELSE
-                  CALL ctl_stop( trim(clinfo), 'Too many variables in the file '//iom_file(kiomid)%name,   &
-                        &                         'increase the parameter jpmax_vars')
-               ENDIF
-               IF( llstop .AND. iom_varid == -1 )   CALL ctl_stop( TRIM(clinfo)//' not found' ) 
-            ELSE
-               iom_varid = iiv
-               IF( PRESENT(kdimsz) ) THEN 
-                  i_nvd = iom_file(kiomid)%ndims(iiv)
-                  IF( i_nvd == size(kdimsz) ) THEN
-                     kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,iiv)
-                  ELSE
-                     WRITE(ctmp1,*) i_nvd, size(kdimsz)
-                     CALL ctl_stop( trim(clinfo), 'error in kdimsz size'//trim(ctmp1) )
-                  ENDIF
-               ENDIF
-               IF( PRESENT(kndims) )  kndims = iom_file(kiomid)%ndims(iiv)
-            ENDIF
-         ENDIF
-      ENDIF
-      !
-   END FUNCTION iom_varid
-
-
-   !!----------------------------------------------------------------------
-   !!                   INTERFACE iom_get
-   !!----------------------------------------------------------------------
-   SUBROUTINE iom_g0d( kiomid, cdvar, pvar )
-      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
-      CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
-      REAL(wp)        , INTENT(  out)                 ::   pvar      ! read field
-      !
-      INTEGER               :: idvar   ! variable id
-      !
-      IF( kiomid > 0 ) THEN
-         idvar = iom_varid( kiomid, cdvar )
-         IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
-            SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, pvar )
-            CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar )
-            CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idvar, pvar )
-            CASE DEFAULT    
-               CALL ctl_stop( 'iom_g0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-            END SELECT
-         ENDIF
-      ENDIF
-   END SUBROUTINE iom_g0d
-
-   SUBROUTINE iom_g1d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
-      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
-      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
-      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
-      REAL(wp)        , INTENT(  out), DIMENSION(:)           ::   pvar      ! read field
-      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
-      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kstart    ! start axis position of the reading 
-      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kcount    ! number of points in each axis
-      !
-      IF( kiomid > 0 ) THEN
-         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r1d=pvar,   &
-              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
-      ENDIF
-   END SUBROUTINE iom_g1d
-
-   SUBROUTINE iom_g2d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
-      INTEGER         , INTENT(in   )                           ::   kiomid    ! Identifier of the file
-      INTEGER         , INTENT(in   )                           ::   kdom      ! Type of domain to be read
-      CHARACTER(len=*), INTENT(in   )                           ::   cdvar     ! Name of the variable
-      REAL(wp)        , INTENT(  out), DIMENSION(:,:)           ::   pvar      ! read field
-      INTEGER         , INTENT(in   )                , OPTIONAL ::   ktime     ! record number
-      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kstart    ! start axis position of the reading 
-      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kcount    ! number of points in each axis
-      !
-      IF( kiomid > 0 ) THEN
-         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r2d=pvar,   &
-              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
-      ENDIF
-   END SUBROUTINE iom_g2d
-
-   SUBROUTINE iom_g3d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
-      INTEGER         , INTENT(in   )                             ::   kiomid    ! Identifier of the file
-      INTEGER         , INTENT(in   )                             ::   kdom      ! Type of domain to be read
-      CHARACTER(len=*), INTENT(in   )                             ::   cdvar     ! Name of the variable
-      REAL(wp)        , INTENT(  out), DIMENSION(:,:,:)           ::   pvar      ! read field
-      INTEGER         , INTENT(in   )                  , OPTIONAL ::   ktime     ! record number
-      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kstart    ! start axis position of the reading 
-      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kcount    ! number of points in each axis
-      !
-      IF( kiomid > 0 ) THEN
-         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r3d=pvar,   &
-              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
-      ENDIF
-   END SUBROUTINE iom_g3d
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE iom_get_123d( kiomid, kdom  , cdvar ,   &
-         &                  pv_r1d, pv_r2d, pv_r3d,   &
-         &                  ktime , kstart, kcount  )
-      !!-----------------------------------------------------------------------
-      !!                  ***  ROUTINE  iom_get_123d  ***
-      !!
-      !! ** Purpose : read a 1D/2D/3D variable
-      !!
-      !! ** Method : read ONE record at each CALL
-      !!-----------------------------------------------------------------------
-      INTEGER                    , INTENT(in   )           ::   kiomid     ! Identifier of the file
-      INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read
-      CHARACTER(len=*)           , INTENT(in   )           ::   cdvar      ! Name of the variable
-      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
-      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
-      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
-      INTEGER                    , INTENT(in   ), OPTIONAL ::   ktime      ! record number
-      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kstart     ! start position of the reading in each axis 
-      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kcount     ! number of points to be read in each axis
-      !
-      LOGICAL                        ::   llnoov      ! local definition to read overlap
-      INTEGER                        ::   jl          ! loop on number of dimension 
-      INTEGER                        ::   idom        ! type of domain
-      INTEGER                        ::   idvar       ! id of the variable
-      INTEGER                        ::   inbdim      ! number of dimensions of the variable
-      INTEGER                        ::   idmspc      ! number of spatial dimensions 
-      INTEGER                        ::   itime       ! record number
-      INTEGER                        ::   istop       ! temporary value of nstop
-      INTEGER                        ::   ix1, ix2, iy1, iy2   ! subdomain indexes
-      INTEGER                        ::   ji, jj      ! loop counters
-      INTEGER                        ::   irankpv       ! 
-      INTEGER                        ::   ind1, ind2  ! substring index
-      INTEGER, DIMENSION(jpmax_dims) ::   istart      ! starting point to read for each axis
-      INTEGER, DIMENSION(jpmax_dims) ::   icnt        ! number of value to read along each axis 
-      INTEGER, DIMENSION(jpmax_dims) ::   idimsz      ! size of the dimensions of the variable
-      INTEGER, DIMENSION(jpmax_dims) ::   ishape      ! size of the dimensions of the variable
-      REAL(wp)                       ::   zscf, zofs  ! sacle_factor and add_offset
-      INTEGER                        ::   itmp        ! temporary integer
-      CHARACTER(LEN=100)             ::   clinfo      ! info character
-      CHARACTER(LEN=100)             ::   clname      ! file name
-      CHARACTER(LEN=1)               ::   clrankpv, cldmspc      ! 
-      !---------------------------------------------------------------------
-      !
-      clname = iom_file(kiomid)%name   !   esier to read
-      clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
-      ! local definition of the domain ?
-      idom = kdom
-      ! do we read the overlap 
-      ! ugly patch SM+JMM+RB to overwrite global definition in some cases
-      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
-      ! check kcount and kstart optionals parameters...
-      IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
-      IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
-      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown   ) CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown')
-
-      ! Search for the variable in the data base (eventually actualize data)
-      istop = nstop
-      idvar = iom_varid( kiomid, cdvar )
-      !
-      IF( idvar > 0 ) THEN
-         ! to write iom_file(kiomid)%dimsz in a shorter way !
-         idimsz(:) = iom_file(kiomid)%dimsz(:, idvar) 
-         inbdim = iom_file(kiomid)%ndims(idvar)            ! number of dimensions in the file
-         idmspc = inbdim                                   ! number of spatial dimensions in the file
-         IF( iom_file(kiomid)%luld(idvar) )   idmspc = inbdim - 1
-         IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') 
-         !
-         ! update idom definition...
-         ! Identify the domain in case of jpdom_auto(glo/dta) definition
-         IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN            
-            IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global 
-            ELSE                               ;   idom = jpdom_data
-            ENDIF
-            ind1 = INDEX( clname, '_', back = .TRUE. ) + 1
-            ind2 = INDEX( clname, '.', back = .TRUE. ) - 1
-            IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF
-         ENDIF
-         ! Identify the domain in case of jpdom_local definition
-         IF( idom == jpdom_local ) THEN
-            IF(     idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN   ;   idom = jpdom_local_full
-            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN   ;   idom = jpdom_local_noextra
-            ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN   ;   idom = jpdom_local_noovlap
-            ELSE   ;   CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' )
-            ENDIF
-         ENDIF
-         !
-         ! check the consistency between input array and data rank in the file
-         !
-         ! initializations
-         itime = 1
-         IF( PRESENT(ktime) ) itime = ktime
-
-         irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) )
-         WRITE(clrankpv, fmt='(i1)') irankpv
-         WRITE(cldmspc , fmt='(i1)') idmspc
-         !
-         IF(     idmspc <  irankpv ) THEN 
-            CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   &
-               &                         'it is impossible to read a '//clrankpv//'D array from this file...' )
-         ELSEIF( idmspc == irankpv ) THEN
-            IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   &
-               &   CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' )
-         ELSEIF( idmspc >  irankpv ) THEN
-               IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
-                  CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...'              ,   &
-                        &         'As the size of the z dimension is 1 and as we try to read the first record, ',   &
-                        &         'we accept this case, even if there is a possible mix-up between z and time dimension' )   
-                  idmspc = idmspc - 1
-               ELSE
-                  CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,'         ,   &
-                     &                         'we do not accept data with more than '//cldmspc//' spatial dimension',   &
-                     &                         'Use ncwa -a to suppress the unnecessary dimensions' )
-               ENDIF
-         ENDIF
-
-         !
-         ! definition of istart and icnt
-         !
-         icnt  (:) = 1
-         istart(:) = 1
-         istart(idmspc+1) = itime
-
-         IF(              PRESENT(kstart)       ) THEN ; istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
-         ELSE
-            IF(           idom == jpdom_unknown ) THEN                                       ; icnt(1:idmspc) = idimsz(1:idmspc)
-            ELSE 
-               IF( .NOT. PRESENT(pv_r1d) ) THEN   !   not a 1D array
-                  IF(     idom == jpdom_data    ) THEN ; istart(1:2) = (/ mig(1), mjg(1) /)  ! icnt(1:2) done bellow
-                  ELSEIF( idom == jpdom_global  ) THEN ; istart(1:2) = (/ nimpp , njmpp  /)  ! icnt(1:2) done bellow
-                  ENDIF
-                  ! we do not read the overlap                     -> we start to read at nldi, nldj
-! JMM + SM: ugly patch before getting the new version of lib_mpp)
-!                  IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
-                  IF( llnoov .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
-                  ! we do not read the overlap and the extra-halos -> from nldi to nlei and from nldj to nlej 
-! JMM + SM: ugly patch before getting the new version of lib_mpp)
-!                  icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
-                  IF( llnoov ) THEN   ;   icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
-                  ELSE                ;   icnt(1:2) = (/ nlci           , nlcj            /)
-                  ENDIF
-                  IF( PRESENT(pv_r3d) ) THEN
-                     IF( idom == jpdom_data ) THEN   ; icnt(3) = jpkdta
-                     ELSE                            ; icnt(3) = jpk
-                     ENDIF
-                  ENDIF
-               ENDIF
-            ENDIF
-         ENDIF
-
-         ! check that istart and icnt can be used with this file
-         !-
-         DO jl = 1, jpmax_dims
-            itmp = istart(jl)+icnt(jl)-1
-            IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
-               WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp
-               WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)"         ) jl, idimsz(jl)
-               CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 )     
-            ENDIF
-         END DO
-
-         ! check that icnt matches the input array
-         !-     
-         IF( idom == jpdom_unknown ) THEN
-            IF( irankpv == 1 )        ishape(1:1) = SHAPE(pv_r1d)
-            IF( irankpv == 2 )        ishape(1:2) = SHAPE(pv_r2d)
-            IF( irankpv == 3 )        ishape(1:3) = SHAPE(pv_r3d)
-            ctmp1 = 'd'
-         ELSE
-            IF( irankpv == 2 ) THEN
-! JMM + SM: ugly patch before getting the new version of lib_mpp)
-!               ishape(1:2) = SHAPE(pv_r2d(nldi:nlei,nldj:nlej  ))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej)'
-               IF( llnoov ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej  )) ; ctmp1='d(nldi:nlei,nldj:nlej)'
-               ELSE              ; ishape(1:2)=SHAPE(pv_r2d(1   :nlci,1   :nlcj  )) ; ctmp1='d(1:nlci,1:nlcj)'
-               ENDIF
-            ENDIF
-            IF( irankpv == 3 ) THEN 
-! JMM + SM: ugly patch before getting the new version of lib_mpp)
-!               ishape(1:3) = SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej,:)'
-               IF( llnoov ) THEN ; ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1='d(nldi:nlei,nldj:nlej,:)'
-               ELSE              ; ishape(1:3)=SHAPE(pv_r3d(1   :nlci,1   :nlcj,:)) ; ctmp1='d(1:nlci,1:nlcj,:)'
-               ENDIF
-            ENDIF
-         ENDIF
-         
-         DO jl = 1, irankpv
-            WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl)
-            IF( ishape(jl) /= icnt(jl) )   CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) )
-         END DO
-
-      ENDIF
-
-      ! read the data
-      !-     
-      IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point...
-         !
-         ! find the right index of the array to be read
-! JMM + SM: ugly patch before getting the new version of lib_mpp)
-!         IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
-!         ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
-!         ENDIF
-         IF( llnoov ) THEN
-            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
-            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
-            ENDIF
-         ELSE
-            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = 1      ;   ix2 = nlci      ;   iy1 = 1      ;   iy2 = nlcj
-            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
-            ENDIF
-         ENDIF
-      
-         SELECT CASE (iom_file(kiomid)%iolib)
-         CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
-            &                                         pv_r1d, pv_r2d, pv_r3d )
-         CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
-            &                                         pv_r1d, pv_r2d, pv_r3d )
-         CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idom, idvar, ix1, ix2, iy1, iy2,   &
-            &                                         pv_r1d, pv_r2d, pv_r3d )
-         CASE DEFAULT    
-            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-         END SELECT
-
-         IF( istop == nstop ) THEN   ! no additional errors until this point...
-            IF(lwp) WRITE(numout,"(10x,' read ',a,' (rec: ',i4,') in ',a,' ok')") TRIM(cdvar), itime, TRIM(iom_file(kiomid)%name)
-          
-            !--- overlap areas and extra hallows (mpp)
-            IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN
-               CALL lbc_lnk( pv_r2d,'Z',-999.,'no0' )
-            ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
-               ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
-               IF( icnt(3) == jpk ) THEN
-                  CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
-               ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
-                  DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO
-                  DO ji = nlci+1, jpi   ;   pv_r3d(ji    , : , :) = pv_r3d(nlei  , :   , :)   ;   END DO
-               ENDIF
-            ENDIF
-            
-            !--- Apply scale_factor and offset
-            zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
-            zofs = iom_file(kiomid)%ofs(idvar)      ! offset
-            IF(     PRESENT(pv_r1d) ) THEN
-               IF( zscf /= 1. )   pv_r1d(:) = pv_r1d(:) * zscf 
-               IF( zofs /= 0. )   pv_r1d(:) = pv_r1d(:) + zofs
-            ELSEIF( PRESENT(pv_r2d) ) THEN
-!CDIR COLLAPSE
-               IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
-!CDIR COLLAPSE
-               IF( zofs /= 0.)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
-            ELSEIF( PRESENT(pv_r3d) ) THEN
-!CDIR COLLAPSE
-               IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
-!CDIR COLLAPSE
-               IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
-            ENDIF
-            !
-         ENDIF
-         !
-      ENDIF
-      !
-   END SUBROUTINE iom_get_123d
-
-
-   SUBROUTINE iom_gettime( kiomid, ptime, cdvar, kntime, cdunits, cdcalendar )
-      !!--------------------------------------------------------------------
-      !!                   ***  SUBROUTINE iom_gettime  ***
-      !!
-      !! ** Purpose : read the time axis cdvar in the file 
-      !!--------------------------------------------------------------------
-      INTEGER                    , INTENT(in   ) ::   kiomid     ! file Identifier
-      REAL(wp), DIMENSION(:)     , INTENT(  out) ::   ptime      ! the time axis
-      CHARACTER(len=*), OPTIONAL , INTENT(in   ) ::   cdvar      ! time axis name
-      INTEGER         , OPTIONAL , INTENT(  out) ::   kntime     ! number of times in file
-      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdunits    ! units attribute of time coordinate
-      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdcalendar ! calendar attribute of 
-      !
-      INTEGER, DIMENSION(1) :: kdimsz
-      INTEGER            ::   idvar    ! id of the variable
-      CHARACTER(LEN=32)  ::   tname    ! local name of time coordinate
-      CHARACTER(LEN=100) ::   clinfo   ! info character
-      !---------------------------------------------------------------------
-      !
-      IF ( PRESENT(cdvar) ) THEN
-         tname = cdvar
-      ELSE
-         tname = iom_file(kiomid)%uldname
-      ENDIF
-      IF( kiomid > 0 ) THEN
-         clinfo = 'iom_gettime, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(tname)
-         IF ( PRESENT(kntime) ) THEN
-            idvar  = iom_varid( kiomid, tname, kdimsz = kdimsz )
-            kntime = kdimsz(1)
-         ELSE
-            idvar = iom_varid( kiomid, tname )
-         ENDIF
-         !
-         ptime(:) = 0. ! default definition
-         IF( idvar > 0 ) THEN
-            IF( iom_file(kiomid)%ndims(idvar) == 1 ) THEN
-               IF( iom_file(kiomid)%luld(idvar) ) THEN
-                  IF( iom_file(kiomid)%dimsz(1,idvar) <= size(ptime) ) THEN
-                     SELECT CASE (iom_file(kiomid)%iolib)
-                     CASE (jpioipsl )   ;   CALL iom_ioipsl_gettime( kiomid, idvar, ptime, cdunits, cdcalendar )
-                     CASE (jpnf90   )   ;   CALL iom_nf90_gettime(   kiomid, idvar, ptime, cdunits, cdcalendar )
-                     CASE (jprstdimg)   ;   CALL ctl_stop( TRIM(clinfo)//' case IO library == jprstdimg not coded...' )
-                     CASE DEFAULT    
-                        CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-                     END SELECT
-                  ELSE
-                     WRITE(ctmp1,*) 'error with the size of ptime ',size(ptime),iom_file(kiomid)%dimsz(1,idvar)
-                     CALL ctl_stop( trim(clinfo), trim(ctmp1) )
-                  ENDIF
-               ELSE
-                  CALL ctl_stop( trim(clinfo), 'variable dimension is not unlimited... use iom_get' )
-               ENDIF
-            ELSE
-               CALL ctl_stop( trim(clinfo), 'the variable has more than 1 dimension' )
-            ENDIF
-         ELSE
-            CALL ctl_stop( trim(clinfo), 'variable not found in '//iom_file(kiomid)%name )
-         ENDIF
-      ENDIF
-      !
-   END SUBROUTINE iom_gettime
-
-
-   !!----------------------------------------------------------------------
-   !!                   INTERFACE iom_getatt
-   !!----------------------------------------------------------------------
-   SUBROUTINE iom_g0d_intatt( kiomid, cdatt, pvar )
-      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
-      CHARACTER(len=*), INTENT(in   )                 ::   cdatt     ! Name of the attribute
-      INTEGER         , INTENT(  out)                 ::   pvar      ! read field
-      !
-      IF( kiomid > 0 ) THEN
-         IF( iom_file(kiomid)%nfid > 0 ) THEN
-            SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpioipsl )   ;   CALL ctl_stop('iom_getatt: only nf90 available')
-            CASE (jpnf90   )   ;   CALL iom_nf90_getatt( kiomid, cdatt, pvar )
-            CASE (jprstdimg)   ;   CALL ctl_stop('iom_getatt: only nf90 available')
-            CASE DEFAULT    
-               CALL ctl_stop( 'iom_g0d_att: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-            END SELECT
-         ENDIF
-      ENDIF
-   END SUBROUTINE iom_g0d_intatt
-
-
-   !!----------------------------------------------------------------------
-   !!                   INTERFACE iom_rstput
-   !!----------------------------------------------------------------------
-   SUBROUTINE iom_rp0d( kt, kwrite, kiomid, cdvar, pvar, ktype )
-      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
-      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
-      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file 
-      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
-      REAL(wp)        , INTENT(in)                         ::   pvar     ! written field
-      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
-      INTEGER :: ivid   ! variable id
-      IF( kiomid > 0 ) THEN
-         IF( iom_file(kiomid)%nfid > 0 ) THEN
-            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
-            SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
-            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
-            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pvar )
-            CASE DEFAULT     
-               CALL ctl_stop( 'iom_rp0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-            END SELECT
-         ENDIF
-      ENDIF
-   END SUBROUTINE iom_rp0d
-
-   SUBROUTINE iom_rp1d( kt, kwrite, kiomid, cdvar, pvar, ktype )
-      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
-      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
-      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file 
-      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
-      REAL(wp)        , INTENT(in), DIMENSION(          :) ::   pvar     ! written field
-      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
-      INTEGER :: ivid   ! variable id
-      IF( kiomid > 0 ) THEN
-         IF( iom_file(kiomid)%nfid > 0 ) THEN
-            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
-            SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
-            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
-            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r1d = pvar )
-            CASE DEFAULT     
-               CALL ctl_stop( 'iom_rp1d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-            END SELECT
-         ENDIF
-      ENDIF
-   END SUBROUTINE iom_rp1d
-
-   SUBROUTINE iom_rp2d( kt, kwrite, kiomid, cdvar, pvar, ktype )
-      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
-      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
-      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file 
-      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
-      REAL(wp)        , INTENT(in), DIMENSION(:,    :    ) ::   pvar     ! written field
-      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
-      INTEGER :: ivid   ! variable id
-      IF( kiomid > 0 ) THEN
-         IF( iom_file(kiomid)%nfid > 0 ) THEN
-            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
-            SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
-            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
-            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r2d = pvar ) 
-            CASE DEFAULT     
-               CALL ctl_stop( 'iom_rp2d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
-            END SELECT
-         ENDIF
-      ENDIF
-   END SUBROUTINE iom_rp2d
-
-   SUBROUTINE iom_rp3d( kt, kwrite, kiomid, cdvar, pvar, ktype )
-      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
-      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
-      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file 
-      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
-      REAL(wp)        , INTENT(in),       DIMENSION(:,:,:) ::   pvar     ! written field
-      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
-      INTEGER :: ivid   ! variable id
-      IF( kiomid > 0 ) THEN
-         IF( iom_file(kiomid)%nfid > 0 ) THEN
-            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
-            SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
-            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
-            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r3d = pvar )
-            CASE DEFAULT     
-               CALL ctl_stop( 'iom_rp3d: accepted IO library are only jpioipsl and jprstdimg' )
-            END SELECT
-         ENDIF
-      ENDIF
-   END SUBROUTINE iom_rp3d
-
-
-   !!----------------------------------------------------------------------
-   !!                   INTERFACE iom_put
-   !!----------------------------------------------------------------------
-   SUBROUTINE iom_p0d( cdname, pfield0d )
-      CHARACTER(LEN=*), INTENT(in) ::   cdname
-      REAL(wp)        , INTENT(in) ::   pfield0d
-      IF( nn_timing == 1 )  CALL timing_start('iom_put0')
-#if defined key_iomput
-      CALL event__write_field2D( cdname, RESHAPE( (/pfield0d/), (/1,1/) ) )
-#else
-      IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
-#endif
-      IF( nn_timing == 1 )  CALL timing_stop('iom_put0')
-   END SUBROUTINE iom_p0d
-
-   SUBROUTINE iom_p1d( cdname, pfield1d )
-      CHARACTER(LEN=*)          , INTENT(in) ::   cdname
-      REAL(wp),     DIMENSION(:), INTENT(in) ::   pfield1d
-      INTEGER :: jpz
-      IF( nn_timing == 1 )  CALL timing_start('iom_put1')
-#if defined key_iomput
-      jpz=SIZE(pfield1d)
-      CALL event__write_field3D( cdname, RESHAPE( (/pfield1d/), (/1,1,jpz/) ) )
-#else
-      IF( .FALSE. )   WRITE(numout,*) cdname, pfield1d   ! useless test to avoid compilation warnings
-#endif
-      IF( nn_timing == 1 )  CALL timing_stop('iom_put1')
-   END SUBROUTINE iom_p1d
-
-   SUBROUTINE iom_p2d( cdname, pfield2d )
-      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
-      REAL(wp),     DIMENSION(:,:), INTENT(in) ::   pfield2d
-      IF( nn_timing == 1 )  CALL timing_start('iom_put2')
-#if defined key_iomput
-      CALL event__write_field2D( cdname, pfield2d(nldi:nlei, nldj:nlej) )
-#else
-      IF( .FALSE. )   WRITE(numout,*) cdname, pfield2d   ! useless test to avoid compilation warnings
-#endif
-      IF( nn_timing == 1 )  CALL timing_stop('iom_put2')
-   END SUBROUTINE iom_p2d
-
-   SUBROUTINE iom_p3d( cdname, pfield3d )
-      CHARACTER(LEN=*)                , INTENT(in) ::   cdname
-      REAL(wp),       DIMENSION(:,:,:), INTENT(in) ::   pfield3d
-      IF( nn_timing == 1 )  CALL timing_start('iom_put3')
-#if defined key_iomput
-      CALL event__write_field3D( cdname, pfield3d(nldi:nlei, nldj:nlej, :) )
-#else
-      IF( .FALSE. )   WRITE(numout,*) cdname, pfield3d   ! useless test to avoid compilation warnings
-#endif
-      IF( nn_timing == 1 )  CALL timing_stop('iom_put3')
-   END SUBROUTINE iom_p3d
-   !!----------------------------------------------------------------------
-
-
-#if defined key_iomput
-
-   SUBROUTINE set_grid( cdname, plon, plat )
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE   ***
-      !!
-      !! ** Purpose :   define horizontal grids
-      !!
-      !!----------------------------------------------------------------------
-      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plon
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat
-
-      CALL event__set_grid_dimension( cdname, jpiglo, jpjglo)
-      CALL event__set_grid_domain( cdname, nlei-nldi+1, nlej-nldj+1, nimpp+nldi-1, njmpp+nldj-1, &
-         &                         plon(nldi:nlei, nldj:nlej), plat(nldi:nlei, nldj:nlej) )
-      CALL event__set_grid_type_nemo( cdname )
-
-   END SUBROUTINE set_grid
-
-
-   SUBROUTINE set_scalar
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE   ***
-      !!
-      !! ** Purpose :   define fake grids for scalar point
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(1,1) ::   zz = 1.
-      !!----------------------------------------------------------------------
-      CALL event__set_grid_dimension( 'scalarpoint', jpnij, 1)
-      CALL event__set_grid_domain   ( 'scalarpoint', 1, 1, narea, 1, zz, zz )
-      CALL event__set_grid_type_nemo( 'scalarpoint' )
-
-   END SUBROUTINE set_scalar
-
-
-   SUBROUTINE set_xmlatt
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE   ***
-      !!
-      !! ** Purpose :   automatic definitions of some of the xml attributs...
-      !!
-      !!----------------------------------------------------------------------
-      CHARACTER(len=6),DIMENSION( 8) ::   clsuff                   ! suffix name
-      CHARACTER(len=1),DIMENSION( 3) ::   clgrd                    ! suffix name
-      CHARACTER(len=50)              ::   clname                   ! file name
-      CHARACTER(len=1)               ::   cl1                      ! 1 character
-      CHARACTER(len=2)               ::   cl2                      ! 1 character
-      INTEGER                        ::   idt                      ! time-step in seconds
-      INTEGER                        ::   iddss, ihhss             ! number of seconds in 1 day, 1 hour and 1 year
-      INTEGER                        ::   iyymo                    ! number of months in 1 year
-      INTEGER                        ::   jg, jh, jd, jm, jy       ! loop counters
-      INTEGER                        ::   ix, iy                   ! i-,j- index
-      REAL(wp)        ,DIMENSION(11) ::   zlontao                  ! longitudes of tao    moorings
-      REAL(wp)        ,DIMENSION( 7) ::   zlattao                  ! latitudes  of tao    moorings
-      REAL(wp)        ,DIMENSION( 4) ::   zlonrama                 ! longitudes of rama   moorings
-      REAL(wp)        ,DIMENSION(11) ::   zlatrama                 ! latitudes  of rama   moorings
-      REAL(wp)        ,DIMENSION( 3) ::   zlonpira                 ! longitudes of pirata moorings
-      REAL(wp)        ,DIMENSION( 9) ::   zlatpira                 ! latitudes  of pirata moorings
-      !!----------------------------------------------------------------------
-      ! 
-      idt   = NINT( rdttra(1)     )
-      iddss = NINT( rday          )                                         ! number of seconds in 1 day
-      ihhss = NINT( rmmss * rhhmm )                                         ! number of seconds in 1 hour
-      iyymo = NINT( raamo         )                                         ! number of months in 1 year
-
-      ! frequency of the call of iom_put (attribut: freq_op)
-      CALL event__set_attribut( 'field_definition', attr( field__freq_op, idt           ) )    ! model time-step
-      CALL event__set_attribut( 'SBC'             , attr( field__freq_op, idt * nn_fsbc ) )    ! SBC time-step
- !SF 
-      CALL event__set_attribut( 'scalar_SBC'      , attr( field__freq_op, idt * nn_fsbc ) )    ! SBC time-step
-      
-      ! output file names (attribut: name)
-      clsuff(:) = (/ 'grid_T', 'grid_U', 'grid_V', 'grid_W', 'icemod', 'ptrc_T', 'diad_T', 'scalar' /)      
-      DO jg = 1, SIZE(clsuff)                                                                  ! grid type
-         DO jh = 1, 12                                                                         ! 1, 2, 3, 4, 6, 12 hours
-            IF( MOD(12,jh) == 0 ) THEN 
-               WRITE(cl2,'(i2)') jh 
-               CALL dia_nam( clname, jh * ihhss, clsuff(jg), ldfsec = .TRUE. )
-               CALL event__set_attribut( TRIM(ADJUSTL(cl2))//'h_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
-            ENDIF
-         END DO
-         DO jd = 1, 5, 2                                                                       ! 1, 3, 5 days
-            WRITE(cl1,'(i1)') jd 
-            CALL dia_nam( clname, jd * iddss, clsuff(jg), ldfsec = .TRUE. )
-            CALL event__set_attribut( cl1//'d_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
-         END DO
-         DO jm = 1, 6                                                                          ! 1, 2, 3, 4, 6 months
-            IF( MOD(6,jm) == 0 ) THEN 
-               WRITE(cl1,'(i1)') jm 
-               CALL dia_nam( clname, -jm, clsuff(jg) )
-               CALL event__set_attribut( cl1//'m_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
-            ENDIF
-         END DO
-         DO jy = 1, 10                                                                         ! 1, 2, 5, 10 years  
-            IF( MOD(10,jy) == 0 ) THEN 
-               WRITE(cl2,'(i2)') jy 
-               CALL dia_nam( clname, -jy * iyymo, clsuff(jg) )
-               CALL event__set_attribut( TRIM(ADJUSTL(cl2))//'y_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
-            ENDIF
-         END DO
-      END DO
-
-      ! Zooms...
-      clgrd = (/ 'T', 'U', 'W' /) 
-      DO jg = 1, SIZE(clgrd)                                                                   ! grid type
-         cl1 = clgrd(jg)
-         ! Equatorial section (attributs: jbegin, ni, name_suffix)
-         CALL dom_ngb( 0., 0., ix, iy, cl1 )
-         CALL event__set_attribut( 'Eq'//cl1, attr( zoom__jbegin     , iy     ) )
-         CALL event__set_attribut( 'Eq'//cl1, attr( zoom__ni         , jpiglo ) )
-         CALL event__set_attribut( 'Eq'//cl1, attr( file__name_suffix, '_Eq'  ) )
-      END DO
-      ! TAO moorings (attributs: ibegin, jbegin, name_suffix)
-      zlontao = (/ 137.0, 147.0, 156.0, 165.0, -180.0, -170.0, -155.0, -140.0, -125.0, -110.0, -95.0 /)
-      zlattao = (/  -8.0,  -5.0,  -2.0,   0.0,    2.0,    5.0,    8.0 /)
-      CALL set_mooring( zlontao, zlattao )
-      ! RAMA moorings (attributs: ibegin, jbegin, name_suffix)
-      zlonrama = (/  55.0,  67.0, 80.5, 90.0 /)
-      zlatrama = (/ -16.0, -12.0, -8.0, -4.0, -1.5, 0.0, 1.5, 4.0, 8.0, 12.0, 15.0 /)
-      CALL set_mooring( zlonrama, zlatrama )
-      ! PIRATA moorings (attributs: ibegin, jbegin, name_suffix)
-      zlonpira = (/ -38.0, -23.0, -10.0 /)
-      zlatpira = (/ -19.0, -14.0,  -8.0, 0.0, 4.0, 8.0, 12.0, 15.0, 20.0 /)
-      CALL set_mooring( zlonpira, zlatpira )
-      
-   END SUBROUTINE set_xmlatt
-
-
-   SUBROUTINE set_mooring( plon, plat)
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE   ***
-      !!
-      !! ** Purpose :   automatic definitions of moorings xml attributs...
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:), INTENT(in) ::  plon, plat           ! longitudes/latitudes oft the mooring
-      !
-!!$      CHARACTER(len=1),DIMENSION(4) ::   clgrd = (/ 'T', 'U', 'V', 'W' /)   ! suffix name
-      CHARACTER(len=1),DIMENSION(1) ::   clgrd = (/ 'T' /)        ! suffix name
-      CHARACTER(len=50)             ::   clname                   ! file name
-      CHARACTER(len=1)              ::   cl1                      ! 1 character
-      CHARACTER(len=6)              ::   clon,clat                ! name of longitude, latitude
-      INTEGER                       ::   ji, jj, jg               ! loop counters
-      INTEGER                       ::   ix, iy                   ! i-,j- index
-      REAL(wp)                      ::   zlon, zlat
-      !!----------------------------------------------------------------------
-      DO jg = 1, SIZE(clgrd)
-         cl1 = clgrd(jg)
-         DO ji = 1, SIZE(plon)
-            DO jj = 1, SIZE(plat)
-               zlon = plon(ji)
-               zlat = plat(jj)
-               ! modifications for RAMA moorings
-               IF( zlon ==  67. .AND. zlat ==  15. )   zlon =  65.
-               IF( zlon ==  90. .AND. zlat <=  -4. )   zlon =  95.
-               IF( zlon ==  95. .AND. zlat ==  -4. )   zlat =  -5.
-               ! modifications for PIRATA moorings
-               IF( zlon == -38. .AND. zlat == -19. )   zlon = -34.
-               IF( zlon == -38. .AND. zlat == -14. )   zlon = -32.
-               IF( zlon == -38. .AND. zlat ==  -8. )   zlon = -30.
-               IF( zlon == -38. .AND. zlat ==   0. )   zlon = -35.
-               IF( zlon == -23. .AND. zlat ==  20. )   zlat =  21.
-               IF( zlon == -10. .AND. zlat == -14. )   zlat = -10.
-               IF( zlon == -10. .AND. zlat ==  -8. )   zlat =  -6.
-               IF( zlon == -10. .AND. zlat ==   4. ) THEN   ;   zlon = 0.   ;   zlat = 0.   ;   ENDIF
-               CALL dom_ngb( zlon, zlat, ix, iy, cl1 )
-               IF( zlon >= 0. ) THEN  
-                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT( zlon), 'e'
-                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')       zlon , 'e'
-                  ENDIF
-               ELSE             
-                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT(-zlon), 'w'
-                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')      -zlon , 'w'
-                  ENDIF
-               ENDIF
-               IF( zlat >= 0. ) THEN  
-                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT( zlat), 'n'
-                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')       zlat , 'n'
-                  ENDIF
-               ELSE             
-                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT(-zlat), 's'
-                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')      -zlat , 's'
-                  ENDIF
-               ENDIF
-               clname = TRIM(ADJUSTL(clat))//TRIM(ADJUSTL(clon))
-               CALL event__set_attribut( TRIM(clname)//cl1, attr( zoom__ibegin     , ix                ) )
-               CALL event__set_attribut( TRIM(clname)//cl1, attr( zoom__jbegin     , iy                ) )
-               CALL event__set_attribut( TRIM(clname)//cl1, attr( file__name_suffix, '_'//TRIM(clname) ) )      
-            END DO
-         END DO
-      END DO
-      
-   END SUBROUTINE set_mooring
-
-#else
-
-   SUBROUTINE iom_setkt( kt )
-      INTEGER, INTENT(in   )::   kt 
-      IF( .FALSE. )   WRITE(numout,*) kt   ! useless test to avoid compilation warnings
-   END SUBROUTINE iom_setkt
-
-#endif
-
-
-   !!======================================================================
-END MODULE iom
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/iom_nf90.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/iom_nf90.F90	(revision 3937)
+++ 	(revision )
@@ -1,579 +1,0 @@
-MODULE iom_nf90
-   !!=====================================================================
-   !!                    ***  MODULE  iom_nf90 ***
-   !! Input/Output manager :  Library to read input files with NF90 (only fliocom module)
-   !!====================================================================
-   !! History :  9.0  ! 05 12  (J. Belier) Original code
-   !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
-   !!             "   ! 07 07  (D. Storkey) Changes to iom_nf90_gettime
-   !!--------------------------------------------------------------------
-   !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
-
-   !!--------------------------------------------------------------------
-   !!   iom_open       : open a file read only
-   !!   iom_close      : close a file or all files opened by iom
-   !!   iom_get        : read a field (interfaced to several routines)
-   !!   iom_gettime    : read the time axis kvid in the file
-   !!   iom_varid      : get the id of a variable in a file
-   !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
-   !!--------------------------------------------------------------------
-   USE dom_oce         ! ocean space and time domain
-   USE lbclnk          ! lateal boundary condition / mpp exchanges
-   USE iom_def         ! iom variables definitions
-   USE netcdf          ! NetCDF library
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! MPP library
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC iom_nf90_open, iom_nf90_close, iom_nf90_varid, iom_nf90_get, iom_nf90_gettime, iom_nf90_rstput
-   PUBLIC iom_nf90_getatt
-
-   INTERFACE iom_nf90_get
-      MODULE PROCEDURE iom_nf90_g0d, iom_nf90_g123d
-   END INTERFACE
-   INTERFACE iom_nf90_getatt
-      MODULE PROCEDURE iom_nf90_intatt
-   END INTERFACE
-   INTERFACE iom_nf90_rstput
-      MODULE PROCEDURE iom_nf90_rp0123d
-   END INTERFACE
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: iom_nf90.F90 2715 2011-03-30 15:58:35Z rblod $
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE iom_nf90_open( cdname, kiomid, ldwrt, ldok, kdompar )
-      !!---------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_open  ***
-      !!
-      !! ** Purpose : open an input file with NF90
-      !!---------------------------------------------------------------------
-      CHARACTER(len=*)       , INTENT(inout)           ::   cdname      ! File name
-      INTEGER                , INTENT(  out)           ::   kiomid      ! nf90 identifier of the opened file
-      LOGICAL                , INTENT(in   )           ::   ldwrt       ! read or write the file?
-      LOGICAL                , INTENT(in   )           ::   ldok        ! check the existence 
-      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar     ! domain parameters: 
-
-      CHARACTER(LEN=100) ::   clinfo           ! info character
-      CHARACTER(LEN=100) ::   cltmp            ! temporary character
-      INTEGER            ::   iln              ! lengths of character
-      INTEGER            ::   istop            ! temporary storage of nstop
-      INTEGER            ::   if90id           ! nf90 identifier of the opened file
-      INTEGER            ::   idmy             ! dummy variable
-      INTEGER            ::   jl               ! loop variable
-      INTEGER            ::   ichunk           ! temporary storage of nn_chunksz
-      INTEGER            ::   imode            ! creation mode flag: NF90_CLOBBER or NF90_NOCLOBBER or NF90_HDF5
-      INTEGER            ::   ihdf5            ! local variable for retrieval of value for NF90_HDF5
-      LOGICAL            ::   llclobber        ! local definition of ln_clobber
-      !---------------------------------------------------------------------
-
-      clinfo = '                    iom_nf90_open ~~~  '
-      istop = nstop   ! store the actual value of nstop
-      IF( nn_chunksz > 0 ) THEN   ;   ichunk = nn_chunksz
-      ELSE                        ;   ichunk = NF90_SIZEHINT_DEFAULT
-      ENDIF
-      !
-      llclobber = ldwrt .AND. ln_clobber
-      IF( ldok .AND. .NOT. llclobber ) THEN      ! Open existing file...
-         !                 ! =============
-         IF( ldwrt ) THEN  ! ... in write mode
-            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in WRITE mode'
-            IF( snc4set%luse ) THEN
-               CALL iom_nf90_check(NF90_OPEN( TRIM(cdname), NF90_WRITE  , if90id ), clinfo)
-            ELSE
-               CALL iom_nf90_check(NF90_OPEN( TRIM(cdname), NF90_WRITE  , if90id, chunksize = ichunk ), clinfo)
-            ENDIF
-            CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy                          ), clinfo)
-         ELSE              ! ... in read mode
-            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READ mode'
-            CALL iom_nf90_check(NF90_OPEN( TRIM(cdname), NF90_NOWRITE, if90id, chunksize = ichunk ), clinfo)
-         ENDIF
-      ELSE                                       ! the file does not exist (or we overwrite it)
-         !                 ! =============
-         iln = INDEX( cdname, '.nc' )
-         IF( ldwrt ) THEN  ! the file should be open in write mode so we create it...
-            IF( jpnij > 1 ) THEN
-               WRITE(cltmp,'(a,a,i4.4,a)') cdname(1:iln-1), '_', narea-1, '.nc'
-               cdname = TRIM(cltmp)
-            ENDIF
-            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//TRIM(cdname)//' in WRITE mode'
-
-            IF( llclobber ) THEN   ;   imode = IOR( NF90_64BIT_OFFSET, NF90_CLOBBER   )
-            ELSE                   ;   imode = IOR( NF90_64BIT_OFFSET, NF90_NOCLOBBER ) 
-            ENDIF
-            IF( snc4set%luse ) THEN
-               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' creating file: '//TRIM(cdname)//' in hdf5 (netcdf4) mode'
-               CALL GET_NF90_SYMBOL("NF90_HDF5", ihdf5)
-               IF( llclobber ) THEN   ;   imode = IOR(ihdf5, NF90_CLOBBER)
-               ELSE                   ;   imode = IOR(ihdf5, NF90_NOCLOBBER)
-               ENDIF
-               CALL iom_nf90_check(NF90_CREATE( TRIM(cdname), imode, if90id ), clinfo)
-            ELSE
-               CALL iom_nf90_check(NF90_CREATE( TRIM(cdname), imode, if90id, chunksize = ichunk ), clinfo)
-            ENDIF
-            CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy                     ), clinfo)
-            ! define dimensions
-            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'x', kdompar(1,1)  , idmy ), clinfo)
-            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'y', kdompar(2,1)  , idmy ), clinfo)
-            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'z', jpk           , idmy ), clinfo)
-            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 't', NF90_UNLIMITED, idmy ), clinfo)
-            ! global attributes
-            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_number_total'   , jpnij              ), clinfo)
-            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_number'         , narea-1            ), clinfo)
-            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_dimensions_ids' , (/1     , 2     /) ), clinfo)
-            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_size_global'    , (/jpiglo, jpjglo/) ), clinfo)
-            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_size_local'     , kdompar(:,1)       ), clinfo)
-            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_position_first' , kdompar(:,2)       ), clinfo)
-            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_position_last'  , kdompar(:,3)       ), clinfo)
-            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_halo_size_start', kdompar(:,4)       ), clinfo)
-            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_halo_size_end'  , kdompar(:,5)       ), clinfo)
-            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_type'           , 'BOX'              ), clinfo)
-         ELSE              ! the file should be open for read mode so it must exist...
-            CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
-         ENDIF
-      ENDIF
-      ! start to fill file informations
-      ! =============
-      IF( istop == nstop ) THEN   ! no error within this routine
-!does not work with some compilers         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
-         kiomid = 0
-         DO jl = jpmax_files, 1, -1
-            IF( iom_file(jl)%nfid == 0 )   kiomid = jl
-         ENDDO
-         iom_file(kiomid)%name   = TRIM(cdname)
-         iom_file(kiomid)%nfid   = if90id
-         iom_file(kiomid)%iolib  = jpnf90
-         iom_file(kiomid)%nvars  = 0
-         iom_file(kiomid)%irec   = -1   ! useless for NetCDF files, used to know if the file is in define mode 
-         CALL iom_nf90_check(NF90_Inquire(if90id, unlimitedDimId = iom_file(kiomid)%iduld), clinfo)
-         IF ( iom_file(kiomid)%iduld .GE. 0 ) THEN
-           CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, iom_file(kiomid)%iduld,   &
-        &                                               name = iom_file(kiomid)%uldname), clinfo)
-         ENDIF
-         IF(lwp) WRITE(numout,*) '                   ---> '//TRIM(cdname)//' OK'
-      ELSE
-         kiomid = 0               ! return error flag
-      ENDIF
-      !
-   END SUBROUTINE iom_nf90_open
-
-
-   SUBROUTINE iom_nf90_close( kiomid )
-      !!--------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_nf90_close  ***
-      !!
-      !! ** Purpose : close an input file with NF90
-      !!--------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kiomid   ! iom identifier of the file to be closed
-      CHARACTER(LEN=100)  ::   clinfo   ! info character
-      !---------------------------------------------------------------------
-      !
-      clinfo = '      iom_nf90_close    , file: '//TRIM(iom_file(kiomid)%name)
-      CALL iom_nf90_check(NF90_CLOSE(iom_file(kiomid)%nfid), clinfo)
-      !    
-   END SUBROUTINE iom_nf90_close
-
-
-   FUNCTION iom_nf90_varid ( kiomid, cdvar, kiv, kdimsz, kndims )  
-      !!-----------------------------------------------------------------------
-      !!                  ***  FUNCTION  iom_varid  ***
-      !!
-      !! ** Purpose : get the id of a variable in a file with NF90
-      !!-----------------------------------------------------------------------
-      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
-      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
-      INTEGER              , INTENT(in   )           ::   kiv   ! 
-      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
-      INTEGER,               INTENT(  out), OPTIONAL ::   kndims   ! size of the dimensions
-      !
-      INTEGER                        ::   iom_nf90_varid   ! iom variable Id
-      INTEGER                        ::   if90id           ! nf90 file identifier
-      INTEGER                        ::   ji               ! dummy loop index
-      INTEGER                        ::   ivarid           ! NetCDF  variable Id
-      INTEGER                        ::   i_nvd            ! number of dimension of the variable
-      INTEGER, DIMENSION(jpmax_dims) ::   idimid           ! dimension ids of the variable
-      LOGICAL                        ::   llok             ! ok  test
-      CHARACTER(LEN=100)             ::   clinfo           ! info character
-      !!-----------------------------------------------------------------------
-      clinfo = '          iom_nf90_varid, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar)
-      iom_nf90_varid = 0                    ! default definition
-      IF( PRESENT(kdimsz) ) kdimsz(:) = 0   ! default definition
-      if90id = iom_file(kiomid)%nfid        ! get back NetCDF file id
-      !
-      llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr   ! does the variable exist in the file
-      IF( llok ) THEN
-         iom_nf90_varid = kiv
-         iom_file(kiomid)%nvars       = kiv
-         iom_file(kiomid)%nvid(kiv)   = ivarid
-         iom_file(kiomid)%cn_var(kiv) = TRIM(cdvar)
-         CALL iom_nf90_check(NF90_Inquire_Variable(if90id, ivarid, ndims = i_nvd), clinfo)   ! number of dimensions
-         iom_file(kiomid)%ndims(kiv)  = i_nvd
-         CALL iom_nf90_check(NF90_Inquire_Variable(if90id, ivarid, dimids = idimid(1:i_nvd)), clinfo)   ! dimensions ids
-         iom_file(kiomid)%luld(kiv) = .FALSE.   ! default value
-         DO ji = 1, i_nvd                       ! dimensions size
-            CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, idimid(ji), len = iom_file(kiomid)%dimsz(ji,kiv)), clinfo)   
-            IF( idimid(ji) == iom_file(kiomid)%iduld ) iom_file(kiomid)%luld(kiv) = .TRUE.   ! unlimited dimension? 
-         END DO
-         !---------- Deal with scale_factor and add_offset
-         llok = NF90_Inquire_attribute(if90id, ivarid, 'scale_factor') == nf90_noerr
-         IF( llok) THEN
-            CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, 'scale_factor', iom_file(kiomid)%scf(kiv)), clinfo)
-         ELSE
-            iom_file(kiomid)%scf(kiv) = 1.
-         END IF
-         llok = NF90_Inquire_attribute(if90id, ivarid, 'add_offset') == nf90_noerr
-         IF( llok ) THEN
-            CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, 'add_offset', iom_file(kiomid)%ofs(kiv)), clinfo)
-         ELSE
-            iom_file(kiomid)%ofs(kiv) = 0.
-         END IF
-         ! return the simension size
-         IF( PRESENT(kdimsz) ) THEN 
-            IF( i_nvd == SIZE(kdimsz) ) THEN
-               kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,kiv)
-            ELSE
-               WRITE(ctmp1,*) i_nvd, SIZE(kdimsz)
-               CALL ctl_stop( TRIM(clinfo), 'error in kdimsz size'//TRIM(ctmp1) )
-            ENDIF
-         ENDIF
-         IF( PRESENT(kndims) )  kndims = iom_file(kiomid)%ndims(kiv)
-      ELSE  
-         iom_nf90_varid = -1   !   variable not found, return error code: -1
-      ENDIF
-      !
-   END FUNCTION iom_nf90_varid
-
-
-   SUBROUTINE iom_nf90_g0d( kiomid, kvid, pvar )
-      !!-----------------------------------------------------------------------
-      !!                  ***  ROUTINE  iom_nf90_g0d  ***
-      !!
-      !! ** Purpose : read a scalar with NF90
-      !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in   ) ::   kiomid   ! Identifier of the file
-      INTEGER , INTENT(in   ) ::   kvid     ! variable id
-      REAL(wp), INTENT(  out) ::   pvar     ! read field
-      !
-      CHARACTER(LEN=100)      ::   clinfo   ! info character
-      !---------------------------------------------------------------------
-      clinfo = 'iom_nf90_g0d , file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid))
-      CALL iom_nf90_check(NF90_GET_VAR(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), pvar), clinfo )
-      ! 
-   END SUBROUTINE iom_nf90_g0d
-
-
-   SUBROUTINE iom_nf90_g123d( kiomid, kvid, knbdim, kstart, kcount, kx1, kx2, ky1, ky2,   &
-         &                    pv_r1d, pv_r2d, pv_r3d )
-      !!-----------------------------------------------------------------------
-      !!                  ***  ROUTINE  iom_nf90_g123d  ***
-      !!
-      !! ** Purpose : read a 1D/2D/3D variable with NF90
-      !!
-      !! ** Method : read ONE record at each CALL
-      !!-----------------------------------------------------------------------
-      INTEGER                    , INTENT(in   )           ::   kiomid    ! iom identifier of the file
-      INTEGER                    , INTENT(in   )           ::   kvid      ! Name of the variable
-      INTEGER                    , INTENT(in   )           ::   knbdim    ! number of dimensions of the variable
-      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kstart    ! start position of the reading in each axis 
-      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kcount    ! number of points to be read in each axis
-      INTEGER ,                    INTENT(in   )           ::   kx1, kx2, ky1, ky2   ! subdomain indexes
-      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d    ! read field (1D case)
-      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d    ! read field (2D case)
-      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d    ! read field (3D case)
-      !
-      CHARACTER(LEN=100) ::   clinfo               ! info character
-      INTEGER            ::   if90id               ! nf90 identifier of the opened file
-      INTEGER            ::   ivid                 ! nf90 variable id
-      !---------------------------------------------------------------------
-      clinfo = 'iom_nf90_g123d , file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid))
-      if90id = iom_file(kiomid)%nfid         ! get back NetCDF file id
-      ivid   = iom_file(kiomid)%nvid(kvid)   ! get back NetCDF var id
-      !
-      IF(     PRESENT(pv_r1d) ) THEN
-         CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r1d(:                ), start = kstart(1:knbdim),   &
-            &                                                                       count = kcount(1:knbdim)), clinfo )
-      ELSEIF( PRESENT(pv_r2d) ) THEN
-         CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r2d(kx1:kx2,ky1:ky2  ), start = kstart(1:knbdim),   &
-            &                                                                       count = kcount(1:knbdim)), clinfo )
-      ELSEIF( PRESENT(pv_r3d) ) THEN
-         CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r3d(kx1:kx2,ky1:ky2,:), start = kstart(1:knbdim),   &
-            &                                                                       count = kcount(1:knbdim)), clinfo )
-      ENDIF
-      !
-   END SUBROUTINE iom_nf90_g123d
-
-
-   SUBROUTINE iom_nf90_intatt( kiomid, cdatt, pvar )
-      !!-----------------------------------------------------------------------
-      !!                  ***  ROUTINE  iom_nf90_intatt  ***
-      !!
-      !! ** Purpose : read an integer attribute with NF90
-      !!-----------------------------------------------------------------------
-      INTEGER         , INTENT(in   ) ::   kiomid   ! Identifier of the file
-      CHARACTER(len=*), INTENT(in   ) ::   cdatt    ! attribute name
-      INTEGER         , INTENT(  out) ::   pvar     ! read field
-      !
-      INTEGER                         ::   if90id   ! temporary integer
-      LOGICAL                         ::   llok     ! temporary logical
-      CHARACTER(LEN=100)              ::   clinfo   ! info character
-      !---------------------------------------------------------------------
-      ! 
-      if90id = iom_file(kiomid)%nfid
-      llok = NF90_Inquire_attribute(if90id, NF90_GLOBAL, cdatt) == nf90_noerr
-      IF( llok) THEN
-         clinfo = 'iom_nf90_getatt, file: '//TRIM(iom_file(kiomid)%name)//', att: '//TRIM(cdatt)
-         CALL iom_nf90_check(NF90_GET_ATT(if90id, NF90_GLOBAL, cdatt, values=pvar), clinfo)
-      ELSE
-         CALL ctl_warn('iom_nf90_getatt: no attribute '//cdatt//' found')
-         pvar = -999
-      ENDIF
-      ! 
-   END SUBROUTINE iom_nf90_intatt
-
-
-   SUBROUTINE iom_nf90_gettime( kiomid, kvid, ptime, cdunits, cdcalendar )
-      !!--------------------------------------------------------------------
-      !!                   ***  SUBROUTINE iom_gettime  ***
-      !!
-      !! ** Purpose : read the time axis kvid in the file with NF90
-      !!--------------------------------------------------------------------
-      INTEGER                   , INTENT(in   ) ::   kiomid     ! file Identifier
-      INTEGER                   , INTENT(in   ) ::   kvid       ! variable id
-      REAL(wp), DIMENSION(:)    , INTENT(  out) ::   ptime      ! the time axis
-      CHARACTER(len=*), OPTIONAL, INTENT(  out) ::   cdunits    ! units attribute
-      CHARACTER(len=*), OPTIONAL, INTENT(  out) ::   cdcalendar ! calendar attribute
-      !
-      CHARACTER(LEN=100) ::   clinfo     ! info character
-      !---------------------------------------------------------------------
-      clinfo = 'iom_nf90_gettime, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid))
-      CALL iom_nf90_check(NF90_GET_VAR(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), ptime(:),   &
-            &                           start=(/ 1 /), count=(/ iom_file(kiomid)%dimsz(1, kvid) /)), clinfo)
-      IF ( PRESENT(cdunits) ) THEN 
-         CALL iom_nf90_check(NF90_GET_ATT(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), "units", &
-            &                           values=cdunits), clinfo)
-      ENDIF
-      IF ( PRESENT(cdcalendar) ) THEN 
-         CALL iom_nf90_check(NF90_GET_ATT(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), "calendar", &
-            &                           values=cdcalendar), clinfo)
-      ENDIF
-      !
-   END SUBROUTINE iom_nf90_gettime
-
-
-   SUBROUTINE iom_nf90_rp0123d( kt, kwrite, kiomid, cdvar , kvid  , ktype,   &
-         &                               pv_r0d, pv_r1d, pv_r2d, pv_r3d )
-      !!--------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_nf90_rstput  ***
-      !!
-      !! ** Purpose : read the time axis cdvar in the file 
-      !!--------------------------------------------------------------------
-      INTEGER                     , INTENT(in)           ::   kt       ! ocean time-step
-      INTEGER                     , INTENT(in)           ::   kwrite   ! writing time-step
-      INTEGER                     , INTENT(in)           ::   kiomid   ! Identifier of the file 
-      CHARACTER(len=*)            , INTENT(in)           ::   cdvar    ! variable name
-      INTEGER                     , INTENT(in)           ::   kvid     ! variable id
-      INTEGER                     , INTENT(in), OPTIONAL ::   ktype    ! variable type (default R8)
-      REAL(wp)                    , INTENT(in), OPTIONAL ::   pv_r0d   ! written Od field
-      REAL(wp), DIMENSION(      :), INTENT(in), OPTIONAL ::   pv_r1d   ! written 1d field
-      REAL(wp), DIMENSION(:, :   ), INTENT(in), OPTIONAL ::   pv_r2d   ! written 2d field
-      REAL(wp), DIMENSION(:, :, :), INTENT(in), OPTIONAL ::   pv_r3d   ! written 3d field
-      !
-      INTEGER               :: idims                ! number of dimension
-      INTEGER               :: idvar                ! variable id
-      INTEGER               :: jd                   ! dimension loop counter   
-      INTEGER               :: ix1, ix2, iy1, iy2   ! subdomain indexes   
-      INTEGER, DIMENSION(4) :: idimsz               ! dimensions size  
-      INTEGER, DIMENSION(4) :: idimid               ! dimensions id
-      CHARACTER(LEN=100)    :: clinfo               ! info character
-      CHARACTER(LEN= 12), DIMENSION(4) :: cltmp     ! temporary character
-      INTEGER               :: if90id               ! nf90 file identifier
-      INTEGER               :: idmy                 ! dummy variable
-      INTEGER               :: itype                ! variable type
-      INTEGER, DIMENSION(4) :: ichunksz             ! NetCDF4 chunk sizes. Will be computed using
-                                                    ! nn_nchunks_[i,j,k,t] namelist parameters
-      INTEGER               :: ichunkalg, ishuffle,&
-                               ideflate, ideflate_level
-                                                    ! NetCDF4 internally fixed parameters
-      LOGICAL               :: lchunk               ! logical switch to activate chunking and compression
-                                                    ! when appropriate (currently chunking is applied to 4d fields only)
-      !---------------------------------------------------------------------
-      !
-      clinfo = '          iom_nf90_rp0123d, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar)
-      if90id = iom_file(kiomid)%nfid
-      !
-      ! define dimension variables if it is not already done
-      ! ==========================
-      IF( iom_file(kiomid)%nvars == 0 ) THEN
-         ! are we in define mode?
-         IF( iom_file(kiomid)%irec /= -1 ) THEN   ! trick: irec used to know if the file is in define mode or not
-            CALL iom_nf90_check(NF90_REDEF( if90id ), clinfo)   ;   iom_file(kiomid)%irec = -1
-         ENDIF
-         ! define the dimension variables if it is not already done
-         cltmp = (/ 'nav_lon     ', 'nav_lat     ', 'nav_lev     ', 'time_counter' /)
-         CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(1)), NF90_FLOAT , (/ 1, 2 /), iom_file(kiomid)%nvid(1) ), clinfo)
-         CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(2)), NF90_FLOAT , (/ 1, 2 /), iom_file(kiomid)%nvid(2) ), clinfo)
-         CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(3)), NF90_FLOAT , (/ 3    /), iom_file(kiomid)%nvid(3) ), clinfo)
-         CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(4)), NF90_DOUBLE, (/ 4    /), iom_file(kiomid)%nvid(4) ), clinfo)
-         ! update informations structure related the dimension variable we just added...
-         iom_file(kiomid)%nvars       = 4
-         iom_file(kiomid)%luld(1:4)   = (/ .FALSE., .FALSE., .FALSE., .TRUE. /)
-         iom_file(kiomid)%cn_var(1:4) = cltmp
-         iom_file(kiomid)%ndims(1:4)  = (/ 2, 2, 1, 1 /)  
-         ! trick: defined to 0 to say that dimension variables are defined but not yet written
-         iom_file(kiomid)%dimsz(1, 1)  = 0   
-         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' define dimension variables done'
-      ENDIF
-      ! define the data if it is not already done
-      ! ===============
-      IF( kvid <= 0 ) THEN
-         !
-         ! NetCDF4 chunking and compression fixed settings
-         ichunkalg = 0
-         ishuffle = 1
-         ideflate = 1
-         ideflate_level = 1
-         !
-         idvar = iom_file(kiomid)%nvars + 1
-         ! are we in define mode?
-         IF( iom_file(kiomid)%irec /= -1 ) THEN   ! trick: irec used to know if the file is in define mode or not
-            CALL iom_nf90_check(NF90_REDEF( if90id ), clinfo)   ;   iom_file(kiomid)%irec = -1
-         ENDIF
-         ! variable definition
-         IF(     PRESENT(pv_r0d) ) THEN   ;   idims = 0
-         ELSEIF( PRESENT(pv_r1d) ) THEN   ;   idims = 2   ;   idimid(1:idims) = (/    3,4/)
-         ELSEIF( PRESENT(pv_r2d) ) THEN   ;   idims = 3   ;   idimid(1:idims) = (/1,2  ,4/)
-         ELSEIF( PRESENT(pv_r3d) ) THEN   ;   idims = 4   ;   idimid(1:idims) = (/1,2,3,4/)
-         ENDIF
-         IF( PRESENT(ktype) ) THEN   ! variable external type
-            SELECT CASE (ktype)
-            CASE (jp_r8)  ;   itype = NF90_DOUBLE
-            CASE (jp_r4)  ;   itype = NF90_FLOAT
-            CASE (jp_i4)  ;   itype = NF90_INT
-            CASE (jp_i2)  ;   itype = NF90_SHORT
-            CASE (jp_i1)  ;   itype = NF90_BYTE
-            CASE DEFAULT   ;   CALL ctl_stop( TRIM(clinfo)//' unknown variable type' )
-            END SELECT
-         ELSE
-            itype = NF90_DOUBLE
-         ENDIF
-         IF( PRESENT(pv_r0d) ) THEN
-            CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cdvar), itype,                    &
-                 &                            iom_file(kiomid)%nvid(idvar) ), clinfo)
-         ELSE
-            CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cdvar), itype, idimid(1:idims),   &
-                 &                            iom_file(kiomid)%nvid(idvar) ), clinfo)
-         ENDIF
-         lchunk = .false.
-         IF( snc4set%luse .AND. idims.eq.4 ) lchunk = .true.
-         ! update informations structure related the new variable we want to add...
-         iom_file(kiomid)%nvars         = idvar
-         iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar)
-         iom_file(kiomid)%scf(idvar)    = 1.
-         iom_file(kiomid)%ofs(idvar)    = 0.
-         iom_file(kiomid)%ndims(idvar)  = idims
-         IF( .NOT. PRESENT(pv_r0d) ) THEN   ;   iom_file(kiomid)%luld(idvar) = .TRUE.
-         ELSE                               ;   iom_file(kiomid)%luld(idvar) = .FALSE.
-         ENDIF
-         DO jd = 1, idims
-            CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, idimid(jd), len = iom_file(kiomid)%dimsz(jd,idvar) ), clinfo)
-            IF ( lchunk ) ichunksz(jd) = iom_file(kiomid)%dimsz(jd,idvar)
-         END DO
-         IF ( lchunk ) THEN
-            ! Calculate chunk sizes by partitioning each dimension as requested in namnc4 namelist
-            ! Disallow very small chunk sizes and prevent chunk sizes larger than each individual dimension
-            ichunksz(1) = MIN( ichunksz(1),MAX( (ichunksz(1)-1)/snc4set%ni + 1 ,16 ) ) ! Suggested default nc4set%ni=4
-            ichunksz(2) = MIN( ichunksz(2),MAX( (ichunksz(2)-1)/snc4set%nj + 1 ,16 ) ) ! Suggested default nc4set%nj=2
-            ichunksz(3) = MIN( ichunksz(3),MAX( (ichunksz(3)-1)/snc4set%nk + 1 , 1 ) ) ! Suggested default nc4set%nk=6
-            ichunksz(4) = 1                                                            ! Do not allow chunks to span the
-                                                                                       ! unlimited dimension
-            CALL iom_nf90_check(SET_NF90_DEF_VAR_CHUNKING(if90id, idvar, ichunkalg, ichunksz), clinfo)
-            CALL iom_nf90_check(SET_NF90_DEF_VAR_DEFLATE(if90id, idvar, ishuffle, ideflate, ideflate_level), clinfo)
-            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' chunked ok. Chunks sizes: ', ichunksz
-         ENDIF
-         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' defined ok'
-      ELSE
-         idvar = kvid
-      ENDIF
-
-      ! time step kwrite : write the variable
-      IF( kt == kwrite ) THEN
-         ! are we in write mode?
-         IF( iom_file(kiomid)%irec == -1 ) THEN   ! trick: irec used to know if the file is in define mode or not
-            CALL iom_nf90_check(NF90_ENDDEF( if90id ), clinfo)   ;   iom_file(kiomid)%irec = 0
-         ENDIF
-         ! on what kind of domain must the data be written?
-         IF( PRESENT(pv_r2d) .OR. PRESENT(pv_r3d) ) THEN
-            idimsz(1:2) = iom_file(kiomid)%dimsz(1:2,idvar)
-            IF(     idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN
-               ix1 = nldi   ;   ix2 = nlei   ;   iy1 = nldj   ;   iy2 = nlej
-            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN
-               ix1 = 1      ;   ix2 = nlci   ;   iy1 = 1      ;   iy2 = nlcj
-            ELSEIF( idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN
-               ix1 = 1      ;   ix2 = jpi    ;   iy1 = 1      ;   iy2 = jpj
-            ELSE 
-               CALL ctl_stop( 'iom_nf90_rp0123d: should have been an impossible case...' )
-            ENDIF
-
-            ! write dimension variables if it is not already done
-            ! =============
-            ! trick: is defined to 0 => dimension variable are defined but not yet written
-            IF( iom_file(kiomid)%dimsz(1, 1) == 0 ) THEN
-               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lon'     , idmy ), clinfo)
-               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, glamt(ix1:ix2, iy1:iy2) ), clinfo)
-               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lat'     , idmy ), clinfo)
-               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, gphit(ix1:ix2, iy1:iy2) ), clinfo)
-               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lev'     , idmy ), clinfo)
-               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, gdept_0                 ), clinfo)
-               ! +++ WRONG VALUE: to be improved but not really useful...
-               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'time_counter', idmy ), clinfo)
-               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, kt                      ), clinfo)   
-               ! update the values of the variables dimensions size
-               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 1, len = iom_file(kiomid)%dimsz(1,1) ), clinfo)
-               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 2, len = iom_file(kiomid)%dimsz(2,1) ), clinfo)
-               iom_file(kiomid)%dimsz(1:2, 2) = iom_file(kiomid)%dimsz(1:2, 1)
-               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 3, len = iom_file(kiomid)%dimsz(1,3) ), clinfo)
-               iom_file(kiomid)%dimsz(1  , 4) = 1   ! unlimited dimension
-               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' write dimension variables done'
-            ENDIF
-         ENDIF
-
-         ! write the data
-         ! =============
-         IF(     PRESENT(pv_r0d) ) THEN
-            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r0d                      ), clinfo)
-         ELSEIF( PRESENT(pv_r1d) ) THEN
-            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r1d(                  :) ), clinfo)
-         ELSEIF( PRESENT(pv_r2d) ) THEN
-            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r2d(ix1:ix2, iy1:iy2   ) ), clinfo)
-         ELSEIF( PRESENT(pv_r3d) ) THEN
-            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r3d(ix1:ix2, iy1:iy2, :) ), clinfo)
-         ENDIF
-         ! add 1 to the size of the temporal dimension (not really useful...)
-         IF( iom_file(kiomid)%luld(idvar) )   iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar)    &
-               &                            = iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar) + 1
-         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' written ok'
-      ENDIF
-      !     
-   END SUBROUTINE iom_nf90_rp0123d
-
-
-   SUBROUTINE iom_nf90_check( kstatus, cdinfo )
-      !!--------------------------------------------------------------------
-      !!                   ***  SUBROUTINE iom_nf90_check  ***
-      !!
-      !! ** Purpose :   check nf90 errors
-      !!--------------------------------------------------------------------
-      INTEGER,          INTENT(in) :: kstatus
-      CHARACTER(LEN=*), INTENT(in) :: cdinfo
-      !---------------------------------------------------------------------
-      IF(kstatus /= nf90_noerr)   CALL ctl_stop( 'iom_nf90_check : '//TRIM(nf90_strerror(kstatus)), TRIM(cdinfo) )
-   END SUBROUTINE iom_nf90_check
-
-   !!======================================================================
-END MODULE iom_nf90
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/ldfdyn_c3d.h90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/ldfdyn_c3d.h90	(revision 3937)
+++ 	(revision )
@@ -1,521 +1,0 @@
-   !!----------------------------------------------------------------------
-   !!                        ***  ldfdyn_c3d.h90  ***
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: ldfdyn_c3d.h90 3294 2012-01-28 16:44:18Z rblod $ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   'key_dynldf_c3d'             3D lateral eddy viscosity coefficients
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE ldf_dyn_c3d( ld_print )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ldf_dyn_c3d  ***
-      !!                   
-      !! ** Purpose :   initializations of the horizontal ocean physics
-      !!
-      !! ** Method  :   3D eddy viscosity coef. ( longitude, latitude, depth )
-      !!       laplacian operator   : ahm1, ahm2 defined at T- and F-points
-      !!                              ahm2, ahm4 never used
-      !!       bilaplacian operator : ahm1, ahm2 never used
-      !!                           :  ahm3, ahm4 defined at U- and V-points
-      !!       ??? explanation of the default is missing
-      !!----------------------------------------------------------------------
-      USE ldftra_oce, ONLY :   aht0
-      !!
-      LOGICAL, INTENT (in) ::   ld_print   ! If true, output arrays on numout
-      !!
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zr = 0.2     ! maximum of the reduction factor at the bottom ocean ( 0 < zr < 1 )
-      REAL(wp) ::   zh = 500.    ! depth of at which start the reduction ( > dept(1) )
-      REAL(wp) ::   zd_max       ! maximum grid spacing over the global domain
-      REAL(wp) ::   za00, zc, zd, zetmax, zefmax, zeumax, zevmax   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:)   :: zcoef   
-      INTEGER,  PARAMETER               :: zrim = 5  ! number of grid points over which diffusion is increased linearly
-      REAL(wp), PARAMETER               :: zinc_coef = 0.0 ! coef of diffusion increase  
-      INTEGER  ::   ii0, ii1, ij0, ij1   ! temporary integers
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpk, zcoef )
-      !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'ldf_dyn_c3d : 3D lateral eddy viscosity coefficient'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
-
-      
-      ! Set ahm1 and ahm2  ( T- and F- points) (used for laplacian operators
-      ! =================                       whatever its orientation is)
-      IF( ln_dynldf_lap ) THEN
-         ! define ahm1 and ahm2 at the right grid point position
-         ! (USER: modify ahm1 and ahm2 following your desiderata)
-
-         zd_max = MAX( MAXVAL( e1t(:,:) ), MAXVAL( e2t(:,:) ) )
-         IF( lk_mpp )   CALL mpp_max( zd_max )   ! max over the global domain
-
-         IF(lwp) WRITE(numout,*) '              laplacian operator: ahm proportional to e1'
-         IF(lwp) WRITE(numout,*) '              maximum grid-spacing = ', zd_max, ' maximum value for ahm = ', ahm0
-
-         za00 = ahm0 / zd_max
-
-         IF( ln_dynldf_iso ) THEN
-            IF(lwp) WRITE(numout,*) '              Caution, as implemented now, the isopycnal part of momentum'
-            IF(lwp) WRITE(numout,*) '                 mixing use aht0 as eddy viscosity coefficient. Thus, it is'
-            IF(lwp) WRITE(numout,*) '                 uniform and you must be sure that your ahm is greater than'
-            IF(lwp) WRITE(numout,*) '                 aht0 everywhere in the model domain.'
-         ENDIF
-
-         CALL ldf_zpf( .TRUE. , 1000., 500., 0.25, fsdept(:,:,:), ahm1 )   ! vertical profile
-         CALL ldf_zpf( .TRUE. , 1000., 500., 0.25, fsdept(:,:,:), ahm2 )   ! vertical profile
-         DO jk = 1,jpk
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zetmax = MAX( e1t(ji,jj), e2t(ji,jj) )
-                  zefmax = MAX( e1f(ji,jj), e2f(ji,jj) )
-                  ahm1(ji,jj,jk) = za00 * zetmax * ahm1(ji,jj,jk)
-                  ahm2(ji,jj,jk) = za00 * zefmax * ahm2(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-
-
-         ! Special case for ORCA R1, R2 and R4 configurations (overwrite the value of ahm1 ahm2)
-         ! ==============================================
-         IF( cp_cfg == "orca" .AND. ( jp_cfg == 1 .OR. jp_cfg == 2 .OR. jp_cfg == 4 ) ) THEN 
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) '              ORCA R1, R2 or R4: overwrite the previous definition of ahm'
-            IF(lwp) WRITE(numout,*) '              ================='
-            CALL ldf_dyn_c3d_orca( ld_print )
-         ENDIF
-
-	 ! --------------------------------------------------------------------
-	 ! clem - Increase viscosity over the edge of the domain (sponge layer)
-	 ! --------------------------------------------------------------------
-         DO ji = 1, jpi
-           ij0 = 1
-	   ij1 = MIN( zrim, ji, jpi-ji+1 )
-           DO jj = mj0(ij0), mj1(ij1)
-               ahm1(ji,jj,:) = ahm1(ji,jj,:) * ( REAL(zrim-jj) * zinc_coef + 1.0 )
-               ahm2(ji,jj,:) = ahm2(ji,jj,:) * ( REAL(zrim-jj) * zinc_coef + 1.0 )
-
-               ahm1(ji,jpj-jj+1,:) = ahm1(ji,jpj-jj+1,:) * ( REAL(zrim-jj) * zinc_coef + 1.0 )
-               ahm2(ji,jpj-jj+1,:) = ahm2(ji,jpj-jj+1,:) * ( REAL(zrim-jj) * zinc_coef + 1.0 )
-            END DO
-         END DO
-
-         DO jj = 2, jpjm1
-            ii0 = 1
-	    ii1 = MAX(1, MIN( zrim, jj-1, jpj-jj ))
-            DO ji = mi0(ii0), mi1(ii1)
-               ahm1(ji,jj,:) = ahm1(ji,jj,:) * ( REAL(zrim-ji) * zinc_coef + 1.0 )
-               ahm2(ji,jj,:) = ahm2(ji,jj,:) * ( REAL(zrim-ji) * zinc_coef + 1.0 )
-
-               ahm1(jpi-ji+1,jj,:) = ahm1(jpi-ji+1,jj,:) * ( REAL(zrim-ji) * zinc_coef + 1.0 )
-               ahm2(jpi-ji+1,jj,:) = ahm2(jpi-ji+1,jj,:) * ( REAL(zrim-ji) * zinc_coef + 1.0 )
-            END DO
-         END DO
-	 ! --------------------------------------------------------------------
-	 
-      	 ! Control print
-         IF(lwp .AND. ld_print ) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) '         3D ahm1 array (k=1)'
-            CALL prihre( ahm1(:,:,1), jpi, jpj, 1, jpi, 1, 1, jpj, 1, 1.e-3, numout )
-            WRITE(numout,*)
-            WRITE(numout,*) '         3D ahm2 array (k=1)'
-            CALL prihre( ahm2(:,:,1), jpi, jpj, 1, jpi, 1, 1, jpj, 1, 1.e-3, numout )
-         ENDIF
-
-      ENDIF
-      
-
-      ! ahm3 and ahm4 at U- and V-points (used for bilaplacian operator
-      ! ================================  whatever its orientation is)
-      ! (USER: modify ahm3 and ahm4 following your desiderata)
-      ! Here: ahm is proportional to the cube of the maximum of the gridspacing
-      !       in the to horizontal direction
-
-      IF( ln_dynldf_bilap ) THEN
-
-         zd_max = MAX( MAXVAL( e1u(:,:) ), MAXVAL( e2u(:,:) ) )
-         IF( lk_mpp )   CALL mpp_max( zd_max )   ! max over the global domain
-
-         IF(lwp) WRITE(numout,*) '              bi-laplacian operator: ahm proportional to e1**3 '
-         IF(lwp) WRITE(numout,*) '              maximum grid-spacing = ', zd_max, ' maximum value for ahm = ', ahm0
-
-         za00 = ahm0_blp / ( zd_max * zd_max * zd_max )
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zeumax = MAX( e1u(ji,jj), e2u(ji,jj) )
-               zevmax = MAX( e1v(ji,jj), e2v(ji,jj) )
-               ahm3(ji,jj,1) = za00 * zeumax * zeumax * zeumax
-               ahm4(ji,jj,1) = za00 * zevmax * zevmax * zevmax
-            END DO
-         END DO
-
-         zh = MAX( zh, fsdept(1,1,1) )   ! at least the first reach ahm0
-         IF( ln_zco ) THEN               ! z-coordinate, same profile everywhere
-            IF(lwp) WRITE(numout,'(36x," ahm ", 7x)')
-            DO jk = 1, jpk
-               IF( fsdept(1,1,jk) <= zh ) THEN
-                  zcoef(jk) = 1.e0
-               ELSE
-                  zcoef(jk) = 1.e0 + ( zr - 1.e0 )   &
-                     &               * (  1. - EXP( ( fsdept(1,1,jk   ) - zh ) / zh )  )   &
-                     &               / (  1. - EXP( ( fsdept(1,1,jpkm1) - zh ) / zh )  )
-               ENDIF
-               ahm3(:,:,jk) = ahm3(:,:,1) * zcoef(jk)
-               ahm4(:,:,jk) = ahm4(:,:,1) * zcoef(jk)
-               IF(lwp) WRITE(numout,'(34x,E7.2,8x,i3)') zcoef(jk) * ahm0, jk
-            END DO
-         ELSE                            ! partial steps or s-ccordinate
-            zc = MAXVAL( fsdept(:,:,jpkm1) )
-            IF( lk_mpp )   CALL mpp_max( zc )   ! max over the global domain
-
-            zc = 1. / (  1. - EXP( ( zc - zh ) / zh )  )
-            DO jk = 2, jpkm1
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     IF( fsdept(ji,jj,jk) <= zh ) THEN
-                        ahm3(ji,jj,jk) = ahm3(ji,jj,1)
-                        ahm4(ji,jj,jk) = ahm4(ji,jj,1)
-                     ELSE
-                        zd = 1.e0 + ( zr - 1.e0 ) * (  1. - EXP( ( fsdept(ji,jj,jk) - zh ) / zh )  ) * zc
-                        ahm3(ji,jj,jk) = ahm3(ji,jj,1) * zd
-                        ahm4(ji,jj,jk) = ahm4(ji,jj,1) * zd
-                     ENDIF
-                  END DO
-               END DO
-            END DO
-            ahm3(:,:,jpk) = ahm3(:,:,jpkm1)
-            ahm4(:,:,jpk) = ahm4(:,:,jpkm1)
-            IF(lwp) WRITE(numout,'(36x," ahm ", 7x)')
-            DO jk = 1, jpk
-               IF(lwp) WRITE(numout,'(30x,E10.2,8x,i3)') ahm3(1,1,jk), jk
-            END DO
-         ENDIF
-
-	 ! --------------------------------------------------------------------
-	 ! clem - Increase viscosity over the edge of the domain (sponge layer)
-	 ! --------------------------------------------------------------------
-        DO ji = 1, jpi
-           ij0 = 1
-           ij1 = MIN( zrim, ji, jpi-ji+1 )
-           DO jj = mj0(ij0), mj1(ij1)
-               ahm3(ji,jj,:) = ahm3(ji,jj,:) * ( REAL(zrim-jj) * zinc_coef + 1.0 )
-               ahm4(ji,jj,:) = ahm4(ji,jj,:) * ( REAL(zrim-jj) * zinc_coef + 1.0 )
-
-               ahm3(ji,jpj-jj+1,:) = ahm3(ji,jpj-jj+1,:) * ( REAL(zrim-jj) * zinc_coef + 1.0 )
-               ahm4(ji,jpj-jj+1,:) = ahm4(ji,jpj-jj+1,:) * ( REAL(zrim-jj) * zinc_coef + 1.0 )
-            END DO
-         END DO
-
-         DO jj = 2, jpjm1
-            ii0 = 1
-	    ii1 = MAX(1, MIN( zrim, jj-1, jpj-jj ))
-            DO ji = mi0(ii0), mi1(ii1)
-               ahm3(ji,jj,:) = ahm3(ji,jj,:) * ( REAL(zrim-ji) * zinc_coef + 1.0 )
-               ahm4(ji,jj,:) = ahm4(ji,jj,:) * ( REAL(zrim-ji) * zinc_coef + 1.0 )
-
-               ahm3(jpi-ji+1,jj,:) = ahm3(jpi-ji+1,jj,:) * ( REAL(zrim-ji) * zinc_coef + 1.0 )
-               ahm4(jpi-ji+1,jj,:) = ahm4(jpi-ji+1,jj,:) * ( REAL(zrim-ji) * zinc_coef + 1.0 )
-            END DO
-         END DO
-	 ! --------------------------------------------------------------------
-
-
-         ! Control print
-         IF( lwp .AND. ld_print ) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) 'inildf: ahm3 array at level 1'
-            CALL prihre(ahm3(:,:,1  ),jpi,jpj,1,jpi,1,1,jpj,1,1.e-12,numout)
-            WRITE(numout,*)
-            WRITE(numout,*) 'inildf: ahm4 array at level 1'
-            CALL prihre(ahm4(:,:,jpk),jpi,jpj,1,jpi,1,1,jpj,1,1.e-12,numout)
-         ENDIF
-      ENDIF
-      !
-      CALL wrk_dealloc( jpk, zcoef )
-      !
-   END SUBROUTINE ldf_dyn_c3d
-
-
-   SUBROUTINE ldf_dyn_c3d_orca( ld_print )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ldf_dyn_c3d  ***
-      !!                   
-      !! ** Purpose :   ORCA R1, R2 and R4 only
-      !!
-      !! ** Method  :   blah blah blah ....
-      !!----------------------------------------------------------------------
-      USE ldftra_oce, ONLY:   aht0
-      !!
-      LOGICAL, INTENT(in) ::   ld_print   ! If true, output arrays on numout
-      !!
-      INTEGER ::   ji, jj, jk, jn      ! dummy loop indices
-      INTEGER ::   ii0, ii1, ij0, ij1  ! local integers
-      INTEGER ::   inum, iim, ijm      ! 
-      INTEGER ::   ifreq, il1, il2, ij, ii
-      REAL(wp) ::   zahmeq, zcoff, zcoft, zmsk   ! local scalars
-      REAL(wp) ::   zemax , zemin, zeref, zahmm
-      CHARACTER (len=15) ::   clexp
-      INTEGER , POINTER, DIMENSION(:,:)  :: icof
-      INTEGER , POINTER, DIMENSION(:,:)  :: idata
-      REAL(wp), POINTER, DIMENSION(:  )  :: zcoef   
-      REAL(wp), POINTER, DIMENSION(:,:)  :: zahm0
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi   , jpj   , icof  )
-      CALL wrk_alloc( jpidta, jpjdta, idata )
-      CALL wrk_alloc( jpk   ,         zcoef )
-      CALL wrk_alloc( jpi   , jpj   , zahm0 )
-      !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'ldfdyn_c3d_orca : 3D eddy viscosity coefficient'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
-      IF(lwp) WRITE(numout,*) '        orca R1, R2 or R4 configuration: reduced in the surface Eq. strip '
-
-      ! Read 2d integer array to specify western boundary increase in the
-      ! ===================== equatorial strip (20N-20S) defined at t-points
-
-      CALL ctl_opn( inum, 'ahmcoef', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp )
-      READ(inum,9101) clexp, iim, ijm
-      READ(inum,'(/)')
-      ifreq = 40
-      il1 = 1
-      DO jn = 1, jpidta/ifreq+1
-         READ(inum,'(/)')
-         il2 = MIN( jpidta, il1+ifreq-1 )
-         READ(inum,9201) ( ii, ji = il1, il2, 5 )
-         READ(inum,'(/)')
-         DO jj = jpjdta, 1, -1
-            READ(inum,9202) ij, ( idata(ji,jj), ji = il1, il2 )
-         END DO
-         il1 = il1 + ifreq
-      END DO
-      
-      DO jj = 1, nlcj
-         DO ji = 1, nlci
-            icof(ji,jj) = idata( mig(ji), mjg(jj) )
-         END DO
-      END DO
-      DO jj = nlcj+1, jpj
-         DO ji = 1, nlci
-            icof(ji,jj) = icof(ji,nlcj)
-         END DO
-      END DO
-      DO jj = 1, jpj
-         DO ji = nlci+1, jpi
-            icof(ji,jj) = icof(nlci,jj)
-         END DO
-      END DO
-      
-9101  FORMAT(1x,a15,2i8)
-9201  FORMAT(3x,13(i3,12x))
-9202  FORMAT(i3,41i3)
-      
-      ! Set ahm1 and ahm2
-      ! =================
-      
-      ! define ahm1 and ahm2 at the right grid point position
-      ! (USER: modify ahm1 and ahm2 following your desiderata)
-      ! biharmonic : ahm1 (ahm2) defined at u- (v-) point
-      ! harmonic   : ahm1 (ahm2) defined at t- (f-) point
-      
-      ! first level : as for 2D coefficients
-      
-      ! Decrease ahm to zahmeq m2/s in the tropics
-      ! (from 90 to 20 degre: ahm = constant
-      ! from 20 to  2.5 degre: ahm = decrease in (1-cos)/2
-      ! from  2.5 to  0 degre: ahm = constant
-      ! symmetric in the south hemisphere)
-      
-      IF( jp_cfg == 4 )   THEN
-         zahmeq = 5.0 * aht0
-         zahmm  = min( 160000.0, ahm0)
-         zemax = MAXVAL ( e1t(:,:) * e2t(:,:), tmask(:,:,1) .GE. 0.5 )
-         zemin = MINVAL ( e1t(:,:) * e2t(:,:), tmask(:,:,1) .GE. 0.5 )
-         zeref = MAXVAL ( e1t(:,:) * e2t(:,:),   &
-             &   tmask(:,:,1) .GE. 0.5 .AND. ABS(gphit(:,:)) .GT. 50. )
- 
-         DO jj = 1, jpj
-           DO ji = 1, jpi
-              zmsk = e1t(ji,jj) * e2t(ji,jj)
-              IF( abs(gphit(ji,jj)) .LE. 15 ) THEN 
-                 zahm0(ji,jj) = ahm0
-              ELSE 
-                 IF( zmsk .GE. zeref ) THEN 
-                    zahm0(ji,jj) = ahm0
-                 ELSE 
-                    zahm0(ji,jj) = zahmm + (ahm0-zahmm)*(1.0 -   &
-                        &          cos((rpi*0.5*(zmsk-zemin)/(zeref-zemin))))
-                 ENDIF 
-              ENDIF 
-           END DO 
-         END DO 
-      ENDIF
-
-      IF( jp_cfg == 2 )   THEN
-         zahmeq     = aht0
-         zahmm      = ahm0
-         zahm0(:,:) = ahm0
-      ENDIF
-
-      IF( jp_cfg == 1 )   THEN
-         zahmeq     = aht0  ! reduced to aht0 on equator; set to ahm0 if no tropical reduction is required
-         zahmm      = ahm0
-         zahm0(:,:) = ahm0
-      ENDIF
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( ABS(gphif(ji,jj)) >= 20.) THEN
-               ahm2(ji,jj,1) =  zahm0(ji,jj)
-            ELSEIF( ABS(gphif(ji,jj)) <= 2.5) THEN
-               ahm2(ji,jj,1) =  zahmeq
-            ELSE
-               ahm2(ji,jj,1) = zahmeq + (zahm0(ji,jj)-zahmeq)/2.   &
-                  &            *(1.-COS( rad*(ABS(gphif(ji,jj))-2.5)*180./17.5 ) )
-            ENDIF
-            IF( ABS(gphit(ji,jj)) >= 20.) THEN
-               ahm1(ji,jj,1) =  zahm0(ji,jj)
-            ELSEIF( ABS(gphit(ji,jj)) <= 2.5) THEN
-               ahm1(ji,jj,1) =  zahmeq
-            ELSE
-               ahm1(ji,jj,1) = zahmeq + (zahm0(ji,jj)-zahmeq)/2.   &
-                  &            *(1.-COS( rad*(ABS(gphit(ji,jj))-2.5)*180./17.5 ) )
-            ENDIF
-         END DO
-      END DO
-      
-      ! increase along western boundaries of equatorial strip
-      ! t-point
-      DO jj = 1, jpjm1
-         DO ji = 1, jpim1
-            zcoft = float( icof(ji,jj) ) / 100.
-            ahm1(ji,jj,1) = zcoft * zahm0(ji,jj) + (1.-zcoft) * ahm1(ji,jj,1)
-         END DO
-      END DO
-      ! f-point
-      icof(:,:) = icof(:,:) * tmask(:,:,1)
-      DO jj = 1, jpjm1
-         DO ji = 1, jpim1   ! NO vector opt.
-            zmsk = tmask(ji,jj+1,1) + tmask(ji+1,jj+1,1) + tmask(ji,jj,1) + tmask(ji,jj+1,1)
-            IF( zmsk == 0. ) THEN
-               zcoff = 1.
-            ELSE
-               zcoff = FLOAT( icof(ji,jj+1) + icof(ji+1,jj+1) + icof(ji,jj) + icof(ji,jj+1) )   &
-                     / (zmsk * 100.)
-            ENDIF
-            ahm2(ji,jj,1) = zcoff * zahm0(ji,jj) + (1.-zcoff) * ahm2(ji,jj,1)
-         END DO
-      END DO
-
-      ! other level: re-increase the coef in the deep ocean
-      !==================================================================
-      ! Prior to v3.3, zcoeff was hardwired according to k-index jk.
-      !
-      ! From v3.3 onwards this has been generalised to a function of 
-      ! depth so that it can be used with any number of levels.
-      !
-      ! The function has been chosen to match the original values (shown
-      ! in the following comments) when using the standard 31 ORCA levels.  
-      !     DO jk = 1, 21
-      !        zcoef(jk) = 1._wp
-      !     END DO
-      !     zcoef(22) = 2._wp
-      !     zcoef(23) = 3._wp
-      !     zcoef(24) = 5._wp
-      !     zcoef(25) = 7._wp
-      !     zcoef(26) = 9._wp
-      !     DO jk = 27, jpk
-      !        zcoef(jk) = 10._wp
-      !     END DO
-      !==================================================================
-
-       IF(lwp) THEN
-          WRITE(numout,*)
-          WRITE(numout,*) '         1D zcoef array '
-          WRITE(numout,*) '         ~~~~~~~~~~~~~~ '
-          WRITE(numout,*)
-          WRITE(numout,*) '    jk        zcoef '
-       ENDIF
-
-      DO jk=1, jpk
-         zcoef(jk) = 1.0_wp + NINT(9.0_wp*(gdept_0(jk)-800.0_wp)/(3000.0_wp-800.0_wp))
-         zcoef(jk) = MIN(10.0_wp, MAX(1.0_wp, zcoef(jk)))
-         IF(lwp) WRITE(numout,'(4x,i3,6x,f7.3)') jk,zcoef(jk)
-      END DO
-
-      DO jk = 2, jpk
-         ahm1(:,:,jk) = MIN( zahm0(:,:), zcoef(jk) * ahm1(:,:,1) )
-         ahm2(:,:,jk) = MIN( zahm0(:,:), zcoef(jk) * ahm2(:,:,1) )
-      END DO
-
-      IF( jp_cfg == 4 )   THEN         ! Limit AHM in Gibraltar strait
-         ij0 = 50   ;   ij1 = 53
-         ii0 = 69   ;   ii1 = 71
-         DO jk = 1, jpk
-            ahm1(mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),jk) = MIN( zahmm, ahm1(mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),jk) ) 
-            ahm2(mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),jk) = MIN( zahmm, ahm2(mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),jk) )
-         END DO
-      ENDIF
-      CALL lbc_lnk( ahm1, 'T', 1. )   ! Lateral boundary conditions (unchanged sign)
-      CALL lbc_lnk( ahm2, 'F', 1. )
-
-
-      IF(lwp) THEN                    ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) '         3D ahm1 array (k=1)'
-         CALL prihre( ahm1(:,:,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1.e-3, numout )
-         WRITE(numout,*)
-         WRITE(numout,*) '         3D ahm2 array (k=1)'
-         CALL prihre( ahm2(:,:,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1.e-3, numout )
-         WRITE(numout,*)
-         WRITE(numout,*) '         3D ahm2 array (k=jpk)'
-         CALL prihre( ahm2(:,:,jpk), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1.e-3, numout )
-      ENDIF
-
-
-      ! Set ahm3 and ahm4
-      ! =================
-
-      ! define ahm3 and ahm4 at the right grid point position
-      ! initialization to a constant value
-      !     (USER: modify ahm3 and ahm4 following your desiderata)
-      !     harmonic isopycnal or geopotential:
-      !                          ahm3 (ahm4) defined at u- (v-) point
-      DO jk = 1, jpk
-         DO jj = 2, jpj
-            DO ji = 2, jpi
-               ahm3(ji,jj,jk) = 0.5 * ( ahm2(ji,jj,jk) + ahm2(ji  ,jj-1,jk) )
-               ahm4(ji,jj,jk) = 0.5 * ( ahm2(ji,jj,jk) + ahm2(ji-1,jj  ,jk) )
-            END DO
-         END DO
-      END DO
-      ahm3 ( :, 1, :) = ahm3 ( :, 2, :)
-      ahm4 ( :, 1, :) = ahm4 ( :, 2, :)
-      
-      CALL lbc_lnk( ahm3, 'U', 1. )    ! Lateral boundary conditions (unchanged sign)
-      CALL lbc_lnk( ahm4, 'V', 1. )
-
-      ! Control print
-
-      IF( lwp .AND. ld_print ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) '         ahm3 array level 1'
-         CALL prihre(ahm3(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-         WRITE(numout,*)
-         WRITE(numout,*) '         ahm4 array level 1'
-         CALL prihre(ahm4(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi   , jpj   , icof  )
-      CALL wrk_dealloc( jpidta, jpjdta, idata )
-      CALL wrk_dealloc( jpk   ,         zcoef )
-      CALL wrk_dealloc( jpi   , jpj   , zahm0 )
-      !
-   END SUBROUTINE ldf_dyn_c3d_orca
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/ldftra_c2d.h90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/ldftra_c2d.h90	(revision 3937)
+++ 	(revision )
@@ -1,165 +1,0 @@
-   !!----------------------------------------------------------------------
-   !!                      ***  ldftra_c2d.h90  ***
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: ldftra_c2d.h90 2715 2011-03-30 15:58:35Z rblod $ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE ldf_tra_c2d( ld_print )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ldftra_c2d  ***
-      !!              
-      !! ** Purpose :   initializations of horizontally non uniform eddy 
-      !!      diffusivity coefficients
-      !!
-      !! ** Method :
-      !!       biharmonic operator    : ahtt = defined at T-level
-      !!                                ahtu,ahtv,ahtw never used
-      !!       harmonic operator (ahtt never used)
-      !!           iso-model level   : ahtu, ahtv defined at u-, v-points
-      !!         isopycnal         : ahtu, ahtv, ahtw defined at u-, v-, w-pts
-      !!         or geopotential   
-      !!       eddy induced velocity
-      !!           always harmonic   : aeiu, aeiv, aeiw defined at u-, v-, w-pts
-      !!----------------------------------------------------------------------
-      LOGICAL, INTENT (in) ::   ld_print   ! If true, print arrays in numout
-      !
-      INTEGER ::   ji, jj   ! dummy loop indices
-# if defined key_orca_r4
-      INTEGER :: i1, i2, j1, j2
-# endif
-      REAL(wp) ::   za00, zd_max, zeumax, zevmax, zetmax
-      !!----------------------------------------------------------------------
-
-      IF( lk_traldf_eiv ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) ' ldf_tra_c2d : 2D eddy diffusivity and eddy'
-         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~   --  induced velocity coefficients'
-      ELSE
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) ' ldf_tra2d : 2D eddy diffusivity coefficient'
-         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~   --'
-      ENDIF
-
-      zd_max = MAX( MAXVAL( e1t(:,:) ), MAXVAL( e2t(:,:) ) )
-      IF( lk_mpp ) CALL mpp_max( zd_max )   ! max over the global domain
-
-      ! harmonic operator : (U-, V-, W-points)
-      ! ==================
-      IF( ln_traldf_lap ) THEN
-         !
-         za00 = aht0 / zd_max
-         !
-         DO jj = 1, jpj 
-            DO ji = 1, jpi 
-               zeumax = MAX( e1u(ji,jj), e2u(ji,jj) ) 
-               zevmax = MAX( e1v(ji,jj), e2v(ji,jj) ) 
-               zetmax = MAX( e1t(ji,jj), e2t(ji,jj) )
-               ahtu(ji,jj) = za00 * zeumax ! set ahtu = ahtv at u- and v-points, 
-               ahtv(ji,jj) = za00 * zevmax ! and ahtw at w-point (idem T-point) 
-               ahtw(ji,jj) = za00 * zetmax ! 
-            END DO
-         END DO
-
-         CALL lbc_lnk( ahtu, 'U', 1. )   ! Lateral boundary conditions
-         CALL lbc_lnk( ahtv, 'V', 1. )   ! (no change of sign)
-         CALL lbc_lnk( ahtw, 'W', 1. )
-
-         ! Special case for ORCA R2 and R4 configurations (overwrite the value of ahtu ahtv ahtw)
-         ! ==============================================
-         IF( cp_cfg == "orca" .AND. ( jp_cfg == 2 .OR. jp_cfg == 4 ) )   THEN
-            ahtu(:,:) = aht0              ! set ahtu = ahtv at u- and v-points,
-            ahtv(:,:) = aht0              ! and ahtw at w-point
-            ahtw(:,:) = aht0              ! (here : no space variation)
-            IF(lwp) WRITE(numout,*) '               ORCA R2 or R4 case'
-            IF(lwp) WRITE(numout,*) '               Constant values used for eddy diffusivity coefficients'
-            IF(lwp) WRITE(numout,*) '               Variation lat/lon only for eddy induced velocity coefficients'
-         ENDIF
-
-         ! Control print
-         IF( lwp .AND. ld_print ) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) 'inildf: ahtu array'
-            CALL prihre( ahtu, jpi, jpj, 1, jpi, 1,   &
-               &                         1, jpj, 1, 1.e-3, numout )
-            WRITE(numout,*)
-            WRITE(numout,*) 'inildf: ahtv array'
-            CALL prihre( ahtv, jpi, jpj, 1, jpi, 1,   &
-               &                         1, jpj, 1, 1.e-3, numout )
-            WRITE(numout,*)
-            WRITE(numout,*) 'inildf: ahtw array'
-            CALL prihre( ahtw, jpi, jpj, 1, jpi, 1,   &
-               &                         1, jpj, 1, 1.e-3, numout )
-         ENDIF
-      ENDIF
-      
-      ! biharmonic operator : (T-point)
-      ! ====================
-      IF( ln_traldf_bilap ) THEN
-         ! (USER: modify ahtt following your desiderata)
-         ! Here: ahm is proportional to the cube of the maximum of the gridspacing
-         !       in the to horizontal direction
-
-         zd_max = MAX( MAXVAL( e1t(:,:) ), MAXVAL( e2t(:,:) ) )
-         IF( lk_mpp )   CALL mpp_max( zd_max )   ! max over the global domain
-
-         za00 = aht0 / ( zd_max * zd_max * zd_max )
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zetmax = MAX( e1t(ji,jj), e2t(ji,jj) )
-               ahtt(ji,jj) = za00 * zetmax * zetmax * zetmax      ! set ahtt at T-point
-            END DO
-         END DO
-
-         CALL lbc_lnk( ahtt, 'T', 1. )   ! Lateral boundary conditions on ( ahtt )
-
-         ! Control print
-         IF( lwp .AND. ld_print ) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) 'inildf: 2D ahtt array'
-            CALL prihre( ahtt, jpi, jpj, 1, jpi, 1,   &
-               &                         1, jpj, 1, 1.e-3, numout )
-         ENDIF
-      ENDIF
-
-# if defined key_traldf_eiv
-      ! set aeiu = aeiv at u- and v-points, and aeiw at w-point (idem T-point)
-      ! (here no space variation)
-      aeiu(:,:) = aeiv0
-      aeiv(:,:) = aeiv0
-      aeiw(:,:) = aeiv0
-      
-      IF( cp_cfg == "orca" .AND. jp_cfg == 4 ) THEN
-         !                                 ! Cancel eiv in Gibraltar strait
-!clem         aeiu( mi0(68):mi1(71) , mj0(50):mj1(53) ) = 0.e0
-!clem         aeiv( mi0(68):mi1(71) , mj0(50):mj1(53) ) = 0.e0
-!clem         aeiw( mi0(68):mi1(71) , mj0(50):mj1(53) ) = 0.e0
-         !                                 ! Cancel eiv in Mediterrannean sea
-!clem         aeiu( mi0(70):mi1(90) , mj0(49):mj1(56) ) = 0.e0
-!clem         aeiv( mi0(70):mi1(90) , mj0(49):mj1(56) ) = 0.e0
-!clem         aeiw( mi0(70):mi1(90) , mj0(49):mj1(56) ) = 0.e0
-      ENDIF
-
-      ! Lateral boundary conditions on ( aeiu, aeiv, aeiw )
-      CALL lbc_lnk( aeiu, 'U', 1. )
-      CALL lbc_lnk( aeiv, 'V', 1. )
-      CALL lbc_lnk( aeiw, 'W', 1. )
-
-      ! Control print
-      IF( lwp .AND. ld_print ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'inildf: aeiu array'
-         CALL prihre(aeiu,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-         WRITE(numout,*)
-         WRITE(numout,*) 'inildf: aeiv array'
-         CALL prihre(aeiv,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-         WRITE(numout,*)
-         WRITE(numout,*) 'inildf: aeiw array'
-         CALL prihre(aeiw,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-      ENDIF
-# endif
-      !
-   END SUBROUTINE ldf_tra_c2d
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/ldftra_c3d.h90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/ldftra_c3d.h90	(revision 3937)
+++ 	(revision )
@@ -1,124 +1,0 @@
-   !!----------------------------------------------------------------------
-   !!                        ***  ldftra_c3d.h90  ***
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: ldftra_c3d.h90 2715 2011-03-30 15:58:35Z rblod $ 
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE ldf_tra_c3d( ld_print )
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE ldftra_c3d  ***
-      !!                
-      !! ** Purpose :
-      !!     initializations of non uniform horizontal eddy diffusivity coef.
-      !!
-      !! ** Method :
-      !!      3D eddy diffusivity coefficients ( longitude, latitude, depth )
-      !!
-      !!       biharmonic operator    : ahtt = defined at T-level
-      !!                                ahtu,ahtv,ahtw never used
-      !!
-      !!       harmonic operator (ahtt never used)
-      !!         iso-model level   : ahtu, ahtv defined at u-, v-points
-      !!         isopycnal         : ahtu, ahtv, ahtw defined at u-, v-, w-pts
-      !!         or geopotential
-      !!
-      !!       eddy induced velocity
-      !!         always harmonic   : aeiu, aeiv, aeiw defined at u-, v-, w-pts
-      !!----------------------------------------------------------------------
-      USE ioipsl
-      !
-      LOGICAL, INTENT (in) ::   ld_print   ! If true, output arrays on numout
-      !!----------------------------------------------------------------------
-
-      IF( lk_traldf_eiv ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) ' ldf_tra_c3d : 3D eddy diffusivity and eddy induced velocity coefficients'
-         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~   --  '
-         IF(lwp) WRITE(numout,*) '               Coefficients set to constant'
-      ELSE
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) ' ldf_tra_c3d : 3D eddy diffusivity coefficient'
-         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~   -- '
-         IF(lwp) WRITE(numout,*) '               Coefficients set to constant'
-      ENDIF
-
-
-      ! biharmonic operator   (T-point)
-      ! -------------------
-
-      ahtt(:,:,:) = aht0              ! set ahtt at T-point (here no space variation)
-
-      CALL lbc_lnk( ahtt, 'T', 1. )   ! Lateral boundary conditions on ( ahtt )
-
-      IF(lwp .AND. ld_print ) THEN                    ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'inildf: ahtt at k = 1'
-         CALL prihre( ahtt(:,:,1), jpi, jpj, 1, jpi, 1,   &
-            &                                1, jpj, 1, 1.e-3, numout )
-      ENDIF
-
-
-      ! harmonic operator   (U-, V-, W-points)
-      ! ----------------- 
-
-      ahtu(:,:,:) = aht0              ! set ahtu = ahtv at u- and v-points,
-      ahtv(:,:,:) = aht0              ! and ahtw at w-point
-      ahtw(:,:,:) = aht0              ! (here example: no space variation)
-      
-      CALL lbc_lnk( ahtu, 'U', 1. )   ! Lateral boundary conditions
-      CALL lbc_lnk( ahtv, 'V', 1. )
-      CALL lbc_lnk( ahtw, 'W', 1. )
-
-      IF(lwp .AND. ld_print ) THEN                    ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'inildf: ahtu at k = 1'
-         CALL prihre( ahtu(:,:,1), jpi, jpj, 1, jpi, 1,   &
-            &                                1, jpj, 1, 1.e-3, numout )
-         WRITE(numout,*)
-         WRITE(numout,*) 'inildf: ahtv at k = 1'
-         CALL prihre( ahtv(:,:,1), jpi, jpj, 1, jpi, 1,   &
-            &                                1, jpj, 1, 1.e-3, numout )
-         WRITE(numout,*)
-         WRITE(numout,*) 'inildf: ahtw at k = 1'
-         CALL prihre( ahtw(:,:,1), jpi, jpj, 1, jpi, 1,   &
-            &                                1, jpj, 1, 1.e-3, numout )
-      ENDIF
-
-# if defined key_traldf_eiv
-      aeiu(:,:,:) = aeiv0            ! set aeiu = aeiv at u- and v-points,
-      aeiv(:,:,:) = aeiv0            ! and aeiw at w-point
-      aeiw(:,:,:) = aeiv0            ! (here example: no space variation)
-
-      IF( cp_cfg == "orca" .AND. jp_cfg == 4 ) THEN
-         !                                 ! Cancel eiv in Gibraltar strait
-!clem         aeiu( mi0(68):mi1(71) , mj0(50):mj1(53) , : ) = 0.e0
-!clem         aeiv( mi0(68):mi1(71) , mj0(50):mj1(53) , : ) = 0.e0
-!clem         aeiw( mi0(68):mi1(71) , mj0(50):mj1(53) , : ) = 0.e0
-         !                                 ! Cancel eiv in Mediterrannean sea
-!clem         aeiu( mi0(70):mi1(90) , mj0(49):mj1(56) , : ) = 0.e0
-!clem         aeiv( mi0(70):mi1(90) , mj0(49):mj1(56) , : ) = 0.e0
-!clem         aeiw( mi0(70):mi1(90) , mj0(49):mj1(56) , : ) = 0.e0
-      ENDIF
-
-      CALL lbc_lnk( aeiu, 'U', 1. )   ! Lateral boundary conditions 
-      CALL lbc_lnk( aeiv, 'V', 1. )
-      CALL lbc_lnk( aeiw, 'W', 1. )
-# endif
-
-      IF(lwp .AND. ld_print ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'inildf: aeiu at k = 1'
-         CALL prihre(aeiu(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-         WRITE(numout,*)
-         WRITE(numout,*) 'inildf: aeiv at k = 1'
-         CALL prihre(aeiv(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-         WRITE(numout,*)
-         WRITE(numout,*) 'inildf: aeiw at k = 1'
-         CALL prihre(aeiw(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
-      ENDIF
-      !
-   END SUBROUTINE ldf_tra_c3d
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/lib_mpp.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/lib_mpp.F90	(revision 3937)
+++ 	(revision )
@@ -1,3038 +1,0 @@
-MODULE lib_mpp
-   !!======================================================================
-   !!                       ***  MODULE  lib_mpp  ***
-   !! Ocean numerics:  massively parallel processing library
-   !!=====================================================================
-   !! History :  OPA  !  1994  (M. Guyon, J. Escobar, M. Imbard)  Original code
-   !!            7.0  !  1997  (A.M. Treguier)  SHMEM additions
-   !!            8.0  !  1998  (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI
-   !!                 !  1998  (J.M. Molines) Open boundary conditions
-   !!   NEMO     1.0  !  2003  (J.-M. Molines, G. Madec)  F90, free form
-   !!                 !  2003  (J.M. Molines) add mpp_ini_north(_3d,_2d)
-   !!             -   !  2004  (R. Bourdalle Badie)  isend option in mpi
-   !!                 !  2004  (J.M. Molines) minloc, maxloc
-   !!             -   !  2005  (G. Madec, S. Masson)  npolj=5,6 F-point & ice cases
-   !!             -   !  2005  (R. Redler) Replacement of MPI_COMM_WORLD except for MPI_Abort
-   !!             -   !  2005  (R. Benshila, G. Madec)  add extra halo case
-   !!             -   !  2008  (R. Benshila) add mpp_ini_ice
-   !!            3.2  !  2009  (R. Benshila) SHMEM suppression, north fold in lbc_nfd
-   !!            3.2  !  2009  (O. Marti)    add mpp_ini_znl 
-   !!            4.0  !  2011  (G. Madec)  move ctl_ routines from in_out_manager
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   ctl_stop   : update momentum and tracer Kz from a tke scheme
-   !!   ctl_warn   : initialization, namelist read, and parameters control
-   !!   ctl_opn    : Open file and check if required file is available.
-   !!   get_unit    : give the index of an unused logical unit
-   !!----------------------------------------------------------------------
-#if   defined key_mpp_mpi  
-   !!----------------------------------------------------------------------
-   !!   'key_mpp_mpi'             MPI massively parallel processing library
-   !!----------------------------------------------------------------------
-   !!   lib_mpp_alloc : allocate mpp arrays
-   !!   mynode        : indentify the processor unit
-   !!   mpp_lnk       : interface (defined in lbclnk) for message passing of 2d or 3d arrays (mpp_lnk_2d, mpp_lnk_3d)
-   !!   mpp_lnk_3d_gather :  Message passing manadgement for two 3D arrays
-   !!   mpp_lnk_e     : interface (defined in lbclnk) for message passing of 2d array with extra halo (mpp_lnk_2d_e)
-   !!   mpprecv         :
-   !!   mppsend       :   SUBROUTINE mpp_ini_znl
-   !!   mppscatter    :
-   !!   mppgather     :
-   !!   mpp_min       : generic interface for mppmin_int , mppmin_a_int , mppmin_real, mppmin_a_real
-   !!   mpp_max       : generic interface for mppmax_int , mppmax_a_int , mppmax_real, mppmax_a_real
-   !!   mpp_sum       : generic interface for mppsum_int , mppsum_a_int , mppsum_real, mppsum_a_real
-   !!   mpp_minloc    :
-   !!   mpp_maxloc    :
-   !!   mppsync       :
-   !!   mppstop       :
-   !!   mppobc        : variant of mpp_lnk for open boundary condition
-   !!   mpp_ini_north : initialisation of north fold
-   !!   mpp_lbc_north : north fold processors gathering
-   !!   mpp_lbc_north_e : variant of mpp_lbc_north for extra outer halo
-   !!----------------------------------------------------------------------
-   USE dom_oce        ! ocean space and time domain 
-   USE lbcnfd         ! north fold treatment
-   USE in_out_manager ! I/O manager
-
-   IMPLICIT NONE
-   PRIVATE
-   
-   PUBLIC   ctl_stop, ctl_warn, get_unit, ctl_opn
-   PUBLIC   mynode, mppstop, mppsync, mpp_comm_free
-   PUBLIC   mpp_ini_north, mpp_lbc_north, mpp_lbc_north_e
-   PUBLIC   mpp_min, mpp_max, mpp_sum, mpp_minloc, mpp_maxloc
-   PUBLIC   mpp_lnk_3d, mpp_lnk_3d_gather, mpp_lnk_2d, mpp_lnk_2d_e
-   PUBLIC   mppscatter, mppgather
-   PUBLIC   mppobc, mpp_ini_ice, mpp_ini_znl
-   PUBLIC   mppsize
-   PUBLIC   lib_mpp_alloc   ! Called in nemogcm.F90
-
-   !! * Interfaces
-   !! define generic interface for these routine as they are called sometimes
-   !! with scalar arguments instead of array arguments, which causes problems
-   !! for the compilation on AIX system as well as NEC and SGI. Ok on COMPACQ
-   INTERFACE mpp_min
-      MODULE PROCEDURE mppmin_a_int, mppmin_int, mppmin_a_real, mppmin_real
-   END INTERFACE
-   INTERFACE mpp_max
-      MODULE PROCEDURE mppmax_a_int, mppmax_int, mppmax_a_real, mppmax_real
-   END INTERFACE
-   INTERFACE mpp_sum
-# if defined key_mpp_rep
-      MODULE PROCEDURE mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real, &
-                       mppsum_realdd, mppsum_a_realdd
-# else
-      MODULE PROCEDURE mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real
-# endif
-   END INTERFACE
-   INTERFACE mpp_lbc_north
-      MODULE PROCEDURE mpp_lbc_north_3d, mpp_lbc_north_2d 
-   END INTERFACE
-   INTERFACE mpp_minloc
-      MODULE PROCEDURE mpp_minloc2d ,mpp_minloc3d
-   END INTERFACE
-   INTERFACE mpp_maxloc
-      MODULE PROCEDURE mpp_maxloc2d ,mpp_maxloc3d
-   END INTERFACE
-   
-   !! ========================= !!
-   !!  MPI  variable definition !!
-   !! ========================= !!
-!$AGRIF_DO_NOT_TREAT
-   INCLUDE 'mpif.h'
-!$AGRIF_END_DO_NOT_TREAT
-   
-   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .TRUE.    !: mpp flag
-
-   INTEGER, PARAMETER         ::   nprocmax = 2**10   ! maximun dimension (required to be a power of 2)
-   
-   INTEGER ::   mppsize        ! number of process
-   INTEGER ::   mpprank        ! process number  [ 0 - size-1 ]
-!$AGRIF_DO_NOT_TREAT
-   INTEGER, PUBLIC ::   mpi_comm_opa   ! opa local communicator
-!$AGRIF_END_DO_NOT_TREAT
-
-# if defined key_mpp_rep
-   INTEGER :: MPI_SUMDD
-# endif
-
-   ! variables used in case of sea-ice
-   INTEGER, PUBLIC ::   ncomm_ice       !: communicator made by the processors with sea-ice
-   INTEGER ::   ngrp_ice        !  group ID for the ice processors (for rheology)
-   INTEGER ::   ndim_rank_ice   !  number of 'ice' processors
-   INTEGER ::   n_ice_root      !  number (in the comm_ice) of proc 0 in the ice comm
-   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE ::   nrank_ice     ! dimension ndim_rank_ice
-
-   ! variables used for zonal integration
-   INTEGER, PUBLIC ::   ncomm_znl       !: communicator made by the processors on the same zonal average
-   LOGICAL, PUBLIC ::   l_znl_root      ! True on the 'left'most processor on the same row
-   INTEGER ::   ngrp_znl        ! group ID for the znl processors
-   INTEGER ::   ndim_rank_znl   ! number of processors on the same zonal average
-   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE ::   nrank_znl  ! dimension ndim_rank_znl, number of the procs into the same znl domain
-   
-   ! North fold condition in mpp_mpi with jpni > 1
-   INTEGER ::   ngrp_world        ! group ID for the world processors
-   INTEGER ::   ngrp_opa          ! group ID for the opa processors
-   INTEGER ::   ngrp_north        ! group ID for the northern processors (to be fold)
-   INTEGER ::   ncomm_north       ! communicator made by the processors belonging to ngrp_north
-   INTEGER ::   ndim_rank_north   ! number of 'sea' processor in the northern line (can be /= jpni !)
-   INTEGER ::   njmppmax          ! value of njmpp for the processors of the northern line
-   INTEGER ::   north_root        ! number (in the comm_opa) of proc 0 in the northern comm
-   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE ::   nrank_north   ! dimension ndim_rank_north
-
-   ! Type of send : standard, buffered, immediate
-   CHARACTER(len=1) ::   cn_mpi_send = 'S'    ! type od mpi send/recieve (S=standard, B=bsend, I=isend)
-   LOGICAL          ::   l_isend = .FALSE.   ! isend use indicator (T if cn_mpi_send='I')
-   INTEGER          ::   nn_buffer = 0       ! size of the buffer in case of mpi_bsend 
-      
-   REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE :: tampon  ! buffer in case of bsend
-
-   ! message passing arrays
-   REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE, SAVE ::   t4ns, t4sn   ! 2 x 3d for north-south & south-north
-   REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE, SAVE ::   t4ew, t4we   ! 2 x 3d for east-west & west-east
-   REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE, SAVE ::   t4p1, t4p2   ! 2 x 3d for north fold
-   REAL(wp), DIMENSION(:,:,:,:)  , ALLOCATABLE, SAVE ::   t3ns, t3sn   ! 3d for north-south & south-north
-   REAL(wp), DIMENSION(:,:,:,:)  , ALLOCATABLE, SAVE ::   t3ew, t3we   ! 3d for east-west & west-east
-   REAL(wp), DIMENSION(:,:,:,:)  , ALLOCATABLE, SAVE ::   t3p1, t3p2   ! 3d for north fold
-   REAL(wp), DIMENSION(:,:,:)    , ALLOCATABLE, SAVE ::   t2ns, t2sn   ! 2d for north-south & south-north
-   REAL(wp), DIMENSION(:,:,:)    , ALLOCATABLE, SAVE ::   t2ew, t2we   ! 2d for east-west & west-east
-   REAL(wp), DIMENSION(:,:,:)    , ALLOCATABLE, SAVE ::   t2p1, t2p2   ! 2d for north fold
-   REAL(wp), DIMENSION(:,:,:)    , ALLOCATABLE, SAVE ::   tr2ns, tr2sn ! 2d for north-south & south-north + extra outer halo
-   REAL(wp), DIMENSION(:,:,:)    , ALLOCATABLE, SAVE ::   tr2ew, tr2we ! 2d for east-west   & west-east   + extra outer halo
-
-   ! Arrays used in mpp_lbc_north_3d()
-   REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE, SAVE   ::   ztab, znorthloc
-   REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE, SAVE   ::   znorthgloio
-   REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE, SAVE   ::   zfoldwk      ! Workspace for message transfers avoiding mpi_allgather
-
-   ! Arrays used in mpp_lbc_north_2d()
-   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE, SAVE    ::   ztab_2d, znorthloc_2d
-   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE, SAVE    ::   znorthgloio_2d
-   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE, SAVE    ::   zfoldwk_2d    ! Workspace for message transfers avoiding mpi_allgather
-
-   ! Arrays used in mpp_lbc_north_e()
-   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE, SAVE    ::   ztab_e, znorthloc_e
-   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE, SAVE    ::   znorthgloio_e
-
-   ! North fold arrays used to minimise the use of allgather operations. Set in nemo_northcomms (nemogcm) so need to be public
-   INTEGER, PUBLIC,  PARAMETER :: jpmaxngh = 8                 ! Assumed maximum number of active neighbours
-   INTEGER, PUBLIC,  PARAMETER :: jptyps   = 5                 ! Number of different neighbour lists to be used for northfold exchanges 
-   INTEGER, PUBLIC,  DIMENSION (jpmaxngh,jptyps)    ::   isendto
-   INTEGER, PUBLIC,  DIMENSION (jptyps)             ::   nsndto
-   LOGICAL, PUBLIC                                  ::   ln_nnogather     = .FALSE.  ! namelist control of northfold comms
-   LOGICAL, PUBLIC                                  ::   l_north_nogather = .FALSE.  ! internal control of northfold comms
-   INTEGER, PUBLIC                                  ::   ityp
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: lib_mpp.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION lib_mpp_alloc( kumout )
-      !!----------------------------------------------------------------------
-      !!              ***  routine lib_mpp_alloc  ***
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kumout   ! ocean.output logical unit
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( t4ns(jpi,jprecj,jpk,2,2) , t4sn(jpi,jprecj,jpk,2,2) ,                                            &
-         &      t4ew(jpj,jpreci,jpk,2,2) , t4we(jpj,jpreci,jpk,2,2) ,                                            &
-         &      t4p1(jpi,jprecj,jpk,2,2) , t4p2(jpi,jprecj,jpk,2,2) ,                                            &
-         &      t3ns(jpi,jprecj,jpk,2)   , t3sn(jpi,jprecj,jpk,2)   ,                                            &
-         &      t3ew(jpj,jpreci,jpk,2)   , t3we(jpj,jpreci,jpk,2)   ,                                            &
-         &      t3p1(jpi,jprecj,jpk,2)   , t3p2(jpi,jprecj,jpk,2)   ,                                            &
-         &      t2ns(jpi,jprecj    ,2)   , t2sn(jpi,jprecj    ,2)   ,                                            &
-         &      t2ew(jpj,jpreci    ,2)   , t2we(jpj,jpreci    ,2)   ,                                            &
-         &      t2p1(jpi,jprecj    ,2)   , t2p2(jpi,jprecj    ,2)   ,                                            &
-         !
-         &      tr2ns(1-jpr2di:jpi+jpr2di,jprecj+jpr2dj,2) ,                                                     &
-         &      tr2sn(1-jpr2di:jpi+jpr2di,jprecj+jpr2dj,2) ,                                                     &
-         &      tr2ew(1-jpr2dj:jpj+jpr2dj,jpreci+jpr2di,2) ,                                                     &
-         &      tr2we(1-jpr2dj:jpj+jpr2dj,jpreci+jpr2di,2) ,                                                     &
-         !
-         &      ztab(jpiglo,4,jpk) , znorthloc(jpi,4,jpk) , znorthgloio(jpi,4,jpk,jpni) ,                        &
-         &      zfoldwk(jpi,4,jpk) ,                                                                             &
-         !
-         &      ztab_2d(jpiglo,4)  , znorthloc_2d(jpi,4)  , znorthgloio_2d(jpi,4,jpni)  ,                        &
-         &      zfoldwk_2d(jpi,4)  ,                                                                             &
-         !
-         &      ztab_e(jpiglo,4+2*jpr2dj) , znorthloc_e(jpi,4+2*jpr2dj) , znorthgloio_e(jpi,4+2*jpr2dj,jpni) ,   &
-         !
-         &      STAT=lib_mpp_alloc )
-         !
-      IF( lib_mpp_alloc /= 0 ) THEN
-         WRITE(kumout,cform_war)
-         WRITE(kumout,*) 'lib_mpp_alloc : failed to allocate arrays'
-      ENDIF
-      !
-   END FUNCTION lib_mpp_alloc
-
-
-   FUNCTION mynode( ldtxt, kumnam, kstop, localComm )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mynode  ***
-      !!                    
-      !! ** Purpose :   Find processor unit
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*),DIMENSION(:), INTENT(  out) ::   ldtxt 
-      INTEGER                      , INTENT(in   ) ::   kumnam       ! namelist logical unit 
-      INTEGER                      , INTENT(inout) ::   kstop        ! stop indicator 
-      INTEGER, OPTIONAL            , INTENT(in   ) ::   localComm
-      !
-      INTEGER ::   mynode, ierr, code, ji, ii
-      LOGICAL ::   mpi_was_called
-      !
-      NAMELIST/nammpp/ cn_mpi_send, nn_buffer, jpni, jpnj, jpnij, ln_nnogather
-      !!----------------------------------------------------------------------
-      !
-      ii = 1
-      WRITE(ldtxt(ii),*)                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'mynode : mpi initialisation'                                            ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~ '                                                                ;   ii = ii + 1
-      !
-      jpni = -1; jpnj = -1; jpnij = -1
-      REWIND( kumnam )               ! Namelist namrun : parameters of the run
-      READ  ( kumnam, nammpp )
-      !                              ! control print
-      WRITE(ldtxt(ii),*) '   Namelist nammpp'                                                     ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      mpi send type                      cn_mpi_send = ', cn_mpi_send   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      size in bytes of exported buffer   nn_buffer   = ', nn_buffer     ;   ii = ii + 1
-
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN
-         jpni  = Agrif_Parent(jpni ) 
-         jpnj  = Agrif_Parent(jpnj )
-         jpnij = Agrif_Parent(jpnij)
-      ENDIF
-#endif
-
-      IF(jpnij < 1)THEN
-         ! If jpnij is not specified in namelist then we calculate it - this
-         ! means there will be no land cutting out.
-         jpnij = jpni * jpnj
-      END IF
-
-      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
-         WRITE(ldtxt(ii),*) '      jpni, jpnj and jpnij will be calculated automatically'; ii = ii + 1
-      ELSE
-         WRITE(ldtxt(ii),*) '      processor grid extent in i         jpni = ',jpni; ii = ii + 1
-         WRITE(ldtxt(ii),*) '      processor grid extent in j         jpnj = ',jpnj; ii = ii + 1
-         WRITE(ldtxt(ii),*) '      number of local domains           jpnij = ',jpnij; ii = ii +1
-      END IF
-
-      WRITE(ldtxt(ii),*) '      avoid use of mpi_allgather at the north fold  ln_nnogather = ', ln_nnogather  ; ii = ii + 1
-
-      CALL mpi_initialized ( mpi_was_called, code )
-      IF( code /= MPI_SUCCESS ) THEN
-         DO ji = 1, SIZE(ldtxt) 
-            IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-         END DO         
-         WRITE(*, cform_err)
-         WRITE(*, *) 'lib_mpp: Error in routine mpi_initialized'
-         CALL mpi_abort( mpi_comm_world, code, ierr )
-      ENDIF
-
-      IF( mpi_was_called ) THEN
-         !
-         SELECT CASE ( cn_mpi_send )
-         CASE ( 'S' )                ! Standard mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'                     ;   ii = ii + 1
-         CASE ( 'B' )                ! Buffer mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'                      ;   ii = ii + 1
-            IF( Agrif_Root() )   CALL mpi_init_opa( ldtxt, ii, ierr ) 
-         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'                   ;   ii = ii + 1
-            l_isend = .TRUE.
-         CASE DEFAULT
-            WRITE(ldtxt(ii),cform_err)                                                            ;   ii = ii + 1
-            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send             ;   ii = ii + 1
-            kstop = kstop + 1
-         END SELECT
-      ELSE IF ( PRESENT(localComm) .and. .not. mpi_was_called ) THEN
-         WRITE(ldtxt(ii),*) ' lib_mpp: You cannot provide a local communicator '                  ;   ii = ii + 1
-         WRITE(ldtxt(ii),*) '          without calling MPI_Init before ! '                        ;   ii = ii + 1
-         kstop = kstop + 1
-      ELSE
-         SELECT CASE ( cn_mpi_send )
-         CASE ( 'S' )                ! Standard mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'                     ;   ii = ii + 1
-            CALL mpi_init( ierr )
-         CASE ( 'B' )                ! Buffer mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'                      ;   ii = ii + 1
-            IF( Agrif_Root() )   CALL mpi_init_opa( ldtxt, ii, ierr )
-         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'                   ;   ii = ii + 1
-            l_isend = .TRUE.
-            CALL mpi_init( ierr )
-         CASE DEFAULT
-            WRITE(ldtxt(ii),cform_err)                                                            ;   ii = ii + 1
-            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send             ;   ii = ii + 1
-            kstop = kstop + 1
-         END SELECT
-         !
-      ENDIF
-
-      IF( PRESENT(localComm) ) THEN 
-         IF( Agrif_Root() ) THEN
-            mpi_comm_opa = localComm
-         ENDIF
-      ELSE
-         CALL mpi_comm_dup( mpi_comm_world, mpi_comm_opa, code)
-         IF( code /= MPI_SUCCESS ) THEN
-            DO ji = 1, SIZE(ldtxt) 
-               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-            END DO
-            WRITE(*, cform_err)
-            WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
-            CALL mpi_abort( mpi_comm_world, code, ierr )
-         ENDIF
-      ENDIF 
-
-      CALL mpi_comm_rank( mpi_comm_opa, mpprank, ierr )
-      CALL mpi_comm_size( mpi_comm_opa, mppsize, ierr )
-      mynode = mpprank
-      ! 
-#if defined key_mpp_rep
-      CALL MPI_OP_CREATE(DDPDD_MPI, .TRUE., MPI_SUMDD, ierr)
-#endif
-      !
-   END FUNCTION mynode
-
-
-   SUBROUTINE mpp_lnk_3d( ptab, cd_type, psgn, cd_mpp, pval, ldup )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_3d  ***
-      !!
-      !! ** Purpose :   Message passing manadgement
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask 
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors 
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !! ** Action  :   ptab with update value at its periphery
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
-      !                                                             ! = T , U , V , F , W points
-      REAL(wp)                        , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
-      !                                                             ! =  1. , the sign is kept
-      CHARACTER(len=3), OPTIONAL      , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only 
-      REAL(wp)        , OPTIONAL      , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
-      LOGICAL         , OPTIONAL      , INTENT(in   ) ::   ldup     ! duplicate value (used at closed boundaries)
-      !!
-      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !!----------------------------------------------------------------------
-
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0.e0      ! zero by default
-      ENDIF
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
-         !
-         ! WARNING ptab is defined only between nld and nle
-         DO jk = 1, jpk
-            DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
-               ptab(nldi  :nlei  , jj          ,jk) = ptab(nldi:nlei,     nlej,jk)   
-               ptab(1     :nldi-1, jj          ,jk) = ptab(nldi     ,     nlej,jk)
-               ptab(nlei+1:nlci  , jj          ,jk) = ptab(     nlei,     nlej,jk)
-            END DO
-            DO ji = nlci+1, jpi                 ! added column(s) (full)
-               ptab(ji           ,nldj  :nlej  ,jk) = ptab(     nlei,nldj:nlej,jk)
-               ptab(ji           ,1     :nldj-1,jk) = ptab(     nlei,nldj     ,jk)
-               ptab(ji           ,nlej+1:jpj   ,jk) = ptab(     nlei,     nlej,jk)
-            END DO
-         END DO
-         !
-      ELSE                              ! standard close or cyclic treatment 
-         !
-         !                                   ! East-West boundaries
-         !                                        !* Cyclic east-west
-         IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-            ptab( 1 ,:,:) = ptab(jpim1,:,:)
-            ptab(jpi,:,:) = ptab(  2  ,:,:)
-         ELSEIF ( nperio == 0 .AND. PRESENT( ldup ) ) THEN
-            ptab(3,:,:) = ptab(2,:,:)
-            ptab(:,3,:) = ptab(:,2,:)
-            ptab(nlci-2,:,:) = ptab(nlci-1,:,:)
-            ptab(:,nlcj-2,:) = ptab(:,nlcj-1,:)
-           
-         ELSE                                     !* closed
-            IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
-                                         ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
-         ENDIF
-         !                                   ! North-South boundaries (always closed)
-         IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj,:) = zland       ! south except F-point
-                                      ptab(:,nlcj-jprecj+1:jpj   ,:) = zland       ! north
-         !
-      ENDIF
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity 
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci
-         DO jl = 1, jpreci
-            t3ew(:,jl,:,1) = ptab(jpreci+jl,:,:)
-            t3we(:,jl,:,1) = ptab(iihom +jl,:,:)
-         END DO
-      END SELECT  
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj * jpk
-      !
-      SELECT CASE ( nbondi ) 
-      CASE ( -1 )
-         CALL mppsend( 2, t3we(1,1,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, t3ew(1,1,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, t3ew(1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, t3we(1,1,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, t3ew(1,1,1,2), imigr, noea )
-         CALL mpprecv( 2, t3we(1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, t3ew(1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, t3we(1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci-jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            ptab(iihom+jl,:,:) = t3ew(:,jl,:,2)
-         END DO
-      CASE ( 0 ) 
-         DO jl = 1, jpreci
-            ptab(jl      ,:,:) = t3we(:,jl,:,2)
-            ptab(iihom+jl,:,:) = t3ew(:,jl,:,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            ptab(jl      ,:,:) = t3we(:,jl,:,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj
-         DO jl = 1, jprecj
-            t3sn(:,jl,:,1) = ptab(:,ijhom +jl,:)
-            t3ns(:,jl,:,1) = ptab(:,jprecj+jl,:)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi * jpk
-      !
-      SELECT CASE ( nbondj )     
-      CASE ( -1 )
-         CALL mppsend( 4, t3sn(1,1,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, t3ns(1,1,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, t3ns(1,1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, t3sn(1,1,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, t3ns(1,1,1,2), imigr, nono )
-         CALL mpprecv( 4, t3sn(1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 ) 
-         CALL mppsend( 3, t3ns(1,1,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, t3sn(1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj-jprecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            ptab(:,ijhom+jl,:) = t3ns(:,jl,:,2)
-         END DO
-      CASE ( 0 ) 
-         DO jl = 1, jprecj
-            ptab(:,jl      ,:) = t3sn(:,jl,:,2)
-            ptab(:,ijhom+jl,:) = t3ns(:,jl,:,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            ptab(:,jl,:) = t3sn(:,jl,:,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-      !
-   END SUBROUTINE mpp_lnk_3d
-
-
-   SUBROUTINE mpp_lnk_2d( pt2d, cd_type, psgn, cd_mpp, pval, ldup )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_2d  ***
-      !!                  
-      !! ** Purpose :   Message passing manadgement for 2d array
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask 
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors 
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d     ! 2D array on which the boundary condition is applied
-      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
-      !                                                         ! = T , U , V , F , W and I points
-      REAL(wp)                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
-      !                                                         ! =  1. , the sign is kept
-      CHARACTER(len=3), OPTIONAL  , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only 
-      REAL(wp)        , OPTIONAL  , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
-      LOGICAL         , OPTIONAL  , INTENT(in   ) ::   ldup     ! duplicate value (used at closed boundaries)
-      !!
-      INTEGER  ::   ji, jj, jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !!----------------------------------------------------------------------
-
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0.e0      ! zero by default
-      ENDIF
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      !
-      IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
-         !
-         ! WARNING pt2d is defined only between nld and nle
-         DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
-            pt2d(nldi  :nlei  , jj          ) = pt2d(nldi:nlei,     nlej)   
-            pt2d(1     :nldi-1, jj          ) = pt2d(nldi     ,     nlej)
-            pt2d(nlei+1:nlci  , jj          ) = pt2d(     nlei,     nlej)
-         END DO
-         DO ji = nlci+1, jpi                 ! added column(s) (full)
-            pt2d(ji           ,nldj  :nlej  ) = pt2d(     nlei,nldj:nlej)
-            pt2d(ji           ,1     :nldj-1) = pt2d(     nlei,nldj     )
-            pt2d(ji           ,nlej+1:jpj   ) = pt2d(     nlei,     nlej)
-         END DO
-         !
-      ELSE                              ! standard close or cyclic treatment 
-         !
-         !                                   ! East-West boundaries
-         IF( nbondi == 2 .AND.   &                ! Cyclic east-west
-            &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-            pt2d( 1 ,:) = pt2d(jpim1,:)                                    ! west
-            pt2d(jpi,:) = pt2d(  2  ,:)                                    ! east
-         ELSEIF ( nperio == 0 .AND. PRESENT( ldup ) ) THEN
-            pt2d(3,:) = pt2d(2,:)
-            pt2d(:,3) = pt2d(:,2)
-            pt2d(nlci-2,:) = pt2d(nlci-1,:)
-            pt2d(:,nlcj-2) = pt2d(:,nlcj-1)
-         ELSE                                     ! closed
-            IF( .NOT. cd_type == 'F' )   pt2d(     1       :jpreci,:) = zland    ! south except F-point
-                                         pt2d(nlci-jpreci+1:jpi   ,:) = zland    ! north
-         ENDIF
-         !                                   ! North-South boundaries (always closed)
-            IF( .NOT. cd_type == 'F' )   pt2d(:,     1       :jprecj) = zland    !south except F-point
-                                         pt2d(:,nlcj-jprecj+1:jpj   ) = zland    ! north
-         !
-      ENDIF
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity 
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci
-         DO jl = 1, jpreci
-            t2ew(:,jl,1) = pt2d(jpreci+jl,:)
-            t2we(:,jl,1) = pt2d(iihom +jl,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, t2ew(1,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, t2ew(1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, t2ew(1,1,2), imigr, noea )
-         CALL mpprecv( 2, t2we(1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, t2ew(1,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, t2we(1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            pt2d(iihom+jl,:) = t2ew(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jpreci
-            pt2d(jl      ,:) = t2we(:,jl,2)
-            pt2d(iihom+jl,:) = t2ew(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            pt2d(jl      ,:) = t2we(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj
-         DO jl = 1, jprecj
-            t2sn(:,jl,1) = pt2d(:,ijhom +jl)
-            t2ns(:,jl,1) = pt2d(:,jprecj+jl)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, t2sn(1,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, t2ns(1,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, t2ns(1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, t2sn(1,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, t2ns(1,1,2), imigr, nono )
-         CALL mpprecv( 4, t2sn(1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, t2ns(1,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, t2sn(1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            pt2d(:,ijhom+jl) = t2ns(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jprecj
-            pt2d(:,jl      ) = t2sn(:,jl,2)
-            pt2d(:,ijhom+jl) = t2ns(:,jl,2)
-         END DO
-      CASE ( 1 ) 
-         DO jl = 1, jprecj
-            pt2d(:,jl      ) = t2sn(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd      ( pt2d, cd_type, psgn )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_lbc_north( pt2d, cd_type, psgn )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-      !
-   END SUBROUTINE mpp_lnk_2d
-
-
-   SUBROUTINE mpp_lnk_3d_gather( ptab1, cd_type1, ptab2, cd_type2, psgn )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_3d_gather  ***
-      !!
-      !! ** Purpose :   Message passing manadgement for two 3D arrays
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask 
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors 
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !! ** Action  :   ptab1 and ptab2  with update value at its periphery
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab1     ! first and second 3D array on which 
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab2     ! the boundary condition is applied
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type1  ! nature of ptab1 and ptab2 arrays 
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type2  ! i.e. grid-points = T , U , V , F or W points
-      REAL(wp)                        , INTENT(in   ) ::   psgn      ! =-1 the sign change across the north fold boundary
-      !!                                                             ! =  1. , the sign is kept
-      INTEGER  ::   jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !!----------------------------------------------------------------------
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      !                                      ! East-West boundaries
-      !                                           !* Cyclic east-west
-      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-         ptab1( 1 ,:,:) = ptab1(jpim1,:,:)
-         ptab1(jpi,:,:) = ptab1(  2  ,:,:)
-         ptab2( 1 ,:,:) = ptab2(jpim1,:,:)
-         ptab2(jpi,:,:) = ptab2(  2  ,:,:)
-      ELSE                                        !* closed
-         IF( .NOT. cd_type1 == 'F' )   ptab1(     1       :jpreci,:,:) = 0.e0    ! south except at F-point
-         IF( .NOT. cd_type2 == 'F' )   ptab2(     1       :jpreci,:,:) = 0.e0
-                                       ptab1(nlci-jpreci+1:jpi   ,:,:) = 0.e0    ! north
-                                       ptab2(nlci-jpreci+1:jpi   ,:,:) = 0.e0
-      ENDIF
-
-      
-      !                                      ! North-South boundaries
-      IF( .NOT. cd_type1 == 'F' )   ptab1(:,     1       :jprecj,:) = 0.e0    ! south except at F-point
-      IF( .NOT. cd_type2 == 'F' )   ptab2(:,     1       :jprecj,:) = 0.e0
-                                    ptab1(:,nlcj-jprecj+1:jpj   ,:) = 0.e0    ! north
-                                    ptab2(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
-
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity 
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci
-         DO jl = 1, jpreci
-            t4ew(:,jl,:,1,1) = ptab1(jpreci+jl,:,:)
-            t4we(:,jl,:,1,1) = ptab1(iihom +jl,:,:)
-            t4ew(:,jl,:,2,1) = ptab2(jpreci+jl,:,:)
-            t4we(:,jl,:,2,1) = ptab2(iihom +jl,:,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj * jpk *2
-      !
-      SELECT CASE ( nbondi ) 
-      CASE ( -1 )
-         CALL mppsend( 2, t4we(1,1,1,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, t4ew(1,1,1,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, t4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, t4we(1,1,1,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, t4ew(1,1,1,1,2), imigr, noea )
-         CALL mpprecv( 2, t4we(1,1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, t4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, t4we(1,1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            ptab1(iihom+jl,:,:) = t4ew(:,jl,:,1,2)
-            ptab2(iihom+jl,:,:) = t4ew(:,jl,:,2,2)
-         END DO
-      CASE ( 0 ) 
-         DO jl = 1, jpreci
-            ptab1(jl      ,:,:) = t4we(:,jl,:,1,2)
-            ptab1(iihom+jl,:,:) = t4ew(:,jl,:,1,2)
-            ptab2(jl      ,:,:) = t4we(:,jl,:,2,2)
-            ptab2(iihom+jl,:,:) = t4ew(:,jl,:,2,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            ptab1(jl      ,:,:) = t4we(:,jl,:,1,2)
-            ptab2(jl      ,:,:) = t4we(:,jl,:,2,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj - nrecj
-         DO jl = 1, jprecj
-            t4sn(:,jl,:,1,1) = ptab1(:,ijhom +jl,:)
-            t4ns(:,jl,:,1,1) = ptab1(:,jprecj+jl,:)
-            t4sn(:,jl,:,2,1) = ptab2(:,ijhom +jl,:)
-            t4ns(:,jl,:,2,1) = ptab2(:,jprecj+jl,:)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi * jpk * 2
-      !
-      SELECT CASE ( nbondj )     
-      CASE ( -1 )
-         CALL mppsend( 4, t4sn(1,1,1,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, t4ns(1,1,1,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, t4ns(1,1,1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, t4sn(1,1,1,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, t4ns(1,1,1,1,2), imigr, nono )
-         CALL mpprecv( 4, t4sn(1,1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 ) 
-         CALL mppsend( 3, t4ns(1,1,1,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, t4sn(1,1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            ptab1(:,ijhom+jl,:) = t4ns(:,jl,:,1,2)
-            ptab2(:,ijhom+jl,:) = t4ns(:,jl,:,2,2)
-         END DO
-      CASE ( 0 ) 
-         DO jl = 1, jprecj
-            ptab1(:,jl      ,:) = t4sn(:,jl,:,1,2)
-            ptab1(:,ijhom+jl,:) = t4ns(:,jl,:,1,2)
-            ptab2(:,jl      ,:) = t4sn(:,jl,:,2,2)
-            ptab2(:,ijhom+jl,:) = t4ns(:,jl,:,2,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            ptab1(:,jl,:) = t4sn(:,jl,:,1,2)
-            ptab2(:,jl,:) = t4sn(:,jl,:,2,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      IF( npolj /= 0 ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )                                           
-            CALL lbc_nfd      ( ptab1, cd_type1, psgn )   ! only for northern procs.
-            CALL lbc_nfd      ( ptab2, cd_type2, psgn )
-         CASE DEFAULT
-            CALL mpp_lbc_north( ptab1, cd_type1, psgn )   ! for all northern procs.
-            CALL mpp_lbc_north (ptab2, cd_type2, psgn)
-         END SELECT 
-         !
-      ENDIF
-      !
-   END SUBROUTINE mpp_lnk_3d_gather
-
-
-   SUBROUTINE mpp_lnk_2d_e( pt2d, cd_type, psgn )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_2d_e  ***
-      !!                  
-      !! ** Purpose :   Message passing manadgement for 2d array (with halo)
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask 
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    jpr2di : number of rows for extra outer halo
-      !!                    jpr2dj : number of columns for extra outer halo
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors 
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)                                            , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
-      !                                                                                         ! = T , U , V , F , W and I points
-      REAL(wp)                                                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the
-      !!                                                                                        ! north boundary, =  1. otherwise
-      INTEGER  ::   jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ipreci, iprecj             ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !!----------------------------------------------------------------------
-
-      ipreci = jpreci + jpr2di      ! take into account outer extra 2D overlap area
-      iprecj = jprecj + jpr2dj
-
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      ! Order matters Here !!!!
-      !
-      !                                      !* North-South boundaries (always colsed)
-      IF( .NOT. cd_type == 'F' )   pt2d(:,  1-jpr2dj   :  jprecj  ) = 0.e0    ! south except at F-point
-                                   pt2d(:,nlcj-jprecj+1:jpj+jpr2dj) = 0.e0    ! north
-                                
-      !                                      ! East-West boundaries
-      !                                           !* Cyclic east-west
-      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-         pt2d(1-jpr2di:     1    ,:) = pt2d(jpim1-jpr2di:  jpim1 ,:)       ! east
-         pt2d(   jpi  :jpi+jpr2di,:) = pt2d(     2      :2+jpr2di,:)       ! west
-         !
-      ELSE                                        !* closed
-         IF( .NOT. cd_type == 'F' )   pt2d(  1-jpr2di   :jpreci    ,:) = 0.e0    ! south except at F-point
-                                      pt2d(nlci-jpreci+1:jpi+jpr2di,:) = 0.e0    ! north
-      ENDIF
-      !
-
-      ! north fold treatment
-      ! -----------------------
-      IF( npolj /= 0 ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd        ( pt2d(1:jpi,1:jpj+jpr2dj), cd_type, psgn, pr2dj=jpr2dj )
-         CASE DEFAULT   ;   CALL mpp_lbc_north_e( pt2d                    , cd_type, psgn               )
-         END SELECT 
-         !
-      ENDIF
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity 
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci-jpr2di
-         DO jl = 1, ipreci
-            tr2ew(:,jl,1) = pt2d(jpreci+jl,:)
-            tr2we(:,jl,1) = pt2d(iihom +jl,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = ipreci * ( jpj + 2*jpr2dj)
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, tr2we(1-jpr2dj,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, tr2ew(1-jpr2dj,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, tr2ew(1-jpr2dj,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, tr2we(1-jpr2dj,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, tr2ew(1-jpr2dj,1,2), imigr, noea )
-         CALL mpprecv( 2, tr2we(1-jpr2dj,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, tr2ew(1-jpr2dj,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, tr2we(1-jpr2dj,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, ipreci
-            pt2d(iihom+jl,:) = tr2ew(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, ipreci
-            pt2d(jl-jpr2di,:) = tr2we(:,jl,2)
-            pt2d( iihom+jl,:) = tr2ew(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, ipreci
-            pt2d(jl-jpr2di,:) = tr2we(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj-jpr2dj
-         DO jl = 1, iprecj
-            tr2sn(:,jl,1) = pt2d(:,ijhom +jl)
-            tr2ns(:,jl,1) = pt2d(:,jprecj+jl)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = iprecj * ( jpi + 2*jpr2di )
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, tr2sn(1-jpr2di,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, tr2ns(1-jpr2di,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, tr2ns(1-jpr2di,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, tr2sn(1-jpr2di,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, tr2ns(1-jpr2di,1,2), imigr, nono )
-         CALL mpprecv( 4, tr2sn(1-jpr2di,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, tr2ns(1-jpr2di,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, tr2sn(1-jpr2di,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj  
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, iprecj
-            pt2d(:,ijhom+jl) = tr2ns(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, iprecj
-            pt2d(:,jl-jpr2dj) = tr2sn(:,jl,2)
-            pt2d(:,ijhom+jl ) = tr2ns(:,jl,2)
-         END DO
-      CASE ( 1 ) 
-         DO jl = 1, iprecj
-            pt2d(:,jl-jpr2dj) = tr2sn(:,jl,2)
-         END DO
-      END SELECT
-
-   END SUBROUTINE mpp_lnk_2d_e
-
-
-   SUBROUTINE mppsend( ktyp, pmess, kbytes, kdest, md_req )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsend  ***
-      !!                   
-      !! ** Purpose :   Send messag passing array
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), INTENT(inout) ::   pmess(*)   ! array of real
-      INTEGER , INTENT(in   ) ::   kbytes     ! size of the array pmess
-      INTEGER , INTENT(in   ) ::   kdest      ! receive process number
-      INTEGER , INTENT(in   ) ::   ktyp       ! tag of the message
-      INTEGER , INTENT(in   ) ::   md_req     ! argument for isend
-      !!
-      INTEGER ::   iflag
-      !!----------------------------------------------------------------------
-      !
-      SELECT CASE ( cn_mpi_send )
-      CASE ( 'S' )                ! Standard mpi send (blocking)
-         CALL mpi_send ( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_opa        , iflag )
-      CASE ( 'B' )                ! Buffer mpi send (blocking)
-         CALL mpi_bsend( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_opa        , iflag )
-      CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-         ! be carefull, one more argument here : the mpi request identifier..
-         CALL mpi_isend( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_opa, md_req, iflag )
-      END SELECT
-      !
-   END SUBROUTINE mppsend
-
-
-   SUBROUTINE mpprecv( ktyp, pmess, kbytes, ksource )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpprecv  ***
-      !!
-      !! ** Purpose :   Receive messag passing array
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), INTENT(inout) ::   pmess(*)   ! array of real
-      INTEGER , INTENT(in   ) ::   kbytes     ! suze of the array pmess
-      INTEGER , INTENT(in   ) ::   ktyp       ! Tag of the recevied message
-      INTEGER, OPTIONAL, INTENT(in) :: ksource    ! source process number 
-      !!
-      INTEGER :: istatus(mpi_status_size)
-      INTEGER :: iflag
-      INTEGER :: use_source
-      !!----------------------------------------------------------------------
-      !
-
-      ! If a specific process number has been passed to the receive call, 
-      ! use that one. Default is to use mpi_any_source
-      use_source=mpi_any_source
-      if(present(ksource)) then
-         use_source=ksource
-      end if
-
-      CALL mpi_recv( pmess, kbytes, mpi_double_precision, use_source, ktyp, mpi_comm_opa, istatus, iflag )
-      !
-   END SUBROUTINE mpprecv
-
-
-   SUBROUTINE mppgather( ptab, kp, pio )
-      !!----------------------------------------------------------------------
-      !!                   ***  routine mppgather  ***
-      !!                   
-      !! ** Purpose :   Transfert between a local subdomain array and a work 
-      !!     array which is distributed following the vertical level.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj),       INTENT(in   ) ::   ptab   ! subdomain input array
-      INTEGER ,                           INTENT(in   ) ::   kp     ! record length
-      REAL(wp), DIMENSION(jpi,jpj,jpnij), INTENT(  out) ::   pio    ! subdomain input array
-      !!
-      INTEGER :: itaille, ierror   ! temporary integer
-      !!---------------------------------------------------------------------
-      !
-      itaille = jpi * jpj
-      CALL mpi_gather( ptab, itaille, mpi_double_precision, pio, itaille     ,   &
-         &                            mpi_double_precision, kp , mpi_comm_opa, ierror ) 
-      !
-   END SUBROUTINE mppgather
-
-
-   SUBROUTINE mppscatter( pio, kp, ptab )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppscatter  ***
-      !!
-      !! ** Purpose :   Transfert between awork array which is distributed 
-      !!      following the vertical level and the local subdomain array.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpnij)  ::  pio        ! output array
-      INTEGER                             ::   kp        ! Tag (not used with MPI
-      REAL(wp), DIMENSION(jpi,jpj)        ::  ptab       ! subdomain array input
-      !!
-      INTEGER :: itaille, ierror   ! temporary integer
-      !!---------------------------------------------------------------------
-      !
-      itaille=jpi*jpj
-      !
-      CALL mpi_scatter( pio, itaille, mpi_double_precision, ptab, itaille     ,   &
-         &                            mpi_double_precision, kp  , mpi_comm_opa, ierror )
-      !
-   END SUBROUTINE mppscatter
-
-
-   SUBROUTINE mppmax_a_int( ktab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmax_a_int  ***
-      !! 
-      !! ** Purpose :   Find maximum value in an integer layout array
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                  ::   kdim   ! size of array
-      INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab   ! input array
-      INTEGER , INTENT(in   ), OPTIONAL        ::   kcom   ! 
-      !!
-      INTEGER :: ierror, localcomm   ! temporary integer
-      INTEGER, DIMENSION(kdim) ::   iwork
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_max, localcomm, ierror )
-      !
-      ktab(:) = iwork(:)
-      !
-   END SUBROUTINE mppmax_a_int
-
-
-   SUBROUTINE mppmax_int( ktab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmax_int  ***
-      !!
-      !! ** Purpose :   Find maximum value in an integer layout array
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(inout)           ::   ktab      ! ???
-      INTEGER, INTENT(in   ), OPTIONAL ::   kcom      ! ???
-      !! 
-      INTEGER ::   ierror, iwork, localcomm   ! temporary integer
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa 
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_max, localcomm, ierror)
-      !
-      ktab = iwork
-      !
-   END SUBROUTINE mppmax_int
-
-
-   SUBROUTINE mppmin_a_int( ktab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmin_a_int  ***
-      !! 
-      !! ** Purpose :   Find minimum value in an integer layout array
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER , INTENT( in  )                  ::   kdim        ! size of array
-      INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab        ! input array
-      INTEGER , INTENT( in  ), OPTIONAL        ::   kcom        ! input array
-      !!
-      INTEGER ::   ierror, localcomm   ! temporary integer
-      INTEGER, DIMENSION(kdim) ::   iwork
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_min, localcomm, ierror )
-      !
-      ktab(:) = iwork(:)
-      !
-   END SUBROUTINE mppmin_a_int
-
-
-   SUBROUTINE mppmin_int( ktab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmin_int  ***
-      !!
-      !! ** Purpose :   Find minimum value in an integer layout array
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(inout) ::   ktab      ! ???
-      INTEGER , INTENT( in  ), OPTIONAL        ::   kcom        ! input array
-      !!
-      INTEGER ::  ierror, iwork, localcomm
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-     CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_min, localcomm, ierror )
-      !
-      ktab = iwork
-      !
-   END SUBROUTINE mppmin_int
-
-
-   SUBROUTINE mppsum_a_int( ktab, kdim )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_a_int  ***
-      !!                    
-      !! ** Purpose :   Global integer sum, 1D array case
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in   )                   ::   kdim      ! ???
-      INTEGER, INTENT(inout), DIMENSION (kdim) ::   ktab      ! ???
-      !!
-      INTEGER :: ierror
-      INTEGER, DIMENSION (kdim) ::  iwork
-      !!----------------------------------------------------------------------
-      !
-      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_sum, mpi_comm_opa, ierror )
-      !
-      ktab(:) = iwork(:)
-      !
-   END SUBROUTINE mppsum_a_int
-
-
-   SUBROUTINE mppsum_int( ktab )
-      !!----------------------------------------------------------------------
-      !!                 ***  routine mppsum_int  ***
-      !!                  
-      !! ** Purpose :   Global integer sum
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(inout) ::   ktab
-      !! 
-      INTEGER :: ierror, iwork
-      !!----------------------------------------------------------------------
-      !
-      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_sum, mpi_comm_opa, ierror )
-      !
-      ktab = iwork
-      !
-   END SUBROUTINE mppsum_int
-
-
-   SUBROUTINE mppmax_a_real( ptab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                 ***  routine mppmax_a_real  ***
-      !!                  
-      !! ** Purpose :   Maximum
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                  ::   kdim
-      REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
-      INTEGER , INTENT(in   ), OPTIONAL        ::   kcom
-      !!
-      INTEGER :: ierror, localcomm
-      REAL(wp), DIMENSION(kdim) ::  zwork
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) ) localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_max, localcomm, ierror )
-      ptab(:) = zwork(:)
-      !
-   END SUBROUTINE mppmax_a_real
-
-
-   SUBROUTINE mppmax_real( ptab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmax_real  ***
-      !!                    
-      !! ** Purpose :   Maximum
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), INTENT(inout)           ::   ptab   ! ???
-      INTEGER , INTENT(in   ), OPTIONAL ::   kcom   ! ???
-      !!
-      INTEGER  ::   ierror, localcomm
-      REAL(wp) ::   zwork
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa 
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_max, localcomm, ierror )
-      ptab = zwork
-      !
-   END SUBROUTINE mppmax_real
-
-
-   SUBROUTINE mppmin_a_real( ptab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                 ***  routine mppmin_a_real  ***
-      !!                  
-      !! ** Purpose :   Minimum of REAL, array case
-      !!
-      !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                  ::   kdim
-      REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
-      INTEGER , INTENT(in   ), OPTIONAL        ::   kcom
-      !!
-      INTEGER :: ierror, localcomm
-      REAL(wp), DIMENSION(kdim) ::   zwork
-      !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa 
-      IF( PRESENT(kcom) ) localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_min, localcomm, ierror )
-      ptab(:) = zwork(:)
-      !
-   END SUBROUTINE mppmin_a_real
-
-
-   SUBROUTINE mppmin_real( ptab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmin_real  ***
-      !! 
-      !! ** Purpose :   minimum of REAL, scalar case
-      !!
-      !!-----------------------------------------------------------------------
-      REAL(wp), INTENT(inout)           ::   ptab        ! 
-      INTEGER , INTENT(in   ), OPTIONAL :: kcom
-      !!
-      INTEGER  ::   ierror
-      REAL(wp) ::   zwork
-      INTEGER :: localcomm
-      !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa 
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_min, localcomm, ierror )
-      ptab = zwork
-      !
-   END SUBROUTINE mppmin_real
-
-
-   SUBROUTINE mppsum_a_real( ptab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_a_real  ***
-      !! 
-      !! ** Purpose :   global sum, REAL ARRAY argument case
-      !!
-      !!-----------------------------------------------------------------------
-      INTEGER , INTENT( in )                     ::   kdim      ! size of ptab
-      REAL(wp), DIMENSION(kdim), INTENT( inout ) ::   ptab      ! input array
-      INTEGER , INTENT( in ), OPTIONAL           :: kcom
-      !!
-      INTEGER                   ::   ierror    ! temporary integer
-      INTEGER                   ::   localcomm 
-      REAL(wp), DIMENSION(kdim) ::   zwork     ! temporary workspace 
-      !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa 
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_sum, localcomm, ierror )
-      ptab(:) = zwork(:)
-      !
-   END SUBROUTINE mppsum_a_real
-
-
-   SUBROUTINE mppsum_real( ptab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_real  ***
-      !!              
-      !! ** Purpose :   global sum, SCALAR argument case
-      !!
-      !!-----------------------------------------------------------------------
-      REAL(wp), INTENT(inout)           ::   ptab   ! input scalar
-      INTEGER , INTENT(in   ), OPTIONAL ::   kcom
-      !!
-      INTEGER  ::   ierror, localcomm 
-      REAL(wp) ::   zwork
-      !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa 
-      IF( PRESENT(kcom) ) localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_sum, localcomm, ierror )
-      ptab = zwork
-      !
-   END SUBROUTINE mppsum_real
-
-# if defined key_mpp_rep
-   SUBROUTINE mppsum_realdd( ytab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_realdd ***
-      !!
-      !! ** Purpose :   global sum in Massively Parallel Processing
-      !!                SCALAR argument case for double-double precision
-      !!
-      !!-----------------------------------------------------------------------
-      COMPLEX(wp), INTENT(inout)         :: ytab    ! input scalar
-      INTEGER , INTENT( in  ), OPTIONAL :: kcom
-
-      !! * Local variables   (MPI version)
-      INTEGER  ::    ierror
-      INTEGER  ::   localcomm
-      COMPLEX(wp) :: zwork
-
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) ) localcomm = kcom
-
-      ! reduce local sums into global sum
-      CALL MPI_ALLREDUCE (ytab, zwork, 1, MPI_DOUBLE_COMPLEX, &
-                       MPI_SUMDD,localcomm,ierror)
-      ytab = zwork
-
-   END SUBROUTINE mppsum_realdd
-  
-  
-   SUBROUTINE mppsum_a_realdd( ytab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_a_realdd  ***
-      !!
-      !! ** Purpose :   global sum in Massively Parallel Processing
-      !!                COMPLEX ARRAY case for double-double precision
-      !!
-      !!-----------------------------------------------------------------------
-      INTEGER , INTENT( in )                        ::   kdim      ! size of ytab
-      COMPLEX(wp), DIMENSION(kdim), INTENT( inout ) ::   ytab      ! input array
-      INTEGER , INTENT( in  ), OPTIONAL :: kcom
-
-      !! * Local variables   (MPI version)
-      INTEGER                      :: ierror    ! temporary integer
-      INTEGER                      ::   localcomm
-      COMPLEX(wp), DIMENSION(kdim) :: zwork     ! temporary workspace
-
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) ) localcomm = kcom
-
-      CALL MPI_ALLREDUCE (ytab, zwork, kdim, MPI_DOUBLE_COMPLEX, &
-                       MPI_SUMDD,localcomm,ierror)
-      ytab(:) = zwork(:)
-
-   END SUBROUTINE mppsum_a_realdd
-# endif   
-   
-   SUBROUTINE mpp_minloc2d( ptab, pmask, pmin, ki,kj )
-      !!------------------------------------------------------------------------
-      !!             ***  routine mpp_minloc  ***
-      !!
-      !! ** Purpose :   Compute the global minimum of an array ptab
-      !!              and also give its global position
-      !!
-      !! ** Method  :   Use MPI_ALLREDUCE with MPI_MINLOC
-      !!
-      !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   ptab    ! Local 2D array
-      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   pmask   ! Local mask
-      REAL(wp)                     , INTENT(  out) ::   pmin    ! Global minimum of ptab
-      INTEGER                      , INTENT(  out) ::   ki, kj   ! index of minimum in global frame
-      !!
-      INTEGER , DIMENSION(2)   ::   ilocs
-      INTEGER :: ierror
-      REAL(wp) ::   zmin   ! local minimum
-      REAL(wp), DIMENSION(2,1) ::   zain, zaout
-      !!-----------------------------------------------------------------------
-      !
-      zmin  = MINVAL( ptab(:,:) , mask= pmask == 1.e0 )
-      ilocs = MINLOC( ptab(:,:) , mask= pmask == 1.e0 )
-      !
-      ki = ilocs(1) + nimpp - 1
-      kj = ilocs(2) + njmpp - 1
-      !
-      zain(1,:)=zmin
-      zain(2,:)=ki+10000.*kj
-      !
-      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MINLOC,MPI_COMM_OPA,ierror)
-      !
-      pmin = zaout(1,1)
-      kj = INT(zaout(2,1)/10000.)
-      ki = INT(zaout(2,1) - 10000.*kj )
-      !
-   END SUBROUTINE mpp_minloc2d
-
-
-   SUBROUTINE mpp_minloc3d( ptab, pmask, pmin, ki, kj ,kk)
-      !!------------------------------------------------------------------------
-      !!             ***  routine mpp_minloc  ***
-      !!
-      !! ** Purpose :   Compute the global minimum of an array ptab
-      !!              and also give its global position
-      !!
-      !! ** Method  :   Use MPI_ALLREDUCE with MPI_MINLOC
-      !!
-      !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   ptab         ! Local 2D array
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pmask        ! Local mask
-      REAL(wp)                         , INTENT(  out) ::   pmin         ! Global minimum of ptab
-      INTEGER                          , INTENT(  out) ::   ki, kj, kk   ! index of minimum in global frame
-      !!
-      INTEGER  ::   ierror
-      REAL(wp) ::   zmin     ! local minimum
-      INTEGER , DIMENSION(3)   ::   ilocs
-      REAL(wp), DIMENSION(2,1) ::   zain, zaout
-      !!-----------------------------------------------------------------------
-      !
-      zmin  = MINVAL( ptab(:,:,:) , mask= pmask == 1.e0 )
-      ilocs = MINLOC( ptab(:,:,:) , mask= pmask == 1.e0 )
-      !
-      ki = ilocs(1) + nimpp - 1
-      kj = ilocs(2) + njmpp - 1
-      kk = ilocs(3)
-      !
-      zain(1,:)=zmin
-      zain(2,:)=ki+10000.*kj+100000000.*kk
-      !
-      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MINLOC,MPI_COMM_OPA,ierror)
-      !
-      pmin = zaout(1,1)
-      kk   = INT( zaout(2,1) / 100000000. )
-      kj   = INT( zaout(2,1) - kk * 100000000. ) / 10000
-      ki   = INT( zaout(2,1) - kk * 100000000. -kj * 10000. )
-      !
-   END SUBROUTINE mpp_minloc3d
-
-
-   SUBROUTINE mpp_maxloc2d( ptab, pmask, pmax, ki, kj )
-      !!------------------------------------------------------------------------
-      !!             ***  routine mpp_maxloc  ***
-      !!
-      !! ** Purpose :   Compute the global maximum of an array ptab
-      !!              and also give its global position
-      !!
-      !! ** Method  :   Use MPI_ALLREDUCE with MPI_MINLOC
-      !!
-      !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   ptab     ! Local 2D array
-      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   pmask    ! Local mask
-      REAL(wp)                     , INTENT(  out) ::   pmax     ! Global maximum of ptab
-      INTEGER                      , INTENT(  out) ::   ki, kj   ! index of maximum in global frame
-      !!  
-      INTEGER  :: ierror
-      INTEGER, DIMENSION (2)   ::   ilocs
-      REAL(wp) :: zmax   ! local maximum
-      REAL(wp), DIMENSION(2,1) ::   zain, zaout
-      !!-----------------------------------------------------------------------
-      !
-      zmax  = MAXVAL( ptab(:,:) , mask= pmask == 1.e0 )
-      ilocs = MAXLOC( ptab(:,:) , mask= pmask == 1.e0 )
-      !
-      ki = ilocs(1) + nimpp - 1
-      kj = ilocs(2) + njmpp - 1
-      !
-      zain(1,:) = zmax
-      zain(2,:) = ki + 10000. * kj
-      !
-      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MAXLOC,MPI_COMM_OPA,ierror)
-      !
-      pmax = zaout(1,1)
-      kj   = INT( zaout(2,1) / 10000.     )
-      ki   = INT( zaout(2,1) - 10000.* kj )
-      !
-   END SUBROUTINE mpp_maxloc2d
-
-
-   SUBROUTINE mpp_maxloc3d( ptab, pmask, pmax, ki, kj, kk )
-      !!------------------------------------------------------------------------
-      !!             ***  routine mpp_maxloc  ***
-      !!
-      !! ** Purpose :  Compute the global maximum of an array ptab
-      !!              and also give its global position
-      !!
-      !! ** Method : Use MPI_ALLREDUCE with MPI_MINLOC
-      !!
-      !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   ptab         ! Local 2D array
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pmask        ! Local mask
-      REAL(wp)                         , INTENT(  out) ::   pmax         ! Global maximum of ptab
-      INTEGER                          , INTENT(  out) ::   ki, kj, kk   ! index of maximum in global frame
-      !!   
-      REAL(wp) :: zmax   ! local maximum
-      REAL(wp), DIMENSION(2,1) ::   zain, zaout
-      INTEGER , DIMENSION(3)   ::   ilocs
-      INTEGER :: ierror
-      !!-----------------------------------------------------------------------
-      !
-      zmax  = MAXVAL( ptab(:,:,:) , mask= pmask == 1.e0 )
-      ilocs = MAXLOC( ptab(:,:,:) , mask= pmask == 1.e0 )
-      !
-      ki = ilocs(1) + nimpp - 1
-      kj = ilocs(2) + njmpp - 1
-      kk = ilocs(3)
-      !
-      zain(1,:)=zmax
-      zain(2,:)=ki+10000.*kj+100000000.*kk
-      !
-      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MAXLOC,MPI_COMM_OPA,ierror)
-      !
-      pmax = zaout(1,1)
-      kk   = INT( zaout(2,1) / 100000000. )
-      kj   = INT( zaout(2,1) - kk * 100000000. ) / 10000
-      ki   = INT( zaout(2,1) - kk * 100000000. -kj * 10000. )
-      !
-   END SUBROUTINE mpp_maxloc3d
-
-
-   SUBROUTINE mppsync()
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsync  ***
-      !!                   
-      !! ** Purpose :   Massively parallel processors, synchroneous
-      !!
-      !!-----------------------------------------------------------------------
-      INTEGER :: ierror
-      !!-----------------------------------------------------------------------
-      !
-      CALL mpi_barrier( mpi_comm_opa, ierror )
-      !
-   END SUBROUTINE mppsync
-
-
-   SUBROUTINE mppstop
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppstop  ***
-      !!                   
-      !! ** purpose :   Stop massively parallel processors method
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER ::   info
-      !!----------------------------------------------------------------------
-      !
-      CALL mppsync
-      CALL mpi_finalize( info )
-      !
-   END SUBROUTINE mppstop
-
-
-   SUBROUTINE mppobc( ptab, kd1, kd2, kl, kk, ktype, kij , kumout)
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppobc  ***
-      !! 
-      !! ** Purpose :   Message passing manadgement for open boundary
-      !!     conditions array
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!       between processors following neighboring subdomains.
-      !!       domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors 
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !!----------------------------------------------------------------------
-      USE wrk_nemo        ! Memory allocation
-      !
-      INTEGER , INTENT(in   )                     ::   kd1, kd2   ! starting and ending indices
-      INTEGER , INTENT(in   )                     ::   kl         ! index of open boundary
-      INTEGER , INTENT(in   )                     ::   kk         ! vertical dimension
-      INTEGER , INTENT(in   )                     ::   ktype      ! define north/south or east/west cdt
-      !                                                           !  = 1  north/south  ;  = 2  east/west
-      INTEGER , INTENT(in   )                     ::   kij        ! horizontal dimension
-      INTEGER , INTENT(in   )                     ::   kumout     ! ocean.output logical unit
-      REAL(wp), INTENT(inout), DIMENSION(kij,kk)  ::   ptab       ! variable array
-      !
-      INTEGER ::   ji, jj, jk, jl        ! dummy loop indices
-      INTEGER ::   iipt0, iipt1, ilpt1   ! local integers
-      INTEGER ::   ijpt0, ijpt1          !   -       -
-      INTEGER ::   imigr, iihom, ijhom   !   -       -
-      INTEGER ::   ml_req1, ml_req2, ml_err    ! for key_mpi_isend
-      INTEGER ::   ml_stat(MPI_STATUS_SIZE)    ! for key_mpi_isend
-      REAL(wp), POINTER, DIMENSION(:,:) ::   ztab   ! temporary workspace
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj, ztab )
-
-      ! boundary condition initialization
-      ! ---------------------------------
-      ztab(:,:) = 0.e0
-      !
-      IF( ktype==1 ) THEN                                  ! north/south boundaries
-         iipt0 = MAX( 1, MIN(kd1 - nimpp+1, nlci     ) )
-         iipt1 = MAX( 0, MIN(kd2 - nimpp+1, nlci - 1 ) )
-         ilpt1 = MAX( 1, MIN(kd2 - nimpp+1, nlci     ) )
-         ijpt0 = MAX( 1, MIN(kl  - njmpp+1, nlcj     ) )
-         ijpt1 = MAX( 0, MIN(kl  - njmpp+1, nlcj - 1 ) )
-      ELSEIF( ktype==2 ) THEN                              ! east/west boundaries
-         iipt0 = MAX( 1, MIN(kl  - nimpp+1, nlci     ) )
-         iipt1 = MAX( 0, MIN(kl  - nimpp+1, nlci - 1 ) )
-         ijpt0 = MAX( 1, MIN(kd1 - njmpp+1, nlcj     ) )
-         ijpt1 = MAX( 0, MIN(kd2 - njmpp+1, nlcj - 1 ) )
-         ilpt1 = MAX( 1, MIN(kd2 - njmpp+1, nlcj     ) )
-      ELSE
-         WRITE(kumout, cform_err)
-         WRITE(kumout,*) 'mppobc : bad ktype'
-         CALL mppstop
-      ENDIF
-      
-      ! Communication level by level
-      ! ----------------------------
-!!gm Remark : this is very time consumming!!!
-      !                                         ! ------------------------ !
-      DO jk = 1, kk                             !   Loop over the levels   !
-         !                                      ! ------------------------ !
-         !
-         IF( ktype == 1 ) THEN                               ! north/south boundaries
-            DO jj = ijpt0, ijpt1
-               DO ji = iipt0, iipt1
-                  ztab(ji,jj) = ptab(ji,jk)
-               END DO
-            END DO
-         ELSEIF( ktype == 2 ) THEN                           ! east/west boundaries
-            DO jj = ijpt0, ijpt1
-               DO ji = iipt0, iipt1
-                  ztab(ji,jj) = ptab(jj,jk)
-               END DO
-            END DO
-         ENDIF
-
-
-         ! 1. East and west directions
-         ! ---------------------------
-         !
-         IF( nbondi /= 2 ) THEN         ! Read Dirichlet lateral conditions
-            iihom = nlci-nreci
-            DO jl = 1, jpreci
-               t2ew(:,jl,1) = ztab(jpreci+jl,:)
-               t2we(:,jl,1) = ztab(iihom +jl,:)
-            END DO
-         ENDIF
-         !
-         !                              ! Migrations
-         imigr=jpreci*jpj
-         !
-         IF( nbondi == -1 ) THEN
-            CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req1 )
-            CALL mpprecv( 1, t2ew(1,1,2), imigr, noea )
-            IF(l_isend)   CALL mpi_wait( ml_req1, ml_stat, ml_err )
-         ELSEIF( nbondi == 0 ) THEN
-            CALL mppsend( 1, t2ew(1,1,1), imigr, nowe, ml_req1 )
-            CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req2 )
-            CALL mpprecv( 1, t2ew(1,1,2), imigr, noea )
-            CALL mpprecv( 2, t2we(1,1,2), imigr, nowe )
-            IF(l_isend)   CALL mpi_wait( ml_req1, ml_stat, ml_err )
-            IF(l_isend)   CALL mpi_wait( ml_req2, ml_stat, ml_err )
-         ELSEIF( nbondi == 1 ) THEN
-            CALL mppsend( 1, t2ew(1,1,1), imigr, nowe, ml_req1 )
-            CALL mpprecv( 2, t2we(1,1,2), imigr, nowe )
-            IF(l_isend) CALL mpi_wait( ml_req1, ml_stat, ml_err )
-         ENDIF
-         !
-         !                              ! Write Dirichlet lateral conditions
-         iihom = nlci-jpreci
-         !
-         IF( nbondi == 0 .OR. nbondi == 1 ) THEN
-            DO jl = 1, jpreci
-               ztab(jl,:) = t2we(:,jl,2)
-            END DO
-         ENDIF
-         IF( nbondi == -1 .OR. nbondi == 0 ) THEN
-            DO jl = 1, jpreci
-               ztab(iihom+jl,:) = t2ew(:,jl,2)
-            END DO
-         ENDIF
-
-
-         ! 2. North and south directions
-         ! -----------------------------
-         !
-         IF( nbondj /= 2 ) THEN         ! Read Dirichlet lateral conditions
-            ijhom = nlcj-nrecj
-            DO jl = 1, jprecj
-               t2sn(:,jl,1) = ztab(:,ijhom +jl)
-               t2ns(:,jl,1) = ztab(:,jprecj+jl)
-            END DO
-         ENDIF
-         !
-         !                              ! Migrations
-         imigr = jprecj * jpi
-         !
-         IF( nbondj == -1 ) THEN
-            CALL mppsend( 4, t2sn(1,1,1), imigr, nono, ml_req1 )
-            CALL mpprecv( 3, t2ns(1,1,2), imigr, nono )
-            IF(l_isend) CALL mpi_wait( ml_req1, ml_stat, ml_err )
-         ELSEIF( nbondj == 0 ) THEN
-            CALL mppsend( 3, t2ns(1,1,1), imigr, noso, ml_req1 )
-            CALL mppsend( 4, t2sn(1,1,1), imigr, nono, ml_req2 )
-            CALL mpprecv( 3, t2ns(1,1,2), imigr, nono )
-            CALL mpprecv( 4, t2sn(1,1,2), imigr, noso )
-            IF( l_isend )   CALL mpi_wait( ml_req1, ml_stat, ml_err )
-            IF( l_isend )   CALL mpi_wait( ml_req2, ml_stat, ml_err )
-         ELSEIF( nbondj == 1 ) THEN
-            CALL mppsend( 3, t2ns(1,1,1), imigr, noso, ml_req1 )
-            CALL mpprecv( 4, t2sn(1,1,2), imigr, noso)
-            IF( l_isend )   CALL mpi_wait( ml_req1, ml_stat, ml_err )
-         ENDIF
-         !
-         !                              ! Write Dirichlet lateral conditions
-         ijhom = nlcj - jprecj
-         IF( nbondj == 0 .OR. nbondj == 1 ) THEN
-            DO jl = 1, jprecj
-               ztab(:,jl) = t2sn(:,jl,2)
-            END DO
-         ENDIF
-         IF( nbondj == 0 .OR. nbondj == -1 ) THEN
-            DO jl = 1, jprecj
-               ztab(:,ijhom+jl) = t2ns(:,jl,2)
-            END DO
-         ENDIF
-         IF( ktype==1 .AND. kd1 <= jpi+nimpp-1 .AND. nimpp <= kd2 ) THEN
-            DO jj = ijpt0, ijpt1            ! north/south boundaries
-               DO ji = iipt0,ilpt1
-                  ptab(ji,jk) = ztab(ji,jj)  
-               END DO
-            END DO
-         ELSEIF( ktype==2 .AND. kd1 <= jpj+njmpp-1 .AND. njmpp <= kd2 ) THEN
-            DO jj = ijpt0, ilpt1            ! east/west boundaries
-               DO ji = iipt0,iipt1
-                  ptab(jj,jk) = ztab(ji,jj) 
-               END DO
-            END DO
-         ENDIF
-         !
-      END DO
-      !
-      CALL wrk_dealloc( jpi,jpj, ztab )
-      !
-   END SUBROUTINE mppobc
-   
-
-   SUBROUTINE mpp_comm_free( kcom )
-      !!----------------------------------------------------------------------
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kcom
-      !!
-      INTEGER :: ierr
-      !!----------------------------------------------------------------------
-      !
-      CALL MPI_COMM_FREE(kcom, ierr)
-      !
-   END SUBROUTINE mpp_comm_free
-
-
-   SUBROUTINE mpp_ini_ice( pindic, kumout )
-      !!----------------------------------------------------------------------
-      !!               ***  routine mpp_ini_ice  ***
-      !!
-      !! ** Purpose :   Initialize special communicator for ice areas
-      !!      condition together with global variables needed in the ddmpp folding
-      !!
-      !! ** Method  : - Look for ice processors in ice routines
-      !!              - Put their number in nrank_ice
-      !!              - Create groups for the world processors and the ice processors
-      !!              - Create a communicator for ice processors
-      !!
-      !! ** output
-      !!      njmppmax = njmpp for northern procs
-      !!      ndim_rank_ice = number of processors with ice
-      !!      nrank_ice (ndim_rank_ice) = ice processors
-      !!      ngrp_world = group ID for the world processors
-      !!      ngrp_ice = group ID for the ice processors
-      !!      ncomm_ice = communicator for the ice procs.
-      !!      n_ice_root = number (in the world) of proc 0 in the ice comm.
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   pindic
-      INTEGER, INTENT(in) ::   kumout   ! ocean.output logical unit
-      !!
-      INTEGER :: jjproc
-      INTEGER :: ii, ierr
-      INTEGER, ALLOCATABLE, DIMENSION(:) ::   kice
-      INTEGER, ALLOCATABLE, DIMENSION(:) ::   zwork
-      !!----------------------------------------------------------------------
-      !
-      ! Since this is just an init routine and these arrays are of length jpnij
-      ! then don't use wrk_nemo module - just allocate and deallocate.
-      ALLOCATE( kice(jpnij), zwork(jpnij), STAT=ierr )
-      IF( ierr /= 0 ) THEN
-         WRITE(kumout, cform_err)
-         WRITE(kumout,*) 'mpp_ini_ice : failed to allocate 2, 1D arrays (jpnij in length)'
-         CALL mppstop
-      ENDIF
-
-      ! Look for how many procs with sea-ice
-      !
-      kice = 0
-      DO jjproc = 1, jpnij
-         IF( jjproc == narea .AND. pindic .GT. 0 )   kice(jjproc) = 1    
-      END DO
-      !
-      zwork = 0
-      CALL MPI_ALLREDUCE( kice, zwork, jpnij, mpi_integer, mpi_sum, mpi_comm_opa, ierr )
-      ndim_rank_ice = SUM( zwork )          
- 
-      !SF ! if there is no ice in the domain, return to the main program (clem modif)
-     !SF  IF ( ndim_rank_ice == 0 ) THEN
-      !SF    DEALLOCATE(kice, zwork)
-     !SF     RETURN
-     !SF  ENDIF
-
-      ! Allocate the right size to nrank_north
-      IF( ALLOCATED ( nrank_ice ) )   DEALLOCATE( nrank_ice )
-      ALLOCATE( nrank_ice(ndim_rank_ice) )
-      !
-      ii = 0     
-      nrank_ice = 0
-      DO jjproc = 1, jpnij
-         IF( zwork(jjproc) == 1) THEN
-            ii = ii + 1
-            nrank_ice(ii) = jjproc -1 
-         ENDIF
-      END DO
-
-      ! Create the world group
-      CALL MPI_COMM_GROUP( mpi_comm_opa, ngrp_world, ierr )
- 
-      ! Create the ice group from the world group
-      CALL MPI_GROUP_INCL( ngrp_world, ndim_rank_ice, nrank_ice, ngrp_ice, ierr )
-
-      ! Create the ice communicator , ie the pool of procs with sea-ice
-      CALL MPI_COMM_CREATE( mpi_comm_opa, ngrp_ice, ncomm_ice, ierr )
-
-      ! Find proc number in the world of proc 0 in the north
-      ! The following line seems to be useless, we just comment & keep it as reminder
-      ! CALL MPI_GROUP_TRANSLATE_RANKS(ngrp_ice,1,0,ngrp_world,n_ice_root,ierr)
-      !
-      DEALLOCATE(kice, zwork)
-      !
-   END SUBROUTINE mpp_ini_ice
-
-
-   SUBROUTINE mpp_ini_znl( kumout )
-      !!----------------------------------------------------------------------
-      !!               ***  routine mpp_ini_znl  ***
-      !!
-      !! ** Purpose :   Initialize special communicator for computing zonal sum
-      !!
-      !! ** Method  : - Look for processors in the same row
-      !!              - Put their number in nrank_znl
-      !!              - Create group for the znl processors
-      !!              - Create a communicator for znl processors
-      !!              - Determine if processor should write znl files
-      !!
-      !! ** output
-      !!      ndim_rank_znl = number of processors on the same row
-      !!      ngrp_znl = group ID for the znl processors
-      !!      ncomm_znl = communicator for the ice procs.
-      !!      n_znl_root = number (in the world) of proc 0 in the ice comm.
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kumout   ! ocean.output logical units
-      !
-      INTEGER :: jproc      ! dummy loop integer
-      INTEGER :: ierr, ii   ! local integer
-      INTEGER, ALLOCATABLE, DIMENSION(:) ::   kwork
-      !!----------------------------------------------------------------------
-      !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ngrp_world     : ', ngrp_world
-      !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - mpi_comm_world : ', mpi_comm_world
-      !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - mpi_comm_opa   : ', mpi_comm_opa
-      !
-      ALLOCATE( kwork(jpnij), STAT=ierr )
-      IF( ierr /= 0 ) THEN
-         WRITE(kumout, cform_err)
-         WRITE(kumout,*) 'mpp_ini_znl : failed to allocate 1D array of length jpnij'
-         CALL mppstop
-      ENDIF
-
-      IF( jpnj == 1 ) THEN
-         ngrp_znl  = ngrp_world
-         ncomm_znl = mpi_comm_opa
-      ELSE
-         !
-         CALL MPI_ALLGATHER ( njmpp, 1, mpi_integer, kwork, 1, mpi_integer, mpi_comm_opa, ierr )
-         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - kwork pour njmpp : ', kwork
-         !-$$        CALL flush(numout)
-         !
-         ! Count number of processors on the same row
-         ndim_rank_znl = 0
-         DO jproc=1,jpnij
-            IF ( kwork(jproc) == njmpp ) THEN
-               ndim_rank_znl = ndim_rank_znl + 1
-            ENDIF
-         END DO
-         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ndim_rank_znl : ', ndim_rank_znl
-         !-$$        CALL flush(numout)
-         ! Allocate the right size to nrank_znl
-         IF (ALLOCATED (nrank_znl)) DEALLOCATE(nrank_znl)
-         ALLOCATE(nrank_znl(ndim_rank_znl))
-         ii = 0     
-         nrank_znl (:) = 0
-         DO jproc=1,jpnij
-            IF ( kwork(jproc) == njmpp) THEN
-               ii = ii + 1
-               nrank_znl(ii) = jproc -1 
-            ENDIF
-         END DO
-         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - nrank_znl : ', nrank_znl
-         !-$$        CALL flush(numout)
-
-         ! Create the opa group
-         CALL MPI_COMM_GROUP(mpi_comm_opa,ngrp_opa,ierr)
-         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ngrp_opa : ', ngrp_opa
-         !-$$        CALL flush(numout)
-
-         ! Create the znl group from the opa group
-         CALL MPI_GROUP_INCL  ( ngrp_opa, ndim_rank_znl, nrank_znl, ngrp_znl, ierr )
-         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ngrp_znl ', ngrp_znl
-         !-$$        CALL flush(numout)
-
-         ! Create the znl communicator from the opa communicator, ie the pool of procs in the same row
-         CALL MPI_COMM_CREATE ( mpi_comm_opa, ngrp_znl, ncomm_znl, ierr )
-         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ncomm_znl ', ncomm_znl
-         !-$$        CALL flush(numout)
-         !
-      END IF
-
-      ! Determines if processor if the first (starting from i=1) on the row
-      IF ( jpni == 1 ) THEN 
-         l_znl_root = .TRUE.
-      ELSE
-         l_znl_root = .FALSE.
-         kwork (1) = nimpp
-         CALL mpp_min ( kwork(1), kcom = ncomm_znl)
-         IF ( nimpp == kwork(1)) l_znl_root = .TRUE.
-      END IF
-
-      DEALLOCATE(kwork)
-
-   END SUBROUTINE mpp_ini_znl
-
-
-   SUBROUTINE mpp_ini_north
-      !!----------------------------------------------------------------------
-      !!               ***  routine mpp_ini_north  ***
-      !!
-      !! ** Purpose :   Initialize special communicator for north folding 
-      !!      condition together with global variables needed in the mpp folding
-      !!
-      !! ** Method  : - Look for northern processors
-      !!              - Put their number in nrank_north
-      !!              - Create groups for the world processors and the north processors
-      !!              - Create a communicator for northern processors
-      !!
-      !! ** output
-      !!      njmppmax = njmpp for northern procs
-      !!      ndim_rank_north = number of processors in the northern line
-      !!      nrank_north (ndim_rank_north) = number  of the northern procs.
-      !!      ngrp_world = group ID for the world processors
-      !!      ngrp_north = group ID for the northern processors
-      !!      ncomm_north = communicator for the northern procs.
-      !!      north_root = number (in the world) of proc 0 in the northern comm.
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER ::   ierr
-      INTEGER ::   jjproc
-      INTEGER ::   ii, ji
-      !!----------------------------------------------------------------------
-      !
-      njmppmax = MAXVAL( njmppt )
-      !
-      ! Look for how many procs on the northern boundary
-      ndim_rank_north = 0
-      DO jjproc = 1, jpnij
-         IF( njmppt(jjproc) == njmppmax )   ndim_rank_north = ndim_rank_north + 1
-      END DO
-      !
-      ! Allocate the right size to nrank_north
-      IF (ALLOCATED (nrank_north)) DEALLOCATE(nrank_north)
-      ALLOCATE( nrank_north(ndim_rank_north) )
-
-      ! Fill the nrank_north array with proc. number of northern procs.
-      ! Note : the rank start at 0 in MPI
-      ii = 0
-      DO ji = 1, jpnij
-         IF ( njmppt(ji) == njmppmax   ) THEN
-            ii=ii+1
-            nrank_north(ii)=ji-1
-         END IF
-      END DO
-      !
-      ! create the world group
-      CALL MPI_COMM_GROUP( mpi_comm_opa, ngrp_world, ierr )
-      !
-      ! Create the North group from the world group
-      CALL MPI_GROUP_INCL( ngrp_world, ndim_rank_north, nrank_north, ngrp_north, ierr )
-      !
-      ! Create the North communicator , ie the pool of procs in the north group
-      CALL MPI_COMM_CREATE( mpi_comm_opa, ngrp_north, ncomm_north, ierr )
-      !
-   END SUBROUTINE mpp_ini_north
-
-
-   SUBROUTINE mpp_lbc_north_3d( pt3d, cd_type, psgn )
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_3d  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition 
-      !!              in mpp configuration in case of jpn1 > 1
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather 
-      !!              the 4 northern lines of the global domain on 1 processor
-      !!              and apply lbc north-fold on this sub array. Then we
-      !!              scatter the north fold array back to the processors.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pt3d      ! 3D array on which the b.c. is applied
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
-      !                                                              !   = T ,  U , V , F or W  gridpoints
-      REAL(wp)                        , INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
-      !!                                                             ! =  1. , the sign is kept
-      INTEGER ::   ji, jj, jr
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ijpjm1, ij, iproc
-      INTEGER, DIMENSION (jpmaxngh)          ::   ml_req_nf          ! for mpi_isend when avoiding mpi_allgather
-      INTEGER                                ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
-      INTEGER, DIMENSION(MPI_STATUS_SIZE)    ::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
-      !!----------------------------------------------------------------------
-      !   
-      ijpj   = 4
-      ityp = -1
-      ijpjm1 = 3
-      ztab(:,:,:) = 0.e0
-      !
-      DO jj = nlcj - ijpj +1, nlcj          ! put in znorthloc the last 4 jlines of pt3d
-         ij = jj - nlcj + ijpj
-         znorthloc(:,ij,:) = pt3d(:,jj,:)
-      END DO
-      !
-      !                                     ! Build in procs of ncomm_north the znorthgloio
-      itaille = jpi * jpk * ijpj
-      IF ( l_north_nogather ) THEN
-         !
-         ! Avoid the use of mpi_allgather by exchanging only with the processes already identified 
-         ! (in nemo_northcomms) as being  involved in this process' northern boundary exchange
-         !
-         DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
-            ij = jj - nlcj + ijpj
-            DO ji = 1, nlci
-               ztab(ji+nimpp-1,ij,:) = pt3d(ji,jj,:)
-            END DO
-         END DO
-
-         !
-         ! Set the exchange type in order to access the correct list of active neighbours
-         !
-         SELECT CASE ( cd_type )
-            CASE ( 'T' , 'W' )
-               ityp = 1
-            CASE ( 'U' )
-               ityp = 2
-            CASE ( 'V' )
-               ityp = 3
-            CASE ( 'F' )
-               ityp = 4
-            CASE ( 'I' )
-               ityp = 5
-            CASE DEFAULT
-               ityp = -1                    ! Set a default value for unsupported types which 
-                                            ! will cause a fallback to the mpi_allgather method
-         END SELECT
-         IF ( ityp .gt. 0 ) THEN
-
-            DO jr = 1,nsndto(ityp)
-               CALL mppsend(5, znorthloc, itaille, isendto(jr,ityp), ml_req_nf(jr) )
-            END DO
-            DO jr = 1,nsndto(ityp)
-               CALL mpprecv(5, zfoldwk, itaille, isendto(jr,ityp))
-               iproc = isendto(jr,ityp) + 1
-               ildi = nldit (iproc)
-               ilei = nleit (iproc)
-               iilb = nimppt(iproc)
-               DO jj = 1, ijpj
-                  DO ji = ildi, ilei
-                     ztab(ji+iilb-1,jj,:) = zfoldwk(ji,jj,:)
-                  END DO
-               END DO
-            END DO
-            IF (l_isend) THEN
-               DO jr = 1,nsndto(ityp)
-                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
-               END DO
-            ENDIF
-
-         ENDIF
-
-      ENDIF
-
-      IF ( ityp .lt. 0 ) THEN
-         CALL MPI_ALLGATHER( znorthloc  , itaille, MPI_DOUBLE_PRECISION,                &
-            &                znorthgloio, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
-         !
-         DO jr = 1, ndim_rank_north         ! recover the global north array
-            iproc = nrank_north(jr) + 1
-            ildi  = nldit (iproc)
-            ilei  = nleit (iproc)
-            iilb  = nimppt(iproc)
-            DO jj = 1, ijpj
-               DO ji = ildi, ilei
-                  ztab(ji+iilb-1,jj,:) = znorthgloio(ji,jj,:,jr)
-               END DO
-            END DO
-         END DO
-      ENDIF
-      !
-      ! The ztab array has been either:
-      !  a. Fully populated by the mpi_allgather operation or
-      !  b. Had the active points for this domain and northern neighbours populated 
-      !     by peer to peer exchanges
-      ! Either way the array may be folded by lbc_nfd and the result for the span of 
-      ! this domain will be identical.
-      !
-      CALL lbc_nfd( ztab, cd_type, psgn )   ! North fold boundary condition
-      !
-      DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt3d
-         ij = jj - nlcj + ijpj
-         DO ji= 1, nlci
-            pt3d(ji,jj,:) = ztab(ji+nimpp-1,ij,:)
-         END DO
-      END DO
-      !
-   END SUBROUTINE mpp_lbc_north_3d
-
-
-   SUBROUTINE mpp_lbc_north_2d( pt2d, cd_type, psgn)
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_2d  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition 
-      !!              in mpp configuration in case of jpn1 > 1 (for 2d array )
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather 
-      !!              the 4 northern lines of the global domain on 1 processor
-      !!              and apply lbc north-fold on this sub array. Then we
-      !!              scatter the north fold array back to the processors.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d      ! 3D array on which the b.c. is applied
-      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
-      !                                                          !   = T ,  U , V , F or W  gridpoints
-      REAL(wp)                    , INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
-      !!                                                             ! =  1. , the sign is kept
-      INTEGER ::   ji, jj, jr
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ijpjm1, ij, iproc
-      INTEGER, DIMENSION (jpmaxngh)      ::   ml_req_nf          ! for mpi_isend when avoiding mpi_allgather
-      INTEGER                            ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
-      INTEGER, DIMENSION(MPI_STATUS_SIZE)::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
-      !!----------------------------------------------------------------------
-      !
-      ijpj   = 4
-      ityp = -1
-      ijpjm1 = 3
-      ztab_2d(:,:) = 0.e0
-      !
-      DO jj = nlcj-ijpj+1, nlcj             ! put in znorthloc_2d the last 4 jlines of pt2d
-         ij = jj - nlcj + ijpj
-         znorthloc_2d(:,ij) = pt2d(:,jj)
-      END DO
-
-      !                                     ! Build in procs of ncomm_north the znorthgloio_2d
-      itaille = jpi * ijpj
-      IF ( l_north_nogather ) THEN
-         !
-         ! Avoid the use of mpi_allgather by exchanging only with the processes already identified 
-         ! (in nemo_northcomms) as being  involved in this process' northern boundary exchange
-         !
-         DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
-            ij = jj - nlcj + ijpj
-            DO ji = 1, nlci
-               ztab_2d(ji+nimpp-1,ij) = pt2d(ji,jj)
-            END DO
-         END DO
-
-         !
-         ! Set the exchange type in order to access the correct list of active neighbours
-         !
-         SELECT CASE ( cd_type )
-            CASE ( 'T' , 'W' )
-               ityp = 1
-            CASE ( 'U' )
-               ityp = 2
-            CASE ( 'V' )
-               ityp = 3
-            CASE ( 'F' )
-               ityp = 4
-            CASE ( 'I' )
-               ityp = 5
-            CASE DEFAULT
-               ityp = -1                    ! Set a default value for unsupported types which 
-                                            ! will cause a fallback to the mpi_allgather method
-         END SELECT
-
-         IF ( ityp .gt. 0 ) THEN
-
-            DO jr = 1,nsndto(ityp)
-               CALL mppsend(5, znorthloc_2d, itaille, isendto(jr,ityp), ml_req_nf(jr) )
-            END DO
-            DO jr = 1,nsndto(ityp)
-               CALL mpprecv(5, zfoldwk_2d, itaille, isendto(jr,ityp))
-               iproc = isendto(jr,ityp) + 1
-               ildi = nldit (iproc)
-               ilei = nleit (iproc)
-               iilb = nimppt(iproc)
-               DO jj = 1, ijpj
-                  DO ji = ildi, ilei
-                     ztab_2d(ji+iilb-1,jj) = zfoldwk_2d(ji,jj)
-                  END DO
-               END DO
-            END DO
-            IF (l_isend) THEN
-               DO jr = 1,nsndto(ityp)
-                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
-               END DO
-            ENDIF
-
-         ENDIF
-
-      ENDIF
-
-      IF ( ityp .lt. 0 ) THEN
-         CALL MPI_ALLGATHER( znorthloc_2d  , itaille, MPI_DOUBLE_PRECISION,        &
-            &                znorthgloio_2d, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
-         !
-         DO jr = 1, ndim_rank_north            ! recover the global north array
-            iproc = nrank_north(jr) + 1
-            ildi = nldit (iproc)
-            ilei = nleit (iproc)
-            iilb = nimppt(iproc)
-            DO jj = 1, ijpj
-               DO ji = ildi, ilei
-                  ztab_2d(ji+iilb-1,jj) = znorthgloio_2d(ji,jj,jr)
-               END DO
-            END DO
-         END DO
-      ENDIF
-      !
-      ! The ztab array has been either:
-      !  a. Fully populated by the mpi_allgather operation or
-      !  b. Had the active points for this domain and northern neighbours populated 
-      !     by peer to peer exchanges
-      ! Either way the array may be folded by lbc_nfd and the result for the span of 
-      ! this domain will be identical.
-      !
-      CALL lbc_nfd( ztab_2d, cd_type, psgn )   ! North fold boundary condition
-      !
-      !
-      DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
-         ij = jj - nlcj + ijpj
-         DO ji = 1, nlci
-            pt2d(ji,jj) = ztab_2d(ji+nimpp-1,ij)
-         END DO
-      END DO
-      !
-   END SUBROUTINE mpp_lbc_north_2d
-
-
-   SUBROUTINE mpp_lbc_north_e( pt2d, cd_type, psgn)
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_2d  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition 
-      !!              in mpp configuration in case of jpn1 > 1 and for 2d 
-      !!              array with outer extra halo
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather 
-      !!              the 4+2*jpr2dj northern lines of the global domain on 1 
-      !!              processor and apply lbc north-fold on this sub array. 
-      !!              Then we scatter the north fold array back to the processors.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)                                            , INTENT(in   ) ::   cd_type  ! nature of pt3d grid-points
-      !                                                                                         !   = T ,  U , V , F or W -points
-      REAL(wp)                                                    , INTENT(in   ) ::   psgn     ! = -1. the sign change across the  
-      !!                                                                                        ! north fold, =  1. otherwise
-      INTEGER ::   ji, jj, jr
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ij, iproc
-      !!----------------------------------------------------------------------
-      !
-      ijpj=4
-      ztab_e(:,:) = 0.e0
-
-      ij=0
-      ! put in znorthloc_e the last 4 jlines of pt2d
-      DO jj = nlcj - ijpj + 1 - jpr2dj, nlcj +jpr2dj
-         ij = ij + 1
-         DO ji = 1, jpi
-            znorthloc_e(ji,ij)=pt2d(ji,jj)
-         END DO
-      END DO
-      !
-      itaille = jpi * ( ijpj + 2 * jpr2dj )
-      CALL MPI_ALLGATHER( znorthloc_e(1,1)  , itaille, MPI_DOUBLE_PRECISION,    &
-         &                znorthgloio_e(1,1,1), itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
-      !
-      DO jr = 1, ndim_rank_north            ! recover the global north array
-         iproc = nrank_north(jr) + 1
-         ildi = nldit (iproc)
-         ilei = nleit (iproc)
-         iilb = nimppt(iproc)
-         DO jj = 1, ijpj+2*jpr2dj
-            DO ji = ildi, ilei
-               ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
-            END DO
-         END DO
-      END DO
-
-
-      ! 2. North-Fold boundary conditions
-      ! ----------------------------------
-      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, pr2dj = jpr2dj )
-
-      ij = jpr2dj
-      !! Scatter back to pt2d
-      DO jj = nlcj - ijpj + 1 , nlcj +jpr2dj
-      ij  = ij +1 
-         DO ji= 1, nlci
-            pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
-         END DO
-      END DO
-      !
-   END SUBROUTINE mpp_lbc_north_e
-
-
-   SUBROUTINE mpi_init_opa( ldtxt, ksft, code )
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_init.opa  ***
-      !!
-      !! ** Purpose :: export and attach a MPI buffer for bsend
-      !!
-      !! ** Method  :: define buffer size in namelist, if 0 no buffer attachment
-      !!            but classical mpi_init
-      !! 
-      !! History :: 01/11 :: IDRIS initial version for IBM only  
-      !!            08/04 :: R. Benshila, generalisation
-      !!---------------------------------------------------------------------
-      CHARACTER(len=*),DIMENSION(:), INTENT(  out) ::   ldtxt 
-      INTEGER                      , INTENT(inout) ::   ksft
-      INTEGER                      , INTENT(  out) ::   code
-      INTEGER                                      ::   ierr, ji
-      LOGICAL                                      ::   mpi_was_called
-      !!---------------------------------------------------------------------
-      !
-      CALL mpi_initialized( mpi_was_called, code )      ! MPI initialization
-      IF ( code /= MPI_SUCCESS ) THEN
-         DO ji = 1, SIZE(ldtxt) 
-            IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-         END DO         
-         WRITE(*, cform_err)
-         WRITE(*, *) ' lib_mpp: Error in routine mpi_initialized'
-         CALL mpi_abort( mpi_comm_world, code, ierr )
-      ENDIF
-      !
-      IF( .NOT. mpi_was_called ) THEN
-         CALL mpi_init( code )
-         CALL mpi_comm_dup( mpi_comm_world, mpi_comm_opa, code )
-         IF ( code /= MPI_SUCCESS ) THEN
-            DO ji = 1, SIZE(ldtxt) 
-               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-            END DO
-            WRITE(*, cform_err)
-            WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
-            CALL mpi_abort( mpi_comm_world, code, ierr )
-         ENDIF
-      ENDIF
-      !
-      IF( nn_buffer > 0 ) THEN
-         WRITE(ldtxt(ksft),*) 'mpi_bsend, buffer allocation of  : ', nn_buffer   ;   ksft = ksft + 1
-         ! Buffer allocation and attachment
-         ALLOCATE( tampon(nn_buffer), stat = ierr )
-         IF( ierr /= 0 ) THEN 
-            DO ji = 1, SIZE(ldtxt) 
-               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-            END DO
-            WRITE(*, cform_err)
-            WRITE(*, *) ' lib_mpp: Error in ALLOCATE', ierr
-            CALL mpi_abort( mpi_comm_world, code, ierr )
-         END IF
-         CALL mpi_buffer_attach( tampon, nn_buffer, code )
-      ENDIF
-      !
-   END SUBROUTINE mpi_init_opa
-
-#if defined key_mpp_rep
-   SUBROUTINE DDPDD_MPI (ydda, yddb, ilen, itype)
-      !!---------------------------------------------------------------------
-      !!   Routine DDPDD_MPI: used by reduction operator MPI_SUMDD
-      !!
-      !!   Modification of original codes written by David H. Bailey
-      !!   This subroutine computes yddb(i) = ydda(i)+yddb(i)
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in)                         :: ilen, itype
-      COMPLEX(wp), DIMENSION(ilen), INTENT(in)     :: ydda
-      COMPLEX(wp), DIMENSION(ilen), INTENT(inout)  :: yddb
-      !
-      REAL(wp) :: zerr, zt1, zt2    ! local work variables
-      INTEGER :: ji, ztmp           ! local scalar
-
-      ztmp = itype   ! avoid compilation warning
-
-      DO ji=1,ilen
-      ! Compute ydda + yddb using Knuth's trick.
-         zt1  = real(ydda(ji)) + real(yddb(ji))
-         zerr = zt1 - real(ydda(ji))
-         zt2  = ((real(yddb(ji)) - zerr) + (real(ydda(ji)) - (zt1 - zerr))) &
-                + aimag(ydda(ji)) + aimag(yddb(ji))
-
-         ! The result is zt1 + zt2, after normalization.
-         yddb(ji) = cmplx ( zt1 + zt2, zt2 - ((zt1 + zt2) - zt1),wp )
-      END DO
-
-   END SUBROUTINE DDPDD_MPI
-#endif
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default case:            Dummy module        share memory computing
-   !!----------------------------------------------------------------------
-   USE in_out_manager
-
-   INTERFACE mpp_sum
-      MODULE PROCEDURE mpp_sum_a2s, mpp_sum_as, mpp_sum_ai, mpp_sum_s, mpp_sum_i, mppsum_realdd, mppsum_a_realdd
-   END INTERFACE
-   INTERFACE mpp_max
-      MODULE PROCEDURE mppmax_a_int, mppmax_int, mppmax_a_real, mppmax_real
-   END INTERFACE
-   INTERFACE mpp_min
-      MODULE PROCEDURE mppmin_a_int, mppmin_int, mppmin_a_real, mppmin_real
-   END INTERFACE
-   INTERFACE mppobc
-      MODULE PROCEDURE mppobc_1d, mppobc_2d, mppobc_3d, mppobc_4d
-   END INTERFACE
-   INTERFACE mpp_minloc
-      MODULE PROCEDURE mpp_minloc2d ,mpp_minloc3d
-   END INTERFACE
-   INTERFACE mpp_maxloc
-      MODULE PROCEDURE mpp_maxloc2d ,mpp_maxloc3d
-   END INTERFACE
-
-   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .FALSE.      !: mpp flag
-   LOGICAL, PUBLIC            ::   ln_nnogather  = .FALSE.  !: namelist control of northfold comms (needed here in case "key_mpp_mpi" is not used)
-   INTEGER :: ncomm_ice
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION lib_mpp_alloc(kumout)          ! Dummy function
-      INTEGER, INTENT(in) ::   kumout
-      lib_mpp_alloc = 0
-   END FUNCTION lib_mpp_alloc
-
-   FUNCTION mynode( ldtxt, kumnam, kstop, localComm ) RESULT (function_value)
-      INTEGER, OPTIONAL            , INTENT(in   ) ::   localComm
-      CHARACTER(len=*),DIMENSION(:) ::   ldtxt 
-      INTEGER ::   kumnam, kstop
-      IF( PRESENT( localComm ) .OR. .NOT.PRESENT( localComm ) )   function_value = 0
-      IF( .FALSE. )   ldtxt(:) = 'never done'
-   END FUNCTION mynode
-
-   SUBROUTINE mppsync                       ! Dummy routine
-   END SUBROUTINE mppsync
-
-   SUBROUTINE mpp_sum_as( parr, kdim, kcom )      ! Dummy routine
-      REAL   , DIMENSION(:) :: parr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom 
-      WRITE(*,*) 'mpp_sum_as: You should not have seen this print! error?', kdim, parr(1), kcom
-   END SUBROUTINE mpp_sum_as
-
-   SUBROUTINE mpp_sum_a2s( parr, kdim, kcom )      ! Dummy routine
-      REAL   , DIMENSION(:,:) :: parr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom 
-      WRITE(*,*) 'mpp_sum_a2s: You should not have seen this print! error?', kdim, parr(1,1), kcom
-   END SUBROUTINE mpp_sum_a2s
-
-   SUBROUTINE mpp_sum_ai( karr, kdim, kcom )      ! Dummy routine
-      INTEGER, DIMENSION(:) :: karr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom 
-      WRITE(*,*) 'mpp_sum_ai: You should not have seen this print! error?', kdim, karr(1), kcom
-   END SUBROUTINE mpp_sum_ai
-
-   SUBROUTINE mpp_sum_s( psca, kcom )            ! Dummy routine
-      REAL                  :: psca
-      INTEGER, OPTIONAL     :: kcom 
-      WRITE(*,*) 'mpp_sum_s: You should not have seen this print! error?', psca, kcom
-   END SUBROUTINE mpp_sum_s
-
-   SUBROUTINE mpp_sum_i( kint, kcom )            ! Dummy routine
-      integer               :: kint
-      INTEGER, OPTIONAL     :: kcom 
-      WRITE(*,*) 'mpp_sum_i: You should not have seen this print! error?', kint, kcom
-   END SUBROUTINE mpp_sum_i
-
-   SUBROUTINE mppsum_realdd( ytab, kcom )
-      COMPLEX(wp), INTENT(inout)         :: ytab    ! input scalar
-      INTEGER , INTENT( in  ), OPTIONAL :: kcom
-      WRITE(*,*) 'mppsum_realdd: You should not have seen this print! error?', ytab
-   END SUBROUTINE mppsum_realdd
- 
-   SUBROUTINE mppsum_a_realdd( ytab, kdim, kcom )
-      INTEGER , INTENT( in )                        ::   kdim      ! size of ytab
-      COMPLEX(wp), DIMENSION(kdim), INTENT( inout ) ::   ytab      ! input array
-      INTEGER , INTENT( in  ), OPTIONAL :: kcom
-      WRITE(*,*) 'mppsum_a_realdd: You should not have seen this print! error?', kdim, ytab(1), kcom
-   END SUBROUTINE mppsum_a_realdd
-
-   SUBROUTINE mppmax_a_real( parr, kdim, kcom )
-      REAL   , DIMENSION(:) :: parr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom 
-      WRITE(*,*) 'mppmax_a_real: You should not have seen this print! error?', kdim, parr(1), kcom
-   END SUBROUTINE mppmax_a_real
-
-   SUBROUTINE mppmax_real( psca, kcom )
-      REAL                  :: psca
-      INTEGER, OPTIONAL     :: kcom 
-      WRITE(*,*) 'mppmax_real: You should not have seen this print! error?', psca, kcom
-   END SUBROUTINE mppmax_real
-
-   SUBROUTINE mppmin_a_real( parr, kdim, kcom )
-      REAL   , DIMENSION(:) :: parr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom 
-      WRITE(*,*) 'mppmin_a_real: You should not have seen this print! error?', kdim, parr(1), kcom
-   END SUBROUTINE mppmin_a_real
-
-   SUBROUTINE mppmin_real( psca, kcom )
-      REAL                  :: psca
-      INTEGER, OPTIONAL     :: kcom 
-      WRITE(*,*) 'mppmin_real: You should not have seen this print! error?', psca, kcom
-   END SUBROUTINE mppmin_real
-
-   SUBROUTINE mppmax_a_int( karr, kdim ,kcom)
-      INTEGER, DIMENSION(:) :: karr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom 
-      WRITE(*,*) 'mppmax_a_int: You should not have seen this print! error?', kdim, karr(1), kcom
-   END SUBROUTINE mppmax_a_int
-
-   SUBROUTINE mppmax_int( kint, kcom)
-      INTEGER               :: kint
-      INTEGER, OPTIONAL     :: kcom 
-      WRITE(*,*) 'mppmax_int: You should not have seen this print! error?', kint, kcom
-   END SUBROUTINE mppmax_int
-
-   SUBROUTINE mppmin_a_int( karr, kdim, kcom )
-      INTEGER, DIMENSION(:) :: karr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom 
-      WRITE(*,*) 'mppmin_a_int: You should not have seen this print! error?', kdim, karr(1), kcom
-   END SUBROUTINE mppmin_a_int
-
-   SUBROUTINE mppmin_int( kint, kcom )
-      INTEGER               :: kint
-      INTEGER, OPTIONAL     :: kcom 
-      WRITE(*,*) 'mppmin_int: You should not have seen this print! error?', kint, kcom
-   END SUBROUTINE mppmin_int
-
-   SUBROUTINE mppobc_1d( parr, kd1, kd2, kl, kk, ktype, kij, knum )
-      INTEGER  ::   kd1, kd2, kl , kk, ktype, kij, knum
-      REAL, DIMENSION(:) ::   parr           ! variable array
-      WRITE(*,*) 'mppobc: You should not have seen this print! error?', parr(1), kd1, kd2, kl, kk, ktype, kij, knum
-   END SUBROUTINE mppobc_1d
-
-   SUBROUTINE mppobc_2d( parr, kd1, kd2, kl, kk, ktype, kij, knum )
-      INTEGER  ::   kd1, kd2, kl , kk, ktype, kij, knum
-      REAL, DIMENSION(:,:) ::   parr           ! variable array
-      WRITE(*,*) 'mppobc: You should not have seen this print! error?', parr(1,1), kd1, kd2, kl, kk, ktype, kij, knum
-   END SUBROUTINE mppobc_2d
-
-   SUBROUTINE mppobc_3d( parr, kd1, kd2, kl, kk, ktype, kij, knum )
-      INTEGER  ::   kd1, kd2, kl , kk, ktype, kij, knum
-      REAL, DIMENSION(:,:,:) ::   parr           ! variable array
-      WRITE(*,*) 'mppobc: You should not have seen this print! error?', parr(1,1,1), kd1, kd2, kl, kk, ktype, kij, knum
-   END SUBROUTINE mppobc_3d
-
-   SUBROUTINE mppobc_4d( parr, kd1, kd2, kl, kk, ktype, kij, knum )
-      INTEGER  ::   kd1, kd2, kl , kk, ktype, kij, knum
-      REAL, DIMENSION(:,:,:,:) ::   parr           ! variable array
-      WRITE(*,*) 'mppobc: You should not have seen this print! error?', parr(1,1,1,1), kd1, kd2, kl, kk, ktype, kij, knum
-   END SUBROUTINE mppobc_4d
-
-   SUBROUTINE mpp_minloc2d( ptab, pmask, pmin, ki, kj )
-      REAL                   :: pmin
-      REAL , DIMENSION (:,:) :: ptab, pmask
-      INTEGER :: ki, kj
-      WRITE(*,*) 'mpp_minloc2d: You should not have seen this print! error?', pmin, ki, kj, ptab(1,1), pmask(1,1)
-   END SUBROUTINE mpp_minloc2d
-
-   SUBROUTINE mpp_minloc3d( ptab, pmask, pmin, ki, kj, kk )
-      REAL                     :: pmin
-      REAL , DIMENSION (:,:,:) :: ptab, pmask
-      INTEGER :: ki, kj, kk
-      WRITE(*,*) 'mpp_minloc3d: You should not have seen this print! error?', pmin, ki, kj, kk, ptab(1,1,1), pmask(1,1,1)
-   END SUBROUTINE mpp_minloc3d
-
-   SUBROUTINE mpp_maxloc2d( ptab, pmask, pmax, ki, kj )
-      REAL                   :: pmax
-      REAL , DIMENSION (:,:) :: ptab, pmask
-      INTEGER :: ki, kj
-      WRITE(*,*) 'mpp_maxloc2d: You should not have seen this print! error?', pmax, ki, kj, ptab(1,1), pmask(1,1)
-   END SUBROUTINE mpp_maxloc2d
-
-   SUBROUTINE mpp_maxloc3d( ptab, pmask, pmax, ki, kj, kk )
-      REAL                     :: pmax
-      REAL , DIMENSION (:,:,:) :: ptab, pmask
-      INTEGER :: ki, kj, kk
-      WRITE(*,*) 'mpp_maxloc3d: You should not have seen this print! error?', pmax, ki, kj, kk, ptab(1,1,1), pmask(1,1,1)
-   END SUBROUTINE mpp_maxloc3d
-
-   SUBROUTINE mppstop
-      WRITE(*,*) 'mppstop: You should not have seen this print if running in mpp mode! error?...'
-      WRITE(*,*) 'mppstop: ..otherwise this is a stop condition raised by ctl_stop in single processor mode'
-      STOP
-   END SUBROUTINE mppstop
-
-   SUBROUTINE mpp_ini_ice( kcom, knum )
-      INTEGER :: kcom, knum
-      WRITE(*,*) 'mpp_ini_ice: You should not have seen this print! error?', kcom, knum
-   END SUBROUTINE mpp_ini_ice
-
-   SUBROUTINE mpp_ini_znl( knum )
-      INTEGER :: knum
-      WRITE(*,*) 'mpp_ini_znl: You should not have seen this print! error?', knum
-   END SUBROUTINE mpp_ini_znl
-
-   SUBROUTINE mpp_comm_free( kcom )
-      INTEGER :: kcom
-      WRITE(*,*) 'mpp_comm_free: You should not have seen this print! error?', kcom
-   END SUBROUTINE mpp_comm_free
-#endif
-
-   !!----------------------------------------------------------------------
-   !!   All cases:         ctl_stop, ctl_warn, get_unit, ctl_opn   routines
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE ctl_stop( cd1, cd2, cd3, cd4, cd5 ,   &
-      &                 cd6, cd7, cd8, cd9, cd10 )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE  stop_opa  ***
-      !!
-      !! ** Purpose :   print in ocean.outpput file a error message and 
-      !!                increment the error number (nstop) by one.
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd1, cd2, cd3, cd4, cd5
-      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd6, cd7, cd8, cd9, cd10
-      !!----------------------------------------------------------------------
-      !
-      nstop = nstop + 1 
-      IF(lwp) THEN
-         WRITE(numout,cform_err)
-         IF( PRESENT(cd1 ) )   WRITE(numout,*) cd1
-         IF( PRESENT(cd2 ) )   WRITE(numout,*) cd2
-         IF( PRESENT(cd3 ) )   WRITE(numout,*) cd3
-         IF( PRESENT(cd4 ) )   WRITE(numout,*) cd4
-         IF( PRESENT(cd5 ) )   WRITE(numout,*) cd5
-         IF( PRESENT(cd6 ) )   WRITE(numout,*) cd6
-         IF( PRESENT(cd7 ) )   WRITE(numout,*) cd7
-         IF( PRESENT(cd8 ) )   WRITE(numout,*) cd8
-         IF( PRESENT(cd9 ) )   WRITE(numout,*) cd9
-         IF( PRESENT(cd10) )   WRITE(numout,*) cd10
-      ENDIF
-                               CALL FLUSH(numout    )
-      IF( numstp     /= -1 )   CALL FLUSH(numstp    )
-      IF( numsol     /= -1 )   CALL FLUSH(numsol    )
-      IF( numevo_ice /= -1 )   CALL FLUSH(numevo_ice)
-      !
-      IF( cd1 == 'STOP' ) THEN
-         IF(lwp) WRITE(numout,*)  'huge E-R-R-O-R : immediate stop'
-         CALL mppstop()
-      ENDIF
-      !
-   END SUBROUTINE ctl_stop
-
-
-   SUBROUTINE ctl_warn( cd1, cd2, cd3, cd4, cd5,   &
-      &                 cd6, cd7, cd8, cd9, cd10 )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE  stop_warn  ***
-      !!
-      !! ** Purpose :   print in ocean.outpput file a error message and 
-      !!                increment the warning number (nwarn) by one.
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd1, cd2, cd3, cd4, cd5
-      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd6, cd7, cd8, cd9, cd10
-      !!----------------------------------------------------------------------
-      ! 
-      nwarn = nwarn + 1 
-      IF(lwp) THEN
-         WRITE(numout,cform_war)
-         IF( PRESENT(cd1 ) ) WRITE(numout,*) cd1
-         IF( PRESENT(cd2 ) ) WRITE(numout,*) cd2
-         IF( PRESENT(cd3 ) ) WRITE(numout,*) cd3
-         IF( PRESENT(cd4 ) ) WRITE(numout,*) cd4
-         IF( PRESENT(cd5 ) ) WRITE(numout,*) cd5
-         IF( PRESENT(cd6 ) ) WRITE(numout,*) cd6
-         IF( PRESENT(cd7 ) ) WRITE(numout,*) cd7
-         IF( PRESENT(cd8 ) ) WRITE(numout,*) cd8
-         IF( PRESENT(cd9 ) ) WRITE(numout,*) cd9
-         IF( PRESENT(cd10) ) WRITE(numout,*) cd10
-      ENDIF
-      CALL FLUSH(numout)
-      !
-   END SUBROUTINE ctl_warn
-
-
-   SUBROUTINE ctl_opn( knum, cdfile, cdstat, cdform, cdacce, klengh, kout, ldwp, karea )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ctl_opn  ***
-      !!
-      !! ** Purpose :   Open file and check if required file is available.
-      !!
-      !! ** Method  :   Fortan open
-      !!----------------------------------------------------------------------
-      INTEGER          , INTENT(  out) ::   knum      ! logical unit to open
-      CHARACTER(len=*) , INTENT(in   ) ::   cdfile    ! file name to open
-      CHARACTER(len=*) , INTENT(in   ) ::   cdstat    ! disposition specifier
-      CHARACTER(len=*) , INTENT(in   ) ::   cdform    ! formatting specifier
-      CHARACTER(len=*) , INTENT(in   ) ::   cdacce    ! access specifier
-      INTEGER          , INTENT(in   ) ::   klengh    ! record length
-      INTEGER          , INTENT(in   ) ::   kout      ! number of logical units for write
-      LOGICAL          , INTENT(in   ) ::   ldwp      ! boolean term for print
-      INTEGER, OPTIONAL, INTENT(in   ) ::   karea     ! proc number
-      !!
-      CHARACTER(len=80) ::   clfile
-      INTEGER           ::   iost
-      !!----------------------------------------------------------------------
-
-      ! adapt filename
-      ! ----------------
-      clfile = TRIM(cdfile)
-      IF( PRESENT( karea ) ) THEN
-         IF( karea > 1 )   WRITE(clfile, "(a,'_',i4.4)") TRIM(clfile), karea-1
-      ENDIF
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() )   clfile = TRIM(Agrif_CFixed())//'_'//TRIM(clfile)
-      knum=Agrif_Get_Unit()
-#else
-      knum=get_unit()
-#endif
-
-      iost=0
-      IF( cdacce(1:6) == 'DIRECT' )  THEN
-         OPEN( UNIT=knum, FILE=clfile, FORM=cdform, ACCESS=cdacce, STATUS=cdstat, RECL=klengh, ERR=100, IOSTAT=iost )
-      ELSE
-         OPEN( UNIT=knum, FILE=clfile, FORM=cdform, ACCESS=cdacce, STATUS=cdstat             , ERR=100, IOSTAT=iost )
-      ENDIF
-      IF( iost == 0 ) THEN
-         IF(ldwp) THEN
-            WRITE(kout,*) '     file   : ', clfile,' open ok'
-            WRITE(kout,*) '     unit   = ', knum
-            WRITE(kout,*) '     status = ', cdstat
-            WRITE(kout,*) '     form   = ', cdform
-            WRITE(kout,*) '     access = ', cdacce
-            WRITE(kout,*)
-         ENDIF
-      ENDIF
-100   CONTINUE
-      IF( iost /= 0 ) THEN
-         IF(ldwp) THEN
-            WRITE(kout,*)
-            WRITE(kout,*) ' ===>>>> : bad opening file: ', clfile
-            WRITE(kout,*) ' =======   ===  '
-            WRITE(kout,*) '           unit   = ', knum
-            WRITE(kout,*) '           status = ', cdstat
-            WRITE(kout,*) '           form   = ', cdform
-            WRITE(kout,*) '           access = ', cdacce
-            WRITE(kout,*) '           iostat = ', iost
-            WRITE(kout,*) '           we stop. verify the file '
-            WRITE(kout,*)
-         ENDIF
-         STOP 'ctl_opn bad opening'
-      ENDIF
-      
-   END SUBROUTINE ctl_opn
-
-
-   INTEGER FUNCTION get_unit()
-      !!----------------------------------------------------------------------
-      !!                  ***  FUNCTION  get_unit  ***
-      !!
-      !! ** Purpose :   return the index of an unused logical unit
-      !!----------------------------------------------------------------------
-      LOGICAL :: llopn 
-      !!----------------------------------------------------------------------
-      !
-      get_unit = 15   ! choose a unit that is big enough then it is not already used in NEMO
-      llopn = .TRUE.
-      DO WHILE( (get_unit < 998) .AND. llopn )
-         get_unit = get_unit + 1
-         INQUIRE( unit = get_unit, opened = llopn )
-      END DO
-      IF( (get_unit == 999) .AND. llopn ) THEN
-         CALL ctl_stop( 'get_unit: All logical units until 999 are used...' )
-         get_unit = -1
-      ENDIF
-      !
-   END FUNCTION get_unit
-
-   !!----------------------------------------------------------------------
-END MODULE lib_mpp
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limadv.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limadv.F90	(revision 3937)
+++ 	(revision )
@@ -1,423 +1,0 @@
-MODULE limadv 
-   !!======================================================================
-   !!                       ***  MODULE limadv   ***
-   !! LIM sea-ice model : sea-ice advection
-   !!======================================================================
-   !! History :  LIM  ! 2008-03 (M. Vancoppenolle)  LIM-3 from LIM-2 code
-   !!            3.2  ! 2009-06 (F. Dupont)  correct a error in the North fold b. c.
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!--------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                     LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_adv_x  : advection of sea ice on x axis
-   !!   lim_adv_y  : advection of sea ice on y axis
-   !!----------------------------------------------------------------------
-   USE dom_oce          ! ocean domain
-   USE dom_ice          ! LIM-3 domain
-   USE ice              ! LIM-3 variables
-   USE lbclnk           ! lateral boundary condition - MPP exchanges
-   USE in_out_manager   ! I/O manager
-   USE prtctl           ! Print control
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE lib_fortran      ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_adv_x   ! called by lim_trp
-   PUBLIC   lim_adv_y   ! called by lim_trp
-
-   REAL(wp)  ::   epsi20 = 1.e-20_wp   ! constant values
-   REAL(wp)  ::   rzero  = 0._wp       !    -       -
-   REAL(wp)  ::   rone   = 1._wp       !    -       -
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limadv.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_adv_x( pdf, put , pcrh, psm , ps0 ,   &
-      &                  psx, psxx, psy , psyy, psxy )
-      !!---------------------------------------------------------------------
-      !!                **  routine lim_adv_x  **
-      !!  
-      !! ** purpose :   Computes and adds the advection trend to sea-ice
-      !!              variable on i-axis
-      !!
-      !! ** method  :   Uses Prather second order scheme that advects tracers
-      !!              but also theirquadratic forms. The method preserves
-      !!              tracer structures by conserving second order moments.
-      !!
-      !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
-      !!--------------------------------------------------------------------
-      REAL(wp)                    , INTENT(in   ) ::   pdf                ! reduction factor for the time step
-      REAL(wp)                    , INTENT(in   ) ::   pcrh               ! call lim_adv_x then lim_adv_y (=1) or the opposite (=0)
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   put                ! i-direction ice velocity at U-point [m/s]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psm                ! area
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ps0                ! field to be advected
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psx , psy          ! 1st moments 
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psxx, psyy, psxy   ! 2nd moments
-      !! 
-      INTEGER  ::   ji, jj                               ! dummy loop indices
-      REAL(wp) ::   zs1max, zrdt, zslpmax, ztemp, zin0   ! local scalars
-      REAL(wp) ::   zs1new, zalf , zalfq , zbt           !   -      -
-      REAL(wp) ::   zs2new, zalf1, zalf1q, zbt1          !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zf0 , zfx  , zfy   , zbet   ! 2D workspace
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zfm , zfxx , zfyy  , zfxy   !  -      -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zalg, zalg1, zalg1q         !  -      -
-      !---------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
-      CALL wrk_alloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
-
-      ! Limitation of moments.                                           
-
-      zrdt = rdt_ice * pdf      ! If ice drift field is too fast, use an appropriate time step for advection.
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zslpmax = MAX( 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 
-         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  *   psxx(ji,jj) * zalfq
-            zfy (ji,jj)  =  zalf  * ( psy (ji,jj) + zalf1 * psxy(ji,jj) )
-            zfxy(ji,jj)  =  zalfq *   psxy(ji,jj)
-            zfyy(ji,jj)  =  zalf  *   psyy(ji,jj)
-
-            !  Readjust moments remaining in the box.
-            psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
-            ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
-            psx (ji,jj)  =  zalf1q * ( psx(ji,jj) - 3.0 * zalf * psxx(ji,jj) )
-            psxx(ji,jj)  =  zalf1  * zalf1q * psxx(ji,jj)
-            psy (ji,jj)  =  psy (ji,jj) - zfy(ji,jj)
-            psyy(ji,jj)  =  psyy(ji,jj) - zfyy(ji,jj)
-            psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
-         END DO
-      END DO
-
-      DO jj = 1, jpjm1                      !  Flux from i+1 to i when u LT 0.
-         DO ji = 1, fs_jpim1
-            zalf          = MAX( 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  *   psxx(ji+1,jj) * zalfq
-            zfy   (ji,jj) = zfy (ji,jj) + zalf  * ( psy (ji+1,jj) - zalf1 * psxy(ji+1,jj) )
-            zfxy  (ji,jj) = zfxy(ji,jj) + zalfq *   psxy(ji+1,jj)
-            zfyy  (ji,jj) = zfyy(ji,jj) + zalf  *   psyy(ji+1,jj)
-         END DO
-      END DO
-
-      DO jj = 2, jpjm1                     !  Readjust moments remaining in the box. 
-         DO ji = fs_2, fs_jpim1
-            zbt  =       zbet(ji-1,jj)
-            zbt1 = 1.0 - zbet(ji-1,jj)
-            !
-            psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji-1,jj) )
-            ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji-1,jj) )
-            psx (ji,jj) = zalg1q(ji-1,jj) * ( psx(ji,jj) + 3.0 * zalg(ji-1,jj) * psxx(ji,jj) )
-            psxx(ji,jj) = zalg1 (ji-1,jj) * zalg1q(ji-1,jj) * psxx(ji,jj)
-            psy (ji,jj) = zbt * psy (ji,jj) + zbt1 * ( psy (ji,jj) - zfy (ji-1,jj) )
-            psyy(ji,jj) = zbt * psyy(ji,jj) + zbt1 * ( psyy(ji,jj) - zfyy(ji-1,jj) )
-            psxy(ji,jj) = zalg1q(ji-1,jj) * psxy(ji,jj)
-         END DO
-      END DO
-
-      !   Put the temporary moments into appropriate neighboring boxes.    
-      DO jj = 2, jpjm1                     !   Flux from i to i+1 IF u GT 0.
-         DO ji = fs_2, fs_jpim1
-            zbt  =       zbet(ji-1,jj)
-            zbt1 = 1.0 - zbet(ji-1,jj)
-            psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji-1,jj) ) + zbt1 * psm(ji,jj)
-            zalf        = zbt * zfm(ji-1,jj) / psm(ji,jj)
-            zalf1       = 1.0 - zalf
-            ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji-1,jj)
-            !
-            ps0 (ji,jj) = zbt * ( ps0(ji,jj) + zf0(ji-1,jj) ) + zbt1 * ps0(ji,jj)
-            psx (ji,jj) = zbt * ( zalf * zfx(ji-1,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp ) + zbt1 * psx(ji,jj)
-            psxx(ji,jj) = zbt * ( zalf * zalf * zfxx(ji-1,jj) + zalf1 * zalf1 * psxx(ji,jj)                               &
-               &                + 5.0 * ( zalf * zalf1 * ( psx (ji,jj) - zfx(ji-1,jj) ) - ( zalf1 - zalf ) * ztemp )  )   &
-               &                                                + zbt1 * psxx(ji,jj)
-            psxy(ji,jj) = zbt * ( zalf * zfxy(ji-1,jj) + zalf1 * psxy(ji,jj)             &
-               &                + 3.0 * (- zalf1*zfy(ji-1,jj)  + zalf * psy(ji,jj) ) )   &
-               &                                                + zbt1 * psxy(ji,jj)
-            psy (ji,jj) = zbt * ( psy (ji,jj) + zfy (ji-1,jj) ) + zbt1 * psy (ji,jj)
-            psyy(ji,jj) = zbt * ( psyy(ji,jj) + zfyy(ji-1,jj) ) + zbt1 * psyy(ji,jj)
-         END DO
-      END DO
-
-      DO jj = 2, jpjm1                     !  Flux from i+1 to i IF u LT 0.
-         DO ji = fs_2, fs_jpim1
-            zbt  =       zbet(ji,jj)
-            zbt1 = 1.0 - zbet(ji,jj)
-            psm(ji,jj)  = zbt * psm(ji,jj)  + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
-            zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
-            zalf1       = 1.0 - zalf
-            ztemp       = - zalf * ps0(ji,jj) + zalf1 * zf0(ji,jj)
-            !
-            ps0(ji,jj)  = zbt * ps0 (ji,jj) + zbt1 * ( ps0(ji,jj) + zf0(ji,jj) )
-            psx(ji,jj)  = zbt * psx (ji,jj) + zbt1 * ( zalf * zfx(ji,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp )
-            psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( zalf * zalf * zfxx(ji,jj)  + zalf1 * zalf1 * psxx(ji,jj)  &
-               &                                      + 5.0 *( zalf * zalf1 * ( - psx(ji,jj) + zfx(ji,jj) )      &
-               &                                      + ( zalf1 - zalf ) * ztemp ) )
-            psxy(ji,jj) = zbt * psxy(ji,jj) + zbt1 * (  zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)  &
-               &                                      + 3.0 * ( zalf1 * zfy(ji,jj) - zalf * psy(ji,jj) )  )
-            psy(ji,jj)  = zbt * psy (ji,jj)  + zbt1 * ( psy (ji,jj) + zfy (ji,jj) )
-            psyy(ji,jj) = zbt * psyy(ji,jj)  + zbt1 * ( psyy(ji,jj) + zfyy(ji,jj) )
-         END DO
-      END DO
-
-      !-- Lateral boundary conditions
-      CALL lbc_lnk( psm , 'T',  1. )   ;   CALL lbc_lnk( ps0 , 'T',  1. )
-      CALL lbc_lnk( psx , 'T', -1. )   ;   CALL lbc_lnk( psy , 'T', -1. )      ! caution gradient ==> the sign changes
-      CALL lbc_lnk( psxx, '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
-      !
-      CALL wrk_dealloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
-      CALL wrk_dealloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
-      !
-   END SUBROUTINE lim_adv_x
-
-
-   SUBROUTINE lim_adv_y( pdf, pvt , pcrh, psm , ps0 ,   &
-      &                  psx, psxx, psy , psyy, psxy )
-      !!---------------------------------------------------------------------
-      !!                **  routine lim_adv_y  **
-      !!            
-      !! ** purpose :   Computes and adds the advection trend to sea-ice 
-      !!              variable on y axis
-      !!
-      !! ** method  :   Uses Prather second order scheme that advects tracers
-      !!              but also their quadratic forms. The method preserves 
-      !!              tracer structures by conserving second order moments.
-      !! 
-      !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
-      !!---------------------------------------------------------------------
-      REAL(wp)                    , INTENT(in   ) ::   pdf                ! reduction factor for the time step
-      REAL(wp)                    , INTENT(in   ) ::   pcrh               ! call lim_adv_x then lim_adv_y (=1) or the opposite (=0)
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pvt                ! j-direction ice velocity at V-point [m/s]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psm                ! area
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ps0                ! field to be advected
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psx , psy          ! 1st moments 
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psxx, psyy, psxy   ! 2nd moments
-      !!
-      INTEGER  ::   ji, jj                               ! dummy loop indices
-      REAL(wp) ::   zs1max, zrdt, zslpmax, ztemp, zin0   ! temporary scalars
-      REAL(wp) ::   zs1new, zalf , zalfq , zbt           !    -         -
-      REAL(wp) ::   zs2new, zalf1, zalf1q, zbt1          !    -         -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zf0, zfx , zfy , zbet   ! 2D workspace
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zfm, zfxx, zfyy, zfxy   !  -      -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zalg, zalg1, zalg1q     !  -      -
-      !---------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
-      CALL wrk_alloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
-
-      ! Limitation of moments.
-
-      zrdt = rdt_ice * pdf ! If ice drift field is too fast, use an appropriate time step for advection.
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zslpmax = MAX( 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              
-      DO jj = 1, jpj                     !  Flux from j to j+1 WHEN v GT 0   
-         DO ji = 1, jpi
-            zbet(ji,jj)  =  MAX( rzero, SIGN( rone, pvt(ji,jj) ) )
-            zalf         =  MAX( rzero, pvt(ji,jj) ) * zrdt * e1v(ji,jj) / psm(ji,jj)
-            zalfq        =  zalf * zalf
-            zalf1        =  1.0 - zalf
-            zalf1q       =  zalf1 * zalf1
-            !
-            zfm (ji,jj)  =  zalf  * psm(ji,jj)
-            zf0 (ji,jj)  =  zalf  * ( ps0(ji,jj) + zalf1 * ( psy(ji,jj)  + (zalf1-zalf) * psyy(ji,jj)  ) ) 
-            zfy (ji,jj)  =  zalfq *( psy(ji,jj) + 3.0*zalf1*psyy(ji,jj) )
-            zfyy(ji,jj)  =  zalf  * zalfq * psyy(ji,jj)
-            zfx (ji,jj)  =  zalf  * ( psx(ji,jj) + zalf1 * psxy(ji,jj) )
-            zfxy(ji,jj)  =  zalfq * psxy(ji,jj)
-            zfxx(ji,jj)  =  zalf  * psxx(ji,jj)
-            !
-            !  Readjust moments remaining in the box.
-            psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
-            ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
-            psy (ji,jj)  =  zalf1q * ( psy(ji,jj) -3.0 * zalf * psyy(ji,jj) )
-            psyy(ji,jj)  =  zalf1 * zalf1q * psyy(ji,jj)
-            psx (ji,jj)  =  psx (ji,jj) - zfx(ji,jj)
-            psxx(ji,jj)  =  psxx(ji,jj) - zfxx(ji,jj)
-            psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
-         END DO
-      END DO
-      !
-      DO jj = 1, jpjm1                   !  Flux from j+1 to j when v LT 0.
-         DO ji = 1, jpi
-            zalf          = ( MAX(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  *   psyy(ji,jj+1) * zalfq
-            zfx   (ji,jj) = zfx (ji,jj) + zalf  * ( psx (ji,jj+1) - zalf1 * psxy(ji,jj+1) )
-            zfxy  (ji,jj) = zfxy(ji,jj) + zalfq *   psxy(ji,jj+1)
-            zfxx  (ji,jj) = zfxx(ji,jj) + zalf  *   psxx(ji,jj+1)
-         END DO
-      END DO
-
-      !  Readjust moments remaining in the box. 
-      DO jj = 2, jpj
-         DO ji = 1, jpi
-            zbt  =         zbet(ji,jj-1)
-            zbt1 = ( 1.0 - zbet(ji,jj-1) )
-            !
-            psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji,jj-1) )
-            ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji,jj-1) )
-            psy (ji,jj) = zalg1q(ji,jj-1) * ( psy(ji,jj) + 3.0 * zalg(ji,jj-1) * psyy(ji,jj) )
-            psyy(ji,jj) = zalg1 (ji,jj-1) * zalg1q(ji,jj-1) * psyy(ji,jj)
-            psx (ji,jj) = zbt * psx (ji,jj) + zbt1 * ( psx (ji,jj) - zfx (ji,jj-1) )
-            psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) - zfxx(ji,jj-1) )
-            psxy(ji,jj) = zalg1q(ji,jj-1) * psxy(ji,jj)
-         END DO
-      END DO
-
-      !   Put the temporary moments into appropriate neighboring boxes.    
-      DO jj = 2, jpjm1                    !   Flux from j to j+1 IF v GT 0.
-         DO ji = 1, jpi
-            zbt  =         zbet(ji,jj-1)
-            zbt1 = ( 1.0 - zbet(ji,jj-1) )
-            psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji,jj-1) ) + zbt1 * psm(ji,jj) 
-            zalf        = zbt * zfm(ji,jj-1) / psm(ji,jj) 
-            zalf1       = 1.0 - zalf
-            ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji,jj-1)
-            !
-            ps0(ji,jj)  = zbt  * ( ps0(ji,jj) + zf0(ji,jj-1) ) + zbt1 * ps0(ji,jj)
-            psy(ji,jj)  = zbt  * ( zalf * zfy(ji,jj-1) + zalf1 * psy(ji,jj) + 3.0 * ztemp )   &
-               &                                               + zbt1 * psy(ji,jj)  
-            psyy(ji,jj) = zbt  * ( zalf * zalf * zfyy(ji,jj-1) + zalf1 * zalf1 * psyy(ji,jj)                             &
-               &                 + 5.0 * ( zalf * zalf1 * ( psy(ji,jj) - zfy(ji,jj-1) ) - ( zalf1 - zalf ) * ztemp ) )   & 
-               &                                               + zbt1 * psyy(ji,jj)
-            psxy(ji,jj) = zbt  * (  zalf * zfxy(ji,jj-1) + zalf1 * psxy(ji,jj)               &
-               &                  + 3.0 * (- zalf1 * zfx(ji,jj-1) + zalf * psx(ji,jj) )  )   &
-               &                                                + zbt1 * psxy(ji,jj)
-            psx (ji,jj) = zbt * ( psx (ji,jj) + zfx (ji,jj-1) ) + zbt1 * psx (ji,jj)
-            psxx(ji,jj) = zbt * ( psxx(ji,jj) + zfxx(ji,jj-1) ) + zbt1 * psxx(ji,jj)
-         END DO
-      END DO
-
-      DO jj = 2, jpjm1                   !  Flux from j+1 to j IF v LT 0.
-         DO ji = 1, jpi
-            zbt  =         zbet(ji,jj)
-            zbt1 = ( 1.0 - zbet(ji,jj) )
-            psm(ji,jj)  = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
-            zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
-            zalf1       = 1.0 - zalf
-            ztemp       = - zalf * ps0 (ji,jj) + zalf1 * zf0(ji,jj)
-            ps0 (ji,jj) =   zbt  * ps0 (ji,jj) + zbt1  * ( ps0(ji,jj) + zf0(ji,jj) )
-            psy (ji,jj) =   zbt  * psy (ji,jj) + zbt1  * ( zalf * zfy(ji,jj) + zalf1 * psy(ji,jj) + 3.0 * ztemp )
-            psyy(ji,jj) =   zbt  * psyy(ji,jj) + zbt1 * (  zalf * zalf * zfyy(ji,jj) + zalf1 * zalf1 * psyy(ji,jj)   &
-               &                                         + 5.0 *( zalf *zalf1 *( -psy(ji,jj) + zfy(ji,jj) )          &
-               &                                         + ( zalf1 - zalf ) * ztemp )                                )
-            psxy(ji,jj) =   zbt  * psxy(ji,jj) + zbt1 * (  zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)       &
-               &                                         + 3.0 * ( zalf1 * zfx(ji,jj) - zalf * psx(ji,jj) )  )
-            psx (ji,jj) =   zbt  * psx (ji,jj) + zbt1 * ( psx (ji,jj) + zfx (ji,jj) )
-            psxx(ji,jj) =   zbt  * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) + zfxx(ji,jj) )
-         END DO
-      END DO
-
-      !-- Lateral boundary conditions
-      CALL lbc_lnk( psm , 'T',  1. )   ;   CALL lbc_lnk( ps0 , 'T',  1. )
-      CALL lbc_lnk( psx , 'T', -1. )   ;   CALL lbc_lnk( psy , 'T', -1. )      ! caution gradient ==> the sign changes
-      CALL lbc_lnk( psxx, '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
-      !
-      CALL wrk_dealloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
-      CALL wrk_dealloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
-      !
-   END SUBROUTINE lim_adv_y
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option            Dummy module         NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-
-   !!======================================================================
-END MODULE limadv
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limdiahsb.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limdiahsb.F90	(revision 3937)
+++ 	(revision )
@@ -1,229 +1,0 @@
-MODULE limdiahsb
-   !!======================================================================
-   !!                       ***  MODULE limdia_hsb   ***
-   !!  LIM-3 sea ice model :   diagnostics of ice model 
-   !!======================================================================
-   !! History :  3.4  ! 2012-10  (C. Rousset)  original code
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                       LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_dia_hsb        : computation and output of the time evolution of keys variables
-   !!   lim_dia_hsb_init   : initialization and namelist read
-   !!----------------------------------------------------------------------
-   USE ice             ! LIM-3: sea-ice variable
-   USE par_ice         ! LIM-3: ice parameters
-   USE dom_ice         ! LIM-3: sea-ice domain
-   USE dom_oce         ! ocean domain
-   USE sbc_oce         ! surface boundary condition: ocean fields
-   USE daymod          ! model calendar
-   USE phycst          ! physical constant
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! MPP library
-   USE timing          ! preformance summary
-   USE iom             ! I/O manager
-   USE lib_fortran     ! glob_sum
-   USE limrst          ! ice restart
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_diahsb        ! routine called by ice_step.F90
-   !!PUBLIC   lim_diahsb_init   ! routine called by ice_init.F90
-   !!PUBLIC   lim_diahsb_rst   ! routine called by ice_init.F90
-
-   REAL(wp), SAVE   ::   frc_sal, frc_vol   ! global forcing trends
-   REAL(wp), SAVE   ::   bg_grpme           ! global ice growth+melt trends
-   REAL(wp) ::   epsi06 = 1.e-6_wp  ! small number
-   REAL(wp) ::   epsi03 = 1.e-3_wp  ! small number
-
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.4 , NEMO Consortium (2012)
-   !! $Id: limdiahsb.F90 3294 2012-10-18 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE lim_diahsb
-      !!---------------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_diahsb  ***
-      !!     
-      !! ** Purpose: Compute the ice global heat content, salt content and volume conservation
-      !!	
-      !! ** Method : - Compute the deviation of heat content, salt content and volume
-      !!	            at the current time step from their values at nit000
-      !!	            - Compute the contribution of forcing and remove it from these deviations
-      !!
-      !!---------------------------------------------------------------------------
-      !!
-      REAL(wp)   ::   zbg_ivo, zbg_svo, zbg_are, zbg_sal ,zbg_tem ,zbg_ihc ,zbg_shc
-      REAL(wp)   ::   zbg_emps, zbg_emp, zbg_fsbri, zbg_fseqv, zbg_fsalt_res, zbg_fsalt_rpo 
-      REAL(wp)   ::   z_frc_vol, z_frc_sal, z_bg_grpme 
-      REAL(wp)   ::   zdeltat, z1_area                     !    -     -
-      !!---------------------------------------------------------------------------
-      IF( nn_timing == 1 )   CALL timing_start('lim_diahsb')
-
-      IF( numit == nstart ) CALL lim_diahsb_init 
-
-      ! 1/area
-      z1_area = 1.0 / MAX( glob_sum( area(:,:) * tms(:,:) ),epsi06 )
-      ! ----------------------- !
-      ! 1 -  Content variations !
-      ! ----------------------- !
-      zbg_ivo = glob_sum( vt_i(:,:) * area(:,:) * tms(:,:) ) ! volume ice 
-      zbg_svo = glob_sum( vt_s(:,:) * area(:,:) * tms(:,:) ) ! volume snow
-      zbg_are = glob_sum( at_i(:,:) * area(:,:) * tms(:,:) ) ! area
-      zbg_sal = glob_sum( SUM(smv_i(:,:,:),dim=3) * area(:,:) * tms(:,:) ) ! mean salt content
-      zbg_tem = glob_sum( (tm_i(:,:)-rtt) * vt_i(:,:) * area(:,:) * tms(:,:) )  ! mean temp content
-
-      !zbg_ihc = glob_sum( et_i(:,:) * area(:,:) * tms(:,:) ) / MAX( zbg_ivo,epsi06 ) ! ice heat content
-      !zbg_shc = glob_sum( et_s(:,:) * area(:,:) * tms(:,:) ) / MAX( zbg_svo,epsi06 ) ! snow heat content
-
-      zbg_ihc = glob_sum( et_i(:,:) ) ! ice heat content  [10^9 J]
-      zbg_shc = glob_sum( et_s(:,:) ) ! snow heat content [10^9 J]
-
-      zbg_emps      = glob_sum(      emps(:,:) * area(:,:) * tms(:,:) ) * z1_area
-      zbg_emp       = glob_sum(       emp(:,:) * area(:,:) * tms(:,:) ) * z1_area
-      zbg_fsbri     = glob_sum(     fsbri(:,:) * area(:,:) * tms(:,:) ) * z1_area
-      zbg_fseqv     = glob_sum(     fseqv(:,:) * area(:,:) * tms(:,:) ) * z1_area
-      zbg_fsalt_res = glob_sum( fsalt_res(:,:) * area(:,:) * tms(:,:) ) * z1_area
-      zbg_fsalt_rpo = glob_sum( fsalt_rpo(:,:) * area(:,:) * tms(:,:) ) * z1_area
-      
-      ! --------------------------------------------- !
-      ! 2 - Trends due to forcing and ice growth/melt !
-      ! --------------------------------------------- !
-      z_frc_vol = ( 1.e0 / rau0 ) * glob_sum( - emp(:,:) * area(:,:) * tms(:,:) ) ! volume fluxes
-      z_frc_sal = ( 1.e0 / rau0 ) * glob_sum(  emps(:,:) * area(:,:) * tms(:,:) ) ! salt fluxes
-      z_bg_grpme = glob_sum( ( diag_bot_gr(:,:) + diag_lat_gr(:,:) + diag_sni_gr(:,:) + diag_dyn_gr(:,:) + &
-                          &    diag_bot_me(:,:) + diag_sur_me(:,:) + diag_res_pr(:,:) ) * area(:,:) * tms(:,:) ) ! volume fluxes
-      !
-      frc_vol  = frc_vol  + z_frc_vol  * rdt_ice
-      frc_sal  = frc_sal  + z_frc_sal  * rdt_ice
-      bg_grpme = bg_grpme + z_bg_grpme * rdt_ice
-      
-      ! difference
-      !frc_vol = zbg_ivo - frc_vol
-      !frc_sal = zbg_sal - frc_sal
-      
-      ! ----------------------- !
-      ! 3 - Diagnostics writing !
-      ! ----------------------- !
-      !zdeltat  = 1.e0 / ( ( kt - nit000 + 1 ) * rdt_ice )
-      !
-      CALL iom_put( 'ibgvoltot',zbg_ivo * rhoic / rau0 * 1.e-9 ) ! m3 (equivalent liquid)         
-      CALL iom_put( 'sbgvoltot',zbg_svo * rhosn / rau0 * 1.e-9 )  ! m3 (equivalent liquid)       
-      CALL iom_put( 'ibgarea',zbg_are * 1.e-6 )         
-      CALL iom_put( 'ibgsaline',zbg_sal / MAX( zbg_ivo,epsi03 ) )         
-      CALL iom_put( 'ibgtemper',zbg_tem / MAX( zbg_ivo,epsi03 ) )         
-      CALL iom_put( 'ibgheatco',zbg_ihc )           ! 10^9 J        
-      CALL iom_put( 'ibgsaltco',zbg_sal * rhoic / rau0 * 1.e-9 ) ! psu*km3        
-      CALL iom_put( 'sbgheatco',zbg_shc )           ! 10^9 J
-      CALL iom_put( 'ibgfrcemp',frc_vol * 1.e-9 )           !vol - forcing : km3 (equivalent liquid)         
-      CALL iom_put( 'ibgfrcemps',frc_sal * 1.e-9 )          !sal - forcing : psu*km3   
-      CALL iom_put( 'ibgemps',zbg_emps *86400)            
-      CALL iom_put( 'ibgemp',zbg_emp *86400)              
-      CALL iom_put( 'ibgfsbri',zbg_fsbri *86400)         
-      CALL iom_put( 'ibgfseqv',zbg_fseqv *86400)         
-      CALL iom_put( 'ibgfsaltres',zbg_fsalt_res *86400)         
-      CALL iom_put( 'ibgfsaltrpo',zbg_fsalt_rpo *86400)         
-      CALL iom_put( 'ibggrpme',bg_grpme * rhoic / rau0 * 1.e-9 ) ! km3 (equivalent liquid)         
-      !
-      IF( lrst_ice )   CALL lim_diahsb_rst( numit, 'WRITE' )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('lim_diahsb')
-!
-   END SUBROUTINE lim_diahsb
-
-
-   SUBROUTINE lim_diahsb_init
-      !!---------------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_diahsb_init  ***
-      !!     
-      !! ** Purpose: Initialization for the heat salt volume budgets
-      !!	
-      !! ** Method : Compute initial heat content, salt content and volume
-      !!
-      !! ** Action : - Compute initial heat content, salt content and volume
-      !!             - Initialize forcing trends
-      !!             - Compute coefficients for conversion
-      !!---------------------------------------------------------------------------
-      INTEGER            ::   jk       ! dummy loop indice
-      INTEGER            ::   ierror   ! local integer
-      !!
-      !!NAMELIST/namicehsb/ blabla
-      !!----------------------------------------------------------------------
-      !
-      !!REWIND ( numnam_ice )              ! Read Namelist namicehsb 
-      !!READ   ( numnam_ice, namicehsb )
-      !
-      IF(lwp) THEN                   ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_diahsb_init : check the heat and salt budgets'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-      ENDIF
-
-      ! ---------------------------------- !
-      ! 2 - initial conservation variables !
-      ! ---------------------------------- !
-      !frc_vol = 0._wp                                           ! volume       trend due to forcing
-      !frc_sal = 0._wp                                           ! salt content   -    -   -    -         
-      !bg_grpme = 0._wp                                          ! ice growth + melt volume trend
-      !
-      CALL lim_diahsb_rst( nstart, 'READ' )  !* read or initialize all required files
-      !
-   END SUBROUTINE lim_diahsb_init
-
-   SUBROUTINE lim_diahsb_rst( kt, cdrw )
-     !!---------------------------------------------------------------------
-     !!                   ***  ROUTINE limdia_rst  ***
-     !!                     
-     !! ** Purpose :   Read or write DIA file in restart file
-     !!
-     !! ** Method  :   use of IOM library
-     !!----------------------------------------------------------------------
-     INTEGER         , INTENT(in) ::   kt     ! ice time-step
-     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
-     !
-     INTEGER ::   id1, id2, id3   ! local integers
-     !!----------------------------------------------------------------------
-     !
-     IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
-        IF( ln_rstart ) THEN                   !* Read the restart file
-           id1 = iom_varid( numrir, 'frc_vol'  , ldstop = .TRUE. )
-           !
-           CALL iom_get( numrir, 'frc_vol', frc_vol )
-           CALL iom_get( numrir, 'frc_sal', frc_sal )
-           CALL iom_get( numrir, 'bg_grpme', bg_grpme )
-       ELSE
-       	   frc_vol = 0._wp                                           
-       	   frc_sal = 0._wp                                                  
-      	   bg_grpme = 0._wp                                        
-       ENDIF	
-
-     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
-        !                                   ! -------------------
-        IF(lwp) WRITE(numout,*) '---- limdia-rst ----'
-        CALL iom_rstput( kt, nitrst, numriw, 'frc_vol'   , frc_vol     )
-        CALL iom_rstput( kt, nitrst, numriw, 'frc_sal'   , frc_sal     )
-        CALL iom_rstput( kt, nitrst, numriw, 'bg_grpme'  , bg_grpme     )
-        !
-     ENDIF
-     !
-   END SUBROUTINE lim_diahsb_rst
- 
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :         Empty module          NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_diahsb          ! Empty routine
-   END SUBROUTINE lim_diahsb
-#endif
-   !!======================================================================
-END MODULE limdiahsb
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limdyn.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limdyn.F90	(revision 3937)
+++ 	(revision )
@@ -1,338 +1,0 @@
-MODULE limdyn
-   !!======================================================================
-   !!                     ***  MODULE  limdyn  ***
-   !!   Sea-Ice dynamics :  
-   !!======================================================================
-   !! history :  1.0  ! 2002-08  (C. Ethe, G. Madec)  original VP code 
-   !!            3.0  ! 2007-03  (MA Morales Maqueda, S. Bouillon, M. Vancoppenolle)  LIM3: EVP-Cgrid
-   !!            4.0  ! 2011-02  (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                 LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!    lim_dyn      : computes ice velocities
-   !!    lim_dyn_init : initialization and namelist read
-   !!----------------------------------------------------------------------
-   USE phycst           ! physical constants
-   USE dom_oce          ! ocean space and time domain
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE sbc_ice          ! Surface boundary condition: ice   fields
-   USE ice              ! LIM-3 variables
-   USE par_ice          ! LIM-3 parameters
-   USE dom_ice          ! LIM-3 domain
-   USE limrhg           ! LIM-3 rheology
-   USE lbclnk           ! lateral boundary conditions - MPP exchanges
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE in_out_manager   ! I/O manager
-   USE prtctl           ! Print control
-   USE lib_fortran      ! glob_sum
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_dyn   ! routine called by ice_step
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limdyn.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_dyn( kt )
-      !!-------------------------------------------------------------------
-      !!               ***  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
-      !!------------------------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt     ! number of iteration
-      !!
-      INTEGER  ::   ji, jj, jl, ja    ! dummy loop indices
-      INTEGER  ::   i_j1, i_jpj       ! Starting/ending j-indices for rheology
-      REAL(wp) ::   zcoef             ! local scalar
-      REAL(wp), POINTER, DIMENSION(:)   ::   zind           ! i-averaged indicator of sea-ice
-      REAL(wp), POINTER, DIMENSION(:)   ::   zmsk           ! i-averaged of tmask
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zu_io, zv_io   ! ice-ocean velocity
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-     !!---------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zu_io, zv_io )
-      CALL wrk_alloc( jpj, zind, zmsk )
-
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
-      IF( kt == nit000 )   CALL lim_dyn_init   ! Initialization (first time-step only)
-
-      IF( ln_limdyn ) THEN
-         !
-         old_u_ice(:,:) = u_ice(:,:) * tmu(:,:)
-         old_v_ice(:,:) = v_ice(:,:) * tmv(:,:)
-
-         ! Rheology (ice dynamics)
-         ! ========
-
-         !  Define the j-limits where ice rheology is computed
-         ! ---------------------------------------------------
-
-         IF( lk_mpp .OR. lk_mpp_rep ) THEN                    ! mpp: compute over the whole domain
-            i_j1 = 1
-            i_jpj = jpj
-            IF(ln_ctl) CALL prt_ctl_info( 'lim_dyn  :    i_j1 = ', ivar1=i_j1, clinfo2=' ij_jpj = ', ivar2=i_jpj )
-            CALL lim_rhg( i_j1, i_jpj )
-         ELSE                                 ! optimization of the computational area
-            !
-            DO jj = 1, jpj
-               zind(jj) = SUM( 1.0 - at_i(:,jj) )   ! = REAL(jpj) if ocean everywhere on a j-line
-               zmsk(jj) = SUM( tmask(:,jj,1)    )   ! = 0         if land  everywhere on a j-line
-            END DO
-
-            IF( l_jeq ) THEN                     ! local domain include both hemisphere
-               !                                 ! Rheology is computed in each hemisphere
-               !                                 ! only over the ice cover latitude strip
-               ! Northern hemisphere
-               i_j1  = njeq
-               i_jpj = jpj
-               DO WHILE ( i_j1 <= jpj .AND. zind(i_j1) == FLOAT(jpi) .AND. zmsk(i_j1) /=0 )
-                  i_j1 = i_j1 + 1
-               END DO
-               i_j1 = MAX( 1, i_j1-2 )
-               IF(ln_ctl) CALL prt_ctl_info( 'lim_dyn  : NH  i_j1 = ', ivar1=i_j1, clinfo2=' ij_jpj = ', ivar2=i_jpj )
-               CALL lim_rhg( i_j1, i_jpj )
-               !
-               ! Southern hemisphere
-               i_j1  =  1
-               i_jpj = njeq
-               DO WHILE ( i_jpj >= 1 .AND. zind(i_jpj) == FLOAT(jpi) .AND. zmsk(i_jpj) /=0 )
-                  i_jpj = i_jpj - 1
-               END DO
-               i_jpj = MIN( jpj, i_jpj+1 )
-               IF(ln_ctl) CALL prt_ctl_info( 'lim_dyn  : SH  i_j1 = ', ivar1=i_j1, clinfo2=' ij_jpj = ', ivar2=i_jpj )
-               !
-               CALL lim_rhg( i_j1, i_jpj )
-               !
-            ELSE                                 ! local domain extends over one hemisphere only
-               !                                 ! Rheology is computed only over the ice cover
-               !                                 ! latitude strip
-               i_j1  = 1
-               DO WHILE ( i_j1 <= jpj .AND. zind(i_j1) == FLOAT(jpi) .AND. zmsk(i_j1) /=0 )
-                  i_j1 = i_j1 + 1
-               END DO
-               i_j1 = MAX( 1, i_j1-2 )
-
-               i_jpj  = jpj
-               DO WHILE ( i_jpj >= 1  .AND. zind(i_jpj) == FLOAT(jpi) .AND. zmsk(i_jpj) /=0 )
-                  i_jpj = i_jpj - 1
-               END DO
-               i_jpj = MIN( jpj, i_jpj+1)
-               !
-               IF(ln_ctl) CALL prt_ctl_info( 'lim_dyn  : one hemisphere:  i_j1 = ', ivar1=i_j1, clinfo2=' ij_jpj = ', ivar2=i_jpj )
-               !
-               CALL lim_rhg( i_j1, i_jpj )
-               !
-            ENDIF
-            !
-         ENDIF
-
-         ! computation of friction velocity
-         ! --------------------------------
-         ! ice-ocean velocity at U & V-points (u_ice v_ice at U- & V-points ; ssu_m, ssv_m at U- & V-points)
-         zu_io(:,:) = u_ice(:,:) - ssu_m(:,:)
-         zv_io(:,:) = v_ice(:,:) - ssv_m(:,:)
-         ! frictional velocity at T-point
-         zcoef = 0.5_wp * cw
-         DO jj = 2, jpjm1 
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ust2s(ji,jj) = zcoef * (  zu_io(ji,jj) * zu_io(ji,jj) + zu_io(ji-1,jj) * zu_io(ji-1,jj)   &
-                  &                    + zv_io(ji,jj) * zv_io(ji,jj) + zv_io(ji,jj-1) * zv_io(ji,jj-1)   ) * tms(ji,jj)
-            END DO
-         END DO
-         !
-      ELSE      ! no ice dynamics : transmit directly the atmospheric stress to the ocean
-         !
-         zcoef = SQRT( 0.5_wp ) / rau0
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ust2s(ji,jj) = zcoef * SQRT(  utau(ji,jj) * utau(ji,jj) + utau(ji-1,jj) * utau(ji-1,jj)   &
-                  &                        + vtau(ji,jj) * vtau(ji,jj) + vtau(ji,jj-1) * vtau(ji,jj-1)   ) * tms(ji,jj)
-            END DO
-         END DO
-         !
-      ENDIF
-      CALL lbc_lnk( ust2s, 'T',  1. )   ! T-point
-
-      IF(ln_ctl) THEN   ! Control print
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Cell values : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=ust2s     , clinfo1=' lim_dyn  : ust2s     :')
-         CALL prt_ctl(tab2d_1=divu_i    , clinfo1=' lim_dyn  : divu_i    :')
-         CALL prt_ctl(tab2d_1=delta_i   , clinfo1=' lim_dyn  : delta_i   :')
-         CALL prt_ctl(tab2d_1=strength  , clinfo1=' lim_dyn  : strength  :')
-         CALL prt_ctl(tab2d_1=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
-      !
-
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         !INTEGER                                 ::   numhsb 
-         !CHARACTER (len=32) ::   cl_name  ! output file name
-         !cl_name    = 'heat_salt_volume_budgets.txt'                         ! name of output file
-
-         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
-
-         IF(lwp) THEN
-            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limdyn) = ',(zchk_v_i * 86400.)
-            IF (    ABS( zchk_smv   ) >  1.e-4  ) WRITE(numout,*) 'violation saline [psu*m3/day] (limdyn) = ',(zchk_smv * 86400.)
-            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limdyn) = ',(MINVAL(v_i) * 1.e-3)
-            IF ( MAXVAL( SUM(a_i(:,:,:),dim=3) ) > amax+1.e-10 ) WRITE(numout,*) 'violation a_i>amax    (limdyn) = ',MAXVAL(SUM(a_i,dim=3))
-         ENDIF
-         !CALL ctl_opn( numhsb , cl_name , 'UNKNOWN' , 'FORMATTED' , 'SEQUENTIAL' , 1 , numout , lwp , 1 )
-         !
-         !WRITE( numhsb, 9010 ) "kt   |     heat content budget     |            salt content budget             ",   &
-         !     &                                                  "|            volume budget (ssh)             ",   &
-         !     &                                                  "|            volume budget (e3t)             "
-         !WRITE( numhsb, 9010 ) "     |      [C]         [W/m2]     |     [psu]        [mmm/s]          [SV]     ",   &
-         !     &                                                  "|     [m3]         [mmm/s]          [SV]     ",   &
-         !     &                                                  "|     [m3]         [mmm/s]          [SV]     "
-         !IF ( kt == nitend ) CLOSE( numhsb )
-         
-!9010     FORMAT(A80,A45,A45)
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
-      CALL wrk_dealloc( jpi, jpj, zu_io, zv_io )
-      CALL wrk_dealloc( jpj, zind, zmsk )
-      !
-   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
-      !!-------------------------------------------------------------------
-      NAMELIST/namicedyn/ epsd, alpha,     &
-         &                dm, nbiter, nbitdr, om, resl, cw, angvg, pstar,   &
-         &                c_rhg, etamn, creepl, ecc, ahi0, &
-         &                nevp, telast, alphaevp, hminrhg
-      !!-------------------------------------------------------------------
-
-      REWIND( numnam_ice )                ! Read Namelist namicedyn
-      READ  ( numnam_ice  , namicedyn )
-      
-      IF(lwp) THEN                        ! control print
-         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
-         WRITE(numout,*) '   min ice thickness for rheology calculations     hminrhg = ', hminrhg
-      ENDIF
-      !
-      IF( angvg /= 0._wp ) THEN
-         CALL ctl_warn( 'lim_dyn_init: turning angle for oceanic stress not properly coded for EVP ',   &
-            &           '(see limsbc module). We force  angvg = 0._wp'  )
-         angvg = 0._wp
-      ENDIF
-      
-      usecc2 = 1._wp / ( ecc * ecc )
-      rhoco  = rau0  * cw
-      angvg  = angvg * rad
-      sangvg = SIN( angvg )
-      cangvg = COS( angvg )
-      pstarh = pstar * 0.5_wp
-
-      !  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: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limhdf.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limhdf.F90	(revision 3937)
+++ 	(revision )
@@ -1,178 +1,0 @@
-MODULE limhdf
-   !!======================================================================
-   !!                    ***  MODULE limhdf   ***
-   !! LIM ice model : horizontal diffusion of sea-ice quantities
-   !!======================================================================
-   !! History :  LIM  !  2000-01 (LIM) Original code
-   !!             -   !  2001-05 (G. Madec, R. Hordoir) opa norm
-   !!            1.0  !  2002-08 (C. Ethe)  F90, free form
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_hdf  : diffusion trend on sea-ice variable
-   !!----------------------------------------------------------------------
-   USE dom_oce          ! ocean domain
-   USE ice              ! LIM-3: ice variables
-   USE lbclnk           ! lateral boundary condition - MPP exchanges
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE prtctl           ! Print control
-   USE in_out_manager   ! I/O manager
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_hdf     ! called by lim_tra
-
-   LOGICAL  ::   linit = .TRUE.              ! initialization flag (set to flase after the 1st call)
-   REAL(wp) ::   epsi04 = 1e-04              ! constant
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   efact   ! metric coefficient
-
-   !! * Substitution 
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
-   !! $Id: limhdf.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/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
-      !!-------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   ptab    ! Field on which the diffusion is applied
-      !
-      INTEGER  ::  ji, jj            ! dummy loop indices
-      INTEGER  ::  its, iter, ierr   ! local integers
-      REAL(wp) ::   zalfa, zrlxint, zconv, zeps   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zrlx, zflu, zflv, zdiv0, zdiv, ztab0
-      CHARACTER(lc) ::   charout   ! local character
-      !!-------------------------------------------------------------------
-      
-      CALL wrk_alloc( jpi, jpj, zrlx, zflu, zflv, zdiv0, zdiv, ztab0 )
-
-      !                       !==  Initialisation  ==!
-      !
-      IF( linit ) THEN              ! Metric coefficient (compute at the first call and saved in efact)
-         ALLOCATE( efact(jpi,jpj) , STAT=ierr )
-         IF( lk_mpp    )   CALL mpp_sum( ierr )
-         IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'lim_hdf : unable to allocate arrays' )
-         DO jj = 2, jpjm1  
-            DO ji = fs_2 , fs_jpim1   ! vector opt.
-               efact(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
-      !                             ! Time integration parameters
-      zalfa = 0.5_wp                      ! =1.0/0.5/0.0 = implicit/Cranck-Nicholson/explicit
-      its   = 100                         ! Maximum number of iteration
-      zeps  =  2._wp * epsi04
-      !
-      ztab0(:, : ) = ptab(:,:)      ! Arrays initialization
-      zdiv0(:, 1 ) = 0._wp
-      zdiv0(:,jpj) = 0._wp
-      IF( .NOT.lk_vopt_loop ) THEN
-         zflu (jpi,:) = 0._wp   
-         zflv (jpi,:) = 0._wp
-         zdiv0(1,  :) = 0._wp
-         zdiv0(jpi,:) = 0._wp
-      ENDIF
-
-      zconv = 1._wp           !==  horizontal diffusion using a Crant-Nicholson scheme  ==!
-      iter  = 0
-      !
-      DO WHILE( zconv > zeps .AND. iter <= its )   ! Sub-time step loop
-         !
-         iter = iter + 1                                 ! incrementation of the sub-time step number
-         !
-         DO jj = 1, jpjm1                                ! diffusive fluxes in U- and V- direction
-            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
-         !
-         DO jj= 2, jpjm1                                 ! diffusive trend : divergence of the fluxes
-            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
-         !
-         IF( iter == 1 )   zdiv0(:,:) = zdiv(:,:)        ! save the 1st evaluation of the diffusive trend in zdiv0
-         !
-         DO jj = 2, jpjm1                                ! iterative evaluation
-            DO ji = fs_2 , fs_jpim1   ! vector opt.
-               zrlxint = (   ztab0(ji,jj)    &
-                  &       +  rdt_ice * (           zalfa   * ( zdiv(ji,jj) + efact(ji,jj) * ptab(ji,jj) )   &
-                  &                      + ( 1.0 - zalfa ) *   zdiv0(ji,jj) )  )                             & 
-                  &    / ( 1.0 + zalfa * rdt_ice * efact(ji,jj) )
-               zrlx(ji,jj) = ptab(ji,jj) + om * ( zrlxint - ptab(ji,jj) )
-            END DO
-         END DO
-         CALL lbc_lnk( zrlx, 'T', 1. )                   ! lateral boundary condition
-         !
-         zconv = 0._wp                                   ! convergence test
-         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
-         !
-         ptab(:,:) = zrlx(:,:)
-         !
-      END DO                                       ! end of sub-time step loop
-
-      ! -----------------------
-      !!! final step (clem) !!!
-      DO jj = 1, jpjm1                                ! diffusive fluxes in U- and V- direction
-         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
-      !
-      DO jj= 2, jpjm1                                 ! diffusive trend : divergence of the fluxes
-         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) )
-            ptab(ji,jj) = ztab0(ji,jj) + 0.5 * ( zdiv(ji,jj) + zdiv0(ji,jj) )
-         END DO
-      END DO
-      CALL lbc_lnk( ptab, 'T', 1. )                   ! lateral boundary condition
-      !!! final step (clem) !!!
-      ! -----------------------
-
-      IF(ln_ctl)   THEN
-         zrlx(:,:) = ptab(:,:) - ztab0(:,:)
-         WRITE(charout,FMT="(' lim_hdf  : zconv =',D23.16, ' iter =',I4,2X)") zconv, iter
-         CALL prt_ctl( tab2d_1=zrlx, clinfo1=charout )
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, zrlx, zflu, zflv, zdiv0, zdiv, ztab0 )
-      !
-   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: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limistate.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limistate.F90	(revision 3937)
+++ 	(revision )
@@ -1,537 +1,0 @@
-MODULE limistate
-   !!======================================================================
-   !!                     ***  MODULE  limistate  ***
-   !!              Initialisation of diagnostics ice variables
-   !!======================================================================
-   !! History :  2.0  ! 2004-01 (C. Ethe, G. Madec)  Original code
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2012    (C. Rousset) clean + add par_oce (for jp_sal)...bug?
-   !!----------------------------------------------------------------------
-#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
-   !!----------------------------------------------------------------------
-   USE phycst           ! physical constant
-   USE oce              ! dynamics and tracers variables
-   USE dom_oce          ! ocean domain
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE eosbn2           ! equation of state
-   USE ice              ! sea-ice variables
-   USE par_ice          ! ice parameters
-   USE par_oce          ! ocean parameters
-   USE dom_ice          ! sea-ice domain
-   USE in_out_manager   ! I/O manager
-   USE lbclnk           ! lateral boundary condition - MPP exchanges
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_istate      ! routine called by lim_init.F90
-
-   !                                  !!** init namelist (namiceini) **
-   REAL(wp) ::   ttest    = 2.0_wp     ! threshold water temperature for initial sea ice
-   REAL(wp) ::   hninn    = 0.5_wp     ! initial snow thickness in the north
-   REAL(wp) ::   hginn_u  = 2.5_wp     ! initial ice thickness in the north
-   REAL(wp) ::   aginn_u  = 0.7_wp     ! initial leads area in the north
-   REAL(wp) ::   hginn_d  = 5.0_wp     ! initial ice thickness in the north
-   REAL(wp) ::   aginn_d  = 0.25_wp    ! initial leads area in the north
-   REAL(wp) ::   hnins    = 0.1_wp     ! initial snow thickness in the south
-   REAL(wp) ::   hgins_u  = 1.0_wp     ! initial ice thickness in the south
-   REAL(wp) ::   agins_u  = 0.7_wp     ! initial leads area in the south
-   REAL(wp) ::   hgins_d  = 2.0_wp     ! initial ice thickness in the south
-   REAL(wp) ::   agins_d  = 0.2_wp     ! initial leads area in the south
-   REAL(wp) ::   sinn     = 6.301_wp   ! initial salinity 
-   REAL(wp) ::   sins     = 6.301_wp   !
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limistate.F90 3349 2012-04-11 08:31:17Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/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
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk, jl            ! dummy loop indices
-      INTEGER  ::   i_fill, jl0, ztest_1, ztest_2, ztest_3, ztest_4, ztests  
-      REAL(wp) ::   zarg, zV, zconv
-      REAL(wp) ::   zeps06, zeps, ztmelts   ! local scalars
-      REAL(wp),          DIMENSION(jpl) ::   zain, zhtin, zhtsn, zais, zhtis, zhtss 
-      REAL(wp),          DIMENSION(jpl) ::   zai, zhti, zhts 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zidto      ! ice indicator
-      !--------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zidto )
-
-      !--------------------------------------------------------------------
-      ! 1) Preliminary things 
-      !--------------------------------------------------------------------
-
-      CALL lim_istate_init     !  reading the initials parameters of the ice
-
-!!gm  in lim2  the initialisation if only done if required in the namelist :
-!!gm      IF( .NOT. ln_limini ) THEN
-!!gm  this should be added in lim3 namelist...
-
-      !--------------------------------------------------------------------
-      ! 2) Ice initialization (hi,hs,frld,t_su,sm_i,t_i,t_s)              | 
-      !--------------------------------------------------------------------
-
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'lim_istate : Ice initialization '
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
-
-      t_bo(:,:) = tfreez( tsn(:,:,1,jp_sal) ) * tmask(:,:,1)       ! freezing/melting point of sea water [Celcius]
-
-      DO jj = 1, jpj                                       ! ice if sst <= t-freez + ttest
-         DO ji = 1, jpi
-            IF( tsn(ji,jj,1,jp_tem)  - t_bo(ji,jj) >= ttest ) THEN   ;   zidto(ji,jj) = 0.e0      ! no ice
-            ELSE                                                     ;   zidto(ji,jj) = 1.e0      !    ice
-            ENDIF
-         END DO
-      END DO
-
-      t_bo(:,:) = t_bo(:,:) + rt0                          ! t_bo converted from Celsius to Kelvin (rt0 over land)
-
-      ! constants for heat contents
-      zeps    = 1.e-20_wp
-      zeps06  = 1.e-06_wp
-
-      !------------------------------------------------------------------------------------
-      ! 3) Distribute ice concentration and thickness into the categories (cf limcat.F90)
-      !------------------------------------------------------------------------------------
-      ! snow distribution
-      zhtsn(1:jpl) = 0.d0
-      zhtss(1:jpl) = 0.d0
-      DO jl = 1, jpl
-         zhtsn(jl) = hninn
-         zhtss(jl) = hnins
-      END DO
-
-      ! -------------------
-      ! Northern Hemisphere
-      ! -------------------
-      ! initialisation of tests
-      ztest_1 = 0
-      ztest_2 = 0
-      ztest_3 = 0
-      ztest_4 = 0
-      ztests  = 0
-         
-      i_fill = jpl + 1                                    !====================================
-      DO WHILE ( ( ztests /= 4 ) .AND. ( i_fill >= 2 ) )  ! iterative loop on i_fill categories  
-         ! iteration                                      !====================================
-         i_fill = i_fill - 1
- 
-         ! initialisation of ice variables for each try
-         zhtin(1:jpl) = 0.d0
-         zain (1:jpl) = 0.d0
-         
-         ! *** case very thin ice: fill only category 1
-         IF ( i_fill == 1 ) THEN
-            zhtin(1) = hginn_u
-            zain (1) = aginn_u
-            
-            ! *** case ice is thicker: fill categories >1
-         ELSE
-            
-            ! Fill ice thicknesses except the last one (i_fill) by (hmax-hmin)/2 
-            DO jl = 1, i_fill - 1
-               zhtin(jl) = ( hi_max(jl) + hi_max(jl-1) ) / 2.
-            END DO
-            
-            ! find which category (jl0) the input ice thickness falls into
-            jl0 = i_fill
-            DO jl = 1, i_fill
-               IF ( ( hginn_u >= hi_max(jl-1) ) .AND. ( hginn_u < hi_max(jl) ) ) THEN
-                  jl0 = jl
-                  CYCLE
-               ENDIF
-            END DO
-            
-            ! Concentrations in the (i_fill-1) categories 
-            zain(jl0) = aginn_u / SQRT(REAL(jpl))
-            DO jl = 1, i_fill - 1
-               IF ( jl == jl0 ) CYCLE
-               zarg           = ( zhtin(jl) - hginn_u ) / ( hginn_u / 2. )
-               zain(jl) =   zain (jl0) * EXP(-zarg**2)
-            END DO
-            
-            ! Concentration in the last (i_fill) category
-            zain(i_fill) = aginn_u - SUM( zain(1:i_fill-1) )
-            
-            ! Ice thickness in the last (i_fill) category
-            zV = SUM( zain(1:i_fill-1) * zhtin(1:i_fill-1) )
-            zhtin(i_fill) = ( hginn_u*aginn_u -  zV ) / zain(i_fill) 
-            
-         ENDIF ! case ice is thick or thin
-         
-         !---------------------
-         ! Compatibility tests
-         !--------------------- 
-         ! Test 1: area conservation
-         zconv = ABS( aginn_u - SUM( zain(1:jpl) ) )
-         IF ( zconv < zeps06 ) ztest_1 = 1
-         
-         ! Test 2: volume conservation
-         zconv = ABS( hginn_u*aginn_u - SUM( zain(1:jpl)*zhtin(1:jpl) ) )
-         IF ( zconv < zeps06 ) ztest_2 = 1
-         
-         ! Test 3: thickness of the last category is in-bounds ?
-         IF ( zhtin(i_fill) >= hi_max(i_fill-1) ) ztest_3 = 1
-         
-         ! Test 4: positivity of ice concentrations
-         ztest_4 = 1
-         DO jl = 1, i_fill
-            IF ( zain(jl) < 0.0d0 ) ztest_4 = 0
-         END DO
-         
-         ztests = ztest_1 + ztest_2 + ztest_3 + ztest_4
-                                                        !============================
-      END DO                                            ! end iteration on categories
-                                                        !============================
-      ! Check if tests have passed (i.e. volume conservation...)
-      IF ( ztests .NE. 4 ) THEN
-         WRITE(numout,*) ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '
-         WRITE(numout,*) ' !! ALERT categories distribution !!'
-         WRITE(numout,*) ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '
-         WRITE(numout,*) ' *** ztests is not equal to 4 '
-         WRITE(numout,*) ' *** ztest (1:4) = ', ztest_1, ztest_2, ztest_3, ztest_4
-      ENDIF
-
-      ! -------------------
-      ! Southern Hemisphere
-      ! -------------------
-      ! initialisation of tests
-      ztest_1 = 0
-      ztest_2 = 0
-      ztest_3 = 0
-      ztest_4 = 0
-      ztests  = 0
-         
-      i_fill = jpl + 1                                    !====================================
-      DO WHILE ( ( ztests /= 4 ) .AND. ( i_fill >= 2 ) )  ! iterative loop on i_fill categories  
-         ! iteration                                      !====================================
-         i_fill = i_fill - 1
- 
-         ! initialisation of ice variables for each try
-         zhtis(1:jpl) = 0.d0
-         zais (1:jpl) = 0.d0
-         
-         ! *** case very thin ice: fill only category 1
-         IF ( i_fill == 1 ) THEN
-            zhtis(1) = hgins_u
-            zais (1) = agins_u
-            
-            ! *** case ice is thicker: fill categories >1
-         ELSE
-            
-            ! Fill ice thicknesses except the last one (i_fill) by (hmax-hmin)/2 
-            DO jl = 1, i_fill - 1
-               zhtis(jl) = ( hi_max(jl) + hi_max(jl-1) ) / 2.
-            END DO
-            
-            ! find which category (jl0) the input ice thickness falls into
-            jl0 = i_fill
-            DO jl = 1, i_fill
-               IF ( ( hgins_u >= hi_max(jl-1) ) .AND. ( hgins_u < hi_max(jl) ) ) THEN
-                  jl0 = jl
-                  CYCLE
-               ENDIF
-            END DO
-            
-            ! Concentrations in the (i_fill-1) categories 
-            zais(jl0) = agins_u / SQRT(REAL(jpl))
-            DO jl = 1, i_fill - 1
-               IF ( jl == jl0 ) CYCLE
-               zarg           = ( zhtis(jl) - hgins_u ) / ( hgins_u / 2. )
-               zais(jl) =   zais (jl0) * EXP(-zarg**2)
-            END DO
-            
-            ! Concentration in the last (i_fill) category
-            zais(i_fill) = agins_u - SUM( zais(1:i_fill-1) )
-            
-            ! Ice thickness in the last (i_fill) category
-            zV = SUM( zais(1:i_fill-1) * zhtis(1:i_fill-1) )
-            zhtis(i_fill) = ( hgins_u*agins_u -  zV ) / zais(i_fill) 
-            
-         ENDIF ! case ice is thick or thin
-         
-         !---------------------
-         ! Compatibility tests
-         !--------------------- 
-         ! Test 1: area conservation
-         zconv = ABS( agins_u - SUM( zais(1:jpl) ) )
-         IF ( zconv < zeps06 ) ztest_1 = 1
-         
-         ! Test 2: volume conservation
-         zconv = ABS( hgins_u*agins_u - SUM( zais(1:jpl)*zhtis(1:jpl) ) )
-         IF ( zconv < zeps06 ) ztest_2 = 1
-         
-         ! Test 3: thickness of the last category is in-bounds ?
-         IF ( zhtis(i_fill) >= hi_max(i_fill-1) ) ztest_3 = 1
-         
-         ! Test 4: positivity of ice concentrations
-         ztest_4 = 1
-         DO jl = 1, i_fill
-            IF ( zais(jl) < 0.0d0 ) ztest_4 = 0
-         END DO
-         
-         ztests = ztest_1 + ztest_2 + ztest_3 + ztest_4
-                                                        !============================
-      END DO                                            ! end iteration on categories
-                                                        !============================
-      ! Check if tests have passed (i.e. volume conservation...)
-      IF ( ztests .NE. 4 ) THEN
-         WRITE(numout,*) ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '
-         WRITE(numout,*) ' !! ALERT categories distribution !!'
-         WRITE(numout,*) ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '
-         WRITE(numout,*) ' *** ztests is not equal to 4 '
-         WRITE(numout,*) ' *** ztest (1:4) = ', ztest_1, ztest_2, ztest_3, ztest_4
-      ENDIF
-!!
-!!
-!!
-      ! ---------------------
-      ! 4) fill ice variables
-      ! ---------------------
-      zai(:) = 0.0
-      zhti(:)= 0.0
-      zhts(:)= 0.0
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-
-            !--- Northern hemisphere
-            !----------------------------------------------------------------
-            IF( fcor(ji,jj) >= 0._wp ) THEN
-               zai(:) = zain(:) ; zhti(:) = zhtin(:) ; zhts(:) = zhtsn(:)     
-            ELSE 
-               zai(:) = zais(:) ; zhti(:) = zhtis(:) ; zhts(:) = zhtss(:)     
-            ENDIF
-            
-            DO jl = 1, jpl
-               !-----------------------
-               ! Ice area / thickness
-               !-----------------------
-               a_i(ji,jj,jl)    = zidto(ji,jj) * zai(jl)
-               ht_i(ji,jj,jl)   = zidto(ji,jj) * zhti(jl)
-               v_i(ji,jj,jl)    = ht_i(ji,jj,jl)*a_i(ji,jj,jl)
-               
-               !-------------
-               ! Snow depth
-               !-------------
-               ht_s(ji,jj,jl)   = zidto(ji,jj) * zhts(jl)
-               v_s(ji,jj,jl)    = ht_s(ji,jj,jl)*a_i(ji,jj,jl)
-               
-               !---------------
-               ! Ice salinity
-               !---------------
-               sm_i(ji,jj,jl)   = zidto(ji,jj) * sinn  + ( 1.0 - zidto(ji,jj) ) * 0.1
-               smv_i(ji,jj,jl)  = MIN( sm_i(ji,jj,jl) , sss_m(ji,jj) ) * v_i(ji,jj,jl)
-               
-               !----------
-               ! Ice age
-               !----------
-               o_i(ji,jj,jl)    = zidto(ji,jj) * 1.0   + ( 1.0 - zidto(ji,jj) )
-               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(ji,jj) * 270.0 + ( 1.0 - zidto(ji,jj) ) * t_bo(ji,jj)
-               
-               !------------------------------------
-               ! Snow temperature and heat content
-               !------------------------------------
-               DO jk = 1, nlay_s
-                  t_s(ji,jj,jk,jl) = zidto(ji,jj) * 270.00 + ( 1.0 - zidto(ji,jj) ) * rtt
-                  ! Snow energy of melting
-                  e_s(ji,jj,jk,jl) = zidto(ji,jj) * rhosn * ( cpic * ( rtt - t_s(ji,jj,jk,jl) ) + lfus )
-                  ! 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)  / REAL( nlay_s )
-               END DO !jk
-               
-               !-----------------------------------------------
-               ! Ice salinities, temperature and heat content 
-               !-----------------------------------------------
-               DO jk = 1, nlay_i
-                  t_i(ji,jj,jk,jl) = zidto(ji,jj)*270.00 + ( 1.0 - zidto(ji,jj) ) * rtt 
-                  s_i(ji,jj,jk,jl) = zidto(ji,jj) * sinn + ( 1.0 - zidto(ji,jj) ) * 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(ji,jj) * 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) / &
-                       REAL( nlay_i )
-               END DO ! jk
-               
-            END DO ! jl 
-            
-         END DO
-      END DO
- 
-      IF(lwp) THEN                        ! control print
-         WRITE(numout,*) '~~~~~~~~~~~~~~~'
-         WRITE(numout,*) '   max ice  thickness   = ', (MAXVAL(ht_i(:,:,jl)),jl=1,jpl)
-         WRITE(numout,*) '   max snow thickness   = ', (MAXVAL(ht_s(:,:,jl)),jl=1,jpl)
-         WRITE(numout,*) '   max ice  area        = ', (MAXVAL(a_i(:,:,jl)),jl=1,jpl)
-         WRITE(numout,*) '   max ice  salinity    = ', (MAXVAL(sm_i(:,:,jl)),jl=1,jpl)
-         WRITE(numout,*) '   min ice  salinity    = ', (MINVAL(sm_i(:,:,jl)),jl=1,jpl)
-         WRITE(numout,*) '   max ice  surf temper = ', (MAXVAL(t_su(:,:,jl)-rtt),jl=1,jpl)
-         WRITE(numout,*) '   min ice  surf temper = ', (MINVAL(t_su(:,:,jl)-rtt),jl=1,jpl)
-      ENDIF
-
-      !--------------------------------------------------------------------
-      ! 5) 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
-
-      !--------------------------------------------------------------------
-      ! 6) Moments for advection
-      !--------------------------------------------------------------------
-
-      sxopw (:,:) = 0.e0 
-      syopw (:,:) = 0.e0 
-      sxxopw(:,:) = 0.e0 
-      syyopw(:,:) = 0.e0 
-      sxyopw(:,:) = 0.e0
-
-      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
-
-      sxopw(:,:) = 0.e0 ; syopw(:,:) = 0.e0; sxxopw(:,:) = 0.e0; syyopw(:,:) = 0.e0; sxyopw(:,:) = 0.e0
-
-      !--------------------------------------------------------------------
-      ! 7) 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 wrk_dealloc( jpi, jpj, zidto )
-      !
-   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
-      !!-----------------------------------------------------------------------------
-      NAMELIST/namiceini/ ttest, hninn, hginn_u, aginn_u, hginn_d, aginn_d, hnins,   &
-         &                hgins_u, agins_u, hgins_d, agins_d, sinn, sins
-      !!-----------------------------------------------------------------------------
-      !
-      REWIND ( numnam_ice )               ! Read Namelist namiceini 
-      READ   ( numnam_ice , namiceini )
-      !
-      IF(lwp) THEN                        ! control print
-         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: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limitd_me.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limitd_me.F90	(revision 3937)
+++ 	(revision )
@@ -1,1648 +1,0 @@
-MODULE limitd_me
-   !!======================================================================
-   !!                       ***  MODULE limitd_me ***
-   !! LIM-3 : Mechanical impact on ice thickness distribution      
-   !!======================================================================
-   !! History :  LIM  ! 2006-02  (M. Vancoppenolle) Original code 
-   !!            3.2  ! 2009-07  (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in smsw & fsalt_rpo
-   !!            4.0  ! 2011-02  (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                    LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE dom_oce          ! ocean domain
-   USE phycst           ! physical constants (ocean directory) 
-   USE sbc_oce          ! surface boundary condition: ocean fields
-   USE thd_ice          ! LIM thermodynamics
-   USE ice              ! LIM variables
-   USE par_ice          ! LIM parameters
-   USE dom_ice          ! LIM domain
-   USE limthd_lac       ! LIM
-   USE limvar           ! LIM
-   USE limcons          ! LIM
-   USE in_out_manager   ! I/O manager
-   USE lbclnk           ! lateral boundary condition - MPP exchanges
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE prtctl           ! Print control
-  ! Check budget (Rousset)
-   USE iom              ! I/O manager
-   USE lib_fortran     ! glob_sum
-   USE limdiahsb
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_itd_me               ! called by ice_stp
-   PUBLIC   lim_itd_me_icestrength
-   PUBLIC   lim_itd_me_init
-   PUBLIC   lim_itd_me_zapsmall
-   PUBLIC   lim_itd_me_alloc        ! called by iceini.F90
-
-   REAL(wp)  ::   epsi11 = 1.e-11_wp   ! constant values
-   REAL(wp)  ::   epsi10 = 1.e-10_wp   ! constant values
-   REAL(wp)  ::   epsi06 = 1.e-06_wp   ! constant values
-
-   !-----------------------------------------------------------------------
-   ! Variables shared among ridging subroutines
-   !-----------------------------------------------------------------------
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   asum     ! sum of total ice and open water area
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   aksum    ! ratio of area removed to area ridged
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   athorn   ! participation function; fraction of ridging/
-   !                                                           !  closing associated w/ category n
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hrmin    ! minimum ridge thickness
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hrmax    ! maximum ridge thickness
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hraft    ! thickness of rafted ice
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   krdg     ! mean ridge thickness/thickness of ridging ice 
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   aridge   ! participating ice ridging
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   araft    ! participating ice rafting
-
-   REAL(wp), PARAMETER ::   krdgmin = 1.1_wp    ! min ridge thickness multiplier
-   REAL(wp), PARAMETER ::   kraft   = 2.0_wp    ! rafting multipliyer
-
-   REAL(wp) ::   Cp                             ! 
-   !
-   !-----------------------------------------------------------------------
-   ! Ridging diagnostic arrays for history files
-   !-----------------------------------------------------------------------
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   dardg1dt   ! rate of fractional area loss by ridging ice (1/s)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   dardg2dt   ! rate of fractional area gain by new ridges (1/s)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   dvirdgdt   ! rate of ice volume ridged (m/s)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   opening    ! rate of opening due to divergence/shear (1/s)
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 3.3 , UCL - NEMO Consortium (2010)
-   !! $Id: limitd_me.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION lim_itd_me_alloc()
-      !!---------------------------------------------------------------------!
-      !!                ***  ROUTINE lim_itd_me_alloc ***
-      !!---------------------------------------------------------------------!
-      ALLOCATE(                                                                     &
-         !* Variables shared among ridging subroutines
-         &      asum (jpi,jpj)     , athorn(jpi,jpj,0:jpl)                    ,     &
-         &      aksum(jpi,jpj)                                                ,     &
-         !
-         &      hrmin(jpi,jpj,jpl) , hraft(jpi,jpj,jpl) , aridge(jpi,jpj,jpl) ,     &
-         &      hrmax(jpi,jpj,jpl) , krdg (jpi,jpj,jpl) , araft (jpi,jpj,jpl) ,     &
-         !
-         !* Ridging diagnostic arrays for history files
-         &      dardg1dt(jpi,jpj)  , dardg2dt(jpi,jpj)                        ,     & 
-         &      dvirdgdt(jpi,jpj)  , opening(jpi,jpj)                         , STAT=lim_itd_me_alloc )
-         !
-      IF( lim_itd_me_alloc /= 0 )   CALL ctl_warn( 'lim_itd_me_alloc: failed to allocate arrays' )
-      !
-   END FUNCTION lim_itd_me_alloc
-
-
-   SUBROUTINE lim_itd_me
-      !!---------------------------------------------------------------------!
-      !!                ***  ROUTINE lim_itd_me ***
-      !!
-      !! ** Purpose :   computes the mechanical redistribution of ice thickness
-      !!
-      !! ** Method  :   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 :   Flato, G. M., and W. D. Hibler III, 1995, JGR, 100, 18,611-18,626.
-      !!                Hibler, W. D. III, 1980, MWR, 108, 1943-1973, 1980.
-      !!                Rothrock, D. A., 1975: JGR, 80, 4514-4519.
-      !!                Thorndike et al., 1975, JGR, 80, 4501-4513. 
-      !!                Bitz et al., JGR, 2001
-      !!                Amundrud and Melling, JGR 2005
-      !!                Babko et al., JGR 2002 
-      !!
-      !!     This routine is based on CICE code and authors William H. Lipscomb,
-      !!  and Elizabeth C. Hunke, LANL are gratefully acknowledged
-      !!--------------------------------------------------------------------!
-      INTEGER ::   ji, jj, jk, jl   ! dummy loop index
-      INTEGER ::   niter, nitermax = 20   ! local integer 
-      LOGICAL  ::   asum_error              ! flag for asum .ne. 1
-      INTEGER  ::   iterate_ridging         ! if true, repeat the ridging
-      REAL(wp) ::   w1, tmpfac, dti         ! local scalar
-      CHARACTER (len = 15) ::   fieldid
-      REAL(wp), POINTER, DIMENSION(:,:) ::   closing_net     ! net rate at which area is removed    (1/s)
-                                                             ! (ridging ice area - area of new ridges) / dt
-      REAL(wp), POINTER, DIMENSION(:,:) ::   divu_adv        ! divu as implied by transport scheme  (1/s)
-      REAL(wp), POINTER, DIMENSION(:,:) ::   opning          ! rate of opening due to divergence/shear
-      REAL(wp), POINTER, DIMENSION(:,:) ::   closing_gross   ! rate at which area removed, not counting area of new ridges
-      REAL(wp), POINTER, DIMENSION(:,:) ::   msnow_mlt       ! mass of snow added to ocean (kg m-2)
-      REAL(wp), POINTER, DIMENSION(:,:) ::   esnow_mlt       ! energy needed to melt snow in ocean (J m-2)
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vt_i_init, vt_i_final  !  ice volume summed over categories
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-      ! mass and salt flux (clem)
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zviold, zvsold, zsmvold   ! old ice volume...
-      !!-----------------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, closing_net, divu_adv, opning, closing_gross, msnow_mlt, esnow_mlt, vt_i_init, vt_i_final )
-
-      CALL wrk_alloc( jpi, jpj, jpl, zviold, zvsold, zsmvold )   ! clem
-
-      IF( numit == nstart  )   CALL lim_itd_me_init   ! Initialization (first time-step only)
-
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab2d_1=ato_i , clinfo1=' lim_itd_me: ato_i  : ', tab2d_2=at_i   , clinfo2=' at_i    : ')
-         CALL prt_ctl(tab2d_1=divu_i, clinfo1=' lim_itd_me: divu_i : ', tab2d_2=delta_i, clinfo2=' delta_i : ')
-      ENDIF
-
-      IF( ln_limdyn ) THEN          !   Start ridging and rafting   !
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
-      ! mass and salt flux init (clem)
-      zviold(:,:,:) = v_i(:,:,:)
-      zvsold(:,:,:) = v_s(:,:,:)
-      zsmvold(:,:,:) = smv_i(:,:,:)
-
-      !-----------------------------------------------------------------------------!
-      ! 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
-
-      IF( con_i)   CALL lim_column_sum( jpl, v_i, vt_i_init )      ! conservation check
-
-      DO jj = 1, jpj                                     ! Initialize arrays.
-         DO ji = 1, jpi
-            msnow_mlt(ji,jj) = 0._wp
-            esnow_mlt(ji,jj) = 0._wp
-            dardg1dt (ji,jj)  = 0._wp
-            dardg2dt (ji,jj)  = 0._wp
-            dvirdgdt (ji,jj)  = 0._wp
-            opening  (ji,jj)  = 0._wp
-
-            !-----------------------------------------------------------------------------!
-            ! 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._wp )
-
-            ! 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) = ( amax - asum(ji,jj) ) / rdt_ice  ! asum found in ridgeprep
-
-            IF( divu_adv(ji,jj) < 0._wp )   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) > epsi11 .AND. athorn(ji,jj,jl) > 0._wp )THEN
-                     w1 = athorn(ji,jj,jl) * closing_gross(ji,jj) * rdt_ice
-                     IF ( w1 > 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) - amax ) .LT. epsi11) THEN
-                  closing_net(ji,jj) = 0._wp
-                  opning     (ji,jj) = 0._wp
-               ELSE
-                  iterate_ridging    = 1
-                  divu_adv   (ji,jj) = ( amax - asum(ji,jj) ) / rdt_ice
-                  closing_net(ji,jj) = MAX( 0._wp, -divu_adv(ji,jj) )
-                  opning     (ji,jj) = MAX( 0._wp,  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._wp / rdt_ice
-
-      asum_error = .false. 
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-
-            IF (ABS(asum(ji,jj) - amax) .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
-            !-----------------------------------------------------------------------------!
-            fmmec(ji,jj) = fmmec(ji,jj) + msnow_mlt(ji,jj) * dti     ! fresh water source for ocean
-            fhmec(ji,jj) = fhmec(ji,jj) + esnow_mlt(ji,jj) * dti     ! heat sink for ocean
-
-         END DO
-      END DO
-
-      ! Check if there is a ridging error
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF (ABS(asum(ji,jj) - amax) .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
-
-      !--------------------------------
-      ! Update mass/salt fluxes (clem)
-      !--------------------------------
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               diag_dyn_gr(ji,jj) = diag_dyn_gr(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) / rdt_ice
-               rdmicif(ji,jj) = rdmicif(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) * rhoic 
-               rdmsnif(ji,jj) = rdmsnif(ji,jj) + ( v_s(ji,jj,jl) - zvsold(ji,jj,jl) ) * rhosn 
-               fsalt_rpo(ji,jj) = fsalt_rpo(ji,jj) - ( smv_i(ji,jj,jl) - zsmvold(ji,jj,jl) ) * rhoic / rdt_ice 
-            END DO
-         END DO
-      END DO
-
-      !-----------------
-      !  Trend terms
-      !-----------------
-
-      d_u_ice_dyn(:,:)     = u_ice(:,:)     - old_u_ice(:,:)
-      d_v_ice_dyn(:,:)     = v_ice(:,:)     - old_v_ice(:,:)
-      d_a_i_trp  (:,:,:)   = a_i  (:,:,:)   - old_a_i  (:,:,:)
-      d_v_s_trp  (:,:,:)   = v_s  (:,:,:)   - old_v_s  (:,:,:)  
-      d_v_i_trp  (:,:,:)   = v_i  (:,:,:)   - old_v_i  (:,:,:)   
-      d_e_s_trp  (:,:,:,:) = e_s  (:,:,:,:) - old_e_s  (:,:,:,:)  
-      d_e_i_trp  (:,:,:,:) = e_i  (:,:,:,:) - old_e_i  (:,:,:,:)
-      d_oa_i_trp (:,:,:)   = oa_i (:,:,:)   - old_oa_i (:,:,:)
-      d_smv_i_trp(:,:,:)   = 0._wp
-      IF(  num_sal == 2  .OR.  num_sal == 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
-
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
-
-         IF(lwp) THEN
-            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limitd_me) = ',(zchk_v_i * 86400.)
-            IF (    ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limitd_me) = ',(zchk_smv * 86400.)
-            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limitd_me) = ',(MINVAL(v_i) * 1.e-3)
-            IF ( MAXVAL( SUM(a_i(:,:,:),dim=3) ) > amax+epsi10 ) WRITE(numout,*) 'violation a_i>amax            (limitd_me) = ',MAXVAL(SUM(a_i,dim=3))
-            IF ( MINVAL( a_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation a_i<0               (limitd_me) = ',MINVAL(a_i)
-         ENDIF
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
-      !-------------------------!
-      ! 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 == 2  .OR.  num_sal == 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
-!clem@order
-!      DO jl = 1, jpl
-!         DO jk = 1, nlay_i
-!            DO jj = 1, jpj
-!               DO ji = 1, jpi
-!                  IF ( ( old_v_i(ji,jj,jl) < epsi06 ) .AND. &
-!                     ( d_v_i_trp(ji,jj,jl) > 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._wp
-!                  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) < epsi06 ) .AND. &
-!                  ( d_v_i_trp(ji,jj,jl) > epsi06 ) ) THEN
-!                  old_v_i(ji,jj,jl)     = d_v_i_trp(ji,jj,jl)
-!                  d_v_i_trp(ji,jj,jl)   = 0._wp
-!                  old_a_i(ji,jj,jl)     = d_a_i_trp(ji,jj,jl)
-!                  d_a_i_trp(ji,jj,jl)   = 0._wp
-!                  old_v_s(ji,jj,jl)     = d_v_s_trp(ji,jj,jl)
-!                  d_v_s_trp(ji,jj,jl)   = 0._wp
-!                  old_e_s(ji,jj,1,jl)   = d_e_s_trp(ji,jj,1,jl)
-!                  d_e_s_trp(ji,jj,1,jl) = 0._wp
-!                  old_oa_i(ji,jj,jl)    = d_oa_i_trp(ji,jj,jl)
-!                  d_oa_i_trp(ji,jj,jl)  = 0._wp
-!                  IF(  num_sal == 2  .OR.  num_sal == 4  )   old_smv_i(ji,jj,jl)   = d_smv_i_trp(ji,jj,jl)
-!                  d_smv_i_trp(ji,jj,jl) = 0._wp
-!               ENDIF
-!            END DO
-!         END DO
-!      END DO
-!clem@order
-      ENDIF  ! ln_limdyn=.true.
-      !
-      CALL wrk_dealloc( jpi, jpj, closing_net, divu_adv, opning, closing_gross, msnow_mlt, esnow_mlt, vt_i_init, vt_i_final )
-      !
-      CALL wrk_dealloc( jpi, jpj, jpl, zviold, zvsold, zsmvold )   ! clem
-      !
-   END SUBROUTINE lim_itd_me
-
-
-   SUBROUTINE lim_itd_me_icestrength( kstrngth )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_me_icestrength ***
-      !!
-      !! ** Purpose :   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)
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kstrngth    ! = 1 for Rothrock formulation, 0 for Hibler (1979)
-
-      INTEGER ::   ji,jj, jl   ! dummy loop indices
-      INTEGER ::   ksmooth     ! smoothing the resistance to deformation
-      INTEGER ::   numts_rm    ! number of time steps for the P smoothing
-      REAL(wp) ::   hi, zw1, zp, zdummy, zzc, z1_3   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zworka   ! temporary array used here
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zworka )
-
-      !------------------------------------------------------------------------------!
-      ! 1) Initialize
-      !------------------------------------------------------------------------------!
-      strength(:,:) = 0._wp
-
-      !------------------------------------------------------------------------------!
-      ! 2) Compute thickness distribution of ridging and ridged ice
-      !------------------------------------------------------------------------------!
-      CALL lim_itd_me_ridgeprep
-
-      !------------------------------------------------------------------------------!
-      ! 3) Rothrock(1975)'s method
-      !------------------------------------------------------------------------------!
-      IF( kstrngth == 1 ) THEN
-         z1_3 = 1._wp / 3._wp
-         DO jl = 1, jpl
-            DO jj= 1, jpj
-               DO ji = 1, jpi
-                  !
-                  IF(  a_i(ji,jj,jl)    > epsi11  .AND.     &
-                       athorn(ji,jj,jl) > 0._wp   ) 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._wp * 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)     &
-                        * z1_3 * (hrmax(ji,jj,jl)**3 - hrmin(ji,jj,jl)**3) / ( hrmax(ji,jj,jl)-hrmin(ji,jj,jl) )   
-!!gm Optimization:  (a**3-b**3)/(a-b) = a*a+ab+b*b   ==> less costly operations even if a**3 is replaced by a*a*a...                    
-                  ENDIF            ! aicen > epsi11
-                  !
-               END DO ! ji
-            END DO !jj
-         END DO !jl
-
-         zzc = Cf * Cp     ! where Cp = (g/2)*(rhow-rhoi)*(rhoi/rhow) and Cf accounts for frictional dissipation
-         strength(:,:) = zzc * strength(:,:) / aksum(:,:)
-
-         ksmooth = 1
-
-         !------------------------------------------------------------------------------!
-         ! 4) Hibler (1979)' method
-         !------------------------------------------------------------------------------!
-      ELSE                      ! kstrngth ne 1:  Hibler (1979) form
-         !
-         strength(:,:) = Pstar * vt_i(:,:) * EXP( - C_rhg * ( 1._wp - at_i(:,:) )  )
-         !
-         ksmooth = 1
-         !
-      ENDIF                     ! kstrngth
-
-      !
-      !------------------------------------------------------------------------------!
-      ! 5) Impact of brine volume
-      !------------------------------------------------------------------------------!
-      ! CAN BE REMOVED
-      !
-      IF ( brinstren_swi == 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 == 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 == nit000 + nn_fsbc - 1 ) THEN
-         strp1(:,:) = 0.0            
-         strp2(:,:) = 0.0            
-      ENDIF
-
-      IF ( ksmooth == 2 ) THEN
-
-
-         CALL lbc_lnk( strength, 'T', 1. )
-
-         DO jj = 1, jpj - 1
-            DO ji = 1, jpi - 1
-               IF ( ( asum(ji,jj) - ato_i(ji,jj) ) .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
-
-      CALL lbc_lnk( strength, 'T', 1. )      ! Boundary conditions
-
-      CALL wrk_dealloc( jpi, jpj, zworka )
-      !
-   END SUBROUTINE lim_itd_me_icestrength
-
-
-   SUBROUTINE lim_itd_me_ridgeprep
-      !!---------------------------------------------------------------------!
-      !!                ***  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.
-      !!---------------------------------------------------------------------!
-      INTEGER ::   ji,jj, jl    ! dummy loop indices
-      INTEGER ::   krdg_index   ! 
-      REAL(wp) ::   Gstari, astari, hi, hrmean, zdummy   ! local scalar
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zworka    ! temporary array used here
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   Gsum      ! Gsum(n) = sum of areas in categories 0 to n
-      !------------------------------------------------------------------------------!
-
-      CALL wrk_alloc( jpi,jpj, zworka )
-      CALL wrk_alloc( jpi,jpj,jpl+2, Gsum, kkstart = -1 )
-
-      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._wp
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( ato_i(ji,jj) > epsi11 ) THEN   ;   Gsum(ji,jj,0) = ato_i(ji,jj)
-            ELSE                               ;   Gsum(ji,jj,0) = 0._wp
-            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
-      zworka(:,:) = 1._wp / Gsum(:,:,jpl)
-      DO jl = 0, jpl
-         Gsum(:,:,jl) = Gsum(:,:,jl) * zworka(:,:)
-      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 == 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                             !--- Exponential, more stable formulation (Lipscomb et al, 2007)
-         !                        
-         zdummy = 1._wp / ( 1._wp - EXP(-astari) )        ! precompute exponential terms using Gsum as a work array
-
-         DO jl = -1, jpl
-            Gsum(:,:,jl) = EXP( -Gsum(:,:,jl) * astari ) * zdummy
-         END DO !jl
-         DO jl = 0, ice_cat_bounds(1,2)
-             athorn(:,:,jl) = Gsum(:,:,jl-1) - Gsum(:,:,jl)
-         END DO
-         !
-      ENDIF ! krdg_index
-
-      IF( raftswi == 1 ) THEN      ! Ridging and rafting ice participation functions
-         !
-         DO jl = 1, jpl
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  IF ( athorn(ji,jj,jl) .GT. 0._wp ) THEN
-!!gm  TANH( -X ) = - TANH( X )  so can be computed only 1 time....
-                     aridge(ji,jj,jl) = ( TANH (  Craft * ( ht_i(ji,jj,jl) - hparmeter ) ) + 1.0 ) * 0.5 * athorn(ji,jj,jl)
-                     araft (ji,jj,jl) = ( TANH ( -Craft * ( ht_i(ji,jj,jl) - hparmeter ) ) + 1.0 ) * 0.5 * athorn(ji,jj,jl)
-                     IF ( araft(ji,jj,jl) < epsi06 )   araft(ji,jj,jl)  = 0._wp
-                     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
-            aridge(:,:,jl) = athorn(:,:,jl)
-         END DO
-         !
-      ENDIF
-
-      IF ( raftswi == 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
-      aksum(:,:) = athorn(:,:,0)
-      DO jl = 1, jpl 
-         aksum(:,:)    = aksum(:,:) + aridge(:,:,jl) * ( 1._wp - 1._wp / krdg(:,:,jl) )    &
-            &                       + araft (:,:,jl) * ( 1._wp - 1._wp / kraft        )
-      END DO
-      !
-      CALL wrk_dealloc( jpi,jpj, zworka )
-      CALL wrk_dealloc( jpi,jpj,jpl+2, Gsum, kkstart = -1 )
-      !
-   END SUBROUTINE lim_itd_me_ridgeprep
-
-
-   SUBROUTINE lim_itd_me_ridgeshift( opning, closing_gross, msnow_mlt, esnow_mlt )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_me_icestrength ***
-      !!
-      !! ** Purpose :   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.
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   opning         ! rate of opening due to divergence/shear
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   closing_gross  ! rate at which area removed, excluding area of new ridges
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   msnow_mlt      ! mass of snow added to ocean (kg m-2)
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   esnow_mlt      ! energy needed to melt snow in ocean (J m-2)
-      !
-      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
-      LOGICAL ::   large_afrac    ! flag for afrac > 1
-      LOGICAL ::   large_afrft    ! flag for afrac > 1
-      INTEGER ::   ji, jj, jl, jl1, jl2, jk   ! dummy loop indices
-      INTEGER ::   ij                ! horizontal index, combines i and j loops
-      INTEGER ::   icells            ! number of cells with aicen > puny
-      REAL(wp) ::   zeps, zindb, zsrdg2   ! local scalar
-      REAL(wp) ::   hL, hR, farea, zdummy, zdummy0, ztmelts    ! left and right limits of integration
-
-      INTEGER , POINTER, DIMENSION(:) ::   indxi, indxj   ! compressed indices
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vice_init, vice_final   ! ice volume summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:) ::   eice_init, eice_final   ! ice energy summed over layers
-
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   aicen_init, vicen_init   ! ice  area    & volume before ridging
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   vsnon_init, esnon_init   ! snow volume  & energy before ridging
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   smv_i_init, oa_i_init    ! ice salinity & age    before ridging
-
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   eicen_init        ! ice energy before ridging
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   afrac , fvol     ! fraction of category area ridged & new ridge volume going to n2
-      REAL(wp), POINTER, DIMENSION(:,:) ::   ardg1 , ardg2    ! area of ice ridged & new ridges
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vsrdg , esrdg    ! snow volume & energy of ridging ice
-      REAL(wp), POINTER, DIMENSION(:,:) ::   oirdg1, oirdg2   ! areal age content of ridged & rifging ice
-      REAL(wp), POINTER, DIMENSION(:,:) ::   dhr   , dhr2     ! hrmax - hrmin  &  hrmax^2 - hrmin^2
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vrdg1   ! volume of ice ridged
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vrdg2   ! volume of new ridges
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vsw     ! volume of seawater trapped into ridges
-      REAL(wp), POINTER, DIMENSION(:,:) ::   srdg1   ! sal*volume of ice ridged
-      REAL(wp), POINTER, DIMENSION(:,:) ::   srdg2   ! sal*volume of new ridges
-      REAL(wp), POINTER, DIMENSION(:,:) ::   smsw    ! sal*volume of water trapped into ridges
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   afrft            ! fraction of category area rafted
-      REAL(wp), POINTER, DIMENSION(:,:) ::   arft1 , arft2    ! area of ice rafted and new rafted zone
-      REAL(wp), POINTER, DIMENSION(:,:) ::   virft , vsrft    ! ice & snow volume of rafting ice
-      REAL(wp), POINTER, DIMENSION(:,:) ::   esrft , smrft    ! snow energy & salinity of rafting ice
-      REAL(wp), POINTER, DIMENSION(:,:) ::   oirft1, oirft2   ! areal age content of rafted ice & rafting ice
-
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   eirft      ! ice energy of rafting ice
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   erdg1      ! enth*volume of ice ridged
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   erdg2      ! enth*volume of new ridges
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ersw       ! enth of water trapped into ridges
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( (jpi+1)*(jpj+1),      indxi, indxj )
-      CALL wrk_alloc( jpi, jpj,             vice_init, vice_final, eice_init, eice_final )
-      CALL wrk_alloc( jpi, jpj,             afrac, fvol , ardg1, ardg2, vsrdg, esrdg, oirdg1, oirdg2, dhr, dhr2 )
-      CALL wrk_alloc( jpi, jpj,             vrdg1, vrdg2, vsw  , srdg1, srdg2, smsw )
-      CALL wrk_alloc( jpi, jpj,             afrft, arft1, arft2, virft, vsrft, esrft, smrft, oirft1, oirft2 )
-      CALL wrk_alloc( jpi, jpj, jpl,        aicen_init, vicen_init, vsnon_init, esnon_init, smv_i_init, oa_i_init )
-      CALL wrk_alloc( jpi, jpj, jkmax,      eirft, erdg1, erdg2, ersw )
-      CALL wrk_alloc( jpi, jpj, jkmax, jpl, eicen_init )
-
-      ! Conservation check
-      eice_init(:,:) = 0._wp
-
-      IF( con_i ) THEN
-         CALL lim_column_sum (jpl,   v_i, vice_init )
-         WRITE(numout,*) ' vice_init  : ', vice_init(jiindx,jjindx)
-         CALL lim_column_sum_energy (jpl, nlay_i,  e_i, eice_init )
-         WRITE(numout,*) ' eice_init  : ', eice_init(jiindx,jjindx)
-      ENDIF
-
-      zeps   = 1.e-20_wp
-
-      !-------------------------------------------------------------------------------
-      ! 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) < -epsi11 ) THEN
-               neg_ato_i = .TRUE.
-            ELSEIF( ato_i(ji,jj) < 0._wp ) THEN    ! roundoff error
-               ato_i(ji,jj) = 0._wp
-            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) < -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
-         END DO
-      ENDIF
-
-      !-----------------------------------------------------------------
-      ! 2) Save initial state variables
-      !-----------------------------------------------------------------
-
-      DO jl = 1, jpl
-         aicen_init(:,:,jl) = a_i(:,:,jl)
-         vicen_init(:,:,jl) = v_i(:,:,jl)
-         vsnon_init(:,:,jl) = v_s(:,:,jl)
-         !
-         smv_i_init(:,:,jl) = smv_i(:,:,jl)
-         oa_i_init (:,:,jl) = oa_i (:,:,jl)
-      END DO !jl
-
-      esnon_init(:,:,:) = e_s(:,:,1,:)
-
-      DO jl = 1, jpl  
-         DO jk = 1, nlay_i
-            eicen_init(:,:,jk,jl) = e_i(:,:,jk,jl)
-         END DO
-      END DO
-
-      !
-      !-----------------------------------------------------------------
-      ! 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) > amax + epsi11) THEN  !riging
-               large_afrac = .true.
-            ELSEIF (afrac(ji,jj) > amax) THEN  ! roundoff error
-               afrac(ji,jj) = amax
-            ENDIF
-            IF (afrft(ji,jj) > amax + epsi11) THEN !rafting
-               large_afrft = .true.
-            ELSEIF (afrft(ji,jj) > amax) THEN  ! roundoff error
-               afrft(ji,jj) = amax
-            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._wp + 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._wp + 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_m(ji,jj) * vsw(ji,jj) * rhoic / rau0       ! salt content of water frozen in voids
-
-            zsrdg2       = srdg1(ji,jj) + smsw(ji,jj)                     ! salt content of new ridge
-
-            srdg2(ji,jj) = MIN( s_i_max * vrdg2(ji,jj) , zsrdg2 )         ! impose a maximum salinity
-            
-            !                                                             ! excess of salt is flushed into the ocean
-            !fsalt_rpo(ji,jj) = fsalt_rpo(ji,jj) + ( zsrdg2 - srdg2(ji,jj) ) * rhoic / rdt_ice
-
-            !rdmicif(ji,jj) = rdmicif(ji,jj) + vsw(ji,jj) * rhoic    ! gurvan: increase in ice volume du to seawater frozen in voids             
-
-            !------------------------------------            
-            ! 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)
-            !clem 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._wp + 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_m(ji,jj) + rtt
-               ! heat content per unit volume
-               zdummy0          = - rcp * ( sst_m(ji,jj) + rt0 - rtt ) * vsw(ji,jj)
-
-               ! corrected sea water salinity
-               zindb  = MAX( 0._wp , SIGN( 1._wp , vsw(ji,jj) - 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.e-09
-
-               ! Mutliply by ice volume, and divide by number of layers to get heat content in 10^9 J
-               ersw (ji,jj,jk)  = ersw(ji,jj,jk) * area(ji,jj) * vsw(ji,jj) / REAL( nlay_i )
-
-               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) > amax + epsi11 ) THEN 
-                  WRITE(numout,*) ''
-                  WRITE(numout,*) ' ardg > a_i'
-                  WRITE(numout,*) ' ardg, aicen_init : ', ardg1(ji,jj), aicen_init(ji,jj,jl1)
-               ENDIF
-            END DO
-         ENDIF
-         IF( large_afrft ) THEN  ! there is a bug
-!CDIR NODEP
-            DO ij = 1, icells
-               ji = indxi(ij)
-               jj = indxj(ij)
-               IF( afrft(ji,jj) > amax + epsi11 ) THEN 
-                  WRITE(numout,*) ''
-                  WRITE(numout,*) ' arft > a_i'
-                  WRITE(numout,*) ' arft, aicen_init : ', arft1(ji,jj), aicen_init(ji,jj,jl1)
-               ENDIF
-            END DO
-         ENDIF
-
-         !-------------------------------------------------------------------------------
-         ! 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)   + ardg2 (ji,jj) * farea
-               v_i  (ji,jj,jl2)   = v_i  (ji,jj,jl2)   + vrdg2 (ji,jj) * fvol(ji,jj)
-               v_s  (ji,jj,jl2)   = v_s  (ji,jj,jl2)   + vsrdg (ji,jj) * fvol(ji,jj) * fsnowrdg
-               e_s  (ji,jj,1,jl2) = e_s  (ji,jj,1,jl2) + esrdg (ji,jj) * fvol(ji,jj) * fsnowrdg
-               smv_i(ji,jj,jl2)   = smv_i(ji,jj,jl2)   + srdg2 (ji,jj) * fvol(ji,jj)
-               oa_i (ji,jj,jl2)   = oa_i (ji,jj,jl2)   + oirdg2(ji,jj) * farea
-
-            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
-            END DO
-            !
-         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(jiindx,jjindx)
-         WRITE(numout,*) ' vice_final : ', vice_final(jiindx,jjindx)
-
-         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(jiindx,jjindx)
-         WRITE(numout,*) ' eice_final : ', eice_final(jiindx,jjindx)
-      ENDIF
-      !
-      CALL wrk_dealloc( (jpi+1)*(jpj+1),      indxi, indxj )
-      CALL wrk_dealloc( jpi, jpj,             vice_init, vice_final, eice_init, eice_final )
-      CALL wrk_dealloc( jpi, jpj,             afrac, fvol , ardg1, ardg2, vsrdg, esrdg, oirdg1, oirdg2, dhr, dhr2 )
-      CALL wrk_dealloc( jpi, jpj,             vrdg1, vrdg2, vsw  , srdg1, srdg2, smsw )
-      CALL wrk_dealloc( jpi, jpj,             afrft, arft1, arft2, virft, vsrft, esrft, smrft, oirft1, oirft2 )
-      CALL wrk_dealloc( jpi, jpj, jpl,        aicen_init, vicen_init, vsnon_init, esnon_init, smv_i_init, oa_i_init )
-      CALL wrk_dealloc( jpi, jpj, jkmax,      eirft, erdg1, erdg2, ersw )
-      CALL wrk_dealloc( jpi, jpj, jkmax, jpl, eicen_init )
-      !
-   END SUBROUTINE lim_itd_me_ridgeshift
-
-
-   SUBROUTINE lim_itd_me_asumr
-      !!-----------------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_me_asumr ***
-      !!
-      !! ** Purpose :   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. 
-      !!-----------------------------------------------------------------------------
-      INTEGER ::   jl   ! dummy loop index
-      !!-----------------------------------------------------------------------------
-      !
-      asum(:,:) = ato_i(:,:)                    ! open water
-      DO jl = 1, jpl                            ! ice categories
-         asum(:,:) = asum(:,:) + a_i(:,:,jl)
-      END DO
-      !
-   END SUBROUTINE lim_itd_me_asumr
-
-
-   SUBROUTINE lim_itd_me_init
-      !!-------------------------------------------------------------------
-      !!                   ***  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
-      !!-------------------------------------------------------------------
-      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
-      !!-------------------------------------------------------------------
-      !
-      REWIND( numnam_ice )                   ! read namiceitdme namelist
-      READ  ( numnam_ice , namiceitdme)
-      !
-      IF (lwp) THEN                          ! control print
-         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, jl, jk   ! dummy loop indices
-      INTEGER ::   icells           ! number of cells with ice to zap
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zmask   ! 2D workspace
-      
-!!gm      REAL(wp) ::   xtmp      ! temporary variable
-      !!-------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zmask )
-
-      DO jl = 1, jpl
-
-         !-----------------------------------------------------------------
-         ! Count categories to be zapped.
-         ! Abort model in case of negative area.
-         !-----------------------------------------------------------------
-         IF( MINVAL(a_i(:,:,jl)) .LT. -epsi11 .AND. ln_nicep ) 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._wp
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF(  ( a_i(ji,jj,jl) .GE. -epsi11 .AND. a_i(ji,jj,jl) .LT. 0._wp   ) .OR.   &
-                  & ( a_i(ji,jj,jl) .GT. 0._wp   .AND. a_i(ji,jj,jl) .LE. 1.0e-11 ) .OR.   &
-                  & ( v_i(ji,jj,jl)  ==  0._wp   .AND. a_i(ji,jj,jl) .GT. 0._wp   ) .OR.   &
-                  & ( v_i(ji,jj,jl) .GT. 0._wp   .AND. v_i(ji,jj,jl) .LT. 1.e-12  )      )   zmask(ji,jj) = 1._wp
-            END DO
-         END DO
-         IF( ln_nicep )   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
-!!gm                  xtmp = e_i(ji,jj,jk,jl) / area(ji,jj) / rdt_ice
-!!gm                  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
-            END DO
-         END DO
-
-         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
-!!gm               xtmp = ( rhosn*cpic*( rtt-t_s(ji,jj,1,jl) ) + rhosn*lfus ) / rdt_ice
-               !           fheat_res(ji,jj) = fheat_res(ji,jj) - xtmp
-
-!!gm               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_m(ji,jj)                  ) * & 
-               !                               rhosn * v_s(ji,jj,jl) / rdt_ice
-
-               !           fsalt_res(ji,jj)  = fsalt_res(ji,jj) + ( sss_m(ji,jj) - sm_i(ji,jj,jl) ) * & 
-               !                               rhoic * v_i(ji,jj,jl) / rdt_ice
-
-               !           emps(i,j)      = emps(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
-         END DO
-         !
-      END DO                 ! jl 
-      !
-      CALL wrk_dealloc( jpi, jpj, zmask )
-      !
-   END SUBROUTINE lim_itd_me_zapsmall
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty module          NO LIM-3 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_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: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limitd_th.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limitd_th.F90	(revision 3937)
+++ 	(revision )
@@ -1,1099 +1,0 @@
-MODULE limitd_th
-   !!======================================================================
-   !!                       ***  MODULE limitd_th ***
-   !!              Thermodynamics of ice thickness distribution
-   !!                   computation of changes in g(h)      
-   !!======================================================================
-   !! History :   -   !          (W. H. Lipscomb and E.C. Hunke) CICE (c) original code
-   !!            3.0  ! 2005-12  (M. Vancoppenolle) adaptation to LIM-3
-   !!             -   ! 2006-06  (M. Vancoppenolle) adaptation to include salt, age and types
-   !!             -   ! 2007-04  (M. Vancoppenolle) Mass conservation checked
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                   LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_itd_th       : thermodynamics of ice thickness distribution
-   !!   lim_itd_th_rem   :
-   !!   lim_itd_th_reb   :
-   !!   lim_itd_fitline  :
-   !!   lim_itd_shiftice :
-   !!----------------------------------------------------------------------
-   USE dom_ice          ! LIM-3 domain
-   USE par_oce          ! ocean parameters
-   USE dom_oce          ! ocean domain
-   USE phycst           ! physical constants (ocean directory) 
-   USE thd_ice          ! LIM-3 thermodynamic variables
-   USE ice              ! LIM-3 variables
-   USE par_ice          ! LIM-3 parameters
-   USE limthd_lac       ! LIM-3 lateral accretion
-   USE limvar           ! LIM-3 variables
-   USE limcons          ! LIM-3 conservation
-   USE prtctl           ! Print control
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE lib_fortran      ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   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
-
-   REAL(wp) ::   epsi20 = 1.e-20_wp   ! constant values
-   REAL(wp) ::   epsi13 = 1.e-13_wp   !
-   REAL(wp) ::   epsi10 = 1.e-10_wp   !
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
-   !! $Id: limitd_th.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_itd_th( kt )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_th ***
-      !!
-      !! ** Purpose :   computes the thermodynamics of ice thickness distribution
-      !!
-      !! ** Method  :
-      !!------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! time step index
-      !
-      INTEGER ::   jl, ja, jm, jbnd1, jbnd2   ! ice types    dummy loop index         
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-      !!------------------------------------------------------------------
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
-      IF( kt == nit000 .AND. 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) > 1 )   CALL lim_itd_th_rem( jbnd1, jbnd2, jm, kt )
-      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_oa_i_thd(:,:,:)  = oa_i (:,:,:) - old_oa_i (:,:,:)
-      d_smv_i_thd(:,:,:) = 0._wp
-      IF( num_sal == 2 .OR. num_sal == 4 )   d_smv_i_thd(:,:,:) = smv_i(:,:,:) - old_smv_i(:,:,:)
-
-      ! diag only (clem)
-      dv_dt_thd(:,:,:) = d_v_i_thd(:,:,:) / rdt_ice * 86400.0
-
-      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
-      !
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
-
-         IF(lwp) THEN
-            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limitd_th) = ',(zchk_v_i * 86400.)
-            IF (    ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limitd_th) = ',(zchk_smv * 86400.)
-            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limitd_th) = ',(MINVAL(v_i) * 1.e-3)
-            IF ( MAXVAL( SUM(a_i(:,:,:),dim=3) ) >  amax+epsi10 ) WRITE(numout,*) 'violation a_i>amax    (limitd_th) = ',MAXVAL(SUM(a_i,dim=3))
-         ENDIF
-       ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-      !
-      !- 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 (:,:,:,:)
-      !?? oa_i(:,:,:)  = old_oa_i(:,:,:)
-      IF( num_sal == 2 .OR. num_sal == 4 )   smv_i(:,:,:)       = old_smv_i (:,:,:)
-      !
-   END SUBROUTINE lim_itd_th
-   !
-
-   SUBROUTINE lim_itd_th_rem( klbnd, kubnd, ntyp, kt )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_th_rem ***
-      !!
-      !! ** Purpose :   computes the redistribution of ice thickness
-      !!              after thermodynamic growth of ice thickness
-      !!
-      !! ** Method  : Linear remapping 
-      !!
-      !! References : W.H. Lipscomb, JGR 2001
-      !!------------------------------------------------------------------
-      INTEGER , INTENT (in) ::   klbnd   ! Start thickness category index point
-      INTEGER , INTENT (in) ::   kubnd   ! End point on which the  the computation is applied
-      INTEGER , INTENT (in) ::   ntyp    ! Number of the type used
-      INTEGER , INTENT (in) ::   kt      ! Ocean time step 
-      !
-      INTEGER  ::   ji, jj, jl     ! dummy loop index
-      INTEGER  ::   zji, zjj, nd   ! local integer
-      REAL(wp) ::   zx1, zwk1, zdh0, zetamin, zdamax   ! local scalars
-      REAL(wp) ::   zx2, zwk2, zda0, zetamax, zhimin   !   -      -
-      REAL(wp) ::   zx3,             zareamin, zindb   !   -      -
-      CHARACTER (len = 15) :: fieldid
-
-      INTEGER , POINTER, DIMENSION(:,:,:) ::   zdonor   ! donor category index
-
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zdhice      ! ice thickness increment
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   g0          ! coefficients for fitting the line of the ITD
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   g1          ! coefficients for fitting the line of the ITD
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   hL          ! left boundary for the ITD for each thickness
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   hR          ! left boundary for the ITD for each thickness
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zht_i_o     ! old ice thickness
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   dummy_es
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zdaice, zdvice          ! local increment of ice area and volume
-      REAL(wp), POINTER, DIMENSION(:)     ::   zvetamin, zvetamax      ! maximum values for etas
-      INTEGER , POINTER, DIMENSION(:)     ::   nind_i, nind_j          ! compressed indices for i/j directions
-      INTEGER                             ::   nbrem                   ! number of cells with ice to transfer
-      REAL(wp)                            ::   zslope                  ! used to compute local thermodynamic "speeds"
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zhb0, zhb1              ! category boundaries for thinnes categories
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   vt_i_init, vt_i_final   !  ice volume summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   vt_s_init, vt_s_final   !  snow volume summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   et_i_init, et_i_final   !  ice energy summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   et_s_init, et_s_final   !  snow energy summed over categories
-      INTEGER , POINTER, DIMENSION(:,:)   ::   zremap_flag      ! compute remapping or not ????
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zhbnew           ! new boundaries of ice categories
-      !!------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj, zremap_flag )    ! integer
-      CALL wrk_alloc( jpi,jpj,jpl-1, zdonor )   ! integer
-      CALL wrk_alloc( jpi,jpj,jpl, zdhice, g0, g1, hL, hR, zht_i_o, dummy_es )
-      CALL wrk_alloc( jpi,jpj,jpl-1, zdaice, zdvice )   
-      CALL wrk_alloc( jpi,jpj,jpl+1, zhbnew, kkstart = 0 )   
-      CALL wrk_alloc( (jpi+1)*(jpj+1), zvetamin, zvetamax )   
-      CALL wrk_alloc( (jpi+1)*(jpj+1), nind_i, nind_j )   ! integer 
-      CALL wrk_alloc( jpi,jpj, zhb0,zhb1,vt_i_init,vt_i_final,vt_s_init,vt_s_final,et_i_init,et_i_final,et_s_init,et_s_final )
-
-      zhimin   = 0.1      !minimum ice thickness tolerated by the model
-      zareamin = epsi10   !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( kt == nit000 .AND. 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._wp
-      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)+epsi10))     !0 if no ice and 1 if yes
-               ht_i(ji,jj,jl)    = v_i(ji,jj,jl) / MAX(a_i(ji,jj,jl),epsi10) * zindb
-               zindb             = 1.0-MAX(0.0,SIGN(1.0,-old_a_i(ji,jj,jl)+epsi10)) !0 if no ice and 1 if yes
-               zht_i_o(ji,jj,jl) = old_v_i(ji,jj,jl) / MAX(old_a_i(ji,jj,jl),epsi10) * zindb
-               IF( a_i(ji,jj,jl) > 1e-6 )   zdhice(ji,jj,jl) = ht_i(ji,jj,jl) - zht_i_o(ji,jj,jl) 
-            END DO
-         END DO
-      END DO
-
-      !-----------------------------------------------------------------------------------------------
-      !  2) Compute fractional ice area in each grid cell
-      !-----------------------------------------------------------------------------------------------
-      at_i(:,:) = 0._wp
-      DO jl = klbnd, kubnd
-         at_i(:,:) = at_i(:,:) + a_i(:,:,jl)
-      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) = 1
-            ELSE
-               zremap_flag(ji,jj) = 0
-            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._wp
-
-      DO jl = klbnd, kubnd - 1
-         DO ji = 1, nbrem
-            zji = nind_i(ji)
-            zjj = nind_j(ji)
-            !
-            IF ( ( zht_i_o(zji,zjj,jl)  .GT.epsi10 ) .AND. & 
-               ( zht_i_o(zji,zjj,jl+1).GT.epsi10 ) ) 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.epsi10) THEN
-               zhbnew(zji,zjj,jl) = hi_max(jl) + zdhice(zji,zjj,jl)
-            ELSEIF (zht_i_o(zji,zjj,jl+1).gt.epsi10) THEN
-               zhbnew(zji,zjj,jl) = hi_max(jl) + zdhice(zji,zjj,jl+1)
-            ELSE
-               zhbnew(zji,zjj,jl) = hi_max(jl)
-            ENDIF
-         END DO
-
-         !- 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.epsi10) .AND. & 
-               ( ht_i(zji,zjj,jl).GE. zhbnew(zji,zjj,jl) ) &
-               ) THEN
-               zremap_flag(zji,zjj) = 0
-            ELSEIF ( ( a_i(zji,zjj,jl+1) .GT. epsi10 ) .AND. &
-               ( ht_i(zji,zjj,jl+1).LE. zhbnew(zji,zjj,jl) ) &
-               ) THEN
-               zremap_flag(zji,zjj) = 0
-            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) = 0
-            ENDIF
-            ! jl, ji
-            IF (zhbnew(zji,zjj,jl).lt.hi_max(jl-1)) THEN
-               zremap_flag(zji,zjj) = 0
-            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) == 1 ) 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._wp
-
-            IF( a_i(ji,jj,kubnd) > epsi10 ) THEN
-               zhbnew(ji,jj,kubnd) = 3._wp * ht_i(ji,jj,kubnd) - 2._wp * zhbnew(ji,jj,kubnd-1)
-            ELSE
-               zhbnew(ji,jj,kubnd) = hi_max(kubnd)
-            ENDIF
-
-            IF( zhbnew(ji,jj,kubnd) < 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. epsi10) THEN
-            zdh0 = zdhice(zji,zjj,klbnd) !decrease of ice thickness in the lower category
-            ! ji, a_i > epsi10
-            IF (zdh0 .lt. 0.0) THEN !remove area from category 1
-               ! ji, a_i > epsi10; 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) ! clem@useless
-               ENDIF     ! zetamax > 0
-               ! ji, a_i > epsi10
-
-            ELSE ! if ice accretion
-               ! ji, a_i > epsi10; 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 > epsi10
-         ENDIF ! a_i > epsi10
-
-      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. epsi10 ) .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) !clem@useless
-         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
-
-      CALL wrk_dealloc( jpi,jpj, zremap_flag )    ! integer
-      CALL wrk_dealloc( jpi,jpj,jpl-1, zdonor )   ! integer
-      CALL wrk_dealloc( jpi,jpj,jpl, zdhice, g0, g1, hL, hR, zht_i_o, dummy_es )
-      CALL wrk_dealloc( jpi,jpj,jpl-1, zdaice, zdvice )   
-      CALL wrk_dealloc( jpi,jpj,jpl+1, zhbnew, kkstart = 0 )   
-      CALL wrk_dealloc( (jpi+1)*(jpj+1), zvetamin, zvetamax )   
-      CALL wrk_dealloc( (jpi+1)*(jpj+1), nind_i, nind_j )   ! integer 
-      CALL wrk_dealloc( jpi,jpj, zhb0,zhb1,vt_i_init,vt_i_final,vt_s_init,vt_s_final,et_i_init,et_i_final,et_s_init,et_s_final )
-
-   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.
-      !!------------------------------------------------------------------
-      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)
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   hL           ! min value of range over which g(h) > 0
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   hR           ! max value of range over which g(h) > 0
-      INTEGER , DIMENSION(jpi,jpj), INTENT(in   ) ::   zremap_flag  !
-      !
-      INTEGER ::   ji,jj           ! horizontal indices
-      REAL(wp) ::   zh13         ! HbL + 1/3 * (HbR - HbL)
-      REAL(wp) ::   zh23         ! HbL + 2/3 * (HbR - HbL)
-      REAL(wp) ::   zdhr         ! 1 / (hR - hL)
-      REAL(wp) ::   zwk1, zwk2   ! temporary variables
-      REAL(wp) ::   zacrith      ! critical minimum concentration in an ice category
-      !!------------------------------------------------------------------
-      !
-      zacrith       = 1.0e-6
-      !
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            !
-            IF( zremap_flag(ji,jj) == 1 .AND. a_i(ji,jj,num_cat) > zacrith   &
-               &                        .AND. hice(ji,jj)        > 0._wp     ) 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._wp * hice(ji,jj) - 2._wp * hL(ji,jj)
-               ELSEIF( hice(ji,jj) > zh23 ) THEN   ;   hL(ji,jj) = 3._wp * hice(ji,jj) - 2._wp * hR(ji,jj)
-               ENDIF
-
-               ! Compute coefficients of g(eta) = g0 + g1*eta
-
-               zdhr = 1._wp / (hR(ji,jj) - hL(ji,jj))
-               zwk1 = 6._wp * a_i(ji,jj,num_cat) * zdhr
-               zwk2 = ( hice(ji,jj) - hL(ji,jj) ) * zdhr
-               g0(ji,jj) = zwk1 * ( 2._wp/3._wp - zwk2 )
-               g1(ji,jj) = 2._wp * zdhr * zwk1 * (zwk2 - 0.5)
-               !
-            ELSE                   ! remap_flag = .false. or a_i < epsi10 
-               hL(ji,jj) = 0._wp
-               hR(ji,jj) = 0._wp
-               g0(ji,jj) = 0._wp
-               g1(ji,jj) = 0._wp
-            ENDIF                  ! a_i > epsi10
-            !
-         END DO
-      END DO
-      !
-   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  :
-      !!------------------------------------------------------------------
-      INTEGER                           , INTENT(in   ) ::   klbnd    ! Start thickness category index point
-      INTEGER                           , INTENT(in   ) ::   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
-      REAL(wp), DIMENSION(jpi,jpj,jpl-1), INTENT(inout) ::   zdvice   ! ice volume transferred across boundary
-
-      INTEGER ::   ji, jj, jl, jl2, jl1, jk   ! dummy loop indices
-      INTEGER ::   zji, zjj          ! indices when changing from 2D-1D is done
-
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zaTsfn
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zworka            ! temporary array used here
-
-      REAL(wp) ::   zdvsnow, zdesnow   ! snow volume and energy transferred
-      REAL(wp) ::   zdeice             ! ice energy transferred
-      REAL(wp) ::   zdsm_vice          ! ice salinity times volume transferred
-      REAL(wp) ::   zdo_aice           ! ice age times volume transferred
-      REAL(wp) ::   zdaTsf             ! aicen*Tsfcn transferred
-      REAL(wp) ::   zindsn             ! snow or not
-      REAL(wp) ::   zindb              ! ice or not
-
-      INTEGER, POINTER, DIMENSION(:) ::   nind_i, nind_j   ! compressed indices for i/j directions
-
-      INTEGER ::   nbrem             ! number of cells with ice to transfer
-
-      LOGICAL ::   zdaice_negative         ! true if daice < -puny
-      LOGICAL ::   zdvice_negative         ! true if dvice < -puny
-      LOGICAL ::   zdaice_greater_aicen    ! true if daice > aicen
-      LOGICAL ::   zdvice_greater_vicen    ! true if dvice > vicen
-      !!------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj,jpl, zaTsfn )
-      CALL wrk_alloc( jpi,jpj, zworka )
-      CALL wrk_alloc( (jpi+1)*(jpj+1), nind_i, nind_j )   ! integer
-
-      !----------------------------------------------------------------------------------------------
-      ! 1) Define a variable equal to a_i*T_su
-      !----------------------------------------------------------------------------------------------
-
-      DO jl = klbnd, kubnd
-         zaTsfn(:,:,jl) = a_i(:,:,jl)*t_su(:,:,jl)
-      END DO
-
-      !----------------------------------------------------------------------------------------------
-      ! 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. -epsi10) 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. -epsi10 ) 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) - epsi10 ) THEN
-                     IF (zdaice(ji,jj,jl) .LT. a_i(ji,jj,jl1)+epsi10) 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)-epsi10) THEN
-                     IF (zdvice(ji,jj,jl) .LT. v_i(ji,jj,jl1)+epsi10) 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) - epsi10 ) )
-            zworka(zji,zjj)   = zdvice(zji,zjj,jl) / MAX(v_i(zji,zjj,jl1),epsi10) * zindb
-            IF( jl1 == jl) THEN   ;   jl2 = jl1+1
-            ELSE                    ;   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) > epsi10 ) 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)+epsi10)) !0 if no ice and 1 if yes
-               ELSE
-                  ht_i(ji,jj,jl)  = 0._wp
-                  t_su(ji,jj,jl)  = rtt
-               ENDIF
-            END DO                 ! ji
-         END DO                 ! jj
-      END DO                    ! jl
-      !
-      CALL wrk_dealloc( jpi,jpj,jpl, zaTsfn )
-      CALL wrk_dealloc( jpi,jpj, zworka )
-      CALL wrk_dealloc( (jpi+1)*(jpj+1), nind_i, nind_j )   ! integer
-      !
-   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  :
-      !!------------------------------------------------------------------
-      INTEGER , INTENT (in) ::   klbnd   ! Start thickness category index point
-      INTEGER , INTENT (in) ::   kubnd   ! End point on which the  the computation is applied
-      INTEGER , INTENT (in) ::   ntyp    ! number of the ice type involved in the rebinning process
-      !
-      INTEGER ::   ji,jj, jl   ! dummy loop indices
-      INTEGER ::   zshiftflag          ! = .true. if ice must be shifted
-      CHARACTER (len = 15) :: fieldid
-
-      INTEGER , POINTER, DIMENSION(:,:,:) ::   zdonor           ! donor category index
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zdaice, zdvice   ! ice area and volume transferred
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vt_i_init, vt_i_final   ! ice volume summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vt_s_init, vt_s_final   ! snow volume summed over categories
-      !!------------------------------------------------------------------
-      
-      CALL wrk_alloc( jpi,jpj,jpl, zdonor )   ! interger
-      CALL wrk_alloc( jpi,jpj,jpl, zdaice, zdvice )
-      CALL wrk_alloc( jpi,jpj, vt_i_init, vt_i_final, vt_s_init, vt_s_final )
-      !     
-      IF( con_i ) THEN                 ! conservation check
-         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) > epsi10 ) THEN 
-                  ht_i(ji,jj,jl) = v_i(ji,jj,jl) / a_i(ji,jj,jl)
-               ELSE
-                  ht_i(ji,jj,jl) = 0._wp
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      !------------------------------------------------------------------------------
-      ! 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) > epsi10 ) THEN
-               IF( ht_i(ji,jj,klbnd) <= hi_max_typ(0,ntyp) .AND. hi_max_typ(0,ntyp) > 0._wp ) THEN
-                  a_i(ji,jj,klbnd)  = v_i(ji,jj,klbnd) / hi_max_typ(0,ntyp) 
-                  ht_i(ji,jj,klbnd) = hi_max_typ(0,ntyp)
-               ENDIF
-            ENDIF
-         END DO
-      END DO
-
-      !------------------------------------------------------------------------------
-      ! 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
-         zdonor(:,:,jl) = 0
-         zdaice(:,:,jl) = 0._wp
-         zdvice(:,:,jl) = 0._wp
-      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) > epsi10 .AND. ht_i(ji,jj,jl) > 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)
-                  ! begin TECLIM change
-                  ! zdaice(ji,jj,jl)  = a_i(ji,jj,jl) 
-                  ! zdvice(ji,jj,jl)  = v_i(ji,jj,jl)
-                  zdaice(ji,jj,jl)  = a_i(ji,jj,jl)/2
-                  zdvice(ji,jj,jl)  = v_i(ji,jj,jl)-zdaice(ji,jj,jl)*(hi_max(jl)+hi_max(jl-1))/2
-                  ! end TECLIM change 
-               ENDIF
-            END DO                 ! ji
-         END DO                 ! jj
-         IF(lk_mpp)   CALL mpp_max( zshiftflag )
-
-         IF( zshiftflag == 1 ) THEN            ! Shift ice between categories
-            CALL lim_itd_shiftice( klbnd, kubnd, zdonor, zdaice, zdvice )
-            ! Reset shift parameters
-            zdonor(:,:,jl) = 0
-            zdaice(:,:,jl) = 0._wp
-            zdvice(:,:,jl) = 0._wp
-         ENDIF
-         !
-      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) >  epsi10 .AND.   &
-                  ht_i(ji,jj,jl+1) <= hi_max(jl) ) THEN
-                  !
-                  zshiftflag = 1
-                  zdonor(ji,jj,jl) = jl + 1
-                  zdaice(ji,jj,jl) = a_i(ji,jj,jl+1) 
-                  zdvice(ji,jj,jl) = v_i(ji,jj,jl+1)
-               ENDIF
-            END DO                 ! ji
-         END DO                 ! jj
-
-         IF(lk_mpp)   CALL mpp_max( zshiftflag )
-         
-         IF( zshiftflag == 1 ) THEN            ! Shift ice between categories
-            CALL lim_itd_shiftice( klbnd, kubnd, zdonor, zdaice, zdvice )
-            ! Reset shift parameters
-            zdonor(:,:,jl) = 0
-            zdaice(:,:,jl) = 0._wp
-            zdvice(:,:,jl) = 0._wp
-         ENDIF
-
-      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
-      !
-      CALL wrk_dealloc( jpi,jpj,jpl, zdonor )   ! interger
-      CALL wrk_dealloc( jpi,jpj,jpl, zdaice, zdvice )
-      CALL wrk_dealloc( jpi,jpj, vt_i_init, vt_i_final, vt_s_init, vt_s_final )
-
-   END SUBROUTINE lim_itd_th_reb
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option            Dummy module         NO LIM 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: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limrhg.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limrhg.F90	(revision 3937)
+++ 	(revision )
@@ -1,789 +1,0 @@
-MODULE limrhg
-   !!======================================================================
-   !!                     ***  MODULE  limrhg  ***
-   !!   Ice rheology : sea ice rheology
-   !!======================================================================
-   !! History :   -   !  2007-03  (M.A. Morales Maqueda, S. Bouillon) Original code
-   !!            3.0  !  2008-03  (M. Vancoppenolle) LIM3
-   !!             -   !  2008-11  (M. Vancoppenolle, S. Bouillon, Y. Aksenov) add surface tilt in ice rheolohy 
-   !!            3.3  !  2009-05  (G.Garric) addition of the lim2_evp cas
-   !!            4.0  !  2011-01  (A Porter)  dynamical allocation 
-   !!----------------------------------------------------------------------
-#if defined key_lim3 || (  defined key_lim2 && ! defined key_lim2_vp )
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'               OR                     LIM-3 sea-ice model
-   !!   'key_lim2' AND NOT 'key_lim2_vp'            EVP LIM-2 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_rhg   : computes ice velocities
-   !!----------------------------------------------------------------------
-   USE phycst           ! Physical constant
-   USE par_oce          ! Ocean parameters
-   USE dom_oce          ! Ocean domain
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE sbc_ice          ! Surface boundary condition: ice fields
-   USE lbclnk           ! Lateral Boundary Condition / MPP link
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE in_out_manager   ! I/O manager
-   USE prtctl           ! Print control
-#if defined key_lim3
-   USE ice              ! LIM-3: ice variables
-   USE dom_ice          ! LIM-3: ice domain
-   USE limitd_me        ! LIM-3: 
-#else
-   USE ice_2            ! LIM2: ice variables
-   USE dom_ice_2        ! LIM2: ice domain
-#endif
-   USE lib_fortran      ! to use key_nosignedzero
-
-#if defined key_bdy
-   USE bdyice_lim
-#endif
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_rhg        ! routine called by lim_dyn (or lim_dyn_2)
-
-   REAL(wp) ::   rzero   = 0._wp   ! constant values
-   REAL(wp) ::   rone    = 1._wp   ! constant values
-   REAL(wp) ::   epsi20  = 1.e-20_wp   ! constant values
-      
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limrhg.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/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., Ocean Modelling 2009
-      !!              Vancoppenolle et al., Ocean Modelling 2008
-      !!-------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   k_j1    ! southern j-index for ice computation
-      INTEGER, INTENT(in) ::   k_jpj   ! northern j-index for ice computation
-      !!
-      INTEGER ::   ji, jj   ! dummy loop indices
-      INTEGER ::   jter     ! local integers
-      CHARACTER (len=50) ::   charout
-      REAL(wp) ::   zt11, zt12, zt21, zt22, ztagnx, ztagny, delta                         !
-      REAL(wp) ::   za, zstms, zsang, zmask   ! local scalars
-
-      REAL(wp) ::   dtevp              ! time step for subcycling
-      REAL(wp) ::   dtotel, ecc2       ! square of yield ellipse eccenticity
-      REAL(wp) ::   z0, zr, zcca, zccb ! temporary scalars
-      REAL(wp) ::   zu_ice2, zv_ice1   !
-      REAL(wp) ::   zddc, zdtc, zdst   ! delta on corners and on centre
-      REAL(wp) ::   zdsshx, zdsshy     ! term for the gradient of ocean surface
-      REAL(wp) ::   sigma1, sigma2     ! internal ice stress
-
-      REAL(wp) ::   zresm         ! Maximal error on ice velocity
-      REAL(wp) ::   zindb         ! ice (1) or not (0)      
-      REAL(wp) ::   zdummy        ! dummy argument
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zpresh           ! temporary array for ice strength
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zpreshc          ! Ice strength on grid cell corners (zpreshc)
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zfrld1, zfrld2   ! lead fraction on U/V points
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zmass1, zmass2   ! ice/snow mass on U/V points
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zcorl1, zcorl2   ! coriolis parameter on U/V points
-      REAL(wp), POINTER, DIMENSION(:,:) ::   za1ct , za2ct    ! temporary arrays
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zc1              ! ice mass
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zusw             ! temporary weight for ice strength computation
-      REAL(wp), POINTER, DIMENSION(:,:) ::   u_oce1, v_oce1   ! ocean u/v component on U points                           
-      REAL(wp), POINTER, DIMENSION(:,:) ::   u_oce2, v_oce2   ! ocean u/v component on V points
-      REAL(wp), POINTER, DIMENSION(:,:) ::   u_ice2, v_ice1   ! ice u/v component on V/U point
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zf1   , zf2      ! arrays for internal stresses
-      
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zdd   , zdt      ! Divergence and tension at centre of grid cells
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zds              ! Shear on northeast corner of grid cells
-      REAL(wp), POINTER, DIMENSION(:,:) ::   deltat, deltac   ! Delta at centre and corners of grid cells
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zs1   , zs2      ! Diagonal stress tensor components zs1 and zs2 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zs12             ! Non-diagonal stress tensor component zs12
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zu_ice, zv_ice, zresr   ! Local error on velocity
-      
-      !!-------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj, zpresh, zfrld1, zmass1, zcorl1, za1ct , zpreshc, zfrld2, zmass2, zcorl2, za2ct )
-      CALL wrk_alloc( jpi,jpj, zc1   , u_oce1, u_oce2, u_ice2, zusw  , v_oce1 , v_oce2, v_ice1                )
-      CALL wrk_alloc( jpi,jpj, zf1   , deltat, zu_ice, zf2   , deltac, zv_ice , zdd   , zdt    , zds          )
-      CALL wrk_alloc( jpi,jpj, zdd   , zdt   , zds   , zs1   , zs2   , zs12   , zresr                         )
-
-#if  defined key_lim2 && ! defined key_lim2_vp
-# if defined key_agrif
-     USE ice_2, vt_s => hsnm
-     USE ice_2, vt_i => hicm
-# else
-     vt_s => hsnm
-     vt_i => hicm
-# endif
-     at_i(:,:) = 1. - frld(:,:)
-#endif
-      !
-      !------------------------------------------------------------------------------!
-      ! 1) Ice-Snow mass (zc1), ice strength (zpresh)                                !
-      !------------------------------------------------------------------------------!
-      !
-      ! Put every vector to 0
-      zpresh (:,:) = 0._wp   ;   zc1   (:,:) = 0._wp
-      zpreshc(:,:) = 0._wp
-      u_ice2 (:,:) = 0._wp   ;   v_ice1(:,:) = 0._wp
-      zdd    (:,:) = 0._wp   ;   zdt   (:,:) = 0._wp   ;   zds(:,:) = 0._wp
-
-#if defined key_lim3
-      CALL lim_itd_me_icestrength( ridge_scheme_swi )      ! LIM-3: Ice strength on T-points
-#endif
-
-!CDIR NOVERRCHK
-      DO jj = k_j1 , k_jpj       ! Ice mass and temp variables
-!CDIR NOVERRCHK
-         DO ji = 1 , jpi
-            zc1(ji,jj)    = tms(ji,jj) * ( rhosn * vt_s(ji,jj) + rhoic * vt_i(ji,jj) )
-#if defined key_lim3
-            zpresh(ji,jj) = tms(ji,jj) *  strength(ji,jj) * 0.5_wp
-#endif
-#if defined key_lim2
-            zpresh(ji,jj) = tms(ji,jj) *  pstar * vt_i(ji,jj) * EXP( -c_rhg * (1. - at_i(ji,jj) ) )
-#endif
-            ! tmi = 1 where there is ice or on land
-            tmi(ji,jj)    = 1._wp - ( 1._wp - MAX( 0._wp , SIGN ( 1._wp , vt_i(ji,jj) ) ) ) * 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_oce(ji,jj)
-            v_oce2(ji,jj)  = v_oce(ji,jj)
-
-            ! Ocean has no slip boundary condition
-            v_oce1(ji,jj)  = 0.5*( (v_oce(ji,jj)+v_oce(ji,jj-1))*e1t(ji,jj)    &
-               &                 +(v_oce(ji+1,jj)+v_oce(ji+1,jj-1))*e1t(ji+1,jj)) &
-               &               /(e1t(ji+1,jj)+e1t(ji,jj)) * tmu(ji,jj)  
-
-            u_oce2(ji,jj)  = 0.5*((u_oce(ji,jj)+u_oce(ji-1,jj))*e2t(ji,jj)     &
-               &                 +(u_oce(ji,jj+1)+u_oce(ji-1,jj+1))*e2t(ji,jj+1)) &
-               &                / (e2t(ji,jj+1)+e2t(ji,jj)) * tmv(ji,jj)
-
-            ! Wind stress at U,V-point
-            ztagnx = ( 1. - zfrld1(ji,jj) ) * utau_ice(ji,jj)
-            ztagny = ( 1. - zfrld2(ji,jj) ) * vtau_ice(ji,jj)
-
-            ! Computation of the velocity field taking into account the ice internal interaction.
-            ! Terms that are independent of the velocity field.
-
-            ! SB On utilise maintenant le gradient de la pente de l'ocean
-            ! include it later
-
-            zdsshx =  ( ssh_m(ji+1,jj) - ssh_m(ji,jj) ) / e1u(ji,jj)
-            zdsshy =  ( ssh_m(ji,jj+1) - ssh_m(ji,jj) ) / e2v(ji,jj)
-
-            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._wp * 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, jpim1   !RB bug no vect opt due to tmi
-
-               !  
-               !- 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. )      ! lateral boundary cond.
-
-!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 defined key_bdy
-!         ! clem: change u_ice and v_ice at the boundary for each iteration
-!         CALL bdy_ice_lim_dyn()
-!#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
-      !------------------------------------------------------------------------------!
-      !clem : add hminrhg in the namelist
-      !
-      ! If the ice thickness is below hminrhg (5cm) 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. hminrhg ) THEN
-               u_ice(ji,jj) = u_oce(ji,jj)
-               v_ice(ji,jj) = v_oce(ji,jj)
-            ENDIF ! zdummy
-         END DO
-      END DO
-
-      CALL lbc_lnk( u_ice(:,:), 'U', -1. ) 
-      CALL lbc_lnk( v_ice(:,:), 'V', -1. ) 
-
-      ! clem: change u_ice and v_ice at the boundary
-#if defined key_bdy
-      CALL bdy_ice_lim_dyn()
-#endif         
-
-      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. hminrhg ) 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, jpim1   !RB bug no vect opt due to tmi
-            !- 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. hminrhg ) 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)
-            ! begin TECLIM change 
-            ! shear_i(ji,jj) = zds   (ji,jj)
-            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) 
-            shear_i(ji,jj) = SQRT( zdt(ji,jj)*zdt(ji,jj) + zdst*zdst )
-            ! end TECLIM change
-         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. )
-      CALL lbc_lnk( shear_i(:,:), 'T', 1. )
-
-      ! * Store the stress tensor for the next time step
-      stress1_i (:,:) = zs1 (:,:)
-      stress2_i (:,:) = zs2 (:,:)
-      stress12_i(:,:) = zs12(:,:)
-
-      !
-      !------------------------------------------------------------------------------!
-      ! 6) Control prints of residual and charge ellipse
-      !------------------------------------------------------------------------------!
-      !
-      ! 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
-      !
-      CALL wrk_dealloc( jpi,jpj, zpresh, zfrld1, zmass1, zcorl1, za1ct , zpreshc, zfrld2, zmass2, zcorl2, za2ct )
-      CALL wrk_dealloc( jpi,jpj, zc1   , u_oce1, u_oce2, u_ice2, zusw  , v_oce1 , v_oce2, v_ice1                )
-      CALL wrk_dealloc( jpi,jpj, zf1   , deltat, zu_ice, zf2   , deltac, zv_ice , zdd   , zdt    , zds          )
-      CALL wrk_dealloc( jpi,jpj, zdd   , zdt   , zds   , zs1   , zs2   , zs12   , zresr                         )
-
-   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: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limrst.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limrst.F90	(revision 3937)
+++ 	(revision )
@@ -1,587 +1,0 @@
-MODULE limrst
-   !!======================================================================
-   !!                     ***  MODULE  limrst  ***
-   !! Ice restart :  write the ice restart file
-   !!======================================================================
-   !! History:   -   ! 2005-04 (M. Vancoppenolle) Original code
-   !!           3.0  ! 2008-03 (C. Ethe) restart files in using IOM interface
-   !!           4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#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 
-   !!----------------------------------------------------------------------
-   USE ice              ! sea-ice variables
-   USE par_ice          ! sea-ice parameters
-   USE dom_oce          ! ocean domain
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE sbc_ice          ! Surface boundary condition: ice fields
-   USE in_out_manager   ! I/O manager
-   USE iom              ! I/O library
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-
-   IMPLICIT NONE
-   PRIVATE
-
-   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 iceini.F90
-
-   LOGICAL, PUBLIC ::   lrst_ice         !: logical to control the ice restart write 
-   INTEGER, PUBLIC ::   numrir, numriw   !: logical unit for ice restart (read and write)
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limrst.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/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 define as a character
-      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
-      !!----------------------------------------------------------------------
-      !
-      IF( kt == nit000 )   lrst_ice = .FALSE.   ! default definition
-
-      ! in order to get better performances with NetCDF format, we open and define the ice restart file 
-      ! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice 
-      ! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1
-      IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nstock == nn_fsbc    &
-         &                             .OR. ( kt == nitend - nn_fsbc + 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))//"_"//TRIM(cn_icerst_out)
-         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*nn_fsbc + 1 ) THEN   
-               WRITE(numout,*)         '             kt = nitrst - 2*nn_fsbc + 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
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt     ! number of iteration
-      !!
-      INTEGER ::   ji, jj, jk ,jl   ! dummy loop indices
-      INTEGER ::   iter
-      CHARACTER(len=15) ::   znam
-      CHARACTER(len=1)  ::   zchar, zchar1
-      REAL(wp), POINTER, DIMENSION(:,:) :: z2d
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, z2d )
-
-      iter = kt + nn_fsbc - 1   ! ice restarts are written at kt == nitrst - nn_fsbc + 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, 'nn_fsbc', REAL( nn_fsbc, 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
-
-      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, 'fsbbq'     , fsbbq      )
-      CALL iom_rstput( iter, nitrst, numriw, 'iatte'     , iatte      ) ! clem modif
-      CALL iom_rstput( iter, nitrst, numriw, 'oatte'     , oatte      ) ! clem modif
-      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
-      !
-      CALL wrk_dealloc( jpi, jpj, z2d )
-      !
-   END SUBROUTINE lim_rst_write
-
-
-   SUBROUTINE lim_rst_read
-      !!----------------------------------------------------------------------
-      !!                    ***  lim_rst_read  ***
-      !!
-      !! ** purpose  :   read of sea-ice variable restart in a netcdf file
-      !!----------------------------------------------------------------------
-      INTEGER :: ji, jj, jk, jl, indx
-      REAL(wp) ::   zfice, ziter
-      REAL(wp) ::   zs_inf, z_slope_s, zsmax, zsmin, zalpha, zindb   ! local scalars used for the salinity profile
-      REAL(wp), POINTER, DIMENSION(:)  ::   zs_zero 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   z2d
-      CHARACTER(len=15) ::   znam
-      CHARACTER(len=1)  ::   zchar, zchar1
-      INTEGER           ::   jlibalt = jprstlib
-      LOGICAL           ::   llok
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( nlay_i, zs_zero )
-      CALL wrk_alloc( jpi, jpj, z2d )
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_rst_read : read ice NetCDF restart file'
-         WRITE(numout,*) '~~~~~~~~~~~~~'
-      ENDIF
-
-      IF ( jprstlib == jprstdimg ) THEN
-        ! eventually read netcdf file (monobloc)  for restarting on different number of processors
-        ! if {cn_icerst_in}.nc exists, then set jlibalt to jpnf90
-        INQUIRE( FILE = TRIM(cn_icerst_in)//'.nc', EXIST = llok )
-        IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
-      ENDIF
-
-      CALL iom_open ( cn_icerst_in, numrir, kiolib = jprstlib )
-
-      CALL iom_get( numrir, 'nn_fsbc', zfice )
-      CALL iom_get( numrir, 'kt_ice' , ziter )    
-      IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
-      IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
-
-      !Control of date
-
-      IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
-         &     CALL ctl_stop( '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( NINT(zfice) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
-         &     CALL ctl_stop( 'lim_rst_read ===>>>> : problem with nn_fsbc in ice restart',  &
-         &                   '   verify the file or rerun with the value 0 for the',         &
-         &                   '   control of time parameter  nrstdt' )
-
-      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
-
-      DO jl = 1, jpl 
-         CALL lbc_lnk( smv_i(:,:,jl) , 'T' ,  1. )
-         CALL lbc_lnk( v_i  (:,:,jl) , 'T' ,  1. )
-         CALL lbc_lnk( a_i  (:,:,jl) , 'T' ,  1. )
-      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
-
-      IF( num_sal == 2 ) THEN      ! Salinity profile
-         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._wp * sm_i(ji,jj,jl) / MAX( 0.01_wp , ht_i(ji,jj,jl) )
-                     !- slope of the salinity profile
-                     zs_zero(jk)   = z_slope_s * ( REAL(jk,wp) - 0.5_wp ) * ht_i(ji,jj,jl) / REAL(nlay_i,wp)
-                     zsmax = 4.5_wp
-                     zsmin = 3.5_wp
-                     IF( sm_i(ji,jj,jl) .LT. zsmin ) THEN
-                        zalpha = 1._wp
-                     ELSEIF( sm_i(ji,jj,jl) .LT.zsmax ) THEN
-                        zalpha = sm_i(ji,jj,jl) / ( zsmin - zsmax ) + zsmax / ( zsmax - zsmin )
-                     ELSE
-                        zalpha = 0._wp
-                     ENDIF
-                     s_i(ji,jj,jk,jl) = zalpha * zs_zero(jk) + ( 1._wp - zalpha ) * zs_inf
-                  END DO
-               END DO
-            END DO
-         END DO
-      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, 'fsbbq'     , fsbbq      )
-      CALL iom_get( numrir, jpdom_autoglo, 'iatte'     , iatte      ) ! clem modif
-      CALL iom_get( numrir, jpdom_autoglo, 'oatte'     , oatte      ) ! clem modif
-      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
-      !
-      !clem CALL iom_close( numrir )
-      !
-      CALL wrk_dealloc( nlay_i, zs_zero )
-      CALL wrk_dealloc( jpi, jpj, z2d )
-      !
-   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: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limsbc.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limsbc.F90	(revision 3937)
+++ 	(revision )
@@ -1,434 +1,0 @@
-MODULE limsbc
-   !!======================================================================
-   !!                       ***  MODULE limsbc   ***
-   !!           computation of the flux at the sea ice/ocean interface
-   !!======================================================================
-   !! History :   -   ! 2006-07 (M. Vancoppelle)  LIM3 original code
-   !!            3.0  ! 2008-03 (C. Tallandier)  surface module
-   !!             -   ! 2008-04 (C. Tallandier)  split in 2 + new ice-ocean coupling
-   !!            3.3  ! 2010-05 (G. Madec) decrease ocean & ice reference salinities in the Baltic sea
-   !!                 !                  + simplification of the ice-ocean stress calculation
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2012    (D. Iovino) salt flux change
-   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                    LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_sbc_alloc : allocate the limsbc arrays
-   !!   lim_sbc_init  : initialisation
-   !!   lim_sbc_flx   : updates mass, heat and salt fluxes at the ocean surface
-   !!   lim_sbc_tau   : update i- and j-stresses, and its modulus at the ocean surface
-   !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE par_ice          ! ice parameters
-   USE dom_oce          ! ocean domain
-   USE sbc_ice          ! Surface boundary condition: sea-ice fields
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE phycst           ! physical constants
-   USE albedo           ! albedo parameters
-   USE ice              ! LIM sea-ice variables
-   USE lbclnk           ! ocean lateral boundary condition
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE prtctl           ! Print control
-   USE cpl_oasis3, ONLY : lk_cpl
-   USE traqsr           ! clem: add penetration of solar flux into the calculation of heat budget
-   USE lib_fortran      ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_sbc_init   ! called by ice_init
-   PUBLIC   lim_sbc_flx    ! called by sbc_ice_lim
-   PUBLIC   lim_sbc_tau    ! called by sbc_ice_lim
-
-   REAL(wp)  ::   r1_rdtice            ! = 1. / rdt_ice 
-   REAL(wp)  ::   epsi16 = 1.e-16_wp   ! constant values
-   REAL(wp)  ::   epsi20 = 1.e-20_wp   ! constant values
-   REAL(wp)  ::   rzero  = 0._wp    
-   REAL(wp)  ::   rone   = 1._wp
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   utau_oce, vtau_oce   ! air-ocean surface i- & j-stress     [N/m2]
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmod_io              ! modulus of the ice-ocean velocity   [m/s]
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   soce_0  , sice_0     ! cst SSS and ice salinity (levitating sea-ice) 
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limsbc.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION lim_sbc_alloc()
-      !!-------------------------------------------------------------------
-      !!             ***  ROUTINE lim_sbc_alloc ***
-      !!-------------------------------------------------------------------
-      ALLOCATE( soce_0(jpi,jpj) , utau_oce(jpi,jpj) ,                       &
-         &      sice_0(jpi,jpj) , vtau_oce(jpi,jpj) , tmod_io(jpi,jpj), STAT=lim_sbc_alloc)
-         !
-      IF( lk_mpp             )   CALL mpp_sum( lim_sbc_alloc )
-      IF( lim_sbc_alloc /= 0 )   CALL ctl_warn('lim_sbc_alloc: failed to allocate arrays')
-   END FUNCTION lim_sbc_alloc
-
-
-   SUBROUTINE lim_sbc_flx( kt )
-      !!-------------------------------------------------------------------
-      !!                ***  ROUTINE lim_sbc_flx ***
-      !!  
-      !! ** Purpose :   Update the surface ocean boundary condition for heat 
-      !!              salt and mass over areas where sea-ice is non-zero
-      !!         
-      !! ** Action  : - computes the heat and freshwater/salt fluxes
-      !!              at the ice-ocean interface.
-      !!              - Update the ocean sbc
-      !!     
-      !! ** Outputs : - qsr     : sea heat flux:     solar 
-      !!              - qns     : sea heat flux: non solar
-      !!              - emp     : freshwater budget: volume flux 
-      !!              - emps    : freshwater budget: concentration/dillution 
-      !!              - fr_i    : ice fraction
-      !!              - tn_ice  : sea-ice surface temperature
-      !!              - alb_ice : sea-ice alberdo (lk_cpl=T)
-      !!
-      !! References : Goosse, H. et al. 1996, Bul. Soc. Roy. Sc. Liege, 65, 87-90.
-      !!              Tartinville et al. 2001 Ocean Modelling, 3, 95-108.
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt    ! number of iteration
-      !
-      INTEGER  ::   ji, jj           ! dummy loop indices
-      INTEGER  ::   ierr             ! local integer
-      INTEGER  ::   ifvt, i1mfr, idfr               ! some switches
-      INTEGER  ::   iflt, ial, iadv, ifral, ifrdv
-      REAL(wp) ::   zinda, zindb, zfons, zpme              ! local scalars
-      REAL(wp) ::   zfmm             ! IOVINO freezing minus melting (F-M) 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zfcm1 , zfcm2    ! solar/non solar heat fluxes
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zalb, zalbp   ! 2D/3D workspace
-      !!---------------------------------------------------------------------
-      
-      CALL wrk_alloc( jpi, jpj, zfcm1 , zfcm2 )
-      IF( lk_cpl )   CALL wrk_alloc( jpi, jpj, jpl, zalb, zalbp )
-
-      !------------------------------------------!
-      !      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) ) ) )
-            zindb   = 1.0 - MAX( rzero , SIGN( rone , - iatte(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(ji,jj)  + &
-                 &           zindb * ( 1. - pfrld(ji,jj) ) * fstric(ji,jj) / MAX( iatte(ji,jj), epsi20 )
-            ! fstric     Solar flux transmitted trough the ice
-            ! qsr        Net short wave heat flux on free ocean
-            ! new line
-            fscmbq(ji,jj) = zindb * ( 1.0 - pfrld(ji,jj) ) * fstric(ji,jj) / MAX( iatte(ji,jj), epsi20 )
-
-            !  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) ) * r1_rdtice   &
-               &           + ifrdv   * ( qfvbq(ji,jj) + qdtcn(ji,jj) )                   * r1_rdtice   &
-               &           + 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 == 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
-            qsr(ji,jj) = zfcm1(ji,jj)                                       ! solar heat flux 
-            qns(ji,jj) = zfcm2(ji,jj) - fdtcn(ji,jj)                        ! non solar heat flux
-            !                           ! fdtcn : turbulent oceanic heat flux
-
-            !!gm   this IF prevents the vertorisation of the whole loop
-          !  IF ( ( ji == jiindx ) .AND. ( jj == jjindx) ) THEN
-          !     WRITE(numout,*) 'lim_sbc : heat fluxes '
-          !     WRITE(numout,*) ' at_i      : ', at_i(jiindx,jjindx)
-          !     WRITE(numout,*) ' ht_i      : ', SUM( ht_i(jiindx,jjindx,1:jpl) )
-          !     WRITE(numout,*) ' ht_s      : ', SUM( ht_s(jiindx,jjindx,1:jpl) )
-          !     WRITE(numout,*)
-          !     WRITE(numout,*) ' qsr       : ', qsr(jiindx,jjindx)
-          !     WRITE(numout,*) ' zfcm1     : ', zfcm1(jiindx,jjindx)
-          !     WRITE(numout,*) ' pfrld     : ', pfrld(jiindx,jjindx)
-          !     WRITE(numout,*) ' fstric    : ', fstric (jiindx,jjindx)
-          !     WRITE(numout,*)
-          !     WRITE(numout,*) ' qns       : ', qns(jiindx,jjindx)
-          !     WRITE(numout,*) ' zfcm2     : ', zfcm2(jiindx,jjindx)
-          !     WRITE(numout,*) ' zfcm1     : ', zfcm1(jiindx,jjindx)
-          !     WRITE(numout,*) ' ifral     : ', ifral
-          !     WRITE(numout,*) ' ial       : ', ial  
-          !     WRITE(numout,*) ' qcmif     : ', qcmif(jiindx,jjindx)
-          !     WRITE(numout,*) ' qldif     : ', qldif(jiindx,jjindx)
-          !     !WRITE(numout,*) ' qcmif / dt: ', qcmif(jiindx,jjindx) * r1_rdtice
-          !     !WRITE(numout,*) ' qldif / dt: ', qldif(jiindx,jjindx) * r1_rdtice
-          !     WRITE(numout,*) ' ifrdv     : ', ifrdv
-          !     WRITE(numout,*) ' qfvbq     : ', qfvbq(jiindx,jjindx)
-          !     WRITE(numout,*) ' qdtcn     : ', qdtcn(jiindx,jjindx)
-          !     !WRITE(numout,*) ' qfvbq / dt: ', qfvbq(jiindx,jjindx) * r1_rdtice
-          !     !WRITE(numout,*) ' qdtcn / dt: ', qdtcn(jiindx,jjindx) * r1_rdtice
-          !     WRITE(numout,*) ' '
-          !     WRITE(numout,*) ' fdtcn     : ', fdtcn(jiindx,jjindx)
-          !     WRITE(numout,*) ' fhmec     : ', fhmec(jiindx,jjindx)
-          !     WRITE(numout,*) ' fheat_rpo : ', fheat_rpo(jiindx,jjindx)
-          !     WRITE(numout,*) ' fhbri     : ', fhbri(jiindx,jjindx)
-          !     WRITE(numout,*) ' fheat_res : ', fheat_res(jiindx,jjindx)
-          !  ENDIF
-            !!gm   end
-         END DO
-      END DO
-
-      !------------------------------------------!
-      !      mass flux at the ocean surface      !
-      !------------------------------------------!
-
-!!gm   optimisation: this loop have to be merged with the previous one
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            !  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 = - emp(ji,jj)     * ( 1.0 - at_i(ji,jj)          )  &   ! evaporation over oceanic fraction
-               &   + tprecip(ji,jj) *         at_i(ji,jj)             &   ! all precipitation reach the ocean
-               &   - sprecip(ji,jj) * ( 1. - (pfrld(ji,jj)**betas) )  &   ! except solid precip intercepted by sea-ice
-               &   - rdmsnif(ji,jj) * r1_rdtice                       &   ! freshwaterflux due to snow melting 
-               &   + fmmec(ji,jj)                                         ! snow falling when ridging
-
-
-            !  computing salt exchanges at the ice/ocean interface
-            !  sice should be the same as computed with the ice model
-            !zfons =  ( soce_0(ji,jj) - sice_0(ji,jj) ) * rdmicif(ji,jj) * r1_rdtice 
-            ! SOCE
-            !zfons =  ( sss_m (ji,jj) - sice_0(ji,jj) ) * rdmicif(ji,jj) * r1_rdtice
-            zfmm = rdmicif(ji,jj) * r1_rdtice  ! IOVINO  
-            !CT useless            !  salt flux for constant salinity
-            !CT useless            fsalt(ji,jj)      =  zfons / ( sss_m(ji,jj) + epsi16 ) + fsalt_res(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_m(ji,jj) + epsi16 )
-            ! fseqv(ji,jj)      =  fseqv(ji,jj)     / ( sss_m(ji,jj) + epsi16 )
-            ! fsbri(ji,jj)      =  fsbri(ji,jj)     / ( sss_m(ji,jj) + epsi16 )
-            ! fsalt_rpo(ji,jj)  =  fsalt_rpo(ji,jj) / ( sss_m(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]
-
-            emp(ji,jj) =  - zpme + zfmm ! volume flux IOVINO  
-            ! emp(ji,jj) = - zpme 
-         END DO
-      END DO
-
-      IF( num_sal == 2 ) THEN      ! variable ice salinity: brine drainage included in the salt flux
-         emps(:,:) =   fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ! + emp(:,:) ! IOVINO
-      ELSE                         ! constant ice salinity:
-         emps(:,:) =   fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ! + emp(:,:)              ! IOVINO
-      ENDIF
-
-
-      !-----------------------------------------------!
-      !   Storing the transmitted variables           !
-      !-----------------------------------------------!
-      fr_i  (:,:)   = at_i(:,:)             ! Sea-ice fraction            
-      tn_ice(:,:,:) = t_su(:,:,:)           ! Ice surface temperature                      
-
-      !------------------------------------------------!
-      !    Computation of snow/ice and ocean albedo    !
-      !------------------------------------------------!
-      IF( lk_cpl ) THEN          ! coupled case
-         CALL albedo_ice( t_su, ht_i, ht_s, zalbp, zalb )                  ! snow/ice albedo
-         !
-         alb_ice(:,:,:) =  0.5_wp * zalbp(:,:,:) + 0.5_wp * zalb (:,:,:)   ! Ice albedo (mean clear and overcast skys)
-      ENDIF
-
-      IF(ln_ctl) THEN
-         CALL prt_ctl( tab2d_1=qsr   , clinfo1=' lim_sbc: qsr    : ', tab2d_2=qns , clinfo2=' qns     : ' )
-         CALL prt_ctl( tab2d_1=emp   , clinfo1=' lim_sbc: emp    : ', tab2d_2=emps, clinfo2=' emps    : ' )
-         CALL prt_ctl( tab2d_1=fr_i  , clinfo1=' lim_sbc: fr_i   : ' )
-         CALL prt_ctl( tab3d_1=tn_ice, clinfo1=' lim_sbc: tn_ice : ', kdim=jpl )
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, zfcm1 , zfcm2 )
-      IF( lk_cpl )   CALL wrk_dealloc( jpi, jpj, jpl, zalb, zalbp )
-      ! 
-   END SUBROUTINE lim_sbc_flx
-
-
-   SUBROUTINE lim_sbc_tau( kt , pu_oce, pv_oce )
-      !!-------------------------------------------------------------------
-      !!                ***  ROUTINE lim_sbc_tau ***
-      !!  
-      !! ** Purpose : Update the ocean surface stresses due to the ice
-      !!         
-      !! ** Action  : * at each ice time step (every nn_fsbc time step):
-      !!                - compute the modulus of ice-ocean relative velocity 
-      !!                  (*rho*Cd) at T-point (C-grid) or I-point (B-grid)
-      !!                      tmod_io = rhoco * | U_ice-U_oce |
-      !!                - update the modulus of stress at ocean surface
-      !!                      taum = frld * taum + (1-frld) * tmod_io * | U_ice-U_oce |
-      !!              * at each ocean time step (every kt): 
-      !!                  compute linearized ice-ocean stresses as
-      !!                      Utau = tmod_io * | U_ice - pU_oce |
-      !!                using instantaneous current ocean velocity (usually before)
-      !!
-      !!    NB: - ice-ocean rotation angle no more allowed
-      !!        - here we make an approximation: taum is only computed every ice time step
-      !!          This avoids mutiple average to pass from T -> U,V grids and next from U,V grids 
-      !!          to T grid. taum is used in TKE and GLS, which should not be too sensitive to this approximaton...
-      !!
-      !! ** Outputs : - utau, vtau   : surface ocean i- and j-stress (u- & v-pts) updated with ice-ocean fluxes
-      !!              - taum         : modulus of the surface ocean stress (T-point) updated with ice-ocean fluxes
-      !!---------------------------------------------------------------------
-      INTEGER ,                     INTENT(in) ::   kt               ! ocean time-step index
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pu_oce, pv_oce   ! surface ocean currents
-      !!
-      INTEGER  ::   ji, jj   ! dummy loop indices
-      REAL(wp) ::   zat_u, zutau_ice, zu_t, zmodt   ! local scalar
-      REAL(wp) ::   zat_v, zvtau_ice, zv_t          !   -      -
-      !!---------------------------------------------------------------------
-      !
-      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN     !==  Ice time-step only  ==!   (i.e. surface module time-step)
-!CDIR NOVERRCHK
-         DO jj = 2, jpjm1                             !* update the modulus of stress at ocean surface (T-point)
-!CDIR NOVERRCHK
-            DO ji = fs_2, fs_jpim1
-               !                                               ! 2*(U_ice-U_oce) at T-point
-               zu_t = u_ice(ji,jj) + u_ice(ji-1,jj) - u_oce(ji,jj) - u_oce(ji-1,jj)   
-               zv_t = v_ice(ji,jj) + v_ice(ji,jj-1) - v_oce(ji,jj) - v_oce(ji,jj-1) 
-               !                                              ! |U_ice-U_oce|^2
-               zmodt =  0.25_wp * (  zu_t * zu_t + zv_t * zv_t  )
-               !                                               ! update the ocean stress modulus
-               taum(ji,jj) = ( 1._wp - at_i(ji,jj) ) * taum(ji,jj) + at_i(ji,jj) * rhoco * zmodt
-               tmod_io(ji,jj) = rhoco * SQRT( zmodt )          ! rhoco * |U_ice-U_oce| at T-point
-            END DO
-         END DO
-         CALL lbc_lnk( taum, 'T', 1. )   ;   CALL lbc_lnk( tmod_io, 'T', 1. )
-         !
-         utau_oce(:,:) = utau(:,:)                    !* save the air-ocean stresses at ice time-step
-         vtau_oce(:,:) = vtau(:,:)
-         !
-      ENDIF
-      !
-      !                                      !==  every ocean time-step  ==!
-      !
-      DO jj = 2, jpjm1                                !* update the stress WITHOUT a ice-ocean rotation angle
-         DO ji = fs_2, fs_jpim1   ! Vect. Opt.
-            zat_u  = ( at_i(ji,jj) + at_i(ji+1,jj) ) * 0.5_wp   ! ice area at u and V-points
-            zat_v  = ( at_i(ji,jj) + at_i(ji,jj+1) ) * 0.5_wp
-            !                                                   ! linearized quadratic drag formulation
-            zutau_ice   = 0.5_wp * ( tmod_io(ji,jj) + tmod_io(ji+1,jj) ) * ( u_ice(ji,jj) - pu_oce(ji,jj) )
-            zvtau_ice   = 0.5_wp * ( tmod_io(ji,jj) + tmod_io(ji,jj+1) ) * ( v_ice(ji,jj) - pv_oce(ji,jj) )
-            !                                                   ! stresses at the ocean surface
-            utau(ji,jj) = ( 1._wp - zat_u ) * utau_oce(ji,jj) + zat_u * zutau_ice
-            vtau(ji,jj) = ( 1._wp - zat_v ) * vtau_oce(ji,jj) + zat_v * zvtau_ice
-         END DO
-      END DO
-      CALL lbc_lnk( utau, 'U', -1. )   ;   CALL lbc_lnk( vtau, 'V', -1. )   ! lateral boundary condition
-      !
-      IF(ln_ctl)   CALL prt_ctl( tab2d_1=utau, clinfo1=' lim_sbc: utau   : ', mask1=umask,   &
-         &                       tab2d_2=vtau, clinfo2=' vtau    : '        , mask2=vmask )
-      !  
-   END SUBROUTINE lim_sbc_tau
-
-
-   SUBROUTINE lim_sbc_init
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_sbc_init  ***
-      !!             
-      !! ** Purpose : Preparation of the file ice_evolu for the output of
-      !!      the temporal evolution of key variables
-      !!
-      !! ** input   : Namelist namicedia
-      !!-------------------------------------------------------------------
-      !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'lim_sbc_init : LIM-3 sea-ice - surface boundary condition'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~   '
-
-      !                                      ! allocate lim_sbc array
-      IF( lim_sbc_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'lim_sbc_init : unable to allocate standard arrays' )
-      !
-      r1_rdtice = 1. / rdt_ice
-      !
-      soce_0(:,:) = soce                     ! constant SSS and ice salinity used in levitating sea-ice case
-      sice_0(:,:) = sice
-      !
-      IF( cp_cfg == "orca" ) THEN            ! decrease ocean & ice reference salinities in the Baltic sea 
-         WHERE( 14._wp <= glamt(:,:) .AND. glamt(:,:) <= 32._wp .AND.   &
-            &   54._wp <= gphit(:,:) .AND. gphit(:,:) <= 66._wp         ) 
-            soce_0(:,:) = 4._wp
-            sice_0(:,:) = 2._wp
-         END WHERE
-      ENDIF
-      ! clem modif
-      iatte(:,:) = 1._wp
-      oatte(:,:) = 1._wp
-      !
-   END SUBROUTINE lim_sbc_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :        Dummy module       NO LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_sbc           ! Dummy routine
-   END SUBROUTINE lim_sbc
-#endif 
-
-   !!======================================================================
-END MODULE limsbc
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limthd.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limthd.F90	(revision 3937)
+++ 	(revision )
@@ -1,888 +1,0 @@
-MODULE limthd
-   !!======================================================================
-   !!                  ***  MODULE limthd   ***
-   !!  LIM-3 :   ice thermodynamic
-   !!======================================================================
-   !! History :  LIM  ! 2000-01 (M.A. Morales Maqueda, H. Goosse, T. Fichefet) LIM-1
-   !!            2.0  ! 2002-07 (C. Ethe, G. Madec)  LIM-2 (F90 rewriting)
-   !!            3.0  ! 2005-11 (M. Vancoppenolle)  LIM-3 : Multi-layer thermodynamics + salinity variations
-   !!             -   ! 2007-04 (M. Vancoppenolle) add lim_thd_glohec, lim_thd_con_dh and lim_thd_con_dif
-   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in rdmsnif
-   !!            3.3  ! 2010-11 (G. Madec) corrected snow melting heat (due to factor betas)
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd        : thermodynamic of sea ice
-   !!   lim_thd_init   : initialisation of sea-ice thermodynamic
-   !!----------------------------------------------------------------------
-   USE phycst          ! physical constants
-   USE dom_oce         ! ocean space and time domain variables
-   USE ice             ! LIM: sea-ice variables
-   USE par_ice         ! LIM: sea-ice parameters
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice fields
-   USE thd_ice         ! LIM thermodynamic sea-ice variables
-   USE dom_ice         ! LIM sea-ice domain
-   USE domvvl          ! domain: variable volume level
-   USE limthd_dif      ! LIM: thermodynamics, vertical diffusion
-   USE limthd_dh       ! LIM: thermodynamics, ice and snow thickness variation
-   USE limthd_sal      ! LIM: thermodynamics, ice salinity
-   USE limthd_ent      ! LIM: thermodynamics, ice enthalpy redistribution
-   USE limtab          ! LIM: 1D <==> 2D transformation
-   USE limvar          ! LIM: sea-ice variables
-   USE lbclnk          ! lateral boundary condition - MPP links
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! work arrays
-   USE in_out_manager  ! I/O manager
-   USE prtctl          ! Print control
-   USE lib_fortran      ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd        ! called by limstp module
-   PUBLIC   lim_thd_init   ! called by iceini module
-
-   REAL(wp) ::   epsi20 = 1e-20_wp   ! constant values
-   REAL(wp) ::   epsi16 = 1e-16_wp   !
-   REAL(wp) ::   epsi10 = 1e-10_wp   !
-   REAL(wp) ::   epsi06 = 1e-06_wp   !
-   REAL(wp) ::   epsi04 = 1e-04_wp   !
-   REAL(wp) ::   zzero  = 0._wp      !
-   REAL(wp) ::   zone   = 1._wp      !
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 3.3 , UCL - NEMO Consortium (2010)
-   !! $Id: limthd.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd( kt )
-      !!-------------------------------------------------------------------
-      !!                ***  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
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt    ! number of iteration
-      !!
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      INTEGER  ::   nbpb             ! nb of icy pts for thermo. cal.
-      REAL(wp) ::   zfric_umin = 5e-03_wp    ! lower bound for the friction velocity
-      REAL(wp) ::   zfric_umax = 2e-02_wp    ! upper bound for the friction velocity
-      REAL(wp) ::   zinda, zindb, zthsnice, zfric_u     ! local scalar
-      REAL(wp) ::   zfntlat, zpareff, zareamin, zcoef   !    -         -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zqlbsbq   ! link with lead energy budget qldif
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-      !!-------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zqlbsbq )
-   
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
-      !------------------------------------------------------------------------------!
-      ! 1) Initialization of diagnostic variables                                    !
-      !------------------------------------------------------------------------------!
-
-      !--------------------
-      ! 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 ) ) * REAL( 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
-         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 ) ) * REAL( 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
-      !-----------------------------
-      !clem rdvosif(:,:) = 0.e0   ! variation of ice volume at surface
-      !clem rdvobif(:,:) = 0.e0   ! variation of ice volume at bottom
-      !clem fdvolif(:,:) = 0.e0   ! total variation of ice volume
-      !clem rdvonif(:,:) = 0.e0   ! lateral variation of ice volume
-      !clem fstric (:,:) = 0.e0   ! part of solar radiation transmitted through the ice
-      !clem ffltbif(:,:) = 0.e0   ! linked with fstric
-      !clem qfvbq  (:,:) = 0.e0   ! linked with fstric
-      !clem rdmsnif(:,:) = 0.e0   ! variation of snow mass per unit area
-      !clem rdmicif(:,:) = 0.e0   ! variation of ice mass per unit area
-      !clem hicifp (:,:) = 0.e0   ! daily thermodynamic ice production. 
-      !clem fsbri  (:,:) = 0.e0   ! brine flux contribution to salt flux to the ocean
-      !clem fhbri  (:,:) = 0.e0   ! brine flux contribution to heat flux to the ocean
-      !clem 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
-            !clem zthsnice       = SUM( ht_s(ji,jj,1:jpl) ) + SUM( ht_i(ji,jj,1:jpl) )
-            !clem zindb          = tms(ji,jj) * ( 1.0 - MAX( zzero , SIGN( zone , - zthsnice + epsi20 ) ) ) 
-            phicif(ji,jj)  = vt_i(ji,jj)
-            pfrld(ji,jj)   = 1.0 - at_i(ji,jj)
-            zinda          = tms(ji,jj) * (1.0 - MAX( zzero , SIGN( zone , - at_i(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)  = zinda * rau0 * rcp * 0.006  * zfric_u * ( (sst_m(ji,jj) + rt0) - t_bo(ji,jj) ) 
-            ! also category dependent
-            !           !-- Energy from the turbulent oceanic heat flux heat flux coming in the lead 
-            qdtcn(ji,jj)  = zinda * fdtcn(ji,jj) * (1.0 - at_i(ji,jj)) * rdt_ice
-            !                       
-            !           !-- Lead heat budget, qldif (part 1, next one is in limthd_dh) 
-            !           !   caution: exponent betas used as more snow can fallinto leads
-            qldif(ji,jj) =  tms(ji,jj) * rdt_ice  * (                             &
-               &   pfrld(ji,jj)        * (  qsr(ji,jj) * oatte(ji,jj)             &   ! solar heat + clem modif
-               &                            + qns(ji,jj)                          &   ! non solar heat
-               &                            + fdtcn(ji,jj)                        &   ! turbulent ice-ocean heat
-               &                            + fsbbq(ji,jj) * ( 1.0 - zinda )  )   &   ! residual heat from previous step
-               & - pfrld(ji,jj)**betas * sprecip(ji,jj) * lfus                    )   ! latent heat of sprecip melting
-            !
-            ! Positive heat budget is used for bottom ablation
-            zfntlat        = 1.0 - MAX( zzero , SIGN( zone ,  - qldif(ji,jj) ) )
-            != 1 if positive heat budget
-            zpareff        = 1.0 - zinda * zfntlat
-            != 0 if ice and positive heat budget and 1 if one of those two is false
-            zqlbsbq(ji,jj) = qldif(ji,jj) * ( 1.0 - zpareff ) / 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_m(ji,jj) + rt0) ) !!clem * ( 1. - zinda )
-            !
-            ! oceanic heat flux (limthd_dh)
-            fbif   (ji,jj) = zinda * (  fsbbq(ji,jj) / MAX( at_i(ji,jj) , epsi20 ) + fdtcn(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
-
-         IF( kt == nit000 .AND. lwp ) THEN
-            WRITE(numout,*) ' lim_thd : transfer to 1D vectors. Category no : ', jl 
-            WRITE(numout,*) ' ~~~~~~~~'
-         ENDIF
-
-         zareamin = 1.e-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.jiindx).AND.(jj.eq.jjindx) ) THEN
-                  jiindex_1d = nbpb
-               ENDIF
-            END DO
-         END DO
-
-         !------------------------------------------------------------------------------!
-         ! 4) Thermodynamic computation
-         !------------------------------------------------------------------------------!
-
-         IF( lk_mpp )   CALL mpp_ini_ice( nbpb , numout )
-
-         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), qns_ice(:,:,jl) , jpi, jpj, npb(1:nbpb) )
-
-#if ! defined key_coupled
-            CALL tab_2d_1d( nbpb, qla_ice_1d (1:nbpb), qla_ice(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, dqla_ice_1d(1:nbpb), dqla_ice(:,:,jl)   , jpi, jpj, npb(1:nbpb) )
-#endif
-
-            CALL tab_2d_1d( nbpb, 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, rdmsnif_1d (1:nbpb), rdmsnif    , 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) )
-            CALL tab_2d_1d( nbpb, iatte_1d   (1:nbpb), iatte(:,:) , jpi, jpj, npb(1:nbpb) ) ! clem modif
-            CALL tab_2d_1d( nbpb, oatte_1d   (1:nbpb), oatte(:,:) , jpi, jpj, npb(1:nbpb) ) ! clem modif
-            !--------------------------------
-            ! 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 )       ! 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, rdmsnif, npb, rdmsnif_1d(1:nbpb), jpi, jpj )
-            CALL tab_1d_2d( nbpb, dmgwi  , npb, dmgwi_1d  (1:nbpb), jpi, jpj )
-            CALL tab_1d_2d( nbpb, rdvosif, npb, dvsbq_1d  (1:nbpb), jpi, jpj )
-            CALL tab_1d_2d( nbpb, rdvobif, npb, dvbbq_1d  (1:nbpb), jpi, jpj )
-            CALL tab_1d_2d( nbpb, fdvolif, npb, dvlbq_1d  (1:nbpb), jpi, jpj )
-            CALL tab_1d_2d( nbpb, rdvonif, npb, dvnbq_1d  (1:nbpb), jpi, jpj ) 
-            CALL tab_1d_2d( nbpb, fseqv  , npb, fseqv_1d  (1:nbpb), jpi, jpj )
-            !
-            IF( num_sal == 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 dummy version
-            CALL tab_1d_2d( nbpb, dh_i_surf2D, npb, dh_i_surf(1:nbpb)      , jpi, jpj )
-            CALL tab_1d_2d( nbpb, dh_i_bott2D, npb, dh_i_bott(1:nbpb)      , jpi, jpj )
-            CALL tab_1d_2d( nbpb, fsup2D     , npb, fsup     (1:nbpb)      , jpi, jpj )
-            CALL tab_1d_2d( nbpb, focea2D    , npb, focea    (1:nbpb)      , jpi, jpj )
-            CALL tab_1d_2d( nbpb, s_i_newice , npb, s_i_new  (1:nbpb)      , jpi, jpj )
-            CALL tab_1d_2d( nbpb, izero(:,:,jl) , npb, i0    (1:nbpb)      , jpi, jpj )
-            CALL tab_1d_2d( nbpb, qns_ice(:,:,jl), npb, qnsr_ice_1d(1:nbpb), jpi, jpj)
-            !+++++
-            !
-            IF( lk_mpp )   CALL mpp_comm_free( ncomm_ice ) !RB necessary ??
-         ENDIF
-         !
-      END DO
-
-      !------------------------------------------------------------------------------!
-      ! 5) Global variables, diagnostics
-      !------------------------------------------------------------------------------!
-
-      !------------------------
-      ! 5.1) Ice heat content              
-      !------------------------
-      ! Enthalpies are global variables we have to readjust the units
-      zcoef = 1._wp / ( unit_fac * REAL( nlay_i ) )
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            ! Multiply by volume, divide by nlayers so that heat content in 10^9 Joules
-            e_i(:,:,jk,jl) = e_i(:,:,jk,jl) * area(:,:) * a_i(:,:,jl) * ht_i(:,:,jl) * zcoef
-         END DO
-      END DO
-
-      !------------------------
-      ! 5.2) Snow heat content              
-      !------------------------
-      ! Enthalpies are global variables we have to readjust the units
-      zcoef = 1._wp / ( unit_fac * REAL( nlay_s ) )
-      DO jl = 1, jpl
-         DO jk = 1, nlay_s
-            ! Multiply by volume, so that heat content in 10^9 Joules
-            e_s(:,:,jk,jl) = e_s(:,:,jk,jl) * area(:,:) * a_i(:,:,jl) * ht_s(:,:,jl) * zcoef
-         END DO
-      END DO
-
-      !----------------------------------
-      ! 5.3) Change thickness to volume
-      !----------------------------------
-      CALL lim_var_eqv2glo
-
-      !--------------------------------------------
-      ! 5.4) Diagnostic thermodynamic growth rates
-      !--------------------------------------------
-!clem@useless      d_v_i_thd(:,:,:) = v_i      (:,:,:) - old_v_i(:,:,:)    ! ice volumes 
-!clem@mv-to-itd    dv_dt_thd(:,:,:) = d_v_i_thd(:,:,:) / 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
-      !
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
-
-         IF(lwp) THEN
-            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limthd) = ',(zchk_v_i * 86400.)
-            IF (    ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limthd) = ',(zchk_smv * 86400.)
-            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limthd) = ',(MINVAL(v_i) * 1.e-3)
-            IF ( MAXVAL( SUM(a_i(:,:,:),dim=3) ) >  amax+epsi10 ) WRITE(numout,*) 'violation a_i>amax    (limthd) = ',MAXVAL(SUM(a_i,dim=3))
-         ENDIF
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-      !
-      CALL wrk_dealloc( jpi, jpj, zqlbsbq )
-      !
-   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
-      !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                         ::   kideb, kiut   ! bounds for the spatial loop
-      INTEGER , INTENT(in   )                         ::   jl            ! category number
-      REAL(wp), INTENT(  out), DIMENSION (jpij,jpl  ) ::   eti, ets      ! vertically-summed heat content for ice & snow
-      REAL(wp), INTENT(  out), DIMENSION (jpij,jkmax) ::   etilayer      ! heat content for ice layers
-      !!
-      INTEGER  ::   ji,jk   ! loop indices
-      !!-----------------------------------------------------------------------
-      eti(:,:) = 0._wp
-      ets(:,:) = 0._wp
-      !
-      DO jk = 1, nlay_i                ! total q over all layers, ice [J.m-2]
-         DO ji = kideb, kiut
-            etilayer(ji,jk) = q_i_b(ji,jk) * ht_i_b(ji) / REAL( nlay_i )
-            eti     (ji,jl) = eti(ji,jl) + etilayer(ji,jk) 
-         END DO
-      END DO
-      DO ji = kideb, kiut              ! total q over all layers, snow [J.m-2]
-         ets(ji,jl) = ets(ji,jl) + q_s_b(ji,1) * ht_s_b(ji) / REAL( nlay_s )
-      END DO
-      !
-      IF(lwp) WRITE(numout,*) ' lim_thd_glohec '
-      IF(lwp) WRITE(numout,*) ' qt_i_in : ', eti(jiindex_1d,jl) / rdt_ice
-      IF(lwp) WRITE(numout,*) ' qt_s_in : ', ets(jiindex_1d,jl) / rdt_ice
-      IF(lwp) 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
-      !!-------------------------------------------------------------------
-      INTEGER , INTENT(in   ) ::   kideb, kiut   ! bounds for the spatial loop
-      INTEGER , INTENT(in   ) ::   jl            ! category number
-
-      INTEGER  ::   ji, jk         ! loop indices
-      INTEGER  ::   zji, zjj
-      INTEGER  ::   numce          ! number of points for which conservation is violated
-      REAL(wp) ::   meance         ! mean conservation error
-      REAL(wp) ::   max_cons_err, max_surf_err
-      !!---------------------------------------------------------------------
-
-      max_cons_err =  1.0_wp          ! maximum tolerated conservation error
-      max_surf_err =  0.001_wp        ! maximum tolerated surface error
-
-      !--------------------------
-      ! Increment of energy
-      !--------------------------
-      ! global
-      DO ji = kideb, kiut
-         dq_i(ji,jl) = qt_i_fin(ji,jl) - qt_i_in(ji,jl) + qt_s_fin(ji,jl) - qt_s_in(ji,jl)
-      END DO
-      ! layer by layer
-      dq_i_layer(:,:) = q_i_layer_fin(:,:) - q_i_layer_in(:,:)
-
-      !----------------------------------------
-      ! Atmospheric heat flux, ice heat budget
-      !----------------------------------------
-      DO ji = kideb, kiut
-         zji = MOD( npb(ji) - 1 , jpi ) + 1
-         zjj =    ( npb(ji) - 1 ) / jpi + 1
-         fatm     (ji,jl) = qnsr_ice_1d(ji) + ( 1._wp - i0(ji) ) * qsr_ice_1d(ji)
-         sum_fluxq(ji,jl) = fc_su(ji) - fc_bo_i(ji) + qsr_ice_1d(ji) * i0(ji) - fstroc(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._wp
-      DO ji = kideb, kiut
-         IF ( cons_error(ji,jl) .GT. max_cons_err ) THEN
-            numce = numce + 1
-            meance = meance + cons_error(ji,jl)
-         ENDIF
-      END DO
-      IF( numce > 0 )   meance = meance / numce
-
-      WRITE(numout,*) ' Maximum tolerated conservation error : ', max_cons_err
-      WRITE(numout,*) ' After lim_thd_dif, category : ', jl
-      WRITE(numout,*) ' Mean conservation error on big error points ', meance, numit
-      WRITE(numout,*) ' Number of points where there is a cons err gt than c.e. : ', numce, numit
-
-      !-------------------------------------------------------
-      ! Surface error due to imbalance between Fatm and Fcsu
-      !-------------------------------------------------------
-      numce  = 0
-      meance = 0._wp
-
-      DO ji = kideb, kiut
-         surf_error(ji,jl) = ABS ( fatm(ji,jl) - fc_su(ji) )
-         IF( ( t_su_b(ji) .LT. rtt ) .AND. ( surf_error(ji,jl) .GT. max_surf_err ) ) THEN
-            numce = numce + 1 
-            meance = meance + surf_error(ji,jl)
-         ENDIF
-      ENDDO
-      IF( numce > 0 )   meance = meance / numce
-
-      WRITE(numout,*) ' Maximum tolerated surface error : ', max_surf_err
-      WRITE(numout,*) ' After lim_thd_dif, category : ', jl
-      WRITE(numout,*) ' Mean surface error on big error points ', meance, numit
-      WRITE(numout,*) ' Number of points where there is a surf err gt than surf_err : ', numce, numit
-
-      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,*) ' qsr_ice    : ', (1.0-i0(ji))*qsr_ice_1d(ji)
-            WRITE(numout,*) ' qns_ice    : ', qnsr_ice_1d(ji)
-            WRITE(numout,*) ' Conduction fluxes : '
-            WRITE(numout,*) ' fc_s      : ', fc_s(ji,0:nlay_s)
-            WRITE(numout,*) ' fc_i      : ', fc_i(ji,0:nlay_i)
-            WRITE(numout,*)
-            WRITE(numout,*) ' Layer by layer ... '
-            WRITE(numout,*) ' dq_snow : ', ( qt_s_fin(ji,jl) - qt_s_in(ji,jl) ) / 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.
-      !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kideb, kiut   ! bounds for the spatial loop
-      INTEGER, INTENT(in) ::   jl            ! category number
-      !
-      INTEGER  ::   ji                ! loop indices
-      INTEGER  ::   zji, zjj, numce         ! local integers
-      REAL(wp) ::   meance, max_cons_err    !local scalar
-      !!---------------------------------------------------------------------
-
-      max_cons_err = 1._wp
-
-      !--------------------------
-      ! Increment of energy
-      !--------------------------
-      DO ji = kideb, kiut
-         dq_i(ji,jl) = qt_i_fin(ji,jl) - qt_i_in(ji,jl) + qt_s_fin(ji,jl) - qt_s_in(ji,jl)   ! global
-      END DO
-      dq_i_layer(:,:)    = q_i_layer_fin(:,:) - q_i_layer_in(:,:)                            ! layer by layer
-
-      !----------------------------------------
-      ! Atmospheric heat flux, ice heat budget
-      !----------------------------------------
-      DO ji = kideb, kiut
-         zji = MOD( npb(ji) - 1 , jpi ) + 1
-         zjj =    ( npb(ji) - 1 ) / jpi + 1
-
-         fatm      (ji,jl) = qnsr_ice_1d(ji) + qsr_ice_1d(ji)                       ! total heat flux
-         sum_fluxq (ji,jl) = fatm(ji,jl) + fbif_1d(ji) - ftotal_fin(ji) - fstroc(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._wp
-      DO ji = kideb, kiut
-         IF( cons_error(ji,jl) .GT. max_cons_err ) THEN
-            numce = numce + 1
-            meance = meance + cons_error(ji,jl)
-         ENDIF
-      ENDDO
-      IF(numce > 0 ) meance = meance / numce
-
-      WRITE(numout,*) ' Error report - Category : ', jl
-      WRITE(numout,*) ' ~~~~~~~~~~~~ '
-      WRITE(numout,*) ' Maximum tolerated conservation error : ', max_cons_err
-      WRITE(numout,*) ' After lim_thd_ent, category : ', jl
-      WRITE(numout,*) ' Mean conservation error on big error points ', meance, numit
-      WRITE(numout,*) ' Number of points where there is a cons err gt than 0.1 W/m2 : ', numce, numit
-
-      !---------------------------------------
-      ! Write ice state in case of big errors
-      !---------------------------------------
-      DO ji = kideb, kiut
-         IF ( cons_error(ji,jl) .GT. max_cons_err  ) THEN
-            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)
-      !!-------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kideb, kiut   ! bounds for the spatial loop
-      !!
-      INTEGER  ::   ji, jk   ! dummy loop indices
-      REAL(wp) ::   ztmelts  ! local scalar 
-      !!-------------------------------------------------------------------
-      !
-      DO jk = 1, nlay_i             ! Sea ice energy of melting
-         DO ji = kideb, kiut
-            ztmelts      =  - tmut  * s_i_b(ji,jk) + rtt 
-            q_i_b(ji,jk) =    rhoic * ( cpic * ( ztmelts - t_i_b(ji,jk) )                                 &
-               &                      + lfus * ( 1.0 - (ztmelts-rtt) / MIN( t_i_b(ji,jk)-rtt, -epsi10 ) )   &
-               &                      - rcp  * ( ztmelts-rtt  )  ) 
-         END DO
-      END DO
-      DO jk = 1, nlay_s             ! Snow energy of melting
-         DO ji = kideb, kiut
-            q_s_b(ji,jk) = rhosn * ( cpic * ( rtt - t_s_b(ji,jk) ) + lfus )
-         END DO
-      END DO
-      !
-   END SUBROUTINE lim_thd_enmelt
-
-
-   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
-      !!-------------------------------------------------------------------
-      NAMELIST/namicethd/ hmelt , hiccrit, fraz_swi, maxfrazb, vfrazb, Cfrazb,   &
-         &                hicmin, hiclim,                                        &
-         &                sbeta  , parlat, hakspl, hibspl, exld,                 &
-         &                hakdif, hnzst  , thth  , parsub, alphs, betas,         & 
-         &                kappa_i, nconv_i_thd, maxer_i_thd, thcon_i_swi
-      !!-------------------------------------------------------------------
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_thd : Ice Thermodynamics'
-         WRITE(numout,*) '~~~~~~~'
-      ENDIF
-      !
-      REWIND( numnam_ice )                  ! read Namelist numnam_ice
-      READ  ( numnam_ice , namicethd )
-      !
-      IF(lwp) THEN                          ! control print
-         WRITE(numout,*)
-         WRITE(numout,*)'   Namelist of ice parameters for ice thermodynamic computation '
-         WRITE(numout,*)'      maximum melting at the bottom                           hmelt        = ', hmelt
-         WRITE(numout,*)'      ice thick. for lateral accretion in NH (SH)             hiccrit(1/2) = ', hiccrit
-         WRITE(numout,*)'      Frazil ice thickness as a function of wind or not       fraz_swi     = ', fraz_swi
-         WRITE(numout,*)'      Maximum proportion of frazil ice collecting at bottom   maxfrazb     = ', maxfrazb
-         WRITE(numout,*)'      Thresold relative drift speed for collection of frazil  vfrazb       = ', vfrazb
-         WRITE(numout,*)'      Squeezing coefficient for collection of frazil          Cfrazb       = ', Cfrazb
-         WRITE(numout,*)'      ice thick. corr. to max. energy stored in brine pocket  hicmin       = ', hicmin  
-         WRITE(numout,*)'      minimum ice thickness                                   hiclim       = ', hiclim 
-         WRITE(numout,*)'      numerical carac. of the scheme for diffusion in ice '
-         WRITE(numout,*)'      Cranck-Nicholson (=0.5), implicit (=1), explicit (=0)   sbeta        = ', sbeta
-         WRITE(numout,*)'      percentage of energy used for lateral ablation          parlat       = ', parlat
-         WRITE(numout,*)'      slope of distr. for Hakkinen-Mellor lateral melting     hakspl       = ', hakspl  
-         WRITE(numout,*)'      slope of distribution for Hibler lateral melting        hibspl       = ', hibspl
-         WRITE(numout,*)'      exponent for leads-closure rate                         exld         = ', exld
-         WRITE(numout,*)'      coefficient for diffusions of ice and snow              hakdif       = ', hakdif
-         WRITE(numout,*)'      threshold thick. for comp. of eq. thermal conductivity  zhth         = ', thth 
-         WRITE(numout,*)'      thickness of the surf. layer in temp. computation       hnzst        = ', hnzst
-         WRITE(numout,*)'      switch for snow sublimation  (=1) or not (=0)           parsub       = ', parsub  
-         WRITE(numout,*)'      coefficient for snow density when snow ice formation    alphs        = ', alphs
-         WRITE(numout,*)'      coefficient for ice-lead partition of snowfall          betas        = ', betas
-         WRITE(numout,*)'      extinction radiation parameter in sea ice (1.0)         kappa_i      = ', kappa_i
-         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
-      ENDIF
-      !
-      rcdsn = hakdif * rcdsn 
-      rcdic = hakdif * rcdic
-      !
-   END SUBROUTINE lim_thd_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Dummy module          NO  LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-
-   !!======================================================================
-END MODULE limthd
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limthd_dh.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limthd_dh.F90	(revision 3937)
+++ 	(revision )
@@ -1,754 +1,0 @@
-MODULE limthd_dh
-   !!======================================================================
-   !!                       ***  MODULE limthd_dh ***
-   !!  LIM-3 :   thermodynamic growth and decay of the ice 
-   !!======================================================================
-   !! History :  LIM  ! 2003-05 (M. Vancoppenolle) Original code in 1D
-   !!                 ! 2005-06 (M. Vancoppenolle) 3D version 
-   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in rdmsnif & rdmicif
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd_dh  : vertical accr./abl. and lateral ablation of sea ice
-   !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE phycst           ! physical constants (OCE directory) 
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE ice              ! LIM variables
-   USE par_ice          ! LIM parameters
-   USE thd_ice          ! LIM thermodynamics
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE lib_fortran      ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_dh   ! called by lim_thd
-
-   REAL(wp) ::   epsi20 = 1e-20   ! constant values
-   REAL(wp) ::   epsi13 = 1e-13   !
-   REAL(wp) ::   epsi16 = 1e-16   !
-   REAL(wp) ::   zzero  = 0.e0    !
-   REAL(wp) ::   zone   = 1.e0    !
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
-   !! $Id: limthd_dh.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd_dh( kideb, kiut, jl )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_thd_dh  ***
-      !!
-      !! ** Purpose :   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
-      !!
-      !!                 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
-      !!
-      !! References : Bitz and Lipscomb, 1999, J. Geophys. Res.
-      !!              Fichefet T. and M. Maqueda 1997, J. Geophys. Res., 102(C6), 12609-12646   
-      !!              Vancoppenolle, Fichefet and Bitz, 2005, Geophys. Res. Let. 
-      !!              Vancoppenolle et al.,2009, Ocean Modelling
-      !!------------------------------------------------------------------
-      INTEGER , INTENT(in) ::   kideb, kiut   ! Start/End point on which the  the computation is applied
-      INTEGER , INTENT(in) ::   jl            ! Thickness cateogry number
-      !! 
-      INTEGER  ::   ji , jk        ! dummy loop indices
-      INTEGER  ::   zji, zjj       ! 2D corresponding indices to ji
-      INTEGER  ::   iter
-
-      REAL(wp) ::   isnow          ! switch for presence (1) or absence (0) of snow
-      REAL(wp) ::   isnowic        ! snow ice formation not
-      REAL(wp) ::   i_ice_switch   ! ice thickness above a certain treshold or not
-
-      REAL(wp) ::   zzfmass_i, zihgnew                     ! local scalar
-      REAL(wp) ::   zzfmass_s, zhsnew, ztmelts             ! local scalar
-      REAL(wp) ::   zhn, zdhcf, zdhbf, zhni, zhnfi, zihg   !
-      REAL(wp) ::   zdhnm, zhnnew, zhisn, zihic, zzc       !
-      REAL(wp) ::   zfracs       ! fractionation coefficient for bottom salt entrapment
-      REAL(wp) ::   zds          ! increment of bottom ice salinity
-      REAL(wp) ::   zcoeff       ! dummy argument for snowfall partitioning over ice and leads
-      REAL(wp) ::   zsm_snowice  ! snow-ice salinity
-      REAL(wp) ::   zswi1        ! switch for computation of bottom salinity
-      REAL(wp) ::   zswi12       ! switch for computation of bottom salinity
-      REAL(wp) ::   zswi2        ! switch for computation of bottom salinity
-      REAL(wp) ::   zgrr         ! bottom growth rate
-      REAL(wp) ::   ztform       ! bottom formation temperature
-      !
-      REAL(wp), POINTER, DIMENSION(:) ::   zh_i        ! ice layer thickness
-      REAL(wp), POINTER, DIMENSION(:) ::   zh_s        ! snow layer thickness
-      REAL(wp), POINTER, DIMENSION(:) ::   ztfs        ! melting point
-      REAL(wp), POINTER, DIMENSION(:) ::   zhsold      ! old snow thickness
-      REAL(wp), POINTER, DIMENSION(:) ::   zqprec      ! energy of fallen snow
-      REAL(wp), POINTER, DIMENSION(:) ::   zqfont_su   ! incoming, remaining surface energy
-      REAL(wp), POINTER, DIMENSION(:) ::   zqfont_bo   ! incoming, bottom energy
-      REAL(wp), POINTER, DIMENSION(:) ::   z_f_surf    ! surface heat for ablation
-      REAL(wp), POINTER, DIMENSION(:) ::   zhgnew      ! new ice thickness
-      REAL(wp), POINTER, DIMENSION(:) ::   zfmass_i    ! 
-
-      REAL(wp), POINTER, DIMENSION(:) ::   zdh_s_mel     ! snow melt 
-      REAL(wp), POINTER, DIMENSION(:) ::   zdh_s_pre     ! snow precipitation 
-      REAL(wp), POINTER, DIMENSION(:) ::   zdh_s_sub     ! snow sublimation
-      REAL(wp), POINTER, DIMENSION(:) ::   zfsalt_melt   ! salt flux due to ice melt
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zdeltah
-
-      ! Pathological cases
-      REAL(wp), POINTER, DIMENSION(:) ::   zfdt_init   ! total incoming heat for ice melt
-      REAL(wp), POINTER, DIMENSION(:) ::   zfdt_final  ! total remaing heat for ice melt
-      REAL(wp), POINTER, DIMENSION(:) ::   zqt_i       ! total ice heat content
-      REAL(wp), POINTER, DIMENSION(:) ::   zqt_s       ! total snow heat content
-      REAL(wp), POINTER, DIMENSION(:) ::   zqt_dummy   ! dummy heat content
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zqt_i_lay   ! total ice heat content
-
-      ! mass and salt flux (clem)
-      REAL(wp) :: zdvres
-      REAL(wp), POINTER, DIMENSION(:) ::   zviold, zvsold   ! old ice volume...
-
-      ! Heat conservation 
-      INTEGER  ::   num_iter_max, numce_dh
-      REAL(wp) ::   meance_dh
-      REAL(wp), POINTER, DIMENSION(:) ::   zinnermelt
-      REAL(wp), POINTER, DIMENSION(:) ::   zfbase, zdq_i
-      !!------------------------------------------------------------------
-
-      CALL wrk_alloc( jpij, zh_i, zh_s, ztfs, zhsold, zqprec, zqfont_su, zqfont_bo, z_f_surf, zhgnew, zfmass_i )
-      CALL wrk_alloc( jpij, zdh_s_mel, zdh_s_pre, zdh_s_sub, zfsalt_melt, zfdt_init, zfdt_final, zqt_i, zqt_s, zqt_dummy )
-      CALL wrk_alloc( jpij, zinnermelt, zfbase, zdq_i )
-      CALL wrk_alloc( jpij, jkmax, zdeltah, zqt_i_lay )
-
-      CALL wrk_alloc( jpij, zviold, zvsold ) ! clem
-      
-      zfsalt_melt(:)  = 0._wp
-      ftotal_fin(:)   = 0._wp
-      zfdt_init(:)    = 0._wp
-      zfdt_final(:)   = 0._wp
-      dh_i_surf(:)    = 0._wp
-      dh_i_bott(:)    = 0._wp
-      dh_snowice(:)    = 0._wp
-
-      DO ji = kideb, kiut
-         old_ht_i_b(ji) = ht_i_b(ji)
-         old_ht_s_b(ji) = ht_s_b(ji)
-         zviold(ji) = a_i_b(ji) * ht_i_b(ji) ! clem
-         zvsold(ji) = a_i_b(ji) * ht_s_b(ji) ! clem
-      END DO
-      !
-      !------------------------------------------------------------------------------!
-      !  1) Calculate available heat for surface ablation                            !
-      !------------------------------------------------------------------------------!
-      !
-      DO ji = kideb, kiut
-         isnow         = 1.0 - MAX ( 0.0 , SIGN ( 1.0 , - ht_s_b(ji) ) )
-         ztfs(ji)      = isnow * rtt + ( 1.0 - isnow ) * rtt
-         z_f_surf(ji)  = qnsr_ice_1d(ji) + ( 1.0 - i0(ji) ) * qsr_ice_1d(ji) - fc_su(ji)
-         z_f_surf(ji)  = MAX( zzero , z_f_surf(ji) ) * MAX( zzero , SIGN( zone , t_su_b(ji) - ztfs(ji) ) )
-         zfdt_init(ji) = ( z_f_surf(ji) + MAX( fbif_1d(ji) + qlbbq_1d(ji) + fc_bo_i(ji),0.0 ) ) * rdt_ice
-      END DO ! ji
-
-      zqfont_su  (:) = 0._wp
-      zqfont_bo  (:) = 0._wp
-      dsm_i_se_1d(:) = 0._wp     
-      dsm_i_si_1d(:) = 0._wp   
-      !
-      !------------------------------------------------------------------------------!
-      !  2) Computing layer thicknesses and  snow and sea-ice enthalpies.            !
-      !------------------------------------------------------------------------------!
-      !
-      DO ji = kideb, kiut     ! Layer thickness
-         zh_i(ji) = ht_i_b(ji) / REAL( nlay_i )
-         zh_s(ji) = ht_s_b(ji) / REAL( nlay_s )
-      END DO
-      !
-      zqt_s(:) = 0._wp        ! Total enthalpy of the snow
-      DO jk = 1, nlay_s
-         DO ji = kideb, kiut
-            zqt_s(ji) =  zqt_s(ji) + q_s_b(ji,jk) * ht_s_b(ji) / REAL( nlay_s )
-         END DO
-      END DO
-      !
-      zqt_i(:) = 0._wp        ! Total enthalpy of the ice
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            zzc = q_i_b(ji,jk) * ht_i_b(ji) / REAL( nlay_i )
-            zqt_i(ji)        =  zqt_i(ji) + zzc
-            zqt_i_lay(ji,jk) =              zzc
-         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._wp
-
-      ! Melt of fallen snow
-      DO ji = kideb, kiut
-         ! tatm_ice is now in K
-         zqprec   (ji)   =  rhosn * ( cpic * ( rtt - tatm_ice_1d(ji) ) + lfus )  
-         zqfont_su(ji)   =  z_f_surf(ji) * rdt_ice
-         zdeltah  (ji,1) =  MIN( 0.e0 , - zqfont_su(ji) / MAX( zqprec(ji) , epsi13 ) )
-         zqfont_su(ji)   =  MAX( 0.e0 , - zdh_s_pre(ji) - zdeltah(ji,1)              ) * zqprec(ji)
-         zdeltah  (ji,1) =  MAX( - zdh_s_pre(ji) , zdeltah(ji,1) )
-         zdh_s_mel(ji)   =  zdh_s_mel(ji) + zdeltah(ji,1)
-         ! heat conservation
-         qt_s_in(ji,jl)  =  qt_s_in(ji,jl) + zqprec(ji) * zdh_s_pre(ji)
-         zqt_s  (ji)     =  zqt_s  (ji)    + zqprec(ji) * zdh_s_pre(ji)
-         zqt_s  (ji)     =  MAX( zqt_s(ji) - zqfont_su(ji) , 0.e0 ) 
-      END DO
-
-
-      ! Snow melt due to surface heat imbalance
-      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) =  a_i_b(ji) * ( ht_s_b(ji) - zhsold(ji) - zdh_s_pre(ji) )   ! IOVINO
-         dvsbq_1d  (ji) =  MIN( zzero, dvsbq_1d(ji) )
-         !clem rdmsnif_1d(ji) =  rdmsnif_1d(ji) + rhosn * dvsbq_1d(ji)
-      END DO ! ji
-
-      !--------------------------
-      ! 3.2 Surface ice ablation 
-      !--------------------------
-      DO ji = kideb, kiut 
-         z_f_surf (ji) =  zqfont_su(ji) / rdt_ice ! heat conservation test
-         zdq_i    (ji) =  0._wp
-      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
-            !
-            ! IOVINO
-            !zfsalt_melt(ji) = zfsalt_melt(ji) - sm_i_b(ji) * a_i_b(ji)    &
-            !   &                              * MIN( zdeltah(ji,jk) , 0.e0 ) * rhoic / rdt_ice
-            fseqv_1d(ji) = fseqv_1d(ji) - sm_i_b(ji) * a_i_b(ji)    &
-               &                              * MIN( zdeltah(ji,jk) , 0._wp ) * rhoic / rdt_ice
-         END DO
-      END DO
-
-      !                     !-------------------
-      IF( con_i ) THEN      ! Conservation test
-         !                  !-------------------
-         numce_dh  = 0
-         meance_dh = 0._wp
-         DO ji = kideb, kiut
-            IF ( ( z_f_surf(ji) + zdq_i(ji) ) .GE. 1.0e-3 ) THEN
-               numce_dh  = numce_dh + 1
-               meance_dh = meance_dh + z_f_surf(ji) + zdq_i(ji)
-            ENDIF
-            IF( z_f_surf(ji) + zdq_i(ji) .GE. 1.0e-3  ) THEN!
-               WRITE(numout,*) ' ALERTE heat loss for surface melt '
-               WRITE(numout,*) ' 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_m        : ', sss_m(zji,zjj)
-            ENDIF
-         END DO
-         !
-         IF( numce_dh > 0 )   meance_dh = meance_dh / numce_dh
-         WRITE(numout,*) ' Error report - Category : ', jl
-         WRITE(numout,*) ' ~~~~~~~~~~~~ '
-         WRITE(numout,*) ' Number of points where there is sur. me. error : ', numce_dh
-         WRITE(numout,*) ' Mean basal growth error on error points : ', meance_dh
-         !
-      ENDIF
-
-      !----------------------
-      ! 3.3 Snow sublimation
-      !----------------------
-
-      DO ji = kideb, kiut
-         ! 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
-
-      zqt_dummy(:) = 0.e0
-      DO jk = 1, nlay_s
-         DO ji = kideb,kiut
-            q_s_b    (ji,jk) = rhosn * ( cpic * ( rtt - t_s_b(ji,jk) ) + lfus )
-            zqt_dummy(ji)    =  zqt_dummy(ji) + q_s_b(ji,jk) * ht_s_b(ji) / REAL( nlay_s )            ! heat conservation
-         END DO
-      END DO
-
-      DO jk = 1, nlay_s
-         DO ji = kideb, kiut
-            ! In case of disparition of the snow, we have to update the snow temperatures
-            zhisn  =  MAX( zzero , SIGN( zone, - ht_s_b(ji) ) )
-            t_s_b(ji,jk) = ( 1.0 - zhisn ) * t_s_b(ji,jk) + zhisn * rtt
-            q_s_b(ji,jk) = ( 1.0 - zhisn ) * q_s_b(ji,jk)
-         END DO
-      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 /= 2  .AND.  num_sal /= 4  ) THEN
-         DO ji = kideb, kiut
-            IF(  ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) < 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) 
-               fseqv_1d(ji) = fseqv_1d(ji) - s_i_new(ji) * a_i_b(ji) * dh_i_bott(ji) * rhoic / rdt_ice
-            ENDIF
-         END DO
-      ENDIF
-
-      !-------------------------------------------------
-      ! 4.1 Basal growth - (b) salinity varying in time 
-      !-------------------------------------------------
-      IF(  num_sal == 2 .OR.  num_sal == 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) < 0.e0  ) 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 , epsi13 ) )
-                  zswi2  = MAX( zzero , SIGN( zone , zgrr - 3.6e-7 ) ) 
-                  zswi12 = MAX( zzero , SIGN( zone , zgrr - 2.0e-8 ) ) * ( 1.0 - zswi2 )
-                  zswi1  = 1. - zswi2 * zswi12 
-                  zfracs = zswi1  * 0.12 + zswi12 * ( 0.8925 + 0.0568 * LOG( 100.0 * zgrr ) )   &
-                     &                   + zswi2  * 0.26 / ( 0.26 + 0.74 * EXP ( - 724300.0 * zgrr ) ) 
-                  zds         = zfracs * sss_m(zji,zjj) - s_i_new(ji)
-                  s_i_new(ji) = zfracs * sss_m(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) ,epsi13 ) - sm_i_b(ji)
-               fseqv_1d(ji) = fseqv_1d(ji) - s_i_new(ji) * a_i_b(ji) * dh_i_bott(ji) * rhoic / rdt_ice
-            ENDIF ! heat budget
-         END DO
-      ENDIF
-
-      !----------------
-      ! 4.2 Basal melt
-      !----------------
-      meance_dh = 0._wp
-      numce_dh  = 0
-      zinnermelt(:) = 0._wp
-
-      DO ji = kideb, kiut
-         ! heat convergence at the surface > 0
-         IF(  ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) >= 0._wp  ) THEN
-            s_i_new(ji)   =  s_i_b(ji,nlay_i)
-            zqfont_bo(ji) =  rdt_ice * ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) )
-            zfbase(ji)    =  zqfont_bo(ji) / rdt_ice     ! heat conservation test
-            zdq_i(ji)     =  0._wp
-            dh_i_bott(ji) =  0._wp
-         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) >= ztmelts ) THEN
-                  zdeltah(ji,jk)  = - zh_i(ji)
-                  dh_i_bott(ji)   = dh_i_bott(ji) + zdeltah(ji,jk)
-                  zinnermelt(ji)   = 1._wp
-               ELSE  ! normal ablation
-                  zdeltah(ji,jk)  = - zqfont_bo(ji) / q_i_b(ji,jk)
-                  zqfont_bo(ji)   = MAX( 0.0 , - zh_i(ji) - zdeltah(ji,jk) ) * q_i_b(ji,jk)
-                  zdeltah(ji,jk)  = MAX(zdeltah(ji,jk), - zh_i(ji) )
-                  dh_i_bott(ji)   = dh_i_bott(ji) + zdeltah(ji,jk)
-                  zdq_i(ji)       = zdq_i(ji) + zdeltah(ji,jk) * q_i_b(ji,jk) / rdt_ice
-               ENDIF
-               ! IOVINO contribution to salt flux
-               !zfsalt_melt(ji) = zfsalt_melt(ji) - sm_i_b(ji) * a_i_b(ji)   &
-               !     &                              * MIN( zdeltah(ji,jk) , 0._wp ) * rhoic / rdt_ice
-               fseqv_1d(ji) = fseqv_1d(ji) - sm_i_b(ji) * a_i_b(ji)    &
-                    &                              * MIN( zdeltah(ji,jk) , 0._wp ) * rhoic / rdt_ice
-            ENDIF
-         END DO ! ji
-      END DO ! jk
-
-      !                     !-------------------
-      IF( con_i ) THEN      ! Conservation test
-      !                     !-------------------
-         DO ji = kideb, kiut
-            IF(  ( fc_bo_i(ji) + fbif_1d(ji) + qlbbq_1d(ji) ) >= 0.e0  ) THEN
-               IF( ( zfbase(ji) + zdq_i(ji) ) >= 1.e-3 ) THEN
-                  numce_dh  = numce_dh + 1
-                  meance_dh = meance_dh + zfbase(ji) + zdq_i(ji)
-               ENDIF
-               IF ( zfbase(ji) + zdq_i(ji) .GE. 1.0e-3  ) THEN
-                  WRITE(numout,*) ' ALERTE heat loss for basal melt : 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_m     : ', sss_m(zji,zjj)
-                  WRITE(numout,*) ' dh_i_bott : ', dh_i_bott(ji)
-                  WRITE(numout,*) ' innermelt : ', INT( zinnermelt(ji) )
-               ENDIF
-            ENDIF
-         END DO
-         IF( numce_dh > 0 )   meance_dh = meance_dh / numce_dh
-         WRITE(numout,*) ' Number of points where there is bas. me. error : ', numce_dh
-         WRITE(numout,*) ' Mean basal melt error on error points : ', meance_dh
-         WRITE(numout,*) ' Remaining bottom heat : ', zqfont_bo(jiindex_1d)
-         !
-      ENDIF
-
-      !
-      !------------------------------------------------------------------------------!
-      !  5) Pathological cases                                                       !
-      !------------------------------------------------------------------------------!
-      !
-      !----------------------------------------------
-      ! 5.1 Excessive ablation in a 1-category model
-      !----------------------------------------------
-
-      DO ji = kideb, kiut
-         !                     ! in a 1-category sea ice model, bottom ablation must not exceed hmelt (-0.15)
-         IF( jpl == 1 ) THEN   ;   zdhbf = MAX( hmelt , dh_i_bott(ji) )
-         ELSE                  ;   zdhbf =              dh_i_bott(ji) 
-         ENDIF
-         zdvres        = zdhbf - dh_i_bott(ji)
-         dh_i_bott(ji) = zdhbf
-         fseqv_1d(ji)  = fseqv_1d(ji) - sm_i_b(ji) * a_i_b(ji) * zdvres * rhoic / rdt_ice
-         !                     ! excessive energy is sent to lateral ablation
-         fsup     (ji) =  rhoic * lfus * at_i_b(ji) / MAX( 1.0 - at_i_b(ji) , epsi13 ) * zdvres / rdt_ice
-         !                     !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)
-      END DO
-
-      !-----------------------------------
-      ! 5.2 More than available ice melts
-      !-----------------------------------
-      ! then heat applied minus heat content at previous time step
-      ! should equal heat remaining 
-      !
-      DO ji = kideb, kiut
-         ! Adapt the remaining energy if too much ice melts
-         !--------------------------------------------------
-         zdvres     = MAX( 0._wp, - zhgnew(ji) )
-         zihgnew    =  1.0 - MAX( zzero , SIGN( zone , - zhgnew(ji) ) ) !1 if ice
-         dh_i_bott (ji) = dh_i_bott(ji) + zdvres ! clem@bug
-         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, epsi13 )
-         zdhnm     =  - ( 1. - zihg ) * ( 1. - zihgnew ) * zfdt_final(ji) / MAX( zqt_s(ji) , epsi13 )
-         zhnfi          =  zhni + zdhnm
-         zfdt_final(ji) =  MAX( zfdt_final(ji) + zqt_s(ji) * zdhnm , 0.0 )
-         ht_s_b(ji)     =  MAX( zzero , zhnfi )
-         zqt_s(ji)      =  zqt_s(ji) * ht_s_b(ji)
-
-         ! Mass variations of ice and snow
-         !---------------------------------
-         !                                              ! mass variation of the jl category
-         zzfmass_s = - a_i_b(ji) * ( zhni       - ht_s_b(ji) ) * rhosn   ! snow
-         zzfmass_i =   a_i_b(ji) * ( zhgnew(ji) - ht_i_b(ji) ) * rhoic   ! ice  
-         !
-         zfmass_i(ji) = zzfmass_i                       ! ice variation saved to compute salt flux (see below)
-         !
-         !                                              ! mass variation cumulated over category
-         !clem rdmsnif_1d(ji) = rdmsnif_1d(ji) + zzfmass_s                     ! snow 
-         !clem rdmicif_1d(ji) = rdmicif_1d(ji) + zzfmass_i                     ! ice 
-
-         ! Remaining heat to the ocean 
-         !---------------------------------
-         focea(ji)  = - zfdt_final(ji) / rdt_ice         ! focea is in W.m-2 * dt
-         ! salt flux
-         fseqv_1d(ji)  = fseqv_1d(ji) - sm_i_b(ji) * a_i_b(ji) * zdvres * rhoic / rdt_ice
-         !                     ! 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
-
-      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
-         ! new lines
-         !IF( num_sal == 4 ) THEN
-         !   ! IOVINO
-         !   fseqv_1d(ji) = fseqv_1d(ji) +        zihgnew  * zfsalt_melt(ji)                                &
-         !      &                        - (1.0 - zihgnew) * zfmass_i(ji) * bulk_sal / rdt_ice
-         !ELSE
-         !   ! IOVINO
-         !   fseqv_1d(ji) = fseqv_1d(ji) +        zihgnew  * zfsalt_melt(ji)                                &
-         !      &                        - (1.0 - zihgnew) * zfmass_i(ji) * sm_i_b(ji) / rdt_ice 
-         !ENDIF
-         ! 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
-         !IF ( (zji.eq.jiindx).AND.(zjj.eq.jjindx) ) THEN
-         !   !clemclem
-         !   WRITE(numout,*) 'lim_thd_dh : qldif = ', qldif_1d(ji)
-         !   !clemclem
-         !ENDIF
-      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
-
-         !clem rdmicif_1d(ji) = rdmicif_1d(ji) + a_i_b(ji) * ( zhgnew(ji) - ht_i_b(ji) ) * rhoic 
-         !clem 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
-
-         IF( num_sal /= 2 ) THEN   ;   zsm_snowice = sm_i_b(ji)
-         ELSE                      ;   zsm_snowice = ( rhoic - rhosn ) / rhoic * sss_m(zji,zjj) 
-         ENDIF
-         !IF( num_sal == 4 ) THEN  
-         !   ! IOVINO
-         !   fseqv_1d(ji) = fseqv_1d(ji) - bulk_sal * a_i_b(ji) * dh_snowice(ji) * rhoic / rdt_ice
-         !ELSE
-         !   ! IOVINO
-         !   fseqv_1d(ji) = fseqv_1d(ji) - zsm_snowice * a_i_b(ji) * dh_snowice(ji) * rhoic / rdt_ice
-         !ENDIF
-         ! entrapment during snow ice formation
-         i_ice_switch = 1.0 - MAX( 0.e0 , SIGN( 1.0 , - ht_i_b(ji) + epsi13 ) )
-         isnowic      = 1.0 - MAX( 0.e0 , SIGN( 1.0 , - dh_snowice(ji) ) ) * i_ice_switch
-
-         !clem IF(  num_sal == 2  .OR.  num_sal == 4  )   &
-         !clem   dsm_i_si_1d(ji) = ( zsm_snowice*dh_snowice(ji) &
-         !clem   &               + sm_i_b(ji) * ht_i_b(ji) / MAX( ht_i_b(ji) + dh_snowice(ji), epsi13)   &
-         !clem   &               - sm_i_b(ji) ) * isnowic
-         IF (  num_sal == 2  .OR.  num_sal == 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), epsi13 ) - sm_i_b(ji) ) * isnowic     
-
-         !  Actualize new snow and ice thickness.
-         ht_s_b(ji)  = zhnnew
-         ht_i_b(ji)  = zhgnew(ji)
-
-         ! Total ablation ! new lines added to debug
-         IF( ht_i_b(ji) <= 0._wp )   a_i_b(ji) = 0._wp
-
-         ! diagnostic ( snow ice growth )
-         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
-
-         ! salt flux
-         fseqv_1d(ji) = fseqv_1d(ji) - zsm_snowice * a_i_b(ji) * dh_snowice(ji) * rhoic / rdt_ice
-         !--------------------------------
-         ! Update mass fluxes (clem)
-         !--------------------------------
-         rdmicif_1d(ji) = rdmicif_1d(ji) + ( a_i_b(ji) * ht_i_b(ji) - zviold(ji) ) * rhoic 
-         rdmsnif_1d(ji) = rdmsnif_1d(ji) + ( a_i_b(ji) * ht_s_b(ji) - zvsold(ji) ) * rhosn 
-
-      END DO !ji
-      !
-      CALL wrk_dealloc( jpij, zh_i, zh_s, ztfs, zhsold, zqprec, zqfont_su, zqfont_bo, z_f_surf, zhgnew, zfmass_i )
-      CALL wrk_dealloc( jpij, zdh_s_mel, zdh_s_pre, zdh_s_sub, zfsalt_melt, zfdt_init, zfdt_final, zqt_i, zqt_s, zqt_dummy )
-      CALL wrk_dealloc( jpij, zinnermelt, zfbase, zdq_i )
-      CALL wrk_dealloc( jpij, jkmax, zdeltah, zqt_i_lay )
-      !
-      CALL wrk_dealloc( jpij, zviold, zvsold ) ! clem
-      !
-   END SUBROUTINE lim_thd_dh
-   
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                               NO  LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_dh          ! Empty routine
-   END SUBROUTINE lim_thd_dh
-#endif
-
-   !!======================================================================
-END MODULE limthd_dh
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limthd_dif.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limthd_dif.F90	(revision 3937)
+++ 	(revision )
@@ -1,780 +1,0 @@
-MODULE limthd_dif
-   !!======================================================================
-   !!                       ***  MODULE limthd_dif ***
-   !!                       heat diffusion in sea ice 
-   !!                   computation of surface and inner T  
-   !!======================================================================
-   !! History :  LIM  ! 02-2003 (M. Vancoppenolle) original 1D code
-   !!                 ! 06-2005 (M. Vancoppenolle) 3d version
-   !!                 ! 11-2006 (X Fettweis) Vectorization by Xavier
-   !!                 ! 04-2007 (M. Vancoppenolle) Energy conservation
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE phycst           ! physical constants (ocean directory) 
-   USE ice              ! LIM-3 variables
-   USE par_ice          ! LIM-3 parameters
-   USE thd_ice          ! LIM-3: thermodynamics
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE lib_fortran      ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_dif   ! called by lim_thd
-
-   REAL(wp) ::   epsi20 = 1e-20     ! constant values
-   REAL(wp) ::   epsi13 = 1e-13     ! constant values
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limthd_dif.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-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
-      !!------------------------------------------------------------------
-      INTEGER , INTENT (in) ::   kideb   ! Start point on which the  the computation is applied
-      INTEGER , INTENT (in) ::   kiut    ! End point on which the  the computation is applied
-      INTEGER , INTENT (in) ::   jl      ! Category number
-
-      !! * Local variables
-      INTEGER ::   ji          ! spatial loop index
-      INTEGER ::   ii, ij      ! temporary dummy loop index
-      INTEGER ::   numeq       ! current reference number of equation
-      INTEGER ::   layer       ! vertical dummy loop index 
-      INTEGER ::   nconv       ! number of iterations in iterative procedure
-      INTEGER ::   minnumeqmin, maxnumeqmax
-
-      INTEGER , DIMENSION(kiut) ::   numeqmin   ! reference number of top equation
-      INTEGER , DIMENSION(kiut) ::   numeqmax   ! reference number of bottom equation
-      INTEGER , DIMENSION(kiut) ::   isnow      ! switch for presence (1) or absence (0) of snow
-
-      !! * New local variables       
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   ztcond_i   !Ice thermal conductivity
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zradtr_i   !Radiation transmitted through the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zradab_i   !Radiation absorbed in the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zkappa_i   !Kappa factor in the ice
-
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zradtr_s   !Radiation transmited through the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zradab_s   !Radiation absorbed in the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zkappa_s   !Kappa factor in the snow
-
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   ztiold      !Old temperature in the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zeta_i      !Eta factor in the ice 
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   ztitemp     !Temporary temperature in the ice to check the convergence
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zspeche_i   !Ice specific heat
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   z_i         !Vertical cotes of the layers in the ice
-
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zeta_s      !Eta factor in the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   ztstemp     !Temporary temperature in the snow to check the convergence
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   ztsold      !Temporary temperature in the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   z_s         !Vertical cotes of the layers in the snow
-
-      REAL(wp), DIMENSION(kiut,jkmax+2)   ::   zindterm    ! Independent term
-      REAL(wp), DIMENSION(kiut,jkmax+2)   ::   zindtbis    ! temporary independent term
-      REAL(wp), DIMENSION(kiut,jkmax+2)   ::   zdiagbis
-      REAL(wp), DIMENSION(kiut,jkmax+2,3) ::   ztrid       ! tridiagonal system terms
-
-      REAL(wp), DIMENSION(kiut) ::   ztfs        ! ice melting point
-      REAL(wp), DIMENSION(kiut) ::   ztsuold     ! old surface temperature (before the iterative procedure )
-      REAL(wp), DIMENSION(kiut) ::   ztsuoldit   ! surface temperature at previous iteration
-      REAL(wp), DIMENSION(kiut) ::   zh_i        ! ice layer thickness
-      REAL(wp), DIMENSION(kiut) ::   zh_s        ! snow layer thickness
-      REAL(wp), DIMENSION(kiut) ::   zfsw        ! solar radiation absorbed at the surface
-      REAL(wp), DIMENSION(kiut) ::   zf          ! surface flux function
-      REAL(wp), DIMENSION(kiut) ::   dzf         ! derivative of the surface flux function
-
-      REAL(wp) ::   zeps      =  1.e-10_wp    !
-      REAL(wp) ::   zg1s      =  2._wp        ! for the tridiagonal system
-      REAL(wp) ::   zg1       =  2._wp        !
-      REAL(wp) ::   zgamma    =  18009._wp    ! for specific heat
-      REAL(wp) ::   zbeta     =  0.117_wp     ! for thermal conductivity (could be 0.13)
-      REAL(wp) ::   zraext_s  =  1.e+8_wp     ! extinction coefficient of radiation in the snow
-      REAL(wp) ::   zkimin    =  0.10_wp      ! minimum ice thermal conductivity
-      REAL(wp) ::   zht_smin  =  1.e-4_wp     ! minimum snow depth
-
-      REAL(wp) ::   ztmelt_i    ! ice melting temperature
-      REAL(wp) ::   zerritmax   ! current maximal error on temperature 
-      REAL(wp), DIMENSION(kiut) ::   zerrit       ! current error on temperature 
-      REAL(wp), DIMENSION(kiut) ::   zdifcase     ! case of the equation resolution (1->4)
-      REAL(wp), DIMENSION(kiut) ::   zftrice      ! solar radiation transmitted through the ice
-      REAL(wp), DIMENSION(kiut) ::   zihic, zhsu
-      !!------------------------------------------------------------------
-      !
-      !------------------------------------------------------------------------------!
-      ! 1) Initialization                                                            !
-      !------------------------------------------------------------------------------!
-      !
-      DO ji = kideb , kiut
-         ! is there snow or not
-         isnow(ji)= NINT(  1._wp - MAX( 0._wp , SIGN(1._wp, - ht_s_b(ji) ) )  )
-         ! surface temperature of fusion
-!!gm ???  ztfs(ji) = rtt !!!????
-         ztfs(ji) = REAL( isnow(ji) ) * rtt + REAL( 1 - isnow(ji) ) * rtt
-         ! layer thickness
-         zh_i(ji) = ht_i_b(ji) / REAL( nlay_i )
-         zh_s(ji) = ht_s_b(ji) / REAL( nlay_s )
-      END DO
-
-      !--------------------
-      ! Ice / snow layers
-      !--------------------
-
-      z_s(:,0) = 0._wp   ! vert. coord. of the up. lim. of the 1st snow layer
-      z_i(:,0) = 0._wp   ! vert. coord. of the up. lim. of the 1st ice layer
-
-      DO layer = 1, nlay_s            ! vert. coord of the up. lim. of the layer-th snow layer
-         DO ji = kideb , kiut
-            z_s(ji,layer) = z_s(ji,layer-1) + ht_s_b(ji) / REAL( nlay_s )
-         END DO
-      END DO
-
-      DO layer = 1, nlay_i            ! vert. coord of the up. lim. of the layer-th ice layer
-         DO ji = kideb , kiut
-            z_i(ji,layer) = z_i(ji,layer-1) + ht_i_b(ji) / REAL( nlay_i )
-         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) = NINT(  1._wp - MAX( 0._wp , SIGN( 1._wp , - ht_s_b(ji) ) )  ) 
-         ! hs > 0, isnow = 1
-         zhsu (ji) = hnzst  ! threshold for the computation of i0
-         zihic(ji) = MAX( 0._wp , 1._wp - ( ht_i_b(ji) / zhsu(ji) ) )     
-
-         i0(ji)    = REAL( 1 - 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
-         zfsw   (ji) =  qsr_ice_1d(ji) * ( 1 - i0(ji) )   ! Shortwave radiation absorbed at surface
-         zftrice(ji) =  qsr_ice_1d(ji) *       i0(ji)     ! Solar radiation transmitted below the surface layer
-         dzf    (ji) = dqns_ice_1d(ji)                    ! derivative of incoming nonsolar flux 
-      END DO
-
-      !---------------------------------------------------------
-      ! Transmission - absorption of solar radiation in the ice
-      !---------------------------------------------------------
-
-      DO ji = kideb, kiut           ! snow initialization
-         zradtr_s(ji,0) = zftrice(ji)     ! radiation penetrating through snow
-      END DO
-
-      DO layer = 1, nlay_s          ! Radiation through snow
-         DO ji = kideb, kiut
-            !                             ! radiation transmitted below the layer-th snow layer
-            zradtr_s(ji,layer) = zradtr_s(ji,0) * EXP( - zraext_s * ( MAX ( 0._wp , z_s(ji,layer) ) ) )
-            !                             ! 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
-
-      DO ji = kideb, kiut           ! ice initialization
-         zradtr_i(ji,0) = zradtr_s(ji,nlay_s) * REAL( isnow(ji) ) + zftrice(ji) * REAL( 1 - isnow(ji) )
-      END DO
-
-      DO layer = 1, nlay_i          ! Radiation through ice
-         DO ji = kideb, kiut
-            !                             ! radiation transmitted below the layer-th ice layer
-            zradtr_i(ji,layer) = zradtr_i(ji,0) * EXP( - kappa_i * ( MAX ( 0._wp , z_i(ji,layer) ) ) )
-            !                             ! 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
-
-      DO ji = kideb, kiut           ! Radiation transmitted below the ice
-         fstbif_1d(ji) = fstbif_1d(ji) + iatte_1d(ji) * zradtr_i(ji,nlay_i) * a_i_b(ji) / at_i_b(ji) ! clem modif
-      END DO
-
-      ! +++++
-      ! just to check energy conservation
-      DO ji = kideb, kiut
-         ii                = MOD( npb(ji) - 1, jpi ) + 1
-         ij                = ( npb(ji) - 1 ) / jpi + 1
-         fstroc(ii,ij,jl) = iatte_1d(ji) * zradtr_i(ji,nlay_i) ! clem modif
-      END DO
-      ! +++++
-
-      DO layer = 1, nlay_i
-         DO ji = kideb, kiut
-            radab(ji,layer) = zradab_i(ji,layer)
-         END DO
-      END DO
-
-      !
-      !------------------------------------------------------------------------------|
-      !  3) Iterative procedure begins                                               |
-      !------------------------------------------------------------------------------|
-      !
-      DO ji = kideb, kiut        ! Old surface temperature
-         ztsuold  (ji) =  t_su_b(ji)                              ! temperature at the beg of iter pr.
-         ztsuoldit(ji) =  t_su_b(ji)                              ! temperature at the previous iter
-         t_su_b   (ji) =  MIN( t_su_b(ji), ztfs(ji)-0.00001 )     ! necessary
-         zerrit   (ji) =  1000._wp                                ! initial value of error
-      END DO
-
-      DO layer = 1, nlay_s       ! Old snow temperature
-         DO ji = kideb , kiut
-            ztsold(ji,layer) =  t_s_b(ji,layer)
-         END DO
-      END DO
-
-      DO layer = 1, nlay_i       ! Old ice temperature
-         DO ji = kideb , kiut
-            ztiold(ji,layer) =  t_i_b(ji,layer)
-         END DO
-      END DO
-
-      nconv     =  0           ! number of iterations
-      zerritmax =  1000._wp    ! 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 == 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
-            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(-2.0_wp * zeps, t_i_b(ji,layer)+t_i_b(ji,layer+1) - 2.0_wp * rtt)
-                  ztcond_i(ji,layer) = MAX(ztcond_i(ji,layer),zkimin)
-               END DO
-            END DO
-         ENDIF
-
-         IF( thcon_i_swi == 1 ) THEN      ! Pringle et al formula included: 2.11 + 0.09 S/T - 0.011.T
-            DO ji = kideb , kiut
-               ztcond_i(ji,0) = rcdic + 0.090_wp * s_i_b(ji,1) / MIN( -zeps, t_i_b(ji,1)-rtt )   &
-                  &                   - 0.011_wp * ( t_i_b(ji,1) - rtt )  
-               ztcond_i(ji,0) = MAX( ztcond_i(ji,0), zkimin )
-            END DO
-            DO layer = 1, nlay_i-1
-               DO ji = kideb , kiut
-                  ztcond_i(ji,layer) = rcdic + 0.090_wp * ( s_i_b(ji,layer) + s_i_b(ji,layer+1) )   &
-                     &                                  / MIN(-2.0_wp * zeps, t_i_b(ji,layer)+t_i_b(ji,layer+1) - 2.0_wp * rtt)   &
-                     &                       - 0.0055_wp* ( t_i_b(ji,layer) + t_i_b(ji,layer+1) - 2.0*rtt )  
-                  ztcond_i(ji,layer) = MAX( ztcond_i(ji,layer), zkimin )
-               END DO
-            END DO
-            DO ji = kideb , kiut
-               ztcond_i(ji,nlay_i) = rcdic + 0.090_wp * s_i_b(ji,nlay_i) / MIN(-zeps,t_bo_b(ji)-rtt)   &
-                  &                        - 0.011_wp * ( 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)*REAL( isnow(ji) ) &
-               + zkappa_i(ji,0)*REAL( 1 - 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))) 
-
-            ! surface temperature
-            isnow(ji)     = NINT(1.0-max(0.0,SIGN(1.0,-ht_s_b(ji))))
-            ztsuoldit(ji) = t_su_b(ji)
-            IF (t_su_b(ji) .LT. ztfs(ji)) &
-               t_su_b(ji) = ( zindtbis(ji,numeqmin(ji)) - ztrid(ji,numeqmin(ji),3)* ( REAL( isnow(ji) )*t_s_b(ji,1)   &
-               &          + REAL( 1 - isnow(ji) )*t_i_b(ji,1) ) ) / zdiagbis(ji,numeqmin(ji))  
-         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._wp  )
-            zerrit(ji) =  ABS( t_su_b(ji) - ztsuoldit(ji) )     
-         END DO
-
-         DO layer  =  1, nlay_s
-            DO ji = kideb , kiut
-               ii = MOD( npb(ji) - 1, jpi ) + 1
-               ij = ( npb(ji) - 1 ) / jpi + 1
-               t_s_b(ji,layer) = MAX(  MIN( t_s_b(ji,layer), rtt ), 190._wp  )
-               zerrit(ji)      = MAX(zerrit(ji),ABS(t_s_b(ji,layer) - ztstemp(ji,layer)))
-            END DO
-         END DO
-
-         DO layer  =  1, nlay_i
-            DO ji = kideb , kiut
-               ztmelt_i        = -tmut * s_i_b(ji,layer) + rtt 
-               t_i_b(ji,layer) =  MAX(MIN(t_i_b(ji,layer),ztmelt_i),190.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._wp
-         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
-
-      IF( ln_nicep ) THEN
-         WRITE(numout,*) ' zerritmax : ', zerritmax
-         WRITE(numout,*) ' nconv     : ', nconv
-      ENDIF
-
-      !
-      !-------------------------------------------------------------------------!
-      !   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) )     ! TECLIM change
-         qla_ice_1d (ji) = MAX( 0.e0, qla_ice_1d (ji) + dqla_ice_1d(ji) * (t_su_b(ji) - ztsuold(ji) ) )
-         !                                ! surface ice conduction flux
-         isnow(ji)       = NINT(  1._wp - MAX( 0._wp, SIGN( 1._wp, -ht_s_b(ji) ) )  )
-         fc_su(ji)       =  -     REAL( isnow(ji) ) * zkappa_s(ji,0) * zg1s * (t_s_b(ji,1) - t_su_b(ji))   &
-            &               - REAL( 1 - isnow(ji) ) * zkappa_i(ji,0) * zg1  * (t_i_b(ji,1) - t_su_b(ji))
-         !                                ! 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) = - REAL( isnow(ji) ) * zkappa_s(ji,0) * zg1s * ( t_s_b(ji,1) - t_su_b(ji) ) 
-            ! Bott. snow value
-            fc_s(ji,1) = - REAL( isnow(ji) ) * zkappa_s(ji,1) * ( t_i_b(ji,1) - t_s_b(ji,1) ) 
-         END DO
-         DO ji = kideb, kiut         ! Upper ice layer
-            fc_i(ji,0) = - REAL( isnow(ji) ) * &  ! interface flux if there is snow
-               ( zkappa_i(ji,0)  * ( t_i_b(ji,1) - t_s_b(ji,nlay_s ) ) ) &
-               - REAL( 1 - isnow(ji) ) * ( zkappa_i(ji,0) * & 
-               zg1 * ( t_i_b(ji,1) - t_su_b(ji) ) ) ! upper flux if not
-         END DO
-         DO layer = 1, nlay_i - 1         ! Internal ice layers
-            DO ji = kideb, kiut
-               fc_i(ji,layer) = - zkappa_i(ji,layer) * ( t_i_b(ji,layer+1) - t_i_b(ji,layer) )
-               ii = MOD( npb(ji) - 1, jpi ) + 1
-               ij = ( npb(ji) - 1 ) / jpi + 1
-            END DO
-         END DO
-         DO ji = kideb, kiut         ! Bottom ice layers
-            fc_i(ji,nlay_i) = - zkappa_i(ji,nlay_i) * ( zg1*(t_bo_b(ji) - t_i_b(ji,nlay_i)) )
-         END DO
-      ENDIF
-      !
-
-   END SUBROUTINE lim_thd_dif
-
-#else
-   !!----------------------------------------------------------------------
-   !!                   Dummy Module                 No LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_dif          ! Empty routine
-   END SUBROUTINE lim_thd_dif
-#endif
-   !!======================================================================
-END MODULE limthd_dif
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limthd_ent.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limthd_ent.F90	(revision 3937)
+++ 	(revision )
@@ -1,708 +1,0 @@
-MODULE limthd_ent
-   !!======================================================================
-   !!                       ***  MODULE limthd_ent   ***
-   !!                  Redistribution of Enthalpy in the ice
-   !!                        on the new vertical grid
-   !!                       after vertical growth/decay
-   !!======================================================================
-   !! History :  LIM  ! 2003-05 (M. Vancoppenolle) Original code in 1D
-   !!                 ! 2005-07 (M. Vancoppenolle) 3D version 
-   !!                 ! 2006-11 (X. Fettweis) Vectorized 
-   !!            3.0  ! 2008-03 (M. Vancoppenolle) Energy conservation and clean code
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd_ent : ice redistribution of enthalpy
-   !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE dom_oce          ! domain variables
-   USE domain           !
-   USE phycst           ! physical constants
-   USE ice              ! LIM variables
-   USE par_ice          ! LIM parameters
-   USE thd_ice          ! LIM thermodynamics
-   USE limvar           ! LIM variables
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE lib_fortran      ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_ent         ! called by lim_thd
-
-   REAL(wp) ::   epsi20 = 1e-20_wp   ! constant values
-   REAL(wp) ::   epsi13 = 1e-13_wp   !
-   REAL(wp) ::   epsi10 = 1e-10_wp   !
-   REAL(wp) ::   epsi06 = 1e-06_wp   !
-   REAL(wp) ::   zzero  = 0._wp      !
-   REAL(wp) ::   zone   = 1._wp      !
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limthd_ent.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-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
-      !!
-      !! References : Bitz & Lipscomb, JGR 99; Vancoppenolle et al., GRL, 2005
-      !!-------------------------------------------------------------------
-      INTEGER , INTENT(in) ::   kideb, kiut   ! Start/End point on which the  the computation is applied
-      INTEGER , INTENT(in) ::   jl            ! Thickness cateogry number
-
-      INTEGER ::   ji,jk   !  dummy loop indices
-      INTEGER ::   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
-
-
-      REAL(wp) :: &
-         ztmelts        ,   &  ! ice melting point
-         zqsnic         ,   &  ! enthalpy of snow ice layer
-         zhsnow         ,   &  ! temporary snow thickness variable
-         zswitch        ,   &  ! dummy switch argument
-         zfac1          ,   &  ! dummy factor
-         zfac2          ,   &  ! dummy factor
-         ztform         ,   &  !: bottom formation temperature
-         zaaa           ,   &  !: dummy factor
-         zbbb           ,   &  !: dummy factor
-         zccc           ,   &  !: dummy factor
-         zdiscrim              !: dummy factor
-
-      INTEGER, POINTER, DIMENSION(:) ::   snswi     !  snow switch
-      INTEGER, POINTER, DIMENSION(:) ::   nbot0     !  old layer bottom index
-      INTEGER, POINTER, DIMENSION(:) ::   icsuind   !  ice surface index
-      INTEGER, POINTER, DIMENSION(:) ::   icsuswi   !  ice surface switch
-      INTEGER, POINTER, DIMENSION(:) ::   icboind   !  ice bottom index
-      INTEGER, POINTER, DIMENSION(:) ::   icboswi   !  ice bottom switch
-      INTEGER, POINTER, DIMENSION(:) ::   snicind   !  snow ice index
-      INTEGER, POINTER, DIMENSION(:) ::   snicswi   !  snow ice switch
-      INTEGER, POINTER, DIMENSION(:) ::   snind     !  snow index
-      !
-      REAL(wp), POINTER, DIMENSION(:) ::   zh_i   ! thickness of an ice layer
-      REAL(wp), POINTER, DIMENSION(:) ::   zh_s          ! thickness of a snow layer
-      REAL(wp), POINTER, DIMENSION(:) ::   zqsnow        ! enthalpy of the snow put in snow ice 	
-      REAL(wp), POINTER, DIMENSION(:) ::   zdeltah       ! temporary variable
-      REAL(wp), POINTER, DIMENSION(:) ::   zqti_in, zqts_in
-      REAL(wp), POINTER, DIMENSION(:) ::   zqti_fin, zqts_fin
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zm0       !  old layer-system vertical cotes 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   qm0       !  old layer-system heat content 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   z_s       !  new snow system vertical cotes 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   z_i       !  new ice system vertical cotes 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zthick0   !  old ice thickness 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zhl0      ! old and new layer thicknesses 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zrl01
-      !!-------------------------------------------------------------------
-
-      CALL wrk_alloc( jpij, snswi, nbot0, icsuind, icsuswi, icboind, icboswi, snicind, snicswi, snind )   ! integer
-      CALL wrk_alloc( jpij, zh_i, zh_s, zqsnow, zdeltah, zqti_in, zqts_in, zqti_fin, zqts_fin )           ! real
-      CALL wrk_alloc( jpij,jkmax+4, zm0, qm0, z_s, z_i, zthick0, zhl0, kjstart = 0 )
-      CALL wrk_alloc( jkmax+4,jkmax+4, zrl01, kistart = 0, kjstart = 0 )
-
-      zthick0(:,:) = 0._wp
-      zm0    (:,:) = 0._wp
-      qm0    (:,:) = 0._wp
-      zrl01  (:,:) = 0._wp
-      zhl0   (:,:) = 0._wp
-      z_i    (:,:) = 0._wp
-      z_s    (:,:) = 0._wp
-
-      !
-      !------------------------------------------------------------------------------|
-      !  1) Grid                                                                     |
-      !------------------------------------------------------------------------------|
-      nlays0 = nlay_s
-      nlayi0 = nlay_i
-
-      DO ji = kideb, kiut
-         zh_i(ji) = old_ht_i_b(ji) / REAL( nlay_i ) 
-         zh_s(ji) = old_ht_s_b(ji) / REAL( nlay_s )
-      END DO
-
-      !
-      !------------------------------------------------------------------------------|
-      !  2) Switches                                                                 |
-      !------------------------------------------------------------------------------|
-      ! 2.1 snind(ji), snswi(ji)
-      ! snow surface behaviour : computation of snind(ji)-snswi(ji)
-      ! snind(ji) : index which equals 
-      ! 	 0 if snow is accumulating
-      ! 	 1 if 1st layer is melting
-      ! 	 2 if 2nd layer is melting ...
-      DO ji = kideb, kiut
-         snind  (ji) = 0
-         zdeltah(ji) = 0._wp
-      ENDDO !ji
-
-      DO jk = 1, nlays0
-         DO ji = kideb, kiut
-            snind(ji)  = jk        *      NINT(MAX(0.0,SIGN(1.0,-dh_s_tot(ji)-zdeltah(ji)))) &
-               + snind(ji) * (1 - NINT(MAX(0.0,SIGN(1.0,-dh_s_tot(ji)-zdeltah(ji)))))
-            zdeltah(ji)= zdeltah(ji) + zh_s(ji)
-         END DO ! ji
-      END DO ! jk
-
-      ! snswi(ji) : switch which value equals 1 if snow melts
-      !				   0 if not
-      DO ji = kideb, kiut
-         snswi(ji)     = MAX(0,NINT(-dh_s_tot(ji)/MAX(epsi20,ABS(dh_s_tot(ji)))))
-      END DO ! ji
-
-      ! 2.2 icsuind(ji), icsuswi(ji)
-      ! ice surface behaviour : computation of icsuind(ji)-icsuswi(ji)
-      ! icsuind(ji) : index which equals
-      !	   0 if nothing happens at the surface
-      !	   1 if first layer is melting
-      !	   2 if 2nd layer is reached by melt ...
-      DO ji = kideb, kiut
-         icsuind(ji) = 0
-         zdeltah(ji) = 0._wp
-      END DO !ji
-      DO jk = 1, nlayi0
-         DO ji = kideb, kiut
-            icsuind(ji) = jk          *      NINT(MAX(0.0,SIGN(1.0,-dh_i_surf(ji)-zdeltah(ji)))) &
-               + icsuind(ji) * (1 - NINT(MAX(0.0,SIGN(1.0,-dh_i_surf(ji)-zdeltah(ji)))))
-            zdeltah(ji) = zdeltah(ji) + zh_i(ji)
-         END DO ! ji
-      ENDDO !jk
-
-      ! icsuswi(ji) : switch which equals 
-      ! 	   1 if ice melts at the surface
-      ! 	   0 if not
-      DO ji = kideb, kiut
-         icsuswi(ji)  = MAX(0,NINT(-dh_i_surf(ji)/MAX(epsi20 , ABS(dh_i_surf(ji)) ) ) )
-      ENDDO
-
-      ! 2.3 icboind(ji), icboswi(ji)
-      ! ice bottom behaviour : computation of icboind(ji)-icboswi(ji)
-      ! icboind(ji) : index which equals
-      ! 	   0 if accretion is on the way
-      ! 	   1 if last layer has started to melt
-      ! 	   2 if penultiem layer is melting ... and so on
-      !            N+1 if all layers melt and that snow transforms into ice
-      DO ji = kideb, kiut 
-         icboind(ji) = 0
-         zdeltah(ji) = 0._wp
-      END DO
-      DO jk = nlayi0, 1, -1
-         DO ji = kideb, kiut
-            icboind(ji) = (nlayi0+1-jk) *      NINT(MAX(0.0,SIGN(1.0,-dh_i_bott(ji)-zdeltah(ji)))) &
-               &          + icboind(ji) * (1 - NINT(MAX(0.0,SIGN(1.0,-dh_i_bott(ji)-zdeltah(ji))))) 
-            zdeltah(ji) = zdeltah(ji) + zh_i(ji)
-         END DO
-      END DO
-
-      DO ji = kideb, kiut
-         ! case of total ablation with remaining snow
-         IF ( ( ht_i_b(ji) .GT. epsi20 ) .AND. &
-            ( ht_i_b(ji) - dh_snowice(ji) .LT. epsi20 ) ) icboind(ji) = nlay_i + 1
-      END DO
-
-      ! icboswi(ji) : switch which equals 
-      ! 	   1 if ice accretion is on the way
-      ! 	   0 if ablation is on the way
-      DO ji = kideb, kiut 
-         icboswi(ji) = MAX(0,NINT(dh_i_bott(ji) / MAX(epsi20,ABS(dh_i_bott(ji)))))
-      END DO
-
-      ! 2.4 snicind(ji), snicswi(ji)
-      ! snow ice formation : calcul de snicind(ji)-snicswi(ji)
-      ! snicind(ji) : index which equals 
-      ! 	   0 if no snow-ice forms
-      ! 	   1 if last layer of snow has started to melt
-      ! 	   2 if penultiem layer ...
-      DO ji = kideb, kiut
-         snicind(ji) = 0
-         zdeltah(ji) = 0._wp
-      END DO
-      DO jk = nlays0, 1, -1
-         DO ji = kideb, kiut
-            snicind(ji) = (nlays0+1-jk) &
-               *      NINT(MAX(0.0,SIGN(1.0,dh_snowice(ji)-zdeltah(ji)))) + snicind(ji)   &
-               * (1 - NINT(MAX(0.0,SIGN(1.0,dh_snowice(ji)-zdeltah(ji)))))
-            zdeltah(ji) = zdeltah(ji) + zh_s(ji)
-         END DO
-      END DO
-
-      ! snicswi(ji) : switch which equals 
-      ! 	   1 if snow-ice forms
-      ! 	   0 if not
-      DO ji = kideb, kiut
-         snicswi(ji)   = MAX(0,NINT(dh_snowice(ji)/MAX(epsi20,ABS(dh_snowice(ji)))))
-      ENDDO
-
-      !
-      !------------------------------------------------------------------------------|
-      !  3) Snow redistribution                                                      |
-      !------------------------------------------------------------------------------|
-      !
-      !-------------
-      ! Old profile
-      !-------------
-
-      ! by 'old', it is meant that layers coming from accretion are included, 
-      ! and that interfacial layers which were partly melted are reduced 
-
-      ! indexes of the vectors
-      !------------------------
-      ntop0    =  1
-      maxnbot0 =  0
-
-      DO ji = kideb, kiut
-         nbot0(ji) =  nlays0  + 1 - snind(ji) + ( 1 - snicind(ji) ) * snicswi(ji)
-         ! cotes of the top of the layers
-         zm0(ji,0) =  0._wp
-         maxnbot0 =  MAX ( maxnbot0 , nbot0(ji) )
-      END DO
-      IF( lk_mpp )   CALL mpp_max( maxnbot0, kcom=ncomm_ice )
-
-      DO jk = 1, maxnbot0
-         DO ji = kideb, kiut
-            !change
-            limsum = ( 1 - snswi(ji) ) * ( jk - 1 ) + snswi(ji) * ( jk + snind(ji) - 1 )
-            limsum = MIN( limsum , nlay_s )
-            zm0(ji,jk) =  dh_s_tot(ji) + zh_s(ji) * REAL( limsum )
-         END DO
-      END DO
-
-      DO ji = kideb, kiut
-         zm0(ji,nbot0(ji)) =  dh_s_tot(ji) - REAL( snicswi(ji) ) * dh_snowice(ji) + zh_s(ji) * REAL( nlays0 )
-         zm0(ji,1)         =  dh_s_tot(ji) * REAL( 1 - snswi(ji) ) + REAL( snswi(ji) ) * zm0(ji,1)
-      END DO
-
-      DO jk = ntop0, maxnbot0
-         DO ji = kideb, kiut
-            zthick0(ji,jk)  =  zm0(ji,jk) - zm0(ji,jk-1)            ! layer thickness
-         END DO
-      END DO
-
-      zqts_in(:) = 0._wp
-
-      DO ji = kideb, kiut         ! layer heat content
-         qm0    (ji,1) =  rhosn * (  cpic * ( rtt - REAL( 1 - snswi(ji) ) * tatm_ice_1d(ji)        &
-            &                                         - REAL( snswi(ji) ) * t_s_b      (ji,1)  )   &
-            &                      + lfus  ) * zthick0(ji,1)
-         zqts_in(ji)   =  zqts_in(ji) + qm0(ji,1) 
-      END DO
-
-      DO jk = 2, maxnbot0
-         DO ji = kideb, kiut
-            limsum      = ( 1 - snswi(ji) ) * ( jk - 1 ) + snswi(ji) * ( jk + snind(ji) - 1 )
-            limsum      = MIN( limsum , nlay_s )
-            qm0(ji,jk)  = rhosn * ( cpic * ( rtt - t_s_b(ji,limsum) ) + lfus ) * zthick0(ji,jk)
-            zswitch = 1.0 - MAX (0.0, SIGN ( 1.0, - ht_s_b(ji) ) )
-            zqts_in(ji) = zqts_in(ji) + REAL( 1 - snswi(ji) ) * qm0(ji,jk) * zswitch
-         END DO ! jk
-      END DO ! ji
-
-      !------------------------------------------------
-      ! Energy given by the snow in snow-ice formation
-      !------------------------------------------------
-      ! zqsnow, enthalpy of the flooded snow
-      DO ji = kideb, kiut
-         zqsnow (ji) =  rhosn * lfus
-         zdeltah(ji) =  0._wp
-      END DO
-
-      DO jk =  nlays0, 1, -1
-         DO ji = kideb, kiut
-            zhsnow =  MAX( 0._wp , dh_snowice(ji)-zdeltah(ji) )
-            zqsnow (ji) =  zqsnow (ji) + rhosn*cpic*(rtt-t_s_b(ji,jk))
-            zdeltah(ji) =  zdeltah(ji) + zh_s(ji)
-         END DO
-      END DO
-
-      DO ji = kideb, kiut
-         zqsnow(ji) = zqsnow(ji) * dh_snowice(ji)
-      END DO
-
-      !------------------
-      ! new snow profile
-      !------------------
-
-      !--------------
-      ! Vector index   
-      !--------------
-      ntop1 =  1
-      nbot1 =  nlay_s
-
-      !-------------------
-      ! Layer coordinates 
-      !-------------------
-      DO ji = kideb, kiut
-         zh_s(ji)  = ht_s_b(ji) / REAL( nlay_s )
-         z_s(ji,0) =  0._wp
-      ENDDO
-
-      DO jk = 1, nlay_s
-         DO ji = kideb, kiut
-            z_s(ji,jk) =  zh_s(ji) * REAL( jk )
-         END DO
-      END DO
-
-      !-----------------
-      ! Layer thickness
-      !-----------------
-      DO layer0 = ntop0, maxnbot0
-         DO ji = kideb, kiut
-            zhl0(ji,layer0) = zm0(ji,layer0) - zm0(ji,layer0-1)
-         END DO
-      END DO
-
-      DO layer1 = ntop1, nbot1
-         DO ji = kideb, kiut
-            q_s_b(ji,layer1) = 0._wp
-         END DO
-      END DO
-
-      !----------------
-      ! Weight factors
-      !----------------
-      DO layer0 = ntop0, maxnbot0
-         DO layer1 = ntop1, nbot1
-            DO ji = kideb, kiut
-               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,REAL(nbot0(ji)-layer0)))
-            END DO
-         END DO
-      END DO
-
-      ! Heat conservation
-      zqts_fin(:) = 0._wp
-      DO jk = 1, nlay_s
-         DO ji = kideb, kiut
-            zqts_fin(ji) = zqts_fin(ji) + q_s_b(ji,jk)
-         END DO
-      END DO
-
-      IF ( con_i ) 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_s
-         DO ji = kideb, kiut
-            q_s_b(ji,jk) = q_s_b(ji,jk) / MAX( zh_s(ji) , epsi20 )
-         END DO !ji
-      END DO !jk  
-
-      !---------------------
-      ! Recover temperature
-      !---------------------
-      zfac1 = 1. / ( rhosn * cpic )
-      zfac2 = lfus / cpic  
-      DO jk = 1, nlay_s
-         DO ji = kideb, kiut
-            zswitch = MAX ( 0.0 , SIGN ( 1.0, - ht_s_b(ji) ) )
-            t_s_b(ji,jk) = rtt + ( 1.0 - zswitch ) * ( - zfac1 * q_s_b(ji,jk) + zfac2 )
-         END DO
-      END DO
-      !
-      !------------------------------------------------------------------------------|
-      !  4) Ice redistribution                                                       |
-      !------------------------------------------------------------------------------|
-      !
-      !-------------
-      ! OLD PROFILE 
-      !-------------
-
-      !----------------
-      ! Vector indexes
-      !----------------
-      ntop0    =  1
-      maxnbot0 =  0
-
-      DO ji = kideb, kiut
-         ! reference number of the bottommost layer
-         nbot0(ji) =  MAX( 1 ,  MIN( nlayi0 + ( 1 - icboind(ji) ) +        &
-            &                           ( 1 - icsuind(ji) ) * icsuswi(ji) + snicswi(ji) , nlay_i + 2 ) )
-         ! maximum reference number of the bottommost layer over all domain
-         maxnbot0 =  MAX( maxnbot0 , nbot0(ji) )
-      END DO
-
-      !-------------------------
-      ! Cotes of old ice layers
-      !-------------------------
-      zm0(:,0) =  0._wp
-
-      DO jk = 1, maxnbot0
-         DO ji = kideb, kiut
-            ! jk goes from 1 to nbot0
-            ! the ice layer number goes from 1 to nlay_i
-            ! limsum is the real ice layer number corresponding to present jk
-            limsum    =  ( (icsuswi(ji)*(icsuind(ji)+jk-1) + & 
-               (1-icsuswi(ji))*jk))*(1-snicswi(ji)) + (jk-1)*snicswi(ji)
-            zm0(ji,jk)=  REAL(icsuswi(ji))*dh_i_surf(ji) + REAL(snicswi(ji))*dh_snowice(ji) &
-               +  REAL(limsum) * zh_i(ji)
-         END DO
-      END DO
-
-      DO ji = kideb, kiut
-         zm0(ji,nbot0(ji)) =  REAL(icsuswi(ji))*dh_i_surf(ji) + REAL(snicswi(ji))*dh_snowice(ji) + dh_i_bott(ji) &
-            +  zh_i(ji) * REAL(nlayi0)
-         zm0(ji,1)         =  REAL(snicswi(ji))*dh_snowice(ji) + REAL(1-snicswi(ji))*zm0(ji,1)
-      END DO
-
-      !-----------------------------
-      ! Thickness of old ice layers
-      !-----------------------------
-      DO jk = ntop0, maxnbot0
-         DO ji = kideb, kiut
-            zthick0(ji,jk) =  zm0(ji,jk) - zm0(ji,jk-1)
-         END DO
-      END DO
-
-      !---------------------------
-      ! Inner layers heat content
-      !---------------------------
-      qm0(:,:) =  0.0
-      zqti_in(:) = 0.0
-
-      DO jk = ntop0, maxnbot0
-         DO ji = kideb, kiut
-            limsum =  MAX(1,MIN(snicswi(ji)*(jk-1) + icsuswi(ji)*(jk-1+icsuind(ji)) + &
-               (1-icsuswi(ji))*(1-snicswi(ji))*jk,nlay_i))
-            ztmelts = -tmut * s_i_b(ji,limsum) + rtt
-            qm0(ji,jk) = rhoic * ( cpic * (ztmelts-t_i_b(ji,limsum)) + lfus * ( 1.0-(ztmelts-rtt)/ &
-               MIN((t_i_b(ji,limsum)-rtt),-epsi20) ) - rcp*(ztmelts-rtt) ) &
-               * zthick0(ji,jk)
-         END DO
-      END DO
-
-      !----------------------------
-      ! Bottom layers heat content
-      !----------------------------
-      DO ji = kideb, kiut        
-         ztmelts    = REAL( 1 - icboswi(ji) ) * (-tmut * s_i_b  (ji,nlayi0) )   &   ! case of melting ice
-            &       +     REAL( icboswi(ji) ) * (-tmut * s_i_new(ji)        )   &   ! case of forming ice
-            &       + rtt                                                         ! in Kelvin
-
-         ! bottom formation temperature
-         ztform = t_i_b(ji,nlay_i)
-         IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) ztform = t_bo_b(ji)
-         qm0(ji,nbot0(ji)) = REAL( 1 - icboswi(ji) )*qm0(ji,nbot0(ji))             &   ! case of melting ice
-            &              + REAL( icboswi(ji) ) * rhoic * ( cpic*(ztmelts-ztform)       &   ! case of forming ice
-            + lfus *( 1.0-(ztmelts-rtt) / MIN ( (ztform-rtt) , - epsi10 ) )      & 
-            - rcp*(ztmelts-rtt) ) * zthick0(ji,nbot0(ji)  )
-      END DO
-
-      !-----------------------------
-      ! Snow ice layer heat content
-      !-----------------------------
-      DO ji = kideb, kiut
-         ! energy of the flooding seawater
-         zqsnic = rau0 * rcp * ( rtt - t_bo_b(ji) ) * dh_snowice(ji) * &
-            (rhoic - rhosn) / rhoic * REAL(snicswi(ji)) ! generally positive
-         ! Heat conservation diagnostic
-         qt_i_in(ji,jl) = qt_i_in(ji,jl) + zqsnic 
-
-         qldif_1d(ji)   = qldif_1d(ji) + zqsnic * a_i_b(ji)
-
-         ! enthalpy of the newly formed snow-ice layer
-         ! = enthalpy of snow + enthalpy of frozen water
-         zqsnic         =  zqsnow(ji) + zqsnic
-         qm0(ji,1)      =  REAL(snicswi(ji)) * zqsnic + REAL( 1 - snicswi(ji) ) * qm0(ji,1)
-
-         zji = MOD( npb(ji) - 1, jpi ) + 1
-         zjj = ( npb(ji) - 1 ) / jpi + 1
-         IF ( (zji.eq.jiindx).AND.(zjj.eq.jjindx) ) THEN
-            !clemclem
-            WRITE(numout,*) 'lim_thd_ent : qldif = ', qldif_1d(ji)
-            !clemclem
-         ENDIF
-
-      END DO ! ji
-
-      DO jk = ntop0, maxnbot0
-         DO ji = kideb, kiut
-            ! Heat conservation
-            zqti_in(ji) = zqti_in(ji) + qm0(ji,jk) * MAX( 0.0 , SIGN(1.0,ht_i_b(ji)-epsi06) ) &
-               &                                   * MAX( 0.0 , SIGN( 1. , REAL(nbot0(ji) - jk) ) )
-         END DO
-      END DO
-
-      !-------------
-      ! NEW PROFILE
-      !-------------
-
-      !---------------
-      ! Vectors index
-      !---------------
-      ntop1 =  1 
-      nbot1 =  nlay_i
-
-      !------------------
-      ! Layers thickness 
-      !------------------
-      DO ji = kideb, kiut
-         zh_i(ji) = ht_i_b(ji) / REAL( nlay_i )
-      ENDDO
-
-      !-------------
-      ! Layer cotes      
-      !-------------
-      z_i(:,0) =  0._wp
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            z_i(ji,jk) =  zh_i(ji) * jk
-         END DO
-      END DO
-
-      !--thicknesses of the layers
-      DO layer0 = ntop0, maxnbot0
-         DO ji = kideb, kiut
-            zhl0(ji,layer0) = zm0(ji,layer0) - zm0(ji,layer0-1)   ! thicknesses of the layers
-         END DO
-      END DO
-
-      !------------------------
-      ! Weights for relayering
-      !------------------------
-      q_i_b(:,:) = 0._wp
-      DO layer0 = ntop0, maxnbot0
-         DO layer1 = ntop1, nbot1
-            DO ji = kideb, kiut
-               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)-epsi06)) &
-                  * MAX(0.0,SIGN(1.0,REAL(nbot0(ji)-layer0)))
-            END DO
-         END DO
-      END DO
-
-      !-------------------------
-      ! Heat conservation check
-      !-------------------------
-      zqti_fin(:) = 0._wp
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            zqti_fin(ji) = zqti_fin(ji) + q_i_b(ji,jk)
-         END DO
-      END DO
-      !
-      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) , epsi20 )
-         END DO !ji
-      END DO !jk  
-
-      ! Heat conservation
-      zqti_fin(:) = 0.0
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            zqti_fin(ji) = zqti_fin(ji) + q_i_b(ji,jk) * zh_i(ji)
-         END DO
-      END DO
-
-      !
-      !------------------------------------------------------------------------------|
-      !  5) Update salinity and recover temperature                                  |
-      !------------------------------------------------------------------------------|
-      !
-      ! Update salinity (basal entrapment, snow ice formation)
-      DO ji = kideb, kiut
-         sm_i_b(ji) = sm_i_b(ji) + dsm_i_se_1d(ji) + dsm_i_si_1d(ji)
-      END DO !ji
-
-      ! Recover temperature
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            ztmelts    =  -tmut*s_i_b(ji,jk) + rtt
-            !Conversion q(S,T) -> T (second order equation)
-            zaaa         =  cpic
-            zbbb         =  ( rcp - cpic ) * ( ztmelts - rtt ) + q_i_b(ji,jk) / rhoic - lfus
-            zccc         =  lfus * ( ztmelts - rtt )
-            zdiscrim     =  SQRT( MAX(zbbb*zbbb - 4.0*zaaa*zccc,0.0) )
-            t_i_b(ji,jk) =  rtt - ( zbbb + zdiscrim ) / ( 2.0 *zaaa )
-         END DO !ji
-
-      END DO !jk
-      !
-      CALL wrk_dealloc( jpij, snswi, nbot0, icsuind, icsuswi, icboind, icboswi, snicind, snicswi, snind )   ! integer
-      CALL wrk_dealloc( jpij, zh_i, zh_s, zqsnow, zdeltah, zqti_in, zqts_in, zqti_fin, zqts_fin )           ! real
-      CALL wrk_dealloc( jpij,jkmax+4, zm0, qm0, z_s, z_i, zthick0, zhl0, kjstart = 0 )
-      CALL wrk_dealloc( jkmax+4,jkmax+4, zrl01, kistart = 0, kjstart = 0 )
-      !
-   END SUBROUTINE lim_thd_ent
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                               NO  LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_ent          ! Empty routine
-   END SUBROUTINE lim_thd_ent
-#endif
-
-   !!======================================================================
-END MODULE limthd_ent
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limthd_lac.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limthd_lac.F90	(revision 3937)
+++ 	(revision )
@@ -1,722 +1,0 @@
-MODULE limthd_lac
-   !!======================================================================
-   !!                       ***  MODULE limthd_lac   ***
-   !!                lateral thermodynamic growth of the ice 
-   !!======================================================================
-   !! History :  LIM  ! 2005-12 (M. Vancoppenolle)  Original code
-   !!             -   ! 2006-01 (M. Vancoppenolle)  add ITD
-   !!            3.0  ! 2007-07 (M. Vancoppenolle)  Mass and energy conservation tested
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_lat_acr    : lateral accretion of ice
-   !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE dom_oce          ! domain variables
-   USE phycst           ! physical constants
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE sbc_ice          ! Surface boundary condition: ice fields
-   USE thd_ice          ! LIM thermodynamics
-   USE dom_ice          ! LIM domain
-   USE par_ice          ! LIM parameters
-   USE ice              ! LIM variables
-   USE limtab           ! LIM 2D <==> 1D
-   USE limcons          ! LIM conservation
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE lib_fortran      ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC lim_thd_lac     ! called by lim_thd
-
-   REAL(wp) ::   epsi20 = 1e-20_wp   ! constant values
-   REAL(wp) ::   epsi13 = 1e-13_wp   !
-   REAL(wp) ::   epsi11 = 1e-11_wp   !
-   REAL(wp) ::   epsi10 = 1e-10_wp   !
-   REAL(wp) ::   epsi06 = 1e-06_wp   !
-   REAL(wp) ::   epsi03 = 1e-03_wp   !
-   REAL(wp) ::   zzero  = 0._wp      !
-   REAL(wp) ::   zone   = 1._wp      !
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limthd_lac.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/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(:,:)      
-      !!------------------------------------------------------------------------
-      INTEGER ::   ji,jj,jk,jl,jm   ! dummy loop indices
-      INTEGER ::   layer, nbpac     ! local integers 
-      INTEGER ::   zji, zjj, iter   !   -       -
-      REAL(wp)  ::   ztmelts, zdv, zqold, zfrazb, zweight, zalphai, zindb, zde  ! local scalars
-      REAL(wp) ::   zgamafr, zvfrx, zvgx, ztaux, ztwogp, zf , zhicol_new        !   -      -
-      REAL(wp) ::   ztenagm, zvfry, zvgy, ztauy, zvrel2, zfp, zsqcd , zhicrit   !   -      -
-      LOGICAL  ::   iterate_frazil   ! iterate frazil ice collection thickness
-      CHARACTER (len = 15) :: fieldid
-      !
-      INTEGER , POINTER, DIMENSION(:) ::   zcatac      ! indexes of categories where new ice grows
-      REAL(wp), POINTER, DIMENSION(:) ::   zswinew     ! switch for new ice or not
-
-      REAL(wp), POINTER, DIMENSION(:) ::   zv_newice   ! volume of accreted ice
-      REAL(wp), POINTER, DIMENSION(:) ::   za_newice   ! fractional area of accreted ice
-      REAL(wp), POINTER, DIMENSION(:) ::   zh_newice   ! thickness of accreted ice
-      REAL(wp), POINTER, DIMENSION(:) ::   ze_newice   ! heat content of accreted ice
-      REAL(wp), POINTER, DIMENSION(:) ::   zs_newice   ! salinity of accreted ice
-      REAL(wp), POINTER, DIMENSION(:) ::   zo_newice   ! age of accreted ice
-      REAL(wp), POINTER, DIMENSION(:) ::   zdv_res     ! residual volume in case of excessive heat budget
-      REAL(wp), POINTER, DIMENSION(:) ::   zda_res     ! residual area in case of excessive heat budget
-      REAL(wp), POINTER, DIMENSION(:) ::   zat_i_ac    ! total ice fraction    
-      REAL(wp), POINTER, DIMENSION(:) ::   zat_i_lev   ! total ice fraction for level ice only (type 1)   
-      REAL(wp), POINTER, DIMENSION(:) ::   zdh_frazb   ! accretion of frazil ice at the ice bottom
-      REAL(wp), POINTER, DIMENSION(:) ::   zvrel_ac    ! relative ice / frazil velocity (1D vector)
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zhice_old   ! previous ice thickness
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zdummy      ! dummy thickness of new ice 
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zdhicbot    ! thickness of new ice which is accreted vertically
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zv_old      ! old volume of ice in category jl
-      REAL(wp), POINTER, DIMENSION(:,:) ::   za_old      ! old area of ice in category jl
-      REAL(wp), POINTER, DIMENSION(:,:) ::   za_i_ac     ! 1-D version of a_i
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zv_i_ac     ! 1-D version of v_i
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zoa_i_ac    ! 1-D version of oa_i
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zsmv_i_ac   ! 1-D version of smv_i
-
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ze_i_ac   !: 1-D version of e_i
-
-      REAL(wp), POINTER, DIMENSION(:) ::   zqbgow    ! heat budget of the open water (negative)
-      REAL(wp), POINTER, DIMENSION(:) ::   zdhex     ! excessively thick accreted sea ice (hlead-hice)
-
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zqm0      ! old layer-system heat content
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zthick0   ! old ice thickness
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vt_i_init, vt_i_final   ! ice volume summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vt_s_init, vt_s_final   !  snow volume summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:) ::   et_i_init, et_i_final   !  ice energy summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:) ::   et_s_init               !  snow energy summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zvrel                   ! relative ice / frazil velocity
-      !!-----------------------------------------------------------------------!
-
-      CALL wrk_alloc( jpij, zcatac )   ! integer
-      CALL wrk_alloc( jpij, zswinew, zv_newice, za_newice, zh_newice, ze_newice, zs_newice, zo_newice )
-      CALL wrk_alloc( jpij, zdv_res, zda_res, zat_i_ac, zat_i_lev, zdh_frazb, zvrel_ac, zqbgow, zdhex )
-      CALL wrk_alloc( jpij,jpl, zhice_old, zdummy, zdhicbot, zv_old, za_old, za_i_ac, zv_i_ac, zoa_i_ac, zsmv_i_ac )
-      CALL wrk_alloc( jpij,jkmax,jpl, ze_i_ac )
-      CALL wrk_alloc( jpij,jkmax+1,jpl, zqm0, zthick0 )
-      CALL wrk_alloc( jpi,jpj, vt_i_init, vt_i_final, vt_s_init, vt_s_final, et_i_init, et_i_final, et_s_init, zvrel )
-
-      et_i_init(:,:) = 0._wp
-      et_s_init(:,:) = 0._wp
-      vt_i_init(:,:) = 0._wp
-      vt_s_init(:,:) = 0._wp
-
-      !------------------------------------------------------------------------------!
-      ! 1) Conservation check and changes in each ice category
-      !------------------------------------------------------------------------------!
-      IF ( con_i ) THEN
-         CALL lim_column_sum (jpl, v_i, vt_i_init)
-         CALL lim_column_sum (jpl, v_s, vt_s_init)
-         CALL lim_column_sum_energy (jpl, nlay_i, e_i, et_i_init)
-         CALL lim_column_sum (jpl,   e_s(:,:,1,:) , et_s_init)
-      ENDIF
-
-      !------------------------------------------------------------------------------|
-      ! 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) ,  epsi10 ) * REAL( 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 
-      hicol(:,:) = hiccrit(1)
-
-      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         = ( utau_ice(ji-1,jj  ) * tmu(ji-1,jj  ) &
-                     &          +   utau_ice(ji  ,jj  ) * tmu(ji  ,jj  ) ) / 2.0
-                  ztauy         = ( vtau_ice(ji  ,jj-1) * tmv(ji  ,jj-1) &
-                     &          +   vtau_ice(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,epsi10)
-                  zvfry         = zgamafr * zsqcd * ztauy / MAX(ztenagm,epsi10)
-
-                  !-------------------
-                  ! 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.jiindx).AND.(jj.eq.jjindx) ) THEN
-                  jiindex_1d = nbpac
-               ENDIF
-            ENDIF
-         END DO
-      END DO
-
-      IF( ln_nicep ) 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) )
-         CALL tab_2d_1d( nbpac, rdmicif_1d  (1:nbpac)   , rdmicif, jpi, jpj, npac(1:nbpac) ) !martin
-
-         !------------------------------------------------------------------------------!
-         ! 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_m(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)
-            !
-!clem@mv            rdmicif_1d(ji) = rdmicif_1d(ji) + zv_newice(ji) * rhoic  !martin
-         END DO
-
-         !---------------------------------
-         ! Salt flux due to new ice growth
-         !---------------------------------
-!clem@mv         IF ( ( num_sal .EQ. 4 ) ) THEN 
-!clem@mv            DO ji = 1, nbpac
-!clem@mv               ! IOVINO
-!clem@mv               fseqv_1d(ji)   = fseqv_1d(ji) - bulk_sal * rhoic *  &
-!clem@mv                  zv_newice(ji) / rdt_ice
-!clem@mv            END DO
-!clem@mv         ELSE
-!clem@mv            DO ji = 1, nbpac
-!clem@mv               ! IOVINO
-!clem@mv               fseqv_1d(ji)   = fseqv_1d(ji)  - zs_newice(ji) * rhoic *   &
-!clem@mv                  zv_newice(ji) / rdt_ice
-!clem@mv            END DO ! ji
-!clem@mv         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. ( amax - zat_i_ac(ji) ) ) THEN
-               zda_res(ji)    = za_newice(ji) - ( amax - 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._wp
-         DO jl = 1, jpl
-            DO ji = 1, nbpac
-               IF(  hi_max   (jl-1)  <  zh_newice(ji)   .AND.   &
-                  & zh_newice(ji)    <= hi_max   (jl)         ) THEN
-                  za_i_ac (ji,jl) = za_i_ac (ji,jl) + za_newice(ji)
-                  zv_i_ac (ji,jl) = zv_i_ac (ji,jl) + zv_newice(ji)
-                  zat_i_ac(ji)    = zat_i_ac(ji)    + za_i_ac  (ji,jl)
-                  zcatac  (ji)    = jl
-               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 = 1._wp - MAX( 0._wp , SIGN( 1._wp , -za_old(ji,jl) + epsi10 ) )             ! zindb=1 if ice =0 otherwise
-            zhice_old(ji,jl) = zv_old(ji,jl) / MAX( za_old(ji,jl) , epsi10 ) * zindb  ! old ice thickness
-            zdhex    (ji) = MAX( 0._wp , zh_newice(ji) - zhice_old(ji,jl) )           ! difference in thickness
-            zswinew  (ji) = MAX( 0._wp , SIGN( 1._wp , - za_old(ji,jl) + epsi10 ) )   ! ice totally new in jl category
-         END DO
-
-         DO jk = 1, nlay_i
-            DO ji = 1, nbpac
-               jl = zcatac(ji)
-               zqold   = ze_i_ac(ji,jk,jl) ! [ J.m-3 ]
-               zalphai = MIN( zhice_old(ji,jl) * REAL( jk )     / REAL( nlay_i ), zh_newice(ji) )   &
-                  &    - MIN( zhice_old(ji,jl) * REAL( jk - 1 ) / REAL( nlay_i ), zh_newice(ji) )
-               ze_i_ac(ji,jk,jl) = zswinew(ji) * ze_newice(ji)                                     &
-                  + ( 1.0 - zswinew(ji) ) * ( za_old(ji,jl)  * zqold * zhice_old(ji,jl) / REAL( nlay_i )  &
-                  + za_newice(ji)  * ze_newice(ji) * zalphai                                       &
-                  + za_newice(ji)  * ze_newice(ji) * zdhex(ji) / REAL( nlay_i ) ) / ( ( zv_i_ac(ji,jl) ) / REAL( nlay_i ) )
-            END DO
-         END DO
-
-         !-----------------------------------------------
-         ! Add excessive volume of new ice at the bottom
-         !-----------------------------------------------
-         ! If the ice concentration exceeds 1, the remaining volume of new ice
-         ! is equally redistributed among all ice categories in which there is
-         ! ice
-
-         ! Fraction of level ice
-         jm = 1
-         zat_i_lev(:) = 0._wp
-
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
-            DO ji = 1, nbpac
-               zat_i_lev(ji) = zat_i_lev(ji) + za_i_ac(ji,jl) 
-            END DO
-         END DO
-
-         IF( ln_nicep ) WRITE(numout,*) ' zv_i_ac : ', zv_i_ac(jiindx, 1:jpl)
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
-            DO ji = 1, nbpac
-               zindb = MAX( 0._wp, SIGN( 1._wp , zdv_res(ji) ) )
-               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
-         END DO
-         IF( ln_nicep )   WRITE(numout,*) ' zv_i_ac : ', zv_i_ac(jiindx, 1:jpl)
-
-         !---------------------------------
-         ! Heat content - bottom accretion
-         !---------------------------------
-         jm = 1
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
-            DO ji = 1, nbpac
-               zindb =  1._wp - MAX( 0._wp , SIGN( 1._wp , - za_i_ac(ji,jl ) + epsi10 ) )       ! zindb=1 if ice =0 otherwise
-               zhice_old(ji,jl) = zv_i_ac(ji,jl) / MAX( za_i_ac(ji,jl) , epsi10 ) * zindb
-               zdhicbot (ji,jl) = zdv_res(ji)    / MAX( za_i_ac(ji,jl) , epsi10 ) * zindb    &
-                  &             +  zindb * zdh_frazb(ji)                               ! frazil ice may coalesce
-               zdummy(ji,jl)    = zv_i_ac(ji,jl)/MAX(za_i_ac(ji,jl),epsi10)*zindb      ! thickness of residual ice
-            END DO
-         END DO
-
-         ! old layers thicknesses and enthalpies
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
-            DO jk = 1, nlay_i
-               DO ji = 1, nbpac
-                  zthick0(ji,jk,jl) =  zhice_old(ji,jl) / REAL( nlay_i )
-                  zqm0   (ji,jk,jl) =  ze_i_ac(ji,jk,jl) * zthick0(ji,jk,jl)
-               END DO
-            END DO
-         END DO
-!!gm ???  why the previous do loop  if ocerwriten by the following one ?
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
-            DO ji = 1, nbpac
-               zthick0(ji,nlay_i+1,jl) =  zdhicbot(ji,jl)
-               zqm0   (ji,nlay_i+1,jl) =  ze_newice(ji) * zdhicbot(ji,jl)
-            END DO ! ji
-         END DO ! jl
-
-         ! Redistributing energy on the new grid
-         ze_i_ac(:,:,:) = 0._wp
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
-            DO jk = 1, nlay_i
-               DO layer = 1, nlay_i + 1
-                  DO ji = 1, nbpac
-                     zindb =  1._wp -  MAX( 0._wp , SIGN( 1._wp , - za_i_ac(ji,jl) + epsi10 ) ) 
-                     ! Redistributing energy on the new grid
-                     zweight = MAX (  MIN( zhice_old(ji,jl) * REAL( layer ), zdummy(ji,jl) * REAL( jk ) )   &
-                        &    - MAX( zhice_old(ji,jl) * REAL( layer - 1 ) , zdummy(ji,jl) * REAL( jk - 1 ) ) , 0._wp )   &
-                        &    /( MAX(REAL(nlay_i) * zthick0(ji,layer,jl),epsi10) ) * zindb
-                     ze_i_ac(ji,jk,jl) =  ze_i_ac(ji,jk,jl) + zweight * zqm0(ji,layer,jl)  
-                  END DO ! ji
-               END DO ! layer
-            END DO ! jk
-         END DO ! jl
-
-         DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
-            DO jk = 1, nlay_i
-               DO ji = 1, nbpac
-                  zindb =  1._wp -  MAX( 0._wp , SIGN( 1._wp , - zv_i_ac(ji,jl) + epsi10 ) ) 
-                  ze_i_ac(ji,jk,jl) = ze_i_ac(ji,jk,jl)   &
-                     &              / MAX( zv_i_ac(ji,jl) , epsi10) * za_i_ac(ji,jl) * REAL( nlay_i ) * zindb
-               END DO
-            END DO
-         END DO
-
-         !------------
-         ! Update age 
-         !------------
-         DO jl = 1, jpl
-            DO ji = 1, nbpac
-               zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - za_i_ac(ji,jl) + epsi10 ) )  ! 0 if no ice and 1 if yes
-               zoa_i_ac(ji,jl)  = za_old(ji,jl) * zoa_i_ac(ji,jl) / MAX( za_i_ac(ji,jl) , epsi10 ) * zindb   
-            END DO 
-         END DO   
-
-         !-----------------
-         ! Update salinity
-         !-----------------
-         IF(  num_sal == 2  .OR.  num_sal == 4  ) THEN
-            DO jl = 1, jpl
-               DO ji = 1, nbpac
-                  zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - zv_i_ac(ji,jl) + epsi10 ) )  ! 0 if no ice and 1 if yes
-                  zdv   = zv_i_ac(ji,jl) - zv_old(ji,jl)
-                  zsmv_i_ac(ji,jl) = ( zsmv_i_ac(ji,jl) + zdv * zs_newice(ji) ) * zindb
-               END DO
-            END DO   
-         ENDIF
-
-         !--------------------------------
-         ! Update mass/salt fluxes (clem)
-         !--------------------------------
-         DO jl = 1, jpl
-            DO ji = 1, nbpac
-               zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - zv_i_ac(ji,jl) + epsi10 ) )  ! 0 if no ice and 1 if yes
-               zdv   = zv_i_ac(ji,jl) - zv_old(ji,jl)
-               rdmicif_1d(ji) = rdmicif_1d(ji) + zdv * rhoic !* zindb
-               fseqv_1d(ji)   =   fseqv_1d(ji) - zdv * rhoic * zs_newice(ji) / rdt_ice * zindb
-           END DO
-         END DO
-
-         !------------------------------------------------------------------------------!
-         ! 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 == 2  .OR.  num_sal == 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
-         END DO
-         CALL tab_1d_2d( nbpac, fseqv , npac(1:nbpac), fseqv_1d  (1:nbpac) , jpi, jpj )
-         CALL tab_1d_2d( nbpac, rdmicif , npac(1:nbpac), rdmicif_1d  (1:nbpac) , jpi, jpj )
-         !
-      ENDIF ! nbpac > 0
-
-      !------------------------------------------------------------------------------!
-      ! 9) Change units for e_i
-      !------------------------------------------------------------------------------!    
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i          ! heat content in 10^9 Joules
-            e_i(:,:,jk,jl) = e_i(:,:,jk,jl) * area(:,:) * v_i(:,:,jl) / REAL( nlay_i )  / unit_fac 
-         END DO
-      END DO
-
-      !------------------------------------------------------------------------------|
-      ! 10) Conservation check and changes in each ice category
-      !------------------------------------------------------------------------------|
-      IF( con_i ) THEN 
-         CALL lim_column_sum (jpl,   v_i, vt_i_final)
-         fieldid = 'v_i, limthd_lac'
-         CALL lim_cons_check (vt_i_init, vt_i_final, 1.0e-6, fieldid) 
-         !
-         CALL lim_column_sum_energy(jpl, nlay_i, e_i, et_i_final)
-         fieldid = 'e_i, limthd_lac'
-         CALL lim_cons_check (et_i_final, et_i_final, 1.0e-3, fieldid) 
-         !
-         CALL lim_column_sum (jpl,   v_s, vt_s_final)
-         fieldid = 'v_s, limthd_lac'
-         CALL lim_cons_check (vt_s_init, vt_s_final, 1.0e-6, fieldid) 
-         !
-         !     CALL lim_column_sum (jpl,   e_s(:,:,1,:) , et_s_init)
-         !     fieldid = 'e_s, limthd_lac'
-         !     CALL lim_cons_check (et_s_init, et_s_final, 1.0e-3, fieldid) 
-         IF( ln_nicep ) THEN
-            WRITE(numout,*) ' vt_i_init : ', vt_i_init(jiindx,jjindx)
-            WRITE(numout,*) ' vt_i_final: ', vt_i_final(jiindx,jjindx)
-            WRITE(numout,*) ' et_i_init : ', et_i_init(jiindx,jjindx)
-            WRITE(numout,*) ' et_i_final: ', et_i_final(jiindx,jjindx)
-         ENDIF
-         !
-      ENDIF
-      !
-      CALL wrk_dealloc( jpij, zcatac )   ! integer
-      CALL wrk_dealloc( jpij, zswinew, zv_newice, za_newice, zh_newice, ze_newice, zs_newice, zo_newice )
-      CALL wrk_dealloc( jpij, zdv_res, zda_res, zat_i_ac, zat_i_lev, zdh_frazb, zvrel_ac, zqbgow, zdhex )
-      CALL wrk_dealloc( jpij,jpl, zhice_old, zdummy, zdhicbot, zv_old, za_old, za_i_ac, zv_i_ac, zoa_i_ac, zsmv_i_ac )
-      CALL wrk_dealloc( jpij,jkmax,jpl, ze_i_ac )
-      CALL wrk_dealloc( jpij,jkmax+1,jpl, zqm0, zthick0 )
-      CALL wrk_dealloc( jpi,jpj, vt_i_init, vt_i_final, vt_s_init, vt_s_final, et_i_init, et_i_final, et_s_init, zvrel )
-      !
-   END SUBROUTINE lim_thd_lac
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                               NO  LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_lac           ! Empty routine
-   END SUBROUTINE lim_thd_lac
-#endif
-
-   !!======================================================================
-END MODULE limthd_lac
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limthd_sal.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limthd_sal.F90	(revision 3937)
+++ 	(revision )
@@ -1,260 +1,0 @@
-MODULE limthd_sal
-   !!======================================================================
-   !!                       ***  MODULE limthd_sal ***
-   !! LIM-3 sea-ice :  computation of salinity variations in the ice
-   !!======================================================================
-   !! History :   -   ! 2003-05 (M. Vancoppenolle) UCL-ASTR first coding for LIM3-1D
-   !!            3.0  ! 2005-12 (M. Vancoppenolle) adapted to the 3-D version
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!---------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd_sal : salinity variations in the ice
-   !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE phycst           ! physical constants (ocean directory)
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE ice              ! LIM variables
-   USE par_ice          ! LIM parameters
-   USE thd_ice          ! LIM thermodynamics
-   USE limvar           ! LIM variables
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE lib_fortran      ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_sal        ! called by limthd module
-   PUBLIC   lim_thd_sal_init   ! called by iceini module
-
-   REAL(wp) ::   epsi20 = 1e-20_wp   ! constant values
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limthd_sal.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd_sal( kideb, kiut )
-      !!-------------------------------------------------------------------
-      !!                ***  ROUTINE lim_thd_sal  ***    
-      !!   
-      !! ** Purpose :   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]
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::  kideb, kiut   ! thickness category index
-      !
-      INTEGER  ::   ji, jk     ! dummy loop indices 
-      INTEGER  ::   zji, zjj   ! local integers
-      REAL(wp) ::   zsold, iflush, iaccrbo, igravdr, isnowic, i_ice_switch,  ztmelts   ! local scalars
-      REAL(wp) ::   zaaa, zbbb, zccc, zdiscrim   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:) ::   ze_init, zhiold, zsiold
-      !!---------------------------------------------------------------------
-
-      CALL wrk_alloc( jpij, ze_init, zhiold, zsiold )
-
-      !------------------------------------------------------------------------------|
-      ! 1) Constant salinity, constant in time                                       |
-      !------------------------------------------------------------------------------|
-!!gm comment: if num_sal = 1 s_i_b and sm_i_b can be set to bulk_sal one for all in the initialisation phase !!
-      IF( num_sal == 1 ) THEN
-         !
-         s_i_b  (kideb:kiut,1:nlay_i) =  bulk_sal 
-         sm_i_b (kideb:kiut)          =  bulk_sal
-         s_i_new(kideb:kiut)          =  bulk_sal
-        !
-      ENDIF
-
-      !------------------------------------------------------------------------------|
-      !  Module 2 : Constant salinity varying in time                                |
-      !------------------------------------------------------------------------------|
-
-      IF(  num_sal == 2  .OR.  num_sal == 4  ) THEN
-
-         !---------------------------------
-         ! Thickness at previous time step
-         !---------------------------------
-         DO ji = kideb, kiut
-            zhiold(ji) = ht_i_b(ji) - dh_i_bott(ji) - dh_snowice(ji) - dh_i_surf(ji)
-            zsiold(ji) = sm_i_b(ji)
-         END DO
-
-         !---------------------
-         ! Global heat content
-         !---------------------
-         ze_init(:)  =  0._wp
-         DO jk = 1, nlay_i
-            DO ji = kideb, kiut
-               ze_init(ji) = ze_init(ji) + q_i_b(ji,jk) * ht_i_b(ji) / REAL (nlay_i )
-            END DO
-         END DO
-
-         DO ji = kideb, kiut
-            !
-            ! Switches 
-            !----------
-            iflush       =         MAX( 0._wp , SIGN( 1.0 , t_su_b(ji) - rtt )        )    ! =1 if summer 
-            igravdr      =         MAX( 0._wp , SIGN( 1.0 , t_bo_b(ji) - t_su_b(ji) ) )    ! =1 if t_su < t_bo
-            iaccrbo      =         MAX( 0._wp , SIGN( 1.0 , dh_i_bott(ji) )           )    ! =1 if bottom accretion
-            i_ice_switch = 1._wp - MAX ( 0._wp , SIGN( 1._wp , - ht_i_b(ji) + 1.e-2 ) )
-            isnowic      = 1._wp - MAX ( 0._wp , SIGN( 1._wp , - dh_snowice(ji) ) ) * i_ice_switch   ! =1 if snow ice formation
-
-            !---------------------
-            ! Salinity tendencies
-            !---------------------
-            !                                   ! drainage by gravity drainage
-            dsm_i_gd_1d(ji) = - igravdr * MAX( sm_i_b(ji) - sal_G , 0._wp ) / time_G * rdt_ice 
-            !                                   ! drainage by flushing  
-            dsm_i_fl_1d(ji) = - iflush * MAX( sm_i_b(ji) - sal_F , 0._wp ) / time_F * rdt_ice
-
-            !-----------------
-            ! Update salinity   
-            !-----------------
-            ! only drainage terms ( gravity drainage and flushing )
-            ! snow ice / bottom sources are added in lim_thd_ent to conserve energy
-            sm_i_b(ji) = sm_i_b(ji) + dsm_i_fl_1d(ji) + dsm_i_gd_1d(ji)
-
-            ! if no ice, salinity = 0.1
-            i_ice_switch = 1._wp - MAX ( 0._wp, SIGN( 1._wp , - ht_i_b(ji) ) )
-            sm_i_b(ji)   = i_ice_switch * sm_i_b(ji) + s_i_min * ( 1._wp - i_ice_switch )
-         END DO ! ji
-
-         ! Salinity profile
-         CALL lim_var_salprof1d( kideb, kiut )
-
-         !----------------------------
-         ! Heat flux - brine drainage
-         !----------------------------
-
-         DO ji = kideb, kiut
-!!gm useless
-            ! iflush  : 1 if summer 
-            iflush  =  MAX( 0._wp , SIGN ( 1._wp , t_su_b(ji) - rtt ) ) 
-            ! igravdr : 1 if t_su lt t_bo
-            igravdr =  MAX( 0._wp , SIGN ( 1._wp , t_bo_b(ji) - t_su_b(ji) ) ) 
-            ! iaccrbo : 1 if bottom accretion
-            iaccrbo =  MAX( 0._wp , SIGN ( 1._wp , dh_i_bott(ji) ) )
-!!gm end useless
-            !
-            fhbri_1d(ji) = 0._wp
-         END DO ! ji
-
-         !----------------------------
-         ! Salt flux - brine drainage
-         !----------------------------
-          DO ji = kideb, kiut
-            i_ice_switch = 1._wp - MAX ( 0._wp, SIGN( 1._wp , - ht_i_b(ji) ) )
-            fsbri_1d(ji) = fsbri_1d(ji) - i_ice_switch * rhoic * a_i_b(ji) * ht_i_b(ji) * ( sm_i_b(ji) - zsiold(ji) ) / rdt_ice
-            !i_ice_switch = 1._wp - MAX ( 0._wp, SIGN( 1._wp , - zhiold(ji) ) )
-            !fsbri_1d(ji) = fsbri_1d(ji) - i_ice_switch * rhoic * a_i_b(ji) * zhiold(ji) * ( sm_i_b(ji) - zsiold(ji) ) / rdt_ice
-            !clem fsbri_1d(ji) = fsbri_1d(ji) - i_ice_switch * rhoic * a_i_b(ji) * ht_i_b(ji)         &
-            !clem     &         * ( MAX(dsm_i_gd_1d(ji) + dsm_i_fl_1d(ji), sm_i_b(ji) - zsiold(ji) ) ) / rdt_ice
-            IF( num_sal == 4 ) fsbri_1d(ji) = 0._wp
-          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._wp )  )
-               t_i_b(ji,jk) =  rtt - ( zbbb + zdiscrim ) / ( 2.0 *zaaa )
-            END DO
-         END DO
-         !
-      ENDIF ! num_sal .EQ. 2
-
-      !------------------------------------------------------------------------------|
-      !  Module 3 : Profile of salinity, constant in time                            |
-      !------------------------------------------------------------------------------|
-
-      IF( num_sal == 3 )   CALL lim_var_salprof1d( kideb, kiut )
-
-      !------------------------------------------------------------------------------|
-      !  Module 4 : Constant salinity varying in time                                |
-      !------------------------------------------------------------------------------|
-
-      IF( num_sal == 5 ) THEN      ! Cox and Weeks, 1974
-         !
-         DO ji = kideb, kiut
-            zsold = sm_i_b(ji)
-            IF( ht_i_b(ji) < 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) > 3.06918239 ) THEN 
-               sm_i_b(ji) = 3._wp
-            ENDIF
-            DO jk = 1, nlay_i
-               s_i_b(ji,jk)   = sm_i_b(ji)
-            END DO
-         END DO
-         !
-      ENDIF ! num_sal
-
-      !
-      CALL wrk_dealloc( jpij, ze_init, zhiold, zsiold )
-      !
-   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
-      !!-------------------------------------------------------------------
-      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
-      !!-------------------------------------------------------------------
-      !
-      REWIND( numnam_ice )                   ! Read Namelist namicesal
-      READ  ( numnam_ice  , namicesal )
-      !
-      IF(lwp) THEN                           ! control print
-         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         Dummy Module          No LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-   !!======================================================================
-END MODULE limthd_sal
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limtrp.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limtrp.F90	(revision 3937)
+++ 	(revision )
@@ -1,617 +1,0 @@
-MODULE limtrp
-   !!======================================================================
-   !!                       ***  MODULE limtrp   ***
-   !! LIM transport ice model : sea-ice advection/diffusion
-   !!======================================================================
-   !! History : LIM-2 ! 2000-01 (M.A. Morales Maqueda, H. Goosse, and T. Fichefet)  Original code
-   !!            3.0  ! 2005-11 (M. Vancoppenolle)   Multi-layer sea ice, salinity variations
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_trp      : advection/diffusion process of sea ice
-   !!----------------------------------------------------------------------
-   USE phycst          ! physical constant
-   USE dom_oce         ! ocean domain
-   USE sbc_oce         ! ocean surface boundary condition
-   USE par_ice         ! LIM-3 parameter
-   USE dom_ice         ! LIM-3 domain
-   USE ice             ! LIM-3 variables
-   USE limadv          ! LIM-3 advection
-   USE limhdf          ! LIM-3 horizontal diffusion
-   USE in_out_manager  ! I/O manager
-   USE lbclnk          ! lateral boundary conditions -- MPP exchanges
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! work arrays
-   USE prtctl          ! Print control
-   USE lib_fortran     ! to use key_nosignedzero
-   USE limvar          ! clem for ice thickness correction
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_trp    ! called by ice_step
-
-   REAL(wp)  ::   epsi06 = 1.e-06_wp   ! constant values
-   REAL(wp)  ::   epsi03 = 1.e-03_wp  
-   REAL(wp)  ::   epsi10 = 1.e-10_wp  
-   REAL(wp)  ::   epsi16 = 1.e-16_wp
-   REAL(wp)  ::   epsi20 = 1.e-20_wp
-   REAL(wp)  ::   rzero  = 0._wp   
-   REAL(wp)  ::   rone   = 1._wp
-
-   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:,:,:) ::   zs0e
-
-   !! * Substitution
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limtrp.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_trp( kt ) 
-      !!-------------------------------------------------------------------
-      !!                   ***  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 :
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! number of iteration
-      !
-      INTEGER  ::   ji, jj, jk, jl, jm, layer   ! dummy loop indices
-      INTEGER  ::   jbnd1, jbnd2
-      INTEGER  ::   initad                  ! number of sub-timestep for the advection
-      INTEGER  ::   ierr                    ! error status
-      REAL(wp) ::   zindb  , zindsn , zindic, zindh, zinda      ! local scalar
-      REAL(wp) ::   zusvosn, zusvoic, zbigval     !   -      -
-      REAL(wp) ::   zcfl , zusnit , zrtt          !   -      -
-      REAL(wp) ::   ze   , zsal   , zage          !   -      -
-      !
-      REAL(wp), POINTER, DIMENSION(:,:)      ::   zui_u, zvi_v, zsm, zs0at, zs0ow
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   zs0ice, zs0sn, zs0a, zs0c0 , zs0sm , zs0oi
-      REAL(wp), POINTER, DIMENSION(:,:,:,:)  ::   zs0e
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-      ! mass and salt flux (clem)
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zviold   ! old ice volume...
-      ! correct ice thickness (clem)
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zaiold, zhimax   ! old ice concentration
-      REAL(wp) :: zdv, zda, zvi, zvs, zsmv
-      !!---------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zui_u, zvi_v, zsm, zs0at, zs0ow )
-      CALL wrk_alloc( jpi, jpj, jpl, zs0ice, zs0sn, zs0a, zs0c0 , zs0sm , zs0oi )
-      CALL wrk_alloc( jpi, jpj, jkmax, jpl, zs0e )
-
-      CALL wrk_alloc( jpi,jpj,jpl,zviold )   ! clem
-      CALL wrk_alloc( jpi,jpj,jpl,zaiold, zhimax )   ! clem
-
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
-      IF( numit == nstart .AND. lwp ) THEN
-         WRITE(numout,*)
-         IF( ln_limdyn ) THEN   ;   WRITE(numout,*) 'lim_trp : Ice transport '
-         ELSE                   ;   WRITE(numout,*) 'lim_trp : No ice advection as ln_limdyn = ', ln_limdyn
-         ENDIF
-         WRITE(numout,*) '~~~~~~~~~~~~'
-      ENDIF
-      
-      zsm(:,:) = area(:,:)
-
-      !                             !-------------------------------------!
-      IF( ln_limdyn ) THEN          !   Advection of sea ice properties   !
-         !                          !-------------------------------------!
-         ! mass and salt flux init (clem)
-         zviold(:,:,:)  = v_i(:,:,:)
-
-         !--- Thickness correction init. (clem) -------------------------------
-         CALL lim_var_glo2eqv
-         zaiold(:,:,:) = a_i(:,:,:)
-         !---------------------------------------------------------------------
-         ! Record max of the surrounding ice thicknesses for correction in limupdate
-         ! in case advection creates ice too thick.
-         !---------------------------------------------------------------------
-         zhimax(:,:,:) = ht_i(:,:,:)
-         DO jl = 1, jpl
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  zhimax(ji,jj,jl) = MAXVAL( ht_i(ji-1:ji+1,jj-1:jj+1,jl) )
-               END DO
-            END DO
-            CALL lbc_lnk(zhimax(:,:,jl),'T',1.)
-         END DO
-         
-         !-------------------------
-         ! transported fields                                        
-         !-------------------------
-         ! Snow vol, ice vol, salt and age contents, area
-         zs0ow(:,:) = ato_i(:,:) * area(:,:)               ! Open water area 
-         DO jl = 1, jpl
-            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
-            zs0c0 (:,:,jl)   = e_s  (:,:,1,jl)              ! Snow heat content
-            zs0e  (:,:,:,jl) = e_i  (:,:,:,jl)              ! Ice  heat content
-         END DO
-
-         !--------------------------
-         ! Advection of Ice fields  (Prather scheme)                                            
-         !--------------------------
-         ! If ice drift field is too fast, use an appropriate time step for advection.         
-         ! CFL test for stability
-         zcfl  =            MAXVAL( ABS( u_ice(:,:) ) * rdt_ice / e1u(:,:) )
-         zcfl  = MAX( zcfl, MAXVAL( ABS( v_ice(:,:) ) * rdt_ice / e2v(:,:) ) )
-         IF(lk_mpp )   CALL mpp_max( zcfl )
-!!gm more readability:
-!         IF( zcfl > 0.5 ) THEN   ;   initad = 2   ;   zusnit = 0.5_wp
-!         ELSE                    ;   initad = 1   ;   zusnit = 1.0_wp
-!         ENDIF
-!!gm end
-         initad = 1 + NINT( MAX( rzero, SIGN( rone, zcfl-0.5 ) ) )
-         zusnit = 1.0 / REAL( initad ) 
-         IF( zcfl > 0.5 .AND. lwp )   &
-            WRITE(numout,*) 'lim_trp_2 : CFL violation at day ', nday, ', cfl = ', zcfl,   &
-               &                        ': the ice time stepping is split in two'
-
-         IF( MOD( ( kt - 1) / nn_fsbc , 2 ) == 0 ) THEN       !==  odd ice time step:  adv_x then adv_y  ==!
-            DO jk = 1,initad
-               CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0ow (:,:), sxopw(:,:),   &             !--- ice open water area
-                   &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
-               CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0ow (:,:), sxopw(:,:),   &
-                   &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
-               DO jl = 1, jpl
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
-                     &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &
-                     &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
-                     &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &
-                     &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
-                     &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &
-                     &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &   !--- ice age      ---     
-                     &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &
-                     &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   &   !--- ice concentrations ---
-                     &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   & 
-                     &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &  !--- snow heat contents ---
-                     &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &
-                     &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  DO layer = 1, nlay_i                                                           !--- ice heat contents ---
-                     CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0e(:,:,layer,jl), sxe (:,:,layer,jl),   & 
-                        &                                       sxxe(:,:,layer,jl), sye (:,:,layer,jl),   &
-                        &                                       syye(:,:,layer,jl), sxye(:,:,layer,jl) )
-                     CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0e(:,:,layer,jl), sxe (:,:,layer,jl),   & 
-                        &                                       sxxe(:,:,layer,jl), sye (:,:,layer,jl),   &
-                        &                                       syye(:,:,layer,jl), sxye(:,:,layer,jl) )
-                  END DO
-               END DO
-            END DO
-         ELSE
-            DO jk = 1, initad
-               CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0ow (:,:), sxopw(:,:),   &             !--- ice open water area
-                   &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
-               CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0ow (:,:), sxopw(:,:),   &
-                   &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
-               DO jl = 1, jpl
-                  CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
-                     &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &
-                     &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
-                     &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &
-                     &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
-                     &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &
-                     &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &   !--- ice age      ---
-                     &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &
-                     &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   &   !--- ice concentrations ---
-                     &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   &
-                     &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &  !--- snow heat contents ---
-                     &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &
-                     &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  DO layer = 1, nlay_i                                                           !--- ice heat contents ---
-                     CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0e(:,:,layer,jl), sxe (:,:,layer,jl),   & 
-                        &                                       sxxe(:,:,layer,jl), sye (:,:,layer,jl),   &
-                        &                                       syye(:,:,layer,jl), sxye(:,:,layer,jl) )
-                     CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0e(:,:,layer,jl), sxe (:,:,layer,jl),   & 
-                        &                                       sxxe(:,:,layer,jl), sye (:,:,layer,jl),   &
-                        &                                       syye(:,:,layer,jl), sxye(:,:,layer,jl) )
-                  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                  
-         !------------------------------------------------------------------------------!
-
-         !--------------------------------
-         !  diffusion of open water area
-         !--------------------------------
-         zs0at(:,:) = zs0a(:,:,1)      ! total ice fraction
-         DO jl = 2, jpl
-            zs0at(:,:) = zs0at(:,:) + zs0a(:,:,jl)
-         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._wp - MAX( rzero, SIGN( rone, -zs0at(ji  ,jj) ) ) )   &
-                  &        * ( 1._wp - MAX( rzero, SIGN( rone, -zs0at(ji+1,jj) ) ) ) * ahiu(ji,jj)
-               pahv(ji,jj) = ( 1._wp - MAX( rzero, SIGN( rone, -zs0at(ji,jj  ) ) ) )   &
-                  &        * ( 1._wp - MAX( rzero, SIGN( rone,- zs0at(ji,jj+1) ) ) ) * ahiv(ji,jj)
-            END DO
-         END DO
-         !
-         CALL lim_hdf( zs0ow (:,:) )   ! Diffusion
-
-         !------------------------------------
-         !  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._wp - MAX( rzero, SIGN( rone, -zs0a(ji  ,jj,jl) ) ) )   &
-                     &        * ( 1._wp - MAX( rzero, SIGN( rone, -zs0a(ji+1,jj,jl) ) ) ) * ahiu(ji,jj)
-                  pahv(ji,jj) = ( 1._wp - MAX( rzero, SIGN( rone, -zs0a(ji,jj  ,jl) ) ) )   &
-                     &        * ( 1._wp - MAX( rzero, SIGN( rone,- zs0a(ji,jj+1,jl) ) ) ) * ahiv(ji,jj)
-               END DO
-            END DO
-
-             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
-         END DO
-
-         !-----------------------------------------
-         !  Remultiply everything by ice area
-         !-----------------------------------------
-         !clem zs0ow(:,:) = MAX( rzero, zs0ow(:,:) * area(:,:) )
-         !clem DO jl = 1, jpl
-         !clem    zs0ice(:,:,jl) = MAX( rzero, zs0ice(:,:,jl) * area(:,:) )    !!bug:  est-ce utile
-         !clem    zs0sn (:,:,jl) = MAX( rzero, zs0sn (:,:,jl) * area(:,:) )    !!bug:  cf /area  juste apres
-         !clem    zs0sm (:,:,jl) = MAX( rzero, zs0sm (:,:,jl) * area(:,:) )    !!bug:  cf /area  juste apres
-         !clem    zs0oi (:,:,jl) = MAX( rzero, zs0oi (:,:,jl) * area(:,:) )
-         !clem    zs0a  (:,:,jl) = MAX( rzero, zs0a  (:,:,jl) * area(:,:) )    !! suppress both change le resultat
-         !clem    zs0c0 (:,:,jl) = MAX( rzero, zs0c0 (:,:,jl) * area(:,:) )
-         !clem    DO jk = 1, nlay_i
-         !clem       zs0e(:,:,jk,jl) = MAX( rzero, zs0e (:,:,jk,jl) * area(:,:) )
-         !clem    END DO ! jk
-         !clem END DO ! jl
-
-         !------------------------------------------------------------------------------!
-         ! 5) Update and limit ice properties after transport                           
-         !------------------------------------------------------------------------------!
-
-         !--------------------------------------------------
-         ! 5.1) Recover mean values over the grid squares.
-         !--------------------------------------------------
-
-         !clem DO jl = 1, jpl
-         !clem    DO jk = 1, nlay_i
-         !clem       DO jj = 1, jpj
-         !clem          DO ji = 1, jpi
-         !clem             zs0e(ji,jj,jk,jl) = MAX( rzero, zs0e(ji,jj,jk,jl) / area(ji,jj) )
-         !clem          END DO
-         !clem       END DO
-         !clem    END DO
-         !clem END DO
-
-         !clem DO jj = 1, jpj
-         !clem    DO ji = 1, jpi
-         !clem       zs0ow(ji,jj) = MAX( rzero, zs0ow (ji,jj) / area(ji,jj) )
-         !clem    END DO
-         !clem END DO
-
-         zs0at(:,:) = 0._wp
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                 !clem  zs0sn (ji,jj,jl) = MAX( rzero, zs0sn (ji,jj,jl)/area(ji,jj) )
-                 !clem  zs0ice(ji,jj,jl) = MAX( rzero, zs0ice(ji,jj,jl)/area(ji,jj) )
-                 !clem  zs0sm (ji,jj,jl) = MAX( rzero, zs0sm (ji,jj,jl)/area(ji,jj) )
-                 !clem  zs0oi (ji,jj,jl) = MAX( rzero, zs0oi (ji,jj,jl)/area(ji,jj) )
-                 !clem  zs0a  (ji,jj,jl) = MAX( rzero, zs0a  (ji,jj,jl)/area(ji,jj) )
-                 !clem  zs0c0 (ji,jj,jl) = MAX( rzero, zs0c0 (ji,jj,jl)/area(ji,jj) )
-                  zs0sn (ji,jj,jl) = MAX( rzero, zs0sn (ji,jj,jl) )
-                  zs0ice(ji,jj,jl) = MAX( rzero, zs0ice(ji,jj,jl) )
-                  zs0sm (ji,jj,jl) = MAX( rzero, zs0sm (ji,jj,jl) )
-                  zs0oi (ji,jj,jl) = MAX( rzero, zs0oi (ji,jj,jl) )
-                  zs0a  (ji,jj,jl) = MAX( rzero, zs0a  (ji,jj,jl) )
-                  zs0c0 (ji,jj,jl) = MAX( rzero, zs0c0 (ji,jj,jl) )
-                  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._wp , SIGN( 1.0, zs0at(ji,jj) - epsi10) )
-               zs0ow(ji,jj) = ( 1._wp - zindb ) + zindb * MAX( zs0ow(ji,jj), 0._wp )
-               ato_i(ji,jj) = zs0ow(ji,jj)
-            END DO
-         END DO
-
-         !
-         !
-         DO jl = 1, jpl         ! Remove very small areas 
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zvi = zs0ice(ji,jj,jl)
-                  zvs = zs0sn(ji,jj,jl)
-                  !
-                  zindb         = MAX( 0.0 , SIGN( 1.0, zs0a(ji,jj,jl) - epsi10) )
-                  !
-                  !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) - epsi10 ) )
-                  zindic         = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) )
-                  zindb          = MAX( zindsn, zindic )
-                  !
-                  zs0a(ji,jj,jl) = zindb  * zs0a(ji,jj,jl) !ice concentration
-                  a_i (ji,jj,jl) = zs0a(ji,jj,jl)
-                  v_s (ji,jj,jl) = zindsn * v_s(ji,jj,jl)
-                  v_i (ji,jj,jl) = zindic * v_i(ji,jj,jl)
-                  !
-                  ! Update mass fluxes (clem)
-                  rdmicif(ji,jj) = rdmicif(ji,jj) + ( v_i(ji,jj,jl) - zvi ) * rhoic 
-                  rdmsnif(ji,jj) = rdmsnif(ji,jj) + ( v_s(ji,jj,jl) - zvs ) * rhosn 
-              END DO
-            END DO
-         END DO
-
-         !--- Thickness correction in case too high (clem) --------------------------------------------------------
-         CALL lim_var_glo2eqv
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-
-                  IF ( v_i(ji,jj,jl) > 0. ) THEN
-                     zvi = v_i(ji,jj,jl)
-                     zvs = v_s(ji,jj,jl)
-                     zdv = v_i(ji,jj,jl) - zviold(ji,jj,jl)   
-                     !zda = a_i(ji,jj,jl) - zaiold(ji,jj,jl)   
-                     
-                     IF ( ( zdv > 0.0 .AND. ht_i(ji,jj,jl) > zhimax(ji,jj,jl) .AND. SUM( zaiold(ji,jj,1:jpl) ) < 0.80 ) .OR. &
-                          ( zdv < 0.0 .AND. ht_i(ji,jj,jl) > zhimax(ji,jj,jl) ) ) THEN                                          
-                        ht_i(ji,jj,jl) = MIN( zhimax(ji,jj,jl), hi_max(jl) )
-                        zindh   =  MAX( rzero, SIGN( rone, ht_i(ji,jj,jl) - epsi10 ) )
-                        a_i(ji,jj,jl)  = zindh * v_i(ji,jj,jl) / MAX( ht_i(ji,jj,jl), epsi10 )
-                     ELSE
-                        ht_i(ji,jj,jl) = MAX( MIN( ht_i(ji,jj,jl), hi_max(jl) ), hi_max(jl-1) )
-                        zindh   =  MAX( rzero, SIGN( rone, ht_i(ji,jj,jl) - epsi10 ) )
-                        a_i(ji,jj,jl)  = zindh * v_i(ji,jj,jl) / MAX( ht_i(ji,jj,jl), epsi10 )
-                     ENDIF
-
-                     !zindh   =  MAX( rzero, SIGN( rone, ht_i(ji,jj,jl) - epsi10 ) )
-                     v_i(ji,jj,jl) = a_i(ji,jj,jl) * ht_i(ji,jj,jl)
-                     v_s(ji,jj,jl) = a_i(ji,jj,jl) * ht_s(ji,jj,jl)
-
-                     ! Update mass fluxes (clem)
-                     rdmicif(ji,jj) = rdmicif(ji,jj) + ( v_i(ji,jj,jl) - zvi ) * rhoic
-                     rdmsnif(ji,jj) = rdmsnif(ji,jj) + ( v_s(ji,jj,jl) - zvs ) * rhosn
-
-                  ENDIF
-
-                  diag_trp_vi(ji,jj) = diag_trp_vi(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) / rdt_ice
-
-               END DO
-            END DO
-         END DO
-
-         ! ---
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-         !      ato_i(ji,jj) = 1._wp - SUM( a_i(ji,jj,1:jpl) ) !clem@rm-ow-advection
-               zs0at(ji,jj) = SUM( zs0a(ji,jj,1:jpl) ) ! clem@useless??
-            END DO
-         END DO
-
-         !----------------------
-         ! 5.3) Ice properties
-         !----------------------
-
-         zbigval = 1.e+13
-
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zsmv = zs0sm(ji,jj,jl)
-
-                  ! Switches and dummy variables
-                  zusvosn         = 1.0/MAX( v_s(ji,jj,jl) , 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) - epsi10 ) )
-                  zindic          = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) )
-                  zindb           = MAX( zindsn, zindic )
-
-                  ! Ice salinity and age
-                  zsal = MAX( MIN( (rhoic-rhosn)/rhoic*sss_m(ji,jj)  , &
-                     zusvoic * zs0sm(ji,jj,jl) ), s_i_min ) * v_i(ji,jj,jl)
-                  IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) smv_i(ji,jj,jl) = zindic*zsal
-
-                  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      
-
-                  ! Update salt fluxes (clem)
-                  fsalt_res(ji,jj) = fsalt_res(ji,jj) - ( smv_i(ji,jj,jl) - zsmv ) * rhoic / rdt_ice 
-               END DO !ji
-            END DO !jj
-         END DO ! jl
-
-         DO jl = 1, jpl
-            DO jk = 1, nlay_i
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     ! Ice heat content
-                     zindic          =  MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) )
-                     ze              =  MIN( MAX( 0.0, zs0e(ji,jj,jk,jl)*area(ji,jj) ), zbigval )
-                     e_i(ji,jj,jk,jl) = zindic * ze
-                  END DO !ji
-               END DO ! jj
-            END DO ! jk
-         END DO ! jl
-
-
-      ! --- agglomerate variables (clem) -----------------
-      vt_i (:,:) = 0._wp
-      vt_s (:,:) = 0._wp
-      at_i (:,:) = 0._wp
-      !
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               !
-               vt_i(ji,jj) = vt_i(ji,jj) + v_i(ji,jj,jl) ! ice volume
-               vt_s(ji,jj) = vt_s(ji,jj) + v_s(ji,jj,jl) ! snow volume
-               at_i(ji,jj) = at_i(ji,jj) + a_i(ji,jj,jl) ! ice concentration
-               !
-               zinda = MAX( rzero , SIGN( rone , at_i(ji,jj) - epsi16 ) )
-               icethi(ji,jj) = vt_i(ji,jj) / MAX( at_i(ji,jj) , epsi16 ) * zinda  ! ice thickness
-            END DO
-         END DO
-      END DO
-      ! -------------------------------------------------
-
-
-
-      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
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
-
-         IF(lwp) THEN
-            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limtrp) = ',(zchk_v_i * 86400.)
-            IF (    ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limtrp) = ',(zchk_smv * 86400.)
-            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limtrp) = ',(MINVAL(v_i) * 1.e-3)
-            IF ( MINVAL( a_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation a_i<0               (limtrp) = ',MINVAL(a_i)
-         ENDIF
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-      !
-      CALL wrk_dealloc( jpi, jpj, zui_u, zvi_v, zsm, zs0at, zs0ow )
-      CALL wrk_dealloc( jpi, jpj, jpl, zs0ice, zs0sn, zs0a, zs0c0 , zs0sm , zs0oi )
-      CALL wrk_dealloc( jpi, jpj, jkmax, jpl, zs0e )
-
-      CALL wrk_dealloc( jpi,jpj,jpl,zaiold, zhimax )   ! clem
-      !
-   END SUBROUTINE lim_trp
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty Module                No sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_trp        ! Empty routine
-   END SUBROUTINE lim_trp
-#endif
-
-   !!======================================================================
-END MODULE limtrp
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limupdate1.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limupdate1.F90	(revision 3937)
+++ 	(revision )
@@ -1,461 +1,0 @@
-MODULE limupdate1
-   !!======================================================================
-   !!                     ***  MODULE  limupdate1  ***
-   !!   LIM-3 : Update of sea-ice global variables at the end of the time step
-   !!======================================================================
-   !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!    lim_update1   : computes update of sea-ice global variables from trend terms
-   !!----------------------------------------------------------------------
-   USE limrhg          ! ice rheology
-
-   USE dom_oce
-   USE oce             ! dynamics and tracers variables
-   USE in_out_manager
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice fields
-   USE dom_ice
-   USE phycst          ! physical constants
-   USE ice
-   USE limdyn
-   USE limtrp
-   USE limthd
-   USE limsbc
-   USE limdia
-   USE limdiahsb
-   USE limwri
-   USE limrst
-   USE thd_ice         ! LIM thermodynamic sea-ice variables
-   USE par_ice
-   USE limitd_th
-   USE limvar
-   USE prtctl           ! Print control
-   USE lbclnk           ! lateral boundary condition - MPP exchanges
-   USE wrk_nemo         ! work arrays
-   USE lib_fortran     ! glob_sum
-   ! Check budget (Rousset)
-   USE in_out_manager   ! I/O manager
-   USE iom              ! I/O manager
-   USE lib_mpp          ! MPP library
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_update1   ! routine called by ice_step
-
-      REAL(wp)  ::   epsi06 = 1.e-06_wp   ! module constants
-      REAL(wp)  ::   epsi04 = 1.e-04_wp   !    -       -
-      REAL(wp)  ::   epsi03 = 1.e-03_wp   !    -       -
-      REAL(wp)  ::   epsi10 = 1.e-10_wp   !    -       -
-      REAL(wp)  ::   epsi16 = 1.e-16_wp   !    -       -
-      REAL(wp)  ::   epsi20 = 1.e-20_wp   !    -       -
-      REAL(wp)  ::   rzero  = 0._wp       !    -       -
-      REAL(wp)  ::   rone   = 1._wp       !    -       -
-         
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limupdate.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_update1
-      !!-------------------------------------------------------------------
-      !!               ***  ROUTINE lim_update1  ***
-      !!               
-      !! ** Purpose :  Computes update of sea-ice global variables at 
-      !!               the end of the time step.
-      !!               Address pathological cases
-      !!               This place is very important
-      !!                
-      !! ** Method  :  
-      !!    Ice speed from ice dynamics
-      !!    Ice thickness, Snow thickness, Temperatures, Lead fraction
-      !!      from advection and ice thermodynamics 
-      !!
-      !! ** Action  : - 
-      !!---------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk, jl, jm    ! dummy loop indices
-      INTEGER ::   jbnd1, jbnd2
-      INTEGER ::   i_ice_switch
-      INTEGER ::   ind_im, layer      ! indices for internal melt
-      REAL(wp) ::   zweight, zesum, z_da_i
-      REAL(wp) ::   zindb, zindsn, zindic
-      REAL(wp) ::   zindg, zh, zdvres, zviold2
-      REAL(wp) ::   zbigvalue, zvsold2, z_da_ex
-      REAL(wp) ::   z_prescr_hi, zat_i_old, ztmelts, ze_s
-
-      REAL(wp), POINTER, DIMENSION(:) ::   zthick0, zqm0      ! thickness of the layers and heat contents for
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-      ! mass and salt flux (clem)
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zviold, zvsold, zsmvold   ! old ice volume...
-      !!-------------------------------------------------------------------
-
-      CALL wrk_alloc( jkmax, zthick0, zqm0 )
-
-      CALL wrk_alloc( jpi,jpj,jpl,zviold, zvsold, zsmvold )   ! clem
-
-      !------------------------------------------------------------------------------
-      ! 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
-         v_i(:,:,jl)  = v_i(:,:,jl) + d_v_i_trp(:,:,jl) 
-         v_s(:,:,jl)  = v_s(:,:,jl) + d_v_s_trp(:,:,jl)
-      END DO
-
-
-      !---------------------------------------------
-      ! Ice concentration and ice heat content
-      !---------------------------------------------
-      a_i (:,:,:)  = a_i (:,:,:) + d_a_i_trp(:,:,:)
-      e_i(:,:,:,:) = e_i(:,:,:,:) + d_e_i_trp(:,:,:,:)  
-
-      !------------------------------
-      ! Snow temperature and ice age
-      !------------------------------
-      e_s (:,:,:,:) = e_s (:,:,:,:) + d_e_s_trp (:,:,:,:)
-      oa_i(:,:,:)   = oa_i(:,:,:)   + d_oa_i_trp(:,:,:)  
-
-      !--------------
-      ! Ice salinity    
-      !--------------
-      IF(  num_sal == 2  .OR.  num_sal == 4  ) THEN      ! general case
-         smv_i(:,:,:) = smv_i(:,:,:) + d_smv_i_trp(:,:,:)
-      ENDIF
-
-      ! mass and salt flux init (clem)
-      zviold(:,:,:) = v_i(:,:,:)
-      zvsold(:,:,:) = v_s(:,:,:)
-      zsmvold(:,:,:) = smv_i(:,:,:)
-
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
-      CALL lim_var_glo2eqv
-
-      !---------------------------------
-      ! Classify the pathological cases
-      !---------------------------------
-      ! (1) v_i (new) > 0; d_v_i_thd + v_i(old) > 0 (easy case)
-      ! (3) v_i (new) < 0; d_v_i_thd + v_i(old) > 0 (combined total ablation)
-      ! (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) .LT. 0.0 ) THEN
-                  patho_case(ji,jj,jl) = 3
-               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
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      !--------------------------------------
-      ! 2. Review of all pathological cases
-      !--------------------------------------
-     
-      at_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      !----------------------------------------------------
-      ! 2.2) Rebin categories with thickness out of bounds
-      !----------------------------------------------------
-      DO jm = 1, jpm
-         jbnd1 = ice_cat_bounds(jm,1)
-         jbnd2 = ice_cat_bounds(jm,2)
-         IF (ice_ncat_types(jm) .GT. 1 )   CALL lim_itd_th_reb(jbnd1, jbnd2, jm)
-      END DO
-
-      at_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      zbigvalue      = 1.0e+20
-
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-
-               !switches
-               zindb         = MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - 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
-               zdvres = (zindsn * zindb - 1._wp) * v_s(ji,jj,jl)
-               v_s(ji,jj,jl) = v_s(ji,jj,jl) + zdvres
-
-               !rdmsnif(ji,jj) = rdmsnif(ji,jj) + zdvres * rhosn
- 
-               !--- 2.5 Correction to ice thickness
-               !-------------------------------------
-               zdvres = (zindb - 1._wp) * v_i(ji,jj,jl)
-               v_i(ji,jj,jl) = v_i(ji,jj,jl) + zdvres
-
-               !rdmicif(ji,jj) = rdmicif(ji,jj) + zdvres * rhoic
-               !fsalt_res(ji,jj)  = fsalt_res(ji,jj) - sm_i(ji,jj,jl) * ( rhoic * zdvres / rdt_ice )
-
-               !--- 2.6 Snow is transformed into ice if the original ice cover disappears
-               !----------------------------------------------------------------------------
-               zindg          = tms(ji,jj) *  MAX( 0._wp, SIGN( 1._wp, -v_i(ji,jj,jl) ) )
-               v_i(ji,jj,jl)  = v_i(ji,jj,jl) + zindg * rhosn * v_s(ji,jj,jl) / rau0
-               v_s(ji,jj,jl)  = ( 1._wp - 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
-               !clem a_i(ji,jj,jl) = zindb * MAX(zindsn, zindic) * MAX( a_i(ji,jj,jl), epsi06 )
-               a_i(ji,jj,jl) = zindb * a_i(ji,jj,jl)
-
-               !-------------------------
-               ! 2.8) Snow heat content
-               !-------------------------
-               e_s(ji,jj,1,jl) = zindsn * ( MIN ( MAX ( 0._wp, e_s(ji,jj,1,jl) ), zbigvalue ) )
-
-            END DO ! ji
-         END DO ! jj
-      END DO ! jl
-
-      !------------------------
-      ! 2.9) Ice heat content 
-      !------------------------
-
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  zindic        = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi04 ) ) 
-                  e_i(ji,jj,jk,jl)= zindic * ( MIN ( MAX ( 0.0, e_i(ji,jj,jk,jl) ), zbigvalue ) )
-               END DO ! ji
-            END DO ! jj
-         END DO !jk
-      END DO !jl
- 
-      at_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      !--- 2.13 ice concentration should not exceed amax 
-      !-----------------------------------------------------
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            z_da_ex =  MAX( at_i(ji,jj) - amax , 0.0 )        
-            DO jl  = 1, jpl
-               zindb   =  MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi04 ) ) 
-               z_da_i = a_i(ji,jj,jl) * z_da_ex / MAX( at_i(ji,jj), epsi06 ) * zindb
-               a_i(ji,jj,jl) = a_i(ji,jj,jl) - z_da_i
-           END DO
-         END DO 
-      END DO 
-      at_i(:,:) = a_i(:,:,1)
-      DO jl = 2, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      ! Final thickness distribution rebinning
-      ! --------------------------------------
-      DO jm = 1, jpm
-         jbnd1 = ice_cat_bounds(jm,1)
-         jbnd2 = ice_cat_bounds(jm,2)
-         IF (ice_ncat_types(jm) .GT. 1 ) CALL lim_itd_th_reb(jbnd1, jbnd2, jm)
-         IF (ice_ncat_types(jm) .EQ. 1 ) THEN
-         ENDIF
-      END DO
-
-      !---------------------
-      ! 2.11) Ice salinity
-      !---------------------
-      !clem@bug: smv_i should be updated too: smv_i(:,:,:) = smv_i(:,:,:) + sm_i(:,:,:) * ( v_i(:,:,:) - zviold(:,:,:) )
-      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_m(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) + epsi20))
-                     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
-
-      at_i(:,:) = a_i(:,:,1)
-      DO jl = 2, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-
-      !--------------------------------
-      ! Update mass/salt fluxes (clem)
-      !--------------------------------
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               diag_res_pr(ji,jj) = diag_res_pr(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) / rdt_ice 
-               rdmicif(ji,jj) = rdmicif(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) * rhoic 
-               rdmsnif(ji,jj) = rdmsnif(ji,jj) + ( v_s(ji,jj,jl) - zvsold(ji,jj,jl) ) * rhosn 
-               fsalt_res(ji,jj) = fsalt_res(ji,jj) - ( smv_i(ji,jj,jl) - zsmvold(ji,jj,jl) ) * rhoic / rdt_ice 
-            END DO
-         END DO
-      END DO
-  
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
-
-         IF(lwp) THEN
-            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limupdate1) = ',(zchk_v_i * 86400.)
-            IF (    ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limupdate1) = ',(zchk_smv * 86400.)
-            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limupdate1) = ',(MINVAL(v_i) * 1.e-3)
-            IF ( MAXVAL( SUM(a_i(:,:,:),dim=3) ) >  amax+epsi10 ) WRITE(numout,*) 'violation a_i>amax    (limupdate1) = ',MAXVAL(SUM(a_i,dim=3))
-            IF ( MINVAL( a_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation a_i<0               (limupdate1) = ',MINVAL(a_i)
-         ENDIF
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
-      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_update1  : cell area   :')
-         CALL prt_ctl(tab2d_1=at_i       , clinfo1=' lim_update1  : at_i        :')
-         CALL prt_ctl(tab2d_1=vt_i       , clinfo1=' lim_update1  : vt_i        :')
-         CALL prt_ctl(tab2d_1=vt_s       , clinfo1=' lim_update1  : vt_s        :')
-         CALL prt_ctl(tab2d_1=strength   , clinfo1=' lim_update1  : strength    :')
-         CALL prt_ctl(tab2d_1=u_ice      , clinfo1=' lim_update1  : u_ice       :', tab2d_2=v_ice      , clinfo2=' v_ice       :')
-         CALL prt_ctl(tab2d_1=d_u_ice_dyn, clinfo1=' lim_update1  : d_u_ice_dyn :', tab2d_2=d_v_ice_dyn, clinfo2=' d_v_ice_dyn :')
-         CALL prt_ctl(tab2d_1=old_u_ice  , clinfo1=' lim_update1  : old_u_ice   :', tab2d_2=old_v_ice  , clinfo2=' old_v_ice   :')
-
-         DO jl = 1, jpl
-            CALL prt_ctl_info(' ')
-            CALL prt_ctl_info(' - Category : ', ivar1=jl)
-            CALL prt_ctl_info('   ~~~~~~~~~~')
-            CALL prt_ctl(tab2d_1=ht_i       (:,:,jl)        , clinfo1= ' lim_update1  : ht_i        : ')
-            CALL prt_ctl(tab2d_1=ht_s       (:,:,jl)        , clinfo1= ' lim_update1  : ht_s        : ')
-            CALL prt_ctl(tab2d_1=t_su       (:,:,jl)        , clinfo1= ' lim_update1  : t_su        : ')
-            CALL prt_ctl(tab2d_1=t_s        (:,:,1,jl)      , clinfo1= ' lim_update1  : t_snow      : ')
-            CALL prt_ctl(tab2d_1=sm_i       (:,:,jl)        , clinfo1= ' lim_update1  : sm_i        : ')
-            CALL prt_ctl(tab2d_1=o_i        (:,:,jl)        , clinfo1= ' lim_update1  : o_i         : ')
-            CALL prt_ctl(tab2d_1=a_i        (:,:,jl)        , clinfo1= ' lim_update1  : a_i         : ')
-            CALL prt_ctl(tab2d_1=old_a_i    (:,:,jl)        , clinfo1= ' lim_update1  : old_a_i     : ')
-            CALL prt_ctl(tab2d_1=d_a_i_trp  (:,:,jl)        , clinfo1= ' lim_update1  : d_a_i_trp   : ')
-            CALL prt_ctl(tab2d_1=v_i        (:,:,jl)        , clinfo1= ' lim_update1  : v_i         : ')
-            CALL prt_ctl(tab2d_1=old_v_i    (:,:,jl)        , clinfo1= ' lim_update1  : old_v_i     : ')
-            CALL prt_ctl(tab2d_1=d_v_i_trp  (:,:,jl)        , clinfo1= ' lim_update1  : d_v_i_trp   : ')
-            CALL prt_ctl(tab2d_1=v_s        (:,:,jl)        , clinfo1= ' lim_update1  : v_s         : ')
-            CALL prt_ctl(tab2d_1=old_v_s    (:,:,jl)        , clinfo1= ' lim_update1  : old_v_s     : ')
-            CALL prt_ctl(tab2d_1=d_v_s_trp  (:,:,jl)        , clinfo1= ' lim_update1  : d_v_s_trp   : ')
-            CALL prt_ctl(tab2d_1=e_i        (:,:,1,jl)/1.0e9, clinfo1= ' lim_update1  : e_i1        : ')
-            CALL prt_ctl(tab2d_1=old_e_i    (:,:,1,jl)/1.0e9, clinfo1= ' lim_update1  : old_e_i1    : ')
-            CALL prt_ctl(tab2d_1=d_e_i_trp  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update1  : de_i1_trp   : ')
-            CALL prt_ctl(tab2d_1=e_i        (:,:,2,jl)/1.0e9, clinfo1= ' lim_update1  : e_i2        : ')
-            CALL prt_ctl(tab2d_1=old_e_i    (:,:,2,jl)/1.0e9, clinfo1= ' lim_update1  : old_e_i2    : ')
-            CALL prt_ctl(tab2d_1=d_e_i_trp  (:,:,2,jl)/1.0e9, clinfo1= ' lim_update1  : de_i2_trp   : ')
-            CALL prt_ctl(tab2d_1=e_s        (:,:,1,jl)      , clinfo1= ' lim_update1  : e_snow      : ')
-            CALL prt_ctl(tab2d_1=old_e_s    (:,:,1,jl)      , clinfo1= ' lim_update1  : old_e_snow  : ')
-            CALL prt_ctl(tab2d_1=d_e_s_trp  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update1  : d_e_s_trp   : ')
-            CALL prt_ctl(tab2d_1=smv_i      (:,:,jl)        , clinfo1= ' lim_update1  : smv_i       : ')
-            CALL prt_ctl(tab2d_1=old_smv_i  (:,:,jl)        , clinfo1= ' lim_update1  : old_smv_i   : ')
-            CALL prt_ctl(tab2d_1=d_smv_i_trp(:,:,jl)        , clinfo1= ' lim_update1  : d_smv_i_trp : ')
-            CALL prt_ctl(tab2d_1=oa_i       (:,:,jl)        , clinfo1= ' lim_update1  : oa_i        : ')
-            CALL prt_ctl(tab2d_1=old_oa_i   (:,:,jl)        , clinfo1= ' lim_update1  : old_oa_i    : ')
-            CALL prt_ctl(tab2d_1=d_oa_i_trp (:,:,jl)        , clinfo1= ' lim_update1  : d_oa_i_trp  : ')
-            CALL prt_ctl(tab2d_1=REAL(patho_case(:,:,jl))   , clinfo1= ' lim_update1  : 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_update1  : t_i       : ')
-            END DO
-         END DO
-
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Heat / FW fluxes : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=fmmec  , clinfo1= ' lim_update1 : fmmec : ', tab2d_2=fhmec     , clinfo2= ' fhmec     : ')
-         CALL prt_ctl(tab2d_1=sst_m  , clinfo1= ' lim_update1 : sst   : ', tab2d_2=sss_m     , clinfo2= ' sss       : ')
-         CALL prt_ctl(tab2d_1=fhbri  , clinfo1= ' lim_update1 : fhbri : ', tab2d_2=fheat_rpo , clinfo2= ' fheat_rpo : ')
-
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Stresses : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=utau       , clinfo1= ' lim_update1 : utau      : ', tab2d_2=vtau       , clinfo2= ' vtau      : ')
-         CALL prt_ctl(tab2d_1=utau_ice   , clinfo1= ' lim_update1 : utau_ice  : ', tab2d_2=vtau_ice   , clinfo2= ' vtau_ice  : ')
-         CALL prt_ctl(tab2d_1=u_oce      , clinfo1= ' lim_update1 : u_oce     : ', tab2d_2=v_oce      , clinfo2= ' v_oce     : ')
-      ENDIF
-   
-
-      CALL wrk_dealloc( jkmax, zthick0, zqm0 )
-
-      CALL wrk_dealloc( jpi,jpj,jpl,zviold, zvsold, zsmvold )   ! clem
-
-   END SUBROUTINE lim_update1
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty Module               No sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_update1     ! Empty routine
-   END SUBROUTINE lim_update1
-
-#endif
-
-END MODULE limupdate1
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limupdate2.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limupdate2.F90	(revision 3937)
+++ 	(revision )
@@ -1,615 +1,0 @@
-MODULE limupdate2
-   !!======================================================================
-   !!                     ***  MODULE  limupdate2  ***
-   !!   LIM-3 : Update of sea-ice global variables at the end of the time step
-   !!======================================================================
-   !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!    lim_update2   : computes update of sea-ice global variables from trend terms
-   !!----------------------------------------------------------------------
-   USE limrhg          ! ice rheology
-
-   USE dom_oce
-   USE oce             ! dynamics and tracers variables
-   USE in_out_manager
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice fields
-   USE dom_ice
-   USE phycst          ! physical constants
-   USE ice
-   USE limdyn
-   USE limtrp
-   USE limthd
-   USE limsbc
-   USE limdia
-   USE limdiahsb
-   USE limwri
-   USE limrst
-   USE thd_ice         ! LIM thermodynamic sea-ice variables
-   USE par_ice
-   USE limitd_th
-   USE limitd_me
-   USE limvar
-   USE prtctl           ! Print control
-   USE lbclnk           ! lateral boundary condition - MPP exchanges
-   USE wrk_nemo         ! work arrays
-   USE lib_fortran     ! glob_sum
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_update2   ! routine called by ice_step
-
-      REAL(wp)  ::   epsi06 = 1.e-06_wp   ! module constants
-      REAL(wp)  ::   epsi04 = 1.e-04_wp   !    -       -
-      REAL(wp)  ::   epsi10 = 1.e-10_wp   !    -       -
-      REAL(wp)  ::   epsi16 = 1.e-16_wp   !    -       -
-      REAL(wp)  ::   epsi20 = 1.e-20_wp   !    -       -
-      REAL(wp)  ::   rzero  = 0._wp       !    -       -
-      REAL(wp)  ::   rone   = 1._wp       !    -       -
-         
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limupdate.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_update2
-      !!-------------------------------------------------------------------
-      !!               ***  ROUTINE lim_update2  ***
-      !!               
-      !! ** Purpose :  Computes update of sea-ice global variables at 
-      !!               the end of the time step.
-      !!               Address pathological cases
-      !!               This place is very important
-      !!                
-      !! ** Method  :  
-      !!    Ice speed from ice dynamics
-      !!    Ice thickness, Snow thickness, Temperatures, Lead fraction
-      !!      from advection and ice thermodynamics 
-      !!
-      !! ** Action  : - 
-      !!---------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk, jl, jm    ! dummy loop indices
-      INTEGER ::   jbnd1, jbnd2
-      INTEGER ::   i_ice_switch
-      INTEGER ::   ind_im, layer      ! indices for internal melt
-      REAL(wp) ::   zweight, zesum, zhimax, z_da_i
-      REAL(wp) ::   zindb, zindsn, zindic
-      REAL(wp) ::   zindg, zh, zdvres, zviold2
-      REAL(wp) ::   zbigvalue, zvsold2, z_da_ex
-      REAL(wp) ::   z_prescr_hi, zat_i_old, ztmelts, ze_s
-
-      INTEGER , POINTER, DIMENSION(:,:,:) ::  internal_melt
-      REAL(wp), POINTER, DIMENSION(:) ::   zthick0, zqm0      ! thickness of the layers and heat contents for
-      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
-
-      ! mass and salt flux (clem)
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zviold, zvsold, zsmvold   ! old ice volume...
-      !!-------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj,jpl, internal_melt )   ! integer
-      CALL wrk_alloc( jkmax, zthick0, zqm0 )
-
-      CALL wrk_alloc( jpi,jpj,jpl,zviold, zvsold, zsmvold )   ! clem
-
-      !------------------------------------------------------------------------------
-      ! 1. Update of Global variables                                               |
-      !------------------------------------------------------------------------------
-
-      !-----------------------------
-      ! Update ice and snow volumes  
-      !-----------------------------
-      DO jl = 1, jpl
-         v_i(:,:,jl)  = v_i(:,:,jl) + d_v_i_thd(:,:,jl) 
-         v_s(:,:,jl)  = v_s(:,:,jl) + d_v_s_thd(:,:,jl)
-      END DO
- 
-      !---------------------------------------------
-      ! Ice concentration and ice heat content
-      !---------------------------------------------
-      a_i (:,:,:) = a_i (:,:,:) + d_a_i_thd(:,:,:)
-      e_i(:,:,:,:) = e_i(:,:,:,:) + d_e_i_thd(:,:,:,:)  
- 
-      !------------------------------
-      ! Snow temperature and ice age
-      !------------------------------
-      e_s (:,:,:,:) = e_s (:,:,:,:) + d_e_s_thd (:,:,:,:)
-      oa_i(:,:,:)   = oa_i(:,:,:)   + d_oa_i_thd(:,:,:)
-
-      !--------------
-      ! Ice salinity    
-      !--------------
-      IF(  num_sal == 2  .OR.  num_sal == 4  ) THEN      ! general case
-         smv_i(:,:,:) = smv_i(:,:,:) + d_smv_i_thd(:,:,:)
-      ENDIF
-
-      ! mass and salt flux init (clem)
-      zviold(:,:,:) = v_i(:,:,:)
-      zvsold(:,:,:) = v_s(:,:,:)
-      zsmvold(:,:,:) = smv_i(:,:,:)
-
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
-         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
-         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
-      CALL lim_var_glo2eqv
-
-      !---------------------------------
-      ! 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 )
-      !
-      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
-             END DO
-         END DO
-      END DO
-
-
-      !--------------------------------------
-      ! 2. Review of all pathological cases
-      !--------------------------------------
-
-
-      !----------------------------------------------------
-      ! 2.2) Rebin categories with thickness out of bounds
-      !----------------------------------------------------
-      DO jm = 1, jpm
-         jbnd1 = ice_cat_bounds(jm,1)
-         jbnd2 = ice_cat_bounds(jm,2)
-         IF (ice_ncat_types(jm) .GT. 1 )   CALL lim_itd_th_reb(jbnd1, jbnd2, jm)
-      END DO
-
-      !---------------------------------
-      ! 2.3) Melt of an internal layer
-      !---------------------------------
-      internal_melt(:,:,:) = 0
-
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  ztmelts = - tmut * s_i(ji,jj,jk,jl) + rtt
-                  IF ( ( ( e_i(ji,jj,jk,jl) .LE. 0.0 ) .OR. ( t_i(ji,jj,jk,jl) .GE. ztmelts ) ) &
-                    & .AND. ( v_i(ji,jj,jl) .GT. 0.0 ) .AND. ( a_i(ji,jj,jl) .GT. 0.0 ) ) THEN
-                     internal_melt(ji,jj,jl) = 1
-                  ENDIF
-               END DO ! ji
-            END DO ! jj
-         END DO !jk
-      END DO !jl
-
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               IF( internal_melt(ji,jj,jl) == 1 ) THEN
-                  ! initial ice thickness
-                  !-----------------------
-                  ht_i(ji,jj,jl) = v_i(ji,jj,jl) / a_i(ji,jj,jl)
-
-                  ! reduce ice thickness
-                  !-----------------------
-                  ind_im = 0
-                  zesum = 0.0
-                  DO jk = 1, nlay_i
-                     ztmelts = - tmut * s_i(ji,jj,jk,jl) + rtt
-                     IF ( ( e_i(ji,jj,jk,jl) .LE. 0.0 ) .OR. ( t_i(ji,jj,jk,jl) .GE. ztmelts ) ) ind_im = ind_im + 1
-                     zesum = zesum + e_i(ji,jj,jk,jl)
-                  END DO
-                  IF (ind_im .LT. nlay_i ) THEN
-                     smv_i(ji,jj,jl) = smv_i(ji,jj,jl) / ht_i(ji,jj,jl) * ( ht_i(ji,jj,jl) - REAL(ind_im)*ht_i(ji,jj,jl) / REAL(nlay_i) )
-                  ENDIF
-                  ht_i(ji,jj,jl) = ht_i(ji,jj,jl) - REAL(ind_im)*ht_i(ji,jj,jl) / REAL(nlay_i)
-                  v_i(ji,jj,jl)  = ht_i(ji,jj,jl) * a_i(ji,jj,jl)
-
-                  !CLEM
-                  zdvres = REAL(ind_im)*ht_i(ji,jj,jl) / REAL(nlay_i) * a_i(ji,jj,jl)
-                  !rdmicif(ji,jj) = rdmicif(ji,jj) - zdvres * rhoic
-                  !fsalt_res(ji,jj)  = fsalt_res(ji,jj) + sm_i(ji,jj,jl) * ( rhoic * zdvres / rdt_ice )
-
-                  ! redistribute heat
-                  !-----------------------
-                  ! old thicknesses and enthalpies
-                  ind_im = 0
-                  DO jk = 1, nlay_i
-                     ztmelts = - tmut * s_i(ji,jj,jk,jl) + rtt
-                     IF ( ( e_i(ji,jj,jk,jl) .GT. 0.0 ) .AND.  & 
-                        ( t_i(ji,jj,jk,jl) .LT. ztmelts ) ) THEN
-                        ind_im = ind_im + 1
-                        zthick0(ind_im) = ht_i(ji,jj,jl) * REAL(ind_im / nlay_i)
-                        zqm0   (ind_im) = MAX( e_i(ji,jj,jk,jl) , 0.0 )
-                     ENDIF
-                  END DO
-
-                  ! Redistributing energy on the new grid
-                  IF ( ind_im .GT. 0 ) THEN
-
-                     DO jk = 1, nlay_i
-                        e_i(ji,jj,jk,jl) = 0.0
-                        DO layer = 1, ind_im
-                           zweight         = MAX (  &
-                              MIN( ht_i(ji,jj,jl) * REAL(layer/ind_im) , ht_i(ji,jj,jl) * REAL(jk / nlay_i) ) -       &
-                              MAX( ht_i(ji,jj,jl) * REAL((layer-1)/ind_im) , ht_i(ji,jj,jl) * REAL((jk-1) / nlay_i) ) , 0.0 ) &
-                              /  ( ht_i(ji,jj,jl) / REAL(ind_im) )
-
-                           e_i(ji,jj,jk,jl) =  e_i(ji,jj,jk,jl) + zweight*zqm0(layer)
-                        END DO !layer
-                     END DO ! jk
-
-                     zesum = 0.0
-                     DO jk = 1, nlay_i
-                        zesum = zesum + e_i(ji,jj,jk,jl)
-                     END DO
-
-                  ELSE ! ind_im .EQ. 0, total melt
-                     e_i(ji,jj,jk,jl) = 0.0
-                  ENDIF
-
-               ENDIF ! internal_melt
-
-            END DO ! ji
-         END DO !jj
-      END DO !jl
-
-      internal_melt(:,:,:) = 0
-
-
-      ! Melt of snow
-      !--------------
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               ! snow energy of melting
-               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) = 1
-
-            END DO
-         END DO
-      END DO
-
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               IF ( internal_melt(ji,jj,jl) == 1 ) THEN
-                  zdvres = v_s(ji,jj,jl)
-                  ! release heat
-                  fheat_res(ji,jj) = fheat_res(ji,jj) + ze_s * zdvres / rdt_ice
-                  ! release mass
-                  !rdmsnif(ji,jj) =  rdmsnif(ji,jj) - zdvres * rhosn
-                  !
-                  v_s(ji,jj,jl)   = 0.0
-                  e_s(ji,jj,1,jl) = 0.0
-                 ENDIF
-            END DO
-         END DO
-      END DO
-
-      zbigvalue      = 1.0e+20
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-
-               !switches
-               zindb         = MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - 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
-               !-------------------------------------
-               zdvres = (zindsn * zindb - 1._wp) * v_s(ji,jj,jl)
-               v_s(ji,jj,jl) = v_s(ji,jj,jl) + zdvres
-
-               !rdmsnif(ji,jj) = rdmsnif(ji,jj) + zdvres * rhosn
- 
-               !--- 2.5 Correction to ice thickness
-               !-------------------------------------
-               zdvres = (zindb - 1._wp) * v_i(ji,jj,jl)
-               v_i(ji,jj,jl) = v_i(ji,jj,jl) + zdvres
-
-               !rdmicif(ji,jj) = rdmicif(ji,jj) + zdvres * rhoic
-               !fsalt_res(ji,jj)  = fsalt_res(ji,jj) - sm_i(ji,jj,jl) * ( rhoic * zdvres / rdt_ice )
-
-               !--- 2.6 Snow is transformed into ice if the original ice cover disappears
-               !----------------------------------------------------------------------------
-               zindg          = tms(ji,jj) *  MAX( 0._wp, SIGN( 1._wp, -v_i(ji,jj,jl) ) )
-               zdvres         = zindg * rhosn * v_s(ji,jj,jl) / rau0
-               v_i(ji,jj,jl)  = v_i(ji,jj,jl)  + zdvres
-
-               zdvres         = - zindg * v_s(ji,jj,jl) + zindg * v_i(ji,jj,jl) * ( rau0 - rhoic ) / rhosn
-               v_s(ji,jj,jl)  = v_s(ji,jj,jl)  + zdvres
-
-               !--- 2.7 Correction to ice concentrations 
-               !--------------------------------------------
-               !clem a_i(ji,jj,jl) = zindb * MAX(zindsn, zindic) * MAX( a_i(ji,jj,jl), epsi06 )
-               a_i(ji,jj,jl) = zindb * a_i(ji,jj,jl)
-
-               !-------------------------
-               ! 2.8) Snow heat content
-               !-------------------------
-               e_s(ji,jj,1,jl) = zindsn * ( MIN ( MAX ( 0.0, e_s(ji,jj,1,jl) ), zbigvalue ) )
-
-            END DO ! ji
-         END DO ! jj
-      END DO ! jl
-
-      !------------------------
-      ! 2.9) Ice heat content 
-      !------------------------
-
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  zindic        = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi04 ) ) 
-                  e_i(ji,jj,jk,jl)= zindic * ( MIN ( MAX ( 0.0, e_i(ji,jj,jk,jl) ), zbigvalue ) )
-               END DO ! ji
-            END DO ! jj
-         END DO !jk
-      END DO !jl
-
-
-      DO jm = 1, jpm
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               jl = ice_cat_bounds(jm,1)
-               !--- 2.12 Constrain the thickness of the smallest category above 5 cm
-               !----------------------------------------------------------------------
-               zindb         = MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - 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
-               ht_i(ji,jj,jl) = ht_i(ji,jj,jl)* zh
-               a_i (ji,jj,jl) = a_i(ji,jj,jl) / zh
-               !CLEM
-               v_i (ji,jj,jl) = a_i(ji,jj,jl) * ht_i(ji,jj,jl)
-               v_s (ji,jj,jl) = a_i(ji,jj,jl) * ht_s(ji,jj,jl)
-            END DO !ji
-         END DO !jj
-      END DO !jm
-
-      at_i(:,:) = 0.0
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-      
-      !--- 2.13 ice concentration should not exceed amax 
-      !-----------------------------------------------------
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            z_da_ex =  MAX( at_i(ji,jj) - amax , 0.0 )        
-            DO jl  = 1, jpl
-               zindb   =  MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi04 ) ) 
-               z_da_i = a_i(ji,jj,jl) * z_da_ex / MAX( at_i(ji,jj), epsi06 ) * zindb
-               a_i(ji,jj,jl) = a_i(ji,jj,jl) - z_da_i
-            END DO
-         END DO
-      END DO
-      at_i(:,:) = 0.0
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      ! Final thickness distribution rebinning
-      ! --------------------------------------
-      DO jm = 1, jpm
-         jbnd1 = ice_cat_bounds(jm,1)
-         jbnd2 = ice_cat_bounds(jm,2)
-         IF (ice_ncat_types(jm) .GT. 1 ) CALL lim_itd_th_reb(jbnd1, jbnd2, jm)
-         IF (ice_ncat_types(jm) .EQ. 1 ) THEN
-         ENDIF
-      END DO
-
-      !---------------------
-      ! 2.11) Ice salinity
-      !---------------------
-      !clem@bug: smv_i should be updated too: smv_i(:,:,:) = smv_i(:,:,:) + sm_i(:,:,:) * ( v_i(:,:,:) - zviold(:,:,:) )
-      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_m(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) + epsi20))
-                     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
-
-      ! -------------------
-      at_i(:,:) = a_i(:,:,1)
-      DO jl = 2, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      !------------------------------------------------------------------------------
-      ! 2) Corrections to avoid wrong values                                        |
-      !------------------------------------------------------------------------------
-      ! Ice drift
-      !------------
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1
-            IF ( at_i(ji,jj) .EQ. 0.0 ) THEN ! what to do if there is no ice
-               IF ( at_i(ji+1,jj) .EQ. 0.0 ) u_ice(ji,jj)   = 0.0 ! right side
-               IF ( at_i(ji-1,jj) .EQ. 0.0 ) u_ice(ji-1,jj) = 0.0 ! left side
-               IF ( at_i(ji,jj+1) .EQ. 0.0 ) v_ice(ji,jj)   = 0.0 ! upper side
-               IF ( at_i(ji,jj-1) .EQ. 0.0 ) v_ice(ji,jj-1) = 0.0 ! bottom side
-            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. )
- 
-      !--------------------------------
-      ! Update mass/salt fluxes (clem)
-      !--------------------------------
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               diag_res_pr(ji,jj) = diag_res_pr(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) / rdt_ice 
-               rdmicif(ji,jj) = rdmicif(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) * rhoic 
-               rdmsnif(ji,jj) = rdmsnif(ji,jj) + ( v_s(ji,jj,jl) - zvsold(ji,jj,jl) ) * rhosn 
-               fsalt_res(ji,jj) = fsalt_res(ji,jj) - ( smv_i(ji,jj,jl) - zsmvold(ji,jj,jl) ) * rhoic / rdt_ice 
-            END DO
-         END DO
-      END DO
-
-      ! -------------------------------
-      !- check conservation (C Rousset)
-      IF (ln_limdiahsb) THEN
-         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
-         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
- 
-         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
-         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
-
-         IF(lwp) THEN
-            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limupdate2) = ',(zchk_v_i * 86400.)
-            IF (    ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limupdate2) = ',(zchk_smv * 86400.)
-            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limupdate2) = ',(MINVAL(v_i) * 1.e-3)
-            IF ( MAXVAL( SUM(a_i(:,:,:),dim=3) ) > amax+epsi10 ) WRITE(numout,*) 'violation a_i>amax    (limupdate2) = ',MAXVAL(SUM(a_i,dim=3))
-            IF ( MINVAL( a_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation a_i<0               (limupdate2) = ',MINVAL(a_i)
-         ENDIF
-      ENDIF
-      !- check conservation (C Rousset)
-      ! -------------------------------
-
-      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_update2  : cell area   :')
-         CALL prt_ctl(tab2d_1=at_i       , clinfo1=' lim_update2  : at_i        :')
-         CALL prt_ctl(tab2d_1=vt_i       , clinfo1=' lim_update2  : vt_i        :')
-         CALL prt_ctl(tab2d_1=vt_s       , clinfo1=' lim_update2  : vt_s        :')
-         CALL prt_ctl(tab2d_1=strength   , clinfo1=' lim_update2  : strength    :')
-         CALL prt_ctl(tab2d_1=u_ice      , clinfo1=' lim_update2  : u_ice       :', tab2d_2=v_ice      , clinfo2=' v_ice       :')
-         CALL prt_ctl(tab2d_1=old_u_ice  , clinfo1=' lim_update2  : 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_update2  : ht_i        : ')
-            CALL prt_ctl(tab2d_1=ht_s       (:,:,jl)        , clinfo1= ' lim_update2  : ht_s        : ')
-            CALL prt_ctl(tab2d_1=t_su       (:,:,jl)        , clinfo1= ' lim_update2  : t_su        : ')
-            CALL prt_ctl(tab2d_1=t_s        (:,:,1,jl)      , clinfo1= ' lim_update2  : t_snow      : ')
-            CALL prt_ctl(tab2d_1=sm_i       (:,:,jl)        , clinfo1= ' lim_update2  : sm_i        : ')
-            CALL prt_ctl(tab2d_1=o_i        (:,:,jl)        , clinfo1= ' lim_update2  : o_i         : ')
-            CALL prt_ctl(tab2d_1=a_i        (:,:,jl)        , clinfo1= ' lim_update2  : a_i         : ')
-            CALL prt_ctl(tab2d_1=old_a_i    (:,:,jl)        , clinfo1= ' lim_update2  : old_a_i     : ')
-            CALL prt_ctl(tab2d_1=d_a_i_thd  (:,:,jl)        , clinfo1= ' lim_update2  : d_a_i_thd   : ')
-            CALL prt_ctl(tab2d_1=v_i        (:,:,jl)        , clinfo1= ' lim_update2  : v_i         : ')
-            CALL prt_ctl(tab2d_1=old_v_i    (:,:,jl)        , clinfo1= ' lim_update2  : old_v_i     : ')
-            CALL prt_ctl(tab2d_1=d_v_i_thd  (:,:,jl)        , clinfo1= ' lim_update2  : d_v_i_thd   : ')
-            CALL prt_ctl(tab2d_1=v_s        (:,:,jl)        , clinfo1= ' lim_update2  : v_s         : ')
-            CALL prt_ctl(tab2d_1=old_v_s    (:,:,jl)        , clinfo1= ' lim_update2  : old_v_s     : ')
-            CALL prt_ctl(tab2d_1=d_v_s_thd  (:,:,jl)        , clinfo1= ' lim_update2  : d_v_s_thd   : ')
-            CALL prt_ctl(tab2d_1=e_i        (:,:,1,jl)/1.0e9, clinfo1= ' lim_update2  : e_i1        : ')
-            CALL prt_ctl(tab2d_1=old_e_i    (:,:,1,jl)/1.0e9, clinfo1= ' lim_update2  : old_e_i1    : ')
-            CALL prt_ctl(tab2d_1=d_e_i_thd  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update2  : de_i1_thd   : ')
-            CALL prt_ctl(tab2d_1=e_i        (:,:,2,jl)/1.0e9, clinfo1= ' lim_update2  : e_i2        : ')
-            CALL prt_ctl(tab2d_1=old_e_i    (:,:,2,jl)/1.0e9, clinfo1= ' lim_update2  : old_e_i2    : ')
-            CALL prt_ctl(tab2d_1=d_e_i_thd  (:,:,2,jl)/1.0e9, clinfo1= ' lim_update2  : de_i2_thd   : ')
-            CALL prt_ctl(tab2d_1=e_s        (:,:,1,jl)      , clinfo1= ' lim_update2  : e_snow      : ')
-            CALL prt_ctl(tab2d_1=old_e_s    (:,:,1,jl)      , clinfo1= ' lim_update2  : old_e_snow  : ')
-            CALL prt_ctl(tab2d_1=d_e_s_thd  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update2  : d_e_s_thd   : ')
-            CALL prt_ctl(tab2d_1=smv_i      (:,:,jl)        , clinfo1= ' lim_update2  : smv_i       : ')
-            CALL prt_ctl(tab2d_1=old_smv_i  (:,:,jl)        , clinfo1= ' lim_update2  : old_smv_i   : ')
-            CALL prt_ctl(tab2d_1=d_smv_i_thd(:,:,jl)        , clinfo1= ' lim_update2  : d_smv_i_thd : ')
-            CALL prt_ctl(tab2d_1=oa_i       (:,:,jl)        , clinfo1= ' lim_update2  : oa_i        : ')
-            CALL prt_ctl(tab2d_1=old_oa_i   (:,:,jl)        , clinfo1= ' lim_update2  : old_oa_i    : ')
-            CALL prt_ctl(tab2d_1=d_oa_i_thd (:,:,jl)        , clinfo1= ' lim_update2  : d_oa_i_thd  : ')
-            CALL prt_ctl(tab2d_1=REAL(patho_case(:,:,jl))   , clinfo1= ' lim_update2  : 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_update2  : t_i       : ')
-            END DO
-         END DO
-
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Heat / FW fluxes : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=fmmec  , clinfo1= ' lim_update2 : fmmec : ', tab2d_2=fhmec     , clinfo2= ' fhmec     : ')
-         CALL prt_ctl(tab2d_1=sst_m  , clinfo1= ' lim_update2 : sst   : ', tab2d_2=sss_m     , clinfo2= ' sss       : ')
-         CALL prt_ctl(tab2d_1=fhbri  , clinfo1= ' lim_update2 : fhbri : ', tab2d_2=fheat_rpo , clinfo2= ' fheat_rpo : ')
-
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Stresses : ')
-         CALL prt_ctl_info('   ~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=utau       , clinfo1= ' lim_update2 : utau      : ', tab2d_2=vtau       , clinfo2= ' vtau      : ')
-         CALL prt_ctl(tab2d_1=utau_ice   , clinfo1= ' lim_update2 : utau_ice  : ', tab2d_2=vtau_ice   , clinfo2= ' vtau_ice  : ')
-         CALL prt_ctl(tab2d_1=u_oce      , clinfo1= ' lim_update2 : u_oce     : ', tab2d_2=v_oce      , clinfo2= ' v_oce     : ')
-      ENDIF
-   
-      CALL wrk_dealloc( jpi,jpj,jpl, internal_melt )   ! integer
-      CALL wrk_dealloc( jkmax, zthick0, zqm0 )
-
-      CALL wrk_dealloc( jpi,jpj,jpl,zviold, zvsold, zsmvold )   ! clem
-
-   END SUBROUTINE lim_update2
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty Module               No sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_update2     ! Empty routine
-   END SUBROUTINE lim_update2
-
-#endif
-
-END MODULE limupdate2
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limvar.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limvar.F90	(revision 3937)
+++ 	(revision )
@@ -1,556 +1,0 @@
-MODULE limvar
-   !!======================================================================
-   !!                       ***  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
-   !!======================================================================
-   !! History :   -   ! 2006-01 (M. Vancoppenolle) Original code
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_var_agg       : 
-   !!   lim_var_glo2eqv   :
-   !!   lim_var_eqv2glo   :
-   !!   lim_var_salprof   : 
-   !!   lim_var_salprof1d :
-   !!   lim_var_bv        :
-   !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE phycst           ! physical constants (ocean directory) 
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE ice              ! LIM variables
-   USE par_ice          ! LIM parameters
-   USE dom_ice          ! LIM domain
-   USE thd_ice          ! LIM thermodynamics
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE lib_fortran      ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_var_agg          !
-   PUBLIC   lim_var_glo2eqv      !
-   PUBLIC   lim_var_eqv2glo      !
-   PUBLIC   lim_var_salprof      !
-   PUBLIC   lim_var_icetm        !
-   PUBLIC   lim_var_bv           !
-   PUBLIC   lim_var_salprof1d    !
-
-   REAL(wp) ::   epsi20 = 1.e-20_wp   ! module constants
-   REAL(wp) ::   epsi16 = 1.e-16_wp   !    -       -
-   REAL(wp) ::   epsi13 = 1.e-13_wp   !    -       -
-   REAL(wp) ::   epsi10 = 1.e-10_wp   !    -       -
-   REAL(wp) ::   epsi06 = 1.e-06_wp   !    -       -
-   REAL(wp) ::   zzero = 0.e0        !    -       -
-   REAL(wp) ::   zone  = 1.e0        !    -       -
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limvar.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_var_agg( kn )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_var_agg  ***
-      !!
-      !! ** Purpose :   aggregates ice-thickness-category variables to all-ice variables
-      !!              i.e. it turns VGLO into VAGG
-      !! ** Method  :
-      !!
-      !! ** Arguments : n = 1, at_i vt_i only
-      !!                n = 2 everything
-      !!
-      !! note : you could add an argument when you need only at_i, vt_i
-      !!        and when you need everything
-      !!------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kn     ! =1 at_i & vt only ; = what is needed
-      !
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) ::   zinda, zindb
-      !!------------------------------------------------------------------
-
-      !--------------------
-      ! Compute variables
-      !--------------------
-      vt_i (:,:) = 0._wp
-      vt_s (:,:) = 0._wp
-      at_i (:,:) = 0._wp
-      ato_i(:,:) = 1._wp
-      !
-      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) - epsi16 ) ) 
-               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._wp - at_i(ji,jj), 0._wp )   ! open water fraction
-         END DO
-      END DO
-
-      IF( kn > 1 ) THEN
-         et_s (:,:) = 0._wp
-         ot_i (:,:) = 0._wp
-         smt_i(:,:) = 0._wp
-         et_i (:,:) = 0._wp
-         !
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zinda = MAX( zzero , SIGN( zone , vt_i(ji,jj) - epsi16 ) ) 
-                  zindb = MAX( zzero , SIGN( zone , at_i(ji,jj) - epsi16 ) ) 
-                  et_s(ji,jj)  = et_s(ji,jj)  + e_s(ji,jj,1,jl)                                       ! snow heat content
-                  smt_i(ji,jj) = smt_i(ji,jj) + smv_i(ji,jj,jl) / MAX( vt_i(ji,jj) , epsi16 ) * zinda   ! ice salinity
-                  ot_i(ji,jj)  = ot_i(ji,jj)  + oa_i(ji,jj,jl)  / MAX( at_i(ji,jj) , epsi16 ) * zindb   ! ice age
-               END DO
-            END DO
-         END DO
-          !
-         DO jl = 1, jpl
-            DO jk = 1, nlay_i
-               et_i(:,:) = et_i(:,:) + e_i(:,:,jk,jl)       ! ice heat content
-            END DO
-         END DO
-         !
-      ENDIF
-      !
-   END SUBROUTINE lim_var_agg
-
-
-   SUBROUTINE lim_var_glo2eqv
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_var_glo2eqv ***
-      !!
-      !! ** Purpose :   computes equivalent variables as function of global variables 
-      !!              i.e. it turns VGLO into VEQV
-      !!------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) ::   zq_i, zaaa, zbbb, zccc, zdiscrim     ! local scalars
-      REAL(wp) ::   ztmelts, zindb, zq_s, zfac1, zfac2   !   -      -
-      !!------------------------------------------------------------------
-
-      !-------------------------------------------------------
-      ! Ice thickness, snow thickness, ice salinity, ice age
-      !-------------------------------------------------------
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp,- a_i(ji,jj,jl) + epsi10 ) )   !0 if no ice and 1 if yes
-               ht_i(ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi10 ) * zindb
-               ht_s(ji,jj,jl) = v_s (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi10 ) * zindb
-               o_i(ji,jj,jl)  = oa_i(ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi10 ) * zindb
-            END DO
-         END DO
-      END DO
-
-      IF(  num_sal == 2  .OR.  num_sal == 4  )THEN
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp,- a_i(ji,jj,jl) + epsi10 ) )   !0 if no ice and 1 if yes
-                  sm_i(ji,jj,jl) = smv_i(ji,jj,jl) / MAX( v_i(ji,jj,jl) , epsi10 ) * zindb
-               END DO
-            END DO
-         END DO
-      ENDIF
-
-      CALL lim_var_salprof      ! salinity profile
-
-      !-------------------
-      ! 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 ) * REAL(nlay_i,wp) 
-                  zindb   = 1.0 - MAX( 0.0 , SIGN( 1.0 , - v_i(ji,jj,jl) ) )     ! zindb = 0 if no ice and 1 if yes
-                  zq_i    = zq_i * unit_fac * zindb                              !convert units
-                  ztmelts = -tmut * s_i(ji,jj,jk,jl) + rtt                       ! Ice layer melt temperature
-                  !
-                  zaaa       =  cpic                  ! Conversion q(S,T) -> T (second order equation)
-                  zbbb       =  ( rcp - cpic ) * ( ztmelts - rtt ) + zq_i / rhoic - lfus
-                  zccc       =  lfus * (ztmelts-rtt)
-                  zdiscrim   =  SQRT( MAX(zbbb*zbbb - 4._wp*zaaa*zccc , 0._wp) )
-                  t_i(ji,jj,jk,jl) = rtt + zindb *( - zbbb - zdiscrim ) / ( 2.0 *zaaa )
-                  t_i(ji,jj,jk,jl) = MIN( rtt, MAX( 173.15_wp, t_i(ji,jj,jk,jl) ) )       ! 100-rtt < t_i < rtt
-               END DO
-            END DO
-         END DO
-      END DO
-
-      !--------------------
-      ! Snow temperatures
-      !--------------------
-      zfac1 = 1._wp / ( rhosn * cpic )
-      zfac2 = lfus / cpic  
-      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]
-                  zq_s  = e_s(ji,jj,jk,jl) / ( area(ji,jj) * MAX( v_s(ji,jj,jl) , epsi06 ) ) * REAL(nlay_s,wp)
-                  zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - v_s(ji,jj,jl) ) )     ! zindb = 0 if no ice and 1 if yes
-                  zq_s  = zq_s * unit_fac * zindb                                    ! convert units
-                  !
-                  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) ) )     ! 100-rtt < t_i < rtt
-               END DO
-            END DO
-         END DO
-      END DO
-
-      !-------------------
-      ! Mean temperature
-      !-------------------
-      tm_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zindb = (  1._wp - MAX( 0._wp , SIGN( 1._wp , - vt_i(ji,jj) + epsi10 ) )  )
-                  tm_i(ji,jj) = tm_i(ji,jj) + zindb * t_i(ji,jj,jk,jl) * v_i(ji,jj,jl)   &
-                     &                      / (  REAL(nlay_i,wp) * MAX( vt_i(ji,jj) , epsi10 )  )
-               END DO
-            END DO
-         END DO
-      END DO
-      !
-   END SUBROUTINE lim_var_glo2eqv
-
-
-   SUBROUTINE lim_var_eqv2glo
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_var_eqv2glo ***
-      !!
-      !! ** Purpose :   computes global variables as function of equivalent variables
-      !!                i.e. it turns VEQV into VGLO
-      !! ** Method  :
-      !!
-      !! ** History :  (01-2006) Martin Vancoppenolle, UCL-ASTR
-      !!------------------------------------------------------------------
-      !
-      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 :   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)
-      !!------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop index
-      REAL(wp) ::   dummy_fac0, dummy_fac1, dummy_fac, zsal      ! local scalar
-      REAL(wp) ::   zind0, zind01, zindbal, zargtemp , zs_zero   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   z_slope_s, zalpha   ! 3D pointer
-      !!------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, jpl, z_slope_s, zalpha )
-
-      !---------------------------------------
-      ! Vertically constant, constant in time
-      !---------------------------------------
-      IF( num_sal == 1 )   s_i(:,:,:,:) = bulk_sal
-
-      !-----------------------------------
-      ! Salinity profile, varying in time
-      !-----------------------------------
-
-      IF(   num_sal == 2  .OR.   num_sal == 4   ) THEN
-         !
-         DO jk = 1, nlay_i
-            s_i(:,:,jk,:)  = sm_i(:,:,:)
-         END DO
-         !
-         DO jl = 1, jpl                               ! Slope of the linear profile 
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  z_slope_s(ji,jj,jl) = 2._wp * sm_i(ji,jj,jl) / MAX( 0.01 , ht_i(ji,jj,jl) )
-               END DO
-            END DO
-         END DO
-         !
-         dummy_fac0 = 1._wp / ( s_i_0 - s_i_1 )       ! Weighting factor between zs_zero and zs_inf
-         dummy_fac1 = s_i_1 / ( s_i_1 - s_i_0 )
-
-         zalpha(:,:,:) = 0._wp
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ! zind0 = 1 if sm_i le s_i_0 and 0 otherwise
-                  zind0  = MAX( 0._wp   , SIGN( 1._wp  , 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._wp - zind0 ) * MAX( 0._wp   , SIGN( 1._wp  , s_i_1 - sm_i(ji,jj,jl) ) ) 
-                  ! If 2.sm_i GE sss_m then zindbal = 1
-                  zindbal = MAX( 0._wp , SIGN( 1._wp , 2._wp * sm_i(ji,jj,jl) - sss_m(ji,jj) ) )
-                  zalpha(ji,jj,jl) = zind0  + zind01 * ( sm_i(ji,jj,jl) * dummy_fac0 + dummy_fac1 )
-                  zalpha(ji,jj,jl) = zalpha(ji,jj,jl) * ( 1._wp - zindbal )
-               END DO
-            END DO
-         END DO
-
-         dummy_fac = 1._wp / REAL( nlay_i )                   ! Computation of the profile
-         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 = z_slope_s(ji,jj,jl) * ( REAL(jk,wp) - 0.5_wp ) * ht_i(ji,jj,jl) * dummy_fac
-                     !                                      ! weighting the profile
-                     s_i(ji,jj,jk,jl) = zalpha(ji,jj,jl) * zs_zero + ( 1._wp - 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
-      !-------------------------------------------------------
-
-      IF( num_sal == 3 ) THEN      ! Schwarzacher (1959) multiyear salinity profile (mean = 2.30)
-         !
-         sm_i(:,:,:) = 2.30_wp
-         !
-         DO jl = 1, jpl
-!CDIR NOVERRCHK
-            DO jk = 1, nlay_i
-               zargtemp  = ( REAL(jk,wp) - 0.5_wp ) / REAL(nlay_i,wp)
-               zsal =  1.6_wp * (  1._wp - COS( rpi * zargtemp**(0.407_wp/(0.573_wp+zargtemp)) )  )
-               s_i(:,:,jk,jl) =  zsal
-            END DO
-         END DO
-
-      ENDIF ! num_sal
-      !
-      CALL wrk_dealloc( jpi, jpj, jpl, z_slope_s, zalpha )
-      !
-   END SUBROUTINE lim_var_salprof
-
-
-   SUBROUTINE lim_var_icetm
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_var_icetm ***
-      !!
-      !! ** Purpose :   computes mean sea ice temperature
-      !!------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) ::   zindb   !   -      -
-      !!------------------------------------------------------------------
-
-      ! Mean sea ice temperature
-      tm_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zindb = (  1._wp - MAX( 0._wp , SIGN( 1._wp , - vt_i(ji,jj) + epsi10 ) )  )
-                  tm_i(ji,jj) = tm_i(ji,jj) + zindb * t_i(ji,jj,jk,jl) * v_i(ji,jj,jl)   &
-                     &                      / (  REAL(nlay_i,wp) * MAX( vt_i(ji,jj) , epsi10 )  )
-               END DO
-            END DO
-         END DO
-      END DO
-
-   END SUBROUTINE lim_var_icetm
-
-
-   SUBROUTINE lim_var_bv
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_var_bv ***
-      !!
-      !! ** Purpose :   computes mean brine volume (%) in sea ice
-      !!
-      !! ** Method  : e = - 0.054 * S (ppt) / T (C)
-      !!
-      !! References : Vancoppenolle et al., JGR, 2007
-      !!------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) ::   zbvi, zinda, zindb      ! local scalars
-      !!------------------------------------------------------------------
-      !
-      bv_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zinda = (  1._wp - MAX( 0._wp , SIGN( 1._wp , (t_i(ji,jj,jk,jl) - rtt) + epsi16 ) )  )
-                  zindb = (  1._wp - MAX( 0._wp , SIGN( 1._wp , - vt_i(ji,jj) + epsi16 ) )  )
-                  zbvi  = - zinda * tmut * s_i(ji,jj,jk,jl) / MIN( t_i(ji,jj,jk,jl) - rtt, - epsi16 )   &
-                     &                   * v_i(ji,jj,jl)    / REAL(nlay_i,wp)
-                  bv_i(ji,jj) = bv_i(ji,jj) + zindb * zbvi  / MAX( vt_i(ji,jj) , epsi16 )
-               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
-      !!-------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kideb, kiut   ! thickness category index
-      !
-      INTEGER  ::   ji, jk    ! dummy loop indices
-      INTEGER  ::   zji, zjj  ! local integers
-      REAL(wp) ::   dummy_fac0, dummy_fac1, dummy_fac2, zargtemp, zsal   ! local scalars
-      REAL(wp) ::   zalpha, zind0, zind01, zindbal, zs_zero              !   -      -
-      !
-      REAL(wp), POINTER, DIMENSION(:) ::   z_slope_s
-      !!---------------------------------------------------------------------
-
-      CALL wrk_alloc( jpij, z_slope_s )
-
-      !---------------------------------------
-      ! Vertically constant, constant in time
-      !---------------------------------------
-      IF( num_sal == 1 )   s_i_b(:,:) = bulk_sal
-
-      !------------------------------------------------------
-      ! Vertically varying salinity profile, varying in time
-      !------------------------------------------------------
-
-      IF(  num_sal == 2  .OR.  num_sal == 4  ) THEN
-         !
-         DO ji = kideb, kiut          ! Slope of the linear profile zs_zero
-            z_slope_s(ji) = 2._wp * sm_i_b(ji) / MAX( 0.01 , ht_i_b(ji) )
-         END DO
-
-         ! Weighting factor between zs_zero and zs_inf
-         !---------------------------------------------
-         dummy_fac0 = 1._wp / ( s_i_0 - s_i_1 )
-         dummy_fac1 = s_i_1 / ( s_i_1 - s_i_0 )
-         dummy_fac2 = 1._wp / REAL(nlay_i,wp)
-
-!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
-               ! zind0 = 1 if sm_i le s_i_0 and 0 otherwise
-               zind0  = MAX( 0._wp , SIGN( 1._wp  , s_i_0 - sm_i_b(ji) ) ) 
-               ! zind01 = 1 if sm_i is between s_i_0 and s_i_1 and 0 othws 
-               zind01 = ( 1._wp - zind0 ) * MAX( 0._wp , SIGN( 1._wp , s_i_1 - sm_i_b(ji) ) ) 
-               ! if 2.sm_i GE sss_m then zindbal = 1
-               zindbal = MAX( 0._wp , SIGN( 1._wp , 2._wp * sm_i_b(ji) - sss_m(zji,zjj) ) )
-               !
-               zalpha = (  zind0 + zind01 * ( sm_i_b(ji) * dummy_fac0 + dummy_fac1 )  ) * ( 1.0 - zindbal )
-               !
-               zs_zero = z_slope_s(ji) * ( REAL(jk,wp) - 0.5_wp ) * ht_i_b(ji) * dummy_fac2
-               ! weighting the profile
-               s_i_b(ji,jk) = zalpha * zs_zero + ( 1._wp - zalpha ) * sm_i_b(ji)
-            END DO ! ji
-         END DO ! jk
-
-      ENDIF ! num_sal
-
-      !-------------------------------------------------------
-      ! Vertically varying salinity profile, constant in time
-      !-------------------------------------------------------
-
-      IF( num_sal == 3 ) THEN      ! Schwarzacher (1959) multiyear salinity profile (mean = 2.30)
-         !
-         sm_i_b(:) = 2.30_wp
-         !
-!CDIR NOVERRCHK
-         DO jk = 1, nlay_i
-            zargtemp  = ( REAL(jk,wp) - 0.5_wp ) / REAL(nlay_i,wp)
-            zsal =  1.6_wp * (  1._wp - COS( rpi * zargtemp**(0.407_wp/(0.573_wp+zargtemp)) )  )
-            DO ji = kideb, kiut
-               s_i_b(ji,jk) = zsal
-            END DO
-         END DO
-         !
-      ENDIF
-      !
-      CALL wrk_dealloc( jpij, z_slope_s )
-      !
-   END SUBROUTINE lim_var_salprof1d
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Dummy module          NO  LIM3 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: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limwri.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limwri.F90	(revision 3937)
+++ 	(revision )
@@ -1,599 +1,0 @@
-MODULE limwri
-   !!======================================================================
-   !!                     ***  MODULE  limwri  ***
-   !!         Ice diagnostics :  write ice output files
-   !!======================================================================
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_wri      : write of the diagnostics variables in ouput file 
-   !!   lim_wri_init : initialization and namelist read
-   !!   lim_wri_state : write for initial state or/and abandon
-   !!----------------------------------------------------------------------
-   USE ioipsl
-   USE dianam          ! build name of file (routine)
-   USE phycst
-   USE dom_oce
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice fields
-   USE dom_ice
-   USE ice
-   USE limvar
-   USE in_out_manager
-   USE lbclnk
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! work arrays
-   USE par_ice
-   USE iom
-   USE timing          ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC lim_wri        ! routine called by lim_step.F90
-   PUBLIC lim_wri_state  ! called by dia_wri_state 
-
-   INTEGER, PARAMETER ::   jpnoumax = 43   !: maximum number of variable for ice output
-   
-   INTEGER  ::   noumef             ! number of fields
-   INTEGER  ::   noumefa            ! number of additional fields
-   INTEGER  ::   add_diag_swi       ! additional diagnostics
-   INTEGER  ::   nz                                         ! dimension for the itd field
-
-   REAL(wp) , DIMENSION(jpnoumax) ::   cmulti         ! multiplicative constant
-   REAL(wp) , DIMENSION(jpnoumax) ::   cadd           ! additive constant
-   REAL(wp) , DIMENSION(jpnoumax) ::   cmultia        ! multiplicative constant
-   REAL(wp) , DIMENSION(jpnoumax) ::   cadda          ! additive constant
-   CHARACTER(len = 35), DIMENSION(jpnoumax) ::   titn, titna   ! title of the field
-   CHARACTER(len = 8 ), DIMENSION(jpnoumax) ::   nam , nama    ! name of the field
-   CHARACTER(len = 8 ), DIMENSION(jpnoumax) ::   uni , unia    ! unit of the field
-   INTEGER            , DIMENSION(jpnoumax) ::   nc  , nca     ! switch for saving field ( = 1 ) or not ( = 0 )
-
-   REAL(wp)  ::   epsi06 = 1e-6_wp
-   REAL(wp)  ::   zzero  = 0._wp
-   REAL(wp)  ::   zone   = 1._wp      
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limwri.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-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
-      !
-      INTEGER ::  ji, jj, jk, jl, jf, ipl ! dummy loop indices
-      INTEGER ::  ierr
-      REAL(wp),DIMENSION(1) ::   zdept
-      REAL(wp) ::  zsto, zjulian, zout, zindh, zinda, zindb, zindc
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zcmo, zcmoa
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zfield
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zmaskitd, zoi, zei
-
-      CHARACTER(len = 40) ::   clhstnam, clop, clhstnama
-
-      INTEGER , SAVE ::   nice, nhorid, ndim, niter, ndepid
-      INTEGER , SAVE ::   nicea, nhorida, ndimitd
-      INTEGER , ALLOCATABLE, DIMENSION(:), SAVE ::   ndex51
-      INTEGER , ALLOCATABLE, DIMENSION(:), SAVE ::   ndexitd
-      !!-------------------------------------------------------------------
-
-      IF( nn_timing == 1 )  CALL timing_start('limwri')
-
-      CALL wrk_alloc( jpi, jpj, zfield )
-      CALL wrk_alloc( jpi, jpj, jpnoumax, zcmo, zcmoa )
-      CALL wrk_alloc( jpi, jpj, jpl, zmaskitd, zoi, zei )
-
-      ipl = jpl
-
-      IF( numit == nstart ) THEN 
-
-         ALLOCATE( ndex51(jpij), ndexitd(jpij*jpl), STAT=ierr )
-         IF( lk_mpp    )   CALL mpp_sum ( ierr )
-         IF( ierr /= 0 ) THEN
-            CALL ctl_stop( 'lim_wri : unable to allocate standard arrays' )   ;   RETURN
-         ENDIF
-
-         CALL lim_wri_init 
-
-         IF(lwp) WRITE(numout,*) ' lim_wri, first time step '
-         IF(lwp) WRITE(numout,*) ' add_diag_swi ', add_diag_swi
-
-         !--------------------
-         !  1) Initialization
-         !--------------------
-
-         !-------------
-         ! Normal file
-         !-------------
-
-         zsto     = rdt_ice
-         IF( ln_mskland )   THEN   ;   clop = "ave(only(x))"   ! put 1.e+20 on land (very expensive!!)
-         ELSE                      ;   clop = "ave(x)"         ! no use of the mask value (require less cpu time)
-         ENDIF
-         zout     = nwrite * rdt_ice / nn_fsbc
-         niter    = ( nit000 - 1 ) / nn_fsbc
-         zdept(1) = 0.
-
-         CALL ymds2ju ( nyear, nmonth, nday, rdt, zjulian )
-         zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
-         CALL dia_nam ( clhstnam, nwrite, 'icemod_old' )
-         CALL histbeg ( clhstnam, jpi, glamt, jpj, gphit, 1, jpi, 1, jpj, niter, zjulian, rdt_ice,   &
-            &           nhorid, nice, domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nice, "deptht", "Vertical T levels", "m", 1, zdept, ndepid, "down")
-         CALL wheneq  ( jpij , tmask(:,:,1), 1, 1., ndex51, ndim)
-
-         DO jf = 1 , noumef
-            IF(lwp) WRITE(numout,*) 'jf', jf
-            IF ( nc(jf) == 1 ) THEN
-               CALL histdef( nice, nam(jf), titn(jf), uni(jf), jpi, jpj &
-                  , nhorid, 1, 1, 1, -99, 32, clop, zsto, zout )
-               IF(lwp) WRITE(numout,*) 'nice, nam(jf), titn(jf), uni(jf), nhorid, clop, zsto, zout'
-               IF(lwp) WRITE(numout,*)  nice, nam(jf), titn(jf), uni(jf), nhorid, clop, zsto, zout 
-            ENDIF
-         END DO
-
-         CALL histend(nice, snc4set)
-
-         !-----------------
-         ! ITD file output
-         !-----------------
-         zsto     = rdt_ice
-         clop     = "ave(x)"
-         zout     = nwrite * rdt_ice / nn_fsbc
-         zdept(1) = 0.
-
-         CALL dia_nam ( clhstnama, nwrite, 'icemoa' )
-         CALL histbeg ( clhstnama, jpi, glamt, jpj, gphit,         &
-            1, jpi, 1, jpj,            & ! zoom
-            niter, zjulian, rdt_ice,   & ! time
-            nhorida,                   & ! ? linked with horizontal ...
-            nicea , domain_id=nidom, snc4chunks=snc4set)                  ! file 
-         CALL histvert( nicea, "icethi", "L levels","m", ipl , hi_mean , nz )
-         DO jl = 1, jpl
-            zmaskitd(:,:,jl) = tmask(:,:,1)
-         END DO
-         CALL wheneq  ( jpij , tmask(:,:,1), 1, 1., ndex51, ndim)
-         CALL wheneq( jpi*jpj*jpl, zmaskitd, 1, 1., ndexitd, ndimitd  )  
-         CALL histdef( nicea, "iice_itd", "Ice area in categories"         , "-"    ,   &  
-            jpi, jpj, nhorida, jpl, 1, jpl, nz, 15, clop, zsto, zout )
-         CALL histdef( nicea, "iice_hid", "Ice thickness in categories"    , "m"    ,   &  
-            jpi, jpj, nhorida, jpl, 1, jpl, nz, 15, clop, zsto, zout )
-         CALL histdef( nicea, "iice_hsd", "Snow depth in in categories"    , "m"    ,   &  
-            jpi, jpj, nhorida, jpl, 1, jpl, nz, 15, clop, zsto, zout )
-         CALL histdef( nicea, "iice_std", "Ice salinity distribution"      , "ppt"  ,   &  
-            jpi, jpj, nhorida, jpl, 1, jpl, nz, 15, clop, zsto, zout )
-         CALL histdef( nicea, "iice_otd", "Ice age distribution"               , "days",   &  
-            jpi, jpj, nhorida, jpl, 1, jpl, nz, 15, clop, zsto, zout )
-         CALL histdef( nicea, "iice_etd", "Brine volume distr. "               , "%"    ,   &  
-            jpi, jpj, nhorida, jpl, 1, jpl, nz, 15, clop, zsto, zout )
-         CALL histend(nicea, snc4set)
-      ENDIF
-
-      !     !-----------------------------------------------------------------------!
-      !     !--2. Computation of instantaneous values                               ! 
-      !     !-----------------------------------------------------------------------!
-
-      !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-      IF( ln_nicep ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_wri : write ice outputs in NetCDF files at time : ', nyear, nmonth, nday, numit
-         WRITE(numout,*) '~~~~~~~ '
-         WRITE(numout,*) ' kindic = ', kindic
-      ENDIF
-      !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
-      !-- calculs des valeurs instantanees
-      zcmo ( 1:jpi, 1:jpj, 1:jpnoumax ) = 0._wp
-      zcmoa( 1:jpi, 1:jpj, 1:jpnoumax ) = 0._wp
-
-      ! Ice surface temperature and some fluxes
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zinda  = MAX( zzero , SIGN( zone , at_i(ji,jj) - epsi06 ) )
-               zcmo(ji,jj,17) = zcmo(ji,jj,17) + a_i(ji,jj,jl)*qsr_ice (ji,jj,jl) 
-               zcmo(ji,jj,18) = zcmo(ji,jj,18) + a_i(ji,jj,jl)*qns_ice(ji,jj,jl) 
-               zcmo(ji,jj,27) = zcmo(ji,jj,27) + zinda*(t_su(ji,jj,jl)-rtt)*a_i(ji,jj,jl)/MAX(at_i(ji,jj),epsi06)
-               zcmo(ji,jj,21) = zcmo(ji,jj,21) + zinda*oa_i(ji,jj,jl)/MAX(at_i(ji,jj),epsi06) 
-            END DO
-         END DO
-      END DO
-
-      ! Mean sea ice temperature
-      CALL lim_var_icetm
-
-      ! Brine volume
-      CALL lim_var_bv
-
-      DO jj = 2 , jpjm1
-         DO ji = 2 , jpim1
-            zinda  = MAX( zzero , SIGN( zone , at_i(ji,jj) - epsi06 ) )
-            zindb  = MAX( zzero , SIGN( zone , at_i(ji,jj) ) )
-
-            zcmo(ji,jj,1)  = at_i(ji,jj)
-            zcmo(ji,jj,2)  = vt_i(ji,jj) / MAX( at_i(ji,jj), epsi06 ) * zinda
-            zcmo(ji,jj,3)  = vt_s(ji,jj) / MAX( at_i(ji,jj), epsi06 ) * zinda
-            zcmo(ji,jj,4)  = diag_bot_gr(ji,jj) * 86400.0     ! Bottom thermodynamic ice production
-            zcmo(ji,jj,5)  = diag_dyn_gr(ji,jj) * 86400.0     ! Dynamic ice production (rid/raft)
-            zcmo(ji,jj,22) = diag_lat_gr(ji,jj) * 86400.0     ! Lateral thermodynamic ice production
-            zcmo(ji,jj,23) = diag_sni_gr(ji,jj) * 86400.0     ! Snow ice production ice production
-            zcmo(ji,jj,24) = (tm_i(ji,jj) - rtt) * zinda
-
-            zcmo(ji,jj,6)  = fbif(ji,jj)*at_i(ji,jj)
-            zcmo(ji,jj,7)  = (  u_ice(ji,jj) * tmu(ji,jj) + u_ice(ji-1,jj) * tmu(ji-1,jj) ) * 0.5_wp
-            zcmo(ji,jj,8)  = (  v_ice(ji,jj) * tmv(ji,jj) + v_ice(ji,jj-1) * tmv(ji,jj-1) ) * 0.5_wp
-            zcmo(ji,jj,9)  = sst_m(ji,jj)
-            zcmo(ji,jj,10) = sss_m(ji,jj)
-
-            zcmo(ji,jj,11) = qns(ji,jj) + qsr(ji,jj)
-            zcmo(ji,jj,12) = qsr(ji,jj)
-            zcmo(ji,jj,13) = qns(ji,jj)
-            zcmo(ji,jj,14) = fhbri(ji,jj)
-            zcmo(ji,jj,15) = utau_ice(ji,jj)
-            zcmo(ji,jj,16) = vtau_ice(ji,jj)
-            zcmo(ji,jj,17) = zcmo(ji,jj,17) + ( 1._wp - at_i(ji,jj) ) * qsr(ji,jj)
-            zcmo(ji,jj,18) = zcmo(ji,jj,18) + ( 1._wp - at_i(ji,jj) ) * qns(ji,jj)
-            zcmo(ji,jj,19) = sprecip(ji,jj)
-            zcmo(ji,jj,20) = smt_i(ji,jj)
-            zcmo(ji,jj,25) = et_i(ji,jj)
-            zcmo(ji,jj,26) = et_s(ji,jj)
-            zcmo(ji,jj,28) = 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) * zindb
-            zcmo(ji,jj,32) = strength(ji,jj)
-            zcmo(ji,jj,33) = SQRT(  zcmo(ji,jj,7)*zcmo(ji,jj,7) + zcmo(ji,jj,8)*zcmo(ji,jj,8)  )
-            zcmo(ji,jj,34) = diag_sur_me(ji,jj) * 86400.0     ! Surface melt
-            zcmo(ji,jj,35) = diag_bot_me(ji,jj) * 86400.0     ! Bottom melt
-            zcmo(ji,jj,36) = divu_i(ji,jj)
-            zcmo(ji,jj,37) = shear_i(ji,jj)
-            zcmo(ji,jj,38) = diag_res_pr(ji,jj) * 86400.0     ! Bottom melt
-            zcmo(ji,jj,39) = vt_i(ji,jj)  ! ice volume
-            zcmo(ji,jj,40) = vt_s(ji,jj)  ! snow volume
-
-            zcmo(ji,jj,41) = fsalt_rpo(ji,jj)
-            zcmo(ji,jj,42) = fsalt_res(ji,jj)
-
-            zcmo(ji,jj,43) = diag_trp_vi(ji,jj) * 86400.0     ! transport of ice volume
-
-        END DO
-      END DO
-
-      !
-      ! ecriture d'un fichier netcdf
-      !
-      niter = niter + 1
-      DO jf = 1 , noumef
-         !
-         zfield(:,:) = zcmo(:,:,jf) * cmulti(jf) + cadd(jf)
-         !
-         IF( jf == 7  .OR. jf == 8  .OR. jf == 15 .OR. jf == 16 ) THEN   ;   CALL lbc_lnk( zfield, 'T', -1. )
-         ELSE                                                            ;   CALL lbc_lnk( zfield, 'T',  1. )
-         ENDIF
-         !
-         IF( ln_nicep ) THEN 
-            WRITE(numout,*)
-            WRITE(numout,*) 'nc(jf), nice, nam(jf), niter, ndim'
-            WRITE(numout,*) nc(jf), nice, nam(jf), niter, ndim
-         ENDIF
-         IF( nc(jf) == 1 ) CALL histwrite( nice, nam(jf), niter, zfield, ndim, ndex51 )
-         !
-      END DO
-
-      IF( ( nn_fsbc * niter ) >= nitend .OR. kindic < 0 ) THEN
-         IF( lwp) WRITE(numout,*) ' Closing the icemod file '
-         CALL histclo( nice )
-      ENDIF
-
-       CALL iom_put ('iceconc', zcmo(:,:,1) )          ! field1: ice concentration
-       CALL iom_put ('icethic_cea', zcmo(:,:,2) )      ! field2: ice thickness (i.e. icethi(:,:))
-       CALL iom_put ('snowthic_cea', zcmo(:,:,3))      ! field3: snow thickness
-       CALL iom_put ('icebopr', zcmo(:,:,4) )   ! field4: daily bottom thermo ice production
-       CALL iom_put ('icedypr', zcmo(:,:,5) )   ! field5: daily dynamic ice production
-       CALL iom_put ('ioceflxb', zcmo(:,:,6) )         ! field6: Oceanic flux at the ice base
-       CALL iom_put ('uice_ipa', zcmo(:,:,7) )         ! field7: ice velocity u component
-       CALL iom_put ('vice_ipa', zcmo(:,:,8) )         ! field8: ice velocity v component
-       CALL iom_put ('isst', zcmo(:,:,9) )             ! field 9: sea surface temperature
-       CALL iom_put ('isss', zcmo(:,:,10) )            ! field 10: sea surface salinity
-       CALL iom_put ('qt_oc', zcmo(:,:,11) )           ! field 11: total flux at ocean surface
-       CALL iom_put ('qsr_oc', zcmo(:,:,12) )          ! field 12: solar flux at ocean surface
-       CALL iom_put ('qns_oc', zcmo(:,:,13) )          ! field 13: non-solar flux at ocean surface
-       !CALL iom_put ('hfbri', fhbri )                  ! field 14: heat flux due to brine release
-       CALL iom_put ('qsr_io', zcmo(:,:,17) )          ! field 17: solar flux at ice/ocean surface
-       CALL iom_put ('qns_io', zcmo(:,:,18) )          ! field 18: non-solar flux at ice/ocean surface
-       !CALL iom_put ('snowpre', zcmo(:,:,19) * 86400) ! field 19 :snow precip          
-       CALL iom_put ('micesalt', zcmo(:,:,20) )        ! field 20 :mean ice salinity
-       CALL iom_put ('miceage', zcmo(:,:,21) / 365)    ! field 21: mean ice age
-       CALL iom_put ('icelapr',zcmo(:,:,22) )   ! field 22: daily lateral thermo ice prod.
-       CALL iom_put ('icesipr',zcmo(:,:,23) )   ! field 23: daily snowice ice prod.
-       CALL iom_put ('micet', zcmo(:,:,24) )           ! field 24: mean ice temperature
-       CALL iom_put ('icehc', zcmo(:,:,25) )           ! field 25: ice total heat content
-       CALL iom_put ('isnowhc', zcmo(:,:,26) )         ! field 26: snow total heat content
-       CALL iom_put ('icest', zcmo(:,:,27) )           ! field 27: ice surface temperature
-       CALL iom_put ('fsbri', zcmo(:,:,28) * 86400 )           ! field 28: brine salt flux
-       CALL iom_put ('fseqv', zcmo(:,:,29) * 86400 )           ! field 29: equivalent FW salt flux
-       CALL iom_put ('ibrinv', zcmo(:,:,30) *100 )     ! field 30: brine volume
-       CALL iom_put ('icecolf', zcmo(:,:,31) )         ! field 31: frazil ice collection thickness
-       CALL iom_put ('icestr', zcmo(:,:,32) * 0.001 )  ! field 32: ice strength
-       CALL iom_put ('icevel', zcmo(:,:,33) )          ! field 33: ice velocity
-       CALL iom_put ('isume', zcmo(:,:,34) )    ! field 34: surface melt
-       CALL iom_put ('ibome', zcmo(:,:,35) )     ! field 35: bottom melt
-       CALL iom_put ('idive', zcmo(:,:,36) * 1.0e8)    ! field 36: divergence
-       CALL iom_put ('ishear', zcmo(:,:,37) * 1.0e8 )  ! field 37: shear
-       CALL iom_put ('icerepr', zcmo(:,:,38) ) ! field 38: daily prod./melting due to limupdate
-       CALL iom_put ('icevolu', zcmo(:,:,39) ) ! field 39: ice volume
-       CALL iom_put ('snowvol', zcmo(:,:,40) ) ! field 40: snow volume
-       CALL iom_put ('fsrpo', zcmo(:,:,41) * 86400 )           ! field 41: salt flux from ridging rafting
-       CALL iom_put ('fsres', zcmo(:,:,42) * 86400 )           ! field 42: salt flux from limupdate (resultant)
-       CALL iom_put ('icetrp', zcmo(:,:,43) )    ! field 43: ice volume transport
-
-      !-----------------------------
-      ! Thickness distribution file
-      !-----------------------------
-      IF( add_diag_swi == 1 ) THEN
-
-         DO jl = 1, jpl 
-            CALL lbc_lnk( a_i(:,:,jl)  , 'T' ,  1. )
-            CALL lbc_lnk( sm_i(:,:,jl) , 'T' ,  1. )
-            CALL lbc_lnk( oa_i(:,:,jl) , 'T' ,  1. )
-            CALL lbc_lnk( ht_i(:,:,jl) , 'T' ,  1. )
-            CALL lbc_lnk( ht_s(:,:,jl) , 'T' ,  1. )
-         END DO
-
-         ! Compute ice age
-         DO jl = 1, jpl 
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zinda = MAX( zzero , SIGN( zone , a_i(ji,jj,jl) - epsi06 ) )
-                  zoi(ji,jj,jl) = oa_i(ji,jj,jl)  / MAX( a_i(ji,jj,jl) , epsi06 ) * zinda
-               END DO
-            END DO
-         END DO
-
-         ! Compute brine volume
-         zei(:,:,:) = 0._wp
-         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) - epsi06 ) )
-                     zei(ji,jj,jl) = zei(ji,jj,jl) + 100.0* &
-                        ( - tmut * s_i(ji,jj,jk,jl) / MIN( ( t_i(ji,jj,jk,jl) - rtt ), - epsi06 ) ) * &
-                        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( ( nn_fsbc * niter ) >= nitend .OR. kindic < 0 ) THEN
-            IF(lwp) WRITE(numout,*) ' Closing the icemod file '
-            CALL histclo( nicea ) 
-         ENDIF
-         !
-      ENDIF
-
-      CALL wrk_dealloc( jpi, jpj, zfield )
-      CALL wrk_dealloc( jpi, jpj, jpnoumax, zcmo, zcmoa )
-      CALL wrk_dealloc( jpi, jpj, jpl, zmaskitd, zoi, zei )
-
-      IF( nn_timing == 1 )  CALL timing_stop('limwri')
-      
-   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
-      !!-------------------------------------------------------------------
-      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, field_38, field_39, field_40, field_41, field_42, field_43
-
-      TYPE(FIELD) , DIMENSION(jpnoumax) :: zfield
-      !
-      NAMELIST/namiceout/ noumef, &
-         field_1 , field_2 , field_3 , field_4 , field_5 , field_6 ,   &
-         field_7 , field_8 , field_9 , field_10, field_11, field_12,   &
-         field_13, field_14, field_15, field_16, field_17, field_18,   &
-         field_19, field_20, field_21, field_22, field_23, field_24,   &
-         field_25, field_26, field_27, field_28, field_29, field_30,   &
-         field_31, field_32, field_33, field_34, field_35, field_36,   &
-         field_37, field_38, field_39, field_40, field_41, field_42, field_43, add_diag_swi
-      !!-------------------------------------------------------------------
-
-      REWIND( numnam_ice )                ! Read Namelist namicewri
-      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
-      zfield(38) = field_38
-      zfield(39) = field_39
-      zfield(40) = field_40
-      zfield(41) = field_41
-      zfield(42) = field_42
-      zfield(43) = field_43
-
-      DO nf = 1, noumef
-         titn  (nf) = zfield(nf)%ztitle
-         nam   (nf) = zfield(nf)%zname
-         uni   (nf) = zfield(nf)%zunit
-         nc    (nf) = zfield(nf)%znc
-         cmulti(nf) = zfield(nf)%zcmulti
-         cadd  (nf) = zfield(nf)%zcadd
-      END DO
-
-      IF(lwp) THEN                        ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_wri_init : Ice parameters for outputs'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '    number of fields to be stored         noumef = ', noumef
-         WRITE(numout,*) '           title                            name     unit      Saving (1/0) ',   &
-            &            '    multiplicative constant       additive constant '
-         DO nf = 1 , noumef         
-            WRITE(numout,*) '   ', titn(nf), '   '    , nam   (nf), '      '  , uni (nf),   &
-               &            '  ' , nc  (nf),'        ', cmulti(nf), '        ', cadd(nf)
-         END DO
-         WRITE(numout,*) ' add_diag_swi ', add_diag_swi
-      ENDIF
-      !
-   END SUBROUTINE lim_wri_init
- 
-   SUBROUTINE lim_wri_state( kt, kid, kh_i )
-      !!---------------------------------------------------------------------
-      !!                 ***  ROUTINE lim_wri_state  ***
-      !!        
-      !! ** Purpose :   create a NetCDF file named cdfile_name which contains 
-      !!      the instantaneous ice state and forcing fields for ice model
-      !!        Used to find errors in the initial state or save the last
-      !!      ocean state in case of abnormal end of a simulation
-      !!
-      !! History :
-      !!   4.1  !  2013-06  (C. Rousset)
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt               ! ocean time-step index)
-      INTEGER, INTENT( in ) ::   kid , kh_i       
-      !!----------------------------------------------------------------------
-      !CALL histvert( kid, "icethi", "L levels","m", jpl , hi_mean , nz )
-
-      CALL histdef( kid, "iicethic", "Ice thickness"           , "m"      , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iiceconc", "Ice concentration"       , "%"      , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicetemp", "Ice temperature"         , "C"      , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicevelu", "i-Ice speed (I-point)"   , "m/s"    , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicevelv", "j-Ice speed (I-point)"   , "m/s"    , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "iicestru", "i-Wind stress over ice (I-pt)", "Pa", jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "iicestrv", "j-Wind stress over ice (I-pt)", "Pa", jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "iicesflx", "Solar flux over ocean"     , "w/m2"   , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "iicenflx", "Non-solar flux over ocean" , "w/m2"   , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "isnowpre", "Snow precipitation"      , "kg/m2/s", jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "iicesali", "Ice salinity"            , "PSU"    , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "iicevolu", "Ice volume"              , "m"      , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "iicedive", "Ice divergence"          , "10-8s-1", jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-
-      !CALL histdef( kid, "iice_itd", "Ice concentration by cat", "%"      , jpi, jpj, kh_i, jpl, 1, jpl, -99, 32, "inst(x)", rdt, rdt ) 
-      !CALL histdef( kid, "iice_hid", "Ice thickness by cat"    , "m"      , jpi, jpj, kh_i, jpl, 1, jpl, -99, 32, "inst(x)", rdt, rdt ) 
-      !CALL histdef( kid, "iice_hsd", "Snow thickness by cat"   , "m"      , jpi, jpj, kh_i, jpl, 1, jpl, -99, 32, "inst(x)", rdt, rdt ) 
-      !CALL histdef( kid, "iice_std", "Ice salinity by cat"     , "PSU"    , jpi, jpj, kh_i, jpl, 1, jpl, -99, 32, "inst(x)", rdt, rdt ) 
-
-      CALL histend( kid, snc4set )   ! end of the file definition
-
-      CALL histwrite( kid, "iicethic", kt, icethi        , jpi*jpj, (/1/) )    
-      CALL histwrite( kid, "iiceconc", kt, at_i          , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicetemp", kt, tm_i - rtt    , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicevelu", kt, u_ice          , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicevelv", kt, v_ice          , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicestru", kt, utau_ice       , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicestrv", kt, vtau_ice       , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicesflx", kt, qsr , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicenflx", kt, qns , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "isnowpre", kt, sprecip        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicesali", kt, smt_i          , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicevolu", kt, vt_i           , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "iicedive", kt, divu_i*1.0e8   , jpi*jpj, (/1/) )
-
-      !CALL histwrite( kid, "iice_itd", kt, a_i  , jpi*jpj*jpl, (/1/)  )   ! area
-      !CALL histwrite( kid, "iice_hid", kt, ht_i , jpi*jpj*jpl, (/1/)  )   ! thickness
-      !CALL histwrite( kid, "iice_hsd", kt, ht_s , jpi*jpj*jpl, (/1/)  )   ! snow depth
-      !CALL histwrite( kid, "iice_std", kt, sm_i , jpi*jpj*jpl, (/1/)  )   ! salinity
-
-    END SUBROUTINE lim_wri_state
-
-#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: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limwri_dimg.h90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/limwri_dimg.h90	(revision 3937)
+++ 	(revision )
@@ -1,196 +1,0 @@
-SUBROUTINE lim_wri
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 3.3 , UCL - NEMO Consortium (2010)
-   !! $Id: limwri_dimg.h90 2715 2011-03-30 15:58:35Z rblod $
-   !! Software governed by the CeCILL licence (NEMOGCM/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
-   !!-------------------------------------------------------------------
-   USE  diawri, ONLY : dia_wri_dimg
-   REAL(wp),DIMENSION(1) ::   zdept
-
-   REAL(wp) ::   zsto, zsec, zjulian,zout, &
-   REAL(wp) ::   zindh,zinda,zindb, ztmu
-   REAL(wp), DIMENSION(jpi,jpj,jpnoumax) ::   zcmo
-   REAL(wp), DIMENSION(jpi,jpj) ::   zfield
-   INTEGER, SAVE ::   nmoyice   !: counter for averaging
-   INTEGER, SAVE ::   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 / nn_fsbc
-      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   ! NO vector opt.
-         zindh  = MAX( zzero , SIGN( zone , ht_i(ji,jj,1) * (1.0 - frld(ji,jj) ) - 0.10 ) )
-         zinda  = MAX( zzero , SIGN( zone , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
-         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_m(ji,jj)
-         zcmo(ji,jj,10) = sss_m(ji,jj)
-
-         zcmo(ji,jj,11) = qns(ji,jj) + qsr(ji,jj)
-         zcmo(ji,jj,12) = qsr(ji,jj)
-         zcmo(ji,jj,13) = qns(ji,jj)
-         ! See thersf for the coefficient
-         zcmo(ji,jj,14) = - emps(ji,jj) * rday     ! converted in Kg/m2/day = mm/day
-         zcmo(ji,jj,15) = utau_ice(ji,jj)
-         zcmo(ji,jj,16) = vtau_ice(ji,jj)
-         zcmo(ji,jj,17) = qsr (ji,jj)
-         zcmo(ji,jj,18) = qns(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   ! NO vector opt.
-               zindh  = MAX( zzero , SIGN( zone , ht_i(ji,jj,1) * (1.0 - frld(ji,jj) ) - 0.10 ) )
-               zinda  = MAX( zzero , SIGN( zone , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
-               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_m(ji,jj)
-               rcmoy(ji,jj,10) = sss_m(ji,jj)
-
-               rcmoy(ji,jj,11) = qns(ji,jj) + qsr(ji,jj)
-               rcmoy(ji,jj,12) = qsr(ji,jj)
-               rcmoy(ji,jj,13) = qns(ji,jj)
-               ! See thersf for the coefficient
-               rcmoy(ji,jj,14) = - emps(ji,jj) * rday     ! converted in Kg/m2/day = mm/day
-               rcmoy(ji,jj,15) = utau_ice(ji,jj)
-               rcmoy(ji,jj,16) = vtau_ice(ji,jj)
-               rcmoy(ji,jj,17) = qsr(ji,jj)
-               rcmoy(ji,jj,18) = qns(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 == 15 .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: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/par_ice.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/par_ice.F90	(revision 3937)
+++ 	(revision )
@@ -1,26 +1,0 @@
-MODULE par_ice
-   !!======================================================================
-   !!                       ***  MODULE par_ice   ***
-   !! LIM-3 Sea Ice :   definition of parameters
-   !!======================================================================
-   !! History :  3.0  ! 2003-08  (M. Vancoppenolle)  LIM-3
-   !!----------------------------------------------------------------------
-   USE par_oce
-
-   IMPLICIT NONE
-   PUBLIC          
-
-   !                                             !!! ice thermodynamics
-   INTEGER, PUBLIC, PARAMETER ::   jkmax    = 6   !: maximum number of ice layers
-   INTEGER, PUBLIC, PARAMETER ::   nlay_s   = 1   !: number of snow layers
-
-   !                                             !!! ice mechanical redistribution
-   INTEGER, PUBLIC, PARAMETER ::   jpl      = 5   !: number of ice categories
-   INTEGER, PUBLIC, PARAMETER ::   jpm      = 1   !: number of ice types
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 3.3 , UCL - NEMO Consortium (2010)
-   !! $Id: par_ice.F90 2528 2010-12-27 17:33:53Z rblod $
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!======================================================================
-END MODULE par_ice
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/restart.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/restart.F90	(revision 3937)
+++ 	(revision )
@@ -1,227 +1,0 @@
-MODULE restart
-   !!======================================================================
-   !!                     ***  MODULE  restart  ***
-   !! Ocean restart :  write the ocean restart file
-   !!======================================================================
-   !! History :  OPA  !  1999-11  (M. Imbard)  Original code
-   !!   NEMO     1.0  !  2002-08  (G. Madec)  F90: Free form
-   !!            2.0  !  2006-07  (S. Masson)  use IOM for restart
-   !!            3.3  !  2010-04  (M. Leclair, G. Madec)  modified LF-RA
-   !!            - -  !  2010-10  (C. Ethe, G. Madec) TRC-TRA merge (T-S in 4D)
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   rst_opn    : open the ocean restart file
-   !!   rst_write  : write the ocean restart file
-   !!   rst_read   : read the ocean restart file
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers 
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O module
-   USE eosbn2          ! equation of state            (eos bn2 routine)
-   USE trdmld_oce      ! ocean active mixed layer tracers trends variables
-   USE domvvl          ! variable volume
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   rst_opn    ! routine called by step module
-   PUBLIC   rst_write  ! routine called by step module
-   PUBLIC   rst_read   ! routine called by opa  module
-
-   LOGICAL, PUBLIC ::   lrst_oce =  .FALSE.   !: logical to control the oce restart write 
-   INTEGER, PUBLIC ::   numror, numrow        !: logical unit for cean restart (read and write)
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: restart.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE rst_opn( kt )
-      !!---------------------------------------------------------------------
-      !!                   ***  ROUTINE rst_opn  ***
-      !!                     
-      !! ** Purpose : + initialization (should be read in the namelist) of nitrst 
-      !!              + open the restart when we are one time step before nitrst
-      !!                   - restart header is defined when kt = nitrst-1
-      !!                   - restart data  are written when kt = nitrst
-      !!              + define lrst_oce to .TRUE. when we need to define or write the restart
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt     ! ocean time-step
-      !!
-      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
-      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
-      !!----------------------------------------------------------------------
-      !
-      IF( kt == nit000 ) THEN   ! default definitions
-         lrst_oce = .FALSE.   
-         nitrst = nitend
-      ENDIF
-      IF( MOD( kt - 1, nstock ) == 0 ) THEN   
-         ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
-         nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
-         IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
-      ENDIF
-      ! to get better performances with NetCDF format:
-      ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1)
-      ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1
-      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN
-         ! beware of the format used to write kt (default is i8.8, that should be large enough...)
-         IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
-         ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
-         ENDIF
-         ! create the file
-         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_ocerst_out)
-         IF(lwp) THEN
-            WRITE(numout,*)
-            SELECT CASE ( jprstlib )
-            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ocean restart binary file: '//clname
-            CASE DEFAULT         ;   WRITE(numout,*) '             open ocean restart NetCDF file: '//clname
-            END SELECT
-            IF ( snc4set%luse )      WRITE(numout,*) '             opened for NetCDF4 chunking and compression'
-            IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt
-            ELSE                          ;   WRITE(numout,*) '             kt = '             , kt
-            ENDIF
-         ENDIF
-         !
-         CALL iom_open( clname, numrow, ldwrt = .TRUE., kiolib = jprstlib )
-         lrst_oce = .TRUE.
-      ENDIF
-      !
-   END SUBROUTINE rst_opn
-
-
-   SUBROUTINE rst_write( kt )
-      !!---------------------------------------------------------------------
-      !!                   ***  ROUTINE rstwrite  ***
-      !!                     
-      !! ** Purpose :   Write restart fields in the format corresponding to jprstlib
-      !!
-      !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
-      !!              file, save fields which are necessary for restart
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step
-      !!----------------------------------------------------------------------
-
-                     CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rdt       )   ! dynamics time step
-                     CALL iom_rstput( kt, nitrst, numrow, 'rdttra1', rdttra(1) )   ! surface tracer time step
-
-                     CALL iom_rstput( kt, nitrst, numrow, 'ub'     , ub        )     ! before fields
-                     CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vb        )
-                     CALL iom_rstput( kt, nitrst, numrow, 'tb'     , tsb(:,:,:,jp_tem) )
-                     CALL iom_rstput( kt, nitrst, numrow, 'sb'     , tsb(:,:,:,jp_sal) )
-                     CALL iom_rstput( kt, nitrst, numrow, 'rotb'   , rotb      )
-                     CALL iom_rstput( kt, nitrst, numrow, 'hdivb'  , hdivb     )
-                     CALL iom_rstput( kt, nitrst, numrow, 'sshb'   , sshb      )
-      IF( lk_vvl )   CALL iom_rstput( kt, nitrst, numrow, 'fse3t_b', fse3t_b(:,:,:) )
-                     !
-                     CALL iom_rstput( kt, nitrst, numrow, 'un'     , un        )     ! now fields
-                     CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vn        )
-                     CALL iom_rstput( kt, nitrst, numrow, 'tn'     , tsn(:,:,:,jp_tem) )
-                     CALL iom_rstput( kt, nitrst, numrow, 'sn'     , tsn(:,:,:,jp_sal) )
-                     CALL iom_rstput( kt, nitrst, numrow, 'rotn'   , rotn      )
-                     CALL iom_rstput( kt, nitrst, numrow, 'hdivn'  , hdivn     )
-                     CALL iom_rstput( kt, nitrst, numrow, 'sshn'   , sshn      )
-                     CALL iom_rstput( kt, nitrst, numrow, 'rhop'   , rhop      )
-#if defined key_zdfkpp
-                     CALL iom_rstput( kt, nitrst, numrow, 'rhd'    , rhd       )
-#endif
-      IF( kt == nitrst ) THEN
-         CALL iom_close( numrow )     ! close the restart file (only at last time step)
-         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
-      ENDIF
-      !
-   END SUBROUTINE rst_write
-
-
-   SUBROUTINE rst_read
-      !!---------------------------------------------------------------------- 
-      !!                   ***  ROUTINE rst_read  ***
-      !! 
-      !! ** Purpose :   Read files for restart (format fixed by jprstlib )
-      !! 
-      !! ** Method  :   Read in restart.nc file fields which are necessary for restart
-      !!----------------------------------------------------------------------
-      REAL(wp) ::   zrdt, zrdttra1
-      INTEGER  ::   jk, jlibalt = jprstlib
-      LOGICAL  ::   llok
-      !!----------------------------------------------------------------------
-
-      IF(lwp) THEN                                             ! Contol prints
-         WRITE(numout,*)
-         SELECT CASE ( jprstlib )
-         CASE ( jpnf90    )   ;   WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
-         CASE ( jprstdimg )   ;   WRITE(numout,*) 'rst_read : read oce binary restart file'
-         END SELECT
-         IF ( snc4set%luse )      WRITE(numout,*) 'rst_read : configured with NetCDF4 support'
-         WRITE(numout,*) '~~~~~~~~'
-      ENDIF
-
-      IF ( jprstlib == jprstdimg ) THEN
-        ! eventually read netcdf file (monobloc)  for restarting on different number of processors
-        ! if {cn_ocerst_in}.nc exists, then set jlibalt to jpnf90
-        INQUIRE( FILE = TRIM(cn_ocerst_in)//'.nc', EXIST = llok )
-        IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
-      ENDIF
-      CALL iom_open( cn_ocerst_in, numror, kiolib = jlibalt )
-
-      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
-      IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
-         CALL iom_get( numror, 'rdt', zrdt )
-         IF( zrdt /= rdt )   neuler = 0
-      ENDIF
-      IF( iom_varid( numror, 'rdttra1', ldstop = .FALSE. ) > 0 )   THEN
-         CALL iom_get( numror, 'rdttra1', zrdttra1 )
-         IF( zrdttra1 /= rdttra(1) )   neuler = 0
-      ENDIF
-      ! 
-                     CALL iom_get( numror, jpdom_autoglo, 'ub'     , ub      )   ! before fields
-                     CALL iom_get( numror, jpdom_autoglo, 'vb'     , vb      )
-                     CALL iom_get( numror, jpdom_autoglo, 'tb'     , tsb(:,:,:,jp_tem) )
-                     CALL iom_get( numror, jpdom_autoglo, 'sb'     , tsb(:,:,:,jp_sal) )
-                     CALL iom_get( numror, jpdom_autoglo, 'rotb'   , rotb    )
-                     CALL iom_get( numror, jpdom_autoglo, 'hdivb'  , hdivb   )
-                     CALL iom_get( numror, jpdom_autoglo, 'sshb'   , sshb    )
-      IF( lk_vvl )   CALL iom_get( numror, jpdom_autoglo, 'fse3t_b', fse3t_b(:,:,:) )
-                     !
-                     CALL iom_get( numror, jpdom_autoglo, 'un'     , un      )   ! now    fields
-                     CALL iom_get( numror, jpdom_autoglo, 'vn'     , vn      )
-                     CALL iom_get( numror, jpdom_autoglo, 'tn'     , tsn(:,:,:,jp_tem) )
-                     CALL iom_get( numror, jpdom_autoglo, 'sn'     , tsn(:,:,:,jp_sal) )
-                     CALL iom_get( numror, jpdom_autoglo, 'rotn'   , rotn    )
-                     CALL iom_get( numror, jpdom_autoglo, 'hdivn'  , hdivn   )
-                     CALL iom_get( numror, jpdom_autoglo, 'sshn'   , sshn    )
-                     CALL iom_get( numror, jpdom_autoglo, 'rhop'   , rhop    )   ! now    potential density
-#if defined key_zdfkpp
-      IF( iom_varid( numror, 'rhd', ldstop = .FALSE. ) > 0 ) THEN
-                     CALL iom_get( numror, jpdom_autoglo, 'rhd'    , rhd     )   ! now    in situ density anomaly
-      ELSE
-                     CALL eos( tsn, rhd )   ! compute rhd
-      ENDIF
-#endif
-      !
-      IF( neuler == 0 ) THEN                                  ! Euler restart (neuler=0)
-         tsb  (:,:,:,:) = tsn  (:,:,:,:)                             ! all before fields set to now values
-         ub   (:,:,:)   = un   (:,:,:)
-         vb   (:,:,:)   = vn   (:,:,:)
-         rotb (:,:,:)   = rotn (:,:,:)
-         hdivb(:,:,:)   = hdivn(:,:,:)
-         sshb (:,:)     = sshn (:,:)
-         IF( lk_vvl ) THEN
-            DO jk = 1, jpk
-               fse3t_b(:,:,jk) = fse3t_n(:,:,jk)
-            END DO
-         ENDIF
-      ENDIF
-      !
-   END SUBROUTINE rst_read
-
-   !!=====================================================================
-END MODULE restart
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/sbc_oce.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/sbc_oce.F90	(revision 3937)
+++ 	(revision )
@@ -1,164 +1,0 @@
-MODULE sbc_oce
-   !!======================================================================
-   !!                       ***  MODULE  sbc_oce  ***
-   !! Surface module :   variables defined in core memory 
-   !!======================================================================
-   !! History :  3.0  ! 2006-06  (G. Madec)  Original code
-   !!             -   ! 2008-08  (G. Madec)  namsbc moved from sbcmod
-   !!            3.3  ! 2010-04  (M. Leclair, G. Madec)  Forcing averaged over 2 time steps
-   !!             -   ! 2010-11  (G. Madec) ice-ocean stress always computed at each ocean time-step
-   !!            3.3  ! 2010-10  (J. Chanut, C. Bricaud)  add the surface pressure forcing
-   !!            4.0  ! 2012-05  (C. Rousset) add attenuation coef for use in ice model 
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   sbc_oce_alloc : allocation of sbc arrays
-   !!   sbc_tau2wnd   : wind speed estimated from wind stress
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   sbc_oce_alloc   ! routine called in sbcmod.F90
-   PUBLIC   sbc_tau2wnd     ! routine called in several sbc modules
-   
-   !!----------------------------------------------------------------------
-   !!           Namelist for the Ocean Surface Boundary Condition
-   !!----------------------------------------------------------------------
-   !                                            !!* namsbc namelist *
-   LOGICAL , PUBLIC ::   ln_ana      = .FALSE.   !: analytical boundary condition flag
-   LOGICAL , PUBLIC ::   ln_flx      = .FALSE.   !: flux      formulation
-   LOGICAL , PUBLIC ::   ln_blk_clio = .FALSE.   !: CLIO bulk formulation
-   LOGICAL , PUBLIC ::   ln_blk_core = .FALSE.   !: CORE bulk formulation
-   LOGICAL , PUBLIC ::   ln_blk_mfs  = .FALSE.   !: MFS  bulk formulation
-   LOGICAL , PUBLIC ::   ln_cpl      = .FALSE.   !: coupled   formulation (overwritten by key_sbc_coupled )
-   LOGICAL , PUBLIC ::   ln_dm2dc    = .FALSE.   !: Daily mean to Diurnal Cycle short wave (qsr)
-   LOGICAL , PUBLIC ::   ln_rnf      = .FALSE.   !: runoffs / runoff mouths
-   LOGICAL , PUBLIC ::   ln_ssr      = .FALSE.   !: Sea Surface restoring on SST and/or SSS      
-   LOGICAL , PUBLIC ::   ln_apr_dyn  = .FALSE.   !: Atmospheric pressure forcing used on dynamics (ocean & ice)
-   INTEGER , PUBLIC ::   nn_ice      = 0         !: flag on ice in the surface boundary condition (=0/1/2/3)
-   INTEGER , PUBLIC ::   nn_fwb      = 0         !: FreshWater Budget: 
-   !                                             !:  = 0 unchecked 
-   !                                             !:  = 1 global mean of e-p-r set to zero at each nn_fsbc time step
-   !                                             !:  = 2 annual global mean of e-p-r set to zero
-   LOGICAL , PUBLIC ::   ln_cdgw     = .FALSE.   !: true if neutral drag coefficient read from wave model
-
-   !!----------------------------------------------------------------------
-   !!              Ocean Surface Boundary Condition fields
-   !!----------------------------------------------------------------------
-   LOGICAL , PUBLIC ::   lhftau = .FALSE.        !: HF tau used in TKE: mean(stress module) - module(mean stress)
-   !!                                   !!   now    ! before   !!
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   utau   , utau_b   !: sea surface i-stress (ocean referential)     [N/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   vtau   , vtau_b   !: sea surface j-stress (ocean referential)     [N/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   taum              !: module of sea surface stress (at T-point)    [N/m2] 
-   !! wndm is used onmpute surface gases exchanges in ice-free ocean or leads
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wndm              !: wind speed module at T-point (=|U10m-Uoce|)  [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qsr               !: sea heat flux:     solar                     [W/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qns    , qns_b    !: sea heat flux: non solar                     [W/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qsr_tot           !: total     solar heat flux (over sea and ice) [W/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qns_tot           !: total non solar heat flux (over sea and ice) [W/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   emp    , emp_b    !: freshwater budget: volume flux               [Kg/m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   emps   , emps_b   !: freshwater budget: concentration/dillution   [Kg/m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   emp_tot           !: total E-P over ocean and ice                 [Kg/m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rnf    , rnf_b    !: river runoff   [Kg/m2/s]  
-   !!
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  sbc_tsc, sbc_tsc_b  !: sbc content trend                      [K.m/s] jpi,jpj,jpts
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  qsr_hc , qsr_hc_b   !: heat content trend due to qsr flux     [K.m/s] jpi,jpj,jpk
-   !!
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   oatte, iatte      !: clem attenuation coef of the input solar flux [unitless]
-   !!
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tprecip           !: total precipitation                          [Kg/m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sprecip           !: solid precipitation                          [Kg/m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fr_i              !: ice fraction = 1 - lead fraction      (between 0 to 1)
-#if defined key_cpl_carbon_cycle
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   atm_co2           !: atmospheric pCO2                             [ppm]
-#endif
-
-   !!----------------------------------------------------------------------
-   !!                     Sea Surface Mean fields
-   !!----------------------------------------------------------------------
-   INTEGER , PUBLIC                     ::   nn_fsbc   !: frequency of sbc computation (as well as sea-ice model)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ssu_m     !: mean (nn_fsbc time-step) surface sea i-current (U-point) [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ssv_m     !: mean (nn_fsbc time-step) surface sea j-current (V-point) [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sst_m     !: mean (nn_fsbc time-step) surface sea temperature     [Celsius]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sss_m     !: mean (nn_fsbc time-step) surface sea salinity            [psu]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ssh_m     !: mean (nn_fsbc time-step) sea surface height                [m]
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
-   !! $Id: sbc_oce.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION sbc_oce_alloc()
-      !!---------------------------------------------------------------------
-      !!                  ***  FUNCTION sbc_oce_alloc  ***
-      !!---------------------------------------------------------------------
-      INTEGER :: ierr(4)
-      !!---------------------------------------------------------------------
-      ierr(:) = 0
-      !
-      ALLOCATE( utau(jpi,jpj) , utau_b(jpi,jpj) , taum(jpi,jpj) ,     &
-         &      vtau(jpi,jpj) , vtau_b(jpi,jpj) , wndm(jpi,jpj) , STAT=ierr(1) ) 
-         !
-      ALLOCATE( qns_tot(jpi,jpj) , qns   (jpi,jpj) , qns_b(jpi,jpj),        &
-         &      qsr_tot(jpi,jpj) , qsr   (jpi,jpj) ,                        &
-         &      emp    (jpi,jpj) , emp_b (jpi,jpj) ,                        &
-         &      emps   (jpi,jpj) , emps_b(jpi,jpj) , emp_tot(jpi,jpj) , STAT=ierr(2) )
-         !
-      ALLOCATE( rnf  (jpi,jpj) , sbc_tsc  (jpi,jpj,jpts) , qsr_hc  (jpi,jpj,jpk) ,     &
-         &      rnf_b(jpi,jpj) , sbc_tsc_b(jpi,jpj,jpts) , qsr_hc_b(jpi,jpj,jpk) ,     &
-         &      iatte(jpi,jpj) , oatte    (jpi,jpj)                              , STAT=ierr(3) )
-         !
-      ALLOCATE( tprecip(jpi,jpj) , sprecip(jpi,jpj) , fr_i(jpi,jpj) ,     &
-#if defined key_cpl_carbon_cycle
-         &      atm_co2(jpi,jpj) ,                                        &
-#endif
-         &      ssu_m  (jpi,jpj) , sst_m(jpi,jpj) ,                       &
-         &      ssv_m  (jpi,jpj) , sss_m  (jpi,jpj), ssh_m(jpi,jpj) , STAT=ierr(4) )
-         !
-      sbc_oce_alloc = MAXVAL( ierr )
-      IF( lk_mpp            )   CALL mpp_sum ( sbc_oce_alloc )
-      IF( sbc_oce_alloc > 0 )   CALL ctl_warn('sbc_oce_alloc: allocation of arrays failed')
-      !
-   END FUNCTION sbc_oce_alloc
-
-
-   SUBROUTINE sbc_tau2wnd
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE sbc_tau2wnd  ***
-      !!                   
-      !! ** Purpose : Estimation of wind speed as a function of wind stress   
-      !!
-      !! ** Method  : |tau|=rhoa*Cd*|U|^2
-      !!---------------------------------------------------------------------
-      USE dom_oce         ! ocean space and time domain
-      USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-      REAL(wp) ::   zrhoa  = 1.22         ! Air density kg/m3
-      REAL(wp) ::   zcdrag = 1.5e-3       ! drag coefficient
-      REAL(wp) ::   ztx, zty, ztau, zcoef ! temporary variables
-      INTEGER  ::   ji, jj                ! dummy indices
-      !!---------------------------------------------------------------------
-      zcoef = 0.5 / ( zrhoa * zcdrag ) 
-!CDIR NOVERRCHK
-      DO jj = 2, jpjm1
-!CDIR NOVERRCHK
-         DO ji = fs_2, fs_jpim1   ! vect. opt.
-            ztx = utau(ji-1,jj  ) + utau(ji,jj) 
-            zty = vtau(ji  ,jj-1) + vtau(ji,jj) 
-            ztau = SQRT( ztx * ztx + zty * zty )
-            wndm(ji,jj) = SQRT ( ztau * zcoef ) * tmask(ji,jj,1)
-         END DO
-      END DO
-      CALL lbc_lnk( wndm(:,:) , 'T', 1. )
-      !
-   END SUBROUTINE sbc_tau2wnd
-
-   !!======================================================================
-END MODULE sbc_oce
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/sbcblk_core.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/sbcblk_core.F90	(revision 3937)
+++ 	(revision )
@@ -1,960 +1,0 @@
-MODULE sbcblk_core
-   !!======================================================================
-   !!                       ***  MODULE  sbcblk_core  ***
-   !! Ocean forcing:  momentum, heat and freshwater flux formulation
-   !!=====================================================================
-   !! History :  1.0  !  2004-08  (U. Schweckendiek)  Original code
-   !!            2.0  !  2005-04  (L. Brodeau, A.M. Treguier) additions: 
-   !!                           -  new bulk routine for efficiency
-   !!                           -  WINDS ARE NOW ASSUMED TO BE AT T POINTS in input files !!!!
-   !!                           -  file names and file characteristics in namelist 
-   !!                           -  Implement reading of 6-hourly fields   
-   !!            3.0  !  2006-06  (G. Madec) sbc rewritting   
-   !!             -   !  2006-12  (L. Brodeau) Original code for TURB_CORE_2Z
-   !!            3.2  !  2009-04  (B. Lemaire)  Introduce iom_put
-   !!            3.3  !  2010-10  (S. Masson)  add diurnal cycle
-   !!            3.4  !  2011-11  (C. Harris) Fill arrays required by CICE
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   sbc_blk_core  : bulk formulation as ocean surface boundary condition
-   !!                   (forced mode, CORE bulk formulea)
-   !!   blk_oce_core  : ocean: computes momentum, heat and freshwater fluxes
-   !!   blk_ice_core  : ice  : computes momentum, heat and freshwater fluxes
-   !!   turb_core     : computes the CORE turbulent transfer coefficients 
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE fldread         ! read input fields
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbcdcy          ! surface boundary condition: diurnal cycle
-   USE iom             ! I/O manager library
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! distribued memory computing library
-   USE wrk_nemo        ! work arrays
-   USE timing          ! Timing
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE prtctl          ! Print control
-   USE sbcwave,ONLY :  cdn_wave !wave module 
-#if defined key_lim3 || defined key_cice
-   USE sbc_ice         ! Surface boundary condition: ice fields
-#endif
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   sbc_blk_core         ! routine called in sbcmod module
-   PUBLIC   blk_ice_core         ! routine called in sbc_ice_lim module
-   PUBLIC   turb_core_2z         ! routine calles in sbcblk_mfs module
-
-   INTEGER , PARAMETER ::   jpfld   = 9           ! maximum number of files to read 
-   INTEGER , PARAMETER ::   jp_wndi = 1           ! index of 10m wind velocity (i-component) (m/s)    at T-point
-   INTEGER , PARAMETER ::   jp_wndj = 2           ! index of 10m wind velocity (j-component) (m/s)    at T-point
-   INTEGER , PARAMETER ::   jp_humi = 3           ! index of specific humidity               ( - )
-   INTEGER , PARAMETER ::   jp_qsr  = 4           ! index of solar heat                      (W/m2)
-   INTEGER , PARAMETER ::   jp_qlw  = 5           ! index of Long wave                       (W/m2)
-   INTEGER , PARAMETER ::   jp_tair = 6           ! index of 10m air temperature             (Kelvin)
-   INTEGER , PARAMETER ::   jp_prec = 7           ! index of total precipitation (rain+snow) (Kg/m2/s)
-   INTEGER , PARAMETER ::   jp_snow = 8           ! index of snow (solid prcipitation)       (kg/m2/s)
-   INTEGER , PARAMETER ::   jp_tdif = 9           ! index of tau diff associated to HF tau   (N/m2)   at T-point
-   
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf   ! structure of input fields (file informations, fields read)
-         
-   !                                             !!! CORE bulk parameters
-   REAL(wp), PARAMETER ::   rhoa =    1.22        ! air density
-   REAL(wp), PARAMETER ::   cpa  = 1000.5         ! specific heat of air
-   REAL(wp), PARAMETER ::   Lv   =    2.5e6       ! latent heat of vaporization
-   REAL(wp), PARAMETER ::   Ls   =    2.839e6     ! latent heat of sublimation
-   REAL(wp), PARAMETER ::   Stef =    5.67e-8     ! Stefan Boltzmann constant
-   !iovi REAL(wp), PARAMETER ::   Cice =    1.63e-3     ! transfer coefficient over ice
-   REAL(wp), PARAMETER ::   Cice =    1.4e-3      ! transfer coefficient over ice
-   REAL(wp), PARAMETER ::   albo =    0.066       ! ocean albedo assumed to be contant
-
-   !                                  !!* Namelist namsbc_core : CORE bulk parameters
-   LOGICAL  ::   ln_2m     = .FALSE.   ! logical flag for height of air temp. and hum
-   LOGICAL  ::   ln_taudif = .FALSE.   ! logical flag to use the "mean of stress module - module of mean stress" data
-   REAL(wp) ::   rn_pfac   = 1.        ! multiplication factor for precipitation
-   REAL(wp) ::   rn_efac   = 1.        ! multiplication factor for evaporation (clem)
-   REAL(wp) ::   rn_vfac   = 1.        ! multiplication factor for ice/ocean velocity in the calculation of wind stress (clem)
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO-consortium (2010) 
-   !! $Id: sbcblk_core.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE sbc_blk_core( kt )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE sbc_blk_core  ***
-      !!                   
-      !! ** Purpose :   provide at each time step the surface ocean fluxes
-      !!      (momentum, heat, freshwater and runoff) 
-      !!
-      !! ** Method  : (1) READ each fluxes in NetCDF files:
-      !!      the 10m wind velocity (i-component) (m/s)    at T-point
-      !!      the 10m wind velocity (j-component) (m/s)    at T-point
-      !!      the specific humidity               ( - )
-      !!      the solar heat                      (W/m2)
-      !!      the Long wave                       (W/m2)
-      !!      the 10m air temperature             (Kelvin)
-      !!      the total precipitation (rain+snow) (Kg/m2/s)
-      !!      the snow (solid prcipitation)       (kg/m2/s)
-      !!   OPTIONAL parameter (see ln_taudif namelist flag):
-      !!      the tau diff associated to HF tau   (N/m2)   at T-point 
-      !!              (2) CALL blk_oce_core
-      !!
-      !!      C A U T I O N : never mask the surface stress fields
-      !!                      the stress is assumed to be in the mesh referential
-      !!                      i.e. the (i,j) referential
-      !!
-      !! ** Action  :   defined at each time-step at the air-sea interface
-      !!              - utau, vtau  i- and j-component of the wind stress
-      !!              - taum        wind stress module at T-point
-      !!              - wndm        10m wind module at T-point
-      !!              - qns, qsr    non-slor and solar heat flux
-      !!              - emp, emps   evaporation minus precipitation
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time step
-      !!
-      INTEGER  ::   ierror   ! return error code
-      INTEGER  ::   ifpr     ! dummy loop indice
-      INTEGER  ::   jfld     ! dummy loop arguments
-      !!
-      CHARACTER(len=100) ::  cn_dir   !   Root directory for location of core files
-      TYPE(FLD_N), DIMENSION(jpfld) ::   slf_i     ! array of namelist informations on the fields to read
-      TYPE(FLD_N) ::   sn_wndi, sn_wndj, sn_humi, sn_qsr       ! informations about the fields to be read
-      TYPE(FLD_N) ::   sn_qlw , sn_tair, sn_prec, sn_snow      !   "                                 "
-      TYPE(FLD_N) ::   sn_tdif                                 !   "                                 "
-      NAMELIST/namsbc_core/ cn_dir , ln_2m  , ln_taudif, rn_pfac, rn_efac, rn_vfac,  &
-         &                  sn_wndi, sn_wndj, sn_humi  , sn_qsr ,           &
-         &                  sn_qlw , sn_tair, sn_prec  , sn_snow, sn_tdif
-      !!---------------------------------------------------------------------
-
-      !                                         ! ====================== !
-      IF( kt == nit000 ) THEN                   !  First call kt=nit000  !
-         !                                      ! ====================== !
-         ! set file information (default values)
-         cn_dir = './'       ! directory in which the model is executed
-         !
-         ! (NB: frequency positive => hours, negative => months)
-         !            !    file    ! frequency ! variable ! time intep !  clim   ! 'yearly' or ! weights  ! rotation !
-         !            !    name    !  (hours)  !  name    !   (T/F)    !  (T/F)  !  'monthly'  ! filename ! pairs    !
-         sn_wndi = FLD_N( 'uwnd10m',    24     , 'u_10'   ,  .false.   , .false. ,   'yearly'  , ''       , ''       )
-         sn_wndj = FLD_N( 'vwnd10m',    24     , 'v_10'   ,  .false.   , .false. ,   'yearly'  , ''       , ''       )
-         sn_qsr  = FLD_N( 'qsw'    ,    24     , 'qsw'    ,  .false.   , .false. ,   'yearly'  , ''       , ''       )
-         sn_qlw  = FLD_N( 'qlw'    ,    24     , 'qlw'    ,  .false.   , .false. ,   'yearly'  , ''       , ''       )
-         sn_tair = FLD_N( 'tair10m',    24     , 't_10'   ,  .false.   , .false. ,   'yearly'  , ''       , ''       )
-         sn_humi = FLD_N( 'humi10m',    24     , 'q_10'   ,  .false.   , .false. ,   'yearly'  , ''       , ''       )
-         sn_prec = FLD_N( 'precip' ,    -1     , 'precip' ,  .true.    , .false. ,   'yearly'  , ''       , ''       )
-         sn_snow = FLD_N( 'snow'   ,    -1     , 'snow'   ,  .true.    , .false. ,   'yearly'  , ''       , ''       )
-         sn_tdif = FLD_N( 'taudif' ,    24     , 'taudif' ,  .true.    , .false. ,   'yearly'  , ''       , ''       )
-         !
-         REWIND( numnam )                          ! read in namlist namsbc_core
-         READ  ( numnam, namsbc_core )
-         !                                         ! check: do we plan to use ln_dm2dc with non-daily forcing?
-         IF( ln_dm2dc .AND. sn_qsr%nfreqh /= 24 )   & 
-            &   CALL ctl_stop( 'sbc_blk_core: ln_dm2dc can be activated only with daily short-wave forcing' ) 
-         IF( ln_dm2dc .AND. sn_qsr%ln_tint ) THEN
-            CALL ctl_warn( 'sbc_blk_core: ln_dm2dc is taking care of the temporal interpolation of daily qsr',   &
-                 &         '              ==> We force time interpolation = .false. for qsr' )
-            sn_qsr%ln_tint = .false.
-         ENDIF
-         !                                         ! store namelist information in an array
-         slf_i(jp_wndi) = sn_wndi   ;   slf_i(jp_wndj) = sn_wndj
-         slf_i(jp_qsr ) = sn_qsr    ;   slf_i(jp_qlw ) = sn_qlw
-         slf_i(jp_tair) = sn_tair   ;   slf_i(jp_humi) = sn_humi
-         slf_i(jp_prec) = sn_prec   ;   slf_i(jp_snow) = sn_snow
-         slf_i(jp_tdif) = sn_tdif
-         !                 
-         lhftau = ln_taudif                        ! do we use HF tau information?
-         jfld = jpfld - COUNT( (/.NOT. lhftau/) )
-         !
-         ALLOCATE( sf(jfld), STAT=ierror )         ! set sf structure
-         IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_blk_core: unable to allocate sf structure' )
-         DO ifpr= 1, jfld
-            ALLOCATE( sf(ifpr)%fnow(jpi,jpj,1) )
-            IF( slf_i(ifpr)%ln_tint )   ALLOCATE( sf(ifpr)%fdta(jpi,jpj,1,2) )
-         END DO
-         !                                         ! fill sf with slf_i and control print
-         CALL fld_fill( sf, slf_i, cn_dir, 'sbc_blk_core', 'flux formulation for ocean surface boundary condition', 'namsbc_core' )
-         !
-      ENDIF
-
-      CALL fld_read( kt, nn_fsbc, sf )        ! input fields provided at the current time-step
-
-      !                                                        ! surface ocean fluxes computed with CLIO bulk formulea
-      IF( MOD( kt - 1, nn_fsbc ) == 0 )   CALL blk_oce_core( sf, sst_m, ssu_m, ssv_m )
-
-#if defined key_cice
-      IF( MOD( kt - 1, nn_fsbc ) == 0 )   THEN
-         qlw_ice(:,:,1)   = sf(jp_qlw)%fnow(:,:,1) 
-         qsr_ice(:,:,1)   = sf(jp_qsr)%fnow(:,:,1)
-         tatm_ice(:,:)    = sf(jp_tair)%fnow(:,:,1)         
-         qatm_ice(:,:)    = sf(jp_humi)%fnow(:,:,1)
-         tprecip(:,:)     = sf(jp_prec)%fnow(:,:,1) * rn_pfac
-         sprecip(:,:)     = sf(jp_snow)%fnow(:,:,1) * rn_pfac
-         wndi_ice(:,:)    = sf(jp_wndi)%fnow(:,:,1)
-         wndj_ice(:,:)    = sf(jp_wndj)%fnow(:,:,1)
-      ENDIF
-#endif
-      !
-   END SUBROUTINE sbc_blk_core
-   
-   
-   SUBROUTINE blk_oce_core( sf, pst, pu, pv )
-      !!---------------------------------------------------------------------
-      !!                     ***  ROUTINE blk_core  ***
-      !!
-      !! ** Purpose :   provide the momentum, heat and freshwater fluxes at
-      !!      the ocean surface at each time step
-      !!
-      !! ** Method  :   CORE bulk formulea for the ocean using atmospheric
-      !!      fields read in sbc_read
-      !! 
-      !! ** Outputs : - utau    : i-component of the stress at U-point  (N/m2)
-      !!              - vtau    : j-component of the stress at V-point  (N/m2)
-      !!              - taum    : Wind stress module at T-point         (N/m2)
-      !!              - wndm    : Wind speed module at T-point          (m/s)
-      !!              - qsr     : Solar heat flux over the ocean        (W/m2)
-      !!              - qns     : Non Solar heat flux over the ocean    (W/m2)
-      !!              - evap    : Evaporation over the ocean            (kg/m2/s)
-      !!              - emp(s)  : evaporation minus precipitation       (kg/m2/s)
-      !!
-      !!  ** Nota  :   sf has to be a dummy argument for AGRIF on NEC
-      !!---------------------------------------------------------------------
-      TYPE(fld), INTENT(in), DIMENSION(:)   ::   sf    ! input data
-      REAL(wp) , INTENT(in), DIMENSION(:,:) ::   pst   ! surface temperature                      [Celcius]
-      REAL(wp) , INTENT(in), DIMENSION(:,:) ::   pu    ! surface current at U-point (i-component) [m/s]
-      REAL(wp) , INTENT(in), DIMENSION(:,:) ::   pv    ! surface current at V-point (j-component) [m/s]
-      !
-      INTEGER  ::   ji, jj               ! dummy loop indices
-      REAL(wp) ::   zcoef_qsatw, zztmp   ! local variable
-      REAL(wp), DIMENSION(:,:), POINTER ::   zwnd_i, zwnd_j    ! wind speed components at T-point
-      REAL(wp), DIMENSION(:,:), POINTER ::   zqsatw            ! specific humidity at pst
-      REAL(wp), DIMENSION(:,:), POINTER ::   zqlw, zqsb        ! long wave and sensible heat fluxes
-      REAL(wp), DIMENSION(:,:), POINTER ::   zqla, zevap       ! latent heat fluxes and evaporation
-      REAL(wp), DIMENSION(:,:), POINTER ::   Cd                ! transfer coefficient for momentum      (tau)
-      REAL(wp), DIMENSION(:,:), POINTER ::   Ch                ! transfer coefficient for sensible heat (Q_sens)
-      REAL(wp), DIMENSION(:,:), POINTER ::   Ce                ! tansfert coefficient for evaporation   (Q_lat)
-      REAL(wp), DIMENSION(:,:), POINTER ::   zst               ! surface temperature in Kelvin
-      REAL(wp), DIMENSION(:,:), POINTER ::   zt_zu             ! air temperature at wind speed height
-      REAL(wp), DIMENSION(:,:), POINTER ::   zq_zu             ! air spec. hum.  at wind speed height
-      !!---------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('blk_oce_core')
-      !
-      CALL wrk_alloc( jpi,jpj, zwnd_i, zwnd_j, zqsatw, zqlw, zqsb, zqla, zevap )
-      CALL wrk_alloc( jpi,jpj, Cd, Ch, Ce, zst, zt_zu, zq_zu )
-      !
-      ! local scalars ( place there for vector optimisation purposes)
-      zcoef_qsatw = 0.98 * 640380. / rhoa
-      
-      zst(:,:) = pst(:,:) + rt0      ! converte Celcius to Kelvin (and set minimum value far above 0 K)
-
-      ! ----------------------------------------------------------------------------- !
-      !      0   Wind components and module at T-point relative to the moving ocean   !
-      ! ----------------------------------------------------------------------------- !
-
-      ! ... components ( U10m - U_oce ) at T-point (unmasked)
-      zwnd_i(:,:) = 0.e0  
-      zwnd_j(:,:) = 0.e0
-#if defined key_vectopt_loop
-!CDIR COLLAPSE
-#endif
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1   ! vect. opt.
-            zwnd_i(ji,jj) = (  sf(jp_wndi)%fnow(ji,jj,1) - rn_vfac * 0.5 * ( pu(ji-1,jj  ) + pu(ji,jj) )  )
-            zwnd_j(ji,jj) = (  sf(jp_wndj)%fnow(ji,jj,1) - rn_vfac * 0.5 * ( pv(ji  ,jj-1) + pv(ji,jj) )  )
-         END DO
-      END DO
-      CALL lbc_lnk( zwnd_i(:,:) , 'T', -1. )
-      CALL lbc_lnk( zwnd_j(:,:) , 'T', -1. )
-      ! ... scalar wind ( = | U10m - U_oce | ) at T-point (masked)
-!CDIR NOVERRCHK
-!CDIR COLLAPSE
-      wndm(:,:) = SQRT(  zwnd_i(:,:) * zwnd_i(:,:)   &
-         &             + zwnd_j(:,:) * zwnd_j(:,:)  ) * tmask(:,:,1)
-
-      ! ----------------------------------------------------------------------------- !
-      !      I   Radiative FLUXES                                                     !
-      ! ----------------------------------------------------------------------------- !
-    
-      ! ocean albedo assumed to be constant + modify now Qsr to include the diurnal cycle                    ! Short Wave
-      zztmp = 1. - albo
-      IF( ln_dm2dc ) THEN   ;   qsr(:,:) = zztmp * sbc_dcy( sf(jp_qsr)%fnow(:,:,1) ) * tmask(:,:,1)
-      ELSE                  ;   qsr(:,:) = zztmp *          sf(jp_qsr)%fnow(:,:,1)   * tmask(:,:,1)
-      ENDIF
-!CDIR COLLAPSE
-      zqlw(:,:) = (  sf(jp_qlw)%fnow(:,:,1) - Stef * zst(:,:)*zst(:,:)*zst(:,:)*zst(:,:)  ) * tmask(:,:,1)   ! Long  Wave
-      ! ----------------------------------------------------------------------------- !
-      !     II    Turbulent FLUXES                                                    !
-      ! ----------------------------------------------------------------------------- !
-
-      ! ... specific humidity at SST and IST
-!CDIR NOVERRCHK
-!CDIR COLLAPSE
-      zqsatw(:,:) = zcoef_qsatw * EXP( -5107.4 / zst(:,:) ) 
-
-      ! ... NCAR Bulk formulae, computation of Cd, Ch, Ce at T-point :
-      IF( ln_2m ) THEN
-         !! If air temp. and spec. hum. are given at different height (2m) than wind (10m) :
-         CALL TURB_CORE_2Z(2.,10., zst   , sf(jp_tair)%fnow,         &
-            &                      zqsatw, sf(jp_humi)%fnow, wndm,   &
-            &                      Cd    , Ch              , Ce  ,   &
-            &                      zt_zu , zq_zu                   )
-      ELSE
-         !! If air temp. and spec. hum. are given at same height than wind (10m) :
-!gm bug?  at the compiling phase, add a copy in temporary arrays...  ==> check perf
-!         CALL TURB_CORE_1Z( 10., zst   (:,:), sf(jp_tair)%fnow(:,:),              &
-!            &                    zqsatw(:,:), sf(jp_humi)%fnow(:,:), wndm(:,:),   &
-!            &                    Cd    (:,:),             Ch  (:,:), Ce  (:,:)  )
-!gm bug
-! ARPDBG - this won't compile with gfortran. Fix but check performance
-! as per comment above.
-         CALL TURB_CORE_1Z( 10., zst   , sf(jp_tair)%fnow(:,:,1),       &
-            &                    zqsatw, sf(jp_humi)%fnow(:,:,1), wndm, &
-            &                    Cd    , Ch              , Ce    )
-      ENDIF
-
-      ! ... tau module, i and j component
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zztmp = rhoa * wndm(ji,jj) * Cd(ji,jj)
-            taum  (ji,jj) = zztmp * wndm  (ji,jj)
-            zwnd_i(ji,jj) = zztmp * zwnd_i(ji,jj)
-            zwnd_j(ji,jj) = zztmp * zwnd_j(ji,jj)
-         END DO
-      END DO
-
-      ! ... add the HF tau contribution to the wind stress module?
-      IF( lhftau ) THEN 
-!CDIR COLLAPSE
-         taum(:,:) = taum(:,:) + sf(jp_tdif)%fnow(:,:,1)
-      ENDIF
-      CALL iom_put( "taum_oce", taum )   ! output wind stress module
-
-      ! ... utau, vtau at U- and V_points, resp.
-      !     Note the use of 0.5*(2-umask) in order to unmask the stress along coastlines
-      DO jj = 1, jpjm1
-         DO ji = 1, fs_jpim1
-            utau(ji,jj) = 0.5 * ( 2. - umask(ji,jj,1) ) * ( zwnd_i(ji,jj) + zwnd_i(ji+1,jj  ) )
-            vtau(ji,jj) = 0.5 * ( 2. - vmask(ji,jj,1) ) * ( zwnd_j(ji,jj) + zwnd_j(ji  ,jj+1) )
-         END DO
-      END DO
-      CALL lbc_lnk( utau(:,:), 'U', -1. )
-      CALL lbc_lnk( vtau(:,:), 'V', -1. )
-
-      !  Turbulent fluxes over ocean
-      ! -----------------------------
-      IF( ln_2m ) THEN
-         ! Values of temp. and hum. adjusted to 10m must be used instead of 2m values
-         zevap(:,:) = rn_efac * MAX( 0.e0, rhoa    *Ce(:,:)*( zqsatw(:,:) - zq_zu(:,:) ) * wndm(:,:) )   ! Evaporation
-         zqsb (:,:) =                      rhoa*cpa*Ch(:,:)*( zst   (:,:) - zt_zu(:,:) ) * wndm(:,:)     ! Sensible Heat
-      ELSE
-!CDIR COLLAPSE
-         zevap(:,:) = rn_efac * MAX( 0.e0, rhoa    *Ce(:,:)*( zqsatw(:,:) - sf(jp_humi)%fnow(:,:,1) ) * wndm(:,:) )   ! Evaporation
-!CDIR COLLAPSE
-         zqsb (:,:) =                      rhoa*cpa*Ch(:,:)*( zst   (:,:) - sf(jp_tair)%fnow(:,:,1) ) * wndm(:,:)     ! Sensible Heat
-      ENDIF
-!CDIR COLLAPSE
-      zqla (:,:) = Lv * zevap(:,:)                                                              ! Latent Heat
-
-      IF(ln_ctl) THEN
-         CALL prt_ctl( tab2d_1=zqla  , clinfo1=' blk_oce_core: zqla   : ', tab2d_2=Ce , clinfo2=' Ce  : ' )
-         CALL prt_ctl( tab2d_1=zqsb  , clinfo1=' blk_oce_core: zqsb   : ', tab2d_2=Ch , clinfo2=' Ch  : ' )
-         CALL prt_ctl( tab2d_1=zqlw  , clinfo1=' blk_oce_core: zqlw   : ', tab2d_2=qsr, clinfo2=' qsr : ' )
-         CALL prt_ctl( tab2d_1=zqsatw, clinfo1=' blk_oce_core: zqsatw : ', tab2d_2=zst, clinfo2=' zst : ' )
-         CALL prt_ctl( tab2d_1=utau  , clinfo1=' blk_oce_core: utau   : ', mask1=umask,   &
-            &          tab2d_2=vtau  , clinfo2=              ' vtau : '  , mask2=vmask )
-         CALL prt_ctl( tab2d_1=wndm  , clinfo1=' blk_oce_core: wndm   : ')
-         CALL prt_ctl( tab2d_1=zst   , clinfo1=' blk_oce_core: zst    : ')
-      ENDIF
-       
-      ! ----------------------------------------------------------------------------- !
-      !     III    Total FLUXES                                                       !
-      ! ----------------------------------------------------------------------------- !
-     
-!CDIR COLLAPSE
-      qns(:,:) = zqlw(:,:) - zqsb(:,:) - zqla(:,:)      ! Downward Non Solar flux
-!CDIR COLLAPSE
-      emp(:,:) = zevap(:,:) - sf(jp_prec)%fnow(:,:,1) * rn_pfac * tmask(:,:,1)
-!CDIR COLLAPSE
-      emps(:,:) = emp(:,:)
-      !
-      CALL iom_put( "qlw_oce",   zqlw )                 ! output downward longwave heat over the ocean
-      CALL iom_put( "qsb_oce", - zqsb )                 ! output downward sensible heat over the ocean
-      CALL iom_put( "qla_oce", - zqla )                 ! output downward latent   heat over the ocean
-      CALL iom_put( "qns_oce",   qns  )                 ! output downward non solar heat over the ocean
-      !
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab2d_1=zqsb , clinfo1=' blk_oce_core: zqsb   : ', tab2d_2=zqlw , clinfo2=' zqlw  : ')
-         CALL prt_ctl(tab2d_1=zqla , clinfo1=' blk_oce_core: zqla   : ', tab2d_2=qsr  , clinfo2=' qsr   : ')
-         CALL prt_ctl(tab2d_1=pst  , clinfo1=' blk_oce_core: pst    : ', tab2d_2=emp  , clinfo2=' emp   : ')
-         CALL prt_ctl(tab2d_1=utau , clinfo1=' blk_oce_core: utau   : ', mask1=umask,   &
-            &         tab2d_2=vtau , clinfo2=              ' vtau  : ' , mask2=vmask )
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi,jpj, zwnd_i, zwnd_j, zqsatw, zqlw, zqsb, zqla, zevap )
-      CALL wrk_dealloc( jpi,jpj, Cd, Ch, Ce, zst, zt_zu, zq_zu )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('blk_oce_core')
-      !
-   END SUBROUTINE blk_oce_core
-   
-   
-   SUBROUTINE blk_ice_core(  pst   , pui   , pvi   , palb ,   &
-      &                      p_taui, p_tauj, p_qns , p_qsr,   &
-      &                      p_qla , p_dqns, p_dqla,          &
-      &                      p_tpr , p_spr ,                  &
-      &                      p_fr1 , p_fr2 , cd_grid, pdim  ) 
-      !!---------------------------------------------------------------------
-      !!                     ***  ROUTINE blk_ice_core  ***
-      !!
-      !! ** Purpose :   provide the surface boundary condition over sea-ice
-      !!
-      !! ** Method  :   compute momentum, heat and freshwater exchanged
-      !!                between atmosphere and sea-ice using CORE bulk
-      !!                formulea, ice variables and read atmmospheric fields.
-      !!                NB: ice drag coefficient is assumed to be a constant
-      !! 
-      !! caution : the net upward water flux has with mm/day unit
-      !!---------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pst      ! ice surface temperature (>0, =rt0 over land) [Kelvin]
-      REAL(wp), DIMENSION(:,:)  , INTENT(in   ) ::   pui      ! ice surface velocity (i- and i- components      [m/s]
-      REAL(wp), DIMENSION(:,:)  , INTENT(in   ) ::   pvi      !    at I-point (B-grid) or U & V-point (C-grid)
-      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   palb     ! ice albedo (clear sky) (alb_ice_cs)               [%]
-      REAL(wp), DIMENSION(:,:)  , INTENT(  out) ::   p_taui   ! i- & j-components of surface ice stress        [N/m2]
-      REAL(wp), DIMENSION(:,:)  , INTENT(  out) ::   p_tauj   !   at I-point (B-grid) or U & V-point (C-grid)
-      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   p_qns    ! non solar heat flux over ice (T-point)         [W/m2]
-      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   p_qsr    !     solar heat flux over ice (T-point)         [W/m2]
-      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   p_qla    ! latent    heat flux over ice (T-point)         [W/m2]
-      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   p_dqns   ! non solar heat sensistivity  (T-point)         [W/m2]
-      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   p_dqla   ! latent    heat sensistivity  (T-point)         [W/m2]
-      REAL(wp), DIMENSION(:,:)  , INTENT(  out) ::   p_tpr    ! total precipitation          (T-point)      [Kg/m2/s]
-      REAL(wp), DIMENSION(:,:)  , INTENT(  out) ::   p_spr    ! solid precipitation          (T-point)      [Kg/m2/s]
-      REAL(wp), DIMENSION(:,:)  , INTENT(  out) ::   p_fr1    ! 1sr fraction of qsr penetration in ice (T-point)  [%]
-      REAL(wp), DIMENSION(:,:)  , INTENT(  out) ::   p_fr2    ! 2nd fraction of qsr penetration in ice (T-point)  [%]
-      CHARACTER(len=1)          , INTENT(in   ) ::   cd_grid  ! ice grid ( C or B-grid)
-      INTEGER                   , INTENT(in   ) ::   pdim     ! number of ice categories
-      !!
-      INTEGER  ::   ji, jj, jl    ! dummy loop indices
-      INTEGER  ::   ijpl          ! number of ice categories (size of 3rd dim of input arrays)
-      REAL(wp) ::   zst2, zst3
-      REAL(wp) ::   zcoef_wnorm, zcoef_wnorm2, zcoef_dqlw, zcoef_dqla, zcoef_dqsb
-      REAL(wp) ::   zztmp                                        ! temporary variable
-      REAL(wp) ::   zcoef_frca                                   ! fractional cloud amount
-      REAL(wp) ::   zwnorm_f, zwndi_f , zwndj_f                  ! relative wind module and components at F-point
-      REAL(wp) ::             zwndi_t , zwndj_t                  ! relative wind components at T-point
-      !!
-      REAL(wp), DIMENSION(:,:)  , POINTER ::   z_wnds_t          ! wind speed ( = | U10m - U_ice | ) at T-point
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   z_qlw             ! long wave heat flux over ice
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   z_qsb             ! sensible  heat flux over ice
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   z_dqlw            ! long wave heat sensitivity over ice
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   z_dqsb            ! sensible  heat sensitivity over ice
-      !!---------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('blk_ice_core')
-      !
-      CALL wrk_alloc( jpi,jpj, z_wnds_t )
-      CALL wrk_alloc( jpi,jpj,pdim, z_qlw, z_qsb, z_dqlw, z_dqsb ) 
-
-      ijpl  = pdim                            ! number of ice categories
-
-      ! local scalars ( place there for vector optimisation purposes)
-      zcoef_wnorm  = rhoa * Cice
-      zcoef_wnorm2 = rhoa * Cice * 0.5
-      zcoef_dqlw   = 4.0 * 0.95 * Stef
-      zcoef_dqla   = -Ls * Cice * 11637800. * (-5897.8)
-      zcoef_dqsb   = rhoa * cpa * Cice
-      zcoef_frca   = 1.0  - 0.3
-
-!!gm brutal....
-      z_wnds_t(:,:) = 0.e0
-      p_taui  (:,:) = 0.e0
-      p_tauj  (:,:) = 0.e0
-!!gm end
-
-#if defined key_lim3
-      tatm_ice(:,:) = sf(jp_tair)%fnow(:,:,1)   ! LIM3: make Tair available in sea-ice. WARNING allocated after call to ice_init
-#endif
-      ! ----------------------------------------------------------------------------- !
-      !    Wind components and module relative to the moving ocean ( U10m - U_ice )   !
-      ! ----------------------------------------------------------------------------- !
-      SELECT CASE( cd_grid )
-      CASE( 'I' )                  ! B-grid ice dynamics :   I-point (i.e. F-point with sea-ice indexation)
-         !                           and scalar wind at T-point ( = | U10m - U_ice | ) (masked)
-!CDIR NOVERRCHK
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1   ! B grid : NO vector opt
-               ! ... scalar wind at I-point (fld being at T-point)
-               zwndi_f = 0.25 * (  sf(jp_wndi)%fnow(ji-1,jj  ,1) + sf(jp_wndi)%fnow(ji  ,jj  ,1)   &
-                  &              + sf(jp_wndi)%fnow(ji-1,jj-1,1) + sf(jp_wndi)%fnow(ji  ,jj-1,1)  ) - rn_vfac * pui(ji,jj)
-               zwndj_f = 0.25 * (  sf(jp_wndj)%fnow(ji-1,jj  ,1) + sf(jp_wndj)%fnow(ji  ,jj  ,1)   &
-                  &              + sf(jp_wndj)%fnow(ji-1,jj-1,1) + sf(jp_wndj)%fnow(ji  ,jj-1,1)  ) - rn_vfac * pvi(ji,jj)
-               zwnorm_f = zcoef_wnorm * SQRT( zwndi_f * zwndi_f + zwndj_f * zwndj_f )
-               ! ... ice stress at I-point
-               p_taui(ji,jj) = zwnorm_f * zwndi_f
-               p_tauj(ji,jj) = zwnorm_f * zwndj_f
-               ! ... scalar wind at T-point (fld being at T-point)
-               zwndi_t = sf(jp_wndi)%fnow(ji,jj,1) - rn_vfac * 0.25 * (  pui(ji,jj+1) + pui(ji+1,jj+1)   &
-                  &                                                    + pui(ji,jj  ) + pui(ji+1,jj  )  )
-               zwndj_t = sf(jp_wndj)%fnow(ji,jj,1) - rn_vfac * 0.25 * (  pvi(ji,jj+1) + pvi(ji+1,jj+1)   &
-                  &                                                    + pvi(ji,jj  ) + pvi(ji+1,jj  )  )
-               z_wnds_t(ji,jj)  = SQRT( zwndi_t * zwndi_t + zwndj_t * zwndj_t ) * tmask(ji,jj,1)
-            END DO
-         END DO
-         CALL lbc_lnk( p_taui  , 'I', -1. )
-         CALL lbc_lnk( p_tauj  , 'I', -1. )
-         CALL lbc_lnk( z_wnds_t, 'T',  1. )
-         !
-      CASE( 'C' )                  ! C-grid ice dynamics :   U & V-points (same as ocean)
-#if defined key_vectopt_loop
-!CDIR COLLAPSE
-#endif
-         DO jj = 2, jpj
-            DO ji = fs_2, jpi   ! vect. opt.
-               zwndi_t = (  sf(jp_wndi)%fnow(ji,jj,1) - rn_vfac * 0.5 * ( pui(ji-1,jj  ) + pui(ji,jj) )  )
-               zwndj_t = (  sf(jp_wndj)%fnow(ji,jj,1) - rn_vfac * 0.5 * ( pvi(ji  ,jj-1) + pvi(ji,jj) )  )
-               z_wnds_t(ji,jj)  = SQRT( zwndi_t * zwndi_t + zwndj_t * zwndj_t ) * tmask(ji,jj,1)
-            END DO
-         END DO
-#if defined key_vectopt_loop
-!CDIR COLLAPSE
-#endif
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vect. opt.
-               p_taui(ji,jj) = zcoef_wnorm2 * ( z_wnds_t(ji+1,jj  ) + z_wnds_t(ji,jj) )                          &
-                  &          * ( 0.5 * (sf(jp_wndi)%fnow(ji+1,jj,1) + sf(jp_wndi)%fnow(ji,jj,1) ) - pui(ji,jj) )
-               p_tauj(ji,jj) = zcoef_wnorm2 * ( z_wnds_t(ji,jj+1  ) + z_wnds_t(ji,jj) )                          &
-                  &          * ( 0.5 * (sf(jp_wndj)%fnow(ji,jj+1,1) + sf(jp_wndj)%fnow(ji,jj,1) ) - pvi(ji,jj) )
-            END DO
-         END DO
-         CALL lbc_lnk( p_taui  , 'U', -1. )
-         CALL lbc_lnk( p_tauj  , 'V', -1. )
-         CALL lbc_lnk( z_wnds_t, 'T',  1. )
-         !
-      END SELECT
-
-      zztmp = 1. / ( 1. - albo )
-      !                                     ! ========================== !
-      DO jl = 1, ijpl                       !  Loop over ice categories  !
-         !                                  ! ========================== !
-!CDIR NOVERRCHK
-!CDIR COLLAPSE
-         DO jj = 1 , jpj
-!CDIR NOVERRCHK
-            DO ji = 1, jpi
-               ! ----------------------------!
-               !      I   Radiative FLUXES   !
-               ! ----------------------------!
-               zst2 = pst(ji,jj,jl) * pst(ji,jj,jl)
-               zst3 = pst(ji,jj,jl) * zst2
-               ! Short Wave (sw)
-               p_qsr(ji,jj,jl) = zztmp * ( 1. - palb(ji,jj,jl) ) * qsr(ji,jj)
-               ! Long  Wave (lw)
-               ! iovino
-               IF( ff(ji,jj) .GT. 0._wp ) THEN
-                  z_qlw(ji,jj,jl) = ( 0.95 * sf(jp_qlw)%fnow(ji,jj,1) - Stef * pst(ji,jj,jl) * zst3 ) * tmask(ji,jj,1) ! MV test 2 garde juste cette ligne ci
-               ELSE
-                  z_qlw(ji,jj,jl) = 0.95 * ( sf(jp_qlw)%fnow(ji,jj,1) - Stef * pst(ji,jj,jl) * zst3 ) * tmask(ji,jj,1) ! MV test 1 garde juste cette ligne ci
-               ENDIF
-               ! lw sensitivity
-               z_dqlw(ji,jj,jl) = zcoef_dqlw * zst3                                               
-
-               ! ----------------------------!
-               !     II    Turbulent FLUXES  !
-               ! ----------------------------!
-
-               ! ... turbulent heat fluxes
-               ! Sensible Heat
-               z_qsb(ji,jj,jl) = rhoa * cpa * Cice * z_wnds_t(ji,jj) * ( pst(ji,jj,jl) - sf(jp_tair)%fnow(ji,jj,1) )
-               ! Latent Heat
-               p_qla(ji,jj,jl) = rn_efac * MAX( 0.e0, rhoa * Ls  * Cice * z_wnds_t(ji,jj)   &                           
-                  &                         * (  11637800. * EXP( -5897.8 / pst(ji,jj,jl) ) / rhoa - sf(jp_humi)%fnow(ji,jj,1)  ) )
-               ! Latent heat sensitivity for ice (Dqla/Dt)
-               p_dqla(ji,jj,jl) = rn_efac * zcoef_dqla * z_wnds_t(ji,jj) / ( zst2 ) * EXP( -5897.8 / pst(ji,jj,jl) )
-               ! Sensible heat sensitivity (Dqsb_ice/Dtn_ice)
-               z_dqsb(ji,jj,jl) = zcoef_dqsb * z_wnds_t(ji,jj)
-               !
-               !
-               ! ----------------------------!
-               !     III    Total FLUXES     !
-               ! ----------------------------!
-               ! Downward Non Solar flux
-               p_qns (ji,jj,jl) =     z_qlw (ji,jj,jl) - z_qsb (ji,jj,jl) - p_qla (ji,jj,jl)      
-               ! Total non solar heat flux sensitivity for ice
-               p_dqns(ji,jj,jl) = - ( z_dqlw(ji,jj,jl) + z_dqsb(ji,jj,jl) + p_dqla(ji,jj,jl) )    
-            END DO
-            !
-         END DO
-         !
-      END DO
-      !
-      !--------------------------------------------------------------------
-      ! FRACTIONs of net shortwave radiation which is not absorbed in the
-      ! thin surface layer and penetrates inside the ice cover
-      ! ( Maykut and Untersteiner, 1971 ; Ebert and Curry, 1993 )
-    
-!CDIR COLLAPSE
-      p_fr1(:,:) = ( 0.18 * ( 1.0 - zcoef_frca ) + 0.35 * zcoef_frca )
-!CDIR COLLAPSE
-      p_fr2(:,:) = ( 0.82 * ( 1.0 - zcoef_frca ) + 0.65 * zcoef_frca )
-       
-!CDIR COLLAPSE
-      p_tpr(:,:) = sf(jp_prec)%fnow(:,:,1) * rn_pfac      ! total precipitation [kg/m2/s]
-!CDIR COLLAPSE
-      p_spr(:,:) = sf(jp_snow)%fnow(:,:,1) * rn_pfac      ! solid precipitation [kg/m2/s]
-      CALL iom_put( 'snowpre', p_spr * 86400 )                  ! Snow precipitation 
-      CALL iom_put( 'precip', p_tpr * 86400 )                   ! Total precipitation 
-      !
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab3d_1=p_qla   , clinfo1=' blk_ice_core: p_qla  : ', tab3d_2=z_qsb   , clinfo2=' z_qsb  : ', kdim=ijpl)
-         CALL prt_ctl(tab3d_1=z_qlw   , clinfo1=' blk_ice_core: z_qlw  : ', tab3d_2=p_dqla  , clinfo2=' p_dqla : ', kdim=ijpl)
-         CALL prt_ctl(tab3d_1=z_dqsb  , clinfo1=' blk_ice_core: z_dqsb : ', tab3d_2=z_dqlw  , clinfo2=' z_dqlw : ', kdim=ijpl)
-         CALL prt_ctl(tab3d_1=p_dqns  , clinfo1=' blk_ice_core: p_dqns : ', tab3d_2=p_qsr   , clinfo2=' p_qsr  : ', kdim=ijpl)
-         CALL prt_ctl(tab3d_1=pst     , clinfo1=' blk_ice_core: pst    : ', tab3d_2=p_qns   , clinfo2=' p_qns  : ', kdim=ijpl)
-         CALL prt_ctl(tab2d_1=p_tpr   , clinfo1=' blk_ice_core: p_tpr  : ', tab2d_2=p_spr   , clinfo2=' p_spr  : ')
-         CALL prt_ctl(tab2d_1=p_taui  , clinfo1=' blk_ice_core: p_taui : ', tab2d_2=p_tauj  , clinfo2=' p_tauj : ')
-         CALL prt_ctl(tab2d_1=z_wnds_t, clinfo1=' blk_ice_core: z_wnds_t : ')
-      ENDIF
-
-      CALL wrk_dealloc( jpi,jpj, z_wnds_t )
-      CALL wrk_dealloc( jpi,jpj,pdim, z_qlw, z_qsb, z_dqlw, z_dqsb ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('blk_ice_core')
-      !
-   END SUBROUTINE blk_ice_core
-  
-
-   SUBROUTINE TURB_CORE_1Z(zu, sst, T_a, q_sat, q_a,   &
-      &                        dU , Cd , Ch   , Ce   )
-      !!----------------------------------------------------------------------
-      !!                      ***  ROUTINE  turb_core  ***
-      !!
-      !! ** Purpose :   Computes turbulent transfert coefficients of surface
-      !!                fluxes according to Large & Yeager (2004)
-      !!
-      !! ** Method  :   I N E R T I A L   D I S S I P A T I O N   M E T H O D
-      !!      Momentum, Latent and sensible heat exchange coefficients
-      !!      Caution: this procedure should only be used in cases when air
-      !!      temperature (T_air), air specific humidity (q_air) and wind (dU)
-      !!      are provided at the same height 'zzu'!
-      !!
-      !! References :   Large & Yeager, 2004 : ???
-      !!----------------------------------------------------------------------
-      REAL(wp)                , INTENT(in   ) ::   zu      ! altitude of wind measurement       [m]
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   sst     ! sea surface temperature         [Kelvin]
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   T_a     ! potential air temperature       [Kelvin]
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   q_sat   ! sea surface specific humidity   [kg/kg]
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   q_a     ! specific air humidity           [kg/kg]
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   dU      ! wind module |U(zu)-U(0)|        [m/s]
-      REAL(wp), DIMENSION(:,:), INTENT(  out) ::   Cd      ! transfert coefficient for momentum       (tau)
-      REAL(wp), DIMENSION(:,:), INTENT(  out) ::   Ch      ! transfert coefficient for temperature (Q_sens)
-      REAL(wp), DIMENSION(:,:), INTENT(  out) ::   Ce      ! transfert coefficient for evaporation  (Q_lat)
-      !!
-      INTEGER :: j_itt
-      INTEGER , PARAMETER ::   nb_itt = 3
-      REAL(wp), PARAMETER ::   grav   = 9.8   ! gravity                       
-      REAL(wp), PARAMETER ::   kappa  = 0.4   ! von Karman s constant
-
-      REAL(wp), DIMENSION(:,:), POINTER  ::   dU10          ! dU                                   [m/s]
-      REAL(wp), DIMENSION(:,:), POINTER  ::   dT            ! air/sea temperature differeence      [K]
-      REAL(wp), DIMENSION(:,:), POINTER  ::   dq            ! air/sea humidity difference          [K]
-      REAL(wp), DIMENSION(:,:), POINTER  ::   Cd_n10        ! 10m neutral drag coefficient
-      REAL(wp), DIMENSION(:,:), POINTER  ::   Ce_n10        ! 10m neutral latent coefficient
-      REAL(wp), DIMENSION(:,:), POINTER  ::   Ch_n10        ! 10m neutral sensible coefficient
-      REAL(wp), DIMENSION(:,:), POINTER  ::   sqrt_Cd_n10   ! root square of Cd_n10
-      REAL(wp), DIMENSION(:,:), POINTER  ::   sqrt_Cd       ! root square of Cd
-      REAL(wp), DIMENSION(:,:), POINTER  ::   T_vpot        ! virtual potential temperature        [K]
-      REAL(wp), DIMENSION(:,:), POINTER  ::   T_star        ! turbulent scale of tem. fluct.
-      REAL(wp), DIMENSION(:,:), POINTER  ::   q_star        ! turbulent humidity of temp. fluct.
-      REAL(wp), DIMENSION(:,:), POINTER  ::   U_star        ! turb. scale of velocity fluct.
-      REAL(wp), DIMENSION(:,:), POINTER  ::   L             ! Monin-Obukov length                  [m]
-      REAL(wp), DIMENSION(:,:), POINTER  ::   zeta          ! stability parameter at height zu
-      REAL(wp), DIMENSION(:,:), POINTER  ::   U_n10         ! neutral wind velocity at 10m         [m]   
-      REAL(wp), DIMENSION(:,:), POINTER  ::   xlogt, xct, zpsi_h, zpsi_m
-      
-      INTEGER , DIMENSION(:,:), POINTER  ::   stab          ! 1st guess stability test integer
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('TURB_CORE_1Z')
-      !
-      CALL wrk_alloc( jpi,jpj, stab )   ! integer
-      CALL wrk_alloc( jpi,jpj, dU10, dT, dq, Cd_n10, Ce_n10, Ch_n10, sqrt_Cd_n10, sqrt_Cd, L )
-      CALL wrk_alloc( jpi,jpj, T_vpot, T_star, q_star, U_star, zeta, U_n10, xlogt, xct, zpsi_h, zpsi_m )
-
-      !! * Start
-      !! Air/sea differences
-      dU10 = max(0.5, dU)     ! we don't want to fall under 0.5 m/s
-      dT = T_a - sst          ! assuming that T_a is allready the potential temp. at zzu
-      dq = q_a - q_sat
-      !!    
-      !! Virtual potential temperature
-      T_vpot = T_a*(1. + 0.608*q_a)
-      !!
-      !! Neutral Drag Coefficient
-      stab    = 0.5 + sign(0.5,dT)    ! stable : stab = 1 ; unstable : stab = 0 
-      IF  ( ln_cdgw ) THEN
-        cdn_wave = cdn_wave - rsmall*(tmask(:,:,1)-1)
-        Cd_n10(:,:) =   cdn_wave
-      ELSE
-        Cd_n10  = 1E-3 * ( 2.7/dU10 + 0.142 + dU10/13.09 )    !   L & Y eq. (6a)
-      ENDIF
-      sqrt_Cd_n10 = sqrt(Cd_n10)
-      Ce_n10  = 1E-3 * ( 34.6 * sqrt_Cd_n10 )               !   L & Y eq. (6b)
-      Ch_n10  = 1E-3*sqrt_Cd_n10*(18*stab + 32.7*(1-stab)) !   L & Y eq. (6c), (6d)
-      !!
-      !! Initializing transfert coefficients with their first guess neutral equivalents :
-      Cd = Cd_n10 ;  Ce = Ce_n10 ;  Ch = Ch_n10 ;  sqrt_Cd = sqrt(Cd)
-
-      !! * Now starting iteration loop
-      DO j_itt=1, nb_itt
-         !! Turbulent scales :
-         U_star  = sqrt_Cd*dU10                !   L & Y eq. (7a)
-         T_star  = Ch/sqrt_Cd*dT               !   L & Y eq. (7b)
-         q_star  = Ce/sqrt_Cd*dq               !   L & Y eq. (7c)
-
-         !! Estimate the Monin-Obukov length :
-         L  = (U_star**2)/( kappa*grav*(T_star/T_vpot + q_star/(q_a + 1./0.608)) )
-
-         !! Stability parameters :
-         zeta  = zu/L ;  zeta   = sign( min(abs(zeta),10.0), zeta )
-         zpsi_h  = psi_h(zeta)
-         zpsi_m  = psi_m(zeta)
-
-         IF  ( ln_cdgw ) THEN
-           sqrt_Cd=kappa/((kappa/sqrt_Cd_n10) - zpsi_m) ; Cd=sqrt_Cd*sqrt_Cd;
-         ELSE
-           !! Shifting the wind speed to 10m and neutral stability :
-           U_n10 = dU10*1./(1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m)) !  L & Y eq. (9a)
-
-           !! Updating the neutral 10m transfer coefficients :
-           Cd_n10  = 1E-3 * (2.7/U_n10 + 0.142 + U_n10/13.09)              !  L & Y eq. (6a)
-           sqrt_Cd_n10 = sqrt(Cd_n10)
-           Ce_n10  = 1E-3 * (34.6 * sqrt_Cd_n10)                           !  L & Y eq. (6b)
-           stab    = 0.5 + sign(0.5,zeta)
-           Ch_n10  = 1E-3*sqrt_Cd_n10*(18.*stab + 32.7*(1-stab))           !  L & Y eq. (6c), (6d)
-
-           !! Shifting the neutral  10m transfer coefficients to ( zu , zeta ) :
-           !!
-           xct = 1. + sqrt_Cd_n10/kappa*(log(zu/10) - zpsi_m)
-           Cd  = Cd_n10/(xct*xct) ;  sqrt_Cd = sqrt(Cd)
-         ENDIF
-         !!
-         xlogt = log(zu/10.) - zpsi_h
-         !!
-         xct = 1. + Ch_n10*xlogt/kappa/sqrt_Cd_n10
-         Ch  = Ch_n10*sqrt_Cd/sqrt_Cd_n10/xct
-         !!
-         xct = 1. + Ce_n10*xlogt/kappa/sqrt_Cd_n10
-         Ce  = Ce_n10*sqrt_Cd/sqrt_Cd_n10/xct
-         !!
-      END DO
-      !!
-      CALL wrk_dealloc( jpi,jpj, stab )   ! integer
-      CALL wrk_dealloc( jpi,jpj, dU10, dT, dq, Cd_n10, Ce_n10, Ch_n10, sqrt_Cd_n10, sqrt_Cd, L )
-      CALL wrk_dealloc( jpi,jpj, T_vpot, T_star, q_star, U_star, zeta, U_n10, xlogt, xct, zpsi_h, zpsi_m )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('TURB_CORE_1Z')
-      !
-    END SUBROUTINE TURB_CORE_1Z
-
-
-    SUBROUTINE TURB_CORE_2Z(zt, zu, sst, T_zt, q_sat, q_zt, dU, Cd, Ch, Ce, T_zu, q_zu)
-      !!----------------------------------------------------------------------
-      !!                      ***  ROUTINE  turb_core  ***
-      !!
-      !! ** Purpose :   Computes turbulent transfert coefficients of surface 
-      !!                fluxes according to Large & Yeager (2004).
-      !!
-      !! ** Method  :   I N E R T I A L   D I S S I P A T I O N   M E T H O D
-      !!      Momentum, Latent and sensible heat exchange coefficients
-      !!      Caution: this procedure should only be used in cases when air
-      !!      temperature (T_air) and air specific humidity (q_air) are at 2m
-      !!      whereas wind (dU) is at 10m.
-      !!
-      !! References :   Large & Yeager, 2004 : ???
-      !!----------------------------------------------------------------------
-      REAL(wp), INTENT(in   )                     ::   zt       ! height for T_zt and q_zt                   [m]
-      REAL(wp), INTENT(in   )                     ::   zu       ! height for dU                              [m]
-      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   sst      ! sea surface temperature              [Kelvin]
-      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   T_zt     ! potential air temperature            [Kelvin]
-      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   q_sat    ! sea surface specific humidity         [kg/kg]
-      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   q_zt     ! specific air humidity                 [kg/kg]
-      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   dU       ! relative wind module |U(zu)-U(0)|       [m/s]
-      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   Cd       ! transfer coefficient for momentum         (tau)
-      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   Ch       ! transfer coefficient for sensible heat (Q_sens)
-      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   Ce       ! transfert coefficient for evaporation   (Q_lat)
-      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   T_zu     ! air temp. shifted at zu                     [K]
-      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   q_zu     ! spec. hum.  shifted at zu               [kg/kg]
-
-      INTEGER :: j_itt
-      INTEGER , PARAMETER :: nb_itt = 3              ! number of itterations
-      REAL(wp), PARAMETER ::   grav   = 9.8          ! gravity                       
-      REAL(wp), PARAMETER ::   kappa  = 0.4          ! von Karman's constant
-      
-      REAL(wp), DIMENSION(:,:), POINTER ::   dU10          ! dU                                [m/s]
-      REAL(wp), DIMENSION(:,:), POINTER ::   dT            ! air/sea temperature differeence   [K]
-      REAL(wp), DIMENSION(:,:), POINTER ::   dq            ! air/sea humidity difference       [K]
-      REAL(wp), DIMENSION(:,:), POINTER ::   Cd_n10        ! 10m neutral drag coefficient
-      REAL(wp), DIMENSION(:,:), POINTER ::   Ce_n10        ! 10m neutral latent coefficient
-      REAL(wp), DIMENSION(:,:), POINTER ::   Ch_n10        ! 10m neutral sensible coefficient
-      REAL(wp), DIMENSION(:,:), POINTER ::   sqrt_Cd_n10   ! root square of Cd_n10
-      REAL(wp), DIMENSION(:,:), POINTER ::   sqrt_Cd       ! root square of Cd
-      REAL(wp), DIMENSION(:,:), POINTER ::   T_vpot        ! virtual potential temperature        [K]
-      REAL(wp), DIMENSION(:,:), POINTER ::   T_star        ! turbulent scale of tem. fluct.
-      REAL(wp), DIMENSION(:,:), POINTER ::   q_star        ! turbulent humidity of temp. fluct.
-      REAL(wp), DIMENSION(:,:), POINTER ::   U_star        ! turb. scale of velocity fluct.
-      REAL(wp), DIMENSION(:,:), POINTER ::   L             ! Monin-Obukov length                  [m]
-      REAL(wp), DIMENSION(:,:), POINTER ::   zeta_u        ! stability parameter at height zu
-      REAL(wp), DIMENSION(:,:), POINTER ::   zeta_t        ! stability parameter at height zt
-      REAL(wp), DIMENSION(:,:), POINTER ::   U_n10         ! neutral wind velocity at 10m        [m]
-      REAL(wp), DIMENSION(:,:), POINTER ::   xlogt, xct, zpsi_hu, zpsi_ht, zpsi_m
-
-      INTEGER , DIMENSION(:,:), POINTER ::   stab          ! 1st stability test integer
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('TURB_CORE_2Z')
-      !
-      CALL wrk_alloc( jpi,jpj, dU10, dT, dq, Cd_n10, Ce_n10, Ch_n10, sqrt_Cd_n10, sqrt_Cd, L )
-      CALL wrk_alloc( jpi,jpj, T_vpot, T_star, q_star, U_star, zeta_u, zeta_t, U_n10 )
-      CALL wrk_alloc( jpi,jpj, xlogt, xct, zpsi_hu, zpsi_ht, zpsi_m )
-      CALL wrk_alloc( jpi,jpj, stab )   ! interger
-
-      !! Initial air/sea differences
-      dU10 = max(0.5, dU)      !  we don't want to fall under 0.5 m/s
-      dT = T_zt - sst 
-      dq = q_zt - q_sat
-
-      !! Neutral Drag Coefficient :
-      stab = 0.5 + sign(0.5,dT)                 ! stab = 1  if dT > 0  -> STABLE
-      IF( ln_cdgw ) THEN
-        cdn_wave = cdn_wave - rsmall*(tmask(:,:,1)-1)
-        Cd_n10(:,:) =   cdn_wave
-      ELSE
-        Cd_n10  = 1E-3*( 2.7/dU10 + 0.142 + dU10/13.09 ) 
-      ENDIF
-      sqrt_Cd_n10 = sqrt(Cd_n10)
-      Ce_n10  = 1E-3*( 34.6 * sqrt_Cd_n10 )
-      Ch_n10  = 1E-3*sqrt_Cd_n10*(18*stab + 32.7*(1 - stab))
-
-      !! Initializing transf. coeff. with their first guess neutral equivalents :
-      Cd = Cd_n10 ;  Ce = Ce_n10 ;  Ch = Ch_n10 ;  sqrt_Cd = sqrt(Cd)
-
-      !! Initializing z_u values with z_t values :
-      T_zu = T_zt ;  q_zu = q_zt
-
-      !!  * Now starting iteration loop
-      DO j_itt=1, nb_itt
-         dT = T_zu - sst ;  dq = q_zu - q_sat ! Updating air/sea differences
-         T_vpot = T_zu*(1. + 0.608*q_zu)    ! Updating virtual potential temperature at zu
-         U_star = sqrt_Cd*dU10                ! Updating turbulent scales :   (L & Y eq. (7))
-         T_star  = Ch/sqrt_Cd*dT              !
-         q_star  = Ce/sqrt_Cd*dq              !
-         !!
-         L = (U_star*U_star) &                ! Estimate the Monin-Obukov length at height zu
-              & / (kappa*grav/T_vpot*(T_star*(1.+0.608*q_zu) + 0.608*T_zu*q_star))
-         !! Stability parameters :
-         zeta_u  = zu/L  ;  zeta_u = sign( min(abs(zeta_u),10.0), zeta_u )
-         zeta_t  = zt/L  ;  zeta_t = sign( min(abs(zeta_t),10.0), zeta_t )
-         zpsi_hu = psi_h(zeta_u)
-         zpsi_ht = psi_h(zeta_t)
-         zpsi_m  = psi_m(zeta_u)
-         !!
-         !! Shifting the wind speed to 10m and neutral stability : (L & Y eq.(9a))
-!        U_n10 = dU10/(1. + sqrt_Cd_n10/kappa*(log(zu/10.) - psi_m(zeta_u)))
-         U_n10 = dU10/(1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m))
-         !!
-         !! Shifting temperature and humidity at zu :          (L & Y eq. (9b-9c))
-!        T_zu = T_zt - T_star/kappa*(log(zt/zu) + psi_h(zeta_u) - psi_h(zeta_t))
-         T_zu = T_zt - T_star/kappa*(log(zt/zu) + zpsi_hu - zpsi_ht)
-!        q_zu = q_zt - q_star/kappa*(log(zt/zu) + psi_h(zeta_u) - psi_h(zeta_t))
-         q_zu = q_zt - q_star/kappa*(log(zt/zu) + zpsi_hu - zpsi_ht)
-         !!
-         !! q_zu cannot have a negative value : forcing 0
-         stab = 0.5 + sign(0.5,q_zu) ;  q_zu = stab*q_zu
-         !!
-         IF( ln_cdgw ) THEN
-            sqrt_Cd=kappa/((kappa/sqrt_Cd_n10) - zpsi_m) ; Cd=sqrt_Cd*sqrt_Cd;
-         ELSE
-           !! Updating the neutral 10m transfer coefficients :
-           Cd_n10  = 1E-3 * (2.7/U_n10 + 0.142 + U_n10/13.09)    ! L & Y eq. (6a)
-           sqrt_Cd_n10 = sqrt(Cd_n10)
-           Ce_n10  = 1E-3 * (34.6 * sqrt_Cd_n10)                 ! L & Y eq. (6b)
-           stab    = 0.5 + sign(0.5,zeta_u)
-           Ch_n10  = 1E-3*sqrt_Cd_n10*(18.*stab + 32.7*(1-stab)) ! L & Y eq. (6c-6d)
-           !!
-           !!
-           !! Shifting the neutral 10m transfer coefficients to (zu,zeta_u) :
-           xct = 1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m)
-           Cd = Cd_n10/(xct*xct) ; sqrt_Cd = sqrt(Cd)
-         ENDIF
-         !!
-         xlogt = log(zu/10.) - zpsi_hu
-         !!
-         xct = 1. + Ch_n10*xlogt/kappa/sqrt_Cd_n10
-         Ch  = Ch_n10*sqrt_Cd/sqrt_Cd_n10/xct
-         !!
-         xct = 1. + Ce_n10*xlogt/kappa/sqrt_Cd_n10
-         Ce  = Ce_n10*sqrt_Cd/sqrt_Cd_n10/xct
-         !!
-         !!
-      END DO
-      !!
-      CALL wrk_dealloc( jpi,jpj, dU10, dT, dq, Cd_n10, Ce_n10, Ch_n10, sqrt_Cd_n10, sqrt_Cd, L )
-      CALL wrk_dealloc( jpi,jpj, T_vpot, T_star, q_star, U_star, zeta_u, zeta_t, U_n10 )
-      CALL wrk_dealloc( jpi,jpj, xlogt, xct, zpsi_hu, zpsi_ht, zpsi_m )
-      CALL wrk_dealloc( jpi,jpj, stab )   ! interger
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('TURB_CORE_2Z')
-      !
-    END SUBROUTINE TURB_CORE_2Z
-
-
-    FUNCTION psi_m(zta)   !! Psis, L & Y eq. (8c), (8d), (8e)
-      !-------------------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: zta
-
-      REAL(wp), PARAMETER :: pi = 3.141592653589793_wp
-      REAL(wp), DIMENSION(jpi,jpj)             :: psi_m
-      REAL(wp), DIMENSION(:,:), POINTER        :: X2, X, stabit
-      !-------------------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj, X2, X, stabit )
-
-      X2 = sqrt(abs(1. - 16.*zta))  ;  X2 = max(X2 , 1.0) ;  X  = sqrt(X2)
-      stabit    = 0.5 + sign(0.5,zta)
-      psi_m = -5.*zta*stabit  &                                                          ! Stable
-         &    + (1. - stabit)*(2*log((1. + X)/2) + log((1. + X2)/2) - 2*atan(X) + pi/2)  ! Unstable 
-
-      CALL wrk_dealloc( jpi,jpj, X2, X, stabit )
-      !
-    END FUNCTION psi_m
-
-
-    FUNCTION psi_h( zta )    !! Psis, L & Y eq. (8c), (8d), (8e)
-      !-------------------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   zta
-      !
-      REAL(wp), DIMENSION(jpi,jpj)             ::   psi_h
-      REAL(wp), DIMENSION(:,:), POINTER        :: X2, X, stabit
-      !-------------------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj, X2, X, stabit )
-
-      X2 = sqrt(abs(1. - 16.*zta))  ;  X2 = max(X2 , 1.) ;  X  = sqrt(X2)
-      stabit    = 0.5 + sign(0.5,zta)
-      psi_h = -5.*zta*stabit  &                                       ! Stable
-         &    + (1. - stabit)*(2.*log( (1. + X2)/2. ))                 ! Unstable
-
-      CALL wrk_dealloc( jpi,jpj, X2, X, stabit )
-      !
-    END FUNCTION psi_h
-  
-   !!======================================================================
-END MODULE sbcblk_core
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/sbcfwb.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/sbcfwb.F90	(revision 3937)
+++ 	(revision )
@@ -1,204 +1,0 @@
-MODULE sbcfwb
-   !!======================================================================
-   !!                       ***  MODULE  sbcfwb  ***
-   !! Ocean fluxes   : domain averaged freshwater budget
-   !!======================================================================
-   !! History :  OPA  ! 2001-02  (E. Durand)  Original code
-   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
-   !!            3.0  ! 2006-08  (G. Madec)  Surface module
-   !!            3.2  ! 2009-07  (C. Talandier) emp mean s spread over erp area 
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   sbc_fwb      : freshwater budget for global ocean configurations
-   !!                  in free surface and forced mode
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! surface ocean boundary condition
-   USE phycst          ! physical constants
-   USE sbcrnf          ! ocean runoffs
-   USE sbcssr          ! SS damping terms
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! distribued memory computing library
-   USE wrk_nemo        ! work arrays
-   USE timing          ! Timing
-   USE lbclnk          ! ocean lateral boundary conditions
-   USE lib_fortran
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   sbc_fwb    ! routine called by step
-
-   REAL(wp) ::   a_fwb_b   ! annual domain averaged freshwater budget
-   REAL(wp) ::   a_fwb     ! for 2 year before (_b) and before year.
-   REAL(wp) ::   fwfold    ! fwfold to be suppressed
-   REAL(wp) ::   area      ! global mean ocean surface (interior domain)
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: sbcfwb.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE sbc_fwb( kt, kn_fwb, kn_fsbc )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE sbc_fwb  ***
-      !!
-      !! ** Purpose :   Control the mean sea surface drift
-      !!
-      !! ** Method  :   several ways  depending on kn_fwb
-      !!                =0 no control 
-      !!                =1 global mean of emp set to zero at each nn_fsbc time step
-      !!                =2 annual global mean corrected from previous year
-      !!                =3 global mean of emp set to zero at each nn_fsbc time step
-      !!                   & spread out over erp area depending its sign
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
-      INTEGER, INTENT( in ) ::   kn_fsbc  ! 
-      INTEGER, INTENT( in ) ::   kn_fwb   ! ocean time-step index
-      !
-      INTEGER  ::   inum, ikty, iyear   ! local integers
-      REAL(wp) ::   z_fwf, z_fwf_nsrf, zsum_fwf, zsum_erp   ! local scalars
-      REAL(wp) ::   zsurf_neg, zsurf_pos, zsurf_tospread    !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   ztmsk_neg, ztmsk_pos, ztmsk_tospread, z_wgt, zerp_cor
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('sbc_fwb')
-      !
-      CALL wrk_alloc( jpi,jpj, ztmsk_neg, ztmsk_pos, ztmsk_tospread, z_wgt, zerp_cor )
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) 'sbc_fwb : FreshWater Budget correction'
-            WRITE(numout,*) '~~~~~~~'
-            IF( kn_fwb == 1 )   WRITE(numout,*) '          instantaneously set to zero'
-            IF( kn_fwb == 2 )   WRITE(numout,*) '          adjusted from previous year budget'
-            IF( kn_fwb == 3 )   WRITE(numout,*) '          fwf set to zero and spread out over erp area'
-         ENDIF
-         !
-         IF( kn_fwb == 3 .AND. nn_sssr /= 2 )   CALL ctl_stop( 'sbc_fwb: nn_fwb = 3 requires nn_sssr = 2, we stop ' )
-         !
-         area = glob_sum( e1e2t(:,:) )           ! interior global domain surface
-      ENDIF
-      
-
-      SELECT CASE ( kn_fwb )
-      !
-      CASE ( 1 )                             !==  global mean fwf set to zero  ==!
-         !
-         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN
-            z_fwf = glob_sum( e1e2t(:,:) * ( emp(:,:) - rnf(:,:) ) ) / area   ! sum over the global domain
-            emp (:,:) = emp (:,:) - z_fwf 
-            erp (:,:) = erp (:,:) - z_fwf 
-!SF bad            emps(:,:) = emps(:,:) - z_fwf 
-         ENDIF
-         !
-      CASE ( 2 )                             !==  fwf budget adjusted from the previous year  ==!
-         !
-         IF( kt == nit000 ) THEN                   ! initialisation
-            !                                         ! Read the corrective factor on precipitations (fwfold)
-            CALL ctl_opn( inum, 'EMPave_old.dat', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
-            READ ( inum, "(24X,I8,2ES24.16)" ) iyear, a_fwb_b, a_fwb
-            CLOSE( inum )
-            fwfold = a_fwb                            ! current year freshwater budget correction
-            !                                         ! estimate from the previous year budget
-            IF(lwp)WRITE(numout,*)
-            IF(lwp)WRITE(numout,*)'sbc_fwb : year = ',iyear  , ' freshwater budget correction = ', fwfold
-            IF(lwp)WRITE(numout,*)'          year = ',iyear-1, ' freshwater budget read       = ', a_fwb
-            IF(lwp)WRITE(numout,*)'          year = ',iyear-2, ' freshwater budget read       = ', a_fwb_b
-         ENDIF   
-         !                                         ! Update fwfold if new year start
-         ikty = 365 * 86400 / rdttra(1)    !!bug  use of 365 days leap year or 360d year !!!!!!!
-         IF( MOD( kt, ikty ) == 0 ) THEN
-            a_fwb_b = a_fwb
-            a_fwb   = glob_sum( e1e2t(:,:) * sshn(:,:) )   ! sum over the global domain
-            a_fwb   = a_fwb * 1.e+3 / ( area * 86400. * 365. )     ! convert in Kg/m3/s = mm/s
-!!gm        !                                                      !!bug 365d year 
-            fwfold =  a_fwb                           ! current year freshwater budget correction
-            !                                         ! estimate from the previous year budget
-         ENDIF
-         ! 
-         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN      ! correct the freshwater fluxes
-            emp (:,:) = emp (:,:) + fwfold
-            erp (:,:) = erp (:,:) + fwfold
-!SF bad            emps(:,:) = emps(:,:) + fwfold
-         ENDIF
-         !
-         IF( kt == nitend .AND. lwp ) THEN         ! save fwfold value in a file
-            CALL ctl_opn( inum, 'EMPave.dat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE., narea )
-            WRITE( inum, "(24X,I8,2ES24.16)" ) nyear, a_fwb_b, a_fwb
-            CLOSE( inum )
-         ENDIF
-         !
-      CASE ( 3 )                             !==  global fwf set to zero and spread out over erp area  ==!
-         !
-         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN
-            ztmsk_pos(:,:) = tmask_i(:,:)                      ! Select <0 and >0 area of erp
-            WHERE( erp < 0._wp )   ztmsk_pos = 0._wp
-            ztmsk_neg(:,:) = tmask_i(:,:) - ztmsk_pos(:,:)
-            !
-            zsurf_neg = glob_sum( e1e2t(:,:)*ztmsk_neg(:,:) )   ! Area filled by <0 and >0 erp 
-            zsurf_pos = glob_sum( e1e2t(:,:)*ztmsk_pos(:,:) )
-            !                                                  ! fwf global mean 
-            z_fwf = glob_sum( e1e2t(:,:) * ( emp(:,:) - rnf(:,:) ) ) / area
-            !            
-            IF( z_fwf < 0._wp ) THEN         ! spread out over >0 erp area to increase evaporation
-                zsurf_tospread      = zsurf_pos
-                ztmsk_tospread(:,:) = ztmsk_pos(:,:)
-            ELSE                             ! spread out over <0 erp area to increase precipitation
-                zsurf_tospread      = zsurf_neg
-                ztmsk_tospread(:,:) = ztmsk_neg(:,:)
-            ENDIF
-            !
-            zsum_fwf   = glob_sum( e1e2t(:,:) * z_fwf )         ! fwf global mean over <0 or >0 erp area
-!!gm :  zsum_fwf   = z_fwf * area   ???  it is right?  I think so....
-            z_fwf_nsrf =  zsum_fwf / ( zsurf_tospread + rsmall )
-            !                                                  ! weight to respect erp field 2D structure 
-            zsum_erp = glob_sum( ztmsk_tospread(:,:) * erp(:,:) * e1e2t(:,:) )
-            z_wgt(:,:) = ztmsk_tospread(:,:) * erp(:,:) / ( zsum_erp + rsmall )
-            !                                                  ! final correction term to apply
-            zerp_cor(:,:) = -1. * z_fwf_nsrf * zsurf_tospread * z_wgt(:,:)
-            !
-!!gm   ===>>>>  lbc_lnk should be useless as all the computation is done over the whole domain !
-            CALL lbc_lnk( zerp_cor, 'T', 1. )
-            !
-            emp (:,:) = emp (:,:) + zerp_cor(:,:)
-!SF bad            emps(:,:) = emps(:,:) + zerp_cor(:,:)
-            erp (:,:) = erp (:,:) + zerp_cor(:,:)
-            !
-            IF( nprint == 1 .AND. lwp ) THEN                   ! control print
-               IF( z_fwf < 0._wp ) THEN
-                  WRITE(numout,*)'   z_fwf < 0'
-                  WRITE(numout,*)'   SUM(erp+)     = ', SUM( ztmsk_tospread(:,:)*erp(:,:)*e1e2t(:,:) )*1.e-9,' Sv'
-               ELSE
-                  WRITE(numout,*)'   z_fwf >= 0'
-                  WRITE(numout,*)'   SUM(erp-)     = ', SUM( ztmsk_tospread(:,:)*erp(:,:)*e1e2t(:,:) )*1.e-9,' Sv'
-               ENDIF
-               WRITE(numout,*)'   SUM(empG)     = ', SUM( z_fwf*e1e2t(:,:) )*1.e-9,' Sv'
-               WRITE(numout,*)'   z_fwf         = ', z_fwf      ,' Kg/m2/s'
-               WRITE(numout,*)'   z_fwf_nsrf    = ', z_fwf_nsrf ,' Kg/m2/s'
-               WRITE(numout,*)'   MIN(zerp_cor) = ', MINVAL(zerp_cor) 
-               WRITE(numout,*)'   MAX(zerp_cor) = ', MAXVAL(zerp_cor) 
-            ENDIF
-         ENDIF
-         !
-      CASE DEFAULT                           !==  you should never be there  ==!
-         CALL ctl_stop( 'sbc_fwb : wrong nn_fwb value for the FreshWater Budget correction, choose either 1, 2 or 3' )
-         !
-      END SELECT
-      !
-      CALL wrk_dealloc( jpi,jpj, ztmsk_neg, ztmsk_pos, ztmsk_tospread, z_wgt, zerp_cor )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('sbc_fwb')
-      !
-   END SUBROUTINE sbc_fwb
-
-   !!======================================================================
-END MODULE sbcfwb
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/sbcice_lim.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/sbcice_lim.F90	(revision 3937)
+++ 	(revision )
@@ -1,733 +1,0 @@
-MODULE sbcice_lim
-   !!======================================================================
-   !!                       ***  MODULE  sbcice_lim  ***
-   !! Surface module :  update the ocean surface boundary condition over ice
-   !!       &           covered area using LIM sea-ice model
-   !! Sea-Ice model  :  LIM-3 Sea ice model time-stepping
-   !!=====================================================================
-   !! History :  2.0  ! 2006-12  (M. Vancoppenolle) Original code
-   !!            3.0  ! 2008-02  (C. Talandier)  Surface module from icestp.F90
-   !!             -   ! 2008-04  (G. Madec)  sltyle and lim_ctl routine
-   !!            3.3  ! 2010-11  (G. Madec) ice-ocean stress always computed at each ocean time-step
-   !!            4.0  ! 2011-01  (A Porter)  dynamical allocation
-   !!             -   ! 2012-10  (C. Rousset)  add lim_diahsb
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                  LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   sbc_ice_lim  : sea-ice model time-stepping and update ocean sbc over ice-covered area
-   !!   lim_ctl       : alerts in case of ice model crash
-   !!   lim_prt_state : ice control print at a given grid point
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE par_ice         ! sea-ice parameters
-   USE ice             ! LIM-3: ice variables
-   USE iceini          ! LIM-3: ice initialisation
-   USE dom_ice         ! LIM-3: ice domain
-
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice   fields
-   USE sbcblk_core     ! Surface boundary condition: CORE bulk
-   USE sbcblk_clio     ! Surface boundary condition: CLIO bulk
-   USE albedo          ! ocean & ice albedo
-
-   USE phycst          ! Define parameters for the routines
-   USE eosbn2          ! equation of state
-   USE limdyn          ! Ice dynamics
-   USE limtrp          ! Ice transport
-   USE limthd          ! Ice thermodynamics
-   USE limitd_th       ! Thermodynamics on ice thickness distribution 
-   USE limitd_me       ! Mechanics on ice thickness distribution
-   USE limsbc          ! sea surface boundary condition
-   USE limdia          ! Ice diagnostics
-   USE limdiahsb       ! Ice budget diagnostics
-   USE limwri          ! Ice outputs
-   USE limrst          ! Ice restarts
-!clem@order   USE limupdate       ! update of global variables
-   USE limupdate1       ! update of global variables
-   USE limupdate2       ! update of global variables
-   USE limvar          ! Ice variables switch
-
-   USE c1d             ! 1D vertical configuration
-   USE lbclnk          ! lateral boundary condition - MPP link
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! work arrays
-   USE timing          ! Timing
-   USE iom             ! I/O manager library
-   USE in_out_manager  ! I/O manager
-   USE prtctl          ! Print control
-
-#if defined key_bdy 
-   USE bdyice_lim       ! unstructured open boundary data  (bdy_ice_lim routine)
-#endif
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC sbc_ice_lim  ! routine called by sbcmod.F90
-   
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , UCL NEMO Consortium (2011)
-   !! $Id: sbcice_lim.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE sbc_ice_lim( kt, kblk )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE sbc_ice_lim  ***
-      !!                   
-      !! ** Purpose :   update the ocean surface boundary condition via the 
-      !!                Louvain la Neuve Sea Ice Model time stepping 
-      !!
-      !! ** Method  :   ice model time stepping
-      !!              - 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
-      !!
-      !! ** Action  : - time evolution of the LIM sea-ice model
-      !!              - update all sbc variables below sea-ice:
-      !!                utau, vtau, taum, wndm, qns , qsr, emp , emps
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt      ! ocean time step
-      INTEGER, INTENT(in) ::   kblk    ! type of bulk (=3 CLIO, =4 CORE)
-      !!
-      INTEGER  ::   jl      ! dummy loop index
-      REAL(wp) ::   zcoef   ! local scalar
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalb_ice_os, zalb_ice_cs  ! albedo of the ice under overcast/clear sky
-      !!----------------------------------------------------------------------
-
-      IF( nn_timing == 1 )  CALL timing_start('sbc_ice_lim')
-
-      CALL wrk_alloc( jpi,jpj,jpl, zalb_ice_os, zalb_ice_cs )
-
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'sbc_ice_lim : update ocean surface boudary condition' 
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   via Louvain la Neuve Ice Model (LIM-3) time stepping'
-         !
-         CALL ice_init
-         !
-         IF( ln_nicep ) THEN      ! control print at a given point
-            !jiindx = 3   ;   jjindx = 51
-            !jiindx = 34   ;   jjindx = 45
-            jiindx = 117   ;   jjindx = 116
-            WRITE(numout,*) ' The debugging point is : jiindx : ',jiindx, ' jjindx : ',jjindx
-         ENDIF
-      ENDIF
-
-      !                                        !----------------------!
-      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN     !  Ice time-step only  !
-         !                                     !----------------------!
-         !                                           !  Bulk Formulea !
-         !                                           !----------------!
-         !
-         u_oce(:,:) = ssu_m(:,:)                     ! mean surface ocean current at ice velocity point
-         v_oce(:,:) = ssv_m(:,:)                     ! (C-grid dynamics :  U- & V-points as the ocean)
-         !
-         t_bo(:,:) = tfreez( sss_m ) +  rt0          ! masked sea surface freezing temperature [Kelvin]
-         !                                           ! (set to rt0 over land)
-         CALL albedo_ice( t_su, ht_i, ht_s, zalb_ice_cs, zalb_ice_os )  ! ... ice albedo
-
-         DO jl = 1, jpl
-            t_su(:,:,jl) = t_su(:,:,jl) +  rt0 * ( 1. - tmask(:,:,1) )
-         END DO
-                                                     ! Bulk formulea - provides the following fields:
-         ! utau_ice, vtau_ice : surface ice stress                     (U- & V-points)   [N/m2]
-         ! qsr_ice , qns_ice  : solar & non solar heat flux over ice   (T-point)         [W/m2]
-         ! qla_ice            : latent heat flux over ice              (T-point)         [W/m2]
-         ! dqns_ice, dqla_ice : non solar & latent heat sensistivity   (T-point)         [W/m2]
-         ! tprecip , sprecip  : total & solid precipitation            (T-point)         [Kg/m2/s]
-         ! fr1_i0  , fr2_i0   : 1sr & 2nd fraction of qsr penetration in ice             [%]
-         !
-         SELECT CASE( kblk )
-         CASE( 3 )                                       ! CLIO bulk formulation
-            CALL blk_ice_clio( t_su , zalb_ice_cs, zalb_ice_os,                           &
-               &                      utau_ice   , vtau_ice   , qns_ice   , qsr_ice   ,   &
-               &                      qla_ice    , dqns_ice   , dqla_ice  ,               &
-               &                      tprecip    , sprecip    ,                           &
-               &                      fr1_i0     , fr2_i0     , cp_ice_msh, jpl  )
-            !         
-         CASE( 4 )                                       ! CORE bulk formulation
-            CALL blk_ice_core( t_su , u_ice     , v_ice     , zalb_ice_cs,               &
-               &                      utau_ice  , vtau_ice  , qns_ice    , qsr_ice   ,   &
-               &                      qla_ice   , dqns_ice  , dqla_ice   ,               &
-               &                      tprecip   , sprecip   ,                            &
-               &                      fr1_i0    , fr2_i0    , cp_ice_msh, jpl  )
-         END SELECT
-
-         CALL iom_put( 'utau_ice', utau_ice )     ! Wind stress over ice along i-axis at I-point
-         CALL iom_put( 'vtau_ice', vtau_ice )     ! Wind stress over ice along j-axis at I-point
-
-         !                                           !----------------------!
-         !                                           ! LIM-3  time-stepping !
-         !                                           !----------------------!
-         ! 
-         numit = numit + nn_fsbc                     ! Ice model time step
-         !
-         !                                           ! Store previous ice values
-!!gm : remark   old_...   should becomes ...b  as tn versus tb  
-         old_a_i  (:,:,:)   = a_i  (:,:,:)     ! ice area
-         old_e_i  (:,:,:,:) = e_i  (:,:,:,:)   ! ice thermal energy
-         old_v_i  (:,:,:)   = v_i  (:,:,:)     ! ice volume
-         old_v_s  (:,:,:)   = v_s  (:,:,:)     ! snow volume 
-         old_e_s  (:,:,:,:) = e_s  (:,:,:,:)   ! snow thermal energy
-         old_smv_i(:,:,:)   = smv_i(:,:,:)     ! salt content
-         old_oa_i (:,:,:)   = oa_i (:,:,:)     ! areal age content
-
-         !                                           ! intialisation to zero    !!gm is it truly necessary ???
-         d_a_i_thd  (:,:,:)   = 0.e0   ;   d_a_i_trp  (:,:,:)   = 0.e0
-         d_v_i_thd  (:,:,:)   = 0.e0   ;   d_v_i_trp  (:,:,:)   = 0.e0
-         d_e_i_thd  (:,:,:,:) = 0.e0   ;   d_e_i_trp  (:,:,:,:) = 0.e0
-         d_v_s_thd  (:,:,:)   = 0.e0   ;   d_v_s_trp  (:,:,:)   = 0.e0
-         d_e_s_thd  (:,:,:,:) = 0.e0   ;   d_e_s_trp  (:,:,:,:) = 0.e0
-         d_smv_i_thd(:,:,:)   = 0.e0   ;   d_smv_i_trp(:,:,:)   = 0.e0
-         d_oa_i_thd (:,:,:)   = 0.e0   ;   d_oa_i_trp (:,:,:)   = 0.e0
-         !
-         !clem fseqv    (:,:) = 0.e0
-         !clem fsbri    (:,:) = 0.e0
-         fsalt_res(:,:) = 0.e0
-         fsalt_rpo(:,:) = 0.e0
-         fhmec    (:,:) = 0.e0
-         !clem fhbri    (:,:) = 0.e0
-         fmmec    (:,:) = 0.e0
-         fheat_res(:,:) = 0.e0
-         fheat_rpo(:,:) = 0.e0
-         focea2D  (:,:) = 0.e0
-         fsup2D   (:,:) = 0.e0
-
-         ! clem: moved from limthd.F90 
-         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
-         !
-         diag_sni_gr(:,:) = 0.e0   ;   diag_lat_gr(:,:) = 0.e0
-         diag_bot_gr(:,:) = 0.e0   ;   diag_dyn_gr(:,:) = 0.e0
-         diag_bot_me(:,:) = 0.e0   ;   diag_sur_me(:,:) = 0.e0
-         diag_res_pr(:,:) = 0.e0   ;   diag_trp_vi(:,:) = 0.e0
-         ! dynamical invariants
-         delta_i(:,:) = 0.e0       ;   divu_i(:,:) = 0.e0       ;   shear_i(:,:) = 0.e0
-         !
-                          CALL lim_rst_opn( kt )     ! Open Ice restart file
-         !
-         IF( ln_nicep )   CALL lim_prt_state( jiindx, jjindx, 1, ' - Beginning the time step - ' )   ! control print
-         !
-         IF( .NOT. lk_c1d ) THEN
-                                                     ! Ice dynamics & transport (not in 1D case)
-                          CALL lim_dyn( kt )              ! Ice dynamics    ( rheology/dynamics )
-                          CALL lim_trp( kt )              ! Ice transport   ( Advection/diffusion )
-                          !clem(done in trp wo ato_i) CALL lim_var_agg(1)             ! aggregate categories, requested
-                          CALL lim_var_glo2eqv            ! equivalent variables, requested for rafting
-         IF( ln_nicep )   CALL lim_prt_state( jiindx, jjindx,-1, ' - ice dyn & trp - ' )   ! control print
-                          CALL lim_itd_me                 ! Mechanical redistribution ! (ridging/rafting)
-                          CALL lim_var_agg( 1 ) ! clem@order
-                          CALL lim_update1  ! clem@order
-         ENDIF
-!                          !- Change old values for new values
-!clem@order
-                          old_u_ice(:,:)   = u_ice (:,:)
-                          old_v_ice(:,:)   = v_ice (:,:)
-                          old_a_i(:,:,:)   = a_i (:,:,:)
-                          old_v_s(:,:,:)   = v_s (:,:,:)
-                          old_v_i(:,:,:)   = v_i (:,:,:)
-                          old_e_s(:,:,:,:) = e_s (:,:,:,:)
-                          old_e_i(:,:,:,:) = e_i (:,:,:,:)
-                          old_oa_i(:,:,:)  = oa_i(:,:,:)
-                          old_smv_i(:,:,:) = smv_i (:,:,:)
-!clem@order
-         !                                           ! 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( kt )              ! Ice thermodynamics 
-                          zcoef = rdt_ice / 86400.e0      !  Ice natural aging
-                          oa_i(:,:,:) = oa_i(:,:,:) + a_i(:,:,:) * zcoef
-                          CALL lim_var_glo2eqv            ! this CALL is maybe not necessary (Martin)
-         IF( ln_nicep )   CALL lim_prt_state( jiindx, jjindx, 1, ' - ice thermodyn. - ' )   ! control print
-                          CALL lim_itd_th( kt )           !  Remap ice categories, lateral accretion  !
-         !
-         !                                           ! Global variables update
-                          CALL lim_var_agg( 1 )           ! requested by limupdate
-                          !clem@order CALL lim_update                 ! Global variables update
-                          CALL lim_update2  ! clem@order
-!
-#if defined key_bdy
-                          CALL bdy_ice_lim( kt )          ! clem modif: bdy ice
-#endif
-                          CALL lim_var_glo2eqv            ! equivalent variables (outputs)
-                          CALL lim_var_agg(2)             ! aggregate ice thickness categories
-         IF( ln_nicep )   CALL lim_prt_state( jiindx, jjindx, 2, ' - Final state - ' )   ! control print
-         !
-                          CALL lim_sbc_flx( kt )     ! Update surface ocean mass, heat and salt fluxes
-         !
-         IF( ln_nicep )   CALL lim_prt_state( jiindx, jjindx, 3, ' - Final state lim_sbc - ' )   ! control print
-         !
-         !                                           ! Diagnostics and outputs 
-         IF( ( MOD( kt+nn_fsbc-1, ninfo ) == 0 .OR. ntmoy == 1 ) .AND. .NOT. lk_mpp )   &
-            &             CALL lim_dia 
-        IF (ln_limdiahsb) CALL lim_diahsb
-                          CALL lim_wri( 1  )              ! Ice outputs 
-         IF( kt == nit000 )   CALL iom_close( numrir )  ! clem: close input ice restart file
-         IF( lrst_ice )   CALL lim_rst_write( kt )        ! Ice restart file 
-                          CALL lim_var_glo2eqv            ! ???
-         !
-         IF( ln_nicep )   CALL lim_ctl               ! alerts in case of model crash
-         !
-     ENDIF                                    ! End sea-ice time step only
-
-      !                                        !--------------------------!
-      !                                        !  at all ocean time step  !
-      !                                        !--------------------------!
-      !                                               
-      !                                              ! Update surface ocean stresses (only in ice-dynamic case)
-      !                                                   ! otherwise the atm.-ocean stresses are used everywhere
-      IF( ln_limdyn )     CALL lim_sbc_tau( kt, ub(:,:,1), vb(:,:,1) )  ! using before instantaneous surf. currents
-      
-!!gm   remark, the ocean-ice stress is not saved in ice diag call above .....  find a solution!!!
-      !
-      CALL wrk_dealloc( jpi,jpj,jpl, zalb_ice_os, zalb_ice_cs )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('sbc_ice_lim')
-      !
-   END SUBROUTINE sbc_ice_lim
-
-
-   SUBROUTINE lim_ctl
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_ctl *** 
-      !!                 
-      !! ** Purpose :   Alerts in case of model crash
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk,  jl   ! dummy loop indices
-      INTEGER  ::   inb_altests       ! number of alert tests (max 20)
-      INTEGER  ::   ialert_id         ! number of the current alert
-      REAL(wp) ::   ztmelts           ! ice layer melting point
-      CHARACTER (len=30), DIMENSION(20)      ::   cl_alname   ! name of alert
-      INTEGER           , DIMENSION(20)      ::   inb_alp     ! number of alerts positive
-      !!-------------------------------------------------------------------
-
-      inb_altests = 10
-      inb_alp(:)  = 0
-
-      ! Alert if incompatible volume and concentration
-      ialert_id = 2 ! reference number of this alert
-      cl_alname(ialert_id) = ' Incompat vol and con         '    ! name of the alert
-
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF(  v_i(ji,jj,jl) /= 0.e0   .AND.   a_i(ji,jj,jl) == 0.e0   ) THEN
-                  WRITE(numout,*) ' ALERTE 2 :   Incompatible volume and concentration '
-                  WRITE(numout,*) ' at_i     ', at_i(ji,jj)
-                  WRITE(numout,*) ' Point - category', ji, jj, jl
-                  WRITE(numout,*) ' a_i *** a_i_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)
-                  inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      ! Alerte if very thick ice
-      ialert_id = 3 ! reference number of this alert
-      cl_alname(ialert_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
-               CALL lim_prt_state( ji, jj, 2, ' ALERTE 3 :   Very thick ice ' )
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-            ENDIF
-         END DO
-      END DO
-
-      ! Alert if very fast ice
-      ialert_id = 4 ! reference number of this alert
-      cl_alname(ialert_id) = ' Very fast ice               ' ! name of the alert
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF(   MAX( ABS( u_ice(ji,jj) ), ABS( v_ice(ji,jj) ) ) .GT. 0.5  .AND.  &
-               &  at_i(ji,jj) .GT. 0.e0   ) THEN
-               CALL lim_prt_state( ji, jj, 1, ' ALERTE 4 :   Very fast ice ' )
-               WRITE(numout,*) ' ice strength             : ', strength(ji,jj)
-               WRITE(numout,*) ' oceanic stress utau      : ', utau(ji,jj) 
-               WRITE(numout,*) ' oceanic stress vtau      : ', vtau(ji,jj)
-               WRITE(numout,*) ' sea-ice stress utau_ice  : ', utau_ice(ji,jj) 
-               WRITE(numout,*) ' sea-ice stress vtau_ice  : ', vtau_ice(ji,jj)
-               WRITE(numout,*) ' oceanic speed u          : ', u_oce(ji,jj)
-               WRITE(numout,*) ' oceanic speed v          : ', v_oce(ji,jj)
-               WRITE(numout,*) ' sst                      : ', sst_m(ji,jj)
-               WRITE(numout,*) ' sss                      : ', sss_m(ji,jj)
-               WRITE(numout,*) 
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-            ENDIF
-         END DO
-      END DO
-
-      ! Alert if there is ice on continents
-      ialert_id = 6 ! reference number of this alert
-      cl_alname(ialert_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.e0   ) THEN 
-               CALL lim_prt_state( ji, jj, 1, ' ALERTE 6 :   Ice on continents ' )
-               WRITE(numout,*) ' masks s, u, v        : ', tms(ji,jj), tmu(ji,jj), tmv(ji,jj) 
-               WRITE(numout,*) ' sst                  : ', sst_m(ji,jj)
-               WRITE(numout,*) ' sss                  : ', sss_m(ji,jj)
-               WRITE(numout,*) ' at_i(ji,jj)          : ', at_i(ji,jj)
-               WRITE(numout,*) ' v_ice(ji,jj)         : ', v_ice(ji,jj)
-               WRITE(numout,*) ' v_ice(ji,jj-1)       : ', v_ice(ji,jj-1)
-               WRITE(numout,*) ' u_ice(ji-1,jj)       : ', u_ice(ji-1,jj)
-               WRITE(numout,*) ' u_ice(ji,jj)         : ', v_ice(ji,jj)
-               !
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-            ENDIF
-         END DO
-      END DO
-
-!
-!     ! Alert if very fresh ice
-      ialert_id = 7 ! reference number of this alert
-      cl_alname(ialert_id) = ' Very fresh ice               ' ! name of the alert
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-!!gm  test twice sm_i ...  ????  bug?
-               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.e0 ) ) THEN
-!                 CALL lim_prt_state(ji,jj,1, ' ALERTE 7 :   Very fresh ice ' )
-!                 WRITE(numout,*) ' sst                  : ', sst_m(ji,jj)
-!                 WRITE(numout,*) ' sss                  : ', sss_m(ji,jj)
-!                 WRITE(numout,*) ' s_i_newice           : ', s_i_newice(ji,jj,1:jpl)
-!                 WRITE(numout,*) 
-                  inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-               ENDIF
-            END DO
-         END DO
-      END DO
-!
-
-!     ! Alert if too old ice
-      ialert_id = 9 ! reference number of this alert
-      cl_alname(ialert_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
-                  CALL lim_prt_state( ji, jj, 1, ' ALERTE 9 :   Wrong ice age ')
-                  inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-               ENDIF
-            END DO
-         END DO
-      END DO
- 
-      ! Alert on salt flux
-      ialert_id = 5 ! reference number of this alert
-      cl_alname(ialert_id) = ' High salt flux               ' ! name of the alert
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( ABS( emps(ji,jj) ) .GT. 1.0e-2 ) THEN
-               CALL lim_prt_state( ji, jj, 3, ' ALERTE 5 :   High salt flux ' )
-               DO jl = 1, jpl
-                  WRITE(numout,*) ' Category no: ', jl
-                  WRITE(numout,*) ' a_i        : ', a_i      (ji,jj,jl) , ' 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
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-            ENDIF
-         END DO
-      END DO
-
-      ! Alert if qns very big
-      ialert_id = 8 ! reference number of this alert
-      cl_alname(ialert_id) = ' fnsolar very big             ' ! name of the alert
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF(   ABS( qns(ji,jj) ) .GT. 1500.0   .AND.  ( at_i(ji,jj) .GT. 0.0 ) )  THEN
-               !
-               WRITE(numout,*) ' ALERTE 8 :   Very high non-solar heat flux'
-               WRITE(numout,*) ' ji, jj    : ', ji, jj
-               WRITE(numout,*) ' qns       : ', qns(ji,jj)
-               WRITE(numout,*) ' sst       : ', sst_m(ji,jj)
-               WRITE(numout,*) ' sss       : ', sss_m(ji,jj)
-               WRITE(numout,*) ' qcmif     : ', qcmif(ji,jj)
-               WRITE(numout,*) ' qldif     : ', qldif(ji,jj)
-               WRITE(numout,*) ' qcmif     : ', qcmif(ji,jj) / rdt_ice
-               WRITE(numout,*) ' qldif     : ', qldif(ji,jj) / rdt_ice
-               WRITE(numout,*) ' qfvbq     : ', qfvbq(ji,jj)
-               WRITE(numout,*) ' qdtcn     : ', qdtcn(ji,jj)
-               WRITE(numout,*) ' qfvbq / dt: ', qfvbq(ji,jj) / rdt_ice
-               WRITE(numout,*) ' qdtcn / dt: ', qdtcn(ji,jj) / rdt_ice
-               WRITE(numout,*) ' fdtcn     : ', fdtcn(ji,jj) 
-               WRITE(numout,*) ' fhmec     : ', fhmec(ji,jj) 
-               WRITE(numout,*) ' fheat_rpo : ', fheat_rpo(ji,jj) 
-               WRITE(numout,*) ' fheat_res : ', fheat_res(ji,jj) 
-               WRITE(numout,*) ' fhbri     : ', fhbri(ji,jj) 
-               !
-               CALL lim_prt_state( ji, jj, 2, '   ')
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-               !
-            ENDIF
-         END DO
-      END DO
-      !+++++
- 
-      ! Alert if very warm ice
-      ialert_id = 10 ! reference number of this alert
-      cl_alname(ialert_id) = ' Very warm ice                ' ! name of the alert
-      inb_alp(ialert_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.e-6   &
-                     &                               .AND.  a_i(ji,jj,jl) .GT. 0.e0    ) THEN
-                     WRITE(numout,*) ' ALERTE 10 :   Very warm ice'
-                     WRITE(numout,*) ' ji, jj, jk, jl : ', ji, jj, jk, jl
-                     WRITE(numout,*) ' t_i : ', t_i(ji,jj,jk,jl)
-                     WRITE(numout,*) ' e_i : ', e_i(ji,jj,jk,jl)
-                     WRITE(numout,*) ' s_i : ', s_i(ji,jj,jk,jl)
-                     WRITE(numout,*) ' ztmelts : ', ztmelts
-                     inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-                  ENDIF
-               END DO
-            END DO
-         END DO
-      END DO
-
-      ialert_id = 1                                 ! reference number of this alert
-      cl_alname(ialert_id) = ' NO alerte 1      '   ! name of the alert
-      WRITE(numout,*)
-      WRITE(numout,*) ' All alerts at the end of ice model '
-      DO ialert_id = 1, inb_altests
-         WRITE(numout,*) ialert_id, cl_alname(ialert_id)//' : ', inb_alp(ialert_id), ' times ! '
-      END DO
-      !
-   END SUBROUTINE lim_ctl
- 
-   
-   SUBROUTINE lim_prt_state( ki, kj, kn, cd1 )
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_prt_state *** 
-      !!                 
-      !! ** Purpose :   Writes global ice state on the (i,j) point 
-      !!                in ocean.ouput 
-      !!                3 possibilities exist 
-      !!                n = 1/-1 -> simple ice state (plus Mechanical Check if -1)
-      !!                n = 2    -> exhaustive state
-      !!                n = 3    -> ice/ocean salt fluxes
-      !!
-      !! ** input   :   point coordinates (i,j) 
-      !!                n : number of the option
-      !!-------------------------------------------------------------------
-      INTEGER         , INTENT(in) ::   ki, kj, kn    ! ocean gridpoint indices
-      CHARACTER(len=*), INTENT(in) ::   cd1           !
-      !!
-      INTEGER :: jl
-      !!-------------------------------------------------------------------
-
-      WRITE(numout,*) cd1             ! print title
-
-      !----------------
-      !  Simple state
-      !----------------
-
-      IF ( kn == 1 .OR. kn == -1 ) THEN
-         WRITE(numout,*) ' lim_prt_state - Point : ',ki,kj
-         WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
-         WRITE(numout,*) ' Simple state '
-         WRITE(numout,*) ' masks s,u,v   : ', tms(ki,kj), tmu(ki,kj), tmv(ki,kj)
-         WRITE(numout,*) ' lat - long    : ', gphit(ki,kj), glamt(ki,kj)
-         WRITE(numout,*) ' Time step     : ', numit
-         WRITE(numout,*) ' - Ice drift   '
-         WRITE(numout,*) '   ~~~~~~~~~~~ '
-         WRITE(numout,*) ' u_ice(i-1,j)  : ', u_ice(ki-1,kj)
-         WRITE(numout,*) ' u_ice(i  ,j)  : ', u_ice(ki,kj)
-         WRITE(numout,*) ' v_ice(i  ,j-1): ', v_ice(ki,kj-1)
-         WRITE(numout,*) ' v_ice(i  ,j)  : ', v_ice(ki,kj)
-         WRITE(numout,*) ' strength      : ', strength(ki,kj)
-         WRITE(numout,*)
-         WRITE(numout,*) ' - Cell values '
-         WRITE(numout,*) '   ~~~~~~~~~~~ '
-         WRITE(numout,*) ' cell area     : ', area(ki,kj)
-         WRITE(numout,*) ' at_i          : ', at_i(ki,kj)       
-         WRITE(numout,*) ' vt_i          : ', vt_i(ki,kj)       
-         WRITE(numout,*) ' vt_s          : ', vt_s(ki,kj)       
-         DO jl = 1, jpl
-            WRITE(numout,*) ' - Category (', jl,')'
-            WRITE(numout,*) ' a_i           : ', a_i(ki,kj,jl)
-            WRITE(numout,*) ' ht_i          : ', ht_i(ki,kj,jl)
-            WRITE(numout,*) ' ht_s          : ', ht_s(ki,kj,jl)
-            WRITE(numout,*) ' v_i           : ', v_i(ki,kj,jl)
-            WRITE(numout,*) ' v_s           : ', v_s(ki,kj,jl)
-            WRITE(numout,*) ' e_s           : ', e_s(ki,kj,1,jl)/1.0e9
-            WRITE(numout,*) ' e_i           : ', e_i(ki,kj,1:nlay_i,jl)/1.0e9
-            WRITE(numout,*) ' t_su          : ', t_su(ki,kj,jl)
-            WRITE(numout,*) ' t_snow        : ', t_s(ki,kj,1,jl)
-            WRITE(numout,*) ' t_i           : ', t_i(ki,kj,1:nlay_i,jl)
-            WRITE(numout,*) ' sm_i          : ', sm_i(ki,kj,jl)
-            WRITE(numout,*) ' smv_i         : ', smv_i(ki,kj,jl)
-            WRITE(numout,*)
-            WRITE(numout,*) ' Pathological case : ', patho_case(ki,kj,jl)
-         END DO
-      ENDIF
-      IF( kn == -1 ) THEN
-         WRITE(numout,*) ' Mechanical Check ************** '
-         WRITE(numout,*) ' Check what means ice divergence '
-         WRITE(numout,*) ' Total ice concentration ', at_i (ki,kj)
-         WRITE(numout,*) ' Total lead fraction     ', ato_i(ki,kj)
-         WRITE(numout,*) ' Sum of both             ', ato_i(ki,kj) + at_i(ki,kj)
-         WRITE(numout,*) ' Sum of both minus 1     ', ato_i(ki,kj) + at_i(ki,kj) - 1.00
-      ENDIF
-
-
-      !--------------------
-      !  Exhaustive state
-      !--------------------
-
-      IF ( kn .EQ. 2 ) THEN
-         WRITE(numout,*) ' lim_prt_state - Point : ',ki,kj
-         WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
-         WRITE(numout,*) ' Exhaustive state '
-         WRITE(numout,*) ' lat - long ', gphit(ki,kj), glamt(ki,kj)
-         WRITE(numout,*) ' Time step ', numit
-         WRITE(numout,*) 
-         WRITE(numout,*) ' - Cell values '
-         WRITE(numout,*) '   ~~~~~~~~~~~ '
-         WRITE(numout,*) ' cell area     : ', area(ki,kj)
-         WRITE(numout,*) ' at_i          : ', at_i(ki,kj)       
-         WRITE(numout,*) ' vt_i          : ', vt_i(ki,kj)       
-         WRITE(numout,*) ' vt_s          : ', vt_s(ki,kj)       
-         WRITE(numout,*) ' u_ice(i-1,j)  : ', u_ice(ki-1,kj)
-         WRITE(numout,*) ' u_ice(i  ,j)  : ', u_ice(ki,kj)
-         WRITE(numout,*) ' v_ice(i  ,j-1): ', v_ice(ki,kj-1)
-         WRITE(numout,*) ' v_ice(i  ,j)  : ', v_ice(ki,kj)
-         WRITE(numout,*) ' strength      : ', strength(ki,kj)
-         WRITE(numout,*) ' d_u_ice_dyn   : ', d_u_ice_dyn(ki,kj), ' d_v_ice_dyn   : ', d_v_ice_dyn(ki,kj)
-         WRITE(numout,*) ' old_u_ice     : ', old_u_ice(ki,kj)  , ' old_v_ice     : ', old_v_ice(ki,kj)  
-         WRITE(numout,*)
-
-         DO jl = 1, jpl
-              WRITE(numout,*) ' - Category (',jl,')'
-              WRITE(numout,*) '   ~~~~~~~~         ' 
-              WRITE(numout,*) ' ht_i       : ', ht_i(ki,kj,jl)             , ' ht_s       : ', ht_s(ki,kj,jl)
-              WRITE(numout,*) ' t_i        : ', t_i(ki,kj,1:nlay_i,jl)
-              WRITE(numout,*) ' t_su       : ', t_su(ki,kj,jl)             , ' t_s        : ', t_s(ki,kj,1,jl)
-              WRITE(numout,*) ' sm_i       : ', sm_i(ki,kj,jl)             , ' o_i        : ', o_i(ki,kj,jl)
-              WRITE(numout,*) ' a_i        : ', a_i(ki,kj,jl)              , ' old_a_i    : ', old_a_i(ki,kj,jl)   
-              WRITE(numout,*) ' d_a_i_trp  : ', d_a_i_trp(ki,kj,jl)        , ' d_a_i_thd  : ', d_a_i_thd(ki,kj,jl) 
-              WRITE(numout,*) ' v_i        : ', v_i(ki,kj,jl)              , ' old_v_i    : ', old_v_i(ki,kj,jl)   
-              WRITE(numout,*) ' d_v_i_trp  : ', d_v_i_trp(ki,kj,jl)        , ' d_v_i_thd  : ', d_v_i_thd(ki,kj,jl) 
-              WRITE(numout,*) ' v_s        : ', v_s(ki,kj,jl)              , ' old_v_s    : ', old_v_s(ki,kj,jl)  
-              WRITE(numout,*) ' d_v_s_trp  : ', d_v_s_trp(ki,kj,jl)        , ' d_v_s_thd  : ', d_v_s_thd(ki,kj,jl)
-              WRITE(numout,*) ' e_i1       : ', e_i(ki,kj,1,jl)/1.0e9      , ' old_ei1    : ', old_e_i(ki,kj,1,jl)/1.0e9 
-              WRITE(numout,*) ' de_i1_trp  : ', d_e_i_trp(ki,kj,1,jl)/1.0e9, ' de_i1_thd  : ', d_e_i_thd(ki,kj,1,jl)/1.0e9
-              WRITE(numout,*) ' e_i2       : ', e_i(ki,kj,2,jl)/1.0e9      , ' old_ei2    : ', old_e_i(ki,kj,2,jl)/1.0e9  
-              WRITE(numout,*) ' de_i2_trp  : ', d_e_i_trp(ki,kj,2,jl)/1.0e9, ' de_i2_thd  : ', d_e_i_thd(ki,kj,2,jl)/1.0e9
-              WRITE(numout,*) ' e_snow     : ', e_s(ki,kj,1,jl)            , ' old_e_snow : ', old_e_s(ki,kj,1,jl) 
-              WRITE(numout,*) ' d_e_s_trp  : ', d_e_s_trp(ki,kj,1,jl)      , ' d_e_s_thd  : ', d_e_s_thd(ki,kj,1,jl)
-              WRITE(numout,*) ' smv_i      : ', smv_i(ki,kj,jl)            , ' old_smv_i  : ', old_smv_i(ki,kj,jl)   
-              WRITE(numout,*) ' d_smv_i_trp: ', d_smv_i_trp(ki,kj,jl)      , ' d_smv_i_thd: ', d_smv_i_thd(ki,kj,jl) 
-              WRITE(numout,*) ' oa_i       : ', oa_i(ki,kj,jl)             , ' old_oa_i   : ', old_oa_i(ki,kj,jl)
-              WRITE(numout,*) ' d_oa_i_trp : ', d_oa_i_trp(ki,kj,jl)       , ' d_oa_i_thd : ', d_oa_i_thd(ki,kj,jl)
-              WRITE(numout,*) ' Path. case : ', patho_case(ki,kj,jl)
-        END DO !jl
-
-        WRITE(numout,*)
-        WRITE(numout,*) ' - Heat / FW fluxes '
-        WRITE(numout,*) '   ~~~~~~~~~~~~~~~~ '
-!       WRITE(numout,*) ' fsbri      : ', fsbri(ki,kj)
-!       WRITE(numout,*) ' fseqv      : ', fseqv(ki,kj)
-!       WRITE(numout,*) ' fsalt_res  : ', fsalt_res(ki,kj)
-        WRITE(numout,*) ' fmmec      : ', fmmec(ki,kj)
-        WRITE(numout,*) ' fhmec      : ', fhmec(ki,kj)
-        WRITE(numout,*) ' fhbri      : ', fhbri(ki,kj)
-        WRITE(numout,*) ' fheat_rpo  : ', fheat_rpo(ki,kj)
-        WRITE(numout,*) 
-        WRITE(numout,*) ' sst        : ', sst_m(ki,kj)  
-        WRITE(numout,*) ' sss        : ', sss_m(ki,kj)  
-        WRITE(numout,*) 
-        WRITE(numout,*) ' - Stresses '
-        WRITE(numout,*) '   ~~~~~~~~ '
-        WRITE(numout,*) ' utau_ice   : ', utau_ice(ki,kj) 
-        WRITE(numout,*) ' vtau_ice   : ', vtau_ice(ki,kj)
-        WRITE(numout,*) ' utau       : ', utau(ki,kj) 
-        WRITE(numout,*) ' vtau       : ', vtau(ki,kj)
-        WRITE(numout,*) ' oc. vel. u : ', u_oce(ki,kj)
-        WRITE(numout,*) ' oc. vel. v : ', v_oce(ki,kj)
-     ENDIF
-
-     !---------------------
-     ! Salt / heat fluxes
-     !---------------------
-
-     IF ( kn .EQ. 3 ) THEN
-        WRITE(numout,*) ' lim_prt_state - Point : ',ki,kj
-        WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
-        WRITE(numout,*) ' - Salt / Heat Fluxes '
-        WRITE(numout,*) '   ~~~~~~~~~~~~~~~~ '
-        WRITE(numout,*) ' lat - long ', gphit(ki,kj), glamt(ki,kj)
-        WRITE(numout,*) ' Time step ', numit
-        WRITE(numout,*)
-        WRITE(numout,*) ' - Heat fluxes at bottom interface ***'
-        WRITE(numout,*) ' qsr        : ', qsr(ki,kj)
-        WRITE(numout,*) ' qns        : ', qns(ki,kj)
-        WRITE(numout,*)
-        WRITE(numout,*) ' - Salt fluxes at bottom interface ***'
-        WRITE(numout,*) ' emps       : ', emps(ki,kj)
-        WRITE(numout,*) ' emp        : ', emp(ki,kj)
-        WRITE(numout,*) ' fsbri      : ', fsbri(ki,kj)
-        WRITE(numout,*) ' fseqv      : ', fseqv(ki,kj)
-        WRITE(numout,*) ' fsalt_res  : ', fsalt_res(ki,kj)
-        WRITE(numout,*) ' fsalt_rpo  : ', fsalt_rpo(ki,kj)
-        WRITE(numout,*) ' - Heat fluxes at bottom interface ***'
-        WRITE(numout,*) ' fheat_res  : ', fheat_res(ki,kj)
-        WRITE(numout,*)
-        WRITE(numout,*) ' - Momentum fluxes '
-        WRITE(numout,*) ' utau      : ', utau(ki,kj) 
-        WRITE(numout,*) ' vtau      : ', vtau(ki,kj)
-      ENDIF
-      WRITE(numout,*) ' '
-      !
-   END SUBROUTINE lim_prt_state
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option           Dummy module      NO LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE sbc_ice_lim ( kt, kblk )     ! Dummy routine
-      WRITE(*,*) 'sbc_ice_lim: You should not have seen this print! error?', kt, kblk
-   END SUBROUTINE sbc_ice_lim
-#endif
-
-   !!======================================================================
-END MODULE sbcice_lim
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/sbcmod.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/sbcmod.F90	(revision 3937)
+++ 	(revision )
@@ -1,389 +1,0 @@
-MODULE sbcmod
-   !!======================================================================
-   !!                       ***  MODULE  sbcmod  ***
-   !! Surface module :  provide to the ocean its surface boundary condition
-   !!======================================================================
-   !! History :  3.0  ! 2006-07  (G. Madec)  Original code
-   !!            3.1  ! 2008-08  (S. Masson, A. Caubel, E. Maisonnave, G. Madec) coupled interface
-   !!            3.3  ! 2010-04  (M. Leclair, G. Madec)  Forcing averaged over 2 time steps
-   !!            3.3  ! 2010-10  (S. Masson)  add diurnal cycle
-   !!            3.3  ! 2010-09  (D. Storkey) add ice boundary conditions (BDY)
-   !!             -   ! 2010-11  (G. Madec) ice-ocean stress always computed at each ocean time-step
-   !!             -   ! 2010-10  (J. Chanut, C. Bricaud, G. Madec)  add the surface pressure forcing
-   !!            3.4  ! 2011-11  (C. Harris) CICE added as an option
-   !!             -   ! 2012-01  (C. Rousset) add ice boundary conditions for LIM3
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   sbc_init       : read namsbc namelist
-   !!   sbc            : surface ocean momentum, heat and freshwater boundary conditions
-   !!----------------------------------------------------------------------
-   USE oce              ! ocean dynamics and tracers
-   USE dom_oce          ! ocean space and time domain
-   USE phycst           ! physical constants
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE sbc_ice          ! Surface boundary condition: ice fields
-   USE sbcdcy           ! surface boundary condition: diurnal cycle
-   USE sbcssm           ! surface boundary condition: sea-surface mean variables
-   USE sbcapr           ! surface boundary condition: atmospheric pressure
-   USE sbcana           ! surface boundary condition: analytical formulation
-   USE sbcflx           ! surface boundary condition: flux formulation
-   USE sbcblk_clio      ! surface boundary condition: bulk formulation : CLIO
-   USE sbcblk_core      ! surface boundary condition: bulk formulation : CORE
-   USE sbcblk_mfs       ! surface boundary condition: bulk formulation : MFS
-   USE sbcice_if        ! surface boundary condition: ice-if sea-ice model
-   USE sbcice_lim       ! surface boundary condition: LIM 3.0 sea-ice model
-   USE sbcice_lim_2     ! surface boundary condition: LIM 2.0 sea-ice model
-   USE sbcice_cice      ! surface boundary condition: CICE    sea-ice model
-   USE sbccpl           ! surface boundary condition: coupled florulation
-   USE cpl_oasis3, ONLY:lk_cpl      ! are we in coupled mode?
-   USE sbcssr           ! surface boundary condition: sea surface restoring
-   USE sbcrnf           ! surface boundary condition: runoffs
-   USE sbcfwb           ! surface boundary condition: freshwater budget
-   USE closea           ! closed sea
-   USE bdy_par          ! for lk_bdy
-   USE bdyice_lim       ! unstructured open boundary data  (bdy_ice_lim routine)
-
-   USE prtctl           ! Print control                    (prt_ctl routine)
-   USE restart          ! ocean restart
-   USE iom              ! IOM library
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE timing           ! Timing
-   USE sbcwave          ! Wave module
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   sbc        ! routine called by step.F90
-   PUBLIC   sbc_init   ! routine called by opa.F90
-   
-   INTEGER ::   nsbc   ! type of surface boundary condition (deduced from namsbc informations)
-      
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO-consortium (2011) 
-   !! $Id: sbcmod.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE sbc_init
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE sbc_init ***
-      !!
-      !! ** Purpose :   Initialisation of the ocean surface boundary computation
-      !!
-      !! ** Method  :   Read the namsbc namelist and set derived parameters
-      !!
-      !! ** Action  : - read namsbc parameters
-      !!              - nsbc: type of sbc
-      !!----------------------------------------------------------------------
-      INTEGER ::   icpt   ! local integer
-      !!
-      NAMELIST/namsbc/ nn_fsbc   , ln_ana , ln_flx  , ln_blk_clio, ln_blk_core, ln_cpl,   &
-         &             ln_blk_mfs, ln_apr_dyn, nn_ice , ln_dm2dc, ln_rnf, ln_ssr     , nn_fwb, ln_cdgw
-      !!----------------------------------------------------------------------
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'sbc_init : surface boundary condition setting'
-         WRITE(numout,*) '~~~~~~~~ '
-      ENDIF
-
-      REWIND( numnam )           ! Read Namelist namsbc
-      READ  ( numnam, namsbc )
-
-      !                          ! overwrite namelist parameter using CPP key information
-      !IF( Agrif_Root() ) THEN                ! AGRIF zoom
-      !  IF( lk_lim2 )   nn_ice      = 2
-      !  IF( lk_lim3 )   nn_ice      = 3
-      !  IF( lk_cice )   nn_ice      = 4
-      !ENDIF
-      IF( cp_cfg == 'gyre' ) THEN            ! GYRE configuration
-          ln_ana      = .TRUE.   
-          nn_ice      =   0
-      ENDIF
-      
-      IF(lwp) THEN               ! Control print
-         WRITE(numout,*) '        Namelist namsbc (partly overwritten with CPP key setting)'
-         WRITE(numout,*) '           frequency update of sbc (and ice)             nn_fsbc     = ', nn_fsbc
-         WRITE(numout,*) '           Type of sbc : '
-         WRITE(numout,*) '              analytical formulation                     ln_ana      = ', ln_ana
-         WRITE(numout,*) '              flux       formulation                     ln_flx      = ', ln_flx
-         WRITE(numout,*) '              CLIO bulk  formulation                     ln_blk_clio = ', ln_blk_clio
-         WRITE(numout,*) '              CORE bulk  formulation                     ln_blk_core = ', ln_blk_core
-         WRITE(numout,*) '              MFS  bulk  formulation                     ln_blk_mfs  = ', ln_blk_mfs
-         WRITE(numout,*) '              coupled    formulation (T if key_sbc_cpl)  ln_cpl      = ', ln_cpl
-         WRITE(numout,*) '           Misc. options of sbc : '
-         WRITE(numout,*) '              Patm gradient added in ocean & ice Eqs.    ln_apr_dyn  = ', ln_apr_dyn
-         WRITE(numout,*) '              ice management in the sbc (=0/1/2/3)       nn_ice      = ', nn_ice 
-         WRITE(numout,*) '              daily mean to diurnal cycle qsr            ln_dm2dc    = ', ln_dm2dc 
-         WRITE(numout,*) '              runoff / runoff mouths                     ln_rnf      = ', ln_rnf
-         WRITE(numout,*) '              Sea Surface Restoring on SST and/or SSS    ln_ssr      = ', ln_ssr
-         WRITE(numout,*) '              FreshWater Budget control  (=0/1/2)        nn_fwb      = ', nn_fwb
-         WRITE(numout,*) '              closed sea (=0/1) (set in namdom)          nn_closea   = ', nn_closea
-      ENDIF
-
-      !                              ! allocate sbc arrays
-      IF( sbc_oce_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sbc_init : unable to allocate sbc_oce arrays' )
-
-      !                          ! Checks:
-      IF( .NOT. ln_rnf ) THEN                      ! no specific treatment in vicinity of river mouths 
-         ln_rnf_mouth  = .false.                      
-         IF( sbc_rnf_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sbc_init : unable to allocate sbc_rnf arrays' )
-         nkrnf         = 0
-         rnf     (:,:) = 0.e0
-         rnfmsk  (:,:) = 0.e0
-         rnfmsk_z(:)   = 0.e0
-      ENDIF
-      IF( nn_ice == 0  )   fr_i(:,:) = 0.e0        ! no ice in the domain, ice fraction is always zero
-
-      !                                            ! restartability   
-      IF( MOD( nitend - nit000 + 1, nn_fsbc) /= 0 .OR.   &
-          MOD( nstock             , nn_fsbc) /= 0 ) THEN 
-         WRITE(ctmp1,*) 'experiment length (', nitend - nit000 + 1, ') or nstock (', nstock,   &
-            &           ' is NOT a multiple of nn_fsbc (', nn_fsbc, ')'
-         CALL ctl_stop( ctmp1, 'Impossible to properly do model restart' )
-      ENDIF
-      !
-      IF( MOD( rday, REAL(nn_fsbc, wp) * rdt ) /= 0 )   &
-         &  CALL ctl_warn( 'nn_fsbc is NOT a multiple of the number of time steps in a day' )
-      !
-      IF( ( nn_ice == 2 .OR. nn_ice ==3 ) .AND. .NOT.( ln_blk_clio .OR. ln_blk_core .OR. lk_cpl ) )   &
-         &   CALL ctl_stop( 'LIM sea-ice model requires a bulk formulation or coupled configuration' )
-      IF( nn_ice == 4 .AND. .NOT.( ln_blk_core .OR. lk_cpl ) )   &
-         &   CALL ctl_stop( 'CICE sea-ice model requires ln_blk_core or lk_cpl' )
-      IF( nn_ice == 4 .AND. ( .NOT. ( cp_cfg == 'orca' ) .OR. lk_agrif ) )   &
-         &   CALL ctl_stop( 'CICE sea-ice model currently only available in a global ORCA configuration without AGRIF' )
-      
-      IF( ln_dm2dc )   nday_qsr = -1   ! initialisation flag
-
-      IF( ln_dm2dc .AND. .NOT.( ln_flx .OR. ln_blk_core ) )   &
-         &   CALL ctl_stop( 'diurnal cycle into qsr field from daily values requires a flux or core-bulk formulation' )
-      
-      IF( ln_dm2dc .AND. ( ( NINT(rday) / ( nn_fsbc * NINT(rdt) ) )  < 8 ) )   &
-         &   CALL ctl_warn( 'diurnal cycle for qsr: the sampling of the diurnal cycle is too small...' )
-
-       !drag coefficient read from wave model definable only with mfs bulk formulae and core 
-       IF(ln_cdgw .AND. .NOT.(ln_blk_mfs .OR. ln_blk_core) )              &
-          &   CALL ctl_stop( 'drag coefficient read from wave model definable only with mfs bulk formulae and core')
-      
-      !                          ! Choice of the Surface Boudary Condition (set nsbc)
-      icpt = 0
-      IF( ln_ana          ) THEN   ;   nsbc =  1   ; icpt = icpt + 1   ;   ENDIF       ! analytical      formulation
-      IF( ln_flx          ) THEN   ;   nsbc =  2   ; icpt = icpt + 1   ;   ENDIF       ! flux            formulation
-      IF( ln_blk_clio     ) THEN   ;   nsbc =  3   ; icpt = icpt + 1   ;   ENDIF       ! CLIO bulk       formulation
-      IF( ln_blk_core     ) THEN   ;   nsbc =  4   ; icpt = icpt + 1   ;   ENDIF       ! CORE bulk       formulation
-      IF( ln_blk_mfs      ) THEN   ;   nsbc =  6   ; icpt = icpt + 1   ;   ENDIF       ! MFS  bulk       formulation
-      IF( ln_cpl          ) THEN   ;   nsbc =  5   ; icpt = icpt + 1   ;   ENDIF       ! Coupled         formulation
-      IF( cp_cfg == 'gyre') THEN   ;   nsbc =  0                       ;   ENDIF       ! GYRE analytical formulation
-      IF( lk_esopa        )            nsbc = -1                                       ! esopa test, ALL formulations
-      !
-      IF( icpt /= 1 .AND. .NOT.lk_esopa ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) '           E R R O R in setting the sbc, one and only one namelist/CPP key option '
-         WRITE(numout,*) '                     must be choosen. You choose ', icpt, ' option(s)'
-         WRITE(numout,*) '                     We stop'
-         nstop = nstop + 1
-      ENDIF
-      IF(lwp) THEN
-         WRITE(numout,*)
-         IF( nsbc == -1 )   WRITE(numout,*) '              ESOPA test All surface boundary conditions'
-         IF( nsbc ==  0 )   WRITE(numout,*) '              GYRE analytical formulation'
-         IF( nsbc ==  1 )   WRITE(numout,*) '              analytical formulation'
-         IF( nsbc ==  2 )   WRITE(numout,*) '              flux formulation'
-         IF( nsbc ==  3 )   WRITE(numout,*) '              CLIO bulk formulation'
-         IF( nsbc ==  4 )   WRITE(numout,*) '              CORE bulk formulation'
-         IF( nsbc ==  5 )   WRITE(numout,*) '              coupled formulation'
-         IF( nsbc ==  6 )   WRITE(numout,*) '              MFS Bulk formulation'
-      ENDIF
-
-      IF( nn_ice == 4 )   CALL cice_sbc_init (nsbc)
-      !
-   END SUBROUTINE sbc_init
-
-
-   SUBROUTINE sbc( kt )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE sbc  ***
-      !!              
-      !! ** Purpose :   provide at each time-step the ocean surface boundary
-      !!                condition (momentum, heat and freshwater fluxes)
-      !!
-      !! ** Method  :   blah blah  to be written ????????? 
-      !!                CAUTION : never mask the surface stress field (tke sbc)
-      !!
-      !! ** Action  : - set the ocean surface boundary condition at before and now 
-      !!                time step, i.e.  
-      !!                utau_b, vtau_b, qns_b, qsr_b, emp_n, emps_b, qrp_b, erp_b
-      !!                utau  , vtau  , qns  , qsr  , emp  , emps  , qrp  , erp
-      !!              - updte the ice fraction : fr_i
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt       ! ocean time step
-      !!---------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('sbc')
-      !
-      !                                            ! ---------------------------------------- !
-      IF( kt /= nit000 ) THEN                      !          Swap of forcing fields          !
-         !                                         ! ---------------------------------------- !
-         utau_b(:,:) = utau(:,:)                         ! Swap the ocean forcing fields
-         vtau_b(:,:) = vtau(:,:)                         ! (except at nit000 where before fields
-         qns_b (:,:) = qns (:,:)                         !  are set at the end of the routine)
-         ! The 3D heat content due to qsr forcing is treated in traqsr
-         ! qsr_b (:,:) = qsr (:,:)
-         emp_b (:,:) = emp (:,:)
-         emps_b(:,:) = emps(:,:)
-      ENDIF
-      !                                            ! ---------------------------------------- !
-      !                                            !        forcing field computation         !
-      !                                            ! ---------------------------------------- !
-
-      CALL iom_setkt( kt + nn_fsbc - 1 )                 ! in sbc, iom_put is called every nn_fsbc time step
-      !
-      IF( ln_apr_dyn ) CALL sbc_apr( kt )                ! atmospheric pressure provided at kt+0.5*nn_fsbc
-                                                         ! (caution called before sbc_ssm)
-      !
-      CALL sbc_ssm( kt )                                 ! ocean sea surface variables (sst_m, sss_m, ssu_m, ssv_m)
-      !                                                  ! averaged over nf_sbc time-step
-
-      IF (ln_cdgw) CALL sbc_wave( kt )
-                                                   !==  sbc formulation  ==!
-                                                            
-      SELECT CASE( nsbc )                                ! Compute ocean surface boundary condition
-      !                                                  ! (i.e. utau,vtau, qns, qsr, emp, emps)
-      CASE(  0 )   ;   CALL sbc_gyre    ( kt )                    ! analytical formulation : GYRE configuration
-      CASE(  1 )   ;   CALL sbc_ana     ( kt )                    ! analytical formulation : uniform sbc
-      CASE(  2 )   ;   CALL sbc_flx     ( kt )                    ! flux formulation
-      CASE(  3 )   ;   CALL sbc_blk_clio( kt )                    ! bulk formulation : CLIO for the ocean
-      CASE(  4 )   ;   CALL sbc_blk_core( kt )                    ! bulk formulation : CORE for the ocean
-      CASE(  5 )   ;   CALL sbc_cpl_rcv ( kt, nn_fsbc, nn_ice )   ! coupled formulation
-      CASE(  6 )   ;   CALL sbc_blk_mfs ( kt )                    ! bulk formulation : MFS for the ocean
-      CASE( -1 )                                
-                       CALL sbc_ana     ( kt )                    ! ESOPA, test ALL the formulations
-                       CALL sbc_gyre    ( kt )                    !
-                       CALL sbc_flx     ( kt )                    !
-                       CALL sbc_blk_clio( kt )                    !
-                       CALL sbc_blk_core( kt )                    !
-                       CALL sbc_cpl_rcv ( kt, nn_fsbc, nn_ice )   !
-      END SELECT
-
-      !                                            !==  Misc. Options  ==!
-      
-      SELECT CASE( nn_ice )                                     ! Update heat and freshwater fluxes over sea-ice areas
-      CASE(  1 )   ;       CALL sbc_ice_if   ( kt )                  ! Ice-cover climatology ("Ice-if" model)
-         !                                                      
-      CASE(  2 )   ;       CALL sbc_ice_lim_2( kt, nsbc )            ! LIM-2 ice model
-         !IF( lk_bdy )      CALL bdy_ice_lim( kt )                   ! clem modif BDY boundary condition
-         !                                                     
-      CASE(  3 )   ;       CALL sbc_ice_lim  ( kt, nsbc )            ! LIM-3 ice model
-         !IF( lk_bdy )      CALL bdy_ice_lim( kt )                   ! clem modif BDY boundary condition
-         !
-      CASE(  4 )   ;       CALL sbc_ice_cice ( kt, nsbc )            ! CICE ice model
-      END SELECT                                              
-
-      IF( ln_rnf       )   CALL sbc_rnf( kt )                   ! add runoffs to fresh water fluxes
- 
-      IF( ln_ssr       )   CALL sbc_ssr( kt )                   ! add SST/SSS damping term
-
-      IF( nn_fwb  /= 0 )   CALL sbc_fwb( kt, nn_fwb, nn_fsbc )  ! control the freshwater budget
-
-      IF( nclosea == 1 )   CALL sbc_clo( kt )                   ! treatment of closed sea in the model domain 
-      !                                                         ! (update freshwater fluxes)
-!RBbug do not understand why see ticket 667
-      CALL lbc_lnk( emp, 'T', 1. )
-      !
-      IF( kt == nit000 ) THEN                          !   set the forcing field at nit000 - 1    !
-         !                                             ! ---------------------------------------- !
-         IF( ln_rstart .AND.    &                               !* Restart: read in restart file
-            & iom_varid( numror, 'utau_b', ldstop = .FALSE. ) > 0 ) THEN 
-            IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields red in the restart file'
-            CALL iom_get( numror, jpdom_autoglo, 'utau_b', utau_b )   ! before i-stress  (U-point)
-            CALL iom_get( numror, jpdom_autoglo, 'vtau_b', vtau_b )   ! before j-stress  (V-point)
-            CALL iom_get( numror, jpdom_autoglo, 'qns_b' , qns_b  )   ! before non solar heat flux (T-point)
-            ! The 3D heat content due to qsr forcing is treated in traqsr
-            ! CALL iom_get( numror, jpdom_autoglo, 'qsr_b' , qsr_b  )   ! before     solar heat flux (T-point)
-            CALL iom_get( numror, jpdom_autoglo, 'emp_b' , emp_b  )   ! before     freshwater flux (T-point)
-            CALL iom_get( numror, jpdom_autoglo, 'emps_b', emps_b )   ! before C/D freshwater flux (T-point)
-         ELSE                                                   !* no restart: set from nit000 values
-            IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields set to nit000'
-            utau_b(:,:) = utau(:,:) 
-            vtau_b(:,:) = vtau(:,:)
-            qns_b (:,:) = qns (:,:)
-            ! qsr_b (:,:) = qsr (:,:)
-            emp_b (:,:) = emp (:,:)
-            emps_b(:,:) = emps(:,:)
-         ENDIF
-      ENDIF
-      !                                                ! ---------------------------------------- !
-      IF( lrst_oce ) THEN                              !      Write in the ocean restart file     !
-         !                                             ! ---------------------------------------- !
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'sbc : ocean surface forcing fields written in ocean restart file ',   &
-            &                    'at it= ', kt,' date= ', ndastp
-         IF(lwp) WRITE(numout,*) '~~~~'
-         CALL iom_rstput( kt, nitrst, numrow, 'utau_b' , utau )
-         CALL iom_rstput( kt, nitrst, numrow, 'vtau_b' , vtau )
-         CALL iom_rstput( kt, nitrst, numrow, 'qns_b'  , qns  )
-         ! The 3D heat content due to qsr forcing is treated in traqsr
-         ! CALL iom_rstput( kt, nitrst, numrow, 'qsr_b'  , qsr  )
-         CALL iom_rstput( kt, nitrst, numrow, 'emp_b'  , emp  )
-         CALL iom_rstput( kt, nitrst, numrow, 'emps_b' , emps )
-      ENDIF
-
-      !                                                ! ---------------------------------------- !
-      !                                                !        Outputs and control print         !
-      !                                                ! ---------------------------------------- !
-      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN
-         CALL iom_put( "empmr" , emp  - rnf )                   ! upward water flux
-!!sf     CALL iom_put( "empsmr", emps - rnf )                   ! c/d water flux
-         CALL iom_put( "empsmr", emps       )                   ! modif lim3 : salt flux
-         CALL iom_put( "qt"    , qns  + qsr )                   ! total heat flux 
-         CALL iom_put( "qns"   , qns        )                   ! solar heat flux
-         CALL iom_put( "qsr"   ,       qsr  )                   ! solar heat flux
-         IF( nn_ice > 0 )   CALL iom_put( "ice_cover", fr_i )   ! ice fraction 
-      ENDIF
-      !
-      CALL iom_setkt( kt )           ! iom_put outside of sbc is called at every time step
-      !
-      CALL iom_put( "utau", utau )   ! i-wind stress   (stress can be updated at 
-      CALL iom_put( "vtau", vtau )   ! j-wind stress    each time step in sea-ice)
-      CALL iom_put( "taum", taum )   ! wind stress module 
-      CALL iom_put( "wspd", wndm )   ! wind speed  module 
-      !
-      IF(ln_ctl) THEN         ! print mean trends (used for debugging)
-         CALL prt_ctl(tab2d_1=fr_i             , clinfo1=' fr_i     - : ', mask1=tmask, ovlap=1 )
-         CALL prt_ctl(tab2d_1=(emp-rnf)        , clinfo1=' emp-rnf  - : ', mask1=tmask, ovlap=1 )
-         CALL prt_ctl(tab2d_1=(emps-rnf)       , clinfo1=' emps-rnf - : ', mask1=tmask, ovlap=1 )
-         CALL prt_ctl(tab2d_1=qns              , clinfo1=' qns      - : ', mask1=tmask, ovlap=1 )
-         CALL prt_ctl(tab2d_1=qsr              , clinfo1=' qsr      - : ', mask1=tmask, ovlap=1 )
-         CALL prt_ctl(tab3d_1=tmask            , clinfo1=' tmask    - : ', mask1=tmask, ovlap=1, kdim=jpk )
-         CALL prt_ctl(tab3d_1=tsn(:,:,:,jp_tem), clinfo1=' sst      - : ', mask1=tmask, ovlap=1, kdim=1   )
-         CALL prt_ctl(tab3d_1=tsn(:,:,:,jp_sal), clinfo1=' sss      - : ', mask1=tmask, ovlap=1, kdim=1   )
-         CALL prt_ctl(tab2d_1=utau             , clinfo1=' utau     - : ', mask1=umask,                      &
-            &         tab2d_2=vtau             , clinfo2=' vtau     - : ', mask2=vmask, ovlap=1 )
-      ENDIF
-
-      IF( kt == nitend )   CALL sbc_final         ! Close down surface module if necessary
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('sbc')
-      !
-   END SUBROUTINE sbc
-
-   SUBROUTINE sbc_final
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE sbc_final  ***
-      !!---------------------------------------------------------------------
-
-      !-----------------------------------------------------------------
-      ! Finalize CICE (if used)
-      !-----------------------------------------------------------------
-
-      IF( nn_ice == 4 )   CALL cice_sbc_final
-      !
-   END SUBROUTINE sbc_final
-
-   !!======================================================================
-END MODULE sbcmod
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/sbcssr.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/sbcssr.F90	(revision 3937)
+++ 	(revision )
@@ -1,215 +1,0 @@
-MODULE sbcssr
-   !!======================================================================
-   !!                       ***  MODULE  sbcssr  ***
-   !! Surface module :  heat and fresh water fluxes a restoring term toward observed SST/SSS
-   !!======================================================================
-   !! History :  3.0  !  2006-06  (G. Madec)  Original code
-   !!            3.2  !  2009-04  (B. Lemaire)  Introduce iom_put
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   sbc_ssr        : add to sbc a restoring term toward SST/SSS climatology
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! surface boundary condition
-   USE phycst          ! physical constants
-   USE sbcrnf          ! surface boundary condition : runoffs
-   USE fldread         ! read input fields
-   USE iom             ! I/O manager
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! distribued memory computing library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE timing          ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   sbc_ssr    ! routine called in sbcmod
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   erp   !: evaporation damping   [kg/m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qrp   !: heat flux damping        [w/m2]
-
-   !                                           !!* Namelist namsbc_ssr *
-   INTEGER, PUBLIC ::   nn_sstr     =   0       ! SST/SSS restoring indicator
-   INTEGER, PUBLIC ::   nn_sssr     =   0       ! SST/SSS restoring indicator
-   REAL(wp)        ::   rn_dqdt     = -40.e0    ! restoring factor on SST and SSS
-   REAL(wp)        ::   rn_deds     = -27.70    ! restoring factor on SST and SSS
-   LOGICAL         ::   ln_sssr_bnd = .false.   ! flag to bound erp term 
-   REAL(wp)        ::   rn_sssr_bnd =   0.e0    ! ABS(Max./Min.) value of erp term [mm/day]
-
-   REAL(wp) , ALLOCATABLE, DIMENSION(:) ::   buffer   ! Temporary buffer for exchange
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_sst   ! structure of input SST (file informations, fields read)
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_sss   ! structure of input SSS (file informations, fields read)
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
-   !! $Id: sbcssr.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE sbc_ssr( kt )
-      !!---------------------------------------------------------------------
-      !!                     ***  ROUTINE sbc_ssr  ***
-      !!
-      !! ** Purpose :   Add to heat and/or freshwater fluxes a damping term
-      !!                toward observed SST and/or SSS.
-      !!
-      !! ** Method  : - Read namelist namsbc_ssr
-      !!              - Read observed SST and/or SSS
-      !!              - at each nscb time step
-      !!                   add a retroaction term on qns    (nn_sstr = 1)
-      !!                   add a damping term on emps       (nn_sssr = 1)
-      !!                   add a damping term on emp & emps (nn_sssr = 2)
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in   ) ::   kt   ! ocean time step
-      !!
-      INTEGER  ::   ji, jj   ! dummy loop indices
-      REAL(wp) ::   zerp     ! local scalar for evaporation damping
-      REAL(wp) ::   zqrp     ! local scalar for heat flux damping
-      REAL(wp) ::   zsrp     ! local scalar for unit conversion of rn_deds factor
-      REAL(wp) ::   zerp_bnd ! local scalar for unit conversion of rn_epr_max factor
-      INTEGER  ::   ierror   ! return error code
-      !!
-      CHARACTER(len=100) ::  cn_dir          ! Root directory for location of ssr files
-      TYPE(FLD_N) ::   sn_sst, sn_sss        ! informations about the fields to be read
-      NAMELIST/namsbc_ssr/ cn_dir, nn_sstr, nn_sssr, rn_dqdt, rn_deds, sn_sst, sn_sss, ln_sssr_bnd, rn_sssr_bnd
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('sbc_ssr')
-      !
-      !                                               ! -------------------- !
-      IF( kt == nit000 ) THEN                         ! First call kt=nit000 !
-         !                                            ! -------------------- !
-         !                            !* set file information
-         cn_dir  = './'            ! directory in which the model is executed
-         ! ... default values (NB: frequency positive => hours, negative => months)
-         !            !   file    ! frequency !  variable  ! time intep !  clim   ! 'yearly' or ! weights  ! rotation   !
-         !            !   name    !  (hours)  !   name     !   (T/F)    !  (T/F)  !  'monthly'  ! filename ! pairs      !
-         sn_sst = FLD_N( 'sst'    ,    24     ,  'sst'     ,  .false.   , .false. ,   'yearly'  , ''       , ''         )
-         sn_sss = FLD_N( 'sss'    ,    -1     ,  'sss'     ,  .true.    , .false. ,   'yearly'  , ''       , ''         )
-
-         REWIND ( numnam )            !* read in namlist namflx
-         READ( numnam, namsbc_ssr ) 
-
-         IF(lwp) THEN                 !* control print
-            WRITE(numout,*)
-            WRITE(numout,*) 'sbc_ssr : SST and/or SSS damping term '
-            WRITE(numout,*) '~~~~~~~ '
-            WRITE(numout,*) '   Namelist namsbc_ssr :'
-            WRITE(numout,*) '      SST restoring term (Yes=1)             nn_sstr     = ', nn_sstr
-            WRITE(numout,*) '      SSS damping term (Yes=1, salt flux)    nn_sssr     = ', nn_sssr
-            WRITE(numout,*) '                       (Yes=2, volume flux) '
-            WRITE(numout,*) '      dQ/dT (restoring magnitude on SST)     rn_dqdt     = ', rn_dqdt, ' W/m2/K'
-            WRITE(numout,*) '      dE/dS (restoring magnitude on SST)     rn_deds     = ', rn_deds, ' mm/day'
-            WRITE(numout,*) '      flag to bound erp term                 ln_sssr_bnd = ', ln_sssr_bnd
-            WRITE(numout,*) '      ABS(Max./Min.) erp threshold           rn_sssr_bnd = ', rn_sssr_bnd, ' mm/day'
-         ENDIF
-
-         ! Allocate erp and qrp array
-         ALLOCATE( qrp(jpi,jpj), erp(jpi,jpj), STAT=ierror )
-         IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_ssr: unable to allocate erp and qrp array' )
-
-         IF( nn_sstr == 1 ) THEN      !* set sf_sst structure & allocate arrays
-            !
-            ALLOCATE( sf_sst(1), STAT=ierror )
-            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_ssr: unable to allocate sf_sst structure' )
-            ALLOCATE( sf_sst(1)%fnow(jpi,jpj,1), STAT=ierror )
-            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_ssr: unable to allocate sf_sst now array' )
-            !
-            ! fill sf_sst with sn_sst and control print
-            CALL fld_fill( sf_sst, (/ sn_sst /), cn_dir, 'sbc_ssr', 'SST restoring term toward SST data', 'namsbc_ssr' )
-            IF( sf_sst(1)%ln_tint )   ALLOCATE( sf_sst(1)%fdta(jpi,jpj,1,2), STAT=ierror )
-            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_ssr: unable to allocate sf_sst data array' )
-            !
-         ENDIF
-         !
-         IF( nn_sssr >= 1 ) THEN      ! set sf_sss structure & allocate arrays
-            !
-            ALLOCATE( sf_sss(1), STAT=ierror )
-            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_ssr: unable to allocate sf_sss structure' )
-            ALLOCATE( sf_sss(1)%fnow(jpi,jpj,1), STAT=ierror )
-            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_ssr: unable to allocate sf_sss now array' )
-            !
-            ! fill sf_sss with sn_sss and control print
-            CALL fld_fill( sf_sss, (/ sn_sss /), cn_dir, 'sbc_ssr', 'SSS restoring term toward SSS data', 'namsbc_ssr' )
-            IF( sf_sss(1)%ln_tint )   ALLOCATE( sf_sss(1)%fdta(jpi,jpj,1,2), STAT=ierror )
-            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_ssr: unable to allocate sf_sss data array' )
-            !
-         ENDIF
-         !
-         ! Initialize qrp and erp if no restoring 
-         IF( nn_sstr /= 1                   )   qrp(:,:) = 0.e0 
-         IF( nn_sssr /= 1 .OR. nn_sssr /= 2 )   erp(:,:) = 0.e0 
-      ENDIF
-
-      IF( nn_sstr + nn_sssr /= 0 ) THEN
-         !
-         IF( nn_sstr == 1)   CALL fld_read( kt, nn_fsbc, sf_sst )   ! Read SST data and provides it at kt
-         IF( nn_sssr >= 1)   CALL fld_read( kt, nn_fsbc, sf_sss )   ! Read SSS data and provides it at kt
-         !
-         !                                         ! ========================= !
-         IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN      !    Add restoring term     !
-            !                                      ! ========================= !
-            !
-            IF( nn_sstr == 1 ) THEN                   !* Temperature restoring term
-!CDIR COLLAPSE
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     zqrp = rn_dqdt * ( sst_m(ji,jj) - sf_sst(1)%fnow(ji,jj,1) )
-                     qns(ji,jj) = qns(ji,jj) + zqrp
-                     qrp(ji,jj) = zqrp
-                  END DO
-               END DO
-               CALL iom_put( "qrp", qrp )                             ! heat flux damping
-            ENDIF
-            !
-            IF( nn_sssr == 1 ) THEN                   !* Salinity damping term (salt flux, emps only)
-               zsrp = rn_deds / rday                                  ! from [mm/day] to [kg/m2/s]
-!CDIR COLLAPSE
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-!SF old                      zerp = zsrp * ( 1. - 2.*rnfmsk(ji,jj) )   &      ! No damping in vicinity of river mouths
-!SF old                         &        * ( sss_m(ji,jj) - sf_sss(1)%fnow(ji,jj,1) )   &
-!SF old                         &        / ( sss_m(ji,jj) + 1.e-20   )
-!SF old                      emps(ji,jj) = emps(ji,jj) + zerp
-!SF old                      erp( ji,jj) = zerp
-!
-                     zerp = zsrp * ( 1. - 2.*rnfmsk(ji,jj) )   &      ! No damping in vicinity of river mouths
-                        &        * ( sss_m(ji,jj) - sf_sss(1)%fnow(ji,jj,1) )   
-                     emps(ji,jj) = emps(ji,jj) + zerp
-                     erp( ji,jj) = zerp
-                  END DO
-               END DO
-               CALL iom_put( "erp", erp )                             ! freshwater flux damping
-               !
-            ELSEIF( nn_sssr == 2 ) THEN               !* Salinity damping term (volume flux, emp and emps)
-               zsrp = rn_deds / rday                                  ! from [mm/day] to [kg/m2/s]
-               zerp_bnd = rn_sssr_bnd / rday                          !       -              -    
-!CDIR COLLAPSE
-               DO jj = 1, jpj
-                  DO ji = 1, jpi                            
-                     zerp = zsrp * ( 1. - 2.*rnfmsk(ji,jj) )   &      ! No damping in vicinity of river mouths
-                        &        * ( sss_m(ji,jj) - sf_sss(1)%fnow(ji,jj,1) )   &
-                        &        / ( sss_m(ji,jj) + 1.e-20   )
-                     IF( ln_sssr_bnd )   zerp = SIGN( 1., zerp ) * MIN( zerp_bnd, ABS(zerp) )
-                     emp (ji,jj) = emp (ji,jj) + zerp
-                     erp (ji,jj) = zerp
-                  END DO
-               END DO
-               CALL iom_put( "erp", erp )                             ! freshwater flux damping
-            ENDIF
-            !
-         ENDIF
-         !
-      ENDIF
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('sbc_ssr')
-      !
-   END SUBROUTINE sbc_ssr
-      
-   !!======================================================================
-END MODULE sbcssr
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/step.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/step.F90	(revision 3937)
+++ 	(revision )
@@ -1,272 +1,0 @@
-MODULE step
-   !!======================================================================
-   !!                       ***  MODULE step  ***
-   !! Time-stepping    : manager of the ocean, tracer and ice time stepping
-   !!======================================================================
-   !! History :  OPA  !  1991-03  (G. Madec)  Original code
-   !!             -   !  1991-11  (G. Madec)
-   !!             -   !  1992-06  (M. Imbard)  add a first output record
-   !!             -   !  1996-04  (G. Madec)  introduction of dynspg
-   !!             -   !  1996-04  (M.A. Foujols)  introduction of passive tracer
-   !!            8.0  !  1997-06  (G. Madec)  new architecture of call
-   !!            8.2  !  1997-06  (G. Madec, M. Imbard, G. Roullet)  free surface
-   !!             -   !  1999-02  (G. Madec, N. Grima)  hpg implicit
-   !!             -   !  2000-07  (J-M Molines, M. Imbard)  Open Bondary Conditions
-   !!   NEMO     1.0  !  2002-06  (G. Madec)  free form, suppress macro-tasking
-   !!             -   !  2004-08  (C. Talandier) New trends organization
-   !!             -   !  2005-01  (C. Ethe) Add the KPP closure scheme
-   !!             -   !  2005-11  (G. Madec)  Reorganisation of tra and dyn calls
-   !!             -   !  2006-01  (L. Debreu, C. Mazauric)  Agrif implementation
-   !!             -   !  2006-07  (S. Masson)  restart using iom
-   !!            3.2  !  2009-02  (G. Madec, R. Benshila)  reintroduicing z*-coordinate
-   !!             -   !  2009-06  (S. Masson, G. Madec)  TKE restart compatible with key_cpl
-   !!            3.3  !  2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
-   !!             -   !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase + merge TRC-TRA
-   !!            3.4  !  2011-04  (G. Madec, C. Ethe) Merge of dtatem and dtasal
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   stp             : OPA system time-stepping
-   !!----------------------------------------------------------------------
-   USE step_oce         ! time stepping definition modules 
-#if defined key_top
-   USE trcstp           ! passive tracer time-stepping      (trc_stp routine)
-#endif
-#if defined key_agrif
-   USE agrif_opa_sponge ! Momemtum and tracers sponges
-#endif
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   stp   ! called by opa.F90
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "zdfddm_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: step.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-#if defined key_agrif
-   SUBROUTINE stp( )
-      INTEGER             ::   kstp   ! ocean time-step index
-#else
-   SUBROUTINE stp( kstp )
-      INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
-#endif
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE stp  ***
-      !!                      
-      !! ** Purpose : - Time stepping of OPA (momentum and active tracer eqs.)
-      !!              - Time stepping of LIM (dynamic and thermodynamic eqs.)
-      !!              - Tme stepping  of TRC (passive tracer eqs.)
-      !! 
-      !! ** Method  : -1- Update forcings and data  
-      !!              -2- Update ocean physics 
-      !!              -3- Compute the t and s trends 
-      !!              -4- Update t and s 
-      !!              -5- Compute the momentum trends
-      !!              -6- Update the horizontal velocity
-      !!              -7- Compute the diagnostics variables (rd,N2, div,cur,w)
-      !!              -8- Outputs and diagnostics
-      !!----------------------------------------------------------------------
-      INTEGER ::   jk       ! dummy loop indice
-      INTEGER ::   indic    ! error indicator if < 0
-      !! ---------------------------------------------------------------------
-
-#if defined key_agrif
-      kstp = nit000 + Agrif_Nb_Step()
-!      IF ( Agrif_Root() .and. lwp) Write(*,*) '---'
-!      IF (lwp) Write(*,*) 'Grid Number',Agrif_Fixed(),' time step ',kstp
-# if defined key_iomput
-      IF( Agrif_Nbstepint() == 0 )   CALL iom_swap
-# endif   
-#endif   
-                             indic = 0                ! reset to no error condition
-      IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
-                             CALL iom_setkt( kstp )   ! say to iom that we are at time step kstp
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Update data, open boundaries, surface boundary condition (including sea-ice)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL sbc    ( kstp )         ! Sea Boundary Condition (including sea-ice)
-      IF( lk_tide    )   CALL sbc_tide( kstp )
-      IF( lk_obc     )   CALL obc_dta( kstp )         ! update dynamic and tracer data at open boundaries
-      IF( lk_obc     )   CALL obc_rad( kstp )         ! compute phase velocities at open boundaries
-      IF( lk_bdy     )   CALL bdy_dta( kstp, time_offset=+1 ) ! update dynamic and tracer data at open boundaries
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      !  Ocean dynamics : ssh, wn, hdiv, rot                                 !
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL ssh_wzv( kstp )         ! after ssh & vertical velocity
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Ocean physics update                (ua, va, tsa used as workspace)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL bn2( tsb, rn2b )        ! before Brunt-Vaisala frequency
-                         CALL bn2( tsn, rn2  )        ! now    Brunt-Vaisala frequency
-      !
-      !  VERTICAL PHYSICS   
-                         CALL zdf_bfr( kstp )         ! bottom friction
-                         
-      !                                               ! Vertical eddy viscosity and diffusivity coefficients
-      IF( lk_zdfric  )   CALL zdf_ric( kstp )            ! Richardson number dependent Kz
-      IF( lk_zdftke  )   CALL zdf_tke( kstp )            ! TKE closure scheme for Kz
-      IF( lk_zdfgls  )   CALL zdf_gls( kstp )            ! GLS closure scheme for Kz
-      IF( lk_zdfkpp  )   CALL zdf_kpp( kstp )            ! KPP closure scheme for Kz
-      IF( lk_zdfcst  )   THEN                            ! Constant Kz (reset avt, avm[uv] to the background value)
-         avt (:,:,:) = rn_avt0 * tmask(:,:,:)
-         avmu(:,:,:) = rn_avm0 * umask(:,:,:)
-         avmv(:,:,:) = rn_avm0 * vmask(:,:,:)
-      ENDIF
-      IF( ln_rnf_mouth ) THEN                         ! increase diffusivity at rivers mouths
-         DO jk = 2, nkrnf   ;   avt(:,:,jk) = avt(:,:,jk) + 2.e0 * rn_avt_rnf * rnfmsk(:,:) * tmask(:,:,jk)   ;   END DO
-      ENDIF
-      IF( ln_zdfevd  )   CALL zdf_evd( kstp )         ! enhanced vertical eddy diffusivity
-
-      IF( lk_zdftmx  )   CALL zdf_tmx( kstp )         ! tidal vertical mixing
-
-      IF( lk_zdfddm .AND. .NOT. lk_zdfkpp )   &
-         &               CALL zdf_ddm( kstp )         ! double diffusive mixing
-         
-                         CALL zdf_mxl( kstp )         ! mixed layer depth
-
-                                                      ! write TKE or GLS information in the restart file
-      IF( lrst_oce .AND. lk_zdftke )   CALL tke_rst( kstp, 'WRITE' )
-      IF( lrst_oce .AND. lk_zdfgls )   CALL gls_rst( kstp, 'WRITE' )
-      !
-      !  LATERAL  PHYSICS 
-      !
-      IF( lk_ldfslp ) THEN                            ! slope of lateral mixing
-                         CALL eos( tsb, rhd )                ! before in situ density
-         IF( ln_zps )    CALL zps_hde( kstp, jpts, tsb, gtsu, gtsv,  &    ! Partial steps: before horizontal gradient
-            &                                      rhd, gru , grv  )      ! of t, s, rd at the last ocean level
-         IF( ln_traldf_grif ) THEN                           ! before slope for Griffies operator
-                         CALL ldf_slp_grif( kstp )
-         ELSE
-                         CALL ldf_slp( kstp, rhd, rn2b )     ! before slope for Madec operator
-         ENDIF
-      ENDIF
-#if defined key_traldf_c2d
-      IF( lk_traldf_eiv )   CALL ldf_eiv( kstp )      ! eddy induced velocity coefficient
-#endif
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! diagnostics and outputs             (ua, va, tsa used as workspace)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( lk_floats  )   CALL flo_stp( kstp )         ! drifting Floats
-      IF( lk_diahth  )   CALL dia_hth( kstp )         ! Thermocline depth (20 degres isotherm depth)
-      IF( lk_diafwb  )   CALL dia_fwb( kstp )         ! Fresh water budget diagnostics
-      IF( ln_diaptr  )   CALL dia_ptr( kstp )         ! Poleward TRansports diagnostics
-      IF( lk_diadct  )   CALL dia_dct( kstp )         ! Transports
-      IF( lk_diaar5  )   CALL dia_ar5( kstp )         ! ar5 diag
-      IF( lk_diaharm )   CALL dia_harm( kstp )        ! Tidal harmonic analysis
-                         CALL dia_wri( kstp )         ! ocean model: outputs
-
-#if defined key_top
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Passive Tracer Model
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL trc_stp( kstp )         ! time-stepping
-#endif
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Active tracers                              (ua, va used as workspace)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                             tsa(:,:,:,:) = 0.e0            ! set tracer trends to zero
-
-      IF(  ln_asmiau .AND. &
-         & ln_trainc     )   CALL tra_asm_inc( kstp )       ! apply tracer assimilation increment
-                             CALL tra_sbc    ( kstp )       ! surface boundary condition
-      IF( ln_traqsr      )   CALL tra_qsr    ( kstp )       ! penetrative solar radiation qsr
-      IF( ln_trabbc      )   CALL tra_bbc    ( kstp )       ! bottom heat flux
-      IF( lk_trabbl      )   CALL tra_bbl    ( kstp )       ! advective (and/or diffusive) bottom boundary layer scheme
-      IF( ln_tradmp      )   CALL tra_dmp    ( kstp )       ! internal damping trends
-                             CALL tra_adv    ( kstp )       ! horizontal & vertical advection
-      IF( lk_zdfkpp      )   CALL tra_kpp    ( kstp )       ! KPP non-local tracer fluxes
-                             CALL tra_ldf    ( kstp )       ! lateral mixing
-#if defined key_agrif
-      IF(.NOT. Agrif_Root()) CALL Agrif_Sponge_tra          ! tracers sponge
-#endif
-                             CALL tra_zdf    ( kstp )       ! vertical mixing and after tracer fields
-
-      IF( ln_dynhpg_imp  ) THEN                             ! semi-implicit hpg (time stepping then eos)
-         IF( ln_zdfnpc   )   CALL tra_npc( kstp )                ! update after fields by non-penetrative convection
-                             CALL tra_nxt( kstp )                ! tracer fields at next time step
-                             CALL eos    ( tsa, rhd, rhop )      ! Time-filtered in situ density for hpg computation
-         IF( ln_zps      )   CALL zps_hde( kstp, jpts, tsa, gtsu, gtsv,  &    ! zps: time filtered hor. derivative
-            &                                          rhd, gru , grv  )      ! of t, s, rd at the last ocean level
-         
-      ELSE                                                  ! centered hpg  (eos then time stepping)
-                             CALL eos    ( tsn, rhd, rhop )      ! now in situ density for hpg computation
-         IF( ln_zps      )   CALL zps_hde( kstp, jpts, tsn, gtsu, gtsv,  &    ! zps: now hor. derivative
-            &                                          rhd, gru , grv  )      ! of t, s, rd at the last ocean level
-         IF( ln_zdfnpc   )   CALL tra_npc( kstp )                ! update after fields by non-penetrative convection
-                             CALL tra_nxt( kstp )                ! tracer fields at next time step
-      ENDIF 
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Dynamics                                    (tsa used as workspace)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                               ua(:,:,:) = 0.e0             ! set dynamics trends to zero
-                               va(:,:,:) = 0.e0
-
-      IF(  ln_asmiau .AND. &
-         & ln_dyninc       )   CALL dyn_asm_inc( kstp )     ! apply dynamics assimilation increment
-      IF( ln_neptsimp )        CALL dyn_nept_cor( kstp )    ! subtract Neptune velocities (simplified)
-                               CALL dyn_adv( kstp )         ! advection (vector or flux form)
-                               CALL dyn_vor( kstp )         ! vorticity term including Coriolis
-                               CALL dyn_ldf( kstp )         ! lateral mixing
-      IF( ln_neptsimp )        CALL dyn_nept_cor( kstp )    ! add Neptune velocities (simplified)
-#if defined key_agrif
-      IF(.NOT. Agrif_Root())   CALL Agrif_Sponge_dyn        ! momemtum sponge
-#endif
-                               CALL dyn_hpg( kstp )         ! horizontal gradient of Hydrostatic pressure
-                               CALL dyn_bfr( kstp )         ! bottom friction   
-                               CALL dyn_zdf( kstp )         ! vertical diffusion
-                               CALL dyn_spg( kstp, indic )  ! surface pressure gradient
-                               CALL dyn_nxt( kstp )         ! lateral velocity at next time step
-
-                               CALL ssh_nxt( kstp )         ! sea surface height at next time step
-
-      IF( ln_diahsb        )   CALL dia_hsb( kstp )         ! global conservation diagnostics
-      IF( lk_diaobs  )         CALL dia_obs( kstp )         ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
-
-      IF( lrst_oce .AND. ln_diahsb )   CALL dia_hsb_rst( kstp, 'WRITE' )
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Control and restarts
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                               CALL stp_ctl( kstp, indic )
-      IF( indic < 0        )   THEN
-                               CALL ctl_stop( 'step: indic < 0' )
-                               CALL dia_wri_state( 'output.abort', kstp )
-      ENDIF
-      IF( kstp == nit000   )   CALL iom_close( numror )     ! close input  ocean restart file
-      IF( lrst_oce         )   CALL rst_write    ( kstp )   ! write output ocean restart file
-      IF( lk_obc           )   CALL obc_rst_write( kstp )   ! write open boundary restart file
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Trends                              (ua, va, tsa used as workspace)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( nstop == 0 ) THEN                         
-         IF( lk_trddyn     )   CALL trd_dwr( kstp )         ! trends: dynamics 
-         IF( lk_trdtra     )   CALL trd_twr( kstp )         ! trends: active tracers
-         IF( lk_trdmld     )   CALL trd_mld( kstp )         ! trends: Mixed-layer 
-         IF( lk_trdvor     )   CALL trd_vor( kstp )         ! trends: vorticity budget
-      ENDIF
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Coupled mode
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( lk_cpl           )   CALL sbc_cpl_snd( kstp )     ! coupled mode : field exchanges
-      !
-      IF( nn_timing == 1 .AND.  kstp == nit000  )   CALL timing_reset
-      !
-   END SUBROUTINE stp
-
-   !!======================================================================
-END MODULE step
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/stpctl.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/stpctl.F90	(revision 3937)
+++ 	(revision )
@@ -1,180 +1,0 @@
-MODULE stpctl
-   !!======================================================================
-   !!                       ***  MODULE  stpctl  ***
-   !! Ocean run control :  gross check of the ocean time stepping
-   !!======================================================================
-   !! History :  OPA  ! 1991-03  (G. Madec) Original code
-   !!            6.0  ! 1992-06  (M. Imbard)
-   !!            8.0  ! 1997-06  (A.M. Treguier)
-   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
-   !!            2.0  ! 2009-07  (G. Madec)  Add statistic for time-spliting
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   stp_ctl      : Control the run
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables 
-   USE sol_oce         ! ocean space and time domain variables 
-   USE in_out_manager  ! I/O manager
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp         ! distributed memory computing
-   USE dynspg_oce      ! pressure gradient schemes 
-   USE c1d             ! 1D vertical configuration
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC stp_ctl           ! routine called by step.F90
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: stpctl.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE stp_ctl( kt, kindic )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE stp_ctl  ***
-      !!                     
-      !! ** Purpose :   Control the run
-      !!
-      !! ** Method  : - Save the time step in numstp
-      !!              - Print it each 50 time steps
-      !!              - Print solver statistics in numsol 
-      !!              - Stop the run IF problem for the solver ( indec < 0 )
-      !!
-      !! ** Actions :   'time.step' file containing the last ocean time-step
-      !!                
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
-      INTEGER, INTENT( inout ) ::   kindic  ! indicator of solver convergence
-      !!
-      INTEGER  ::   ji, jj, jk              ! dummy loop indices
-      INTEGER  ::   ii, ij, ik              ! temporary integers
-      REAL(wp) ::   zumax, zsmin, zssh2     ! temporary scalars
-      INTEGER, DIMENSION(3) ::   ilocu      ! 
-      INTEGER, DIMENSION(2) ::   ilocs      ! 
-      !!----------------------------------------------------------------------
-
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'stp_ctl : time-stepping control'
-         WRITE(numout,*) '~~~~~~~'
-         ! open time.step file
-         CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
-      ENDIF
-
-      IF(lwp) WRITE ( numstp, '(1x, i8)' )   kt      !* save the current time step in numstp
-      IF(lwp) REWIND( numstp )                       !  --------------------------
-
-      !                                              !* Test maximum of velocity (zonal only)
-      !                                              !  ------------------------
-      !! zumax = MAXVAL( ABS( un(:,:,:) ) )                ! slower than the following loop on NEC SX5
-      zumax = 0.e0
-      DO jk = 1, jpk
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zumax = MAX(zumax,ABS(un(ji,jj,jk)))
-          END DO 
-        END DO 
-      END DO        
-      IF( lk_mpp )   CALL mpp_max( zumax )                 ! max over the global domain
-      !
-      IF( MOD( kt, nwrite ) == 1 .AND. lwp )   WRITE(numout,*) ' ==>> time-step= ',kt,' abs(U) max: ', zumax
-      !
-      IF( zumax > 20.e0 ) THEN
-         IF( lk_mpp ) THEN
-            CALL mpp_maxloc(ABS(un),umask,zumax,ii,ij,ik)
-         ELSE
-            ilocu = MAXLOC( ABS( un(:,:,:) ) )
-            ii = ilocu(1) + nimpp - 1
-            ij = ilocu(2) + njmpp - 1
-            ik = ilocu(3)
-         ENDIF
-         IF(lwp) THEN
-            WRITE(numout,cform_err)
-            WRITE(numout,*) ' stpctl: the zonal velocity is larger than 20 m/s'
-            WRITE(numout,*) ' ====== '
-            WRITE(numout,9400) kt, zumax, ii, ij, ik
-            WRITE(numout,*)
-            WRITE(numout,*) '          output of last fields in numwso'
-         ENDIF
-         kindic = -3
-      ENDIF
-9400  FORMAT (' kt=',i6,' max abs(U): ',1pg11.4,', i j k: ',3i5)
-
-      !                                              !* Test minimum of salinity
-      !                                              !  ------------------------
-      !! zsmin = MINVAL( tsn(:,:,1,jp_sal), mask = tmask(:,:,1) == 1.e0 )  slower than the following loop on NEC SX5
-      zsmin = 100.e0
-      DO jj = 2, jpjm1
-         DO ji = 1, jpi
-            IF( tmask(ji,jj,1) == 1) zsmin = MIN(zsmin,tsn(ji,jj,1,jp_sal))
-         END DO
-      END DO
-      IF( lk_mpp )   CALL mpp_min( zsmin )                ! min over the global domain
-      !
-      IF( MOD( kt, nwrite ) == 1 .AND. lwp )   WRITE(numout,*) ' ==>> time-step= ',kt,' SSS min:', zsmin
-      !
-      IF( zsmin < 0.) THEN 
-         IF (lk_mpp) THEN
-            CALL mpp_minloc ( tsn(:,:,1,jp_sal),tmask(:,:,1), zsmin, ii,ij )
-         ELSE
-            ilocs = MINLOC( tsn(:,:,1,jp_sal), mask = tmask(:,:,1) == 1.e0 )
-            ii = ilocs(1) + nimpp - 1
-            ij = ilocs(2) + njmpp - 1
-         ENDIF
-         !
-         IF(lwp) THEN
-            WRITE(numout,cform_err)
-            WRITE(numout,*) 'stp_ctl : NEGATIVE sea surface salinity'
-            WRITE(numout,*) '======= '
-            WRITE(numout,9500) kt, zsmin, ii, ij
-            WRITE(numout,*)
-            WRITE(numout,*) '          output of last fields in numwso'
-         ENDIF
-         kindic = -3
-      ENDIF
-9500  FORMAT (' kt=',i6,' min SSS: ',1pg11.4,', i j: ',2i5)
-
-      
-      IF( lk_c1d )  RETURN          ! No log file in case of 1D vertical configuration
-
-      ! log file (solver or ssh statistics)
-      ! --------
-      IF( lk_dynspg_flt ) THEN      ! elliptic solver statistics (if required)
-         !
-         IF(lwp) WRITE(numsol,9200) kt, niter, res, SQRT(epsr)/eps       ! Solver
-         !
-         IF( kindic < 0 .AND. zsmin > 0.e0 .AND. zumax <= 20.e0 ) THEN   ! create a abort file if problem found 
-            IF(lwp) THEN
-               WRITE(numout,*) ' stpctl: the elliptic solver DO not converge or explode'
-               WRITE(numout,*) ' ====== '
-               WRITE(numout,9200) kt, niter, res, sqrt(epsr)/eps
-               WRITE(numout,*)
-               WRITE(numout,*) ' stpctl: output of last fields'
-               WRITE(numout,*) ' ======  '
-            ENDIF
-         ENDIF
-         !
-      ELSE                                   !* ssh statistics (and others...)
-         IF( kt == nit000 .AND. lwp ) THEN   ! open ssh statistics file (put in solver.stat file)
-            CALL ctl_opn( numsol, 'solver.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
-         ENDIF
-         !
-         zssh2 = SUM( sshn(:,:) * sshn(:,:) * tmask_i(:,:) )
-         IF( lk_mpp )   CALL mpp_sum( zssh2 )      ! sum over the global domain
-         !
-         IF(lwp) WRITE(numsol,9300) kt, zssh2, zumax, zsmin      ! ssh statistics
-         !
-      ENDIF
-
-9200  FORMAT('it:', i8, ' iter:', i4, ' r: ',e16.10, ' b: ',e16.10 )
-9300  FORMAT(' it :', i8, ' ssh2: ', e16.10, ' Umax: ',e16.10,' Smin: ',e16.10)
-      !
-   END SUBROUTINE stp_ctl
-
-   !!======================================================================
-END MODULE stpctl
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/thd_ice.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/thd_ice.F90	(revision 3937)
+++ 	(revision )
@@ -1,206 +1,0 @@
-MODULE thd_ice
-   !!======================================================================
-   !!                       ***  MODULE thd_ice  ***
-   !! LIM sea-ice :   Ice thermodynamics in 1D
-   !!=====================================================================
-   !! History :  3.0  !  2002-11  (C. Ethe)  F90: Free form and module
-   !!----------------------------------------------------------------------
-   USE par_ice        ! LIM-3 parameters
-   USE in_out_manager ! I/O manager
-   USE lib_mpp         ! MPP library
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC thd_ice_alloc ! Routine called by nemogcm.F90
-
-   !!---------------------------
-   !! * Share Module variables
-   !!---------------------------
-   !                                         !!! ** ice-thermo namelist (namicethd) **
-   REAL(wp), PUBLIC ::   hmelt   = -0.15     !: maximum melting at the bottom; active only for one category
-   REAL(wp), PUBLIC ::   hicmin  = 0.2       !: (REMOVE)
-   REAL(wp), PUBLIC ::   hiclim  = 0.05      !: minimum ice thickness
-   REAL(wp), PUBLIC ::   sbeta   = 1.0       !: numerical scheme for diffusion in ice  (REMOVE)
-   REAL(wp), PUBLIC ::   parlat  = 0.0       !: (REMOVE)
-   REAL(wp), PUBLIC ::   hakspl  = 0.5       !: (REMOVE)
-   REAL(wp), PUBLIC ::   hibspl  = 0.5       !: (REMOVE)
-   REAL(wp), PUBLIC ::   exld    = 2.0       !: (REMOVE)
-   REAL(wp), PUBLIC ::   hakdif  = 1.0       !: (REMOVE)
-   REAL(wp), PUBLIC ::   thth    = 0.2       !: (REMOVE)
-   REAL(wp), PUBLIC ::   hnzst   = 0.1       !: thick. of the surf. layer in temp. comp.
-   REAL(wp), PUBLIC ::   parsub  = 1.0       !: switch for snow sublimation or not
-   REAL(wp), PUBLIC ::   alphs   = 1.0       !: coef. for snow density when snow-ice formation
-   REAL(wp), PUBLIC ::   fraz_swi= 1.0       !: use of frazil ice collection in function of wind (1.0) or not (0.0)
-   REAL(wp), PUBLIC ::   maxfrazb= 0.7       !: maximum portion of frazil ice collecting at the ice bottom
-   REAL(wp), PUBLIC ::   vfrazb  = 0.41667   !: threshold drift speed for collection of bottom frazil ice
-   REAL(wp), PUBLIC ::   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, ALLOCATABLE, SAVE, DIMENSION(:) ::   npb    !: number of points where computations has to be done
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   npac   !: correspondance between points (lateral accretion)
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qldif_1d      !: <==> the 2D  qldif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qcmif_1d      !: <==> the 2D  qcmif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fstbif_1d     !: <==> the 2D  fstric
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fltbif_1d     !: <==> the 2D  ffltbif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fscbq_1d      !: <==> the 2D  fscmcbq
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qsr_ice_1d    !: <==> the 2D  qsr_ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fr1_i0_1d     !: <==> the 2D  fr1_i0
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fr2_i0_1d     !: <==> the 2D  fr2_i0
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qnsr_ice_1d   !: <==> the 2D  qns_ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qfvbq_1d      !: <==> the 2D  qfvbq
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   t_bo_b        !: <==> the 2D  t_bo
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sprecip_1d    !: <==> the 2D  sprecip
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   frld_1d       !: <==> the 2D  frld
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   at_i_b        !: <==> the 2D  frld
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fbif_1d       !: <==> the 2D  fbif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   rdmicif_1d    !: <==> the 2D  rdmicif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   rdmsnif_1d    !: <==> the 2D  rdmsnif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qlbbq_1d      !: <==> the 2D  qlbsbq
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dmgwi_1d      !: <==> the 2D  dmgwi
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dvsbq_1d      !: <==> the 2D  rdvosif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dvbbq_1d      !: <==> the 2D  rdvobif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dvlbq_1d      !: <==> the 2D  rdvolif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dvnbq_1d      !: <==> the 2D  rdvolif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dqns_ice_1d   !: <==> the 2D  dqns_ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qla_ice_1d    !: <==> the 2D  qla_ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dqla_ice_1d   !: <==> the 2D  dqla_ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   tatm_ice_1d   !: <==> the 2D  tatm_ice
-   !                                                     ! to reintegrate longwave flux inside the ice thermodynamics
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fsup          !: Energy flux sent from bottom to lateral ablation if |dhb|> 0.15 m
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   focea         !: Remaining energy in case of total ablation
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   i0            !: fraction of radiation transmitted to the ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   old_ht_i_b    !: Ice thickness at the beginnning of the time step [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   old_ht_s_b    !: Snow thickness at the beginning of the time step [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fsbri_1d      !: Salt flux due to brine drainage
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fhbri_1d      !: Heat flux due to brine drainage
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fseqv_1d      !: Equivalent Salt flux due to ice growth/decay
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dsm_i_fl_1d   !: Ice salinity variations due to flushing
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dsm_i_gd_1d   !: Ice salinity variations due to gravity drainage
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dsm_i_se_1d   !: Ice salinity variations due to basal salt entrapment
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dsm_i_si_1d   !: Ice salinity variations due to lateral accretion    
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hicol_b       !: Ice collection thickness accumulated in fleads
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   t_su_b      !: <==> the 2D  t_su
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   a_i_b       !: <==> the 2D  a_i
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ht_i_b      !: <==> the 2D  ht_s
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ht_s_b      !: <==> the 2D  ht_i
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fc_su       !: Surface Conduction flux 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fc_bo_i     !: Bottom  Conduction flux 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_s_tot    !: Snow accretion/ablation        [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_i_surf   !: Ice surface accretion/ablation [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_i_bott   !: Ice bottom accretion/ablation  [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_snowice  !: Snow ice formation             [m of ice]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sm_i_b      !: Ice bulk salinity [ppt]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   s_i_new     !: Salinity of new ice at the bottom
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   s_snowice   !: Salinity of new snow ice on top of the ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   o_i_b       !: Ice age                        [days]
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   iatte_1d   !: clem attenuation coef of the input solar flux (unitless)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   oatte_1d   !: clem attenuation coef of the input solar flux (unitless)
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_s_b   !: corresponding to the 2D var  t_s
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_i_b   !: corresponding to the 2D var  t_i
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   s_i_b   !: profiled ice salinity
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   q_i_b   !:    Ice  enthalpy per unit volume
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   q_s_b   !:    Snow enthalpy per unit volume
-
-   ! Clean the following ...
-   ! These variables are coded for conservation checks
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qt_i_in                  !: ice energy summed over categories (initial)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qt_i_fin                 !: ice energy summed over categories (final)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qt_s_in, qt_s_fin        !: snow energy summed over categories
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   dq_i, sum_fluxq          !: increment of energy, sum of fluxes
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fatm, foce               !: atmospheric, oceanic, heat flux
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   cons_error, surf_error   !: conservation, surface error
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   q_i_layer_in        !: goes to trash
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   q_i_layer_fin       !: goes to trash
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   dq_i_layer, radab   !: goes to trash
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ftotal_in    !: initial total heat flux
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ftotal_fin   !: final total heat flux
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fc_s
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fc_i
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   de_s_lay
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   de_i_lay
-   
-   INTEGER , PUBLIC ::   jiindex_1d   ! 1D index of debugging point
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: thd_ice.F90 2715 2011-03-30 15:58:35Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   FUNCTION thd_ice_alloc()
-      !!---------------------------------------------------------------------!
-      !!                ***  ROUTINE thd_ice_alloc ***
-      !!---------------------------------------------------------------------!
-      INTEGER ::   thd_ice_alloc   ! return value
-      INTEGER ::   ierr(4)
-      !!---------------------------------------------------------------------!
-
-      ALLOCATE( npb      (jpij) , npac     (jpij),                          &
-         !                                                                  !
-         &      qldif_1d (jpij) , qcmif_1d (jpij) , fstbif_1d  (jpij) ,     &
-         &      fltbif_1d(jpij) , fscbq_1d (jpij) , qsr_ice_1d (jpij) ,     &
-         &      fr1_i0_1d(jpij) , fr2_i0_1d(jpij) , qnsr_ice_1d(jpij) ,     &
-         &      qfvbq_1d (jpij) , t_bo_b   (jpij) , iatte_1d   (jpij) ,     &
-         &      oatte_1d (jpij)                                       , STAT=ierr(1) )
-      !
-      ALLOCATE( sprecip_1d (jpij) , frld_1d    (jpij) , at_i_b     (jpij) ,     &
-         &      fbif_1d    (jpij) , rdmicif_1d (jpij) , rdmsnif_1d (jpij) ,     &
-         &      qlbbq_1d   (jpij) , dmgwi_1d   (jpij) , dvsbq_1d   (jpij) ,     &
-         &      dvbbq_1d   (jpij) , dvlbq_1d   (jpij) , dvnbq_1d   (jpij) ,     &
-         &      dqns_ice_1d(jpij) , qla_ice_1d (jpij) , dqla_ice_1d(jpij) ,     &
-         &      tatm_ice_1d(jpij) , fsup       (jpij) , focea      (jpij) ,     &   
-         &      i0         (jpij) , old_ht_i_b (jpij) , old_ht_s_b (jpij) ,     &  
-         &      fsbri_1d   (jpij) , fhbri_1d   (jpij) , fseqv_1d   (jpij) ,     &
-         &      dsm_i_fl_1d(jpij) , dsm_i_gd_1d(jpij) , dsm_i_se_1d(jpij) ,     &     
-         &      dsm_i_si_1d(jpij) , hicol_b    (jpij)                     , STAT=ierr(2) )
-      !
-      ALLOCATE( t_su_b    (jpij) , a_i_b    (jpij) , ht_i_b   (jpij) ,    &   
-         &      ht_s_b    (jpij) , fc_su    (jpij) , fc_bo_i  (jpij) ,    &    
-         &      dh_s_tot  (jpij) , dh_i_surf(jpij) , dh_i_bott(jpij) ,    &    
-         &      dh_snowice(jpij) , sm_i_b   (jpij) , s_i_new  (jpij) ,    &    
-         &      s_snowice (jpij) , o_i_b    (jpij)                   ,    &
-         !                                                                !
-         &      t_s_b(jpij,nlay_s),                                       &
-         !                                                                !
-         &      t_i_b(jpij,jkmax), s_i_b(jpij,jkmax)                ,     &            
-         &      q_i_b(jpij,jkmax), q_s_b(jpij,jkmax)                , STAT=ierr(3))
-      !
-      ALLOCATE( qt_i_in   (jpij,jpl) , qt_i_fin(jpij,jpl) , qt_s_in   (jpij,jpl) ,     &
-         &      qt_s_fin  (jpij,jpl) , dq_i    (jpij,jpl) , sum_fluxq (jpij,jpl) ,     &
-         &      fatm      (jpij,jpl) , foce    (jpij,jpl) , cons_error(jpij,jpl) ,     &
-         &      surf_error(jpij,jpl)                                             ,     &
-         !                                                                             !
-         &      q_i_layer_in(jpij,jkmax) , q_i_layer_fin(jpij,jkmax)             ,     &
-         &      dq_i_layer  (jpij,jkmax) , radab        (jpij,jkmax)             ,     &
-         !                                                                             !
-         &      ftotal_in(jpij), ftotal_fin(jpij)                                ,     &
-         !                                                                             !
-         &      fc_s(jpij,0:nlay_s) , de_s_lay(jpij,nlay_s)                      ,     &
-         &      fc_i(jpij,0:jkmax)  , de_i_lay(jpij,jkmax)                       , STAT=ierr(4) )
-
-      thd_ice_alloc = MAXVAL( ierr )
-
-      IF( thd_ice_alloc /= 0 )   CALL ctl_warn( 'thd_ice_alloc: failed to allocate arrays.' )
-      !
-   END FUNCTION thd_ice_alloc
-   
-   !!======================================================================
-END MODULE thd_ice
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/traqsr.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/traqsr.F90	(revision 3937)
+++ 	(revision )
@@ -1,581 +1,0 @@
-MODULE traqsr
-   !!======================================================================
-   !!                       ***  MODULE  traqsr  ***
-   !! Ocean physics: solar radiation penetration in the top ocean levels
-   !!======================================================================
-   !! History :  OPA  !  1990-10  (B. Blanke)  Original code
-   !!            7.0  !  1991-11  (G. Madec)
-   !!                 !  1996-01  (G. Madec)  s-coordinates
-   !!   NEMO     1.0  !  2002-06  (G. Madec)  F90: Free form and module
-   !!             -   !  2005-11  (G. Madec) zco, zps, sco coordinate
-   !!            3.2  !  2009-04  (G. Madec & NEMO team) 
-   !!            4.0  !  2012-05  (C. Rousset) store attenuation coef for use in ice model 
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   tra_qsr      : trend due to the solar radiation penetration
-   !!   tra_qsr_init : solar radiation penetration initialization
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and active tracers
-   USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! surface boundary condition: ocean
-   USE trc_oce         ! share SMS/Ocean variables
-   USE trdmod_oce      ! ocean variables trends
-   USE trdtra          ! ocean active tracers trends 
-   USE in_out_manager  ! I/O manager
-   USE phycst          ! physical constants
-   USE prtctl          ! Print control
-   USE iom             ! I/O manager
-   USE fldread         ! read input fields
-   USE restart         ! ocean restart
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo       ! Memory Allocation
-   USE timing         ! Timing
-
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   tra_qsr       ! routine called by step.F90 (ln_traqsr=T)
-   PUBLIC   tra_qsr_init  ! routine called by opa.F90
-
-   !                                           !!* Namelist namtra_qsr: penetrative solar radiation
-   LOGICAL , PUBLIC ::   ln_traqsr  = .TRUE.    !: light absorption (qsr) flag
-   LOGICAL , PUBLIC ::   ln_qsr_rgb = .FALSE.   !: Red-Green-Blue light absorption flag  
-   LOGICAL , PUBLIC ::   ln_qsr_2bd = .TRUE.    !: 2 band         light absorption flag
-   LOGICAL , PUBLIC ::   ln_qsr_bio = .FALSE.   !: bio-model      light absorption flag
-   LOGICAL , PUBLIC ::   ln_qsr_ice = .TRUE.    !: light penetration for ice-model LIM3 (clem)
-   INTEGER , PUBLIC ::   nn_chldta  = 0         !: use Chlorophyll data (=1) or not (=0)
-   REAL(wp), PUBLIC ::   rn_abs     = 0.58_wp   !: fraction absorbed in the very near surface (RGB & 2 bands)
-   REAL(wp), PUBLIC ::   rn_si0     = 0.35_wp   !: very near surface depth of extinction      (RGB & 2 bands)
-   REAL(wp), PUBLIC ::   rn_si1     = 23.0_wp   !: deepest depth of extinction (water type I)       (2 bands)
-   
-   ! Module variables
-   REAL(wp) ::   xsi0r                           !: inverse of rn_si0
-   REAL(wp) ::   xsi1r                           !: inverse of rn_si1
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_chl   ! structure of input Chl (file informations, fields read)
-   INTEGER, PUBLIC ::   nksr              ! levels below which the light cannot penetrate ( depth larger than 391 m)
-   REAL(wp), DIMENSION(3,61) ::   rkrgb   !: tabulated attenuation coefficients for RGB absorption
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: traqsr.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE tra_qsr( kt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE tra_qsr  ***
-      !!
-      !! ** Purpose :   Compute the temperature trend due to the solar radiation
-      !!      penetration and add it to the general temperature trend.
-      !!
-      !! ** Method  : The profile of the solar radiation within the ocean is defined
-      !!      through 2 wavebands (rn_si0,rn_si1) or 3 wavebands (RGB) and a ratio rn_abs
-      !!      Considering the 2 wavebands case:
-      !!         I(k) = Qsr*( rn_abs*EXP(z(k)/rn_si0) + (1.-rn_abs)*EXP(z(k)/rn_si1) )
-      !!         The temperature trend associated with the solar radiation penetration 
-      !!         is given by : zta = 1/e3t dk[ I ] / (rau0*Cp)
-      !!         At the bottom, boudary condition for the radiation is no flux :
-      !!      all heat which has not been absorbed in the above levels is put
-      !!      in the last ocean level.
-      !!         In z-coordinate case, the computation is only done down to the
-      !!      level where I(k) < 1.e-15 W/m2. In addition, the coefficients 
-      !!      used for the computation are calculated one for once as they
-      !!      depends on k only.
-      !!
-      !! ** Action  : - update ta with the penetrative solar radiation trend
-      !!              - save the trend in ttrd ('key_trdtra')
-      !!
-      !! Reference  : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
-      !!              Lengaigne et al. 2007, Clim. Dyn., V28, 5, 503-516.
-      !!----------------------------------------------------------------------
-      !
-      INTEGER, INTENT(in) ::   kt     ! ocean time-step
-      !
-      INTEGER  ::   ji, jj, jk           ! dummy loop indices
-      INTEGER  ::   irgb                 ! local integers
-      REAL(wp) ::   zchl, zcoef, zfact   ! local scalars
-      REAL(wp) ::   zc0, zc1, zc2, zc3   !    -         -
-      REAL(wp) ::   zzc0, zzc1, zzc2, zzc3   !    -         -
-      REAL(wp) ::   zz0, zz1, z1_e3t     !    -         -
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: zekb, zekg, zekr
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: ze0, ze1, ze2, ze3, zea, ztrdt
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_qsr')
-      !
-      CALL wrk_alloc( jpi, jpj,      zekb, zekg, zekr        ) 
-      CALL wrk_alloc( jpi, jpj, jpk, ze0, ze1, ze2, ze3, zea ) 
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'tra_qsr : penetration of the surface solar radiation'
-         IF(lwp) WRITE(numout,*) '~~~~~~~'
-         IF( .NOT.ln_traqsr )   RETURN
-      ENDIF
-
-      IF( l_trdtra ) THEN      ! Save ta and sa trends
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdt ) 
-         ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
-      ENDIF
-
-      !                                        Set before qsr tracer content field
-      !                                        ***********************************
-      IF( kt == nit000 ) THEN                     ! Set the forcing field at nit000 - 1
-         !                                        ! -----------------------------------
-         IF( ln_rstart .AND.    &                    ! Restart: read in restart file
-              & iom_varid( numror, 'qsr_hc_b', ldstop = .FALSE. ) > 0 ) THEN
-            IF(lwp) WRITE(numout,*) '          nit000-1 qsr tracer content forcing field red in the restart file'
-            zfact = 0.5e0
-            CALL iom_get( numror, jpdom_autoglo, 'qsr_hc_b', qsr_hc_b )   ! before heat content trend due to Qsr flux
-         ELSE                                           ! No restart or restart not found: Euler forward time stepping
-            zfact = 1.e0
-            qsr_hc_b(:,:,:) = 0.e0
-         ENDIF
-      ELSE                                        ! Swap of forcing field
-         !                                        ! ---------------------
-         zfact = 0.5e0
-         qsr_hc_b(:,:,:) = qsr_hc(:,:,:)
-      ENDIF
-      !                                        Compute now qsr tracer content field
-      !                                        ************************************
-      
-      !                                           ! ============================================== !
-      IF( lk_qsr_bio .AND. ln_qsr_bio ) THEN      !  bio-model fluxes  : all vertical coordinates  !
-         !                                        ! ============================================== !
-         DO jk = 1, jpkm1
-            qsr_hc(:,:,jk) = ro0cpr * ( etot3(:,:,jk) - etot3(:,:,jk+1) )
-         END DO
-         !                                        Add to the general trend
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1 
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z1_e3t = zfact / fse3t(ji,jj,jk)
-                  tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem) + ( qsr_hc_b(ji,jj,jk) + qsr_hc(ji,jj,jk) ) * z1_e3t
-               END DO
-            END DO
-         END DO
-         CALL iom_put( 'qsr3d', etot3 )   ! Shortwave Radiation 3D distribution
-         ! clem: store attenuation coefficient of the first ocean level
-         IF ( ln_qsr_ice ) THEN
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  IF ( qsr(ji,jj) /= 0._wp ) THEN
-                     oatte(ji,jj) = ( qsr_hc(ji,jj,1) / ( ro0cpr * qsr(ji,jj) ) )
-                     iatte(ji,jj) = oatte(ji,jj)
-                  ENDIF
-               END DO
-            END DO
-         ENDIF
-         !                                        ! ============================================== !
-      ELSE                                        !  Ocean alone : 
-         !                                        ! ============================================== !
-         !
-         !                                                ! ------------------------- !
-         IF( ln_qsr_rgb) THEN                             !  R-G-B  light penetration !
-            !                                             ! ------------------------- !
-            ! Set chlorophyl concentration
-            IF( nn_chldta == 1 .OR. lk_vvl ) THEN            !*  Variable Chlorophyll or ocean volume
-               !
-               IF( nn_chldta == 1 ) THEN                             !*  Variable Chlorophyll
-                  !
-                  CALL fld_read( kt, 1, sf_chl )                         ! Read Chl data and provides it at the current time step
-                  !         
-!CDIR COLLAPSE
-!CDIR NOVERRCHK
-                  DO jj = 1, jpj                                         ! Separation in R-G-B depending of the surface Chl
-!CDIR NOVERRCHK
-                     DO ji = 1, jpi
-                        zchl = MIN( 10. , MAX( 0.03, sf_chl(1)%fnow(ji,jj,1) ) )
-                        irgb = NINT( 41 + 20.*LOG10(zchl) + 1.e-15 )
-                        zekb(ji,jj) = rkrgb(1,irgb)
-                        zekg(ji,jj) = rkrgb(2,irgb)
-                        zekr(ji,jj) = rkrgb(3,irgb)
-                     END DO
-                  END DO
-               ELSE                                            ! Variable ocean volume but constant chrlorophyll
-                  zchl = 0.05                                     ! constant chlorophyll
-                  irgb = NINT( 41 + 20.*LOG10( zchl ) + 1.e-15 )
-                  zekb(:,:) = rkrgb(1,irgb)                       ! Separation in R-G-B depending of the chlorophyll 
-                  zekg(:,:) = rkrgb(2,irgb)
-                  zekr(:,:) = rkrgb(3,irgb)
-               ENDIF
-               !
-               zcoef  = ( 1. - rn_abs ) / 3.e0                        ! equi-partition in R-G-B
-               ze0(:,:,1) = rn_abs  * qsr(:,:)
-               ze1(:,:,1) = zcoef * qsr(:,:)
-               ze2(:,:,1) = zcoef * qsr(:,:)
-               ze3(:,:,1) = zcoef * qsr(:,:)
-               zea(:,:,1) =         qsr(:,:)
-               !
-               DO jk = 2, nksr+1
-!CDIR NOVERRCHK
-                  DO jj = 1, jpj
-!CDIR NOVERRCHK   
-                     DO ji = 1, jpi
-                        zc0 = ze0(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * xsi0r     )
-                        zc1 = ze1(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekb(ji,jj) )
-                        zc2 = ze2(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekg(ji,jj) )
-                        zc3 = ze3(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekr(ji,jj) )
-                        ze0(ji,jj,jk) = zc0
-                        ze1(ji,jj,jk) = zc1
-                        ze2(ji,jj,jk) = zc2
-                        ze3(ji,jj,jk) = zc3
-                        zea(ji,jj,jk) = ( zc0 + zc1 + zc2 + zc3 ) * tmask(ji,jj,jk)
-                     END DO
-                  END DO
-               END DO
-               ! clem: store attenuation coefficient of the first ocean level
-               IF ( ln_qsr_ice ) THEN
-                  DO jj = 1, jpj
-                     DO ji = 1, jpi
-                        zzc0 = rn_abs * EXP( - fse3t(ji,jj,1) * xsi0r     )
-                        zzc1 = zcoef  * EXP( - fse3t(ji,jj,1) * zekb(ji,jj) )
-                        zzc2 = zcoef  * EXP( - fse3t(ji,jj,1) * zekg(ji,jj) )
-                        zzc3 = zcoef  * EXP( - fse3t(ji,jj,1) * zekr(ji,jj) )
-                        oatte(ji,jj) = ( 1.0 - ( zzc0 + zzc1 + zzc2  + zzc3  ) ) * tmask(ji,jj,2) 
-                        iatte(ji,jj) = ( 1.0 - ( zzc0 + zzc1 + zcoef + zcoef ) ) * tmask(ji,jj,2)
-                     END DO
-                  END DO
-               ENDIF
-               !
-               DO jk = 1, nksr                                        ! compute and add qsr trend to ta
-                  qsr_hc(:,:,jk) = ro0cpr * ( zea(:,:,jk) - zea(:,:,jk+1) )
-               END DO
-               zea(:,:,nksr+1:jpk) = 0.e0     ! below 400m set to zero
-               CALL iom_put( 'qsr3d', zea )   ! Shortwave Radiation 3D distribution
-               !
-            ELSE                                                 !*  Constant Chlorophyll
-               DO jk = 1, nksr
-                  qsr_hc(:,:,jk) =  etot3(:,:,jk) * qsr(:,:)
-               END DO
-               ! clem: store attenuation coefficient of the first ocean level
-               IF ( ln_qsr_ice ) THEN
-                  oatte(:,:) = etot3(:,:,1) / ro0cpr
-                  iatte(:,:) = oatte(:,:)
-               ENDIF
-           ENDIF
-
-         ENDIF
-         !                                                ! ------------------------- !
-         IF( ln_qsr_2bd ) THEN                            !  2 band light penetration !
-            !                                             ! ------------------------- !
-            !
-            IF( lk_vvl ) THEN                                  !* variable volume
-               zz0   =        rn_abs   * ro0cpr
-               zz1   = ( 1. - rn_abs ) * ro0cpr
-               DO jk = 1, nksr                    ! solar heat absorbed at T-point in the top 400m 
-                  DO jj = 1, jpj
-                     DO ji = 1, jpi
-                        zc0 = zz0 * EXP( -fsdepw(ji,jj,jk  )*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,jk  )*xsi1r )
-                        zc1 = zz0 * EXP( -fsdepw(ji,jj,jk+1)*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,jk+1)*xsi1r )
-                        qsr_hc(ji,jj,jk) = qsr(ji,jj) * ( zc0*tmask(ji,jj,jk) - zc1*tmask(ji,jj,jk+1) ) 
-                     END DO
-                  END DO
-               END DO
-               ! clem: store attenuation coefficient of the first ocean level
-               IF ( ln_qsr_ice ) THEN
-                  DO jj = 1, jpj
-                     DO ji = 1, jpi
-                        zc0 = zz0 * EXP( -fsdepw(ji,jj,1)*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,1)*xsi1r )
-                        zc1 = zz0 * EXP( -fsdepw(ji,jj,2)*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,2)*xsi1r )
-                        oatte(ji,jj) = ( zc0*tmask(ji,jj,1) - zc1*tmask(ji,jj,2) ) / ro0cpr
-                        iatte(ji,jj) = oatte(ji,jj)
-                     END DO
-                  END DO
-               ENDIF
-            ELSE                                               !* constant volume: coef. computed one for all
-               DO jk = 1, nksr
-                  DO jj = 2, jpjm1
-                     DO ji = fs_2, fs_jpim1   ! vector opt.
-                        qsr_hc(ji,jj,jk) =  etot3(ji,jj,jk) * qsr(ji,jj)
-                     END DO
-                  END DO
-               END DO
-               ! clem: store attenuation coefficient of the first ocean level
-               IF ( ln_qsr_ice ) THEN
-                  oatte(:,:) = etot3(:,:,1) / ro0cpr
-                  iatte(:,:) = oatte(:,:)
-               ENDIF
-               !
-            ENDIF
-            !
-         ENDIF
-         !
-         !                                        Add to the general trend
-         DO jk = 1, nksr
-            DO jj = 2, jpjm1 
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z1_e3t = zfact / fse3t(ji,jj,jk)
-                  tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem) + ( qsr_hc_b(ji,jj,jk) + qsr_hc(ji,jj,jk) ) * z1_e3t
-               END DO
-            END DO
-         END DO
-         !
-      ENDIF
-      ! clem: store attenuation coefficient of the first ocean level
-      !IF (ln_traqsr) THEN
-      !   DO jj = 1, jpj
-      !      DO ji = 1, jpi
-      !         IF ( qsr(ji,jj) /= 0._wp ) THEN
-      !            oatte(ji,jj) = qsr_hc(ji,jj,1) / ( ro0cpr * qsr(ji,jj) )
-      !            iatte(ji,jj) = qsr_hc(ji,jj,1) / ( ro0cpr * qsr(ji,jj) )
-      !         ENDIF
-      !      END DO
-      !   END DO
-      !END IF
-      !
-      IF( lrst_oce ) THEN   !                  Write in the ocean restart file
-         !                                     *******************************
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'qsr tracer content forcing field written in ocean restart file ',   &
-            &                    'at it= ', kt,' date= ', ndastp
-         IF(lwp) WRITE(numout,*) '~~~~'
-         CALL iom_rstput( kt, nitrst, numrow, 'qsr_hc_b', qsr_hc )
-      ENDIF
-
-      IF( l_trdtra ) THEN     ! qsr tracers trends saved for diagnostics
-         ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_qsr, ztrdt )
-         CALL wrk_dealloc( jpi, jpj, jpk, ztrdt ) 
-      ENDIF
-      !                       ! print mean trends (used for debugging)
-      IF(ln_ctl)   CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' qsr  - Ta: ', mask1=tmask, clinfo3='tra-ta' )
-      !
-      CALL wrk_dealloc( jpi, jpj,      zekb, zekg, zekr        ) 
-      CALL wrk_dealloc( jpi, jpj, jpk, ze0, ze1, ze2, ze3, zea ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_qsr')
-      !
-   END SUBROUTINE tra_qsr
-
-
-   SUBROUTINE tra_qsr_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE tra_qsr_init  ***
-      !!
-      !! ** Purpose :   Initialization for the penetrative solar radiation
-      !!
-      !! ** Method  :   The profile of solar radiation within the ocean is set
-      !!      from two length scale of penetration (rn_si0,rn_si1) and a ratio
-      !!      (rn_abs). These parameters are read in the namtra_qsr namelist. The
-      !!      default values correspond to clear water (type I in Jerlov' 
-      !!      (1968) classification.
-      !!         called by tra_qsr at the first timestep (nit000)
-      !!
-      !! ** Action  : - initialize rn_si0, rn_si1 and rn_abs
-      !!
-      !! Reference : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
-      !!----------------------------------------------------------------------
-      !
-      INTEGER  ::   ji, jj, jk     ! dummy loop indices
-      INTEGER  ::   irgb, ierror, ioptio, nqsr   ! local integer
-      REAL(wp) ::   zz0, zc0  , zc1, zcoef       ! local scalars
-      REAL(wp) ::   zz1, zc2  , zc3, zchl        !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: zekb, zekg, zekr
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: ze0, ze1, ze2, ze3, zea
-      !
-      CHARACTER(len=100) ::   cn_dir   ! Root directory for location of ssr files
-      TYPE(FLD_N)        ::   sn_chl   ! informations about the chlorofyl field to be read
-      !!
-      NAMELIST/namtra_qsr/  sn_chl, cn_dir, ln_traqsr, ln_qsr_rgb, ln_qsr_2bd, ln_qsr_bio, ln_qsr_ice,  &
-         &                  nn_chldta, rn_abs, rn_si0, rn_si1
-      !!----------------------------------------------------------------------
-
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_qsr_init')
-      !
-      ! clem init for oatte and iatte
-      oatte(:,:) = 1._wp
-      iatte(:,:) = 1._wp
-      !
-      CALL wrk_alloc( jpi, jpj,      zekb, zekg, zekr        ) 
-      CALL wrk_alloc( jpi, jpj, jpk, ze0, ze1, ze2, ze3, zea ) 
-      !
-      cn_dir = './'       ! directory in which the model is executed
-      ! ... default values (NB: frequency positive => hours, negative => months)
-      !            !     file       ! frequency !  variable  ! time interp !  clim   ! 'yearly' or ! weights  ! rotation   !
-      !            !     name       !  (hours)  !    name    !    (T/F)    !  (T/F)  ! 'monthly'   ! filename ! pairs      !
-      sn_chl = FLD_N( 'chlorophyll' ,    -1     ,  'CHLA'    ,  .true.     , .true.  ,   'yearly'  , ''       , ''         )
-      !
-      REWIND( numnam )            ! Read Namelist namtra_qsr : ratio and length of penetration
-      READ  ( numnam, namtra_qsr )
-      !
-      IF(lwp) THEN                ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'tra_qsr_init : penetration of the surface solar radiation'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist namtra_qsr : set the parameter of penetration'
-         WRITE(numout,*) '      Light penetration (T) or not (F)         ln_traqsr  = ', ln_traqsr
-         WRITE(numout,*) '      RGB (Red-Green-Blue) light penetration   ln_qsr_rgb = ', ln_qsr_rgb
-         WRITE(numout,*) '      2 band               light penetration   ln_qsr_2bd = ', ln_qsr_2bd
-         WRITE(numout,*) '      bio-model            light penetration   ln_qsr_bio = ', ln_qsr_bio
-         WRITE(numout,*) '      light penetration for ice-model LIM3     ln_qsr_ice = ', ln_qsr_ice
-         WRITE(numout,*) '      RGB : Chl data (=1) or cst value (=0)    nn_chldta  = ', nn_chldta
-         WRITE(numout,*) '      RGB & 2 bands: fraction of light (rn_si1)    rn_abs = ', rn_abs
-         WRITE(numout,*) '      RGB & 2 bands: shortess depth of extinction  rn_si0 = ', rn_si0
-         WRITE(numout,*) '      2 bands: longest depth of extinction         rn_si1 = ', rn_si1
-      ENDIF
-
-      IF( ln_traqsr ) THEN     ! control consistency
-         !                      
-         IF( .NOT.lk_qsr_bio .AND. ln_qsr_bio )   THEN
-            CALL ctl_warn( 'No bio model : force ln_qsr_bio = FALSE ' )
-            ln_qsr_bio = .FALSE.
-         ENDIF
-         !
-         ioptio = 0                      ! Parameter control
-         IF( ln_qsr_rgb  )   ioptio = ioptio + 1
-         IF( ln_qsr_2bd  )   ioptio = ioptio + 1
-         IF( ln_qsr_bio  )   ioptio = ioptio + 1
-         !
-         IF( ioptio /= 1 ) &
-            CALL ctl_stop( '          Choose ONE type of light penetration in namelist namtra_qsr',  &
-            &              ' 2 bands, 3 RGB bands or bio-model light penetration' )
-         !
-         IF( ln_qsr_rgb .AND. nn_chldta == 0 )   nqsr =  1 
-         IF( ln_qsr_rgb .AND. nn_chldta == 1 )   nqsr =  2
-         IF( ln_qsr_2bd                      )   nqsr =  3
-         IF( ln_qsr_bio                      )   nqsr =  4
-         !
-         IF(lwp) THEN                   ! Print the choice
-            WRITE(numout,*)
-            IF( nqsr ==  1 )   WRITE(numout,*) '         R-G-B   light penetration - Constant Chlorophyll'
-            IF( nqsr ==  2 )   WRITE(numout,*) '         R-G-B   light penetration - Chl data '
-            IF( nqsr ==  3 )   WRITE(numout,*) '         2 bands light penetration'
-            IF( nqsr ==  4 )   WRITE(numout,*) '         bio-model light penetration'
-         ENDIF
-         !
-      ENDIF
-      !                          ! ===================================== !
-      IF( ln_traqsr  ) THEN      !  Initialisation of Light Penetration  !  
-         !                       ! ===================================== !
-         !
-         xsi0r = 1.e0 / rn_si0
-         xsi1r = 1.e0 / rn_si1
-         !                                ! ---------------------------------- !
-         IF( ln_qsr_rgb ) THEN            !  Red-Green-Blue light penetration  !
-            !                             ! ---------------------------------- !
-            !
-            CALL trc_oce_rgb( rkrgb )           !* tabulated attenuation coef.
-            !
-            !                                   !* level of light extinction
-            IF(  ln_sco ) THEN   ;   nksr = jpkm1
-            ELSE                 ;   nksr = trc_oce_ext_lev( r_si2, 0.33e2 )
-            ENDIF
-
-            IF(lwp) WRITE(numout,*) '        level of light extinction = ', nksr, ' ref depth = ', gdepw_0(nksr+1), ' m'
-            !
-            IF( nn_chldta == 1 ) THEN           !* Chl data : set sf_chl structure
-               IF(lwp) WRITE(numout,*)
-               IF(lwp) WRITE(numout,*) '        Chlorophyll read in a file'
-               ALLOCATE( sf_chl(1), STAT=ierror )
-               IF( ierror > 0 ) THEN
-                  CALL ctl_stop( 'tra_qsr_init: unable to allocate sf_chl structure' )   ;   RETURN
-               ENDIF
-               ALLOCATE( sf_chl(1)%fnow(jpi,jpj,1)   )
-               IF( sn_chl%ln_tint )ALLOCATE( sf_chl(1)%fdta(jpi,jpj,1,2) )
-               !                                        ! fill sf_chl with sn_chl and control print
-               CALL fld_fill( sf_chl, (/ sn_chl /), cn_dir, 'tra_qsr_init',   &
-                  &                                         'Solar penetration function of read chlorophyll', 'namtra_qsr' )
-               !
-            ELSE                                !* constant Chl : compute once for all the distribution of light (etot3)
-               IF(lwp) WRITE(numout,*)
-               IF(lwp) WRITE(numout,*) '        Constant Chlorophyll concentration = 0.05'
-               IF( lk_vvl ) THEN                   ! variable volume
-                  IF(lwp) WRITE(numout,*) '        key_vvl: light distribution will be computed at each time step'
-               ELSE                                ! constant volume: computes one for all
-                  IF(lwp) WRITE(numout,*) '        fixed volume: light distribution computed one for all'
-                  !
-                  zchl = 0.05                                 ! constant chlorophyll
-                  irgb = NINT( 41 + 20.*LOG10(zchl) + 1.e-15 )
-                  zekb(:,:) = rkrgb(1,irgb)                   ! Separation in R-G-B depending of the chlorophyll 
-                  zekg(:,:) = rkrgb(2,irgb)
-                  zekr(:,:) = rkrgb(3,irgb)
-                  !
-                  zcoef = ( 1. - rn_abs ) / 3.e0              ! equi-partition in R-G-B
-                  ze0(:,:,1) = rn_abs
-                  ze1(:,:,1) = zcoef
-                  ze2(:,:,1) = zcoef 
-                  ze3(:,:,1) = zcoef
-                  zea(:,:,1) = tmask(:,:,1)                   ! = ( ze0+ze1+z2+ze3 ) * tmask
-               
-                  DO jk = 2, nksr+1
-!CDIR NOVERRCHK
-                     DO jj = 1, jpj
-!CDIR NOVERRCHK   
-                        DO ji = 1, jpi
-                           zc0 = ze0(ji,jj,jk-1) * EXP( - fse3t_0(ji,jj,jk-1) * xsi0r     )
-                           zc1 = ze1(ji,jj,jk-1) * EXP( - fse3t_0(ji,jj,jk-1) * zekb(ji,jj) )
-                           zc2 = ze2(ji,jj,jk-1) * EXP( - fse3t_0(ji,jj,jk-1) * zekg(ji,jj) )
-                           zc3 = ze3(ji,jj,jk-1) * EXP( - fse3t_0(ji,jj,jk-1) * zekr(ji,jj) )
-                           ze0(ji,jj,jk) = zc0
-                           ze1(ji,jj,jk) = zc1
-                           ze2(ji,jj,jk) = zc2
-                           ze3(ji,jj,jk) = zc3
-                           zea(ji,jj,jk) = ( zc0 + zc1 + zc2 + zc3 ) * tmask(ji,jj,jk)
-                        END DO
-                     END DO
-                  END DO 
-                  !
-                  DO jk = 1, nksr
-                     etot3(:,:,jk) = ro0cpr * ( zea(:,:,jk) - zea(:,:,jk+1) ) 
-                  END DO
-                  etot3(:,:,nksr+1:jpk) = 0.e0                ! below 400m set to zero
-               ENDIF
-            ENDIF
-            !
-         ENDIF
-            !                             ! ---------------------------------- !
-         IF( ln_qsr_2bd ) THEN            !    2 bands    light penetration    !
-            !                             ! ---------------------------------- !
-            !
-            !                                ! level of light extinction
-            nksr = trc_oce_ext_lev( rn_si1, 1.e2 )
-            IF(lwp) THEN
-               WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) '        level of light extinction = ', nksr, ' ref depth = ', gdepw_0(nksr+1), ' m'
-            ENDIF
-            !
-            IF( lk_vvl ) THEN                   ! variable volume
-               IF(lwp) WRITE(numout,*) '        key_vvl: light distribution will be computed at each time step'
-            ELSE                                ! constant volume: computes one for all
-               zz0 =        rn_abs   * ro0cpr
-               zz1 = ( 1. - rn_abs ) * ro0cpr
-               DO jk = 1, nksr                    !*  solar heat absorbed at T-point computed once for all
-                  DO jj = 1, jpj                              ! top 400 meters
-                     DO ji = 1, jpi
-                        zc0 = zz0 * EXP( -fsdepw(ji,jj,jk  )*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,jk  )*xsi1r )
-                        zc1 = zz0 * EXP( -fsdepw(ji,jj,jk+1)*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,jk+1)*xsi1r )
-                        etot3(ji,jj,jk) = (  zc0 * tmask(ji,jj,jk) - zc1 * tmask(ji,jj,jk+1)  ) 
-                     END DO
-                  END DO
-               END DO
-               etot3(:,:,nksr+1:jpk) = 0.e0                   ! below 400m set to zero
-               !
-            ENDIF
-         ENDIF
-         !                       ! ===================================== !
-      ELSE                       !        No light penetration           !                   
-         !                       ! ===================================== !
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) 'tra_qsr_init : NO solar flux penetration'
-            WRITE(numout,*) '~~~~~~~~~~~~'
-         ENDIF
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj,      zekb, zekg, zekr        ) 
-      CALL wrk_dealloc( jpi, jpj, jpk, ze0, ze1, ze2, ze3, zea ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_qsr_init')
-      !
-   END SUBROUTINE tra_qsr_init
-
-   !!======================================================================
-END MODULE traqsr
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/trasbc.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/CONFIG/ORCA2_LIM3/MY_SRC/trasbc.F90	(revision 3937)
+++ 	(revision )
@@ -1,251 +1,0 @@
-MODULE trasbc
-   !!==============================================================================
-   !!                       ***  MODULE  trasbc  ***
-   !! Ocean active tracers:  surface boundary condition
-   !!==============================================================================
-   !! History :  OPA  !  1998-10  (G. Madec, G. Roullet, M. Imbard)  Original code
-   !!            8.2  !  2001-02  (D. Ludicone)  sea ice and free surface
-   !!  NEMO      1.0  !  2002-06  (G. Madec)  F90: Free form and module
-   !!            3.3  !  2010-04  (M. Leclair, G. Madec)  Forcing averaged over 2 time steps
-   !!             -   !  2010-09  (C. Ethe, G. Madec) Merge TRA-TRC
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   tra_sbc      : update the tracer trend at ocean surface
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and active tracers
-   USE sbc_oce         ! surface boundary condition: ocean
-   USE dom_oce         ! ocean space domain variables
-   USE phycst          ! physical constant
-   USE traqsr          ! solar radiation penetration
-   USE trdmod_oce      ! ocean trends 
-   USE trdtra          ! ocean trends
-   USE in_out_manager  ! I/O manager
-   USE prtctl          ! Print control
-   USE restart         ! ocean restart
-   USE sbcrnf          ! River runoff  
-   USE sbcmod          ! ln_rnf  
-   USE iom
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   tra_sbc    ! routine called by step.F90
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: trasbc.F90 3294 2012-01-28 16:44:18Z rblod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE tra_sbc ( kt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE tra_sbc  ***
-      !!                   
-      !! ** Purpose :   Compute the tracer surface boundary condition trend of
-      !!      (flux through the interface, concentration/dilution effect)
-      !!      and add it to the general trend of tracer equations.
-      !!
-      !! ** Method :
-      !!      Following Roullet and Madec (2000), the air-sea flux can be divided 
-      !!      into three effects: (1) Fext, external forcing; 
-      !!      (2) Fwi, concentration/dilution effect due to water exchanged 
-      !!         at the surface by evaporation, precipitations and runoff (E-P-R); 
-      !!      (3) Fwe, tracer carried with the water that is exchanged. 
-      !!
-      !!      Fext, flux through the air-sea interface for temperature and salt: 
-      !!            - temperature : heat flux q (w/m2). If penetrative solar
-      !!         radiation q is only the non solar part of the heat flux, the
-      !!         solar part is added in traqsr.F routine.
-      !!            ta = ta + q /(rau0 rcp e3t)  for k=1
-      !!            - salinity    : no salt flux
-      !!
-      !!      The formulation for Fwb and Fwi vary according to the free 
-      !!      surface formulation (linear or variable volume). 
-      !!      * Linear free surface
-      !!            The surface freshwater flux modifies the ocean volume
-      !!         and thus the concentration of a tracer and the temperature.
-      !!         First order of the effect of surface freshwater exchange 
-      !!         for salinity, it can be neglected on temperature (especially
-      !!         as the temperature of precipitations and runoffs is usually
-      !!         unknown).
-      !!            - temperature : we assume that the temperature of both
-      !!         precipitations and runoffs is equal to the SST, thus there
-      !!         is no additional flux since in this case, the concentration
-      !!         dilution effect is balanced by the net heat flux associated
-      !!         to the freshwater exchange (Fwe+Fwi=0):
-      !!            (Tp P - Te E) + SST (P-E) = 0 when Tp=Te=SST
-      !!            - salinity    : evaporation, precipitation and runoff
-      !!         water has a zero salinity (Fwe=0), thus only Fwi remains:
-      !!            sa = sa + emp * sn / e3t   for k=1
-      !!         where emp, the surface freshwater budget (evaporation minus
-      !!         precipitation minus runoff) given in kg/m2/s is divided
-      !!         by 1035 kg/m3 (density of ocena water) to obtain m/s.    
-      !!         Note: even though Fwe does not appear explicitly for 
-      !!         temperature in this routine, the heat carried by the water
-      !!         exchanged through the surface is part of the total heat flux
-      !!         forcing and must be taken into account in the global heat
-      !!         balance).
-      !!      * nonlinear free surface (variable volume, lk_vvl)
-      !!         contrary to the linear free surface case, Fwi is properly 
-      !!         taken into account by using the true layer thicknesses to       
-      !!         calculate tracer content and advection. There is no need to 
-      !!         deal with it in this routine.
-      !!           - temperature: Fwe=SST (P-E+R) is added to Fext.
-      !!           - salinity:  Fwe = 0, there is no surface flux of salt.
-      !!
-      !! ** Action  : - Update the 1st level of (ta,sa) with the trend associated
-      !!                with the tracer surface boundary condition 
-      !!              - save the trend it in ttrd ('key_trdtra')
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      !!
-      INTEGER  ::   ji, jj, jk, jn           ! dummy loop indices  
-      REAL(wp) ::   zfact, z1_e3t, zsrau, zdep
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdt, ztrds
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_sbc')
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'tra_sbc : TRAcer Surface Boundary Condition'
-         IF(lwp) WRITE(numout,*) '~~~~~~~ '
-      ENDIF
-
-      zsrau = 1. / rau0             ! initialization
-
-      IF( l_trdtra )   THEN                    !* Save ta and sa trends
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds ) 
-         ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
-         ztrds(:,:,:) = tsa(:,:,:,jp_sal)
-      ENDIF
-
-!!gm      IF( .NOT.ln_traqsr )   qsr(:,:) = 0.e0   ! no solar radiation penetration
-      IF( .NOT.ln_traqsr ) THEN     ! no solar radiation penetration
-         qns(:,:) = qns(:,:) + qsr(:,:)      ! total heat flux in qns
-         qsr(:,:) = 0.e0                     ! qsr set to zero
-      ENDIF
-
-      !----------------------------------------
-      !        EMP, EMPS and QNS effects
-      !----------------------------------------
-      !                                          Set before sbc tracer content fields
-      !                                          ************************************
-      IF( kt == nit000 ) THEN                      ! Set the forcing field at nit000 - 1
-         !                                         ! -----------------------------------
-         IF( ln_rstart .AND.    &                     ! Restart: read in restart file
-              & iom_varid( numror, 'sbc_hc_b', ldstop = .FALSE. ) > 0 ) THEN
-            IF(lwp) WRITE(numout,*) '          nit000-1 surface tracer content forcing fields red in the restart file'
-            zfact = 0.5e0
-            CALL iom_get( numror, jpdom_autoglo, 'sbc_hc_b', sbc_tsc_b(:,:,jp_tem) )   ! before heat content sbc trend
-            CALL iom_get( numror, jpdom_autoglo, 'sbc_sc_b', sbc_tsc_b(:,:,jp_sal) )   ! before salt content sbc trend
-         ELSE                                         ! No restart or restart not found: Euler forward time stepping
-            zfact = 1.e0
-            sbc_tsc_b(:,:,:) = 0.e0
-         ENDIF
-      ELSE                                         ! Swap of forcing fields
-         !                                         ! ----------------------
-         zfact = 0.5e0
-         sbc_tsc_b(:,:,:) = sbc_tsc(:,:,:)
-      ENDIF
-      !                                          Compute now sbc tracer content fields
-      !                                          *************************************
-
-                                                   ! Concentration dilution effect on (t,s) due to  
-                                                   ! evaporation, precipitation and qns, but not river runoff 
-                                               
-      IF( lk_vvl ) THEN                            ! Variable Volume case
-         DO jj = 1, jpj
-            DO ji = 1, jpi 
-               ! temperature : heat flux + cooling/heating effet of EMP flux
-               sbc_tsc(ji,jj,jp_tem) = ro0cpr * qns(ji,jj) - zsrau * emp(ji,jj) * tsn(ji,jj,1,jp_tem)
-               ! concent./dilut. effect due to sea-ice melt/formation and (possibly) SSS restoration
-               !sbc_tsc(ji,jj,jp_sal) = ( emps(ji,jj) - emp(ji,jj) ) * zsrau * tsn(ji,jj,1,jp_sal)
-               sbc_tsc(ji,jj,jp_sal) = emps(ji,jj) * zsrau  ! IOVINO + CLEM
-            END DO
-         END DO
-      ELSE                                         ! Constant Volume case
-         DO jj = 2, jpj
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ! temperature : heat flux
-               sbc_tsc(ji,jj,jp_tem) = ro0cpr * qns(ji,jj)
-               ! salinity    : salt flux + concent./dilut. effect (both in emps)
-#if defined key_lim3
-               sbc_tsc(ji,jj,jp_sal) = zsrau * emps(ji,jj) + zsrau * emp(ji,jj) * tsn(ji,jj,1,jp_sal) ! IOVINO
-#else
-               sbc_tsc(ji,jj,jp_sal) = zsrau * emps(ji,jj) * tsn(ji,jj,1,jp_sal) ! regular expression
-#endif
-            END DO
-         END DO
-      ENDIF
-      ! Concentration dilution effect on (t,s) due to evapouration, precipitation and qns, but not river runoff  
-      DO jn = 1, jpts
-         DO jj = 2, jpj
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               z1_e3t = zfact / fse3t(ji,jj,1)
-               tsa(ji,jj,1,jn) = tsa(ji,jj,1,jn) + ( sbc_tsc_b(ji,jj,jn) + sbc_tsc(ji,jj,jn) ) * z1_e3t
-            END DO
-         END DO
-      END DO
-      !                                          Write in the ocean restart file
-      !                                          *******************************
-      IF( lrst_oce ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'sbc : ocean surface tracer content forcing fields written in ocean restart file ',   &
-            &                    'at it= ', kt,' date= ', ndastp
-         IF(lwp) WRITE(numout,*) '~~~~'
-         CALL iom_rstput( kt, nitrst, numrow, 'sbc_hc_b', sbc_tsc(:,:,jp_tem) )
-         CALL iom_rstput( kt, nitrst, numrow, 'sbc_sc_b', sbc_tsc(:,:,jp_sal) )
-      ENDIF
-      !
-      !----------------------------------------
-      !        River Runoff effects
-      !----------------------------------------
-      !
-      zfact = 0.5e0
-
-      ! Effect on (t,s) due to river runoff (dilution effect automatically applied via vertical tracer advection) 
-      IF( ln_rnf ) THEN  
-         DO jj = 2, jpj 
-            DO ji = fs_2, fs_jpim1
-               zdep = 1. / h_rnf(ji,jj)
-               zdep = zfact * zdep  
-               IF ( rnf(ji,jj) /= 0._wp ) THEN
-                  DO jk = 1, nk_rnf(ji,jj)
-                                        tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem)   &
-                                          &               +  ( rnf_tsc_b(ji,jj,jp_tem) + rnf_tsc(ji,jj,jp_tem) ) * zdep
-                     IF( ln_rnf_sal )   tsa(ji,jj,jk,jp_sal) = tsa(ji,jj,jk,jp_sal)   &
-                                          &               +  ( rnf_tsc_b(ji,jj,jp_sal) + rnf_tsc(ji,jj,jp_sal) ) * zdep 
-                  END DO
-               ENDIF
-            END DO  
-         END DO  
-      ENDIF  
-!!gm  It should be useless
-      CALL lbc_lnk( tsa(:,:,:,jp_tem), 'T', 1. )    ;    CALL lbc_lnk( tsa(:,:,:,jp_sal), 'T', 1. )
-
-      IF( l_trdtra )   THEN                      ! save the horizontal diffusive trends for further diagnostics
-         ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
-         ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_nsr, ztrdt )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_nsr, ztrds )
-         CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds ) 
-      ENDIF
-      !
-      IF(ln_ctl)   CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' sbc  - Ta: ', mask1=tmask,   &
-         &                       tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_sbc')
-      !
-   END SUBROUTINE tra_sbc
-
-   !!======================================================================
-END MODULE trasbc
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/ice.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/ice.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/ice.F90	(revision 3938)
@@ -187,4 +187,5 @@
    REAL(wp), PUBLIC ::   alphaevp = 1._wp      !: coeficient of the internal stresses !SB
    REAL(wp), PUBLIC ::   unit_fac = 1.e+09_wp  !: conversion factor for ice / snow enthalpy
+   REAL(wp), PUBLIC ::   hminrhg = 0.05_wp     !: clem : ice thickness (in m) below which ice velocity is set to ocean velocity
 
    !                                              !!** ice-salinity namelist (namicesal) **
@@ -393,14 +394,13 @@
    LOGICAL               , PUBLIC ::   ln_limdyn     = .TRUE.             !: flag for ice dynamics (T) or not (F)
    LOGICAL               , PUBLIC ::   ln_nicep      = .TRUE.             !: flag for sea-ice points output (T) or not (F)
-   REAL(wp)              , PUBLIC ::   hsndif        = 0.e0               !: computation of temp. in snow (0) or not (9999)
-   REAL(wp)              , PUBLIC ::   hicdif        = 0.e0               !: computation of temp. in ice (0) or not (9999)
    REAL(wp)              , PUBLIC ::   cai           = 1.40e-3            !: atmospheric drag over sea ice
    REAL(wp)              , PUBLIC ::   cao           = 1.00e-3            !: atmospheric drag over ocean
-   REAL(wp), DIMENSION(2), PUBLIC ::   acrit  = (/ 1.e-06 , 1.e-06 /)     !: minimum fraction for leads in
-   !                                                                      !: north and south hemisphere
+   REAL(wp)              , PUBLIC ::   amax          = 0.99               !: maximum ice concentration
+   !                                                                      !
    !!--------------------------------------------------------------------------
    !! * Ice diagnostics
    !!--------------------------------------------------------------------------
    !! Check if everything down here is necessary
+   LOGICAL , PUBLIC                                      ::   ln_limdiahsb  = .TRUE. !: flag for ice diag (T) or not (F)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   v_newice   !: volume of ice formed in the leads
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dv_dt_thd  !: thermodynamic growth rates 
@@ -412,4 +412,6 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_bot_me   ! vertical bottom melt 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_sur_me   ! vertical surface melt
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_res_pr   ! production (growth+melt) due to limupdate
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_trp_vi   ! transport of ice volume
    INTEGER , PUBLIC ::   jiindx, jjindx        !: indexes of the debugging point
 
@@ -460,5 +462,5 @@
 
       ii = ii + 1
-      ALLOCATE( patho_case(jpi, jpj, jpl)  , STAT=ierr(ii) )
+      ALLOCATE( patho_case(jpi,jpj,jpl) , STAT=ierr(ii) )
 
       ! * Ice global state variables
@@ -524,5 +526,5 @@
          &      izero    (jpi,jpj,jpl) , diag_bot_gr(jpi,jpj) , diag_dyn_gr(jpi,jpj) ,     &
          &      fstroc   (jpi,jpj,jpl) , diag_bot_me(jpi,jpj) , diag_sur_me(jpi,jpj) ,     &
-         &      fhbricat (jpi,jpj,jpl) , v_newice   (jpi,jpj)                        , STAT=ierr(ii) )
+         &      fhbricat (jpi,jpj,jpl) , diag_res_pr(jpi,jpj) , diag_trp_vi(jpi,jpj) , v_newice(jpi,jpj) , STAT=ierr(ii) )
 
       ice_alloc = MAXVAL( ierr(:) )
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/iceini.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/iceini.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/iceini.F90	(revision 3938)
@@ -124,5 +124,5 @@
       !! ** input   :   Namelist namicerun
       !!-------------------------------------------------------------------
-      NAMELIST/namicerun/ cn_icerst_in, cn_icerst_out, ln_limdyn, acrit, hsndif, hicdif, cai, cao, ln_nicep
+      NAMELIST/namicerun/ cn_icerst_in, cn_icerst_out, ln_limdyn, amax, cai, cao, ln_nicep, ln_limdiahsb
       !!-------------------------------------------------------------------
       !                    
@@ -140,10 +140,9 @@
          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,*) '   maximum ice concentration                               = ', amax 
          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
+         WRITE(numout,*) '   Diagnose heat/salt budget or not          ln_limdiahsb  = ', ln_limdiahsb
       ENDIF
       !
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limadv.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limadv.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limadv.F90	(revision 3938)
@@ -23,4 +23,5 @@
    USE lib_mpp          ! MPP library
    USE wrk_nemo         ! work arrays
+   USE lib_fortran      ! to use key_nosignedzero
 
    IMPLICIT NONE
@@ -88,5 +89,5 @@
             zs2new  = MIN(  2.0 * zslpmax - 0.3334 * ABS( zs1new ),      &
                &            MAX( ABS( zs1new ) - zslpmax, psxx(ji,jj) )  )
-            zin0    = ( 1.0 - MAX( rzero, sign ( rone, -zslpmax) ) ) * tms(ji,jj)   ! Case of empty boxes & Apply mask
+            zin0    = ( 1.0 - MAX( rzero, SIGN ( rone, -zslpmax ) ) ) * tms(ji,jj)   ! Case of empty boxes & Apply mask
 
             ps0 (ji,jj) = zslpmax  
@@ -273,5 +274,5 @@
             zs2new  = MIN(  ( 2.0 * zslpmax - 0.3334 * ABS( zs1new ) ),   &
                &             MAX( ABS( zs1new )-zslpmax, psyy(ji,jj) )  )
-            zin0    = ( 1.0 - MAX( rzero, sign ( rone, -zslpmax) ) ) * tms(ji,jj)   ! Case of empty boxes & Apply mask
+            zin0    = ( 1.0 - MAX( rzero, SIGN ( rone, -zslpmax ) ) ) * tms(ji,jj)   ! Case of empty boxes & Apply mask
             !
             ps0 (ji,jj) = zslpmax  
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limdia.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limdia.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limdia.F90	(revision 3938)
@@ -23,4 +23,5 @@
    USE in_out_manager  ! I/O manager
    USE lib_mpp         ! MPP library
+   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
    
    IMPLICIT NONE
@@ -43,4 +44,5 @@
    INTEGER  ::   naveg               ! number of step for accumulation before averaging
    REAL(wp) ::   epsi06 = 1.e-6_wp   ! small number
+   REAL(wp) ::   epsi20 = 1.e-20_wp  ! small number
 
    CHARACTER(len= 8) ::   fmtinf = '1PE13.5 '   ! format of the output values  
@@ -70,14 +72,16 @@
       !!              the temporal evolution of some key variables
       !!-------------------------------------------------------------------
-      INTEGER  ::   jv, ji, jj, jl   ! dummy loop indices
-      REAL(wp) ::   zshift_date      ! date from the minimum ice extent
-      REAL(wp) ::   zday, zday_min   ! current day, day of minimum extent
-      REAL(wp) ::   zafy, zamy       ! temporary area of fy and my ice
+      INTEGER  ::   jv, ji, jj, jl       ! dummy loop indices
+      INTEGER  ::   ii0, ii1, ij0, ij1   ! temporary integer
+      REAL(wp) ::   zshift_date          ! date from the minimum ice extent
+      REAL(wp) ::   zday, zday_min       ! current day, day of minimum extent
+      REAL(wp) ::   zafy, zamy           ! temporary area of fy and my ice
       REAL(wp) ::   zindb
-      REAL(wp), DIMENSION(jpinfmx) ::   vinfor           ! temporary working space 
+      REAL(wp), DIMENSION(jpinfmx) ::   vinfor   ! 1D workspace 
       !!-------------------------------------------------------------------
 
       ! 0) date from the minimum of ice extent
       !---------------------------------------
+      !RETURN ! use this for debugging
       zday_min = 273._wp        ! zday_min = date of minimum extent, here September 30th
       zday = REAL(numit-nit000,wp) * rdt_ice / ( 86400._wp * REAL(nn_fsbc,wp) )
@@ -112,5 +116,5 @@
                ! 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 
+                  v_ice(ji,jj)*v_ice(ji,jj) )*aire(ji,jj) * 1.e-12 
                vinfor(53) = vinfor(53) + emps(ji,jj)*aire(ji,jj) * 1.e-12_wp !salt flux
                vinfor(55) = vinfor(55) + fsbri(ji,jj)*aire(ji,jj) * 1.e-12_wp !brine drainage flux
@@ -153,9 +157,9 @@
       vinfor(79) = vinfor(79) / MAX(vinfor(5),epsi06) !
 
-      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(3))) !
+      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(3)+epsi20)) !
       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))) !
+      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(9)+epsi20)) !
       vinfor(65) = zindb*vinfor(65) / MAX(vinfor(9),epsi06) ! divide it by snow volume
 
@@ -226,23 +230,25 @@
          END DO
       END DO
-      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(25))) !=0 if no multiyear ice 1 if yes
+      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(25)+epsi20)) !=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
+      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(27)+epsi20)) !=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.e-12_wp
-         vinfor(84) = vinfor(84) - v_ice(ji,jj) * & 
-            e1t(ji,jj)*vt_i(ji,jj)*rdt_ice * 1.e-12_wp
-      END DO
+      IF( cp_cfg == "orca" ) THEN   !* ORCA configuration : Fram Strait Export
+         SELECT CASE ( jp_cfg )
+         CASE ( 2 )                          ! ORCA_R2
+            ij0 = 136   ;   ij1 = 136              ! Fram strait : 83 = area export
+            ii0 = 134   ;   ii1 = 138              !               84 = volume export
+            DO jj = mj0(ij0),mj1(ij1)
+               DO ji = mi0(ii0),mi1(ii1)
+                  vinfor(83) = vinfor(83) - v_ice(ji,jj) * e1t(ji,jj)*at_i(ji,jj)*rdt_ice * 1.e-12_wp
+                  vinfor(84) = vinfor(84) - v_ice(ji,jj) * e1t(ji,jj)*vt_i(ji,jj)*rdt_ice * 1.e-12_wp
+               END DO
+            END DO
+         END SELECT
+!!gm   just above, this is NOT the correct way of evaluating the transport !
+!!gm        mass of snow is missing and v_ice should be the mean between jj and jj+1
+!!gm   Other ORCA configurations should be added
+      ENDIF
 
       !!-------------------------------------------------------------------
@@ -264,7 +270,9 @@
                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
+!!gm  error??  multiplication by at_i seem wrong here....
                vinfor(54) = vinfor(54) + at_i(ji,jj)*emps(ji,jj)*aire(ji,jj) * 1.e-12_wp ! Total salt flux
                vinfor(56) = vinfor(56) + at_i(ji,jj)*fsbri(ji,jj)*aire(ji,jj) * 1.e-12_wp ! Brine drainage salt flux
                vinfor(58) = vinfor(58) + at_i(ji,jj)*fseqv(ji,jj)*aire(ji,jj) * 1.e-12_wp ! Equivalent salt flux
+!!gm end
                vinfor(60) = vinfor(60) +(sst_m(ji,jj)+rt0)*at_i(ji,jj)*aire(ji,jj) * 1.e-12_wp  !SST
                vinfor(62) = vinfor(62) + sss_m(ji,jj)*at_i(ji,jj)*aire(ji,jj) * 1.e-12_wp  !SSS
@@ -292,5 +300,5 @@
       vinfor(14) = 0.0
 
-      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(8))) 
+      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(8)+epsi20)) 
       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) ! 
@@ -298,5 +306,5 @@
       vinfor(68) = zindb * vinfor(68) / MAX(vinfor(8),epsi06) ! 
 
-      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(6))) 
+      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(6)+epsi20)) 
       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) ! 
@@ -305,9 +313,9 @@
       !      vinfor(84) = vinfor(84) / vinfor(6) !
 
-      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(4))) !
+      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(4)+epsi20)) !
       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))) !
+      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(10)+epsi20)) !
       vinfor(66) = zindb*vinfor(66) / MAX(vinfor(10),epsi06) ! divide it by snow volume
 
@@ -345,5 +353,5 @@
          END DO
       END DO
-      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(4))) !
+      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(4)+epsi20)) !
       vinfor(64) = zindb * vinfor(64) / MAX(vinfor(4),epsi06) ! divide by ice extt
       !! 2.2) Diagnostics dependent on age
@@ -377,7 +385,7 @@
          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
+      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(26)+epsi20)) !=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
+      zindb      = 1.0 - MAX(0.0,SIGN(1.0,-vinfor(28)+epsi20)) !=0 if no multiyear ice 1 if yes
       vinfor(52) = zindb*vinfor(52) / MAX(vinfor(28),epsi06)
 
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90	(revision 3938)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90	(revision 3938)
@@ -0,0 +1,229 @@
+MODULE limdiahsb
+   !!======================================================================
+   !!                       ***  MODULE limdia_hsb   ***
+   !!  LIM-3 sea ice model :   diagnostics of ice model 
+   !!======================================================================
+   !! History :  3.4  ! 2012-10  (C. Rousset)  original code
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_dia_hsb        : computation and output of the time evolution of keys variables
+   !!   lim_dia_hsb_init   : initialization and namelist read
+   !!----------------------------------------------------------------------
+   USE ice             ! LIM-3: sea-ice variable
+   USE par_ice         ! LIM-3: ice parameters
+   USE dom_ice         ! LIM-3: sea-ice domain
+   USE dom_oce         ! ocean domain
+   USE sbc_oce         ! surface boundary condition: ocean fields
+   USE daymod          ! model calendar
+   USE phycst          ! physical constant
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! MPP library
+   USE timing          ! preformance summary
+   USE iom             ! I/O manager
+   USE lib_fortran     ! glob_sum
+   USE limrst          ! ice restart
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   lim_diahsb        ! routine called by ice_step.F90
+   !!PUBLIC   lim_diahsb_init   ! routine called by ice_init.F90
+   !!PUBLIC   lim_diahsb_rst   ! routine called by ice_init.F90
+
+   REAL(wp), SAVE   ::   frc_sal, frc_vol   ! global forcing trends
+   REAL(wp), SAVE   ::   bg_grpme           ! global ice growth+melt trends
+   REAL(wp) ::   epsi06 = 1.e-6_wp  ! small number
+   REAL(wp) ::   epsi03 = 1.e-3_wp  ! small number
+
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.4 , NEMO Consortium (2012)
+   !! $Id: limdiahsb.F90 3294 2012-10-18 16:44:18Z rblod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_diahsb
+      !!---------------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_diahsb  ***
+      !!     
+      !! ** Purpose: Compute the ice global heat content, salt content and volume conservation
+      !!	
+      !! ** Method : - Compute the deviation of heat content, salt content and volume
+      !!	            at the current time step from their values at nit000
+      !!	            - Compute the contribution of forcing and remove it from these deviations
+      !!
+      !!---------------------------------------------------------------------------
+      !!
+      REAL(wp)   ::   zbg_ivo, zbg_svo, zbg_are, zbg_sal ,zbg_tem ,zbg_ihc ,zbg_shc
+      REAL(wp)   ::   zbg_emps, zbg_emp, zbg_fsbri, zbg_fseqv, zbg_fsalt_res, zbg_fsalt_rpo 
+      REAL(wp)   ::   z_frc_vol, z_frc_sal, z_bg_grpme 
+      REAL(wp)   ::   zdeltat, z1_area                     !    -     -
+      !!---------------------------------------------------------------------------
+      IF( nn_timing == 1 )   CALL timing_start('lim_diahsb')
+
+      IF( numit == nstart ) CALL lim_diahsb_init 
+
+      ! 1/area
+      z1_area = 1.0 / MAX( glob_sum( area(:,:) * tms(:,:) ),epsi06 )
+      ! ----------------------- !
+      ! 1 -  Content variations !
+      ! ----------------------- !
+      zbg_ivo = glob_sum( vt_i(:,:) * area(:,:) * tms(:,:) ) ! volume ice 
+      zbg_svo = glob_sum( vt_s(:,:) * area(:,:) * tms(:,:) ) ! volume snow
+      zbg_are = glob_sum( at_i(:,:) * area(:,:) * tms(:,:) ) ! area
+      zbg_sal = glob_sum( SUM(smv_i(:,:,:),dim=3) * area(:,:) * tms(:,:) ) ! mean salt content
+      zbg_tem = glob_sum( (tm_i(:,:)-rtt) * vt_i(:,:) * area(:,:) * tms(:,:) )  ! mean temp content
+
+      !zbg_ihc = glob_sum( et_i(:,:) * area(:,:) * tms(:,:) ) / MAX( zbg_ivo,epsi06 ) ! ice heat content
+      !zbg_shc = glob_sum( et_s(:,:) * area(:,:) * tms(:,:) ) / MAX( zbg_svo,epsi06 ) ! snow heat content
+
+      zbg_ihc = glob_sum( et_i(:,:) ) ! ice heat content  [10^9 J]
+      zbg_shc = glob_sum( et_s(:,:) ) ! snow heat content [10^9 J]
+
+      zbg_emps      = glob_sum(      emps(:,:) * area(:,:) * tms(:,:) ) * z1_area
+      zbg_emp       = glob_sum(       emp(:,:) * area(:,:) * tms(:,:) ) * z1_area
+      zbg_fsbri     = glob_sum(     fsbri(:,:) * area(:,:) * tms(:,:) ) * z1_area
+      zbg_fseqv     = glob_sum(     fseqv(:,:) * area(:,:) * tms(:,:) ) * z1_area
+      zbg_fsalt_res = glob_sum( fsalt_res(:,:) * area(:,:) * tms(:,:) ) * z1_area
+      zbg_fsalt_rpo = glob_sum( fsalt_rpo(:,:) * area(:,:) * tms(:,:) ) * z1_area
+      
+      ! --------------------------------------------- !
+      ! 2 - Trends due to forcing and ice growth/melt !
+      ! --------------------------------------------- !
+      z_frc_vol = ( 1.e0 / rau0 ) * glob_sum( - emp(:,:) * area(:,:) * tms(:,:) ) ! volume fluxes
+      z_frc_sal = ( 1.e0 / rau0 ) * glob_sum(  emps(:,:) * area(:,:) * tms(:,:) ) ! salt fluxes
+      z_bg_grpme = glob_sum( ( diag_bot_gr(:,:) + diag_lat_gr(:,:) + diag_sni_gr(:,:) + diag_dyn_gr(:,:) + &
+                          &    diag_bot_me(:,:) + diag_sur_me(:,:) + diag_res_pr(:,:) ) * area(:,:) * tms(:,:) ) ! volume fluxes
+      !
+      frc_vol  = frc_vol  + z_frc_vol  * rdt_ice
+      frc_sal  = frc_sal  + z_frc_sal  * rdt_ice
+      bg_grpme = bg_grpme + z_bg_grpme * rdt_ice
+      
+      ! difference
+      !frc_vol = zbg_ivo - frc_vol
+      !frc_sal = zbg_sal - frc_sal
+      
+      ! ----------------------- !
+      ! 3 - Diagnostics writing !
+      ! ----------------------- !
+      !zdeltat  = 1.e0 / ( ( kt - nit000 + 1 ) * rdt_ice )
+      !
+      CALL iom_put( 'ibgvoltot',zbg_ivo * rhoic / rau0 * 1.e-9 ) ! m3 (equivalent liquid)         
+      CALL iom_put( 'sbgvoltot',zbg_svo * rhosn / rau0 * 1.e-9 )  ! m3 (equivalent liquid)       
+      CALL iom_put( 'ibgarea',zbg_are * 1.e-6 )         
+      CALL iom_put( 'ibgsaline',zbg_sal / MAX( zbg_ivo,epsi03 ) )         
+      CALL iom_put( 'ibgtemper',zbg_tem / MAX( zbg_ivo,epsi03 ) )         
+      CALL iom_put( 'ibgheatco',zbg_ihc )           ! 10^9 J        
+      CALL iom_put( 'ibgsaltco',zbg_sal * rhoic / rau0 * 1.e-9 ) ! psu*km3        
+      CALL iom_put( 'sbgheatco',zbg_shc )           ! 10^9 J
+      CALL iom_put( 'ibgfrcemp',frc_vol * 1.e-9 )           !vol - forcing : km3 (equivalent liquid)         
+      CALL iom_put( 'ibgfrcemps',frc_sal * 1.e-9 )          !sal - forcing : psu*km3   
+      CALL iom_put( 'ibgemps',zbg_emps *86400)            
+      CALL iom_put( 'ibgemp',zbg_emp *86400)              
+      CALL iom_put( 'ibgfsbri',zbg_fsbri *86400)         
+      CALL iom_put( 'ibgfseqv',zbg_fseqv *86400)         
+      CALL iom_put( 'ibgfsaltres',zbg_fsalt_res *86400)         
+      CALL iom_put( 'ibgfsaltrpo',zbg_fsalt_rpo *86400)         
+      CALL iom_put( 'ibggrpme',bg_grpme * rhoic / rau0 * 1.e-9 ) ! km3 (equivalent liquid)         
+      !
+      IF( lrst_ice )   CALL lim_diahsb_rst( numit, 'WRITE' )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('lim_diahsb')
+!
+   END SUBROUTINE lim_diahsb
+
+
+   SUBROUTINE lim_diahsb_init
+      !!---------------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_diahsb_init  ***
+      !!     
+      !! ** Purpose: Initialization for the heat salt volume budgets
+      !!	
+      !! ** Method : Compute initial heat content, salt content and volume
+      !!
+      !! ** Action : - Compute initial heat content, salt content and volume
+      !!             - Initialize forcing trends
+      !!             - Compute coefficients for conversion
+      !!---------------------------------------------------------------------------
+      INTEGER            ::   jk       ! dummy loop indice
+      INTEGER            ::   ierror   ! local integer
+      !!
+      !!NAMELIST/namicehsb/ blabla
+      !!----------------------------------------------------------------------
+      !
+      !!REWIND ( numnam_ice )              ! Read Namelist namicehsb 
+      !!READ   ( numnam_ice, namicehsb )
+      !
+      IF(lwp) THEN                   ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_diahsb_init : check the heat and salt budgets'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+      ENDIF
+
+      ! ---------------------------------- !
+      ! 2 - initial conservation variables !
+      ! ---------------------------------- !
+      !frc_vol = 0._wp                                           ! volume       trend due to forcing
+      !frc_sal = 0._wp                                           ! salt content   -    -   -    -         
+      !bg_grpme = 0._wp                                          ! ice growth + melt volume trend
+      !
+      CALL lim_diahsb_rst( nstart, 'READ' )  !* read or initialize all required files
+      !
+   END SUBROUTINE lim_diahsb_init
+
+   SUBROUTINE lim_diahsb_rst( kt, cdrw )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE limdia_rst  ***
+     !!                     
+     !! ** Purpose :   Read or write DIA file in restart file
+     !!
+     !! ** Method  :   use of IOM library
+     !!----------------------------------------------------------------------
+     INTEGER         , INTENT(in) ::   kt     ! ice time-step
+     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
+     !
+     INTEGER ::   id1, id2, id3   ! local integers
+     !!----------------------------------------------------------------------
+     !
+     IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
+        IF( ln_rstart ) THEN                   !* Read the restart file
+           id1 = iom_varid( numrir, 'frc_vol'  , ldstop = .TRUE. )
+           !
+           CALL iom_get( numrir, 'frc_vol', frc_vol )
+           CALL iom_get( numrir, 'frc_sal', frc_sal )
+           CALL iom_get( numrir, 'bg_grpme', bg_grpme )
+       ELSE
+       	   frc_vol = 0._wp                                           
+       	   frc_sal = 0._wp                                                  
+      	   bg_grpme = 0._wp                                        
+       ENDIF	
+
+     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
+        !                                   ! -------------------
+        IF(lwp) WRITE(numout,*) '---- limdia-rst ----'
+        CALL iom_rstput( kt, nitrst, numriw, 'frc_vol'   , frc_vol     )
+        CALL iom_rstput( kt, nitrst, numriw, 'frc_sal'   , frc_sal     )
+        CALL iom_rstput( kt, nitrst, numriw, 'bg_grpme'  , bg_grpme     )
+        !
+     ENDIF
+     !
+   END SUBROUTINE lim_diahsb_rst
+ 
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :         Empty module          NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_diahsb          ! Empty routine
+   END SUBROUTINE lim_diahsb
+#endif
+   !!======================================================================
+END MODULE limdiahsb
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limdyn.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limdyn.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limdyn.F90	(revision 3938)
@@ -28,4 +28,5 @@
    USE in_out_manager   ! I/O manager
    USE prtctl           ! Print control
+   USE lib_fortran      ! glob_sum
 
    IMPLICIT NONE
@@ -64,8 +65,20 @@
       REAL(wp), POINTER, DIMENSION(:)   ::   zmsk           ! i-averaged of tmask
       REAL(wp), POINTER, DIMENSION(:,:) ::   zu_io, zv_io   ! ice-ocean velocity
-      !!---------------------------------------------------------------------
+      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
+     !!---------------------------------------------------------------------
 
       CALL wrk_alloc( jpi, jpj, zu_io, zv_io )
       CALL wrk_alloc( jpj, zind, zmsk )
+
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
+         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
+      ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
 
       IF( kt == nit000 )   CALL lim_dyn_init   ! Initialization (first time-step only)
@@ -207,4 +220,39 @@
       ENDIF
       !
+
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         !INTEGER                                 ::   numhsb 
+         !CHARACTER (len=32) ::   cl_name  ! output file name
+         !cl_name    = 'heat_salt_volume_budgets.txt'                         ! name of output file
+
+         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
+         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
+ 
+         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
+         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
+
+         IF(lwp) THEN
+            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limdyn) = ',(zchk_v_i * 86400.)
+            IF (    ABS( zchk_smv   ) >  1.e-4  ) WRITE(numout,*) 'violation saline [psu*m3/day] (limdyn) = ',(zchk_smv * 86400.)
+            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limdyn) = ',(MINVAL(v_i) * 1.e-3)
+            IF ( MAXVAL( SUM(a_i(:,:,:),dim=3) ) > amax+1.e-10 ) WRITE(numout,*) 'violation a_i>amax    (limdyn) = ',MAXVAL(SUM(a_i,dim=3))
+         ENDIF
+         !CALL ctl_opn( numhsb , cl_name , 'UNKNOWN' , 'FORMATTED' , 'SEQUENTIAL' , 1 , numout , lwp , 1 )
+         !
+         !WRITE( numhsb, 9010 ) "kt   |     heat content budget     |            salt content budget             ",   &
+         !     &                                                  "|            volume budget (ssh)             ",   &
+         !     &                                                  "|            volume budget (e3t)             "
+         !WRITE( numhsb, 9010 ) "     |      [C]         [W/m2]     |     [psu]        [mmm/s]          [SV]     ",   &
+         !     &                                                  "|     [m3]         [mmm/s]          [SV]     ",   &
+         !     &                                                  "|     [m3]         [mmm/s]          [SV]     "
+         !IF ( kt == nitend ) CLOSE( numhsb )
+         
+!9010     FORMAT(A80,A45,A45)
+      ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
+
       CALL wrk_dealloc( jpi, jpj, zu_io, zv_io )
       CALL wrk_dealloc( jpj, zind, zmsk )
@@ -228,5 +276,5 @@
          &                dm, nbiter, nbitdr, om, resl, cw, angvg, pstar,   &
          &                c_rhg, etamn, creepl, ecc, ahi0, &
-         &                nevp, telast, alphaevp
+         &                nevp, telast, alphaevp, hminrhg
       !!-------------------------------------------------------------------
 
@@ -256,4 +304,5 @@
          WRITE(numout,*) '   timescale for elastic waves                      telast = ', telast
          WRITE(numout,*) '   coefficient for the solution of int. stresses  alphaevp = ', alphaevp
+         WRITE(numout,*) '   min ice thickness for rheology calculations     hminrhg = ', hminrhg
       ENDIF
       !
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limhdf.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limhdf.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limhdf.F90	(revision 3938)
@@ -136,4 +136,24 @@
       END DO                                       ! end of sub-time step loop
 
+      ! -----------------------
+      !!! final step (clem) !!!
+      DO jj = 1, jpjm1                                ! diffusive fluxes in U- and V- direction
+         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
+      !
+      DO jj= 2, jpjm1                                 ! diffusive trend : divergence of the fluxes
+         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) )
+            ptab(ji,jj) = ztab0(ji,jj) + 0.5 * ( zdiv(ji,jj) + zdiv0(ji,jj) )
+         END DO
+      END DO
+      CALL lbc_lnk( ptab, 'T', 1. )                   ! lateral boundary condition
+      !!! final step (clem) !!!
+      ! -----------------------
+
       IF(ln_ctl)   THEN
          zrlx(:,:) = ptab(:,:) - ztab0(:,:)
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 3938)
@@ -5,5 +5,6 @@
    !!======================================================================
    !! History :  2.0  ! 2004-01 (C. Ethe, G. Madec)  Original code
-   !!            4.0  ! 2011-02  (G. Madec) dynamical allocation
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!             -   ! 2012    (C. Rousset) clean + add par_oce (for jp_sal)...bug?
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -21,4 +22,5 @@
    USE ice              ! sea-ice variables
    USE par_ice          ! ice parameters
+   USE par_oce          ! ocean parameters
    USE dom_ice          ! sea-ice domain
    USE in_out_manager   ! I/O manager
@@ -63,13 +65,13 @@
       !!                or from arbitrary sea-ice conditions
       !!-------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
-      REAL(wp) ::   zeps6, zeps, ztmelts, epsi06   ! local scalars
-      REAL(wp) ::   zvol, zare, zh, zh1, zh2, zh3, zan, zbn, zas, zbs 
-      REAL(wp), POINTER, DIMENSION(:)   ::   zgfactorn, zhin 
-      REAL(wp), POINTER, DIMENSION(:)   ::   zgfactors, zhis
+      INTEGER  ::   ji, jj, jk, jl            ! dummy loop indices
+      INTEGER  ::   i_fill, jl0, ztest_1, ztest_2, ztest_3, ztest_4, ztests  
+      REAL(wp) ::   zarg, zV, zconv
+      REAL(wp) ::   zeps06, zeps, ztmelts   ! local scalars
+      REAL(wp),          DIMENSION(jpl) ::   zain, zhtin, zhtsn, zais, zhtis, zhtss 
+      REAL(wp),          DIMENSION(jpl) ::   zai, zhti, zhts 
       REAL(wp), POINTER, DIMENSION(:,:) ::   zidto      ! ice indicator
       !--------------------------------------------------------------------
 
-      CALL wrk_alloc( jpm, zgfactorn, zgfactors, zhin, zhis )
       CALL wrk_alloc( jpi, jpj, zidto )
 
@@ -77,5 +79,4 @@
       ! 1) Preliminary things 
       !--------------------------------------------------------------------
-      epsi06 = 1.e-6_wp
 
       CALL lim_istate_init     !  reading the initials parameters of the ice
@@ -106,88 +107,208 @@
 
       ! constants for heat contents
-      zeps   = 1.e-20_wp
-      zeps6  = 1.e-06_wp
-
-      ! zgfactor for initial ice distribution
-      zgfactorn(:) = 0._wp
-      zgfactors(:) = 0._wp
-
-      ! first ice type
-      DO jl = ice_cat_bounds(1,1), ice_cat_bounds(1,2)
-         zhin (1)     = ( hi_max(jl-1) + hi_max(jl) ) * 0.5_wp
-         zgfactorn(1) = zgfactorn(1) + exp(-(zhin(1)-hginn_u)*(zhin(1)-hginn_u) * 0.5_wp )
-         zhis (1)     = ( hi_max(jl-1) + hi_max(jl) ) * 0.5_wp
-         zgfactors(1) = zgfactors(1) + exp(-(zhis(1)-hgins_u)*(zhis(1)-hgins_u) * 0.5_wp )
-      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._wp
-      zh2 = 0._wp
-      zh3 = 0._wp
+      zeps    = 1.e-20_wp
+      zeps06  = 1.e-06_wp
+
+      !-------------------------------------------------------------------
+      ! 3) Distribute ice concentration and thickness into the categories 
+      !-------------------------------------------------------------------
+      ! snow distribution
+      zhtsn(1:jpl) = 0.d0
+      zhtss(1:jpl) = 0.d0
       DO jl = 1, jpl
-         zh = ( hi_max(jl-1) + hi_max(jl) ) * 0.5_wp
-         zh1 = zh1 + zh
-         zh2 = zh2 + zh * zh
-         zh3 = zh3 + zh * zh * zh
+         zhtsn(jl) = hninn
+         zhtss(jl) = hnins
       END DO
-      IF(lwp) WRITE(numout,*) ' zh1 : ', zh1
-      IF(lwp) WRITE(numout,*) ' zh2 : ', zh2
-      IF(lwp) WRITE(numout,*) ' zh3 : ', zh3
-
-      zvol = aginn_u * hginn_u
-      zare = aginn_u
-      IF( jpl >= 2 ) THEN
-         zbn = ( zvol*zh2 - zare*zh3 ) / ( zh2*zh2 - zh1*zh3)
-         zan = ( zare - zbn*zh1 ) / zh2
+
+      ! -------------------
+      ! Northern Hemisphere
+      ! -------------------
+      ! initialisation of tests
+      ztest_1 = 0
+      ztest_2 = 0
+      ztest_3 = 0
+      ztest_4 = 0
+      ztests  = 0
+         
+      i_fill = jpl + 1                                    !====================================
+      DO WHILE ( ( ztests /= 4 ) .AND. ( i_fill >= 2 ) )  ! iterative loop on i_fill categories  
+         ! iteration                                      !====================================
+         i_fill = i_fill - 1
+ 
+         ! initialisation of ice variables for each try
+         zhtin(1:jpl) = 0.d0
+         zain (1:jpl) = 0.d0
+         
+         ! *** case very thin ice: fill only category 1
+         IF ( i_fill == 1 ) THEN
+            zhtin(1) = hginn_u
+            zain (1) = aginn_u
+            
+            ! *** case ice is thicker: fill categories >1
+         ELSE
+            
+            ! Fill ice thicknesses except the last one (i_fill) by (hmax-hmin)/2 
+            DO jl = 1, i_fill - 1
+               zhtin(jl) = ( hi_max(jl) + hi_max(jl-1) ) / 2.
+            END DO
+            
+            ! find which category (jl0) the input ice thickness falls into
+            jl0 = i_fill
+            DO jl = 1, i_fill
+               IF ( ( hginn_u >= hi_max(jl-1) ) .AND. ( hginn_u < hi_max(jl) ) ) THEN
+                  jl0 = jl
+                  CYCLE
+               ENDIF
+            END DO
+            
+            ! Concentrations in the (i_fill-1) categories 
+            zain(jl0) = aginn_u / SQRT(REAL(jpl))
+            DO jl = 1, i_fill - 1
+               IF ( jl == jl0 ) CYCLE
+               zarg           = ( zhtin(jl) - hginn_u ) / ( hginn_u / 2. )
+               zain(jl) =   zain (jl0) * EXP(-zarg**2)
+            END DO
+            
+            ! Concentration in the last (i_fill) category
+            zain(i_fill) = aginn_u - SUM( zain(1:i_fill-1) )
+            
+            ! Ice thickness in the last (i_fill) category
+            zV = SUM( zain(1:i_fill-1) * zhtin(1:i_fill-1) )
+            zhtin(i_fill) = ( hginn_u*aginn_u -  zV ) / zain(i_fill) 
+            
+         ENDIF ! case ice is thick or thin
+         
+         !---------------------
+         ! Compatibility tests
+         !--------------------- 
+         ! Test 1: area conservation
+         zconv = ABS( aginn_u - SUM( zain(1:jpl) ) )
+         IF ( zconv < zeps06 ) ztest_1 = 1
+         
+         ! Test 2: volume conservation
+         zconv = ABS( hginn_u*aginn_u - SUM( zain(1:jpl)*zhtin(1:jpl) ) )
+         IF ( zconv < zeps06 ) ztest_2 = 1
+         
+         ! Test 3: thickness of the last category is in-bounds ?
+         IF ( zhtin(i_fill) >= hi_max(i_fill-1) ) ztest_3 = 1
+         
+         ! Test 4: positivity of ice concentrations
+         ztest_4 = 1
+         DO jl = 1, i_fill
+            IF ( zain(jl) < 0.0d0 ) ztest_4 = 0
+         END DO
+         
+         ztests = ztest_1 + ztest_2 + ztest_3 + ztest_4
+                                                        !============================
+      END DO                                            ! end iteration on categories
+                                                        !============================
+      ! Check if tests have passed (i.e. volume conservation...)
+      IF ( ztests .NE. 4 ) THEN
+         WRITE(numout,*) ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '
+         WRITE(numout,*) ' !! ALERT categories distribution !!'
+         WRITE(numout,*) ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '
+         WRITE(numout,*) ' *** ztests is not equal to 4 '
+         WRITE(numout,*) ' *** ztest (1:4) = ', ztest_1, ztest_2, ztest_3, ztest_4
       ENDIF
 
-      IF(lwp) WRITE(numout,*) ' zvol: ', zvol
-      IF(lwp) WRITE(numout,*) ' zare: ', zare
-      IF(lwp) WRITE(numout,*) ' zbn : ', zbn 
-      IF(lwp) WRITE(numout,*) ' zan : ', zan 
-
-      zvol = agins_u * hgins_u
-      zare = agins_u
-      IF( jpl >= 2 ) THEN
-         zbs = ( zvol*zh2 - zare*zh3 ) / ( zh2*zh2 - zh1*zh3)
-         zas = ( zare - zbs*zh1 ) / zh2
+      ! -------------------
+      ! Southern Hemisphere
+      ! -------------------
+      ! initialisation of tests
+      ztest_1 = 0
+      ztest_2 = 0
+      ztest_3 = 0
+      ztest_4 = 0
+      ztests  = 0
+         
+      i_fill = jpl + 1                                    !====================================
+      DO WHILE ( ( ztests /= 4 ) .AND. ( i_fill >= 2 ) )  ! iterative loop on i_fill categories  
+         ! iteration                                      !====================================
+         i_fill = i_fill - 1
+ 
+         ! initialisation of ice variables for each try
+         zhtis(1:jpl) = 0.d0
+         zais (1:jpl) = 0.d0
+         
+         ! *** case very thin ice: fill only category 1
+         IF ( i_fill == 1 ) THEN
+            zhtis(1) = hgins_u
+            zais (1) = agins_u
+            
+            ! *** case ice is thicker: fill categories >1
+         ELSE
+            
+            ! Fill ice thicknesses except the last one (i_fill) by (hmax-hmin)/2 
+            DO jl = 1, i_fill - 1
+               zhtis(jl) = ( hi_max(jl) + hi_max(jl-1) ) / 2.
+            END DO
+            
+            ! find which category (jl0) the input ice thickness falls into
+            jl0 = i_fill
+            DO jl = 1, i_fill
+               IF ( ( hgins_u >= hi_max(jl-1) ) .AND. ( hgins_u < hi_max(jl) ) ) THEN
+                  jl0 = jl
+                  CYCLE
+               ENDIF
+            END DO
+            
+            ! Concentrations in the (i_fill-1) categories 
+            zais(jl0) = agins_u / SQRT(REAL(jpl))
+            DO jl = 1, i_fill - 1
+               IF ( jl == jl0 ) CYCLE
+               zarg           = ( zhtis(jl) - hgins_u ) / ( hgins_u / 2. )
+               zais(jl) =   zais (jl0) * EXP(-zarg**2)
+            END DO
+            
+            ! Concentration in the last (i_fill) category
+            zais(i_fill) = agins_u - SUM( zais(1:i_fill-1) )
+            
+            ! Ice thickness in the last (i_fill) category
+            zV = SUM( zais(1:i_fill-1) * zhtis(1:i_fill-1) )
+            zhtis(i_fill) = ( hgins_u*agins_u -  zV ) / zais(i_fill) 
+            
+         ENDIF ! case ice is thick or thin
+         
+         !---------------------
+         ! Compatibility tests
+         !--------------------- 
+         ! Test 1: area conservation
+         zconv = ABS( agins_u - SUM( zais(1:jpl) ) )
+         IF ( zconv < zeps06 ) ztest_1 = 1
+         
+         ! Test 2: volume conservation
+         zconv = ABS( hgins_u*agins_u - SUM( zais(1:jpl)*zhtis(1:jpl) ) )
+         IF ( zconv < zeps06 ) ztest_2 = 1
+         
+         ! Test 3: thickness of the last category is in-bounds ?
+         IF ( zhtis(i_fill) >= hi_max(i_fill-1) ) ztest_3 = 1
+         
+         ! Test 4: positivity of ice concentrations
+         ztest_4 = 1
+         DO jl = 1, i_fill
+            IF ( zais(jl) < 0.0d0 ) ztest_4 = 0
+         END DO
+         
+         ztests = ztest_1 + ztest_2 + ztest_3 + ztest_4
+                                                        !============================
+      END DO                                            ! end iteration on categories
+                                                        !============================
+      ! Check if tests have passed (i.e. volume conservation...)
+      IF ( ztests .NE. 4 ) THEN
+         WRITE(numout,*) ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '
+         WRITE(numout,*) ' !! ALERT categories distribution !!'
+         WRITE(numout,*) ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '
+         WRITE(numout,*) ' *** ztests is not equal to 4 '
+         WRITE(numout,*) ' *** ztest (1:4) = ', ztest_1, ztest_2, ztest_3, ztest_4
       ENDIF
-
-      IF(lwp) WRITE(numout,*) ' zvol: ', zvol
-      IF(lwp) WRITE(numout,*) ' zare: ', zare
-      IF(lwp) WRITE(numout,*) ' zbn : ', zbn 
-      IF(lwp) 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
-!!!
-
-!!gm  optimisation :  loop over the ice categories inside the ji, jj loop !!!
-
+!!
+!!
+!!
+      ! ---------------------
+      ! 4) fill ice variables
+      ! ---------------------
+      zai(:) = 0.0
+      zhti(:)= 0.0
+      zhts(:)= 0.0
       DO jj = 1, jpj
          DO ji = 1, jpi
@@ -195,257 +316,97 @@
             !--- Northern hemisphere
             !----------------------------------------------------------------
-            IF( fcor(ji,jj) >= 0._wp ) THEN    
-
+            IF( fcor(ji,jj) >= 0._wp ) THEN
+               zai(:) = zain(:) ; zhti(:) = zhtin(:) ; zhts(:) = zhtsn(:)     
+            ELSE 
+               zai(:) = zais(:) ; zhti(:) = zhtis(:) ; zhts(:) = zhtss(:)     
+            ENDIF
+            
+            DO jl = 1, jpl
                !-----------------------
                ! 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(ji,jj) * aginn_u
-                     ht_i(ji,jj,jl)   = zidto(ji,jj) * 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(ji,jj) * MAX( zgfactorn(1) * exp(-(zhin(1)-hginn_u)* & 
-                        (zhin(1)-hginn_u)/2.0) , epsi06)
-                     ! new line
-                     a_i(ji,jj,jl)    = zidto(ji,jj) * ( zan * zhin(1) * zhin(1) + zbn * zhin(1) )
-                     ht_i(ji,jj,jl)   = zidto(ji,jj) * 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(ji,jj) * MAX( zgfactorn(2) * exp(-(zhin(2)-hginn_d)* &
-               !                                    (zhin(2)-hginn_d)/2.0) , epsi06)
-               !                 ht_i(ji,jj,jl)   = zidto(ji,jj) * 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(ji,jj) * hninn
-                  v_s(ji,jj,jl)    = ht_s(ji,jj,jl)*a_i(ji,jj,jl)
-
-                  !---------------
-                  ! Ice salinity
-                  !---------------
-                  sm_i(ji,jj,jl)   = zidto(ji,jj) * sinn  + ( 1.0 - zidto(ji,jj) ) * 0.1
-                  smv_i(ji,jj,jl)  = MIN( sm_i(ji,jj,jl) , sss_m(ji,jj) ) * v_i(ji,jj,jl)
-
-                  !----------
-                  ! Ice age
-                  !----------
-                  o_i(ji,jj,jl)    = zidto(ji,jj) * 1.0   + ( 1.0 - zidto(ji,jj) )
-                  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(ji,jj) * 270.0 + ( 1.0 - zidto(ji,jj) ) * t_bo(ji,jj)
-
-                  !------------------------------------
-                  ! Snow temperature and heat content
-                  !------------------------------------
-
-                  DO jk = 1, nlay_s
-                     t_s(ji,jj,jk,jl) = zidto(ji,jj) * 270.00 + ( 1.0 - zidto(ji,jj) ) * rtt
-                     ! Snow energy of melting
-                     e_s(ji,jj,jk,jl) = zidto(ji,jj) * rhosn * ( cpic * ( rtt - t_s(ji,jj,jk,jl) ) + lfus )
-                     ! 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(ji,jj)*270.00 + ( 1.0 - zidto(ji,jj) ) * rtt 
-                     s_i(ji,jj,jk,jl) = zidto(ji,jj) * sinn + ( 1.0 - zidto(ji,jj) ) * 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(ji,jj) * 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(ji,jj) * agins_u
-                     ht_i(ji,jj,jl)   = zidto(ji,jj) * 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(ji,jj) * 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(ji,jj) * ( zas * zhis(1) * zhis(1) + zbs * zhis(1) )
-                     ht_i(ji,jj,jl)   = zidto(ji,jj) * 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(ji,jj)*MAX( zgfactors(2)   &
-               !                    &          * exp(-(zhis(2)-hgins_d)*(zhis(2)-hgins_d)/2.0), epsi06 )
-               !                 ht_i(ji,jj,jl)   = zidto(ji,jj) * 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(ji,jj) * hnins
-                  v_s(ji,jj,jl)    = ht_s(ji,jj,jl)*a_i(ji,jj,jl)
-
-                  !---------------
-                  ! Ice salinity
-                  !---------------
-
-                  sm_i(ji,jj,jl)   = zidto(ji,jj) * sins  + ( 1.0 - zidto(ji,jj) ) * 0.1
-                  smv_i(ji,jj,jl)  = MIN( sm_i(ji,jj,jl) , sss_m(ji,jj) ) * v_i(ji,jj,jl)
-
-                  !----------
-                  ! Ice age
-                  !----------
-
-                  o_i(ji,jj,jl)    = zidto(ji,jj) * 1.0   + ( 1.0 - zidto(ji,jj) )
-                  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(ji,jj) * 270.0 + ( 1.0 - zidto(ji,jj) ) * t_bo(ji,jj)
-
-                  !----------------------------------
-                  ! Snow temperature / heat content
-                  !----------------------------------
-
-                  DO jk = 1, nlay_s
-                     t_s(ji,jj,jk,jl) = zidto(ji,jj) * 270.00 + ( 1.0 - zidto(ji,jj) ) * rtt
-                     ! Snow energy of melting
-                     e_s(ji,jj,jk,jl) = zidto(ji,jj) * rhosn * ( cpic * ( rtt - t_s(ji,jj,jk,jl) ) + lfus )
-                     ! 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(ji,jj)*270.00 + ( 1.0 - zidto(ji,jj) ) * rtt 
-                     s_i(ji,jj,jk,jl) = zidto(ji,jj) * sins + ( 1.0 - zidto(ji,jj) ) * 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(ji,jj) * 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
-
+               a_i(ji,jj,jl)    = zidto(ji,jj) * zai(jl)
+               ht_i(ji,jj,jl)   = zidto(ji,jj) * zhti(jl)
+               v_i(ji,jj,jl)    = ht_i(ji,jj,jl)*a_i(ji,jj,jl)
+               
+               !-------------
+               ! Snow depth
+               !-------------
+               ht_s(ji,jj,jl)   = zidto(ji,jj) * zhts(jl)
+               v_s(ji,jj,jl)    = ht_s(ji,jj,jl)*a_i(ji,jj,jl)
+               
+               !---------------
+               ! Ice salinity
+               !---------------
+               sm_i(ji,jj,jl)   = zidto(ji,jj) * sinn  + ( 1.0 - zidto(ji,jj) ) * 0.1
+               smv_i(ji,jj,jl)  = MIN( sm_i(ji,jj,jl) , sss_m(ji,jj) ) * v_i(ji,jj,jl)
+               
+               !----------
+               ! Ice age
+               !----------
+               o_i(ji,jj,jl)    = zidto(ji,jj) * 1.0   + ( 1.0 - zidto(ji,jj) )
+               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(ji,jj) * 270.0 + ( 1.0 - zidto(ji,jj) ) * t_bo(ji,jj)
+               
+               !------------------------------------
+               ! Snow temperature and heat content
+               !------------------------------------
+               DO jk = 1, nlay_s
+                  t_s(ji,jj,jk,jl) = zidto(ji,jj) * 270.00 + ( 1.0 - zidto(ji,jj) ) * rtt
+                  ! Snow energy of melting
+                  e_s(ji,jj,jk,jl) = zidto(ji,jj) * rhosn * ( cpic * ( rtt - t_s(ji,jj,jk,jl) ) + lfus )
+                  ! 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)  / REAL( nlay_s )
+               END DO !jk
+               
+               !-----------------------------------------------
+               ! Ice salinities, temperature and heat content 
+               !-----------------------------------------------
+               DO jk = 1, nlay_i
+                  t_i(ji,jj,jk,jl) = zidto(ji,jj)*270.00 + ( 1.0 - zidto(ji,jj) ) * rtt 
+                  s_i(ji,jj,jk,jl) = zidto(ji,jj) * sinn + ( 1.0 - zidto(ji,jj) ) * 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(ji,jj) * 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) / &
+                       REAL( nlay_i )
+               END DO ! jk
+               
+            END DO ! jl 
+            
          END DO
       END DO
-
-      !--------------------------------------------------------------------
-      ! 3) Global ice variables for output diagnostics                    | 
+ 
+      IF(lwp) THEN                        ! control print
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   max ice  thickness   = ', (MAXVAL(ht_i(:,:,jl)),jl=1,jpl)
+         WRITE(numout,*) '   max snow thickness   = ', (MAXVAL(ht_s(:,:,jl)),jl=1,jpl)
+         WRITE(numout,*) '   max ice  area        = ', (MAXVAL(a_i(:,:,jl)),jl=1,jpl)
+         WRITE(numout,*) '   max ice  salinity    = ', (MAXVAL(sm_i(:,:,jl)),jl=1,jpl)
+         WRITE(numout,*) '   min ice  salinity    = ', (MINVAL(sm_i(:,:,jl)),jl=1,jpl)
+         WRITE(numout,*) '   max ice  surf temper = ', (MAXVAL(t_su(:,:,jl)-rtt),jl=1,jpl)
+         WRITE(numout,*) '   min ice  surf temper = ', (MINVAL(t_su(:,:,jl)-rtt),jl=1,jpl)
+      ENDIF
+
+      !--------------------------------------------------------------------
+      ! 5) Global ice variables for output diagnostics                    | 
       !--------------------------------------------------------------------
 
@@ -458,5 +419,5 @@
 
       !--------------------------------------------------------------------
-      ! 4) Moments for advection
+      ! 6) Moments for advection
       !--------------------------------------------------------------------
 
@@ -485,6 +446,8 @@
       sxysal (:,:,:)  = 0.e0
 
-      !--------------------------------------------------------------------
-      ! 5) Lateral boundary conditions                                    | 
+      sxopw(:,:) = 0.e0 ; syopw(:,:) = 0.e0; sxxopw(:,:) = 0.e0; syyopw(:,:) = 0.e0; sxyopw(:,:) = 0.e0
+
+      !--------------------------------------------------------------------
+      ! 7) Lateral boundary conditions                                    | 
       !--------------------------------------------------------------------
 
@@ -518,5 +481,4 @@
       CALL lbc_lnk( fsbbq  , 'T', 1. )
       !
-      CALL wrk_dealloc( jpm, zgfactorn, zgfactors, zhin, zhis )
       CALL wrk_dealloc( jpi, jpj, zidto )
       !
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90	(revision 3938)
@@ -28,4 +28,8 @@
    USE wrk_nemo         ! work arrays
    USE prtctl           ! Print control
+  ! Check budget (Rousset)
+   USE iom              ! I/O manager
+   USE lib_fortran     ! glob_sum
+   USE limdiahsb
 
    IMPLICIT NONE
@@ -50,5 +54,4 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   athorn   ! participation function; fraction of ridging/
    !                                                           !  closing associated w/ category n
-
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hrmin    ! minimum ridge thickness
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hrmax    ! maximum ridge thickness
@@ -138,7 +141,12 @@
       REAL(wp), POINTER, DIMENSION(:,:) ::   esnow_mlt       ! energy needed to melt snow in ocean (J m-2)
       REAL(wp), POINTER, DIMENSION(:,:) ::   vt_i_init, vt_i_final  !  ice volume summed over categories
+      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
+      ! mass and salt flux (clem)
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zviold, zvsold, zsmvold   ! old ice volume...
       !!-----------------------------------------------------------------------------
 
       CALL wrk_alloc( jpi, jpj, closing_net, divu_adv, opning, closing_gross, msnow_mlt, esnow_mlt, vt_i_init, vt_i_final )
+
+      CALL wrk_alloc( jpi, jpj, jpl, zviold, zvsold, zsmvold )   ! clem
 
       IF( numit == nstart  )   CALL lim_itd_me_init   ! Initialization (first time-step only)
@@ -148,4 +156,21 @@
          CALL prt_ctl(tab2d_1=divu_i, clinfo1=' lim_itd_me: divu_i : ', tab2d_2=delta_i, clinfo2=' delta_i : ')
       ENDIF
+
+      IF( ln_limdyn ) THEN          !   Start ridging and rafting   !
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
+         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
+      ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
+
+      ! mass and salt flux init (clem)
+      zviold(:,:,:) = v_i(:,:,:)
+      zvsold(:,:,:) = v_s(:,:,:)
+      zsmvold(:,:,:) = smv_i(:,:,:)
 
       !-----------------------------------------------------------------------------!
@@ -201,5 +226,5 @@
             ! to give asum = 1.0 after ridging.
 
-            divu_adv(ji,jj) = ( 1._wp - asum(ji,jj) ) / rdt_ice  ! asum found in ridgeprep
+            divu_adv(ji,jj) = ( amax - asum(ji,jj) ) / rdt_ice  ! asum found in ridgeprep
 
             IF( divu_adv(ji,jj) < 0._wp )   closing_net(ji,jj) = MAX( closing_net(ji,jj), -divu_adv(ji,jj) )
@@ -286,10 +311,10 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               IF (ABS(asum(ji,jj) - 1.0) .LT. epsi11) THEN
+               IF (ABS(asum(ji,jj) - amax ) .LT. epsi11) THEN
                   closing_net(ji,jj) = 0._wp
                   opning     (ji,jj) = 0._wp
                ELSE
                   iterate_ridging    = 1
-                  divu_adv   (ji,jj) = (1._wp - asum(ji,jj)) / rdt_ice
+                  divu_adv   (ji,jj) = ( amax - asum(ji,jj) ) / rdt_ice
                   closing_net(ji,jj) = MAX( 0._wp, -divu_adv(ji,jj) )
                   opning     (ji,jj) = MAX( 0._wp,  divu_adv(ji,jj) )
@@ -330,5 +355,5 @@
          DO ji = 1, jpi
 
-            IF (ABS(asum(ji,jj) - 1.0) .GT. epsi11) asum_error = .true.
+            IF (ABS(asum(ji,jj) - amax) .GT. epsi11) asum_error = .true.
 
             dardg1dt(ji,jj) = dardg1dt(ji,jj) * dti
@@ -349,5 +374,5 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            IF (ABS(asum(ji,jj) - 1.0) .GT. epsi11) THEN ! there is a bug
+            IF (ABS(asum(ji,jj) - amax) .GT. epsi11) THEN ! there is a bug
                WRITE(numout,*) ' '
                WRITE(numout,*) ' ALERTE : Ridging error: total area = ', asum(ji,jj)
@@ -377,4 +402,18 @@
       CALL lim_var_glo2eqv
       CALL lim_itd_me_zapsmall
+
+      !--------------------------------
+      ! Update mass/salt fluxes (clem)
+      !--------------------------------
+      DO jl = 1, jpl
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+               diag_dyn_gr(ji,jj) = diag_dyn_gr(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) / rdt_ice
+               rdmicif(ji,jj) = rdmicif(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) * rhoic 
+               rdmsnif(ji,jj) = rdmsnif(ji,jj) + ( v_s(ji,jj,jl) - zvsold(ji,jj,jl) ) * rhosn 
+               fsalt_rpo(ji,jj) = fsalt_rpo(ji,jj) - ( smv_i(ji,jj,jl) - zsmvold(ji,jj,jl) ) * rhoic / rdt_ice 
+            END DO
+         END DO
+      END DO
 
       !-----------------
@@ -425,8 +464,27 @@
       ENDIF
 
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
+         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
+ 
+         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
+         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
+
+         IF(lwp) THEN
+            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limitd_me) = ',(zchk_v_i * 86400.)
+            IF (    ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limitd_me) = ',(zchk_smv * 86400.)
+            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limitd_me) = ',(MINVAL(v_i) * 1.e-3)
+            IF ( MAXVAL( SUM(a_i(:,:,:),dim=3) ) > amax+epsi10 ) WRITE(numout,*) 'violation a_i>amax            (limitd_me) = ',MAXVAL(SUM(a_i,dim=3))
+            IF ( MINVAL( a_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation a_i<0               (limitd_me) = ',MINVAL(a_i)
+         ENDIF
+      ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
+
       !-------------------------!
       ! Back to initial values
       !-------------------------!
-
       ! update of fields will be made later in lim update
       u_ice(:,:)    = old_u_ice(:,:)
@@ -439,5 +497,4 @@
       oa_i(:,:,:)   = old_oa_i(:,:,:)
       IF(  num_sal == 2  .OR.  num_sal == 4  )   smv_i(:,:,:)  = old_smv_i(:,:,:)
-
       !----------------------------------------------------!
       ! Advection of ice in a free cell, newly ridged ice
@@ -448,41 +505,46 @@
 
       ! 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) < epsi06 ) .AND. &
-                     ( d_v_i_trp(ji,jj,jl) > 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._wp
-                  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) < epsi06 ) .AND. &
-                  ( d_v_i_trp(ji,jj,jl) > epsi06 ) ) THEN
-                  old_v_i(ji,jj,jl)     = d_v_i_trp(ji,jj,jl)
-                  d_v_i_trp(ji,jj,jl)   = 0._wp
-                  old_a_i(ji,jj,jl)     = d_a_i_trp(ji,jj,jl)
-                  d_a_i_trp(ji,jj,jl)   = 0._wp
-                  old_v_s(ji,jj,jl)     = d_v_s_trp(ji,jj,jl)
-                  d_v_s_trp(ji,jj,jl)   = 0._wp
-                  old_e_s(ji,jj,1,jl)   = d_e_s_trp(ji,jj,1,jl)
-                  d_e_s_trp(ji,jj,1,jl) = 0._wp
-                  old_oa_i(ji,jj,jl)    = d_oa_i_trp(ji,jj,jl)
-                  d_oa_i_trp(ji,jj,jl)  = 0._wp
-                  IF(  num_sal == 2  .OR.  num_sal == 4  )   old_smv_i(ji,jj,jl)   = d_smv_i_trp(ji,jj,jl)
-                  d_smv_i_trp(ji,jj,jl) = 0._wp
-               ENDIF
-            END DO
-         END DO
-      END DO
-
+!clem@order
+!      DO jl = 1, jpl
+!         DO jk = 1, nlay_i
+!            DO jj = 1, jpj
+!               DO ji = 1, jpi
+!                  IF ( ( old_v_i(ji,jj,jl) < epsi06 ) .AND. &
+!                     ( d_v_i_trp(ji,jj,jl) > 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._wp
+!                  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) < epsi06 ) .AND. &
+!                  ( d_v_i_trp(ji,jj,jl) > epsi06 ) ) THEN
+!                  old_v_i(ji,jj,jl)     = d_v_i_trp(ji,jj,jl)
+!                  d_v_i_trp(ji,jj,jl)   = 0._wp
+!                  old_a_i(ji,jj,jl)     = d_a_i_trp(ji,jj,jl)
+!                  d_a_i_trp(ji,jj,jl)   = 0._wp
+!                  old_v_s(ji,jj,jl)     = d_v_s_trp(ji,jj,jl)
+!                  d_v_s_trp(ji,jj,jl)   = 0._wp
+!                  old_e_s(ji,jj,1,jl)   = d_e_s_trp(ji,jj,1,jl)
+!                  d_e_s_trp(ji,jj,1,jl) = 0._wp
+!                  old_oa_i(ji,jj,jl)    = d_oa_i_trp(ji,jj,jl)
+!                  d_oa_i_trp(ji,jj,jl)  = 0._wp
+!                  IF(  num_sal == 2  .OR.  num_sal == 4  )   old_smv_i(ji,jj,jl)   = d_smv_i_trp(ji,jj,jl)
+!                  d_smv_i_trp(ji,jj,jl) = 0._wp
+!               ENDIF
+!            END DO
+!         END DO
+!      END DO
+!clem@order
+      ENDIF  ! ln_limdyn=.true.
+      !
       CALL wrk_dealloc( jpi, jpj, closing_net, divu_adv, opning, closing_gross, msnow_mlt, esnow_mlt, vt_i_init, vt_i_final )
+      !
+      CALL wrk_dealloc( jpi, jpj, jpl, zviold, zvsold, zsmvold )   ! clem
       !
    END SUBROUTINE lim_itd_me
@@ -1086,13 +1148,13 @@
             afrft(ji,jj) = arft1(ji,jj) / aicen_init(ji,jj,jl1) !rafting
 
-            IF (afrac(ji,jj) > 1.0 + epsi11) THEN  !riging
+            IF (afrac(ji,jj) > amax + epsi11) THEN  !riging
                large_afrac = .true.
-            ELSEIF (afrac(ji,jj) > 1.0) THEN  ! roundoff error
-               afrac(ji,jj) = 1.0
+            ELSEIF (afrac(ji,jj) > amax) THEN  ! roundoff error
+               afrac(ji,jj) = amax
             ENDIF
-            IF (afrft(ji,jj) > 1.0 + epsi11) THEN !rafting
+            IF (afrft(ji,jj) > amax + epsi11) THEN !rafting
                large_afrft = .true.
-            ELSEIF (afrft(ji,jj) > 1.0) THEN  ! roundoff error
-               afrft(ji,jj) = 1.0
+            ELSEIF (afrft(ji,jj) > amax) THEN  ! roundoff error
+               afrft(ji,jj) = amax
             ENDIF
 
@@ -1137,5 +1199,7 @@
             
             !                                                             ! excess of salt is flushed into the ocean
-            fsalt_rpo(ji,jj) = fsalt_rpo(ji,jj) + ( zsrdg2 - srdg2(ji,jj) ) * rhoic / rdt_ice
+            !fsalt_rpo(ji,jj) = fsalt_rpo(ji,jj) + ( zsrdg2 - srdg2(ji,jj) ) * rhoic / rdt_ice
+
+            !rdmicif(ji,jj) = rdmicif(ji,jj) + vsw(ji,jj) * rhoic    ! gurvan: increase in ice volume du to seawater frozen in voids             
 
             !------------------------------------            
@@ -1148,5 +1212,5 @@
             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
+            !clem 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
 
@@ -1217,5 +1281,5 @@
 
                ! 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
+               ersw (ji,jj,jk)  = ersw(ji,jj,jk) * area(ji,jj) * vsw(ji,jj) / REAL( nlay_i )
 
                erdg2(ji,jj,jk)  = erdg1(ji,jj,jk) + ersw(ji,jj,jk)
@@ -1240,5 +1304,5 @@
                ji = indxi(ij)
                jj = indxj(ij)
-               IF( afrac(ji,jj) > 1.0 + epsi11 ) THEN 
+               IF( afrac(ji,jj) > amax + epsi11 ) THEN 
                   WRITE(numout,*) ''
                   WRITE(numout,*) ' ardg > a_i'
@@ -1252,5 +1316,5 @@
                ji = indxi(ij)
                jj = indxj(ij)
-               IF( afrft(ji,jj) > 1.0 + epsi11 ) THEN 
+               IF( afrft(ji,jj) > amax + epsi11 ) THEN 
                   WRITE(numout,*) ''
                   WRITE(numout,*) ' arft > a_i'
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90	(revision 3938)
@@ -34,4 +34,5 @@
    USE lib_mpp          ! MPP library
    USE wrk_nemo         ! work arrays
+   USE lib_fortran      ! to use key_nosignedzero
 
    IMPLICIT NONE
@@ -44,7 +45,7 @@
    PUBLIC   lim_itd_shiftice
 
-   REAL(wp) ::   epsi20 = 1e-20_wp   ! constant values
-   REAL(wp) ::   epsi13 = 1e-13_wp   !
-   REAL(wp) ::   epsi10 = 1e-10_wp   !
+   REAL(wp) ::   epsi20 = 1.e-20_wp   ! constant values
+   REAL(wp) ::   epsi13 = 1.e-13_wp   !
+   REAL(wp) ::   epsi10 = 1.e-10_wp   !
 
    !!----------------------------------------------------------------------
@@ -66,6 +67,16 @@
       !
       INTEGER ::   jl, ja, jm, jbnd1, jbnd2   ! ice types    dummy loop index         
-
-      !!------------------------------------------------------------------
+      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
+      !!------------------------------------------------------------------
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
+         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
+      ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
 
       IF( kt == nit000 .AND. lwp ) THEN
@@ -106,7 +117,10 @@
       d_e_s_thd(:,:,:,:) = e_s(:,:,:,:) - old_e_s(:,:,:,:) 
       d_e_i_thd(:,:,:,:) = e_i(:,:,:,:) - old_e_i(:,:,:,:)
-
+      !?? d_oa_i_thd(:,:,:)  = oa_i (:,:,:) - old_oa_i (:,:,:)
       d_smv_i_thd(:,:,:) = 0._wp
       IF( num_sal == 2 .OR. num_sal == 4 )   d_smv_i_thd(:,:,:) = smv_i(:,:,:) - old_smv_i(:,:,:)
+
+      ! diag only (clem)
+      dv_dt_thd(:,:,:) = d_v_i_thd(:,:,:) / rdt_ice * 86400.0
 
       IF(ln_ctl) THEN   ! Control print
@@ -141,5 +155,24 @@
          END DO
       ENDIF
-
+      !
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
+         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
+ 
+         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
+         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
+
+         IF(lwp) THEN
+            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limitd_th) = ',(zchk_v_i * 86400.)
+            IF (    ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limitd_th) = ',(zchk_smv * 86400.)
+            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limitd_th) = ',(MINVAL(v_i) * 1.e-3)
+            IF ( MAXVAL( SUM(a_i(:,:,:),dim=3) ) >  amax+epsi10 ) WRITE(numout,*) 'violation a_i>amax    (limitd_th) = ',MAXVAL(SUM(a_i,dim=3))
+         ENDIF
+       ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
+      !
       !- Recover Old values
       a_i(:,:,:)   = old_a_i (:,:,:)
@@ -148,5 +181,5 @@
       e_s(:,:,:,:) = old_e_s (:,:,:,:)
       e_i(:,:,:,:) = old_e_i (:,:,:,:)
-      !
+      !?? oa_i(:,:,:)  = old_oa_i(:,:,:)
       IF( num_sal == 2 .OR. num_sal == 4 )   smv_i(:,:,:)       = old_smv_i (:,:,:)
       !
@@ -239,7 +272,7 @@
          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
+               zindb             = 1.0-MAX(0.0,SIGN(1.0,-a_i(ji,jj,jl)+epsi10))     !0 if no ice and 1 if yes
                ht_i(ji,jj,jl)    = v_i(ji,jj,jl) / MAX(a_i(ji,jj,jl),epsi10) * zindb
-               zindb             = 1.0-MAX(0.0,SIGN(1.0,-old_a_i(ji,jj,jl))) !0 if no ice and 1 if yes
+               zindb             = 1.0-MAX(0.0,SIGN(1.0,-old_a_i(ji,jj,jl)+epsi10)) !0 if no ice and 1 if yes
                zht_i_o(ji,jj,jl) = old_v_i(ji,jj,jl) / MAX(old_a_i(ji,jj,jl),epsi10) * zindb
                IF( a_i(ji,jj,jl) > 1e-6 )   zdhice(ji,jj,jl) = ht_i(ji,jj,jl) - zht_i_o(ji,jj,jl) 
@@ -405,5 +438,5 @@
                      * 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)
+                  v_i(zji,zjj,klbnd)  = a_i(zji,zjj,klbnd)*ht_i(zji,zjj,klbnd) ! clem@useless
                ENDIF     ! zetamax > 0
                ! ji, a_i > epsi10
@@ -499,5 +532,5 @@
             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)
+            v_i(zji,zjj,1)  = a_i(zji,zjj,1)*ht_i(zji,zjj,1) !clem@useless
          ENDIF
       END DO !ji
@@ -859,5 +892,5 @@
                   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
+                  zindsn          =  1.0 - MAX(0.0,SIGN(1.0,-v_s(ji,jj,jl)+epsi10)) !0 if no ice and 1 if yes
                ELSE
                   ht_i(ji,jj,jl)  = 0._wp
@@ -968,4 +1001,10 @@
                   zdaice(ji,jj,jl)  = a_i(ji,jj,jl)
                   zdvice(ji,jj,jl)  = v_i(ji,jj,jl)
+                  ! begin TECLIM change
+                  ! zdaice(ji,jj,jl)  = a_i(ji,jj,jl) 
+                  ! zdvice(ji,jj,jl)  = v_i(ji,jj,jl)
+                  zdaice(ji,jj,jl)  = a_i(ji,jj,jl)/2
+                  zdvice(ji,jj,jl)  = v_i(ji,jj,jl)-zdaice(ji,jj,jl)*(hi_max(jl)+hi_max(jl-1))/2
+                  ! end TECLIM change 
                ENDIF
             END DO                 ! ji
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90	(revision 3938)
@@ -35,4 +35,9 @@
    USE dom_ice_2        ! LIM2: ice domain
 #endif
+   USE lib_fortran      ! to use key_nosignedzero
+
+#if defined key_bdy
+   USE bdyice_lim
+#endif
 
    IMPLICIT NONE
@@ -43,4 +48,5 @@
    REAL(wp) ::   rzero   = 0._wp   ! constant values
    REAL(wp) ::   rone    = 1._wp   ! constant values
+   REAL(wp) ::   epsi20  = 1.e-20_wp   ! constant values
       
    !! * Substitutions
@@ -189,5 +195,5 @@
 #endif
             ! tmi = 1 where there is ice or on land
-            tmi(ji,jj)    = 1._wp - ( 1._wp - MAX( 0._wp , SIGN ( 1._wp , vt_i(ji,jj) - epsd ) ) ) * tms(ji,jj)
+            tmi(ji,jj)    = 1._wp - ( 1._wp - MAX( 0._wp , SIGN ( 1._wp , vt_i(ji,jj) ) ) ) * tms(ji,jj)
          END DO
       END DO
@@ -569,4 +575,9 @@
 
          ENDIF
+         
+!#if defined key_bdy
+!         ! clem: change u_ice and v_ice at the boundary for each iteration
+!         CALL bdy_ice_lim_dyn()
+!#endif         
 
          IF(ln_ctl) THEN
@@ -580,14 +591,14 @@
          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
+      !clem : add hminrhg in the namelist
+      !
+      ! If the ice thickness is below hminrhg (5cm) then ice velocity should equal the
       ! ocean velocity, 
       ! This prevents high velocity when ice is thin
@@ -598,5 +609,5 @@
             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
+            IF ( zdummy .LE. hminrhg ) THEN
                u_ice(ji,jj) = u_oce(ji,jj)
                v_ice(ji,jj) = v_oce(ji,jj)
@@ -607,4 +618,9 @@
       CALL lbc_lnk( u_ice(:,:), 'U', -1. ) 
       CALL lbc_lnk( v_ice(:,:), 'V', -1. ) 
+
+      ! clem: change u_ice and v_ice at the boundary
+#if defined key_bdy
+      CALL bdy_ice_lim_dyn()
+#endif         
 
       DO jj = k_j1+1, k_jpj-1 
@@ -612,5 +628,5 @@
             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
+            IF ( zdummy .LE. hminrhg ) 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)) &
@@ -637,5 +653,5 @@
             zdummy = zindb * vt_i(ji,jj) / MAX(at_i(ji,jj) , 1.0e-06 )
 
-            IF ( zdummy .LE. 5.0e-2 ) THEN
+            IF ( zdummy .LE. hminrhg ) THEN
 
                zdd(ji,jj) = ( e2u(ji,jj)*u_ice(ji,jj)                      &
@@ -692,5 +708,14 @@
             divu_i (ji,jj) = zdd   (ji,jj)
             delta_i(ji,jj) = deltat(ji,jj)
-            shear_i(ji,jj) = zds   (ji,jj)
+            ! begin TECLIM change 
+            ! shear_i(ji,jj) = zds   (ji,jj)
+            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) 
+            shear_i(ji,jj) = SQRT( zdt(ji,jj)*zdt(ji,jj) + zdst*zdst )
+            ! end TECLIM change
          END DO
       END DO
@@ -699,5 +724,6 @@
       CALL lbc_lnk( divu_i (:,:), 'T', 1. )
       CALL lbc_lnk( delta_i(:,:), 'T', 1. )
-      CALL lbc_lnk( shear_i(:,:), 'F', 1. )
+      ! CALL lbc_lnk( shear_i(:,:), 'F', 1. )
+      CALL lbc_lnk( shear_i(:,:), 'T', 1. )
 
       ! * Store the stress tensor for the next time step
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90	(revision 3938)
@@ -25,4 +25,5 @@
    USE lib_mpp          ! MPP library
    USE wrk_nemo         ! work arrays
+   USE lib_fortran      ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
 
    IMPLICIT NONE
@@ -161,4 +162,6 @@
       CALL iom_rstput( iter, nitrst, numriw, 'v_ice'     , v_ice      )
       CALL iom_rstput( iter, nitrst, numriw, 'fsbbq'     , fsbbq      )
+      CALL iom_rstput( iter, nitrst, numriw, 'iatte'     , iatte      ) ! clem modif
+      CALL iom_rstput( iter, nitrst, numriw, 'oatte'     , oatte      ) ! clem modif
       CALL iom_rstput( iter, nitrst, numriw, 'stress1_i' , stress1_i  )
       CALL iom_rstput( iter, nitrst, numriw, 'stress2_i' , stress2_i  )
@@ -339,9 +342,9 @@
       !Control of date
 
-      IF( ( nit000 - INT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
+      IF( ( nit000 - NINT(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) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
+      IF( NINT(zfice) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
          &     CALL ctl_stop( 'lim_rst_read ===>>>> : problem with nn_fsbc in ice restart',  &
          &                   '   verify the file or rerun with the value 0 for the',         &
@@ -436,4 +439,6 @@
       CALL iom_get( numrir, jpdom_autoglo, 'v_ice'     , v_ice      )
       CALL iom_get( numrir, jpdom_autoglo, 'fsbbq'     , fsbbq      )
+      CALL iom_get( numrir, jpdom_autoglo, 'iatte'     , iatte      ) ! clem modif
+      CALL iom_get( numrir, jpdom_autoglo, 'oatte'     , oatte      ) ! clem modif
       CALL iom_get( numrir, jpdom_autoglo, 'stress1_i' , stress1_i  )
       CALL iom_get( numrir, jpdom_autoglo, 'stress2_i' , stress2_i  )
@@ -562,5 +567,5 @@
       END DO
       !
-      CALL iom_close( numrir )
+      !clem CALL iom_close( numrir )
       !
       CALL wrk_dealloc( nlay_i, zs_zero )
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90	(revision 3938)
@@ -10,4 +10,6 @@
    !!                 !                  + simplification of the ice-ocean stress calculation
    !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!             -   ! 2012    (D. Iovino) salt flux change
+   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -34,4 +36,6 @@
    USE prtctl           ! Print control
    USE cpl_oasis3, ONLY : lk_cpl
+   USE traqsr           ! clem: add penetration of solar flux into the calculation of heat budget
+   USE lib_fortran      ! to use key_nosignedzero
 
    IMPLICIT NONE
@@ -44,4 +48,5 @@
    REAL(wp)  ::   r1_rdtice            ! = 1. / rdt_ice 
    REAL(wp)  ::   epsi16 = 1.e-16_wp   ! constant values
+   REAL(wp)  ::   epsi20 = 1.e-20_wp   ! constant values
    REAL(wp)  ::   rzero  = 0._wp    
    REAL(wp)  ::   rone   = 1._wp
@@ -100,5 +105,6 @@
       INTEGER  ::   ifvt, i1mfr, idfr               ! some switches
       INTEGER  ::   iflt, ial, iadv, ifral, ifrdv
-      REAL(wp) ::   zinda, zfons, zpme              ! local scalars
+      REAL(wp) ::   zinda, zindb, zfons, zpme              ! local scalars
+      REAL(wp) ::   zfmm             ! IOVINO freezing minus melting (F-M) 
       REAL(wp), POINTER, DIMENSION(:,:) ::   zfcm1 , zfcm2    ! solar/non solar heat fluxes
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   zalb, zalbp   ! 2D/3D workspace
@@ -117,6 +123,7 @@
          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)       ) ) )
+            zindb   = 1.0 - MAX( rzero , SIGN( rone , - iatte(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 )
@@ -139,9 +146,10 @@
 
             !   computation the solar flux at ocean surface
-            zfcm1(ji,jj)   = pfrld(ji,jj) * qsr(ji,jj)  + ( 1. - pfrld(ji,jj) ) * fstric(ji,jj)
+            zfcm1(ji,jj)   = pfrld(ji,jj) * qsr(ji,jj)  + &
+                 &           zindb * ( 1. - pfrld(ji,jj) ) * fstric(ji,jj) / MAX( iatte(ji,jj), epsi20 )
             ! fstric     Solar flux transmitted trough the ice
             ! qsr        Net short wave heat flux on free ocean
             ! new line
-            fscmbq(ji,jj) = ( 1.0 - pfrld(ji,jj) ) * fstric(ji,jj)
+            fscmbq(ji,jj) = zindb * ( 1.0 - pfrld(ji,jj) ) * fstric(ji,jj) / MAX( iatte(ji,jj), epsi20 )
 
             !  computation the non solar heat flux at ocean surface
@@ -178,32 +186,36 @@
 
             !!gm   this IF prevents the vertorisation of the whole loop
-            IF ( ( ji == jiindx ) .AND. ( jj == jjindx) ) THEN
-               WRITE(numout,*) ' lim_sbc : heat fluxes '
-               WRITE(numout,*) ' qsr       : ', qsr(jiindx,jjindx)
-               WRITE(numout,*) ' zfcm1     : ', zfcm1(jiindx,jjindx)
-               WRITE(numout,*) ' pfrld     : ', pfrld(jiindx,jjindx)
-               WRITE(numout,*) ' fstric    : ', fstric (jiindx,jjindx)
-               WRITE(numout,*)
-               WRITE(numout,*) ' qns       : ', qns(jiindx,jjindx)
-               WRITE(numout,*) ' zfcm2     : ', zfcm2(jiindx,jjindx)
-               WRITE(numout,*) ' zfcm1     : ', zfcm1(jiindx,jjindx)
-               WRITE(numout,*) ' ifral     : ', ifral
-               WRITE(numout,*) ' ial       : ', ial  
-               WRITE(numout,*) ' qcmif     : ', qcmif(jiindx,jjindx)
-               WRITE(numout,*) ' qldif     : ', qldif(jiindx,jjindx)
-               WRITE(numout,*) ' qcmif / dt: ', qcmif(jiindx,jjindx) * r1_rdtice
-               WRITE(numout,*) ' qldif / dt: ', qldif(jiindx,jjindx) * r1_rdtice
-               WRITE(numout,*) ' ifrdv     : ', ifrdv
-               WRITE(numout,*) ' qfvbq     : ', qfvbq(jiindx,jjindx)
-               WRITE(numout,*) ' qdtcn     : ', qdtcn(jiindx,jjindx)
-               WRITE(numout,*) ' qfvbq / dt: ', qfvbq(jiindx,jjindx) * r1_rdtice
-               WRITE(numout,*) ' qdtcn / dt: ', qdtcn(jiindx,jjindx) * r1_rdtice
-               WRITE(numout,*) ' '
-               WRITE(numout,*) ' fdtcn     : ', fdtcn(jiindx,jjindx)
-               WRITE(numout,*) ' fhmec     : ', fhmec(jiindx,jjindx)
-               WRITE(numout,*) ' fheat_rpo : ', fheat_rpo(jiindx,jjindx)
-               WRITE(numout,*) ' fhbri     : ', fhbri(jiindx,jjindx)
-               WRITE(numout,*) ' fheat_res : ', fheat_res(jiindx,jjindx)
-            ENDIF
+          !  IF ( ( ji == jiindx ) .AND. ( jj == jjindx) ) THEN
+          !     WRITE(numout,*) 'lim_sbc : heat fluxes '
+          !     WRITE(numout,*) ' at_i      : ', at_i(jiindx,jjindx)
+          !     WRITE(numout,*) ' ht_i      : ', SUM( ht_i(jiindx,jjindx,1:jpl) )
+          !     WRITE(numout,*) ' ht_s      : ', SUM( ht_s(jiindx,jjindx,1:jpl) )
+          !     WRITE(numout,*)
+          !     WRITE(numout,*) ' qsr       : ', qsr(jiindx,jjindx)
+          !     WRITE(numout,*) ' zfcm1     : ', zfcm1(jiindx,jjindx)
+          !     WRITE(numout,*) ' pfrld     : ', pfrld(jiindx,jjindx)
+          !     WRITE(numout,*) ' fstric    : ', fstric (jiindx,jjindx)
+          !     WRITE(numout,*)
+          !     WRITE(numout,*) ' qns       : ', qns(jiindx,jjindx)
+          !     WRITE(numout,*) ' zfcm2     : ', zfcm2(jiindx,jjindx)
+          !     WRITE(numout,*) ' zfcm1     : ', zfcm1(jiindx,jjindx)
+          !     WRITE(numout,*) ' ifral     : ', ifral
+          !     WRITE(numout,*) ' ial       : ', ial  
+          !     WRITE(numout,*) ' qcmif     : ', qcmif(jiindx,jjindx)
+          !     WRITE(numout,*) ' qldif     : ', qldif(jiindx,jjindx)
+          !     !WRITE(numout,*) ' qcmif / dt: ', qcmif(jiindx,jjindx) * r1_rdtice
+          !     !WRITE(numout,*) ' qldif / dt: ', qldif(jiindx,jjindx) * r1_rdtice
+          !     WRITE(numout,*) ' ifrdv     : ', ifrdv
+          !     WRITE(numout,*) ' qfvbq     : ', qfvbq(jiindx,jjindx)
+          !     WRITE(numout,*) ' qdtcn     : ', qdtcn(jiindx,jjindx)
+          !     !WRITE(numout,*) ' qfvbq / dt: ', qfvbq(jiindx,jjindx) * r1_rdtice
+          !     !WRITE(numout,*) ' qdtcn / dt: ', qdtcn(jiindx,jjindx) * r1_rdtice
+          !     WRITE(numout,*) ' '
+          !     WRITE(numout,*) ' fdtcn     : ', fdtcn(jiindx,jjindx)
+          !     WRITE(numout,*) ' fhmec     : ', fhmec(jiindx,jjindx)
+          !     WRITE(numout,*) ' fheat_rpo : ', fheat_rpo(jiindx,jjindx)
+          !     WRITE(numout,*) ' fhbri     : ', fhbri(jiindx,jjindx)
+          !     WRITE(numout,*) ' fheat_res : ', fheat_res(jiindx,jjindx)
+          !  ENDIF
             !!gm   end
          END DO
@@ -236,8 +248,8 @@
             !  computing salt exchanges at the ice/ocean interface
             !  sice should be the same as computed with the ice model
-            zfons =  ( soce_0(ji,jj) - sice_0(ji,jj) ) * rdmicif(ji,jj) * r1_rdtice 
+            !zfons =  ( soce_0(ji,jj) - sice_0(ji,jj) ) * rdmicif(ji,jj) * r1_rdtice 
             ! SOCE
-            zfons =  ( sss_m (ji,jj) - sice_0(ji,jj) ) * rdmicif(ji,jj) * r1_rdtice
-
+            !zfons =  ( sss_m (ji,jj) - sice_0(ji,jj) ) * rdmicif(ji,jj) * r1_rdtice
+            zfmm = rdmicif(ji,jj) * r1_rdtice  ! IOVINO  
             !CT useless            !  salt flux for constant salinity
             !CT useless            fsalt(ji,jj)      =  zfons / ( sss_m(ji,jj) + epsi16 ) + fsalt_res(ji,jj)
@@ -247,8 +259,8 @@
             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_m(ji,jj) + epsi16 )
-            fseqv(ji,jj)      =  fseqv(ji,jj)     / ( sss_m(ji,jj) + epsi16 )
-            fsbri(ji,jj)      =  fsbri(ji,jj)     / ( sss_m(ji,jj) + epsi16 )
-            fsalt_rpo(ji,jj)  =  fsalt_rpo(ji,jj) / ( sss_m(ji,jj) + epsi16 )
+            ! fsalt_res(ji,jj)  =  fsalt_res(ji,jj) / ( sss_m(ji,jj) + epsi16 )
+            ! fseqv(ji,jj)      =  fseqv(ji,jj)     / ( sss_m(ji,jj) + epsi16 )
+            ! fsbri(ji,jj)      =  fsbri(ji,jj)     / ( sss_m(ji,jj) + epsi16 )
+            ! fsalt_rpo(ji,jj)  =  fsalt_rpo(ji,jj) / ( sss_m(ji,jj) + epsi16 )
 
             !  freshwater mass exchange (positive to the ice, negative for the ocean ?)
@@ -258,13 +270,15 @@
             !  POSITIVE FRESHWATER FLUX FROM THE OCEAN TO THE ICE [kg.m-2.s-1]
 
-            emp(ji,jj) = - zpme 
+            emp(ji,jj) =  - zpme + zfmm ! volume flux IOVINO  
+            ! emp(ji,jj) = - zpme 
          END DO
       END DO
 
       IF( num_sal == 2 ) THEN      ! variable ice salinity: brine drainage included in the salt flux
-         emps(:,:) = fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) + emp(:,:)
+         emps(:,:) =   fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ! + emp(:,:) ! IOVINO
       ELSE                         ! constant ice salinity:
-         emps(:,:) =              fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) + emp(:,:)
+         emps(:,:) =   fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ! + emp(:,:)              ! IOVINO
       ENDIF
+
 
       !-----------------------------------------------!
@@ -402,4 +416,7 @@
          END WHERE
       ENDIF
+      ! clem modif
+      iatte(:,:) = 1._wp
+      oatte(:,:) = 1._wp
       !
    END SUBROUTINE lim_sbc_init
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 3938)
@@ -11,4 +11,5 @@
    !!            3.3  ! 2010-11 (G. Madec) corrected snow melting heat (due to factor betas)
    !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -39,4 +40,5 @@
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
+   USE lib_fortran      ! to use key_nosignedzero
 
    IMPLICIT NONE
@@ -91,8 +93,20 @@
       REAL(wp) ::   zfntlat, zpareff, zareamin, zcoef   !    -         -
       REAL(wp), POINTER, DIMENSION(:,:) ::   zqlbsbq   ! link with lead energy budget qldif
+      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
       !!-------------------------------------------------------------------
 
       CALL wrk_alloc( jpi, jpj, zqlbsbq )
    
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
+         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
+      ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
+
       !------------------------------------------------------------------------------!
       ! 1) Initialization of diagnostic variables                                    !
@@ -108,5 +122,5 @@
                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
+                  e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) / ( area(ji,jj) * MAX( v_i(ji,jj,jl) , epsi06 ) ) * REAL( nlay_i )
                   !0 if no ice and 1 if yes
                   zindb = 1.0 - MAX ( 0.0 , SIGN ( 1.0 , - ht_i(ji,jj,jl) ) ) 
@@ -120,5 +134,5 @@
                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
+                  e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) / ( area(ji,jj) * MAX( v_s(ji,jj,jl) , epsi06 ) ) * REAL( nlay_s )
                   !0 if no ice and 1 if yes
                   zindb = 1.0 - MAX ( 0.0 , SIGN ( 1.0 , - ht_s(ji,jj,jl) ) ) 
@@ -133,17 +147,17 @@
       ! 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
+      !clem rdvosif(:,:) = 0.e0   ! variation of ice volume at surface
+      !clem rdvobif(:,:) = 0.e0   ! variation of ice volume at bottom
+      !clem fdvolif(:,:) = 0.e0   ! total variation of ice volume
+      !clem rdvonif(:,:) = 0.e0   ! lateral variation of ice volume
+      !clem fstric (:,:) = 0.e0   ! part of solar radiation transmitted through the ice
+      !clem ffltbif(:,:) = 0.e0   ! linked with fstric
+      !clem qfvbq  (:,:) = 0.e0   ! linked with fstric
+      !clem rdmsnif(:,:) = 0.e0   ! variation of snow mass per unit area
+      !clem rdmicif(:,:) = 0.e0   ! variation of ice mass per unit area
+      !clem hicifp (:,:) = 0.e0   ! daily thermodynamic ice production. 
+      !clem fsbri  (:,:) = 0.e0   ! brine flux contribution to salt flux to the ocean
+      !clem fhbri  (:,:) = 0.e0   ! brine flux contribution to heat flux to the ocean
+      !clem fseqv  (:,:) = 0.e0   ! equivalent salt flux to the ocean due to ice/growth decay
 
       !-----------------------------------
@@ -164,9 +178,9 @@
 !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 ) ) ) 
+            !clem zthsnice       = SUM( ht_s(ji,jj,1:jpl) ) + SUM( ht_i(ji,jj,1:jpl) )
+            !clem zindb          = tms(ji,jj) * ( 1.0 - MAX( zzero , SIGN( zone , - zthsnice + epsi20 ) ) ) 
             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) ) ) )
+            zinda          = tms(ji,jj) * (1.0 - MAX( zzero , SIGN( zone , - at_i(ji,jj) ) ) )
             !
             !           !  solar irradiance transmission at the mixed layer bottom and used in the lead heat budget
@@ -179,16 +193,16 @@
 
             ! here the drag will depend on ice thickness and type (0.006)
-            fdtcn(ji,jj)  = zindb * rau0 * rcp * 0.006  * zfric_u * ( (sst_m(ji,jj) + rt0) - t_bo(ji,jj) ) 
+            fdtcn(ji,jj)  = zinda * rau0 * rcp * 0.006  * zfric_u * ( (sst_m(ji,jj) + rt0) - t_bo(ji,jj) ) 
             ! also category dependent
             !           !-- Energy from the turbulent oceanic heat flux heat flux coming in the lead 
-            qdtcn(ji,jj)  = zindb * fdtcn(ji,jj) * (1.0 - at_i(ji,jj)) * rdt_ice
+            qdtcn(ji,jj)  = zinda * fdtcn(ji,jj) * (1.0 - at_i(ji,jj)) * rdt_ice
             !                       
             !           !-- Lead heat budget, qldif (part 1, next one is in limthd_dh) 
             !           !   caution: exponent betas used as more snow can fallinto leads
             qldif(ji,jj) =  tms(ji,jj) * rdt_ice  * (                             &
-               &   pfrld(ji,jj)        * (  qsr(ji,jj)                            &   ! solar heat
+               &   pfrld(ji,jj)        * (  qsr(ji,jj) * oatte(ji,jj)             &   ! solar heat + clem modif
                &                            + qns(ji,jj)                          &   ! non solar heat
                &                            + fdtcn(ji,jj)                        &   ! turbulent ice-ocean heat
-               &                            + fsbbq(ji,jj) * ( 1.0 - zindb )  )   &   ! residual heat from previous step
+               &                            + fsbbq(ji,jj) * ( 1.0 - zinda )  )   &   ! residual heat from previous step
                & - pfrld(ji,jj)**betas * sprecip(ji,jj) * lfus                    )   ! latent heat of sprecip melting
             !
@@ -205,8 +219,8 @@
             !
             ! 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_m(ji,jj) + rt0) ) * ( 1. - zinda )
+            qcmif  (ji,jj) =  rau0 * rcp * fse3t(ji,jj,1) * ( t_bo(ji,jj) - (sst_m(ji,jj) + rt0) ) !!clem * ( 1. - zinda )
             !
             ! oceanic heat flux (limthd_dh)
-            fbif   (ji,jj) = zindb * (  fsbbq(ji,jj) / MAX( at_i(ji,jj) , epsi20 ) + fdtcn(ji,jj) )
+            fbif   (ji,jj) = zinda * (  fsbbq(ji,jj) / MAX( at_i(ji,jj) , epsi20 ) + fdtcn(ji,jj) )
             !
          END DO
@@ -294,5 +308,6 @@
             CALL tab_2d_1d( nbpb, fstbif_1d  (1:nbpb), fstric     , jpi, jpj, npb(1:nbpb) )
             CALL tab_2d_1d( nbpb, qfvbq_1d   (1:nbpb), qfvbq      , jpi, jpj, npb(1:nbpb) )
-
+            CALL tab_2d_1d( nbpb, iatte_1d   (1:nbpb), iatte(:,:) , jpi, jpj, npb(1:nbpb) ) ! clem modif
+            CALL tab_2d_1d( nbpb, oatte_1d   (1:nbpb), oatte(:,:) , jpi, jpj, npb(1:nbpb) ) ! clem modif
             !--------------------------------
             ! 4.3) Thermodynamic processes
@@ -305,7 +320,7 @@
             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 )
@@ -314,13 +329,10 @@
             CALL lim_thd_dh( 1, nbpb, jl )    ! Ice/Snow thickness              ! 
             !                                 !---------------------------------!
-
             !                                 !---------------------------------!
             CALL lim_thd_ent( 1, nbpb, jl )   ! Ice/Snow enthalpy remapping     !
             !                                 !---------------------------------!
-
             !                                 !---------------------------------!
             CALL lim_thd_sal( 1, nbpb )       ! Ice salinity computation        !
             !                                 !---------------------------------!
-
             !           CALL lim_thd_enmelt(1,nbpb)   ! computes sea ice energy of melting
             IF( con_i )   CALL lim_thd_glohec( qt_i_fin, qt_s_fin, q_i_layer_fin, 1, nbpb, jl ) 
@@ -418,6 +430,6 @@
       ! 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
+!clem@useless      d_v_i_thd(:,:,:) = v_i      (:,:,:) - old_v_i(:,:,:)    ! ice volumes 
+!clem@mv-to-itd    dv_dt_thd(:,:,:) = d_v_i_thd(:,:,:) / rdt_ice * 86400.0
 
       IF( con_i )   fbif(:,:) = fbif(:,:) + zqlbsbq(:,:)
@@ -455,4 +467,23 @@
       ENDIF
       !
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
+         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
+ 
+         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
+         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
+
+         IF(lwp) THEN
+            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limthd) = ',(zchk_v_i * 86400.)
+            IF (    ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limthd) = ',(zchk_smv * 86400.)
+            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limthd) = ',(MINVAL(v_i) * 1.e-3)
+            IF ( MAXVAL( SUM(a_i(:,:,:),dim=3) ) >  amax+epsi10 ) WRITE(numout,*) 'violation a_i>amax    (limthd) = ',MAXVAL(SUM(a_i,dim=3))
+         ENDIF
+      ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
+      !
       CALL wrk_dealloc( jpi, jpj, zqlbsbq )
       !
@@ -479,10 +510,10 @@
       DO jk = 1, nlay_i                ! total q over all layers, ice [J.m-2]
          DO ji = kideb, kiut
-            etilayer(ji,jk) = q_i_b(ji,jk) * ht_i_b(ji) / nlay_i
+            etilayer(ji,jk) = q_i_b(ji,jk) * ht_i_b(ji) / REAL( nlay_i )
             eti     (ji,jl) = eti(ji,jl) + etilayer(ji,jk) 
          END DO
       END DO
       DO ji = kideb, kiut              ! total q over all layers, snow [J.m-2]
-         ets(ji,jl) = ets(ji,jl) + q_s_b(ji,1) * ht_s_b(ji) / nlay_s
+         ets(ji,jl) = ets(ji,jl) + q_s_b(ji,1) * ht_s_b(ji) / REAL( nlay_s )
       END DO
       !
@@ -799,5 +830,5 @@
       !!-------------------------------------------------------------------
       NAMELIST/namicethd/ hmelt , hiccrit, fraz_swi, maxfrazb, vfrazb, Cfrazb,   &
-         &                hicmin, hiclim, amax  ,                                &
+         &                hicmin, hiclim,                                        &
          &                sbeta  , parlat, hakspl, hibspl, exld,                 &
          &                hakdif, hnzst  , thth  , parsub, alphs, betas,         & 
@@ -825,5 +856,4 @@
          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
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 3938)
@@ -24,4 +24,5 @@
    USE lib_mpp          ! MPP library
    USE wrk_nemo         ! work arrays
+   USE lib_fortran      ! to use key_nosignedzero
 
    IMPLICIT NONE
@@ -72,8 +73,9 @@
       INTEGER  ::   ji , jk        ! dummy loop indices
       INTEGER  ::   zji, zjj       ! 2D corresponding indices to ji
-      INTEGER  ::   isnow          ! switch for presence (1) or absence (0) of snow
-      INTEGER  ::   isnowic        ! snow ice formation not
-      INTEGER  ::   i_ice_switch   ! ice thickness above a certain treshold or not
       INTEGER  ::   iter
+
+      REAL(wp) ::   isnow          ! switch for presence (1) or absence (0) of snow
+      REAL(wp) ::   isnowic        ! snow ice formation not
+      REAL(wp) ::   i_ice_switch   ! ice thickness above a certain treshold or not
 
       REAL(wp) ::   zzfmass_i, zihgnew                     ! local scalar
@@ -118,4 +120,8 @@
       REAL(wp), POINTER, DIMENSION(:,:) ::   zqt_i_lay   ! total ice heat content
 
+      ! mass and salt flux (clem)
+      REAL(wp) :: zdvres
+      REAL(wp), POINTER, DIMENSION(:) ::   zviold, zvsold   ! old ice volume...
+
       ! Heat conservation 
       INTEGER  ::   num_iter_max, numce_dh
@@ -130,12 +136,19 @@
       CALL wrk_alloc( jpij, jkmax, zdeltah, zqt_i_lay )
 
+      CALL wrk_alloc( jpij, zviold, zvsold ) ! clem
+      
       zfsalt_melt(:)  = 0._wp
       ftotal_fin(:)   = 0._wp
       zfdt_init(:)    = 0._wp
       zfdt_final(:)   = 0._wp
+      dh_i_surf(:)    = 0._wp
+      dh_i_bott(:)    = 0._wp
+      dh_snowice(:)    = 0._wp
 
       DO ji = kideb, kiut
          old_ht_i_b(ji) = ht_i_b(ji)
          old_ht_s_b(ji) = ht_s_b(ji)
+         zviold(ji) = a_i_b(ji) * ht_i_b(ji) ! clem
+         zvsold(ji) = a_i_b(ji) * ht_s_b(ji) ! clem
       END DO
       !
@@ -145,5 +158,5 @@
       !
       DO ji = kideb, kiut
-         isnow         = INT( 1.0 - MAX ( 0.0 , SIGN ( 1.0 , - ht_s_b(ji) ) ) )
+         isnow         = 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)
@@ -162,6 +175,6 @@
       !
       DO ji = kideb, kiut     ! Layer thickness
-         zh_i(ji) = ht_i_b(ji) / nlay_i
-         zh_s(ji) = ht_s_b(ji) / nlay_s
+         zh_i(ji) = ht_i_b(ji) / REAL( nlay_i )
+         zh_s(ji) = ht_s_b(ji) / REAL( nlay_s )
       END DO
       !
@@ -169,5 +182,5 @@
       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
+            zqt_s(ji) =  zqt_s(ji) + q_s_b(ji,jk) * ht_s_b(ji) / REAL( nlay_s )
          END DO
       END DO
@@ -176,5 +189,5 @@
       DO jk = 1, nlay_i
          DO ji = kideb, kiut
-            zzc = q_i_b(ji,jk) * ht_i_b(ji) / nlay_i
+            zzc = q_i_b(ji,jk) * ht_i_b(ji) / REAL( nlay_i )
             zqt_i(ji)        =  zqt_i(ji) + zzc
             zqt_i_lay(ji,jk) =              zzc
@@ -243,7 +256,8 @@
          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) =  a_i_b(ji) * ( ht_s_b(ji) - zhsold(ji) - zdh_s_mel(ji) )
+         dvsbq_1d  (ji) =  a_i_b(ji) * ( ht_s_b(ji) - zhsold(ji) - zdh_s_pre(ji) )   ! IOVINO
          dvsbq_1d  (ji) =  MIN( zzero, dvsbq_1d(ji) )
-         rdmsnif_1d(ji) =  rdmsnif_1d(ji) + rhosn * dvsbq_1d(ji)
+         !clem rdmsnif_1d(ji) =  rdmsnif_1d(ji) + rhosn * dvsbq_1d(ji)
       END DO ! ji
 
@@ -252,5 +266,4 @@
       !--------------------------
       DO ji = kideb, kiut 
-         dh_i_surf(ji) =  0._wp
          z_f_surf (ji) =  zqfont_su(ji) / rdt_ice ! heat conservation test
          zdq_i    (ji) =  0._wp
@@ -270,9 +283,9 @@
             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_m(zji,zjj) - sm_i_b(ji) ) * a_i_b(ji)    &
-               &                              * MIN( zdeltah(ji,jk) , 0.e0 ) * rhoic / rdt_ice 
+            ! IOVINO
+            !zfsalt_melt(ji) = zfsalt_melt(ji) - sm_i_b(ji) * a_i_b(ji)    &
+            !   &                              * MIN( zdeltah(ji,jk) , 0.e0 ) * rhoic / rdt_ice
+            fseqv_1d(ji) = fseqv_1d(ji) - sm_i_b(ji) * a_i_b(ji)    &
+               &                              * MIN( zdeltah(ji,jk) , 0._wp ) * rhoic / rdt_ice
          END DO
       END DO
@@ -331,5 +344,5 @@
          DO ji = kideb,kiut
             q_s_b    (ji,jk) = rhosn * ( cpic * ( rtt - t_s_b(ji,jk) ) + lfus )
-            zqt_dummy(ji)    =  zqt_dummy(ji) + q_s_b(ji,jk) * ht_s_b(ji) / nlay_s            ! heat conservation
+            zqt_dummy(ji)    =  zqt_dummy(ji) + q_s_b(ji,jk) * ht_s_b(ji) / REAL( nlay_s )            ! heat conservation
          END DO
       END DO
@@ -372,4 +385,5 @@
                ! 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) 
+               fseqv_1d(ji) = fseqv_1d(ji) - s_i_new(ji) * a_i_b(ji) * dh_i_bott(ji) * rhoic / rdt_ice
             ENDIF
          END DO
@@ -437,4 +451,5 @@
                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) ,epsi13 ) - sm_i_b(ji)
+               fseqv_1d(ji) = fseqv_1d(ji) - s_i_new(ji) * a_i_b(ji) * dh_i_bott(ji) * rhoic / rdt_ice
             ENDIF ! heat budget
          END DO
@@ -473,10 +488,10 @@
                   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_m(zji,zjj) - sm_i_b(ji)   ) * a_i_b(ji)   &
-                     &                              * MIN( zdeltah(ji,jk) , 0.0 ) * rhoic / rdt_ice 
                ENDIF
+               ! IOVINO contribution to salt flux
+               !zfsalt_melt(ji) = zfsalt_melt(ji) - sm_i_b(ji) * a_i_b(ji)   &
+               !     &                              * MIN( zdeltah(ji,jk) , 0._wp ) * rhoic / rdt_ice
+               fseqv_1d(ji) = fseqv_1d(ji) - sm_i_b(ji) * a_i_b(ji)    &
+                    &                              * MIN( zdeltah(ji,jk) , 0._wp ) * rhoic / rdt_ice
             ENDIF
          END DO ! ji
@@ -529,18 +544,13 @@
          ELSE                  ;   zdhbf =              dh_i_bott(ji) 
          ENDIF
+         zdvres        = zdhbf - dh_i_bott(ji)
+         dh_i_bott(ji) = zdhbf
+         fseqv_1d(ji)  = fseqv_1d(ji) - sm_i_b(ji) * a_i_b(ji) * zdvres * rhoic / rdt_ice
          !                     ! 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
+         fsup     (ji) =  rhoic * lfus * at_i_b(ji) / MAX( 1.0 - at_i_b(ji) , epsi13 ) * zdvres / rdt_ice
          !                     !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
 
@@ -554,6 +564,7 @@
          ! Adapt the remaining energy if too much ice melts
          !--------------------------------------------------
+         zdvres     = MAX( 0._wp, - zhgnew(ji) )
          zihgnew    =  1.0 - MAX( zzero , SIGN( zone , - zhgnew(ji) ) ) !1 if ice
-         ! 0 if no more ice
+         dh_i_bott (ji) = dh_i_bott(ji) + zdvres ! clem@bug
          zhgnew    (ji) =         zihgnew   * zhgnew(ji)      ! ice thickness is put to 0
          ! remaining heat
@@ -581,11 +592,18 @@
          !
          !                                              ! mass variation cumulated over category
-         rdmsnif_1d(ji) = rdmsnif_1d(ji) + zzfmass_s                     ! snow 
-         rdmicif_1d(ji) = rdmicif_1d(ji) + zzfmass_i                     ! ice 
+         !clem rdmsnif_1d(ji) = rdmsnif_1d(ji) + zzfmass_s                     ! snow 
+         !clem rdmicif_1d(ji) = rdmicif_1d(ji) + zzfmass_i                     ! ice 
 
          ! Remaining heat to the ocean 
          !---------------------------------
          focea(ji)  = - zfdt_final(ji) / rdt_ice         ! focea is in W.m-2 * dt
-
+         ! salt flux
+         fseqv_1d(ji)  = fseqv_1d(ji) - sm_i_b(ji) * a_i_b(ji) * zdvres * rhoic / rdt_ice
+         !                     ! 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
 
@@ -602,11 +620,13 @@
          zjj = ( npb(ji) - 1 ) / jpi + 1
          ! new lines
-         IF( num_sal == 4 ) THEN
-            fseqv_1d(ji) = fseqv_1d(ji) +        zihgnew  * zfsalt_melt(ji)                                &
-               &                        + (1.0 - zihgnew) * zfmass_i(ji) * ( sss_m(zji,zjj) - bulk_sal   ) / rdt_ice
-         ELSE
-            fseqv_1d(ji) = fseqv_1d(ji) +        zihgnew  * zfsalt_melt(ji)                                &
-               &                        + (1.0 - zihgnew) * zfmass_i(ji) * ( sss_m(zji,zjj) - sm_i_b(ji) ) / rdt_ice
-         ENDIF
+         !IF( num_sal == 4 ) THEN
+         !   ! IOVINO
+         !   fseqv_1d(ji) = fseqv_1d(ji) +        zihgnew  * zfsalt_melt(ji)                                &
+         !      &                        - (1.0 - zihgnew) * zfmass_i(ji) * bulk_sal / rdt_ice
+         !ELSE
+         !   ! IOVINO
+         !   fseqv_1d(ji) = fseqv_1d(ji) +        zihgnew  * zfsalt_melt(ji)                                &
+         !      &                        - (1.0 - zihgnew) * zfmass_i(ji) * sm_i_b(ji) / rdt_ice 
+         !ENDIF
          ! Heat flux
          ! excessive bottom ablation energy (fsup) - 0 except if jpl = 1
@@ -619,4 +639,9 @@
          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
+         !IF ( (zji.eq.jiindx).AND.(zjj.eq.jjindx) ) THEN
+         !   !clemclem
+         !   WRITE(numout,*) 'lim_thd_dh : qldif = ', qldif_1d(ji)
+         !   !clemclem
+         !ENDIF
       END DO  ! ji
 
@@ -656,6 +681,6 @@
          dmgwi_1d  (ji) = dmgwi_1d(ji) + a_i_b(ji) * ( ht_s_b(ji) - zhnnew ) * rhosn
 
-         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
+         !clem rdmicif_1d(ji) = rdmicif_1d(ji) + a_i_b(ji) * ( zhgnew(ji) - ht_i_b(ji) ) * rhoic 
+         !clem rdmsnif_1d(ji) = rdmsnif_1d(ji) + a_i_b(ji) * ( zhnnew     - ht_s_b(ji) ) * rhosn 
 
          !        Equivalent salt flux (1) Snow-ice formation component
@@ -667,18 +692,22 @@
          ELSE                      ;   zsm_snowice = ( rhoic - rhosn ) / rhoic * sss_m(zji,zjj) 
          ENDIF
-         IF( num_sal == 4 ) THEN
-            fseqv_1d(ji) = fseqv_1d(ji) + ( sss_m(zji,zjj) - bulk_sal    ) * a_i_b(ji)   &
-               &                        * ( zhgnew(ji) - ht_i_b(ji) ) * rhoic / rdt_ice
-         ELSE
-            fseqv_1d(ji) = fseqv_1d(ji) + ( sss_m(zji,zjj) - zsm_snowice ) * a_i_b(ji)   &
-               &                        * ( zhgnew(ji) - ht_i_b(ji) ) * rhoic / rdt_ice
-         ENDIF
+         !IF( num_sal == 4 ) THEN  
+         !   ! IOVINO
+         !   fseqv_1d(ji) = fseqv_1d(ji) - bulk_sal * a_i_b(ji) * dh_snowice(ji) * rhoic / rdt_ice
+         !ELSE
+         !   ! IOVINO
+         !   fseqv_1d(ji) = fseqv_1d(ji) - zsm_snowice * a_i_b(ji) * dh_snowice(ji) * rhoic / rdt_ice
+         !ENDIF
          ! entrapment during snow ice formation
-         i_ice_switch = 1.0 - MAX( 0.e0 , SIGN( 1.0 , - ht_i_b(ji) + 1.0e-6 ) )
-         isnowic      = 1.0 - MAX( 0.e0 , SIGN( 1.0 , - dh_snowice(ji)      ) ) * i_ice_switch
-         IF(  num_sal == 2  .OR.  num_sal == 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), epsi13)   &
-            &               - sm_i_b(ji) ) * isnowic     
+         i_ice_switch = 1.0 - MAX( 0.e0 , SIGN( 1.0 , - ht_i_b(ji) + epsi13 ) )
+         isnowic      = 1.0 - MAX( 0.e0 , SIGN( 1.0 , - dh_snowice(ji) ) ) * i_ice_switch
+
+         !clem IF(  num_sal == 2  .OR.  num_sal == 4  )   &
+         !clem   dsm_i_si_1d(ji) = ( zsm_snowice*dh_snowice(ji) &
+         !clem   &               + sm_i_b(ji) * ht_i_b(ji) / MAX( ht_i_b(ji) + dh_snowice(ji), epsi13)   &
+         !clem   &               - sm_i_b(ji) ) * isnowic
+         IF (  num_sal == 2  .OR.  num_sal == 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), epsi13 ) - sm_i_b(ji) ) * isnowic     
 
          !  Actualize new snow and ice thickness.
@@ -693,5 +722,13 @@
          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
-         !
+
+         ! salt flux
+         fseqv_1d(ji) = fseqv_1d(ji) - zsm_snowice * a_i_b(ji) * dh_snowice(ji) * rhoic / rdt_ice
+         !--------------------------------
+         ! Update mass fluxes (clem)
+         !--------------------------------
+         rdmicif_1d(ji) = rdmicif_1d(ji) + ( a_i_b(ji) * ht_i_b(ji) - zviold(ji) ) * rhoic 
+         rdmsnif_1d(ji) = rdmsnif_1d(ji) + ( a_i_b(ji) * ht_s_b(ji) - zvsold(ji) ) * rhosn 
+
       END DO !ji
       !
@@ -700,4 +737,6 @@
       CALL wrk_dealloc( jpij, zinnermelt, zfbase, zdq_i )
       CALL wrk_dealloc( jpij, jkmax, zdeltah, zqt_i_lay )
+      !
+      CALL wrk_dealloc( jpij, zviold, zvsold ) ! clem
       !
    END SUBROUTINE lim_thd_dh
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90	(revision 3938)
@@ -10,4 +10,5 @@
    !!                 ! 04-2007 (M. Vancoppenolle) Energy conservation
    !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -23,4 +24,5 @@
    USE lib_mpp          ! MPP library
    USE wrk_nemo         ! work arrays
+   USE lib_fortran      ! to use key_nosignedzero
 
    IMPLICIT NONE
@@ -102,7 +104,44 @@
       INTEGER ::   nconv       ! number of iterations in iterative procedure
       INTEGER ::   minnumeqmin, maxnumeqmax
-      INTEGER, DIMENSION(kiut) ::   numeqmin   ! reference number of top equation
-      INTEGER, DIMENSION(kiut) ::   numeqmax   ! reference number of bottom equation
-      INTEGER, DIMENSION(kiut) ::   isnow      ! switch for presence (1) or absence (0) of snow
+
+      INTEGER , DIMENSION(kiut) ::   numeqmin   ! reference number of top equation
+      INTEGER , DIMENSION(kiut) ::   numeqmax   ! reference number of bottom equation
+      INTEGER , DIMENSION(kiut) ::   isnow      ! switch for presence (1) or absence (0) of snow
+
+      !! * New local variables       
+      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   ztcond_i   !Ice thermal conductivity
+      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zradtr_i   !Radiation transmitted through the ice
+      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zradab_i   !Radiation absorbed in the ice
+      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zkappa_i   !Kappa factor in the ice
+
+      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zradtr_s   !Radiation transmited through the snow
+      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zradab_s   !Radiation absorbed in the snow
+      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zkappa_s   !Kappa factor in the snow
+
+      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   ztiold      !Old temperature in the ice
+      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zeta_i      !Eta factor in the ice 
+      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   ztitemp     !Temporary temperature in the ice to check the convergence
+      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zspeche_i   !Ice specific heat
+      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   z_i         !Vertical cotes of the layers in the ice
+
+      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zeta_s      !Eta factor in the snow
+      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   ztstemp     !Temporary temperature in the snow to check the convergence
+      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   ztsold      !Temporary temperature in the snow
+      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   z_s         !Vertical cotes of the layers in the snow
+
+      REAL(wp), DIMENSION(kiut,jkmax+2)   ::   zindterm    ! Independent term
+      REAL(wp), DIMENSION(kiut,jkmax+2)   ::   zindtbis    ! temporary independent term
+      REAL(wp), DIMENSION(kiut,jkmax+2)   ::   zdiagbis
+      REAL(wp), DIMENSION(kiut,jkmax+2,3) ::   ztrid       ! tridiagonal system terms
+
+      REAL(wp), DIMENSION(kiut) ::   ztfs        ! ice melting point
+      REAL(wp), DIMENSION(kiut) ::   ztsuold     ! old surface temperature (before the iterative procedure )
+      REAL(wp), DIMENSION(kiut) ::   ztsuoldit   ! surface temperature at previous iteration
+      REAL(wp), DIMENSION(kiut) ::   zh_i        ! ice layer thickness
+      REAL(wp), DIMENSION(kiut) ::   zh_s        ! snow layer thickness
+      REAL(wp), DIMENSION(kiut) ::   zfsw        ! solar radiation absorbed at the surface
+      REAL(wp), DIMENSION(kiut) ::   zf          ! surface flux function
+      REAL(wp), DIMENSION(kiut) ::   dzf         ! derivative of the surface flux function
+
       REAL(wp) ::   zeps      =  1.e-10_wp    !
       REAL(wp) ::   zg1s      =  2._wp        ! for the tridiagonal system
@@ -113,41 +152,13 @@
       REAL(wp) ::   zkimin    =  0.10_wp      ! minimum ice thermal conductivity
       REAL(wp) ::   zht_smin  =  1.e-4_wp     ! minimum snow depth
+
       REAL(wp) ::   ztmelt_i    ! ice melting temperature
       REAL(wp) ::   zerritmax   ! current maximal error on temperature 
-      REAL(wp), DIMENSION(kiut) ::   ztfs        ! ice melting point
-      REAL(wp), DIMENSION(kiut) ::   ztsuold     ! old surface temperature (before the iterative procedure )
-      REAL(wp), DIMENSION(kiut) ::   ztsuoldit   ! surface temperature at previous iteration
-      REAL(wp), DIMENSION(kiut) ::   zh_i        ! ice layer thickness
-      REAL(wp), DIMENSION(kiut) ::   zh_s        ! snow layer thickness
-      REAL(wp), DIMENSION(kiut) ::   zfsw        ! solar radiation absorbed at the surface
-      REAL(wp), DIMENSION(kiut) ::   zf          ! surface flux function
-      REAL(wp), DIMENSION(kiut) ::   dzf         ! derivative of the surface flux function
-      REAL(wp), DIMENSION(kiut) ::   zerrit      ! current error on temperature
-      REAL(wp), DIMENSION(kiut) ::   zdifcase    ! case of the equation resolution (1->4)
-      REAL(wp), DIMENSION(kiut) ::   zftrice     ! solar radiation transmitted through the ice
+      REAL(wp), DIMENSION(kiut) ::   zerrit       ! current error on temperature 
+      REAL(wp), DIMENSION(kiut) ::   zdifcase     ! case of the equation resolution (1->4)
+      REAL(wp), DIMENSION(kiut) ::   zftrice      ! solar radiation transmitted through the ice
       REAL(wp), DIMENSION(kiut) ::   zihic, zhsu
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   ztcond_i    ! Ice thermal conductivity
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zradtr_i    ! Radiation transmitted through the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zradab_i    ! Radiation absorbed in the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zkappa_i    ! Kappa factor in the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   ztiold      ! Old temperature in the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zeta_i      ! Eta factor in the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   ztitemp     ! Temporary temperature in the ice to check the convergence
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   zspeche_i   ! Ice specific heat
-      REAL(wp), DIMENSION(kiut,0:nlay_i) ::   z_i         ! Vertical cotes of the layers in the ice
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zradtr_s    ! Radiation transmited through the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zradab_s    ! Radiation absorbed in the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zkappa_s    ! Kappa factor in the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   zeta_s       ! Eta factor in the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   ztstemp      ! Temporary temperature in the snow to check the convergence
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   ztsold       ! Temporary temperature in the snow
-      REAL(wp), DIMENSION(kiut,0:nlay_s) ::   z_s          ! Vertical cotes of the layers in the snow
-      REAL(wp), DIMENSION(kiut,jkmax+2) ::   zindterm   ! Independent term
-      REAL(wp), DIMENSION(kiut,jkmax+2) ::   zindtbis   ! temporary independent term
-      REAL(wp), DIMENSION(kiut,jkmax+2) ::   zdiagbis
-      REAL(wp), DIMENSION(kiut,jkmax+2,3) ::   ztrid   ! tridiagonal system terms
       !!------------------------------------------------------------------
-      
-      ! 
+      !
       !------------------------------------------------------------------------------!
       ! 1) Initialization                                                            !
@@ -156,11 +167,11 @@
       DO ji = kideb , kiut
          ! is there snow or not
-         isnow(ji)= INT(  1._wp - MAX( 0._wp , SIGN(1._wp, - ht_s_b(ji) ) )  )
+         isnow(ji)= NINT(  1._wp - MAX( 0._wp , SIGN(1._wp, - ht_s_b(ji) ) )  )
          ! surface temperature of fusion
 !!gm ???  ztfs(ji) = rtt !!!????
-         ztfs(ji) = isnow(ji) * rtt + (1.0-isnow(ji)) * rtt
+         ztfs(ji) = REAL( isnow(ji) ) * rtt + REAL( 1 - isnow(ji) ) * rtt
          ! layer thickness
-         zh_i(ji) = ht_i_b(ji) / nlay_i
-         zh_s(ji) = ht_s_b(ji) / nlay_s
+         zh_i(ji) = ht_i_b(ji) / REAL( nlay_i )
+         zh_s(ji) = ht_s_b(ji) / REAL( nlay_s )
       END DO
 
@@ -174,5 +185,5 @@
       DO layer = 1, nlay_s            ! vert. coord of the up. lim. of the layer-th snow layer
          DO ji = kideb , kiut
-            z_s(ji,layer) = z_s(ji,layer-1) + ht_s_b(ji) / nlay_s
+            z_s(ji,layer) = z_s(ji,layer-1) + ht_s_b(ji) / REAL( nlay_s )
          END DO
       END DO
@@ -180,5 +191,5 @@
       DO layer = 1, nlay_i            ! vert. coord of the up. lim. of the layer-th ice layer
          DO ji = kideb , kiut
-            z_i(ji,layer) = z_i(ji,layer-1) + ht_i_b(ji) / nlay_i
+            z_i(ji,layer) = z_i(ji,layer-1) + ht_i_b(ji) / REAL( nlay_i )
          END DO
       END DO
@@ -201,10 +212,10 @@
       DO ji = kideb , kiut
          ! switches
-         isnow(ji) = INT(  1._wp - MAX( 0._wp , SIGN( 1._wp , - ht_s_b(ji) ) )  ) 
+         isnow(ji) = NINT(  1._wp - MAX( 0._wp , SIGN( 1._wp , - ht_s_b(ji) ) )  ) 
          ! hs > 0, isnow = 1
          zhsu (ji) = hnzst  ! threshold for the computation of i0
          zihic(ji) = MAX( 0._wp , 1._wp - ( ht_i_b(ji) / zhsu(ji) ) )     
 
-         i0(ji)    = ( 1._wp - isnow(ji) ) * ( fr1_i0_1d(ji) + zihic(ji) * fr2_i0_1d(ji) )
+         i0(ji)    = REAL( 1 - 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
@@ -243,5 +254,5 @@
 
       DO ji = kideb, kiut           ! ice initialization
-         zradtr_i(ji,0) = zradtr_s(ji,nlay_s) * isnow(ji) + zftrice(ji) * ( 1._wp - isnow(ji) )
+         zradtr_i(ji,0) = zradtr_s(ji,nlay_s) * REAL( isnow(ji) ) + zftrice(ji) * REAL( 1 - isnow(ji) )
       END DO
 
@@ -256,5 +267,5 @@
 
       DO ji = kideb, kiut           ! Radiation transmitted below the ice
-         fstbif_1d(ji) = fstbif_1d(ji) + zradtr_i(ji,nlay_i) * a_i_b(ji) / at_i_b(ji)
+         fstbif_1d(ji) = fstbif_1d(ji) + iatte_1d(ji) * zradtr_i(ji,nlay_i) * a_i_b(ji) / at_i_b(ji) ! clem modif
       END DO
 
@@ -264,5 +275,5 @@
          ii                = MOD( npb(ji) - 1, jpi ) + 1
          ij                = ( npb(ji) - 1 ) / jpi + 1
-         fstroc(ii,ij,jl) = zradtr_i(ji,nlay_i)
+         fstroc(ii,ij,jl) = iatte_1d(ji) * zradtr_i(ji,nlay_i) ! clem modif
       END DO
       ! +++++
@@ -273,5 +284,4 @@
          END DO
       END DO
-
 
       !
@@ -377,6 +387,6 @@
             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))
+            zkappa_i(ji,0)        = zkappa_s(ji,nlay_s)*REAL( isnow(ji) ) &
+               + zkappa_i(ji,0)*REAL( 1 - isnow(ji) )
          END DO
          !
@@ -659,12 +669,12 @@
                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)) 
+               *        MAX(0.0,SIGN(1.0,ht_s_b(ji))) 
 
             ! surface temperature
-            isnow(ji)     = INT(1.0-max(0.0,sign(1.0,-ht_s_b(ji))))
+            isnow(ji)     = NINT(1.0-max(0.0,SIGN(1.0,-ht_s_b(ji))))
             ztsuoldit(ji) = t_su_b(ji)
             IF (t_su_b(ji) .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))  
+               t_su_b(ji) = ( zindtbis(ji,numeqmin(ji)) - ztrid(ji,numeqmin(ji),3)* ( REAL( isnow(ji) )*t_s_b(ji,1)   &
+               &          + REAL( 1 - isnow(ji) )*t_i_b(ji,1) ) ) / zdiagbis(ji,numeqmin(ji))  
          END DO
          !
@@ -718,9 +728,10 @@
       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) )
+         ! qla_ice_1d (ji) =          qla_ice_1d (ji) + dqla_ice_1d(ji) * ( t_su_b(ji)! - ztsuold(ji) )     ! TECLIM change
+         qla_ice_1d (ji) = MAX( 0.e0, qla_ice_1d (ji) + dqla_ice_1d(ji) * (t_su_b(ji) - ztsuold(ji) ) )
          !                                ! surface ice conduction flux
-         isnow(ji)       = INT(  1._wp - MAX( 0._wp, SIGN( 1._wp, -ht_s_b(ji) ) )  )
-         fc_su(ji)       =  -           isnow(ji)   * zkappa_s(ji,0) * zg1s * (t_s_b(ji,1) - t_su_b(ji))   &
-            &               - ( 1._wp - isnow(ji) ) * zkappa_i(ji,0) * zg1  * (t_i_b(ji,1) - t_su_b(ji))
+         isnow(ji)       = NINT(  1._wp - MAX( 0._wp, SIGN( 1._wp, -ht_s_b(ji) ) )  )
+         fc_su(ji)       =  -     REAL( isnow(ji) ) * zkappa_s(ji,0) * zg1s * (t_s_b(ji,1) - t_su_b(ji))   &
+            &               - REAL( 1 - isnow(ji) ) * zkappa_i(ji,0) * zg1  * (t_i_b(ji,1) - t_su_b(ji))
          !                                ! bottom ice conduction flux
          fc_bo_i(ji)     =  - zkappa_i(ji,nlay_i) * ( zg1*(t_bo_b(ji) - t_i_b(ji,nlay_i)) )
@@ -733,12 +744,12 @@
          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) ) 
+            fc_s(ji,0) = - REAL( isnow(ji) ) * zkappa_s(ji,0) * zg1s * ( t_s_b(ji,1) - t_su_b(ji) ) 
             ! Bott. snow value
-            fc_s(ji,1) = - isnow(ji)* zkappa_s(ji,1) * ( t_i_b(ji,1) - t_s_b(ji,1) ) 
+            fc_s(ji,1) = - REAL( isnow(ji) ) * zkappa_s(ji,1) * ( t_i_b(ji,1) - t_s_b(ji,1) ) 
          END DO
          DO ji = kideb, kiut         ! Upper ice layer
-            fc_i(ji,0) = - isnow(ji) * &  ! interface flux if there is snow
+            fc_i(ji,0) = - REAL( isnow(ji) ) * &  ! interface flux if there is snow
                ( zkappa_i(ji,0)  * ( t_i_b(ji,1) - t_s_b(ji,nlay_s ) ) ) &
-               - ( 1.0 - isnow(ji) ) * ( zkappa_i(ji,0) * & 
+               - REAL( 1 - isnow(ji) ) * ( zkappa_i(ji,0) * & 
                zg1 * ( t_i_b(ji,1) - t_su_b(ji) ) ) ! upper flux if not
          END DO
@@ -755,4 +766,5 @@
       ENDIF
       !
+
    END SUBROUTINE lim_thd_dif
 
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_ent.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_ent.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_ent.F90	(revision 3938)
@@ -29,4 +29,5 @@
    USE lib_mpp          ! MPP library
    USE wrk_nemo         ! work arrays
+   USE lib_fortran      ! to use key_nosignedzero
 
    IMPLICIT NONE
@@ -144,6 +145,6 @@
 
       DO ji = kideb, kiut
-         zh_i(ji) = old_ht_i_b(ji) / nlay_i 
-         zh_s(ji) = old_ht_s_b(ji) / nlay_s
+         zh_i(ji) = old_ht_i_b(ji) / REAL( nlay_i ) 
+         zh_s(ji) = old_ht_s_b(ji) / REAL( nlay_s )
       END DO
 
@@ -165,6 +166,6 @@
       DO jk = 1, nlays0
          DO ji = kideb, kiut
-            snind(ji)  = jk        *      INT(MAX(0.0,SIGN(1.0,-dh_s_tot(ji)-zdeltah(ji)-epsi20))) &
-               + snind(ji) * (1 - INT(MAX(0.0,SIGN(1.0,-dh_s_tot(ji)-zdeltah(ji)-epsi20))))
+            snind(ji)  = jk        *      NINT(MAX(0.0,SIGN(1.0,-dh_s_tot(ji)-zdeltah(ji)))) &
+               + snind(ji) * (1 - NINT(MAX(0.0,SIGN(1.0,-dh_s_tot(ji)-zdeltah(ji)))))
             zdeltah(ji)= zdeltah(ji) + zh_s(ji)
          END DO ! ji
@@ -174,5 +175,5 @@
       !				   0 if not
       DO ji = kideb, kiut
-         snswi(ji)     = MAX(0,INT(-dh_s_tot(ji)/MAX(epsi20,ABS(dh_s_tot(ji)))))
+         snswi(ji)     = MAX(0,NINT(-dh_s_tot(ji)/MAX(epsi20,ABS(dh_s_tot(ji)))))
       END DO ! ji
 
@@ -189,6 +190,6 @@
       DO jk = 1, nlayi0
          DO ji = kideb, kiut
-            icsuind(ji) = jk          *      INT(MAX(0.0,SIGN(1.0,-dh_i_surf(ji)-zdeltah(ji)-epsi20))) &
-               + icsuind(ji) * (1 - INT(MAX(0.0,SIGN(1.0,-dh_i_surf(ji)-zdeltah(ji)-epsi20))))
+            icsuind(ji) = jk          *      NINT(MAX(0.0,SIGN(1.0,-dh_i_surf(ji)-zdeltah(ji)))) &
+               + icsuind(ji) * (1 - NINT(MAX(0.0,SIGN(1.0,-dh_i_surf(ji)-zdeltah(ji)))))
             zdeltah(ji) = zdeltah(ji) + zh_i(ji)
          END DO ! ji
@@ -199,5 +200,5 @@
       ! 	   0 if not
       DO ji = kideb, kiut
-         icsuswi(ji)  = MAX(0,INT(-dh_i_surf(ji)/MAX(epsi20 , ABS(dh_i_surf(ji)) ) ) )
+         icsuswi(ji)  = MAX(0,NINT(-dh_i_surf(ji)/MAX(epsi20 , ABS(dh_i_surf(ji)) ) ) )
       ENDDO
 
@@ -215,6 +216,6 @@
       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)-epsi20))) &
-               &          + icboind(ji) * (1 - INT(MAX(0.0,SIGN(1.0,-dh_i_bott(ji)-zdeltah(ji)-epsi20)))) 
+            icboind(ji) = (nlayi0+1-jk) *      NINT(MAX(0.0,SIGN(1.0,-dh_i_bott(ji)-zdeltah(ji)))) &
+               &          + icboind(ji) * (1 - NINT(MAX(0.0,SIGN(1.0,-dh_i_bott(ji)-zdeltah(ji))))) 
             zdeltah(ji) = zdeltah(ji) + zh_i(ji)
          END DO
@@ -231,5 +232,5 @@
       ! 	   0 if ablation is on the way
       DO ji = kideb, kiut 
-         icboswi(ji) = MAX(0,INT(dh_i_bott(ji) / MAX(epsi20,ABS(dh_i_bott(ji)))))
+         icboswi(ji) = MAX(0,NINT(dh_i_bott(ji) / MAX(epsi20,ABS(dh_i_bott(ji)))))
       END DO
 
@@ -247,6 +248,6 @@
          DO ji = kideb, kiut
             snicind(ji) = (nlays0+1-jk) &
-               *      INT(MAX(0.0,SIGN(1.0,dh_snowice(ji)-zdeltah(ji)-epsi20))) + snicind(ji)   &
-               * (1 - INT(MAX(0.0,SIGN(1.0,dh_snowice(ji)-zdeltah(ji)-epsi20))))
+               *      NINT(MAX(0.0,SIGN(1.0,dh_snowice(ji)-zdeltah(ji)))) + snicind(ji)   &
+               * (1 - NINT(MAX(0.0,SIGN(1.0,dh_snowice(ji)-zdeltah(ji)))))
             zdeltah(ji) = zdeltah(ji) + zh_s(ji)
          END DO
@@ -257,5 +258,5 @@
       ! 	   0 if not
       DO ji = kideb, kiut
-         snicswi(ji)   = MAX(0,INT(dh_snowice(ji)/MAX(epsi20,ABS(dh_snowice(ji)))))
+         snicswi(ji)   = MAX(0,NINT(dh_snowice(ji)/MAX(epsi20,ABS(dh_snowice(ji)))))
       ENDDO
 
@@ -278,5 +279,5 @@
 
       DO ji = kideb, kiut
-         nbot0(ji) =  nlays0  + 1 - snind(ji) + ( 1. - snicind(ji) ) * snicswi(ji)
+         nbot0(ji) =  nlays0  + 1 - snind(ji) + ( 1 - snicind(ji) ) * snicswi(ji)
          ! cotes of the top of the layers
          zm0(ji,0) =  0._wp
@@ -290,11 +291,11 @@
             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
-      END DO
-
-      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)
+            zm0(ji,jk) =  dh_s_tot(ji) + zh_s(ji) * REAL( limsum )
+         END DO
+      END DO
+
+      DO ji = kideb, kiut
+         zm0(ji,nbot0(ji)) =  dh_s_tot(ji) - REAL( snicswi(ji) ) * dh_snowice(ji) + zh_s(ji) * REAL( nlays0 )
+         zm0(ji,1)         =  dh_s_tot(ji) * REAL( 1 - snswi(ji) ) + REAL( snswi(ji) ) * zm0(ji,1)
       END DO
 
@@ -308,6 +309,6 @@
 
       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)  )   &
+         qm0    (ji,1) =  rhosn * (  cpic * ( rtt - REAL( 1 - snswi(ji) ) * tatm_ice_1d(ji)        &
+            &                                         - REAL( snswi(ji) ) * t_s_b      (ji,1)  )   &
             &                      + lfus  ) * zthick0(ji,1)
          zqts_in(ji)   =  zqts_in(ji) + qm0(ji,1) 
@@ -319,6 +320,6 @@
             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, epsi20 - ht_s_b(ji) ) )
-            zqts_in(ji) = zqts_in(ji) + ( 1. - snswi(ji) ) * qm0(ji,jk) * zswitch
+            zswitch = 1.0 - MAX (0.0, SIGN ( 1.0, - ht_s_b(ji) ) )
+            zqts_in(ji) = zqts_in(ji) + REAL( 1 - snswi(ji) ) * qm0(ji,jk) * zswitch
          END DO ! jk
       END DO ! ji
@@ -359,5 +360,5 @@
       !-------------------
       DO ji = kideb, kiut
-         zh_s(ji)  = ht_s_b(ji) / nlay_s
+         zh_s(ji)  = ht_s_b(ji) / REAL( nlay_s )
          z_s(ji,0) =  0._wp
       ENDDO
@@ -365,5 +366,5 @@
       DO jk = 1, nlay_s
          DO ji = kideb, kiut
-            z_s(ji,jk) =  zh_s(ji) * jk
+            z_s(ji,jk) =  zh_s(ji) * REAL( jk )
          END DO
       END DO
@@ -393,5 +394,5 @@
                   &                 - 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+epsi20))
+                  &                                * MAX(0.0,SIGN(1.0,REAL(nbot0(ji)-layer0)))
             END DO
          END DO
@@ -440,5 +441,5 @@
       DO jk = 1, nlay_s
          DO ji = kideb, kiut
-            zswitch = MAX ( 0.0 , SIGN ( 1.0, epsi20 - ht_s_b(ji) ) )
+            zswitch = MAX ( 0.0 , SIGN ( 1.0, - ht_s_b(ji) ) )
             t_s_b(ji,jk) = rtt + ( 1.0 - zswitch ) * ( - zfac1 * q_s_b(ji,jk) + zfac2 )
          END DO
@@ -479,13 +480,13 @@
             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
-      END DO
-
-      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)
+            zm0(ji,jk)=  REAL(icsuswi(ji))*dh_i_surf(ji) + REAL(snicswi(ji))*dh_snowice(ji) &
+               +  REAL(limsum) * zh_i(ji)
+         END DO
+      END DO
+
+      DO ji = kideb, kiut
+         zm0(ji,nbot0(ji)) =  REAL(icsuswi(ji))*dh_i_surf(ji) + REAL(snicswi(ji))*dh_snowice(ji) + dh_i_bott(ji) &
+            +  zh_i(ji) * REAL(nlayi0)
+         zm0(ji,1)         =  REAL(snicswi(ji))*dh_snowice(ji) + REAL(1-snicswi(ji))*zm0(ji,1)
       END DO
 
@@ -520,6 +521,6 @@
       !----------------------------
       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
+         ztmelts    = REAL( 1 - icboswi(ji) ) * (-tmut * s_i_b  (ji,nlayi0) )   &   ! case of melting ice
+            &       +     REAL( icboswi(ji) ) * (-tmut * s_i_new(ji)        )   &   ! case of forming ice
             &       + rtt                                                         ! in Kelvin
 
@@ -527,6 +528,6 @@
          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) * rhoic * ( cpic*(ztmelts-ztform)       &   ! case of forming ice
+         qm0(ji,nbot0(ji)) = REAL( 1 - icboswi(ji) )*qm0(ji,nbot0(ji))             &   ! case of melting ice
+            &              + REAL( icboswi(ji) ) * rhoic * ( cpic*(ztmelts-ztform)       &   ! case of forming ice
             + lfus *( 1.0-(ztmelts-rtt) / MIN ( (ztform-rtt) , - epsi10 ) )      & 
             - rcp*(ztmelts-rtt) ) * zthick0(ji,nbot0(ji)  )
@@ -539,5 +540,5 @@
          ! energy of the flooding seawater
          zqsnic = rau0 * rcp * ( rtt - t_bo_b(ji) ) * dh_snowice(ji) * &
-            (rhoic - rhosn) / rhoic * snicswi(ji) ! generally positive
+            (rhoic - rhosn) / rhoic * REAL(snicswi(ji)) ! generally positive
          ! Heat conservation diagnostic
          qt_i_in(ji,jl) = qt_i_in(ji,jl) + zqsnic 
@@ -548,5 +549,13 @@
          ! = enthalpy of snow + enthalpy of frozen water
          zqsnic         =  zqsnow(ji) + zqsnic
-         qm0(ji,1)      =  snicswi(ji) * zqsnic + ( 1 - snicswi(ji) ) * qm0(ji,1)
+         qm0(ji,1)      =  REAL(snicswi(ji)) * zqsnic + REAL( 1 - snicswi(ji) ) * qm0(ji,1)
+
+         zji = MOD( npb(ji) - 1, jpi ) + 1
+         zjj = ( npb(ji) - 1 ) / jpi + 1
+         IF ( (zji.eq.jiindx).AND.(zjj.eq.jjindx) ) THEN
+            !clemclem
+            WRITE(numout,*) 'lim_thd_ent : qldif = ', qldif_1d(ji)
+            !clemclem
+         ENDIF
 
       END DO ! ji
@@ -555,6 +564,6 @@
          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)-epsi06+epsi20) ) &
-               &                                   * MAX( 0.0 , SIGN( 1. , nbot0(ji) - jk + epsi20 ) )
+            zqti_in(ji) = zqti_in(ji) + qm0(ji,jk) * MAX( 0.0 , SIGN(1.0,ht_i_b(ji)-epsi06) ) &
+               &                                   * MAX( 0.0 , SIGN( 1. , REAL(nbot0(ji) - jk) ) )
          END DO
       END DO
@@ -574,5 +583,5 @@
       !------------------
       DO ji = kideb, kiut
-         zh_i(ji) = ht_i_b(ji) / nlay_i
+         zh_i(ji) = ht_i_b(ji) / REAL( nlay_i )
       ENDDO
 
@@ -605,6 +614,6 @@
                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)-epsi06+epsi20)) &
-                  * MAX(0.0,SIGN(1.0,nbot0(ji)-layer0+epsi20))
+                  * MAX(0.0,SIGN(1.0,ht_i_b(ji)-epsi06)) &
+                  * MAX(0.0,SIGN(1.0,REAL(nbot0(ji)-layer0)))
             END DO
          END DO
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90	(revision 3938)
@@ -29,4 +29,5 @@
    USE lib_mpp          ! MPP library
    USE wrk_nemo         ! work arrays
+   USE lib_fortran      ! to use key_nosignedzero
 
    IMPLICIT NONE
@@ -159,6 +160,5 @@
                   !Energy of melting q(S,T) [J.m-3]
                   e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) / &
-                     MAX( area(ji,jj) * v_i(ji,jj,jl) ,  epsi10 ) * &
-                     nlay_i
+                     MAX( area(ji,jj) * v_i(ji,jj,jl) ,  epsi10 ) * REAL( 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
@@ -185,9 +185,5 @@
 
       ! Default new ice thickness 
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            hicol(ji,jj) = hiccrit(1)
-         END DO
-      END DO
+      hicol(:,:) = hiccrit(1)
 
       IF (fraz_swi.eq.1.0) THEN
@@ -335,4 +331,5 @@
          CALL tab_2d_1d( nbpac, zvrel_ac  (1:nbpac)     , zvrel ,              &
             jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, rdmicif_1d  (1:nbpac)   , rdmicif, jpi, jpj, npac(1:nbpac) ) !martin
 
          !------------------------------------------------------------------------------!
@@ -410,4 +407,6 @@
             zdh_frazb(ji) = zfrazb*zv_newice(ji)
             zv_newice(ji) = ( 1.0 - zfrazb ) * zv_newice(ji)
+            !
+!clem@mv            rdmicif_1d(ji) = rdmicif_1d(ji) + zv_newice(ji) * rhoic  !martin
          END DO
 
@@ -415,21 +414,17 @@
          ! 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_m(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_m(zji,zjj) - zs_newice(ji) ) * rhoic *       &
-                  zv_newice(ji) / rdt_ice
-            END DO ! ji
-         ENDIF
+!clem@mv         IF ( ( num_sal .EQ. 4 ) ) THEN 
+!clem@mv            DO ji = 1, nbpac
+!clem@mv               ! IOVINO
+!clem@mv               fseqv_1d(ji)   = fseqv_1d(ji) - bulk_sal * rhoic *  &
+!clem@mv                  zv_newice(ji) / rdt_ice
+!clem@mv            END DO
+!clem@mv         ELSE
+!clem@mv            DO ji = 1, nbpac
+!clem@mv               ! IOVINO
+!clem@mv               fseqv_1d(ji)   = fseqv_1d(ji)  - zs_newice(ji) * rhoic *   &
+!clem@mv                  zv_newice(ji) / rdt_ice
+!clem@mv            END DO ! ji
+!clem@mv         ENDIF
 
          !------------------------------------
@@ -460,5 +455,5 @@
             zjj                  = ( npac(ji) - 1 ) / jpi + 1
             diag_lat_gr(zji,zjj) = zv_newice(ji) / rdt_ice
-         END DO !ji
+          END DO !ji
 
          !------------------------------------------------------------------------------!
@@ -480,10 +475,10 @@
          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) )
+            IF ( za_newice(ji) .GT. ( amax - zat_i_ac(ji) ) ) THEN
+               zda_res(ji)    = za_newice(ji) - ( amax - 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
+           ELSE
                zda_res(ji) = 0.0
                zdv_res(ji) = 0.0
@@ -512,8 +507,8 @@
          DO ji = 1, nbpac
             jl = zcatac(ji)                                                           ! categroy in which new ice is put
-            zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , -za_old(ji,jl) ) )             ! zindb=1 if ice =0 otherwise
+            zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , -za_old(ji,jl) + epsi10 ) )             ! zindb=1 if ice =0 otherwise
             zhice_old(ji,jl) = zv_old(ji,jl) / MAX( za_old(ji,jl) , epsi10 ) * zindb  ! old ice thickness
             zdhex    (ji) = MAX( 0._wp , zh_newice(ji) - zhice_old(ji,jl) )           ! difference in thickness
-            zswinew  (ji) = MAX( 0._wp , SIGN( 1._wp , - za_old(ji,jl) + epsi11 ) )   ! ice totally new in jl category
+            zswinew  (ji) = MAX( 0._wp , SIGN( 1._wp , - za_old(ji,jl) + epsi10 ) )   ! ice totally new in jl category
          END DO
 
@@ -522,10 +517,10 @@
                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) )
+               zalphai = MIN( zhice_old(ji,jl) * REAL( jk )     / REAL( nlay_i ), zh_newice(ji) )   &
+                  &    - MIN( zhice_old(ji,jl) * REAL( jk - 1 ) / REAL( nlay_i ), zh_newice(ji) )
                ze_i_ac(ji,jk,jl) = zswinew(ji) * ze_newice(ji)                                     &
-                  + ( 1.0 - zswinew(ji) ) * ( za_old(ji,jl)  * zqold * zhice_old(ji,jl) / nlay_i   &
+                  + ( 1.0 - zswinew(ji) ) * ( za_old(ji,jl)  * zqold * zhice_old(ji,jl) / REAL( nlay_i )  &
                   + za_newice(ji)  * ze_newice(ji) * zalphai                                       &
-                  + za_newice(ji)  * ze_newice(ji) * zdhex(ji) / nlay_i ) / ( ( zv_i_ac(ji,jl) ) / nlay_i )
+                  + za_newice(ji)  * ze_newice(ji) * zdhex(ji) / REAL( nlay_i ) ) / ( ( zv_i_ac(ji,jl) ) / REAL( nlay_i ) )
             END DO
          END DO
@@ -563,5 +558,5 @@
          DO jl = ice_cat_bounds(jm,1), ice_cat_bounds(jm,2)
             DO ji = 1, nbpac
-               zindb =  1._wp - MAX( 0._wp , SIGN( 1._wp , - za_i_ac(ji,jl ) ) )       ! zindb=1 if ice =0 otherwise
+               zindb =  1._wp - MAX( 0._wp , SIGN( 1._wp , - za_i_ac(ji,jl ) + epsi10 ) )       ! zindb=1 if ice =0 otherwise
                zhice_old(ji,jl) = zv_i_ac(ji,jl) / MAX( za_i_ac(ji,jl) , epsi10 ) * zindb
                zdhicbot (ji,jl) = zdv_res(ji)    / MAX( za_i_ac(ji,jl) , epsi10 ) * zindb    &
@@ -575,5 +570,5 @@
             DO jk = 1, nlay_i
                DO ji = 1, nbpac
-                  zthick0(ji,jk,jl) =  zhice_old(ji,jl) / nlay_i
+                  zthick0(ji,jk,jl) =  zhice_old(ji,jl) / REAL( nlay_i )
                   zqm0   (ji,jk,jl) =  ze_i_ac(ji,jk,jl) * zthick0(ji,jk,jl)
                END DO
@@ -594,9 +589,9 @@
                DO layer = 1, nlay_i + 1
                   DO ji = 1, nbpac
-                     zindb =  1._wp -  MAX( 0._wp , SIGN( 1._wp , - za_i_ac(ji,jl) ) ) 
+                     zindb =  1._wp -  MAX( 0._wp , SIGN( 1._wp , - za_i_ac(ji,jl) + epsi10 ) ) 
                      ! Redistributing energy on the new grid
-                     zweight = MAX (  MIN( zhice_old(ji,jl) * layer , zdummy(ji,jl) * jk )   &
-                        &    - MAX( zhice_old(ji,jl) * ( layer - 1 ) , zdummy(ji,jl) * ( jk - 1 ) ) , 0._wp )   &
-                        &    /( MAX(nlay_i * zthick0(ji,layer,jl),epsi10) ) * zindb
+                     zweight = MAX (  MIN( zhice_old(ji,jl) * REAL( layer ), zdummy(ji,jl) * REAL( jk ) )   &
+                        &    - MAX( zhice_old(ji,jl) * REAL( layer - 1 ) , zdummy(ji,jl) * REAL( jk - 1 ) ) , 0._wp )   &
+                        &    /( MAX(REAL(nlay_i) * zthick0(ji,layer,jl),epsi10) ) * zindb
                      ze_i_ac(ji,jk,jl) =  ze_i_ac(ji,jk,jl) + zweight * zqm0(ji,layer,jl)  
                   END DO ! ji
@@ -608,7 +603,7 @@
             DO jk = 1, nlay_i
                DO ji = 1, nbpac
-                  zindb =  1._wp -  MAX( 0._wp , SIGN( 1._wp , - zv_i_ac(ji,jl) ) ) 
+                  zindb =  1._wp -  MAX( 0._wp , SIGN( 1._wp , - zv_i_ac(ji,jl) + epsi10 ) ) 
                   ze_i_ac(ji,jk,jl) = ze_i_ac(ji,jk,jl)   &
-                     &              / MAX( zv_i_ac(ji,jl) , epsi10) * za_i_ac(ji,jl) * nlay_i * zindb
+                     &              / MAX( zv_i_ac(ji,jl) , epsi10) * za_i_ac(ji,jl) * REAL( nlay_i ) * zindb
                END DO
             END DO
@@ -620,5 +615,5 @@
          DO jl = 1, jpl
             DO ji = 1, nbpac
-               zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - za_i_ac(ji,jl) ) )  ! 0 if no ice and 1 if yes
+               zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - za_i_ac(ji,jl) + epsi10 ) )  ! 0 if no ice and 1 if yes
                zoa_i_ac(ji,jl)  = za_old(ji,jl) * zoa_i_ac(ji,jl) / MAX( za_i_ac(ji,jl) , epsi10 ) * zindb   
             END DO 
@@ -631,5 +626,5 @@
             DO jl = 1, jpl
                DO ji = 1, nbpac
-                  zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - zv_i_ac(ji,jl) ) )  ! 0 if no ice and 1 if yes
+                  zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - zv_i_ac(ji,jl) + epsi10 ) )  ! 0 if no ice and 1 if yes
                   zdv   = zv_i_ac(ji,jl) - zv_old(ji,jl)
                   zsmv_i_ac(ji,jl) = ( zsmv_i_ac(ji,jl) + zdv * zs_newice(ji) ) * zindb
@@ -637,4 +632,16 @@
             END DO   
          ENDIF
+
+         !--------------------------------
+         ! Update mass/salt fluxes (clem)
+         !--------------------------------
+         DO jl = 1, jpl
+            DO ji = 1, nbpac
+               zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - zv_i_ac(ji,jl) + epsi10 ) )  ! 0 if no ice and 1 if yes
+               zdv   = zv_i_ac(ji,jl) - zv_old(ji,jl)
+               rdmicif_1d(ji) = rdmicif_1d(ji) + zdv * rhoic !* zindb
+               fseqv_1d(ji)   =   fseqv_1d(ji) - zdv * rhoic * zs_newice(ji) / rdt_ice * zindb
+           END DO
+         END DO
 
          !------------------------------------------------------------------------------!
@@ -652,4 +659,5 @@
          END DO
          CALL tab_1d_2d( nbpac, fseqv , npac(1:nbpac), fseqv_1d  (1:nbpac) , jpi, jpj )
+         CALL tab_1d_2d( nbpac, rdmicif , npac(1:nbpac), rdmicif_1d  (1:nbpac) , jpi, jpj )
          !
       ENDIF ! nbpac > 0
@@ -660,5 +668,5 @@
       DO jl = 1, jpl
          DO jk = 1, nlay_i          ! heat content in 10^9 Joules
-            e_i(:,:,jk,jl) = e_i(:,:,jk,jl) * area(:,:) * v_i(:,:,jl) / nlay_i  / unit_fac 
+            e_i(:,:,jk,jl) = e_i(:,:,jk,jl) * area(:,:) * v_i(:,:,jl) / REAL( nlay_i )  / unit_fac 
          END DO
       END DO
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_sal.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_sal.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limthd_sal.F90	(revision 3938)
@@ -24,4 +24,5 @@
    USE lib_mpp          ! MPP library
    USE wrk_nemo         ! work arrays
+   USE lib_fortran      ! to use key_nosignedzero
 
    IMPLICIT NONE
@@ -31,4 +32,5 @@
    PUBLIC   lim_thd_sal_init   ! called by iceini module
 
+   REAL(wp) ::   epsi20 = 1e-20_wp   ! constant values
    !!----------------------------------------------------------------------
    !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
@@ -67,14 +69,8 @@
       IF( num_sal == 1 ) THEN
          !
-         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
-         !
+         s_i_b  (kideb:kiut,1:nlay_i) =  bulk_sal 
+         sm_i_b (kideb:kiut)          =  bulk_sal
+         s_i_new(kideb:kiut)          =  bulk_sal
+        !
       ENDIF
 
@@ -90,4 +86,5 @@
          DO ji = kideb, kiut
             zhiold(ji) = ht_i_b(ji) - dh_i_bott(ji) - dh_snowice(ji) - dh_i_surf(ji)
+            zsiold(ji) = sm_i_b(ji)
          END DO
 
@@ -98,5 +95,5 @@
          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
+               ze_init(ji) = ze_init(ji) + q_i_b(ji,jk) * ht_i_b(ji) / REAL (nlay_i )
             END DO
          END DO
@@ -125,5 +122,4 @@
             ! 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)
 
@@ -156,10 +152,13 @@
          ! Salt flux - brine drainage
          !----------------------------
-         DO ji = kideb, kiut
+          DO ji = kideb, kiut
             i_ice_switch = 1._wp - MAX ( 0._wp, SIGN( 1._wp , - 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
+            fsbri_1d(ji) = fsbri_1d(ji) - i_ice_switch * rhoic * a_i_b(ji) * ht_i_b(ji) * ( sm_i_b(ji) - zsiold(ji) ) / rdt_ice
+            !i_ice_switch = 1._wp - MAX ( 0._wp, SIGN( 1._wp , - zhiold(ji) ) )
+            !fsbri_1d(ji) = fsbri_1d(ji) - i_ice_switch * rhoic * a_i_b(ji) * zhiold(ji) * ( sm_i_b(ji) - zsiold(ji) ) / rdt_ice
+            !clem fsbri_1d(ji) = fsbri_1d(ji) - i_ice_switch * rhoic * a_i_b(ji) * ht_i_b(ji)         &
+            !clem     &         * ( MAX(dsm_i_gd_1d(ji) + dsm_i_fl_1d(ji), sm_i_b(ji) - zsiold(ji) ) ) / rdt_ice
             IF( num_sal == 4 ) fsbri_1d(ji) = 0._wp
-         END DO ! ji
+          END DO ! ji
 
          ! Only necessary for conservation check since salinity is modified
@@ -211,23 +210,4 @@
       ENDIF ! num_sal
 
-      !------------------------------------------------------------------------------|
-      ! 5) Computation of salt flux due to Bottom growth
-      !------------------------------------------------------------------------------|
-
-      IF ( num_sal == 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_m(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_m(zji,zjj) - s_i_new(ji) )               &
-               &                        * rhoic * a_i_b(ji) * MAX( dh_i_bott(ji) , 0.0 ) / rdt_ice
-         END DO
-      ENDIF
       !
       CALL wrk_dealloc( jpij, ze_init, zhiold, zsiold )
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limtrp.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limtrp.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limtrp.F90	(revision 3938)
@@ -27,4 +27,6 @@
    USE wrk_nemo        ! work arrays
    USE prtctl          ! Print control
+   USE lib_fortran     ! to use key_nosignedzero
+   USE limvar          ! clem for ice thickness correction
 
    IMPLICIT NONE
@@ -35,6 +37,7 @@
    REAL(wp)  ::   epsi06 = 1.e-06_wp   ! constant values
    REAL(wp)  ::   epsi03 = 1.e-03_wp  
-   REAL(wp)  ::   zeps10 = 1.e-10_wp  
+   REAL(wp)  ::   epsi10 = 1.e-10_wp  
    REAL(wp)  ::   epsi16 = 1.e-16_wp
+   REAL(wp)  ::   epsi20 = 1.e-20_wp
    REAL(wp)  ::   rzero  = 0._wp   
    REAL(wp)  ::   rone   = 1._wp
@@ -65,8 +68,9 @@
       INTEGER, INTENT(in) ::   kt   ! number of iteration
       !
-      INTEGER  ::   ji, jj, jk, jl, layer   ! dummy loop indices
+      INTEGER  ::   ji, jj, jk, jl, jm, layer   ! dummy loop indices
+      INTEGER  ::   jbnd1, jbnd2
       INTEGER  ::   initad                  ! number of sub-timestep for the advection
       INTEGER  ::   ierr                    ! error status
-      REAL(wp) ::   zindb  , zindsn , zindic      ! local scalar
+      REAL(wp) ::   zindb  , zindsn , zindic, zindh, zinda      ! local scalar
       REAL(wp) ::   zusvosn, zusvoic, zbigval     !   -      -
       REAL(wp) ::   zcfl , zusnit , zrtt          !   -      -
@@ -76,4 +80,10 @@
       REAL(wp), POINTER, DIMENSION(:,:,:)    ::   zs0ice, zs0sn, zs0a, zs0c0 , zs0sm , zs0oi
       REAL(wp), POINTER, DIMENSION(:,:,:,:)  ::   zs0e
+      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
+      ! mass and salt flux (clem)
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zviold   ! old ice volume...
+      ! correct ice thickness (clem)
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zaiold, zhimax   ! old ice concentration
+      REAL(wp) :: zdv, zda, zvi, zvs, zsmv
       !!---------------------------------------------------------------------
 
@@ -81,4 +91,18 @@
       CALL wrk_alloc( jpi, jpj, jpl, zs0ice, zs0sn, zs0a, zs0c0 , zs0sm , zs0oi )
       CALL wrk_alloc( jpi, jpj, jkmax, jpl, zs0e )
+
+      CALL wrk_alloc( jpi,jpj,jpl,zviold )   ! clem
+      CALL wrk_alloc( jpi,jpj,jpl,zaiold, zhimax )   ! clem
+
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
+         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
+      ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
 
       IF( numit == nstart .AND. lwp ) THEN
@@ -95,6 +119,24 @@
       IF( ln_limdyn ) THEN          !   Advection of sea ice properties   !
          !                          !-------------------------------------!
-         !
-
+         ! mass and salt flux init (clem)
+         zviold(:,:,:)  = v_i(:,:,:)
+
+         !--- Thickness correction init. (clem) -------------------------------
+         CALL lim_var_glo2eqv
+         zaiold(:,:,:) = a_i(:,:,:)
+         !---------------------------------------------------------------------
+         ! Record max of the surrounding ice thicknesses for correction in limupdate
+         ! in case advection creates ice too thick.
+         !---------------------------------------------------------------------
+         zhimax(:,:,:) = ht_i(:,:,:)
+         DO jl = 1, jpl
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  zhimax(ji,jj,jl) = MAXVAL( ht_i(ji-1:ji+1,jj-1:jj+1,jl) )
+               END DO
+            END DO
+            CALL lbc_lnk(zhimax(:,:,jl),'T',1.)
+         END DO
+         
          !-------------------------
          ! transported fields                                        
@@ -125,5 +167,5 @@
 !         ENDIF
 !!gm end
-         initad = 1 + INT( MAX( rzero, SIGN( rone, zcfl-0.5 ) ) )
+         initad = 1 + NINT( MAX( rzero, SIGN( rone, zcfl-0.5 ) ) )
          zusnit = 1.0 / REAL( initad ) 
          IF( zcfl > 0.5 .AND. lwp )   &
@@ -134,7 +176,7 @@
             DO jk = 1,initad
                CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0ow (:,:), sxopw(:,:),   &             !--- ice open water area
-                  &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
+                   &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
                CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0ow (:,:), sxopw(:,:),   &
-                  &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
+                   &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
                DO jl = 1, jpl
                   CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
@@ -174,39 +216,38 @@
          ELSE
             DO jk = 1, initad
-               CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0ow (:,:), sxopw(:,:),   &             !--- ice open water area
-                  &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
-               CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0ow (:,:), sxopw(:,:),   &
-                  &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
+               CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0ow (:,:), sxopw(:,:),   &             !--- ice open water area
+                   &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
+               CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0ow (:,:), sxopw(:,:),   &
+                   &                                       sxxopw(:,:), syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
                DO jl = 1, jpl
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
+                  CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
                      &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &
+                  CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0ice(:,:,jl), sxice(:,:,jl),   &
                      &                                       sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
+                  CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
                      &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &
+                  CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0sn (:,:,jl), sxsn (:,:,jl),   &
                      &                                       sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
+                  CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
                      &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &
+                  CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0sm (:,:,jl), sxsal(:,:,jl),   &
                      &                                       sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &   !--- ice age      ---
+                  CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &   !--- ice age      ---
                      &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &
+                  CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0oi (:,:,jl), sxage(:,:,jl),   &
                      &                                       sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   &   !--- ice concentrations ---
+                  CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   &   !--- ice concentrations ---
                      &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   &
+                  CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0a  (:,:,jl), sxa  (:,:,jl),   &
                      &                                       sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &  !--- snow heat contents ---
+                  CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &  !--- snow heat contents ---
                      &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &
+                  CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0c0 (:,:,jl), sxc0 (:,:,jl),   &
                      &                                       sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
                   DO layer = 1, nlay_i                                                           !--- ice heat contents ---
-                     CALL lim_adv_y( zusnit, v_ice, rzero, zsm, zs0e(:,:,layer,jl), sxe (:,:,layer,jl),   & 
+                     CALL lim_adv_y( zusnit, v_ice, rone, zsm, zs0e(:,:,layer,jl), sxe (:,:,layer,jl),   & 
                         &                                       sxxe(:,:,layer,jl), sye (:,:,layer,jl),   &
                         &                                       syye(:,:,layer,jl), sxye(:,:,layer,jl) )
-                     CALL lim_adv_x( zusnit, u_ice, rone , zsm, zs0e(:,:,layer,jl), sxe (:,:,layer,jl),   & 
+                     CALL lim_adv_x( zusnit, u_ice, rzero , zsm, zs0e(:,:,layer,jl), sxe (:,:,layer,jl),   & 
                         &                                       sxxe(:,:,layer,jl), sye (:,:,layer,jl),   &
                         &                                       syye(:,:,layer,jl), sxye(:,:,layer,jl) )
@@ -270,13 +311,13 @@
             END DO
 
-            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
+             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
          END DO
 
@@ -284,16 +325,16 @@
          !  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
+         !clem zs0ow(:,:) = MAX( rzero, zs0ow(:,:) * area(:,:) )
+         !clem DO jl = 1, jpl
+         !clem    zs0ice(:,:,jl) = MAX( rzero, zs0ice(:,:,jl) * area(:,:) )    !!bug:  est-ce utile
+         !clem    zs0sn (:,:,jl) = MAX( rzero, zs0sn (:,:,jl) * area(:,:) )    !!bug:  cf /area  juste apres
+         !clem    zs0sm (:,:,jl) = MAX( rzero, zs0sm (:,:,jl) * area(:,:) )    !!bug:  cf /area  juste apres
+         !clem    zs0oi (:,:,jl) = MAX( rzero, zs0oi (:,:,jl) * area(:,:) )
+         !clem    zs0a  (:,:,jl) = MAX( rzero, zs0a  (:,:,jl) * area(:,:) )    !! suppress both change le resultat
+         !clem    zs0c0 (:,:,jl) = MAX( rzero, zs0c0 (:,:,jl) * area(:,:) )
+         !clem    DO jk = 1, nlay_i
+         !clem       zs0e(:,:,jk,jl) = MAX( rzero, zs0e (:,:,jk,jl) * area(:,:) )
+         !clem    END DO ! jk
+         !clem END DO ! jl
 
          !------------------------------------------------------------------------------!
@@ -305,19 +346,19 @@
          !--------------------------------------------------
 
-         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
+         !clem DO jl = 1, jpl
+         !clem    DO jk = 1, nlay_i
+         !clem       DO jj = 1, jpj
+         !clem          DO ji = 1, jpi
+         !clem             zs0e(ji,jj,jk,jl) = MAX( rzero, zs0e(ji,jj,jk,jl) / area(ji,jj) )
+         !clem          END DO
+         !clem       END DO
+         !clem    END DO
+         !clem END DO
+
+         !clem DO jj = 1, jpj
+         !clem    DO ji = 1, jpi
+         !clem       zs0ow(ji,jj) = MAX( rzero, zs0ow (ji,jj) / area(ji,jj) )
+         !clem    END DO
+         !clem END DO
 
          zs0at(:,:) = 0._wp
@@ -325,10 +366,16 @@
             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) )
+                 !clem  zs0sn (ji,jj,jl) = MAX( rzero, zs0sn (ji,jj,jl)/area(ji,jj) )
+                 !clem  zs0ice(ji,jj,jl) = MAX( rzero, zs0ice(ji,jj,jl)/area(ji,jj) )
+                 !clem  zs0sm (ji,jj,jl) = MAX( rzero, zs0sm (ji,jj,jl)/area(ji,jj) )
+                 !clem  zs0oi (ji,jj,jl) = MAX( rzero, zs0oi (ji,jj,jl)/area(ji,jj) )
+                 !clem  zs0a  (ji,jj,jl) = MAX( rzero, zs0a  (ji,jj,jl)/area(ji,jj) )
+                 !clem  zs0c0 (ji,jj,jl) = MAX( rzero, zs0c0 (ji,jj,jl)/area(ji,jj) )
+                  zs0sn (ji,jj,jl) = MAX( rzero, zs0sn (ji,jj,jl) )
+                  zs0ice(ji,jj,jl) = MAX( rzero, zs0ice(ji,jj,jl) )
+                  zs0sm (ji,jj,jl) = MAX( rzero, zs0sm (ji,jj,jl) )
+                  zs0oi (ji,jj,jl) = MAX( rzero, zs0oi (ji,jj,jl) )
+                  zs0a  (ji,jj,jl) = MAX( rzero, zs0a  (ji,jj,jl) )
+                  zs0c0 (ji,jj,jl) = MAX( rzero, zs0c0 (ji,jj,jl) )
                   zs0at (ji,jj)    = zs0at(ji,jj) + zs0a(ji,jj,jl)
                END DO
@@ -341,5 +388,5 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               zindb        = MAX( 0._wp , SIGN( 1.0, zs0at(ji,jj) - zeps10) )
+               zindb        = MAX( 0._wp , SIGN( 1.0, zs0at(ji,jj) - epsi10) )
                zs0ow(ji,jj) = ( 1._wp - zindb ) + zindb * MAX( zs0ow(ji,jj), 0._wp )
                ato_i(ji,jj) = zs0ow(ji,jj)
@@ -347,27 +394,78 @@
          END DO
 
+         !
+         !
          DO jl = 1, jpl         ! Remove very small areas 
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zindb         = MAX( 0.0 , SIGN( 1.0, zs0a(ji,jj,jl) - zeps10) )
+                  zvi = zs0ice(ji,jj,jl)
+                  zvs = zs0sn(ji,jj,jl)
                   !
-                  zs0a(ji,jj,jl) = zindb * MIN( zs0a(ji,jj,jl), 0.99 )
+                  zindb         = MAX( 0.0 , SIGN( 1.0, zs0a(ji,jj,jl) - epsi10) )
+                  !
+                  !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 ) )
+                  zindsn         = MAX( rzero, SIGN( rone, v_s(ji,jj,jl) - epsi10 ) )
+                  zindic         = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) )
                   zindb          = MAX( zindsn, zindic )
+                  !
                   zs0a(ji,jj,jl) = zindb  * zs0a(ji,jj,jl) !ice concentration
                   a_i (ji,jj,jl) = zs0a(ji,jj,jl)
                   v_s (ji,jj,jl) = zindsn * v_s(ji,jj,jl)
                   v_i (ji,jj,jl) = zindic * v_i(ji,jj,jl)
+                  !
+                  ! Update mass fluxes (clem)
+                  rdmicif(ji,jj) = rdmicif(ji,jj) + ( v_i(ji,jj,jl) - zvi ) * rhoic 
+                  rdmsnif(ji,jj) = rdmsnif(ji,jj) + ( v_s(ji,jj,jl) - zvs ) * rhosn 
+              END DO
+            END DO
+         END DO
+
+         !--- Thickness correction in case too high (clem) --------------------------------------------------------
+         CALL lim_var_glo2eqv
+         DO jl = 1, jpl
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+
+                  IF ( v_i(ji,jj,jl) > 0. ) THEN
+                     zvi = v_i(ji,jj,jl)
+                     zvs = v_s(ji,jj,jl)
+                     zdv = v_i(ji,jj,jl) - zviold(ji,jj,jl)   
+                     !zda = a_i(ji,jj,jl) - zaiold(ji,jj,jl)   
+                     
+                     IF ( ( zdv > 0.0 .AND. ht_i(ji,jj,jl) > zhimax(ji,jj,jl) .AND. SUM( zaiold(ji,jj,1:jpl) ) < 0.80 ) .OR. &
+                          ( zdv < 0.0 .AND. ht_i(ji,jj,jl) > zhimax(ji,jj,jl) ) ) THEN                                          
+                        ht_i(ji,jj,jl) = MIN( zhimax(ji,jj,jl), hi_max(jl) )
+                        zindh   =  MAX( rzero, SIGN( rone, ht_i(ji,jj,jl) - epsi10 ) )
+                        a_i(ji,jj,jl)  = zindh * v_i(ji,jj,jl) / MAX( ht_i(ji,jj,jl), epsi10 )
+                     ELSE
+                        ht_i(ji,jj,jl) = MAX( MIN( ht_i(ji,jj,jl), hi_max(jl) ), hi_max(jl-1) )
+                        zindh   =  MAX( rzero, SIGN( rone, ht_i(ji,jj,jl) - epsi10 ) )
+                        a_i(ji,jj,jl)  = zindh * v_i(ji,jj,jl) / MAX( ht_i(ji,jj,jl), epsi10 )
+                     ENDIF
+
+                     !zindh   =  MAX( rzero, SIGN( rone, ht_i(ji,jj,jl) - epsi10 ) )
+                     v_i(ji,jj,jl) = a_i(ji,jj,jl) * ht_i(ji,jj,jl)
+                     v_s(ji,jj,jl) = a_i(ji,jj,jl) * ht_s(ji,jj,jl)
+
+                     ! Update mass fluxes (clem)
+                     rdmicif(ji,jj) = rdmicif(ji,jj) + ( v_i(ji,jj,jl) - zvi ) * rhoic
+                     rdmsnif(ji,jj) = rdmsnif(ji,jj) + ( v_s(ji,jj,jl) - zvs ) * rhosn
+
+                  ENDIF
+
+                  diag_trp_vi(ji,jj) = diag_trp_vi(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) / rdt_ice
+
                END DO
             END DO
          END DO
 
+         ! ---
          DO jj = 1, jpj
             DO ji = 1, jpi
-               zs0at(ji,jj) = SUM( zs0a(ji,jj,1:jpl) )
+         !      ato_i(ji,jj) = 1._wp - SUM( a_i(ji,jj,1:jpl) ) !clem@rm-ow-advection
+               zs0at(ji,jj) = SUM( zs0a(ji,jj,1:jpl) ) ! clem@useless??
             END DO
          END DO
@@ -377,9 +475,10 @@
          !----------------------
 
-         zbigval = 1.d+13
+         zbigval = 1.e+13
 
          DO jl = 1, jpl
             DO jj = 1, jpj
                DO ji = 1, jpi
+                  zsmv = zs0sm(ji,jj,jl)
 
                   ! Switches and dummy variables
@@ -387,6 +486,6 @@
                   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 ) )
+                  zindsn          = MAX( rzero, SIGN( rone, v_s(ji,jj,jl) - epsi10 ) )
+                  zindic          = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) )
                   zindb           = MAX( zindsn, zindic )
 
@@ -394,6 +493,5 @@
                   zsal = MAX( MIN( (rhoic-rhosn)/rhoic*sss_m(ji,jj)  , &
                      zusvoic * zs0sm(ji,jj,jl) ), s_i_min ) * v_i(ji,jj,jl)
-                  IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) & 
-                     smv_i(ji,jj,jl) = zindic*zsal + (1.0-zindic)*0.0
+                  IF ( ( num_sal .EQ. 2 ) .OR. ( num_sal .EQ. 4 ) ) smv_i(ji,jj,jl) = zindic*zsal
 
                   zage = MAX( MIN( zbigval, zs0oi(ji,jj,jl) / & 
@@ -403,6 +501,8 @@
                   ! 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      
-
+                  e_s(ji,jj,1,jl) = zindsn * ze      
+
+                  ! Update salt fluxes (clem)
+                  fsalt_res(ji,jj) = fsalt_res(ji,jj) - ( smv_i(ji,jj,jl) - zsmv ) * rhoic / rdt_ice 
                END DO !ji
             END DO !jj
@@ -414,11 +514,34 @@
                   DO ji = 1, jpi
                      ! Ice heat content
-                     zindic          =  MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - zeps10 ) )
+                     zindic          =  MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi10 ) )
                      ze              =  MIN( MAX( 0.0, zs0e(ji,jj,jk,jl)*area(ji,jj) ), zbigval )
-                     e_i(ji,jj,jk,jl) = zindic * ze    + ( 1.0 - zindic ) * 0.0
+                     e_i(ji,jj,jk,jl) = zindic * ze
                   END DO !ji
                END DO ! jj
             END DO ! jk
          END DO ! jl
+
+
+      ! --- agglomerate variables (clem) -----------------
+      vt_i (:,:) = 0._wp
+      vt_s (:,:) = 0._wp
+      at_i (:,:) = 0._wp
+      !
+      DO jl = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               !
+               vt_i(ji,jj) = vt_i(ji,jj) + v_i(ji,jj,jl) ! ice volume
+               vt_s(ji,jj) = vt_s(ji,jj) + v_s(ji,jj,jl) ! snow volume
+               at_i(ji,jj) = at_i(ji,jj) + a_i(ji,jj,jl) ! ice concentration
+               !
+               zinda = MAX( rzero , SIGN( rone , at_i(ji,jj) - epsi16 ) )
+               icethi(ji,jj) = vt_i(ji,jj) / MAX( at_i(ji,jj) , epsi16 ) * zinda  ! ice thickness
+            END DO
+         END DO
+      END DO
+      ! -------------------------------------------------
+
+
 
       ENDIF
@@ -455,8 +578,28 @@
          END DO
       ENDIF
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
+         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
+ 
+         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
+         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
+
+         IF(lwp) THEN
+            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limtrp) = ',(zchk_v_i * 86400.)
+            IF (    ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limtrp) = ',(zchk_smv * 86400.)
+            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limtrp) = ',(MINVAL(v_i) * 1.e-3)
+            IF ( MINVAL( a_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation a_i<0               (limtrp) = ',MINVAL(a_i)
+         ENDIF
+      ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
       !
       CALL wrk_dealloc( jpi, jpj, zui_u, zvi_v, zsm, zs0at, zs0ow )
       CALL wrk_dealloc( jpi, jpj, jpl, zs0ice, zs0sn, zs0a, zs0c0 , zs0sm , zs0oi )
       CALL wrk_dealloc( jpi, jpj, jkmax, jpl, zs0e )
+
+      CALL wrk_dealloc( jpi,jpj,jpl,zaiold, zhimax )   ! clem
       !
    END SUBROUTINE lim_trp
Index: anches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limupdate.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limupdate.F90	(revision 3937)
+++ 	(revision )
@@ -1,1047 +1,0 @@
-MODULE limupdate
-   !!======================================================================
-   !!                     ***  MODULE  limupdate  ***
-   !!   LIM-3 : Update of sea-ice global variables at the end of the time step
-   !!======================================================================
-   !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!    lim_update   : computes update of sea-ice global variables from trend terms
-   !!----------------------------------------------------------------------
-   USE limrhg          ! ice rheology
-
-   USE dom_oce
-   USE oce             ! dynamics and tracers variables
-   USE in_out_manager
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice fields
-   USE dom_ice
-   USE phycst          ! physical constants
-   USE ice
-   USE limdyn
-   USE limtrp
-   USE limthd
-   USE limsbc
-   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
-   USE lbclnk           ! lateral boundary condition - MPP exchanges
-   USE wrk_nemo         ! work arrays
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_update   ! routine called by ice_step
-
-      REAL(wp)  ::   epsi06 = 1.e-06_wp   ! module constants
-      REAL(wp)  ::   epsi04 = 1.e-04_wp   !    -       -
-      REAL(wp)  ::   epsi03 = 1.e-03_wp   !    -       -
-      REAL(wp)  ::   epsi10 = 1.e-10_wp   !    -       -
-      REAL(wp)  ::   epsi16 = 1.e-16_wp   !    -       -
-      REAL(wp)  ::   epsi20 = 1.e-20_wp   !    -       -
-      REAL(wp)  ::   rzero  = 0._wp       !    -       -
-      REAL(wp)  ::   rone   = 1._wp       !    -       -
-         
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_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  :  
-      !!    Ice speed from ice dynamics
-      !!    Ice thickness, Snow thickness, Temperatures, Lead fraction
-      !!      from advection and ice thermodynamics 
-      !!
-      !! ** Action  : - 
-      !!---------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk, jl, jm    ! dummy loop indices
-      INTEGER ::   jbnd1, jbnd2
-      INTEGER ::   i_ice_switch
-      INTEGER ::   ind_im, layer      ! indices for internal melt
-      REAL(wp) ::   zweight, zesum, zhimax, z_da_i, z_dv_i
-      REAL(wp) ::   zindb, zindsn, zindic, zacrith
-      REAL(wp) ::   zrtt, zindg, zh, zdvres, zviold
-      REAL(wp) ::   zbigvalue, zvsold, z_da_ex, zamax
-      REAL(wp) ::   z_prescr_hi, zat_i_old, ztmelts, ze_s
-
-      INTEGER , POINTER, DIMENSION(:,:,:) ::  internal_melt
-      REAL(wp), POINTER, DIMENSION(:) ::   zthick0, zqm0      ! thickness of the layers and heat contents for
-      !!-------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj,jpl, internal_melt )   ! integer
-      CALL wrk_alloc( jkmax, zthick0, zqm0 )
-
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' lim_update '
-         WRITE(numout,*) ' ~~~~~~~~~~ '
-
-         WRITE(numout,*) ' O) Initial values '
-         WRITE(numout,*) ' a_i : ', a_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' at_i: ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-         DO jk = 1, nlay_i
-            WRITE(numout,*) ' e_i : ', e_i(jiindx, jjindx, jk, 1:jpl)
-         END DO
-      ENDIF
-
-      !------------------------------------------------------------------------------
-      ! 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
-         v_i(:,:,jl)  = v_i(:,:,jl) + d_v_i_trp(:,:,jl) + d_v_i_thd(:,:,jl) 
-         v_s(:,:,jl)  = v_s(:,:,jl) + d_v_s_trp(:,:,jl) + d_v_s_thd(:,:,jl)
-      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
-                  IF( ln_nicep ) THEN  
-                     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
-
-               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_m(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_m(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
-
-      IF( ln_nicep ) THEN  
-         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(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' at_i: ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-         DO jk = 1, nlay_i
-            WRITE(numout,*) ' e_i : ', e_i(jiindx, jjindx, jk, 1:jpl)
-         END DO
-      ENDIF
-
-      !---------------------------------------------
-      ! 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
-      IF( ln_nicep ) THEN 
-         DO jk = 1, nlay_i
-            WRITE(numout,*) ' t_i : ', t_i(jiindx, jjindx, jk, 1:jpl)
-         END DO
-      ENDIF
-      e_i(:,:,:,:) = e_i(:,:,:,:) + d_e_i_trp(:,:,:,:)  
-      CALL lim_var_glo2eqv    ! useless, just for debug
-      IF( ln_nicep) THEN
-         WRITE(numout,*) ' After transport update '
-         DO jk = 1, nlay_i
-            WRITE(numout,*) ' t_i : ', t_i(jiindx, jjindx, jk, 1:jpl)
-         END DO
-      ENDIF
-      e_i(:,:,:,:) = e_i(:,:,:,:) + d_e_i_thd(:,:,:,:)  
-      CALL lim_var_glo2eqv ! useless, just for debug
-      IF( ln_nicep ) THEN
-         WRITE(numout,*) ' After thermodyn update '
-         DO jk = 1, nlay_i
-            WRITE(numout,*) ' t_i : ', t_i(jiindx, jjindx, jk, 1:jpl)
-         END DO
-      ENDIF
-
-      at_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' 1. After update of Global variables (2) '
-         WRITE(numout,*) ' a_i : ', a_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' at_i: ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' oa_i : ', oa_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' e_s : ', e_s(jiindx, jjindx, 1, 1:jpl)
-         DO jk = 1, nlay_i
-            WRITE(numout,*) ' e_i : ', e_i(jiindx, jjindx, jk, 1:jpl)
-         END DO
-      ENDIF
-
-      !------------------------------
-      ! 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 == 2  .OR.  num_sal == 4  ) THEN      ! general case
-         !
-         IF( ln_nicep ) THEN  
-            WRITE(numout,*) ' Before everything '
-            WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-            WRITE(numout,*) ' oa_i:  ', oa_i(jiindx, jjindx, 1:jpl)
-            DO jk = 1, nlay_i
-               WRITE(numout,*) ' e_i : ', e_i(jiindx, jjindx, jk, 1:jpl)
-            END DO
-            WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-         ENDIF
-
-         smv_i(:,:,:) = smv_i(:,:,:) + d_smv_i_thd(:,:,:) + d_smv_i_trp(:,:,:)
-         !
-         IF( ln_nicep ) THEN  
-            WRITE(numout,*) ' After advection   '
-            WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-            WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-         ENDIF
-         !
-      ENDIF
-
-      CALL lim_var_glo2eqv
-
-      !--------------------------------------
-      ! 2. Review of all pathological cases
-      !--------------------------------------
-      zrtt    = 173.15_wp * rone
-      zacrith = 1.e-6_wp
-
-      !-------------------------------------------
-      ! 2.1) Advection of ice in an ice-free cell
-      !-------------------------------------------
-      ! should be removed since it is treated after dynamics now
-
-      zhimax = 5._wp
-      ! first category
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            !--- the thickness of such an ice is often out of bounds
-            !--- thus we recompute a new area while conserving ice volume
-            zat_i_old = SUM(old_a_i(ji,jj,:))
-            zindb          =  MAX( 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
-
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' 2.1 '
-         WRITE(numout,*) ' a_i : ', a_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' at_i: ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-         DO jk = 1, nlay_i
-            WRITE(numout,*) ' e_i : ', e_i(jiindx, jjindx, jk, 1:jpl)
-         END DO
-      ENDIF
-
-      !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
-
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' 2.1 initial '
-         WRITE(numout,*) ' a_i : ', a_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' at_i: ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-         DO jk = 1, nlay_i
-            WRITE(numout,*) ' e_i : ', e_i(jiindx, jjindx, jk, 1:jpl)
-         END DO
-      ENDIF
-
-      at_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      !----------------------------------------------------
-      ! 2.2) Rebin categories with thickness out of bounds
-      !----------------------------------------------------
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' 2.1 before rebinning '
-         WRITE(numout,*) ' a_i : ', a_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' at_i: ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-         DO jk = 1, nlay_i
-            WRITE(numout,*) ' e_i : ', e_i(jiindx, jjindx, jk, 1:jpl)
-         END DO
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-      ENDIF
-
-      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
-
-
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' 2.1 after rebinning'
-         WRITE(numout,*) ' a_i : ', a_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' at_i: ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-         DO jk = 1, nlay_i
-            WRITE(numout,*) ' e_i : ', e_i(jiindx, jjindx, jk, 1:jpl)
-            WRITE(numout,*) ' t_i : ', t_i(jiindx, jjindx, jk, 1:jpl)
-         END DO
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-      ENDIF
-
-      at_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      !---------------------------------
-      ! 2.3) Melt of an internal layer
-      !---------------------------------
-      internal_melt(:,:,:) = 0
-
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  ztmelts = - tmut * s_i(ji,jj,jk,jl) + rtt
-                  IF ( ( ( e_i(ji,jj,jk,jl) .LE. 0.0 ) .OR. &
-                     ( t_i(ji,jj,jk,jl) .GE. ztmelts ) ) .AND. &
-                     ( v_i(ji,jj,jl) .GT. 0.0 ) .AND. &
-                     ( a_i(ji,jj,jl) .GT. 0.0 ) ) THEN
-                     !                    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) = 1
-                  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) == 1 ) 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
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' 2.3 after melt of an internal ice layer '
-         WRITE(numout,*) ' a_i : ', a_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' at_i: ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-         DO jk = 1, nlay_i
-            WRITE(numout,*) ' e_i : ', e_i(jiindx, jjindx, jk, 1:jpl)
-            WRITE(numout,*) ' t_i : ', t_i(jiindx, jjindx, jk, 1:jpl)
-         END DO
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-      ENDIF
-
-      internal_melt(:,:,:) = 0
-
-      ! 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) = 1
-
-               IF( ln_nicep ) THEN  
-                  IF ( (ji.eq.jiindx) .AND. (jj.eq.jjindx) ) 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
-               ENDIF
-
-            END DO
-         END DO
-      END DO
-
-      DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               IF ( internal_melt(ji,jj,jl) == 1 ) THEN
-                  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
-
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' 2.8 '
-         WRITE(numout,*) ' a_i : ', a_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' at_i: ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-         DO jk = 1, nlay_i
-            WRITE(numout,*) ' e_i : ', e_i(jiindx, jjindx, jk, 1:jpl)
-         END DO
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-      ENDIF
-
-      !------------------------
-      ! 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
-
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' 2.9 '
-         DO jk = 1, nlay_i
-            WRITE(numout,*) ' e_i : ', e_i(jiindx, jjindx, jk, 1:jpl)
-         END DO
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-      ENDIF
-
-      !---------------------
-      ! 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_m(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
-
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' 2.11 '
-         WRITE(numout,*) ' a_i : ', a_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' at_i    ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-      ENDIF
-
-      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
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' 2.12 '
-         WRITE(numout,*) ' a_i : ', a_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' at_i    ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-      ENDIF
-
-      !--- 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(:,:) = a_i(:,:,1)
-      DO jl = 2, 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 = a_i(ji,jj,jl) * z_da_ex / MAX( at_i(ji,jj), epsi06 ) * zindb
-               z_dv_i = v_i(ji,jj,jl) * z_da_i  / MAX( at_i(ji,jj), epsi06 )
-               a_i(ji,jj,jl) = a_i(ji,jj,jl) - z_da_i
-               v_i(ji,jj,jl) = v_i(ji,jj,jl) + z_dv_i
-            END DO
-
-         END DO !ji
-      END DO !jj
-
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' 2.13 '
-         WRITE(numout,*) ' a_i : ', a_i(jiindx, jjindx, 1:jpl), ' at_i    ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl), ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-      ENDIF
-
-      at_i(:,:) = a_i(:,:,1)
-      DO jl = 2, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      IF( ln_nicep ) THEN  
-         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
-      ENDIF
-
-      ! Final thickness distribution rebinning
-      ! --------------------------------------
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' rebinning before'
-         WRITE(numout,*) ' a_i : ', a_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' at_i    ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-      ENDIF
-      !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
-
-      IF( ln_nicep ) THEN  
-         WRITE(numout,*) ' rebinning final'
-         WRITE(numout,*) ' a_i : ', a_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' at_i    ', at_i(jiindx,jjindx)
-         WRITE(numout,*) ' v_i : ', v_i(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' v_s : ', v_s(jiindx, jjindx, 1:jpl)
-         WRITE(numout,*) ' smv_i: ', smv_i(jiindx, jjindx, 1:jpl)
-      ENDIF
-
-      at_i(:,:) = a_i(:,:,1)
-      DO jl = 2, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      !------------------------------------------------------------------------------
-      ! 2) Corrections to avoid wrong values                                        |
-      !------------------------------------------------------------------------------
-      ! Ice drift
-      !------------
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1
-            IF ( at_i(ji,jj) .EQ. 0.0 ) THEN ! what to do if there is no ice
-               IF ( at_i(ji+1,jj) .EQ. 0.0 ) u_ice(ji,jj)   = 0.0 ! right side
-               IF ( at_i(ji-1,jj) .EQ. 0.0 ) u_ice(ji-1,jj) = 0.0 ! left side
-               IF ( at_i(ji,jj+1) .EQ. 0.0 ) v_ice(ji,jj)   = 0.0 ! upper side
-               IF ( at_i(ji,jj-1) .EQ. 0.0 ) v_ice(ji,jj-1) = 0.0 ! bottom side
-            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
-      !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
-      IF( ln_nicep ) THEN  
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               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(jiindx,jjindx), tio_v(jiindx,jjindx)
-         WRITE(numout,*) ' TESTOSC2 ', u_ice(jiindx,jjindx), v_ice(jiindx,jjindx)
-         WRITE(numout,*) ' TESTOSC3 ', u_oce(jiindx,jjindx), v_oce(jiindx,jjindx)
-         WRITE(numout,*) ' TESTOSC4 ', utau (jiindx,jjindx), vtau (jiindx,jjindx)
-      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_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_m  , clinfo1= ' lim_update : sst   : ', tab2d_2=sss_m     , 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=utau       , clinfo1= ' lim_update : utau      : ', tab2d_2=vtau       , clinfo2= ' vtau      : ')
-         CALL prt_ctl(tab2d_1=utau_ice   , clinfo1= ' lim_update : utau_ice  : ', tab2d_2=vtau_ice   , clinfo2= ' vtau_ice  : ')
-         CALL prt_ctl(tab2d_1=u_oce      , clinfo1= ' lim_update : u_oce     : ', tab2d_2=v_oce      , clinfo2= ' v_oce     : ')
-      ENDIF
-
-      CALL wrk_dealloc( jpi,jpj,jpl, internal_melt )   ! integer
-      CALL wrk_dealloc( jkmax, zthick0, zqm0 )
-
-   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/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limupdate1.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limupdate1.F90	(revision 3938)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limupdate1.F90	(revision 3938)
@@ -0,0 +1,461 @@
+MODULE limupdate1
+   !!======================================================================
+   !!                     ***  MODULE  limupdate1  ***
+   !!   LIM-3 : Update of sea-ice global variables at the end of the time step
+   !!======================================================================
+   !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!    lim_update1   : computes update of sea-ice global variables from trend terms
+   !!----------------------------------------------------------------------
+   USE limrhg          ! ice rheology
+
+   USE dom_oce
+   USE oce             ! dynamics and tracers variables
+   USE in_out_manager
+   USE sbc_oce         ! Surface boundary condition: ocean fields
+   USE sbc_ice         ! Surface boundary condition: ice fields
+   USE dom_ice
+   USE phycst          ! physical constants
+   USE ice
+   USE limdyn
+   USE limtrp
+   USE limthd
+   USE limsbc
+   USE limdia
+   USE limdiahsb
+   USE limwri
+   USE limrst
+   USE thd_ice         ! LIM thermodynamic sea-ice variables
+   USE par_ice
+   USE limitd_th
+   USE limvar
+   USE prtctl           ! Print control
+   USE lbclnk           ! lateral boundary condition - MPP exchanges
+   USE wrk_nemo         ! work arrays
+   USE lib_fortran     ! glob_sum
+   ! Check budget (Rousset)
+   USE in_out_manager   ! I/O manager
+   USE iom              ! I/O manager
+   USE lib_mpp          ! MPP library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   lim_update1   ! routine called by ice_step
+
+      REAL(wp)  ::   epsi06 = 1.e-06_wp   ! module constants
+      REAL(wp)  ::   epsi04 = 1.e-04_wp   !    -       -
+      REAL(wp)  ::   epsi03 = 1.e-03_wp   !    -       -
+      REAL(wp)  ::   epsi10 = 1.e-10_wp   !    -       -
+      REAL(wp)  ::   epsi16 = 1.e-16_wp   !    -       -
+      REAL(wp)  ::   epsi20 = 1.e-20_wp   !    -       -
+      REAL(wp)  ::   rzero  = 0._wp       !    -       -
+      REAL(wp)  ::   rone   = 1._wp       !    -       -
+         
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! $Id: limupdate.F90 3294 2012-01-28 16:44:18Z rblod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE lim_update1
+      !!-------------------------------------------------------------------
+      !!               ***  ROUTINE lim_update1  ***
+      !!               
+      !! ** Purpose :  Computes update of sea-ice global variables at 
+      !!               the end of the time step.
+      !!               Address pathological cases
+      !!               This place is very important
+      !!                
+      !! ** Method  :  
+      !!    Ice speed from ice dynamics
+      !!    Ice thickness, Snow thickness, Temperatures, Lead fraction
+      !!      from advection and ice thermodynamics 
+      !!
+      !! ** Action  : - 
+      !!---------------------------------------------------------------------
+      INTEGER ::   ji, jj, jk, jl, jm    ! dummy loop indices
+      INTEGER ::   jbnd1, jbnd2
+      INTEGER ::   i_ice_switch
+      INTEGER ::   ind_im, layer      ! indices for internal melt
+      REAL(wp) ::   zweight, zesum, z_da_i
+      REAL(wp) ::   zindb, zindsn, zindic
+      REAL(wp) ::   zindg, zh, zdvres, zviold2
+      REAL(wp) ::   zbigvalue, zvsold2, z_da_ex
+      REAL(wp) ::   z_prescr_hi, zat_i_old, ztmelts, ze_s
+
+      REAL(wp), POINTER, DIMENSION(:) ::   zthick0, zqm0      ! thickness of the layers and heat contents for
+      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
+      ! mass and salt flux (clem)
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zviold, zvsold, zsmvold   ! old ice volume...
+      !!-------------------------------------------------------------------
+
+      CALL wrk_alloc( jkmax, zthick0, zqm0 )
+
+      CALL wrk_alloc( jpi,jpj,jpl,zviold, zvsold, zsmvold )   ! clem
+
+      !------------------------------------------------------------------------------
+      ! 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
+         v_i(:,:,jl)  = v_i(:,:,jl) + d_v_i_trp(:,:,jl) 
+         v_s(:,:,jl)  = v_s(:,:,jl) + d_v_s_trp(:,:,jl)
+      END DO
+
+
+      !---------------------------------------------
+      ! Ice concentration and ice heat content
+      !---------------------------------------------
+      a_i (:,:,:)  = a_i (:,:,:) + d_a_i_trp(:,:,:)
+      e_i(:,:,:,:) = e_i(:,:,:,:) + d_e_i_trp(:,:,:,:)  
+
+      !------------------------------
+      ! Snow temperature and ice age
+      !------------------------------
+      e_s (:,:,:,:) = e_s (:,:,:,:) + d_e_s_trp (:,:,:,:)
+      oa_i(:,:,:)   = oa_i(:,:,:)   + d_oa_i_trp(:,:,:)  
+
+      !--------------
+      ! Ice salinity    
+      !--------------
+      IF(  num_sal == 2  .OR.  num_sal == 4  ) THEN      ! general case
+         smv_i(:,:,:) = smv_i(:,:,:) + d_smv_i_trp(:,:,:)
+      ENDIF
+
+      ! mass and salt flux init (clem)
+      zviold(:,:,:) = v_i(:,:,:)
+      zvsold(:,:,:) = v_s(:,:,:)
+      zsmvold(:,:,:) = smv_i(:,:,:)
+
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
+         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
+      ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
+
+      CALL lim_var_glo2eqv
+
+      !---------------------------------
+      ! Classify the pathological cases
+      !---------------------------------
+      ! (1) v_i (new) > 0; d_v_i_thd + v_i(old) > 0 (easy case)
+      ! (3) v_i (new) < 0; d_v_i_thd + v_i(old) > 0 (combined total ablation)
+      ! (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) .LT. 0.0 ) THEN
+                  patho_case(ji,jj,jl) = 3
+               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
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      !--------------------------------------
+      ! 2. Review of all pathological cases
+      !--------------------------------------
+     
+      at_i(:,:) = 0._wp
+      DO jl = 1, jpl
+         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+      END DO
+
+      !----------------------------------------------------
+      ! 2.2) Rebin categories with thickness out of bounds
+      !----------------------------------------------------
+      DO jm = 1, jpm
+         jbnd1 = ice_cat_bounds(jm,1)
+         jbnd2 = ice_cat_bounds(jm,2)
+         IF (ice_ncat_types(jm) .GT. 1 )   CALL lim_itd_th_reb(jbnd1, jbnd2, jm)
+      END DO
+
+      at_i(:,:) = 0._wp
+      DO jl = 1, jpl
+         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+      END DO
+
+      zbigvalue      = 1.0e+20
+
+      DO jl = 1, jpl
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+
+               !switches
+               zindb         = MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - 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
+               zdvres = (zindsn * zindb - 1._wp) * v_s(ji,jj,jl)
+               v_s(ji,jj,jl) = v_s(ji,jj,jl) + zdvres
+
+               !rdmsnif(ji,jj) = rdmsnif(ji,jj) + zdvres * rhosn
+ 
+               !--- 2.5 Correction to ice thickness
+               !-------------------------------------
+               zdvres = (zindb - 1._wp) * v_i(ji,jj,jl)
+               v_i(ji,jj,jl) = v_i(ji,jj,jl) + zdvres
+
+               !rdmicif(ji,jj) = rdmicif(ji,jj) + zdvres * rhoic
+               !fsalt_res(ji,jj)  = fsalt_res(ji,jj) - sm_i(ji,jj,jl) * ( rhoic * zdvres / rdt_ice )
+
+               !--- 2.6 Snow is transformed into ice if the original ice cover disappears
+               !----------------------------------------------------------------------------
+               zindg          = tms(ji,jj) *  MAX( 0._wp, SIGN( 1._wp, -v_i(ji,jj,jl) ) )
+               v_i(ji,jj,jl)  = v_i(ji,jj,jl) + zindg * rhosn * v_s(ji,jj,jl) / rau0
+               v_s(ji,jj,jl)  = ( 1._wp - 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
+               !clem a_i(ji,jj,jl) = zindb * MAX(zindsn, zindic) * MAX( a_i(ji,jj,jl), epsi06 )
+               a_i(ji,jj,jl) = zindb * a_i(ji,jj,jl)
+
+               !-------------------------
+               ! 2.8) Snow heat content
+               !-------------------------
+               e_s(ji,jj,1,jl) = zindsn * ( MIN ( MAX ( 0._wp, e_s(ji,jj,1,jl) ), zbigvalue ) )
+
+            END DO ! ji
+         END DO ! jj
+      END DO ! jl
+
+      !------------------------
+      ! 2.9) Ice heat content 
+      !------------------------
+
+      DO jl = 1, jpl
+         DO jk = 1, nlay_i
+            DO jj = 1, jpj 
+               DO ji = 1, jpi
+                  zindic        = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi04 ) ) 
+                  e_i(ji,jj,jk,jl)= zindic * ( MIN ( MAX ( 0.0, e_i(ji,jj,jk,jl) ), zbigvalue ) )
+               END DO ! ji
+            END DO ! jj
+         END DO !jk
+      END DO !jl
+ 
+      at_i(:,:) = 0._wp
+      DO jl = 1, jpl
+         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+      END DO
+
+      !--- 2.13 ice concentration should not exceed amax 
+      !-----------------------------------------------------
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            z_da_ex =  MAX( at_i(ji,jj) - amax , 0.0 )        
+            DO jl  = 1, jpl
+               zindb   =  MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi04 ) ) 
+               z_da_i = a_i(ji,jj,jl) * z_da_ex / MAX( at_i(ji,jj), epsi06 ) * zindb
+               a_i(ji,jj,jl) = a_i(ji,jj,jl) - z_da_i
+           END DO
+         END DO 
+      END DO 
+      at_i(:,:) = a_i(:,:,1)
+      DO jl = 2, jpl
+         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+      END DO
+
+      ! Final thickness distribution rebinning
+      ! --------------------------------------
+      DO jm = 1, jpm
+         jbnd1 = ice_cat_bounds(jm,1)
+         jbnd2 = ice_cat_bounds(jm,2)
+         IF (ice_ncat_types(jm) .GT. 1 ) CALL lim_itd_th_reb(jbnd1, jbnd2, jm)
+         IF (ice_ncat_types(jm) .EQ. 1 ) THEN
+         ENDIF
+      END DO
+
+      !---------------------
+      ! 2.11) Ice salinity
+      !---------------------
+      !clem@bug: smv_i should be updated too: smv_i(:,:,:) = smv_i(:,:,:) + sm_i(:,:,:) * ( v_i(:,:,:) - zviold(:,:,:) )
+      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_m(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) + epsi20))
+                     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
+
+      at_i(:,:) = a_i(:,:,1)
+      DO jl = 2, jpl
+         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+      END DO
+
+
+      !--------------------------------
+      ! Update mass/salt fluxes (clem)
+      !--------------------------------
+      DO jl = 1, jpl
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+               diag_res_pr(ji,jj) = diag_res_pr(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) / rdt_ice 
+               rdmicif(ji,jj) = rdmicif(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) * rhoic 
+               rdmsnif(ji,jj) = rdmsnif(ji,jj) + ( v_s(ji,jj,jl) - zvsold(ji,jj,jl) ) * rhosn 
+               fsalt_res(ji,jj) = fsalt_res(ji,jj) - ( smv_i(ji,jj,jl) - zsmvold(ji,jj,jl) ) * rhoic / rdt_ice 
+            END DO
+         END DO
+      END DO
+  
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
+         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
+ 
+         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
+         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
+
+         IF(lwp) THEN
+            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limupdate1) = ',(zchk_v_i * 86400.)
+            IF (    ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limupdate1) = ',(zchk_smv * 86400.)
+            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limupdate1) = ',(MINVAL(v_i) * 1.e-3)
+            IF ( MAXVAL( SUM(a_i(:,:,:),dim=3) ) >  amax+epsi10 ) WRITE(numout,*) 'violation a_i>amax    (limupdate1) = ',MAXVAL(SUM(a_i,dim=3))
+            IF ( MINVAL( a_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation a_i<0               (limupdate1) = ',MINVAL(a_i)
+         ENDIF
+      ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
+
+      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_update1  : cell area   :')
+         CALL prt_ctl(tab2d_1=at_i       , clinfo1=' lim_update1  : at_i        :')
+         CALL prt_ctl(tab2d_1=vt_i       , clinfo1=' lim_update1  : vt_i        :')
+         CALL prt_ctl(tab2d_1=vt_s       , clinfo1=' lim_update1  : vt_s        :')
+         CALL prt_ctl(tab2d_1=strength   , clinfo1=' lim_update1  : strength    :')
+         CALL prt_ctl(tab2d_1=u_ice      , clinfo1=' lim_update1  : u_ice       :', tab2d_2=v_ice      , clinfo2=' v_ice       :')
+         CALL prt_ctl(tab2d_1=d_u_ice_dyn, clinfo1=' lim_update1  : d_u_ice_dyn :', tab2d_2=d_v_ice_dyn, clinfo2=' d_v_ice_dyn :')
+         CALL prt_ctl(tab2d_1=old_u_ice  , clinfo1=' lim_update1  : old_u_ice   :', tab2d_2=old_v_ice  , clinfo2=' old_v_ice   :')
+
+         DO jl = 1, jpl
+            CALL prt_ctl_info(' ')
+            CALL prt_ctl_info(' - Category : ', ivar1=jl)
+            CALL prt_ctl_info('   ~~~~~~~~~~')
+            CALL prt_ctl(tab2d_1=ht_i       (:,:,jl)        , clinfo1= ' lim_update1  : ht_i        : ')
+            CALL prt_ctl(tab2d_1=ht_s       (:,:,jl)        , clinfo1= ' lim_update1  : ht_s        : ')
+            CALL prt_ctl(tab2d_1=t_su       (:,:,jl)        , clinfo1= ' lim_update1  : t_su        : ')
+            CALL prt_ctl(tab2d_1=t_s        (:,:,1,jl)      , clinfo1= ' lim_update1  : t_snow      : ')
+            CALL prt_ctl(tab2d_1=sm_i       (:,:,jl)        , clinfo1= ' lim_update1  : sm_i        : ')
+            CALL prt_ctl(tab2d_1=o_i        (:,:,jl)        , clinfo1= ' lim_update1  : o_i         : ')
+            CALL prt_ctl(tab2d_1=a_i        (:,:,jl)        , clinfo1= ' lim_update1  : a_i         : ')
+            CALL prt_ctl(tab2d_1=old_a_i    (:,:,jl)        , clinfo1= ' lim_update1  : old_a_i     : ')
+            CALL prt_ctl(tab2d_1=d_a_i_trp  (:,:,jl)        , clinfo1= ' lim_update1  : d_a_i_trp   : ')
+            CALL prt_ctl(tab2d_1=v_i        (:,:,jl)        , clinfo1= ' lim_update1  : v_i         : ')
+            CALL prt_ctl(tab2d_1=old_v_i    (:,:,jl)        , clinfo1= ' lim_update1  : old_v_i     : ')
+            CALL prt_ctl(tab2d_1=d_v_i_trp  (:,:,jl)        , clinfo1= ' lim_update1  : d_v_i_trp   : ')
+            CALL prt_ctl(tab2d_1=v_s        (:,:,jl)        , clinfo1= ' lim_update1  : v_s         : ')
+            CALL prt_ctl(tab2d_1=old_v_s    (:,:,jl)        , clinfo1= ' lim_update1  : old_v_s     : ')
+            CALL prt_ctl(tab2d_1=d_v_s_trp  (:,:,jl)        , clinfo1= ' lim_update1  : d_v_s_trp   : ')
+            CALL prt_ctl(tab2d_1=e_i        (:,:,1,jl)/1.0e9, clinfo1= ' lim_update1  : e_i1        : ')
+            CALL prt_ctl(tab2d_1=old_e_i    (:,:,1,jl)/1.0e9, clinfo1= ' lim_update1  : old_e_i1    : ')
+            CALL prt_ctl(tab2d_1=d_e_i_trp  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update1  : de_i1_trp   : ')
+            CALL prt_ctl(tab2d_1=e_i        (:,:,2,jl)/1.0e9, clinfo1= ' lim_update1  : e_i2        : ')
+            CALL prt_ctl(tab2d_1=old_e_i    (:,:,2,jl)/1.0e9, clinfo1= ' lim_update1  : old_e_i2    : ')
+            CALL prt_ctl(tab2d_1=d_e_i_trp  (:,:,2,jl)/1.0e9, clinfo1= ' lim_update1  : de_i2_trp   : ')
+            CALL prt_ctl(tab2d_1=e_s        (:,:,1,jl)      , clinfo1= ' lim_update1  : e_snow      : ')
+            CALL prt_ctl(tab2d_1=old_e_s    (:,:,1,jl)      , clinfo1= ' lim_update1  : old_e_snow  : ')
+            CALL prt_ctl(tab2d_1=d_e_s_trp  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update1  : d_e_s_trp   : ')
+            CALL prt_ctl(tab2d_1=smv_i      (:,:,jl)        , clinfo1= ' lim_update1  : smv_i       : ')
+            CALL prt_ctl(tab2d_1=old_smv_i  (:,:,jl)        , clinfo1= ' lim_update1  : old_smv_i   : ')
+            CALL prt_ctl(tab2d_1=d_smv_i_trp(:,:,jl)        , clinfo1= ' lim_update1  : d_smv_i_trp : ')
+            CALL prt_ctl(tab2d_1=oa_i       (:,:,jl)        , clinfo1= ' lim_update1  : oa_i        : ')
+            CALL prt_ctl(tab2d_1=old_oa_i   (:,:,jl)        , clinfo1= ' lim_update1  : old_oa_i    : ')
+            CALL prt_ctl(tab2d_1=d_oa_i_trp (:,:,jl)        , clinfo1= ' lim_update1  : d_oa_i_trp  : ')
+            CALL prt_ctl(tab2d_1=REAL(patho_case(:,:,jl))   , clinfo1= ' lim_update1  : 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_update1  : t_i       : ')
+            END DO
+         END DO
+
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Heat / FW fluxes : ')
+         CALL prt_ctl_info('   ~~~~~~~~~~~~~~~~~~ ')
+         CALL prt_ctl(tab2d_1=fmmec  , clinfo1= ' lim_update1 : fmmec : ', tab2d_2=fhmec     , clinfo2= ' fhmec     : ')
+         CALL prt_ctl(tab2d_1=sst_m  , clinfo1= ' lim_update1 : sst   : ', tab2d_2=sss_m     , clinfo2= ' sss       : ')
+         CALL prt_ctl(tab2d_1=fhbri  , clinfo1= ' lim_update1 : fhbri : ', tab2d_2=fheat_rpo , clinfo2= ' fheat_rpo : ')
+
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Stresses : ')
+         CALL prt_ctl_info('   ~~~~~~~~~~ ')
+         CALL prt_ctl(tab2d_1=utau       , clinfo1= ' lim_update1 : utau      : ', tab2d_2=vtau       , clinfo2= ' vtau      : ')
+         CALL prt_ctl(tab2d_1=utau_ice   , clinfo1= ' lim_update1 : utau_ice  : ', tab2d_2=vtau_ice   , clinfo2= ' vtau_ice  : ')
+         CALL prt_ctl(tab2d_1=u_oce      , clinfo1= ' lim_update1 : u_oce     : ', tab2d_2=v_oce      , clinfo2= ' v_oce     : ')
+      ENDIF
+   
+
+      CALL wrk_dealloc( jkmax, zthick0, zqm0 )
+
+      CALL wrk_dealloc( jpi,jpj,jpl,zviold, zvsold, zsmvold )   ! clem
+
+   END SUBROUTINE lim_update1
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty Module               No sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_update1     ! Empty routine
+   END SUBROUTINE lim_update1
+
+#endif
+
+END MODULE limupdate1
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limupdate2.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limupdate2.F90	(revision 3938)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limupdate2.F90	(revision 3938)
@@ -0,0 +1,615 @@
+MODULE limupdate2
+   !!======================================================================
+   !!                     ***  MODULE  limupdate2  ***
+   !!   LIM-3 : Update of sea-ice global variables at the end of the time step
+   !!======================================================================
+   !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!    lim_update2   : computes update of sea-ice global variables from trend terms
+   !!----------------------------------------------------------------------
+   USE limrhg          ! ice rheology
+
+   USE dom_oce
+   USE oce             ! dynamics and tracers variables
+   USE in_out_manager
+   USE sbc_oce         ! Surface boundary condition: ocean fields
+   USE sbc_ice         ! Surface boundary condition: ice fields
+   USE dom_ice
+   USE phycst          ! physical constants
+   USE ice
+   USE limdyn
+   USE limtrp
+   USE limthd
+   USE limsbc
+   USE limdia
+   USE limdiahsb
+   USE limwri
+   USE limrst
+   USE thd_ice         ! LIM thermodynamic sea-ice variables
+   USE par_ice
+   USE limitd_th
+   USE limitd_me
+   USE limvar
+   USE prtctl           ! Print control
+   USE lbclnk           ! lateral boundary condition - MPP exchanges
+   USE wrk_nemo         ! work arrays
+   USE lib_fortran     ! glob_sum
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   lim_update2   ! routine called by ice_step
+
+      REAL(wp)  ::   epsi06 = 1.e-06_wp   ! module constants
+      REAL(wp)  ::   epsi04 = 1.e-04_wp   !    -       -
+      REAL(wp)  ::   epsi10 = 1.e-10_wp   !    -       -
+      REAL(wp)  ::   epsi16 = 1.e-16_wp   !    -       -
+      REAL(wp)  ::   epsi20 = 1.e-20_wp   !    -       -
+      REAL(wp)  ::   rzero  = 0._wp       !    -       -
+      REAL(wp)  ::   rone   = 1._wp       !    -       -
+         
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! $Id: limupdate.F90 3294 2012-01-28 16:44:18Z rblod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE lim_update2
+      !!-------------------------------------------------------------------
+      !!               ***  ROUTINE lim_update2  ***
+      !!               
+      !! ** Purpose :  Computes update of sea-ice global variables at 
+      !!               the end of the time step.
+      !!               Address pathological cases
+      !!               This place is very important
+      !!                
+      !! ** Method  :  
+      !!    Ice speed from ice dynamics
+      !!    Ice thickness, Snow thickness, Temperatures, Lead fraction
+      !!      from advection and ice thermodynamics 
+      !!
+      !! ** Action  : - 
+      !!---------------------------------------------------------------------
+      INTEGER ::   ji, jj, jk, jl, jm    ! dummy loop indices
+      INTEGER ::   jbnd1, jbnd2
+      INTEGER ::   i_ice_switch
+      INTEGER ::   ind_im, layer      ! indices for internal melt
+      REAL(wp) ::   zweight, zesum, zhimax, z_da_i
+      REAL(wp) ::   zindb, zindsn, zindic
+      REAL(wp) ::   zindg, zh, zdvres, zviold2
+      REAL(wp) ::   zbigvalue, zvsold2, z_da_ex
+      REAL(wp) ::   z_prescr_hi, zat_i_old, ztmelts, ze_s
+
+      INTEGER , POINTER, DIMENSION(:,:,:) ::  internal_melt
+      REAL(wp), POINTER, DIMENSION(:) ::   zthick0, zqm0      ! thickness of the layers and heat contents for
+      REAL(wp) :: zchk_v_i, zchk_smv, zchk_fs, zchk_fw, zchk_v_i_b, zchk_smv_b, zchk_fs_b, zchk_fw_b ! Check conservation (C Rousset)
+
+      ! mass and salt flux (clem)
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zviold, zvsold, zsmvold   ! old ice volume...
+      !!-------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi,jpj,jpl, internal_melt )   ! integer
+      CALL wrk_alloc( jkmax, zthick0, zqm0 )
+
+      CALL wrk_alloc( jpi,jpj,jpl,zviold, zvsold, zsmvold )   ! clem
+
+      !------------------------------------------------------------------------------
+      ! 1. Update of Global variables                                               |
+      !------------------------------------------------------------------------------
+
+      !-----------------------------
+      ! Update ice and snow volumes  
+      !-----------------------------
+      DO jl = 1, jpl
+         v_i(:,:,jl)  = v_i(:,:,jl) + d_v_i_thd(:,:,jl) 
+         v_s(:,:,jl)  = v_s(:,:,jl) + d_v_s_thd(:,:,jl)
+      END DO
+ 
+      !---------------------------------------------
+      ! Ice concentration and ice heat content
+      !---------------------------------------------
+      a_i (:,:,:) = a_i (:,:,:) + d_a_i_thd(:,:,:)
+      e_i(:,:,:,:) = e_i(:,:,:,:) + d_e_i_thd(:,:,:,:)  
+ 
+      !------------------------------
+      ! Snow temperature and ice age
+      !------------------------------
+      e_s (:,:,:,:) = e_s (:,:,:,:) + d_e_s_thd (:,:,:,:)
+      oa_i(:,:,:)   = oa_i(:,:,:)   + d_oa_i_thd(:,:,:)
+
+      !--------------
+      ! Ice salinity    
+      !--------------
+      IF(  num_sal == 2  .OR.  num_sal == 4  ) THEN      ! general case
+         smv_i(:,:,:) = smv_i(:,:,:) + d_smv_i_thd(:,:,:)
+      ENDIF
+
+      ! mass and salt flux init (clem)
+      zviold(:,:,:) = v_i(:,:,:)
+      zvsold(:,:,:) = v_s(:,:,:)
+      zsmvold(:,:,:) = smv_i(:,:,:)
+
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         zchk_v_i_b = glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_smv_b = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) )
+         zchk_fw_b  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) )
+         zchk_fs_b  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) )
+      ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
+
+      CALL lim_var_glo2eqv
+
+      !---------------------------------
+      ! 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 )
+      !
+      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
+             END DO
+         END DO
+      END DO
+
+
+      !--------------------------------------
+      ! 2. Review of all pathological cases
+      !--------------------------------------
+
+
+      !----------------------------------------------------
+      ! 2.2) Rebin categories with thickness out of bounds
+      !----------------------------------------------------
+      DO jm = 1, jpm
+         jbnd1 = ice_cat_bounds(jm,1)
+         jbnd2 = ice_cat_bounds(jm,2)
+         IF (ice_ncat_types(jm) .GT. 1 )   CALL lim_itd_th_reb(jbnd1, jbnd2, jm)
+      END DO
+
+      !---------------------------------
+      ! 2.3) Melt of an internal layer
+      !---------------------------------
+      internal_melt(:,:,:) = 0
+
+      DO jl = 1, jpl
+         DO jk = 1, nlay_i
+            DO jj = 1, jpj 
+               DO ji = 1, jpi
+                  ztmelts = - tmut * s_i(ji,jj,jk,jl) + rtt
+                  IF ( ( ( e_i(ji,jj,jk,jl) .LE. 0.0 ) .OR. ( t_i(ji,jj,jk,jl) .GE. ztmelts ) ) &
+                    & .AND. ( v_i(ji,jj,jl) .GT. 0.0 ) .AND. ( a_i(ji,jj,jl) .GT. 0.0 ) ) THEN
+                     internal_melt(ji,jj,jl) = 1
+                  ENDIF
+               END DO ! ji
+            END DO ! jj
+         END DO !jk
+      END DO !jl
+
+      DO jl = 1, jpl
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+               IF( internal_melt(ji,jj,jl) == 1 ) THEN
+                  ! initial ice thickness
+                  !-----------------------
+                  ht_i(ji,jj,jl) = v_i(ji,jj,jl) / a_i(ji,jj,jl)
+
+                  ! reduce ice thickness
+                  !-----------------------
+                  ind_im = 0
+                  zesum = 0.0
+                  DO jk = 1, nlay_i
+                     ztmelts = - tmut * s_i(ji,jj,jk,jl) + rtt
+                     IF ( ( e_i(ji,jj,jk,jl) .LE. 0.0 ) .OR. ( t_i(ji,jj,jk,jl) .GE. ztmelts ) ) ind_im = ind_im + 1
+                     zesum = zesum + e_i(ji,jj,jk,jl)
+                  END DO
+                  IF (ind_im .LT. nlay_i ) THEN
+                     smv_i(ji,jj,jl) = smv_i(ji,jj,jl) / ht_i(ji,jj,jl) * ( ht_i(ji,jj,jl) - REAL(ind_im)*ht_i(ji,jj,jl) / REAL(nlay_i) )
+                  ENDIF
+                  ht_i(ji,jj,jl) = ht_i(ji,jj,jl) - REAL(ind_im)*ht_i(ji,jj,jl) / REAL(nlay_i)
+                  v_i(ji,jj,jl)  = ht_i(ji,jj,jl) * a_i(ji,jj,jl)
+
+                  !CLEM
+                  zdvres = REAL(ind_im)*ht_i(ji,jj,jl) / REAL(nlay_i) * a_i(ji,jj,jl)
+                  !rdmicif(ji,jj) = rdmicif(ji,jj) - zdvres * rhoic
+                  !fsalt_res(ji,jj)  = fsalt_res(ji,jj) + sm_i(ji,jj,jl) * ( rhoic * zdvres / rdt_ice )
+
+                  ! redistribute heat
+                  !-----------------------
+                  ! old thicknesses and enthalpies
+                  ind_im = 0
+                  DO jk = 1, nlay_i
+                     ztmelts = - tmut * s_i(ji,jj,jk,jl) + rtt
+                     IF ( ( e_i(ji,jj,jk,jl) .GT. 0.0 ) .AND.  & 
+                        ( t_i(ji,jj,jk,jl) .LT. ztmelts ) ) THEN
+                        ind_im = ind_im + 1
+                        zthick0(ind_im) = ht_i(ji,jj,jl) * REAL(ind_im / nlay_i)
+                        zqm0   (ind_im) = MAX( e_i(ji,jj,jk,jl) , 0.0 )
+                     ENDIF
+                  END DO
+
+                  ! Redistributing energy on the new grid
+                  IF ( ind_im .GT. 0 ) THEN
+
+                     DO jk = 1, nlay_i
+                        e_i(ji,jj,jk,jl) = 0.0
+                        DO layer = 1, ind_im
+                           zweight         = MAX (  &
+                              MIN( ht_i(ji,jj,jl) * REAL(layer/ind_im) , ht_i(ji,jj,jl) * REAL(jk / nlay_i) ) -       &
+                              MAX( ht_i(ji,jj,jl) * REAL((layer-1)/ind_im) , ht_i(ji,jj,jl) * REAL((jk-1) / nlay_i) ) , 0.0 ) &
+                              /  ( ht_i(ji,jj,jl) / REAL(ind_im) )
+
+                           e_i(ji,jj,jk,jl) =  e_i(ji,jj,jk,jl) + zweight*zqm0(layer)
+                        END DO !layer
+                     END DO ! jk
+
+                     zesum = 0.0
+                     DO jk = 1, nlay_i
+                        zesum = zesum + e_i(ji,jj,jk,jl)
+                     END DO
+
+                  ELSE ! ind_im .EQ. 0, total melt
+                     e_i(ji,jj,jk,jl) = 0.0
+                  ENDIF
+
+               ENDIF ! internal_melt
+
+            END DO ! ji
+         END DO !jj
+      END DO !jl
+
+      internal_melt(:,:,:) = 0
+
+
+      ! Melt of snow
+      !--------------
+      DO jl = 1, jpl
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+               ! snow energy of melting
+               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) = 1
+
+            END DO
+         END DO
+      END DO
+
+      DO jl = 1, jpl
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+               IF ( internal_melt(ji,jj,jl) == 1 ) THEN
+                  zdvres = v_s(ji,jj,jl)
+                  ! release heat
+                  fheat_res(ji,jj) = fheat_res(ji,jj) + ze_s * zdvres / rdt_ice
+                  ! release mass
+                  !rdmsnif(ji,jj) =  rdmsnif(ji,jj) - zdvres * rhosn
+                  !
+                  v_s(ji,jj,jl)   = 0.0
+                  e_s(ji,jj,1,jl) = 0.0
+                 ENDIF
+            END DO
+         END DO
+      END DO
+
+      zbigvalue      = 1.0e+20
+      DO jl = 1, jpl
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+
+               !switches
+               zindb         = MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - 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
+               !-------------------------------------
+               zdvres = (zindsn * zindb - 1._wp) * v_s(ji,jj,jl)
+               v_s(ji,jj,jl) = v_s(ji,jj,jl) + zdvres
+
+               !rdmsnif(ji,jj) = rdmsnif(ji,jj) + zdvres * rhosn
+ 
+               !--- 2.5 Correction to ice thickness
+               !-------------------------------------
+               zdvres = (zindb - 1._wp) * v_i(ji,jj,jl)
+               v_i(ji,jj,jl) = v_i(ji,jj,jl) + zdvres
+
+               !rdmicif(ji,jj) = rdmicif(ji,jj) + zdvres * rhoic
+               !fsalt_res(ji,jj)  = fsalt_res(ji,jj) - sm_i(ji,jj,jl) * ( rhoic * zdvres / rdt_ice )
+
+               !--- 2.6 Snow is transformed into ice if the original ice cover disappears
+               !----------------------------------------------------------------------------
+               zindg          = tms(ji,jj) *  MAX( 0._wp, SIGN( 1._wp, -v_i(ji,jj,jl) ) )
+               zdvres         = zindg * rhosn * v_s(ji,jj,jl) / rau0
+               v_i(ji,jj,jl)  = v_i(ji,jj,jl)  + zdvres
+
+               zdvres         = - zindg * v_s(ji,jj,jl) + zindg * v_i(ji,jj,jl) * ( rau0 - rhoic ) / rhosn
+               v_s(ji,jj,jl)  = v_s(ji,jj,jl)  + zdvres
+
+               !--- 2.7 Correction to ice concentrations 
+               !--------------------------------------------
+               !clem a_i(ji,jj,jl) = zindb * MAX(zindsn, zindic) * MAX( a_i(ji,jj,jl), epsi06 )
+               a_i(ji,jj,jl) = zindb * a_i(ji,jj,jl)
+
+               !-------------------------
+               ! 2.8) Snow heat content
+               !-------------------------
+               e_s(ji,jj,1,jl) = zindsn * ( MIN ( MAX ( 0.0, e_s(ji,jj,1,jl) ), zbigvalue ) )
+
+            END DO ! ji
+         END DO ! jj
+      END DO ! jl
+
+      !------------------------
+      ! 2.9) Ice heat content 
+      !------------------------
+
+      DO jl = 1, jpl
+         DO jk = 1, nlay_i
+            DO jj = 1, jpj 
+               DO ji = 1, jpi
+                  zindic        = MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi04 ) ) 
+                  e_i(ji,jj,jk,jl)= zindic * ( MIN ( MAX ( 0.0, e_i(ji,jj,jk,jl) ), zbigvalue ) )
+               END DO ! ji
+            END DO ! jj
+         END DO !jk
+      END DO !jl
+
+
+      DO jm = 1, jpm
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+               jl = ice_cat_bounds(jm,1)
+               !--- 2.12 Constrain the thickness of the smallest category above 5 cm
+               !----------------------------------------------------------------------
+               zindb         = MAX( rzero, SIGN( rone, a_i(ji,jj,jl) - 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
+               ht_i(ji,jj,jl) = ht_i(ji,jj,jl)* zh
+               a_i (ji,jj,jl) = a_i(ji,jj,jl) / zh
+               !CLEM
+               v_i (ji,jj,jl) = a_i(ji,jj,jl) * ht_i(ji,jj,jl)
+               v_s (ji,jj,jl) = a_i(ji,jj,jl) * ht_s(ji,jj,jl)
+            END DO !ji
+         END DO !jj
+      END DO !jm
+
+      at_i(:,:) = 0.0
+      DO jl = 1, jpl
+         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+      END DO
+      
+      !--- 2.13 ice concentration should not exceed amax 
+      !-----------------------------------------------------
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            z_da_ex =  MAX( at_i(ji,jj) - amax , 0.0 )        
+            DO jl  = 1, jpl
+               zindb   =  MAX( rzero, SIGN( rone, v_i(ji,jj,jl) - epsi04 ) ) 
+               z_da_i = a_i(ji,jj,jl) * z_da_ex / MAX( at_i(ji,jj), epsi06 ) * zindb
+               a_i(ji,jj,jl) = a_i(ji,jj,jl) - z_da_i
+            END DO
+         END DO
+      END DO
+      at_i(:,:) = 0.0
+      DO jl = 1, jpl
+         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+      END DO
+
+      ! Final thickness distribution rebinning
+      ! --------------------------------------
+      DO jm = 1, jpm
+         jbnd1 = ice_cat_bounds(jm,1)
+         jbnd2 = ice_cat_bounds(jm,2)
+         IF (ice_ncat_types(jm) .GT. 1 ) CALL lim_itd_th_reb(jbnd1, jbnd2, jm)
+         IF (ice_ncat_types(jm) .EQ. 1 ) THEN
+         ENDIF
+      END DO
+
+      !---------------------
+      ! 2.11) Ice salinity
+      !---------------------
+      !clem@bug: smv_i should be updated too: smv_i(:,:,:) = smv_i(:,:,:) + sm_i(:,:,:) * ( v_i(:,:,:) - zviold(:,:,:) )
+      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_m(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) + epsi20))
+                     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
+
+      ! -------------------
+      at_i(:,:) = a_i(:,:,1)
+      DO jl = 2, jpl
+         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+      END DO
+
+      !------------------------------------------------------------------------------
+      ! 2) Corrections to avoid wrong values                                        |
+      !------------------------------------------------------------------------------
+      ! Ice drift
+      !------------
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            IF ( at_i(ji,jj) .EQ. 0.0 ) THEN ! what to do if there is no ice
+               IF ( at_i(ji+1,jj) .EQ. 0.0 ) u_ice(ji,jj)   = 0.0 ! right side
+               IF ( at_i(ji-1,jj) .EQ. 0.0 ) u_ice(ji-1,jj) = 0.0 ! left side
+               IF ( at_i(ji,jj+1) .EQ. 0.0 ) v_ice(ji,jj)   = 0.0 ! upper side
+               IF ( at_i(ji,jj-1) .EQ. 0.0 ) v_ice(ji,jj-1) = 0.0 ! bottom side
+            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. )
+ 
+      !--------------------------------
+      ! Update mass/salt fluxes (clem)
+      !--------------------------------
+      DO jl = 1, jpl
+         DO jj = 1, jpj 
+            DO ji = 1, jpi
+               diag_res_pr(ji,jj) = diag_res_pr(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) / rdt_ice 
+               rdmicif(ji,jj) = rdmicif(ji,jj) + ( v_i(ji,jj,jl) - zviold(ji,jj,jl) ) * rhoic 
+               rdmsnif(ji,jj) = rdmsnif(ji,jj) + ( v_s(ji,jj,jl) - zvsold(ji,jj,jl) ) * rhosn 
+               fsalt_res(ji,jj) = fsalt_res(ji,jj) - ( smv_i(ji,jj,jl) - zsmvold(ji,jj,jl) ) * rhoic / rdt_ice 
+            END DO
+         END DO
+      END DO
+
+      ! -------------------------------
+      !- check conservation (C Rousset)
+      IF (ln_limdiahsb) THEN
+         zchk_fs  = glob_sum( ( fsbri(:,:) + fseqv(:,:) + fsalt_res(:,:) + fsalt_rpo(:,:) ) * area(:,:) * tms(:,:) ) - zchk_fs_b
+         zchk_fw  = glob_sum( rdmicif(:,:) * area(:,:) * tms(:,:) ) - zchk_fw_b
+ 
+         zchk_v_i = ( glob_sum( SUM(   v_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_v_i_b - ( zchk_fw / rhoic ) ) / rdt_ice
+         zchk_smv = ( glob_sum( SUM( smv_i(:,:,:), dim=3 ) * area(:,:) * tms(:,:) ) - zchk_smv_b ) / rdt_ice + ( zchk_fs / rhoic )
+
+         IF(lwp) THEN
+            IF (    ABS( zchk_v_i   ) >  1.e-5 ) WRITE(numout,*) 'violation volume [m3/day]     (limupdate2) = ',(zchk_v_i * 86400.)
+            IF (    ABS( zchk_smv   ) >  1.e-4 ) WRITE(numout,*) 'violation saline [psu*m3/day] (limupdate2) = ',(zchk_smv * 86400.)
+            IF ( MINVAL( v_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation v_i<0  [mm]         (limupdate2) = ',(MINVAL(v_i) * 1.e-3)
+            IF ( MAXVAL( SUM(a_i(:,:,:),dim=3) ) > amax+epsi10 ) WRITE(numout,*) 'violation a_i>amax    (limupdate2) = ',MAXVAL(SUM(a_i,dim=3))
+            IF ( MINVAL( a_i(:,:,:) ) <  0.    ) WRITE(numout,*) 'violation a_i<0               (limupdate2) = ',MINVAL(a_i)
+         ENDIF
+      ENDIF
+      !- check conservation (C Rousset)
+      ! -------------------------------
+
+      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_update2  : cell area   :')
+         CALL prt_ctl(tab2d_1=at_i       , clinfo1=' lim_update2  : at_i        :')
+         CALL prt_ctl(tab2d_1=vt_i       , clinfo1=' lim_update2  : vt_i        :')
+         CALL prt_ctl(tab2d_1=vt_s       , clinfo1=' lim_update2  : vt_s        :')
+         CALL prt_ctl(tab2d_1=strength   , clinfo1=' lim_update2  : strength    :')
+         CALL prt_ctl(tab2d_1=u_ice      , clinfo1=' lim_update2  : u_ice       :', tab2d_2=v_ice      , clinfo2=' v_ice       :')
+         CALL prt_ctl(tab2d_1=old_u_ice  , clinfo1=' lim_update2  : 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_update2  : ht_i        : ')
+            CALL prt_ctl(tab2d_1=ht_s       (:,:,jl)        , clinfo1= ' lim_update2  : ht_s        : ')
+            CALL prt_ctl(tab2d_1=t_su       (:,:,jl)        , clinfo1= ' lim_update2  : t_su        : ')
+            CALL prt_ctl(tab2d_1=t_s        (:,:,1,jl)      , clinfo1= ' lim_update2  : t_snow      : ')
+            CALL prt_ctl(tab2d_1=sm_i       (:,:,jl)        , clinfo1= ' lim_update2  : sm_i        : ')
+            CALL prt_ctl(tab2d_1=o_i        (:,:,jl)        , clinfo1= ' lim_update2  : o_i         : ')
+            CALL prt_ctl(tab2d_1=a_i        (:,:,jl)        , clinfo1= ' lim_update2  : a_i         : ')
+            CALL prt_ctl(tab2d_1=old_a_i    (:,:,jl)        , clinfo1= ' lim_update2  : old_a_i     : ')
+            CALL prt_ctl(tab2d_1=d_a_i_thd  (:,:,jl)        , clinfo1= ' lim_update2  : d_a_i_thd   : ')
+            CALL prt_ctl(tab2d_1=v_i        (:,:,jl)        , clinfo1= ' lim_update2  : v_i         : ')
+            CALL prt_ctl(tab2d_1=old_v_i    (:,:,jl)        , clinfo1= ' lim_update2  : old_v_i     : ')
+            CALL prt_ctl(tab2d_1=d_v_i_thd  (:,:,jl)        , clinfo1= ' lim_update2  : d_v_i_thd   : ')
+            CALL prt_ctl(tab2d_1=v_s        (:,:,jl)        , clinfo1= ' lim_update2  : v_s         : ')
+            CALL prt_ctl(tab2d_1=old_v_s    (:,:,jl)        , clinfo1= ' lim_update2  : old_v_s     : ')
+            CALL prt_ctl(tab2d_1=d_v_s_thd  (:,:,jl)        , clinfo1= ' lim_update2  : d_v_s_thd   : ')
+            CALL prt_ctl(tab2d_1=e_i        (:,:,1,jl)/1.0e9, clinfo1= ' lim_update2  : e_i1        : ')
+            CALL prt_ctl(tab2d_1=old_e_i    (:,:,1,jl)/1.0e9, clinfo1= ' lim_update2  : old_e_i1    : ')
+            CALL prt_ctl(tab2d_1=d_e_i_thd  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update2  : de_i1_thd   : ')
+            CALL prt_ctl(tab2d_1=e_i        (:,:,2,jl)/1.0e9, clinfo1= ' lim_update2  : e_i2        : ')
+            CALL prt_ctl(tab2d_1=old_e_i    (:,:,2,jl)/1.0e9, clinfo1= ' lim_update2  : old_e_i2    : ')
+            CALL prt_ctl(tab2d_1=d_e_i_thd  (:,:,2,jl)/1.0e9, clinfo1= ' lim_update2  : de_i2_thd   : ')
+            CALL prt_ctl(tab2d_1=e_s        (:,:,1,jl)      , clinfo1= ' lim_update2  : e_snow      : ')
+            CALL prt_ctl(tab2d_1=old_e_s    (:,:,1,jl)      , clinfo1= ' lim_update2  : old_e_snow  : ')
+            CALL prt_ctl(tab2d_1=d_e_s_thd  (:,:,1,jl)/1.0e9, clinfo1= ' lim_update2  : d_e_s_thd   : ')
+            CALL prt_ctl(tab2d_1=smv_i      (:,:,jl)        , clinfo1= ' lim_update2  : smv_i       : ')
+            CALL prt_ctl(tab2d_1=old_smv_i  (:,:,jl)        , clinfo1= ' lim_update2  : old_smv_i   : ')
+            CALL prt_ctl(tab2d_1=d_smv_i_thd(:,:,jl)        , clinfo1= ' lim_update2  : d_smv_i_thd : ')
+            CALL prt_ctl(tab2d_1=oa_i       (:,:,jl)        , clinfo1= ' lim_update2  : oa_i        : ')
+            CALL prt_ctl(tab2d_1=old_oa_i   (:,:,jl)        , clinfo1= ' lim_update2  : old_oa_i    : ')
+            CALL prt_ctl(tab2d_1=d_oa_i_thd (:,:,jl)        , clinfo1= ' lim_update2  : d_oa_i_thd  : ')
+            CALL prt_ctl(tab2d_1=REAL(patho_case(:,:,jl))   , clinfo1= ' lim_update2  : 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_update2  : t_i       : ')
+            END DO
+         END DO
+
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Heat / FW fluxes : ')
+         CALL prt_ctl_info('   ~~~~~~~~~~~~~~~~~~ ')
+         CALL prt_ctl(tab2d_1=fmmec  , clinfo1= ' lim_update2 : fmmec : ', tab2d_2=fhmec     , clinfo2= ' fhmec     : ')
+         CALL prt_ctl(tab2d_1=sst_m  , clinfo1= ' lim_update2 : sst   : ', tab2d_2=sss_m     , clinfo2= ' sss       : ')
+         CALL prt_ctl(tab2d_1=fhbri  , clinfo1= ' lim_update2 : fhbri : ', tab2d_2=fheat_rpo , clinfo2= ' fheat_rpo : ')
+
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Stresses : ')
+         CALL prt_ctl_info('   ~~~~~~~~~~ ')
+         CALL prt_ctl(tab2d_1=utau       , clinfo1= ' lim_update2 : utau      : ', tab2d_2=vtau       , clinfo2= ' vtau      : ')
+         CALL prt_ctl(tab2d_1=utau_ice   , clinfo1= ' lim_update2 : utau_ice  : ', tab2d_2=vtau_ice   , clinfo2= ' vtau_ice  : ')
+         CALL prt_ctl(tab2d_1=u_oce      , clinfo1= ' lim_update2 : u_oce     : ', tab2d_2=v_oce      , clinfo2= ' v_oce     : ')
+      ENDIF
+   
+      CALL wrk_dealloc( jpi,jpj,jpl, internal_melt )   ! integer
+      CALL wrk_dealloc( jkmax, zthick0, zqm0 )
+
+      CALL wrk_dealloc( jpi,jpj,jpl,zviold, zvsold, zsmvold )   ! clem
+
+   END SUBROUTINE lim_update2
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty Module               No sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_update2     ! Empty routine
+   END SUBROUTINE lim_update2
+
+#endif
+
+END MODULE limupdate2
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90	(revision 3938)
@@ -53,4 +53,5 @@
    USE lib_mpp          ! MPP library
    USE wrk_nemo         ! work arrays
+   USE lib_fortran      ! to use key_nosignedzero
 
    IMPLICIT NONE
@@ -61,12 +62,13 @@
    PUBLIC   lim_var_eqv2glo      !
    PUBLIC   lim_var_salprof      !
+   PUBLIC   lim_var_icetm        !
    PUBLIC   lim_var_bv           !
    PUBLIC   lim_var_salprof1d    !
 
-   REAL(wp) ::   eps20 = 1.e-20_wp   ! module constants
-   REAL(wp) ::   eps16 = 1.e-16_wp   !    -       -
-   REAL(wp) ::   eps13 = 1.e-13_wp   !    -       -
-   REAL(wp) ::   eps10 = 1.e-10_wp   !    -       -
-   REAL(wp) ::   eps06 = 1.e-06_wp   !    -       -
+   REAL(wp) ::   epsi20 = 1.e-20_wp   ! module constants
+   REAL(wp) ::   epsi16 = 1.e-16_wp   !    -       -
+   REAL(wp) ::   epsi13 = 1.e-13_wp   !    -       -
+   REAL(wp) ::   epsi10 = 1.e-10_wp   !    -       -
+   REAL(wp) ::   epsi06 = 1.e-06_wp   !    -       -
    REAL(wp) ::   zzero = 0.e0        !    -       -
    REAL(wp) ::   zone  = 1.e0        !    -       -
@@ -96,5 +98,5 @@
       !
       INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) ::   zinda
+      REAL(wp) ::   zinda, zindb
       !!------------------------------------------------------------------
 
@@ -115,6 +117,6 @@
                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) , eps16 ) * zinda  ! ice thickness
+               zinda = MAX( zzero , SIGN( zone , at_i(ji,jj) - epsi16 ) ) 
+               icethi(ji,jj) = vt_i(ji,jj) / MAX( at_i(ji,jj) , epsi16 ) * zinda  ! ice thickness
             END DO
          END DO
@@ -136,13 +138,13 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
+                  zinda = MAX( zzero , SIGN( zone , vt_i(ji,jj) - epsi16 ) ) 
+                  zindb = MAX( zzero , SIGN( zone , at_i(ji,jj) - epsi16 ) ) 
                   et_s(ji,jj)  = et_s(ji,jj)  + e_s(ji,jj,1,jl)                                       ! snow heat content
-                  zinda = MAX( zzero , SIGN( zone , vt_i(ji,jj) - 0.10 ) ) 
-                  smt_i(ji,jj) = smt_i(ji,jj) + smv_i(ji,jj,jl) / MAX( vt_i(ji,jj) , eps13 ) * zinda   ! ice salinity
-                  zinda = MAX( zzero , SIGN( zone , at_i(ji,jj) - 0.10 ) ) 
-                  ot_i(ji,jj)  = ot_i(ji,jj)  + oa_i(ji,jj,jl)  / MAX( at_i(ji,jj) , eps13 ) * zinda   ! ice age
-               END DO
-            END DO
-         END DO
-         !
+                  smt_i(ji,jj) = smt_i(ji,jj) + smv_i(ji,jj,jl) / MAX( vt_i(ji,jj) , epsi16 ) * zinda   ! ice salinity
+                  ot_i(ji,jj)  = ot_i(ji,jj)  + oa_i(ji,jj,jl)  / MAX( at_i(ji,jj) , epsi16 ) * zindb   ! ice age
+               END DO
+            END DO
+         END DO
+          !
          DO jl = 1, jpl
             DO jk = 1, nlay_i
@@ -174,8 +176,8 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp,- 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) , eps10 ) * zindb
-               ht_s(ji,jj,jl) = v_s (ji,jj,jl) / MAX( a_i(ji,jj,jl) , eps10 ) * zindb
-               o_i(ji,jj,jl)  = oa_i(ji,jj,jl) / MAX( a_i(ji,jj,jl) , eps10 ) * zindb
+               zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp,- a_i(ji,jj,jl) + epsi10 ) )   !0 if no ice and 1 if yes
+               ht_i(ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi10 ) * zindb
+               ht_s(ji,jj,jl) = v_s (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi10 ) * zindb
+               o_i(ji,jj,jl)  = oa_i(ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi10 ) * zindb
             END DO
          END DO
@@ -186,6 +188,6 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp,- 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) , eps10 ) * zindb
+                  zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp,- a_i(ji,jj,jl) + epsi10 ) )   !0 if no ice and 1 if yes
+                  sm_i(ji,jj,jl) = smv_i(ji,jj,jl) / MAX( v_i(ji,jj,jl) , epsi10 ) * zindb
                END DO
             END DO
@@ -207,5 +209,5 @@
                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) , eps06 ) * REAL(nlay_i,wp) 
+                  zq_i    = e_i(ji,jj,jk,jl) / area(ji,jj) / MAX( v_i(ji,jj,jl) , epsi06 ) * REAL(nlay_i,wp) 
                   zindb   = 1.0 - MAX( 0.0 , SIGN( 1.0 , - v_i(ji,jj,jl) ) )     ! zindb = 0 if no ice and 1 if yes
                   zq_i    = zq_i * unit_fac * zindb                              !convert units
@@ -233,5 +235,5 @@
                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) , eps06 ) ) * REAL(nlay_s,wp)
+                  zq_s  = e_s(ji,jj,jk,jl) / ( area(ji,jj) * MAX( v_s(ji,jj,jl) , epsi06 ) ) * REAL(nlay_s,wp)
                   zindb = 1._wp - MAX( 0._wp , SIGN( 1._wp , - v_s(ji,jj,jl) ) )     ! zindb = 0 if no ice and 1 if yes
                   zq_s  = zq_s * unit_fac * zindb                                    ! convert units
@@ -252,8 +254,7 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zindb = (  1._wp - MAX( 0._wp , SIGN( 1._wp , -a_i(ji,jj,jl) ) )  )   &
-                     &  * (  1._wp - MAX( 0._wp , SIGN( 1._wp , -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,wp) * MAX( vt_i(ji,jj) , eps10 )  )
+                  zindb = (  1._wp - MAX( 0._wp , SIGN( 1._wp , - vt_i(ji,jj) + epsi10 ) )  )
+                  tm_i(ji,jj) = tm_i(ji,jj) + zindb * t_i(ji,jj,jk,jl) * v_i(ji,jj,jl)   &
+                     &                      / (  REAL(nlay_i,wp) * MAX( vt_i(ji,jj) , epsi10 )  )
                END DO
             END DO
@@ -337,16 +338,16 @@
                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) ) ) 
+                  zind0  = MAX( 0._wp   , SIGN( 1._wp  , 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) ) ) 
+                  zind01 = ( 1._wp - zind0 ) * MAX( 0._wp   , SIGN( 1._wp  , s_i_1 - sm_i(ji,jj,jl) ) ) 
                   ! If 2.sm_i GE sss_m then zindbal = 1
-                  zindbal = MAX( 0.0 , SIGN( 1.0 , 2. * sm_i(ji,jj,jl) - sss_m(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
-
-         dummy_fac = 1._wp / nlay_i                   ! Computation of the profile
+                  zindbal = MAX( 0._wp , SIGN( 1._wp , 2._wp * sm_i(ji,jj,jl) - sss_m(ji,jj) ) )
+                  zalpha(ji,jj,jl) = zind0  + zind01 * ( sm_i(ji,jj,jl) * dummy_fac0 + dummy_fac1 )
+                  zalpha(ji,jj,jl) = zalpha(ji,jj,jl) * ( 1._wp - zindbal )
+               END DO
+            END DO
+         END DO
+
+         dummy_fac = 1._wp / REAL( nlay_i )                   ! Computation of the profile
          DO jl = 1, jpl
             DO jk = 1, nlay_i
@@ -388,4 +389,31 @@
 
 
+   SUBROUTINE lim_var_icetm
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE lim_var_icetm ***
+      !!
+      !! ** Purpose :   computes mean sea ice temperature
+      !!------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
+      REAL(wp) ::   zindb   !   -      -
+      !!------------------------------------------------------------------
+
+      ! Mean sea ice temperature
+      tm_i(:,:) = 0._wp
+      DO jl = 1, jpl
+         DO jk = 1, nlay_i
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zindb = (  1._wp - MAX( 0._wp , SIGN( 1._wp , - vt_i(ji,jj) + epsi10 ) )  )
+                  tm_i(ji,jj) = tm_i(ji,jj) + zindb * t_i(ji,jj,jk,jl) * v_i(ji,jj,jl)   &
+                     &                      / (  REAL(nlay_i,wp) * MAX( vt_i(ji,jj) , epsi10 )  )
+               END DO
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE lim_var_icetm
+
+
    SUBROUTINE lim_var_bv
       !!------------------------------------------------------------------
@@ -399,5 +427,5 @@
       !!------------------------------------------------------------------
       INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) ::   zbvi, zindb      ! local scalars
+      REAL(wp) ::   zbvi, zinda, zindb      ! local scalars
       !!------------------------------------------------------------------
       !
@@ -407,8 +435,9 @@
             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
-                  zbvi  = - zindb * tmut * s_i(ji,jj,jk,jl) / MIN( t_i(ji,jj,jk,jl) - 273.15 , eps13 )   &
+                  zinda = (  1._wp - MAX( 0._wp , SIGN( 1._wp , (t_i(ji,jj,jk,jl) - rtt) + epsi16 ) )  )
+                  zindb = (  1._wp - MAX( 0._wp , SIGN( 1._wp , - vt_i(ji,jj) + epsi16 ) )  )
+                  zbvi  = - zinda * tmut * s_i(ji,jj,jk,jl) / MIN( t_i(ji,jj,jk,jl) - rtt, - epsi16 )   &
                      &                   * v_i(ji,jj,jl)    / REAL(nlay_i,wp)
-                  bv_i(ji,jj) = bv_i(ji,jj) + zbvi  / MAX( vt_i(ji,jj) , eps13 )
+                  bv_i(ji,jj) = bv_i(ji,jj) + zindb * zbvi  / MAX( vt_i(ji,jj) , epsi16 )
                END DO
             END DO
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90	(revision 3938)
@@ -10,4 +10,5 @@
    !!   lim_wri      : write of the diagnostics variables in ouput file 
    !!   lim_wri_init : initialization and namelist read
+   !!   lim_wri_state : write for initial state or/and abandon
    !!----------------------------------------------------------------------
    USE ioipsl
@@ -25,4 +26,7 @@
    USE wrk_nemo        ! work arrays
    USE par_ice
+   USE iom
+   USE timing          ! Timing
+   USE lib_fortran     ! Fortran utilities
 
    IMPLICIT NONE
@@ -30,6 +34,7 @@
 
    PUBLIC lim_wri        ! routine called by lim_step.F90
-
-   INTEGER, PARAMETER ::   jpnoumax = 40   !: maximum number of variable for ice output
+   PUBLIC lim_wri_state  ! called by dia_wri_state 
+
+   INTEGER, PARAMETER ::   jpnoumax = 43   !: maximum number of variable for ice output
    
    INTEGER  ::   noumef             ! number of fields
@@ -47,5 +52,5 @@
    INTEGER            , DIMENSION(jpnoumax) ::   nc  , nca     ! switch for saving field ( = 1 ) or not ( = 0 )
 
-   REAL(wp)  ::   epsi16 = 1e-16_wp
+   REAL(wp)  ::   epsi06 = 1e-6_wp
    REAL(wp)  ::   zzero  = 0._wp
    REAL(wp)  ::   zone   = 1._wp      
@@ -76,5 +81,5 @@
       INTEGER ::  ierr
       REAL(wp),DIMENSION(1) ::   zdept
-      REAL(wp) ::  zsto, zjulian, zout, zindh, zinda, zindb
+      REAL(wp) ::  zsto, zjulian, zout, zindh, zinda, zindb, zindc
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   zcmo, zcmoa
       REAL(wp), POINTER, DIMENSION(:,:  ) ::   zfield
@@ -88,4 +93,6 @@
       INTEGER , ALLOCATABLE, DIMENSION(:), SAVE ::   ndexitd
       !!-------------------------------------------------------------------
+
+      IF( nn_timing == 1 )  CALL timing_start('limwri')
 
       CALL wrk_alloc( jpi, jpj, zfield )
@@ -126,5 +133,5 @@
          CALL ymds2ju ( nyear, nmonth, nday, rdt, zjulian )
          zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
-         CALL dia_nam ( clhstnam, nwrite, 'icemod' )
+         CALL dia_nam ( clhstnam, nwrite, 'icemod_old' )
          CALL histbeg ( clhstnam, jpi, glamt, jpj, gphit, 1, jpi, 1, jpj, niter, zjulian, rdt_ice,   &
             &           nhorid, nice, domain_id=nidom, snc4chunks=snc4set )
@@ -158,6 +165,5 @@
             nhorida,                   & ! ? linked with horizontal ...
             nicea , domain_id=nidom, snc4chunks=snc4set)                  ! file 
-         CALL histvert( nicea, "icethi", "L levels",               &
-            "m", ipl , hi_mean , nz )
+         CALL histvert( nicea, "icethi", "L levels","m", ipl , hi_mean , nz )
          DO jl = 1, jpl
             zmaskitd(:,:,jl) = tmask(:,:,1)
@@ -197,36 +203,40 @@
       zcmoa( 1:jpi, 1:jpj, 1:jpnoumax ) = 0._wp
 
+      ! Ice surface temperature and some fluxes
       DO jl = 1, jpl
          DO jj = 1, jpj
             DO ji = 1, jpi
-               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 ) )
+               zinda  = MAX( zzero , SIGN( zone , at_i(ji,jj) - epsi06 ) )
                zcmo(ji,jj,17) = zcmo(ji,jj,17) + a_i(ji,jj,jl)*qsr_ice (ji,jj,jl) 
                zcmo(ji,jj,18) = zcmo(ji,jj,18) + a_i(ji,jj,jl)*qns_ice(ji,jj,jl) 
-               zcmo(ji,jj,27) = zcmo(ji,jj,27) + t_su(ji,jj,jl)*a_i(ji,jj,jl)/MAX(at_i(ji,jj),epsi16)*zinda
+               zcmo(ji,jj,27) = zcmo(ji,jj,27) + zinda*(t_su(ji,jj,jl)-rtt)*a_i(ji,jj,jl)/MAX(at_i(ji,jj),epsi06)
+               zcmo(ji,jj,21) = zcmo(ji,jj,21) + zinda*oa_i(ji,jj,jl)/MAX(at_i(ji,jj),epsi06) 
             END DO
          END DO
       END DO
 
+      ! Mean sea ice temperature
+      CALL lim_var_icetm
+
+      ! Brine volume
       CALL lim_var_bv
 
       DO jj = 2 , jpjm1
          DO ji = 2 , jpim1
-            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
+            zinda  = MAX( zzero , SIGN( zone , at_i(ji,jj) - epsi06 ) )
+            zindb  = MAX( zzero , SIGN( zone , at_i(ji,jj) ) )
 
             zcmo(ji,jj,1)  = at_i(ji,jj)
-            zcmo(ji,jj,2)  = vt_i(ji,jj) / MAX( at_i(ji,jj), 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) ) * 0.5_wp
-            zcmo(ji,jj,8)  = zindb * (  v_ice(ji,jj) * tmv(ji,jj) + v_ice(ji,jj-1) * tmv(ji,jj-1) ) * 0.5_wp
+            zcmo(ji,jj,2)  = vt_i(ji,jj) / MAX( at_i(ji,jj), epsi06 ) * zinda
+            zcmo(ji,jj,3)  = vt_s(ji,jj) / MAX( at_i(ji,jj), epsi06 ) * zinda
+            zcmo(ji,jj,4)  = diag_bot_gr(ji,jj) * 86400.0     ! Bottom thermodynamic ice production
+            zcmo(ji,jj,5)  = diag_dyn_gr(ji,jj) * 86400.0     ! Dynamic ice production (rid/raft)
+            zcmo(ji,jj,22) = diag_lat_gr(ji,jj) * 86400.0     ! Lateral thermodynamic ice production
+            zcmo(ji,jj,23) = diag_sni_gr(ji,jj) * 86400.0     ! Snow ice production ice production
+            zcmo(ji,jj,24) = (tm_i(ji,jj) - rtt) * zinda
+
+            zcmo(ji,jj,6)  = fbif(ji,jj)*at_i(ji,jj)
+            zcmo(ji,jj,7)  = (  u_ice(ji,jj) * tmu(ji,jj) + u_ice(ji-1,jj) * tmu(ji-1,jj) ) * 0.5_wp
+            zcmo(ji,jj,8)  = (  v_ice(ji,jj) * tmv(ji,jj) + v_ice(ji,jj-1) * tmv(ji,jj-1) ) * 0.5_wp
             zcmo(ji,jj,9)  = sst_m(ji,jj)
             zcmo(ji,jj,10) = sss_m(ji,jj)
@@ -242,5 +252,4 @@
             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)
@@ -249,12 +258,21 @@
 
             zcmo(ji,jj,30) = bv_i(ji,jj)
-            zcmo(ji,jj,31) = hicol(ji,jj)
+            zcmo(ji,jj,31) = hicol(ji,jj) * zindb
             zcmo(ji,jj,32) = strength(ji,jj)
             zcmo(ji,jj,33) = SQRT(  zcmo(ji,jj,7)*zcmo(ji,jj,7) + zcmo(ji,jj,8)*zcmo(ji,jj,8)  )
-            zcmo(ji,jj,34) = diag_sur_me(ji,jj) * 86400.0 * zinda    ! Surface melt
-            zcmo(ji,jj,35) = diag_bot_me(ji,jj) * 86400.0 * zinda    ! Bottom melt
+            zcmo(ji,jj,34) = diag_sur_me(ji,jj) * 86400.0     ! Surface melt
+            zcmo(ji,jj,35) = diag_bot_me(ji,jj) * 86400.0     ! Bottom melt
             zcmo(ji,jj,36) = divu_i(ji,jj)
             zcmo(ji,jj,37) = shear_i(ji,jj)
-         END DO
+            zcmo(ji,jj,38) = diag_res_pr(ji,jj) * 86400.0     ! Bottom melt
+            zcmo(ji,jj,39) = vt_i(ji,jj)  ! ice volume
+            zcmo(ji,jj,40) = vt_s(ji,jj)  ! snow volume
+
+            zcmo(ji,jj,41) = fsalt_rpo(ji,jj)
+            zcmo(ji,jj,42) = fsalt_res(ji,jj)
+
+            zcmo(ji,jj,43) = diag_trp_vi(ji,jj) * 86400.0     ! transport of ice volume
+
+        END DO
       END DO
 
@@ -285,4 +303,46 @@
       ENDIF
 
+       CALL iom_put ('iceconc', zcmo(:,:,1) )          ! field1: ice concentration
+       CALL iom_put ('icethic_cea', zcmo(:,:,2) )      ! field2: ice thickness (i.e. icethi(:,:))
+       CALL iom_put ('snowthic_cea', zcmo(:,:,3))      ! field3: snow thickness
+       CALL iom_put ('icebopr', zcmo(:,:,4) )   ! field4: daily bottom thermo ice production
+       CALL iom_put ('icedypr', zcmo(:,:,5) )   ! field5: daily dynamic ice production
+       CALL iom_put ('ioceflxb', zcmo(:,:,6) )         ! field6: Oceanic flux at the ice base
+       CALL iom_put ('uice_ipa', zcmo(:,:,7) )         ! field7: ice velocity u component
+       CALL iom_put ('vice_ipa', zcmo(:,:,8) )         ! field8: ice velocity v component
+       CALL iom_put ('isst', zcmo(:,:,9) )             ! field 9: sea surface temperature
+       CALL iom_put ('isss', zcmo(:,:,10) )            ! field 10: sea surface salinity
+       CALL iom_put ('qt_oc', zcmo(:,:,11) )           ! field 11: total flux at ocean surface
+       CALL iom_put ('qsr_oc', zcmo(:,:,12) )          ! field 12: solar flux at ocean surface
+       CALL iom_put ('qns_oc', zcmo(:,:,13) )          ! field 13: non-solar flux at ocean surface
+       !CALL iom_put ('hfbri', fhbri )                  ! field 14: heat flux due to brine release
+       CALL iom_put ('qsr_io', zcmo(:,:,17) )          ! field 17: solar flux at ice/ocean surface
+       CALL iom_put ('qns_io', zcmo(:,:,18) )          ! field 18: non-solar flux at ice/ocean surface
+       !CALL iom_put ('snowpre', zcmo(:,:,19) * 86400) ! field 19 :snow precip          
+       CALL iom_put ('micesalt', zcmo(:,:,20) )        ! field 20 :mean ice salinity
+       CALL iom_put ('miceage', zcmo(:,:,21) / 365)    ! field 21: mean ice age
+       CALL iom_put ('icelapr',zcmo(:,:,22) )   ! field 22: daily lateral thermo ice prod.
+       CALL iom_put ('icesipr',zcmo(:,:,23) )   ! field 23: daily snowice ice prod.
+       CALL iom_put ('micet', zcmo(:,:,24) )           ! field 24: mean ice temperature
+       CALL iom_put ('icehc', zcmo(:,:,25) )           ! field 25: ice total heat content
+       CALL iom_put ('isnowhc', zcmo(:,:,26) )         ! field 26: snow total heat content
+       CALL iom_put ('icest', zcmo(:,:,27) )           ! field 27: ice surface temperature
+       CALL iom_put ('fsbri', zcmo(:,:,28) * 86400 )           ! field 28: brine salt flux
+       CALL iom_put ('fseqv', zcmo(:,:,29) * 86400 )           ! field 29: equivalent FW salt flux
+       CALL iom_put ('ibrinv', zcmo(:,:,30) *100 )     ! field 30: brine volume
+       CALL iom_put ('icecolf', zcmo(:,:,31) )         ! field 31: frazil ice collection thickness
+       CALL iom_put ('icestr', zcmo(:,:,32) * 0.001 )  ! field 32: ice strength
+       CALL iom_put ('icevel', zcmo(:,:,33) )          ! field 33: ice velocity
+       CALL iom_put ('isume', zcmo(:,:,34) )    ! field 34: surface melt
+       CALL iom_put ('ibome', zcmo(:,:,35) )     ! field 35: bottom melt
+       CALL iom_put ('idive', zcmo(:,:,36) * 1.0e8)    ! field 36: divergence
+       CALL iom_put ('ishear', zcmo(:,:,37) * 1.0e8 )  ! field 37: shear
+       CALL iom_put ('icerepr', zcmo(:,:,38) ) ! field 38: daily prod./melting due to limupdate
+       CALL iom_put ('icevolu', zcmo(:,:,39) ) ! field 39: ice volume
+       CALL iom_put ('snowvol', zcmo(:,:,40) ) ! field 40: snow volume
+       CALL iom_put ('fsrpo', zcmo(:,:,41) * 86400 )           ! field 41: salt flux from ridging rafting
+       CALL iom_put ('fsres', zcmo(:,:,42) * 86400 )           ! field 42: salt flux from limupdate (resultant)
+       CALL iom_put ('icetrp', zcmo(:,:,43) )    ! field 43: ice volume transport
+
       !-----------------------------
       ! Thickness distribution file
@@ -302,6 +362,6 @@
             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
+                  zinda = MAX( zzero , SIGN( zone , a_i(ji,jj,jl) - epsi06 ) )
+                  zoi(ji,jj,jl) = oa_i(ji,jj,jl)  / MAX( a_i(ji,jj,jl) , epsi06 ) * zinda
                END DO
             END DO
@@ -314,7 +374,7 @@
                DO jj = 1, jpj
                   DO ji = 1, jpi
-                     zinda = MAX( zzero , SIGN( zone , a_i(ji,jj,jl) - 1.0e-6 ) )
+                     zinda = MAX( zzero , SIGN( zone , a_i(ji,jj,jl) - epsi06 ) )
                      zei(ji,jj,jl) = zei(ji,jj,jl) + 100.0* &
-                        ( - tmut * s_i(ji,jj,jk,jl) / MIN( ( t_i(ji,jj,jk,jl) - rtt ), -1.0e-6 ) ) * &
+                        ( - tmut * s_i(ji,jj,jk,jl) / MIN( ( t_i(ji,jj,jk,jl) - rtt ), - epsi06 ) ) * &
                         zinda / nlay_i
                   END DO
@@ -348,4 +408,6 @@
       CALL wrk_dealloc( jpi, jpj, jpnoumax, zcmo, zcmoa )
       CALL wrk_dealloc( jpi, jpj, jpl, zmaskitd, zoi, zei )
+
+      IF( nn_timing == 1 )  CALL timing_stop('limwri')
       
    END SUBROUTINE lim_wri
@@ -381,5 +443,5 @@
          field_25, field_26, field_27, field_28, field_29, field_30,   &
          field_31, field_32, field_33, field_34, field_35, field_36,   &
-         field_37
+         field_37, field_38, field_39, field_40, field_41, field_42, field_43
 
       TYPE(FIELD) , DIMENSION(jpnoumax) :: zfield
@@ -392,5 +454,5 @@
          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
+         field_37, field_38, field_39, field_40, field_41, field_42, field_43, add_diag_swi
       !!-------------------------------------------------------------------
 
@@ -435,4 +497,10 @@
       zfield(36) = field_36
       zfield(37) = field_37
+      zfield(38) = field_38
+      zfield(39) = field_39
+      zfield(40) = field_40
+      zfield(41) = field_41
+      zfield(42) = field_42
+      zfield(43) = field_43
 
       DO nf = 1, noumef
@@ -460,4 +528,63 @@
       !
    END SUBROUTINE lim_wri_init
+ 
+   SUBROUTINE lim_wri_state( kt, kid, kh_i )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE lim_wri_state  ***
+      !!        
+      !! ** Purpose :   create a NetCDF file named cdfile_name which contains 
+      !!      the instantaneous ice state and forcing fields for ice model
+      !!        Used to find errors in the initial state or save the last
+      !!      ocean state in case of abnormal end of a simulation
+      !!
+      !! History :
+      !!   4.1  !  2013-06  (C. Rousset)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt               ! ocean time-step index)
+      INTEGER, INTENT( in ) ::   kid , kh_i       
+      !!----------------------------------------------------------------------
+      !CALL histvert( kid, "icethi", "L levels","m", jpl , hi_mean , nz )
+
+      CALL histdef( kid, "iicethic", "Ice thickness"           , "m"      , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "iiceconc", "Ice concentration"       , "%"      , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "iicetemp", "Ice temperature"         , "C"      , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "iicevelu", "i-Ice speed (I-point)"   , "m/s"    , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "iicevelv", "j-Ice speed (I-point)"   , "m/s"    , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "iicestru", "i-Wind stress over ice (I-pt)", "Pa", jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "iicestrv", "j-Wind stress over ice (I-pt)", "Pa", jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "iicesflx", "Solar flux over ocean"     , "w/m2"   , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "iicenflx", "Non-solar flux over ocean" , "w/m2"   , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "isnowpre", "Snow precipitation"      , "kg/m2/s", jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "iicesali", "Ice salinity"            , "PSU"    , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "iicevolu", "Ice volume"              , "m"      , jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "iicedive", "Ice divergence"          , "10-8s-1", jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+
+      !CALL histdef( kid, "iice_itd", "Ice concentration by cat", "%"      , jpi, jpj, kh_i, jpl, 1, jpl, -99, 32, "inst(x)", rdt, rdt ) 
+      !CALL histdef( kid, "iice_hid", "Ice thickness by cat"    , "m"      , jpi, jpj, kh_i, jpl, 1, jpl, -99, 32, "inst(x)", rdt, rdt ) 
+      !CALL histdef( kid, "iice_hsd", "Snow thickness by cat"   , "m"      , jpi, jpj, kh_i, jpl, 1, jpl, -99, 32, "inst(x)", rdt, rdt ) 
+      !CALL histdef( kid, "iice_std", "Ice salinity by cat"     , "PSU"    , jpi, jpj, kh_i, jpl, 1, jpl, -99, 32, "inst(x)", rdt, rdt ) 
+
+      CALL histend( kid, snc4set )   ! end of the file definition
+
+      CALL histwrite( kid, "iicethic", kt, icethi        , jpi*jpj, (/1/) )    
+      CALL histwrite( kid, "iiceconc", kt, at_i          , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "iicetemp", kt, tm_i - rtt    , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "iicevelu", kt, u_ice          , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "iicevelv", kt, v_ice          , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "iicestru", kt, utau_ice       , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "iicestrv", kt, vtau_ice       , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "iicesflx", kt, qsr , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "iicenflx", kt, qns , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "isnowpre", kt, sprecip        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "iicesali", kt, smt_i          , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "iicevolu", kt, vt_i           , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "iicedive", kt, divu_i*1.0e8   , jpi*jpj, (/1/) )
+
+      !CALL histwrite( kid, "iice_itd", kt, a_i  , jpi*jpj*jpl, (/1/)  )   ! area
+      !CALL histwrite( kid, "iice_hid", kt, ht_i , jpi*jpj*jpl, (/1/)  )   ! thickness
+      !CALL histwrite( kid, "iice_hsd", kt, ht_s , jpi*jpj*jpl, (/1/)  )   ! snow depth
+      !CALL histwrite( kid, "iice_std", kt, sm_i , jpi*jpj*jpl, (/1/)  )   ! salinity
+
+    END SUBROUTINE lim_wri_state
 
 #else
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limwri_dimg.h90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limwri_dimg.h90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limwri_dimg.h90	(revision 3938)
@@ -111,5 +111,5 @@
          zcmo(ji,jj,13) = qns(ji,jj)
          ! See thersf for the coefficient
-         zcmo(ji,jj,14) = - emps(ji,jj) * rday * ( sss_m(ji,jj) + epsi16 ) / soce
+         zcmo(ji,jj,14) = - emps(ji,jj) * rday     ! converted in Kg/m2/day = mm/day
          zcmo(ji,jj,15) = utau_ice(ji,jj)
          zcmo(ji,jj,16) = vtau_ice(ji,jj)
@@ -154,5 +154,5 @@
                rcmoy(ji,jj,13) = qns(ji,jj)
                ! See thersf for the coefficient
-               rcmoy(ji,jj,14) = - emps(ji,jj) * rday * ( sss_m(ji,jj) + epsi16 ) / soce
+               rcmoy(ji,jj,14) = - emps(ji,jj) * rday     ! converted in Kg/m2/day = mm/day
                rcmoy(ji,jj,15) = utau_ice(ji,jj)
                rcmoy(ji,jj,16) = vtau_ice(ji,jj)
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90	(revision 3938)
@@ -22,5 +22,4 @@
    REAL(wp), PUBLIC ::   hicmin  = 0.2       !: (REMOVE)
    REAL(wp), PUBLIC ::   hiclim  = 0.05      !: minimum ice thickness
-   REAL(wp), PUBLIC ::   amax    = 0.999     !: maximum lead fraction
    REAL(wp), PUBLIC ::   sbeta   = 1.0       !: numerical scheme for diffusion in ice  (REMOVE)
    REAL(wp), PUBLIC ::   parlat  = 0.0       !: (REMOVE)
@@ -83,5 +82,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   i0            !: fraction of radiation transmitted to the ice
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   old_ht_i_b    !: Ice thickness at the beginnning of the time step [m]
-    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::  old_ht_s_b    !: Snow thickness at the beginning of the time step [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   old_ht_s_b    !: Snow thickness at the beginning of the time step [m]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fsbri_1d      !: Salt flux due to brine drainage
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fhbri_1d      !: Heat flux due to brine drainage
@@ -108,4 +107,7 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   o_i_b       !: Ice age                        [days]
 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   iatte_1d   !: clem attenuation coef of the input solar flux (unitless)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   oatte_1d   !: clem attenuation coef of the input solar flux (unitless)
+
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_s_b   !: corresponding to the 2D var  t_s
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_i_b   !: corresponding to the 2D var  t_i
@@ -157,5 +159,6 @@
          &      fltbif_1d(jpij) , fscbq_1d (jpij) , qsr_ice_1d (jpij) ,     &
          &      fr1_i0_1d(jpij) , fr2_i0_1d(jpij) , qnsr_ice_1d(jpij) ,     &
-         &      qfvbq_1d (jpij) , t_bo_b   (jpij)                     , STAT=ierr(1) )
+         &      qfvbq_1d (jpij) , t_bo_b   (jpij) , iatte_1d   (jpij) ,     &
+         &      oatte_1d (jpij)                                       , STAT=ierr(1) )
       !
       ALLOCATE( sprecip_1d (jpij) , frld_1d    (jpij) , at_i_b     (jpij) ,     &
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 3938)
@@ -8,4 +8,5 @@
    !!            3.3  !  2010-09  (D. Storkey) add ice boundary conditions
    !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
+   !!             -   !  2012-01  (C. Rousset) add ice boundary conditions for lim3
    !!----------------------------------------------------------------------
 #if defined key_bdy 
@@ -44,4 +45,8 @@
       REAL, POINTER, DIMENSION(:)     ::  hicif
       REAL, POINTER, DIMENSION(:)     ::  hsnif
+#elif defined key_lim3
+      REAL, POINTER, DIMENSION(:,:)   ::  a_i   !: now ice leads fraction climatology
+      REAL, POINTER, DIMENSION(:,:)   ::  ht_i  !: Now ice  thickness climatology
+      REAL, POINTER, DIMENSION(:,:)   ::  ht_s  !: now snow thickness
 #endif
    END TYPE OBC_DATA
@@ -73,7 +78,7 @@
    INTEGER, DIMENSION(jp_bdy) ::   nn_tra_dta      	    !: = 0 use the initial state as bdy dta ; 
                                                             !: = 1 read it in a NetCDF file
-#if defined key_lim2
-   INTEGER, DIMENSION(jp_bdy) ::   nn_ice_lim2              ! Choice of boundary condition for sea ice variables 
-   INTEGER, DIMENSION(jp_bdy) ::   nn_ice_lim2_dta          !: = 0 use the initial state as bdy dta ; 
+#if ( defined key_lim2 || defined key_lim3 )
+   INTEGER, DIMENSION(jp_bdy) ::   nn_ice_lim               ! Choice of boundary condition for sea ice variables 
+   INTEGER, DIMENSION(jp_bdy) ::   nn_ice_lim_dta           !: = 0 use the initial state as bdy dta ; 
                                                             !: = 1 read it in a NetCDF file
 #endif
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 3938)
@@ -11,4 +11,5 @@
    !!            3.3  !  2010-09  (D.Storkey) add ice boundary conditions
    !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
+   !!             -   !  2012-01  (C. Rousset) add ice boundary conditions for lim3
    !!----------------------------------------------------------------------
 #if defined key_bdy
@@ -31,4 +32,8 @@
 #if defined key_lim2
    USE ice_2
+#elif defined key_lim3
+   USE par_ice
+   USE ice
+   USE limcat_1D          ! redistribute ice input into categories
 #endif
 
@@ -48,4 +53,9 @@
 
    TYPE(MAP_POINTER), ALLOCATABLE, DIMENSION(:) :: nbmap_ptr   ! array of pointers to nbmap
+
+#if defined key_lim3
+   LOGICAL :: ll_bdylim3                  ! determine whether ice input is lim2 (F) or lim3 (T) type
+   INTEGER :: jfld_hti, jfld_hts, jfld_ai ! indices of ice thickness, snow thickness and concentration in bf structure
+#endif
 
 #  include "domzgr_substitute.h90"
@@ -76,5 +86,5 @@
                                                         ! etc.
       !!
-      INTEGER     ::  ib_bdy, jfld, jstart, jend, ib, ii, ij, ik, igrd  ! local indices
+      INTEGER     ::  ib_bdy, jfld, jstart, jend, ib, ii, ij, ik, igrd, jl  ! local indices
       INTEGER,          DIMENSION(jpbgrd) ::   ilen1 
       INTEGER, POINTER, DIMENSION(:)      ::   nblen, nblenrim  ! short cuts
@@ -175,6 +185,6 @@
 
 #if defined key_lim2
-            IF( nn_ice_lim2(ib_bdy) .gt. 0 .and. nn_ice_lim2_dta(ib_bdy) .eq. 0 ) THEN 
-               IF( nn_ice_lim2(ib_bdy) .eq. jp_frs ) THEN
+            IF( nn_ice_lim(ib_bdy) .gt. 0 .and. nn_ice_lim_dta(ib_bdy) .eq. 0 ) THEN 
+               IF( nn_ice_lim(ib_bdy) .eq. jp_frs ) THEN
                   ilen1(:) = nblen(:)
                ELSE
@@ -185,8 +195,26 @@
                   ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
                   ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                  dta_bdy(ib_bdy)%frld(ib) = frld(ii,ij) * tmask(ii,ij,1)         
+                  dta_bdy(ib_bdy)%frld (ib) =  frld(ii,ij) * tmask(ii,ij,1)         
                   dta_bdy(ib_bdy)%hicif(ib) = hicif(ii,ij) * tmask(ii,ij,1)         
                   dta_bdy(ib_bdy)%hsnif(ib) = hsnif(ii,ij) * tmask(ii,ij,1)         
                END DO 
+            ENDIF
+#elif defined key_lim3
+            IF( nn_ice_lim(ib_bdy) .gt. 0 .and. nn_ice_lim_dta(ib_bdy) .eq. 0 ) THEN 
+               IF( nn_ice_lim(ib_bdy) .eq. jp_frs ) THEN
+                  ilen1(:) = nblen(:)
+               ELSE
+                  ilen1(:) = nblenrim(:)
+               ENDIF
+               igrd = 1                       ! Everything is at T-points here
+               DO jl = 1, jpl
+                  DO ib = 1, ilen1(igrd)
+                     ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                     ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                     dta_bdy(ib_bdy)%a_i (ib,jl) =  a_i(ii,ij,jl) * tmask(ii,ij,1) 
+                     dta_bdy(ib_bdy)%ht_i(ib,jl) = ht_i(ii,ij,jl) * tmask(ii,ij,1) 
+                     dta_bdy(ib_bdy)%ht_s(ib,jl) = ht_s(ii,ij,jl) * tmask(ii,ij,1) 
+                  END DO
+               END DO
             ENDIF
 #endif
@@ -237,4 +265,14 @@
                   CALL tide_update( kt=kt, idx=idx_bdy(ib_bdy), dta=dta_bdy(ib_bdy), td=tides(ib_bdy), time_offset=time_offset )
                ENDIF
+
+#if defined key_lim3
+               IF( nn_ice_lim(ib_bdy) .gt. 0 .and. nn_ice_lim_dta(ib_bdy) .eq. 1 ) THEN ! bdy ice input
+     	          IF ( .NOT. ll_bdylim3 ) THEN ! case input is lim2 type
+     	             CALL lim_cat_1D ( bf(jfld_hti)%fnow(:,1,1), bf(jfld_hts)%fnow(:,1,1), bf(jfld_ai)%fnow(:,1,1), &
+                                     & dta_bdy(ib_bdy)%ht_i,     dta_bdy(ib_bdy)%ht_s,     dta_bdy(ib_bdy)%a_i     )
+     	          ENDIF
+               ENDIF
+#endif
+
             ENDIF
             jstart = jend+1
@@ -311,13 +349,22 @@
       INTEGER, ALLOCATABLE, DIMENSION(:)     ::   igrid         ! index for grid type (1,2,3 = T,U,V)
       INTEGER, POINTER, DIMENSION(:)         ::   nblen, nblenrim  ! short cuts
+#if defined key_lim3
+      INTEGER, DIMENSION(3) ::   zdimsz   ! number of elements in each of the 4 dimensions (i.e. i,j,t,ice-cat) for an array
+      INTEGER               ::   zndims   ! number of dimensions in an array (i.e. 3 = wo ice cat; 4 = w ice cat)
+      INTEGER               ::   inum,id1 ! local integer
+#endif
       TYPE(FLD_N), ALLOCATABLE, DIMENSION(:) ::   blf_i         !  array of namelist information structures
       TYPE(FLD_N) ::   bn_tem, bn_sal, bn_u3d, bn_v3d   ! 
       TYPE(FLD_N) ::   bn_ssh, bn_u2d, bn_v2d           ! informations about the fields to be read
 #if defined key_lim2
-      TYPE(FLD_N) ::   bn_frld, bn_hicif, bn_hsnif      !
+      TYPE(FLD_N) ::   bn_frld, bn_hicif, bn_hsnif      
+#elif defined key_lim3
+      TYPE(FLD_N) ::   bn_a_i, bn_ht_i, bn_ht_s      
 #endif
       NAMELIST/nambdy_dta/ cn_dir, bn_tem, bn_sal, bn_u3d, bn_v3d, bn_ssh, bn_u2d, bn_v2d 
 #if defined key_lim2
       NAMELIST/nambdy_dta/ bn_frld, bn_hicif, bn_hsnif
+#elif defined key_lim3
+      NAMELIST/nambdy_dta/ bn_a_i, bn_ht_i, bn_ht_s
 #endif
       NAMELIST/nambdy_dta/ ln_full_vel
@@ -326,11 +373,11 @@
       IF( nn_timing == 1 ) CALL timing_start('bdy_dta_init')
 
-      ! Set nn_dta
+      ! Set nn_dta to 0 or 1
       DO ib_bdy = 1, nb_bdy
-         nn_dta(ib_bdy) = MAX(  nn_dyn2d_dta(ib_bdy)       &
-                               ,nn_dyn3d_dta(ib_bdy)       &
-                               ,nn_tra_dta(ib_bdy)         &
-#if defined key_lim2
-                               ,nn_ice_lim2_dta(ib_bdy)    &
+         nn_dta(ib_bdy) = MAX( nn_dyn2d_dta(ib_bdy)       &
+                              ,nn_dyn3d_dta(ib_bdy)       &
+                              ,nn_tra_dta(ib_bdy)         &
+#if ( defined key_lim2 || defined key_lim3 )
+                              ,nn_ice_lim_dta(ib_bdy)    &
 #endif
                               )
@@ -352,6 +399,6 @@
             nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 2
          ENDIF
-#if defined key_lim2
-         IF( nn_ice_lim2(ib_bdy) .gt. 0 .and. nn_ice_lim2_dta(ib_bdy) .eq. 1  ) THEN
+#if ( defined key_lim2 || defined key_lim3 )
+         IF( nn_ice_lim(ib_bdy) .gt. 0 .and. nn_ice_lim_dta(ib_bdy) .eq. 1  ) THEN
             nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 3
          ENDIF
@@ -377,5 +424,5 @@
       ALLOCATE( igrid(nb_bdy_fld_sum) ) 
 
-      ! Read namelists
+     ! Read namelists
       ! --------------
       REWIND(numnam)
@@ -387,17 +434,21 @@
             ln_full_vel = .false.
             ! ... default values (NB: frequency positive => hours, negative => months)
-            !                    !  file       ! frequency !  variable   ! time intep !  clim   ! 'yearly' or ! weights  ! rotation  !
-            !                    !  name       ! hours !   name     !  (T/F)  !  (T/F)  !  'monthly'  ! filename ! pairs     !
-            bn_ssh     = FLD_N(  'bdy_ssh'     ,  24   , 'sossheig' , .false. , .false. ,   'yearly'  , ''       , ''        )
-            bn_u2d     = FLD_N(  'bdy_vel2d_u' ,  24   , 'vobtcrtx' , .false. , .false. ,   'yearly'  , ''       , ''        )
-            bn_v2d     = FLD_N(  'bdy_vel2d_v' ,  24   , 'vobtcrty' , .false. , .false. ,   'yearly'  , ''       , ''        )
-            bn_u3d     = FLD_N(  'bdy_vel3d_u' ,  24   , 'vozocrtx' , .false. , .false. ,   'yearly'  , ''       , ''        )
-            bn_v3d     = FLD_N(  'bdy_vel3d_v' ,  24   , 'vomecrty' , .false. , .false. ,   'yearly'  , ''       , ''        )
-            bn_tem     = FLD_N(  'bdy_tem'     ,  24   , 'votemper' , .false. , .false. ,   'yearly'  , ''       , ''        )
-            bn_sal     = FLD_N(  'bdy_sal'     ,  24   , 'vosaline' , .false. , .false. ,   'yearly'  , ''       , ''        )
+            !                 !  file       ! frequency !  variable  ! time intep !  clim   ! 'yearly' or ! weights  ! rotation  !
+            !                 !  name       ! hours     !   name     !  (T/F)     !  (T/F)  !  'monthly'  ! filename ! pairs     !
+            bn_ssh   = FLD_N(  'bdy_ssh'     ,  24      , 'sossheig' , .false.    , .false. ,   'yearly'  , ''       , ''        )
+            bn_u2d   = FLD_N(  'bdy_vel2d_u' ,  24      , 'vobtcrtx' , .false.    , .false. ,   'yearly'  , ''       , ''        )
+            bn_v2d   = FLD_N(  'bdy_vel2d_v' ,  24      , 'vobtcrty' , .false.    , .false. ,   'yearly'  , ''       , ''        )
+            bn_u3d   = FLD_N(  'bdy_vel3d_u' ,  24      , 'vozocrtx' , .false.    , .false. ,   'yearly'  , ''       , ''        )
+            bn_v3d   = FLD_N(  'bdy_vel3d_v' ,  24      , 'vomecrty' , .false.    , .false. ,   'yearly'  , ''       , ''        )
+            bn_tem   = FLD_N(  'bdy_tem'     ,  24      , 'votemper' , .false.    , .false. ,   'yearly'  , ''       , ''        )
+            bn_sal   = FLD_N(  'bdy_sal'     ,  24      , 'vosaline' , .false.    , .false. ,   'yearly'  , ''       , ''        )
 #if defined key_lim2
-            bn_frld    = FLD_N(  'bdy_frld'    ,  24   , 'ildsconc' , .false. , .false. ,   'yearly'  , ''       , ''        )
-            bn_hicif   = FLD_N(  'bdy_hicif'   ,  24   , 'iicethic' , .false. , .false. ,   'yearly'  , ''       , ''        )
-            bn_hsnif   = FLD_N(  'bdy_hsnif'   ,  24   , 'isnothic' , .false. , .false. ,   'yearly'  , ''       , ''        )
+            bn_frld  = FLD_N(  'bdy_frld'    ,  24      , 'ildsconc' , .false.    , .false. ,   'yearly'  , ''       , ''        )
+            bn_hicif = FLD_N(  'bdy_hicif'   ,  24      , 'iicethic' , .false.    , .false. ,   'yearly'  , ''       , ''        )
+            bn_hsnif = FLD_N(  'bdy_hsnif'   ,  24      , 'isnothic' , .false.    , .false. ,   'yearly'  , ''       , ''        )
+#elif defined key_lim3
+            bn_a_i  = FLD_N(  'bdy_a_i'     ,  24   , 'ileadfra' , .false. , .false. ,   'yearly'  , ''       , ''        )
+            bn_ht_i = FLD_N(  'bdy_ht_i'    ,  24   , 'iicethic' , .false. , .false. ,   'yearly'  , ''       , ''        )
+            bn_ht_s = FLD_N(  'bdy_ht_s'    ,  24   , 'isnowthi' , .false. , .false. ,   'yearly'  , ''       , ''        )
 #endif
 
@@ -515,5 +566,5 @@
 #if defined key_lim2
             ! sea ice
-            IF( nn_ice_lim2(ib_bdy) .gt. 0 .and. nn_ice_lim2_dta(ib_bdy) .eq. 1 ) THEN
+            IF( nn_ice_lim(ib_bdy) .gt. 0 .and. nn_ice_lim_dta(ib_bdy) .eq. 1 ) THEN
 
                jfld = jfld + 1
@@ -521,5 +572,5 @@
                ibdy(jfld) = ib_bdy
                igrid(jfld) = 1
-               IF( nn_ice_lim2(ib_bdy) .eq. jp_frs ) THEN
+               IF( nn_ice_lim(ib_bdy) .eq. jp_frs ) THEN
                   ilen1(jfld) = nblen(igrid(jfld))
                ELSE
@@ -532,5 +583,5 @@
                ibdy(jfld) = ib_bdy
                igrid(jfld) = 1
-               IF( nn_ice_lim2(ib_bdy) .eq. jp_frs ) THEN
+               IF( nn_ice_lim(ib_bdy) .eq. jp_frs ) THEN
                   ilen1(jfld) = nblen(igrid(jfld))
                ELSE
@@ -543,5 +594,5 @@
                ibdy(jfld) = ib_bdy
                igrid(jfld) = 1
-               IF( nn_ice_lim2(ib_bdy) .eq. jp_frs ) THEN
+               IF( nn_ice_lim(ib_bdy) .eq. jp_frs ) THEN
                   ilen1(jfld) = nblen(igrid(jfld))
                ELSE
@@ -549,4 +600,56 @@
                ENDIF
                ilen3(jfld) = 1
+
+            ENDIF
+#elif defined key_lim3
+            ! sea ice
+            IF( nn_ice_lim(ib_bdy) .gt. 0 .and. nn_ice_lim_dta(ib_bdy) .eq. 1 ) THEN
+
+               ! Test for types of ice input (lim2 or lim3) 
+               CALL iom_open ( bn_a_i%clname, inum )
+               id1 = iom_varid ( inum, bn_a_i%clvar, kdimsz=zdimsz, kndims=zndims, ldstop = .FALSE. )
+               CALL iom_close ( inum )
+               !CALL fld_clopn ( bn_a_i, nyear, nmonth, nday, ldstop=.TRUE. )
+               !CALL iom_open ( bn_a_i%clname, inum )
+               !id1 = iom_varid ( bn_a_i%num, bn_a_i%clvar, kdimsz=zdimsz, kndims=zndims, ldstop = .FALSE. )
+      	       IF ( zndims == 4 ) THEN
+                 ll_bdylim3 = .TRUE.
+               ELSE
+                 ll_bdylim3 = .FALSE.        
+               ENDIF
+               ! End test
+
+               jfld = jfld + 1
+               blf_i(jfld) = bn_a_i
+               ibdy(jfld) = ib_bdy
+               igrid(jfld) = 1
+               IF( nn_ice_lim(ib_bdy) .eq. jp_frs ) THEN
+                  ilen1(jfld) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(jfld) = nblenrim(igrid(jfld))
+               ENDIF
+               IF ( ll_bdylim3 ) THEN ; ilen3(jfld)=jpl ; ELSE ; ilen3(jfld)=1 ; ENDIF
+
+               jfld = jfld + 1
+               blf_i(jfld) = bn_ht_i
+               ibdy(jfld) = ib_bdy
+               igrid(jfld) = 1
+               IF( nn_ice_lim(ib_bdy) .eq. jp_frs ) THEN
+                  ilen1(jfld) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(jfld) = nblenrim(igrid(jfld))
+               ENDIF
+               IF ( ll_bdylim3 ) THEN ; ilen3(jfld)=jpl ; ELSE ; ilen3(jfld)=1 ; ENDIF
+
+               jfld = jfld + 1
+               blf_i(jfld) = bn_ht_s
+               ibdy(jfld) = ib_bdy
+               igrid(jfld) = 1
+               IF( nn_ice_lim(ib_bdy) .eq. jp_frs ) THEN
+                  ilen1(jfld) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(jfld) = nblenrim(igrid(jfld))
+               ENDIF
+               IF ( ll_bdylim3 ) THEN ; ilen3(jfld)=jpl ; ELSE ; ilen3(jfld)=1 ; ENDIF
 
             ENDIF
@@ -652,7 +755,7 @@
 
 #if defined key_lim2
-         IF (nn_ice_lim2(ib_bdy) .gt. 0) THEN
-            IF( nn_ice_lim2_dta(ib_bdy) .eq. 0 ) THEN
-               IF( nn_ice_lim2(ib_bdy) .eq. jp_frs ) THEN
+         IF (nn_ice_lim(ib_bdy) .gt. 0) THEN
+            IF( nn_ice_lim_dta(ib_bdy) .eq. 0 ) THEN
+               IF( nn_ice_lim(ib_bdy) .eq. jp_frs ) THEN
                   ilen0(1:3) = nblen(1:3)
                ELSE
@@ -669,4 +772,40 @@
                jfld = jfld + 1
                dta_bdy(ib_bdy)%hsnif => bf(jfld)%fnow(:,1,1)
+            ENDIF
+         ENDIF
+#elif defined key_lim3
+         IF (nn_ice_lim(ib_bdy) .gt. 0) THEN
+            IF( nn_ice_lim(ib_bdy) .eq. jp_frs ) THEN
+               ilen0(1:3) = nblen(1:3)
+            ELSE
+               ilen0(1:3) = nblenrim(1:3)
+            ENDIF
+            IF( nn_ice_lim_dta(ib_bdy) .eq. 0 ) THEN
+               ALLOCATE( dta_bdy(ib_bdy)%a_i (ilen0(1),jpl) )
+               ALLOCATE( dta_bdy(ib_bdy)%ht_i(ilen0(1),jpl) )
+               ALLOCATE( dta_bdy(ib_bdy)%ht_s(ilen0(1),jpl) )
+            ELSE
+               IF ( ll_bdylim3 ) THEN
+                  jfld = jfld + 1
+                  dta_bdy(ib_bdy)%a_i  => bf(jfld)%fnow(:,1,:)
+                  jfld = jfld + 1
+                  dta_bdy(ib_bdy)%ht_i => bf(jfld)%fnow(:,1,:)
+                  jfld = jfld + 1
+                  dta_bdy(ib_bdy)%ht_s => bf(jfld)%fnow(:,1,:)
+               ELSE
+                  jfld    = jfld + 1                  
+                  jfld_ai = jfld
+                  ALLOCATE( dta_bdy(ib_bdy)%a_i (ilen0(1),jpl) )
+                  dta_bdy(ib_bdy)%a_i(:,:) = 0.0
+                  jfld     = jfld + 1                  
+                  jfld_hti = jfld
+                  ALLOCATE( dta_bdy(ib_bdy)%ht_i(ilen0(1),jpl) )
+                  dta_bdy(ib_bdy)%ht_i(:,:) = 0.0
+                  jfld     = jfld + 1                  
+                  jfld_hts = jfld
+                  ALLOCATE( dta_bdy(ib_bdy)%ht_s(ilen0(1),jpl) )
+                  dta_bdy(ib_bdy)%ht_s(:,:) = 0.0
+               ENDIF
+
             ENDIF
          ENDIF
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90	(revision 3938)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90	(revision 3938)
@@ -0,0 +1,306 @@
+MODULE bdyice_lim
+   !!======================================================================
+   !!                       ***  MODULE  bdyice_lim  ***
+   !! Unstructured Open Boundary Cond. :  Open boundary conditions for sea-ice (LIM2 and LIM3)
+   !!======================================================================
+   !!  History :  3.3  !  2010-09 (D. Storkey)  Original code
+   !!             3.4  !  2011    (D. Storkey)  rewrite in preparation for OBC-BDY merge
+   !!              -   !  2012-01 (C. Rousset)  add lim3 and remove useless jk loop 
+   !!----------------------------------------------------------------------
+#if defined   key_bdy   &&  ( defined key_lim2 || defined key_lim3 )
+   !!----------------------------------------------------------------------
+   !!   'key_bdy'            and                 Unstructured Open Boundary Conditions
+   !!   'key_lim2'                                                 LIM-2 sea ice model
+   !!   'key_lim3'                                                 LIM-3 sea ice model
+   !!----------------------------------------------------------------------
+   !!   bdy_ice_lim        : Application of open boundaries to ice
+   !!   bdy_ice_frs        : Application of Flow Relaxation Scheme
+   !!----------------------------------------------------------------------
+   USE timing          ! Timing
+   USE phycst          ! physical constant
+   USE eosbn2          ! equation of state
+   USE oce             ! ocean dynamics and tracers variables
+#if defined key_lim2
+   USE par_ice_2
+   USE ice_2           ! LIM_2 ice variables
+#elif defined key_lim3
+   USE par_ice
+   USE ice             ! LIM_3 ice variables
+#endif 
+   USE par_oce         ! ocean parameters
+   USE dom_oce         ! ocean space and time domain variables 
+   USE dom_ice          ! sea-ice domain
+   USE sbc_oce         ! Surface boundary condition: ocean fields
+   USE bdy_oce         ! ocean open boundary conditions
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! write to numout file
+   USE lib_mpp         ! distributed memory computing
+   USE lib_fortran     ! to use key_nosignedzero
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   bdy_ice_lim    ! routine called in sbcmod
+
+   REAL(wp) ::   epsi20 = 1.e-20_wp  ! module constants
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: bdyice.F90 2715 2011-03-30 15:58:35Z rblod $
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE bdy_ice_lim( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  SUBROUTINE bdy_ice_lim  ***
+      !!
+      !! ** Purpose : - Apply open boundary conditions for ice (LIM2 and LIM3)
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) :: kt     ! Main time step counter
+      !!
+      INTEGER               :: ib_bdy ! Loop index
+      DO ib_bdy=1, nb_bdy
+
+         SELECT CASE( nn_ice_lim(ib_bdy) )
+         CASE(jp_none)
+            CYCLE
+         CASE(jp_frs)
+            CALL bdy_ice_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
+         CASE DEFAULT
+            CALL ctl_stop( 'bdy_ice_lim : unrecognised option for open boundaries for ice fields' )
+         END SELECT
+      ENDDO
+
+   END SUBROUTINE bdy_ice_lim
+
+   SUBROUTINE bdy_ice_frs( idx, dta, kt )
+      !!------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_ice_frs  ***
+      !!                    
+      !! ** Purpose : Apply the Flow Relaxation Scheme for sea-ice fields in the case 
+      !!              of unstructured open boundaries.
+      !! 
+      !! Reference : Engedahl H., 1995: Use of the flow relaxation scheme in a three-
+      !!             dimensional baroclinic ocean model with realistic topography. Tellus, 365-382.
+      !!------------------------------------------------------------------------------
+      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
+      INTEGER, INTENT( in )       ::   kt   ! main time-step counter
+      !!
+      INTEGER  ::   jb, jk, jgrd, jl   ! dummy loop indices
+      INTEGER  ::   ji, jj             ! local scalar
+      REAL(wp) ::   zwgt, zwgt1        ! local scalar
+      REAL(wp) ::   zinda, ztmelts
+      REAL(wp), DIMENSION(2,2) :: zindaa
+      !!------------------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('bdy_ice_frs')
+      !
+      !IF( kt /= nit000 ) THEN
+      jgrd = 1      ! Everything is at T-points here
+      !
+#if defined key_lim2
+      DO jb = 1, idx%nblen(jgrd)
+         ji    = idx%nbi(jb,jgrd)
+         jj    = idx%nbj(jb,jgrd)
+         zwgt  = idx%nbw(jb,jgrd)
+         zwgt1 = 1.e0 - idx%nbw(jb,jgrd)
+         frld (ji,jj) = ( frld (ji,jj) * zwgt1 + dta%frld (jb) * zwgt ) * tmask(ji,jj,1)     ! Leads fraction 
+         hicif(ji,jj) = ( hicif(ji,jj) * zwgt1 + dta%hicif(jb) * zwgt ) * tmask(ji,jj,1)     ! Ice depth 
+         hsnif(ji,jj) = ( hsnif(ji,jj) * zwgt1 + dta%hsnif(jb) * zwgt ) * tmask(ji,jj,1)     ! Snow depth
+
+         zinda = 1.0 - MAX( 0.0_wp , SIGN ( 1.0_wp , - frld(ji,jj) ) ) ! 0 if no ice
+         !------------------------------
+         ! Sea ice surface temperature
+         !------------------------------
+         sist(ji,jj)   = zinda * 270.0 + ( 1.0 - zinda ) * tfu(ji,jj)
+         !-----------------------------------------------
+         ! Ice/snow temperatures and energy stored in brines 
+         !-----------------------------------------------
+         !!! A CONTINUER !!!
+            zindhe = MAX( 0.e0, SIGN( 1.e0, fcor(1,jj) ) )              ! = 0 for SH, =1 for NH
+ 
+               ! Recover in situ values.
+               zindb         = MAX( rzero, SIGN( rone, zs0a(ji,jj) - epsi06 ) )
+               zacrith       = 1.0 - ( zindhe * acrit(1) + ( 1.0 - zindhe ) * acrit(2) )
+               zs0a (ji,jj)  = zindb * MIN( zs0a(ji,jj), zacrith )
+               hsnif(ji,jj)  = zindb * ( zs0sn(ji,jj) /MAX( zs0a(ji,jj), epsi16 ) )
+               hicif(ji,jj)  = zindb * ( zs0ice(ji,jj)/MAX( zs0a(ji,jj), epsi16 ) )
+               zindsn        = MAX( rzero, SIGN( rone, hsnif(ji,jj) - epsi06 ) )
+               zindic        = MAX( rzero, SIGN( rone, hicif(ji,jj) - epsi03 ) )
+               zindb         = MAX( zindsn, zindic )
+               zs0a (ji,jj)  = zindb * zs0a(ji,jj)
+               frld (ji,jj)  = 1.0 - zs0a(ji,jj)
+               hsnif(ji,jj)  = zindsn * hsnif(ji,jj)
+               hicif(ji,jj)  = zindic * hicif(ji,jj)
+               zusvosn       = 1.0/MAX( hsnif(ji,jj) * zs0a(ji,jj), epsi16 )
+               zusvoic       = 1.0/MAX( hicif(ji,jj) * zs0a(ji,jj), epsi16 )
+               zignm         = MAX( rzero,  SIGN( rone, hsndif - hsnif(ji,jj) ) )
+               zrtt          = 173.15 * rone 
+               ztsn          =          zignm   * tbif(ji,jj,1)  &
+                              + ( 1.0 - zignm ) * MIN( MAX( zrtt, rt0_snow * zusvosn * zs0c0(ji,jj)) , tfu(ji,jj) ) 
+               ztic1          = MIN( MAX( zrtt, rt0_ice * zusvoic * zs0c1(ji,jj) ) , tfu(ji,jj) )
+               ztic2          = MIN( MAX( zrtt, rt0_ice * zusvoic * zs0c2(ji,jj) ) , tfu(ji,jj) )
+ 
+               tbif(ji,jj,1) = zindsn * ztsn  + ( 1.0 - zindsn ) * tfu(ji,jj)               
+               tbif(ji,jj,2) = zindic * ztic1 + ( 1.0 - zindic ) * tfu(ji,jj)
+               tbif(ji,jj,3) = zindic * ztic2 + ( 1.0 - zindic ) * tfu(ji,jj)
+               qstoif(ji,jj) = zindb  * xlic * zs0st(ji,jj) /  MAX( zs0a(ji,jj), epsi16 )
+
+      END DO 
+
+      vt_i(:,:) = hicif(:,:) * frld(:,:)
+      vt_s(:,:) = hsnif(:,:) * frld(:,:)
+      
+      CALL lbc_lnk( frld,  'T', 1. )                                         ! lateral boundary conditions
+      CALL lbc_lnk( hicif, 'T', 1. )
+      CALL lbc_lnk( hsnif, 'T', 1. )
+      CALL lbc_lnk(  vt_i, 'T', 1. )
+      CALL lbc_lnk(  vt_s, 'T', 1. )
+      !
+#elif defined key_lim3
+
+     ! --------------------
+     ! ice velocity
+     ! --------------------
+     !DO jb = 1, idx%nblen(jgrd)
+     !   ji    = idx%nbi(jb,jgrd)
+     !   jj    = idx%nbj(jb,jgrd)
+     !   u_ice(ji,jj)=0.
+     !   v_ice(ji,jj)=0.
+     !END DO
+     !CALL lbc_lnk(u_ice(:,:),'U', -1. )                                         ! lateral boundary conditions
+     !CALL lbc_lnk(v_ice(:,:),'V', -1. )                                         ! lateral boundary conditions
+
+      DO jl = 1, jpl
+         DO jb = 1, idx%nblen(jgrd)
+            ji    = idx%nbi(jb,jgrd)
+            jj    = idx%nbj(jb,jgrd)
+            zwgt  = idx%nbw(jb,jgrd)
+            zwgt1 = 1.e0 - idx%nbw(jb,jgrd)
+            a_i (ji,jj,jl) = ( a_i (ji,jj,jl) * zwgt1 + dta%a_i (jb,jl) * zwgt ) * tmask(ji,jj,1)  ! Leads fraction 
+            ht_i(ji,jj,jl) = ( ht_i(ji,jj,jl) * zwgt1 + dta%ht_i(jb,jl) * zwgt ) * tmask(ji,jj,1)  ! Ice depth 
+            ht_s(ji,jj,jl) = ( ht_s(ji,jj,jl) * zwgt1 + dta%ht_s(jb,jl) * zwgt ) * tmask(ji,jj,1)  ! Snow depth
+
+            a_i (ji,jj+1,jl) = a_i (ji,jj,jl) * tmask(ji,jj+1,1) ! Leads fraction 
+            ht_i(ji,jj+1,jl) = ht_i(ji,jj,jl) * tmask(ji,jj+1,1) ! Ice depth 
+            ht_s(ji,jj+1,jl) = ht_s(ji,jj,jl) * tmask(ji,jj+1,1) ! Snow depth
+
+            a_i (ji,jj-1,jl) = a_i (ji,jj,jl) * tmask(ji,jj-1,1) ! Leads fraction 
+            ht_i(ji,jj-1,jl) = ht_i(ji,jj,jl) * tmask(ji,jj-1,1) ! Ice depth 
+            ht_s(ji,jj-1,jl) = ht_s(ji,jj,jl) * tmask(ji,jj-1,1) ! Snow depth
+
+            a_i (ji+1,jj,jl) = a_i (ji,jj,jl) * tmask(ji+1,jj,1) ! Leads fraction 
+            ht_i(ji+1,jj,jl) = ht_i(ji,jj,jl) * tmask(ji+1,jj,1) ! Ice depth 
+            ht_s(ji+1,jj,jl) = ht_s(ji,jj,jl) * tmask(ji+1,jj,1) ! Snow depth
+
+            a_i (ji-1,jj,jl) = a_i (ji,jj,jl) * tmask(ji-1,jj,1) ! Leads fraction 
+            ht_i(ji-1,jj,jl) = ht_i(ji,jj,jl) * tmask(ji-1,jj,1) ! Ice depth 
+            ht_s(ji-1,jj,jl) = ht_s(ji,jj,jl) * tmask(ji-1,jj,1) ! Snow depth
+
+            zindaa = ( 1.0 - MAX( 0.0_wp , SIGN ( 1.0_wp , - a_i(ji,jj,jl) ) ) ) * tmask(ji-1:ji+1,jj-1:jj+1,1) ! 0 if no ice
+            ! --------------------
+            ! Ice and snow volumes
+            ! --------------------
+            v_i(ji-1:ji+1,jj-1:jj+1,jl) = ht_i(ji-1:ji+1,jj-1:jj+1,jl) * a_i(ji-1:ji+1,jj-1:jj+1,jl)
+            v_s(ji-1:ji+1,jj-1:jj+1,jl) = ht_s(ji-1:ji+1,jj-1:jj+1,jl) * a_i(ji-1:ji+1,jj-1:jj+1,jl)
+
+            ! -------------
+            ! Ice salinity
+            !---------------
+            sm_i(ji-1:ji+1,jj-1:jj+1,jl)   = zindaa * 8.0  + ( 1.0 - zindaa ) * 0.1
+            smv_i(ji-1:ji+1,jj-1:jj+1,jl)  = MIN( sm_i(ji-1:ji+1,jj-1:jj+1,jl) , sss_m(ji-1:ji+1,jj-1:jj+1) ) * v_i(ji-1:ji+1,jj-1:jj+1,jl)
+            
+            !----------
+            ! Ice age
+            !----------
+            o_i(ji-1:ji+1,jj-1:jj+1,jl)    = zindaa * 1.0   + ( 1.0 - zindaa )
+            oa_i(ji-1:ji+1,jj-1:jj+1,jl)   = o_i(ji-1:ji+1,jj-1:jj+1,jl) * a_i(ji-1:ji+1,jj-1:jj+1,jl)
+            
+            !------------------------------
+            ! Sea ice surface temperature
+            !------------------------------
+            t_su(ji-1:ji+1,jj-1:jj+1,jl)   = zindaa * ( rtt - 1.9 ) + ( 1.0 - zindaa ) * t_bo(ji-1:ji+1,jj-1:jj+1)
+            
+            !------------------------------------
+            ! Snow temperature and heat content
+            !------------------------------------
+            DO jk = 1, nlay_s
+               t_s(ji-1:ji+1,jj-1:jj+1,jk,jl) = zindaa * ( rtt - 1.9 ) + ( 1.0 - zindaa ) * rtt
+               ! Snow energy of melting
+               e_s(ji-1:ji+1,jj-1:jj+1,jk,jl) = zindaa * rhosn * ( cpic * ( rtt - t_s(ji-1:ji+1,jj-1:jj+1,jk,jl) ) + lfus )
+               ! Change dimensions
+               e_s(ji-1:ji+1,jj-1:jj+1,jk,jl) = e_s(ji-1:ji+1,jj-1:jj+1,jk,jl) / unit_fac
+               ! Multiply by volume, so that heat content in 10^9 Joules
+               e_s(ji-1:ji+1,jj-1:jj+1,jk,jl) = e_s(ji-1:ji+1,jj-1:jj+1,jk,jl) * area(ji-1:ji+1,jj-1:jj+1) * &
+                    v_s(ji-1:ji+1,jj-1:jj+1,jl)  / nlay_s
+            END DO !jk
+            
+            !-----------------------------------------------
+            ! Ice salinities, temperature and heat content 
+            !-----------------------------------------------
+            DO jk = 1, nlay_i
+               t_i(ji-1:ji+1,jj-1:jj+1,jk,jl) = zindaa * ( rtt - 1.9 ) + ( 1.0 - zindaa ) * rtt 
+               s_i(ji-1:ji+1,jj-1:jj+1,jk,jl) = zindaa * 8.0 + ( 1.0 - zindaa ) * 0.1
+               ztmelts          = - tmut * s_i(ji,jj,jk,jl) + rtt !Melting temperature in K
+               
+               ! heat content per unit volume
+               e_i(ji-1:ji+1,jj-1:jj+1,jk,jl) = zindaa * rhoic * &
+                    (   cpic    * ( ztmelts - t_i(ji-1:ji+1,jj-1:jj+1,jk,jl) ) &
+                    +   lfus    * ( 1.0 - (ztmelts-rtt) / MIN((t_i(ji-1:ji+1,jj-1:jj+1,jk,jl)-rtt),-epsi20) ) &
+                    - rcp      * ( ztmelts - rtt ) &
+                    )
+               
+               ! Correct dimensions to avoid big values
+               e_i(ji-1:ji+1,jj-1:jj+1,jk,jl) = e_i(ji-1:ji+1,jj-1:jj+1,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-1:ji+1,jj-1:jj+1,jk,jl) = e_i(ji-1:ji+1,jj-1:jj+1,jk,jl) * & 
+                    area(ji-1:ji+1,jj-1:jj+1) * a_i(ji-1:ji+1,jj-1:jj+1,jl) * ht_i(ji-1:ji+1,jj-1:jj+1,jl) / &
+                    nlay_i
+            END DO ! jk
+
+        END DO !jb
+
+
+         CALL lbc_lnk(  a_i(:,:,jl), 'T', 1. )                                         ! lateral boundary conditions
+         CALL lbc_lnk( ht_i(:,:,jl), 'T', 1. )
+         CALL lbc_lnk( ht_s(:,:,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(  sm_i(:,:,jl), 'T', 1. )
+         CALL lbc_lnk(  oa_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
+
+      END DO !jl
+    
+#endif
+      !      
+      !ENDIF !nit000/=0
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_ice_frs')
+      !
+   END SUBROUTINE bdy_ice_frs
+#else
+   !!---------------------------------------------------------------------------------
+   !!   Default option                                                    Empty module
+   !!---------------------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE bdy_ice_lim( kt )      ! Empty routine
+      WRITE(*,*) 'bdy_ice_lim: You should not have seen this print! error?', kt
+   END SUBROUTINE bdy_ice_lim
+#endif
+
+   !!=================================================================================
+END MODULE bdyice_lim
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 3938)
@@ -69,8 +69,9 @@
       REAL   , POINTER  ::  flagu, flagv                   !    -   -
       REAL(wp) ::   zefl, zwfl, znfl, zsfl                 ! local scalars
-      INTEGER, DIMENSION (2)                ::   kdimsz
+      INTEGER, DIMENSION (1)                ::   kdimsz
       INTEGER, DIMENSION(jpbgrd,jp_bdy)       ::   nblendta         ! Length of index arrays 
       INTEGER, ALLOCATABLE, DIMENSION(:,:,:)  ::   nbidta, nbjdta   ! Index arrays: i and j indices of bdy dta
       INTEGER, ALLOCATABLE, DIMENSION(:,:,:)  ::   nbrdta           ! Discrete distance from rim points
+      REAL, ALLOCATABLE, DIMENSION(:)         ::   znblendta           
       REAL(wp), DIMENSION(jpidta,jpjdta)    ::   zmask            ! global domain mask
       CHARACTER(LEN=80),DIMENSION(jpbgrd)  ::   clfile
@@ -80,6 +81,6 @@
          &             ln_mask_file, cn_mask_file, nn_dyn2d, nn_dyn2d_dta, &
          &             nn_dyn3d, nn_dyn3d_dta, nn_tra, nn_tra_dta,         &  
-#if defined key_lim2
-         &             nn_ice_lim2, nn_ice_lim2_dta,                       &
+#if ( defined key_lim2 || defined key_lim3 )
+         &             nn_ice_lim, nn_ice_lim_dta,                       &
 #endif
          &             ln_vol, nn_volctl, nn_rimwidth
@@ -121,7 +122,7 @@
       nn_tra(:)         = 0
       nn_tra_dta(:)     = -1  ! uninitialised flag
-#if defined key_lim2
-      nn_ice_lim2(:)    = 0
-      nn_ice_lim2_dta(:)= -1  ! uninitialised flag
+#if ( defined key_lim2 || defined key_lim3 )
+      nn_ice_lim(:)    = 0
+      nn_ice_lim_dta(:)= -1  ! uninitialised flag
 #endif
       ln_vol            = .false.
@@ -204,16 +205,16 @@
         IF(lwp) WRITE(numout,*)
 
-#if defined key_lim2
+#if ( defined key_lim2 || defined key_lim3 )
         IF(lwp) WRITE(numout,*) 'Boundary conditions for sea ice:  '
-        SELECT CASE( nn_ice_lim2(ib_bdy) )                  
+        SELECT CASE( nn_ice_lim(ib_bdy) )                  
           CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      no open boundary condition'        
           CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
           CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_tra' )
         END SELECT
-        IF( nn_ice_lim2(ib_bdy) .gt. 0 ) THEN 
-           SELECT CASE( nn_ice_lim2_dta(ib_bdy) )                   ! 
+        IF( nn_ice_lim(ib_bdy) .gt. 0 ) THEN 
+           SELECT CASE( nn_ice_lim_dta(ib_bdy) )                   ! 
               CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
               CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
-              CASE DEFAULT   ;   CALL ctl_stop( 'nn_ice_lim2_dta must be 0 or 1' )
+              CASE DEFAULT   ;   CALL ctl_stop( 'nn_ice_lim_dta must be 0 or 1' )
            END SELECT
         ENDIF
@@ -327,7 +328,10 @@
             DO igrd = 1, jpbgrd
                id_dummy = iom_varid( inum, 'nbi'//cgrid(igrd), kdimsz=kdimsz )  
-               nblendta(igrd,ib_bdy) = kdimsz(1)
-               jpbdta = MAX(jpbdta, kdimsz(1))
-            ENDDO
+               !clem nblendta(igrd,ib_bdy) = kdimsz(1)
+               !clem jpbdta = MAX(jpbdta, kdimsz(1))
+               nblendta(igrd,ib_bdy) = MAXVAL(kdimsz)
+               jpbdta = MAX(jpbdta, MAXVAL(kdimsz))
+            ENDDO
+            CALL iom_close( inum )
 
          ENDIF 
@@ -505,21 +509,25 @@
             ENDDO
 
-         ELSE            ! Read global index arrays from boundary coordinates file.
-
-            DO igrd = 1, jpbgrd
-               CALL iom_get( inum, jpdom_unknown, 'nbi'//cgrid(igrd), dta_global(1:nblendta(igrd,ib_bdy),:,1) )
+         ELSE            ! Read global index arrays from boundary coordinates file
+
+          CALL iom_open( cn_coords_file(ib_bdy), inum )
+          DO igrd = 1, jpbgrd
+               ALLOCATE(znblendta(nblendta(igrd,ib_bdy)))
+
+               CALL iom_get( inum, jpdom_unknown, 'nbi'//cgrid(igrd), znblendta(1:nblendta(igrd,ib_bdy)) )
                DO ii = 1,nblendta(igrd,ib_bdy)
-                  nbidta(ii,igrd,ib_bdy) = INT( dta_global(ii,1,1) )
+                  nbidta(ii,igrd,ib_bdy) = INT( znblendta(ii) )
                END DO
-               CALL iom_get( inum, jpdom_unknown, 'nbj'//cgrid(igrd), dta_global(1:nblendta(igrd,ib_bdy),:,1) )
+               CALL iom_get( inum, jpdom_unknown, 'nbj'//cgrid(igrd), znblendta(1:nblendta(igrd,ib_bdy)) )
                DO ii = 1,nblendta(igrd,ib_bdy)
-                  nbjdta(ii,igrd,ib_bdy) = INT( dta_global(ii,1,1) )
+                  nbjdta(ii,igrd,ib_bdy) = INT( znblendta(ii) )
                END DO
-               CALL iom_get( inum, jpdom_unknown, 'nbr'//cgrid(igrd), dta_global(1:nblendta(igrd,ib_bdy),:,1) )
+               CALL iom_get( inum, jpdom_unknown, 'nbr'//cgrid(igrd), znblendta(1:nblendta(igrd,ib_bdy)) )
                DO ii = 1,nblendta(igrd,ib_bdy)
-                  nbrdta(ii,igrd,ib_bdy) = INT( dta_global(ii,1,1) )
+                  nbrdta(ii,igrd,ib_bdy) = INT( znblendta(ii) )
                END DO
 
-               ibr_max = MAXVAL( nbrdta(:,igrd,ib_bdy) )
+               ibr_max = MAXVAL( nbrdta(1:nblendta(igrd,ib_bdy),igrd,ib_bdy) )
+               !WRITE(numout,*) nbrdta(1:nblendta(igrd,ib_bdy),igrd,ib_bdy)
                IF(lwp) WRITE(numout,*)
                IF(lwp) WRITE(numout,*) ' Maximum rimwidth in file is ', ibr_max
@@ -527,5 +535,5 @@
                IF (ibr_max < nn_rimwidth(ib_bdy))   &
                      CALL ctl_stop( 'nn_rimwidth is larger than maximum rimwidth in file',cn_coords_file(ib_bdy) )
-
+               DEALLOCATE(znblendta)
             END DO
             CALL iom_close( inum )
@@ -680,4 +688,6 @@
       tmask_i (:,:) = tmask(:,:,1) * tmask_i(:,:)             
       bdytmask(:,:) = tmask(:,:,1)
+      bdyumask(:,:) = umask(:,:,1)
+      bdyvmask(:,:) = vmask(:,:,1)
 
       ! bdy masks and bmask are now set to zero on boundary points:
@@ -803,5 +813,4 @@
 
       IF( nn_timing == 1 ) CALL timing_stop('bdy_init')
-
    END SUBROUTINE bdy_init
 
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 3938)
@@ -9,4 +9,5 @@
    !!            3.3  !  2010-09  (D.Storkey and E.O'Dea)  bug fixes
    !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
+   !!             -   !  2012-02  (C. Rousset) tides reordered 
    !!----------------------------------------------------------------------
 #if defined key_bdy
@@ -89,6 +90,5 @@
       NAMELIST/nambdy_tide/ln_tide_date, filtide, tide_cpt, tide_speed
       !!----------------------------------------------------------------------
-
-      IF( nn_timing == 1 ) CALL timing_start('tide_init')
+      IF( nn_timing == 1 ) CALL timing_start('bdy-tide_init')
 
       IF(lwp) WRITE(numout,*)
@@ -125,18 +125,18 @@
             DO itide = 1, td%ncpt
                nindx(itide) = 0
-               IF( TRIM( tide_cpt(itide) ) == 'Q1'  )   nindx(itide) =  1
-               IF( TRIM( tide_cpt(itide) ) == 'O1'  )   nindx(itide) =  2
-               IF( TRIM( tide_cpt(itide) ) == 'P1'  )   nindx(itide) =  3
-               IF( TRIM( tide_cpt(itide) ) == 'S1'  )   nindx(itide) =  4
+               IF( TRIM( tide_cpt(itide) ) == 'M2'  )   nindx(itide) =  1
+               IF( TRIM( tide_cpt(itide) ) == 'S2'  )   nindx(itide) =  2
+               IF( TRIM( tide_cpt(itide) ) == 'N2'  )   nindx(itide) =  3
+               IF( TRIM( tide_cpt(itide) ) == 'K2'  )   nindx(itide) =  4
                IF( TRIM( tide_cpt(itide) ) == 'K1'  )   nindx(itide) =  5
-               IF( TRIM( tide_cpt(itide) ) == '2N2' )   nindx(itide) =  6
-               IF( TRIM( tide_cpt(itide) ) == 'MU2' )   nindx(itide) =  7
-               IF( TRIM( tide_cpt(itide) ) == 'N2'  )   nindx(itide) =  8
-               IF( TRIM( tide_cpt(itide) ) == 'NU2' )   nindx(itide) =  9
-               IF( TRIM( tide_cpt(itide) ) == 'M2'  )   nindx(itide) = 10
-               IF( TRIM( tide_cpt(itide) ) == 'L2'  )   nindx(itide) = 11
-               IF( TRIM( tide_cpt(itide) ) == 'T2'  )   nindx(itide) = 12
-               IF( TRIM( tide_cpt(itide) ) == 'S2'  )   nindx(itide) = 13
-               IF( TRIM( tide_cpt(itide) ) == 'K2'  )   nindx(itide) = 14
+               IF( TRIM( tide_cpt(itide) ) == 'O1'  )   nindx(itide) =  6
+               IF( TRIM( tide_cpt(itide) ) == 'P1'  )   nindx(itide) =  7
+               IF( TRIM( tide_cpt(itide) ) == 'Q1'  )   nindx(itide) =  8
+               IF( TRIM( tide_cpt(itide) ) == 'S1'  )   nindx(itide) =  9
+               IF( TRIM( tide_cpt(itide) ) == '2N2' )   nindx(itide) = 10 
+               IF( TRIM( tide_cpt(itide) ) == 'MU2' )   nindx(itide) = 11 
+               IF( TRIM( tide_cpt(itide) ) == 'NU2' )   nindx(itide) = 12 
+               IF( TRIM( tide_cpt(itide) ) == 'L2'  )   nindx(itide) = 13
+               IF( TRIM( tide_cpt(itide) ) == 'T2'  )   nindx(itide) = 14
                IF( TRIM( tide_cpt(itide) ) == 'M4'  )   nindx(itide) = 15
                IF( nindx(itide) == 0  .AND. lwp ) THEN
@@ -225,6 +225,5 @@
                   !
                   IF( nindx(itide) /= 0 ) THEN
-!!gm use rpi  and rad global variable  
-                     z_arg = 3.14159265d0 * z_vplu(nindx(itide)) / 180.0d0
+                     z_arg = rad * z_vplu(nindx(itide))
                      z_atde=z_ftc(nindx(itide))*cos(z_arg)
                      z_btde=z_ftc(nindx(itide))*sin(z_arg)
@@ -268,5 +267,5 @@
       END DO ! loop on ib_bdy
 
-      IF( nn_timing == 1 ) CALL timing_stop('tide_init')
+      IF( nn_timing == 1 ) CALL timing_stop('bdy-tide_init')
 
    END SUBROUTINE tide_init
@@ -299,5 +298,5 @@
       !!----------------------------------------------------------------------
 
-      IF( nn_timing == 1 ) CALL timing_start('tide_update')
+      IF( nn_timing == 1 ) CALL timing_start('bdy-tide_update')
 
       time_add = 0
@@ -338,5 +337,5 @@
       END DO
       !
-      IF( nn_timing == 1 ) CALL timing_stop('tide_update')
+      IF( nn_timing == 1 ) CALL timing_stop('bdy-tide_update')
       !
    END SUBROUTINE tide_update
@@ -361,15 +360,15 @@
       CHARACTER(len=8), DIMENSION(nc) :: cname
       INTEGER                 ::   year, vd, ivdy, ndc, i, k
-      REAL(wp)                ::   ss, h, p, en, p1, rtd
+      REAL(wp)                ::   ss, h, p, en, p1
       REAL(wp), DIMENSION(nc) ::   f                          ! nodal correction
       REAL(wp), DIMENSION(nc) ::   z_vplu                     ! phase correction
       REAL(wp), DIMENSION(nc) ::   u, v, zig
       !!
-      DATA cname/  'q1'    ,    'o1'    ,     'p1'   ,    's1'    ,     'k1'    ,   &
-         &         '2n2'   ,    'mu2'   ,     'n2'   ,    'nu2'   ,     'm2'    ,   &
-         &         'l2'    ,    't2'    ,     's2'   ,    'k2'    ,     'm4'      /
-      DATA zig/ .2338507481, .2433518789, .2610826055, .2617993878,  .2625161701,   &
-         &      .4868657873, .4881373225, .4963669182, .4976384533,  .5058680490,   &
-         &      .5153691799, .5228820265, .5235987756, .5250323419, 1.011736098   /
+      DATA cname/  'm2'   ,    's2'   ,     'n2'   ,    'k2'   ,     'k1'    ,   &
+         &         'o1'   ,    'p1'   ,     'q1'   ,    's1'   ,     '2n2'   ,   &
+         &         'mu2'  ,    'nu2'  ,     'l2'   ,    't2'   ,     'm4'      /
+      DATA zig/ .5058680490, .5235987756, .4963669182, .5250323419, .2625161701, &
+                .2433518789, .2610826055, .2338507481, .2617993878, .4868657873, &
+                .4881373225, .4976384533, .5153691799, .5228820265, 1.011736098 /
       !!----------------------------------------------------------------------
 !
@@ -389,8 +388,6 @@
       ndc = nc
 !.....ndc   =  number of constituents allowed
-!!gm use rpi ?
-      rtd = 360.0 / 6.2831852
       DO i = 1, ndc
-         zig(i) = zig(i)*rtd
+         zig(i) = zig(i) / rad
          ! sigo(i)= zig(i)
       END DO
@@ -535,10 +532,9 @@
 !
 !!gm   precision of the computation   :  example for s it should be replace by:
-!!gm  s   = 218.3165 + (481267.8813 - 0.0016*t)*t + 152.0*deltat   ==>  more precise  modify the last digits results
-      s   = 218.3165 + 481267.8813*t - 0.0016*t*t + 152.0*deltat
-      h   = 280.4661 + 36000.7698 *t + 0.0003*t*t +  11.0*deltat
-      p   =  83.3535 + 4069.0139  *t - 0.0103*t*t +       deltat
-      en  = 234.9555 + 1934.1363  *t - 0.0021*t*t +       deltat
-      p1  = 282.9384 + 1.7195     *t + 0.0005*t*t
+      s   = 218.3165 + (481267.8813 - 0.0016*t)*t + 152.0*deltat
+      h   = 280.4661 + (36000.7698  + 0.0003*t)*t +  11.0*deltat
+      p   =  83.3535 + (4069.0139   - 0.0103*t)*t +       deltat
+      en  = 234.9555 + (1934.1363   - 0.0021*t)*t +       deltat
+      p1  = 282.9384 + (1.7195      + 0.0005*t)*t
       !
       nn = s / cycle
@@ -579,6 +575,5 @@
       !!
       
-!!gm  rad is already a public variable defined in phycst.F90 ....   ==> doctor norme  local real start with "z"
-      REAL(wp) ::   w1, w2, w3, w4, w5, w6, w7, w8, nw, pw, rad
+      REAL(wp) ::   w1, w2, w3, w4, w5, w6, w7, w8, nw, pw
       REAL(wp) ::   a(nc), b(nc)
       INTEGER  ::   ndc, k
@@ -589,6 +584,4 @@
 !    a=f       ,  b =u
 !    t is  zero as compared to tifa.
-!! use rad defined in phycst   (i.e.  add a USE phycst at the begining of the module
-      rad = 6.2831852d0/360.0
       pw = p  * rad
       nw = cn * rad
@@ -604,50 +597,50 @@
          &    - 0.0156 * SIN( 2*pw-2*nw ) - 0.037  * SIN(     nw )
       !
-      a(1) = 1.0089 + 0.1871 * w1 - 0.0147 * w2 + 0.0014 * w3
-      b(1) =          0.1885 * w4 - 0.0234 * w5 + 0.0033 * w6
-      !   q1
-      a(2) = a(1)
-      b(2) = b(1)
-      !   o1
-      a(3) = 1.0
-      b(3) = 0.0
-      !   p1
-      a(4) = 1.0
-      b(4) = 0.0
-      !   s1
+      a(1) = 1.0004 -0.0373*w1+ 0.0002*w2
+      b(1) = -0.0374*w4
+      !   m2
+      a(2)=  1.0
+      b(2)=  0.0
+      !   s2
+      a(3) = 1.0004 -0.0373*w1+ 0.0002*w2
+      b(3) = -0.0374*w4
+      !   n2
+      a(4) = 1.0241+0.2863*w1+0.0083*w2 -0.0015*w3
+      b(4) = -0.3096*w4 + 0.0119*w5 - 0.0007*w6
+      !   k2
       a(5) = 1.0060+0.1150*w1- 0.0088*w2 +0.0006*w3
       b(5) = -0.1546*w4 + 0.0119*w5 -0.0012*w6
       !   k1
-      a(6) =1.0004 -0.0373*w1+ 0.0002*w2
-      b(6) = -0.0374*w4
+      a(6) = 1.0089 + 0.1871 * w1 - 0.0147 * w2 + 0.0014 * w3
+      b(6) =          0.1885 * w4 - 0.0234 * w5 + 0.0033 * w6
+      !   o1
+      a(7) = 1.0
+      b(7) = 0.0
+      !   p1
+      a(8) = 1.0089 + 0.1871 * w1 - 0.0147 * w2 + 0.0014 * w3
+      b(8) =          0.1885 * w4 - 0.0234 * w5 + 0.0033 * w6
+      !   q1
+      a(9) = 1.0
+      b(9) = 0.0
+      !   s1
+      a(10) =  1.0004 -0.0373*w1+ 0.0002*w2
+      b(10) = -0.0374*w4
       !  2n2
-      a(7) = a(6)
-      b(7) = b(6)
+      a(11) =  1.0004 -0.0373*w1+ 0.0002*w2
+      b(11) = -0.0374*w4
       !  mu2
-      a(8) = a(6)
-      b(8) = b(6)
-      !   n2
-      a(9) = a(6)
-      b(9) = b(6)
+      a(12) =  1.0004 -0.0373*w1+ 0.0002*w2
+      b(12) = -0.0374*w4
       !  nu2
-      a(10) = a(6)
-      b(10) = b(6)
-      !   m2
-      a(11) = SQRT( w7 * w7 + w8 * w8 )
-      b(11) = ATAN( w8 / w7 )
+      a(13) = SQRT( w7 * w7 + w8 * w8 )
+      b(13) = ATAN( w8 / w7 )
 !!gmuse rpi  instead of 3.141992 ???   true pi is rpi=3.141592653589793_wp  .....   ????
-      IF( w7 < 0.e0 )   b(11) = b(11) + 3.141992
+      IF( w7 < 0.e0 )   b(13) = b(13) + 3.141992
       !   l2
-      a(12) = 1.0
-      b(12) = 0.0
+      a(14) = 1.0
+      b(14) = 0.0
       !   t2
-      a(13)= a(12)
-      b(13)= b(12)
-      !   s2
-      a(14) = 1.0241+0.2863*w1+0.0083*w2 -0.0015*w3
-      b(14) = -0.3096*w4 + 0.0119*w5 - 0.0007*w6
-      !   k2
-      a(15) = a(6)*a(6)
-      b(15) = 2*b(6)
+      a(15) = a(10)*a(10)
+      b(15) = 2*b(10)
       !   m4
 !!gm  old coding,  remove GOTO and label of lines
@@ -686,19 +679,19 @@
       ndc = nc
       !   v s  are computed here.
-      v(1) =-3*s +h +p +270      ! Q1
-      v(2) =-2*s +h +270.0       ! O1
-      v(3) =-h +270              ! P1
-      v(4) =180                  ! S1
-      v(5) =h +90.0              ! K1
-      v(6) =-4*s +2*h +2*p       ! 2N2
-      v(7) =-4*(s-h)             ! MU2
-      v(8) =-3*s +2*h +p         ! N2
-      v(9) =-3*s +4*h -p         ! MU2
-      v(10) =-2*s +2*h           ! M2
-      v(11) =-s +2*h -p +180     ! L2 
-      v(12) =-h +p1              ! T2
-      v(13) =0                   ! S2
-      v(14) =h+h                 ! K2
-      v(15) =2*v(10)             ! M4
+      v(1)  =-2*s +2*h           ! M2
+      v(2)  =0                   ! S2
+      v(3)  =-3*s +2*h +p        ! N2
+      v(4)  =h+h                 ! K2
+      v(5)  =h +90.0             ! K1
+      v(6)  =-2*s +h +270.0      ! O1
+      v(7)  =-h +270             ! P1
+      v(8)  =-3*s +h +p +270     ! Q1
+      v(9)  =180                 ! S1
+      v(10) =-4*s +2*h +2*p      ! 2N2
+      v(11) =-4*(s-h)            ! MU2
+      v(12) =-3*s +4*h -p        ! NU2
+      v(13) =-s +2*h -p +180     ! L2 
+      v(14) =-h +p1              ! T2
+      v(15) =2*v(1)              ! M4
 !
 !!gm  old coding,  remove GOTO and label of lines
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90	(revision 3938)
@@ -85,5 +85,5 @@
             ij = idx%nbj(ib,igrd)
             zwgt = idx%nbw(ib,igrd)
-            tsa(ii,ij,ik,jp_tem) = ( tsa(ii,ij,ik,jp_tem) + zwgt * ( dta%tem(ib,ik) - tsa(ii,ij,ik,jp_tem) ) ) * tmask(ii,ij,ik)         
+            tsa(ii,ij,ik,jp_tem) = ( tsa(ii,ij,ik,jp_tem) + zwgt * ( dta%tem(ib,ik) - tsa(ii,ij,ik,jp_tem) ) ) * tmask(ii,ij,ik)
             tsa(ii,ij,ik,jp_sal) = ( tsa(ii,ij,ik,jp_sal) + zwgt * ( dta%sal(ib,ik) - tsa(ii,ij,ik,jp_sal) ) ) * tmask(ii,ij,ik)
          END DO
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90	(revision 3938)
@@ -77,5 +77,4 @@
       TYPE(OBC_INDEX), POINTER :: idx
       !!-----------------------------------------------------------------------------
-
       IF( nn_timing == 1 ) CALL timing_start('bdy_vol')
 
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 3938)
@@ -5,4 +5,5 @@
    !!======================================================================
    !! History :  3.3  ! 2010-09  (M. Leclair)  Original code 
+   !!                 ! 2012-10  (C. Rousset)  add iom_put
    !!----------------------------------------------------------------------
 
@@ -21,4 +22,8 @@
    USE bdy_par         ! (for lk_bdy)
    USE timing          ! preformance summary
+   USE iom             ! I/O manager
+   USE lib_fortran     ! glob_sum
+   USE restart         ! ocean restart
+   USE wrk_nemo         ! work arrays
 
    IMPLICIT NONE
@@ -26,16 +31,13 @@
 
    PUBLIC   dia_hsb        ! routine called by step.F90
-   PUBLIC   dia_hsb_init   ! routine called by opa.F90
+   PUBLIC   dia_hsb_init   ! routine called by nemogcm.F90
+   PUBLIC   dia_hsb_rst    ! routine called by step.F90
 
    LOGICAL, PUBLIC ::   ln_diahsb  = .FALSE.   !: check the heat and salt budgets
 
-   INTEGER                                 ::   numhsb                           !
-   REAL(dp)                                ::   surf_tot   , vol_tot             !
-   REAL(dp)                                ::   frc_t      , frc_s     , frc_v   ! global forcing trends
-   REAL(dp)                                ::   fact1                            ! conversion factors
-   REAL(dp)                                ::   fact21    , fact22               !     -         -
-   REAL(dp)                                ::   fact31    , fact32               !     -         -
-   REAL(dp), DIMENSION(:,:)  , ALLOCATABLE ::   surf      , ssh_ini              !
-   REAL(dp), DIMENSION(:,:,:), ALLOCATABLE ::   hc_loc_ini, sc_loc_ini, e3t_ini  !
+   REAL(wp), SAVE                                ::   frc_t      , frc_s     , frc_v   ! global forcing trends
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ssh_ini              !
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hc_loc_ini, sc_loc_ini, e3t_ini  !
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hcssh_loc_ini, scssh_loc_ini     !
 
    !! * Substitutions
@@ -61,88 +63,118 @@
       !!	            - Compute the contribution of forcing and remove it from these deviations
       !!
-      !! ** Action : Write the results in the 'heat_salt_volume_budgets.txt' ASCII file
       !!---------------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !!
       INTEGER    ::   jk                          ! dummy loop indice
-      REAL(dp)   ::   zdiff_hc    , zdiff_sc      ! heat and salt content variations
-      REAL(dp)   ::   zdiff_v1    , zdiff_v2      ! volume variation
-      REAL(dp)   ::   z1_rau0                     ! local scalars
-      REAL(dp)   ::   zdeltat                     !    -     -
-      REAL(dp)   ::   z_frc_trd_t , z_frc_trd_s   !    -     -
-      REAL(dp)   ::   z_frc_trd_v                 !    -     -
-      !!---------------------------------------------------------------------------
-      IF( nn_timing == 1 )   CALL timing_start('dia_hsb')
-
+      REAL(wp)   ::   zdiff_hc    , zdiff_sc      ! heat and salt content variations
+      REAL(wp)   ::   zdiff_v1    , zdiff_v2      ! volume variation
+      REAL(wp)   ::   z_hc        , z_sc          ! heat and salt content
+      REAL(wp)   ::   z_v1        , z_v2          ! volume
+      REAL(wp)   ::   z1_rau0                     ! local scalars
+      REAL(wp)   ::   zdeltat                     !    -     -
+      REAL(wp)   ::   z_frc_trd_t , z_frc_trd_s   !    -     -
+      REAL(wp)   ::   z_frc_trd_v                 !    -     -
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   zsurf              !
+      !!---------------------------------------------------------------------------
+      IF( nn_timing == 1 )   CALL timing_start('dia_hsb')      
+
+      CALL wrk_alloc( jpi, jpj, zsurf )
+  
+      zsurf(:,:) = e1t(:,:) * e2t(:,:) * tmask(:,:,1) * tmask_i(:,:)      ! masked surface grid cell area
+      
       ! ------------------------- !
       ! 1 - Trends due to forcing !
       ! ------------------------- !
       z1_rau0 = 1.e0 / rau0
-      z_frc_trd_v = z1_rau0 * SUM( - ( emp(:,:) - rnf(:,:) ) * surf(:,:) )     ! volume fluxes
-      z_frc_trd_t =           SUM( sbc_tsc(:,:,jp_tem) * surf(:,:) )     ! heat fluxes
-      z_frc_trd_s =           SUM( sbc_tsc(:,:,jp_sal) * surf(:,:) )     ! salt fluxes
+      z_frc_trd_v = z1_rau0 * glob_sum( - ( emp(:,:) - rnf(:,:) ) * zsurf(:,:) ) ! volume fluxes
+      z_frc_trd_t =           glob_sum( sbc_tsc(:,:,jp_tem) * zsurf(:,:) )       ! heat fluxes
+      z_frc_trd_s =           glob_sum( sbc_tsc(:,:,jp_sal) * zsurf(:,:) )       ! salt fluxes
       ! Add penetrative solar radiation
-      IF( ln_traqsr )   z_frc_trd_t = z_frc_trd_t + ro0cpr * SUM( qsr     (:,:) * surf(:,:) )
+      IF( ln_traqsr )   z_frc_trd_t = z_frc_trd_t + ro0cpr * glob_sum( qsr     (:,:) * zsurf(:,:) )
       ! Add geothermal heat flux
-      IF( ln_trabbc )   z_frc_trd_t = z_frc_trd_t + ro0cpr * SUM( qgh_trd0(:,:) * surf(:,:) )
-      IF( lk_mpp ) THEN
-         CALL mpp_sum( z_frc_trd_v )
-         CALL mpp_sum( z_frc_trd_t )
-      ENDIF
+      IF( ln_trabbc )   z_frc_trd_t = z_frc_trd_t + ro0cpr * glob_sum( qgh_trd0(:,:) * zsurf(:,:) )
+      !
       frc_v = frc_v + z_frc_trd_v * rdt
       frc_t = frc_t + z_frc_trd_t * rdt
       frc_s = frc_s + z_frc_trd_s * rdt
 
-      ! ----------------------- !
-      ! 2 -  Content variations !
-      ! ----------------------- !
-      zdiff_v2 = 0.d0
-      zdiff_hc = 0.d0
-      zdiff_sc = 0.d0
+      ! ------------------------ !
+      ! 2a -  Content variations !
+      ! ------------------------ !
+      zdiff_v2 = 0._wp
+      zdiff_hc = 0._wp
+      zdiff_sc = 0._wp
       ! volume variation (calculated with ssh)
-      zdiff_v1 = SUM( surf(:,:) * tmask(:,:,1) * ( sshn(:,:) - ssh_ini(:,:) ) )
+      zdiff_v1 = glob_sum( zsurf(:,:) * ( sshn(:,:) - ssh_ini(:,:) ) )
       DO jk = 1, jpkm1
          ! volume variation (calculated with scale factors)
-         zdiff_v2 = zdiff_v2 + SUM( surf(:,:) * tmask(:,:,jk)   &
-            &                       * ( fse3t_n(:,:,jk)         &
-            &                           - e3t_ini(:,:,jk) ) )
+         zdiff_v2 = zdiff_v2 + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) - e3t_ini(:,:,jk) ) )
          ! heat content variation
-         zdiff_hc = zdiff_hc + SUM( surf(:,:) * tmask(:,:,jk)          &
-            &                       * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_tem)   &
+         zdiff_hc = zdiff_hc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_tem)   &
             &                           - hc_loc_ini(:,:,jk) ) )
          ! salt content variation
-         zdiff_sc = zdiff_sc + SUM( surf(:,:) * tmask(:,:,jk)          &
-            &                       * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_sal)   &
+         zdiff_sc = zdiff_sc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_sal)   &
             &                           - sc_loc_ini(:,:,jk) ) )
       ENDDO
 
-      IF( lk_mpp ) THEN
-         CALL mpp_sum( zdiff_hc )
-         CALL mpp_sum( zdiff_sc )
-         CALL mpp_sum( zdiff_v1 )
-         CALL mpp_sum( zdiff_v2 )
-      ENDIF
-
       ! Substract forcing from heat content, salt content and volume variations
-      zdiff_v1 = zdiff_v1 - frc_v
-      zdiff_v2 = zdiff_v2 - frc_v
-      zdiff_hc = zdiff_hc - frc_t
-      zdiff_sc = zdiff_sc - frc_s
+      !frc_v = zdiff_v2 - frc_v
+      !frc_t = zdiff_hc - frc_t
+      !frc_s = zdiff_sc - frc_s
       
+      ! add ssh if not vvl
+#ifndef key_vvl
+     zdiff_v2 = zdiff_v2 + zdiff_v1
+     zdiff_hc = zdiff_hc + glob_sum( zsurf(:,:) * ( sshn(:,:) * tsn(:,:,1,jp_tem)   &
+            &                           - hcssh_loc_ini(:,:) ) )
+     zdiff_sc = zdiff_sc + glob_sum( zsurf(:,:) * ( sshn(:,:) * tsn(:,:,1,jp_sal)   &
+            &                           - scssh_loc_ini(:,:) ) )
+#endif 
+      !
+      ! ----------------------- !
+      ! 2b -  Content           !
+      ! ----------------------- !
+      z_v2 = 0._wp
+      z_hc = 0._wp
+      z_sc = 0._wp
+      ! volume (calculated with ssh)
+      z_v1 = glob_sum( zsurf(:,:) * sshn(:,:) )
+      DO jk = 1, jpkm1
+         ! volume (calculated with scale factors)
+         z_v2 = z_v2 + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) )
+         ! heat content
+         z_hc = z_hc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) * tsn(:,:,jk,jp_tem) )
+         ! salt content
+         z_sc = z_sc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) * tsn(:,:,jk,jp_sal) )
+      ENDDO
+      ! add ssh if not vvl
+#ifndef key_vvl
+     z_v2 = z_v2 + z_v1
+     z_hc = z_hc + glob_sum( zsurf(:,:) * sshn(:,:) * tsn(:,:,1,jp_tem) )
+     z_sc = z_sc + glob_sum( zsurf(:,:) * sshn(:,:) * tsn(:,:,1,jp_sal) )
+#endif 
+
       ! ----------------------- !
       ! 3 - Diagnostics writing !
       ! ----------------------- !
       zdeltat  = 1.e0 / ( ( kt - nit000 + 1 ) * rdt )
-      WRITE(numhsb , 9020) kt , zdiff_hc / vol_tot , zdiff_hc * fact1  * zdeltat,                                &
-         &                      zdiff_sc / vol_tot , zdiff_sc * fact21 * zdeltat, zdiff_sc * fact22 * zdeltat,   &
-         &                      zdiff_v1           , zdiff_v1 * fact31 * zdeltat, zdiff_v1 * fact32 * zdeltat,   &
-         &                      zdiff_v2           , zdiff_v2 * fact31 * zdeltat, zdiff_v2 * fact32 * zdeltat
-
-      IF ( kt == nitend ) CLOSE( numhsb )
-
+!
+      CALL iom_put( 'bgtemper',z_hc / z_v2 )               ! Temperature (C) 
+      CALL iom_put( 'bgsaline',z_sc / z_v2 )               ! Salinity (psu)
+      !CALL iom_put( 'bgheatco',zdiff_hc*fact1*zdeltat )      ! Equivalent heat flux (W/m2)
+      !CALL iom_put( 'bgsaltco',zdiff_sc*fact21*zdeltat )     ! Equivalent water flux (mm/s)
+      CALL iom_put( 'bgheatco',zdiff_hc * rau0 * rcp * 1.e-9_wp ) ! Heat content variation (10^9 J)
+      CALL iom_put( 'bgsaltco',zdiff_sc * 1.e-9 )                        ! Salt content variation (psu*km3) 
+      CALL iom_put( 'bgvolssh',zdiff_v1 * 1.e-9 )                         ! volume ssh (km3)  
+      CALL iom_put( 'bgsshtot',zdiff_v1 / glob_sum(zsurf) )              ! ssh (m)  
+      CALL iom_put( 'bgvoltot',zdiff_v2 * 1.e-9 )                         ! volume total (km3) 
+      CALL iom_put( 'bgfrcvol',frc_v * 1.e-9 )                         ! vol - surface forcing (volume) 
+      CALL iom_put( 'bgfrctem',frc_t * rau0 * rcp * 1.e-9_wp ) ! hc  - surface forcing (heat content) 
+      CALL iom_put( 'bgfrcsal',frc_s * 1.e-9 )                         ! sc  - surface forcing (salt content) 
+      !
+      CALL wrk_dealloc( jpi, jpj, zsurf )
+      !
       IF( nn_timing == 1 )   CALL timing_stop('dia_hsb')
-
-9020  FORMAT(I5,11D15.7)
-      !
+!
    END SUBROUTINE dia_hsb
 
@@ -160,5 +192,4 @@
       !!             - Compute coefficients for conversion
       !!---------------------------------------------------------------------------
-      CHARACTER (len=32) ::   cl_name  ! output file name
       INTEGER            ::   jk       ! dummy loop indice
       INTEGER            ::   ierror   ! local integer
@@ -180,89 +211,119 @@
       IF( .NOT. ln_diahsb )   RETURN
 
-      ! ------------------- !
-      ! 1 - Allocate memory !
-      ! ------------------- !
-      ALLOCATE( hc_loc_ini(jpi,jpj,jpk), STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN
-      ENDIF
-      ALLOCATE( sc_loc_ini(jpi,jpj,jpk), STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_hsb: unable to allocate sc_loc_ini' )   ;   RETURN
-      ENDIF
-      ALLOCATE( e3t_ini(jpi,jpj,jpk)   , STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_hsb: unable to allocate e3t_ini' )      ;   RETURN
-      ENDIF
-      ALLOCATE( surf(jpi,jpj)          , STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_hsb: unable to allocate surf' )         ;   RETURN
-      ENDIF
-      ALLOCATE( ssh_ini(jpi,jpj)       , STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_hsb: unable to allocate ssh_ini' )      ;   RETURN
-      ENDIF
-
-      ! ----------------------------------------------- !
-      ! 2 - Time independant variables and file opening !
-      ! ----------------------------------------------- !
-      WRITE(numout,*) "dia_hsb: heat salt volume budgets activated"
-      WRITE(numout,*) "~~~~~~~  output written in the 'heat_salt_volume_budgets.txt' ASCII file"
-      IF( lk_obc .or. lk_bdy ) THEN
-         CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' )         
-      ENDIF
-      cl_name    = 'heat_salt_volume_budgets.txt'                         ! name of output file
-      surf(:,:) = e1t(:,:) * e2t(:,:) * tmask(:,:,1) * tmask_i(:,:)      ! masked surface grid cell area
-      surf_tot  = SUM( surf(:,:) )                                       ! total ocean surface area
-      vol_tot   = 0.d0                                                   ! total ocean volume
-      DO jk = 1, jpkm1
-         vol_tot  = vol_tot + SUM( surf(:,:) * tmask(:,:,jk)     &
-            &                      * fse3t_n(:,:,jk)         )
-      END DO
-      IF( lk_mpp ) THEN 
-         CALL mpp_sum( vol_tot )
-         CALL mpp_sum( surf_tot )
-      ENDIF
-
-      CALL ctl_opn( numhsb , cl_name , 'UNKNOWN' , 'FORMATTED' , 'SEQUENTIAL' , 1 , numout , lwp , 1 )
-      !                   12345678901234567890123456789012345678901234567890123456789012345678901234567890 -> 80
-      WRITE( numhsb, 9010 ) "kt   |     heat content budget     |            salt content budget             ",   &
-         !                                                   123456789012345678901234567890123456789012345 -> 45
-         &                                                  "|            volume budget (ssh)             ",   &
-         !                                                   678901234567890123456789012345678901234567890 -> 45
-         &                                                  "|            volume budget (e3t)             "
-      WRITE( numhsb, 9010 ) "     |      [C]         [W/m2]     |     [psu]        [mmm/s]          [SV]     ",   &
-         &                                                  "|     [m3]         [mmm/s]          [SV]     ",   &
-         &                                                  "|     [m3]         [mmm/s]          [SV]     "
-
-      ! --------------- !
-      ! 3 - Conversions ! (factors will be multiplied by duration afterwards)
-      ! --------------- !
-
-      ! heat content variation   =>   equivalent heat flux:
-      fact1  = rau0 * rcp / surf_tot                                         ! [C*m3]   ->  [W/m2]
-      ! salt content variation   =>   equivalent EMP and equivalent "flow": 
-      fact21 = 1.e3  / ( soce * surf_tot )                                   ! [psu*m3] ->  [mm/s]
-      fact22 = 1.e-6 / soce                                                  ! [psu*m3] ->  [Sv]
-      ! volume variation         =>   equivalent EMP and equivalent "flow":
-      fact31 = 1.e3  / surf_tot                                              ! [m3]     ->  [mm/s]
-      fact32 = 1.e-6                                                         ! [m3]     ->  [SV]
-
-      ! ---------------------------------- !
-      ! 4 - initial conservation variables !
-      ! ---------------------------------- !
-      ssh_ini(:,:) = sshn(:,:)                                       ! initial ssh
-      DO jk = 1, jpk
-         e3t_ini   (:,:,jk) = fse3t_n(:,:,jk)                        ! initial vertical scale factors
-         hc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_tem) * fse3t_n(:,:,jk)   ! initial heat content
-         sc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_sal) * fse3t_n(:,:,jk)   ! initial salt content
-      END DO
-      frc_v = 0.d0                                           ! volume       trend due to forcing
-      frc_t = 0.d0                                           ! heat content   -    -   -    -   
-      frc_s = 0.d0                                           ! salt content   -    -   -    -         
-      !
-9010  FORMAT(A80,A45,A45)
+         ! ------------------- !
+         ! 1 - Allocate memory !
+         ! ------------------- !
+         ALLOCATE( hc_loc_ini(jpi,jpj,jpk), STAT=ierror )
+         IF( ierror > 0 ) THEN
+            CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN
+         ENDIF
+         ALLOCATE( sc_loc_ini(jpi,jpj,jpk), STAT=ierror )
+         IF( ierror > 0 ) THEN
+            CALL ctl_stop( 'dia_hsb: unable to allocate sc_loc_ini' )   ;   RETURN
+         ENDIF
+         ALLOCATE( hcssh_loc_ini(jpi,jpj), STAT=ierror )
+         IF( ierror > 0 ) THEN
+            CALL ctl_stop( 'dia_hsb: unable to allocate hcssh_loc_ini' )   ;   RETURN
+         ENDIF
+         ALLOCATE( scssh_loc_ini(jpi,jpj), STAT=ierror )
+         IF( ierror > 0 ) THEN
+            CALL ctl_stop( 'dia_hsb: unable to allocate scssh_loc_ini' )   ;   RETURN
+         ENDIF
+         ALLOCATE( e3t_ini(jpi,jpj,jpk)   , STAT=ierror )
+         IF( ierror > 0 ) THEN
+            CALL ctl_stop( 'dia_hsb: unable to allocate e3t_ini' )      ;   RETURN
+         ENDIF
+         ALLOCATE( ssh_ini(jpi,jpj)       , STAT=ierror )
+         IF( ierror > 0 ) THEN
+            CALL ctl_stop( 'dia_hsb: unable to allocate ssh_ini' )      ;   RETURN
+         ENDIF
+         
+         ! ----------------------------------------------- !
+         ! 2 - Time independant variables and file opening !
+         ! ----------------------------------------------- !
+         WRITE(numout,*) "dia_hsb: heat salt volume budgets activated"
+         IF( lk_obc .or. lk_bdy ) THEN
+            CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' )         
+         ENDIF
+         
+         ! ---------------------------------- !
+         ! 4 - initial conservation variables !
+         ! ---------------------------------- !
+         !ssh_ini(:,:) = sshn(:,:)                                       ! initial ssh
+         !DO jk = 1, jpk
+         !   e3t_ini   (:,:,jk) = fse3t_n(:,:,jk)                        ! initial vertical scale factors
+         !   hc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_tem) * fse3t_n(:,:,jk)   ! initial heat content
+         !   sc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_sal) * fse3t_n(:,:,jk)   ! initial salt content
+         !END DO
+         !hcssh_loc_ini(:,:) = tsn(:,:,1,jp_tem) * sshn(:,:)   ! initial heat content in ssh
+         !scssh_loc_ini(:,:) = tsn(:,:,1,jp_sal) * sshn(:,:)   ! initial salt content in ssh
+         !frc_v = 0._wp                                           ! volume       trend due to forcing
+         !frc_t = 0._wp                                           ! heat content   -    -   -    -   
+         !frc_s = 0._wp                                           ! salt content   -    -   -    -         
+         !
+         CALL dia_hsb_rst( nit000, 'READ' )  !* read or initialize all required files
       !
    END SUBROUTINE dia_hsb_init
+
+   SUBROUTINE dia_hsb_rst( kt, cdrw )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE limdia_rst  ***
+     !!                     
+     !! ** Purpose :   Read or write DIA file in restart file
+     !!
+     !! ** Method  :   use of IOM library
+     !!----------------------------------------------------------------------
+     INTEGER         , INTENT(in) ::   kt     ! ocean time-step
+     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
+     !
+     INTEGER ::   jk   ! 
+     INTEGER ::   id1   ! local integers
+     !!----------------------------------------------------------------------
+     !
+     IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
+        IF( ln_rstart ) THEN                   !* Read the restart file
+           !id1 = iom_varid( numror, 'frc_vol'  , ldstop = .FALSE. )
+           !
+           CALL iom_get( numror, 'frc_v', frc_v )
+           CALL iom_get( numror, 'frc_t', frc_t )
+           CALL iom_get( numror, 'frc_s', frc_s )
+
+           CALL iom_get( numror, jpdom_autoglo, 'ssh_ini', ssh_ini )
+           CALL iom_get( numror, jpdom_autoglo, 'e3t_ini', e3t_ini )
+           CALL iom_get( numror, jpdom_autoglo, 'hc_loc_ini', hc_loc_ini )
+           CALL iom_get( numror, jpdom_autoglo, 'sc_loc_ini', sc_loc_ini )
+           CALL iom_get( numror, jpdom_autoglo, 'hcssh_loc_ini', hcssh_loc_ini )
+           CALL iom_get( numror, jpdom_autoglo, 'scssh_loc_ini', scssh_loc_ini )
+       ELSE
+          ssh_ini(:,:) = sshn(:,:)                                       ! initial ssh
+          DO jk = 1, jpk
+             e3t_ini   (:,:,jk) = fse3t_n(:,:,jk)                        ! initial vertical scale factors
+             hc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_tem) * fse3t_n(:,:,jk)   ! initial heat content
+             sc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_sal) * fse3t_n(:,:,jk)   ! initial salt content
+          END DO
+          hcssh_loc_ini(:,:) = tsn(:,:,1,jp_tem) * sshn(:,:)   ! initial heat content in ssh
+          scssh_loc_ini(:,:) = tsn(:,:,1,jp_sal) * sshn(:,:)   ! initial salt content in ssh
+          frc_v = 0._wp                                           
+          frc_t = 0._wp                                           
+          frc_s = 0._wp                                                  
+       ENDIF	
+
+     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
+        !                                   ! -------------------
+        IF(lwp) WRITE(numout,*) '---- dia-rst ----'
+        CALL iom_rstput( kt, nitrst, numrow, 'frc_v'   , frc_v     )
+        CALL iom_rstput( kt, nitrst, numrow, 'frc_t'   , frc_t     )
+        CALL iom_rstput( kt, nitrst, numrow, 'frc_s'   , frc_s     )
+        
+        CALL iom_rstput( kt, nitrst, numrow, 'ssh_ini', ssh_ini )
+        CALL iom_rstput( kt, nitrst, numrow, 'e3t_ini', e3t_ini )
+        CALL iom_rstput( kt, nitrst, numrow, 'hc_loc_ini', hc_loc_ini )
+        CALL iom_rstput( kt, nitrst, numrow, 'sc_loc_ini', sc_loc_ini )
+        CALL iom_rstput( kt, nitrst, numrow, 'hcssh_loc_ini', hcssh_loc_ini )
+        CALL iom_rstput( kt, nitrst, numrow, 'scssh_loc_ini', scssh_loc_ini )
+        !
+     ENDIF
+     !
+   END SUBROUTINE dia_hsb_rst
 
    !!======================================================================
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 3938)
@@ -46,4 +46,6 @@
 #if defined key_lim2
    USE limwri_2 
+#elif defined key_lim3
+   USE limwri 
 #endif
    USE lib_mpp         ! MPP library
@@ -743,4 +745,6 @@
       CALL histdef( id_i, "sowaflup", "Net Upward Water Flux" , "Kg/m2/S",   &   ! net freshwater 
          &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+      CALL histdef( id_i, "sosaltfx", "Net Upward Salt Flux"  , "Kg/m2/S",   &   ! net salt flux 
+         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
       CALL histdef( id_i, "sohefldo", "Net Downward Heat Flux", "W/m2"   ,   &   ! net heat flux
          &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
@@ -756,4 +760,6 @@
 #if defined key_lim2
       CALL lim_wri_state_2( kt, id_i, nh_i )
+#elif defined key_lim3
+      CALL lim_wri_state( kt, id_i, nh_i )
 #else
       CALL histend( id_i, snc4chunks=snc4set )
@@ -775,4 +781,5 @@
       CALL histwrite( id_i, "vovecrtz", kt, wn               , jpi*jpj*jpk, idex )    ! now k-velocity
       CALL histwrite( id_i, "sowaflup", kt, (emp-rnf )       , jpi*jpj    , idex )    ! freshwater budget
+      CALL histwrite( id_i, "sosaltfx", kt, emps             , jpi*jpj    , idex )    ! freshwater budget
       CALL histwrite( id_i, "sohefldo", kt, qsr + qns        , jpi*jpj    , idex )    ! total heat flux
       CALL histwrite( id_i, "soshfldo", kt, qsr              , jpi*jpj    , idex )    ! solar heat flux
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 3938)
@@ -510,5 +510,5 @@
          zhmin = gdepw_0(ik+1)                                                         ! minimum depth = ik+1 w-levels 
          WHERE( bathy(:,:) <= 0._wp )   ;   bathy(:,:) = 0._wp                         ! min=0     over the lands
-         ELSE WHERE                     ;   bathy(:,:) = MAX(  zhmin , bathy(:,:)  )   ! min=zhmin over the oceans
+         ELSEWHERE                      ;   bathy(:,:) = MAX(  zhmin , bathy(:,:)  )   ! min=zhmin over the oceans
          END WHERE
          IF(lwp) write(numout,*) 'Minimum ocean depth: ', zhmin, ' minimum number of ocean levels : ', ik
@@ -871,5 +871,5 @@
       bathy(:,:) = MIN( zmax ,  bathy(:,:) )    ! bounded value of bathy (min already set at the end of zgr_bat)
       WHERE( bathy(:,:) == 0._wp )   ;   mbathy(:,:) = 0       ! land  : set mbathy to 0
-      ELSE WHERE                     ;   mbathy(:,:) = jpkm1   ! ocean : initialize mbathy to the max ocean level
+      ELSEWHERE                      ;   mbathy(:,:) = jpkm1   ! ocean : initialize mbathy to the max ocean level
       END WHERE
 
@@ -1575,15 +1575,5 @@
             END DO
          END DO
-         DO jj = mj0(74), mj1(74)
-            DO ji = mi0(100), mi1(100)
-               WRITE(numout,*)
-               WRITE(numout,*) ' domzgr: vertical coordinates : point (100,74,k)   bathy = ', bathy(ji,jj), hbatt(ji,jj)
-               WRITE(numout,*) ' ~~~~~~  --------------------'
-               WRITE(numout,"(9x,' level   gdept    gdepw    gde3w     e3t      e3w  ')")
-               WRITE(numout,"(10x,i4,4f9.2)") ( jk, fsdept(ji,jj,jk), fsdepw(ji,jj,jk),     &
-                  &                                 fse3t (ji,jj,jk), fse3w (ji,jj,jk), jk=1,jpk )
-            END DO
-         END DO
-      ENDIF
+       ENDIF
 
 !!gm bug?  no more necessary?  if ! defined key_helsinki
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 3938)
@@ -319,6 +319,6 @@
             !RBbug for vvl and external mode we may need to use varying fse3
             !!gm  Rq: the bottom e3 present the smallest variation, the use of e3u_0 is not a big approx.
-              zbfru(ji,jj) = MAX(  bfrua(ji,jj) , fse3u(ji,jj,mbku(ji,jj)) * zcoef  )
-              zbfrv(ji,jj) = MAX(  bfrva(ji,jj) , fse3v(ji,jj,mbkv(ji,jj)) * zcoef  )
+            zbfru(ji,jj) = MAX(  bfrua(ji,jj) , fse3u(ji,jj,mbku(ji,jj)) * zcoef  )
+            zbfrv(ji,jj) = MAX(  bfrva(ji,jj) , fse3v(ji,jj,mbkv(ji,jj)) * zcoef  )
            END DO
         END DO
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 3938)
@@ -27,4 +27,5 @@
    USE in_out_manager  ! I/O manager
    USE lib_mpp           ! MPP library
+   USE timing          ! Timing
 #if defined key_iomput
    USE sbc_oce, ONLY :   nn_fsbc         ! ocean space and time domain
@@ -376,5 +377,5 @@
 
 
-   FUNCTION iom_varid ( kiomid, cdvar, kdimsz, ldstop )  
+   FUNCTION iom_varid ( kiomid, cdvar, kdimsz, kndims, ldstop )  
       !!-----------------------------------------------------------------------
       !!                  ***  FUNCTION  iom_varid  ***
@@ -385,4 +386,5 @@
       CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
       INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
+      INTEGER,               INTENT(  out), OPTIONAL ::   kndims   ! size of the dimensions
       LOGICAL              , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if looking for non-existing variable (default = .TRUE.)
       !
@@ -416,5 +418,5 @@
                   SELECT CASE (iom_file(kiomid)%iolib)
                   CASE (jpioipsl )   ;   iom_varid = iom_ioipsl_varid( kiomid, cdvar, iiv, kdimsz )
-                  CASE (jpnf90   )   ;   iom_varid = iom_nf90_varid  ( kiomid, cdvar, iiv, kdimsz )
+                  CASE (jpnf90   )   ;   iom_varid = iom_nf90_varid  ( kiomid, cdvar, iiv, kdimsz, kndims )
                   CASE (jprstdimg)   ;   iom_varid = -1   ! all variables are listed in iom_file
                   CASE DEFAULT   
@@ -437,4 +439,5 @@
                   ENDIF
                ENDIF
+               IF( PRESENT(kndims) )  kndims = iom_file(kiomid)%ndims(iiv)
             ENDIF
          ENDIF
@@ -959,4 +962,5 @@
       CHARACTER(LEN=*), INTENT(in) ::   cdname
       REAL(wp)        , INTENT(in) ::   pfield0d
+      IF( nn_timing == 1 )  CALL timing_start('iom_put0')
 #if defined key_iomput
       CALL event__write_field2D( cdname, RESHAPE( (/pfield0d/), (/1,1/) ) )
@@ -964,4 +968,5 @@
       IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
 #endif
+      IF( nn_timing == 1 )  CALL timing_stop('iom_put0')
    END SUBROUTINE iom_p0d
 
@@ -970,4 +975,5 @@
       REAL(wp),     DIMENSION(:), INTENT(in) ::   pfield1d
       INTEGER :: jpz
+      IF( nn_timing == 1 )  CALL timing_start('iom_put1')
 #if defined key_iomput
       jpz=SIZE(pfield1d)
@@ -976,4 +982,5 @@
       IF( .FALSE. )   WRITE(numout,*) cdname, pfield1d   ! useless test to avoid compilation warnings
 #endif
+      IF( nn_timing == 1 )  CALL timing_stop('iom_put1')
    END SUBROUTINE iom_p1d
 
@@ -981,4 +988,5 @@
       CHARACTER(LEN=*)            , INTENT(in) ::   cdname
       REAL(wp),     DIMENSION(:,:), INTENT(in) ::   pfield2d
+      IF( nn_timing == 1 )  CALL timing_start('iom_put2')
 #if defined key_iomput
       CALL event__write_field2D( cdname, pfield2d(nldi:nlei, nldj:nlej) )
@@ -986,4 +994,5 @@
       IF( .FALSE. )   WRITE(numout,*) cdname, pfield2d   ! useless test to avoid compilation warnings
 #endif
+      IF( nn_timing == 1 )  CALL timing_stop('iom_put2')
    END SUBROUTINE iom_p2d
 
@@ -991,4 +1000,5 @@
       CHARACTER(LEN=*)                , INTENT(in) ::   cdname
       REAL(wp),       DIMENSION(:,:,:), INTENT(in) ::   pfield3d
+      IF( nn_timing == 1 )  CALL timing_start('iom_put3')
 #if defined key_iomput
       CALL event__write_field3D( cdname, pfield3d(nldi:nlei, nldj:nlej, :) )
@@ -996,4 +1006,5 @@
       IF( .FALSE. )   WRITE(numout,*) cdname, pfield3d   ! useless test to avoid compilation warnings
 #endif
+      IF( nn_timing == 1 )  CALL timing_stop('iom_put3')
    END SUBROUTINE iom_p3d
    !!----------------------------------------------------------------------
@@ -1070,4 +1081,6 @@
       CALL event__set_attribut( 'field_definition', attr( field__freq_op, idt           ) )    ! model time-step
       CALL event__set_attribut( 'SBC'             , attr( field__freq_op, idt * nn_fsbc ) )    ! SBC time-step
+ !SF 
+      CALL event__set_attribut( 'scalar_SBC'      , attr( field__freq_op, idt * nn_fsbc ) )    ! SBC time-step
       
       ! output file names (attribut: name)
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 3938)
@@ -181,5 +181,5 @@
 
 
-   FUNCTION iom_nf90_varid ( kiomid, cdvar, kiv, kdimsz )  
+   FUNCTION iom_nf90_varid ( kiomid, cdvar, kiv, kdimsz, kndims )  
       !!-----------------------------------------------------------------------
       !!                  ***  FUNCTION  iom_varid  ***
@@ -191,4 +191,5 @@
       INTEGER              , INTENT(in   )           ::   kiv   ! 
       INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
+      INTEGER,               INTENT(  out), OPTIONAL ::   kndims   ! size of the dimensions
       !
       INTEGER                        ::   iom_nf90_varid   ! iom variable Id
@@ -242,4 +243,5 @@
             ENDIF
          ENDIF
+         IF( PRESENT(kndims) )  kndims = iom_file(kiomid)%ndims(kiv)
       ELSE  
          iom_nf90_varid = -1   !   variable not found, return error code: -1
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 3938)
@@ -362,5 +362,5 @@
 
 
-   SUBROUTINE mpp_lnk_3d( ptab, cd_type, psgn, cd_mpp, pval )
+   SUBROUTINE mpp_lnk_3d( ptab, cd_type, psgn, cd_mpp, pval, ldup )
       !!----------------------------------------------------------------------
       !!                  ***  routine mpp_lnk_3d  ***
@@ -390,4 +390,5 @@
       CHARACTER(len=3), OPTIONAL      , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only 
       REAL(wp)        , OPTIONAL      , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
+      LOGICAL         , OPTIONAL      , INTENT(in   ) ::   ldup     ! duplicate value (used at closed boundaries)
       !!
       INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
@@ -427,4 +428,10 @@
             ptab( 1 ,:,:) = ptab(jpim1,:,:)
             ptab(jpi,:,:) = ptab(  2  ,:,:)
+         ELSEIF ( nperio == 0 .AND. PRESENT( ldup ) ) THEN
+            ptab(3,:,:) = ptab(2,:,:)
+            ptab(:,3,:) = ptab(:,2,:)
+            ptab(nlci-2,:,:) = ptab(nlci-1,:,:)
+            ptab(:,nlcj-2,:) = ptab(:,nlcj-1,:)
+           
          ELSE                                     !* closed
             IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
@@ -559,5 +566,5 @@
 
 
-   SUBROUTINE mpp_lnk_2d( pt2d, cd_type, psgn, cd_mpp, pval )
+   SUBROUTINE mpp_lnk_2d( pt2d, cd_type, psgn, cd_mpp, pval, ldup )
       !!----------------------------------------------------------------------
       !!                  ***  routine mpp_lnk_2d  ***
@@ -585,4 +592,5 @@
       CHARACTER(len=3), OPTIONAL  , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only 
       REAL(wp)        , OPTIONAL  , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
+      LOGICAL         , OPTIONAL  , INTENT(in   ) ::   ldup     ! duplicate value (used at closed boundaries)
       !!
       INTEGER  ::   ji, jj, jl   ! dummy loop indices
@@ -621,4 +629,9 @@
             pt2d( 1 ,:) = pt2d(jpim1,:)                                    ! west
             pt2d(jpi,:) = pt2d(  2  ,:)                                    ! east
+         ELSEIF ( nperio == 0 .AND. PRESENT( ldup ) ) THEN
+            pt2d(3,:) = pt2d(2,:)
+            pt2d(:,3) = pt2d(:,2)
+            pt2d(nlci-2,:) = pt2d(nlci-1,:)
+            pt2d(:,nlcj-2) = pt2d(:,nlcj-1)
          ELSE                                     ! closed
             IF( .NOT. cd_type == 'F' )   pt2d(     1       :jpreci,:) = zland    ! south except F-point
@@ -2011,4 +2024,10 @@
       CALL MPI_ALLREDUCE( kice, zwork, jpnij, mpi_integer, mpi_sum, mpi_comm_opa, ierr )
       ndim_rank_ice = SUM( zwork )          
+ 
+      !SF ! if there is no ice in the domain, return to the main program (clem modif)
+     !SF  IF ( ndim_rank_ice == 0 ) THEN
+      !SF    DEALLOCATE(kice, zwork)
+     !SF     RETURN
+     !SF  ENDIF
 
       ! Allocate the right size to nrank_north
@@ -2027,5 +2046,5 @@
       ! Create the world group
       CALL MPI_COMM_GROUP( mpi_comm_opa, ngrp_world, ierr )
-
+ 
       ! Create the ice group from the world group
       CALL MPI_GROUP_INCL( ngrp_world, ndim_rank_ice, nrank_ice, ngrp_ice, ierr )
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn_c3d.h90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn_c3d.h90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn_c3d.h90	(revision 3938)
@@ -35,5 +35,8 @@
       REAL(wp) ::   zd_max       ! maximum grid spacing over the global domain
       REAL(wp) ::   za00, zc, zd, zetmax, zefmax, zeumax, zevmax   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:) :: zcoef   
+      REAL(wp), POINTER, DIMENSION(:)   :: zcoef   
+      INTEGER,  PARAMETER               :: zrim = 5  ! number of grid points over which diffusion is increased linearly
+      REAL(wp), PARAMETER               :: zinc_coef = 0.0 ! coef of diffusion increase  
+      INTEGER  ::   ii0, ii1, ij0, ij1   ! temporary integers
       !!----------------------------------------------------------------------
       !
@@ -88,17 +91,17 @@
             CALL ldf_dyn_c3d_orca( ld_print )
          ENDIF
-
-      ENDIF
-      
-      ! Control print
-      IF(lwp .AND. ld_print ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) '         3D ahm1 array (k=1)'
-         CALL prihre( ahm1(:,:,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1.e-3, numout )
-         WRITE(numout,*)
-         WRITE(numout,*) '         3D ahm2 array (k=1)'
-         CALL prihre( ahm2(:,:,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1.e-3, numout )
-      ENDIF
-
+	 
+      	 ! Control print
+         IF(lwp .AND. ld_print ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) '         3D ahm1 array (k=1)'
+            CALL prihre( ahm1(:,:,1), jpi, jpj, 1, jpi, 1, 1, jpj, 1, 1.e-3, numout )
+            WRITE(numout,*)
+            WRITE(numout,*) '         3D ahm2 array (k=1)'
+            CALL prihre( ahm2(:,:,1), jpi, jpj, 1, jpi, 1, 1, jpj, 1, 1.e-3, numout )
+         ENDIF
+
+      ENDIF
+      
 
       ! ahm3 and ahm4 at U- and V-points (used for bilaplacian operator
@@ -172,8 +175,8 @@
             WRITE(numout,*)
             WRITE(numout,*) 'inildf: ahm3 array at level 1'
-            CALL prihre(ahm3(:,:,1  ),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+            CALL prihre(ahm3(:,:,1  ),jpi,jpj,1,jpi,1,1,jpj,1,1.e-12,numout)
             WRITE(numout,*)
             WRITE(numout,*) 'inildf: ahm4 array at level 1'
-            CALL prihre(ahm4(:,:,jpk),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+            CALL prihre(ahm4(:,:,jpk),jpi,jpj,1,jpi,1,1,jpj,1,1.e-12,numout)
          ENDIF
       ENDIF
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/LDF/ldfslp.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/LDF/ldfslp.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/LDF/ldfslp.F90	(revision 3938)
@@ -33,4 +33,6 @@
    USE wrk_nemo        ! work arrays
    USE timing          ! Timing
+   USE lib_fortran     ! to use key_nosignedzero
+ 
 
    IMPLICIT NONE
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90	(revision 3938)
@@ -9,4 +9,5 @@
    !!             -   ! 2010-11  (G. Madec) ice-ocean stress always computed at each ocean time-step
    !!            3.3  ! 2010-10  (J. Chanut, C. Bricaud)  add the surface pressure forcing
+   !!            4.0  ! 2012-05  (C. Rousset) add attenuation coef for use in ice model 
    !!----------------------------------------------------------------------
 
@@ -68,4 +69,6 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  qsr_hc , qsr_hc_b   !: heat content trend due to qsr flux     [K.m/s] jpi,jpj,jpk
    !!
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   oatte, iatte      !: clem attenuation coef of the input solar flux [unitless]
+   !!
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tprecip           !: total precipitation                          [Kg/m2/s]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sprecip           !: solid precipitation                          [Kg/m2/s]
@@ -111,5 +114,6 @@
          !
       ALLOCATE( rnf  (jpi,jpj) , sbc_tsc  (jpi,jpj,jpts) , qsr_hc  (jpi,jpj,jpk) ,     &
-         &      rnf_b(jpi,jpj) , sbc_tsc_b(jpi,jpj,jpts) , qsr_hc_b(jpi,jpj,jpk) , STAT=ierr(3) )
+         &      rnf_b(jpi,jpj) , sbc_tsc_b(jpi,jpj,jpts) , qsr_hc_b(jpi,jpj,jpk) ,     &
+         &      iatte(jpi,jpj) , oatte    (jpi,jpj)                              , STAT=ierr(3) )
          !
       ALLOCATE( tprecip(jpi,jpj) , sprecip(jpi,jpj) , fr_i(jpi,jpj) ,     &
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 3938)
@@ -68,5 +68,6 @@
    REAL(wp), PARAMETER ::   Ls   =    2.839e6     ! latent heat of sublimation
    REAL(wp), PARAMETER ::   Stef =    5.67e-8     ! Stefan Boltzmann constant
-   REAL(wp), PARAMETER ::   Cice =    1.63e-3     ! transfer coefficient over ice
+   !iovi REAL(wp), PARAMETER ::   Cice =    1.63e-3     ! transfer coefficient over ice
+   REAL(wp), PARAMETER ::   Cice =    1.4e-3      ! transfer coefficient over ice
    REAL(wp), PARAMETER ::   albo =    0.066       ! ocean albedo assumed to be contant
 
@@ -75,4 +76,6 @@
    LOGICAL  ::   ln_taudif = .FALSE.   ! logical flag to use the "mean of stress module - module of mean stress" data
    REAL(wp) ::   rn_pfac   = 1.        ! multiplication factor for precipitation
+   REAL(wp) ::   rn_efac   = 1.        ! multiplication factor for evaporation (clem)
+   REAL(wp) ::   rn_vfac   = 1.        ! multiplication factor for ice/ocean velocity in the calculation of wind stress (clem)
 
    !! * Substitutions
@@ -128,5 +131,5 @@
       TYPE(FLD_N) ::   sn_qlw , sn_tair, sn_prec, sn_snow      !   "                                 "
       TYPE(FLD_N) ::   sn_tdif                                 !   "                                 "
-      NAMELIST/namsbc_core/ cn_dir , ln_2m  , ln_taudif, rn_pfac,           &
+      NAMELIST/namsbc_core/ cn_dir , ln_2m  , ln_taudif, rn_pfac, rn_efac, rn_vfac,  &
          &                  sn_wndi, sn_wndj, sn_humi  , sn_qsr ,           &
          &                  sn_qlw , sn_tair, sn_prec  , sn_snow, sn_tdif
@@ -266,6 +269,6 @@
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vect. opt.
-            zwnd_i(ji,jj) = (  sf(jp_wndi)%fnow(ji,jj,1) - 0.5 * ( pu(ji-1,jj  ) + pu(ji,jj) )  )
-            zwnd_j(ji,jj) = (  sf(jp_wndj)%fnow(ji,jj,1) - 0.5 * ( pv(ji  ,jj-1) + pv(ji,jj) )  )
+            zwnd_i(ji,jj) = (  sf(jp_wndi)%fnow(ji,jj,1) - rn_vfac * 0.5 * ( pu(ji-1,jj  ) + pu(ji,jj) )  )
+            zwnd_j(ji,jj) = (  sf(jp_wndj)%fnow(ji,jj,1) - rn_vfac * 0.5 * ( pv(ji  ,jj-1) + pv(ji,jj) )  )
          END DO
       END DO
@@ -351,11 +354,11 @@
       IF( ln_2m ) THEN
          ! Values of temp. and hum. adjusted to 10m must be used instead of 2m values
-         zevap(:,:) = MAX( 0.e0, rhoa    *Ce(:,:)*( zqsatw(:,:) - zq_zu(:,:) ) * wndm(:,:) )   ! Evaporation
-         zqsb (:,:) =            rhoa*cpa*Ch(:,:)*( zst   (:,:) - zt_zu(:,:) ) * wndm(:,:)     ! Sensible Heat
+         zevap(:,:) = rn_efac * MAX( 0.e0, rhoa    *Ce(:,:)*( zqsatw(:,:) - zq_zu(:,:) ) * wndm(:,:) )   ! Evaporation
+         zqsb (:,:) =                      rhoa*cpa*Ch(:,:)*( zst   (:,:) - zt_zu(:,:) ) * wndm(:,:)     ! Sensible Heat
       ELSE
 !CDIR COLLAPSE
-         zevap(:,:) = MAX( 0.e0, rhoa    *Ce(:,:)*( zqsatw(:,:) - sf(jp_humi)%fnow(:,:,1) ) * wndm(:,:) )   ! Evaporation
-!CDIR COLLAPSE
-         zqsb (:,:) =            rhoa*cpa*Ch(:,:)*( zst   (:,:) - sf(jp_tair)%fnow(:,:,1) ) * wndm(:,:)     ! Sensible Heat
+         zevap(:,:) = rn_efac * MAX( 0.e0, rhoa    *Ce(:,:)*( zqsatw(:,:) - sf(jp_humi)%fnow(:,:,1) ) * wndm(:,:) )   ! Evaporation
+!CDIR COLLAPSE
+         zqsb (:,:) =                      rhoa*cpa*Ch(:,:)*( zst   (:,:) - sf(jp_tair)%fnow(:,:,1) ) * wndm(:,:)     ! Sensible Heat
       ENDIF
 !CDIR COLLAPSE
@@ -491,7 +494,7 @@
                ! ... scalar wind at I-point (fld being at T-point)
                zwndi_f = 0.25 * (  sf(jp_wndi)%fnow(ji-1,jj  ,1) + sf(jp_wndi)%fnow(ji  ,jj  ,1)   &
-                  &              + sf(jp_wndi)%fnow(ji-1,jj-1,1) + sf(jp_wndi)%fnow(ji  ,jj-1,1)  ) - pui(ji,jj)
+                  &              + sf(jp_wndi)%fnow(ji-1,jj-1,1) + sf(jp_wndi)%fnow(ji  ,jj-1,1)  ) - rn_vfac * pui(ji,jj)
                zwndj_f = 0.25 * (  sf(jp_wndj)%fnow(ji-1,jj  ,1) + sf(jp_wndj)%fnow(ji  ,jj  ,1)   &
-                  &              + sf(jp_wndj)%fnow(ji-1,jj-1,1) + sf(jp_wndj)%fnow(ji  ,jj-1,1)  ) - pvi(ji,jj)
+                  &              + sf(jp_wndj)%fnow(ji-1,jj-1,1) + sf(jp_wndj)%fnow(ji  ,jj-1,1)  ) - rn_vfac * pvi(ji,jj)
                zwnorm_f = zcoef_wnorm * SQRT( zwndi_f * zwndi_f + zwndj_f * zwndj_f )
                ! ... ice stress at I-point
@@ -499,8 +502,8 @@
                p_tauj(ji,jj) = zwnorm_f * zwndj_f
                ! ... scalar wind at T-point (fld being at T-point)
-               zwndi_t = sf(jp_wndi)%fnow(ji,jj,1) - 0.25 * (  pui(ji,jj+1) + pui(ji+1,jj+1)   &
-                  &                                          + pui(ji,jj  ) + pui(ji+1,jj  )  )
-               zwndj_t = sf(jp_wndj)%fnow(ji,jj,1) - 0.25 * (  pvi(ji,jj+1) + pvi(ji+1,jj+1)   &
-                  &                                          + pvi(ji,jj  ) + pvi(ji+1,jj  )  )
+               zwndi_t = sf(jp_wndi)%fnow(ji,jj,1) - rn_vfac * 0.25 * (  pui(ji,jj+1) + pui(ji+1,jj+1)   &
+                  &                                                    + pui(ji,jj  ) + pui(ji+1,jj  )  )
+               zwndj_t = sf(jp_wndj)%fnow(ji,jj,1) - rn_vfac * 0.25 * (  pvi(ji,jj+1) + pvi(ji+1,jj+1)   &
+                  &                                                    + pvi(ji,jj  ) + pvi(ji+1,jj  )  )
                z_wnds_t(ji,jj)  = SQRT( zwndi_t * zwndi_t + zwndj_t * zwndj_t ) * tmask(ji,jj,1)
             END DO
@@ -516,6 +519,6 @@
          DO jj = 2, jpj
             DO ji = fs_2, jpi   ! vect. opt.
-               zwndi_t = (  sf(jp_wndi)%fnow(ji,jj,1) - 0.5 * ( pui(ji-1,jj  ) + pui(ji,jj) )  )
-               zwndj_t = (  sf(jp_wndj)%fnow(ji,jj,1) - 0.5 * ( pvi(ji  ,jj-1) + pvi(ji,jj) )  )
+               zwndi_t = (  sf(jp_wndi)%fnow(ji,jj,1) - rn_vfac * 0.5 * ( pui(ji-1,jj  ) + pui(ji,jj) )  )
+               zwndj_t = (  sf(jp_wndj)%fnow(ji,jj,1) - rn_vfac * 0.5 * ( pvi(ji  ,jj-1) + pvi(ji,jj) )  )
                z_wnds_t(ji,jj)  = SQRT( zwndi_t * zwndi_t + zwndj_t * zwndj_t ) * tmask(ji,jj,1)
             END DO
@@ -555,5 +558,10 @@
                p_qsr(ji,jj,jl) = zztmp * ( 1. - palb(ji,jj,jl) ) * qsr(ji,jj)
                ! Long  Wave (lw)
-               z_qlw(ji,jj,jl) = 0.95 * (  sf(jp_qlw)%fnow(ji,jj,1) - Stef * pst(ji,jj,jl) * zst3  ) * tmask(ji,jj,1)
+               ! iovino
+               IF( ff(ji,jj) .GT. 0._wp ) THEN
+                  z_qlw(ji,jj,jl) = ( 0.95 * sf(jp_qlw)%fnow(ji,jj,1) - Stef * pst(ji,jj,jl) * zst3 ) * tmask(ji,jj,1) ! MV test 2 garde juste cette ligne ci
+               ELSE
+                  z_qlw(ji,jj,jl) = 0.95 * ( sf(jp_qlw)%fnow(ji,jj,1) - Stef * pst(ji,jj,jl) * zst3 ) * tmask(ji,jj,1) ! MV test 1 garde juste cette ligne ci
+               ENDIF
                ! lw sensitivity
                z_dqlw(ji,jj,jl) = zcoef_dqlw * zst3                                               
@@ -567,11 +575,12 @@
                z_qsb(ji,jj,jl) = rhoa * cpa * Cice * z_wnds_t(ji,jj) * ( pst(ji,jj,jl) - sf(jp_tair)%fnow(ji,jj,1) )
                ! Latent Heat
-               p_qla(ji,jj,jl) = MAX( 0.e0, rhoa * Ls  * Cice * z_wnds_t(ji,jj)   &                           
-                  &                    * (  11637800. * EXP( -5897.8 / pst(ji,jj,jl) ) / rhoa - sf(jp_humi)%fnow(ji,jj,1)  ) )
+               p_qla(ji,jj,jl) = rn_efac * MAX( 0.e0, rhoa * Ls  * Cice * z_wnds_t(ji,jj)   &                           
+                  &                         * (  11637800. * EXP( -5897.8 / pst(ji,jj,jl) ) / rhoa - sf(jp_humi)%fnow(ji,jj,1)  ) )
                ! Latent heat sensitivity for ice (Dqla/Dt)
-               p_dqla(ji,jj,jl) = zcoef_dqla * z_wnds_t(ji,jj) / ( zst2 ) * EXP( -5897.8 / pst(ji,jj,jl) )
+               p_dqla(ji,jj,jl) = rn_efac * zcoef_dqla * z_wnds_t(ji,jj) / ( zst2 ) * EXP( -5897.8 / pst(ji,jj,jl) )
                ! Sensible heat sensitivity (Dqsb_ice/Dtn_ice)
                z_dqsb(ji,jj,jl) = zcoef_dqsb * z_wnds_t(ji,jj)
-
+               !
+               !
                ! ----------------------------!
                !     III    Total FLUXES     !
@@ -601,5 +610,6 @@
 !CDIR COLLAPSE
       p_spr(:,:) = sf(jp_snow)%fnow(:,:,1) * rn_pfac      ! solid precipitation [kg/m2/s]
-      CALL iom_put( 'snowpre', p_spr )                  ! Snow precipitation 
+      CALL iom_put( 'snowpre', p_spr * 86400 )                  ! Snow precipitation 
+      CALL iom_put( 'precip', p_tpr * 86400 )                   ! Total precipitation 
       !
       IF(ln_ctl) THEN
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90	(revision 3938)
@@ -97,5 +97,6 @@
             z_fwf = glob_sum( e1e2t(:,:) * ( emp(:,:) - rnf(:,:) ) ) / area   ! sum over the global domain
             emp (:,:) = emp (:,:) - z_fwf 
-            emps(:,:) = emps(:,:) - z_fwf 
+            erp (:,:) = erp (:,:) - z_fwf 
+!SF bad            emps(:,:) = emps(:,:) - z_fwf 
          ENDIF
          !
@@ -127,5 +128,6 @@
          IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN      ! correct the freshwater fluxes
             emp (:,:) = emp (:,:) + fwfold
-            emps(:,:) = emps(:,:) + fwfold
+            erp (:,:) = erp (:,:) + fwfold
+!SF bad            emps(:,:) = emps(:,:) + fwfold
          ENDIF
          !
@@ -169,5 +171,5 @@
             !
             emp (:,:) = emp (:,:) + zerp_cor(:,:)
-            emps(:,:) = emps(:,:) + zerp_cor(:,:)
+!SF bad            emps(:,:) = emps(:,:) + zerp_cor(:,:)
             erp (:,:) = erp (:,:) + zerp_cor(:,:)
             !
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 3938)
@@ -11,4 +11,5 @@
    !!            3.3  ! 2010-11  (G. Madec) ice-ocean stress always computed at each ocean time-step
    !!            4.0  ! 2011-01  (A Porter)  dynamical allocation
+   !!             -   ! 2012-10  (C. Rousset)  add lim_diahsb
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -42,7 +43,10 @@
    USE limsbc          ! sea surface boundary condition
    USE limdia          ! Ice diagnostics
+   USE limdiahsb       ! Ice budget diagnostics
    USE limwri          ! Ice outputs
    USE limrst          ! Ice restarts
-   USE limupdate       ! update of global variables
+!clem@order   USE limupdate       ! update of global variables
+   USE limupdate1       ! update of global variables
+   USE limupdate2       ! update of global variables
    USE limvar          ! Ice variables switch
 
@@ -51,7 +55,12 @@
    USE lib_mpp         ! MPP library
    USE wrk_nemo        ! work arrays
+   USE timing          ! Timing
    USE iom             ! I/O manager library
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
+
+#if defined key_bdy 
+   USE bdyice_lim       ! unstructured open boundary data  (bdy_ice_lim routine)
+#endif
 
    IMPLICIT NONE
@@ -98,4 +107,6 @@
       !!----------------------------------------------------------------------
 
+      IF( nn_timing == 1 )  CALL timing_start('sbc_ice_lim')
+
       CALL wrk_alloc( jpi,jpj,jpl, zalb_ice_os, zalb_ice_cs )
 
@@ -108,5 +119,7 @@
          !
          IF( ln_nicep ) THEN      ! control print at a given point
-            jiindx = 44   ;   jjindx = 140
+            !jiindx = 3   ;   jjindx = 51
+            !jiindx = 34   ;   jjindx = 45
+            jiindx = 117   ;   jjindx = 116
             WRITE(numout,*) ' The debugging point is : jiindx : ',jiindx, ' jjindx : ',jjindx
          ENDIF
@@ -153,4 +166,7 @@
          END SELECT
 
+         CALL iom_put( 'utau_ice', utau_ice )     ! Wind stress over ice along i-axis at I-point
+         CALL iom_put( 'vtau_ice', vtau_ice )     ! Wind stress over ice along j-axis at I-point
+
          !                                           !----------------------!
          !                                           ! LIM-3  time-stepping !
@@ -178,18 +194,38 @@
          d_oa_i_thd (:,:,:)   = 0.e0   ;   d_oa_i_trp (:,:,:)   = 0.e0
          !
-         fseqv    (:,:) = 0.e0
-         fsbri    (:,:) = 0.e0     ;   fsalt_res(:,:) = 0.e0
+         !clem fseqv    (:,:) = 0.e0
+         !clem fsbri    (:,:) = 0.e0
+         fsalt_res(:,:) = 0.e0
          fsalt_rpo(:,:) = 0.e0
-         fhmec    (:,:) = 0.e0     ;   fhbri    (:,:) = 0.e0
-         fmmec    (:,:) = 0.e0     ;   fheat_res(:,:) = 0.e0
-         fheat_rpo(:,:) = 0.e0     ;   focea2D  (:,:) = 0.e0
+         fhmec    (:,:) = 0.e0
+         !clem fhbri    (:,:) = 0.e0
+         fmmec    (:,:) = 0.e0
+         fheat_res(:,:) = 0.e0
+         fheat_rpo(:,:) = 0.e0
+         focea2D  (:,:) = 0.e0
          fsup2D   (:,:) = 0.e0
-         ! 
+
+         ! clem: moved from limthd.F90 
+         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
+         !
          diag_sni_gr(:,:) = 0.e0   ;   diag_lat_gr(:,:) = 0.e0
          diag_bot_gr(:,:) = 0.e0   ;   diag_dyn_gr(:,:) = 0.e0
          diag_bot_me(:,:) = 0.e0   ;   diag_sur_me(:,:) = 0.e0
+         diag_res_pr(:,:) = 0.e0   ;   diag_trp_vi(:,:) = 0.e0
          ! dynamical invariants
          delta_i(:,:) = 0.e0       ;   divu_i(:,:) = 0.e0       ;   shear_i(:,:) = 0.e0
-
+         !
                           CALL lim_rst_opn( kt )     ! Open Ice restart file
          !
@@ -200,9 +236,23 @@
                           CALL lim_dyn( kt )              ! Ice dynamics    ( rheology/dynamics )
                           CALL lim_trp( kt )              ! Ice transport   ( Advection/diffusion )
-                          CALL lim_var_agg(1)             ! aggregate categories, requested
+                          !clem(done in trp wo ato_i) CALL lim_var_agg(1)             ! aggregate categories, requested
                           CALL lim_var_glo2eqv            ! equivalent variables, requested for rafting
          IF( ln_nicep )   CALL lim_prt_state( jiindx, jjindx,-1, ' - ice dyn & trp - ' )   ! control print
                           CALL lim_itd_me                 ! Mechanical redistribution ! (ridging/rafting)
+                          CALL lim_var_agg( 1 ) ! clem@order
+                          CALL lim_update1  ! clem@order
          ENDIF
+!                          !- Change old values for new values
+!clem@order
+                          old_u_ice(:,:)   = u_ice (:,:)
+                          old_v_ice(:,:)   = v_ice (:,:)
+                          old_a_i(:,:,:)   = a_i (:,:,:)
+                          old_v_s(:,:,:)   = v_s (:,:,:)
+                          old_v_i(:,:,:)   = v_i (:,:,:)
+                          old_e_s(:,:,:,:) = e_s (:,:,:,:)
+                          old_e_i(:,:,:,:) = e_i (:,:,:,:)
+                          old_oa_i(:,:,:)  = oa_i(:,:,:)
+                          old_smv_i(:,:,:) = smv_i (:,:,:)
+!clem@order
          !                                           ! Ice thermodynamics 
                           CALL lim_var_glo2eqv            ! equivalent variables
@@ -218,5 +268,10 @@
          !                                           ! Global variables update
                           CALL lim_var_agg( 1 )           ! requested by limupdate
-                          CALL lim_update                 ! Global variables update
+                          !clem@order CALL lim_update                 ! Global variables update
+                          CALL lim_update2  ! clem@order
+!
+#if defined key_bdy
+                          CALL bdy_ice_lim( kt )          ! clem modif: bdy ice
+#endif
                           CALL lim_var_glo2eqv            ! equivalent variables (outputs)
                           CALL lim_var_agg(2)             ! aggregate ice thickness categories
@@ -230,5 +285,7 @@
          IF( ( MOD( kt+nn_fsbc-1, ninfo ) == 0 .OR. ntmoy == 1 ) .AND. .NOT. lk_mpp )   &
             &             CALL lim_dia 
+        IF (ln_limdiahsb) CALL lim_diahsb
                           CALL lim_wri( 1  )              ! Ice outputs 
+         IF( kt == nit000 )   CALL iom_close( numrir )  ! clem: close input ice restart file
          IF( lrst_ice )   CALL lim_rst_write( kt )        ! Ice restart file 
                           CALL lim_var_glo2eqv            ! ???
@@ -236,5 +293,5 @@
          IF( ln_nicep )   CALL lim_ctl               ! alerts in case of model crash
          !
-      ENDIF                                    ! End sea-ice time step only
+     ENDIF                                    ! End sea-ice time step only
 
       !                                        !--------------------------!
@@ -249,4 +306,6 @@
       !
       CALL wrk_dealloc( jpi,jpj,jpl, zalb_ice_os, zalb_ice_cs )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('sbc_ice_lim')
       !
    END SUBROUTINE sbc_ice_lim
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90	(revision 3938)
@@ -48,4 +48,8 @@
    USE in_out_manager   ! I/O manager
    USE prtctl           ! Print control
+
+#if defined key_bdy 
+   USE bdyice_lim       ! unstructured open boundary data  (bdy_ice_lim routine)
+#endif
 
    IMPLICIT NONE
@@ -191,4 +195,7 @@
            IF( ln_limdmp ) CALL lim_dmp_2      ( kt )      ! Ice damping 
          END IF
+!#if defined key_bdy
+!                           CALL bdy_ice_lim    ( kt )      ! clem modif
+!#endif
 #if defined key_coupled
          !                                             ! Ice surface fluxes in coupled mode 
@@ -202,4 +209,7 @@
 #endif
                            CALL lim_thd_2      ( kt )      ! Ice thermodynamics 
+#if defined key_bdy
+                           CALL bdy_ice_lim    ( kt )      ! clem modif
+#endif
                            CALL lim_sbc_flx_2  ( kt )      ! update surface ocean mass, heat & salt fluxes 
 
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 3938)
@@ -12,4 +12,5 @@
    !!             -   ! 2010-10  (J. Chanut, C. Bricaud, G. Madec)  add the surface pressure forcing
    !!            3.4  ! 2011-11  (C. Harris) CICE added as an option
+   !!             -   ! 2012-01  (C. Rousset) add ice boundary conditions for LIM3
    !!----------------------------------------------------------------------
 
@@ -42,5 +43,5 @@
    USE closea           ! closed sea
    USE bdy_par          ! for lk_bdy
-   USE bdyice_lim2      ! unstructured open boundary data  (bdy_ice_lim_2 routine)
+   USE bdyice_lim       ! unstructured open boundary data  (bdy_ice_lim routine)
 
    USE prtctl           ! Print control                    (prt_ctl routine)
@@ -96,9 +97,9 @@
 
       !                          ! overwrite namelist parameter using CPP key information
-      IF( Agrif_Root() ) THEN                ! AGRIF zoom
-        IF( lk_lim2 )   nn_ice      = 2
-        IF( lk_lim3 )   nn_ice      = 3
-        IF( lk_cice )   nn_ice      = 4
-      ENDIF
+      !IF( Agrif_Root() ) THEN                ! AGRIF zoom
+      !  IF( lk_lim2 )   nn_ice      = 2
+      !  IF( lk_lim3 )   nn_ice      = 3
+      !  IF( lk_cice )   nn_ice      = 4
+      !ENDIF
       IF( cp_cfg == 'gyre' ) THEN            ! GYRE configuration
           ln_ana      = .TRUE.   
@@ -276,7 +277,8 @@
          !                                                      
       CASE(  2 )   ;       CALL sbc_ice_lim_2( kt, nsbc )            ! LIM-2 ice model
-         IF( lk_bdy )      CALL bdy_ice_lim_2( kt )                  ! BDY boundary condition
+         !IF( lk_bdy )      CALL bdy_ice_lim( kt )                   ! clem modif BDY boundary condition
          !                                                     
       CASE(  3 )   ;       CALL sbc_ice_lim  ( kt, nsbc )            ! LIM-3 ice model
+         !IF( lk_bdy )      CALL bdy_ice_lim( kt )                   ! clem modif BDY boundary condition
          !
       CASE(  4 )   ;       CALL sbc_ice_cice ( kt, nsbc )            ! CICE ice model
@@ -337,5 +339,6 @@
       IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN
          CALL iom_put( "empmr" , emp  - rnf )                   ! upward water flux
-         CALL iom_put( "empsmr", emps - rnf )                   ! c/d water flux
+!!sf     CALL iom_put( "empsmr", emps - rnf )                   ! c/d water flux
+         CALL iom_put( "empsmr", emps       )                   ! modif lim3 : salt flux
          CALL iom_put( "qt"    , qns  + qsr )                   ! total heat flux 
          CALL iom_put( "qns"   , qns        )                   ! solar heat flux
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssr.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssr.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssr.F90	(revision 3938)
@@ -22,4 +22,5 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE timing          ! Timing
+   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
 
    IMPLICIT NONE
@@ -174,13 +175,12 @@
                   DO ji = 1, jpi
                      zerp = zsrp * ( 1. - 2.*rnfmsk(ji,jj) )   &      ! No damping in vicinity of river mouths
-                        &        * ( sss_m(ji,jj) - sf_sss(1)%fnow(ji,jj,1) )   &
-                        &        / ( sss_m(ji,jj) + 1.e-20   )
+                        &        * ( sss_m(ji,jj) - sf_sss(1)%fnow(ji,jj,1) )   
                      emps(ji,jj) = emps(ji,jj) + zerp
-                     erp( ji,jj) = zerp
+                     erp (ji,jj) = zerp / MAX( sss_m(ji,jj), 1.e-20 ) ! converted into an equivalent volume flux (diagnostic only)
                   END DO
                END DO
                CALL iom_put( "erp", erp )                             ! freshwater flux damping
                !
-            ELSEIF( nn_sssr == 2 ) THEN               !* Salinity damping term (volume flux, emp and emps)
+            ELSEIF( nn_sssr == 2 ) THEN               !* Salinity damping term (volume flux, emp only)
                zsrp = rn_deds / rday                                  ! from [mm/day] to [kg/m2/s]
                zerp_bnd = rn_sssr_bnd / rday                          !       -              -    
@@ -190,9 +190,8 @@
                      zerp = zsrp * ( 1. - 2.*rnfmsk(ji,jj) )   &      ! No damping in vicinity of river mouths
                         &        * ( sss_m(ji,jj) - sf_sss(1)%fnow(ji,jj,1) )   &
-                        &        / ( sss_m(ji,jj) + 1.e-20   )
+                        &        / MAX(  sss_m(ji,jj), 1.e-20   )
                      IF( ln_sssr_bnd )   zerp = SIGN( 1., zerp ) * MIN( zerp_bnd, ABS(zerp) )
-                     emp (ji,jj) = emp (ji,jj) + zerp
-                     emps(ji,jj) = emps(ji,jj) + zerp
-                     erp (ji,jj) = zerp
+                     emp(ji,jj) = emp (ji,jj) + zerp
+                     erp(ji,jj) = zerp
                   END DO
                END DO
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90	(revision 3938)
@@ -16,4 +16,5 @@
   USE tide_mod
   USE iom
+  USE timing          ! Timing
 
   IMPLICIT NONE
@@ -58,4 +59,5 @@
     NAMELIST/nam_tide/ln_tide_pot,nb_harmo,clname,nn_tide
 
+    IF( nn_timing == 1 )  CALL timing_start('sbctide')
     IF ( kt == nit000 ) THEN
 
@@ -83,4 +85,5 @@
        CALL flush(numout)
     ENDIF
+ 
 
     ALLOCATE(ntide     (nb_harmo))
@@ -113,4 +116,6 @@
     IF (ln_tide_pot          ) CALL tide_init_potential
 
+    IF( nn_timing == 1 )  CALL timing_stop('sbctide')
+    !
   END SUBROUTINE sbc_tide
 
@@ -122,5 +127,4 @@
     INTEGER  :: ji,jj,jk
     REAL(wp) :: zcons,ztmp1,ztmp2,zlat,zlon
-
 
     DO jk=1,nb_harmo
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 3938)
@@ -10,4 +10,5 @@
    !!             -   !  2005-11  (G. Madec) zco, zps, sco coordinate
    !!            3.2  !  2009-04  (G. Madec & NEMO team) 
+   !!            4.0  !  2012-05  (C. Rousset) store attenuation coef for use in ice model 
    !!----------------------------------------------------------------------
 
@@ -44,4 +45,5 @@
    LOGICAL , PUBLIC ::   ln_qsr_2bd = .TRUE.    !: 2 band         light absorption flag
    LOGICAL , PUBLIC ::   ln_qsr_bio = .FALSE.   !: bio-model      light absorption flag
+   LOGICAL , PUBLIC ::   ln_qsr_ice = .TRUE.    !: light penetration for ice-model LIM3 (clem)
    INTEGER , PUBLIC ::   nn_chldta  = 0         !: use Chlorophyll data (=1) or not (=0)
    REAL(wp), PUBLIC ::   rn_abs     = 0.58_wp   !: fraction absorbed in the very near surface (RGB & 2 bands)
@@ -100,4 +102,5 @@
       REAL(wp) ::   zchl, zcoef, zfact   ! local scalars
       REAL(wp) ::   zc0, zc1, zc2, zc3   !    -         -
+      REAL(wp) ::   zzc0, zzc1, zzc2, zzc3   !    -         -
       REAL(wp) ::   zz0, zz1, z1_e3t     !    -         -
       REAL(wp), POINTER, DIMENSION(:,:  ) :: zekb, zekg, zekr
@@ -159,4 +162,15 @@
          END DO
          CALL iom_put( 'qsr3d', etot3 )   ! Shortwave Radiation 3D distribution
+         ! clem: store attenuation coefficient of the first ocean level
+         IF ( ln_qsr_ice ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF ( qsr(ji,jj) /= 0._wp ) THEN
+                     oatte(ji,jj) = ( qsr_hc(ji,jj,1) / ( ro0cpr * qsr(ji,jj) ) )
+                     iatte(ji,jj) = oatte(ji,jj)
+                  ENDIF
+               END DO
+            END DO
+         ENDIF
          !                                        ! ============================================== !
       ELSE                                        !  Ocean alone : 
@@ -217,4 +231,17 @@
                   END DO
                END DO
+               ! clem: store attenuation coefficient of the first ocean level
+               IF ( ln_qsr_ice ) THEN
+                  DO jj = 1, jpj
+                     DO ji = 1, jpi
+                        zzc0 = rn_abs * EXP( - fse3t(ji,jj,1) * xsi0r     )
+                        zzc1 = zcoef  * EXP( - fse3t(ji,jj,1) * zekb(ji,jj) )
+                        zzc2 = zcoef  * EXP( - fse3t(ji,jj,1) * zekg(ji,jj) )
+                        zzc3 = zcoef  * EXP( - fse3t(ji,jj,1) * zekr(ji,jj) )
+                        oatte(ji,jj) = ( 1.0 - ( zzc0 + zzc1 + zzc2  + zzc3  ) ) * tmask(ji,jj,2) 
+                        iatte(ji,jj) = ( 1.0 - ( zzc0 + zzc1 + zcoef + zcoef ) ) * tmask(ji,jj,2)
+                     END DO
+                  END DO
+               ENDIF
                !
                DO jk = 1, nksr                                        ! compute and add qsr trend to ta
@@ -228,5 +255,10 @@
                   qsr_hc(:,:,jk) =  etot3(:,:,jk) * qsr(:,:)
                END DO
-            ENDIF
+               ! clem: store attenuation coefficient of the first ocean level
+               IF ( ln_qsr_ice ) THEN
+                  oatte(:,:) = etot3(:,:,1) / ro0cpr
+                  iatte(:,:) = oatte(:,:)
+               ENDIF
+           ENDIF
 
          ENDIF
@@ -247,4 +279,15 @@
                   END DO
                END DO
+               ! clem: store attenuation coefficient of the first ocean level
+               IF ( ln_qsr_ice ) THEN
+                  DO jj = 1, jpj
+                     DO ji = 1, jpi
+                        zc0 = zz0 * EXP( -fsdepw(ji,jj,1)*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,1)*xsi1r )
+                        zc1 = zz0 * EXP( -fsdepw(ji,jj,2)*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,2)*xsi1r )
+                        oatte(ji,jj) = ( zc0*tmask(ji,jj,1) - zc1*tmask(ji,jj,2) ) / ro0cpr
+                        iatte(ji,jj) = oatte(ji,jj)
+                     END DO
+                  END DO
+               ENDIF
             ELSE                                               !* constant volume: coef. computed one for all
                DO jk = 1, nksr
@@ -255,4 +298,9 @@
                   END DO
                END DO
+               ! clem: store attenuation coefficient of the first ocean level
+               IF ( ln_qsr_ice ) THEN
+                  oatte(:,:) = etot3(:,:,1) / ro0cpr
+                  iatte(:,:) = oatte(:,:)
+               ENDIF
                !
             ENDIF
@@ -271,4 +319,15 @@
          !
       ENDIF
+      ! clem: store attenuation coefficient of the first ocean level
+      !IF (ln_traqsr) THEN
+      !   DO jj = 1, jpj
+      !      DO ji = 1, jpi
+      !         IF ( qsr(ji,jj) /= 0._wp ) THEN
+      !            oatte(ji,jj) = qsr_hc(ji,jj,1) / ( ro0cpr * qsr(ji,jj) )
+      !            iatte(ji,jj) = qsr_hc(ji,jj,1) / ( ro0cpr * qsr(ji,jj) )
+      !         ENDIF
+      !      END DO
+      !   END DO
+      !END IF
       !
       IF( lrst_oce ) THEN   !                  Write in the ocean restart file
@@ -279,5 +338,4 @@
          IF(lwp) WRITE(numout,*) '~~~~'
          CALL iom_rstput( kt, nitrst, numrow, 'qsr_hc_b', qsr_hc )
-         !
       ENDIF
 
@@ -326,5 +384,5 @@
       TYPE(FLD_N)        ::   sn_chl   ! informations about the chlorofyl field to be read
       !!
-      NAMELIST/namtra_qsr/  sn_chl, cn_dir, ln_traqsr, ln_qsr_rgb, ln_qsr_2bd, ln_qsr_bio,   &
+      NAMELIST/namtra_qsr/  sn_chl, cn_dir, ln_traqsr, ln_qsr_rgb, ln_qsr_2bd, ln_qsr_bio, ln_qsr_ice,  &
          &                  nn_chldta, rn_abs, rn_si0, rn_si1
       !!----------------------------------------------------------------------
@@ -333,8 +391,11 @@
       IF( nn_timing == 1 )  CALL timing_start('tra_qsr_init')
       !
+      ! clem init for oatte and iatte
+      oatte(:,:) = 1._wp
+      iatte(:,:) = 1._wp
+      !
       CALL wrk_alloc( jpi, jpj,      zekb, zekg, zekr        ) 
       CALL wrk_alloc( jpi, jpj, jpk, ze0, ze1, ze2, ze3, zea ) 
       !
-
       cn_dir = './'       ! directory in which the model is executed
       ! ... default values (NB: frequency positive => hours, negative => months)
@@ -355,4 +416,5 @@
          WRITE(numout,*) '      2 band               light penetration   ln_qsr_2bd = ', ln_qsr_2bd
          WRITE(numout,*) '      bio-model            light penetration   ln_qsr_bio = ', ln_qsr_bio
+         WRITE(numout,*) '      light penetration for ice-model LIM3     ln_qsr_ice = ', ln_qsr_ice
          WRITE(numout,*) '      RGB : Chl data (=1) or cst value (=0)    nn_chldta  = ', nn_chldta
          WRITE(numout,*) '      RGB & 2 bands: fraction of light (rn_si1)    rn_abs = ', rn_abs
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 3938)
@@ -169,5 +169,6 @@
                sbc_tsc(ji,jj,jp_tem) = ro0cpr * qns(ji,jj) - zsrau * emp(ji,jj) * tsn(ji,jj,1,jp_tem)
                ! concent./dilut. effect due to sea-ice melt/formation and (possibly) SSS restoration
-               sbc_tsc(ji,jj,jp_sal) = ( emps(ji,jj) - emp(ji,jj) ) * zsrau * tsn(ji,jj,1,jp_sal)
+               !sbc_tsc(ji,jj,jp_sal) = ( emps(ji,jj) - emp(ji,jj) ) * zsrau * tsn(ji,jj,1,jp_sal)
+               sbc_tsc(ji,jj,jp_sal) = emps(ji,jj) * zsrau  ! IOVINO + CLEM
             END DO
          END DO
@@ -178,5 +179,9 @@
                sbc_tsc(ji,jj,jp_tem) = ro0cpr * qns(ji,jj)
                ! salinity    : salt flux + concent./dilut. effect (both in emps)
-               sbc_tsc(ji,jj,jp_sal) = zsrau * emps(ji,jj) * tsn(ji,jj,1,jp_sal)
+#if defined key_lim3
+               sbc_tsc(ji,jj,jp_sal) = zsrau * emps(ji,jj) + zsrau * emp(ji,jj) * tsn(ji,jj,1,jp_sal) ! IOVINO
+#else
+               sbc_tsc(ji,jj,jp_sal) = zsrau * emps(ji,jj) * tsn(ji,jj,1,jp_sal) ! regular expression
+#endif
             END DO
          END DO
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 3938)
Index: /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 3937)
+++ /branches/2013/dev_r3406_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 3938)
@@ -234,7 +234,8 @@
                                CALL ssh_nxt( kstp )         ! sea surface height at next time step
 
-      IF( ln_diahsb        )   CALL dia_hsb( kstp )         ! - ML - global conservation diagnostics
+      IF( ln_diahsb        )   CALL dia_hsb( kstp )         ! global conservation diagnostics
       IF( lk_diaobs  )         CALL dia_obs( kstp )         ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
 
+      IF( lrst_oce .AND. ln_diahsb )   CALL dia_hsb_rst( kstp, 'WRITE' )
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Control and restarts
