Index: /trunk/NEMO/TOP_SRC/oce_trc.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/oce_trc.F90	(revision 1010)
+++ /trunk/NEMO/TOP_SRC/oce_trc.F90	(revision 1011)
@@ -166,9 +166,8 @@
    USE dom_oce , ONLY :   n_cla     =>   n_cla         !: flag (0/1) for cross land advection 
 
-
-
    !* surface fluxes *
    USE sbc_oce , ONLY :   utau       =>    utau       !: i-surface stress component
    USE sbc_oce , ONLY :   vtau       =>    vtau       !: j-surface stress component
+   USE sbc_oce , ONLY :   wndm       =>    wndm       !: 10m wind speed 
    USE sbc_oce , ONLY :   qsr        =>    qsr        !: penetrative solar radiation (w m-2)  
    USE sbc_oce , ONLY :   emp        =>    emp        !: evaporation minus precipitation (kg m-2 s-2) 
Index: /trunk/NEMO/TOP_SRC/trcdia.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/trcdia.F90	(revision 1010)
+++ /trunk/NEMO/TOP_SRC/trcdia.F90	(revision 1011)
@@ -4,5 +4,10 @@
    !! TOP :   Output of passive tracers
    !!======================================================================
-   !! History :   1.0  !  2005-03 (O. Aumont, A. El Moussaoui) original code
+   !! History :    -   !  1995-01 (M. Levy)  Original code
+   !!              -   !  1998-01 (C. Levy) NETCDF format using ioipsl interface
+   !!              -   !  1999-01 (M.A. Foujols) adapted for passive tracer
+   !!              -   !  1999-09 (M.A. Foujols) split into three parts
+   !!             1.0  !  2005-03 (O. Aumont, A. El Moussaoui) F90
+   !!                  !  2008-05 (C. Ethe re-organization)
    !!----------------------------------------------------------------------
 #if defined key_top
@@ -10,13 +15,47 @@
    !!   'key_top'                                                TOP models
    !!----------------------------------------------------------------------
-   !!   trc_dia    :  output passive tracer fields
+   !! trc_dia     : main routine of output passive tracer
+   !! trcdit_wr   : outputs of concentration fields
+   !! trcdid_wr   : outputs of dvection-diffusion trends
+   !! trcdii_wr   : outputs of additional 2D/3D diagnostics
+   !! trcdib_wr   : outputs of biological fields
    !!----------------------------------------------------------------------
-   USE trcdit
+   USE oce_trc
+   USE trc
+   USE dianam    ! build name of file (routine)
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp
+   USE ioipsl
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC trc_dia      ! called by ???
-
+   PUBLIC trc_dia      
+
+   INTEGER  ::   nit5      !: id for tracer output file
+   INTEGER  ::   ndepit5   !: id for depth mesh
+   INTEGER  ::   nhorit5   !: id for horizontal mesh
+   INTEGER  ::   ndimt50   !: number of ocean points in index array
+   INTEGER  ::   ndimt51   !: number of ocean points in index array
+   REAL(wp) ::   zjulian   !: ????   not DOCTOR !
+   INTEGER , DIMENSION (jpij*jpk) ::   ndext50   !: integer arrays for ocean 3D index
+   INTEGER , DIMENSION (jpij)     ::   ndext51   !: integer arrays for ocean surface index
+# if defined key_trc_diaadd
+   INTEGER  ::   nitd      !: id for additional array output file
+   INTEGER  ::   ndepitd   !: id for depth mesh
+   INTEGER  ::   nhoritd   !: id for horizontal mesh
+# endif
+# if defined key_trc_diatrd
+   INTEGER , DIMENSION (jptra) ::   nit6      !: id for additional array output file
+   INTEGER , DIMENSION (jptra) ::   ndepit6   !: id for depth mesh
+   INTEGER , DIMENSION (jptra) ::   nhorit6   !: id for horizontal mesh
+# endif
+# if defined key_trc_diabio
+   INTEGER  ::   ndepitb   !:  id for depth mesh
+   INTEGER  ::   nhoritb   !:  id for horizontal mesh
+# endif
+
+   !! * Substitutions
+#  include "top_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
@@ -37,18 +76,672 @@
       
       CALL trcdit_wr( kt, kindic )      ! outputs for tracer concentration
-
-# if defined key_trc_diatrd
+      
+
       CALL trcdid_wr( kt, kindic )      ! outputs for dynamical trends
-# endif
-
-# if defined key_trc_diaadd
+
+      
       CALL trcdii_wr( kt, kindic )      ! outputs for additional arrays
-# endif
-
-# if defined key_trc_diabio
+
+      
       CALL trcdib_wr( kt, kindic )      ! outputs for biological trends
-# endif
+
       !
    END SUBROUTINE trc_dia
+
+   SUBROUTINE trcdit_wr( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trcdit_wr  ***
+      !!
+      !! ** Purpose :   Standard output of passive tracer : concentration fields
+      !!
+      !! ** Method  :   At the beginning of the first time step (nit000), define all
+      !!             the NETCDF files and fields for concentration of passive tracer
+      !!
+      !!        At each time step call histdef to compute the mean if necessary
+      !!        Each nwritetrc time step, output the instantaneous or mean fields
+      !!
+      !!        IF kindic <0, output of fields before the model interruption.
+      !!        IF kindic =0, time step loop
+      !!        IF kindic >0, output of fields before the time step loop
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step
+      INTEGER, INTENT( in ) ::   kindic      ! indicator of abnormal termination
+      !!
+      INTEGER ::   jn
+      LOGICAL ::   ll_print = .FALSE.
+      CHARACTER (len=40) :: clhstnam, clop
+      CHARACTER (len=20) :: cltra, cltrau
+      CHARACTER (len=80) :: cltral
+      REAL(wp) :: zsto, zout, zdt
+      INTEGER  :: iimi, iima, ijmi, ijma, ipk, it
+      !!----------------------------------------------------------------------
+
+      ! Initialisation
+      ! --------------
+
+      ! local variable for debugging
+      ll_print = .FALSE.                  ! change it to true for more control print
+      ll_print = ll_print .AND. lwp
+
+      ! Define frequency of output and means
+      zdt = rdt
+# if defined key_diainstant
+      zsto = nwritetrc * rdt
+      clop = 'inst(only(x))'
+# else
+      zsto = zdt
+      clop = 'ave(only(x))'
+# endif
+      zout = nwritetrc * zdt
+
+      ! Define indices of the horizontal output zoom and vertical limit storage
+      iimi = 1      ;      iima = jpi
+      ijmi = 1      ;      ijma = jpj
+      ipk = jpk
+
+      ! define time axis
+      it = kt - nittrc000 + 1
+
+      ! Define NETCDF files and fields at beginning of first time step
+      ! --------------------------------------------------------------
+
+      IF(ll_print)WRITE(numout,*)'trcdit_wr kt=',kt,' kindic ',kindic
+      
+      IF( kt == nittrc000 ) THEN
+
+         ! Compute julian date from starting date of the run
+         CALL ymds2ju( nyear, nmonth, nday, 0.0, zjulian )
+         IF(lwp)WRITE(numout,*)' '  
+         IF(lwp)WRITE(numout,*)' Date 0 used :', nittrc000                         &
+            &                 ,' YEAR ', nyear, ' MONTH ', nmonth, ' DAY ', nday   &
+            &                 ,'Julian day : ', zjulian    
+         IF(lwp) WRITE(numout,*) ' indexes of zoom = ', iimi, iima, ijmi, ijma,  &
+            &                    ' limit storage in depth = ', ipk
+
+
+! Define the NETCDF files for passive tracer concentration
+
+         CALL dia_nam( clhstnam, nwritetrc, 'ptrc_T' )
+         IF(lwp)WRITE(numout,*)" Name of NETCDF file ", clhstnam
+! Horizontal grid : glamt and gphit
+         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,     &
+            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,         & 
+            &          0, zjulian, zdt, nhorit5, nit5 , domain_id=nidom)
+! Vertical grid for tracer : gdept
+         CALL histvert( nit5, 'deptht', 'Vertical T levels', &
+            &            'm', ipk, gdept_0, ndepit5)
+
+! Index of ocean points in 3D and 2D (surface)
+         CALL wheneq( jpi*jpj*ipk,tmask,1,1.,ndext50,ndimt50 )
+         CALL wheneq( jpi*jpj,tmask,1,1.,ndext51,ndimt51 )
+
+! Declare all the output fields as NETCDF variables
+
+! tracer concentrations
+         DO jn = 1, jptra
+            IF( lutsav(jn) ) THEN
+               cltra  = ctrcnm(jn)   ! short title for tracer
+               cltral = ctrcnl(jn)   ! long title for tracer
+               cltrau = ctrcun(jn)   ! UNIT for tracer
+               CALL histdef( nit5, cltra, cltral, cltrau, jpi, jpj, nhorit5,  &
+                  &               ipk, 1, ipk,  ndepit5, 32, clop, zsto, zout) 
+            ENDIF
+         END DO
+
+         ! end netcdf files header
+         CALL histend( nit5 )
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdit_wr'
+         IF( ll_print )   CALL FLUSH(numout )
+
+      ENDIF
+
+      ! Start writing the tracer concentrations
+      ! ---------------------------------------
+
+      IF( lwp .AND. MOD( kt, nwritetrc ) == 0 ) THEN
+         WRITE(numout,*) 'trcdit_wr : write NetCDF passive tracer concentrations at ', kt, 'time-step'
+         WRITE(numout,*) '~~~~~~~~~ '
+      ENDIF
+
+      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
+      END DO
+
+      ! synchronise file
+      IF( MOD( kt, nwritetrc ) == 0 .OR. kindic < 0 )   CALL histsync( nit5 )
+
+
+      ! close the file 
+      ! --------------
+      IF( kt == nitend .OR. kindic < 0 )   CALL histclo( nit5 )
+      !
+   END SUBROUTINE trcdit_wr
+
+# if defined key_trc_diatrd
+
+   SUBROUTINE trcdid_wr( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trcdid_wr  ***
+      !!
+      !! ** Purpose :   output of passive tracer : advection-diffusion trends
+      !!
+      !! ** Method  :   At the beginning of the first time step (nit000), define all
+      !!             the NETCDF files and fields for concentration of passive tracer
+      !!
+      !!        At each time step call histdef to compute the mean if necessary
+      !!        Each nwritetrc time step, output the instantaneous or mean fields
+      !!
+      !!        IF kindic <0, output of fields before the model interruption.
+      !!        IF kindic =0, time step loop
+      !!        IF kindic >0, output of fields before the time step loop
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step
+      INTEGER, INTENT( in ) ::   kindic      ! indicator of abnormal termination
+      !!
+      LOGICAL ::   ll_print = .FALSE.
+      CHARACTER (len=40) ::   clhstnam, clop
+      CHARACTER (len=20) ::   cltra, cltrau
+      CHARACTER (len=80) ::   cltral
+      CHARACTER (len=10) ::   csuff
+      INTEGER  ::   jn, jl
+      INTEGER  ::   iimi, iima, ijmi, ijma, ipk, it
+      REAL(wp) ::   zsto, zout, zdt
+      !!----------------------------------------------------------------------
+
+      ! 0. Initialisation
+      ! -----------------
+
+      ! local variable for debugging
+      ll_print = .FALSE.
+      ll_print = ll_print .AND. lwp
+      !
+      ! Define frequency of output and means
+      zdt = rdt
+#  if defined key_diainstant
+      zsto = nwritetrd * rdt
+      clop = 'inst(only(x))'
+#  else
+      zsto = zdt
+      clop = 'ave(only(x))'
+#  endif
+      zout = nwritetrd * zdt
+
+      ! Define indices of the horizontal output zoom and vertical limit storage
+      iimi = 1      ;      iima = jpi
+      ijmi = 1      ;      ijma = jpj
+      ipk = jpk
+
+      ! define time axis
+      it = kt - nittrc000 + 1
+
+      ! Define the NETCDF files (one per tracer)
+      IF( ll_print ) WRITE(numout,*) 'trcdid kt=', kt, ' kindic ', kindic
+      
+      
+      IF( kt == nittrc000 ) THEN
+
+         DO jn = 1, jptra
+            !
+            IF( luttrd(jn) ) THEN      ! Define the file for dynamical trends - one per each tracer IF required
+
+               IF(lwp)WRITE(numout,*) ' indexes of zoom = ', iimi, iima, ijmi, ijma,  &
+                   &                   ' limit storage in depth = ', ipk
+               csuff='DY_'//ctrcnm(jn)
+               CALL dia_nam( clhstnam, nwritetrd, csuff )
+               IF(lwp)WRITE(numout,*)   " Name of NETCDF file for dynamical trends",   &
+                  &                     " of tracer number : ",clhstnam
+
+               CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,       &
+                  &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,   &
+                  &          0, zjulian, rdt, nhorit6(jn),           &
+                  &          nit6(jn) , domain_id=nidom )
+
+               ! Vertical grid for tracer trend - one per each tracer IF needed
+               CALL histvert( nit6(jn), 'deptht', 'Vertical T levels',   &
+                  &           'm', ipk, gdept_0, ndepit6(jn) ) 
+             END IF
+          END DO
+
+          ! Declare all the output fields as NETCDF variables
+
+          ! trends for tracer concentrations
+          DO jn = 1, jptra
+            IF( luttrd(jn) ) THEN
+                DO jl = 1, jpdiatrc
+                  IF( jl == 1 ) THEN
+                      ! short and long title for x advection for tracer
+                      WRITE (cltra,'("XAD_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("X advective trend for ",58a)')  &
+                         &      ctrcnl(jn)(1:58)
+                  END IF
+                  IF( jl == 2 ) THEN
+                      ! short and long title for y advection for tracer
+                      WRITE (cltra,'("YAD_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Y advective trend for ",58a)')  &
+                         &      ctrcnl(jn)(1:58)
+                  END IF
+                  IF( jl == 3 ) THEN
+                      ! short and long title for Z advection for tracer
+                      WRITE (cltra,'("ZAD_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Z advective trend for ",58a)')  &
+                         &      ctrcnl(jn)(1:58)
+                  END IF
+                  IF( jl == 4 ) THEN
+                      ! short and long title for X diffusion for tracer
+                      WRITE (cltra,'("XDF_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("X diffusion trend for ",58a)')  &
+                         &      ctrcnl(jn)(1:58)
+                  END IF
+                  IF( jl == 5 ) THEN
+                      ! short and long title for Y diffusion for tracer
+                      WRITE (cltra,'("YDF_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Y diffusion trend for ",58a)')  &
+                         &      ctrcnl(jn)(1:58)
+                  END IF
+                  IF( jl == 6 ) THEN
+                      ! short and long title for Z diffusion for tracer
+                      WRITE (cltra,'("ZDF_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Z diffusion trend for ",58a)')  &
+                         &      ctrcnl(jn)(1:58)
+                  END IF
+# if defined key_trc_ldfeiv
+                  IF( jl == 7 ) THEN
+                      ! short and long title for x gent velocity for tracer
+                      WRITE (cltra,'("XGV_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("X gent velocity trend for ",53a)')  &
+                         &      ctrcnl(jn)(1:53)
+                  END IF
+                  IF( jl == 8 ) THEN
+                      ! short and long title for y gent velocity for tracer
+                      WRITE (cltra,'("YGV_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Y gent velocity trend for ",53a)')  &
+                         &      ctrcnl(jn)(1:53)
+                  END IF
+                  IF( jl == 9 ) THEN
+                      ! short and long title for Z gent velocity for tracer
+                      WRITE (cltra,'("ZGV_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Z gent velocity trend for ",53a)')  &
+                         &      ctrcnl(jn)(1:53)
+                  END IF
+# endif
+# if defined key_trcdmp
+                  IF( jl == jpdiatrc - 1 ) THEN
+                      ! last trends for tracer damping : short and long title
+                      WRITE (cltra,'("TDM_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Tracer damping trend for ",55a)')  &
+                         &      ctrcnl(jn)(1:55)
+                  END IF
+# endif
+                  IF( jl == jpdiatrc ) THEN
+                      ! last trends for tracer damping : short and long title
+                      WRITE (cltra,'("SBC_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Surface boundary flux ",58a)')  &
+                      &      ctrcnl(jn)(1:58)
+                  END IF
+
+                  CALL FLUSH( numout )
+                  cltrau = ctrcun(jn)      ! UNIT for tracer /trends
+                  CALL histdef( nit6(jn), cltra, cltral, cltrau, jpi,jpj,  &
+                     &          nhorit6(jn), ipk, 1, ipk,  ndepit6(jn), 32, clop ,  &
+                     &          zsto,zout )
+               END DO
+            END IF
+         END DO
+
+         ! CLOSE netcdf Files
+          DO jn = 1, jptra
+             IF( luttrd(jn) )   CALL histend( nit6(jn) )
+          END DO
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdid'
+         IF(ll_print) CALL FLUSH(numout )
+         !
+      ENDIF
+
+      ! SOME diagnostics to DO first time
+
+      ! Start writing data
+      ! ---------------------
+
+      ! trends for tracer concentrations
+
+      IF( lwp .AND. MOD( kt, nwritetrd ) == 0 ) THEN
+         WRITE(numout,*) 'trcdid_wr : write NetCDF dynamical trends at ', kt, 'time-step'
+         WRITE(numout,*) '~~~~~~ '
+      ENDIF
+
+      DO jn = 1, jptra
+         IF( luttrd(jn) ) THEN
+            DO jl = 1, jpdiatrc
+               ! short titles 
+               IF( jl == 1)   WRITE (cltra,'("XAD_",16a)') ctrcnm(jn)      ! x advection for tracer
+               IF( jl == 2)   WRITE (cltra,'("YAD_",16a)') ctrcnm(jn)      ! z advection for tracer
+               IF( jl == 3)   WRITE (cltra,'("ZAD_",16a)') ctrcnm(jn)      ! z advection for tracer
+               IF( jl == 4)   WRITE (cltra,'("XDF_",16a)') ctrcnm(jn)      ! x diffusion for tracer
+               IF( jl == 5)   WRITE (cltra,'("YDF_",16a)') ctrcnm(jn)      ! y diffusion for tracer
+               IF( jl == 6)   WRITE (cltra,'("ZDF_",16a)') ctrcnm(jn)      ! z diffusion for tracer
+# if defined key_trcldf_eiv
+               IF( jl == 7)   WRITE (cltra,'("XGV_",16a)') ctrcnm(jn)      ! x gent velocity for tracer
+               IF( jl == 8)   WRITE (cltra,'("YGV_",16a)') ctrcnm(jn)      ! y gent velocity for tracer
+               IF( jl == 9)   WRITE (cltra,'("ZGV_",16a)') ctrcnm(jn)      ! z gent velocity for tracer
+# endif
+# if defined key_trcdmp
+               IF( jl == jpdiatrc - 1 )   WRITE (cltra,'("TDM_",16a)') ctrcnm(jn)      ! damping
+# endif
+               IF( jl == jpdiatrc )   WRITE (cltra,'("SBC_",a)') ctrcnm(jn)      ! surface boundary conditions
+               !
+               CALL histwrite(nit6(jn), cltra, it, trtrd(:,:,:,ikeep(jn),jl)   &
+                  &          ,ndimt50, ndext50)
+            END DO
+         END IF
+      END DO
+
+      ! synchronise FILE
+      IF( MOD( kt, nwritetrd ) == 0 .OR. kindic < 0 ) THEN
+         DO jn = 1, jptra
+            IF (luttrd(jn))   CALL histsync( nit6(jn) )
+         END DO
+      ENDIF
+
+      ! Closing all files
+      ! -----------------
+      IF( kt == nitend .OR. kindic < 0 ) THEN
+         DO jn = 1, jptra
+            IF( luttrd(jn) )   CALL histclo( nit6(jn) )
+         END DO
+      ENDIF
+      !
+   END SUBROUTINE trcdid_wr
+
+# else
+
+   SUBROUTINE trcdid_wr( kt, kindic )                      ! Dummy routine
+      INTEGER, INTENT ( in ) ::   kt, kindic
+   END SUBROUTINE trcdid_wr
+
+# endif
+
+#if defined key_trc_diaadd
+
+   SUBROUTINE trcdii_wr( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trcdii_wr  ***
+      !!
+      !! ** Purpose :   output of passive tracer : additional 2D and 3D arrays
+      !!
+      !! ** Method  :   At the beginning of the first time step (nit000), define all
+      !!             the NETCDF files and fields for concentration of passive tracer
+      !!
+      !!        At each time step call histdef to compute the mean if necessary
+      !!        Each nwritetrc time step, output the instantaneous or mean fields
+      !!
+      !!        IF kindic <0, output of fields before the model interruption.
+      !!        IF kindic =0, time step loop
+      !!        IF kindic >0, output of fields before the time step loop
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step
+      INTEGER, INTENT( in ) ::   kindic      ! indicator of abnormal termination
+      !!
+      LOGICAL ::   ll_print = .FALSE.
+      CHARACTER (len=40) ::   clhstnam, clop
+      CHARACTER (len=20) ::   cltra, cltrau
+      CHARACTER (len=80) ::   cltral
+      INTEGER  ::   jn
+      INTEGER  ::   iimi, iima, ijmi, ijma, ipk, it
+      REAL(wp) ::   zsto, zout, zdt
+      !!----------------------------------------------------------------------
+
+      ! Initialisation
+      ! --------------
+
+      ! local variable for debugging
+      ll_print = .FALSE.
+      ll_print = ll_print .AND. lwp
+      !
+      ! Define frequency of output and means
+      zdt = rdt
+#  if defined key_diainstant
+      zsto=nwritedia*zdt
+      clop='inst(only(x))'
+#  else
+      zsto=zdt
+      clop='ave(only(x))'
+#  endif
+      zout=nwritedia*zdt
+
+      ! Define indices of the horizontal output zoom and vertical limit storage
+      iimi = 1      ;      iima = jpi
+      ijmi = 1      ;      ijma = jpj
+      ipk = jpk
+
+      ! define time axis
+      it = kt - nittrc000 + 1
+
+      ! 1. Define NETCDF files and fields at beginning of first time step
+      ! -----------------------------------------------------------------
+
+      IF( ll_print ) WRITE(numout,*) 'trcdii_wr kt=', kt, ' kindic ', kindic
+
+      IF( kt == nittrc000 ) THEN
+
+         ! Define the NETCDF files for additional arrays : 2D or 3D
+
+         ! Define the T grid file for tracer auxiliary files
+
+         CALL dia_nam( clhstnam, nwrite, 'diad_T' )
+         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
+
+         ! Define a netcdf FILE for 2d and 3d arrays
+
+         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,             &
+            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,         &
+            &          0, zjulian, zdt, nhoritd, nitd , domain_id=nidom )
+
+         ! Vertical grid for 2d and 3d arrays
+
+         CALL histvert( nitd, 'deptht', 'Vertical T levels',   &
+            &           'm', ipk, gdept_0, ndepitd)
+
+         ! Declare all the output fields as NETCDF variables
+
+         ! 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
+            CALL histdef( nitd, cltra, cltral, cltrau, jpi, jpj, nhoritd,   &
+               &          ipk, 1, ipk,  ndepitd, 32, clop, zsto, zout )
+         END DO
+
+         ! 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
+            CALL histdef( nitd, cltra, cltral, cltrau, jpi, jpj, nhoritd,  &
+               &          1, 1, 1,  -99, 32, clop, zsto, zout )
+         END DO
+
+         ! TODO: more 2D vertical sections arrays : I or J indice fixed
+
+         ! CLOSE netcdf Files
+         CALL histend( nitd )
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdii_wr'
+         IF( ll_print )   CALL FLUSH(numout )
+         !
+      ENDIF
+
+      ! 2. Start writing data
+      ! ---------------------
+
+      IF( lwp .AND. MOD( kt, nwritedia ) == 0 ) THEN
+         WRITE(numout,*) 'trcdii_wr : write NetCDF additional arrays at ', kt, 'time-step'
+         WRITE(numout,*) '~~~~~~ '
+      ENDIF
+
+      ! 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)
+      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)
+      END DO
+
+      ! synchronise FILE
+      IF( MOD( kt, nwritedia ) == 0 .OR. kindic < 0 )   CALL histsync( nitd )
+
+      ! Closing all files
+      ! -----------------
+      IF( kt == nitend .OR. kindic < 0 )   CALL histclo(nitd)
+      !
+   END SUBROUTINE trcdii_wr
+
+# else
+
+   SUBROUTINE trcdii_wr( kt, kindic )                      ! Dummy routine
+      INTEGER, INTENT ( in ) :: kt, kindic
+   END SUBROUTINE trcdii_wr
+
+# endif
+
+# if defined key_trc_diabio
+
+   SUBROUTINE trcdib_wr( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trcdib_wr  ***
+      !!
+      !! ** Purpose :   output of passive tracer : biological fields
+      !!
+      !! ** Method  :   At the beginning of the first time step (nit000), define all
+      !!             the NETCDF files and fields for concentration of passive tracer
+      !!
+      !!        At each time step call histdef to compute the mean if necessary
+      !!        Each nwritetrc time step, output the instantaneous or mean fields
+      !!
+      !!        IF kindic <0, output of fields before the model interruption.
+      !!        IF kindic =0, time step loop
+      !!        IF kindic >0, output of fields before the time step loop
+      !!----------------------------------------------------------------------
+      USE sms
+      !!
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step
+      INTEGER, INTENT( in ) ::   kindic      ! indicator of abnormal termination
+      !!
+      LOGICAL ::   ll_print = .FALSE.
+      CHARACTER (len=40) ::   clhstnam, clop
+      CHARACTER (len=20) ::   cltra, cltrau
+      CHARACTER (len=80) ::   cltral
+      INTEGER  ::   ji, jj, jk, jn
+      INTEGER  ::   iimi, iima, ijmi, ijma, ipk, it
+      REAL(wp) ::   zsto, zout, zdt
+      !!----------------------------------------------------------------------
+
+      ! Initialisation
+      ! --------------
+
+      ! local variable for debugging
+      ll_print = .FALSE.
+      ll_print = ll_print .AND. lwp
+
+      ! Define frequency of output and means
+      zdt = rdt
+#        if defined key_diainstant
+      zsto=nwritebio*zdt
+      clop='inst(only(x))'
+#        else
+      zsto=zdt
+      clop='ave(only(x))'
+#        endif
+      zout=nwritebio*zdt
+
+      ! Define indices of the horizontal output zoom and vertical limit storage      iimi = 1      ;      iima = jpi
+      iimi = 1      ;      iima = jpi
+      ijmi = 1      ;      ijma = jpj
+      ipk = jpk
+
+      ! define time axis
+      it = kt - nittrc000 + 1
+
+      ! Define NETCDF files and fields at beginning of first time step
+      ! --------------------------------------------------------------
+
+      IF(ll_print) WRITE(numout,*)'trcdib_wr kt=',kt,' kindic ',kindic
+
+      IF( kt == nittrc000 ) THEN
+
+         ! Define the NETCDF files for biological trends
+
+         CALL dia_nam(clhstnam,nwrite,'biolog')
+         IF(lwp)WRITE(numout,*) " Name of NETCDF file for biological trends ", clhstnam
+         ! Horizontal grid : glamt and gphit
+         CALL histbeg(clhstnam, jpi, glamt, jpj, gphit,      &
+            &    iimi, iima-iimi+1, ijmi, ijma-ijmi+1,          &
+            &    0, zjulian, rdt, nhoritb, nitb , domain_id=nidom)
+         ! Vertical grid for biological trends
+         CALL histvert(nitb, 'deptht', 'Vertical T levels',  &
+            &    'm', ipk, gdept_0, ndepitb)
+
+         ! 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
+            CALL histdef(nitb, cltra, cltral, cltrau, jpi, jpj, nhoritb,  &
+               &         ipk, 1, ipk,  ndepitb, 32, clop, zsto, zout)
+         END DO
+
+         ! CLOSE netcdf Files
+          CALL histend(nitb)
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdib_wr'
+         IF(ll_print) CALL FLUSH(numout )
+         !
+      ENDIF
+
+      ! Start writing data
+      ! ------------------
+
+      ! biological trends
+      IF( lwp .AND. MOD( kt, nwritebio ) == 0 ) THEN
+         WRITE(numout,*) 'trcdit_wr : write NetCDF biological trends at ', kt, 'time-step'
+         WRITE(numout,*) '~~~~~~ '
+      ENDIF
+
+      DO jn = 1, jpdiabio
+         cltra=ctrbio(jn)  ! short title for biological diagnostic
+         CALL histwrite(nitb, cltra, it, trbio(:,:,:,jn), ndimt50,ndext50)
+      END DO
+
+      ! synchronise FILE
+      IF( MOD( kt, nwritebio ) == 0 .OR. kindic < 0 )   CALL histsync( nitb )
+
+      ! Closing all files
+      ! -----------------
+      IF( kt == nitend .OR. kindic < 0 )   CALL histclo( nitb )
+      !
+   END SUBROUTINE trcdib_wr
+
+# else
+
+   SUBROUTINE trcdib_wr( kt, kindic )                      ! Dummy routine
+      INTEGER, INTENT ( in ) ::   kt, kindic
+   END SUBROUTINE trcdib_wr
+
+# endif 
 
 #else
@@ -59,4 +752,5 @@
    SUBROUTINE trc_dia                      ! Empty routine   
    END SUBROUTINE trc_dia   
+
 #endif
 
Index: /trunk/NEMO/TOP_SRC/trcdta.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/trcdta.F90	(revision 1010)
+++ /trunk/NEMO/TOP_SRC/trcdta.F90	(revision 1011)
@@ -23,5 +23,5 @@
    PRIVATE
 
-   PUBLIC dta_trc   ! called in trcdtr.F90 and trcdmp.F90
+   PUBLIC trc_dta   ! called in trcdtr.F90 and trcdmp.F90
 
    REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk,jptra) ::   trdta   !: tracer data at given time-step
@@ -46,7 +46,7 @@
    !!----------------------------------------------------------------------
    
-   SUBROUTINE dta_trc( kt )
+   SUBROUTINE trc_dta( kt )
       !!----------------------------------------------------------------------
-      !!                   ***  ROUTINE dta_trc  ***
+      !!                   ***  ROUTINE trc_dta  ***
       !!
       !! ** Purpose :   Reads passive tracer data (Levitus monthly data)
@@ -198,5 +198,5 @@
       END DO
       !
-   END SUBROUTINE dta_trc
+   END SUBROUTINE trc_dta
 
 #else
@@ -205,7 +205,7 @@
    !!----------------------------------------------------------------------
 CONTAINS
-   SUBROUTINE dta_trc( kt )        ! Empty routine
-      WRITE(*,*) 'dta_trc: You should not have seen this print! error?', kt
-   END SUBROUTINE dta_trc
+   SUBROUTINE trc_dta( kt )        ! Empty routine
+      WRITE(*,*) 'trc_dta: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_dta
 #endif
 
Index: /trunk/NEMO/TOP_SRC/trcini.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/trcini.F90	(revision 1010)
+++ /trunk/NEMO/TOP_SRC/trcini.F90	(revision 1011)
@@ -4,62 +4,151 @@
    !! TOP :   Manage the passive tracer initialization
    !!======================================================================
-   !! History :    -   !  2000-04  (O. Aumont, M.A. Foujols)  original code
-   !!             1.0  !  2005-03  (O. Aumont, A. El Moussaoui) F90
-   !!              -   !  2005-10  (C. Ethe) Module
-   !!             2.0  !  2007-12  (C. Ethe, G. Madec) re-writing
+   !! History :    -   !  1991-03  ()  original code
+   !!             1.0  !  2005-03 (O. Aumont, A. El Moussaoui) F90
+   !!              -   !  2005-10 (C. Ethe) print control
+   !!             2.0  !  2005-10 (C. Ethe, G. Madec) revised architecture
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
    !!----------------------------------------------------------------------
    !!   trc_ini :   Initialization for passive tracer
    !!----------------------------------------------------------------------
-   USE par_trc         ! TOP parameters
+   USE oce_trc
+   USE trc
+   USE trcrst
+   USE trcctl
+   USE trclec
    USE trcini_cfc      ! CFC     initialisation
    USE trcini_lobster  ! LOBSTER initialisation
    USE trcini_pisces   ! PISCES  initialisation
    USE trcini_my_trc   ! MY_TRC  initialisation
+   USE trcdta          ! 
    USE in_out_manager  ! I/O manager
-
+   USE prtctl_trc      ! Print control passive tracers (prt_ctl_trc_init routine)
+   USE lib_mpp         ! distributed memory computing library
+   
    IMPLICIT NONE
    PRIVATE
+   
+   PUBLIC   trc_ini   ! called by opa
 
-   PUBLIC   trc_ini   ! called by ???
-
+    !! * Substitutions
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
-   !! $Header:$ 
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$ 
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
+  
+CONTAINS
+   
+   SUBROUTINE trc_ini
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_ini  ***
+      !!
+      !! ** Purpose :   Initialization of the passive tracer fields 
+      !!
+      !! ** Method  : - read namelist
+      !!              - control the consistancy 
+      !!              - compute specific initialisations
+      !!              - set initial tracer fields (either read restart 
+      !!                or read data or analytical formulation
+      !!---------------------------------------------------------------------
+      INTEGER ::   jk, jn    ! dummy loop indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zbt   ! workspace: masked grid volume
+      CHARACTER (len=25) :: charout
 
-CONTAINS
+      !!---------------------------------------------------------------------
 
-   SUBROUTINE trc_ini
-      !!-------------------------------------------------------------------
-      !!                    ***  ROUTINE trc_ini  ***
-      !!              
-      !! ** Purpose :   Initialization of passive tracer to zero
-      !!
-      !! ** Method  :   call the initialisation of each defined tracer
-      !!             model (LOBSTER, PISCES, CFC, MY_TRC)
-      !!-------------------------------------------------------------------
-      !
       IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'trc_ini : initial set up of the tracer models'
+      IF(lwp) WRITE(numout,*) 'trc_ini : initial set up of the passive tracers'
       IF(lwp) WRITE(numout,*) '~~~~~~~'
-      !
+
+      !                 ! masked grid volume
+      DO jk = 1, jpk
+         zbt(:,:,jk) = e1t(:,:) * e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:)
+      END DO
+#if defined key_off_degrad
+      DO jk = 1, jpk
+         zbt(:,:,:) = zbt(:,:,:) * facvol(:,:,jk)      ! degrad option: reduction by facvol
+      ENDDO
+#endif
+
+      !                 ! total volume of the ocean
+      areatot = SUM( zbt(:,:,:) )
+      IF( lk_mpp )   CALL mpp_sum( areatot )     ! sum over the global domain  
+
+      CALL trc_lec      ! READ passive tracers namelists
+
+      CALL trc_ctl      ! control consistency between parameters, cpp key and namelists
+
       IF( lk_lobster ) THEN   ;   CALL trc_ini_lobster      ! LOBSTER bio-model
       ELSE                    ;   IF(lwp) WRITE(numout,*) '          LOBSTER not used'
       ENDIF
-
+      
       IF( lk_pisces  ) THEN   ;   CALL trc_ini_pisces       ! PISCES  bio-model
       ELSE                    ;   IF(lwp) WRITE(numout,*) '          PISCES not used'
       ENDIF
-
+      
       IF( lk_cfc     ) THEN   ;   CALL trc_ini_cfc          ! CFC     tracers
       ELSE                    ;   IF(lwp) WRITE(numout,*) '          CFC not used'
       ENDIF
-
+      
       IF( lk_my_trc  ) THEN   ;   CALL trc_ini_my_trc       ! MY_TRC  tracers
       ELSE                    ;   IF(lwp) WRITE(numout,*) '          MY_TRC not used'
       ENDIF
+
+      IF( .NOT. lrsttr ) THEN 
+           
+# if defined key_dtatrc
+         ! Initialization of tracer from a file that may also be used for damping
+         CALL trc_dta( nittrc000 )
+         DO jn = 1, jptra
+            IF( lutini(jn) )   trn(:,:,:,jn) = trdta(:,:,:,jn) * tmask(:,:,:)   ! initialisation from file if required
+         END DO
+# endif
+         trb(:,:,:,:) = trn(:,:,:,:)
+
+      ELSE
+
+         CALL trc_rst_read      ! restart from a file
+
+      ENDIF
+
+      !                 ! Computation content of all tracers
+      trai = 0.e0
+      DO jn = 1, jptra
+         trai = trai + SUM( trn(:,:,:,jn) * zbt(:,:,:) )
+      END DO      
+      IF( lk_mpp )   CALL mpp_sum( trai )     ! sum over the global domain  
+
+
+      !                 ! control print
+      IF(lwp) WRITE(numout,*) '          *** Total number of passive tracer jptra = ', jptra
+      IF(lwp) WRITE(numout,*) '          *** Total volume of ocean                = ', areatot
+      IF(lwp) WRITE(numout,*) '          *** Total inital content of all tracers  = ', trai
+      IF(lwp) WRITE(numout,*)
+
+      IF( ln_ctl )   CALL prt_ctl_trc_init      ! control print
       !
+
+      IF(ln_ctl) THEN      ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('ini ')")
+         CALL prt_ctl_trc_info( charout )
+         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
+      ENDIF
+
    END SUBROUTINE trc_ini
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Empty module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ini                      ! Dummy routine   
+   END SUBROUTINE trc_ini
+#endif
 
    !!======================================================================
Index: /trunk/NEMO/TOP_SRC/trcrst.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/trcrst.F90	(revision 1010)
+++ /trunk/NEMO/TOP_SRC/trcrst.F90	(revision 1011)
@@ -32,4 +32,5 @@
    INTEGER, PUBLIC ::   numrtr, numrtw   !: logical unit for trc restart (read and write)
 
+#if defined key_pisces
    REAL(wp) ::  &
      alkmean = 2426. ,  & ! mean value of alkalinity ( Glodap ; for Goyet 2391. )
@@ -37,4 +38,5 @@
      no3mean = 30.90 ,  & ! mean value of nitrate
      siomean = 91.51      ! mean value of silicate
+#endif
 
    !! * Substitutions
@@ -158,9 +160,11 @@
       CALL iom_get( numrtr, jpdom_local, 'SEDB'//ctrcnm(jpdet), sedpocb(:,:) ) 
       CALL iom_get( numrtr, jpdom_local, 'SEDN'//ctrcnm(jpdet), sedpocn(:,:) ) 
-# elif defined key_pisces
+#endif
+#if defined key_pisces
       CALL iom_get( numrtr, jpdom_local, 'Silicalim', xksi(:,:) ) 
       CALL iom_get( numrtr, jpdom_local, 'Silicamax', xksimax(:,:) )
-# elif defined key_cfc
-      DO jn = 1, jptra
+#endif
+#if defined key_cfc
+      DO jn = jp_cfc0, jp_cfc1
          CALL iom_get( numrtr, jpdom_local, 'qint'//ctrcnm(jn), qint(:,:,jn) ) 
          CALL iom_get( numrtr, jpdom_local, 'qtr'//ctrcnm(jn) , qtr( :,:,jn) ) 
@@ -325,10 +329,11 @@
          CALL iom_rstput( kt, nitrst, numrtw, 'SEDB'//ctrcnm(jpdet), sedpocb(:,:) )
          CALL iom_rstput( kt, nitrst, numrtw, 'SEDN'//ctrcnm(jpdet), sedpocn(:,:) )
-#elif defined key_pisces
+#endif
+#if defined key_pisces
          CALL iom_rstput( kt, nitrst, numrtw, 'Silicalim', xksi(:,:) )
          CALL iom_rstput( kt, nitrst, numrtw, 'Silicamax', xksimax(:,:) )
-
-#elif defined key_cfc
-         DO jn = 1, jptra
+#endif
+#if defined key_cfc
+         DO jn = jp_cfc0, jp_cfc1
             CALL iom_rstput( kt, nitrst, numrtw, 'qint'//ctrcnm(jn), qint(:,:,jn) )
             CALL iom_rstput( kt, nitrst, numrtw, 'qtr'//ctrcnm(jn) , qtr (:,:,jn) )
Index: /trunk/NEMO/TOP_SRC/trcsms.F90
===================================================================
--- /trunk/NEMO/TOP_SRC/trcsms.F90	(revision 1010)
+++ /trunk/NEMO/TOP_SRC/trcsms.F90	(revision 1011)
@@ -36,5 +36,5 @@
    SUBROUTINE trc_sms( kt )
       !!---------------------------------------------------------------------
-      !!                     ***  ROUTINE ini_trc  ***
+      !!                     ***  ROUTINE trc_sms  ***
       !!
       !! ** Purpose :   Managment of the time loop of passive tracers sms 
