Index: /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 3183)
+++ /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 3184)
@@ -27,4 +27,5 @@
    USE agrif_opa_sponge
    USE lib_mpp
+   USE wrk_nemo_2
 
    IMPLICIT NONE
@@ -47,6 +48,4 @@
       !!                  ***  ROUTINE Agrif_Tra  ***
       !!----------------------------------------------------------------------
-      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY: wrk_4d_1
       !!
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
@@ -58,9 +57,5 @@
       IF( Agrif_Root() )   RETURN
 
-      ztsa => wrk_4d_1 
-      IF( wrk_in_use(4, 1) )THEN
-         CALL ctl_stop('agrif_tra: requested workspace arrays unavailable.')
-         RETURN
-      END IF
+      CALL wrk_alloc( jpi, jpj, jpk, jpts, ztsa ) 
 
       Agrif_SpecialValue    = 0.e0
@@ -159,7 +154,5 @@
       ENDIF
       !
-      IF( wrk_not_released(4, 1) ) THEN
-         CALL ctl_stop('agrif_tra: failed to release workspace arrays.')
-      ENDIF
+      CALL wrk_dealloc( jpi, jpj, jpk, jpts, ztsa ) 
       !
    END SUBROUTINE Agrif_tra
@@ -170,8 +163,4 @@
       !!                  ***  ROUTINE Agrif_DYN  ***
       !!----------------------------------------------------------------------  
-      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY: wrk_2d_4, wrk_2d_5
-      USE wrk_nemo, ONLY: wrk_2d_6, wrk_2d_7
-      USE wrk_nemo, ONLY: wrk_3d_1, wrk_3d_2
       !! 
       INTEGER, INTENT(in) ::   kt
@@ -187,11 +176,6 @@
       IF( Agrif_Root() )   RETURN
 
-      spgu1  => wrk_2d_4 ; spgv1 => wrk_2d_5
-      zua2d  => wrk_2d_6 ; zva2d => wrk_2d_7
-      zua  => wrk_3d_1 ; zva => wrk_3d_2
-      IF( wrk_in_use(2, 4,5,6,7) .OR. wrk_in_use(3, 1,2) )THEN
-         CALL ctl_stop('agrif_dyn: requested workspace arrays unavailable.')
-         RETURN
-      END IF
+      CALL wrk_alloc( jpi, jpj, spgv1, spgu1, zua2d, zva2d )
+      CALL wrk_alloc( jpi, jpj, jpk, zua, zva )
 
       zrhox = Agrif_Rhox()
@@ -506,7 +490,6 @@
       ENDIF
       !
-      IF( wrk_not_released(3, 1,2) .OR. wrk_not_released(2, 4,5,6,7)) THEN
-         CALL ctl_stop('agrif_dyn: failed to release workspace arrays.')
-      ENDIF
+      CALL wrk_dealloc( jpi, jpj, spgv1, spgu1, zua2d, zva2d )
+      CALL wrk_dealloc( jpi, jpj, jpk, zua, zva )
       !
    END SUBROUTINE Agrif_dyn
Index: /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90
===================================================================
--- /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 3183)
+++ /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 3184)
@@ -8,4 +8,5 @@
    USE in_out_manager
    USE agrif_oce
+   USE wrk_nemo_2
 
    IMPLICIT NONE
@@ -27,7 +28,4 @@
       !!---------------------------------------------
 #include "domzgr_substitute.h90"
-      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY: wrk_2d_1, wrk_2d_2, wrk_2d_3
-      USE wrk_nemo, ONLY: wrk_4d_1, wrk_4d_2
       !!
       INTEGER :: ji,jj,jk,jn
@@ -41,9 +39,6 @@
 
 #if defined SPONGE
-      localviscsponge => wrk_2d_1
-      ztu             => wrk_2d_2
-      ztv             => wrk_2d_3
-      ztab            => wrk_4d_1
-      tsbdiff         => wrk_4d_2
+      CALL wrk_alloc( jpi, jpj, localviscsponge, ztu, ztv )
+      CALL wrk_alloc( jpi, jpj, jpk, jpts, ztab, tsbdiff  )
 
       timecoeff = REAL(Agrif_NbStepint(),wp)/Agrif_rhot()
@@ -152,4 +147,6 @@
       ENDDO
 
+      CALL wrk_dealloc( jpi, jpj, localviscsponge, ztu, ztv )
+      CALL wrk_dealloc( jpi, jpj, jpk, jpts, ztab, tsbdiff  )
 #endif
 
@@ -161,9 +158,4 @@
       !!---------------------------------------------
 #include "domzgr_substitute.h90"
-      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY: wrk_2d_1
-      USE wrk_nemo, ONLY: wrk_3d_1, wrk_3d_2
-      USE wrk_nemo, ONLY: wrk_3d_3, wrk_3d_4
-      USE wrk_nemo, ONLY: wrk_3d_5
       !!
       INTEGER :: ji,jj,jk
@@ -177,8 +169,6 @@
 
 #if defined SPONGE
-      localviscsponge => wrk_2d_1
-      ubdiff => wrk_3d_1 ; vbdiff => wrk_3d_2
-      rotdiff => wrk_3d_3 ; hdivdiff => wrk_3d_4
-      ztab => wrk_3d_5
+      CALL wrk_alloc( jpi, jpj, localviscsponge )
+      CALL wrk_alloc( jpi, jpj, jpk, ztab, ubdiff, vbdiff, rotdiff, hdivdiff )
 
       timecoeff = REAL(Agrif_NbStepint(),wp)/Agrif_rhot()
@@ -327,4 +317,6 @@
       END DO                                           !   End of slab
       !                                                ! ===============
+      CALL wrk_dealloc( jpi, jpj, localviscsponge )
+      CALL wrk_dealloc( jpi, jpj, jpk, ztab, ubdiff, vbdiff, rotdiff, hdivdiff )
 
 #endif
Index: /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90
===================================================================
--- /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 3183)
+++ /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 3184)
@@ -9,4 +9,6 @@
    USE in_out_manager  ! I/O manager
    USE lib_mpp
+   USE wrk_nemo_2
+
    IMPLICIT NONE
    PRIVATE
@@ -28,6 +30,4 @@
       !!   *** ROUTINE Agrif_Update_Tra ***
       !!---------------------------------------------
-      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY: wrk_4d_1
       !!
       INTEGER, INTENT(in) :: kt
@@ -37,9 +37,5 @@
       IF((Agrif_NbStepint() .NE. (Agrif_irhot()-1)).AND.(kt /= 0)) RETURN
 #if defined TWO_WAY
-      IF( wrk_in_use(4, 1) ) THEN
-         CALL ctl_stop('agrif_update_tra: ERROR: requested workspace arrays unavailable')
-         RETURN
-      END IF
-      ztab => wrk_4d_1
+      CALL wrk_alloc( jpi, jpj, jpk, jpts, ztab )
 
       Agrif_UseSpecialValueInUpdate = .TRUE.
@@ -54,7 +50,5 @@
       Agrif_UseSpecialValueInUpdate = .FALSE.
 
-      IF( wrk_not_released(4, 1) ) THEN
-         CALL ctl_stop('Agrif_Update_Tra: ERROR: failed to release workspace arrays')
-      END IF
+      CALL wrk_dealloc( jpi, jpj, jpk, jpts, ztab )
 #endif
 
@@ -65,7 +59,4 @@
       !!   *** ROUTINE Agrif_Update_Dyn ***
       !!---------------------------------------------
-      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY: wrk_2d_1
-      USE wrk_nemo, ONLY: wrk_3d_1
       !!
       INTEGER, INTENT(in) :: kt
@@ -76,9 +67,6 @@
       IF ((Agrif_NbStepint() .NE. (Agrif_irhot()-1)).AND.(kt /= 0)) Return
 #if defined TWO_WAY
-      ztab => wrk_3d_1 ; ztab2d => wrk_2d_1
-      IF( ( wrk_in_use(2, 1)) .OR.  wrk_in_use(3, 1) )THEN
-         CALL ctl_stop('agrif_update_dyn: ERROR: requested workspace arrays unavailable')
-         RETURN
-      END IF
+      CALL wrk_alloc( jpi, jpj,      ztab2d )
+      CALL wrk_alloc( jpi, jpj, jpk, ztab   )
 
       IF (mod(nbcline,nbclineupdate) == 0) THEN
@@ -100,7 +88,6 @@
       Agrif_UseSpecialValueInUpdate = .FALSE.
 
-      IF( wrk_not_released(2, 1) .OR. wrk_not_released(3, 1) )THEN
-         CALL ctl_stop('agrif_update_dyn: ERROR: failed to release workspace arrays')
-      END IF
+      CALL wrk_dealloc( jpi, jpj,      ztab2d )
+      CALL wrk_dealloc( jpi, jpj, jpk, ztab   )
 
 !Done in step
Index: /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90
===================================================================
--- /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90	(revision 3183)
+++ /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90	(revision 3184)
@@ -9,4 +9,5 @@
    USE trc
    USE lib_mpp
+   USE wrk_nemo_2
 
    IMPLICIT NONE
@@ -29,6 +30,4 @@
       !!   *** ROUTINE Agrif_trc ***
       !!---------------------------------------------
-      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY: wrk_4d_1
       
       INTEGER :: ji,jj,jk,jn
@@ -40,9 +39,5 @@
       IF (Agrif_Root()) RETURN
 
-      IF( wrk_in_use(4, 1) ) THEN
-         CALL ctl_stop('Agrif_trc : requested workspace arrays unavailable')
-         RETURN
-      ENDIF
-      ztra =>  wrk_4d_1(:,:,:,jptra)
+      CALL wrk_alloc( jpi, jpj, jpk, jptra, ztra )
 
       Agrif_SpecialValue=0.
@@ -141,8 +136,5 @@
       ENDIF
 
-      IF( wrk_not_released(4, 1) ) THEN
-         CALL ctl_stop('Agrif_trc : failed to release workspace arrays.')
-         RETURN
-      ENDIF
+      CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztra )
 
    END SUBROUTINE Agrif_trc
Index: /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90
===================================================================
--- /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90	(revision 3183)
+++ /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90	(revision 3184)
@@ -10,4 +10,5 @@
    USE trc
    USE lib_mpp
+   USE wrk_nemo_2
 
    IMPLICIT NONE
@@ -29,7 +30,4 @@
       !!---------------------------------------------
 #include "domzgr_substitute.h90"
-      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY: wrk_2d_1
-      USE wrk_nemo, ONLY: wrk_4d_1, wrk_4d_2, wrk_4d_3, wrk_4d_4
       !! 
       INTEGER :: ji,jj,jk,jl
@@ -41,13 +39,6 @@
 
 #if defined SPONGE_TOP
-      IF( wrk_in_use(4, 1,2,3,4) .OR. wrk_in_use(2, 1) ) THEN
-         CALL ctl_stop('Agrif_Sponge_trc : requested workspace arrays unavailable')
-         RETURN
-      ENDIF
-      localviscsponge => wrk_2d_1
-      trbdiff(:,:,:,:) => wrk_4d_1(:,:,:,1:jptra)
-      ztru   (:,:,:,:) => wrk_4d_2(:,:,:,1:jptra)
-      ztrv   (:,:,:,:) => wrk_4d_3(:,:,:,1:jptra)
-      ztab   (:,:,:,:) => wrk_4d_4(:,:,:,1:jptra)
+      CALL wrk_alloc( jpi, jpj, localviscsponge )
+      CALL wrk_alloc( jpi, jpj, jpk, jptra, trbdiff, ztru, ztrv, ztab )
 
       timecoeff = REAL(Agrif_NbStepint(),wp)/Agrif_rhot()
@@ -155,8 +146,6 @@
       ENDDO
  
-      IF( wrk_not_released(4, 1,2,3,4) .OR. wrk_not_released(2, 1) ) THEN
-         CALL ctl_stop('Agrif_Sponge_trc : failed to release workspace arrays.')
-         RETURN
-      ENDIF
+      CALL wrk_dealloc( jpi, jpj, localviscsponge )
+      CALL wrk_dealloc( jpi, jpj, jpk, jptra, trbdiff, ztru, ztrv, ztab )
 
 #endif
Index: /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_top_update.F90
===================================================================
--- /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_top_update.F90	(revision 3183)
+++ /branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/NST_SRC/agrif_top_update.F90	(revision 3184)
@@ -9,4 +9,5 @@
    USE agrif_oce
    USE trc
+   USE wrk_nemo_2
 
    IMPLICIT NONE
@@ -29,6 +30,4 @@
       !!   *** ROUTINE Agrif_Update_Trc ***
       !!---------------------------------------------
-      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY: wrk_4d_1
       !!
       INTEGER, INTENT(in) :: kt
@@ -39,9 +38,5 @@
 
 #if defined TWO_WAY
-      IF( wrk_in_use(4, 1) ) THEN
-         CALL ctl_stop('Agrif_Update_trc : requested workspace arrays unavailable')
-         RETURN
-      ENDIF
-      ztra =>  wrk_4d_1(:,:,:,jptra)
+      CALL wrk_alloc( jpi, jpj, jpk, jpts, ztra )
 
       Agrif_UseSpecialValueInUpdate = .TRUE.
@@ -57,8 +52,5 @@
       nbcline_trc = nbcline_trc + 1
 
-      IF( wrk_not_released(4, 1) ) THEN
-         CALL ctl_stop('Agrif_Update_trc : failed to release workspace arrays.')
-         RETURN
-      ENDIF
+      CALL wrk_dealloc( jpi, jpj, jpk, jpts, ztra )
 #endif
 
