Index: /trunk/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90
===================================================================
--- /trunk/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90	(revision 2761)
+++ /trunk/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90	(revision 2762)
@@ -78,5 +78,5 @@
    REAL(wp), ALLOCATABLE, SAVE,   DIMENSION(:,:,:) :: bblydta    ! frequency of bbl in the y direction at 2 consecutive times 
    LOGICAL :: l_offbbl
-#if defined key_ldfslp
+#if defined key_ldfslp && ! defined key_c1d
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: uslpdta    ! zonal isopycnal slopes
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: vslpdta    ! meridional isopycnal slopes
@@ -158,23 +158,4 @@
          !
          CALL dynrea( kt, MAX( 1, iperm1) )           ! data read for the iperm1 period
-         
-         IF( lk_ldfslp .AND. .NOT. lk_c1d ) THEN      ! Computes slopes (here tsn and avt are used as workspace)
-            tsn (:,:,:,jp_tem) = tdta  (:,:,:,2)
-            tsn (:,:,:,jp_sal) = sdta  (:,:,:,2)
-            avt(:,:,:)         = avtdta(:,:,:,2)
-         
-            CALL eos( tsn, rhd, rhop )   ! Time-filtered in situ density 
-            CALL bn2( tsn, rn2 )         ! before Brunt-Vaisala frequency
-            IF( ln_zps )   &
-               &   CALL zps_hde( kt, jpts, tsn, gtsu, gtsv,  &  ! Partial steps: before Horizontal DErivative
-               &                           rhd, gru , grv   )    ! of t, s, rd at the bottom ocean level
-            CALL zdf_mxl( kt )           ! mixed layer depth
-            CALL ldf_slp( kt, rhd, rn2 )
-         
-            uslpdta (:,:,:,2) = uslp (:,:,:)
-            vslpdta (:,:,:,2) = vslp (:,:,:)
-            wslpidta(:,:,:,2) = wslpi(:,:,:)
-            wslpjdta(:,:,:,2) = wslpj(:,:,:)
-         END IF
          !
          CALL swap_dyn_data            ! swap from record 2 to 1
@@ -183,22 +164,4 @@
          !
          CALL dynrea( kt, iper )       ! data read for the iper period
-         !
-         IF( lk_ldfslp .AND. .NOT. lk_c1d ) THEN      ! Computes slopes (here tsn and avt are used as workspace)
-            tsn (:,:,:,jp_tem) = tdta  (:,:,:,2)
-            tsn (:,:,:,jp_sal) = sdta  (:,:,:,2)
-            avt(:,:,:)         = avtdta(:,:,:,2)
-            !
-                           CALL eos( tsn, rhd, rhop )                   ! now in situ density 
-                           CALL bn2( tsn, rn2 )                         ! now Brunt-Vaisala frequency
-            IF( ln_zps )   CALL zps_hde( kt, jpts, tsn, gtsu, gtsv,  &  ! Partial steps: before Horizontal DErivative
-               &                                   rhd, gru , grv   )   ! of t, s, rd at the bottom ocean level
-                           CALL zdf_mxl( kt )                           ! mixed layer depth
-                           CALL ldf_slp( kt, rhd, rn2 )                 ! slope of iso-neutral surfaces
-            !
-            uslpdta (:,:,:,2) = uslp (:,:,:)
-            vslpdta (:,:,:,2) = vslp (:,:,:)
-            wslpidta(:,:,:,2) = wslpi(:,:,:)
-            wslpjdta(:,:,:,2) = wslpj(:,:,:)
-         END IF
          !
          lfirdyn = .FALSE.    ! trace the first call
@@ -226,23 +189,4 @@
          CALL dynrea( kt, iper )    ! data read for the iper period
          !
-         IF( lk_ldfslp .AND. .NOT. lk_c1d ) THEN
-            ! Computes slopes. Caution : here tsn and avt are used as workspace
-            tsn(:,:,:,jp_tem) = tdta  (:,:,:,2)
-            tsn(:,:,:,jp_sal) = sdta  (:,:,:,2)
-            avt(:,:,:)        = avtdta(:,:,:,2)
-            !
-                           CALL eos( tsn, rhd, rhop )                   ! now in situ density 
-                           CALL bn2( tsn, rn2 )                         ! now Brunt-Vaisala frequency
-            IF( ln_zps )   CALL zps_hde( kt, jpts, tsn, gtsu, gtsv,  &  ! Partial steps: before Horizontal DErivative
-               &                                   rhd, gru , grv   )   ! of t, s, rd at the bottom ocean level
-            CALL zdf_mxl( kt )                                          ! mixed layer depth
-            CALL ldf_slp( kt, rhd, rn2 )                                ! slope of iso-neutral surfaces
-            !
-            uslpdta (:,:,:,2) = uslp (:,:,:)
-            vslpdta (:,:,:,2) = vslp (:,:,:)
-            wslpidta(:,:,:,2) = wslpi(:,:,:)
-            wslpjdta(:,:,:,2) = wslpj(:,:,:)
-         END IF
-         !
          ndyn1 = ndyn2         ! store the information of the period read
          ndyn2 = iper
@@ -280,4 +224,5 @@
          CALL bbl( kt, 'TRC')
       END IF
+      !
       IF(ln_ctl) THEN
          CALL prt_ctl(tab3d_1=tsn(:,:,:,jp_tem), clinfo1=' tn      - : ', mask1=tmask, ovlap=1, kdim=jpk   )
@@ -305,5 +250,5 @@
          &      udta    (jpi,jpj,jpk,2), vdta    (jpi,jpj,jpk,2),    &
          &      wdta    (jpi,jpj,jpk,2), avtdta  (jpi,jpj,jpk,2),    &
-#if defined key_ldfslp 
+#if defined key_ldfslp && ! defined key_c1d
          &      uslpdta (jpi,jpj,jpk,2), vslpdta (jpi,jpj,jpk,2),    &
          &      wslpidta(jpi,jpj,jpk,2), wslpjdta(jpi,jpj,jpk,2),    &
@@ -338,25 +283,36 @@
       !!----------------------------------------------------------------------
       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: zu      => wrk_3d_3  , zv    => wrk_3d_4 , zw   => wrk_3d_5
+      USE wrk_nemo, ONLY: zt      => wrk_3d_6  , zs    => wrk_3d_7 , zavt => wrk_3d_8  
+      USE wrk_nemo, ONLY: zemp    => wrk_2d_11 , zqsr  => wrk_2d_12, zmld => wrk_2d_13
+      USE wrk_nemo, ONLY: zice    => wrk_2d_14 , zwspd => wrk_2d_15 
+      USE wrk_nemo, ONLY: ztaux   => wrk_2d_16 , ztauy => wrk_2d_17
+      USE wrk_nemo, ONLY: zbblx   => wrk_2d_18 , zbbly => wrk_2d_19
       USE wrk_nemo, ONLY: zaeiw2d => wrk_2d_10
+      USE wrk_nemo, ONLY: ztsn    => wrk_4d_1
       !
       INTEGER, INTENT(in) ::   kt, kenr   ! time index
       !!
       INTEGER ::  jkenr
+#if defined key_degrad
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: zahtu, zahtv, zahtw   ! Lateral diffusivity
+# if defined key_traldf_eiv
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: zaeiu, zaeiv, zaeiw   ! G&M coefficient
+# endif
+#endif
       !!----------------------------------------------------------------------
       ! 
-      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
+      IF( wrk_in_use(3, 3,4,5,6,7,8) .OR. &
+          wrk_in_use(4, 1)                             .OR. &
+          wrk_in_use(2, 10,11,12,13,14,15,16,17,18,19)               ) THEN
          CALL ctl_stop('domrea/dta_dyn: requested workspace arrays unavailable')   ;   RETURN
       ENDIF
+
+#if defined key_degrad
+      ALLOCATE( zahtu(jpi,jpj,jpk), zahtv(jpi,jpj,jpk), zahtw(jpi,jpj,jpk) ) 
+# if defined key_traldf_eiv
+      ALLOCATE( zaeiu(jpi,jpj,jpk), zaeiv(jpi,jpj,jpk), zaeiw(jpi,jpj,jpk) )
+# endif
+#endif
       
       ! cas d'un fichier non periodique : on utilise deux fois le premier et
@@ -414,7 +370,7 @@
 
       ! file grid-W
-!!      CALL iom_get ( numfl_w, jpdom_data, 'vovecrtz', zw   (:,:,:), jkenr )
+      ! CALL iom_get ( numfl_w, jpdom_data, 'vovecrtz', zw   (:,:,:), jkenr )
       ! Computation of vertical velocity using horizontal divergence
-      CALL wzv( zu, zv, zw, zhdiv )
+      CALL wzv( zu, zv, zw )
 
       IF( iom_varid( numfl_w, 'voddmavs', ldstop = .FALSE. ) > 0 ) THEN          ! avs exist: it is used
@@ -439,11 +395,30 @@
 #endif
 
-      udta(:,:,:,2) = zu(:,:,:) * umask(:,:,:)
-      vdta(:,:,:,2) = zv(:,:,:) * vmask(:,:,:) 
-      wdta(:,:,:,2) = zw(:,:,:) * tmask(:,:,:)
-
-      tdta(:,:,:,2)   = zt  (:,:,:) * tmask(:,:,:)
-      sdta(:,:,:,2)   = zs  (:,:,:) * tmask(:,:,:)
+      udta  (:,:,:,2) = zu  (:,:,:) * umask(:,:,:)
+      vdta  (:,:,:,2) = zv  (:,:,:) * vmask(:,:,:) 
+      wdta  (:,:,:,2) = zw  (:,:,:) * tmask(:,:,:)
+      tdta  (:,:,:,2) = zt  (:,:,:) * tmask(:,:,:)
+      sdta  (:,:,:,2) = zs  (:,:,:) * tmask(:,:,:)
       avtdta(:,:,:,2) = zavt(:,:,:) * tmask(:,:,:)
+
+#if defined key_ldfslp && ! defined key_c1d
+      ! Computes slopes (here tsn and avt are used as workspace)
+      ztsn (:,:,:,jp_tem) = tdta  (:,:,:,2)
+      ztsn (:,:,:,jp_sal) = sdta  (:,:,:,2)
+      avt(:,:,:)          = avtdta(:,:,:,2)
+      
+      CALL eos( ztsn, rhd, rhop )   ! Time-filtered in situ density 
+      CALL bn2( ztsn, rn2 )         ! before Brunt-Vaisala frequency
+      IF( ln_zps )   &
+         &   CALL zps_hde( kt, jpts, ztsn, gtsu, gtsv,  &  ! Partial steps: before Horizontal DErivative
+         &                           rhd, gru , grv   )    ! of t, s, rd at the bottom ocean level
+      CALL zdf_mxl( kt )           ! mixed layer depth
+      CALL ldf_slp( kt, rhd, rn2 )
+         
+      uslpdta (:,:,:,2) = uslp (:,:,:)
+      vslpdta (:,:,:,2) = vslp (:,:,:)
+      wslpidta(:,:,:,2) = wslpi(:,:,:)
+      wslpjdta(:,:,:,2) = wslpj(:,:,:)
+#endif
 
 #if ! defined key_degrad && defined key_traldf_c2d && defined key_traldf_eiv
@@ -486,8 +461,15 @@
       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
+      IF( wrk_not_released(3, 3,4,5,6,7,8) .OR. &
+          wrk_not_released(4, 1                            ) .OR. &
+          wrk_not_released(2, 10,11,12,13,14,15,16,17,18,19)                ) THEN
          CALL ctl_stop('domrea/dta_dyn: failed to release workspace arrays')
       END IF
+#if defined key_degrad
+      DEALLOCATE( zahtu )   ;   DEALLOCATE( zahtv )   ;   DEALLOCATE( zahtw )
+# if defined key_traldf_eiv
+      DEALLOCATE( zaeiu )   ;   DEALLOCATE( zaeiv )   ;   DEALLOCATE( zaeiw )
+# endif
+#endif
       !
    END SUBROUTINE dynrea
@@ -540,5 +522,5 @@
 
 
-   SUBROUTINE wzv( pu, pv, pw, phdiv )
+   SUBROUTINE wzv( pu, pv, pw )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE wzv  ***
@@ -556,12 +538,12 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) :: pu, pv    !:  horizontal velocities
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(  out) :: pw        !:  verticla velocity
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) :: phdiv     !:  horizontal divergence
       !!
       INTEGER  ::  ji, jj, jk
       REAL(wp) ::  zu, zu1, zv, zv1, zet
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zhdiv     !:  horizontal divergence
       !!----------------------------------------------------------------------
       !
       ! Computation of vertical velocity using horizontal divergence
-      phdiv(:,:,:) = 0.
+      zhdiv(:,:,:) = 0.
       DO jk = 1, jpkm1
          DO jj = 2, jpjm1
@@ -572,14 +554,14 @@
                zv1 = pv(ji  ,jj-1,jk) * vmask(ji  ,jj-1,jk) * e1v(ji  ,jj-1) * fse3v(ji  ,jj-1,jk)
                zet = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
-               phdiv(ji,jj,jk) = ( zu - zu1 + zv - zv1 ) * zet 
+               zhdiv(ji,jj,jk) = ( zu - zu1 + zv - zv1 ) * zet 
             END DO
          END DO
       END DO
-      CALL lbc_lnk( phdiv, 'T', 1. )      ! Lateral boundary conditions on phdiv
+      CALL lbc_lnk( zhdiv, 'T', 1. )      ! Lateral boundary conditions on zhdiv
       !
       ! computation of vertical velocity from the bottom
       pw(:,:,jpk) = 0._wp
       DO jk = jpkm1, 1, -1
-         pw(:,:,jk) = pw(:,:,jk+1) - fse3t(:,:,jk) * phdiv(:,:,jk)
+         pw(:,:,jk) = pw(:,:,jk+1) - fse3t(:,:,jk) * zhdiv(:,:,jk)
       END DO
       !
