Index: branches/UKMO/dev_r5518_GO6_package_FOAMv14/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc.F90
===================================================================
--- branches/UKMO/dev_r5518_GO6_package_FOAMv14/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc.F90	(revision 9287)
+++ branches/UKMO/dev_r5518_GO6_package_FOAMv14/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc.F90	(revision 10302)
@@ -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
    !!----------------------------------------------------------------------
