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 5659)
+++ branches/2015/dev_r5072_UKMO2_OBS_simplification/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90	(revision 5682)
@@ -55,5 +55,5 @@
 CONTAINS
 
-   SUBROUTINE obs_wri_prof( cobstype, profdata, padd, pext )
+   SUBROUTINE obs_wri_prof( profdata, k2dint, padd, pext )
       !!-----------------------------------------------------------------------
       !!
@@ -76,15 +76,14 @@
       !!-----------------------------------------------------------------------
 
-      !! * Modules used
-
       !! * Arguments
-      CHARACTER(LEN=*), INTENT(IN) :: cobstype        ! 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
+      CHARACTER(LEN=40) :: clfname
+      CHARACTER(LEN=6) :: clfiletype
       INTEGER :: ilevel
       INTEGER :: jvar
@@ -94,20 +93,23 @@
       INTEGER :: ja
       INTEGER :: je
+      INTEGER :: iadd
+      INTEGER :: iext
       REAL(wp) :: zpres
-      INTEGER :: nadd
-      INTEGER :: next
+      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
+         & zu, &
+         & zv
 
       IF ( PRESENT( padd ) ) THEN
-         nadd = padd%inum
+         iadd = padd%inum
       ELSE
-         nadd = 0
+         iadd = 0
       ENDIF
 
       IF ( PRESENT( pext ) ) THEN
-         next = pext%inum
+         iext = pext%inum
       ELSE
-         next = 0
-      ENDIF
-      
+         iext = 0
+      ENDIF
+
       CALL init_obfbdata( fbdata )
 
@@ -118,11 +120,12 @@
       END DO
 
-      SELECT CASE ( TRIM(cobstype) )
-      CASE('prof')
-
+      SELECT CASE ( TRIM(profdata%cvars(1)) )
+      CASE('POTM')
+
+         clfiletype='profb'
          CALL alloc_obfbdata( fbdata, 2, profdata%nprof, ilevel, &
-            &                 1 + nadd, 1 + next, .TRUE. )
-         fbdata%cname(1)      = 'POTM'
-         fbdata%cname(2)      = 'PSAL'
+            &                 1 + iadd, 1 + iext, .TRUE. )
+         fbdata%cname(1)      = profdata%cvars(1)
+         fbdata%cname(2)      = profdata%cvars(2)
          fbdata%coblong(1)    = 'Potential temperature'
          fbdata%coblong(2)    = 'Practical salinity'
@@ -137,10 +140,10 @@
          fbdata%caddunit(1,2) = 'PSU'
          fbdata%cgrid(:)      = 'T'
-         DO je = 1, next
+         DO je = 1, iext
             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
+         DO ja = 1, iadd
             fbdata%caddname(1+ja) = padd%cdname(ja)
             DO jvar = 1, 2
@@ -149,15 +152,16 @@
             END DO
          END DO
-      
-      CASE('vel')
-      
+
+      CASE('UVEL')
+
+         clfiletype='velfb'
          CALL alloc_obfbdata( fbdata, 2, profdata%nprof, ilevel, 2, 0, .TRUE. )
-         fbdata%cname(1)      = 'UVEL'
-         fbdata%cname(2)      = 'VVEL'
+         fbdata%cname(1)      = profdata%cvars(1)
+         fbdata%cname(2)      = profdata%cvars(2)
          fbdata%coblong(1)    = 'Zonal velocity'
          fbdata%coblong(2)    = 'Meridional velocity'
          fbdata%cobunit(1)    = 'm/s'
          fbdata%cobunit(2)    = 'm/s'
-         DO je = 1, next
+         DO je = 1, iext
             fbdata%cextname(je) = pext%cdname(je)
             fbdata%cextlong(je) = pext%cdlong(je,1)
@@ -175,5 +179,5 @@
          fbdata%cgrid(1)      = 'U' 
          fbdata%cgrid(2)      = 'V'
-         DO ja = 1, nadd
+         DO ja = 1, iadd
             fbdata%caddname(2+ja) = padd%cdname(ja)
             fbdata%caddlong(2+ja,1) = padd%cdlong(ja,1)
@@ -187,8 +191,8 @@
 
       END SELECT
-         
+
       fbdata%caddname(1)   = 'Hx'
-         
-      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cobstype), nproc
+
+      WRITE(clfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(clfiletype), nproc
 
       IF(lwp) THEN
@@ -196,5 +200,5 @@
          WRITE(numout,*)'obs_wri_prof :'
          WRITE(numout,*)'~~~~~~~~~~~~~'
-         WRITE(numout,*)'Writing profile feedback file : ',TRIM(cfname)
+         WRITE(numout,*)'Writing '//TRIM(clfiletype)//' feedback file : ',TRIM(clfname)
       ENDIF
 
@@ -242,7 +246,7 @@
             DO jk = profdata%npvsta(jo,jvar), profdata%npvend(jo,jvar)
                ik = profdata%var(jvar)%nvlidx(jk)
-               IF ( TRIM(cobstype) == 'prof' ) THEN
+               IF ( TRIM(profdata%cvars(1)) == 'POTM' ) THEN
                   fbdata%padd(ik,jo,1,jvar) = profdata%var(jvar)%vmod(jk)
-               ELSE IF ( TRIM(cobstype) == 'vel' ) THEN
+               ELSE IF ( TRIM(profdata%cvars(1)) == 'UVEL' ) THEN
                   IF ( jvar == 1 ) THEN
                      fbdata%padd(ik,jo,1,jvar) = zu(jk)
@@ -265,9 +269,9 @@
                ENDIF
                fbdata%iobsk(ik,jo,jvar)  = profdata%var(jvar)%mvk(jk)
-               DO ja = 1, nadd
+               DO ja = 1, iadd
                   fbdata%padd(ik,jo,1+ja,jvar) = &
                      & profdata%var(jvar)%vext(jk,padd%ipoint(ja))
                END DO
-               DO je = 1, next
+               DO je = 1, iext
                   fbdata%pext(ik,jo,1+je) = &
                      & profdata%var(jvar)%vext(jk,pext%ipoint(je))
@@ -280,5 +284,5 @@
       END DO
 
-      IF ( TRIM(cobstype) == 'prof' ) THEN
+      IF ( TRIM(profdata%cvars(1)) == 'POTM' ) THEN
          ! Convert insitu temperature to potential temperature using the model
          ! salinity if no potential temperature
@@ -301,7 +305,7 @@
          END DO
       ENDIF
-      
+
       ! Write the obfbdata structure
-      CALL write_obfbdata( cfname, fbdata )
+      CALL write_obfbdata( clfname, fbdata )
 
       ! Output some basic statistics
@@ -309,8 +313,8 @@
 
       CALL dealloc_obfbdata( fbdata )
-     
+
    END SUBROUTINE obs_wri_prof
 
-   SUBROUTINE obs_wri_surf( cobstype, surfdata, padd, pext )
+   SUBROUTINE obs_wri_surf( surfdata, padd, pext )
       !!-----------------------------------------------------------------------
       !!
@@ -332,5 +336,4 @@
 
       !! * Arguments
-      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
@@ -339,22 +342,23 @@
       !! * Local declarations
       TYPE(obfbdata) :: fbdata
-      CHARACTER(LEN=40) :: cfname         ! netCDF filename
+      CHARACTER(LEN=40) :: clfname         ! netCDF filename
+      CHARACTER(LEN=6)  :: clfiletype
       CHARACTER(LEN=12), PARAMETER :: cpname = 'obs_wri_surf'
       INTEGER :: jo
       INTEGER :: ja
       INTEGER :: je
-      INTEGER :: nadd
-      INTEGER :: next
+      INTEGER :: iadd
+      INTEGER :: iext
 
       IF ( PRESENT( padd ) ) THEN
-         nadd = padd%inum
+         iadd = padd%inum
       ELSE
-         nadd = 0
+         iadd = 0
       ENDIF
 
       IF ( PRESENT( pext ) ) THEN
-         next = pext%inum
+         iext = pext%inum
       ELSE
-         next = 0
+         iext = 0
       ENDIF
 
@@ -362,10 +366,11 @@
 
       CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-         &                 2 + nadd, 1 + next, .TRUE. )
-
-      SELECT CASE ( TRIM(cobstype) )
-      CASE('sla')
-
-         fbdata%cname(1)      = 'SLA'
+         &                 2 + iadd, 1 + iext, .TRUE. )
+
+      SELECT CASE ( TRIM(surfdata%cvars(1)) )
+      CASE('SLA')
+
+         clfiletype = 'slafb'
+         fbdata%cname(1)      = surfdata%cvars(1)
          fbdata%coblong(1)    = 'Sea level anomaly'
          fbdata%cobunit(1)    = 'Metres'
@@ -373,5 +378,5 @@
          fbdata%cextlong(1)   = 'Mean dynamic topography'
          fbdata%cextunit(1)   = 'Metres'
-         DO je = 1, next
+         DO je = 1, iext
             fbdata%cextname(je) = pext%cdname(je)
             fbdata%cextlong(je) = pext%cdlong(je,1)
@@ -384,5 +389,5 @@
          fbdata%caddunit(2,1) = 'Metres'
          fbdata%cgrid(1)      = 'T'
-         DO ja = 1, nadd
+         DO ja = 1, iadd
             fbdata%caddname(2+ja) = padd%cdname(ja)
             fbdata%caddlong(2+ja,1) = padd%cdlong(ja,1)
@@ -390,10 +395,11 @@
          END DO
 
-      CASE('sst')
-
-         fbdata%cname(1)      = 'SST'
+      CASE('SST')
+
+         clfiletype = 'sstfb'
+         fbdata%cname(1)      = surfdata%cvars(1)
          fbdata%coblong(1)    = 'Sea surface temperature'
          fbdata%cobunit(1)    = 'Degree centigrade'
-         DO je = 1, next
+         DO je = 1, iext
             fbdata%cextname(je) = pext%cdname(je)
             fbdata%cextlong(je) = pext%cdlong(je,1)
@@ -403,5 +409,5 @@
          fbdata%caddunit(1,1) = 'Degree centigrade'
          fbdata%cgrid(1)      = 'T'
-         DO ja = 1, nadd
+         DO ja = 1, iadd
             fbdata%caddname(1+ja) = padd%cdname(ja)
             fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
@@ -409,18 +415,19 @@
          END DO
 
-      CASE('sss')
-
-         fbdata%cname(1)      = 'SSS'
-         fbdata%coblong(1)    = 'Sea surface salinity'
-         fbdata%cobunit(1)    = 'PSU'
-         DO je = 1, next
+      CASE('SEAICE')
+
+         clfiletype = 'sicfb'
+         fbdata%cname(1)      = surfdata%cvars(1)
+         fbdata%coblong(1)    = 'Sea ice'
+         fbdata%cobunit(1)    = 'Fraction'
+         DO je = 1, iext
             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%caddlong(1,1) = 'Model interpolated ICE'
+         fbdata%caddunit(1,1) = 'Fraction'
          fbdata%cgrid(1)      = 'T'
-         DO ja = 1, nadd
+         DO ja = 1, iadd
             fbdata%caddname(1+ja) = padd%cdname(ja)
             fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
@@ -428,28 +435,9 @@
          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'
 
-      WRITE(cfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(cobstype), nproc
+      WRITE(clfname, FMT="(A,'_fdbk_',I4.4,'.nc')") TRIM(clfiletype), nproc
 
       IF(lwp) THEN
@@ -457,5 +445,5 @@
          WRITE(numout,*)'obs_wri_surf :'
          WRITE(numout,*)'~~~~~~~~~~~~~'
-         WRITE(numout,*)'Writing surface feedback file : ',TRIM(cfname)
+         WRITE(numout,*)'Writing '//TRIM(surfdata%cvars(1))//' feedback file : ',TRIM(clfname)
       ENDIF
 
@@ -498,5 +486,5 @@
             &           krefdate = 19500101 )
          fbdata%padd(1,jo,1,1) = surfdata%rmod(jo,1)
-         IF ( TRIM(cobstype) == 'sla' ) fbdata%padd(1,jo,2,1) = surfdata%rext(jo,1)
+         IF ( TRIM(surfdata%cvars(1)) == '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
@@ -514,10 +502,10 @@
          ENDIF
          fbdata%iobsk(1,jo,1)  = 0
-         IF ( TRIM(cobstype) == 'sla' ) fbdata%pext(1,jo,1) = surfdata%rext(jo,2)
-         DO ja = 1, nadd
+         IF ( TRIM(surfdata%cvars(1)) == 'SLA' ) fbdata%pext(1,jo,1) = surfdata%rext(jo,2)
+         DO ja = 1, iadd
             fbdata%padd(1,jo,2+ja,1) = &
                & surfdata%rext(jo,padd%ipoint(ja))
          END DO
-         DO je = 1, next
+         DO je = 1, iext
             fbdata%pext(1,jo,1+je) = &
                & surfdata%rext(jo,pext%ipoint(je))
@@ -526,5 +514,5 @@
 
       ! Write the obfbdata structure
-      CALL write_obfbdata( cfname, fbdata )
+      CALL write_obfbdata( clfname, fbdata )
 
       ! Output some basic statistics
@@ -556,7 +544,6 @@
       INTEGER :: jo
       INTEGER :: jk
-
-      INTEGER :: numgoodobs
-      INTEGER :: numgoodobsmpp
+      INTEGER :: inumgoodobs
+      INTEGER :: inumgoodobsmpp
       REAL(wp) :: zsumx
       REAL(wp) :: zsumx2
@@ -566,5 +553,5 @@
          WRITE(numout,*) ''
          WRITE(numout,*) 'obs_wri_stats :'
-         WRITE(numout,*) '~~~~~~~~~~~~~~~' 
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
       ENDIF
 
@@ -572,5 +559,5 @@
          zsumx=0.0_wp
          zsumx2=0.0_wp
-         numgoodobs=0
+         inumgoodobs=0
          DO jo = 1, fbdata%nobs
             DO jk = 1, fbdata%nlev
@@ -578,24 +565,24 @@
                   & ( 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)
+
+                  zomb=fbdata%pob(jk, jo, jvar)-fbdata%padd(jk, jo, 1, jvar)
                   zsumx=zsumx+zomb
                   zsumx2=zsumx2+zomb**2
-                  numgoodobs=numgoodobs+1
-	       ENDIF
+                  inumgoodobs=inumgoodobs+1
+               ENDIF
             ENDDO
          ENDDO
 
-         CALL obs_mpp_sum_integer( numgoodobs, numgoodobsmpp )
+         CALL obs_mpp_sum_integer( inumgoodobs, inumgoodobsmpp )
          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,*) ''
+            WRITE(numout,*) 'Type: ',fbdata%cname(jvar),'  Total number of good observations: ',inumgoodobsmpp 
+            WRITE(numout,*) 'Overall mean obs minus model of the good observations: ',zsumx/inumgoodobsmpp
+            WRITE(numout,*) 'Overall RMS obs minus model of the good observations: ',sqrt( zsumx2/inumgoodobsmpp )
+            WRITE(numout,*) ''
          ENDIF
- 
+
       ENDDO
 
