Index: /trunk/NEMO/OFF_SRC/IOM/iom.F90
===================================================================
--- /trunk/NEMO/OFF_SRC/IOM/iom.F90	(revision 1449)
+++ /trunk/NEMO/OFF_SRC/IOM/iom.F90	(revision 1450)
@@ -26,11 +26,20 @@
    USE iom_rstdimg     ! restarts access direct format "dimg" style...
 
+#if defined key_iomput
+   USE mod_event_client
+# endif
+
    IMPLICIT NONE
    PUBLIC   !   must be public to be able to access iom_def through iom
    
-   PUBLIC iom_open, iom_close, iom_varid, iom_get, iom_gettime, iom_rstput
+   PUBLIC iom_init, iom_open, iom_close, iom_setkt, iom_varid, iom_get, iom_gettime, iom_rstput, iom_put
 
    PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
    PRIVATE iom_g0d, iom_g1d, iom_g2d, iom_g3d, iom_get_123d
+   PRIVATE iom_p2d, iom_p3d
+#if defined key_iomput
+   PRIVATE iom_init_chkcpp
+   PRIVATE set_grid
+# endif
 
    INTERFACE iom_get
@@ -40,4 +49,12 @@
       MODULE PROCEDURE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
    END INTERFACE
+  INTERFACE iom_put
+     MODULE PROCEDURE iom_p2d, iom_p3d
+  END INTERFACE
+#if defined key_iomput
+   INTERFACE iom_setkt
+      MODULE PROCEDURE event__set_timestep
+   END INTERFACE
+# endif
 
    !!----------------------------------------------------------------------
@@ -49,5 +66,43 @@
 CONTAINS
 
-   SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, kiolib, ldstop )
+   SUBROUTINE iom_init( pjulian )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE   ***
+      !!
+      !! ** Purpose :   
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in) ::  pjulian   !: julian day at nit000 = 0
+#if defined key_iomput
+      !!----------------------------------------------------------------------
+      ! read the xml file
+      CALL event__parse_xml_file( 'iodef.xml' )   ! <- to get from the nameliste (namrun)...
+
+      ! calendar parameters
+      CALL event__set_time_parameters( nit000 - 1, pjulian, rdt )
+
+      ! horizontal grid definition
+      CALL set_grid( "grid_T", glamt, gphit )
+      CALL set_grid( "grid_U", glamu, gphiu )
+      CALL set_grid( "grid_V", glamv, gphiv )
+      CALL set_grid( "grid_W", glamt, gphit )
+
+      ! vertical grid definition
+      CALL event__set_vert_axis( "deptht", gdept_0 )
+      CALL event__set_vert_axis( "depthu", gdept_0 )
+      CALL event__set_vert_axis( "depthv", gdept_0 )
+      CALL event__set_vert_axis( "depthw", gdepw_0 )
+
+      ! consistency regarding CPP keys...
+      CALL iom_init_chkcpp
+
+      ! end file definition
+      CALL event__close_io_definition
+#endif
+
+   END SUBROUTINE iom_init
+
+
+   SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, kiolib, ldstop, ldiof )
       !!---------------------------------------------------------------------
       !!                   ***  SUBROUTINE  iom_open  ***
@@ -61,4 +116,5 @@
       INTEGER         , INTENT(in   ), OPTIONAL ::   kiolib   ! library used to open the file (default = jpnf90) 
       LOGICAL         , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
+      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldiof    ! Interp On the Fly, needed for AGRIF (default = .FALSE.)
 
       CHARACTER(LEN=100)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
@@ -71,4 +127,5 @@
       LOGICAL               ::   llnoov    ! local definition to read overlap
       LOGICAL               ::   llstop    ! local definition of ldstop
+      LOGICAL               ::   lliof     ! local definition of ldiof
       INTEGER               ::   iolib     ! library do we use to open the file
       INTEGER               ::   icnt      ! counter for digits in clcpu (max = jpmax_digits)
@@ -85,12 +142,22 @@
       ! Initializations and control
       ! =============
+      kiomid = -1
       clinfo = '                    iom_open ~~~  '
       istop = nstop
       ! if iom_open is called for the first time: initialize iom_file(:)%nfid to 0
       ! (could be done when defining iom_file in f95 but not in f90)
-      IF( iom_init == 0 ) THEN
+#if ! defined key_agrif
+      IF( iom_open_init == 0 ) THEN
          iom_file(:)%nfid = 0
-         iom_init = 1
-      ENDIF
+         iom_open_init = 1
+      ENDIF
+#else
+      IF( Agrif_Root() ) THEN
+         IF( iom_open_init == 0 ) THEN
+            iom_file(:)%nfid = 0
+            iom_open_init = 1
+         ENDIF
+      ENDIF
+#endif
       ! do we read or write the file?
       IF( PRESENT(ldwrt) ) THEN   ;   llwrt = ldwrt
@@ -105,14 +172,16 @@
       ELSE                         ;   iolib = jpnf90
       ENDIF
+      ! are we using interpolation on the fly?
+      IF( PRESENT(ldiof) ) THEN   ;   lliof = ldiof
+      ELSE                        ;   lliof = .FALSE.
+      ENDIF
       ! do we read the overlap 
       ! ugly patch SM+JMM+RB to overwrite global definition in some cases
-#if ! defined key_agrif
-      llnoov = (jpni * jpnj ) == jpnij
-#endif
+      llnoov = (jpni * jpnj ) == jpnij 
       ! create the file name by added, if needed, TRIM(Agrif_CFixed()) and TRIM(clsuffix)
       ! =============
       clname   = trim(cdname)
 #if defined key_agrif
-      IF ( .NOT. Agrif_Root() ) THEN
+      IF ( .NOT. Agrif_Root() .AND. .NOT. lliof ) THEN
          iln    = INDEX(clname,'/') 
          cltmpn = clname(1:iln)
@@ -239,4 +308,7 @@
          i_s = 1
          i_e = jpmax_files
+#if defined key_iomput
+         CALL event__stop_ioserver
+#endif
       ENDIF
 
@@ -451,7 +523,5 @@
       ! do we read the overlap 
       ! ugly patch SM+JMM+RB to overwrite global definition in some cases
-#if ! defined key_agrif
-      llnoov = (jpni * jpnj ) == jpnij
-#endif
+      llnoov = (jpni * jpnj ) == jpnij 
       ! check kcount and kstart optionals parameters...
       IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
@@ -819,5 +889,131 @@
       ENDIF
    END SUBROUTINE iom_rp3d
+
+
    !!----------------------------------------------------------------------
+   !!                   INTERFACE iom_rstput
+   !!----------------------------------------------------------------------
+   SUBROUTINE iom_p2d( cdname, pfield2d )
+      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pfield2d
+#if defined key_iomput
+      CALL event__write_field2D( cdname, pfield2d(nldi:nlei, nldj:nlej) )
+#endif
+   END SUBROUTINE iom_p2d
+
+   SUBROUTINE iom_p3d( cdname, pfield3d )
+      CHARACTER(LEN=*)                , INTENT(in) ::   cdname
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in) ::   pfield3d
+#if defined key_iomput
+      CALL event__write_field3D( cdname, pfield3d(nldi:nlei, nldj:nlej, :) )
+#endif
+   END SUBROUTINE iom_p3d
+   !!----------------------------------------------------------------------
+
+
+#if defined key_iomput
+
+   SUBROUTINE set_grid( cdname, plon, plat )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE   ***
+      !!
+      !! ** Purpose :   
+      !!
+      !!----------------------------------------------------------------------
+      CHARACTER(LEN=*)            , INTENT(in) ::   cdname
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plon
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat
+
+      CALL event__set_grid_dimension( cdname, jpiglo, jpjglo)
+      CALL event__set_grid_domain( cdname, nlei-nldi+1, nlej-nldj+1, nimpp+nldi-1, njmpp+nldj-1, &
+         &                         plon(nldi:nlei, nldj:nlej), plat(nldi:nlei, nldj:nlej) )
+      CALL event__set_grid_type_nemo( cdname )
+
+   END SUBROUTINE set_grid
+
+
+   SUBROUTINE iom_init_chkcpp
+      !!---------------------------------------------------------------------
+      !!                   ***  SUBROUTINE    ***
+      !!
+      !! ** Purpose :  
+      !!---------------------------------------------------------------------
+      USE zdfddm, ONLY :   lk_zdfddm      ! vertical  physics: double diffusion
+
+#if ! defined key_off_tra      
+#if defined key_dynspg_rl
+      CALL event__disable_field( "sossheig" )
+#else
+      CALL event__disable_field( "sobarstf" )
+#endif
+
+      !!#if ! ( ! defined key_dynspg_rl && defined key_ice_lim)
+      !!        CALL disable_field( "iowaflup" )
+      !!         CALL disable_field( "sowaflep" )
+      !!#endif
+
+#if ! defined key_coupled
+      CALL event__enable_field( "sohefldp" )
+      CALL event__enable_field( "sowafldp" )
+      CALL event__enable_field( "sosafldp" )
+#endif
+
+#if ( defined key_coupled && ! defined key_lim3 && ! defined key_lim2 ) 
+      CALL event__enable_field( "sohefldp" )
+      CALL event__enable_field( "sowafldp" )
+      CALL event__enable_field( "sosafldp" )
+#endif
+
+#if ! defined key_diaspr
+      CALL event__disable_field( "sosurfps" )
+#endif
+
+#if ! defined key_diahth
+      CALL event__disable_field( "sothedep" )
+      CALL event__disable_field( "so20chgt" )
+      CALL event__disable_field( "so28chgt" )
+      CALL event__disable_field( "sohtc300" )
+#endif
+
+#if defined key_coupled 
+# if defined key_lim3
+      Must be adapted to LIM3
+# else
+      CALL event__enable_field( "soicetem" )
+      CALL event__enable_field( "soicealb" )
+# endif 
+#endif 
+
+#if ! defined key_diaeiv
+      CALL event__disable_field( "vozoeivu" )
+      CALL event__disable_field( "vomeeivv" )
+      CALL event__disable_field( "voveeivw" )
+#endif
+
+#if ! defined key_dynspg_rl
+      CALL event__disable_field( "sozospgx" )
+      CALL event__disable_field( "somespgy" )
+#endif
+
+      IF( lk_zdfddm ) CALL event__enable_field( "voddmavs" )
+
+#if ! defined key_traldf_c2d
+      CALL event__disable_field( "soleahtw" )
+#endif
+
+#if ! defined key_traldf_eiv 
+      CALL event__disable_field( "soleaeiw" )
+#endif
+#endif
+
+   END SUBROUTINE iom_init_chkcpp
+
+#else
+
+   SUBROUTINE iom_setkt( kt )
+      INTEGER, INTENT(in   )::   kt 
+   END SUBROUTINE iom_setkt
+
+#endif
 
 
Index: /trunk/NEMO/OFF_SRC/IOM/iom_def.F90
===================================================================
--- /trunk/NEMO/OFF_SRC/IOM/iom_def.F90	(revision 1449)
+++ /trunk/NEMO/OFF_SRC/IOM/iom_def.F90	(revision 1450)
@@ -49,5 +49,5 @@
 
 !$AGRIF_DO_NOT_TREAT
-   INTEGER, PUBLIC            ::   iom_init = 0        !: used to initialize iom_file(:)%nfid to 0
+   INTEGER, PUBLIC            ::   iom_open_init = 0   !: used to initialize iom_file(:)%nfid to 0
 
    TYPE, PUBLIC ::   file_descriptor
Index: /trunk/NEMO/OFF_SRC/daymod.F90
===================================================================
--- /trunk/NEMO/OFF_SRC/daymod.F90	(revision 1449)
+++ /trunk/NEMO/OFF_SRC/daymod.F90	(revision 1450)
@@ -30,4 +30,5 @@
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
+   USE ioipsl, ONLY :   ymds2ju        ! for calendar
 
    IMPLICIT NONE
@@ -46,4 +47,5 @@
    REAL(wp), PUBLIC ::   rsec_day    !: current time step counted in second since 00h of the current day
 
+   REAL(wp), PUBLIC ::   fjulday     !: julian day
    REAL(wp), PUBLIC ::   adatrj      !: number of elapsed days since the begining of the run
    !                                 !: it is the accumulated duration of previous runs
@@ -95,4 +97,8 @@
       nmonth  = ( ndastp - (nyear * 10000) ) / 100
       nday    =   ndastp - (nyear * 10000) - ( nmonth * 100 ) 
+
+      CALL ymds2ju( nyear, nmonth, nday, 0.0, fjulday )  ! we assume that we start run at 00:00
+      fjulday = fjulday + 1.                             ! move back to the day at nit000 (and not at nit000 - 1)
+
 
       sec1jan000 = 0.e0
@@ -203,5 +209,6 @@
       rsec_day   = rsec_day   + rdttra(1)                 
       adatrj = adatrj + rdttra(1) / rday
-      
+      fjulday = fjulday + rdttra(1) / rday
+   
       IF( rsec_day > rday ) THEN                        ! NEW day
          !
Index: /trunk/NEMO/OFF_SRC/opa.F90
===================================================================
--- /trunk/NEMO/OFF_SRC/opa.F90	(revision 1449)
+++ /trunk/NEMO/OFF_SRC/opa.F90	(revision 1450)
@@ -29,4 +29,9 @@
    USE trcini          ! Initilization of the passive tracers
    USE step            ! OPA time-stepping                  (stp     routine)
+
+   USE iom
+#if defined key_iomput
+   USE  mod_ioclient
+#endif 
 
    IMPLICIT NONE
@@ -130,6 +135,11 @@
       !!----------------------------------------------------------------------
       !! * Local declarations
+#if defined key_iomput
+      INTEGER :: localComm
+#endif
       CHARACTER (len=20) ::   namelistname
       CHARACTER (len=28) ::   file_out
+      NAMELIST/namctl/ ln_ctl, nprint, nictls, nictle,   &
+         &             isplt , jsplt , njctls, njctle, nbench
 
       !!----------------------------------------------------------------------
@@ -156,6 +166,17 @@
       WRITE(numout,*)
 
+      ! Namelist namctl : Control prints & Benchmark
+      REWIND( numnam )
+      READ  ( numnam, namctl )
+
+#if defined key_iomput
+      CALL init_ioclient(localcomm)
+      narea = mynode(localComm)
+#else
       ! Nodes selection
       narea = mynode()
+#endif
+
+      ! Nodes selection
       narea = narea + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
       lwp   = narea == 1
@@ -180,4 +201,6 @@
       ENDIF
 
+      CALL opa_flg                          ! Control prints & Benchmark
+
       !                                     ! ============================== !
       !                                     !  Model general initialization  !
@@ -212,4 +235,5 @@
       CALL ldf_tra_init                         ! Lateral ocean tracer physics
 #endif 
+      CALL iom_init( fjulday - adatrj )     ! iom_put initialization
       !                                     ! =============== !
       !                                     !  time stepping  !
@@ -220,4 +244,96 @@
    END SUBROUTINE opa_init
 
+   SUBROUTINE opa_flg
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa  ***
+      !!
+      !! ** Purpose :   Initialize logical flags that control the choice of
+      !!      some algorithm or control print
+      !!
+      !! ** Method  :    Read in namilist namflg logical flags
+      !!
+      !! History :
+      !!   9.0  !  03-11  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'opa_flg: Control prints & Benchmark'
+         WRITE(numout,*) '~~~~~~~ '
+         WRITE(numout,*) '          Namelist namctl'
+         WRITE(numout,*) '             run control (for debugging)     ln_ctl    = ', ln_ctl
+         WRITE(numout,*) '             level of print                  nprint    = ', nprint
+         WRITE(numout,*) '             Start i indice for SUM control  nictls    = ', nictls
+         WRITE(numout,*) '             End i indice for SUM control    nictle    = ', nictle
+         WRITE(numout,*) '             Start j indice for SUM control  njctls    = ', njctls
+         WRITE(numout,*) '             End j indice for SUM control    njctle    = ', njctle
+         WRITE(numout,*) '             number of proc. following i     isplt     = ', isplt
+         WRITE(numout,*) '             number of proc. following j     jsplt     = ', jsplt
+         WRITE(numout,*) '             benchmark parameter (0/1)       nbench    = ', nbench
+      ENDIF
+
+      ! ... Control the sub-domain area indices for the control prints
+      IF( ln_ctl )   THEN
+         IF( lk_mpp )   THEN
+            ! the domain is forced to the real splitted domain in MPI
+            isplt = jpni ; jsplt = jpnj ; ijsplt = jpni*jpnj
+         ELSE
+            IF( isplt == 1 .AND. jsplt == 1  ) THEN
+               CALL ctl_warn( '          - isplt & jsplt are equal to 1',   &
+                    &         '          - the print control will be done over the whole domain' )
+            ENDIF
+
+            ! compute the total number of processors ijsplt
+            ijsplt = isplt*jsplt
+         ENDIF
+
+         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
+         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
+
+         ! Control the indices used for the SUM control
+         IF( nictls+nictle+njctls+njctle == 0 )   THEN
+            ! the print control is done over the default area
+            lsp_area = .FALSE.
+         ELSE
+            ! the print control is done over a specific  area
+            lsp_area = .TRUE.
+            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
+               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
+               nictls = 1
+            ENDIF
+
+            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
+               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
+               nictle = jpiglo
+            ENDIF
+
+            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
+               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
+               njctls = 1
+            ENDIF
+
+            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
+               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
+               njctle = jpjglo
+            ENDIF
+
+         ENDIF          ! IF( nictls+nictle+njctls+njctle == 0 )
+       ENDIF            ! IF(ln_ctl)
+
+      IF( nbench == 1 )   THEN
+         SELECT CASE ( cp_cfg )
+         CASE ( 'gyre' )
+            CALL ctl_warn( '          The Benchmark is activated ' )
+         CASE DEFAULT
+            CALL ctl_stop( '          The Benchmark is based on the GYRE configuration: key_gyre must &
+               &                      be used or set nbench = 0' )
+         END SELECT
+      ENDIF
+
+   END SUBROUTINE opa_flg
+
    SUBROUTINE opa_closefile
       !!----------------------------------------------------------------------
@@ -243,4 +359,6 @@
       IF(lwp) CLOSE( numstp )   ! time-step file
 
+      CALL iom_close            ! close all input/output files
+
    END SUBROUTINE opa_closefile
 
Index: /trunk/NEMO/TOP_SRC/trcdia.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/trcdia.F90	(revision 1449)
+++ /trunk/NEMO/TOP_SRC/trcdia.F90	(revision 1450)
@@ -29,4 +29,5 @@
    USE lib_mpp
    USE ioipsl
+   USE iom
 
    IMPLICIT NONE
@@ -117,4 +118,6 @@
       ! --------------
 
+      CALL iom_setkt( kt + ndttrc - 1 )
+
       ! local variable for debugging
       ll_print = .FALSE.                  ! change it to true for more control print
@@ -207,8 +210,7 @@
 
       DO jn = 1, jptra
-         IF( lutsav(jn) ) THEN
-            cltra = ctrcnm(jn)      ! short title for tracer
-            CALL histwrite( nit5, cltra, it, trn(:,:,:,jn), ndimt50, ndext50 )
-         ENDIF
+         cltra = ctrcnm(jn)      ! short title for tracer
+         IF( lutsav(jn) ) CALL histwrite( nit5, cltra, it, trn(:,:,:,jn), ndimt50, ndext50 )
+         CALL iom_put( ctrcnm(jn), trn(:,:,:,jn) )
       END DO
 
@@ -217,4 +219,6 @@
       IF( kt == nitend .OR. kindic < 0 )   CALL histclo( nit5 )
       !
+      CALL iom_setkt( kt )
+
    END SUBROUTINE trcdit_wr
 
@@ -252,4 +256,6 @@
       ! 0. Initialisation
       ! -----------------
+      
+      CALL iom_setkt( kt + ndttrc - 1 )
 
       ! local variable for debugging
@@ -439,4 +445,5 @@
             END DO
          END IF
+         CALL iom_put( ctrcnm(jn), trn(:,:,:,jn) )
       END DO
 
@@ -449,4 +456,6 @@
       ENDIF
       !
+      CALL iom_setkt( kt )
+
    END SUBROUTINE trcdid_wr
 
@@ -484,5 +493,5 @@
       CHARACTER (len=20) ::   cltra, cltrau
       CHARACTER (len=80) ::   cltral
-      INTEGER  ::   jn
+      INTEGER  ::   jl
       INTEGER  ::   iimi, iima, ijmi, ijma, ipk, it, itmod
       REAL(wp) ::   zsto, zout, zdt
@@ -491,5 +500,7 @@
       ! Initialisation
       ! --------------
-
+   
+      CALL iom_setkt( kt + ndttrc - 1 )
+      
       ! local variable for debugging
       ll_print = .FALSE.
@@ -546,8 +557,8 @@
 
          ! more 3D horizontal arrays
-         DO jn = 1, jpdia3d
-            cltra  = ctrc3d(jn)   ! short title for 3D diagnostic
-            cltral = ctrc3l(jn)   ! long title for 3D diagnostic
-            cltrau = ctrc3u(jn)   ! UNIT for 3D diagnostic
+         DO jl = 1, jpdia3d
+            cltra  = ctrc3d(jl)   ! short title for 3D diagnostic
+            cltral = ctrc3l(jl)   ! long title for 3D diagnostic
+            cltrau = ctrc3u(jl)   ! UNIT for 3D diagnostic
             CALL histdef( nitd, cltra, cltral, cltrau, jpi, jpj, nhoritd,   &
                &          ipk, 1, ipk,  ndepitd, 32, clop, zsto, zout )
@@ -555,8 +566,8 @@
 
          ! more 2D horizontal arrays
-         DO jn = 1, jpdia2d
-            cltra  = ctrc2d(jn)    ! short title for 2D diagnostic
-            cltral = ctrc2l(jn)   ! long title for 2D diagnostic
-            cltrau = ctrc2u(jn)   ! UNIT for 2D diagnostic
+         DO jl = 1, jpdia2d
+            cltra  = ctrc2d(jl)    ! short title for 2D diagnostic
+            cltral = ctrc2l(jl)   ! long title for 2D diagnostic
+            cltrau = ctrc2u(jl)   ! UNIT for 2D diagnostic
             CALL histdef( nitd, cltra, cltral, cltrau, jpi, jpj, nhoritd,  &
                &          1, 1, 1,  -99, 32, clop, zsto, zout )
@@ -583,13 +594,15 @@
 
       ! more 3D horizontal arrays
-      DO jn = 1, jpdia3d
-         cltra = ctrc3d(jn)   ! short title for 3D diagnostic
-         CALL histwrite( nitd, cltra, it, trc3d(:,:,:,jn), ndimt50 ,ndext50)
+      DO jl = 1, jpdia3d
+         cltra = ctrc3d(jl)   ! short title for 3D diagnostic
+         CALL histwrite( nitd, cltra, it, trc3d(:,:,:,jl), ndimt50 ,ndext50)
+         CALL iom_put( cltra, trc3d(:,:,:,jl) )
       END DO
 
       ! more 2D horizontal arrays
-      DO jn = 1, jpdia2d
-         cltra = ctrc2d(jn)   ! short title for 2D diagnostic
-         CALL histwrite(nitd, cltra, it, trc2d(:,:,jn), ndimt51  ,ndext51)
+      DO jl = 1, jpdia2d
+         cltra = ctrc2d(jl)   ! short title for 2D diagnostic
+         CALL histwrite(nitd, cltra, it, trc2d(:,:,jl), ndimt51  ,ndext51)
+         CALL iom_put( cltra, trc2d(:,:,jl) )
       END DO
 
@@ -598,4 +611,6 @@
       IF( kt == nitend .OR. kindic < 0 )   CALL histclo(nitd)
       !
+      CALL iom_setkt( kt )
+
    END SUBROUTINE trcdii_wr
 
@@ -634,5 +649,5 @@
       CHARACTER (len=20) ::   cltra, cltrau
       CHARACTER (len=80) ::   cltral
-      INTEGER  ::   ji, jj, jk, jn
+      INTEGER  ::   ji, jj, jk, jl
       INTEGER  ::   iimi, iima, ijmi, ijma, ipk, it, itmod
       REAL(wp) ::   zsto, zout, zdt
@@ -642,4 +657,6 @@
       ! --------------
 
+      CALL iom_setkt( kt + ndttrc - 1 )
+      
       ! local variable for debugging
       ll_print = .FALSE.
@@ -689,8 +706,8 @@
          ! Declare all the output fields as NETCDF variables
          ! biological trends
-         DO jn = 1, jpdiabio
-            cltra  = ctrbio(jn)   ! short title for biological diagnostic
-            cltral = ctrbil(jn)   ! long title for biological diagnostic
-            cltrau = ctrbiu(jn)   ! UNIT for biological diagnostic
+         DO jl = 1, jpdiabio
+            cltra  = ctrbio(jl)   ! short title for biological diagnostic
+            cltral = ctrbil(jl)   ! long title for biological diagnostic
+            cltrau = ctrbiu(jl)   ! UNIT for biological diagnostic
             CALL histdef( nitb, cltra, cltral, cltrau, jpi, jpj, nhoritb,  &
                &         ipk, 1, ipk,  ndepitb, 32, clop, zsto, zout)
@@ -715,7 +732,8 @@
       ENDIF
 
-      DO jn = 1, jpdiabio
-         cltra = ctrbio(jn)  ! short title for biological diagnostic
-         CALL histwrite(nitb, cltra, it, trbio(:,:,:,jn), ndimt50,ndext50)
+      DO jl = 1, jpdiabio
+         cltra = ctrbio(jl)  ! short title for biological diagnostic
+         CALL histwrite(nitb, cltra, it, trbio(:,:,:,jl), ndimt50,ndext50)
+         CALL iom_put( cltra, trbio(:,:,:,jl) )
       END DO
 
@@ -724,4 +742,6 @@
       IF( kt == nitend .OR. kindic < 0 )   CALL histclo( nitb )
       !
+      CALL iom_setkt( kt )
+
    END SUBROUTINE trcdib_wr
 
