Index: branches/2014/dev_r4704_NOC5_MPP_BDY_UPDATE/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90
===================================================================
--- branches/2014/dev_r4704_NOC5_MPP_BDY_UPDATE/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 4705)
+++ branches/2014/dev_r4704_NOC5_MPP_BDY_UPDATE/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 6225)
@@ -7,12 +7,9 @@
 
    !!---------------------------------------------------------------------
-   !!   obs_pre_pro  : First level check and screening of T/S profiles
-   !!   obs_pre_sla  : First level check and screening of SLA observations
-   !!   obs_pre_sst  : First level check and screening of SLA observations
-   !!   obs_pre_seaice : First level check and screening of sea ice observations
-   !!   obs_pre_vel  : First level check and screening of velocity obs.
-   !!   obs_scr      : Basic screening of the observations
-   !!   obs_coo_tim  : Compute number of time steps to the observation time
-   !!   obs_sor      : Sort the observation arrays
+   !!   obs_pre_prof  : First level check and screening of profile observations
+   !!   obs_pre_surf  : First level check and screening of surface observations
+   !!   obs_scr       : Basic screening of the observations
+   !!   obs_coo_tim   : Compute number of time steps to the observation time
+   !!   obs_sor       : Sort the observation arrays
    !!---------------------------------------------------------------------
    !! * Modules used
@@ -36,10 +33,7 @@
 
    PUBLIC &
-      & obs_pre_pro, &    ! First level check and screening of profiles
-      & obs_pre_sla, &    ! First level check and screening of SLA data
-      & obs_pre_sst, &    ! First level check and screening of SLA data
-      & obs_pre_seaice, & ! First level check and screening of sea ice data
-      & obs_pre_vel, &     ! First level check and screening of velocity profiles
-      & calc_month_len     ! Calculate the number of days in the months of a year  
+      & obs_pre_prof, &    ! First level check and screening of profile obs
+      & obs_pre_surf, &    ! First level check and screening of surface obs
+      & calc_month_len     ! Calculate the number of days in the months of a year
 
    !!----------------------------------------------------------------------
@@ -49,299 +43,14 @@
    !!----------------------------------------------------------------------
 
+
 CONTAINS
 
-   SUBROUTINE obs_pre_pro( profdata, prodatqc, ld_t3d, ld_s3d, ld_nea, &
-      &                    kdailyavtypes )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE obs_pre_pro  ***
-      !!
-      !! ** Purpose : First level check and screening of T and S profiles
-      !!
-      !! ** Method  : First level check and screening of T and S profiles
-      !!
-      !! ** Action  : 
-      !!
-      !! References :
-      !!   
-      !! History :
-      !!        !  2007-01  (K. Mogensen) Merge of obs_pre_t3d and obs_pre_s3d 
-      !!        !  2007-03  (K. Mogensen) General handling of profiles
-      !!        !  2007-06  (K. Mogensen et al) Reject obs. near land.
-      !!----------------------------------------------------------------------
-      !! * Modules used
-      USE domstp              ! Domain: set the time-step
-      USE par_oce             ! Ocean parameters
-      USE dom_oce, ONLY : &   ! Geographical information
-         & glamt,   &
-         & gphit,   &
-         & gdept_1d,&
-         & tmask,   &
-         & nproc
-      !! * Arguments
-      TYPE(obs_prof), INTENT(INOUT) :: profdata     ! Full set of profile data
-      TYPE(obs_prof), INTENT(INOUT) :: prodatqc     ! Subset of profile data not failing screening
-      LOGICAL, INTENT(IN) :: ld_t3d         ! Switch for temperature
-      LOGICAL, INTENT(IN) :: ld_s3d         ! Switch for salinity
-      LOGICAL, INTENT(IN) :: ld_nea         ! Switch for rejecting observation near land
-      INTEGER, DIMENSION(imaxavtypes), OPTIONAL :: &
-         & kdailyavtypes! Types for daily averages
-      !! * Local declarations   
-      INTEGER :: iyea0         ! Initial date
-      INTEGER :: imon0         !  - (year, month, day, hour, minute)
-      INTEGER :: iday0   
-      INTEGER :: ihou0
-      INTEGER :: imin0
-      INTEGER :: icycle        ! Current assimilation cycle
-                               ! Counters for observations that
-      INTEGER :: iotdobs       !  - outside time domain
-      INTEGER :: iosdtobs      !  - outside space domain (temperature)
-      INTEGER :: iosdsobs      !  - outside space domain (salinity)
-      INTEGER :: ilantobs      !  - within a model land cell (temperature)
-      INTEGER :: ilansobs      !  - within a model land cell (salinity)
-      INTEGER :: inlatobs      !  - close to land (temperature)
-      INTEGER :: inlasobs      !  - close to land (salinity)
-      INTEGER :: igrdobs       !  - fail the grid search
-                               ! Global counters for observations that
-      INTEGER :: iotdobsmpp    !  - outside time domain
-      INTEGER :: iosdtobsmpp   !  - outside space domain (temperature)
-      INTEGER :: iosdsobsmpp   !  - outside space domain (salinity)
-      INTEGER :: ilantobsmpp   !  - within a model land cell (temperature)
-      INTEGER :: ilansobsmpp   !  - within a model land cell (salinity)
-      INTEGER :: inlatobsmpp   !  - close to land (temperature)
-      INTEGER :: inlasobsmpp   !  - close to land (salinity)
-      INTEGER :: igrdobsmpp    !  - fail the grid search
-      TYPE(obs_prof_valid) ::  llvalid     ! Profile selection 
-      TYPE(obs_prof_valid), DIMENSION(profdata%nvar) :: &
-         & llvvalid            ! T,S selection 
-      INTEGER :: jvar          ! Variable loop variable
-      INTEGER :: jobs          ! Obs. loop variable
-      INTEGER :: jstp          ! Time loop variable
-      INTEGER :: inrc          ! Time index variable
-      
-      IF(lwp) WRITE(numout,*)'obs_pre_pro : Preparing the profile observations...'
-
-      ! Initial date initialization (year, month, day, hour, minute)
-      iyea0 =   ndate0 / 10000
-      imon0 = ( ndate0 - iyea0 * 10000 ) / 100
-      iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
-
-      icycle = no     ! Assimilation cycle
-
-      ! Diagnotics counters for various failures.
-
-      iotdobs  = 0
-      igrdobs  = 0
-      iosdtobs = 0
-      iosdsobs = 0
-      ilantobs = 0
-      ilansobs = 0
-      inlatobs = 0
-      inlasobs = 0
-
-      ! -----------------------------------------------------------------------
-      ! Find time coordinate for profiles
-      ! -----------------------------------------------------------------------
-
-      IF ( PRESENT(kdailyavtypes) ) THEN
-         CALL obs_coo_tim_prof( icycle, &
-            &                iyea0,   imon0,   iday0,   ihou0,   imin0,      &
-            &                profdata%nprof,   profdata%nyea, profdata%nmon, &
-            &                profdata%nday,    profdata%nhou, profdata%nmin, &
-            &                profdata%ntyp,    profdata%nqc,  profdata%mstp, &
-            &                iotdobs, kdailyavtypes = kdailyavtypes        )
-      ELSE
-         CALL obs_coo_tim_prof( icycle, &
-            &                iyea0,   imon0,   iday0,   ihou0,   imin0,      &
-            &                profdata%nprof,   profdata%nyea, profdata%nmon, &
-            &                profdata%nday,    profdata%nhou, profdata%nmin, &
-            &                profdata%ntyp,    profdata%nqc,  profdata%mstp, &
-            &                iotdobs )
-      ENDIF
-      CALL obs_mpp_sum_integer( iotdobs, iotdobsmpp )
-      
-      ! -----------------------------------------------------------------------
-      ! Check for profiles failing the grid search
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_grd( profdata%nprof,   profdata%mi, profdata%mj, &
-         &              profdata%nqc,     igrdobs                         )
-
-      CALL obs_mpp_sum_integer( igrdobs, igrdobsmpp )
-
-      ! -----------------------------------------------------------------------
-      ! Reject all observations for profiles with nqc > 10
-      ! -----------------------------------------------------------------------
-
-      CALL obs_pro_rej( profdata )
-
-      ! -----------------------------------------------------------------------
-      ! Check for land points. This includes points below the model
-      ! bathymetry so this is done for every point in the profile
-      ! -----------------------------------------------------------------------
-
-      ! Temperature
-
-      CALL obs_coo_spc_3d( profdata%nprof,        profdata%nvprot(1),   &
-         &                 profdata%npvsta(:,1),  profdata%npvend(:,1), &
-         &                 jpi,                   jpj,                  &
-         &                 jpk,                                         &
-         &                 profdata%mi,           profdata%mj,          & 
-         &                 profdata%var(1)%mvk,                         &
-         &                 profdata%rlam,         profdata%rphi,        &
-         &                 profdata%var(1)%vdep,                        &
-         &                 glamt,                 gphit,                &
-         &                 gdept_1d,              tmask,                &
-         &                 profdata%nqc,          profdata%var(1)%nvqc, &
-         &                 iosdtobs,              ilantobs,             &
-         &                 inlatobs,              ld_nea                )
-
-      CALL obs_mpp_sum_integer( iosdtobs, iosdtobsmpp )
-      CALL obs_mpp_sum_integer( ilantobs, ilantobsmpp )
-      CALL obs_mpp_sum_integer( inlatobs, inlatobsmpp )
-
-      ! Salinity
-
-      CALL obs_coo_spc_3d( profdata%nprof,        profdata%nvprot(2),   &
-         &                 profdata%npvsta(:,2),  profdata%npvend(:,2), &
-         &                 jpi,                   jpj,                  &
-         &                 jpk,                                         &
-         &                 profdata%mi,           profdata%mj,          & 
-         &                 profdata%var(2)%mvk,                         &
-         &                 profdata%rlam,         profdata%rphi,        &
-         &                 profdata%var(2)%vdep,                        &
-         &                 glamt,                 gphit,                &
-         &                 gdept_1d,              tmask,                &
-         &                 profdata%nqc,          profdata%var(2)%nvqc, &
-         &                 iosdsobs,              ilansobs,             &
-         &                 inlasobs,              ld_nea                )
-
-      CALL obs_mpp_sum_integer( iosdsobs, iosdsobsmpp )
-      CALL obs_mpp_sum_integer( ilansobs, ilansobsmpp )
-      CALL obs_mpp_sum_integer( inlasobs, inlasobsmpp )
-
-      ! -----------------------------------------------------------------------
-      ! Copy useful data from the profdata data structure to
-      ! the prodatqc data structure 
-      ! -----------------------------------------------------------------------
-
-      ! Allocate the selection arrays
-
-      ALLOCATE( llvalid%luse(profdata%nprof) )
-      DO jvar = 1,profdata%nvar
-         ALLOCATE( llvvalid(jvar)%luse(profdata%nvprot(jvar)) )
-      END DO
-
-      ! We want all data which has qc flags <= 10
-
-      llvalid%luse(:) = ( profdata%nqc(:)  <= 10 )
-      DO jvar = 1,profdata%nvar
-         llvvalid(jvar)%luse(:) = ( profdata%var(jvar)%nvqc(:) <= 10 )
-      END DO
-
-      ! The actual copying
-
-      CALL obs_prof_compress( profdata,     prodatqc,       .TRUE.,  numout, &
-         &                    lvalid=llvalid, lvvalid=llvvalid )
-
-      ! Dellocate the selection arrays
-      DEALLOCATE( llvalid%luse )
-      DO jvar = 1,profdata%nvar
-         DEALLOCATE( llvvalid(jvar)%luse )
-      END DO
-
-      ! -----------------------------------------------------------------------
-      ! Print information about what observations are left after qc
-      ! -----------------------------------------------------------------------
-
-      ! Update the total observation counter array
-      
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'obs_pre_pro :'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*)
-         WRITE(numout,*) ' Profiles outside time domain                = ', &
-            &            iotdobsmpp
-         WRITE(numout,*) ' Remaining profiles that failed grid search  = ', &
-            &            igrdobsmpp
-         WRITE(numout,*) ' Remaining T data outside space domain       = ', &
-            &            iosdtobsmpp
-         WRITE(numout,*) ' Remaining T data at land points             = ', &
-            &            ilantobsmpp
-         IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining T data near land points (removed) = ',&
-               &            inlatobsmpp
-         ELSE
-            WRITE(numout,*) ' Remaining T data near land points (kept)    = ',&
-               &            inlatobsmpp
-         ENDIF
-         WRITE(numout,*) ' T data accepted                             = ', &
-            &            prodatqc%nvprotmpp(1)
-         WRITE(numout,*) ' Remaining S data outside space domain       = ', &
-            &            iosdsobsmpp
-         WRITE(numout,*) ' Remaining S data at land points             = ', &
-            &            ilansobsmpp
-         IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining S data near land points (removed) = ',&
-               &            inlasobsmpp
-         ELSE
-            WRITE(numout,*) ' Remaining S data near land points (kept)    = ',&
-               &            inlasobsmpp
-         ENDIF
-         WRITE(numout,*) ' S data accepted                             = ', &
-            &            prodatqc%nvprotmpp(2)
-
-         WRITE(numout,*)
-         WRITE(numout,*) ' Number of observations per time step :'
-         WRITE(numout,*)
-         WRITE(numout,997)
-         WRITE(numout,998)
-      ENDIF
-      
-      DO jobs = 1, prodatqc%nprof
-         inrc = prodatqc%mstp(jobs) + 2 - nit000
-         prodatqc%npstp(inrc)  = prodatqc%npstp(inrc) + 1
-         DO jvar = 1, prodatqc%nvar
-            IF ( prodatqc%npvend(jobs,jvar) > 0 ) THEN
-               prodatqc%nvstp(inrc,jvar) = prodatqc%nvstp(inrc,jvar) + &
-                  &                      ( prodatqc%npvend(jobs,jvar) - &
-                  &                        prodatqc%npvsta(jobs,jvar) + 1 )
-            ENDIF
-         END DO
-      END DO
-      
-      
-      CALL obs_mpp_sum_integers( prodatqc%npstp, prodatqc%npstpmpp, &
-         &                       nitend - nit000 + 2 )
-      DO jvar = 1, prodatqc%nvar
-         CALL obs_mpp_sum_integers( prodatqc%nvstp(:,jvar), &
-            &                       prodatqc%nvstpmpp(:,jvar), &
-            &                       nitend - nit000 + 2 )
-      END DO
-
-      IF ( lwp ) THEN
-         DO jstp = nit000 - 1, nitend
-            inrc = jstp - nit000 + 2
-            WRITE(numout,999) jstp, prodatqc%npstpmpp(inrc), &
-               &                    prodatqc%nvstpmpp(inrc,1), &
-               &                    prodatqc%nvstpmpp(inrc,2)
-         END DO
-      ENDIF
-
-997   FORMAT(10X,'Time step',5X,'Profiles',5X,'Temperature',5X,'Salinity')
-998   FORMAT(10X,'---------',5X,'--------',5X,'-----------',5X,'--------')
-999   FORMAT(10X,I9,5X,I8,5X,I11,5X,I8)
-      
-   END SUBROUTINE obs_pre_pro
-
-   SUBROUTINE obs_pre_sla( sladata, sladatqc, ld_sla, ld_nea )
+   SUBROUTINE obs_pre_surf( surfdata, surfdataqc, ld_nea )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE obs_pre_sla  ***
       !!
-      !! ** Purpose : First level check and screening of SLA observations
-      !!
-      !! ** Method  : First level check and screening of SLA observations
+      !! ** Purpose : First level check and screening of surface observations
+      !!
+      !! ** Method  : First level check and screening of surface observations
       !!
       !! ** Action  : 
@@ -352,4 +61,5 @@
       !!        !  2007-03  (A. Weaver, K. Mogensen) Original
       !!        !  2007-06  (K. Mogensen et al) Reject obs. near land.
+      !!        !  2015-02  (M. Martin) Combined routine for surface types.
       !!----------------------------------------------------------------------
       !! * Modules used
@@ -362,7 +72,6 @@
          & nproc
       !! * Arguments
-      TYPE(obs_surf), INTENT(INOUT) :: sladata    ! Full set of SLA data
-      TYPE(obs_surf), INTENT(INOUT) :: sladatqc   ! Subset of SLA data not failing screening
-      LOGICAL, INTENT(IN) :: ld_sla         ! Switch for SLA data
+      TYPE(obs_surf), INTENT(INOUT) :: surfdata    ! Full set of surface data
+      TYPE(obs_surf), INTENT(INOUT) :: surfdataqc   ! Subset of surface data not failing screening
       LOGICAL, INTENT(IN) :: ld_nea         ! Switch for rejecting observation near land
       !! * Local declarations
@@ -391,12 +100,13 @@
       INTEGER :: inrc         ! Time index variable
 
-      IF(lwp) WRITE(numout,*)'obs_pre_sla : Preparing the SLA observations...'
-
+      IF(lwp) WRITE(numout,*)'obs_pre_surf : Preparing the surface observations...'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      
       ! Initial date initialization (year, month, day, hour, minute)
       iyea0 =   ndate0 / 10000
       imon0 = ( ndate0 - iyea0 * 10000 ) / 100
       iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
+      ihou0 = nn_time0 / 100
+      imin0 = ( nn_time0 - ihou0 * 100 )
 
       icycle = no     ! Assimilation cycle
@@ -411,21 +121,21 @@
 
       ! -----------------------------------------------------------------------
-      ! Find time coordinate for SLA data
+      ! Find time coordinate for surface data
       ! -----------------------------------------------------------------------
 
       CALL obs_coo_tim( icycle, &
          &              iyea0,   imon0,   iday0,   ihou0,   imin0,      &
-         &              sladata%nsurf,   sladata%nyea, sladata%nmon, &
-         &              sladata%nday,    sladata%nhou, sladata%nmin, &
-         &              sladata%nqc,     sladata%mstp, iotdobs        )
+         &              surfdata%nsurf,   surfdata%nyea, surfdata%nmon, &
+         &              surfdata%nday,    surfdata%nhou, surfdata%nmin, &
+         &              surfdata%nqc,     surfdata%mstp, iotdobs        )
 
       CALL obs_mpp_sum_integer( iotdobs, iotdobsmpp )
       
       ! -----------------------------------------------------------------------
-      ! Check for SLA data failing the grid search
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_grd( sladata%nsurf,   sladata%mi, sladata%mj, &
-         &              sladata%nqc,     igrdobs                         )
+      ! Check for surface data failing the grid search
+      ! -----------------------------------------------------------------------
+
+      CALL obs_coo_grd( surfdata%nsurf,   surfdata%mi, surfdata%mj, &
+         &              surfdata%nqc,     igrdobs                         )
 
       CALL obs_mpp_sum_integer( igrdobs, igrdobsmpp )
@@ -435,10 +145,10 @@
       ! -----------------------------------------------------------------------
 
-      CALL obs_coo_spc_2d( sladata%nsurf,              &
+      CALL obs_coo_spc_2d( surfdata%nsurf,              &
          &                 jpi,          jpj,          &
-         &                 sladata%mi,   sladata%mj,   & 
-         &                 sladata%rlam, sladata%rphi, &
+         &                 surfdata%mi,   surfdata%mj,   & 
+         &                 surfdata%rlam, surfdata%rphi, &
          &                 glamt,        gphit,        &
-         &                 tmask(:,:,1), sladata%nqc,  &
+         &                 tmask(:,:,1), surfdata%nqc,  &
          &                 iosdsobs,     ilansobs,     &
          &                 inlasobs,     ld_nea        )
@@ -449,19 +159,19 @@
 
       ! -----------------------------------------------------------------------
-      ! Copy useful data from the sladata data structure to
-      ! the sladatqc data structure 
+      ! Copy useful data from the surfdata data structure to
+      ! the surfdataqc data structure 
       ! -----------------------------------------------------------------------
 
       ! Allocate the selection arrays
 
-      ALLOCATE( llvalid(sladata%nsurf) )
+      ALLOCATE( llvalid(surfdata%nsurf) )
       
       ! We want all data which has qc flags <= 10
 
-      llvalid(:)  = ( sladata%nqc(:)  <= 10 )
+      llvalid(:)  = ( surfdata%nqc(:)  <= 10 )
 
       ! The actual copying
 
-      CALL obs_surf_compress( sladata,     sladatqc,       .TRUE.,  numout, &
+      CALL obs_surf_compress( surfdata,     surfdataqc,       .TRUE.,  numout, &
          &                    lvalid=llvalid )
 
@@ -477,38 +187,36 @@
       IF(lwp) THEN
          WRITE(numout,*)
-         WRITE(numout,*) 'obs_pre_sla :'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*)
-         WRITE(numout,*) ' SLA data outside time domain                  = ', &
+         WRITE(numout,*) ' '//surfdataqc%cvars(1)//' data outside time domain                  = ', &
             &            iotdobsmpp
-         WRITE(numout,*) ' Remaining SLA data that failed grid search    = ', &
+         WRITE(numout,*) ' Remaining '//surfdataqc%cvars(1)//' data that failed grid search    = ', &
             &            igrdobsmpp
-         WRITE(numout,*) ' Remaining SLA data outside space domain       = ', &
+         WRITE(numout,*) ' Remaining '//surfdataqc%cvars(1)//' data outside space domain       = ', &
             &            iosdsobsmpp
-         WRITE(numout,*) ' Remaining SLA data at land points             = ', &
+         WRITE(numout,*) ' Remaining '//surfdataqc%cvars(1)//' data at land points             = ', &
             &            ilansobsmpp
          IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining SLA data near land points (removed) = ', &
+            WRITE(numout,*) ' Remaining '//surfdataqc%cvars(1)//' data near land points (removed) = ', &
                &            inlasobsmpp
          ELSE
-            WRITE(numout,*) ' Remaining SLA data near land points (kept)    = ', &
+            WRITE(numout,*) ' Remaining '//surfdataqc%cvars(1)//' data near land points (kept)    = ', &
                &            inlasobsmpp
          ENDIF
-         WRITE(numout,*) ' SLA data accepted                             = ', &
-            &            sladatqc%nsurfmpp
+         WRITE(numout,*) ' '//surfdataqc%cvars(1)//' data accepted                             = ', &
+            &            surfdataqc%nsurfmpp
 
          WRITE(numout,*)
          WRITE(numout,*) ' Number of observations per time step :'
          WRITE(numout,*)
-         WRITE(numout,1997)
-         WRITE(numout,1998)
+         WRITE(numout,'(10X,A,10X,A)')'Time step',surfdataqc%cvars(1)
+         WRITE(numout,'(10X,A,5X,A)')'---------','-----------------'
+         CALL FLUSH(numout)
       ENDIF
       
-      DO jobs = 1, sladatqc%nsurf
-         inrc = sladatqc%mstp(jobs) + 2 - nit000
-         sladatqc%nsstp(inrc)  = sladatqc%nsstp(inrc) + 1
+      DO jobs = 1, surfdataqc%nsurf
+         inrc = surfdataqc%mstp(jobs) + 2 - nit000
+         surfdataqc%nsstp(inrc)  = surfdataqc%nsstp(inrc) + 1
       END DO
       
-      CALL obs_mpp_sum_integers( sladatqc%nsstp, sladatqc%nsstpmpp, &
+      CALL obs_mpp_sum_integers( surfdataqc%nsstp, surfdataqc%nsstpmpp, &
          &                       nitend - nit000 + 2 )
 
@@ -516,28 +224,32 @@
          DO jstp = nit000 - 1, nitend
             inrc = jstp - nit000 + 2
-            WRITE(numout,1999) jstp, sladatqc%nsstpmpp(inrc)
+            WRITE(numout,1999) jstp, surfdataqc%nsstpmpp(inrc)
+            CALL FLUSH(numout)
          END DO
       ENDIF
 
-1997  FORMAT(10X,'Time step',5X,'Sea level anomaly')
-1998  FORMAT(10X,'---------',5X,'-----------------')
 1999  FORMAT(10X,I9,5X,I17)
 
-   END SUBROUTINE obs_pre_sla
-
-   SUBROUTINE obs_pre_sst( sstdata, sstdatqc, ld_sst, ld_nea )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE obs_pre_sst  ***
-      !!
-      !! ** Purpose : First level check and screening of SST observations
-      !!
-      !! ** Method  : First level check and screening of SST observations
-      !!
-      !! ** Action  : 
-      !!
-      !! References :
-      !!   
+   END SUBROUTINE obs_pre_surf
+
+
+   SUBROUTINE obs_pre_prof( profdata, prodatqc, ld_var1, ld_var2, &
+      &                     kpi, kpj, kpk, &
+      &                     zmask1, pglam1, pgphi1, zmask2, pglam2, pgphi2,  &
+      &                     ld_nea, kdailyavtypes )
+
+!!----------------------------------------------------------------------
+      !!                    ***  ROUTINE obs_pre_prof  ***
+      !!
+      !! ** Purpose : First level check and screening of profiles
+      !!
+      !! ** Method  : First level check and screening of profiles
+      !!
       !! History :
-      !!        !  2007-03  (S. Ricci) SST data preparation 
+      !!        !  2007-06  (K. Mogensen) original : T and S profile data
+      !!        !  2008-09  (M. Valdivieso) : TAO velocity data
+      !!        !  2009-01  (K. Mogensen) : New feedback stricture
+      !!        !  2015-02  (M. Martin) : Combined profile routine.
+      !!
       !!----------------------------------------------------------------------
       !! * Modules used
@@ -545,384 +257,25 @@
       USE par_oce             ! Ocean parameters
       USE dom_oce, ONLY : &   ! Geographical information
-         & glamt,   &
-         & gphit,   &
-         & tmask,   &
+         & gdept_1d,             &
          & nproc
-      !! * Arguments
-      TYPE(obs_surf), INTENT(INOUT) :: sstdata     ! Full set of SST data
-      TYPE(obs_surf), INTENT(INOUT) :: sstdatqc    ! Subset of SST data not failing screening
-      LOGICAL :: ld_sst             ! Switch for SST data
-      LOGICAL :: ld_nea             ! Switch for rejecting observation near land
-      !! * Local declarations
-      INTEGER :: iyea0        ! Initial date
-      INTEGER :: imon0        !  - (year, month, day, hour, minute)
-      INTEGER :: iday0   
-      INTEGER :: ihou0    
-      INTEGER :: imin0
-      INTEGER :: icycle       ! Current assimilation cycle
-                              ! Counters for observations that
-      INTEGER :: iotdobs      !  - outside time domain
-      INTEGER :: iosdsobs     !  - outside space domain
-      INTEGER :: ilansobs     !  - within a model land cell
-      INTEGER :: inlasobs     !  - close to land
-      INTEGER :: igrdobs      !  - fail the grid search
-                              ! Global counters for observations that
-      INTEGER :: iotdobsmpp   !  - outside time domain
-      INTEGER :: iosdsobsmpp  !  - outside space domain
-      INTEGER :: ilansobsmpp  !  - within a model land cell
-      INTEGER :: inlasobsmpp  !  - close to land
-      INTEGER :: igrdobsmpp   !  - fail the grid search
-      LOGICAL, DIMENSION(:), ALLOCATABLE :: & 
-         & llvalid            ! SST data selection
-      INTEGER :: jobs         ! Obs. loop variable
-      INTEGER :: jstp         ! Time loop variable
-      INTEGER :: inrc         ! Time index variable
-
-      IF(lwp) WRITE(numout,*)'obs_pre_sst : Preparing the SST observations...'
-
-      ! Initial date initialization (year, month, day, hour, minute)
-      iyea0 =   ndate0 / 10000
-      imon0 = ( ndate0 - iyea0 * 10000 ) / 100
-      iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
-
-      icycle = no     ! Assimilation cycle
-
-      ! Diagnotics counters for various failures.
-
-      iotdobs  = 0
-      igrdobs  = 0
-      iosdsobs = 0
-      ilansobs = 0
-      inlasobs = 0
-
-      ! -----------------------------------------------------------------------
-      ! Find time coordinate for SST data
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_tim( icycle, &
-         &              iyea0,   imon0,   iday0,   ihou0,   imin0,      &
-         &              sstdata%nsurf,   sstdata%nyea, sstdata%nmon, &
-         &              sstdata%nday,    sstdata%nhou, sstdata%nmin, &
-         &              sstdata%nqc,     sstdata%mstp, iotdobs        )
-      CALL obs_mpp_sum_integer( iotdobs, iotdobsmpp )
-      ! -----------------------------------------------------------------------
-      ! Check for SST data failing the grid search
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_grd( sstdata%nsurf,   sstdata%mi, sstdata%mj, &
-         &              sstdata%nqc,     igrdobs                         )
-      CALL obs_mpp_sum_integer( igrdobs, igrdobsmpp )
-
-      ! -----------------------------------------------------------------------
-      ! Check for land points. 
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_spc_2d( sstdata%nsurf,              &
-         &                 jpi,          jpj,          &
-         &                 sstdata%mi,   sstdata%mj,   & 
-         &                 sstdata%rlam, sstdata%rphi, &
-         &                 glamt,        gphit,        &
-         &                 tmask(:,:,1), sstdata%nqc,  &
-         &                 iosdsobs,     ilansobs,     &
-         &                 inlasobs,     ld_nea        )
-
-      CALL obs_mpp_sum_integer( iosdsobs, iosdsobsmpp )
-      CALL obs_mpp_sum_integer( ilansobs, ilansobsmpp )
-      CALL obs_mpp_sum_integer( inlasobs, inlasobsmpp )
-
-      ! -----------------------------------------------------------------------
-      ! Copy useful data from the sstdata data structure to
-      ! the sstdatqc data structure 
-      ! -----------------------------------------------------------------------
-
-      ! Allocate the selection arrays
-
-      ALLOCATE( llvalid(sstdata%nsurf) )
-      
-      ! We want all data which has qc flags <= 0
-
-      llvalid(:)  = ( sstdata%nqc(:)  <= 10 )
-
-      ! The actual copying
-
-      CALL obs_surf_compress( sstdata,     sstdatqc,       .TRUE.,  numout, &
-         &                    lvalid=llvalid )
-
-      ! Dellocate the selection arrays
-      DEALLOCATE( llvalid )
-
-      ! -----------------------------------------------------------------------
-      ! Print information about what observations are left after qc
-      ! -----------------------------------------------------------------------
-
-      ! Update the total observation counter array
-      
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'obs_pre_sst :'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*)
-         WRITE(numout,*) ' SST data outside time domain                  = ', &
-            &            iotdobsmpp
-         WRITE(numout,*) ' Remaining SST data that failed grid search    = ', &
-            &            igrdobsmpp
-         WRITE(numout,*) ' Remaining SST data outside space domain       = ', &
-            &            iosdsobsmpp
-         WRITE(numout,*) ' Remaining SST data at land points             = ', &
-            &            ilansobsmpp
-         IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining SST data near land points (removed) = ', &
-               &            inlasobsmpp
-         ELSE
-            WRITE(numout,*) ' Remaining SST data near land points (kept)    = ', &
-               &            inlasobsmpp
-         ENDIF
-         WRITE(numout,*) ' SST data accepted                             = ', &
-            &            sstdatqc%nsurfmpp
-
-         WRITE(numout,*)
-         WRITE(numout,*) ' Number of observations per time step :'
-         WRITE(numout,*)
-         WRITE(numout,1997)
-         WRITE(numout,1998)
-      ENDIF
-      
-      DO jobs = 1, sstdatqc%nsurf
-         inrc = sstdatqc%mstp(jobs) + 2 - nit000
-         sstdatqc%nsstp(inrc)  = sstdatqc%nsstp(inrc) + 1
-      END DO
-      
-      CALL obs_mpp_sum_integers( sstdatqc%nsstp, sstdatqc%nsstpmpp, &
-         &                       nitend - nit000 + 2 )
-
-      IF ( lwp ) THEN
-         DO jstp = nit000 - 1, nitend
-            inrc = jstp - nit000 + 2
-            WRITE(numout,1999) jstp, sstdatqc%nsstpmpp(inrc)
-         END DO
-      ENDIF
-
-1997  FORMAT(10X,'Time step',5X,'Sea surface temperature')
-1998  FORMAT(10X,'---------',5X,'-----------------')
-1999  FORMAT(10X,I9,5X,I17)
-      
-   END SUBROUTINE obs_pre_sst
-
-   SUBROUTINE obs_pre_seaice( seaicedata, seaicedatqc, ld_seaice, ld_nea )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE obs_pre_seaice  ***
-      !!
-      !! ** Purpose : First level check and screening of Sea Ice observations
-      !!
-      !! ** Method  : First level check and screening of Sea Ice observations
-      !!
-      !! ** Action  : 
-      !!
-      !! References :
-      !!   
-      !! History :
-      !!        !  2007-11 (D. Lea) based on obs_pre_sst
-      !!----------------------------------------------------------------------
-      !! * Modules used
-      USE domstp              ! Domain: set the time-step
-      USE par_oce             ! Ocean parameters
-      USE dom_oce, ONLY : &   ! Geographical information
-         & glamt,   &
-         & gphit,   &
-         & tmask,   &
-         & nproc
-      !! * Arguments
-      TYPE(obs_surf), INTENT(INOUT) :: seaicedata     ! Full set of Sea Ice data
-      TYPE(obs_surf), INTENT(INOUT) :: seaicedatqc    ! Subset of sea ice data not failing screening
-      LOGICAL :: ld_seaice     ! Switch for sea ice data
-      LOGICAL :: ld_nea        ! Switch for rejecting observation near land
-      !! * Local declarations
-      INTEGER :: iyea0         ! Initial date
-      INTEGER :: imon0         !  - (year, month, day, hour, minute)
-      INTEGER :: iday0    
-      INTEGER :: ihou0    
-      INTEGER :: imin0
-      INTEGER :: icycle       ! Current assimilation cycle
-                              ! Counters for observations that
-      INTEGER :: iotdobs      !  - outside time domain
-      INTEGER :: iosdsobs     !  - outside space domain
-      INTEGER :: ilansobs     !  - within a model land cell
-      INTEGER :: inlasobs     !  - close to land
-      INTEGER :: igrdobs      !  - fail the grid search
-                              ! Global counters for observations that
-      INTEGER :: iotdobsmpp   !  - outside time domain
-      INTEGER :: iosdsobsmpp  !  - outside space domain
-      INTEGER :: ilansobsmpp  !  - within a model land cell
-      INTEGER :: inlasobsmpp  !  - close to land
-      INTEGER :: igrdobsmpp   !  - fail the grid search
-      LOGICAL, DIMENSION(:), ALLOCATABLE :: & 
-         & llvalid            ! data selection
-      INTEGER :: jobs         ! Obs. loop variable
-      INTEGER :: jstp         ! Time loop variable
-      INTEGER :: inrc         ! Time index variable
-
-      IF (lwp) WRITE(numout,*)'obs_pre_seaice : Preparing the sea ice observations...'
-
-      ! Initial date initialization (year, month, day, hour, minute)
-      iyea0 =   ndate0 / 10000
-      imon0 = ( ndate0 - iyea0 * 10000 ) / 100
-      iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
-
-      icycle = no     ! Assimilation cycle
-
-      ! Diagnotics counters for various failures.
-
-      iotdobs  = 0
-      igrdobs  = 0
-      iosdsobs = 0
-      ilansobs = 0
-      inlasobs = 0
-
-      ! -----------------------------------------------------------------------
-      ! Find time coordinate for sea ice data
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_tim( icycle, &
-         &              iyea0,   imon0,   iday0,   ihou0,   imin0,      &
-         &              seaicedata%nsurf,   seaicedata%nyea, seaicedata%nmon, &
-         &              seaicedata%nday,    seaicedata%nhou, seaicedata%nmin, &
-         &              seaicedata%nqc,     seaicedata%mstp, iotdobs        )
-      CALL obs_mpp_sum_integer( iotdobs, iotdobsmpp )
-      ! -----------------------------------------------------------------------
-      ! Check for sea ice data failing the grid search
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_grd( seaicedata%nsurf,   seaicedata%mi, seaicedata%mj, &
-         &              seaicedata%nqc,     igrdobs                         )
-      CALL obs_mpp_sum_integer( igrdobs, igrdobsmpp )
-
-      ! -----------------------------------------------------------------------
-      ! Check for land points. 
-      ! -----------------------------------------------------------------------
-
-      CALL obs_coo_spc_2d( seaicedata%nsurf,                 &
-         &                 jpi,             jpj,             &
-         &                 seaicedata%mi,   seaicedata%mj,   & 
-         &                 seaicedata%rlam, seaicedata%rphi, &
-         &                 glamt,           gphit,           &
-         &                 tmask(:,:,1),    seaicedata%nqc,  &
-         &                 iosdsobs,        ilansobs,        &
-         &                 inlasobs,        ld_nea           )
-
-      CALL obs_mpp_sum_integer( iosdsobs, iosdsobsmpp )
-      CALL obs_mpp_sum_integer( ilansobs, ilansobsmpp )
-      CALL obs_mpp_sum_integer( inlasobs, inlasobsmpp )
-
-      ! -----------------------------------------------------------------------
-      ! Copy useful data from the seaicedata data structure to
-      ! the seaicedatqc data structure 
-      ! -----------------------------------------------------------------------
-
-      ! Allocate the selection arrays
-
-      ALLOCATE( llvalid(seaicedata%nsurf) )
-      
-      ! We want all data which has qc flags <= 0
-
-      llvalid(:)  = ( seaicedata%nqc(:)  <= 10 )
-
-      ! The actual copying
-
-      CALL obs_surf_compress( seaicedata,     seaicedatqc,       .TRUE.,  numout, &
-         &                    lvalid=llvalid )
-
-      ! Dellocate the selection arrays
-      DEALLOCATE( llvalid )
-
-      ! -----------------------------------------------------------------------
-      ! Print information about what observations are left after qc
-      ! -----------------------------------------------------------------------
-
-      ! Update the total observation counter array
-      
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'obs_pre_seaice :'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*)
-         WRITE(numout,*) ' Sea ice data outside time domain                  = ', &
-            &            iotdobsmpp
-         WRITE(numout,*) ' Remaining sea ice data that failed grid search    = ', &
-            &            igrdobsmpp
-         WRITE(numout,*) ' Remaining sea ice data outside space domain       = ', &
-            &            iosdsobsmpp
-         WRITE(numout,*) ' Remaining sea ice data at land points             = ', &
-            &            ilansobsmpp
-         IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining sea ice data near land points (removed) = ', &
-               &            inlasobsmpp
-         ELSE
-            WRITE(numout,*) ' Remaining sea ice data near land points (kept)    = ', &
-               &            inlasobsmpp
-         ENDIF
-         WRITE(numout,*) ' Sea ice data accepted                             = ', &
-            &            seaicedatqc%nsurfmpp
-
-         WRITE(numout,*)
-         WRITE(numout,*) ' Number of observations per time step :'
-         WRITE(numout,*)
-         WRITE(numout,1997)
-         WRITE(numout,1998)
-      ENDIF
-      
-      DO jobs = 1, seaicedatqc%nsurf
-         inrc = seaicedatqc%mstp(jobs) + 2 - nit000
-         seaicedatqc%nsstp(inrc)  = seaicedatqc%nsstp(inrc) + 1
-      END DO
-      
-      CALL obs_mpp_sum_integers( seaicedatqc%nsstp, seaicedatqc%nsstpmpp, &
-         &                       nitend - nit000 + 2 )
-
-      IF ( lwp ) THEN
-         DO jstp = nit000 - 1, nitend
-            inrc = jstp - nit000 + 2
-            WRITE(numout,1999) jstp, seaicedatqc%nsstpmpp(inrc)
-         END DO
-      ENDIF
-
-1997  FORMAT(10X,'Time step',5X,'Sea ice data           ')
-1998  FORMAT(10X,'---------',5X,'-----------------')
-1999  FORMAT(10X,I9,5X,I17)
-      
-   END SUBROUTINE obs_pre_seaice
-
-   SUBROUTINE obs_pre_vel( profdata, prodatqc, ld_vel3d, ld_nea, ld_dailyav )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE obs_pre_taovel  ***
-      !!
-      !! ** Purpose : First level check and screening of U and V profiles
-      !!
-      !! ** Method  : First level check and screening of U and V profiles
-      !!
-      !! History :
-      !!        !  2007-06  (K. Mogensen) original : T and S profile data
-      !!        !  2008-09  (M. Valdivieso) : TAO velocity data
-      !!        !  2009-01  (K. Mogensen) : New feedback strictuer
-      !!
-      !!----------------------------------------------------------------------
-      !! * Modules used
-      USE domstp              ! Domain: set the time-step
-      USE par_oce             ! Ocean parameters
-      USE dom_oce, ONLY : &   ! Geographical information
-         & glamt, glamu, glamv,    &
-         & gphit, gphiu, gphiv,    &
-         & gdept_1d,             &
-         & tmask, umask, vmask,  &
-         & nproc
+
       !! * Arguments
       TYPE(obs_prof), INTENT(INOUT) :: profdata   ! Full set of profile data
       TYPE(obs_prof), INTENT(INOUT) :: prodatqc   ! Subset of profile data not failing screening
-      LOGICAL, INTENT(IN) :: ld_vel3d      ! Switch for zonal and meridional velocity components
-      LOGICAL, INTENT(IN) :: ld_nea        ! Switch for rejecting observation near land
-      LOGICAL, INTENT(IN) :: ld_dailyav    ! Switch for daily average data
+      LOGICAL, INTENT(IN) :: ld_var1              ! Observed variables switches
+      LOGICAL, INTENT(IN) :: ld_var2
+      LOGICAL, INTENT(IN) :: ld_nea               ! Switch for rejecting observation near land
+      INTEGER, INTENT(IN) :: kpi, kpj, kpk        ! Local domain sizes
+      INTEGER, DIMENSION(imaxavtypes), OPTIONAL :: &
+         & kdailyavtypes                          ! Types for daily averages
+      REAL(wp), INTENT(IN), DIMENSION(kpi,kpj,kpk) :: &
+         & zmask1, &
+         & zmask2
+      REAL(wp), INTENT(IN), DIMENSION(kpi,kpj) :: &
+         & pglam1, &
+         & pglam2, &
+         & pgphi1, &
+         & pgphi2
+
       !! * Local declarations
       INTEGER :: iyea0        ! Initial date
@@ -932,29 +285,29 @@
       INTEGER :: imin0
       INTEGER :: icycle       ! Current assimilation cycle
-                              ! Counters for observations that
+                              ! Counters for observations that are
       INTEGER :: iotdobs      !  - outside time domain
-      INTEGER :: iosduobs     !  - outside space domain (zonal velocity component)
-      INTEGER :: iosdvobs     !  - outside space domain (meridional velocity component)
-      INTEGER :: ilanuobs     !  - within a model land cell (zonal velocity component)
-      INTEGER :: ilanvobs     !  - within a model land cell (meridional velocity component)
-      INTEGER :: inlauobs     !  - close to land (zonal velocity component)
-      INTEGER :: inlavobs     !  - close to land (meridional velocity component)
+      INTEGER :: iosdv1obs    !  - outside space domain (variable 1)
+      INTEGER :: iosdv2obs    !  - outside space domain (variable 2)
+      INTEGER :: ilanv1obs    !  - within a model land cell (variable 1)
+      INTEGER :: ilanv2obs    !  - within a model land cell (variable 2)
+      INTEGER :: inlav1obs    !  - close to land (variable 1)
+      INTEGER :: inlav2obs    !  - close to land (variable 2)
       INTEGER :: igrdobs      !  - fail the grid search
       INTEGER :: iuvchku      !  - reject u if v rejected and vice versa
       INTEGER :: iuvchkv      !
-                              ! Global counters for observations that
+                              ! Global counters for observations that are
       INTEGER :: iotdobsmpp   !  - outside time domain
-      INTEGER :: iosduobsmpp  !  - outside space domain (zonal velocity component)
-      INTEGER :: iosdvobsmpp  !  - outside space domain (meridional velocity component)
-      INTEGER :: ilanuobsmpp  !  - within a model land cell (zonal velocity component)
-      INTEGER :: ilanvobsmpp  !  - within a model land cell (meridional velocity component)
-      INTEGER :: inlauobsmpp  !  - close to land (zonal velocity component)
-      INTEGER :: inlavobsmpp  !  - close to land (meridional velocity component)
+      INTEGER :: iosdv1obsmpp !  - outside space domain (variable 1)
+      INTEGER :: iosdv2obsmpp !  - outside space domain (variable 2)
+      INTEGER :: ilanv1obsmpp !  - within a model land cell (variable 1)
+      INTEGER :: ilanv2obsmpp !  - within a model land cell (variable 2)
+      INTEGER :: inlav1obsmpp !  - close to land (variable 1)
+      INTEGER :: inlav2obsmpp !  - close to land (variable 2)
       INTEGER :: igrdobsmpp   !  - fail the grid search
-      INTEGER :: iuvchkumpp   !  - reject u if v rejected and vice versa
+      INTEGER :: iuvchkumpp   !  - reject var1 if var2 rejected and vice versa
       INTEGER :: iuvchkvmpp   !
       TYPE(obs_prof_valid) ::  llvalid      ! Profile selection 
       TYPE(obs_prof_valid), DIMENSION(profdata%nvar) :: &
-         & llvvalid           ! U,V selection 
+         & llvvalid           ! var1,var2 selection 
       INTEGER :: jvar         ! Variable loop variable
       INTEGER :: jobs         ! Obs. loop variable
@@ -962,5 +315,6 @@
       INTEGER :: inrc         ! Time index variable
 
-      IF(lwp) WRITE(numout,*)'obs_pre_vel: Preparing the velocity profile data'
+      IF(lwp) WRITE(numout,*)'obs_pre_prof: Preparing the profile data...'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
 
       ! Initial date initialization (year, month, day, hour, minute)
@@ -968,6 +322,6 @@
       imon0 = ( ndate0 - iyea0 * 10000 ) / 100
       iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
+      ihou0 = nn_time0 / 100
+      imin0 = ( nn_time0 - ihou0 * 100 )
 
       icycle = no     ! Assimilation cycle
@@ -977,10 +331,10 @@
       iotdobs  = 0
       igrdobs  = 0
-      iosduobs = 0
-      iosdvobs = 0
-      ilanuobs = 0
-      ilanvobs = 0
-      inlauobs = 0
-      inlavobs = 0
+      iosdv1obs = 0
+      iosdv2obs = 0
+      ilanv1obs = 0
+      ilanv2obs = 0
+      inlav1obs = 0
+      inlav2obs = 0
       iuvchku  = 0
       iuvchkv = 0
@@ -990,11 +344,20 @@
       ! -----------------------------------------------------------------------
 
-      CALL obs_coo_tim_prof( icycle, &
-         &              iyea0,   imon0,   iday0,   ihou0,   imin0,      &
-         &              profdata%nprof,   profdata%nyea, profdata%nmon, &
-         &              profdata%nday,    profdata%nhou, profdata%nmin, &
-         &              profdata%ntyp,    profdata%nqc,  profdata%mstp, &
-         &              iotdobs, ld_dailyav = ld_dailyav        )
-	 
+      IF ( PRESENT(kdailyavtypes) ) THEN
+         CALL obs_coo_tim_prof( icycle, &
+            &              iyea0,   imon0,   iday0,   ihou0,   imin0,      &
+            &              profdata%nprof,   profdata%nyea, profdata%nmon, &
+            &              profdata%nday,    profdata%nhou, profdata%nmin, &
+            &              profdata%ntyp,    profdata%nqc,  profdata%mstp, &
+            &              iotdobs, kdailyavtypes = kdailyavtypes )
+      ELSE
+         CALL obs_coo_tim_prof( icycle, &
+            &              iyea0,   imon0,   iday0,   ihou0,   imin0,      &
+            &              profdata%nprof,   profdata%nyea, profdata%nmon, &
+            &              profdata%nday,    profdata%nhou, profdata%nmin, &
+            &              profdata%ntyp,    profdata%nqc,  profdata%mstp, &
+            &              iotdobs )
+      ENDIF
+
       CALL obs_mpp_sum_integer( iotdobs, iotdobsmpp )
       
@@ -1021,26 +384,24 @@
       ! -----------------------------------------------------------------------
 
-      ! Zonal Velocity Component
-
+      ! Variable 1
       CALL obs_coo_spc_3d( profdata%nprof,        profdata%nvprot(1),   &
          &                 profdata%npvsta(:,1),  profdata%npvend(:,1), &
          &                 jpi,                   jpj,                  &
          &                 jpk,                                         &
-         &                 profdata%mi,           profdata%mj,          & 
+         &                 profdata%mi,           profdata%mj,          &
          &                 profdata%var(1)%mvk,                         &
          &                 profdata%rlam,         profdata%rphi,        &
          &                 profdata%var(1)%vdep,                        &
-         &                 glamu,                 gphiu,                &
-         &                 gdept_1d,              umask,                &
+         &                 pglam1,                pgphi1,               &
+         &                 gdept_1d,              zmask1,               &
          &                 profdata%nqc,          profdata%var(1)%nvqc, &
-         &                 iosduobs,              ilanuobs,             &
-         &                 inlauobs,              ld_nea                )
-
-      CALL obs_mpp_sum_integer( iosduobs, iosduobsmpp )
-      CALL obs_mpp_sum_integer( ilanuobs, ilanuobsmpp )
-      CALL obs_mpp_sum_integer( inlauobs, inlauobsmpp )
-
-      ! Meridional Velocity Component
-
+         &                 iosdv1obs,              ilanv1obs,           &
+         &                 inlav1obs,              ld_nea                )
+
+      CALL obs_mpp_sum_integer( iosdv1obs, iosdv1obsmpp )
+      CALL obs_mpp_sum_integer( ilanv1obs, ilanv1obsmpp )
+      CALL obs_mpp_sum_integer( inlav1obs, inlav1obsmpp )
+
+      ! Variable 2
       CALL obs_coo_spc_3d( profdata%nprof,        profdata%nvprot(2),   &
          &                 profdata%npvsta(:,2),  profdata%npvend(:,2), &
@@ -1051,13 +412,13 @@
          &                 profdata%rlam,         profdata%rphi,        &
          &                 profdata%var(2)%vdep,                        &
-         &                 glamv,                 gphiv,                &
-         &                 gdept_1d,              vmask,                &
+         &                 pglam2,                pgphi2,               &
+         &                 gdept_1d,              zmask2,               &
          &                 profdata%nqc,          profdata%var(2)%nvqc, &
-         &                 iosdvobs,              ilanvobs,             &
-         &                 inlavobs,              ld_nea                )
-
-      CALL obs_mpp_sum_integer( iosdvobs, iosdvobsmpp )
-      CALL obs_mpp_sum_integer( ilanvobs, ilanvobsmpp )
-      CALL obs_mpp_sum_integer( inlavobs, inlavobsmpp )
+         &                 iosdv2obs,              ilanv2obs,           &
+         &                 inlav2obs,              ld_nea                )
+
+      CALL obs_mpp_sum_integer( iosdv2obs, iosdv2obsmpp )
+      CALL obs_mpp_sum_integer( ilanv2obs, ilanv2obsmpp )
+      CALL obs_mpp_sum_integer( inlav2obs, inlav2obsmpp )
 
       ! -----------------------------------------------------------------------
@@ -1065,7 +426,9 @@
       ! -----------------------------------------------------------------------
 
-      CALL obs_uv_rej( profdata, iuvchku, iuvchkv )
-      CALL obs_mpp_sum_integer( iuvchku, iuvchkumpp )
-      CALL obs_mpp_sum_integer( iuvchkv, iuvchkvmpp )
+      IF ( TRIM(profdata%cvars(1)) == 'UVEL' ) THEN
+         CALL obs_uv_rej( profdata, iuvchku, iuvchkv )
+         CALL obs_mpp_sum_integer( iuvchku, iuvchkumpp )
+         CALL obs_mpp_sum_integer( iuvchkv, iuvchkvmpp )
+      ENDIF
 
       ! -----------------------------------------------------------------------
@@ -1106,41 +469,43 @@
       
       IF(lwp) THEN
+      
          WRITE(numout,*)
-         WRITE(numout,*) 'obs_pre_vel :'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*)
-         WRITE(numout,*) ' Profiles outside time domain                = ', &
+         WRITE(numout,*) ' Profiles outside time domain                     = ', &
             &            iotdobsmpp
-         WRITE(numout,*) ' Remaining profiles that failed grid search  = ', &
+         WRITE(numout,*) ' Remaining profiles that failed grid search       = ', &
             &            igrdobsmpp
-         WRITE(numout,*) ' Remaining U data outside space domain       = ', &
-            &            iosduobsmpp
-         WRITE(numout,*) ' Remaining U data at land points             = ', &
-            &            ilanuobsmpp
+         WRITE(numout,*) ' Remaining '//prodatqc%cvars(1)//' data outside space domain       = ', &
+            &            iosdv1obsmpp
+         WRITE(numout,*) ' Remaining '//prodatqc%cvars(1)//' data at land points             = ', &
+            &            ilanv1obsmpp
          IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining U data near land points (removed) = ',&
-               &            inlauobsmpp
+            WRITE(numout,*) ' Remaining '//prodatqc%cvars(1)//' data near land points (removed) = ',&
+               &            inlav1obsmpp
          ELSE
-            WRITE(numout,*) ' Remaining U data near land points (kept)    = ',&
-               &            inlauobsmpp
-         ENDIF
-         WRITE(numout,*) ' U observation rejected since V rejected     = ', &
-            &            iuvchku     
-         WRITE(numout,*) ' U data accepted                             = ', &
+            WRITE(numout,*) ' Remaining '//prodatqc%cvars(1)//' data near land points (kept)    = ',&
+               &            inlav1obsmpp
+         ENDIF
+         IF ( TRIM(profdata%cvars(1)) == 'UVEL' ) THEN
+            WRITE(numout,*) ' U observation rejected since V rejected     = ', &
+               &            iuvchku
+         ENDIF
+         WRITE(numout,*) ' '//prodatqc%cvars(1)//' data accepted                             = ', &
             &            prodatqc%nvprotmpp(1)
-         WRITE(numout,*) ' Remaining V data outside space domain       = ', &
-            &            iosdvobsmpp
-         WRITE(numout,*) ' Remaining V data at land points             = ', &
-            &            ilanvobsmpp
+         WRITE(numout,*) ' Remaining '//prodatqc%cvars(2)//' data outside space domain       = ', &
+            &            iosdv2obsmpp
+         WRITE(numout,*) ' Remaining '//prodatqc%cvars(2)//' data at land points             = ', &
+            &            ilanv2obsmpp
          IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining V data near land points (removed) = ',&
-               &            inlavobsmpp
+            WRITE(numout,*) ' Remaining '//prodatqc%cvars(2)//' data near land points (removed) = ',&
+               &            inlav2obsmpp
          ELSE
-            WRITE(numout,*) ' Remaining V data near land points (kept)    = ',&
-               &            inlavobsmpp
-         ENDIF
-         WRITE(numout,*) ' V observation rejected since U rejected     = ', &
-            &            iuvchkv     
-         WRITE(numout,*) ' V data accepted                             = ', &
+            WRITE(numout,*) ' Remaining '//prodatqc%cvars(2)//' data near land points (kept)    = ',&
+               &            inlav2obsmpp
+         ENDIF
+         IF ( TRIM(profdata%cvars(1)) == 'UVEL' ) THEN
+            WRITE(numout,*) ' V observation rejected since U rejected     = ', &
+               &            iuvchkv
+         ENDIF
+         WRITE(numout,*) ' '//prodatqc%cvars(2)//' data accepted                             = ', &
             &            prodatqc%nvprotmpp(2)
 
@@ -1148,5 +513,7 @@
          WRITE(numout,*) ' Number of observations per time step :'
          WRITE(numout,*)
-         WRITE(numout,997)
+         WRITE(numout,'(10X,A,5X,A,5X,A,A)')'Time step','Profiles', &
+            &                               '     '//prodatqc%cvars(1)//'     ', &
+            &                               '     '//prodatqc%cvars(2)//'     '
          WRITE(numout,998)
       ENDIF
@@ -1182,9 +549,8 @@
       ENDIF
 
-997   FORMAT(10X,'Time step',5X,'Profiles',5X,'Zonal Comp.',5X,'Meridional Comp.')
 998   FORMAT(10X,'---------',5X,'--------',5X,'-----------',5X,'----------------')
 999   FORMAT(10X,I9,5X,I8,5X,I11,5X,I8)
 
-   END SUBROUTINE obs_pre_vel
+   END SUBROUTINE obs_pre_prof
 
    SUBROUTINE obs_coo_tim( kcycle, &
@@ -1388,6 +754,5 @@
       &                    kobsno,                                        &
       &                    kobsyea, kobsmon, kobsday, kobshou, kobsmin,   &
-      &                    ktyp,    kobsqc,  kobsstp, kotdobs, kdailyavtypes, &
-      &                    ld_dailyav )
+      &                    ktyp,    kobsqc,  kobsstp, kotdobs, kdailyavtypes )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE obs_coo_tim ***
@@ -1433,5 +798,4 @@
       INTEGER, DIMENSION(imaxavtypes), OPTIONAL :: &
          & kdailyavtypes    ! Types for daily averages
-      LOGICAL, OPTIONAL :: ld_dailyav    ! All types are daily averages
       !! * Local declarations
       INTEGER :: jobs
@@ -1467,24 +831,4 @@
       ENDIF
 
-      !------------------------------------------------------------------------
-      ! If ld_dailyav is set then all data assumed to be daily averaged
-      !------------------------------------------------------------------------
-      
-      IF ( PRESENT( ld_dailyav) ) THEN
-         IF (ld_dailyav) THEN
-            DO jobs = 1, kobsno
-               
-               IF ( kobsqc(jobs) <= 10 ) THEN
-                  
-                  IF ( kobsstp(jobs) == (nit000 - 1) ) THEN
-                     kobsqc(jobs) = kobsqc(jobs) + 14
-                     kotdobs      = kotdobs + 1
-                     CYCLE
-                  ENDIF
-                  
-               ENDIF
-            END DO
-         ENDIF
-      ENDIF
 
    END SUBROUTINE obs_coo_tim_prof
@@ -1614,7 +958,7 @@
       END DO
       
-      CALL obs_int_comm_2d( 2, 2, kobsno, igrdi, igrdj, pmask, zgmsk )
-      CALL obs_int_comm_2d( 2, 2, kobsno, igrdi, igrdj, plam, zglam )
-      CALL obs_int_comm_2d( 2, 2, kobsno, igrdi, igrdj, pphi, zgphi )
+      CALL obs_int_comm_2d( 2, 2, kobsno, kpi, kpj, igrdi, igrdj, pmask, zgmsk )
+      CALL obs_int_comm_2d( 2, 2, kobsno, kpi, kpj, igrdi, igrdj, plam, zglam )
+      CALL obs_int_comm_2d( 2, 2, kobsno, kpi, kpj, igrdi, igrdj, pphi, zgphi )
 
       DO jobs = 1, kobsno
@@ -1709,5 +1053,10 @@
       !! * Modules used
       USE dom_oce, ONLY : &       ! Geographical information
-         & gdepw_1d                        
+         & gdepw_1d,      &
+         & gdepw_0,       &                       
+         & gdepw_n,       &
+         & gdept_n,       &
+         & ln_zco,        &
+         & ln_zps             
 
       !! * Arguments
@@ -1747,4 +1096,6 @@
       REAL(KIND=wp), DIMENSION(2,2,kpk,kprofno) :: &
          & zgmsk              ! Grid mask
+      REAL(KIND=wp), DIMENSION(2,2,kpk,kprofno) :: &
+         & zgdepw
       REAL(KIND=wp), DIMENSION(2,2,kprofno) :: &
          & zglam, &           ! Model longitude at grid points
@@ -1754,4 +1105,5 @@
          & igrdj
       LOGICAL :: lgridobs           ! Is observation on a model grid point.
+      LOGICAL :: ll_next_to_land    ! Is a profile next to land 
       INTEGER :: iig, ijg           ! i,j of observation on model grid point.
       INTEGER :: jobs, jobsp, jk, ji, jj
@@ -1789,7 +1141,12 @@
       END DO
       
-      CALL obs_int_comm_3d( 2, 2, kprofno, kpk, igrdi, igrdj, pmask, zgmsk )
-      CALL obs_int_comm_2d( 2, 2, kprofno, igrdi, igrdj, plam, zglam )
-      CALL obs_int_comm_2d( 2, 2, kprofno, igrdi, igrdj, pphi, zgphi )
+      CALL obs_int_comm_3d( 2, 2, kprofno, kpi, kpj, kpk, igrdi, igrdj, pmask, zgmsk )
+      CALL obs_int_comm_2d( 2, 2, kprofno, kpi, kpj, igrdi, igrdj, plam, zglam )
+      CALL obs_int_comm_2d( 2, 2, kprofno, kpi, kpj, igrdi, igrdj, pphi, zgphi )
+      IF ( .NOT.( ln_zps .OR. ln_zco ) ) THEN
+        ! Need to know the bathy depth for each observation for sco
+        CALL obs_int_comm_3d( 2, 2, kprofno, kpi, kpj, kpk, igrdi, igrdj, gdepw_n(:,:,:), &
+        &                     zgdepw )
+      ENDIF
 
       DO jobs = 1, kprofno
@@ -1816,4 +1173,11 @@
          END DO
 
+         ! Check if next to land
+         IF (  ANY( zgmsk(1:2,1:2,1,jobs) == 0.0_wp ) ) THEN
+            ll_next_to_land=.TRUE.
+         ELSE
+            ll_next_to_land=.FALSE.
+         ENDIF 
+
          ! Reject observations
 
@@ -1832,12 +1196,50 @@
             ENDIF
 
-            ! Flag if the observation falls with a model land cell
-            IF ( SUM( zgmsk(1:2,1:2,kobsk(jobsp)-1:kobsk(jobsp),jobs) ) &
-               &  == 0.0_wp ) THEN
-               kobsqc(jobsp) = kobsqc(jobsp) + 12
-               klanobs = klanobs + 1
-               CYCLE
+            ! To check if an observations falls within land there are two cases:
+            ! 1: z-coordibnates, where the check uses the mask
+            ! 2: terrain following (eg s-coordinates), 
+            !    where we use the depth of the bottom cell to mask observations
+             
+            IF( ln_zps .OR. ln_zco ) THEN !(CASE 1)
+               
+               ! Flag if the observation falls with a model land cell
+               IF ( SUM( zgmsk(1:2,1:2,kobsk(jobsp)-1:kobsk(jobsp),jobs) ) &
+                  &  == 0.0_wp ) THEN
+                  kobsqc(jobsp) = kobsqc(jobsp) + 12
+                  klanobs = klanobs + 1
+                  CYCLE
+               ENDIF
+             
+               ! Flag if the observation is close to land
+              IF ( MINVAL( zgmsk(1:2,1:2,kobsk(jobsp)-1:kobsk(jobsp),jobs) ) == &
+                  &  0.0_wp) THEN
+                  knlaobs = knlaobs + 1
+                  IF (ld_nea) THEN   
+                     kobsqc(jobsp) = kobsqc(jobsp) + 14 
+                  ENDIF 
+               ENDIF
+             
+            ELSE ! Case 2
+ 
+               ! Flag if the observation is deeper than the bathymetry
+               ! Or if it is within the mask
+               IF ( ALL( zgdepw(1:2,1:2,kpk,jobs) < pobsdep(jobsp) ) &
+                  &     .OR. &
+                  &  ( SUM( zgmsk(1:2,1:2,kobsk(jobsp)-1:kobsk(jobsp),jobs) ) &
+                  &  == 0.0_wp) ) THEN
+                  kobsqc(jobsp) = kobsqc(jobsp) + 12
+                  klanobs = klanobs + 1
+                  CYCLE
+               ENDIF
+               
+               ! Flag if the observation is close to land
+               IF ( ll_next_to_land ) THEN
+                  knlaobs = knlaobs + 1
+                  IF (ld_nea) THEN   
+                     kobsqc(jobsp) = kobsqc(jobsp) + 14 
+                  ENDIF 
+               ENDIF
             ENDIF
-
+            
             ! For observations on the grid reject them if their are at
             ! a masked point
