Index: branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/OBS/obs_grid.F90
===================================================================
--- branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/OBS/obs_grid.F90	(revision 2740)
+++ branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/OBS/obs_grid.F90	(revision 3211)
@@ -85,4 +85,7 @@
       & grid_search_file    ! file name head for grid search lookup 
 
+   !! * Control permutation of array indices
+#  include "dom_oce_ftrans.h90"
+
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -128,31 +131,47 @@
          ELSE
             IF ( cdgrid == 'T' ) THEN
-               CALL obs_grd_bruteforce( jpi, jpj, jpiglo, jpjglo, &
-                  &                             nldi, nlei,nldj,  nlej,   &
-                  &                             nproc, jpnij,             &
-                  &                             glamt, gphit, tmask,      &
-                  &                             kobsin, plam, pphi,       &
-                  &                             kobsi, kobsj, kproc )
+               CALL obs_grd_bruteforce( jpi, jpj, jpiglo, jpjglo,        &
+                  &                     nldi, nlei,nldj,  nlej,          &
+                  &                     nproc, jpnij,                    &
+#if defined key_z_first
+                  &                     glamt, gphit, tmask_1(:,:),      &
+#else
+                  &                     glamt, gphit, tmask(:,:,1),      &
+#endif
+                  &                     kobsin, plam, pphi,              &
+                  &                     kobsi, kobsj, kproc )
             ELSEIF ( cdgrid == 'U' ) THEN
-               CALL obs_grd_bruteforce( jpi, jpj, jpiglo, jpjglo, &
-                  &                             nldi, nlei,nldj,  nlej,   &
-                  &                             nproc, jpnij,             &
-                  &                             glamu, gphiu, umask,      &
-                  &                             kobsin, plam, pphi,       &
-                  &                             kobsi, kobsj, kproc )
+               CALL obs_grd_bruteforce( jpi, jpj, jpiglo, jpjglo,        &
+                  &                     nldi, nlei,nldj,  nlej,          &
+                  &                     nproc, jpnij,                    &
+#if defined key_z_first
+                  &                     glamu, gphiu, umask_1(:,:),      &
+#else
+                  &                     glamu, gphiu, umask(:,:,1),      &
+#endif
+                  &                     kobsin, plam, pphi,              &
+                  &                     kobsi, kobsj, kproc )
             ELSEIF ( cdgrid == 'V' ) THEN
-               CALL obs_grd_bruteforce( jpi, jpj, jpiglo, jpjglo, &
-                  &                             nldi, nlei,nldj,  nlej,   &
-                  &                             nproc, jpnij,             &
-                  &                             glamv, gphiv, vmask,      &
-                  &                             kobsin, plam, pphi,       &
-                  &                             kobsi, kobsj, kproc )
+               CALL obs_grd_bruteforce( jpi, jpj, jpiglo, jpjglo,        &
+                  &                     nldi, nlei,nldj,  nlej,          &
+                  &                     nproc, jpnij,                    &
+#if defined key_z_first
+                  &                     glamv, gphiv, vmask_1(:,:),      &
+#else
+                  &                     glamv, gphiv, vmask(:,:,1),      &
+#endif
+                  &                     kobsin, plam, pphi,              &
+                  &                     kobsi, kobsj, kproc )
             ELSEIF ( cdgrid == 'F' ) THEN
-               CALL obs_grd_bruteforce( jpi, jpj, jpiglo, jpjglo, &
-                  &                             nldi, nlei,nldj,  nlej,   &
-                  &                             nproc, jpnij,             &
-                  &                             glamf, gphif, fmask,      &
-                  &                             kobsin, plam, pphi,       &
-                  &                             kobsi, kobsj, kproc )
+               CALL obs_grd_bruteforce( jpi, jpj, jpiglo, jpjglo,        &
+                  &                     nldi, nlei,nldj,  nlej,          &
+                  &                     nproc, jpnij,                    &
+#if defined key_z_first
+                  &                     glamf, gphif, fmask_1(:,:),      &
+#else
+                  &                     glamf, gphif, fmask(:,:,1),      &
+#endif
+                  &                     kobsin, plam, pphi,              &
+                  &                     kobsi, kobsj, kproc )
             ELSE
                CALL ctl_stop( 'Grid not supported' )
@@ -283,5 +302,9 @@
                zlamg(mig(ji),mjg(jj)) = glamt(ji,jj)
                zphig(mig(ji),mjg(jj)) = gphit(ji,jj)
+#if defined key_z_first
+               zmskg(mig(ji),mjg(jj)) = tmask_1(ji,jj)
+#else
                zmskg(mig(ji),mjg(jj)) = tmask(ji,jj,1)
+#endif
             END DO
          END DO
@@ -295,5 +318,9 @@
                zlamg(ji,jj) = glamt(ji,jj)
                zphig(ji,jj) = gphit(ji,jj)
+#if defined key_z_first
+               zmskg(ji,jj) = tmask_1(ji,jj)
+#else
                zmskg(ji,jj) = tmask(ji,jj,1)
+#endif
             END DO
          END DO
@@ -813,9 +840,9 @@
             END DO
             
-            CALL obs_grd_bruteforce( jpi, jpj, jpiglo, jpjglo,  &
-               &                     nldi, nlei,nldj,  nlej,    &
-               &                     nproc, jpnij,              &
-               &                     glamt, gphit, tmask,       &
-               &                     nlons*nlats, lonsi, latsi, &
+            CALL obs_grd_bruteforce( jpi, jpj, jpiglo, jpjglo,   &
+               &                     nldi, nlei,nldj,  nlej,     &
+               &                     nproc, jpnij,               &
+               &                     glamt, gphit, tmask(:,:,1), &
+               &                     nlons*nlats, lonsi, latsi,  &
                &                     ixposi, iyposi, iproci )
             
