Index: branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90
===================================================================
--- branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 9019)
+++ branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 9023)
@@ -46,15 +46,48 @@
    LOGICAL, PUBLIC :: ln_diaobs   !: Logical switch for the obs operator
    LOGICAL :: ln_sstnight         !: Logical switch for night mean SST obs
-   
+   LOGICAL :: ln_sla_fp_indegs    !: T=> SLA obs footprint size specified in degrees, F=> in metres
+   LOGICAL :: ln_sst_fp_indegs    !: T=> SST obs footprint size specified in degrees, F=> in metres
+   LOGICAL :: ln_sss_fp_indegs    !: T=> SSS obs footprint size specified in degrees, F=> in metres
+   LOGICAL :: ln_sic_fp_indegs    !: T=> sea-ice obs footprint size specified in degrees, F=> in metres
+
+   REAL(wp) :: rn_sla_avglamscl !: E/W diameter of SLA observation footprint (metres)
+   REAL(wp) :: rn_sla_avgphiscl !: N/S diameter of SLA observation footprint (metres)
+   REAL(wp) :: rn_sst_avglamscl !: E/W diameter of SST observation footprint (metres)
+   REAL(wp) :: rn_sst_avgphiscl !: N/S diameter of SST observation footprint (metres)
+   REAL(wp) :: rn_sss_avglamscl !: E/W diameter of SSS observation footprint (metres)
+   REAL(wp) :: rn_sss_avgphiscl !: N/S diameter of SSS observation footprint (metres)
+   REAL(wp) :: rn_sic_avglamscl !: E/W diameter of sea-ice observation footprint (metres)
+   REAL(wp) :: rn_sic_avgphiscl !: N/S diameter of sea-ice observation footprint (metres)
+
    INTEGER :: nn_1dint       !: Vertical interpolation method
-   INTEGER :: nn_2dint       !: Horizontal interpolation method
+   INTEGER :: nn_2dint       !: Default horizontal interpolation method
+   INTEGER :: nn_2dint_sla   !: SLA horizontal interpolation method 
+   INTEGER :: nn_2dint_sst   !: SST horizontal interpolation method 
+   INTEGER :: nn_2dint_sss   !: SSS horizontal interpolation method 
+   INTEGER :: nn_2dint_sic   !: Seaice horizontal interpolation method 
    INTEGER, DIMENSION(imaxavtypes) ::   nn_profdavtypes   !: Profile data types representing a daily average
    INTEGER :: nproftypes     !: Number of profile obs types
    INTEGER :: nsurftypes     !: Number of surface obs types
-   INTEGER, DIMENSION(:), ALLOCATABLE ::   nvarsprof, nvarssurf   !: Number of profile & surface variables
-   INTEGER, DIMENSION(:), ALLOCATABLE ::   nextrprof, nextrsurf   !: Number of profile & surface extra variables
-   INTEGER, PUBLIC, ALLOCATABLE, DIMENSION(:) ::   sstbias_type   !: SST bias type    
-   TYPE(obs_surf), PUBLIC, POINTER, DIMENSION(:) ::   surfdata, surfdataqc   !: Initial surface data before & after quality control
-   TYPE(obs_prof), PUBLIC, POINTER, DIMENSION(:) ::   profdata, profdataqc   !: Initial profile data before & after quality control
+   INTEGER, DIMENSION(:), ALLOCATABLE :: &
+      & nvarsprof, &         !: Number of profile variables
+      & nvarssurf            !: Number of surface variables
+   INTEGER, DIMENSION(:), ALLOCATABLE :: &
+      & nextrprof, &         !: Number of profile extra variables
+      & nextrsurf            !: Number of surface extra variables
+   INTEGER, DIMENSION(:), ALLOCATABLE :: &
+      & n2dintsurf           !: Interpolation option for surface variables
+   REAL(wp), DIMENSION(:), ALLOCATABLE :: &
+      & zavglamscl, &        !: E/W diameter of averaging footprint for surface variables
+      & zavgphiscl           !: N/S diameter of averaging footprint for surface variables
+   LOGICAL, DIMENSION(:), ALLOCATABLE :: &
+      & lfpindegs, &         !: T=> surface obs footprint size specified in degrees, F=> in metres
+      & llnightav            !: Logical for calculating night-time averages
+
+   TYPE(obs_surf), PUBLIC, POINTER, DIMENSION(:) :: &
+      & surfdata, &          !: Initial surface data
+      & surfdataqc           !: Surface data after quality control
+   TYPE(obs_prof), PUBLIC, POINTER, DIMENSION(:) :: &
+      & profdata, &          !: Initial profile data
+      & profdataqc           !: Profile data after quality control
 
    CHARACTER(len=6), PUBLIC, DIMENSION(:), ALLOCATABLE ::   cobstypesprof, cobstypessurf   !: Profile & surface obs types
@@ -95,8 +128,9 @@
          & cn_profbfiles, &      ! T/S profile input filenames
          & cn_sstfbfiles, &      ! Sea surface temperature input filenames
+         & cn_sssfbfiles, &      ! Sea surface salinity input filenames
          & cn_slafbfiles, &      ! Sea level anomaly input filenames
          & cn_sicfbfiles, &      ! Seaice concentration input filenames
          & cn_velfbfiles, &      ! Velocity profile input filenames
-         & cn_sstbias_files      ! SST bias input filenames
+         & cn_sstbiasfiles      ! SST bias input filenames
       CHARACTER(LEN=128) :: &
          & cn_altbiasfile        ! Altimeter bias input filename
@@ -109,4 +143,5 @@
       LOGICAL :: ln_sla          ! Logical switch for sea level anomalies 
       LOGICAL :: ln_sst          ! Logical switch for sea surface temperature
+      LOGICAL :: ln_sss          ! Logical switch for sea surface salinity
       LOGICAL :: ln_sic          ! Logical switch for sea ice concentration
       LOGICAL :: ln_vel3d        ! Logical switch for velocity (u,v) obs
@@ -116,7 +151,7 @@
       LOGICAL :: ln_ignmis       ! Logical switch for ignoring missing files
       LOGICAL :: ln_s_at_t       ! Logical switch to compute model S at T obs
+      LOGICAL :: ln_bound_reject ! Logical to remove obs near boundaries in LAMs.
       LOGICAL :: llvar1          ! Logical for profile variable 1
       LOGICAL :: llvar2          ! Logical for profile variable 1
-      LOGICAL :: llnightav       ! Logical for calculating night-time averages
       LOGICAL, DIMENSION(jpmaxnfiles) :: lmask ! Used for finding number of sstbias files
 
@@ -134,15 +169,26 @@
 
       NAMELIST/namobs/ln_diaobs, ln_t3d, ln_s3d, ln_sla,              &
-         &            ln_sst, ln_sic, ln_vel3d,                       &
-         &            ln_altbias, ln_nea, ln_grid_global,             &
-         &            ln_grid_search_lookup,                          &
-         &            ln_ignmis, ln_s_at_t, ln_sstnight,              &
+         &            ln_sst, ln_sic, ln_sss, ln_vel3d,               &
+         &            ln_altbias, ln_sstbias, ln_nea,                 &
+         &            ln_grid_global, ln_grid_search_lookup,          &
+         &            ln_ignmis, ln_s_at_t, ln_bound_reject,          &
+         &            ln_sstnight,                                    &
+         &            ln_sla_fp_indegs, ln_sst_fp_indegs,             &
+         &            ln_sss_fp_indegs, ln_sic_fp_indegs,             &
          &            cn_profbfiles, cn_slafbfiles,                   &
          &            cn_sstfbfiles, cn_sicfbfiles,                   &
-         &            cn_velfbfiles, cn_altbiasfile,                  &
+         &            cn_velfbfiles, cn_sssfbfiles,                   &
+         &            cn_sstbiasfiles, cn_altbiasfile,                &
          &            cn_gridsearchfile, rn_gridsearchres,            &
-         &            rn_dobsini, rn_dobsend, nn_1dint, nn_2dint,     &
+         &            rn_dobsini, rn_dobsend,                         &
+         &            rn_sla_avglamscl, rn_sla_avgphiscl,             &
+         &            rn_sst_avglamscl, rn_sst_avgphiscl,             &
+         &            rn_sss_avglamscl, rn_sss_avgphiscl,             &
+         &            rn_sic_avglamscl, rn_sic_avgphiscl,             &
+         &            nn_1dint, nn_2dint,                             &
+         &            nn_2dint_sla, nn_2dint_sst,                     &
+         &            nn_2dint_sss, nn_2dint_sic,                     &
          &            nn_msshc, rn_mdtcorr, rn_mdtcutoff,             &
-         &            nn_profdavtypes, ln_sstbias, cn_sstbias_files
+         &            nn_profdavtypes
 
       INTEGER :: jnumsstbias
@@ -157,7 +203,4 @@
       ! Read namelist parameters
       !-----------------------------------------------------------------------
-      
-      !Initalise all values in namelist arrays
-      ALLOCATE(sstbias_type(jpmaxnfiles))
       ! Some namelist arrays need initialising
       cn_profbfiles(:) = ''
@@ -166,5 +209,6 @@
       cn_sicfbfiles(:) = ''
       cn_velfbfiles(:) = ''
-      cn_sstbias_files(:) = ''
+      cn_sssfbfiles(:)    = ''
+      cn_sstbiasfiles(:) = ''
       nn_profdavtypes(:) = -1
 
@@ -187,103 +231,5 @@
          RETURN
       ENDIF
-      
-      !-----------------------------------------------------------------------
-      ! Set up list of observation types to be used
-      ! and the files associated with each type
-      !-----------------------------------------------------------------------
-
-      nproftypes = COUNT( (/ln_t3d .OR. ln_s3d, ln_vel3d /) )
-      nsurftypes = COUNT( (/ln_sla, ln_sst, ln_sic /) )
-
-      IF (ln_sstbias) THEN 
-         lmask(:) = .FALSE. 
-         WHERE (cn_sstbias_files(:) /= '') lmask(:) = .TRUE. 
-         jnumsstbias = COUNT(lmask) 
-         lmask(:) = .FALSE. 
-      ENDIF      
-
-      IF ( nproftypes == 0 .AND. nsurftypes == 0 ) THEN
-         IF(lwp) WRITE(numout,cform_war)
-         IF(lwp) WRITE(numout,*) ' ln_diaobs is set to true, but all obs operator logical flags', &
-            &                    ' ln_t3d, ln_s3d, ln_sla, ln_sst, ln_sic, ln_vel3d', &
-            &                    ' are set to .FALSE. so turning off calls to dia_obs'
-         nwarn = nwarn + 1
-         ln_diaobs = .FALSE.
-         RETURN
-      ENDIF
-
-      IF ( nproftypes > 0 ) THEN
-
-         ALLOCATE( cobstypesprof(nproftypes) )
-         ALLOCATE( ifilesprof(nproftypes) )
-         ALLOCATE( clproffiles(nproftypes,jpmaxnfiles) )
-
-         jtype = 0
-         IF (ln_t3d .OR. ln_s3d) THEN
-            jtype = jtype + 1
-            clproffiles(jtype,:) = cn_profbfiles(:)
-            cobstypesprof(jtype) = 'prof  '
-            ifilesprof(jtype) = 0
-            DO jfile = 1, jpmaxnfiles
-               IF ( trim(clproffiles(jtype,jfile)) /= '' ) &
-                  ifilesprof(jtype) = ifilesprof(jtype) + 1
-            END DO
-         ENDIF
-         IF (ln_vel3d) THEN
-            jtype = jtype + 1
-            clproffiles(jtype,:) = cn_velfbfiles(:)
-            cobstypesprof(jtype) = 'vel   '
-            ifilesprof(jtype) = 0
-            DO jfile = 1, jpmaxnfiles
-               IF ( trim(clproffiles(jtype,jfile)) /= '' ) &
-                  ifilesprof(jtype) = ifilesprof(jtype) + 1
-            END DO
-         ENDIF
-
-      ENDIF
-
-      IF ( nsurftypes > 0 ) THEN
-
-         ALLOCATE( cobstypessurf(nsurftypes) )
-         ALLOCATE( ifilessurf(nsurftypes) )
-         ALLOCATE( clsurffiles(nsurftypes, jpmaxnfiles) )
-
-         jtype = 0
-         IF (ln_sla) THEN
-            jtype = jtype + 1
-            clsurffiles(jtype,:) = cn_slafbfiles(:)
-            cobstypessurf(jtype) = 'sla   '
-            ifilessurf(jtype) = 0
-            DO jfile = 1, jpmaxnfiles
-               IF ( trim(clsurffiles(jtype,jfile)) /= '' ) &
-                  ifilessurf(jtype) = ifilessurf(jtype) + 1
-            END DO
-         ENDIF
-         IF (ln_sst) THEN
-            jtype = jtype + 1
-            clsurffiles(jtype,:) = cn_sstfbfiles(:)
-            cobstypessurf(jtype) = 'sst   '
-            ifilessurf(jtype) = 0
-            DO jfile = 1, jpmaxnfiles
-               IF ( trim(clsurffiles(jtype,jfile)) /= '' ) &
-                  ifilessurf(jtype) = ifilessurf(jtype) + 1
-            END DO
-         ENDIF
-#if defined key_lim3
-         IF (ln_sic) THEN
-            jtype = jtype + 1
-            clsurffiles(jtype,:) = cn_sicfbfiles(:)
-            cobstypessurf(jtype) = 'sic   '
-            ifilessurf(jtype) = 0
-            DO jfile = 1, jpmaxnfiles
-               IF ( trim(clsurffiles(jtype,jfile)) /= '' ) &
-                  ifilessurf(jtype) = ifilessurf(jtype) + 1
-            END DO
-         ENDIF
-#endif
-
-      ENDIF
-
-      !Write namelist settings to stdout
+
       IF(lwp) THEN
          WRITE(numout,*)
@@ -297,7 +243,7 @@
          WRITE(numout,*) '             Logical switch for Sea Ice observations                  ln_sic = ', ln_sic
          WRITE(numout,*) '             Logical switch for velocity observations               ln_vel3d = ', ln_vel3d
-         WRITE(numout,*) '             Global distribution of observations              ln_grid_global = ',ln_grid_global
-         WRITE(numout,*) '             Logical switch for SST bias correction         ln_sstbias = ', ln_sstbias 
-         WRITE(numout,*) '             Logical switch for obs grid search lookup ln_grid_search_lookup = ',ln_grid_search_lookup
+         WRITE(numout,*) '             Logical switch for SSS observations                      ln_sss = ', ln_sss
+         WRITE(numout,*) '             Global distribution of observations              ln_grid_global = ', ln_grid_global
+         WRITE(numout,*) '             Logical switch for obs grid search lookup ln_grid_search_lookup = ', ln_grid_search_lookup
          IF (ln_grid_search_lookup) &
             WRITE(numout,*) '             Grid search lookup file header                cn_gridsearchfile = ', cn_gridsearchfile
@@ -307,34 +253,121 @@
          WRITE(numout,*) '             Type of horizontal interpolation method                nn_2dint = ', nn_2dint
          WRITE(numout,*) '             Rejection of observations near land switch               ln_nea = ', ln_nea
+         WRITE(numout,*) '             Rejection of obs near open bdys                 ln_bound_reject = ', ln_bound_reject
          WRITE(numout,*) '             MSSH correction scheme                                 nn_msshc = ', nn_msshc
          WRITE(numout,*) '             MDT  correction                                      rn_mdtcorr = ', rn_mdtcorr
          WRITE(numout,*) '             MDT cutoff for computed correction                 rn_mdtcutoff = ', rn_mdtcutoff
          WRITE(numout,*) '             Logical switch for alt bias                          ln_altbias = ', ln_altbias
+         WRITE(numout,*) '             Logical switch for sst bias                          ln_sstbias = ', ln_sstbias
          WRITE(numout,*) '             Logical switch for ignoring missing files             ln_ignmis = ', ln_ignmis
          WRITE(numout,*) '             Daily average types                             nn_profdavtypes = ', nn_profdavtypes
          WRITE(numout,*) '             Logical switch for night-time SST obs               ln_sstnight = ', ln_sstnight
-         WRITE(numout,*) '          Number of profile obs types: ',nproftypes
-
-         IF ( nproftypes > 0 ) THEN
-            DO jtype = 1, nproftypes
-               DO jfile = 1, ifilesprof(jtype)
-                  WRITE(numout,'(1X,2A)') '             '//cobstypesprof(jtype)//' input observation file names  = ', &
-                     TRIM(clproffiles(jtype,jfile))
-               END DO
-            END DO
+      ENDIF
+      !-----------------------------------------------------------------------
+      ! Set up list of observation types to be used
+      ! and the files associated with each type
+      !-----------------------------------------------------------------------
+
+      nproftypes = COUNT( (/ln_t3d .OR. ln_s3d, ln_vel3d /) )
+      nsurftypes = COUNT( (/ln_sla, ln_sst, ln_sic, ln_sss /) )
+
+      IF (ln_sstbias) THEN 
+         lmask(:) = .FALSE. 
+         WHERE (cn_sstbiasfiles(:) /= '') lmask(:) = .TRUE. 
+         jnumsstbias = COUNT(lmask) 
+         lmask(:) = .FALSE. 
+      ENDIF      
+
+      IF ( nproftypes == 0 .AND. nsurftypes == 0 ) THEN
+         IF(lwp) WRITE(numout,cform_war)
+         IF(lwp) WRITE(numout,*) ' ln_diaobs is set to true, but all obs operator logical flags', &
+            &                    ' ln_t3d, ln_s3d, ln_sla, ln_sst, ln_sic, ln_vel3d', &
+            &                    ' are set to .FALSE. so turning off calls to dia_obs'
+         nwarn = nwarn + 1
+         ln_diaobs = .FALSE.
+         RETURN
+      ENDIF
+
+      IF ( nproftypes > 0 ) THEN
+
+         ALLOCATE( cobstypesprof(nproftypes) )
+         ALLOCATE( ifilesprof(nproftypes) )
+         ALLOCATE( clproffiles(nproftypes,jpmaxnfiles) )
+
+         jtype = 0
+         IF (ln_t3d .OR. ln_s3d) THEN
+            jtype = jtype + 1
+            CALL obs_settypefiles( nproftypes, jpmaxnfiles, jtype, 'prof  ', &
+               &                   cn_profbfiles, ifilesprof, cobstypesprof, clproffiles )
          ENDIF
-
-         WRITE(numout,*)'          Number of surface obs types: ',nsurftypes
-         IF ( nsurftypes > 0 ) THEN
-            DO jtype = 1, nsurftypes
-               DO jfile = 1, ifilessurf(jtype)
-                  WRITE(numout,'(1X,2A)') '             '//cobstypessurf(jtype)//' input observation file names  = ', &
-                     TRIM(clsurffiles(jtype,jfile))
-               END DO
-            END DO
+         IF (ln_vel3d) THEN
+            jtype = jtype + 1
+            CALL obs_settypefiles( nproftypes, jpmaxnfiles, jtype, 'vel   ', &
+               &                   cn_velfbfiles, ifilesprof, cobstypesprof, clproffiles )
          ENDIF
-         WRITE(numout,*) '~~~~~~~~~~~~'
-
-      ENDIF
+
+      ENDIF
+
+      IF ( nsurftypes > 0 ) THEN
+
+         ALLOCATE( cobstypessurf(nsurftypes) )
+         ALLOCATE( ifilessurf(nsurftypes) )
+         ALLOCATE( clsurffiles(nsurftypes, jpmaxnfiles) )
+         ALLOCATE(n2dintsurf(nsurftypes))
+         ALLOCATE(zavglamscl(nsurftypes))
+         ALLOCATE(zavgphiscl(nsurftypes))
+         ALLOCATE(lfpindegs(nsurftypes))
+         ALLOCATE(llnightav(nsurftypes))
+
+         jtype = 0
+         IF (ln_sla) THEN
+            jtype = jtype + 1
+            CALL obs_settypefiles( nsurftypes, jpmaxnfiles, jtype, 'sla   ', &
+               &                   cn_slafbfiles, ifilessurf, cobstypessurf, clsurffiles )
+            CALL obs_setinterpopts( nsurftypes, jtype, 'sla   ',      &
+               &                  nn_2dint, nn_2dint_sla,             &
+               &                  rn_sla_avglamscl, rn_sla_avgphiscl, &
+               &                  ln_sla_fp_indegs, .FALSE.,          &
+               &                  n2dintsurf, zavglamscl, zavgphiscl, &
+               &                  lfpindegs, llnightav )
+         ENDIF
+         IF (ln_sst) THEN
+            jtype = jtype + 1
+            CALL obs_settypefiles( nsurftypes, jpmaxnfiles, jtype, 'sst   ', &
+               &                   cn_sstfbfiles, ifilessurf, cobstypessurf, clsurffiles )
+            CALL obs_setinterpopts( nsurftypes, jtype, 'sst   ',      &
+               &                  nn_2dint, nn_2dint_sst,             &
+               &                  rn_sst_avglamscl, rn_sst_avgphiscl, &
+               &                  ln_sst_fp_indegs, ln_sstnight,      &
+               &                  n2dintsurf, zavglamscl, zavgphiscl, &
+               &                  lfpindegs, llnightav )
+         ENDIF
+#if defined key_lim3 || defined key_cice
+         IF (ln_sic) THEN
+            jtype = jtype + 1
+            CALL obs_settypefiles( nsurftypes, jpmaxnfiles, jtype, 'sic   ', &
+               &                   cn_sicfbfiles, ifilessurf, cobstypessurf, clsurffiles )
+            CALL obs_setinterpopts( nsurftypes, jtype, 'sic   ',      &
+               &                  nn_2dint, nn_2dint_sic,             &
+               &                  rn_sic_avglamscl, rn_sic_avgphiscl, &
+               &                  ln_sic_fp_indegs, .FALSE.,          &
+               &                  n2dintsurf, zavglamscl, zavgphiscl, &
+               &                  lfpindegs, llnightav )
+         ENDIF
+#endif
+         IF (ln_sss) THEN
+            jtype = jtype + 1
+            CALL obs_settypefiles( nsurftypes, jpmaxnfiles, jtype, 'sss   ', &
+               &                   cn_sssfbfiles, ifilessurf, cobstypessurf, clsurffiles )
+            CALL obs_setinterpopts( nsurftypes, jtype, 'sss   ',      &
+               &                  nn_2dint, nn_2dint_sss,             &
+               &                  rn_sss_avglamscl, rn_sss_avgphiscl, &
+               &                  ln_sss_fp_indegs, .FALSE.,          &
+               &                  n2dintsurf, zavglamscl, zavgphiscl, &
+               &                  lfpindegs, llnightav )
+         ENDIF
+
+      ENDIF
+
+
 
       !-----------------------------------------------------------------------
@@ -356,5 +389,5 @@
       ENDIF
 
-      IF ( ( nn_2dint < 0 ) .OR. ( nn_2dint > 4 ) ) THEN
+      IF ( ( nn_2dint < 0 ) .OR. ( nn_2dint > 6 ) ) THEN
          CALL ctl_stop(' Choice of horizontal (2D) interpolation method', &
             &                    ' is not available')
@@ -421,5 +454,6 @@
                &               jpi, jpj, jpk, &
                &               zmask1, zglam1, zgphi1, zmask2, zglam2, zgphi2,  &
-               &               ln_nea, kdailyavtypes = nn_profdavtypes )
+               &               ln_nea, ln_bound_reject, &
+               &               kdailyavtypes = nn_profdavtypes )
 
          END DO
@@ -440,7 +474,7 @@
             nvarssurf(jtype) = 1
             nextrsurf(jtype) = 0
-            llnightav = .FALSE.
+            llnightav(jtype) = .FALSE.
             IF ( TRIM(cobstypessurf(jtype)) == 'sla' ) nextrsurf(jtype) = 2
-            IF ( TRIM(cobstypessurf(jtype)) == 'sst' ) llnightav = ln_sstnight
+            IF ( TRIM(cobstypessurf(jtype)) == 'sst' ) llnightav(jtype) = ln_sstnight
 
             !Read in surface obs types
@@ -448,20 +482,27 @@
                &               clsurffiles(jtype,1:ifilessurf(jtype)), &
                &               nvarssurf(jtype), nextrsurf(jtype), nitend-nit000+2, &
-               &               rn_dobsini, rn_dobsend, ln_ignmis, .FALSE., llnightav )
-         
-         
-            CALL obs_pre_surf( surfdata(jtype), surfdataqc(jtype), ln_nea )
+               &               rn_dobsini, rn_dobsend, ln_ignmis, .FALSE., llnightav(jtype) )
+
+            CALL obs_pre_surf( surfdata(jtype), surfdataqc(jtype), ln_nea, ln_bound_reject )
 
             IF ( TRIM(cobstypessurf(jtype)) == 'sla' ) THEN
-               CALL obs_rea_mdt( surfdataqc(jtype), nn_2dint )
-               IF ( ln_altbias ) CALL obs_rea_altbias ( surfdataqc(jtype), nn_2dint, cn_altbiasfile )
+               CALL obs_rea_mdt( surfdataqc(jtype), n2dintsurf(jtype) )
+               IF ( ln_altbias ) &
+                  & CALL obs_rea_altbias ( surfdataqc(jtype), n2dintsurf(jtype), cn_altbiasfile )
             ENDIF
+
             IF ( TRIM(cobstypessurf(jtype)) == 'sst' .AND. ln_sstbias ) THEN
-               !Read in bias field and correct SST.
-               IF ( jnumsstbias == 0 ) CALL ctl_stop("ln_sstbias set,"// &
-                                                     "  but no bias"// &
-                                                     " files to read in")   
-                  CALL obs_app_sstbias( surfdataqc(jtype), nn_2dint, &
-                                        jnumsstbias, cn_sstbias_files(1:jnumsstbias) )
+               jnumsstbias = 0
+               DO jfile = 1, jpmaxnfiles
+                  IF ( TRIM(cn_sstbiasfiles(jfile)) /= '' ) &
+                     &  jnumsstbias = jnumsstbias + 1
+               END DO
+               IF ( jnumsstbias == 0 ) THEN
+                  CALL ctl_stop("ln_sstbias set but no bias files to read in")    
+               ENDIF
+
+               CALL obs_app_sstbias( surfdataqc(jtype), n2dintsurf(jtype), & 
+                  &                  jnumsstbias, cn_sstbiasfiles(1:jnumsstbias) ) 
+
             ENDIF
          END DO
@@ -512,4 +553,8 @@
       USE ice    , ONLY : at_i                ! LIM3 Ice model variables
 #endif
+#if defined key_cice
+      USE sbc_oce, ONLY : fr_i     ! ice fraction
+#endif
+
       IMPLICIT NONE
 
@@ -528,5 +573,6 @@
          & zprofmask2              ! Mask associated with zprofvar2
       REAL(wp), POINTER, DIMENSION(:,:) :: &
-         & zsurfvar                ! Model values equivalent to surface ob.
+         & zsurfvar, &             ! Model values equivalent to surface ob.
+         & zsurfmask               ! Mask associated with surface variable
       REAL(wp), POINTER, DIMENSION(:,:) :: &
          & zglam1,    &            ! Model longitudes for prof variable 1
@@ -534,8 +580,4 @@
          & zgphi1,    &            ! Model latitudes for prof variable 1
          & zgphi2                  ! Model latitudes for prof variable 2
-#if ! defined key_lim3
-      REAL(wp), POINTER, DIMENSION(:,:) :: at_i
-#endif
-      LOGICAL :: llnightav        ! Logical for calculating night-time average
 
       !Allocate local work arrays
@@ -545,11 +587,9 @@
       CALL wrk_alloc( jpi, jpj, jpk, zprofmask2 )
       CALL wrk_alloc( jpi, jpj, zsurfvar )
+      CALL wrk_alloc( jpi, jpj, zsurfmask )
       CALL wrk_alloc( jpi, jpj, zglam1 )
       CALL wrk_alloc( jpi, jpj, zglam2 )
       CALL wrk_alloc( jpi, jpj, zgphi1 )
       CALL wrk_alloc( jpi, jpj, zgphi2 )
-#if ! defined key_lim3
-      CALL wrk_alloc(jpi,jpj,at_i) 
-#endif
       !-----------------------------------------------------------------------
 
@@ -562,10 +602,4 @@
       idaystp = NINT( rday / rdt )
 
-      !-----------------------------------------------------------------------
-      ! No LIM => at_i == 0.0_wp
-      !-----------------------------------------------------------------------
-#if ! defined key_lim3
-      at_i(:,:) = 0.0_wp
-#endif
       !-----------------------------------------------------------------------
       ! Call the profile and surface observation operators
@@ -595,26 +629,16 @@
                zgphi1(:,:) = gphiu(:,:)
                zgphi2(:,:) = gphiv(:,:)
+            CASE DEFAULT
+               CALL ctl_stop( 'Unknown profile observation type '//TRIM(cobstypesprof(jtype))//' in dia_obs' )
             END SELECT
 
-            IF( ln_zco .OR. ln_zps ) THEN 
-               CALL obs_prof_opt( profdataqc(jtype), kstp, jpi, jpj, jpk,  &
-                  &               nit000, idaystp,                         &
-                  &               zprofvar1, zprofvar2,                    &
-                  &               gdept_1d, zprofmask1, zprofmask2,        &
-                  &               zglam1, zglam2, zgphi1, zgphi2,          &
-                  &               nn_1dint, nn_2dint,                      &
-                  &               kdailyavtypes = nn_profdavtypes )
-            ELSE IF(TRIM(cobstypesprof(jtype)) == 'prof') THEN
-               !TG - THIS NEEDS MODIFICATION TO MATCH SIMPLIFICATION
-               CALL obs_pro_sco_opt( profdataqc(jtype),                    & 
-                  &              kstp, jpi, jpj, jpk, nit000, idaystp,   & 
-                  &              zprofvar1, zprofvar2,                   & 
-                  &              gdept_n(:,:,:), gdepw_n(:,:,:),           &
-                  &              tmask, nn_1dint, nn_2dint,              & 
-                  &              kdailyavtypes = nn_profdavtypes ) 
-            ELSE
-               CALL ctl_stop('DIA_OBS: Generalised vertical interpolation not'// &
-                         'yet working for velocity data (turn off velocity observations')
-            ENDIF
+            CALL obs_prof_opt( profdataqc(jtype), kstp, jpi, jpj, jpk,  &
+               &               nit000, idaystp,                         &
+               &               zprofvar1, zprofvar2,                    &
+               &               gdept_n(:,:,:), gdepw_n(:,:,:),            & 
+               &               zprofmask1, zprofmask2,                  &
+               &               zglam1, zglam2, zgphi1, zgphi2,          &
+               &               nn_1dint, nn_2dint,                      &
+               &               kdailyavtypes = nn_profdavtypes )
 
          END DO
@@ -625,13 +649,15 @@
 
          DO jtype = 1, nsurftypes
+
+            !Defaults which might be changed
+            zsurfmask(:,:) = tmask(:,:,1)
 
             SELECT CASE ( TRIM(cobstypessurf(jtype)) )
             CASE('sst')
                zsurfvar(:,:) = tsn(:,:,1,jp_tem)
-               llnightav = ln_sstnight
             CASE('sla')
                zsurfvar(:,:) = sshn(:,:)
-               llnightav = .FALSE.
-#if defined key_lim3
+            CASE('sss')
+               zsurfvar(:,:) = tsn(:,:,1,jp_sal)
             CASE('sic')
                IF ( kstp == 0 ) THEN
@@ -646,14 +672,21 @@
                   CYCLE
                ELSE
-                  zsurfvar(:,:) = at_i(:,:)
+#if defined key_cice
+                  zsurfvar(:,:) = fr_i(:,:)
+#elif defined key_lim2 || defined key_lim3
+                  zsurfvar(:,:) = 1._wp - frld(:,:)
+#else
+               CALL ctl_stop( ' Trying to run sea-ice observation operator', &
+                  &           ' but no sea-ice model appears to have been defined' )
+#endif
                ENDIF
 
-               llnightav = .FALSE.
-#endif
             END SELECT
 
             CALL obs_surf_opt( surfdataqc(jtype), kstp, jpi, jpj,       &
-               &               nit000, idaystp, zsurfvar, tmask(:,:,1), &
-               &               nn_2dint, llnightav )
+               &               nit000, idaystp, zsurfvar, zsurfmask,    &
+               &               n2dintsurf(jtype), llnightav(jtype),     &
+               &               zavglamscl(jtype), zavgphiscl(jtype),     &
+               &               lfpindegs(jtype) )
 
          END DO
@@ -666,11 +699,9 @@
       CALL wrk_dealloc( jpi, jpj, jpk, zprofmask2 )
       CALL wrk_dealloc( jpi, jpj, zsurfvar )
+      CALL wrk_dealloc( jpi, jpj, zsurfmask )
       CALL wrk_dealloc( jpi, jpj, zglam1 )
       CALL wrk_dealloc( jpi, jpj, zglam2 )
       CALL wrk_dealloc( jpi, jpj, zgphi1 )
       CALL wrk_dealloc( jpi, jpj, zgphi2 )
-#if ! defined key_lim3
-      CALL wrk_dealloc(jpi,jpj,at_i)
-#endif
 
    END SUBROUTINE dia_obs
@@ -789,5 +820,6 @@
 
       IF ( nsurftypes > 0 ) &
-         &   DEALLOCATE( cobstypessurf, surfdata, surfdataqc, nvarssurf, nextrsurf )
+         &   DEALLOCATE( cobstypessurf, surfdata, surfdataqc, nvarssurf, nextrsurf, &
+         &               n2dintsurf, zavglamscl, zavgphiscl, lfpindegs, llnightav )
 
    END SUBROUTINE dia_obs_dealloc
@@ -938,3 +970,118 @@
    END SUBROUTINE fin_date
    
+    SUBROUTINE obs_settypefiles( ntypes, jpmaxnfiles, jtype, ctypein, &
+       &                         cfilestype, ifiles, cobstypes, cfiles )
+
+    INTEGER, INTENT(IN) :: ntypes      ! Total number of obs types
+    INTEGER, INTENT(IN) :: jpmaxnfiles ! Maximum number of files allowed for each type
+    INTEGER, INTENT(IN) :: jtype       ! Index of the current type of obs
+    INTEGER, DIMENSION(ntypes), INTENT(INOUT) :: &
+       &                   ifiles      ! Out appended number of files for this type
+
+    CHARACTER(len=6), INTENT(IN) :: ctypein 
+    CHARACTER(len=128), DIMENSION(jpmaxnfiles), INTENT(IN) :: &
+       &                   cfilestype  ! In list of files for this obs type
+    CHARACTER(len=6), DIMENSION(ntypes), INTENT(INOUT) :: &
+       &                   cobstypes   ! Out appended list of obs types
+    CHARACTER(len=128), DIMENSION(ntypes, jpmaxnfiles), INTENT(INOUT) :: &
+       &                   cfiles      ! Out appended list of files for all types
+
+    !Local variables
+    INTEGER :: jfile
+
+    cfiles(jtype,:) = cfilestype(:)
+    cobstypes(jtype) = ctypein
+    ifiles(jtype) = 0
+    DO jfile = 1, jpmaxnfiles
+       IF ( trim(cfiles(jtype,jfile)) /= '' ) &
+                 ifiles(jtype) = ifiles(jtype) + 1
+    END DO
+
+    IF ( ifiles(jtype) == 0 ) THEN
+         CALL ctl_stop( 'Logical for observation type '//TRIM(ctypein)//   &
+            &           ' set to true but no files available to read' )
+    ENDIF
+
+    IF(lwp) THEN    
+       WRITE(numout,*) '             '//cobstypes(jtype)//' input observation file names:'
+       DO jfile = 1, ifiles(jtype)
+          WRITE(numout,*) '                '//TRIM(cfiles(jtype,jfile))
+       END DO
+    ENDIF
+
+    END SUBROUTINE obs_settypefiles
+
+    SUBROUTINE obs_setinterpopts( ntypes, jtype, ctypein,             &
+               &                  n2dint_default, n2dint_type,        &
+               &                  zavglamscl_type, zavgphiscl_type,   &
+               &                  lfp_indegs_type, lavnight_type,     &
+               &                  n2dint, zavglamscl, zavgphiscl,     &
+               &                  lfpindegs, lavnight )
+
+    INTEGER, INTENT(IN)  :: ntypes             ! Total number of obs types
+    INTEGER, INTENT(IN)  :: jtype              ! Index of the current type of obs
+    INTEGER, INTENT(IN)  :: n2dint_default     ! Default option for interpolation type
+    INTEGER, INTENT(IN)  :: n2dint_type        ! Option for interpolation type
+    REAL(wp), INTENT(IN) :: &
+       &                    zavglamscl_type, & !E/W diameter of obs footprint for this type
+       &                    zavgphiscl_type    !N/S diameter of obs footprint for this type
+    LOGICAL, INTENT(IN)  :: lfp_indegs_type    !T=> footprint in degrees, F=> in metres
+    LOGICAL, INTENT(IN)  :: lavnight_type      !T=> obs represent night time average
+    CHARACTER(len=6), INTENT(IN) :: ctypein 
+
+    INTEGER, DIMENSION(ntypes), INTENT(INOUT) :: &
+       &                    n2dint 
+    REAL(wp), DIMENSION(ntypes), INTENT(INOUT) :: &
+       &                    zavglamscl, zavgphiscl
+    LOGICAL, DIMENSION(ntypes), INTENT(INOUT) :: &
+       &                    lfpindegs, lavnight
+
+    lavnight(jtype) = lavnight_type
+
+    IF ( (n2dint_type >= 1) .AND. (n2dint_type <= 6) ) THEN
+       n2dint(jtype) = n2dint_type
+    ELSE
+       n2dint(jtype) = n2dint_default
+    ENDIF
+
+    ! For averaging observation footprints set options for size of footprint 
+    IF ( (n2dint(jtype) > 4) .AND. (n2dint(jtype) <= 6) ) THEN
+       IF ( zavglamscl_type > 0._wp ) THEN
+          zavglamscl(jtype) = zavglamscl_type
+       ELSE
+          CALL ctl_stop( 'Incorrect value set for averaging footprint '// &
+                         'scale (zavglamscl) for observation type '//TRIM(ctypein) )      
+       ENDIF
+
+       IF ( zavgphiscl_type > 0._wp ) THEN
+          zavgphiscl(jtype) = zavgphiscl_type
+       ELSE
+          CALL ctl_stop( 'Incorrect value set for averaging footprint '// &
+                         'scale (zavgphiscl) for observation type '//TRIM(ctypein) )      
+       ENDIF
+
+       lfpindegs(jtype) = lfp_indegs_type 
+
+    ENDIF
+
+    ! Write out info 
+    IF(lwp) THEN
+       IF ( n2dint(jtype) <= 4 ) THEN
+          WRITE(numout,*) '             '//TRIM(ctypein)// &
+             &            ' model counterparts will be interpolated horizontally'
+       ELSE IF ( n2dint(jtype) <= 6 ) THEN
+          WRITE(numout,*) '             '//TRIM(ctypein)// &
+             &            ' model counterparts will be averaged horizontally'
+          WRITE(numout,*) '             '//'    with E/W scale: ',zavglamscl(jtype)
+          WRITE(numout,*) '             '//'    with N/S scale: ',zavgphiscl(jtype)
+          IF ( lfpindegs(jtype) ) THEN
+              WRITE(numout,*) '             '//'    (in degrees)'
+          ELSE
+              WRITE(numout,*) '             '//'    (in metres)'
+          ENDIF
+       ENDIF
+    ENDIF
+
+    END SUBROUTINE obs_setinterpopts
+
 END MODULE diaobs
