Index: branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90
===================================================================
--- branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 7887)
+++ branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 7915)
@@ -52,5 +52,6 @@
 CONTAINS
 
-   SUBROUTINE obs_pre_surf( surfdata, surfdataqc, ld_nea, ld_bound_reject )
+   SUBROUTINE obs_pre_surf( surfdata, surfdataqc, ld_nea, ld_bound_reject, &
+                            kqc_cutoff )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE obs_pre_sla  ***
@@ -82,5 +83,7 @@
       LOGICAL, INTENT(IN) :: ld_nea                ! Switch for rejecting observation near land
       LOGICAL, INTENT(IN) :: ld_bound_reject       ! Switch for rejecting obs near the boundary
+      INTEGER, INTENT(IN), OPTIONAL :: kqc_cutoff   ! cut off for QC value
       !! * Local declarations
+      INTEGER :: iqc_cutoff = 255   ! cut off for QC value
       INTEGER :: iyea0        ! Initial date
       INTEGER :: imon0        !  - (year, month, day, hour, minute)
@@ -130,4 +133,7 @@
       ibdysobs = 0 
 
+      ! Set QC cutoff to optional value if provided
+      IF ( PRESENT(kqc_cutoff) ) iqc_cutoff=kqc_cutoff
+
       ! -----------------------------------------------------------------------
       ! Find time coordinate for surface data
@@ -138,5 +144,6 @@
          &              surfdata%nsurf,   surfdata%nyea, surfdata%nmon, &
          &              surfdata%nday,    surfdata%nhou, surfdata%nmin, &
-         &              surfdata%nqc,     surfdata%mstp, iotdobs        )
+         &              surfdata%nqc,     surfdata%mstp, iotdobs,       &
+         &              kqc_cutoff = iqc_cutoff  )
 
       CALL obs_mpp_sum_integer( iotdobs, iotdobsmpp )
@@ -179,7 +186,7 @@
       ALLOCATE( llvalid(surfdata%nsurf) )
       
-      ! We want all data which has qc flags <= 10
-
-      llvalid(:)  = ( surfdata%nqc(:)  <= 10 )
+      ! We want all data which has qc flags <= iqc_cutoff
+
+      llvalid(:)  = ( surfdata%nqc(:)  <= iqc_cutoff )
 
       ! The actual copying
@@ -251,5 +258,5 @@
       &                     kpi, kpj, kpk, &
       &                     zmask1, pglam1, pgphi1, zmask2, pglam2, pgphi2,  &
-      &                     ld_nea, ld_bound_reject, kdailyavtypes )
+      &                     ld_nea, ld_bound_reject, kdailyavtypes,  kqc_cutoff )
 
 !!----------------------------------------------------------------------
@@ -292,6 +299,8 @@
          & pgphi1, &
          & pgphi2
+      INTEGER, INTENT(IN), OPTIONAL :: kqc_cutoff   ! cut off for QC value
 
       !! * Local declarations
+      INTEGER :: iqc_cutoff = 255   ! cut off for QC value
       INTEGER :: iyea0        ! Initial date
       INTEGER :: imon0        !  - (year, month, day, hour, minute)
@@ -361,4 +370,8 @@
       iuvchkv   = 0
 
+
+      ! Set QC cutoff to optional value if provided
+      IF ( PRESENT(kqc_cutoff) ) iqc_cutoff=kqc_cutoff
+
       ! -----------------------------------------------------------------------
       ! Find time coordinate for profiles
@@ -371,5 +384,6 @@
             &              profdata%nday,    profdata%nhou, profdata%nmin, &
             &              profdata%ntyp,    profdata%nqc,  profdata%mstp, &
-            &              iotdobs, kdailyavtypes = kdailyavtypes )
+            &              iotdobs, kdailyavtypes = kdailyavtypes,         &
+            &              kqc_cutoff = iqc_cutoff )
       ELSE
          CALL obs_coo_tim_prof( icycle, &
@@ -378,5 +392,5 @@
             &              profdata%nday,    profdata%nhou, profdata%nmin, &
             &              profdata%ntyp,    profdata%nqc,  profdata%mstp, &
-            &              iotdobs )
+            &              iotdobs,          kqc_cutoff = iqc_cutoff )
       ENDIF
 
@@ -395,8 +409,8 @@
 
       ! -----------------------------------------------------------------------
-      ! Reject all observations for profiles with nqc > 10
-      ! -----------------------------------------------------------------------
-
-      CALL obs_pro_rej( profdata )
+      ! Reject all observations for profiles with nqc > iqc_cutoff
+      ! -----------------------------------------------------------------------
+
+      CALL obs_pro_rej( profdata, kqc_cutoff = iqc_cutoff )
 
       ! -----------------------------------------------------------------------
@@ -419,5 +433,6 @@
          &                 iosdv1obs,             ilanv1obs,            &
          &                 inlav1obs,             ld_nea,               &
-         &                 ibdyv1obs,             ld_bound_reject       )
+         &                 ibdyv1obs,             ld_bound_reject,      &
+         &                 iqc_cutoff       )
 
       CALL obs_mpp_sum_integer( iosdv1obs, iosdv1obsmpp )
@@ -440,5 +455,6 @@
          &                 iosdv2obs,             ilanv2obs,            &
          &                 inlav2obs,             ld_nea,               &
-         &                 ibdyv2obs,             ld_bound_reject       )
+         &                 ibdyv2obs,             ld_bound_reject,      &
+         &                 iqc_cutoff       )
 
       CALL obs_mpp_sum_integer( iosdv2obs, iosdv2obsmpp )
@@ -452,5 +468,5 @@
 
       IF ( TRIM(profdata%cvars(1)) == 'UVEL' ) THEN
-         CALL obs_uv_rej( profdata, iuvchku, iuvchkv )
+         CALL obs_uv_rej( profdata, iuvchku, iuvchkv, iqc_cutoff )
          CALL obs_mpp_sum_integer( iuvchku, iuvchkumpp )
          CALL obs_mpp_sum_integer( iuvchkv, iuvchkvmpp )
@@ -469,9 +485,9 @@
       END DO
 
-      ! We want all data which has qc flags = 0
-
-      llvalid%luse(:) = ( profdata%nqc(:)  <= 10 )
+      ! We want all data which has qc flags <= iqc_cutoff
+
+      llvalid%luse(:) = ( profdata%nqc(:)  <= iqc_cutoff )
       DO jvar = 1,profdata%nvar
-         llvvalid(jvar)%luse(:) = ( profdata%var(jvar)%nvqc(:) <= 10 )
+         llvvalid(jvar)%luse(:) = ( profdata%var(jvar)%nvqc(:) <= iqc_cutoff )
       END DO
 
@@ -783,5 +799,6 @@
       &                    kobsno,                                        &
       &                    kobsyea, kobsmon, kobsday, kobshou, kobsmin,   &
-      &                    ktyp,    kobsqc,  kobsstp, kotdobs, kdailyavtypes )
+      &                    ktyp,    kobsqc,  kobsstp, kotdobs, kdailyavtypes, &
+      &                    kqc_cutoff )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE obs_coo_tim ***
@@ -827,6 +844,9 @@
       INTEGER, DIMENSION(imaxavtypes), OPTIONAL :: &
          & kdailyavtypes    ! Types for daily averages
+      INTEGER, OPTIONAL, INTENT(IN) :: kqc_cutoff           ! QC cutoff value
+
       !! * Local declarations
       INTEGER :: jobs
+      INTEGER :: iqc_cutoff=255
 
       !-----------------------------------------------------------------------
@@ -847,9 +867,9 @@
          DO jobs = 1, kobsno
             
-            IF ( kobsqc(jobs) <= 10 ) THEN
+            IF ( kobsqc(jobs) <= iqc_cutoff ) THEN
                
                IF ( ( kobsstp(jobs) == (nit000 - 1) ).AND.&
                   & ( ANY (kdailyavtypes(:) == ktyp(jobs)) ) ) THEN
-                  kobsqc(jobs) = kobsqc(jobs) + 14
+                  kobsqc(jobs) = IBSET(kobsqc(jobs),13)
                   kotdobs      = kotdobs + 1
                   CYCLE
@@ -894,5 +914,5 @@
       DO jobs = 1, kobsno
          IF ( ( kobsi(jobs) <= 0 ) .AND. ( kobsj(jobs) <= 0 ) ) THEN
-            kobsqc(jobs) = kobsqc(jobs) + 18
+            kobsqc(jobs) = IBSET(kobsqc(jobs),12)
             kgrdobs = kgrdobs + 1
          ENDIF
@@ -906,5 +926,6 @@
       &                       kobsqc, kosdobs, klanobs,          &
       &                       knlaobs,ld_nea,                    &
-      &                       kbdyobs,ld_bound_reject            )
+      &                       kbdyobs,ld_bound_reject,           &
+      &                       kqc_cutoff                         )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE obs_coo_spc_2d  ***
@@ -945,4 +966,6 @@
       LOGICAL, INTENT(IN)    :: ld_nea           ! Flag observations near land
       LOGICAL, INTENT(IN)    :: ld_bound_reject  ! Flag observations near open boundary 
+      INTEGER, INTENT(IN)    :: kqc_cutoff       ! Cutoff QC value
+
       !! * Local declarations
       REAL(KIND=wp), DIMENSION(2,2,kobsno) :: &
@@ -969,5 +992,5 @@
          ! For invalid points use 2,2
 
-         IF ( kobsqc(jobs) >= 10 ) THEN
+         IF ( kobsqc(jobs) >= kqc_cutoff ) THEN
 
             igrdi(1,1,jobs) = 1
@@ -1016,5 +1039,5 @@
 
          ! Skip bad observations
-         IF ( kobsqc(jobs) >= 10 ) CYCLE
+         IF ( kobsqc(jobs) >= kqc_cutoff ) CYCLE
 
          ! Flag if the observation falls outside the model spatial domain
@@ -1023,5 +1046,5 @@
             &  .OR. ( pobsphi(jobs) <  -90. ) &
             &  .OR. ( pobsphi(jobs) >   90. ) ) THEN
-            kobsqc(jobs) = kobsqc(jobs) + 11
+            kobsqc(jobs) = IBSET(kobsqc(jobs),11)
             kosdobs = kosdobs + 1
             CYCLE
@@ -1030,5 +1053,5 @@
          ! Flag if the observation falls with a model land cell
          IF ( SUM( zgmsk(1:2,1:2,jobs) ) == 0.0_wp ) THEN
-            kobsqc(jobs) = kobsqc(jobs)  + 12
+            kobsqc(jobs) = IBSET(kobsqc(jobs),10)
             klanobs = klanobs + 1
             CYCLE
@@ -1055,5 +1078,5 @@
          IF (lgridobs) THEN
             IF (zgmsk(iig,ijg,jobs) == 0.0_wp ) THEN
-               kobsqc(jobs) = kobsqc(jobs) + 12
+               kobsqc(jobs) = IBSET(kobsqc(jobs),10)
                klanobs = klanobs + 1
                CYCLE
@@ -1066,5 +1089,5 @@
             knlaobs = knlaobs + 1
             IF (ld_nea) THEN
-               kobsqc(jobs) = kobsqc(jobs) + 14
+               kobsqc(jobs) = IBSET(kobsqc(jobs),9)
                CYCLE
             ENDIF
@@ -1101,5 +1124,6 @@
       &                       kpobsqc, kobsqc,  kosdobs,        &
       &                       klanobs, knlaobs, ld_nea,         &
-      &                       kbdyobs, ld_bound_reject          )
+      &                       kbdyobs, ld_bound_reject,         &
+      &                       kqc_cutoff                        )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE obs_coo_spc_3d  ***
@@ -1169,4 +1193,6 @@
       LOGICAL, INTENT(IN) :: ld_nea         ! Flag observations near land
       LOGICAL, INTENT(IN) :: ld_bound_reject  ! Flag observations near open boundary
+      INTEGER, INTENT(IN) :: kqc_cutoff     ! Cutoff QC value
+
       !! * Local declarations
       REAL(KIND=wp), DIMENSION(2,2,kpk,kprofno) :: &
@@ -1196,5 +1222,5 @@
          ! For invalid points use 2,2
 
-         IF ( kpobsqc(jobs) >= 10 ) THEN
+         IF ( kpobsqc(jobs) >= kqc_cutoff ) THEN
             
             igrdi(1,1,jobs) = 1
@@ -1246,5 +1272,5 @@
 
          ! Skip bad profiles
-         IF ( kpobsqc(jobs) >= 10 ) CYCLE
+         IF ( kpobsqc(jobs) >= kqc_cutoff ) CYCLE
 
          ! Check if this observation is on a grid point
@@ -1284,5 +1310,5 @@
                &  .OR. ( pobsdep(jobsp) < 0.0          )       &
                &  .OR. ( pobsdep(jobsp) > gdepw_1d(kpk)) ) THEN
-               kobsqc(jobsp) = kobsqc(jobsp) + 11
+               kobsqc(jobsp) = IBSET(kobsqc(jobsp),11)
                kosdobs = kosdobs + 1
                CYCLE
@@ -1299,5 +1325,5 @@
                IF ( SUM( zgmsk(1:2,1:2,kobsk(jobsp)-1:kobsk(jobsp),jobs) ) & 
                   &  == 0.0_wp ) THEN 
-                  kobsqc(jobsp) = kobsqc(jobsp) + 12 
+                  kobsqc(jobsp) = IBSET(kobsqc(jobsp),10)
                   klanobs = klanobs + 1 
                   CYCLE 
@@ -1309,5 +1335,5 @@
                   knlaobs = knlaobs + 1 
                   IF (ld_nea) THEN   
-                     kobsqc(jobsp) = kobsqc(jobsp) + 14  
+                     kobsqc(jobsp) = IBSET(kobsqc(jobsp),10)
                   ENDIF  
                ENDIF 
@@ -1320,5 +1346,5 @@
                   &  ( SUM( zgmsk(1:2,1:2,kobsk(jobsp)-1:kobsk(jobsp),jobs) ) &
                   &  == 0.0_wp) ) THEN
-                  kobsqc(jobsp) = kobsqc(jobsp) + 12 
+                  kobsqc(jobsp) = IBSET(kobsqc(jobsp),10)
                   klanobs = klanobs + 1 
                   CYCLE 
@@ -1329,5 +1355,5 @@
                   knlaobs = knlaobs + 1 
                   IF (ld_nea) THEN   
-                     kobsqc(jobsp) = kobsqc(jobsp) + 14  
+                     kobsqc(jobsp) = IBSET(kobsqc(jobsp),10)
                   ENDIF  
                ENDIF 
@@ -1375,5 +1401,5 @@
    END SUBROUTINE obs_coo_spc_3d
 
-   SUBROUTINE obs_pro_rej( profdata )
+   SUBROUTINE obs_pro_rej( profdata, kqc_cutoff )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE obs_pro_rej ***
@@ -1393,4 +1419,6 @@
       !! * Arguments
       TYPE(obs_prof), INTENT(INOUT) :: profdata     ! Profile data
+      INTEGER, INTENT(IN) :: kqc_cutoff             ! QC cutoff value
+
       !! * Local declarations
       INTEGER :: jprof
@@ -1402,5 +1430,5 @@
       DO jprof = 1, profdata%nprof
 
-         IF ( profdata%nqc(jprof) > 10 ) THEN
+         IF ( profdata%nqc(jprof) > kqc_cutoff ) THEN
             
             DO jvar = 1, profdata%nvar
@@ -1410,5 +1438,5 @@
                   
                   profdata%var(jvar)%nvqc(jobs) = &
-                     & profdata%var(jvar)%nvqc(jobs) + 26
+                     & IBSET(profdata%var(jvar)%nvqc(jobs),14)
 
                END DO
@@ -1422,5 +1450,5 @@
    END SUBROUTINE obs_pro_rej
 
-   SUBROUTINE obs_uv_rej( profdata, knumu, knumv )
+   SUBROUTINE obs_uv_rej( profdata, knumu, knumv, kqc_cutof )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE obs_uv_rej ***
@@ -1442,4 +1470,6 @@
       INTEGER, INTENT(INOUT) :: knumu             ! Number of u rejected
       INTEGER, INTENT(INOUT) :: knumv             ! Number of v rejected
+      INTEGER, INTENT(IN) :: kqc_cutoff           ! QC cutoff value
+
       !! * Local declarations
       INTEGER :: jprof
@@ -1461,12 +1491,12 @@
          DO jobs = profdata%npvsta(jprof,1), profdata%npvend(jprof,1)
             
-            IF ( ( profdata%var(1)%nvqc(jobs) > 10 ) .AND. &
-               & ( profdata%var(2)%nvqc(jobs) <= 10) ) THEN
-               profdata%var(2)%nvqc(jobs) = profdata%var(2)%nvqc(jobs) + 42
+            IF ( ( profdata%var(1)%nvqc(jobs) >  kqc_cutoff ) .AND. &
+               & ( profdata%var(2)%nvqc(jobs) <=  kqc_cutoff) ) THEN
+               profdata%var(2)%nvqc(jobs) = IBSET(profdata%var(1)%nvqc(jobs),15)
                knumv = knumv + 1
             ENDIF
-            IF ( ( profdata%var(2)%nvqc(jobs) > 10 ) .AND. &
-               & ( profdata%var(1)%nvqc(jobs) <= 10) ) THEN
-               profdata%var(1)%nvqc(jobs) = profdata%var(1)%nvqc(jobs) + 42
+            IF ( ( profdata%var(2)%nvqc(jobs) >  kqc_cutoff ) .AND. &
+               & ( profdata%var(1)%nvqc(jobs) <=  kqc_cutoff) ) THEN
+               profdata%var(1)%nvqc(jobs) = IBSET(profdata%var(1)%nvqc(jobs),15)
                knumu = knumu + 1
             ENDIF
Index: branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90
===================================================================
--- branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90	(revision 7887)
+++ branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90	(revision 7915)
@@ -307,7 +307,7 @@
             inowin = 0
             DO ji = 1, inpfiles(jj)%nobs
-               IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-               IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
-                  & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
+               IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
+               IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
+                  & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
                IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
                   & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
@@ -325,7 +325,7 @@
             inowin = 0
             DO ji = 1, inpfiles(jj)%nobs
-               IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-               IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
-                  & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
+               IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
+               IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
+                  & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
                IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
                   & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
@@ -351,7 +351,7 @@
             inowin = 0
             DO ji = 1, inpfiles(jj)%nobs
-               IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-               IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
-                  & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
+               IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
+               IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
+                  & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
                IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
                   & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
@@ -373,7 +373,7 @@
 
             DO ji = 1, inpfiles(jj)%nobs
-               IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-               IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
-                  & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
+               IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
+               IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
+                  & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
                IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
                   & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
@@ -388,6 +388,6 @@
                         IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
                            & CYCLE
-                        IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
-                           & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
+                        IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,1),2) .AND. &
+                           & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
                            ivar1t0 = ivar1t0 + 1
                         ENDIF
@@ -398,6 +398,6 @@
                         IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
                            & CYCLE
-                        IF ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
-                           & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
+                        IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,2),2) .AND. &
+                           & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
                            ivar2t0 = ivar2t0 + 1
                         ENDIF
@@ -407,9 +407,9 @@
                      IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
                         & CYCLE
-                     IF ( ( ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
-                        &     ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
-                        &     ldvar1 ) .OR. &
-                        & ( ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
-                        &     ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
+                     IF ( ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,1),2) .AND. &
+                        &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
+                        &    ldt3d ) .OR. &
+                        & ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,2),2) .AND. &
+                        &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
                         &     ldvar2 ) ) THEN
                         ip3dt = ip3dt + 1
@@ -437,7 +437,7 @@
       DO jj = 1, inobf
          DO ji = 1, inpfiles(jj)%nobs
-            IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-            IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
-               & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
+            IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
+            IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
+               & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
             IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
                & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
@@ -452,7 +452,7 @@
       DO jj = 1, inobf
          DO ji = 1, inpfiles(jj)%nobs
-            IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-            IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
-               & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
+            IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
+            IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
+               & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
             IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
                & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
@@ -501,7 +501,7 @@
          ji = iprofidx(iindx(jk))
 
-         IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-         IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
-            & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
+            IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
+            IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
+               & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
 
          IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
@@ -518,6 +518,7 @@
             IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
 
-            IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
-               & ( inpfiles(jj)%ivqc(ji,2) > 2 ) ) CYCLE
+            IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
+            IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
+               & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
 
             loop_prof : DO ij = 1, inpfiles(jj)%nlev
@@ -526,6 +527,6 @@
                   & CYCLE
 
-               IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
-                  & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
+               IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,1),2) .AND. &
+                  & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
 
                   llvalprof = .TRUE. 
@@ -534,6 +535,6 @@
                ENDIF
 
-               IF ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
-                  & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
+               IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,2),2) .AND. &
+                  & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
 
                   llvalprof = .TRUE. 
@@ -615,10 +616,10 @@
                   IF (ldsatt) THEN
 
-                     IF ( ( ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
-                        &     ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
-                        &     ldvar1 ) .OR. &
-                        & ( ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
-                        &     ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
-                        &     ldvar2 ) ) THEN
+                     IF ( ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,1),2) .AND. &
+                        &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
+                        &    ldt3d ) .OR. &
+                        & ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,2),2) .AND. &
+                        &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
+                        &   lds3d ) ) THEN
                         ip3dt = ip3dt + 1
                      ELSE
@@ -628,7 +629,7 @@
                   ENDIF
 
-                  IF ( ( ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
-                     &     ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
-                     &       ldvar1 ) .OR. ldsatt ) THEN
+                  IF ( ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,1),2) .AND. &
+                    &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
+                    &    ldt3d ) .OR. ldsatt ) THEN
 
                      IF (ldsatt) THEN
@@ -661,6 +662,6 @@
 
                      ! Profile var1 value
-                     IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
-                        & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
+                     IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,1),2) .AND. &
+                        & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
                         profdata%var(1)%vobs(ivar1t) = &
                            &                inpfiles(jj)%pob(ij,ji,1)
@@ -692,6 +693,6 @@
                   ENDIF
 
-                  IF ( ( ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
-                     &   ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
+                  IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,2),2) .AND. &
+                     & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
                      &   ldvar2 ) .OR. ldsatt ) THEN
 
@@ -725,6 +726,6 @@
 
                      ! Profile var2 value
-                     IF ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
-                        & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
+                  IF ( ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,2),2) .AND. &
+                    &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
                         profdata%var(2)%vobs(ivar2t) = &
                            &                inpfiles(jj)%pob(ij,ji,2)
Index: branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_surf.F90
===================================================================
--- branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_surf.F90	(revision 7887)
+++ branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_surf.F90	(revision 7915)
@@ -294,6 +294,5 @@
                   ENDIF
                   llvalprof = .FALSE.
-                  IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-                     & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
+                  IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(1,ji,1),2) ) THEN
                      iobs = iobs + 1
                   ENDIF
@@ -367,6 +366,5 @@
             ! Set observation information
 
-            IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-               & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
+            IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(1,ji,1),2) ) THEN
 
                iobs = iobs + 1
Index: branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_readmdt.F90
===================================================================
--- branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_readmdt.F90	(revision 7887)
+++ branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_readmdt.F90	(revision 7915)
@@ -154,5 +154,5 @@
 
 ! mark any masked data with a QC flag
-         IF( zobsmask(1) == 0 )   sladata%nqc(jobs) = 11
+         IF( zobsmask(1) == 0 )   sladata%nqc(jobs) = IBSET(sladata(jslano)%nqc(jobs),15)
 
          END DO
Index: branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90
===================================================================
--- branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90	(revision 7887)
+++ branches/UKMO/obs_oper_do_not_assim_update/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90	(revision 7915)
@@ -196,8 +196,8 @@
          fbdata%ivqc(jo,:)    = profdata%ivqc(jo,:)
          fbdata%ivqcf(:,jo,:) = profdata%ivqcf(:,jo,:)
-         IF ( profdata%nqc(jo) > 10 ) THEN
-            fbdata%ioqc(jo)    = 4
+         IF ( profdata%nqc(jo) > 255 ) THEN
+            fbdata%ioqc(jo)    = IBSET(profdata%nqc(jo),2)
             fbdata%ioqcf(1,jo) = profdata%nqcf(1,jo)
-            fbdata%ioqcf(2,jo) = profdata%nqc(jo) - 10
+            fbdata%ioqcf(2,jo) = profdata%nqc(jo)
          ELSE
             fbdata%ioqc(jo)    = profdata%nqc(jo)
@@ -236,8 +236,8 @@
                fbdata%idqc(ik,jo)        = profdata%var(jvar)%idqc(jk)
                fbdata%idqcf(:,ik,jo)     = profdata%var(jvar)%idqcf(:,jk)
-               IF ( profdata%var(jvar)%nvqc(jk) > 10 ) THEN
-                  fbdata%ivlqc(ik,jo,jvar) = 4
+               IF ( profdata%var(jvar)%nvqc(jk) > 255 ) THEN
+                  fbdata%ivlqc(ik,jo,jvar) = IBSET(profdata%var(jvar)%nvqc(jk),2)
                   fbdata%ivlqcf(1,ik,jo,jvar) = profdata%var(jvar)%nvqcf(1,jk)
-                  fbdata%ivlqcf(2,ik,jo,jvar) = profdata%var(jvar)%nvqc(jk) - 10
+                  fbdata%ivlqcf(2,ik,jo,jvar) = IAND(profdata%var(jvar)%nvqc(jk),b'0000 0000 1111 1111')
                ELSE
                   fbdata%ivlqc(ik,jo,jvar) = profdata%var(jvar)%nvqc(jk)
@@ -558,8 +558,8 @@
          fbdata%ivqc(jo,:)    = 0
          fbdata%ivqcf(:,jo,:) = 0
-         IF ( surfdata%nqc(jo) > 10 ) THEN
+         IF ( surfdata%nqc(jo) > 255 ) THEN
             fbdata%ioqc(jo)    = 4
             fbdata%ioqcf(1,jo) = 0
-            fbdata%ioqcf(2,jo) = surfdata%nqc(jo) - 10
+            fbdata%ioqcf(2,jo) = IAND(surfdata%nqc(jo),b'0000 0000 1111 1111')
          ELSE
             fbdata%ioqc(jo)    = surfdata%nqc(jo)
@@ -593,9 +593,9 @@
          fbdata%idqc(1,jo)     = 0
          fbdata%idqcf(:,1,jo)  = 0
-         IF ( surfdata%nqc(jo) > 10 ) THEN
+         IF ( surfdata%nqc(jo) > 255 ) THEN
             fbdata%ivqc(jo,1)       = 4
             fbdata%ivlqc(1,jo,1)    = 4
             fbdata%ivlqcf(1,1,jo,1) = 0
-            fbdata%ivlqcf(2,1,jo,1) = surfdata%nqc(jo) - 10
+            fbdata%ivlqcf(2,1,jo,1) = IAND(surfdata%nqc(jo),b'0000 0000 1111 1111')
          ELSE
             fbdata%ivqc(jo,1)       = surfdata%nqc(jo)
