Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdicp.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdicp.F90	(revision 3313)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdicp.F90	(revision 3316)
@@ -5,4 +5,5 @@
    !!=====================================================================
    !! History :  1.0  !  2004-08 (C. Talandier) New trends organization
+   !!            3.5  !  2012-02 (G. Madec)  add 3D tracer zdf trend output using iom
    !!----------------------------------------------------------------------
 #if  defined key_trdtra   ||   defined key_trddyn   ||   defined key_esopa
@@ -22,10 +23,11 @@
    USE ldfdyn_oce      ! ocean dynamics: lateral physics
    USE zdf_oce         ! ocean vertical physics
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! distibuted memory computing library
+   USE zdfddm          ! ocean vertical physics: double diffusion
    USE eosbn2          ! equation of state
    USE phycst          ! physical constants
+   USE lib_mpp         ! distibuted memory computing library
+   USE in_out_manager  ! I/O manager
+   USE iom             ! I/O manager library
    USE wrk_nemo        ! Memory allocation
-
 
    IMPLICIT NONE
@@ -44,4 +46,5 @@
 #  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
+#  include "zdfddm_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -55,11 +58,11 @@
       !!                  ***  ROUTINE trd_2d  ***
       !! 
-      !! ** Purpose : verify the basin averaged properties of tracers and/or
-      !!              momentum equations at every time step frequency nn_trd.
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ptrd2dx   ! Temperature or U trend 
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ptrd2dy   ! Salinity    or V trend
-      INTEGER                     , INTENT(in   ) ::   ktrd      ! tracer trend index
-      CHARACTER(len=3)            , INTENT(in   ) ::   ctype     ! momentum ('DYN') or tracers ('TRA') trends
+      !! ** Purpose :   compute and print the domain averaged properties of tracers 
+      !!              and/or momentum equations at each nn_trd time step.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   ptrd2dx   ! Temperature or U trend 
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   ptrd2dy   ! Salinity    or V trend
+      INTEGER                 , INTENT(in   ) ::   ktrd      ! tracer trend index
+      CHARACTER(len=3)        , INTENT(in   ) ::   ctype     ! momentum ('DYN') or tracers ('TRA') trends
       !!
       INTEGER ::   ji, jj   ! loop indices
@@ -123,8 +126,8 @@
       !!              momentum equations at every time step frequency nn_trd.
       !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptrd3dx   ! Temperature or U trend 
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptrd3dy   ! Salinity    or V trend
-      INTEGER,                          INTENT(in   ) ::   ktrd      ! momentum or tracer trend index
-      CHARACTER(len=3),                 INTENT(in   ) ::   ctype     ! momentum ('DYN') or tracers ('TRA') trends
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrd3dx   ! Temperature or U trend 
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrd3dy   ! Salinity    or V trend
+      INTEGER,                    INTENT(in   ) ::   ktrd      ! momentum or tracer trend index
+      CHARACTER(len=3),           INTENT(in   ) ::   ctype     ! momentum ('DYN') or tracers ('TRA') trends
       !!
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
@@ -253,5 +256,4 @@
       !! ** Purpose :  write dynamic trends in ocean.output 
       !!----------------------------------------------------------------------
-      !
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !
@@ -261,4 +263,6 @@
       !!----------------------------------------------------------------------
 
+      IF( ln_3D_trd_t .AND. ln_3D_trd_d )   RETURN            ! do nothing if 3D output with IOM
+
       CALL wrk_alloc( jpi, jpj, jpk, zkx, zky, zkz, zkepe )
 
@@ -266,5 +270,5 @@
       ! -------------------
 
-      IF( MOD(kt,nn_trd) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
+      IF( MOD( kt, nn_trd ) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
 
          ! I.1 Conversion potential energy - kinetic energy
@@ -449,5 +453,38 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      !!----------------------------------------------------------------------
+      !
+      INTEGER  ::   jk   ! loop indices
+      REAL(wp), POINTER, DIMENSION(:,:,:)  ::   zwt, zws, ztrdt, ztrds   ! 3D workspace
+      !!----------------------------------------------------------------------
+
+
+      IF( ln_3D_trd_t ) THEN      ! 3D output: treat the vertical diffusion trends (if iso)
+         !
+         CALL wrk_alloc( jpi, jpj, jpk, zwt, zws, ztrdt, ztrds )
+         !
+         IF( ln_traldf_iso ) THEN      ! iso-neutral diffusion : re-compute the PURE vertical diffusive trend
+            !                                 !  zdf trends using now field (called after the swap)
+            zwt(:,:, 1 ) = 0._wp   ;   zws(:,:, 1 ) = 0._wp            ! vertical diffusive fluxes
+            zwt(:,:,jpk) = 0._wp   ;   zws(:,:,jpk) = 0._wp
+            DO jk = 2, jpk
+               zwt(:,:,jk) =   avt(:,:,jk) * ( tsn(:,:,jk-1,jp_tem) - tsn(:,:,jk,jp_tem) ) / fse3w(:,:,jk) * tmask(:,:,jk)
+               zws(:,:,jk) = fsavs(:,:,jk) * ( tsn(:,:,jk-1,jp_sal) - tsn(:,:,jk,jp_sal) ) / fse3w(:,:,jk) * tmask(:,:,jk)
+            END DO
+            !
+            ztrdt(:,:,jpk) = 0._wp   ;   ztrds(:,:,jpk) = 0._wp
+            DO jk = 1, jpkm1
+               ztrdt(:,:,jk) = ( zwt(:,:,jk) - zwt(:,:,jk+1) ) / fse3t(:,:,jk)
+               ztrds(:,:,jk) = ( zws(:,:,jk) - zws(:,:,jk+1) ) / fse3t(:,:,jk)
+            END DO
+            CALL iom_put( "ttrd_zdfp", ztrdt )        ! PURE vertical diffusion (no isoneutral contribution)
+            CALL iom_put( "strd_zdfp", ztrds )
+         ENDIF
+         !
+         CALL wrk_dealloc( jpi, jpj, jpk, zwt, zws, ztrdt, ztrds )
+         !
+         RETURN                     ! do nothing else if 3D output with IOM
+         !
+      ENDIF
+
 
       ! I. Tracers trends
