Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/ice_2.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/ice_2.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/ice_2.F90	(revision 2613)
@@ -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
@@ -16,6 +17,5 @@
    PRIVATE
    
-   ! Routine accessibility
-   PUBLIC    ice_alloc_2  !  Called in nemogcm.F90
+   PUBLIC    ice_alloc_2  !  Called in iceini_2.F90
 
    INTEGER , PUBLIC ::   numit     !: ice iteration index
@@ -124,93 +124,77 @@
    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
+
+   FUNCTION ice_alloc_2()
+      !!-----------------------------------------------------------------
+      !!               *** FUNCTION ice_alloc_2 ***
+      !!-----------------------------------------------------------------
+      USE in_out_manager, ONLY: ctl_warn
+      INTEGER :: ice_alloc_2     ! return value
+      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
    !!----------------------------------------------------------------------
    !!   Default option         Empty module        NO LIM 2.0 sea-ice model
    !!----------------------------------------------------------------------
 #endif
-
-   !!----------------------------------------------------------------------
+   !!-----------------------------------------------------------------
    !! NEMO/LIM2 3.3 , UCL - NEMO Consortium (2010)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!======================================================================
-
-#if defined key_lim2
-   CONTAINS
-
-     FUNCTION ice_alloc_2()
-        !!-----------------------------------------------------------------
-        !!               *** Routine ice_alloc_2 ***
-        !!-----------------------------------------------------------------
-        USE in_out_manager, ONLY: ctl_warn
-        IMPLICIT none
-        INTEGER :: ice_alloc_2
-        ! Local variables
-        INTEGER :: ierr(9)
-        !!-----------------------------------------------------------------
-
-        ierr(:) = 0
-
-        ! What could be one huge allocate statement is broken-up to try to
-        ! stay within Fortran's max-line length limit.
-        ALLOCATE(ahiu(jpi,jpj), ahiv(jpi,jpj), &
-                 pahu(jpi,jpj), pahv(jpi,jpj), &
-                 ust2s(jpi,jpj), Stat=ierr(1))
-
-        ALLOCATE(                              &
-#if defined key_lim2_vp
-                 hsnm(jpi,jpj), hicm(jpi,jpj), &
-#else
-                 stress1_i(jpi,jpj), stress2_i(jpi,jpj), stress12_i(jpi,jpj), &
-                 delta_i(jpi,jpj),   divu_i(jpi,jpj),    shear_i(jpi,jpj),    &
-                 at_i(jpi,jpj), hsnm(jpi,jpj), hicm(jpi,jpj),                 &
-#endif
-                 Stat=ierr(2))
-
-        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))
-
-        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)THEN
-           CALL ctl_warn('ice_alloc_2: failed to allocate arrays.')
-        END IF
-
-     END FUNCTION ice_alloc_2
-
-#endif
-
 END MODULE ice_2
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/iceini_2.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/iceini_2.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/iceini_2.F90	(revision 2613)
@@ -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,17 +13,19 @@
    !!   '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 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 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
       
@@ -33,5 +36,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 +48,23 @@
       !! ** 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' )
+
       !                                ! Open the namelist file 
       CALL ctl_opn( numnam_ice, 'namelist_ice', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp ) 
@@ -61,6 +82,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: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limadv_2.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limadv_2.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limadv_2.F90	(revision 2613)
@@ -58,10 +58,9 @@
       !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
       !!--------------------------------------------------------------------
-      USE wrk_nemo, ONLY: wrk_use, wrk_release
-      USE wrk_nemo, ONLY: zf0 => wrk_2d_11, zfx => wrk_2d_12, zfy => wrk_2d_13
-      USE wrk_nemo, ONLY: zbet => wrk_2d_14, zfm => wrk_2d_15, zfxx => wrk_2d_16
-      USE wrk_nemo, ONLY: zfyy => wrk_2d_17, zfxy => wrk_2d_18, zalg => wrk_2d_19
-      USE wrk_nemo, ONLY: zalg1 => wrk_2d_20, zalg1q => wrk_2d_21
-      !!
+      USE wrk_nemo, ONLY:   wrk_use, wrk_release
+      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)
@@ -71,5 +70,5 @@
       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
@@ -78,7 +77,6 @@
       !---------------------------------------------------------------------
 
-      IF(.NOT. wrk_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
+      IF( .NOT. wrk_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
       END IF
 
@@ -226,6 +224,6 @@
       ENDIF
       !
-      IF(.NOT. wrk_release(2, 11,12,13,14,15,16,17,18,19,20,21))THEN
-         CALL ctl_stop('lim_adv_x_2 : failed to release workspace arrays.')
+      IF( .NOT. wrk_release(2, 11,12,13,14,15,16,17,18,19,20,21) ) THEN
+         CALL ctl_stop( 'lim_adv_x_2 : failed to release workspace arrays.' )
       END IF
       !
@@ -247,9 +245,8 @@
       !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
       !!---------------------------------------------------------------------
-      USE wrk_nemo, ONLY: wrk_use, wrk_release
-      USE wrk_nemo, ONLY: zf0 => wrk_2d_11, zfx => wrk_2d_12, zfy => wrk_2d_13
-      USE wrk_nemo, ONLY: zbet => wrk_2d_14, zfm => wrk_2d_15, zfxx => wrk_2d_16
-      USE wrk_nemo, ONLY: zfyy => wrk_2d_17, zfxy => wrk_2d_18, zalg => wrk_2d_19
-      USE wrk_nemo, ONLY: zalg1 => wrk_2d_20, zalg1q => wrk_2d_21
+      USE wrk_nemo, ONLY:   wrk_use, wrk_release
+      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
@@ -267,7 +264,6 @@
       !---------------------------------------------------------------------
 
-      IF(.NOT. wrk_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
+      IF(.NOT. wrk_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
 
@@ -418,6 +414,6 @@
       ENDIF
       !
-      IF(.NOT. wrk_release(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.')
+      IF( .NOT. wrk_release(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
       !
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limdia_2.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limdia_2.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limdia_2.F90	(revision 2613)
@@ -29,5 +29,4 @@
 
    PUBLIC               lim_dia_2          ! called by sbc_ice_lim_2
-   PUBLIC               lim_dia_alloc_2    ! called by nemogcm
 
    INTEGER, PUBLIC ::   ntmoy   = 1 ,   &  !: instantaneous values of ice evolution or averaging ntmoy
@@ -63,23 +62,5 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
-
-   FUNCTION lim_dia_alloc_2()
-      !!--------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_dia_2  ***
-      !!--------------------------------------------------------------------
-      IMPLICIT none
-      INTEGER :: lim_dia_alloc_2
-      !!--------------------------------------------------------------------
-
-      ALLOCATE(aire(jpi,jpj), Stat=lim_dia_alloc_2)
-
-      IF(lim_dia_alloc_2 /= 0)THEN
-         CALL ctl_warn('lim_dia_alloc_2: failed to allocate array aire.')
-      END IF
-
-   END FUNCTION lim_dia_alloc_2
-
 
    SUBROUTINE lim_dia_2( kt )
@@ -192,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 '
@@ -214,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: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limdyn_2.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limdyn_2.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limdyn_2.F90	(revision 2613)
@@ -58,7 +58,8 @@
       !!              - treatment of the case if no ice dynamic
       !!---------------------------------------------------------------------
-      USE wrk_nemo, ONLY: wrk_use, wrk_release
-      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
+      USE wrk_nemo, ONLY:   wrk_use, wrk_release
+      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
       !!
@@ -66,14 +67,12 @@
       INTEGER  ::   i_j1, i_jpj        ! Starting/ending j-indices for rheology
       REAL(wp) ::   zcoef              ! temporary scalar
-      REAL(wp), POINTER, DIMENSION(:)     ::   zind     ! i-averaged indicator of sea-ice
-      REAL(wp), POINTER, DIMENSION(:)     ::   zmsk     ! i-averaged of tmask
+      REAL(wp), POINTER, DIMENSION(:) ::   zind     ! i-averaged indicator of sea-ice
+      REAL(wp), POINTER, DIMENSION(:) ::   zmsk     ! i-averaged of tmask
       !!---------------------------------------------------------------------
 
-      IF( (.NOT. wrk_use(1, 1,2)) .OR. (.NOT. wrk_use(2, 1,2)) )THEN
-         CALL ctl_stop('lim_dyn_2 : requested workspace arrays unavailable.')
-         RETURN
+      IF(  .NOT. wrk_use(1, 1,2)  .OR.  .NOT. wrk_use(2, 1,2)  ) THEN
+         CALL ctl_stop( 'lim_dyn_2 : requested workspace arrays unavailable.' )   ;   RETURN
       END IF
-      ! Set-up pointers to sub-arrays of workspaces
-      zind => wrk_1d_1(1:jpj)
+      zind => wrk_1d_1(1:jpj)      ! Set-up pointers to sub-arrays of workspaces
       zmsk => wrk_1d_2(1:jpj)
 
@@ -103,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
             !
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limhdf_2.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limhdf_2.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limhdf_2.F90	(revision 2613)
@@ -25,10 +25,9 @@
 
    PUBLIC   lim_hdf_2         ! called by limtrp_2.F90
-   PUBLIC   lim_hdf_alloc_2   ! called by nemogcm.F90
 
    LOGICAL  ::   linit = .TRUE.   ! ! initialization flag (set to flase after the 1st call)
    REAL(wp) ::   epsi04 = 1e-04   ! constant
    
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   efact   ! ???
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   efact   ! metric coefficient
 
    !! * Substitution 
@@ -40,20 +39,4 @@
    !!----------------------------------------------------------------------
 CONTAINS
-
-   FUNCTION lim_hdf_alloc_2()
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_hdf_alloc_2  ***
-      !!-------------------------------------------------------------------
-      INTEGER :: lim_hdf_alloc_2
-      !!-------------------------------------------------------------------
-      !
-      ALLOCATE( efact(jpi,jpj) , STAT=lim_hdf_alloc_2 )
-      !
-      IF( lim_hdf_alloc_2 /= 0 ) THEN
-         CALL ctl_warn( 'lim_hdf_alloc_2: failed to allocate efact array.' )
-      ENDIF
-      !
-   END FUNCTION lim_hdf_alloc_2
-
 
    SUBROUTINE lim_hdf_2( ptab )
@@ -74,6 +57,6 @@
       REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   ptab   ! Field on which the diffusion is applied  
       !
-      INTEGER  ::  ji, jj      ! dummy loop indices
-      INTEGER  ::  its, iter   ! local integers
+      INTEGER  ::   ji, jj            ! dummy loop indices
+      INTEGER  ::   its, iter, ierr   ! local integers
       REAL(wp) ::   zalfa, zrlxint, zconv, zeps   ! local scalars
       CHARACTER (len=55) :: charout
@@ -87,8 +70,10 @@
       !
       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.
-               efact(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
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90	(revision 2613)
@@ -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
@@ -36,7 +39,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_alloc_2   ! called by nemogcm.F90
+   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 
@@ -53,5 +56,5 @@
 #  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)
@@ -63,17 +66,13 @@
       !!             ***  ROUTINE lim_sbc_alloc_2 ***
       !!-------------------------------------------------------------------
-      IMPLICIT none
       INTEGER :: lim_sbc_alloc_2
       !!-------------------------------------------------------------------
-
-      ALLOCATE(soce_0(jpi,jpj),   sice_0(jpi,jpj),   &
-               utau_oce(jpi,jpj), vtau_oce(jpi,jpj), &
-               tmod_io(jpi,jpj),                     &
-               Stat=lim_sbc_alloc_2)
-
-      IF(lim_sbc_alloc_2 /= 0)THEN
-         CALL ctl_warn('lim_sbc_alloc_2: failed to allocate arrays.')
-      END IF
-
+      !
+      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
 
@@ -121,27 +120,6 @@
          RETURN
       END IF
-      ! Set-up pointers to sub-arrays of 3d workspaces
-      zalb  => wrk_3d_4(:,:,1:1)
+      zalb  => wrk_3d_4(:,:,1:1)      ! Set-up pointers to sub-arrays of 3d workspaces
       zalbp => wrk_3d_5(:,:,1:1)
-
-      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
-         !
-      ENDIF
 
       !------------------------------------------!
@@ -260,7 +238,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)
@@ -321,16 +298,6 @@
       !
       IF(.NOT. wrk_use(2, 1,2))THEN
-         CALL ctl_stop('lim_sbc_tau_2 : requested workspace arrays unavailable.')
-         RETURN
+         CALL ctl_stop('lim_sbc_tau_2 : requested workspace arrays unavailable.')   ;   RETURN
       END IF
-      !
-      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
-      ENDIF
       !
       SELECT CASE( cp_ice_msh )     
@@ -446,9 +413,40 @@
          &                       tab2d_2=vtau, clinfo2=' vtau    : '        , mask2=vmask )
       !  
-      IF(.NOT. wrk_release(2, 1,2))THEN
-         CALL ctl_stop('lim_sbc_tau_2 : failed to release workspace arrays.')
-      END IF
-
+      IF(.NOT. wrk_release(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() /= 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: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limtab_2.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limtab_2.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limtab_2.F90	(revision 2613)
@@ -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: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90	(revision 2613)
@@ -53,8 +53,7 @@
    INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) :: ndex51   ! ????
 
-   REAL(wp)  ::            &  ! constant values
-      epsi16 = 1.e-16   ,  &
-      zzero  = 0.e0     ,  &
-      zone   = 1.e0
+   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. 
@@ -68,5 +67,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -78,11 +76,10 @@
       INTEGER :: lim_wri_alloc_2
       !!-------------------------------------------------------------------
-
-      ALLOCATE(ndex51(jpij), zcmo(jpi,jpj,jpnoumax), Stat=lim_wri_alloc_2)
-
-      IF(lim_wri_alloc_2 /= 0)THEN
-         CALL ctl_warn('lim_wri_alloc_2: failed to allocate array ndex51')
-      END IF
-
+      !
+      ALLOCATE( ndex51(jpij), zcmo(jpi,jpj,jpnoumax), STAT=lim_wri_alloc_2)
+      !
+      IF( lk_mpp               )   CALL mpp_sum( ierr )
+      IF( lim_wri_alloc_2 /= 0 )   CALL ctl_warn('lim_wri_alloc_2: failed to allocate array ndex51')
+      !
    END FUNCTION lim_wri_alloc_2
 
@@ -125,4 +122,5 @@
       IF( kt == nit000 ) THEN                    !   Initialisation   !
          !                                       !--------------------!
+
          CALL lim_wri_init_2 
                            
@@ -253,4 +251,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: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limwri_dimg_2.h90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limwri_dimg_2.h90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/LIM_SRC_2/limwri_dimg_2.h90	(revision 2613)
@@ -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 !ARPDBGWORK
-    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: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 2613)
@@ -32,7 +32,6 @@
    LOGICAL ::   ln_vol  = .false.     !: =T volume correction             
    LOGICAL ::   ln_mask = .false.     !: =T read bdymask from file
-   LOGICAL ::   ln_clim = .false.     !: if true, we assume that bdy data files contain 
-   !                                    !  1 time dump  (-->bdy forcing will be constant) 
-   !                                    !  or 12 months (-->bdy forcing will be cyclic) 
+   LOGICAL ::   ln_clim = .false.     !: =T bdy data files contain  1 time dump  (-->bdy forcing will be constant) 
+   !                                  !                         or 12 months     (-->bdy forcing will be cyclic) 
    LOGICAL ::   ln_dyn_fla  = .false. !: =T Flather boundary conditions on barotropic velocities
    LOGICAL ::   ln_dyn_frs  = .false. !: =T FRS boundary conditions on velocities
@@ -40,8 +39,8 @@
    LOGICAL ::   ln_ice_frs  = .false. !: =T FRS boundary conditions on seaice (leads fraction, ice depth, snow depth)
    !
-   INTEGER ::   nn_rimwidth = 7         !: boundary rim width
-   INTEGER ::   nn_dtactl   = 1	        !: = 0 use the initial state as bdy dta or = 1 read it in a NetCDF file
-   INTEGER ::   nn_volctl   = 1         !: = 0 the total volume will have the variability of the surface Flux E-P 
-   !                                    !  = 1 the volume will be constant during all the integration.
+   INTEGER ::   nn_rimwidth = 7       !: boundary rim width
+   INTEGER ::   nn_dtactl   = 1	     !: = 0 use the initial state as bdy dta ; = 1 read it in a NetCDF file
+   INTEGER ::   nn_volctl   = 1       !: = 0 the total volume will have the variability of the surface Flux E-P 
+   !                                  !  = 1 the volume will be constant during all the integration.
 
    !!----------------------------------------------------------------------
@@ -63,5 +62,5 @@
    INTEGER, DIMENSION(jpbdim,jpbgrd) ::   nbmap           !: Indices of data in file for data in memory 
     
-   REAL(wp) ::   bdysurftot	                          !: Lateral surface of unstructured open boundary
+   REAL(wp) ::   bdysurftot	                            !: Lateral surface of unstructured open boundary
 
    REAL(wp), DIMENSION(jpbdim)        ::   flagu, flagv   !: Flag for normal velocity compnt for velocity components
@@ -75,8 +74,29 @@
    REAL(wp), DIMENSION(jpbdim) ::   utide, vtide          !: Tidal boundary array : U and V
 #if defined key_lim2
-   REAL(wp), DIMENSION(jpbdim) ::  &
-      frld_bdy, hicif_bdy,  & !: Now clim of ice leads fraction, ice  
-      hsnif_bdy               !: thickness and snow thickness
+   REAL(wp), DIMENSION(jpbdim) ::   frld_bdy    !: now ice leads fraction climatology   
+   REAL(wp), DIMENSION(jpbdim) ::   hicif_bdy   !: Now ice  thickness climatology
+   REAL(wp), DIMENSION(jpbdim) ::   hsnif_bdy   !: now snow thickness
 #endif
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! $Id$ 
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   FUNCTION bdy_oce_alloc()
+      !!----------------------------------------------------------------------
+      INTEGER :: bdy_oce_alloc
+      !!----------------------------------------------------------------------
+      !
+      ALLOCATE( bdytmask(jpi,jpj) , tbdy(jpbdim,jpk) , sbdy(jpbdim,jpk) ,     &
+         &      bdyumask(jpi,jpj) , ubdy(jpbdim,jpk) ,                        &
+         &      bdyvmask(jpi,jpj) , vbdy(jpbdim,jpk) ,                    STAT=bdy_oce_alloc )
+         !
+      IF( lk_mpp             )   CALL mpp_sum ( bdy_oce_alloc )
+      IF( bdy_oce_alloc /= 0 )   CALL ctl_warn('bdy_oce_alloc: failed to allocate arrays.')
+      !
+   END FUNCTION bdy_oce_alloc
 
 #else
@@ -87,26 +107,4 @@
 #endif
 
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!======================================================================
-#if defined key_bdy 
-CONTAINS
-
-   FUNCTION bdy_oce_alloc()
-      INTEGER :: bdy_oce_alloc
-
-      ALLOCATE(bdytmask(jpi,jpj), bdyumask(jpi,jpj), bdyvmask(jpi,jpj), &
-               tbdy(jpbdim,jpk),  sbdy(jpbdim,jpk),                     &
-               ubdy(jpbdim,jpk),  vbdy(jpbdim,jpk),                     &
-               Stat=bdy_oce_alloc)
- 
-      IF(bdy_oce_alloc /= 0)THEN
-         CALL ctl_warn('bdy_oce_alloc: failed to allocate arrays.')
-      END IF
-
-   END FUNCTION bdy_oce_alloc
-#endif
-
 END MODULE bdy_oce
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 2613)
@@ -33,7 +33,7 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
    !! $Id$ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 CONTAINS
@@ -44,30 +44,27 @@
       !!         
       !! ** Purpose :   Initialization of the dynamics and tracer fields with 
-      !!      unstructured open boundaries.
+      !!              unstructured open boundaries.
       !!
-      !! ** Method  :  Read initialization arrays (mask, indices) to identify 
-      !!               an unstructured open boundary
+      !! ** Method  :   Read initialization arrays (mask, indices) to identify 
+      !!              an unstructured open boundary
       !!
       !! ** Input   :  bdy_init.nc, input file for unstructured open boundaries
       !!----------------------------------------------------------------------      
-      INTEGER ::   ii, ij, ik, igrd, ib, ir   ! dummy loop indices
-      INTEGER ::   icount, icountr
-      INTEGER ::   ib_len, ibr_max
-      INTEGER ::   iw, ie, is, in 
-      INTEGER ::   inum                 ! local logical unit
-      INTEGER ::   id_dummy             ! local integers
-      INTEGER ::   igrd_start, igrd_end ! start and end of loops on igrd
+      INTEGER  ::   ii, ij, ik, igrd, ib, ir   ! dummy loop indices
+      INTEGER  ::   icount, icountr, ib_len, ibr_max   ! local integers
+      INTEGER  ::   iw, ie, is, in, inum, id_dummy     !   -       -
+      INTEGER  ::   igrd_start, igrd_end               !   -       -
+      REAL(wp) ::   zefl, zwfl, znfl, zsfl              ! local scalars
       INTEGER, DIMENSION (2)             ::   kdimsz
       INTEGER, DIMENSION(jpbdta, jpbgrd) ::   nbidta, nbjdta   ! Index arrays: i and j indices of bdy dta
       INTEGER, DIMENSION(jpbdta, jpbgrd) ::   nbrdta           ! Discrete distance from rim points
-      REAL(wp) :: zefl, zwfl, znfl, zsfl                       ! temporary scalars
-      REAL(wp) , DIMENSION(jpidta,jpjdta) ::   zmask           ! global domain mask
-      REAL(wp) , DIMENSION(jpbdta,1)      ::   zdta            ! temporary array 
-      CHARACTER(LEN=80),DIMENSION(6)      ::   clfile
+      REAL(wp), DIMENSION(jpidta,jpjdta) ::   zmask            ! global domain mask
+      REAL(wp), DIMENSION(jpbdta,1)      ::   zdta             ! temporary array 
+      CHARACTER(LEN=80),DIMENSION(6)     ::   clfile
       !!
-      NAMELIST/nambdy/cn_mask, cn_dta_frs_T, cn_dta_frs_U, cn_dta_frs_V,          &
-         &            cn_dta_fla_T, cn_dta_fla_U, cn_dta_fla_V,              &
-         &            ln_tides, ln_clim, ln_vol, ln_mask,                &
-         &            ln_dyn_fla, ln_dyn_frs, ln_tra_frs,ln_ice_frs,     &
+      NAMELIST/nambdy/cn_mask, cn_dta_frs_T, cn_dta_frs_U, cn_dta_frs_V,   &
+         &            cn_dta_fla_T, cn_dta_fla_U, cn_dta_fla_V,            &
+         &            ln_tides, ln_clim, ln_vol, ln_mask,                  &
+         &            ln_dyn_fla, ln_dyn_frs, ln_tra_frs,ln_ice_frs,       &
          &            nn_dtactl, nn_rimwidth, nn_volctl
       !!----------------------------------------------------------------------
@@ -77,4 +74,7 @@
       IF(lwp) WRITE(numout,*) '~~~~~~~~'
       !
+      !                                      ! allocate bdy_oce arrays
+      IF( bdy_oce_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'bdy_init : unable to allocate arrays' )
+
       IF( jperio /= 0 )   CALL ctl_stop( 'Cyclic or symmetric,',   &
          &                               ' and unstructured open boundary condition are not compatible' )
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90	(revision 2613)
@@ -7,5 +7,5 @@
    !!            3.3  !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase + merge TRC-TRA
    !!----------------------------------------------------------------------
-#if defined key_diaar5
+#if defined key_diaar5   || defined key_esopa
    !!----------------------------------------------------------------------
    !!   'key_diaar5'  :                           activate ar5 diagnotics
@@ -50,12 +50,10 @@
       INTEGER :: dia_ar5_alloc
       !!----------------------------------------------------------------------
-
-      ALLOCATE(area(jpi,jpj), thick0(jpi,jpj), sn0(jpi,jpj,jpk), &
-               Stat=dia_ar5_alloc)
-
-      IF(dia_ar5_alloc /= 0)THEN
-         CALL ctl_warn('dia_ar5_alloc: failed to allocate arrays')
-      END IF
-
+      !
+      ALLOCATE( area(jpi,jpj), thick0(jpi,jpj) , sn0(jpi,jpj,jpk) , STAT=dia_ar5_alloc )
+      !
+      IF( lk_mpp             )   CALL mpp_sum ( dia_ar5_alloc )
+      IF( dia_ar5_alloc /= 0 )   CALL ctl_warn('dia_ar5_alloc: failed to allocate arrays')
+      !
    END FUNCTION dia_ar5_alloc
 
@@ -66,5 +64,4 @@
       !!
       !! ** Purpose :   compute and output some AR5 diagnostics
-      !!
       !!----------------------------------------------------------------------
       USE wrk_nemo, ONLY: wrk_use, wrk_release
@@ -82,6 +79,5 @@
           (.NOT. wrk_use(3, 1,2)) .OR. &
           (.NOT. wrk_use(4, 1)) )THEN
-         CALL ctl_stop('dia_ar5: requested workspace arrays unavailable')
-         RETURN
+         CALL ctl_stop('dia_ar5: requested workspace arrays unavailable')   ;   RETURN
       END IF
 
@@ -190,8 +186,10 @@
       !
       IF(.NOT. wrk_use(4, 1))THEN
-         CALL ctl_stop('dia_ar5_init: requested workspace array unavailable.')
-         RETURN
+         CALL ctl_stop('dia_ar5_init: requested workspace array unavailable.')   ;   RETURN
       END IF
       zsaldta => wrk_4d_1(:,:,:,1:2)
+
+      !                                      ! allocate dia_ar5 arrays
+      IF( dia_ar5_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dia_ar5_init : unable to allocate arrays' )
 
       area(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diadimg.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diadimg.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diadimg.F90	(revision 2613)
@@ -6,5 +6,4 @@
 # if defined key_dimgout
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and tracers 
    USE dom_oce         ! ocean space and time domain
@@ -15,17 +14,15 @@
    PRIVATE
 
-   !! * Accessibility
    PUBLIC dia_wri_dimg            ! called by trd_mld (eg)
    PUBLIC dia_wri_dimg_alloc      ! called by nemo_alloc in nemogcm.F90
 
+
+   !! These workspace arrays are inside the module so that we can make them
+   !! allocatable in a clean way. Not done in wrk_nemo because these are of KIND(sp).
+   REAL(sp), ALLOCATABLE, SAVE, DIMENSION(:,:) :: z42d    ! 2d temporary workspace (sp)
+   REAL(sp), ALLOCATABLE, SAVE, DIMENSION(:)   :: z4dep   ! vertical level (sp)
+
    !! * Substitutions
 #  include "domzgr_substitute.h90"
-
-   !! These workspace arrays are inside the module so that we can make them
-   !! allocatable in a clean way. Not done in wrk_nemo because these are
-   !! of KIND(sp).
-   REAL(sp), ALLOCATABLE, SAVE, DIMENSION(:,:) :: z42d  ! 2d temporary workspace (sp)
-   REAL(sp), ALLOCATABLE, SAVE,   DIMENSION(:) :: z4dep ! vertical level (sp)
-
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -33,41 +30,36 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
-  FUNCTION dia_wri_dimg_alloc()
-     !!---------------------------------------------------------------------
-     !!        *** ROUTINE dia_wri_dimg_alloc ***
-     !!
-     !!---------------------------------------------------------------------
-     INTEGER :: dia_wri_dimg_alloc
-     !!---------------------------------------------------------------------
-
-     ALLOCATE(z42d(jpi,jpj), z4dep(jpk), Stat=dia_wri_dimg_alloc)
-
-     IF(dia_wri_dimg_alloc /= 0)THEN
-        CALL ctl_warn('dia_wri_dimg_alloc: allocation of array failed.')
-     END IF
-
+   FUNCTION dia_wri_dimg_alloc()
+      !!---------------------------------------------------------------------
+      !!        *** ROUTINE dia_wri_dimg_alloc ***
+      !!
+      !!---------------------------------------------------------------------
+      INTEGER :: dia_wri_dimg_alloc   ! return value
+      !!---------------------------------------------------------------------
+      !
+      ALLOCATE( z42d(jpi,jpj), z4dep(jpk), STAT=dia_wri_dimg_alloc )
+      !
+      IF( lk_mpp                  )   CALL mpp_sum ( dia_wri_dimg_alloc )
+      IF( dia_wri_dimg_alloc /= 0 )   CALL ctl_warn('dia_wri_dimg_alloc: allocation of array failed.')
+      !
   END FUNCTION dia_wri_dimg_alloc
 
 
-  SUBROUTINE dia_wri_dimg(cd_name, cd_text, ptab, klev, cd_type , ksubi )
+  SUBROUTINE dia_wri_dimg( cd_name, cd_text, ptab, klev, cd_type , ksubi )
     !!-------------------------------------------------------------------------
     !!        *** ROUTINE dia_wri_dimg ***
     !!
-    !! ** Purpose : write ptab in the dimg file cd_name, with comment cd_text.
-    !!       ptab has klev x 2D fields
+    !! ** Purpose :   write ptab in the dimg file cd_name, with comment cd_text.
+    !!              ptab has klev x 2D fields
     !!
-    !! ** Action :
-    !!       Define header variables from the config parameters
-    !!       Open the dimg file on unit inum = 14 ( IEEE I4R4 file )
-    !!       Write header on record 1
-    !!       Write ptab on the following klev records
+    !! ** Action :   Define header variables from the config parameters
+    !!               Open the dimg file on unit inum = 14 ( IEEE I4R4 file )
+    !!               Write header on record 1
+    !!               Write ptab on the following klev records
     !!
-    !! History :
-    !!   03-12 (J.M. Molines ) : Original. Replace ctl_opn, writn2d
+    !! History :  2003-12 (J.M. Molines ) : Original. Replace ctl_opn, writn2d
     !!---------------------------------------------------------------------------
-    !! * Arguments
     CHARACTER(len=*),INTENT(in) ::   &
          &                            cd_name,  &  ! dimg file name
@@ -91,4 +83,7 @@
     CHARACTER(LEN=4) :: clver='@!01'           ! dimg string identifier
     !!---------------------------------------------------------------------------
+
+    !                                      ! allocate dia_wri_dimg array
+    IF( dia_wri_dimg_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dia_wri_dimg : unable to allocate arrays' )
 
     !! * Initialisations
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90	(revision 2613)
@@ -21,4 +21,5 @@
    USE phycst          ! physical constants
    USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! MPP library
    USE iom             ! I/O library
 
@@ -29,15 +30,15 @@
    PUBLIC   dia_hth_alloc ! routine called by nemogcm.F90
 
-   LOGICAL , PUBLIC, PARAMETER          ::   lk_diahth = .TRUE.   !: thermocline-20d depths flag
+   LOGICAL , PUBLIC, PARAMETER          ::   lk_diahth = .TRUE.    !: thermocline-20d depths flag
    ! note: following variables should move to local variables once iom_put is always used 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hth                  !: depth of the max vertical temperature gradient [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hd20                 !: depth of 20 C isotherm                         [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hd28                 !: depth of 28 C isotherm                         [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   htc3                 !: heat content of first 300 m                    [W]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hth    !: depth of the max vertical temperature gradient [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hd20   !: depth of 20 C isotherm                         [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hd28   !: depth of 28 C isotherm                         [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   htc3   !: heat content of first 300 m                    [W]
 
    !! * Substitutions
 #  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -46,14 +47,13 @@
 
    FUNCTION dia_hth_alloc()
-     !!---------------------------------------------------------------------
-      IMPLICIT none
+      !!---------------------------------------------------------------------
       INTEGER :: dia_hth_alloc
-
-      ALLOCATE(hth(jpi,jpj), hd20(jpi,jpj), hd28(jpi,jpj), htc3(jpi,jpj), &
-               Stat=dia_hth_alloc)
-
-      IF(dia_hth_alloc /= 0)THEN
-         CALL ctl_warn('dia_hth_alloc: failed to allocate arrays.')
-      END IF
+      !!---------------------------------------------------------------------
+      !
+      ALLOCATE(hth(jpi,jpj), hd20(jpi,jpj), hd28(jpi,jpj), htc3(jpi,jpj), STAT=dia_hth_alloc)
+      !
+      IF( lk_mpp           )   CALL mpp_sum ( dia_hth_alloc )
+      IF(dia_hth_alloc /= 0)   CALL ctl_warn('dia_hth_alloc: failed to allocate arrays.')
+      !
    END FUNCTION dia_hth_alloc
 
@@ -117,9 +117,7 @@
                      zmaxdzT(jpi,jpj), &
                      zthick(jpi,jpj),  &
-                     zdelr(jpi,jpj), Stat=ji)
-            IF(ji /= 0)THEN
-               WRITE(*,*) 'ERROR: allocation of arrays failed in dia_hth'
-               CALL mppabort()
-            END IF
+                     zdelr(jpi,jpj), STAT=ji)
+            IF( lk_mpp  )   CALL mpp_sum(ji)
+            IF( ji /= 0 )   CALL ctl_stop( 'STOP', 'dia_hth : unable to allocate standard ocean arrays' )
          END IF
 
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 2613)
@@ -75,19 +75,20 @@
 CONTAINS
 
-  FUNCTION dia_wri_alloc()
-    !!----------------------------------------------------------------------
-    IMPLICIT none
-    INTEGER :: dia_wri_alloc
-    INTEGER, DIMENSION(2) :: ierr
-    !!----------------------------------------------------------------------
-    
-    ierr = 0
-
-    ALLOCATE(ndex_hT(jpi*jpj), ndex_hU(jpi*jpj), ndex_hV(jpi*jpj), &
-             ndex_T(jpi*jpj*jpk), ndex_U(jpi*jpj*jpk), ndex_V(jpi*jpj*jpk), &
-             Stat=ierr(1))
-
-    dia_wri_alloc = MAXVAL(ierr)
-
+   FUNCTION dia_wri_alloc()
+      !!----------------------------------------------------------------------
+      IMPLICIT none
+      INTEGER :: dia_wri_alloc
+      INTEGER, DIMENSION(2) :: ierr
+      !!----------------------------------------------------------------------
+      !
+      ierr = 0
+      !
+      ALLOCATE( ndex_hT(jpi*jpj) , ndex_T(jpi*jpj*jpk) ,     &
+         &      ndex_hU(jpi*jpj) , ndex_U(jpi*jpj*jpk) ,     &
+         &      ndex_hV(jpi*jpj) , ndex_V(jpi*jpj*jpk) , STAT=ierr(1) )
+         !
+      dia_wri_alloc = MAXVAL(ierr)
+      IF( lk_mpp )   CALL mpp_sum( ierr )
+      !
   END FUNCTION dia_wri_alloc
 
@@ -106,4 +107,5 @@
    !!   'key_iomput'                                        use IOM library
    !!----------------------------------------------------------------------
+
    SUBROUTINE dia_wri( kt )
       !!---------------------------------------------------------------------
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diawri_dimg.h90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diawri_dimg.h90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DIA/diawri_dimg.h90	(revision 2613)
@@ -69,8 +69,4 @@
     INTEGER ,INTENT(in) :: kt
     !!
-    INTEGER :: inbsel, jk
-    INTEGER :: iyear,imon,iday
-    INTEGER, SAVE :: nmoyct 
-
 #if defined key_diainstant
     LOGICAL, PARAMETER :: ll_dia_inst=.TRUE.  !: for instantaneous output
@@ -78,12 +74,13 @@
     LOGICAL, PARAMETER :: ll_dia_inst=.FALSE. !: for average output
 #endif
-
-    REAL(wp), ALLOCATABLE, SAVE, DIMENSION (:,:,:) ::  um , vm   ! used to compute mean u, v fields
-    REAL(wp), ALLOCATABLE, SAVE, DIMENSION (:,:,:) ::  wm        ! used to compute mean w fields
-    REAL(wp), ALLOCATABLE, SAVE, DIMENSION (:,:,:) ::  avtm      ! used to compute mean kz fields
-    REAL(wp), ALLOCATABLE, SAVE, DIMENSION (:,:,:) ::  tm , sm   ! used to compute mean t, s fields
-    REAL(wp), ALLOCATABLE, SAVE, DIMENSION (:,:,:) ::  fsel      ! used to compute mean 2d fields
+    INTEGER              , SAVE                    ::  nmoyct 
+    REAL(wp), ALLOCATABLE, SAVE, DIMENSION (:,:,:) ::  um , vm, wm   ! mean u, v, w fields
+    REAL(wp), ALLOCATABLE, SAVE, DIMENSION (:,:,:) ::  avtm          ! mean kz fields
+    REAL(wp), ALLOCATABLE, SAVE, DIMENSION (:,:,:) ::  tm , sm       ! mean t, s fields
+    REAL(wp), ALLOCATABLE, SAVE, DIMENSION (:,:,:) ::  fsel          ! mean 2d fields
+    
+    INTEGER :: inbsel, jk
+    INTEGER :: iyear,imon,iday
     REAL(wp) :: zdtj
-    !
     CHARACTER(LEN=80) :: clname
     CHARACTER(LEN=80) :: cltext
@@ -260,9 +257,6 @@
        cltext=TRIM(cexper)//' U(m/s) '//TRIM(clmode)
        !
-       IF( ll_dia_inst) THEN 
-          CALL dia_wri_dimg(clname, cltext, un, jpk, 'T')
-
-       ELSE 
-          CALL dia_wri_dimg(clname, cltext, um, jpk, 'T')
+       IF( ll_dia_inst) THEN   ;   CALL dia_wri_dimg(clname, cltext, un, jpk, 'T')
+       ELSE                    ;   CALL dia_wri_dimg(clname, cltext, um, jpk, 'T')
        ENDIF
 
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 2613)
@@ -72,13 +72,12 @@
       !!                  ***  routine dyn_spg_ts_alloc  ***
       !!----------------------------------------------------------------------
-      IMPLICIT none
-      INTEGER :: dyn_spg_ts_malloc
+      INTEGER ::   dyn_spg_ts_alloc   ! return value
       !!----------------------------------------------------------------------
-
+      !
       ALLOCATE(ftnw(jpi,jpj), ftne(jpi,jpj), ftsw(jpi,jpj), ftse(jpi,jpj), &
-               un_b(jpi,jpj), vn_b(jpi,jpj), ub_b(jpi,jpj), vb_b(jpi,jpj), &
-               Stat=dyn_spg_ts_malloc)
-
-   END FUNCTION dyn_spg_ts_malloc
+         &      un_b(jpi,jpj), vn_b(jpi,jpj), ub_b(jpi,jpj), vb_b(jpi,jpj), &
+         &      STAT=dyn_spg_ts_alloc)
+         !
+   END FUNCTION dyn_spg_ts_alloc
 
 
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/FLO/flo_oce.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/FLO/flo_oce.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/FLO/flo_oce.F90	(revision 2613)
@@ -16,5 +16,5 @@
    PUBLIC
 
-   PUBLIC flo_oce_alloc ! Routine called in nemogcm.F90
+   PUBLIC   flo_oce_alloc   ! Routine called in nemogcm.F90
 
    LOGICAL, PUBLIC, PARAMETER ::   lk_floats = .TRUE.    !: float flag
@@ -34,5 +34,5 @@
    REAL(wp), PUBLIC, DIMENSION(jpnfl) ::   tpifl, tpjfl, tpkfl   !: (i,j,k) indices of float position
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   wb              !: vertical velocity at previous time step (m s-1).
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   wb   !: vertical velocity at previous time step (m s-1).
    
    !                                            !!! * namelist namflo : langrangian floats *
@@ -43,12 +43,14 @@
    INTEGER, PUBLIC  ::   nn_stockfl = 450        !: frequency of float restart file
 
+   !!----------------------------------------------------------------------
 CONTAINS
 
    FUNCTION flo_oce_alloc()
-     IMPLICIT none
-     INTEGER :: flo_oce_alloc
-
-     ALLOCATE(wb(jpi,jpj,jpk), Stat=flo_oce_alloc)
-
+      !!----------------------------------------------------------------------
+      INTEGER :: flo_oce_alloc
+      !!----------------------------------------------------------------------
+      !
+      ALLOCATE(wb(jpi,jpj,jpk), Stat=flo_oce_alloc)
+      !
    END FUNCTION flo_oce_alloc
 
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/FLO/flowri.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/FLO/flowri.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/FLO/flowri.F90	(revision 2613)
@@ -24,5 +24,5 @@
 
    PUBLIC   flo_wri          ! routine called by floats.F90
-   PUBLIC   flow_wri_alloc   ! routine called by nemogcm.F90
+   PUBLIC   flo_wri_alloc   ! routine called by nemogcm.F90
 
    INTEGER ::   jfl      ! number of floats
@@ -37,5 +37,5 @@
 #  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -43,17 +43,17 @@
 CONTAINS
 
-   FUNCTION flow_wri_alloc
+   FUNCTION flo_wri_alloc
       !!-------------------------------------------------------------------
       !!                ***  ROUTINE flo_wri_alloc  ***
       !!-------------------------------------------------------------------
-      INTEGER :: flow_wri_alloc
-
-      ALLOCATE(ztemp(jpk,jpnfl), zsal(jpk,jpnfl), Stat=flow_wri_alloc)
-
-      IF(flow_wri_alloc /= 0)THEN
-         CALL ctl_warn('flow_wri_alloc: failed to allocate arrays.')
-      END IF
-
-   END FUNCTION flow_wri_alloc
+      INTEGER :: flo_wri_alloc
+      !!-------------------------------------------------------------------
+      !
+      ALLOCATE(ztemp(jpk,jpnfl), zsal(jpk,jpnfl), Stat=flo_wri_alloc)
+      !
+      IF( lk_mpp             )   CALL mpp_sum ( flo_wri_alloc )
+      IF( flo_wri_alloc /= 0 )   CALL ctl_warn('flo_wri_alloc: failed to allocate arrays.')
+      !
+   END FUNCTION flo_wri_alloc
 
 
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 2613)
@@ -20,4 +20,5 @@
    USE lib_print     ! formated print library
    USE nc4interface  ! NetCDF4 interface
+   USE lib_mpp, ONLY :   lk_mpp
 
    IMPLICIT NONE
@@ -137,6 +138,6 @@
 CONTAINS
 
-   SUBROUTINE ctl_stop( cd1, cd2, cd3, cd4, cd5,   &
-      &                 cd6, cd7, cd8, cd9, cd10 )
+   SUBROUTINE ctl_stop( cd_stop, cd1, cd2, cd3, cd4, cd5 ,   &
+      &                          cd6, cd7, cd8, cd9, cd10 )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE  stop_opa  ***
@@ -145,6 +146,6 @@
       !!                increment the error number (nstop) by one.
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd1, cd2, cd3, cd4, cd5
-      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd6, cd7, cd8, cd9, cd10
+      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd_stop, cd1, cd2, cd3, cd4, cd5
+      CHARACTER(len=*), INTENT(in), OPTIONAL ::           cd6, cd7, cd8, cd9, cd10
       !!----------------------------------------------------------------------
       !
@@ -167,4 +168,13 @@
       IF( numsol     /= -1 )   CALL FLUSH(numsol    )
       IF( numevo_ice /= -1 )   CALL FLUSH(numevo_ice)
+      !
+      IF( PRESENT(cd_stop) ) THEN
+         IF( cd_stop == 'STOP' ) THEN
+            WRITE(numout,*) 
+            WRITE(numout,*) 'huge E-R-R-O-R : immediate stop'
+            IF(lk_mpp)   CALL mppstop()
+            STOP
+         ENDIF
+      ENDIF
       !
    END SUBROUTINE ctl_stop
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_ice.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_ice.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_ice.F90	(revision 2613)
@@ -2,8 +2,9 @@
    !!======================================================================
    !!                 ***  MODULE  sbc_ice  ***
-   !!        parameter and  variables defined in memory in forced mode
+   !! Surface module - LIM-3: parameters & variables defined in memory
    !!======================================================================
-   !! History :  3.0  !  2006-08  (G. Madec)  Surface module
-   !!            3.2  !  2009-06  (S. Masson) merge with ice_oce
+   !! History :  3.0  ! 2006-08  (G. Madec)  Surface module
+   !!            3.2  ! 2009-06  (S. Masson) merge with ice_oce
+   !!            4.0  ! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
    !!----------------------------------------------------------------------
 #if defined key_lim3 || defined key_lim2
@@ -13,8 +14,8 @@
    USE par_oce          ! ocean parameters
 # if defined key_lim3
-   USE par_ice          ! ice parameters
+   USE par_ice          ! LIM-3 parameters
 # endif
 # if defined key_lim2
-   USE par_ice_2        ! ice parameters
+   USE par_ice_2        ! LIM-2 parameters
 # endif
 
@@ -39,17 +40,17 @@
 # endif
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qns_ice   !: non solar heat flux over ice                         [W/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qsr_ice   !: solar heat flux over ice                             [W/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qla_ice   !: latent flux over ice                                 [W/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dqla_ice  !: latent sensibility over ice                          [W/m2/K]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dqns_ice  !: non solar heat flux sensibility over ice (LW+SEN+LA) [W/m2/K]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tn_ice    !: ice surface temperature                              [K]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qns_ice   !: non solar heat flux over ice                  [W/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qsr_ice   !: solar heat flux over ice                      [W/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qla_ice   !: latent flux over ice                          [W/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dqla_ice  !: latent sensibility over ice                 [W/m2/K]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dqns_ice  !: non solar heat flux over ice (LW+SEN+LA)    [W/m2/K]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tn_ice    !: ice surface temperature                          [K]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   alb_ice   !: albedo of ice
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   utau_ice    !: u-stress over ice (I-pt for VP or U,V-pts for EVP)   [N/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   vtau_ice    !: v-stress over ice (I-pt for VP or U,V-pts for EVP)   [N/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fr1_i0      !: 1st fraction of Qsr which penetrates inside the ice cover
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fr2_i0      !: 2nd fraction of Qsr which penetrates inside the ice cover
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   emp_ice     !: solid freshwater budget over ice: sublivation - snow
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   utau_ice    !: atmos-ice u-stress. VP: I-pt ; EVP: U,V-pts   [N/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   vtau_ice    !: atmos-ice v-stress. VP: I-pt ; EVP: U,V-pts   [N/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fr1_i0      !: 1st Qsr fraction penetrating inside ice cover    [-]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fr2_i0      !: 2nd Qsr fraction penetrating inside ice cover    [-]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   emp_ice     !: sublimation-snow budget over ice             [kg/m2]
 
 # if defined key_lim3
@@ -57,21 +58,28 @@
 # endif
 
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! $Id$ 
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
 
-  FUNCTION sbc_ice_alloc()
-    !!----------------------------------------------------------------------
-    !!----------------------------------------------------------------------
-    IMPLICIT none
-    INTEGER :: sbc_ice_alloc
-    !!----------------------------------------------------------------------
- 
-    ALLOCATE(qns_ice(jpi,jpj,jpl),  qsr_ice(jpi,jpj,jpl),               &
-             qla_ice(jpi,jpj,jpl),  dqla_ice(jpi,jpj,jpl),              &
-             dqns_ice(jpi,jpj,jpl), tn_ice(jpi,jpj,jpl),                &
-             alb_ice(jpi,jpj,jpl),                                      &
-             utau_ice(jpi,jpj),     vtau_ice(jpi,jpj), fr1_i0(jpi,jpj), &
-             fr2_i0(jpi,jpj),       emp_ice(jpi,jpj),                   &
-             Stat=sbc_ice_alloc)
-
+   FUNCTION sbc_ice_alloc()
+      !!----------------------------------------------------------------------
+     !!                     ***  FUNCTION sbc_ice_alloc  ***
+     !!
+     !! ** Purpose :   Allocate all the dynamic arrays in the modules
+      !!----------------------------------------------------------------------
+      INTEGER :: sbc_ice_alloc   ! return value
+      !!----------------------------------------------------------------------
+      !
+      ALLOCATE( qns_ice (jpi,jpj,jpl) , qsr_ice (jpi,jpj,jpl) ,     &
+         &      qla_ice (jpi,jpj,jpl) , dqla_ice(jpi,jpj,jpl) ,     &
+         &      dqns_ice(jpi,jpj,jpl) , tn_ice  (jpi,jpj,jpl) ,     &
+         &      alb_ice (jpi,jpj,jpl) ,                             &
+         &      utau_ice(jpi,jpj)     , vtau_ice(jpi,jpj)     ,     &
+         &      fr1_i0  (jpi,jpj)     , fr2_i0  (jpi,jpj)     ,     &
+         &      emp_ice(jpi,jpj)                              , STAT=sbc_ice_alloc)
+      !
   END FUNCTION sbc_ice_alloc
 
@@ -85,8 +93,4 @@
 #endif
 
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!======================================================================
 END MODULE sbc_ice
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 2613)
@@ -63,5 +63,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , UCL NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , UCL NEMO Consortium (2011)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -146,14 +146,14 @@
          CASE( 3 )                                       ! CLIO bulk formulation
             CALL blk_ice_clio( t_su , zalb_ice_cs, zalb_ice_os,                           &
-               &                      utau_ice  , vtau_ice  , qns_ice   , qsr_ice   ,   &
-               &                      qla_ice   , dqns_ice  , dqla_ice  ,               &
-               &                      tprecip   , sprecip   ,                           &
-               &                      fr1_i0    , fr2_i0    , cp_ice_msh, jpl  )
+               &                      utau_ice   , vtau_ice   , qns_ice   , qsr_ice   ,   &
+               &                      qla_ice    , dqns_ice   , dqla_ice  ,               &
+               &                      tprecip    , sprecip    ,                           &
+               &                      fr1_i0     , fr2_i0     , cp_ice_msh, jpl  )
             !         
          CASE( 4 )                                       ! CORE bulk formulation
             CALL blk_ice_core( t_su , u_ice     , v_ice     , zalb_ice_cs,               &
-               &                      utau_ice  , vtau_ice  , qns_ice   , qsr_ice   ,   &
-               &                      qla_ice   , dqns_ice  , dqla_ice  ,               &
-               &                      tprecip   , sprecip   ,                           &
+               &                      utau_ice  , vtau_ice  , qns_ice    , qsr_ice   ,   &
+               &                      qla_ice   , dqns_ice  , dqla_ice   ,               &
+               &                      tprecip   , sprecip   ,                            &
                &                      fr1_i0    , fr2_i0    , cp_ice_msh, jpl  )
          END SELECT
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso_grif.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso_grif.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso_grif.F90	(revision 2613)
@@ -57,11 +57,9 @@
       INTEGER :: tra_ldf_iso_grif_alloc
       !!----------------------------------------------------------------------
-
+      !
       ALLOCATE(zdkt(jpi,jpj,0:1), Stat=tra_ldf_iso_grif_alloc)
-
-      IF(tra_ldf_iso_grif_alloc /= 0)THEN
-         CALL ctl_warn('tra_ldf_iso_grif_alloc : allocation of arrays failed.')
-      END IF
-
+      !
+      IF( tra_ldf_iso_grif_alloc /= 0 )   CALL ctl_warn('tra_ldf_iso_grif_alloc : allocation of arrays failed.')
+      !
   END FUNCTION tra_ldf_iso_grif_alloc
 
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90	(revision 2613)
@@ -72,12 +72,11 @@
       INTEGER :: trd_mld_alloc
       !!----------------------------------------------------------------------
-
+      !
       ALLOCATE(ndextrd1(jpi*jpj), Stat=trd_mld_alloc)
-
-      IF(trd_mld_alloc /= 0)THEN
-         CALL ctl_warn('trd_mld_alloc: failed to allocate array ndextrd1.')
-      END IF
-
+      !
+      IF( trd_mld_alloc /= 0 )   CALL ctl_warn('trd_mld_alloc: failed to allocate array ndextrd1.')
+      !
    END FUNCTION trd_mld_alloc
+
 
    SUBROUTINE trd_mld_zint( pttrdmld, pstrdmld, ktrd, ctype )
@@ -262,5 +261,6 @@
       USE wrk_nemo, ONLY: ztmltot2 => wrk_2d_7, ztmlres2 => wrk_2d_8, ztmltrdm2 => wrk_2d_9    ! \  working arrays to diagnose the trends
       USE wrk_nemo, ONLY: zsmltot2 => wrk_2d_10, zsmlres2 => wrk_2d_11, zsmltrdm2 => wrk_2d_12 !  > associated with the time meaned ML T & S
-      USE wrk_nemo, ONLY: ztmlatf2 => wrk_2d_13, zsmlatf2 => wrk_2d_14                         ! /
+      USE wrk_nemo, ONLY: ztmlatf2 => wrk_2d_13, zsmlatf2 => wrk_2d_14    
+      USE wrk_nemo, ONLY: wrk_3d_1, wrk_3d_2                     ! /
       !!
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
@@ -269,6 +269,5 @@
       LOGICAL :: lldebug = .TRUE.
       REAL(wp) :: zavt, zfn, zfn2
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  &
-           ztmltrd2, zsmltrd2               ! only needed for mean diagnostics
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztmltrd2, zsmltrd2   ! only needed for mean diagnostics
 #if defined key_dimgout
       INTEGER ::  iyear,imon,iday
@@ -282,5 +281,5 @@
          CALL ctl_stop('trd_mld : requested workspace arrays unavailable.')
          RETURN
-      ELSE IF(jpltrd > jpk)
+      ELSE IF(jpltrd > jpk) THEN
          ! ARPDBG, is this reasonable or will this cause trouble in the future?
          CALL ctl_stop('trd_mld : no. of mixed-layer trends (jpltrd) exceeds no. of model levels so cannot use 3D workspaces.')
@@ -288,6 +287,6 @@
       END IF
       ! Set-up pointers into sub-arrays of 3d-workspaces
-      ztmltrd2 => wrk_3d_1(:,:,1:jpltrd)
-      zsmltrd2 => wrk_3d_2(:,:,1:jpltrd)
+      ztmltrd2 => wrk_3d_1(1:,:,1:jpltrd)
+      zsmltrd2 => wrk_3d_2(1:,:,1:jpltrd)
 
       ! ======================================================================
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld_oce.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld_oce.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld_oce.F90	(revision 2613)
@@ -71,5 +71,5 @@
       tmlatfm, smlatfm                !: accumulator for Asselin trends (needed for storage only)
 
-   REAL(wp), PUBLIC, DIMENSION(:,:,:) ::  &
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:) ::  &
       tmltrd,                       & !: \ physical contributions to the total trend (for T/S),
       smltrd,                       & !: / cumulated over the current analysis window
@@ -82,8 +82,8 @@
 #endif
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
    !! $Id$ 
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!======================================================================
+   !!----------------------------------------------------------------------
 CONTAINS
 
@@ -92,5 +92,4 @@
      !!----------------------------------------------------------------------
      USE in_out_manager, ONLY: ctl_warn
-     IMPLICIT none
      INTEGER :: trdmld_oce_alloc
      INTEGER :: ierr(5)
@@ -104,40 +103,39 @@
 
 #if   defined  key_trdmld   ||   defined key_esopa
-     ALLOCATE(nmld(jpi,jpj), nbol(jpi,jpj),       &
-              wkx(jpi,jpj,jpk), rmld(jpi,jpj),    & 
-              tml(jpi,jpj)    , sml(jpi,jpj),     & 
-              tmlb(jpi,jpj)   , smlb(jpi,jpj) ,   &
-              tmlbb(jpi,jpj)  , smlbb(jpi,jpj),   &
-              Stat = ierr(1))
+     ALLOCATE( nmld(jpi,jpj), nbol(jpi,jpj),       &
+        &      wkx(jpi,jpj,jpk), rmld(jpi,jpj),    & 
+        &      tml(jpi,jpj)    , sml(jpi,jpj),     & 
+        &      tmlb(jpi,jpj)   , smlb(jpi,jpj) ,   &
+        &      tmlbb(jpi,jpj)  , smlbb(jpi,jpj),   &
+        &      Stat = ierr(1))
 
-     ALLOCATE(tmlbn(jpi,jpj)  , smlbn(jpi,jpj),   &
-              tmltrdm(jpi,jpj), smltrdm(jpi,jpj), &
-              tml_sum(jpi,jpj), tml_sumb(jpi,jpj),&
-              tmltrd_atf_sumb(jpi,jpj), Stat=ierr(2))
+     ALLOCATE( tmlbn(jpi,jpj)  , smlbn(jpi,jpj),   &
+        &      tmltrdm(jpi,jpj), smltrdm(jpi,jpj), &
+        &      tml_sum(jpi,jpj), tml_sumb(jpi,jpj),&
+        &      tmltrd_atf_sumb(jpi,jpj), Stat=ierr(2))
 
-     ALLOCATE(sml_sum(jpi,jpj), sml_sumb(jpi,jpj), &
-              smltrd_atf_sumb(jpi,jpj),            &
-              rmld_sum(jpi,jpj), rmldbn(jpi,jpj),  &
-              tmlatfb(jpi,jpj), tmlatfn(jpi,jpj),  & 
-              Stat = ierr(3))
+     ALLOCATE( sml_sum(jpi,jpj), sml_sumb(jpi,jpj), &
+        &      smltrd_atf_sumb(jpi,jpj),            &
+        &      rmld_sum(jpi,jpj), rmldbn(jpi,jpj),  &
+        &      tmlatfb(jpi,jpj), tmlatfn(jpi,jpj),  & 
+        &      Stat = ierr(3))
 
-     ALLOCATE(smlatfb(jpi,jpj), smlatfn(jpi,jpj), & 
-              tmlatfm(jpi,jpj), smlatfm(jpi,jpj), &
-              tmltrd(jpi,jpj,jpltrd),   smltrd(jpi,jpj,jpltrd), &
-              Stat=ierr(4))
+     ALLOCATE( smlatfb(jpi,jpj), smlatfn(jpi,jpj), & 
+        &      tmlatfm(jpi,jpj), smlatfm(jpi,jpj), &
+        &      tmltrd(jpi,jpj,jpltrd),   smltrd(jpi,jpj,jpltrd), &
+        &      Stat=ierr(4))
 
-     ALLOCATE(tmltrd_sum(jpi,jpj,jpltrd),tmltrd_csum_ln(jpi,jpj,jpltrd),      &
-              tmltrd_csum_ub(jpi,jpj,jpltrd), smltrd_sum(jpi,jpj,jpltrd),     &
-              smltrd_csum_ln(jpi,jpj,jpltrd), smltrd_csum_ub(jpi,jpj,jpltrd), &
-              Stat=ierr(5))
+     ALLOCATE( tmltrd_sum(jpi,jpj,jpltrd),tmltrd_csum_ln(jpi,jpj,jpltrd),      &
+        &      tmltrd_csum_ub(jpi,jpj,jpltrd), smltrd_sum(jpi,jpj,jpltrd),     &
+        &      smltrd_csum_ln(jpi,jpj,jpltrd), smltrd_csum_ub(jpi,jpj,jpltrd), &
+        &      Stat=ierr(5))
 #endif
+      !
+      trdmld_oce_alloc = MAXVAL(ierr)
+      !
+      IF( trdmld_oce_alloc /= 0 )   CALL ctl_warn('trdmld_oce_alloc: failed to allocate arrays.')
+      !
+   END FUNCTION trdmld_oce_alloc
 
-     trdmld_oce_alloc = MAXVAL(ierr)
-
-    IF(trdmld_oce_alloc /= 0)THEN
-       CALL ctl_warn('trdmld_oce_alloc: failed to allocate arrays.')
-    END IF
-
-  END FUNCTION trdmld_oce_alloc
-
+   !!======================================================================
 END MODULE trdmld_oce
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod.F90	(revision 2613)
@@ -58,23 +58,22 @@
                           z2dx  => wrk_2d_5,  &
                           z2dy  => wrk_2d_6
-      IMPLICIT none
-      INTEGER, INTENT( in ) ::   kt                                ! time step
-      INTEGER, INTENT( in ) ::   ktrd                              ! tracer trend index
-      CHARACTER(len=3), INTENT( in ) ::   ctype                    ! momentum or tracers trends type 'DYN'/'TRA'
-      REAL(wp), DIMENSION(:,:,:), INTENT( inout ) ::   ptrdx ! Temperature or U trend 
-      REAL(wp), DIMENSION(:,:,:), INTENT( inout ) ::   ptrdy ! Salinity    or V trend
+      !
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend 
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
+      CHARACTER(len=3)          , INTENT(in   ) ::   ctype   ! momentum or tracers trends type 'DYN'/'TRA'
+      INTEGER                   , INTENT(in   ) ::   kt      ! time step
+      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
       !!
-      INTEGER ::   ji, jj
+      INTEGER ::   ji, jj   ! dummy loop indices
       !!----------------------------------------------------------------------
 
       IF(.not. wrk_use(2, 1,2,3,4,5,6))THEN
-         CALL ctl_error('trd_mod: Requested workspace arrays already in use.')
-         RETURN
+         CALL ctl_warn('trd_mod: Requested workspace arrays already in use.')   ;   RETURN
       END IF
 
-      z2dx(:,:)   = 0.e0   ;   z2dy(:,:)   = 0.e0                  ! initialization of workspace arrays
-
-      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (restarting with Euler time stepping)
-      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdttra (leapfrog)
+      z2dx(:,:) = 0._wp   ;   z2dy(:,:) = 0._wp                            ! initialization of workspace arrays
+
+      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt   ! = rdtra (restart with Euler time stepping)
+      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt   ! = 2 rdttra (leapfrog)
       ENDIF
 
@@ -94,15 +93,15 @@
             CASE ( jptra_trd_dmp )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_dmp, ctype )   ! damping
             CASE ( jptra_trd_qsr )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_qsr, ctype )   ! penetrative solar radiat.
-            CASE ( jptra_trd_nsr )   
-               z2dx(:,:) = ptrdx(:,:,1)   ;   z2dy(:,:) = ptrdy(:,:,1)
-               CALL trd_icp( z2dx, z2dy, jpicpt_nsr, ctype )                               ! non solar radiation
+            CASE ( jptra_trd_nsr )   ;   z2dx(:,:) = ptrdx(:,:,1)   
+                                         z2dy(:,:) = ptrdy(:,:,1)
+                                         CALL trd_icp( z2dx , z2dy , jpicpt_nsr, ctype )   ! non solar radiation
             CASE ( jptra_trd_xad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_xad, ctype )   ! x- horiz adv
             CASE ( jptra_trd_yad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_yad, ctype )   ! y- horiz adv
-            CASE ( jptra_trd_zad )                                                         ! z- vertical adv 
-               CALL trd_icp( ptrdx, ptrdy, jpicpt_zad, ctype )   
-               ! compute the surface flux condition wn(:,:,1)*tn(:,:,1)
-               z2dx(:,:) = wn(:,:,1)*tn(:,:,1)/fse3t(:,:,1)
-               z2dy(:,:) = wn(:,:,1)*sn(:,:,1)/fse3t(:,:,1)
-               CALL trd_icp( z2dx , z2dy , jpicpt_zl1, ctype )                             ! 1st z- vertical adv 
+            CASE ( jptra_trd_zad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_zad, ctype )   ! z- vertical adv 
+                                         CALL trd_icp( ptrdx, ptrdy, jpicpt_zad, ctype )   
+                                         ! compute the surface flux condition wn(:,:,1)*tn(:,:,1)
+                                         z2dx(:,:) = wn(:,:,1)*tn(:,:,1)/fse3t(:,:,1)
+                                         z2dy(:,:) = wn(:,:,1)*sn(:,:,1)/fse3t(:,:,1)
+                                         CALL trd_icp( z2dx , z2dy , jpicpt_zl1, ctype )   ! 1st z- vertical adv 
             END SELECT
          END IF
@@ -123,6 +122,6 @@
                ! subtract surface forcing/bottom friction trends 
                ! from vertical diffusive momentum trends
-               ztswu(:,:) = 0.e0   ;   ztswv(:,:) = 0.e0
-               ztbfu(:,:) = 0.e0   ;   ztbfv(:,:) = 0.e0  
+               ztswu(:,:) = 0._wp   ;   ztswv(:,:) = 0._wp
+               ztbfu(:,:) = 0._wp   ;   ztbfv(:,:) = 0._wp 
                DO jj = 2, jpjm1   
                   DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -131,7 +130,6 @@
                      ztswv(ji,jj) = vtau(ji,jj) / ( fse3v(ji,jj,1)*rau0 )
                      ! bottom friction contribution now handled explicitly
-                     !
-                     ptrdx(ji,jj,1     ) = ptrdx(ji,jj,1     ) - ztswu(ji,jj)
-                     ptrdy(ji,jj,1     ) = ptrdy(ji,jj,1     ) - ztswv(ji,jj)
+                     ptrdx(ji,jj,1) = ptrdx(ji,jj,1) - ztswu(ji,jj)
+                     ptrdy(ji,jj,1) = ptrdy(ji,jj,1) - ztswv(ji,jj)
                   END DO
                END DO
@@ -228,7 +226,5 @@
       ENDIF
       !
-      IF(.not. wrk_release(2, 1,2,3,4,5,6))THEN
-         CALL ctl_error('trd_mod: Failed to release workspace arrays.')
-      END IF
+      IF( .not. wrk_release(2, 1,2,3,4,5,6) )   CALL ctl_warn('trd_mod: Failed to release workspace arrays.')
       !
    END SUBROUTINE trd_mod
@@ -242,5 +238,5 @@
    USE trdicp          ! ocean bassin integral constraints properties
    USE trdmld          ! ocean active mixed layer tracers trends 
-
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE trd_mod(ptrd3dx, ptrd3dy, ktrd , ctype, kt )   ! Empty routine
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfkpp.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfkpp.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfkpp.F90	(revision 2613)
@@ -225,5 +225,6 @@
                           zustar => wrk_2d_3
       USE wrk_nemo, ONLY: zmask  => wrk_2d_4
-      USE wrk_nemo, ONLY: wrk_2d_5, wrk_2d_6, wrk_2d_7, wrk_2d_8, wrk_2d_9, &
+!gm      USE wrk_nemo, ONLY: wrk_2d_5, wrk_2d_6, wrk_2d_7, wrk_2d_8, wrk_2d_9, &
+      USE wrk_nemo, ONLY:           wrk_2d_6, wrk_2d_7, wrk_2d_8, wrk_2d_9, &
                           wrk_2d_10,wrk_2d_11
       USE wrk_nemo, ONLY: wrk_1d_1,  wrk_1d_2,  wrk_1d_3,  wrk_1d_4,  &
@@ -260,5 +261,6 @@
       REAL(wp) ::   zflag, ztemp, zrn2, zdep21, zdep32, zdep43
       REAL(wp) ::   zdku2, zdkv2, ze3sqr, zsh2, zri, zfri          ! Interior richardson mixing
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zmoek                 ! Moning-Obukov limitation
+!gm      REAL(wp), POINTER, DIMENSION(:,:) ::   zmoek                 ! Moning-Obukov limitation
+      REAL(wp), DIMENSION(jpi,0:2) ::   zmoek                 ! Moning-Obukov limitation
       REAL(wp), POINTER, DIMENSION(:)   ::   zmoa, zekman                
       REAL(wp)                          ::   zmob, zek
@@ -285,5 +287,5 @@
       END IF
       ! Set-up pointers to 2D spaces
-      zmoek(1:jpi,0:2) => wrk_2d_5(1:jpi,1:3)
+!gm      zmoek(1:jpi,0:2) => wrk_2d_5(1:jpi,1:3)
       zdepw => wrk_2d_6(:,1:4)
       zdift => wrk_2d_7(:,1:4)
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 2613)
@@ -31,4 +31,5 @@
    PUBLIC   zdf_ric         ! called by step.F90
    PUBLIC   zdf_ric_init    ! called by opa.F90
+   PUBLIC   zdf_ric_alloc   ! called by nemogcm.F90
 
    LOGICAL, PUBLIC, PARAMETER ::   lk_zdfric = .TRUE.   !: Richardson vertical mixing flag
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 2613)
@@ -101,5 +101,5 @@
       !!              - finalize the run by closing files and communications
       !!
-      !! References : Madec, Delecluse,Imbard, and Levy, 1997:  internal report, IPSL.
+      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
       !!              Madec, 2008, internal report, IPSL.
       !!----------------------------------------------------------------------
@@ -183,6 +183,6 @@
       !! ** Purpose :   initialization of the NEMO GCM
       !!----------------------------------------------------------------------
-      INTEGER ::   ji          ! dummy loop indices
-      INTEGER :: ilocal_comm   ! local integer
+      INTEGER ::   ji            ! dummy loop indices
+      INTEGER ::   ilocal_comm   ! local integer
       CHARACTER(len=80), DIMENSION(10) ::   cltxt
       !!
@@ -456,5 +456,4 @@
    END SUBROUTINE nemo_closefile
 
-   !!======================================================================
 
    SUBROUTINE nemo_alloc
@@ -462,37 +461,8 @@
      !!                     ***  ROUTINE nemo_alloc  ***
      !!
-     !! ** Purpose :   Allocate all the dynamic arrays in the modules
+     !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
      !!
      !! ** Method  :
-     !!
-     !! History :
-     !!   9.0  !  01-11  (A. R. Porter, STFC Daresbury)
      !!----------------------------------------------------------------------
-#if defined key_lim2
-     USE dom_ice_2,    ONLY: dom_ice_alloc_2
-     USE ice_2,        ONLY: ice_alloc_2
-     USE limdia_2,     ONLY: lim_dia_alloc_2
-     USE limhdf_2,     ONLY: lim_hdf_alloc_2
-     USE limsbc_2,     ONLY: lim_sbc_alloc_2
-     USE limwri_2,     ONLY: lim_wri_alloc_2
-     USE thd_ice_2,    ONLY: thd_ice_alloc_2
-#endif
-#if defined key_lim3 || (  defined key_lim2 && ! defined key_lim2_vp )
-     USE limrhg,       ONLY: lim_rhg_alloc
-#endif
-#if defined key_lim3
-     USE dom_ice,      ONLY: dom_ice_alloc
-     USE limitd_me,    ONLY: lim_itd_me_alloc
-     USE thd_ice,      ONLY: thd_ice_alloc
-#endif
-#if defined key_bdy 
-     USE bdy_oce,      ONLY: bdy_oce_alloc
-#endif
-#if defined key_diaar5
-     USE diaar5,       ONLY: dia_ar5_alloc
-#endif
-# if defined key_dimgout
-     USE diadimg,      ONLY: dia_wri_dimg_alloc
-#endif
 #if   defined key_diahth   ||   defined key_esopa
      USE diahth,       ONLY: dia_hth_alloc
@@ -549,7 +519,4 @@
      USE sbcdcy,       ONLY: sbc_dcy_alloc
      USE sbcfwb,       ONLY: sbc_fwb_alloc
-#if defined key_lim3 || defined key_lim2
-     USE sbc_ice,      ONLY: sbc_ice_alloc
-#endif
      USE sbc_oce,      ONLY: sbc_oce_alloc
      USE sbcrnf,       ONLY: sbc_rnf_alloc
@@ -575,254 +542,217 @@
      ! TOP-related alloc routines...
 #if defined key_top
-     USE trcadv,       ONLY: trc_adv_alloc
-     USE trc,          ONLY: trc_alloc
-     USE trcnxt,       ONLY: trc_nxt_alloc
-     USE trczdf,       ONLY: trc_zdf_alloc
-     USE trdmod_trc_oce,ONLY: trd_mod_trc_oce_alloc
+      USE trcadv,       ONLY: trc_adv_alloc
+      USE trc,          ONLY: trc_alloc
+      USE trcnxt,       ONLY: trc_nxt_alloc
+      USE trczdf,       ONLY: trc_zdf_alloc
+      USE trdmod_trc_oce,ONLY: trd_mod_trc_oce_alloc
 #endif
 #if defined key_top && ! defined key_iomput
-     USE trcdia,       ONLY: trc_dia_alloc
+      USE trcdia,       ONLY: trc_dia_alloc
 #endif
 #if  defined key_top && defined key_trcdmp 
-     USE trcdmp,       ONLY: trc_dmp_alloc
+      USE trcdmp,       ONLY: trc_dmp_alloc
 #endif
 #if  defined key_top  &&  defined key_dtatrc
-     USE trcdta,       ONLY: trc_dta_alloc
+      USE trcdta,       ONLY: trc_dta_alloc
 #endif
 #if   defined key_top && ( defined key_trdmld_trc   ||   defined key_esopa )
-     USE trdmld_trc,   ONLY: trd_mld_trc_alloc
-#endif
-     ! ...end of TOP-related alloc routines
-
-     ! LOBSTER-related alloc routines...
-     USE sms_lobster,  ONLY: sms_lobster_alloc
-     ! ...end of LOBSTER-related alloc routines
-
-     USE trc_oce,      ONLY: trc_oce_alloc
+      USE trdmld_trc,   ONLY: trd_mld_trc_alloc
+#endif
+      ! ...end of TOP-related alloc routines
+
+      ! LOBSTER-related alloc routines...
+      USE sms_lobster,  ONLY: sms_lobster_alloc
+      ! ...end of LOBSTER-related alloc routines
+
+      USE trc_oce,      ONLY: trc_oce_alloc
 #if   defined key_trdmld   ||   defined key_esopa
-     USE trdmld,       ONLY: trd_mld_alloc
-#endif
-     USE trdmld_oce,   ONLY: trdmld_oce_alloc
+      USE trdmld,       ONLY: trd_mld_alloc
+#endif
+      USE trdmld_oce,   ONLY: trdmld_oce_alloc
 #if  defined key_trdtra || defined key_trdmld || defined key_trdmld_trc 
-     USE trdtra,       ONLY: trd_tra_alloc
+      USE trdtra,       ONLY: trd_tra_alloc
 #endif
 #if defined key_trdvor   ||   defined key_esopa
-     USE trdvor,       ONLY: trd_vor_alloc
-#endif
-     USE wrk_nemo,     ONLY: wrk_alloc
-     USE zdfbfr,       ONLY: zdf_bfr_alloc
+      USE trdvor,       ONLY: trd_vor_alloc
+#endif
+      USE wrk_nemo,     ONLY: wrk_alloc
+      USE zdfbfr,       ONLY: zdf_bfr_alloc
 #if defined key_zdfddm   ||   defined key_esopa
-     USE zdfddm,       ONLY: zdf_ddm_alloc
+      USE zdfddm,       ONLY: zdf_ddm_alloc
 #endif
 #if defined key_zdfkpp   ||   defined key_esopa
-     USE zdfkpp,       ONLY: zdf_kpp_alloc
+      USE zdfkpp,       ONLY: zdf_kpp_alloc
 #endif
 #if defined key_zdfgls   ||   defined key_esopa
-     USE zdfgls,       ONLY: zdf_gls_alloc
-#endif
-     USE zdfmxl,       ONLY: zdf_mxl_alloc
-     USE zdf_oce,      ONLY: zdf_oce_alloc
+      USE zdfgls,       ONLY: zdf_gls_alloc
+#endif
+      USE zdfmxl,       ONLY: zdf_mxl_alloc
+      USE zdf_oce,      ONLY: zdf_oce_alloc
 #if defined key_zdfric   ||   defined key_esopa
-     USE zdfric,       ONLY: zdf_ric_alloc
+      USE zdfric,       ONLY: zdf_ric_alloc
 #endif
 #if defined key_zdftke   ||   defined key_esopa
-     USE zdftke,       ONLY: zdf_tke_alloc
+      USE zdftke,       ONLY: zdf_tke_alloc
 #endif
 #if defined key_zdftmx
-     USE zdftmx,       ONLY: zdf_tmx_alloc
-#endif
-     IMPLICIT none
-     INTEGER :: ierr
-     INTEGER :: i
-     !!----------------------------------------------------------------------
-
-     ierr = 0
-
-     !! Calls to the _alloc() routines should be in the same order as the 
-     !! modules are USE'd above
-#if defined key_lim2
-     ierr = ierr + dom_ice_alloc_2()
-     ierr = ierr + ice_alloc_2()
-     ierr = ierr + lim_dia_alloc_2()
-     ierr = ierr + lim_hdf_alloc_2()
-     ierr = ierr + lim_sbc_alloc_2()
-     ierr = ierr + lim_wri_alloc_2()
-     ierr = ierr + thd_ice_alloc_2()
-#endif
-#if defined key_lim3 || (  defined key_lim2 && ! defined key_lim2_vp )
-     ierr = ierr + lim_rhg_alloc()
-#endif
-#if defined key_lim3
-     ierr = ierr + dom_ice_alloc()
-     ierr = ierr + lim_itd_me_alloc()
-     ierr = ierr + thd_ice_alloc()
-#endif
-     ! End of ice-related allocations
-#if  defined key_bdy
-     ierr = ierr + bdy_oce_alloc()
-#endif
-#if defined key_diaar5
-     ierr = ierr + dia_ar5_alloc()
-#endif
-# if defined key_dimgout
-     ierr = ierr + dia_wri_dimg_alloc()
-#endif
-     ierr = ierr + div_cur_alloc()
+      USE zdftmx,       ONLY: zdf_tmx_alloc
+#endif
+      IMPLICIT none
+      INTEGER :: ierr
+      INTEGER :: i
+      !!----------------------------------------------------------------------
+
+      ierr = 0
+
+      !! Calls to the _alloc() routines should be in the same order as the 
+      !! modules are USE'd above
+      ! End of ice-related allocations
+      ierr = ierr + div_cur_alloc()
 #if   defined key_diahth   ||   defined key_esopa
-     ierr = ierr + dia_hth_alloc()
-#endif
-     ierr = ierr + dia_ptr_alloc()
-     ierr = ierr + dia_wri_alloc()
-     ierr = ierr + dom_oce_alloc()
+      ierr = ierr + dia_hth_alloc()
+#endif
+      ierr = ierr + dia_ptr_alloc()
+      ierr = ierr + dia_wri_alloc()
+      ierr = ierr + dom_oce_alloc()
 #if defined key_vvl
-     ierr = ierr + dom_vvl_alloc()
-#endif
-     ierr = ierr + dom_wri_alloc()
+      ierr = ierr + dom_vvl_alloc()
+#endif
+      ierr = ierr + dom_wri_alloc()
 #if defined key_dtasal   ||   defined key_esopa
-     ierr = ierr + dta_sal_alloc()
+      ierr = ierr + dta_sal_alloc()
 #endif
 #if defined key_ldfslp   ||   defined key_esopa
-     ierr = ierr + dyn_ldf_bilapg_alloc()
+      ierr = ierr + dyn_ldf_bilapg_alloc()
 #endif
 #if defined key_dtasal   ||   defined key_esopa
-     ierr = ierr + dta_sal_alloc()
+      ierr = ierr + dta_sal_alloc()
 #endif
 #if defined key_dtatem   ||   defined key_esopa
-     ierr = ierr + dta_tem_alloc()
+      ierr = ierr + dta_tem_alloc()
 #endif
 #if defined key_ldfslp   ||   defined key_esopa
-     ierr = ierr + dyn_ldf_iso_alloc()
+      ierr = ierr + dyn_ldf_iso_alloc()
 #endif
 #if   defined key_dynspg_ts   ||   defined key_vvl   ||   defined key_esopa
-     ierr = ierr + dynspg_oce_alloc()
-#endif
-     ierr = ierr + dyn_vor_alloc()
-     ierr = ierr + dyn_zdf_exp_alloc()
+      ierr = ierr + dynspg_oce_alloc()
+#endif
+      ierr = ierr + dyn_vor_alloc()
+      ierr = ierr + dyn_zdf_exp_alloc()
 #if   defined key_floats   ||   defined key_esopa
-     ierr = ierr + flo_oce_alloc()
+      ierr = ierr + flo_oce_alloc()
 #endif
 #if   defined key_floats   ||   defined key_esopa
-     ierr = ierr + flo_wri_alloc()
-#endif
-     ierr = ierr + geo2oce_alloc()
-     ierr = ierr + ldfdyn_oce_alloc()
+      ierr = ierr + flo_wri_alloc()
+#endif
+      ierr = ierr + geo2oce_alloc()
+      ierr = ierr + ldfdyn_oce_alloc()
 #if   defined key_ldfslp   ||   defined key_esopa
      ierr = ierr + ldf_slp_alloc()
 #endif
-     ierr = ierr + ldftra_oce_alloc()
+      ierr = ierr + ldftra_oce_alloc()
 #if defined key_mpp_mpi 
-     ierr = ierr + lib_mpp_alloc()
+      ierr = ierr + lib_mpp_alloc()
 #endif
 #if defined key_obc
-     ierr = ierr + obc_dta_alloc()
-     ierr = ierr + obc_oce_alloc()
-#endif
-     ierr = ierr + oce_alloc()
-     ierr = ierr + sbc_blk_clio_alloc()
+      ierr = ierr + obc_dta_alloc()
+      ierr = ierr + obc_oce_alloc()
+#endif
+      ierr = ierr + oce_alloc()
+      ierr = ierr + sbc_blk_clio_alloc()
 #if defined key_oasis3 || defined key_oasis4
-     ierr = ierr + sbc_cpl_init_alloc()
-#endif
-     ierr = ierr + sbc_dcy_alloc()
-     ierr = ierr + sbc_fwb_alloc()
-#if defined key_lim3 || defined key_lim2
-     ierr = ierr + sbc_ice_alloc()
-#endif
-     ierr = ierr + sbc_oce_alloc()
-     ierr = ierr + sbc_rnf_alloc()
-     ierr = ierr + sbc_ssr_alloc()
-     ierr = ierr + sol_oce_alloc()
-     ierr = ierr + sol_mat_alloc()
-     ierr = ierr + tra_adv_alloc()
-     ierr = ierr + tra_adv_cen2_alloc()
-#if   defined key_trabbl   ||   defined key_esopa
-     ierr = ierr + tra_bbl_alloc()
-#endif
-#if   defined key_tradmp   ||   defined key_esopa
-     ierr = ierr + tra_dmp_alloc()
-#endif
-     ierr = ierr + tra_ldf_alloc()
-#if   defined key_ldfslp   ||   defined key_esopa
-     ierr = ierr + tra_ldf_iso_grif_alloc()
-#endif
-     ierr = ierr + tra_ldf_lap_alloc()
-     ierr = ierr + tra_nxt_alloc()
-     ierr = ierr + tra_zdf_alloc()
-
-     ! Start of TOP-related alloc routines...
+      ierr = ierr + sbc_cpl_init_alloc()
+#endif
+      ierr = ierr + sbc_dcy_alloc()
+      ierr = ierr + sbc_fwb_alloc()
+      ierr = ierr + sbc_oce_alloc()
+      ierr = ierr + sbc_rnf_alloc()
+      ierr = ierr + sbc_ssr_alloc()
+      ierr = ierr + sol_oce_alloc()
+      ierr = ierr + sol_mat_alloc()
+      ierr = ierr + tra_adv_alloc()
+      ierr = ierr + tra_adv_cen2_alloc()
+#if defined key_trabbl   ||   defined key_esopa
+      ierr = ierr + tra_bbl_alloc()
+#endif
+#if defined key_tradmp   ||   defined key_esopa
+      ierr = ierr + tra_dmp_alloc()
+#endif
+      ierr = ierr + tra_ldf_alloc()
+#if defined key_ldfslp   ||   defined key_esopa
+      ierr = ierr + tra_ldf_iso_grif_alloc()
+#endif
+      ierr = ierr + tra_ldf_lap_alloc()
+      ierr = ierr + tra_nxt_alloc()
+      ierr = ierr + tra_zdf_alloc()
+
+      ! Start of TOP-related alloc routines...
 #if defined key_top
-     ierr = ierr + trc_adv_alloc()
-     ierr = ierr + trc_alloc()
-     ierr = ierr + trc_nxt_alloc()
-     ierr = ierr + trc_zdf_alloc()
-     ierr = ierr + trd_mod_trc_oce_alloc()
+      ierr = ierr + trc_adv_alloc()
+      ierr = ierr + trc_alloc()
+      ierr = ierr + trc_nxt_alloc()
+      ierr = ierr + trc_zdf_alloc()
+      ierr = ierr + trd_mod_trc_oce_alloc()
 #endif
 #if defined key_top && ! defined key_iomput
-     ierr = ierr + trc_dia_alloc()
+      ierr = ierr + trc_dia_alloc()
 #endif
 #if  defined key_top && defined key_trcdmp 
-     ierr = ierr + trc_dmp_alloc()
+      ierr = ierr + trc_dmp_alloc()
 #endif
 #if  defined key_top  &&  defined key_dtatrc
-     ierr = ierr + trc_dta_alloc()
+      ierr = ierr + trc_dta_alloc()
 #endif
 #if   defined key_top && ( defined key_trdmld_trc   ||   defined key_esopa )
-     ierr = ierr + trd_mld_trc_alloc()
-#endif
-     ! ...end of TOP-related alloc routines
-
-     ! Start of LOBSTER-related alloc routines
-     ierr = ierr + sms_lobster_alloc()
-     ! ...end of LOBSTER-related alloc routines
-
-     ierr = ierr + trc_oce_alloc()
+      ierr = ierr + trd_mld_trc_alloc()
+#endif
+      ! ...end of TOP-related alloc routines
+
+      ! Start of LOBSTER-related alloc routines
+      ierr = ierr + sms_lobster_alloc()
+      ! ...end of LOBSTER-related alloc routines
+
+      ierr = ierr + trc_oce_alloc()
 #if   defined key_trdmld   ||   defined key_esopa
-     ierr = ierr + trd_mld_alloc()
-#endif
-     ierr = ierr + trdmld_oce_alloc()
+      ierr = ierr + trd_mld_alloc()
+#endif
+      ierr = ierr + trdmld_oce_alloc()
 #if  defined key_trdtra || defined key_trdmld || defined key_trdmld_trc 
-     ierr = ierr + trd_tra_alloc()
+      ierr = ierr + trd_tra_alloc()
 #endif
 #if defined key_trdvor   ||   defined key_esopa
-     ierr = ierr + trd_vor_alloc()
-#endif
-     ierr = ierr + wrk_alloc()
-     ierr = ierr + zdf_bfr_alloc()
+      ierr = ierr + trd_vor_alloc()
+#endif
+      ierr = ierr + wrk_alloc()
+      ierr = ierr + zdf_bfr_alloc()
 #if defined key_zdfddm   ||   defined key_esopa
-     ierr = ierr + zdf_ddm_alloc()
+      ierr = ierr + zdf_ddm_alloc()
 #endif
 #if defined key_zdfkpp   ||   defined key_esopa
-     ierr = ierr + zdf_kpp_alloc()
+      ierr = ierr + zdf_kpp_alloc()
 #endif
 #if defined key_zdfgls   ||   defined key_esopa
-     ierr = ierr + zdf_gls_alloc()
-#endif
-     ierr = ierr + zdf_mxl_alloc()
-     ierr = ierr + zdf_oce_alloc()
+      ierr = ierr + zdf_gls_alloc()
+#endif
+      ierr = ierr + zdf_mxl_alloc()
+      ierr = ierr + zdf_oce_alloc()
 #if defined key_zdfric   ||   defined key_esopa
-     ierr = ierr + zdf_ric_alloc()
+      ierr = ierr + zdf_ric_alloc()
 #endif
 #if defined key_zdftke   ||   defined key_esopa
-     ierr = ierr + zdf_tke_alloc()
+      ierr = ierr + zdf_tke_alloc()
 #endif
 #if defined key_zdftmx
-     ierr = ierr + zdf_tmx_alloc()
-#endif
-
-     IF( lk_mpp ) CALL mpp_sum(ierr)
-
-     IF(ierr > 0)THEN
-        WRITE(numout,*) 
-        WRITE(numout,*) 'ERROR: Allocation of memory failed in nemo_alloc'
-        IF( lk_mpp ) CALL mppstop()
-        STOP
-     END IF
-
+      ierr = ierr + zdf_tmx_alloc()
+#endif
+
+      IF( lk_mpp    )   CALL mpp_sum(ierr)
+      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
+      !
    END SUBROUTINE nemo_alloc
 
-   !!======================================================================
-
-   SUBROUTINE nemo_partition(num_pes)
+
+   SUBROUTINE nemo_partition( num_pes )
      USE par_oce
-     IMPLICIT none
      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
      ! Local variables
Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/wrk_nemo.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/wrk_nemo.F90	(revision 2612)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/wrk_nemo.F90	(revision 2613)
@@ -20,5 +20,5 @@
    INTEGER, PARAMETER :: num_2d_wrkspaces  = 35   ! No. of 2D workspace arrays (jpi,jpj)
    INTEGER, PARAMETER :: num_3d_wrkspaces  = 15   ! No. of 3D workspace arrays (jpi,jpj,jpk)
-   INTEGER, PARAMETER :: num_4d_wrkspaces  = 4   ! No. of 4D workspace arrays (jpi,jpj,jpk,jpts)
+   INTEGER, PARAMETER :: num_4d_wrkspaces  = 4    ! No. of 4D workspace arrays (jpi,jpj,jpk,jpts)
 
    INTEGER, PARAMETER :: num_xz_wrkspaces  = 4   ! No. of 2D, xz workspace arrays (jpi,jpk)
