Index: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90
===================================================================
--- branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 2588)
+++ branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 2590)
@@ -76,8 +76,15 @@
       !!             - Save the trend (l_trddyn=T)
       !!----------------------------------------------------------------------
+      USE wrk_nemo, ONLY: wrk_use, wrk_release
+      USE wrk_nemo, ONLY: ztrdu => wrk_3d_1, ztrdv => wrk_3d_2
+      !!
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !!
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D temporary workspace
-      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      !
+      IF(.NOT. wrk_use(3, 1,2))THEN
+         CALL ctl_stop('dyn_hpg: requested workspace arrays are unavailable.')
+         RETURN
+      END IF
       !
       IF( l_trddyn ) THEN                    ! Temporary saving of ua and va trends (l_trddyn)
@@ -104,4 +111,8 @@
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' hpg  - Ua: ', mask1=umask,   &
          &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
+      IF(.NOT. wrk_release(3, 1,2))THEN
+         CALL ctl_stop('dyn_hpg: failed to release workspace arrays.')
+      END IF
       !
    END SUBROUTINE dyn_hpg
@@ -594,4 +605,12 @@
       USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
       USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      USE wrk_nemo, ONLY: wrk_use, wrk_release
+      USE wrk_nemo, ONLY: drhox => wrk_3d_1, dzx => wrk_3d_2
+      USE wrk_nemo, ONLY: drhou => wrk_3d_3, dzu => wrk_3d_4, rho_i => wrk_3d_5
+      USE wrk_nemo, ONLY: drhoy => wrk_3d_6, dzy => wrk_3d_7
+      USE wrk_nemo, ONLY: drhov => wrk_3d_8, dzv => wrk_3d_9, rho_j => wrk_3d_10
+      USE wrk_nemo, ONLY: drhoz => wrk_3d_11, dzz => wrk_3d_12 
+      USE wrk_nemo, ONLY: drhow => wrk_3d_13, dzw => wrk_3d_14
+      USE wrk_nemo, ONLY: rho_k => wrk_3d_15
       !!
       INTEGER, INTENT(in) ::   kt    ! ocean time-step index
@@ -601,8 +620,10 @@
       REAL(wp) ::   z1_10, cffu, cffx   !    "         "
       REAL(wp) ::   z1_12, cffv, cffy   !    "         "
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   drhox, dzx, drhou, dzu, rho_i   ! 3D workspace
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   drhoy, dzy, drhov, dzv, rho_j   !  "      "
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   drhoz, dzz, drhow, dzw, rho_k   !  "      "
-      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+
+      IF(.NOT. wrk_use(3, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15))THEN
+         CALL ctl_stop('dyn:hpg_djc : requested workspace arrays unavailable.')
+         RETURN
+      END IF
 
       IF( kt == nit000 ) THEN
@@ -802,4 +823,8 @@
       END DO
       !
+      IF(.NOT. wrk_release(3, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15))THEN
+         CALL ctl_stop('dyn:hpg_djc : failed to release workspace arrays.')
+      END IF
+      !
    END SUBROUTINE hpg_djc
 
@@ -815,4 +840,11 @@
       USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
       USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      USE wrk_nemo, ONLY: wrk_use, wrk_release
+      USE wrk_nemo, ONLY: zdistr => wrk_2d_1, zsina => wrk_2d_2, &
+                          zcosa  => wrk_2d_3
+      USE wrk_nemo, ONLY: zhpiorg => wrk_3d_1, zhpirot => wrk_3d_2
+      USE wrk_nemo, ONLY: zhpitra => wrk_3d_3, zhpine => wrk_3d_4
+      USE wrk_nemo, ONLY: zhpjorg => wrk_3d_5, zhpjrot => wrk_3d_6
+      USE wrk_nemo, ONLY: zhpjtra => wrk_3d_7, zhpjne => wrk_3d_8
       !!
       INTEGER, INTENT(in) ::   kt    ! ocean time-step index
@@ -821,8 +853,11 @@
       REAL(wp) ::   zforg, zcoef0, zuap, zmskd1, zmskd1m   ! temporary scalar
       REAL(wp) ::   zfrot        , zvap, zmskd2, zmskd2m   !    "         "
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zdistr, zsina, zcosa                ! 2D workspace
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhpiorg, zhpirot, zhpitra, zhpine   ! 3D workspace
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhpjorg, zhpjrot, zhpjtra, zhpjne   !  "      "
-      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+
+      IF( (.NOT. wrk_use(2, 1,2,3)) .OR.               &
+          (.NOT. wrk_use(3, 1,2,3,4,5,6,7,8)))THEN
+         CALL ctl_stop('dyn:hpg_rot : requested workspace arrays unavailable.')
+         RETURN
+      END IF
 
       IF( kt == nit000 ) THEN
@@ -981,4 +1016,9 @@
       END DO
       !
+      IF( (.NOT. wrk_release(2, 1,2,3)) .OR.               &
+          (.NOT. wrk_release(3, 1,2,3,4,5,6,7,8)))THEN
+         CALL ctl_stop('dyn:hpg_rot : failed to release workspace arrays.')
+      END IF
+      !
    END SUBROUTINE hpg_rot
 
