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 4449)
+++ branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 4450)
@@ -628,5 +628,5 @@
          DO jj = 1, jpjm1
             DO ji = 1, jpim1
-               DO jk = 1, jpk
+               DO jk = 1, mbkmax(ji,jj) ! jpk
 #else
          DO jk = 1, jpk
@@ -646,105 +646,102 @@
 
 #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 jj = 1, jpj, 1
-               DO ji = 1, jpi, 1
-                  DO jk = 1, jpkm1
-                     zwz(ji,jj,jk) = ff(ji,jj)      * ze3f(ji,jj,jk)
-                  END DO
-               END DO
-            END DO
-         CASE ( 2 )                                                ! relative  vorticity
-            DO jj = 1, jpj, 1
-               DO ji = 1, jpi, 1
-                  DO jk = 1, jpkm1
-                     zwz(ji,jj,jk) = rotn(ji,jj,jk) * ze3f(ji,jj,jk)
-                  END DO
-               END DO
-            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) ) &
+      ! Potential vorticity and horizontal fluxes
+      ! -----------------------------------------
+      SELECT CASE( kvor )      ! vorticity considered
+      CASE ( 1 )                                                ! planetary vorticity (Coriolis)
+         DO jj = 1, jpj, 1
+            DO ji = 1, jpi, 1
+               DO jk = 1, mbkmax(ji,jj)-1 ! jpkm1
+                  zwz(ji,jj,jk) = ff(ji,jj)      * ze3f(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      CASE ( 2 )                                                ! relative  vorticity
+         DO jj = 1, jpj, 1
+            DO ji = 1, jpi, 1
+               DO jk = 1, mbkmax(ji,jj)-1 ! jpkm1
+                  zwz(ji,jj,jk) = rotn(ji,jj,jk) * ze3f(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      CASE ( 3 )                                                ! metric term
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1 
+               DO jk = 1, mbkmax(ji,jj)-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 jj = 1, jpj, 1
-               DO ji = 1, jpi, 1
-                  DO jk = 1, jpkm1
-                     zwz(ji,jj,jk) = ( rotn(ji,jj,jk) + ff(ji,jj) ) * ze3f(ji,jj,jk)
-                  END DO
-               END DO
-            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)                                                                 &
+                       &     * 0.5_wp / ( 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 jj = 1, jpj, 1
+            DO ji = 1, jpi, 1
+               DO jk = 1, mbkmax(ji,jj)-1 ! jpkm1
+                  zwz(ji,jj,jk) = ( rotn(ji,jj,jk) + ff(ji,jj) ) * ze3f(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      CASE ( 5 )                                                ! total (coriolis + metric)
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               DO jk = 1, mbkmax(ji,jj)-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
-         ! ----------------------------------------
-         DO jj = 1,jpj,1
-            DO jk = 1,jpk,1
-               ztne(1,jj,jk) = 0.0_wp ; ztnw(1,jj,jk) = 0.0_wp 
-               ztse(1,jj,jk) = 0.0_wp ; ztsw(1,jj,jk) = 0.0_wp
-            END DO
-         END DO
-
-         DO jj = 2, jpj
-            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
-         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
+               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, mbkmax(ji,jj)-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
+      ! ----------------------------------------
+      DO jj = 1,jpj,1
+         DO jk = 1,mbkmax(1,jj) ! jpk,1
+            ztne(1,jj,jk) = 0.0_wp ; ztnw(1,jj,jk) = 0.0_wp 
+            ztse(1,jj,jk) = 0.0_wp ; ztsw(1,jj,jk) = 0.0_wp
+         END DO
+      END DO
+
+      DO jj = 2, jpj
+         DO ji = 2, jpi
+            DO jk = 1, mbkmax(ji,jj)-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, mbkmax(ji,jj)-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
 
 #else
