Index: branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90
===================================================================
--- branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 8442)
+++ branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 9163)
@@ -27,7 +27,9 @@
    !!----------------------------------------------------------------------
    USE oce_trc         ! ocean dynamics and tracers variables
+   USE domvvl          ! variable volume  
    USE trc             ! ocean passive tracers variables
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE prtctl_trc      ! Print control for debbuging
+   USE trcnam_trp      ! passive tracers transport namelist variables
    USE trd_oce
    USE trdtra
@@ -45,4 +47,6 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::   r2dt
 
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -124,5 +128,37 @@
       IF( l_trdtrc )  THEN
          CALL wrk_alloc( jpi, jpj, jpk, jptra, ztrdt )  !* store now fields before applying the Asselin filter
-         ztrdt(:,:,:,:)  = trn(:,:,:,:)
+         ztrdt(:,:,jpk,:) = 0._wp
+         IF( ln_trcldf_iso ) THEN                       ! diagnose the "pure" Kz diffusive trend 
+            DO jn = 1, jptra
+               CALL trd_tra( kt, 'TRC', jn, jptra_zdfp, ztrdt(:,:,:,jn) )
+            ENDDO
+         ENDIF
+         ! total trend for the non-time-filtered variables.
+         ! G Nurser 23 Mar 2017. Recalculate trend as Delta(e3t*T)/e3tn; e3tn
+         ! cancel from tsn terms
+         IF( lk_vvl ) THEN
+            DO jn = 1, jptra
+               DO jk = 1, jpkm1
+                  zfact = 1.0 / rdttrc(jk)
+                  ztrdt(:,:,jk,jn) = ( tra(:,:,jk,jn)*fse3t_a(:,:,jk) / fse3t_n(:,:,jk) - &
+                                       trn(:,:,jk,jn) ) * zfact
+               END DO
+            END DO
+         ELSE
+            DO jn = 1, jptra
+               DO jk = 1, jpkm1
+                  zfact = 1.0 / rdttrc(jk)
+                  ztrdt(:,:,jk,jn) = ( tra(:,:,jk,jn) - trn(:,:,jk,jn) ) * zfact
+               END DO
+            END DO
+         END IF
+         DO jn = 1, jptra
+            CALL trd_tra( kt, 'TRC', jn, jptra_tot, ztrdt(:,:,:,jn) )
+         ENDDO
+         IF( .NOT.lk_vvl )  THEN
+            ! Store now fields before applying the Asselin filter 
+            ! in order to calculate Asselin filter trend later.
+            ztrdt(:,:,:,:)  = trn(:,:,:,:)
+         ENDIF
       ENDIF
       ! Leap-Frog + Asselin filter time stepping
@@ -134,4 +170,15 @@
             END DO
          END DO
+         IF (l_trdtrc.AND.lk_vvl) THEN      ! Zero Asselin filter contribution
+                                            ! must be explicitly written out since for vvl
+                                            ! Asselin filter is output by
+                                            ! tra_nxt_vvl that is not called on
+                                            ! this time step
+            ztrdt(:,:,:,:) = 0._wp
+            DO jn = 1, jptra
+               CALL trd_tra( kt, 'TRC', jn, jptra_atf, ztrdt(:,:,:,jn) )
+            ENDDO
+         END IF
+
          !                                              
       ELSE
@@ -144,14 +191,15 @@
 
       ! trends computation
-      IF( l_trdtrc ) THEN                                      ! trends
+      IF( l_trdtrc.AND..NOT.lk_vvl) THEN                                      ! trends
          DO jn = 1, jptra
             DO jk = 1, jpkm1
                zfact = 1.e0 / r2dt(jk)  
                ztrdt(:,:,jk,jn) = ( trb(:,:,jk,jn) - ztrdt(:,:,jk,jn) ) * zfact 
-               CALL trd_tra( kt, 'TRC', jn, jptra_atf, ztrdt )
-            END DO
+            END DO
+            CALL trd_tra( kt, 'TRC', jn, jptra_atf, ztrdt(:,:,:,jn) )
          END DO
-         CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztrdt ) 
       END IF
+      !
+      IF( l_trdtrc)  CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztrdt ) 
       !
       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
Index: branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90
===================================================================
--- branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 8442)
+++ branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 9163)
@@ -140,6 +140,9 @@
       DO jn = 1, jptra
          !
-         IF( l_trdtrc ) ztrtrd(:,:,:) = tra(:,:,:,jn)  ! save trends
-         !                                             ! add the trend to the general tracer trend
+         IF( l_trdtrc ) THEN
+            ztrtrd(:,:,:) = 0.0
+            ztrtrd(:,:,1) = tra(:,:,1,jn)  ! save surface trends
+         !                                 ! add the trend to the general tracer trend
+         ENDIF
 
          IF ( nn_ice_tr == -1 ) THEN  ! No tracers in sea ice (null concentration in sea ice)
@@ -184,5 +187,5 @@
          !
          IF( l_trdtrc ) THEN
-            ztrtrd(:,:,:) = tra(:,:,:,jn) - ztrtrd(:,:,:)
+            ztrtrd(:,:,1) = tra(:,:,1,jn) - ztrtrd(:,:,1)
             CALL trd_tra( kt, 'TRC', jn, jptra_nsr, ztrtrd )
          END IF
Index: branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90
===================================================================
--- branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 8442)
+++ branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 9163)
@@ -28,5 +28,5 @@
    USE zpshde          ! partial step: hor. derivative       (zps_hde routine)
 # if defined key_debug_medusa
-   USE trcrst
+   USE trcstat
 # endif
 
Index: branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90
===================================================================
--- branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90	(revision 8442)
+++ branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90	(revision 9163)
@@ -15,4 +15,5 @@
    !!----------------------------------------------------------------------
    USE oce_trc         ! ocean dynamics and active tracers
+   USE domvvl          ! variable volume       
    USE trc             ! ocean passive tracers variables
    USE trcnam_trp      ! passive tracers transport namelist variables
@@ -98,8 +99,21 @@
 
       IF( l_trdtrc )   THEN                      ! save the vertical diffusive trends for further diagnostics
+         !! JPALM -- 18-08-2017 -- vvl case, do as done by G Nurser in trazdf 
+         IF( lk_vvl ) THEN
+            DO jn = 1, jptra
+               DO jk = 1, jpkm1
+                  ztrtrd(:,:,jk,jn) = ( ( tra(:,:,jk,jn)*fse3t_a(:,:,jk) - &
+                                          trb(:,:,jk,jn)*fse3t_b(:,:,jk) ) &
+                                       / (fse3t_n(:,:,jk)*r2dt(jk)) ) - ztrtrd(:,:,jk,jn)
+               END DO
+            END DO
+         ELSE
+            DO jn = 1, jptra
+               DO jk = 1, jpkm1
+                  ztrtrd(:,:,jk,jn) = ( ( tra(:,:,jk,jn) - trb(:,:,jk,jn) ) / r2dt(jk) ) - ztrtrd(:,:,jk,jn)
+               END DO
+            END DO
+         ENDIF 
          DO jn = 1, jptra
-            DO jk = 1, jpkm1
-               ztrtrd(:,:,jk,jn) = ( ( tra(:,:,jk,jn) - trb(:,:,jk,jn) ) / r2dt(jk) ) - ztrtrd(:,:,jk,jn)
-            END DO
             CALL trd_tra( kt, 'TRC', jn, jptra_zdf, ztrtrd(:,:,:,jn) )
          END DO
Index: branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc.F90
===================================================================
--- branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc.F90	(revision 8442)
+++ branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc.F90	(revision 9163)
@@ -19,4 +19,7 @@
    USE trdmxl_trc        ! Mixed layer trends diag.
    USE iom               ! I/O library
+# if defined key_debug_medusa
+   USE trcstat,          ONLY: trc_rst_dia_stat     
+# endif
 
    IMPLICIT NONE
@@ -86,21 +89,70 @@
 
       IF( lk_trdtrc .AND. ln_trdtrc( kjn ) ) THEN
-         !
+      !! JPALM -- 17-08-2017 -- modif following trd_tra_iom as suggested by Georges
+      !!                     -- add jptra_tot; jptra_totad; jptra_zdfp
+      !!                     -- shange to output trends every 2 time-step, except tot.
+      !!                     -- move cltra and iomput inside the select case
+      !!                     So if an non-wanted case arrives here it will not go
+      !!                     through cltra (without value) and break iomput.
+      !!                     -- Add iom_use in prevision of not using All trends
+      !!                     for All passive tracers (will create a HUGE 3D file otherwise --
+      !!                     might be interested in very few of them : SMS and TOT probably)
+         !
+         SELECT CASE( ktrd )
+         !! tot - output every time-step:
+         CASE( jptra_tot  )       ;    WRITE (cltra,'("TOT_",4a)')
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
+         END SELECT
+         !
+       IF( MOD( kt, 2 ) == 0 ) THEN
          SELECT CASE( ktrd )
          CASE( jptra_xad  )       ;    WRITE (cltra,'("XAD_",4a)')
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_yad  )       ;    WRITE (cltra,'("YAD_",4a)')
-         CASE( jptra_zad  )       ;    WRITE (cltra,'("ZAD_",4a)')
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
+         CASE( jptra_zad  )       ;    WRITE (cltra,'("ZAD_",4a)')      !! care vvl case
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
+         CASE( jptra_totad  )     ;    WRITE (cltra,'("TAD_",4a)')      !! total adv
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_ldf  )       ;    WRITE (cltra,'("LDF_",4a)')
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_bbl  )       ;    WRITE (cltra,'("BBL_",4a)')
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_nsr  )       ;    WRITE (cltra,'("FOR_",4a)')
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_zdf  )       ;    WRITE (cltra,'("ZDF_",4a)')
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
+         CASE( jptra_zdfp )       ;    WRITE (cltra,'("ZDP_",4a)')
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_dmp  )       ;    WRITE (cltra,'("DMP_",4a)')
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_sms  )       ;    WRITE (cltra,'("SMS_",4a)')
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
+         CASE( jptra_radb )       ;    WRITE (cltra,'("RDB_",4a)')
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
+         CASE( jptra_radn )       ;    WRITE (cltra,'("RDN_",4a)')
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
+         END SELECT
+       ELSE IF( MOD( kt, 2 ) == 1 ) THEN
+         SELECT CASE( ktrd )
          CASE( jptra_atf  )       ;    WRITE (cltra,'("ATF_",4a)')
-         CASE( jptra_radb )       ;    WRITE (cltra,'("RDB_",4a)')
-         CASE( jptra_radn )       ;    WRITE (cltra,'("RDN_",4a)')
-         END SELECT
-                                          cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                                          CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
+         END SELECT
+       END IF
          !
       END IF
@@ -123,4 +175,33 @@
 
    END SUBROUTINE trd_trc_bio
+
+   SUBROUTINE trd_trc_iomput( cltra, ptrtrd, kjn, kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_trc_iomput  ***
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in )  ::   kt                                  ! timestep
+      INTEGER, INTENT( in )  ::   kjn                                 ! biotrend index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout )  ::   ptrtrd  ! var trend
+      CHARACTER (len=*),INTENT( in ) :: cltra                         ! trend name
+      !!----------------------------------------------------------------------
+
+
+      IF  (iom_use(cltra)) THEN
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' TREND stats (min, max,sum) kt = ',kt ,' jn = ',kjn
+         CALL trc_rst_dia_stat( ptrtrd(:,:,1), cltra)
+# endif
+         CALL iom_put( cltra,  ptrtrd(:,:,:) )
+# if defined key_debug_medusa
+      ELSE
+         IF(lwp) WRITE(numout,*) &
+                      ' TREND -- No output asked for ',cltra,' kt = ',kt,' jn = ',kjn
+         CALL trc_rst_dia_stat( ptrtrd(:,:,1), cltra)
+# endif
+      ENDIF
+
+   END SUBROUTINE trd_trc_iomput
+
+
 #else
    !!----------------------------------------------------------------------
