Index: branches/UKMO/dev_r5518_GO6_diag_bitcomp/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- branches/UKMO/dev_r5518_GO6_diag_bitcomp/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 9706)
+++ branches/UKMO/dev_r5518_GO6_diag_bitcomp/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 9707)
@@ -254,7 +254,7 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bathy                              !: ocean depth (meters)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmask_i, umask_i, vmask_i, fmask_i !: interior domain T-point mask
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tmask_i_3d       !: 3D T-point mask of wrap and redundant N-fold points only.
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: umask_i_3d       !: 3D U-point mask of wrap and redundant N-fold points only.
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: vmask_i_3d       !: 3D V-point mask of wrap and redundant N-fold points only.
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tmask_i_diag     !: partial mask for use in T diagnostic mask calc. 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: umask_i_diag     !: partial mask for use in U diagnostic mask calc. 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: vmask_i_diag     !: partial mask for use in V diagnostic mask calc. 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bmask                              !: land/ocean mask of barotropic stream function
 
@@ -410,7 +410,7 @@
       ALLOCATE( tmask(jpi,jpj,jpk) , umask(jpi,jpj,jpk),     & 
          &      vmask(jpi,jpj,jpk) , fmask(jpi,jpj,jpk),     &
-                tmask_i_3d(jpi,jpj,jpk),       &
-                umask_i_3d(jpi,jpj,jpk),       &
-                vmask_i_3d(jpi,jpj,jpk),       &
+                tmask_i_diag(jpi,jpj,jpk),     &
+                umask_i_diag(jpi,jpj,jpk),     &
+                vmask_i_diag(jpi,jpj,jpk),     &
                 STAT=ierr(11) )
 
Index: branches/UKMO/dev_r5518_GO6_diag_bitcomp/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90
===================================================================
--- branches/UKMO/dev_r5518_GO6_diag_bitcomp/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 9706)
+++ branches/UKMO/dev_r5518_GO6_diag_bitcomp/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 9707)
@@ -1,2 +1,3 @@
+
 MODULE dommsk
    !!======================================================================
@@ -138,4 +139,5 @@
       REAL(wp) ::  zphi_drake_passage, zshlat_antarc
       REAL(wp), POINTER, DIMENSION(:,:) ::  zwf
+      REAL(wp) :: uv(jpi,jpj)
       !!
       NAMELIST/namlbc/ rn_shlat, ln_vorlat
@@ -223,4 +225,5 @@
       ! --------------------
       tmask_i(:,:) = ssmask(:,:)            ! (ISH) tmask_i = 1 even on the ice shelf
+
       iif = jpreci                         ! ???
       iil = nlci - jpreci + 1
@@ -232,13 +235,4 @@
       tmask_i(   :   , 1 :ijf) = 0._wp      ! first rows
       tmask_i(   :   ,ijl:jpj) = 0._wp      ! last  rows (including mpp extra rows)
-
-      tmask_i_3d(:,:,:) = tmask(:,:,:)      ! Initialise 3D interior tmask with standard t mask
-      ! Now mask out any wrap columns
-      tmask_i_3d( 1 :iif,:,:) = 0._wp       ! first columns
-      tmask_i_3d(iil:jpi,:,:) = 0._wp       ! last  columns (including mpp extra columns)
-      ! Now mask out any extra rows
-      tmask_i_3d(:,1:ijf,:) = 0._wp         ! first rows
-      tmask_i_3d(:,ijl:jpj,:) = 0._wp       ! last  rows (including mpp extra rows)
-
 
       ! north fold mask
@@ -252,9 +246,4 @@
             DO ji = iif+1, iil-1
                tmask_i(ji,nlej-1) = tmask_i(ji,nlej-1) * tpol(mig(ji))
-               ! It would seem logical that the following SHOULD be applied, 
-               ! but the existing code in iom.F90 which we are trying to 
-               ! replicate, and where we aim to use this array simply uses 
-               ! tmask which does NOT account for masking in the N-fold.  
-               ! tmask_i_3d(ji,nlej-1,:) = tmask_i_3d(ji,nlej-1,:) * tpol(mig(ji))
             END DO
          ENDIF
@@ -299,23 +288,61 @@
       CALL lbc_lnk( fmask_i, 'F', 1._wp )
 
-      ! Set up interior 3d U mask
-      umask_i_3d(2:jpim1,:,:) = tmask(2:jpim1,:,:) + tmask(3:jpi,:,:)
-      CALL lbc_lnk( umask_i_3d, 'U', 1. )
+
+      ! Set up mask for diagnostics on T points, to exclude duplicate
+      ! data points in wrap and N-fold regions. 
+      DO jk = 1, jpk
+         tmask_i_diag(:,:,jk) = tmask(:,:,jk) * tmask_i(:,:)
+      END DO
+
+      ! Set up mask for diagnostics on U points, to exclude duplicate
+      ! data points in wrap and N-fold regions. 
+      umask_i_diag(:,:,:) = 1.0
+      umask_i_diag(2:jpim1,:,:) = tmask(2:jpim1,:,:) + tmask(3:jpi,:,:)
+      CALL lbc_lnk( umask_i_diag, 'U', 1. )
       ! Now mask out any wrap columns
-      umask_i_3d( 1 :iif,:,:) = 0._wp       ! first columns
-      umask_i_3d(iil:jpi,:,:) = 0._wp       ! last  columns (including mpp extra columns)
+      umask_i_diag( 1 :iif,:,:) = 0._wp       ! first columns
+      umask_i_diag(iil:jpi,:,:) = 0._wp       ! last  columns (including mpp extra columns)
+      ! Now mask out any extra bottom rows
+      umask_i_diag(:,1:ijf,:) = 0._wp         ! first rows
+
+      ! Now find which points change sign during a U lbc_lnk to find
+      ! out which points to mask in the N fold.   
+      uv(:,:) = 1.0
+      CALL lbc_lnk( uv, 'U', -1. )
+
+      ! Now find out which points have changed sign and mask them 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF (uv(ji,jj) < 0.0) THEN
+               umask_i_diag(ji,jj,:) = 0.0
+            END IF
+         END DO
+      END DO
+
+      ! Set up mask for diagnostics on V points, to exclude duplicate
+      ! data points in wrap and N-fold regions. 
+      vmask_i_diag(:,:,:) = 1.0
+      vmask_i_diag(:,2:jpjm1,:) = tmask(:,2:jpjm1,:) + tmask(:,3:jpj,:)
+      CALL lbc_lnk( vmask_i_diag, 'V', 1. )
+
+      ! Now mask out any wrap columns
+      vmask_i_diag( 1 :iif,:,:) = 0._wp       ! first columns
+      vmask_i_diag(iil:jpi,:,:) = 0._wp       ! last  columns (including mpp extra columns)
       ! Now mask out any extra rows
-      umask_i_3d(:,1:ijf,:) = 0._wp         ! first rows
-      umask_i_3d(:,ijl:jpj,:) = 0._wp       ! last  rows (including mpp extra rows)
-
-      ! Set up interior 3d V mask
-      vmask_i_3d(:,2:jpjm1,:) = tmask(:,2:jpjm1,:) + tmask(:,3:jpj,:)
-      CALL lbc_lnk( vmask_i_3d, 'V', 1. )
-      ! Now mask out any wrap columns
-      vmask_i_3d( 1 :iif,:,:) = 0._wp       ! first columns
-      vmask_i_3d(iil:jpi,:,:) = 0._wp       ! last  columns (including mpp extra columns)
-      ! Now mask out any extra rows
-      vmask_i_3d(:,1:ijf,:) = 0._wp         ! first rows
-      vmask_i_3d(:,ijl:jpj,:) = 0._wp       ! last  rows (including mpp extra rows)
+      vmask_i_diag(:,1:ijf,:) = 0._wp         ! first rows
+
+      ! Now find which points change sign during a V lbc_lnk to find
+      ! out which points to mask in the N fold.   
+      uv(:,:) = 1.0
+      CALL lbc_lnk( uv, 'V', -1. )
+
+      ! Now find out which points have changed sign and mask them 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF (uv(ji,jj) < 0.0) THEN
+               vmask_i_diag(ji,jj,:) = 0.0
+            END IF
+         END DO
+      END DO
 
 
Index: branches/UKMO/dev_r5518_GO6_diag_bitcomp/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- branches/UKMO/dev_r5518_GO6_diag_bitcomp/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 9706)
+++ branches/UKMO/dev_r5518_GO6_diag_bitcomp/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 9707)
@@ -1400,15 +1400,23 @@
       IF ( ln_mskland ) THEN
          ! mask land points, keep values on coast line -> specific mask for U, V and W points
+
+
          SELECT CASE ( cdgrd )
+         ! The masks applied here are specifically used to mask out duplicate 
+         ! data poits in wrap columns and N-fold rows in order to ensure bit 
+         ! comparison of diagnostics which have not undergone an explicit
+         ! lbc_lnk prior to writing and which are thus prone to junk in 
+         ! in these duplicate points since they are not usually explicitly 
+         ! involved in field computation. 
          CASE('T')   
-            zmask(:,:,:) = tmask_i_3d(:,:,:)
-         CASE('U')
-            zmask(:,:,:) = umask_i_3d(:,:,:) 
-         CASE('V') 
-            zmask(:,:,:) = vmask_i_3d(:,:,:) 
+            zmask(:,:,:) = tmask_i_diag(:,:,:)
+         CASE('U')   	
+            zmask(:,:,:) = umask_i_diag(:,:,:)
+ 	 CASE('V')   
+            zmask(:,:,:) = vmask_i_diag(:,:,:)
          CASE('W')   
-            zmask(:,:,2:jpk  ) = tmask_i_3d(:,:,1:jpkm1) + tmask_i_3d(:,:,2:jpk)   
-            zmask(:,:,1) = tmask_i_3d(:,:,1)
-         END SELECT
+            zmask(:,:,2:jpk  ) = tmask_i_diag(:,:,1:jpkm1) + tmask_i_diag(:,:,2:jpk)   
+            zmask(:,:,1) = tmask_i_diag(:,:,1)
+        END SELECT
          !
 #if ! defined key_xios2
