Index: trunk/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90
===================================================================
--- trunk/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90	(revision 2559)
+++ trunk/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90	(revision 2715)
@@ -63,32 +63,32 @@
    INTEGER ::   numfl_t, numfl_u, numfl_v, numfl_w
 
-   REAL(wp), DIMENSION(jpi,jpj,jpk,2) :: tdta       ! temperature at two consecutive times
-   REAL(wp), DIMENSION(jpi,jpj,jpk,2) :: sdta       ! salinity at two consecutive times
-   REAL(wp), DIMENSION(jpi,jpj,jpk,2) :: udta       ! zonal velocity at two consecutive times
-   REAL(wp), DIMENSION(jpi,jpj,jpk,2) :: vdta       ! meridional velocity at two consecutive times
-   REAL(wp), DIMENSION(jpi,jpj,jpk,2) :: wdta       ! vertical velocity at two consecutive times
-   REAL(wp), DIMENSION(jpi,jpj,jpk,2) :: avtdta     ! vertical diffusivity coefficient
-
-   REAL(wp), DIMENSION(jpi,jpj    ,2) :: hmlddta    ! mixed layer depth at two consecutive times
-   REAL(wp), DIMENSION(jpi,jpj    ,2) :: wspddta    ! wind speed at two consecutive times
-   REAL(wp), DIMENSION(jpi,jpj    ,2) :: frlddta    ! sea-ice fraction at two consecutive times
-   REAL(wp), DIMENSION(jpi,jpj    ,2) :: empdta     ! E-P at two consecutive times
-   REAL(wp), DIMENSION(jpi,jpj    ,2) :: qsrdta     ! short wave heat flux at two consecutive times
-   REAL(wp), DIMENSION(jpi,jpj    ,2) :: bblxdta    ! frequency of bbl in the x direction at 2 consecutive times 
-   REAL(wp), DIMENSION(jpi,jpj    ,2) :: bblydta    ! frequency of bbl in the y direction at 2 consecutive times 
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: tdta       ! temperature at two consecutive times
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: sdta       ! salinity at two consecutive times
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: udta       ! zonal velocity at two consecutive times
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: vdta       ! meridional velocity at two consecutive times
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: wdta       ! vertical velocity at two consecutive times
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: avtdta     ! vertical diffusivity coefficient
+
+   REAL(wp), ALLOCATABLE, SAVE,   DIMENSION(:,:,:) :: hmlddta    ! mixed layer depth at two consecutive times
+   REAL(wp), ALLOCATABLE, SAVE,   DIMENSION(:,:,:) :: wspddta    ! wind speed at two consecutive times
+   REAL(wp), ALLOCATABLE, SAVE,   DIMENSION(:,:,:) :: frlddta    ! sea-ice fraction at two consecutive times
+   REAL(wp), ALLOCATABLE, SAVE,   DIMENSION(:,:,:) :: empdta     ! E-P at two consecutive times
+   REAL(wp), ALLOCATABLE, SAVE,   DIMENSION(:,:,:) :: qsrdta     ! short wave heat flux at two consecutive times
+   REAL(wp), ALLOCATABLE, SAVE,   DIMENSION(:,:,:) :: bblxdta    ! frequency of bbl in the x direction at 2 consecutive times 
+   REAL(wp), ALLOCATABLE, SAVE,   DIMENSION(:,:,:) :: bblydta    ! frequency of bbl in the y direction at 2 consecutive times 
    LOGICAL :: l_offbbl
 #if defined key_ldfslp
-   REAL(wp), DIMENSION(jpi,jpj,jpk,2) :: uslpdta    ! zonal isopycnal slopes
-   REAL(wp), DIMENSION(jpi,jpj,jpk,2) :: vslpdta    ! meridional isopycnal slopes
-   REAL(wp), DIMENSION(jpi,jpj,jpk,2) :: wslpidta   ! zonal diapycnal slopes
-   REAL(wp), DIMENSION(jpi,jpj,jpk,2) :: wslpjdta   ! meridional diapycnal slopes
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: uslpdta    ! zonal isopycnal slopes
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: vslpdta    ! meridional isopycnal slopes
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: wslpidta   ! zonal diapycnal slopes
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: wslpjdta   ! meridional diapycnal slopes
 #endif
 #if ! defined key_degrad &&  defined key_traldf_c2d && defined key_traldf_eiv 
-   REAL(wp), DIMENSION(jpi,jpj    ,2) :: aeiwdta    ! G&M coefficient
+   REAL(wp), ALLOCATABLE, SAVE,   DIMENSION(:,:,:) :: aeiwdta    ! G&M coefficient
 #endif
 #if defined key_degrad
-   REAL(wp), DIMENSION(jpi,jpj,jpk,2) :: ahtudta, ahtvdta, ahtwdta   ! Lateral diffusivity
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: ahtudta, ahtvdta, ahtwdta   ! Lateral diffusivity
 # if defined key_traldf_eiv
-   REAL(wp), DIMENSION(jpi,jpj,jpk,2) :: aeiudta, aeivdta, aeiwdta   ! G&M coefficient
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: aeiudta, aeivdta, aeiwdta   ! G&M coefficient
 # endif
 #endif
@@ -297,4 +297,36 @@
 
 
+   INTEGER FUNCTION dta_dyn_alloc()
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE dta_dyn_alloc  ***
+      !!---------------------------------------------------------------------
+
+      ALLOCATE( tdta    (jpi,jpj,jpk,2), sdta    (jpi,jpj,jpk,2),    &
+         &      udta    (jpi,jpj,jpk,2), vdta    (jpi,jpj,jpk,2),    &
+         &      wdta    (jpi,jpj,jpk,2), avtdta  (jpi,jpj,jpk,2),    &
+#if defined key_ldfslp 
+         &      uslpdta (jpi,jpj,jpk,2), vslpdta (jpi,jpj,jpk,2),    &
+         &      wslpidta(jpi,jpj,jpk,2), wslpjdta(jpi,jpj,jpk,2),    &
+#endif
+#if defined key_degrad
+         &      ahtudta (jpi,jpj,jpk,2), ahtvdta (jpi,jpj,jpk,2),    &
+         &      ahtwdta (jpi,jpj,jpk,2),                             &
+# if defined key_traldf_eiv
+         &      aeiudta (jpi,jpj,jpk,2), aeivdta (jpi,jpj,jpk,2),    &
+         &      aeiwdta (jpi,jpj,jpk,2),                             &
+# endif
+#endif
+#if ! defined key_degrad &&  defined key_traldf_c2d && defined key_traldf_eiv
+         &      aeiwdta (jpi,jpj,    2),                             &
+#endif
+         &      hmlddta (jpi,jpj,    2), wspddta (jpi,jpj,    2),    &
+         &      frlddta (jpi,jpj,    2), qsrdta  (jpi,jpj,    2),    &
+         &      empdta  (jpi,jpj,    2),                         STAT=dta_dyn_alloc ) 
+         !
+      IF( dta_dyn_alloc /= 0 )   CALL ctl_warn('dta_dyn_alloc: failed to allocate facvol array')
+      !
+   END FUNCTION dta_dyn_alloc
+
+
    SUBROUTINE dynrea( kt, kenr )
       !!----------------------------------------------------------------------
@@ -305,23 +337,26 @@
       !! ** Method : READ the kenr records of DATA and store in udta(...,2), ....  
       !!----------------------------------------------------------------------
+      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY: zu    => wrk_3d_1 , zv    => wrk_3d_2 , zw    => wrk_3d_3
+      USE wrk_nemo, ONLY: zt    => wrk_3d_4 , zs    => wrk_3d_5
+      USE wrk_nemo, ONLY: zavt  => wrk_3d_6 , zhdiv => wrk_3d_7
+      USE wrk_nemo, ONLY: zahtu => wrk_3d_8 , zahtv => wrk_3d_9 , zahtw => wrk_3d_10
+      USE wrk_nemo, ONLY: zaeiu => wrk_3d_11, zaeiv => wrk_3d_12, zaeiw => wrk_3d_13
+      !
+      USE wrk_nemo, ONLY: zemp  => wrk_2d_1 , zqsr  => wrk_2d_2 , zmld  => wrk_2d_3
+      USE wrk_nemo, ONLY: zice  => wrk_2d_4 , zwspd => wrk_2d_5 
+      USE wrk_nemo, ONLY: ztaux => wrk_2d_6 , ztauy => wrk_2d_7
+      USE wrk_nemo, ONLY: zbblx => wrk_2d_8 , zbbly => wrk_2d_9
+      USE wrk_nemo, ONLY: zaeiw2d => wrk_2d_10
+      !
       INTEGER, INTENT(in) ::   kt, kenr   ! time index
       !!
       INTEGER ::  jkenr
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  zu, zv, zw, zt, zs, zavt , zhdiv              ! 3D workspace
-      REAL(wp), DIMENSION(jpi,jpj)     ::  zemp, zqsr, zmld, zice, zwspd, ztaux, ztauy   ! 2D workspace
-      REAL(wp), DIMENSION(jpi,jpj)     ::  zbblx, zbbly
-
-#if ! defined key_degrad && defined key_traldf_c2d && defined key_traldf_eiv
-      REAL(wp), DIMENSION(jpi,jpj) :: zaeiw 
-#endif
-#if defined key_degrad
-   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zahtu, zahtv, zahtw  !  Lateral diffusivity
-# if defined key_traldf_eiv
-   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zaeiu, zaeiv, zaeiw  ! G&M coefficient
-# endif
-#endif
-      !!----------------------------------------------------------------------
-
-      ! 0. Initialization
+      !!----------------------------------------------------------------------
+      ! 
+      IF( wrk_in_use(3, 1,2,3,4,5,6,7,8,9,10,11,12,13) .OR. &
+          wrk_in_use(2, 1,2,3,4,5,6,7,8,9,10)               ) THEN
+         CALL ctl_stop('domrea/dta_dyn: requested workspace arrays unavailable')   ;   RETURN
+      ENDIF
       
       ! cas d'un fichier non periodique : on utilise deux fois le premier et
@@ -390,5 +425,5 @@
 
 #if ! defined key_degrad && defined key_traldf_c2d && defined key_traldf_eiv 
-      CALL iom_get( numfl_w, jpdom_data, 'soleaeiw', zaeiw (:,: ), jkenr )
+      CALL iom_get( numfl_w, jpdom_data, 'soleaeiw', zaeiw2d(:,: ), jkenr )
 #endif
 
@@ -413,5 +448,5 @@
 
 #if ! defined key_degrad && defined key_traldf_c2d && defined key_traldf_eiv
-      aeiwdta(:,:,2)  = zaeiw(:,:) * tmask(:,:,1)
+      aeiwdta(:,:,2)  = zaeiw2d(:,:) * tmask(:,:,1)
 #endif
 
@@ -451,4 +486,9 @@
       ENDIF
       !      
+      IF( wrk_not_released(3, 1,2,3,4,5,6,7,8,9,10,11,12,13) .OR. &
+          wrk_not_released(2, 1,2,3,4,5,6,7,8,9,10)               ) THEN
+         CALL ctl_stop('domrea/dta_dyn: failed to release workspace arrays')
+      END IF
+      !
    END SUBROUTINE dynrea
 
@@ -462,16 +502,15 @@
       !! ** Method :
       !!----------------------------------------------------------------------
-      REAL(wp) ::   znspyr   !: number of time step per year
-      !!
+      REAL(wp) :: znspyr   !: number of time step per year
+      !
       NAMELIST/namdyn/ ndtadyn, ndtatot, nsptint, lperdyn,  &
-      &                cfile_grid_T, cfile_grid_U, cfile_grid_V, cfile_grid_W
-      !!----------------------------------------------------------------------
-
-      !  Define the dynamical input parameters
-      ! ======================================
-
+         &             cfile_grid_T, cfile_grid_U, cfile_grid_V, cfile_grid_W
+      !!----------------------------------------------------------------------
+      !
+      IF( dta_dyn_alloc() /= 0 )  CALL ctl_stop( 'STOP', 'dta_dyn_alloc: unable to allocate standard ocean arrays' )
+      !
       REWIND( numnam )              ! Read Namelist namdyn : Lateral physics on tracers
       READ  ( numnam, namdyn )
-
+      !
       IF(lwp) THEN                  ! control print
          WRITE(numout,*)
@@ -493,5 +532,5 @@
       !
       znspyr   = nyear_len(1) * rday / rdt  
-      rnspdta  = znspyr / FLOAT( ndtadyn )
+      rnspdta  = znspyr / REAL( ndtadyn, wp )
       rnspdta2 = rnspdta * 0.5 
       !
