Index: /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90
===================================================================
--- /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90	(revision 10389)
+++ /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90	(revision 10390)
@@ -21,4 +21,11 @@
 #endif
    USE diatmb
+#if defined key_fabm
+   USE trc, ONLY: trn
+   USE par_fabm
+   USE st2d_fabm, ONLY: fabm_st2dn
+   USE fabm, ONLY: fabm_get_interior_diagnostic_data, &
+      &            fabm_get_horizontal_diagnostic_data
+#endif
 
    IMPLICIT NONE
@@ -39,4 +46,11 @@
 #if defined key_zdfgls 
    REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   rmxln_25h
+#endif
+#if defined key_fabm
+   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:,:) :: fabm_25h
+   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:,:) :: fabm_3d_25h
+   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:)   :: fabm_surface_25h
+   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:)   :: fabm_bottom_25h
+   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:)   :: fabm_2d_25h
 #endif
    INTEGER, SAVE :: cnt_25h     ! Counter for 25 hour means
@@ -64,4 +78,5 @@
       INTEGER ::   ios                 ! Local integer output status for namelist read
       INTEGER ::   ierror              ! Local integer for memory allocation
+      INTEGER ::   jn                  ! Loop counter
       REAL(wp), DIMENSION(jpi,jpj,3)   ::   zwtmb                                 ! temporary workspace
       !
@@ -145,4 +160,26 @@
          CALL ctl_stop( 'dia_25h: unable to allocate sshn_25h' )   ;   RETURN
       ENDIF
+#if defined key_fabm
+      ALLOCATE( fabm_25h(jpi,jpj,jpk,jp_fabm), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate fabm_25h' )   ;   RETURN
+      ENDIF
+      ALLOCATE( fabm_3d_25h(jpi,jpj,jpk,jp_fabm_3d), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate fabm_3d_25h' )   ;   RETURN
+      ENDIF
+      ALLOCATE( fabm_surface_25h(jpi,jpj,jp_fabm_surface), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate fabm_surface_25h' )   ;   RETURN
+      ENDIF
+      ALLOCATE( fabm_bottom_25h(jpi,jpj,jp_fabm_bottom), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate fabm_bottom_25h' )   ;   RETURN
+      ENDIF
+      ALLOCATE( fabm_2d_25h(jpi,jpj,jp_fabm_2d), STAT=ierror )
+      IF( ierror > 0 ) THEN
+         CALL ctl_stop( 'dia_25h: unable to allocate fabm_2d_25h' )   ;   RETURN
+      ENDIF
+#endif 
       ! ------------------------- !
       ! 2 - Assign Initial Values !
@@ -169,4 +206,21 @@
          rmxln_25h(:,:,:) = mxln(:,:,:)
 #endif
+#if defined key_fabm
+      DO jn = 1, jp_fabm
+         fabm_25h(:,:,:,jn) = trn(:,:,:,jp_fabm_m1+jn)
+      END DO
+      DO jn = 1, jp_fabm_3d
+         fabm_3d_25h(:,:,:,jn) = fabm_get_interior_diagnostic_data(model, jn)
+      END DO
+      DO jn = 1, jp_fabm_surface
+         fabm_surface_25h(:,:,jn) = fabm_st2dn(:,:,jn)
+      END DO
+      DO jn = 1, jp_fabm_bottom
+         fabm_bottom_25h(:,:,jn) = fabm_st2dn(:,:,jp_fabm_surface+jn)
+      END DO
+      DO jn = 1, jp_fabm_2d
+         fabm_2d_25h(:,:,jn) = fabm_get_horizontal_diagnostic_data(model,jn)
+      END DO
+#endif
 #if defined key_lim3 || defined key_lim2
          CALL ctl_stop('STOP', 'dia_25h not setup yet to do tidemean ice')
@@ -207,5 +261,5 @@
 
       !! * Local declarations
-      INTEGER ::   ji, jj, jk
+      INTEGER ::   ji, jj, jk, jn
 
       LOGICAL ::   ll_print = .FALSE.    ! =T print and flush numout
@@ -268,4 +322,21 @@
          rmxln_25h(:,:,:)      = rmxln_25h(:,:,:) + mxln(:,:,:)
 #endif
+#if defined key_fabm
+      DO jn = 1, jp_fabm
+         fabm_25h(:,:,:,jn) = fabm_25h(:,:,:,jn) + trn(:,:,:,jp_fabm_m1+jn)
+      END DO
+      DO jn = 1, jp_fabm_3d
+         fabm_3d_25h(:,:,:,jn) = fabm_3d_25h(:,:,:,jn) + fabm_get_interior_diagnostic_data(model, jn)
+      END DO
+      DO jn = 1, jp_fabm_surface
+         fabm_surface_25h(:,:,jn) = fabm_surface_25h(:,:,jn) + fabm_st2dn(:,:,jn)
+      END DO
+      DO jn = 1, jp_fabm_bottom
+         fabm_bottom_25h(:,:,jn) = fabm_bottom_25h(:,:,jn) + fabm_st2dn(:,:,jp_fabm_surface+jn)
+      END DO
+      DO jn = 1, jp_fabm_2d
+         fabm_2d_25h(:,:,jn) = fabm_2d_25h(:,:,jn) + fabm_get_horizontal_diagnostic_data(model,jn)
+      END DO
+#endif
          cnt_25h = cnt_25h + 1
 
@@ -300,4 +371,11 @@
 # if defined key_zdfgls
             rmxln_25h(:,:,:)       = rmxln_25h(:,:,:) / 25.0_wp
+#endif
+#if defined key_fabm
+            fabm_25h(:,:,:,:)       = fabm_25h(:,:,:,:)       / 25.0_wp
+            fabm_3d_25h(:,:,:,:)    = fabm_3d_25h(:,:,:,:)    / 25.0_wp
+            fabm_surface_25h(:,:,:) = fabm_surface_25h(:,:,:) / 25.0_wp
+            fabm_bottom_25h(:,:,:)  = fabm_bottom_25h(:,:,:)  / 25.0_wp
+            fabm_2d_25h(:,:,:)      = fabm_2d_25h(:,:,:)      / 25.0_wp
 #endif
 
@@ -319,4 +397,27 @@
             CALL iom_put( "ssh25h", zw2d )   ! sea surface 
 
+#if defined key_fabm
+            ! Write ERSEM variables
+            DO jn = 1, jp_fabm
+               zw3d(:,:,:) = fabm_25h(:,:,:,jn)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+               CALL iom_put( TRIM(model%state_variables(jn)%name)//"25h", zw3d  )
+            END DO
+            DO jn = 1, jp_fabm_3d
+               zw3d(:,:,:) = fabm_3d_25h(:,:,:,jn)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+               CALL iom_put( TRIM(model%diagnostic_variables(jn)%name)//"25h", zw3d  )
+            END DO
+            DO jn = 1, jp_fabm_surface
+               zw2d(:,:) = fabm_surface_25h(:,:,jn)*tmask(:,:,1) + zmdi*(1.0-tmask(:,:,1))
+               CALL iom_put( TRIM(model%surface_state_variables(jn)%name)//"25h", zw2d  )
+            END DO
+            DO jn = 1, jp_fabm_bottom
+               zw2d(:,:) = fabm_bottom_25h(:,:,jn)*tmask(:,:,1) + zmdi*(1.0-tmask(:,:,1))
+               CALL iom_put( TRIM(model%bottom_state_variables(jn)%name)//"25h", zw2d  )
+            END DO
+            DO jn = 1, jp_fabm_2d
+               zw2d(:,:) = fabm_2d_25h(:,:,jn)*tmask(:,:,1) + zmdi*(1.0-tmask(:,:,1))
+               CALL iom_put( TRIM(model%horizontal_diagnostic_variables(jn)%name)//"25h", zw2d  )
+            END DO
+#endif
 
             ! Write velocities (instantaneous)
@@ -362,4 +463,21 @@
             rmxln_25h(:,:,:) = mxln(:,:,:)
 #endif
+#if defined key_fabm
+      DO jn = 1, jp_fabm
+         fabm_25h(:,:,:,jn) = trn(:,:,:,jp_fabm_m1+jn)
+      END DO
+      DO jn = 1, jp_fabm_3d
+         fabm_3d_25h(:,:,:,jn) = fabm_get_interior_diagnostic_data(model, jn)
+      END DO
+      DO jn = 1, jp_fabm_surface
+         fabm_surface_25h(:,:,jn) = fabm_st2dn(:,:,jn)
+      END DO
+      DO jn = 1, jp_fabm_bottom
+         fabm_bottom_25h(:,:,jn) = fabm_st2dn(:,:,jp_fabm_surface+jn)
+      END DO
+      DO jn = 1, jp_fabm_2d
+         fabm_2d_25h(:,:,jn) = fabm_get_horizontal_diagnostic_data(model,jn)
+      END DO
+#endif
             cnt_25h = 1
             IF (lwp)  WRITE(numout,*) 'dia_wri_tide : After 25hr mean write, reset sum to current value and cnt_25h to one for overlapping average',cnt_25h
Index: /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/OPA_SRC/DIA/diaopfoam.F90
===================================================================
--- /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/OPA_SRC/DIA/diaopfoam.F90	(revision 10389)
+++ /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/OPA_SRC/DIA/diaopfoam.F90	(revision 10390)
@@ -109,9 +109,4 @@
          CALL iom_put( "voce_op"   , vn                                    )    ! j-current
          !CALL iom_put( "woce_op"   , wn                                    )    ! k-current
-#if defined key_spm
-         cltra = TRIM(ctrc3d(5))//"_op"
-         zw3d(:,:,:) = trc3d(:,:,:,5)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:)) ! Visibility
-         CALL iom_put( cltra, zw3d  )
-#endif
          CALL calc_max_cur(zwu,zwv,zwz,zmdi)
          CALL iom_put( "maxu" , zwu                                     ) ! max u current
Index: /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/OPA_SRC/DIA/diatmb.F90
===================================================================
--- /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/OPA_SRC/DIA/diatmb.F90	(revision 10389)
+++ /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/OPA_SRC/DIA/diatmb.F90	(revision 10390)
@@ -11,4 +11,9 @@
    USE iom             ! I/0 library
    USE wrk_nemo        ! working arrays
+#if defined key_fabm
+   USE trc, ONLY: trn
+   USE par_fabm
+   USE fabm, ONLY: fabm_get_interior_diagnostic_data
+#endif
 
 
@@ -133,4 +138,5 @@
       REAL(wp), POINTER, DIMENSION(:,:,:) :: zwtmb    ! temporary workspace 
       REAL(wp)                         ::   zmdi      ! set masked values
+      INTEGER                          ::   jn        ! loop counter
 
       zmdi=1.e+20 !missing data indicator for maskin
@@ -162,4 +168,19 @@
          CALL iom_put( "bot_v" , zwtmb(:,:,3) )    ! tmb  V Velocity
 !Called in  dynspg_ts.F90       CALL iom_put( "baro_v" , vn_b )    ! Barotropic  V Velocity
+
+#if defined key_fabm
+         DO jn = 1, jp_fabm
+            CALL dia_calctmb( trn(:,:,:,jp_fabm_m1+jn), zwtmb )
+            CALL iom_put( "top_"//TRIM(model%state_variables(jn)%name) , zwtmb(:,:,1) )
+            CALL iom_put( "mid_"//TRIM(model%state_variables(jn)%name) , zwtmb(:,:,2) )
+            CALL iom_put( "bot_"//TRIM(model%state_variables(jn)%name) , zwtmb(:,:,3) )
+         END DO
+         DO jn = 1, jp_fabm_3d
+            CALL dia_calctmb( fabm_get_interior_diagnostic_data(model, jn), zwtmb )
+            CALL iom_put( "top_"//TRIM(model%diagnostic_variables(jn)%name) , zwtmb(:,:,1) )
+            CALL iom_put( "mid_"//TRIM(model%diagnostic_variables(jn)%name) , zwtmb(:,:,2) )
+            CALL iom_put( "bot_"//TRIM(model%diagnostic_variables(jn)%name) , zwtmb(:,:,3) )
+         END DO
+#endif
       ELSE
          CALL ctl_warn('dia_tmb: tmb diagnostic is set to false you should not have seen this')
Index: /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/TOP_SRC/FABM/par_fabm.F90
===================================================================
--- /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/TOP_SRC/FABM/par_fabm.F90	(revision 10389)
+++ /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/TOP_SRC/FABM/par_fabm.F90	(revision 10390)
@@ -9,5 +9,24 @@
    INTEGER, PUBLIC :: jp_fabm0, jp_fabm1, jp_fabm, &
                       jp_fabm_surface, jp_fabm_bottom, &
-                      jp_fabm_m1
+                      jp_fabm_m1, jp_fabm_2d, jp_fabm_3d
+
+   ! Variables needed for OBS/ASM
+   INTEGER, PUBLIC :: jp_fabm_chl1, jp_fabm_chl2, &
+                      jp_fabm_chl3, jp_fabm_chl4, &
+                      jp_fabm_p1c,  jp_fabm_p1n,  &
+                      jp_fabm_p1p,  jp_fabm_p1s,  &
+                      jp_fabm_p2c,  jp_fabm_p2n,  &
+                      jp_fabm_p2p,  jp_fabm_p3c,  &
+                      jp_fabm_p3n,  jp_fabm_p3p,  &
+                      jp_fabm_p4c,  jp_fabm_p4n,  &
+                      jp_fabm_p4p,  jp_fabm_z4c,  &
+                      jp_fabm_z5c,  jp_fabm_z5n,  &
+                      jp_fabm_z5p,  jp_fabm_z6c,  &
+                      jp_fabm_z6n,  jp_fabm_z6p,  &
+                      jp_fabm_n1p,  jp_fabm_n3n,  &
+                      jp_fabm_n4n,  jp_fabm_n5s,  &
+                      jp_fabm_o2o,  jp_fabm_o3c,  &
+                      jp_fabm_o3a,  jp_fabm_o3ph, &
+                      jp_fabm_o3pc
 
 #if defined key_fabm
Index: /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/TOP_SRC/FABM/trcini_fabm.F90
===================================================================
--- /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/TOP_SRC/FABM/trcini_fabm.F90	(revision 10389)
+++ /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/TOP_SRC/FABM/trcini_fabm.F90	(revision 10390)
@@ -65,10 +65,49 @@
       jp_fabm_m1=jptra
       jptra = jptra + jp_fabm
-      jpdia2d = jpdia2d + size(model%horizontal_diagnostic_variables)
-      jpdia3d = jpdia3d + size(model%diagnostic_variables)
+      jp_fabm_2d = size(model%horizontal_diagnostic_variables)
+      jp_fabm_3d = size(model%diagnostic_variables)
+      jpdia2d = jpdia2d + jp_fabm_2d
+      jpdia3d = jpdia3d + jp_fabm_3d
       jpdiabio = jpdiabio + jp_fabm
 
       !Initialize input data structures.
       call initialize_inputs
+
+      ! Get indexes for select state variables
+      jp_fabm_chl1 = fabm_state_index( 'P1_Chl' )
+      jp_fabm_chl2 = fabm_state_index( 'P2_Chl' )
+      jp_fabm_chl3 = fabm_state_index( 'P3_Chl' )
+      jp_fabm_chl4 = fabm_state_index( 'P4_Chl' )
+      jp_fabm_p1c  = fabm_state_index( 'P1_c' )
+      jp_fabm_p1n  = fabm_state_index( 'P1_n' )
+      jp_fabm_p1p  = fabm_state_index( 'P1_p' )
+      jp_fabm_p1s  = fabm_state_index( 'P1_s' )
+      jp_fabm_p2c  = fabm_state_index( 'P2_c' )
+      jp_fabm_p2n  = fabm_state_index( 'P2_n' )
+      jp_fabm_p2p  = fabm_state_index( 'P2_p' )
+      jp_fabm_p3c  = fabm_state_index( 'P3_c' )
+      jp_fabm_p3n  = fabm_state_index( 'P3_n' )
+      jp_fabm_p3p  = fabm_state_index( 'P3_p' )
+      jp_fabm_p4c  = fabm_state_index( 'P4_c' )
+      jp_fabm_p4n  = fabm_state_index( 'P4_n' )
+      jp_fabm_p4p  = fabm_state_index( 'P4_p' )
+      jp_fabm_z4c  = fabm_state_index( 'Z4_c' )
+      jp_fabm_z5c  = fabm_state_index( 'Z5_c' )
+      jp_fabm_z5n  = fabm_state_index( 'Z5_n' )
+      jp_fabm_z5p  = fabm_state_index( 'Z5_p' )
+      jp_fabm_z6c  = fabm_state_index( 'Z6_c' )
+      jp_fabm_z6n  = fabm_state_index( 'Z6_n' )
+      jp_fabm_z6p  = fabm_state_index( 'Z6_p' )
+      jp_fabm_n1p  = fabm_state_index( 'N1_p' )
+      jp_fabm_n3n  = fabm_state_index( 'N3_n' )
+      jp_fabm_n4n  = fabm_state_index( 'N4_n' )
+      jp_fabm_n5s  = fabm_state_index( 'N5_s' )
+      jp_fabm_o2o  = fabm_state_index( 'O2_o' )
+      jp_fabm_o3c  = fabm_state_index( 'O3_c' )
+      jp_fabm_o3a  = fabm_state_index( 'O3_bioalk' )
+
+      ! Get indexes for select diagnostic variables
+      jp_fabm_o3ph = fabm_diag_index( 'O3_pH' )
+      jp_fabm_o3pc = fabm_diag_index( 'O3_pCO2' )
 
       IF (lwp) THEN
@@ -84,4 +123,6 @@
             CALL write_trends_xml(xml_unit,model%state_variables(jn))
 #endif
+            CALL write_25hourm_xml(xml_unit,model%state_variables(jn))
+            CALL write_tmb_xml(xml_unit,model%state_variables(jn))
          END DO
          WRITE (xml_unit,1000) ' </field_group>'
@@ -90,7 +131,9 @@
          DO jn=1,jp_fabm_surface
             CALL write_variable_xml(xml_unit,model%surface_state_variables(jn))
+            CALL write_25hourm_xml(xml_unit,model%surface_state_variables(jn))
          END DO
          DO jn=1,jp_fabm_bottom
             CALL write_variable_xml(xml_unit,model%bottom_state_variables(jn))
+            CALL write_25hourm_xml(xml_unit,model%bottom_state_variables(jn))
          END DO
          WRITE (xml_unit,1000) ' </field_group>'
@@ -99,7 +142,10 @@
          DO jn=1,size(model%diagnostic_variables)
             CALL write_variable_xml(xml_unit,model%diagnostic_variables(jn),3)
+            CALL write_25hourm_xml(xml_unit,model%diagnostic_variables(jn),3)
+            CALL write_tmb_xml(xml_unit,model%diagnostic_variables(jn))
          END DO
          DO jn=1,size(model%horizontal_diagnostic_variables)
             CALL write_variable_xml(xml_unit,model%horizontal_diagnostic_variables(jn))
+            CALL write_25hourm_xml(xml_unit,model%horizontal_diagnostic_variables(jn))
          END DO
          WRITE (xml_unit,1000) ' </field_group>'
@@ -168,4 +214,50 @@
 
    END SUBROUTINE write_variable_xml
+
+   SUBROUTINE write_25hourm_xml(xml_unit,variable,flag_grid_ref)
+      INTEGER,INTENT(IN) :: xml_unit
+      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
+      CLASS (type_external_variable),INTENT(IN) :: variable
+
+      CHARACTER(LEN=20) :: missing_value,string_dimensions
+      INTEGER :: number_dimensions
+
+      ! Check variable dimension for grid_ref specificaiton.
+      ! Default is to not specify the grid_ref in the field definition.
+      IF (present(flag_grid_ref)) THEN
+          number_dimensions=flag_grid_ref
+      ELSE
+          number_dimensions=-1 !default, don't specify grid_ref
+      ENDIF
+
+      WRITE (missing_value,'(E9.3)') 1.e+20
+      WRITE (string_dimensions,'(I1)') number_dimensions
+      SELECT CASE (number_dimensions)
+      CASE (3)
+         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'25h'//'" long_name="'//TRIM(variable%long_name)//' 25-hour mean'//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
+      CASE (2)
+         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'25h'//'" long_name="'//TRIM(variable%long_name)//' 25-hour mean'//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
+      CASE (0)
+         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'25h'//'" long_name="'//TRIM(variable%long_name)//' 25-hour mean'//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="1point"/>'
+      CASE (-1)
+         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'25h'//'" long_name="'//TRIM(variable%long_name)//' 25-hour mean'//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" />'
+      CASE default
+         IF(lwp) WRITE(numout,*) ' trc_ini_fabm: Failing to initialise output of variable '//TRIM(variable%name)//'25h'//': Output of '//TRIM(ADJUSTL(string_dimensions))//'-dimensional variables not supported!!!'
+      END SELECT
+
+   END SUBROUTINE write_25hourm_xml
+
+   SUBROUTINE write_tmb_xml(xml_unit,variable)
+      INTEGER,INTENT(IN) :: xml_unit
+      CLASS (type_external_variable),INTENT(IN) :: variable
+
+      CHARACTER(LEN=20) :: missing_value
+
+      WRITE (missing_value,'(E9.3)') 1.e+20
+      WRITE (xml_unit,'(A)') '  <field id="top_'//TRIM(variable%name)//'" long_name="Top-level '//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
+      WRITE (xml_unit,'(A)') '  <field id="mid_'//TRIM(variable%name)//'" long_name="Middle-level '//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
+      WRITE (xml_unit,'(A)') '  <field id="bot_'//TRIM(variable%name)//'" long_name="Bottom-level '//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
+
+   END SUBROUTINE write_tmb_xml
 
    SUBROUTINE write_trends_xml(xml_unit,variable,flag_grid_ref)
@@ -328,4 +420,68 @@
    END SUBROUTINE trc_ini_fabm
 
+   INTEGER FUNCTION fabm_state_index( state_name )
+      !!----------------------------------------------------------------------
+      !!                     ***  fabm_state_index  ***  
+      !!
+      !! ** Purpose :   return index of a given FABM state variable
+      !!
+      !! ** Method  : - loop through state variables until found
+      !!----------------------------------------------------------------------
+      
+      IMPLICIT NONE
+      
+      CHARACTER(LEN=256), INTENT(IN) :: state_name
+      
+      INTEGER                        :: jn
+
+      !!----------------------------------------------------------------------
+      
+      fabm_state_index = -1
+      DO jn=1,jp_fabm
+         IF (TRIM(model%state_variables(jn)%name) == TRIM(state_name)) THEN
+            fabm_state_index = jn
+            EXIT
+         ENDIF
+      END DO
+      IF (fabm_state_index == -1) THEN
+         CALL ctl_stop( 'Could not find '//TRIM(state_name)//' state variable' )
+      ELSE
+         IF (lwp) WRITE(numout,*) 'Index for '//TRIM(state_name)//' is: ', fabm_state_index
+      ENDIF
+   
+   END FUNCTION fabm_state_index
+
+   INTEGER FUNCTION fabm_diag_index( diag_name )
+      !!----------------------------------------------------------------------
+      !!                     ***  fabm_state_index  ***  
+      !!
+      !! ** Purpose :   return index of a given FABM diagnostic variable
+      !!
+      !! ** Method  : - loop through diagnostic variables until found
+      !!----------------------------------------------------------------------
+      
+      IMPLICIT NONE
+      
+      CHARACTER(LEN=256), INTENT(IN) :: diag_name
+      
+      INTEGER                        :: jn
+
+      !!----------------------------------------------------------------------
+      
+      fabm_diag_index = -1
+      DO jn = 1, SIZE(model%diagnostic_variables)
+         IF (TRIM(model%diagnostic_variables(jn)%name) == TRIM(diag_name)) THEN
+            fabm_diag_index = jn
+            EXIT
+         ENDIF
+      END DO
+      IF (fabm_diag_index == -1) THEN
+         CALL ctl_stop( 'Could not find '//TRIM(diag_name)//' diagnostic' )
+      ELSE
+         IF (lwp) WRITE(numout,*) 'Index for '//TRIM(diag_name)//' is: ', fabm_diag_index
+      ENDIF
+   
+   END FUNCTION fabm_diag_index
+
 #else
    !!----------------------------------------------------------------------
Index: /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/TOP_SRC/trcbc.F90
===================================================================
--- /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/TOP_SRC/trcbc.F90	(revision 10389)
+++ /branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/TOP_SRC/trcbc.F90	(revision 10390)
@@ -46,5 +46,5 @@
 #  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.6 , NEMO Consortium (2015)
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
