Index: /branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90
===================================================================
--- /branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 4447)
+++ /branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 4448)
@@ -566,7 +566,20 @@
       !!----------------------------------------------------------------------
       USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released
+#if defined key_z_first
+!FTRANS zwx :I :I :z
+!FTRANS zwy :I :I :z
+!FTRANS zwz :I :I :z
+!FTRANS ztnw :I :I :z
+!FTRANS ztne :I :I :z
+!FTRANS ztsw :I :I :z
+!FTRANS ztse :I :I :z
+      USE wrk_nemo, ONLY:   zwx  => wrk_3d_8 , zwy  => wrk_3d_2 ,  zwz => wrk_3d_3     ! 2D workspace
+      USE wrk_nemo, ONLY:   ztnw => wrk_3d_4 , ztne => wrk_3d_5 
+      USE wrk_nemo, ONLY:   ztsw => wrk_3d_6 , ztse => wrk_3d_7
+#else
       USE wrk_nemo, ONLY:   zwx  => wrk_2d_1 , zwy  => wrk_2d_2 ,  zwz => wrk_2d_3     ! 2D workspace
       USE wrk_nemo, ONLY:   ztnw => wrk_2d_4 , ztne => wrk_2d_5 
       USE wrk_nemo, ONLY:   ztsw => wrk_2d_6 , ztse => wrk_2d_7
+#endif
 #if defined key_vvl
 !FTRANS ze3f :I :I :z
@@ -580,7 +593,5 @@
 !FTRANS pva :I :I :z
 !! DCSE_NEMO: work around a deficiency in ftrans
-!     REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pua    ! total u-trend
-!     REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pva    ! total v-trend
-      REAL(wp), INTENT(inout) ::   pua(jpi,jpj,jpkorig)    ! total u-trend
+      REAL(wp), INTENT(inout) ::   pua(jpi,jpj,jpkorig)   ! total u-trend
       REAL(wp), INTENT(inout) ::   pva(jpi,jpj,jpkorig)   ! total v-trend
       !!
@@ -594,5 +605,9 @@
       !!----------------------------------------------------------------------
 
+#if defined key_z_first
+      IF( wrk_in_use(3, 1,2,3,4,5,6,7,8) ) THEN
+#else
       IF( wrk_in_use(2, 1,2,3,4,5,6,7) .OR. wrk_in_use(3, 1) ) THEN
+#endif
          CALL ctl_stop('dyn:vor_een: requested workspace arrays unavailable')   ;   RETURN
       ENDIF
@@ -610,7 +625,13 @@
 
       IF( kt == nit000 .OR. lk_vvl ) THEN      ! reciprocal of e3 at F-point (masked averaging of e3t)
+#if defined key_z_first
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               DO jk = 1, jpk
+#else
          DO jk = 1, jpk
             DO jj = 1, jpjm1
                DO ji = 1, jpim1
+#endif
                   ze3f(ji,jj,jk) = ( fse3t(ji,jj+1,jk)*tmask(ji,jj+1,jk) + fse3t(ji+1,jj+1,jk)*tmask(ji+1,jj+1,jk)   &
                      &             + fse3t(ji,jj  ,jk)*tmask(ji,jj  ,jk) + fse3t(ji+1,jj  ,jk)*tmask(ji+1,jj  ,jk) ) * 0.25
@@ -624,4 +645,97 @@
       zfac12 = 1._wp / 12._wp    ! Local constant initialization
 
+#if defined key_z_first
+!      DO jk = 1, jpkm1
+         
+         ! Potential vorticity and horizontal fluxes
+         ! -----------------------------------------
+         SELECT CASE( kvor )      ! vorticity considered
+         CASE ( 1 )                                                ! planetary vorticity (Coriolis)
+            DO jk = 1, jpkm1
+               zwz(:,:,jk) = ff(:,:)      * ze3f(:,:,jk)
+            END DO
+         CASE ( 2 )                                                ! relative  vorticity
+            DO jk = 1, jpkm1
+               zwz(:,:,jk) = rotn(:,:,jk) * ze3f(:,:,jk)
+            END DO
+         CASE ( 3 )                                                ! metric term
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1 
+                  DO jk = 1, jpkm1
+                     zwz(ji,jj,jk) = (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) ) &
+                       &         - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &     * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) ) * ze3f(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+            CALL lbc_lnk( zwz, 'F', 1. )
+         CASE ( 4 )                                                ! total (relative + planetary vorticity)
+            DO jk = 1, jpkm1
+               zwz(:,:,jk) = ( rotn(:,:,jk) + ff(:,:) ) * ze3f(:,:,jk)
+            END DO
+         CASE ( 5 )                                                ! total (coriolis + metric)
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  DO jk = 1, jpkm1
+                     zwz(ji,jj,jk) = ( ff (ji,jj)                                                                 &
+                       &       + (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &           - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &       * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )                                                &
+                       &       ) * ze3f(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+            CALL lbc_lnk( zwz, 'F', 1. )
+         END SELECT
+
+         DO jj = 1, jpj, 1
+            DO ji = 1, jpi, 1
+               DO jk = 1, jpkm1
+                  zwx(ji,jj,jk) = e2u(ji,jj) * fse3u(ji,jj,jk) * un(ji,jj,jk)
+                  zwy(ji,jj,jk) = e1v(ji,jj) * fse3v(ji,jj,jk) * vn(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         ! Compute and add the vorticity term trend
+         ! ----------------------------------------
+         jj = 2
+         ztne(1,:,:) = 0   ;   ztnw(1,:,:) = 0   ;   ztse(1,:,:) = 0   ;   ztsw(1,:,:) = 0
+         DO ji = 2, jpi   
+               DO jk = 1, jpkm1
+                  ztne(ji,jj,jk) = zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk)
+                  ztnw(ji,jj,jk) = zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk)
+                  ztse(ji,jj,jk) = zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk)
+                  ztsw(ji,jj,jk) = zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk)
+               END DO
+         END DO
+         DO jj = 3, jpj
+            DO ji = fs_2, jpi   ! vector opt. ok because we start at jj = 3
+               DO jk = 1, jpkm1
+                  ztne(ji,jj,jk) = zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk)
+                  ztnw(ji,jj,jk) = zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk)
+                  ztse(ji,jj,jk) = zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk)
+                  ztsw(ji,jj,jk) = zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk)
+               END DO
+            END DO
+         END DO
+         DO jj = 2, jpjm1
+            DO ji = fs_2, jpim1
+               DO jk = 1, jpkm1
+                  zua = + zfac12 / e1u(ji,jj) * (  ztne(ji,jj  ,jk) * zwy(ji  ,jj  ,jk) + &
+                          ztnw(ji+1,jj,jk) * zwy(ji+1,jj  ,jk)   &
+                  &     + ztse(ji,jj  ,jk) * zwy(ji  ,jj-1,jk) + ztsw(ji+1,jj,jk) * zwy(ji+1,jj-1,jk) )
+                  zva = - zfac12 / e2v(ji,jj) * (  ztsw(ji,jj+1,jk) * zwx(ji-1,jj+1,jk) + &
+                          ztse(ji,jj+1,jk) * zwx(ji  ,jj+1,jk)   &
+                  &     + ztnw(ji,jj  ,jk) * zwx(ji-1,jj  ,jk) + ztne(ji,jj  ,jk) * zwx(ji  ,jj  ,jk) )
+                  pua(ji,jj,jk) = pua(ji,jj,jk) + zua
+                  pva(ji,jj,jk) = pva(ji,jj,jk) + zva
+               END DO
+            END DO  
+         END DO  
+
+!      END DO
+
+#else
 !CDIR PARALLEL DO PRIVATE( zwx, zwy, zwz, ztnw, ztne, ztsw, ztse )
       !                                                ! ===============
@@ -694,6 +808,12 @@
       END DO                                           !   End of slab
       !                                                ! ===============
+#endif
+
+#if defined key_z_first
+      IF( wrk_not_released(3, 1,2,3,4,5,6,7,8) ) CALL ctl_stop('dyn:vor_een: failed to release workspace arrays')
+#else
       IF( wrk_not_released(2, 1,2,3,4,5,6,7) .OR.   &
           wrk_not_released(3, 1)             )   CALL ctl_stop('dyn:vor_een: failed to release workspace arrays')
+#endif
       !
    END SUBROUTINE vor_een
