Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 5658)
+++ branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 5659)
@@ -23,9 +23,6 @@
    USE obs_fbm, ONLY: ln_cl4    ! Class 4 diagnostic switch
    USE obs_read_prof            ! Reading and allocation of observations (Coriolis)
-   USE obs_read_sla             ! Reading and allocation of SLA observations  
-   USE obs_read_sst             ! Reading and allocation of SST observations  
+   USE obs_read_surf            ! Reading and allocation of SLA observations  
    USE obs_readmdt              ! Reading and allocation of MDT for SLA.
-   USE obs_read_seaice          ! Reading and allocation of Sea Ice observations  
-   USE obs_read_vel             ! Reading and allocation of velocity component observations
    USE obs_prep                 ! Preparation of obs. (grid search etc).
    USE obs_oper                 ! Observation operators
@@ -34,9 +31,5 @@
    USE obs_read_altbias         ! Bias treatment for altimeter
    USE obs_profiles_def         ! Profile data definitions
-   USE obs_profiles             ! Profile data storage
    USE obs_surf_def             ! Surface data definitions
-   USE obs_sla                  ! SLA data storage
-   USE obs_sst                  ! SST data storage
-   USE obs_seaice               ! Sea Ice data storage
    USE obs_types                ! Definitions for observation types
    USE mpp_map                  ! MPP mapping
@@ -63,21 +56,8 @@
    LOGICAL, PUBLIC :: ln_t3d         !: Logical switch for temperature profiles
    LOGICAL, PUBLIC :: ln_s3d         !: Logical switch for salinity profiles
-   LOGICAL, PUBLIC :: ln_ena         !: Logical switch for the ENACT data set
-   LOGICAL, PUBLIC :: ln_cor         !: Logical switch for the Coriolis data set
-   LOGICAL, PUBLIC :: ln_profb       !: Logical switch for profile feedback datafiles
    LOGICAL, PUBLIC :: ln_sla         !: Logical switch for sea level anomalies 
-   LOGICAL, PUBLIC :: ln_sladt       !: Logical switch for SLA from AVISO files
-   LOGICAL, PUBLIC :: ln_slafb       !: Logical switch for SLA from feedback files
    LOGICAL, PUBLIC :: ln_sst         !: Logical switch for sea surface temperature
-   LOGICAL, PUBLIC :: ln_reysst      !: Logical switch for Reynolds sea surface temperature
-   LOGICAL, PUBLIC :: ln_ghrsst      !: Logical switch for GHRSST data
-   LOGICAL, PUBLIC :: ln_sstfb       !: Logical switch for SST from feedback files
    LOGICAL, PUBLIC :: ln_seaice      !: Logical switch for sea ice concentration
    LOGICAL, PUBLIC :: ln_vel3d       !: Logical switch for velocity component (u,v) observations
-   LOGICAL, PUBLIC :: ln_velavcur    !: Logical switch for raw daily averaged netCDF current meter vel. data 
-   LOGICAL, PUBLIC :: ln_velhrcur    !: Logical switch for raw high freq netCDF current meter vel. data 
-   LOGICAL, PUBLIC :: ln_velavadcp   !: Logical switch for raw daily averaged netCDF ADCP vel. data 
-   LOGICAL, PUBLIC :: ln_velhradcp   !: Logical switch for raw high freq netCDF ADCP vel. data 
-   LOGICAL, PUBLIC :: ln_velfb       !: Logical switch for velocities from feedback files
    LOGICAL, PUBLIC :: ln_ssh         !: Logical switch for sea surface height
    LOGICAL, PUBLIC :: ln_sss         !: Logical switch for sea surface salinity
@@ -91,14 +71,29 @@
    REAL(KIND=dp), PUBLIC :: dobsend   !: Observation window end date YYYYMMDD.HHMMSS
   
+   INTEGER, PUBLIC :: numobtypes   !: Number of observation types to read in.
    INTEGER, PUBLIC :: n1dint       !: Vertical interpolation method
    INTEGER, PUBLIC :: n2dint       !: Horizontal interpolation method 
-
+   INTEGER, DIMENSION(:), ALLOCATABLE :: nvarsprof !Number of profile variables
+   INTEGER, DIMENSION(:), ALLOCATABLE :: nextrprof !Number of profile extra variables
+   INTEGER, DIMENSION(:), ALLOCATABLE :: nvarssurf !Number of surface variables
+   INTEGER, DIMENSION(:), ALLOCATABLE :: nextrsurf !Number of surface extra variables
    INTEGER, DIMENSION(imaxavtypes) :: &
-      & endailyavtypes !: ENACT data types which are daily average
-
+      & dailyavtypes !: Data types which are daily average
+
+   TYPE(obs_surf), PUBLIC, POINTER, DIMENSION(:) :: surfdata   ! Initial surface data
+   TYPE(obs_surf), PUBLIC, POINTER, DIMENSION(:) :: surfdataqc ! Surface data after quality control
+   TYPE(obs_prof), PUBLIC, POINTER, DIMENSION(:) :: profdata   ! Initial profile data
+   TYPE(obs_prof), PUBLIC, POINTER, DIMENSION(:) :: profdataqc ! Profile data after quality control
+
+   CHARACTER(len=6),   PUBLIC, DIMENSION(:),   ALLOCATABLE :: obstypesprof
+   CHARACTER(len=6),   PUBLIC, DIMENSION(:),   ALLOCATABLE :: obstypessurf
+
+
+      
    INTEGER, PARAMETER :: MaxNumFiles = 1000
+   
    LOGICAL, DIMENSION(MaxNumFiles) :: &
       & ln_profb_ena, & !: Is the feedback files from ENACT data ?
-   !                    !: If so use endailyavtypes
+   !                    !: If so use dailyavtypes
       & ln_profb_enatim !: Change tim for 820 enact data set.
    
@@ -106,5 +101,5 @@
       & ln_velfb_av   !: Is the velocity feedback files daily average?
    LOGICAL, DIMENSION(:), ALLOCATABLE :: &
-      & ld_enact     !: Profile data is ENACT so use endailyavtypes
+      & ld_enact     !: Profile data is ENACT so use dailyavtypes
    LOGICAL, DIMENSION(:), ALLOCATABLE :: &
       & ld_velav     !: Velocity data is daily averaged
@@ -135,4 +130,5 @@
       !!        !  06-10  (A. Weaver) Cleaning and add controls
       !!        !  07-03  (K. Mogensen) General handling of profiles
+      !!        !  15-02  (M. Martin) Simplification of namelist and code
       !!----------------------------------------------------------------------
 
@@ -140,100 +136,51 @@
 
       !! * Local declarations
-      CHARACTER(len=128) :: enactfiles(MaxNumFiles)
-      CHARACTER(len=128) :: coriofiles(MaxNumFiles)
       CHARACTER(len=128) :: profbfiles(MaxNumFiles)
-      CHARACTER(len=128) :: sstfiles(MaxNumFiles)      
-      CHARACTER(len=128) :: sstfbfiles(MaxNumFiles) 
-      CHARACTER(len=128) :: slafilesact(MaxNumFiles)      
-      CHARACTER(len=128) :: slafilespas(MaxNumFiles)      
+      CHARACTER(len=128) :: sstfbfiles(MaxNumFiles)
       CHARACTER(len=128) :: slafbfiles(MaxNumFiles)
-      CHARACTER(len=128) :: seaicefiles(MaxNumFiles)           
-      CHARACTER(len=128) :: velcurfiles(MaxNumFiles)  
-      CHARACTER(len=128) :: veladcpfiles(MaxNumFiles)    
-      CHARACTER(len=128) :: velavcurfiles(MaxNumFiles)
-      CHARACTER(len=128) :: velhrcurfiles(MaxNumFiles)
-      CHARACTER(len=128) :: velavadcpfiles(MaxNumFiles)
-      CHARACTER(len=128) :: velhradcpfiles(MaxNumFiles)
+      CHARACTER(len=128) :: seaicefbfiles(MaxNumFiles)
       CHARACTER(len=128) :: velfbfiles(MaxNumFiles)
-      CHARACTER(LEN=128) :: reysstname
-      CHARACTER(LEN=12)  :: reysstfmt
       CHARACTER(LEN=128) :: bias_file
       CHARACTER(LEN=20)  :: datestr=" ", timestr=" "
-      NAMELIST/namobs/ln_ena, ln_cor, ln_profb, ln_t3d, ln_s3d,       &
-         &            ln_sla, ln_sladt, ln_slafb,                     &
-         &            ln_ssh, ln_sst, ln_sstfb, ln_sss, ln_nea,       &
-         &            enactfiles, coriofiles, profbfiles,             &
-         &            slafilesact, slafilespas, slafbfiles,           &
-         &            sstfiles, sstfbfiles,                           &
-         &            ln_seaice, seaicefiles,                         &
+
+      NAMELIST/namobs/ln_t3d, ln_s3d, ln_sla, ln_sss, ln_ssh,         &
+         &            ln_sst, ln_seaice, ln_vel3d,                    &
+         &            ln_altbias, ln_nea, ln_grid_global,             &
+         &            ln_grid_search_lookup, ln_cl4,                  &
+         &            ln_ignmis, ln_s_at_t, ln_sstnight,              &
+         &            ln_profb_ena, ln_profb_enatim,                  &
+         &            profbfiles, slafbfiles, sssfbfiles,             &
+         &            sshfbfiles, sstfbfiles, seaicefbfiles,          &
+         &            velfbfiles, bias_file, grid_search_file,        &
          &            dobsini, dobsend, n1dint, n2dint,               &
          &            nmsshc, mdtcorr, mdtcutoff,                     &
-         &            ln_reysst, ln_ghrsst, reysstname, reysstfmt,    &
-         &            ln_sstnight,                                    &
-         &            ln_grid_search_lookup,                          &
-         &            grid_search_file, grid_search_res,              &
-         &            ln_grid_global, bias_file, ln_altbias,          &
-         &            endailyavtypes, ln_s_at_t, ln_profb_ena,        &
-         &            ln_vel3d, ln_velavcur, velavcurfiles,           &
-         &            ln_velhrcur, velhrcurfiles,                     &
-         &            ln_velavadcp, velavadcpfiles,                   &
-         &            ln_velhradcp, velhradcpfiles,                   &
-         &            ln_velfb, velfbfiles, ln_velfb_av,              &
-         &            ln_profb_enatim, ln_ignmis, ln_cl4
-
-      INTEGER :: jprofset
-      INTEGER :: jveloset
-      INTEGER :: jvar
-      INTEGER :: jnumenact
-      INTEGER :: jnumcorio
-      INTEGER :: jnumprofb
-      INTEGER :: jnumslaact
-      INTEGER :: jnumslapas
-      INTEGER :: jnumslafb
-      INTEGER :: jnumsst
-      INTEGER :: jnumsstfb
-      INTEGER :: jnumseaice
-      INTEGER :: jnumvelavcur
-      INTEGER :: jnumvelhrcur  
-      INTEGER :: jnumvelavadcp
-      INTEGER :: jnumvelhradcp   
-      INTEGER :: jnumvelfb
-      INTEGER :: ji
-      INTEGER :: jset
+         &            grid_search_res, dailyavtypes
+
+      INTEGER :: jtype
       INTEGER :: ios                 ! Local integer output status for namelist read
-      LOGICAL :: lmask(MaxNumFiles), ll_u3d, ll_v3d
-
+      INTEGER, DIMENSION(:), ALLOCATABLE :: jnumfilesprof
+      INTEGER, DIMENSION(:), ALLOCATABLE :: jnumfilessurf
+      CHARACTER(len=128), DIMENSION(:,:), ALLOCATABLE :: obsfilesprof
+      CHARACTER(len=128), DIMENSION(:,:), ALLOCATABLE :: obsfilessurf
+      LOGICAL :: lmask(MaxNumFiles)
       !-----------------------------------------------------------------------
       ! Read namelist parameters
       !-----------------------------------------------------------------------
 
-      enactfiles(:) = ''
-      coriofiles(:) = ''
       profbfiles(:) = ''
-      slafilesact(:) = ''
-      slafilespas(:) = ''
       slafbfiles(:) = ''
-      sstfiles(:)   = ''
       sstfbfiles(:) = ''
-      seaicefiles(:) = ''
-      velcurfiles(:) = ''
-      veladcpfiles(:) = ''
-      velavcurfiles(:) = ''
-      velhrcurfiles(:) = ''
-      velavadcpfiles(:) = ''
-      velhradcpfiles(:) = ''
+      seaicefbfiles(:) = ''
       velfbfiles(:) = ''
-      velcurfiles(:) = ''
-      veladcpfiles(:) = ''
-      endailyavtypes(:) = -1
-      endailyavtypes(1) = 820
+      dailyavtypes(:) = -1
+      dailyavtypes(1) = 820
       ln_profb_ena(:) = .FALSE.
       ln_profb_enatim(:) = .TRUE.
       ln_velfb_av(:) = .FALSE.
       ln_ignmis = .FALSE.
-      
+
       CALL ini_date( dobsini )
       CALL fin_date( dobsend )
- 
+
       ! Read Namelist namobs : control observation diagnostics
       REWIND( numnam_ref )              ! Namelist namobs in reference namelist : Diagnostic: control observation
@@ -246,78 +193,65 @@
       IF(lwm) WRITE ( numond, namobs )
 
-      ! Count number of files for each type
-      IF (ln_ena) THEN
-         lmask(:) = .FALSE.
-         WHERE (enactfiles(:) /= '') lmask(:) = .TRUE.
-         jnumenact = COUNT(lmask)
-      ENDIF
-      IF (ln_cor) THEN
-         lmask(:) = .FALSE.
-         WHERE (coriofiles(:) /= '') lmask(:) = .TRUE.
-         jnumcorio = COUNT(lmask)
-      ENDIF
-      IF (ln_profb) THEN
-         lmask(:) = .FALSE.
-         WHERE (profbfiles(:) /= '') lmask(:) = .TRUE.
-         jnumprofb = COUNT(lmask)
-      ENDIF
-      IF (ln_sladt) THEN
-         lmask(:) = .FALSE.
-         WHERE (slafilesact(:) /= '') lmask(:) = .TRUE.
-         jnumslaact = COUNT(lmask)
-         lmask(:) = .FALSE.
-         WHERE (slafilespas(:) /= '') lmask(:) = .TRUE.
-         jnumslapas = COUNT(lmask)
-      ENDIF
-      IF (ln_slafb) THEN
-         lmask(:) = .FALSE.
-         WHERE (slafbfiles(:) /= '') lmask(:) = .TRUE.
-         jnumslafb = COUNT(lmask)
-         lmask(:) = .FALSE.
-      ENDIF
-      IF (ln_ghrsst) THEN
-         lmask(:) = .FALSE.
-         WHERE (sstfiles(:) /= '') lmask(:) = .TRUE.
-         jnumsst = COUNT(lmask)
-      ENDIF      
-      IF (ln_sstfb) THEN
-         lmask(:) = .FALSE.
-         WHERE (sstfbfiles(:) /= '') lmask(:) = .TRUE.
-         jnumsstfb = COUNT(lmask)
-         lmask(:) = .FALSE.
-      ENDIF
-      IF (ln_seaice) THEN
-         lmask(:) = .FALSE.
-         WHERE (seaicefiles(:) /= '') lmask(:) = .TRUE.
-         jnumseaice = COUNT(lmask)
-      ENDIF
-      IF (ln_velavcur) THEN
-         lmask(:) = .FALSE.
-         WHERE (velavcurfiles(:) /= '') lmask(:) = .TRUE.
-         jnumvelavcur = COUNT(lmask)
-      ENDIF
-      IF (ln_velhrcur) THEN
-         lmask(:) = .FALSE.
-         WHERE (velhrcurfiles(:) /= '') lmask(:) = .TRUE.
-         jnumvelhrcur = COUNT(lmask)
-      ENDIF
-      IF (ln_velavadcp) THEN
-         lmask(:) = .FALSE.
-         WHERE (velavadcpfiles(:) /= '') lmask(:) = .TRUE.
-         jnumvelavadcp = COUNT(lmask)
-      ENDIF
-      IF (ln_velhradcp) THEN
-         lmask(:) = .FALSE.
-         WHERE (velhradcpfiles(:) /= '') lmask(:) = .TRUE.
-         jnumvelhradcp = COUNT(lmask)
-      ENDIF
-      IF (ln_velfb) THEN
-         lmask(:) = .FALSE.
-         WHERE (velfbfiles(:) /= '') lmask(:) = .TRUE.
-         jnumvelfb = COUNT(lmask)
-         lmask(:) = .FALSE.
-      ENDIF
-      
-      ! Control print
+      !Set up list of observation types to be used
+      numproftypes = COUNT( (/ln_t3d .OR. ln_s3d, ln_vel3d /) )
+      numsurftypes = COUNT( (/ln_sla, ln_sss, ln_sst, ln_seaice /) )
+      IF ( numproftypes > 0 ) THEN
+      
+         ALLOCATE( obstypesprof(numproftypes) )
+         ALLOCATE( jnumfilesprof(numproftypes) )
+         ALLOCATE( obsfilesprof(numproftypes, MaxNumFiles) )
+      
+         DO jtype = 1, numproftypes
+            IF (ln_t3d .OR. ln_s3d) THEN
+               obsfilesprof(:,jtype) = profbfiles(:)
+               obstypesprof(jtype) = 'prof'
+            ENDIF
+            IF (ln_vel3d) THEN
+               obsfilesprof(:,jtype) = velfbfiles(:)
+               obstypesprof(jtype) = 'vel'
+            ENDIF
+         
+            lmask(:) = .FALSE.
+            WHERE (obsfilesprof(jtype,:) /= '') lmask(:) = .TRUE.
+            jnumfilesprof(jtype) = COUNT(lmask)
+         END DO
+         
+      ENDIF
+      
+      IF ( numsurftypes > 0 ) THEN
+      
+         ALLOCATE( obstypessurf(numsurftypes) )
+         ALLOCATE( jnumfilessurf(numproftypes) )
+         ALLOCATE( obsfilessurf(numsurftypes, MaxNumFiles) )
+         
+         DO jtype = 1, numsurftypes
+            IF (ln_sla) THEN
+               obsfilessurf(:,jtype) = slafbfiles(:)
+               obstypessurf(jtype) = 'sla'
+            ENDIF
+            IF (ln_sss) THEN
+               obsfilessurf(:,jtype) = sssfbfiles(:)
+               obstypessurf(jtype) = 'sss'
+            ENDIF
+            IF (ln_sst) THEN
+               obsfilessurf(:,jtype) = sstfbfiles(:)
+               obstypessurf(jtype) = 'sst'
+            ENDIF
+#if defined key_lim2 || defined key_lim3
+            IF (ln_seaice) THEN
+               obsfilessurf(:,jtype) = seaicefbfiles(:)
+               obstypessurf(jtype) = 'seaice'
+            ENDIF
+#endif
+
+            lmask(:) = .FALSE.
+            WHERE (obsfilessurf(jtype,:) /= '') lmask(:) = .TRUE.
+            jnumfilessurf(jtype) = COUNT(lmask)
+         
+         END DO
+         
+      ENDIF
+
+      !Write namelist settings to stdout
       IF(lwp) THEN
          WRITE(numout,*)
@@ -327,123 +261,17 @@
          WRITE(numout,*) '             Logical switch for T profile observations          ln_t3d = ', ln_t3d
          WRITE(numout,*) '             Logical switch for S profile observations          ln_s3d = ', ln_s3d
-         WRITE(numout,*) '             Logical switch for ENACT insitu data set           ln_ena = ', ln_ena
-         WRITE(numout,*) '             Logical switch for Coriolis insitu data set        ln_cor = ', ln_cor
-         WRITE(numout,*) '             Logical switch for feedback insitu data set      ln_profb = ', ln_profb
          WRITE(numout,*) '             Logical switch for SLA observations                ln_sla = ', ln_sla
-         WRITE(numout,*) '             Logical switch for AVISO SLA data                ln_sladt = ', ln_sladt
-         WRITE(numout,*) '             Logical switch for feedback SLA data             ln_slafb = ', ln_slafb
          WRITE(numout,*) '             Logical switch for SSH observations                ln_ssh = ', ln_ssh
          WRITE(numout,*) '             Logical switch for SST observations                ln_sst = ', ln_sst
-         WRITE(numout,*) '             Logical switch for Reynolds observations        ln_reysst = ', ln_reysst    
-         WRITE(numout,*) '             Logical switch for GHRSST observations          ln_ghrsst = ', ln_ghrsst
-         WRITE(numout,*) '             Logical switch for feedback SST data             ln_sstfb = ', ln_sstfb
          WRITE(numout,*) '             Logical switch for night-time SST obs         ln_sstnight = ', ln_sstnight
          WRITE(numout,*) '             Logical switch for SSS observations                ln_sss = ', ln_sss
          WRITE(numout,*) '             Logical switch for Sea Ice observations         ln_seaice = ', ln_seaice
          WRITE(numout,*) '             Logical switch for velocity observations         ln_vel3d = ', ln_vel3d
-         WRITE(numout,*) '             Logical switch for velocity daily av. cur.    ln_velavcur = ', ln_velavcur
-         WRITE(numout,*) '             Logical switch for velocity high freq. cur.   ln_velhrcur = ', ln_velhrcur
-         WRITE(numout,*) '             Logical switch for velocity daily av. ADCP   ln_velavadcp = ', ln_velavadcp
-         WRITE(numout,*) '             Logical switch for velocity high freq. ADCP  ln_velhradcp = ', ln_velhradcp
-         WRITE(numout,*) '             Logical switch for feedback velocity data        ln_velfb = ', ln_velfb
-         WRITE(numout,*) '             Global distribtion of observations         ln_grid_global = ',ln_grid_global
+         WRITE(numout,*) '             Global distribution of observations        ln_grid_global = ',ln_grid_global
          WRITE(numout,*) &
    '             Logical switch for obs grid search w/lookup table  ln_grid_search_lookup = ',ln_grid_search_lookup
          IF (ln_grid_search_lookup) &
             WRITE(numout,*) '             Grid search lookup file header       grid_search_file = ', grid_search_file
-         IF (ln_ena) THEN
-            DO ji = 1, jnumenact
-               WRITE(numout,'(1X,2A)') '             ENACT input observation file name          enactfiles = ', &
-                  TRIM(enactfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_cor) THEN
-            DO ji = 1, jnumcorio
-               WRITE(numout,'(1X,2A)') '             Coriolis input observation file name       coriofiles = ', &
-                  TRIM(coriofiles(ji))
-            END DO
-         ENDIF
-         IF (ln_profb) THEN
-            DO ji = 1, jnumprofb
-               IF (ln_profb_ena(ji)) THEN
-                  WRITE(numout,'(1X,2A)') '       Enact feedback input observation file name       profbfiles = ', &
-                     TRIM(profbfiles(ji))
-               ELSE
-                  WRITE(numout,'(1X,2A)') '             Feedback input observation file name       profbfiles = ', &
-                     TRIM(profbfiles(ji))
-               ENDIF
-               WRITE(numout,'(1X,2A)') '       Enact feedback input time setting switch    ln_profb_enatim = ', ln_profb_enatim(ji)
-            END DO
-         ENDIF
-         IF (ln_sladt) THEN
-            DO ji = 1, jnumslaact
-               WRITE(numout,'(1X,2A)') '             Active SLA input observation file name    slafilesact = ', &
-                  TRIM(slafilesact(ji))
-            END DO
-            DO ji = 1, jnumslapas
-               WRITE(numout,'(1X,2A)') '             Passive SLA input observation file name   slafilespas = ', &
-                  TRIM(slafilespas(ji))
-            END DO
-         ENDIF
-         IF (ln_slafb) THEN
-            DO ji = 1, jnumslafb
-               WRITE(numout,'(1X,2A)') '             Feedback SLA input observation file name   slafbfiles = ', &
-                  TRIM(slafbfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_ghrsst) THEN
-            DO ji = 1, jnumsst
-               WRITE(numout,'(1X,2A)') '             GHRSST input observation file name           sstfiles = ', &
-                  TRIM(sstfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_sstfb) THEN
-            DO ji = 1, jnumsstfb
-               WRITE(numout,'(1X,2A)') '             Feedback SST input observation file name   sstfbfiles = ', &
-                  TRIM(sstfbfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_seaice) THEN
-            DO ji = 1, jnumseaice
-               WRITE(numout,'(1X,2A)') '             Sea Ice input observation file name       seaicefiles = ', &
-                  TRIM(seaicefiles(ji))
-            END DO
-         ENDIF
-         IF (ln_velavcur) THEN
-            DO ji = 1, jnumvelavcur
-               WRITE(numout,'(1X,2A)') '             Vel. cur. daily av. input file name     velavcurfiles = ', &
-                  TRIM(velavcurfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_velhrcur) THEN
-            DO ji = 1, jnumvelhrcur
-               WRITE(numout,'(1X,2A)') '             Vel. cur. high freq. input file name    velhvcurfiles = ', &
-                  TRIM(velhrcurfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_velavadcp) THEN
-            DO ji = 1, jnumvelavadcp
-               WRITE(numout,'(1X,2A)') '             Vel. ADCP daily av. input file name    velavadcpfiles = ', &
-                  TRIM(velavadcpfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_velhradcp) THEN
-            DO ji = 1, jnumvelhradcp
-               WRITE(numout,'(1X,2A)') '             Vel. ADCP high freq. input file name   velhvadcpfiles = ', &
-                  TRIM(velhradcpfiles(ji))
-            END DO
-         ENDIF
-         IF (ln_velfb) THEN
-            DO ji = 1, jnumvelfb
-               IF (ln_velfb_av(ji)) THEN
-                  WRITE(numout,'(1X,2A)') '             Vel. feedback daily av. input file name    velfbfiles = ', &
-                     TRIM(velfbfiles(ji))
-               ELSE
-                  WRITE(numout,'(1X,2A)') '             Vel. feedback input observation file name  velfbfiles = ', &
-                     TRIM(velfbfiles(ji))
-               ENDIF
-            END DO
-         ENDIF
-         WRITE(numout,*) '             Initial date in window YYYYMMDD.HHMMSS        dobsini = ', dobsini
+         WRITE(numout,*) '             Initial date in window YYYYMMDD.HHMMSS        dobsini = ', dobsin
          WRITE(numout,*) '             Final date in window YYYYMMDD.HHMMSS          dobsend = ', dobsend
          WRITE(numout,*) '             Type of vertical interpolation method          n1dint = ', n1dint
@@ -455,5 +283,25 @@
          WRITE(numout,*) '             Logical switch for alt bias                ln_altbias = ', ln_altbias
          WRITE(numout,*) '             Logical switch for ignoring missing files   ln_ignmis = ', ln_ignmis
-         WRITE(numout,*) '             ENACT daily average types                             = ',endailyavtypes
+         WRITE(numout,*) '             Daily average types                                   = ', dailyavtypes
+
+         IF ( numproftypes > 0 ) THEN
+            DO jtype = 1, numproftypes
+               DO ji = 1, jnumfilesprof(jtype)
+                  WRITE(numout,'(1X,2A)') '             '//obstypesprof(jtype)//' input observation file names  = ', &
+                     TRIM(obsfilesprof(jtype,ji))
+                  IF ( TRIM(obstypesprof(jtype)) == 'prof' ) &
+                     WRITE(numout,'(1X,2A)') '       Enact feedback input time setting switch    ln_profb_enatim = ', ln_profb_enatim(ji)
+               END DO
+            END DO
+         ENDIF
+         
+         IF ( numsurftypes > 0 ) THEN
+            DO jtype = 1, numsurftypes
+               DO ji = 1, jnumfilessurf(jtype)
+                  WRITE(numout,'(1X,2A)') '             '//obstypessurf(jtype)//' input observation file names  = ', &
+                     TRIM(obsfilessurf(jtype,ji))
+               END DO
+            END DO
+         ENDIF
 
       ENDIF
@@ -470,8 +318,5 @@
       ! Parameter control
 #if defined key_diaobs
-      IF ( ( .NOT. ln_t3d ).AND.( .NOT. ln_s3d ).AND.( .NOT. ln_sla ).AND. &
-         & ( .NOT. ln_vel3d ).AND.                                         &
-         & ( .NOT. ln_ssh ).AND.( .NOT. ln_sst ).AND.( .NOT. ln_sss ).AND. &
-         & ( .NOT. ln_seaice ).AND.( .NOT. ln_vel3d ) ) THEN
+      IF ( numobtypes == 0 ) THEN
          IF(lwp) WRITE(numout,cform_war)
          IF(lwp) WRITE(numout,*) ' key_diaobs is activated but logical flags', &
@@ -494,475 +339,71 @@
       ! Depending on switches read the various observation types
       !-----------------------------------------------------------------------
-      !  - Temperature/salinity profiles
-
-      IF ( ln_t3d .OR. ln_s3d ) THEN
-
-         ! Set the number of variables for profiles to 2 (T and S)
-         nprofvars = 2
-         ! Set the number of extra variables for profiles to 1 (insitu temp).
-         nprofextr = 1
-
-         ! Count how may insitu data sets we have and allocate data.
-         jprofset = 0
-         IF ( ln_ena ) jprofset = jprofset + 1
-         IF ( ln_cor ) jprofset = jprofset + 1
-         IF ( ln_profb ) jprofset = jprofset + jnumprofb
-         nprofsets = jprofset
-         IF ( nprofsets > 0 ) THEN
-            ALLOCATE(ld_enact(nprofsets))
-            ALLOCATE(profdata(nprofsets))
-            ALLOCATE(prodatqc(nprofsets))
-         ENDIF
-
-         jprofset = 0
-          
-         ! ENACT insitu data
-
-         IF ( ln_ena ) THEN
-
-            jprofset = jprofset + 1
+      
+      IF ( numproftypes > 0 ) THEN
+      
+         ALLOCATE(profdata(numproftypes))
+         ALLOCATE(profdataqc(numproftypes))
+         ALLOCATE(nvarsprof(numproftypes))
+         ALLOCATE(nextrprof(numproftypes))
             
-            ld_enact(jprofset) = .TRUE.
-
-            CALL obs_rea_pro_dri( 1, profdata(jprofset),          &
-               &                  jnumenact, enactfiles(1:jnumenact), &
-               &                  nprofvars, nprofextr,        &
-               &                  nitend-nit000+2,             &
-               &                  dobsini, dobsend, ln_t3d, ln_s3d, &
-               &                  ln_ignmis, ln_s_at_t, .TRUE., .FALSE., &
-               &                  kdailyavtypes = endailyavtypes )
-
-            DO jvar = 1, 2
-
-               CALL obs_prof_staend( profdata(jprofset), jvar )
-
+         DO jtype = 1, numproftypes
+      
+            nvarsprof(jtype) = 2
+            IF ( TRIM(obstypesprof(jtype)) == 'prof' ) nextrprof(jtype) = 1
+            IF ( TRIM(obstypesprof(jtype)) == 'vel' )  nextrprof(jtype) = 2
+
+            !Read in profile or velocity obs types
+            CALL obs_rea_prof( profdata(jtype),          &
+               &               jnumfilesprof(jtype),       &
+               &               obsfilesprof(jtype,1:jnumfilesprof(jtype)), &
+               &               nvarsprof(jtype), nextrprof(jtype), nitend-nit000+2,             &
+               &               dobsini, dobsend, ln_t3d, ln_s3d, &
+               &               ln_ignmis, ln_s_at_t, .TRUE., .FALSE., &
+               &               kdailyavtypes = dailyavtypes )
+            
+            DO jvar = 1, nvars
+               CALL obs_prof_staend( profdata(jtype), jvar )
             END DO
-
-            CALL obs_pre_pro( profdata(jprofset), prodatqc(jprofset),   &
+         
+            CALL obs_pre_prof( profdata(jtype), profdataqc(jtype),   &
                &              ln_t3d, ln_s3d, ln_nea, &
-               &              kdailyavtypes=endailyavtypes )
-            
-         ENDIF
-
-         ! Coriolis insitu data
-
-         IF ( ln_cor ) THEN
-           
-            jprofset = jprofset + 1
-
-            ld_enact(jprofset) = .FALSE.
-
-            CALL obs_rea_pro_dri( 2, profdata(jprofset),          &
-               &                  jnumcorio, coriofiles(1:jnumcorio), &
-               &                  nprofvars, nprofextr,        &
-               &                  nitend-nit000+2,             &
-               &                  dobsini, dobsend, ln_t3d, ln_s3d, &
-               &                  ln_ignmis, ln_s_at_t, .FALSE., .FALSE. )
-
-            DO jvar = 1, 2
-
-               CALL obs_prof_staend( profdata(jprofset), jvar )
-
-            END DO
-
-            CALL obs_pre_pro( profdata(jprofset), prodatqc(jprofset),   &
-                 &            ln_t3d, ln_s3d, ln_nea )
-            
-         ENDIF
- 
-         ! Feedback insitu data
-
-         IF ( ln_profb ) THEN
-           
-            DO jset = 1, jnumprofb
-               
-               jprofset = jprofset + 1
-               ld_enact (jprofset) = ln_profb_ena(jset)
-
-               CALL obs_rea_pro_dri( 0, profdata(jprofset),          &
-                  &                  1, profbfiles(jset:jset), &
-                  &                  nprofvars, nprofextr,        &
-                  &                  nitend-nit000+2,             &
-                  &                  dobsini, dobsend, ln_t3d, ln_s3d, &
-                  &                  ln_ignmis, ln_s_at_t, &
-                  &                  ld_enact(jprofset).AND.&
-                  &                  ln_profb_enatim(jset), &
-                  &                  .FALSE., kdailyavtypes = endailyavtypes )
-               
-               DO jvar = 1, 2
-                  
-                  CALL obs_prof_staend( profdata(jprofset), jvar )
-                  
-               END DO
-               
-               IF ( ld_enact(jprofset) ) THEN
-                  CALL obs_pre_pro( profdata(jprofset), prodatqc(jprofset),   &
-                     &              ln_t3d, ln_s3d, ln_nea, &
-                     &              kdailyavtypes = endailyavtypes )
-               ELSE
-                  CALL obs_pre_pro( profdata(jprofset), prodatqc(jprofset),   &
-                     &              ln_t3d, ln_s3d, ln_nea )
-               ENDIF
-               
-            END DO
-
-         ENDIF
-
-      ENDIF
-
-      !  - Sea level anomalies
-      IF ( ln_sla ) THEN
-        ! Set the number of variables for sla to 1
-         nslavars = 1
-
-         ! Set the number of extra variables for sla to 2
-         nslaextr = 2
-         
-         ! Set the number of sla data sets to 2
-         nslasets = 0
-         IF ( ln_sladt ) THEN
-            nslasets = nslasets + 2
-         ENDIF
-         IF ( ln_slafb ) THEN
-            nslasets = nslasets + jnumslafb
-         ENDIF
-         
-         ALLOCATE(sladata(nslasets))
-         ALLOCATE(sladatqc(nslasets))
-         sladata(:)%nsurf=0
-         sladatqc(:)%nsurf=0
-
-         nslasets = 0
-
-         ! AVISO SLA data
-
-         IF ( ln_sladt ) THEN
-
-            ! Active SLA observations
-            
-            nslasets = nslasets + 1
-            
-            CALL obs_rea_sla( 1, sladata(nslasets), jnumslaact, &
-               &              slafilesact(1:jnumslaact), &
-               &              nslavars, nslaextr, nitend-nit000+2, &
-               &              dobsini, dobsend, ln_ignmis, .FALSE. )
-            CALL obs_pre_sla( sladata(nslasets), sladatqc(nslasets), &
-               &              ln_sla, ln_nea )
-            
-            ! Passive SLA observations
-            
-            nslasets = nslasets + 1
-            
-            CALL obs_rea_sla( 1, sladata(nslasets), jnumslapas, &
-               &              slafilespas(1:jnumslapas), &
-               &              nslavars, nslaextr, nitend-nit000+2, &
-               &              dobsini, dobsend, ln_ignmis, .FALSE. )
-            
-            CALL obs_pre_sla( sladata(nslasets), sladatqc(nslasets), &
-               &              ln_sla, ln_nea )
-
-         ENDIF
-         
-         ! Feedback SLA data
-
-         IF ( ln_slafb ) THEN
-
-            DO jset = 1, jnumslafb
-            
-               nslasets = nslasets + 1
-            
-               CALL obs_rea_sla( 0, sladata(nslasets), 1, &
-                  &              slafbfiles(jset:jset), &
-                  &              nslavars, nslaextr, nitend-nit000+2, &
-                  &              dobsini, dobsend, ln_ignmis, .FALSE. )
-               CALL obs_pre_sla( sladata(nslasets), sladatqc(nslasets), &
-                  &              ln_sla, ln_nea )
-
-            END DO               
-
-         ENDIF
-         
-         CALL obs_rea_mdt( nslasets, sladatqc, n2dint )
-            
-         ! read in altimeter bias
-         
-         IF ( ln_altbias ) THEN     
-            CALL obs_rea_altbias ( nslasets, sladatqc, n2dint, bias_file )
-         ENDIF
-     
-      ENDIF
-
-      !  - Sea surface height
-      IF ( ln_ssh ) THEN
-         IF(lwp) WRITE(numout,*) ' SSH currently not available'
-      ENDIF
-
-      !  - Sea surface temperature
-      IF ( ln_sst ) THEN
-
-         ! Set the number of variables for sst to 1
-         nsstvars = 1
-
-         ! Set the number of extra variables for sst to 0
-         nsstextr = 0
-
-         nsstsets = 0
-
-         IF (ln_reysst) nsstsets = nsstsets + 1
-         IF (ln_ghrsst) nsstsets = nsstsets + 1
-         IF ( ln_sstfb ) THEN
-            nsstsets = nsstsets + jnumsstfb
-         ENDIF
-
-         ALLOCATE(sstdata(nsstsets))
-         ALLOCATE(sstdatqc(nsstsets))
-         ALLOCATE(ld_sstnight(nsstsets))
-         sstdata(:)%nsurf=0
-         sstdatqc(:)%nsurf=0    
-         ld_sstnight(:)=.false.
-
-         nsstsets = 0
-
-         IF (ln_reysst) THEN
-
-            nsstsets = nsstsets + 1
-
-            ld_sstnight(nsstsets) = ln_sstnight
-
-            CALL obs_rea_sst_rey( reysstname, reysstfmt, sstdata(nsstsets), &
-               &                  nsstvars, nsstextr, &
-               &                  nitend-nit000+2, dobsini, dobsend )
-            CALL obs_pre_sst( sstdata(nsstsets), sstdatqc(nsstsets), ln_sst, &
-               &              ln_nea )
-
-        ENDIF
-        
-        IF (ln_ghrsst) THEN
-        
-            nsstsets = nsstsets + 1
-
-            ld_sstnight(nsstsets) = ln_sstnight
-          
-            CALL obs_rea_sst( 1, sstdata(nsstsets), jnumsst, &
-               &              sstfiles(1:jnumsst), &
-               &              nsstvars, nsstextr, nitend-nit000+2, &
-               &              dobsini, dobsend, ln_ignmis, .FALSE. )
-            CALL obs_pre_sst( sstdata(nsstsets), sstdatqc(nsstsets), ln_sst, &
-               &              ln_nea )
-
-        ENDIF
-               
-         ! Feedback SST data
-
-         IF ( ln_sstfb ) THEN
-
-            DO jset = 1, jnumsstfb
-            
-               nsstsets = nsstsets + 1
-
-               ld_sstnight(nsstsets) = ln_sstnight
-            
-               CALL obs_rea_sst( 0, sstdata(nsstsets), 1, &
-                  &              sstfbfiles(jset:jset), &
-                  &              nsstvars, nsstextr, nitend-nit000+2, &
-                  &              dobsini, dobsend, ln_ignmis, .FALSE. )
-               CALL obs_pre_sst( sstdata(nsstsets), sstdatqc(nsstsets), &
-                  &              ln_sst, ln_nea )
-
-            END DO               
-
-         ENDIF
-
-      ENDIF
-
-      !  - Sea surface salinity
-      IF ( ln_sss ) THEN
-         IF(lwp) WRITE(numout,*) ' SSS currently not available'
-      ENDIF
-
-      !  - Sea Ice Concentration
-      
-      IF ( ln_seaice ) THEN
-
-         ! Set the number of variables for seaice to 1
-         nseaicevars = 1
-
-         ! Set the number of extra variables for seaice to 0
-         nseaiceextr = 0
-         
-         ! Set the number of data sets to 1
-         nseaicesets = 1
-
-         ALLOCATE(seaicedata(nseaicesets))
-         ALLOCATE(seaicedatqc(nseaicesets))
-         seaicedata(:)%nsurf=0
-         seaicedatqc(:)%nsurf=0
-
-         CALL obs_rea_seaice( 1, seaicedata(nseaicesets), jnumseaice, &
-            &                 seaicefiles(1:jnumseaice), &
-            &                 nseaicevars, nseaiceextr, nitend-nit000+2, &
-            &                 dobsini, dobsend, ln_ignmis, .FALSE. )
-
-         CALL obs_pre_seaice( seaicedata(nseaicesets), seaicedatqc(nseaicesets), &
-            &                 ln_seaice, ln_nea )
- 
-      ENDIF
-
-      IF (ln_vel3d) THEN
-
-         ! Set the number of variables for profiles to 2 (U and V)
-         nvelovars = 2
-
-         ! Set the number of extra variables for profiles to 2 to store 
-         ! rotation parameters
-         nveloextr = 2
-
-         jveloset = 0
-         
-         IF ( ln_velavcur ) jveloset = jveloset + 1
-         IF ( ln_velhrcur ) jveloset = jveloset + 1
-         IF ( ln_velavadcp ) jveloset = jveloset + 1
-         IF ( ln_velhradcp ) jveloset = jveloset + 1
-         IF (ln_velfb) jveloset = jveloset + jnumvelfb
-
-         nvelosets = jveloset
-         IF ( nvelosets > 0 ) THEN
-            ALLOCATE( velodata(nvelosets) )
-            ALLOCATE( veldatqc(nvelosets) )
-            ALLOCATE( ld_velav(nvelosets) )
-         ENDIF
-         
-         jveloset = 0
-         
-         ! Daily averaged data
-
-         IF ( ln_velavcur ) THEN
-            
-            jveloset = jveloset + 1
-            
-            ld_velav(jveloset) = .TRUE.
-            
-            CALL obs_rea_vel_dri( 1, velodata(jveloset), jnumvelavcur, &
-               &                  velavcurfiles(1:jnumvelavcur), &
-               &                  nvelovars, nveloextr, &
-               &                  nitend-nit000+2,              &
-               &                  dobsini, dobsend, ln_ignmis, &
-               &                  ld_velav(jveloset), &
-               &                  .FALSE. )
-            
-            DO jvar = 1, 2
-               CALL obs_prof_staend( velodata(jveloset), jvar )
-            END DO
-            
-            CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
-               &              ln_vel3d, ln_nea, ld_velav(jveloset) )
-            
-         ENDIF
-
-         ! High frequency data
-
-         IF ( ln_velhrcur ) THEN
-            
-            jveloset = jveloset + 1
-            
-            ld_velav(jveloset) = .FALSE.
-               
-            CALL obs_rea_vel_dri( 1, velodata(jveloset), jnumvelhrcur, &
-               &                  velhrcurfiles(1:jnumvelhrcur), &
-               &                  nvelovars, nveloextr, &
-               &                  nitend-nit000+2,              &
-               &                  dobsini, dobsend, ln_ignmis, &
-               &                  ld_velav(jveloset), &
-               &                  .FALSE. )
-            
-            DO jvar = 1, 2
-               CALL obs_prof_staend( velodata(jveloset), jvar )
-            END DO
-            
-            CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
-               &              ln_vel3d, ln_nea, ld_velav(jveloset) )
-            
-         ENDIF
-
-         ! Daily averaged data
-
-         IF ( ln_velavadcp ) THEN
-            
-            jveloset = jveloset + 1
-            
-            ld_velav(jveloset) = .TRUE.
-            
-            CALL obs_rea_vel_dri( 1, velodata(jveloset), jnumvelavadcp, &
-               &                  velavadcpfiles(1:jnumvelavadcp), &
-               &                  nvelovars, nveloextr, &
-               &                  nitend-nit000+2,              &
-               &                  dobsini, dobsend, ln_ignmis, &
-               &                  ld_velav(jveloset), &
-               &                  .FALSE. )
-            
-            DO jvar = 1, 2
-               CALL obs_prof_staend( velodata(jveloset), jvar )
-            END DO
-            
-            CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
-               &              ln_vel3d, ln_nea, ld_velav(jveloset) )
-            
-         ENDIF
-
-         ! High frequency data
-
-         IF ( ln_velhradcp ) THEN
-            
-            jveloset = jveloset + 1
-            
-            ld_velav(jveloset) = .FALSE.
-               
-            CALL obs_rea_vel_dri( 1, velodata(jveloset), jnumvelhradcp, &
-               &                  velhradcpfiles(1:jnumvelhradcp), &
-               &                  nvelovars, nveloextr, &
-               &                  nitend-nit000+2,              &
-               &                  dobsini, dobsend, ln_ignmis, &
-               &                  ld_velav(jveloset), &
-               &                  .FALSE. )
-            
-            DO jvar = 1, 2
-               CALL obs_prof_staend( velodata(jveloset), jvar )
-            END DO
-            
-            CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
-               &              ln_vel3d, ln_nea, ld_velav(jveloset) )
-            
-         ENDIF
-
-         IF ( ln_velfb ) THEN
-
-            DO jset = 1, jnumvelfb
-            
-               jveloset = jveloset + 1
-
-               ld_velav(jveloset) = ln_velfb_av(jset)
-               
-               CALL obs_rea_vel_dri( 0, velodata(jveloset), 1, &
-                  &                  velfbfiles(jset:jset), &
-                  &                  nvelovars, nveloextr, &
-                  &                  nitend-nit000+2,              &
-                  &                  dobsini, dobsend, ln_ignmis, &
-                  &                  ld_velav(jveloset), &
-                  &                  .FALSE. )
-               
-               DO jvar = 1, 2
-                  CALL obs_prof_staend( velodata(jveloset), jvar )
-               END DO
-               
-               CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
-                  &              ln_vel3d, ln_nea, ld_velav(jveloset) )
-
-
-            END DO
-            
-         ENDIF
-
-      ENDIF
-     
+               &              kdailyavtypes = dailyavtypes )
+
+         END DO
+
+         DEALLOCATE( jnumfilesprof, obsfilesprof )
+
+      ENDIF
+
+      IF ( numsurftypes > 0 ) THEN
+      
+         ALLOCATE(surfdata(numsurftypes))
+         ALLOCATE(surfdatatqc(numsurftypes))
+         ALLOCATE(nvarssurf(numsurftypes))
+         ALLOCATE(nextrsurf(numsurftypes))
+         
+         DO jtype = 1, numsurftypes
+      
+            nvarssurf(jtype) = 1
+            nextrsurf(jtype) = 0
+            IF ( TRIM(obstypessurf(jtype)) == 'sla' ) nextrsurf(jtype) = 2
+
+            !Read in surface obs types
+            CALL obs_rea_surf( surfdata(jtype), jnumfilessurf(jtype), &
+               &               obsfilessurf(jtype,1:jnumfilessurf(jtype)), &
+               &               nvarssurf(jtype), nextrsurf(jtype), nitend-nit000+2, &
+               &               dobsini, dobsend, ln_ignmis, .FALSE. )
+
+            CALL obs_pre_surf( surfdata(jtype), surfdataqc(jtype), ln_nea )
+         
+            IF ( TRIM(obstypessurf(jtype)) == 'sla' ) THEN
+               CALL obs_rea_mdt( surfdataqc(jtype), n2dint )
+               IF ( ln_altbias ) CALL obs_rea_altbias ( surfdataqc(jtype), n2dint, bias_file )
+            ENDIF
+
+            DEALLOCATE( jnumfilessurf, obsfilessurf )
+
+         END DO
+
    END SUBROUTINE dia_obs_init
 
@@ -1017,9 +458,5 @@
       !! * Local declarations
       INTEGER :: idaystp                ! Number of timesteps per day
-      INTEGER :: jprofset               ! Profile data set loop variable
-      INTEGER :: jslaset                ! SLA data set loop variable
-      INTEGER :: jsstset                ! SST data set loop variable
-      INTEGER :: jseaiceset             ! sea ice data set loop variable
-      INTEGER :: jveloset               ! velocity profile data loop variable
+      INTEGER :: jtype                  ! data loop variable
       INTEGER :: jvar                   ! Variable number    
 #if ! defined key_lim2 && ! defined key_lim3
@@ -1050,66 +487,54 @@
       !-----------------------------------------------------------------------
 
-      !  - Temperature/salinity profiles
-      IF ( ln_t3d .OR. ln_s3d ) THEN
-         DO jprofset = 1, nprofsets
-            IF ( ld_enact(jprofset) ) THEN
-               CALL obs_pro_opt( prodatqc(jprofset),                     &
-                  &              kstp, jpi, jpj, jpk, nit000, idaystp,   &
-                  &              tsn(:,:,:,jp_tem), tsn(:,:,:,jp_sal),   &
-                  &              gdept_1d, tmask, n1dint, n2dint,        &
-                  &              kdailyavtypes = endailyavtypes )
-            ELSE
-               CALL obs_pro_opt( prodatqc(jprofset),                     &
-                  &              kstp, jpi, jpj, jpk, nit000, idaystp,   &
-                  &              tsn(:,:,:,jp_tem), tsn(:,:,:,jp_sal),   &
-                  &              gdept_1d, tmask, n1dint, n2dint              )
-            ENDIF
+      IF ( numproftypes > 0 ) THEN
+         DO jtype = 1, numproftypes
+      
+            SELECT CASE ( TRIM(obstypesprof(jtype)) )
+            CASE('prof')
+               profvar1(:,:,:) = tsn(:,:,:,jp_tem)
+               profvar2(:,:,:) = tsn(:,:,:,jp_sal)
+               profmask1(:,:,:) = tmask(:,:,:)
+               profmask2(:,:,:) = tmask(:,:,:)
+            CASE('vel')
+               profvar1(:,:,:) = un(:,:,:)
+               profvar2(:,:,:) = vn(:,:,:)
+               profmask1(:,:,:) = umask(:,:,:)
+               profmask2(:,:,:) = vmask(:,:,:)
+            END SELECT
+            
+            CALL obs_prof_opt( profdataqc(jtype),                       &
+               &               kstp, jpi, jpj, jpk, nit000, idaystp,   &
+               &               profvar1, profvar2,   &
+               &               gdept_1d, profmask1, profmask2, n1dint, n2dint,        &
+               &               kdailyavtypes = dailyavtypes )
+            
          END DO
-      ENDIF
-
-      !  - Sea surface anomaly
-      IF ( ln_sla ) THEN
-         DO jslaset = 1, nslasets
-            CALL obs_sla_opt( sladatqc(jslaset),            &
-               &              kstp, jpi, jpj, nit000, sshn, &
-               &              tmask(:,:,1), n2dint )
-         END DO         
-      ENDIF
-
-      !  - Sea surface temperature
-      IF ( ln_sst ) THEN
-         DO jsstset = 1, nsstsets
-            CALL obs_sst_opt( sstdatqc(jsstset),                &
-               &              kstp, jpi, jpj, nit000, idaystp,  &
-               &              tsn(:,:,1,jp_tem), tmask(:,:,1),  &
-               &              n2dint, ld_sstnight(jsstset) )
+
+      ENDIF
+
+      IF ( numsurftypes > 0 ) THEN
+         DO jtype = 1, numsurftypes
+      
+            SELECT CASE ( TRIM(obstypessurf(jtype)) )
+            CASE('sst')
+               surfvar(:,:) = tsn(:,:,1,jp_tem)
+            CASE('sla')
+               surfvar(:,:) = sshn(:,:)
+            CASE('sss')
+               surfvar(:,:) = tsn(:,:,1,jp_sal)
+#if defined key_lim2 || defined key_lim3
+            CASE('seaice')
+               surfvar(:,:) = 1._wp - frld(:,:)
+#endif
+            END SELECT
+         
+            CALL obs_surf_opt( surfdatqc(jtype),             &
+               &               kstp, jpi, jpj, nit000, surfvar, &
+               &               tmask(:,:,1), n2dint, ld_sstnight )
+            
          END DO
-      ENDIF
-
-      !  - Sea surface salinity
-      IF ( ln_sss ) THEN
-         IF(lwp) WRITE(numout,*) ' SSS currently not available'
-      ENDIF
-
-#if defined key_lim2 || defined key_lim3
-      IF ( ln_seaice ) THEN
-         DO jseaiceset = 1, nseaicesets
-            CALL obs_seaice_opt( seaicedatqc(jseaiceset),      &
-               &              kstp, jpi, jpj, nit000, 1.-frld, &
-               &              tmask(:,:,1), n2dint )
-         END DO
-      ENDIF      
-#endif
-
-      !  - Velocity profiles
-      IF ( ln_vel3d ) THEN
-         DO jveloset = 1, nvelosets
-           ! zonal component of velocity
-           CALL obs_vel_opt( veldatqc(jveloset), kstp, jpi, jpj, jpk, &
-              &              nit000, idaystp, un, vn, gdept_1d, umask, vmask, &
-                             n1dint, n2dint, ld_velav(jveloset) )
-         END DO
-      ENDIF
-
+         
+      ENDIF
+      
 #if ! defined key_lim2 && ! defined key_lim3
       CALL wrk_dealloc(jpi,jpj,frld) 
@@ -1139,254 +564,33 @@
       !! * Local declarations
 
-      INTEGER :: jprofset                 ! Profile data set loop variable
-      INTEGER :: jveloset                 ! Velocity data set loop variable
-      INTEGER :: jslaset                  ! SLA data set loop variable
-      INTEGER :: jsstset                  ! SST data set loop variable
-      INTEGER :: jseaiceset               ! Sea Ice data set loop variable
-      INTEGER :: jset
-      INTEGER :: jfbini
-      CHARACTER(LEN=20) :: datestr=" ",timestr=" "
-      CHARACTER(LEN=10) :: cdtmp
+      INTEGER :: jtype                    ! Data set loop variable
       !-----------------------------------------------------------------------
       ! Depending on switches call various observation output routines
       !-----------------------------------------------------------------------
 
-      !  - Temperature/salinity profiles
-
-      IF( ln_t3d .OR. ln_s3d ) THEN
-
-         ! Copy data from prodatqc to profdata structures
-         DO jprofset = 1, nprofsets
-
-            CALL obs_prof_decompress( prodatqc(jprofset), &
-                 &                    profdata(jprofset), .TRUE., numout )
-
+      IF ( numproftypes > 0 ) THEN
+         DO jtype = 1, numproftypes
+      
+            CALL obs_prof_decompress( profdataqc(jtype), &
+               &                      profdata(jtype), .TRUE., numout )
+
+            CALL obs_wri_prof( obstypesprof(jtype), profdata(jtype), n2dint )
+         
          END DO
-
-         ! Write the profiles.
-
-         jprofset = 0
-
-         ! ENACT insitu data
-
-         IF ( ln_ena ) THEN
-           
-            jprofset = jprofset + 1
-
-            CALL obs_wri_p3d( 'enact', profdata(jprofset) )
-
-         ENDIF
-
-         ! Coriolis insitu data
-
-         IF ( ln_cor ) THEN
-            
-            jprofset = jprofset + 1
-
-            CALL obs_wri_p3d( 'corio', profdata(jprofset) )
-            
-         ENDIF
-         
-         ! Feedback insitu data
-
-         IF ( ln_profb ) THEN
-
-            jfbini = jprofset + 1
-
-            DO jprofset = jfbini, nprofsets
-               
-               jset = jprofset - jfbini + 1
-               WRITE(cdtmp,'(A,I2.2)')'profb_',jset
-               CALL obs_wri_p3d( cdtmp, profdata(jprofset) )
-
-            END DO
-
-         ENDIF
-
-      ENDIF
-
-      !  - Sea surface anomaly
-      IF ( ln_sla ) THEN
-
-         ! Copy data from sladatqc to sladata structures
-         DO jslaset = 1, nslasets
-
-              CALL obs_surf_decompress( sladatqc(jslaset), &
-                 &                    sladata(jslaset), .TRUE., numout )
+         
+      ENDIF
+
+      IF ( numsurftypes > 0 ) THEN
+         DO jtype = 1, numsurftypes
+      
+            CALL obs_surf_decompress( surfdatqc(jtype), &
+               &                      surfdata(jtype), .TRUE., numout )
+
+            CALL obs_wri_surf( obstypessurf(jtype), surfdata(jtype), n2dint )
 
          END DO
-
-         jslaset = 0 
-
-         ! Write the AVISO SLA data
-
-         IF ( ln_sladt ) THEN
-            
-            jslaset = 1
-            CALL obs_wri_sla( 'aviso_act', sladata(jslaset) )
-            jslaset = 2
-            CALL obs_wri_sla( 'aviso_pas', sladata(jslaset) )
-
-         ENDIF
-
-         IF ( ln_slafb ) THEN
-            
-            jfbini = jslaset + 1
-
-            DO jslaset = jfbini, nslasets
-               
-               jset = jslaset - jfbini + 1
-               WRITE(cdtmp,'(A,I2.2)')'slafb_',jset
-               CALL obs_wri_sla( cdtmp, sladata(jslaset) )
-
-            END DO
-
-         ENDIF
-
-      ENDIF
-
-      !  - Sea surface temperature
-      IF ( ln_sst ) THEN
-
-         ! Copy data from sstdatqc to sstdata structures
-         DO jsstset = 1, nsstsets
-     
-              CALL obs_surf_decompress( sstdatqc(jsstset), &
-                 &                    sstdata(jsstset), .TRUE., numout )
-
-         END DO
-
-         jsstset = 0 
-
-         ! Write the AVISO SST data
-
-         IF ( ln_reysst ) THEN
-            
-            jsstset = jsstset + 1
-            CALL obs_wri_sst( 'reynolds', sstdata(jsstset) )
-
-         ENDIF
-
-         IF ( ln_ghrsst ) THEN
-            
-            jsstset = jsstset + 1
-            CALL obs_wri_sst( 'ghr', sstdata(jsstset) )
-
-         ENDIF
-
-         IF ( ln_sstfb ) THEN
-            
-            jfbini = jsstset + 1
-
-            DO jsstset = jfbini, nsstsets
-               
-               jset = jsstset - jfbini + 1
-               WRITE(cdtmp,'(A,I2.2)')'sstfb_',jset
-               CALL obs_wri_sst( cdtmp, sstdata(jsstset) )
-
-            END DO
-
-         ENDIF
-
-      ENDIF
-
-      !  - Sea surface salinity
-      IF ( ln_sss ) THEN
-         IF(lwp) WRITE(numout,*) ' SSS currently not available'
-      ENDIF
-
-      !  - Sea Ice Concentration
-      IF ( ln_seaice ) THEN
-
-         ! Copy data from seaicedatqc to seaicedata structures
-         DO jseaiceset = 1, nseaicesets
-
-              CALL obs_surf_decompress( seaicedatqc(jseaiceset), &
-                 &                    seaicedata(jseaiceset), .TRUE., numout )
-
-         END DO
-
-         ! Write the Sea Ice data
-         DO jseaiceset = 1, nseaicesets
-      
-            WRITE(cdtmp,'(A,I2.2)')'seaicefb_',jseaiceset
-            CALL obs_wri_seaice( cdtmp, seaicedata(jseaiceset) )
-
-         END DO
-
-      ENDIF
-      
-      ! Velocity data
-      IF( ln_vel3d ) THEN
-
-         ! Copy data from veldatqc to velodata structures
-         DO jveloset = 1, nvelosets
-
-            CALL obs_prof_decompress( veldatqc(jveloset), &
-                 &                    velodata(jveloset), .TRUE., numout )
-
-         END DO
-
-         ! Write the profiles.
-
-         jveloset = 0
-
-         ! Daily averaged data
-
-         IF ( ln_velavcur ) THEN
-            
-            jveloset = jveloset + 1
-
-            CALL obs_wri_vel( 'velavcurr', velodata(jveloset), n2dint )
-
-         ENDIF
-
-         ! High frequency data
-
-         IF ( ln_velhrcur ) THEN
-            
-            jveloset = jveloset + 1
-
-            CALL obs_wri_vel( 'velhrcurr', velodata(jveloset), n2dint )
-
-         ENDIF
-
-         ! Daily averaged data
-
-         IF ( ln_velavadcp ) THEN
-            
-            jveloset = jveloset + 1
-
-            CALL obs_wri_vel( 'velavadcp', velodata(jveloset), n2dint )
-
-         ENDIF
-
-         ! High frequency data
-
-         IF ( ln_velhradcp ) THEN
-            
-            jveloset = jveloset + 1
-            
-            CALL obs_wri_vel( 'velhradcp', velodata(jveloset), n2dint )
-               
-         ENDIF
-
-         ! Feedback velocity data
-
-         IF ( ln_velfb ) THEN
-
-            jfbini = jveloset + 1
-
-            DO jveloset = jfbini, nvelosets
-               
-               jset = jveloset - jfbini + 1
-               WRITE(cdtmp,'(A,I2.2)')'velfb_',jset
-               CALL obs_wri_vel( cdtmp, velodata(jveloset), n2dint )
-
-            END DO
-
-         ENDIF
-         
-      ENDIF
+         
+      ENDIF
+
 
    END SUBROUTINE dia_obs_wri
@@ -1409,26 +613,7 @@
 
       !! diaobs deallocation
-      IF ( nprofsets > 0 ) THEN
-          DEALLOCATE(ld_enact, &
-                  &  profdata, &
-                  &  prodatqc)
-      END IF
-      IF ( ln_sla ) THEN
-          DEALLOCATE(sladata, &
-                  &  sladatqc)
-      END IF
-      IF ( ln_seaice ) THEN
-          DEALLOCATE(sladata, &
-                  &  sladatqc)
-      END IF
-      IF ( ln_sst ) THEN
-          DEALLOCATE(sstdata, &
-                  &  sstdatqc)
-      END IF
-      IF ( ln_vel3d ) THEN
-          DEALLOCATE(ld_velav, &
-                  &  velodata, &
-                  &  veldatqc)
-      END IF
+      IF ( numproftypes > 0 ) DEALLOCATE(profdata, profdataqc, nvarsprof, nextrprof)
+      IF ( numsurftypes > 0 ) DEALLOCATE(surfdata, surfdataqc, nvarssurf, nextrsurf)
+      
    END SUBROUTINE dia_obs_dealloc
 
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/julian.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/julian.F90	(revision 5658)
+++ branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/julian.F90	(revision 5659)
@@ -24,4 +24,5 @@
       &   greg2jul            ! Convert date to relative time 
   
+   !! $Id$
 CONTAINS
  
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_oper.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_oper.F90	(revision 5658)
+++ branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_oper.F90	(revision 5659)
@@ -7,17 +7,6 @@
 
    !!----------------------------------------------------------------------
-   !!   obs_pro_opt :    Compute the model counterpart of temperature and
-   !!                    salinity observations from profiles
-   !!   obs_sla_opt :    Compute the model counterpart of sea level anomaly
-   !!                    observations
-   !!   obs_sst_opt :    Compute the model counterpart of sea surface temperature
-   !!                    observations
-   !!   obs_sss_opt :    Compute the model counterpart of sea surface salinity
-   !!                    observations
-   !!   obs_seaice_opt : Compute the model counterpart of sea ice concentration
-   !!                    observations
-   !!
-   !!   obs_vel_opt :    Compute the model counterpart of zonal and meridional
-   !!                    components of velocity from observations.
+   !!   obs_prof_opt :    Compute the model counterpart of profile data
+   !!   obs_surf_opt :    Compute the model counterpart of surface data
    !!----------------------------------------------------------------------
 
@@ -46,10 +35,6 @@
    PRIVATE
 
-   PUBLIC obs_pro_opt, &  ! Compute the model counterpart of profile observations
-      &   obs_sla_opt, &  ! Compute the model counterpart of SLA observations
-      &   obs_sst_opt, &  ! Compute the model counterpart of SST observations
-      &   obs_sss_opt, &  ! Compute the model counterpart of SSS observations
-      &   obs_seaice_opt, &
-      &   obs_vel_opt     ! Compute the model counterpart of velocity profile data
+   PUBLIC obs_prof_opt, &  ! Compute the model counterpart of profile observations
+      &   obs_surf_opt     ! Compute the model counterpart of surface observations
 
    INTEGER, PARAMETER, PUBLIC :: imaxavtypes = 20 ! Max number of daily avgd obs types
@@ -63,7 +48,7 @@
 CONTAINS
 
-   SUBROUTINE obs_pro_opt( prodatqc, kt, kpi, kpj, kpk, kit000, kdaystp, &
-      &                    ptn, psn, pgdept, ptmask, k1dint, k2dint, &
-      &                    kdailyavtypes )
+   SUBROUTINE obs_prof_opt( prodatqc, kt, kpi, kpj, kpk, kit000, kdaystp, &
+      &                     pvar1, pvar2, pgdept, pmask1, k1dint, k2dint, &
+      &                     kdailyavtypes )
       !!-----------------------------------------------------------------------
       !!
@@ -78,5 +63,5 @@
       !!
       !!    First, a vertical profile of horizontally interpolated model
-      !!    now temperatures is computed at the obs (lon, lat) point.
+      !!    now values is computed at the obs (lon, lat) point.
       !!    Several horizontal interpolation schemes are available:
       !!        - distance-weighted (great circle) (k2dint = 0)
@@ -86,5 +71,5 @@
       !!        - polynomial (quadrilateral grid)  (k2dint = 4)
       !!
-      !!    Next, the vertical temperature profile is interpolated to the
+      !!    Next, the vertical profile is interpolated to the
       !!    data depth points. Two vertical interpolation schemes are
       !!    available:
@@ -96,14 +81,11 @@
       !!    routine.
       !!
-      !!    For ENACT moored buoy data (e.g., TAO), the model equivalent is
+      !!    If the logical is switched on, the model equivalent is
       !!    a daily mean model temperature field. So, we first compute
       !!    the mean, then interpolate only at the end of the day.
       !!
-      !!    Note: the in situ temperature observations must be converted
+      !!    Note: in situ temperature observations must be converted
       !!    to potential temperature (the model variable) prior to
       !!    assimilation. 
-      !!??????????????????????????????????????????????????????????????
-      !!    INCLUDE POTENTIAL TEMP -> IN SITU TEMP IN OBS OPERATOR???
-      !!??????????????????????????????????????????????????????????????
       !!
       !! ** Action  :
@@ -115,4 +97,5 @@
       !!      ! 07-01 (K. Mogensen) Merge of temperature and salinity
       !!      ! 07-03 (K. Mogensen) General handling of profiles
+      !!      ! 15-02 (M. Martin) Combined routine for all profile types
       !!-----------------------------------------------------------------------
   
@@ -134,7 +117,8 @@
       INTEGER, INTENT(IN) :: kdaystp   ! Number of time steps per day                    
       REAL(KIND=wp), INTENT(IN), DIMENSION(kpi,kpj,kpk) :: &
-         & ptn,    &    ! Model temperature field
-         & psn,    &    ! Model salinity field
-         & ptmask       ! Land-sea mask
+         & pvar1,    &    ! Model field 1
+         & pvar2,    &    ! Model field 2
+         & pmask1,   &    ! Land-sea mask 1
+         & pmask2         ! Land-sea mask 2
       REAL(KIND=wp), INTENT(IN), DIMENSION(kpk) :: &
          & pgdept       ! Model array of depth levels
@@ -158,21 +142,29 @@
       REAL(KIND=wp) :: zdaystp
       REAL(KIND=wp), DIMENSION(kpk) :: &
+         & zobsmask1, &
+         & zobsmask2, &
          & zobsmask, &
          & zobsk,    &
          & zobs2k
       REAL(KIND=wp), DIMENSION(2,2,kpk) :: &
-         & zweig
+         & zweig1, &
+         & zweig2
       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: &
-         & zmask, &
-         & zintt, &
-         & zints, &
-         & zinmt, &
-         & zinms
+         & zmask1, &
+         & zmask2, &
+         & zint1, &
+         & zint2, &
+         & zinm1, &
+         & zinm2
       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
-         & zglam, &
-         & zgphi
+         & zglam1, &
+         & zglam2, &
+         & zgphi1, &
+         & zgphi2
       INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: &
-         & igrdi, &
-         & igrdj
+         & igrdi1, &
+         & igrdi2, &
+         & igrdj1, &
+         & igrdj2
 
       !------------------------------------------------------------------------
@@ -209,10 +201,10 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               ! Increment the temperature field for computing daily mean
+               ! Increment field 1 for computing daily mean
                prodatqc%vdmean(ji,jj,jk,1) = prodatqc%vdmean(ji,jj,jk,1) &
-                  &                        + ptn(ji,jj,jk)
-               ! Increment the salinity field for computing daily mean
+                  &                        + pvar1(ji,jj,jk)
+               ! Increment field 2 for computing daily mean
                prodatqc%vdmean(ji,jj,jk,2) = prodatqc%vdmean(ji,jj,jk,2) &
-                  &                        + psn(ji,jj,jk)
+                  &                        + pvar2(ji,jj,jk)
             END DO
          END DO
@@ -236,30 +228,47 @@
       ! Get the data for interpolation
       ALLOCATE( &
-         & igrdi(2,2,ipro),      &
-         & igrdj(2,2,ipro),      &
-         & zglam(2,2,ipro),      &
-         & zgphi(2,2,ipro),      &
-         & zmask(2,2,kpk,ipro),  &
-         & zintt(2,2,kpk,ipro),  &
-         & zints(2,2,kpk,ipro)   &
+         & igrdi1(2,2,ipro),      &
+         & igrdi2(2,2,ipro),      &
+         & igrdj1(2,2,ipro),      &
+         & igrdj2(2,2,ipro),      &
+         & zglam1(2,2,ipro),      &
+         & zglam2(2,2,ipro),      &
+         & zgphi1(2,2,ipro),      &
+         & zgphi2(2,2,ipro),      &
+         & zmask1(2,2,kpk,ipro),  &
+         & zmask2(2,2,kpk,ipro),  &
+         & zint1(2,2,kpk,ipro),  &
+         & zint2(2,2,kpk,ipro)   &
          & )
 
       DO jobs = prodatqc%nprofup + 1, prodatqc%nprofup + ipro
          iobs = jobs - prodatqc%nprofup
-         igrdi(1,1,iobs) = prodatqc%mi(jobs,1)-1
-         igrdj(1,1,iobs) = prodatqc%mj(jobs,1)-1
-         igrdi(1,2,iobs) = prodatqc%mi(jobs,1)-1
-         igrdj(1,2,iobs) = prodatqc%mj(jobs,1)
-         igrdi(2,1,iobs) = prodatqc%mi(jobs,1)
-         igrdj(2,1,iobs) = prodatqc%mj(jobs,1)-1
-         igrdi(2,2,iobs) = prodatqc%mi(jobs,1)
-         igrdj(2,2,iobs) = prodatqc%mj(jobs,1)
+         igrdi1(1,1,iobs) = prodatqc%mi(jobs,1)-1
+         igrdj1(1,1,iobs) = prodatqc%mj(jobs,1)-1
+         igrdi1(1,2,iobs) = prodatqc%mi(jobs,1)-1
+         igrdj1(1,2,iobs) = prodatqc%mj(jobs,1)
+         igrdi1(2,1,iobs) = prodatqc%mi(jobs,1)
+         igrdj1(2,1,iobs) = prodatqc%mj(jobs,1)-1
+         igrdi1(2,2,iobs) = prodatqc%mi(jobs,1)
+         igrdj1(2,2,iobs) = prodatqc%mj(jobs,1)
+         igrdi2(1,1,iobs) = prodatqc%mi(jobs,2)-1
+         igrdj2(1,1,iobs) = prodatqc%mj(jobs,2)-1
+         igrdi2(1,2,iobs) = prodatqc%mi(jobs,2)-1
+         igrdj2(1,2,iobs) = prodatqc%mj(jobs,2)
+         igrdi2(2,1,iobs) = prodatqc%mi(jobs,2)
+         igrdj2(2,1,iobs) = prodatqc%mj(jobs,2)-1
+         igrdi2(2,2,iobs) = prodatqc%mi(jobs,2)
+         igrdj2(2,2,iobs) = prodatqc%mj(jobs,2)
       END DO
 
-      CALL obs_int_comm_2d( 2, 2, ipro, igrdi, igrdj, glamt, zglam )
-      CALL obs_int_comm_2d( 2, 2, ipro, igrdi, igrdj, gphit, zgphi )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi, igrdj, ptmask,zmask )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi, igrdj, ptn,   zintt )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi, igrdj, psn,   zints )
+      CALL obs_int_comm_2d( 2, 2, ipro, igrdi1, igrdj1, glamt1, zglam1 )
+      CALL obs_int_comm_2d( 2, 2, ipro, igrdi1, igrdj1, gphit1, zgphi1 )
+      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi1, igrdj1, pmask1, zmask1 )
+      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi1, igrdj1, pvar1,   zint1 )
+      
+      CALL obs_int_comm_2d( 2, 2, ipro, igrdi2, igrdj2, glamt2, zglam2 )
+      CALL obs_int_comm_2d( 2, 2, ipro, igrdi2, igrdj2, gphit2, zgphi2 )
+      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi2, igrdj2, pmask1, zmask2 )
+      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi2, igrdj2, pvar2,   zint2 )
 
       ! At the end of the day also get interpolated means
@@ -267,12 +276,12 @@
 
          ALLOCATE( &
-            & zinmt(2,2,kpk,ipro),  &
-            & zinms(2,2,kpk,ipro)   &
+            & zinm1(2,2,kpk,ipro),  &
+            & zinm2(2,2,kpk,ipro)   &
             & )
 
-         CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi, igrdj, &
-            &                  prodatqc%vdmean(:,:,:,1), zinmt )
-         CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi, igrdj, &
-            &                  prodatqc%vdmean(:,:,:,2), zinms )
+         CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi1, igrdj1, &
+            &                  prodatqc%vdmean(:,:,:,1), zinm1 )
+         CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdi2, igrdj2, &
+            &                  prodatqc%vdmean(:,:,:,2), zinm2 )
 
       ENDIF
@@ -304,11 +313,18 @@
          ! Horizontal weights and vertical mask
 
-         IF ( ( prodatqc%npvend(jobs,1) > 0 ) .OR. &
-            & ( prodatqc%npvend(jobs,2) > 0 ) ) THEN
+         IF ( prodatqc%npvend(jobs,1) > 0 ) THEN
 
             CALL obs_int_h2d_init( kpk, kpk, k2dint, zlam, zphi,     &
-               &                   zglam(:,:,iobs), zgphi(:,:,iobs), &
-               &                   zmask(:,:,:,iobs), zweig, zobsmask )
-
+               &                   zglam1(:,:,iobs), zgphi1(:,:,iobs), &
+               &                   zmask1(:,:,:,iobs), zweig1, zobsmask1 )
+
+         ENDIF
+
+         IF ( prodatqc%npvend(jobs,2) > 0 ) THEN
+
+            CALL obs_int_h2d_init( kpk, kpk, k2dint, zlam, zphi,     &
+               &                   zglam2(:,:,iobs), zgphi2(:,:,iobs), &
+               &                   zmask2(:,:,:,iobs), zweig2, zobsmask2 )
+ 
          ENDIF
 
@@ -321,8 +337,8 @@
                IF ( idayend == 0 )  THEN
                   
-                  ! Daily averaged moored buoy (MRB) data
+                  ! Daily averaged data
                   
                   CALL obs_int_h2d( kpk, kpk,      &
-                     &              zweig, zinmt(:,:,:,iobs), zobsk )
+                     &              zweig1, zinm1(:,:,:,iobs), zobsk )
                   
                   
@@ -330,5 +346,5 @@
                
                   CALL ctl_stop( ' A nonzero' //     &
-                     &           ' number of profile T BUOY data should' // &
+                     &           ' number of average profile data should' // &
                      &           ' only occur at the end of a given day' )
 
@@ -340,5 +356,5 @@
 
                CALL obs_int_h2d( kpk, kpk,      &
-                  &              zweig, zintt(:,:,:,iobs), zobsk )
+                  &              zweig1, zint1(:,:,:,iobs), zobsk )
 
             ENDIF
@@ -377,13 +393,13 @@
                IF ( idayend == 0 )  THEN
 
-                  ! Daily averaged moored buoy (MRB) data
+                  ! Daily averaged data
                   
                   CALL obs_int_h2d( kpk, kpk,      &
-                     &              zweig, zinms(:,:,:,iobs), zobsk )
+                     &              zweig2, zinm2(:,:,:,iobs), zobsk )
                   
                ELSE
 
                   CALL ctl_stop( ' A nonzero' //     &
-                     &           ' number of profile S BUOY data should' // &
+                     &           ' number of average profile data should' // &
                      &           ' only occur at the end of a given day' )
 
@@ -395,5 +411,5 @@
 
                CALL obs_int_h2d( kpk, kpk,      &
-                  &              zweig, zints(:,:,:,iobs), zobsk )
+                  &              zweig2, zint2(:,:,:,iobs), zobsk )
 
             ENDIF
@@ -429,17 +445,22 @@
       ! Deallocate the data for interpolation
       DEALLOCATE( &
-         & igrdi, &
-         & igrdj, &
-         & zglam, &
-         & zgphi, &
-         & zmask, &
-         & zintt, &
-         & zints  &
+         & igrdi1, &
+         & igrdi2, &
+         & igrdj1, &
+         & igrdj2, &
+         & zglam1, &
+         & zglam2, &
+         & zgphi1, &
+         & zgphi2, &
+         & zmask1, &
+         & zmask2, &
+         & zint1,  &
+         & zint2   &
          & )
       ! At the end of the day also get interpolated means
       IF ( idayend == 0 ) THEN
          DEALLOCATE( &
-            & zinmt,  &
-            & zinms   &
+            & zinm1,  &
+            & zinm2   &
             & )
       ENDIF
@@ -447,13 +468,13 @@
       prodatqc%nprofup = prodatqc%nprofup + ipro 
       
-   END SUBROUTINE obs_pro_opt
-
-   SUBROUTINE obs_sla_opt( sladatqc, kt, kpi, kpj, kit000, &
-      &                    psshn, psshmask, k2dint )
+   END SUBROUTINE obs_prof_opt
+
+   SUBROUTINE obs_surf_opt( surfdataqc, kt, kpi, kpj, kit000, &
+      &                    psurf, psurfmask, k2dint, ld_nightav )
       !!-----------------------------------------------------------------------
       !!
-      !!                     ***  ROUTINE obs_sla_opt  ***
-      !!
-      !! ** Purpose : Compute the model counterpart of sea level anomaly
+      !!                     ***  ROUTINE obs_surf_opt  ***
+      !!
+      !! ** Purpose : Compute the model counterpart of surface
       !!              data by interpolating from the model grid to the 
       !!              observation point.
@@ -462,5 +483,5 @@
       !!              the model values at the corners of the surrounding grid box.
       !!
-      !!    The now model SSH is first computed at the obs (lon, lat) point.
+      !!    The new model value is first computed at the obs (lon, lat) point.
       !!
       !!    Several horizontal interpolation schemes are available:
@@ -471,6 +492,4 @@
       !!        - polynomial (quadrilateral grid)  (k2dint = 4)
       !!  
-      !!    The sea level anomaly at the observation points is then computed 
-      !!    by removing a mean dynamic topography (defined at the obs. point).
       !!
       !! ** Action  :
@@ -478,4 +497,5 @@
       !! History :
       !!      ! 07-03 (A. Weaver)
+      !!      ! 15-02 (M. Martin) Combined routine for surface types
       !!-----------------------------------------------------------------------
   
@@ -486,5 +506,5 @@
 
       !! * Arguments
-      TYPE(obs_surf), INTENT(INOUT) :: sladatqc     ! Subset of surface data not failing screening
+      TYPE(obs_surf), INTENT(INOUT) :: surfdataqc     ! Subset of surface data not failing screening
       INTEGER, INTENT(IN) :: kt      ! Time step
       INTEGER, INTENT(IN) :: kpi     ! Model grid parameters
@@ -494,6 +514,6 @@
       INTEGER, INTENT(IN) :: k2dint   ! Horizontal interpolation type (see header)
       REAL(KIND=wp), INTENT(IN), DIMENSION(kpi,kpj) :: &
-         & psshn,  &    ! Model SSH field
-         & psshmask     ! Land-sea mask
+         & psurf,  &    ! Model surface field
+         & psurfmask    ! Land-sea mask
          
       !! * Local declarations
@@ -502,5 +522,5 @@
       INTEGER :: jobs
       INTEGER :: inrc
-      INTEGER :: isla
+      INTEGER :: isurf
       INTEGER :: iobs
       REAL(KIND=wp) :: zlam
@@ -511,5 +531,5 @@
       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
          & zmask, &
-         & zsshl, &
+         & zsurf, &
          & zglam, &
          & zgphi
@@ -523,45 +543,117 @@
       ! ... Record and data counters
       inrc = kt - kit000 + 2
-      isla = sladatqc%nsstp(inrc)
+      isurf = surfdataqc%nsstp(inrc)
+      
+      IF ( ld_nightav ) THEN
+
+      ! Initialize array for night mean
+         IF ( kt .EQ. 0 ) THEN
+            ALLOCATE ( icount_night(kpi,kpj) )
+            ALLOCATE ( imask_night(kpi,kpj) )
+            ALLOCATE ( zintmp(kpi,kpj) )
+            ALLOCATE ( zouttmp(kpi,kpj) )
+            ALLOCATE ( zmeanday(kpi,kpj) )
+            nday_qsr = -1   ! initialisation flag for nbc_dcy
+         ENDIF
+
+         ! Initialize daily mean for first timestep
+         idayend = MOD( kt - kit000 + 1, kdaystp )
+
+         ! Added kt == 0 test to catch restart case 
+         IF ( idayend == 1 .OR. kt == 0) THEN
+            IF (lwp) WRITE(numout,*) 'Reset surfdataqc%vdmean on time-step: ',kt
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  surfdataqc%vdmean(ji,jj) = 0.0
+                  zmeanday(ji,jj) = 0.0
+                  icount_night(ji,jj) = 0
+               END DO
+            END DO
+         ENDIF
+
+         zintmp(:,:) = 0.0
+         zouttmp(:,:) = sbc_dcy( zintmp(:,:), .TRUE. )
+         imask_night(:,:) = INT( zouttmp(:,:) )
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ! Increment the temperature field for computing night mean and counter
+               surfdataqc%vdmean(ji,jj) = surfdataqc%vdmean(ji,jj)  &
+                      &                        + psurf(ji,jj)*imask_night(ji,jj)
+               zmeanday(ji,jj)        = zmeanday(ji,jj) + psurf(ji,jj)
+               icount_night(ji,jj) = icount_night(ji,jj) + imask_night(ji,jj)
+            END DO
+         END DO
+   
+         ! Compute the daily mean at the end of day
+
+         zdaystp = 1.0 / REAL( kdaystp )
+
+         IF ( idayend == 0 ) THEN 
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ! Test if "no night" point
+                  IF ( icount_night(ji,jj) .NE. 0 ) THEN
+                     surfdataqc%vdmean(ji,jj) = surfdataqc%vdmean(ji,jj) &
+                       &                        / icount_night(ji,jj) 
+                  ELSE
+                     surfdataqc%vdmean(ji,jj) = zmeanday(ji,jj) * zdaystp
+                  ENDIF
+               END DO
+            END DO
+         ENDIF
+
+      ENDIF
 
       ! Get the data for interpolation
 
       ALLOCATE( &
-         & igrdi(2,2,isla), &
-         & igrdj(2,2,isla), &
-         & zglam(2,2,isla), &
-         & zgphi(2,2,isla), &
-         & zmask(2,2,isla), &
-         & zsshl(2,2,isla)  &
+         & igrdi(2,2,isurf), &
+         & igrdj(2,2,isurf), &
+         & zglam(2,2,isurf), &
+         & zgphi(2,2,isurf), &
+         & zmask(2,2,isurf), &
+         & zsurf(2,2,isurf)  &
          & )
       
-      DO jobs = sladatqc%nsurfup + 1, sladatqc%nsurfup + isla
-         iobs = jobs - sladatqc%nsurfup
-         igrdi(1,1,iobs) = sladatqc%mi(jobs)-1
-         igrdj(1,1,iobs) = sladatqc%mj(jobs)-1
-         igrdi(1,2,iobs) = sladatqc%mi(jobs)-1
-         igrdj(1,2,iobs) = sladatqc%mj(jobs)
-         igrdi(2,1,iobs) = sladatqc%mi(jobs)
-         igrdj(2,1,iobs) = sladatqc%mj(jobs)-1
-         igrdi(2,2,iobs) = sladatqc%mi(jobs)
-         igrdj(2,2,iobs) = sladatqc%mj(jobs)
+      DO jobs = surfdataqc%nsurfup + 1, surfdataqc%nsurfup + isurf
+         iobs = jobs - surfdataqc%nsurfup
+         igrdi(1,1,iobs) = surfdataqc%mi(jobs)-1
+         igrdj(1,1,iobs) = surfdataqc%mj(jobs)-1
+         igrdi(1,2,iobs) = surfdataqc%mi(jobs)-1
+         igrdj(1,2,iobs) = surfdataqc%mj(jobs)
+         igrdi(2,1,iobs) = surfdataqc%mi(jobs)
+         igrdj(2,1,iobs) = surfdataqc%mj(jobs)-1
+         igrdi(2,2,iobs) = surfdataqc%mi(jobs)
+         igrdj(2,2,iobs) = surfdataqc%mj(jobs)
       END DO
 
-      CALL obs_int_comm_2d( 2, 2, isla, &
+      CALL obs_int_comm_2d( 2, 2, isurf, &
          &                  igrdi, igrdj, glamt, zglam )
-      CALL obs_int_comm_2d( 2, 2, isla, &
+      CALL obs_int_comm_2d( 2, 2, isurf, &
          &                  igrdi, igrdj, gphit, zgphi )
-      CALL obs_int_comm_2d( 2, 2, isla, &
-         &                  igrdi, igrdj, psshmask, zmask )
-      CALL obs_int_comm_2d( 2, 2, isla, &
-         &                  igrdi, igrdj, psshn, zsshl )
+      CALL obs_int_comm_2d( 2, 2, isurf, &
+         &                  igrdi, igrdj, psurfmask, zmask )
+      CALL obs_int_comm_2d( 2, 2, isurf, &
+         &                  igrdi, igrdj, psurf, zsurf )
+
+      ! At the end of the day get interpolated means
+      IF ( idayend == 0 .AND. ld_nightav ) THEN
+
+         ALLOCATE( &
+            & zsurfm(2,2,isurf)  &
+            & )
+
+         CALL obs_int_comm_2d( 2, 2, isurf, igrdi, igrdj, &
+            &               surfdataqc%vdmean(:,:), zsurfm )
+
+      ENDIF
 
       ! Loop over observations
-
-      DO jobs = sladatqc%nsurfup + 1, sladatqc%nsurfup + isla
-
-         iobs = jobs - sladatqc%nsurfup
-
-         IF ( kt /= sladatqc%mstp(jobs) ) THEN
+      DO jobs = surfdataqc%nsurfup + 1, surfdataqc%nsurfup + isurf
+
+         iobs = jobs - surfdataqc%nsurfup
+
+         IF ( kt /= surfdataqc%mstp(jobs) ) THEN
             
             IF(lwp) THEN
@@ -574,6 +666,6 @@
                WRITE(numout,*) ' Record  = ', jobs,                &
                   &            ' kt      = ', kt,                  &
-                  &            ' mstp    = ', sladatqc%mstp(jobs), &
-                  &            ' ntyp    = ', sladatqc%ntyp(jobs)
+                  &            ' mstp    = ', surfdataqc%mstp(jobs), &
+                  &            ' ntyp    = ', surfdataqc%ntyp(jobs)
             ENDIF
             CALL ctl_stop( 'obs_sla_opt', 'Inconsistent time' )
@@ -581,8 +673,8 @@
          ENDIF
          
-         zlam = sladatqc%rlam(jobs)
-         zphi = sladatqc%rphi(jobs)
-
-         ! Get weights to interpolate the model SSH to the observation point
+         zlam = surfdataqc%rlam(jobs)
+         zphi = surfdataqc%rphi(jobs)
+
+         ! Get weights to interpolate the model value to the observation point
          CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,         &
             &                   zglam(:,:,iobs), zgphi(:,:,iobs), &
@@ -590,11 +682,31 @@
          
 
-         ! Interpolate the model SSH to the observation point
-         CALL obs_int_h2d( 1, 1,      &
-            &              zweig, zsshl(:,:,iobs),  zext )
+         ! Interpolate the model field to the observation point
+         IF ( ld_nightav ) THEN
+
+           IF ( idayend == 0 )  THEN
+               ! Daily averaged data
+               CALL obs_int_h2d( 1, 1,      & 
+                     &              zweig, zsurfm(:,:,iobs), zext )
+            ELSE 
+               CALL ctl_stop( ' ld_nightav is set to true: a nonzero' //     &
+                     &           ' number of night data should' // &
+                     &           ' only occur at the end of a given day' )
+            ENDIF
+
+         ELSE
+
+            CALL obs_int_h2d( 1, 1,      &
+               &              zweig, zsurf(:,:,iobs),  zext )
+
+         ENDIF
          
-         sladatqc%rext(jobs,1) = zext(1)
-         ! ... Remove the MDT at the observation point
-         sladatqc%rmod(jobs,1) = sladatqc%rext(jobs,1) - sladatqc%rext(jobs,2)
+         IF ( surfdataqc%nextr == 2 ) THEN
+            ! ... Remove the MDT from the SSH at the observation point to get the SLA
+            surfdataqc%rext(jobs,1) = zext(1)
+            surfdataqc%rmod(jobs,1) = surfdataqc%rext(jobs,1) - surfdataqc%rext(jobs,2)
+         ELSE
+            surfdataqc%rmod(jobs,1) = zext(1)
+         ENDIF
 
       END DO
@@ -607,270 +719,5 @@
          & zgphi, &
          & zmask, &
-         & zsshl  &
-         & )
-
-      sladatqc%nsurfup = sladatqc%nsurfup + isla
-
-   END SUBROUTINE obs_sla_opt
-
-   SUBROUTINE obs_sst_opt( sstdatqc, kt, kpi, kpj, kit000, kdaystp, &
-      &                    psstn, psstmask, k2dint, ld_nightav )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_sst_opt  ***
-      !!
-      !! ** Purpose : Compute the model counterpart of surface temperature
-      !!              data by interpolating from the model grid to the 
-      !!              observation point.
-      !!
-      !! ** Method  : Linearly interpolate to each observation point using 
-      !!              the model values at the corners of the surrounding grid box.
-      !!
-      !!    The now model SST is first computed at the obs (lon, lat) point.
-      !!
-      !!    Several horizontal interpolation schemes are available:
-      !!        - distance-weighted (great circle) (k2dint = 0)
-      !!        - distance-weighted (small angle)  (k2dint = 1)
-      !!        - bilinear (geographical grid)     (k2dint = 2)
-      !!        - bilinear (quadrilateral grid)    (k2dint = 3)
-      !!        - polynomial (quadrilateral grid)  (k2dint = 4)
-      !!
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!        !  07-07  (S. Ricci ) : Original
-      !!      
-      !!-----------------------------------------------------------------------
-
-      !! * Modules used
-      USE obs_surf_def  ! Definition of storage space for surface observations
-      USE sbcdcy
-
-      IMPLICIT NONE
-
-      !! * Arguments
-      TYPE(obs_surf), INTENT(INOUT) :: &
-         & sstdatqc     ! Subset of surface data not failing screening
-      INTEGER, INTENT(IN) :: kt        ! Time step
-      INTEGER, INTENT(IN) :: kpi       ! Model grid parameters
-      INTEGER, INTENT(IN) :: kpj
-      INTEGER, INTENT(IN) :: kit000    ! Number of the first time step 
-                                       !   (kit000-1 = restart time)
-      INTEGER, INTENT(IN) :: k2dint    ! Horizontal interpolation type (see header)
-      INTEGER, INTENT(IN) :: kdaystp   ! Number of time steps per day  
-      REAL(KIND=wp), INTENT(IN), DIMENSION(kpi,kpj) :: &
-         & psstn,  &    ! Model SST field
-         & psstmask     ! Land-sea mask
-
-      !! * Local declarations
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jobs
-      INTEGER :: inrc
-      INTEGER :: isst
-      INTEGER :: iobs
-      INTEGER :: idayend
-      REAL(KIND=wp) :: zlam
-      REAL(KIND=wp) :: zphi
-      REAL(KIND=wp) :: zext(1), zobsmask(1)
-      REAL(KIND=wp) :: zdaystp
-      INTEGER, DIMENSION(:,:), SAVE, ALLOCATABLE :: &
-         & icount_sstnight,      &
-         & imask_night
-      REAL(kind=wp), DIMENSION(:,:), SAVE, ALLOCATABLE :: &
-         & zintmp, &
-         & zouttmp, & 
-         & zmeanday    ! to compute model sst in region of 24h daylight (pole)
-      REAL(kind=wp), DIMENSION(2,2,1) :: &
-         & zweig
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
-         & zmask, &
-         & zsstl, &
-         & zsstm, &
-         & zglam, &
-         & zgphi
-      INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: &
-         & igrdi, &
-         & igrdj
-      LOGICAL, INTENT(IN) :: ld_nightav
-
-      !-----------------------------------------------------------------------
-      ! Local initialization 
-      !-----------------------------------------------------------------------
-      ! ... Record and data counters
-      inrc = kt - kit000 + 2
-      isst = sstdatqc%nsstp(inrc)
-
-      IF ( ld_nightav ) THEN
-
-      ! Initialize array for night mean
-
-      IF ( kt .EQ. 0 ) THEN
-         ALLOCATE ( icount_sstnight(kpi,kpj) )
-         ALLOCATE ( imask_night(kpi,kpj) )
-         ALLOCATE ( zintmp(kpi,kpj) )
-         ALLOCATE ( zouttmp(kpi,kpj) )
-         ALLOCATE ( zmeanday(kpi,kpj) )
-         nday_qsr = -1   ! initialisation flag for nbc_dcy
-      ENDIF
-
-      ! Initialize daily mean for first timestep
-      idayend = MOD( kt - kit000 + 1, kdaystp )
-
-      ! Added kt == 0 test to catch restart case 
-      IF ( idayend == 1 .OR. kt == 0) THEN
-         IF (lwp) WRITE(numout,*) 'Reset sstdatqc%vdmean on time-step: ',kt
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               sstdatqc%vdmean(ji,jj) = 0.0
-               zmeanday(ji,jj) = 0.0
-               icount_sstnight(ji,jj) = 0
-            END DO
-         END DO
-      ENDIF
-
-      zintmp(:,:) = 0.0
-      zouttmp(:,:) = sbc_dcy( zintmp(:,:), .TRUE. )
-      imask_night(:,:) = INT( zouttmp(:,:) )
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            ! Increment the temperature field for computing night mean and counter
-            sstdatqc%vdmean(ji,jj) = sstdatqc%vdmean(ji,jj)  &
-                   &                        + psstn(ji,jj)*imask_night(ji,jj)
-            zmeanday(ji,jj)        = zmeanday(ji,jj) + psstn(ji,jj)
-            icount_sstnight(ji,jj) = icount_sstnight(ji,jj) + imask_night(ji,jj)
-         END DO
-      END DO
-   
-      ! Compute the daily mean at the end of day
-
-      zdaystp = 1.0 / REAL( kdaystp )
-
-      IF ( idayend == 0 ) THEN 
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! Test if "no night" point
-               IF ( icount_sstnight(ji,jj) .NE. 0 ) THEN
-                  sstdatqc%vdmean(ji,jj) = sstdatqc%vdmean(ji,jj) &
-                    &                        / icount_sstnight(ji,jj) 
-               ELSE
-                  sstdatqc%vdmean(ji,jj) = zmeanday(ji,jj) * zdaystp
-               ENDIF
-            END DO
-         END DO
-      ENDIF
-
-      ENDIF
-
-      ! Get the data for interpolation
-      
-      ALLOCATE( &
-         & igrdi(2,2,isst), &
-         & igrdj(2,2,isst), &
-         & zglam(2,2,isst), &
-         & zgphi(2,2,isst), &
-         & zmask(2,2,isst), &
-         & zsstl(2,2,isst)  &
-         & )
-      
-      DO jobs = sstdatqc%nsurfup + 1, sstdatqc%nsurfup + isst
-         iobs = jobs - sstdatqc%nsurfup
-         igrdi(1,1,iobs) = sstdatqc%mi(jobs)-1
-         igrdj(1,1,iobs) = sstdatqc%mj(jobs)-1
-         igrdi(1,2,iobs) = sstdatqc%mi(jobs)-1
-         igrdj(1,2,iobs) = sstdatqc%mj(jobs)
-         igrdi(2,1,iobs) = sstdatqc%mi(jobs)
-         igrdj(2,1,iobs) = sstdatqc%mj(jobs)-1
-         igrdi(2,2,iobs) = sstdatqc%mi(jobs)
-         igrdj(2,2,iobs) = sstdatqc%mj(jobs)
-      END DO
-      
-      CALL obs_int_comm_2d( 2, 2, isst, &
-         &                  igrdi, igrdj, glamt, zglam )
-      CALL obs_int_comm_2d( 2, 2, isst, &
-         &                  igrdi, igrdj, gphit, zgphi )
-      CALL obs_int_comm_2d( 2, 2, isst, &
-         &                  igrdi, igrdj, psstmask, zmask )
-      CALL obs_int_comm_2d( 2, 2, isst, &
-         &                  igrdi, igrdj, psstn, zsstl )
-
-      ! At the end of the day get interpolated means
-      IF ( idayend == 0 .AND. ld_nightav ) THEN
-
-         ALLOCATE( &
-            & zsstm(2,2,isst)  &
-            & )
-
-         CALL obs_int_comm_2d( 2, 2, isst, igrdi, igrdj, &
-            &               sstdatqc%vdmean(:,:), zsstm )
-
-      ENDIF
-
-      ! Loop over observations
-
-      DO jobs = sstdatqc%nsurfup + 1, sstdatqc%nsurfup + isst
-         
-         iobs = jobs - sstdatqc%nsurfup
-         
-         IF ( kt /= sstdatqc%mstp(jobs) ) THEN
-            
-            IF(lwp) THEN
-               WRITE(numout,*)
-               WRITE(numout,*) ' E R R O R : Observation',              &
-                  &            ' time step is not consistent with the', &
-                  &            ' model time step'
-               WRITE(numout,*) ' ========='
-               WRITE(numout,*)
-               WRITE(numout,*) ' Record  = ', jobs,                &
-                  &            ' kt      = ', kt,                  &
-                  &            ' mstp    = ', sstdatqc%mstp(jobs), &
-                  &            ' ntyp    = ', sstdatqc%ntyp(jobs)
-            ENDIF
-            CALL ctl_stop( 'obs_sst_opt', 'Inconsistent time' )
-            
-         ENDIF
-         
-         zlam = sstdatqc%rlam(jobs)
-         zphi = sstdatqc%rphi(jobs)
-         
-         ! Get weights to interpolate the model SST to the observation point
-         CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,         &
-            &                   zglam(:,:,iobs), zgphi(:,:,iobs), &
-            &                   zmask(:,:,iobs), zweig, zobsmask )
-            
-         ! Interpolate the model SST to the observation point 
-
-         IF ( ld_nightav ) THEN
-
-           IF ( idayend == 0 )  THEN
-               ! Daily averaged/diurnal cycle of SST  data
-               CALL obs_int_h2d( 1, 1,      & 
-                     &              zweig, zsstm(:,:,iobs), zext )
-            ELSE 
-               CALL ctl_stop( ' ld_nightav is set to true: a nonzero' //     &
-                     &           ' number of night SST data should' // &
-                     &           ' only occur at the end of a given day' )
-            ENDIF
-
-         ELSE
-
-            CALL obs_int_h2d( 1, 1,      &
-            &              zweig, zsstl(:,:,iobs),  zext )
-
-         ENDIF
-         sstdatqc%rmod(jobs,1) = zext(1)
-         
-      END DO
-      
-      ! Deallocate the data for interpolation
-      DEALLOCATE( &
-         & igrdi, &
-         & igrdj, &
-         & zglam, &
-         & zgphi, &
-         & zmask, &
-         & zsstl  &
+         & zsurf  &
          & )
 
@@ -878,564 +725,11 @@
       IF ( idayend == 0 .AND. ld_nightav ) THEN
          DEALLOCATE( &
-            & zsstm  &
+            & zsurfm  &
             & )
       ENDIF
-      
-      sstdatqc%nsurfup = sstdatqc%nsurfup + isst
-
-   END SUBROUTINE obs_sst_opt
-
-   SUBROUTINE obs_sss_opt
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_sss_opt  ***
-      !!
-      !! ** Purpose : Compute the model counterpart of sea surface salinity
-      !!              data by interpolating from the model grid to the 
-      !!              observation point.
-      !!
-      !! ** Method  : 
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!      ! ??-?? 
-      !!-----------------------------------------------------------------------
-
-      IMPLICIT NONE
-
-   END SUBROUTINE obs_sss_opt
-
-   SUBROUTINE obs_seaice_opt( seaicedatqc, kt, kpi, kpj, kit000, &
-      &                    pseaicen, pseaicemask, k2dint )
-
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_seaice_opt  ***
-      !!
-      !! ** Purpose : Compute the model counterpart of surface temperature
-      !!              data by interpolating from the model grid to the 
-      !!              observation point.
-      !!
-      !! ** Method  : Linearly interpolate to each observation point using 
-      !!              the model values at the corners of the surrounding grid box.
-      !!
-      !!    The now model sea ice is first computed at the obs (lon, lat) point.
-      !!
-      !!    Several horizontal interpolation schemes are available:
-      !!        - distance-weighted (great circle) (k2dint = 0)
-      !!        - distance-weighted (small angle)  (k2dint = 1)
-      !!        - bilinear (geographical grid)     (k2dint = 2)
-      !!        - bilinear (quadrilateral grid)    (k2dint = 3)
-      !!        - polynomial (quadrilateral grid)  (k2dint = 4)
-      !!
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!        !  07-07  (S. Ricci ) : Original
-      !!      
-      !!-----------------------------------------------------------------------
-
-      !! * Modules used
-      USE obs_surf_def  ! Definition of storage space for surface observations
-
-      IMPLICIT NONE
-
-      !! * Arguments
-      TYPE(obs_surf), INTENT(INOUT) :: seaicedatqc     ! Subset of surface data not failing screening
-      INTEGER, INTENT(IN) :: kt       ! Time step
-      INTEGER, INTENT(IN) :: kpi      ! Model grid parameters
-      INTEGER, INTENT(IN) :: kpj
-      INTEGER, INTENT(IN) :: kit000   ! Number of the first time step 
-                                      !   (kit000-1 = restart time)
-      INTEGER, INTENT(IN) :: k2dint   ! Horizontal interpolation type (see header)
-      REAL(KIND=wp), INTENT(IN), DIMENSION(kpi,kpj) :: &
-         & pseaicen,  &    ! Model sea ice field
-         & pseaicemask     ! Land-sea mask
-         
-      !! * Local declarations
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jobs
-      INTEGER :: inrc
-      INTEGER :: iseaice
-      INTEGER :: iobs
-       
-      REAL(KIND=wp) :: zlam
-      REAL(KIND=wp) :: zphi
-      REAL(KIND=wp) :: zext(1), zobsmask(1)
-      REAL(kind=wp), DIMENSION(2,2,1) :: &
-         & zweig
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
-         & zmask, &
-         & zseaicel, &
-         & zglam, &
-         & zgphi
-      INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: &
-         & igrdi, &
-         & igrdj
-
-      !------------------------------------------------------------------------
-      ! Local initialization 
-      !------------------------------------------------------------------------
-      ! ... Record and data counters
-      inrc = kt - kit000 + 2
-      iseaice = seaicedatqc%nsstp(inrc)
-
-      ! Get the data for interpolation
-      
-      ALLOCATE( &
-         & igrdi(2,2,iseaice), &
-         & igrdj(2,2,iseaice), &
-         & zglam(2,2,iseaice), &
-         & zgphi(2,2,iseaice), &
-         & zmask(2,2,iseaice), &
-         & zseaicel(2,2,iseaice)  &
-         & )
-      
-      DO jobs = seaicedatqc%nsurfup + 1, seaicedatqc%nsurfup + iseaice
-         iobs = jobs - seaicedatqc%nsurfup
-         igrdi(1,1,iobs) = seaicedatqc%mi(jobs)-1
-         igrdj(1,1,iobs) = seaicedatqc%mj(jobs)-1
-         igrdi(1,2,iobs) = seaicedatqc%mi(jobs)-1
-         igrdj(1,2,iobs) = seaicedatqc%mj(jobs)
-         igrdi(2,1,iobs) = seaicedatqc%mi(jobs)
-         igrdj(2,1,iobs) = seaicedatqc%mj(jobs)-1
-         igrdi(2,2,iobs) = seaicedatqc%mi(jobs)
-         igrdj(2,2,iobs) = seaicedatqc%mj(jobs)
-      END DO
-      
-      CALL obs_int_comm_2d( 2, 2, iseaice, &
-         &                  igrdi, igrdj, glamt, zglam )
-      CALL obs_int_comm_2d( 2, 2, iseaice, &
-         &                  igrdi, igrdj, gphit, zgphi )
-      CALL obs_int_comm_2d( 2, 2, iseaice, &
-         &                  igrdi, igrdj, pseaicemask, zmask )
-      CALL obs_int_comm_2d( 2, 2, iseaice, &
-         &                  igrdi, igrdj, pseaicen, zseaicel )
-      
-      DO jobs = seaicedatqc%nsurfup + 1, seaicedatqc%nsurfup + iseaice
-         
-         iobs = jobs - seaicedatqc%nsurfup
-         
-         IF ( kt /= seaicedatqc%mstp(jobs) ) THEN
-            
-            IF(lwp) THEN
-               WRITE(numout,*)
-               WRITE(numout,*) ' E R R O R : Observation',              &
-                  &            ' time step is not consistent with the', &
-                  &            ' model time step'
-               WRITE(numout,*) ' ========='
-               WRITE(numout,*)
-               WRITE(numout,*) ' Record  = ', jobs,                &
-                  &            ' kt      = ', kt,                  &
-                  &            ' mstp    = ', seaicedatqc%mstp(jobs), &
-                  &            ' ntyp    = ', seaicedatqc%ntyp(jobs)
-            ENDIF
-            CALL ctl_stop( 'obs_seaice_opt', 'Inconsistent time' )
-            
-         ENDIF
-         
-         zlam = seaicedatqc%rlam(jobs)
-         zphi = seaicedatqc%rphi(jobs)
-         
-         ! Get weights to interpolate the model sea ice to the observation point
-         CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,         &
-            &                   zglam(:,:,iobs), zgphi(:,:,iobs), &
-            &                   zmask(:,:,iobs), zweig, zobsmask )
-         
-         ! ... Interpolate the model sea ice to the observation point
-         CALL obs_int_h2d( 1, 1,      &
-            &              zweig, zseaicel(:,:,iobs),  zext )
-         
-         seaicedatqc%rmod(jobs,1) = zext(1)
-         
-      END DO
-      
-      ! Deallocate the data for interpolation
-      DEALLOCATE( &
-         & igrdi,    &
-         & igrdj,    &
-         & zglam,    &
-         & zgphi,    &
-         & zmask,    &
-         & zseaicel  &
-         & )
-      
-      seaicedatqc%nsurfup = seaicedatqc%nsurfup + iseaice
-
-   END SUBROUTINE obs_seaice_opt
-
-   SUBROUTINE obs_vel_opt( prodatqc, kt, kpi, kpj, kpk, kit000, kdaystp, &
-      &                    pun, pvn, pgdept, pumask, pvmask, k1dint, k2dint, &
-      &                    ld_dailyav )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_vel_opt  ***
-      !!
-      !! ** Purpose : Compute the model counterpart of velocity profile
-      !!              data by interpolating from the model grid to the 
-      !!              observation point.
-      !!
-      !! ** Method  : Linearly interpolate zonal and meridional components of velocity 
-      !!              to each observation point using the model values at the corners of 
-      !!              the surrounding grid box. The model velocity components are on a 
-      !!              staggered C- grid.
-      !!
-      !!    For velocity data from the TAO array, the model equivalent is
-      !!    a daily mean velocity field. So, we first compute
-      !!    the mean, then interpolate only at the end of the day.
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!    ! 07-03 (K. Mogensen)      : Temperature and Salinity profiles
-      !!    ! 08-10 (Maria Valdivieso) : Velocity component (U,V) profiles
-      !!-----------------------------------------------------------------------
-    
-      !! * Modules used
-      USE obs_profiles_def ! Definition of storage space for profile obs.
-
-      IMPLICIT NONE
-
-      !! * Arguments
-      TYPE(obs_prof), INTENT(INOUT) :: &
-         & prodatqc        ! Subset of profile data not failing screening
-      INTEGER, INTENT(IN) :: kt        ! Time step
-      INTEGER, INTENT(IN) :: kpi       ! Model grid parameters
-      INTEGER, INTENT(IN) :: kpj
-      INTEGER, INTENT(IN) :: kpk 
-      INTEGER, INTENT(IN) :: kit000    ! Number of the first time step 
-                                       !   (kit000-1 = restart time)
-      INTEGER, INTENT(IN) :: k1dint    ! Vertical interpolation type (see header)
-      INTEGER, INTENT(IN) :: k2dint    ! Horizontal interpolation type (see header)
-      INTEGER, INTENT(IN) :: kdaystp   ! Number of time steps per day                    
-      REAL(KIND=wp), INTENT(IN), DIMENSION(kpi,kpj,kpk) :: &
-         & pun,    &    ! Model zonal component of velocity
-         & pvn,    &    ! Model meridional component of velocity
-         & pumask, &    ! Land-sea mask
-         & pvmask       ! Land-sea mask
-      REAL(KIND=wp), INTENT(IN), DIMENSION(kpk) :: &
-         & pgdept       ! Model array of depth levels
-      LOGICAL, INTENT(IN) :: ld_dailyav
-         
-      !! * Local declarations
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jk
-      INTEGER :: jobs
-      INTEGER :: inrc
-      INTEGER :: ipro
-      INTEGER :: idayend
-      INTEGER :: ista
-      INTEGER :: iend
-      INTEGER :: iobs
-      INTEGER, DIMENSION(imaxavtypes) :: &
-         & idailyavtypes
-      REAL(KIND=wp) :: zlam
-      REAL(KIND=wp) :: zphi
-      REAL(KIND=wp) :: zdaystp
-      REAL(KIND=wp), DIMENSION(kpk) :: &
-         & zobsmasku, &
-         & zobsmaskv, &
-         & zobsmask,  &
-         & zobsk,     &
-         & zobs2k
-      REAL(KIND=wp), DIMENSION(2,2,kpk) :: &
-         & zweigu,zweigv
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: &
-         & zumask, zvmask, &
-         & zintu, &
-         & zintv, &
-         & zinmu, &
-         & zinmv
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
-         & zglamu, zglamv, &
-         & zgphiu, zgphiv
-      INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: &
-         & igrdiu, &
-         & igrdju, &
-         & igrdiv, &
-         & igrdjv
-
-      !------------------------------------------------------------------------
-      ! Local initialization 
-      !------------------------------------------------------------------------
-      ! ... Record and data counters
-      inrc = kt - kit000 + 2
-      ipro = prodatqc%npstp(inrc)
-
-      ! Initialize daily mean for first timestep
-      idayend = MOD( kt - kit000 + 1, kdaystp )
-
-      ! Added kt == 0 test to catch restart case 
-      IF ( idayend == 1 .OR. kt == 0) THEN
-         IF (lwp) WRITE(numout,*) 'Reset prodatqc%vdmean on time-step: ',kt
-         prodatqc%vdmean(:,:,:,1) = 0.0
-         prodatqc%vdmean(:,:,:,2) = 0.0
-      ENDIF
-
-      ! Increment the zonal velocity field for computing daily mean
-      prodatqc%vdmean(:,:,:,1) = prodatqc%vdmean(:,:,:,1) + pun(:,:,:)
-      ! Increment the meridional velocity field for computing daily mean
-      prodatqc%vdmean(:,:,:,2) = prodatqc%vdmean(:,:,:,2) + pvn(:,:,:)
-   
-      ! Compute the daily mean at the end of day
-      zdaystp = 1.0 / REAL( kdaystp )
-      IF ( idayend == 0 ) THEN
-         prodatqc%vdmean(:,:,:,1) = prodatqc%vdmean(:,:,:,1) * zdaystp
-         prodatqc%vdmean(:,:,:,2) = prodatqc%vdmean(:,:,:,2) * zdaystp
-      ENDIF
-
-      ! Get the data for interpolation
-      ALLOCATE( &
-         & igrdiu(2,2,ipro),      &
-         & igrdju(2,2,ipro),      &
-         & igrdiv(2,2,ipro),      &
-         & igrdjv(2,2,ipro),      &
-         & zglamu(2,2,ipro), zglamv(2,2,ipro), &
-         & zgphiu(2,2,ipro), zgphiv(2,2,ipro), &
-         & zumask(2,2,kpk,ipro), zvmask(2,2,kpk,ipro), &
-         & zintu(2,2,kpk,ipro),  &
-         & zintv(2,2,kpk,ipro)   &
-         & )
-
-      DO jobs = prodatqc%nprofup + 1, prodatqc%nprofup + ipro
-         iobs = jobs - prodatqc%nprofup
-         igrdiu(1,1,iobs) = prodatqc%mi(jobs,1)-1
-         igrdju(1,1,iobs) = prodatqc%mj(jobs,1)-1
-         igrdiu(1,2,iobs) = prodatqc%mi(jobs,1)-1
-         igrdju(1,2,iobs) = prodatqc%mj(jobs,1)
-         igrdiu(2,1,iobs) = prodatqc%mi(jobs,1)
-         igrdju(2,1,iobs) = prodatqc%mj(jobs,1)-1
-         igrdiu(2,2,iobs) = prodatqc%mi(jobs,1)
-         igrdju(2,2,iobs) = prodatqc%mj(jobs,1)
-         igrdiv(1,1,iobs) = prodatqc%mi(jobs,2)-1
-         igrdjv(1,1,iobs) = prodatqc%mj(jobs,2)-1
-         igrdiv(1,2,iobs) = prodatqc%mi(jobs,2)-1
-         igrdjv(1,2,iobs) = prodatqc%mj(jobs,2)
-         igrdiv(2,1,iobs) = prodatqc%mi(jobs,2)
-         igrdjv(2,1,iobs) = prodatqc%mj(jobs,2)-1
-         igrdiv(2,2,iobs) = prodatqc%mi(jobs,2)
-         igrdjv(2,2,iobs) = prodatqc%mj(jobs,2)
-      END DO
-
-      CALL obs_int_comm_2d( 2, 2, ipro, igrdiu, igrdju, glamu, zglamu )
-      CALL obs_int_comm_2d( 2, 2, ipro, igrdiu, igrdju, gphiu, zgphiu )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdiu, igrdju, pumask, zumask )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdiu, igrdju, pun, zintu )
-
-      CALL obs_int_comm_2d( 2, 2, ipro, igrdiv, igrdjv, glamv, zglamv )
-      CALL obs_int_comm_2d( 2, 2, ipro, igrdiv, igrdjv, gphiv, zgphiv )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdiv, igrdjv, pvmask, zvmask )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdiv, igrdjv, pvn, zintv )
-
-      ! At the end of the day also get interpolated means
-      IF ( idayend == 0 ) THEN
-
-         ALLOCATE( &
-            & zinmu(2,2,kpk,ipro),  &
-            & zinmv(2,2,kpk,ipro)   &
-            & )
-
-         CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdiu, igrdju, &
-            &                  prodatqc%vdmean(:,:,:,1), zinmu )
-         CALL obs_int_comm_3d( 2, 2, ipro, kpk, igrdiv, igrdjv, &
-            &                  prodatqc%vdmean(:,:,:,2), zinmv )
-
-      ENDIF
-
-! loop over observations
-
-      DO jobs = prodatqc%nprofup + 1, prodatqc%nprofup + ipro
-
-         iobs = jobs - prodatqc%nprofup
-
-         IF ( kt /= prodatqc%mstp(jobs) ) THEN
-            
-            IF(lwp) THEN
-               WRITE(numout,*)
-               WRITE(numout,*) ' E R R O R : Observation',              &
-                  &            ' time step is not consistent with the', &
-                  &            ' model time step'
-               WRITE(numout,*) ' ========='
-               WRITE(numout,*)
-               WRITE(numout,*) ' Record  = ', jobs,                    &
-                  &            ' kt      = ', kt,                      &
-                  &            ' mstp    = ', prodatqc%mstp(jobs), &
-                  &            ' ntyp    = ', prodatqc%ntyp(jobs)
-            ENDIF
-            CALL ctl_stop( 'obs_pro_opt', 'Inconsistent time' )
-         ENDIF
-         
-         zlam = prodatqc%rlam(jobs)
-         zphi = prodatqc%rphi(jobs)
-
-         ! Initialize observation masks
-
-         zobsmasku(:) = 0.0
-         zobsmaskv(:) = 0.0
-         
-         ! Horizontal weights and vertical mask
-
-         IF  ( prodatqc%npvend(jobs,1) > 0 ) THEN
-
-            CALL obs_int_h2d_init( kpk, kpk, k2dint, zlam, zphi,     &
-               &                   zglamu(:,:,iobs), zgphiu(:,:,iobs), &
-               &                   zumask(:,:,:,iobs), zweigu, zobsmasku )
-
-         ENDIF
-
-         
-         IF ( prodatqc%npvend(jobs,2) > 0 ) THEN
-
-            CALL obs_int_h2d_init( kpk, kpk, k2dint, zlam, zphi,     &
-               &                   zglamv(:,:,iobs), zgphiv(:,:,iobs), &
-               &                   zvmask(:,:,:,iobs), zweigv, zobsmasku )
-
-         ENDIF
-
-         ! Ensure that the vertical mask on u and v are consistent.
-
-         zobsmask(:) = MIN( zobsmasku(:), zobsmaskv(:) )
-
-         IF ( prodatqc%npvend(jobs,1) > 0 ) THEN
-
-            zobsk(:) = obfillflt
-
-	    IF ( ld_dailyav ) THEN
-
-               IF ( idayend == 0 )  THEN
-                  
-                  ! Daily averaged data
-                  
-                  CALL obs_int_h2d( kpk, kpk,      &
-                     &              zweigu, zinmu(:,:,:,iobs), zobsk )
-                  
-                  
-               ELSE
-               
-                  CALL ctl_stop( ' A nonzero' //     &
-                     &           ' number of U profile data should' // &
-                     &           ' only occur at the end of a given day' )
-
-               ENDIF
-	       
-            ELSE 
-               
-               ! Point data
-
-               CALL obs_int_h2d( kpk, kpk,      &
-                  &              zweigu, zintu(:,:,:,iobs), zobsk )
-
-            ENDIF
-
-            !-------------------------------------------------------------
-            ! Compute vertical second-derivative of the interpolating 
-            ! polynomial at obs points
-            !-------------------------------------------------------------
-            
-            IF ( k1dint == 1 ) THEN
-               CALL obs_int_z1d_spl( kpk, zobsk, zobs2k,   &
-                  &                  pgdept, zobsmask )
-            ENDIF
-            
-            !-----------------------------------------------------------------
-            !  Vertical interpolation to the observation point
-            !-----------------------------------------------------------------
-            ista = prodatqc%npvsta(jobs,1)
-            iend = prodatqc%npvend(jobs,1)
-            CALL obs_int_z1d( kpk,                &
-               & prodatqc%var(1)%mvk(ista:iend),  &
-               & k1dint, iend - ista + 1,         &
-               & prodatqc%var(1)%vdep(ista:iend), &
-               & zobsk, zobs2k,                   &
-               & prodatqc%var(1)%vmod(ista:iend), &
-               & pgdept, zobsmask )
-
-         ENDIF
-
-         IF ( prodatqc%npvend(jobs,2) > 0 ) THEN
-
-            zobsk(:) = obfillflt
-
-            IF ( ld_dailyav ) THEN
-
-               IF ( idayend == 0 )  THEN
-
-                  ! Daily averaged data
-                  
-                  CALL obs_int_h2d( kpk, kpk,      &
-                     &              zweigv, zinmv(:,:,:,iobs), zobsk )
-                  
-               ELSE
-
-                  CALL ctl_stop( ' A nonzero' //     &
-                     &           ' number of V profile data should' // &
-                     &           ' only occur at the end of a given day' )
-
-               ENDIF
-
-            ELSE
-               
-               ! Point data
-
-               CALL obs_int_h2d( kpk, kpk,      &
-                  &              zweigv, zintv(:,:,:,iobs), zobsk )
-
-            ENDIF
-
-
-            !-------------------------------------------------------------
-            ! Compute vertical second-derivative of the interpolating 
-            ! polynomial at obs points
-            !-------------------------------------------------------------
-            
-            IF ( k1dint == 1 ) THEN
-               CALL obs_int_z1d_spl( kpk, zobsk, zobs2k, &
-                  &                  pgdept, zobsmask )
-            ENDIF
-            
-            !----------------------------------------------------------------
-            !  Vertical interpolation to the observation point
-            !----------------------------------------------------------------
-            ista = prodatqc%npvsta(jobs,2)
-            iend = prodatqc%npvend(jobs,2)
-            CALL obs_int_z1d( kpk, &
-               & prodatqc%var(2)%mvk(ista:iend),&
-               & k1dint, iend - ista + 1, &
-               & prodatqc%var(2)%vdep(ista:iend),&
-               & zobsk, zobs2k, &
-               & prodatqc%var(2)%vmod(ista:iend),&
-               & pgdept, zobsmask )
-
-         ENDIF
-
-      END DO
- 
-      ! Deallocate the data for interpolation
-      DEALLOCATE( &
-         & igrdiu, &
-         & igrdju, &
-         & igrdiv, &
-         & igrdjv, &
-         & zglamu, zglamv, &
-         & zgphiu, zgphiv, &
-         & zumask, zvmask, &
-         & zintu, &
-         & zintv  &
-         & )
-      ! At the end of the day also get interpolated means
-      IF ( idayend == 0 ) THEN
-         DEALLOCATE( &
-            & zinmu,  &
-            & zinmv   &
-            & )
-      ENDIF
-
-      prodatqc%nprofup = prodatqc%nprofup + ipro 
-      
-   END SUBROUTINE obs_vel_opt
+
+      surfdataqc%nsurfup = surfdataqc%nsurfup + isurf
+
+   END SUBROUTINE obs_surf_opt
 
 END MODULE obs_oper
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 5658)
+++ branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 5659)
@@ -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
 
    !!----------------------------------------------------------------------
@@ -51,297 +45,11 @@
 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 +60,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 +71,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 SLA data
+      TYPE(obs_surf), INTENT(INOUT) :: surfdataqc   ! Subset of SLA data not failing screening
       LOGICAL, INTENT(IN) :: ld_nea         ! Switch for rejecting observation near land
       !! * Local declarations
@@ -411,21 +119,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 +143,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 +157,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,24 +185,24 @@
       IF(lwp) THEN
          WRITE(numout,*)
-         WRITE(numout,*) 'obs_pre_sla :'
+         WRITE(numout,*) 'obs_pre_surf :'
          WRITE(numout,*) '~~~~~~~~~~~'
          WRITE(numout,*)
-         WRITE(numout,*) ' SLA data outside time domain                  = ', &
+         WRITE(numout,*) ' Surface data outside time domain               = ', &
             &            iotdobsmpp
-         WRITE(numout,*) ' Remaining SLA data that failed grid search    = ', &
+         WRITE(numout,*) ' Remaining surface data that failed grid search    = ', &
             &            igrdobsmpp
-         WRITE(numout,*) ' Remaining SLA data outside space domain       = ', &
+         WRITE(numout,*) ' Remaining surface data outside space domain       = ', &
             &            iosdsobsmpp
-         WRITE(numout,*) ' Remaining SLA data at land points             = ', &
+         WRITE(numout,*) ' Remaining surface data at land points             = ', &
             &            ilansobsmpp
          IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining SLA data near land points (removed) = ', &
+            WRITE(numout,*) ' Remaining surface data near land points (removed) = ', &
                &            inlasobsmpp
          ELSE
-            WRITE(numout,*) ' Remaining SLA data near land points (kept)    = ', &
+            WRITE(numout,*) ' Remaining surface data near land points (kept)    = ', &
                &            inlasobsmpp
          ENDIF
-         WRITE(numout,*) ' SLA data accepted                             = ', &
-            &            sladatqc%nsurfmpp
+         WRITE(numout,*) ' surface data accepted                             = ', &
+            &            surfdataqc%nsurfmpp
 
          WRITE(numout,*)
@@ -505,10 +213,10 @@
       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,5 +224,5 @@
          DO jstp = nit000 - 1, nitend
             inrc = jstp - nit000 + 2
-            WRITE(numout,1999) jstp, sladatqc%nsstpmpp(inrc)
+            WRITE(numout,1999) jstp, surfdataqc%nsstpmpp(inrc)
          END DO
       ENDIF
@@ -524,383 +232,14 @@
 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 :
-      !!   
-      !! History :
-      !!        !  2007-03  (S. Ricci) SST data preparation 
-      !!----------------------------------------------------------------------
-      !! * 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) :: 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
+   END SUBROUTINE obs_pre_surf
+
+
+   SUBROUTINE obs_pre_prof( profdata, prodatqc, ld_vel3d, ld_nea, ld_dailyav )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE obs_pre_prof  ***
+      !!
+      !! ** Purpose : First level check and screening of profiles
+      !!
+      !! ** Method  : First level check and screening of profiles
       !!
       !! History :
@@ -908,4 +247,5 @@
       !!        !  2008-09  (M. Valdivieso) : TAO velocity data
       !!        !  2009-01  (K. Mogensen) : New feedback strictuer
+      !!        !  2015-02  (M. Martin) : Combined profile routine.
       !!
       !!----------------------------------------------------------------------
@@ -962,5 +302,5 @@
       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'
 
       ! Initial date initialization (year, month, day, hour, minute)
@@ -1186,5 +526,5 @@
 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, &
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prof_io.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prof_io.F90	(revision 5658)
+++ 	(revision )
@@ -1,32 +1,0 @@
-MODULE obs_prof_io
-   !!======================================================================
-   !!                       ***  MODULE obs_prof_io  ***
-   !! Observation operators : I/O for ENACT and Coriolis files
-   !!======================================================================
-   !! History : 
-   !!             !  09-01  (K. Mogensen) Initial version
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!   read_enactfile    :  Read a obfbdata structure from an ENACT file.
-   !!   read_coriofile    :  Read a obfbdata structure from an Coriolis file.
-   !!----------------------------------------------------------------------
-   USE par_kind
-   USE obs_utils
-   USE obs_fbm
-   USE obs_conv
-   USE netcdf
-   IMPLICIT NONE
-
-   INTEGER, PARAMETER :: imaxlev = 10000
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-#include "obsprof_io.h90"
-
-END MODULE obs_prof_io
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90	(revision 5658)
+++ branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90	(revision 5659)
@@ -33,5 +33,5 @@
    PRIVATE
 
-   PUBLIC obs_rea_pro_dri  ! Read the profile observations 
+   PUBLIC obs_rea_prof  ! Read the profile observations 
 
    !!----------------------------------------------------------------------
@@ -43,17 +43,16 @@
 CONTAINS
  
-   SUBROUTINE obs_rea_pro_dri( kformat, &
-      &                        profdata, knumfiles, cfilenames, &
-      &                        kvars, kextr, kstp, ddobsini, ddobsend, &
-      &                        ldt3d, lds3d, ldignmis, ldsatt, ldavtimset, &
-      &                        ldmod, kdailyavtypes )
+   SUBROUTINE obs_rea_prof( profdata, knumfiles, cfilenames, &
+      &                     kvars, kextr, kstp, ddobsini, ddobsend, &
+      &                     ldt3d, lds3d, ldignmis, ldsatt, ldavtimset, &
+      &                     ldmod, kdailyavtypes )
       !!---------------------------------------------------------------------
       !!
-      !!                   *** ROUTINE obs_rea_pro_dri ***
+      !!                   *** ROUTINE obs_rea_prof ***
       !!
       !! ** Purpose : Read from file the profile observations
       !!
-      !! ** Method  : Depending on kformat either ENACT, CORIOLIS or
-      !!              feedback data files are read
+      !! ** Method  : Read feedback data in and transform to NEMO internal 
+      !!              profile data structure
       !!
       !! ** Action  : 
@@ -67,7 +66,4 @@
    
       !! * Arguments
-      INTEGER ::  kformat    ! Format of input data
-      !                      ! 1: ENACT
-      !                      ! 2: Coriolis
       TYPE(obs_prof), INTENT(OUT) ::  profdata     ! Profile data to be read
       INTEGER, INTENT(IN) :: knumfiles      ! Number of files to read in
@@ -89,5 +85,5 @@
 
       !! * Local declarations
-      CHARACTER(LEN=15), PARAMETER :: cpname='obs_rea_pro_dri'
+      CHARACTER(LEN=15), PARAMETER :: cpname='obs_rea_prof'
       INTEGER :: jvar
       INTEGER :: ji
@@ -195,5 +191,5 @@
          !---------------------------------------------------------------------
          
-         iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
+         iflag = nf90_open( TRIM( cfilenames(jj) ), nf90_nowrite, &
             &                      i_file_id )
          
@@ -202,8 +198,8 @@
             IF ( ldignmis ) THEN
                inpfiles(jj)%nobs = 0
-               CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
+               CALL ctl_warn( 'File ' // TRIM( cfilenames(jj) ) // &
                   &           ' not found' )
             ELSE 
-               CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
+               CALL ctl_stop( 'File ' // TRIM( cfilenames(jj) ) // &
                   &           ' not found' )
             ENDIF
@@ -220,37 +216,20 @@
             !  Read the profile file into inpfiles
             !------------------------------------------------------------------
-            IF ( kformat == 0 ) THEN
-               CALL init_obfbdata( inpfiles(jj) )
-               IF(lwp) THEN
-                  WRITE(numout,*)
-                  WRITE(numout,*)'Reading from feedback file :', &
-                     &           TRIM( cfilenames(jj) )
-               ENDIF
-               CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                ldgrid = .TRUE. )
-               IF ( inpfiles(jj)%nvar < 2 ) THEN
-                  CALL ctl_stop( 'Feedback format error' )
-                  RETURN
-               ENDIF
-               IF ( TRIM(inpfiles(jj)%cname(1)) /= 'POTM' ) THEN
-                  CALL ctl_stop( 'Feedback format error' )
-                  RETURN
-               ENDIF
-               IF ( TRIM(inpfiles(jj)%cname(2)) /= 'PSAL' ) THEN
-                  CALL ctl_stop( 'Feedback format error' )
-                  RETURN
-               ENDIF
-               IF ( ldmod .AND. ( inpfiles(jj)%nadd == 0 ) ) THEN
-                  CALL ctl_stop( 'Model not in input data' )
-                  RETURN
-               ENDIF
-            ELSEIF ( kformat == 1 ) THEN
-               CALL read_enactfile( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                 numout, lwp, .TRUE. )
-            ELSEIF ( kformat == 2 ) THEN
-               CALL read_coriofile( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                 numout, lwp, .TRUE. )
-            ELSE
-               CALL ctl_stop( 'File format unknown' )
+            CALL init_obfbdata( inpfiles(jj) )
+            IF(lwp) THEN
+               WRITE(numout,*)
+               WRITE(numout,*)'Reading from feedback file :', &
+                  &           TRIM( cfilenames(jj) )
+            ENDIF
+            CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
+               &                ldgrid = .TRUE. )
+               
+            IF ( inpfiles(jj)%nvar < 2 ) THEN
+               CALL ctl_stop( 'Feedback format error' )
+               RETURN
+            ENDIF
+            IF ( ldmod .AND. ( inpfiles(jj)%nadd == 0 ) ) THEN
+               CALL ctl_stop( 'Model not in input data' )
+               RETURN
             ENDIF
             
@@ -836,5 +815,5 @@
       DEALLOCATE( inpfiles )
 
-   END SUBROUTINE obs_rea_pro_dri
+   END SUBROUTINE obs_rea_prof
 
 END MODULE obs_read_prof
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_seaice.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_seaice.F90	(revision 5658)
+++ 	(revision )
@@ -1,465 +1,0 @@
-MODULE obs_read_seaice
-   !!======================================================================
-   !!                       ***  MODULE obs_read_seaice  ***
-   !! Observation diagnostics: Read the along track SEAICE data from
-   !!                          GHRSST or any SEAICE data from feedback files
-   !!======================================================================
-
-   !!----------------------------------------------------------------------
-   !!   obs_rea_seaice : Driver for reading seaice data from the GHRSST/feedback
-   !!----------------------------------------------------------------------
-
-   !! * Modules used   
-   USE par_kind                 ! Precision variables
-   USE in_out_manager           ! I/O manager
-   USE dom_oce                  ! Ocean space and time domain variables
-   USE obs_mpp                  ! MPP support routines for observation diagnostics
-   USE julian                   ! Julian date routines
-   USE obs_utils                ! Observation operator utility functions
-   USE obs_grid                 ! Grid search
-   USE obs_sort                 ! Sorting observation arrays
-   USE obs_surf_def             ! Surface observation definitions
-   USE obs_types                ! Observation type definitions
-   USE obs_seaice_io            ! I/O for seaice files
-   USE iom                      ! I/O of fields for Reynolds data
-   USE netcdf                   ! NetCDF library
-
-   IMPLICIT NONE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC obs_rea_seaice      ! Read the seaice observations from the point data
-   
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE obs_rea_seaice( kformat, &
-      &                    seaicedata, knumfiles, cfilenames, &
-      &                    kvars, kextr, kstp, ddobsini, ddobsend, &
-      &                    ldignmis, ldmod )
-      !!---------------------------------------------------------------------
-      !!
-      !!                   *** ROUTINE obs_rea_seaice ***
-      !!
-      !! ** Purpose : Read from file the seaice data
-      !!
-      !! ** Method  : Depending on kformat either AVISO or
-      !!              feedback data files are read
-      !!
-      !! ** Action  : 
-      !!
-      !!
-      !! History :  
-      !!      ! :  2009-01 (K. Mogensen) Initial version based on old versions
-      !!----------------------------------------------------------------------
-      !! * Modules used
-
-      !! * Arguments
-      INTEGER :: kformat   ! Format of input data 
-      !                    ! 0: Feedback
-      !                    ! 1: GHRSST
-      TYPE(obs_surf), INTENT(INOUT) :: &
-         & seaicedata     ! seaice data to be read
-      INTEGER, INTENT(IN) :: knumfiles   ! Number of corio format files to read in
-      CHARACTER(LEN=128), INTENT(IN) :: cfilenames(knumfiles) ! File names to read in
-      INTEGER, INTENT(IN) :: kvars    ! Number of variables in seaicedata
-      INTEGER, INTENT(IN) :: kextr    ! Number of extra fields for each var in seaicedata
-      INTEGER, INTENT(IN) :: kstp     ! Ocean time-step index
-      LOGICAL, INTENT(IN) :: ldignmis   ! Ignore missing files
-      LOGICAL, INTENT(IN) :: ldmod      ! Initialize model from input data
-      REAL(KIND=dp), INTENT(IN) :: ddobsini    ! Obs. ini time in YYYYMMDD.HHMMSS
-      REAL(KIND=dp), INTENT(IN) :: ddobsend    ! Obs. end time in YYYYMMDD.HHMMSS
-         
-      !! * Local declarations
-      CHARACTER(LEN=14), PARAMETER :: cpname='obs_rea_seaice'
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jk
-      INTEGER :: iflag
-      INTEGER :: inobf
-      INTEGER :: i_file_id
-      INTEGER :: inowin
-      INTEGER :: iyea
-      INTEGER :: imon
-      INTEGER :: iday
-      INTEGER :: ihou
-      INTEGER :: imin
-      INTEGER :: isec
-      INTEGER, DIMENSION(knumfiles) :: &
-         & irefdate
-      INTEGER :: iobsmpp
-      INTEGER, PARAMETER :: iseaicemaxtype = 1024
-      INTEGER, DIMENSION(0:iseaicemaxtype) :: &
-         & ityp, &
-         & itypmpp
-      INTEGER, DIMENSION(:), ALLOCATABLE :: &
-         & iobsi,    &
-         & iobsj,    &
-         & iproc,    &
-         & iindx,    &
-         & ifileidx, &
-         & iseaiceidx
-      INTEGER :: itype
-      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zphi, &
-         & zlam
-      real(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zdat
-      LOGICAL :: llvalprof
-      TYPE(obfbdata), POINTER, DIMENSION(:) :: &
-         & inpfiles
-      real(wp), DIMENSION(knumfiles) :: &
-         & djulini, &
-         & djulend
-      INTEGER :: iobs
-      INTEGER :: iobstot
-      INTEGER :: ios
-      INTEGER :: ioserrcount
-      CHARACTER(len=8) :: cl_refdate
-   
-      ! Local initialization
-      iobs = 0
- 
-      !-----------------------------------------------------------------------
-      ! Check data the model part is just with feedback data files
-      !-----------------------------------------------------------------------
-      IF ( ldmod .AND. ( kformat /= 0 ) ) THEN
-         CALL ctl_stop( 'Model can only be read from feedback data' )
-         RETURN
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Count the number of files needed and allocate the obfbdata type
-      !-----------------------------------------------------------------------
-      
-      inobf = knumfiles
-      
-      ALLOCATE( inpfiles(inobf) )
-
-      seaice_files : DO jj = 1, inobf
-          
-         !---------------------------------------------------------------------
-         ! Prints
-         !---------------------------------------------------------------------
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) ' obs_rea_seaice : Reading from file = ', &
-               & TRIM( TRIM( cfilenames(jj) ) )
-            WRITE(numout,*) ' ~~~~~~~~~~~~~~'
-            WRITE(numout,*)
-         ENDIF
-
-         !---------------------------------------------------------------------
-         !  Initialization: Open file and get dimensions only
-         !---------------------------------------------------------------------
-         
-         iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
-            &                      i_file_id )
-         
-         IF ( iflag /= nf90_noerr ) THEN
-
-            IF ( ldignmis ) THEN
-               inpfiles(jj)%nobs = 0
-               CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ELSE 
-               CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ENDIF
-
-         ELSE 
-            
-            !------------------------------------------------------------------
-            !  Close the file since it is opened in read_proffile
-            !------------------------------------------------------------------
-            
-            iflag = nf90_close( i_file_id )
-
-            !------------------------------------------------------------------
-            !  Read the profile file into inpfiles
-            !------------------------------------------------------------------
-            IF ( kformat == 0 ) THEN
-               CALL init_obfbdata( inpfiles(jj) )
-               IF(lwp) THEN
-                  WRITE(numout,*)
-                  WRITE(numout,*)'Reading from feedback file :', &
-                     &           TRIM( cfilenames(jj) )
-               ENDIF
-               CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                ldgrid = .TRUE. )
-               IF ( ldmod .AND. ( ( inpfiles(jj)%nadd == 0 ) .OR.&
-                  &               ( inpfiles(jj)%next < 2 ) ) ) THEN
-                  CALL ctl_stop( 'Model not in input data' )
-                  RETURN
-               ENDIF
-            ELSEIF ( kformat == 1) THEN
-               CALL read_seaice( TRIM( cfilenames(jj) ), inpfiles(jj), &
-               &                 numout, lwp, .TRUE. )
-            ELSE
-               CALL ctl_stop( 'File format unknown' )
-            ENDIF
-
-            !------------------------------------------------------------------
-            !  Change longitude (-180,180)
-            !------------------------------------------------------------------
-
-            DO ji = 1, inpfiles(jj)%nobs 
-
-               IF ( inpfiles(jj)%plam(ji) < -180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) + 360.
-
-               IF ( inpfiles(jj)%plam(ji) >  180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) - 360.
-
-            END DO
-
-            !------------------------------------------------------------------
-            !  Calculate the date  (change eventually)
-            !------------------------------------------------------------------
-            cl_refdate=inpfiles(jj)%cdjuldref(1:8)
-            READ(cl_refdate,'(I8)') irefdate(jj)
-            
-            CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
-               &           krefdate = irefdate(jj) )
-            CALL ddatetoymdhms( ddobsend, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulend(jj), &
-               &           krefdate = irefdate(jj) )
-            IF ( inpfiles(jj)%nobs > 0 ) THEN
-               inpfiles(jj)%iproc = -1
-               inpfiles(jj)%iobsi = -1
-               inpfiles(jj)%iobsj = -1
-            ENDIF
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-               ENDIF
-            END DO
-            ALLOCATE( zlam(inowin)  )
-            ALLOCATE( zphi(inowin)  )
-            ALLOCATE( iobsi(inowin) )
-            ALLOCATE( iobsj(inowin) )
-            ALLOCATE( iproc(inowin) )
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  zlam(inowin) = inpfiles(jj)%plam(ji)
-                  zphi(inowin) = inpfiles(jj)%pphi(ji)
-               ENDIF
-            END DO
-
-            CALL obs_grid_search( inowin, zlam, zphi, iobsi, iobsj, iproc, 'T' )
-
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  inpfiles(jj)%iproc(ji,1) = iproc(inowin)
-                  inpfiles(jj)%iobsi(ji,1) = iobsi(inowin)
-                  inpfiles(jj)%iobsj(ji,1) = iobsj(inowin)
-               ENDIF
-            END DO
-            DEALLOCATE( zlam, zphi, iobsi, iobsj, iproc )
-
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  IF ( nproc == 0 ) THEN
-                     IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-                  ELSE
-                     IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-                  ENDIF
-                  llvalprof = .FALSE.
-                  IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-                     & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
-                     iobs = iobs + 1
-                  ENDIF
-               ENDIF
-            END DO
-
-         ENDIF
-
-      END DO seaice_files
-
-      !-----------------------------------------------------------------------
-      ! Get the time ordered indices of the input data
-      !-----------------------------------------------------------------------
-
-      !---------------------------------------------------------------------
-      !  Loop over input data files to count total number of profiles
-      !---------------------------------------------------------------------
-      iobstot = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               iobstot = iobstot + 1
-            ENDIF
-         END DO
-      END DO
-
-      ALLOCATE( iindx(iobstot), ifileidx(iobstot), &
-         &      iseaiceidx(iobstot), zdat(iobstot) )
-      jk = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               jk = jk + 1
-               ifileidx(jk) = jj
-               iseaiceidx(jk) = ji
-               zdat(jk)     = inpfiles(jj)%ptim(ji)
-            ENDIF
-         END DO
-      END DO
-      CALL sort_dp_indx( iobstot, &
-         &               zdat,     &
-         &               iindx   )
-      
-      CALL obs_surf_alloc( seaicedata, iobs, & 
-                           kvars, kextr, kstp, jpi, jpj )
-      
-      ! * Read obs/positions, QC, all variable and assign to seaicedata
- 
-      iobs = 0
-
-      ityp   (:) = 0
-      itypmpp(:) = 0
-
-      ioserrcount=0      
-
-      DO jk = 1, iobstot
-         
-         jj = ifileidx(iindx(jk))
-         ji = iseaiceidx(iindx(jk))
-         IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
-            & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
-            
-            IF ( nproc == 0 ) THEN
-               IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-            ELSE
-               IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-            ENDIF
-            
-            ! Set observation information
-            
-            IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-               & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
-
-               iobs = iobs + 1
-
-               CALL jul2greg( isec,                   &
-                  &           imin,                   &
-                  &           ihou,                   &
-                  &           iday,                   &
-                  &           imon,                   &
-                  &           iyea,                   &
-                  &           inpfiles(jj)%ptim(ji), &
-                  &           irefdate(jj) )
-
-
-               ! seaice time coordinates
-               seaicedata%nyea(iobs) = iyea
-               seaicedata%nmon(iobs) = imon
-               seaicedata%nday(iobs) = iday
-               seaicedata%nhou(iobs) = ihou
-               seaicedata%nmin(iobs) = imin
-               
-               ! seaice space coordinates
-               seaicedata%rlam(iobs) = inpfiles(jj)%plam(ji)
-               seaicedata%rphi(iobs) = inpfiles(jj)%pphi(ji)
-
-               ! Coordinate search parameters
-               seaicedata%mi  (iobs) = inpfiles(jj)%iobsi(ji,1)
-               seaicedata%mj  (iobs) = inpfiles(jj)%iobsj(ji,1)
-               
-               ! Instrument type
-               READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
-901            IF ( ios /= 0 ) THEN
-                  IF (ioserrcount == 0) CALL ctl_warn ( 'Problem converting an instrument type to integer. Setting type to zero' ) 
-                  ioserrcount = ioserrcount + 1
-                  itype = 0
-               ENDIF
-               seaicedata%ntyp(iobs) = itype
-               IF ( itype < iseaicemaxtype + 1 ) THEN
-                  ityp(itype+1) = ityp(itype+1) + 1
-               ELSE
-                  IF(lwp)WRITE(numout,*)'WARNING:Increase iseaicemaxtype in ',&
-                     &                  cpname
-               ENDIF
-
-               ! Bookkeeping data to match observations
-               seaicedata%nsidx(iobs) = iobs
-               seaicedata%nsfil(iobs) = iindx(jk)
-
-               ! QC flags
-               seaicedata%nqc(iobs) = inpfiles(jj)%ivqc(ji,1)
-
-               ! Observed value
-               seaicedata%robs(iobs,1) = inpfiles(jj)%pob(1,ji,1)
-
-
-               ! Model and MDT is set to fbrmdi unless read from file
-               IF ( ldmod ) THEN
-                  seaicedata%rmod(iobs,1) = inpfiles(jj)%padd(1,ji,1,1)
-               ELSE
-                  seaicedata%rmod(iobs,1) = fbrmdi
-               ENDIF
-            ENDIF
-         ENDIF
-
-      END DO
-
-      !-----------------------------------------------------------------------
-      ! Sum up over processors
-      !-----------------------------------------------------------------------
-      
-      CALL obs_mpp_sum_integer( iobs, iobsmpp )
-      
-      !-----------------------------------------------------------------------
-      ! Output number of observations.
-      !-----------------------------------------------------------------------
-      IF (lwp) THEN
-
-         WRITE(numout,*)
-         WRITE(numout,'(1X,A)')'Seaice data types'
-         WRITE(numout,'(1X,A)')'-----------------'
-         DO jj = 1,8
-            IF ( itypmpp(jj) > 0 ) THEN
-               WRITE(numout,'(1X,A4,I4,A3,I10)')'Type ', jj,' = ',itypmpp(jj)
-            ENDIF
-         END DO
-         WRITE(numout,'(1X,A50)')'--------------------------------------------------'
-         WRITE(numout,'(1X,A40,I10)')'Total                                 = ',iobsmpp
-         WRITE(numout,*)
-
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Deallocate temporary data
-      !-----------------------------------------------------------------------
-      DEALLOCATE( ifileidx, iseaiceidx, zdat )
-
-      !-----------------------------------------------------------------------
-      ! Deallocate input data
-      !-----------------------------------------------------------------------
-      DO jj = 1, inobf
-         CALL dealloc_obfbdata( inpfiles(jj) )
-      END DO
-      DEALLOCATE( inpfiles )
-
-   END SUBROUTINE obs_rea_seaice
-
-END MODULE obs_read_seaice
-
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sla.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sla.F90	(revision 5658)
+++ 	(revision )
@@ -1,548 +1,0 @@
-MODULE obs_read_sla
-   !!======================================================================
-   !!                       ***  MODULE obs_read_sla  ***
-   !! Observation diagnostics: Read the along track SLA data from
-   !!                          the AVISO/CLS database or any SLA data 
-   !!                          from feedback files
-   !!======================================================================
-
-   !!----------------------------------------------------------------------
-   !!   obs_rea_sla : Driver for reading SLA data from the AVISO/CLS/feedback
-   !!----------------------------------------------------------------------
-
-   !! * Modules used   
-   USE par_kind                 ! Precision variables
-   USE in_out_manager           ! I/O manager
-   USE dom_oce                  ! Ocean space and time domain variables
-   USE obs_mpp                  ! MPP support routines for observation diagnostics
-   USE julian                   ! Julian date routines
-   USE obs_utils                ! Observation operator utility functions
-   USE obs_grid                 ! Grid search
-   USE obs_sort                 ! Sorting observation arrays
-   USE obs_surf_def             ! Surface observation definitions
-   USE obs_types                ! Observation type definitions
-   USE obs_sla_io               ! I/O for sla files
-   USE netcdf                   ! NetCDF library
-
-   IMPLICIT NONE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC obs_rea_sla  ! Read the SLA observations from the AVISO/SLA database
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE obs_rea_sla( kformat, &
-      &                    sladata, knumfiles, cfilenames, &
-      &                    kvars, kextr, kstp, ddobsini, ddobsend, &
-      &                    ldignmis, ldmod, ldobstd )
-      !!---------------------------------------------------------------------
-      !!
-      !!                   *** ROUTINE obs_rea_sla ***
-      !!
-      !! ** Purpose : Read from file the SLA data
-      !!
-      !! ** Method  : Depending on kformat either AVISO or
-      !!              feedback data files are read
-      !!
-      !! ** Action  : 
-      !!
-      !!
-      !! History :  
-      !!      ! :  2009-01 (K. Mogensen) Initial version based on old versions
-      !!----------------------------------------------------------------------
-      !! * Modules used
-
-      !! * Arguments
-      INTEGER :: kformat    ! Format of input data
-      !                     ! 0: Feedback
-      !                     ! 1: AVISO
-      TYPE(obs_surf), INTENT(INOUT) :: sladata    ! SLA data to be read
-      INTEGER, INTENT(IN) :: knumfiles      ! Number of files to read in
-      CHARACTER(LEN=128), INTENT(IN) ::  &
-         & cfilenames(knumfiles) ! File names to read in
-      INTEGER, INTENT(IN) :: kvars     ! Number of variables in sladata
-      INTEGER, INTENT(IN) :: kextr     ! Number of extra fields for each var in sladata
-      INTEGER, INTENT(IN) :: kstp      ! Ocean time-step index
-      LOGICAL, INTENT(IN) :: ldignmis    ! Ignore missing files
-      LOGICAL, INTENT(IN) :: ldmod       ! Initialize model from input data
-      LOGICAL, INTENT(INOUT), optional :: &
-         & ldobstd        ! Read observation standard deviation from fb. file
-      REAL(KIND=dp), INTENT(IN) :: ddobsini  ! Obs. ini time in YYYYMMDD.HHMMSS
-      REAL(KIND=dp), INTENT(IN) :: ddobsend  ! Obs. end time in YYYYMMDD.HHMMSS
-         
-      !! * Local declarations
-      CHARACTER(LEN=11), PARAMETER :: cpname='obs_rea_sla'
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jk
-      INTEGER :: iflag
-      INTEGER :: inobf
-      INTEGER :: i_file_id
-      INTEGER :: inowin
-      INTEGER :: iyea
-      INTEGER :: imon
-      INTEGER :: iday
-      INTEGER :: ihou
-      INTEGER :: imin
-      INTEGER :: isec
-      INTEGER, DIMENSION(knumfiles) :: &
-         & irefdate
-      INTEGER :: iobsmpp
-      INTEGER, DIMENSION(imaxmissions+1) :: &
-         & ityp, &
-         & itypmpp
-      INTEGER, DIMENSION(:), ALLOCATABLE :: &
-         & iobsi,    &
-         & iobsj,    &
-         & iproc,    &
-         & iindx,    &
-         & ifileidx, &
-         & islaidx
-      INTEGER :: itype 
-      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zphi, &
-         & zlam
-      real(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zdat
-      LOGICAL :: llvalprof
-      LOGICAL :: llobstd
-      TYPE(obfbdata), POINTER, DIMENSION(:) :: &
-         & inpfiles
-      real(wp), DIMENSION(knumfiles) :: &
-         & djulini, &
-         & djulend
-      INTEGER, DIMENSION(knumfiles) :: &
-         & iobspos, &
-         & iobcpos
-      INTEGER :: iobs
-      INTEGER :: iobstot
-      INTEGER :: ios
-      INTEGER :: ioserrcount
-      CHARACTER(len=8) :: cl_refdate
-   
-      ! Local initialization
-      iobs = 0
-      IF ( PRESENT(ldobstd) ) THEN
-         IF (.NOT.ldmod) THEN
-            llobstd = .false.
-         ELSE
-            llobstd = ldobstd
-         ENDIF
-      ELSE
-         llobstd = .FALSE.
-      ENDIF
- 
-      !-----------------------------------------------------------------------
-      ! Check that the model part is just with feedback data files
-      !-----------------------------------------------------------------------
-      IF ( ldmod .AND. ( kformat /= 0 ) ) THEN
-         CALL ctl_stop( 'Model can only be read from feedback data' )
-         RETURN
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Check that the prescribed obs err is just with feedback data files
-      !-----------------------------------------------------------------------
-      IF ( llobstd .AND. ( kformat /= 0 ) ) THEN
-         CALL ctl_stop( 'Observation error can only be read from feedback files' )
-         RETURN
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Count the number of files needed and allocate the obfbdata type
-      !-----------------------------------------------------------------------
-      
-      inobf = knumfiles
-      
-      ALLOCATE( inpfiles(inobf) )
-
-      sla_files : DO jj = 1, inobf
-          
-         !---------------------------------------------------------------------
-         ! Prints
-         !---------------------------------------------------------------------
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) ' obs_rea_sla : Reading from file = ', &
-               & TRIM( TRIM( cfilenames(jj) ) )
-            WRITE(numout,*) ' ~~~~~~~~~~~'
-            WRITE(numout,*)
-         ENDIF
-
-         !---------------------------------------------------------------------
-         !  Initialization: Open file and get dimensions only
-         !---------------------------------------------------------------------
-         
-         iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
-            &                      i_file_id )
-         
-         IF ( iflag /= nf90_noerr ) THEN
-
-            IF ( ldignmis ) THEN
-               inpfiles(jj)%nobs = 0
-               CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ELSE 
-               CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ENDIF
-
-         ELSE 
-            
-            !------------------------------------------------------------------
-            !  Close the file since it is opened in read_proffile
-            !------------------------------------------------------------------
-            
-            iflag = nf90_close( i_file_id )
-
-            !------------------------------------------------------------------
-            !  Read the profile file into inpfiles
-            !------------------------------------------------------------------
-            IF ( kformat == 0 ) THEN
-               CALL init_obfbdata( inpfiles(jj) )
-               IF(lwp) THEN
-                  WRITE(numout,*)
-                  WRITE(numout,*)'Reading from feedback file :', &
-                     &           TRIM( cfilenames(jj) )
-               ENDIF
-               CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                ldgrid = .TRUE. )
-               IF ( inpfiles(jj)%nvar < 1 ) THEN
-                  CALL ctl_stop( 'Feedback format error' )
-                  RETURN
-               ENDIF
-               IF ( TRIM(inpfiles(jj)%cname(1)) /= 'SLA' ) THEN
-                  CALL ctl_stop( 'Feedback format error' )
-                  RETURN
-               ENDIF 
-               IF ( ldmod .AND. ( ( inpfiles(jj)%nadd == 0 ) .OR.&
-                  &               ( inpfiles(jj)%next == 0 ) ) ) THEN
-                  CALL ctl_stop( 'Model not in input data' )
-                  RETURN
-               ENDIF
-            ELSEIF ( kformat == 1) THEN
-               CALL read_avisofile( TRIM( cfilenames(jj) ), inpfiles(jj), &
-               &                    numout, lwp, .TRUE. )
-            ELSE
-               CALL ctl_stop( 'File format unknown' )
-            ENDIF
-
-            !------------------------------------------------------------------
-            !  Change longitude (-180,180)
-            !------------------------------------------------------------------
-
-            DO ji = 1, inpfiles(jj)%nobs 
-
-               IF ( inpfiles(jj)%plam(ji) < -180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) + 360.
-
-               IF ( inpfiles(jj)%plam(ji) >  180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) - 360.
-
-            END DO
-
-            !------------------------------------------------------------------
-            !  Calculate the date  (change eventually)
-            !------------------------------------------------------------------
-            cl_refdate=inpfiles(jj)%cdjuldref(1:8)
-            READ(cl_refdate,'(I8)') irefdate(jj)
-            
-            CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
-               &           krefdate = irefdate(jj) )
-            CALL ddatetoymdhms( ddobsend, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulend(jj), &
-               &           krefdate = irefdate(jj) )
-            IF ( inpfiles(jj)%nobs > 0 ) THEN
-               inpfiles(jj)%iproc = -1
-               inpfiles(jj)%iobsi = -1
-               inpfiles(jj)%iobsj = -1
-            ENDIF
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-               IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-               ENDIF
-            END DO
-            ALLOCATE( zlam(inowin)  )
-            ALLOCATE( zphi(inowin)  )
-            ALLOCATE( iobsi(inowin) )
-            ALLOCATE( iobsj(inowin) )
-            ALLOCATE( iproc(inowin) )
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-               IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  zlam(inowin) = inpfiles(jj)%plam(ji)
-                  zphi(inowin) = inpfiles(jj)%pphi(ji)
-               ENDIF
-            END DO
-
-            CALL obs_grid_search( inowin, zlam, zphi, iobsi, iobsj, iproc, 'T' )
-
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-               IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  inpfiles(jj)%iproc(ji,1) = iproc(inowin)
-                  inpfiles(jj)%iobsi(ji,1) = iobsi(inowin)
-                  inpfiles(jj)%iobsj(ji,1) = iobsj(inowin)
-               ENDIF
-            END DO
-            DEALLOCATE( zlam, zphi, iobsi, iobsj, iproc )
-
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-               IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  IF ( nproc == 0 ) THEN
-                     IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-                  ELSE
-                     IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-                  ENDIF
-                  llvalprof = .FALSE.
-                  IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-                     & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
-                     iobs = iobs + 1
-                  ENDIF
-               ENDIF
-            END DO
-
-         ENDIF
-      
-      END DO sla_files
-
-      IF (llobstd) THEN
-         
-         DO jj = 1, inobf
-            iobspos(jj) = -1
-            iobcpos(jj) = -1
-            DO ji = 1,inpfiles(jj)%nadd
-               IF ( TRIM(inpfiles(jj)%caddname(ji)) == 'OSTD' ) THEN
-                  iobspos(jj)=ji
-               ENDIF
-               IF ( TRIM(inpfiles(jj)%caddname(ji)) == 'OCNT' ) THEN
-                  iobcpos(jj)=ji
-               ENDIF
-            END DO
-         END DO
-         llobstd = ( ( MINVAL(iobspos) > 0 ) .AND. ( MINVAL(iobcpos) > 0 ) )
-         IF (llobstd) THEN
-            IF (lwp) WRITE(numout,*)'SLA superobs information present.'
-         ELSE
-            IF (lwp) WRITE(numout,*)'SLA superobs information not present.'
-         ENDIF
-
-      ENDIF
-      
-      !-----------------------------------------------------------------------
-      ! Get the time ordered indices of the input data
-      !-----------------------------------------------------------------------
-
-      !---------------------------------------------------------------------
-      !  Loop over input data files to count total number of profiles
-      !---------------------------------------------------------------------
-      iobstot = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-            IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               iobstot = iobstot + 1
-            ENDIF
-         END DO
-      END DO
-
-      ALLOCATE( iindx(iobstot), ifileidx(iobstot), &
-         &      islaidx(iobstot), zdat(iobstot) )
-      jk = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-            IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               jk = jk + 1
-               ifileidx(jk) = jj
-               islaidx(jk) = ji
-               zdat(jk)     = inpfiles(jj)%ptim(ji)
-            ENDIF
-         END DO
-      END DO
-      CALL sort_dp_indx( iobstot, &
-         &               zdat,     &
-         &               iindx   )
-      
-      CALL obs_surf_alloc( sladata, iobs, kvars, kextr, kstp, jpi, jpj )
-      
-      ! * Read obs/positions, QC, all variable and assign to sladata
- 
-      iobs = 0
-
-      ityp   (:) = 0
-      itypmpp(:) = 0
-
-      ioserrcount = 0
-      
-      DO jk = 1, iobstot
-         
-         jj = ifileidx(iindx(jk))
-         ji = islaidx(iindx(jk))
-
-         IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
-         IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
-
-         IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
-            & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
-            
-            IF ( nproc == 0 ) THEN
-               IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-            ELSE
-               IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-            ENDIF
-            
-            ! Set observation information
-            
-            IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-               & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
-
-               iobs = iobs + 1
-
-               CALL jul2greg( isec,                   &
-                  &           imin,                   &
-                  &           ihou,                   &
-                  &           iday,                   &
-                  &           imon,                   &
-                  &           iyea,                   &
-                  &           inpfiles(jj)%ptim(ji), &
-                  &           irefdate(jj) )
-
-
-               ! SLA time coordinates
-               sladata%nyea(iobs) = iyea
-               sladata%nmon(iobs) = imon
-               sladata%nday(iobs) = iday
-               sladata%nhou(iobs) = ihou
-               sladata%nmin(iobs) = imin
-               
-               ! SLA space coordinates
-               sladata%rlam(iobs) = inpfiles(jj)%plam(ji)
-               sladata%rphi(iobs) = inpfiles(jj)%pphi(ji)
-
-               ! Coordinate search parameters
-               sladata%mi  (iobs) = inpfiles(jj)%iobsi(ji,1)
-               sladata%mj  (iobs) = inpfiles(jj)%iobsj(ji,1)
-               
-               ! Instrument type
-               READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
-901            IF ( ios /= 0 ) THEN
-                  IF (ioserrcount == 0) CALL ctl_warn ( 'Problem converting an instrument type to integer. Setting type to zero' ) 
-                  ioserrcount = ioserrcount + 1
-                  itype = 0
-               ENDIF
-               sladata%ntyp(iobs) = itype
-               ityp(itype+1) = ityp(itype+1) + 1
-
-               ! Identifier
-               sladata%cwmo(iobs) = inpfiles(jj)%cdwmo(ji)
-
-               ! Bookkeeping data to match observations
-               sladata%nsidx(iobs) = iobs
-               sladata%nsfil(iobs) = iindx(jk)
-
-               ! QC flags
-               sladata%nqc(iobs) = inpfiles(jj)%ivqc(ji,1)
-
-               ! Observed value
-               sladata%robs(iobs,1) = inpfiles(jj)%pob(1,ji,1)
-
-
-               ! Model and MDT is set to fbrmdi unless read from file
-               IF ( ldmod ) THEN
-                  sladata%rmod(iobs,1) = inpfiles(jj)%padd(1,ji,1,1)
-                  sladata%rext(iobs,1) = inpfiles(jj)%padd(1,ji,2,1)
-                  sladata%rext(iobs,2) = inpfiles(jj)%pext(1,ji,1)
-                  IF (llobstd) THEN
-                     sladata%rext(iobs,3) = &
-                        & inpfiles(jj)%padd(1,ji,iobspos(jj),1)
-                     sladata%rext(iobs,4) = &
-                        & inpfiles(jj)%padd(1,ji,iobcpos(jj),1)
-                  ENDIF
-               ELSE
-                  sladata%rmod(iobs,1) = fbrmdi
-                  sladata%rext(iobs,:) = fbrmdi
-               ENDIF
-
-            ENDIF
-         ENDIF
-
-      END DO
-
-      !-----------------------------------------------------------------------
-      ! Sum up over processors
-      !-----------------------------------------------------------------------
-      
-      CALL obs_mpp_sum_integer( iobs, iobsmpp )
-      CALL obs_mpp_sum_integers( ityp, itypmpp, imaxmissions + 1 )
-      
-      !-----------------------------------------------------------------------
-      ! Output number of observations.
-      !-----------------------------------------------------------------------
-      IF (lwp) THEN
-
-         WRITE(numout,*)
-         WRITE(numout,'(1X,A)')'Altimeter satellites'
-         WRITE(numout,'(1X,A)')'--------------------'
-         DO jj = 1,8
-            IF ( itypmpp(jj) > 0 ) THEN
-               WRITE(numout,'(1X,A38,A2,I10)')calttyp(jj-1),'= ',itypmpp(jj)
-            ENDIF
-         END DO
-         WRITE(numout,'(1X,A50)')'--------------------------------------------------'
-         WRITE(numout,'(1X,A40,I10)')'Total                                 = ',iobsmpp
-         WRITE(numout,*)
-
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Deallocate temporary data
-      !-----------------------------------------------------------------------
-      DEALLOCATE( ifileidx, islaidx, zdat )
-
-      !-----------------------------------------------------------------------
-      ! Deallocate input data
-      !-----------------------------------------------------------------------
-      DO jj = 1, inobf
-         CALL dealloc_obfbdata( inpfiles(jj) )
-      END DO
-      DEALLOCATE( inpfiles )
-
-      !-----------------------------------------------------------------------
-      ! Reset ldobstd if the data is present
-      !-----------------------------------------------------------------------
-      IF ( PRESENT(ldobstd) ) THEN
-         ldobstd = llobstd
-      ENDIF
-
-   END SUBROUTINE obs_rea_sla
-
-END MODULE obs_read_sla
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sst.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sst.F90	(revision 5658)
+++ 	(revision )
@@ -1,771 +1,0 @@
-MODULE obs_read_sst
-   !!======================================================================
-   !!                       ***  MODULE obs_read_sst  ***
-   !! Observation diagnostics: Read the SST data from the GHRSST database 
-   !!                          or any SST data from feedback files
-   !!======================================================================
-
-   !!----------------------------------------------------------------------
-   !!   obs_rea_sst : Driver for reading SST data from the GHRSST/feedback
-   !!   obs_rea_sst_rey : Driver for reading SST data from Reynolds
-   !!----------------------------------------------------------------------
-
-   !! * Modules used   
-   USE par_kind                 ! Precision variables
-   USE in_out_manager           ! I/O manager
-   USE dom_oce                  ! Ocean space and time domain variables
-   USE obs_mpp                  ! MPP support routines for observation diagnostics
-   USE julian                   ! Julian date routines
-   USE obs_utils                ! Observation operator utility functions
-   USE obs_grid                 ! Grid search
-   USE obs_sort                 ! Sorting observation arrays
-   USE obs_surf_def             ! Surface observation definitions
-   USE obs_types                ! Observation type definitions
-   USE obs_sst_io               ! I/O for sst files
-   USE iom                      ! I/O of fields for Reynolds data
-   USE netcdf                   ! NetCDF library
-
-   IMPLICIT NONE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC obs_rea_sst      ! Read the SST observations from the point data
-   PUBLIC obs_rea_sst_rey  ! Read the gridded Reynolds SST 
-   
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE obs_rea_sst( kformat, &
-      &                    sstdata, knumfiles, cfilenames, &
-      &                    kvars, kextr, kstp, ddobsini, ddobsend, &
-      &                    ldignmis, ldmod )
-      !!---------------------------------------------------------------------
-      !!
-      !!                   *** ROUTINE obs_rea_sst ***
-      !!
-      !! ** Purpose : Read from file the SST data
-      !!
-      !! ** Method  : Depending on kformat either AVISO or
-      !!              feedback data files are read
-      !!
-      !! ** Action  : 
-      !!
-      !!
-      !! History :  
-      !!      ! :  2009-01 (K. Mogensen) Initial version based on old versions
-      !!----------------------------------------------------------------------
-      !! * Modules used
-
-      !! * Arguments
-      INTEGER :: kformat   ! Format of input data
-      !                    ! 0: Feedback
-      !                    ! 1: GHRSST
-      TYPE(obs_surf), INTENT(INOUT) :: sstdata   ! SST data to be read
-      INTEGER, INTENT(IN) :: knumfiles    ! Number of corio format files to read in
-      CHARACTER(LEN=128), INTENT(IN) :: cfilenames(knumfiles) ! File names to read in
-      INTEGER, INTENT(IN) :: kvars      ! Number of variables in sstdata
-      INTEGER, INTENT(IN) :: kextr      ! Number of extra fields for each var in sstdata
-      INTEGER, INTENT(IN) :: kstp       ! Ocean time-step index
-      LOGICAL, INTENT(IN) :: ldignmis   ! Ignore missing files
-      LOGICAL, INTENT(IN) :: ldmod      ! Initialize model from input data
-      REAL(KIND=dp), INTENT(IN) :: ddobsini   ! Obs. ini time in YYYYMMDD.HHMMSS
-      REAL(KIND=dp), INTENT(IN) :: ddobsend   ! Obs. end time in YYYYMMDD.HHMMSS
-         
-      !! * Local declarations
-      CHARACTER(LEN=11), PARAMETER :: cpname='obs_rea_sst'
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jk
-      INTEGER :: iflag
-      INTEGER :: inobf
-      INTEGER :: i_file_id
-      INTEGER :: inowin
-      INTEGER :: iyea
-      INTEGER :: imon
-      INTEGER :: iday
-      INTEGER :: ihou
-      INTEGER :: imin
-      INTEGER :: isec
-      INTEGER, DIMENSION(knumfiles) :: irefdate
-      INTEGER :: iobsmpp
-      INTEGER, PARAMETER :: isstmaxtype = 1024
-      INTEGER, DIMENSION(0:isstmaxtype) :: &
-         & ityp, &
-         & itypmpp
-      INTEGER, DIMENSION(:), ALLOCATABLE :: &
-         & iobsi,    &
-         & iobsj,    &
-         & iproc,    &
-         & iindx,    &
-         & ifileidx, &
-         & isstidx
-      INTEGER :: itype
-      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zphi, &
-         & zlam
-      real(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zdat
-      LOGICAL :: llvalprof
-      TYPE(obfbdata), POINTER, DIMENSION(:) :: &
-         & inpfiles
-      real(wp), DIMENSION(knumfiles) :: &
-         & djulini, &
-         & djulend
-      INTEGER :: iobs
-      INTEGER :: iobstot
-      INTEGER :: ios
-      INTEGER :: ioserrcount
-      CHARACTER(len=8) :: cl_refdate
-   
-      ! Local initialization
-      iobs = 0
- 
-      !-----------------------------------------------------------------------
-      ! Check data the model part is just with feedback data files
-      !-----------------------------------------------------------------------
-      IF ( ldmod .AND. ( kformat /= 0 ) ) THEN
-         CALL ctl_stop( 'Model can only be read from feedback data' )
-         RETURN
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Count the number of files needed and allocate the obfbdata type
-      !-----------------------------------------------------------------------
-      
-      inobf = knumfiles
-      
-      ALLOCATE( inpfiles(inobf) )
-
-      sst_files : DO jj = 1, inobf
-
-         CALL init_obfbdata( inpfiles(jj) )
-          
-         !---------------------------------------------------------------------
-         ! Prints
-         !---------------------------------------------------------------------
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) ' obs_rea_sst : Reading from file = ', &
-               & TRIM( TRIM( cfilenames(jj) ) )
-            WRITE(numout,*) ' ~~~~~~~~~~~'
-            WRITE(numout,*)
-         ENDIF
-
-         !---------------------------------------------------------------------
-         !  Initialization: Open file and get dimensions only
-         !---------------------------------------------------------------------
-         
-         iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
-            &                      i_file_id )
-         
-         IF ( iflag /= nf90_noerr ) THEN
-
-            IF ( ldignmis ) THEN
-               inpfiles(jj)%nobs = 0
-               CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ELSE 
-               CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ENDIF
-
-         ELSE 
-            
-            !------------------------------------------------------------------
-            !  Close the file since it is opened in read_proffile
-            !------------------------------------------------------------------
-            
-            iflag = nf90_close( i_file_id )
-
-            !------------------------------------------------------------------
-            !  Read the profile file into inpfiles
-            !------------------------------------------------------------------
-            IF ( kformat == 0 ) THEN
-               IF(lwp) THEN
-                  WRITE(numout,*)
-                  WRITE(numout,*)'Reading from feedback file :', &
-                     &           TRIM( cfilenames(jj) )
-               ENDIF
-               CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                ldgrid = .TRUE. )
-               IF ( ldmod .AND. ( inpfiles(jj)%nadd == 0 ) ) THEN
-                  CALL ctl_stop( 'Model not in input data' )
-                  RETURN
-               ENDIF
-            ELSEIF ( kformat == 1) THEN
-               CALL read_ghrsst( TRIM( cfilenames(jj) ), inpfiles(jj), &
-               &                 numout, lwp, .TRUE. )
-            ELSE
-               CALL ctl_stop( 'File format unknown' )
-            ENDIF
-
-            !------------------------------------------------------------------
-            !  Change longitude (-180,180)
-            !------------------------------------------------------------------
-
-            DO ji = 1, inpfiles(jj)%nobs 
-
-               IF ( inpfiles(jj)%plam(ji) < -180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) + 360.
-
-               IF ( inpfiles(jj)%plam(ji) >  180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) - 360.
-
-            END DO
-
-            !------------------------------------------------------------------
-            !  Calculate the date  (change eventually)
-            !------------------------------------------------------------------
-            cl_refdate=inpfiles(jj)%cdjuldref(1:8)
-            READ(cl_refdate,'(I8)') irefdate(jj)
-            
-            CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
-               &           krefdate = irefdate(jj) )
-            CALL ddatetoymdhms( ddobsend, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulend(jj), &
-               &           krefdate = irefdate(jj) )
-            IF ( inpfiles(jj)%nobs > 0 ) THEN
-               inpfiles(jj)%iproc = -1
-               inpfiles(jj)%iobsi = -1
-               inpfiles(jj)%iobsj = -1
-            ENDIF
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-               ENDIF
-            END DO
-            ALLOCATE( zlam(inowin)  )
-            ALLOCATE( zphi(inowin)  )
-            ALLOCATE( iobsi(inowin) )
-            ALLOCATE( iobsj(inowin) )
-            ALLOCATE( iproc(inowin) )
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  zlam(inowin) = inpfiles(jj)%plam(ji)
-                  zphi(inowin) = inpfiles(jj)%pphi(ji)
-               ENDIF
-            END DO
-
-            CALL obs_grid_search( inowin, zlam, zphi, iobsi, iobsj, iproc, 'T' )
-
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  inpfiles(jj)%iproc(ji,1) = iproc(inowin)
-                  inpfiles(jj)%iobsi(ji,1) = iobsi(inowin)
-                  inpfiles(jj)%iobsj(ji,1) = iobsj(inowin)
-               ENDIF
-            END DO
-            DEALLOCATE( zlam, zphi, iobsi, iobsj, iproc )
-
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  IF ( nproc == 0 ) THEN
-                     IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-                  ELSE
-                     IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-                  ENDIF
-                  llvalprof = .FALSE.
-                  IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-                     & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
-                     iobs = iobs + 1
-                  ENDIF
-               ENDIF
-            END DO
-
-         ENDIF
-
-      END DO sst_files
-
-      !-----------------------------------------------------------------------
-      ! Get the time ordered indices of the input data
-      !-----------------------------------------------------------------------
-
-      !---------------------------------------------------------------------
-      !  Loop over input data files to count total number of profiles
-      !---------------------------------------------------------------------
-      iobstot = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               iobstot = iobstot + 1
-            ENDIF
-         END DO
-      END DO
-
-      ALLOCATE( iindx(iobstot), ifileidx(iobstot), &
-         &      isstidx(iobstot), zdat(iobstot) )
-      jk = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               jk = jk + 1
-               ifileidx(jk) = jj
-               isstidx(jk) = ji
-               zdat(jk)     = inpfiles(jj)%ptim(ji)
-            ENDIF
-         END DO
-      END DO
-      CALL sort_dp_indx( iobstot, &
-         &               zdat,     &
-         &               iindx   )
-      
-      CALL obs_surf_alloc( sstdata, iobs, kvars, kextr, kstp, jpi, jpj )
-      
-      ! * Read obs/positions, QC, all variable and assign to sstdata
- 
-      iobs = 0
-
-      ityp   (:) = 0
-      itypmpp(:) = 0
-      
-      ioserrcount = 0
-      
-      DO jk = 1, iobstot
-         
-         jj = ifileidx(iindx(jk))
-         ji = isstidx(iindx(jk))
-         IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
-            & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
-            
-            IF ( nproc == 0 ) THEN
-               IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-            ELSE
-               IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-            ENDIF
-            
-            ! Set observation information
-            
-            IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
-               & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
-
-               iobs = iobs + 1
-
-               CALL jul2greg( isec,                   &
-                  &           imin,                   &
-                  &           ihou,                   &
-                  &           iday,                   &
-                  &           imon,                   &
-                  &           iyea,                   &
-                  &           inpfiles(jj)%ptim(ji), &
-                  &           irefdate(jj) )
-
-
-               ! SST time coordinates
-               sstdata%nyea(iobs) = iyea
-               sstdata%nmon(iobs) = imon
-               sstdata%nday(iobs) = iday
-               sstdata%nhou(iobs) = ihou
-               sstdata%nmin(iobs) = imin
-               
-               ! SST space coordinates
-               sstdata%rlam(iobs) = inpfiles(jj)%plam(ji)
-               sstdata%rphi(iobs) = inpfiles(jj)%pphi(ji)
-
-               ! Coordinate search parameters
-               sstdata%mi  (iobs) = inpfiles(jj)%iobsi(ji,1)
-               sstdata%mj  (iobs) = inpfiles(jj)%iobsj(ji,1)
-               
-               ! Instrument type
-               READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
-901            IF ( ios /= 0 ) THEN
-                  IF (ioserrcount == 0) CALL ctl_warn ( 'Problem converting an instrument type to integer. Setting type to zero' ) 
-                  ioserrcount = ioserrcount + 1
-                  itype = 0
-               ENDIF
-               sstdata%ntyp(iobs) = itype
-               IF ( itype < isstmaxtype + 1 ) THEN
-                  ityp(itype+1) = ityp(itype+1) + 1
-               ELSE
-                  IF(lwp)WRITE(numout,*)'WARNING:Increase isstmaxtype in ',&
-                     &                  cpname
-               ENDIF
-
-               ! Bookkeeping data to match observations
-               sstdata%nsidx(iobs) = iobs
-               sstdata%nsfil(iobs) = iindx(jk)
-
-               ! QC flags
-               sstdata%nqc(iobs) = inpfiles(jj)%ivqc(ji,1)
-
-               ! Observed value
-               sstdata%robs(iobs,1) = inpfiles(jj)%pob(1,ji,1)
-
-
-               ! Model and MDT is set to fbrmdi unless read from file
-               IF ( ldmod ) THEN
-                  sstdata%rmod(iobs,1) = inpfiles(jj)%padd(1,ji,1,1)
-               ELSE
-                  sstdata%rmod(iobs,1) = fbrmdi
-               ENDIF
-            ENDIF
-         ENDIF
-
-      END DO
-
-      !-----------------------------------------------------------------------
-      ! Sum up over processors
-      !-----------------------------------------------------------------------
-      
-      CALL obs_mpp_sum_integer( iobs, iobsmpp )
-      
-      !-----------------------------------------------------------------------
-      ! Output number of observations.
-      !-----------------------------------------------------------------------
-      IF (lwp) THEN
-
-         WRITE(numout,*)
-         WRITE(numout,'(1X,A)')'SST data types'
-         WRITE(numout,'(1X,A)')'--------------'
-         DO jj = 1,8
-            IF ( itypmpp(jj) > 0 ) THEN
-               WRITE(numout,'(1X,A4,I4,A3,I10)')'Type ', jj,' = ',itypmpp(jj)
-            ENDIF
-         END DO
-         WRITE(numout,'(1X,A50)')'--------------------------------------------------'
-         WRITE(numout,'(1X,A40,I10)')'Total                                 = ',iobsmpp
-         WRITE(numout,*)
-
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Deallocate temporary data
-      !-----------------------------------------------------------------------
-      DEALLOCATE( ifileidx, isstidx, zdat )
-
-      !-----------------------------------------------------------------------
-      ! Deallocate input data
-      !-----------------------------------------------------------------------
-      DO jj = 1, inobf
-         IF ( inpfiles(jj)%lalloc ) THEN
-            CALL dealloc_obfbdata( inpfiles(jj) )
-         ENDIF
-      END DO
-      DEALLOCATE( inpfiles )
-
-   END SUBROUTINE obs_rea_sst
-
-   SUBROUTINE obs_rea_sst_rey( sstname, cdsstfmt, sstdata, kvars, kextra, &
-      &                        kstp, ddobsini, ddobsend )
-      !!---------------------------------------------------------------------
-      !!
-      !!                   *** ROUTINE obs_rea_sst ***
-      !!
-      !! ** Purpose : Read from file the pseudo SST data from Reynolds
-      !!
-      !! ** Method  : 
-      !!
-      !! ** Action  : 
-      !!
-      !! References : 
-      !!
-      !! History :  
-      !!      ! :  
-      !!----------------------------------------------------------------------
-      !! * Modules used
-      USE par_oce          ! Ocean parameters
-   
-      !! * Arguments
-      CHARACTER(len=128), INTENT(IN) :: sstname   ! Generic file name
-      CHARACTER(len=12), INTENT(IN) :: cdsstfmt   ! Format of SST files (yearly/monthly)
-      TYPE(obs_surf), INTENT(INOUT) :: sstdata    ! SST data
-      REAL(KIND=dp), INTENT(IN) :: ddobsini    ! Obs. ini time in YYYYMMDD.HHMMSS
-      REAL(KIND=dp), INTENT(IN) :: ddobsend    ! Obs. end time in YYYYMMDD.HHMMSS
-      INTEGER, INTENT(IN) :: kvars      ! Number of variables in sstdata structures
-      INTEGER, INTENT(IN) :: kextra     ! Number of extra variables in sstdata structures
-      INTEGER, INTENT(IN) :: kstp       ! Ocean time-step index
-      
-      INTEGER :: iyear
-      INTEGER :: imon
-      INTEGER :: iday
-      INTEGER :: ihour
-      INTEGER :: imin
-      INTEGER :: isec
-      INTEGER :: ihhmmss
-      INTEGER :: iyear1
-      INTEGER :: iyear2
-      INTEGER :: imon1
-      INTEGER :: imon2
-      INTEGER :: iyearf
-      INTEGER :: imonf
-      REAL(KIND=wp) :: pjulini
-      REAL(KIND=wp) :: pjulend
-      REAL(KIND=wp) :: pjulb
-      REAL(KIND=wp) :: pjule
-      REAL(KIND=wp) :: pjul
-      INTEGER :: inumsst
-      INTEGER :: itotrec
-      INTEGER :: inumobs
-      INTEGER :: irec
-      INTEGER :: ifld
-      INTEGER :: inum
-      INTEGER :: ji, jj
-      CHARACTER(len=128) :: clname
-      CHARACTER(len=4) :: cdyear
-      CHARACTER(len=2) :: cdmon
-      REAL(kind=wp), ALLOCATABLE, DIMENSION(:,:,:) :: zsstin
-
-      IF (lwp) WRITE(numout,*)'In obs_rea_sst_rey',sstname
-
-      !-----------------------------------------------------------------------
-      ! Convert observation window to julian dates.
-      !-----------------------------------------------------------------------
-      iyear1 = NINT( ddobsini / 10000 )
-      imon1 = NINT( ( ddobsini - iyear1 * 10000 ) / 100 )
-      iday = MOD( NINT( ddobsini ), 100 )
-      ihhmmss = ( ddobsini - NINT( ddobsini ) ) * 1000000
-      ihour = ihhmmss / 10000
-      imin = ( ihhmmss - ihour * 100 ) / 100
-      isec = MOD( ihhmmss, 100 )
-      CALL greg2jul ( isec, imin, ihour, iday, imon1, iyear1, pjulini )
-      IF (lwp) WRITE(numout,*)'dateini',ddobsini,iyear1,imon1,iday,ihour, &
-         & imin,isec,pjulini
-
-      iyear2 = NINT( ddobsini / 10000 )
-      imon2 = NINT( ( ddobsend - iyear2 * 10000 ) / 100 )
-      iday = MOD( NINT( ddobsend ), 100 )
-      ihhmmss = ( ddobsend - NINT( ddobsend ) ) * 1000000
-      ihour = ihhmmss / 10000
-      imin = ( ihhmmss - ihour * 100 ) / 100
-      isec = MOD( ihhmmss, 100 )
-      CALL greg2jul ( isec, imin, ihour, iday, imon2, iyear2, pjulend )
-      IF (lwp) WRITE(numout,*)'dateend',ddobsend,iyear2,imon2,iday,ihour, &
-         & imin,isec,pjulend
-
-      itotrec = NINT( pjulend - pjulini ) 
-      ALLOCATE( &
-         & zsstin( jpi, jpj, itotrec) &
-         & )
-      
-      pjul = pjulini + 1
-      
-      iyearf = -1 
-      imonf = -1
-
-      IF ( TRIM(cdsstfmt) == 'yearly' ) THEN
-
-         DO
-         
-            CALL jul2greg( isec, imin, ihour, iday, imon, iyear, &
-               &           pjul, 19500101 )
-            !
-            IF ( iyear /= iyearf ) THEN
-               
-               CALL greg2jul ( 0, 0, 0, 1, 1, iyear, pjulb )
-               
-               IF ( iyearf /= -1 ) THEN
-                  
-                  CALL iom_close ( inumsst )      
-                  
-               ENDIF
-               
-               clname = sstname
-               jj = INDEX( clname, 'YYYY' )
-               
-               IF ( jj == 0 ) THEN
-                  
-                  CALL ctl_stop( 'obs_rea_sst_rey : ', &
-                  &           'Error processing filename ' // TRIM(sstname) )
-                  
-               ENDIF
-               
-               WRITE(cdyear,'(I4.4)') iyear
-               clname(jj:jj+3) = cdyear
-               IF(lwp) WRITE(numout,*)'Reading from Reynolds SST file : ',&
-                  & TRIM(clname)
-               
-               inumsst = 0
-               
-               CALL iom_open ( clname, inumsst )
-               
-               IF ( inumsst == 0 ) THEN
-                  
-                  CALL ctl_stop( 'obs_rea_sst_rey : ', &
-                     &           'Error reading ' // TRIM(clname) )
-                  
-               ENDIF
-               
-               iyearf = iyear
-               
-            ENDIF
-            
-            irec = pjul - pjulb + 1
-            ifld = pjul - pjulini
-            
-            CALL iom_get ( inumsst, jpdom_data, 'sst', zsstin(:,:,ifld), irec )
-            
-            pjul = pjul + 1
-            
-            IF ( pjul > pjulend ) EXIT
-         
-         END DO
-
-      ELSEIF ( TRIM(cdsstfmt) == 'monthly' ) THEN
-
-         DO
-         
-            CALL jul2greg( isec, imin, ihour, iday, imon, iyear, &
-               &           pjul, 19500101 )
-            !
-            IF ( iyear /= iyearf .OR. imon /= imonf ) THEN
-               
-               CALL greg2jul ( 0, 0, 0, 1, imon, iyear, pjulb )
-               
-               IF ( iyearf /= -1 .AND. imonf /= -1 ) THEN
-                  
-                  CALL iom_close ( inumsst )      
-                  
-               ENDIF
-               
-               clname = sstname
-
-               jj = INDEX( clname, 'YYYY' )
-
-               IF ( jj == 0 ) THEN
-                  
-                  CALL ctl_stop( 'obs_rea_sst_rey : ', &
-                  &           'Error processing filename ' // TRIM(sstname) )
-                  
-               ENDIF
-               
-               WRITE(cdyear,'(I4.4)') iyear
-               clname(jj:jj+3) = cdyear
-
-               jj = INDEX( clname, 'MM' )
-               
-               IF ( jj == 0 ) THEN
-                  
-                  CALL ctl_stop( 'obs_rea_sst_rey : ', &
-                  &           'Error processing filename ' // TRIM(sstname) )
-                  
-               ENDIF
-               
-               WRITE(cdmon,'(I2.2)') imon
-               clname(jj:jj+1) = cdmon
-
-
-               IF(lwp) WRITE(numout,*)'Reading from Reynolds SST file : ',&
-                  & TRIM(clname)
-               
-               inumsst = 0
-               
-               CALL iom_open ( clname, inumsst )
-               
-               IF ( inumsst == 0 ) THEN
-                  
-                  CALL ctl_stop( 'obs_rea_sst_rey : ', &
-                     &           'Error reading ' // TRIM(clname) )
-                  
-               ENDIF
-               
-               iyearf = iyear
-               imonf = iyear
-               
-            ENDIF
-            
-            irec = pjul - pjulb + 1
-            ifld = pjul - pjulini
-            
-            CALL iom_get ( inumsst, jpdom_data, 'sst', zsstin(:,:,ifld), irec )
-            
-            pjul = pjul + 1
-            
-            IF ( pjul > pjulend ) EXIT
-         
-         END DO
-
-      ELSE
-         
-         CALL ctl_stop('Unknown REYNOLDS sst input data file format')
-
-      ENDIF
-
-      CALL iom_close ( inumsst )      
-
-      inumobs = 0
-      DO jj = nldj, nlej
-         DO ji = nldi, nlei
-            IF ( tmask(ji,jj,1) == 1.0_wp ) inumobs = inumobs + 1
-         END DO
-      END DO
-      inumobs = inumobs * itotrec
-
-      ! Allocate obs_surf data structure for time sorted data
-         
-      CALL obs_surf_alloc( sstdata, inumobs, kvars, kextra, kstp, jpi, jpj )
-
-      pjul = pjulini + 1
-
-      inumobs = 0
-
-      DO
-
-         CALL jul2greg( isec, imin, ihour, iday, imon, iyear, &
-            &           pjul, 19500101 )
-
-         ifld = pjul - pjulini
-
-         DO jj = nldj, nlej
-            DO ji = nldi, nlei
-
-               IF ( tmask(ji,jj,1) == 1.0_wp ) THEN
-
-                  inumobs = inumobs + 1
-                  
-                  ! Integer values
-                  IF (ln_grid_global) THEN
-                     sstdata%mi(inumobs)     = MAX(mig(ji),2)
-                     sstdata%mj(inumobs)     = MAX(mjg(jj),2)
-                  ELSE
-                     sstdata%mi(inumobs)     = MAX(ji,2)
-                     sstdata%mj(inumobs)     = MAX(jj,2)
-                  ENDIF
-                  sstdata%nsidx(inumobs)  = 0
-                  sstdata%nsfil(inumobs)  = 0
-                  sstdata%nyea(inumobs)   = iyear
-                  sstdata%nmon(inumobs)   = imon
-                  sstdata%nday(inumobs)   = iday
-                  sstdata%nhou(inumobs)   = ihour
-                  sstdata%nmin(inumobs)   = imin
-                  sstdata%mstp(inumobs)   = 0
-                  sstdata%nqc(inumobs)    = 0
-                  sstdata%ntyp(inumobs)   = 0
-         
-                  ! Real values
-                  sstdata%rlam(inumobs)   = glamt(ji,jj)
-                  sstdata%rphi(inumobs)   = gphit(ji,jj)
-                  sstdata%robs(inumobs,1) = zsstin(ji,jj,ifld)
-                  sstdata%rmod(inumobs,1) = fbrmdi
-                  sstdata%rext(inumobs,:) = fbrmdi
-
-               ENDIF
-
-            END DO
-         END DO
-
-         pjul = pjul + 1
-
-         IF ( pjul > pjulend ) EXIT
-
-      END DO
-
-   END SUBROUTINE obs_rea_sst_rey
-
-END MODULE obs_read_sst
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_surf.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_surf.F90	(revision 5659)
+++ branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_surf.F90	(revision 5659)
@@ -0,0 +1,450 @@
+MODULE obs_read_surf
+   !!======================================================================
+   !!                       ***  MODULE obs_read_surf  ***
+   !! Observation diagnostics: Read the surface data from feedback files
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   obs_rea_surf : Driver for reading surface data from feedback files
+   !!----------------------------------------------------------------------
+
+   !! * Modules used   
+   USE par_kind                 ! Precision variables
+   USE in_out_manager           ! I/O manager
+   USE dom_oce                  ! Ocean space and time domain variables
+   USE obs_mpp                  ! MPP support routines for observation diagnostics
+   USE julian                   ! Julian date routines
+   USE obs_utils                ! Observation operator utility functions
+   USE obs_grid                 ! Grid search
+   USE obs_sort                 ! Sorting observation arrays
+   USE obs_surf_def             ! Surface observation definitions
+   USE obs_types                ! Observation type definitions
+   USE netcdf                   ! NetCDF library
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+
+   PUBLIC obs_rea_surf      ! Read the surface observations from the point data
+   
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: obs_read_surf.F90 4990 2014-12-15 16:42:49Z timgraham $
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obs_rea_surf( surfdata, knumfiles, cfilenames, &
+      &                     kvars, kextr, kstp, ddobsini, ddobsend, &
+      &                     ldignmis, ldmod )
+      !!---------------------------------------------------------------------
+      !!
+      !!                   *** ROUTINE obs_rea_surf ***
+      !!
+      !! ** Purpose : Read from file the surface data
+      !!
+      !! ** Method  : Read in the data from feedback format files and 
+      !!              put into the NEMO internal surface data structure
+      !!
+      !! ** Action  : 
+      !!
+      !!
+      !! History :  
+      !!      ! :  2009-01 (K. Mogensen) Initial version based on old versions
+      !!      ! :  2015-02 (M. Martin)   Unify the different surface data type reading.
+      !!----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      TYPE(obs_surf), INTENT(INOUT) :: surfdata   ! Surface data to be read
+      INTEGER, INTENT(IN) :: knumfiles    ! Number of corio format files to read in
+      CHARACTER(LEN=128), INTENT(IN) :: cfilenames(knumfiles) ! File names to read in
+      INTEGER, INTENT(IN) :: kvars      ! Number of variables in surfdata
+      INTEGER, INTENT(IN) :: kextr      ! Number of extra fields for each var in surfdata
+      INTEGER, INTENT(IN) :: kstp       ! Ocean time-step index
+      LOGICAL, INTENT(IN) :: ldignmis   ! Ignore missing files
+      LOGICAL, INTENT(IN) :: ldmod      ! Initialize model from input data
+      REAL(KIND=dp), INTENT(IN) :: ddobsini   ! Obs. ini time in YYYYMMDD.HHMMSS
+      REAL(KIND=dp), INTENT(IN) :: ddobsend   ! Obs. end time in YYYYMMDD.HHMMSS
+         
+      !! * Local declarations
+      CHARACTER(LEN=11), PARAMETER :: cpname='obs_rea_surf'
+      INTEGER :: ji
+      INTEGER :: jj
+      INTEGER :: jk
+      INTEGER :: iflag
+      INTEGER :: inobf
+      INTEGER :: i_file_id
+      INTEGER :: inowin
+      INTEGER :: iyea
+      INTEGER :: imon
+      INTEGER :: iday
+      INTEGER :: ihou
+      INTEGER :: imin
+      INTEGER :: isec
+      INTEGER, DIMENSION(knumfiles) :: irefdate
+      INTEGER :: iobsmpp
+      INTEGER, PARAMETER :: isurfmaxtype = 1024
+      INTEGER, DIMENSION(0:isurfmaxtype) :: &
+         & ityp, &
+         & itypmpp
+      INTEGER, DIMENSION(:), ALLOCATABLE :: &
+         & iobsi,    &
+         & iobsj,    &
+         & iproc,    &
+         & iindx,    &
+         & ifileidx, &
+         & isurfidx
+      INTEGER :: itype
+      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
+         & zphi, &
+         & zlam
+      real(wp), DIMENSION(:), ALLOCATABLE :: &
+         & zdat
+      LOGICAL :: llvalprof
+      TYPE(obfbdata), POINTER, DIMENSION(:) :: &
+         & inpfiles
+      real(wp), DIMENSION(knumfiles) :: &
+         & djulini, &
+         & djulend
+      INTEGER :: iobs
+      INTEGER :: iobstot
+      INTEGER :: ios
+      INTEGER :: ioserrcount
+      CHARACTER(len=8) :: cl_refdate
+   
+      ! Local initialization
+      iobs = 0
+ 
+      !-----------------------------------------------------------------------
+      ! Check data the model part is just with feedback data files
+      !-----------------------------------------------------------------------
+      IF ( ldmod .AND. ( kformat /= 0 ) ) THEN
+         CALL ctl_stop( 'Model can only be read from feedback data' )
+         RETURN
+      ENDIF
+
+      !-----------------------------------------------------------------------
+      ! Count the number of files needed and allocate the obfbdata type
+      !-----------------------------------------------------------------------
+      
+      inobf = knumfiles
+      
+      ALLOCATE( inpfiles(inobf) )
+
+      surf_files : DO jj = 1, inobf
+
+         CALL init_obfbdata( inpfiles(jj) )
+          
+         !---------------------------------------------------------------------
+         ! Prints
+         !---------------------------------------------------------------------
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' obs_rea_surf : Reading from file = ', &
+               & TRIM( TRIM( cfilenames(jj) ) )
+            WRITE(numout,*) ' ~~~~~~~~~~~'
+            WRITE(numout,*)
+         ENDIF
+
+         !---------------------------------------------------------------------
+         !  Initialization: Open file and get dimensions only
+         !---------------------------------------------------------------------
+         
+         iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
+            &                      i_file_id )
+         
+         IF ( iflag /= nf90_noerr ) THEN
+
+            IF ( ldignmis ) THEN
+               inpfiles(jj)%nobs = 0
+               CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
+                  &           ' not found' )
+            ELSE 
+               CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
+                  &           ' not found' )
+            ENDIF
+
+         ELSE 
+            
+            !------------------------------------------------------------------
+            !  Close the file since it is opened in read_proffile
+            !------------------------------------------------------------------
+            
+            iflag = nf90_close( i_file_id )
+
+            !------------------------------------------------------------------
+            !  Read the profile file into inpfiles
+            !------------------------------------------------------------------
+            IF(lwp) THEN
+               WRITE(numout,*)
+               WRITE(numout,*)'Reading from feedback file :', &
+                  &           TRIM( cfilenames(jj) )
+            ENDIF
+            CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
+               &                ldgrid = .TRUE. )
+            IF ( ldmod .AND. ( inpfiles(jj)%nadd == 0 ) ) THEN
+               CALL ctl_stop( 'Model not in input data' )
+               RETURN
+            ENDIF
+
+            !------------------------------------------------------------------
+            !  Change longitude (-180,180)
+            !------------------------------------------------------------------
+
+            DO ji = 1, inpfiles(jj)%nobs 
+
+               IF ( inpfiles(jj)%plam(ji) < -180. ) &
+                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) + 360.
+
+               IF ( inpfiles(jj)%plam(ji) >  180. ) &
+                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) - 360.
+
+            END DO
+
+            !------------------------------------------------------------------
+            !  Calculate the date  (change eventually)
+            !------------------------------------------------------------------
+            cl_refdate=inpfiles(jj)%cdjuldref(1:8)
+            READ(cl_refdate,'(I8)') irefdate(jj)
+            
+            CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
+            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
+               &           krefdate = irefdate(jj) )
+            CALL ddatetoymdhms( ddobsend, iyea, imon, iday, ihou, imin, isec )
+            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulend(jj), &
+               &           krefdate = irefdate(jj) )
+            IF ( inpfiles(jj)%nobs > 0 ) THEN
+               inpfiles(jj)%iproc = -1
+               inpfiles(jj)%iobsi = -1
+               inpfiles(jj)%iobsj = -1
+            ENDIF
+            inowin = 0
+            DO ji = 1, inpfiles(jj)%nobs
+               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
+                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
+                  inowin = inowin + 1
+               ENDIF
+            END DO
+            ALLOCATE( zlam(inowin)  )
+            ALLOCATE( zphi(inowin)  )
+            ALLOCATE( iobsi(inowin) )
+            ALLOCATE( iobsj(inowin) )
+            ALLOCATE( iproc(inowin) )
+            inowin = 0
+            DO ji = 1, inpfiles(jj)%nobs
+               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
+                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
+                  inowin = inowin + 1
+                  zlam(inowin) = inpfiles(jj)%plam(ji)
+                  zphi(inowin) = inpfiles(jj)%pphi(ji)
+               ENDIF
+            END DO
+
+            CALL obs_grid_search( inowin, zlam, zphi, iobsi, iobsj, iproc, 'T' )
+
+            inowin = 0
+            DO ji = 1, inpfiles(jj)%nobs
+               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
+                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
+                  inowin = inowin + 1
+                  inpfiles(jj)%iproc(ji,1) = iproc(inowin)
+                  inpfiles(jj)%iobsi(ji,1) = iobsi(inowin)
+                  inpfiles(jj)%iobsj(ji,1) = iobsj(inowin)
+               ENDIF
+            END DO
+            DEALLOCATE( zlam, zphi, iobsi, iobsj, iproc )
+
+            DO ji = 1, inpfiles(jj)%nobs
+               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
+                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
+                  IF ( nproc == 0 ) THEN
+                     IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
+                  ELSE
+                     IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
+                  ENDIF
+                  llvalprof = .FALSE.
+                  IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
+                     & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
+                     iobs = iobs + 1
+                  ENDIF
+               ENDIF
+            END DO
+
+         ENDIF
+
+      END DO surf_files
+
+      !-----------------------------------------------------------------------
+      ! Get the time ordered indices of the input data
+      !-----------------------------------------------------------------------
+
+      !---------------------------------------------------------------------
+      !  Loop over input data files to count total number of profiles
+      !---------------------------------------------------------------------
+      iobstot = 0
+      DO jj = 1, inobf
+         DO ji = 1, inpfiles(jj)%nobs
+            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
+               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
+               iobstot = iobstot + 1
+            ENDIF
+         END DO
+      END DO
+
+      ALLOCATE( iindx(iobstot), ifileidx(iobstot), &
+         &      isurfidx(iobstot), zdat(iobstot) )
+      jk = 0
+      DO jj = 1, inobf
+         DO ji = 1, inpfiles(jj)%nobs
+            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
+               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
+               jk = jk + 1
+               ifileidx(jk) = jj
+               isurfidx(jk) = ji
+               zdat(jk)     = inpfiles(jj)%ptim(ji)
+            ENDIF
+         END DO
+      END DO
+      CALL sort_dp_indx( iobstot, &
+         &               zdat,     &
+         &               iindx   )
+      
+      CALL obs_surf_alloc( surfdata, iobs, kvars, kextr, kstp, jpi, jpj )
+      
+      ! * Read obs/positions, QC, all variable and assign to surfdata
+ 
+      iobs = 0
+
+      ityp   (:) = 0
+      itypmpp(:) = 0
+      
+      ioserrcount = 0
+      
+      DO jk = 1, iobstot
+         
+         jj = ifileidx(iindx(jk))
+         ji = isurfidx(iindx(jk))
+         IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
+            & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
+            
+            IF ( nproc == 0 ) THEN
+               IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
+            ELSE
+               IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
+            ENDIF
+            
+            ! Set observation information
+            
+            IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
+               & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
+
+               iobs = iobs + 1
+
+               CALL jul2greg( isec,                   &
+                  &           imin,                   &
+                  &           ihou,                   &
+                  &           iday,                   &
+                  &           imon,                   &
+                  &           iyea,                   &
+                  &           inpfiles(jj)%ptim(ji), &
+                  &           irefdate(jj) )
+
+
+               ! Surface time coordinates
+               surfdata%nyea(iobs) = iyea
+               surfdata%nmon(iobs) = imon
+               surfdata%nday(iobs) = iday
+               surfdata%nhou(iobs) = ihou
+               surfdata%nmin(iobs) = imin
+               
+               ! Surface space coordinates
+               surfdata%rlam(iobs) = inpfiles(jj)%plam(ji)
+               surfdata%rphi(iobs) = inpfiles(jj)%pphi(ji)
+
+               ! Coordinate search parameters
+               surfdata%mi  (iobs) = inpfiles(jj)%iobsi(ji,1)
+               surfdata%mj  (iobs) = inpfiles(jj)%iobsj(ji,1)
+               
+               ! Instrument type
+               READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
+901            IF ( ios /= 0 ) THEN
+                  IF (ioserrcount == 0) CALL ctl_warn ( 'Problem converting an instrument type to integer. Setting type to zero' ) 
+                  ioserrcount = ioserrcount + 1
+                  itype = 0
+               ENDIF
+               surfdata%ntyp(iobs) = itype
+               IF ( itype < isurfmaxtype + 1 ) THEN
+                  ityp(itype+1) = ityp(itype+1) + 1
+               ELSE
+                  IF(lwp)WRITE(numout,*)'WARNING:Increase isurfmaxtype in ',&
+                     &                  cpname
+               ENDIF
+
+               ! Bookkeeping data to match observations
+               surfdata%nsidx(iobs) = iobs
+               surfdata%nsfil(iobs) = iindx(jk)
+
+               ! QC flags
+               surfdata%nqc(iobs) = inpfiles(jj)%ivqc(ji,1)
+
+               ! Observed value
+               surfdata%robs(iobs,1) = inpfiles(jj)%pob(1,ji,1)
+
+
+               ! Model and MDT is set to fbrmdi unless read from file
+               IF ( ldmod ) THEN
+                  surfdata%rmod(iobs,1) = inpfiles(jj)%padd(1,ji,1,1)
+               ELSE
+                  surfdata%rmod(iobs,1) = fbrmdi
+               ENDIF
+            ENDIF
+         ENDIF
+
+      END DO
+
+      !-----------------------------------------------------------------------
+      ! Sum up over processors
+      !-----------------------------------------------------------------------
+      
+      CALL obs_mpp_sum_integer( iobs, iobsmpp )
+      
+      !-----------------------------------------------------------------------
+      ! Output number of observations.
+      !-----------------------------------------------------------------------
+      IF (lwp) THEN
+
+         WRITE(numout,*)
+         WRITE(numout,'(1X,A)')'Surface data types'
+         WRITE(numout,'(1X,A)')'--------------'
+         DO jj = 1,8
+            IF ( itypmpp(jj) > 0 ) THEN
+               WRITE(numout,'(1X,A4,I4,A3,I10)')'Type ', jj,' = ',itypmpp(jj)
+            ENDIF
+         END DO
+         WRITE(numout,'(1X,A50)')'--------------------------------------------------'
+         WRITE(numout,'(1X,A40,I10)')'Total                                 = ',iobsmpp
+         WRITE(numout,*)
+
+      ENDIF
+
+      !-----------------------------------------------------------------------
+      ! Deallocate temporary data
+      !-----------------------------------------------------------------------
+      DEALLOCATE( ifileidx, isurfidx, zdat )
+
+      !-----------------------------------------------------------------------
+      ! Deallocate input data
+      !-----------------------------------------------------------------------
+      DO jj = 1, inobf
+         IF ( inpfiles(jj)%lalloc ) THEN
+            CALL dealloc_obfbdata( inpfiles(jj) )
+         ENDIF
+      END DO
+      DEALLOCATE( inpfiles )
+
+   END SUBROUTINE obs_rea_surf
+
+END MODULE obs_read_surf
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_vel.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_vel.F90	(revision 5658)
+++ 	(revision )
@@ -1,653 +1,0 @@
-MODULE obs_read_vel
-   !!======================================================================
-   !!                       ***  MODULE obs_read_vel  ***
-   !! Observation diagnostics: Read the velocity profile observations
-   !!======================================================================
-
-   !!----------------------------------------------------------------------
-   !!   obs_rea_vel_dri : Driver for reading profile obs
-   !!----------------------------------------------------------------------
-
-   !! * Modules used   
-   USE par_kind                 ! Precision variables
-   USE par_oce                  ! Ocean parameters
-   USE in_out_manager           ! I/O manager
-   USE dom_oce                  ! Ocean space and time domain variables
-   USE obs_mpp                  ! MPP support routines for observation diagnostics
-   USE julian                   ! Julian date routines
-   USE obs_utils                ! Observation operator utility functions
-   USE obs_prep                 ! Prepare observation arrays
-   USE obs_grid                 ! Grid search
-   USE obs_sort                 ! Sorting observation arrays
-   USE obs_profiles_def         ! Profile definitions
-   USE obs_conv                 ! Various conversion routines
-   USE obs_types                ! Observation type definitions
-   USE netcdf                   ! NetCDF library
-   USE obs_oper                 ! Observation operators
-   USE obs_vel_io               ! Velocity profile files I/O (non-FB files)
-   USE lib_mpp                  ! For ctl_warn/stop
-
-   IMPLICIT NONE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC obs_rea_vel_dri  ! Read the profile observations 
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
- 
-   SUBROUTINE obs_rea_vel_dri( kformat, &
-      &                        profdata, knumfiles, cfilenames, &
-      &                        kvars, kextr, kstp, ddobsini, ddobsend, &
-      &                        ldignmis, ldavtimset, ldmod )
-      !!---------------------------------------------------------------------
-      !!
-      !!                   *** ROUTINE obs_rea_pro_dri ***
-      !!
-      !! ** Purpose : Read from file the profile observations
-      !!
-      !! ** Method  : Depending on kformat either ENACT, CORIOLIS or
-      !!              feedback data files are read
-      !!
-      !! ** Action  : 
-      !!
-      !! References : 
-      !!
-      !! History :  
-      !!      ! :  2009-01 (K. Mogensen) : New merged version of old routines
-      !!----------------------------------------------------------------------
-      !! * Modules used
-   
-      !! * Arguments
-      INTEGER :: kformat   ! Format of input data
-      !                    ! 1: ENACT
-      !                    ! 2: Coriolis
-      TYPE(obs_prof), INTENT(OUT) :: profdata    ! Profile data to be read
-      INTEGER, INTENT(IN) :: knumfiles           ! Number of files to read in
-      CHARACTER(LEN=128), INTENT(IN) ::  cfilenames(knumfiles) ! File names to read in
-      INTEGER, INTENT(IN) :: kvars       ! Number of variables in profdata
-      INTEGER, INTENT(IN) :: kextr       ! Number of extra fields for each var in profdata
-      INTEGER, INTENT(IN) :: kstp        !  Ocean time-step index
-      LOGICAL, INTENT(IN) :: ldignmis    ! Ignore missing files
-      LOGICAL, INTENT(IN) :: ldavtimset  ! Set time to be equal to the end of the day
-      LOGICAL, INTENT(IN) :: ldmod       ! Initialize model from input data
-      REAL(KIND=dp), INTENT(IN) :: ddobsini   ! Obs. ini time in YYYYMMDD.HHMMSS
-      REAL(KIND=dp), INTENT(IN) :: ddobsend   ! Obs. end time in YYYYMMDD.HHMMSS
-
-      !! * Local declarations
-      CHARACTER(LEN=15), PARAMETER :: cpname='obs_rea_vel_dri'
-      INTEGER :: jvar
-      INTEGER :: ji
-      INTEGER :: jj
-      INTEGER :: jk
-      INTEGER :: ij
-      INTEGER :: iflag
-      INTEGER :: inobf
-      INTEGER :: i_file_id
-      INTEGER :: inowin
-      INTEGER :: iyea
-      INTEGER :: imon
-      INTEGER :: iday
-      INTEGER :: ihou
-      INTEGER :: imin
-      INTEGER :: isec
-      INTEGER, DIMENSION(knumfiles) :: &
-         & irefdate
-      INTEGER, DIMENSION(ntyp1770+1) :: &
-         & itypuv,    &
-         & itypuvmpp 
-      INTEGER :: iuv3dtmpp
-      INTEGER, DIMENSION(:), ALLOCATABLE :: &
-         & iobsiu,   &
-         & iobsju,   &
-         & iprocu,   &
-         & iobsiv,   &
-         & iobsjv,   &
-         & iprocv,   &
-         & iindx,    &
-         & ifileidx, &
-         & iprofidx
-      INTEGER :: itype
-      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zphi, &
-         & zlam
-      real(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zdat
-      LOGICAL :: &
-         & llvalprof
-      TYPE(obfbdata), POINTER, DIMENSION(:) :: &
-         & inpfiles
-      real(wp), DIMENSION(knumfiles) :: &
-         & djulini, &
-         & djulend
-      INTEGER :: iprof
-      INTEGER :: iproftot
-      INTEGER :: iuv3dt
-      INTEGER :: ios
-      INTEGER :: ioserrcount
-      INTEGER, DIMENSION(kvars) :: iv3dt
-      CHARACTER(len=8) :: cl_refdate
-   
-      ! Local initialization
-      iprof = 0
-      iuv3dt = 0
-
-      !-----------------------------------------------------------------------
-      ! Check data the model part is just with feedback data files
-      !-----------------------------------------------------------------------
-      IF ( ldmod .AND. ( kformat /= 0 ) ) THEN
-         CALL ctl_stop( 'Model can only be read from feedback data' )
-         RETURN
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Count the number of files needed and allocate the obfbdata type
-      !-----------------------------------------------------------------------
-      
-      inobf = knumfiles
-
-      ALLOCATE( inpfiles(inobf) )
-
-      prof_files : DO jj = 1, inobf
-          
-         !---------------------------------------------------------------------
-         ! Prints
-         !---------------------------------------------------------------------
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) ' obs_rea_vel_dri : Reading from file = ', &
-               & TRIM( TRIM( cfilenames(jj) ) )
-            WRITE(numout,*) ' ~~~~~~~~~~~~~~~'
-            WRITE(numout,*)
-         ENDIF
-
-         !---------------------------------------------------------------------
-         !  Initialization: Open file and get dimensions only
-         !---------------------------------------------------------------------
-         
-         iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
-            &                      i_file_id )
-         
-         IF ( iflag /= nf90_noerr ) THEN
-
-            IF ( ldignmis ) THEN
-               inpfiles(jj)%nobs = 0
-               CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ELSE 
-               CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
-                  &           ' not found' )
-            ENDIF
-
-         ELSE 
-            
-            !------------------------------------------------------------------
-            !  Close the file since it is opened in read_proffile
-            !------------------------------------------------------------------
-            
-            iflag = nf90_close( i_file_id )
-
-            !------------------------------------------------------------------
-            !  Read the profile file into inpfiles
-            !------------------------------------------------------------------
-            IF ( kformat == 0 ) THEN
-               CALL init_obfbdata( inpfiles(jj) )
-               IF(lwp) THEN
-                  WRITE(numout,*)
-                  WRITE(numout,*)'Reading from feedback file :', &
-                     &           TRIM( cfilenames(jj) )
-               ENDIF
-               CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &                ldgrid = .TRUE. )
-               IF ( ldmod .AND. ( inpfiles(jj)%nadd == 0 ) ) THEN
-                  CALL ctl_stop( 'Model not in input data' )
-                  RETURN
-               ENDIF
-            ELSEIF ( kformat == 1 ) THEN
-               CALL read_taondbc( TRIM( cfilenames(jj) ), inpfiles(jj), &
-                  &               numout, lwp, .TRUE. )
-            ELSE
-               CALL ctl_stop( 'File format unknown' )
-            ENDIF
-            
-            !------------------------------------------------------------------
-            !  Change longitude (-180,180)
-            !------------------------------------------------------------------
-
-            DO ji = 1, inpfiles(jj)%nobs 
-
-               IF ( inpfiles(jj)%plam(ji) < -180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) + 360.
-
-               IF ( inpfiles(jj)%plam(ji) >  180. ) &
-                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) - 360.
-
-            END DO
-
-            !------------------------------------------------------------------
-            !  Calculate the date  (change eventually)
-            !------------------------------------------------------------------
-            cl_refdate=inpfiles(jj)%cdjuldref(1:8)
-            READ(cl_refdate,'(I8)') irefdate(jj)
-            
-            CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
-               &           krefdate = irefdate(jj) )
-            CALL ddatetoymdhms( ddobsend, iyea, imon, iday, ihou, imin, isec )
-            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulend(jj), &
-               &           krefdate = irefdate(jj) )
-
-            IF ( ldavtimset ) THEN
-               DO ji = 1, inpfiles(jj)%nobs
-                  ! 
-                  !  for daily averaged data force the time
-                  !  to be the  end of the day
-                  !
-                  inpfiles(jj)%ptim(ji) = &
-                     & INT(inpfiles(jj)%ptim(ji)) + 1
-               END DO
-            ENDIF
-            
-            IF ( inpfiles(jj)%nobs > 0 ) THEN
-               inpfiles(jj)%iproc = -1
-               inpfiles(jj)%iobsi = -1
-               inpfiles(jj)%iobsj = -1
-            ENDIF
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-               ENDIF
-            END DO
-            ALLOCATE( zlam(inowin)  )
-            ALLOCATE( zphi(inowin)  )
-            ALLOCATE( iobsiu(inowin) )
-            ALLOCATE( iobsju(inowin) )
-            ALLOCATE( iprocu(inowin) )
-            ALLOCATE( iobsiv(inowin) )
-            ALLOCATE( iobsjv(inowin) )
-            ALLOCATE( iprocv(inowin) )
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  zlam(inowin) = inpfiles(jj)%plam(ji)
-                  zphi(inowin) = inpfiles(jj)%pphi(ji)
-               ENDIF
-            END DO
-
-            CALL obs_grid_search( inowin, zlam, zphi, iobsiu, iobsju, iprocu, &
-               & 'U' )
-            CALL obs_grid_search( inowin, zlam, zphi, iobsiv, iobsjv, iprocv, &
-               & 'V' )
-
-            inowin = 0
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  inowin = inowin + 1
-                  inpfiles(jj)%iproc(ji,1) = iprocu(inowin)
-                  inpfiles(jj)%iobsi(ji,1) = iobsiu(inowin)
-                  inpfiles(jj)%iobsj(ji,1) = iobsju(inowin)
-                  inpfiles(jj)%iproc(ji,2) = iprocv(inowin)
-                  inpfiles(jj)%iobsi(ji,2) = iobsiv(inowin)
-                  inpfiles(jj)%iobsj(ji,2) = iobsjv(inowin)
-                  IF ( inpfiles(jj)%iproc(ji,1) /= &
-                     & inpfiles(jj)%iproc(ji,2) ) THEN
-                     CALL ctl_stop( 'Error in obs_read_vel:', &
-                        & 'U and V observation on different processors')
-                  ENDIF
-               ENDIF
-            END DO
-            DEALLOCATE( zlam, zphi, iobsiu, iobsju, iprocu,  &
-               & iobsiv, iobsjv, iprocv )
-
-            DO ji = 1, inpfiles(jj)%nobs
-               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-                  IF ( nproc == 0 ) THEN
-                     IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-                  ELSE
-                     IF ( inpfiles(jj)%iproc(ji,1) /=  nproc ) CYCLE
-                  ENDIF
-                  llvalprof = .FALSE.
-                  IF ( ( ( nproc == 0 ) .AND. &
-                     & ( inpfiles(jj)%iproc(ji,1) <=  nproc ) ) .OR. &
-                     & ( inpfiles(jj)%iproc(ji,1) ==  nproc ) ) THEN
-                     loop_uv_count : DO ij = 1,inpfiles(jj)%nlev
-                        IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
-                           & CYCLE
-                        IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
-                           & ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
-                           & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
-                           iuv3dt = iuv3dt + 1
-                           llvalprof = .TRUE.
-                        ENDIF
-                     END DO loop_uv_count
-                  ENDIF
-                  IF ( llvalprof ) iprof = iprof + 1
-               ENDIF
-            END DO
-
-         ENDIF
-         
-      END DO prof_files
-
-      !-----------------------------------------------------------------------
-      ! Get the time ordered indices of the input data
-      !-----------------------------------------------------------------------
-
-      !---------------------------------------------------------------------
-      !  Loop over input data files to count total number of profiles
-      !---------------------------------------------------------------------
-      iproftot = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               iproftot = iproftot + 1
-            ENDIF
-         END DO
-      END DO
-
-      ALLOCATE( iindx(iproftot), ifileidx(iproftot), &
-         &      iprofidx(iproftot), zdat(iproftot) )
-      jk = 0
-      DO jj = 1, inobf
-         DO ji = 1, inpfiles(jj)%nobs
-            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
-               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
-               jk = jk + 1
-               ifileidx(jk) = jj
-               iprofidx(jk) = ji
-               zdat(jk)     = inpfiles(jj)%ptim(ji)
-            ENDIF
-         END DO
-      END DO
-      CALL sort_dp_indx( iproftot, &
-         &               zdat,     &
-         &               iindx   )
-      
-      iv3dt(:) = -1
-      iv3dt(1:2) = iuv3dt
-      CALL obs_prof_alloc( profdata, kvars, kextr, iprof, iv3dt, &
-         &                 kstp, jpi, jpj, jpk )
-      
-      ! * Read obs/positions, QC, all variable and assign to profdata
-
-      profdata%nprof     = 0
-      profdata%nvprot(:) = 0
-
-      iprof = 0
-
-      iuv3dt = 0
-      itypuv   (:) = 0
-      itypuvmpp(:) = 0
-      
-      DO jk = 1, iproftot
-         
-         jj = ifileidx(iindx(jk))
-         ji = iprofidx(iindx(jk))
-         IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
-            & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
-            
-            IF ( nproc == 0 ) THEN
-               IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
-            ELSE
-               IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
-            ENDIF
-            
-            llvalprof = .FALSE.
-
-            loop_prof : DO ij = 1, inpfiles(jj)%nlev
-               
-               IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
-                  & CYCLE
-               
-               IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
-                  & ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
-                  & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
-
-                  llvalprof = .TRUE.
-                  EXIT loop_prof
-
-               ENDIF
-
-            END DO loop_prof
-            
-            ! Set profile information
-            
-            IF ( llvalprof ) THEN
-               
-               iprof = iprof + 1
-
-               CALL jul2greg( isec,                   &
-                  &           imin,                   &
-                  &           ihou,                   &
-                  &           iday,                   &
-                  &           imon,                   &
-                  &           iyea,                   &
-                  &           inpfiles(jj)%ptim(ji), &
-                  &           irefdate(jj) )
-
-
-               ! Profile time coordinates
-               profdata%nyea(iprof) = iyea
-               profdata%nmon(iprof) = imon
-               profdata%nday(iprof) = iday
-               profdata%nhou(iprof) = ihou
-               profdata%nmin(iprof) = imin
-               
-               ! Profile space coordinates
-               profdata%rlam(iprof) = inpfiles(jj)%plam(ji)
-               profdata%rphi(iprof) = inpfiles(jj)%pphi(ji)
-
-               ! Coordinate search parameters
-               profdata%mi  (iprof,1) = inpfiles(jj)%iobsi(ji,1)
-               profdata%mj  (iprof,1) = inpfiles(jj)%iobsj(ji,1)
-               profdata%mi  (iprof,2) = inpfiles(jj)%iobsi(ji,2)
-               profdata%mj  (iprof,2) = inpfiles(jj)%iobsj(ji,2)
-               
-               ! Profile WMO number
-               profdata%cwmo(iprof) = inpfiles(jj)%cdwmo(ji)
-               
-               ! Instrument type
-               READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
-901            IF ( ios /= 0 ) THEN
-                  IF (ioserrcount == 0) CALL ctl_warn ( 'Problem converting an instrument type to integer. Setting type to zero' ) 
-                  ioserrcount = ioserrcount + 1
-                  itype = 0
-               ENDIF
-               profdata%ntyp(iprof) = itype
-               
-               ! QC stuff
-
-               profdata%nqc(iprof)     = inpfiles(jj)%ioqc(ji)
-               profdata%nqcf(:,iprof)  = inpfiles(jj)%ioqcf(:,ji)
-               profdata%ipqc(iprof)    = inpfiles(jj)%ipqc(ji)
-               profdata%ipqcf(:,iprof) = inpfiles(jj)%ipqcf(:,ji)
-               profdata%itqc(iprof)    = inpfiles(jj)%itqc(ji)
-               profdata%itqcf(:,iprof) = inpfiles(jj)%itqcf(:,ji)
-               profdata%ivqc(iprof,:)  = inpfiles(jj)%ivqc(ji,:)
-               profdata%ivqcf(:,iprof,:) = inpfiles(jj)%ivqcf(:,ji,:)
-
-               ! Bookkeeping data to match profiles
-               profdata%npidx(iprof) = iprof
-               profdata%npfil(iprof) = iindx(jk)
-
-               ! Observation QC flag (whole profile)
-               profdata%nqc(iprof)  = 0 !TODO
-
-               loop_uv : DO ij = 1, inpfiles(jj)%nlev            
-                   
-                  IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
-                     & CYCLE
-
-                  IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
-                     & ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
-                     & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
-                     iuv3dt = iuv3dt + 1
-                  ELSE
-                     CYCLE
-                  ENDIF
-
-                  ! Depth of U observation
-                  profdata%var(1)%vdep(iuv3dt) = &
-                     &                inpfiles(jj)%pdep(ij,ji)
-                  
-                  ! Depth of U observation QC
-                  profdata%var(1)%idqc(iuv3dt) = &
-                     &                inpfiles(jj)%idqc(ij,ji)
-                  
-                  ! Depth of U observation QC flags
-                  profdata%var(1)%idqcf(:,iuv3dt) = &
-                     &                inpfiles(jj)%idqcf(:,ij,ji)
-                  
-                  ! Profile index
-                  profdata%var(1)%nvpidx(iuv3dt) = iprof
-                  
-                  ! Vertical index in original profile
-                  profdata%var(1)%nvlidx(iuv3dt) = ij
-
-                  ! Profile U value
-
-                  profdata%var(1)%vobs(iuv3dt) = &
-                     &                inpfiles(jj)%pob(ij,ji,1)
-                  IF ( ldmod ) THEN
-                     profdata%var(1)%vmod(iuv3dt) = &
-                        &                inpfiles(jj)%padd(ij,ji,1,1)
-                  ENDIF
-                  
-                  ! Profile U qc
-                  profdata%var(1)%nvqc(iuv3dt) = &
-                     & inpfiles(jj)%ivlqc(ij,ji,1)
-                  
-                  ! Profile U qc flags
-                  profdata%var(1)%nvqcf(:,iuv3dt) = &
-                     & inpfiles(jj)%ivlqcf(:,ij,ji,1)
-                  
-                  
-                  ! Depth of V observation
-                  profdata%var(2)%vdep(iuv3dt) = &
-                     &                inpfiles(jj)%pdep(ij,ji)
-                  
-                  ! Depth of V observation QC
-                  profdata%var(2)%idqc(iuv3dt) = &
-                     &                inpfiles(jj)%idqc(ij,ji)
-                  
-                  ! Depth of V observation QC flags
-                  profdata%var(2)%idqcf(:,iuv3dt) = &
-                     &                inpfiles(jj)%idqcf(:,ij,ji)
-                  
-                  ! Profile index
-                  profdata%var(2)%nvpidx(iuv3dt) = iprof
-                  
-                  ! Vertical index in original profile
-                  profdata%var(2)%nvlidx(iuv3dt) = ij
-                  
-                  ! Profile V value
-                  profdata%var(2)%vobs(iuv3dt) = &
-                     &                inpfiles(jj)%pob(ij,ji,2)
-                  IF ( ldmod ) THEN
-                     profdata%var(2)%vmod(iuv3dt) = &
-                        &                inpfiles(jj)%padd(ij,ji,1,2)
-                  ENDIF
-                     
-                  ! Profile V qc
-                  profdata%var(2)%nvqc(iuv3dt) = &
-                     & inpfiles(jj)%ivlqc(ij,ji,2)
-                  
-                  ! Profile V qc flags
-                  profdata%var(2)%nvqcf(:,iuv3dt) = &
-                        & inpfiles(jj)%ivlqcf(:,ij,ji,2)
-                  
-                  ! Observation type
-                  itypuv( profdata%ntyp(iprof) + 1 ) = &
-                     & itypuv( profdata%ntyp(iprof) + 1 ) + 1
-
-
-               END DO loop_uv
-
-            ENDIF
-
-         ENDIF
-
-      END DO
-
-      !-----------------------------------------------------------------------
-      ! Sum up over processors
-      !-----------------------------------------------------------------------
-      
-      CALL obs_mpp_sum_integer ( iuv3dt, iuv3dtmpp )
-      
-      CALL obs_mpp_sum_integers( itypuv, itypuvmpp, ntyp1770 + 1 )
-      
-      !-----------------------------------------------------------------------
-      ! Output number of observations.
-      !-----------------------------------------------------------------------
-      IF(lwp) THEN
-         WRITE(numout,*) 
-         WRITE(numout,'(1X,A)') 'Profile U,V velocity data'
-         WRITE(numout,'(1X,A)') '-------------------------'
-         WRITE(numout,*) 
-         DO ji = 0, ntyp1770
-            IF ( itypuvmpp(ji+1) > 0 ) THEN
-               WRITE(numout,'(1X,A3,A3,I8)') ctypshort(ji), ' = ', &
-                  & itypuvmpp(ji+1)
-            ENDIF
-         END DO
-         WRITE(numout,'(1X,A)') '--------------'
-         WRITE(numout,'(1X,A6,I8)') &
-            & 'Total profile UV data                                 = ',&
-            & iuv3dtmpp
-         WRITE(numout,'(1X,A)') '--------------'
-      ENDIF
-      
-      profdata%nvprot(1)    = iuv3dt
-      profdata%nvprot(2)    = iuv3dt
-      profdata%nvprotmpp(1) = iuv3dtmpp
-      profdata%nvprotmpp(2) = iuv3dtmpp
-      profdata%nprof        = iprof
-
-      !-----------------------------------------------------------------------
-      ! Model level search
-      !-----------------------------------------------------------------------
-      CALL obs_level_search( jpk, gdept_1d,          &
-         & profdata%nvprot(1), profdata%var(1)%vdep, &
-         & profdata%var(1)%mvk )
-      CALL obs_level_search( jpk, gdept_1d,          &
-         & profdata%nvprot(2), profdata%var(2)%vdep, &
-         & profdata%var(2)%mvk )
-      
-      !-----------------------------------------------------------------------
-      ! Set model equivalent to 99999
-      !-----------------------------------------------------------------------
-      IF ( .NOT. ldmod ) THEN
-         DO jvar = 1, kvars
-            profdata%var(jvar)%vmod(:) = fbrmdi
-         END DO
-      ENDIF
-      !-----------------------------------------------------------------------
-      ! Deallocate temporary data
-      !-----------------------------------------------------------------------
-      DEALLOCATE( ifileidx, iprofidx, zdat )
-
-      !-----------------------------------------------------------------------
-      ! Deallocate input data
-      !-----------------------------------------------------------------------
-      DO jj = 1, inobf
-         CALL dealloc_obfbdata( inpfiles(jj) )
-      END DO
-      DEALLOCATE( inpfiles )
-
-   END SUBROUTINE obs_rea_vel_dri
-   
-END MODULE obs_read_vel
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_seaice.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_seaice.F90	(revision 5658)
+++ 	(revision )
@@ -1,35 +1,0 @@
-MODULE obs_seaice
-   !!=====================================================================
-   !!                       ***  MODULE  obs_seaice  ***
-   !! Observation diagnostics: Storage space for sea ice observations
-   !!                          arrays and additional flags etc.
-   !!=====================================================================
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   
-   !! * Modules used 
-   USE obs_surf_def ! Definition of sea ice data types and tools
-
-   IMPLICIT NONE
-   
-   SAVE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC nseaicevars, nseaiceextr, nseaicesets, seaicedata, seaicedatqc
-
-   !! * Shared Module variables
-   INTEGER :: nseaicevars                               ! Number of seaicedata variables
-   INTEGER :: nseaiceextr                               ! Number of seaicedata extra 
-                                                     ! variables
-   INTEGER :: nseaicesets                               ! Number of seaicedata sets
-   TYPE(obs_surf), POINTER, DIMENSION(:) :: seaicedata  ! Initial sea ice data
-   TYPE(obs_surf), POINTER, DIMENSION(:) :: seaicedatqc ! Sea ice data after quality control
-
-END MODULE obs_seaice
-
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_seaice_io.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_seaice_io.F90	(revision 5658)
+++ 	(revision )
@@ -1,30 +1,0 @@
-MODULE obs_seaice_io
-   !!======================================================================
-   !!                       ***  MODULE obs_seaice_io  ***
-   !! Observation operators : I/O for GHRSEAICE files
-   !!======================================================================
-   !! History : 
-   !!             !  09-01  (K. Mogensen) Initial version
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!   read_seaicefile    :  Read a obfbdata structure from an GHRSEAICE file
-   !!----------------------------------------------------------------------
-   USE par_kind
-   USE obs_utils
-   USE obs_fbm
-   USE julian
-   USE netcdf
-
-   IMPLICIT NONE
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-#include "obsseaice_io.h90"
-
-END MODULE obs_seaice_io
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sla.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sla.F90	(revision 5658)
+++ 	(revision )
@@ -1,33 +1,0 @@
-MODULE obs_sla
-   !!=====================================================================
-   !!                       ***  MODULE  obs_sla  ***
-   !! Observation diagnostics: Storage space for SLA observations
-   !!                          arrays and additional flags etc.
-   !!=====================================================================
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-   
-   !! * Modules used 
-   USE obs_surf_def ! Definition of SLA data types and tools
-
-   IMPLICIT NONE
-   
-   SAVE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC nslavars, nslaextr, nslasets, sladata, sladatqc
-
-   !! * Shared Module variables
-   INTEGER :: nslavars                               ! Number of sladata variables
-   INTEGER :: nslaextr                               ! Number of sladata extra 
-                                                     ! variables
-   INTEGER :: nslasets                               ! Number of sladata sets                                               
-   TYPE(obs_surf), POINTER, DIMENSION(:) :: sladata  ! Initial SLA data
-   TYPE(obs_surf), POINTER, DIMENSION(:) :: sladatqc ! SLA data after quality control
-
-END MODULE obs_sla
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sla_io.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sla_io.F90	(revision 5658)
+++ 	(revision )
@@ -1,30 +1,0 @@
-MODULE obs_sla_io
-   !!======================================================================
-   !!                       ***  MODULE obs_sla_io  ***
-   !! Observation operators : I/O for AVISO SLA files
-   !!======================================================================
-   !! History : 
-   !!             !  09-01  (K. Mogensen) Initial version
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!   read_enactfile    :  Read a obfbdata structure from an AVISO SLA file
-   !!----------------------------------------------------------------------
-   USE par_kind
-   USE obs_utils
-   USE obs_fbm
-   use obs_sla_types
-   USE netcdf
-
-   IMPLICIT NONE
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-#include "obssla_io.h90"
-
-END MODULE obs_sla_io
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sla_types.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sla_types.F90	(revision 5658)
+++ 	(revision )
@@ -1,19 +1,0 @@
-MODULE obs_sla_types
-   !!======================================================================
-   !!                       ***  MODULE obs_sla_type  ***
-   !! Observation operators : Satellite identifiers for SLA data
-   !!======================================================================
-   !! History : 
-   !!             !  09-01  (K. Mogensen) Initial version
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   IMPLICIT NONE
-
-#include "obssla_types.h90"
-
-END MODULE obs_sla_types
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sst.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sst.F90	(revision 5658)
+++ 	(revision )
@@ -1,35 +1,0 @@
-MODULE obs_sst
-   !!=====================================================================
-   !!                       ***  MODULE  obs_sst  ***
-   !! Observation diagnostics: Storage space for SST observations
-   !!                          arrays and additional flags etc.
-   !!=====================================================================
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   
-   !! * Modules used 
-   USE obs_surf_def ! Definition of SST data types and tools
-
-   IMPLICIT NONE
-   
-   SAVE
-
-   !! * Routine accessibility
-   PRIVATE
-
-   PUBLIC nsstvars, nsstextr, nsstsets, sstdata, sstdatqc
-
-   !! * Shared Module variables
-   INTEGER :: nsstvars                               ! Number of sstdata variables
-   INTEGER :: nsstextr                               ! Number of sstdata extra 
-                                                     ! variables
-   INTEGER :: nsstsets                               ! Number of sstdata sets
-   TYPE(obs_surf), POINTER, DIMENSION(:) :: sstdata  ! Initial SST data
-   TYPE(obs_surf), POINTER, DIMENSION(:) :: sstdatqc ! SST data after quality control
-
-END MODULE obs_sst
-
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sst_io.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_sst_io.F90	(revision 5658)
+++ 	(revision )
@@ -1,30 +1,0 @@
-MODULE obs_sst_io
-   !!======================================================================
-   !!                       ***  MODULE obs_sst_io  ***
-   !! Observation operators : I/O for GHRSST files
-   !!======================================================================
-   !! History : 
-   !!             !  09-01  (K. Mogensen) Initial version
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!   read_sstfile    :  Read a obfbdata structure from an GHRSST file
-   !!----------------------------------------------------------------------
-   USE par_kind
-   USE obs_utils
-   USE obs_fbm
-   USE julian
-   USE netcdf
-
-   IMPLICIT NONE
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-#include "obssst_io.h90"
-
-END MODULE obs_sst_io
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_vel_io.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_vel_io.F90	(revision 5658)
+++ 	(revision )
@@ -1,32 +1,0 @@
-MODULE obs_vel_io
-   !!======================================================================
-   !!                       ***  MODULE obs_vel_io  ***
-   !! Observation operators : I/O for TAO velocity data
-   !!======================================================================
-   !! History : 
-   !!             !  09-01  (K. Mogensen) Initial version based on obs_read_taovel
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !!   read_taofile    :  Read a obfbdata structure from an TAO velocity file.
-   !!----------------------------------------------------------------------
-   USE par_kind
-   USE obs_utils
-   USE obs_fbm
-   USE obs_conv
-   USE in_out_manager
-   USE netcdf
-   IMPLICIT NONE
-
-   INTEGER, PARAMETER :: imaxlev = 10000
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-#include "obsvel_io.h90"
-
-END MODULE obs_vel_io
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90	(revision 5658)
+++ branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90	(revision 5659)
@@ -6,9 +6,6 @@
 
    !!----------------------------------------------------------------------
-   !!   obs_wri_p3d   : Write profile observation diagnostics in NetCDF format
-   !!   obs_wri_sla   : Write SLA observation related diagnostics
-   !!   obs_wri_sst   : Write SST observation related diagnostics
-   !!   obs_wri_seaice: Write seaice observation related diagnostics
-   !!   obs_wri_vel   : Write velocity observation diagnostics in NetCDF format
+   !!   obs_wri_prof   : Write profile observations in feedback format
+   !!   obs_wri_surf   : Write surface observations in feedback format
    !!   obs_wri_stats : Print basic statistics on the data being written out
    !!----------------------------------------------------------------------
@@ -30,5 +27,4 @@
    USE obs_conv             ! Conversion between units
    USE obs_const
-   USE obs_sla_types
    USE obs_rot_vel          ! Rotation of velocities
    USE obs_mpp              ! MPP support routines for observation diagnostics
@@ -39,10 +35,6 @@
    !! * Routine accessibility
    PRIVATE
-   PUBLIC obs_wri_p3d, &    ! Write profile observation related diagnostics
-      &   obs_wri_sla, &    ! Write SLA observation related diagnostics
-      &   obs_wri_sst, &    ! Write SST observation related diagnostics
-      &   obs_wri_sss, &    ! Write SSS observation related diagnostics
-      &   obs_wri_seaice, & ! Write seaice observation related diagnostics
-      &   obs_wri_vel, &    ! Write velocity observation related diagnostics
+   PUBLIC obs_wri_prof, &    ! Write profile observation files
+      &   obs_wri_surf, &    ! Write surface observation files
       &   obswriinfo
    
@@ -63,11 +55,10 @@
 CONTAINS
 
-   SUBROUTINE obs_wri_p3d( cprefix, profdata, padd, pext )
+   SUBROUTINE obs_wri_prof( cobstype, profdata, padd, pext )
       !!-----------------------------------------------------------------------
       !!
-      !!                     *** ROUTINE obs_wri_p3d  ***
-      !!
-      !! ** Purpose : Write temperature and salinity (profile) observation 
-      !!              related diagnostics
+      !!                     *** ROUTINE obs_wri_prof  ***
+      !!
+      !! ** Purpose : Write profile feedback files
       !!
       !! ** Method  : NetCDF
@@ -82,4 +73,5 @@
       !!      ! 07-03  (K. Mogensen) General handling of profiles
       !!      ! 09-01  (K. Mogensen) New feedback format
+      !!      ! 15-02  (M. Martin) Combined routine for writing profiles
       !!-----------------------------------------------------------------------
 
@@ -87,5 +79,5 @@
 
       !! * Arguments
-      CHARACTER(LEN=*), INTENT(IN) :: cprefix        ! Prefix for output files
+      CHARACTER(LEN=*), INTENT(IN) :: cobstype        ! Prefix for output files
       TYPE(obs_prof), INTENT(INOUT) :: profdata      ! Full set of profile data
       TYPE(obswriinfo), OPTIONAL :: padd             ! Additional info for each variable
@@ -125,40 +117,82 @@
          ilevel = MAX( ilevel, MAXVAL( profdata%var(jvar)%nvlidx(:) ) )
       END DO
-      CALL alloc_obfbdata( fbdata, 2, profdata%nprof, ilevel, &
-         &                 1 + nadd, 1 + next, .TRUE. )
-
-      fbdata%cname(1)      = 'POTM'
-      fbdata%cname(2)      = 'PSAL'
-      fbdata%coblong(1)    = 'Potential temperature'
-      fbdata%coblong(2)    = 'Practical salinity'
-      fbdata%cobunit(1)    = 'Degrees centigrade'
-      fbdata%cobunit(2)    = 'PSU'
-      fbdata%cextname(1)   = 'TEMP'
-      fbdata%cextlong(1)   = 'Insitu temperature'
-      fbdata%cextunit(1)   = 'Degrees centigrade'
-      DO je = 1, next
-         fbdata%cextname(1+je) = pext%cdname(je)
-         fbdata%cextlong(1+je) = pext%cdlong(je,1)
-         fbdata%cextunit(1+je) = pext%cdunit(je,1)
-      END DO
+
+      SELECT CASE ( TRIM(cobstype) )
+      CASE('prof')
+
+         CALL alloc_obfbdata( fbdata, 2, profdata%nprof, ilevel, &
+            &                 1 + nadd, 1 + next, .TRUE. )
+         fbdata%cname(1)      = 'POTM'
+         fbdata%cname(2)      = 'PSAL'
+         fbdata%coblong(1)    = 'Potential temperature'
+         fbdata%coblong(2)    = 'Practical salinity'
+         fbdata%cobunit(1)    = 'Degrees centigrade'
+         fbdata%cobunit(2)    = 'PSU'
+         fbdata%cextname(1)   = 'TEMP'
+         fbdata%cextlong(1)   = 'Insitu temperature'
+         fbdata%cextunit(1)   = 'Degrees centigrade'
+         fbdata%caddlong(1,1) = 'Model interpolated potential temperature'
+         fbdata%caddlong(1,2) = 'Model interpolated practical salinity'
+         fbdata%caddunit(1,1) = 'Degrees centigrade'
+         fbdata%caddunit(1,2) = 'PSU'
+         fbdata%cgrid(:)      = 'T'
+         DO je = 1, next
+            fbdata%cextname(1+je) = pext%cdname(je)
+            fbdata%cextlong(1+je) = pext%cdlong(je,1)
+            fbdata%cextunit(1+je) = pext%cdunit(je,1)
+         END DO
+         DO ja = 1, nadd
+            fbdata%caddname(1+ja) = padd%cdname(ja)
+            DO jvar = 1, 2
+               fbdata%caddlong(1+ja,jvar) = padd%cdlong(ja,jvar)
+               fbdata%caddunit(1+ja,jvar) = padd%cdunit(ja,jvar)
+            END DO
+         END DO
+      
+      CASE('vel')
+      
+         CALL alloc_obfbdata( fbdata, 2, profdata%nprof, ilevel, 2, 0, .TRUE. )
+         fbdata%cname(1)      = 'UVEL'
+         fbdata%cname(2)      = 'VVEL'
+         fbdata%coblong(1)    = 'Zonal velocity'
+         fbdata%coblong(2)    = 'Meridional velocity'
+         fbdata%cobunit(1)    = 'm/s'
+         fbdata%cobunit(2)    = 'm/s'
+         DO je = 1, next
+            fbdata%cextname(je) = pext%cdname(je)
+            fbdata%cextlong(je) = pext%cdlong(je,1)
+            fbdata%cextunit(je) = pext%cdunit(je,1)
+         END DO
+         fbdata%caddlong(1,1) = 'Model interpolated zonal velocity'
+         fbdata%caddlong(1,2) = 'Model interpolated meridional velocity'
+         fbdata%caddunit(1,1) = 'm/s'
+         fbdata%caddunit(1,2) = 'm/s'
+         fbdata%caddname(2)   = 'HxG'
+         fbdata%caddlong(2,1) = 'Model interpolated zonal velocity (model grid)'
+         fbdata%caddlong(2,2) = 'Model interpolated meridional velocity (model grid)'
+         fbdata%caddunit(2,1) = 'm/s'
+         fbdata%caddunit(2,2) = 'm/s' 
+         fbdata%cgrid(1)      = 'U' 
+         fbdata%cgrid(2)      = 'V'
+         DO ja = 1, nadd
+            fbdata%caddname(2+ja) = padd%cdname(ja)
+            fbdata%caddlong(2+ja,1) = padd%cdlong(ja,1)
+            fbdata%caddunit(2+ja,1) = padd%cdunit(ja,1)
+         END DO
+         ALLOCATE( &
+            & zu(profdata%nvprot(1)), &
+            & zv(profdata%nvprot(2))  &
+            & )
+         CALL obs_rotvel( profdata, k2dint, zu, zv )
+
+      END SELECT
+         
       fbdata%caddname(1)   = 'Hx'
-      fbdata%caddlong(1,1) = 'Model interpolated potential temperature'
-      fbdata%caddlong(1,2) = 'Model interpolated practical salinity'
-      fbdata%caddunit(1,1) = 'Degrees centigrade'
-      fbdata%caddunit(1,2) = 'PSU'
-      fbdata%cgrid(:)      = 'T'
-      DO ja = 1, nadd
-         fbdata%caddname(1+ja) = padd%cdname(ja)
-         DO jvar = 1, 2
-            fbdata%caddlong(1+ja,jvar) = padd%cdlong(ja,jvar)
-            fbdata%caddunit(1+ja,jvar) = padd%cdunit(ja,jvar)
-         END DO
-      END DO
          
-      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cprefix), nproc
+      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cobstype), nproc
 
       IF(lwp) THEN
          WRITE(numout,*)
-         WRITE(numout,*)'obs_wri_p3d :'
+         WRITE(numout,*)'obs_wri_prof :'
          WRITE(numout,*)'~~~~~~~~~~~~~'
          WRITE(numout,*)'Writing profile feedback file : ',TRIM(cfname)
@@ -208,5 +242,14 @@
             DO jk = profdata%npvsta(jo,jvar), profdata%npvend(jo,jvar)
                ik = profdata%var(jvar)%nvlidx(jk)
-               fbdata%padd(ik,jo,1,jvar) = profdata%var(jvar)%vmod(jk)
+               IF ( TRIM(cobstype) == 'prof' ) THEN
+                  fbdata%padd(ik,jo,1,jvar) = profdata%var(jvar)%vmod(jk)
+               ELSE IF ( TRIM(cobstype) == 'vel' ) THEN
+                  IF ( jvar == 1 ) THEN
+                     fbdata%padd(ik,jo,1,jvar) = zu(jk)
+                  ELSE
+                     fbdata%padd(ik,jo,1,jvar) = zv(jk)
+                  ENDIF
+                  fbdata%padd(ik,jo,2,jvar) = profdata%var(jvar)%vmod(jk)
+               ENDIF
                fbdata%pob(ik,jo,jvar)    = profdata%var(jvar)%vobs(jk)
                fbdata%pdep(ik,jo)        = profdata%var(jvar)%vdep(jk)
@@ -237,23 +280,25 @@
       END DO
 
-      ! Convert insitu temperature to potential temperature using the model
-      ! salinity if no potential temperature
-      DO jo = 1, fbdata%nobs
-         IF ( fbdata%pphi(jo) < 9999.0 ) THEN
-            DO jk = 1, fbdata%nlev
-               IF ( ( fbdata%pob(jk,jo,1) >= 9999.0 ) .AND. &
-                  & ( fbdata%pdep(jk,jo) < 9999.0 ) .AND. &
-                  & ( fbdata%padd(jk,jo,1,2) < 9999.0 ) .AND. &
-                  & ( fbdata%pext(jk,jo,1) < 9999.0 ) ) THEN
-                  zpres = dep_to_p( REAL(fbdata%pdep(jk,jo),wp), &
-                     &              REAL(fbdata%pphi(jo),wp) )
-                  fbdata%pob(jk,jo,1) = potemp( &
-                     &                     REAL(fbdata%padd(jk,jo,1,2), wp),  &
-                     &                     REAL(fbdata%pext(jk,jo,1), wp), &
-                     &                     zpres, 0.0_wp )
-               ENDIF
-            END DO
-         ENDIF
-      END DO
+      IF ( TRIM(cobstype) == 'prof' ) THEN
+         ! Convert insitu temperature to potential temperature using the model
+         ! salinity if no potential temperature
+         DO jo = 1, fbdata%nobs
+            IF ( fbdata%pphi(jo) < 9999.0 ) THEN
+               DO jk = 1, fbdata%nlev
+                  IF ( ( fbdata%pob(jk,jo,1) >= 9999.0 ) .AND. &
+                     & ( fbdata%pdep(jk,jo) < 9999.0 ) .AND. &
+                     & ( fbdata%padd(jk,jo,1,2) < 9999.0 ) .AND. &
+                     & ( fbdata%pext(jk,jo,1) < 9999.0 ) ) THEN
+                     zpres = dep_to_p( REAL(fbdata%pdep(jk,jo),wp), &
+                        &              REAL(fbdata%pphi(jo),wp) )
+                     fbdata%pob(jk,jo,1) = potemp( &
+                        &                     REAL(fbdata%padd(jk,jo,1,2), wp),  &
+                        &                     REAL(fbdata%pext(jk,jo,1), wp), &
+                        &                     zpres, 0.0_wp )
+                  ENDIF
+               END DO
+            ENDIF
+         END DO
+      ENDIF
       
       ! Write the obfbdata structure
@@ -265,13 +310,12 @@
       CALL dealloc_obfbdata( fbdata )
      
-   END SUBROUTINE obs_wri_p3d
-
-   SUBROUTINE obs_wri_sla( cprefix, sladata, padd, pext )
+   END SUBROUTINE obs_wri_prof
+
+   SUBROUTINE obs_wri_surf( cobstype, surfdata, padd, pext )
       !!-----------------------------------------------------------------------
       !!
-      !!                     *** ROUTINE obs_wri_sla  ***
-      !!
-      !! ** Purpose : Write SLA observation diagnostics
-      !!              related 
+      !!                     *** ROUTINE obs_wri_surf  ***
+      !!
+      !! ** Purpose : Write surface observation files
       !!
       !! ** Method  : NetCDF
@@ -281,4 +325,5 @@
       !!      ! 07-03  (K. Mogensen) Original
       !!      ! 09-01  (K. Mogensen) New feedback format.
+      !!      ! 15-02  (M. Martin) Combined surface writing routine.
       !!-----------------------------------------------------------------------
 
@@ -287,6 +332,6 @@
 
       !! * Arguments
-      CHARACTER(LEN=*), INTENT(IN) :: cprefix          ! Prefix for output files
-      TYPE(obs_surf), INTENT(INOUT) :: sladata         ! Full set of SLAa
+      CHARACTER(LEN=*), INTENT(IN) :: cobstype          ! Prefix for output files
+      TYPE(obs_surf), INTENT(INOUT) :: surfdata         ! Full set of surface data
       TYPE(obswriinfo), OPTIONAL :: padd               ! Additional info for each variable
       TYPE(obswriinfo), OPTIONAL :: pext               ! Extra info
@@ -295,5 +340,5 @@
       TYPE(obfbdata) :: fbdata
       CHARACTER(LEN=40) :: cfname         ! netCDF filename
-      CHARACTER(LEN=12), PARAMETER :: cpname = 'obs_wri_sla'
+      CHARACTER(LEN=12), PARAMETER :: cpname = 'obs_wri_surf'
       INTEGER :: jo
       INTEGER :: ja
@@ -316,54 +361,117 @@
       CALL init_obfbdata( fbdata )
 
-      CALL alloc_obfbdata( fbdata, 1, sladata%nsurf, 1, &
+      CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
          &                 2 + nadd, 1 + next, .TRUE. )
 
-      fbdata%cname(1)      = 'SLA'
-      fbdata%coblong(1)    = 'Sea level anomaly'
-      fbdata%cobunit(1)    = 'Metres'
-      fbdata%cextname(1)   = 'MDT'
-      fbdata%cextlong(1)   = 'Mean dynamic topography'
-      fbdata%cextunit(1)   = 'Metres'
-      DO je = 1, next
-         fbdata%cextname(1+je) = pext%cdname(je)
-         fbdata%cextlong(1+je) = pext%cdlong(je,1)
-         fbdata%cextunit(1+je) = pext%cdunit(je,1)
-      END DO
+      SELECT CASE ( TRIM(cobstype) )
+      CASE('sla')
+
+         fbdata%cname(1)      = 'SLA'
+         fbdata%coblong(1)    = 'Sea level anomaly'
+         fbdata%cobunit(1)    = 'Metres'
+         fbdata%cextname(1)   = 'MDT'
+         fbdata%cextlong(1)   = 'Mean dynamic topography'
+         fbdata%cextunit(1)   = 'Metres'
+         DO je = 1, next
+            fbdata%cextname(je) = pext%cdname(je)
+            fbdata%cextlong(je) = pext%cdlong(je,1)
+            fbdata%cextunit(je) = pext%cdunit(je,1)
+         END DO
+         fbdata%caddlong(1,1) = 'Model interpolated SSH - MDT'
+         fbdata%caddunit(1,1) = 'Metres' 
+         fbdata%caddname(2)   = 'SSH'
+         fbdata%caddlong(2,1) = 'Model Sea surface height'
+         fbdata%caddunit(2,1) = 'Metres'
+         fbdata%cgrid(1)      = 'T'
+         DO ja = 1, nadd
+            fbdata%caddname(2+ja) = padd%cdname(ja)
+            fbdata%caddlong(2+ja,1) = padd%cdlong(ja,1)
+            fbdata%caddunit(2+ja,1) = padd%cdunit(ja,1)
+         END DO
+
+      CASE('sst')
+
+         fbdata%cname(1)      = 'SST'
+         fbdata%coblong(1)    = 'Sea surface temperature'
+         fbdata%cobunit(1)    = 'Degree centigrade'
+         DO je = 1, next
+            fbdata%cextname(je) = pext%cdname(je)
+            fbdata%cextlong(je) = pext%cdlong(je,1)
+            fbdata%cextunit(je) = pext%cdunit(je,1)
+         END DO
+         fbdata%caddlong(1,1) = 'Model interpolated SST'
+         fbdata%caddunit(1,1) = 'Degree centigrade'
+         fbdata%cgrid(1)      = 'T'
+         DO ja = 1, nadd
+            fbdata%caddname(1+ja) = padd%cdname(ja)
+            fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
+            fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
+         END DO
+
+      CASE('sss')
+
+         fbdata%cname(1)      = 'SSS'
+         fbdata%coblong(1)    = 'Sea surface salinity'
+         fbdata%cobunit(1)    = 'PSU'
+         DO je = 1, next
+            fbdata%cextname(je) = pext%cdname(je)
+            fbdata%cextlong(je) = pext%cdlong(je,1)
+            fbdata%cextunit(je) = pext%cdunit(je,1)
+         END DO
+         fbdata%caddlong(1,1) = 'Model interpolated SSS'
+         fbdata%caddunit(1,1) = 'PSU'
+         fbdata%cgrid(1)      = 'T'
+         DO ja = 1, nadd
+            fbdata%caddname(1+ja) = padd%cdname(ja)
+            fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
+            fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
+         END DO
+
+      CASE('seaice')
+
+         fbdata%cname(1)      = 'SEAICE'
+         fbdata%coblong(1)    = 'Sea ice'
+         fbdata%cobunit(1)    = 'Fraction'
+         DO je = 1, next
+            fbdata%cextname(je) = pext%cdname(je)
+            fbdata%cextlong(je) = pext%cdlong(je,1)
+            fbdata%cextunit(je) = pext%cdunit(je,1)
+         END DO
+         fbdata%caddlong(1,1) = 'Model interpolated ICE'
+         fbdata%caddunit(1,1) = 'Fraction'
+         fbdata%cgrid(1)      = 'T'
+         DO ja = 1, nadd
+            fbdata%caddname(1+ja) = padd%cdname(ja)
+            fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
+            fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
+         END DO
+
+      END SELECT
+
       fbdata%caddname(1)   = 'Hx'
-      fbdata%caddlong(1,1) = 'Model interpolated SSH - MDT'
-      fbdata%caddunit(1,1) = 'Metres' 
-      fbdata%caddname(2)   = 'SSH'
-      fbdata%caddlong(2,1) = 'Model Sea surface height'
-      fbdata%caddunit(2,1) = 'Metres'
-      fbdata%cgrid(1)      = 'T'
-      DO ja = 1, nadd
-         fbdata%caddname(2+ja) = padd%cdname(ja)
-         fbdata%caddlong(2+ja,1) = padd%cdlong(ja,1)
-         fbdata%caddunit(2+ja,1) = padd%cdunit(ja,1)
-      END DO
-
-      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cprefix), nproc
+
+      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cobstype), nproc
 
       IF(lwp) THEN
          WRITE(numout,*)
-         WRITE(numout,*)'obs_wri_sla :'
+         WRITE(numout,*)'obs_wri_surf :'
          WRITE(numout,*)'~~~~~~~~~~~~~'
-         WRITE(numout,*)'Writing SLA feedback file : ',TRIM(cfname)
+         WRITE(numout,*)'Writing surface feedback file : ',TRIM(cfname)
       ENDIF
 
       ! Transform obs_prof data structure into obfbdata structure
       fbdata%cdjuldref = '19500101000000'
-      DO jo = 1, sladata%nsurf
-         fbdata%plam(jo)      = sladata%rlam(jo)
-         fbdata%pphi(jo)      = sladata%rphi(jo)
-         WRITE(fbdata%cdtyp(jo),'(I4)') sladata%ntyp(jo)
+      DO jo = 1, surfdata%nsurf
+         fbdata%plam(jo)      = surfdata%rlam(jo)
+         fbdata%pphi(jo)      = surfdata%rphi(jo)
+         WRITE(fbdata%cdtyp(jo),'(I4)') surfdata%ntyp(jo)
          fbdata%ivqc(jo,:)    = 0
          fbdata%ivqcf(:,jo,:) = 0
-         IF ( sladata%nqc(jo) > 10 ) THEN
+         IF ( surfdata%nqc(jo) > 10 ) THEN
             fbdata%ioqc(jo)    = 4
             fbdata%ioqcf(1,jo) = 0
-            fbdata%ioqcf(2,jo) = sladata%nqc(jo) - 10
+            fbdata%ioqcf(2,jo) = surfdata%nqc(jo) - 10
          ELSE
-            fbdata%ioqc(jo)    = sladata%nqc(jo)
+            fbdata%ioqc(jo)    = surfdata%nqc(jo)
             fbdata%ioqcf(:,jo) = 0
          ENDIF
@@ -372,46 +480,46 @@
          fbdata%itqc(jo)      = 0
          fbdata%itqcf(:,jo)   = 0
-         fbdata%cdwmo(jo)     = sladata%cwmo(jo)
-         fbdata%kindex(jo)    = sladata%nsfil(jo)
+         fbdata%cdwmo(jo)     = surfdata%cwmo(jo)
+         fbdata%kindex(jo)    = surfdata%nsfil(jo)
          IF (ln_grid_global) THEN
-            fbdata%iobsi(jo,1) = sladata%mi(jo)
-            fbdata%iobsj(jo,1) = sladata%mj(jo)
+            fbdata%iobsi(jo,1) = surfdata%mi(jo)
+            fbdata%iobsj(jo,1) = surfdata%mj(jo)
          ELSE
-            fbdata%iobsi(jo,1) = mig(sladata%mi(jo))
-            fbdata%iobsj(jo,1) = mjg(sladata%mj(jo))
+            fbdata%iobsi(jo,1) = mig(surfdata%mi(jo))
+            fbdata%iobsj(jo,1) = mjg(surfdata%mj(jo))
          ENDIF
          CALL greg2jul( 0, &
-            &           sladata%nmin(jo), &
-            &           sladata%nhou(jo), &
-            &           sladata%nday(jo), &
-            &           sladata%nmon(jo), &
-            &           sladata%nyea(jo), &
+            &           surfdata%nmin(jo), &
+            &           surfdata%nhou(jo), &
+            &           surfdata%nday(jo), &
+            &           surfdata%nmon(jo), &
+            &           surfdata%nyea(jo), &
             &           fbdata%ptim(jo),   &
             &           krefdate = 19500101 )
-         fbdata%padd(1,jo,1,1) = sladata%rmod(jo,1)
-         fbdata%padd(1,jo,2,1) = sladata%rext(jo,1)
-         fbdata%pob(1,jo,1)    = sladata%robs(jo,1) 
+         fbdata%padd(1,jo,1,1) = surfdata%rmod(jo,1)
+         IF ( TRIM(cobstype) == 'sla' ) fbdata%padd(1,jo,2,1) = surfdata%rext(jo,1)
+         fbdata%pob(1,jo,1)    = surfdata%robs(jo,1) 
          fbdata%pdep(1,jo)     = 0.0
          fbdata%idqc(1,jo)     = 0
          fbdata%idqcf(:,1,jo)  = 0
-         IF ( sladata%nqc(jo) > 10 ) THEN
+         IF ( surfdata%nqc(jo) > 10 ) THEN
             fbdata%ivqc(jo,1)       = 4
             fbdata%ivlqc(1,jo,1)    = 4
             fbdata%ivlqcf(1,1,jo,1) = 0
-            fbdata%ivlqcf(2,1,jo,1) = sladata%nqc(jo) - 10
+            fbdata%ivlqcf(2,1,jo,1) = surfdata%nqc(jo) - 10
          ELSE
-            fbdata%ivqc(jo,1)       = sladata%nqc(jo)
-            fbdata%ivlqc(1,jo,1)    = sladata%nqc(jo)
+            fbdata%ivqc(jo,1)       = surfdata%nqc(jo)
+            fbdata%ivlqc(1,jo,1)    = surfdata%nqc(jo)
             fbdata%ivlqcf(:,1,jo,1) = 0
          ENDIF
          fbdata%iobsk(1,jo,1)  = 0
-         fbdata%pext(1,jo,1) = sladata%rext(jo,2)
+         IF ( TRIM(cobstype) == 'sla' ) fbdata%pext(1,jo,1) = surfdata%rext(jo,2)
          DO ja = 1, nadd
             fbdata%padd(1,jo,2+ja,1) = &
-               & sladata%rext(jo,padd%ipoint(ja))
+               & surfdata%rext(jo,padd%ipoint(ja))
          END DO
          DO je = 1, next
             fbdata%pext(1,jo,1+je) = &
-               & sladata%rext(jo,pext%ipoint(je))
+               & surfdata%rext(jo,pext%ipoint(je))
          END DO
       END DO
@@ -425,508 +533,5 @@
       CALL dealloc_obfbdata( fbdata )
 
-   END SUBROUTINE obs_wri_sla
-
-   SUBROUTINE obs_wri_sst( cprefix, sstdata, padd, pext )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     *** ROUTINE obs_wri_sst  ***
-      !!
-      !! ** Purpose : Write SST observation diagnostics
-      !!              related 
-      !!
-      !! ** Method  : NetCDF
-      !! 
-      !! ** Action  :
-      !!
-      !!      ! 07-07  (S. Ricci) Original
-      !!      ! 09-01  (K. Mogensen) New feedback format.
-      !!-----------------------------------------------------------------------
-
-      !! * Modules used
-      IMPLICIT NONE
-
-      !! * Arguments
-      CHARACTER(LEN=*), INTENT(IN) :: cprefix       ! Prefix for output files
-      TYPE(obs_surf), INTENT(INOUT) :: sstdata      ! Full set of SST
-      TYPE(obswriinfo), OPTIONAL :: padd            ! Additional info for each variable
-      TYPE(obswriinfo), OPTIONAL :: pext            ! Extra info
-
-      !! * Local declarations 
-      TYPE(obfbdata) :: fbdata
-      CHARACTER(LEN=40) ::  cfname             ! netCDF filename
-      CHARACTER(LEN=12), PARAMETER :: cpname = 'obs_wri_sst'
-      INTEGER :: jo
-      INTEGER :: ja
-      INTEGER :: je
-      INTEGER :: nadd
-      INTEGER :: next
-
-      IF ( PRESENT( padd ) ) THEN
-         nadd = padd%inum
-      ELSE
-         nadd = 0
-      ENDIF
-
-      IF ( PRESENT( pext ) ) THEN
-         next = pext%inum
-      ELSE
-         next = 0
-      ENDIF
-
-      CALL init_obfbdata( fbdata )
-
-      CALL alloc_obfbdata( fbdata, 1, sstdata%nsurf, 1, &
-         &                 1 + nadd, next, .TRUE. )
-
-      fbdata%cname(1)      = 'SST'
-      fbdata%coblong(1)    = 'Sea surface temperature'
-      fbdata%cobunit(1)    = 'Degree centigrade'
-      DO je = 1, next
-         fbdata%cextname(je) = pext%cdname(je)
-         fbdata%cextlong(je) = pext%cdlong(je,1)
-         fbdata%cextunit(je) = pext%cdunit(je,1)
-      END DO
-      fbdata%caddname(1)   = 'Hx'
-      fbdata%caddlong(1,1) = 'Model interpolated SST'
-      fbdata%caddunit(1,1) = 'Degree centigrade'
-      fbdata%cgrid(1)      = 'T'
-      DO ja = 1, nadd
-         fbdata%caddname(1+ja) = padd%cdname(ja)
-         fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
-         fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
-      END DO
-
-      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cprefix), nproc
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*)'obs_wri_sst :'
-         WRITE(numout,*)'~~~~~~~~~~~~~'
-         WRITE(numout,*)'Writing SST feedback file : ',TRIM(cfname)
-      ENDIF
-
-      ! Transform obs_prof data structure into obfbdata structure
-      fbdata%cdjuldref = '19500101000000'
-      DO jo = 1, sstdata%nsurf
-         fbdata%plam(jo)      = sstdata%rlam(jo)
-         fbdata%pphi(jo)      = sstdata%rphi(jo)
-         WRITE(fbdata%cdtyp(jo),'(I4)') sstdata%ntyp(jo)
-         fbdata%ivqc(jo,:)    = 0
-         fbdata%ivqcf(:,jo,:) = 0
-         IF ( sstdata%nqc(jo) > 10 ) THEN
-            fbdata%ioqc(jo)    = 4
-            fbdata%ioqcf(1,jo) = 0
-            fbdata%ioqcf(2,jo) = sstdata%nqc(jo) - 10
-         ELSE
-            fbdata%ioqc(jo)    = MAX(sstdata%nqc(jo),1)
-            fbdata%ioqcf(:,jo) = 0
-         ENDIF
-         fbdata%ipqc(jo)      = 0
-         fbdata%ipqcf(:,jo)   = 0
-         fbdata%itqc(jo)      = 0
-         fbdata%itqcf(:,jo)   = 0
-         fbdata%cdwmo(jo)     = ''
-         fbdata%kindex(jo)    = sstdata%nsfil(jo)
-         IF (ln_grid_global) THEN
-            fbdata%iobsi(jo,1) = sstdata%mi(jo)
-            fbdata%iobsj(jo,1) = sstdata%mj(jo)
-         ELSE
-            fbdata%iobsi(jo,1) = mig(sstdata%mi(jo))
-            fbdata%iobsj(jo,1) = mjg(sstdata%mj(jo))
-         ENDIF
-         CALL greg2jul( 0, &
-            &           sstdata%nmin(jo), &
-            &           sstdata%nhou(jo), &
-            &           sstdata%nday(jo), &
-            &           sstdata%nmon(jo), &
-            &           sstdata%nyea(jo), &
-            &           fbdata%ptim(jo),   &
-            &           krefdate = 19500101 )
-         fbdata%padd(1,jo,1,1) = sstdata%rmod(jo,1)
-         fbdata%pob(1,jo,1)    = sstdata%robs(jo,1)
-         fbdata%pdep(1,jo)     = 0.0
-         fbdata%idqc(1,jo)     = 0
-         fbdata%idqcf(:,1,jo)  = 0
-         IF ( sstdata%nqc(jo) > 10 ) THEN
-            fbdata%ivqc(jo,1)       = 4
-            fbdata%ivlqc(1,jo,1)    = 4
-            fbdata%ivlqcf(1,1,jo,1) = 0
-            fbdata%ivlqcf(2,1,jo,1) = sstdata%nqc(jo) - 10
-         ELSE
-            fbdata%ivqc(jo,1)       = MAX(sstdata%nqc(jo),1)
-            fbdata%ivlqc(1,jo,1)    = MAX(sstdata%nqc(jo),1)
-            fbdata%ivlqcf(:,1,jo,1) = 0
-         ENDIF
-         fbdata%iobsk(1,jo,1)  = 0
-         DO ja = 1, nadd
-            fbdata%padd(1,jo,1+ja,1) = &
-               & sstdata%rext(jo,padd%ipoint(ja))
-         END DO
-         DO je = 1, next
-            fbdata%pext(1,jo,je) = &
-               & sstdata%rext(jo,pext%ipoint(je))
-         END DO
-
-      END DO
-
-      ! Write the obfbdata structure
-
-      CALL write_obfbdata( cfname, fbdata )
-
-      ! Output some basic statistics
-      CALL obs_wri_stats( fbdata )
-
-      CALL dealloc_obfbdata( fbdata )
-
-   END SUBROUTINE obs_wri_sst
-
-   SUBROUTINE obs_wri_sss
-   END SUBROUTINE obs_wri_sss
-
-   SUBROUTINE obs_wri_seaice( cprefix, seaicedata, padd, pext )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     *** ROUTINE obs_wri_seaice  ***
-      !!
-      !! ** Purpose : Write sea ice observation diagnostics
-      !!              related 
-      !!
-      !! ** Method  : NetCDF
-      !! 
-      !! ** Action  :
-      !!
-      !!      ! 07-07  (S. Ricci) Original
-      !!      ! 09-01  (K. Mogensen) New feedback format.
-      !!-----------------------------------------------------------------------
-
-      !! * Modules used
-      IMPLICIT NONE
-
-      !! * Arguments
-      CHARACTER(LEN=*), INTENT(IN) :: cprefix       ! Prefix for output files
-      TYPE(obs_surf), INTENT(INOUT) :: seaicedata   ! Full set of sea ice
-      TYPE(obswriinfo), OPTIONAL :: padd            ! Additional info for each variable
-      TYPE(obswriinfo), OPTIONAL :: pext            ! Extra info
-
-      !! * Local declarations 
-      TYPE(obfbdata) :: fbdata
-      CHARACTER(LEN=40) :: cfname             ! netCDF filename
-      CHARACTER(LEN=12), PARAMETER :: cpname = 'obs_wri_seaice'
-      INTEGER :: jo
-      INTEGER :: ja
-      INTEGER :: je
-      INTEGER :: nadd
-      INTEGER :: next
-
-      IF ( PRESENT( padd ) ) THEN
-         nadd = padd%inum
-      ELSE
-         nadd = 0
-      ENDIF
-
-      IF ( PRESENT( pext ) ) THEN
-         next = pext%inum
-      ELSE
-         next = 0
-      ENDIF
-
-      CALL init_obfbdata( fbdata )
-
-      CALL alloc_obfbdata( fbdata, 1, seaicedata%nsurf, 1, 1, 0, .TRUE. )
-
-      fbdata%cname(1)      = 'SEAICE'
-      fbdata%coblong(1)    = 'Sea ice'
-      fbdata%cobunit(1)    = 'Fraction'
-      DO je = 1, next
-         fbdata%cextname(je) = pext%cdname(je)
-         fbdata%cextlong(je) = pext%cdlong(je,1)
-         fbdata%cextunit(je) = pext%cdunit(je,1)
-      END DO
-      fbdata%caddname(1)   = 'Hx'
-      fbdata%caddlong(1,1) = 'Model interpolated ICE'
-      fbdata%caddunit(1,1) = 'Fraction'
-      fbdata%cgrid(1)      = 'T'
-      DO ja = 1, nadd
-         fbdata%caddname(1+ja) = padd%cdname(ja)
-         fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
-         fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
-      END DO
-
-      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cprefix), nproc
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*)'obs_wri_seaice :'
-         WRITE(numout,*)'~~~~~~~~~~~~~~~~'
-         WRITE(numout,*)'Writing SEAICE feedback file : ',TRIM(cfname)
-      ENDIF
-
-      ! Transform obs_prof data structure into obfbdata structure
-      fbdata%cdjuldref = '19500101000000'
-      DO jo = 1, seaicedata%nsurf
-         fbdata%plam(jo)      = seaicedata%rlam(jo)
-         fbdata%pphi(jo)      = seaicedata%rphi(jo)
-         WRITE(fbdata%cdtyp(jo),'(I4)') seaicedata%ntyp(jo)
-         fbdata%ivqc(jo,:)    = 0
-         fbdata%ivqcf(:,jo,:) = 0
-         IF ( seaicedata%nqc(jo) > 10 ) THEN
-            fbdata%ioqc(jo)    = 4
-            fbdata%ioqcf(1,jo) = 0
-            fbdata%ioqcf(2,jo) = seaicedata%nqc(jo) - 10
-         ELSE
-            fbdata%ioqc(jo)    = MAX(seaicedata%nqc(jo),1)
-            fbdata%ioqcf(:,jo) = 0
-         ENDIF
-         fbdata%ipqc(jo)      = 0
-         fbdata%ipqcf(:,jo)   = 0
-         fbdata%itqc(jo)      = 0
-         fbdata%itqcf(:,jo)   = 0
-         fbdata%cdwmo(jo)     = ''
-         fbdata%kindex(jo)    = seaicedata%nsfil(jo)
-         IF (ln_grid_global) THEN
-            fbdata%iobsi(jo,1) = seaicedata%mi(jo)
-            fbdata%iobsj(jo,1) = seaicedata%mj(jo)
-         ELSE
-            fbdata%iobsi(jo,1) = mig(seaicedata%mi(jo))
-            fbdata%iobsj(jo,1) = mjg(seaicedata%mj(jo))
-         ENDIF
-         CALL greg2jul( 0, &
-            &           seaicedata%nmin(jo), &
-            &           seaicedata%nhou(jo), &
-            &           seaicedata%nday(jo), &
-            &           seaicedata%nmon(jo), &
-            &           seaicedata%nyea(jo), &
-            &           fbdata%ptim(jo),   &
-            &           krefdate = 19500101 )
-         fbdata%padd(1,jo,1,1) = seaicedata%rmod(jo,1)
-         fbdata%pob(1,jo,1)    = seaicedata%robs(jo,1)
-         fbdata%pdep(1,jo)     = 0.0
-         fbdata%idqc(1,jo)     = 0
-         fbdata%idqcf(:,1,jo)  = 0
-         IF ( seaicedata%nqc(jo) > 10 ) THEN
-            fbdata%ivlqc(1,jo,1) = 4
-            fbdata%ivlqcf(1,1,jo,1) = 0
-            fbdata%ivlqcf(2,1,jo,1) = seaicedata%nqc(jo) - 10
-         ELSE
-            fbdata%ivlqc(1,jo,1) = MAX(seaicedata%nqc(jo),1)
-            fbdata%ivlqcf(:,1,jo,1) = 0
-         ENDIF
-         fbdata%iobsk(1,jo,1)  = 0
-         DO ja = 1, nadd
-            fbdata%padd(1,jo,1+ja,1) = &
-               & seaicedata%rext(jo,padd%ipoint(ja))
-         END DO
-         DO je = 1, next
-            fbdata%pext(1,jo,je) = &
-               & seaicedata%rext(jo,pext%ipoint(je))
-         END DO
-
-      END DO
-
-      ! Write the obfbdata structure
-      CALL write_obfbdata( cfname, fbdata )
-
-      ! Output some basic statistics
-      CALL obs_wri_stats( fbdata )
-
-      CALL dealloc_obfbdata( fbdata )
-
-   END SUBROUTINE obs_wri_seaice
-
-   SUBROUTINE obs_wri_vel( cprefix, profdata, k2dint, padd, pext )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     *** ROUTINE obs_wri_vel  ***
-      !!
-      !! ** Purpose : Write current (profile) observation 
-      !!              related diagnostics
-      !!
-      !! ** Method  : NetCDF
-      !! 
-      !! ** Action  :
-      !!
-      !! History :
-      !!      ! 09-01  (K. Mogensen) New feedback format routine
-      !!-----------------------------------------------------------------------
-
-      !! * Modules used
-
-      !! * Arguments
-      CHARACTER(LEN=*), INTENT(IN) :: cprefix       ! Prefix for output files
-      TYPE(obs_prof), INTENT(INOUT) :: profdata     ! Full set of profile data
-      INTEGER, INTENT(IN) :: k2dint                 ! Horizontal interpolation method
-      TYPE(obswriinfo), OPTIONAL :: padd            ! Additional info for each variable
-      TYPE(obswriinfo), OPTIONAL :: pext            ! Extra info
-
-      !! * Local declarations
-      TYPE(obfbdata) :: fbdata
-      CHARACTER(LEN=40) :: cfname
-      INTEGER :: ilevel
-      INTEGER :: jvar
-      INTEGER :: jk
-      INTEGER :: ik
-      INTEGER :: jo
-      INTEGER :: ja
-      INTEGER :: je
-      INTEGER :: nadd
-      INTEGER :: next
-      REAL(wp) :: zpres
-      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
-         & zu, &
-         & zv
-
-      IF ( PRESENT( padd ) ) THEN
-         nadd = padd%inum
-      ELSE
-         nadd = 0
-      ENDIF
-
-      IF ( PRESENT( pext ) ) THEN
-         next = pext%inum
-      ELSE
-         next = 0
-      ENDIF
-
-      CALL init_obfbdata( fbdata )
-
-      ! Find maximum level
-      ilevel = 0
-      DO jvar = 1, 2
-         ilevel = MAX( ilevel, MAXVAL( profdata%var(jvar)%nvlidx(:) ) )
-      END DO
-      CALL alloc_obfbdata( fbdata, 2, profdata%nprof, ilevel, 2, 0, .TRUE. )
-
-      fbdata%cname(1)      = 'UVEL'
-      fbdata%cname(2)      = 'VVEL'
-      fbdata%coblong(1)    = 'Zonal velocity'
-      fbdata%coblong(2)    = 'Meridional velocity'
-      fbdata%cobunit(1)    = 'm/s'
-      fbdata%cobunit(2)    = 'm/s'
-      DO je = 1, next
-         fbdata%cextname(je) = pext%cdname(je)
-         fbdata%cextlong(je) = pext%cdlong(je,1)
-         fbdata%cextunit(je) = pext%cdunit(je,1)
-      END DO
-      fbdata%caddname(1)   = 'Hx'
-      fbdata%caddlong(1,1) = 'Model interpolated zonal velocity'
-      fbdata%caddlong(1,2) = 'Model interpolated meridional velocity'
-      fbdata%caddunit(1,1) = 'm/s'
-      fbdata%caddunit(1,2) = 'm/s'
-      fbdata%caddname(2)   = 'HxG'
-      fbdata%caddlong(2,1) = 'Model interpolated zonal velocity (model grid)'
-      fbdata%caddlong(2,2) = 'Model interpolated meridional velocity (model grid)'
-      fbdata%caddunit(2,1) = 'm/s'
-      fbdata%caddunit(2,2) = 'm/s' 
-      fbdata%cgrid(1)      = 'U' 
-      fbdata%cgrid(2)      = 'V'
-      DO ja = 1, nadd
-         fbdata%caddname(2+ja) = padd%cdname(ja)
-         fbdata%caddlong(2+ja,1) = padd%cdlong(ja,1)
-         fbdata%caddunit(2+ja,1) = padd%cdunit(ja,1)
-      END DO
-
-      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cprefix), nproc
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*)'obs_wri_vel :'
-         WRITE(numout,*)'~~~~~~~~~~~~~'
-         WRITE(numout,*)'Writing velocuty feedback file : ',TRIM(cfname)
-      ENDIF
-
-      ALLOCATE( &
-         & zu(profdata%nvprot(1)), &
-         & zv(profdata%nvprot(2))  &
-         & )
-      CALL obs_rotvel( profdata, k2dint, zu, zv )
-
-      ! Transform obs_prof data structure into obfbdata structure
-      fbdata%cdjuldref = '19500101000000'
-      DO jo = 1, profdata%nprof
-         fbdata%plam(jo)      = profdata%rlam(jo)
-         fbdata%pphi(jo)      = profdata%rphi(jo)
-         WRITE(fbdata%cdtyp(jo),'(I4)') profdata%ntyp(jo)
-         fbdata%ivqc(jo,:)    = profdata%ivqc(jo,:)
-         fbdata%ivqcf(:,jo,:) = profdata%ivqcf(:,jo,:)
-         IF ( profdata%nqc(jo) > 10 ) THEN
-            fbdata%ioqc(jo)    = 4
-            fbdata%ioqcf(1,jo) = profdata%nqcf(1,jo)
-            fbdata%ioqcf(2,jo) = profdata%nqc(jo) - 10
-         ELSE
-            fbdata%ioqc(jo)    = profdata%nqc(jo)
-            fbdata%ioqcf(:,jo) = profdata%nqcf(:,jo)
-         ENDIF
-         fbdata%ipqc(jo)      = profdata%ipqc(jo)
-         fbdata%ipqcf(:,jo)   = profdata%ipqcf(:,jo)
-         fbdata%itqc(jo)      = profdata%itqc(jo)
-         fbdata%itqcf(:,jo)   = profdata%itqcf(:,jo)
-         fbdata%cdwmo(jo)     = profdata%cwmo(jo)
-         fbdata%kindex(jo)    = profdata%npfil(jo)
-         DO jvar = 1, profdata%nvar
-            IF (ln_grid_global) THEN
-               fbdata%iobsi(jo,jvar) = profdata%mi(jo,jvar)
-               fbdata%iobsj(jo,jvar) = profdata%mj(jo,jvar)
-            ELSE
-               fbdata%iobsi(jo,jvar) = mig(profdata%mi(jo,jvar))
-               fbdata%iobsj(jo,jvar) = mjg(profdata%mj(jo,jvar))
-            ENDIF
-         END DO
-         CALL greg2jul( 0, &
-            &           profdata%nmin(jo), &
-            &           profdata%nhou(jo), &
-            &           profdata%nday(jo), &
-            &           profdata%nmon(jo), &
-            &           profdata%nyea(jo), &
-            &           fbdata%ptim(jo),   &
-            &           krefdate = 19500101 )
-         ! Reform the profiles arrays for output
-         DO jvar = 1, 2
-            DO jk = profdata%npvsta(jo,jvar), profdata%npvend(jo,jvar)
-               ik = profdata%var(jvar)%nvlidx(jk)
-               IF ( jvar == 1 ) THEN
-                  fbdata%padd(ik,jo,1,jvar) = zu(jk)
-               ELSE
-                  fbdata%padd(ik,jo,1,jvar) = zv(jk)
-               ENDIF
-               fbdata%padd(ik,jo,2,jvar) = profdata%var(jvar)%vmod(jk)
-               fbdata%pob(ik,jo,jvar)    = profdata%var(jvar)%vobs(jk)
-               fbdata%pdep(ik,jo)        = profdata%var(jvar)%vdep(jk)
-               fbdata%idqc(ik,jo)        = profdata%var(jvar)%idqc(jk)
-               fbdata%idqcf(:,ik,jo)     = profdata%var(jvar)%idqcf(:,jk)
-               IF ( profdata%var(jvar)%nvqc(jk) > 10 ) THEN
-                  fbdata%ivlqc(ik,jo,jvar) = 4
-                  fbdata%ivlqcf(1,ik,jo,jvar) = profdata%var(jvar)%nvqcf(1,jk)
-                  fbdata%ivlqcf(2,ik,jo,jvar) = profdata%var(jvar)%nvqc(jk) - 10
-               ELSE
-                  fbdata%ivlqc(ik,jo,jvar) = profdata%var(jvar)%nvqc(jk)
-                  fbdata%ivlqcf(:,ik,jo,jvar) = profdata%var(jvar)%nvqcf(:,jk)
-               ENDIF
-               fbdata%iobsk(ik,jo,jvar)  = profdata%var(jvar)%mvk(jk)
-               DO ja = 1, nadd
-                  fbdata%padd(ik,jo,2+ja,jvar) = &
-                     & profdata%var(jvar)%vext(jk,padd%ipoint(ja))
-               END DO
-               DO je = 1, next
-                  fbdata%pext(ik,jo,je) = &
-                     & profdata%var(jvar)%vext(jk,pext%ipoint(je))
-               END DO
-            END DO
-         END DO
-      END DO
-
-      ! Write the obfbdata structure
-      CALL write_obfbdata( cfname, fbdata )
-      
-      ! Output some basic statistics
-      CALL obs_wri_stats( fbdata )
-
-      CALL dealloc_obfbdata( fbdata )
-     
-      DEALLOCATE( &
-         & zu, &
-         & zv  &
-         & )
-
-   END SUBROUTINE obs_wri_vel
+   END SUBROUTINE obs_wri_surf
 
    SUBROUTINE obs_wri_stats( fbdata )
@@ -952,7 +557,4 @@
       INTEGER :: jk
 
-!      INTEGER :: nlev
-!      INTEGER :: nlevmpp
-!      INTEGER :: nobsmpp
       INTEGER :: numgoodobs
       INTEGER :: numgoodobsmpp
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obsprof_io.h90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obsprof_io.h90	(revision 5658)
+++ 	(revision )
@@ -1,834 +1,0 @@
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE read_enactfile( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_enactfile **
-      !!
-      !! ** Purpose : Read from file the profile ENACT observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      INTEGER :: iobs                ! Number of observations
-      INTEGER :: ilev                      ! Number of levels
-      INTEGER :: i_file_id
-      INTEGER :: i_obs_id
-      INTEGER :: i_lev_id
-      INTEGER :: i_phi_id
-      INTEGER :: i_lam_id
-      INTEGER :: i_depth_id
-      INTEGER :: i_var_id
-      INTEGER :: i_pl_num_id
-      INTEGER :: i_reference_date_time_id
-      INTEGER :: i_format_version_id
-      INTEGER :: i_juld_id
-      INTEGER :: i_data_type_id
-      INTEGER :: i_wmo_inst_type_id
-      INTEGER :: i_qc_var_id
-      INTEGER :: i_dc_ref_id
-      INTEGER :: i_qc_flag_id
-      CHARACTER(LEN=40) :: cl_fld_lam
-      CHARACTER(LEN=40) :: cl_fld_phi
-      CHARACTER(LEN=40) :: cl_fld_depth 
-      CHARACTER(LEN=40) :: cl_fld_var_tp
-      CHARACTER(LEN=40) :: cl_fld_var_s
-      CHARACTER(LEN=40) :: cl_fld_var_ti
-      CHARACTER(LEN=40) :: cl_fld_var_juld_qc
-      CHARACTER(LEN=40) :: cl_fld_var_pos_qc
-      CHARACTER(LEN=40) :: cl_fld_var_depth_qc 
-      CHARACTER(LEN=40) :: cl_fld_var_qc_t
-      CHARACTER(LEN=40) :: cl_fld_var_qc_s
-      CHARACTER(LEN=40) :: cl_fld_var_prof_qc_t
-      CHARACTER(LEN=40) :: cl_fld_var_prof_qc_s
-      CHARACTER(LEN=40) :: cl_fld_reference_date_time
-      CHARACTER(LEN=40) :: cl_fld_juld
-      CHARACTER(LEN=40) :: cl_fld_data_type
-      CHARACTER(LEN=40) :: cl_fld_pl_num
-      CHARACTER(LEN=40) :: cl_fld_format_version
-      CHARACTER(LEN=40) :: cl_fld_wmo_inst_type
-      CHARACTER(LEN=40) :: cl_fld_qc_flags_profiles
-      CHARACTER(LEN=40) :: cl_fld_qc_flags_levels
-
-      CHARACTER(LEN=14), PARAMETER :: cl_name = 'read_enactfile'
-      CHARACTER(LEN=16)            :: cl_data_type = ''
-      CHARACTER(LEN=4 )            :: cl_format_version = ''
-      INTEGER, DIMENSION(1) :: istart1, icount1
-      INTEGER, DIMENSION(2) :: istart2, icount2
-      CHARACTER(len=imaxlev) :: clqc
-      CHARACTER(len=1) :: cqc
-      INTEGER :: ji, jk
-      INTEGER, ALLOCATABLE, DIMENSION(:) :: iqc1
-      INTEGER, ALLOCATABLE, DIMENSION(:,:) :: iqc2
-
-      !-----------------------------------------------------------------------
-      ! Initialization
-      !-----------------------------------------------------------------------
-
-      cl_fld_lam                 = 'LONGITUDE'
-      cl_fld_phi                 = 'LATITUDE'
-      cl_fld_depth               = 'DEPH_CORRECTED'
-      cl_fld_reference_date_time = 'REFERENCE_DATE_TIME'
-      cl_fld_juld                = 'JULD'
-      cl_fld_data_type           = 'DATA_TYPE'
-      cl_fld_format_version      = 'FORMAT_VERSION'
-      cl_fld_wmo_inst_type       = 'WMO_INST_TYPE'
-      cl_fld_pl_num              = 'PLATFORM_NUMBER'
-
-      cl_fld_var_qc_t            = 'POTM_CORRECTED_QC'
-      cl_fld_var_prof_qc_t       = 'PROFILE_POTM_QC'
-      cl_fld_var_tp              = 'POTM_CORRECTED'
-      cl_fld_var_qc_s            = 'PSAL_CORRECTED_QC'
-      cl_fld_var_prof_qc_s       = 'PROFILE_PSAL_QC'
-      cl_fld_var_s               = 'PSAL_CORRECTED'
-      cl_fld_var_depth_qc        = 'DEPH_CORRECTED_QC'
-      cl_fld_var_juld_qc         = 'JULD_QC'
-      cl_fld_var_pos_qc          = 'POSITION_QC'
-      cl_fld_var_ti              = 'TEMP'
-      cl_fld_qc_flags_profiles   = 'QC_FLAGS_PROFILES'
-      cl_fld_qc_flags_levels     = 'QC_FLAGS_LEVELS'
-
-      icount1(1) = 1 
-
-      !-----------------------------------------------------------------------
-      ! Open file
-      !-----------------------------------------------------------------------
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-            &      i_file_id ),           cl_name, __LINE__ )
-
-      !-----------------------------------------------------------------------
-      ! Read the heading of the file
-      !-----------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_data_type,      &
-         &         i_data_type_id ),      cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_data_type_id,        &
-         &         cl_data_type ),        cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_format_version, &
-         &         i_format_version_id ), cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_format_version_id,   &
-         &         cl_format_version ),   cl_name, __LINE__ )
-      
-      CALL str_c_to_for( cl_data_type )
-      CALL str_c_to_for( cl_format_version )
-      
-      IF(ldwp)WRITE(kunit,*)
-      IF(ldwp)WRITE(kunit,*) ' read_enactfile :' 
-      IF(ldwp)WRITE(kunit,*) ' ~~~~~~~~~~~~~~~~'
-      IF(ldwp)WRITE(kunit,*) '               Data type           = ', &
-         &                TRIM( ADJUSTL( cl_data_type ) )
-      IF(ldwp)WRITE(kunit,*) '               Format version      = ',  &
-         &                TRIM( ADJUSTL( cl_format_version ) )
-      
-      IF ( ( ( INDEX( cl_data_type,"ENACT v1.0" ) == 1 ) .OR.   &
-         &   ( INDEX( cl_data_type,"ENACT v1.4" ) == 1 ) .OR.   &
-         &   ( INDEX( cl_data_type,"ENACT v1.5" ) == 1 ) .OR.   &
-         &   ( INDEX( cl_data_type,"ENSEMBLES EN3 v1" ) == 1 )      ) &
-         &   .AND.                                              &
-         &   ( INDEX( cl_format_version,"2.0"   ) == 1 ) ) THEN
-         IF(ldwp)WRITE(kunit,*)'               Valid input file'
-      ELSE
-         CALL fatal_error( 'Invalid input file', __LINE__ )
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Read the number of observations and levels to allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'N_PROF', i_obs_id ),         &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_obs_id, len = iobs ),     &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'N_LEVELS', i_lev_id ),     &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_lev_id, len = ilev ), &
-         &         cl_name, __LINE__ )
-      IF(ldwp)WRITE(kunit,*) '               No. of data records = ', iobs
-      IF(ldwp)WRITE(kunit,*) '               No. of levels       = ', ilev
-      IF(ldwp)WRITE(kunit,*) 
-      IF (ilev > imaxlev) THEN
-         CALL fatal_error( 'Increase imaxlev in obs_prof_io.F90', __LINE__ )
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 1, ldgrid )
-      inpfile%cname(1) = 'POTM'
-      inpfile%cname(2) = 'PSAL'
-      inpfile%coblong(1) = 'Potential temperature'
-      inpfile%coblong(2) = 'Practical salinity'
-      inpfile%cobunit(1) = 'Degrees Celsius'
-      inpfile%cobunit(2) = 'PSU'
-      inpfile%cextname(1) = 'TEMP'
-      inpfile%cextlong(1) = 'Insitu temperature'
-      inpfile%cextunit(1) = 'Degrees Celsius'
-
-      !---------------------------------------------------------------------
-      ! Read the QC atributes
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_t, i_qc_var_id ),                         &
-         &         cl_name, __LINE__ )        
-      istart2(1) = 1
-      icount2(2) = 1
-      icount2(1) = ilev
-      DO ji = 1, iobs 
-         istart2(2) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                   &
-            &                         start = istart2, count = icount2),                              &
-            &         cl_name, __LINE__ )
-         DO jk = 1, ilev
-            inpfile%ivlqc(jk,ji,1) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-         END DO
-      END DO
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_s, i_qc_var_id ),                         &
-         &         cl_name, __LINE__ )
-      DO ji = 1, iobs
-         istart2(2) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                   &
-            &                         start = istart2, count = icount2),                              &
-            &         cl_name, __LINE__ )
-         DO jk = 1, ilev
-            inpfile%ivlqc(jk,ji,2) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-         END DO
-      END DO
-      ! No depth QC in files
-      DO ji = 1, iobs
-         DO jk = 1, ilev
-            inpfile%idqc(jk,ji)  = 1
-            inpfile%idqcf(:,jk,ji) = 0
-         END DO
-      END DO
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_t, i_qc_var_id ),                    &
-         &         cl_name,  __LINE__ )
-      DO ji = 1,iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ivqc(ji,1) = IACHAR( cqc ) - IACHAR( '0' )
-      END DO
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_s, i_qc_var_id ),                    & 
-         &         cl_name, __LINE__ ) 
-      DO ji = 1,iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ivqc(ji,2) = IACHAR( cqc ) - IACHAR( '0' )
-      END DO
-!!      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_juld_qc, i_qc_var_id ),                       &
-!!         &         cl_name, __LINE__ ) 
-!!      !DO ji = 1,iobs
-!!         istart1(1) = ji
-!!         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-!!            &                         start = istart1, count = icount1),                              &
-!!            &         cl_name, __LINE__ )
-!!         inpfile%itqc(ji)    = IACHAR( cqc ) - IACHAR( '0' )
-!!         inpfile%itqcf(:,ji) = 0
-!!      END DO
-      ! Since the flags are not set in the ENACT files we reset them to 0
-      inpfile%itqc(:)    = 1      
-      inpfile%itqcf(:,:) = 0
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_pos_qc, i_qc_var_id ),                       &
-         &         cl_name, __LINE__ ) 
-      DO ji = 1,iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ipqc(ji)    = IACHAR( cqc ) - IACHAR( '0' )
-         inpfile%ipqcf(:,ji) = 0
-      END DO
-      DO ji = 1,iobs
-         inpfile%ioqc(ji) = MIN( inpfile%ivqc(ji,1), inpfile%ivqc(ji,2) )
-      END DO
-      IF ( nf90_inq_varid( i_file_id, cl_fld_qc_flags_profiles, i_qc_flag_id ) == nf90_noerr ) THEN
-         ALLOCATE( &
-            & iqc1(iobs) &
-            & )
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_flag_id, iqc1 ),                                &
-            &         cl_name, __LINE__ )
-         DO ji = 1,iobs
-            inpfile%ioqcf(1,ji)   = iqc1(ji)
-            inpfile%ivqcf(1,ji,:) = iqc1(ji)
-            inpfile%ioqcf(2,ji)   = 0
-            inpfile%ivqcf(2,ji,:) = 0
-         END DO
-         DEALLOCATE( &
-            & iqc1 &
-            & )
-      ELSE
-         IF(ldwp) WRITE(kunit,*)'No QC profile flags in file'
-         inpfile%ioqcf(:,:)   = 0
-         inpfile%ivqcf(:,:,:) = 0
-      ENDIF
-      IF ( nf90_inq_varid( i_file_id, cl_fld_qc_flags_levels, i_qc_flag_id ) == nf90_noerr ) THEN
-         ALLOCATE( &
-            & iqc2(ilev,iobs) &
-            & )
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_flag_id, iqc2 ),                                &
-            &         cl_name, __LINE__ )
-         DO ji = 1,iobs
-            DO jk = 1,ilev
-               inpfile%ivlqcf(1,jk,ji,:) = iqc2(jk,ji)
-               inpfile%ivlqcf(2,jk,ji,:) = 0
-            END DO
-         END DO
-         DEALLOCATE( &
-            & iqc2 &
-            & )
-      ELSE
-         IF(ldwp) WRITE(kunit,*)'No QC level flags in file'
-         inpfile%ivlqcf(:,:,:,:) = 0
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Read the time/position variables 
-      !---------------------------------------------------------------------
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_juld, i_juld_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_juld_id, inpfile%ptim ),                              &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ),                             &
-            &         cl_name, __LINE__ )         
-      CALL chkerr( nf90_get_var  ( i_file_id, i_depth_id, inpfile%pdep ),                             &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_phi_id, inpfile%pphi ),                               &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_lam_id, inpfile%plam ),                               &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_reference_date_time, i_reference_date_time_id ), &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_reference_date_time_id, inpfile%cdjuldref ),          &
-         &         cl_name, __LINE__ )
-      
-      !---------------------------------------------------------------------
-      ! Read the platform information
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_wmo_inst_type, i_wmo_inst_type_id ),             &
-         &         cl_name, __LINE__ )          
-      CALL chkerr( nf90_get_var  ( i_file_id, i_wmo_inst_type_id, inpfile%cdtyp ),                    &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pl_num, i_pl_num_id ),                           &
-         &         cl_name, __LINE__ )         
-      CALL chkerr( nf90_get_var  ( i_file_id, i_pl_num_id, inpfile%cdwmo ),                           &
-         &         cl_name, __LINE__ )         
-
-      !---------------------------------------------------------------------
-      ! Read the variables
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_tp, i_var_id ),                              &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pob(:,:,1) ),                         &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_s, i_var_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pob(:,:,2) ),                         &
-         &         cl_name, __LINE__ )
- 
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_ti, i_var_id ),                              &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pext(:,:,1) ),                        &
-         &         cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Close file
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_close( i_file_id ),           cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Set file indexes
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         inpfile%kindex(ji) = ji
-      END DO
-
-   END SUBROUTINE read_enactfile
-
-   SUBROUTINE read_coriofile( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_coriofile **
-      !!
-      !! ** Purpose : Read from file the profile CORIO observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output enactfile structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      INTEGER  :: &
-         & iobs, &
-         & ilev
-      !! * Local declarations
-      INTEGER :: &
-         & i_file_id,                &
-         & i_obs_id,                 &
-         & i_lev_id,                 &
-         & i_phi_id,                 & 
-         & i_lam_id,                 &
-         & i_depth_id,               &
-         & i_pres_id,                &
-         & i_var_id,                 &
-         & i_pl_num_id,              &
-         & i_format_version_id,      &
-         & i_juld_id,                &
-         & i_data_type_id,           &
-         & i_wmo_inst_type_id,       &
-         & i_qc_var_id,              &
-         & i_dc_ref_id
-      CHARACTER(LEN=40) :: & 
-         & cl_fld_lam,                 &
-         & cl_fld_phi,                 &
-         & cl_fld_depth,               & 
-         & cl_fld_depth_qc,            & 
-         & cl_fld_pres,                & 
-         & cl_fld_pres_qc,             & 
-         & cl_fld_var_t,               &
-         & cl_fld_var_s,               &
-         & cl_fld_var_ti,              &
-         & cl_fld_var_pos_qc,          &
-         & cl_fld_var_qc_t,            &
-         & cl_fld_var_qc_s,            &
-         & cl_fld_var_prof_qc_t,       &
-         & cl_fld_var_prof_qc_s,       &
-         & cl_fld_dc_ref,              &
-         & cl_fld_juld,                &
-         & cl_fld_pl_num,              &
-         & cl_fld_wmo_inst_type
-      CHARACTER(LEN=14), PARAMETER :: &
-         & cl_name = 'read_coriofile'
-      CHARACTER(LEN=4 )            :: &
-         & cl_format_version = ''
-      INTEGER, DIMENSION(1) :: &
-         & istart1, icount1
-      INTEGER, DIMENSION(2) :: &
-         & istart2, icount2
-      CHARACTER(len=imaxlev) :: &
-         & clqc
-      CHARACTER(len=1) :: &
-         & cqc
-      CHARACTER(len=256) :: &
-         & cdjulref
-      INTEGER :: &
-         & ji, jk
-      INTEGER :: &
-         & iformat
-      LOGICAL :: & 
-         & lsal
-      REAL(fbdp), DIMENSION(:,:), ALLOCATABLE :: &
-         & zpres
-      INTEGER, DIMENSION(:,:), ALLOCATABLE :: &
-         & ipresqc
-      CHARACTER(len=256) :: &
-         & cerr
-      !-----------------------------------------------------------------------
-      ! Initialization
-      !-----------------------------------------------------------------------
-
-      icount1(1) = 1 
-      lsal = .TRUE.
-
-      !-----------------------------------------------------------------------
-      ! Open file
-      !-----------------------------------------------------------------------
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-            &      i_file_id ),           cl_name, __LINE__ )
-
-      !-----------------------------------------------------------------------
-      ! Check format and set variables accordingly
-      !-----------------------------------------------------------------------
-
-      IF ( ( nf90_inq_dimid( i_file_id, 'N_PROF', i_obs_id ) == nf90_noerr ) .AND. &
-         & ( nf90_inq_dimid( i_file_id, 'N_LEVELS', i_lev_id ) == nf90_noerr ) ) THEN
-         iformat = 1
-      ELSEIF ( ( nf90_inq_dimid( i_file_id, 'mN_PROF', i_obs_id ) == nf90_noerr ) .AND. &
-         & ( nf90_inq_dimid( i_file_id, 'mN_ZLEV', i_lev_id ) == nf90_noerr ) ) THEN
-         iformat = 2
-      ELSE
-         WRITE(cerr,'(2A)')'Invalid data format in ',cl_name
-         CALL fatal_error( cerr, __LINE__ )
-      ENDIF
-      IF ( iformat == 1 ) THEN
-         cl_fld_lam                 = 'LONGITUDE'
-         cl_fld_phi                 = 'LATITUDE'  
-         cl_fld_depth               = 'DEPH'
-         cl_fld_depth_qc            = 'DEPH_QC'
-         cl_fld_pres                = 'PRES'
-         cl_fld_pres_qc             = 'PRES_QC'
-         cl_fld_juld                = 'JULD'
-         cl_fld_wmo_inst_type       = 'WMO_INST_TYPE'
-         cl_fld_dc_ref              = 'DC_REFERENCE'
-         cl_fld_pl_num              = 'PLATFORM_NUMBER'
-         cl_fld_var_qc_t            = 'TEMP_QC'
-         cl_fld_var_prof_qc_t       = 'PROFILE_TEMP_QC'
-         cl_fld_var_t               = 'TEMP'
-         cl_fld_var_qc_s            = 'PSAL_QC'
-         cl_fld_var_prof_qc_s       = 'PROFILE_PSAL_QC'
-         cl_fld_var_s               = 'PSAL'
-         cl_fld_var_pos_qc          = 'POSITION_QC'
-      ELSEIF ( iformat==2 ) THEN
-         cl_fld_lam                 = 'LONGITUDE'
-         cl_fld_phi                 = 'LATITUDE'  
-         cl_fld_depth               = 'DEPH'
-         cl_fld_depth_qc            = 'QC_DEPH'
-         cl_fld_pres                = 'PRES'
-         cl_fld_pres_qc             = 'QC_PRES'
-         cl_fld_juld                = 'JULD'
-         cl_fld_wmo_inst_type       = 'INST_TYPE'
-         cl_fld_dc_ref              = 'REFERENCE'
-         cl_fld_pl_num              = 'PLATFORM_NUMBER'
-         cl_fld_var_qc_t            = 'QC_TEMP'
-         cl_fld_var_prof_qc_t       = 'Q_PROFILE_TEMP'
-         cl_fld_var_t               = 'TEMP'
-         cl_fld_var_qc_s            = 'QC_PSAL'
-         cl_fld_var_prof_qc_s       = 'Q_PROFILE_PSAL'
-         cl_fld_var_s               = 'PSAL'
-         cl_fld_var_pos_qc          = 'Q_POSITION'
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Read the heading of the file
-      !-----------------------------------------------------------------------
-
-      IF(ldwp)WRITE(kunit,*)
-      IF(ldwp)WRITE(kunit,*) ' read_coriofile :' 
-      IF(ldwp)WRITE(kunit,*) ' ~~~~~~~~~~~~~~~~'
-      IF(ldwp)WRITE(kunit,*) '               Format version      = ', iformat
-
-      !---------------------------------------------------------------------
-      ! Read the number of observations and levels to allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_obs_id, len = iobs ), &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_lev_id, len = ilev ), &
-         &         cl_name, __LINE__ )
-      IF(ldwp)WRITE(kunit,*) '               No. of data records = ', iobs
-      IF(ldwp)WRITE(kunit,*) '               No. of levels       = ', ilev
-      IF(ldwp)WRITE(kunit,*) 
-      IF (ilev > imaxlev) THEN
-         CALL fatal_error( 'Increase imaxlev in obs_prof_io.F90', __LINE__ )
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 1, ldgrid )
-      inpfile%cname(1) = 'POTM'
-      inpfile%cname(2) = 'PSAL'
-      inpfile%coblong(1) = 'Potential temperature'
-      inpfile%coblong(2) = 'Practical salinity'
-      inpfile%cobunit(1) = 'Degrees Celsius'
-      inpfile%cobunit(2) = 'PSU'
-      inpfile%cextname(1) = 'TEMP'
-      inpfile%cextlong(1) = 'Insitu temperature'
-      inpfile%cextunit(1) = 'Degrees Celsius'
-      ALLOCATE( &
-         & zpres(ilev,iobs),  &
-         & ipresqc(ilev,iobs) &
-         & )
-      !---------------------------------------------------------------------
-      ! Get julian data reference (iformat==2)
-      !---------------------------------------------------------------------
-
-      IF (iformat==2) THEN
-         CALL chkerr ( nf90_get_att( i_file_id, nf90_global, &
-            &                        "Reference_date_time", cdjulref ), &
-            &         cl_name, __LINE__ )
-         inpfile%cdjuldref = cdjulref(7:10)//cdjulref(4:5)// &
-            & cdjulref(1:2)//cdjulref(12:13)//cdjulref(15:16)//cdjulref(18:19)
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Read the QC attributes
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_t, i_qc_var_id ),                                &
-         &         cl_name, __LINE__ )
-      istart2(1) = 1
-      icount2(2) = 1
-      icount2(1) = ilev
-      DO ji = 1, iobs 
-         istart2(2) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                   &
-            &                         start = istart2, count = icount2),                              &
-            &         cl_name, __LINE__ )
-         DO jk = 1, ilev
-            inpfile%ivlqc(jk,ji,1) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-         END DO
-      END DO
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_s, i_qc_var_id ) == nf90_noerr ) THEN
-         DO ji = 1, iobs
-            istart2(2) = ji
-            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                &
-               &                         start = istart2, count = icount2),                           &
-               &         cl_name, __LINE__ )
-            DO jk = 1, ilev
-               inpfile%ivlqc(jk,ji,2) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-            END DO
-         END DO
-      ELSE
-         inpfile%ivlqc(:,:,2) = 4
-         inpfile%pob(:,:,2) = fbrmdi
-         lsal = .FALSE.
-      ENDIF
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_t, i_qc_var_id ),                    &
-         &         cl_name,  __LINE__ )
-      DO ji = 1,iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ivqc(ji,1) = IACHAR( cqc ) - IACHAR( '0' )
-      END DO
-      IF (lsal) THEN
-         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_s, i_qc_var_id ),                 & 
-            &         cl_name, __LINE__ ) 
-         DO ji = 1,iobs
-            istart1(1) = ji
-            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                 &
-               &                         start = istart1, count = icount1),                           &
-               &         cl_name, __LINE__ )
-            inpfile%ivqc(ji,2) = IACHAR( cqc ) - IACHAR( '0' )
-         END DO
-      ELSE
-         inpfile%ivqc(:,2) = 4
-      ENDIF
-      DO ji = 1,iobs
-         inpfile%ioqc(ji) = MIN( inpfile%ivqc(ji,1), inpfile%ivqc(ji,2) )
-      END DO
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_pos_qc, i_qc_var_id ),                       &
-         &         cl_name, __LINE__ ) 
-      DO ji = 1, iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ipqc(ji)  = IACHAR( cqc ) - IACHAR( '0' )
-      END DO
-      
-      !---------------------------------------------------------------------
-      ! Read the time/position variables 
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_juld, i_juld_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_juld_id, inpfile%ptim ),                              &
-         &         cl_name, __LINE__ )
-      IF (iformat==1) THEN
-         CALL chkerr ( nf90_get_att( i_file_id, i_juld_id, &
-            &                        "units", cdjulref ), &
-            &         cl_name, __LINE__ )
-         inpfile%cdjuldref = cdjulref(12:15)//cdjulref(17:18)// &
-            & cdjulref(20:21)//cdjulref(23:24)//cdjulref(26:27)//&
-            & cdjulref(29:30)
-      ENDIF
-      
-      IF ( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ) == nf90_noerr ) THEN
-         CALL chkerr( nf90_get_var  ( i_file_id, i_depth_id, inpfile%pdep ),                          &
-            &         cl_name, __LINE__ )
-         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth_qc, i_qc_var_id ),                      & 
-            &         cl_name, __LINE__ ) 
-         DO ji = 1, iobs
-            istart2(2) = ji
-            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                &
-               &                         start = istart2, count = icount2),                           &
-               &         cl_name, __LINE__ )
-            DO jk = 1, ilev
-               inpfile%idqc(jk,ji) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-            END DO
-         END DO
-      ELSE
-         inpfile%pdep(:,:) = fbrmdi
-         inpfile%idqc(:,:) = 4
-      ENDIF
-
-      IF ( nf90_inq_varid( i_file_id, cl_fld_pres, i_pres_id ) == nf90_noerr ) THEN
-         CALL chkerr( nf90_get_var  ( i_file_id, i_pres_id, zpres ),                                  &
-            &         cl_name, __LINE__ )
-         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pres_qc, i_qc_var_id ),                       & 
-            &         cl_name, __LINE__ ) 
-         DO ji = 1, iobs
-            istart2(2) = ji
-            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                &
-               &                         start = istart2, count = icount2),                           &
-               &         cl_name, __LINE__ )
-            DO jk = 1, ilev
-               ipresqc(jk,ji) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-            END DO
-         END DO
-      ELSE
-         zpres(:,:) = fbrmdi
-         ipresqc(:,:) = 4
-      ENDIF
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_phi_id, inpfile%pphi ),                               &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_lam_id, inpfile%plam ),                               &
-         &         cl_name, __LINE__ )
-      
-      !---------------------------------------------------------------------
-      ! Read the platform information
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_wmo_inst_type, i_wmo_inst_type_id ),             &
-         &         cl_name, __LINE__ )          
-      CALL chkerr( nf90_get_var  ( i_file_id, i_wmo_inst_type_id, inpfile%cdtyp ),                    &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pl_num, i_pl_num_id ),                           &
-         &         cl_name, __LINE__ )         
-      CALL chkerr( nf90_get_var  ( i_file_id, i_pl_num_id, inpfile%cdwmo ),                           &
-         &         cl_name, __LINE__ )         
-
-      
-      !---------------------------------------------------------------------
-      ! Read the variables
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_t, i_var_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pext(:,:,1) ),                        &
-         &         cl_name, __LINE__ )
-
-      IF (lsal) THEN      
-         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_s, i_var_id ),                            &
-            &         cl_name, __LINE__ )
-         CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pob(:,:,2) ),                      &
-            &         cl_name, __LINE__ )
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Close file
-      !---------------------------------------------------------------------
-         
-      CALL chkerr( nf90_close( i_file_id ),           cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Set file indexes
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         inpfile%kindex(ji) = ji
-      END DO
-      
-      !---------------------------------------------------------------------
-      !  Coriolis data conversion from insitu to potential temperature
-      !---------------------------------------------------------------------
-      !---------------------------------------------------------------------
-      !  Convert pressure to depth if depth not present
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         IF ( inpfile%pphi(ji) < 9999.0 ) THEN
-            DO jk = 1, inpfile%nlev
-               IF ( inpfile%pdep(jk,ji) >= 9999.0 ) THEN
-                  IF ( zpres(jk,ji) < 9999.0 ) THEN
-                     inpfile%pdep(jk,ji) = &
-                        & p_to_dep( REAL(zpres(jk,ji),wp), REAL(inpfile%pphi(ji),wp) )
-                     inpfile%idqc(jk,ji) = ipresqc(jk,ji)
-                  ENDIF
-               ENDIF
-            END DO
-         ENDIF
-      END DO
-      
-      !---------------------------------------------------------------------
-      !  Convert depth to pressure if pressure not present
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         IF ( inpfile%pphi(ji) < 9999.0 ) THEN
-            DO jk = 1, inpfile%nlev
-               IF ( zpres(jk,ji) >= 9999.0 ) THEN
-                  IF ( inpfile%pdep(jk,ji) < 9999.0 ) THEN
-                     zpres(jk,ji) = dep_to_p( REAL(inpfile%pdep(jk,ji),wp), &
-                        &                            REAL(inpfile%pphi(ji),wp) )
-                     ipresqc(jk,ji) = inpfile%idqc(jk,ji)
-                  ENDIF
-               ENDIF
-            END DO
-         ENDIF
-      END DO
-      
-      !---------------------------------------------------------------------
-      !  Convert insitu temperature to potential temperature if
-      !  salinity, insitu temperature and pressure are present
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         DO jk = 1, inpfile%nlev
-            IF (( inpfile%pob(jk,ji,2) < 9999.0 ) .AND. &
-               &( inpfile%pext(jk,ji,1) < 9999.0 ) .AND. &
-               &( zpres(jk,ji) < 9999.0 ) ) THEN
-               inpfile%pob(jk,ji,1) = potemp( REAL(inpfile%pob(jk,ji,2), wp),  &
-                  &                           REAL(inpfile%pext(jk,ji,1), wp), &
-                  &                           REAL(zpres(jk,ji),wp),  &
-                  &                           0.0_wp )
-            ELSE
-               inpfile%pob(jk,ji,1) = fbrmdi
-            ENDIF
-         END DO
-      END DO
-
-      !---------------------------------------------------------------------
-      !  Initialize flags since they are not in the CORIOLIS input files
-      !---------------------------------------------------------------------
-
-      inpfile%ioqcf(:,:)      = 0
-      inpfile%ipqcf(:,:)      = 0
-      inpfile%itqcf(:,:)      = 0
-      inpfile%idqcf(:,:,:)    = 0
-      inpfile%ivqcf(:,:,:)    = 0
-      inpfile%ivlqcf(:,:,:,:) = 0
-
-   END SUBROUTINE read_coriofile
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obsseaice_io.h90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obsseaice_io.h90	(revision 5658)
+++ 	(revision )
@@ -1,270 +1,0 @@
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE read_seaice( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_seaice **
-      !!
-      !! ** Purpose : Read from file the SEAICE observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! References : 
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      CHARACTER(LEN=12),PARAMETER :: cpname = 'read_seaice'
-      INTEGER :: i_file_id    ! netcdf IDS
-      INTEGER :: i_time_id
-      INTEGER :: i_ni_id
-      INTEGER :: i_data_id
-      INTEGER :: i_var_id
-      INTEGER :: i_data       ! Number of data per parameter in current file
-      INTEGER :: i_time       ! Number of reference times in file
-      INTEGER, DIMENSION(:), POINTER :: &
-         & i_reftime        ! Reference time in file in seconds since 1/1/1981.
-      INTEGER, DIMENSION(:,:), POINTER :: &
-         & i_dtime, &       ! Offset in seconds since reference time
-         & i_qc,    &       ! Quality control flag.
-         & i_type           ! Type of seaice measurement.            
-      REAL(wp), DIMENSION(:), POINTER :: &
-         & z_phi,   &       ! Latitudes
-         & z_lam            ! Longitudes
-      REAL(wp), DIMENSION(:,:), POINTER :: &
-         & z_seaice         ! Seaice data     
-      INTEGER, PARAMETER :: imaxdim = 2    ! Assumed maximum for no. dims. in file
-      INTEGER, DIMENSION(2) :: idims       ! Dimensions in file
-      INTEGER :: iilen          ! Length of netCDF attributes
-      INTEGER :: itype          ! Typeof netCDF attributes
-      REAL(KIND=wp) :: zsca      ! Scale factor
-      REAL(KIND=wp) :: zoff      ! Offset for data in netcdf file
-      REAL(KIND=wp) :: z_offset  ! Offset for time conversion
-      REAL(KIND=wp) :: zfill     ! Fill value in netcdf file
-      CHARACTER (len=33) ::creftime     ! Reference time of file
-      INTEGER :: i_refyear       ! Integer version of reference time
-      INTEGER :: i_refmonth
-      INTEGER :: i_refday
-      INTEGER :: i_refhour
-      INTEGER :: i_refmin
-      INTEGER :: i_refsec
-      INTEGER :: ichunk
-      INTEGER :: jtim
-      INTEGER :: jobs
-      INTEGER :: iobs
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-         &                i_file_id, chunksize=ichunk), cpname, __LINE__ )
-      
-      ! Get the netCDF dimensions
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'time', i_time_id ),  &
-         &       cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_time_id, &
-         &                              len = i_time ),  &
-         &      cpname, __LINE__ )
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'ni', i_ni_id ),  &
-         &       cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_ni_id, &
-         &                              len = i_data ),  &
-         &      cpname, __LINE__ )
-      
-      
-      ! Allocate NetCDF variables
-      
-      ALLOCATE( &
-         & i_reftime    ( i_time                 ), &
-         & i_dtime      ( i_data,i_time  ), &      
-         & i_qc         ( i_data,i_time  ), & 
-         & i_type       ( i_data,i_time  ), &     
-         & z_phi        ( i_data                 ), &   
-         & z_lam        ( i_data                 ), &  
-         & z_seaice        ( i_data,i_time  )  &
-         & )
-      
-      ! Get reference time of file which is in seconds since 1981/1/1 00:00. 
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'time', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_time
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_reftime),&
-         &       cpname, __LINE__ )
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "units") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "units",creftime), cpname,  __LINE__ )
-      ELSE
-         creftime = "seconds since 1981-01-01 00:00:00"
-      ENDIF
-      READ(creftime(15:18),*)i_refyear
-      READ(creftime(20:21),*)i_refmonth
-      READ(creftime(23:24),*)i_refday
-      READ(creftime(26:27),*)i_refhour
-      READ(creftime(29:30),*)i_refmin
-      READ(creftime(32:33),*)i_refsec
-      !Work out offset in days between reference time and 1/1/1950.
-      CALL greg2jul( i_refsec, i_refmin, i_refhour, i_refday, &
-         &           i_refmonth, i_refyear, z_offset)
-      
-      ! Get list of times for each ob in seconds relative to reference time
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'SeaIce_dtime', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_dtime),&
-         &       cpname, __LINE__ )
-      zsca = 1.0      
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "scale_factor",zsca), cpname,  __LINE__ )
-      ENDIF
-      zoff = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "add_offset") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "add_offset",zoff), cpname,  __LINE__ )
-      ENDIF
-      i_dtime(:,:) = NINT((zsca * FLOAT(i_dtime(:,:))) &
-         &                 + zoff)
-      
-      ! Get longitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'lon', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_lam),   &
-         &         cpname, __LINE__ )
-      
-      ! Get latitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'lat', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_phi),   &
-         &         cpname, __LINE__ )
-      
-      ! Get seaice data
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'sea_ice_concentration', &
-         &                         i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_seaice), &
-         &       cpname, __LINE__ )
-      zoff = 0.
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "scale_factor",zsca), cpname, __LINE__ )
-      ENDIF
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       "scale_factor",zsca), cpname, __LINE__ )
-      ENDIF
-      zfill = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "_FillValue") &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       "_FillValue",zfill), cpname, __LINE__ )
-      ENDIF
-      WHERE(z_seaice(:,:) /=  zfill)
-         z_seaice(:,:) = (zsca * z_seaice(:,:)) + zoff
-      ELSEWHERE
-         z_seaice(:,:) = fbrmdi
-      END WHERE
-      
-      ! Get QC flag
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'confidence_flag', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_qc),   &
-            &       cpname, __LINE__ )
-      
-      ! Get seaice obs type
-      
-      i_type(:,:)=1
-      
-      ! Close the file
-      
-      CALL chkerr( nf90_close( i_file_id ), cpname, __LINE__ )
-
-      ! Fill the obfbdata structure
-
-      ! Allocate obfbdata
-      
-      iobs = i_data * i_time
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 1, iobs, 1, 0, 0, ldgrid )
-      inpfile%cname(1) = 'SEAICE'
-
-      ! Fill the obfbdata structure from input data
-
-      inpfile%cdjuldref = "19500101000000"
-      iobs = 0
-      DO jtim = 1, i_time
-         DO jobs = 1, i_data
-            iobs = iobs + 1
-            ! Characters
-            WRITE(inpfile%cdwmo(iobs),'(A6,A2)') 'seaice','  '
-            WRITE(inpfile%cdtyp(iobs),'(I4)') i_type(jobs,jtim)
-            ! Real values
-            inpfile%plam(iobs)         = z_lam(jobs)
-            inpfile%pphi(iobs)         = z_phi(jobs)
-            inpfile%pob(1,iobs,1)      = z_seaice(jobs,jtim)
-            inpfile%ptim(iobs)         = &
-               & REAL(i_reftime(jtim))/(60.*60.*24.) + &
-               & z_offset + REAL(i_dtime(jobs,jtim))/(60.*60.*24.)
-            inpfile%pdep(1,iobs)       = 0.0
-            ! Integers
-            inpfile%kindex(iobs)       = iobs
-            IF ( z_seaice(jobs,jtim) == fbrmdi ) THEN
-               inpfile%ioqc(iobs)      = 4
-               inpfile%ivqc(iobs,1)    = 4 
-               inpfile%ivlqc(1,iobs,1) = 4
-            ELSE 
-               inpfile%ioqc(iobs)      = i_qc(jobs,jtim)
-               inpfile%ivqc(iobs,1)    = i_qc(jobs,jtim)
-               inpfile%ivlqc(1,iobs,1) = 1
-            ENDIF
-            inpfile%ipqc(iobs)         = 0 
-            inpfile%ipqcf(:,iobs)      = 0
-            inpfile%itqc(iobs)         = 0
-            inpfile%itqcf(:,iobs)      = 0
-            inpfile%ivqcf(:,iobs,1)    = 0
-            inpfile%ioqcf(:,iobs)      = 0
-            inpfile%idqc(1,iobs)       = 0
-            inpfile%idqcf(1,1,iobs)    = 0
-            inpfile%ivlqcf(:,1,iobs,1) = 0
-         END DO
-      END DO
-
-   END SUBROUTINE read_seaice
-
-
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obssla_io.h90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obssla_io.h90	(revision 5658)
+++ 	(revision )
@@ -1,378 +1,0 @@
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE read_avisofile( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_avisofile **
-      !!
-      !! ** Purpose : Read from file the AVISO SLA observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! References : http://www.aviso.oceanobs.com
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      CHARACTER(LEN=14),PARAMETER :: cpname = 'read_avisofile'
-      INTEGER :: i_file_id     ! netcdf IDS
-      INTEGER :: i_tracks_id
-      INTEGER :: i_cycles_id
-      INTEGER :: i_data_id
-      INTEGER :: i_var_id
-      INTEGER, PARAMETER :: imaxdim = 2    ! Assumed maximum for no. dims. in file
-      INTEGER, DIMENSION(2) :: idims       ! Dimensions in file
-      INTEGER :: iilen         ! Length of netCDF attributes
-      INTEGER :: itype         ! Typeof netCDF attributes
-      REAL(fbdp) :: zsca       ! Scale factor
-      REAL(fbdp) :: zfill      ! Fill value
-      CHARACTER(len=3) ::  cmission      ! Mission global attribute
-      INTEGER :: itracks       ! Maximum number of passes in file
-      INTEGER :: icycles       ! Maximum number of cycles for each pass
-      INTEGER :: idata         ! Number of data per parameter in current file
-      REAL(fbdp) :: zdeltat    ! Time gap getween two measurements in seconds
-      INTEGER, DIMENSION(:), POINTER :: & 
-         & iptracks,     &  ! List of passes contained in current file
-         & ipnbpoints,   &  ! Number of points per pass
-         & ipdataindexes    ! Index of data in theoretical profile
-      INTEGER, DIMENSION(:,:), POINTER :: & 
-         & ipcycles         ! List of cycles per pass
-      REAL(fbdp), DIMENSION(:), POINTER :: &
-         & zphi,   &        ! Latitudes
-         & zlam             ! Longitudes
-      REAL(fbdp), DIMENSION(:,:), POINTER :: &
-         & zbegindates      ! Date of point with index 0
-      REAL(fbdp) :: zbeginmiss    ! Missing data for dates
-      REAL(fbsp), DIMENSION(:,:), POINTER :: &
-         & zsla             ! SLA data
-      REAL(fbdp), DIMENSION(:), POINTER :: &
-         & zjuld            ! Julian date
-      LOGICAL, DIMENSION(:), POINTER :: &
-         & llskip           ! Skip observation
-      CHARACTER(len=14) :: cdjuldref    ! Julian data reference
-      INTEGER :: imission   ! Mission number converted from Mission global 
-                            ! netCDF atttribute.
-      CHARACTER(len=255) :: ctmp
-      INTEGER :: iobs
-      INTEGER :: jl
-      INTEGER :: jm
-      INTEGER :: jj
-      INTEGER :: ji
-      INTEGER :: jk
-      INTEGER :: jobs
-      INTEGER :: jcycle
-
-      ! Open the file
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, i_file_id ), &
-         &         cpname, __LINE__ )
-
-      ! Get the netCDF dimensions
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'Tracks', i_tracks_id ),  &
-         &         cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_tracks_id, &
-         &                                 len = itracks ),  &
-         &         cpname, __LINE__ )
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'Cycles', i_cycles_id ),  &
-         &         cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_cycles_id, &
-         &                                 len = icycles ),  &
-         &      cpname, __LINE__ )
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'Data', i_data_id ),  &
-         &         cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_data_id, &
-         &                                 len = idata ),  &
-         &         cpname, __LINE__ )
-
-      ! Allocate memory for input data
-
-      ALLOCATE( &
-         & iptracks     ( itracks          ), &  
-         & ipnbpoints   ( itracks          ), &  
-         & ipcycles     ( icycles, itracks ), &
-         & zphi         ( idata            ), &   
-         & zlam         ( idata            ), &  
-         & zbegindates  ( icycles, itracks ), &
-         & ipdataindexes( idata            ), & 
-         & zsla         ( icycles, idata   ), &
-         & zjuld        ( idata*icycles    ), &
-         & llskip       ( idata*icycles    )  &
-         & )
-
-      ! Get time gap getween two measurements in seconds
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'DeltaT', i_var_id ), & 
-         &         cpname, __LINE__ )
-      CALL chkdim( i_file_id, i_var_id, 0, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zdeltat), &
-         &         cpname, __LINE__ )
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     'scale_factor',zsca), cpname,  __LINE__)
-      ENDIF
-      zdeltat = zsca * zdeltat
-         
-      ! Get List of passes contained in current file      
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'Tracks', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = itracks
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, iptracks), &
-         &         cpname, __LINE__ )
-      
-      ! Get Number of points per pass
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'NbPoints', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = itracks
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, ipnbpoints),&
-         &         cpname, __LINE__ )
-      
-      ! Get list of cycles per pass
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'Cycles', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = icycles
-      idims(2) = itracks
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, ipcycles),   &
-         &         cpname, __LINE__ )
-
-      ! Get longitudes
-
-      CALL chkerr( nf90_inq_varid( i_file_id, 'Longitudes', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = idata
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zlam),   &
-         &         cpname, __LINE__ )
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
-         &                         == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     'scale_factor',zsca), cpname,  __LINE__)
-      ENDIF
-      zlam(:) = zsca * zlam(:)
-      
-      ! Get latitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'Latitudes', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = idata
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zphi),   &
-         &         cpname, __LINE__ )
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     'scale_factor',zsca), cpname,  __LINE__)
-      ENDIF
-      zphi(:) = zsca * zphi(:)
-      
-      ! Get date of point with index 0
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'BeginDates', i_var_id ), & 
-         &        cpname, __LINE__ )
-      idims(1) = icycles
-      idims(2) = itracks
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zbegindates), &
-         &         cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_attribute( i_file_id, i_var_id, &
-         &                                 'units', len = iilen,  &
-         &                                  xtype = itype), cpname, __LINE__ )
-      IF (( itype /= NF90_CHAR ) .OR. ( iilen > 255 )) THEN
-         CALL fatal_error('Error decoding BeginDates unit', __LINE__ )
-      ENDIF
-      CALL chkerr( nf90_get_att( i_file_id, i_var_id, 'units', &
-         &                       ctmp ), cpname, __LINE__ )
-      jl=1
-      DO jm = 1, LEN(TRIM(ctmp))
-         IF ((ctmp(jm:jm)>='0').AND.(ctmp(jm:jm)<='9')) THEN
-            cdjuldref(jl:jl) = ctmp(jm:jm)
-            jl=jl+1
-         ENDIF
-         IF (jl>14) EXIT
-      END DO
-      CALL chkerr( nf90_inquire_attribute( i_file_id, i_var_id, '_FillValue', &
-         &                                  xtype = itype), cpname, __LINE__ )
-      IF ( itype /= NF90_DOUBLE ) THEN
-         CALL fatal_error('Error decoding BeginDates missing data', __LINE__ )
-      ENDIF
-      CALL chkerr( nf90_get_att( i_file_id, i_var_id, '_FillValue', &
-         &                       zbeginmiss ), cpname, __LINE__ )
-
-      ! Get indices of data in theoretical profile
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'DataIndexes', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = idata
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, ipdataindexes),   &
-         &       cpname, __LINE__ )
-      
-      ! Get SLA data
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'SLA', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = icycles
-      idims(2) = idata
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zsla),   &
-         &         cpname, __LINE__ )
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
-         &                        == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       'scale_factor',zsca), cpname, __LINE__ )
-      ENDIF
-      zfill = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, '_FillValue') &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     '_FillValue',zfill), cpname,  __LINE__ )
-      ENDIF
-      WHERE(zsla(:,:) /=  zfill)
-         zsla(:,:) = zsca * zsla(:,:)
-      ELSEWHERE
-         zsla(:,:) = fbrmdi
-      END WHERE
-      
-      ! Get the global Mission netCDF attribute
-      
-      cmission='   '
-      CALL chkerr( nf90_inquire_attribute( i_file_id, nf90_global, &
-         &                                 'Mission', len = iilen,  &
-         &                                 xtype = itype), cpname, __LINE__ )
-      IF (( itype /= NF90_CHAR ) .OR. ( iilen > 3 )) THEN
-         CALL fatal_error('Error decoding Mission global attribute', __LINE__ )
-      ENDIF
-      CALL chkerr( nf90_get_att( i_file_id, nf90_global, 'Mission', &
-         &                       cmission ), cpname, __LINE__ )
-      
-      ! Convert it to an integer
-      imission = 0
-      DO jm = 1, imaxmissions
-         IF (cmission==cmissions(jm)) THEN
-            imission = jm
-            EXIT
-         ENDIF
-      END DO
-      
-      ! Close the file
-      
-      CALL chkerr( nf90_close( i_file_id ), cpname, __LINE__ )
-
-      ! Compute Julian dates for all observations
-      
-      jm = 0
-      jl = 0
-      DO jj = 1, itracks
-         DO ji = 1, ipnbpoints(jj)
-            jl = jl + 1
-            DO jk = 1, icycles
-               jm = jm + 1
-               IF (zbegindates(jk,jj)==zbeginmiss) THEN
-                  llskip(jm) = .TRUE.
-                  zjuld(jm)  = fbrmdi
-               ELSE
-                  llskip(jm) = .FALSE.
-                  zjuld(jm)  = zbegindates(jk,jj) + &
-                     &         (ipdataindexes(jl) * zdeltat / 86400._wp )
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      ! Get rid of missing data
-
-      jm = 0
-      DO jobs = 1, idata
-         DO jcycle = 1, icycles
-            jm = jm + 1
-            IF (zsla(jcycle,jobs) == fbrmdi) llskip(jm) = .TRUE.
-         END DO
-      END DO
-      
-      ! Allocate obfbdata
-
-      iobs = COUNT( .NOT.llskip(:) )
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 1, iobs, 1, 0, 0, ldgrid )
-      inpfile%cname(1) = 'SLA'
-
-      ! Fill the obfbdata structure from input data
-
-      inpfile%cdjuldref = cdjuldref
-      iobs = 0
-      jm = 0
-      DO jobs = 1, idata
-         DO jcycle = 1, icycles
-            jm = jm + 1
-            IF (llskip(jm)) CYCLE
-            iobs = iobs + 1
-            ! Characters
-            WRITE(inpfile%cdwmo(iobs),'(A3,A5)') cmissions(imission), '     '
-            WRITE(inpfile%cdtyp(iobs),'(I4)') imission
-            ! Real values
-            inpfile%plam(iobs)         = zlam(jobs)
-            inpfile%pphi(iobs)         = zphi(jobs)
-            inpfile%pob(1,iobs,1)      = zsla(jcycle,jobs)
-            inpfile%ptim(iobs)         = zjuld(jm)
-            inpfile%pdep(1,iobs)       = 0.0
-            ! Integers
-            inpfile%kindex(iobs)       = iobs
-            inpfile%ioqc(iobs)      = 1
-            inpfile%ivqc(iobs,1)    = 1
-            inpfile%ivlqc(1,iobs,1) = 1
-            inpfile%ipqc(iobs)         = 0 
-            inpfile%ipqcf(:,iobs)      = 0
-            inpfile%itqc(iobs)         = 0
-            inpfile%itqcf(:,iobs)      = 0
-            inpfile%ivqcf(:,iobs,1)    = 0
-            inpfile%ioqcf(:,iobs)      = 0
-            inpfile%idqc(1,iobs)       = 0
-            inpfile%idqcf(1,1,iobs)    = 0
-            inpfile%ivlqcf(:,1,iobs,1) = 0
-         END DO
-      END DO
-
-
-      ! Deallocate memory for input data
-
-      DEALLOCATE( &
-         & iptracks,      &
-         & ipnbpoints,    &
-         & ipcycles,      &
-         & zphi,          &
-         & zlam,          &  
-         & zbegindates,   &
-         & ipdataindexes, &
-         & zsla,          &
-         & zjuld,         &
-         & llskip         &
-         & )
-
-   END SUBROUTINE read_avisofile
-
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obssla_types.h90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obssla_types.h90	(revision 5658)
+++ 	(revision )
@@ -1,9 +1,0 @@
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   INTEGER, PARAMETER :: imaxmissions=8
-   CHARACTER(len=3) :: cmissions(0:imaxmissions) = &
-      & (/ 'XXX', 'E1 ', 'E2 ', 'TP ', 'TPM', 'G2 ', 'J1 ', 'EN ', 'J2 ' /)
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obssst_io.h90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obssst_io.h90	(revision 5658)
+++ 	(revision )
@@ -1,286 +1,0 @@
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE read_ghrsst( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_ghrsst **
-      !!
-      !! ** Purpose : Read from file the GHRSST observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! References : 
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      CHARACTER(LEN=12),PARAMETER :: cpname = 'read_ghrsst'
-      INTEGER :: i_file_id        ! netcdf IDS
-      INTEGER :: i_time_id
-      INTEGER :: i_ni_id
-      INTEGER :: i_data_id
-      INTEGER :: i_var_id
-      INTEGER :: i_data           ! Number of data per parameter in current file
-      INTEGER :: i_time           ! Number of reference times in file
-      INTEGER, DIMENSION(:), POINTER :: &
-         & i_reftime        ! Reference time in file in seconds since 1/1/1981.
-      INTEGER, DIMENSION(:,:), POINTER :: &
-         & i_dtime, &       ! Offset in seconds since reference time
-         & i_qc,    &       ! Quality control flag.
-         & i_type           ! Type of SST measurement.            
-      REAL(wp), DIMENSION(:), POINTER :: &
-         & z_phi,   &       ! Latitudes
-         & z_lam            ! Longitudes
-      REAL(wp), DIMENSION(:,:), POINTER :: &
-         & z_sst            ! SST data     
-      INTEGER, PARAMETER :: imaxdim = 2      ! Assumed maximum for no. dims. in file
-      INTEGER, DIMENSION(2) :: idims         ! Dimensions in file
-      INTEGER :: iilen            ! Length of netCDF attributes
-      INTEGER :: itype            ! Typeof netCDF attributes
-      REAL(KIND=wp) :: zsca           ! Scale factor
-      REAL(KIND=wp) :: zoff           ! Offset for data in netcdf file
-      REAL(KIND=wp) :: z_offset       ! Offset for time conversion
-      REAL(KIND=wp) :: zfill          ! Fill value in netcdf file
-      CHARACTER (len=33) :: creftime  ! Reference time of file
-      INTEGER :: i_refyear            ! Integer version of reference time
-      INTEGER :: i_refmonth
-      INTEGER :: i_refday
-      INTEGER :: i_refhour
-      INTEGER :: i_refmin
-      INTEGER :: i_refsec
-      INTEGER :: ichunk
-      INTEGER :: jtim
-      INTEGER :: jobs
-      INTEGER :: iobs
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-         &                i_file_id, chunksize=ichunk), cpname, __LINE__ )
-      
-      ! Get the netCDF dimensions
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'time', i_time_id ),  &
-         &       cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_time_id, &
-         &                              len = i_time ),  &
-         &      cpname, __LINE__ )
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'ni', i_ni_id ),  &
-         &       cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_ni_id, &
-         &                              len = i_data ),  &
-         &      cpname, __LINE__ )
-      
-      
-      ! Allocate NetCDF variables
-      
-      ALLOCATE( &
-         & i_reftime    ( i_time                 ), &
-         & i_dtime      ( i_data,i_time  ), &      
-         & i_qc         ( i_data,i_time  ), & 
-         & i_type       ( i_data,i_time  ), &     
-         & z_phi        ( i_data                 ), &   
-         & z_lam        ( i_data                 ), &  
-         & z_sst        ( i_data,i_time  )  &
-         & )
-      
-      ! Get reference time of file which is in seconds since 1981/1/1 00:00. 
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'time', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_time
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_reftime),&
-         &       cpname, __LINE__ )
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "units") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "units",creftime), cpname,  __LINE__ )
-      ELSE
-         creftime = "seconds since 1981-01-01 00:00:00"
-      ENDIF
-      READ(creftime(15:18),*)i_refyear
-      READ(creftime(20:21),*)i_refmonth
-      READ(creftime(23:24),*)i_refday
-      READ(creftime(26:27),*)i_refhour
-      READ(creftime(29:30),*)i_refmin
-      READ(creftime(32:33),*)i_refsec
-      !Work out offset in days between reference time and 1/1/1950.
-      CALL greg2jul( i_refsec, i_refmin, i_refhour, i_refday, &
-         &           i_refmonth, i_refyear, z_offset)
-      
-      ! Get list of times for each ob in seconds relative to reference time
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'sst_dtime', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_dtime),&
-         &       cpname, __LINE__ )
-      zsca = 1.0      
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "scale_factor",zsca), cpname,  __LINE__ )
-      ENDIF
-      zoff = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "add_offset") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "add_offset",zoff), cpname,  __LINE__ )
-      ENDIF
-      i_dtime(:,:) = NINT((zsca * FLOAT(i_dtime(:,:))) &
-         &                 + zoff)
-      
-      ! Get longitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'lon', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_lam),   &
-         &         cpname, __LINE__ )
-      
-      ! Get latitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'lat', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_phi),   &
-         &         cpname, __LINE__ )
-      
-      ! Get SST data
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'sea_surface_temperature', &
-         &                         i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_sst), &
-         &       cpname, __LINE__ )
-      zoff = 0.
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "scale_factor",zsca), cpname, __LINE__ )
-      ENDIF
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       "scale_factor",zsca), cpname, __LINE__ )
-      ENDIF
-      zfill = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "_FillValue") &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       "_FillValue",zfill), cpname, __LINE__ )
-      ENDIF
-      WHERE(z_sst(:,:) /=  zfill)
-         z_sst(:,:) = (zsca * z_sst(:,:)) + zoff
-      ELSEWHERE
-         z_sst(:,:) = fbrmdi
-      END WHERE
-      
-      ! Get QC flag
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'confidence_flag', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_qc),   &
-            &       cpname, __LINE__ )
-      
-      ! Get SST obs type
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'data_source', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_type),   &
-         &       cpname, __LINE__ )
-      
-      ! Close the file
-      
-      CALL chkerr( nf90_close( i_file_id ), cpname, __LINE__ )
-
-      ! Fill the obfbdata structure
-
-      ! Allocate obfbdata
-      
-      iobs = i_data * i_time
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 1, iobs, 1, 0, 0, ldgrid )
-      inpfile%cname(1) = 'SST'
-
-      ! Fill the obfbdata structure from input data
-
-      inpfile%cdjuldref = "19500101000000"
-      iobs = 0
-      DO jtim = 1, i_time
-         DO jobs = 1, i_data
-            iobs = iobs + 1
-            ! Characters
-            WRITE(inpfile%cdwmo(iobs),'(A6,A2)') 'ghrsst','  '
-            WRITE(inpfile%cdtyp(iobs),'(I4)') i_type(jobs,jtim)
-            ! Real values
-            inpfile%plam(iobs)         = z_lam(jobs)
-            inpfile%pphi(iobs)         = z_phi(jobs)
-            inpfile%pob(1,iobs,1)      = z_sst(jobs,jtim)
-            inpfile%ptim(iobs)         = &
-               & REAL(i_reftime(jtim))/(60.*60.*24.) + &
-               & z_offset + REAL(i_dtime(jobs,jtim))/(60.*60.*24.)
-            inpfile%pdep(1,iobs)       = 0.0
-            ! Integers
-            inpfile%kindex(iobs)       = iobs
-            IF ( z_sst(jobs,jtim) == fbrmdi ) THEN
-               inpfile%ioqc(iobs)      = 4
-               inpfile%ivqc(iobs,1)    = 4 
-               inpfile%ivlqc(1,iobs,1) = 4
-            ELSE 
-               inpfile%ioqc(iobs)      = i_qc(jobs,jtim)
-               inpfile%ivqc(iobs,1)    = i_qc(jobs,jtim)
-               inpfile%ivlqc(1,iobs,1) = 1
-            ENDIF
-            inpfile%ipqc(iobs)         = 0 
-            inpfile%ipqcf(:,iobs)      = 0
-            inpfile%itqc(iobs)         = 0
-            inpfile%itqcf(:,iobs)      = 0
-            inpfile%ivqcf(:,iobs,1)    = 0
-            inpfile%ioqcf(:,iobs)      = 0
-            inpfile%idqc(1,iobs)       = 0
-            inpfile%idqcf(1,1,iobs)    = 0
-            inpfile%ivlqcf(:,1,iobs,1) = 0
-         END DO
-      END DO
-
-      DEALLOCATE( &
-         & i_reftime, &
-         & i_dtime,   &
-         & i_qc,      &
-         & i_type,    &
-         & z_phi,     &
-         & z_lam,     &
-         & z_sst      &
-         & )
-
-   END SUBROUTINE read_ghrsst
-
-
Index: branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obsvel_io.h90
===================================================================
--- branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obsvel_io.h90	(revision 5658)
+++ 	(revision )
@@ -1,360 +1,0 @@
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE read_taondbc( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_enactfile **
-      !!
-      !! ** Purpose : Read from file the TAO data fro NDBC.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! ** Reference : http://tao.noaa.gov/tao/data_deliv/deliv_ndbc.shtml
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original version.
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      INTEGER :: iobs                ! Number of observations
-      INTEGER :: ilev                ! Number of levels
-      INTEGER :: ilat                ! Number of latitudes
-      INTEGER :: ilon                ! Number of longtudes
-      INTEGER :: itim                ! Number of obs. times
-      INTEGER :: i_file_id
-      INTEGER :: i_dimid_id
-      INTEGER :: i_phi_id
-      INTEGER :: i_lam_id
-      INTEGER :: i_depth_id
-      INTEGER :: i_var_id
-      INTEGER :: i_time_id
-      INTEGER :: i_time2_id
-      INTEGER :: i_qc_var_id
-      CHARACTER(LEN=40) :: cl_fld_lam
-      CHARACTER(LEN=40) :: cl_fld_phi
-      CHARACTER(LEN=40) :: cl_fld_depth
-      CHARACTER(LEN=40) :: cl_fld_var_u
-      CHARACTER(LEN=40) :: cl_fld_var_v
-      CHARACTER(LEN=40) :: cl_fld_var_qc_uv1
-      CHARACTER(LEN=40) :: cl_fld_var_qc_uv2
-      CHARACTER(LEN=40) :: cl_fld_time
-      CHARACTER(LEN=40) :: cl_fld_time2
-      INTEGER :: ja
-      INTEGER :: jo
-      INTEGER :: jk
-      INTEGER :: jt
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) :: &
-         & zv,     &
-         & zu,     &
-         & zuv1qc, &
-         & zuv2qc
-      REAL(wp), ALLOCATABLE, DIMENSION(:) :: &
-         & zdep, &
-         & zlat, &
-         & zlon, &
-         & zjuld
-      REAL(wp) :: zl
-      INTEGER, ALLOCATABLE, DIMENSION(:) :: &
-         & itime, &
-         & itime2
-      CHARACTER(LEN=50) :: cdjulref
-      CHARACTER(LEN=12), PARAMETER :: cl_name = 'read_taondbc'
-      CHARACTER(len=1) :: cns, cew
-
-      !-----------------------------------------------------------------------
-      ! Initialization
-      !-----------------------------------------------------------------------
-      cl_fld_lam                 = 'lon'
-      cl_fld_phi                 = 'lat'
-      cl_fld_depth               = 'depth'
-      cl_fld_time                = 'time'
-      cl_fld_time2               = 'time2'
-
-      !-----------------------------------------------------------------------
-      ! Open file
-      !-----------------------------------------------------------------------
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-            &      i_file_id ),           cl_name, __LINE__ )
-
-      !-----------------------------------------------------------------------
-      ! Read the heading of the file
-      !-----------------------------------------------------------------------
-      IF(ldwp) WRITE(kunit,*)
-      IF(ldwp) WRITE(kunit,*) ' read_taondbc :' 
-      IF(ldwp) WRITE(kunit,*) ' ~~~~~~~~~~~~'
-      
-      !---------------------------------------------------------------------
-      ! Read the number of observations and of levels to allocate array
-      !---------------------------------------------------------------------
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'time', i_dimid_id ),        &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = itim ),    &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'depth', i_dimid_id ),       &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = ilev ),    &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'lat', i_dimid_id ),           &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = ilat ),    &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'lon', i_dimid_id ),         &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = ilon ),    &
-         &         cl_name, __LINE__ ) 
-
-      iobs = itim * ilat * ilon
-      IF(ldwp)WRITE(kunit,*) '         No. of data records = ', iobs
-      IF(ldwp)WRITE(kunit,*) '         No. of levels       = ', ilev
-      IF(ldwp)WRITE(kunit,*) 
-
-      !---------------------------------------------------------------------
-      ! Allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 0, ldgrid )
-      inpfile%cname(1) = 'UVEL'
-      inpfile%cname(2) = 'VVEL'
-      inpfile%coblong(1) = 'Zonal current'
-      inpfile%coblong(2) = 'Meridional current'
-      inpfile%cobunit(1) = 'Meters per second'
-      inpfile%cobunit(2) = 'Meters per second'
-
-      ALLOCATE( &
-         & zu(ilon,ilat,ilev,itim),     &
-         & zv(ilon,ilat,ilev,itim),     &
-         & zdep(ilev),                  &
-         & zuv1qc(ilon,ilat,ilev,itim), &
-         & zuv2qc(ilon,ilat,ilev,itim), &
-         & itime(itim),                 &
-         & itime2(itim),                &
-         & zlat(ilat),                  &
-         & zlon(ilon),                  &
-         & zjuld(itim)                  &
-         & )
-
-      !---------------------------------------------------------------------
-      ! Read the time/position variables 
-      !---------------------------------------------------------------------
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_time, i_time_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_time_id, itime ),                                     &
-         &         cl_name, __LINE__ )
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_time2, i_time2_id ),                             &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_time2_id, itime2 ),                                   &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ),                             &
-            &         cl_name, __LINE__ )         
-      CALL chkerr( nf90_get_var  ( i_file_id, i_depth_id, zdep ),                                     &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_phi_id, zlat ),                                       &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_lam_id, zlon ),                                       &
-         &         cl_name, __LINE__ )
-      
-      !---------------------------------------------------------------------
-      ! Read the variables
-      !---------------------------------------------------------------------
-
-      ! ADCP format assumed
-      cl_fld_var_u = 'u_1205'
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_u, i_var_id ) /= nf90_noerr ) THEN
-         ! Try again with current meter format
-         cl_fld_var_u = 'U_320'
-         IF ( nf90_inq_varid( i_file_id, cl_fld_var_u, i_var_id ) /= nf90_noerr ) THEN
-            CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
-         ENDIF
-      ENDIF
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zu ),                                         &
-         &         cl_name, __LINE__ )
-      
-      ! ADCP format assumed
-      cl_fld_var_v = 'v_1206'
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_v, i_var_id ) /= nf90_noerr ) THEN
-         ! Try again with current meter format
-         cl_fld_var_v = 'V_321'
-         IF ( nf90_inq_varid( i_file_id, cl_fld_var_v, i_var_id ) /= nf90_noerr ) THEN
-            CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
-         ENDIF
-      ENDIF
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zv ),                                         &
-         &         cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Read the QC attributes
-      !---------------------------------------------------------------------
-      
-      ! ADCP format assumed
-      cl_fld_var_qc_uv1 = 'QU_5205'
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv1, i_qc_var_id ) /= nf90_noerr ) THEN
-         ! Try again with current meter format
-         cl_fld_var_qc_uv1 = 'QCS_5300'
-         IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv1, i_qc_var_id ) /= nf90_noerr ) THEN
-            ! Try again with high freq. current meter format
-            cl_fld_var_qc_uv1 = 'QCU_5320'
-            IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv1, i_qc_var_id ) /= nf90_noerr ) THEN
-               CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
-            ENDIF
-         ENDIF
-      ENDIF
-      CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, zuv1qc),                                   &
-         &         cl_name, __LINE__ )
-
-      ! ADCP format assumed
-      cl_fld_var_qc_uv2 = 'QV_5206'
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv2, i_qc_var_id ) /= nf90_noerr ) THEN
-         ! Try again with current meter format
-         cl_fld_var_qc_uv2 = 'QCD_5310'
-         IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv2, i_qc_var_id ) /= nf90_noerr ) THEN
-            ! Try again with high freq. current meter format
-            cl_fld_var_qc_uv2 = 'QCV_5321'
-            IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv2, i_qc_var_id ) /= nf90_noerr ) THEN
-               CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
-            ENDIF
-         ENDIF
-      ENDIF
-      CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, zuv2qc),                                   &
-         &         cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Close file
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_close( i_file_id ),           cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Convert to to 19500101 based Julian date
-      !---------------------------------------------------------------------
-      DO jt = 1, itim
-         zjuld(jt) = REAL(itime(jt),wp) + REAL(itime2(jt),wp)/86400000.0_wp &
-            &           - 2433283.0_wp
-      END DO
-      inpfile%cdjuldref = '19500101000000'
-
-      !---------------------------------------------------------------------
-      ! Copy info to obfbdata structure
-      !---------------------------------------------------------------------
-
-      iobs = 0
-      DO jt = 1, itim
-         DO ja = 1, ilat
-            DO jo = 1, ilon
-               iobs = iobs + 1
-               zl = zlon(jo)
-               IF ( zl > 180.0_wp ) zl = zl - 360.0_wp
-               IF ( zl < 0 ) THEN
-                  cew = 'w'
-               ELSE
-                  cew = 'e'
-               ENDIF
-               IF ( zlat(jo) < 0 ) THEN
-                  cns = 's'
-               ELSE
-                  cns = 'n'
-               ENDIF
-               WRITE(inpfile%cdwmo(iobs),'(A1,I2.2,A1,I3.3)') &
-                  & cns, ABS(NINT(zlat(ja))), cew, ABS(NINT(zl))
-               DO jk = 1, ilev
-                  inpfile%pob(jk,iobs,1)     = zu(jo,ja,jk,jt)
-                  inpfile%pob(jk,iobs,2)     = zv(jo,ja,jk,jt)
-                  inpfile%pdep(jk,iobs)      = zdep(jk)
-                  inpfile%ivlqc(jk,iobs,1:2) = INT( MAX( zuv1qc(jo,ja,jk,jt), zuv2qc(jo,ja,jk,jt) ) )
-               END DO
-               inpfile%plam(iobs) = zlon(jo)
-               inpfile%pphi(iobs) = zlat(ja)
-               inpfile%ptim(iobs) = zjuld(jt)
-            END DO
-         END DO
-      END DO
-
-      ! No position, time, depth and variable QC in input files
-      DO jo = 1, iobs
-         inpfile%ipqc(jo) = 1
-         inpfile%itqc(jo) = 1
-         inpfile%ivqc(jo,1:2) = 1
-         DO jk = 1, ilev
-            inpfile%idqc(jk,jo) = 1
-         END DO
-      END DO
-
-      !---------------------------------------------------------------------
-      ! Set the platform information
-      !---------------------------------------------------------------------
-      inpfile%cdtyp(:)=' 820'
-
-      !---------------------------------------------------------------------
-      ! Set QC flags for missing data and rescale to m/s
-      !---------------------------------------------------------------------
-
-      DO jo = 1, iobs
-         DO jk = 1, ilev
-            IF ( ( ABS(inpfile%pob(jk,jo,1)) > 10000.0_wp ) .OR. &
-               & ( ABS(inpfile%pob(jk,jo,2)) > 10000.0_wp ) ) THEN
-               inpfile%ivlqc(jk,jo,:) = 4
-               inpfile%pob(jk,jo,1) = fbrmdi
-               inpfile%pob(jk,jo,2) = fbrmdi
-            ELSE
-               inpfile%pob(jk,jo,1) = 0.01 * inpfile%pob(jk,jo,1)
-               inpfile%pob(jk,jo,2) = 0.01 * inpfile%pob(jk,jo,2)
-            ENDIF
-         END DO
-      END DO
-
-      !---------------------------------------------------------------------
-      ! Set file indexes
-      !---------------------------------------------------------------------
-
-      DO jo = 1, inpfile%nobs
-         inpfile%kindex(jo) = jo
-      END DO
-
-      !---------------------------------------------------------------------
-      ! Initialize flags since they are not in the TAO input files
-      !---------------------------------------------------------------------
-
-      inpfile%ioqcf(:,:)      = 0
-      inpfile%ipqcf(:,:)      = 0
-      inpfile%itqcf(:,:)      = 0
-      inpfile%idqcf(:,:,:)    = 0
-      inpfile%ivqcf(:,:,:)    = 0
-      inpfile%ivlqcf(:,:,:,:) = 0
-
-      !---------------------------------------------------------------------
-      ! Deallocate data
-      !---------------------------------------------------------------------
-      DEALLOCATE( &
-         & zu,     &
-         & zv,     &
-         & zdep,   &
-         & zuv1qc, &
-         & zuv2qc, &
-         & itime,  &
-         & itime2, &
-         & zlat,   &
-         & zlon,   &
-         & zjuld   &
-         & )
-
-   END SUBROUTINE read_taondbc
