Index: branches/UKMO/r6232_collate_bgc_diagnostics/NEMOGCM/NEMO/TOP_SRC/TRP/trcrad.F90
===================================================================
--- branches/UKMO/r6232_collate_bgc_diagnostics/NEMOGCM/NEMO/TOP_SRC/TRP/trcrad.F90	(revision 11132)
+++ branches/UKMO/r6232_collate_bgc_diagnostics/NEMOGCM/NEMO/TOP_SRC/TRP/trcrad.F90	(revision 11134)
@@ -18,4 +18,7 @@
    USE trdtra
    USE prtctl_trc          ! Print control for debbuging
+#if defined key_tracer_budget
+   USE iom
+#endif
 
    IMPLICIT NONE
@@ -51,4 +54,7 @@
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index      
       CHARACTER (len=22) :: charout
+      ! +++>>> FABM
+      INTEGER :: jn
+      ! FABM <<<+++
       !!----------------------------------------------------------------------
       !
@@ -65,5 +71,13 @@
       IF( lk_pisces  )   CALL trc_rad_sms( kt, trb, trn, jp_pcs0 , jp_pcs1, cpreserv='Y' )  ! PISCES model
       IF( lk_my_trc  )   CALL trc_rad_sms( kt, trb, trn, jp_myt0 , jp_myt1               )  ! MY_TRC model
-
+      ! +++>>> FABM
+      IF( lk_fabm  )   THEN
+        DO jn=1,jp_fabm ! state variable loop
+          IF (lk_rad_fabm(jn)) THEN
+           CALL trc_rad_sms( kt, trb, trn, jn+jp_fabm_m1 , jn+jp_fabm_m1 )
+          ENDIF
+        END DO
+      END IF
+      ! FABM <<<+++
       !
       IF(ln_ctl) THEN      ! print mean trends (used for debugging)
@@ -110,4 +124,7 @@
       REAL(wp) :: zcoef, ztrcorn, ztrmasn   !    "         "
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrtrdb, ztrtrdn   ! workspace arrays
+#if defined key_tracer_budget
+      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  ztrtrdb_m1 ! slwa 
+#endif
       REAL(wp) :: zs2rdt
       LOGICAL ::   lldebug = .FALSE.
@@ -116,4 +133,19 @@
  
       IF( l_trdtrc )  CALL wrk_alloc( jpi, jpj, jpk, ztrtrdb, ztrtrdn )
+#if defined key_tracer_budget
+      IF( kt == nittrc000 .AND. l_trdtrc) THEN
+         IF (.not. ALLOCATED(ztrtrdb_m1)) ALLOCATE( ztrtrdb_m1(jpi,jpj,jpk,jptra) )  ! slwa
+            DO jn = jp_sms0, jp_sms1
+               IF( ln_rsttr .AND.    &                     ! Restart: read in restart  file
+                  iom_varid( numrtr, 'rdb_trend_'//TRIM(ctrcnm(jn)), ldstop = .FALSE. ) > 0 ) THEN
+                  IF(lwp) WRITE(numout,*) '          nittrc000-nn_dttrc RDB tracer trend read for',TRIM(ctrcnm(jn))
+                  CALL iom_get( numrtr, jpdom_autoglo, 'rdb_trend_'//TRIM(ctrcnm(jn)), ztrtrdb_m1(:,:,:,jn) )   ! before tracer trend for rdb
+               ELSE
+                  IF(lwp) WRITE(numout,*) '          no nittrc000-nn_dttrc RDB tracer trend for',TRIM(ctrcnm(jn)),', setting to 0.'
+                  ztrtrdb_m1(:,:,:,jn)=0.0
+               ENDIF
+            END DO
+      ENDIF
+#endif
       
       IF( PRESENT( cpreserv )  ) THEN   !  total tracer concentration is preserved 
@@ -156,5 +188,15 @@
                ztrtrdb(:,:,:) = ( ptrb(:,:,:,jn) - ztrtrdb(:,:,:) ) * zs2rdt
                ztrtrdn(:,:,:) = ( ptrn(:,:,:,jn) - ztrtrdn(:,:,:) ) * zs2rdt 
+#if defined key_tracer_budget
+! slwa budget code
+               DO jk = 1, jpkm1
+                  ztrtrdb(:,:,jk) = ztrtrdb(:,:,jk) * e1t(:,:) * e2t(:,:) * fse3t(:,:,jk)
+                  ztrtrdn(:,:,jk) = ztrtrdn(:,:,jk) * e1t(:,:) * e2t(:,:) * fse3t(:,:,jk)
+               END DO
+               CALL trd_tra( kt, 'TRC', jn, jptra_radb, ztrtrdb_m1(:,:,:,jn) )
+               ztrtrdb_m1(:,:,:,jn)=ztrtrdb(:,:,:)
+#else
                CALL trd_tra( kt, 'TRC', jn, jptra_radb, ztrtrdb )       ! Asselin-like trend handling
+#endif
                CALL trd_tra( kt, 'TRC', jn, jptra_radn, ztrtrdn )       ! standard     trend handling
               !
@@ -187,5 +229,15 @@
                ztrtrdb(:,:,:) = ( ptrb(:,:,:,jn) - ztrtrdb(:,:,:) ) * zs2rdt
                ztrtrdn(:,:,:) = ( ptrn(:,:,:,jn) - ztrtrdn(:,:,:) ) * zs2rdt 
+#if defined key_tracer_budget
+! slwa budget code
+               DO jk = 1, jpkm1
+                  ztrtrdb(:,:,jk) = ztrtrdb(:,:,jk) * e1t(:,:) * e2t(:,:) * fse3t(:,:,jk)
+                  ztrtrdn(:,:,jk) = ztrtrdn(:,:,jk) * e1t(:,:) * e2t(:,:) * fse3t(:,:,jk)
+               END DO
+               CALL trd_tra( kt, 'TRC', jn, jptra_radb, ztrtrdb_m1(:,:,:,jn) )
+               ztrtrdb_m1(:,:,:,jn)=ztrtrdb(:,:,:)
+#else
                CALL trd_tra( kt, 'TRC', jn, jptra_radb, ztrtrdb )       ! Asselin-like trend handling
+#endif
                CALL trd_tra( kt, 'TRC', jn, jptra_radn, ztrtrdn )       ! standard     trend handling
               !
@@ -195,4 +247,18 @@
 
       ENDIF
+
+#if defined key_tracer_budget
+      !                                           Write in the tracer restart file
+      !                                          *******************************
+      IF( lrst_trc ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc : RDB trend at last time step for tracer budget written in tracer restart file ',   &
+            &                    'at it= ', kt,' date= ', ndastp
+         IF(lwp) WRITE(numout,*) '~~~~'
+         DO jn = jp_sms0, jp_sms1
+            CALL iom_rstput( kt, nitrst, numrtw, 'rdb_trend_'//TRIM(ctrcnm(jn)), ztrtrdb_m1(:,:,:,jn) )
+         END DO
+      ENDIF
+#endif
 
       IF( l_trdtrc )  CALL wrk_dealloc( jpi, jpj, jpk, ztrtrdb, ztrtrdn )
