Index: /branches/UKMO/dev_r4650_general_vert_coord_obsoper/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90
===================================================================
--- /branches/UKMO/dev_r4650_general_vert_coord_obsoper/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 6989)
+++ /branches/UKMO/dev_r4650_general_vert_coord_obsoper/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 6990)
@@ -171,4 +171,5 @@
          &            ln_sla, ln_sladt, ln_slafb,                     &
          &            ln_ssh, ln_sst, ln_sstfb, ln_sss, ln_nea,       &
+         &            ln_bound_reject,                                &
          &            enactfiles, coriofiles, profbfiles,             &
          &            slafilesact, slafilespas, slafbfiles,           &
@@ -244,4 +245,5 @@
       ln_velfb_av(:) = .FALSE.
       ln_ignmis = .FALSE.
+      ln_bound_reject = .TRUE.
 
       ! Read Namelist namobs : control observation diagnostics
@@ -469,4 +471,5 @@
          WRITE(numout,*) '             Type of horizontal interpolation method        n2dint = ', n2dint
          WRITE(numout,*) '             Rejection of observations near land swithch    ln_nea = ', ln_nea
+         WRITE(numout,*) '             Rejection of obs near open bdys       ln_bound_reject = ', ln_bound_reject
          WRITE(numout,*) '             MSSH correction scheme                         nmsshc = ', nmsshc
          WRITE(numout,*) '             MDT  correction                               mdtcorr = ', mdtcorr
Index: /branches/UKMO/dev_r4650_general_vert_coord_obsoper/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90
===================================================================
--- /branches/UKMO/dev_r4650_general_vert_coord_obsoper/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 6989)
+++ /branches/UKMO/dev_r4650_general_vert_coord_obsoper/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 6990)
@@ -27,4 +27,8 @@
    USE obs_inter_sup      ! Interpolation support
    USE obs_oper           ! Observation operators
+#if defined key_bdy
+   USE bdy_oce, ONLY : &        ! Boundary information
+      idx_bdy, nb_bdy
+#endif
    USE lib_mpp, ONLY : &
       & ctl_warn, ctl_stop
@@ -43,4 +47,6 @@
       & calc_month_len     ! Calculate the number of days in the months of a year  
 
+   LOGICAL, PUBLIC :: ln_bound_reject  !: Remove obs near open boundaries   
+
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -79,5 +85,15 @@
          & gphit,   &
          & gdept_1d,&
-         & tmask     
+#if defined key_vvl
+         & gdepw_n, &
+         & gdept_n, &
+#else
+         & gdepw_1d,   &
+         & gdept_1d,   &
+#endif         
+         & tmask,   &
+         & ln_zco,  &
+         & ln_zps,  &
+         & nproc
       !! * Arguments
       TYPE(obs_prof), INTENT(INOUT) :: profdata     ! Full set of profile data
@@ -101,4 +117,6 @@
       INTEGER :: ilantobs      !  - within a model land cell (temperature)
       INTEGER :: ilansobs      !  - within a model land cell (salinity)
+      INTEGER :: ibdytobs      !  - boundary (temperature) 
+      INTEGER :: ibdysobs      !  - boundary (salinity)      
       INTEGER :: inlatobs      !  - close to land (temperature)
       INTEGER :: inlasobs      !  - close to land (salinity)
@@ -110,4 +128,6 @@
       INTEGER :: ilantobsmpp   !  - within a model land cell (temperature)
       INTEGER :: ilansobsmpp   !  - within a model land cell (salinity)
+      INTEGER :: ibdytobsmpp   !  - boundary (temperature) 
+      INTEGER :: ibdysobsmpp    !  - boundary (salinity)      
       INTEGER :: inlatobsmpp   !  - close to land (temperature)
       INTEGER :: inlasobsmpp   !  - close to land (salinity)
@@ -142,4 +162,6 @@
       inlatobs = 0
       inlasobs = 0
+      ibdytobs = 0
+      ibdysobs = 0
 
       ! -----------------------------------------------------------------------
@@ -198,9 +220,12 @@
          &                 profdata%nqc,          profdata%var(1)%nvqc, &
          &                 iosdtobs,              ilantobs,             &
-         &                 inlatobs,              ld_nea                )
+         &                 inlatobs,              ld_nea,               &
+         &                 ibdytobs,              ln_bound_reject       )
+
 
       CALL obs_mpp_sum_integer( iosdtobs, iosdtobsmpp )
       CALL obs_mpp_sum_integer( ilantobs, ilantobsmpp )
       CALL obs_mpp_sum_integer( inlatobs, inlatobsmpp )
+      CALL obs_mpp_sum_integer( ibdytobs, ibdytobsmpp )
 
       ! Salinity
@@ -218,9 +243,11 @@
          &                 profdata%nqc,          profdata%var(2)%nvqc, &
          &                 iosdsobs,              ilansobs,             &
-         &                 inlasobs,              ld_nea                )
+         &                 inlasobs,              ld_nea,               &
+         &                 ibdysobs,              ln_bound_reject       )
 
       CALL obs_mpp_sum_integer( iosdsobs, iosdsobsmpp )
       CALL obs_mpp_sum_integer( ilansobs, ilansobsmpp )
       CALL obs_mpp_sum_integer( inlasobs, inlasobsmpp )
+      CALL obs_mpp_sum_integer( ibdysobs, ibdysobsmpp )
 
       ! -----------------------------------------------------------------------
@@ -280,4 +307,6 @@
                &            inlatobsmpp
          ENDIF
+         WRITE(numout,*) ' Remaining T data near open boundary (removed) = ',&
+               &            ibdytobsmpp
          WRITE(numout,*) ' T data accepted                             = ', &
             &            prodatqc%nvprotmpp(1)
@@ -293,4 +322,6 @@
                &            inlasobsmpp
          ENDIF
+         WRITE(numout,*) ' Remaining S data near open boundary (removed) = ',&
+               &            ibdysobsmpp
          WRITE(numout,*) ' S data accepted                             = ', &
             &            prodatqc%nvprotmpp(2)
@@ -380,4 +411,5 @@
       INTEGER :: inlasobs     !  - close to land
       INTEGER :: igrdobs      !  - fail the grid search
+      INTEGER :: ibdysobs     !  - close to open boundary
                               ! Global counters for observations that
       INTEGER :: iotdobsmpp     !  - outside time domain
@@ -386,4 +418,5 @@
       INTEGER :: inlasobsmpp    !  - close to land
       INTEGER :: igrdobsmpp     !  - fail the grid search
+      INTEGER :: ibdysobsmpp    !  - close to open boundary   
       LOGICAL, DIMENSION(:), ALLOCATABLE :: & 
          & llvalid            ! SLA data selection
@@ -391,4 +424,5 @@
       INTEGER :: jstp         ! Time loop variable
       INTEGER :: inrc         ! Time index variable
+      INTEGER :: irec         ! Record index
 
       IF(lwp) WRITE(numout,*)'obs_pre_sla : Preparing the SLA observations...'
@@ -410,4 +444,5 @@
       ilansobs = 0
       inlasobs = 0
+      ibdysobs = 0
 
       ! -----------------------------------------------------------------------
@@ -443,9 +478,11 @@
          &                 tmask(:,:,1), sladata%nqc,  &
          &                 iosdsobs,     ilansobs,     &
-         &                 inlasobs,     ld_nea        )
+         &                 inlasobs,     ld_nea,       &
+         &                 ibdysobs,     ln_bound_reject        )
 
       CALL obs_mpp_sum_integer( iosdsobs, iosdsobsmpp )
       CALL obs_mpp_sum_integer( ilansobs, ilansobsmpp )
       CALL obs_mpp_sum_integer( inlasobs, inlasobsmpp )
+      CALL obs_mpp_sum_integer( ibdysobs, ibdysobsmpp )
 
       ! -----------------------------------------------------------------------
@@ -496,4 +533,6 @@
                &            inlasobsmpp
          ENDIF
+         WRITE(numout,*) ' Remaining SLA data near open boundary (removed) = ', &
+            &            ibdysobsmpp  
          WRITE(numout,*) ' SLA data accepted                             = ', &
             &            sladatqc%nsurfmpp
@@ -521,7 +560,48 @@
       ENDIF
 
+      !---------------------------------------------------------
+      ! Record handling
+      !---------------------------------------------------------
+      ! First count the number of records
+      sladatqc%nrec = 0
+      DO jstp = nit000 - 1, nitend
+         inrc = jstp - nit000 + 2
+         IF ( sladatqc%nsstpmpp(inrc) > 0 ) THEN
+            sladatqc%nrec = sladatqc%nrec + 1
+         ENDIF
+      END DO
+      ! Allocate record data
+      ALLOCATE( &
+         & sladatqc%mrecstp(sladatqc%nrec) &
+         & )
+      ! Finally save the time step corresponding to record rank
+      irec = 0
+      DO jstp = nit000 - 1, nitend
+         inrc = jstp - nit000 + 2
+         IF ( sladatqc%nsstpmpp(inrc) > 0 ) THEN
+            irec = irec + 1
+            sladatqc%mrecstp(irec) = inrc
+         ENDIF
+         IF ( lwp ) THEN
+            WRITE(numout,1999) inrc, sladatqc%nsstpmpp(inrc)
+         ENDIF
+      END DO
+     
+      ! Print record information
+      IF( lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,2000)
+         WRITE(numout,2001)
+         DO irec = 1, sladatqc%nrec
+            WRITE(numout,1999) irec, sladatqc%mrecstp(irec)
+         END DO
+      ENDIF
+
+
 1997  FORMAT(10X,'Time step',5X,'Sea level anomaly')
 1998  FORMAT(10X,'---------',5X,'-----------------')
 1999  FORMAT(10X,I9,5X,I17)
+2000  FORMAT(15X,'Record',10X,'Time step')
+2001  FORMAT(15X,'------',10X,'---------')
 
    END SUBROUTINE obs_pre_sla
@@ -567,4 +647,5 @@
       INTEGER :: inlasobs     !  - close to land
       INTEGER :: igrdobs      !  - fail the grid search
+      INTEGER :: ibdysobs     !  - close to open boundary
                               ! Global counters for observations that
       INTEGER :: iotdobsmpp   !  - outside time domain
@@ -573,4 +654,5 @@
       INTEGER :: inlasobsmpp  !  - close to land
       INTEGER :: igrdobsmpp   !  - fail the grid search
+      INTEGER :: ibdysobsmpp  !  - close to open boundary
       LOGICAL, DIMENSION(:), ALLOCATABLE :: & 
          & llvalid            ! SST data selection
@@ -578,4 +660,5 @@
       INTEGER :: jstp         ! Time loop variable
       INTEGER :: inrc         ! Time index variable
+      INTEGER :: irec         ! Record index
 
       IF(lwp) WRITE(numout,*)'obs_pre_sst : Preparing the SST observations...'
@@ -597,4 +680,5 @@
       ilansobs = 0
       inlasobs = 0
+      ibdysobs = 0 
 
       ! -----------------------------------------------------------------------
@@ -627,9 +711,11 @@
          &                 tmask(:,:,1), sstdata%nqc,  &
          &                 iosdsobs,     ilansobs,     &
-         &                 inlasobs,     ld_nea        )
+         &                 inlasobs,     ld_nea,       &
+         &                 ibdysobs,     ln_bound_reject        )
 
       CALL obs_mpp_sum_integer( iosdsobs, iosdsobsmpp )
       CALL obs_mpp_sum_integer( ilansobs, ilansobsmpp )
       CALL obs_mpp_sum_integer( inlasobs, inlasobsmpp )
+      CALL obs_mpp_sum_integer( ibdysobs, ibdysobsmpp )
 
       ! -----------------------------------------------------------------------
@@ -680,4 +766,6 @@
                &            inlasobsmpp
          ENDIF
+         WRITE(numout,*) ' Remaining SST data near open boundary (removed) = ', &
+            &               ibdysobsmpp
          WRITE(numout,*) ' SST data accepted                             = ', &
             &            sstdatqc%nsurfmpp
@@ -705,7 +793,47 @@
       ENDIF
 
+      !---------------------------------------------------------
+      ! Record handling
+      !---------------------------------------------------------
+      ! First count the number of records
+      sstdatqc%nrec = 0
+      DO jstp = nit000 - 1, nitend
+         inrc = jstp - nit000 + 2
+         IF ( sstdatqc%nsstpmpp(inrc) > 0 ) THEN
+            sstdatqc%nrec = sstdatqc%nrec + 1
+         ENDIF
+      END DO
+      ! Allocate record data
+      ALLOCATE( &
+         & sstdatqc%mrecstp(sstdatqc%nrec) &
+         & )
+      ! Finally save the time step corresponding to record rank
+      irec = 0
+      DO jstp = nit000 - 1, nitend
+         inrc = jstp - nit000 + 2
+         IF ( sstdatqc%nsstpmpp(inrc) > 0 ) THEN
+            irec = irec + 1
+            sstdatqc%mrecstp(irec) = inrc
+         ENDIF
+         IF ( lwp ) THEN
+            WRITE(numout,1999) jstp, sstdatqc%nsstpmpp(inrc)
+         ENDIF
+      END DO
+     
+      ! Print record information
+      IF( lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,2000)
+         WRITE(numout,2001)
+         DO irec = 1, sstdatqc%nrec
+            WRITE(numout,1999) irec, sstdatqc%mrecstp(irec) - 1
+         END DO
+      ENDIF
+      
 1997  FORMAT(10X,'Time step',5X,'Sea surface temperature')
 1998  FORMAT(10X,'---------',5X,'-----------------')
 1999  FORMAT(10X,I9,5X,I17)
+2000  FORMAT(15X,'Record',10X,'Time step')
+2001  FORMAT(15X,'------',10X,'---------')
       
    END SUBROUTINE obs_pre_sst
@@ -751,4 +879,5 @@
       INTEGER :: inlasobs     !  - close to land
       INTEGER :: igrdobs      !  - fail the grid search
+      INTEGER :: ibdysobs     !  - close to open boundary
                               ! Global counters for observations that
       INTEGER :: iotdobsmpp   !  - outside time domain
@@ -757,4 +886,5 @@
       INTEGER :: inlasobsmpp  !  - close to land
       INTEGER :: igrdobsmpp   !  - fail the grid search
+      INTEGER :: ibdysobsmpp  !  - close to open boundary
       LOGICAL, DIMENSION(:), ALLOCATABLE :: & 
          & llvalid            ! data selection
@@ -762,4 +892,5 @@
       INTEGER :: jstp         ! Time loop variable
       INTEGER :: inrc         ! Time index variable
+      INTEGER :: irec         ! Record index
 
       IF (lwp) WRITE(numout,*)'obs_pre_seaice : Preparing the sea ice observations...'
@@ -781,4 +912,5 @@
       ilansobs = 0
       inlasobs = 0
+      ibdysobs = 0
 
       ! -----------------------------------------------------------------------
@@ -811,9 +943,11 @@
          &                 tmask(:,:,1),    seaicedata%nqc,  &
          &                 iosdsobs,        ilansobs,        &
-         &                 inlasobs,        ld_nea           )
+         &                 inlasobs,        ld_nea,          &
+         &                 ibdysobs,        ln_bound_reject           )
 
       CALL obs_mpp_sum_integer( iosdsobs, iosdsobsmpp )
       CALL obs_mpp_sum_integer( ilansobs, ilansobsmpp )
       CALL obs_mpp_sum_integer( inlasobs, inlasobsmpp )
+      CALL obs_mpp_sum_integer( ibdysobs, ibdysobsmpp )
 
       ! -----------------------------------------------------------------------
@@ -864,4 +998,6 @@
                &            inlasobsmpp
          ENDIF
+         WRITE(numout,*) ' Remaining sea ice data near open boundary (removed) = ', &
+           &            ibdysobsmpp 
          WRITE(numout,*) ' Sea ice data accepted                             = ', &
             &            seaicedatqc%nsurfmpp
@@ -889,7 +1025,47 @@
       ENDIF
 
+      !---------------------------------------------------------
+      ! Record handling
+      !---------------------------------------------------------
+      ! First count the number of records
+      seaicedatqc%nrec = 0
+      DO jstp = nit000 - 1, nitend
+         inrc = jstp - nit000 + 2
+         IF ( seaicedatqc%nsstpmpp(inrc) > 0 ) THEN
+            seaicedatqc%nrec = seaicedatqc%nrec + 1
+         ENDIF
+      END DO
+      ! Allocate record data
+      ALLOCATE( &
+         & seaicedatqc%mrecstp(seaicedatqc%nrec) &
+         & )
+      ! Finally save the time step corresponding to record rank
+      irec = 0
+      DO jstp = nit000 - 1, nitend
+         inrc = jstp - nit000 + 2
+         IF ( seaicedatqc%nsstpmpp(inrc) > 0 ) THEN
+            irec = irec + 1
+            seaicedatqc%mrecstp(irec) = inrc
+         ENDIF
+         IF ( lwp ) THEN
+            WRITE(numout,1999) inrc, seaicedatqc%nsstpmpp(inrc)
+         ENDIF
+      END DO
+     
+      ! Print record information
+      IF( lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,2000)
+         WRITE(numout,2001)
+         DO irec = 1, seaicedatqc%nrec
+            WRITE(numout,1999) irec, seaicedatqc%mrecstp(irec)
+         END DO
+      ENDIF
+
 1997  FORMAT(10X,'Time step',5X,'Sea ice data           ')
 1998  FORMAT(10X,'---------',5X,'-----------------')
 1999  FORMAT(10X,I9,5X,I17)
+2000  FORMAT(15X,'Record',10X,'Time step')
+2001  FORMAT(15X,'------',10X,'---------')
       
    END SUBROUTINE obs_pre_seaice
@@ -939,4 +1115,6 @@
       INTEGER :: inlavobs     !  - close to land (meridional velocity component)
       INTEGER :: igrdobs      !  - fail the grid search
+      INTEGER :: ibdyuobs     !  - close to open boundary
+      INTEGER :: ibdyvobs     !  - close to open boundary
       INTEGER :: iuvchku      !  - reject u if v rejected and vice versa
       INTEGER :: iuvchkv      !
@@ -950,4 +1128,6 @@
       INTEGER :: inlavobsmpp  !  - close to land (meridional velocity component)
       INTEGER :: igrdobsmpp   !  - fail the grid search
+      INTEGER :: ibdyuobsmpp  !  - close to open boundary
+      INTEGER :: ibdyvobsmpp  !  - close to open boundary
       INTEGER :: iuvchkumpp   !  - reject u if v rejected and vice versa
       INTEGER :: iuvchkvmpp   !
@@ -981,4 +1161,6 @@
       inlauobs = 0
       inlavobs = 0
+      ibdyuobs = 0 
+      ibdyvobs = 0 
       iuvchku  = 0
       iuvchkv = 0
@@ -1033,9 +1215,11 @@
          &                 profdata%nqc,          profdata%var(1)%nvqc, &
          &                 iosduobs,              ilanuobs,             &
-         &                 inlauobs,              ld_nea                )
+         &                 inlauobs,              ld_nea,               &
+         &                 ibdyuobs,              ln_bound_reject                )
 
       CALL obs_mpp_sum_integer( iosduobs, iosduobsmpp )
       CALL obs_mpp_sum_integer( ilanuobs, ilanuobsmpp )
       CALL obs_mpp_sum_integer( inlauobs, inlauobsmpp )
+      CALL obs_mpp_sum_integer( ibdyuobs, ibdyuobsmpp )
 
       ! Meridional Velocity Component
@@ -1053,9 +1237,11 @@
          &                 profdata%nqc,          profdata%var(2)%nvqc, &
          &                 iosdvobs,              ilanvobs,             &
-         &                 inlavobs,              ld_nea                )
+         &                 inlavobs,              ld_nea,               &
+         &                 ibdyvobs,              ln_bound_reject                )
 
       CALL obs_mpp_sum_integer( iosdvobs, iosdvobsmpp )
       CALL obs_mpp_sum_integer( ilanvobs, ilanvobsmpp )
       CALL obs_mpp_sum_integer( inlavobs, inlavobsmpp )
+      CALL obs_mpp_sum_integer( ibdyvobs, ibdyvobsmpp )
 
       ! -----------------------------------------------------------------------
@@ -1123,4 +1309,6 @@
                &            inlauobsmpp
          ENDIF
+         WRITE(numout,*) ' Remaining U data near open boundary (removed) = ', &
+           &            ibdyuobsmpp
          WRITE(numout,*) ' U observation rejected since V rejected     = ', &
             &            iuvchku     
@@ -1138,4 +1326,6 @@
                &            inlavobsmpp
          ENDIF
+         WRITE(numout,*) ' Remaining V data near open boundary (removed) = ', &
+            &            ibdyvobsmpp
          WRITE(numout,*) ' V observation rejected since U rejected     = ', &
             &            iuvchkv     
@@ -1530,5 +1720,6 @@
       &                       plam,   pphi,    pmask,            &
       &                       kobsqc, kosdobs, klanobs,          &
-      &                       knlaobs,ld_nea                     )
+      &                       knlaobs,ld_nea,                    &
+      &                       kbdyobs,ld_bound_reject            )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE obs_coo_spc_2d  ***
@@ -1566,8 +1757,15 @@
       INTEGER, INTENT(INOUT) :: klanobs   ! Observations within a model land cell
       INTEGER, INTENT(INOUT) :: knlaobs   ! Observations near land
+      INTEGER, INTENT(INOUT) :: kbdyobs     ! Observations near boundary
       LOGICAL, INTENT(IN) :: ld_nea       ! Flag observations near land
+      LOGICAL, INTENT(IN) :: ld_bound_reject  ! Flag observations near open boundary 
       !! * Local declarations
       REAL(KIND=wp), DIMENSION(2,2,kobsno) :: &
          & zgmsk              ! Grid mask
+#if defined key_bdy 
+      REAL(KIND=wp), DIMENSION(2,2,kobsno) :: &
+         & zbmsk              ! Boundary mask
+      REAL(KIND=wp), DIMENSION(jpi,jpj) :: zbdymask
+#endif 
       REAL(KIND=wp), DIMENSION(2,2,kobsno) :: &
          & zglam, &           ! Model longitude at grid points
@@ -1611,4 +1809,18 @@
 
       END DO
+
+#if defined key_bdy             
+      ! Create a mask grid points in boundary rim
+      IF (ld_bound_reject) THEN
+         zbdymask(:,:) = 1.0_wp
+         DO ji = 1, nb_bdy
+            DO jj = 1, idx_bdy(ji)%nblen(1)
+               zbdymask(idx_bdy(ji)%nbi(jj,1),idx_bdy(ji)%nbj(jj,1)) = 0.0_wp
+            ENDDO
+         ENDDO
+ 
+         CALL obs_int_comm_2d( 2, 2, kobsno, igrdi, igrdj, zbdymask, zbmsk )       
+      ENDIF
+#endif       
       
       CALL obs_int_comm_2d( 2, 2, kobsno, igrdi, igrdj, pmask, zgmsk )
@@ -1656,21 +1868,31 @@
          END DO
   
-         ! For observations on the grid reject them if their are at
-         ! a masked point
-         
-         IF (lgridobs) THEN
-            IF (zgmsk(iig,ijg,jobs) == 0.0_wp ) THEN
-               kobsqc(jobs) = kobsqc(jobs) + 12
-               klanobs = klanobs + 1
+         ! Flag if the observation falls is close to land
+         IF ( MINVAL( zgmsk(1:2,1:2,jobs) ) == 0.0_wp) THEN
+            knlaobs = knlaobs + 1
+            IF (ld_nea) THEN
+               kobsqc(jobs) = kobsqc(jobs) + 14
                CYCLE
             ENDIF
          ENDIF
-                      
-         ! Flag if the observation falls is close to land
-         IF ( MINVAL( zgmsk(1:2,1:2,jobs) ) == 0.0_wp) THEN
-            IF (ld_nea) kobsqc(jobs) = kobsqc(jobs) + 14
-            knlaobs = knlaobs + 1
-            CYCLE
-         ENDIF
+
+#if defined key_bdy
+         ! Flag if the observation falls close to the boundary rim
+         IF (ld_bound_reject) THEN
+            IF ( MINVAL( zbmsk(1:2,1:2,jobs) ) == 0.0_wp ) THEN
+               kobsqc(jobs) = kobsqc(jobs) + 15
+               kbdyobs = kbdyobs + 1
+               CYCLE
+            ENDIF
+            ! for observations on the grid...
+            IF (lgridobs) THEN
+               IF (zbmsk(iig,ijg,jobs) == 0.0_wp ) THEN
+                  kobsqc(jobs) = kobsqc(jobs) + 15
+                  kbdyobs = kbdyobs + 1
+                  CYCLE
+               ENDIF
+            ENDIF
+         ENDIF
+#endif 
             
       END DO
@@ -1684,5 +1906,6 @@
       &                       plam,    pphi,    pdep,    pmask, &
       &                       kpobsqc, kobsqc,  kosdobs,        &
-      &                       klanobs, knlaobs, ld_nea          )
+      &                       klanobs, knlaobs, ld_nea,         &
+      &                       kbdyobs, ld_bound_reject          )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE obs_coo_spc_3d  ***
@@ -1749,8 +1972,15 @@
       INTEGER, INTENT(INOUT) :: klanobs     ! Observations within a model land cell
       INTEGER, INTENT(INOUT) :: knlaobs     ! Observations near land
+      INTEGER, INTENT(INOUT) :: kbdyobs     ! Observations near boundary
       LOGICAL, INTENT(IN) :: ld_nea         ! Flag observations near land
+      LOGICAL, INTENT(IN) :: ld_bound_reject  ! Flag observations near open boundary
       !! * Local declarations
       REAL(KIND=wp), DIMENSION(2,2,kpk,kprofno) :: &
          & zgmsk              ! Grid mask
+#if defined key_bdy 
+      REAL(KIND=wp), DIMENSION(2,2,kprofno) :: &
+         & zbmsk              ! Boundary mask
+      REAL(KIND=wp), DIMENSION(jpi,jpj) :: zbdymask
+#endif 
       REAL(KIND=wp), DIMENSION(2,2,kpk,kprofno) :: &
          & zgdepw         
@@ -1797,4 +2027,18 @@
          
       END DO
+
+#if defined key_bdy 
+      ! Create a mask grid points in boundary rim
+      IF (ld_bound_reject) THEN           
+         zbdymask(:,:) = 1.0_wp
+         DO ji = 1, nb_bdy
+            DO jj = 1, idx_bdy(ji)%nblen(1)
+               zbdymask(idx_bdy(ji)%nbi(jj,1),idx_bdy(ji)%nbj(jj,1)) = 0.0_wp
+            ENDDO
+         ENDDO
+      ENDIF
+ 
+      CALL obs_int_comm_2d( 2, 2, kprofno, igrdi, igrdj, zbdymask, zbmsk )
+#endif 
       
       CALL obs_int_comm_3d( 2, 2, kprofno, kpk, igrdi, igrdj, pmask, zgmsk )
@@ -1876,5 +2120,4 @@
              
             ELSE ! Case 2 
- 
                ! Flag if the observation is deeper than the bathymetry 
                ! Or if it is within the mask 
@@ -1908,16 +2151,28 @@
                ENDIF
             ENDIF
-           
-            ! Flag if the observation falls is close to land
-            IF ( MINVAL( zgmsk(1:2,1:2,kobsk(jobsp)-1:kobsk(jobsp),jobs) ) == &
-               &  0.0_wp) THEN
-               IF (ld_nea) kobsqc(jobsp) = kobsqc(jobsp) + 14
-               knlaobs = knlaobs + 1
-            ENDIF
-
+            
             ! Set observation depth equal to that of the first model depth
             IF ( pobsdep(jobsp) <= pdep(1) ) THEN
                pobsdep(jobsp) = pdep(1)  
             ENDIF
+            
+#if defined key_bdy
+            ! Flag if the observation falls close to the boundary rim
+            IF (ld_bound_reject) THEN
+               IF ( MINVAL( zbmsk(1:2,1:2,jobs) ) == 0.0_wp ) THEN
+                  kobsqc(jobsp) = kobsqc(jobsp) + 15
+                  kbdyobs = kbdyobs + 1
+                  CYCLE
+               ENDIF
+               ! for observations on the grid...
+               IF (lgridobs) THEN
+                  IF (zbmsk(iig,ijg,jobs) == 0.0_wp ) THEN
+                     kobsqc(jobsp) = kobsqc(jobsp) + 15
+                     kbdyobs = kbdyobs + 1
+                     CYCLE
+                  ENDIF
+               ENDIF
+            ENDIF
+#endif 
             
          END DO
Index: /branches/UKMO/dev_r4650_general_vert_coord_obsoper/NEMOGCM/NEMO/OPA_SRC/OBS/obs_surf_def.F90
===================================================================
--- /branches/UKMO/dev_r4650_general_vert_coord_obsoper/NEMOGCM/NEMO/OPA_SRC/OBS/obs_surf_def.F90	(revision 6989)
+++ /branches/UKMO/dev_r4650_general_vert_coord_obsoper/NEMOGCM/NEMO/OPA_SRC/OBS/obs_surf_def.F90	(revision 6990)
@@ -50,4 +50,5 @@
       INTEGER :: npj
       INTEGER :: nsurfup    !: Observation counter used in obs_oper
+      INTEGER :: nrec       !: Number of surface observation records in window
 
       ! Arrays with size equal to the number of surface observations
@@ -56,4 +57,5 @@
          & mi,   &        !: i-th grid coord. for interpolating to surface observation
          & mj,   &        !: j-th grid coord. for interpolating to surface observation
+         & mt,   &        !: time record number for gridded data
          & nsidx,&        !: Surface observation number
          & nsfil,&        !: Surface observation number in file
@@ -90,4 +92,8 @@
          & nsstpmpp       !: Global number of surface observations per time step
 
+      ! Arrays with size equal to the number of observation records in the window
+      INTEGER, POINTER, DIMENSION(:) :: &
+         & mrecstp   ! Time step of the records
+
       ! Arrays used to store source indices when 
       ! compressing obs_surf derived types
@@ -97,4 +103,8 @@
       INTEGER, POINTER, DIMENSION(:) :: &
          & nsind          !: Source indices of surface data in compressed data
+
+      ! Is this a gridded product?
+     
+      LOGICAL :: lgrid
 
    END TYPE obs_surf
@@ -146,4 +156,5 @@
          & surf%mi(ksurf),      &
          & surf%mj(ksurf),      &
+         & surf%mt(ksurf),      &
          & surf%nsidx(ksurf),   &
          & surf%nsfil(ksurf),   &
@@ -162,4 +173,6 @@
          & )
 
+      surf%mt(:) = -1
+
 
       ! Allocate arrays of number of surface data size * number of variables
@@ -176,4 +189,6 @@
          & )
 
+      surf%rext(:,:) = 0.0_wp 
+
       ! Allocate arrays of number of time step size
 
@@ -203,4 +218,8 @@
 
       surf%nsurfup     = 0
+      
+      ! Not gridded by default
+          
+      surf%lgrid       = .FALSE.
               
    END SUBROUTINE obs_surf_alloc
@@ -228,4 +247,5 @@
          & surf%mi,      &
          & surf%mj,      &
+         & surf%mt,      &
          & surf%nsidx,   &
          & surf%nsfil,   &
@@ -350,4 +370,5 @@
             newsurf%mi(insurf)    = surf%mi(ji)
             newsurf%mj(insurf)    = surf%mj(ji)
+            newsurf%mt(insurf)    = surf%mt(ji)
             newsurf%nsidx(insurf) = surf%nsidx(ji)
             newsurf%nsfil(insurf) = surf%nsfil(ji)
@@ -393,4 +414,8 @@
 
       newsurf%nstp  = surf%nstp
+      
+      ! Set gridded stuff
+      
+      newsurf%mt(insurf)    = surf%mt(ji)
  
       ! Deallocate temporary data
@@ -433,4 +458,5 @@
          oldsurf%mi(jj)    = surf%mi(ji)
          oldsurf%mj(jj)    = surf%mj(ji)
+         oldsurf%mt(jj)    = surf%mt(ji)
          oldsurf%nsidx(jj) = surf%nsidx(ji)
          oldsurf%nsfil(jj) = surf%nsfil(ji)
