Index: branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdicp.F90
===================================================================
--- branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdicp.F90	(revision 3180)
+++ branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdicp.F90	(revision 3181)
@@ -26,4 +26,6 @@
    USE eosbn2          ! equation of state
    USE phycst          ! physical constants
+   USE wrk_nemo_2      ! Memory allocation
+
 
    IMPLICIT NONE
@@ -251,7 +253,4 @@
       !! ** Purpose :  write dynamic trends in ocean.output 
       !!----------------------------------------------------------------------
-      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY:   zkepe => wrk_3d_1 , zkx => wrk_3d_2   ! 3D workspace
-      USE wrk_nemo, ONLY:   zky   => wrk_3d_3 , zkz => wrk_3d_4   !  -      -
       !
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
@@ -259,9 +258,8 @@
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
       REAL(wp) ::   zcof         ! local scalar
-      !!----------------------------------------------------------------------
-
-      IF( wrk_in_use(3, 1,2,3,4) ) THEN
-         CALL ctl_stop('trd_dwr: requested workspace arrays unavailable')   ;   RETURN
-      ENDIF
+      REAL(wp), POINTER, DIMENSION(:,:,:)  ::  zkx, zky, zkz, zkepe  
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, jpk, zkx, zky, zkz, zkepe )
 
       ! I. Momentum trends
@@ -439,5 +437,5 @@
       ENDIF
       !
-      IF( wrk_not_released(3, 1,2,3,4) )   CALL ctl_stop('trd_dwr: failed to release workspace arrays')
+      CALL wrk_dealloc( jpi, jpj, jpk, zkx, zky, zkz, zkepe )
       !
    END SUBROUTINE trd_dwr
Index: branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90
===================================================================
--- branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90	(revision 3180)
+++ branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90	(revision 3181)
@@ -38,4 +38,5 @@
    USE restart         ! for lrst_oce
    USE lib_mpp         ! MPP library
+   USE wrk_nemo_2      ! Memory allocation
 
    IMPLICIT NONE
@@ -93,6 +94,4 @@
       !!            surface and the control surface is called "mixed-layer"
       !!----------------------------------------------------------------------
-      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY:   zvlmsk => wrk_2d_10     ! 2D workspace
       !
       INTEGER                         , INTENT( in ) ::   ktrd       ! ocean trend index
@@ -102,9 +101,8 @@
       !
       INTEGER ::   ji, jj, jk, isum
-      !!----------------------------------------------------------------------
-
-      IF( wrk_in_use(2, 10) ) THEN
-         CALL ctl_stop('trd_mld_zint : requested workspace arrays unavailable')   ;   RETURN
-      ENDIF
+      REAL(wp), POINTER, DIMENSION(:,:)  :: zvlmsk 
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, zvlmsk ) 
 
       ! I. Definition of control surface and associated fields
@@ -195,5 +193,5 @@
       END SELECT
       !
-      IF( wrk_not_released(2, 10) )   CALL ctl_stop('trd_mld_zint: failed to release workspace arrays')
+      CALL wrk_dealloc( jpi, jpj, zvlmsk ) 
       !
    END SUBROUTINE trd_mld_zint
@@ -247,12 +245,4 @@
       !!       - See NEMO documentation (in preparation)
       !!----------------------------------------------------------------------
-      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY: ztmltot => wrk_2d_1,  zsmltot => wrk_2d_2 ! dT/dt over the anlysis window (including Asselin)
-      USE wrk_nemo, ONLY: ztmlres => wrk_2d_3,  zsmlres => wrk_2d_4 ! residual = dh/dt entrainment term
-      USE wrk_nemo, ONLY: ztmlatf => wrk_2d_5,  zsmlatf => wrk_2d_6 ! needed for storage only
-      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: wrk_3d_1, wrk_3d_2                     ! /
       !
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
@@ -261,4 +251,8 @@
       LOGICAL :: lldebug = .TRUE.
       REAL(wp) :: zavt, zfn, zfn2
+      !                                              ! z(ts)mltot : dT/dt over the anlysis window (including Asselin)
+      !                                              ! z(ts)mlres : residual = dh/dt entrainment term
+      REAL(wp), POINTER, DIMENSION(:,:  ) ::  ztmltot , zsmltot , ztmlres , zsmlres , ztmlatf , zsmlatf
+      REAL(wp), POINTER, DIMENSION(:,:  ) ::  ztmltot2, zsmltot2, ztmlres2, zsmlres2, ztmlatf2, zsmlatf2, ztmltrdm2, zsmltrdm2  
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztmltrd2, zsmltrd2   ! only needed for mean diagnostics
 #if defined key_dimgout
@@ -267,17 +261,8 @@
 #endif
       !!----------------------------------------------------------------------
-      
-      ! Check that the workspace arrays are all OK to be used
-      IF( wrk_in_use(2, 1,2,3,4,5,6,7,8,9,10,11,12,13,14)  .OR. &
-          wrk_in_use(3, 1,2)                                 ) THEN
-         CALL ctl_stop('trd_mld : requested workspace arrays unavailable')   ;   RETURN
-      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.')
-         RETURN         
-      END IF
-      ! Set-up pointers into sub-arrays of 3d-workspaces
-      ztmltrd2 => wrk_3d_1(1:,:,1:jpltrd)
-      zsmltrd2 => wrk_3d_2(1:,:,1:jpltrd)
+  
+      CALL wrk_alloc( jpi, jpj,         ztmltot , zsmltot , ztmlres , zsmlres , ztmlatf , zsmlatf                        )
+      CALL wrk_alloc( jpi, jpj,         ztmltot2, zsmltot2, ztmlres2, zsmlres2, ztmlatf2, zsmlatf2, ztmltrdm2, zsmltrdm2 )  
+      CALL wrk_alloc( jpi, jpj, jpltrd, ztmltrd2, zsmltrd2                                                               )
 
       ! ======================================================================
@@ -740,7 +725,7 @@
       IF( lrst_oce )   CALL trd_mld_rst_write( kt ) 
 
-      IF( wrk_not_released(2, 1,2,3,4,5,6,7,8,9,10,11,12,13,14)  .OR. &
-          wrk_not_released(3, 1,2)                                )   &
-          CALL ctl_stop('trd_mld : failed to release workspace arrays.')
+      CALL wrk_dealloc( jpi, jpj,         ztmltot , zsmltot , ztmlres , zsmlres , ztmlatf , zsmlatf                        )
+      CALL wrk_dealloc( jpi, jpj,         ztmltot2, zsmltot2, ztmlres2, zsmlres2, ztmlatf2, zsmlatf2, ztmltrdm2, zsmltrdm2 )  
+      CALL wrk_dealloc( jpi, jpj, jpltrd, ztmltrd2, zsmltrd2                                                               )
       !
    END SUBROUTINE trd_mld
Index: branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod.F90
===================================================================
--- branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod.F90	(revision 3180)
+++ branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod.F90	(revision 3181)
@@ -24,5 +24,7 @@
    USE trdmld                  ! ocean active mixed layer tracers trends 
    USE in_out_manager          ! I/O manager
-   USE lib_mpp         ! MPP library
+   USE lib_mpp                 ! MPP library
+   USE wrk_nemo_2              ! Memory allocation
+
 
    IMPLICIT NONE
@@ -52,11 +54,4 @@
       !!              integral constraints
       !!----------------------------------------------------------------------
-      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY: ztswu => wrk_2d_1,  &
-                          ztswv => wrk_2d_2,  &
-                          ztbfu => wrk_2d_3,  &
-                          ztbfv => wrk_2d_4,  &
-                          z2dx  => wrk_2d_5,  &
-                          z2dy  => wrk_2d_6
       !
       REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend 
@@ -67,9 +62,8 @@
       !!
       INTEGER ::   ji, jj   ! dummy loop indices
-      !!----------------------------------------------------------------------
-
-      IF(wrk_in_use(2, 1,2,3,4,5,6))THEN
-         CALL ctl_warn('trd_mod: Requested workspace arrays already in use.')   ;   RETURN
-      END IF
+      REAL(wp), POINTER, DIMENSION(:,:)  :: ztswu, ztswv, ztbfu, ztbfv, z2dx, z2dy 
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, ztswu, ztswv, ztbfu, ztbfv, z2dx, z2dy )
 
       z2dx(:,:) = 0._wp   ;   z2dy(:,:) = 0._wp                            ! initialization of workspace arrays
@@ -227,5 +221,5 @@
       ENDIF
       !
-      IF( wrk_not_released(2, 1,2,3,4,5,6) )   CALL ctl_warn('trd_mod: Failed to release workspace arrays.')
+      CALL wrk_dealloc( jpi, jpj, ztswu, ztswv, ztbfu, ztbfv, z2dx, z2dy )
       !
    END SUBROUTINE trd_mod
Index: branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90
===================================================================
--- branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 3180)
+++ branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 3181)
@@ -18,4 +18,6 @@
    USE in_out_manager   ! I/O manager
    USE lib_mpp          ! MPP library
+   USE wrk_nemo_2      ! Memory allocation
+
 
    IMPLICIT NONE
@@ -61,6 +63,4 @@
       !!        nn_ctls > 1  : use fixed level surface jk = nn_ctls
       !!----------------------------------------------------------------------
-      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY:   ztrds => wrk_3d_10   ! 3D workspace
       !
       INTEGER                         , INTENT(in)           ::  kt      ! time step
@@ -70,10 +70,10 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in)           ::  ptrd    ! tracer trend  or flux
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::  pun     ! velocity 
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::  ptra    ! Tracer variable 
-      !!----------------------------------------------------------------------
-
-      IF( wrk_in_use(3, 10) ) THEN
-         CALL ctl_stop('trd_tra: requested workspace array unavailable')   ;   RETURN
-      ENDIF
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::  ptra    ! Tracer variablea
+      !
+      REAL(wp), POINTER, DIMENSION(:,:,:)  ::  ztrds
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, jpk, ztrds )
 
       IF( .NOT. ALLOCATED( trdtx ) ) THEN       ! allocate trdtra arrays
@@ -138,5 +138,5 @@
       ENDIF
       !
-      IF( wrk_not_released(3, 10) )   CALL ctl_stop('trd_tra: failed to release workspace array')
+      CALL wrk_dealloc( jpi, jpj, jpk, ztrds )
       !
    END SUBROUTINE trd_tra
Index: branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90
===================================================================
--- branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 3180)
+++ branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 3181)
@@ -27,4 +27,6 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp         ! MPP library
+   USE wrk_nemo_2      ! Memory allocation
+
 
    IMPLICIT NONE
@@ -107,6 +109,4 @@
       !!      trends output in netCDF format using ioipsl
       !!----------------------------------------------------------------------
-      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY:   zudpvor => wrk_2d_1 , zvdpvor => wrk_2d_2   ! total cmulative trends
       !
       INTEGER                     , INTENT(in   ) ::   ktrd       ! ocean trend index
@@ -116,12 +116,12 @@
       INTEGER ::   ji, jj       ! dummy loop indices
       INTEGER ::   ikbu, ikbv   ! local integers
-      !!----------------------------------------------------------------------
-
-      IF( wrk_in_use(2, 1,2) ) THEN
-         CALL ctl_stop('trd_vor_zint_2d: requested workspace arrays unavailable')   ;   RETURN
-      ENDIF
-
-      ! Initialization
-      zudpvor(:,:) = 0._wp                 ;   zvdpvor(:,:) = 0._wp
+      REAL(wp), POINTER, DIMENSION(:,:) :: zudpvor, zvdpvor  ! total cmulative trends
+      !!----------------------------------------------------------------------
+
+      !
+      CALL wrk_alloc( jpi, jpj, zudpvor, zvdpvor )                                     ! Memory allocation
+      !
+
+      zudpvor(:,:) = 0._wp                 ;   zvdpvor(:,:) = 0._wp                    ! Initialisation
       CALL lbc_lnk( putrdvor, 'U', -1. )   ;   CALL lbc_lnk( pvtrdvor, 'V', -1. )      ! lateral boundary condition
       
@@ -167,5 +167,5 @@
       ENDIF
       !
-      IF( wrk_not_released(2, 1,2) )   CALL ctl_stop('trd_vor_zint_2d : failed to release workspace arrays.')
+      CALL wrk_dealloc( jpi, jpj, zudpvor, zvdpvor )                                   
       !
    END SUBROUTINE trd_vor_zint_2d
@@ -199,7 +199,4 @@
       !!      trends output in netCDF format using ioipsl
       !!----------------------------------------------------------------------
-      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY:   zubet   => wrk_2d_1,   zvbet => wrk_2d_2   ! Beta.V 
-      USE wrk_nemo, ONLY:   zudpvor => wrk_2d_3, zvdpvor => wrk_2d_4   ! total cmulative trends
       !
       INTEGER                         , INTENT(in   ) ::   ktrd       ! ocean trend index
@@ -208,9 +205,10 @@
       !
       INTEGER ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: zubet  , zvbet  ! Beta.V   
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zudpvor, zvdpvor  ! total cmulative trends
       !!----------------------------------------------------------------------
      
-      IF( wrk_in_use(2, 1,2,3,4) ) THEN
-         CALL ctl_stop('trd_vor_zint_3d: requested workspace arrays unavailable.')   ;   RETURN
-      ENDIF
+      CALL wrk_alloc( jpi, jpj,      zubet  , zvbet   )                                   
+      CALL wrk_alloc( jpi, jpj, jpk, zudpvor, zvdpvor )                                   
 
       ! Initialization
@@ -276,5 +274,6 @@
       ENDIF
       !
-      IF( wrk_not_released(2, 1,2,3,4) )   CALL ctl_stop('trd_vor_zint_3d: failed to release workspace arrays')
+      CALL wrk_dealloc( jpi, jpj,      zubet  , zvbet   )                                   
+      CALL wrk_dealloc( jpi, jpj, jpk, zudpvor, zvdpvor )                                   
       !
    END SUBROUTINE trd_vor_zint_3d
@@ -288,6 +287,4 @@
       !!               and make outputs (NetCDF or DIMG format)
       !!----------------------------------------------------------------------
-      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY:   zun => wrk_2d_1 , zvn => wrk_2d_2 ! 2D workspace
       !
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
@@ -296,9 +293,8 @@
       INTEGER  ::   it, itmod        ! local integers
       REAL(wp) ::   zmean            ! local scalars
-      !!----------------------------------------------------------------------
-
-      IF( wrk_in_use(2, 1,2) ) THEN
-         CALL ctl_stop('trd_vor: requested workspace arrays unavailable.')   ;   RETURN
-      ENDIF
+      REAL(wp), POINTER, DIMENSION(:,:) :: zun, zvn
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, zun, zvn )                                   
 
       !  =================
@@ -467,5 +463,5 @@
       IF( kt == nitend )   CALL histclo( nidvor )
       !
-      IF( wrk_not_released(2, 1,2) )   CALL ctl_stop('trd_vor: failed to release workspace arrays')
+      CALL wrk_dealloc( jpi, jpj, zun, zvn )                                   
       !
    END SUBROUTINE trd_vor
