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 4810)
+++ 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
