Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/dom_ice_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/dom_ice_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/dom_ice_2.F90	(revision 2715)
@@ -15,8 +15,10 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-   USE par_ice_2
+   USE par_ice_2   ! LIM parameters
 
    IMPLICIT NONE
    PRIVATE
+
+   PUBLIC    dom_ice_alloc_2    ! Called from nemogcm.F90
 
    LOGICAL, PUBLIC ::   l_jeq     = .TRUE.     !: Equator inside the domain flag
@@ -25,18 +27,45 @@
       !                                        !  (otherwise = jpj+10 (SH) or -10 (SH) )
 
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)         ::   fs2cor , fcor     !: coriolis factor and coeficient
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)         ::   covrai            !: sine of geographic latitude
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)         ::   area              !: surface of grid cell 
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)         ::   tms    , tmu      !: temperature and velocity points masks
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,2,2)     ::   wght              !: weight of the 4 neighbours to compute averages
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   fs2cor , fcor     !: coriolis factor and coeficient
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   covrai            !: sine of geographic latitude
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   area              !: surface of grid cell 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   tms    , tmu      !: temperature and velocity points masks
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:)     ::   wght              !: weight of the 4 neighbours to compute averages
 
 
 # if defined key_lim2_vp
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,2,2)     ::   akappa , bkappa   !: first and third group of metric coefficients
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,2,2,2,2) ::   alambd            !: second group of metric coefficients
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:)     ::   akappa , bkappa   !: first and third group of metric coefficients
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:,:,:) ::   alambd            !: second group of metric coefficients
 # else
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)         ::   tmv    , tmf      !: y-velocity and F-points masks
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)         ::   tmi               !: ice mask: =1 if ice thick > 0
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   tmv    , tmf      !: y-velocity and F-points masks
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   tmi               !: ice mask: =1 if ice thick > 0
 # endif
+   !!----------------------------------------------------------------------
+   CONTAINS
+
+   INTEGER FUNCTION dom_ice_alloc_2()
+      !!----------------------------------------------------------------------
+      USE lib_mpp, ONLY:   ctl_warn   ! MPP library
+      INTEGER :: ierr(2)
+      !!----------------------------------------------------------------------
+      ierr(:) = 0
+      !
+      ALLOCATE( fs2cor(jpi,jpj)     , fcor(jpi,jpj) ,                                   &
+         &      covrai(jpi,jpj)     , area(jpi,jpj) , tms(jpi,jpj) , tmu(jpi,jpj) ,     &
+         &      wght  (jpi,jpj,2,2)                                               , STAT=ierr(1) )
+         !
+      ALLOCATE(                                                    &
+#if defined key_lim2_vp 
+         &        akappa(jpi,jpj,2,2)     , bkappa(jpi,jpj,2,2),   &
+         &        alambd(jpi,jpj,2,2,2,2) ,                        &
+#else
+         &        tmv(jpi,jpj) , tmf(jpi,jpj) , tmi(jpi,jpj) ,     &
+#endif
+         &        STAT=ierr(2) )
+         !
+      dom_ice_alloc_2 = MAXVAL(ierr)
+      IF( dom_ice_alloc_2 /= 0 )   CALL ctl_warn('dom_ice_alloc_2: failed to allocate arrays')
+      !
+   END FUNCTION dom_ice_alloc_2
 
 #else
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/ice_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/ice_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/ice_2.F90	(revision 2715)
@@ -4,6 +4,7 @@
    !! Sea Ice physics:  diagnostics variables of ice defined in memory
    !!=====================================================================
-   !! History :  2.0  !  2003-08  (C. Ethe)  F90: Free form and module
-   !!            3.3  !  2009-05  (G.Garric) addition of the lim2_evp cas
+   !! History :  2.0  ! 2003-08  (C. Ethe)  F90: Free form and module
+   !!            3.3  ! 2009-05  (G.Garric) addition of the lim2_evp cas
+   !!            4.0  ! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
    !!----------------------------------------------------------------------
 #if defined key_lim2
@@ -11,9 +12,11 @@
    !!   'key_lim2' :                                  LIM 2.0 sea-ice model
    !!----------------------------------------------------------------------
-   USE par_ice_2          ! LIM sea-ice parameters
+   USE par_ice_2      ! LIM sea-ice parameters
 
    IMPLICIT NONE
    PRIVATE
    
+   PUBLIC    ice_alloc_2  !  Called in iceini_2.F90
+
    INTEGER , PUBLIC ::   numit     !: ice iteration index
    REAL(wp), PUBLIC ::   rdt_ice   !: ice time step
@@ -54,7 +57,7 @@
    REAL(wp), PUBLIC ::   pstarh                !: pstar / 2.0
 
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   ahiu , ahiv   !: hor. diffusivity coeff. at ocean U- and V-points (m2/s)
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   pahu , pahv   !: ice hor. eddy diffusivity coef. at ocean U- and V-points
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   ust2s         !: friction velocity
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ahiu , ahiv   !: hor. diffusivity coeff. at ocean U- and V-points (m2/s)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   pahu , pahv   !: ice hor. eddy diffusivity coef. at ocean U- and V-points
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ust2s         !: friction velocity
 
    !!* Ice Rheology
@@ -63,5 +66,5 @@
    LOGICAL , PUBLIC ::   lk_lim2_vp = .TRUE.               !: Visco-Plactic reology flag 
    !
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   hsnm , hicm   !: mean snow and ice thicknesses
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hsnm , hicm   !: mean snow and ice thicknesses
    !
 # else
@@ -69,56 +72,116 @@
    LOGICAL , PUBLIC::   lk_lim2_vp = .FALSE.               !: Visco-Plactic reology flag 
    !
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   stress1_i     !: first stress tensor element       
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   stress2_i     !: second stress tensor element
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   stress12_i    !: diagonal stress tensor element
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   delta_i       !: rheology delta factor (see Flato and Hibler 95) [s-1]
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   divu_i        !: Divergence of the velocity field [s-1] -> limrhg.F90
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   shear_i       !: Shear of the velocity field [s-1] -> limrhg.F90
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   at_i          !: ice fraction
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   stress1_i     !: first stress tensor element       
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   stress2_i     !: second stress tensor element
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   stress12_i    !: diagonal stress tensor element
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   delta_i       !: rheology delta factor (see Flato and Hibler 95) [s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   divu_i        !: Divergence of the velocity field [s-1] -> limrhg.F90
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   shear_i       !: Shear of the velocity field [s-1] -> limrhg.F90
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   at_i          !: ice fraction
    !
    REAL(wp), PUBLIC, DIMENSION(:,:)    , POINTER :: vt_s ,vt_i    !: mean snow and ice thicknesses
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj), TARGET  :: hsnm , hicm   !: target vt_s,vt_i pointers 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:), TARGET  :: hsnm , hicm   !: target vt_s,vt_i pointers 
 #endif
 
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   rdvosif       !: ice volume change at ice surface (only used for outputs)
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   rdvobif       !: ice volume change at ice bottom  (only used for outputs)
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   fdvolif       !: Total   ice volume change (only used for outputs)
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   rdvonif       !: Lateral ice volume change (only used for outputs)
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   sist          !: Sea-Ice Surface Temperature [Kelvin]
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   tfu           !: Freezing/Melting point temperature of sea water at SSS
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   hicif         !: Ice thickness
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   hsnif         !: Snow thickness
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   hicifp        !: Ice production/melting
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   frld          !: Leads fraction = 1-a/totalarea
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   phicif        !: ice thickness  at previous time 
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   pfrld         !: Leads fraction at previous time  
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   qstoif        !: Energy stored in the brine pockets
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   fbif          !: Heat flux at the ice base
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   rdmsnif       !: Variation of snow mass
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   rdmicif       !: Variation of ice mass
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   qldif         !: heat balance of the lead (or of the open ocean)
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   qcmif         !: Energy needed to freeze the ocean surface layer
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   fdtcn         !: net downward heat flux from the ice to the ocean
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   qdtcn         !: energy from the ice to the ocean point (at a factor 2)
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   thcm          !: part of the solar energy used in the lead heat budget
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   fstric        !: Solar flux transmitted trough the ice
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   ffltbif       !: linked with the max heat contained in brine pockets (?)
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   fscmbq        !: Linked with the solar flux below the ice (?)
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   fsbbq         !: Also linked with the solar flux below the ice (?)
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   qfvbq         !: used to store energy in case of toral lateral ablation (?)
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   dmgwi         !: Variation of the mass of snow ice
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   u_ice, v_ice  !: two components of the ice   velocity at I-point (m/s)
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   u_oce, v_oce  !: two components of the ocean velocity at I-point (m/s)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdvosif       !: ice volume change at ice surface (only used for outputs)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdvobif       !: ice volume change at ice bottom  (only used for outputs)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fdvolif       !: Total   ice volume change (only used for outputs)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rdvonif       !: Lateral ice volume change (only used for outputs)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sist          !: Sea-Ice Surface Temperature [Kelvin]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tfu           !: Freezing/Melting point temperature of sea water at SSS
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hicif         !: Ice thickness
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hsnif         !: Snow thickness
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hicifp        !: Ice production/melting
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   frld          !: Leads fraction = 1-a/totalarea
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   phicif        !: ice thickness  at previous time 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   pfrld         !: Leads fraction at previous time  
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qstoif        !: Energy stored in the brine pockets
+   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 freeze the ocean surface layer
+   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 point (at a factor 2)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   thcm          !: part of the solar energy used in the lead heat budget
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fstric        !: Solar flux transmitted trough the ice
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ffltbif       !: linked with the max heat contained in brine pockets (?)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fscmbq        !: Linked with the solar flux below the ice (?)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fsbbq         !: Also linked with the solar flux below the ice (?)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qfvbq         !: used to store energy in case of toral lateral ablation (?)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   dmgwi         !: Variation of the mass of snow ice
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   u_ice, v_ice  !: two components of the ice   velocity at I-point (m/s)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   u_oce, v_oce  !: two components of the ocean velocity at I-point (m/s)
 
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jplayersp1) ::   tbif  !: Temperature inside the ice/snow layer
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tbif  !: Temperature inside the ice/snow layer
 
    !!* moment used in the advection scheme
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   sxice, syice, sxxice, syyice, sxyice   !: for ice  volume
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   sxsn,  sysn,  sxxsn,  syysn,  sxysn    !: for snow volume
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   sxa,   sya,   sxxa,   syya,   sxya     !: for ice cover area
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   sxc0,  syc0,  sxxc0,  syyc0,  sxyc0    !: for heat content of snow
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   sxc1,  syc1,  sxxc1,  syyc1,  sxyc1    !: for heat content of 1st ice layer
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   sxc2,  syc2,  sxxc2,  syyc2,  sxyc2    !: for heat content of 2nd ice layer
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   sxst,  syst,  sxxst,  syyst,  sxyst    !: for heat content of brine pockets
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sxice, syice, sxxice, syyice, sxyice   !: for ice  volume
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sxsn,  sysn,  sxxsn,  syysn,  sxysn    !: for snow volume                  
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sxa,   sya,   sxxa,   syya,   sxya     !: for ice cover area               
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sxc0,  syc0,  sxxc0,  syyc0,  sxyc0    !: for heat content of snow         
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sxc1,  syc1,  sxxc1,  syyc1,  sxyc1    !: for heat content of 1st ice layer
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sxc2,  syc2,  sxxc2,  syyc2,  sxyc2    !: for heat content of 2nd ice layer
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sxst,  syst,  sxxst,  syyst,  sxyst    !: for heat content of brine pockets
+   !!----------------------------------------------------------------------
+   CONTAINS
+
+   INTEGER FUNCTION ice_alloc_2()
+      !!-----------------------------------------------------------------
+      !!               *** FUNCTION ice_alloc_2 ***
+      !!-----------------------------------------------------------------
+      USE lib_mpp, ONLY:   ctl_warn   ! MPP library
+      INTEGER :: ierr(9)              ! Local variables
+      !!-----------------------------------------------------------------
+      ierr(:) = 0
+      !
+      ALLOCATE( ahiu(jpi,jpj) , pahu(jpi,jpj) ,                      &
+         &      ahiv(jpi,jpj) , pahv(jpi,jpj) , ust2s(jpi,jpj) , STAT=ierr(1) )
+         !
+      !* Ice Rheology
+#if defined key_lim2_vp
+      ALLOCATE( hsnm(jpi,jpj) , hicm(jpi,jpj) , STAT=ierr(2) )
+#else
+      ALLOCATE( stress1_i (jpi,jpj) , delta_i(jpi,jpj) , at_i(jpi,jpj) ,     &
+                stress2_i (jpi,jpj) , divu_i (jpi,jpj) , hsnm(jpi,jpj) ,     &
+                stress12_i(jpi,jpj) , shear_i(jpi,jpj) , hicm(jpi,jpj) , STAT=ierr(2) )
+#endif
+      ALLOCATE( rdvosif(jpi,jpj) , rdvobif(jpi,jpj) ,                      &
+         &      fdvolif(jpi,jpj) , rdvonif(jpi,jpj) ,                      &
+         &      sist   (jpi,jpj) , tfu    (jpi,jpj) , hicif(jpi,jpj) ,     &
+         &      hsnif  (jpi,jpj) , hicifp (jpi,jpj) , frld (jpi,jpj) , STAT=ierr(3) )
+
+      ALLOCATE(phicif(jpi,jpj) , pfrld  (jpi,jpj) , qstoif (jpi,jpj) ,     &
+         &     fbif  (jpi,jpj) , rdmsnif(jpi,jpj) , rdmicif(jpi,jpj) ,     &
+         &     qldif (jpi,jpj) , qcmif  (jpi,jpj) , fdtcn  (jpi,jpj) ,     &
+         &     qdtcn (jpi,jpj) , thcm   (jpi,jpj)                    , STAT=ierr(4) )
+
+      ALLOCATE(fstric(jpi,jpj) , ffltbif(jpi,jpj) , fscmbq(jpi,jpj) ,     &
+         &     fsbbq (jpi,jpj) , qfvbq  (jpi,jpj) , dmgwi (jpi,jpj) ,     &
+         &     u_ice (jpi,jpj) , v_ice  (jpi,jpj) ,                       &
+         &     u_oce (jpi,jpj) , v_oce  (jpi,jpj) ,                       &
+         &     tbif  (jpi,jpj,jplayersp1)                           , STAT=ierr(5))
+
+      !* moment used in the advection scheme
+      ALLOCATE(sxice (jpi,jpj) , syice (jpi,jpj) , sxxice(jpi,jpj) ,     &
+         &     syyice(jpi,jpj) , sxyice(jpi,jpj) ,                       &
+         &     sxsn  (jpi,jpj) , sysn  (jpi,jpj) , sxxsn (jpi,jpj) ,     &
+         &     syysn (jpi,jpj) , sxysn (jpi,jpj)                   , STAT=ierr(6) )
+      ALLOCATE(sxa   (jpi,jpj) , sya   (jpi,jpj) , sxxa  (jpi,jpj) ,     &
+         &     syya  (jpi,jpj) , sxya  (jpi,jpj) ,                       & 
+         &     sxc0  (jpi,jpj) , syc0  (jpi,jpj) , sxxc0 (jpi,jpj) ,     &
+         &     syyc0 (jpi,jpj) , sxyc0 (jpi,jpj)                   , STAT=ierr(7))
+      ALLOCATE(sxc1  (jpi,jpj) , syc1  (jpi,jpj) , sxxc1 (jpi,jpj) ,     &
+         &     syyc1 (jpi,jpj) , sxyc1 (jpi,jpj) ,                       &
+         &     sxc2  (jpi,jpj) , syc2  (jpi,jpj) , sxxc2 (jpi,jpj) ,     &
+         &     syyc2 (jpi,jpj) , sxyc2 (jpi,jpj)                   , STAT=ierr(8))
+      ALLOCATE(sxst  (jpi,jpj) , syst  (jpi,jpj) , sxxst (jpi,jpj) ,     &
+         &     syyst (jpi,jpj) , sxyst (jpi,jpj)                   , STAT=ierr(9))
+         !
+      ice_alloc_2 = MAXVAL( ierr )
+      !
+      IF( ice_alloc_2 /= 0 )   CALL ctl_warn('ice_alloc_2: failed to allocate arrays')
+      !
+   END FUNCTION ice_alloc_2
 
 #else
@@ -127,6 +190,5 @@
    !!----------------------------------------------------------------------
 #endif
-
-   !!----------------------------------------------------------------------
+   !!-----------------------------------------------------------------
    !! NEMO/LIM2 3.3 , UCL - NEMO Consortium (2010)
    !! $Id$
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/iceini_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/iceini_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/iceini_2.F90	(revision 2715)
@@ -4,7 +4,8 @@
    !!   Sea-ice model : LIM 2.0 Sea ice model Initialization
    !!======================================================================
-   !! History :   1.0  !  02-08  (G. Madec)  F90: Free form and modules
-   !!             2.0  !  03-08  (C. Ethe)  add ice_run
-   !!             3.3  !  09-05  (G.Garric, C. Bricaud) addition of the lim2_evp case
+   !! History :  1.0  ! 2002-08  (G. Madec)  F90: Free form and modules
+   !!            2.0  ! 2003-08  (C. Ethe)  add ice_run
+   !!            3.3  ! 2009-05  (G. Garric, C. Bricaud) addition of the lim2_evp case
+   !!            4.0  ! 2011-02  (G. Madec) dynamical allocation
    !!----------------------------------------------------------------------
 #if defined key_lim2
@@ -12,19 +13,23 @@
    !!   'key_lim2' :                                  LIM 2.0 sea-ice model
    !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
    !!   ice_init_2       : sea-ice model initialization
    !!   ice_run_2        : Definition some run parameter for ice model
    !!----------------------------------------------------------------------
+   USE phycst           ! physical constants
    USE dom_oce          ! ocean domain
-   USE dom_ice_2        ! LIM2: ice domain
    USE sbc_oce          ! surface boundary condition: ocean
-   USE sbc_ice          ! surface boundary condition: ice
-   USE phycst           ! Define parameters for the routines
-   USE ice_2            ! LIM2: ice variable
-   USE limmsh_2         ! LIM2: mesh
-   USE limistate_2      ! LIM2: initial state
-   USE limrst_2         ! LIM2: restart
+   USE sbc_ice          ! LIM2 surface boundary condition
+   USE dom_ice_2        ! LIM2 ice domain
+   USE par_ice_2        ! LIM2 parameters
+   USE thd_ice_2        ! LIM2 thermodynamical variables
+   USE limrhg           ! LIM2 rheology
+   USE ice_2            ! LIM2 ice variable
+   USE limmsh_2         ! LIM2 mesh
+   USE limistate_2      ! LIM2 initial state
+   USE limrst_2         ! LIM2 restart
+   USE limsbc_2         ! LIM2 surface boundary condition
    USE in_out_manager   ! I/O manager
-      
+   USE lib_mpp          ! MPP library
+
    IMPLICIT NONE
    PRIVATE
@@ -33,5 +38,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/LIM2 3.3 , UCL - NEMO Consortium (2010)
+   !! NEMO/LIM2 4.0 , UCL - NEMO Consortium (2011)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -45,5 +50,28 @@
       !! ** purpose :   initialisation of LIM-2 domain and variables  
       !!----------------------------------------------------------------------
+      INTEGER :: ierr
+      !!----------------------------------------------------------------------
       !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_init_2 : LIM-2 sea-ice - initialization'
+         WRITE(numout,*) '~~~~~~~~~~~   '
+      ENDIF
+      !                                ! Allocate the ice arrays
+      ierr =        ice_alloc_2    ()       ! ice variables
+      ierr = ierr + dom_ice_alloc_2()       ! domain
+      ierr = ierr + sbc_ice_alloc  ()       ! surface forcing
+      ierr = ierr + thd_ice_alloc_2()       ! thermodynamics
+#if ! defined key_lim2_vp
+      ierr = ierr + lim_rhg_alloc  ()
+#endif
+      IF( lk_mpp    )   CALL mpp_sum( ierr )
+      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'ice_init_2 : unable to allocate ice arrays' )
+
+      !                                ! adequation jpk versus ice/snow layers
+      IF( jpl > jpk  .OR.  jplayersp1 > jpk  )   CALL ctl_stop( 'STOP',           &
+         &     'ice_init: the 3rd dimension of workspace arrays is too small.',   &
+         &     'use more ocean levels or less ice layers/categories.' )
+
       !                                ! Open the namelist file 
       CALL ctl_opn( numnam_ice, 'namelist_ice', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp ) 
@@ -61,6 +89,12 @@
       ENDIF
       !
-      tn_ice(:,:,1) = sist(:,:)        ! initialisation of ice temperature   
-      fr_i  (:,:) = 1.0 - frld(:,:)    ! initialisation of sea-ice fraction    
+      tn_ice(:,:,1) = sist(:,:)        ! ice temperature  known by the ocean
+      fr_i  (:,:)   = 1.0 - frld(:,:)  ! sea-ice fraction known by the ocean
+      !
+      CALL lim_sbc_init_2              ! ice surface boundary condition   
+      !
+      IF( lk_lim2_vp )   THEN   ;   WRITE(numout,*) '                VP  rheology - B-grid case'
+      ELSE                      ;   WRITE(numout,*) '                EVP rheology - C-grid case'
+      ENDIF
       !
    END SUBROUTINE ice_init_2
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limadv_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limadv_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limadv_2.F90	(revision 2715)
@@ -22,4 +22,5 @@
    USE lbclnk
    USE in_out_manager     ! I/O manager
+   USE lib_mpp            ! MPP library
    USE prtctl             ! Print control
 
@@ -58,4 +59,9 @@
       !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
       !!--------------------------------------------------------------------
+      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY:   zf0  => wrk_2d_11 , zfx   => wrk_2d_12 , zfy    => wrk_2d_13 , zbet => wrk_2d_14   ! 2D workspace
+      USE wrk_nemo, ONLY:   zfm  => wrk_2d_15 , zfxx  => wrk_2d_16 , zfyy   => wrk_2d_17 , zfxy => wrk_2d_18   !  -      -
+      USE wrk_nemo, ONLY:   zalg => wrk_2d_19 , zalg1 => wrk_2d_20 , zalg1q => wrk_2d_21                       !  -      -
+      !
       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)
@@ -65,13 +71,14 @@
       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), DIMENSION(jpi,jpj) ::   zf0, zfx , zfy , zbet   ! 2D workspace
-      REAL(wp), DIMENSION(jpi,jpj) ::   zfm, zfxx, zfyy, zfxy   !  -      -
-      REAL(wp), DIMENSION(jpi,jpj) ::   zalg, zalg1, zalg1q     !  -      -
       !---------------------------------------------------------------------
+
+      IF( wrk_in_use(2, 11,12,13,14,15,16,17,18,19,20,21) ) THEN
+         CALL ctl_stop( 'lim_adv_x_2 : requested workspace arrays unavailable.' )   ;   RETURN
+      ENDIF
 
       ! Limitation of moments.                                           
@@ -218,4 +225,7 @@
       ENDIF
       !
+      IF( wrk_not_released(2, 11,12,13,14,15,16,17,18,19,20,21) )   &
+          CALL ctl_stop( 'lim_adv_x_2 : failed to release workspace arrays.' )
+      !
    END SUBROUTINE lim_adv_x_2
 
@@ -235,4 +245,9 @@
       !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
       !!---------------------------------------------------------------------
+      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY:   zf0  => wrk_2d_11 , zfx   => wrk_2d_12 , zfy    => wrk_2d_13 , zbet => wrk_2d_14   ! 2D workspace
+      USE wrk_nemo, ONLY:   zfm  => wrk_2d_15 , zfxx  => wrk_2d_16 , zfyy   => wrk_2d_17 , zfxy => wrk_2d_18   !  -      -
+      USE wrk_nemo, ONLY:   zalg => wrk_2d_19 , zalg1 => wrk_2d_20 , zalg1q => wrk_2d_21                       !  -      -
+      !!
       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)
@@ -247,8 +262,9 @@
       REAL(wp) ::   zs1new, zalf , zalfq , zbt           !    -         -
       REAL(wp) ::   zs2new, zalf1, zalf1q, zbt1          !    -         -
-      REAL(wp), DIMENSION(jpi,jpj) ::   zf0, zfx , zfy , zbet   ! 2D workspace
-      REAL(wp), DIMENSION(jpi,jpj) ::   zfm, zfxx, zfyy, zfxy   !  -      -
-      REAL(wp), DIMENSION(jpi,jpj) ::   zalg, zalg1, zalg1q     !  -      -
       !---------------------------------------------------------------------
+
+      IF(wrk_in_use(2, 11,12,13,14,15,16,17,18,19,20,21) ) THEN
+         CALL ctl_stop( 'lim_adv_y_2 : requested workspace arrays unavailable.' )   ;   RETURN
+      END IF
 
       ! Limitation of moments.
@@ -398,4 +414,8 @@
       ENDIF
       !
+      IF( wrk_not_released(2, 11,12,13,14,15,16,17,18,19,20,21) ) THEN
+        CALL ctl_stop( 'lim_adv_y_2 : failed to release workspace arrays.' )
+      END IF
+      !
    END SUBROUTINE lim_adv_y_2
 
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limdia_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limdia_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limdia_2.F90	(revision 2715)
@@ -12,5 +12,4 @@
    !!   'key_lim2' :                                  LIM 2.0 sea-ice model
    !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
    !!   lim_dia_2      : computation of the time evolution of keys var.
    !!   lim_dia_init_2 : initialization and namelist read
@@ -24,4 +23,5 @@
    USE limistate_2     !
    USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! MPP library
 
    IMPLICIT NONE
@@ -29,4 +29,5 @@
 
    PUBLIC               lim_dia_2          ! called by sbc_ice_lim_2
+
    INTEGER, PUBLIC ::   ntmoy   = 1 ,   &  !: instantaneous values of ice evolution or averaging ntmoy
       &                 ninfo   = 1        !: frequency of ouputs on file ice_evolu in case of averaging
@@ -52,5 +53,5 @@
    REAL(wp)                     ::   epsi06 = 1.e-06      ! ???
    REAL(wp), DIMENSION(jpinfmx) ::   vinfom               ! temporary working space
-   REAL(wp), DIMENSION(jpi,jpj) ::   aire                 ! masked grid cell area
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   aire                 ! masked grid cell area
 
    !! * Substitutions
@@ -61,5 +62,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -173,17 +173,15 @@
        !!-------------------------------------------------------------------
        CHARACTER(len=jpchinf) ::   titinf
-       INTEGER  ::   jv            ! dummy loop indice
-       INTEGER  ::   ntot , ndeb 
-       INTEGER  ::   nv            ! indice of variable 
-       REAL(wp) ::   zxx0, zxx1    ! temporary scalars
+       INTEGER  ::   jv   ! dummy loop indice
+       INTEGER  ::   ntot , ndeb, nv, ierr   ! local integer
+       REAL(wp) ::   zxx0, zxx1              ! local scalars
 
        NAMELIST/namicedia/fmtinf, nfrinf, ninfo, ntmoy
        !!-------------------------------------------------------------------
 
-       ! Read Namelist namicedia
-       REWIND ( numnam_ice )
-       READ   ( numnam_ice  , namicedia )
+       REWIND( numnam_ice )                     ! Read Namelist namicedia
+       READ  ( numnam_ice  , namicedia )
        
-       IF(lwp) THEN
+       IF(lwp) THEN                             ! control print
           WRITE(numout,*)
           WRITE(numout,*) 'lim_dia_init_2 : ice parameters for ice diagnostics '
@@ -195,15 +193,14 @@
        ENDIF
 
-       ! masked grid cell area
+       ALLOCATE( aire(jpi,jpj) , STAT=ierr )    ! masked grid cell area
+       IF( lk_mpp    )   CALL mpp_sum( ierr )
+       IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'lim_dia_init_2 : unable to allocate standard arrays' )
        aire(:,:) = area(:,:) * tms(:,:)
 
-       ! Titles of ice key variables :
-       nv = 1
+       nv = 1                                   ! Titles of ice key variables
        titvar(nv) = 'NoIt'  ! iteration number
        nv = nv + 1
        titvar(nv) = 'T yr'  ! time step in years
-       
        nbvt = nv - 1
-
        nv = nv + 1   ;   titvar(nv) = 'AEFN' ! sea ice area in the northern Hemisp.(10^12 km2)
        nv = nv + 1   ;   titvar(nv) = 'AEFS' ! sea ice area in the southern Hemisp.(10^12 km2)
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limdmp_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limdmp_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limdmp_2.F90	(revision 2715)
@@ -13,10 +13,11 @@
    !!   lim_dmp_2      : ice model damping
    !!----------------------------------------------------------------------
-   USE in_out_manager  ! I/O manager
    USE ice_2           ! ice variables 
    USE sbc_oce, ONLY : nn_fsbc ! for fldread
    USE dom_oce         ! for mi0; mi1 etc ...
    USE fldread         ! read input fields
-   
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! MPP library
+
    IMPLICIT NONE
    PRIVATE
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limdyn_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limdyn_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limdyn_2.F90	(revision 2715)
@@ -58,4 +58,8 @@
       !!              - treatment of the case if no ice dynamic
       !!---------------------------------------------------------------------
+      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY:   wrk_1d_1, wrk_1d_2
+      USE wrk_nemo, ONLY:   zu_io => wrk_2d_1, zv_io => wrk_2d_2  ! ice-ocean velocity
+      !
       INTEGER, INTENT(in) ::   kt     ! number of iteration
       !!
@@ -63,8 +67,13 @@
       INTEGER  ::   i_j1, i_jpj        ! Starting/ending j-indices for rheology
       REAL(wp) ::   zcoef              ! temporary scalar
-      REAL(wp), DIMENSION(jpj)     ::   zind           ! i-averaged indicator of sea-ice
-      REAL(wp), DIMENSION(jpj)     ::   zmsk           ! i-averaged of tmask
-      REAL(wp), DIMENSION(jpi,jpj) ::   zu_io, zv_io   ! ice-ocean velocity
+      REAL(wp), POINTER, DIMENSION(:) ::   zind     ! i-averaged indicator of sea-ice
+      REAL(wp), POINTER, DIMENSION(:) ::   zmsk     ! i-averaged of tmask
       !!---------------------------------------------------------------------
+
+      IF(  wrk_in_use(1, 1,2)  .OR.  wrk_in_use(2, 1,2)  ) THEN
+         CALL ctl_stop( 'lim_dyn_2 : requested workspace arrays unavailable' )   ;   RETURN
+      ENDIF
+      zind => wrk_1d_1(1:jpj)      ! Set-up pointers to sub-arrays of workspaces
+      zmsk => wrk_1d_2(1:jpj)
 
       IF( kt == nit000 )   CALL lim_dyn_init_2   ! Initialization (first time-step only)
@@ -93,6 +102,6 @@
             !
             DO jj = 1, jpj
-               zind(jj) = SUM( frld (:,jj  ) )   ! = FLOAT(jpj) if ocean everywhere on a j-line
-               zmsk(jj) = SUM( tmask(:,jj,1) )   ! = 0          if land  everywhere on a j-line
+               zind(jj) = SUM( frld (:,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
             !
@@ -200,4 +209,7 @@
       !
       IF(ln_ctl)   CALL prt_ctl(tab2d_1=ust2s , clinfo1=' lim_dyn  : ust2s :')
+      !
+      IF( wrk_not_released(1, 1,2)     .OR.   &
+          wrk_not_released(2, 1,2) )   CALL ctl_stop('lim_dyn_2 : failed to release workspace arrays')
       !
    END SUBROUTINE lim_dyn_2
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limhdf_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limhdf_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limhdf_2.F90	(revision 2715)
@@ -4,4 +4,8 @@
    !! LIM 2.0 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_lim2
    !!----------------------------------------------------------------------
@@ -10,31 +14,28 @@
    !!   lim_hdf_2  : diffusion trend on sea-ice variable
    !!----------------------------------------------------------------------
-   !! * Modules used
-   USE dom_oce
-   USE in_out_manager
-   USE ice_2
-   USE lbclnk
-   USE lib_mpp
-   USE prtctl          ! Print control
+   USE dom_oce          ! ocean domain
+   USE ice_2            ! LIM-2: ice variables
+   USE lbclnk           ! lateral boundary condition - MPP exchanges
+   USE lib_mpp          ! MPP library
+   USE prtctl           ! Print control
+   USE in_out_manager   ! I/O manager
 
    IMPLICIT NONE
    PRIVATE
 
-   !! * Routine accessibility
-   PUBLIC lim_hdf_2    ! called by lim_tra_2
+   PUBLIC   lim_hdf_2         ! called by limtrp_2.F90
 
-   !! * Module variables
-   LOGICAL  ::   linit = .TRUE.              ! ???
-   REAL(wp) ::   epsi04 = 1e-04              ! constant
-   REAL(wp), DIMENSION(jpi,jpj) ::   zfact   ! ???
+   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/LIM2 3.3 , UCL - NEMO Consortium (2010)
+   !! NEMO/LIM2 4.0 , UCL - NEMO Consortium (2010)
    !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -43,79 +44,64 @@
       !!                  ***  ROUTINE lim_hdf_2  ***
       !!
-      !! ** purpose :   Compute and add the diffusive trend on sea-ice
-      !!      variables
+      !! ** purpose :   Compute and add the diffusive trend on sea-ice variables
       !!
       !! ** method  :   Second order diffusive operator evaluated using a
-      !!      Cranck-Nicholson time Scheme.
+      !!              Cranck-Nicholson time Scheme.
       !!
       !! ** Action  :    update ptab with the diffusive contribution
-      !!
-      !! History :
-      !!        !  00-01 (LIM) Original code
-      !!        !  01-05 (G. Madec, R. Hordoir) opa norm
-      !!        !  02-08 (C. Ethe)  F90, free form
       !!-------------------------------------------------------------------
-      ! * Arguments
-      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
-         ptab                 ! Field on which the diffusion is applied  
-      REAL(wp), DIMENSION(jpi,jpj) ::   &
-         ptab0                ! ???
-
-      ! * Local variables
-      INTEGER ::  ji, jj      ! dummy loop indices
-      INTEGER ::  &
-         its, iter            ! temporary integers
+      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY:   zflu => wrk_2d_11, zdiv  => wrk_2d_13, zrlx  => wrk_2d_15 
+      USE wrk_nemo, ONLY:   zflv => wrk_2d_12, zdiv0 => wrk_2d_14, ztab0 => wrk_2d_16
+      !
+      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
       CHARACTER (len=55) :: charout
-      REAL(wp) ::  &
-         zalfa, zrlxint, zconv, zeps   ! temporary scalars
-      REAL(wp), DIMENSION(jpi,jpj) ::  & 
-         zrlx, zflu, zflv, &  ! temporary workspaces
-         zdiv0, zdiv          !    "           "
       !!-------------------------------------------------------------------
 
-      ! Initialisation
-      ! ---------------   
-      ! Time integration parameters
-      zalfa = 0.5       ! =1.0/0.5/0.0 = implicit/Cranck-Nicholson/explicit
-      its   = 100       ! Maximum number of iteration
-      zeps  =  2. * epsi04
+      IF( wrk_in_use(2, 11,12,13,14,15,16) ) THEN
+         CALL ctl_stop( 'lim_hdf_2 : requested workspace arrays unavailable.' )   ;   RETURN
+      END IF
 
-      ! Arrays initialization
-      ptab0 (:, : ) = ptab(:,:)
-!bug  zflu (:,jpj) = 0.e0
-!bug  zflv (:,jpj) = 0.e0
-      zdiv0(:, 1 ) = 0.e0
-      zdiv0(:,jpj) = 0.e0
-      IF( .NOT.lk_vopt_loop ) THEN
-         zflu (jpi,:) = 0.e0   
-         zflv (jpi,:) = 0.e0
-         zdiv0(1,  :) = 0.e0
-         zdiv0(jpi,:) = 0.e0
-      ENDIF
-
-      ! Metric coefficient (compute at the first call and saved in
-      IF( linit ) THEN
+      !                       !==  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_2 : unable to allocate standard arrays' )
          DO jj = 2, jpjm1  
             DO ji = fs_2 , fs_jpim1   ! vector opt.
-               zfact(ji,jj) = ( e2u(ji,jj) + e2u(ji-1,jj  ) + e1v(ji,jj) + e1v(ji,jj-1) ) &
-                  &          / ( e1t(ji,jj) * e2t(ji,jj) )
+               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
 
-
-      ! Sub-time step loop
-      zconv = 1.e0
+      zconv = 1._wp           !==  horizontal diffusion using a Crant-Nicholson scheme  ==!
       iter  = 0
-
-      !                                                   !===================
-      DO WHILE ( ( zconv > zeps ) .AND. (iter <= its) )   ! Sub-time step loop
-         !                                                !===================
-         ! incrementation of the sub-time step number
-         iter = iter + 1
-
-         ! diffusive fluxes in U- and V- direction
-         DO jj = 1, jpjm1
+      !
+      DO 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) )
@@ -123,7 +109,6 @@
             END DO
          END DO
-
-         ! diffusive trend : divergence of the fluxes
-         DO jj= 2, jpjm1
+         !
+         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  )   &
@@ -131,24 +116,20 @@
             END DO
          END DO
-
-         ! save the first evaluation of the diffusive trend in zdiv0
-         IF( iter == 1 )   zdiv0(:,:) = zdiv(:,:)       
-
-         ! XXXX iterative evaluation?????
-         DO jj = 2, jpjm1
+         !
+         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 = (   ptab0(ji,jj)    &
-                  &       +  rdt_ice * (           zalfa   * ( zdiv(ji,jj) + zfact(ji,jj) * ptab(ji,jj) )   &
+               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 * zfact(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
 
-         ! lateral boundary condition on ptab
-         CALL lbc_lnk( zrlx, 'T', 1. )
+         zconv = 0._wp                                         ! convergence test
 
-         ! convergence test
-         zconv = 0.e0
          DO jj = 2, jpjm1
             DO ji = 2, jpim1
@@ -156,18 +137,18 @@
             END DO
          END DO
-         IF( lk_mpp )   CALL mpp_max( zconv )   ! max over the global domain
+         IF( lk_mpp )   CALL mpp_max( zconv )                  ! max over the global domain
 
          ptab(:,:) = zrlx(:,:)
-
-         !                                         !==========================
-      END DO                                       ! end of sub-time step loop
-      !                                            !==========================
+         !
+      END DO                                             ! end of sub-time step loop
 
       IF(ln_ctl)   THEN
-         zrlx(:,:) = ptab(:,:) - ptab0(:,:)
+         zrlx(:,:) = ptab(:,:) - ztab0(:,:)
          WRITE(charout,FMT="(' lim_hdf  : zconv =',D23.16, ' iter =',I4,2X)") zconv, iter
-         CALL prt_ctl(tab2d_1=zrlx, clinfo1=charout)
+         CALL prt_ctl( tab2d_1=zrlx, clinfo1=charout )
       ENDIF
-
+      !
+      IF( wrk_not_released(2, 11,12,13,14,15,16) )   CALL ctl_stop('lim_hdf_2: failed to release workspace arrays')
+      !
    END SUBROUTINE lim_hdf_2
 
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limmsh_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limmsh_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limmsh_2.F90	(revision 2715)
@@ -19,4 +19,5 @@
    USE lbclnk
    USE in_out_manager
+   USE lib_mpp          ! MPP library
 
    IMPLICIT NONE
@@ -45,4 +46,6 @@
       !! ** Refer.  : Deleersnijder et al. Ocean Modelling 100, 7-10 
       !!--------------------------------------------------------------------- 
+      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY: zd2d1 => wrk_2d_1, zd1d2 => wrk_2d_2
       INTEGER :: ji, jj      ! dummy loop indices
       REAL(wp) ::   zusden   ! local scalars
@@ -51,7 +54,10 @@
       REAL(wp) ::   zh1p  , zh2p      !   -      -
       REAL(wp) ::   zd2d1p, zd1d2p    !   -      -
-      REAL(wp), DIMENSION(jpi,jpj) ::   zd2d1 , zd1d2   ! 2D workspace
 #endif
       !!---------------------------------------------------------------------
+
+      IF( wrk_in_use(2, 1,2) ) THEN
+         CALL ctl_stop('lim_msh_2 : requested workspace arrays unavailable')   ;   RETURN
+      ENDIF
 
       IF(lwp) THEN
@@ -275,4 +281,6 @@
       area(:,:) = e1t(:,:) * e2t(:,:)
       !
+      IF( wrk_not_released(2, 1,2) )   CALL ctl_stop('lim_msh_2 : failed to release workspace arrays')
+      !
    END SUBROUTINE lim_msh_2
 
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limrhg_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limrhg_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limrhg_2.F90	(revision 2715)
@@ -33,8 +33,18 @@
    PRIVATE
 
-   PUBLIC   lim_rhg_2 ! routine called by lim_dyn
+   PUBLIC   lim_rhg_2         ! routine called by lim_dyn
+   PUBLIC   lim_rhg_alloc_2   ! routine called by lim_dyn_alloc_2
 
    REAL(wp) ::   rzero   = 0._wp   ! constant value: zero
    REAL(wp) ::   rone    = 1._wp   !            and  one
+
+   ! 2D workspaces for lim_rhg_2. Can't use wrk_nemo module for them because
+   ! extent in 2nd dimension is > jpj.
+   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:) ::   zu0, zv0
+   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:) ::   zu_n, zv_n
+   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:) ::   zu_a, zv_a
+   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:) ::   zviszeta, zviseta
+   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:) ::   zzfrld, zztms
+   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:) ::   zi1, zi2, zmasst, zpresh
 
    !! * Substitutions
@@ -46,4 +56,22 @@
    !!----------------------------------------------------------------------
 CONTAINS
+
+   INTEGER FUNCTION lim_rhg_alloc_2()
+      !!-------------------------------------------------------------------
+      !!               ***  FUNCTION lim_rhg_alloc_2  ***
+      !!-------------------------------------------------------------------
+      ALLOCATE( zu0(jpi,0:jpj+1),      zv0(jpi,0:jpj+1),     &
+         &      zu_n(jpi,0:jpj+1),     zv_n(jpi,0:jpj+1),    &
+         &      zu_a(jpi,0:jpj+1),     zv_a(jpi,0:jpj+1),    &
+         &      zviszeta(jpi,0:jpj+1), zviseta(jpi,0:jpj+1), &
+         &      zzfrld(jpi,0:jpj+1),   zztms(jpi,0:jpj+1),   &
+         &      zi1(jpi,0:jpj+1),      zi2(jpi,0:jpj+1),     &
+         &      zmasst(jpi,0:jpj+1),   zpresh(jpi,0:jpj+1),  &
+         &      Stat=lim_rhg_alloc_2)
+         !
+      IF( lim_rhg_alloc_2 /= 0 )   CALL ctl_warn('lim_rhg_alloc_2 : failed to allocate arrays')
+      !
+   END FUNCTION lim_rhg_alloc_2
+
 
    SUBROUTINE lim_rhg_2( k_j1, k_jpj )
@@ -59,4 +87,10 @@
       !!              at I-point
       !!-------------------------------------------------------------------
+      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY: zfrld => wrk_2d_1, zmass => wrk_2d_2, zcorl => wrk_2d_3
+      USE wrk_nemo, ONLY: za1ct => wrk_2d_4, za2ct => wrk_2d_5, zresr => wrk_2d_6
+      USE wrk_nemo, ONLY: zc1u  => wrk_2d_7, zc1v  => wrk_2d_8, zc2u => wrk_2d_9
+      USE wrk_nemo, ONLY: zc2v  => wrk_2d_10, zsang => wrk_2d_11
+      !!
       INTEGER, INTENT(in) ::   k_j1    ! southern j-index for ice computation
       INTEGER, INTENT(in) ::   k_jpj   ! northern j-index for ice computation
@@ -79,14 +113,4 @@
       REAL(wp) ::   zs21_11, zs21_12, zs21_21, zs21_22
       REAL(wp) ::   zs22_11, zs22_12, zs22_21, zs22_22
-      REAL(wp), DIMENSION(jpi,  jpj  ) ::   zfrld, zmass, zcorl
-      REAL(wp), DIMENSION(jpi,  jpj  ) ::   za1ct, za2ct, zresr
-      REAL(wp), DIMENSION(jpi,  jpj  ) ::   zc1u, zc1v, zc2u, zc2v
-      REAL(wp), DIMENSION(jpi,  jpj  ) ::   zsang
-      REAL(wp), DIMENSION(jpi,0:jpj+1) ::   zu0, zv0
-      REAL(wp), DIMENSION(jpi,0:jpj+1) ::   zu_n, zv_n
-      REAL(wp), DIMENSION(jpi,0:jpj+1) ::   zu_a, zv_a
-      REAL(wp), DIMENSION(jpi,0:jpj+1) ::   zviszeta, zviseta
-      REAL(wp), DIMENSION(jpi,0:jpj+1) ::   zzfrld, zztms
-      REAL(wp), DIMENSION(jpi,0:jpj+1) ::   zi1, zi2, zmasst, zpresh
       !!-------------------------------------------------------------------
       
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90	(revision 2715)
@@ -9,4 +9,5 @@
    !!            3.3  ! 2009-05 (G. Garric, C. Bricaud) addition of the lim2_evp case
    !!             -   ! 2010-11 (G. Madec) ice-ocean stress computed at each ocean time-step
+   !!            4.0  ! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
    !!----------------------------------------------------------------------
 #if defined key_lim2
@@ -14,6 +15,8 @@
    !!   'key_lim2'                                    LIM 2.0 sea-ice model
    !!----------------------------------------------------------------------
-   !!   lim_sbc_flx_2  : update mass, heat and salt fluxes at the ocean surface
-   !!   lim_sbc_tau_2  : update i- and j-stresses, and its modulus at the ocean surface
+   !!   lim_sbc_alloc_2 : allocate the limsbc arrays
+   !!   lim_sbc_init    : initialisation
+   !!   lim_sbc_flx_2   : update mass, heat and salt fluxes at the ocean surface
+   !!   lim_sbc_tau_2   : update i- and j-stresses, and its modulus at the ocean surface
    !!----------------------------------------------------------------------
    USE par_oce          ! ocean parameters
@@ -27,4 +30,5 @@
    USE albedo           ! albedo parameters
    USE lbclnk           ! ocean lateral boundary condition - MPP exchanges
+   USE lib_mpp          ! MPP library
    USE in_out_manager   ! I/O manager
    USE diaar5, ONLY :   lk_diaar5
@@ -36,6 +40,7 @@
    PRIVATE
 
-   PUBLIC   lim_sbc_flx_2   ! called by sbc_ice_lim_2
-   PUBLIC   lim_sbc_tau_2   ! called by sbc_ice_lim_2
+   PUBLIC   lim_sbc_init_2     ! called by ice_init_2
+   PUBLIC   lim_sbc_flx_2      ! called by sbc_ice_lim_2
+   PUBLIC   lim_sbc_tau_2      ! called by sbc_ice_lim_2
 
    REAL(wp)  ::   r1_rdtice            ! = 1. / rdt_ice 
@@ -44,17 +49,30 @@
    REAL(wp)  ::   rone   = 1._wp       !     -      -
    !
-   REAL(wp), DIMENSION(jpi,jpj) ::   soce_0, sice_0   ! constant SSS and ice salinity used in levitating sea-ice case
-
-   REAL(wp), DIMENSION(jpi,jpj) ::   utau_oce, vtau_oce   ! air-ocean surface i- & j-stress              [N/m2]
-   REAL(wp), DIMENSION(jpi,jpj) ::   tmod_io              ! modulus of the ice-ocean relative velocity   [m/s]
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   soce_0, sice_0   ! constant SSS and ice salinity used in levitating sea-ice case
+
+   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 relative velocity   [m/s]
 
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/LIM2 3.3 , UCL - NEMO Consortium (2010)
+   !! NEMO/LIM2 4.0 , UCL - NEMO Consortium (2011)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 CONTAINS
+
+   INTEGER FUNCTION lim_sbc_alloc_2()
+      !!-------------------------------------------------------------------
+      !!             ***  ROUTINE lim_sbc_alloc_2 ***
+      !!-------------------------------------------------------------------
+      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_2)
+         !
+      IF( lk_mpp               )   CALL mpp_sum( lim_sbc_alloc_2 )
+      IF( lim_sbc_alloc_2 /= 0 )   CALL ctl_warn('lim_sbc_alloc_2: failed to allocate arrays.')
+      !
+   END FUNCTION lim_sbc_alloc_2
+
 
    SUBROUTINE lim_sbc_flx_2( kt )
@@ -82,4 +100,7 @@
       !!              Tartinville et al. 2001 Ocean Modelling, 3, 95-108.
       !!---------------------------------------------------------------------
+      USE wrk_nemo, ONLY: wrk_not_released, wrk_in_use
+      USE wrk_nemo, ONLY: zqnsoce => wrk_2d_1 ! 2D workspace
+      USE wrk_nemo, ONLY: wrk_3d_4, wrk_3d_5
       INTEGER, INTENT(in) ::   kt    ! number of iteration
       !!
@@ -90,27 +111,12 @@
       REAL(wp) ::   zqsr, zqns, zfm            ! local scalars
       REAL(wp) ::   zinda, zfons, zemp         !   -      -
-      REAL(wp), DIMENSION(jpi,jpj)   ::   zqnsoce       ! 2D workspace
-      REAL(wp), DIMENSION(jpi,jpj,1) ::   zalb, zalbp   ! 2D/3D workspace
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zalb, zalbp   ! 2D/3D workspace
       !!---------------------------------------------------------------------
      
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'lim_sbc_flx_2 : LIM-2 sea-ice - surface boundary condition - Mass, heat & salt fluxes'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~   '
-         !
-         r1_rdtice = 1._wp / 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
-         !
+      IF( wrk_in_use(2, 1) .OR. wrk_in_use(3, 4,5) )THEN
+         CALL ctl_stop('lim_sbc_flx_2 : requested workspace arrays unavailable')   ;   RETURN
       ENDIF
+      zalb  => wrk_3d_4(:,:,1:1)      ! Set-up pointers to sub-arrays of 3d workspaces
+      zalbp => wrk_3d_5(:,:,1:1)
 
       !------------------------------------------!
@@ -150,5 +156,5 @@
 !!$!                -> ice aera increases  ???         -> ice aera decreases ???
 !!$
-!!$            iadv    = ( 1  - i1mfr ) * zinda  
+!!$            iadv    = ( 1  - i1mfr ) * zinda
 !!$!                     pure ocean      ice at
 !!$!                     at current      previous
@@ -159,7 +165,7 @@
 !!$!                            current         
 !!$!                         -> ???
-!!$ 
-!!$            ifrdv   = ( 1  - ifral * ( 1 - ial ) ) * iadv 
-!!$!                                                    ice disapear                           
+!!$
+!!$            ifrdv   = ( 1  - ifral * ( 1 - ial ) ) * iadv
+!!$!                                                    ice disapear
 !!$
 !!$
@@ -229,7 +235,6 @@
 
       IF( lk_cpl ) THEN          ! coupled case
-         ! Ice surface temperature 
          tn_ice(:,:,1) = sist(:,:)          ! sea-ice surface temperature       
-         ! Computation of snow/ice and ocean albedo
+         !                                  ! Computation of snow/ice and ocean albedo
          CALL albedo_ice( tn_ice, reshape( hicif, (/jpi,jpj,1/) ), reshape( hsnif, (/jpi,jpj,1/) ), zalbp, zalb )
          alb_ice(:,:,1) =  0.5 * ( zalbp(:,:,1) + zalb (:,:,1) )   ! Ice albedo (mean clear and overcast skys)
@@ -244,4 +249,7 @@
          CALL prt_ctl(tab2d_1=fr_i  , clinfo1=' lim_sbc: fr_i   : ', tab2d_2=tn_ice(:,:,1), clinfo2=' tn_ice  : ')
       ENDIF 
+      !
+      IF( wrk_not_released(2, 1)     .OR.    &
+          wrk_not_released(3, 4,5) )   CALL ctl_stop('lim_sbc_flx_2 : failed to release workspace arrays')
       !
    END SUBROUTINE lim_sbc_flx_2
@@ -274,4 +282,6 @@
       !!              - taum       : modulus of the surface ocean stress (T-point) updated with ice-ocean fluxes
       !!---------------------------------------------------------------------
+      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY: ztio_u => wrk_2d_1, ztio_v => wrk_2d_2     ! ocean stress below sea-ice
       INTEGER ,                     INTENT(in) ::   kt               ! ocean time-step index
       REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pu_oce, pv_oce   ! surface ocean currents
@@ -281,14 +291,8 @@
       REAL(wp) ::   zfrldv, zat_v, zv_i, zvtau_ice, zv_t, zmodi   !   -      -
       REAL(wp) ::   zsang, zumt                                   !    -         -
-      REAL(wp), DIMENSION(jpi,jpj) ::   ztio_u, ztio_v   ! ocean stress below sea-ice
       !!---------------------------------------------------------------------
       !
-      IF( kt == nit000 .AND. lwp ) THEN         ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_sbc_tau_2 : LIM 2.0 sea-ice - surface ocean momentum fluxes'
-         WRITE(numout,*) '~~~~~~~~~~~~~ '
-         IF( lk_lim2_vp )   THEN   ;   WRITE(numout,*) '                VP  rheology - B-grid case'
-         ELSE                      ;   WRITE(numout,*) '                EVP rheology - C-grid case'
-         ENDIF
+      IF( wrk_in_use(2, 1,2) ) THEN
+         CALL ctl_stop('lim_sbc_tau_2 : requested workspace arrays unavailable.')   ;   RETURN
       ENDIF
       !
@@ -405,5 +409,40 @@
          &                       tab2d_2=vtau, clinfo2=' vtau    : '        , mask2=vmask )
       !  
+      IF( wrk_not_released(2, 1,2) )   CALL ctl_stop('lim_sbc_tau_2 : failed to release workspace arrays')
+      !
    END SUBROUTINE lim_sbc_tau_2
+
+
+   SUBROUTINE lim_sbc_init_2
+      !!-------------------------------------------------------------------
+      !!                  ***  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_2 : LIM-2 sea-ice - surface boundary condition'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~   '
+
+      !                                      ! allocate lim_sbc arrays
+      IF( lim_sbc_alloc_2() /= 0 )   CALL ctl_stop( 'STOP', 'lim_sbc_flx_2 : unable to allocate arrays' )
+      !
+      r1_rdtice = 1._wp / 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
+      !
+   END SUBROUTINE lim_sbc_init_2
 
 #else
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limtab_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limtab_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limtab_2.F90	(revision 2715)
@@ -2,12 +2,11 @@
    !!======================================================================
    !!                       ***  MODULE limtab_2   ***
-   !!              transform 1D (2D) array to a 2D (1D) table
+   !!   LIM : transform 1D (2D) array to a 2D (1D) table
    !!======================================================================
 #if defined key_lim2
    !!----------------------------------------------------------------------
-   !!   tab_2d_1d  : 2-D to 1-D
-   !!   tab_1d_2d  : 1-D to 2-D
+   !!   tab_2d_1d  : 2-D <==> 1-D
+   !!   tab_1d_2d  : 1-D <==> 2-D
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE par_kind
 
@@ -15,66 +14,56 @@
    PRIVATE
 
-   !! * Routine accessibility
-   PUBLIC tab_2d_1d_2  ! called by lim_ther
-   PUBLIC tab_1d_2d_2  ! called by lim_ther
+   PUBLIC   tab_2d_1d_2   ! called by limthd
+   PUBLIC   tab_1d_2d_2   ! called by limthd
 
    !!----------------------------------------------------------------------
-   !! NEMO/LIM2 3.3 , UCL - NEMO Consortium (2010)
+   !! NEMO/LIM2 4.0 , UCL - NEMO Consortium (2010)
    !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 CONTAINS
 
    SUBROUTINE tab_2d_1d_2 ( ndim1d, tab1d, tab2d, ndim2d_x, ndim2d_y, tab_ind )
-
-      INTEGER, INTENT(in) :: &
-         ndim1d, ndim2d_x, ndim2d_y
-
-      REAL(wp), DIMENSION (ndim2d_x, ndim2d_y), INTENT(in) ::  &
-         tab2d
-
-      INTEGER, DIMENSION ( ndim1d), INTENT ( in) :: &
-         tab_ind
-
-      REAL(wp), DIMENSION(ndim1d), INTENT ( out) ::  & 
-         tab1d
-
-      INTEGER ::  &
-         jn , jid, jjd
-        
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tab_2d_1d  ***
+      !!----------------------------------------------------------------------
+      INTEGER                               , INTENT(in   ) ::   ndim1d, ndim2d_x, ndim2d_y   ! 1D & 2D sizes
+      REAL(wp), DIMENSION(ndim2d_x,ndim2d_y), INTENT(in   ) ::   tab2d                        ! input 2D field
+      INTEGER , DIMENSION(ndim1d)           , INTENT(in   ) ::   tab_ind                      ! input index
+      REAL(wp), DIMENSION(ndim1d)           , INTENT(  out) ::   tab1d                        ! output 1D field
+      !
+      INTEGER ::   jn , jid, jjd
+      !!----------------------------------------------------------------------
       DO jn = 1, ndim1d
-         jid        = MOD( tab_ind(jn) - 1, ndim2d_x ) + 1
-         jjd        = ( tab_ind(jn) - 1 ) / ndim2d_x + 1
+         jid        = MOD( tab_ind(jn) - 1 , ndim2d_x ) + 1
+         jjd        =    ( tab_ind(jn) - 1 ) / ndim2d_x + 1
          tab1d( jn) = tab2d( jid, jjd)
       END DO 
-
    END SUBROUTINE tab_2d_1d_2
 
 
    SUBROUTINE tab_1d_2d_2 ( ndim1d, tab2d, tab_ind, tab1d, ndim2d_x, ndim2d_y )
-
-      INTEGER, INTENT ( in) :: &
-         ndim1d, ndim2d_x, ndim2d_y
-
-      INTEGER, DIMENSION (ndim1d) , INTENT (in) :: &
-         tab_ind
-
-      REAL(wp), DIMENSION(ndim1d), INTENT (in) ::  &
-         tab1d  
-
-      REAL(wp), DIMENSION (ndim2d_x, ndim2d_y), INTENT ( out) :: &
-         tab2d
-
-      INTEGER :: &
-         jn, jid, jjd
-
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tab_2d_1d  ***
+      !!----------------------------------------------------------------------
+      INTEGER                               , INTENT(in   ) ::   ndim1d, ndim2d_x, ndim2d_y   ! 1d & 2D sizes
+      REAL(wp), DIMENSION(ndim1d)           , INTENT(in   ) ::   tab1d                        ! input 1D field
+      INTEGER , DIMENSION(ndim1d)           , INTENT(in   ) ::   tab_ind                      ! input index
+      REAL(wp), DIMENSION(ndim2d_x,ndim2d_y), INTENT(  out) ::   tab2d                        ! output 2D field
+      !
+      INTEGER ::   jn , jid, jjd
+      !!----------------------------------------------------------------------
       DO jn = 1, ndim1d
-         jid             = MOD( tab_ind(jn) - 1, ndim2d_x) + 1
+         jid             = MOD( tab_ind(jn) - 1 , ndim2d_x ) + 1
          jjd             =    ( tab_ind(jn) - 1 ) / ndim2d_x  + 1
          tab2d(jid, jjd) = tab1d( jn)
       END DO
-
    END SUBROUTINE tab_1d_2d_2
 
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option        Dummy module             NO LIM sea-ice model
+   !!----------------------------------------------------------------------
 #endif
+   !!======================================================================
 END MODULE limtab_2
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90	(revision 2715)
@@ -75,4 +75,17 @@
       !! References :   Goosse et al. 1996, Bul. Soc. Roy. Sc. Liege, 65, 87-90
       !!---------------------------------------------------------------------
+      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY: ztmp    => wrk_2d_1, & ! 2D workspace
+                          zqlbsbq => wrk_2d_2, & ! link with lead energy budget qldif
+                          zlicegr => wrk_2d_3    ! link with lateral ice growth 
+      USE wrk_nemo, ONLY: zmsk => wrk_3d_4       ! 3D workspace
+      USE wrk_nemo, ONLY: zdvosif => wrk_2d_4, & !: Variation of volume at surface
+                          zdvobif => wrk_2d_5, & !: Variation of ice volume at the bottom ice     (outputs only)
+                          zdvolif => wrk_2d_6, & !: Total variation of ice volume                 (outputs only)
+                          zdvonif => wrk_2d_7, & !: Surface accretion Snow to Ice transformation  (outputs only)
+                          zdvomif => wrk_2d_8, & !: Bottom variation of ice volume due to melting (outputs only)
+                          zu_imasstr =>wrk_2d_9, & !: Sea-ice transport along i-axis at U-point     (outputs only) 
+                          zv_imasstr =>wrk_2d_10   !: Sea-ice transport along j-axis at V-point     (outputs only) 
+      !!
       INTEGER, INTENT(in) ::   kt     ! number of iteration
       !!
@@ -91,6 +104,5 @@
       REAL(wp) ::   zfontn               ! heat flux from snow thickness
       REAL(wp) ::   zfntlat, zpareff     ! test. the val. of lead heat budget
-      REAL(wp), DIMENSION(jpi,jpj)     ::   ztmp      ! 2D workspace
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zqlbsbq   ! link with lead energy budget qldif
+
       REAL(wp) ::   zuice_m, zvice_m     ! Sea-ice velocities at U & V-points
       REAL(wp) ::   zhice_u, zhice_v     ! Sea-ice volume at U & V-points
@@ -98,18 +110,14 @@
       REAL(wp) ::   zrhoij, zrhoijm1     ! temporary scalars
       REAL(wp) ::   zztmp                ! temporary scalars within a loop
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zlicegr   ! link with lateral ice growth 
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmsk      ! 3D workspace
 !!$      REAL(wp), DIMENSION(jpi,jpj) ::   firic         !: IR flux over the ice            (outputs only)
 !!$      REAL(wp), DIMENSION(jpi,jpj) ::   fcsic         !: Sensible heat flux over the ice (outputs only)
 !!$      REAL(wp), DIMENSION(jpi,jpj) ::   fleic         !: Latent heat flux over the ice   (outputs only)
 !!$      REAL(wp), DIMENSION(jpi,jpj) ::   qlatic        !: latent flux                     (outputs only)
-      REAL(wp), DIMENSION(jpi,jpj) ::   zdvosif       !: Variation of volume at surface                (outputs only)
-      REAL(wp), DIMENSION(jpi,jpj) ::   zdvobif       !: Variation of ice volume at the bottom ice     (outputs only)
-      REAL(wp), DIMENSION(jpi,jpj) ::   zdvolif       !: Total variation of ice volume                 (outputs only)
-      REAL(wp), DIMENSION(jpi,jpj) ::   zdvonif       !: Surface accretion Snow to Ice transformation  (outputs only)
-      REAL(wp), DIMENSION(jpi,jpj) ::   zdvomif       !: Bottom variation of ice volume due to melting (outputs only)
-      REAL(wp), DIMENSION(jpi,jpj) ::   zu_imasstr    !: Sea-ice transport along i-axis at U-point     (outputs only) 
-      REAL(wp), DIMENSION(jpi,jpj) ::   zv_imasstr    !: Sea-ice transport along j-axis at V-point     (outputs only) 
       !!-------------------------------------------------------------------
+
+      IF( wrk_in_use(2, 1,2,3,4,5,6,7,8,9,10)   .OR.  &
+          wrk_in_use(3, 4)                    ) THEN
+         CALL ctl_stop('lim_thd_2 : requested workspace arrays unavailable')   ;   RETURN
+      ENDIF
 
       IF( kt == nit000 )   CALL lim_thd_init_2  ! Initialization (first time-step only)
@@ -512,4 +520,9 @@
       ENDIF
        !
+      IF( wrk_not_released(2, 1,2,3,4,5,6,7,8,9,10)   .OR.  &
+          wrk_not_released(3, 4)                    ) THEN
+         CALL ctl_stop('lim_thd_2 : failed to release workspace arrays')
+      ENDIF
+      !
     END SUBROUTINE lim_thd_2
 
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limthd_lac_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limthd_lac_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limthd_lac_2.F90	(revision 2715)
@@ -7,6 +7,6 @@
 
    !!----------------------------------------------------------------------
-   !!   lim_lat_acr_2    : lateral accretion of ice
-   !! * Modules used
+   !!   lim_lat_acr_2   : lateral accretion of ice
+   !!----------------------------------------------------------------------
    USE par_oce          ! ocean parameters
    USE phycst
@@ -14,12 +14,11 @@
    USE ice_2
    USE limistate_2 
-     
+   USE lib_mpp          ! MPP library
+
    IMPLICIT NONE
    PRIVATE
 
-   !! * Routine accessibility
-   PUBLIC lim_thd_lac_2   ! called by lim_thd_2
-
-   !! * Module variables
+   PUBLIC   lim_thd_lac_2   ! called by lim_thd_2
+
    REAL(wp)  ::           &  ! constant values
       epsi20 = 1.e-20  ,  &
@@ -27,4 +26,5 @@
       zzero  = 0.e0    ,  &
       zone   = 1.e0
+
    !!----------------------------------------------------------------------
    !! NEMO/LIM2 3.3 , UCL - NEMO Consortium (2010)
@@ -68,10 +68,12 @@
       !!   2.0  !  02-08 (C. Ethe, G. Madec)  F90, mpp
       !!-------------------------------------------------------------------
-      !! * Arguments
+      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY: wrk_1d_1, wrk_1d_2, wrk_1d_3, wrk_1d_4, wrk_1d_5, wrk_1d_6
+      !
       INTEGER , INTENT(IN)::  &
          kideb          ,   &  ! start point on which the the computation is applied
          kiut                  ! end point on which the the computation is applied
 
-      !! * Local variables
+      ! * Local variables
       INTEGER ::            &
          ji             ,   &  !  dummy loop indices
@@ -79,5 +81,5 @@
          iiceform       ,   &  !  1 = ice formed   ; 0 = no ice formed
          ihemis                !  dummy indice
-      REAL(wp), DIMENSION(jpij) :: &
+      REAL(wp), POINTER, DIMENSION(:) :: &
          zqbgow           ,  &  !  heat budget of the open water (negative)
          zfrl_old         ,  &  !  previous sea/ice fraction
@@ -101,5 +103,16 @@
          zah, zalpha , zbeta
       !!---------------------------------------------------------------------      
-                   
+               
+      IF( wrk_in_use(1, 1,2,3,4,5,6) ) THEN
+         CALL ctl_stop('lim_thd_lac_2 : requestead workspace arrays unavailable')   ;   RETURN
+      ENDIF
+      ! Set-up pointers to sub-arrays of workspace arrays
+      zqbgow    => wrk_1d_1(1:jpij)
+      zfrl_old  => wrk_1d_2(1:jpij)         
+      zhice_old => wrk_1d_3(1:jpij)        
+      zhice0    => wrk_1d_4(1:jpij)        
+      zfrlmin   => wrk_1d_5(1:jpij)        
+      zdhicbot  => wrk_1d_6(1:jpij) 
+      
       !--------------------------------------------------------------
       !   Computation of the heat budget of the open water (negative)
@@ -219,13 +232,16 @@
       END DO
       
+      IF( wrk_not_released(1, 1,2,3,4,5,6) )   CALL ctl_stop('lim_thd_lac_2 : failed to release workspace arrays.')
+      !
    END SUBROUTINE lim_thd_lac_2
 #else
-   !!======================================================================
+   !!----------------------------------------------------------------------
    !!                       ***  MODULE limthd_lac_2   ***
    !!                           no sea ice model
-   !!======================================================================
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE lim_thd_lac_2           ! Empty routine
    END SUBROUTINE lim_thd_lac_2
 #endif
+   !!======================================================================
 END MODULE limthd_lac_2
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limthd_zdf_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limthd_zdf_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limthd_zdf_2.F90	(revision 2715)
@@ -11,8 +11,6 @@
    !!   'key_lim2'                                    LIM 2.0 sea-ice model
    !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
    !!   lim_thd_zdf_2 : vertical accr./abl. and lateral ablation of sea ice
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE par_oce          ! ocean parameters
    USE phycst           ! ???
@@ -21,4 +19,5 @@
    USE limistate_2
    USE in_out_manager
+   USE lib_mpp          ! MPP library
    USE cpl_oasis3, ONLY : lk_cpl
       
@@ -35,7 +34,6 @@
    !! NEMO/LIM2 3.3 , UCL - NEMO Consortium (2010)
    !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -69,10 +67,19 @@
       !!              Fichefet T. and M. Maqueda 1999, Clim. Dyn, 15(4), 251-268  
       !!------------------------------------------------------------------
+      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY: wrk_1d_1,  wrk_1d_2,  wrk_1d_3,  wrk_1d_4,  wrk_1d_5 
+      USE wrk_nemo, ONLY: wrk_1d_6,  wrk_1d_7,  wrk_1d_8,  wrk_1d_9,  wrk_1d_10
+      USE wrk_nemo, ONLY: wrk_1d_11, wrk_1d_12, wrk_1d_13, wrk_1d_14, wrk_1d_15
+      USE wrk_nemo, ONLY: wrk_1d_16, wrk_1d_17, wrk_1d_18, wrk_1d_19, wrk_1d_20
+      USE wrk_nemo, ONLY: wrk_1d_21, wrk_1d_22, wrk_1d_23, wrk_1d_24, wrk_1d_25
+      USE wrk_nemo, ONLY: wrk_1d_26, wrk_1d_27
+      !!
       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 ::   ji       ! dummy loop indices
-      REAL(wp), DIMENSION(jpij,2) ::   zqcmlt        ! energy due to surface( /1 ) and bottom melting( /2 )
-      REAL(wp), DIMENSION(jpij) ::  &
+      REAL(wp), POINTER, DIMENSION(:) ::   zqcmlts        ! energy due to surface melting
+      REAL(wp), POINTER, DIMENSION(:) ::   zqcmltb        ! energy due to bottom melting
+      REAL(wp), POINTER, DIMENSION(:) ::  &
          ztsmlt      &    ! snow/ice surface melting temperature
          ,ztbif      &    ! int. temp. at the mid-point of the 1st layer of the snow/ice sys. 
@@ -88,5 +95,5 @@
          , zts_old   &    ! previous surface temperature
          , zidsn , z1midsn , zidsnic ! tempory variables
-      REAL(wp), DIMENSION(jpij) ::   &
+      REAL(wp), POINTER, DIMENSION(:) ::   &
           zfnet       &  ! net heat flux at the top surface( incl. conductive heat flux)
           , zsprecip  &    ! snow accumulation
@@ -160,4 +167,40 @@
        !!----------------------------------------------------------------------
 
+       IF(wrk_in_use(1, 1,  2, 3, 4, 5, 6, 7, 8, 9,10, &
+          &             11,12,13,14,15,16,17,18,19,20, &
+          &             21,22,23,24,25,26,27) ) THEN
+          CALL ctl_stop('lim_thd_zdf_2 : requested workspace arrays unavailable')   ;   RETURN
+       ENDIF
+
+       ztsmlt  => wrk_1d_1(1:jpij)
+       ztbif   => wrk_1d_2(1:jpij)  
+       zksn    => wrk_1d_3(1:jpij)  
+       zkic    => wrk_1d_4(1:jpij)   
+       zksndh  => wrk_1d_5(1:jpij)   
+       zfcsu   => wrk_1d_6(1:jpij)   
+       zfcsudt => wrk_1d_7(1:jpij)  
+       zi0     => wrk_1d_8(1:jpij)   
+       z1mi0   => wrk_1d_9(1:jpij)    
+       zqmax   => wrk_1d_10(1:jpij)    
+       zrcpdt  => wrk_1d_11(1:jpij)  
+       zts_old => wrk_1d_12(1:jpij)  
+       zidsn   => wrk_1d_13(1:jpij) 
+       z1midsn => wrk_1d_14(1:jpij) 
+       zidsnic => wrk_1d_15(1:jpij)
+
+       zfnet     => wrk_1d_16(1:jpij)
+       zsprecip  => wrk_1d_17(1:jpij)  
+       zhsnw_old => wrk_1d_18(1:jpij) 
+       zdhictop  => wrk_1d_19(1:jpij) 
+       zdhicbot  => wrk_1d_20(1:jpij)
+       zqsup     => wrk_1d_21(1:jpij)  
+       zqocea    => wrk_1d_22(1:jpij)
+       zfrl_old  => wrk_1d_23(1:jpij) 
+       zfrld_1d  => wrk_1d_24(1:jpij) 
+       zep       => wrk_1d_25(1:jpij) 
+
+       zqcmlts   => wrk_1d_26(1:jpij)
+       zqcmltb   => wrk_1d_27(1:jpij)
+
        !-----------------------------------------------------------------------
        !  1. Boundaries conditions for snow/ice system internal temperature
@@ -171,8 +214,8 @@
           zihic = MAX( zzero , SIGN( zone , hicdif - h_ice_1d(ji) ) )
           !--computation of energy due to surface melting
-          zqcmlt(ji,1) = ( MAX ( zzero ,  &
+          zqcmlts(ji) = ( MAX ( zzero ,  &
              &                   rcpsn * h_snow_1d(ji) * ( tbif_1d(ji,1) - rt0_snow ) ) ) * ( 1.0 - zihsn )
           !--computation of energy due to bottom melting
-          zqcmlt(ji,2) = ( MAX( zzero , &
+          zqcmltb(ji) = ( MAX( zzero , &
              &                  rcpic * ( tbif_1d(ji,2) - rt0_ice ) * ( h_ice_1d(ji) / 2. ) ) &
              &           + MAX( zzero , &
@@ -467,5 +510,5 @@
           zhsnw_old(ji) =  h_snow_1d(ji)
           !--computation of the energy needed to melt snow
-          zqsnw_mlt  = zfnet(ji) * rdt_ice - zqcmlt(ji,1)
+          zqsnw_mlt  = zfnet(ji) * rdt_ice - zqcmlts(ji)
           !--change in snow thickness due to melt
           zdhsmlt = - zqsnw_mlt / xlsn
@@ -587,6 +630,6 @@
 
           !---treatment of the case of melting/growing
-          zqice_bot   =         zibmlt   * ( zqice_bot_mlt - zqcmlt(ji,2) )   &
-             &        + ( 1.0 - zibmlt ) * ( zqice_bot - zqcmlt(ji,2)  )
+          zqice_bot   =         zibmlt   * ( zqice_bot_mlt - zqcmltb(ji) )   &
+             &        + ( 1.0 - zibmlt ) * ( zqice_bot - zqcmltb(ji)  )
           qstbif_1d(ji) =         zibmlt   * qstbif_1d(ji)   &
              &           + ( 1.0 - zibmlt ) * zqstbif_bot
@@ -762,4 +805,9 @@
        END DO
        ! 
+       IF( wrk_not_released(1, 1,  2, 3, 4, 5, 6, 7, 8, 9,10,   &
+           &                   11,12,13,14,15,16,17,18,19,20,   &
+           &                   21,22,23,24,25,26,27)        )   &
+           CALL ctl_stop('lim_thd_zdf_2 : failed to release workspace arrays.')
+       !
     END SUBROUTINE lim_thd_zdf_2
 
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limtrp_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limtrp_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limtrp_2.F90	(revision 2715)
@@ -63,4 +63,10 @@
       !! ** action :
       !!---------------------------------------------------------------------
+      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY: zui_u  => wrk_2d_1, zvi_v => wrk_2d_2, zsm  => wrk_2d_3
+      USE wrk_nemo, ONLY: zs0ice => wrk_2d_4, zs0sn => wrk_2d_5, zs0a => wrk_2d_6
+      USE wrk_nemo, ONLY: zs0c0 => wrk_2d_7,  zs0c1 => wrk_2d_8, zs0c2 => wrk_2d_9, &
+                          zs0st => wrk_2d_10
+      !!
       INTEGER, INTENT(in) ::   kt     ! number of iteration
       !!
@@ -71,8 +77,9 @@
       REAL(wp) ::   zvbord , zcfl   , zusnit            !   -      -
       REAL(wp) ::   zrtt   , ztsn   , ztic1 , ztic2     !   -      -
-      REAL(wp), DIMENSION(jpi,jpj)  ::   zui_u , zvi_v , zsm             ! 2D workspace
-      REAL(wp), DIMENSION(jpi,jpj)  ::   zs0ice, zs0sn , zs0a            !  -      -
-      REAL(wp), DIMENSION(jpi,jpj)  ::   zs0c0 , zs0c1 , zs0c2 , zs0st   !  -      -
       !---------------------------------------------------------------------
+
+      IF( wrk_in_use(2, 1,2,3,4,5,6,7,8,9,10) ) THEN
+         CALL ctl_stop('lim_trp_2 : requested workspace arrays unavailable')   ;   RETURN
+      ENDIF
 
       IF( kt == nit000  )   CALL lim_trp_init_2      ! Initialization (first time-step only)
@@ -266,4 +273,6 @@
       ENDIF
       !
+      IF( wrk_not_released(2, 1,2,3,4,5,6,7,8,9,10) )   CALL ctl_stop('lim_trp_2 : failed to release workspace arrays')
+      !
    END SUBROUTINE lim_trp_2
 
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90	(revision 2715)
@@ -26,7 +26,8 @@
    USE ice_2
 
+   USE dianam          ! build name of file (routine)
    USE lbclnk
-   USE dianam          ! build name of file (routine)
    USE in_out_manager
+   USE lib_mpp         ! MPP library
    USE iom
    USE ioipsl
@@ -39,4 +40,5 @@
 #endif
    PUBLIC   lim_wri_state_2   ! called by dia_wri_state 
+   PUBLIC   lim_wri_alloc_2   ! called by nemogcm.F90
 
    INTEGER, PARAMETER                       ::   jpnoumax = 40   ! maximum number of variable for ice output
@@ -50,10 +52,12 @@
 
    INTEGER ::   nice, nhorid, ndim, niter, ndepid       ! ????
-   INTEGER , DIMENSION( jpij ) ::   ndex51              ! ????
-
-   REAL(wp)  ::            &  ! constant values
-      epsi16 = 1.e-16   ,  &
-      zzero  = 0.e0     ,  &
-      zone   = 1.e0
+   INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) :: ndex51   ! ????
+
+   REAL(wp) ::   epsi16 = 1.e-16_wp   ! constant values
+   REAL(wp) ::   zzero  = 0._wp       !     -      -
+   REAL(wp) ::   zone   = 1._wp       !     -      -
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   zcmo      ! Workspace array for netcdf writer. 
+
 
    !! * Substitutions
@@ -64,6 +68,17 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
+
+   INTEGER FUNCTION lim_wri_alloc_2()
+      !!-------------------------------------------------------------------
+      !!                  ***   ROUTINE lim_wri_alloc_2  ***
+      !!-------------------------------------------------------------------
+      ALLOCATE( ndex51(jpij), zcmo(jpi,jpj,jpnoumax), STAT=lim_wri_alloc_2)
+      !
+      IF( lk_mpp               )   CALL mpp_sum ( lim_wri_alloc_2 )
+      IF( lim_wri_alloc_2 /= 0 )   CALL ctl_warn('lim_wri_alloc_2: failed to allocate array ndex51')
+      !
+   END FUNCTION lim_wri_alloc_2
+
 
 #if ! defined key_iomput
@@ -85,4 +100,7 @@
       !!      of a day
       !!-------------------------------------------------------------------
+      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY: zfield => wrk_2d_1
+      !!
       INTEGER, INTENT(in) ::   kt     ! number of iteration
       !!
@@ -92,10 +110,13 @@
          &          zindh, zinda, zindb, ztmu
       REAL(wp), DIMENSION(1)                ::   zdept
-      REAL(wp), DIMENSION(jpi,jpj)          ::   zfield
-      REAL(wp), DIMENSION(jpi,jpj,jpnoumax) ::   zcmo
-      !!-------------------------------------------------------------------
+      !!-------------------------------------------------------------------
+
+      IF( wrk_in_use(2, 1) ) THEN
+         CALL ctl_stop('lim_wri_2 : requested workspace array unavailable')   ;   RETURN
+      ENDIF
                                                  !--------------------!
       IF( kt == nit000 ) THEN                    !   Initialisation   !
          !                                       !--------------------!
+
          CALL lim_wri_init_2 
                            
@@ -186,4 +207,6 @@
       IF( ( nn_fsbc * niter ) >= nitend )   CALL histclo( nice ) 
 
+      IF( wrk_not_released(2, 1) )   CALL ctl_stop('lim_wri_2 : failed to release workspace array.')
+      !
    END SUBROUTINE lim_wri_2
      
@@ -222,4 +245,8 @@
          field_19
       !!-------------------------------------------------------------------
+      !
+      IF( lim_wri_alloc_2() /= 0 ) THEN      ! allocate lim_wri arrrays
+         CALL ctl_stop( 'STOP', 'lim_wri_init_2 : unable to allocate standard arrays' )   ;   RETURN
+      ENDIF
 
       REWIND ( numnam_ice )                ! Read Namelist namicewri
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/limwri_dimg_2.h90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/limwri_dimg_2.h90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/limwri_dimg_2.h90	(revision 2715)
@@ -18,20 +18,19 @@
     INTEGER, INTENT(in) ::   kt     ! number of iteration
 
-    REAL(wp),DIMENSION(1) ::   zdept
+    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
+    INTEGER , SAVE ::   nice, nhorid, ndim, niter, ndepid
+    REAL(wp), SAVE, DIMENSION(jpi,jpj,jpnoumax) :: rcmoy
 
-    REAL(wp) :: &
-         zsto, zsec, zjulian,zout, &
-         zindh,zinda,zindb,  &
-         ztmu
-    REAL(wp), DIMENSION(jpi,jpj,jpnoumax) :: &
-         zcmo
-    REAL(wp), DIMENSION(jpi,jpj) ::  &
-         zfield
-    INTEGER, SAVE :: nmoyice, &  !: counter for averaging
-         &             nwf         !: number of fields to write on disk
-    INTEGER, SAVE,DIMENSION (:), ALLOCATABLE  :: nsubindex   !: subindex to be saved
-    ! according to namelist
+    INTEGER ::  ji, jj, jf, ii   ! dummy loop indices and array index
+    INTEGER :: iyear, iday, imon ! 
+    CHARACTER(LEN=80) :: clname, cltext, clmode
+    REAL(wp), DIMENSION(1) ::   zdept
+    REAL(wp) ::   zsto, zsec, zjulian,zout
+    REAL(wp) ::   zindh,zinda,zindb, ztmu
+    REAL(wp), DIMENSION(jpi,jpj,jpnoumax) ::   zcmo   !ARPDBGWORK
+    REAL(wp), DIMENSION(jpi,jpj)          ::   zfield
 
-    REAL(wp), SAVE, DIMENSION(jpi,jpj,jpnoumax) :: rcmoy
 #if ! defined key_diainstant
     LOGICAL, PARAMETER :: ll_dia_inst=.false.      ! local logical variable 
@@ -39,17 +38,8 @@
     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 ( kt == nit000 ) THEN 
-
+    IF( kt == nit000 ) THEN 
+       !
        CALL lim_wri_init_2 
 
@@ -57,5 +47,5 @@
        ii  = 0
 
-       IF (lwp ) THEN
+       IF(lwp ) THEN
           WRITE(numout,*) 'lim_wri_2 : Write ice outputs in dimg'
           WRITE(numout,*) '~~~~~~~~'
Index: trunk/NEMOGCM/NEMO/LIM_SRC_2/thd_ice_2.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_2/thd_ice_2.F90	(revision 2566)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_2/thd_ice_2.F90	(revision 2715)
@@ -12,9 +12,10 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE par_ice_2
 
    IMPLICIT NONE
    PRIVATE
+
+   PUBLIC thd_ice_alloc_2 ! Routine called by nemogcm.F90
 
    !! * Share Module variables
@@ -43,9 +44,9 @@
       cnscg                  !: ratio  rcpsn/rcpic
 
-   INTEGER , PUBLIC, DIMENSION(jpij) ::   &  !:
+   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   &  !:
       npb     ,   &   !: number of points where computations has to be done
       npac            !: correspondance between the points
 
-   REAL(wp), PUBLIC, DIMENSION(jpij) ::   &  !: 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   &  !: 
       qldif_1d    ,     &  !: corresponding to the 2D var  qldif
       qcmif_1d    ,     &  !: corresponding to the 2D var  qcmif
@@ -80,8 +81,45 @@
       dqla_ice_1d          !:    "                  "      dqla_ice
 
-   REAL(wp), PUBLIC, DIMENSION(jpij,jplayersp1) ::   &  !:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   &  !:
       tbif_1d              !: corresponding to the 2D var  tbif
 
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM2 3.3 , UCL - NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+ CONTAINS
+
+   INTEGER FUNCTION thd_ice_alloc_2()
+      !!----------------------------------------------------------------------
+      USE lib_mpp        ! MPP library
+      INTEGER :: ierr(4)
+      !!----------------------------------------------------------------------
+      !
+      ierr(:) = 0
+      !
+      ALLOCATE( npb(jpij), npac(jpij),                             &
+         &      qldif_1d(jpij), qcmif_1d(jpij), thcm_1d(jpij),     &
+         &      fstbif_1d(jpij), fltbif_1d(jpij), fscbq_1d(jpij),  &
+         &      qsr_ice_1d(jpij),fr1_i0_1d(jpij), fr2_i0_1d(jpij), Stat=ierr(1))
+         !
+      ALLOCATE( qns_ice_1d(jpij), qfvbq_1d(jpij), sist_1d(jpij), tfu_1d(jpij), &
+         &      sprecip_1d(jpij), h_snow_1d(jpij),h_ice_1d(jpij),frld_1d(jpij),&
+         &      qstbif_1d(jpij),  fbif_1d(jpij),  Stat=ierr(2))
+         !
+      ALLOCATE( rdmicif_1d(jpij), rdmsnif_1d(jpij), qlbbq_1d(jpij),   &
+         &      dmgwi_1d(jpij)  , dvsbq_1d(jpij)  , rdvomif_1d(jpij), &
+         &      dvbbq_1d(jpij)  , dvlbq_1d(jpij)  , dvnbq_1d(jpij)  , &
+         &      Stat=ierr(3))
+         !
+      ALLOCATE( dqns_ice_1d(jpij) ,qla_ice_1d(jpij), dqla_ice_1d(jpij), &
+         &      tbif_1d(jpij, jplayersp1), Stat=ierr(4))
+         !
+      thd_ice_alloc_2 = MAXVAL(ierr)
+      IF( thd_ice_alloc_2 /= 0 )   CALL ctl_warn('thd_ice_alloc_2: failed to allocate arrays')
+      !
+   END FUNCTION thd_ice_alloc_2
+
+#endif
    !!======================================================================
-#endif
 END MODULE thd_ice_2
