Index: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/ddatetoymdhms.h90
===================================================================
--- branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/ddatetoymdhms.h90	(revision 4850)
+++ branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/ddatetoymdhms.h90	(revision 5034)
@@ -21,5 +21,5 @@
 
       !! * Arguments
-      REAL(dp), INTENT(IN) :: ddate
+      real(wp), INTENT(IN) :: ddate
       INTEGER, INTENT(OUT) :: kyea
       INTEGER, INTENT(OUT) :: kmon
Index: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90
===================================================================
--- branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 4850)
+++ branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 5034)
@@ -208,5 +208,4 @@
       !-----------------------------------------------------------------------
 
-      !Initalise all values in namelist arrays
       enactfiles(:) = ''
       coriofiles(:) = ''
@@ -232,6 +231,6 @@
       ln_profb_enatim(:) = .TRUE.
       ln_velfb_av(:) = .FALSE.
-      ln_ignmis = .FALSE.     
-
+      ln_ignmis = .FALSE.
+      
       CALL ini_date( dobsini )
       CALL fin_date( dobsend )
@@ -484,14 +483,10 @@
       CALL obs_grid_setup( )
       IF ( ( n1dint < 0 ).OR.( n1dint > 1 ) ) THEN
-         IF(lwp) WRITE(numout,cform_err)
-         IF(lwp) WRITE(numout,*) ' Choice of vertical (1D) interpolation method', &
-            &                    ' is not available'
-         nstop = nstop + 1
+         CALL ctl_stop(' Choice of vertical (1D) interpolation method', &
+            &                    ' is not available')
       ENDIF
       IF ( ( n2dint < 0 ).OR.( n2dint > 4 ) ) THEN
-         IF(lwp) WRITE(numout,cform_err)
-         IF(lwp) WRITE(numout,*) ' Choice of horizontal (2D) interpolation method', &
-            &                    ' is not available'
-         nstop = nstop + 1
+         CALL ctl_stop(' Choice of horizontal (2D) interpolation method', &
+            &                    ' is not available')
       ENDIF
 
Index: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/jul2greg.h90
===================================================================
--- branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/jul2greg.h90	(revision 4850)
+++ branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/jul2greg.h90	(revision 5034)
@@ -16,4 +16,5 @@
       !!      ! 06-05  (A. Vidard) Reformatted and refdate      
       !!      ! 06-10  (A. Weaver) Cleanup
+      !!      ! 2014-09 (D. Lea) Change to use FLOOR to deal with negative prelday
       !!-----------------------------------------------------------------------
 
@@ -82,5 +83,5 @@
 
       zday = prelday
-      ksec = NINT( 86400. * MOD( zday, 1. ) )
+      ksec = FLOOR( 86400. * MOD( zday, 1. ) )
 
       IF ( ksec < 0. ) ksec = 86400. + ksec
Index: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_grid.F90
===================================================================
--- branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_grid.F90	(revision 4850)
+++ branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_grid.F90	(revision 5034)
@@ -412,5 +412,7 @@
          ENDIF
 
-         IF (MAXVAL(ixpos(ipx1:ipx,ipy1:ipy)) == -1) CYCLE! cycle if no lookup points found
+         IF (.NOT. llfourflag) THEN
+            IF (MAXVAL(ixpos(ipx1:ipx,ipy1:ipy)) == -1) CYCLE! cycle if no lookup points found
+         ENDIF
          
          jimin = 0
@@ -996,5 +998,5 @@
                         df = ABS( iypos(ji+1,jj) - iypos(ji,jj) )
                         tmpy1 = df
-                        IF ( df < limxdiff ) numy1 = numy1 + 1
+                        IF ( df < limydiff ) numy1 = numy1 + 1
                         IF ( df < histsize ) histy1(df+1) = histy1(df+1) + 1
                      ENDIF
@@ -1002,5 +1004,5 @@
                         df = ABS( iypos(ji,jj+1) - iypos(ji,jj) )
                         tmpy2 = df
-                        IF ( df < limxdiff ) numy2 = numy2+1
+                        IF ( df < limydiff ) numy2 = numy2+1
                         IF ( df < histsize ) histy2(df+1) = histy2(df+1)+1
                      ENDIF
Index: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90
===================================================================
--- branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90	(revision 4850)
+++ branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90	(revision 5034)
@@ -128,10 +128,10 @@
          & zphi, &
          & zlam
-      REAL(dp), DIMENSION(:), ALLOCATABLE :: &
+      real(wp), DIMENSION(:), ALLOCATABLE :: &
          & zdat
       LOGICAL :: llvalprof
       TYPE(obfbdata), POINTER, DIMENSION(:) :: &
          & inpfiles
-      REAL(dp), DIMENSION(knumfiles) :: &
+      real(wp), DIMENSION(knumfiles) :: &
          & djulini, &
          & djulend
@@ -143,4 +143,6 @@
       INTEGER :: is3dt
       INTEGER :: ip3dt
+      INTEGER :: ios
+      INTEGER :: ioserrcount
       INTEGER, DIMENSION(kvars) :: &
          & iv3dt
@@ -280,4 +282,5 @@
                &           krefdate = irefdate(jj) )
 
+            ioserrcount=0
             IF ( ldavtimset ) THEN
                DO ji = 1, inpfiles(jj)%nobs
@@ -287,5 +290,8 @@
                   !  to be the  end of the day
                   !
-                  READ( inpfiles(jj)%cdtyp(ji), '(I4)' ) itype
+                  READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 900 ) itype
+900               IF ( ios /= 0 ) THEN
+                     itype = 0         ! Set type to zero if there is a problem in the string conversion
+                  ENDIF
                   IF ( ANY (idailyavtypes == itype ) ) THEN
                      inpfiles(jj)%ptim(ji) = &
@@ -468,5 +474,5 @@
       itypsmpp(:) = 0
       
-      
+      ioserrcount = 0      
       DO jk = 1, iproftot
          
@@ -552,5 +558,11 @@
                
                ! Instrument type
-               READ( inpfiles(jj)%cdtyp(ji), '(I4)' ) itype
+               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
                
Index: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_seaice.F90
===================================================================
--- branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_seaice.F90	(revision 4850)
+++ branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_seaice.F90	(revision 5034)
@@ -110,14 +110,16 @@
          & zphi, &
          & zlam
-      REAL(dp), DIMENSION(:), ALLOCATABLE :: &
+      real(wp), DIMENSION(:), ALLOCATABLE :: &
          & zdat
       LOGICAL :: llvalprof
       TYPE(obfbdata), POINTER, DIMENSION(:) :: &
          & inpfiles
-      REAL(dp), DIMENSION(knumfiles) :: &
+      real(wp), DIMENSION(knumfiles) :: &
          & djulini, &
          & djulend
       INTEGER :: iobs
       INTEGER :: iobstot
+      INTEGER :: ios
+      INTEGER :: ioserrcount
       CHARACTER(len=8) :: cl_refdate
    
@@ -335,5 +337,7 @@
       ityp   (:) = 0
       itypmpp(:) = 0
-      
+
+      ioserrcount=0      
+
       DO jk = 1, iobstot
          
@@ -382,5 +386,10 @@
                
                ! Instrument type
-               READ( inpfiles(jj)%cdtyp(ji), '(I4)' ) itype
+               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
Index: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sla.F90
===================================================================
--- branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sla.F90	(revision 4850)
+++ branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sla.F90	(revision 5034)
@@ -111,5 +111,5 @@
          & zphi, &
          & zlam
-      REAL(dp), DIMENSION(:), ALLOCATABLE :: &
+      real(wp), DIMENSION(:), ALLOCATABLE :: &
          & zdat
       LOGICAL :: llvalprof
@@ -117,5 +117,5 @@
       TYPE(obfbdata), POINTER, DIMENSION(:) :: &
          & inpfiles
-      REAL(dp), DIMENSION(knumfiles) :: &
+      real(wp), DIMENSION(knumfiles) :: &
          & djulini, &
          & djulend
@@ -125,4 +125,6 @@
       INTEGER :: iobs
       INTEGER :: iobstot
+      INTEGER :: ios
+      INTEGER :: ioserrcount
       CHARACTER(len=8) :: cl_refdate
    
@@ -391,6 +393,5 @@
          &               iindx   )
       
-      CALL obs_surf_alloc( sladata, iobs, kvars, kextr, &
-         &                 jpi, jpj, kstp )
+      CALL obs_surf_alloc( sladata, iobs, kvars, kextr, kstp, jpi, jpj )
       
       ! * Read obs/positions, QC, all variable and assign to sladata
@@ -400,4 +401,6 @@
       ityp   (:) = 0
       itypmpp(:) = 0
+
+      ioserrcount = 0
       
       DO jk = 1, iobstot
@@ -451,5 +454,10 @@
                
                ! Instrument type
-               READ( inpfiles(jj)%cdtyp(ji), '(I4)' ) itype
+               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
Index: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sst.F90
===================================================================
--- branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sst.F90	(revision 4850)
+++ branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_sst.F90	(revision 5034)
@@ -110,14 +110,16 @@
          & zphi, &
          & zlam
-      REAL(dp), DIMENSION(:), ALLOCATABLE :: &
+      real(wp), DIMENSION(:), ALLOCATABLE :: &
          & zdat
       LOGICAL :: llvalprof
       TYPE(obfbdata), POINTER, DIMENSION(:) :: &
          & inpfiles
-      REAL(dp), DIMENSION(knumfiles) :: &
+      real(wp), DIMENSION(knumfiles) :: &
          & djulini, &
          & djulend
       INTEGER :: iobs
       INTEGER :: iobstot
+      INTEGER :: ios
+      INTEGER :: ioserrcount
       CHARACTER(len=8) :: cl_refdate
    
@@ -335,4 +337,6 @@
       itypmpp(:) = 0
       
+      ioserrcount = 0
+      
       DO jk = 1, iobstot
          
@@ -381,5 +385,10 @@
                
                ! Instrument type
-               READ( inpfiles(jj)%cdtyp(ji), '(I4)' ) itype
+               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
Index: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_vel.F90
===================================================================
--- branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_vel.F90	(revision 4850)
+++ branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_vel.F90	(revision 5034)
@@ -118,5 +118,5 @@
          & zphi, &
          & zlam
-      REAL(dp), DIMENSION(:), ALLOCATABLE :: &
+      real(wp), DIMENSION(:), ALLOCATABLE :: &
          & zdat
       LOGICAL :: &
@@ -124,5 +124,5 @@
       TYPE(obfbdata), POINTER, DIMENSION(:) :: &
          & inpfiles
-      REAL(dp), DIMENSION(knumfiles) :: &
+      real(wp), DIMENSION(knumfiles) :: &
          & djulini, &
          & djulend
@@ -130,4 +130,6 @@
       INTEGER :: iproftot
       INTEGER :: iuv3dt
+      INTEGER :: ios
+      INTEGER :: ioserrcount
       INTEGER, DIMENSION(kvars) :: iv3dt
       CHARACTER(len=8) :: cl_refdate
@@ -459,5 +461,10 @@
                
                ! Instrument type
-               READ( inpfiles(jj)%cdtyp(ji), '(I4)' ) itype
+               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
                
Index: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90
===================================================================
--- branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90	(revision 4850)
+++ branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90	(revision 5034)
@@ -6,9 +6,10 @@
 
    !!----------------------------------------------------------------------
-   !!   cdf_wri_p3d   : Write profile observation diagnostics in NetCDF format
+   !!   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
-   !!   cdf_wri_vel   : Write velocity observation diagnostics in NetCDF format
+   !!   obs_wri_vel   : Write velocity observation diagnostics in NetCDF format
+   !!   obs_wri_stats : Print basic statistics on the data being written out
    !!----------------------------------------------------------------------
 
@@ -31,4 +32,6 @@
    USE obs_sla_types
    USE obs_rot_vel          ! Rotation of velocities
+   USE obs_mpp              ! MPP support routines for observation diagnostics
+   USE lib_mpp		    ! MPP routines
 
    IMPLICIT NONE
@@ -256,5 +259,8 @@
       ! Write the obfbdata structure
       CALL write_obfbdata( cfname, fbdata )
-      
+
+      ! Output some basic statistics
+      CALL obs_wri_stats( fbdata )
+
       CALL dealloc_obfbdata( fbdata )
      
@@ -414,4 +420,7 @@
       CALL write_obfbdata( cfname, fbdata )
 
+      ! Output some basic statistics
+      CALL obs_wri_stats( fbdata )
+
       CALL dealloc_obfbdata( fbdata )
 
@@ -565,4 +574,7 @@
       CALL write_obfbdata( cfname, fbdata )
 
+      ! Output some basic statistics
+      CALL obs_wri_stats( fbdata )
+
       CALL dealloc_obfbdata( fbdata )
 
@@ -715,4 +727,7 @@
       CALL write_obfbdata( cfname, fbdata )
 
+      ! Output some basic statistics
+      CALL obs_wri_stats( fbdata )
+
       CALL dealloc_obfbdata( fbdata )
 
@@ -722,5 +737,5 @@
       !!-----------------------------------------------------------------------
       !!
-      !!                     *** ROUTINE obs_wri_p3d  ***
+      !!                     *** ROUTINE obs_wri_vel  ***
       !!
       !! ** Purpose : Write current (profile) observation 
@@ -903,4 +918,7 @@
       CALL write_obfbdata( cfname, fbdata )
       
+      ! Output some basic statistics
+      CALL obs_wri_stats( fbdata )
+
       CALL dealloc_obfbdata( fbdata )
      
@@ -912,3 +930,73 @@
    END SUBROUTINE obs_wri_vel
 
+   SUBROUTINE obs_wri_stats( fbdata )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                     *** ROUTINE obs_wri_stats  ***
+      !!
+      !! ** Purpose : Output some basic statistics of the data being written out
+      !!
+      !! ** Method  :
+      !! 
+      !! ** Action  :
+      !!
+      !!      ! 2014-08  (D. Lea) Initial version 
+      !!-----------------------------------------------------------------------
+
+      !! * Arguments
+      TYPE(obfbdata) :: fbdata
+
+      !! * Local declarations
+      INTEGER :: jvar
+      INTEGER :: jo
+      INTEGER :: jk
+
+!      INTEGER :: nlev
+!      INTEGER :: nlevmpp
+!      INTEGER :: nobsmpp
+      INTEGER :: numgoodobs
+      INTEGER :: numgoodobsmpp
+      REAL(wp) :: zsumx
+      REAL(wp) :: zsumx2
+      REAL(wp) :: zomb
+
+      IF (lwp) THEN
+         WRITE(numout,*) ''
+         WRITE(numout,*) 'obs_wri_stats :'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~' 
+      ENDIF
+
+      DO jvar = 1, fbdata%nvar
+         zsumx=0.0_wp
+         zsumx2=0.0_wp
+         numgoodobs=0
+         DO jo = 1, fbdata%nobs
+            DO jk = 1, fbdata%nlev
+               IF ( ( fbdata%pob(jk,jo,jvar) < 9999.0 ) .AND. &
+                  & ( fbdata%pdep(jk,jo) < 9999.0 ) .AND. &
+                  & ( fbdata%padd(jk,jo,1,jvar) < 9999.0 ) ) THEN
+	    
+	          zomb=fbdata%pob(jk, jo, jvar)-fbdata%padd(jk, jo, 1, jvar)
+                  zsumx=zsumx+zomb
+                  zsumx2=zsumx2+zomb**2
+                  numgoodobs=numgoodobs+1
+	       ENDIF
+            ENDDO
+         ENDDO
+
+         CALL obs_mpp_sum_integer( numgoodobs, numgoodobsmpp )
+         CALL mpp_sum(zsumx)
+         CALL mpp_sum(zsumx2)
+
+         IF (lwp) THEN
+	    WRITE(numout,*) 'Type: ',fbdata%cname(jvar),'  Total number of good observations: ',numgoodobsmpp 
+	    WRITE(numout,*) 'Overall mean obs minus model of the good observations: ',zsumx/numgoodobsmpp
+            WRITE(numout,*) 'Overall RMS obs minus model of the good observations: ',sqrt( zsumx2/numgoodobsmpp )
+	    WRITE(numout,*) ''
+         ENDIF
+ 
+      ENDDO
+
+   END SUBROUTINE obs_wri_stats
+
 END MODULE obs_write
