Index: /branches/2012/dev_v3_4_STABLE_2012/NEMOGCM/NEMO/OPATAM_SRC/DYN/dynvor_tam.F90
===================================================================
--- /branches/2012/dev_v3_4_STABLE_2012/NEMOGCM/NEMO/OPATAM_SRC/DYN/dynvor_tam.F90	(revision 4578)
+++ /branches/2012/dev_v3_4_STABLE_2012/NEMOGCM/NEMO/OPATAM_SRC/DYN/dynvor_tam.F90	(revision 4579)
@@ -40,4 +40,5 @@
    USE dom_oce
    USE dynadv
+   USE dynvor
    USE lbclnk
    USE lbclnk_tam
@@ -58,11 +59,4 @@
    PUBLIC   dyn_vor_adj     ! routine called by step_tam.F90
    PUBLIC   dyn_vor_adj_tst ! routine called by the tst.F90
-
-
-   !!* Namelist nam_dynvor: vorticity term
-   LOGICAL, PUBLIC ::   ln_dynvor_ene = .FALSE.   !: energy conserving scheme
-   LOGICAL, PUBLIC ::   ln_dynvor_ens = .TRUE.    !: enstrophy conserving scheme
-   LOGICAL, PUBLIC ::   ln_dynvor_mix = .FALSE.   !: mixed scheme
-   LOGICAL, PUBLIC ::   ln_dynvor_een = .FALSE.   !: energy and enstrophy conserving scheme
 
    INTEGER ::   nvor = 0   ! type of vorticity trend used
@@ -615,4 +609,5 @@
       CALL wrk_alloc( jpi, jpj,      zwxtl , zwytl , zwztl        )
       CALL wrk_alloc( jpi, jpj,      ztnwtl, ztnetl, ztswtl, ztsetl )
+
       zuatl = 0.0_wp ; zvatl = 0.0_wp
       zwx (:,:) = 0.0_wp ; zwy (:,:) = 0.0_wp ; zwz (:,:) = 0.0_wp
@@ -621,5 +616,5 @@
       ztnwtl(:,:) = 0.0_wp ; ztnetl(:,:) = 0.0_wp ; ztswtl(:,:) = 0.0_wp ; ztsetl(:,:) = 0.0_wp
 #if defined key_vvl
-      CALL wrk_alloc( jpi, jpj, jpk, ze3f_tl                   )
+      CALL ctl_stop( 'STOP', 'key_vvl not available for tam' )
 #endif
       IF( kt == nit000 ) THEN
@@ -760,11 +755,12 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-      CALL wrk_dealloc( jpi, jpj,      zwx , zwy , zwz        )
-      CALL wrk_dealloc( jpi, jpj,      ztnw, ztne, ztsw, ztse )
-      CALL wrk_dealloc( jpi, jpj,      zwxtl , zwytl , zwztl        )
+      CALL wrk_dealloc( jpi, jpj,      zwx , zwy , zwz                )
+      CALL wrk_dealloc( jpi, jpj,      ztnw, ztne, ztsw, ztse         )
+      CALL wrk_dealloc( jpi, jpj,      zwxtl , zwytl , zwztl          )
       CALL wrk_dealloc( jpi, jpj,      ztnwtl, ztnetl, ztswtl, ztsetl )
 #if defined key_vvl
-      CALL wrk_dealloc( jpi, jpj, jpk, ze3f_tl                   )
+      CALL wrk_dealloc( jpi, jpj, jpk, ze3f_tl                        )
 #endif
+      IF ( kt == nitend .AND. .NOT. lk_vvl ) DEALLOCATE( ze3f_tl )
       !
       IF( nn_timing == 1 )  CALL timing_stop('vor_een_tan')
@@ -1048,4 +1044,5 @@
       !!
       INTEGER ::   ji, jj, jk          ! dummy loop indices
+      INTEGER :: ierr
       REAL(wp) ::   zfac12             ! temporary scalars
       REAL(wp) ::   zuaad, zvaad       ! temporary scalars
@@ -1054,5 +1051,9 @@
       REAL(wp), POINTER, DIMENSION(:,:) ::   zwxad, zwyad, zwzad              ! temporary 2D workspace
       REAL(wp), POINTER, DIMENSION(:,:) ::   ztnwad, ztnead, ztswad, ztsead   ! temporary 3D workspace
+#if defined key_vvl
+      REAL(wp), POINTER, DIMENSION(:,:,:)       ::   ze3f_ad
+#else
       REAL(wp), POINTER, DIMENSION(:,:,:), SAVE ::   ze3f_ad
+#endif
       !!----------------------------------------------------------------------
       !
@@ -1063,5 +1064,5 @@
       CALL wrk_alloc( jpi, jpj,      zwxad , zwyad , zwzad        )
       CALL wrk_alloc( jpi, jpj,      ztnwad, ztnead, ztswad, ztsead )
-      CALL wrk_alloc( jpi, jpj, jpk,  ze3f_ad )
+
       ! local adjoint initailization
       zuaad = 0.0_wp ; zvaad = 0.0_wp
@@ -1072,11 +1073,21 @@
       ze3f_ad = 0._wp
 
+#if defined key_vvl
+      CALL wrk_alloc( jpi, jpj, jpk, ze3f_ad )
+#endif
+
       IF( kt == nitend ) THEN
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*) 'dyn:vor_een_adj : vorticity term: energy and enstrophy conserving scheme'
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+         IF( .NOT.lk_vvl ) THEN
+            ALLOCATE( ze3f_ad(jpi,jpj,jpk) , STAT=ierr )
+            IF( lk_mpp    )   CALL mpp_sum ( ierr )
+            IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'dyn:vor_een : unable to allocate arrays' )
+            ze3f_ad = 0._wp
+         ENDIF
       ENDIF
 
-      IF( kt == nit000 ) THEN      ! reciprocal of e3 at F-point (masked averaging of e3t)
+      IF( kt == nitend .OR. lk_vvl ) THEN      ! reciprocal of e3 at F-point (masked averaging of e3t)
          DO jk = 1, jpk
             DO jj = 1, jpjm1
@@ -1272,6 +1283,10 @@
       CALL wrk_dealloc( jpi, jpj,      zwxad , zwyad , zwzad        )
       CALL wrk_dealloc( jpi, jpj,      ztnwad, ztnead, ztswad, ztsead )
-      CALL wrk_dealloc( jpi, jpj, jpk, ze3f_ad)
-      !
+
+#if defined key_vvl
+      CALL wrk_dealloc( jpi, jpj, jpk, ze3f )
+#endif
+      IF ( kt == nit000 .AND. .NOT. lk_vvl ) DEALLOCATE( ze3f )      
+      
       IF( nn_timing == 1 )  CALL timing_stop('vor_een_adj')
       !
