Index: trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90
===================================================================
--- trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 2528)
+++ trunk/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 2715)
@@ -31,9 +31,10 @@
    USE dom_oce         ! ocean space and time domain
    USE phycst          ! physical constants
-   USE in_out_manager  ! I/O manager
    USE trdmod          ! ocean dynamics trends 
    USE trdmod_oce      ! ocean variables trends
+   USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
    USE lbclnk          ! lateral boundary condition 
+   USE lib_mpp         ! MPP library
 
    IMPLICIT NONE
@@ -76,8 +77,13 @@
       !!             - Save the trend (l_trddyn=T)
       !!----------------------------------------------------------------------
+      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released
+      USE wrk_nemo, ONLY:   ztrdu => wrk_3d_1 , ztrdv => wrk_3d_2   ! 3D workspace
+      !!
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      !!
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D temporary workspace
-      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      !
+      IF( wrk_in_use(3, 1,2) ) THEN
+         CALL ctl_stop('dyn_hpg: requested workspace arrays are unavailable')   ;   RETURN
+      ENDIF
       !
       IF( l_trddyn ) THEN                    ! Temporary saving of ua and va trends (l_trddyn)
@@ -104,4 +110,6 @@
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' hpg  - Ua: ', mask1=umask,   &
          &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
+      IF( wrk_not_released(3, 1,2) )   CALL ctl_stop('dyn_hpg: failed to release workspace arrays')
       !
    END SUBROUTINE dyn_hpg
@@ -144,5 +152,5 @@
       !
       IF( lk_vvl .AND. .NOT. ln_hpg_sco )   &
-         &   CALL ctl_stop( 'dyn_hpg_init : variable volume key_vvl require the standard jacobian formulation hpg_sco')
+         &   CALL ctl_stop('dyn_hpg_init : variable volume key_vvl require the standard jacobian formulation hpg_sco')
       !
       !                               ! Set nhpg from ln_hpg_... flags
@@ -164,5 +172,5 @@
       IF( ln_hpg_djc )   ioptio = ioptio + 1
       IF( ln_hpg_rot )   ioptio = ioptio + 1
-      IF ( ioptio /= 1 )   CALL ctl_stop( ' NO or several hydrostatic pressure gradient options used' )
+      IF( ioptio /= 1 )   CALL ctl_stop( 'NO or several hydrostatic pressure gradient options used' )
       !
    END SUBROUTINE dyn_hpg_init
@@ -185,6 +193,5 @@
       !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
       !!----------------------------------------------------------------------
-      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
-      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      USE oce, ONLY:   zhpi => ta , zhpj => sa   ! (ta,sa) used as 3D workspace
       !!
       INTEGER, INTENT(in) ::   kt    ! ocean time-step index
@@ -200,6 +207,5 @@
       ENDIF
       
-      ! Local constant initialization 
-      zcoef0 = - grav * 0.5_wp
+      zcoef0 = - grav * 0.5_wp      ! Local constant initialization 
 
       ! Surface value
@@ -247,6 +253,5 @@
       !! ** Action  : - Update (ua,va) with the now hydrastatic pressure trend
       !!---------------------------------------------------------------------- 
-      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
-      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      USE oce, ONLY:   zhpi => ta , zhpj => sa   ! (ta,sa) used as 3D workspace
       !!
       INTEGER, INTENT(in) ::   kt    ! ocean time-step index
@@ -349,6 +354,5 @@
       !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
       !!----------------------------------------------------------------------
-      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
-      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      USE oce, ONLY:   zhpi => ta , zhpj => sa   ! (ta,sa) used as 3D workspace
       !!
       INTEGER, INTENT(in) ::   kt    ! ocean time-step index
@@ -435,6 +439,5 @@
       !!             - Save the trend (l_trddyn=T)
       !!----------------------------------------------------------------------
-      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
-      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      USE oce, ONLY:   zhpi => ta , zhpj => sa   ! (ta,sa) used as 3D workspace
       !!
       INTEGER, INTENT(in) ::   kt    ! ocean time-step index
@@ -512,6 +515,5 @@
       !! Reference : Song, Mon. Wea. Rev., 126, 3213-3230, 1998.
       !!----------------------------------------------------------------------
-      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
-      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      USE oce, ONLY:   zhpi => ta , zhpj => sa   ! (ta,sa) used as 3D workspace
       !!
       INTEGER, INTENT(in) ::   kt    ! ocean time-step index
@@ -592,6 +594,13 @@
       !! Reference: Shchepetkin and McWilliams, J. Geophys. Res., 108(C3), 3090, 2003
       !!----------------------------------------------------------------------
-      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_in_use, wrk_not_released
+      USE oce     , ONLY:   zhpi  => ta        , zhpj => sa       ! (ta,sa) used as 3D workspace
+      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 +610,9 @@
       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( wrk_in_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
+      ENDIF
 
       IF( kt == nit000 ) THEN
@@ -611,5 +621,4 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   s-coordinate case, density Jacobian with cubic polynomial scheme'
       ENDIF
-
 
       ! Local constant initialization
@@ -802,4 +811,7 @@
       END DO
       !
+      IF( wrk_not_released(3, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) )   &
+         CALL ctl_stop('dyn:hpg_djc: failed to release workspace arrays')
+      !
    END SUBROUTINE hpg_djc
 
@@ -813,6 +825,11 @@
       !! Reference: Thiem & Berntsen, Ocean Modelling, In press, 2005.
       !!----------------------------------------------------------------------
-      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_in_use, wrk_not_released
+      USE oce     , ONLY:   zhpi    => ta       , zhpj    => sa       ! (ta,sa) used as 3D workspace
+      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 +838,10 @@
       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( wrk_in_use(2, 1,2,3)             .OR.   &
+          wrk_in_use(3, 1,2,3,4,5,6,7,8) ) THEN
+         CALL ctl_stop('dyn:hpg_rot: requested workspace arrays unavailable')   ;   RETURN
+      ENDIF
 
       IF( kt == nit000 ) THEN
@@ -981,4 +1000,7 @@
       END DO
       !
+      IF( wrk_not_released(2, 1,2,3)           .OR.   &
+          wrk_not_released(3, 1,2,3,4,5,6,7,8) )   CALL ctl_stop('dyn:hpg_rot: failed to release workspace arrays')
+      !
    END SUBROUTINE hpg_rot
 
