Index: /branches/UKMO/dev_r5518_obs_oper_update_bgc3d/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90
===================================================================
--- /branches/UKMO/dev_r5518_obs_oper_update_bgc3d/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90	(revision 8692)
+++ /branches/UKMO/dev_r5518_obs_oper_update_bgc3d/NEMOGCM/NEMO/OPA_SRC/OBS/obs_write.F90	(revision 8693)
@@ -322,4 +322,7 @@
       CHARACTER(LEN=27) :: clfiletype
       CHARACTER(LEN=12), PARAMETER :: cpname = 'obs_wri_surf'
+      CHARACTER(LEN=ilenlong) :: cllongname  ! Long name of variable
+      CHARACTER(LEN=ilenunit) :: clunits     ! Units of variable
+      CHARACTER(LEN=ilengrid) :: clgrid      ! Grid of variable
       INTEGER :: jo
       INTEGER :: ja
@@ -344,4 +347,7 @@
       SELECT CASE ( TRIM(surfdata%cvars(1)) )
       CASE('SLA')
+
+         ! SLA needs special treatment because of MDT, so is all done here
+         ! Other variables are done more generically
 
          CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
@@ -374,11 +380,117 @@
       CASE('SST')
 
+         clfiletype = 'sstfb'
+         cllongname = 'Sea surface temperature'
+         clunits    = 'Degree centigrade'
+         clgrid     = 'T'
+
+      CASE('ICECONC')
+
+         clfiletype = 'sicfb'
+         cllongname = 'Sea ice'
+         clunits    = 'Fraction'
+         clgrid     = 'T'
+
+      CASE('SSS')
+
+         clfiletype = 'sssfb'
+         cllongname = 'Sea surface salinity'
+         clunits    = 'psu'
+         clgrid     = 'T'
+
+      CASE('SURF_LOGCHL_TOTAL','LOGCHL','LogChl','logchl')
+
+         clfiletype = 'surf_logchl_totalfb'
+         cllongname = 'Surface total log10(chlorophyll)'
+         clunits    = 'log10(mg/m3)'
+         clgrid     = 'T'
+
+      CASE('SURF_LOGCHL_DIAT')
+
+         clfiletype = 'surf_logchl_diatfb'
+         cllongname = 'Surface diatom log10(chlorophyll)'
+         clunits    = 'log10(mg/m3)'
+         clgrid     = 'T'
+
+      CASE('SURF_LOGCHL_NONDIAT')
+
+         clfiletype = 'surf_logchl_nondiatfb'
+         cllongname = 'Surface non-diatom log10(chlorophyll)'
+         clunits    = 'log10(mg/m3)'
+         clgrid     = 'T'
+
+      CASE('SURF_LOGCHL_DINO')
+
+         clfiletype = 'surf_logchl_dinofb'
+         cllongname = 'Surface dinoflagellate log10(chlorophyll)'
+         clunits    = 'log10(mg/m3)'
+         clgrid     = 'T'
+
+      CASE('SURF_LOGCHL_MICRO')
+
+         clfiletype = 'surf_logchl_microfb'
+         cllongname = 'Surface microphytoplankton log10(chlorophyll)'
+         clunits    = 'log10(mg/m3)'
+         clgrid     = 'T'
+
+      CASE('SURF_LOGCHL_NANO')
+
+         clfiletype = 'surf_logchl_nanofb'
+         cllongname = 'Surface nanophytoplankton log10(chlorophyll)'
+         clunits    = 'log10(mg/m3)'
+         clgrid     = 'T'
+
+      CASE('SURF_LOGCHL_PICO')
+
+         clfiletype = 'surf_logchl_picofb'
+         cllongname = 'Surface picophytoplankton log10(chlorophyll)'
+         clunits    = 'log10(mg/m3)'
+         clgrid     = 'T'
+
+      CASE('SURF_CHL_TOTAL')
+
+         clfiletype = 'surf_chl_totalfb'
+         cllongname = 'Surface total chlorophyll'
+         clunits    = 'mg/m3'
+         clgrid     = 'T'
+
+      CASE('SURF_SPM')
+
+         clfiletype = 'surf_spmfb'
+         cllongname = 'Surface suspended particulate matter'
+         clunits    = 'g/m3'
+         clgrid     = 'T'
+
+      CASE('SURF_FCO2','FCO2','fCO2','fco2')
+
+         clfiletype = 'surf_fco2fb'
+         cllongname = 'Surface fugacity of carbon dioxide'
+         clunits    = 'uatm'
+         clgrid     = 'T'
+
+      CASE('SURF_PCO2')
+
+         clfiletype = 'surf_pco2fb'
+         cllongname = 'Surface partial pressure of carbon dioxide'
+         clunits    = 'uatm'
+         clgrid     = 'T'
+
+      CASE DEFAULT
+
+         CALL ctl_stop( 'Unknown observation type '//TRIM(surfdata%cvars(1))//' in obs_wri_surf' )
+
+      END SELECT
+
+      ! SLA needs special treatment because of MDT, so is done above
+      ! Remaining variables treated more generically
+
+      IF ( TRIM(surfdata%cvars(1)) /= 'SLA' ) THEN
+      
          CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
             &                 1 + iadd, iext, .TRUE. )
 
-         clfiletype = 'sstfb'
          fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Sea surface temperature'
-         fbdata%cobunit(1)    = 'Degree centigrade'
+         fbdata%coblong(1)    = cllongname
+         fbdata%cobunit(1)    = clunits
          DO je = 1, iext
             fbdata%cextname(je) = pext%cdname(je)
@@ -386,7 +498,11 @@
             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'
+         IF ( TRIM(surfdata%cvars(1)) == 'ICECONC' ) THEN
+            fbdata%caddlong(1,1) = 'Model interpolated ICE'
+         ELSE
+            fbdata%caddlong(1,1) = 'Model interpolated ' // TRIM(surfdata%cvars(1))
+         ENDIF
+         fbdata%caddunit(1,1) = clunits
+         fbdata%cgrid(1)      = clgrid
          DO ja = 1, iadd
             fbdata%caddname(1+ja) = padd%cdname(ja)
@@ -395,309 +511,6 @@
          END DO
 
-      CASE('ICECONC')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         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 ICE'
-         fbdata%caddunit(1,1) = 'Fraction'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            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')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'sssfb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Sea surface salinity'
-         fbdata%cobunit(1)    = 'psu'
-         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%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            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('SURF_LOGCHL_TOTAL','LOGCHL','LogChl','logchl')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'surf_logchl_totalfb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Surface total log10(chlorophyll)'
-         fbdata%cobunit(1)    = 'log10(mg/m3)'
-         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 ' // TRIM(surfdata%cvars(1))
-         fbdata%caddunit(1,1) = 'log10(mg/m3)'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            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('SURF_LOGCHL_DIAT')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'surf_logchl_diatfb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Surface diatom log10(chlorophyll)'
-         fbdata%cobunit(1)    = 'log10(mg/m3)'
-         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 ' // TRIM(surfdata%cvars(1))
-         fbdata%caddunit(1,1) = 'log10(mg/m3)'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            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('SURF_LOGCHL_NONDIAT')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'surf_logchl_nondiatfb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Surface non-diatom log10(chlorophyll)'
-         fbdata%cobunit(1)    = 'log10(mg/m3)'
-         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 ' // TRIM(surfdata%cvars(1))
-         fbdata%caddunit(1,1) = 'log10(mg/m3)'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            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('SURF_LOGCHL_DINO')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'surf_logchl_dinofb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Surface dinoflagellate log10(chlorophyll)'
-         fbdata%cobunit(1)    = 'log10(mg/m3)'
-         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 ' // TRIM(surfdata%cvars(1))
-         fbdata%caddunit(1,1) = 'log10(mg/m3)'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            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('SURF_LOGCHL_MICRO')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'surf_logchl_microfb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Surface microphytoplankton log10(chlorophyll)'
-         fbdata%cobunit(1)    = 'log10(mg/m3)'
-         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 ' // TRIM(surfdata%cvars(1))
-         fbdata%caddunit(1,1) = 'log10(mg/m3)'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            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('SURF_LOGCHL_NANO')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'surf_logchl_nanofb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Surface nanophytoplankton log10(chlorophyll)'
-         fbdata%cobunit(1)    = 'log10(mg/m3)'
-         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 ' // TRIM(surfdata%cvars(1))
-         fbdata%caddunit(1,1) = 'log10(mg/m3)'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            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('SURF_LOGCHL_PICO')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'surf_logchl_picofb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Surface picophytoplankton log10(chlorophyll)'
-         fbdata%cobunit(1)    = 'log10(mg/m3)'
-         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 ' // TRIM(surfdata%cvars(1))
-         fbdata%caddunit(1,1) = 'log10(mg/m3)'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            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('SURF_CHL_TOTAL')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'surf_chl_totalfb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Surface total chlorophyll'
-         fbdata%cobunit(1)    = 'mg/m3'
-         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 ' // TRIM(surfdata%cvars(1))
-         fbdata%caddunit(1,1) = 'mg/m3'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            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('SURF_SPM')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'surf_spmfb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Surface suspended particulate matter'
-         fbdata%cobunit(1)    = 'g/m3'
-         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 ' // TRIM(surfdata%cvars(1))
-         fbdata%caddunit(1,1) = 'g/m3'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            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('SURF_FCO2','FCO2','fCO2','fco2')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'surf_fco2fb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Surface fugacity of carbon dioxide'
-         fbdata%cobunit(1)    = 'uatm'
-         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 ' // TRIM(surfdata%cvars(1))
-         fbdata%caddunit(1,1) = 'uatm'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            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('SURF_PCO2')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'surf_pco2fb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Surface partial pressure of carbon dioxide'
-         fbdata%cobunit(1)    = 'uatm'
-         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 ' // TRIM(surfdata%cvars(1))
-         fbdata%caddunit(1,1) = 'uatm'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            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 DEFAULT
-
-         CALL ctl_stop( 'Unknown observation type '//TRIM(surfdata%cvars(1))//' in obs_wri_surf' )
-
-      END SELECT
-
+      ENDIF
+      
       fbdata%caddname(1)   = 'Hx'
 
